Merge branch '7.0' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2018-03-20 20:07:24 +01:00
commit fc50fcd59e
3 changed files with 148 additions and 133 deletions

View File

@ -177,20 +177,10 @@ class Ldap
if ($connected) break; if ($connected) break;
if (empty($host)) continue; 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) { if ($this->serverPing($host, $this->serverPort) === true) {
$this->connection = ldap_connect($host,$this->serverPort); $this->connection = ldap_connect($host, $this->serverPort);
} }
else continue; else continue;
}
if (is_resource($this->connection)) if (is_resource($this->connection))
{ {
@ -742,6 +732,10 @@ class Ldap
if (preg_match('/^ldaps:\/\/([^\/]+)\/?$/',$host, $regs)) { if (preg_match('/^ldaps:\/\/([^\/]+)\/?$/',$host, $regs)) {
$host = 'ssl://'.$regs[1]; $host = 'ssl://'.$regs[1];
} }
// Remove ldap://
if (preg_match('/^ldap:\/\/([^\/]+)\/?$/',$host, $regs)) {
$host = $regs[1];
}
$op = @fsockopen($host, $port, $errno, $errstr, $timeout); $op = @fsockopen($host, $port, $errno, $errstr, $timeout);
if (!$op) return false; //DC is N/A if (!$op) return false; //DC is N/A
else { else {

View File

@ -802,15 +802,15 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
} }
// Personalized field {XXX-1} à {XXX-9} // Personalized field {XXX-1} à {XXX-9}
/*$maskperso=array(); $maskperso=array();
$maskpersonew=array(); $maskpersonew=array();
$tmpmask=$mask; $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].'\}'; $maskperso[$regKey[1]]='{'.$regKey[1].'-'.$regKey[2].'}';
$maskpersonew[$regKey[1]]=str_pad('', '_', $regKey[2], STR_PAD_RIGHT); $maskpersonew[$regKey[1]]=str_pad('', $regKey[2], '_', STR_PAD_RIGHT);
$tmpmask=preg_replace('/\{'.$regKey[1].'\-'.$regKey[2].'\}/i', $maskpersonew, $tmpmask); $tmpmask=preg_replace('/\{'.$regKey[1].'\-'.$regKey[2].'\}/i', $maskpersonew[$regKey[1]], $tmpmask);
}*/ }
if (strstr($mask,'user_extra_')) 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('/\{(c+)(0*)\}/i',$maskrefclient,$maskwithonlyymcode);
$maskwithonlyymcode=preg_replace('/\{(t+)\}/i',$masktype_value,$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{(t+)\}/i',$masktype_value,$maskwithonlyymcode);
$maskwithonlyymcode=preg_replace('/\{(u+)\}/i',$maskuser_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=$maskwithonlyymcode;
$maskwithnocode=preg_replace('/\{yyyy\}/i','yyyy',$maskwithnocode); $maskwithnocode=preg_replace('/\{yyyy\}/i','yyyy',$maskwithnocode);
$maskwithnocode=preg_replace('/\{yy\}/i','yy',$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 ($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 ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
if ($maskuser) $maskLike = str_replace(dol_string_nospecial('{'.$maskuser.'}'),$maskuser_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 // Get counter in database
$counter=0; $counter=0;

View File

@ -261,22 +261,29 @@ if ($action == 'update')
// Update // Update
$verif = $object->update($user); $verif = $object->update($user);
if ($verif > 0)
if ($verif <= 0)
{ {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); setEventMessages($object->error, $object->errors, 'warnings');
exit; $action='edit';
} }
else 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;
}
}
} else {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit; exit;
} }
}
else
{
setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
$action='';
}
}
else
{
setEventMessages($langs->trans("ErrorBadStatus"), null, 'errors');
$action='';
}
} }
// If delete of request // If delete of request
@ -299,7 +306,9 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights-
} }
else else
{ {
$error = $langs->trans('ErrorCantDeleteCP'); $error++;
setEventMessages($langs->trans('ErrorCantDeleteCP'), null, 'errors');
$action='';
} }
} }
@ -393,26 +402,28 @@ if ($action == 'confirm_send')
$trackid='leav'.$object->id; $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 // Envoi du mail
$result=$mail->sendfile(); $result=$mail->sendfile();
if (!$result) if (!$result)
{ {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error); setEventMessages($mail->error, $mail->errors, 'warnings');
exit; $action='';
}
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
} }
else else
{ {
// Sinon on affiche le formulaire de demande avec le message d'erreur SQL header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error);
exit; exit;
} }
} }
else
{
setEventMessages($object->error, $object->errors, 'errors');
$action='';
}
}
} }
@ -481,29 +492,31 @@ if ($action == 'confirm_valid')
$trackid='leav'.$object->id; $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 // Envoi du mail
$result=$mail->sendfile(); $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); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit; 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']))
{ {
@ -513,10 +526,10 @@ if ($action == 'confirm_refuse')
// Si statut en attente de validation et valideur = utilisateur // Si statut en attente de validation et valideur = utilisateur
if ($object->statut == 2 && $user->id == $object->fk_validator) 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->fk_user_refuse = $user->id;
$object->statut = 5; $object->statut = 5;
$object->detail_refuse = $_POST['detail_refuse']; $object->detail_refuse = GETPOST('detail_refuse','alphanohtml');
$verif = $object->update($user); $verif = $object->update($user);
@ -558,29 +571,31 @@ if ($action == 'confirm_refuse')
$trackid='leav'.$object->id; $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 // Envoi du mail
$result=$mail->sendfile(); $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); header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit; 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 { } else {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=NoMotifRefuse'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DetailRefusCP")), null, 'errors');
exit; $action='refuse';
} }
} }
@ -588,6 +603,8 @@ if ($action == 'confirm_refuse')
// Si Validation de la demande // Si Validation de la demande
if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes') if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes')
{ {
$error = 0;
$object = new Holiday($db); $object = new Holiday($db);
$object->fetch($id); $object->fetch($id);
@ -597,7 +614,8 @@ if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes')
$result = $object->update($user); $result = $object->update($user);
if ($result < 0) if ($result < 0)
{ {
$error = $langs->trans('ErrorBackToDraft'); $error++;
setEventMessages($langs->trans('ErrorBackToDraft').' '.$object->error, $object->errors, 'errors');
} }
if (! $error) if (! $error)
@ -616,6 +634,8 @@ if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes')
// Si Validation de la demande // Si Validation de la demande
if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes')
{ {
$error = 0;
$object = new Holiday($db); $object = new Holiday($db);
$object->fetch($id); $object->fetch($id);
@ -647,7 +667,8 @@ if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes')
if ($result1 < 0 || $result2 < 0) 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; $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 // Envoi du mail
$result=$mail->sendfile(); $result=$mail->sendfile();
if(!$result) if (!$result)
{ {
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=mail&error_content='.$mail->error); setEventMessages($mail->error, $mail->errors, 'warnings');
exit; $action='';
}
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
} }
else else
{ {
// Sinon on affiche le formulaire de demande avec le message d'erreur SQL header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&error=SQL_Create&msg='.$object->error);
exit; exit;
} }
}
} }
} }
@ -1010,48 +1026,8 @@ else
// On vérifie si l'utilisateur à le droit de lire cette demande // On vérifie si l'utilisateur à le droit de lire cette demande
if ($cancreate) 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); $head=holiday_prepare_head($object);
if ($action == 'edit' && $object->statut == 1) if ($action == 'edit' && $object->statut == 1)
{ {
$edit = true; $edit = true;
@ -1244,6 +1220,47 @@ else
dol_fiche_end(); 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) if ($action == 'edit' && $object->statut == 1)
{ {
print '<div align="center">'; print '<div align="center">';