/** * Affiche le dialogue d'erreur pour profil insuffisant. * * @access public * @param $MissingProfilesArray : the missing profile Ids * @param $debug : boolean : TRUE pour le debug ou test * @return void */ public function showMissingProfilesDialog() { $message = sprintf(E_USER_NOT_ALLOWED, $this->getUser()->getIdentity()); $retURL = isset($_REQUEST['retURL']) ? $_REQUEST['retURL'] : 'home.php'; Template::errorDialog($message, $retURL); exit; }
/** * Affiche le resultat de la recherche * * @param object $grid objet de type Grid * @param boolean $pager : pagination * @param array or object $filter * @param array $order * @param string $title titre de la page * @param array $JSRequirements * @param string $addContent Contenu html à ajouter avant ou apres le Grid * de la forme: array('beforeForm' => '...', // avant le SearchForm * 'between' => '...', // entre le SearchForm et le Grid... * 'afterGrid' => '...') * @return string */ public function displayResult($grid, $pager = false, $filter = array(), $order = array(), $title = '', $JSRequirements = array(), $addContent = array(), $renderFunc = 'page') { // Si on ne passe pas une Collection directemt au Grid::render() if ($this->getItemsCollection() === false) { $mapper = Mapper::singleton($this->entity); if (!$grid->getMapper() instanceof Mapper) { $grid->setMapper($mapper); } } if ($grid->isPendingAction()) { $dispatchResult = $grid->dispatchAction($this->getItemsCollection()); if (Tools::isException($dispatchResult)) { $urlVarArray = array(); // On passe ds l'url les valeurs des hidden s'il y en a $hiddenFields = $this->getHiddenFields(); foreach ($hiddenFields as $key => $value) { if ($key == 'formSubmitted') { continue; } $urlVarArray[] = $key . '=' . $value; } $urlComplement = empty($urlVarArray) ? '' : '?' . implode('&', $urlVarArray); // L'action est-elle de type Popup: $triggeredAction = $grid->getAction($_REQUEST['actionId']); if ($triggeredAction->targetPopup === true) { $tpl = BASE_POPUP_TEMPLATE; $returnURL = 'javascript:window.close()'; } else { $tpl = BASE_TEMPLATE; $returnURL = basename($_SERVER['PHP_SELF']) . $urlComplement; } Template::errorDialog($dispatchResult->getMessage(), $returnURL, $tpl); exit; } } else { if ($this->getItemsCollection() !== false) { $mapper = $this->getItemsCollection(); } $result = $grid->render($mapper, $pager, $filter, $order); $addContent['beforeForm'] = isset($addContent['beforeForm']) ? $addContent['beforeForm'] : ''; $addContent['between'] = isset($addContent['between']) ? $addContent['between'] : ''; $addContent['afterGrid'] = isset($addContent['afterGrid']) ? $addContent['afterGrid'] : ''; $pageContent = $addContent['beforeForm'] . $this->render() . $addContent['between'] . $result . $addContent['afterGrid']; if (isset($_REQUEST['formSubmitted'])) { SearchTools::saveLastEntitySearched(); } Template::$renderFunc($title, $pageContent . '</form>', $JSRequirements); exit; } }
/** * Retourne un FilterComponent * * @param string $Attribute nom de l'attribut sur lequel s'effectue le filtre * @param string $DbTablesPath chemin en cas de jointure, ou '' si pas de jointure * Exple: ''ActivatedOperation.ActivatedChain.CommandItem().Command.CommandNo' * les () expriment une relation 1..* ou *..* * Autre type de path autorise: Command@ProductCommand.CommandItem().Product.BaseReference * le "@" permet de gerer le pb de l'heritage: on force la classe ProductCommand ici * @param string $Operator "Like" ou "Equal" ou "NotLike", ...: * cf ds SearchTools::getToSqlOperator() tous les operateurs disponibles * @param string $Value valeur du champs: facultatif * @param int $force (facultatif): si vaut 1 (0 par defaut), force la * construction du FilterComponent, * même si pas de var REQUEST ou SESSION reçue * @param string $startEntity nom de l'entité cherché dans le cas où il y a * une relation 1..* ou *..* * @static * @return object FilterComponent ou false */ static function newFilterComponent($Attribute, $DbTablesPath, $Operator = 'Equals', $Value = '', $force = 0, $startEntity = '') { $OperatorArray = array('Like', 'NotLike', 'Equals', 'NotEquals', 'GreaterThan', 'GreaterThanOrEquals', 'LowerThan', 'LowerThanOrEquals', 'In', 'NotIn', 'IsNull', 'IsNotNull'); if (!in_array($Operator, $OperatorArray)) { Template::errorDialog('Bad operator. Filter can\'t be builded.', $_SERVER['PHP_SELF']); exit; } unset($FilterComponent); $FilterComponent = new FilterComponent(); $FilterRuleOperator = SearchTools::getToSqlOperator($Operator); $pos = strpos($DbTablesPath, "()"); if ($pos === false) { // Pas de relation * ds la jointure eventuelle if (isset($_REQUEST[$Attribute]) && $_REQUEST[$Attribute] != '' && $_REQUEST[$Attribute] != '##' || isset($_SESSION[$Attribute]) && $_SESSION[$Attribute] != '' && $_SESSION[$Attribute] != '##' || $force == 1) { // || !(is_string($Value) && $Value == '') // selon si jointure ou pas $DbTablesPath = $DbTablesPath == "" ? $Attribute : $DbTablesPath; /* si c'est c'est un tab de valeurs, par exple un select multiple */ if (isset($_REQUEST[$Attribute]) && is_array($_REQUEST[$Attribute]) || isset($_SESSION[$Attribute]) && is_array($_SESSION[$Attribute]) || is_array($Value)) { if ($force == 1) { $Array = $Value; } else { $Array = isset($_REQUEST[$Attribute]) ? $_REQUEST[$Attribute] : $_SESSION[$Attribute]; } // pour une raison que j'ignore, $Array n'est dans certains // cas pas un array :/ on fait ce truc ici donc pour s'en // assurer: if (!is_array($Array)) { $Array = array($Array); } if (!in_array('##', $Array, true)) { // si la bonne selection foreach ($Array as $key => $val) { $Array[$key] = $Operator == 'Like' || $Operator == 'NotLike' ? str_replace('*', "%", $val) : $val; } if (in_array($Operator, array('Equals', 'In'))) { $ope = FilterRule::OPERATOR_IN; } elseif (in_array($Operator, array('NotEquals', 'NotIn'))) { $ope = FilterRule::OPERATOR_NOT_IN; } elseif (in_array($Operator, array('Like', 'NotLike'))) { foreach ($Array as $key => $val) { $FilterComponent->setItem(new FilterRule($DbTablesPath, $FilterRuleOperator, $Array[$key])); // c'est un OR ds ce cas!! $FilterComponent->operator = FilterComponent::OPERATOR_OR; } return $FilterComponent; } else { return null; } // Pas de sens dans ce cas (autres operateurs) $FilterComponent->setItem(new FilterRule($DbTablesPath, $ope, $Array)); } else { return false; } // si '##' selectionne } else { if (is_string($Value) && $Value == "") { // !empty($Value) if ($force == 0) { if (isset($_REQUEST[$Attribute]) && ($_REQUEST[$Attribute] == '' || $_REQUEST[$Attribute] == '##')) { return false; // pas de filtre dans ce cas } $Value = isset($_REQUEST[$Attribute]) ? strtoupper($_REQUEST[$Attribute]) : strtoupper($_SESSION[$Attribute]); } } else { $Value = is_string($Value) ? strtoupper($Value) : $Value; } $AttributeValue = $Operator == 'Like' || $Operator == 'NotLike' ? str_replace('*', "%", $Value) : $Value; $FilterComponent->setItem(new FilterRule($DbTablesPath, $FilterRuleOperator, $AttributeValue)); } return $FilterComponent; } } else { // Au moins une relation 1..* ou *..* ds la jointure eventuelle if (isset($_REQUEST[$Attribute]) && $_REQUEST[$Attribute] != '' && $_REQUEST[$Attribute] != '##' || isset($_SESSION[$Attribute]) && $_SESSION[$Attribute] != '' && $_SESSION[$Attribute] != '##' || $force == 1 || !empty($Value)) { // ne pas oublier de preciser ce parametre pour les relation 1..* if ($startEntity == '') { trigger_error('There is a 1..* relation in search criterions: you have to define EntitySearched in SearchForm constructor call !!', E_USER_ERROR); exit; } if ($Value == '' && SearchTools::requestOrSessionExist($Attribute) !== false) { $Value = SearchTools::requestOrSessionExist($Attribute); } if (is_string($Value)) { $Value = strtoupper($Value); } elseif (is_array($Value) && in_array('##', $Value)) { return false; } // Recuperation des Id qui conviennent $sql = SearchTools::getSQLfromMacro($startEntity, $DbTablesPath, $FilterRuleOperator, $Value); $result = Database::connection()->execute($sql); if (false === $result) { // si erreur sql if (DEV_VERSION) { echo $sql . '<br />'; } trigger_error(Database::connection()->ErrorMsg(), E_USER_ERROR); } if ($result->_numOfRows == 0) { // si 0 resultat $FilterComponent->setItem(new FilterRule('Id', FilterRule::OPERATOR_EQUALS, 0)); return $FilterComponent; } $valueArray = array(); while (!$result->EOF) { $valueArray[] = (int) $result->fields['_Id']; $result->moveNext(); } $FilterComponent->setItem(new FilterRule('Id', FilterRule::OPERATOR_IN, $valueArray)); return $FilterComponent; } } return false; }
/** * Méthode qui gère l'action delete, supprime l'objet dans une transaction. * * @access protected * @return void */ protected function delete() { $this->onBeforeDelete(); Database::connection()->startTrans(); $mapper = Mapper::singleton($this->clsname); $emptyForDeleteProperties = call_user_func(array($this->clsname, 'getEmptyForDeleteProperties')); $notDeletedObjects = array(); // il y a des check auto on supprime un à un car les verif ne sont // pas faites par Mapper::delete() mais par Object::delete() $col = $mapper->loadCollection(array('Id' => $this->objID)); $count = $col->getCount(); for ($i = 0; $i < $count; $i++) { $o = $col->getItem($i); try { $o->delete(); } catch (Exception $exc) { $notDeletedObjects[] = $o->toString(); //. ': ' . $exc->getMessage(); } } if (Database::connection()->hasFailedTrans()) { $err = Database::connection()->errorMsg(); trigger_error($err, E_USER_WARNING); Database::connection()->rollbackTrans(); Template::errorDialog(E_ERROR_SQL . '.<br/>' . $err, $this->guessReturnURL()); exit; } Database::connection()->completeTrans(); if (!empty($notDeletedObjects)) { Template::infoDialog(sprintf(I_NOT_DELETED_WITH_LIST, implode('</li><li>', $notDeletedObjects)), $this->guessReturnURL()); exit; } $this->onAfterDelete(); }