dolibarr  9.0.0
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 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 <http://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','alpha');
36 
37 // Security check
38 if ($user->societe_id) $socid=$user->societe_id;
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  if (GETPOST('deletephoto'))
70  {
71  require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
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  }
89  else
90  {
91  // Create thumbs
92  $object->addThumbs($newfile);
93  }
94  }
95  }
96  else
97  {
98  setEventMessages("ErrorBadImageFormat", null, 'errors');
99  }
100  }
101  else
102  {
103  switch($_FILES['photo']['error'])
104  {
105  case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
106  case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
107  $errors[] = "ErrorFileSizeTooLarge";
108  break;
109  case 3: //uploaded file was only partially uploaded
110  $errors[] = "ErrorFilePartiallyUploaded";
111  break;
112  }
113  }
114  }
115  else
116  {
117  $error = $object->error;
118  }
119 }
120 
121 
122 /*
123  * View
124  */
125 
126 $now=dol_now();
127 
128 $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
129 if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->lastname) $title=$object->lastname;
130 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
131 llxHeader('', $title, $helpurl);
132 
133 $form = new Form($db);
134 
135 $object->fetch($id, $user);
136 
137 $head = contact_prepare_head($object);
138 
139 if ($action == 'edit')
140 {
141  /*
142  * Fiche en mode edition
143  */
144 
145  print '<form name="perso" method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
146  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
147  print '<input type="hidden" name="action" value="update">';
148  print '<input type="hidden" name="id" value="'.$object->id.'">';
149 
150  dol_fiche_head($head, 'perso', $title, 0, 'contact');
151 
152  print '<table class="border" width="100%">';
153 
154  // Ref
155  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td colspan="3">';
156  print $object->id;
157  print '</td>';
158 
159  // Photo
160  print '<td align="center" class="hideonsmartphone" valign="middle" rowspan="6">';
161  print $form->showphoto('contact',$object)."\n";
162  if ($object->photo) print "<br>\n";
163 
164  print '<table class="nobordernopadding">';
165 
166  if ($object->photo) print '<tr><td align="center"><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
167  print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
168  print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
169  print '</table>';
170 
171  print '</td></tr>';
172 
173  // Name
174  print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td colspan="3">'.$object->lastname.'</td></tr>';
175  print '<tr><td>'.$langs->trans("Firstname").'</td><td colspan="3">'.$object->firstname.'</td>';
176 
177  // Company
178  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
179  {
180  if ($object->socid > 0)
181  {
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  }
187  else
188  {
189  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
190  print $langs->trans("ContactNotLinkedToCompany");
191  print '</td></tr>';
192  }
193  }
194 
195  // Civility
196  print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
197  print $object->getCivilityLabel();
198  print '</td></tr>';
199 
200  // Date To Birth
201  print '<tr><td>'.$langs->trans("DateToBirth").'</td><td>';
202  $form=new Form($db);
203  print $form->selectDate($object->birthday, 'birthday', 0, 0, 1, "perso", 1,0);
204  print '</td>';
205 
206  print '<td colspan="2">'.$langs->trans("Alert").': ';
207  if (! empty($object->birthday_alert))
208  {
209  print '<input type="checkbox" name="birthday_alert" checked></td>';
210  }
211  else
212  {
213  print '<input type="checkbox" name="birthday_alert"></td>';
214  }
215  print '</tr>';
216 
217  print "</table>";
218 
219  dol_fiche_end();
220 
221  print '<div class="center">';
222  print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
223  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
224  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
225  print '</div>';
226 
227  print "</form>";
228 }
229 else
230 {
231  // View mode
232 
233  dol_fiche_head($head, 'perso', $title, -1, 'contact');
234 
235  $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
236 
237  $morehtmlref='<div class="refidno">';
238  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
239  {
240  $objsoc=new Societe($db);
241  $objsoc->fetch($object->socid);
242  // Thirdparty
243  $morehtmlref.=$langs->trans('ThirdParty') . ' : ';
244  if ($objsoc->id > 0) $morehtmlref.=$objsoc->getNomUrl(1);
245  else $morehtmlref.=$langs->trans("ContactNotLinkedToCompany");
246  }
247  $morehtmlref.='</div>';
248 
249 
250  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
251 
252 
253  print '<div class="fichecenter">';
254 
255  print '<div class="underbanner clearboth"></div>';
256  print '<table class="border centpercent">';
257 
258  // Company
259  /*
260  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
261  {
262  if ($object->socid > 0)
263  {
264  $objsoc = new Societe($db);
265  $objsoc->fetch($object->socid);
266 
267  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
268  }
269 
270  else
271  {
272  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
273  print $langs->trans("ContactNotLinkedToCompany");
274  print '</td></tr>';
275  }
276  }*/
277 
278  // Civility
279  print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
280  print $object->getCivilityLabel();
281  print '</td></tr>';
282 
283  // Date To Birth
284  print '<tr>';
285  if (! empty($object->birthday))
286  {
287  include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
288 
289  print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.dol_print_date($object->birthday,"day");
290 
291  print ' &nbsp; ';
292  //var_dump($birthdatearray);
293  $ageyear=convertSecondToTime($now-$object->birthday,'year')-1970;
294  $agemonth=convertSecondToTime($now-$object->birthday,'month')-1;
295  if ($ageyear >= 2) print '('.$ageyear.' '.$langs->trans("DurationYears").')';
296  else if ($agemonth >= 2) print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
297  else print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
298 
299 
300  print ' &nbsp; - &nbsp; ';
301  if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn");
302  else print $langs->trans("BirthdayAlertOff");
303  print '</td>';
304  }
305  else
306  {
307  print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3"></td>';
308  }
309  print "</tr>";
310 
311  print "</table>";
312 
313  print '</div>';
314 
315  dol_fiche_end();
316 }
317 
318 
319 if ($action != 'edit')
320 {
321  // Barre d'actions
322  if ($user->societe_id == 0)
323  {
324  print '<div class="tabsAction">';
325 
326  if ($user->rights->societe->contact->creer)
327  {
328  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
329  }
330 
331  print "</div>";
332  }
333 }
334 
335 
336 llxFooter();
337 
338 $db->close();
image_format_supported($file)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:38
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
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile')
Make control on an uploaded file from an GUI page and move it to final destination.
Definition: files.lib.php:996
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage contact/addresses.
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_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.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_fiche_end($notab=0)
Show tab footer of a card.
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:1273
llxHeader()
Empty header.
Definition: wrapper.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:1139
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
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_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.