예제 #1
0
 public function addNew()
 {
     if (in_array(Auth::getCapability(), array(CAPABILITY_ADMINISTRATOR))) {
         Model::autoloadModel('city');
         $model = new CityModel($this->db);
         $this->para = new stdClass();
         if (isset($_POST['action']) && $_POST['action'] == "addNew") {
             $this->para->action = $_POST['action'];
             if (isset($_POST['name'])) {
                 $this->para->name = $_POST['name'];
             }
             if (isset($_POST['slug'])) {
                 $this->para->slug = $_POST['slug'];
             }
             if (isset($_POST['description'])) {
                 $this->para->description = $_POST['description'];
             }
             if (isset($_POST['country'])) {
                 $this->para->country = $_POST['country'];
             }
             if (isset($_POST['post_content_1'])) {
                 $this->para->post_content_1 = $_POST['post_content_1'];
             }
             if (isset($_POST['post_content_2'])) {
                 $this->para->post_content_2 = $_POST['post_content_2'];
             }
             if (isset($_POST['current_rating'])) {
                 $this->para->current_rating = $_POST['current_rating'];
             }
             if (isset($_POST['vote_times'])) {
                 $this->para->vote_times = $_POST['vote_times'];
             }
             if (isset($_POST['tag_list'])) {
                 $this->para->tag_list = $_POST['tag_list'];
             }
             if (isset($_FILES['images']) && count($_FILES['images']) > 0 && isset($_FILES['images']['name']) && isset($_FILES['images']['name'][0]) && $_FILES['images']['name'][0] != '') {
                 $this->para->images = $_FILES['images'];
             }
             $result = $model->addToDatabase($this->para);
             if (!$result) {
                 $this->view->para = $this->para;
             }
         }
         $this->view->countryList = new SplDoublyLinkedList();
         $model->getAllSorted($this->view->countryList, $model->buildTree($model->getAll("country")), -1);
         if (isset($_POST['ajax']) && !is_null($_POST['ajax'])) {
             $this->view->renderAdmin(RENDER_VIEW_CITY_ADD_NEW, TRUE);
         } else {
             $this->view->renderAdmin(RENDER_VIEW_CITY_ADD_NEW);
         }
     } else {
         $this->login();
     }
 }