public function edit_product($id = null, $product_name = null) { $result = array(); $product = array(); $valid = true; $date_posted = ""; if (!$this->Auth->loggedIn() || $this->shop_count == 0) { $this->redirect(Router::url('/', true) . strtolower($this->default_language_id) . "/"); } $this->loadModel("Shop"); $shop = $this->Shop->find('first', array('conditions' => array('Shop.sh_u_id_created' => $this->user_front["id"]))); $this->loadModel("Product"); $product = $this->Product->find('first', array('conditions' => array('Product.id' => $id), 'recursive' => 1)); if ($shop["Shop"]["id"] != $product["Product"]["id_shop"]) { $this->redirect(Router::url('/', true)); } //PENDING DELETE DI TEMPAK if ($product["Product"]["pr_active"] == 9 || $product["Product"]["pr_active"] == 0) { $this->redirect(Router::url('/', true)); } if (!$this->request->data) { $this->request->data = $product; /*LOAD SUB CATEGORY */ $this->loadModel("SubcategoryDetail"); $subcategory = $this->SubcategoryDetail->find('list', array('fields' => array('SubcategoryDetail.sctd_sct_id', 'SubcategoryDetail.sctd_title'), 'conditions' => array('SubcategoryDetail.sctd_active' => 1, 'SubcategoryDetail.sctd_language' => $this->default_language_id, 'subcategory_header.id_category' => $this->request->data["Product"]["pr_category"]), 'recursive' => 0, 'order' => array('SubcategoryDetail.sctd_title' => 'ASC'))); $subcategory[0] = "-"; asort($subcategory); $this->set('subcategory', $subcategory); $this->loadModel("Subcategorysub"); $subcategorysub = $this->Subcategorysub->find('list', array('fields' => array('subcategorysub_detail_many.sctsd_scts_id', 'subcategorysub_detail_many.sctsd_title'), 'joins' => array("LEFT JOIN `ca_subcategorysub_detail` AS `subcategorysub_detail_many` ON `Subcategorysub`.`id` = `subcategorysub_detail_many`.`sctsd_scts_id`"), 'conditions' => array('Subcategorysub.id_subcategory' => $this->request->data["Product"]["pr_sub_category"], 'subcategorysub_detail_many.sctsd_active' => 1, 'subcategorysub_detail_many.sctsd_language' => $this->default_language_id), 'order' => array('subcategorysub_detail_many.sctsd_title' => 'ASC'))); $subcategorysub[0] = "-"; asort($subcategorysub); $this->set('subcategorysub', $subcategorysub); if ($this->request->data["Product"]["pr_discount_date"] != 0) { $date_posted = date('m/d/Y', strtotime($this->request->data["Product"]["pr_discount_date"])); } foreach ($this->all_language as $all_language_single) { foreach ($product["product_detail_many"] as $product_detail_single) { if ($product_detail_single["pd_language"] == $all_language_single["Language"]["lg_code"]) { $product["pd_name_" . $all_language_single["Language"]["lg_code"]] = $product_detail_single["pd_name"]; $product["pd_description_" . $all_language_single["Language"]["lg_code"]] = $product_detail_single["pd_description"]; $product["pd_tags_" . $all_language_single["Language"]["lg_code"]] = $product_detail_single["pd_tags"]; } } } } /*LOAD CATEGORY */ $this->loadModel("CategoryDetail"); $category = $this->CategoryDetail->find('list', array('fields' => array('CategoryDetail.ctd_ct_id', 'CategoryDetail.ctd_title'), 'conditions' => array('CategoryDetail.ctd_active' => 1, 'CategoryDetail.ctd_language' => $this->default_language_id), 'order' => array('CategoryDetail.ctd_title' => 'ASC'))); $this->set('category', $category); if ($this->request->is(array('post', 'put'))) { /*THUMB PIC*/ $filename_product_thumbnail = $this->request->data['Document']['product_thumbnail']['name']; $dirname_product_thumbnail = dirname($_SERVER['SCRIPT_FILENAME']) . '/upload/shop/product/'; if (!empty($filename_product_thumbnail)) { $allowed = $this->allowed; $ext = pathinfo($filename_product_thumbnail, PATHINFO_EXTENSION); if (!in_array($ext, $allowed)) { $valid = false; $result["error_product_thumbnail"] = "Only gif, png and jpg allowed"; } } /*PRODUCT GALLERY 1*/ $filename_product_gallery_1 = $this->request->data['Document']['product_gallery_1']['name']; $dirname_product_gallery = dirname($_SERVER['SCRIPT_FILENAME']) . '/upload/shop/product/'; if (!empty($filename_product_gallery_1)) { $allowed = $this->allowed; $ext = pathinfo($filename_product_gallery_1, PATHINFO_EXTENSION); if (!in_array($ext, $allowed)) { $valid = false; $result["error_product_gallery_1"] = "Only gif, png and jpg allowed"; } } /*PRODUCT GALLERY 2*/ $filename_product_gallery_2 = $this->request->data['Document']['product_gallery_2']['name']; $dirname_product_gallery = dirname($_SERVER['SCRIPT_FILENAME']) . '/upload/shop/product/'; if (!empty($filename_product_gallery_2)) { $allowed = $this->allowed; $ext = pathinfo($filename_product_gallery_2, PATHINFO_EXTENSION); if (!in_array($ext, $allowed)) { $valid = false; $result["error_product_gallery_2"] = "Only gif, png and jpg allowed"; } } /*PRODUCT GALLERY 3*/ $filename_product_gallery_3 = $this->request->data['Document']['product_gallery_3']['name']; $dirname_product_gallery = dirname($_SERVER['SCRIPT_FILENAME']) . '/upload/shop/product/'; if (!empty($filename_product_gallery_3)) { $allowed = $this->allowed; $ext = pathinfo($filename_product_gallery_3, PATHINFO_EXTENSION); if (!in_array($ext, $allowed)) { $valid = false; $result["error_product_gallery_3"] = "Only gif, png and jpg allowed"; } } /*PRODUCT GALLERY 4*/ $filename_product_gallery_4 = $this->request->data['Document']['product_gallery_4']['name']; $dirname_product_gallery = dirname($_SERVER['SCRIPT_FILENAME']) . '/upload/shop/product/'; if (!empty($filename_product_gallery_4)) { $allowed = $this->allowed; $ext = pathinfo($filename_product_gallery_4, PATHINFO_EXTENSION); if (!in_array($ext, $allowed)) { $valid = false; $result["error_product_gallery_4"] = "Only gif, png and jpg allowed"; } } /*PRODUCT GALLERY 5*/ $filename_product_gallery_5 = $this->request->data['Document']['product_gallery_5']['name']; $dirname_product_gallery = dirname($_SERVER['SCRIPT_FILENAME']) . '/upload/shop/product/'; if (!empty($filename_product_gallery_5)) { $allowed = $this->allowed; $ext = pathinfo($filename_product_gallery_5, PATHINFO_EXTENSION); if (!in_array($ext, $allowed)) { $valid = false; $result["error_product_gallery_5"] = "Only gif, png and jpg allowed"; } } /* MAX > MIN */ // if ($this->request->data["Product"]["pr_max_order"] < $this->request->data["Product"]["pr_min_order"]){ // $result["error_min_order"] = "Max Order must be greater than min order"; // $valid = false; // } /* BULK ORDER */ //if ($this->request->data["Product"]["pr_bulk_order"] < $this->request->data["Product"]["pr_min_order"]){ //$result["error_bulk_order"] = "Bulk Order must be greater than min order"; //$valid = false; //} /* hapus minimum order */ if ($this->request->data["Product"]["pr_stock"] < $this->min_stock) { $result["error_stock"] = "Stock minimum is <strong>{$this->min_stock}</strong>"; $valid = false; } if (strlen(trim($_POST["pd_title_" . $this->default_language["Language"]["lg_code"]])) <= 0) { $valid = false; } if ($valid) { /*PRODUCT THUMBNAIL*/ if (!empty($filename_product_thumbnail)) { if (file_exists(WWW_ROOT . $product['Product']['pr_image'])) { unlink(WWW_ROOT . $product['Product']['pr_image']); } /* HAPUS THUMBNAIL */ if (file_exists(WWW_ROOT . "upload/shop/product/thumbnail/" . basename($product['Product']['pr_image']))) { unlink(WWW_ROOT . "upload/shop/product/thumbnail/" . basename($product['Product']['pr_image'])); } /* HAPUS THUMBNAIL */ if (file_exists(WWW_ROOT . "upload/shop/product/thumbnail-mini/" . basename($product['Product']['pr_image']))) { unlink(WWW_ROOT . "upload/shop/product/thumbnail-mini/" . basename($product['Product']['pr_image'])); } $extension = pathinfo($filename_product_thumbnail, PATHINFO_EXTENSION); $filename_new = $this->user_front["id"] . date('dmyHis') . "_thumb." . $extension; move_uploaded_file($this->data['Document']['product_thumbnail']['tmp_name'], $dirname_product_thumbnail . $filename_new); $pr_image = "upload/shop/product/" . $filename_new; $this->request->data['Product']['pr_image'] = $pr_image; /* RESIZE IMAGE */ $MyImageCom = new ImageComponent(); $MyImageCom->prepare("upload/shop/product/" . $filename_new); $MyImageCom->resize(350, 350); //width,height,Red,Green,Blue $MyImageCom->save("upload/shop/product/thumbnail/" . $filename_new); /* RESIZE IMAGE */ $MyImageCom = new ImageComponent(); $MyImageCom->prepare("upload/shop/product/" . $filename_new); $MyImageCom->resize(60, 60); //width,height,Red,Green,Blue $MyImageCom->save("upload/shop/product/thumbnail-mini/" . $filename_new); } else { $this->request->data['Product']['pr_image'] = $_POST["Product_Thumbnail"]; } /*PRODUCT GALLERY 1*/ if (!empty($filename_product_gallery_1)) { if (file_exists(WWW_ROOT . $product['Product']['pr_gallery_1'])) { unlink(WWW_ROOT . $product['Product']['pr_gallery_1']); } $extension = pathinfo($filename_product_gallery_1, PATHINFO_EXTENSION); $filename_new = $this->user_front["id"] . date('dmyHis') . "_g1." . $extension; move_uploaded_file($this->data['Document']['product_gallery_1']['tmp_name'], $dirname_product_gallery . $filename_new); $pr_gallery_1 = "upload/shop/product/" . $filename_new; $this->request->data['Product']['pr_gallery_1'] = $pr_gallery_1; } else { $this->request->data['Product']['pr_gallery_1'] = $_POST["Product_Gallery_1"]; } /*PRODUCT GALLERY 2*/ if (!empty($filename_product_gallery_2)) { if ($product['Product']['pr_gallery_2'] != "") { if (file_exists(WWW_ROOT . $product['Product']['pr_gallery_2'])) { unlink(WWW_ROOT . $product['Product']['pr_gallery_2']); } } $extension = pathinfo($filename_product_gallery_2, PATHINFO_EXTENSION); $filename_new = $this->user_front["id"] . date('dmyHis') . "_g2." . $extension; move_uploaded_file($this->data['Document']['product_gallery_2']['tmp_name'], $dirname_product_gallery . $filename_new); $pr_gallery_2 = "upload/shop/product/" . $filename_new; $this->request->data['Product']['pr_gallery_2'] = $pr_gallery_2; } else { $product_gallery_2 = $_POST["Product_Gallery_2"]; if ($product_gallery_2 == "") { $this->request->data['Product']['pr_gallery_2'] = ""; if ($product['Product']['pr_gallery_2'] != "") { if (file_exists(WWW_ROOT . $product['Product']['pr_gallery_2'])) { unlink(WWW_ROOT . $product['Product']['pr_gallery_2']); } } } } /*PRODUCT GALLERY 3*/ if (!empty($filename_product_gallery_3)) { if ($product['Product']['pr_gallery_3'] != "") { if (file_exists(WWW_ROOT . $product['Product']['pr_gallery_3'])) { unlink(WWW_ROOT . $product['Product']['pr_gallery_3']); } } $extension = pathinfo($filename_product_gallery_3, PATHINFO_EXTENSION); $filename_new = $this->user_front["id"] . date('dmyHis') . "_g3." . $extension; move_uploaded_file($this->data['Document']['product_gallery_3']['tmp_name'], $dirname_product_gallery . $filename_new); $pr_gallery_3 = "upload/shop/product/" . $filename_new; $this->request->data['Product']['pr_gallery_3'] = $pr_gallery_3; } else { $product_gallery_3 = $_POST["Product_Gallery_3"]; if ($product_gallery_3 == "") { $this->request->data['Product']['pr_gallery_3'] = ""; if ($product['Product']['pr_gallery_3'] != "") { if (file_exists(WWW_ROOT . $product['Product']['pr_gallery_3'])) { unlink(WWW_ROOT . $product['Product']['pr_gallery_3']); } } } } /*PRODUCT GALLERY 4*/ if (!empty($filename_product_gallery_4)) { if ($product['Product']['pr_gallery_4'] != "") { if (file_exists(WWW_ROOT . $product['Product']['pr_gallery_4'])) { unlink(WWW_ROOT . $product['Product']['pr_gallery_4']); } } $extension = pathinfo($filename_product_gallery_4, PATHINFO_EXTENSION); $filename_new = $this->user_front["id"] . date('dmyHis') . "_g4." . $extension; move_uploaded_file($this->data['Document']['product_gallery_4']['tmp_name'], $dirname_product_gallery . $filename_new); $pr_gallery_4 = "upload/shop/product/" . $filename_new; $this->request->data['Product']['pr_gallery_4'] = $pr_gallery_4; } else { $product_gallery_4 = $_POST["Product_Gallery_4"]; if ($product_gallery_4 == "") { $this->request->data['Product']['pr_gallery_4'] = ""; if ($product['Product']['pr_gallery_4'] != "") { if (file_exists(WWW_ROOT . $product['Product']['pr_gallery_4'])) { unlink(WWW_ROOT . $product['Product']['pr_gallery_4']); } } } } /*PRODUCT GALLERY 5*/ if (!empty($filename_product_gallery_5)) { if ($product['Product']['pr_gallery_5'] != "") { if (file_exists(WWW_ROOT . $product['Product']['pr_gallery_5'])) { unlink(WWW_ROOT . $product['Product']['pr_gallery_5']); } } $extension = pathinfo($filename_product_gallery_5, PATHINFO_EXTENSION); $filename_new = $this->user_front["id"] . date('dmyHis') . "_g5." . $extension; move_uploaded_file($this->data['Document']['product_gallery_5']['tmp_name'], $dirname_product_gallery . $filename_new); $pr_gallery_5 = "upload/shop/product/" . $filename_new; $this->request->data['Product']['pr_gallery_5'] = $pr_gallery_5; } else { $product_gallery_5 = $_POST["Product_Gallery_5"]; if ($product_gallery_5 == "") { $this->request->data['Product']['pr_gallery_5'] = ""; if ($product['Product']['pr_gallery_5'] != "") { if (file_exists(WWW_ROOT . $product['Product']['pr_gallery_5'])) { unlink(WWW_ROOT . $product['Product']['pr_gallery_5']); } } } } $id_product = $id; $this->loadModel("ProductHistory"); $post_history = $this->ProductHistory->find('first', array('fields' => array('ProductHistory.id'), 'order' => array('ProductHistory.id DESC'), 'limit' => '1')); if (count($post_history) == 0) { $id_product_history = 1; } else { $id_product_history = $post_history['ProductHistory']['id'] + 1; } $this->loadModel("ProductDetail"); $this->loadModel("ProductDetailHistory"); foreach ($this->all_language as $all_language_single) { /*PRODUCT TAGS*/ $product_tag = explode(',', $_POST['pd_tags_' . $all_language_single["Language"]["lg_code"]]); $this->loadModel('Tag'); for ($i = 0; $i < count($product_tag); $i++) { $count = $this->Tag->find('count', array('conditions' => array('Tag.t_name' => $product_tag[$i]))); if ($count == 0) { /*INSERT KE MASTER TAG*/ $post = $this->Tag->find('first', array('fields' => array('Tag.id'), 'order' => array('Tag.id DESC'), 'limit' => '1')); if (count($post) == 0) { $id = 1; } else { $id = $post['Tag']['id'] + 1; } $this->Tag->create(); $this->request->data['Tag']['id'] = $id; $this->request->data['Tag']['t_name'] = $product_tag[$i]; $this->request->data['Tag']['t_active'] = 1; $this->request->data['Tag']['t_u_id_created'] = $this->user_front['id']; $this->request->data['Tag']['t_date_created'] = date('Y-m-d H:i:s'); $this->request->data['Tag']['t_u_id_modified'] = $this->user_front['id']; $this->request->data['Tag']['t_date_modified'] = date('Y-m-d H:i:s'); $this->Tag->save($this->request->data); } } //JIKA STATUS REJECT DIUBAH KE PENDING if ($product["Product"]["pr_active"] == 10) { $this->request->data['ProductDetail']['pd_active'] = 9; $this->request->data['ProductDetailHistory']['pd_active'] = 9; } else { $this->request->data['ProductDetailHistory']['pd_active'] = $product["Product"]["pr_active"]; } //CARI ADA DI TABEL APA BELUM $detail = $this->ProductDetail->find('first', array('fields' => array('ProductDetail.id'), 'conditions' => array('ProductDetail.pd_pr_id' => $id_product, 'ProductDetail.pd_language' => $all_language_single["Language"]["lg_code"]))); if (count($detail) != 0) { $this->request->data['ProductDetail']['id'] = $detail["ProductDetail"]["id"]; $this->request->data['ProductDetail']['pd_pr_id'] = $id_product; $this->request->data['ProductDetail']['pd_language'] = $all_language_single["Language"]["lg_code"]; if ($_POST["pd_title_" . $all_language_single["Language"]["lg_code"]] != "") { $this->request->data['ProductDetail']['pd_name'] = $_POST["pd_title_" . $all_language_single["Language"]["lg_code"]]; } else { $this->request->data['ProductDetail']['pd_name'] = $_POST["pd_title_" . $this->default_language["Language"]["lg_code"]]; } if ($_POST["pd_description_" . $all_language_single["Language"]["lg_code"]] != "") { $this->request->data['ProductDetail']['pd_description'] = $_POST["pd_description_" . $all_language_single["Language"]["lg_code"]]; } else { $this->request->data['ProductDetail']['pd_description'] = $_POST["pd_description_" . $this->default_language["Language"]["lg_code"]]; } $this->request->data['ProductDetail']['pd_tags'] = $_POST["pd_tags_" . $all_language_single["Language"]["lg_code"]]; $this->ProductDetail->set($this->request->data); $this->ProductDetail->save($this->request->data); $post_history = $this->ProductDetailHistory->find('first', array('fields' => array('ProductDetailHistory.id'), 'order' => array('ProductDetailHistory.id DESC'), 'limit' => '1')); if (count($post_history) == 0) { $id_history = 1; } else { $id_history = $post_history['ProductDetailHistory']['id'] + 1; } $this->request->data['ProductDetailHistory']['id'] = $id_history; $this->request->data['ProductDetailHistory']['pd_pr_id'] = $id_product_history; $this->request->data['ProductDetailHistory']['pd_language'] = $all_language_single["Language"]["lg_code"]; if ($_POST["pd_title_" . $all_language_single["Language"]["lg_code"]] != "") { $this->request->data['ProductDetailHistory']['pd_name'] = $_POST["pd_title_" . $all_language_single["Language"]["lg_code"]]; } else { $this->request->data['ProductDetailHistory']['pd_name'] = $_POST["pd_title_" . $this->default_language["Language"]["lg_code"]]; } if ($_POST["pd_description_" . $all_language_single["Language"]["lg_code"]] != "") { $this->request->data['ProductDetailHistory']['pd_description'] = $_POST["pd_description_" . $all_language_single["Language"]["lg_code"]]; } else { $this->request->data['ProductDetailHistory']['pd_description'] = $_POST["pd_description_" . $this->default_language["Language"]["lg_code"]]; } $this->request->data['ProductDetailHistory']['pd_tags'] = $_POST["pd_tags_" . $all_language_single["Language"]["lg_code"]]; $this->ProductDetailHistory->set($this->request->data); $this->ProductDetailHistory->create(); $this->ProductDetailHistory->save($this->request->data); } else { /* INSERT BARU */ $post_sql = $this->ProductDetail->find('first', array('fields' => array('ProductDetail.id'), 'order' => array('ProductDetail.id DESC'), 'limit' => '1')); if (count($post_sql) == 0) { $id_detail = 1; } else { $id_detail = $post_sql['ProductDetail']['id'] + 1; } $this->request->data['ProductDetail']['id'] = $id_detail; $this->request->data['ProductDetail']['pd_pr_id'] = $id_product; $this->request->data['ProductDetail']['pd_language'] = $all_language_single["Language"]["lg_code"]; if ($_POST["pd_title_" . $all_language_single["Language"]["lg_code"]] != "") { $this->request->data['ProductDetail']['pd_name'] = $_POST["pd_title_" . $all_language_single["Language"]["lg_code"]]; } else { $this->request->data['ProductDetail']['pd_name'] = $_POST["pd_title_" . $this->default_language["Language"]["lg_code"]]; } if ($_POST["pd_description_" . $all_language_single["Language"]["lg_code"]] != "") { $this->request->data['ProductDetail']['pd_description'] = $_POST["pd_description_" . $all_language_single["Language"]["lg_code"]]; } else { $this->request->data['ProductDetail']['pd_description'] = $_POST["pd_description_" . $this->default_language["Language"]["lg_code"]]; } $this->request->data['ProductDetail']['pd_tags'] = $_POST["pd_tags_" . $all_language_single["Language"]["lg_code"]]; $this->ProductDetail->set($this->request->data); $this->ProductDetail->create(); $this->ProductDetail->save($this->request->data); $post_history = $this->ProductDetailHistory->find('first', array('fields' => array('ProductDetailHistory.id'), 'order' => array('ProductDetailHistory.id DESC'), 'limit' => '1')); if (count($post_history) == 0) { $id_history = 1; } else { $id_history = $post_history['ProductDetailHistory']['id'] + 1; } $this->request->data['ProductDetailHistory']['id'] = $id_history; $this->request->data['ProductDetailHistory']['pd_pr_id'] = $id_product_history; $this->request->data['ProductDetailHistory']['pd_language'] = $all_language_single["Language"]["lg_code"]; if ($_POST["pd_title_" . $all_language_single["Language"]["lg_code"]] != "") { $this->request->data['ProductDetailHistory']['pd_name'] = $_POST["pd_title_" . $all_language_single["Language"]["lg_code"]]; } else { $this->request->data['ProductDetailHistory']['pd_name'] = $_POST["pd_title_" . $this->default_language["Language"]["lg_code"]]; } if ($_POST["pd_description_" . $all_language_single["Language"]["lg_code"]] != "") { $this->request->data['ProductDetailHistory']['pd_description'] = $_POST["pd_description_" . $all_language_single["Language"]["lg_code"]]; } else { $this->request->data['ProductDetailHistory']['pd_description'] = $_POST["pd_description_" . $this->default_language["Language"]["lg_code"]]; } $this->request->data['ProductDetailHistory']['pd_tags'] = $_POST["pd_tags_" . $all_language_single["Language"]["lg_code"]]; $this->ProductDetailHistory->set($this->request->data); $this->ProductDetailHistory->create(); $this->ProductDetailHistory->save($this->request->data); } } //JIKA STATUS REJECT DI UBAH KE PENDING if ($product["Product"]["pr_active"] == 10) { $this->request->data['Product']['pr_active'] = 9; $this->request->data['ProductHistory']['pr_active'] = 9; } else { $this->request->data['ProductHistory']['pr_active'] = $product["Product"]["pr_active"]; } $this->loadModel('Shop'); $post = $this->Shop->find('first', array('fields' => array('Shop.id'), 'conditions' => array('Shop.sh_u_id_created' => $this->user_front["id"]), 'limit' => '1')); /* UPDATE HEADER */ $this->request->data["Product"]["id_shop"] = $post["Shop"]["id"]; if ($this->request->data["Product"]["pr_stock"] < 0) { $this->request->data["Product"]["pr_stock"] = 0; } if ($this->request->data["Product"]["pr_request"] == 1) { $this->request->data["Product"]["pr_stock"] = 0; } if ($this->request->data["Product"]["pr_package"] < 1) { $this->request->data["Product"]["pr_package"] = 1; } $this->request->data['Product']['id'] = $id_product; if ($this->request->data["Product"]["pr_discount"] == 0) { $discount_date = 0; } else { $discount_date = date("Y-m-d", strtotime($_POST["discount_expired"])); } $this->request->data['Product']['pr_discount_date'] = $discount_date; //if ($this->request->data["Product"]["pr_min_order"] < 1){ //$this->request->data["Product"]["pr_min_order"] = 1; //} /* hapus minimum order */ if ($this->request->data["Product"]["pr_weight"] < 1) { $this->request->data["Product"]["pr_weight"] = 1; } if ($this->request->data["Product"]["pr_p"] < 1) { $this->request->data["Product"]["pr_p"] = 1; } if ($this->request->data["Product"]["pr_l"] < 1) { $this->request->data["Product"]["pr_l"] = 1; } if ($this->request->data["Product"]["pr_t"] < 1) { $this->request->data["Product"]["pr_t"] = 1; } $this->request->data['Product']['pr_u_id_created'] = $this->user_front['id']; $this->request->data['Product']['pr_date_created'] = date('Y-m-d H:i:s'); $this->request->data['Product']['pr_u_id_modified'] = $this->user_front['id']; $this->request->data['Product']['pr_date_modified'] = date('Y-m-d H:i:s'); $this->Product->set($this->request->data); if ($this->Product->save($this->request->data)) { $this->request->data["ProductHistory"] = $this->request->data["Product"]; $this->request->data['ProductHistory']['id'] = $id_product_history; $this->request->data['ProductHistory']['id_product'] = $id_product; $this->request->data['ProductHistory']['pr_status'] = "Edit Product"; $this->ProductHistory->set($this->request->data); $this->ProductHistory->create(); $this->ProductHistory->save($this->request->data); $this->Session->setFlash(__($this->default_save_success), 'flash_message'); return $this->redirect(Router::url('/', true) . strtolower($this->default_language_id) . "/product/list/"); } } else { $date_posted = $_POST["discount_expired"]; foreach ($this->all_language as $all_language_single) { $product["pd_name_" . $all_language_single["Language"]["lg_code"]] = $_POST["pd_title_" . $all_language_single["Language"]["lg_code"]]; $product["pd_description_" . $all_language_single["Language"]["lg_code"]] = $_POST["pd_description_" . $all_language_single["Language"]["lg_code"]]; $product["pd_tags_" . $all_language_single["Language"]["lg_code"]] = $_POST["pd_tags_" . $all_language_single["Language"]["lg_code"]]; } $this->Session->setFlash(__($this->default_save_error), 'flash_message_error'); } } if ($this->request->is(array('post', 'put'))) { /*LOAD SUB CATEGORY */ $this->loadModel("SubcategoryDetail"); $subcategory = $this->SubcategoryDetail->find('list', array('fields' => array('SubcategoryDetail.sctd_sct_id', 'SubcategoryDetail.sctd_title'), 'conditions' => array('SubcategoryDetail.sctd_active' => 1, 'SubcategoryDetail.sctd_language' => $this->default_language_id, 'subcategory_header.id_category' => $this->request->data["Product"]["pr_category"]), 'recursive' => 0, 'order' => array('SubcategoryDetail.sctd_title' => 'ASC'))); $subcategory[0] = "-"; asort($subcategory); $this->set('subcategory', $subcategory); $this->loadModel("Subcategorysub"); $subcategorysub = $this->Subcategorysub->find('list', array('fields' => array('subcategorysub_detail_many.sctsd_scts_id', 'subcategorysub_detail_many.sctsd_title'), 'joins' => array("LEFT JOIN `ca_subcategorysub_detail` AS `subcategorysub_detail_many` ON `Subcategorysub`.`id` = `subcategorysub_detail_many`.`sctsd_scts_id`"), 'conditions' => array('Subcategorysub.id_subcategory' => $this->request->data["Product"]["pr_sub_category"], 'subcategorysub_detail_many.sctsd_active' => 1, 'subcategorysub_detail_many.sctsd_language' => $this->default_language_id), 'order' => array('subcategorysub_detail_many.sctsd_title' => 'ASC'))); $subcategorysub[0] = "-"; asort($subcategorysub); $this->set('subcategorysub', $subcategorysub); } $this->set('date_posted', $date_posted); $this->set('product', $product); /*LOAD SHOP CATEGORY */ $this->loadModel("Shop"); $shop = $this->Shop->find('first', array('conditions' => array('Shop.sh_u_id_created' => $this->user_front["id"]))); $this->loadModel("ShopCategoryDetail"); $shop_category = $this->ShopCategoryDetail->find('list', array('fields' => array('ShopCategoryDetail.id_shop_category', 'ShopCategoryDetail.scd_title'), 'conditions' => array('ShopCategoryDetail.scd_active' => 1, 'ShopCategoryDetail.scd_language' => $this->default_language_id, 'shop_category_header.id_shop' => $shop["Shop"]["id"]), 'recursive' => 0, 'order' => array('ShopCategoryDetail.scd_title' => 'ASC'))); $shop_category[0] = "-"; asort($shop_category); $this->set('shop_category', $shop_category); /* LOAD TAGS */ $this->loadModel('Tag'); $posts = $this->Tag->find('all', array('condition' => array('Tag.t_active' => 1), 'order' => array('Tag.id ASC'))); $tags = ""; foreach ($posts as $post) { $tags .= "'" . $post['Tag']['t_name'] . "', "; } if ($tags != "") { $tags = substr($tags, 0, strlen($tags) - 2); } $this->set('tags', $tags); /*LOAD PROVINCE */ $this->loadModel("Province"); $province = $this->Province->find('list', array('fields' => array('Province.id', 'Province.pc_province_name'), 'conditions' => array('Province.pc_active' => 1), 'order' => array('Province.pc_province_name' => 'ASC'))); $this->set('province', $province); $this->layout = 'main_front'; $this->set('title_for_layout', 'Edit Product | ' . $this->web_title); $this->set('error', $result); $this->set('keyword', $this->shop_keyword); $this->set('id', $id); $this->set('product_name', $product_name); $this->set('description', $this->shop_desc); $this->render($this->pathFront . 'edit_product'); }
if (!isset($_GET) || empty($_GET)) { throw new Exception("Paramètres d'image manquants"); } // Bootstrap $Bootstrap = Bootstrap::getInstance(); $Bootstrap->setEnv(ENV); $Bootstrap->loadConfigs(ROOT . '/configs/'); $default = array('src' => false, 'width' => false, 'height' => false, 'mode' => false); extract(array_merge($default, $_GET)); if (!$height) { $height = $width; } if (Config::get('cache.pictures')) { sort($_GET); $cachename = ROOT . 'cache/' . sha1($src . '&' . http_build_query($_GET)); $Cache = new CacheComponent($cachename, '-1 month'); $Cache->open(); } $Image = new ImageComponent(ROOT . 'www' . $src); if ($mode == 'crop') { $Image->thumbnail($width, $height); } elseif ($mode == 'zoom') { $Image->zoom($width, $height); } elseif ($width || $height) { $Image->resize($width, $height); } $Image->show(); if (Config::get('cache.pictures')) { $Cache->close(); } flush();
function upload_images1() { // pr($_FILES); die; // pr($this->data); die; $this->layout = false; $this->autoRender = false; if (!empty($_FILES)) { $flag = false; $this->loadModel('GalleryImage'); $pre_images = $this->GalleryImage->find('all', array('conditions' => array('gallery_id' => $this->data['gallery_id']), 'order' => 'sort desc', 'limit' => 1)); if (!empty($pre_images) && isset($pre_images[0]['GalleryImage']['sort'])) { $psort = $pre_images[0]['GalleryImage']['sort']; } else { $psort = 0; } $galery = $this->{$this->modelClass}->findById($this->data['gallery_id']); foreach ($_FILES['images']['name'] as $key => $image) { App::import('Component', 'Image'); $data = array(); $file = $image; // $filename = md5(time()); $filename = ''; $ext = strtolower(substr($file, strrpos($file, ".") + 1)); if (!in_array($ext, array('jpeg', 'jpg', 'JPEG', 'JPG'))) { $this->Session->setFlash(__('Upload Only .jpg images'), 'error'); $this->redirect(array('action' => 'index', $galery[$this->modelClass]['client_id'])); } $newImage = $filename . $file; $folder = $this->createFolder(USER_IMAGE_STORE_PATH, 'gallery_' . $this->data['gallery_id']); $folder_low = $this->createFolder(USER_IMAGE_STORE_PATH . 'gallery_' . $this->data['gallery_id'] . DS, 'low'); $directory = $folder['path'] . DS . $newImage; // upload image move_uploaded_file($_FILES['images']['tmp_name'][$key], $directory); /* save low resulation */ $MyImageCom = new ImageComponent(); $MyImageCom->prepare($directory); list($width, $height) = getimagesize($directory); $info = pathinfo($directory); if ($width > 700) { $height = $height * (700 / $width); $width = 700; } if ($height > 700) { $width = $width * (700 / $height); $height = 700; } // pr($width); // pr($height); // pr($info); die; $MyImageCom->resize($width, $height); //width,height,Red,Green,Blue $MyImageCom->save($folder['path'] . DS . "low" . DS . $newImage); $data['image'] = $newImage; $data['image_folder'] = $folder['folder']; $data['gallery_id'] = $this->data['gallery_id']; $data['sort'] = $psort++; // save user data // pr($data); $this->GalleryImage->create(); if ($this->GalleryImage->save($data, array('validate' => false))) { $flag = true; } else { $flag = false; } } if ($flag) { $this->Session->setFlash(__('Images successfully Uploaded'), 'success'); } else { $this->Session->setFlash(__('Images not uploaded'), 'success'); } $this->{$this->modelClass}->id = $this->data['gallery_id']; $this->{$this->modelClass}->save(array('status' => 2), array('validate' => false)); $this->redirect(array('action' => 'index', $galery[$this->modelClass]['client_id'])); } }
public function add() { $this->layout = 'backend'; if ($this->request->is('post')) { if ($this->request->data) { $filename = $this->request->data['Property']['file']['name']; $this->request->data['Property']['image'] = $filename; } $this->Property->create(); if ($this->Property->save($this->request->data)) { $property_id = $this->Property->getLastInsertId(); if ($this->request->data['Property']['files'][0]['error'] === UPLOAD_ERR_OK) { $dir = new Folder(WWW_ROOT . 'img' . DS . 'property' . DS . $property_id . DS . 'images', true, 0755); $files = $this->request->data['Property']['files']; foreach ($files as $file) { $filename = $file['name']; $filePath = "./img/property/" . $property_id . '/images/' . $filename; move_uploaded_file($file['tmp_name'], $filePath); } } if ($this->request->data['Property']['file']['error'] === UPLOAD_ERR_OK) { //Process the upload of a single front image for 280x165 $filename = $this->request->data['Property']['file']['name']; $dir = new Folder(WWW_ROOT . 'img' . DS . 'property' . DS . $property_id . DS . '400x250', true, 0755); $filePath = "./img/property/" . $property_id . '/' . '400x250/' . $filename; $filePath2 = "./img/property/" . $property_id . '/' . '650x400/' . $filename; $tmpfile = $this->request->data['Property']['file']['tmp_name']; move_uploaded_file($tmpfile, $filePath); $dir = new Folder(WWW_ROOT . 'img' . DS . 'property' . DS . $property_id . DS . '650x400', true, 0755); $file = new File($filePath, false, 755); $file->copy($filePath2, false); $MyImageCom = new ImageComponent(new ComponentCollection()); $MyImageCom->prepare($filePath); $MyImageCom->resize(400, 250); //width,height,Red,Green,Blue $MyImageCom->save($filePath); //Process the upload of a single front image for 480x350 //$filename = $this->request->data['Property']['file']['name']; //$dir = new Folder(WWW_ROOT . 'img/property/'.$property_id.'/'.'480x350/', true, 0755); //$filePath = "./img/property/".$property_id.'/'.'480x350/'.$filename; //move_uploaded_file($tmpfile, $filePath); //$files = $dir->find('.*', true); //$MyImageCom = new ImageComponent(new ComponentCollection()); $MyImageCom->prepare($filePath2); $MyImageCom->resize(650, 400); //width,height,Red,Green,Blue $MyImageCom->save($filePath2); } $this->Session->setFlash(__('The property has been saved')); return $this->redirect(array('action' => 'index')); } $this->Session->setFlash(__('The Property could not be saved. Please, try again.')); } }