Source for file Ldap2Mysql.php

Documentation is available at Ldap2Mysql.php

  1. <?php
  2. /*-----------------------------------------------------------------------*                             
  3.                              modules : Ldap2Mysql
  4.                              projet : Ldap2Mysql-Authentification
  5.                              CHEFS DE PROJETS : P.BAFFALIE, S.GRESSARD
  6.  
  7.  Description :      importation des utilisateurs ldap=>mysql et gestion du mode d'authentification          
  8.                              -
  9.  Environnement PHP   : PHP4 OU PHP5
  10.  author                    : nordine.zetoutou<nzetoutou@educagri.fr>
  11.  date de création     : 25 sept. 06 
  12.  Historique de modification :
  13.                              -
  14.                              -
  15.  version                   :    1.0
  16. /*-----------------------------------------------------------------------*/
  17.  
  18.  
  19. /**
  20.    * Classe  Ldap2Mysql
  21.    * 
  22.    * @author Nordine Zetoutou  - <nzetoutou@educagri.fr>
  23.    * @package Ldap2Mysql-Authentification
  24.    * @module Ldap2Mysql
  25.    * @description importation/mise à jour des utilisateurs ldap=>mysql
  26.    * @dependance  activation de l'extension php_ldap
  27.    * @dependance  si CAS comme serveur d'authentification activation  de l'extension=php_curl.dll
  28.    * @dependance  module de gestion de langue : Lang
  29.    * 
  30.    * @license GPL
  31.    * @version 1.0
  32.    * @date   25 sept. 2006
  33.    
  34. */
  35.  
  36. class Ldap2Mysql
  37. {
  38.     //@promethee
  39.     //table à mettre à jour
  40.     
  41.     var $sMysqlTableToUpdate = 'user_id';
  42.     //tableau contenant les droits utilisateurs
  43.     
  44.     var $aMysqlTableUserGroups = array (
  45.         'table' => 'user_group',
  46.         'field_id' => '_IDgrp',
  47.         'field_groupeType' => '_ident'
  48.     );
  49.     var $dateCreation = '_create';
  50.     var $champ_motDePasse = '_passwd';
  51.     var $champ_login = '_ident';
  52.     var $aListeChampToUpdate = array (
  53.         '_nom' => 'nom',
  54.         '_email' => 'email'
  55.     );
  56.     //fin @promethee
  57.     //masque le select des bases
  58.     
  59.     var $blisteDeroulanteVisible = false;
  60.     //initialisation du filtre de recherche ldap
  61.     
  62.     var $sFilter = '';
  63.     //
  64.         var $bCheckbox_includeImportedUsers = false;
  65.     //
  66.     //
  67.     //
  68.     //
  69.     //
  70.         /** 
  71.      * constructeur
  72.      * 
  73.      * @description initialise la classe avec
  74.      * @param string $slang 
  75.      */
  76.     function Ldap2Mysql($lang 'fr_FR')
  77.     {
  78.         //chargement d'un tableau des libelles et messages selon la langue par
  79.         $this->getParamLang($lang);
  80.         $this->lang $lang;
  81.         //
  82.         
  83.         define('MODULE_DIR','ldap2Mysql/');
  84.         //
  85.         define('TEMP_DIR'MODULE_DIR 'tmp/');
  86.         define('CONFIG_DIR'MODULE_DIR '/config/');
  87.         define('CONFIG_DOC'MODULE_DIR '/doc/');
  88.         define('IMAGE_DIR'MODULE_DIR '/images/');
  89.         //on tente de créer les différents répertoires si inexistants avec droits entiers
  90.         mkdir(MODULE_DIR '/tmp'0777);
  91.         mkdir(MODULE_DIR '/config'0777);
  92.         mkdir(MODULE_DIR '/images'0777);
  93.         //
  94.         if (!isset ($_SESSION))
  95.         {
  96.             session_start();
  97.         }
  98.         //
  99.         $this->fBaseAuth CONFIG_DIR 'baseAuth';
  100.         //
  101.         define('SPACE6'str_repeat(' '6));
  102.         define('SPACE5'str_repeat(' '5));
  103.         define('SPACE4'str_repeat(' '4));
  104.         define('SPACE3'str_repeat(' '3));
  105.         define('SPACE2'str_repeat(' '2));
  106.         define('SPACE1'str_repeat(' '1));
  107.         //
  108.         //
  109.     }
  110.     //
  111.     //
  112.         /**
  113.      * @description manuel d'utilisation simplifié
  114.      * @todo à complèter ou à améliorer
  115.      */
  116.     function manual_view()
  117.     {
  118.         $file MODULE_DIR 'manual/' 'manual_' $this->lang '.txt';
  119.         $content file_get_contents($file);
  120.         return $content;
  121.     }
  122.     //
  123.         function authModeConfig_controller()
  124.     {
  125.         $fFile $this->fBaseAuth;
  126.         //
  127.         if (!empty ($_POST['btn_validerSelect']))
  128.         {
  129.             if (!empty ($_POST['select_listBase']))
  130.             {
  131.                 //
  132.                 if ($_POST['select_listBase'== 'NoAuthentification')
  133.                 {
  134.                     //si le fichier n'existe pas on tente de le créer
  135.                     $handle fopen($fFile'w+');
  136.                     fwrite($handle'NoAuthentification');
  137.                     fclose($handle);
  138.                     $selected_item 'NoAuthentification';
  139.                 }
  140.                 else
  141.                 {
  142.                     //on charge les informations de la base choisi et on crée un fichier de config
  143.                     $arr array ();
  144.                     $obj $this->baseLoadParam($_POST['select_listBase']);
  145.                     //
  146.                     switch ($obj->type->value)
  147.                     {
  148.                         case 'cas' :
  149.                             $arr['id'$obj->id->value;
  150.                             $arr['type'$obj->type->value;
  151.                             $arr['host'$obj->host->value;
  152.                             $arr['port'$obj->port->value;
  153.                             break;
  154.                         case 'ldap' :
  155.                             $arr['id'$obj->id->value;
  156.                             $arr['type'$obj->type->value;
  157.                             $arr['host'$obj->host->value;
  158.                             //
  159.                             $port 389;
  160.                             if ($obj->port->value)
  161.                             {
  162.                                 $port $obj->port->value;
  163.                             }
  164.                             $arr['port'$port;
  165.                             //
  166.                             $arr['login_field'$obj->login_field->value;
  167.                             $arr['ldap_user_id_field'$obj->ldap_user_id_field->value;
  168.                             $arr['dn'$obj->dn->value;
  169.                             break;
  170.                     }
  171.                     $oBase = (object) $arr;
  172.                     //
  173.                     //si le fichier n'existe pas on tente de le créer                    
  174.                     $handle fopen($fFile'w+');
  175.                     fwrite($handleserialize($oBase));
  176.                     fclose($handle);
  177.                     //on charge le serveur activé
  178.                 }
  179.             //fin if
  180.         }
  181.         //
  182.         return $this->authModeConfig_view();
  183.     }
  184.     /**
  185.      * @description récupère le contenu du fichier : soit une config d'une base soit une
  186.      *  chaine spécifiant que le mode d'authentification externe est désactivé
  187.      * @return object $oBase ou  string null
  188.      */
  189.     function authMode_getContentFile()
  190.     {
  191.         $fFile $this->fBaseAuth;
  192.         if (file_exists($fFile))
  193.         {
  194.             $sFileContent file_get_contents($fFile);
  195.             //juste une chaine
  196.             if ($sFileContent == 'NoAuthentification')
  197.             {
  198.                 return 'NoAuthentification';
  199.             }
  200.             else
  201.             {
  202.                 //alors c'est un objet base
  203.                 $oBase unserialize($sFileContent);
  204.                 return $oBase;
  205.             }
  206.         }
  207.     }
  208.     //
  209.         /**
  210.      * @description affiche le mode d'authentification à choisir
  211.      */
  212.     function authModeConfig_view()
  213.     {
  214.         $arr $this->baseLoadList();
  215.         //
  216.         //
  217.         if (is_array($arr))
  218.         {
  219.             foreach ($arr as $key => $oBase)
  220.             {
  221.                 //on prend que le cas et le ldap 
  222.                 //
  223.                 if ($oBase->type->value <> 'mysql')
  224.                 {
  225.                     $aoListeBase[$key$oBase;
  226.                 //fin if
  227.                 //
  228.             }
  229.             //
  230.         //fin if
  231.         //
  232.         $obj new stdClass();
  233.         $obj->nom new stdClass();
  234.         $obj->nom->value $this->aParamLang['authMode']['NoAuthentification'];
  235.         $aoListeBase['NoAuthentification'$obj;
  236.         //
  237.         $aContent['<div class="row">';
  238.         //
  239.         $aContent['<span>' $this->aParamLang['authMode']['libelle_1'' : </span>';
  240.         //
  241.         $contentFile $this->authMode_getContentFile();
  242.         //
  243.         if (is_object($contentFile))
  244.         {
  245.             $selected_item $contentFile->id;
  246.         }
  247.         else
  248.         {
  249.             $selected_item $contentFile;
  250.         }
  251.         //
  252.         $aContent[$this->buildSelectListeBase($aoListeBase'noOption'$selected_item);
  253.         //
  254.         $aContent['</div>';
  255.         //
  256.         return implode("\n"$aContent);
  257.     }
  258.     /**
  259.      * @description  fonction de suppression d'un objet (représentant une configuration d'une importation) dans le fichier import
  260.      * @param objet $oParamImport 
  261.      */
  262.     function importConfig_save_delete($objetToSerialize$sDelete null)
  263.     {
  264.         //
  265.         $file CONFIG_DIR 'importConfig';
  266.         //
  267.         $aObjet array ();
  268.         if (file_exists($file))
  269.         {
  270.             //on charge  le fichier texte, chaque ligne est un objet
  271.             $aObjet unserialize(file_get_contents($file));
  272.         }
  273.         //
  274.         $aObjet[$objetToSerialize->id$objetToSerialize;
  275.         //suppression
  276.         if ($sDelete == 'delete')
  277.         {
  278.             unset ($aObjet[$objetToSerialize->id]);
  279.         }
  280.         //si le fichier n'existe pas on tente de le créer
  281.         $handle fopen($file'w+');
  282.         fwrite($handleserialize($aObjet));
  283.         //
  284.         $bIsSucceed fclose($handle);
  285.         if ($bIsSucceed == true)
  286.         {
  287.             $_SESSION['Ldap2Mysql']['writeFileMessageSucceed'$this->aParamLang['config_import']['writeFileMessageSucceed'];
  288.         }
  289.         else
  290.         {
  291.             $_SESSION['Ldap2Mysql']['writeFileMessageNotSucceed'$this->aParamLang['config_import']['writeFileMessageNotSucceed'];
  292.         }
  293.         //
  294.     }
  295.     //
  296.         /**
  297.      * @description execute les actions relatives aux chargements des champs ldap et mysql
  298.      *   execute les actions relatives à l'ajout/suppression des champs de correspondance
  299.      * 
  300.      */
  301.     function importConfig_controller()
  302.     {
  303.         if (!empty ($_POST['btn_addToListFieldsToImport']))
  304.         {
  305.             //
  306.             if (!empty ($_POST['select_ldap_ListFields']AND !empty ($_POST['select_mysql_ListFields']))
  307.             {
  308.                 //le champ ldap à correspondre
  309.                 $ldapFieldToConnect $_POST['select_ldap_ListFields'];
  310.                 //le champ mysql à correspondre
  311.                 $mysqlFieldToConnect $_POST['select_mysql_ListFields'];
  312.                 //
  313.                 $aCorrespondance array (
  314.                     'ldap_ListFields' => $ldapFieldToConnect,
  315.                     'mysql_ListFields' => $mysqlFieldToConnect
  316.                 );
  317.                 //la création d'un id unique par md5 facilite la suppression  
  318.                 $correspondance_id md5($ldapFieldToConnect);
  319.                 //stocke la liste des champs ldap et mysql sous forme de tableaux
  320.                 $_SESSION['Ldap2Mysql']['listFieldsToImport'][$correspondance_id$aCorrespondance;
  321.                 //suppression des doublons des champs mysql
  322.                 $session $_SESSION['Ldap2Mysql']['listFieldsToImport'];
  323.                 //
  324.                 //on regarde si 2 champs mysql similaire existe
  325.                 foreach ($session as $key => $array)
  326.                 {
  327.                     //
  328.                     if ($mysqlFieldToConnect == $array['mysql_ListFields'])
  329.                     {
  330.                         $keyTrouve[$key;
  331.                     }
  332.                     //
  333.                 }
  334.                 //
  335.                 if (count($keyTrouve1)
  336.                 {
  337.                     unset ($_SESSION['Ldap2Mysql']['listFieldsToImport'][$keyTrouve[0]]);
  338.                 }
  339.             //fin if
  340.         //fin if
  341.         //
  342.         if (!empty ($_POST['btn_loadListFields']))
  343.         {
  344.             //
  345.             if (isset ($_SESSION['Ldap2Mysql']['listFieldsToImport']))
  346.             {
  347.                 unset ($_SESSION['Ldap2Mysql']['listFieldsToImport']);
  348.             //fin if
  349.             //
  350.         }
  351.         //
  352.         if (!empty ($_POST['select_listeBase_ldap']AND !empty ($_POST['select_listeBase_mysql']))
  353.         {
  354.             $_SESSION['Ldap2Mysql']['ldap_selected_id'$_POST['select_listeBase_ldap'];
  355.             $_SESSION['Ldap2Mysql']['mysql_selected_id'$_POST['select_listeBase_mysql'];
  356.         }
  357.         //
  358.         if (!empty ($_POST['btn_enregisterImportConfig']))
  359.         {
  360.             $ldap_selected_id $_SESSION['Ldap2Mysql']['ldap_selected_id'];
  361.             $mysql_selected_id $_SESSION['Ldap2Mysql']['mysql_selected_id'];
  362.             //
  363.             $oParamImport new stdClass();
  364.             //on cree un id pour cet import qui sera une date avec l'heure
  365.             $oParamImport->id md5($ldap_selected_id $mysql_selected_id);
  366.             //l'id du ldap (défini lors de son enregistrement dans le fichier de config)
  367.             $oParamImport->ldap_id $ldap_selected_id;
  368.             //l'id du mysql (défini lors de son enregistrement dans le fichier de config)
  369.             $oParamImport->mysql_id $mysql_selected_id;
  370.             //
  371.             $oParamImport->mysql_detailedListFields $_SESSION['Ldap2Mysql']['mysql_detailedListFields'];
  372.             //
  373.             if (!empty ($_SESSION['Ldap2Mysql']['listFieldsToImport']))
  374.             {
  375.                 $oParamImport->listFieldsToImport $_SESSION['Ldap2Mysql']['listFieldsToImport'];
  376.                 $this->importConfig_save_delete($oParamImport);
  377.             }
  378.             //on efface de la session la dernière récupération
  379.             $this->delete_var_session();
  380.             //return;
  381.         }
  382.         if ($_POST)
  383.         {
  384.             //
  385.             foreach ($_POST as $key => $value)
  386.             {
  387.                 $array explode('_'$key);
  388.                 //suppression d'une correspondance
  389.                 if (isset ($array[1]AND $array[1== 'supprimerCorrespondance')
  390.                 {
  391.                     unset ($_SESSION['Ldap2Mysql']['listFieldsToImport'][$array[2]]);
  392.                     //on sort de la boucle si trouvé
  393.                     break;
  394.                 }
  395.                 //
  396.             }
  397.             //
  398.         }
  399.         //
  400.         return $this->importConfig_view();
  401.         //
  402.     }
  403.     //
  404.         /**
  405.      * @description affiche le l'interface de la config
  406.      */
  407.     function importConfig_view()
  408.     {
  409.         //
  410.         $aContent['<div class="row">';
  411.         $aContent['<span class="etape">' $this->aParamLang['base']['libelle_8'' 1 :</span>';
  412.         $aContent['</div>';
  413.         //liste de tous les serveurs
  414.         $aContent['<div class="colonneGauche">';
  415.         //on récupère toutes les base mysql et ldap
  416.         $aAllBases $this->getAllBases();
  417.         $aLdapAllBases $aAllBases['ldap'];
  418.         $aMysqlAllBases $aAllBases['mysql'];
  419.         //liste des serveurs ldap
  420.         $aContent['&raquo;&nbsp;' $this->aParamLang['base']['libelle_1'' <b>LDAP</b> <br/>' $this->formSelectComponent('select_listeBase_ldap'$aLdapAllBasesarray (
  421.             'style="width:200px;"'
  422.         ));
  423.         $aContent['</div>';
  424.         //liste des serveurs mysql    
  425.         $aContent['<div class="colonneDroite">';
  426.         $aContent['&raquo;&nbsp;' $this->aParamLang['base']['libelle_1'' <b>MYSQL</b> <br/>' $this->formSelectComponent('select_listeBase_mysql'$aMysqlAllBasesarray (
  427.             'style="width:200px;"'
  428.         ));
  429.         //
  430.         $aContent[' <input type="submit" name="btn_loadListFields" value="&raquo; ' $this->aParamLang['base']['libelle_9''" class="inputSubmit"  />';
  431.         $aContent['</div>';
  432.         //
  433.         $aContent['<div class="row">';
  434.         $aContent['&nbsp;';
  435.         $aContent['</div>';
  436.         //
  437.         $aLdapFields $this->ldap_getFields();
  438.         //on supprime le champ unique_id qu'on a crée
  439.         unset ($aLdapFields['unique_id']);
  440.         unset ($aLdapFields['ldap_user_id']);
  441.         //
  442.         $aMysqlFields $this->mysql_getFields();
  443.         //
  444.         if (!empty ($aLdapFieldsAND !empty ($aMysqlFields))
  445.         {
  446.             //
  447.             $aContent['<div class="row">';
  448.             $aContent['<span class="etape">' $this->aParamLang['base']['libelle_8'' 2 :</span>';
  449.             $aContent['</div>';
  450.             //liste des champs ldap
  451.             $aContent['<div class="colonneGauche">';
  452.             $aContent[$this->aParamLang['base']['libelle_6''<br/>' $this->formSelectComponent('select_ldap_ListFields'$aLdapFields' (<b>' count($aLdapFields'</b>)&nbsp;';
  453.             $aContent['</div>';
  454.             //
  455.             //liste des champs mysql
  456.             $aContent['<div class="colonneDroite">';
  457.             $aContent[$this->aParamLang['base']['libelle_7''<br/>' $this->formSelectComponent('select_mysql_ListFields'$aMysqlFields' (<b>' count($aMysqlFields'</b>)&nbsp;';
  458.             $aContent['<input type="submit" name="btn_addToListFieldsToImport" value="&raquo;&nbsp;' $this->aParamLang['ldap_import']['libelle_10''" class="inputSubmit"  />';
  459.             $aContent['</div>';
  460.         //fin if
  461.         //
  462.         $aContent['<div class="row">';
  463.         $aContent['&nbsp;';
  464.         $aContent['</div>';
  465.         //
  466.         $array $_SESSION['Ldap2Mysql']['listFieldsToImport'];
  467.         //
  468.         if (!empty ($array))
  469.         {
  470.             $aContent['<div class="row">';
  471.             $aContent[SPACE2 '<table  summary="correspondance" id="ldap_import_correspondance"  cellpadding="0" cellspacing="0">';
  472.             //
  473.             foreach ($array as $key => $aFields)
  474.             {
  475.                 //l'utilisation de md5 permet d'avoir un id avec chiffre et lettres uniquement
  476.                 $champ_ldap $aFields['ldap_ListFields'];
  477.                 $champ_mysql $aFields['mysql_ListFields'];
  478.                 //
  479.                 $aContent[SPACE3 '<tr>';
  480.                 $aContent[SPACE4 '<td><input type="image" name="btn_supprimerCorrespondance_' $key '" src="' IMAGE_DIR 'iconeSupprimer.png" value="' $key '" title="' $this->aParamLang['ldap_import']['libelle_11''" alt="' $this->aParamLang['ldap_import']['libelle_11''" />';
  481.                 $aContent[SPACE4 '</td>';
  482.                 $aContent[SPACE4 '<td>' $champ_ldap;
  483.                 $aContent[SPACE4 '</td>';
  484.                 $aContent[SPACE4 '<td><img src="' IMAGE_DIR 'fleche.png" title="" alt="" />&nbsp;&nbsp;&nbsp;';
  485.                 $aContent[SPACE4 '<td>' $champ_mysql;
  486.                 $aContent[SPACE4 '</td>';
  487.                 $aContent[SPACE3 '</tr>';
  488.             }
  489.             //
  490.             $aContent[SPACE2 '</table>';
  491.             $aContent['</div>';
  492.             //
  493.         }
  494.         //
  495.         if (!empty ($_SESSION['Ldap2Mysql']['errorConnexionMysql']))
  496.         {
  497.             $aContent['<div class="row">';
  498.             $aContent['<span  class="errorMessage">&raquo;&nbsp;' $_SESSION['Ldap2Mysql']['errorConnexionMysql''</span>';
  499.             $aContent['</div>';
  500.         }
  501.         //
  502.         if (!empty ($_SESSION['Ldap2Mysql']['errorUniqueId']))
  503.         {
  504.             $aContent['<div class="row">';
  505.             $aContent['<span  class="errorMessage">&raquo;&nbsp;' $_SESSION['Ldap2Mysql']['errorUniqueId''</span>';
  506.             $aContent['</div>';
  507.             //
  508.             unset ($_SESSION['Ldap2Mysql']['errorUniqueId']);
  509.         }
  510.         //
  511.         if (!empty ($_SESSION['Ldap2Mysql']['errorConnexionLdap']))
  512.         {
  513.             $aContent['<div class="row">';
  514.             $aContent['<span  class="errorMessage">&raquo;&nbsp;' $_SESSION['Ldap2Mysql']['errorConnexionLdap''</span>';
  515.             $aContent['</div>';
  516.             //
  517.             unset ($_SESSION['Ldap2Mysql']['errorConnexionLdap']);
  518.         }
  519.         //
  520.         if (!empty ($_SESSION['Ldap2Mysql']['listFieldsToImport']))
  521.         {
  522.             $aContent['<div class="row">';
  523.             $aContent['&nbsp;';
  524.             $aContent['</div>';
  525.             $aContent['<div class="row">';
  526.             $aContent['<span  class="etape">' $this->aParamLang['base']['libelle_8'' 3 :</span>';
  527.             $aContent['</div>';
  528.             //
  529.             $aContent['<br/>';
  530.             //
  531.             $aContent['<div class="row">';
  532.             $aContent['<input type="submit" name="btn_enregisterImportConfig" value="&raquo;&nbsp;' $this->aParamLang['ldap_import']['libelle_12''" class="inputSubmit"  />';
  533.             $aContent['</div>';
  534.             //  
  535.         }
  536.         if (!empty ($_SESSION['Ldap2Mysql']['writeFileMessageSucceed']))
  537.         {
  538.             $sMessage $_SESSION['Ldap2Mysql']['writeFileMessageSucceed'];
  539.             unset ($_SESSION['Ldap2Mysql']['writeFileMessageSucceed']);
  540.         }
  541.         if (!empty ($_SESSION['Ldap2Mysql']['writeFileMessageNotSucceed']))
  542.         {
  543.             $sMessage $_SESSION['Ldap2Mysql']['writeFileMessageNotSucceed'];
  544.             unset ($_SESSION['Ldap2Mysql']['writeFileMessageNotSucceed']);
  545.         }
  546.         //
  547.         if (isset ($sMessage))
  548.         {
  549.             $aContent['<div class="row">';
  550.             $aContent['<span  class="errorMessage">&raquo;&nbsp;' $sMessage '</span>';
  551.             $aContent['</div>';
  552.         //fin if
  553.         //
  554.         //
  555.         return implode("\n"$aContent);
  556.         //
  557.     }
  558.     //
  559.         /** 
  560.     *
  561.     * @description  retourne un tableau de la liste de tous les  champs ldap
  562.     *
  563.     * @return  array  $_SESSION['Ldap2Mysql']['aListeCles']
  564.     *
  565.     */
  566.     function ldap_getFields()
  567.     {
  568.         //
  569.         if (!empty ($_POST['select_listeBase_ldap']))
  570.         {
  571.             //unset ($_SESSION['Ldap2Mysql']['listFieldsToImport']);
  572.             $oBase_id $_POST['select_listeBase_ldap'];
  573.             //---------------------------------------------------------------------------------------------//
  574.             //on charge sa config
  575.             $object $this->baseLoadParam($oBase_id);
  576.             $oLdap new stdClass();
  577.             foreach ($object as $key => $obj)
  578.             {
  579.                 $oLdap-> $key $obj->value;
  580.             }
  581.             //
  582.             $arrayParam['justeFields'true;
  583.             $oLdap->filter '(objectclass=*)';
  584.             $array $this->ldap_import_getData($oLdap$arrayParam);
  585.             //
  586.             //
  587.             if (isset ($array['Ldap2Mysql']['errorUniqueId']))
  588.             {
  589.                 return $array['Ldap2Mysql']['errorUniqueId'];
  590.             //fin if
  591.             //
  592.             if (isset ($array['ldap']['ldap_ListFields']))
  593.             {
  594.                 $_SESSION['Ldap2Mysql']['ldap_ListFields'$array['ldap']['ldap_ListFields'];
  595.                 //
  596.                 return $array['ldap']['ldap_ListFields'];
  597.             }
  598.             //
  599.         }
  600.         else
  601.         {
  602.             return null;
  603.         }
  604.         //fin if
  605.     }
  606.     /** 
  607.     *
  608.     * @description  retourne un tableau de la liste de tous les  champs mysql
  609.     *
  610.     * @return array  $_SESSION['Ldap2Mysql']['aListeCles']
  611.     *
  612.     */
  613.     //
  614.         function ldap_import_appliquerModifSelectUsers()
  615.     {
  616.         //on récupère les users des id sélectionnées
  617.         $aCheckbox_user $_POST['checkbox_user'];
  618.         if (!empty ($aCheckbox_user))
  619.         {
  620.             foreach ($aCheckbox_user as $unique_id)
  621.             {
  622.                 foreach ($_POST as $key => $value)
  623.                 {
  624.                     $tab explode('-'$key);
  625.                     $champLdap $tab[1];
  626.                     $aSelectedUsers[$unique_id$_SESSION['Ldap2Mysql']['aoUser'][$unique_id];
  627.                     //
  628.                     if ($tab[0== $unique_id)
  629.                     {
  630.                         $champLdap $tab[1];
  631.                         //on modifie le contenu
  632.                         $_SESSION['Ldap2Mysql']['aoUser'][$unique_id][$champLdaptrim($value);
  633.                         $aSelectedUsers[$unique_id$_SESSION['Ldap2Mysql']['aoUser'][$unique_id];
  634.                     }
  635.                 //fin foreach
  636.             //fin foreach
  637.         //fin if
  638.         //
  639.         if (isset ($aSelectedUsers))
  640.         {
  641.             return $aSelectedUsers;
  642.         }
  643.         //
  644.     //fin function ldap_import_appliquerModifSelectUsers()
  645.     //
  646.         /**
  647.      * @description  fonction de chargement de la liste des config d'importations
  648.      */
  649.     function ldap_import_loadListConfig()
  650.     {
  651.         //
  652.         $file CONFIG_DIR 'importConfig';
  653.         //
  654.         if (file_exists($file))
  655.         {
  656.             $aObjet array ();
  657.             //
  658.             if (file_exists($file))
  659.             {
  660.                 //on charge  le tableau d'objets texte avec désérialisation
  661.                 $aObjet unserialize(file_get_contents($file));
  662.             }
  663.             //
  664.             foreach ($aObjet as $key => $objet)
  665.             {
  666.                 //on charge le nom des base ldap
  667.                 $oLdap $this->baseLoadParam($objet->ldap_id);
  668.                 //
  669.                 if (isset ($oLdap->nom->value))
  670.                 {
  671.                     $nom_ldap $oLdap->nom->value;
  672.                 //fin if
  673.                 //
  674.                 //on charge le nom des base mysql
  675.                 $oMysql $this->baseLoadParam($objet->mysql_id);
  676.                 if (isset ($oMysql->nom->value))
  677.                 {
  678.                     $nom_mysql $oMysql->nom->value;
  679.                 }
  680.                 //
  681.                 //
  682.                 if (isset ($nom_ldapAND isset ($nom_mysql))
  683.                 {
  684.                     $aOption[$objet->id$nom_ldap ' -> ' $nom_mysql;
  685.                 //fin if
  686.                 //
  687.                 //
  688.             }
  689.             return $aOption;
  690.         //fin if
  691.     }
  692.     //
  693.         /**
  694.      * @description charge une config en fonction de son id
  695.      */
  696.     function ldap_import_loadConfig($configImport_id)
  697.     {
  698.         $file CONFIG_DIR 'importConfig';
  699.         //
  700.         $aObjet array ();
  701.         if (file_exists($file))
  702.         {
  703.             //on charge  le fichier texte, chaque ligne est un objet
  704.             $aObjet unserialize(file_get_contents($file));
  705.         }
  706.         $oParamImport $aObjet[$configImport_id];
  707.         //on récupèrela liste des champs ldap
  708.         if (isset ($oParamImport))
  709.         {
  710.             //chargement des champs des 2 bases 
  711.             //
  712.             if (isset ($_SESSION['Ldap2Mysql']['ldap_listFieldsToImport']))
  713.             {
  714.                 unset ($_SESSION['Ldap2Mysql']['ldap_listFieldsToImport']);
  715.             //fin if
  716.             //
  717.             if (isset ($_SESSION['Ldap2Mysql']['mysql_listFieldsToImport']))
  718.             {
  719.                 unset ($_SESSION['Ldap2Mysql']['mysql_listFieldsToImport']);
  720.             //fin if
  721.             //
  722.             foreach ($oParamImport->listFieldsToImport as $key => $value)
  723.             {
  724.                 $_SESSION['Ldap2Mysql']['ldap_listFieldsToImport'][$value['ldap_ListFields'];
  725.                 $_SESSION['Ldap2Mysql']['mysql_listFieldsToImport'][$value['mysql_ListFields'];
  726.             }
  727.             //pour la requete sql
  728.             $_SESSION['Ldap2Mysql']['confListFieldsToImport'$oParamImport->listFieldsToImport;
  729.             //liste détaillee des champs de la table
  730.             $_SESSION['Ldap2Mysql']['mysql_detailedListFields'$oParamImport->mysql_detailedListFields;
  731.             //on garde en session les propriétés des 2 base
  732.             $arr $this->baseLoadParam($oParamImport->ldap_id);
  733.             //param ldap
  734.             //on construit un objet plus simple avec juste le champ valeur de chaque propriété
  735.             foreach ($arr as $key => $propertie)
  736.             {
  737.                 $aLdap[$key$propertie->value;
  738.             }
  739.             $oLdap = (object) $aLdap;
  740.             //param mysql
  741.             //on construit un objet plus simple avec juste le champ valeur de chaque propriété
  742.             $arr $this->baseLoadParam($oParamImport->mysql_id);
  743.             foreach ($arr as $key => $propertie)
  744.             {
  745.                 $aMysql[$key$propertie->value;
  746.             }
  747.             $oMysql = (object) $aMysql;
  748.             $array['oLdap'$oLdap;
  749.             $array['oMysql'$oMysql;
  750.             //
  751.             return $array;
  752.         //fin if
  753.         //
  754.     }
  755.     //
  756.         /**
  757.      * @description execute l'importation
  758.      */
  759.     function ldap_import_finalize()
  760.     {
  761.         //
  762.         $aSelectedUsers $this->ldap_import_appliquerModifSelectUsers();
  763.         //
  764.         if (!isset ($aSelectedUsers))
  765.         {
  766.             return;
  767.         }
  768.         //une connexion est déjà initialisée en activant l'importation
  769.         //---------------------------------------------------------------------------------------------//
  770.         //on récupère la liste des personnes déjà importés
  771.         //id de la config $_SESSION['Ldap2Mysql']['ldap_config_import_id']
  772.         $sldap_config_import_id $_SESSION['Ldap2Mysql']['ldap_config_import_id'];
  773.         $aInsertedUsers $this->mysql_getInsertedUsers($sldap_config_import_id);
  774.         //on leur affecte une nouvelle propriété dans la session
  775.         //---------------------------------------------------------------------------------------------//
  776.         //on vérifie si les champs d'import exitent dans la base mysql        
  777.         $aFieldsToAdd $this->mysql_isFieldsExists();
  778.         if (isset ($aFieldsToAddAND is_array($aFieldsToAdd))
  779.         {
  780.             //on les crée
  781.             $this->mysql_createFields($aFieldsToAdd);
  782.         }
  783.         //---------------------------------------------------------------------------------------------//
  784.         foreach ($aSelectedUsers as $user)
  785.         {
  786.             //UPDATE
  787.             $sWhere '';
  788.             if (in_array($user['ldap_user_id']array_keys($aInsertedUsers)))
  789.             {
  790.                 //on indique quelle type de requête, servira pour l'affichage à la afin de l 'import
  791.                 $sUpdateOrInsert 'update';
  792.                 //on initialise le début de la requête
  793.                 $sQuery 'UPDATE ' $this->sMysqlTableToUpdate . ' SET ';
  794.                 //on initialise la fin de la requête
  795.                 $sWhere ' WHERE ldap_user_id' "='" $user['ldap_user_id'"'";
  796.             }
  797.             else
  798.             {
  799.                 //on indique quelle type de requête, servira pour l'affichage à la afin de l 'import
  800.                 $sUpdateOrInsert 'insert';
  801.                 //on prépare la requête
  802.                 $sQuery 'INSERT INTO ' $this->sMysqlTableToUpdate . ' SET ';
  803.                 //on affecte notre tableau initialisé à un autre qui se verra écraser certains champs
  804.                 $arr $this->mysql_initializeFieldsToImport();
  805.                 //CREATION    
  806.                 //@promethee                
  807.                 if (isset ($this->dateCreation))
  808.                 {
  809.                     $arr['_create'$this->dateCreation . "='" date('Y-m-d H:i:s'"'";
  810.                 //fin if
  811.                 //
  812.                 //fin @promethee
  813.                 $arr['ldap_user_id'"ldap_user_id='" trim($user['ldap_user_id']"'";
  814.             }
  815.             //CREATION AND UPDATE
  816.             $arr['ldap_config_import_id'"ldap_config_import_id='" $_SESSION['Ldap2Mysql']['ldap_config_import_id'"'";
  817.             $arr['ldap_last_update'"ldap_last_update='" date('Y-m-d H:i:s'"'";
  818.             //on parcourt la liste de tous les champs de la tableau
  819.             //un exemple  de value est    value=array( 'ldap_ListFields'=> 'mail','mysql_ListFields' => '_email')
  820.             foreach ($_SESSION['Ldap2Mysql']['confListFieldsToImport'as $key => $value)
  821.             {
  822.                 if (isset ($value['ldap_ListFields']AND isset ($user[$value['ldap_ListFields']]))
  823.                 {
  824.                     $arr[$value['mysql_ListFields']] $value['mysql_ListFields'"='" addslashes(trim($user[$value['ldap_ListFields']])) "'";
  825.                 }
  826.             }
  827.             //UPDATE
  828.             //on affecte à tous les utilisateurs le droit choisi 
  829.             if (!empty ($_POST['select_usersGroups']))
  830.             {
  831.                 $arr[$this->aMysqlTableUserGroups['field_id']] $this->aMysqlTableUserGroups['field_id''=' trim($_POST['select_usersGroups']);
  832.             }
  833.             //
  834.             $sQuery .= implode(','$arr);
  835.             //on crée un tableau assoc avec comme clé l'unique_id du ldap
  836.             $aQuery[$user['unique_id']] $sQuery $sWhere;
  837.             $aUpdateOrInsert[$user['unique_id']] $sUpdateOrInsert;
  838.             //destruction des variables
  839.             unset ($arr);
  840.             unset ($sQuery);
  841.             unset ($sUpdateOrInsert);
  842.         }
  843.         //insertion
  844.         if (isset ($aQuery))
  845.         {
  846.             $this->mysql_addUsersFromLdap($aQuery$aUpdateOrInsert);
  847.         }
  848.     //fin ldap_import_finalize()
  849.     //
  850.         /**
  851.      * @description execute le chargement des utilisateurs du ldap (si click su bouton 'charger liste')
  852.      *   et charge un tableau de session qui est réutilisé
  853.      *  sinon renvoi le tableau de session chargé la première fois
  854.      * @return un tableau d'objets des utilisateurs
  855.      */
  856.     function ldap_import_getUsers()
  857.     {
  858.         //
  859.         if (!empty ($_POST['btn_loadUsers']))
  860.         {
  861.             //pour l'affichage du résultat
  862.             $this->result true;
  863.             //si des utilsateurs ont été déjà sélectionnés dans une autre config, on les supprime 
  864.             if (isset ($_SESSION['Ldap2Mysql']['selectedUsers']))
  865.             {
  866.                 unset ($_SESSION['Ldap2Mysql']['selectedUsers']);
  867.             }
  868.             //on remet à zéro la pagination
  869.             if (!empty ($_POST['select_configImport']))
  870.             {
  871.                 unset ($_SESSION['Ldap2Mysql']['numeroPage']);
  872.             }
  873.             //
  874.             if (!empty ($_POST['select_configImport']))
  875.             {
  876.                 //on charge la config qui va alimenter des variables de sessions
  877.                 $arr $this->ldap_import_loadConfig($_POST['select_configImport']);
  878.                 $oLdap $arr['oLdap'];
  879.                 //on charge les propriétés du ldap de la config
  880.                 $_SESSION['Ldap2Mysql']['ldap_config_import_id'$_POST['select_configImport'];
  881.             }
  882.             //
  883.             if (isset ($oLdap))
  884.             {
  885.                 //on construit un filtre par défaut
  886.                 $filter '(|'// |=or &=et
  887.                 foreach ($_SESSION['Ldap2Mysql']['ldap_listFieldsToImport'as $key => $value)
  888.                 {
  889.                     $filter .= '(' $value '=*)';
  890.                 }
  891.                 $filter .= ')';
  892.                 $oLdap->filter $filter;
  893.                 //
  894.                 if (!empty ($_POST['txt_filter']))
  895.                 {
  896.                     $oLdap->filter str_replace(' '''$_POST['txt_filter']);
  897.                 }
  898.                 //pour recharger le filtre
  899.                 $this->ldap_import_setFilter($oLdap->filter);
  900.                 //
  901.                 $arrayParam['ldap_listFieldsToImport'$_SESSION['Ldap2Mysql']['ldap_listFieldsToImport'];
  902.                 $array $this->ldap_import_getData($oLdap$arrayParam);
  903.                 //
  904.                 if (isset ($array['ldap']['aoUser']))
  905.                 {
  906.                     $_SESSION['Ldap2Mysql']['aoUser'$array['ldap']['aoUser'];
  907.                     return $array['ldap']['aoUser'];
  908.                 }
  909.             //fin if        
  910.         }
  911.         else
  912.         {
  913.             //
  914.             if (isset ($_SESSION['Ldap2Mysql']['aoUser']))
  915.             {
  916.                 //pour l'affichage du résultat
  917.                 $this->result true;
  918.                 return $_SESSION['Ldap2Mysql']['aoUser'];
  919.             }
  920.             //
  921.         //fin if
  922.         return null;
  923.     //fin function ldap_import_getUsers()
  924.     //
  925.         function ldap_import_getData($oLdap$arrayParam null)
  926.     {
  927.         //
  928.         if (empty ($oLdap->port))
  929.         {
  930.             $oLdap->port 389//port ldap par défaut
  931.         }
  932.         //
  933.         $ressource_link ldap_connect($oLdap->host$oLdap->port);
  934.         //on attache la base
  935.         //$bBind =  ldap_bind($ressource_link, $oLdap->login, $oLdap->pass);
  936.         $bBind ldap_bind($ressource_link$oLdap->login$oLdap->pass);
  937.         //on tente en anonymous
  938.         if ($bBind == false)
  939.         {
  940.             $bBind ldap_bind($ressource_link'''');
  941.         //fin if
  942.         //
  943.         //
  944.         if ($bBind == false)
  945.         {
  946.             $_SESSION['Ldap2Mysql']['errorConnexionLdap'$this->aParamLang['config_import']['errorConnexionLdap'];
  947.             return array ();
  948.         }
  949.         $result ldap_search($ressource_link$oLdap->dn$oLdap->filter);
  950.         //
  951.         //
  952.         if (!$result)
  953.         {
  954.             return array ();
  955.         //fin if
  956.         //
  957.         $aEntries ldap_get_entries($ressource_link$result);
  958.         //on libère la mémoire serveur
  959.         ldap_free_result($result);
  960.         //
  961.         $bLdap_user_id false;
  962.         //
  963.         foreach ($aEntries as $key => $entrie)
  964.         {
  965.             //
  966.             if (is_array($entrie))
  967.             {
  968.                 //
  969.                 $sStringToHash '';
  970.                 //
  971.                 foreach ($entrie as $_key => $attribut)
  972.                 {
  973.                     //
  974.                     if (is_array($attribut))
  975.                     {
  976.                         //si $attribut n'est pas un tableau donc a une  valeur=1
  977.                         if ($attribut['count'== (int) 1)
  978.                         {
  979.                             unset ($attribut['count'])//on n'a pas besoin de ce tableau
  980.                             $value strtolower(trim($attribut[0]))//on prend la première valeur
  981.                         }
  982.                         else
  983.                         {
  984.                             unset ($attribut['count']);
  985.                             $value $attribut;
  986.                         //fin if
  987.                         //
  988.                         if ($_key == $oLdap->ldap_user_id_field)
  989.                         {
  990.                             if (is_array($value))
  991.                             {
  992.                                 $value $value[0];
  993.                             }
  994.                             $user['ldap_user_id'$value;
  995.                             $bLdap_user_id true;
  996.                             //utile pour la manipulation des données en session
  997.                             //on rajoute une chaine dans l'id car les id de balise n'autorise pas un début de chaine en numérique
  998.                             $user['unique_id''md5' md5($value);
  999.                         }
  1000.                         //
  1001.                         //
  1002.                         $user[$_key$value;
  1003.                         //on crée un tableau de toutes les clés car certains users n'ont pas certains attributs                        
  1004.                         //on met comme clé le champ lui même cela permet d'avoir un tableau dont la liste est unique
  1005.                         $aListeCles[$_key$_key;
  1006.                         //on ajoute ce champ comme clé
  1007.                         $aListeCles['ldap_user_id''ldap_user_id';
  1008.                         $aListeCles['unique_id''unique_id';
  1009.                     //fin if
  1010.                 //fin foreach
  1011.                 //on constitue un tableau d'objet
  1012.                 $aUserTemp[$user;
  1013.                 unset ($user);
  1014.             //fin if
  1015.         //fin foreach
  1016.         //
  1017.         //
  1018.         if ($bLdap_user_id == false)
  1019.         {
  1020.             $_SESSION['Ldap2Mysql']['errorUniqueId'$this->aParamLang['config_import']['errorUniqueId'];
  1021.             return array ();
  1022.         }
  1023.         else
  1024.         {
  1025.             unset ($_SESSION['Ldap2Mysql']['errorUniqueId']);
  1026.         }
  1027.         //
  1028.         if (!isset ($aListeCles))
  1029.         {
  1030.             return;
  1031.         }
  1032.         //idem pour la liste des champs
  1033.         ksort($aListeCles);
  1034.         //
  1035.         $array['ldap']['ldap_ListFields'$aListeCles;
  1036.         //si simple récupération des champs
  1037.         if (isset ($arrayParam['justeFields']AND $arrayParam['justeFields'== true)
  1038.         {
  1039.             return $array;
  1040.         }
  1041.         //si affichage des utilisateurs
  1042.         foreach ($aUserTemp as $index => $user)
  1043.         {
  1044.             //
  1045.             foreach ($aListeCles as $cle)
  1046.             {
  1047.                 //
  1048.                 if (!isset ($user[$cle]))
  1049.                 {
  1050.                     //donc pour éviter des erreurs php on leurs affecte une chaine vide
  1051.                     $arr[$clenull;
  1052.                 }
  1053.                 else
  1054.                 {
  1055.                     $arr[$cle$user[$cle];
  1056.                 }
  1057.                 //
  1058.             }
  1059.             //
  1060.             if (!empty ($arr))
  1061.             {
  1062.                 //on ajoute au tableau le tableau de l'utilisateur
  1063.                 $aUser[$user['unique_id']] $arr;
  1064.                 unset ($arr);
  1065.             }
  1066.             //
  1067.         //fin foreach
  1068.         //on stocke cette liste dans une session pour éviter de réinterroger le ldap
  1069.         //
  1070.         $array['ldap']['aoUser'$aUser;
  1071.         //
  1072.         return $array;
  1073.         //
  1074.     }
  1075.     //
  1076.         /**
  1077.      * @description enregistre le filtre saisie pour le recharger
  1078.      */
  1079.     function ldap_import_setFilter($sFilter '')
  1080.     {
  1081.         //on éfface la dernière saisie
  1082.         unset ($_SESSION['Ldap2Mysql']['sFilter']);
  1083.         $_SESSION['Ldap2Mysql']['sFilter'$sFilter;
  1084.         $this->sFilter = $sFilter;
  1085.     }
  1086.     //
  1087.         /**
  1088.      * @description permet de recharger le filtre saisi
  1089.      * @return string $_SESSION['Ldap2Mysql']['sFilter']
  1090.      */
  1091.     function ldap_import_getFilter()
  1092.     {
  1093.         //
  1094.         if (isset ($_SESSION['Ldap2Mysql']['sFilter']))
  1095.         {
  1096.             return $_SESSION['Ldap2Mysql']['sFilter'];
  1097.         }
  1098.     }
  1099.     //
  1100.         function ldap_import_controller()
  1101.     {
  1102.         //on crée une connexion avec selection de la base
  1103.         if (!empty ($_POST['select_configImport']))
  1104.         {
  1105.             $this->mysql_getConnexion();
  1106.         }
  1107.         //
  1108.         if (!empty ($_POST['btn_finaliserModifSelectUsers']))
  1109.         {
  1110.             $this->ldap_import_finalize();
  1111.         }
  1112.         //
  1113.         return $this->ldap_import_view();
  1114.     }
  1115.     /**
  1116.      * @description affiche la vue de l'interface d'importation
  1117.      */
  1118.     function ldap_import_view()
  1119.     {
  1120.         $aoUser $this->ldap_import_getUsers();
  1121.         //
  1122.         //liste des serveurs ldap
  1123.         $aContent[SPACE1 '<div class="row">';
  1124.         $aContent['<div class ="divLeft">' $this->aParamLang['ldap_import']['libelle_13''&nbsp;:&nbsp;</div>';
  1125.         $aContent['<div class ="divRight">';
  1126.         $aConfigImport $this->ldap_import_loadListConfig();
  1127.         $aContent[$this->formSelectComponent('select_configImport'$aConfigImport$aOption array (
  1128.             'onchange="clearField();"'
  1129.         ));
  1130.         $aContent['</div>';
  1131.         $aContent[SPACE1 '</div>';
  1132.         //case à cocher de visualisation des users déjà importées
  1133.         $aContent[SPACE1 '<div class="row">';
  1134.         $aContent['<div class ="divLeft">&nbsp;</div>';
  1135.         $aContent['<div class ="divRight">';
  1136.         $aContent['<input type="checkbox" checked="checked"  id="checkbox_includeImportedUsers" name="checkbox_includeImportedUsers"   />' $this->aParamLang['ldap_import']['libelle_22'];
  1137.         $aContent['</div>';
  1138.         $aContent[SPACE1 '</div>';
  1139.         //
  1140.         $aContent[SPACE1 '<br/>';
  1141.         //filtre
  1142.         $aContent[SPACE1 '<div class="row">';
  1143.         $aContent['<div class ="divLeft">';
  1144.         $aContent[$this->aParamLang['ldap_import']['libelle_2''&nbsp;:&nbsp;';
  1145.         $aContent['</div>';
  1146.         $aContent['<div class ="divRight">';
  1147.         $aContent['<input type="text"  id="txt_filter" name="txt_filter" value="' $this->ldap_import_getFilter('" class="inputText"  size="50"  />';
  1148.         $aContent['</div>';
  1149.         $aContent[SPACE1 '</div>';
  1150.         //
  1151.         $libelle $this->aParamLang['ldap_import']['libelle_5'];
  1152.         $nombreUser 0;
  1153.         $nombreUser count($aoUser);
  1154.         //
  1155.         switch ($nombreUser)
  1156.         {
  1157.             //
  1158.             case (int) :
  1159.                 $libelle $this->aParamLang['ldap_import']['libelle_3'];
  1160.                 break;
  1161.                 //
  1162.             case (int) :
  1163.                 $libelle $this->aParamLang['ldap_import']['libelle_5'];
  1164.                 break;
  1165.                 //
  1166.             case $nombreUser > (int) :
  1167.                 $libelle $this->aParamLang['ldap_import']['libelle_4'];
  1168.                 break;
  1169.                 //
  1170.         }
  1171.         //
  1172.         if (isset ($_SESSION['Ldap2Mysql']['ldap_config_import_id']))
  1173.         {
  1174.             $aInsertedUsers $this->mysql_getInsertedUsers($_SESSION['Ldap2Mysql']['ldap_config_import_id']);
  1175.             if (!isset ($_POST['checkbox_includeImportedUsers']))
  1176.             {
  1177.                 $nombreUser $nombreUser -count($aInsertedUsers);
  1178.             }
  1179.         }
  1180.         //
  1181.         if (isset ($this->result))
  1182.         {
  1183.             //résultat nombre personnes trouvées
  1184.             $aContent[SPACE1 '<div class="row">';
  1185.             $aContent['<div class ="divLeft">&nbsp;';
  1186.             $aContent['</div>';
  1187.             $aContent['<div class ="divRight">';
  1188.             //
  1189.             $aContent['&nbsp;&raquo;&nbsp;<span class="redBold">' $nombreUser '</span>&nbsp;' $libelle;
  1190.             //
  1191.             $aContent['</div>';
  1192.             $aContent[SPACE1 '</div>';
  1193.         }
  1194.         //
  1195.         $aContent[SPACE1 '<div class="row">';
  1196.         $aContent['<div class ="divLeft">&nbsp;';
  1197.         $aContent['</div>';
  1198.         $aContent['<div class ="divRight">';
  1199.         $aContent[SPACE2 $this->formInputComponent('submit''btn_loadUsers''&raquo;&nbsp;' $this->aParamLang['ldap_import']['libelle_26']array (
  1200.             'class' => 'inputSubmit'
  1201.         ));
  1202.         $aContent['</div>';
  1203.         $aContent[SPACE1 '</div>';
  1204.         $aContent[SPACE1 '<br/><br/>';
  1205.         //
  1206.         if (!empty ($aoUser))
  1207.         {
  1208.             //select des droits utlisateurs
  1209.             //
  1210.             $aContent[SPACE1 '<div class="row">';
  1211.             $aContent['<div class ="divLeft">' $this->aParamLang['ldap_import']['libelle_21''&nbsp;:&nbsp;';
  1212.             $aContent['</div>';
  1213.             $aContent['<div class ="divRight">';
  1214.             $aUsersGroups $this->mysql_getFieldsUserGroups();
  1215.             $aContent[$this->formSelectComponent('select_usersGroups'$aUsersGroups);
  1216.             $aContent['</div>';
  1217.             $aContent[SPACE1 '</div>';
  1218.             //
  1219.             $aContent[SPACE1 '<br/><br/>';
  1220.             $aContent[SPACE1 '<div class="row">';
  1221.             $aContent['<div class ="divLeft">&nbsp;';
  1222.             $aContent['</div>';
  1223.             $aContent['<div class ="divRight">';
  1224.             $aContent[SPACE2 $this->formInputComponent('submit''btn_finaliserModifSelectUsers''&raquo;&nbsp;' $this->aParamLang['ldap_import']['libelle_16']array (
  1225.                 'class' => 'inputSubmit'
  1226.             ));
  1227.             $aContent['</div>';
  1228.             $aContent[SPACE1 '</div>';
  1229.             //
  1230.             $aContent[SPACE1 '<br/><br/>';
  1231.             //legende des picto
  1232.             $aContent[SPACE1 '<div id="legende">';
  1233.             $listePicto '<img src="' IMAGE_DIR 'croix.png" title="" alt="" />&nbsp;' $this->aParamLang['ldap_import']['libelle_19''&nbsp;';
  1234.             $listePicto .= '<img src="' IMAGE_DIR 'coche.png" title="" alt="" />&nbsp;' $this->aParamLang['ldap_import']['libelle_18''&nbsp;';
  1235.             $listePicto .= '<img src="' IMAGE_DIR 'exclamation_orange.png" title="" alt="" />&nbsp;' $this->aParamLang['ldap_import']['libelle_20''&nbsp;';
  1236.             $listePicto .= '<img src="' IMAGE_DIR 'refresh.png" title="" alt="" />&nbsp;' $this->aParamLang['ldap_import']['libelle_27''&nbsp;';
  1237.             $aContent[$listePicto;
  1238.             $aContent[SPACE1 '</div>';
  1239.             //gestion de la pagination
  1240.             $aContent[SPACE1 '<div class="row">';
  1241.             //on récupère un objet pager : avec les prop iLimiteInferieure et   iNombreLignesAffichees
  1242.             $iTotalUser count($aoUser);
  1243.             $oPager $this->pager($iTotalUser);
  1244.             //on découpe le tableau et on préserve les clés associatives
  1245.         
  1246.             $aoUser_sliced_arrays array_chunk($aoUser$oPager->iNombreLignesAfficheestrue);
  1247.             //$_SESSION['aoUser_sliced_arrays']=$aoUser_sliced_arrays;
  1248.             //
  1249.             if ($oPager->iNumeroPage == (int) 0)
  1250.             {
  1251.                 $aContent[SPACE2 $this->formInputComponent('submit''btn_preview''&laquo;&nbsp;' $this->aParamLang['ldap_import']['libelle_30']array (
  1252.                     'class' => 'inputSubmit',
  1253.                     'disabled' => 'disabled'
  1254.                 ));
  1255.             }
  1256.             else
  1257.             {
  1258.                 $aContent[SPACE2 $this->formInputComponent('submit''btn_preview''&laquo;&nbsp;' $this->aParamLang['ldap_import']['libelle_30']array (
  1259.                     'class' => 'inputSubmit'
  1260.                 ));
  1261.             }
  1262.             if (isset ($oPager->bStopAND $oPager->bStop == true)
  1263.             {
  1264.                 $aContent[SPACE2 $this->formInputComponent('submit''btn_next'$this->aParamLang['ldap_import']['libelle_29''&nbsp;&raquo;'array (
  1265.                     'class' => 'inputSubmit',
  1266.                     'disabled' => 'disabled'
  1267.                 ));
  1268.             }
  1269.             else
  1270.             {
  1271.                 $aContent[SPACE2 $this->formInputComponent('submit''btn_next'$this->aParamLang['ldap_import']['libelle_29''&nbsp;&raquo;'array (
  1272.                     'class' => 'inputSubmit'
  1273.                 ));
  1274.             }
  1275.             //
  1276.             $aData array (
  1277.                 '10' => '10',
  1278.                 '20' => '20',
  1279.                 '50' => '50'
  1280.             );
  1281.             $aContent[$this->formSelectComponent('select_nombre_Affichage'$aData$aOption array (
  1282.                 'onchange="javascript:submit();"'
  1283.             )'freeze');
  1284.             $aContent[$this->formInputComponent('submit''btn_validerSelect''OK'array (
  1285.                 'class' => 'inputSubmit'
  1286.             ));
  1287.             $aContent[SPACE1 '</div>';
  1288.             //
  1289.             $aContent[SPACE1 '<div class="row">&nbsp;';
  1290.             $aContent[SPACE1 '</div>';
  1291.             //
  1292.             $aContent['<!-- table des utilisateurs-->';
  1293.             $aContent[SPACE1 '<div class="row">';
  1294.             //
  1295.             $aContent[SPACE2 '<table  summary="users" class="ldap_import"  cellpadding="0" cellspacing="0">';
  1296.             $aContent[SPACE3 '<tr>';
  1297.             $aContent[SPACE4 '<th>#';
  1298.             $aContent[SPACE4 '</th>';
  1299.             //
  1300.             $aContent[SPACE4 '<th>';
  1301.             $aContent[SPACE4 '<input type="checkbox"  id="checkbox_selectAll" name="checkbox_selectAll"  onclick="selectAll();"  />';
  1302.             $aContent[SPACE4 '</th>';
  1303.             $aContent[SPACE4 '<th>';
  1304.             $aContent[SPACE4 '</th>';
  1305.             //
  1306.             $sSortBy '';
  1307.             //
  1308.             if (!empty ($_POST))
  1309.             {
  1310.                 //
  1311.                 foreach ($_POST as $key => $value)
  1312.                 {
  1313.                     $tab explode('#'$key);
  1314.                     //
  1315.                     if (isset ($tab[0]AND $tab[0== 'sortBy')
  1316.                     {
  1317.                         $sAttribut $tab[1];
  1318.                         //
  1319.                         if (isset ($_SESSION['Ldap2Mysql']['sSortBy']))
  1320.                         {
  1321.                             //
  1322.                             if ($_SESSION['Ldap2Mysql']['sSortBy'== 'ASC')
  1323.                             {
  1324.                                 $_SESSION['Ldap2Mysql']['sSortBy''DESC';
  1325.                                 $sSortBy 'DESC';
  1326.                             }
  1327.                             else
  1328.                             {
  1329.                                 $_SESSION['Ldap2Mysql']['sSortBy''ASC';
  1330.                                 $sSortBy 'ASC';
  1331.                             }
  1332.                             //
  1333.                         }
  1334.                         else
  1335.                         {
  1336.                             $sSortBy 'ASC';
  1337.                             $_SESSION['Ldap2Mysql']['sSortBy''ASC';
  1338.                         }
  1339.                         //
  1340.                     //fin if
  1341.                 //fin foreach
  1342.                 //
  1343.             }
  1344.             else
  1345.             {
  1346.                 $sSortBy $_SESSION['Ldap2Mysql']['sSortBy'];
  1347.             //fin if
  1348.             //  
  1349.             $imageSortType '';
  1350.             switch ($sSortBy)
  1351.             {
  1352.                 case 'ASC' :
  1353.                     //
  1354.                     $sSortBy 'DESC';
  1355.                     $pictoDesc IMAGE_DIR 'desc.png';
  1356.                     //on récupère un tableau des propriétés de l'image
  1357.                     //assurera la norme future pour xhtml 2.0
  1358.                     $imageWidthHeight getimagesize($pictoDesc);
  1359.                     $imageSortType '<img src="' $pictoDesc '" ' $imageWidthHeight[3' alt="' $this->aParamLang['ldap_import']['libelle_23''" title="' $this->aParamLang['ldap_import']['libelle_23''" />';
  1360.                     break;
  1361.                     //
  1362.                 case 'DESC' :
  1363.                     //
  1364.                     $sSortBy 'ASC';
  1365.                     $pictoAsc IMAGE_DIR 'asc.png';
  1366.                     $imageWidthHeight getimagesize($pictoAsc);
  1367.                     $imageSortType '<img src="' $pictoAsc '" ' $imageWidthHeight[3' alt="' $this->aParamLang['ldap_import']['libelle_24''" title="' $this->aParamLang['ldap_import']['libelle_24''" />';
  1368.                     break;
  1369.                     //
  1370.             //fin switch
  1371.             //
  1372.             foreach ($this->ldap_getAttributListToDisplay(as $key => $value)
  1373.             {
  1374.                 $entete '<input type="submit" name="sortBy#' $value '" value="' $value '" class="submit_entete" />';
  1375.                 //on n'active que celui qui est cliqueé 
  1376.                 if (isset ($sAttributAND $sAttribut == $value)
  1377.                 {
  1378.                     $aContent[SPACE4 '<th>' $imageSortType $entete;
  1379.                 }
  1380.                 else
  1381.                 {
  1382.                     $aContent[SPACE4 '<th>' $entete;
  1383.                 }
  1384.                 $aContent[SPACE4 '</th>';
  1385.             }
  1386.             //              
  1387.             $aContent[SPACE3 '</tr>';
  1388.             //
  1389.             $aId_insertedUsers array_keys($aInsertedUsers);
  1390.             //
  1391.             if (isset ($aoUser_sliced_arrays[$oPager->iNumeroPage]))
  1392.             {
  1393.                 //
  1394.                 foreach ($aoUser_sliced_arrays[$oPager->iNumeroPageas $key => $user)
  1395.                 {
  1396.                     $oUser = (object) $user;
  1397.                     //si case à cocher checkbox_includeImportedUsers activé
  1398.                     if (!isset ($_POST['checkbox_includeImportedUsers']))
  1399.                     {
  1400.                         //on crée un tabelau avec les clés de ce tableau associatif
  1401.                         if (in_array($oUser->unique_id$aId_insertedUsers))
  1402.                         {
  1403.                             continue;
  1404.                         }
  1405.                     }
  1406.                     //
  1407.                     //colonne des numéros de lignes, 
  1408.                     static $iterator 0;
  1409.                     $iterator++;
  1410.                     //
  1411.                     $numero ($oPager->iNombreLignesAffichees $oPager->iNumeroPage$iterator;
  1412.                     //
  1413.                     $tr_user[SPACE3 '<tr id="TR_' $numero '">';
  1414.                     $tr_user[SPACE4 '<td>' $numero '</td>';
  1415.                     //colonne des checkboxes
  1416.                     $tr_user[SPACE4 '<td><input id="checkbox_' $numero '" type="checkbox" name="checkbox_user[]" value="' $oUser->unique_id '" />';
  1417.                     //on affiche ceux existants dans la base mysql
  1418.                     //on examine l'état de l'insertion déterminé par la nouvelle propriété
  1419.                     //affecté à l'objet oUser lors de la tentative d'insertion
  1420.                     if (isset ($oUser->userImported))
  1421.                     {
  1422.                         //
  1423.                         switch ($oUser->userImported)
  1424.                         {
  1425.                             //
  1426.                             case 'insert' :
  1427.                                 $tr_user[SPACE4 '<td class="White_TD"><img src="' IMAGE_DIR 'coche.png" title="' $this->aParamLang['ldap_import']['libelle_18''" alt="' $this->aParamLang['ldap_import']['libelle_18''" /></td>';
  1428.                                 break;
  1429.                                 //
  1430.                             case 'update' :
  1431.                                 $tr_user[SPACE4 '<td class="White_TD"><img src="' IMAGE_DIR 'refresh.png" title="' $this->aParamLang['ldap_import']['libelle_20''" alt="' $this->aParamLang['ldap_import']['libelle_18''" /></td>';
  1432.                                 break;
  1433.                                 //
  1434.                             case 'failed' :
  1435.                                 $tr_user[SPACE4 '<td class="White_TD"><img src="' IMAGE_DIR 'croix.png" title="' $this->aParamLang['ldap_import']['libelle_19''" alt="' $this->aParamLang['ldap_import']['libelle_19''" /></td>';
  1436.                                 break;
  1437.                                 //
  1438.                         //fin switch
  1439.                     }
  1440.                     else
  1441.                     {
  1442.                         //
  1443.                         if (in_array($oUser->ldap_user_id$aId_insertedUsers))
  1444.                         {
  1445.                             $tr_user[SPACE4 '<td class="White_TD"><img src="' IMAGE_DIR 'exclamation_orange.png" title="' $this->aParamLang['ldap_import']['libelle_20''" alt="' $this->aParamLang['ldap_import']['libelle_18''" /></td>';
  1446.                         }
  1447.                         else
  1448.                         {
  1449.                             $tr_user[SPACE4 '<td>&nbsp;</td>';
  1450.                         }
  1451.                         //
  1452.                     //fin if
  1453.                     //on récupère les td de chaque champ 
  1454.                     $tr_user[$this->ldap_checkUserAttribut($oUser);
  1455.                     //
  1456.                     $tr_user[SPACE4 '</td>';
  1457.                     $tr_user[SPACE3 '</tr>';
  1458.                     //on ajoute la ligne tr à un tableau pour le trier selon le critère demandé
  1459.                     if (isset ($sAttribut))
  1460.                     {
  1461.                         //on provoque le tri avec $oUser->$sortBy 
  1462.                         //$oUser->unique_id  évite les doublons
  1463.                         $arraytemp["'" $oUser-> $sAttribut $oUser->unique_id "'"implode("\n"$tr_user);
  1464.                     }
  1465.                     else
  1466.                     {
  1467.                         $arraytemp[implode("\n"$tr_user);
  1468.                     }
  1469.                     unset ($tr_user);
  1470.                 //fin foreach 
  1471.                 //on active le type de tri selon le cas
  1472.                 switch ($sSortBy)
  1473.                 {
  1474.                     //
  1475.                     case 'ASC' :
  1476.                         ksort($arraytemp);
  1477.                         break;
  1478.                     case 'DESC' :
  1479.                         krsort($arraytemp);
  1480.                         break;
  1481.                         //
  1482.                 }
  1483.                 //on inclue la numérotation
  1484.                 //            foreach ($arraytemp as $value)
  1485.                 //            {
  1486.                 //                static $i = 1;
  1487.                 //                $aTR[] = str_replace('##ITERATOR##', $i++, $value);
  1488.                 //            }
  1489.                 //
  1490.                 $aContent[implode("\n"$arraytemp);
  1491.             //fin if
  1492.             //
  1493.             $aContent[SPACE2 '</table>';
  1494.             $aContent[SPACE1 '</div>';
  1495.         }
  1496.         //
  1497.         return implode("\n"$aContent);
  1498.     //fin ldap_display_import()
  1499.     //
  1500.         /**
  1501.      * @description gère la pagination des résultats
  1502.      */
  1503.     function pager($totalData)
  1504.     {
  1505.         //on construit un objet pager (sans class)
  1506.         $oPager new stdclass();
  1507.         //si aucune action
  1508.         if (!isset ($_SESSION['Ldap2Mysql']['numeroPage']))
  1509.         {
  1510.             $_SESSION['Ldap2Mysql']['numeroPage'0;
  1511.             $_SESSION['Ldap2Mysql']['nombreLignesAffichees'10//$this->_aSelect_nombre_Affichage[0];
  1512.         }
  1513.         if (!empty ($_POST))
  1514.         {
  1515.             foreach ($_POST as $_key => $_value)
  1516.             {
  1517.                 switch ($_key)
  1518.                 {
  1519.                     //select_nombre_Affichage
  1520.                     case 'select_nombre_Affichage' :
  1521.                         //
  1522.                         $_SESSION['Ldap2Mysql']['nombreLignesAffichees'$_POST['select_nombre_Affichage'];
  1523.                         break;
  1524.                         //
  1525.                     case 'btn_next' :
  1526.                         //        
  1527.                         $iLimiteDesactivation $_SESSION['Ldap2Mysql']['numeroPage'($_SESSION['Ldap2Mysql']['nombreLignesAffichees']);
  1528.                         //
  1529.                         if ($iLimiteDesactivation <= ($totalData $_SESSION['Ldap2Mysql']['nombreLignesAffichees']))
  1530.                         {
  1531.                             $_SESSION['Ldap2Mysql']['numeroPage']++;
  1532.                         }
  1533.                         //
  1534.                         $iTotalPage ceil($totalData $_SESSION['Ldap2Mysql']['nombreLignesAffichees']);
  1535.                         if ($_SESSION['Ldap2Mysql']['numeroPage'== ($iTotalPage -1))
  1536.                         {
  1537.                             $oPager->bStop true;
  1538.                         //fin if
  1539.                         //
  1540.                         break;
  1541.                         //
  1542.                     case 'btn_preview' :
  1543.                         //
  1544.                         if ($_SESSION['Ldap2Mysql']['numeroPage'> (int) 0)
  1545.                         {
  1546.                             $_SESSION['Ldap2Mysql']['numeroPage']--;
  1547.                         }
  1548.                         //                        
  1549.                         break;
  1550.                         //
  1551.                 //fin switch
  1552.                 //
  1553.             //fin foreach
  1554.         //fin if
  1555.         // 
  1556.         $oPager->iNombreLignesAffichees $_SESSION['Ldap2Mysql']['nombreLignesAffichees'];
  1557.         $oPager->iNumeroPage $_SESSION['Ldap2Mysql']['numeroPage'];
  1558.         //
  1559.         return $oPager;
  1560.     //fin  function pager()
  1561.     //
  1562.         function consult_getAttributListToDisplay()
  1563.     {
  1564.         //
  1565.         if ($_SESSION['Ldap2Mysql']['mysql_listFieldsToImport'])
  1566.         {
  1567.             return $_SESSION['Ldap2Mysql']['mysql_listFieldsToImport'];
  1568.         }
  1569.         else
  1570.         {
  1571.             return null;
  1572.         }
  1573.         //
  1574.     }
  1575.     //
  1576.         /**
  1577.      * @description récupère les utilisateurs non présents dans le ldap
  1578.      * @return array d'objets $aoUser
  1579.      */
  1580.     //
  1581.         function consult_getUsersNotInLdap()
  1582.     {
  1583.         //
  1584.         $sQuery 'SELECT * FROM ' $this->sMysqlTableToUpdate;
  1585.         $sQuery .= " WHERE ldap_user_id IS NULL OR  ldap_user_id LIKE ''";
  1586.         //construction de la requête
  1587.         //connexion et création d'une ressource
  1588.         $bNoConnexion $this->mysql_getConnexion();
  1589.         //
  1590.         if (isset ($bNoConnexion))
  1591.         {
  1592.             return null;
  1593.         //fin if
  1594.         //
  1595.         $res mysql_query($sQuery);
  1596.         //
  1597.         //on récupère la list des champs mysql
  1598.         $mysql_listFieldsToImport $_SESSION['Ldap2Mysql']['mysql_listFieldsToImport'];
  1599.         //on récupère les données correspondantes
  1600.         while ($row mysql_fetch_assoc($res))
  1601.         {
  1602.             //
  1603.             $oUser new stdClass();
  1604.             //$oUser->
  1605.             foreach ($mysql_listFieldsToImport as $champ)
  1606.             {
  1607.                 $oUser-> $champ $row[$champ];
  1608.             }
  1609.             $aoUser[$oUser;
  1610.             //            
  1611.         }
  1612.         //
  1613.         if (isset ($aoUser))
  1614.         {
  1615.             return $aoUser;
  1616.         }
  1617.         //
  1618.     }
  1619.     function consult_controller()
  1620.     {
  1621.         return $this->consult_view($this->consult_getUsersNotInLdap());
  1622.     }
  1623.     //
  1624.     //
  1625.         function consult_view($aoUser)
  1626.     {
  1627.         $aContent[SPACE1 '<div class="row">&raquo;&nbsp;' $this->aParamLang['ldap_import']['libelle_28'];
  1628.         $aContent[SPACE1 '</div><br/>';
  1629.         //
  1630.         //liste des serveurs ldap
  1631.         $aContent[SPACE1 '<div class="row">';
  1632.         $aContent['<div class ="divLeft">' $this->aParamLang['ldap_import']['libelle_25''&nbsp;:&nbsp;</div>';
  1633.         $aContent['<div class ="divRight">';
  1634.         $aConfigImport $this->ldap_import_loadListConfig();
  1635.         $aContent[$this->formSelectComponent('select_configImport'$aConfigImport$aOption array (
  1636.             'onchange="clearField();"'
  1637.         ));
  1638.         $aContent['<input type="submit" name="btn_loadUsersfromMysql" value="&raquo;&nbsp;' $this->aParamLang['ldap_import']['libelle_26''" class="inputSubmit"  />';
  1639.         $aContent['</div>';
  1640.         $aContent[SPACE1 '</div>';
  1641.         //
  1642.         $libelle $this->aParamLang['ldap_import']['libelle_5'];
  1643.         $nombreUser 0;
  1644.         //
  1645.         if (isset ($aoUser))
  1646.         {
  1647.             $nombreUser count($aoUser);
  1648.             $this->result true;
  1649.         }
  1650.         //
  1651.         //
  1652.         switch ($nombreUser)
  1653.         {
  1654.             //
  1655.             case (int) :
  1656.                 $libelle $this->aParamLang['ldap_import']['libelle_3'];
  1657.                 break;
  1658.                 //
  1659.             case (int) :
  1660.                 $libelle $this->aParamLang['ldap_import']['libelle_5'];
  1661.                 break;
  1662.                 //
  1663.             case $nombreUser > (int) :
  1664.                 $libelle $this->aParamLang['ldap_import']['libelle_4'];
  1665.                 break;
  1666.                 //
  1667.         }
  1668.         //
  1669.         if (isset ($this->result))
  1670.         {
  1671.             //résultat nombre personnes trouvées
  1672.             $aContent[SPACE1 '<div class="row">';
  1673.             $aContent['<div class ="divLeft">&nbsp;';
  1674.             $aContent['</div>';
  1675.             $aContent['<div class ="divRight">';
  1676.             //
  1677.             $aContent['&nbsp;&raquo;&nbsp;<span class="redBold">' $nombreUser '</span>&nbsp;' $libelle;
  1678.             //
  1679.             $aContent['</div>';
  1680.             $aContent[SPACE1 '</div>';
  1681.         }
  1682.         //
  1683.         $aContent[SPACE1 '<div class="row">';
  1684.         $aContent['&nbsp;';
  1685.         $aContent[SPACE1 '</div>';
  1686.         if (!empty ($aoUser))
  1687.         {
  1688.             //
  1689.             $aContent['<!-- table des utilisateurs-->';
  1690.             $aContent[SPACE1 '<div class="row">';
  1691.             //
  1692.             $aContent[SPACE2 '<table  summary="users" class="ldap_import"  cellpadding="0" cellspacing="0">';
  1693.             $aContent[SPACE3 '<tr>';
  1694.             $aContent[SPACE4 '<th>#';
  1695.             $aContent[SPACE4 '</th>';
  1696.             //
  1697.             $sSortBy '';
  1698.             //
  1699.             if (!empty ($_POST))
  1700.             {
  1701.                 //
  1702.                 foreach ($_POST as $key => $value)
  1703.                 {
  1704.                     $tab explode('#'$key);
  1705.                     //
  1706.                     if (isset ($tab[0]AND $tab[0== 'sortBy')
  1707.                     {
  1708.                         $sAttribut $tab[1];
  1709.                         //
  1710.                         if (isset ($_SESSION['Ldap2Mysql']['sSortBy']))
  1711.                         {
  1712.                             //
  1713.                             if ($_SESSION['Ldap2Mysql']['sSortBy'== 'ASC')
  1714.                             {
  1715.                                 $_SESSION['Ldap2Mysql']['sSortBy''DESC';
  1716.                                 $sSortBy 'DESC';
  1717.                             }
  1718.                             else
  1719.                             {
  1720.                                 $_SESSION['Ldap2Mysql']['sSortBy''ASC';
  1721.                                 $sSortBy 'ASC';
  1722.                             }
  1723.                             //
  1724.                         }
  1725.                         else
  1726.                         {
  1727.                             $_SESSION['Ldap2Mysql']['sSortBy''ASC';
  1728.                         }
  1729.                         //
  1730.                     //fin if
  1731.                 //fin foreach
  1732.                 //
  1733.             }
  1734.             else
  1735.             {
  1736.                 $sSortBy $_SESSION['Ldap2Mysql']['sSortBy'];
  1737.             //fin if
  1738.             //  
  1739.             $imageSortType '';
  1740.             switch ($sSortBy)
  1741.             {
  1742.                 case 'ASC' :
  1743.                     //
  1744.                     $sSortBy 'DESC';
  1745.                     $pictoDesc IMAGE_DIR 'desc.png';
  1746.                     $imageWidthHeight getimagesize($pictoDesc);
  1747.                     $imageSortType '<img src="' $pictoDesc '" ' $imageWidthHeight ' alt="' $this->aParamLang['ldap_import']['libelle_23''" title="' $this->aParamLang['ldap_import']['libelle_23''" />';
  1748.                     break;
  1749.                     //
  1750.                 case 'DESC' :
  1751.                     //
  1752.                     $sSortBy 'ASC';
  1753.                     $pictoAsc IMAGE_DIR 'asc.png';
  1754.                     $imageWidthHeight getimagesize($pictoAsc);
  1755.                     $imageSortType '<img src="' $pictoAsc '" ' $imageWidthHeight ' alt="' $this->aParamLang['ldap_import']['libelle_24''" title="' $this->aParamLang['ldap_import']['libelle_24''" />';
  1756.                     break;
  1757.                     //
  1758.             //fin switch
  1759.             //
  1760.             $aListeChampMysql $this->consult_getAttributListToDisplay();
  1761.             foreach ($aListeChampMysql as $key => $champ)
  1762.             {
  1763.                 $entete '<input type="submit" name="sortBy#' $champ '" value="' $champ '" class="submit_entete" />';
  1764.                 //on n'active que celui qui est cliqueé 
  1765.                 if (isset ($sAttributAND $sAttribut == $champ)
  1766.                 {
  1767.                     $aContent[SPACE4 '<th>' $imageSortType $entete;
  1768.                 }
  1769.                 else
  1770.                 {
  1771.                     $aContent[SPACE4 '<th>' $entete;
  1772.                 }
  1773.                 $aContent[SPACE4 '</th>';
  1774.             }
  1775.             //              
  1776.             $aContent[SPACE3 '</tr>';
  1777.             //
  1778.             foreach ($aoUser as $key => $oUser)
  1779.             {
  1780.                 //
  1781.                 $tr_user[SPACE3 '<tr>';
  1782.                 //colonne des numéros de lignes, on numérote les lignes avec $key
  1783.                 $tr_user[SPACE4 '<td>##ITERATOR##</td>';
  1784.                 //
  1785.                 foreach ($aListeChampMysql as $champ)
  1786.                 {
  1787.                     $tr_user[SPACE4 '<td>' $oUser-> $champ '</td>';
  1788.                 }
  1789.                 $tr_user[SPACE3 '</tr>';
  1790.                 //on ajoute la ligne tr à un tableau pour le trier selon le critère demandé
  1791.                 if (isset ($sAttribut))
  1792.                 {
  1793.                     //on provoque le tri avec $oUser->$sortBy 
  1794.                     //pour  éviter les doublons on ajoute $this->get_temporary_unique_id 
  1795.                     $arraytemp["'" $oUser-> $sAttribut $this->get_temporary_unique_id("'"implode("\n"$tr_user);
  1796.                 }
  1797.                 else
  1798.                 {
  1799.                     $arraytemp[implode("\n"$tr_user);
  1800.                 }
  1801.                 unset ($tr_user);
  1802.             //fin foreach 
  1803.             //on active le type de tri selon le cas
  1804.             switch ($sSortBy)
  1805.             {
  1806.                 //
  1807.                 case 'ASC' :
  1808.                     ksort($arraytemp);
  1809.                     break;
  1810.                 case 'DESC' :
  1811.                     krsort($arraytemp);
  1812.                     break;
  1813.                     //
  1814.             }
  1815.             //on inclue la numérotation
  1816.             foreach ($arraytemp as $value)
  1817.             {
  1818.                 static $i 1;
  1819.                 $aTR[str_replace('##ITERATOR##'$i++$value);
  1820.             }
  1821.             //
  1822.             $aContent[implode("\n"$aTR);
  1823.             //
  1824.             $aContent[SPACE2 '</table>';
  1825.             $aContent[SPACE1 '</div>';
  1826.         }
  1827.         //
  1828.         return implode("\n"$aContent);
  1829.     }
  1830.     //
  1831.         /**
  1832.      * @description liste des champs ldap à afficher
  1833.      */
  1834.     function ldap_getAttributListToDisplay()
  1835.     {
  1836.         //
  1837.         if ($_SESSION['Ldap2Mysql']['ldap_listFieldsToImport'])
  1838.         {
  1839.             return $_SESSION['Ldap2Mysql']['ldap_listFieldsToImport'];
  1840.         }
  1841.         else
  1842.         {
  1843.             return null;
  1844.         }
  1845.         //
  1846.     }
  1847.     //
  1848.         function ldap_checkUserAttribut($oUser)
  1849.     {
  1850.         //
  1851.         $ldap_attributListToDisplay $this->ldap_getAttributListToDisplay();
  1852.         if (isset ($ldap_attributListToDisplay))
  1853.         {
  1854.             //$value étant le champ à afficher donc l'attribut de $oUser
  1855.             foreach ($ldap_attributListToDisplay as $key => $attribut)
  1856.             {
  1857.                 //on vérifie quel type de contenu (array,string)
  1858.                 switch (gettype($oUser-> $attribut))
  1859.                 {
  1860.                     //l'attibut est un array donc à parcourir
  1861.                     case 'array' :
  1862.                         //
  1863.                         $select['<select name="' $oUser->unique_id '-' $attribut '">';
  1864.                         foreach ($oUser-> $attribut as $_key => $_value)
  1865.                         {
  1866.                             $_value strtolower(trim($_value));
  1867.                             $select['<option value="' $_value '">' $_value '</option>';
  1868.                         }
  1869.                         $select['</select>';
  1870.                         $td[implode("\n"$select);
  1871.                         break;
  1872.                         //
  1873.                     case 'string' :
  1874.                         //
  1875.                         $contentTD $oUser-> $attribut;
  1876.                         //
  1877.                         if (strlen($contentTD25)
  1878.                         {
  1879.                             $td['<a href="#" title="' $contentTD '">' substr($oUser-> $attribut025'...</a>';
  1880.                         }
  1881.                         else
  1882.                         {
  1883.                             $td[$contentTD;
  1884.                         }
  1885.                         break;
  1886.                         //
  1887.                     case 'NULL' :
  1888.                         //
  1889.                         $td[null;
  1890.                         break;
  1891.                         //
  1892.                 //fin switch
  1893.                 //
  1894.             }
  1895.             //
  1896.             if (isset ($td))
  1897.             {
  1898.                 return SPACE4 '<td class="content">' implode('</td>' "\n" SPACE4 '<td class="content">'$td);
  1899.             }
  1900.             //
  1901.         //fin if
  1902.     }
  1903.     //
  1904.         function baseConfig_save_delete($objetToSerialize$fFile$sDelete null)
  1905.     {
  1906.         //
  1907.         $aObjet array ();
  1908.         if (file_exists($fFile))
  1909.         {
  1910.             //on charge  le fichier texte, chaque ligne est un objet
  1911.             $aObjet unserialize(file_get_contents($fFile));
  1912.         }
  1913.         //
  1914.         $aObjet[$objetToSerialize->id->value$objetToSerialize;
  1915.         //suppression
  1916.         if ($sDelete == 'delete')
  1917.         {
  1918.             unset ($aObjet[$objetToSerialize->id->value]);
  1919.         }
  1920.         //si le fichier n'existe pas on tente de le créer
  1921.         $handle fopen($fFile'w+');
  1922.         fwrite($handleserialize($aObjet));
  1923.         fclose($handle);
  1924.     }
  1925.     //
  1926.         /**
  1927.      * @description initialise un  objet base (MYSQL, ldap, CAS) avec les
  1928.      *  paramètres par défaut
  1929.      * 
  1930.      * @param string $sBaseType 
  1931.      * @return object $oBase
  1932.      *
  1933.      */
  1934.     function baseInitializeObject($sBaseType)
  1935.     {
  1936.         //on charge un modèle d'objet
  1937.         $oBase $this->formInitializeObject($sBaseType);
  1938.         //on redéfinit certaines propriétés sinon on renvoie l'objet tel quel 
  1939.         switch ($sBaseType)
  1940.         {
  1941.             //
  1942.             case 'ldap' :
  1943.                 //
  1944.                 $oBase->port->required false//pass
  1945.                 break;
  1946.                 //
  1947.             case 'mysql' :
  1948.                 //
  1949.                 $oBase->pass->required false//pass
  1950.                 $oBase->port->required false//port
  1951.                 break;
  1952.                 //
  1953.             case 'cas' :
  1954.                 //
  1955.                 $oBase->path->required false//path
  1956.                 $oBase->port->required false//port
  1957.                 $oBase->nom->required false//port
  1958.                 break;
  1959.                 //
  1960.         }
  1961.         //
  1962.         return $oBase;
  1963.     }
  1964.     //
  1965.         /**
  1966.      * @description gestion de toutes les actions sur l'interface de configuration
  1967.      * @return object $oBase
  1968.      */
  1969.     function baseConfig_controller($sBaseType 'ldap')
  1970.     {
  1971.         $fFile CONFIG_DIR 'baseConfig';
  1972.         //
  1973.         $action null;
  1974.         if (!empty ($_POST['type']))
  1975.         {
  1976.             $sBaseType $_POST['type'];
  1977.             $action 'type';
  1978.         }
  1979.         //
  1980.         $aAction array (
  1981.             'new',
  1982.             'cancel',
  1983.             'save',
  1984.             'modify',
  1985.             'delete'
  1986.         );
  1987.         //
  1988.         $oBase $this->baseInitializeObject($sBaseType);
  1989.         $this->formVisible false;
  1990.         //liste des boutons à afficher
  1991.         $this->listeBoutons array (
  1992.             'new',
  1993.             'modify',
  1994.             'delete'
  1995.         )//on affiche la liste des serveurs           
  1996.         $this->blisteDeroulanteVisible = true;
  1997.         //on active l'affichage de la date de mise à jour
  1998.         //on capture l'action
  1999.         if (!empty ($_POST))
  2000.         {
  2001.             foreach ($_POST as $key => $value)
  2002.             {
  2003.                 //l'action est la valeur name du bouton ou le submit du select de la base select_loadBase
  2004.                 if (in_array($key$aAction))
  2005.                 {
  2006.                     $action $key;
  2007.                 }
  2008.             }
  2009.             //
  2010.         }
  2011.         //
  2012.         if (!empty ($_POST['select_listBase']))
  2013.         {
  2014.             //chargement du modèle de notre objet $oBase
  2015.             $oBase $this->baseLoadParam($_POST['select_listBase']);
  2016.             $this->formVisible true;
  2017.         }
  2018.         //    
  2019.         switch ($action)
  2020.         {
  2021.             //
  2022.             case 'new' :
  2023.                 $this->formVisible true;
  2024.                 //
  2025.                 $oBase $this->baseInitializeObject($sBaseType);
  2026.                 //pour rendre visible le formulaire vide
  2027.                 //on affiche la liste des serveurs        
  2028.                 $this->blisteDeroulanteVisible = false;
  2029.                 $this->isVisible_btn_Test true;
  2030.                 $this->listeBoutons array (
  2031.                     'cancel',
  2032.                     'save'
  2033.                 );
  2034.                 break;
  2035.                 //    
  2036.             case 'type' :
  2037.                 //
  2038.             case 'save' :
  2039.                 //
  2040.                 $this->formVisible true;
  2041.                 $bValider true;
  2042.                 //
  2043.                 foreach ($oBase as $propertie => $value)
  2044.                 {
  2045.                     //pour  éviter d'écraser les valeurs par défaut de l'objet
  2046.                     if (isset ($_POST[$propertie]))
  2047.                     {
  2048.                         $oBase-> $propertie->value trim($_POST[$propertie]);
  2049.                         //on récupère au passage la liste des champs saisis            
  2050.                         if ($propertie <> 'id' AND $oBase-> $propertie->required == AND $oBase-> $propertie->value == '')
  2051.                         {
  2052.                             $oBase-> $propertie->valide false;
  2053.                             $bValider false;
  2054.                         }
  2055.                     }
  2056.                 }
  2057.                 if ($action == 'save')
  2058.                 {
  2059.                     //on vérifie si nom n'existe pas déjà
  2060.                     if (isset ($oBase->nom->valueAND trim($oBase->nom->value<> '')
  2061.                     {
  2062.                         $iNombreBaseTrouve $this->baseNomExist($oBase->nom->value);
  2063.                     }
  2064.                     //on verifie qu'aucun nom n'est déjà attribué
  2065.                     if (isset ($iNombreBaseTrouve))
  2066.                     {
  2067.                         //
  2068.                         $bValider false;
  2069.                         //
  2070.                         $oBase->nom->valide false;
  2071.                         $oBase->nom->errorMessage $this->aParamLang['base']['libelle_13'];
  2072.                         //
  2073.                     }
  2074.                 }
  2075.                 //les champs requis sont remplis on enregistre ET ce n'est pas un tes de connexion
  2076.                 if ($bValider == true)
  2077.                 {
  2078.                     //la première portion faciltera le tri selon le type de base 
  2079.                     $oBase->id->value $oBase->type->value '-' md5($oBase->nom->value);
  2080.                     //
  2081.                     $this->baseConfig_save_delete($oBase$fFile);
  2082.                     //on affiche la liste des serveurs            
  2083.                     $this->blisteDeroulanteVisible = true;
  2084.                     $this->listeBoutons array (
  2085.                         'new',
  2086.                         'modify',
  2087.                         'delete'
  2088.                     );
  2089.                     $oBase $this->baseInitializeObject($sBaseType);
  2090.                 }
  2091.                 else
  2092.                 {
  2093.                     $this->blisteDeroulanteVisible = false;
  2094.                     $this->isVisible_btn_Test true;
  2095.                     $this->listeBoutons array (
  2096.                         'cancel',
  2097.                         'save'
  2098.                     );
  2099.                 //fin if
  2100.                 break;
  2101.                 //
  2102.             case 'modify' :
  2103.                 //
  2104.                 $bValider true;
  2105.                 //
  2106.                 foreach ($oBase as $propertie => $value)
  2107.                 {
  2108.                     //pour  éviter d'écraser les valeurs par défaut de l'objet
  2109.                     if (isset ($_POST[$propertie]))
  2110.                     {
  2111.                         $oBase-> $propertie->value trim($_POST[$propertie]);
  2112.                         //on récupère au passage la liste des champs saisis            
  2113.                         if ($oBase-> $propertie->required == AND $oBase-> $propertie->value == '')
  2114.                         {
  2115.                             $oBase-> $propertie->valide false;
  2116.                             $bValider false;
  2117.                         //fin if
  2118.                     //fin if
  2119.                 //fin foreach
  2120.                 //on vérifie si nom n'existe pas déjà
  2121.                 $iNombreBaseTrouve $this->baseNomExist($oBase->nom->value);
  2122.                 //on verifie qu'aucun nom n'est déjà attribué
  2123.                 if (count($iNombreBaseTrouve1)
  2124.                 //
  2125.                     $bValider false;
  2126.                     $oBase->nom->valide false;
  2127.                     $oBase->nom->errorMessage $this->aParamLang['base']['libelle_13'];
  2128.                 }
  2129.                 //les champs requis sont remplis on enregistre
  2130.                 if ($bValider == true)
  2131.                 {
  2132.                     $this->baseConfig_save_delete($oBase$fFile);
  2133.                 }
  2134.                 //on affiche la liste des serveurs          
  2135.                 $this->blisteDeroulanteVisible = true;
  2136.                 $this->listeBoutons array (
  2137.                     'new',
  2138.                     'modify',
  2139.                     'delete'
  2140.                 );
  2141.                 break;
  2142.                 //
  2143.             case 'delete' :
  2144.                 //
  2145.                 if (isset ($oBase))
  2146.                 {
  2147.                     $this->baseConfig_save_delete($oBase$fFile'delete');
  2148.                 //fin if
  2149.                 //on réinitialise l'objet base
  2150.                 $oBase $this->baseInitializeObject($sBaseType);
  2151.                 $this->listeBoutons array (
  2152.                     'new',
  2153.                     'modify',
  2154.                     'delete'
  2155.                 );
  2156.                 //on affiche la liste des serveurs            
  2157.                 $this->blisteDeroulanteVisible = true;
  2158.                 //on met les boutons de contrôles necéssaires
  2159.                 //
  2160.                 break;
  2161.                 //
  2162.             case 'cancel' :
  2163.                 //on affiche la liste des bases            
  2164.                 $this->blisteDeroulanteVisible = true;
  2165.                 $this->listeBoutons array (
  2166.                     'new',
  2167.                     'modify',
  2168.                     'delete'
  2169.                 );
  2170.                 //
  2171.                 break;
  2172.                 //
  2173.             default :
  2174.                 break;
  2175.         //fin switch
  2176.         //
  2177.         //
  2178.         return $this->baseConfig_view($oBase);
  2179.     // fin baseConfig_controller($sBaseType)
  2180.     //
  2181.         function baseConfig_view($oBase)
  2182.     {
  2183.         //selection des différents serveurs pour chaque type
  2184.         if ($this->blisteDeroulanteVisible == true)
  2185.         {
  2186.             unset ($oBase->type);
  2187.             $aContent['<div class="row">';
  2188.             $aContent['<div class ="divLeft">' $this->aParamLang['base']['libelle_1'' : </div>';
  2189.             $aContent['<div class ="divRight">';
  2190.             //on récupère un tableau d'objets et on construit le select  de la liste des bases
  2191.             $aoListeBase $this->baseLoadList();
  2192.             $aContent[$this->buildSelectListeBase($aoListeBase);
  2193.             $aContent['</div>';
  2194.             $aContent['</div>';
  2195.             //
  2196.         }
  2197.         //
  2198.         if ($this->formVisible == true)
  2199.         {
  2200.             $sComponent '';
  2201.             foreach ($oBase as $propertie => $value)
  2202.             {
  2203.                 //
  2204.                 switch ($propertie)
  2205.                 {
  2206.                     //si id de la base, on le met en hidden
  2207.                     case 'id' :
  2208.                         $sComponentHidden $this->formInputComponent('hidden''id'$oBase-> $propertie->value);
  2209.                         break;
  2210.                         //si type de la base, on le met en hidden
  2211.                     case 'type' :
  2212.                         //
  2213.                         $sComponent $this->formSelectComponent('type'array (
  2214.                             'cas' => 'CAS',
  2215.                             'ldap' => 'LDAP',
  2216.                             'mysql' => 'MYSQL'
  2217.                         )$aOption array (
  2218.                             'onchange="javascript:submit();"'
  2219.                         )$oBase-> $propertie->value);
  2220.                         $sComponent .= $this->formInputComponent('submit''btn_validerSelect''OK'array (
  2221.                             'class' => 'inputSubmit'
  2222.                         ));
  2223.                         break;
  2224.                         //
  2225.                     default :
  2226.                         //
  2227.                         $sComponent $this->formInputComponent('text'$propertie$oBase-> $propertie->valuearray (
  2228.                             'class' => 'inputText'
  2229.                         ));
  2230.                         //
  2231.                         break;
  2232.                 //fin switch
  2233.                 //
  2234.                 //on charge le label de chaque contrôle
  2235.                 if ($propertie <> 'id')
  2236.                 {
  2237.                     //
  2238.                     $sAsterisque '';
  2239.                     if ($oBase-> $propertie->required == true)
  2240.                     {
  2241.                         $sAsterisque '<span style="color:red;font-weight:normal;">&nbsp;*</span>';
  2242.                     }
  2243.                     //
  2244.                     $aContent['<div class="row">';
  2245.                     $aContent['<div class ="divLeft">' $this->aParamLang['base'][$propertie' : </div>';
  2246.                     $aContent['<div class ="divRight">' $sComponent $sAsterisque '</div>';
  2247.                     $aContent['</div>';
  2248.                     //si la propriété est invalide , on affiche son message d'erreur
  2249.                     if (isset ($oBase-> $propertie->valideAND $oBase-> $propertie->valide == false)
  2250.                     {
  2251.                         $aContent['<div class="row">';
  2252.                         $aContent['<div class ="divLeft">&nbsp;</div>';
  2253.                         $aContent['<div class ="divRight">';
  2254.                         $aContent['<span class="errorMessage">^&nbsp;' $oBase-> $propertie->errorMessage '</span>';
  2255.                         $aContent['</div>';
  2256.                         $aContent['</div>';
  2257.                     }
  2258.                 //fin if
  2259.                 //
  2260.                 //
  2261.             //fin foreach
  2262.             $aContent[$sComponentHidden;
  2263.             //
  2264.             //
  2265.         //fin if
  2266.         //
  2267.         $aContent['<div id="boutonsControls">';
  2268.         $aContent['<div class ="divLeft">&nbsp;</div>';
  2269.         $aContent['<div class ="divRight">';
  2270.         //
  2271.         foreach ($this->listeBoutons as $value)
  2272.         {
  2273.             static $sListeBoutons '';
  2274.             $sListeBoutons .= $this->formInputComponent('submit'$value$this->aParamLang[$value]array (
  2275.                 'class' => 'inputSubmit'
  2276.             )) '&nbsp;';
  2277.         }
  2278.         $aContent[$sListeBoutons;
  2279.         $aContent['</div>';
  2280.         $aContent['</div>';
  2281.         return implode("\n"$aContent);
  2282.     //fin  ldap_get_controlPanel
  2283.     //
  2284.     //
  2285.         /** 
  2286.      *
  2287.      * @description vérifie si le nom du base existe
  2288.      * @param string $nom 
  2289.      * @return object $oBase
  2290.      */
  2291.     //
  2292.         function baseNomExist($nom)
  2293.     {
  2294.         //on charge toutes les base selon le type
  2295.         $aObjet $this->baseLoadList();
  2296.         //
  2297.         //
  2298.         if (isset ($aObjet))
  2299.         {
  2300.             //
  2301.             foreach ($aObjet as $objet)
  2302.             {
  2303.                 //
  2304.                 if (isset ($nomAND isset ($objet->nom->value))
  2305.                 {
  2306.                     //
  2307.                     if (strtolower($nom== strtolower($objet->nom->value))
  2308.                     {
  2309.                         //on comptabilise le nombre de libelle semblable
  2310.                         //utile pour l'enregistrement et sa modif
  2311.                         $arr[true;
  2312.                     }
  2313.                 //fin if
  2314.             }
  2315.             //
  2316.             if (isset ($arr))
  2317.             {
  2318.                 return $arr;
  2319.             //fin if
  2320.         //fin if
  2321.         //
  2322.     //fin  baseExist()
  2323.     
  2324.     /**
  2325.      * @description charge la config d'une base
  2326.      * @param string $oBase_id 
  2327.      * @return object 
  2328.      */
  2329.     function baseLoadParam($oBase_id)
  2330.     {
  2331.         //on charge toutes les base
  2332.         $aObjet $this->baseLoadList();
  2333.         //on charge celle choisie
  2334.         if (isset ($aObjet[$oBase_id]))
  2335.         {
  2336.             return $aObjet[$oBase_id];
  2337.         }
  2338.         //
  2339.     }
  2340.     //
  2341.         function baseLoadList()
  2342.     {
  2343.         //
  2344.         $fFile CONFIG_DIR 'baseConfig';
  2345.         //
  2346.         if (file_exists($fFile))
  2347.         {
  2348.             if (file_exists($fFile))
  2349.             //on charge  le fichier texte, chaque ligne est un objet
  2350.                 $aObjet unserialize(file_get_contents($fFile));
  2351.             }
  2352.         }
  2353.         //
  2354.         if (!empty ($aObjet))
  2355.         {
  2356.             ksort($aObjet);
  2357.             return $aObjet;
  2358.         }
  2359.         //
  2360.     }
  2361.     //
  2362.         function mysql_import_display()
  2363.     {
  2364.         $this->mysql_import_action();
  2365.         //liste des serveurs mysql
  2366.         $aContent['<div class="row">';
  2367.         $aContent['<div class ="divLeft">' $this->aParamLang['base']['libelle_1'' <b>MYSQL</b> : </div>';
  2368.         $aContent['<div class ="divRight">';
  2369.         $aContent[$this->buildSelectBaseOptions('mysql');
  2370.         $aContent['<input type="submit" name="btn_validerSelect" value="OK" class="inputSubmit"  />';
  2371.         $aContent['</div>';
  2372.         $aContent['</div>';
  2373.     }
  2374.     //
  2375.         function mysql_getFieldsUserGroups()
  2376.     {
  2377.         if (!empty ($_POST['btn_loadUsers']))
  2378.         {
  2379.             $this->mysql_getConnexion();
  2380.             $table $this->aMysqlTableUserGroups['table'];
  2381.             $field_id $this->aMysqlTableUserGroups['field_id'];
  2382.             $field_groupeType $this->aMysqlTableUserGroups['field_groupeType'];
  2383.             $sQuery 'SELECT ' $field_id ' ,' $field_groupeType;
  2384.             $sQuery .= ' FROM ' $table;
  2385.             $sQuery .= ' ORDER BY ' $field_groupeType;
  2386.             $res mysql_query($sQuery);
  2387.             while ($row mysql_fetch_assoc($res)) //on ne récupère pas le champ de la clé primaire 
  2388.             {
  2389.                 $aFields[$row[$field_id]] $row[$field_groupeType];
  2390.             }
  2391.             //
  2392.             //
  2393.             if (isset ($aFields))
  2394.             {
  2395.                 $_SESSION['Ldap2Mysql']['field_groupeType'$aFields;
  2396.                 return $aFields;
  2397.             //fin if
  2398.             //
  2399.         }
  2400.         else
  2401.         {
  2402.         }
  2403.         return $_SESSION['Ldap2Mysql']['field_groupeType'];
  2404.         //
  2405.     }
  2406.     /**
  2407.     * @description crée les champs gérant l'importation ldap
  2408.     * @return void 
  2409.     */
  2410.     function mysql_createFields($aFieldsToAdd)
  2411.     {
  2412.         //on construit      
  2413.         foreach ($aFieldsToAdd as $field => $value)
  2414.         {
  2415.             $aQuery['ALTER TABLE ' $this->sMysqlTableToUpdate . ' ADD ' $field ' ' $value;
  2416.         }
  2417.         //
  2418.         foreach ($aQuery as $sQuery)
  2419.         {
  2420.             $res mysql_query($sQuery);
  2421.         }
  2422.         //
  2423.     }
  2424.     //
  2425.         /** 
  2426.           * @description vérifie si les champs gérant l'importation ldap existent
  2427.         * @return mixed bool si true ou array $aFieldsToAdd nom des champs à créer
  2428.     */
  2429.     //
  2430.         function mysql_isFieldsExists()
  2431.     {
  2432.         //
  2433.         $sQuery 'SHOW COLUMNS  FROM ' $this->sMysqlTableToUpdate;
  2434.         $res mysql_query($sQuery);
  2435.         //modfication de la table
  2436.         $aFieldsToAdd['ldap_user_id''varchar(255) not null';
  2437.         $aFieldsToAdd['ldap_config_import_id''varchar(80) not null';
  2438.         $aFieldsToAdd['ldap_last_update''datetime not null';
  2439.         //
  2440.         $aFound array ();
  2441.         while ($row mysql_fetch_assoc($res)) //on ne récupère pas le champ de la clé primaire 
  2442.         {
  2443.             //on vérifie si le champ existe dans la liste 
  2444.             if (in_array($row['Field']array_keys($aFieldsToAdd)))
  2445.             {
  2446.                 //on le comptabilise
  2447.                 $aFound[$row['Field'];
  2448.             }
  2449.         }
  2450.         // le nombre de champs voulu doit être = au nombre de champ trouvé
  2451.         if (count($aFound== count($aFieldsToAdd))
  2452.         {
  2453.             //tous les champs existent
  2454.             return true;
  2455.         }
  2456.         else
  2457.         {
  2458.             //certains n'existent pas on envoi toute la liste
  2459.             return $aFieldsToAdd;
  2460.         }
  2461.         //
  2462.     //fin  mysql_isFieldsExists()
  2463.     //
  2464.         function mysql_getImportedUsers()
  2465.     {
  2466.         $arr $this->ldap_import_loadConfig($_POST['select_configImport']);
  2467.         $oMysql $arr['oMysql'];
  2468.         if (empty ($oMysql->port))
  2469.         {
  2470.             $oMysql->port 3306//port ldap par défaut
  2471.         }
  2472.         //on transmet un tableau qui représente les propriétés d'une base
  2473.         mysql_connect($oMysql->host$oMysql->login$oMysql->pass);
  2474.         mysql_select_db($oMysql->nom);
  2475.         $sQuery 'SELECT * FROM ' $this->sMysqlTableToUpdate . ' WHERE ldap_user_id NOT LIKE \'\'';
  2476.         //
  2477.         $res mysql_query($sQuery);
  2478.         while ($row mysql_fetch_assoc($res))
  2479.         {
  2480.             $champ['ldap_config_import_id'$row['ldap_config_import_id'];
  2481.             $champ['ldap_last_update'$row['ldap_last_update'];
  2482.             $champ['ldap_user_id'$row['ldap_user_id'];
  2483.             $arraytemp[$champ;
  2484.         }
  2485.         return $arraytemp;
  2486.         //
  2487.     //fin function mysql_getImportedUsers()
  2488.     //
  2489.         function mysql_getFields()
  2490.     {
  2491.         //
  2492.         if (!empty ($_POST['select_listeBase_mysql']))
  2493.         {
  2494.             $oBase_id $_POST['select_listeBase_mysql'];
  2495.             //on charge sa config
  2496.             $object $this->baseLoadParam($oBase_id);
  2497.             //
  2498.             $oMysql new stdClass();
  2499.             //
  2500.             foreach ($object as $key => $obj)
  2501.             {
  2502.                 $oMysql-> $key $obj->value;
  2503.             }
  2504.             mysql_connect($oMysql->host$oMysql->login$oMysql->pass);
  2505.             //
  2506.             $bSelectSucceed mysql_select_db($oMysql->nom);
  2507.             if ($bSelectSucceed == true)
  2508.             {
  2509.                 //
  2510.                 $sQuery 'SHOW COLUMNS FROM ' $this->sMysqlTableToUpdate;
  2511.                 $res mysql_query($sQuery);
  2512.                 while ($row mysql_fetch_assoc($res)) //on ne récupère pas le champ de la clé primaire 
  2513.                 {
  2514.                     if ($row['Key'<> 'PRI')
  2515.                     {
  2516.                         $aFields[$row['Field']] $row;
  2517.                     }
  2518.                 }
  2519.                 if (isset ($aFields))
  2520.                 {
  2521.                     //on stocke la structure détaillée des tables( type de champ etc..) pour l'enregistrement de la config
  2522.                     $_SESSION['Ldap2Mysql']['mysql_detailedListFields'$aFields;
  2523.                     //on récupère uniquement la liste des champs
  2524.                     $liste array_keys($aFields);
  2525.                     //on construit un tableau associatif pour le contrôle select
  2526.                     foreach ($liste as $value)
  2527.                     {
  2528.                         $_SESSION['Ldap2Mysql']['mysql_ListFields'][$value$value;
  2529.                     }
  2530.                     //on ne renvoi que le liste des champs
  2531.                     return $_SESSION['Ldap2Mysql']['mysql_ListFields'];
  2532.                 }
  2533.                 else
  2534.                 {
  2535.                     return null;
  2536.                 //fin if
  2537.             }
  2538.             else
  2539.             {
  2540.                 $_SESSION['Ldap2Mysql']['errorConnexionMysql'$this->aParamLang['config_import']['errorConnexionMysql'];
  2541.             //fin if
  2542.         }
  2543.         else
  2544.         {
  2545.             return null;
  2546.         //fin if
  2547.         //
  2548.     }
  2549.     //
  2550.         /**
  2551.      * 
  2552.      * @description  crée une ressource mysql
  2553.      * @return bool si pas de connexion
  2554.      */
  2555.     function mysql_getConnexion()
  2556.     {
  2557.         //
  2558.         if (!empty ($_POST['select_configImport']))
  2559.         {
  2560.             $arr $this->ldap_import_loadConfig($_POST['select_configImport']);
  2561.             $oMysql $arr['oMysql'];
  2562.             //
  2563.             if (empty ($oMysql->port))
  2564.             {
  2565.                 $oMysql->port 3306//port ldap par défaut
  2566.             }
  2567.             //on transmet un tableau qui représente les propriétés d'une base
  2568.             $resource_link mysql_connect($oMysql->host$oMysql->login$oMysql->pass);
  2569.             //
  2570.             if ($resource_link)
  2571.             {
  2572.                 mysql_select_db($oMysql->nom);
  2573.             }
  2574.             else
  2575.             {
  2576.             }
  2577.         }
  2578.         else
  2579.         {
  2580.             return false;
  2581.         }
  2582.     }
  2583.     //
  2584.         /**
  2585.      * @description fonction récupérant les logins de la base mysql
  2586.      * 
  2587.      * @return array associatif liste  des logins
  2588.      */
  2589.     function mysql_getAllLogin()
  2590.     {
  2591.         //construction de la requête
  2592.         $sQuery 'SELECT ' $this->champ_login . ' FROM ' $this->sMysqlTableToUpdate;
  2593.         //
  2594.         $res mysql_query($sQuery);
  2595.         $aLogin array ();
  2596.         //
  2597.         while ($row mysql_fetch_assoc($res))
  2598.         {
  2599.             $aLogin[$this->champ_login$row[$this->champ_login];
  2600.         }
  2601.         return $aLogin;
  2602.     }
  2603.     /**
  2604.      * @description fonction récupérant les personnes déjà importées
  2605.      * 
  2606.      * @param string le nom de la config d'importation
  2607.      * @return array associatif liste objet des personnes importées
  2608.      */
  2609.     function mysql_getInsertedUsers($sldap_config_import_id)
  2610.     {
  2611.         //connexion et création d'une ressource
  2612.         $sWhere '  WHERE ldap_config_import_id ' "='" $sldap_config_import_id "'";
  2613.         //construction de la requête
  2614.         $sQuery 'SELECT * FROM ' $this->sMysqlTableToUpdate . $sWhere;
  2615.         //
  2616.         $res mysql_query($sQuery);
  2617.         $arr array ();
  2618.         //
  2619.         while ($row mysql_fetch_assoc($res))
  2620.         {
  2621.             $oInsertedUser new stdClass();
  2622.             $oInsertedUser->ldap_config_import_id $row['ldap_config_import_id'];
  2623.             $oInsertedUser->ldap_user_id $row['ldap_user_id'];
  2624.             $oInsertedUser->ldap_last_update $row['ldap_last_update'];
  2625.             //on crée un tableau respectant l'unicité par ldap_user_id
  2626.             $arr[$oInsertedUser->ldap_user_id$oInsertedUser;
  2627.         }
  2628.         //
  2629.         return $arr;
  2630.         //
  2631.     //fin function mysql_getInsertedUsers($sldap_config_import_id)
  2632.     //
  2633.         /**
  2634.      * @description fonction qui va initialiser un tableay dont les clés sont les champs mysql et les valeurs
  2635.      *  sont la valeur default du champ si elle existe, si le champ est obligatoire
  2636.      *   on lui asscie un valeur temporaire sinon une valeur null  ou
  2637.      */
  2638.     function mysql_initializeFieldsToImport()
  2639.     {
  2640.         //
  2641.         $aMysql_detailedListFields $_SESSION['Ldap2Mysql']['mysql_detailedListFields'];
  2642.         //on initialise un tabelau avec des valeurs par défaut 
  2643.         foreach ($aMysql_detailedListFields as $champ => $champDetail)
  2644.         {
  2645.             //on vérifie la nullité de chaque champ de la base          
  2646.             if ($champDetail['Null'== 'YES')
  2647.             {
  2648.                 if (!empty ($champDetail['Default']))
  2649.                 {
  2650.                     //on prend la valeur par défaut du champ
  2651.                     $aMysql_ListFields[$champ$champ "='" $champDetail['Default'"'";
  2652.                 }
  2653.                 else
  2654.                 {
  2655.                     //sinon on lui affecte la valeur null
  2656.                     $aMysql_ListFields[$champ$champ "=null";
  2657.                 }
  2658.             }
  2659.             else
  2660.             {
  2661.                 if (!empty ($champDetail['Default']))
  2662.                 {
  2663.                     //on prend la valeur par défaut du champ
  2664.                     $aMysql_ListFields[$champ$champ "='" $champDetail['Default'"'";
  2665.                 }
  2666.                 else
  2667.                 {
  2668.                     //@promethee
  2669.                     //on prompose un mot de passe pour promethee
  2670.                     if (isset ($this->champ_motDePasseAND $champ == $this->champ_motDePasse)
  2671.                     {
  2672.                         $aMysql_ListFields[$this->champ_motDePasse$this->champ_motDePasse . "='" $this->mysql_generate_passWord("'";
  2673.                     }
  2674.                     elseif (isset ($this->champ_loginAND $champ == $this->champ_login)
  2675.                     {
  2676.                         //on récupère les logins de la base
  2677.                         $aLogin $this->mysql_getAllLogin();
  2678.                         //on génère un login unique
  2679.                         $newLogin '';
  2680.                         while (in_array($newLogin $this->mysql_generate_login()$aLogin))
  2681.                         {
  2682.                             //la boucle tourne jusqu'à trouver un login unique
  2683.                         }
  2684.                         //à la fin, on récupère notre variable $newLogin
  2685.                         $aMysql_ListFields[$this->champ_login$this->champ_login . "='" $newLogin "'";
  2686.                     }
  2687.                     else
  2688.                     {
  2689.                         //on remplit les champs non nul avec une valeur temporaire  unique
  2690.                         //à ne pas confondre avec unique_id qui, lui, vient du ldap
  2691.                         $aMysql_ListFields[$champ$champ "='tmp" $this->get_temporary_unique_id("'";
  2692.                     }
  2693.                 }
  2694.                 //
  2695.             //fin if
  2696.         //fin foreach
  2697.         return $aMysql_ListFields;
  2698.     //fin function mysql_initializeFieldsToImport()
  2699.     //
  2700.         /**
  2701.      * @description  ajoute les utilisateurs dans la base mysql
  2702.      * @param  array $aQuery les requêtes d'insertion
  2703.      * @return  ajoute des valeurs booléennes de succès (insertion ou mise
  2704.      *  à jour ou non succès dans chaque  objet ($aoUser)
  2705.      * 
  2706.      */
  2707.     function mysql_addUsersFromLdap($aQuery$aUpdateOrInsert)
  2708.     {
  2709.         //
  2710.         foreach ($aQuery as $unique_id => $sQuery)
  2711.         {
  2712.             $res mysql_query($sQuery);
  2713.             $userLog new stdClass();
  2714.             $userLog->ldap_user_id $unique_id;
  2715.             $userLog->date_import date('Y-m-d H:i:s');
  2716.             //
  2717.             if (mysql_affected_rows(== (int) 1)
  2718.             {
  2719.                 $this->set_variableSessionUser($unique_id'userImported'$aUpdateOrInsert[$unique_id]);
  2720.             }
  2721.             else
  2722.             {
  2723.                 $this->set_variableSessionUser($unique_id'userImported''failed');
  2724.             }
  2725.             //
  2726.         }
  2727.         //
  2728.     }
  2729.     //
  2730.         /**
  2731.     * @description crée un login temporaire pour promethée
  2732.     * @return string login
  2733.     */
  2734.     function mysql_generate_login()
  2735.     {
  2736.         $aBannerList array (
  2737.             'pute'
  2738.         );
  2739.         $aVoyelle array (
  2740.             'a',
  2741.             'e',
  2742.             'i',
  2743.             'o',
  2744.             'u',
  2745.             'ou',
  2746.             'on'
  2747.         );
  2748.         $aConsonne array (
  2749.             'b',
  2750.             'c',
  2751.             'd',
  2752.             'f',
  2753.             'g',
  2754.             'j',
  2755.             'k',
  2756.             'l',
  2757.             'm',
  2758.             'n',
  2759.             'p',
  2760.             'r',
  2761.             's',
  2762.             't',
  2763.             'v',
  2764.             'w',
  2765.             'x',
  2766.             'z'
  2767.         );
  2768.         //fin for{echo "<p style='color:red;font-weight:bold;'> ************* </br></br>*************</p>";
  2769.         foreach ($aConsonne as $consonne)
  2770.         {
  2771.             if (!in_array($consonne$aVoyelle))
  2772.             {
  2773.                 shuffle($aVoyelle);
  2774.                 shuffle($aConsonne);
  2775.                 $str1 $aConsonne[0$aVoyelle[0];
  2776.                 $arr1[$str1;
  2777.                 //
  2778.                 shuffle($arr1);
  2779.                 shuffle($aVoyelle);
  2780.                 shuffle($aConsonne);
  2781.                 $str2 $aConsonne[0$aVoyelle[0];
  2782.                 $arr2[$str2 $arr1[0];
  2783.                 //
  2784.                 shuffle($arr2);
  2785.                 $arr[$arr2[0];
  2786.                 $arr[$str1 $str2;
  2787.                 //
  2788.                 shuffle($arr2);
  2789.                 shuffle($aVoyelle);
  2790.                 shuffle($aConsonne);
  2791.                 $arr[$aVoyelle[0$arr2[0$aConsonne[0$aVoyelle[1];
  2792.                 //
  2793.                 shuffle($arr2);
  2794.                 shuffle($aConsonne);
  2795.                 shuffle($aVoyelle);
  2796.                 $arr[$aVoyelle[0$arr2[0$aConsonne[0$aVoyelle[1];
  2797.                 //
  2798.                 shuffle($aConsonne);
  2799.                 shuffle($aVoyelle);
  2800.                 $arr[$aVoyelle[0$aConsonne[1$aConsonne[0$aVoyelle[1];
  2801.                 //
  2802.                 shuffle($aConsonne);
  2803.                 shuffle($aVoyelle);
  2804.                 $arr[$aVoyelle[0$aConsonne[1$aConsonne[0$aVoyelle[1];
  2805.                 //
  2806.                 shuffle($arr);
  2807.                 //
  2808.                 if (!in_array($arr[0]$aBannerList))
  2809.                 {
  2810.                     //
  2811.                     return $arr[0];
  2812.                 //fin if
  2813.             }
  2814.             //
  2815.         }
  2816.     }
  2817.     //
  2818.         /**
  2819.      * @description crée un mot de passe temporaire pour promethée
  2820.      * @return string $pass de 4 caract maj et min
  2821.      */
  2822.     function mysql_generate_passWord($passLength 4)
  2823.     {
  2824.     
  2825.         $chiffres substr(str_shuffle('23456789')0$passLength 2);
  2826.         //        
  2827.         $lettres substr(str_shuffle('abcdefghjkmnpqrstuvwxyz')0$passLength 2);
  2828.         $pass str_shuffle($chiffres $lettres);
  2829.         return $pass;
  2830.     }
  2831.     //
  2832.         /**
  2833.      * @description récupère les libellés du module selon la langue choisie
  2834.      *  par défaut langue fr_FR
  2835.      */
  2836.     function getParamLang($lang)
  2837.     {
  2838.         //
  2839.         require_once 'Lang/Lang.php';
  2840.         //
  2841.         $aParamLang Lang :: getParam($lang);
  2842.         $this->aParamLang $aParamLang['Ldap2Mysql'];
  2843.         //
  2844.     }
  2845.     //
  2846.         /**
  2847.      * @description construit un select selon le type de base
  2848.      */
  2849.     function buildSelectListeBase($aoListeBase$aOption null$selected null)
  2850.     {
  2851.         //si aucune base n'est configurée
  2852.         $aData array (
  2853.             '' => $this->aParamLang['base']['noBase']
  2854.         );
  2855.         //
  2856.         if (isset ($aoListeBase))
  2857.         {
  2858.             //
  2859.             $aData null;
  2860.             foreach ($aoListeBase as $key => $propertieValue)
  2861.             {
  2862.                 //
  2863.                 if (isset ($propertieValue->nom->value))
  2864.                 {
  2865.                     //
  2866.                     if ($key == 'NoAuthentification')
  2867.                     {
  2868.                         $aData[$key$propertieValue->nom->value;
  2869.                     }
  2870.                     else
  2871.                     {
  2872.                         $aData[$keystrtoupper($propertieValue->type->value' &raquo;  ' $propertieValue->nom->value;
  2873.                     }
  2874.                 }
  2875.                 //
  2876.             }
  2877.             //
  2878.         }
  2879.         //
  2880.         if ($aOption == null)
  2881.         {
  2882.             $aOption array (
  2883.                 'onchange="javascript:submit();"'
  2884.             );
  2885.         }
  2886.         //
  2887.         $aContent[$this->formSelectComponent('select_listBase'$aData$aOption$selected);
  2888.         $aContent[$this->formInputComponent('submit''btn_validerSelect''OK'array (
  2889.             'class' => 'inputSubmit'
  2890.         ));
  2891.         //
  2892.         return implode("\n"$aContent);
  2893.     }
  2894.     //
  2895.         /**
  2896.      * @description construit le menu
  2897.      * @return string menu
  2898.      */
  2899.     function ldap_getLinks()
  2900.     {
  2901.         //
  2902.         $array array (
  2903.             'baseConfig' => $this->aParamLang['base']['lien_1'],
  2904.             'importConfig' => $this->aParamLang['base']['lien_2'],
  2905.             'import' => $this->aParamLang['base']['lien_3'],
  2906.             'consult' => $this->aParamLang['base']['lien_5'],
  2907.             'authConfig' => $this->aParamLang['base']['lien_4'],
  2908.             'manual' => 'Aide'
  2909.         );
  2910.         $tab explode('&'$_SERVER['QUERY_STRING']);
  2911.         $action $tab[0];
  2912.         //
  2913.         //en quittant l'ecran de l'import, on supprime le tableau  de sessions
  2914.         if ($action <> 'import')
  2915.         {
  2916.             if (isset ($_SESSION['Ldap2Mysql']['aoUser']))
  2917.             {
  2918.                 unset ($_SESSION['Ldap2Mysql']['aoUser']);
  2919.             }
  2920.         //fin if
  2921.         //
  2922.         //
  2923.         if (!in_array($actionarray_keys($array)))
  2924.         {
  2925.             $action 'baseConfig';
  2926.         //fin if
  2927.         //
  2928.         foreach ($array as $key => $value)
  2929.         {
  2930.             //
  2931.             if (isset ($actionAND $action == $key)
  2932.             {
  2933.                 $str '<li class="selected">' $value '</li>';
  2934.             }
  2935.             else
  2936.             {
  2937.                 $urlQueryString $key '&amp;item=23';
  2938.                 //
  2939.                 $str '<li><a href="?' $urlQueryString '" >' $value '</a></li>';
  2940.             }
  2941.             $aLien[$str;
  2942.         }
  2943.         //
  2944.         return '<ul  class="ldapMenu">' implode(''$aLien'</ul>';
  2945.         //
  2946.     }
  2947.     //
  2948.         function formInputComponent($type$elementName$value null$aOptions array ())
  2949.     {
  2950.         //text
  2951.         $attributs['text'array (
  2952.             'type' => 'text',
  2953.             'name' => 'name',
  2954.             'value' => null,
  2955.             'size' => 25
  2956.         );
  2957.         //bouton image
  2958.         $attributs['image'array (
  2959.             'type' => 'image',
  2960.             'name' => 'name',
  2961.             'src' => null,
  2962.             'title' => null,
  2963.             'alt' => null
  2964.         );
  2965.         //hidden
  2966.         $attributs['hidden'array (
  2967.             'type' => 'hidden',
  2968.             'name' => null,
  2969.             'value' => null
  2970.         );
  2971.         //submit
  2972.         $attributs['submit'array (
  2973.             'type' => 'submit',
  2974.             'name' => 'value'
  2975.         );
  2976.         //on construit  l'objet 
  2977.         $oComponent new stdClass();
  2978.         $oComponent->name $elementName;
  2979.         $oComponent->type $type;
  2980.         $oComponent->value $value;
  2981.         //
  2982.         if (in_array($oComponent->typearray_keys($attributs)))
  2983.         {
  2984.             foreach ($oComponent as $key => $value)
  2985.             {
  2986.                 //on complète le tableau si clé manquante
  2987.                 $attributs[$oComponent->type][$key$value;
  2988.             }
  2989.             //
  2990.             $sComponent '<input';
  2991.             foreach ($attributs[$oComponent->typeas $key => $value)
  2992.             {
  2993.                 $sComponent .= ' ' trim($key'="' trim($value'"';
  2994.             }
  2995.             //construction des attributs supplémentaires
  2996.             $sOptions '';
  2997.             if (!empty ($aOptions))
  2998.             {
  2999.                 foreach ($aOptions as $key => $value)
  3000.                 {
  3001.                     $sOptions .= ' ' trim($key'="' trim($value'" ';
  3002.                 }
  3003.             }
  3004.             $sComponent .= $sOptions ' />';
  3005.             //
  3006.             return $sComponent;
  3007.             //
  3008.         }
  3009.         else
  3010.         {
  3011.             echo 'le type du input demandé n\'existe pas !';
  3012.         }
  3013.         // 
  3014.     }
  3015.     //
  3016.         /**
  3017.      * @description initialise un  objet de champde formulaire
  3018.      * @return    object $oComponent
  3019.      */
  3020.     function formInitializeObject($sBaseType)
  3021.     {
  3022.         switch ($sBaseType)
  3023.         {
  3024.             //ldap
  3025.             case 'ldap' :
  3026.                 $aBase array (
  3027.                     'id',
  3028.                     'type',
  3029.                     'nom',
  3030.                     'host',
  3031.                     'port',
  3032.                     'dn',
  3033.                     'ldap_user_id_field',
  3034.                     'login_field',
  3035.                     'login',
  3036.                     'pass'
  3037.                 );
  3038.                 break;
  3039.                 //ldap
  3040.             case 'mysql' :
  3041.                 $aBase array (
  3042.                     'id',
  3043.                     'type',
  3044.                     'nom',
  3045.                     'host',
  3046.                     'port',
  3047.                     'login',
  3048.                     'pass'
  3049.                 );
  3050.                 break;
  3051.                 //
  3052.             case 'cas' :
  3053.                 $aBase array (
  3054.                     'id',
  3055.                     'type',
  3056.                     'nom',
  3057.                     'host',
  3058.                     'port',
  3059.                     'path'
  3060.                 );
  3061.                 break;
  3062.                 // 
  3063.         }
  3064.         //on instancie un objet vide sans class
  3065.         //dont les propriétés seront des objets aussi
  3066.         $oBase new stdClass();
  3067.         foreach ($aBase as $propertie)
  3068.         {
  3069.             $oPropertie new stdClass();
  3070.             //
  3071.             $oPropertie->defaultValue null;
  3072.             $oPropertie->value null;
  3073.             $oPropertie->required true;
  3074.             $oPropertie->errorMessage $this->aParamLang['base']['errorMessage'];
  3075.             //
  3076.             $oBase-> $propertie $oPropertie;
  3077.         }
  3078.         //
  3079.         return $oBase;
  3080.     }
  3081.     //
  3082.         /**
  3083.      * @description fonction de construction d'un select
  3084.      * @param1 string <nom du select>
  3085.      * @param2 array de type associatif (les cles sont transformées en values)
  3086.      * @param3 array ajoute des fonctionnalités au select exemple du javascript, une classe etc
  3087.      * @return string 
  3088.      */
  3089.     function formSelectComponent($selectName$adata$aOption null$default null)
  3090.     {
  3091.         //
  3092.         $sOption '';
  3093.         //
  3094.         if (is_array($aOption))
  3095.         {
  3096.             $sOption implode(' '$aOption);
  3097.         }
  3098.         //
  3099.         $selected $default;
  3100.         if (isset ($defaultAND in_array($defaultarray_keys($adata)))
  3101.         {
  3102.             $selected $default;
  3103.         }
  3104.         elseif (!empty ($_POST[$selectName]))
  3105.         {
  3106.             $selected $_POST[$selectName];
  3107.         }
  3108.         //
  3109.         $select['<select   name="' $selectName '" ' $sOption '   >';
  3110.         //
  3111.         //on veut la première valuer qui s'affiche
  3112.         if ($default == 'freeze')
  3113.         {
  3114.             //$select[] = '<option value="">&nbsp;</option>';
  3115.         }
  3116.         else
  3117.         {
  3118.             $select['<option value="">&nbsp;</option>';
  3119.         }
  3120.         //
  3121.         if (!empty ($adata))
  3122.         {
  3123.             //
  3124.             foreach ($adata as $key => $value)
  3125.             {
  3126.                 if ($key == $selected)
  3127.                 {
  3128.                     $select['<option value="' $key '" selected="selected" >' $value '</option>';
  3129.                 }
  3130.                 else
  3131.                 {
  3132.                     $select['<option value="' $key '">' $value '</option>';
  3133.                 }
  3134.             }
  3135.             //
  3136.         }
  3137.         //
  3138.         $select['</select>';
  3139.         //
  3140.         return "\n" implode("\n"$select);
  3141.         //
  3142.     }
  3143.     //
  3144.         /**
  3145.      * @description récupère la liste des bases ldap et mysql
  3146.      */
  3147.     function getAllBases()
  3148.     {
  3149.         $aObjects $this->baseLoadList();
  3150.         //
  3151.         if (isset ($aObjects))
  3152.         {
  3153.             //initialisation
  3154.             $arr array (
  3155.                 'ldap' => '',
  3156.                 'mysql' => ''
  3157.             );
  3158.             //
  3159.             foreach ($aObjects as $key => $value)
  3160.             {
  3161.                 //
  3162.                 //
  3163.                 if (isset ($value->type->value))
  3164.                 {
  3165.                     if (in_array($value->type->valuearray_keys($arr)))
  3166.                     {
  3167.                         //
  3168.                         switch ($value->type->value)
  3169.                         {
  3170.                             //
  3171.                             case 'ldap' :
  3172.                                 //
  3173.                                 $arr['ldap'][$key$value->nom->value;
  3174.                                 //
  3175.                                 break;
  3176.                                 //
  3177.                             case 'mysql' :
  3178.                                 //
  3179.                                 $arr['mysql'][$key$value->nom->value;
  3180.                                 break;
  3181.                                 //
  3182.                         }
  3183.                     //fin if
  3184.                 //fin if
  3185.                 //
  3186.             //fin foreach
  3187.             return $arr;
  3188.         //fin if
  3189.     //fin function getAllBases()
  3190.     //
  3191.         /**
  3192.      * @description fonction ajoutant une propriété  ou modifiant une valeur d'une propriété dans la session au tableau des users
  3193.      *  $_SESSION['Ldap2Mysql']['aoUser'][$unique_id]['variable']
  3194.      */
  3195.     function set_variableSessionUser($unique_id$variable$value)
  3196.     {
  3197.         $_SESSION['Ldap2Mysql']['aoUser'][$unique_id][$variable$value;
  3198.     }
  3199.     //
  3200.         /**
  3201.      * @description supprime des variables de sessions dont on n'a plus besoin
  3202.      */
  3203.     function delete_var_session()
  3204.     {
  3205.         unset ($_SESSION['Ldap2Mysql']['aoUser']);
  3206.         unset ($_SESSION['Ldap2Mysql']['listFieldsToImport']);
  3207.         unset ($_SESSION['Ldap2Mysql']['ldap_ListFields']);
  3208.         unset ($_SESSION['Ldap2Mysql']['ldap_listFieldsToImport']);
  3209.         unset ($_SESSION['Ldap2Mysql']['mysql_ListFields']);
  3210.         unset ($_SESSION['Ldap2Mysql']['mysql_listFieldsToImport']);
  3211.         unset ($_SESSION['Ldap2Mysql']['mysql_detailedListFields']);
  3212.     }
  3213.     //
  3214.     //
  3215.         /**
  3216.      * @description fonction de création d'une chaine unique servant pour l'insertion dans la base pour éviter les doublons
  3217.      */
  3218.     function get_temporary_unique_id()
  3219.     {
  3220.         list ($usec$secexplode(' 'microtime());
  3221.         $time = (float) $sec ((float) $usec 100000);
  3222.         mt_srand($time);
  3223.         $unique_id md5(uniqid(mt_rand()1));
  3224.         return $unique_id;
  3225.     }
  3226.     function display_warning($messageWarning$NumeroLigne null)
  3227.     {
  3228.         $line str_repeat('-'strlen($messageWarning2);
  3229.         $warning '<span style="font-family: \'trebuchet MS\', arial, sans-serif;font-size: 0.7em;color: red;">';
  3230.         $warning .= $line ' <br/> ';
  3231.         $warning .= '  <span style="font-weight:bold;">Attention : </span><br/>';
  3232.         $warning .= $messageWarning '<br/>' $line ' <br/> ';
  3233.         $warning .= '</span>';
  3234.         //
  3235.         echo $warning;
  3236.         //
  3237.     }
  3238.     function run()
  3239.     {
  3240.         //
  3241.         $tab explode('&'$_SERVER['QUERY_STRING']);
  3242.         $action $tab[0];
  3243.         // 
  3244.         switch ($action)
  3245.         {
  3246.             // 
  3247.             case 'manual' :
  3248.                 $this->display($this->manual_view());
  3249.                 break;
  3250.                 // 
  3251.             case 'authConfig' :
  3252.                 $this->display($this->authModeConfig_controller());
  3253.                 break;
  3254.                 // 
  3255.             case 'import' :
  3256.                 $this->display($this->ldap_import_controller());
  3257.                 break;
  3258.                 // 
  3259.             case 'importConfig' :
  3260.                 //
  3261.                 $this->display($this->importConfig_controller());
  3262.                 break;
  3263.                 // 
  3264.             case 'baseConfig' :
  3265.                 $this->display($this->baseConfig_controller());
  3266.                 break;
  3267.                 // 
  3268.             case 'consult' :
  3269.                 $this->display($this->consult_controller());
  3270.                 break;
  3271.                 // 
  3272.             default :
  3273.                 $this->display($this->baseConfig_controller());
  3274.                 break;
  3275.         // fin switch
  3276.         //
  3277.     }
  3278.     //
  3279.         /**
  3280.      * @description remplit le div principal avec le contenu de chaque interface
  3281.      */
  3282.     function display($sControlPanel)
  3283.     {
  3284.         $aContent['<form id="Ldap2Mysql_form" action="' str_replace('&''&amp;'$_SERVER['REQUEST_URI']'" method="post">';
  3285.         $aContent['<div id="ldap2Mysql">';
  3286.         //
  3287.         $aContent['<div class="row">';
  3288.         $aContent[$this->ldap_getLinks();
  3289.         $aContent['</div>';
  3290.         //
  3291.         $aContent['<div class="row">&nbsp;</div>';
  3292.         //on récupère une chaine representant le panneau de chaque type de serveur
  3293.         $aContent[$sControlPanel;
  3294.         $aContent['<div class="row">&nbsp;</div>';
  3295.         $aContent['<hr class="ligneHorizontale" />';
  3296.         //
  3297.         $aContent['</div>';
  3298.         $aContent['</form>';
  3299.         //on créé le html de sortie avec un retour chariot pour chaque ligne
  3300.         echo implode("\n"$aContent);
  3301.     }
  3302. //fin classe Base
  3303. ?>

Documentation generated on Wed, 22 Nov 2006 11:41:10 +0100 by phpDocumentor 1.3.0RC6