Damien LASSERRE 15b99fdaf3
2011-06-03 08:53:22 +00:00

516 lines
12 KiB
PHP

<?php
class Menu
{
protected $menu = null;
protected $siret = null;
protected $id = 0;
protected $defineMenu = array(
array(
'label' => 'RECHERCHES',
'pages' => array(
array(
'label' => "Rechercher une entreprise",
'title' => "Rechercher une entreprise",
'controller' => 'recherche',
'action' => 'entreprise',
),
array(
'label' => "Rechercher par dirigeant",
'controller' => 'recherche',
'action' => 'dirigeant',
),
array(
'label' => "Recherche Internationale",
'controller' => '',
'action' => '',
'permission' => 'INTERNATIONAL'
),
array( // idClient = 1
'label' => "Rechercher une annonce",
'controller' => 'recherche',
'action' => 'annonce',
),
array( // ModeEdition
'label' => "Rechercher par actionnaire",
'controller' => 'recherche',
'action' => 'actionnaire'
),
array( // Vérifier la présence d'au moins une recherche
'label' => "Dernière recherche",
'controller' => 'recherche',
'action' => 'last',
),
array( // Vérifier la présence d'au moins une recherche
'label' => "Liste des dernières recherches",
'controller' => 'recherche',
'action' => 'list',
),
array(
'label' => "Centrale IparI",
'controller' => 'recherche',
'action' => 'ipari',
'permission' => 'ipari',
),
),
),
array(
'label' => 'IDENTITE',
'pages' => array(
array(
'label' => "Fiche d'identité",
'controller' => 'identite',
'action' => 'fiche',
'forceVisible' => true,
),
array(
'label' => "Fiche Procédure Collective",
'controller' => 'identite',
'action' => 'fichepc',
),
array(
'label' => "Liste des établissements",
'controller' => 'identite',
'action' => 'etablissements',
'forceVisible' => true,
),
array(
'label' => "Liens inter-entreprise",
'controller' => 'identite',
'action' => 'liens',
'forceVisible' => true,
),
array(
'label' => "Modifications Insee",
'controller' => 'identite',
'action' => 'evenements',
'forceVisible' => true,
),
),
),
array(
'label' => 'DIRIGEANTS',
'pages' => array(
array(
'label' => "Liste des dirigeants",
'controller' => 'dirigeant',
'action' => 'liste',
'forceVisible' => true,
),
array(
'label' => "Historique des dirigeants",
'controller' => 'dirigeant',
'action' => 'histo',
'forceVisible' => true,
),
),
),
array(
'label' => 'ELEMENTS FINANCIERS',
'pages' => array(
array(
'label' => "Synthèse",
'controller' => 'finance',
'action' => 'synthese',
'forceVisible' => true,
),
array(
'label' => "Bilans, Compte de résultat",
'controller' => 'finance',
'action' => 'bilan',
'forceVisible' => true,
),
array(
'label' => "Ratios",
'controller' => 'finance',
'action' => 'ratios',
'forceVisible' => true,
),
array(
'label' => "Liasse fiscale",
'controller' => 'finance',
'action' => 'liasse',
'forceVisible' => true,
),
array(
'label' => "Bourse & Cotations",
'controller' => 'finance',
'action' => 'bourse',
'forceVisible' => true,
),
array(
'label' => "Relations bancaires",
'controller' => 'finance',
'action' => 'banque',
'forceVisible' => true,
),
),
),
array(
'label' => 'ELEMENTS JURIDIQUES',
'pages' => array(
array(
'label' => "Annonces Légales",
'controller' => 'juridique',
'action' => 'annonces',
'forceVisible' => true,
),
array(
'label' => "Information Réglementée",
'controller' => 'juridique',
'action' => 'infosreg',
'forceVisible' => true,
),
array(
'label' => "Compétences Territoriales",
'controller' => 'juridique',
'action' => 'competences',
'forceVisible' => true,
),
array(
'label' => "Conventions collectives",
'controller' => 'juridique',
'action' => 'conventions',
'forceVisible' => true,
),
array(
'label' => "Marques déposées",
'controller' => 'juridique',
'action' => 'marques',
'forceVisible' => true,
),
),
),
array(
'label' => 'BANQUE DE FRANCE',
'permission' => 'BDF',
'pages' => array(
array(
'label' => "27. Panorama",
'controller' => 'bdf',
'action' => '',
),
array(
'label' => "28. Concours Bancaires",
'controller' => 'bdf',
'action' => '',
),
array(
'label' => "29. Impayés",
'controller' => 'bdf',
'action' => '',
),
array(
'controller' => 'bdf',
'action' => '',
),
array(
'label' => "40. Relations Bancaires",
'controller' => 'bdf',
'action' => '',
),
array(
'label' => "51. Dirigeants",
'controller' => 'bdf',
'action' => '',
),
array(
'label' => "Autres",
'controller' => 'bdf',
'action' => '',
),
),
),
array(
'label' => 'EVALUATION',
'pages' => array(
array(
'label' => "IndiScore",
'controller' => 'evaluation',
'action' => 'indiscore',
'forceVisible' => true,
),
array(
'label' => "Rapport de synthèse",
'controller' => 'evaluation',
'action' => 'indiscore2',
'forceVisible' => true,
),
array(
'label' => "Rapport complet",
'controller' => 'evaluation',
'action' => 'indiscore3',
'forceVisible' => true,
),
array(
'label' => "Scoring Credit Safe",
'controller' => 'evaluation',
'action' => '',
'forceVisible' => true,
),
array(
'label' => "Enquête commerciale",
'controller' => 'evaluation',
'action' => 'enquetec',
'forceVisible' => true,
),
),
),
array(
'label' => 'PIECES OFFICIELLES',
'pages' => array(
array(
'label' => "Commande de Pièces",
'controller' => 'pieces',
'action' => 'commande',
'forceVisible' => true,
),
array(
'label' => "Comptes annuels",
'controller' => 'pieces',
'action' => 'bilans',
'forceVisible' => true,
),
array(
'label' => "Actes & Statuts",
'controller' => 'pieces',
'action' => 'actes',
'forceVisible' => true,
),
array(
'label' => "Suivi Privilèges",
'controller' => 'pieces',
'action' => 'privileges',
),
),
),
array(
'label' => 'OPTIONS',
'pages' => array(
array(
'label' => "Mes options",
'controller' => 'user',
'action' => 'index',
),
array(
'label' => "Mes surveillances",
'controller' => 'surveillance',
'action' => 'liste',
),
array(
'label' => "Surveillances fichier",
'controller' => 'surveillance',
'action' => 'fichier',
),
array(
'label' => "Mon portefeuille",
'controller' => 'surveillance',
'action' => 'portefeuille',
),
array(
'label' => "Administration",
'controller' => 'user',
'action' => 'liste',
),
array(
'label' => "Commandes Greffe",
'controller' => 'dashboard',
'action' => '',
),
array(
'label' => "Commandes International",
'controller' => '',
'action' => '',
),
array(
'label' => "Commandes Giant",
'controller' => '',
'action' => '',
),
array(
'label' => "Surveillances",
'controller' => '',
'action' => '',
),
array(
'label' => "Se déconnecter",
'controller' => 'user',
'action' => 'logout',
),
),
),
array(
'label' => 'GESTION S&D',
'check' => 'dashboard',
'pages' => array(
array(
'label' => "Gestion",
'controller' => 'dashboard',
'action' => 'index',
),
),
),
);
public function __construct($siret = null, $id = 0){
$this->siret = $siret;
$this->id = $id;
$this->menu = new Zend_Navigation();
$this->computeMenu();
}
public function getMenu(){
return $this->menu;
}
protected function computeMenu(){
foreach($this->defineMenu as $element){
$perm = true;
if (array_key_exists('permission', $element)){
$perm = $this->checkPermission($element['permission']);
}
$visible = true;
if (array_key_exists('check', $element)){
$visible = $this->checkMenu($element['check']);
}
if ($perm && $visible){
$menu = array();
$menu['label'] = $element['label'];
$menu['uri'] = '#';
$menu['class'] = 'header';
if (array_key_exists('pages', $element)){
$menu['pages'] = $this->computePage($element['pages']);
}
$this->menu->addPage($menu);
}
}
}
protected function computePage($pages) {
$computePages = array();
foreach($pages as $page){
$visible = false;
if (array_key_exists('forceVisible', $page)){
$visible = $page['forceVisible'];
}
$perm = true;
if (array_key_exists('permission', $page)){
$perm = $this->checkPermission($page['permission']);
}
if (!$perm && $visible){
$computePage = array();
$computePage['label'] = $page['label'];
$computePage['class'] = 'inactif';
$computePage['uri'] = '#';
$computePages[] = $computePage;
} elseif ($perm){
if ($this->checkParams($page['controller'], $page['action'])){
$computePage = array();
$computePage = $page;
$computePage['params'] = $this->setParams($page['controller'], $page['action']);
$computePages[] = $computePage;
} elseif ($visible) {
$computePage = array();
$computePage['label'] = $page['label'];
$computePage['class'] = 'inactif';
$computePage['uri'] = '#';
$computePages[] = $computePage;
}
}
}
return $computePages;
}
protected function checkPermission($perm) {
$hasPerm = false;
if (is_array($perm)){
$list = $perm;
} else if (is_string($perm)){
$list = (array)$perm;
}
$auth = Zend_Auth::getInstance();
$droits = $auth->getIdentity()->droits;
foreach($list as $permission){
if (preg_match('/\b'.$permission.'\b/i', $droits)){
$hasPerm = true;
break;
}
}
return $hasPerm;
}
protected function checkMenu($controller)
{
switch($controller) {
case 'dashboard':
$auth = Zend_Auth::getInstance();
if (in_array($auth->getIdentity()->profil, array('Administrateur', 'SuperAdministrateur'))
&& $auth->getIdentity()->modeEdition && $auth->getIdentity()->idClient==1 ) {
return true;
}
return false;
break;
}
}
protected function checkParams($controller, $action = '')
{
switch($controller) {
case 'dashboard':
return true;
break;
case 'administration':
$auth = Zend_Auth::getInstance();
if (in_array($auth->getIdentity()->profil,
array('Administrateur', 'SuperAdministrateur'))) {
return true;
}
return false;
break;
case 'recherche':
return true;
break;
case 'user':
return true;
break;
case 'surveillance':
switch($action) {
case 'fichier':
break;
}
return true;
break;
case 'identite':
case 'dirigeant':
case 'finance':
case 'evaluation':
case 'juridique':
case 'pieces':
if ( !empty($this->siret) && intval($this->siret)!=0 )
return true;
if ( !empty($this->id) )
return true;
return false;
break;
}
}
protected function setParams($controller, $action){
$params = array();
switch($controller) {
case 'recherche':
break;
case 'evaluation':
case 'pieces':
case 'juridique':
case 'identite':
case 'finance':
case 'dirigeant':
if (!empty($this->siret)) { $params['siret'] = $this->siret; }
if (!empty($this->id)) { $params['id'] = $this->id; }
break;
}
return $params;
}
}