perso.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. /**
  21. * \file htdocs/contact/perso.php
  22. * \ingroup societe
  23. * \brief Onglet informations personnelles d'un contact
  24. */
  25. // Load Dolibarr environment
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('companies', 'other'));
  32. $id = GETPOST('id', 'int');
  33. $action = GETPOST('action', 'aZ09');
  34. // Security check
  35. if ($user->socid) {
  36. $socid = $user->socid;
  37. }
  38. $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
  39. $object = new Contact($db);
  40. $errors = array();
  41. /*
  42. * Action
  43. */
  44. if ($action == 'update' && !GETPOST("cancel") && $user->hasRight('societe', 'contact', 'creer')) {
  45. $ret = $object->fetch($id);
  46. // Note: Correct date should be completed with location to have exact GM time of birth.
  47. $object->birthday = dol_mktime(0, 0, 0, GETPOST("birthdaymonth"), GETPOST("birthdayday"), GETPOST("birthdayyear"));
  48. $object->birthday_alert = GETPOST("birthday_alert");
  49. if (GETPOST('deletephoto')) {
  50. $object->photo = '';
  51. } elseif (!empty($_FILES['photo']['name'])) {
  52. $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
  53. }
  54. $result = $object->update_perso($id, $user);
  55. if ($result > 0) {
  56. $object->oldcopy = dol_clone($object);
  57. // Logo/Photo save
  58. $dir = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos';
  59. $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
  60. if ($file_OK) {
  61. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  62. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  63. if (GETPOST('deletephoto')) {
  64. $fileimg = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/'.$object->photo;
  65. $dirthumbs = $conf->societe->dir_output.'/contact/'.get_exdir($object->id, 0, 0, 1, $object, 'contact').'/photos/thumbs';
  66. dol_delete_file($fileimg);
  67. dol_delete_dir_recursive($dirthumbs);
  68. }
  69. if (image_format_supported($_FILES['photo']['name']) > 0) {
  70. dol_mkdir($dir);
  71. if (@is_dir($dir)) {
  72. $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
  73. if (!dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']) > 0) {
  74. setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
  75. } else {
  76. // Create thumbs
  77. $object->addThumbs($newfile);
  78. }
  79. }
  80. } else {
  81. setEventMessages("ErrorBadImageFormat", null, 'errors');
  82. }
  83. } else {
  84. switch ($_FILES['photo']['error']) {
  85. case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
  86. case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
  87. $errors[] = "ErrorFileSizeTooLarge";
  88. break;
  89. case 3: //uploaded file was only partially uploaded
  90. $errors[] = "ErrorFilePartiallyUploaded";
  91. break;
  92. }
  93. }
  94. } else {
  95. $error = $object->error;
  96. }
  97. }
  98. /*
  99. * View
  100. */
  101. $now = dol_now();
  102. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  103. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
  104. $title = $object->lastname;
  105. }
  106. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  107. llxHeader('', $title, $help_url);
  108. $form = new Form($db);
  109. $formcompany = new FormCompany($db);
  110. $object->fetch($id, $user);
  111. $head = contact_prepare_head($object);
  112. if ($action == 'edit') {
  113. /*
  114. * Fiche en mode edition
  115. */
  116. print '<form name="perso" method="POST" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  117. print '<input type="hidden" name="token" value="'.newToken().'">';
  118. print '<input type="hidden" name="action" value="update">';
  119. print '<input type="hidden" name="id" value="'.$object->id.'">';
  120. print dol_get_fiche_head($head, 'perso', $title, 0, 'contact');
  121. print '<table class="border centpercent">';
  122. // Ref
  123. print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>';
  124. print $object->id;
  125. print '</td>';
  126. // Name
  127. print '<tr><td>'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td>'.$object->lastname.'</td></tr>';
  128. print '<tr><td>'.$langs->trans("Firstname").'</td><td>'.$object->firstname.'</td>';
  129. // Company
  130. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  131. if ($object->socid > 0) {
  132. $objsoc = new Societe($db);
  133. $objsoc->fetch($object->socid);
  134. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>'.$objsoc->getNomUrl(1).'</td>';
  135. } else {
  136. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
  137. print $langs->trans("ContactNotLinkedToCompany");
  138. print '</td></tr>';
  139. }
  140. }
  141. // Civility
  142. print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td>';
  143. print $object->getCivilityLabel();
  144. //print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'alpha') : $object->civility_code, 'civility_code');
  145. print '</td></tr>';
  146. // Photo
  147. print '<tr class="hideonsmartphone">';
  148. print '<td>'.$form->editfieldkey('PhotoFile', 'photoinput', '', $object, 0).'</td>';
  149. print '<td>';
  150. if ($object->photo) {
  151. print $form->showphoto('contact', $object);
  152. }
  153. $caneditfield = 1;
  154. if ($caneditfield) {
  155. if ($object->photo) {
  156. print "<br>\n";
  157. }
  158. print '<table class="nobordernopadding">';
  159. if ($object->photo) {
  160. print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> <label for="photodelete">'.$langs->trans("Delete").'</photo><br><br></td></tr>';
  161. }
  162. //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
  163. print '<tr><td>';
  164. $maxfilesizearray = getMaxFileSizeArray();
  165. $maxmin = $maxfilesizearray['maxmin'];
  166. if ($maxmin > 0) {
  167. print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
  168. }
  169. print '<input type="file" class="flat" name="photo" id="photoinput">';
  170. print '</td></tr>';
  171. print '</table>';
  172. }
  173. print '</td>';
  174. print '</tr>';
  175. // Date To Birth
  176. print '<tr><td>'.$langs->trans("DateOfBirth").'</td><td>';
  177. $form = new Form($db);
  178. print $form->selectDate($object->birthday, 'birthday', 0, 0, 1, "perso", 1, 0);
  179. print ' &nbsp; &nbsp; ';
  180. print '<label for="birthday_alert">'.$langs->trans("BirthdayAlert").':</label> ';
  181. if (!empty($object->birthday_alert)) {
  182. print '<input type="checkbox" id="birthday_alert" name="birthday_alert" checked>';
  183. } else {
  184. print '<input type="checkbox" id="birthday_alert" name="birthday_alert">';
  185. }
  186. print '</td>';
  187. print '</tr>';
  188. print "</table>";
  189. print dol_get_fiche_end();
  190. print $form->buttonsSaveCancel();
  191. print "</form>";
  192. } else {
  193. // View mode
  194. print dol_get_fiche_head($head, 'perso', $title, -1, 'contact');
  195. $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  196. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
  197. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  198. $morehtmlref .= '</a>';
  199. $morehtmlref .= '<div class="refidno">';
  200. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  201. $objsoc = new Societe($db);
  202. $objsoc->fetch($object->socid);
  203. // Thirdparty
  204. if ($objsoc->id > 0) {
  205. $morehtmlref .= $objsoc->getNomUrl(1);
  206. } else {
  207. $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
  208. }
  209. }
  210. $morehtmlref .= '</div>';
  211. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  212. print '<div class="fichecenter">';
  213. print '<div class="underbanner clearboth"></div>';
  214. print '<table class="border centpercent tableforfield">';
  215. // Company
  216. /*
  217. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  218. {
  219. if ($object->socid > 0)
  220. {
  221. $objsoc = new Societe($db);
  222. $objsoc->fetch($object->socid);
  223. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
  224. }
  225. else
  226. {
  227. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
  228. print $langs->trans("ContactNotLinkedToCompany");
  229. print '</td></tr>';
  230. }
  231. }*/
  232. // Civility
  233. print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td colspan="3">';
  234. print $object->getCivilityLabel();
  235. print '</td></tr>';
  236. // Date To Birth
  237. print '<tr>';
  238. if (!empty($object->birthday)) {
  239. include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  240. print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3">'.dol_print_date($object->birthday, "day");
  241. print ' &nbsp; ';
  242. //var_dump($birthdatearray);
  243. $ageyear = convertSecondToTime($now - $object->birthday, 'year') - 1970;
  244. $agemonth = convertSecondToTime($now - $object->birthday, 'month') - 1;
  245. if ($ageyear >= 2) {
  246. print '('.$ageyear.' '.$langs->trans("DurationYears").')';
  247. } elseif ($agemonth >= 2) {
  248. print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
  249. } else {
  250. print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
  251. }
  252. print ' &nbsp; - &nbsp; ';
  253. if ($object->birthday_alert) {
  254. print $langs->trans("BirthdayAlertOn");
  255. } else {
  256. print $langs->trans("BirthdayAlertOff");
  257. }
  258. print '</td>';
  259. } else {
  260. print '<td>'.$langs->trans("DateOfBirth").'</td><td colspan="3"></td>';
  261. }
  262. print "</tr>";
  263. print "</table>";
  264. print '</div>';
  265. print dol_get_fiche_end();
  266. }
  267. if ($action != 'edit') {
  268. /*
  269. * Action bar
  270. */
  271. if ($user->socid == 0) {
  272. print '<div class="tabsAction">';
  273. if ($user->rights->societe->contact->creer) {
  274. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
  275. }
  276. print "</div>";
  277. }
  278. }
  279. llxFooter();
  280. $db->close();