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