public function __construct($arg, $uid = null) { // parent constructor parent::__construct(); // check uid if (is_null($uid)) { $uid = $_SESSION['user']->get_id(); } $this->set_uid($uid); // check if user has allready corrected if (ProtocolCorrection::hasCorrected($arg->get_id(), $uid) === true) { $this->getFromDb($arg->get_id()); } else { $this->set_protocol($arg->get_protocol()); $this->set_finished(0); } }
/** * correct handles the corrections of the protocol * * @param int $pid entry-id for protocol * @return string html of the correction page */ private function correct($pid) { // pagecaption $this->tpl->assign('pagecaption', parent::lang('class.ProtocolView#page#caption#correct')); // get protocol object $protocol = new Protocol($pid); $correctable = $protocol->get_correctable(false); // 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); // check rights if (Rights::check_rights($pid, 'protocol', true) && (in_array($_SESSION['user']->get_id(), $correctable['correctors']) || $_SESSION['user']->get_userinfo('name') == $protocol->get_owner())) { // check owner if ($_SESSION['user']->get_userinfo('name') == $protocol->get_owner()) { // smarty $sPCo = new JudoIntranetSmarty(); // check action if ($this->get('action') == 'diff' && $this->get('uid') !== false) { // diff correction of $uid // get correction $correction = new ProtocolCorrection($protocol, $this->get('uid')); // clean protocols for diff $diffBase = html_entity_decode(preg_replace('/<.*>/U', '', $protocol->get_protocol())); $diffNew = html_entity_decode(preg_replace('/<.*>/U', '', $correction->get_protocol())); // smarty $sJsDL = new JudoIntranetSmarty(); // activate difflib js-files $this->tpl->assign('jsdifflib', true); // set values for difflib $difflib = array('protDiffBase' => 'protDiffBase-0', 'protDiffNew' => 'protDiffNew-0', 'protDiffOut' => 'diffOut', 'protDiffBaseCaption' => parent::lang('class.ProtocolView#correct#diff#baseCaption'), 'protDiffNewCaption' => parent::lang('class.ProtocolView#correct#diff#newCaption')); // add difflib values to js-template $sJsDL->assign('dl', $difflib); $this->add_jquery($sJsDL->fetch('smarty.js-jsdifflib.tpl')); // add diffOut to template $sPCo->assign('diffOut', 'diffOut'); // build form $form = new HTML_QuickForm2('diffCorrection', 'post', array('name' => 'diffCorrection', 'action' => 'protocol.php?id=correct&pid=' . $pid . '&action=diff&uid=' . $this->get('uid'))); $datasource = array('protocol' => $protocol->get_protocol(), 'protDiffBase' => $diffBase, 'protDiffNew' => $diffNew); // 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 // 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')); // checkbox to mark correction as finished $finished = $form->addElement('checkbox', 'finished'); $finished->setLabel(parent::lang('class.ProtocolView#entry#form#finished') . ':'); // hidden textareas for texts to diff $protocolBase = $form->addElement('textarea', 'protDiffBase'); $protocolNew = $form->addElement('textarea', 'protDiffNew'); // submit-button $form->addElement('submit', 'submit', array('value' => parent::lang('class.ProtocolView#entry#form#submitButton'))); // add form to template $sPCo->assign('c', true); $sPCo->assign('form', $form->render($renderer)); // validate if ($form->validate()) { // get form data $data = $form->getValue(); // check finished if (!isset($data['finished'])) { $data['finished'] = 0; } $correctionUpdate = array('finished' => $data['finished']); $protocolUpdate = array('protocol' => $data['protocol']); // update $protocol->update($protocolUpdate); $correction->update($correctionUpdate); $protocol->writeDb('update'); $correction->writeDb('update'); // message $message = array('message' => parent::lang('class.ProtocolView#correct#message#corrected'), 'href' => 'protocol.php?id=correct&pid=' . $pid . '&action=diff&uid=' . $this->get('uid'), 'title' => parent::lang('class.ProtocolView#correct#message#back'), 'text' => parent::lang('class.ProtocolView#correct#message#back')); // assign to template $sPCo->assign('c', false); $sPCo->assign('message', $message); } } else { // list all corrections // get corrections $corrections = ProtocolCorrection::listCorrections($pid); // put information together $list = array(); $user = new User(); foreach ($corrections as $correction) { // change user $user->change_user($correction['uid'], false, 'id'); // fill list $img = false; if ($correction['finished'] == 1) { $img = array('src' => 'img/done.png', 'alt' => parent::lang('class.ProtocolView#correct#difflist#imgDone'), 'title' => parent::lang('class.ProtocolView#correct#difflist#imgDone')); } $list[] = array('href' => 'protocol.php?id=correct&pid=' . $pid . '&action=diff&uid=' . $correction['uid'], 'title' => parent::lang('class.ProtocolView#correct#difflist#correctedBy') . ': ' . $user->get_userinfo('name'), 'text' => $user->get_userinfo('name') . ' (' . date('d.m.Y', strtotime($correction['modified'])) . ')', 'img' => $img); } // smarty $sPCo->assign('caption', parent::lang('class.ProtocolView#correct#difflist#caption')); $sPCo->assign('list', $list); } // return return $sPCo->fetch('smarty.protocolcorrection.owner.tpl'); } else { // get ProtocolCorretion object $correction = new ProtocolCorrection($protocol); // formular $form = new HTML_QuickForm2('correctProtocol', 'post', array('name' => 'correctProtocol', 'action' => 'protocol.php?id=correct&pid=' . $pid)); $datasource = array('protocol' => $correction->get_protocol()); // 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 // 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')); // 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(); $correctionUpdate = array('protocol' => $data['protocol'], 'modified' => date('U'), 'pid' => $pid); // update protocol $correction->update($correctionUpdate); // write to db $action = 'new'; if (ProtocolCorrection::hasCorrected($pid) === true) { $action = 'update'; } $correction->writeDb($action); return parent::lang('class.ProtocolView#correct#message#done'); } 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); } }
/** * hasCorrections returns if there are corrections for this protocol * * @return bool true if there are corrections, false otherwise */ public function hasCorrections() { // get corrections list $corrections = ProtocolCorrection::listCorrections($this->get_id()); // check list if (count($corrections) > 0) { return true; } else { return false; } }