PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/contact/perso.php

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