Esempio n. 1
0
 /**
  * used to create a location, requires the hidden fields for the latatude and longatude.
  */
 public function create()
 {
     if ($this->access->allowed('locations', 'create')) {
         $input = Validation::factory($this->input->post())->pre_filter('trim')->add_rules('name', 'required')->add_rules('status', 'required')->add_rules('group', 'required')->add_rules('latitude', 'required')->add_rules('longitude', 'required')->add_rules('address', 'required');
         if ($input->validate()) {
             $location = orm::Factory('location');
             $location->name = $this->input->post('name');
             $location->description = $this->input->post('description');
             $location->url = $this->input->post('url');
             $location->status = $this->input->post('status');
             $location->group = $this->input->post('group');
             $location->order = orm::facrtory('location')->where('group', $this->input->post('group'))->count_all();
             $location->latitude = $this->input->post('latitude');
             $location->longitude = $this->input->post('longitude');
             $location->address = $this->input->post('address');
             $images = $this->input->post('images');
             $location->image = !is_null($images['logo']) ? $images['logo'] : 'logo.jpg';
             if ($location->save()) {
                 $this->notification->add($this->i18n['system.location.success'], $location->name);
                 $cms = DOCROOT . 'application/' . SITE . '/media/cms/locations/' . $location->id;
                 // this will create the folder
                 if (file::tree($cms)) {
                     $file = $location->image;
                     // if there was no image set, then use the default
                     if (isset($images)) {
                         $path = DOCROOT . 'upload/' . $location->image;
                         // use the uploaded file
                     } else {
                         $path = 'application/' . SITE . '/media/cms/locations/logo.jpg';
                     }
                     if (file_exists($path)) {
                         if (copy($path, $cms . '/' . $file)) {
                             $this->notification->add($this->i18n['cms.image.success']);
                         } else {
                             $this->notification->add($this->i18n['cms.image.error']);
                         }
                     } else {
                         $this->notification->add($this->i18n['cms.image.error']);
                     }
                 } else {
                     $this->notification->add($this->i18n['cms.folder.error']);
                 }
                 url::redirect(url::area() . 'edit/' . $location->id);
             } else {
                 $this->notification->add($this->i18n['system.location.error']);
             }
         } else {
             foreach ($input->errors() as $key => $value) {
                 $this->notification->add($this->i18n['filter.' . $key . '.' . $value]);
             }
         }
     }
     url::redirect(url::area() . 'add/');
     // name might not exist
 }