Beispiel #1
0
 /**
  * create actions
  */
 public function action_create()
 {
     $this->template->title = __('Thêm mới bài viết: xung - hợp cung');
     $this->template->section_title = __('Thêm mới bài viết: xung - hợp cung');
     $data = array();
     if (Request::$method == 'POST') {
         //print_r($_POST);
         $_story = new Model_Horoscope_XungHop();
         #Load the validation rules, filters and callbacks
         $post = $_story->validate_create($_POST);
         #Check that all fields are valid.
         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();
                 //unset($post);
                 //die(var_dump($post_values));
                 $_story->alias = $post_values['alias'];
                 $_story->cung_1 = $post_values['cung_1'];
                 $_story->cung_2 = $post_values['cung_2'];
                 //die(print_r($_FILES));
                 //save(array $file, $filename = NULL, $directory = NULL, $chmod = 0644)
                 $save_dir = 'assets/horoscope/xung-hop/';
                 if (!file_exists($save_dir)) {
                     @mkdir($save_dir, $mode = 0777, $recursive = true);
                 }
                 $file_name = $_story->alias . '.jpg';
                 $path = Upload::save($_FILES['hinh_anh'], $_story->alias . '.jpg', $save_dir, 0777);
                 //die(print_r($path));
                 $_story->hinh_anh = "/" . $save_dir . $file_name;
                 $_story->tom_tat = trim($post_values['tom_tat']);
                 $_story->noi_dung = trim($post_values['noi_dung']);
                 $_story->url_nguon = trim($post_values['url_nguon']);
                 $_story->ngay_tao = date("Y-m-d");
                 $_story->kiem_tra = 'yes';
                 $_story->auto_get = false;
                 $_story->source_date = $_story->ngay_tao;
                 //post date format : dd-mm-yyyy (need to convert -> sql style: yyyy-mm-dd)
                 //die(print_r($_story->alias));
                 $_story->save();
                 Request::instance()->redirect('admin/horoscope_xunghop/index');
             } else {
                 #Repopulate $_POST data
                 $_POST = $post->as_array();
                 //error
                 $data['errors'] = $validate->errors();
             }
         } else {
             //die("check done");
             #Repopulate $_POST data
             //$_POST = array_intersect_key($post->as_array(), $_POST);
             $_POST = $post->as_array();
             #Affects errors for further display
             $data['errors'] = $post->errors();
         }
     }
     $data['stories'] = Model_Horoscope_CungBLL::GetAllCungForListing();
     $this->template->content = View::factory('horoscope/admin/xung-hop/create', $data);
 }
Beispiel #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');
     }
 }
Beispiel #3
0
 public function action_create()
 {
     $this->template->title = __('Thêm mới cung');
     $this->template->section_title = __('Thêm mới cung');
     $data = array();
     if (Request::$method == 'POST') {
         $_cung = new Model_Horoscope_Cung();
         #Load the validation rules, filters and callbacks
         $post = $_cung->validate_create($_POST);
         #Check that all fields are valid.
         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();
                 //unset($post);
                 //die(var_dump($post_values));
                 $_cung->alias = $post_values['alias'];
                 //die(print_r($_FILES));
                 //save(array $file, $filename = NULL, $directory = NULL, $chmod = 0644)
                 $path = Upload::save($_FILES['hinh_anh'], $_cung->alias . '.jpg', 'assets/horoscope/cung/', 0777);
                 //die(print_r($path));
                 $_cung->ten_cung = $post_values['ten_cung'];
                 $_cung->hinh_anh = $path;
                 $_cung->mieu_ta = $post_values['mieu_ta'];
                 $_cung->nhan_dang_chung = $post_values['nhan_dang_chung'];
                 $_cung->nhan_dang_nam = $post_values['nhan_dang_nam'];
                 $_cung->nhan_dang_nu = $post_values['nhan_dang_nu'];
                 $_cung->vi_tri = $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'] = $validate->errors();
             }
         } else {
             //die("check done");
             #Repopulate $_POST data
             //$_POST = array_intersect_key($post->as_array(), $_POST);
             $_POST = $post->as_array();
             #Affects errors for further display
             $data['errors'] = $post->errors();
         }
     }
     $added_cungs = Model_Horoscope_CungBLL::GetAllAddedCung();
     $data['added'] = $added_cungs;
     $this->template->content = View::factory('horoscope/admin/cung/create', $data);
 }