diff --git a/htdocs/core/class/ldap.class.php b/htdocs/core/class/ldap.class.php index 3d92d5f9019..8fcdf53b4a6 100644 --- a/htdocs/core/class/ldap.class.php +++ b/htdocs/core/class/ldap.class.php @@ -177,20 +177,10 @@ class Ldap if ($connected) break; if (empty($host)) continue; - if (preg_match('/^ldap/',$host)) - { - if ($this->serverPing($host) === true) { - $this->connection = ldap_connect($host); - } - else continue; - } - else - { - if ($this->serverPing($host, $this->serverPort) === true) { - $this->connection = ldap_connect($host,$this->serverPort); - } - else continue; + if ($this->serverPing($host, $this->serverPort) === true) { + $this->connection = ldap_connect($host, $this->serverPort); } + else continue; if (is_resource($this->connection)) { @@ -742,6 +732,10 @@ class Ldap if (preg_match('/^ldaps:\/\/([^\/]+)\/?$/',$host, $regs)) { $host = 'ssl://'.$regs[1]; } + // Remove ldap:// + if (preg_match('/^ldap:\/\/([^\/]+)\/?$/',$host, $regs)) { + $host = $regs[1]; + } $op = @fsockopen($host, $port, $errno, $errstr, $timeout); if (!$op) return false; //DC is N/A else { diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index e3a20533de0..dc223f58ec3 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -802,15 +802,15 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m } // Personalized field {XXX-1} à {XXX-9} - /*$maskperso=array(); + $maskperso=array(); $maskpersonew=array(); $tmpmask=$mask; - while (preg_match('/\{([A-Z]+)\-([1-9])\}/i',$tmpmask,$regKey)) + while (preg_match('/\{([A-Z]+)\-([1-9])\}/',$tmpmask,$regKey)) { - $maskperso[$regKey[1]]='\{'.$regKey[1]+'\-'.$regKey[2].'\}'; - $maskpersonew[$regKey[1]]=str_pad('', '_', $regKey[2], STR_PAD_RIGHT); - $tmpmask=preg_replace('/\{'.$regKey[1].'\-'.$regKey[2].'\}/i', $maskpersonew, $tmpmask); - }*/ + $maskperso[$regKey[1]]='{'.$regKey[1].'-'.$regKey[2].'}'; + $maskpersonew[$regKey[1]]=str_pad('', $regKey[2], '_', STR_PAD_RIGHT); + $tmpmask=preg_replace('/\{'.$regKey[1].'\-'.$regKey[2].'\}/i', $maskpersonew[$regKey[1]], $tmpmask); + } if (strstr($mask,'user_extra_')) { @@ -827,10 +827,10 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m $maskwithonlyymcode=preg_replace('/\{(c+)(0*)\}/i',$maskrefclient,$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{(t+)\}/i',$masktype_value,$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{(u+)\}/i',$maskuser_value,$maskwithonlyymcode); - /*foreach($maskperso as $key => $val) + foreach($maskperso as $key => $val) { - $maskwithonlyymcode=preg_replace('/'.$val.'/i', $maskpersonew[$key], $maskwithonlyymcode); - }*/ + $maskwithonlyymcode=preg_replace('/'.preg_quote($val,'/').'/i', $maskpersonew[$key], $maskwithonlyymcode); + } $maskwithnocode=$maskwithonlyymcode; $maskwithnocode=preg_replace('/\{yyyy\}/i','yyyy',$maskwithnocode); $maskwithnocode=preg_replace('/\{yy\}/i','yy',$maskwithnocode); @@ -974,6 +974,10 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike); if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike); if ($maskuser) $maskLike = str_replace(dol_string_nospecial('{'.$maskuser.'}'),$maskuser_value,$maskLike); + foreach($maskperso as $key => $val) + { + $maskLike = str_replace(dol_string_nospecial($maskperso[$key]),$maskpersonew[$key],$maskLike); + } // Get counter in database $counter=0; diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index 23744912c9b..c653c756bba 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -261,21 +261,28 @@ if ($action == 'update') // Update $verif = $object->update($user); - if ($verif > 0) - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } - else - { - // Otherwise we display the request form with the SQL error message - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=SQL_Create&msg='.$object->error); - exit; - } + + if ($verif <= 0) + { + setEventMessages($object->error, $object->errors, 'warnings'); + $action='edit'; + } + else + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } } - } else { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; + else + { + setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); + $action=''; + } + } + else + { + setEventMessages($langs->trans("ErrorBadStatus"), null, 'errors'); + $action=''; } } @@ -299,7 +306,9 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights- } else { - $error = $langs->trans('ErrorCantDeleteCP'); + $error++; + setEventMessages($langs->trans('ErrorCantDeleteCP'), null, 'errors'); + $action=''; } } @@ -393,24 +402,26 @@ if ($action == 'confirm_send') $trackid='leav'.$object->id; - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, null, null, null, '', '', 0, 0, '', '', $trackid); + $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); // Envoi du mail $result=$mail->sendfile(); if (!$result) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error); - exit; + setEventMessages($mail->error, $mail->errors, 'warnings'); + $action=''; + } + else + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; } - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; } else { - // Sinon on affiche le formulaire de demande avec le message d'erreur SQL - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error); - exit; + setEventMessages($object->error, $object->errors, 'errors'); + $action=''; } } } @@ -481,31 +492,33 @@ if ($action == 'confirm_valid') $trackid='leav'.$object->id; - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, null, null, null, '', '', 0, 0, '', '', $trackid); + $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); // Envoi du mail $result=$mail->sendfile(); - if (!$result) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error); - exit; + if (!$result) + { + setEventMessages($mail->error, $mail->errors, 'warnings'); + $action=''; + } + else + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; } - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } else { - // Sinon on affiche le formulaire de demande avec le message d'erreur SQL - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error); - exit; } - + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $action=''; + } } - } -if ($action == 'confirm_refuse') +if ($action == 'confirm_refuse' && GETPOST('confirm','alpha') == 'yes') { - if (! empty($_POST['detail_refuse'])) + if (! empty($_POST['detail_refuse'])) { $object = new Holiday($db); $object->fetch($id); @@ -513,10 +526,10 @@ if ($action == 'confirm_refuse') // Si statut en attente de validation et valideur = utilisateur if ($object->statut == 2 && $user->id == $object->fk_validator) { - $object->date_refuse = date('Y-m-d H:i:s', time()); + $object->date_refuse = dol_print_date('dayhour', dol_now()); $object->fk_user_refuse = $user->id; $object->statut = 5; - $object->detail_refuse = $_POST['detail_refuse']; + $object->detail_refuse = GETPOST('detail_refuse','alphanohtml'); $verif = $object->update($user); @@ -558,29 +571,31 @@ if ($action == 'confirm_refuse') $trackid='leav'.$object->id; - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, null, null, null, '', '', 0, 0, '', '', $trackid); + $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); // Envoi du mail $result=$mail->sendfile(); - if(!$result) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error); - exit; + if (!$result) + { + setEventMessages($mail->error, $mail->errors, 'warnings'); + $action=''; + } + else + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; } - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; - } else { - // Sinon on affiche le formulaire de demande avec le message d'erreur SQL - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error); - exit; } - + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $action=''; + } } - } else { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=NoMotifRefuse'); - exit; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DetailRefusCP")), null, 'errors'); + $action='refuse'; } } @@ -588,6 +603,8 @@ if ($action == 'confirm_refuse') // Si Validation de la demande if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes') { + $error = 0; + $object = new Holiday($db); $object->fetch($id); @@ -597,7 +614,8 @@ if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes') $result = $object->update($user); if ($result < 0) { - $error = $langs->trans('ErrorBackToDraft'); + $error++; + setEventMessages($langs->trans('ErrorBackToDraft').' '.$object->error, $object->errors, 'errors'); } if (! $error) @@ -616,6 +634,8 @@ if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes') // Si Validation de la demande if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') { + $error = 0; + $object = new Holiday($db); $object->fetch($id); @@ -647,7 +667,8 @@ if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') if ($result1 < 0 || $result2 < 0) { - $error = $langs->trans('ErrorCantDeleteCP'); + $error++; + setEventMessages($langs->trans('ErrorCantDeleteCP').' '.$object->error, $object->errors, 'errors'); } } @@ -697,27 +718,22 @@ if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') $trackid='leav'.$object->id; - $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, null, null, null, '', '', 0, 0, '', '', $trackid); + $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid); // Envoi du mail $result=$mail->sendfile(); - if(!$result) + if (!$result) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error); - exit; + setEventMessages($mail->error, $mail->errors, 'warnings'); + $action=''; + } + else + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; } - - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit; } - else - { - // Sinon on affiche le formulaire de demande avec le message d'erreur SQL - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error); - exit; - } - } } @@ -1010,48 +1026,8 @@ else // On vérifie si l'utilisateur à le droit de lire cette demande if ($cancreate) { - if ($action == 'delete') - { - if ($user->rights->holiday->delete) - { - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleDeleteCP"),$langs->trans("ConfirmDeleteCP"),"confirm_delete", '', 0, 1); - } - } - - // Si envoi en validation - if ($action == 'sendToValidate' && $object->statut == 1) - { - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleToValidCP"),$langs->trans("ConfirmToValidCP"),"confirm_send", '', 1, 1); - } - - // Si validation de la demande - if ($action == 'valid') - { - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleValidCP"),$langs->trans("ConfirmValidCP"),"confirm_valid", '', 1, 1); - } - - // Si refus de la demande - if ($action == 'refuse') - { - $array_input = array(array('type'=>"text",'label'=> $langs->trans('DetailRefusCP'),'name'=>"detail_refuse",'size'=>"50",'value'=>"")); - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0); - } - - // Si annulation de la demande - if ($action == 'cancel') - { - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleCancelCP"),$langs->trans("ConfirmCancelCP"),"confirm_cancel", '', 1, 1); - } - - // Si back to draft - if ($action == 'backtodraft') - { - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleSetToDraft"),$langs->trans("ConfirmSetToDraft"),"confirm_draft", '', 1, 1); - } - $head=holiday_prepare_head($object); - if ($action == 'edit' && $object->statut == 1) { $edit = true; @@ -1244,6 +1220,47 @@ else dol_fiche_end(); + // Confirmation messages + if ($action == 'delete') + { + if ($user->rights->holiday->delete) + { + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleDeleteCP"),$langs->trans("ConfirmDeleteCP"),"confirm_delete", '', 0, 1); + } + } + + // Si envoi en validation + if ($action == 'sendToValidate' && $object->statut == 1) + { + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleToValidCP"),$langs->trans("ConfirmToValidCP"),"confirm_send", '', 1, 1); + } + + // Si validation de la demande + if ($action == 'valid') + { + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleValidCP"),$langs->trans("ConfirmValidCP"),"confirm_valid", '', 1, 1); + } + + // Si refus de la demande + if ($action == 'refuse') + { + $array_input = array(array('type'=>"text",'label'=> $langs->trans('DetailRefusCP'),'name'=>"detail_refuse",'size'=>"50",'value'=>"")); + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0); + } + + // Si annulation de la demande + if ($action == 'cancel') + { + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleCancelCP"),$langs->trans("ConfirmCancelCP"),"confirm_cancel", '', 1, 1); + } + + // Si back to draft + if ($action == 'backtodraft') + { + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleSetToDraft"),$langs->trans("ConfirmSetToDraft"),"confirm_draft", '', 1, 1); + } + + if ($action == 'edit' && $object->statut == 1) { print '