コード例 #1
0
ファイル: ManyToOneRelation.php プロジェクト: sintattica/atk
 /**
  * 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;
 }
コード例 #2
0
ファイル: Node.php プロジェクト: sintattica/atk
 /**
  * Builds a list of tabs.
  *
  * This doesn't generate the actual HTML code, but returns the data for
  * the tabs (title, selected, urls that should be loaded upon click of the
  * tab etc).
  *
  * @param string $action The action for which the tabs should be generated.
  *
  * @return array List of tabs
  *
  * @todo Make translation of tabs module aware
  */
 public function buildTabs($action = '')
 {
     if ($action == '') {
         // assume active action
         $action = $this->m_action;
     }
     $result = [];
     // which tab is currently selected
     $tab = $this->getActiveTab();
     // build navigator
     $list = $this->getTabs($action);
     if (is_array($list)) {
         $sm = SessionManager::getInstance();
         $newtab['total'] = count($list);
         foreach ($list as $t) {
             $newtab['title'] = $this->text(array("tab_{$t}", $t));
             $newtab['tab'] = $t;
             $url = Config::getGlobal('dispatcher') . '?atknodeuri=' . $this->atkNodeUri() . '&atkaction=' . $this->m_action . '&atktab=' . $t;
             if ($this->m_action == 'view') {
                 $newtab['link'] = $sm->sessionUrl($url, SessionManager::SESSION_DEFAULT);
             } else {
                 $newtab['link'] = "javascript:atkSubmit('" . Tools::atkurlencode($sm->sessionUrl($url, SessionManager::SESSION_DEFAULT)) . "')";
             }
             $newtab['selected'] = $t == $tab;
             $result[] = $newtab;
         }
     }
     return $result;
 }
コード例 #3
0
ファイル: TreeNode.php プロジェクト: sintattica/atk
 /**
  * Recursive funtion which fills an array with all the items of the tree.
  *
  * @param bool $showactions Show actions?
  * @param bool $expandAll Expand all leafs?
  * @param bool $foldable Is this tree foldable?
  *
  * @return string
  */
 public function GraphTreeRender($showactions = true, $expandAll = false, $foldable = true)
 {
     global $g_maxlevel, $exp_index;
     // Return
     if (count($this->m_tree) == 1) {
         return '';
     }
     $img_expand = $this->getIcon('expand');
     $img_collapse = $this->getIcon('collapse');
     $img_line = $this->getIcon('vertline');
     $img_split = $this->getIcon('split');
     $img_plus = $this->getIcon('split_plus');
     $img_minus = $this->getIcon('split_minus');
     $img_end = $this->getIcon('end');
     $img_end_plus = $this->getIcon('end_plus');
     $img_end_minus = $this->getIcon('end_minus');
     $img_leaf = $this->getIcon('leaf');
     $img_leaflink = $this->getIcon('leaf_link');
     $img_spc = $this->getIcon('space');
     $img_extfile = $this->getIcon('extfile');
     $res = '';
     $lastlevel = 0;
     //echo $this->m_tree[0]["expand"]."--".$this->m_tree[0]["colapse"];
     $explevels = [];
     if ($this->m_tree[0]['expand'] != 1 && $this->m_tree[0]['colapse'] != 1) {
         // normal operation
         for ($i = 0; $i < count($this->m_tree); ++$i) {
             if ($this->m_tree[$i]['level'] < 2) {
                 if ($this->m_tree[$i]['isleaf'] == 1 && $this->m_tree[$i]['level'] < 1) {
                     $expand[$i] = 1;
                     $visible[$i] = 1;
                 } else {
                     $expand[$i] = 0;
                     $visible[$i] = 1;
                 }
             } else {
                 $expand[$i] = 0;
                 $visible[$i] = 0;
             }
             $levels[$i] = 0;
         }
         if ($this->m_postvars['atktree'] != '') {
             $explevels = explode('|', $this->m_postvars['atktree']);
         }
     } elseif ($this->m_tree[0]['expand'] == 1) {
         // expand all mode!
         for ($i = 0; $i < count($this->m_tree); ++$i) {
             $expand[$i] = 1;
             $visible[$i] = 1;
             $levels[$i] = 0;
         }
         $this->m_tree[0]['expand'] = 0;
         // next time we are back in normal view mode!
     } elseif ($this->m_tree[0]['colapse'] == 1) {
         //  colapse all mode!
         for ($i = 0; $i < count($this->m_tree); ++$i) {
             if ($this->m_tree[$i]['level'] < 2) {
                 if ($this->m_tree[$i]['isleaf'] == 1 && $this->m_tree[$i]['level'] < 1) {
                     $expand[$i] = 1;
                     $visible[$i] = 1;
                 } else {
                     $expand[$i] = 0;
                     $visible[$i] = 1;
                 }
             }
             $levels[$i] = 0;
         }
         $this->m_tree[0]['colapse'] = 0;
         // next time we are back in normal view mode!
     }
     /*         * ****************************************** */
     /*  Get Node numbers to expand               */
     /*         * ****************************************** */
     $i = 0;
     while ($i < count($explevels)) {
         //$expand[$explevels[$i]]=1;
         $expand[$exp_index[$explevels[$i]]] = 1;
         ++$i;
     }
     /*         * ****************************************** */
     /*  Find last nodes of subtrees              */
     /*         * ****************************************** */
     $lastlevel = $g_maxlevel;
     for ($i = count($this->m_tree) - 1; $i >= 0; --$i) {
         if ($this->m_tree[$i]['level'] < $lastlevel) {
             for ($j = $this->m_tree[$i]['level'] + 1; $j <= $g_maxlevel; ++$j) {
                 $levels[$j] = 0;
             }
         }
         if ($levels[$this->m_tree[$i]['level']] == 0) {
             $levels[$this->m_tree[$i]['level']] = 1;
             $this->m_tree[$i]['isleaf'] = 1;
         } else {
             $this->m_tree[$i]['isleaf'] = 0;
         }
         $lastlevel = $this->m_tree[$i]['level'];
     }
     /*         * ****************************************** */
     /*  Determine visible nodes                  */
     /*         * ****************************************** */
     $visible[0] = 1;
     // root is always visible
     for ($i = 0; $i < count($explevels); ++$i) {
         $n = $exp_index[$explevels[$i]];
         if ($visible[$n] == 1 && $expand[$n] == 1) {
             $j = $n + 1;
             while ($this->m_tree[$j]['level'] > $this->m_tree[$n]['level']) {
                 if ($this->m_tree[$j]['level'] == $this->m_tree[$n]['level'] + 1) {
                     $visible[$j] = 1;
                 }
                 ++$j;
             }
         }
     }
     for ($i = 0; $i < $g_maxlevel; ++$i) {
         $levels[$i] = 1;
     }
     $res .= '<tr>';
     // Make cols for max level
     for ($i = 0; $i < $g_maxlevel; ++$i) {
         $res .= "<td width=16>&nbsp;</td>\n";
     }
     // Make the last text column
     $res .= '<td width=300>&nbsp;</td>';
     // Column for the functions
     if ($showactions) {
         $res .= '<td width=300>&nbsp;</td>';
     }
     $res .= "</tr>\n";
     $cnt = 0;
     while ($cnt < count($this->m_tree)) {
         if ($visible[$cnt]) {
             $currentlevel = isset($this->m_tree[$cnt]['level']) ? $this->m_tree[$cnt]['level'] : 0;
             $nextlevel = isset($this->m_tree[$cnt + 1]['level']) ? $this->m_tree[$cnt + 1]['level'] : 0;
             /****************************************/
             /* start new row                        */
             /****************************************/
             $res .= '<tr>';
             /****************************************/
             /* vertical lines from higher levels    */
             /****************************************/
             $i = 0;
             while ($i < $this->m_tree[$cnt]['level'] - 1) {
                 if ($levels[$i] == 1) {
                     $res .= '<td><img src="' . $img_line . "\" border=0></td>\n";
                 } else {
                     $res .= '<td><img src="' . $img_spc . "\" border=0></td>\n";
                 }
                 ++$i;
             }
             /***************************************/
             /* corner at end of subtree or t-split */
             /***************************************/
             if ($this->m_tree[$cnt]['isleaf'] == 1 && $nextlevel < $currentlevel) {
                 if ($cnt != 0) {
                     $res .= '<td><img src="' . $img_end . "\" border=0></td>\n";
                 }
                 $levels[$this->m_tree[$cnt]['level'] - 1] = 0;
             } else {
                 if ($expand[$cnt] == 0) {
                     if ($nextlevel > $currentlevel) {
                         /*                             * ************************************* */
                         /* Create expand/collapse parameters    */
                         /*                             * ************************************* */
                         $i = 0;
                         $params = 'atktree=';
                         while ($i < count($expand)) {
                             if ($expand[$i] == 1 && $cnt != $i || $expand[$i] == 0 && $cnt == $i) {
                                 $params = $params . $this->m_tree[$i]['id'];
                                 $params = $params . '|';
                             }
                             ++$i;
                         }
                         if ($this->extraparams) {
                             $params = $params . $this->extraparams;
                         }
                         if ($this->m_tree[$cnt]['isleaf'] == 1) {
                             if ($cnt != 0) {
                                 $res .= '<td>' . Tools::href(Config::getGlobal('dispatcher') . '?atknodeuri=' . $this->atkNodeUri() . '&atkaction=' . $this->m_action . '&' . $params, '<img src="' . $img_end_plus . '" border=0>') . "</td>\n";
                             }
                         } else {
                             if ($cnt != 0) {
                                 $res .= '<td>' . Tools::href(Config::getGlobal('dispatcher') . '?atknodeuri=' . $this->atkNodeUri() . '&atkaction=' . $this->m_action . '&' . $params, '<img src="' . $img_plus . '" border=0>') . "</td>\n";
                             }
                         }
                     } else {
                         $res .= '<td><img src="' . $img_split . "\" border=0></td>\n";
                     }
                 } else {
                     if ($nextlevel > $currentlevel) {
                         /*                             * ************************************* */
                         /* Create expand/collapse parameters    */
                         /*                             * ************************************* */
                         $i = 0;
                         $params = 'atktree=';
                         while ($i < count($expand)) {
                             if ($expand[$i] == 1 && $cnt != $i || $expand[$i] == 0 && $cnt == $i) {
                                 $params = $params . $this->m_tree[$i]['id'];
                                 $params = $params . '|';
                             }
                             ++$i;
                         }
                         if (isset($this->extraparams)) {
                             $params = $params . $this->extraparams;
                         }
                         if ($this->m_tree[$cnt]['isleaf'] == 1) {
                             if ($cnt != 0) {
                                 if ($foldable) {
                                     $res .= '<td>' . Tools::href(Config::getGlobal('dispatcher') . '?atknodeuri=' . $this->atkNodeUri() . '&atkaction=' . $this->m_action . '&' . $params, '<img src="' . $img_end_minus . '" border=0>') . "</td>\n";
                                 } else {
                                     $res .= '<td><img src="' . $img_end . "\" border=0></td>\n";
                                 }
                             }
                         } else {
                             if ($cnt != 0) {
                                 if ($foldable) {
                                     $res .= '<td>' . Tools::href(Config::getGlobal('dispatcher') . '?atknodeuri=' . $this->atkNodeUri() . '&atkaction=' . $this->m_action . '&' . $params, '<img src="' . $img_minus . '" border=0>') . "</td>\n";
                                 } else {
                                     $res .= '<td><img src="' . $img_split . "\" border=0></td>\n";
                                 }
                             }
                         }
                     } else {
                         $res .= '<td><img src="' . $img_split . "\" border=0></td>\n";
                     }
                 }
                 if ($this->m_tree[$cnt]['isleaf'] == 1) {
                     $levels[$this->m_tree[$cnt]['level'] - 1] = 0;
                 } else {
                     $levels[$this->m_tree[$cnt]['level'] - 1] = 1;
                 }
             }
             /*                 * ***************************************** */
             /* Node (with subtree) or Leaf (no subtree) */
             /*                 * ***************************************** */
             if ($nextlevel > $currentlevel) {
                 /*                     * ************************************* */
                 /* Create expand/collapse parameters    */
                 /*                     * ************************************* */
                 if ($foldable) {
                     $i = 0;
                     $params = 'atktree=';
                     while ($i < count($expand)) {
                         if ($expand[$i] == 1 && $cnt != $i || $expand[$i] == 0 && $cnt == $i) {
                             $params = $params . $this->m_tree[$i]['id'];
                             $params = $params . '|';
                         }
                         ++$i;
                     }
                     if (isset($this->extraparams)) {
                         $params = $params . $this->extraparams;
                     }
                     if ($expand[$cnt] == 0) {
                         $res .= '<td>' . Tools::href(Config::getGlobal('dispatcher') . '?' . $params, '<img src="' . $img_expand . '" border=0>') . "</td>\n";
                     } else {
                         $res .= '<td>' . Tools::href(Config::getGlobal('dispatcher') . '?' . $params, '<img src="' . $img_collapse . '" border=0>') . "</td>\n";
                     }
                 } else {
                     $res .= '<td><img src="' . $img_collapse . "\" border=0></td>\n";
                 }
             } else {
                 /*                     * ********************** */
                 /* Tree Leaf             */
                 /*                     * ********************** */
                 $img = $img_leaf;
                 // the image is a leaf image by default, but it can be overridden
                 // by putting img to something else
                 if ($this->m_tree[$cnt]['img'] != '') {
                     $imgname = $this->m_tree[$cnt]['img'];
                     $img = ${$imgname};
                 }
                 $res .= '<td><img src="' . $img . "\"></td>\n";
             }
             /*                 * ************************************* */
             /* output item text                     */
             /*                 * ************************************* */
             // If there's an array inside the 'label' thingee, we have an entire record.
             // Else, it's probably just a textual label.
             if (is_array($this->m_tree[$cnt]['label'])) {
                 $label = $this->descriptor($this->m_tree[$cnt]['label']);
             } else {
                 $label = $this->m_tree[$cnt]['label'];
             }
             $res .= '<td colspan=' . ($g_maxlevel - $this->m_tree[$cnt]['level']) . ' nowrap><font size=2>' . $label . "</font></td>\n";
             /*                 * ************************************* */
             /* end row   with the functions                      */
             /*                 * ************************************* */
             if ($showactions) {
                 $res .= '<td nowrap> ';
                 $actions = [];
                 if (!$this->hasFlag(self::NF_NO_ADD) && !($this->hasFlag(self::NF_TREE_NO_ROOT_ADD) && $this->m_tree[$cnt]['level'] == 0)) {
                     $actions['add'] = Config::getGlobal('dispatcher') . '?atknodeuri=' . $this->atkNodeUri() . '&atkaction=add&atkfilter=' . $this->m_parent . '.' . $this->m_primaryKey[0] . rawurlencode("='" . $this->m_tree[$cnt]['id'] . "'");
                 }
                 if ($cnt > 0) {
                     if (!$this->hasFlag(self::NF_NO_EDIT)) {
                         $actions['edit'] = Config::getGlobal('dispatcher') . '?atknodeuri=' . $this->atkNodeUri() . '&atkaction=edit&atkselector=' . $this->m_table . '.' . $this->m_primaryKey[0] . '=' . $this->m_tree[$cnt]['id'];
                     }
                     if ($this->hasFlag(self::NF_COPY) && $this->allowed('add') && !$this->hasFlag(self::NF_TREE_NO_ROOT_COPY) || $this->m_tree[$cnt]['level'] != 1 && $this->hasFlag(self::NF_COPY) && $this->allowed('add')) {
                         $actions['copy'] = Config::getGlobal('dispatcher') . '?atknodeuri=' . $this->atkNodeUri() . '&atkaction=copy&atkselector=' . $this->m_table . '.' . $this->m_primaryKey[0] . '=' . $this->m_tree[$cnt]['id'];
                     }
                     if ($this->hasFlag(self::NF_NO_DELETE) || $this->hasFlag(self::NF_TREE_NO_ROOT_DELETE) && $this->m_tree[$cnt]['level'] == 1) {
                         // Do nothing
                     } else {
                         $actions['delete'] = Config::getGlobal('dispatcher') . '?atknodeuri=' . $this->atkNodeUri() . '&atkaction=delete&atkselector=' . $this->m_table . '.' . $this->m_primaryKey[0] . '=' . $this->m_tree[$cnt]['id'];
                     }
                 }
                 // Look for custom record actions.
                 $recordactions = $actions;
                 $this->collectRecordActions($this->m_tree[$cnt]['label'], $recordactions, $dummy);
                 foreach ($recordactions as $name => $url) {
                     if (!empty($url)) {
                         /* dirty hack */
                         $atkencoded = strpos($url, '_1') > 0;
                         $url = str_replace('%5B', '[', $url);
                         $url = str_replace('%5D', ']', $url);
                         $url = str_replace('_1' . '5B', '[', $url);
                         $url = str_replace('_1' . '5D', ']', $url);
                         if ($atkencoded) {
                             $url = str_replace('[pk]', Tools::atkurlencode(rawurlencode($this->primaryKey($this->m_tree[$cnt]['label'])), false), $url);
                         } else {
                             $url = str_replace('[pk]', rawurlencode($this->primaryKey($this->m_tree[$cnt]['label'])), $url);
                         }
                         $stringparser = new StringParser($url);
                         $url = $stringparser->parse($this->m_tree[$cnt]['label'], true);
                         $res .= Tools::href($url, Tools::atktext($name), SessionManager::SESSION_NESTED) . '&nbsp;';
                     }
                 }
                 $res .= '</td>';
             }
             $res .= "</tr>\n";
         }
         ++$cnt;
     }
     return $res;
 }
コード例 #4
0
ファイル: DataGridList.php プロジェクト: sintattica/atk
 /**
  * Function outputs an array with all information necessary to output a recordlist.
  *
  * @param array $recordset List of records that need to be displayed
  * @param string $prefix Prefix for each column name (used for subcalls)
  * @param array $actions List of default actions for each record
  * @param array $suppress An array of fields that you want to hide
  *
  * The result array contains the following information:
  *  "name"     => the name of the recordlist
  *  "heading"  => for each visible column an array containing: "title" {, "url"}
  *  "search"   => for each visible column HTML input field(s) for searching
  *  "rows"     => list of rows, per row: "data", "actions", "mra", "record"
  *  "totalraw" => for each totalisable column the sum value field(s) (raw)
  *  "total"    => for each totalisable column the sum value (display)
  *  "mra"      => list of all multi-record actions
  *
  * @return array see above
  */
 private function listArray(&$recordset, $prefix = '', $actions = [], $suppress = array())
 {
     $grid = $this->getGrid();
     $flags = $this->convertDataGridFlags();
     if (!is_array($suppress)) {
         $suppress = [];
     }
     $result = array('name' => $grid->getName(), 'heading' => [], 'search' => [], 'rows' => [], 'totalraw' => [], 'total' => [], 'mra' => []);
     $columnConfig = $grid->getNode()->getColumnConfig($grid->getName());
     if (!Tools::hasFlag($flags, RecordList::RL_NO_SEARCH) || $grid->isEditing()) {
         $grid->getNode()->setAttribSizes();
     }
     $this->_addListArrayHeader($result, $prefix, $suppress, $flags, $columnConfig);
     /* actions array can contain multi-record-actions */
     if (count($actions) == 2 && count(array_diff(array_keys($actions), array('actions', 'mra'))) == 0) {
         $mra = $actions['mra'];
         $actions = $actions['actions'];
     } else {
         $mra = $grid->getNode()->hasFlag(Node::NF_NO_DELETE) ? [] : array('delete');
     }
     /* get the rows */
     for ($i = 0, $_i = count($recordset); $i < $_i; ++$i) {
         $result['rows'][$i] = array('columns' => [], 'actions' => $actions, 'mra' => $mra, 'record' => &$recordset[$i], 'data' => []);
         $result['rows'][$i]['selector'] = $grid->getNode()->primaryKey($recordset[$i]);
         $result['rows'][$i]['type'] = 'data';
         $row =& $result['rows'][$i];
         /* actions / mra */
         $grid->getNode()->collectRecordActions($row['record'], $row['actions'], $row['mra']);
         // filter actions we are allowed to execute
         foreach ($row['actions'] as $name => $url) {
             if (!empty($url) && $grid->getNode()->allowed($name, $row['record'])) {
                 /* dirty hack */
                 $atkencoded = strpos($url, '_15B') > 0;
                 $url = str_replace('%5B', '[', $url);
                 $url = str_replace('%5D', ']', $url);
                 $url = str_replace('_1' . '5B', '[', $url);
                 $url = str_replace('_1' . '5D', ']', $url);
                 if ($atkencoded) {
                     $url = str_replace('[pk]', Tools::atkurlencode(rawurlencode($row['selector']), false), $url);
                 } else {
                     $url = str_replace('[pk]', rawurlencode($row['selector']), $url);
                 }
                 $parser = new StringParser($url);
                 $url = $parser->parse($row['record'], true, false);
                 $row['actions'][$name] = $url;
             } else {
                 unset($row['actions'][$name]);
             }
         }
         // filter multi-record-actions we are allowed to execute
         foreach ($row['mra'] as $j => $name) {
             if (!$grid->getNode()->allowed($name, $row['record'])) {
                 unset($row['mra'][$j]);
             }
         }
         $row['mra'] = array_values($row['mra']);
         $result['mra'] = array_merge($result['mra'], $row['mra']);
         /* columns */
         $editAllowed = $grid->getPostvar('atkgridedit', false) && $grid->getNode()->allowed('edit', $result['rows'][$i]['record']);
         $result['rows'][$i]['edit'] = $editAllowed;
         $this->_addListArrayRow($result, $prefix, $suppress, $flags, $i, $editAllowed);
     }
     // override totals
     if (is_array($result['total']) && count($result['total']) > 0) {
         $selector = $grid->getNode()->select()->ignoreDefaultFilters();
         foreach ($grid->getFilters() as $filter) {
             $selector->where($filter['filter'], $filter['params']);
         }
         $result['totalraw'] = $selector->getTotals(array_keys($result['total']));
         foreach ($result['totalraw'] as $attrName => $value) {
             $result['total'][$attrName] = $grid->getNode()->getAttribute($attrName)->getView('list', $result['totalraw']);
         }
     }
     if (Tools::hasFlag($flags, RecordList::RL_EXT_SORT) && $columnConfig->hasSubTotals()) {
         $totalizer = new Totalizer($grid->getNode(), $columnConfig);
         $result['rows'] = $totalizer->totalize($result['rows']);
     }
     if (Tools::hasFlag($flags, RecordList::RL_MRA)) {
         $result['mra'] = array_values(array_unique($result['mra']));
     }
     return $result;
 }