Example #1
0
 /**
  * Short description for 'edit'
  *
  * Long description (if any) ...
  *
  * @param      mixed $row Parameter description (if any) ...
  * @return     unknown Return description (if any) ...
  */
 public function editTask($row = NULL)
 {
     // Check if they are logged in
     if (User::isGuest()) {
         if (Pathway::count() <= 0) {
             Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option);
         }
         Pathway::append(Lang::txt('EVENTS_CAL_LANG_ADD_TITLE'), 'index.php?option=' . $this->_option . '&task=add');
         $this->loginTask();
         return;
     }
     // We need at least one category before we can proceed
     $cat = new Category($this->database);
     if ($cat->getCategoryCount($this->_option) < 1) {
         throw new Exception(Lang::txt('EVENTS_LANG_NEED_CATEGORY'), 500);
     }
     // Incoming
     $id = Request::getInt('id', 0, 'request');
     // Load event object
     if (!is_object($row)) {
         $row = new Event($this->database);
         $row->load($id);
     }
     // Do we have an ID?
     if ($row->id) {
         // Yes - edit mode
         // Are they authorized to make edits?
         if (!$this->_authorize($row->created_by) && !(User::get('id') == $row->created_by)) {
             // Not authorized - redirect
             App::redirect(Route::url('index.php?option=' . $this->_option));
             return;
         }
         //get timezone
         $time_zone = $row->time_zone;
         // get start date and time
         $start_publish = Date::of($row->publish_up, $time_zone)->format('Y-m-d', true);
         $start_time = Date::of($row->publish_up, $time_zone)->format('H:i', true);
         // get end date and time
         $stop_publish = Date::of($row->publish_down, $time_zone)->format('Y-m-d', true);
         $end_time = Date::of($row->publish_down, $time_zone)->format('H:i', true);
         $registerby_date = Date::of($row->registerby, $time_zone)->format('Y-m-d', true);
         $registerby_time = Date::of($row->registerby, $time_zone)->format('H:i', true);
         $arr = array(\Html::select('option', 0, strtolower(Lang::txt('EVENTS_NO')), 'value', 'text'), \Html::select('option', 1, strtolower(Lang::txt('EVENTS_YES')), 'value', 'text'));
         $lists['state'] = \Html::select('genericlist', $arr, 'state', '', 'value', 'text', $row->state, false, false);
     } else {
         if ($row->publish_up && $row->publish_up != '0000-00-00 00:00:00') {
             $event_up = new EventsDate($row->publish_up);
             $start_publish = sprintf("%4d-%02d-%02d", $event_up->year, $event_up->month, $event_up->day);
             $start_time = $event_up->hour . ':' . $event_up->minute;
             $event_down = new EventsDate($row->publish_down);
             $stop_publish = sprintf("%4d-%02d-%02d", $event_down->year, $event_down->month, $event_down->day);
             $end_time = $event_down->hour . ':' . $event_down->minute;
             $time_zone = $row->time_zone;
             $event_registerby = new EventsDate($row->registerby);
             $registerby_date = sprintf("%4d-%02d-%02d", $event_registerby->year, $event_registerby->month, $event_registerby->day);
             $registerby_time = $event_registerby->hour . ':' . $event_registerby->minute;
         } else {
             // No ID - we're creating a new event
             $year = $this->year;
             $month = $this->month;
             $day = $this->day;
             if ($year && $month && $day) {
                 $start_publish = $year . '-' . $month . '-' . $day;
                 $stop_publish = $year . '-' . $month . '-' . $day;
                 $registerby_date = $year . '-' . $month . '-' . $day;
             } else {
                 $offset = $this->offset;
                 $start_publish = strftime("%Y-%m-%d", time() + $offset * 60 * 60);
                 //date("Y-m-d");
                 $stop_publish = strftime("%Y-%m-%d", time() + $offset * 60 * 60);
                 //date("Y-m-d");
                 $registerby_date = strftime("%Y-%m-%d", time() + $offset * 60 * 60);
                 //date("Y-m-d");
             }
             $start_time = "08:00";
             $end_time = "17:00";
             $registerby_time = "08:00";
             $time_zone = -5;
         }
         // If user hits refresh, try to maintain event form state
         $row->bind($_POST);
         $row->created_by = User::get('id');
         $lists = '';
     }
     // Get custom fields
     $fields = $this->config->getCfg('fields');
     if (!empty($fields)) {
         for ($i = 0, $n = count($fields); $i < $n; $i++) {
             // Explore the text and pull out all matches
             array_push($fields[$i], self::parseTag($row->content, $fields[$i][0]));
             // Clean the original text of any matches
             $row->content = str_replace('<ef:' . $fields[$i][0] . '>' . end($fields[$i]) . '</ef:' . $fields[$i][0] . '>', '', $row->content);
         }
         $row->content = trim($row->content);
     }
     list($start_hrs, $start_mins) = explode(':', $start_time);
     list($end_hrs, $end_mins) = explode(':', $end_time);
     list($registerby_hrs, $registerby_mins) = explode(':', $registerby_time);
     $start_pm = false;
     $end_pm = false;
     $registerby_pm = false;
     if ($this->config->getCfg('calUseStdTime') == 'YES') {
         $start_hrs = intval($start_hrs);
         if ($start_hrs >= 12) {
             $start_pm = true;
         }
         if ($start_hrs > 12) {
             $start_hrs -= 12;
         } else {
             if ($start_hrs == 0) {
                 $start_hrs = 12;
             }
         }
         if (strlen($start_mins) == 1) {
             $start_mins = '0' . $start_mins;
         }
         $start_time = $start_hrs . ':' . $start_mins;
         $end_hrs = intval($end_hrs);
         if ($end_hrs >= 12) {
             $end_pm = true;
         }
         if ($end_hrs > 12) {
             $end_hrs -= 12;
         } else {
             if ($end_hrs == 0) {
                 $end_hrs = 12;
             }
         }
         $registerby_hrs = intval($registerby_hrs);
         if ($registerby_hrs >= 12) {
             $registerby_pm = true;
         }
         if ($registerby_hrs > 12) {
             $registerby_hrs -= 12;
         } else {
             if ($registerby_hrs == 0) {
                 $registerby_hrs = 12;
             }
         }
         if (strlen($registerby_mins) == 1) {
             $registerby_mins = '0' . $registerby_mins;
         }
         $registerby_time = $registerby_hrs . ':' . $registerby_mins;
     }
     if (strlen($start_mins) == 1) {
         $start_mins = '0' . $start_mins;
     }
     if (strlen($start_hrs) == 1) {
         $start_hrs = '0' . $start_hrs;
     }
     $start_time = $start_hrs . ':' . $start_mins;
     if (strlen($end_mins) == 1) {
         $end_mins = '0' . $end_mins;
     }
     if (strlen($end_hrs) == 1) {
         $end_hrs = '0' . $end_hrs;
     }
     $end_time = $end_hrs . ':' . $end_mins;
     if (strlen($registerby_mins) == 1) {
         $registerby_mins = '0' . $registerby_mins;
     }
     if (strlen($registerby_hrs) == 1) {
         $registerby_hrs = '0' . $registerby_hrs;
     }
     $registerby_time = $registerby_hrs . ':' . $registerby_mins;
     $times = array();
     $times['start_publish'] = $start_publish;
     $times['start_time'] = $start_time;
     $times['start_pm'] = $start_pm;
     $times['stop_publish'] = $stop_publish;
     $times['end_time'] = $end_time;
     $times['end_pm'] = $end_pm;
     $times['time_zone'] = $time_zone;
     $times['registerby_date'] = $registerby_date;
     $times['registerby_time'] = $registerby_time;
     $times['registerby_pm'] = $registerby_pm;
     // Get tags on this event
     $lists['tags'] = '';
     if ($row->id) {
         $rt = new Tags($row->id);
         $lists['tags'] = $rt->render('string');
     }
     // get tags passed from failed save
     if (isset($this->tags)) {
         $lists['tags'] = $this->tags;
     }
     // Set the title
     Document::setTitle(Lang::txt(strtoupper($this->_name)) . ': ' . Lang::txt(strtoupper($this->_name) . '_' . strtoupper($this->_task)));
     // Set the pathway
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option);
     }
     $p = 'index.php?option=' . $this->_option . '&task=' . $this->_task;
     if ($row->id) {
         $p .= '&id=' . $row->id;
     }
     Pathway::append(Lang::txt(strtoupper($this->_name) . '_' . strtoupper($this->_task)), $p);
     if ($row->id) {
         Pathway::append(stripslashes($row->title), 'index.php?option=' . $this->_option . '&task=details&id=' . $row->id);
     }
     // Output HTML
     $this->view->setLayout('default')->setName('edit');
     $this->view->option = $this->_option;
     $this->view->title = Lang::txt(strtoupper($this->_name)) . ': ' . Lang::txt(strtoupper($this->_name) . '_' . strtoupper($this->_task));
     $this->view->task = $this->_task;
     $this->view->config = $this->config;
     $this->view->row = $row;
     $this->view->fields = $fields;
     $this->view->times = $times;
     $this->view->lists = $lists;
     $this->view->gid = $this->gid;
     $this->view->admin = $this->_authorize();
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     $this->view->display();
 }
Example #2
0
 /**
  * Display a form for editing an entry
  *
  * @return     void
  */
 public function editTask()
 {
     Request::setVar('hidemainmenu', 1);
     // Instantiate a new view
     $this->view->setLayout('edit');
     $this->view->config = $this->config;
     $offset = Config::get('offset');
     // We need at least one category before we can proceed
     $cat = new Category($this->database);
     if ($cat->getCategoryCount($this->_option) < 1) {
         throw new Exception(Lang::txt('COM_EVENTS_LANG_NEED_CATEGORY'), 500);
     }
     // Incoming
     $id = Request::getVar('id', array(), 'request');
     if (is_array($id)) {
         $id = !empty($id) ? $id[0] : 0;
     }
     // Load the event object
     $this->view->row = new Event($this->database);
     $this->view->row->load($id);
     // Fail if checked out not by 'me'
     if ($this->view->row->checked_out && $this->view->row->checked_out != User::get('id')) {
         $this->_redirect = 'index.php?option=' . $this->_option;
         $this->_message = Lang::txt('COM_EVENTS_CAL_LANG_WARN_CHECKEDOUT');
     }
     $this->css('calendar.css');
     if ($this->view->row->id) {
         $this->view->row->checkout(User::get('id'));
         if (trim($this->view->row->publish_down) == '0000-00-00 00:00:00') {
             $this->view->row->publish_down = Lang::txt('COM_EVENTS_CAL_LANG_NEVER');
         }
         $start_publish = Date::of($this->view->row->publish_up)->toLocal('Y-m-d');
         $start_time = Date::of($this->view->row->publish_up)->toLocal('H:i');
         // make sure the never setting doesn't throw an error
         if ($this->view->row->publish_down != 'Never') {
             $stop_publish = Date::of($this->view->row->publish_down)->toLocal('Y-m-d');
             $end_time = Date::of($this->view->row->publish_down)->toLocal('H:i');
         } else {
             $end_time = '00:00';
             $stop_publish = '0000-00-00';
         }
     } else {
         $this->view->row->state = 0;
         $start_publish = Date::format('Y-m-d');
         $stop_publish = Date::format('Y-m-d');
         $start_time = "08:00";
         $end_time = "17:00";
     }
     // Get list of groups
     $this->database->setQuery("SELECT 0 AS value, 'Public' AS text");
     $groups = $this->database->loadObjectList();
     $this->view->fields = $this->config->getCfg('fields');
     if (!empty($this->view->fields)) {
         for ($i = 0, $n = count($this->view->fields); $i < $n; $i++) {
             // explore the text and pull out all matches
             array_push($this->view->fields[$i], $this->parseTag($this->view->row->content, $this->view->fields[$i][0]));
             // clean the original text of any matches
             $this->view->row->content = str_replace('<ef:' . $this->view->fields[$i][0] . '>' . end($this->view->fields[$i]) . '</ef:' . $this->view->fields[$i][0] . '>', '', $this->view->row->content);
         }
         $this->view->row->content = trim($this->view->row->content);
     }
     list($start_hrs, $start_mins) = explode(':', $start_time);
     list($end_hrs, $end_mins) = explode(':', $end_time);
     $start_pm = false;
     $end_pm = false;
     if ($this->config->getCfg('calUseStdTime') == 'YES') {
         $start_hrs = intval($start_hrs);
         if ($start_hrs >= 12) {
             $start_pm = true;
         }
         if ($start_hrs > 12) {
             $start_hrs -= 12;
         } else {
             if ($start_hrs == 0) {
                 $start_hrs = 12;
             }
         }
         $end_hrs = intval($end_hrs);
         if ($end_hrs >= 12) {
             $end_pm = true;
         }
         if ($end_hrs > 12) {
             $end_hrs -= 12;
         } else {
             if ($end_hrs == 0) {
                 $end_hrs = 12;
             }
         }
     }
     if (strlen($start_mins) == 1) {
         $start_mins = '0' . $start_mins;
     }
     if (strlen($start_hrs) == 1) {
         $start_hrs = '0' . $start_hrs;
     }
     $start_time = $start_hrs . ':' . $start_mins;
     if (strlen($end_mins) == 1) {
         $end_mins = '0' . $end_mins;
     }
     if (strlen($end_hrs) == 1) {
         $end_hrs = '0' . $end_hrs;
     }
     $end_time = $end_hrs . ':' . $end_mins;
     $this->view->times = array();
     $this->view->times['start_publish'] = $start_publish;
     $this->view->times['start_time'] = $start_time;
     $this->view->times['start_pm'] = $start_pm;
     $this->view->times['stop_publish'] = $stop_publish;
     $this->view->times['end_time'] = $end_time;
     $this->view->times['end_pm'] = $end_pm;
     // only load tags if the event exists already
     if ($this->view->row->id != NULL) {
         // Get tags on this event
         $rt = new Tags($this->view->row->id);
         $this->view->tags = $rt->render('string');
     }
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->display();
 }