Exemple #1
0
 function edit()
 {
     $get = $this->request->get;
     $str = '';
     foreach ($get as $val => $keys) {
         $str .= '&' . $val . '=' . $keys;
     }
     $str = trim($str, '&');
     $str_get = count($get) ? '?' . $str : '';
     $data['title'] = 'Cập nhật bài viết';
     $data['save'] = true;
     $data['apply'] = true;
     $data['cancel'] = 'news/ds/' . $this->uri->segment(4) . '/' . $str_get;
     $id = segment(3, 'int');
     $data['listcategory'] = $this->news->get_all_category();
     $data['rs'] = $this->news->get_info_new($id);
     $data['list'] = $this->news->get_news_by_id($id);
     $row = $this->db->row("SELECT * FROM category WHERE cat_id=" . $data['rs']->catid);
     if ($row->parent_id == 0) {
         $cat = $row->cat_id;
     } else {
         $cat = $row->parent_id;
     }
     $data['channel'] = $this->news->get_list_channel($cat);
     // Form validation
     foreach ($this->language as $lang) {
         $this->form_validation->set_rules('vdata[title][' . $lang->lang_id . ']', 'Tiêu đề: ' . $lang->lang_name, 'required');
         $this->form_validation->set_rules('vdata[fulltext][' . $lang->lang_id . ']', '', '');
         $this->form_validation->set_rules('vdata[introtext][' . $lang->lang_id . ']', '', '');
     }
     $this->form_validation->set_rules('vdata[cat_id]', '', '');
     $this->form_validation->set_rules('vdata[published]', '', '');
     $this->form_validation->set_rules('vdata[metakey]', '', '');
     $this->form_validation->set_rules('vdata[metadesc]', '', '');
     if ($this->form_validation->run() === FALSE) {
         $this->pre_message = validation_errors();
     } else {
         $vdata = $this->request->post['vdata'];
         $attr = $_POST['attr'];
         $idata['cat_id'] = $vdata['cat_id'];
         $idata['published'] = $vdata['published'];
         $idata['noibat'] = $this->request->post['noibat'];
         $idata['created_by'] = $_SESSION['user_id'];
         $idata['modified'] = time();
         $idata['attr'] = '';
         $idata['attr'] .= 'show_intro=' . $attr['show_intro'];
         $idata['attr'] .= '&show_author=' . $attr['show_author'];
         $idata['attr'] .= '&show_date=' . $attr['show_date'];
         $idata['attr'] .= '&show_editdate=' . $attr['show_editdate'];
         $idata['attr'] .= '&show_print=' . $attr['show_print'];
         $idata['attr'] .= '&show_email=' . $attr['show_email'];
         $idata['attr'] .= '&show_comment=' . $attr['show_comment'];
         $idata['attr'] .= '&show_other=' . $attr['show_other'];
         if ($_FILES["userfile"]["size"] > 0) {
             $config['upload_path'] = ROOT . 'data/news/default/';
             $config['allowed_types'] = 'gif|jpg|png';
             $config['max_size'] = '10000';
             $config['file_name'] = vnit_change_title($vdata['title'][$this->lang_default]);
             $this->load->library('upload', $config);
             $this->upload->initialize($config);
             if (!$this->upload->do_upload()) {
                 $this->pre_message = $this->upload->display_errors();
                 $this->session->set_flashdata('error', $this->pre_message);
                 redirect(uri_string());
             } else {
                 $result = $this->upload->data();
                 $idata['images'] = $result['file_name'];
                 vnit_resize_image(ROOT . 'data/news/default/' . $idata['images'], ROOT . 'data/news/80/' . $idata['images'], 80, 0, false);
                 vnit_resize_image(ROOT . 'data/news/default/' . $idata['images'], ROOT . 'data/news/200/' . $idata['images'], 200, 0, false);
                 vnit_resize_image(ROOT . 'data/news/default/' . $idata['images'], ROOT . 'data/news/300/' . $idata['images'], 300, 0, false);
             }
         }
         if ($this->db->update('news', $idata, array('id' => $id))) {
             $this->db->delete('news_des', array('id' => $id));
             for ($i = 0; $i < sizeof($this->language); $i++) {
                 $val1 = $this->language[0];
                 $val = $this->language[$i];
                 $vdes['id'] = $id;
                 $vdes['cat_id'] = $idata['cat_id'];
                 $vdes['lang_id'] = $val->lang_id;
                 $vdes['title'] = $vdata['title'][$val->lang_id] != '' ? $vdata['title'][$val->lang_id] : $vdata['title'][$val1->lang_id];
                 $vdes['slug'] = vnit_change_title($vdes['title']);
                 $vdes['cat_slug'] = $this->news->get_cat_by_id($vdata['cat_id'], $val->lang_id)->cat_slug;
                 $vdes['main_slug'] = $this->news->main_cat_slug($vdata['cat_id'], $val->lang_id);
                 $vdes['main_id'] = $this->news->main_cat_id($vdata['cat_id'], $val->lang_id);
                 $vdes['introtext'] = $vdata['introtext'][$val->lang_id] != '' ? $vdata['introtext'][$val->lang_id] : $vdata['introtext'][$val1->lang_id];
                 $vdes['fulltext'] = $vdata['fulltext'][$val->lang_id] != '' ? $vdata['fulltext'][$val->lang_id] : $vdata['fulltext'][$val1->lang_id];
                 $this->db->insert('news_des', $vdes);
             }
             $this->session->set_flashdata('message', 'Lưu thành công');
             $option = $_POST['option'];
             if ($option == 'save') {
                 $url = 'news/ds/' . $this->uri->segment(4) . '/' . $str_get;
             } else {
                 $url = uri_string();
             }
             redirect($url);
         }
     }
     $data['message'] = $this->pre_message;
     $this->load->templates('edit', $data);
 }
Exemple #2
0
 function edit()
 {
     $catid = $this->uri->segment(3);
     $maincat = $catid;
     $row = $this->db->row("SElECT name FROM pcat WHERE catid = {$catid}");
     $id = $this->uri->segment(4);
     $data['catid'] = $catid;
     $data['save'] = true;
     $data['apply'] = true;
     $data['cancel'] = 'pcat/ds/' . $catid;
     $data['title'] = "Thêm danh mục trong: " . $row->name;
     $data['list'] = $this->pcat->get_all_maincat();
     $data['rs'] = $this->db->row("SELECT * FROM pcat WHERE catid = {$id}");
     $this->form_validation->set_rules('vdata[name]', 'Danh mục', 'required');
     $this->form_validation->set_rules('vdata[ordering]', 'Sắp xếp', 'required');
     if ($this->form_validation->run() == FALSE) {
         $this->pre_message = validation_errors();
     } else {
         $catid = $this->request->post['catid'];
         $vdata = $this->request->post['vdata'];
         $vdata['slugcat'] = vnit_change_title($vdata['name']);
         $vdata['is_home'] = $this->request->post['is_home'];
         $vdata['is_menu'] = $this->request->post['is_menu'];
         if ($_FILES["userfile"]["size"] > 0) {
             $config['upload_path'] = ROOT . 'data/tam/';
             $config['allowed_types'] = 'gif|jpg|png';
             $config['max_size'] = '10000';
             $config['file_name'] = $data['slug'];
             $this->load->library('upload', $config);
             $this->upload->initialize($config);
             if (!$this->upload->do_upload()) {
                 $this->pre_message = $this->upload->display_errors();
                 $this->session->set_flashdata('error', $this->pre_message);
                 redirect(uri_string());
             } else {
                 $result = $this->upload->data();
                 $vdata['icon'] = $result['file_name'];
                 vnit_resize_image(ROOT . 'data/tam/' . $vdata['icon'], ROOT . 'data/pcat/150/' . $vdata['icon'], 150, 150, true);
                 vnit_resize_image(ROOT . 'data/tam/' . $vdata['icon'], ROOT . 'data/pcat/80/' . $vdata['icon'], 80, 80, true);
                 unlink(ROOT . 'data/tam/' . $vdata['icon']);
             }
         }
         if ($this->db->update('pcat', $vdata, array('catid' => $catid))) {
             $this->session->set_flashdata('message', 'Lưu thành công');
             $option = $_POST['option'];
             if ($option == 'save') {
                 $url = 'pcat/ds/' . $maincat;
             } else {
                 $url = 'pcat/edit/' . $catid;
             }
             redirect($url);
         }
     }
     $data['message'] = $this->pre_message;
     $this->load->templates('edit', $data);
 }
Exemple #3
0
 function edit()
 {
     $get = $this->request->get;
     $str = '';
     foreach ($get as $val => $keys) {
         $str .= '&' . $val . '=' . $keys;
     }
     $str = trim($str, '&');
     $str_get = count($get) ? '?' . $str : '';
     $data['title'] = 'Cập nhật';
     $data['save'] = true;
     $data['apply'] = true;
     $data['cancel'] = 'contacts/' . $this->uri->segment(4) . '/' . $str_get;
     $id = segment(3, 'int');
     $data['listoffice'] = $this->contacts->get_all_office();
     $data['rs'] = $this->contacts->get_info_contacts($id);
     $data['list'] = $this->contacts->get_contacts_by_id($id);
     // Form validation
     $this->form_validation->set_rules('vdata[name]', 'Họ và Tên', 'required');
     $this->form_validation->set_rules('vdata[title]', 'Chức vụ / Chức danh', '');
     $this->form_validation->set_rules('vdata[phone_1]', 'Số điện thoại', '');
     $this->form_validation->set_rules('vdata[ordering]', '', '');
     if ($this->form_validation->run() === FALSE) {
         $this->pre_message = validation_errors();
     } else {
         $vdata = $this->request->post['vdata'];
         $vdata['created_by'] = $_SESSION['user_id'];
         $vdata['modified'] = time();
         $idata['attr'] .= 'show_intro=' . $attr['show_intro'];
         $idata['attr'] .= '&show_author=' . $attr['show_author'];
         $idata['attr'] .= '&show_date=' . $attr['show_date'];
         $idata['attr'] .= '&show_editdate=' . $attr['show_editdate'];
         $idata['attr'] .= '&show_print=' . $attr['show_print'];
         $idata['attr'] .= '&show_email=' . $attr['show_email'];
         $idata['attr'] .= '&show_comment=' . $attr['show_comment'];
         $idata['attr'] .= '&show_other=' . $attr['show_other'];
         if ($_FILES["userfile"]["size"] > 0) {
             $config['upload_path'] = ROOT . 'data/contacts/default/';
             $config['allowed_types'] = 'gif|jpg|png';
             $config['max_size'] = '10000';
             $config['file_name'] = vnit_change_title($vdata['name'] . '-' . $vdata['title']);
             $this->load->library('upload', $config);
             $this->upload->initialize($config);
             if (!$this->upload->do_upload()) {
                 $this->pre_message = $this->upload->display_errors();
                 $this->session->set_flashdata('error', $this->pre_message);
                 redirect(uri_string());
             } else {
                 $result = $this->upload->data();
                 $vdata['images'] = $result['file_name'];
                 vnit_resize_image(ROOT . 'data/contacts/default/' . $vdata['images'], ROOT . 'data/contacts/80/' . $vdata['images'], 80, 0, false);
                 vnit_resize_image(ROOT . 'data/contacts/default/' . $vdata['images'], ROOT . 'data/contacts/200/' . $vdata['images'], 200, 0, false);
                 vnit_resize_image(ROOT . 'data/contacts/default/' . $vdata['images'], ROOT . 'data/contacts/300/' . $vdata['images'], 300, 0, false);
             }
         }
         if ($this->db->update('contacts', $vdata, array('id' => $id))) {
             //$this->db->delete('news_des',array('id'=>$id));
             $this->session->set_flashdata('message', 'Lưu thành công');
             $option = $_POST['option'];
             if ($option == 'save') {
                 $url = 'contacts';
                 //.$this->uri->segment(4).'/'.$str_get;
             } else {
                 $url = uri_string();
             }
             redirect($url);
         }
     }
     $data['message'] = $this->pre_message;
     $this->load->templates('edit', $data);
 }
Exemple #4
0
 function uploader_edit()
 {
     $id = $this->uri->segment(3);
     $dir = ROOT . 'data/tam/';
     $dir_admin = 'data/tam/';
     $size = $_FILES['Filedata']['size'];
     if ($size > 204857600) {
         $data['error'] = 1;
         $data['msg'] = "File quá lớn. Không thể tải lên";
     }
     $filename = stripslashes($_FILES['Filedata']['name']);
     $i = strrpos($filename, ".");
     if (!$i) {
         return "";
     }
     $l = strlen($filename) - $i;
     $extension = substr($filename, $i + 1, $l);
     $extension = strtolower($extension);
     $file_name = str_replace($extension, '', $filename);
     $file_name = vnit_change_title($file_name);
     $filename = $dir . $file_name . '-' . time() . '.' . $extension;
     $file_ext = $file_name . '-' . time() . '.' . $extension;
     if (move_uploaded_file($_FILES['Filedata']['tmp_name'], $filename)) {
         $vdata['id'] = $id;
         $vdata['path'] = $file_ext;
         $this->db->insert('khachhang_img', $vdata);
         $this->load->helper('vimg');
         $folder_tam = ROOT . 'data/tam/' . $file_ext;
         $folder_150 = ROOT . 'data/khachhang/150/' . $file_ext;
         $folder_500 = ROOT . 'data/khachhang/500/' . $file_ext;
         $this->load->helper('vimg');
         vnit_resize_image($folder_tam, $folder_150, 150, 0, false);
         vnit_resize_image($folder_tam, $folder_500, 500, 0, false);
         $data['id'] = $this->db->insert_id();
         $data['error'] = 0;
         $data['filename'] = $file_ext;
         $data['msg'] = "Tải file lên thành công";
     } else {
         $data['error'] = 1;
         $data['msg'] = "Tải file lên không thành công";
     }
     echo json_encode($data);
 }
Exemple #5
0
 function edit()
 {
     $id = segment(3, 'int');
     $data['title'] = "Cập nhật sản phẩm";
     $data['save'] = true;
     $data['apply'] = true;
     $data['cancel'] = 'product/ds';
     $data['dscat'] = $this->product->get_all_cat();
     $data['rs'] = $this->db->row("SELECT * FROM product WHERE id = {$id}");
     $data['list'] = $this->product->get_product_($id);
     // Form validation
     //foreach($this->language as $lang):
     $this->form_validation->set_rules('vdata[title][' . $this->language[0]->lang_id . ']', 'Tên sản phẩm ' . $this->language[0]->lang_name, 'required');
     $this->form_validation->set_rules('vdata[gioithieu][' . $this->language[0]->lang_id . ']', 'thanhphan', '');
     //endforeach;
     if ($this->form_validation->run() === FALSE) {
         $this->pre_message = validation_errors();
     } else {
         $vdata = $this->request->post['vdata'];
         if ($_FILES["userfile"]["size"] > 0) {
             $config['upload_path'] = ROOT . 'data/tam/';
             $config['allowed_types'] = 'gif|jpg|png|jpeg';
             $config['max_size'] = '10000';
             $config['file_name'] = vnit_change_title($vdata['title'][$this->lang_default]);
             $this->load->library('upload', $config);
             $this->upload->initialize($config);
             if (!$this->upload->do_upload()) {
                 $this->pre_message = $this->upload->display_errors();
                 $this->session->set_flashdata('message', $this->pre_message);
                 redirect(uri_string());
             } else {
                 $result = $this->upload->data();
                 $filename = $result['file_name'];
                 $ext = end(explode('.', $filename));
                 if ($ext == 'jpeg') {
                     $ext = 'png';
                 }
                 $filenames = $result['raw_name'] . '.' . $ext;
                 $idata['images'] = $filenames;
                 $folder_tam = ROOT . 'data/tam/' . $filename;
                 $folder_200 = ROOT . 'data/product/200/' . $filename;
                 $folder_500 = ROOT . 'data/product/500/' . $filename;
                 $this->load->helper('vimg');
                 @copy($folder_tam, $folder_500);
                 vnit_resize_image($folder_500, $folder_200, 220, 0, true);
                 unlink($folder_tam);
             }
         }
         $idata['cat_id'] = $vdata['cat_id'];
         $idata['is_new'] = (int) $vdata['is_new'];
         $idata['published'] = $vdata['published'];
         $idata['size'] = $vdata['size'];
         if ($this->db->update('product', $idata, array('id' => $id))) {
             $this->db->delete('product_des', array('id' => $id));
             for ($i = 0; $i < sizeof($this->language); $i++) {
                 $val1 = $this->language[0];
                 $val = $this->language[$i];
                 $cat = $this->product->get_slug_cat($vdata['cat_id'], $val->lang_id);
                 $vdes['id'] = $id;
                 $vdes['lang_id'] = $val->lang_id;
                 $vdes['title'] = $vdata['title'][$val->lang_id] != '' ? $vdata['title'][$val->lang_id] : $vdata['title'][$val1->lang_id];
                 $vdes['main_id'] = $cat->cat_id;
                 $vdes['slugcat'] = $cat->slug;
                 $vdes['slug'] = vnit_change_title($vdes['title']);
                 $vdes['price'] = str_replace(',', '', $vdata['price'][$val->lang_id]);
                 $vdes['gioithieu'] = $vdata['gioithieu'][$val->lang_id] != '' ? $vdata['gioithieu'][$val->lang_id] : $vdata['gioithieu'][$val1->lang_id];
                 $this->db->insert('product_des', $vdes);
             }
             $this->session->set_flashdata('message', 'Lưu thành công');
             $option = $_POST['option'];
             $otp = $this->request->post['otp'];
             if ($option == 'save') {
                 $url = site_url('product/ds/' . $otp['page_']) . '/?cat_id=' . $otp['cat_id_'] . '&key=' . $otp['key_'];
             } else {
                 $url = site_url('product/edit/' . $id . '/' . $otp['page_']) . '/?cat_id=' . $otp['cat_id_'] . '&key=' . $otp['key_'];
             }
             redirect($url);
         } else {
             $this->pre_message = "Lưu không thành công";
         }
     }
     $data['message'] = $this->pre_message;
     $this->load->templates('product/edit', $data, 'file');
 }