181 lines
7.7 KiB
PHP
181 lines
7.7 KiB
PHP
<?php
|
|
class Application_Controller_Plugin_Menu extends Zend_Controller_Plugin_Abstract
|
|
{
|
|
/**
|
|
* Menu Container
|
|
* @var Zend_Navigation_Container
|
|
*/
|
|
protected $container;
|
|
|
|
/**
|
|
* Créer le menu en fonction des besoins et des paramètres en entrée
|
|
* @param Zend_Controller_Request_Abstract $request
|
|
*/
|
|
public function preDispatch(Zend_Controller_Request_Abstract $request)
|
|
{
|
|
/**
|
|
* Définition du menu à afficher par module
|
|
* admin => Administration : Liste des utilisateurs, etc
|
|
* auth => authentification
|
|
* default
|
|
* file => Distribution des fichiers + print, pas de navbar
|
|
* help => Aide, Faq, Nouveautés
|
|
* input => Element de saisie, pas de navbar
|
|
* legal => Identite, Dirigeants, Finance, Juridique, Evaluation, Pieces Officielles, BDF !!!!!
|
|
* search => Formulaire de recherche
|
|
* user => Paramètres, Portefeuille, Surveillances
|
|
*/
|
|
|
|
$module = $request->getModuleName();
|
|
$controller = $request->getControllerName();
|
|
$action = $request->getActionName();
|
|
|
|
if ($request->isXmlHttpRequest()) {
|
|
return;
|
|
}
|
|
|
|
if ($module == 'default') {
|
|
return;
|
|
}
|
|
|
|
if ($module == 'auth') {
|
|
return;
|
|
}
|
|
|
|
Zend_Registry::get('firebug')->info('PLUGIN MENU - START');
|
|
|
|
$layout = Zend_Layout::getMVCInstance();
|
|
if ($layout->isEnabled() && $controller != 'print' ) {
|
|
$user = new Scores_Utilisateur();
|
|
if ($user->isLog()) {
|
|
switch ($module) {
|
|
case 'admin':
|
|
$view = $layout->getView();
|
|
$view->MenuAdvanced = true;
|
|
$view->MenuLabel = 'Administration';
|
|
$config = include APPLICATION_PATH . '/configs/menu.admin.php';
|
|
$this->container = new Zend_Navigation($config);
|
|
$view->navigation($this->container);
|
|
$view->headLink()
|
|
->appendStylesheet('/libs/metisMenu/metisMenu.min.css', 'all');
|
|
$view->headScript()
|
|
->appendFile('/libs/metisMenu/metisMenu.min.js', 'text/javascript');
|
|
break;
|
|
case 'search':
|
|
$view = $layout->getView();
|
|
$view->MenuAdvanced = true;
|
|
$view->MenuLabel = 'Recherche';
|
|
$config = include APPLICATION_PATH . '/configs/menu.search.php';
|
|
$this->container = new Zend_Navigation($config);
|
|
$view->navigation($this->container);
|
|
$view->headLink()
|
|
->appendStylesheet('/libs/metisMenu/metisMenu.min.css', 'all');
|
|
$view->headScript()
|
|
->appendFile('/libs/metisMenu/metisMenu.min.js', 'text/javascript');
|
|
break;
|
|
case 'user':
|
|
$view = $layout->getView();
|
|
$view->MenuAdvanced = true;
|
|
$view->MenuLabel = 'Mon compte';
|
|
$config = include APPLICATION_PATH . '/configs/menu.user.php';
|
|
$this->container = new Zend_Navigation($config);
|
|
$view->navigation($this->container);
|
|
$view->headLink()
|
|
->appendStylesheet('/libs/metisMenu/metisMenu.min.css', 'all');
|
|
$view->headScript()
|
|
->appendFile('/libs/metisMenu/metisMenu.min.js', 'text/javascript');
|
|
break;
|
|
case 'legal':
|
|
$view = $layout->getView();
|
|
$view->MenuAdvanced = true;
|
|
$view->MenuLabel = 'Informations légales';
|
|
$config = include APPLICATION_PATH . '/configs/menu.legal.php';
|
|
$this->container = new Zend_Navigation($config);
|
|
$this->setPageParams($request);
|
|
$view->navigation($this->container);
|
|
$view->headLink()
|
|
->appendStylesheet('/libs/metisMenu/metisMenu.min.css', 'all');
|
|
$view->headScript()
|
|
->appendFile('/libs/metisMenu/metisMenu.min.js', 'text/javascript');
|
|
break;
|
|
default:
|
|
// Menu Default
|
|
// --- Affichage page error
|
|
// --- Affichage page 404
|
|
|
|
// --- Override SIRET to complete with zero by left
|
|
$siret = $request->getParam('siret');
|
|
if ( intval($siret)>100 ) {
|
|
$request->setParam('siret', str_pad($siret, 9, '0', STR_PAD_LEFT));
|
|
}
|
|
|
|
// --- Génération du menu
|
|
$computeMenu = new Scores_Menu($request->getParams());
|
|
$menu = $computeMenu->getMenu();
|
|
$view = $layout->getView();
|
|
$view->navigation($menu);
|
|
|
|
// --- Identifiant Menu
|
|
$view->menuId = $computeMenu->getIdMenu($controller, $action);
|
|
|
|
// --- Page Access
|
|
$hasPerm = true;
|
|
$permPage = $computeMenu->getPagePermission($controller, $action);
|
|
if ( !empty($permPage) ) {
|
|
$hasPerm = false;
|
|
if (is_array($permPage)){
|
|
$list = $permPage;
|
|
} else if (is_string($permPage)){
|
|
$list = (array)$permPage;
|
|
}
|
|
foreach($list as $permission){
|
|
if ($user->checkPerm($permission)){
|
|
$hasPerm = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( !$hasPerm ) {
|
|
$request->setModuleName('default')->setControllerName('error')->setActionName('perms');
|
|
} else {
|
|
//Gestion affichage Lien Print / PDF / XML
|
|
$page = new Scores_Export_Print($controller, $action);
|
|
|
|
if ($page->exportable('print')){
|
|
$view->print = $page->filename('print', $request->getParams());
|
|
}
|
|
if ($page->exportable('pdf')){
|
|
$view->pdf = $page->filename('pdf', $request->getParams());
|
|
}
|
|
if ($page->exportable('xml') && in_array($user->getIdClient(), array(1,147)) ){
|
|
$view->xml = $page->filename('xml', $request->getParams());
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
Zend_Registry::get('firebug')->info('PLUGIN MENU - END');
|
|
}
|
|
|
|
/**
|
|
* Set specific page params
|
|
* @param Zend_Controller_Request_Abstract $request
|
|
*/
|
|
protected function setPageParams($request)
|
|
{
|
|
if ($this->container->hasPages()) {
|
|
foreach($this->container->getPages() as $head) {
|
|
if ($head->hasChildren()) {
|
|
foreach($head->getPages() as $page) {
|
|
// @todo : Set parameters filters by plugin ProxId "cid", "ctype"
|
|
$page->setParam('siret', $request->getParam('siret'));
|
|
$page->setParam('id', $request->getParam('id'));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |