home
/
zktecojo
/
public_html
/
app
/
controllers
/
admin
➕ New
📤 Upload
✎ Editing:
ProductController.php
← Back
<?php class ProductController extends BaseController { public function __construct(){ $this->is_admin_login(); parent::__construct(); } public function index(){ $priority_update=0; if(Input::get('btnsubmitpriority')==true){ if(@$_POST['prd_priority']==true){ //print_r($_POST['prd_priority']);exit; foreach(@$_POST['prd_priority'] as $getid=>$value){ $this->dataupdate['product_priority']=$value; DB::table('products')->where('product_id', '=',$getid)->update($this->dataupdate); $this->data['messages'] =$this->custom_message('product priority updated successfully','success'); } $priority_update=1; } } $this->data['productsList']= DB::table('products as P') ->join('pages as pg','pg.page_id','=','P.product_cat_id') ->orderBy('P.product_priority','desc') ->get(); if($priority_update==1){ return Redirect::back(); } // dd($this->data['productsList']); return View::make('admin.products.list',$this->data); } public function show_products($id){ //echo 'shamjas';exit; $this->data['messages']=''; $this->data['rsproducts']= DB::table('products') ->where('product_id','=',$id) ->first(); $relat_array=$this->data['rsproducts']->related_products; $this->data['relatedProduct']= DB::table('product_related') ->select('pr_related_cat_id') ->groupBy('pr_related_cat_id') ->get(); //print_r($this->data['relatedProduct']);exit; $this->data['productGallery']= DB::table('product_gallery as pg') ->where('pg.pg_product_id','=',$id) ->get(); $this->data['productPackages']= DB::table('product_packages as pp') ->where('pp.pp_product_id','=',$id) ->get(); $this->data['productPdfList']= DB::table('product_pdf_download as pd') ->where('pd.ppd_product_id','=',$id) ->get(); //dd(DB::getQueryLog()); $this->data['pdf_cat_list'] = DB::table('pdf_category')->where('pc_status','=',1)->where('pc_cat_flag','=',1)->orderBy('pc_priority','asc')->get(); $this->data['productRelate']= DB::table('products as p') ->join('product_related as pr','pr.pr_product_id','=','p.product_id') ->where('p.product_id','=',$id) ->groupBy('pr.pr_product_id') ->get(); //echo '<pre>', print_r($this->data['productGallery']);exit(); return View::make('admin.products.edit',$this->data); } public function create(){ $this->data['messages']=''; if(Input::get('createbtnsubmit')){ $maxpriority=DB::table('products')->max('product_priority'); //echo $slug=$this->get_unique_product_slug(Str::slug(trim(Input::get('product_title')) ));exit; $insertDatas = array( 'product_cat_id' =>Input::get('product_cat'), 'product_title' =>Input::get('product_title'), 'product_content' =>Input::get('product_content'), 'product_short_content' =>Input::get('product_short_desc'), 'product_datetime' =>date('Y-m-d H:i:s'), //'product_alias' =>Str::slug(Input::get('product_title'))."-".date('Y-m-d'), 'product_alias' =>$slug, 'product_status' =>Input::get('product_status'), 'product_priority' =>$maxpriority+1, 'product_publish_date' =>date('Y-m-d',strtotime(Input::get('product_publish_date'))), ); $youtubeLink=Input::get('product_youtube'); if(!empty($youtubeLink)){ parse_str( parse_url( $youtubeLink, PHP_URL_QUERY ), $my_array_of_vars ); $insertDatas['product_youtube_link'] =Input::get('product_youtube'); $insertDatas['product_youtube_id'] =$my_array_of_vars['v']; } $file = Input::file('product_image_name'); if(!empty($file)){ if($file->getClientMimeType() == 'application/pdf' || $file->getClientMimeType() == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') { $destinationPath = 'assets/uploads/products/file'; if (!empty($file)){ $filename = $file->getClientOriginalName(); if(!empty($filename)){ $upload_success = $file->move($destinationPath, $filename); } $insertDatas['product_configuration_image'] = $filename; } } } /* if($file){ $filename = $this->resize_and_crop_image('product_image_name','assets/uploads/products',array(array('width'=>785,'height'=>416,'folder'=>'recomended'),array('width'=>134,'height'=>104,'folder'=>'small')),null); $insertDatas['product_image_name'] = $filename; } // end file */ DB::table('products')->insert($insertDatas); $this->data['messages'] =$this->custom_message('products Added Successfully','success'); } $this->data['productsMenuList'] = DB::table('pages')->where('page_parent_id','=',8)->where('page_status','=',1)->get(); return View::make('admin.products.add',$this->data); } public function save_product_basic(){ $this->data['messages']=''; if(Input::get('product_title')){ $maxpriority=DB::table('products')->max('product_priority'); $slug=$this->get_unique_product_slug(Str::slug(trim(Input::get('product_title')) )); $insertDatas = array( 'product_cat_id' =>Input::get('product_cat'), 'product_title' =>Input::get('product_title'), 'product_title_arabic' =>Input::get('product_title_arabic'), 'product_short_content' =>Input::get('product_short_desc'), 'product_short_content_arabic' =>Input::get('product_short_desc_arabic'), 'product_datetime' =>date('Y-m-d H:i:s'), //'product_alias' =>Str::slug(Input::get('product_title'))."-".date('Y-m-d'), 'product_alias' =>$slug, 'product_status' =>Input::get('product_status'), 'product_priority' =>$maxpriority+1, 'product_overview' =>Input::get('pgm_overview'), 'product_overview_arabic' =>Input::get('pgm_overview_arabic'), 'product_function' =>Input::get('pgm_function'), 'product_function_arabic' =>Input::get('pgm_function_arabic'), 'product_specification' =>Input::get('pgm_specification'), 'product_specification_arabic' =>Input::get('pgm_specification_arabic'), ); $file = Input::file('product_image_name'); if($file){ $filename = $this->resize_and_crop_image('product_image_name','assets/uploads/products',array(array('width'=>785,'height'=>416,'folder'=>'recomended'),array('width'=>134,'height'=>104,'folder'=>'small')),null); $insertDatas['product_configuration_image'] = $filename; } DB::table('products')->insert($insertDatas); $lastInsertId=DB::getPdo()->lastInsertId(); return Redirect::to('admin/product/show_products/'.$lastInsertId); $this->data['messages'] =$this->custom_message('products Added Successfully','success'); } //echo 'shamk';exit; return View::make('admin.products.add',$this->data); } public function update_product_basic(){ $editID=Input::get('prd_id'); $this->data['messages'] =''; if(Input::get('product_title')){ $slug=$this->get_unique_product_slug(Str::slug(trim(Input::get('product_title')) )); $datasupdate = array( 'product_cat_id' =>Input::get('product_cat'), 'product_title' =>Input::get('product_title'), 'product_title_arabic' =>Input::get('product_title_arabic'), 'product_short_content' =>Input::get('product_short_desc'), 'product_short_content_arabic' =>Input::get('product_short_desc_arabic'), 'product_datetime' =>date('Y-m-d H:i:s'), 'product_alias' =>$slug, 'product_status' =>Input::get('product_status'), 'product_priority' =>Input::get('product_priority'), 'product_overview' =>Input::get('pgm_overview'), 'product_overview_arabic' =>Input::get('pgm_overview_arabic'), 'product_function' =>Input::get('pgm_function'), 'product_function_arabic' =>Input::get('pgm_function_arabic'), 'product_specification' =>Input::get('pgm_specification'), 'product_specification_arabic' =>Input::get('pgm_specification_arabic'), ); $file = Input::file('product_image_name'); if($file){ $filename = $this->resize_and_crop_image('product_image_name','assets/uploads/products',array(array('width'=>785,'height'=>416,'folder'=>'recomended'),array('width'=>134,'height'=>104,'folder'=>'small')),Input::get('product_image_old_name')); $datasupdate['product_configuration_image'] = $filename; } // end file DB::table('products')->where('product_id', '=',$editID)->update($datasupdate); $this->data['messages'] = $this->custom_message('products updated successfully','success'); return Redirect::to('admin/product/show_products/'.$editID); } //$this->data['productsMenuList'] = DB::table('pages')->where('page_parent_id','=',8)->where('page_status','=',1)->get(); $this->data['rsproducts'] = DB::table('products')->where('product_id','=',$editID)->first(); return View::make('admin.products.add',$this->data); } public function update_product_seo(){ $editID=Input::get('prd_id'); $this->data['messages'] =''; if(Input::get('product_seo_title')){ $datasupdate = array( 'product_seo_title' =>Input::get('product_seo_title'), 'product_meta_title' =>Input::get('product_meta_title'), 'product_meta_author' =>Input::get('product_meta_author'), 'product_meta_description' =>Input::get('product_meta_description'), 'product_meta_keyword' =>Input::get('product_meta_keyword'), ); DB::table('products')->where('product_id', '=',$editID)->update($datasupdate); $this->data['messages'] = $this->custom_message('products updated successfully','success'); return Redirect::to('admin/product/show_products/'.$editID); } //$this->data['productsMenuList'] = DB::table('pages')->where('page_parent_id','=',8)->where('page_status','=',1)->get(); $this->data['rsproducts'] = DB::table('products')->where('product_id','=',$editID)->first(); return View::make('admin.products.add',$this->data); } public function update_gallery(){ $editID=Input::get('prd_id'); $this->data['messages'] =''; /* $file = Input::file('gal_name'); echo '<pre>'; print_r($file);exit; */ if(Input::file('gal_name')){ $file = Input::file('gal_name'); if($file){ foreach($file as $filelist){ if(!empty($filelist)){ $filename = $this->mutiple_image_upload($filelist,'assets/uploads/products',array(array('width'=>350,'height'=>386,'folder'=>'recomended'),array('width'=>250,'height'=>228,'folder'=>'small')),Input::get('product_image_old_name')); $insertDatas=array( 'pg_product_id'=>$editID, 'pg_image_name'=>$filename, 'pg_image_date'=>date('Y-m-d H:i:s'), 'pg_image_status'=>1, ); DB::table('product_gallery')->insert($insertDatas); } // end file } // end file } // end file //DB::table('products')->insert($insertDatas); $this->data['messages'] = $this->custom_message('products updated successfully','success'); return Redirect::to('admin/product/show_products/'.$editID.'#fragment-2'); } $this->data['galleryList'] = DB::table('product_gallery')->where('pg_product_id','=',$editID)->get(); $this->data['rsproducts'] = DB::table('products')->where('product_id','=',$editID)->first(); return View::make('admin.products.add',$this->data); } public function update_packages(){ $editID=Input::get('prd_id'); $this->data['messages'] =''; /* $file = Input::file('gal_name'); echo '<pre>'; print_r($file);exit; */ if(Input::file('pack_name')){ $file = Input::file('pack_name'); $labelName=Input::get('pack_label'); $labelNameArabic=Input::get('pack_label_arabic'); $i=0; if($file){ foreach($file as $filelist){ if(!empty($filelist)){ $filename = $this->mutiple_image_upload($filelist,'assets/uploads/products',array(array('width'=>785,'height'=>416,'folder'=>'recomended'),array('width'=>200,'height'=>200,'folder'=>'small')),Input::get('product_image_old_name')); $insertDatas=array( 'pp_product_id'=>$editID, 'pp_name'=>$labelName[$i], 'pp_name_arabic'=>$labelNameArabic[$i], 'pp_image_name'=>$filename, 'pp_image_date'=>date('Y-m-d H:i:s'), 'pp_image_status'=>1, ); DB::table('product_packages')->insert($insertDatas); } // end file $i++; } // end file } // end file //DB::table('products')->insert($insertDatas); $this->data['messages'] = $this->custom_message('products updated successfully','success'); return Redirect::to('admin/product/show_products/'.$editID.'#fragment-3'); } $this->data['galleryList'] = DB::table('product_gallery')->where('pg_product_id','=',$editID)->get(); $this->data['rsproducts'] = DB::table('products')->where('product_id','=',$editID)->first(); return View::make('admin.products.add',$this->data); } public function update_download(){ $editID=Input::get('prd_id'); $this->data['messages'] =''; /* $file = Input::file('pdf_name'); echo '<pre>'; print_r($file);exit; */ if(Input::file('pdf_name')){ $file = Input::file('pdf_name'); $pdf_image = Input::file('pdf_image'); $pdf_cat_name=Input::get('pdf_cat_name'); $pdf_subcat_id=Input::get('pdf_sub_cat'); $pdfName=Input::get('pdf_label'); $pdfName_arabic=Input::get('pdf_label_arabic'); $pdfSize=Input::get('pdf_size'); $pdfDate=Input::get('pdf_date'); $i=0; if($file){ foreach($file as $filelist){ if(!empty($filelist)){ $filename = $this->pdf_upload($filelist,'assets/uploads/products/pdf',Input::get('product_image_old_name')); //$bytes = File::size('assets/uploads/products/pdf/'.$filename); $bytes = File::size('assets/uploads/products/pdf/'.$filename); $bytes=$bytes/1048576; $bytes=round($bytes, 2); $insertDatas=array( 'ppd_product_id'=>$editID, 'ppd_label'=>$pdfName[$i], 'ppd_label_arabic'=>$pdfName_arabic[$i], 'ppd_category_name'=>$pdf_cat_name[$i], 'ppd_size'=>$bytes, 'ppd_subcategory_id'=>$pdf_subcat_id[$i], 'ppd_pdf_name'=>$filename, 'ppd_date'=>date('Y-m-d',strtotime($pdfDate[$i])), 'ppd_status'=>1, ); if(!empty($pdf_image[$i])){ $extension = $pdf_image[$i]->getClientOriginalExtension(); $extensions = array('jpg', 'JPG', 'png' ,'PNG' ,'jpeg' ,'JPEG'); if(in_array($extension,$extensions)){ $pdfimgname = $this->mutiple_image_upload($pdf_image[$i],'assets/uploads/products/pdf/image',array(array('width'=>785,'height'=>416,'folder'=>'recomended'),array('width'=>102,'height'=>132,'folder'=>'small')),Input::get('product_image_old_name')); $insertDatas['ppd_image_name']=$pdfimgname; } } DB::table('product_pdf_download')->insert($insertDatas); } // end file $i++; } // end file } // end file //DB::table('products')->insert($insertDatas); $this->data['messages'] = $this->custom_message('products updated successfully','success'); return Redirect::to('admin/product/show_products/'.$editID.'#fragment-4'); } $this->data['galleryList'] = DB::table('product_gallery')->where('pg_product_id','=',$editID)->get(); $this->data['rsproducts'] = DB::table('products')->where('product_id','=',$editID)->first(); return View::make('admin.products.add',$this->data); } public function load_subcategory(){ $catId=Input::get('cat_id'); $catlist = DB::table('download_subcategory')->where('ds_category_id','=',$catId)->get(); if(!empty($catlist)){ $str= '<div><label>Select Sub Category</label></div>'; $str.= '<select name="pdf_sub_cat[]" class="pdfSubCat" >'; $str.= '<option value="0">Select</option>'; foreach($catlist as $list){ $str.= '<option value="'.$list->ds_id.'">'.$list->ds_name.'</option>'; } $str.= '</select>'; }else{ $str = '<div><label> </label></div>'; $str.= '<div><label>No subcategory found</label></div>'; } echo $str; } public function load_product(){ $productId=Input::get('product'); $piD=Input::get('cat_id'); $pvalue=Input::get('cat_value'); $i=0; //$list=implode(',',$piD);echo $list;EXIT; // PRINT_R($piD);EXIT; //$relatedList=DB::table('product_related')->where('pr_product_id','=',$productId)->get(); $checkedList=DB::table('product_related') ->where('pr_product_id','=',$productId) ->get(); //echo'<pre>'; print_r($checkedList);exit; $productsCollection= DB::table('products as p') ->select('p.product_id','p.product_cat_id','p.product_title','pages.page_name','pg.pg_image_name') ->leftJoin('pages','pages.page_id','=','p.product_cat_id') ->leftJoin('product_gallery as pg',function($join) { $join->on('pg.pg_product_id', '=', 'p.product_id') ->where('pg.pg_base_image', '=',1); }) ->whereIn('p.product_cat_id',$piD) ->get(); //echo'<pre>'; print_r($productsCollection);exit; /* $productsList[]=DB::select(DB::raw("SELECT * FROM products AS p LEFT JOIN pages AS pag ON pag.page_id=p.product_cat_id LEFT JOIN product_gallery AS pg ON pg.pg_product_id=p.product_id AND pg.pg_base_image=1 LEFT JOIN (SELECT group_concat(pr_relate_id) as checked,pr_product_id FROM product_related WHERE pr_product_id =? GROUP BY pr_product_id) AS prd on prd.pr_product_id=p.product_id WHERE p.product_cat_id=?"),array($productId,$list)); */ $i++; //dd(DB::getQueryLog()); $result=array();$i=0; foreach($productsCollection as $list){ //$result[$list->page_name][]=$list; // echo '<pre>';print_r($result);exit; //$result[$list->page_name][]->isChecked ='false'; $list->isChecked ='false'; foreach($checkedList as $raw){ if($raw->pr_relate_id == $list->product_id){ $list->isChecked ='true'; } } $result[$list->page_name][]=$list; } //echo '<pre>';print_r($result);exit; if(!empty($result)){ /* echo '<label>Select Product </label> <select multiple="multiple" name="product_list[]" class="form-control mSelect">'; foreach($productsList as $list){ echo '<option value="'.$list->product_id .'">'.$list->product_title .'</option>'; } echo '</select>'; echo '<script> $(document).ready(function(){ $(".mSelect").multiselect(); }) </script>'; */ echo '<div class="row padding25">'; foreach($result as $key=>$value){ //print_r($list[0]['page_name']);exit; echo '<div><h3>'.$key.'</h3></div>'; echo '<div class="row">'; foreach($value as $smallList){ echo '<div class="col-sm-2"><div class="alignRight"><input type="checkbox" name="product_list[]" '.(($smallList->isChecked=='true')? 'checked="checked"':"").' value="'. $smallList->product_id .'" /><input type="hidden" name="product_cat[]" value="'. $smallList->product_cat_id .'" /></div>'; if(!empty($smallList->pg_image_name)){ echo '<img src="'.asset('assets/uploads/products/'.$smallList->pg_image_name).'" width="100" height="80" />'; }else{ echo '<img src="'.asset('assets/images/no_image.gif').'" width="100" height="80" />'; } echo '<div>'.$smallList->product_title.'</div>'; echo '</div>'; } echo '</div>'; } echo '</div>'; }else{ echo '<label>No product found</label>'; } } public function update_related_products(){ $editID=Input::get('prd_id'); $this->data['messages'] =''; /* $checkedList=DB::table('product_related') ->select(DB::Raw('group_concat(pr_relate_id) as checked ')) ->where('pr_product_id','=',$editID) ->groupBy('pr_product_id') ->first(); */ $insertValue=Input::get('product_list'); if(!empty($insertValue)){ DB::table('product_related')->where('pr_product_id','=',$editID)->delete(); foreach($insertValue as $list=>$val){ $listCat=DB::table('products')->select('product_cat_id')->where('product_id','=',$val)->first(); DB::table('product_related')->insert(array('pr_relate_id'=>$val,'pr_related_cat_id'=>$listCat->product_cat_id,'pr_product_id'=>$editID)); } return Redirect::to('admin/product/show_products/'.$editID.'#fragment-5'); exit; $this->data['messages'] = $this->custom_message('products updated successfully','success'); }else{ //echo 'shamjas';exit; DB::table('product_related')->where('pr_product_id','=',$editID)->delete(); return Redirect::to('admin/product/show_products/'.$editID.'#fragment-5'); exit; } //$this->data['productsMenuList'] = DB::table('pages')->where('page_parent_id','=',8)->where('page_status','=',1)->get(); $this->data['rsproducts'] = DB::table('products')->where('product_id','=',$editID)->first(); return View::make('admin.products.tabs.product_basic_update',$this->data); } public function update_gallery_baseImage(){ $this->data['messages'] =''; $editID=Input::get('prd_id'); $temp = Input::get('deleteImg'); if(Input::get('deleteGal')){ if(!empty($temp)){ $delImgList=Input::get('deleteImg'); foreach($delImgList as $key=>$val){ DB::table('product_gallery')->where('pg_id', '=',$val)->delete(); } } return Redirect::to('admin/product/show_products/'.$editID.'#fragment-2'); }else{ $imageId= Input::get('base_image'); if(Input::get('base_image')){ DB::table('product_gallery')->where('pg_id', '=',$imageId)->update(array('pg_base_image' =>0,)); $datasupdate = array( 'pg_base_image' =>1, ); DB::table('product_gallery')->where('pg_id', '=',$imageId)->update($datasupdate); return Redirect::to('admin/product/show_products/'.$editID.'#fragment-2'); $this->data['messages'] = $this->custom_message('products updated successfully','success'); } } //$this->data['productsMenuList'] = DB::table('pages')->where('page_parent_id','=',8)->where('page_status','=',1)->get(); $this->data['rsproducts'] = DB::table('products')->where('product_id','=',$editID)->first(); return View::make('admin.products.tabs.product_basic_update',$this->data); } public function delete_pack(){ $this->data['messages'] =''; $editID=Input::get('prd_id'); $temp = Input::get('delete_pack'); if(Input::get('deletePack')){ if(!empty( $temp )){ $delImgList=Input::get('delete_pack'); foreach($delImgList as $key=>$val){ DB::table('product_packages')->where('pp_id', '=',$val)->delete(); } } return Redirect::to('admin/product/show_products/'.$editID.'#fragment-3'); } $this->data['rsproducts'] = DB::table('products')->where('product_id','=',$editID)->first(); return View::make('admin.products.tabs.product_basic_update',$this->data); } public function delete_download(){ $this->data['messages'] =''; $editID=Input::get('prd_id'); $temp = Input::get('delete_download'); if(Input::get('deleteDownload')){ if(!empty($temp)){ $delImgList=Input::get('delete_download'); foreach($delImgList as $key=>$val){ DB::table('product_pdf_download')->where('ppd_id', '=',$val)->delete(); } } return Redirect::to('admin/product/show_products/'.$editID.'#fragment-4'); } $this->data['rsproducts'] = DB::table('products')->where('product_id','=',$editID)->first(); return View::make('admin.products.tabs.product_basic_update',$this->data); } public function changestatus($statusID,$currentStatus){ $currentStatus = ($currentStatus==0)?1:0; $currentStatusdatas = array("product_status"=>$currentStatus); DB::table('products')->where('product_id', '=',$statusID)->update($currentStatusdatas); return Redirect::to('admin/product')->with('flash_error','deleted'); } public function delete($deleteID){ if(empty($deleteID)) { return Redirect::to('admin/products');} $productsList = DB::table('products')->where('product_id','=',$deleteID)->get(); foreach($productsList as $products){ if(File::exists('assets/uploads/products/'.$products->product_image_name)){ File::delete('assets/uploads/products/'.$products->product_image_name); File::delete('assets/uploads/products/small/'.$products->product_image_name); File::delete('assets/uploads/products/large/'.$products->product_image_name); } } DB::table('products')->where('product_id', '=',$deleteID)->delete(); $this->data['messages'] = $this->custom_message('Deleted Successfully','success'); return Redirect::to('admin/product')->with('flash_error','deleted'); } public function change_download_category(){ $editID=Input::get('prd_id'); $subcat=Input::get('subcat_id'); $cat=Input::get('cat_id'); $editStatusdatas = array( "ppd_category_name"=>$cat, "ppd_subcategory_id"=>$subcat, ); DB::table('product_pdf_download')->where('ppd_id', '=',$editID)->update($editStatusdatas); echo '<span style="color:red">updated succesfuly</span>'; } }
💾 Save Changes
Cancel
📤 Upload File
×
Select File
Upload
Cancel
➕ Create New
×
Type
📄 File
📁 Folder
Name
Create
Cancel
✎ Rename Item
×
Current Name
New Name
Rename
Cancel
🔐 Change Permissions
×
Target File
Permission (e.g., 0755, 0644)
0755
0644
0777
Apply
Cancel