dolibarr 22.0.5
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';
31require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
34
43// Load translation files required by the page
44$langs->loadLangs(array('companies', 'other'));
45
46$id = GETPOSTINT('id');
47$action = GETPOST('action', 'aZ09');
48
49// Security check
50if ($user->socid) {
51 $socid = $user->socid;
52}
53$result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
54$object = new Contact($db);
55
56$errors = array();
57
58
59/*
60 * Action
61 */
62
63if ($action == 'update' && !GETPOST("cancel") && $user->hasRight('societe', 'contact', 'creer')) {
64 $ret = $object->fetch($id);
65
66 // Note: Correct date should be completed with location to have exact GM time of birth.
67 $object->birthday = dol_mktime(0, 0, 0, GETPOSTINT("birthdaymonth"), GETPOSTINT("birthdayday"), GETPOSTINT("birthdayyear"));
68 $object->birthday_alert = GETPOSTINT("birthday_alert");
69
70 if (GETPOST('deletephoto')) {
71 $object->photo = '';
72 } elseif (!empty($_FILES['photo']['name']) && empty($_FILES['photo']['error'])) { // A refused upload keeps the current photo
73 $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
74 }
75
76 $result = $object->update_perso($id, $user);
77 if ($result > 0) {
78 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
79
80 // Logo/Photo save
81 $dir = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos';
82
83 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
84 if ($file_OK) {
85 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
86 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
87 if (GETPOST('deletephoto')) {
88 $fileimg = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/'.$object->photo;
89 $dirthumbs = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/thumbs';
90 dol_delete_file($fileimg);
91 dol_delete_dir_recursive($dirthumbs);
92 }
93
94 if (image_format_supported($_FILES['photo']['name']) > 0) {
95 dol_mkdir($dir);
96
97 if (@is_dir($dir)) {
98 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
99 $resultupload = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']);
100 // Note: $resultupload is a string when the file was refused and, in PHP 8, such a string compares as greater than 0
101 if (!is_numeric($resultupload) || $resultupload <= 0) {
102 setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
103 } else {
104 // Create thumbs
105 $object->addThumbs($newfile);
106 }
107 }
108 } else {
109 $langs->load("errors");
110 setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors');
111 }
112 } else {
113 switch ($_FILES['photo']['error']) {
114 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
115 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
116 $langs->load("errors");
117 setEventMessages($langs->trans("ErrorFileSizeTooLarge"), null, 'errors');
118 break;
119 case 3: //uploaded file was only partially uploaded
120 setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
121 break;
122 }
123 }
124 } else {
125 $error = $object->error;
126 }
127}
128
129
130/*
131 * View
132 */
133
134$now = dol_now();
135
136$title = $langs->trans("ContactPersonalData");
137if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->lastname) {
138 $title = $object->lastname;
139}
140$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
141
142llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-societe page-contact-card_perso');
143
144$form = new Form($db);
145$formcompany = new FormCompany($db);
146
147$object->fetch($id, $user);
148
149$head = contact_prepare_head($object);
150
151if ($action == 'edit') {
152 /*
153 * Card in edit mode
154 */
155
156 print '<form name="perso" method="POST" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
157 print '<input type="hidden" name="token" value="'.newToken().'">';
158 print '<input type="hidden" name="action" value="update">';
159 print '<input type="hidden" name="id" value="'.$object->id.'">';
160
161 print dol_get_fiche_head($head, 'perso', $title, 0, 'contact');
162
163 print '<table class="border centpercent">';
164
165 // Ref
166 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>';
167 print $object->id;
168 print '</td>';
169
170 // Name
171 print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$object->lastname.'</td></tr>';
172 print '<tr><td>'.$langs->trans("Firstname").'</td><td>'.$object->firstname.'</td>';
173
174 // Company
175 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
176 if ($object->socid > 0) {
177 $objsoc = new Societe($db);
178 $objsoc->fetch($object->socid);
179
180 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>'.$objsoc->getNomUrl(1).'</td>';
181 } else {
182 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
183 print $langs->trans("ContactNotLinkedToCompany");
184 print '</td></tr>';
185 }
186 }
187
188 // Civility
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 // Photo
195 print '<tr class="hideonsmartphone">';
196 print '<td>'.$form->editfieldkey('PhotoFile', 'photoinput', '', $object, 0).'</td>';
197 print '<td>';
198 if ($object->photo) {
199 print $form->showphoto('contact', $object);
200 }
201 $caneditfield = 1;
202 if ($caneditfield) {
203 if ($object->photo) {
204 print "<br>\n";
205 }
206 print '<table class="nobordernopadding">';
207 if ($object->photo) {
208 print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">'.$langs->trans("Delete").'</photo><br><br></td></tr>';
209 }
210 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
211 print '<tr><td>';
212 $maxfilesizearray = getMaxFileSizeArray();
213 $maxmin = $maxfilesizearray['maxmin'];
214 if ($maxmin > 0) {
215 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
216 }
217 print '<input type="file" class="flat" name="photo" id="photoinput">';
218 print '</td></tr>';
219 print '</table>';
220 }
221 print '</td>';
222 print '</tr>';
223
224 // Date To Birth
225 print '<tr><td>'.$langs->trans("DateOfBirth").'</td><td>';
226 $form = new Form($db);
227 print $form->selectDate($object->birthday, 'birthday', 0, 0, 1, "perso", 1, 0);
228 print ' &nbsp; &nbsp; ';
229 print '<label for="birthday_alert">'.$langs->trans("BirthdayAlert").':</label> ';
230 if (!empty($object->birthday_alert)) {
231 print '<input type="checkbox" id="birthday_alert" name="birthday_alert" value="1" checked>';
232 } else {
233 print '<input type="checkbox" id="birthday_alert" name="birthday_alert" value="1">';
234 }
235 print '</td>';
236 print '</tr>';
237
238 print "</table>";
239
240 print dol_get_fiche_end();
241
242 print $form->buttonsSaveCancel();
243
244 print "</form>";
245} else {
246 // View mode
247
248 print dol_get_fiche_head($head, 'perso', $title, -1, 'contact');
249
250 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
251
252 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
253 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
254 $morehtmlref .= '</a>';
255
256 $morehtmlref .= '<div class="refidno">';
257 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
258 $objsoc = new Societe($db);
259 $objsoc->fetch($object->socid);
260 // Thirdparty
261 if ($objsoc->id > 0) {
262 $morehtmlref .= $objsoc->getNomUrl(1);
263 } else {
264 $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
265 }
266 }
267 $morehtmlref .= '</div>';
268
269
270 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
271
272
273 print '<div class="fichecenter">';
274
275 print '<div class="underbanner clearboth"></div>';
276 print '<table class="border centpercent tableforfield">';
277
278 // Company
279 /*
280 if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
281 {
282 if ($object->socid > 0)
283 {
284 $objsoc = new Societe($db);
285 $objsoc->fetch($object->socid);
286
287 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
288 }
289
290 else
291 {
292 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
293 print $langs->trans("ContactNotLinkedToCompany");
294 print '</td></tr>';
295 }
296 }*/
297
298 // Civility
299 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
300 print $object->getCivilityLabel();
301 print '</td></tr>';
302
303 // Date To Birth
304 print '<tr>';
305 if (!empty($object->birthday)) {
306 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
307
308 print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3">'.dol_print_date($object->birthday, "day");
309
310 print ' &nbsp; ';
311 //var_dump($birthdatearray);
312 $ageyear = (int) convertSecondToTime($now - $object->birthday, 'year') - 1970;
313 $agemonth = (int) convertSecondToTime($now - $object->birthday, 'month') - 1;
314 if ($ageyear >= 2) {
315 print '('.$ageyear.' '.$langs->trans("DurationYears").')';
316 } elseif ($agemonth >= 2) {
317 print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
318 } else {
319 print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
320 }
321
322
323 print ' &nbsp; - &nbsp; ';
324 if ($object->birthday_alert) {
325 print $langs->trans("BirthdayAlertOn");
326 } else {
327 print $langs->trans("BirthdayAlertOff");
328 }
329 print '</td>';
330 } else {
331 print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3"></td>';
332 }
333 print "</tr>";
334
335 print "</table>";
336
337 print '</div>';
338
339 print dol_get_fiche_end();
340}
341
342
343if ($action != 'edit') {
344 /*
345 * Action bar
346 */
347 if ($user->socid == 0) {
348 print '<div class="tabsAction">';
349
350 if ($user->hasRight('societe', 'contact', 'creer')) {
351 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
352 }
353
354 print "</div>";
355 }
356}
357
358
359llxFooter();
360
361$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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:244
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_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)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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)
Return value of a param into GET or POST supervariable.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.