|
Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/angkasapuraretail.com/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Promo_banners extends Admin_Controller {
function __construct() {
parent::__construct();
$this->load->model('promo_banners_m');
if (!in_array('promo_banners', $this->data['allowed_module'])) {
$this->data['allowed'] = false;
} else {
$this->data['allowed'] = true;
}
}
//this is to list all promo_banners
public function index() {
//pagination in action. 100 results per page
$this->load->library('pagination');
$config['base_url'] = base_url() . 'admin/promo_banners/index';
$config['per_page'] = 100;
$config["uri_segment"] = 4;
//fetch all promo_banners
$config['total_rows'] = $this->promo_banners_m->record_count();
$this->pagination->initialize($config);
$this->data['promo_banners'] = $this->promo_banners_m->get_all_promo_banners($config["per_page"],
$this->uri->segment(4));
//load view
$this->data['subview'] = 'admin/promo_banners/index';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
//to add a new brand
public function add() {
if($this->data['allowed'] == false) { redirect('admin/dashboard'); }
$this->data['promo_banners'] = $this->promo_banners_m->get_new();
//get ordering number and display at add form
$this->db->select_max('priority')->from('promo_banners');
$current_priority = $this->db->get()->row()->priority;
if($current_priority == NULL) {
$this->data['promo_banners']->priority = 1;
} else {
$this->data['promo_banners']->priority = $current_priority + 1;
}
//validation check in action
$config = array(
array(
'field' => 'title',
'label' => 'Banner Title',
'rules' => 'trim|required'
),
array(
'field' => 'banner_link',
'label' => 'Banner Link',
'rules' => 'trim'
),
array(
'field' => 'priority',
'label' => 'Priority',
'rules' => 'trim|required|numeric'
),
array(
'field' => 'status',
'label' => 'status',
'rules' => 'trim|required'
),
array(
'field' => 'text_content',
'label' => 'text_content',
'rules' => 'trim'
),
);
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>'); //above is to add class to form validation error, to be styled
$this->form_validation->set_rules($config);
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
if($this->form_validation->run() == TRUE) {
if($_POST) {
//check & processing image banner upload files
if ($_FILES['image1']['size'] !== 0) {
$config['upload_path'] = './uploads/banners/';
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '300';
$config['max_width'] = '600';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('image1')) {
//echo $this->upload->display_errors(); die();
$this->session->set_flashdata('error', '<br>
<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
redirect('admin/promo_banners/add');
} else {
$image1 = $this->upload->data();
$image1_filename = $image1['file_name'];
}
}
$data = array(
'title' => $this->security->xss_clean($this->input->post('title')),
'banner_link' => $this->security->xss_clean($this->input->post('banner_link')),
'priority' => $this->input->post('priority'),
'status' => $this->input->post('status'),
'position' => $this->input->post('position'),
);
//image upload
if (isset($image1_filename)) {
$data['image'] = $image1_filename;
}
$this->promo_banners_m->add_promo_banners($data);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Promo Banner Add Successful</p>');
redirect('admin/promo_banners');
}
}
$this->data['subview'] = 'admin/promo_banners/edit';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
//to edit brand in admin
public function edit($id = NULL) {
//check if id exist. If not exist, show 404.
$count = $this->promo_banners_m->count_exist($id);
if ($count == 0) {
//page not exist
show_404();
}
$this->data['promo_banners'] = $this->promo_banners_m->get($id);
//validation check in action
$config = array(
array(
'field' => 'title',
'label' => 'Banner Title',
'rules' => 'trim|required'
),
array(
'field' => 'banner_link',
'label' => 'Banner Link',
'rules' => 'trim'
),
array(
'field' => 'priority',
'label' => 'Priority',
'rules' => 'trim|required|numeric'
),
array(
'field' => 'status',
'label' => 'status',
'rules' => 'trim|required'
),
array(
'field' => 'text_content',
'label' => 'text_content',
'rules' => 'trim'
),
);
$this->load->library('form_validation');
$this->form_validation->set_rules($config);
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
if($this->form_validation->run() == TRUE) {
if($_POST) {
//check & processing image banner upload files
if ($_FILES['image1']['size'] !== 0) {
$config['upload_path'] = './uploads/banners/';
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '300';
$config['max_width'] = '600';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('image1')) {
//echo $this->upload->display_errors(); die();
$this->session->set_flashdata('error', '<br>
<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
redirect('admin/promo_banners/edit/' . $id);
} else {
$image1 = $this->upload->data();
$image1_filename = $image1['file_name'];
}
}
$data = array(
'title' => $this->security->xss_clean($this->input->post('title')),
'banner_link' => $this->security->xss_clean($this->input->post('banner_link')),
'priority' => $this->input->post('priority'),
'status' => $this->input->post('status'),
'position' => $this->input->post('position'),
);
//image upload
if (isset($image1_filename)) {
$data['image'] = $image1_filename;
}
$this->promo_banners_m->edit_promo_banners($id, $data);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Promo Banner Edit Successful</p>');
redirect('admin/promo_banners');
}
}
$this->data['subview'] = 'admin/promo_banners/edit';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
//to delete a brand
public function delete($id) {
if($this->data['allowed'] == false || $this->data['role'] == 'admin') { redirect('admin/dashboard'); }
//check if id exist. If not exist, show 404.
$count = $this->promo_banners_m->count_exist($id);
if ($count == 0) {
//page not exist
show_404();
}
//delete brand
$this->promo_banners_m->delete($id);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Promo Banner Delete Successful</p>');
redirect('admin/promo_banners');
}
}