group_number = $_SESSION['cms']['edit'][0]['group_number']; $this->group = &$_SESSION['cms']['edit'][0]['group']; $this->action = $_SESSION['cms']['edit'][0]['action']; $this->active = &$_SESSION['cms']['set_timer']['active']; $this->isTicket = ($this->action == "ticket"); if (!Timer::get ($this->active)) { $this->active = 0; } $this->status = $this->status (); } //*************************** // GETTER / SETTER //*************************** public function __get ($name) { switch ($name) { case "timers": return Timer::getList ($this->isTicket ? -1 : Ticket::selected ()); case "may_set_online": return ($this->isTicket ? Ticket::getEditRight () : $this->group['edit_right']) & Base::MODE_ONLINE; default: return $this->$name; } } public function __set ($name, $value) { } private function status () { $status = array (); $status['name'] = $_SESSION['cms']['edit'][0]['name']; $status['range'] = preg_replace ("/.*(group|list|ticket).*|.*/", "\\1", $this->action); $status['active'] = $this->active ? $this->active : (isset ($_SESSION['cms']['set_timer']['last']) ? $_SESSION['cms']['set_timer']['last'] : 0); $timer = $this->isTicket ? Ticket::getTimer () : (($status['range']) ? Group::getTimer ($this->group['id']) : $status['active']); $status['values'] = array ('timer' => "$timer", 'time' => ""); $status['now'] = date ("Y-m-d H:i:s"); //$status['parent_edit_groups'] = Group::getEditGroup ($this->group['id']); $status['messages'] = array (); $status['quickbar']['disabledButtons']['save'] = true; if (!History::getFirstUndo ($this->active, "timer", false)) { $status['quickbar']['disabledButtons']['undo'] = true; } if (!History::getFirstRedo ($this->active, "timer", false)) { $status['quickbar']['disabledButtons']['redo'] = true; } $status['quickbar']['disabledButtons']['edit'] = $this->active==0; $status['statusbar']['value'] = ""; // Elementname, User, letzte Änderung,... if (User::get ("is_admin")) { $status['statusbar']['value'] .= " #{$status['active']}"; } return $status; } public function select ($id) { $this->active = $id; $this->status = $this->status (); } public function save ($values) { $history = new History ("timer set"); $history->groupStart (); $this->active = isset ($values['timer']) ? $values['timer'] : 0; $time = isset ($values['time']) ? $values['time'] : ""; $action = preg_match ("/online/", $this->action) ? 1 : -1; if ($time && !preg_match ("/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/", $time)) { $this->status['messages'][] = array ('type' => "error", 'text' => I18n::tr ("edit", "set_timer/wrong time format", "wrong time format")); $this->status['quickbar']['disabledButtons']['save'] = true; return false; } if ($time && $time <= $this->status['now']) { $this->status['messages'][] = array ('type' => "error", 'text' => I18n::tr ("edit", "set_timer/given time in past", "given time in past")); $this->status['quickbar']['disabledButtons']['save'] = true; return false; } if ($time) { $this->active = Timer::setTime ($this->active, $time, $this->isTicket ? -1 : Ticket::selected (), !$this->isTicket); } if ($this->status['range'] == 'group') { if (!$this->group['id']) { // gelöschte Gruppen foreach (Group::getChildList ($this->group['parent_id'], $this->group['name'], true) as $row) { if ($row['status'] & (Base::STATUS_ERASED | Base::STATUS_ARCHIVED)) { Group::setTimer ($row['id'], $this->active*$action); } } } else { Group::setTimer ($this->group['id'], $this->active*$action); } } if ($this->status['range'] == 'list') { foreach (Group::getChildList ($this->group['parent_id'], $this->group['name']) as $row) { Group::setTimer ($row['id'], $this->active*$action); } } if ($this->status['range'] == 'ticket') { Ticket::setTimer (Ticket::selected (), $this->active); } $_SESSION['cms']['set_timer']['last'] = $this->active; $history->groupEnd(); return true; } public function undo () { if ($undo = History::getFirstUndo ($this->active, "timer", false)) { History::restore ($undo['id']); //$this->status = $this->status (); } } public function redo () { if ($redo = History::getFirstRedo ($this->active, "timer", false)) { History::restore ($redo['id']); //$this->status = $this->status (); } } public function message ($text) { return I18n::tr ("edit", "set_timer/$text", $text); } // Wandelt das gegebene Array/Text in eine Form um, die direkt einer JavaScript Variablen zugewiesen werden kann public function toJavaScript ($value) { if (is_array ($value)) { $values = array (); foreach ($value as $key => $val) { $values[] = "'$key':".$this->toJavaScript ($val); } return "{".implode (",", $values)."}"; } else { $value = Database::escape ($value); return ($value===true) ? "true" : (($value===false) ? "false" : "'$value'"); } } } ?>