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_upload_coupon_csv() { $this->layout = "backend/product"; $this->set("title_for_layout", UPLOAD_COUPON); App::import("Model", "Category"); $this->Category = new Category(); $fields = array("Category.id", "Category.title"); $category_data = $this->Category->find("all", array("conditions" => array("Category.is_deleted" => 0), "order" => "Category.title asc", "fields" => $fields, "contain" => array("Product" => array("conditions" => array("Product.is_deleted" => 0), 'fields' => array("Product.id", "Product.title"))))); $this->set("category_data", $category_data); if (!empty($this->data)) { $errors = array(); if ($this->data['Coupon']['product_id'] != "" && $this->data['Coupon']['category_id'] != "" && $this->data['Coupon']['category_title'] != "" && $this->data['Coupon']['csv_file']['name'] != "") { App::import("Component", "Upload"); $upload = new UploadComponent(); $file = $this->data['Coupon']['csv_file']; $name = $this->data['Coupon']['csv_file']['name']; $path_info = pathinfo($this->data['Coupon']['csv_file']['name']); $file_extension = strtolower($path_info['extension']); if ($file_extension == 'csv') { $directory_path = $this->create_directory("coupon_csv_upload"); $file_name = $upload->upload($file, $directory_path, $name, null, array($file_extension)); if ($file_name) { $result = $this->Coupon->save_csv($directory_path . $name, $this->data); if ($result) { unlink($directory_path . $name); $this->Session->setFlash(RECORD_SAVE, 'message/green'); $this->redirect(array("controller" => "coupons", "action" => "upload_coupon_csv", "admin" => true)); } else { unlink($directory_path . $name); $errors['Product'][] = WRONG_PRODUCT_CATEGORY; $this->set("errors", $errors); } } else { $errors['Product'][] = NOT_UPLODED_CSV; $this->set("errors", $errors); } } else { $errors['Product'][] = ERR_COUPON_CSV; $this->set("errors", $errors); } } else { if ($this->data['Coupon']['product_id'] == "" && $this->data['Coupon']['category_id'] == "") { $errors['Product'][] = ERR_PRODUCT_CATEGORY_EMPTY; } if ($this->data['Coupon']['csv_file']['name'] == "") { $errors['Product'][] = ERR_COUPON_CSV; } } $this->set("errors", $errors); } }