Exemplo n.º 1
0
 public function addevent()
 {
     if ($post = $this->input->post()) {
         $event = new Event_Model();
         $validation = new Validation($post);
         $validation->add_rules('title', 'required')->add_rules('location', 'required')->add_rules('start_date', 'required')->add_rules('end_date', 'required')->add_rules('tipul', 'required');
         $event->user_id = Auth::instance()->get_user()->id;
         $event->validate($validation, true);
         $event->save();
         url::redirect('day/' . date('Y-m-d', strtotime($event->start_date)));
     }
     $this->template->content = new View('calendar/addevent');
     $this->template->content->start_date = date('Y-m-d', strtotime($this->input->get('day', date('Y-m-d')))) . date(' H:i', strtotime('+10 minutes'));
     $this->template->content->end_date = date('Y-m-d', strtotime($this->input->get('day', date('Y-m-d')))) . date(' H:i', strtotime('+40 minutes'));
     $this->template->title = 'Manually Add An event';
 }
Exemplo n.º 2
0
 /**
  * Edit event
  *
  * @param  int|string  $event_id
  */
 public function _event_edit($event_id = false)
 {
     $this->history = false;
     $event = new Event_Model((int) $event_id);
     // For authenticated users only
     if (!$this->user || !$event->is_author() && !$this->visitor->logged_in(array('admin', 'event moderator'))) {
         url::back('/events');
     }
     $errors = $form_errors = array();
     $form_values = $event->as_array();
     $form_values['start_date'] = '';
     $form_values['start_hour'] = '';
     $form_values['end_hour'] = '';
     /***** CHECK POST *****/
     if (request::method() == 'post') {
         $post = array_merge($this->input->post(), $_FILES);
         $extra = array('start_time' => date::unix2sql(strtotime($post['start_date'] . ' ' . date::time_24h($post['start_hour']))));
         if (!empty($post['end_hour'])) {
             $end_time = strtotime($post['start_date']);
             // end hour is earlier than start hour = event ends the next day
             if ($post['end_hour'] < $post['start_hour']) {
                 $end_time = strtotime('+1 day', $end_time);
             }
             $extra['end_time'] = date('Y-m-d', $end_time) . ' ' . date::time_24h($post['end_hour']) . ':00';
         }
         // update
         $editing = (bool) $event->id;
         if ($editing) {
             $extra['modified'] = date::unix2sql(time());
             $extra['modifies'] = (int) $event->modifies + 1;
         } else {
             $extra['author_id'] = $this->user->id;
         }
         $city = ORM::factory('city', $post['city_id']);
         if ($city) {
             $extra['country_id'] = $city->country_id;
         }
         if (csrf::valid() && $event->validate($post, true, $extra)) {
             // Update tags
             $event->remove(ORM::factory('tag'));
             if (!empty($post['tags'])) {
                 foreach ($post['tags'] as $tag_id => $tag) {
                     $event->add(ORM::factory('tag', $tag_id));
                 }
                 $event->save();
             }
             // Handle flyer uploads
             foreach (array('flyer_front_image_id' => $post->flyer_front, 'flyer_back_image_id' => $post->flyer_back) as $image_id => $flyer) {
                 if (isset($flyer) && empty($flyer['error'])) {
                     $image = Image_Model::factory('events.flyer', $flyer, $this->user->id);
                     if ($image->id) {
                         $event->add($image);
                         $event->{$image_id} = $image->id;
                         $event->save();
                     }
                 }
             }
             if (!$editing) {
                 newsfeeditem_events::event($this->user, $event);
             }
             url::redirect(url::model($event));
         } else {
             $form_errors = $post->errors();
         }
         $form_values = arr::overwrite($form_values, $post->as_array());
     }
     /***** /CHECK POST *****/
     /***** SHOW FORM *****/
     if ($event->id) {
         $this->page_actions[] = array('link' => url::model($event) . '/delete/?token=' . csrf::token(), 'text' => __('Delete event'), 'class' => 'event-delete');
         $this->page_title = text::title($event->name);
         $this->page_subtitle = __('Edit event');
         list($form_values['start_date'], $form_values['start_hour']) = explode(' ', date('Y-m-d H', strtotime($event->start_time)));
         if (!empty($event->end_time)) {
             list($temp, $form_values['end_hour']) = explode(' ', date('Y-m-d H', strtotime($event->end_time)));
         }
     } else {
         $this->page_title = __('New event');
     }
     $form = $event->get_form();
     // Tags
     if ($tag_group = Kohana::config('events.tag_group')) {
         $form['tags'] = $form_values['tags'] = array();
         $tags = ORM::factory('tag_group', $tag_group);
         foreach ($tags->tags as $tag) {
             $form['tags'][$tag->id] = $tag->name;
             if ($event->has($tag)) {
                 $form_values['tags'][$tag->id] = $tag->name;
             }
         }
     }
     // City autocomplete
     $this->_autocomplete_city('city_name');
     // Venue autocomplete
     $venues = ORM::factory('venue')->where('event_host', '=', 1)->find_all();
     $hosts = array();
     foreach ($venues as $venue) {
         $hosts[] = "{ id: '" . $venue->id . "', text: '" . html::chars($venue->name) . "' }";
     }
     widget::add('foot', html::script_source('var venues = [' . implode(', ', $hosts) . "];\n\$('input[name=venue_name]').autocomplete(venues, {\n\tformatItem: function(item) {\n\t\treturn item.text;\n\t}\n}).result(function(event, item) {\n\t\$('input[name=venue_id]').val(item.id);\n});"));
     // Date pickers
     widget::add('foot', html::script_source("\$('input#start_date').datepicker({ dateFormat: 'd.m.yy', firstDay: 1, changeFirstDay: false, showOtherMonths: true, showWeeks: true, showStatus: true, showOn: 'both' });"));
     if (empty($errors)) {
         widget::add('main', View::factory('events/event_edit', array('form' => $form, 'values' => $form_values, 'errors' => $form_errors)));
     } else {
         //			$this->_error(Kohana::lang('generic.error'), $errors);
     }
     /***** /SHOW FORM *****/
     $this->_side_views();
 }