public function addArticle($parameters = array()) { $view = new ui($this); $form = new mygridform($parameters, $parameters['-gridid-'], 'edit'); $form->addField(new textField('title', 'Titel', '', array('required'))); $form->addField(new textField('alias', 'Werktitel', '')); $form->addField(new datepickerField('start', 'Gepubliceerd van', true, '', array('required'))); $form->addField(new checkboxField('limit', 'Publicatie gelimiteerd in tijd', 'limit')); $form->addField(new datepickerField('stop', 'Gepubliceerd tot', true, '', array('required'))); $form->addField(new rteField('content', 'Inhoud', '', array('required'))); $draft = new selectField('state', 'Bewaar als', array('required')); $draft->addOption(new selectoptionField('Actieve versie', 'Actief', true)); $draft->addOption(new selectoptionField('Draft', 'Draft', false)); $form->addField($draft); if (isset($parameters['oldgrid'])) { $form->addField(new hiddenField('oldgrid', $parameters['oldgrid'])); } if (isset($parameters['linksection'])) { $form->addField(new hiddenField('linksection', $parameters['linksection'])); } if ($form->validate()) { $newarticle = new myarticleObject(); $newarticle->setAuthor(myauth::getCurrentuser()->getId()); $newarticle->setAuthorname(myauth::getCurrentuser()->getName()); $newarticle->setCreationdate(time()); if ($form->getFieldvalue('alias') != '') { $newarticle->setAlias($form->getFieldvalue('alias')); } else { $newarticle->setAlias($form->getFieldvalue('title')); } $newversion = new myarticleversionObject(); $newversion->setAuthor($newarticle->getAuthor()); $newversion->setAuthorname($newarticle->getAuthorname()); $newversion->setCreationdate($newarticle->getCreationdate()); $newversion->setTitle($form->getFieldvalue('title')); $newversion->setState($form->getFieldvalue('state')); $newversion->setStartpublishdate($form->getFieldvalue('start')); $newversion->setContent($form->getFieldvalue('content')); if ($form->getFieldvalue('limit') == 'limit') { $newversion->setStoppublishdate($form->getFieldvalue('stop')); } else { $newversion->setStoppublishdate(-1); } try { $articlemodel = new myarticleModel(); $versionmodel = new myarticleversionModel(); $articlemodel->save($newarticle); $newversion->setArticleid($newarticle->getId()); $versionmodel->save($newversion); if (isset($parameters['linksection'])) { $linkmodel = new myarticlesectionlinkModel(); $newlink = new myarticlesectionlinkObject(); $newlink->setArticleid($newarticle->getId()); $newlink->setSectionid($parameters['linksection']); $newlink->setOrder($linkmodel->getmax('order', array('sectionid' => array('mode' => '=', 'value' => $parameters['linksection']))) + 1); $linkmodel->save($newlink); } } catch (Exception $e) { $flash = new popupController(); $flash->createflash(array('name' => 'erroredit', 'type' => 'error', 'content' => 'De gegevens werden niet toegevoegd! Raadpleeg de informaticadienst.')); return false; } $flash = new popupController(); $flash->createflash(array('name' => 'flash_add_' . $parameters['-gridid-'], 'type' => 'success', 'content' => 'De gegevens zijn goed toegevoegd.')); // Rechten geven try { myacl::setAcl(myauth::getCurrentuser(), $newarticle, 'edit', 1); myacl::setAcl(myauth::getCurrentuser(), $newarticle, 'create_newversion', 1); myacl::setAcl(myauth::getCurrentuser(), $newarticle, 'manage_sectionlinks', 1); myacl::setAcl(myauth::getCurrentuser(), $newarticle, 'managerights', 1); } catch (Exception $e) { $flash->createflash(array('name' => 'flash_add_' . $parameters['-gridid-'], 'type' => 'error', 'content' => 'De gegevens zijn goed toegevoegd maar de rechten zijn niet toegekend! Raadpleeg de informaticadienst.' . $e->getMessage())); } $gridcontroller = new mygridController(); if (!isset($parameters['linksection'])) { $parameters['action'] = 'editarticle'; $parameters['controller'] = 'myarticle'; $parameters['id'] = $newarticle->getId(); $parameters['title'] = 'Artikel aanpassen'; unset($parameters['hidden_form_id']); $parameters['name'] = ''; $gridcontroller->editrequest($parameters); } else { $gridcontroller->reloadgrid($parameters['oldgrid']); $this->response->assign('gridextra_' . $parameters['oldgrid'], 'innerHTML', ''); } return true; } elseif (!$form->isSent()) { $view->assign('form', $form); return $view->fetch('myarticle_addarticle.tpl'); } else { return false; } }
public function addacl($parameters) { include FRAMEWORK . DS . 'conf' . DS . 'myacl.php'; $view = new ui($this); $form = new mygridform($parameters, $parameters['-gridid-'], 'edit'); $objecttype = $parameters['objecttype']; $objectid = $parameters['objectid']; $form->addField(new suggestselectField('myacl', 'getRequesterlist', 'requester', 'Aanvrager', '', array('required'), array('objectype' => $objecttype != 'securitytarget' ? $objecttype : $objectid))); if ($objecttype == 'securitytarget') { $rights = $myacl[$objectid]['rights']; } else { $rights = $myacl[$objecttype]['rights']; } $object = new $objecttype(); $object->setId($objectid); if (myacl::isAllowed(myauth::getCurrentuser(), $object, '_ALL_')) { $form->addField(new checkboxField('form_all', 'Full control', '_ALL_', false)); $form->addField(new checkboxField('form_managerights', 'Rechten beheren', 'managerights', false)); } foreach ($rights as $right => $rightconf) { $form->addField(new checkboxField('form_' . $right, $rightconf['description'], $right, false)); } $form->addField(new hiddenField('objecttype', $objecttype)); $form->addField(new hiddenField('objectid', $objectid)); $form->addField(new hiddenField('module', $parameters['module'])); if ($form->validate()) { $requestertypes = $myacl[$objecttype != 'securitytarget' ? $objecttype : $objectid]['requesters']; $requesters = array(); foreach ($form->getFieldvalue('requester') as $requestername) { foreach ($requestertypes as $type => $conf) { $modelname = str_replace('Object', 'Model', $type); $model = new $modelname(); $func = $conf['getfunction']; $res = $model->{$func}($requestername); if (count($res) == 1) { $requesters[] = $res[0]; break; } } } $selectedrights = array(); if ($form->getFieldvalue('form_all') == '_ALL_') { $selectedrights['_ALL_'] = '_ALL_'; } else { if ($form->getFieldvalue('form_managerights') == 'managerights') { $selectedrights['managerights'] = 'managerights'; } foreach ($rights as $right => $rightconf) { if ($form->getFieldvalue('form_' . $right) == $right) { $selectedrights[$right] = $right; if (isset($rightconf['requires'])) { foreach ($rightconf['requires'] as $required) { $selectedrights[$required] = $required; } } } } } try { $object = new $objecttype(); $object->setId($objectid); foreach ($requesters as $requester) { foreach ($selectedrights as $selectedright) { myacl::setAcl($requester, $object, $selectedright, 1); } } } catch (Exception $e) { $flash = new popupController(); $flash->createflash(array('name' => 'err', 'type' => 'error', 'content' => 'De gegevens zijn niet goed doorgevoerd! Raadpleeg de informaticadienst.')); return false; } $this->response->assign('gridextra_' . $parameters['-gridid-'], 'innerHTML', ''); $flash = new popupController(); $flash->createflash(array('name' => 's', 'type' => 'success', 'content' => 'De gegevens zijn goed doorgevoerd.')); return true; } elseif (!$form->isSent()) { $view->assign('form', $form); return $view->fetch('myacl_addacl.tpl'); } }