*/ // must be run within Dokuwiki if (!defined('DOKU_INC')) { die(); } class admin_plugin_structnotification extends DokuWiki_Admin_Plugin { protected $headers = ['schema', 'field', 'operator', 'value', 'users_and_groups', 'message']; protected $operators = ['before', 'after', 'at']; /** * @return int sort number in admin menu */ public function getMenuSort() { return 499; } /** * @return bool true if only access for superuser, false is for superusers and moderators */ public function forAdminOnly() { return false; } /** * Should carry out any processing required by the plugin. */ public function handle() { global $INPUT; global $ID; try { /** @var \helper_plugin_structnotification_db$db_helper */ $db_helper = plugin_load('helper', 'structnotification_db'); $sqlite = $db_helper->getDB(); } catch (Exception $e) { msg($e->getMessage(), -1); return; } if ($INPUT->str('action') && $INPUT->arr('predicate') && checkSecurityToken()) { $predicate = $INPUT->arr('predicate'); if ($INPUT->str('action') === 'add') { $errors = $this->validate($predicate); if ($errors) { $this->display_errors($errors); return; } $ok = $sqlite->storeEntry('predicate', $predicate); if(!$ok) msg('failed to add predicate', -1); } elseif($INPUT->str('action') === 'delete') { $ok = $sqlite->query('DELETE FROM predicate WHERE id=?', $predicate['id']); if(!$ok) msg('failed to delete predicate', -1); } elseif($INPUT->str('action') === 'update') { $errors = $this->validate($predicate); if ($errors) { $this->display_errors($errors); return; } $set = implode(',', array_map(function ($header) { return "$header=?"; }, $this->headers)); $predicate['id'] = $INPUT->str('edit'); $ok = $sqlite->query("UPDATE predicate SET $set WHERE id=?", $predicate); if(!$ok) msg('failed to update predicate', -1); } if ($ok) send_redirect(wl($ID, array('do' => 'admin', 'page' => 'structnotification'), true, '&')); } } /** * Render HTML output, e.g. helpful text and a form */ public function html() { global $INPUT; global $ID; try { /** @var \helper_plugin_structnotification_db$db_helper */ $db_helper = plugin_load('helper', 'structnotification_db'); $sqlite = $db_helper->getDB(); } catch (Exception $e) { msg($e->getMessage(), -1); return; } ptln('
' . $this->getLang('admin header '. $header) . ' | '); } //extra field for buttons ptln(''); ptln(' | |
---|---|---|
' . $html . ' | '); } else { ptln('' . $value . ' | '); } } ptln(''); $link = wl( $ID, array( 'do' => 'admin', 'page' => 'structnotification', 'edit' => $predicate['id'] ) ); ptln(''.$this->getLang('edit').' | '); $link = wl( $ID, array( 'do' => 'admin', 'page' => 'structnotification', 'action' => 'delete', 'sectok' => getSecurityToken(), 'predicate[id]' => $predicate['id'] ) ); ptln(''.$this->getLang('delete').''); ptln(' | '); ptln('