perso.php 10 KB

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