function admin_my_profile($user_id = null)
 {
     $this->layout = "backend/backend";
     $this->set("title_for_layout", MY_PROFILE);
     $user_id = !empty($user_id) ? DECRYPT_DATA($user_id) : $this->Session->read("Auth.User.id");
     App::import("Model", "User");
     $this->User = new User();
     if (!empty($this->data)) {
         $data = $this->data;
         $data['User']['id'] = DECRYPT_DATA($data['User']['id']);
         $data['UserProfile']['id'] = DECRYPT_DATA($data['UserProfile']['id']);
         $errors = $this->User->validate_add_user($data);
         if (count($errors) == 0) {
             $user_id = $this->User->save_user($data);
             if ($user_id != "") {
                 $this->Session->setFlash(RECORD_SAVE, 'message/green');
                 $this->redirect(array('controller' => 'users', 'action' => 'user_listing', "admin" => true));
             } else {
                 $this->Session->setFlash(RECORD_ERROR, 'message/red');
                 $this->redirect(array('controller' => 'dashboards', 'action' => 'my_profile', ENCRYPT_DATA($this->data['User']['id']), "admin" => true));
             }
         } else {
             $this->set("errors", $errors);
         }
     } else {
         if (isset($user_id)) {
             if ($this->is_id_exist($user_id, "User")) {
                 $this->User->id = $user_id;
                 $data = $this->User->read();
                 $data['User']['id'] = ENCRYPT_DATA($data['User']['id']);
                 $data['UserProfile']['id'] = ENCRYPT_DATA($data['UserProfile']['id']);
                 $this->data = $data;
             } else {
                 $this->Session->setFlash(NOT_FOUND_ERROR, 'message/red');
                 $this->redirect(array('controller' => 'users', 'action' => 'user_listing', 'admin' => true));
                 exit;
             }
         }
     }
 }
 function admin_edit_role($role_id = null)
 {
     $this->layout = "backend/backend";
     $this->set("title_for_layout", EDIT_ROLE);
     $role_id = DECRYPT_DATA($role_id);
     App::import("Model", "Permission");
     $this->Permission = new Permission();
     $permissions = $this->Permission->get_all_permissions();
     $this->set('permissions', $permissions);
     App::import("Model", "Role");
     $this->Role = new Role();
     if (!empty($this->data)) {
         $data = $this->data;
         $data['Role']['id'] = DECRYPT_DATA($data['Role']['id']);
         $errors = $this->Role->validate_add_role($data);
         if (count($errors) == 0) {
             if ($this->Role->save($data)) {
                 $role_id = $data['Role']['id'];
                 $this->Session->setFlash(RECORD_SAVE, 'message/green');
             }
             App::import('Model', 'RolePermission');
             $this->RolePermission = new RolePermission();
             $permission_data['RolePermission']['role_id'] = $role_id;
             $this->RolePermission->deleteAll(array("role_id" => $role_id));
             foreach ($this->data['RolePermission']['permission_id'] as $permisson_id) {
                 $permission_data['RolePermission']['permission_id'] = $permisson_id;
                 $this->RolePermission->create();
                 $this->RolePermission->save($permission_data);
             }
             $this->redirect(array("controller" => 'users', "action" => "role_listing", 'admin' => true));
             exit;
         } else {
             $this->set("errors", $errors);
         }
     } else {
         if (isset($role_id)) {
             if ($this->is_id_exist($role_id, "Role")) {
                 $this->Role->id = $role_id;
                 $data = $this->Role->read();
                 $data['Role']['id'] = ENCRYPT_DATA($data['Role']['id']);
                 $this->data = $data;
             } else {
                 $this->Session->setFlash(NOT_FOUND_ERROR, 'message/red');
                 $this->redirect(array('controller' => 'users', 'action' => 'role_listing', 'admin' => true));
                 exit;
             }
         }
     }
 }
 function admin_edit($vendor_id = null)
 {
     $vendor_id = DECRYPT_DATA($vendor_id);
     $this->layout = 'backend/backend';
     $this->set("title_for_layout", EDIT_VENDOR);
     if (!empty($this->data)) {
         $data = $this->data;
         $data['Vendor']['id'] = DECRYPT_DATA($data['Vendor']['id']);
         $errors = $this->Vendor->validate_data($data);
         if (count($errors) == 0) {
             if ($this->data['Vendor']['image']['name'] != "") {
                 App::import("Component", "Upload");
                 $upload = new UploadComponent();
                 $allowed_ext = array('jpg', 'jpeg', 'gif', 'png', 'JPG', 'JPEG', 'GIF', 'PNG');
                 $path_info = pathinfo($this->data['Vendor']['image']['name']);
                 $file_extension = strtolower($path_info['extension']);
                 if (in_array($file_extension, $allowed_ext)) {
                     $file = $this->data['Vendor']['image'];
                     $thumb_directory_path = $this->create_directory("vendor_image_thumb");
                     $actual_directory_path = $this->create_directory("vendor_image_actual");
                     $filename = str_replace(array(" ", "."), "", md5(microtime())) . "." . $path_info['extension'];
                     $rules['type'] = 'resizecrop';
                     $rules['size'] = array(75, 50);
                     if (file_exists($thumb_directory_path . $data['Vendor']['previous_image'])) {
                         unlink($thumb_directory_path . $data['Vendor']['previous_image']);
                     }
                     if (file_exists($actual_directory_path . $data['Vendor']['previous_image'])) {
                         unlink($actual_directory_path . $data['Vendor']['previous_image']);
                     }
                     $file_name = $upload->upload($file, $thumb_directory_path, $filename, $rules, $allowed_ext);
                     $file_name = $upload->upload($file, $actual_directory_path, $filename, null, $allowed_ext);
                     if ($file_name) {
                         unset($data['Vendor']['previous_image']);
                         $data['Vendor']['image'] = $filename;
                         if ($this->Vendor->save($data)) {
                             $this->Session->setFlash(RECORD_SAVE, 'message/green');
                             $this->redirect(array('controller' => "vendors", 'action' => 'list', 'admin' => true));
                         } else {
                             $this->Session->setFlash(RECORD_ERROR, 'message/red');
                             $this->redirect($this->referer());
                         }
                     }
                 } else {
                     $errors['image'][] = ERR_IMAGE_TYPE;
                 }
             } else {
                 unset($data['Vendor']['image']);
                 unset($data['Vendor']['previous_image']);
                 if ($this->Vendor->save($data)) {
                     $this->Session->setFlash(RECORD_SAVE, 'message/green');
                     $this->redirect(array("controller" => "vendors", "action" => "list", "admin" => true));
                 } else {
                     $this->Session->setFlash(RECORD_ERROR, 'message/red');
                     $this->redirect(array("controller" => "vendors", "action" => "edit", $this->data['Vendor']['id'], "admin" => true));
                 }
             }
         }
         $this->set("errors", $errors);
     } else {
         if (isset($vendor_id)) {
             if ($this->is_id_exist($vendor_id, "Vendor")) {
                 $this->Vendor->id = $vendor_id;
                 $data = $this->Vendor->read();
                 $data['Vendor']['id'] = ENCRYPT_DATA($data['Vendor']['id']);
                 $this->data = $data;
             } else {
                 $this->Session->setFlash(NOT_FOUND_ERROR, 'message/red');
                 $this->redirect(array("controller" => "products", 'action' => 'list', 'admin' => true));
                 exit;
             }
         }
     }
 }
 function admin_search($action = null, $id = null)
 {
     $this->layout = "";
     $this->autoRender = false;
     if ($this->RequestHandler->isAjax()) {
         //if(1){
         $user = $this->Auth->user();
         if (!empty($action)) {
             if ($user['role_id'] == 2 || $user['role_id'] == 3) {
                 $dealer_id = $user['id'];
                 $Dealerlimit = $this->admin_couponlimit($dealer_id);
                 if (is_array($Dealerlimit) && !empty($Dealerlimit) && $Dealerlimit['action'] && $Dealerlimit['price_coupon_limit'] != 0) {
                     $price_coupon_limit = $Dealerlimit['price_coupon_limit'];
                     switch ($action) {
                         case 'category':
                             $set_categorydata = array();
                             if (!empty($id)) {
                                 $vendor_id = DECRYPT_DATA($id);
                                 App::import("Model", "Vendor");
                                 $this->Vendor = new Vendor();
                                 $validID = $this->Vendor->find('count', array("fields" => array('id'), "conditions" => array("Vendor.id" => $vendor_id)));
                                 if ($validID > 0) {
                                     App::import("Model", "Category");
                                     $this->Category = new Category();
                                     App::import("Model", "Product");
                                     $this->Product = new Product();
                                     $product_join = array('table' => 'products', 'alias' => 'Product', 'type' => 'INNER', 'conditions' => array('Product.category_id = Category.id', 'Product.vendor_id' => $vendor_id, 'Product.is_active' => '1', 'Product.is_deleted' => '0'));
                                     $Categorydata = $this->Category->find('all', array('fields' => array('Category.id,Category.title'), 'conditions' => array("Category.title <= {$price_coupon_limit}", 'Category.is_active' => '1', 'Category.is_deleted' => '0'), 'recursive' => 0, 'joins' => array($product_join)));
                                     $Categorydata = Set::extract('/Category/.', $Categorydata);
                                     $result = array_map("unserialize", array_unique(array_map("serialize", $Categorydata)));
                                     $counter = 0;
                                     foreach ($result as $key => $value) {
                                         $set_categorydata[$counter]['key'] = ENCRYPT_DATA($value['id']);
                                         $set_categorydata[$counter]['value'] = $value['title'];
                                         $counter++;
                                     }
                                 }
                             }
                             return json_encode($set_categorydata);
                             break;
                     }
                 }
             }
         }
     } else {
         $this->redirect(array("controller" => "dashboards", "action" => "unauthorize", "admin" => true));
     }
 }
 function admin_edit_category($category_id = null)
 {
     $category_id = DECRYPT_DATA($category_id);
     $this->layout = 'backend/backend';
     $this->set("title_for_layout", EDIT_CATEGORY);
     if (!empty($this->data)) {
         $data = $this->data;
         $data['Category']['id'] = DECRYPT_DATA($data['Category']['id']);
         $errors = $this->Category->validate_add_category($data['Category']);
         if (count($errors) == 0) {
             if ($this->Category->save($data)) {
                 $this->Session->setFlash(RECORD_SAVE, 'message/green');
                 $this->redirect(array("controller" => "categories", "action" => "listing", "admin" => true));
             } else {
                 $this->Session->setFlash(RECORD_ERROR, 'message/red');
                 $this->redirect(array("controller" => "categories", "action" => "edit_category", $this->data['Category']['id'], "admin" => true));
             }
         } else {
             $this->set("errors", $errors);
         }
     } else {
         if (isset($category_id)) {
             if ($this->is_id_exist($category_id, "Category")) {
                 $this->Category->id = $category_id;
                 $data = $this->Category->read();
                 $data['Category']['id'] = ENCRYPT_DATA($data['Category']['id']);
                 $this->data = $data;
             } else {
                 $this->Session->setFlash(NOT_FOUND_ERROR, 'message/red');
                 $this->redirect(array("controller" => "categories", 'action' => 'listing', 'admin' => true));
                 exit;
             }
         }
     }
 }
 function admin_edit($coupon_id = null)
 {
     $coupon_id = DECRYPT_DATA($coupon_id);
     $this->layout = 'backend/backend';
     $this->set("title_for_layout", EDIT_COUPON);
     $category_list = $this->find_categories_list();
     $this->set("category_list", $category_list);
     if (!empty($this->data)) {
         $data = $this->data;
         $data['Coupon']['id'] = DECRYPT_DATA($data['Coupon']['id']);
         $errors = $this->Coupon->validate_data($data['Coupon']);
         if (count($errors) == 0) {
             $result = $this->Coupon->save_data($data);
             if ($result) {
                 $this->Session->setFlash(RECORD_SAVE, 'message/green');
                 $this->redirect(array("controller" => "coupons", "action" => "list", "admin" => true));
             } else {
                 $this->Session->setFlash(RECORD_ERROR, 'message/red');
                 $this->redirect(array("controller" => "coupons", "action" => "edit", $this->data['Coupon']['id'], "admin" => true));
             }
         } else {
             $this->set("errors", $errors);
         }
     } else {
         if (isset($coupon_id)) {
             if ($this->is_id_exist($coupon_id, "Coupon")) {
                 $this->Coupon->id = $coupon_id;
                 $data = $this->Coupon->read();
                 $data['Coupon']['id'] = ENCRYPT_DATA($data['Coupon']['id']);
                 $this->data = $data;
                 $this->set("product_options", $this->find_product_list($this->data['Coupon']['product_id']));
             } else {
                 $this->Session->setFlash(NOT_FOUND_ERROR, 'message/red');
                 $this->redirect(array("controller" => "products", 'action' => 'list', 'admin' => true));
                 exit;
             }
         }
     }
 }
 function admin_edit_cms_page($cms_page_id = null)
 {
     $cms_page_id = DECRYPT_DATA($cms_page_id);
     $this->layout = 'backend/backend';
     $this->set("title_for_layout", EDIT_CMS_PAGE);
     if (!empty($this->data)) {
         App::import("Model", "CmsPage");
         $this->CmsPage = new CmsPage();
         $data = $this->data;
         $data['CmsPage']['id'] = DECRYPT_DATA($data['CmsPage']['id']);
         $errors = $this->CmsPage->valid_edit_cms($data);
         if (count($errors) == 0) {
             /* if((($data['CmsPage']['slug'] == 'home-1') || ($data['CmsPage']['slug'] == 'home-2') || ($data['CmsPage']['slug'] == 'home-3') || ($data['CmsPage']['slug'] == 'home-4')) && ($data['CmsPage']['image']['name'] != "")){
             				App::import("Component","Upload");
             				$upload = new UploadComponent();
             				$allowed_ext = array('jpg','jpeg','gif','png','JPG','JPEG','GIF','PNG');
             				$path_info = pathinfo($this->data['CmsPage']['image']['name']);
             				$file_extension = strtolower($path_info['extension']);
             				
             				if(in_array($file_extension,$allowed_ext)){
             					$file = $this->data['CmsPage']['image'];
             					$filename = str_replace(array(" ","."),"",md5(microtime())).".".$file_extension;
             					$image_path = $this->create_directory("cms_photos");
             					$file_name = $upload->upload($file,$image_path,$filename,null,$allowed_ext);
             					if($data['CmsPage']['previous_image'] != ""){
             						unlink($image_path.$data['CmsPage']['previous_image']);
             					}
             					if($file_name){
             						unset($data['CmsPage']['slug']);
             						$data['CmsPage']['image'] = $filename;
             						$this->CmsPage->save($data);
             						$this->Session->setFlash(RECORD_SAVE, 'message/green');
             						$this->redirect(array("controller"=>"settings","action"=>"admin_cms_list","admin"=>true));
             					}
             				}else{
             				    $errors['image'][] = ERR_CMS_IMAGE_TYPE;
             				}
             			}else{
             			
             				unset($data['CmsPage']['image']);
             			*/
             unset($data['CmsPage']['slug']);
             if ($this->CmsPage->save($data)) {
                 $this->Session->setFlash(RECORD_SAVE, 'message/green');
                 $this->redirect(array("controller" => "settings", "action" => "admin_cms_list", "admin" => true));
             } else {
                 $this->Session->setFlash(RECORD_ERROR, 'message/red');
                 $this->redirect(array("controller" => "coupons", "action" => "edit", $this->data['CmsPage']['id'], "admin" => true));
             }
             //}
         }
         $this->set("errors", $errors);
     } else {
         if (isset($cms_page_id)) {
             if ($this->is_id_exist($cms_page_id, "CmsPage")) {
                 $this->CmsPage->id = $cms_page_id;
                 $data = $this->CmsPage->read();
                 $data['CmsPage']['id'] = ENCRYPT_DATA($data['CmsPage']['id']);
                 $this->data = $data;
             } else {
                 $this->Session->setFlash(NOT_FOUND_ERROR, 'message/red');
                 $this->redirect(array("controller" => "coupons", 'action' => 'admin_cms_list', 'admin' => true));
                 exit;
             }
         }
     }
 }
 function admin_edit($vendor_id = null)
 {
     $vendor_id = DECRYPT_DATA($vendor_id);
     $this->layout = 'backend/backend';
     $this->set("title_for_layout", EDIT_VENDOR);
     if (!empty($this->data)) {
         $data = $this->data;
         $data['Vendor']['id'] = DECRYPT_DATA($data['Vendor']['id']);
         $errors = $this->Vendor->validate_data($data);
         if (count($errors) == 0) {
             if ($this->Vendor->save($data)) {
                 $this->Session->setFlash(RECORD_SAVE, 'message/green');
                 $this->redirect(array("controller" => "vendors", "action" => "list", "admin" => true));
             } else {
                 $this->Session->setFlash(RECORD_ERROR, 'message/red');
                 $this->redirect(array("controller" => "vendors", "action" => "edit", $this->data['Vendor']['id'], "admin" => true));
             }
         } else {
             $this->set("errors", $errors);
         }
     } else {
         if (isset($vendor_id)) {
             if ($this->is_id_exist($vendor_id, "Vendor")) {
                 $this->Vendor->id = $vendor_id;
                 $data = $this->Vendor->read();
                 $data['Vendor']['id'] = ENCRYPT_DATA($data['Vendor']['id']);
                 $this->data = $data;
             } else {
                 $this->Session->setFlash(NOT_FOUND_ERROR, 'message/red');
                 $this->redirect(array("controller" => "products", 'action' => 'list', 'admin' => true));
                 exit;
             }
         }
     }
 }
 function admin_edit_product($product_id = null)
 {
     $product_id = DECRYPT_DATA($product_id);
     $this->layout = 'backend/backend';
     $this->set("title_for_layout", EDIT_PRODUCT);
     $category_list = $this->find_categories_list();
     $this->set("category_list", $category_list);
     $vendor_list = $this->find_vendor_listing();
     $this->set("vendor_list", $vendor_list);
     if (!empty($this->data)) {
         $data = $this->data;
         $data['Product']['id'] = DECRYPT_DATA($data['Product']['id']);
         $errors = $this->Product->validate_add_product($data['Product']);
         if (count($errors) == 0) {
             $voucher_value['Category']['title'] = $data["Product"]['voucher_value'];
             App::import("Model", "Category");
             $this->Category = new Category();
             $check_title = $this->Category->find('first', array("recursive" => -1, "fields" => array("id"), "conditions" => array("Category.title" => $voucher_value['Category']['title'])));
             if (!empty($check_title)) {
                 $data["Product"]['category_id'] = $check_title['Category']['id'];
             } else {
                 $this->Category->save($voucher_value);
                 $data["Product"]['category_id'] = $this->Category->getLastInsertId();
             }
             if ($this->Product->save($data)) {
                 $this->Session->setFlash(RECORD_SAVE, 'message/green');
                 $this->redirect(array("controller" => "products", "action" => "listing", "admin" => true));
             } else {
                 $this->Session->setFlash(RECORD_ERROR, 'message/red');
                 $this->redirect(array("controller" => "products", "action" => "edit_product", $this->data['Product']['id'], "admin" => true));
             }
         } else {
             $this->set("errors", $errors);
         }
     } else {
         if (isset($product_id)) {
             if ($this->is_id_exist($product_id, "Product")) {
                 $this->Product->id = $product_id;
                 $this->Product->recursive = -1;
                 $data = $this->Product->read();
                 $data['Product']['id'] = ENCRYPT_DATA($data['Product']['id']);
                 $this->data = $data;
             } else {
                 $this->Session->setFlash(NOT_FOUND_ERROR, 'message/red');
                 $this->redirect(array("controller" => "products", 'action' => 'listing', 'admin' => true));
                 exit;
             }
         }
     }
 }
Beispiel #10
0
 function admin_edit_cms_page($cms_page_id = null)
 {
     $cms_page_id = DECRYPT_DATA($cms_page_id);
     $this->layout = 'backend/backend';
     $this->set("title_for_layout", EDIT_CMS_PAGE);
     if (!empty($this->data)) {
         App::import("Model", "CmsPage");
         $this->CmsPage = new CmsPage();
         $data = $this->data;
         $data['CmsPage']['id'] = DECRYPT_DATA($data['CmsPage']['id']);
         $errors = $this->CmsPage->valid_edit_cms($data);
         if (count($errors) == 0) {
             if ($this->CmsPage->save($data)) {
                 $this->Session->setFlash(RECORD_SAVE, 'message/green');
                 $this->redirect(array("controller" => "settings", "action" => "admin_cms_list", "admin" => true));
             } else {
                 $this->Session->setFlash(RECORD_ERROR, 'message/red');
                 $this->redirect(array("controller" => "coupons", "action" => "edit", $this->data['CmsPage']['id'], "admin" => true));
             }
         }
         $this->set("errors", $errors);
     } else {
         if (isset($cms_page_id)) {
             if ($this->is_id_exist($cms_page_id, "CmsPage")) {
                 $this->CmsPage->id = $cms_page_id;
                 $data = $this->CmsPage->read();
                 $data['CmsPage']['id'] = ENCRYPT_DATA($data['CmsPage']['id']);
                 $this->data = $data;
             } else {
                 $this->Session->setFlash(NOT_FOUND_ERROR, 'message/red');
                 $this->redirect(array("controller" => "coupons", 'action' => 'admin_cms_list', 'admin' => true));
                 exit;
             }
         }
     }
 }