public function edit($id = 0) { $user = $this->session->userdata('user'); $data = array(); if ($id <= 0) { redirect(base_url('admin/product/index/' . $type)); } $type = 1; $data['type'] = $type; $data['title'] = "Edit product"; $category = $this->modelcategory->getCategories(array("type" => $type)); #Tải thư viện và helper của Form trên CodeIgniter $this->load->helper(array('form')); $dataC = $this->modelproduct->getproductById($id); if ($this->input->post('submit') == "ok") { $this->load->library(array('form_validation')); $this->form_validation->set_rules('title', 'Title', 'required|min_length[5]'); $this->form_validation->set_rules('detail', 'Detail', 'required|min_length[5]'); #Kiểm tra điều kiện validate if ($this->form_validation->run() == TRUE) { $dataC['title'] = $this->input->post('title'); $dataC['slug'] = safe_title($this->input->post('title')); $dataC['description'] = $this->input->post('description'); $dataC['detail'] = $this->input->post('detail'); $dataC['info'] = $this->input->post('info'); $dataC['price'] = $this->input->post('price'); $dataC['tag'] = $this->input->post('tag'); // $dataC['author'] = $user['id']; $dataC['category_id'] = $this->input->post('category_id'); // $dataC['created'] = time(); $dataC['order'] = $this->input->post('order'); if ($this->input->post('hot_product')) { $dataC['hot_product'] = 1; } else { $dataC['hot_product'] = 0; } if ($this->input->post('home_product')) { $dataC['home_product'] = 1; } else { $dataC['home_product'] = 0; } if ($this->input->post('status')) { $dataC['status'] = 1; } else { $dataC['status'] = 0; } $dataC['type'] = $type; if (!empty($_FILES['image'])) { $this->load->model(array('Mgallery')); $image_data = $this->Mgallery->do_upload("/product/"); if ($image_data) { $dataC['image'] = $image_data["file_name"]; } } if (!empty($_FILES['image_detail_1'])) { $this->load->model(array('Mgallery')); $image_data = $this->Mgallery->do_upload("/product/", "image_detail_1"); if ($image_data) { $dataC['image_detail_1'] = $image_data["file_name"]; } } if (!empty($_FILES['image_detail_2'])) { $this->load->model(array('Mgallery')); $image_data = $this->Mgallery->do_upload("/product/", "image_detail_2"); if ($image_data) { $dataC['image_detail_2'] = $image_data["file_name"]; } } if ($this->modelproduct->updateproduct($id, $dataC)) { $data['b_Check'] = true; redirect(base_url('admin/product/index')); } else { $data['b_Check'] = false; } } } $data['category_box'] = $this->category_box($category, $dataC); $data['item'] = $dataC; $this->template->build('addproduct', $data); }
/** * Make link fix product * * @author MinhNV * Date 2010/07/07 */ private function makeLinkProduct() { $link_depart = ''; $link_section = ''; $link_product = ''; $link_url = ''; $depart_id = Url::get('depart_id', 0); $cat_id = Url::get('cat_id', 0); $cat_name = Url::get('cat_name', ''); $url_filter = Url::get('url_filter'); $arySerialize = array(); $url_serialize = ''; $url_product = Url::get('url_product'); $aryParamFilter = array(); $is_same_cat = Url::get('is_same_cat', 0); $is_same_depart = Url::get('is_same_depart', 0); $is_new = Url::get('is_new', 0); $is_discount_new = Url::get('is_discount_new', 0); $is_discount = Url::get('is_discount', 0); $is_attention = Url::get('is_attention', 0); $type_special = 0; if ($is_new == 1) { $type_special = IS_NEW; } if ($is_discount_new == 1) { $type_special = IS_DISCOUNT_NEW; } if ($is_discount == 1) { $type_special = IS_DISCOUNT; } if ($is_attention == 1) { $type_special = NUM_CLASSIFIED; } $city_id = Url::get('city_id', 0); $district_id = Url::get('district_id', 0); if ($url_filter) { $aryParamFilter = $this->buildArrayFromURL($url_filter); } if ($url_product) { $aryProduct = explode(',', $url_product); if (is_array($aryProduct) && count($aryProduct) == 1) { $page = ''; $aryProduct = Product::getProduct($url_product); $link_product = Product::buildLinkProductDetail(0, $aryProduct['category_id'], $aryProduct['id'], $aryProduct['name']); $arySerialize = array('page' => $page, 'params' => array('id' => $url_product, 'title' => EClassApi::safe_title($aryProduct['name']))); } else { if ($is_same_cat == 1) { $page = CGlobal::$aryDepartName[$depart_id] . '_section'; $link_product = Url::build($page, array('cat_product_id' => $cat_id, 'title' => EClassApi::safe_title($cat_name), 'product_id' => $url_product)); $arySerialize = array('page' => $page, 'params' => array('cat_product_id' => $cat_id, 'title' => EClassApi::safe_title($cat_name), 'product_id' => $url_product)); } else { $page = 'list_product'; $link_product = Url::build($page, array('product_id' => $url_product)); $arySerialize = array('page' => $page, 'params' => array('product_id' => $url_product)); } } } else { if ($depart_id) { $page = CGlobal::$aryDepartName[$depart_id]; //Neu co tinh thanh if ($city_id > 0) { $aryCity = SoLib::getListOptionCity(); if ($district_id > 0) { //Get quan huyen $aryDistrict = EClassApi::getDistrict($city_id); //$districtName = $this->getDistrictName ( $district_id ); $aryParams = array('city_id' => $city_id, 'district_id' => $district_id, 'title' => safe_title($aryDistrict['name'])); $arySerialize = array('page' => $page, 'params' => $aryParams); $link_depart = Url::build($page, $aryParams); } else { $aryParams = array('city_id' => $city_id, 'title' => safe_title($aryCity[$city_id])); $arySerialize = array('page' => $page, 'params' => $aryParams); $link_depart = Url::build($page, $aryParams); } } else { if ($url_filter) { if ($depart_id == CGlobal::THOI_TRANG || $depart_id == CGlobal::SACH) { $page = CGlobal::$aryDepartName[$depart_id] . '_section'; $aryParams = array('cat_product_id' => $depart_id, 'title' => safe_title(CGlobal::$aryDepart[$depart_id])); $aryParams = array_merge($aryParams, $aryParamFilter); } else { $aryParams = $aryParamFilter; } $arySerialize = array('page' => $page, 'params' => $aryParams); $link_depart = Url::build($page, $aryParams); } else { $arySerialize = array('page' => $page, 'params' => array()); $link_depart = Url::build($page, array()); } } if ($cat_id) { $page = CGlobal::$aryDepartName[$depart_id] . '_section'; if ($city_id > 0) { $aryCity = SoLib::getListOptionCity(); if ($district_id > 0) { //Get quan huyen $aryDistrict = EClassApi::getDistrict($city_id); //$aryDistrict = EClassApi::getDistrict($city_id); $aryParams = array('cat_product_id' => $cat_id, 'city_id' => $city_id, 'district_id' => $district_id, 'title' => safe_title($aryDistrict['name'])); } else { $aryParams = array('cat_product_id' => $cat_id, 'city_id' => $city_id, 'title' => safe_title($aryCity[$city_id])); } $arySerialize = array('page' => $page, 'params' => $aryParams); $link_depart = Url::build($page, $aryParams); } else { if ($type_special > 0) { $page = 'list_special'; $aryParams = array('cat_product_id' => $cat_id, 'type' => $type_special, 'title' => safe_title($cat_name)); } else { $aryParams = array('cat_product_id' => $cat_id, 'title' => safe_title($cat_name)); } if ($url_filter) { $aryParams = array_merge($aryParams, $aryParamFilter); } $arySerialize = array('page' => $page, 'params' => $aryParams); $link_depart = Url::build($page, $aryParams); } } } } if ($link_product) { $link_url = $link_product; } else { if ($link_depart) { $link_url = $link_depart; } } if (is_array($arySerialize) && count($arySerialize) > 0) { $url_serialize = serialize($arySerialize); } $aryData = array(); $aryData['link_product_fix'] = $link_url; $aryData['url_serialize'] = $url_serialize; $aryData['intIsOK'] = 1; echo json_encode($aryData); exit; }
public function edit($type = 0, $id = 0) { $data = array(); if ($id <= 0) { redirect(base_url('list-category/' . $type)); } $data['type'] = $type; $data['title'] = "Edit category"; $category = $this->modelcategory->getCategories(array("type" => $type)); $data['category'] = $category; #Tải thư viện và helper của Form trên CodeIgniter $this->load->helper(array('form')); $dataC = $this->modelcategory->getCategoryById($id); if ($this->input->post('submit') == "ok") { $this->load->library(array('form_validation')); $this->form_validation->set_rules('name', 'Name', 'required|min_length[3]'); #Kiểm tra điều kiện validate if ($this->form_validation->run() == TRUE) { $dataC['name'] = $this->input->post('name'); $dataC['slug'] = safe_title($this->input->post('name')); $dataC['parent'] = $this->input->post('parent'); $dataC['description'] = $this->input->post('description'); $dataC['order'] = $this->input->post('order'); if ($this->input->post('status')) { $dataC['status'] = 1; } else { $dataC['status'] = 0; } $dataC['type'] = $type; if (!empty($_FILES['image'])) { $this->load->model(array('Mgallery')); $image_data = $this->Mgallery->do_upload("/categories/"); if ($image_data) { $dataC['image'] = $image_data["file_name"]; } } if ($this->modelcategory->updateCategory($dataC['id'], $dataC)) { $data['b_Check'] = true; // redirect(base_url('list-category/'.$type)); } else { $data['b_Check'] = false; } } } $data['item'] = $dataC; $data['category_box'] = $this->category_box($category, $dataC); $this->template->build('addcategory', $data); }