dolibarr 24.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-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
41
42// Load translation files required by the page
43$langs->loadLangs(array('companies', 'other', 'users'));
44
45$id = GETPOSTINT('id');
46$action = GETPOST('action', 'aZ09');
47
48// Security check
49if ($user->socid) {
50 $socid = $user->socid;
51}
52$result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
53$object = new Contact($db);
54
55$errors = array();
56
57
58/*
59 * Action
60 */
61
62if ($action == 'update' && !GETPOST("cancel") && $user->hasRight('societe', 'contact', 'creer')) {
63 $ret = $object->fetch($id);
64
65 // Note: Correct date should be completed with location to have exact GM time of birth.
66 $object->birthday = dol_mktime(0, 0, 0, GETPOSTINT("birthdaymonth"), GETPOSTINT("birthdayday"), GETPOSTINT("birthdayyear"));
67 $object->birthday_alert = GETPOSTINT("birthday_alert");
68
69 $oldphoto = $object->photo;
70
71 if (GETPOST('deletephoto')) {
72 $object->photo = '';
73 } elseif (!empty($_FILES['photo']['name']) && empty($_FILES['photo']['error'])) { // A refused upload keeps the current photo
74 $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
75 }
76
77 $db->begin();
78
79 $result = $object->update_perso($id, $user);
80 if ($result > 0) {
81 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
82
83 // Logo/Photo save
84 $dir = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos';
85
86 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
87 if ($file_OK) {
88 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
89 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
90
91 if (GETPOST('deletephoto') || ($oldphoto != $object->photo)) {
92 $fileimg = $dir.'/'.$oldphoto;
93 $dirthumbs = $dir.'/thumbs';
94 dol_delete_file($fileimg);
95 dol_delete_dir_recursive($dirthumbs);
96 }
97
98 if (image_format_supported($_FILES['photo']['name']) > 0) {
99 dol_mkdir($dir);
100
101 if (@is_dir($dir)) {
102 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
103 $resultupload = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']);
104 // Note: $resultupload is a string when the file was refused and, in PHP 8, such a string compares as greater than 0
105 if (!is_numeric($resultupload) || $resultupload <= 0) {
106 setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
107 } else {
108 // Create thumbs
109 $object->addThumbs($newfile);
110 }
111 }
112 } else {
113 $langs->load("errors");
114 setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors');
115 }
116 } else {
117 switch ($_FILES['photo']['error']) {
118 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
119 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
120 $langs->load("errors");
121 setEventMessages($langs->trans("ErrorFileSizeTooLarge"), null, 'errors');
122 break;
123 case 3: //uploaded file was only partially uploaded
124 setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
125 break;
126 }
127 }
128
129 $db->commit();
130 } else {
131 $db->rollback();
132 }
133}
134
135
136/*
137 * View
138 */
139
140$now = dol_now();
141
142$title = $langs->trans("ContactPersonalData");
143if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->lastname) {
144 $title = $object->lastname;
145}
146$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
147
148llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-societe page-contact-card_perso');
149
150$form = new Form($db);
151$formcompany = new FormCompany($db);
152
153$object->fetch($id, $user);
154
155$head = contact_prepare_head($object);
156
157if ($action == 'edit') {
158 /*
159 * Card in edit mode
160 */
161
162 print '<form name="perso" method="POST" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
163 print '<input type="hidden" name="token" value="'.newToken().'">';
164 print '<input type="hidden" name="action" value="update">';
165 print '<input type="hidden" name="id" value="'.$object->id.'">';
166
167 print dol_get_fiche_head($head, 'perso', $title, 0, 'contact');
168
169 print '<table class="border centpercent">';
170
171 // Name
172 print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$object->lastname.'</td></tr>';
173 print '<tr><td>'.$langs->trans("Firstname").'</td><td>'.$object->firstname.'</td>';
174
175 // Company
176 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
177 if ($object->socid > 0) {
178 $objsoc = new Societe($db);
179 $objsoc->fetch($object->socid);
180
181 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>'.$objsoc->getNomUrl(1).'</td>';
182 } else {
183 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
184 print $langs->trans("ContactNotLinkedToCompany");
185 print '</td></tr>';
186 }
187 }
188
189 // Civility
190 if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
191 print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td>';
192 print $object->getCivilityLabel();
193 //print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'alpha') : $object->civility_code, 'civility_code');
194 print '</td></tr>';
195 }
196
197 // Photo
198 print '<tr class="hideonsmartphone">';
199 print '<td>'.$form->editfieldkey('PhotoFile', 'photoinput', '', $object, 0).'</td>';
200 print '<td>';
201 if ($object->photo) {
202 print $form->showphoto('contact', $object);
203 }
204 $caneditfield = 1;
205 if ($caneditfield) {
206 if ($object->photo) {
207 print "<br>\n";
208 }
209 print '<table class="nobordernopadding">';
210 if ($object->photo) {
211 print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">'.$langs->trans("Delete").'</photo><br><br></td></tr>';
212 }
213 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
214 print '<tr><td>';
215 $maxfilesizearray = getMaxFileSizeArray();
216 $maxmin = $maxfilesizearray['maxmin'];
217 if ($maxmin > 0) {
218 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
219 }
220 print '<input type="file" class="flat" name="photo" id="photoinput">';
221 print '</td></tr>';
222 print '</table>';
223 }
224 print '</td>';
225 print '</tr>';
226
227 // Date To Birth
228 print '<tr><td>'.$langs->trans("DateOfBirth").'</td><td>';
229 $form = new Form($db);
230 print $form->selectDate($object->birthday, 'birthday', 0, 0, 1, "perso", 1, 0);
231 print ' &nbsp; &nbsp; ';
232 print '<label for="birthday_alert">'.$langs->trans("BirthdayAlert").':</label> ';
233 if (!empty($object->birthday_alert)) {
234 print '<input type="checkbox" id="birthday_alert" name="birthday_alert" value="1" checked>';
235 } else {
236 print '<input type="checkbox" id="birthday_alert" name="birthday_alert" value="1">';
237 }
238 print '</td>';
239 print '</tr>';
240
241 print "</table>";
242
243 print dol_get_fiche_end();
244
245 print $form->buttonsSaveCancel();
246
247 print "</form>";
248} else {
249 // View mode
250
251 print dol_get_fiche_head($head, 'perso', $title, -1, 'contact');
252
253 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
254
255 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
256 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
257 $morehtmlref .= '</a>';
258
259 $morehtmlref .= '<div class="refidno">';
260 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
261 $objsoc = new Societe($db);
262 $objsoc->fetch($object->socid);
263 // Thirdparty
264 if ($objsoc->id > 0) {
265 $morehtmlref .= $objsoc->getNomUrl(1);
266 } else {
267 $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
268 }
269 }
270 $morehtmlref .= '</div>';
271
272
273 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
274
275
276 print '<div class="fichecenter">';
277
278 print '<div class="underbanner clearboth"></div>';
279 print '<table class="border centpercent tableforfield">';
280
281 // Company
282 /*
283 if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
284 {
285 if ($object->socid > 0)
286 {
287 $objsoc = new Societe($db);
288 $objsoc->fetch($object->socid);
289
290 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
291 }
292
293 else
294 {
295 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
296 print $langs->trans("ContactNotLinkedToCompany");
297 print '</td></tr>';
298 }
299 }*/
300
301 // Civility
302 if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
303 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
304 print $object->getCivilityLabel();
305 print '</td></tr>';
306 }
307
308 // Date To Birth
309 print '<tr>';
310 if (!empty($object->birthday)) {
311 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
312
313 print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3">'.dol_print_date($object->birthday, "day");
314
315 print ' &nbsp; ';
316 //var_dump($birthdatearray);
317 print '<span class="opacitymedium">';
318 $ageyear = (int) convertSecondToTime($now - $object->birthday, 'year') - 1970;
319 $agemonth = (int) convertSecondToTime($now - $object->birthday, 'month') - 1;
320 if ($ageyear >= 2) {
321 print '('.$ageyear.' '.$langs->trans("DurationYears").')';
322 } elseif ($agemonth >= 2) {
323 print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
324 } else {
325 print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
326 }
327 print '</span>';
328
329 print ' &nbsp; <span class="opacitymedium">- &nbsp; ';
330 if ($object->birthday_alert) {
331 print img_picto('', 'birthday-cake', 'class="pictofixedwidth"').$langs->trans("BirthdayAlertOn");
332 } else {
333 print $langs->trans("BirthdayAlertOff");
334 }
335 print '</span>';
336 print '</td>';
337 } else {
338 print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3"></td>';
339 }
340 print "</tr>";
341
342 print "</table>";
343
344 print '</div>';
345
346 print dol_get_fiche_end();
347}
348
349
350if ($action != 'edit') {
351 /*
352 * Action bar
353 */
354 if ($user->socid == 0) {
355 print '<div class="tabsAction">';
356
357 if ($user->hasRight('societe', 'contact', 'creer')) {
358 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
359 }
360
361 print "</div>";
362 }
363}
364
365
366llxFooter();
367
368$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage contact/addresses.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
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:263
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $keyforsourcefile='addedfile', $upload_dir='', $mode=0)
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
getMaxFileSizeArray()
Return the max allowed for file upload.