array ( * 'possible_values' => array ( * '[LSformat de la valeur clé]' => '[LSformat du nom d'affichage]', * ... * 'OTHER_OBJECT' => array ( * 'object_type' => '[Type d'LSobject]', * 'display_name_format' => '[LSformat du nom d'affichage des LSobjects]', * 'value_attribute' => '[Nom de l'attribut clé]', * 'filter' => '[Filtre de recherche des LSobject]', * 'scope' => '[Scope de la recherche]', * 'basedn' => '[Basedn de la recherche]' * ) * ) * ), * * @author Benjamin Renard */ class LSattr_html_select_list extends LSattr_html{ var $LSformElement_type = 'select'; /** * Ajoute l'attribut au formualaire passer en paramètre * * @param[in] &$form LSform Le formulaire * @param[in] $idForm L'identifiant du formulaire * @param[in] $data Valeur du champs du formulaire * * @retval LSformElement L'element du formulaire ajouté */ function addToForm (&$form,$idForm,$data=NULL) { $possible_values=$this -> getPossibleValues(); $this -> config['text_possible_values'] = $possible_values; $element=parent::addToForm($form,$idForm,$data); if ($element) { // Mise en place de la regle de verification des donnees $form -> addRule($this -> name, 'inarray', array('msg'=> 'Valeur incorrect','params' => array('possible_values' => array_keys($possible_values))) ); } return $element; } /** * Retourne un tableau des valeurs possibles de la liste * * @author Benjamin Renard * * @retval array Tableau associatif des valeurs possible de la liste avec en clé * la valeur des balises option et en valeur ce qui sera affiché. */ function getPossibleValues() { $retInfos = array(); if (is_array($this -> config['html_options']['possible_values'])) { foreach($this -> config['html_options']['possible_values'] as $val_name => $val) { if($val_name==='OTHER_OBJECT') { if ((!isset($val['object_type'])) || (!isset($val['value_attribute']))) { LSerror :: addErrorCode('LSattr_html_select_list_01',$this -> name); break; } if (!LSsession :: loadLSclass('LSsearch')) { return; } $param=array( 'filter' => (isset($val['filter'])?$val['filter']:null), 'basedn' => (isset($val['basedn'])?$val['basedn']:null), 'scope' => (isset($val['scope'])?$val['scope']:null), 'displayFormat' => (isset($val['display_name_format'])?$val['display_name_format']:null), ); if ($val['value_attribute']!='dn') { $param['attributes'][] = $val['value_attribute']; } $LSsearch = new LSsearch($val['object_type'],'LSattr_html_select_list',$param,true); $LSsearch -> run(); if(($val['value_attribute']=='dn')||($val['value_attribute']=='%{dn}')) { $retInfos = $LSsearch -> listObjectsName(); } else { $list = $LSsearch -> getSearchEntries(); foreach($list as $entry) { $key = $entry -> get($val['value_attribute']); if(is_array($key)) { $key = $key[0]; } $retInfos[$key]=$entry -> displayName; } } } else { $val_name=$this->attribute->ldapObject->getFData($val_name); $val=$this->attribute->ldapObject->getFData(__($val)); $retInfos[$val_name]=$val; } } } if (!isset($this -> config['html_options']['sort']) || $this -> config['html_options']['sort']) { uasort($retInfos,array($this,'_sortTwoValues')); } return $retInfos; } /** * Function use with uasort to sort two values * * @param[in] $va string One value * @param[in] $vb string One value * * @retval int Value for uasort **/ private function _sortTwoValues(&$va,&$vb) { if (isset($this -> config['html_options']['sortDirection']) && $this -> config['html_options']['sortDirection']=='DESC') { $dir=-1; } else { $dir=1; } if ($va == $vb) return 0; $val = strcoll(strtolower($va), strtolower($vb)); return $val*$dir; } } /* * Error Codes */ LSerror :: defineError('LSattr_html_select_list_01', _("LSattr_html_select_list : Configuration data are missing to generate the select list of the attribute %{attr}.") ); ?>