PageRenderTime 62ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/contact/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 917 lines | 653 code | 157 blank | 107 comment | 167 complexity | c37ea67a770ad461d088a323436a88d7 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. require '../main.inc.php';
  22. require_once DOL_DOCUMENT_ROOT . '/agenda/class/agenda.class.php';
  23. require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
  24. require_once DOL_DOCUMENT_ROOT . '/core/lib/contact.lib.php';
  25. require_once DOL_DOCUMENT_ROOT . '/societe/lib/societe.lib.php';
  26. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  27. $langs->load("companies");
  28. $langs->load("users");
  29. $langs->load("other");
  30. $langs->load("commercial");
  31. $mesg = '';
  32. $error = 0;
  33. $errors = array();
  34. $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
  35. $confirm = GETPOST('confirm', 'alpha');
  36. $backtopage = GETPOST('backtopage', 'alpha');
  37. $id = GETPOST('id', 'alpha');
  38. $socid = GETPOST('socid', 'alpha');
  39. if ($user->societe_id)
  40. $socid = $user->societe_id;
  41. $object = new Contact($db);
  42. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  43. $object->getCanvas($id);
  44. $objcanvas = null;
  45. $canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
  46. if (!empty($canvas)) {
  47. require_once DOL_DOCUMENT_ROOT . '/core/class/canvas.class.php';
  48. $objcanvas = new Canvas($db, $action);
  49. $objcanvas->getCanvas('contact', 'contactcard', $canvas);
  50. }
  51. // Security check
  52. $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', '', $objcanvas); // If we create a contact with no company (shared contacts), no check on write permission
  53. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  54. $hookmanager->initHooks(array('contactcard'));
  55. /*
  56. * Actions
  57. */
  58. $parameters = array('id' => $id, 'objcanvas' => $objcanvas);
  59. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  60. $error = $hookmanager->error;
  61. $errors = array_merge($errors, (array) $hookmanager->errors);
  62. if (empty($reshook)) {
  63. // Cancel
  64. if (GETPOST("cancel") && !empty($backtopage)) {
  65. header("Location: " . $backtopage);
  66. exit;
  67. }
  68. // Creation utilisateur depuis contact
  69. if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) {
  70. // Recuperation contact actuel
  71. $result = $object->fetch($id);
  72. if ($result > 0) {
  73. $db->begin();
  74. // Creation user
  75. $nuser = new User($db);
  76. $result = $nuser->create_from_contact($object, $_POST["login"]);
  77. if ($result > 0) {
  78. $result2 = $nuser->setPassword($user, $_POST["password"], 0, 0, 1);
  79. if ($result2) {
  80. $db->commit();
  81. } else {
  82. $error = $nuser->error;
  83. $errors = $nuser->errors;
  84. $db->rollback();
  85. }
  86. } else {
  87. $error = $nuser->error;
  88. $errors = $nuser->errors;
  89. $db->rollback();
  90. }
  91. } else {
  92. $error = $object->error;
  93. $errors = $object->errors;
  94. }
  95. }
  96. // Add contact
  97. if ($action == 'add' && $user->rights->societe->contact->creer) {
  98. if ($canvas)
  99. $object->canvas = $canvas;
  100. $object->societe->id = $_POST["socid"];
  101. $object->lastname = $_POST["lastname"];
  102. $object->firstname = $_POST["firstname"];
  103. $object->civilite_id = $_POST["civilite_id"];
  104. $object->poste = $_POST["poste"];
  105. $object->address = $_POST["address"];
  106. $object->zip = $_POST["zipcode"];
  107. $object->town = $_POST["town"];
  108. $object->country_id = $_POST["country_id"];
  109. $object->state_id = $_POST["departement_id"];
  110. $object->email = $_POST["email"];
  111. $object->phone_pro = $_POST["phone_pro"];
  112. $object->phone_perso = $_POST["phone_perso"];
  113. $object->phone_mobile = $_POST["phone_mobile"];
  114. $object->fax = $_POST["fax"];
  115. $object->jabberid = $_POST["jabberid"];
  116. $object->no_email = $_POST["no_email"];
  117. $object->note = $_POST["note"];
  118. // Note: Correct date should be completed with location to have exact GM time of birth.
  119. $object->birthday = dol_mktime(0, 0, 0, $_POST["birthdaymonth"], $_POST["birthdayday"], $_POST["birthdayyear"]);
  120. $object->birthday_alert = $_POST["birthday_alert"];
  121. // Get extra fields
  122. foreach ($_POST as $key => $value) {
  123. if (preg_match("/^options_/", $key)) {
  124. $object->array_options[$key] = GETPOST($key);
  125. }
  126. }
  127. if (!$_POST["lastname"]) {
  128. $error++;
  129. $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname") . ' / ' . $langs->transnoentities("Label"));
  130. $action = 'create';
  131. }
  132. if (!$error) {
  133. $id = $object->create($user);
  134. if (is_numeric($id) && $id <= 0) {
  135. $error++;
  136. $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
  137. $action = 'create';
  138. }
  139. }
  140. if (!$error && is_nan($id)) {
  141. if (!empty($backtopage))
  142. $url = $backtopage;
  143. else
  144. $url = 'fiche.php?id=' . $id;
  145. header("Location: " . $url);
  146. exit;
  147. }
  148. }
  149. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->contact->supprimer) {
  150. $result = $object->fetch($_GET["id"]);
  151. $object->old_name = $_POST["old_name"];
  152. $object->old_firstname = $_POST["old_firstname"];
  153. $result = $object->delete();
  154. if ($result > 0) {
  155. header("Location: " . DOL_URL_ROOT . '/contact/list.php');
  156. exit;
  157. } else {
  158. $error = $object->error;
  159. $errors = $object->errors;
  160. }
  161. }
  162. if ($action == 'update' && !$_POST["cancel"] && $user->rights->societe->contact->creer) {
  163. if (empty($_POST["lastname"])) {
  164. $error++;
  165. $errors = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name") . ' / ' . $langs->transnoentities("Label")));
  166. $action = 'edit';
  167. }
  168. if (!$error) {
  169. $object->fetch($_POST["contactid"]);
  170. $object->oldcopy = dol_clone($object);
  171. $object->old_name = $_POST["old_name"];
  172. $object->old_firstname = $_POST["old_firstname"];
  173. $object->societe->id = $_POST["socid"];
  174. $object->lastname = $_POST["lastname"];
  175. $object->firstname = $_POST["firstname"];
  176. $object->civilite_id = $_POST["civilite_id"];
  177. $object->poste = $_POST["poste"];
  178. $object->address = $_POST["address"];
  179. $object->zip = $_POST["zipcode"];
  180. $object->town = $_POST["town"];
  181. $object->state_id = $_POST["departement_id"];
  182. $object->country_id = $_POST["country_id"];
  183. $object->email = $_POST["email"];
  184. $object->phone_pro = $_POST["phone_pro"];
  185. $object->phone_perso = $_POST["phone_perso"];
  186. $object->phone_mobile = $_POST["phone_mobile"];
  187. $object->fax = $_POST["fax"];
  188. $object->jabberid = $_POST["jabberid"];
  189. $object->no_email = $_POST["no_email"];
  190. $object->note = $_POST["note"];
  191. // Get extra fields
  192. foreach ($_POST as $key => $value) {
  193. if (preg_match("/^options_/", $key)) {
  194. $object->array_options[$key] = GETPOST($key);
  195. }
  196. }
  197. $result = $object->update($_POST["contactid"], $user);
  198. if ($result > 0) {
  199. $object->old_name = '';
  200. $object->old_firstname = '';
  201. $action = 'view';
  202. } else {
  203. $error = $object->error;
  204. $errors = $object->errors;
  205. $action = 'edit';
  206. }
  207. }
  208. }
  209. }
  210. /*
  211. * View
  212. */
  213. llxHeader('', $langs->trans("ContactsAddresses"));
  214. $form = new Form($db);
  215. $formcompany = new FormCompany($db);
  216. $countrynotdefined = $langs->trans("ErrorSetACountryFirst") . ' (' . $langs->trans("SeeAbove") . ')';
  217. if (!empty($socid)) {
  218. $objsoc = new Societe($db);
  219. $objsoc->fetch($socid);
  220. }
  221. if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
  222. // -----------------------------------------
  223. // When used with CANVAS
  224. // -----------------------------------------
  225. if (empty($object->error) && $id) {
  226. $object = new Contact($db);
  227. $object->fetch($id);
  228. }
  229. $objcanvas->assign_values($action, $id); // Set value for templates
  230. $objcanvas->display_canvas($action); // Show template
  231. } else {
  232. // -----------------------------------------
  233. // When used in standard mode
  234. // -----------------------------------------
  235. // Confirm deleting contact
  236. if ($user->rights->societe->contact->supprimer) {
  237. if ($action == 'delete') {
  238. $ret = $form->form_confirm($_SERVER["PHP_SELF"] . "?id=" . $_GET["id"], $langs->trans("DeleteContact"), $langs->trans("ConfirmDeleteContact"), "confirm_delete", '', 0, 1);
  239. if ($ret == 'html')
  240. print '<br>';
  241. }
  242. }
  243. /*
  244. * Onglets
  245. */
  246. if (!empty($id)) {
  247. // Si edition contact deja existant
  248. $object = new Contact($db);
  249. $res = $object->fetch($id);
  250. // Show tabs
  251. //$head = contact_prepare_head($object);
  252. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  253. print_fiche_titre($object->firstname . " " . $object->lastname);
  254. print '<div class="with-padding">';
  255. print '<div class="columns">';
  256. print column_start();
  257. //print start_box($title, $object->fk_extrafields->ico);
  258. dol_fiche_head($head, 'card', $title, 0, 'contact');
  259. }
  260. if ($user->rights->societe->contact->creer) {
  261. if ($action == 'create') {
  262. /*
  263. * Fiche en mode creation
  264. */
  265. $object->canvas = $canvas;
  266. $object->state_id = $_POST["state_id"];
  267. // We set country_id, country_code and label for the selected country
  268. $object->country_id = $_POST["country_id"] ? $_POST["country_id"] : $mysoc->country_id;
  269. $title = $addcontact = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
  270. print_fiche_titre($title);
  271. print '<div class="with-padding">';
  272. print '<div class="columns">';
  273. // Affiche les erreurs
  274. dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
  275. print column_start();
  276. print "\n" . '<script type="text/javascript" language="javascript">' . "\n";
  277. print 'jQuery(document).ready(function () {
  278. jQuery("#selectcountry_id").change(function() {
  279. document.formsoc.action.value="create";
  280. document.formsoc.submit();
  281. });
  282. $("#copyaddressfromsoc").click(function() {
  283. $(\'textarea[name="address"]\').text("' . addslashes($objsoc->address) . '");
  284. $(\'input[name="zipcode"]\').val("' . addslashes($objsoc->zip) . '");
  285. $(\'input[name="town"]\').val("' . addslashes($objsoc->town) . '");
  286. $(\'select[name="country_id"]\').val("' . addslashes($objsoc->country_id) . '");
  287. $(\'select[name="state_id"]\').val("' . addslashes($objsoc->state_id) . '");
  288. });
  289. })' . "\n";
  290. print '</script>' . "\n";
  291. print '<form method="post" name="formsoc" action="' . $_SERVER["PHP_SELF"] . '">';
  292. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  293. print '<input type="hidden" name="action" value="add">';
  294. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  295. print '<table class="border" width="100%">';
  296. // Name
  297. print '<tr><td width="20%" class="fieldrequired">' . $langs->trans("Lastname") . ' / ' . $langs->trans("Label") . '</td><td width="30%"><input name="lastname" type="text" size="30" maxlength="80" value="' . (isset($_POST["lastname"]) ? $_POST["lastname"] : $object->lastname) . '"></td>';
  298. print '<td width="20%">' . $langs->trans("Firstname") . '</td><td width="30%"><input name="firstname" type="text" size="30" maxlength="80" value="' . (isset($_POST["firstname"]) ? $_POST["firstname"] : $object->firstname) . '"></td></tr>';
  299. // Company
  300. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  301. if (!empty($socid)) {
  302. print '<tr><td>' . $langs->trans("Company") . '</td>';
  303. print '<td colspan="3">';
  304. print $objsoc->getNomUrl(1);
  305. print '</td>';
  306. print '<input type="hidden" name="socid" value="' . $objsoc->id . '">';
  307. print '</td></tr>';
  308. } else {
  309. print '<tr><td>' . $langs->trans("Company") . '</td><td colspan="3">';
  310. print $object->select_fk_extrafields('societe', 'socid', null, true, 25);
  311. print '</td></tr>';
  312. }
  313. }
  314. // Civility
  315. print '<tr><td width="15%">' . $langs->trans("UserTitle") . '</td><td colspan="3">';
  316. print $object->select_fk_extrafields("civilite_id", "civilite_id");
  317. print '</td></tr>';
  318. print '<tr><td>' . $langs->trans("PostOrFunction") . '</td><td colspan="3"><input name="poste" type="text" size="50" maxlength="80" value="' . (isset($_POST["poste"]) ? $_POST["poste"] : $object->poste) . '"></td>';
  319. // Address
  320. if (($objsoc->typent_code == 'TE_PRIVATE' || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->address)) == 0)
  321. $object->address = $objsoc->address; // Predefined with third party
  322. print '<tr><td>' . $langs->trans("Address");
  323. print '</td><td colspan="2"><textarea class="flat" name="address" cols="70">' . (isset($_POST["address"]) ? $_POST["address"] : $object->address) . '</textarea></td>';
  324. $rowspan = 3;
  325. if (empty($conf->global->SOCIETE_DISABLE_STATE))
  326. $rowspan++;
  327. print '<td valign="middle" align="center" rowspan="' . $rowspan . '">';
  328. if ($conf->use_javascript_ajax && $socid)
  329. print '<a href="#" id="copyaddressfromsoc">' . $langs->trans('CopyAddressFromSoc') . '</a>';
  330. print '</td>';
  331. print '</tr>';
  332. // Zip / Town
  333. if (($objsoc->typent_code == 'TE_PRIVATE' || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->zip)) == 0)
  334. $object->zip = $objsoc->zip; // Predefined with third party
  335. if (($objsoc->typent_code == 'TE_PRIVATE' || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->town)) == 0)
  336. $object->town = $objsoc->town; // Predefined with third party
  337. print '<tr><td>' . $langs->trans("Zip") . ' / ' . $langs->trans("Town") . '</td><td colspan="2">';
  338. print $formcompany->select_ziptown((isset($_POST["zipcode"]) ? $_POST["zipcode"] : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6) . '&nbsp;';
  339. print $formcompany->select_ziptown((isset($_POST["town"]) ? $_POST["town"] : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
  340. print '</td></tr>';
  341. // Country
  342. if (dol_strlen(trim($object->country_id)) == 0)
  343. $object->country_id = $objsoc->country_id; // Predefined with third party
  344. print '<tr><td>' . $langs->trans("Country") . '</td><td colspan="2">';
  345. print $object->select_fk_extrafields("country_id", "country_id");
  346. if ($user->admin)
  347. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1);
  348. print '</td></tr>';
  349. // State
  350. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  351. print '<tr><td>' . $langs->trans('State') . '</td><td colspan="2">';
  352. if ($object->country_id) {
  353. print $object->select_fk_extrafields("state_id", 'state_id');
  354. } else {
  355. print $countrynotdefined;
  356. }
  357. print '</td></tr>';
  358. }
  359. // Phone / Fax
  360. if (($objsoc->typent_code == 'TE_PRIVATE' || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->phone_pro)) == 0)
  361. $object->phone_pro = $objsoc->tel; // Predefined with third party
  362. print '<tr><td>' . $langs->trans("PhonePro") . '</td><td><input name="phone_pro" type="text" size="18" maxlength="80" value="' . (isset($_POST["phone_pro"]) ? $_POST["phone_pro"] : $object->phone_pro) . '"></td>';
  363. print '<td>' . $langs->trans("PhonePerso") . '</td><td><input name="phone_perso" type="text" size="18" maxlength="80" value="' . (isset($_POST["phone_perso"]) ? $_POST["phone_perso"] : $object->phone_perso) . '"></td></tr>';
  364. if (($objsoc->typent_code == 'TE_PRIVATE' || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->fax)) == 0)
  365. $object->fax = $objsoc->fax; // Predefined with third party
  366. print '<tr><td>' . $langs->trans("PhoneMobile") . '</td><td><input name="phone_mobile" type="text" size="18" maxlength="80" value="' . (isset($_POST["phone_mobile"]) ? $_POST["phone_mobile"] : $object->phone_mobile) . '"></td>';
  367. print '<td>' . $langs->trans("Fax") . '</td><td><input name="fax" type="text" size="18" maxlength="80" value="' . (isset($_POST["fax"]) ? $_POST["fax"] : $object->fax) . '"></td></tr>';
  368. // EMail
  369. if (($objsoc->typent_code == 'TE_PRIVATE' || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->email)) == 0)
  370. $object->email = $objsoc->email; // Predefined with third party
  371. print '<tr><td>' . $langs->trans("Email") . '</td><td><input name="email" type="text" size="40" maxlength="80" value="' . (isset($_POST["email"]) ? $_POST["email"] : $object->email) . '"></td>';
  372. if (!empty($conf->mailing->enabled)) {
  373. print '<td>' . $langs->trans("No_Email") . '</td><td>' . $form->selectyesno('no_email', (isset($_POST["no_email"]) ? $_POST["no_email"] : $object->no_email), 1) . '</td>';
  374. } else {
  375. print '<td colspan="2">&nbsp;</td>';
  376. }
  377. print '</tr>';
  378. // Instant message and no email
  379. print '<tr><td>' . $langs->trans("IM") . '</td><td colspan="3"><input name="jabberid" type="text" size="50" maxlength="80" value="' . (isset($_POST["jabberid"]) ? $_POST["jabberid"] : $object->jabberid) . '"></td></tr>';
  380. // Note
  381. print '<tr><td valign="top">' . $langs->trans("Note") . '</td><td colspan="3" valign="top"><textarea name="note" cols="70" rows="' . ROWS_3 . '">' . (isset($_POST["note"]) ? $_POST["note"] : $object->note) . '</textarea></td></tr>';
  382. // Other attributes
  383. $parameters = array('colspan' => ' colspan="3"');
  384. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  385. if (empty($reshook)) {
  386. foreach ($object->fk_extrafields->fields as $key => $aRow) {
  387. if ($aRow->optional && $aRow->enable) {
  388. $value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : (isset($object->array_options["options_" . $key]) ? $object->array_options["options_" . $key] : ''));
  389. print '<tr><td>' . $aRow->label . '</td><td colspan="3">';
  390. print $object->fk_extrafields->showInputField($key, $value);
  391. print '</td></tr>' . "\n";
  392. }
  393. }
  394. }
  395. print "</table><br>";
  396. // Add personnal information
  397. print_fiche_titre('<div class="comboperso">' . $langs->trans("PersonalInformations") . '</div>', '', '');
  398. print '<table class="border" width="100%">';
  399. // Date To Birth
  400. print '<tr><td width="20%">' . $langs->trans("DateToBirth") . '</td><td width="30%">';
  401. $form = new Form($db);
  402. if ($object->birthday) {
  403. print $form->select_date($object->birthday, 'birthday', 0, 0, 0, "perso");
  404. } else {
  405. print $form->select_date('', 'birthday', 0, 0, 1, "perso");
  406. }
  407. print '</td>';
  408. print '<td colspan="2">' . $langs->trans("Alert") . ': ';
  409. if ($object->birthday_alert) {
  410. print '<input type="checkbox" name="birthday_alert" checked></td>';
  411. } else {
  412. print '<input type="checkbox" name="birthday_alert"></td>';
  413. }
  414. print '</tr>';
  415. print "</table><br><br>";
  416. print '<center>';
  417. print '<input type="submit" class="button" name="add" value="' . $langs->trans("Add") . '">';
  418. if (!empty($backtopage)) {
  419. print ' &nbsp; &nbsp; ';
  420. print '<input type="submit" class="button" name="cancel" value="' . $langs->trans("Cancel") . '">';
  421. }
  422. print '</center>';
  423. print "</form>";
  424. print column_end();
  425. } elseif ($action == 'edit' && !empty($id)) {
  426. /*
  427. * Fiche en mode edition
  428. */
  429. // Affiche les erreurs
  430. dol_htmloutput_errors($error, $errors);
  431. print "\n" . '<script type="text/javascript" language="javascript">' . "\n";
  432. print 'jQuery(document).ready(function () {
  433. jQuery("#selectcountry_id").change(function() {
  434. document.formsoc.action.value="edit";
  435. document.formsoc.submit();
  436. });
  437. $("#copyaddressfromsoc").click(function() {
  438. $(\'textarea[name="address"]\').text("' . addslashes($objsoc->address) . '");
  439. $(\'input[name="zipcode"]\').val("' . addslashes($objsoc->zip) . '");
  440. $(\'input[name="town"]\').val("' . addslashes($objsoc->town) . '");
  441. $(\'select[name="country_id"]\').val("' . addslashes($objsoc->country_id) . '");
  442. $(\'select[name="state_id"]\').val("' . addslashes($objsoc->state_id) . '");
  443. return false;
  444. });
  445. })' . "\n";
  446. print '</script>' . "\n";
  447. print '<form method="post" action="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '" name="formsoc">';
  448. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  449. print '<input type="hidden" name="id" value="' . $id . '">';
  450. print '<input type="hidden" name="action" value="update">';
  451. print '<input type="hidden" name="contactid" value="' . $object->id . '">';
  452. print '<input type="hidden" name="old_name" value="' . $object->name . '">';
  453. print '<input type="hidden" name="old_firstname" value="' . $object->firstname . '">';
  454. if (!empty($backtopage))
  455. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  456. print '<table class="border" width="100%">';
  457. // Ref
  458. print '<tr><td>' . $langs->trans("Ref") . '</td><td colspan="3">';
  459. print $form->showrefnav($object, 'ref', '', 1, 'ref');
  460. print '</td></tr>';
  461. // Name
  462. print '<tr><td width="20%" class="fieldrequired">' . $langs->trans("Lastname") . ' / ' . $langs->trans("Label") . '</td><td width="30%"><input name="lastname" type="text" size="20" maxlength="80" value="' . (isset($_POST["lastname"]) ? $_POST["lastname"] : $object->lastname) . '"></td>';
  463. print '<td width="20%">' . $langs->trans("Firstname") . '</td><td width="30%"><input name="firstname" type="text" size="20" maxlength="80" value="' . (isset($_POST["firstname"]) ? $_POST["firstname"] : $object->firstname) . '"></td></tr>';
  464. // Company
  465. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  466. print '<tr><td>' . $langs->trans("Company") . '</td>';
  467. print '<td colspan="3">';
  468. print $object->select_fk_extrafields('societe', 'socid');
  469. print '</td>';
  470. print '</tr>';
  471. }
  472. // Civility
  473. print '<tr><td>' . $langs->trans("UserTitle") . '</td><td colspan="3">';
  474. print $object->select_fk_extrafields("civilite_id", "civilite_id");
  475. print '</td></tr>';
  476. print '<tr><td>' . $langs->trans("PostOrFunction") . '</td><td colspan="3"><input name="poste" type="text" size="50" maxlength="80" value="' . (isset($_POST["poste"]) ? $_POST["poste"] : $object->poste) . '"></td></tr>';
  477. // Address
  478. print '<tr><td>' . $langs->trans("Address");
  479. print '</td><td colspan="2"><textarea class="flat" name="address" cols="70">' . (isset($_POST["address"]) ? $_POST["address"] : $object->address) . '</textarea></td>';
  480. $rowspan = 3;
  481. if (empty($conf->global->SOCIETE_DISABLE_STATE))
  482. $rowspan++;
  483. print '<td valign="middle" align="center" rowspan="' . $rowspan . '">';
  484. if ($conf->use_javascript_ajax)
  485. print '<a href="" id="copyaddressfromsoc">' . $langs->trans('CopyAddressFromSoc') . '</a>';
  486. print '</td></tr>';
  487. // Zip / Town
  488. print '<tr><td>' . $langs->trans("Zip") . ' / ' . $langs->trans("Town") . '</td><td colspan="2">';
  489. print $formcompany->select_ziptown((isset($_POST["zipcode"]) ? $_POST["zipcode"] : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6) . '&nbsp;';
  490. print $formcompany->select_ziptown((isset($_POST["town"]) ? $_POST["town"] : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
  491. print '</td></tr>';
  492. // Country
  493. print '<tr><td>' . $langs->trans("Country") . '</td><td colspan="2">';
  494. print $object->select_fk_extrafields("country_id", "country_id");
  495. if ($user->admin)
  496. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1);
  497. print '</td></tr>';
  498. // State
  499. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  500. print '<tr><td>' . $langs->trans('State') . '</td><td colspan="2">';
  501. print $object->select_fk_extrafields("state_id", 'state_id');
  502. print '</td></tr>';
  503. }
  504. // Phone
  505. print '<tr><td>' . $langs->trans("PhonePro") . '</td><td><input name="phone_pro" type="text" size="18" maxlength="80" value="' . (isset($_POST["phone_pro"]) ? $_POST["phone_pro"] : $object->phone_pro) . '"></td>';
  506. print '<td>' . $langs->trans("PhonePerso") . '</td><td><input name="phone_perso" type="text" size="18" maxlength="80" value="' . (isset($_POST["phone_perso"]) ? $_POST["phone_perso"] : $object->phone_perso) . '"></td></tr>';
  507. print '<tr><td>' . $langs->trans("PhoneMobile") . '</td><td><input name="phone_mobile" type="text" size="18" maxlength="80" value="' . (isset($_POST["phone_mobile"]) ? $_POST["phone_mobile"] : $object->phone_mobile) . '"></td>';
  508. print '<td>' . $langs->trans("Fax") . '</td><td><input name="fax" type="text" size="18" maxlength="80" value="' . (isset($_POST["fax"]) ? $_POST["fax"] : $object->fax) . '"></td></tr>';
  509. // EMail
  510. print '<tr><td>' . $langs->trans("EMail") . '</td><td><input name="email" type="text" size="40" maxlength="80" value="' . (isset($_POST["email"]) ? $_POST["email"] : $object->email) . '"></td>';
  511. if (!empty($conf->mailing->enabled)) {
  512. $langs->load("mails");
  513. print '<td nowrap>' . $langs->trans("NbOfEMailingsReceived") . '</td>';
  514. print '<td>' . $object->getNbOfEMailings() . '</td>';
  515. } else {
  516. print '<td colspan="2">&nbsp;</td>';
  517. }
  518. print '</tr>';
  519. // Jabberid
  520. print '<tr><td>Jabberid</td><td><input name="jabberid" type="text" size="40" maxlength="80" value="' . (isset($_POST["jabberid"]) ? $_POST["jabberid"] : $object->jabberid) . '"></td>';
  521. if (!empty($conf->mailing->enabled)) {
  522. print '<td>' . $langs->trans("No_Email") . '</td><td>' . $form->selectyesno('no_email', (isset($_POST["no_email"]) ? $_POST["no_email"] : $object->no_email), 1) . '</td>';
  523. } else {
  524. print '<td colspan="2">&nbsp;</td>';
  525. }
  526. print '</tr>';
  527. // Other attributes
  528. $parameters = array('colspan' => ' colspan="3"');
  529. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  530. if (empty($reshook)) {
  531. foreach ($object->fk_extrafields->fields as $key => $aRow) {
  532. if ($aRow->optional && $aRow->enable) {
  533. $value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : (isset($object->array_options["options_" . $key]) ? $object->array_options["options_" . $key] : ''));
  534. print '<tr><td>' . $aRow->label . '</td><td colspan="3">';
  535. print $object->fk_extrafields->showInputField($key, $value);
  536. print '</td></tr>' . "\n";
  537. }
  538. }
  539. }
  540. $object->load_ref_elements();
  541. if (!empty($conf->commande->enabled)) {
  542. print '<tr><td>' . $langs->trans("ContactForOrders") . '</td><td colspan="3">';
  543. print $object->ref_commande ? $object->ref_commande : $langs->trans("NoContactForAnyOrder");
  544. print '</td></tr>';
  545. }
  546. if (!empty($conf->propal->enabled)) {
  547. print '<tr><td>' . $langs->trans("ContactForProposals") . '</td><td colspan="3">';
  548. print $object->ref_propal ? $object->ref_propal : $langs->trans("NoContactForAnyProposal");
  549. print '</td></tr>';
  550. }
  551. if (!empty($conf->contrat->enabled)) {
  552. print '<tr><td>' . $langs->trans("ContactForContracts") . '</td><td colspan="3">';
  553. print $object->ref_contrat ? $object->ref_contrat : $langs->trans("NoContactForAnyContract");
  554. print '</td></tr>';
  555. }
  556. if (!empty($conf->facture->enabled)) {
  557. print '<tr><td>' . $langs->trans("ContactForInvoices") . '</td><td colspan="3">';
  558. print $object->ref_facturation ? $object->ref_facturation : $langs->trans("NoContactForAnyInvoice");
  559. print '</td></tr>';
  560. }
  561. // Login Dolibarr
  562. print '<tr><td>' . $langs->trans("SpeedealingLogin") . '</td><td colspan="3">';
  563. if ($object->user_id) {
  564. $dolibarr_user = new User($db);
  565. $result = $dolibarr_user->fetch($object->user_id);
  566. print $dolibarr_user->getLoginUrl(1);
  567. }
  568. else
  569. print $langs->trans("NoSpeedealingAccess");
  570. print '</td></tr>';
  571. print '</table><br>';
  572. print '<center>';
  573. print '<input type="submit" class="button" name="save" value="' . $langs->trans("Save") . '">';
  574. print ' &nbsp; ';
  575. print '<input type="submit" class="button" name="cancel" value="' . $langs->trans("Cancel") . '">';
  576. print '</center>';
  577. print "</form>";
  578. print column_end();
  579. }
  580. }
  581. if (!empty($id) && $action != 'edit' && $action != 'create') {
  582. $objsoc = new Societe($db);
  583. /*
  584. * Fiche en mode visualisation
  585. */
  586. dol_htmloutput_errors($error, $errors);
  587. if ($action == 'create_user') {
  588. // Full firstname and name separated with a dot : firstname.name
  589. include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
  590. $login = dol_buildlogin($object->nom, $object->prenom);
  591. $generated_password = '';
  592. if (!$ldap_sid) { // TODO ldap_sid ?
  593. require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
  594. $generated_password = getRandomPassword('');
  595. }
  596. $password = $generated_password;
  597. // Create a form array
  598. $formquestion = array(
  599. array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
  600. array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password),
  601. //array('label' => $form->textwithpicto($langs->trans("Type"),$langs->trans("InternalExternalDesc")), 'type' => 'select', 'name' => 'intern', 'default' => 1, 'values' => array(0=>$langs->trans('Internal'),1=>$langs->trans('External')))
  602. );
  603. $text = $langs->trans("ConfirmCreateContact") . '<br>';
  604. if (!empty($conf->societe->enabled)) {
  605. if ($object->societe->id > 0)
  606. $text.=$langs->trans("UserWillBeExternalUser");
  607. else
  608. $text.=$langs->trans("UserWillBeInternalUser");
  609. }
  610. $ret = $form->form_confirm($_SERVER["PHP_SELF"] . "?id=" . $object->id, $langs->trans("CreateSpeedealingLogin"), $text, "confirm_create_user", $formquestion, 'yes');
  611. if ($ret == 'html')
  612. print '<br>';
  613. }
  614. print '<table class="border" width="100%">';
  615. $linkback = '<a href="' . DOL_URL_ROOT . '/contact/list.php">' . $langs->trans("BackToList") . '</a>';
  616. // Ref
  617. print '<tr><td width="20%">' . $langs->trans("Ref") . '</td><td colspan="3">';
  618. print $form->showrefnav($object, 'id', $linkback);
  619. print '</td></tr>';
  620. // Name
  621. print '<tr><td width="20%">' . $langs->trans("Lastname") . ' / ' . $langs->trans("Label") . '</td><td width="30%">' . $object->lastname . '</td>';
  622. print '<td width="20%">' . $langs->trans("Firstname") . '</td><td width="30%">' . $object->firstname . '</td></tr>';
  623. // Company
  624. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  625. print '<tr><td>' . $langs->trans("Company") . '</td><td colspan="3">';
  626. if (!empty($object->societe->id)) {
  627. print $object->print_fk_extrafields("societe");
  628. } else {
  629. print $langs->trans("ContactNotLinkedToCompany");
  630. }
  631. print '</td></tr>';
  632. }
  633. // Civility
  634. print '<tr><td width="15%">' . $langs->trans("UserTitle") . '</td><td colspan="3">';
  635. print $object->print_fk_extrafields("civilite_id");
  636. print '</td></tr>';
  637. // Role
  638. print '<tr><td>' . $langs->trans("PostOrFunction") . '</td><td colspan="3">' . $object->poste . '</td>';
  639. // Address
  640. print '<tr><td>' . $langs->trans("Address") . '</td><td colspan="3">';
  641. dol_print_address($object->address, 'gmap', 'contact', $object->id);
  642. print '</td></tr>';
  643. // Zip Town
  644. print '<tr><td>' . $langs->trans("Zip") . ' / ' . $langs->trans("Town") . '</td><td colspan="3">';
  645. print $object->zip;
  646. if ($object->zip)
  647. print '&nbsp;';
  648. print $object->town . '</td></tr>';
  649. // Country
  650. print '<tr><td>' . $langs->trans("Country") . '</td><td colspan="3">';
  651. $img = picto_from_langcode($object->country_id);
  652. if ($img)
  653. print $img . ' ';
  654. print $object->print_fk_extrafields("country_id");
  655. print '</td></tr>';
  656. // State
  657. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  658. print '<tr><td>' . $langs->trans('State') . '</td><td colspan="3">' . $object->print_fk_extrafields("state_id") . '</td>';
  659. }
  660. // Phone
  661. print '<tr><td>' . $langs->trans("PhonePro") . '</td><td>' . dol_print_phone($object->phone_pro, $object->country_code, $object->id, $object->societe->id, 'AC_TEL') . '</td>';
  662. print '<td>' . $langs->trans("PhonePerso") . '</td><td>' . dol_print_phone($object->phone_perso, $object->country_code, $object->id, $object->societe->id, 'AC_TEL') . '</td></tr>';
  663. print '<tr><td>' . $langs->trans("PhoneMobile") . '</td><td>' . dol_print_phone($object->phone_mobile, $object->country_code, $object->id, $object->societe->id, 'AC_TEL') . '</td>';
  664. print '<td>' . $langs->trans("Fax") . '</td><td>' . dol_print_phone($object->fax, $object->country_code, $object->id, $object->societe->id, 'AC_FAX') . '</td></tr>';
  665. // Email
  666. print '<tr><td>' . $langs->trans("EMail") . '</td><td>' . dol_print_email($object->email, $object->id, $object->societe->id, 'AC_EMAIL') . '</td>';
  667. if (!empty($conf->mailing->enabled)) {
  668. $langs->load("mails");
  669. print '<td nowrap>' . $langs->trans("NbOfEMailingsReceived") . '</td>';
  670. print '<td><a href="' . DOL_URL_ROOT . '/comm/mailing/liste.php?filteremail=' . urlencode($object->email) . '">' . $object->getNbOfEMailings() . '</a></td>';
  671. } else {
  672. print '<td colspan="2">&nbsp;</td>';
  673. }
  674. print '</tr>';
  675. // Instant message and no email
  676. print '<tr><td>' . $langs->trans("IM") . '</td><td>' . $object->jabberid . '</td>';
  677. if (!empty($conf->mailing->enabled)) {
  678. print '<td>' . $langs->trans("No_Email") . '</td><td>' . yn($object->no_email) . '</td>';
  679. } else {
  680. print '<td colspan="2">&nbsp;</td>';
  681. }
  682. print '</tr>';
  683. // Tag
  684. print '<tr><td>' . $form->editfieldkey("Categories", 'Tag', $object->Tag, $object, $user->rights->societe->creer, "tag") . '</td><td colspan="' . (2 + (($showlogo || $showbarcode) ? 0 : 1)) . '">';
  685. print $form->editfieldval("Categories", 'Tag', $object->Tag, $object, $user->rights->societe->creer, "tag");
  686. print "</td></tr>";
  687. // Other attributes
  688. $parameters = array('socid' => $socid, 'colspan' => ' colspan="3"');
  689. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  690. if (empty($reshook)) {
  691. foreach ($object->fk_extrafields->fields as $key => $aRow) {
  692. if ($aRow->optional && $aRow->enable) {
  693. $value = (isset($_POST["options_" . $key]) ? $_POST["options_" . $key] : (isset($object->array_options["options_" . $key]) ? $object->array_options["options_" . $key] : ''));
  694. print '<tr><td>' . $aRow->label . '</td><td colspan="3">';
  695. print $object->fk_extrafields->showOutputField($key, $value);
  696. print '</td></tr>' . "\n";
  697. }
  698. }
  699. }
  700. $object->load_ref_elements();
  701. if (!empty($conf->commande->enabled)) {
  702. print '<tr><td>' . $langs->trans("ContactForOrders") . '</td><td colspan="3">';
  703. print $object->ref_commande ? $object->ref_commande : $langs->trans("NoContactForAnyOrder");
  704. print '</td></tr>';
  705. }
  706. if (!empty($conf->propal->enabled)) {
  707. print '<tr><td>' . $langs->trans("ContactForProposals") . '</td><td colspan="3">';
  708. print $object->ref_propal ? $object->ref_propal : $langs->trans("NoContactForAnyProposal");
  709. print '</td></tr>';
  710. }
  711. if (!empty($conf->contrat->enabled)) {
  712. print '<tr><td>' . $langs->trans("ContactForContracts") . '</td><td colspan="3">';
  713. print $object->ref_contrat ? $object->ref_contrat : $langs->trans("NoContactForAnyContract");
  714. print '</td></tr>';
  715. }
  716. if (!empty($conf->facture->enabled)) {
  717. print '<tr><td>' . $langs->trans("ContactForInvoices") . '</td><td colspan="3">';
  718. print $object->ref_facturation ? $object->ref_facturation : $langs->trans("NoContactForAnyInvoice");
  719. print '</td></tr>';
  720. }
  721. print '<tr><td>' . $langs->trans("SpeedealingLogin") . '</td><td colspan="3">';
  722. if ($object->user_id) {
  723. $dolibarr_user = new User($db);
  724. $result = $dolibarr_user->fetch($object->user_id);
  725. print $dolibarr_user->getLoginUrl(1);
  726. }
  727. else
  728. print $langs->trans("NoSpeedealingAccess");
  729. print '</td></tr>';
  730. print "</table>";
  731. print "</div>";
  732. // Barre d'actions
  733. if (!$user->societe_id) {
  734. print '<div class="tabsAction">';
  735. if ($user->rights->societe->contact->creer) {
  736. print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=edit">' . $langs->trans('Modify') . '</a>';
  737. }
  738. if (!$object->user_id && $user->rights->user->user->creer) {
  739. print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=create_user">' . $langs->trans("CreateSpeedealingLogin") . '</a>';
  740. }
  741. if ($user->rights->societe->contact->supprimer) {
  742. print '<a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;action=delete">' . $langs->trans('Delete') . '</a>';
  743. }
  744. print "</div>";
  745. }
  746. print column_end();
  747. print column_start("six");
  748. print $object->show_notes(true);
  749. print column_end();
  750. $agenda = new Agenda($db);
  751. print column_start("six");
  752. print $agenda->show($object->id, 25);
  753. print column_end();
  754. }
  755. }
  756. print '</div></div>';
  757. llxFooter();
  758. ?>