averatec
Advanced OT User
features
now we need to install this mess
#1
execute this query
#2
add these values to config.php
#3
add to system/application/models/admin_model
#4
add to system/application/views/admin_menu
#5
create new file system/application/views/add_ticker.php
#6
create new file system/application/views/admin_ticker_show.php
#7
add to system/application/controllers/admin
#8
add to system/application/controllers/home
in function index after line with $date['news'] = ....
#9
add to system/application/models/home_model
#10
edit file system/application/views/home
before line
add it
Now simple tickers system will work.
- includes js script script to hide/show content(needed jquery, that is normally included maac)
- admin panel
- adding tickers
- deleting tickers
- config
- tickers limit
- words limit - ticker before will be fully showed by clicking "+", will show some initial words and that's count of these words
now we need to install this mess
#1
execute this query
Code:
CREATE TABLE `newsticker` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`date` INT(11) NOT NULL ,
`text` TEXT NOT NULL
) ENGINE=MYISAM ;
#2
add these values to config.php
PHP:
$config['newsTickerLimit'] = 10;
$config['newsTickerWords'] = 4;
add to system/application/models/admin_model
PHP:
public function getTickerList() {
$this->load->helper("url");
$page = $this->uri->segment(3);
if(empty($page))
$page = "0";
return $this->db->get("newsticker", 10, $page)->result_array();
}
public function getTickerAmount() {
return $this->db->count_all('newsticker');
}
public function addTicker($body) {
$data = array('text' => $body,
'date' => $_SERVER['REQUEST_TIME']);
$this->db->insert('newsticker', $data);
}
public function deleteTicker($id) {
$this->db->delete('newsticker', array('id' => $id));
}
add to system/application/views/admin_menu
PHP:
echo "<a href='".WEBSITE."/index.php/admin/ticker'>Tickers</a> | ";
create new file system/application/views/add_ticker.php
PHP:
<?php
echo error(validation_errors());
echo form_open("admin/add_ticker");
echo "<textarea name='text' class='tinymce'>".set_value('body')."</textarea><br />";
echo "<input type='submit' value='Add ticker'>";
echo "</form>";
?>
create new file system/application/views/admin_ticker_show.php
PHP:
<?php
echo "<div class='toolbar'>";
echo "<a href='".WEBSITE."/index.php/admin/add_ticker'>Add ticker</a> | ";
echo "</div>";
$this->load->helper('text');
if(count($news) == 0)
alert("There is no tickers yet.");
else {
echo "<table width='100%'>";
echo "<tr><td><center><b>ID</b></center></td><td><center><b>Created</b></center></td><td><center><b>Introduce</b></center></td><td><center><b>Edit</b></center></td></tr>";
foreach($news as $value) {
echo "<tr class='highlight'><td><center>".$value['id']."</center></td><td><center>".UNIX_TimeStamp($value['date'])."</center></td><td><center>".word_limiter($value['text'], $wordLimit)."</center></td><td><center><a href='#' onClick=\"if(confirm('Are you sure you want to remove?')) window.location.href='".WEBSITE."/index.php/admin/delete_ticker/".$value['id']."';\"><img src='".WEBSITE."/public/images/false.gif'></a></center></td></tr>";
}
echo "</table>";
}
echo "<center>".$pages."</center>";
?>
add to system/application/controllers/admin
PHP:
public function ticker() {
require("config.php");
$ide = new IDE;
$ide->requireAdmin();
$data = array();
$this->load->model("admin_model");
$data['news'] = $this->admin_model->getTickerList();
$this->load->library('pagination');
$config['base_url'] = WEBSITE.'/index.php/admin/ticker/';
$config['total_rows'] = $this->admin_model->getTickerAmount();
$config['per_page'] = $config['newsTickerLimit'];
$this->pagination->initialize($config);
$data['pages'] = $this->pagination->create_links();
$data['wordLimit'] = $config['newsTickerWords'];
$this->load->view("admin_menu");
$this->load->view("admin_ticker_show", $data);
}
public function add_ticker() {
$ide = new IDE;
$ide->requireAdmin();
$this->load->helper("form_helper");
$this->load->library("form_validation");
if($_POST) {
$this->form_validation->set_rules('text', 'Text', 'required');
if($this->form_validation->run() == true) {
$body = $_POST['text'];
$this->load->model("admin_model");
$this->admin_model->addTicker($body);
success("Ticker has been added.");
$ide->redirect(WEBSITE."/index.php/admin/ticker", 2);
}
}
$this->load->view("admin_menu");
$this->load->view("add_ticker");
}
public function delete_ticker() {
$ide = new IDE;
$ide->requireAdmin();
$this->load->model("admin_model");
$this->admin_model->deleteTicker($id);
$ide->goPrevious();
success("Ticker has been deleted.");
$ide->redirect(WEBSITE."/index.php/admin/ticker", 2);
}
add to system/application/controllers/home
in function index after line with $date['news'] = ....
PHP:
$data['tickers'] = $this->home_model->getTickers();
add to system/application/models/home_model
PHP:
public function getTickers() {
require("config.php");
$this->db->order_by('id desc');
$sql = $this->db->get('newsticker', $config['newsTickerLimit']);
$ret['amount'] = $sql->num_rows;
$ret['news'] = $sql->result_array();
return $ret;
}
edit file system/application/views/home
before line
PHP:
foreach($news['news'] as $value) {
PHP:
echo "<div id='tickers'>";
$this->load->helper('text');
?>
<script type="text/javascript">
$(document).ready(function() {
$(".tickerButton").each(function() {
$(this).click(function() {
if ($(this).html() == "-")
$(this).html("+")
else
$(this).html("-")
$(this).parent().find("span").each(function() {
$(this).toggle();
});
});
});
});
</script>
<?php
foreach($tickers['news'] as $value) {
echo '<div style="border: 1px black dotted; padding: 3px 3px 3px 3px; margin-bottom: 3px;"><a href="#" class="tickerButton">+</a>'.date('d M Y',$value['date']).', <span>'.word_limiter($value['text'], $config['newsTickerWords']).'</span><span style="display: none">'.$value['text'].'</span></div>';
//
}
echo "</div><br/>";
Now simple tickers system will work.