/** * GridActionExport::__construct() * * @param array $params * @return void */ public function __construct($params = array()) { if (false == isset($params['GlyphEnabled'])) { $params['GlyphEnabled'] = 'images/envoyer.gif'; } if (false == isset($params['GlyphDisabled'])) { $params['GlyphDisabled'] = 'images/envoyer_no.gif'; } if (false == isset($params['Caption'])) { $params['Caption'] = A_EXPORT; } if (false == isset($params['Title'])) { $params['Title'] = _('Export list in csv format (Excel)'); } // nom du fichier csv $fileName = isset($params['FileName']) ? $params['FileName'] : 'export'; // 1ere arrivee ou pas sur l'ecran $firstArrival = isset($params['FirstArrival']) ? $params['FirstArrival'] : 0; if (strrpos($_SERVER['REQUEST_URI'], '?') === false) { $url = $_SERVER['REQUEST_URI'] . '?'; } else { $url = $_SERVER['REQUEST_URI'] . '&'; } $url = $firstArrival ? $url . 'FirstArrival=1&' : $url; $url = $this->returnURL ? $url . 'returnURL=' . $this->returnURL . '&' : $url; // Pour les GenericGrid $url .= isset($_REQUEST['entity']) && stripos($url, 'entity=') === false ? 'entity=' . $_REQUEST['entity'] . '&' : ''; $url .= isset($_REQUEST['altname']) && stripos($url, 'altname=') === false ? 'altname=' . $_REQUEST['altname'] . '&' : ''; $url .= stripos($url, 'export=') === false ? 'export=' . $fileName : ''; $url = UrlTools::compliantURL($url); $params['jsActionArray'] = array('window.location=\'' . $url . '\''); parent::__construct($params); }
/** * Set the default values for missing data keys and set the state of the * item according to GET data or COOKIE data. * * @access public * @param integer $level * @param integer $index * @param array $data * @return void */ protected function handleData(&$data, $level, $index, $indexStack = array()) { // default values if (!isset($data['title'])) { $data['title'] = 'Untitled ' . $index; } if (!isset($data['description'])) { $data['description'] = ''; } if (!isset($data['accesskey'])) { $data['accesskey'] = ''; } $indexes = ''; $padding = ''; $indexStack[] = $index; foreach ($indexStack as $i) { $indexes .= $padding . $i; $padding = ','; } if ($this->useCookie) { $data['onclick'] = 'fw.cookie.create(\'' . self::NAVIGATION_VAR . '\', \'' . $indexes . '\')'; } else { // if not cookie pass the tab index infos in the url $qs = false === strrpos($data['link'], '?') ? '?' : '&'; $data['link'] .= $qs . self::NAVIGATION_VAR . '=' . $indexes; $data['onclick'] = false; } // state of the item $active = false; if (!$this->hasActiveItem[$level]) { // there's no selected item for this level yet $array = $this->useCookie ? $_COOKIE : $_GET; if (isset($array[self::NAVIGATION_VAR])) { $a = explode(',', $array[self::NAVIGATION_VAR]); $active = isset($a[$level - 1]) && $index == $a[$level - 1]; } } $data['active'] = $active; // Pour afficher directement le sous onglet si un seul possible if (isset($data['children'])) { $children = $data['children']; $chidrenIndexes = $this->_getChildrenForAuth($children); $uri = explode('?', $_SERVER['REQUEST_URI']); $url = basename($_SERVER['PHP_SELF']) . (isset($uri[1]) ? '?' . $uri[1] : ''); if (count($chidrenIndexes) == 1) { $data['link'] = $children[$chidrenIndexes[0]]['link']; $indexes .= ',' . $chidrenIndexes[0]; if ($this->useCookie) { $data['onclick'] = 'fw.cookie.create(\'' . self::NAVIGATION_VAR . '\', \'' . $indexes . '\')'; } else { $qs = false === strrpos($data['link'], '?') ? '?' : '&'; $data['link'] .= $qs . self::NAVIGATION_VAR . '=' . $indexes; } } } $data['link'] = UrlTools::compliantURL($data['link']); return $active; }
/** * Affiche une page avec un grid. * * <code> * Template::pageWithGrid( * $gridInstance, * 'EntityName', * 'My title', * array('Active'=>true), * array('Name'=>SORT_ASC) * ); * </code> * * @static * @access public * @param object $grid * @param string $clsname * @param string $title * @param array $filter * @param array $order * @param string $tpl * @return void */ public static function pageWithGrid($grid, $clsname, $title = '', $filter = array(), $order = array(), $tpl = BASE_TEMPLATE) { $retURL = $tpl == BASE_POPUP_TEMPLATE ? 'javascript:window.close();' : 'javascript:history.go(-1);'; $grid->setMapper($clsname); $result = $grid->execute($filter, $order); if (Tools::isException($result)) { self::errorDialog(E_ERROR_IN_EXEC . '<br/>' . $result->getMessage(), $retURL, $tpl); exit(1); } $action = UrlTools::compliantURL($_SERVER['REQUEST_URI']); self::page($title, '<form id="' . $clsname . 'Grid" action="' . $action . '" method="post">' . $result . '</form>', array(), array(), $tpl); }
/** * GridActionRedirect::execute() * * @access public * @param object $objects * @param boolean $doRedirect * @return mixed */ public function execute($objects, $itemIds = array(), $doRedirect = true) { // Retourne exception si pas d'item selectionne $result = parent::execute($objects, $itemIds); if (Tools::isException($result)) { return $result; } if (false !== strpos($this->_URL, '%d')) { if (count($objects) == 1) { $target = sprintf($this->_URL, $objects[0]->getId()); } else { if (!$this->allowEmptySelection) { return new Exception(I_NEED_SINGLE_ITEM); } $target = $this->_URL; } } else { if (empty($objects)) { if ($this->transmitedArrayName && !$this->allowEmptySelection) { return new Exception(I_NEED_SELECT_ITEM); } $target = $this->_URL; } else { $padding = strpos($this->_URL, '?') === false ? '?' : '&'; $queryString = ''; foreach ($objects as $key => $object) { $object = $objects[$key]; if (method_exists($object, 'getId')) { $queryString .= $padding . $this->transmitedArrayName . "[]=" . $object->getId(); $padding = '&'; } } $target = $this->_URL . $queryString; } } $target = UrlTools::compliantURL($target, false); if ($doRedirect) { Tools::redirectTo($target); exit; } else { return $target; } }