config['tableenv'])) { $this->config['tableenv'] = self::TABLE_ENV_CALENDAREVENT; } $this->config['requiredgroup'] = 'calendar-staff'; $this->config['requiredgroupmanager'] = 'calendar-staff'; $this->config['searchfields'] = array(); $this->config['usefilter'] = 1; $this->config['addcurrentuser'] = 'new'; $this->config['translator'] = 'no'; $this->config['limit'] = 25; switch ($this->config['tableenv']) { case self::TABLE_ENV_CALENDAR: $this->config['table'] = WBDatasource::TABLE_CALENDAR; $this->config['searchfields'] = array('title', 'brief'); break; default: case self::TABLE_ENV_CALENDAREVENT: $this->config['table'] = WBDatasource::TABLE_CALENDAREVENT; $this->config['searchfields'] = array('title', 'brief', 'blurb'); break; } // tweak permissions if (!$this->isUserInGroup($this->config['requiredgroup'])) { $this->config['action'] = 'edit'; } // call parent's init parent::init(); $this->addFiddler4Mandator(); } /** * Prepare List Entries 4 Template * * @param array * @return array */ protected function prepareListEntry($list) { $list = parent::prepareListEntry($list); if (self::TABLE_ENV_CALENDAR == $this->config['tableenv']) { foreach ($list as &$l) { $l['record_editable'] = 0; // allow to edit all records with id larger than 999 $id = array_pop(explode('-', $l['id'])); if (3 < strlen($id)) { $l['record_editable'] = 1; continue; } // master may edit eveything if (!$this->mandator->isEnabled() || $this->mandator->isMaster()) { $l['record_editable'] = 1; continue; } } } if (self::TABLE_ENV_CALENDAREVENT != $this->config['tableenv']) { return $list; } foreach ($list as &$l) { $tmp = explode(' ', $l['timestampstart']); $l['timestampstart_day'] = $tmp[0]; $l['timestampstart_time'] = $tmp[1]; $tmp = explode(' ', $l['timestampend']); $l['timestampend_day'] = $tmp[0]; $l['timestampend_time'] = $tmp[1]; } return $list; } /** * Auxiliary Function to Show Edit form * * @used by runClone() * @used by runEdit() * @param array */ protected function runPreparedEdit($p) { if (self::TABLE_ENV_CALENDAREVENT != $this->config['tableenv']) { parent::runPreparedEdit($p); return; } if (empty($p)) { $p['timestampstart'] = date('Y-m-d 00:00:00'); $p['timestampend'] = $p['timestampstart']; $p['timestampend_use_checked'] = ''; $p['time_use_checked'] = ''; $p['timestart'] = '00:00'; $p['timeend'] = '00:00'; $p['calendareventrepeattypeid'] = 1; $p['repeatuntil_min'] = date('Y-m-d'); // today $p['repeatuntil_max'] = date('Y-m-d', time() + 31536001); // next year parent::runPreparedEdit($p); return; } // fix invalid start date if ('1970-01-01 00:00:00' == $p['timestampstart']) { $p['timestampstart'] = date('Y-m-d 00:00:00'); } $p['timestampend_use_checked'] = ''; $ts1 = array_shift(explode(' ', $p['timestampend'])); if (!empty($ts1) && '1970-01-01' != $ts1) { $p['timestampend_use_checked'] = 'checked="checked"'; } $p['time_use_checked'] = ''; $t0 = array_pop(explode(' ', $p['timestampstart'])); $t1 = array_pop(explode(' ', $p['timestampend'])); if ('00:00:00' != $t0 || '00:00:00' != $t1) { $p['time_use_checked'] = 'checked="checked"'; } // only hours and minutes $p['timestart'] = substr($t0, 0, 5); $p['timeend'] = substr($t1, 0, 5); if ('1970-01-01' == $ts1) { $p['timestampend'] = $p['timestampstart']; } parent::runPreparedEdit($p); } /** * Save Primary Records in DB * * Use method of parent class, but not for schedule * * Allow to set timestampend based on switch. * * @param bool true if database record is new * @param array validated form values to be saved * @return string id of saved record */ protected function saveRecord($new, $values) { if (self::TABLE_ENV_CALENDAREVENT != $this->config['tableenv']) { return parent::saveRecord($new, $values); } // times $t0 = '00:00:00'; $t1 = '00:00:00'; if ($this->req->get('time_use', 0)) { $tt0 = $this->req->get('timestart', '00:00'); $tt1 = $this->req->get('timeend', '00:00'); if (preg_match('/[012]\\d:[0-5]\\d/', $tt0) && preg_match('/[012]\\d:[0-5]\\d/', $tt1) ){ $t0 = $tt0 . ':00'; $t1 = $tt1 . ':00'; } } if ($this->req->get('timestampend_use', 0)) { $ts0 = strtotime(array_shift(explode(' ', $values['timestampstart']))); $ts1 = strtotime(array_shift(explode(' ', $values['timestampend']))); if ($ts0 > $ts1) { $ts1 = 0; $values['timestampend'] = '1970-01-01'; } } else { $values['timestampend'] = '1970-01-01'; } $ts0 = explode(' ', $values['timestampstart']); $ts0[1] = $t0; $values['timestampstart'] = implode(' ', $ts0); $ts1 = explode(' ', $values['timestampend']); $ts1[1] = $t1; $values['timestampend'] = implode(' ', $ts1); $values['repeatuntil'] = $this->req->get('repeatuntil', ''); $this->startCalenderEventDatasource(); if ($new) { $this->dsce->add($values); } else { $this->dsce->loadById($this->config['id']); $this->dsce->save($values); } return $this->dsce->getId(); } /** * Actually Run Action: Delete * * Override parent method for calender events * * @param array * @param string * @param string * @return bool */ protected function runRm($p, $foreign, $tmplDir) { if (self::TABLE_ENV_CALENDAREVENT != $this->config['tableenv']) { return parent::runRm($p, $foreign, $tmplDir); } // action and id required if ('rm' != $this->config['action'] || '__new' == $this->id) { return false; } // load and verify record $this->startCalenderEventDatasource(); $this->dsce->loadById($this->id); if (!$this->dsce->isOK()) { return false; } // special behaviour for recurrence events $p['isrecurrence'] = intval($this->dsce->isRecurrence()); $this->tmpl->addGlobalVars($p); $which = $this->req->get('which', '__not_set'); switch ($which) { case WBDatasource_Calendar_Event::DELETE_TYPE_ALL: case WBDatasource_Calendar_Event::DELETE_TYPE_FUTURE: case WBDatasource_Calendar_Event::DELETE_TYPE_CURRENT: break; default: $which = WBDatasource_Calendar_Event::DELETE_TYPE_CURRENT; break; } // Ask: Do you really want to delete this record? if (empty($which) || 'yes' != $this->req->get('force', 'no')) { $this->loadTemplates('rm'); $this->config['tmplDir'] = $tmplDir; return true; } // actually delete $this->dsce->delete($which); $this->loadTemplates('rmDeleted'); $this->config['tmplDir'] = $tmplDir; return true; } /** * Init Calender Object * */ private function startCalenderEventDatasource() { if (!empty($this->dsce)) { return; } $parameter = array( 'table' => $this->table, 'mandator' => $this->mandator ); $this->dsce = WBClass::create('WBDatasource_Calendar_Event', $parameter); } /** * Fetch List of Form Elements * * Use parent's method and add translators form elements * * @param string name of the xml- and template-filename * @return array $elements */ protected function getFormElementList($name) { $elements = parent::getFormElementList($name); if (self::TABLE_ENV_CALENDAREVENT != $this->config['tableenv']) { return $elements; } // don't allow to change repeat type if ('__new' != $this->config['id']) { unset($elements[$this->table->getIdentifier(WBDatasource::TABLE_CALENDAREVENTREPEATTYPE, true)]); } return $elements; } /** * Location of Form Config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return 'calendar/manager/' . $this->config['tableenv']; } }