Add and use helper methods to access configuration parameters

This commit is contained in:
Benjamin Renard 2019-03-11 22:21:25 +01:00
parent 6bd68d8d25
commit 80b747a0c5
30 changed files with 422 additions and 394 deletions

View file

@ -61,12 +61,7 @@ class LSattr_html {
* @retval string Le label de l'attribut. * @retval string Le label de l'attribut.
*/ */
function getLabel() { function getLabel() {
if ( $this -> config['label'] != '' ) { return __($this -> getConfig('label', $this -> name));
return __($this -> config['label']);
}
else {
return __($this -> name);
}
} }
/** /**
@ -83,7 +78,7 @@ class LSattr_html {
LSerror :: addErrorCode('LSattr_html_01',$this -> name); LSerror :: addErrorCode('LSattr_html_01',$this -> name);
return; return;
} }
$element=$form -> addElement($this -> LSformElement_type, $this -> name, $this -> config['label'],$this -> config, $this); $element=$form -> addElement($this -> LSformElement_type, $this -> name, $this -> getLabel(), $this -> config, $this);
if(!$element) { if(!$element) {
LSerror :: addErrorCode('LSform_06',$this -> name); LSerror :: addErrorCode('LSform_06',$this -> name);
return; return;
@ -116,6 +111,19 @@ class LSattr_html {
return $this -> attribute -> getDisplayValue(); return $this -> attribute -> getDisplayValue();
} }
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/
public function getConfig($param, $default=null, $cast=null) {
return LSconfig :: get($param, $default, $cast, $this -> config);
}
} }
/* /*

View file

@ -37,7 +37,7 @@ class LSattr_html_image extends LSattr_html {
* @retval LSformElement L'element du formulaire ajouté * @retval LSformElement L'element du formulaire ajouté
*/ */
function addToForm (&$form,$idForm,$data=NULL) { function addToForm (&$form,$idForm,$data=NULL) {
$element=$form -> addElement('image', $this -> name, $this -> config['label'],$this -> config, $this); $element=$form -> addElement('image', $this -> name, $this -> getLabel(), $this -> config, $this);
if(!$element) { if(!$element) {
LSerror :: addErrorCode('LSform_06',$this -> name); LSerror :: addErrorCode('LSform_06',$this -> name);
return; return;

View file

@ -76,9 +76,10 @@ class LSattr_html_maildir extends LSattr_html {
} }
public function deleteMaildirByFTP() { public function deleteMaildirByFTP() {
if ($this -> config['html_options']['archiveNameFormat']) { $archiveNameFormat = $this -> getConfig('html_options.archiveNameFormat');
if ($archiveNameFormat) {
LSdebug('LSformElement_maildir : archive'); LSdebug('LSformElement_maildir : archive');
$newname=getFData($this -> config['html_options']['archiveNameFormat'],$this -> _toDo['old']); $newname = getFData($archiveNameFormat, $this -> _toDo['old']);
if ($newname) { if ($newname) {
if (renameMaildirByFTP($this -> _toDo['old'],$newname)) { if (renameMaildirByFTP($this -> _toDo['old'],$newname)) {
LSsession :: addInfo(_("The mailbox has been archived successfully.")); LSsession :: addInfo(_("The mailbox has been archived successfully."));
@ -112,9 +113,10 @@ class LSattr_html_maildir extends LSattr_html {
$val = $this -> attribute -> getValue(); $val = $this -> attribute -> getValue();
$val=$val[0]; $val=$val[0];
} }
if ($this -> config['html_options']['remoteRootPathRegex']) { $remoteRootPathRegex = $this -> getConfig('html_options.remoteRootPathRegex');
if ($remoteRootPathRegex) {
if ( if (
preg_match($this -> config['html_options']['remoteRootPathRegex'],$val,$r) preg_match($remoteRootPathRegex, $val, $r)
|| ||
empty($val) empty($val)
) )

View file

@ -37,7 +37,7 @@ class LSattr_html_password extends LSattr_html {
* @retval LSformElement L'element du formulaire ajouté * @retval LSformElement L'element du formulaire ajouté
*/ */
function addToForm (&$form,$idForm,$data=NULL) { function addToForm (&$form,$idForm,$data=NULL) {
$element=$form -> addElement('password', $this -> name, $this -> config['label'], $this -> config, $this); $element=$form -> addElement('password', $this -> name, $this -> getLabel(), $this -> config, $this);
if(!$element) { if(!$element) {
LSerror :: addErrorCode('LSform_06',$this -> name); LSerror :: addErrorCode('LSform_06',$this -> name);
return; return;

View file

@ -82,7 +82,7 @@ class LSattr_html_select_list extends LSattr_html{
if (!$name) $name=$this -> name; if (!$name) $name=$this -> name;
if (!$ldapObject) $ldapObject=$this->attribute->ldapObject; if (!$ldapObject) $ldapObject=$this->attribute->ldapObject;
$retInfos = array(); $retInfos = array();
if (is_array($options['possible_values'])) { if (isset($options['possible_values']) && is_array($options['possible_values'])) {
foreach($options['possible_values'] as $val_key => $val_label) { foreach($options['possible_values'] as $val_key => $val_label) {
if($val_key==='OTHER_OBJECT') { if($val_key==='OTHER_OBJECT') {
$objInfos=self :: getLSobjectPossibleValues($val_label,$options,$name); $objInfos=self :: getLSobjectPossibleValues($val_label,$options,$name);

View file

@ -40,7 +40,7 @@ class LSattr_html_select_object extends LSattr_html{
*/ */
function addToForm (&$form,$idForm,$data=NULL) { function addToForm (&$form,$idForm,$data=NULL) {
$this -> config['attrObject'] = $this; $this -> config['attrObject'] = $this;
$element=$form -> addElement('select_object', $this -> name, $this -> config['label'],$this -> config,$this); $element=$form -> addElement('select_object', $this -> name, $this -> getLabel(), $this -> config, $this);
if(!$element) { if(!$element) {
LSerror :: addErrorCode('LSform_06',$this -> name); LSerror :: addErrorCode('LSform_06',$this -> name);
return; return;
@ -54,7 +54,7 @@ class LSattr_html_select_object extends LSattr_html{
$element -> setValue($values); $element -> setValue($values);
} }
} }
$element -> setSelectableObject($this -> config['html_options']['selectable_object']['object_type']); $element -> setSelectableObject($this -> getConfig('html_options.selectable_object.object_type'));
return $element; return $element;
} }
@ -82,41 +82,45 @@ class LSattr_html_select_object extends LSattr_html{
* @retval array Tableau des valeurs de l'attribut * @retval array Tableau des valeurs de l'attribut
*/ */
function getValuesFromFormValues($values=NULL) { function getValuesFromFormValues($values=NULL) {
$retValues = array(); $conf = $this -> getConfig('html_options.selectable_object');
if (isset($this -> config['html_options']['selectable_object'])) { if (is_array($conf) && is_array($values)) {
$conf=$this -> config['html_options']['selectable_object']; $retValues = array();
if (!isset($conf['object_type'])) { if (!isset($conf['object_type'])) {
LSerror :: addErrorCode('LSattr_html_select_object_01',$this -> name); LSerror :: addErrorCode('LSattr_html_select_object_01',$this -> name);
return; return;
} }
if (!isset($conf['value_attribute'])) {
LSerror :: addErrorCode('LSattr_html_select_object_02',$this -> name);
return;
}
if (!LSsession :: loadLSobject($conf['object_type'])) { if (!LSsession :: loadLSobject($conf['object_type'])) {
return; return;
} }
if (is_array($values)) { $obj=new $conf['object_type']();
$obj=new $conf['object_type'](); foreach($values as $dn => $name) {
foreach($values as $dn => $name) { if ($obj -> loadData($dn)) {
if ($obj -> loadData($dn)) { $val = '';
if(($conf['value_attribute']=='dn')||($conf['value_attribute']=='%{dn}')) { if(($conf['value_attribute']=='dn')||($conf['value_attribute']=='%{dn}')) {
$val = $dn; $val = $dn;
} }
elseif (!isset($obj->attrs[$conf['value_attribute']])) { else {
if (!isset($obj->attrs[$conf['value_attribute']])) {
LSerror :: addErrorCode('LSattr_html_select_object_02',$this -> name); LSerror :: addErrorCode('LSattr_html_select_object_02',$this -> name);
return; return;
} }
else { $val = $obj -> getValue($conf['value_attribute']);
$val = $obj -> getValue($conf['value_attribute']); $val = $val[0];
$val = $val[0];
}
if (empty($val)) {
continue;
}
$retValues[]=$val;
} }
if (empty($val)) {
continue;
}
$retValues[] = $val;
} }
return $retValues;
} }
return $retValues;
} }
return; return;
} }
@ -132,64 +136,65 @@ class LSattr_html_select_object extends LSattr_html{
* @retval array Tableau associatif des objects selectionés avec en clé * @retval array Tableau associatif des objects selectionés avec en clé
* le DN et en valeur ce qui sera affiché. * le DN et en valeur ce qui sera affiché.
*/ */
function getFormValues($values=NULL,$fromDNs=false) { function getFormValues($values=NULL, $fromDNs=false) {
$retInfos = array(); $conf = $this -> getConfig('html_options.selectable_object');
$DNs=array(); if (is_array($conf) && is_array($values)) {
if (isset($this -> config['html_options']['selectable_object'])) {
$conf=$this -> config['html_options']['selectable_object'];
if (!isset($conf['object_type'])) { if (!isset($conf['object_type'])) {
LSerror :: addErrorCode('LSattr_html_select_object_01',$this -> name); LSerror :: addErrorCode('LSattr_html_select_object_01',$this -> name);
return; return;
} }
if (!isset($conf['value_attribute'])) {
LSerror :: addErrorCode('LSattr_html_select_object_02',$this -> name);
return;
}
if (!LSsession :: loadLSobject($conf['object_type'])) { if (!LSsession :: loadLSobject($conf['object_type'])) {
return; return;
} }
if (is_array($values)) { $retInfos = array();
$obj = new $conf['object_type'](); $DNs=array();
if(($conf['value_attribute']=='dn')||($conf['value_attribute']=='%{dn}')||$fromDNs) {
$DNs=$values; $obj = new $conf['object_type']();
foreach($DNs as $dn) { if(($conf['value_attribute']=='dn')||($conf['value_attribute']=='%{dn}')||$fromDNs) {
if($obj -> loadData($dn)) { $DNs=$values;
$retInfos[$dn] = $obj -> getDisplayName($conf['display_name_format']); foreach($DNs as $dn) {
} if($obj -> loadData($dn)) {
$retInfos[$dn] = $obj -> getDisplayName($conf['display_name_format']);
} }
} }
else {
if (!isset($conf['value_attribute']) || (!is_array(LSconfig::get('LSobjects.'.$conf['object_type'].'.attrs.'.$conf['value_attribute'])))) {
LSerror :: addErrorCode('LSattr_html_select_object_02',$this -> name);
return;
}
$unrecognizedValues=array();
foreach($values as $val) {
if (!empty($val)) {
$filter=Net_LDAP2_Filter::create($conf['value_attribute'],'equals',$val);
if (isset($conf['filter'])) $filter = LSldap::combineFilters('and',array($filter,$conf['filter']));
$sparams=array();
$sparams['onlyAccessible'] = (isset($conf['onlyAccessible'])?$conf['onlyAccessible']:False);
$listobj = $obj -> listObjectsName($filter,NULL,$sparams,$conf['display_name_format']);
if (count($listobj)==1) {
foreach($listobj as $dn => $name) {
$DNs[]=$dn;
$retInfos[$dn] = $name;
}
}
else {
$unrecognizedValues[]=$val;
if(count($listobj)>1) {
LSerror :: addErrorCode('LSattr_html_select_object_03',array('val' => $val, 'attribute' => $this -> name));
}
}
}
}
$this -> unrecognizedValues=$unrecognizedValues;
}
} }
else { else {
return false; if (!is_array(LSconfig::get('LSobjects.'.$conf['object_type'].'.attrs.'.$conf['value_attribute']))) {
LSerror :: addErrorCode('LSattr_html_select_object_02', $this -> name);
return;
}
$unrecognizedValues=array();
foreach($values as $val) {
if (!empty($val)) {
$filter=Net_LDAP2_Filter::create($conf['value_attribute'],'equals',$val);
if (isset($conf['filter'])) $filter = LSldap::combineFilters('and',array($filter,$conf['filter']));
$sparams=array();
$sparams['onlyAccessible'] = (isset($conf['onlyAccessible'])?$conf['onlyAccessible']:False);
$listobj = $obj -> listObjectsName($filter, NULL, $sparams, (isset($conf['display_name_format'])?$conf['display_name_format']:false));
if (count($listobj)==1) {
foreach($listobj as $dn => $name) {
$DNs[]=$dn;
$retInfos[$dn] = $name;
}
}
else {
$unrecognizedValues[]=$val;
if(count($listobj)>1) {
LSerror :: addErrorCode('LSattr_html_select_object_03',array('val' => $val, 'attribute' => $this -> name));
}
}
}
}
$this -> unrecognizedValues=$unrecognizedValues;
} }
$_SESSION['LSselect'][$conf['object_type']]=$DNs; $_SESSION['LSselect'][$conf['object_type']] = $DNs;
return $retInfos; return $retInfos;
} }
return false; return false;
@ -205,8 +210,9 @@ class LSattr_html_select_object extends LSattr_html{
* le DN et en valeur ce qui sera affiché. * le DN et en valeur ce qui sera affiché.
*/ */
function getValuesFromSession() { function getValuesFromSession() {
if(is_array($_SESSION['LSselect'][$this -> config['html_options']['selectable_object']['object_type']])) { $obj_type = $this -> getConfig('html_options.selectable_object.object_type');
return $this -> getFormValues($_SESSION['LSselect'][$this -> config['html_options']['selectable_object']['object_type']],true); if ( $obj_type && is_array($_SESSION['LSselect'][$obj_type]) ) {
return $this -> getFormValues($_SESSION['LSselect'][$obj_type], true);
} }
return false; return false;
} }

View file

@ -88,6 +88,19 @@ class LSattr_ldap {
} }
return; return;
} }
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/
public function getConfig($param, $default=null, $cast=null) {
return LSconfig :: get($param, $default, $cast, $this -> config);
}
} }
?>

View file

@ -97,12 +97,7 @@ class LSattr_ldap_boolean extends LSattr_ldap {
* @retval string The True value * @retval string The True value
**/ **/
function getTrue() { function getTrue() {
if (isset($this -> config['ldap_options']['true_value'])) { return $this -> getConfig('ldap_options.true_value', 'TRUE', 'string');
return $this -> config['ldap_options']['true_value'];
}
else {
return 'TRUE';
}
} }
/** /**
@ -111,13 +106,9 @@ class LSattr_ldap_boolean extends LSattr_ldap {
* @retval string The False value * @retval string The False value
**/ **/
function getFalse() { function getFalse() {
if (isset($this -> config['ldap_options']['false_value'])) { return $this -> getConfig('ldap_options.false_value', 'FALSE', 'string');
return $this -> config['ldap_options']['false_value'];
}
else {
return 'FALSE';
}
} }
} }
?> ?>

View file

@ -37,7 +37,7 @@ class LSattr_ldap_date extends LSattr_ldap {
if(!is_array($data)) { if(!is_array($data)) {
$data=array($data); $data=array($data);
} }
if ($this -> config['ldap_options']['timestamp']==1) { if ($this -> getConfig('ldap_options.timestamp', false, 'bool')) {
return $data; return $data;
} }
$retval=array(); $retval=array();
@ -58,7 +58,7 @@ class LSattr_ldap_date extends LSattr_ldap {
* @retval mixed La valeur traitée de l'attribut * @retval mixed La valeur traitée de l'attribut
*/ */
function getUpdateData($data) { function getUpdateData($data) {
if ($this -> config['ldap_options']['timestamp']==1) { if ($this -> getConfig('ldap_options.timestamp', false, 'bool')) {
return $data; return $data;
} }
$retval=array(); $retval=array();
@ -76,13 +76,9 @@ class LSattr_ldap_date extends LSattr_ldap {
* @retval string Le format de la date * @retval string Le format de la date
**/ **/
function getFormat() { function getFormat() {
if (isset($this -> config['ldap_options']['format'])) { return $this -> getConfig('ldap_options.format', '%Y%m%d%H%M%SZ');
return $this -> config['ldap_options']['format'];
}
else {
return "%Y%m%d%H%M%SZ";
}
} }
} }
?> ?>

View file

@ -36,11 +36,13 @@ class LSattr_ldap_password extends LSattr_ldap {
* @retval mixed The display value of this attribute * @retval mixed The display value of this attribute
*/ */
function getDisplayValue($data) { function getDisplayValue($data) {
if ($this -> config['ldap_options']['displayClearValue']) { if ($this -> getConfig('ldap_options.displayClearValue', false, 'bool')) {
if (is_array($data)) { if (is_array($data)) {
$ret=array(); $ret=array();
$wildcardPassword = $this -> getConfig('ldap_options.wildcardPassword');
$encodedWildcardPassword = $this -> getConfig('ldap_options.encodedWildcardPassword');
foreach($data as $p) { foreach($data as $p) {
if ($p==$this -> config['ldap_options']['wildcardPassword'] || $p==$this -> config['ldap_options']['encodedWildcardPassword']) { if ($p == $wildcardPassword || $p == $encodedWildcardPassword) {
continue; continue;
} }
$ret[]=$p; $ret[]=$p;
@ -73,24 +75,26 @@ class LSattr_ldap_password extends LSattr_ldap {
$data[]=$this -> encodePassword($this -> clearPassword); $data[]=$this -> encodePassword($this -> clearPassword);
// Wildcard Password // Wildcard Password
if (isset($this -> config['ldap_options']['wildcardPassword'])) { $wildcardPassword = $this -> getConfig('ldap_options.wildcardPassword');
if(!is_array($this -> config['ldap_options']['wildcardPassword'])) { if ($wildcardPassword) {
$data[]=$this -> encodePassword($this -> config['ldap_options']['wildcardPassword']); if (!is_array($wildcardPassword)) {
$data[] = $this -> encodePassword($wildcardPassword);
} }
else { else {
foreach($this -> config['ldap_options']['wildcardPassword'] as $pwd) { foreach($wildcardPassword as $pwd) {
$data[]=$this -> encodePassword($pwd); $data[] = $this -> encodePassword($pwd);
} }
} }
} }
// Wildcard Password already encoded // Wildcard Password already encoded
if (isset($this -> config['ldap_options']['encodedWildcardPassword'])) { $encodedWildcardPassword = $this -> getConfig('ldap_options.encodedWildcardPassword');
if(!is_array($this -> config['ldap_options']['encodedWildcardPassword'])) { if ($encodedWildcardPassword) {
$data[]=$this -> config['ldap_options']['encodedWildcardPassword']; if (!is_array($encodedWildcardPassword)) {
$data[] = $encodedWildcardPassword;
} }
else { else {
$data=array_merge($data,$this -> config['ldap_options']['encodedWildcardPassword']); $data = array_merge($data, $encodedWildcardPassword);
} }
} }
@ -108,21 +112,21 @@ class LSattr_ldap_password extends LSattr_ldap {
* @retval strinf The encode password * @retval strinf The encode password
*/ */
function encodePassword($clearPassword) { function encodePassword($clearPassword) {
if (isset($this -> config['ldap_options']['encode_function']) || $this -> config['ldap_options']['encode']=='function') { $encode = $this -> getConfig('ldap_options.encode', 'md5crypt', 'string');
if (!is_callable($this -> config['ldap_options']['encode_function'])) { $encode_function = $this -> getConfig('ldap_options.encode_function');
$this -> config['ldap_options']['encode'] = 'clear'; if ($encode_function || $encode == 'function') {
LSerror :: addErrorCode('LSattr_ldap_password_02',$this -> config['ldap_options']['encode_function']); if ( (!$encode_function) || (!is_callable($encode_function)) ) {
$encode = 'clear';
$encode_function = null;
LSerror :: addErrorCode('LSattr_ldap_password_02', ($encode_function?$encode_function:__('undefined')));
} }
else { else {
$this -> config['ldap_options']['encode'] = 'function'; $encode = 'function';
} }
} }
elseif (!$this -> config['ldap_options']['encode']) { switch($encode) {
$this -> config['ldap_options']['encode'] = 'md5crypt';
}
switch($this -> config['ldap_options']['encode']) {
case 'crypt': case 'crypt':
if ($this -> config['ldap_options']['no_random_crypt_salt']) { if ($this -> getConfig('ldap_options.no_random_crypt_salt')) {
return '{CRYPT}' . crypt($clearPassword,substr($clearPassword,0,2)); return '{CRYPT}' . crypt($clearPassword,substr($clearPassword,0,2));
} }
else { else {
@ -157,7 +161,7 @@ class LSattr_ldap_password extends LSattr_ldap {
break; break;
case 'sha256': case 'sha256':
case 'sha512': case 'sha512':
switch($this -> config['ldap_options']['encode']) { switch($encode) {
case 'sha256': case 'sha256':
$mhash_type = MHASH_SHA256; $mhash_type = MHASH_SHA256;
break; break;
@ -166,15 +170,15 @@ class LSattr_ldap_password extends LSattr_ldap {
break; break;
} }
if( function_exists( 'mhash' ) ) { if( function_exists( 'mhash' ) ) {
return '{'.strtoupper($this -> config['ldap_options']['encode']).'}' . base64_encode( mhash( $mhash_type, $clearPassword ) ); return '{'.strtoupper($encode).'}' . base64_encode( mhash( $mhash_type, $clearPassword ) );
} else { } else {
LSerror :: addErrorCode('LSattr_ldap_password_01', $this -> config['ldap_options']['encode']); LSerror :: addErrorCode('LSattr_ldap_password_01', $encode);
} }
break; break;
case 'ssha': case 'ssha':
case 'ssha256': case 'ssha256':
case 'ssha512': case 'ssha512':
switch($this -> config['ldap_options']['encode']) { switch($encode) {
case 'ssha': case 'ssha':
$mhash_type = MHASH_SHA1; $mhash_type = MHASH_SHA1;
break; break;
@ -188,10 +192,10 @@ class LSattr_ldap_password extends LSattr_ldap {
if( function_exists( 'mhash' ) && function_exists( 'mhash_keygen_s2k' ) ) { if( function_exists( 'mhash' ) && function_exists( 'mhash_keygen_s2k' ) ) {
mt_srand( (double) microtime() * 1000000 ); mt_srand( (double) microtime() * 1000000 );
$salt = mhash_keygen_s2k( $mhash_type, $clearPassword, substr( pack( "h*", md5( mt_rand() ) ), 0, 8 ), 4 ); $salt = mhash_keygen_s2k( $mhash_type, $clearPassword, substr( pack( "h*", md5( mt_rand() ) ), 0, 8 ), 4 );
return "{".strtoupper($this -> config['ldap_options']['encode'])."}".base64_encode( mhash( $mhash_type, $clearPassword.$salt ).$salt ); return "{".strtoupper($encode)."}".base64_encode( mhash( $mhash_type, $clearPassword.$salt ).$salt );
} }
else { else {
LSerror :: addErrorCode('LSattr_ldap_password_01', $this -> config['ldap_options']['encode']); LSerror :: addErrorCode('LSattr_ldap_password_01', $encode);
} }
break; break;
case 'smd5': case 'smd5':
@ -219,10 +223,10 @@ class LSattr_ldap_password extends LSattr_ldap {
return $clearPassword; return $clearPassword;
break; break;
case 'function': case 'function':
return call_user_func_array($this -> config['ldap_options']['encode_function'], array(&$this -> attribute -> ldapObject, $clearPassword)); return call_user_func_array($encode_function, array(&$this -> attribute -> ldapObject, $clearPassword));
break; break;
} }
LSerror :: addErrorCode('LSattr_ldap_password_01',$this -> config['ldap_options']['encode']); LSerror :: addErrorCode('LSattr_ldap_password_01', $encode);
return $clearPassword; return $clearPassword;
} }

View file

@ -179,29 +179,21 @@ class LSattribute {
$data = $this -> ldap -> getDisplayValue($this -> data); $data = $this -> ldap -> getDisplayValue($this -> data);
} }
if (isset($this -> config['onDisplay'])) { $onDisplay = $this -> getConfig('onDisplay');
if (is_array($this -> config['onDisplay'])) { if ($onDisplay) {
$result=$data; if (!is_array($onDisplay))
foreach($this -> config['onDisplay'] as $func) { $onDisplay = array($onDisplay);
if (function_exists($func)) { $result = $data;
$result=call_user_func($func, $result); foreach($onDisplay as $func) {
} if (function_exists($func)) {
else { $result = call_user_func($func, $result);
LSerror :: addErrorCode('LSattribute_02',array('attr' => $this->name,'func' => $func));
return;
}
}
return $result;
}
else {
if (function_exists($this -> config['onDisplay'])) {
return $this -> config['onDisplay']($data);
} }
else { else {
LSerror :: addErrorCode('LSattribute_02',array('attr' => $this->name,'func' => $this -> config['onDisplay'])); LSerror :: addErrorCode('LSattribute_02', array('attr' => $this->name, 'func' => $func));
return; return;
} }
} }
return $result;
} }
return $data; return $data;
} }
@ -222,7 +214,7 @@ class LSattribute {
* @retval boolean true si l'ajout a fonctionner ou qu'il n'est pas nécessaire, false sinon * @retval boolean true si l'ajout a fonctionner ou qu'il n'est pas nécessaire, false sinon
*/ */
function addToForm(&$form,$idForm,&$obj=NULL,$value=NULL) { function addToForm(&$form,$idForm,&$obj=NULL,$value=NULL) {
if(isset($this -> config['form'][$idForm])) { if($this -> getConfig("form.$idForm")) {
if (!$this -> html) { if (!$this -> html) {
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name)); LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
return; return;
@ -234,13 +226,13 @@ class LSattribute {
$data = $value; $data = $value;
} }
else if($this -> data !='') { else if($this -> data !='') {
$data=$this -> getFormVal(); $data = $this -> getFormVal();
} }
else if (isset($this -> config['default_value'])) { else if ($this -> getConfig('default_value')) {
$data=$obj -> getFData($this -> config['default_value']); $data = $obj -> getFData($this -> getConfig('default_value'));
} }
else { else {
$data=NULL; $data = NULL;
} }
$element = $this -> html -> addToForm($form,$idForm,$data); $element = $this -> html -> addToForm($form,$idForm,$data);
@ -248,35 +240,34 @@ class LSattribute {
LSerror :: addErrorCode('LSform_06',$this -> name); LSerror :: addErrorCode('LSform_06',$this -> name);
} }
if(isset($this -> config['required']) && $this -> config['required']==1) { if($this -> getConfig('required')) {
$form -> setRequired($this -> name); $form -> setRequired($this -> name);
} }
if (($this -> config['form'][$idForm]==0) || ($this -> myRights() == 'r')) { if ( ($this -> getConfig("form.$idForm")==0) || ($this -> myRights() == 'r') ) {
$element -> freeze(); $element -> freeze();
} }
else { else {
if(isset($this -> config['check_data'])) { $check_data = $this -> getConfig('check_data', array());
if(is_array($this -> config['check_data'])) { if(is_array($check_data)) {
foreach ($this -> config['check_data'] as $rule => $rule_infos) { foreach ($check_data as $rule => $rule_infos) {
if((!$form -> isRuleRegistered($rule))&&($rule!='')) { if((!$form -> isRuleRegistered($rule))&&($rule!='')) {
LSerror :: addErrorCode('LSattribute_03',array('attr' => $this->name,'rule' => $rule)); LSerror :: addErrorCode('LSattribute_03',array('attr' => $this->name,'rule' => $rule));
return; return;
}
if(!isset($rule_infos['msg'])) {
$rule_infos['msg']=getFData(_('The value of field %{label} is invalid.'),$this -> getLabel());
}
else {
$rule_infos['msg']=__($rule_infos['msg']);
}
if(!isset($rule_infos['params']))
$rule_infos['params']=NULL;
$form -> addRule($this -> name,$rule,array('msg' => $rule_infos['msg'], 'params' => $rule_infos['params']));
} }
if(!isset($rule_infos['msg'])) {
$rule_infos['msg']=getFData(_('The value of field %{label} is invalid.'),$this -> getLabel());
}
else {
$rule_infos['msg']=__($rule_infos['msg']);
}
if(!isset($rule_infos['params']))
$rule_infos['params']=NULL;
$form -> addRule($this -> name,$rule,array('msg' => $rule_infos['msg'], 'params' => $rule_infos['params']));
} }
else { }
LSerror :: addErrorCode('LSattribute_04',$this->name); else {
} LSerror :: addErrorCode('LSattribute_04',$this->name);
} }
} }
} }
@ -296,29 +287,10 @@ class LSattribute {
$return='n'; $return='n';
$whoami = $this -> ldapObject -> whoami(); $whoami = $this -> ldapObject -> whoami();
foreach($whoami as $who) { foreach($whoami as $who) {
switch ($who) { $right = $this -> getConfig("rights.$who", ($who=='admin'?'r':null));
case 'admin': if (in_array($right, array('r', 'w'))) {
if($this -> config['rights']['admin']=='w') { $return = $right;
$return='w'; if ($return == 'w') break;
break;
}
else {
$return='r';
}
break;
default:
if (!isset($this -> config['rights'][$who])) break;
if ($this -> config['rights'][$who] == 'w') {
$return='w';
break;
}
else if($this -> config['rights'][$who] == 'r') {
$return='r';
}
break;
}
if ($return=='w') {
break;
} }
} }
$this -> _myRights = $return; $this -> _myRights = $return;
@ -337,7 +309,7 @@ class LSattribute {
* @retval boolean true si l'ajout a fonctionner ou qu'il n'est pas nécessaire, false sinon * @retval boolean true si l'ajout a fonctionner ou qu'il n'est pas nécessaire, false sinon
*/ */
function addToView(&$form) { function addToView(&$form) {
if((isset($this -> config['view'])) && ($this -> config['view']) && ($this -> myRights() != 'n') ) { if ($this -> getConfig('view', false, 'bool') && ($this -> myRights() != 'n') ) {
if (!$this -> html) { if (!$this -> html) {
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name)); LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
return; return;
@ -370,7 +342,7 @@ class LSattribute {
* @retval boolean true si la valeur a été rafraichie ou que ce n'est pas nécessaire, false sinon * @retval boolean true si la valeur a été rafraichie ou que ce n'est pas nécessaire, false sinon
*/ */
function refreshForm(&$form,$idForm) { function refreshForm(&$form,$idForm) {
if(isset($this -> config['form'][$idForm])&&($this -> myRights()!='n')) { if ($this -> getConfig("form.$idForm") && ($this -> myRights() != 'n')) {
if (!$this -> html) { if (!$this -> html) {
LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name)); LSerror :: addErrorCode('LSattribute_09',array('type' => 'html','name' => $this -> name));
return; return;
@ -461,7 +433,7 @@ class LSattribute {
* @retval boolean true si l'attribut est obligatoire, false sinon * @retval boolean true si l'attribut est obligatoire, false sinon
*/ */
function isRequired() { function isRequired() {
return (isset($this -> config['required'])?(bool)$this -> config['required']:false); return $this -> getConfig('required', false, 'bool');
} }
/** /**
@ -472,15 +444,14 @@ class LSattribute {
* @retval boolean true si la valeur de l'attribut peut être générée, false sinon * @retval boolean true si la valeur de l'attribut peut être générée, false sinon
*/ */
function canBeGenerated() { function canBeGenerated() {
$format = $this -> getConfig('generate_value_format', $this -> getConfig('default_value'));
return ( return (
(function_exists($this -> config['generate_function'])) (function_exists($this -> getConfig('generate_function')))
||
(isset($this -> config['generate_value_format']))
|| ||
( (
(is_string($this -> config['default_value'])) (is_string($format))
&& &&
(strlen($this -> config['default_value'])>0) (strlen($format) > 0)
) )
); );
} }
@ -493,17 +464,16 @@ class LSattribute {
* @retval boolean true si la valeur à put être générée, false sinon * @retval boolean true si la valeur à put être générée, false sinon
*/ */
function generateValue() { function generateValue() {
$value=false; $value = false;
if (function_exists($this -> config['generate_function'])) { $generate_function = $this -> getConfig('generate_function');
$value=call_user_func_array($this -> config['generate_function'],array(&$this -> ldapObject)); $format = $this -> getConfig('generate_value_format', $this -> getConfig('default_value'));
if ($generate_function && function_exists($generate_function)) {
$value = call_user_func_array($generate_function, array(&$this -> ldapObject));
} }
else if (isset($this -> config['generate_value_format'])) { else if ($format) {
$value = $this -> ldapObject -> getFData($this -> config['generate_value_format']); $value = $this -> ldapObject -> getFData($format);
} }
else if (is_string($this -> config['default_value']) && strlen($this -> config['default_value'])>0) { if ($value !== false) {
$value = $this -> ldapObject -> getFData($this -> config['default_value']);
}
if ($value!==false) {
if (!empty($value)) { if (!empty($value)) {
if (!is_array($value)) { if (!is_array($value)) {
$value=array($value); $value=array($value);
@ -722,6 +692,19 @@ class LSattribute {
return $return; return $return;
} }
/**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/
public function getConfig($param, $default=null, $cast=null) {
return LSconfig :: get($param, $default, $cast, $this -> config);
}
} }
/** /**

View file

@ -60,17 +60,31 @@ class LSconfig {
* *
* @retval mixed La valeur de la variable, ou false si son nom n'est parsable * @retval mixed La valeur de la variable, ou false si son nom n'est parsable
**/ **/
public static function get($var) { public static function get($var, $default=null, $cast=null, $data=null) {
$vars=explode('.',$var); $vars = explode('.', $var);
if(is_array($vars)) { $value = $default;
$data=self :: $data; if (is_array($vars)) {
$value = (is_array($data)?$data:self :: $data);
foreach ($vars as $v) { foreach ($vars as $v) {
if (!isset($data[$v])) return; if (!is_array($value) || !isset($value[$v])) {
$data=$data[$v]; $value = $default;
break;
}
$value = $value[$v];
} }
return $data;
} }
return; switch($cast) {
case 'bool':
return boolval($value);
case 'int':
return intval($value);
case 'float':
return floatval($value);
case 'string':
return strval($value);
default:
return $value;
}
} }
/** /**

View file

@ -189,16 +189,15 @@ class LSformElement {
$return['required']=true; $return['required']=true;
} }
$return['label'] = $this -> getLabel(); $return['label'] = $this -> getLabel();
$help_info = ""; $help_infos = array();
if ( (isset($this -> params['displayAttrName']) && $this -> params['displayAttrName']) || (isset($this -> attr_html -> attribute -> ldapObject -> config['displayAttrName']) && $this -> attr_html -> attribute -> ldapObject -> config['displayAttrName']) ) { if ( $this -> getParam('displayAttrName', $this -> attr_html -> attribute -> ldapObject -> getConfig('displayAttrName', false, 'bool'), 'bool') ) {
$help_info=_("Attribute")." : ".$this -> name."\n"; $help_infos[] = _("Attribute")." : ".$this -> name."\n";
} }
if (isset($this -> params['help_info'])) { if ($this -> getParam('help_info')) {
if (!empty($help_info)) $help_info .= " - "; $help_infos[] = __($this -> getParam('help_info'));
$help_info.=__($this -> params['help_info']);
} }
if (!empty($help_info)) if (!empty($help_infos))
$return['help_info'] = $help_info; $return['help_info'] = implode(' - ', $help_infos);
return $return; return $return;
} }
@ -246,12 +245,7 @@ class LSformElement {
if ($this -> label != "") { if ($this -> label != "") {
return __($this -> label); return __($this -> label);
} }
else if ($this -> params['label']) { return __($this -> getParam('label', $this -> name));
return __($this -> params['label']);
}
else {
return __($this -> name);
}
} }
/** /**
@ -260,7 +254,7 @@ class LSformElement {
* @retval boolean True si le champ est à valeur multiple, False sinon * @retval boolean True si le champ est à valeur multiple, False sinon
*/ */
function isMultiple() { function isMultiple() {
return ( (isset($this -> params['multiple']))?($this -> params['multiple'] == true):false ); return $this -> getParam('multiple', false, 'bool');
} }
/** /**
@ -286,7 +280,7 @@ class LSformElement {
'value' => '', 'value' => '',
'values' => $this -> values, 'values' => $this -> values,
'attr_name' => $this -> name, 'attr_name' => $this -> name,
'noValueTxt' => ( (isset($this -> params['no_value_label']))? __($this -> params['no_value_label']):_('No set value') ), 'noValueTxt' => __($this -> getParam('no_value_label', 'No set value', 'string')),
'fieldTemplate' => $this -> fieldTemplate, 'fieldTemplate' => $this -> fieldTemplate,
'fieldType' => get_class($this) 'fieldType' => get_class($this)
) )
@ -302,6 +296,19 @@ class LSformElement {
function getEmptyField() { function getEmptyField() {
return $this -> fetchTemplate($this -> fieldTemplate); return $this -> fetchTemplate($this -> fieldTemplate);
} }
/**
* Return a parameter (or default value)
*
* @param[] $param The parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The parameter value or default value if not set
**/
public function getParam($param, $default=null, $cast=null) {
return LSconfig :: get($param, $default, $cast, $this -> params);
}
} }
?> ?>

View file

@ -57,13 +57,11 @@ class LSformElement_boolean extends LSformElement {
$return['html'] = $this -> fetchTemplate( $return['html'] = $this -> fetchTemplate(
NULL, NULL,
array( array(
'yesTxt' => (isset($this -> params['html_options']['true_label']) && !empty($this -> params['html_options']['true_label']))?__($this -> params['html_options']['true_label']):_('Yes'), 'yesTxt' => __($this -> getParam('html_options.true_label', 'Yes')),
'noTxt' => (isset($this -> params['html_options']['false_label']) && !empty($this -> params['html_options']['false_label']))?__($this -> params['html_options']['false_label']):_('No'), 'noTxt' => __($this -> getParam('html_options.false_label', 'No')),
) )
); );
return $return; return $return;
} }
} }
?>

View file

@ -115,15 +115,7 @@ class LSformElement_date extends LSformElement {
* @retval string Le format de la date * @retval string Le format de la date
**/ **/
function getFormat() { function getFormat() {
if (isset($this -> params['html_options']['format'])) { return $this -> getParam('html_options.format', ($this -> getParam('html_options.time', true)?'%d/%m/%Y, %T':'%d/%m/%Y'));
return $this -> params['html_options']['format'];
}
else {
if (isset($this -> params['html_options']['time']) && !$this -> params['html_options']['time']) {
return '%d/%m/%Y';
}
return "%d/%m/%Y, %T";
}
} }
/** /**
@ -132,11 +124,12 @@ class LSformElement_date extends LSformElement {
* @retval string The date picker style * @retval string The date picker style
**/ **/
function getStyle() { function getStyle() {
if (isset($this -> params['html_options']['style'])) { $style = $this -> getParam('html_options.style', $this -> default_style, 'string');
if (is_dir(LS_LIB_DIR.'arian-mootools-datepicker/datepicker_'.strval($this -> params['html_options']['style']))) { if ($style) {
return $this -> params['html_options']['style']; if (is_dir(LS_LIB_DIR.'arian-mootools-datepicker/datepicker_'.$style)) {
return $style;
} }
LSdebug('LSformElement :: Date => unknown style parameter value '.strval($this -> params['html_options']['style'])); LSdebug('LSformElement :: Date => unknown style parameter value '.$style);
} }
return $this -> default_style; return $this -> default_style;
} }
@ -164,12 +157,12 @@ class LSformElement_date extends LSformElement {
$params = array( $params = array(
'format' => $this -> php2js_format($this -> getFormat()), 'format' => $this -> php2js_format($this -> getFormat()),
'style' => $this -> getStyle(), 'style' => $this -> getStyle(),
'time' => (isset($this -> params['html_options']['time'])?$this -> params['html_options']['time']:true), 'time' => $this -> getParam('html_options.time', true, 'bool'),
'manual' => (isset($this -> params['html_options']['manual'])?$this -> params['html_options']['manual']:true), 'manual' => $this -> getParam('html_options.manual', true, 'bool'),
'showNowButton' => (isset($this -> params['html_options']['showNowButton'])?$this -> params['html_options']['showNowButton']:true), 'showNowButton' => $this -> getParam('html_options.showNowButton', true, 'bool'),
'showTodayButton' => (isset($this -> params['html_options']['showTodayButton'])?$this -> params['html_options']['showTodayButton']:true), 'showTodayButton' => $this -> getParam('html_options.showTodayButton', true, 'bool'),
); );
LSsession :: addJSconfigParam($this -> name,$params); LSsession :: addJSconfigParam($this -> name, $params);
$codeLang = str_replace('_','-',preg_replace('/\..*$/','',LSsession :: getLang())); $codeLang = str_replace('_','-',preg_replace('/\..*$/','',LSsession :: getLang()));

View file

@ -37,9 +37,7 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
function LSformElement_jsonCompositeAttribute (&$form, $name, $label, $params,&$attr_html){ function LSformElement_jsonCompositeAttribute (&$form, $name, $label, $params,&$attr_html){
parent :: LSformElement($form, $name, $label, $params,$attr_html); parent :: LSformElement($form, $name, $label, $params,$attr_html);
if (is_array($this -> params['html_options']['components'])) { $this -> components = $this -> getParam('html_options.components', array());
$this -> components = $this -> params['html_options']['components'];
}
} }
/* /*

View file

@ -51,7 +51,7 @@ class LSformElement_labeledValue extends LSformElement {
$parseValues[]=$this -> parseValue($val); $parseValues[]=$this -> parseValue($val);
} }
$return['html'] = $this -> fetchTemplate(NULL,array( $return['html'] = $this -> fetchTemplate(NULL,array(
'labels' => $this -> params['html_options']['labels'], 'labels' => $this -> getParam('html_options.labels'),
'parseValues' => $parseValues, 'parseValues' => $parseValues,
'unrecognizedValueTxt' => __('(unrecognized value)'), 'unrecognizedValueTxt' => __('(unrecognized value)'),
'unrecognizedLabelTxt' => __('(unrecognized label)'), 'unrecognizedLabelTxt' => __('(unrecognized label)'),
@ -66,11 +66,10 @@ class LSformElement_labeledValue extends LSformElement {
*/ */
function getEmptyField() { function getEmptyField() {
return $this -> fetchTemplate($this -> fieldTemplate,array( return $this -> fetchTemplate($this -> fieldTemplate,array(
'labels' => $this -> params['html_options']['labels'], 'labels' => $this -> getParam('html_options.labels'),
)); ));
} }
/** /**
* Parse une valeur * Parse une valeur
* *
@ -82,8 +81,9 @@ class LSformElement_labeledValue extends LSformElement {
$ret=array('raw_value' => $value); $ret=array('raw_value' => $value);
if (preg_match('/^\[([^\]]*)\](.*)$/',$value,$m)) { if (preg_match('/^\[([^\]]*)\](.*)$/',$value,$m)) {
$ret['label'] = $m[1]; $ret['label'] = $m[1];
if (isset($this -> params['html_options']['labels'][$ret['label']])) $label = $this -> getParam('html_options.labels.'.$ret['label']);
$ret['translated_label'] = $this -> params['html_options']['labels'][$ret['label']]; if ($label)
$ret['translated_label'] = $label;
$ret['value'] = $m[2]; $ret['value'] = $m[2];
} }
return $ret; return $ret;

View file

@ -58,7 +58,7 @@ class LSformElement_mail extends LSformElement_text {
} }
function fetchTemplate($template=NULL,$variables=array()) { function fetchTemplate($template=NULL,$variables=array()) {
if (isset($this -> params['html_options']['disableMailSending']) && $this -> params['html_options']['disableMailSending']) { if ($this -> getParam('html_options.disableMailSending', false, 'bool')) {
$this -> fetchVariables['uriClass'] .= " LSformElement_mail_disableMailSending"; $this -> fetchVariables['uriClass'] .= " LSformElement_mail_disableMailSending";
} }
return parent :: fetchTemplate($template,$variables); return parent :: fetchTemplate($template,$variables);

View file

@ -114,12 +114,7 @@ class LSformElement_mailQuota extends LSformElement {
* @retval string Suffix value * @retval string Suffix value
**/ **/
function getSuffix() { function getSuffix() {
if(isset($this -> params['html_options']['suffix'])){ return $this -> getParam('html_options.suffix', 'S', 'string');
return strval($this -> params['html_options']['suffix']);
}
else {
return "S";
}
} }
/** /**

View file

@ -80,13 +80,13 @@ class LSformElement_password extends LSformElement {
LSdebug ('send by form'); LSdebug ('send by form');
} }
} }
else if (isset($this -> params['html_options']['mail']['isset']) && $this -> params['html_options']['mail']['send']==1) { else if ($this -> getParam('html_options.mail.send')) {
$this -> sendMail = true; $this -> sendMail = true;
LSdebug ('send by config'); LSdebug ('send by config');
} }
if ($this -> sendMail && LSsession :: loadLSaddon('mail')) { if ($this -> sendMail && LSsession :: loadLSaddon('mail')) {
$msg = $this -> params['html_options']['mail']['msg']; $msg = $this -> getParam('html_options.mail.msg');
$subject = $this -> params['html_options']['mail']['subject']; $subject = $this -> getParam('html_options.mail.subject');
if (isset($_POST['LSformElement_password_'.$this -> name.'_msg'])) { if (isset($_POST['LSformElement_password_'.$this -> name.'_msg'])) {
$msgInfos = json_decode($_POST['LSformElement_password_'.$this -> name.'_msg']); $msgInfos = json_decode($_POST['LSformElement_password_'.$this -> name.'_msg']);
if ($msgInfos -> subject) { if ($msgInfos -> subject) {
@ -122,7 +122,7 @@ class LSformElement_password extends LSformElement {
LSsession :: addCssFile('LSformElement_password.css'); LSsession :: addCssFile('LSformElement_password.css');
$return = $this -> getLabelInfos(); $return = $this -> getLabelInfos();
$pwd = ""; $pwd = "";
if ($this -> params['html_options']['clearView'] or $this -> params['html_options']['clearEdit']) { if ($this -> getParam('html_options.clearView') or $this -> getParam('html_options.clearEdit')) {
$pwd = $this -> values[0]; $pwd = $this -> values[0];
} }
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
@ -142,35 +142,43 @@ class LSformElement_password extends LSformElement {
) )
); );
if (($this -> params['html_options']['generationTool'])&&($this -> params['html_options']['autoGenerate'])&&(empty($this -> values))) { if ($this -> getParam('html_options.generationTool') && $this -> getParam('html_options.autoGenerate') && empty($this -> values)) {
$pwd=$this->generatePassword($this -> params); $pwd=$this->generatePassword($this -> params);
} }
$params = array( $params = array(
'generate' => ($this -> params['html_options']['generationTool']==True), 'generate' => $this -> getParam('html_options.generationTool', true, 'bool'),
'clearEdit' => ($this -> params['html_options']['clearEdit']==True), 'clearEdit' => $this -> getParam('html_options.clearEdit', false, 'bool'),
'viewHash' => ($this -> params['html_options']['viewHash']==True), 'viewHash' => $this -> getParam('html_options.viewHash', false, 'bool'),
'verify' => ( (!$this -> attr_html -> attribute -> ldapObject-> isNew()) && ( (isset($this -> params['html_options']['verify']) && $this -> params['html_options']['verify']) || (!isset($this -> params['html_options']['verify'])) ) ) 'verify' => ( (!$this -> attr_html -> attribute -> ldapObject-> isNew()) && $this -> getParam('html_options.verify', True, 'bool') )
); );
if (isset($this -> params['html_options']['mail'])) {
$params['mail'] = $this -> params['html_options']['mail']; if ($this -> getParam('html_options.mail')) {
$params['mail'] = $this -> getParam('html_options.mail');
$params['mail']['mail_attr'] = $this -> getMailAttrs(); $params['mail']['mail_attr'] = $this -> getMailAttrs();
} }
LSsession :: addJSconfigParam($this -> name,$params); LSsession :: addJSconfigParam($this -> name, $params);
LSsession :: addJSscript('LSformElement_password_field.js'); LSsession :: addJSscript('LSformElement_password_field.js');
LSsession :: addJSscript('LSformElement_password.js'); LSsession :: addJSscript('LSformElement_password.js');
} }
$return['html'] = $this -> fetchTemplate(NULL,array('pwd' => $pwd,'clearView' => $this -> params['html_options']['clearView'],'clearEdit' => $this -> params['html_options']['clearEdit'])); $return['html'] = $this -> fetchTemplate (
NULL,
array(
'pwd' => $pwd,
'clearView' => $this -> getParam('html_options.clearView'),
'clearEdit' => $this -> getParam('html_options.clearEdit'),
)
);
return $return; return $return;
} }
function generatePassword($params=NULL) { function generatePassword($params=NULL) {
if ($params['html_options']['use_pwgen']) { if (LSconfig :: get('html_options.use_pwgen', false, null, $params)) {
$args=(isset($params['html_options']['pwgen_opts'])?$params['html_options']['pwgen_opts']:''); $args = LSconfig :: get('html_options.pwgen_opts', '', 'string', $params);
$len=(isset($params['html_options']['lenght'])?$params['html_options']['lenght']:8); $len = LSconfig :: get('html_options.lenght', 8, 'int', $params);
$bin=(isset($params['html_options']['pwgen_path'])?$params['html_options']['pwgen_path']:'pwgen'); $bin = LSconfig :: get('html_options.pwgen_path', 'pwgen', 'string', $params);
$cmd="$bin ".escapeshellcmd($args)." $len 1"; $cmd = "$bin ".escapeshellcmd($args)." $len 1";
exec($cmd,$ret,$retcode); exec($cmd,$ret,$retcode);
LSdebug("Generate password using pwgen. Cmd : '$cmd' / Return code : $retcode / Return : ".print_r($ret,1)); LSdebug("Generate password using pwgen. Cmd : '$cmd' / Return code : $retcode / Return : ".print_r($ret,1));
if ($retcode==0 && count($ret)>0) { if ($retcode==0 && count($ret)>0) {
@ -180,7 +188,7 @@ class LSformElement_password extends LSformElement {
LSerror :: addErrorCode('LSformElement_password_03'); LSerror :: addErrorCode('LSformElement_password_03');
} }
} }
return generatePassword($params['html_options']['chars'],$params['html_options']['lenght']); return generatePassword(LSconfig :: get('html_options.chars', null, null, $params), LSconfig :: get('html_options.lenght', 8, 'int', $params));
} }
function verifyPassword($pwd) { function verifyPassword($pwd) {
@ -211,12 +219,13 @@ class LSformElement_password extends LSformElement {
} }
function getMailAttrs() { function getMailAttrs() {
if (!isset($this -> params['html_options']['mail']) || !is_array($this -> params['html_options']['mail'])) if (!$this -> getParam('html_options.mail'))
return False; return False;
if (isset($this -> params['html_options']['mail']['get_mail_attr_function'])) { if ($this -> getParam('html_options.mail.get_mail_attr_function')) {
if (is_callable($this -> params['html_options']['mail']['get_mail_attr_function'])) { $func = $this -> getParam('html_options.mail.get_mail_attr_function');
if (is_callable($func)) {
try { try {
return call_user_func_array($this -> params['html_options']['mail']['get_mail_attr_function'], array(&$this)); return call_user_func_array($func, array(&$this));
} }
catch(Exception $e) { catch(Exception $e) {
LSerror :: addErrorCode('LSformElement_password_05', $e->getMessage()); LSerror :: addErrorCode('LSformElement_password_05', $e->getMessage());
@ -227,9 +236,7 @@ class LSformElement_password extends LSformElement {
return False; return False;
} }
} }
elseif (isset($this -> params['html_options']['mail']['mail_attr'])) { return $this -> getParam('html_options.mail.mail_attr');
return $this -> params['html_options']['mail']['mail_attr'];
}
} }
function send($params) { function send($params) {
@ -266,15 +273,9 @@ class LSformElement_password extends LSformElement {
if (checkEmail($mail,NULL,true)) { if (checkEmail($mail,NULL,true)) {
$this -> attr_html -> attribute -> ldapObject -> registerOtherValue('password',$this -> sendMail['pwd']); $this -> attr_html -> attribute -> ldapObject -> registerOtherValue('password',$this -> sendMail['pwd']);
$msg = $this -> attr_html -> attribute -> ldapObject -> getFData($this -> sendMail['msg']); $msg = $this -> attr_html -> attribute -> ldapObject -> getFData($this -> sendMail['msg']);
if (isset($this -> params['html_options']['mail']['headers'])) { $headers = $this -> getParam('html_options.mail.headers', array());
$headers = $this -> params['html_options']['mail']['headers']; $bcc = $this -> getParam('html_options.mail.bcc');
} if ($bcc) $headers['Bcc'] = $bcc;
else {
$headers = array();
}
if ($this -> params['html_options']['mail']['bcc']) {
$headers['Bcc']=$this -> params['html_options']['mail']['bcc'];
}
if (sendMail( if (sendMail(
$mail, $mail,
$this -> sendMail['subject'], $this -> sendMail['subject'],
@ -349,10 +350,7 @@ class LSformElement_password extends LSformElement {
} }
public function isLoginPassword() { public function isLoginPassword() {
if (!isset($this -> params['html_options']['isLoginPassword']) || $this -> params['html_options']['isLoginPassword']) { return $this -> getParam('html_options.isLoginPassword', true);
return true;
}
return false;
} }
} }

View file

@ -43,23 +43,25 @@ class LSformElement_postaladdress extends LSformElement_textarea {
$return = parent :: getDisplay(); $return = parent :: getDisplay();
if ($this -> isFreeze()) { if ($this -> isFreeze()) {
if (!empty($this->values)) { if (!empty($this->values)) {
$map_url_format=(isset($this -> params['html_options']['map_url_format'])?$this -> params['html_options']['map_url_format']:'http://nominatim.openstreetmap.org/search.php?q=%{pattern}'); $map_url_format = $this -> getParam('html_options.map_url_format', 'http://nominatim.openstreetmap.org/search.php?q=%{pattern}', 'string');
if (isset($this -> params['html_options']['map_url_pattern_generate_function'])) { $map_url_pattern_generate_function = $this -> getParam('html_options.map_url_pattern_generate_function');
if (is_callable($this -> params['html_options']['map_url_pattern_generate_function'])) { $map_url_pattern_format = $this -> getParam('html_options.map_url_pattern_format');
$this -> attr_html -> attribute -> ldapObject -> registerOtherValue('pattern',call_user_func($this -> params['html_options']['map_url_pattern_generate_function'],$this)); if ($map_url_pattern_generate_function) {
if (is_callable($map_url_pattern_generate_function)) {
$this -> attr_html -> attribute -> ldapObject -> registerOtherValue('pattern', call_user_func($map_url_pattern_generate_function, $this));
} }
else { else {
LSerror::addErrorCode('LSformElement_postaladdress_01', $this -> params['html_options']['map_url_pattern_generate_function']); LSerror::addErrorCode('LSformElement_postaladdress_01', $map_url_pattern_generate_function);
} }
} }
elseif (isset($this -> params['html_options']['map_url_pattern_format'])) { elseif ($map_url_pattern_format) {
$pattern=$this -> attr_html -> attribute -> ldapObject -> getFData($this -> params['html_options']['map_url_pattern_format']); $pattern = $this -> attr_html -> attribute -> ldapObject -> getFData($map_url_pattern_format);
$pattern=str_replace("\n"," ",$pattern); $pattern = str_replace("\n"," ",$pattern);
$pattern=urlencode($pattern); $pattern = urlencode($pattern);
$this -> attr_html -> attribute -> ldapObject -> registerOtherValue('pattern',$pattern); $this -> attr_html -> attribute -> ldapObject -> registerOtherValue('pattern', $pattern);
} }
else { else {
$this -> attr_html -> attribute -> ldapObject -> registerOtherValue('pattern',LSformElement_postaladdress__generate_pattern($this)); $this -> attr_html -> attribute -> ldapObject -> registerOtherValue('pattern', LSformElement_postaladdress__generate_pattern($this));
} }
LSsession :: addJSconfigParam('LSformElement_postaladdress_'.$this -> name, array ( LSsession :: addJSconfigParam('LSformElement_postaladdress_'.$this -> name, array (
'map_url' => $this -> attr_html -> attribute -> ldapObject -> getFData($map_url_format) 'map_url' => $this -> attr_html -> attribute -> ldapObject -> getFData($map_url_format)

View file

@ -149,10 +149,7 @@ class LSformElement_quota extends LSformElement {
} }
private function getFactor() { private function getFactor() {
if (isset($this -> params['html_options']['factor'])) { return $this -> getParam('html_options.factor', 1);
return $this -> params['html_options']['factor'];
}
return 1;
} }
} }

View file

@ -73,8 +73,8 @@ class LSformElement_select extends LSformElement {
*/ */
public function isValidValue($value,$possible_values=False) { public function isValidValue($value,$possible_values=False) {
if (!is_array($possible_values)) { if (!is_array($possible_values)) {
if (isset($this) && is_a($this, __CLASS__) && is_array($this -> params['text_possible_values'])) { if (isset($this) && is_a($this, __CLASS__) && $this -> getParam('text_possible_values')) {
$possible_values=$this -> params['text_possible_values']; $possible_values = $this -> getParam('text_possible_values');
} }
else { else {
return False; return False;

View file

@ -47,7 +47,7 @@ class LSformElement_select_box extends LSformElement_select {
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
LSsession :: addCssFile('LSformElement_select_box.css'); LSsession :: addCssFile('LSformElement_select_box.css');
} }
$this -> fetchVariables['translate_labels'] = ((isset($this -> params['translate_labels']) && !$this -> params['translate_labels'])?false:true); $this -> fetchVariables['translate_labels'] = $this -> getParam('translate_labels', true);
return parent :: getDisplay(); return parent :: getDisplay();
} }

View file

@ -69,9 +69,9 @@ class LSformElement_select_object extends LSformElement {
'deleteBtns' => _('Delete'), 'deleteBtns' => _('Delete'),
'up_label' => _('Move up'), 'up_label' => _('Move up'),
'down_label' => _('Move down'), 'down_label' => _('Move down'),
'ordered' => (($this -> params['html_options']['ordered'])?1:0), 'ordered' => $this -> getParam('html_options.ordered', 0, 'int'),
'multiple' => (($this -> params['multiple'])?1:0), 'multiple' => $this -> getParam('multiple', 0, 'int'),
'filter64' => (($this -> params['html_options']['selectable_object']['filter'])?base64_encode($this -> params['html_options']['selectable_object']['filter']):''), 'filter64' => base64_encode($this -> getParam('html_options.selectable_object.filter', '', 'string')),
'noValueLabel' => _('No set value'), 'noValueLabel' => _('No set value'),
'noResultLabel' => _('No result') 'noResultLabel' => _('No result')
) )
@ -93,7 +93,7 @@ class LSformElement_select_object extends LSformElement {
} }
} }
if ((!isset($this -> params['html_options']['sort']) || $this -> params['html_options']['sort']) && !$this -> params['html_options']['ordered']) { if ($this -> getParam('html_options.sort', true) && !$this -> getParam('html_options.ordered', false, 'bool')) {
uasort($this -> values,array($this,'_sortTwoValues')); uasort($this -> values,array($this,'_sortTwoValues'));
} }
@ -114,7 +114,7 @@ class LSformElement_select_object extends LSformElement {
* @retval int Value for uasort * @retval int Value for uasort
**/ **/
private function _sortTwoValues(&$va,&$vb) { private function _sortTwoValues(&$va,&$vb) {
if (isset($this -> params['html_options']['sortDirection']) && $this -> params['html_options']['sortDirection']=='DESC') { if ($this -> getParam('html_options.sortDirection') == 'DESC') {
$dir=-1; $dir=-1;
} }
else { else {
@ -176,12 +176,21 @@ class LSformElement_select_object extends LSformElement {
* @retval array(dn -> displayName) Found objects * @retval array(dn -> displayName) Found objects
*/ */
function searchAdd ($pattern) { function searchAdd ($pattern) {
if (is_array($this -> params['html_options']['selectable_object'])) { if ($this -> getParam('html_options.selectable_object')) {
if (LSsession :: loadLSobject($this -> params['html_options']['selectable_object']['object_type'])) { $obj_type = $this -> getParam('html_options.selectable_object.object_type');
$obj = new $this -> params['html_options']['selectable_object']['object_type'](); if (LSsession :: loadLSobject($obj_type)) {
$obj = new $obj_type();
$sparams = array(); $sparams = array();
$sparams['onlyAccessible'] = (isset($this -> params['html_options']['selectable_object']['onlyAccessible'])?$this -> params['html_options']['selectable_object']['onlyAccessible']:FALSE); $sparams['onlyAccessible'] = $this -> getParam('html_options.selectable_object.onlyAccessible', false, 'bool');
$ret = $obj -> getSelectArray($pattern,NULL,$this -> params['html_options']['selectable_object']['display_name_format'],false,true,(isset($this -> params['html_options']['selectable_object']['filter'])?$this -> params['html_options']['selectable_object']['filter']:NULL),$sparams); $ret = $obj -> getSelectArray(
$pattern,
NULL,
$this -> getParam('html_options.selectable_object.display_name_format'),
false,
true,
$this -> getParam('html_options.selectable_object.filter'),
$sparams
);
if (is_array($ret)) { if (is_array($ret)) {
return $ret; return $ret;
} }

View file

@ -48,8 +48,8 @@ class LSformElement_text extends LSformElement {
$return = $this -> getLabelInfos(); $return = $this -> getLabelInfos();
// value // value
if (!$this -> isFreeze()) { if (!$this -> isFreeze()) {
if (isset($this -> params['html_options'])) { if ($this -> getParam('html_options')) {
LSsession :: addJSconfigParam($this -> name,$this -> params['html_options']); LSsession :: addJSconfigParam($this -> name, $this -> getParam('html_options'));
} }
LSsession :: addHelpInfos( LSsession :: addHelpInfos(
'LSformElement_text', 'LSformElement_text',

View file

@ -41,15 +41,17 @@ class LSformElement_valueWithUnit extends LSformElement {
* Si le parametre units n'est pas defini, cette fonction retournera False * Si le parametre units n'est pas defini, cette fonction retournera False
**/ **/
function getUnits() { function getUnits() {
if (isset($this -> params['html_options']['units']) && is_array($this -> params['html_options']['units'])) { $units = $this -> getParam('html_options.units');
$units=array(); if (is_array($units)) {
foreach($this -> params['html_options']['units'] as $sill => $label) { if ($this -> getParam('html_options.translate_labels', true)) {
$units[$sill]=((!isset($this -> params['html_options']['translate_labels']) || $this -> params['html_options']['translate_labels'])?__($label):$label); foreach($units as $sill => $label) {
$units[$sill] = __($label);
}
} }
krsort($units); krsort($units);
return $units; return $units;
} }
LSerror :: addErrorCode('LSformElement_valueWithUnit_01',$this -> name); LSerror :: addErrorCode('LSformElement_valueWithUnit_01', $this -> name);
return; return;
} }
@ -66,9 +68,9 @@ class LSformElement_valueWithUnit extends LSformElement {
function formatNumber($number) { function formatNumber($number) {
if ((int)$number==$number) return $number; if ((int)$number==$number) return $number;
return number_format($number, return number_format($number,
(isset($this -> params['html_options']['nb_decimals'])?$this -> params['html_options']['nb_decimals']:2), $this -> getParam('html_options.nb_decimals', 2, 'int'),
(isset($this -> params['html_options']['dec_point'])?$this -> params['html_options']['dec_point']:","), $this -> getParam('html_options.dec_point', ',', 'string'),
(isset($this -> params['html_options']['thousands_sep'])?$this -> params['html_options']['thousands_sep']:" ") $this -> getParam('html_options.thousands_sep', ' ', 'string')
); );
} }
@ -163,8 +165,8 @@ class LSformElement_valueWithUnit extends LSformElement {
if (isset($_POST[$this -> name.'_unitFact'][$key]) && ($_POST[$this -> name.'_unitFact'][$key]!=1)) { if (isset($_POST[$this -> name.'_unitFact'][$key]) && ($_POST[$this -> name.'_unitFact'][$key]!=1)) {
$f = $_POST[$this -> name.'_unitFact'][$key]; $f = $_POST[$this -> name.'_unitFact'][$key];
} }
if (isset($this -> params['html_options']['store_integer']) && $this -> params['html_options']['store_integer']) { if ($this -> getParam('html_options.store_integer'])) {
if (isset($this -> params['html_options']['round_down']) && $this -> params['html_options']['round_down']) { if ($this -> getParam('html_options.round_down')) {
$return[$this -> name][$key] = floor($val*$f); $return[$this -> name][$key] = floor($val*$f);
} }
else { else {

View file

@ -47,7 +47,7 @@ class LSformElement_wysiwyg extends LSformElement {
LSsession :: addJSconfigParam( LSsession :: addJSconfigParam(
$this -> name, $this -> name,
array( array(
'extra_options' => (isset($this -> params['html_options']['extra_options'])?$this -> params['html_options']['extra_options']:array()), 'extra_options' => $this -> getParam('html_options.extra_options', array()),
) )
); );
} }

View file

@ -68,7 +68,7 @@ class LSldapObject {
return; return;
} }
foreach($this -> config['attrs'] as $attr_name => $attr_config) { foreach($this -> getConfig('attrs', array()) as $attr_name => $attr_config) {
if(!$this -> attrs[$attr_name]=new LSattribute($attr_name,$attr_config,$this)) { if(!$this -> attrs[$attr_name]=new LSattribute($attr_name,$attr_config,$this)) {
return; return;
} }
@ -127,7 +127,7 @@ class LSldapObject {
* @retval string Format d'affichage de l'objet. * @retval string Format d'affichage de l'objet.
*/ */
function getDisplayNameFormat() { function getDisplayNameFormat() {
return $this -> config['display_name_format']; return $this -> getConfig('display_name_format');
} }
/** /**
@ -589,7 +589,7 @@ class LSldapObject {
$new = $this -> isNew(); $new = $this -> isNew();
foreach($this -> attrs as $attr) { foreach($this -> attrs as $attr) {
if(($attr -> isUpdate())&&($attr -> isValidate())) { if(($attr -> isUpdate())&&($attr -> isValidate())) {
if(($attr -> name == $this -> config['rdn'])&&(!$new)) { if(($attr -> name == $this -> getConfig('rdn')) && (!$new)) {
$new = true; $new = true;
LSdebug('Rename'); LSdebug('Rename');
if (!$this -> fireEvent('before_rename')) { if (!$this -> fireEvent('before_rename')) {
@ -838,7 +838,7 @@ class LSldapObject {
*/ */
function searchObject($name,$basedn=NULL,$filter=NULL,$params=NULL) { function searchObject($name,$basedn=NULL,$filter=NULL,$params=NULL) {
if (!$filter) { if (!$filter) {
$filter = '('.$this -> config['rdn'].'='.$name.')'; $filter = '('.$this -> getConfig('rdn').'='.$name.')';
} }
else { else {
$filter = getFData($filter,$name); $filter = getFData($filter,$name);
@ -952,14 +952,14 @@ class LSldapObject {
else { else {
$container_dn=$this -> getContainerDn(); $container_dn=$this -> getContainerDn();
if ($container_dn) { if ($container_dn) {
$rdn_attr=$this -> config['rdn']; $rdn_attr = $this -> getConfig('rdn');
if( (isset($this -> config['rdn'])) && (isset($this -> attrs[$rdn_attr])) ) { if( $rdn_attr && isset($this -> attrs[$rdn_attr]) ) {
$rdn_val=$this -> attrs[$rdn_attr] -> getUpdateData(); $rdn_val=$this -> attrs[$rdn_attr] -> getUpdateData();
if (!empty($rdn_val)) { if (!empty($rdn_val)) {
return $rdn_attr.'='.$rdn_val[0].','.$container_dn; return $rdn_attr.'='.$rdn_val[0].','.$container_dn;
} }
else { else {
LSerror :: addErrorCode('LSldapObject_12',$this -> config['rdn']); LSerror :: addErrorCode('LSldapObject_12', $rdn_attr);
return; return;
} }
} }
@ -983,10 +983,12 @@ class LSldapObject {
*/ */
function getContainerDn() { function getContainerDn() {
$topDn = LSsession :: getTopDn(); $topDn = LSsession :: getTopDn();
if (isset($this -> config['generate_container_dn'])) { $generate_container_dn = $this -> getConfig('generate_container_dn');
if (is_callable($this -> config['generate_container_dn'])) { $container_dn = $this -> getConfig('container_dn');
if ($generate_container_dn) {
if (is_callable($generate_container_dn)) {
try { try {
$container_dn=$this -> config['generate_container_dn']($this); $container_dn = call_user_func_array($generate_container_dn, array(&$this));
return $container_dn.','.$topDn; return $container_dn.','.$topDn;
} }
catch (Exception $e) { catch (Exception $e) {
@ -994,11 +996,11 @@ class LSldapObject {
} }
} }
else { else {
LSerror :: addErrorCode('LSldapObject_33',$this -> config['generate_container_dn']); LSerror :: addErrorCode('LSldapObject_33', $generate_container_dn);
} }
} }
else if ((isset($this -> config['container_dn'])) && ($topDn)) { else if ($container_dn && $topDn) {
return $this -> config['container_dn'].','.$topDn; return $container_dn.','.$topDn;
} }
else { else {
LSerror :: addErrorCode('LSldapObject_11',$this -> getType()); LSerror :: addErrorCode('LSldapObject_11',$this -> getType());
@ -1118,11 +1120,12 @@ class LSldapObject {
*/ */
function updateLSrelationsCache() { function updateLSrelationsCache() {
$this -> _LSrelationsCache=array(); $this -> _LSrelationsCache=array();
if (is_array($this->config['LSrelation']) && LSsession :: loadLSclass('LSrelation')) { $LSrelations = $this -> getConfig('LSrelation');
if (is_array($LSrelations) && LSsession :: loadLSclass('LSrelation')) {
$type = $this -> getType(); $type = $this -> getType();
$me = new $type(); $me = new $type();
$me -> loadData($this -> getDn()); $me -> loadData($this -> getDn());
foreach($this->config['LSrelation'] as $relation_name => $relation_conf) { foreach($LSrelations as $relation_name => $relation_conf) {
$relation = new LSrelation($me, $relation_name); $relation = new LSrelation($me, $relation_name);
$list = $relation -> listRelatedObjects(); $list = $relation -> listRelatedObjects();
if (is_array($list)) { if (is_array($list)) {
@ -1659,16 +1662,13 @@ class LSldapObject {
$return = $this -> fireObjectEvent($event); $return = $this -> fireObjectEvent($event);
// Config // Config
if(isset($this -> config[$event])) { $funcs = $this -> getConfig($event);
if (!is_array($this -> config[$event])) { if($funcs) {
if (!is_array($funcs))
$funcs = array($this -> config[$event]); $funcs = array($this -> config[$event]);
}
else {
$funcs = $this -> config[$event];
}
foreach($funcs as $func) { foreach($funcs as $func) {
if(function_exists($func)) { if(function_exists($func)) {
if(!call_user_func_array($func,array(&$this))) { if(!call_user_func_array($func, array(&$this))) {
$return = false; $return = false;
LSerror :: addErrorCode('LSldapObject_07',array('func' => $func,'event' => $event)); LSerror :: addErrorCode('LSldapObject_07',array('func' => $func,'event' => $event));
} }
@ -1801,8 +1801,9 @@ class LSldapObject {
return $this -> cache['subDnName']; return $this -> cache['subDnName'];
} }
elseif ($key=='rdn') { elseif ($key=='rdn') {
if ($this -> config['rdn'] && isset($this -> attrs[ $this -> config['rdn'] ])) { $rdn_attr = $this -> getConfig('rdn');
return $this -> attrs[ $this -> config['rdn'] ] -> getValue(); if ($rdn_attr && isset($this -> attrs[ $rdn_attr ])) {
return $this -> attrs[ $rdn_attr ] -> getValue();
} }
return false; return false;
} }
@ -1815,9 +1816,10 @@ class LSldapObject {
**/ **/
function listValidIOformats() { function listValidIOformats() {
$ret=array(); $ret=array();
if (isset($this -> config['ioFormat']) && is_array($this -> config['ioFormat'])) { $ioFormats = $this -> getConfig('ioFormat');
foreach($this -> config['ioFormat'] as $name => $conf) { if (is_array($ioFormats)) {
$ret[$name]=_((isset($conf['label'])?$conf['label']:$name)); foreach($ioFormats as $name => $conf) {
$ret[$name] = _((isset($conf['label'])?$conf['label']:$name));
} }
} }
return $ret; return $ret;
@ -1831,10 +1833,20 @@ class LSldapObject {
* @retval boolean True if it's a valid IOformat, false otherwise * @retval boolean True if it's a valid IOformat, false otherwise
**/ **/
function isValidIOformat($f) { function isValidIOformat($f) {
if (isset($this -> config['ioFormat']) && is_array($this -> config['ioFormat']) && isset($this -> config['ioFormat'][$f])) { return is_array($this -> getConfig("ioFormat.$f"));
return True; }
}
return False; /**
* Return a configuration parameter (or default value)
*
* @param[] $param The configuration parameter
* @param[] $default The default value (default : null)
* @param[] $cast Cast resulting value in specific type (default : disabled)
*
* @retval mixed The configuration parameter value or default value if not set
**/
public function getConfig($param, $default=null, $cast=null) {
return LSconfig :: get($param, $default, $cast, $this -> config);
} }
} }

View file

@ -123,7 +123,7 @@ class LSsearch {
*/ */
private function loadConfig() { private function loadConfig() {
$this -> config = LSconfig::get("LSobjects.".$this -> LSobject.".LSsearch"); $this -> config = LSconfig::get("LSobjects.".$this -> LSobject.".LSsearch");
if (is_array($this -> config['predefinedFilters'])) { if (isset($this -> config['predefinedFilters']) && is_array($this -> config['predefinedFilters'])) {
foreach($this -> config['predefinedFilters'] as $filter => $label) { foreach($this -> config['predefinedFilters'] as $filter => $label) {
if(!LSldap::isValidFilter($filter)) { if(!LSldap::isValidFilter($filter)) {
LSerror::addErrorCode('LSsearch_15',array('label' => $label, 'filter' => $filter, 'type' => $this -> LSobject)); LSerror::addErrorCode('LSsearch_15',array('label' => $label, 'filter' => $filter, 'type' => $this -> LSobject));
@ -179,7 +179,7 @@ class LSsearch {
foreach ($params as $param => $value) { foreach ($params as $param => $value) {
if ( !isset($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]) || $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]!=$value) { if ( !isset($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]) || $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]!=$value) {
LSdebug("S: $param => $value"); LSdebug("S: $param => ".varDump($value));
$_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]=$value; $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]=$value;
} }
} }
@ -372,8 +372,8 @@ class LSsearch {
} }
else { else {
$this -> params['sortBy'] = $params['sortBy']; $this -> params['sortBy'] = $params['sortBy'];
if (!is_string($params['sortDirection'])) { if (!isset($params['sortDirection']) || !is_string($params['sortDirection'])) {
$this -> params['sortDirection']='ASC'; $this -> params['sortDirection'] = 'ASC';
} }
} }
} }