|
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/kamariallee.com/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sizes extends Admin_Controller {
//this property is used for validating existing size title on call back edit size
protected $size_current_id;
protected $attribute_current_id;
function __construct() {
parent::__construct();
$this->load->model('size_m');
$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 is to list all sizes
public function index() {
//pagination in action. 100 results per page
$this->load->library('pagination');
$config['base_url'] = base_url() . 'admin/sizes/index';
$config['per_page'] = 100;
$config["uri_segment"] = 4;
//config for bootstrap pagination class integration
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
//fetch all sizes
$config['total_rows'] = $this->size_m->record_count();
$this->pagination->initialize($config);
$this->data['sizes'] = $this->size_m->get_all_product_size($config["per_page"],
$this->uri->segment(4));
//load view
$this->data['subview'] = 'admin/sizes/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 size
public function add() {
redirect('admin/sizes');
$this->data['sizes'] = $this->size_m->get_new();
//validation in action
//validation check in action
$config = $this->size_m->rules;
$this->form_validation->set_rules($config);
if($this->form_validation->run($this) == TRUE) {
$data = $this->table_data_processing($this->input->post('size'));
$this->size_m->add_product_size($data);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Product Option Add Successful</p>');
redirect('admin/sizes');
}
$this->data['subview'] = 'admin/sizes/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 size in admin
public function edit($id = NULL) {
//check if id exist. If not exist, show 404.
$count = $this->size_m->count_exist($id);
if ($count == 0) {
//page not exist
show_404();
}
$this->data['sizes'] = $this->size_m->get($id);
$this->size_current_id = (int) $this->data['sizes']->id_product_size;
//validation check in action
$config = $this->size_m->rules;
$this->form_validation->set_rules($config);
if($this->form_validation->run($this) == TRUE) {
$data = $this->table_data_processing($this->input->post('size'));
$this->size_m->edit_product_size($id, $data);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Product Option Edit Successful</p>');
redirect('admin/sizes');
}
$this->data['subview'] = 'admin/sizes/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 size
public function delete($id) {
redirect('admin/sizes');
//delete size
$this->size_m->delete($id);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Product Option Delete Successful</p>');
redirect('admin/sizes');
}
private function table_data_processing($size)
{
$data = array(
'product_size' => $this->security->xss_clean($size),
'is_color' => $this->security->xss_clean($this->input->post('is_color'))
);
return $data;
}
//callback function validation add new size
public function _cek_existing_size_title($str) {
$num_rows = $this->size_m->cek_existing_size_title($str, $this->size_current_id);
if ($num_rows != 0 ) {
$this->form_validation->set_message('_cek_existing_size_title', 'Product Option already exist !');
return FALSE;
} else {
return TRUE;
}
}
/*-----ATTRIBUTES----------*/
public function view_attributes($id = NULL) {
if ($id == NULL) { show_404(); }
$this->data['attributes'] = $this->size_m->get_all_product_attributes($id);
$this->data['id_option'] = $id;
$this->db->select('product_size, is_color')->from('product_size')->where('id_product_size', $id);
$sizes = $this->db->get()->row();
$this->data['option_name'] = $sizes->product_size;
$this->data['is_color'] = $sizes->is_color;
//load view
$this->data['subview'] = 'admin/sizes/attributes_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 size
public function add_attribute($id)
{
$this->size_current_id = $id;
$this->data['attributes'] = $this->size_m->get_new_attributes();
//validation in action
//validation check in action
$config = $this->size_m->attribute_rules;
$this->form_validation->set_rules($config);
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
if($this->form_validation->run($this) == TRUE)
{
if($_FILES['image']) {
$image_filename = $this->image_processing($_FILES['image'], 'image');
}
if($_FILES['image2']) {
$image_filename2 = $this->image_processing($_FILES['image2'], 'image2');
}
if($_FILES['image3']) {
$image_filename3 = $this->image_processing($_FILES['image3'], 'image3');
}
// $product_attribute = preg_replace('/\s+/', '', $this->input->post('product_attributes'));
$product_attribute = str_replace(',','', $this->input->post('product_attributes'));
$data = array(
'product_attributes' => $product_attribute,
'id_product_size' => $id,
'color_code' => $this->input->post('color_code'),
'additional_price' => (int) $this->input->post('additional_price'),
);
//image upload
if(isset($image_filename))
{
$data['image'] = $image_filename;
}
//image upload
if(isset($image_filename2))
{
$data['image2'] = $image_filename2;
}
//image upload
if(isset($image_filename3))
{
$data['image3'] = $image_filename3;
}
$this->size_m->add_product_attributes($data);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Attributes Add Successful</p>');
redirect('admin/sizes/view_attributes/' . $id);
}
$this->data['size_id'] = $this->size_current_id;
$this->db->select('product_size, is_color')->from('product_size')->where('id_product_size',$this->size_current_id);
$sizes = $this->db->get()->row();
$this->data['product_size'] = $sizes->product_size;
$this->data['is_color'] = $sizes->is_color;
$this->data['subview'] = 'admin/sizes/edit_attributes';
$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 size in admin
public function edit_attribute($attribute_id)
{
//check if id exist. If not exist, show 404.
$this->db->select('*');
$this->db->from('product_attributes');
$this->db->where('id_product_attributes', $attribute_id);
$query = $this->db->get();
$count = $query->num_rows();
if ($count == 0) {
//page not exist
show_404();
}
//get attributes
$this->db->select('*');
$this->db->from('product_attributes');
$this->db->where('id_product_attributes', $attribute_id);
$this->data['attributes'] = $this->db->get()->row();
$this->attribute_current_id = (int) $this->data['attributes']->id_product_attributes;
//validation in action
//validation check in action
$config = $this->size_m->attribute_rules;
$this->form_validation->set_rules($config);
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
if($this->form_validation->run($this) == TRUE) {
if($_FILES['image']) {
$image_filename = $this->image_processing($_FILES['image'], 'image');
}
if($_FILES['image2']) {
$image_filename2 = $this->image_processing($_FILES['image2'], 'image2');
}
if($_FILES['image3']) {
$image_filename3 = $this->image_processing($_FILES['image3'], 'image3');
}
/* $product_attribute = preg_replace('/\s+/', '', $this->input->post('product_attributes')); */
$product_attribute = str_replace(',','',$this->input->post('product_attributes'));
$data = array(
'product_attributes' => $product_attribute,
'color_code' => $this->input->post('color_code'),
'additional_price' => (int) $this->input->post('additional_price'),
);
//image upload
if(isset($image_filename))
{
$data['image'] = $image_filename;
}
//image upload
if(isset($image_filename2))
{
$data['image2'] = $image_filename2;
}
//image upload
if(isset($image_filename3))
{
$data['image3'] = $image_filename3;
}
$this->size_m->edit_product_attribute($attribute_id, $data);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Product Attributes Edit Successful</p>');
redirect('admin/sizes/edit_attribute/' . $attribute_id);
}
$this->data['size_id'] = $this->data['attributes']->id_product_size;
$this->db->select('product_size, is_color')->from('product_size')->where('id_product_size', $this->data['attributes']->id_product_size);
$sizes = $this->db->get()->row();
$this->data['product_size'] = $sizes->product_size;
$this->data['is_color'] = $sizes->is_color;
$this->data['subview'] = 'admin/sizes/edit_attributes';
$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 size
public function delete_attribute($id) {
//get size_id
$this->db->select('id_product_size');
$this->db->from('product_attributes');
$this->db->where('id_product_attributes', $id);
$size_id = $this->db->get()->row()->id_product_size;
//delete size
$this->db->where('id_product_attributes', $id);
$this->db->delete('product_attributes');
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Product Attribute Delete Successful</p>');
redirect('admin/sizes/view_attributes/' . $size_id);
}
//callback function validation add new size
public function _cek_existing_attribute_title($str) {
$num_rows = $this->size_m->cek_existing_attribute_title($str, $this->attribute_current_id);
return TRUE;
// if ($num_rows != 0 ) {
// $this->form_validation->set_message('_cek_existing_attribute_title', 'Attribute already exist !');
// return FALSE;
// } else {
// return TRUE;
// }
}
//image upload processing
private function image_processing($image_file, $name)
{
//check & processing image banner upload files
if ($image_file['size'] !== 0)
{
$config = array();
$config['upload_path'] = './uploads/sizes/';
$config['allowed_types'] = 'jpg|png|jpeg';
$config['max_size'] = '500';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload($name))
{
echo $this->upload->display_errors(); die();
$this->session->set_flashdata('banner_error', '<br>
<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
if ($this->attribute_current_id_id != NULL)
{
redirect('admin/sizes/edit_attribute/' . $this->attribute_current_id);
}
elseif($this->attribute_current_id_id == NULL)
{
redirect('admin/sizes/add_attribute/' . $this->attribute_current_id);
}
}
else
{
$image = $this->upload->data();
$image_filename = $image['file_name'];
return $image_filename;
}
}
}
//To delete product image file from server, and from database
public function delete_attribute_image($id = NULL, $image_name) {
//get image file name for deletion
$this->db->select($image_name)->from('product_attributes')->where('id_product_attributes', (int) $id);
$image = $this->db->get()->row();
switch ($image_name) {
case 'image':
//Delete the actual image file from server. FCPATH is codeigniter base path
if (file_exists(base_url() . 'uploads/sizes/' . $image->image)) {
unlink(FCPATH .'/uploads/sizes/'. $image->image);
}
//Delete image field from database
$data = array(
'image' => '',
);
break;
case 'image2':
//Delete the actual image file from server. FCPATH is codeigniter base path
if (file_exists(base_url() . 'uploads/sizes/' . $image->image2)) {
unlink(FCPATH .'/uploads/sizes/'. $image->image2);
}
//Delete image field from database
$data = array(
'image2' => '',
);
break;
case 'image3':
//Delete the actual image file from server. FCPATH is codeigniter base path
if (file_exists(base_url() . 'uploads/sizes/' . $image->image3)) {
unlink(FCPATH .'/uploads/sizes/'. $image->image3);
}
//Delete image field from database
$data = array(
'image3' => '',
);
break;
}
$this->db->where('id_product_attributes', (int) $id);
$this->db->update('product_attributes', $data);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>');
redirect('admin/sizes/edit_attribute/' . $id);
}
}