dolibarr 24.0.1
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'])) {
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 setEventMessages("ErrorBadImageFormat", null, 'errors');
114 }
115 } else {
116 switch ($_FILES['photo']['error']) {
117 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
118 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
119 $errors[] = "ErrorFileSizeTooLarge";
120 break;
121 case 3: //uploaded file was only partially uploaded
122 $errors[] = "ErrorFilePartiallyUploaded";
123 break;
124 }
125 }
126
127 $db->commit();
128 } else {
129 $db->rollback();
130 }
131}
132
133
134/*
135 * View
136 */
137
138$now = dol_now();
139
140$title = $langs->trans("ContactPersonalData");
141if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->lastname) {
142 $title = $object->lastname;
143}
144$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
145
146llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-societe page-contact-card_perso');
147
148$form = new Form($db);
149$formcompany = new FormCompany($db);
150
151$object->fetch($id, $user);
152
153$head = contact_prepare_head($object);
154
155if ($action == 'edit') {
156 /*
157 * Card in edit mode
158 */
159
160 print '<form name="perso" method="POST" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
161 print '<input type="hidden" name="token" value="'.newToken().'">';
162 print '<input type="hidden" name="action" value="update">';
163 print '<input type="hidden" name="id" value="'.$object->id.'">';
164
165 print dol_get_fiche_head($head, 'perso', $title, 0, 'contact');
166
167 print '<table class="border centpercent">';
168
169 // Name
170 print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$object->lastname.'</td></tr>';
171 print '<tr><td>'.$langs->trans("Firstname").'</td><td>'.$object->firstname.'</td>';
172
173 // Company
174 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
175 if ($object->socid > 0) {
176 $objsoc = new Societe($db);
177 $objsoc->fetch($object->socid);
178
179 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>'.$objsoc->getNomUrl(1).'</td>';
180 } else {
181 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
182 print $langs->trans("ContactNotLinkedToCompany");
183 print '</td></tr>';
184 }
185 }
186
187 // Civility
188 if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
189 print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td>';
190 print $object->getCivilityLabel();
191 //print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'alpha') : $object->civility_code, 'civility_code');
192 print '</td></tr>';
193 }
194
195 // Photo
196 print '<tr class="hideonsmartphone">';
197 print '<td>'.$form->editfieldkey('PhotoFile', 'photoinput', '', $object, 0).'</td>';
198 print '<td>';
199 if ($object->photo) {
200 print $form->showphoto('contact', $object);
201 }
202 $caneditfield = 1;
203 if ($caneditfield) {
204 if ($object->photo) {
205 print "<br>\n";
206 }
207 print '<table class="nobordernopadding">';
208 if ($object->photo) {
209 print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">'.$langs->trans("Delete").'</photo><br><br></td></tr>';
210 }
211 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
212 print '<tr><td>';
213 $maxfilesizearray = getMaxFileSizeArray();
214 $maxmin = $maxfilesizearray['maxmin'];
215 if ($maxmin > 0) {
216 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
217 }
218 print '<input type="file" class="flat" name="photo" id="photoinput">';
219 print '</td></tr>';
220 print '</table>';
221 }
222 print '</td>';
223 print '</tr>';
224
225 // Date To Birth
226 print '<tr><td>'.$langs->trans("DateOfBirth").'</td><td>';
227 $form = new Form($db);
228 print $form->selectDate($object->birthday, 'birthday', 0, 0, 1, "perso", 1, 0);
229 print ' &nbsp; &nbsp; ';
230 print '<label for="birthday_alert">'.$langs->trans("BirthdayAlert").':</label> ';
231 if (!empty($object->birthday_alert)) {
232 print '<input type="checkbox" id="birthday_alert" name="birthday_alert" value="1" checked>';
233 } else {
234 print '<input type="checkbox" id="birthday_alert" name="birthday_alert" value="1">';
235 }
236 print '</td>';
237 print '</tr>';
238
239 print "</table>";
240
241 print dol_get_fiche_end();
242
243 print $form->buttonsSaveCancel();
244
245 print "</form>";
246} else {
247 // View mode
248
249 print dol_get_fiche_head($head, 'perso', $title, -1, 'contact');
250
251 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
252
253 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
254 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
255 $morehtmlref .= '</a>';
256
257 $morehtmlref .= '<div class="refidno">';
258 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
259 $objsoc = new Societe($db);
260 $objsoc->fetch($object->socid);
261 // Thirdparty
262 if ($objsoc->id > 0) {
263 $morehtmlref .= $objsoc->getNomUrl(1);
264 } else {
265 $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
266 }
267 }
268 $morehtmlref .= '</div>';
269
270
271 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
272
273
274 print '<div class="fichecenter">';
275
276 print '<div class="underbanner clearboth"></div>';
277 print '<table class="border centpercent tableforfield">';
278
279 // Company
280 /*
281 if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
282 {
283 if ($object->socid > 0)
284 {
285 $objsoc = new Societe($db);
286 $objsoc->fetch($object->socid);
287
288 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
289 }
290
291 else
292 {
293 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
294 print $langs->trans("ContactNotLinkedToCompany");
295 print '</td></tr>';
296 }
297 }*/
298
299 // Civility
300 if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
301 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
302 print $object->getCivilityLabel();
303 print '</td></tr>';
304 }
305
306 // Date To Birth
307 print '<tr>';
308 if (!empty($object->birthday)) {
309 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
310
311 print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3">'.dol_print_date($object->birthday, "day");
312
313 print ' &nbsp; ';
314 //var_dump($birthdatearray);
315 $ageyear = (int) convertSecondToTime($now - $object->birthday, 'year') - 1970;
316 $agemonth = (int) convertSecondToTime($now - $object->birthday, 'month') - 1;
317 if ($ageyear >= 2) {
318 print '('.$ageyear.' '.$langs->trans("DurationYears").')';
319 } elseif ($agemonth >= 2) {
320 print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
321 } else {
322 print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
323 }
324
325
326 print ' &nbsp; - &nbsp; ';
327 if ($object->birthday_alert) {
328 print $langs->trans("BirthdayAlertOn");
329 } else {
330 print $langs->trans("BirthdayAlertOff");
331 }
332 print '</td>';
333 } else {
334 print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3"></td>';
335 }
336 print "</tr>";
337
338 print "</table>";
339
340 print '</div>';
341
342 print dol_get_fiche_end();
343}
344
345
346if ($action != 'edit') {
347 /*
348 * Action bar
349 */
350 if ($user->socid == 0) {
351 print '<div class="tabsAction">';
352
353 if ($user->hasRight('societe', 'contact', 'creer')) {
354 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
355 }
356
357 print "</div>";
358 }
359}
360
361
362llxFooter();
363
364$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:248
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.
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.