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