dolibarr  13.0.2
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-2020 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) $socid = $user->socid;
39 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
40 $object = new Contact($db);
41 
42 /*
43  * Action
44  */
45 
46 if ($action == 'update' && !$_POST["cancel"] && $user->rights->societe->contact->creer)
47 {
48  $ret = $object->fetch($id);
49 
50  // Note: Correct date should be completed with location to have exact GM time of birth.
51  $object->birthday = dol_mktime(0, 0, 0, $_POST["birthdaymonth"], $_POST["birthdayday"], $_POST["birthdayyear"]);
52  $object->birthday_alert = $_POST["birthday_alert"];
53 
54  if (GETPOST('deletephoto')) $object->photo = '';
55  elseif (!empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
56 
57  $result = $object->update_perso($id, $user);
58  if ($result > 0)
59  {
60  $object->old_name = '';
61  $object->old_firstname = '';
62  // Logo/Photo save
63  $dir = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos';
64 
65  $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
66  if ($file_OK)
67  {
68  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
69  require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
70  if (GETPOST('deletephoto'))
71  {
72  $fileimg = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/'.$object->photo;
73  $dirthumbs = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/thumbs';
74  dol_delete_file($fileimg);
75  dol_delete_dir_recursive($dirthumbs);
76  }
77 
78  if (image_format_supported($_FILES['photo']['name']) > 0)
79  {
80  dol_mkdir($dir);
81 
82  if (@is_dir($dir))
83  {
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  {
87  setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
88  } else {
89  // Create thumbs
90  $object->addThumbs($newfile);
91  }
92  }
93  } else {
94  setEventMessages("ErrorBadImageFormat", null, 'errors');
95  }
96  } else {
97  switch ($_FILES['photo']['error'])
98  {
99  case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
100  case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
101  $errors[] = "ErrorFileSizeTooLarge";
102  break;
103  case 3: //uploaded file was only partially uploaded
104  $errors[] = "ErrorFilePartiallyUploaded";
105  break;
106  }
107  }
108  } else {
109  $error = $object->error;
110  }
111 }
112 
113 
114 /*
115  * View
116  */
117 
118 $now = dol_now();
119 
120 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
121 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) $title = $object->lastname;
122 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
123 llxHeader('', $title, $helpurl);
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  /*
134  * Fiche en mode edition
135  */
136 
137  print '<form name="perso" method="POST" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
138  print '<input type="hidden" name="token" value="'.newToken().'">';
139  print '<input type="hidden" name="action" value="update">';
140  print '<input type="hidden" name="id" value="'.$object->id.'">';
141 
142  print dol_get_fiche_head($head, 'perso', $title, 0, 'contact');
143 
144  print '<table class="border centpercent">';
145 
146  // Ref
147  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td colspan="3">';
148  print $object->id;
149  print '</td>';
150 
151  // Photo
152  print '<td class="center hideonsmartphone valignmiddle" rowspan="6">';
153  print $form->showphoto('contact', $object)."\n";
154  if ($object->photo) print "<br>\n";
155 
156  print '<table class="nobordernopadding">';
157 
158  if ($object->photo) print '<tr><td class="center"><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
159  print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
160  print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
161  print '</table>';
162 
163  print '</td></tr>';
164 
165  // Name
166  print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td colspan="3">'.$object->lastname.'</td></tr>';
167  print '<tr><td>'.$langs->trans("Firstname").'</td><td colspan="3">'.$object->firstname.'</td>';
168 
169  // Company
170  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
171  {
172  if ($object->socid > 0)
173  {
174  $objsoc = new Societe($db);
175  $objsoc->fetch($object->socid);
176 
177  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td>';
178  } else {
179  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
180  print $langs->trans("ContactNotLinkedToCompany");
181  print '</td></tr>';
182  }
183  }
184 
185  // Civility
186  print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
187  print $object->getCivilityLabel();
188  print '</td></tr>';
189 
190  // Date To Birth
191  print '<tr><td>'.$langs->trans("DateOfBirth").'</td><td>';
192  $form = new Form($db);
193  print $form->selectDate($object->birthday, 'birthday', 0, 0, 1, "perso", 1, 0);
194  print '</td>';
195 
196  print '<td colspan="2">'.$langs->trans("Alert").': ';
197  if (!empty($object->birthday_alert))
198  {
199  print '<input type="checkbox" name="birthday_alert" checked></td>';
200  } else {
201  print '<input type="checkbox" name="birthday_alert"></td>';
202  }
203  print '</tr>';
204 
205  print "</table>";
206 
208 
209  print '<div class="center">';
210  print '<input type="submit" class="button button-save" name="save" value="'.$langs->trans("Save").'">';
211  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
212  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
213  print '</div>';
214 
215  print "</form>";
216 } else {
217  // View mode
218 
219  print dol_get_fiche_head($head, 'perso', $title, -1, 'contact');
220 
221  $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
222 
223  $morehtmlref = '<div class="refidno">';
224  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
225  {
226  $objsoc = new Societe($db);
227  $objsoc->fetch($object->socid);
228  // Thirdparty
229  $morehtmlref .= $langs->trans('ThirdParty').' : ';
230  if ($objsoc->id > 0) $morehtmlref .= $objsoc->getNomUrl(1);
231  else $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
232  }
233  $morehtmlref .= '</div>';
234 
235 
236  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
237 
238 
239  print '<div class="fichecenter">';
240 
241  print '<div class="underbanner clearboth"></div>';
242  print '<table class="border centpercent tableforfield">';
243 
244  // Company
245  /*
246  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
247  {
248  if ($object->socid > 0)
249  {
250  $objsoc = new Societe($db);
251  $objsoc->fetch($object->socid);
252 
253  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
254  }
255 
256  else
257  {
258  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
259  print $langs->trans("ContactNotLinkedToCompany");
260  print '</td></tr>';
261  }
262  }*/
263 
264  // Civility
265  print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
266  print $object->getCivilityLabel();
267  print '</td></tr>';
268 
269  // Date To Birth
270  print '<tr>';
271  if (!empty($object->birthday))
272  {
273  include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
274 
275  print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3">'.dol_print_date($object->birthday, "day");
276 
277  print ' &nbsp; ';
278  //var_dump($birthdatearray);
279  $ageyear = convertSecondToTime($now - $object->birthday, 'year') - 1970;
280  $agemonth = convertSecondToTime($now - $object->birthday, 'month') - 1;
281  if ($ageyear >= 2) print '('.$ageyear.' '.$langs->trans("DurationYears").')';
282  elseif ($agemonth >= 2) print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
283  else print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
284 
285 
286  print ' &nbsp; - &nbsp; ';
287  if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn");
288  else print $langs->trans("BirthdayAlertOff");
289  print '</td>';
290  } else {
291  print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3"></td>';
292  }
293  print "</tr>";
294 
295  print "</table>";
296 
297  print '</div>';
298 
300 }
301 
302 
303 if ($action != 'edit')
304 {
305  // Barre d'actions
306  if ($user->socid == 0)
307  {
308  print '<div class="tabsAction">';
309 
310  if ($user->rights->societe->contact->creer)
311  {
312  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
313  }
314 
315  print "</div>";
316  }
317 }
318 
319 
320 llxFooter();
321 
322 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
Class to manage contact/addresses.
dol_now($mode= 'auto')
Return date for now.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:39
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart= '')
Return a path to have a the directory according to object where files are stored. ...
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
Definition: contact.lib.php:33
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
Definition: files.lib.php:1286
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
Definition: files.lib.php:1144
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
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:999
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
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_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
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:180