dolibarr  17.0.4
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 // Load Dolibarr environment
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array('companies', 'other'));
34 
35 $id = GETPOST('id', 'int');
36 $action = GETPOST('action', 'aZ09');
37 
38 // Security check
39 if ($user->socid) {
40  $socid = $user->socid;
41 }
42 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
43 $object = new Contact($db);
44 
45 /*
46  * Action
47  */
48 
49 if ($action == 'update' && !GETPOST("cancel") && $user->rights->societe->contact->creer) {
50  $ret = $object->fetch($id);
51 
52  // Note: Correct date should be completed with location to have exact GM time of birth.
53  $object->birthday = dol_mktime(0, 0, 0, GETPOST("birthdaymonth"), GETPOST("birthdayday"), GETPOST("birthdayyear"));
54  $object->birthday_alert = GETPOST("birthday_alert");
55 
56  if (GETPOST('deletephoto')) {
57  $object->photo = '';
58  } elseif (!empty($_FILES['photo']['name'])) {
59  $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
60  }
61 
62  $result = $object->update_perso($id, $user);
63  if ($result > 0) {
64  $object->oldcopy = dol_clone($object);
65 
66  // Logo/Photo save
67  $dir = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos';
68 
69  $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
70  if ($file_OK) {
71  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
72  require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
73  if (GETPOST('deletephoto')) {
74  $fileimg = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/'.$object->photo;
75  $dirthumbs = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/thumbs';
76  dol_delete_file($fileimg);
77  dol_delete_dir_recursive($dirthumbs);
78  }
79 
80  if (image_format_supported($_FILES['photo']['name']) > 0) {
81  dol_mkdir($dir);
82 
83  if (@is_dir($dir)) {
84  $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
85  if (!dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']) > 0) {
86  setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
87  } else {
88  // Create thumbs
89  $object->addThumbs($newfile);
90  }
91  }
92  } else {
93  setEventMessages("ErrorBadImageFormat", null, 'errors');
94  }
95  } else {
96  switch ($_FILES['photo']['error']) {
97  case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
98  case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
99  $errors[] = "ErrorFileSizeTooLarge";
100  break;
101  case 3: //uploaded file was only partially uploaded
102  $errors[] = "ErrorFilePartiallyUploaded";
103  break;
104  }
105  }
106  } else {
107  $error = $object->error;
108  }
109 }
110 
111 
112 /*
113  * View
114  */
115 
116 $now = dol_now();
117 
118 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
119 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
120  $title = $object->lastname;
121 }
122 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
123 llxHeader('', $title, $help_url);
124 
125 $form = new Form($db);
126 
127 $object->fetch($id, $user);
128 
129 $head = contact_prepare_head($object);
130 
131 if ($action == 'edit') {
132  /*
133  * Fiche en mode edition
134  */
135 
136  print '<form name="perso" method="POST" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
137  print '<input type="hidden" name="token" value="'.newToken().'">';
138  print '<input type="hidden" name="action" value="update">';
139  print '<input type="hidden" name="id" value="'.$object->id.'">';
140 
141  print dol_get_fiche_head($head, 'perso', $title, 0, 'contact');
142 
143  print '<table class="border centpercent">';
144 
145  // Ref
146  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td colspan="3">';
147  print $object->id;
148  print '</td>';
149 
150  // Photo
151  print '<td class="center hideonsmartphone valignmiddle" rowspan="6">';
152  print $form->showphoto('contact', $object)."\n";
153  if ($object->photo) {
154  print "<br>\n";
155  }
156 
157  print '<table class="nobordernopadding">';
158 
159  if ($object->photo) {
160  print '<tr><td class="center"><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
161  }
162  print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
163  print '<tr><td>';
164  $maxfilesizearray = getMaxFileSizeArray();
165  $maxmin = $maxfilesizearray['maxmin'];
166  if ($maxmin > 0) {
167  print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
168  }
169  print '<input type="file" class="flat" name="photo" id="photoinput">';
170  print '</td></tr>';
171  print '</table>';
172 
173  print '</td></tr>';
174 
175  // Name
176  print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td colspan="3">'.$object->lastname.'</td></tr>';
177  print '<tr><td>'.$langs->trans("Firstname").'</td><td colspan="3">'.$object->firstname.'</td>';
178 
179  // Company
180  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
181  if ($object->socid > 0) {
182  $objsoc = new Societe($db);
183  $objsoc->fetch($object->socid);
184 
185  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td>';
186  } else {
187  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
188  print $langs->trans("ContactNotLinkedToCompany");
189  print '</td></tr>';
190  }
191  }
192 
193  // Civility
194  print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
195  print $object->getCivilityLabel();
196  print '</td></tr>';
197 
198  // Date To Birth
199  print '<tr><td>'.$langs->trans("DateOfBirth").'</td><td>';
200  $form = new Form($db);
201  print $form->selectDate($object->birthday, 'birthday', 0, 0, 1, "perso", 1, 0);
202  print '</td>';
203 
204  print '<td colspan="2">'.$langs->trans("Alert").': ';
205  if (!empty($object->birthday_alert)) {
206  print '<input type="checkbox" name="birthday_alert" checked></td>';
207  } else {
208  print '<input type="checkbox" name="birthday_alert"></td>';
209  }
210  print '</tr>';
211 
212  print "</table>";
213 
214  print dol_get_fiche_end();
215 
216  print $form->buttonsSaveCancel();
217 
218  print "</form>";
219 } else {
220  // View mode
221 
222  print dol_get_fiche_head($head, 'perso', $title, -1, 'contact');
223 
224  $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
225 
226  $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
227  $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
228  $morehtmlref .= '</a>';
229 
230  $morehtmlref .= '<div class="refidno">';
231  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
232  $objsoc = new Societe($db);
233  $objsoc->fetch($object->socid);
234  // Thirdparty
235  $morehtmlref .= $langs->trans('ThirdParty').' : ';
236  if ($objsoc->id > 0) {
237  $morehtmlref .= $objsoc->getNomUrl(1);
238  } else {
239  $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
240  }
241  }
242  $morehtmlref .= '</div>';
243 
244 
245  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
246 
247 
248  print '<div class="fichecenter">';
249 
250  print '<div class="underbanner clearboth"></div>';
251  print '<table class="border centpercent tableforfield">';
252 
253  // Company
254  /*
255  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
256  {
257  if ($object->socid > 0)
258  {
259  $objsoc = new Societe($db);
260  $objsoc->fetch($object->socid);
261 
262  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
263  }
264 
265  else
266  {
267  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
268  print $langs->trans("ContactNotLinkedToCompany");
269  print '</td></tr>';
270  }
271  }*/
272 
273  // Civility
274  print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
275  print $object->getCivilityLabel();
276  print '</td></tr>';
277 
278  // Date To Birth
279  print '<tr>';
280  if (!empty($object->birthday)) {
281  include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
282 
283  print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3">'.dol_print_date($object->birthday, "day");
284 
285  print ' &nbsp; ';
286  //var_dump($birthdatearray);
287  $ageyear = convertSecondToTime($now - $object->birthday, 'year') - 1970;
288  $agemonth = convertSecondToTime($now - $object->birthday, 'month') - 1;
289  if ($ageyear >= 2) {
290  print '('.$ageyear.' '.$langs->trans("DurationYears").')';
291  } elseif ($agemonth >= 2) {
292  print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
293  } else {
294  print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
295  }
296 
297 
298  print ' &nbsp; - &nbsp; ';
299  if ($object->birthday_alert) {
300  print $langs->trans("BirthdayAlertOn");
301  } else {
302  print $langs->trans("BirthdayAlertOff");
303  }
304  print '</td>';
305  } else {
306  print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3"></td>';
307  }
308  print "</tr>";
309 
310  print "</table>";
311 
312  print '</div>';
313 
314  print dol_get_fiche_end();
315 }
316 
317 
318 if ($action != 'edit') {
319  /*
320  * Action bar
321  */
322  if ($user->socid == 0) {
323  print '<div class="tabsAction">';
324 
325  if ($user->rights->societe->contact->creer) {
326  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
327  }
328 
329  print "</div>";
330  }
331 }
332 
333 
334 llxFooter();
335 
336 $db->close();
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:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage contact/addresses.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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:238
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:1402
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:1251
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:1112
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.
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...
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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:80
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.