noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_profile_menu.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00020 
00021 require_once 'class_profile_menu_sql.php';
00022 
00023 /**
00024  * Manage the menu of a profile
00025  *
00026  * @author dany
00027  */
00028 class Profile_Menu
00029 {
00030 
00031         function __construct($p_cn)
00032         {
00033                 $this->cn = $p_cn;
00034         }
00035         /**
00036          * Display the content of a profile
00037          * @param type $resource
00038          * @param type $p_id
00039          */
00040         function sub_menu($resource, $p_id)
00041         {
00042                 if (Database::num_row($resource) != 0)
00043                 {
00044                         $gDossier = dossier::id();
00045                         echo '<ul style="list-style-type:none">';
00046                         for ($e = 0; $e < Database::num_row($resource); $e++)
00047                         {
00048                                 $menu = Database::fetch_array($resource, $e);
00049                                 $me_code = $menu['me_code'];
00050 
00051                                 $me_code_dep = $menu['me_code_dep'];
00052 
00053                                 $mp_type = $menu['p_type_display'];
00054 
00055                                 $me_menu = $menu['me_menu'];
00056                                 $me_desc = $menu['me_description'];
00057                                 $me_def=($menu['pm_default']=='1')?'<span class="notice" style="display:inline">Défaut</span>':'';
00058                                 $js = sprintf(
00059                                                 '<a class="line" href="javascript:void(0)" onclick="mod_menu(\'%s\',\'%s\')">%s</A>', $gDossier, $menu['pm_id'], $me_code);
00060                                 ?>
00061                                 <li>
00062 
00063                                         <?php echo  $me_menu?>
00064                                         ( <?php echo  $js?> )
00065                                         <?php echo  $me_desc?>  <?php echo $me_def?>
00066                                         <?php 
00067                                         $ret2 = $this->cn->exec_sql("
00068                                                                         SELECT pm_id,
00069                                                                                 pm.me_code,
00070                                                                                 me_code_dep,
00071                                                                                 p_id,
00072                                                                                 p_order,
00073                                                                                 p_type_display,
00074                                                                                 pm_default,
00075                                                                                 pm_desc,
00076                                                                                 me_menu,
00077                                                                                 me_description
00078                                                                                 FROM profile_menu as pm
00079                                                                                         join profile_menu_type on (p_type_display=pm_type)
00080                                                                                         join menu_ref as mr on (mr.me_code=pm.me_code)
00081                                                                                 where
00082                                                                                 p_id=$1 and me_code_dep=$2
00083                                                                                 order by p_order asc
00084                                                         ", array($p_id, $me_code));
00085                                         $this->sub_menu($ret2, $p_id);
00086                                         echo "</li>";
00087                                 } //end loop e
00088                                 echo '</ul>';
00089                         } // end if
00090                 }
00091 
00092                 /**
00093                  * Show a table with all the menu and the type
00094                  * @param type $p_id profile.p_id
00095                  */
00096                 function listing_profile($p_id)
00097                 {
00098                         $array = $this->cn->get_array("
00099                         SELECT pm_id,
00100                                         pm.me_code,
00101                                         me_code_dep,
00102                                         p_id,
00103                                         p_order,
00104                                         p_type_display,
00105                                         pm_default,
00106                                         pm_desc,
00107                                         me_menu,
00108                                         me_description
00109                         FROM profile_menu as pm join profile_menu_type on (p_type_display=pm_type)
00110                         join menu_ref as mr on (mr.me_code=pm.me_code)
00111                         where
00112                         p_id=$1 and p_type_display='M'
00113                         order by p_order asc
00114                         ", array($p_id));
00115                         if (count($array) == 0)
00116                         {
00117                                 // if not module show only menu
00118                                 $ret = $this->cn->exec_sql("
00119                                                                                 SELECT pm_id,
00120                                                                                 pm.me_code,
00121                                                                                 me_code_dep,
00122                                                                                 p_id,
00123                                                                                 p_order,
00124                                                                                 p_type_display,
00125                                                                                 pm_default,
00126                                                                                 pm_desc,
00127                                                                                 me_menu,
00128                                                                                 me_description
00129                                                                                 FROM profile_menu as pm
00130                                                                                         join profile_menu_type on (p_type_display=pm_type)
00131                                                                                         join menu_ref as mr on (mr.me_code=pm.me_code)
00132                                         where
00133                                         p_id=$1 and p_type_display='E'
00134                                         order by p_order asc
00135                                                         ", array($p_id));
00136                                 echo '<ul style="list-style-type:none">';
00137 
00138                                 $this->sub_menu($ret, $p_id);
00139                                 // $this->listing_profile($p_id,$ret, $array[$i]['me_code']);
00140 
00141                                 echo "</li>";
00142                                 echo '</ul>';
00143                         }
00144                         else
00145                         {
00146                                 $this->cn->prepare("menu", "
00147                                 SELECT pm_id,
00148                                                                                 pm.me_code,
00149                                                                                 me_code_dep,
00150                                                                                 p_id,
00151                                                                                 p_order,
00152                                                                                 p_type_display,
00153                                                                                 pm_default,
00154                                                                                 pm_desc,
00155                                                                                 me_menu,
00156                                                                                 me_description
00157                                                                                 FROM profile_menu as pm
00158                                                                                         join profile_menu_type on (p_type_display=pm_type)
00159                                                                                         join menu_ref as mr on (mr.me_code=pm.me_code)
00160                                         where
00161                                         p_id=$1 and me_code_dep=$2 and p_type_display in ('E','S')
00162                                         order by p_order asc
00163                                                         ");
00164                                 echo '<ul style="list-style-type:none">';
00165                                 // Menu by module
00166                                 $gDossier = Dossier::id();
00167                                 for ($i = 0; $i < count($array); $i++)
00168                                 {
00169                                         $me_def=($array[$i]['pm_default']=='1')?'<span class="notice" style="display:inline">Défaut</span>':'';
00170                                         $js = sprintf('<a class="line" style="display:inline;text-decoration:underline"
00171                                                 href="javascript:void(0)" onclick="mod_menu(\'%s\',\'%s\')">%s</A>', $gDossier, $array[$i]['pm_id'], $array[$i]['me_code']);
00172                                         echo "<li>" . $array[$i]['me_menu'] . " (" . $js . ")" . $array[$i]['me_description']." ".$me_def;
00173 
00174                                         $ret = $this->cn->execute("menu", array($p_id, $array[$i]['me_code']));
00175                                         $this->sub_menu($ret, $p_id);
00176 
00177                                         echo "</li>";
00178                                 }// end loop i
00179                                 echo '</ul>';
00180                                 //*******************************************
00181                                 // show also menu without a module
00182                                 //*******************************************
00183                                 $ret = $this->cn->exec_sql("
00184                                                                                 SELECT pm_id,
00185                                                                                 pm.me_code,
00186                                                                                 me_code_dep,
00187                                                                                 p_id,
00188                                                                                 p_order,
00189                                                                                 p_type_display,
00190                                                                                 pm_default,
00191                                                                                 pm_desc,
00192                                                                                 me_menu,
00193                                                                                 me_description
00194                                                                                 FROM profile_menu as pm
00195                                                                                         join profile_menu_type on (p_type_display=pm_type)
00196                                                                                         join menu_ref as mr on (mr.me_code=pm.me_code)
00197                                         where
00198                                         p_id=$1 and  p_type_display not in ('M','P') and me_code_dep is null
00199                                         order by p_order asc
00200                                                         ", array($p_id));
00201                                 if (Database::num_row($ret))
00202                                 {
00203                                         echo "<h2>Menu sans module</h2>";
00204                                         $this->sub_menu($ret, $p_id);
00205                                 }
00206                         }
00207                 }
00208 
00209                 function printing($p_id)
00210                 {
00211                         $ret = $this->cn->exec_sql("
00212                                 SELECT pm_id,
00213                                                                                 pm.me_code,
00214                                                                                 me_code_dep,
00215                                                                                 p_id,
00216                                                                                 p_order,
00217                                                                                 p_type_display,
00218                                                                                 pm_default,
00219                                                                                 pm_desc,
00220                                                                                 me_menu,
00221                                                                                 me_description
00222                                                                                 FROM profile_menu as pm
00223                                                                                         join profile_menu_type on (p_type_display=pm_type)
00224                                                                                         join menu_ref as mr on (mr.me_code=pm.me_code)
00225                                         where
00226                                         p_id=$1 and me_type='PR'
00227                                         order by p_order asc
00228                                                         ", array($p_id));
00229                         // Menu by module
00230                         $gDossier = Dossier::id();
00231                         $this->sub_menu($ret, $p_id);
00232                 }
00233                 /**
00234                  * Show the available profile for the profile $p_id, it concerns only the action of management (action-gestion)
00235                  * @param $p_id is the profile p_id
00236                  */
00237                 function available_profile($p_id)
00238                 {
00239                         $array=$this->cn->get_array("
00240                                         select p.p_id,p.p_name,s.p_granted,s.ua_id,s.ua_right
00241                                                 from profile as p
00242                                                 join user_sec_action_profile as s on (s.p_granted=p.p_id)
00243                                                 where s.p_id=$1
00244                                         union
00245                                                 select p2.p_id, p2.p_name,null,null,'X'
00246                                                 from profile as p2
00247                                                 where
00248                                                 p2.p_id not in (select p_granted from user_sec_action_profile where p_id = $1) order by p_name;
00249                                 ",array($p_id));
00250                         $aright_value=array(
00251                                                                 array('value'=>'R','label'=>_('Lecture')),
00252                                                                 array('value'=>'W','label'=>_('Ecriture')),
00253                                                                 array('value'=>'X','label'=>_('Aucun accès'))
00254                                         );
00255                         require_once 'template/user_sec_profile.php';
00256                 }
00257                 /**
00258                  * Show the available repository for the profile $p_id
00259                  * @param $p_id is the profile p_id
00260                  */
00261                 function available_repository($p_id)
00262                 {
00263                         $array=$this->cn->get_array("
00264                                         select p.r_id,p.r_name,s.ur_id,s.ur_right
00265                                                 from stock_repository as p
00266                                                 join profile_sec_repository as s on (s.r_id=p.r_id)
00267                                                 where s.p_id=$1
00268                                         union
00269                                                 select p2.r_id, p2.r_name,null,'X'
00270                                                 from stock_repository as p2
00271                                                 where
00272                                                 p2.r_id not in (select r_id from profile_sec_repository where p_id = $1) order by r_name;
00273                                 ",array($p_id));
00274                         $aright_value=array(
00275                                                                 array('value'=>'R','label'=>_('Lecture')),
00276                                                                 array('value'=>'W','label'=>_('Ecriture')),
00277                                                                 array('value'=>'X','label'=>_('Aucun accès'))
00278                                         );
00279                         require_once 'template/profile_sec_repository.php';
00280                 }
00281         }
00282         //end class
00283         ?>
 All Data Structures Namespaces Files Functions Variables Enumerations