dolibarr  7.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@capnetworks.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
29 
30 $langs->load("companies");
31 $langs->load("other");
32 
33 $id = GETPOST('id','int');
34 $action = GETPOST('action','alpha');
35 
36 // Security check
37 if ($user->societe_id) $socid=$user->societe_id;
38 $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
39 $object = new Contact($db);
40 
41 /*
42  * Action
43  */
44 
45 if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
46 {
47  $ret = $object->fetch($id);
48 
49  // Note: Correct date should be completed with location to have exact GM time of birth.
50  $object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]);
51  $object->birthday_alert = $_POST["birthday_alert"];
52 
53  if (GETPOST('deletephoto')) $object->photo='';
54  elseif (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
55 
56  $result = $object->update_perso($id, $user);
57  if ($result > 0)
58  {
59  $object->old_name='';
60  $object->old_firstname='';
61  // Logo/Photo save
62  $dir= $conf->societe->dir_output.'/contact/' . get_exdir($object->id,0,0,1,$object,'contact').'/photos';
63 
64  $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
65  if ($file_OK)
66  {
67  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
68  if (GETPOST('deletephoto'))
69  {
70  require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
71  $fileimg=$conf->societe->dir_output.'/contact/'.get_exdir($object->id,0,0,1,$object,'contact').'/photos/'.$object->photo;
72  $dirthumbs=$conf->societe->dir_output.'/contact/'.get_exdir($object->id,0,0,1,$object,'contact').'/photos/thumbs';
73  dol_delete_file($fileimg);
74  dol_delete_dir_recursive($dirthumbs);
75  }
76 
77  if (image_format_supported($_FILES['photo']['name']) > 0)
78  {
79  dol_mkdir($dir);
80 
81  if (@is_dir($dir))
82  {
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  {
86  setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
87  }
88  else
89  {
90  // Create thumbs
91  $object->addThumbs($newfile);
92  }
93  }
94  }
95  else
96  {
97  setEventMessages("ErrorBadImageFormat", null, 'errors');
98  }
99  }
100  else
101  {
102  switch($_FILES['photo']['error'])
103  {
104  case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
105  case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
106  $errors[] = "ErrorFileSizeTooLarge";
107  break;
108  case 3: //uploaded file was only partially uploaded
109  $errors[] = "ErrorFilePartiallyUploaded";
110  break;
111  }
112  }
113  }
114  else
115  {
116  $error = $object->error;
117  }
118 }
119 
120 
121 /*
122  * View
123  */
124 
125 $now=dol_now();
126 
127 $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
128 if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->lastname) $title=$object->lastname;
129 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
130 llxHeader('', $title, $helpurl);
131 
132 $form = new Form($db);
133 
134 $object->fetch($id, $user);
135 
136 $head = contact_prepare_head($object);
137 
138 if ($action == 'edit')
139 {
140  /*
141  * Fiche en mode edition
142  */
143 
144  print '<form name="perso" method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
145  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
146  print '<input type="hidden" name="action" value="update">';
147  print '<input type="hidden" name="id" value="'.$object->id.'">';
148 
149  dol_fiche_head($head, 'perso', $title, 0, 'contact');
150 
151  print '<table class="border" width="100%">';
152 
153  // Ref
154  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td colspan="3">';
155  print $object->id;
156  print '</td>';
157 
158  // Photo
159  print '<td align="center" class="hideonsmartphone" valign="middle" rowspan="6">';
160  print $form->showphoto('contact',$object)."\n";
161  if ($object->photo) print "<br>\n";
162 
163  print '<table class="nobordernopadding">';
164 
165  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>';
166  print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
167  print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
168  print '</table>';
169 
170  print '</td></tr>';
171 
172  // Name
173  print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td colspan="3">'.$object->lastname.'</td></tr>';
174  print '<tr><td>'.$langs->trans("Firstname").'</td><td colspan="3">'.$object->firstname.'</td>';
175 
176  // Company
177  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
178  {
179  if ($object->socid > 0)
180  {
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  }
186  else
187  {
188  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
189  print $langs->trans("ContactNotLinkedToCompany");
190  print '</td></tr>';
191  }
192  }
193 
194  // Civility
195  print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
196  print $object->getCivilityLabel();
197  print '</td></tr>';
198 
199  // Date To Birth
200  print '<tr><td>'.$langs->trans("DateToBirth").'</td><td>';
201  $form=new Form($db);
202  print $form->select_date($object->birthday,'birthday',0,0,1,"perso", 1,0,1);
203  print '</td>';
204 
205  print '<td colspan="2">'.$langs->trans("Alert").': ';
206  if (! empty($object->birthday_alert))
207  {
208  print '<input type="checkbox" name="birthday_alert" checked></td>';
209  }
210  else
211  {
212  print '<input type="checkbox" name="birthday_alert"></td>';
213  }
214  print '</tr>';
215 
216  print "</table>";
217 
218  dol_fiche_end();
219 
220  print '<div class="center">';
221  print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
222  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
223  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
224  print '</div>';
225 
226  print "</form>";
227 }
228 else
229 {
230  // View mode
231 
232  dol_fiche_head($head, 'perso', $title, -1, 'contact');
233 
234  $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
235 
236  $morehtmlref='<div class="refidno">';
237  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
238  {
239  $objsoc=new Societe($db);
240  $objsoc->fetch($object->socid);
241  // Thirdparty
242  $morehtmlref.=$langs->trans('ThirdParty') . ' : ';
243  if ($objsoc->id > 0) $morehtmlref.=$objsoc->getNomUrl(1);
244  else $morehtmlref.=$langs->trans("ContactNotLinkedToCompany");
245  }
246  $morehtmlref.='</div>';
247 
248 
249  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
250 
251 
252  print '<div class="fichecenter">';
253 
254  print '<div class="underbanner clearboth"></div>';
255  print '<table class="border centpercent">';
256 
257  // Company
258  /*
259  if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
260  {
261  if ($object->socid > 0)
262  {
263  $objsoc = new Societe($db);
264  $objsoc->fetch($object->socid);
265 
266  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
267  }
268 
269  else
270  {
271  print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
272  print $langs->trans("ContactNotLinkedToCompany");
273  print '</td></tr>';
274  }
275  }*/
276 
277  // Civility
278  print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
279  print $object->getCivilityLabel();
280  print '</td></tr>';
281 
282  // Date To Birth
283  print '<tr>';
284  if (! empty($object->birthday))
285  {
286  include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
287 
288  print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.dol_print_date($object->birthday,"day");
289 
290  print ' &nbsp; ';
291  //var_dump($birthdatearray);
292  $ageyear=convertSecondToTime($now-$object->birthday,'year')-1970;
293  $agemonth=convertSecondToTime($now-$object->birthday,'month')-1;
294  if ($ageyear >= 2) print '('.$ageyear.' '.$langs->trans("DurationYears").')';
295  else if ($agemonth >= 2) print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
296  else print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
297 
298 
299  print ' &nbsp; - &nbsp; ';
300  if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn");
301  else print $langs->trans("BirthdayAlertOff");
302  print '</td>';
303  }
304  else
305  {
306  print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3"></td>';
307  }
308  print "</tr>";
309 
310  print "</table>";
311 
312  print '</div>';
313 
314  dol_fiche_end();
315 }
316 
317 
318 if ($action != 'edit')
319 {
320  // Barre d'actions
321  if ($user->societe_id == 0)
322  {
323  print '<div class="tabsAction">';
324 
325  if ($user->rights->societe->contact->creer)
326  {
327  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
328  }
329 
330  print "</div>";
331  }
332 }
333 
334 
335 llxFooter();
336 
337 $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:171
llxFooter()
Empty footer.
Definition: wrapper.php:58
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:962
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...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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. ...
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
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.
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
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:1234
llxHeader()
Empty header.
Definition: wrapper.php:46
dol_now($mode='gmt')
Return date for now.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print
Draft customers invoices.
Definition: index.php:91
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null)
Remove a file or several files with a mask.
Definition: files.lib.php:1103
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.