Exemple #1
0
 public function action_update($cung_id)
 {
     $this->template->title = __('Sửa thông tin của cung');
     $this->template->section_title = __('Sửa thông tin của cung');
     $data = array();
     $cung_id = intval($cung_id);
     $cung = Model_Horoscope_CungBLL::GetCungById($cung_id);
     //print_r(Model_Horoscope_CungBLL::GetCungById_ToArray($cung_id));
     //print_r($cung->toArray());
     if ($cung) {
         //ok record found
         if (Request::$method == 'POST') {
             //begin check and update record
             #validate
             $post = $cung->validate_update($_POST);
             #Check that all fields are valid.
             if ($post->check()) {
                 //begin save
                 $post_values = $post->as_array();
                 $cung->ten_cung = trim(strip_tags($post_values['ten_cung']));
                 $cung->mieu_ta = str_replace(array("\r\n", "\r", "\n", "\t"), '', $post_values['mieu_ta']);
                 $cung->nhan_dang_chung = str_replace(array("\r\n", "\r", "\n", "\t"), '', $post_values['nhan_dang_chung']);
                 $cung->nhan_dang_nam = str_replace(array("\r\n", "\r", "\n", "\t"), '', $post_values['nhan_dang_nam']);
                 $cung->nhan_dang_nu = str_replace(array("\r\n", "\r", "\n", "\t"), '', $post_values['nhan_dang_nu']);
                 $cung->vi_tri = intval($post_values['vi_tri']);
                 //post date format : dd-mm-yyyy (need to convert -> sql style: yyyy-mm-dd)
                 list($d1, $m1, $y1) = explode('-', $post_values['tu_ngay']);
                 $cung->tu_ngay = '1970' . '-' . $m1 . '-' . $d1;
                 list($d2, $m2, $y2) = explode('-', $post_values['den_ngay']);
                 $cung->den_ngay = '1970' . '-' . $m2 . '-' . $d2;
                 $cung->save();
                 Request::instance()->redirect('admin/horoscope_cung/index');
             } else {
                 #Repopulate $_POST data
                 $_POST = $post->as_array();
                 //error
                 $data['errors'] = $post->errors();
                 //print_r($_POST);
             }
         }
         //EOF check postback
         $data['cung'] = $cung->toArray();
         //render view
         $this->template->content = View::factory('horoscope/admin/cung/update', $data);
     } else {
         //record not found
         Request::instance()->redirect('admin/horoscope_cung/index');
     }
 }
Exemple #2
0
 public function action_create($cung_id)
 {
     if (intval($cung_id) <= 0) {
         //not found
         Request::instance()->redirect('admin/horoscope_cung/index');
     }
     $cung = Model_Horoscope_CungBLL::GetCungById($cung_id);
     if ($cung) {
         $this->template->section_title = __('Thêm mới người nổi tiếng vào cung: ' . $cung->ten_cung);
         $this->template->title = __('Thêm mới người nổi tiếng vào cung: ' . $cung->ten_cung);
         if (Request::$method == "POST") {
             //print_r($_POST);
             $people = new Model_Horoscope_FamousPeople();
             $post = $people->validate_create($_POST);
             if ($post->check()) {
                 //validate file upload
                 $validate = Validate::factory($_FILES);
                 $validate->rules('hinh_anh', array('Upload::valid' => array(), 'Upload::not_empty' => array(), 'Upload::type' => array('Upload::type' => array('jpg', 'png', 'gif')), 'Upload::size' => array('1M')));
                 if ($validate->check()) {
                     //begin save
                     $post_values = $post->as_array();
                     $people->thuoc_cung = $cung->alias;
                     $people->ho_ten = $post_values['ho_ten'];
                     list($ngay, $thang, $nam) = explode('-', $post_values['ngay_sinh']);
                     $people->ngay_sinh = $nam . '-' . $thang . '-' . $ngay;
                     $people->mieu_ta = $post_values['mieu_ta'];
                     $save_dir = Model_Horoscope_FamousPeople::SAVE_DIR;
                     if (!file_exists($save_dir)) {
                         @mkdir($save_dir, $mode = 0777, $recursive = true);
                     }
                     $file_name = $people->_to_slug($people->ho_ten) . '.jpg';
                     $path = Upload::save($_FILES['hinh_anh'], $file_name, $save_dir, 0777);
                     $people->hinh_anh_1 = Model_Horoscope_FamousPeople::IMAGE_DIR . $file_name;
                     $people->hinh_anh_2 = Model_Horoscope_FamousPeople::IMAGE_DIR . $file_name;
                     $people->save();
                     Request::instance()->redirect('admin/horoscope_famous/index/' . $cung->id);
                 } else {
                     #Repopulate $_POST data
                     $_POST = $validate->as_array();
                     //error
                     $data['errors'] = $validate->errors();
                 }
             } else {
                 #Repopulate $_POST data
                 $_POST = $post->as_array();
                 //error
                 $data['errors'] = $post->errors();
             }
         }
         $data['cung_id'] = $cung_id;
         $this->template->content = View::factory('horoscope/admin/famous/create', $data);
     } else {
         //not found
         Request::instance()->redirect('admin/horoscope_cung/index');
     }
 }