Exemple #1
0
 /**
  * Constructor
  * @param $atk Atk
  *
  * @return IndexPage
  */
 public function __construct(Atk $atk)
 {
     global $ATK_VARS;
     $this->atk = $atk;
     $this->m_page = Page::getInstance();
     $this->m_ui = Ui::getInstance();
     $this->m_output = Output::getInstance();
     $this->m_user = SecurityManager::atkGetUser();
     $this->m_flags = array_key_exists('atkpartial', $ATK_VARS) ? Page::HTML_PARTIAL : Page::HTML_STRICT;
 }
Exemple #2
0
 /**
  * Gets the HTML for the initial mode of the exporthandler.
  *
  * @return string The HTML for the screen
  */
 public function _getInitHtml()
 {
     $action = Tools::dispatch_url($this->m_node->m_module . '.' . $this->m_node->m_type, 'export');
     $sm = SessionManager::getInstance();
     $params = [];
     $params['formstart'] = '<form name="entryform" enctype="multipart/form-data" action="' . $action . '" method="post" class="form-horizontal">';
     $params['formstart'] .= $sm->formState();
     $params['formstart'] .= '<input type="hidden" name="phase" value="process"/>';
     $params['buttons'][] = Tools::atkButton(Tools::atktext('cancel', 'atk'), '', SessionManager::SESSION_BACK, true);
     $params['buttons'][] = '<input class="btn" type="submit" value="' . Tools::atktext('export', 'atk') . '"/>';
     $params['buttons'][] = '<input id="export_save_button" style="display:none;" value="' . Tools::atktext('save_export_selection', 'atk') . '" name="save_export" class="btn" type="submit" /> ';
     $params['content'] = '<b>' . Tools::atktext('export_config_explanation', 'atk', $this->m_node->m_type) . '</b><br/><br/>';
     $params['content'] .= $this->_getOptions();
     $params['formend'] = '</form>';
     return Ui::getInstance()->renderAction('export', $params, $this->m_node->m_module);
 }
Exemple #3
0
 /**
  * Renders the debug and error messages to a nice HTML string.
  *
  * @return string html string
  */
 public function renderDebugAndErrorMessages()
 {
     global $ATK_VARS, $g_debug_msg, $g_error_msg;
     // check if this is an Ajax request
     $isPartial = isset($ATK_VARS['atkpartial']);
     // only display error messages
     if (count($g_error_msg) > 0 && Config::getGlobal('display_errors') && Config::getGlobal('debug') <= 0 && !$isPartial) {
         return $this->renderPlainErrorMessages();
     } else {
         if (Config::getGlobal('debug') <= 0 || count($g_debug_msg) == 0 && count($g_error_msg) == 0) {
             return '';
         }
     }
     $expanded = !$isPartial;
     if ($expanded && array_key_exists('atkdebugstate', $_COOKIE) && @$_COOKIE['atkdebugstate'] == 'collapsed') {
         $expanded = false;
     }
     // render debug block
     $block = $this->renderDebugBlock($expanded);
     if ($isPartial) {
         $output = '<script type="text/javascript">
         ATK.Debug.addContent(' . Json::encode($block) . ');
        </script>';
     } else {
         $ui = Ui::getInstance();
         $script = Config::getGlobal('assets_url') . 'javascript/class.atkdebug.js';
         $redirect = $this->renderRedirectLink();
         $output = '
       <script type="text/javascript" src="' . $script . '"></script>
       <div id="atk_debugging_div">
         ' . $redirect . '
         ' . $block . '
       </div>';
     }
     return $output;
 }
Exemple #4
0
 /**
  * Gets the node and the descriptor for the current item
  * and returns a trace of that.
  *
  * So for instance, if we were adding a grade to a student,
  * it would show:
  * Student [ Teknoman ] - Grade [ A+ ]
  *
  * @return string The descriptortrace
  */
 public function descriptorTrace()
 {
     $sessionData =& self::getSession();
     $stack = $sessionData[$this->m_namespace]['stack'][$this->atkStackID()];
     $res = [];
     $node = null;
     $module = null;
     $nodename = null;
     $stackcount = count($stack);
     $atk = Atk::getInstance();
     for ($i = 0; $i < $stackcount; ++$i) {
         if (isset($stack[$i]['descriptor']) || $i == $stackcount - 1) {
             if ($stack[$i]['atknodeuri'] != '') {
                 $node = $atk->atkGetNode($stack[$i]['atknodeuri']);
                 $module = Tools::getNodeModule($stack[$i]['atknodeuri']);
                 $nodename = Tools::getNodeType($stack[$i]['atknodeuri']);
             }
             if (is_object($node)) {
                 $ui = Ui::getInstance();
                 $txt = $ui->title($module, $nodename);
             } else {
                 $txt = Tools::atktext($nodename, $module);
             }
             $res[] = $txt . (isset($stack[$i]['descriptor']) ? " [ {$stack[$i]['descriptor']} ] " : '');
         }
     }
     return $res;
 }
 /**
  * Returns a piece of html code that can be used in a form to edit this
  * attribute's value.
  *
  * @param array $record The record that holds the value for this attribute.
  * @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 A piece of htmlcode for editing this attribute
  */
 public function edit($record, $fieldprefix, $mode)
 {
     // Add onchange handler
     $mode = $mode == 'add' ?: 'edit';
     $url = addslashes(Tools::partial_url($this->m_ownerInstance->atkNodeUri(), $mode, 'attribute.' . $this->getHtmlId($fieldprefix) . '.selection', array('atkfieldprefix' => $fieldprefix)));
     $this->addOnChangeHandler("shuttle_refresh('{$url}', '" . $this->getHtmlId($fieldprefix) . '[cselected][][' . $this->getRemoteKey() . ']' . "', '" . $fieldprefix . $this->fieldName() . "[section]', el);");
     $this->_renderChangeHandler($fieldprefix);
     $filtersBySection = [];
     foreach (array(ShuttleControl::AVAILABLE, ShuttleControl::SELECTED) as $section) {
         foreach ($this->m_controlsBySection[$section] as $control) {
             if (is_a($control, 'ShuttleFilter')) {
                 /** @var ShuttleFilter $control */
                 $filter = $control->getFilter($record);
                 if (!empty($filter)) {
                     $filtersBySection[$section][] = $filter;
                 }
                 $limit = $control->getLimit();
                 if ($limit !== null) {
                     $this->m_limit = $limit;
                 }
             }
         }
     }
     $availableFilter = '';
     if (count($filtersBySection[ShuttleControl::AVAILABLE]) > 0) {
         $availableFilter = '(' . implode(') AND (', $filtersBySection[ShuttleControl::AVAILABLE]) . ')';
     }
     $selectedFilter = '';
     if (count($filtersBySection[ShuttleControl::SELECTED]) > 0) {
         $selectedFilter = '(' . implode(') AND (', $filtersBySection[ShuttleControl::SELECTED]) . ')';
     }
     // Get controls for 'available' side
     $ava_controls = [];
     foreach ($this->m_controlsBySection[ShuttleControl::AVAILABLE] as $control) {
         $ava_controls[] = $control->render($record, $mode, $fieldprefix);
     }
     // Get controls for 'selected' side
     $sel_controls = [];
     foreach ($this->m_controlsBySection[ShuttleControl::SELECTED] as $control) {
         $sel_controls[] = $control->render($record, $mode, $fieldprefix);
     }
     // Get available records
     $left = $this->hasFlag(self::AF_SHUTTLERELATION_NO_AUTOLOAD) ? [] : $this->getAvailableFields($record, $mode, $availableFilter);
     $available_options = [];
     for ($i = 0, $_i = count($left); $i < $_i; ++$i) {
         $available_options[$left[$i][$this->m_destInstance->primaryKeyField()]] = $this->m_destInstance->descriptor($left[$i]);
     }
     // Get selected records
     $right = $this->getSelectedFields($record, $mode, $selectedFilter, $availableFilter);
     $selected_options = [];
     for ($i = 0, $_i = count($right); $i < $_i; ++$i) {
         $selected_options[$right[$i][$this->m_destInstance->primaryKeyField()]] = $this->m_destInstance->descriptor($right[$i]);
     }
     $leftname = $this->getHtmlId($fieldprefix) . '[available]';
     $rightname = $this->getHtmlId($fieldprefix) . '[cselected][][' . $this->getRemoteKey() . ']';
     $name = $this->getHtmlId($fieldprefix) . '[selected][][' . $this->getRemoteKey() . ']';
     // Build jsonned value for selected fields
     $vals = [];
     foreach ($right as $fld) {
         $vals[] = $fld[$this->m_destInstance->primaryKeyField()];
     }
     $value = Json::encode($vals);
     if ($value == 'null') {
         $value = '[]';
     }
     // on submit, we must select all items in the right selector, as unselected items will not be posted.
     $page = $this->m_ownerInstance->getPage();
     $page->register_script(Config::getGlobal('assets_url') . 'javascript/class.atkextendableshuttlerelation.js');
     $page->register_submitscript("shuttle_selectAll('" . $rightname . "');");
     $ui = Ui::getInstance();
     $result = $ui->render('extendableshuttle.tpl', array('leftname' => $leftname, 'rightname' => $rightname, 'name' => $name, 'htmlid' => $this->getHtmlId($fieldprefix), 'remotekey' => $this->getRemoteKey(), 'value' => $value, 'ava_controls' => $ava_controls, 'sel_controls' => $sel_controls, 'available_options' => $available_options, 'selected_options' => $selected_options));
     return $result;
 }
Exemple #6
0
 /**
  * Get the ui instance for drawing and templating purposes.
  *
  * @return Ui An Ui instance for drawing and templating.
  */
 public function getUi()
 {
     return Ui::getInstance();
 }
Exemple #7
0
 /**
  * Display a login form.
  *
  * @param string $defaultname The username that might already be known
  * @param int $lastresponse The lastresponse when trying to login
  *                             possible values:
  *                             SecurityManager::AUTH_MISMATCH,
  *                             SecurityManager::AUTH_LOCKED,
  *                             SecurityManager::AUTH_MISSINGUSERNAME,
  *                             SecurityManager::AUTH_PASSWORDSENT
  */
 public function loginForm($defaultname, $lastresponse)
 {
     $page = Page::getInstance();
     $ui = Ui::getInstance();
     $page->register_script(Config::getGlobal('assets_url') . 'javascript/tools.js');
     $tplvars = [];
     $output = '<form action="' . Config::getGlobal('dispatcher') . '" method="post">';
     $output .= Tools::makeHiddenPostvars(array('atklogout'));
     $output .= '<br><br><table border="0" cellspacing="2" cellpadding="0" align="center">';
     $tplvars['atksessionformvars'] = Tools::makeHiddenPostvars(['atklogout', 'auth_rememberme']);
     $tplvars['formurl'] = Config::getGlobal('dispatcher');
     $tplvars['username'] = Tools::atktext('username');
     $tplvars['password'] = Tools::atktext('password');
     $tplvars['userfield'] = '<input class="form-control loginform" type="text" size="20" id="auth_user" name="auth_user" value="' . htmlentities($defaultname) . '" />';
     $tplvars['passwordfield'] = '<input class="loginform" type="password" size="20" name="auth_pw" value="" />';
     $tplvars['submitbutton'] = '<input name="login" class="button" type="submit" value="' . Tools::atktext('login') . '" />';
     $tplvars['title'] = Tools::atktext('login_form');
     if ($lastresponse == self::AUTH_LOCKED) {
         $output .= '<tr><td colspan=3 class=error>' . Tools::atktext('auth_account_locked') . '<br><br></td></tr>';
         $tplvars['auth_account_locked'] = Tools::atktext('auth_account_locked');
         $tplvars['error'] = Tools::atktext('auth_account_locked');
     } elseif ($lastresponse == self::AUTH_MISMATCH) {
         $output .= '<tr><td colspan=3 class=error>' . Tools::atktext('auth_mismatch') . '<br><br></td></tr>';
         $tplvars['auth_mismatch'] = Tools::atktext('auth_mismatch');
         $tplvars['error'] = Tools::atktext('auth_mismatch');
     } elseif ($lastresponse == self::AUTH_MISSINGUSERNAME) {
         $output .= '<tr><td colspan="3" class=error>' . Tools::atktext('auth_missingusername') . '<br /><br /></td></tr>';
         $tplvars['auth_mismatch'] = Tools::atktext('auth_missingusername');
         $tplvars['error'] = Tools::atktext('auth_missingusername');
     } elseif ($lastresponse == self::AUTH_PASSWORDSENT) {
         $output .= '<tr><td colspan="3">' . Tools::atktext('auth_passwordmail_sent') . '<br /><br /></td></tr>';
         $tplvars['auth_mismatch'] = Tools::atktext('auth_passwordmail_sent');
     }
     if (Config::getGlobal('auth_enable_rememberme')) {
         $tplvars['auth_enable_rememberme'] = true;
         if (isset($_POST['auth_rememberme']) && $_POST['auth_rememberme'] == '1') {
             $tplvars['auth_rememberme'] = true;
         }
     }
     // generate the form
     $output .= '<tr><td valign=top>' . Tools::atktext('username') . '</td><td>:</td><td>' . $tplvars['userfield'] . '</td></tr>';
     $output .= '<tr><td colspan=3 height=6></td></tr>';
     $output .= '<tr><td valign=top>' . Tools::atktext('password') . "</td><td>:</td><td><input type=password size=15 name=auth_pw value='' /></td></tr>";
     $output .= '<tr><td colspan="3" align="center" height="50" valign="middle">';
     $output .= '<input name="login" class="button" type="submit" value="' . Tools::atktext('login') . '">';
     $tplvars['auth_enablepasswordmailer'] = $this->get_enablepasswordmailer();
     if ($this->get_enablepasswordmailer()) {
         $output .= '&nbsp;&nbsp;<input name="login" class="button" type="submit" value="' . Tools::atktext('password_forgotten') . '">';
         $tplvars['forgotpasswordbutton'] = '<input name="login" class="button" type="submit" value="' . Tools::atktext('password_forgotten') . '">';
     }
     $output .= '</td></tr>';
     $output .= '</table></form>';
     $tplvars['content'] = $output;
     $page->addContent($ui->render('login.tpl', $tplvars));
     $o = Output::getInstance();
     $o->output($page->render(Tools::atktext('app_title'), Page::HTML_STRICT, '', $ui->render('login_meta.tpl')));
 }
Exemple #8
0
 /**
  * Render the complete page, including head and body.
  *
  * @param string $title Title of the HTML page.
  * @param bool|int $flags (bool) Set to true to generate <body> tags. It is useful
  *                                 to set this to false only when rendering content
  *                                 that either already had its own <body></body>
  *                                 statement, or content that needs no body
  *                                 statements, like a frameset. (DEPRICATED !!)
  *                                 (int) Flags for the render function
  * @param string $extrabodyprops Extra attributes to add to the <body> tag.
  * @param string $extra_header HTML code of extra headers to add to the head section
  *
  * @return string The HTML page, including <html> and </html> tags.
  */
 public function render($title = null, $flags = self::HTML_STRICT, $extrabodyprops = '', $extra_header = '')
 {
     if ($title == null) {
         $title = $this->m_title != '' ? $this->m_title : Tools::atktext('app_title');
     }
     $ui = Ui::getInstance();
     if (is_bool($flags) && $flags == true) {
         $flags = self::HTML_STRICT;
     } elseif (is_bool($flags) && $flags == false) {
         $flags = self::HTML_HEADER | self::HTML_DOCTYPE;
     } elseif (Tools::hasFlag($flags, self::HTML_PARTIAL)) {
         return $this->renderPartial();
     }
     $this->m_content = $ui->render('page.tpl', array('content' => $this->m_content));
     $layout = [];
     $layout['title'] = $title;
     if (Tools::hasFlag($flags, self::HTML_HEADER)) {
         $layout['head'] = $this->head() . $extra_header;
     }
     if (Tools::hasFlag($flags, self::HTML_BODY)) {
         $layout['extrabodyprops'] = $extrabodyprops;
         $layout['body'] = $this->m_content . "\n";
     }
     $layout['hiddenvars'] = $this->hiddenVars();
     $layout['atkversion'] = Atk::VERSION;
     return $ui->render('layout.tpl', $layout);
 }