| Server IP : 68.178.202.69 / Your IP : 216.73.216.174 Web Server : Apache System : Linux 69.202.178.68.host.secureserver.net 3.10.0-1160.139.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Nov 3 13:30:41 UTC 2025 x86_64 User : ikioworld ( 1005) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/ikioworld/www/application/controllers/admin/ |
Upload File : |
<?php
class Subcategory extends CI_Controller {
public function __construct() {
parent::__construct ();
$this->load->helper('download');
}
function index()
{
$this->load->helper(array('form', 'url','common'));
$this->load->library(array('session','pagination'));
$this->load->model('loginmodel','',TRUE);
$this->loginmodel->check_is_valid_user();
$this->load->model('subcategorymodel','',TRUE);
$data = array(
'header' => $this->load->view('admin/assets/header', '', TRUE),
'footer' => $this->load->view('admin/assets/footer', '', TRUE),
);
$num_records = $this->subcategorymodel->get_total_records();
$data['num_records'] = $num_records;
$base_url=base_url().'admin/subcategory/index';
$start_index=$this->uri->segment($this->uri->total_segments());
$default_page_size = 5;
if( $this->input->get('per_page') != '' ){
$per_page = $this->input->get('per_page');
}
else{
$per_page=$default_page_size;
}
$data['default_page_size'] = $default_page_size;
$content_array=$this->subcategorymodel->get_contents($per_page,$start_index);
$data['content_array']=$content_array;
$data['start_index']=$start_index;
$data['pagination_links']=paging($base_url,$this->input->server("QUERY_STRING"),$num_records,$per_page,$this->uri->total_segments());
$data['categorys']=$this->subcategorymodel->getAllCategories();
$this->load->view('admin/subcategory/index',$data);
}
function add(){
$this->load->helper(array('form', 'url','common'));
$this->load->library(array('session','pagination'));
$this->load->model('subcategorymodel','',TRUE);
if(!empty($this->input->post())){
$insert_id=$this->subcategorymodel->add($this->input->post());
self::upload_file($insert_id,$_FILES,'image','add');
$subcat_filter_array=isset($_POST['subcat_filter']) && !empty($_POST['subcat_filter'])?$_POST['subcat_filter']:[];
if(!empty($subcat_filter_array)){
foreach($subcat_filter_array as $key=>$value){
$appInsert=['subcategory_id'=>$insert_id,'name'=>$value];
$this->db->insert('subcategory_filter',$appInsert);
}
}
$this->session->set_flashdata('message',"subcategory has been added.");
redirect("admin/subcategory");
}
$data = array(
'header' => $this->load->view('admin/assets/header', '', TRUE),
'footer' => $this->load->view('admin/assets/footer', '', TRUE),
);
$data['categorys']=$this->subcategorymodel->getAllCategories();
$data['filters'] =$this->subcategorymodel->getAllFilters();
$this->load->view('admin/subcategory/add',$data);
}
function edit($id){
$this->load->helper(array('form', 'url','common'));
$this->load->library(array('session','pagination'));
$this->load->model('subcategorymodel','',TRUE);
$data = array(
'header' => $this->load->view('admin/assets/header', '', TRUE),
'footer' => $this->load->view('admin/assets/footer', '', TRUE),
);
$data['record']=$this->subcategorymodel->fetch_details($id);
if(!empty($this->input->post())){
$result=$this->subcategorymodel->edit($id,$this->input->post());
if($result){
self::upload_file($id,$_FILES,'image','edit');
}
$subcat_filter_array=isset($_POST['subcat_filter']) && !empty($_POST['subcat_filter'])?$_POST['subcat_filter']:[];
if(!empty($subcat_filter_array)){
$this->db->where('subcategory_id',$id);
$this->db->delete('subcategory_filter');
foreach($subcat_filter_array as $key=>$value){
$appInsert=['subcategory_id'=>$id,'name'=>$value];
$this->db->insert('subcategory_filter',$appInsert);
}
}
// $sql=$this->db->query('INSERT into subcategory_logs (subcategory_id) values('.$id.')');
$this->session->set_flashdata('message',"subcategory has been updated.");
redirect("admin/subcategory");
}
$data['categorys']=$this->subcategorymodel->getAllCategories();
$data['filters'] =$this->subcategorymodel->getAllFilters();
$this->load->view('admin/subcategory/edit',$data);
}
function upload_file($id,$fileArray,$column,$for='add'){
if($id!='' && !empty($fileArray) && $fileArray[$column]['error']=="0" && $column!=''){
$record=$this->subcategorymodel->fetch_details($id);
$file_name=$fileArray[$column]['name'];
if($for=="edit"){
@unlink(FCPATH."uploads/subcategory/".$record->$column);
}
$ffdsf=$this->subcategorymodel->edit($id,[$column=>$file_name]);
move_uploaded_file($fileArray[$column]['tmp_name'],FCPATH."uploads/subcategory/".$file_name);
}
}
function delete($id){
$this->load->helper(array('form', 'url'));
$this->load->library(array('session','pagination'));
$this->load->model('subcategorymodel','',TRUE);
if($id!=''){
$this->subcategorymodel->deletesubcategory($id);
$this->session->set_flashdata('message',"subcategory has been deleted.");
redirect("admin/subcategory");
}
}
function update_status(){
$this->load->helper(array('form', 'url'));
$this->load->library(array('session','pagination'));
$this->load->model('subcategorymodel','',TRUE);
$id= $_GET['sid'];
$status= $_GET['svalue'];
if($status == 'active')
{
$sql=$this->db->query("UPDATE subcategory set status='inactive' where id='$id'");
}else{
$sql=$this->db->query("UPDATE subcategory set status='active' where id='$id'");
}
redirect("admin/subcategory");
}
function export_csv(){
$this->load->helper(array('form', 'url','common'));
$this->load->library(array('session','pagination'));
$this->load->model('loginmodel','',TRUE);
$this->loginmodel->check_is_valid_user();
$this->load->model('subcategorymodel','',TRUE);
$filename = 'subcategory_'.date('Ymd').'.csv';
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/csv; ");
// get data
$productData = $this->subcategorymodel->get_export_data();
// file creation
$file = fopen('php://output', 'w');
$header = array("category_type","image","name","slug");
fputcsv($file, $header);
foreach ($productData as $key=>$line){
fputcsv($file,$line);
}
fclose($file);
exit;
}
function delete_subcategory()
{
$this->load->helper(array('form', 'url','common'));
$this->load->library(array('session','pagination'));
$this->load->model('loginmodel','',TRUE);
$this->loginmodel->check_is_valid_user();
$this->load->model('subcategorymodel','',TRUE);
if($this->input->post('checkbox_value'))
{
$id = $this->input->post('checkbox_value');
for($count = 0; $count < count($id); $count++)
{
$this->subcategorymodel->delete_subcategory($id[$count]);
}
}
}
}