/** * edit returns the protocoltext as html-string for the edit page * * @param int $pid entry-id for protocol * @return string html-string with the protocoltext */ private function edit($pid) { // check rights if (Rights::check_rights($pid, 'protocol', true)) { // pagecaption $this->tpl->assign('pagecaption', parent::lang('class.ProtocolView#page#caption#edit')); // get protocol-object $protocol = new Protocol($pid); // smarty-templates $sD = new JudoIntranetSmarty(); // get rights $pRights = $protocol->get_rights()->get_rights(); // check public access $kPublicAccess = array_search(0, $pRights); $publicAccess = false; if ($kPublicAccess !== false) { $publicAccess = true; unset($pRights[$kPublicAccess]); } // formular $form = new HTML_QuickForm2('editProtocol', 'post', array('name' => 'editProtocol', 'action' => 'protocol.php?id=edit&pid=' . $pid)); // get correction status and correctors $correctable = $protocol->get_correctable(false); $datasource = array('date' => $protocol->get_date('Y-m-d'), 'type' => $protocol->get_type('i'), 'location' => $protocol->get_location(), 'member0' => $protocol->get_member(false, 0), 'member1' => $protocol->get_member(false, 1), 'member2' => $protocol->get_member(false, 2), 'protocol' => $protocol->get_protocol(), 'preset' => $protocol->get_preset()->get_id(), 'recorder' => $protocol->get_recorder(), 'correction' => $correctable['status'], 'correctors' => $correctable['correctors']); // add public access if ($publicAccess) { $datasource['public'] = 1; } // add datasource $form->addDataSource(new HTML_QuickForm2_DataSource_Array($datasource)); // renderer $renderer = HTML_QuickForm2_Renderer::factory('default'); $renderer->setOption('required_note', parent::lang('class.ProtocolView#entry#form#requiredNote')); // elements // correction // radio $radio0 = $form->addElement('radio', 'correction', array('value' => 0)); $radio0->setContent(parent::lang('class.ProtocolView#entry#form#correctionInWork')); $radio0->setLabel(parent::lang('class.ProtocolView#entry#form#correction') . ':'); $radio1 = $form->addElement('radio', 'correction', array('value' => 1)); $radio1->setContent(parent::lang('class.ProtocolView#entry#form#correctionCorrect')); $radio2 = $form->addElement('radio', 'correction', array('value' => 2)); $radio2->setContent(parent::lang('class.ProtocolView#entry#form#correctionFinished')); // select correctors // get all users and put id and name to options $users = $_SESSION['user']->return_all_users(array($_SESSION['user']->get_userinfo('username'))); $options = array(); foreach ($users as $user) { $options[$user->get_userinfo('id')] = $user->get_userinfo('name'); } $correctors = $form->addElement('select', 'correctors', array('multiple' => 'multiple', 'size' => 5)); $correctors->setLabel(parent::lang('class.ProtocolView#entry#form#correctors') . ':'); $correctors->loadOptions($options); // preset $options = array(0 => '--') + Preset::read_all_presets('protocol'); $preset = $form->addElement('select', 'preset'); $preset->setLabel(parent::lang('class.ProtocolView#entry#form#preset') . ':'); $preset->loadOptions($options); $preset->addRule('required', parent::lang('class.ProtocolView#entry#rule#required.preset')); $preset->addRule('callback', parent::lang('class.ProtocolView#entry#rule#check.select'), array($this, 'callback_check_select')); // date $date = $form->addElement('text', 'date', array()); $date->setLabel(parent::lang('class.ProtocolView#entry#form#date') . ':'); // rule $date->addRule('required', parent::lang('class.ProtocolView#entry#rule#required.date')); $date->addRule('callback', parent::lang('class.ProtocolView#entry#rule#check.date'), array($this, 'callback_check_date')); // add jquery-datepicker // smarty $sD->assign('elementid', 'date-0'); $sD->assign('dateFormat', 'yy-mm-dd'); $sD->assign('dateValue', $protocol->get_date('y-m-d')); $this->add_jquery($sD->fetch('smarty.js-datepicker.tpl')); // type $options = array_merge(array(0 => '--'), Protocol::return_types()); $type = $form->addElement('select', 'type'); $type->setLabel(parent::lang('class.ProtocolView#entry#form#type') . ':'); $type->loadOptions($options); $type->addRule('required', parent::lang('class.ProtocolView#entry#rule#required.type')); $type->addRule('callback', parent::lang('class.ProtocolView#entry#rule#check.select'), array($this, 'callback_check_select')); // location $location = $form->addElement('text', 'location'); $location->setLabel(parent::lang('class.ProtocolView#entry#form#location') . ':'); $location->addRule('required', parent::lang('class.ProtocolView#entry#rule#required.location')); $location->addRule('regex', parent::lang('class.ProtocolView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('name.desc') . ']', $_SESSION['GC']->get_config('name.regexp')); // member0 $member = $form->addElement('text', 'member0'); $member->setLabel(parent::lang('class.ProtocolView#entry#form#member0') . ':'); $member->addRule('regex', parent::lang('class.ProtocolView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('text.desc') . ']', $_SESSION['GC']->get_config('text.regexp')); // member1 $member = $form->addElement('text', 'member1'); $member->setLabel(parent::lang('class.ProtocolView#entry#form#member1') . ':'); $member->addRule('regex', parent::lang('class.ProtocolView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('text.desc') . ']', $_SESSION['GC']->get_config('text.regexp')); // member2 $member = $form->addElement('text', 'member2'); $member->setLabel(parent::lang('class.ProtocolView#entry#form#member2') . ':'); $member->addRule('regex', parent::lang('class.ProtocolView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('text.desc') . ']', $_SESSION['GC']->get_config('text.regexp')); // recorder $recorder = $form->addElement('text', 'recorder'); $recorder->setLabel(parent::lang('class.ProtocolView#entry#form#recorder') . ':'); $recorder->addRule('required', parent::lang('class.ProtocolView#entry#rule#required.recorder')); $recorder->addRule('regex', parent::lang('class.ProtocolView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('name.desc') . ']', $_SESSION['GC']->get_config('name.regexp')); // protocol text $protocolTA = $form->addElement('textarea', 'protocol'); $protocolTA->setLabel(parent::lang('class.ProtocolView#entry#form#protocol') . ':'); $protocolTA->addRule('regex', parent::lang('class.ProtocolView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('textarea.desc') . ']', $_SESSION['GC']->get_config('textarea.regexp')); // js tiny_mce $tmce = array('element' => 'protocol-0', 'css' => 'templates/protocols/tmce_' . $protocol->get_preset()->get_path() . '.css', 'transitem' => parent::lang('class.ProtocolView#new_entry#tmce#item'), 'transdecision' => parent::lang('class.ProtocolView#new_entry#tmce#decision')); // smarty $this->tpl->assign('tmce', $tmce); // checkbox public $public = $form->addElement('checkbox', 'public'); $public->setLabel(parent::lang('class.ProtocolView#entry#form#public') . ':'); // submit-button $form->addElement('submit', 'submit', array('value' => parent::lang('class.ProtocolView#entry#form#submitButton'))); // validate if ($form->validate()) { // get form data $data = $form->getValue(); // set owner $data['owner'] = $protocol->get_owner(); // check $data['rights'] if (!isset($data['rights'])) { $data['rights'] = array(); } // merge with own groups, add admin $data['rights'] = array_merge($data['rights'], $_SESSION['user']->get_groups(), array(1)); // add public access $kPublicAccess = array_search(0, $data['rights']); if ($kPublicAccess === false && isset($data['public']) && $data['public'] == 1) { $data['rights'][] = 0; } elseif ($kPublicAccess !== false && !isset($data['public'])) { unset($data['rights'][$kPublicAccess]); } if (!isset($data['correctors'])) { $data['correctors'] = array(); } // get user and put to update $correctionString = $data['correction'] . '|'; foreach ($data['correctors'] as $userid) { $correctionString .= $userid . ','; } if (count($data['correctors']) > 0) { $correctionString = substr($correctionString, 0, -1); } $protocolUpdate = array('date' => $data['date'], 'type' => $data['type'], 'location' => $data['location'], 'member' => $data['member0'] . '|' . $data['member1'] . '|' . $data['member2'], 'protocol' => $data['protocol'], 'preset' => new Preset($data['preset'], 'protocol', $protocol->get_id()), 'recorder' => $data['recorder'], 'correctable' => $correctionString, 'rights' => $data['rights'], 'owner' => $data['owner'], 'valid' => 1); // update protocol $protocol->update($protocolUpdate); // write to db $protocol->writeDb('update'); // smarty $sCD = new JudoIntranetSmarty(); $sCD->assign('data', $protocol->details()); return $sCD->fetch('smarty.protocol.details.tpl'); } else { return $form->render($renderer); } } 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); } }