dolibarr  20.0.0-beta
perso.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
6  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 // Load Dolibarr environment
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array('companies', 'other'));
36 
37 $id = GETPOSTINT('id');
38 $action = GETPOST('action', 'aZ09');
39 
40 // Security check
41 if ($user->socid) {
42  $socid = $user->socid;
43 }
44 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
45 $object = new Contact($db);
46 
47 $errors = array();
48 
49 
50 /*
51  * Action
52  */
53 
54 if ($action == 'update' && !GETPOST("cancel") && $user->hasRight('societe', 'contact', 'creer')) {
55  $ret = $object->fetch($id);
56 
57  // Note: Correct date should be completed with location to have exact GM time of birth.
58  $object->birthday = dol_mktime(0, 0, 0, GETPOST("birthdaymonth"), GETPOST("birthdayday"), GETPOST("birthdayyear"));
59  $object->birthday_alert = GETPOSTINT("birthday_alert");
60 
61  if (GETPOST('deletephoto')) {
62  $object->photo = '';
63  } elseif (!empty($_FILES['photo']['name'])) {
64  $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
65  }
66 
67  $result = $object->update_perso($id, $user);
68  if ($result > 0) {
69  $object->oldcopy = dol_clone($object, 2);
70 
71  // Logo/Photo save
72  $dir = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos';
73 
74  $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
75  if ($file_OK) {
76  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
77  require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
78  if (GETPOST('deletephoto')) {
79  $fileimg = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/'.$object->photo;
80  $dirthumbs = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/thumbs';
81  dol_delete_file($fileimg);
82  dol_delete_dir_recursive($dirthumbs);
83  }
84 
85  if (image_format_supported($_FILES['photo']['name']) > 0) {
86  dol_mkdir($dir);
87 
88  if (@is_dir($dir)) {
89  $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
90  if (!dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']) > 0) {
91  setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
92  } else {
93  // Create thumbs
94  $object->addThumbs($newfile);
95  }
96  }
97  } else {
98  setEventMessages("ErrorBadImageFormat", null, 'errors');
99  }
100  } else {
101  switch ($_FILES['photo']['error']) {
102  case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
103  case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
104  $errors[] = "ErrorFileSizeTooLarge";
105  break;
106  case 3: //uploaded file was only partially uploaded
107  $errors[] = "ErrorFilePartiallyUploaded";
108  break;
109  }
110  }
111  } else {
112  $error = $object->error;
113  }
114 }
115 
116 
117 /*
118  * View
119  */
120 
121 $now = dol_now();
122 
123 $title = $langs->trans("ContactPersonalData");
124 if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->lastname) {
125  $title = $object->lastname;
126 }
127 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
128 llxHeader('', $title, $help_url);
129 
130 $form = new Form($db);
131 $formcompany = new FormCompany($db);
132 
133 $object->fetch($id, $user);
134 
136 
137 if ($action == 'edit') {
138  /*
139  * Card in edit mode
140  */
141 
142  print '<form name="perso" method="POST" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
143  print '<input type="hidden" name="token" value="'.newToken().'">';
144  print '<input type="hidden" name="action" value="update">';
145  print '<input type="hidden" name="id" value="'.$object->id.'">';
146 
147  print dol_get_fiche_head($head, 'perso', $title, 0, 'contact');
148 
149  print '<table class="border centpercent">';
150 
151  // Ref
152  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>';
153  print $object->id;
154  print '</td>';
155 
156  // Name
157  print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$object->lastname.'</td></tr>';
158  print '<tr><td>'.$langs->trans("Firstname").'</td><td>'.$object->firstname.'</td>';
159 
160  // Company
161  if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
162  if ($object->socid > 0) {
163  $objsoc = new Societe($db);
164  $objsoc->fetch($object->socid);
165 
166  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>'.$objsoc->getNomUrl(1).'</td>';
167  } else {
168  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
169  print $langs->trans("ContactNotLinkedToCompany");
170  print '</td></tr>';
171  }
172  }
173 
174  // Civility
175  print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td>';
176  print $object->getCivilityLabel();
177  //print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'alpha') : $object->civility_code, 'civility_code');
178  print '</td></tr>';
179 
180  // Photo
181  print '<tr class="hideonsmartphone">';
182  print '<td>'.$form->editfieldkey('PhotoFile', 'photoinput', '', $object, 0).'</td>';
183  print '<td>';
184  if ($object->photo) {
185  print $form->showphoto('contact', $object);
186  }
187  $caneditfield = 1;
188  if ($caneditfield) {
189  if ($object->photo) {
190  print "<br>\n";
191  }
192  print '<table class="nobordernopadding">';
193  if ($object->photo) {
194  print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">'.$langs->trans("Delete").'</photo><br><br></td></tr>';
195  }
196  //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
197  print '<tr><td>';
198  $maxfilesizearray = getMaxFileSizeArray();
199  $maxmin = $maxfilesizearray['maxmin'];
200  if ($maxmin > 0) {
201  print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
202  }
203  print '<input type="file" class="flat" name="photo" id="photoinput">';
204  print '</td></tr>';
205  print '</table>';
206  }
207  print '</td>';
208  print '</tr>';
209 
210  // Date To Birth
211  print '<tr><td>'.$langs->trans("DateOfBirth").'</td><td>';
212  $form = new Form($db);
213  print $form->selectDate($object->birthday, 'birthday', 0, 0, 1, "perso", 1, 0);
214  print ' &nbsp; &nbsp; ';
215  print '<label for="birthday_alert">'.$langs->trans("BirthdayAlert").':</label> ';
216  if (!empty($object->birthday_alert)) {
217  print '<input type="checkbox" id="birthday_alert" name="birthday_alert" checked>';
218  } else {
219  print '<input type="checkbox" id="birthday_alert" name="birthday_alert">';
220  }
221  print '</td>';
222  print '</tr>';
223 
224  print "</table>";
225 
226  print dol_get_fiche_end();
227 
228  print $form->buttonsSaveCancel();
229 
230  print "</form>";
231 } else {
232  // View mode
233 
234  print dol_get_fiche_head($head, 'perso', $title, -1, 'contact');
235 
236  $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
237 
238  $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
239  $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
240  $morehtmlref .= '</a>';
241 
242  $morehtmlref .= '<div class="refidno">';
243  if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
244  $objsoc = new Societe($db);
245  $objsoc->fetch($object->socid);
246  // Thirdparty
247  if ($objsoc->id > 0) {
248  $morehtmlref .= $objsoc->getNomUrl(1);
249  } else {
250  $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
251  }
252  }
253  $morehtmlref .= '</div>';
254 
255 
256  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
257 
258 
259  print '<div class="fichecenter">';
260 
261  print '<div class="underbanner clearboth"></div>';
262  print '<table class="border centpercent tableforfield">';
263 
264  // Company
265  /*
266  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
267  {
268  if ($object->socid > 0)
269  {
270  $objsoc = new Societe($db);
271  $objsoc->fetch($object->socid);
272 
273  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
274  }
275 
276  else
277  {
278  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
279  print $langs->trans("ContactNotLinkedToCompany");
280  print '</td></tr>';
281  }
282  }*/
283 
284  // Civility
285  print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
286  print $object->getCivilityLabel();
287  print '</td></tr>';
288 
289  // Date To Birth
290  print '<tr>';
291  if (!empty($object->birthday)) {
292  include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
293 
294  print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3">'.dol_print_date($object->birthday, "day");
295 
296  print ' &nbsp; ';
297  //var_dump($birthdatearray);
298  $ageyear = (int) convertSecondToTime($now - $object->birthday, 'year') - 1970;
299  $agemonth = (int) convertSecondToTime($now - $object->birthday, 'month') - 1;
300  if ($ageyear >= 2) {
301  print '('.$ageyear.' '.$langs->trans("DurationYears").')';
302  } elseif ($agemonth >= 2) {
303  print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
304  } else {
305  print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
306  }
307 
308 
309  print ' &nbsp; - &nbsp; ';
310  if ($object->birthday_alert) {
311  print $langs->trans("BirthdayAlertOn");
312  } else {
313  print $langs->trans("BirthdayAlertOff");
314  }
315  print '</td>';
316  } else {
317  print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3"></td>';
318  }
319  print "</tr>";
320 
321  print "</table>";
322 
323  print '</div>';
324 
325  print dol_get_fiche_end();
326 }
327 
328 
329 if ($action != 'edit') {
330  /*
331  * Action bar
332  */
333  if ($user->socid == 0) {
334  print '<div class="tabsAction">';
335 
336  if ($user->hasRight('societe', 'contact', 'creer')) {
337  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
338  }
339 
340  print "</div>";
341  }
342 }
343 
344 
345 llxFooter();
346 
347 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage contact/addresses.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
Definition: contact.lib.php:33
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition: date.lib.php:242
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
Definition: files.lib.php:1609
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
Definition: files.lib.php:1458
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Check validity of a file upload from an GUI page, and move it to its final destination.
Definition: files.lib.php:1320
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:84
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.