| Server IP : 68.178.202.69 / Your IP : 216.73.216.122 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/public_html/application/controllers/admin/ |
Upload File : |
<?php
class Product 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('productmodel','',TRUE);
$data = array(
'header' => $this->load->view('admin/assets/header', '', TRUE),
'footer' => $this->load->view('admin/assets/footer', '', TRUE),
);
$num_records = $this->productmodel->get_total_records();
$data['num_records'] = $num_records;
$base_url=base_url().'admin/product/index';
$start_index=$this->uri->segment($this->uri->total_segments());
$default_page_size = 10;
if( $this->input->get('per_page') != '' ){
$per_page = $this->input->get('per_page');
}
else{
$per_page=$default_page_size;
}
if(isset($_GET['product_category'])){
$cat = $_GET['product_category'];
$sql=$this->db->query("SELECT * from category where id='$cat'");
$result = $sql->result();
$data['filter_name'] = $result[0]->category_name;
}
if(isset($_GET['product_subcategory'])){
$subcat = $_GET['product_subcategory'];
$sqel=$this->db->query("SELECT * from subcategory where id='$subcat'");
$results = $sqel->result();
$data['filter_name'] = $results[0]->name;
}
$data['default_page_size'] = $default_page_size;
$content_array=$this->productmodel->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['subcategory'] = $this->productmodel->getAllSubCategories();
$data['category']=$this->productmodel->getAllCategories();
$this->load->view('admin/product/index',$data);
}
function featured()
{
$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('productmodel','',TRUE);
$data = array(
'header' => $this->load->view('admin/assets/header', '', TRUE),
'footer' => $this->load->view('admin/assets/footer', '', TRUE),
);
$num_records = $this->productmodel->get_featured_total_records();
$data['num_records'] = $num_records;
$base_url=base_url().'admin/product/index';
$start_index=$this->uri->segment($this->uri->total_segments());
$default_page_size = 10;
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->productmodel->get_featured_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());
$this->load->view('admin/product/featured',$data);
}
function add(){
$this->load->helper(array('form', 'url'));
$this->load->library(array('session','pagination'));
$this->load->model('productmodel','',TRUE);
if(!empty($this->input->post())){
$insert_id=$this->productmodel->add($this->input->post());
if($insert_id!=''){
self::upload_file($insert_id,$_FILES,'product_right_top_image','add');
self::upload_file($insert_id,$_FILES,'product_left_bottom_image','add');
self::upload_file($insert_id,$_FILES,'featured_image','add');
self::upload_docs($insert_id,$_FILES,'document1','add');
self::upload_docs($insert_id,$_FILES,'document2','add');
self::upload_docs($insert_id,$_FILES,'document3','add');
self::upload_docs($insert_id,$_FILES,'document4','add');
self::upload_docs($insert_id,$_FILES,'document5','add');
$postData=$this->input->post();
$product_app_array=isset($postData['application_area']) && !empty($postData['application_area'])?$postData['application_area']:[];
if(!empty($product_app_array)){
foreach($product_app_array as $key=>$value){
$appInsert=['product_id'=>$insert_id,'product_application'=>$value];
$this->db->insert('product_application',$appInsert);
}
}
$product_variant_array=isset($postData['product_variant']) && !empty($postData['product_variant'])?$postData['product_variant']:[];
if(!empty($product_variant_array)){
foreach($product_variant_array as $key=>$value){
$appInsert=['product_id'=>$insert_id,'product_variant'=>$value];
$this->db->insert('product_variant',$appInsert);
}
}
$product_features_array=isset($postData['product_features']) && !empty($postData['product_features'])?$postData['product_features']:[];
if(!empty($product_features_array)){
foreach($product_features_array as $key=>$value){
$appInsert=['product_id'=>$insert_id,'product_features'=>$value];
$this->db->insert('product_feature',$appInsert);
}
}
$product_type_array=isset($postData['product_type']) && !empty($postData['product_type'])?$postData['product_type']:[];
if(!empty($product_type_array)){
foreach($product_type_array as $key=>$value){
$appInsert=['product_id'=>$insert_id,'product_type'=>$value];
$this->db->insert('product_type',$appInsert);
}
}
$product_rating_array=isset($postData['product_rating']) && !empty($postData['product_rating'])?$postData['product_rating']:[];
if(!empty($product_rating_array)){
foreach($product_rating_array as $key=>$value){
$appInsert=['product_id'=>$insert_id,'product_rating'=>$value];
$this->db->insert('product_rating',$appInsert);
}
}
$product_company_array=isset($postData['product_company']) && !empty($postData['product_company'])?$postData['product_company']:[];
if(!empty($product_company_array)){
foreach($product_company_array as $key=>$value){
$appInsert=['product_id'=>$insert_id,'company_id'=>$value];
$this->db->insert('product_company',$appInsert);
}
}
$product_image_array=isset($_FILES['product_image']) && !empty($_FILES['product_image'])?$_FILES['product_image']:[];
$fileNameArray=isset($product_image_array['name'])?$product_image_array['name']:[];
if(!empty($fileNameArray)){
foreach($fileNameArray as $key=>$file_name){
$file_type=isset($product_image_array['type'][$key])?$product_image_array['type'][$key]:[];
$file_tmp_name=isset($product_image_array['tmp_name'][$key])?$product_image_array['tmp_name'][$key]:[];
$file_error=isset($product_image_array['error'][$key])?$product_image_array['error'][$key]:[];
move_uploaded_file($file_tmp_name,FCPATH."uploads/product/".$file_name);
if($file_error==0){
$imageInsert=['product_id'=>$insert_id,'image'=>$file_name];
$this->db->insert('product_images',$imageInsert);
}else{
}
}
}
}
$this->session->set_flashdata('message',"Product has been added.");
{
redirect('admin/product');
}
}
$data = array(
'header' => $this->load->view('admin/assets/header', '', TRUE),
'footer' => $this->load->view('admin/assets/footer', '', TRUE),
);
$data['type'] = $this->productmodel->getAllType();
$data['application'] = $this->productmodel->getAllApps();
$data['variant'] = $this->productmodel->getAllVariant();
$data['features'] = $this->productmodel->getAllFeatures();
$data['rating'] = $this->productmodel->getAllRating();
$data['company'] = $this->productmodel->getAllCompanies();
$data['category']=$this->productmodel->getAllCategories();
$data['subcategorys']=$this->productmodel->getAllSubCategories();
$this->load->view('admin/product/add',$data);
}
function edit($id){
$this->load->helper(array('form', 'url', 'common'));
$this->load->library(array('session','pagination'));
$this->load->model('productmodel','',TRUE);
$data = array(
'header' => $this->load->view('admin/assets/header', '', TRUE),
'footer' => $this->load->view('admin/assets/footer', '', TRUE),
);
$current_url = current_url();
$data['record']=$this->productmodel->fetch_details($id);
if(!empty($this->input->post())){
$res=$this->productmodel->edit($id,$this->input->post());
self::upload_file($id,$_FILES,'product_right_top_image','edit');
self::upload_file($id,$_FILES,'product_left_bottom_image','edit');
self::upload_file($id,$_FILES,'featured_image','edit');
self::upload_docs($id,$_FILES,'document1','edit');
self::upload_docs($id,$_FILES,'document2','edit');
self::upload_docs($id,$_FILES,'document3','edit');
self::upload_docs($id,$_FILES,'document4','edit');
self::upload_docs($id,$_FILES,'document5','edit');
$postData=$this->input->post();
$product_app_array=isset($postData['application_area']) && !empty($postData['application_area'])?$postData['application_area']:[];
if(empty($product_app_array)){
$this->db->where('product_id',$id);
$this->db->delete('product_application');
}else{
$this->db->where('product_id',$id);
$this->db->delete('product_application');
foreach($product_app_array as $key=>$value){
$sizeInsert=['product_id'=>$id,'product_application'=>$value];
$this->db->insert('product_application',$sizeInsert);
}
}
$product_var_array=isset($postData['product_variant']) && !empty($postData['product_variant'])?$postData['product_variant']:[];
if(empty($product_var_array)){
$this->db->where('product_id',$id);
$this->db->delete('product_variant');
}else{
foreach($product_var_array as $key=>$value){
$sizeInsert=['product_id'=>$id,'product_variant'=>$value];
$this->db->insert('product_variant',$sizeInsert);
}
}
$product_feat_array=isset($postData['product_features']) && !empty($postData['product_features'])?$postData['product_features']:[];
if(empty($product_feat_array)){
$this->db->where('product_id',$id);
$this->db->delete('product_feature');
}else{
foreach($product_feat_array as $key=>$value){
$sizeInsert=['product_id'=>$id,'product_features'=>$value];
$this->db->insert('product_feature',$sizeInsert);
}
}
$product_type_array=isset($postData['product_type']) && !empty($postData['product_type'])?$postData['product_type']:[];
if(empty($product_type_array)){
$this->db->where('product_id',$id);
$this->db->delete('product_type');
} else{
foreach($product_type_array as $key=>$value){
$sizeInsert=['product_id'=>$id,'product_type'=>$value];
$this->db->insert('product_type',$sizeInsert);
}
}
$product_rating_array=isset($postData['product_rating']) && !empty($postData['product_rating'])?$postData['product_rating']:[];
if(empty($product_rating_array)){
$this->db->where('product_id',$id);
$this->db->delete('product_rating');
}else{
foreach($product_rating_array as $key=>$value){
$sizeInsert=['product_id'=>$id,'product_rating'=>$value];
$this->db->insert('product_rating',$sizeInsert);
}
}
$product_company_array=isset($postData['product_company']) && !empty($postData['product_company'])?$postData['product_company']:[];
if(empty($product_company_array)){
$this->db->where('product_id',$id);
$this->db->delete('product_company');
}else{
foreach($product_company_array as $key=>$value){
$compInsert=['product_id'=>$id,'company_id'=>$value];
$this->db->insert('product_company',$compInsert);
}
}
$product_image_array=isset($_FILES['product_image']) && !empty($_FILES['product_image'])?$_FILES['product_image']:[];
$fileNameArray=isset($product_image_array['name'])?$product_image_array['name']:[];
if(!empty($fileNameArray)){
foreach($fileNameArray as $key=>$file_name){
$file_type=isset($product_image_array['type'][$key])?$product_image_array['type'][$key]:[];
$file_tmp_name=isset($product_image_array['tmp_name'][$key])?$product_image_array['tmp_name'][$key]:[];
$file_error=isset($product_image_array['error'][$key])?$product_image_array['error'][$key]:[];
move_uploaded_file($file_tmp_name,FCPATH."uploads/product/".$file_name);
if($file_error==0){
$imageInsert=['product_id'=>$id,'image'=>$file_name];
$this->db->insert('product_images',$imageInsert);
}else{
}
}
}
$this->session->set_flashdata('message',"Product has been updated.");
redirect($current_url);
}
$data['category']=$this->productmodel->getAllCategories();
$data['subcategorys']=$this->productmodel->getAllSubCategories();
$data['type'] = $this->productmodel->getAllType();
$data['application'] = $this->productmodel->getAllApps();
$data['variant'] = $this->productmodel->getAllVariant();
$data['features'] = $this->productmodel->getAllFeatures();
$data['rating'] = $this->productmodel->getAllRating();
$data['company'] = $this->productmodel->getAllCompanies();
$this->load->view('admin/product/edit',$data);
}
function duplicate($id){
$this->load->helper(array('form', 'url', 'common'));
$this->load->library(array('session','pagination'));
$this->load->model('productmodel','',TRUE);
$data = array(
'header' => $this->load->view('admin/assets/header', '', TRUE),
'footer' => $this->load->view('admin/assets/footer', '', TRUE),
);
$current_url = current_url();
$data['record']=$this->productmodel->fetch_details($id);
if(!empty($this->input->post())){
$insert_id=$this->productmodel->add($this->input->post());
if($insert_id!=''){
self::upload_file($insert_id,$_FILES,'product_right_top_image','add');
self::upload_file($insert_id,$_FILES,'product_left_bottom_image','add');
self::upload_file($insert_id,$_FILES,'featured_image','add');
self::upload_docs($insert_id,$_FILES,'document1','add');
self::upload_docs($insert_id,$_FILES,'document2','add');
self::upload_docs($insert_id,$_FILES,'document3','add');
self::upload_docs($insert_id,$_FILES,'document4','add');
self::upload_docs($insert_id,$_FILES,'document5','add');
$postData=$this->input->post();
$product_app_array=isset($postData['application_area']) && !empty($postData['application_area'])?$postData['application_area']:[];
if(!empty($product_app_array)){
foreach($product_app_array as $key=>$value){
$appInsert=['product_id'=>$insert_id,'product_application'=>$value];
$this->db->insert('product_application',$appInsert);
}
}
$product_variant_array=isset($postData['product_variant']) && !empty($postData['product_variant'])?$postData['product_variant']:[];
if(!empty($product_variant_array)){
foreach($product_variant_array as $key=>$value){
$appInsert=['product_id'=>$insert_id,'product_variant'=>$value];
$this->db->insert('product_variant',$appInsert);
}
}
$product_features_array=isset($postData['product_features']) && !empty($postData['product_features'])?$postData['product_features']:[];
if(!empty($product_features_array)){
foreach($product_features_array as $key=>$value){
$appInsert=['product_id'=>$insert_id,'product_features'=>$value];
$this->db->insert('product_feature',$appInsert);
}
}
$product_type_array=isset($postData['product_type']) && !empty($postData['product_type'])?$postData['product_type']:[];
if(!empty($product_type_array)){
foreach($product_type_array as $key=>$value){
$appInsert=['product_id'=>$insert_id,'product_type'=>$value];
$this->db->insert('product_type',$appInsert);
}
}
$product_rating_array=isset($postData['product_rating']) && !empty($postData['product_rating'])?$postData['product_rating']:[];
if(!empty($product_rating_array)){
foreach($product_rating_array as $key=>$value){
$appInsert=['product_id'=>$insert_id,'product_rating'=>$value];
$this->db->insert('product_rating',$appInsert);
}
}
$product_image_array=isset($_FILES['product_image']) && !empty($_FILES['product_image'])?$_FILES['product_image']:[];
$fileNameArray=isset($product_image_array['name'])?$product_image_array['name']:[];
if(!empty($fileNameArray)){
foreach($fileNameArray as $key=>$file_name){
$file_type=isset($product_image_array['type'][$key])?$product_image_array['type'][$key]:[];
$file_tmp_name=isset($product_image_array['tmp_name'][$key])?$product_image_array['tmp_name'][$key]:[];
$file_error=isset($product_image_array['error'][$key])?$product_image_array['error'][$key]:[];
move_uploaded_file($file_tmp_name,FCPATH."uploads/product/".$file_name);
if($file_error==0){
$imageInsert=['product_id'=>$insert_id,'image'=>$file_name];
$this->db->insert('product_images',$imageInsert);
}else{
}
}
}
}
$this->session->set_flashdata('message',"Product has been added.");
{
redirect('admin/product');
}
}
$data['category']=$this->productmodel->getAllCategories();
$data['subcategorys']=$this->productmodel->getAllSubCategories();
$data['type'] = $this->productmodel->getAllType();
$data['application'] = $this->productmodel->getAllApps();
$data['variant'] = $this->productmodel->getAllVariant();
$data['features'] = $this->productmodel->getAllFeatures();
$data['rating'] = $this->productmodel->getAllRating();
$this->load->view('admin/product/duplicate',$data);
}
function upload_file($id,$fileArray,$column,$for='add'){
if($id!='' && !empty($fileArray) && $fileArray[$column]['error']=="0" && $column!=''){
$record=$this->productmodel->fetch_details($id);
$file_name=$fileArray[$column]['name'];
if($for=="edit"){
@unlink(FCPATH."uploads/product/".$record->$column);
}
$ffdsf=$this->productmodel->edit($id,[$column=>$file_name]);
move_uploaded_file($fileArray[$column]['tmp_name'],FCPATH."uploads/product/".$file_name);
return true;
}
}
function upload_docs($id,$fileArray,$column,$for='add'){
if($id!='' && !empty($fileArray) && $fileArray[$column]['error']=="0" && $column!=''){
$record=$this->productmodel->fetch_details($id);
$file_name=$fileArray[$column]['name'];
if($for=="edit"){
@unlink(FCPATH."uploads/tech_document/".$record->$column);
}
$ffdsf=$this->productmodel->edit($id,[$column=>$file_name]);
move_uploaded_file($fileArray[$column]['tmp_name'],FCPATH."uploads/tech_document/".$file_name);
return true;
}
}
function delete($id){
$this->load->helper(array('form', 'url'));
$this->load->library(array('session','pagination'));
$this->load->model('productmodel','',TRUE);
if($id!=''){
$this->productmodel->deleteproduct($id);
$this->session->set_flashdata('message',"Product has been deleted.");
redirect("admin/product");
}
}
function getAllCategories()
{
$data['groups'] = $this->productmodel->get_category();
$this->load->view('admin/product/add',$data);
}
function get_subcategory(){
if($this->input->post()){
$item_id=$this->input->post('item_id');
$this->load->helper(array('form', 'url'));
$this->load->library(array('session','pagination'));
$this->load->model('productmodel','',TRUE);
$subcategorys=$this->productmodel->get_subcategory($item_id);
$html='<option value="">Select Your Sub Category</option>';
if(count($subcategorys)>0)
{
foreach($subcategorys as $subcategories){
$html.='<option value="'.$subcategories->id.'">'.$subcategories->name.'</option>';
}
}
echo $html;
}
}
function update_status(){
$this->load->helper(array('form', 'url'));
$this->load->library(array('session','pagination'));
$this->load->model('productmodel','',TRUE);
$id= $_GET['sid'];
$status= $_GET['svalue'];
if($status == 'active')
{
$sql=$this->db->query("UPDATE product set status='inactive' where id='$id'");
}else{
$sql=$this->db->query("UPDATE product set status='active' where id='$id'");
}
redirect("admin/product");
}
function update_featured(){
$this->load->helper(array('form', 'url'));
$this->load->library(array('session','pagination'));
$this->load->model('productmodel','',TRUE);
$id= $_GET['sid'];
$status= $_GET['svalue'];
if($status == 'no')
{
$sql=$this->db->query("UPDATE product set is_featured='yes' where id='$id'");
}else{
$sql=$this->db->query("UPDATE product set is_featured='no' where id='$id'");
}
redirect("admin/product");
}
function export_csv()
{
$this->load->helper(array('form', 'url','common'));
$this->load->library(array('session','pagination'));
$this->load->model('productmodel','',TRUE);
$filename = 'products_'.date('Ymd').'.csv';
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/csv;");
$productData = $this->productmodel->get_export_data();
$file = fopen('php://output', 'w');
$header = array("product_category","product_subcategory","product_name","featured_image","product_tagline","product_short_description","product_long_description","features","video_link","meta_title","meta_description","meta_keyword","product_right_top_image","product_left_bottom_image","ordering_information","accessories","slug");
fputcsv($file, $header);
foreach ($productData as $key => $line){
fputcsv($file,$line);
}
}
function delete_all_product()
{
$this->load->helper(array('form', 'url','common'));
$this->load->library(array('session','pagination'));
$this->load->model('productmodel','',TRUE);
if($this->input->post('checkbox_value'))
{
$id = $this->input->post('checkbox_value');
for($count = 0; $count < count($id); $count++)
{
$this->productmodel->deleteallproduct($id[$count]);
}
redirect("admin/product");
}
}
function delete_product()
{
$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('productmodel','',TRUE);
if($this->input->post('checkbox_value'))
{
$id = $this->input->post('checkbox_value');
for($count = 0; $count < count($id); $count++)
{
$this->productmodel->delete_product($id[$count]);
}
}
}
function make_featured()
{
$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('productmodel','',TRUE);
if($this->input->post('checkbox_value'))
{
$id = $this->input->post('checkbox_value');
for($count = 0; $count < count($id); $count++)
{
$this->productmodel->make_featured($id[$count]);
}
}
}
function remove_featured()
{
$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('productmodel','',TRUE);
if($this->input->post('checkbox_value'))
{
$id = $this->input->post('checkbox_value');
for($count = 0; $count < count($id); $count++)
{
$this->productmodel->remove_featured($id[$count]);
}
}
}
function make_activated()
{
$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('productmodel','',TRUE);
if($this->input->post('checkbox_value'))
{
$id = $this->input->post('checkbox_value');
for($count = 0; $count < count($id); $count++)
{
$this->productmodel->make_activated($id[$count]);
}
}
}
function remove_activated()
{
$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('productmodel','',TRUE);
if($this->input->post('checkbox_value'))
{
$id = $this->input->post('checkbox_value');
for($count = 0; $count < count($id); $count++)
{
$this->productmodel->remove_activated($id[$count]);
}
}
}
function remove_top()
{
$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('productmodel','',TRUE);
$doc_id = $_GET['doc_name'];
$prod_id = $_GET['product_id'];
$sql=$this->db->query("UPDATE product set product_right_top_image = null where id ='$prod_id'");
echo "<script>
history.go(-1);
</script>";
}
function remove_bottom()
{
$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('productmodel','',TRUE);
$doc_id = $_GET['doc_name'];
$prod_id = $_GET['product_id'];
$sql=$this->db->query("UPDATE product set product_left_bottom_image = null where id ='$prod_id'");
echo "<script>
history.go(-1);
</script>";
}
}