From f504716501adf9c9cd4ee8fe6a0c827dc8ed837a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Dec 2017 16:16:31 +0100 Subject: [PATCH] Fix sync contact - external user --- htdocs/contact/class/contact.class.php | 68 +++- htdocs/core/class/commonobject.class.php | 8 +- htdocs/user/card.php | 455 ++++++++++++----------- htdocs/user/class/user.class.php | 64 +++- htdocs/website/index.php | 9 +- 5 files changed, 370 insertions(+), 234 deletions(-) diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 494533fce75..08fe253dffd 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -267,9 +267,10 @@ class Contact extends CommonObject * @param User $user Objet user making change * @param int $notrigger 0=no, 1=yes * @param string $action Current action for hookmanager + * @param int $nosyncuser No sync linked user (external users and contacts are linked) * @return int <0 if KO, >0 if OK */ - function update($id, $user=null, $notrigger=0, $action='update') + function update($id, $user=null, $notrigger=0, $action='update', $nosyncuser=0) { global $conf, $langs, $hookmanager; @@ -353,12 +354,69 @@ class Contact extends CommonObject } else if ($reshook < 0) $error++; + if (! $error && $this->user_id > 0) + { + $tmpobj = new User($this->db); + $tmpobj->fetch($this->user_id); + $usermustbemodified = 0; + if ($tmpobj->office_phone != $this->phone_pro) + { + $tmpobj->office_phone = $this->phone_pro; + $usermustbemodified++; + } + if ($tmpobj->office_fax != $this->fax) + { + $tmpobj->office_fax = $this->fax; + $usermustbemodified++; + } + if ($tmpobj->address != $this->address) + { + $tmpobj->address = $this->address; + $usermustbemodified++; + } + if ($tmpobj->town != $this->town) + { + $tmpobj->town = $this->town; + $usermustbemodified++; + } + if ($tmpobj->zip != $this->zip) + { + $tmpobj->zip = $this->zip; + $usermustbemodified++; + } + if ($tmpobj->zip != $this->zip) + { + $tmpobj->state_id=$this->state_id; + $usermustbemodified++; + } + if ($tmpobj->country_id != $this->country_id) + { + $tmpobj->country_id = $this->country_id; + $usermustbemodified++; + } + if ($tmpobj->email != $this->email) + { + $tmpobj->email = $this->email; + $usermustbemodified++; + } + if ($tmpobj->skype != $this->skype) + { + $tmpobj->skype = $this->skype; + $usermustbemodified++; + } + if ($usermustbemodified) + { + $result=$tmpobj->update($user, 0, 1, 1, 1); + if ($result < 0) { $error++; } + } + } + if (! $error && ! $notrigger) { - // Call trigger - $result=$this->call_trigger('CONTACT_MODIFY',$user); - if ($result < 0) { $error++; } - // End call triggers + // Call trigger + $result=$this->call_trigger('CONTACT_MODIFY',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 25d9f67a219..a375593dc2d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -505,18 +505,18 @@ abstract class CommonObject if (! empty($this->phone_perso)) { $out.=dol_print_phone($this->phone_perso,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePerso")); $outdone++; } - if (! empty($this->fax)) { - $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; - } if (! empty($this->office_phone)) { $out.=dol_print_phone($this->office_phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; } if (! empty($this->user_mobile)) { $out.=dol_print_phone($this->user_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; } - if (! empty($this->office_fax)) { + if (! empty($this->fax)) { $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; } + if (! empty($this->office_fax)) { + $out.=dol_print_phone($this->office_fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; + } $out.='
'; $outdone=0; diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 6444faa3958..7b5a9f29be4 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -413,7 +413,7 @@ if (empty($reshook)) { } if (!$error && GETPOSTISSET('contactid')) { - $contactid = GETPOST('contactid', 'int'); + $contactid = GETPOST('contactid', 'int'); if ($contactid > 0) { $contact = new Contact($db); @@ -765,33 +765,6 @@ if ($action == 'create' || $action == 'adduserldap') } print ''; - // Employee - $defaultemployee=1; - print ''; - print ''.$langs->trans('Employee').''; - print $form->selectyesno("employee",(GETPOST('employee')!=''?GETPOST('employee'):$defaultemployee),1); - print ''; - - // Position/Job - print ''.$langs->trans("PostOrFunction").''; - print ''; - print ''; - print ''; - - // Gender - print ''.$langs->trans("Gender").''; - print ''; - $arraygender=array('man'=>$langs->trans("Genderman"),'woman'=>$langs->trans("Genderwoman")); - print $form->selectarray('gender', $arraygender, GETPOST('gender'), 1); - print ''; - - // Date employment - print ''.$langs->trans("DateToBirth").''; - print ''; - echo $form->select_date(GETPOST('birth'),'birth',0,0,1,'createuser',1,0,1); - print ''; - print "\n"; - // Login print ''.$langs->trans("Login").''; print ''; @@ -912,8 +885,33 @@ if ($action == 'create' || $action == 'adduserldap') print $form->textwithpicto($langs->trans("Internal"),$langs->trans("InternalExternalDesc"), 1, 'help', '', 0, 2); print ''; + // Gender + print ''.$langs->trans("Gender").''; + print ''; + $arraygender=array('man'=>$langs->trans("Genderman"),'woman'=>$langs->trans("Genderwoman")); + print $form->selectarray('gender', $arraygender, GETPOST('gender'), 1); + print ''; + + // Employee + $defaultemployee=1; + print ''; + print ''.$langs->trans('Employee').''; + print $form->selectyesno("employee",(GETPOST('employee')!=''?GETPOST('employee'):$defaultemployee),1); + print ''; + + // Hierarchy + print ''.$langs->trans("HierarchicalResponsible").''; + print ''; + print $form->select_dolusers($object->fk_user, 'fk_user', 1, array($object->id), 0, '', 0, $conf->entity, 0, 0, '', 0, '', 'maxwidth300'); + print ''; + print "\n"; + + + print '
'; + + // Address - print ''; + print ''; print ''; @@ -1024,62 +1022,6 @@ if ($action == 'create' || $action == 'adduserldap') print ''; } - // TODO Move this into tab RH (HierarchicalResponsible must be on both tab) - - // Hierarchy - print ''; - print ''; - print "\n"; - - if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) - || (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read))) - { - $langs->load("salaries"); - - // THM - print ''; - print ''; - print "\n"; - - // TJM - print ''; - print ''; - print "\n"; - - // Salary - print ''; - print ''; - print "\n"; - } - - // Weeklyhours - print ''; - print ''; - print "\n"; - - // Date employment - print ''; - print ''; - print "\n"; - // User color if (! empty($conf->agenda->enabled)) { @@ -1143,6 +1085,73 @@ if ($action == 'create' || $action == 'adduserldap') print $doleditor->Create(1); print ''; + + print '
'.fieldLabel('Address','address').'
'.fieldLabel('Address','address').'
'.$langs->trans("HierarchicalResponsible").''; - print $form->select_dolusers($object->fk_user, 'fk_user', 1, array($object->id), 0, '', 0, $conf->entity, 0, 0, '', 0, '', 'maxwidth300'); - print '
'; - $text=$langs->trans("THM"); - print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm'); - print ''; - print ''; - print '
'; - $text=$langs->trans("TJM"); - print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classtjm'); - print ''; - print ''; - print '
'.$langs->trans("Salary").''; - print ''; - print '
'.$langs->trans("WeeklyHours").''; - print ''; - print '
'.$langs->trans("DateEmployment").''; - echo $form->select_date(GETPOST('dateemployment'),'dateemployment',0,0,1,'form'.'dateemployment',1,0,1); - print '

'; + + + // TODO Move this into tab RH (HierarchicalResponsible must be on both tab) + + // Position/Job + print ''; + print ''; + + + if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) + || (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read))) + { + $langs->load("salaries"); + + // THM + print ''; + print ''; + print "\n"; + + // TJM + print ''; + print ''; + print "\n"; + + // Salary + print ''; + print ''; + print "\n"; + } + + // Weeklyhours + print ''; + print ''; + print "\n"; + + // Date employment + print ''; + print ''; + print "\n"; + + // Date birth + print ''; + print ''; + print "\n"; + print "
'.$langs->trans("PostOrFunction").''; + print ''; + print '
'; + $text=$langs->trans("THM"); + print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm'); + print ''; + print ''; + print '
'; + $text=$langs->trans("TJM"); + print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classtjm'); + print ''; + print ''; + print '
'.$langs->trans("Salary").''; + print ''; + print '
'.$langs->trans("WeeklyHours").''; + print ''; + print '
'.$langs->trans("DateEmployment").''; + echo $form->select_date(GETPOST('dateemployment'),'dateemployment',0,0,1,'form'.'dateemployment',1,0,1); + print '
'.$langs->trans("DateToBirth").''; + echo $form->select_date(GETPOST('birth'),'birth',0,0,1,'createuser',1,0,1); + print '
\n"; dol_fiche_end(); @@ -1337,31 +1346,8 @@ else } print ''."\n"; - // Employee - print ''.$langs->trans("Employee").''; - print yn($object->employee); - print ''."\n"; - - // Position/Job - print ''.$langs->trans("PostOrFunction").''; - print ''.$object->job.''; - print ''."\n"; - - // Gender - print ''.$langs->trans("Gender").''; - print ''; - if ($object->gender) print $langs->trans("Gender".$object->gender); - print ''; - - // Date of birth - print ''.$langs->trans("DateToBirth").''; - print ''; - print dol_print_date($object->birth, 'day'); - print ''; - print "\n"; - // API key - if(! empty($conf->api->enabled) && $user->admin) { + if (! empty($conf->api->enabled) && $user->admin) { print ''.$langs->trans("ApiKey").''; print ''; if (! empty($object->api_key)) print preg_replace('/./','*',$object->api_key); @@ -1403,12 +1389,16 @@ else print ''."\n"; } - // Accountancy code - if ($conf->accounting->enabled) - { - print ''.$langs->trans("AccountancyCode").''; - print ''.$object->accountancy_code.''; - } + // Gender + print ''.$langs->trans("Gender").''; + print ''; + if ($object->gender) print $langs->trans("Gender".$object->gender); + print ''; + + // Employee + print ''.$langs->trans("Employee").''; + print yn($object->employee); + print ''."\n"; // TODO Move this into tab RH, visible when salarie or RH is visible (HierarchicalResponsible must be on both tab) @@ -1424,6 +1414,11 @@ else print ''; print "\n"; + // Position/Job + print ''.$langs->trans("PostOrFunction").''; + print ''.$object->job.''; + print ''."\n"; + //$childids = $user->getAllChildIds(1); if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) @@ -1475,6 +1470,20 @@ else print ''; print "\n"; + // Date of birth + print ''.$langs->trans("DateToBirth").''; + print ''; + print dol_print_date($object->birth, 'day'); + print ''; + print "\n"; + + // Accountancy code + if ($conf->accounting->enabled) + { + print ''.$langs->trans("AccountancyCode").''; + print ''.$object->accountancy_code.''; + } + print ''; print ''; @@ -1818,7 +1827,7 @@ else // Ref/ID if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) { - print ''.$langs->trans("Ref").''; + print ''.$langs->trans("Ref").''; print ''; print $object->id; print ''; @@ -1827,7 +1836,7 @@ else // Lastname print ""; - print ''.$langs->trans("Lastname").''; + print ''.$langs->trans("Lastname").''; print ''; if ($caneditfield && !$object->ldap_sid) { @@ -1855,40 +1864,6 @@ else } print ''; - // Employee - print ''; - print ''.fieldLabel('Employee','employee',0).''; - print $form->selectyesno("employee",$object->employee,1); - print ''; - - // Position/Job - print ''.$langs->trans("PostOrFunction").''; - print ''; - if ($caneditfield) - { - print ''; - } - else - { - print ''; - print $object->job; - } - print ''; - - // Gender - print ''.$langs->trans("Gender").''; - print ''; - $arraygender=array('man'=>$langs->trans("Genderman"),'woman'=>$langs->trans("Genderwoman")); - print $form->selectarray('gender', $arraygender, GETPOST('gender')?GETPOST('gender'):$object->gender, 1); - print ''; - - // Date birth - print ''.$langs->trans("DateToBirth").''; - print ''; - echo $form->select_date(GETPOST('birth')?GETPOST('birth'):$object->birth,'birth',0,0,1,'updateuser',1,0,1); - print ''; - print "\n"; - // Login print "".''.$langs->trans("Login").''; print ''; @@ -2039,8 +2014,42 @@ else } print ''; + // Gender + print ''.$langs->trans("Gender").''; + print ''; + $arraygender=array('man'=>$langs->trans("Genderman"),'woman'=>$langs->trans("Genderwoman")); + print $form->selectarray('gender', $arraygender, GETPOST('gender')?GETPOST('gender'):$object->gender, 1); + print ''; + + // Employee + print ''; + print ''.fieldLabel('Employee','employee',0).''; + print $form->selectyesno("employee",$object->employee,1); + print ''; + + // Hierarchy + print ''.$langs->trans("HierarchicalResponsible").''; + print ''; + if ($caneditfield) + { + print $form->select_dolusers($object->fk_user, 'fk_user', 1, array($object->id), 0, '', 0, $object->entity, 0, 0, '', 0, '', 'maxwidth300'); + } + else + { + print ''; + $huser=new User($db); + $huser->fetch($object->fk_user); + print $huser->getNomUrl(1); + } + print ''; + print "\n"; + + + print '
'; + + // Address - print ''; + print ''; print ''; @@ -2159,6 +2168,8 @@ else print ''; } + print '
'.fieldLabel('Address','address').'
'.fieldLabel('Address','address').'

'; + // Accountancy code if ($conf->accounting->enabled) { @@ -2178,72 +2189,6 @@ else print ""; } - // TODO Move this into tab RH (HierarchicalResponsible must be on both tab) - - // Hierarchy - print ''; - print ''; - print "\n"; - - if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) - || (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read))) - { - $langs->load("salaries"); - - // THM - print ''; - print ''; - print "\n"; - - // TJM - print ''; - print ''; - print "\n"; - - // Salary - print ''; - print ''; - print "\n"; - } - - // Weeklyhours - print ''; - print ''; - print "\n"; - - // Date employment - print ''; - print ''; - print "\n"; - // User color if (! empty($conf->agenda->enabled)) { @@ -2372,6 +2317,80 @@ else } print ''; + + print '
'.$langs->trans("HierarchicalResponsible").''; - if ($caneditfield) - { - print $form->select_dolusers($object->fk_user, 'fk_user', 1, array($object->id), 0, '', 0, $object->entity, 0, 0, '', 0, '', 'maxwidth300'); - } - else - { - print ''; - $huser=new User($db); - $huser->fetch($object->fk_user); - print $huser->getNomUrl(1); - } - print '
'; - $text=$langs->trans("THM"); - print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm'); - print ''; - print ''; - print '
'; - $text=$langs->trans("TJM"); - print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classthm'); - print ''; - print ''; - print '
'.$langs->trans("Salary").''; - print ''; - print '
'.$langs->trans("WeeklyHours").''; - print ''; - print '
'.$langs->trans("DateEmployment").''; - echo $form->select_date(GETPOST('dateemployment')?GETPOST('dateemployment'):$object->dateemployment,'dateemployment',0,0,1,'form'.'dateemployment',1,0,1); - print '

'; + + + // TODO Move this into tab RH (HierarchicalResponsible must be on both tab) + + // Position/Job + print ''; + print ''; + + if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) + || (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read))) + { + $langs->load("salaries"); + + // THM + print ''; + print ''; + print "\n"; + + // TJM + print ''; + print ''; + print "\n"; + + // Salary + print ''; + print ''; + print "\n"; + } + + // Weeklyhours + print ''; + print ''; + print "\n"; + + // Date employment + print ''; + print ''; + print "\n"; + + // Date birth + print ''; + print ''; + print "\n"; + print '
'.$langs->trans("PostOrFunction").''; + if ($caneditfield) + { + print ''; + } + else + { + print ''; + print $object->job; + } + print '
'; + $text=$langs->trans("THM"); + print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm'); + print ''; + print ''; + print '
'; + $text=$langs->trans("TJM"); + print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classthm'); + print ''; + print ''; + print '
'.$langs->trans("Salary").''; + print ''; + print '
'.$langs->trans("WeeklyHours").''; + print ''; + print '
'.$langs->trans("DateEmployment").''; + echo $form->select_date(GETPOST('dateemployment')?GETPOST('dateemployment'):$object->dateemployment,'dateemployment',0,0,1,'form'.'dateemployment',1,0,1); + print '
'.$langs->trans("DateToBirth").''; + echo $form->select_date(GETPOST('birth')?GETPOST('birth'):$object->birth,'birth',0,0,1,'updateuser',1,0,1); + print '
'; dol_fiche_end(); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index e7b31400bc0..f8b263b49a4 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1011,7 +1011,7 @@ class User extends CommonObject * @param int $notrigger 1=do not execute triggers, 0 otherwise * @return int <0 if KO, id of created user if OK */ - function create($user,$notrigger=0) + function create($user, $notrigger=0) { global $conf,$langs; global $mysoc; @@ -1337,9 +1337,10 @@ class User extends CommonObject * @param int $notrigger 1 ne declenche pas les triggers, 0 sinon * @param int $nosyncmember 0=Synchronize linked member (standard info), 1=Do not synchronize linked member * @param int $nosyncmemberpass 0=Synchronize linked member (password), 1=Do not synchronize linked member + * @param int $nosynccontact 0=Synchronize linked contact, 1=Do not synchronize linked contact * @return int <0 si KO, >=0 si OK */ - function update($user,$notrigger=0,$nosyncmember=0,$nosyncmemberpass=0) + function update($user, $notrigger=0, $nosyncmember=0, $nosyncmemberpass=0, $nosynccontact=0) { global $conf, $langs; @@ -1474,7 +1475,7 @@ class User extends CommonObject require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - // This user is linked with a member, so we also update members informations + // This user is linked with a member, so we also update member information // if this is an update. $adh=new Adherent($this->db); $result=$adh->fetch($this->fk_member); @@ -1496,8 +1497,6 @@ class User extends CommonObject $adh->phone=$this->office_phone; $adh->phone_mobile=$this->user_mobile; - $adh->note=$this->note; - $adh->user_id=$this->id; $adh->user_login=$this->login; @@ -1517,6 +1516,61 @@ class User extends CommonObject $error++; } } + + if ($this->contact_id > 0 && ! $nosynccontact) + { + dol_syslog(get_class($this)."::update user is linked with a contact. We try to update contact too.", LOG_DEBUG); + + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; + + // This user is linked with a contact, so we also update contact information + // if this is an update. + $tmpobj=new Contact($this->db); + $result=$tmpobj->fetch($this->contact_id); + + if ($result >= 0) + { + $tmpobj->firstname=$this->firstname; + $tmpobj->lastname=$this->lastname; + $tmpobj->login=$this->login; + $tmpobj->gender=$this->gender; + $tmpobj->birth=$this->birth; + + //$tmpobj->pass=$this->pass; + + //$tmpobj->societe=(empty($tmpobj->societe) && $this->societe_id ? $this->societe_id : $tmpobj->societe); + + $tmpobj->email=$this->email; + $tmpobj->skype=$this->skype; + $tmpobj->phone_pro=$this->office_phone; + $tmpobj->phone_mobile=$this->user_mobile; + $tmpobj->fax=$this->office_fax; + + $tmpobj->address=$this->address; + $tmpobj->town=$this->town; + $tmpobj->zip=$this->zip; + $tmpobj->state_id=$this->state_id; + $tmpobj->country_id=$this->country_id; + + $tmpobj->user_id=$this->id; + $tmpobj->user_login=$this->login; + + $result=$tmpobj->update($tmpobj->id, $user, 0, 'update', 1); + if ($result < 0) + { + $this->error=$tmpobj->error; + $this->errors=$tmpobj->errors; + dol_syslog(get_class($this)."::update error after calling adh->update to sync it with user: ".$this->error, LOG_ERR); + $error++; + } + } + else + { + $this->error=$tmpobj->error; + $this->errors=$tmpobj->errors; + $error++; + } + } } $action='update'; diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 96120b278c1..505bfdc9a6a 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -1622,7 +1622,7 @@ $head = array(); /* - * Edit Site HTML header of CSS + * Edit Site HTML header and CSS */ if ($action == 'editcss') @@ -1672,7 +1672,12 @@ if ($action == 'editcss') $htmlheadercontent.=''."\n"; $htmlheadercontent.=""; } - else $htmlheadercontent=''."\n".trim($htmlheadercontent)."\n".''; + else + { + $htmlheadercontent = preg_replace('/^\s*/ims', '', $htmlheadercontent); + $htmlheadercontent = preg_replace('/<\/html>\s*$/ims', '', $htmlheadercontent); + $htmlheadercontent=''."\n".trim($htmlheadercontent)."\n".''; + } if (GETPOST('editcss','alpha') || GETPOST('refreshpage','alpha')) {