/** * Get the record to view/edit. It is cached as long as the instance * exists, unless we force a reload. * * @param bool $force Whether or not to force the fetching of the record * * @return array The record for viewing/editting */ public function getRecord($force = false) { // if we are not forcing a fetch and we already have a cached record, return it if ($force === false && $this->m_record !== null) { return $this->m_record; } $record = $this->getRejectInfo(); // Check reject info first if ($record == null) { // If reject info not set - do select $atkstoretype = ''; $sessionmanager = SessionManager::getInstance(); if ($sessionmanager) { $atkstoretype = $sessionmanager->stackVar('atkstore'); } switch ($atkstoretype) { case 'session': $record = $this->getRecordFromSession(); break; default: $record = $this->getRecordFromDb(); break; } } // cache the record $this->m_record = $record; return $record; }
/** * Get an instance of the columnconfig class. * * @param Node $node * @param string $id * @param bool $forceNew force new instance? * * @return ColumnConfig An instance of the columnconfig class */ public static function getConfig($node, $id = null, $forceNew = false) { static $s_instances = []; $sm = SessionManager::getInstance(); if ($id == null) { $id = $node->atkNodeUri(); } if (!isset($s_instances[$id]) || $forceNew) { $cc = new self(); $s_instances[$id] = $cc; $cc->setNode($node); $colcfg = $sm != null ? $sm->pageVar('atkcolcfg_' . $id) : null; if (!is_array($colcfg) || $forceNew) { // create new Tools::atkdebug('New colconfig initialising'); $cc->init(); } else { // inherit old config from session. Tools::atkdebug('Resuming colconfig from session'); $cc->m_colcfg =& $colcfg; } // See if there are any url params which influence this colcfg. $cc->doUrlCommands(); } if ($sm != null) { $sm->pageVar('atkcolcfg_' . $id, $s_instances[$id]->m_colcfg); } return $s_instances[$id]; }
/** * Surrounds the grid by a form if needed. * * @param string $result grid HTML * * @return string grid HTML */ protected function renderForm($result) { if (!$this->getGrid()->isUpdate() && !$this->getGrid()->isEmbedded()) { $sm = SessionManager::getInstance(); $result = '<form id="' . $this->getGrid()->getFormName() . '" name="' . $this->getGrid()->getFormName() . '" method="post" action="' . Config::getGlobal('dispatcher') . '">' . $sm->formState() . $result . '</form>'; } return $result; }
/** * Get the start of the form. * * @return string HTML The forms' start */ public function getFormStart($record = null) { $sm = SessionManager::getInstance(); $formstart = '<form name="entryform" id="entryform" action="' . Config::getGlobal('dispatcher') . '" method="get" onsubmit="return globalSubmit(this,false)">'; $formstart .= $sm->formState(SessionManager::SESSION_NESTED); $formstart .= '<input type="hidden" name="atkselector" value="' . $this->getNode()->primaryKey($record) . '">'; $formstart .= '<input type="hidden" class="atksubmitaction" />'; return $formstart; }
/** * Implements the {stacktrace} plugin for use in templates. * * The {stacktrace} tag does not output anything. Instead, it loads * a stacktrace into the template variables {$stacktrace}, which is * an array of elements, each with a 'title' and 'url' field. * * <b>Example:</b> * <code> * {stacktrace} * * {foreach from=$stacktrace item=item} * <a href="{$item.url}">{$item.title}</a> * {/foreach} * </code> * * @author Ivo Jansch <*****@*****.**> */ function smarty_function_stacktrace($params, $smarty) { $sessionManager = SessionManager::getInstance(); if (is_object($sessionManager)) { $smarty->assign('stacktrace', $sessionManager->stackTrace()); return ''; } return ''; }
public function auth_sspi() { global $ATK_VARS; if (isset($ATK_VARS['atklogout'])) { if ($this->validateUser() == SecurityManager::AUTH_SUCCESS) { // On se reconnecte par defaut $session =& SessionManager::getSession(); $session['relogin'] = 1; } } }
/** * Implements the {atkmessages} plugin for use in templates. * * The {atkmessages} tag does not output anything. Instead, it loads * the messages into the template variable {$atkmessages}, which is * an array of elements, each with a single message. * * <b>Example:</b> * <code> * {atkmessages} * * {foreach from=$atkmessages item=message} * {$message.message}<br> * {/foreach} * </code> * * @author Patrick van der Velden <*****@*****.**> */ function smarty_function_atkmessages($params, $smarty) { $sessionManager = SessionManager::getInstance(); if (is_object($sessionManager)) { $msgs = MessageQueue::getMessages(); $smarty->assign('atkmessages', $msgs); if (empty($msgs)) { Tools::atkdebug('No messages in MessageQueue'); } return ''; } return ''; }
/** * Pops tree's on the session. */ public function sessionTree() { global $ATK_VARS; $postTree = $ATK_VARS['atktree']; $sm = SessionManager::getInstance(); $sessionTree = $sm->getValue('atktree'); if ($postTree != '' && $sessionTree != $postTree) { $sm->globalVar('atktree', $postTree); $realTree = $postTree; } else { $realTree = $sessionTree; // use the last known tree } $ATK_VARS['atktree'] = $realTree; // postvars now should contain the last Knowtree }
/** * The method returns a complete html page containing the feedback info. * * @param string $action The action for which feedback is provided * @param int $actionstatus The status of the action for which feedback is * provided * @param string $message An optional message to display in addition to the * default feedback information message. * * @return string The feedback page as an html String. */ public function feedbackPage($action, $actionstatus, $message = '') { $node = $this->m_node; $ui = $this->getUi(); $params['content'] = '<br>' . Tools::atktext('feedback_' . $action . '_' . Tools::atkActionStatus($actionstatus), $node->m_module, $node->m_type); if ($message) { $params['content'] .= ' <br>' . $message; } $sm = SessionManager::getInstance(); if ($sm->atkLevel() > 0) { $params['formstart'] = '<form method="get">' . $sm->formState(SessionManager::SESSION_BACK); $params['buttons'][] = '<input type="submit" class="btn btn-default btn_cancel" value="<< ' . Tools::atktext('back') . '">'; $params['formend'] = '</form>'; } $output = $ui->renderAction($action, $params); return $ui->renderBox(array('title' => $node->actionTitle($action), 'content' => $output)); }
/** * Given an confirmed delete, determine where the record * needs to be deleted (session or dabase), delete it * and redirect to the feedback url. */ protected function _doDelete() { $atkstoretype = ''; $sessionmanager = SessionManager::getInstance(); if ($sessionmanager) { $atkstoretype = $sessionmanager->stackVar('atkstore'); } switch ($atkstoretype) { case 'session': $result = $this->_doDeleteSession(); break; default: $result = $this->_doDeleteDb(); break; } if ($result === true) { $location = $this->m_node->feedbackUrl('delete', self::ACTION_SUCCESS); } else { $location = $this->m_node->feedbackUrl('delete', self::ACTION_FAILED, null, $result); } $this->m_node->redirect($location); }
/** * The action method. */ public function action_editcopy() { Tools::atkdebug('node::action_editcopy()'); $record = $this->getCopyRecord(); // allowed to editcopy record? if (!$this->allowed($record)) { $this->renderAccessDeniedPage(); return; } $db = $this->m_node->getDb(); if (!$this->m_node->copyDb($record)) { $db->rollback(); $location = $this->m_node->feedbackUrl('editcopy', self::ACTION_FAILED, $record, $db->getErrorMsg()); $this->m_node->redirect($location); } else { $db->commit(); $this->clearCache(); $sm = SessionManager::getInstance(); $location = $sm->sessionUrl(Tools::dispatch_url($this->m_node->atkNodeUri(), 'edit', array('atkselector' => $this->m_node->primaryKey($record))), SessionManager::SESSION_REPLACE); $this->m_node->redirect($location); } }
/** * Get the start of the form. * * @return string HTML The forms' start */ public function getFormStart() { $sm = SessionManager::getInstance(); $formstart = '<form id="entryform" name="entryform" enctype="multipart/form-data" action="' . Config::getGlobal('dispatcher') . '"' . ' method="post" onsubmit="return globalSubmit(this,false)" class="form-horizontal" role="form" autocomplete="off">' . $sm->formState($this->getUpdateSessionStatus()); $formstart .= '<input type="hidden" name="' . $this->getNode()->getEditFieldPrefix() . 'atkaction" value="' . $this->getUpdateAction() . '" />'; $formstart .= '<input type="hidden" name="' . $this->getNode()->getEditFieldPrefix() . 'atkprevaction" value="' . $this->getNode()->m_action . '" />'; $formstart .= '<input type="hidden" name="' . $this->getNode()->getEditFieldPrefix() . 'atkcsrftoken" value="' . $this->getCSRFToken() . '" />'; $formstart .= '<input type="hidden" class="atksubmitaction" />'; return $formstart; }
public function run() { $sessionManager = SessionManager::getInstance(); $sessionManager->start(); if (Config::getGlobal('session_autorefresh') && array_key_exists(Config::getGlobal('session_autorefresh_key'), $_GET)) { die(session_id()); } $securityManager = SecurityManager::getInstance(); if ($securityManager->authenticate()) { $this->bootModules(); $indexPageClass = Config::getGlobal('indexPage'); /** @var IndexPage $indexPage */ $indexPage = new $indexPageClass($this); $indexPage->generate(); } }
/** * Handle the error. * * @param string $errorMessage * @param string $debugMessage */ public function handle($errorMessage, $debugMessage) { $sessionManager = SessionManager::getInstance(); $sessionData =& SessionManager::getSession(); $txt_app_title = Tools::atktext('app_title'); if ($this->params['mailto'] != '') { // only if enabled.. $atk = Atk::getInstance(); $subject = '[' . $_SERVER['SERVER_NAME'] . "] {$txt_app_title} error"; $defaultfrom = sprintf('%s <%s@%s>', $txt_app_title, Config::getGlobal('identifier', 'atk'), $_SERVER['SERVER_NAME']); $from = Config::getGlobal('mail_sender', $defaultfrom); $body = "Hello,\n\nAn error seems to have occurred in the atk application named '{$txt_app_title}'.\n"; $body .= "\nThe errormessage was:\n\n" . implode("\n", is_array($errorMessage) ? $errorMessage : array()) . "\n"; $body .= "\nA detailed report follows:\n"; $body .= "\nPHP Version: " . phpversion() . "\n\n"; $body .= "\nDEBUGMESSAGES\n" . str_repeat('-', 70) . "\n"; $lines = []; for ($i = 0, $_ = count($debugMessage); $i < $_; ++$i) { $lines[] = $this->_wordwrap(Tools::atk_html_entity_decode(preg_replace('(\\[<a.*</a>\\])', '', $debugMessage[$i]))); } $body .= implode("\n", $lines); if (is_array($_GET)) { $body .= "\n\n_GET\n" . str_repeat('-', 70) . "\n"; foreach ($_GET as $key => $value) { $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 20 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n"; } } if (function_exists('getallheaders')) { $request = getallheaders(); if (count($request) > 0) { $body .= "\n\nREQUEST INFORMATION\n" . str_repeat('-', 70) . "\n"; foreach ($request as $key => $value) { $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n"; } } } if (is_array($_POST)) { $body .= "\n\n_POST\n" . str_repeat('-', 70) . "\n"; foreach ($_POST as $key => $value) { $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 20 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n"; } } if (is_array($_COOKIE)) { $body .= "\n\n_COOKIE\n" . str_repeat('-', 70) . "\n"; foreach ($_COOKIE as $key => $value) { $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 20 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n"; } } $body .= "\n\nATK CONFIGURATION\n" . str_repeat('-', 70) . "\n"; foreach ($GLOBALS as $key => $value) { if (substr($key, 0, 7) == 'config_') { $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n"; } } $body .= "\n\nMODULE CONFIGURATION\n" . str_repeat('-', 70) . "\n"; foreach ($atk->g_modules as $modname => $modpath) { $modexists = file_exists($modpath) ? ' (path exists)' : ' (PATH DOES NOT EXIST!)'; $body .= $this->_wordwrap($modname . ':' . str_repeat(' ', max(1, 20 - strlen($modname))) . var_export($modpath, 1) . $modexists) . "\n"; } $body .= "\n\nCurrent User:\n" . str_repeat('-', 70) . "\n"; $user = SecurityManager::atkGetUser(); if (is_array($user) && count($user)) { foreach ($user as $key => $value) { $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n"; } } else { $body .= "Not known\n"; } if (is_object($sessionManager)) { $body .= "\n\nATK SESSION\n" . str_repeat('-', 70); $body .= "\nNamespace: " . $sessionManager->getNameSpace() . "\n"; if (isset($sessionData[$sessionManager->getNameSpace()]['stack'])) { $stack = $sessionData[$sessionManager->getNameSpace()]['stack']; for ($i = 0; $i < count($stack); ++$i) { $body .= "\nStack level {$i}:\n"; $item = isset($stack[$i]) ? $stack[$i] : null; if (is_array($item)) { foreach ($item as $key => $value) { $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n"; } } } } if (isset($sessionData[$sessionManager->getNameSpace()]['globals'])) { $ns_globals = $sessionData[$sessionManager->getNameSpace()]['globals']; if (count($ns_globals) > 0) { $body .= "\nNamespace globals:\n"; foreach ($ns_globals as $key => $value) { $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n"; } } } if (isset($sessionData['globals'])) { $globals = $sessionData['globals']; if (count($globals) > 0) { $body .= "\nGlobals:\n"; foreach ($globals as $key => $value) { $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 30 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n"; } } } } $body .= "\n\nSERVER INFORMATION\n" . str_repeat('-', 70) . "\n"; foreach ($_SERVER as $key => $value) { $body .= $this->_wordwrap($key . str_repeat(' ', max(1, 20 - strlen($key))) . ' = ' . var_export($value, 1)) . "\n"; } //TODO: replace with some mailer object mail($this->params['mailto'], $subject, $body, "From: {$from}"); } }
/** * If the auto-select flag is set and only one record exists we immediately * return with the selected record. * * @param DataGrid $grid data grid * * @return bool auto-select active? */ protected function autoSelectRecord($grid) { $node = $this->getNode(); if (!$node->hasFlag(Node::NF_AUTOSELECT)) { return false; } $grid->loadRecords(); if ($grid->getCount() != 1) { return false; } $sm = SessionManager::getInstance(); if ($sm->atkLevel() > 0 && $grid->getPostvar('atkprevlevel', 0) > $sm->atkLevel()) { $backUrl = $sm->sessionUrl(Config::getGlobal('dispatcher') . '?atklevel=' . $sm->newLevel(SessionManager::SESSION_BACK)); $node->redirect($backUrl); } else { $records = $grid->getRecords(); // There's only one record and the autoselect flag is set, so we // automatically go to the target. $parser = new StringParser(rawurldecode(Tools::atkurldecode($grid->getPostvar('atktarget')))); // For backwardscompatibility reasons, we also support the '[pk]' var. $records[0]['pk'] = $node->primaryKey($records[0]); $target = $parser->parse($records[0], true); $node->redirect($sm->sessionUrl($target, SessionManager::SESSION_NESTED)); } return true; }
/** * Returns a JavaScript call to save the current grid's contents when in edit mode. * * @return string JavaScript call (might need escaping when used in HTML code) */ public function getSaveCall() { $sm = SessionManager::getInstance(); $url = $sm->sessionUrl(Tools::dispatch_url($this->getNode()->atkNodeUri(), 'multiupdate', array('output' => 'json')), SessionManager::SESSION_PARTIAL); return 'ATK.DataGrid.save(' . Json::encode($this->getName()) . ', ' . Json::encode($url) . ');'; }
/** * Get/generate CSRF token for the current session stack. * * http://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28CSRF%29_Prevention_Cheat_Sheet * * @return string CSRF token */ public function getCSRFToken() { // retrieve earlier generated token from the session stack $token = SessionManager::getInstance()->globalStackVar('ATK_CSRF_TOKEN'); if ($token != null) { return $token; } // generate and store token in sesion stack $token = md5(uniqid(rand(), true)); SessionManager::getInstance()->globalStackVar('ATK_CSRF_TOKEN', $token); return $token; }
/** * Retrieve all known information about the currently logged-in user. * * @param $key string * * @return array Array with userinfo, or "" if no user is logged in. */ public static function atkGetUser($key = '') { $sm = SessionManager::getInstance(); $session = SessionManager::getSession(); $user = ''; $session_auth = is_object($sm) ? $sm->getValue('authentication', 'globals') : []; if (Config::getGlobal('authentication_session') && Tools::atkArrayNvl($session, 'login', 0) == 1 && $session_auth['authenticated'] == 1 && !empty($session_auth['user'])) { $user = $session_auth['user']; if (!isset($user['access_level']) || empty($user['access_level'])) { $user['access_level'] = 0; } } if ($key) { return $user[$key]; } return $user; }
/** * Here we prepare our record for updating or return false, * indicating that we need to insert the record instead of updating it. * * @param array &$record The record to prepare * * @return bool If the record wasn't prepared we return false, otherwise true */ public function prepareUpdateRecord(&$record) { $sessionManager = SessionManager::getInstance(); // The keys to update the record on $updatekey1 = $this->m_postvars['updatekey1']; $updatekey1val = $this->getValueFromRecord($record, $updatekey1); $allFields = $sessionManager->pageVar('allFields'); foreach ($allFields as $allField) { $allFieldsValues[$allField] = $this->m_postvars[$allField]; } $this->m_importNode->m_postvars['atksearchmode'] = 'exact'; // if (!in_array($allFieldValue)) $this->m_importNode->m_fuzzyFilters[] = $allFieldValue; $dbrec = $this->m_importNode->searchDb(array($updatekey1 => $updatekey1val)); if (count($dbrec) == 1) { $record[$this->m_importNode->primaryKeyField()] = $dbrec[0][$this->m_importNode->primaryKeyField()]; $record['atkprimkey'] = $dbrec[0]['atkprimkey']; return true; } return false; }
/** * Returns a link for removing the currently selected criteria. If * nothing (valid) is selected nothing is returned. * * @param string $current currently loaded criteria * * @return string forget url */ public function getForgetCriteria($current) { if (empty($current) || $this->loadCriteria($current) == null) { return; } else { $sm = SessionManager::getInstance(); return $sm->sessionUrl(Tools::dispatch_url($this->m_node->atkNodeUri(), $this->m_action, array('forget_criteria' => $current)), SessionManager::SESSION_REPLACE); } }
public function validate(&$record, $mode) { $sessionmanager = SessionManager::getInstance(); $storetype = null; if ($sessionmanager) { $storetype = $sessionmanager->stackVar('atkstore'); } if ($storetype !== 'session' && !$this->_isSelectableRecord($record, $mode)) { Tools::triggerError($record, $this->fieldName(), 'error_integrity_violation'); } }
/** * This method returns an html page containing a recordlist to select * records from. The recordlist can be searched, sorted etc. like an * admin screen. * * @return string The html select page. */ public function multiSelectPage() { // add the postvars to the form global $g_stickyurl; $sm = SessionManager::getInstance(); $g_stickyurl[] = 'atktarget'; $g_stickyurl[] = 'atktargetvar'; $g_stickyurl[] = 'atktargetvartpl'; $GLOBALS['atktarget'] = $this->getNode()->m_postvars['atktarget']; $GLOBALS['atktargetvar'] = $this->getNode()->m_postvars['atktargetvar']; $GLOBALS['atktargetvartpl'] = $this->getNode()->m_postvars['atktargetvartpl']; $params['header'] = Tools::atktext('title_multiselect', $this->getNode()->m_module, $this->getNode()->m_type); $actions['actions'] = []; $actions['mra'][] = 'multiselect'; $grid = DataGrid::create($this->getNode(), 'multiselect'); /* * At first the changes below looked like the solution for the error * on the contact multiselect page. Except this is not the case, because * the MRA actions will not be shown, which is a must. */ if (is_array($actions['actions'])) { $grid->setDefaultActions($actions['actions']); } else { $grid->setDefaultActions($actions); } $grid->removeFlag(DataGrid::EXTENDED_SEARCH); $grid->addFlag(DataGrid::MULTI_RECORD_ACTIONS); $params['list'] = $grid->render(); if ($sm->atkLevel() > 0) { $backlinkurl = $sm->sessionUrl(Config::getGlobal('dispatcher') . '?atklevel=' . $sm->newLevel(SessionManager::SESSION_BACK)); $params['footer'] = '<br><div style="text-align: center"><input type="button" class="btn btn-default" onclick="window.location=\'' . $backlinkurl . '\';" value="' . Tools::atktext('cancel') . '"></div>'; } $output = $this->getUi()->renderList('multiselect', $params); return $this->getUi()->renderBox(array('title' => $this->getNode()->actionTitle('multiselect'), 'content' => $output)); }
/** * This method returns an html page that can be used as a search form. * * @param array $record A record containing default values that will be * entered in the searchform. * * @return string The html search page. */ public function searchPage($record = null) { $node = $this->m_node; $page = $this->getPage(); $page->register_script(Config::getGlobal('assets_url') . 'javascript/tools.js'); $ui = $this->getUi(); if (is_object($ui)) { $sm = SessionManager::getInstance(); $params = []; $params['formstart'] = '<form name="entryform" action="' . Config::getGlobal('dispatcher') . '" method="post">'; $params['formstart'] .= $sm->formState(SessionManager::SESSION_REPLACE); $params['formstart'] .= '<input type="hidden" name="atkaction" value="search">'; $params['formstart'] .= '<input type="hidden" name="atknodeuri" value="' . $node->atkNodeUri() . '">'; $params['formstart'] .= '<input type="hidden" name="atkstartat" value="0">'; // start at first page after new search $params['content'] = $this->invoke('searchForm', $record); $params['buttons'] = $node->getFormButtons('search'); $params['formend'] = '</form>'; $output = $ui->renderAction('search', $params); $total = $ui->renderBox(array('title' => $node->actionTitle('search'), 'content' => $output)); return $total; } else { Tools::atkerror('ui object failure'); } return ''; }
/** * Makes a session-aware href url. * When using hrefs in the editform, you can set saveform to true. This will save your * form variables in the session and restore them whenever you come back. * * @param string $url the url to make session aware * @param string $name the name to display (will not be escaped!) * @param int $sessionstatus the session flags * (SessionManager::SESSION_DEFAULT (default)|SessionManager::SESSION_NEW|SessionManager::SESSION_REPLACE| * SessionManager::SESSION_NESTED|SessionManager::SESSION_BACK) * @param bool $saveform wether or not to save the form * @param string $extraprops extra props you can add in the link such as * 'onChange="doSomething()"' * @static * * @return string the HTML link for the session aware URI */ public static function href($url, $name = '', $sessionstatus = SessionManager::SESSION_DEFAULT, $saveform = false, $extraprops = '') { $sm = SessionManager::getInstance(); if ($saveform) { $str = 'atkSubmit("' . self::atkurlencode($sm->sessionUrl($url, $sessionstatus)) . '", true);'; return '<a href="javascript:void(0)" onclick="' . htmlentities($str) . '" ' . $extraprops . '>' . $name . '</a>'; } else { $str = $sm->sessionUrl($url, $sessionstatus); return '<a href="' . htmlentities($str) . '" ' . $extraprops . '>' . $name . '</a>'; } }
/** * If a search action has been defined and a search only returns one result * the user will be automatically redirected to the search action. * * @param DataGrid $grid data grid * * @return bool redirect active? */ protected function redirectToSearchAction($grid) { $node = $this->getNode(); $search = $grid->getPostvar('atksearch'); // check if we are searching and a search action has been defined if (!is_array($search) || count($search) == 0 || !is_array($node->m_search_action) || count($node->m_search_action) == 0) { return false; } // check if there is only a single record in the result $grid->loadRecords(); if ($grid->getCount() != 1) { return false; } $records = $grid->getRecords(); foreach ($node->m_search_action as $action) { if (!$node->allowed($action, $records[0])) { continue; } // reset search so we can back to the normal admin screen if we want $grid->setPostvar('atksearch', array()); $sm = SessionManager::getInstance(); $url = $sm->sessionUrl(Tools::dispatch_url($node->atkNodeUri(), $action, array('atkselector' => $node->primaryKey($records[0]))), SessionManager::SESSION_NESTED); if ($grid->isUpdate()) { $script = 'document.location.href = ' . Json::encode($url) . ';'; $node->getPage()->register_loadscript($script); } else { $node->redirect($url); } return true; } return false; }
/** * Stops building the action box and returns the page builder. * * @return PageBuilder */ public function endActionBox() { if ($this->m_sessionStatus !== null) { $sm = SessionManager::getInstance(); $this->m_params['formend'] = $sm->formState($this->m_sessionStatus) . $this->m_params['formend']; } $this->m_pageBuilder->actionBox($this->m_params, $this->m_title, $this->m_template); return $this->m_pageBuilder; }
/** * Get the sessionmanager to use. * * @return mixed Sessionmanager or false if we don't have a session */ protected static function getSessionManager() { $sessionmanager = SessionManager::getInstance(); if (!$sessionmanager) { return false; } else { return $sessionmanager; } }
/** * the real import function * import the uploaded csv file for real. */ public function doExport() { $enclosure = $this->m_postvars['enclosure']; $delimiter = $this->m_postvars['delimiter']; $source = $this->m_postvars; $list_includes = []; foreach ($source as $name => $value) { $pos = strpos($name, 'export_'); if (is_integer($pos) and $pos == 0) { $list_includes[] = substr($name, strlen('export_')); } } $sm = SessionManager::getInstance(); $sessionData =& SessionManager::getSession(); $session_back = $sessionData['default']['stack'][$sm->atkStackID()][$sm->atkLevel() - 1]; $atkorderby = $session_back['atkorderby']; $node = $this->m_node; $node_bk = $node; $num_atts = count($node_bk->m_attribList); $atts =& $node_bk->m_attribList; foreach ($atts as $name => $object) { $att = $node_bk->getAttribute($name); if (in_array($name, $list_includes) && $att->hasFlag(Attribute::AF_HIDE_LIST)) { $att->removeFlag(Attribute::AF_HIDE_LIST); } elseif (!in_array($name, $list_includes)) { $att->addFlag(Attribute::AF_HIDE_LIST); } } $rl = new CustomRecordList(); $flags = ($node_bk->hasFlag(Node::NF_MRA) ? RecordList::RL_MRA : 0) | ($node_bk->hasFlag(Node::NF_MRPA) ? RecordList::RL_MRPA : 0); $node_bk->m_postvars = $session_back; if (isset($session_back['atkdg']['admin']['atksearch'])) { $node_bk->m_postvars['atksearch'] = $session_back['atkdg']['admin']['atksearch']; } if (isset($session_back['atkdg']['admin']['atksearchmode'])) { $node_bk->m_postvars['atksearchmode'] = $session_back['atkdg']['admin']['atksearchmode']; } $atkfilter = Tools::atkArrayNvl($source, 'atkfilter', ''); $condition = $session_back['atkselector'] . ($session_back['atkselector'] != '' && $atkfilter != '' ? ' AND ' : '') . $atkfilter; $recordset = $node_bk->select($condition)->orderBy($atkorderby)->includes($list_includes)->mode('export')->getAllRows(); if (method_exists($this->m_node, 'assignExportData')) { $this->m_node->assignExportData($list_includes, $recordset); } $recordset_new = []; foreach ($recordset as $row) { foreach ($row as $name => $value) { if (in_array($name, $list_includes)) { $value = str_replace("\r\n", '\\n', $value); $value = str_replace("\n", '\\n', $value); $value = str_replace("\t", '\\t', $value); $row[$name] = $value; } } $recordset_new[] = $row; } $filename = 'export_' . strtolower(str_replace(' ', '_', $this->getUi()->nodeTitle($node))); $rl->render($node_bk, $recordset_new, '', $enclosure, $enclosure, "\r\n", 1, '', '', array('filename' => $filename), 'csv', $source['generatetitlerow'], true, $delimiter); return true; }
/** * Get debugger data. * * @param bool $clean * @param int $stackId * * @return array Array with data */ public function &getDebuggerData($clean = false, $stackId = null) { $sm = SessionManager::getInstance(); if ($stackId == null) { $stackId = $sm->atkStackID(); } if (is_object($sm)) { $session =& $sm->getSession(); if ($clean) { $session['debugger'] = []; } $var =& $session['debugger'][$stackId]; return $var; } $data = []; return $data; }
/** * Determine the url for the feedbackpage. * * Output is dependent on the feedback configuration. If feedback is not * enabled for the action, this method returns an empty string, so the * result of this method can be passed directly to the redirect() method * after completing the action. * * The $record parameter is ignored by the default implementation, but * derived classes may override this method to perform record-specific * feedback. * * @param string $action The action that was performed * @param int $status The status of the action. * @param array $record The record on which the action was performed. * @param string $message An optional message to pass to the feedbackpage, * for example to explain the reason why an action * failed. * @param int $levelskip Number of levels to skip * * @return string The feedback url. */ public function feedbackUrl($action, $status, $record = [], $message = '', $levelskip = null) { $sm = SessionManager::getInstance(); $vars = []; $atkNodeUri = ''; $sessionStatus = SessionManager::SESSION_BACK; if (isset($this->m_feedback[$action]) && Tools::hasFlag($this->m_feedback[$action], $status) || $status == ActionHandler::ACTION_FAILED) { $vars = array('atkaction' => 'feedback', 'atkfbaction' => $action, 'atkactionstatus' => $status, 'atkfbmessage' => $message); $atkNodeUri = $this->atkNodeUri(); $sessionStatus = SessionManager::SESSION_REPLACE; // The level skip given is based on where we should end up after the // feedback action is shown to the user. This means that the feedback // action should be shown one level higher in the stack, hence the -1. // Default the feedback action is shown on the current level, so in that // case we have a simple SessionManager::SESSION_REPLACE with a level skip of null. $levelskip = $levelskip == null ? null : $levelskip - 1; } $dispatch_url = Tools::dispatch_url($atkNodeUri, Tools::atkArrayNvl($vars, 'atkaction', ''), $vars); return $sm->sessionUrl($dispatch_url, $sessionStatus, $levelskip); }