/**
  * read_preset_form generates a quickform-object to choose the announcement-preset,
  * if validated redirect to announcement.php?id=new&cid=$id
  * 
  * @param object $calendar the actual calendarentry
  * @return object quickform-object to choose the preset, if validated redirect to new announcement
  */
 private function read_preset_form(&$calendar)
 {
     // check sort or from/to
     $sort = $from = $to = '';
     if ($this->get('sort') !== false) {
         $sort = "&sort=" . $this->get('sort');
     }
     if ($this->get('from') !== false) {
         $from = "&from=" . $this->get('from');
     }
     if ($this->get('to') !== false) {
         $to = "&to=" . $this->get('to');
     }
     // form-object
     $form = new HTML_QuickForm2('choose_preset_' . $calendar->get_id(), 'post', array('name' => 'choose_preset_' . $calendar->get_id(), 'action' => 'calendar.php?id=listall' . $sort . $from . $to));
     // add selectfield
     $select = $form->addSelect('preset', array());
     $options = array(0 => parent::lang('class.CalendarView#read_preset_form#select#choosePreset'));
     $options = $options + Preset::read_all_presets('calendar');
     $select->loadOptions($options);
     $select->addRule('callback', parent::lang('class.CalendarView#read_preset_form#rule#select'), array($this, 'callback_check_select'));
     // add submit
     $submit = $form->addSubmit('submit', array('value' => parent::lang('class.CalendarView#read_preset_form#select#submit')));
     // validate
     if ($form->validate()) {
         // get data
         $data = $form->getValue();
         // insert preset_id in calendar-entry
         $update = array('preset_id' => $data['preset']);
         $calendar->update($update);
         $calendar->write_db('update');
         // redirect to listall
         header('Location: calendar.php?id=listall' . $sort . $from . $to);
         exit;
     } else {
         return $form;
     }
 }
 /**
  * shows the details of the entry
  * 
  * @return string html-string
  */
 private function details()
 {
     // check cid and pid given
     if ($this->get('cid') !== false && $this->get('pid') !== false) {
         // check cid and pid exists
         if (Calendar::check_id($this->get('cid')) && Preset::check_preset($this->get('pid'), 'calendar')) {
             // check if announcement has values
             if (Calendar::check_ann_value($this->get('cid'))) {
                 // pagecaption
                 $this->tpl->assign('pagecaption', parent::lang('class.AnnouncementView#page#caption#details'));
                 // prepare return
                 $return = '';
                 // get preset
                 $preset = new Preset($this->get('pid'), 'calendar', $this->get('cid'));
                 // smarty
                 $sA = new JudoIntranetSmarty();
                 // get calendar
                 $calendar = new Calendar($this->get('cid'));
                 // prepare marker-array
                 $announcement = array('version' => date('dmy'));
                 // add calendar-fields to array
                 $calendar->add_marks($announcement);
                 // add field-names and -values to array
                 $preset->add_marks($announcement);
                 // smarty
                 $sA->assign('a', $announcement);
                 // check marks in values
                 foreach ($announcement as $k => $v) {
                     if (preg_match('/\\{\\$a\\..*\\}/U', $v)) {
                         $announcement[$k] = $sA->fetch('string:' . $v);
                     }
                 }
                 // smarty
                 $sA->assign('a', $announcement);
                 $div_out = $sA->fetch($preset->get_path());
                 // smarty
                 $sAd = new JudoIntranetSmarty();
                 $sAd->assign('page', $div_out);
                 return $sAd->fetch('smarty.announcement.details.tpl');
             } else {
                 // error
                 $errno = $GLOBALS['Error']->error_raised('AnnNotExists', 'entry:' . $this->get('cid') . '|' . $this->get('pid'), $this->get('cid') . '|' . $this->get('pid'));
                 $GLOBALS['Error']->handle_error($errno);
                 return $GLOBALS['Error']->to_html($errno);
             }
         } else {
             // error
             $errno = $GLOBALS['Error']->error_raised('WrongParams', 'entry:cid_or_pid', 'cid_or_pid');
             $GLOBALS['Error']->handle_error($errno);
             return $GLOBALS['Error']->to_html($errno);
         }
     } else {
         // error
         $errno = $GLOBALS['Error']->error_raised('MissingParams', 'entry:cid_or_pid', 'cid_or_pid');
         $GLOBALS['Error']->handle_error($errno);
         return $GLOBALS['Error']->to_html($errno);
     }
 }
 /**
  * decissions shows the decissions of this or all protocols
  * 
  * @param int $pid entry-id for protocol
  * @return string html of the decissions page
  */
 private function decisions($pid)
 {
     // pagecaption
     $this->tpl->assign('pagecaption', parent::lang('class.ProtocolView#page#caption#decisions'));
     // check rights
     if (Rights::check_rights($pid, 'protocol', true) || $pid == false) {
         // prepare template
         $sD = new JudoIntranetSmarty();
         // check pid all or single
         if ($pid === false) {
             // get protocol ids
             $pids = Protocol::return_protocols();
             // create protocol objects to sort
             $protocols = array();
             foreach ($pids as $pid) {
                 $protocols[] = new Protocol($pid);
             }
             // sort array by protocols date
             usort($protocols, array($this, 'callback_compare_protocols'));
             // walk through ids
             $counter = 0;
             foreach ($protocols as $protocol) {
                 // assign data
                 $data[$counter] = array('date' => $protocol->get_date('d.m.Y'), 'type' => $protocol->get_type(), 'location' => $protocol->get_location(), 'decisions' => $this->parseHtml($protocol->get_protocol(), '<p class="tmceDecision">|</p>'));
                 // check if protocol has decisions
                 if (count($data[$counter]['decisions']) == 0) {
                     unset($data[$counter]);
                 }
                 $data = array_merge($data);
                 // add to template
                 $sD->assign('data', $data);
                 // increment counter
                 $counter++;
             }
         } else {
             // get protocol object
             $protocol = new Protocol($pid);
             // assign data
             $data[] = array('date' => $protocol->get_date('d.m.Y'), 'type' => $protocol->get_type(), 'location' => $protocol->get_location(), 'decisions' => $this->parseHtml($protocol->get_protocol(), '<p class="tmceDecision">|</p>'));
             // add to template
             $sD->assign('data', $data);
         }
         // return
         return $sD->fetch('smarty.protocol.showdecisions.tpl');
     } else {
         // error
         $errno = $GLOBALS['Error']->error_raised('NotAuthorized', 'entry:' . $this->get('id'), $this->get('id'));
         $GLOBALS['Error']->handle_error($errno);
         return $GLOBALS['Error']->to_html($errno);
     }
 }
 /**
  * get_movements returns the htmlstring of the movements
  * 
  * @param object $inventory the inventory object
  * @return string html of the movement list
  */
 private function get_movements($inventory)
 {
     // get id
     $id = $inventory->get_id();
     // get preset
     $preset = $inventory->get_preset();
     // get fields
     $fields = $preset->get_fields();
     // get db-object
     $db = Db::newDb();
     // prepare sql-statement
     $sql = "SELECT u.name,m.id,m.date_time\n\t\t\t\tFROM user AS u, inventory_movement AS m\n\t\t\t\tWHERE m.action = 'taken'\n\t\t\t\tAND m.inventory_id = {$id}\n\t\t\t\tAND u.id = m.user_id\n\t\t\t\tORDER BY m.date_time DESC";
     // execute
     $result = $db->query($sql);
     $movements = array();
     while (list($name, $movement_id, $date_time) = $result->fetch_array(MYSQL_NUM)) {
         // smarty
         $movements[] = array('href' => 'inventory.php?id=movement&mid=' . $movement_id, 'title' => parent::lang('class.InventoryView#get_movements#date#title'), 'content' => date('d.m.Y', strtotime($date_time)), 'name' => $name);
     }
     // return
     return $movements;
 }
 /**
  * defaults handles the administration of the default-values
  * 
  * @return string html-string with the field-administration-page
  */
 private function defaults()
 {
     // prepare content
     $content = '';
     $rid = $this->get('rid');
     // check $_GET['field']
     if ($this->get('rid') !== false || $this->get('action') == 'new') {
         // pagecaption
         $this->tpl->assign('pagecaption', parent::lang('class.AdministrationView#page#caption#defaults'));
         // check if row exists
         if ($this->row_exists('defaults', $rid) || $this->get('action') == 'new') {
             // check $_GET['action']
             if ($this->get('action') == 'new') {
                 $content .= $this->new_row('defaults');
             } elseif ($this->get('action') == 'edit') {
                 $content .= $this->edit_row('defaults', $rid);
             } elseif ($this->get('action') == 'disable') {
                 // check if row is enabled
                 if ($this->is_valid('defaults', $rid)) {
                     // set valid 0
                     $this->set_valid('defaults', $rid, 0);
                     // list table content
                     $content .= $this->list_table_content('defaults', $this->get('page'));
                 } else {
                     // give link to enable
                     // smarty
                     $sE = new JudoIntranetSmarty();
                     $sE->assign('message', parent::lang('class.AdministrationView#defaults#disable#rowNotEnabled'));
                     $sE->assign('href', 'administration.php?id=' . $this->get('id') . '&action=enable&rid=' . $rid);
                     $sE->assign('title', parent::lang('class.AdministrationView#defaults#disable#rowNotEnabled.enable'));
                     $sE->assign('content', parent::lang('class.AdministrationView#defaults#disable#rowNotEnabled.enable'));
                     $content .= $sE->fetch('smarty.admin.dis-enable.tpl');
                 }
             } elseif ($this->get('action') == 'enable') {
                 // check if row is disabled
                 if (!$this->is_valid('defaults', $rid)) {
                     // set valid 1
                     $this->set_valid('defaults', $rid, 1);
                     // list table content
                     $content .= $this->list_table_content('defaults', $this->get('page'));
                 } else {
                     // give link to disable
                     // smarty
                     $sE = new JudoIntranetSmarty();
                     $sE->assign('message', parent::lang('class.AdministrationView#defaults#enable#rowNotDisabled'));
                     $sE->assign('href', 'administration.php?id=' . $this->get('id') . '&action=disable&rid=' . $rid);
                     $sE->assign('title', parent::lang('class.AdministrationView#defaults#enable#rowNotDisabled.disable'));
                     $sE->assign('content', parent::lang('class.AdministrationView#defaults#enable#rowNotDisabled.disable'));
                     $content .= $sE->fetch('smarty.admin.dis-enable.tpl');
                 }
             } elseif ($this->get('action') == 'delete') {
                 $content .= $this->delete_row('defaults', $rid);
             } else {
                 $content .= $this->list_table_content('defaults', $this->get('page'));
             }
         } else {
             $errno = $GLOBALS['Error']->error_raised('RowNotExists', $this->get('rid'));
             $GLOBALS['Error']->handle_error($errno);
             return $GLOBALS['Error']->to_html($errno);
         }
     } else {
         // add default content
         $content .= $this->list_table_content('defaults', $this->get('page'));
     }
     // smarty
     $this->tpl->assign('caption', parent::lang('class.AdministrationView#defaults#caption#name'));
     $this->tpl->assign('tablelinks', '');
     // return
     return $content;
 }
 /**
  * user controles the actions for usersettings
  * 
  * @return string the html-string of usersettings-page
  */
 private function user()
 {
     // smarty-template
     $sUserPasswd = new JudoIntranetSmarty();
     // prepare return
     $return = '';
     // check login
     if ($_SESSION['user']->get_loggedin()) {
         // smarty
         $sUserPasswd->assign('pagecaption', parent::lang('class.MainView#user#caption#general') . ' ' . $_SESSION['user']->get_userinfo('name'));
         // check action
         if ($this->get('action') == 'passwd') {
             // smarty
             $sUserPasswd->assign('section', parent::lang('class.MainView#user#caption#passwd'));
             // prepare form
             $form = new HTML_QuickForm2('passwd', 'post', array('name' => 'passwd', 'action' => 'index.php?id=user&action=passwd'));
             // add elementgroup
             $passwd = $form->addElement('group', 'password', array());
             // add fields
             $passwd1 = $passwd->addElement('password', 'password1', array());
             $passwd2 = $passwd->addElement('password', 'password2', array());
             // add label
             $passwd->setLabel(parent::lang('class.MainView#user#passwd#label') . ':');
             // submit-button
             $form->addSubmit('submit', array('value' => parent::lang('class.MainView#user#passwd#submitButton')));
             // renderer
             $renderer = HTML_QuickForm2_Renderer::factory('default');
             $renderer->setOption('required_note', parent::lang('class.MainView#user#form#requiredNote'));
             // add rules
             $passwd->addRule('required', parent::lang('class.MainView#user#rule#required'));
             $passwd->addRule('callback', parent::lang('class.MainView#user#rule#checkPasswd'), array($this, 'callback_check_passwd'));
             // validate
             if ($form->validate()) {
                 // get values
                 $data = $form->getValue();
                 // get db-object
                 $db = Db::newDb();
                 // prepare sql-statement
                 $sql = "UPDATE user\n\t\t\t\t\t\t\tSET password='******'password']['password1']) . "'\n\t\t\t\t\t\t\tWHERE id=" . $_SESSION['user']->get_id();
                 // execute statement
                 $result = $db->query($sql);
                 // smarty message
                 $sUserPasswd->assign('message', parent::lang('class.MainView#user#validate#passwdChanged'));
             } else {
                 // smarty form and return
                 $sUserPasswd->assign('form', $form->render($renderer));
             }
             return $sUserPasswd->fetch('smarty.user.passwd.tpl');
         } else {
             return 'default content';
         }
     } else {
         // not authorized
         $errno = $GLOBALS['Error']->error_raised('NotAuthorized', 'entry:' . $this->get('id'), $this->get('id'));
         $GLOBALS['Error']->handle_error($errno);
         return $GLOBALS['Error']->to_html($errno);
     }
 }