perso.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/contact/perso.php
  21. * \ingroup societe
  22. * \brief Onglet informations personnelles d'un contact
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
  27. $langs->load("companies");
  28. $langs->load("other");
  29. $id = GETPOST('id','int');
  30. $action = GETPOST('action','alpha');
  31. // Security check
  32. if ($user->societe_id) $socid=$user->societe_id;
  33. $result = restrictedArea($user, 'contact', $id, 'socpeople&societe');
  34. $object = new Contact($db);
  35. /*
  36. * Action
  37. */
  38. if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
  39. {
  40. $ret = $object->fetch($id);
  41. // Note: Correct date should be completed with location to have exact GM time of birth.
  42. $object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]);
  43. $object->birthday_alert = $_POST["birthday_alert"];
  44. $result = $object->update_perso($id, $user);
  45. if ($result > 0)
  46. {
  47. $object->old_name='';
  48. $object->old_firstname='';
  49. }
  50. else
  51. {
  52. $error = $object->error;
  53. }
  54. }
  55. /*
  56. * View
  57. */
  58. $now=dol_now();
  59. $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  60. llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
  61. $form = new Form($db);
  62. $object->fetch($id, $user);
  63. $head = contact_prepare_head($object);
  64. dol_fiche_head($head, 'perso', $title, 0, 'contact');
  65. if ($action == 'edit')
  66. {
  67. /*
  68. * Fiche en mode edition
  69. */
  70. print '<form name="perso" method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  71. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  72. print '<input type="hidden" name="action" value="update">';
  73. print '<input type="hidden" name="id" value="'.$object->id.'">';
  74. print '<table class="border" width="100%">';
  75. // Ref
  76. print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
  77. print $object->id;
  78. print '</td></tr>';
  79. // Name
  80. print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
  81. print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td>';
  82. // Company
  83. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  84. {
  85. if ($object->socid > 0)
  86. {
  87. $objsoc = new Societe($db);
  88. $objsoc->fetch($object->socid);
  89. print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td>';
  90. }
  91. else
  92. {
  93. print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
  94. print $langs->trans("ContactNotLinkedToCompany");
  95. print '</td></tr>';
  96. }
  97. }
  98. // Civility
  99. print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
  100. print $object->getCivilityLabel();
  101. print '</td></tr>';
  102. // Date To Birth
  103. print '<tr><td>'.$langs->trans("DateToBirth").'</td><td>';
  104. $form=new Form($db);
  105. print $form->select_date($object->birthday,'birthday',0,0,1,"perso");
  106. print '</td>';
  107. print '<td colspan="2">'.$langs->trans("Alert").': ';
  108. if (! empty($object->birthday_alert))
  109. {
  110. print '<input type="checkbox" name="birthday_alert" checked="checked"></td>';
  111. }
  112. else
  113. {
  114. print '<input type="checkbox" name="birthday_alert"></td>';
  115. }
  116. print '</tr>';
  117. print "</table><br>";
  118. print '<center>';
  119. print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  120. print ' &nbsp; ';
  121. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  122. print '</center>';
  123. print "</form>";
  124. }
  125. else
  126. {
  127. /*
  128. * Fiche en mode visu
  129. */
  130. print '<table class="border" width="100%">';
  131. $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
  132. // Ref
  133. print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
  134. print $form->showrefnav($object, 'id', $linkback);
  135. print '</td></tr>';
  136. // Name
  137. print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
  138. print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td></tr>';
  139. // Company
  140. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  141. {
  142. if ($object->socid > 0)
  143. {
  144. $objsoc = new Societe($db);
  145. $objsoc->fetch($object->socid);
  146. print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
  147. }
  148. else
  149. {
  150. print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
  151. print $langs->trans("ContactNotLinkedToCompany");
  152. print '</td></tr>';
  153. }
  154. }
  155. // Civility
  156. print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
  157. print $object->getCivilityLabel();
  158. print '</td></tr>';
  159. // Date To Birth
  160. print '<tr>';
  161. if (! empty($object->birthday))
  162. {
  163. include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  164. print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.dol_print_date($object->birthday,"day");
  165. print ' &nbsp; ';
  166. //var_dump($birthdatearray);
  167. $ageyear=convertSecondToTime($now-$object->birthday,'year')-1970;
  168. $agemonth=convertSecondToTime($now-$object->birthday,'month')-1;
  169. if ($ageyear >= 2) print '('.$ageyear.' '.$langs->trans("DurationYears").')';
  170. else if ($agemonth >= 2) print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
  171. else print '('.$agemonth.' '.$langs->trans("DurationMonth").')';
  172. print ' &nbsp; - &nbsp; ';
  173. if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn");
  174. else print $langs->trans("BirthdayAlertOff");
  175. print '</td>';
  176. }
  177. else
  178. {
  179. print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.$langs->trans("Unknown")."</td>";
  180. }
  181. print "</tr>";
  182. print "</table>";
  183. }
  184. dol_fiche_end();
  185. if ($action != 'edit')
  186. {
  187. // Barre d'actions
  188. if ($user->societe_id == 0)
  189. {
  190. print '<div class="tabsAction">';
  191. if ($user->rights->societe->contact->creer)
  192. {
  193. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
  194. }
  195. print "</div>";
  196. }
  197. }
  198. llxFooter();
  199. $db->close();