perso.php 10 KB

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