dolibarr 19.0.4
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@netlogic.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
32
33// Load translation files required by the page
34$langs->loadLangs(array('companies', 'other'));
35
36$id = GETPOST('id', 'int');
37$action = GETPOST('action', 'aZ09');
38
39// Security check
40if ($user->socid) {
41 $socid = $user->socid;
42}
43$result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
44$object = new Contact($db);
45
46$errors = array();
47
48
49/*
50 * Action
51 */
52
53if ($action == 'update' && !GETPOST("cancel") && $user->hasRight('societe', 'contact', 'creer')) {
54 $ret = $object->fetch($id);
55
56 // Note: Correct date should be completed with location to have exact GM time of birth.
57 $object->birthday = dol_mktime(0, 0, 0, GETPOST("birthdaymonth"), GETPOST("birthdayday"), GETPOST("birthdayyear"));
58 $object->birthday_alert = GETPOST("birthday_alert");
59
60 if (GETPOST('deletephoto')) {
61 $object->photo = '';
62 } elseif (!empty($_FILES['photo']['name'])) {
63 $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
64 }
65
66 $result = $object->update_perso($id, $user);
67 if ($result > 0) {
68 $object->oldcopy = dol_clone($object, 2);
69
70 // Logo/Photo save
71 $dir = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos';
72
73 $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
74 if ($file_OK) {
75 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
76 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
77 if (GETPOST('deletephoto')) {
78 $fileimg = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/'.$object->photo;
79 $dirthumbs = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/thumbs';
80 dol_delete_file($fileimg);
81 dol_delete_dir_recursive($dirthumbs);
82 }
83
84 if (image_format_supported($_FILES['photo']['name']) > 0) {
85 dol_mkdir($dir);
86
87 if (@is_dir($dir)) {
88 $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
89 if (!dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']) > 0) {
90 setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
91 } else {
92 // Create thumbs
93 $object->addThumbs($newfile);
94 }
95 }
96 } else {
97 setEventMessages("ErrorBadImageFormat", null, 'errors');
98 }
99 } else {
100 switch ($_FILES['photo']['error']) {
101 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
102 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
103 $errors[] = "ErrorFileSizeTooLarge";
104 break;
105 case 3: //uploaded file was only partially uploaded
106 $errors[] = "ErrorFilePartiallyUploaded";
107 break;
108 }
109 }
110 } else {
111 $error = $object->error;
112 }
113}
114
115
116/*
117 * View
118 */
119
120$now = dol_now();
121
122$title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
123if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
124 $title = $object->lastname;
125}
126$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
127llxHeader('', $title, $help_url);
128
129$form = new Form($db);
130$formcompany = new FormCompany($db);
131
132$object->fetch($id, $user);
133
134$head = contact_prepare_head($object);
135
136if ($action == 'edit') {
137 /*
138 * Fiche en mode edition
139 */
140
141 print '<form name="perso" method="POST" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
142 print '<input type="hidden" name="token" value="'.newToken().'">';
143 print '<input type="hidden" name="action" value="update">';
144 print '<input type="hidden" name="id" value="'.$object->id.'">';
145
146 print dol_get_fiche_head($head, 'perso', $title, 0, 'contact');
147
148 print '<table class="border centpercent">';
149
150 // Ref
151 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>';
152 print $object->id;
153 print '</td>';
154
155 // Name
156 print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$object->lastname.'</td></tr>';
157 print '<tr><td>'.$langs->trans("Firstname").'</td><td>'.$object->firstname.'</td>';
158
159 // Company
160 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
161 if ($object->socid > 0) {
162 $objsoc = new Societe($db);
163 $objsoc->fetch($object->socid);
164
165 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>'.$objsoc->getNomUrl(1).'</td>';
166 } else {
167 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
168 print $langs->trans("ContactNotLinkedToCompany");
169 print '</td></tr>';
170 }
171 }
172
173 // Civility
174 print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td>';
175 print $object->getCivilityLabel();
176 //print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'alpha') : $object->civility_code, 'civility_code');
177 print '</td></tr>';
178
179 // Photo
180 print '<tr class="hideonsmartphone">';
181 print '<td>'.$form->editfieldkey('PhotoFile', 'photoinput', '', $object, 0).'</td>';
182 print '<td>';
183 if ($object->photo) {
184 print $form->showphoto('contact', $object);
185 }
186 $caneditfield = 1;
187 if ($caneditfield) {
188 if ($object->photo) {
189 print "<br>\n";
190 }
191 print '<table class="nobordernopadding">';
192 if ($object->photo) {
193 print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">'.$langs->trans("Delete").'</photo><br><br></td></tr>';
194 }
195 //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
196 print '<tr><td>';
197 $maxfilesizearray = getMaxFileSizeArray();
198 $maxmin = $maxfilesizearray['maxmin'];
199 if ($maxmin > 0) {
200 print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
201 }
202 print '<input type="file" class="flat" name="photo" id="photoinput">';
203 print '</td></tr>';
204 print '</table>';
205 }
206 print '</td>';
207 print '</tr>';
208
209 // Date To Birth
210 print '<tr><td>'.$langs->trans("DateOfBirth").'</td><td>';
211 $form = new Form($db);
212 print $form->selectDate($object->birthday, 'birthday', 0, 0, 1, "perso", 1, 0);
213 print ' &nbsp; &nbsp; ';
214 print '<label for="birthday_alert">'.$langs->trans("BirthdayAlert").':</label> ';
215 if (!empty($object->birthday_alert)) {
216 print '<input type="checkbox" id="birthday_alert" name="birthday_alert" checked>';
217 } else {
218 print '<input type="checkbox" id="birthday_alert" name="birthday_alert">';
219 }
220 print '</td>';
221 print '</tr>';
222
223 print "</table>";
224
225 print dol_get_fiche_end();
226
227 print $form->buttonsSaveCancel();
228
229 print "</form>";
230} else {
231 // View mode
232
233 print dol_get_fiche_head($head, 'perso', $title, -1, 'contact');
234
235 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
236
237 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
238 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
239 $morehtmlref .= '</a>';
240
241 $morehtmlref .= '<div class="refidno">';
242 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
243 $objsoc = new Societe($db);
244 $objsoc->fetch($object->socid);
245 // Thirdparty
246 if ($objsoc->id > 0) {
247 $morehtmlref .= $objsoc->getNomUrl(1);
248 } else {
249 $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
250 }
251 }
252 $morehtmlref .= '</div>';
253
254
255 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
256
257
258 print '<div class="fichecenter">';
259
260 print '<div class="underbanner clearboth"></div>';
261 print '<table class="border centpercent tableforfield">';
262
263 // Company
264 /*
265 if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
266 {
267 if ($object->socid > 0)
268 {
269 $objsoc = new Societe($db);
270 $objsoc->fetch($object->socid);
271
272 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
273 }
274
275 else
276 {
277 print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
278 print $langs->trans("ContactNotLinkedToCompany");
279 print '</td></tr>';
280 }
281 }*/
282
283 // Civility
284 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
285 print $object->getCivilityLabel();
286 print '</td></tr>';
287
288 // Date To Birth
289 print '<tr>';
290 if (!empty($object->birthday)) {
291 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
292
293 print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3">'.dol_print_date($object->birthday, "day");
294
295 print ' &nbsp; ';
296 //var_dump($birthdatearray);
297 $ageyear = convertSecondToTime($now - $object->birthday, 'year') - 1970;
298 $agemonth = convertSecondToTime($now - $object->birthday, 'month') - 1;
299 if ($ageyear >= 2) {
300 print '('.$ageyear.' '.$langs->trans("DurationYears").')';
301 } elseif ($agemonth >= 2) {
302 print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
303 } else {
304 print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
305 }
306
307
308 print ' &nbsp; - &nbsp; ';
309 if ($object->birthday_alert) {
310 print $langs->trans("BirthdayAlertOn");
311 } else {
312 print $langs->trans("BirthdayAlertOff");
313 }
314 print '</td>';
315 } else {
316 print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3"></td>';
317 }
318 print "</tr>";
319
320 print "</table>";
321
322 print '</div>';
323
324 print dol_get_fiche_end();
325}
326
327
328if ($action != 'edit') {
329 /*
330 * Action bar
331 */
332 if ($user->socid == 0) {
333 print '<div class="tabsAction">';
334
335 if ($user->hasRight('societe', 'contact', 'creer')) {
336 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
337 }
338
339 print "</div>";
340 }
341}
342
343
344llxFooter();
345
346$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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:243
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='')
Make control on an uploaded file from an GUI page and move it to final destination.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return 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.
Contact()
Old copy.
Definition index.php:572