private function handleAdminDeletePost() { $request = Request::getInstance(); try { if (!$request->exists('id')) { throw new Exception('Gebruikersgroep ontbreekt.'); } $id = intval($request->getValue('id')); $this->delete(array('id' => $id)); viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW); $this->handleAdminOverview(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleAdminDeleteGet(); } }
private function handleConfEditPost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { if ($this->exists(array())) { $this->update($this->getKey($values), $values); } else { $this->insert($values); } viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW); $this->referer->handleHttpGetRequest(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleConfEditGet(false); } }
private function handleUserPost() { $request = Request::getInstance(); $user = new NewsLetterUser($this->plugin); $usr_used = $request->getValue('usr_used'); if (!$usr_used) { $usr_used = array(); } try { if (!$request->exists('id')) { throw new Exception('User group is missing.'); } $id = intval($request->getValue('id')); $key = array('id' => $id); $this->removeUser($key); foreach ($usr_used as $item) { $user->addGroup(array('id' => $item), $key); } viewManager::getInstance()->setType(NewsLetter::VIEW_GROUP_OVERVIEW); $this->handleOverview(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleUserGet(false); } }
private function handleDeletePost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { if (!$request->exists('ip')) { throw new Exception('id is missing.'); } $ip = $request->getValue('ip'); $key = array('ip' => $ip); $this->delete($key); viewManager::getInstance()->setType(self::VIEW_OVERVIEW); $this->handleOverview(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleDeleteGet(); } }
private function handleConfigPost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { $key = $this->getKey(); if ($this->exists($key)) { $this->update($key, $values); } else { $this->insert($values); } viewManager::getInstance()->setType(ViewManager::TREE_OVERVIEW); $this->plugin->handleHttpGetRequest(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleConfigGet(false); } }
private function handleDeletePost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { $key = $this->getKey(); $this->delete($key); viewManager::getInstance()->setType(NewsLetter::VIEW_PLUGIN_OVERVIEW); $plugin = $this->plugin->getObject(NewsLetter::TYPE_PLUGIN); $plugin->handleHttpGetRequest(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleDeleteGet(); } }
private function handleConfEditPost() { viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW); $this->referer->handleHttpGetRequest(); }
private function handleTreeDeletePost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { if (!$request->exists('id')) { throw new Exception('Calendar id is missing.'); } $ids = $request->getValue('id'); if (!is_array($ids)) { $ids = array($ids); } foreach ($ids as $id) { $key = array('id' => $id); $this->delete($key); } viewManager::getInstance()->setType(ViewManager::TREE_OVERVIEW); $this->handleTreeOverview(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleTreeDeleteGet(); } }
private function handleTreeEditPost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { if (!$request->exists('tree_id')) { throw new Exception('Node ontbreekt.'); } if (!$request->exists('tag')) { throw new Exception('Tag ontbreekt.'); } $tree_id = intval($request->getValue('tree_id')); $tag = $request->getValue('tag'); $key = array('tree_id' => $tree_id, 'tag' => $tag); if ($this->exists($key)) { $this->update($key, $values); } else { $this->insert($values); } viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW); $this->referer->handleHttpGetRequest(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleTreeEditGet(false); } }
private function handleAdminOverviewPost() { $request = Request::getInstance(); $values = array_merge($request->getRequest(Request::POST), $request->getRequest(Request::FILES)); try { $this->install($values); viewManager::getInstance()->setType(self::VIEW_SUCCESS); $this->handleAdminOverviewGet(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleAdminOverviewGet(); } }
/** * handle Move request */ private function handleMove() { $request = Request::getInstance(); $view = ViewManager::getInstance(); if (!$request->exists('id')) { throw new Exception(__FUNCTION__ . ' Element is missing.'); } $form_id = intval($request->getValue('id')); // check if node exists if (!$this->exists($form_id)) { throw new HttpException('404'); } $key = array('id' => $form_id); try { switch ($view->getType()) { case Links::VIEW_MV_PREC: $this->movetoPreceding($key); break; case Links::VIEW_MV_FOL: $this->movetoFollowing($key); break; } } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); } viewManager::getInstance()->setType(ViewManager::TREE_OVERVIEW); $this->handleTreeOverview(); }
private function handleMovePost() { $request = Request::getInstance(); try { $key = $this->getKey(); if (!$request->exists('newtag')) { throw new Exception("Destination tag cannot be empty"); } $sqlParser = clone $this->sqlParser; $sqlParser->parseCriteria($key, false); $this->parseCriteria($sqlParser, $key); $sqlParser->setFieldValue('nl_tag', $request->getValue('newtag')); $query = $sqlParser->getSql(SqlParser::MOD_UPDATE_FIELDS); $db = $this->getDb(); $res = $db->query($query); if ($db->isError($res)) { throw new Exception($res->getDebugInfo()); } viewManager::getInstance()->setType(NewsLetter::VIEW_PLUGIN_OVERVIEW); $this->handleOverview(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleMoveGet(); } }
private function handleImportPost() { $request = Request::getInstance(); $values = array_merge($request->getRequest(Request::POST), $request->getRequest(Request::FILES)); $grp_used = $request->getValue('grp_used'); if (!$grp_used) { $grp_used = array(); } try { require_once DIF_ROOT . "utils/CsvFile.php"; // check if import file is uploaded if (!array_key_exists('import_file', $values) && !is_array($values['import_file'])) { throw new Exception('No import file set'); } // validate file is really a uploaded file $file = $values['import_file']; if (!array_key_exists('tmp_name', $file) || !is_uploaded_file($file['tmp_name'])) { throw new Exception('wrong file.'); } $csvFile = new CsvFile(); $records = $csvFile->import($file['tmp_name']); // check fields $fields = array_intersect($csvFile->getFields(), $this->exportColumns); if (!$fields || !in_array('username', $fields)) { throw new Exception("Username is not present in import file"); } $db = $this->getDb(); // create temporary table $query = "create temporary table userimport like " . $this->sqlParser->getTable(); $res = $db->query($query); if ($db->isError($res)) { throw new Exception($res->getDebugInfo()); } // filter and insert records $fieldNames = array_intersect($this->sqlParser->getFieldNames(), $fields); ksort($fieldNames); $query = "insert into userimport(" . join(",", array_keys($fieldNames)) . ") values "; $recordFields = array(); foreach ($fieldNames as $name) { $recordFields[$name] = $name; } $rows = array(); foreach ($records as $record) { $record = array_intersect_key($record, $recordFields); if (!$record) { next; } ksort($record); if (array_key_exists('role', $record) && $record['role']) { $record['role'] = $this->getRoleId($record['role']); } foreach ($record as &$item) { //if(!$item) $item = "NULL"; $item = addslashes($item); } $rows[] = "('" . join("','", $record) . "')"; } $query .= join(",", $rows); $res = $db->query($query); if ($db->isError($res)) { throw new Exception($res->getDebugInfo()); } // update records $update = array(); $insert = array(); foreach ($fieldNames as $key => $value) { $insert[] = "a.{$key}"; // skip username and password if ($key == 'username' || $key == 'password') { continue; } $update[] = "a.{$key} = b.{$key}"; } $tablename = $this->sqlParser->getTable(); $query = sprintf("update %s as a inner join userimport as b on a.usr_username = b.usr_username set %s", $tablename, join(",", $update)); $res = $db->query($query); if ($db->isError($res)) { throw new Exception($res->getDebugInfo()); } // insert records $query = sprintf("insert into %s (%s,usr_create) select %s, now() from userimport as a left join %s as b on a.usr_username = b.usr_username where b.usr_id is NULL", $tablename, join(",", array_keys($fieldNames)), join(",", $insert), $tablename); $res = $db->query($query); if ($db->isError($res)) { throw new Exception($res->getDebugInfo()); } // update group foreach ($grp_used as $grp_id) { $query = sprintf("insert into usergroup (usr_id, grp_id) \n\t\t\t\t\t\t\t\t\t\t\t\t\tselect a.usr_id, %d \n\t\t\t\t\t\t\t\t\t\t\t\t\tfrom %s as a \n\t\t\t\t\t\t\t\t\t\t\t\t\tinner join userimport as b \n\t\t\t\t\t\t\t\t\t\t\t\t\ton a.usr_username = b.usr_username \n\t\t\t\t\t\t\t\t\t\t\t\t\tleft join usergroup as c \n\t\t\t\t\t\t\t\t\t\t\t\t\ton a.usr_id = c.usr_id and c.grp_id = %d \n\t\t\t\t\t\t\t\t\t\t\t\t\twhere c.usr_id is NULL", $grp_id, $this->sqlParser->getTable(), $grp_id); $res = $db->query($query); if ($db->isError($res)) { throw new Exception($res->getDebugInfo()); } } viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW); $this->handleAdminOverview(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleImportGet(); } }
private function handleAdminDeletePost() { $request = Request::getInstance(); try { if (!$request->exists('id')) { throw new Exception('Node ontbreekt.'); } $id = intval($request->getValue('id')); // check if user has execute rights $authentication = Authentication::getInstance(); if (!$authentication->canDelete($id)) { throw new HttpException('403'); } $parent = $this->tree->getParentId($id); $this->delete(array('id' => $id)); viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW); $this->handleAdminOverview($parent); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleAdminDeleteGet(); } }
private function handleTreeDeletePost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { if (!$request->exists('id')) { throw new Exception('Post ontbreekt.'); } $id = $request->getValue('id'); $key = array('id' => $id); $this->delete($key); viewManager::getInstance()->setType(Calendar::VIEW_COMMENT_OVERVIEW); $this->handleHttpGetRequest(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleTreeDeleteGet(); } }
private function handleTreeEditPost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { if (!$request->exists('tree_id')) { throw new Exception('Node ontbreekt.'); } if (!$request->exists('tag')) { throw new Exception('Tag ontbreekt.'); } $tree_id = intval($request->getValue('tree_id')); $tag = $request->getValue('tag'); $key = array('tree_id' => $tree_id, 'tag' => $tag); if ($this->exists($key)) { $this->update($key, $values); } else { $this->insert($values); } $treeRef = new NewsTreeRef(); $treeRef->delete($key); foreach ($values['ref_tree_id'] as $ref_tree_id) { $key['ref_tree_id'] = $ref_tree_id; $treeRef->insert($key); } viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW); $this->plugin->getReferer()->handleHttpGetRequest(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); // reset date values $online = $this->sqlParser->getFieldByName('online'); $this->sqlParser->setFieldValue('online', strftime('%Y-%m-%d', strtotime($online->getValue()))); $offline = $this->sqlParser->getFieldByName('offline'); $this->sqlParser->setFieldValue('offline', strftime('%Y-%m-%d', strtotime($offline->getValue()))); $this->handleTreeEditGet(false); } }
private function handleConfigPost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { if (!$request->exists('id')) { throw new Exception('Thema ontbreekt.'); } $id = intval($request->getValue('id')); $key = array('id' => $id); $theme = $this->director->themeManager->getThemeFromId($key); $fileTpl = $theme->getTemplateFile(); $fileIni = $theme->getConfigFile(); $fileCss = $theme->getStyleSheetFile(); $tpl_content = $request->getValue('file_tpl'); $ini_content = $request->getValue('file_ini'); $css_content = $request->getValue('file_css'); if (!$tpl_content) { throw new Exception("Template file is empty."); } if (!$ini_content) { throw new Exception("Configuration file is empty."); } if (!$css_content) { throw new Exception("Stylesheet file is empty."); } if (!($hTpl = fopen($fileTpl, "w"))) { throw new Exception("Error opening {$fileTpl} for writing."); } if (!($hIni = fopen($fileIni, "w"))) { throw new Exception("Error opening {$fileIni} for writing."); } if (!($hCss = fopen($fileCss, "w"))) { throw new Exception("Error opening {$fileCss} for writing."); } fputs($hTpl, $tpl_content); fputs($hIni, $ini_content); fputs($hCss, $css_content); fclose($hTpl); fclose($hIni); fclose($hCss); // clear cache $cache = Cache::getInstance(); $cache->clear(); viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW); $this->handleAdminOverview(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleConfigGet(false); } }
private function handleRecordDeleteAllPost() { $request = Request::getInstance(); $values = $request->getRequest(Request::POST); try { if (!$request->exists('tree_id')) { throw new Exception('Node ontbreekt.'); } if (!$request->exists('tag')) { throw new Exception('Tag ontbreekt.'); } $tree_id = intval($request->getValue('tree_id')); $tag = $request->getValue('tag'); $key = array('tree_id' => $tree_id, 'tag' => $tag); $record = $this->plugin->getObject(Form::TYPE_RECORD); $recordItem = $this->plugin->getObject(Form::TYPE_RECORD_ITEM); $record->delete($key); $recordItem->delete($key); viewManager::getInstance()->setType(ViewManager::TREE_OVERVIEW); $this->handleHttpGetRequest(); } catch (Exception $e) { $template = new TemplateEngine(); $template->setVariable('errorMessage', $e->getMessage(), false); $this->handleRecordDeleteAllGet(); } }