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