PageRenderTime 58ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/contact/fiche.php

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