Пример #1
0
 /**
  * Redirect to search results based on the given criteria.
  */
 public function redirectToResults()
 {
     $sm = SessionManager::getInstance();
     $url = Tools::dispatch_url($this->getPreviousNode(), $this->getPreviousAction(), $this->fetchCriteria());
     $url = $sm->sessionUrl($url, $sm->atkLevel() > 0 ? SessionManager::SESSION_BACK : SessionManager::SESSION_REPLACE);
     $this->m_node->redirect($url);
 }
Пример #2
0
 /**
  * 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);
     }
 }
Пример #3
0
 /**
  * Get the exportlink to add to the admin header.
  *
  * @return string HTML code with link to the export action of the node (if allowed)
  */
 public function getExportLink()
 {
     $link = '';
     if ($this->m_node->allowed('view') && $this->m_node->allowed('export') && $this->m_node->hasFlag(Node::NF_EXPORT)) {
         $filter = '';
         if (count($this->m_node->m_fuzzyFilters) > 0) {
             $filter = implode(' AND ', str_replace('[table]', $this->m_node->getTable(), $this->m_node->m_fuzzyFilters));
         }
         $link .= Tools::href(Tools::dispatch_url($this->m_node->atkNodeUri(), 'export', array('atkfilter' => $filter)), Tools::atktext('export', 'atk', $this->m_node->m_type), SessionManager::SESSION_NESTED);
     }
     return $link;
 }
Пример #4
0
 /**
  * This function checks if there is enough information to export the date
  * else it wil shows a form to set how the file wil be exported.
  */
 public function doProcess()
 {
     // Update selection
     if (array_key_exists('exportvalue', $this->m_postvars) && array_key_exists('save_export', $this->m_postvars) && '' != $this->m_postvars['export_selection_name']) {
         $this->updateSelection();
         $this->getNode()->redirect(Tools::dispatch_url($this->getNode(), 'export'));
     }
     // Save selection
     if (array_key_exists('export_selection_options', $this->m_postvars) && array_key_exists('export_selection_name', $this->m_postvars) && 'none' == $this->m_postvars['export_selection_options'] && '' != $this->m_postvars['export_selection_name']) {
         $this->saveSelection();
     }
     // Export CVS
     if (!array_key_exists('save_export', $this->m_postvars)) {
         return $this->doExport();
     }
 }
Пример #5
0
 /**
  * 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);
     }
 }
Пример #6
0
 protected function getAddURL($params = array())
 {
     return Tools::dispatch_url($this->m_destination, 'add', $params);
 }
Пример #7
0
 /**
  * Creates and returns the auto edit/view links.
  *
  * @param string $id The field html id
  * @param string $name The field html name
  * @param string $filter Filter that we want to apply on the destination node
  *
  * @return array The HTML code for the autolink links
  */
 public function getRelationAutolink($id, $name, $filter)
 {
     $autolink = [];
     if ($this->hasFlag(self::AF_RELATION_AUTOLINK)) {
         // auto edit/view link
         $page = Page::getInstance();
         $page->register_script(Config::getGlobal('assets_url') . 'javascript/class.atkmanytoonerelation.js');
         $sm = SessionManager::getInstance();
         if ($this->m_destInstance->allowed('edit')) {
             $editlink = $sm->sessionUrl(Tools::dispatch_url($this->getAutoLinkDestination(), 'edit', array('atkselector' => 'REPLACEME')), SessionManager::SESSION_NESTED);
             $autolink['edit'] = "<a href='javascript:atkSubmit(mto_parse(\"" . Tools::atkurlencode($editlink) . '", document.entryform.' . $id . ".value),true)' class='atkmanytoonerelation atkmanytoonerelation-link'>" . Tools::atktext('edit') . '</a>';
         }
         if ($this->m_destInstance->allowed('add')) {
             $autolink['add'] = ' ' . Tools::href(Tools::dispatch_url($this->getAutoLinkDestination(), 'add', array('atkpkret' => $name, 'atkfilter' => $this->m_useFilterForAddLink && $filter != '' ? $filter : '')), Tools::atktext('new'), SessionManager::SESSION_NESTED, true, 'class="atkmanytoonerelation atkmanytoonerelation-link"');
         }
     }
     return $autolink;
 }
Пример #8
0
 /**
  * Returns a displayable string for this value.
  *
  * @param array $record The record that holds the value for this attribute
  * @param string $mode The display mode ("view" for viewpages, or "list"
  *                       for displaying in recordlists, "edit" for
  *                       displaying in editscreens, "add" for displaying in
  *                       add screens. "csv" for csv files. Applications can
  *                       use additional modes.
  *
  * @return string a displayable string for this value
  */
 public function display($record, $mode)
 {
     $result = '';
     if ($this->createDestination() && Tools::atk_value_in_array($record[$this->fieldName()])) {
         $recordset = [];
         $remotekey = $this->getRemoteKey();
         for ($i = 0; $i < count($record[$this->fieldName()]); ++$i) {
             $rec = $record[$this->fieldName()][$i][$remotekey];
             if (!is_array($rec)) {
                 $selector = $this->m_destInstance->m_table . '.' . $this->m_destInstance->primaryKeyField() . "= '{$rec}'";
                 $rec = $this->m_destInstance->select($selector)->includes($this->m_destInstance->descriptorFields())->getFirstRow();
                 $descr = $this->m_destInstance->descriptor($rec);
             } else {
                 $descr = $this->m_destInstance->descriptor($rec);
             }
             if ($this->hasFlag(self::AF_MANYTOMANY_DETAILVIEW) && $this->m_destInstance->allowed('view')) {
                 $descr = Tools::href(Tools::dispatch_url($this->m_destination, 'view', array('atkselector' => $this->getDestination()->primaryKey($rec))), $descr, SessionManager::SESSION_NESTED);
             }
             $recordset[] = $descr;
         }
         if (!in_array($mode, array('csv', 'plain'))) {
             $result = '<ul><li>' . implode('<li>', $recordset) . '</ul>';
         } else {
             $result = implode(', ', $recordset);
         }
     } else {
         if (!in_array($mode, array('csv', 'plain'))) {
             $result = $this->text('none');
         }
     }
     return $result;
 }
Пример #9
0
 /**
  * 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) . ');';
 }
Пример #10
0
 /**
  * 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);
 }
Пример #11
0
 /**
  * Return a piece of html code to edit the attribute.
  *
  * @param array $record Current record
  * @param string $fieldprefix The fieldprefix to put in front of the name
  *                            of any html form element for this attribute.
  * @param string $mode The mode we're in ('add' or 'edit')
  *
  * @return string piece of html code
  */
 public function edit($record, $fieldprefix, $mode)
 {
     $this->createDestination();
     $this->createLink();
     $result = '';
     $selectedPk = $this->getSelectedRecords($record);
     $recordset = $this->_getSelectableRecords($record, $mode);
     $total_records = count($recordset);
     if ($total_records > 0) {
         $page = Page::getInstance();
         $page->register_script(Config::getGlobal('assets_url') . 'javascript/class.atkprofileattribute.js');
         if (!$this->hasFlag(self::AF_MANYBOOL_NO_TOOLBAR)) {
             $result .= '<div align="left">
                   [<a href="javascript:void(0)" onclick="profile_checkAll(\'' . $this->getHtmlId($fieldprefix) . '\'); return false;">' . Tools::atktext('check_all', 'atk') . '</a> <a href="javascript:void(0)" onclick="profile_checkNone(\'' . $this->getHtmlId($fieldprefix) . '\'); return false;">' . Tools::atktext('check_none', 'atk') . '</a> <a href="javascript:void(0)" onclick="profile_checkInvert(\'' . $this->getHtmlId($fieldprefix) . '\'); return false;">' . Tools::atktext('invert_selection', 'atk') . '</a>]</div>';
         }
         $result .= '<div>';
         for ($i = 0; $i < $total_records; ++$i) {
             $detailLink = '';
             $sel = '';
             $onchange = '';
             $inputId = $this->getHtmlId($fieldprefix) . '_' . $i;
             if (in_array($this->m_destInstance->primaryKey($recordset[$i]), $selectedPk)) {
                 $sel = 'checked';
                 if ($this->getShowDetailsLink() && !$this->m_linkInstance->hasFlag(Node::NF_NO_EDIT) && $this->m_linkInstance->allowed('edit')) {
                     $localPkAttr = $this->getOwnerInstance()->getAttribute($this->getOwnerInstance()->primaryKeyField());
                     $localValue = $localPkAttr->value2db($record);
                     $remotePkAttr = $this->getDestination()->getAttribute($this->getDestination()->primaryKeyField());
                     $remoteValue = $remotePkAttr->value2db($recordset[$i]);
                     $selector = $this->m_linkInstance->m_table . '.' . $this->getLocalKey() . '=' . $localValue . '' . ' AND ' . $this->m_linkInstance->m_table . '.' . $this->getRemoteKey() . "='" . $remoteValue . "'";
                     $detailLink = Tools::href(Tools::dispatch_url($this->m_link, 'edit', array('atkselector' => $selector)), '[' . Tools::atktext('edit', 'atk') . ']', SessionManager::SESSION_NESTED, true);
                 }
             }
             if (count($this->m_onchangecode)) {
                 $onchange = ' onChange="' . $inputId . '_onChange(this);"';
                 $this->_renderChangeHandler($fieldprefix, '_' . $i);
             }
             $value = $recordset[$i][$this->m_destInstance->primaryKeyField()];
             $css = $this->getCSSClassAttribute('atkcheckbox');
             $label = $this->m_destInstance->descriptor($recordset[$i]);
             $result .= '<div>';
             $result .= '  <input type="checkbox" id="' . $inputId . '" name="' . $this->getHtmlName($fieldprefix) . '[][' . $this->getRemoteKey() . ']" value="' . $value . '" ' . $css . ' ' . $sel . $onchange . ' />';
             $result .= '  <label for="' . $inputId . '">' . $label . '</label>';
             if ($detailLink != '') {
                 $result .= ' ' . $detailLink;
             }
             $result .= '</div>';
         }
         $result .= '</div>';
     } else {
         $nodename = $this->m_destInstance->m_type;
         $modulename = $this->m_destInstance->m_module;
         $result .= Tools::atktext('select_none', $modulename, $nodename) . ' ';
     }
     if ($this->hasFlag(self::AF_MANYBOOL_AUTOLINK) && $this->m_destInstance->allowed('add')) {
         $result .= Tools::href(Tools::dispatch_url($this->m_destination, 'add'), $this->getAddLabel(), SessionManager::SESSION_NESTED) . "\n";
     }
     return $result;
 }
Пример #12
0
 /**
  * This method returns a form that the user can use to search records.
  *
  * @param string $name
  * @param array $criteria
  *
  * @return string The searchform in html form.
  */
 public function smartSearchForm($name = '', $criteria = array())
 {
     $ui = $this->getUi();
     $sm = SessionManager::getInstance();
     $params = [];
     $params['label'] = $this->getLabels();
     $params['reset_criteria'] = $this->getResetCriteria();
     // $params['load_criteria']        = $this->getLoadCriteria($name);
     // $params['forget_criteria']      = $this->getForgetCriteria($name);
     // $params['toggle_save_criteria'] = $this->getToggleSaveCriteria();
     // $params['save_criteria']        = $this->getSaveCriteria($name);
     $params['saved_criteria'] = $this->getSavedCriteria($name);
     $params['criteria'] = [];
     Tools::atkdebug('criteria smartSearchForm: ' . print_r($criteria, true));
     foreach ($criteria as $i => $criterium) {
         $params['criteria'][] = $this->getCriterium($i, $criterium);
     }
     $url = $sm->sessionUrl(Tools::dispatch_url($this->m_node->atkNodeUri(), 'smartsearch', array('atkpartial' => 'criterium')), SessionManager::SESSION_NEW);
     $params['action_add'] = "ATK.SmartSearchHandler.addCriterium('" . addslashes($url) . "')";
     return $ui->render($this->getTemplate('form'), $params);
 }
Пример #13
0
 /**
  * This function sets the actions of the items in the list.
  *
  * @param string $record Identifier for the record
  * @param array $actions Result array containing the options
  * @param mixed $mraactions
  */
 public function recordActions($record, &$actions, &$mraactions)
 {
     $this->m_dir = $this->stripDir($this->m_dir);
     if (is_dir($this->m_dir . '/' . $record['filename'])) {
         $actions['view'] = Tools::dispatch_url($this->atkNodeUri(), 'dirchange', array('atkselector' => $this->m_dir . $record['filename']));
         unset($actions['edit']);
         unset($actions['delete']);
         return;
     }
     // Remove edit/delete actions when a file is not writeable.
     if (!is_writeable($this->m_dir . '/' . $record['filename'])) {
         unset($actions['edit']);
         unset($actions['delete']);
     }
 }
Пример #14
0
 /**
  * The default view link.
  *
  * @param array $record
  *
  * @return string
  */
 protected function getViewActionLink($record)
 {
     return Tools::href(Tools::dispatch_url($this->getDestination()->atkNodeUri(), 'view', array('atkselector' => $this->getDestination()->primaryKey($record))), $this->text('view'), SessionManager::SESSION_NESTED, true, 'class="atkmanytomanyselectrelation-link"');
 }
Пример #15
0
 /**
  * Handle update success. Normally redirects the user either back to the edit form
  * (when the user only saved) or back to the previous action if the user choose save
  * and close.
  *
  * This method can be overriden inside your node.
  *
  * @param array $record the record
  */
 public function handleUpdateSuccess($record)
 {
     if (isset($this->m_postvars['atknoclose'])) {
         // 'save' was clicked
         $params = array('atkselector' => $this->m_node->primaryKey($record), 'atktab' => $this->m_node->getActiveTab());
         $sm = SessionManager::getInstance();
         $location = $sm->sessionUrl(Tools::dispatch_url($this->m_node->atkNodeUri(), $this->getEditAction(), $params), SessionManager::SESSION_REPLACE, 1);
     } else {
         // 'save and close' was clicked
         $location = $this->m_node->feedbackUrl('update', self::ACTION_SUCCESS, $record, '', 2);
     }
     $this->m_node->redirect($location, $record);
 }
Пример #16
0
 /**
  * Generate the dispatcher.
  */
 public function atkGenerateDispatcher()
 {
     global $ATK_VARS;
     $session =& SessionManager::getSession();
     if ($session['login'] != 1) {
         // no nodetype passed, or session expired
         $destination = '';
         if (isset($ATK_VARS['atknodeuri']) && isset($ATK_VARS['atkaction'])) {
             $destination = '&atknodeuri=' . $ATK_VARS['atknodeuri'] . '&atkaction=' . $ATK_VARS['atkaction'];
             if (isset($ATK_VARS['atkselector'])) {
                 $destination .= '&atkselector=' . $ATK_VARS['atkselector'];
             }
         }
         $box = $this->m_ui->renderBox(array('title' => Tools::atktext('title_session_expired'), 'content' => '<br><br>' . Tools::atktext('explain_session_expired') . '<br><br><br><br>
                                        <a href="' . Config::getGlobal('dispatcher') . '?atklogout=true' . $destination . '" target="_top">' . Tools::atktext('relogin') . '</a><br><br>'));
         $this->m_page->addContent($box);
         $this->m_output->output($this->m_page->render(Tools::atktext('title_session_expired'), true));
     } else {
         // Create node
         if (isset($ATK_VARS['atknodeuri'])) {
             $node = $this->atk->atkGetNode($ATK_VARS['atknodeuri']);
             $this->loadDispatchPage($ATK_VARS, $node);
         } else {
             if (is_array($this->m_defaultDestination)) {
                 // using dispatch_url to redirect to the node
                 $isIndexed = array_values($this->m_defaultDestination) === $this->m_defaultDestination;
                 if ($isIndexed) {
                     $destination = Tools::dispatch_url($this->m_defaultDestination[0], $this->m_defaultDestination[1], $this->m_defaultDestination[2] ? $this->m_defaultDestination[2] : array());
                 } else {
                     $destination = Tools::dispatch_url($this->m_defaultDestination['atknodeuri'], $this->m_defaultDestination['atkaction'], $this->m_defaultDestination[0] ? $this->m_defaultDestination[0] : array());
                 }
                 header('Location: ' . $destination);
                 exit;
             } else {
                 $this->renderContent();
             }
         }
     }
 }