mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-18 00:09:06 +01:00
Use ensureIsArray() helper to make code more readable
This commit is contained in:
parent
770533b7ec
commit
106a2d9f04
19 changed files with 110 additions and 199 deletions
|
@ -47,14 +47,8 @@ class LSattr_html_image extends LSattr_html {
|
||||||
LSerror :: addErrorCode('LSattr_html_03','password');
|
LSerror :: addErrorCode('LSattr_html_03','password');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($data) {
|
if ($data)
|
||||||
if(is_array($data)) {
|
$element -> setValue(ensureIsArray($data)[0]);
|
||||||
$element -> setValue($data[0]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$element -> setValue($data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $element;
|
return $element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,14 +44,10 @@ class LSattr_html_password extends LSattr_html {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($data) {
|
if ($data) {
|
||||||
if(is_array($data)) {
|
$data = ensureIsArray($data);
|
||||||
if (count($data)>1)
|
if (count($data) > 1)
|
||||||
LSerror :: addErrorCode('LSattr_html_03','password');
|
LSerror :: addErrorCode('LSattr_html_03', 'password');
|
||||||
$element -> setValue($data[0]);
|
$element -> setValue($data[0]);
|
||||||
}
|
|
||||||
else {
|
|
||||||
$element -> setValue($data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $element;
|
return $element;
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,8 +283,7 @@ class LSattr_html_select_list extends LSattr_html{
|
||||||
$list = $LSsearch -> getSearchEntries();
|
$list = $LSsearch -> getSearchEntries();
|
||||||
foreach($list as $entry) {
|
foreach($list as $entry) {
|
||||||
$keys = $entry -> get($conf['values_attribute']);
|
$keys = $entry -> get($conf['values_attribute']);
|
||||||
if (!is_array($keys)) $keys=array($keys);
|
foreach (ensureIsArray($keys) as $key) {
|
||||||
foreach ($keys as $key) {
|
|
||||||
$retInfos[$key]=$key;
|
$retInfos[$key]=$key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,11 +311,7 @@ class LSattr_html_select_list extends LSattr_html{
|
||||||
$retInfos=array();
|
$retInfos=array();
|
||||||
if (is_string($attr)) {
|
if (is_string($attr)) {
|
||||||
if (isset($ldapObject->attrs[$attr]) && $ldapObject->attrs[$attr] instanceof LSattribute) {
|
if (isset($ldapObject->attrs[$attr]) && $ldapObject->attrs[$attr] instanceof LSattribute) {
|
||||||
$attr_values = $ldapObject->attrs[$attr]->getValue();
|
$attr_values = ensureIsArray($ldapObject->attrs[$attr]->getValue());
|
||||||
if (!$attr_values)
|
|
||||||
$attr_values = array();
|
|
||||||
elseif (!is_array($attr_values))
|
|
||||||
$attr_values = array($attr_values);
|
|
||||||
if (isset($options['translate_labels']) && !$options['translate_labels']) {
|
if (isset($options['translate_labels']) && !$options['translate_labels']) {
|
||||||
foreach($attr_values as $attr_value)
|
foreach($attr_values as $attr_value)
|
||||||
$retInfos[$attr_value] = $attr_value;
|
$retInfos[$attr_value] = $attr_value;
|
||||||
|
@ -334,11 +329,7 @@ class LSattr_html_select_list extends LSattr_html{
|
||||||
if (isset($ldapObject->attrs[$attr['attr']]) && $ldapObject->attrs[$attr['attr']] instanceof LSattribute) {
|
if (isset($ldapObject->attrs[$attr['attr']]) && $ldapObject->attrs[$attr['attr']] instanceof LSattribute) {
|
||||||
if (isset($attr['json_component_key'])) {
|
if (isset($attr['json_component_key'])) {
|
||||||
if (get_class($ldapObject->attrs[$attr['attr']]->html) == 'LSattr_html_jsonCompositeAttribute') {
|
if (get_class($ldapObject->attrs[$attr['attr']]->html) == 'LSattr_html_jsonCompositeAttribute') {
|
||||||
$attr_values = $ldapObject->attrs[$attr['attr']]->getValue();
|
$attr_values = ensureIsArray($ldapObject->attrs[$attr['attr']]->getValue());
|
||||||
if (!$attr_values)
|
|
||||||
$attr_values = array();
|
|
||||||
elseif (!is_array($attr_values))
|
|
||||||
$attr_values = array($attr_values);
|
|
||||||
foreach($attr_values as $attr_value) {
|
foreach($attr_values as $attr_value) {
|
||||||
$value_data = @json_decode($attr_value, true);
|
$value_data = @json_decode($attr_value, true);
|
||||||
if (!isset($value_data[$attr['json_component_key']])) {
|
if (!isset($value_data[$attr['json_component_key']])) {
|
||||||
|
|
|
@ -46,10 +46,7 @@ class LSattr_html_select_object extends LSattr_html{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($data) {
|
if ($data) {
|
||||||
if (!is_array($data)) {
|
$values = $this -> getFormValues(ensureIsArray($data));
|
||||||
$data=array($data);
|
|
||||||
}
|
|
||||||
$values=$this -> getFormValues($data);
|
|
||||||
if ($values) {
|
if ($values) {
|
||||||
$element -> setValue($values);
|
$element -> setValue($values);
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,10 +184,8 @@ class LSattribute extends LSlog_staticLoggerClass {
|
||||||
|
|
||||||
$onDisplay = $this -> getConfig('onDisplay');
|
$onDisplay = $this -> getConfig('onDisplay');
|
||||||
if ($onDisplay) {
|
if ($onDisplay) {
|
||||||
if (!is_array($onDisplay))
|
|
||||||
$onDisplay = array($onDisplay);
|
|
||||||
$result = $data;
|
$result = $data;
|
||||||
foreach($onDisplay as $func) {
|
foreach(ensureIsArray($onDisplay) as $func) {
|
||||||
if (function_exists($func)) {
|
if (function_exists($func)) {
|
||||||
$result = call_user_func($func, $result);
|
$result = call_user_func($func, $result);
|
||||||
}
|
}
|
||||||
|
@ -615,8 +613,7 @@ class LSattribute extends LSlog_staticLoggerClass {
|
||||||
self :: log_debug(strval($this)." -> fireEvent($event)");
|
self :: log_debug(strval($this)." -> fireEvent($event)");
|
||||||
$return = true;
|
$return = true;
|
||||||
if(isset($this -> config[$event])) {
|
if(isset($this -> config[$event])) {
|
||||||
$funcs = (!is_array($this -> config[$event])?array($this -> config[$event]):$this -> config[$event]);
|
foreach(ensureIsArray($this -> config[$event]) as $func) {
|
||||||
foreach($funcs as $func) {
|
|
||||||
if(function_exists($func)) {
|
if(function_exists($func)) {
|
||||||
self :: log_debug(strval($this)." -> fireEvent($event): run ".format_callable($func));
|
self :: log_debug(strval($this)." -> fireEvent($event): run ".format_callable($func));
|
||||||
if(!call_user_func_array($func, array(&$this -> ldapObject))) {
|
if(!call_user_func_array($func, array(&$this -> ldapObject))) {
|
||||||
|
|
|
@ -87,11 +87,7 @@ class LSformElement extends LSlog_staticLoggerClass {
|
||||||
* @retval boolean Retourne True
|
* @retval boolean Retourne True
|
||||||
*/
|
*/
|
||||||
public function setValue($data) {
|
public function setValue($data) {
|
||||||
if (!is_array($data)) {
|
$this -> values = ensureIsArray($data);
|
||||||
$data=array($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this -> values = $data;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,10 +105,7 @@ class LSformElement extends LSlog_staticLoggerClass {
|
||||||
* @retval boolean Retourne True
|
* @retval boolean Retourne True
|
||||||
*/
|
*/
|
||||||
public function setValueFromPostData($data) {
|
public function setValueFromPostData($data) {
|
||||||
if (!is_array($data)) {
|
$this -> values = ensureIsArray($data);
|
||||||
$data=array($data);
|
|
||||||
}
|
|
||||||
$this -> values = $data;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,12 +130,7 @@ class LSformElement extends LSlog_staticLoggerClass {
|
||||||
* @retval void
|
* @retval void
|
||||||
*/
|
*/
|
||||||
public function addValue($data) {
|
public function addValue($data) {
|
||||||
if (is_array($data)) {
|
$this -> values = array_merge($this -> values, ensureIsArray($data));
|
||||||
$this -> values = array_merge($this -> values, $data);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$this -> values[] = $data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -253,10 +241,8 @@ class LSformElement extends LSlog_staticLoggerClass {
|
||||||
*/
|
*/
|
||||||
protected static function getData(&$post, $name) {
|
protected static function getData(&$post, $name) {
|
||||||
if (isset($post[$name])) {
|
if (isset($post[$name])) {
|
||||||
$return=array();
|
$return = array();
|
||||||
if(!is_array($post[$name])) {
|
$post[$name] = ensureIsArray($post[$name]);
|
||||||
$post[$name] = array($post[$name]);
|
|
||||||
}
|
|
||||||
foreach($post[$name] as $key => $val) {
|
foreach($post[$name] as $key => $val) {
|
||||||
if (!is_empty($val)) {
|
if (!is_empty($val)) {
|
||||||
$return[$key] = $val;
|
$return[$key] = $val;
|
||||||
|
|
|
@ -74,12 +74,9 @@ class LSformElement_date extends LSformElement {
|
||||||
* @retval boolean Retourne True
|
* @retval boolean Retourne True
|
||||||
*/
|
*/
|
||||||
public function setValue($data) {
|
public function setValue($data) {
|
||||||
if (!is_array($data)) {
|
|
||||||
$data=array($data);
|
|
||||||
}
|
|
||||||
$special_values = $this -> getSpecialValues();
|
$special_values = $this -> getSpecialValues();
|
||||||
$values = array();
|
$values = array();
|
||||||
foreach ($data as $value) {
|
foreach (ensureIsArray($data) as $value) {
|
||||||
if(is_numeric($value)) {
|
if(is_numeric($value)) {
|
||||||
if (array_key_exists($value, $special_values)) {
|
if (array_key_exists($value, $special_values)) {
|
||||||
$values[] = $special_values[$value];
|
$values[] = $special_values[$value];
|
||||||
|
@ -239,11 +236,7 @@ class LSformElement_date extends LSformElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(!is_array($values))
|
$return[$this -> name] = ensureIsArray($special_values) + ensureIsArray($values);
|
||||||
$values = array();
|
|
||||||
if(!is_array($special_values))
|
|
||||||
$special_values = array();
|
|
||||||
$return[$this -> name] = $special_values + $values;
|
|
||||||
self :: log_trace($this." -> merged values=".varDump($return[$this -> name]));
|
self :: log_trace($this." -> merged values=".varDump($return[$this -> name]));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -151,9 +151,7 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
|
||||||
protected function translateComponentValue($c,$value,$inLoop=false) {
|
protected function translateComponentValue($c,$value,$inLoop=false) {
|
||||||
if (!$inLoop && isset($this -> components[$c]['multiple']) && $this -> components[$c]['multiple']) {
|
if (!$inLoop && isset($this -> components[$c]['multiple']) && $this -> components[$c]['multiple']) {
|
||||||
$retval = array();
|
$retval = array();
|
||||||
if (!is_array($value))
|
foreach(ensureIsArray($value) as $val)
|
||||||
$value = array($value);
|
|
||||||
foreach($value as $val)
|
|
||||||
$retval[] = $this -> translateComponentValue($c, $val, true);
|
$retval[] = $this -> translateComponentValue($c, $val, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -121,15 +121,11 @@ class LSformElement_labeledValue extends LSformElement {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (isset($_POST[$this -> name."_labels"]) && isset($_POST[$this -> name."_values"])) {
|
if (isset($_POST[$this -> name."_labels"]) && isset($_POST[$this -> name."_values"])) {
|
||||||
$return[$this -> name]=array();
|
$return[$this -> name] = array();
|
||||||
if(!is_array($_POST[$this -> name."_labels"])) {
|
$_POST[$this -> name."_labels"] = ensureIsArray($_POST[$this -> name."_labels"]);
|
||||||
$_POST[$this -> name."_labels"] = array($_POST[$this -> name."_labels"]);
|
$_POST[$this -> name."_values"] = ensureIsArray($_POST[$this -> name."_values"]);
|
||||||
}
|
|
||||||
if(!is_array($_POST[$this -> name."_values"])) {
|
|
||||||
$_POST[$this -> name."_values"] = array($_POST[$this -> name."_values"]);
|
|
||||||
}
|
|
||||||
foreach($_POST[$this -> name."_labels"] as $key => $label) {
|
foreach($_POST[$this -> name."_labels"] as $key => $label) {
|
||||||
$val=$_POST[$this -> name."_values"][$key];
|
$val = $_POST[$this -> name."_values"][$key];
|
||||||
if (!empty($label) && !is_empty($val)) {
|
if (!empty($label) && !is_empty($val)) {
|
||||||
$return[$this -> name][$key] = "[$label]$val";
|
$return[$this -> name][$key] = "[$label]$val";
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,8 +85,7 @@ class LSformElement_mail extends LSformElement_text {
|
||||||
public function autocomplete($pattern) {
|
public function autocomplete($pattern) {
|
||||||
$ret = array();
|
$ret = array();
|
||||||
if ($this -> getParam('html_options.autocomplete')) {
|
if ($this -> getParam('html_options.autocomplete')) {
|
||||||
$mail_attributes = $this -> getParam('html_options.autocomplete.mail_attributes', array('mail'));
|
$mail_attributes = ensureIsArray($this -> getParam('html_options.autocomplete.mail_attributes', array('mail')));
|
||||||
if (!is_array($mail_attributes)) $mail_attributes = array($mail_attributes);
|
|
||||||
|
|
||||||
$obj_type = $this -> getParam('html_options.autocomplete.object_type');
|
$obj_type = $this -> getParam('html_options.autocomplete.object_type');
|
||||||
if ($obj_type) {
|
if ($obj_type) {
|
||||||
|
@ -124,9 +123,8 @@ class LSformElement_mail extends LSformElement_text {
|
||||||
$search -> run();
|
$search -> run();
|
||||||
foreach($search -> getSearchEntries() as $e) {
|
foreach($search -> getSearchEntries() as $e) {
|
||||||
foreach($mail_attributes as $attr) {
|
foreach($mail_attributes as $attr) {
|
||||||
$mails = $e->get($attr);
|
$mails = ensureIsArray($e->get($attr));
|
||||||
if (!$mails) continue;
|
if (!$mails) continue;
|
||||||
if (!is_array($mails)) $mails = array($mails);
|
|
||||||
foreach($mails as $mail)
|
foreach($mails as $mail)
|
||||||
$ret[$mail] = $e->displayName;
|
$ret[$mail] = $e->displayName;
|
||||||
}
|
}
|
||||||
|
@ -170,8 +168,7 @@ class LSformElement_mail extends LSformElement_text {
|
||||||
$displayName = ($displayNameFormat?getFData($displayNameFormat, $object['attrs']):null);
|
$displayName = ($displayNameFormat?getFData($displayNameFormat, $object['attrs']):null);
|
||||||
foreach($mail_attributes as $attr) {
|
foreach($mail_attributes as $attr) {
|
||||||
if (!isset($object['attrs'][$attr])) continue;
|
if (!isset($object['attrs'][$attr])) continue;
|
||||||
$mails = $object['attrs'][$attr];
|
$mails = ensureIsArray($object['attrs'][$attr]);
|
||||||
if (!is_array($mails)) $mails = array($mails);
|
|
||||||
foreach($mails as $mail)
|
foreach($mails as $mail)
|
||||||
$ret[$mail] = ($displayName?$displayName:$mail);
|
$ret[$mail] = ($displayName?$displayName:$mail);
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,9 +139,7 @@ class LSformElement_mailQuota extends LSformElement {
|
||||||
}
|
}
|
||||||
if (isset($_POST[$this -> name.'_size'])) {
|
if (isset($_POST[$this -> name.'_size'])) {
|
||||||
$return[$this -> name]=array();
|
$return[$this -> name]=array();
|
||||||
if(!is_array($_POST[$this -> name.'_size'])) {
|
$_POST[$this -> name.'_size'] = ensureIsArray($_POST[$this -> name.'_size']);
|
||||||
$_POST[$this -> name.'_size'] = array($_POST[$this -> name.'_size']);
|
|
||||||
}
|
|
||||||
if(isset($_POST[$this -> name.'_sizeFact']) && !is_array($_POST[$this -> name.'_sizeFact'])) {
|
if(isset($_POST[$this -> name.'_sizeFact']) && !is_array($_POST[$this -> name.'_sizeFact'])) {
|
||||||
$_POST[$this -> name.'_sizeFact'] = array($_POST[$this -> name.'_sizeFact']);
|
$_POST[$this -> name.'_sizeFact'] = array($_POST[$this -> name.'_sizeFact']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,19 +278,14 @@ class LSformElement_password extends LSformElement {
|
||||||
$mail = (String)$this -> sendMail['mail'];
|
$mail = (String)$this -> sendMail['mail'];
|
||||||
self :: log_debug("send(): mail from params: '$mail'");
|
self :: log_debug("send(): mail from params: '$mail'");
|
||||||
if (!$mail) {
|
if (!$mail) {
|
||||||
$mail_attrs = $this -> getMailAttrs();
|
$mail_attrs = ensureIsArray($this -> getMailAttrs());
|
||||||
if (!is_array($mail_attrs)) {
|
|
||||||
$mail_attrs=array($mail_attrs);
|
|
||||||
}
|
|
||||||
self :: log_debug('send(): mail attrs: '.varDump($mail_attrs));
|
self :: log_debug('send(): mail attrs: '.varDump($mail_attrs));
|
||||||
$checkDomainsList = $this -> getParam('html_options.mail.domain');
|
$checkDomainsList = $this -> getParam('html_options.mail.domain');
|
||||||
$checkDomain = $this -> getParam('html_options.mail.checkDomain', true, 'bool');
|
$checkDomain = $this -> getParam('html_options.mail.checkDomain', true, 'bool');
|
||||||
foreach($mail_attrs as $attr) {
|
foreach($mail_attrs as $attr) {
|
||||||
$mail_attr = $this -> attr_html -> attribute -> ldapObject -> attrs[$attr];
|
$mail_attr = $this -> attr_html -> attribute -> ldapObject -> attrs[$attr];
|
||||||
if ($mail_attr instanceOf LSattribute) {
|
if ($mail_attr instanceOf LSattribute) {
|
||||||
$mail_values = $mail_attr -> getValue();
|
$mail_values = ensureIsArray($mail_attr -> getValue());
|
||||||
if (!is_array($mail_values))
|
|
||||||
$mail_values = array($mail_values);
|
|
||||||
foreach($mail_values as $mail_value) {
|
foreach($mail_values as $mail_value) {
|
||||||
if ($mail_value && checkEmail($mail_value, $checkDomainsList, $checkDomain)) {
|
if ($mail_value && checkEmail($mail_value, $checkDomainsList, $checkDomain)) {
|
||||||
$mail = $mail_value;
|
$mail = $mail_value;
|
||||||
|
|
|
@ -130,9 +130,7 @@ class LSformElement_quota extends LSformElement {
|
||||||
}
|
}
|
||||||
if (isset($_POST[$this -> name.'_size'])) {
|
if (isset($_POST[$this -> name.'_size'])) {
|
||||||
$return[$this -> name]=array();
|
$return[$this -> name]=array();
|
||||||
if(!is_array($_POST[$this -> name.'_size'])) {
|
$_POST[$this -> name.'_size'] = ensureIsArray($_POST[$this -> name.'_size']);
|
||||||
$_POST[$this -> name.'_size'] = array($_POST[$this -> name.'_size']);
|
|
||||||
}
|
|
||||||
if(isset($_POST[$this -> name.'_sizeFact']) && !is_array($_POST[$this -> name.'_sizeFact'])) {
|
if(isset($_POST[$this -> name.'_sizeFact']) && !is_array($_POST[$this -> name.'_sizeFact'])) {
|
||||||
$_POST[$this -> name.'_sizeFact'] = array($_POST[$this -> name.'_sizeFact']);
|
$_POST[$this -> name.'_sizeFact'] = array($_POST[$this -> name.'_sizeFact']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,9 +159,7 @@ class LSformElement_valueWithUnit extends LSformElement {
|
||||||
}
|
}
|
||||||
$return[$this -> name]=array();
|
$return[$this -> name]=array();
|
||||||
if (isset($_POST[$this -> name.'_valueWithUnit'])) {
|
if (isset($_POST[$this -> name.'_valueWithUnit'])) {
|
||||||
if(!is_array($_POST[$this -> name.'_valueWithUnit'])) {
|
$_POST[$this -> name.'_valueWithUnit'] = ensureIsArray($_POST[$this -> name.'_valueWithUnit']);
|
||||||
$_POST[$this -> name.'_valueWithUnit'] = array($_POST[$this -> name.'_valueWithUnit']);
|
|
||||||
}
|
|
||||||
if(isset($_POST[$this -> name.'_unitFact']) && !is_array($_POST[$this -> name.'_unitFact'])) {
|
if(isset($_POST[$this -> name.'_unitFact']) && !is_array($_POST[$this -> name.'_unitFact'])) {
|
||||||
$_POST[$this -> name.'_unitFact'] = array($_POST[$this -> name.'_unitFact']);
|
$_POST[$this -> name.'_unitFact'] = array($_POST[$this -> name.'_unitFact']);
|
||||||
}
|
}
|
||||||
|
@ -186,16 +184,12 @@ class LSformElement_valueWithUnit extends LSformElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($_POST[$this -> name])) {
|
if (isset($_POST[$this -> name])) {
|
||||||
if(!is_array($_POST[$this -> name])) {
|
$_POST[$this -> name] = ensureIsArray($_POST[$this -> name]);
|
||||||
$_POST[$this -> name] = array($_POST[$this -> name]);
|
$return[$this -> name] = array_merge($return[$this -> name], $_POST[$this -> name]);
|
||||||
}
|
|
||||||
$return[$this -> name]=array_merge($return[$this -> name],$_POST[$this -> name]);
|
|
||||||
}
|
}
|
||||||
if (isset($_POST[$this -> name.'_value'])) {
|
if (isset($_POST[$this -> name.'_value'])) {
|
||||||
if (!is_array($_POST[$this -> name.'_value'])) {
|
$_POST[$this -> name.'_value'] = ensureIsArray($_POST[$this -> name.'_value']);
|
||||||
$_POST[$this -> name.'_value']=array($_POST[$this -> name.'_value']);
|
$return[$this -> name] = array_merge($return[$this -> name], $_POST[$this -> name.'_value']);
|
||||||
}
|
|
||||||
$return[$this -> name]=array_merge($return[$this -> name],$_POST[$this -> name.'_value']);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,10 +40,6 @@ class LSformRule_differentPassword extends LSformRule {
|
||||||
public static function validate($value, $options=array(), &$formElement) {
|
public static function validate($value, $options=array(), &$formElement) {
|
||||||
$otherPasswordAttributes = LSconfig :: get('params.otherPasswordAttributes', null, null, $options);
|
$otherPasswordAttributes = LSconfig :: get('params.otherPasswordAttributes', null, null, $options);
|
||||||
if (!is_null($otherPasswordAttributes)) {
|
if (!is_null($otherPasswordAttributes)) {
|
||||||
// Make sure otherPasswordAttributes is an array
|
|
||||||
if (!is_array($otherPasswordAttributes))
|
|
||||||
$otherPasswordAttributes = array($otherPasswordAttributes);
|
|
||||||
|
|
||||||
// Load LSattr_ldap_password
|
// Load LSattr_ldap_password
|
||||||
if (!LSsession :: loadLSclass("LSattr_ldap_password")) {
|
if (!LSsession :: loadLSclass("LSattr_ldap_password")) {
|
||||||
LSerror :: addErrorCode('LSformRule_differentPassword_02');
|
LSerror :: addErrorCode('LSformRule_differentPassword_02');
|
||||||
|
@ -51,7 +47,7 @@ class LSformRule_differentPassword extends LSformRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iter on otherPasswordAttributes to check password does not match
|
// Iter on otherPasswordAttributes to check password does not match
|
||||||
foreach($otherPasswordAttributes as $attr) {
|
foreach(ensureIsArray($otherPasswordAttributes) as $attr) {
|
||||||
// Check attribute exist
|
// Check attribute exist
|
||||||
if (!isset($formElement -> attr_html -> attribute -> ldapObject -> attrs[$attr])) {
|
if (!isset($formElement -> attr_html -> attribute -> ldapObject -> attrs[$attr])) {
|
||||||
LSerror :: addErrorCode('LSformRule_differentPassword_03', $attr);
|
LSerror :: addErrorCode('LSformRule_differentPassword_03', $attr);
|
||||||
|
|
|
@ -42,17 +42,9 @@ class LSformRule_mimetype extends LSformRule {
|
||||||
$file = LSsession :: getTmpFile($value);
|
$file = LSsession :: getTmpFile($value);
|
||||||
$real_mimetype = mime_content_type($file);
|
$real_mimetype = mime_content_type($file);
|
||||||
|
|
||||||
$mimetype = LSconfig :: get('params.mimeType', null, null, $options);
|
$mimetypes = ensureIsArray(LSconfig :: get('params.mimeType', null, null, $options));
|
||||||
if (!is_null($mimetype)) {
|
if ($mimetypes && !in_array($real_mimetype, $mimetypes))
|
||||||
if (is_array($mimetype)) {
|
return false;
|
||||||
if (!in_array($real_mimetype, $mimetype))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ($real_mimetype != $mimetype)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$mimeTypeRegEx = LSconfig :: get('params.mimeTypeRegEx', null, 'string', $options);
|
$mimeTypeRegEx = LSconfig :: get('params.mimeTypeRegEx', null, 'string', $options);
|
||||||
if (is_string($mimeTypeRegEx) && !preg_match($mimeTypeRegEx, $real_mimetype))
|
if (is_string($mimeTypeRegEx) && !preg_match($mimeTypeRegEx, $real_mimetype))
|
||||||
|
|
|
@ -56,11 +56,8 @@ class LSformRule_password extends LSformRule {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$regex = LSconfig :: get('params.regex', null, null, $options);
|
$regex = ensureIsArray(LSconfig :: get('params.regex', null, null, $options));
|
||||||
if(!is_null($regex)) {
|
if($regex) {
|
||||||
if (!is_array($regex))
|
|
||||||
$regex = array($regex);
|
|
||||||
|
|
||||||
$minValidRegex = LSconfig :: get('params.minValidRegex', count($regex), 'int', $options);
|
$minValidRegex = LSconfig :: get('params.minValidRegex', count($regex), 'int', $options);
|
||||||
if ($minValidRegex == 0 || $minValidRegex > count($regex))
|
if ($minValidRegex == 0 || $minValidRegex > count($regex))
|
||||||
$minValidRegex = count($regex);
|
$minValidRegex = count($regex);
|
||||||
|
@ -85,8 +82,8 @@ class LSformRule_password extends LSformRule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$prohibitedValues = LSconfig :: get('params.prohibitedValues', null, null, $options);
|
$prohibitedValues = ensureIsArray(LSconfig :: get('params.prohibitedValues', null, null, $options));
|
||||||
if(is_array($prohibitedValues) && in_array($value, $prohibitedValues)) {
|
if(in_array($value, $prohibitedValues)) {
|
||||||
self :: log_debug("this password is prohibited");
|
self :: log_debug("this password is prohibited");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1354,25 +1354,24 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
||||||
*
|
*
|
||||||
* @retval Mixed La valeur clef d'un objet en relation
|
* @retval Mixed La valeur clef d'un objet en relation
|
||||||
**/
|
**/
|
||||||
public static function getObjectKeyValueInRelation($object,$objectType,$attrValues='dn') {
|
public static function getObjectKeyValueInRelation($object, $objectType, $attrValues='dn') {
|
||||||
if (!$objectType) {
|
if (!$objectType) {
|
||||||
LSerror :: addErrorCode('LSrelation_05','getObjectKeyValueInRelation');
|
LSerror :: addErrorCode('LSrelation_05','getObjectKeyValueInRelation');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!is_array($attrValues)) $attrValues=array($attrValues);
|
$keyValues = array();
|
||||||
$keyValues=array();
|
foreach (ensureIsArray($attrValues) as $attrValue) {
|
||||||
foreach ($attrValues as $attrValue) {
|
if ($attrValue == 'dn') {
|
||||||
if ($attrValue=='dn') {
|
|
||||||
$dn=$object -> getDn();
|
$dn=$object -> getDn();
|
||||||
if (!in_array($dn,$keyValues))
|
if (!in_array($dn, $keyValues))
|
||||||
$keyValues[] = $dn;
|
$keyValues[] = $dn;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$values=$object -> getValue($attrValue);
|
$values = $object -> getValue($attrValue);
|
||||||
if (is_array($values))
|
if (is_array($values))
|
||||||
foreach ($values as $keyValue)
|
foreach ($values as $keyValue)
|
||||||
if (!in_array($keyValue,$keyValues))
|
if (!in_array($keyValue, $keyValues))
|
||||||
$keyValues[]=$keyValue;
|
$keyValues[] = $keyValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $keyValues;
|
return $keyValues;
|
||||||
|
@ -1396,20 +1395,28 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
||||||
*
|
*
|
||||||
* @retval Array of $objectType Les objets en relations
|
* @retval Array of $objectType Les objets en relations
|
||||||
**/
|
**/
|
||||||
public function listObjectsInRelation($object,$attr,$objectType,$attrValues='dn') {
|
public function listObjectsInRelation($object, $attr, $objectType, $attrValues='dn') {
|
||||||
if ((!$attr)||(!$objectType)) {
|
if ((!$attr)||(!$objectType)) {
|
||||||
LSerror :: addErrorCode('LSrelation_05','listObjectsInRelation');
|
LSerror :: addErrorCode('LSrelation_05','listObjectsInRelation');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!is_array($attrValues)) $attrValues=array($attrValues);
|
$keyValues = self :: getObjectKeyValueInRelation($object, $objectType, $attrValues);
|
||||||
$keyValues=self :: getObjectKeyValueInRelation($object,$objectType,$attrValues);
|
|
||||||
if (!empty($keyValues)) {
|
if (!empty($keyValues)) {
|
||||||
$keyValuesFilters=array();
|
$keyValuesFilters = array();
|
||||||
foreach($keyValues as $keyValue) {
|
foreach($keyValues as $keyValue) {
|
||||||
$keyValuesFilters[] = Net_LDAP2_Filter::create($attr,'equals',$keyValue);
|
$keyValuesFilters[] = Net_LDAP2_Filter::create($attr,'equals',$keyValue);
|
||||||
}
|
}
|
||||||
$filter = LSldap::combineFilters('or', $keyValuesFilters);
|
$filter = LSldap::combineFilters('or', $keyValuesFilters);
|
||||||
return $this -> listObjects($filter,LSsession :: getRootDn(),array('scope' => 'sub','recursive' => true,'withoutCache'=>true, 'onlyAccessible' => false));
|
return $this -> listObjects(
|
||||||
|
$filter,
|
||||||
|
LSsession :: getRootDn(),
|
||||||
|
array(
|
||||||
|
'scope' => 'sub',
|
||||||
|
'recursive' => true,
|
||||||
|
'withoutCache'=>true,
|
||||||
|
'onlyAccessible' => false
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array();
|
return array();
|
||||||
|
@ -1511,17 +1518,13 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($this -> attrs[$attr] instanceof LSattribute) {
|
if ($this -> attrs[$attr] instanceof LSattribute) {
|
||||||
if (!is_array($attrValues)) $attrValues=array($attrValue);
|
$keyValues = self :: getObjectKeyValueInRelation($object, $objectType, $attrValues);
|
||||||
$keyValues=self :: getObjectKeyValueInRelation($object,$objectType,$attrValues);
|
$values = ensureIsArray($this -> attrs[$attr] -> getValue());
|
||||||
$values = $this -> attrs[$attr] -> getValue();
|
if ($values) {
|
||||||
if ((!is_array($values)) && (!empty($values))) {
|
$updateData = array();
|
||||||
$values = array($values);
|
|
||||||
}
|
|
||||||
if (is_array($values)) {
|
|
||||||
$updateData=array();
|
|
||||||
foreach($values as $value) {
|
foreach($values as $value) {
|
||||||
if (!in_array($value,$keyValues)) {
|
if (!in_array($value, $keyValues)) {
|
||||||
$updateData[]=$value;
|
$updateData[] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this -> _updateData(array($attr => $updateData));
|
return $this -> _updateData(array($attr => $updateData));
|
||||||
|
@ -1545,40 +1548,36 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
||||||
*
|
*
|
||||||
* @retval boolean True en cas de succès, False sinon
|
* @retval boolean True en cas de succès, False sinon
|
||||||
*/
|
*/
|
||||||
public function renameOneObjectInRelation($object,$oldValues,$attr,$objectType,$attrValue='dn') {
|
public function renameOneObjectInRelation($object, $oldValues, $attr, $objectType, $attrValue='dn') {
|
||||||
if ((!$attr)||(!$objectType)) {
|
if ((!$attr)||(!$objectType)) {
|
||||||
LSerror :: addErrorCode('LSrelation_05','renameOneObjectInRelation');
|
LSerror :: addErrorCode('LSrelation_05','renameOneObjectInRelation');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!is_array($oldValues)) $oldValues=array($oldValues);
|
if (!($object instanceof $objectType))
|
||||||
if ($object instanceof $objectType) {
|
return;
|
||||||
if ($this -> attrs[$attr] instanceof LSattribute) {
|
if (!($this -> attrs[$attr] instanceof LSattribute))
|
||||||
$values = $this -> attrs[$attr] -> getValue();
|
return;
|
||||||
if ((!is_array($values)) && (!empty($values))) {
|
$values = ensureIsArray($this -> attrs[$attr] -> getValue());
|
||||||
$values = array($values);
|
if (!$values)
|
||||||
|
return;
|
||||||
|
$updateData = array();
|
||||||
|
$oldValues = ensureIsArray($oldValues);
|
||||||
|
foreach($values as $value) {
|
||||||
|
if (!in_array($value, $oldValues)) {
|
||||||
|
$updateData[] = $value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ($attrValue == 'dn') {
|
||||||
|
$val = $object -> getDn();
|
||||||
}
|
}
|
||||||
if (is_array($values)) {
|
else {
|
||||||
$updateData=array();
|
$val = $object -> getValue($attrValue);
|
||||||
foreach($values as $value) {
|
$val = $val[0];
|
||||||
if (!in_array($value,$oldValues)) {
|
|
||||||
$updateData[] = $value;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ($attrValue=='dn') {
|
|
||||||
$val = $object -> getDn();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$val = $object -> getValue($attrValue);
|
|
||||||
$val = $val[0];
|
|
||||||
}
|
|
||||||
$updateData[] = $val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this -> _updateData(array($attr => $updateData));
|
|
||||||
}
|
}
|
||||||
|
$updateData[] = $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return $this -> _updateData(array($attr => $updateData));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1606,29 +1605,28 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
||||||
LSerror :: addErrorCode('LSrelation_05','updateObjectsInRelation');
|
LSerror :: addErrorCode('LSrelation_05','updateObjectsInRelation');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!is_array($attrValues)) $attrValues=array($attrValue);
|
$currentDns = array();
|
||||||
$currentDns=array();
|
$currentObjects = $this -> listObjectsInRelation($object, $attr, $objectType, $attrValues);
|
||||||
$currentObjects = $this -> listObjectsInRelation($object,$attr,$objectType,$attrValues);
|
if(!is_array($currentObjects))
|
||||||
if(is_array($currentObjects)) {
|
return;
|
||||||
for ($i=0;$i<count($currentObjects);$i++) {
|
for ($i=0; $i<count($currentObjects); $i++) {
|
||||||
$currentDns[]=$currentObjects[$i] -> getDn();
|
$currentDns[] = $currentObjects[$i] -> getDn();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$dontTouch=array_intersect($listDns,$currentDns);
|
$dontTouch = array_intersect($listDns, $currentDns);
|
||||||
|
|
||||||
for($i=0;$i<count($currentObjects);$i++) {
|
for($i=0; $i<count($currentObjects); $i++) {
|
||||||
if (in_array($currentObjects[$i] -> getDn(),$dontTouch)) continue;
|
if (in_array($currentObjects[$i] -> getDn(), $dontTouch)) continue;
|
||||||
if (!$currentObjects[$i] -> deleteOneObjectInRelation($object,$attr,$objectType,$attrValue,$canEditFunction,$attrValues)) {
|
if (!$currentObjects[$i] -> deleteOneObjectInRelation($object, $attr, $objectType, $attrValue, $canEditFunction, $attrValues)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$type=$this -> getType();
|
$type = $this -> getType();
|
||||||
foreach($listDns as $dn) {
|
foreach($listDns as $dn) {
|
||||||
if (in_array($dn,$dontTouch)) continue;
|
if (in_array($dn, $dontTouch)) continue;
|
||||||
$obj = new $type();
|
$obj = new $type();
|
||||||
if ($obj -> loadData($dn)) {
|
if ($obj -> loadData($dn)) {
|
||||||
if (!$obj -> addOneObjectInRelation($object,$attr,$objectType,$attrValue,$canEditFunction)) {
|
if (!$obj -> addOneObjectInRelation($object, $attr, $objectType, $attrValue, $canEditFunction)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1863,7 +1861,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
||||||
* @retval mixed Array of valid IOformats of this object type
|
* @retval mixed Array of valid IOformats of this object type
|
||||||
**/
|
**/
|
||||||
public function listValidIOformats() {
|
public function listValidIOformats() {
|
||||||
$ret=array();
|
$ret = array();
|
||||||
$ioFormats = $this -> getConfig('ioFormat');
|
$ioFormats = $this -> getConfig('ioFormat');
|
||||||
if (is_array($ioFormats)) {
|
if (is_array($ioFormats)) {
|
||||||
foreach($ioFormats as $name => $conf) {
|
foreach($ioFormats as $name => $conf) {
|
||||||
|
@ -2109,7 +2107,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
||||||
if (empty($values)) {
|
if (empty($values)) {
|
||||||
return $return." empty\n";
|
return $return." empty\n";
|
||||||
}
|
}
|
||||||
if (!is_array($values)) $values = array($values);
|
$values = ensureIsArray($values);
|
||||||
|
|
||||||
// Truncate values if too long
|
// Truncate values if too long
|
||||||
for ($i=0; $i < count($values); $i++)
|
for ($i=0; $i < count($values); $i++)
|
||||||
|
|
|
@ -112,7 +112,7 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
case 'canEdit_attribute':
|
case 'canEdit_attribute':
|
||||||
return $this -> getConfig($key);
|
return $this -> getConfig($key);
|
||||||
case 'linkAttributeValues':
|
case 'linkAttributeValues':
|
||||||
$linkAttributeValues = (is_array($this -> linkAttributeOtherValues)?$this -> linkAttributeOtherValues:array());
|
$linkAttributeValues = ensureIsArray($this -> linkAttributeOtherValues);
|
||||||
if ($this -> linkAttributeValue)
|
if ($this -> linkAttributeValue)
|
||||||
$linkAttributeValues[] = $this -> linkAttributeValue;
|
$linkAttributeValues[] = $this -> linkAttributeValue;
|
||||||
return $linkAttributeValues;
|
return $linkAttributeValues;
|
||||||
|
@ -761,9 +761,7 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
|
|
||||||
// Check additional required parameters
|
// Check additional required parameters
|
||||||
if ($additional_required_parameters) {
|
if ($additional_required_parameters) {
|
||||||
if (!is_array($additional_required_parameters))
|
foreach(ensureIsArray($additional_required_parameters) as $p) {
|
||||||
$additional_required_parameters = array($additional_required_parameters);
|
|
||||||
foreach($additional_required_parameters as $p) {
|
|
||||||
if (!isset($_REQUEST[$p])) {
|
if (!isset($_REQUEST[$p])) {
|
||||||
self :: log_warning("Parameter '$p' is missing.");
|
self :: log_warning("Parameter '$p' is missing.");
|
||||||
LSerror :: addErrorCode('LSsession_12');
|
LSerror :: addErrorCode('LSsession_12');
|
||||||
|
|
Loading…
Reference in a new issue