card.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. <?php
  2. /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 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. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  8. * Copyright (C) 2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  9. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  10. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/contact/card.php
  27. * \ingroup societe
  28. * \brief Card of a contact
  29. */
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  39. require_once DOL_DOCUMENT_ROOT. '/core/class/html.form.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  41. require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
  42. $langs->load("companies");
  43. $langs->load("users");
  44. $langs->load("other");
  45. $langs->load("commercial");
  46. $mesg=''; $error=0; $errors=array();
  47. $action = (GETPOST('action','alpha') ? GETPOST('action','alpha') : 'view');
  48. $confirm = GETPOST('confirm','alpha');
  49. $backtopage = GETPOST('backtopage','alpha');
  50. $id = GETPOST('id','int');
  51. $socid = GETPOST('socid','int');
  52. if ($user->societe_id) $socid=$user->societe_id;
  53. $object = new Contact($db);
  54. $extrafields = new ExtraFields($db);
  55. // fetch optionals attributes and labels
  56. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  57. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  58. $object->getCanvas($id);
  59. $objcanvas=null;
  60. $canvas = (! empty($object->canvas)?$object->canvas:GETPOST("canvas"));
  61. if (! empty($canvas))
  62. {
  63. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  64. $objcanvas = new Canvas($db, $action);
  65. $objcanvas->getCanvas('contact', 'contactcard', $canvas);
  66. }
  67. // Security check
  68. $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', $objcanvas); // If we create a contact with no company (shared contacts), no check on write permission
  69. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  70. $hookmanager->initHooks(array('contactcard','globalcard'));
  71. /*
  72. * Actions
  73. */
  74. $parameters=array('id'=>$id, 'objcanvas'=>$objcanvas);
  75. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  76. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  77. if (empty($reshook))
  78. {
  79. // Cancel
  80. if (GETPOST("cancel") && ! empty($backtopage))
  81. {
  82. header("Location: ".$backtopage);
  83. exit;
  84. }
  85. // Creation utilisateur depuis contact
  86. if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer)
  87. {
  88. // Recuperation contact actuel
  89. $result = $object->fetch($id);
  90. if ($result > 0)
  91. {
  92. $db->begin();
  93. // Creation user
  94. $nuser = new User($db);
  95. $result=$nuser->create_from_contact($object,GETPOST("login")); // Do not use GETPOST(alpha)
  96. if ($result > 0)
  97. {
  98. $result2=$nuser->setPassword($user,GETPOST("password"),0,0,1); // Do not use GETPOST(alpha)
  99. if ($result2)
  100. {
  101. $db->commit();
  102. }
  103. else
  104. {
  105. $error=$nuser->error; $errors=$nuser->errors;
  106. $db->rollback();
  107. }
  108. }
  109. else
  110. {
  111. $error=$nuser->error; $errors=$nuser->errors;
  112. $db->rollback();
  113. }
  114. }
  115. else
  116. {
  117. $error=$object->error; $errors=$object->errors;
  118. }
  119. }
  120. // Confirmation desactivation
  121. if ($action == 'disable')
  122. {
  123. $object->fetch($id);
  124. if ($object->setstatus(0)<0)
  125. {
  126. setEventMessage($object->error,'errors');
  127. }
  128. else
  129. {
  130. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  131. exit;
  132. }
  133. }
  134. // Confirmation activation
  135. if ($action == 'enable')
  136. {
  137. $object->fetch($id);
  138. if ($object->setstatus(1)<0)
  139. {
  140. setEventMessage($object->error,'errors');
  141. }
  142. else
  143. {
  144. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  145. exit;
  146. }
  147. }
  148. // Add contact
  149. if ($action == 'add' && $user->rights->societe->contact->creer)
  150. {
  151. $db->begin();
  152. if ($canvas) $object->canvas=$canvas;
  153. $object->socid = GETPOST("socid",'int');
  154. $object->lastname = GETPOST("lastname");
  155. $object->firstname = GETPOST("firstname");
  156. $object->civility_id = GETPOST("civility_id",'alpha');
  157. $object->poste = GETPOST("poste");
  158. $object->address = GETPOST("address");
  159. $object->zip = GETPOST("zipcode");
  160. $object->town = GETPOST("town");
  161. $object->country_id = GETPOST("country_id",'int');
  162. $object->state_id = GETPOST("state_id",'int');
  163. $object->skype = GETPOST("skype");
  164. $object->email = GETPOST("email",'alpha');
  165. $object->phone_pro = GETPOST("phone_pro");
  166. $object->phone_perso = GETPOST("phone_perso");
  167. $object->phone_mobile = GETPOST("phone_mobile");
  168. $object->fax = GETPOST("fax");
  169. $object->jabberid = GETPOST("jabberid",'alpha');
  170. $object->no_email = GETPOST("no_email",'int');
  171. $object->priv = GETPOST("priv",'int');
  172. $object->note_public = GETPOST("note_public");
  173. $object->note_private = GETPOST("note_private");
  174. $object->statut = 1; //Defult status to Actif
  175. // Note: Correct date should be completed with location to have exact GM time of birth.
  176. $object->birthday = dol_mktime(0,0,0,GETPOST("birthdaymonth",'int'),GETPOST("birthdayday",'int'),GETPOST("birthdayyear",'int'));
  177. $object->birthday_alert = GETPOST("birthday_alert",'alpha');
  178. // Fill array 'array_options' with data from add form
  179. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  180. if ($ret < 0)
  181. {
  182. $error++;
  183. $action = 'create';
  184. }
  185. if (! GETPOST("lastname"))
  186. {
  187. $error++; $errors[]=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
  188. $action = 'create';
  189. }
  190. if (! $error)
  191. {
  192. $id = $object->create($user);
  193. if ($id <= 0)
  194. {
  195. $error++; $errors=array_merge($errors,($object->error?array($object->error):$object->errors));
  196. $action = 'create';
  197. } else {
  198. // Categories association
  199. $contcats = GETPOST( 'contcats', 'array' );
  200. if (!empty( $contcats )) {
  201. $cat = new Categorie( $db );
  202. foreach ($contcats as $id_category) {
  203. $cat->fetch( $id_category );
  204. $cat->add_type( $object, 'contact' );
  205. }
  206. }
  207. }
  208. }
  209. if (! $error && $id > 0)
  210. {
  211. $db->commit();
  212. if (! empty($backtopage)) $url=$backtopage;
  213. else $url='card.php?id='.$id;
  214. header("Location: ".$url);
  215. exit;
  216. }
  217. else
  218. {
  219. $db->rollback();
  220. }
  221. }
  222. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->contact->supprimer)
  223. {
  224. $result=$object->fetch($id);
  225. $object->old_lastname = GETPOST("old_lastname");
  226. $object->old_firstname = GETPOST("old_firstname");
  227. $result = $object->delete();
  228. if ($result > 0)
  229. {
  230. if ($backtopage)
  231. {
  232. header("Location: ".$backtopage);
  233. exit;
  234. }
  235. else
  236. {
  237. header("Location: ".DOL_URL_ROOT.'/contact/list.php');
  238. exit;
  239. }
  240. }
  241. else
  242. {
  243. setEventMessages($object->error,$object->errors,'errors');
  244. }
  245. }
  246. if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
  247. {
  248. if (empty($_POST["lastname"]))
  249. {
  250. $error++; $errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
  251. $action = 'edit';
  252. }
  253. if (! $error)
  254. {
  255. $contactid=GETPOST("contactid",'int');
  256. $object->fetch($contactid);
  257. $object->oldcopy=dol_clone($object);
  258. $object->old_lastname = GETPOST("old_lastname");
  259. $object->old_firstname = GETPOST("old_firstname");
  260. $object->socid = GETPOST("socid",'int');
  261. $object->lastname = GETPOST("lastname");
  262. $object->firstname = GETPOST("firstname");
  263. $object->civility_id = GETPOST("civility_id",'alpha');
  264. $object->poste = GETPOST("poste");
  265. $object->address = GETPOST("address");
  266. $object->zip = GETPOST("zipcode");
  267. $object->town = GETPOST("town");
  268. $object->state_id = GETPOST("state_id",'int');
  269. $object->country_id = GETPOST("country_id",'int');
  270. $object->email = GETPOST("email",'alpha');
  271. $object->skype = GETPOST("skype",'alpha');
  272. $object->phone_pro = GETPOST("phone_pro");
  273. $object->phone_perso = GETPOST("phone_perso");
  274. $object->phone_mobile = GETPOST("phone_mobile");
  275. $object->fax = GETPOST("fax");
  276. $object->jabberid = GETPOST("jabberid",'alpha');
  277. $object->no_email = GETPOST("no_email",'int');
  278. $object->priv = GETPOST("priv",'int');
  279. $object->note_public = GETPOST("note_public");
  280. $object->note_private = GETPOST("note_private");
  281. // Fill array 'array_options' with data from add form
  282. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  283. if ($ret < 0) $error++;
  284. $result = $object->update($contactid, $user);
  285. if ($result > 0) {
  286. // Categories association
  287. // First we delete all categories association
  288. $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'categorie_contact';
  289. $sql .= ' WHERE fk_socpeople = ' . $object->id;
  290. $db->query( $sql );
  291. // Then we add the associated categories
  292. $categories = GETPOST( 'contcats', 'array' );
  293. if (!empty( $categories )) {
  294. $cat = new Categorie( $db );
  295. foreach ($categories as $id_category) {
  296. $cat->fetch( $id_category );
  297. $cat->add_type( $object, 'contact' );
  298. }
  299. }
  300. $object->old_lastname='';
  301. $object->old_firstname='';
  302. $action = 'view';
  303. }
  304. else
  305. {
  306. setEventMessage($object->error,'errors');
  307. setEventMessage($object->errors,'errors');
  308. $action = 'edit';
  309. }
  310. }
  311. }
  312. }
  313. /*
  314. * View
  315. */
  316. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  317. llxHeader('',$langs->trans("ContactsAddresses"),$help_url);
  318. $form = new Form($db);
  319. $formcompany = new FormCompany($db);
  320. $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  321. if ($socid > 0)
  322. {
  323. $objsoc = new Societe($db);
  324. $objsoc->fetch($socid);
  325. }
  326. if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
  327. {
  328. // -----------------------------------------
  329. // When used with CANVAS
  330. // -----------------------------------------
  331. if (empty($object->error) && $id)
  332. {
  333. $object = new Contact($db);
  334. $result=$object->fetch($id);
  335. if ($result <= 0) dol_print_error('',$object->error);
  336. }
  337. $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
  338. $objcanvas->display_canvas($action); // Show template
  339. }
  340. else
  341. {
  342. // -----------------------------------------
  343. // When used in standard mode
  344. // -----------------------------------------
  345. // Confirm deleting contact
  346. if ($user->rights->societe->contact->supprimer)
  347. {
  348. if ($action == 'delete')
  349. {
  350. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage?'&backtopage='.$backtopage:''),$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1);
  351. }
  352. }
  353. /*
  354. * Onglets
  355. */
  356. $head=array();
  357. if ($id > 0)
  358. {
  359. // Si edition contact deja existant
  360. $object = new Contact($db);
  361. $res=$object->fetch($id, $user);
  362. if ($res < 0) { dol_print_error($db,$object->error); exit; }
  363. $res=$object->fetch_optionals($object->id,$extralabels);
  364. // Show tabs
  365. $head = contact_prepare_head($object);
  366. $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  367. }
  368. if ($user->rights->societe->contact->creer)
  369. {
  370. if ($action == 'create')
  371. {
  372. /*
  373. * Fiche en mode creation
  374. */
  375. $object->canvas=$canvas;
  376. $object->state_id = $_POST["state_id"];
  377. // We set country_id, country_code and label for the selected country
  378. $object->country_id=$_POST["country_id"]?$_POST["country_id"]:(empty($objsoc->country_id)?$mysoc->country_id:$objsoc->country_id);
  379. if ($object->country_id)
  380. {
  381. $tmparray=getCountry($object->country_id,'all');
  382. $object->country_code = $tmparray['code'];
  383. $object->country = $tmparray['label'];
  384. }
  385. $title = $addcontact = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
  386. $linkback='';
  387. print_fiche_titre($title,$linkback,'title_companies.png');
  388. // Affiche les erreurs
  389. dol_htmloutput_errors(is_numeric($error)?'':$error,$errors);
  390. if ($conf->use_javascript_ajax)
  391. {
  392. print "\n".'<script type="text/javascript" language="javascript">'."\n";
  393. print 'jQuery(document).ready(function () {
  394. jQuery("#selectcountry_id").change(function() {
  395. document.formsoc.action.value="create";
  396. document.formsoc.submit();
  397. });
  398. $("#copyaddressfromsoc").click(function() {
  399. $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
  400. $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
  401. $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
  402. $(\'select[name="country_id"]\').val("'.dol_escape_js($objsoc->country_id).'");
  403. $(\'select[name="state_id"]\').val("'.dol_escape_js($objsoc->state_id).'");
  404. $(\'input[name="email"]\').val("'.dol_escape_js($objsoc->email).'");
  405. });
  406. })'."\n";
  407. print '</script>'."\n";
  408. }
  409. print '<form method="post" name="formsoc" action="'.$_SERVER["PHP_SELF"].'">';
  410. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  411. print '<input type="hidden" name="action" value="add">';
  412. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  413. dol_fiche_head($head, 'card', '', 0, '');
  414. print '<table class="border" width="100%">';
  415. // Name
  416. print '<tr><td width="20%" class="fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
  417. print '<td width="30%"><input name="lastname" id="lastname" type="text" size="30" maxlength="80" value="'.dol_escape_htmltag(GETPOST("lastname")?GETPOST("lastname"):$object->lastname).'" autofocus="autofocus"></td>';
  418. print '<td width="20%"><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
  419. print '<td width="30%"><input name="firstname" id="firstname"type="text" size="30" maxlength="80" value="'.dol_escape_htmltag(GETPOST("firstname")?GETPOST("firstname"):$object->firstname).'"></td></tr>';
  420. // Company
  421. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  422. {
  423. if ($socid > 0)
  424. {
  425. print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
  426. print '<td colspan="3" class="maxwidthonsmartphone">';
  427. print $objsoc->getNomUrl(1);
  428. print '</td>';
  429. print '<input type="hidden" name="socid" id="socid" value="'.$objsoc->id.'">';
  430. print '</td></tr>';
  431. }
  432. else {
  433. print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  434. print $form->select_company($socid,'socid','',1);
  435. print '</td></tr>';
  436. }
  437. }
  438. // Civility
  439. print '<tr><td width="15%"><label for="civility_id">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
  440. print $formcompany->select_civility(GETPOST("civility_id",'alpha')?GETPOST("civility_id",'alpha'):$object->civility_id);
  441. print '</td></tr>';
  442. print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
  443. print '<td colspan="3"><input name="poste" id="title" type="text" size="50" maxlength="80" value="'.dol_escape_htmltag(GETPOST("poste",'alpha')?GETPOST("poste",'alpha'):$object->poste).'"></td>';
  444. $colspan=3;
  445. if ($conf->use_javascript_ajax && $socid > 0) $colspan=2;
  446. // Address
  447. 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
  448. print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
  449. print '<td colspan="'.$colspan.'"><textarea class="flat" name="address" id="address" cols="70">'.(GETPOST("address",'alpha')?GETPOST("address",'alpha'):$object->address).'</textarea></td>';
  450. if ($conf->use_javascript_ajax && $socid > 0)
  451. {
  452. $rowspan=3;
  453. if (empty($conf->global->SOCIETE_DISABLE_STATE)) $rowspan++;
  454. print '<td valign="middle" align="center" rowspan="'.$rowspan.'">';
  455. print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a>';
  456. print '</td>';
  457. }
  458. print '</tr>';
  459. // Zip / Town
  460. 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
  461. 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
  462. print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
  463. print $formcompany->select_ziptown((GETPOST("zipcode")?GETPOST("zipcode"):$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6).'&nbsp;';
  464. print $formcompany->select_ziptown((GETPOST("town")?GETPOST("town"):$object->town),'town',array('zipcode','selectcountry_id','state_id'));
  465. print '</td></tr>';
  466. // Country
  467. print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
  468. print $form->select_country((GETPOST("country_id",'alpha')?GETPOST("country_id",'alpha'):$object->country_id),'country_id');
  469. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  470. print '</td></tr>';
  471. // State
  472. if (empty($conf->global->SOCIETE_DISABLE_STATE))
  473. {
  474. print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
  475. if ($object->country_id)
  476. {
  477. print $formcompany->select_state(GETPOST("state_id",'alpha')?GETPOST("state_id",'alpha'):$object->state_id,$object->country_code,'state_id');
  478. }
  479. else
  480. {
  481. print $countrynotdefined;
  482. }
  483. print '</td></tr>';
  484. }
  485. // Phone / Fax
  486. if (($objsoc->typent_code == 'TE_PRIVATE' || ! empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->phone_pro)) == 0) $object->phone_pro = $objsoc->phone; // Predefined with third party
  487. print '<tr><td><label for="phone_pro">'.$langs->trans("PhonePro").'</label></td>';
  488. print '<td><input name="phone_pro" id="phone_pro" type="text" size="18" maxlength="80" value="'.dol_escape_htmltag(GETPOST("phone_pro")?GETPOST("phone_pro"):$object->phone_pro).'"></td>';
  489. print '<td><label for="phone_perso">'.$langs->trans("PhonePerso").'</label></td>';
  490. print '<td><input name="phone_perso" id="phone_perso" type="text" size="18" maxlength="80" value="'.dol_escape_htmltag(GETPOST("phone_perso")?GETPOST("phone_perso"):$object->phone_perso).'"></td></tr>';
  491. 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
  492. print '<tr><td><label for="phone_mobile">'.$langs->trans("PhoneMobile").'</label></td>';
  493. print '<td><input name="phone_mobile" id="phone_mobile" type="text" size="18" maxlength="80" value="'.dol_escape_htmltag(GETPOST("phone_mobile")?GETPOST("phone_mobile"):$object->phone_mobile).'"></td>';
  494. print '<td><label for="fax">'.$langs->trans("Fax").'</label></td>';
  495. print '<td><input name="fax" id="fax" type="text" size="18" maxlength="80" value="'.dol_escape_htmltag(GETPOST("fax",'alpha')?GETPOST("fax",'alpha'):$object->fax).'"></td></tr>';
  496. // EMail
  497. 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
  498. print '<tr><td><label for="email">'.$langs->trans("Email").'</label></td>';
  499. print '<td><input name="email" id="email" type="text" size="50" maxlength="80" value="'.(GETPOST("email",'alpha')?GETPOST("email",'alpha'):$object->email).'"></td>';
  500. if (! empty($conf->mailing->enabled))
  501. {
  502. print '<td><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
  503. print '<td>'.$form->selectyesno('no_email',(GETPOST("no_email",'alpha')?GETPOST("no_email",'alpha'):$object->no_email), 1).'</td>';
  504. }
  505. else
  506. {
  507. print '<td colspan="2">&nbsp;</td>';
  508. }
  509. print '</tr>';
  510. // Instant message and no email
  511. print '<tr><td><label for="jabberid">'.$langs->trans("IM").'</label></td>';
  512. print '<td colspan="3"><input name="jabberid" id="jabberid" type="text" size="50" maxlength="80" value="'.(GETPOST("jabberid",'alpha')?GETPOST("jabberid",'alpha'):$object->jabberid).'"></td></tr>';
  513. // Skype
  514. if (! empty($conf->skype->enabled))
  515. {
  516. print '<tr><td><label for="skype">'.$langs->trans("Skype").'</label></td>';
  517. print '<td colspan="3"><input name="skype" id="skype" type="text" size="50" maxlength="80" value="'.(GETPOST("skype",'alpha')?GETPOST("skype",'alpha'):$object->skype).'"></td></tr>';
  518. }
  519. // Visibility
  520. print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
  521. $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
  522. print $form->selectarray('priv',$selectarray,(GETPOST("priv",'alpha')?GETPOST("priv",'alpha'):$object->priv),0);
  523. print '</td></tr>';
  524. // Categories
  525. if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) {
  526. print '<tr><td>' . fieldLabel( 'Categories', 'contcats' ) . '</td><td colspan="3">';
  527. $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, 'parent', null, null, 1 );
  528. print $form->multiselectarray( 'contcats', $cate_arbo, GETPOST( 'contcats', 'array' ), null, null, null,
  529. null, '90%' );
  530. print "</td></tr>";
  531. }
  532. // Other attributes
  533. $parameters=array('colspan' => ' colspan="3"');
  534. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  535. if (empty($reshook) && ! empty($extrafields->attribute_label))
  536. {
  537. print $object->showOptionals($extrafields,'edit');
  538. }
  539. print "</table><br>";
  540. // Add personnal information
  541. print_fiche_titre('<div class="comboperso">'.$langs->trans("PersonalInformations").'</div>','','');
  542. print '<table class="border" width="100%">';
  543. // Date To Birth
  544. print '<tr><td width="20%"><label for="birthday">'.$langs->trans("DateToBirth").'</label></td><td width="30%">';
  545. $form=new Form($db);
  546. if ($object->birthday)
  547. {
  548. print $form->select_date($object->birthday,'birthday',0,0,0,"perso", 1, 0, 1);
  549. }
  550. else
  551. {
  552. print $form->select_date('','birthday',0,0,1,"perso", 1, 0, 1);
  553. }
  554. print '</td>';
  555. print '<td colspan="2"><label for="birthday_alert">'.$langs->trans("Alert").'</label>: ';
  556. if ($object->birthday_alert)
  557. {
  558. print '<input type="checkbox" name="birthday_alert" id="birthday_aler" checked></td>';
  559. }
  560. else
  561. {
  562. print '<input type="checkbox" name="birthday_alert" id="birthday_alert"></td>';
  563. }
  564. print '</tr>';
  565. print "</table>";
  566. print dol_fiche_end();
  567. print '<div class="center">';
  568. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  569. if (! empty($backtopage))
  570. {
  571. print ' &nbsp; &nbsp; ';
  572. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  573. }
  574. print '</div>';
  575. print "</form>";
  576. }
  577. elseif ($action == 'edit' && ! empty($id))
  578. {
  579. /*
  580. * Fiche en mode edition
  581. */
  582. // We set country_id, and country_code label of the chosen country
  583. if (isset($_POST["country_id"]) || $object->country_id)
  584. {
  585. $tmparray=getCountry($object->country_id,'all');
  586. $object->country_code = $tmparray['code'];
  587. $object->country = $tmparray['label'];
  588. }
  589. $objsoc = new Societe($db);
  590. $objsoc->fetch($object->socid);
  591. // Affiche les erreurs
  592. dol_htmloutput_errors($error,$errors);
  593. if ($conf->use_javascript_ajax)
  594. {
  595. print "\n".'<script type="text/javascript" language="javascript">'."\n";
  596. print 'jQuery(document).ready(function () {
  597. jQuery("#selectcountry_id").change(function() {
  598. document.formsoc.action.value="edit";
  599. document.formsoc.submit();
  600. });
  601. $("#copyaddressfromsoc").click(function() {
  602. $(\'textarea[name="address"]\').text("'.dol_escape_js($objsoc->address).'");
  603. $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
  604. $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
  605. $(\'select[name="country_id"]\').val("'.dol_escape_js($objsoc->country_id).'");
  606. $(\'select[name="state_id"]\').val("'.dol_escape_js($objsoc->state_id).'");
  607. });
  608. })'."\n";
  609. print '</script>'."\n";
  610. }
  611. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" name="formsoc">';
  612. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  613. print '<input type="hidden" name="id" value="'.$id.'">';
  614. print '<input type="hidden" name="action" value="update">';
  615. print '<input type="hidden" name="contactid" value="'.$object->id.'">';
  616. print '<input type="hidden" name="old_lastname" value="'.$object->lastname.'">';
  617. print '<input type="hidden" name="old_firstname" value="'.$object->firstname.'">';
  618. if (! empty($backtopage)) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  619. dol_fiche_head($head, 'card', $title, 0, 'contact');
  620. print '<table class="border" width="100%">';
  621. // Ref
  622. print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="3">';
  623. print $object->ref;
  624. print '</td></tr>';
  625. // Lastname
  626. print '<tr><td width="20%" class="fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
  627. print '<td width="30%"><input name="lastname" id="lastname" type="text" size="20" maxlength="80" value="'.(isset($_POST["lastname"])?$_POST["lastname"]:$object->lastname).'" autofocus="autofocus"></td>';
  628. print '<td width="20%"><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
  629. print '<td width="30%"><input name="firstname" id="firstname" type="text" size="20" maxlength="80" value="'.(isset($_POST["firstname"])?$_POST["firstname"]:$object->firstname).'"></td></tr>';
  630. // Company
  631. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  632. {
  633. print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
  634. print '<td colspan="3" class="maxwidthonsmartphone">';
  635. print $form->select_company(GETPOST('socid','int')?GETPOST('socid','int'):($object->socid?$object->socid:-1),'socid','',1);
  636. print '</td>';
  637. print '</tr>';
  638. }
  639. // Civility
  640. print '<tr><td><label for="civility_id">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
  641. print $formcompany->select_civility(isset($_POST["civility_id"])?$_POST["civility_id"]:$object->civility_id);
  642. print '</td></tr>';
  643. print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
  644. print '<td colspan="3"><input name="poste" id="title" type="text" size="50" maxlength="80" value="'.(isset($_POST["poste"])?$_POST["poste"]:$object->poste).'"></td></tr>';
  645. // Address
  646. print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
  647. print '<td colspan="2"><textarea class="flat" name="address" id="address" cols="70">'.(isset($_POST["address"])?$_POST["address"]:$object->address).'</textarea></td>';
  648. $rowspan=3;
  649. if (empty($conf->global->SOCIETE_DISABLE_STATE)) $rowspan++;
  650. print '<td valign="middle" align="center" rowspan="'.$rowspan.'">';
  651. if ($conf->use_javascript_ajax) print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a>';
  652. print '</td></tr>';
  653. // Zip / Town
  654. print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="2" class="maxwidthonsmartphone">';
  655. print $formcompany->select_ziptown((isset($_POST["zipcode"])?$_POST["zipcode"]:$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6).'&nbsp;';
  656. print $formcompany->select_ziptown((isset($_POST["town"])?$_POST["town"]:$object->town),'town',array('zipcode','selectcountry_id','state_id'));
  657. print '</td></tr>';
  658. // Country
  659. print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="2" class="maxwidthonsmartphone">';
  660. print $form->select_country(isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id,'country_id');
  661. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  662. print '</td></tr>';
  663. // State
  664. if (empty($conf->global->SOCIETE_DISABLE_STATE))
  665. {
  666. print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="2" class="maxwidthonsmartphone">';
  667. print $formcompany->select_state($object->state_id,isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id,'state_id');
  668. print '</td></tr>';
  669. }
  670. // Phone
  671. print '<tr><td><label for="phone_pro">'.$langs->trans("PhonePro").'</label></td>';
  672. print '<td><input name="phone_pro" id="phone_pro" type="text" size="18" maxlength="80" value="'.(isset($_POST["phone_pro"])?$_POST["phone_pro"]:$object->phone_pro).'"></td>';
  673. print '<td><label for="phone_perso">'.$langs->trans("PhonePerso").'</label></td>';
  674. print '<td><input name="phone_perso" id="phone_perso" type="text" size="18" maxlength="80" value="'.(isset($_POST["phone_perso"])?$_POST["phone_perso"]:$object->phone_perso).'"></td></tr>';
  675. print '<tr><td><label for="phone_mobile">'.$langs->trans("PhoneMobile").'</label></td>';
  676. print '<td><input name="phone_mobile" id="phone_mobile" type="text" size="18" maxlength="80" value="'.(isset($_POST["phone_mobile"])?$_POST["phone_mobile"]:$object->phone_mobile).'"></td>';
  677. print '<td><label for="fax">'.$langs->trans("Fax").'</label></td>';
  678. print '<td><input name="fax" id="fax" type="text" size="18" maxlength="80" value="'.(isset($_POST["fax"])?$_POST["fax"]:$object->fax).'"></td></tr>';
  679. // EMail
  680. print '<tr><td><label for="email">'.$langs->trans("EMail").'</label></td>';
  681. print '<td><input name="email" id="email" type="text" size="40" maxlength="80" value="'.(isset($_POST["email"])?$_POST["email"]:$object->email).'"></td>';
  682. if (! empty($conf->mailing->enabled))
  683. {
  684. $langs->load("mails");
  685. print '<td class="nowrap">'.$langs->trans("NbOfEMailingsSend").'</td>';
  686. print '<td>'.$object->getNbOfEMailings().'</td>';
  687. }
  688. else
  689. {
  690. print '<td colspan="2">&nbsp;</td>';
  691. }
  692. print '</tr>';
  693. // Jabberid
  694. print '<tr><td><label for="jabberid">'.$langs->trans("IM").'</label></td>';
  695. print '<td><input name="jabberid" id="jabberid" type="text" size="40" maxlength="80" value="'.(isset($_POST["jabberid"])?$_POST["jabberid"]:$object->jabberid).'"></td>';
  696. if (! empty($conf->mailing->enabled))
  697. {
  698. print '<td><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
  699. print '<td>'.$form->selectyesno('no_email',(isset($_POST["no_email"])?$_POST["no_email"]:$object->no_email), 1).'</td>';
  700. }
  701. else
  702. {
  703. print '<td colspan="2">&nbsp;</td>';
  704. }
  705. print '</tr>';
  706. // Skype
  707. if (! empty($conf->skype->enabled))
  708. {
  709. print '<tr><td><label for="skype">'.$langs->trans("Skype").'</label></td>';
  710. print '<td><input name="skype" id="skype" type="text" size="40" maxlength="80" value="'.(isset($_POST["skype"])?$_POST["skype"]:$object->skype).'"></td></tr>';
  711. }
  712. // Visibility
  713. print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
  714. $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
  715. print $form->selectarray('priv',$selectarray,$object->priv,0);
  716. print '</td></tr>';
  717. // Note Public
  718. print '<tr><td class="tdtop"><label for="note_public">'.$langs->trans("NotePublic").'</label></td><td colspan="3">';
  719. $doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  720. print $doleditor->Create(1);
  721. print '</td></tr>';
  722. // Note Private
  723. print '<tr><td class="tdtop"><label for="note_private">'.$langs->trans("NotePrivate").'</label></td><td colspan="3">';
  724. $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  725. print $doleditor->Create(1);
  726. print '</td></tr>';
  727. // Statut
  728. print '<tr><td>'.$langs->trans("Status").'</td>';
  729. print '<td>';
  730. print $object->getLibStatut(4);
  731. print '</td></tr>';
  732. // Categories
  733. if (!empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire )) {
  734. print '<tr><td>' . fieldLabel( 'Categories', 'contcats' ) . '</td>';
  735. print '<td colspan="3">';
  736. $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, null, null, null, 1 );
  737. $c = new Categorie( $db );
  738. $cats = $c->containing( $object->id, Categorie::TYPE_CONTACT );
  739. foreach ($cats as $cat) {
  740. $arrayselected[] = $cat->id;
  741. }
  742. print $form->multiselectarray( 'contcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%' );
  743. print "</td></tr>";
  744. }
  745. // Other attributes
  746. $parameters=array('colspan' => ' colspan="3"');
  747. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  748. if (empty($reshook) && ! empty($extrafields->attribute_label))
  749. {
  750. print $object->showOptionals($extrafields,'edit');
  751. }
  752. $object->load_ref_elements();
  753. if (! empty($conf->commande->enabled))
  754. {
  755. print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
  756. print $object->ref_commande?$object->ref_commande:$langs->trans("NoContactForAnyOrder");
  757. print '</td></tr>';
  758. }
  759. if (! empty($conf->propal->enabled))
  760. {
  761. print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
  762. print $object->ref_propal?$object->ref_propal:$langs->trans("NoContactForAnyProposal");
  763. print '</td></tr>';
  764. }
  765. if (! empty($conf->contrat->enabled))
  766. {
  767. print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
  768. print $object->ref_contrat?$object->ref_contrat:$langs->trans("NoContactForAnyContract");
  769. print '</td></tr>';
  770. }
  771. if (! empty($conf->facture->enabled))
  772. {
  773. print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
  774. print $object->ref_facturation?$object->ref_facturation:$langs->trans("NoContactForAnyInvoice");
  775. print '</td></tr>';
  776. }
  777. // Login Dolibarr
  778. print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
  779. if ($object->user_id)
  780. {
  781. $dolibarr_user=new User($db);
  782. $result=$dolibarr_user->fetch($object->user_id);
  783. print $dolibarr_user->getLoginUrl(1);
  784. }
  785. else print $langs->trans("NoDolibarrAccess");
  786. print '</td></tr>';
  787. print '</table>';
  788. print dol_fiche_end();
  789. print '<div class="center">';
  790. print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  791. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  792. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  793. print '</div>';
  794. print "</form>";
  795. }
  796. }
  797. if (! empty($id) && $action != 'edit' && $action != 'create')
  798. {
  799. $objsoc = new Societe($db);
  800. /*
  801. * Fiche en mode visualisation
  802. */
  803. dol_htmloutput_errors($error,$errors);
  804. dol_fiche_head($head, 'card', $title, 0, 'contact');
  805. if ($action == 'create_user')
  806. {
  807. // Full firstname and lastname separated with a dot : firstname.lastname
  808. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  809. $login=dol_buildlogin($object->lastname,$object->firstname);
  810. $generated_password='';
  811. if (! $ldap_sid) // TODO ldap_sid ?
  812. {
  813. require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  814. $generated_password=getRandomPassword(false);
  815. }
  816. $password=$generated_password;
  817. // Create a form array
  818. $formquestion=array(
  819. array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
  820. array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password),
  821. //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')))
  822. );
  823. $text=$langs->trans("ConfirmCreateContact").'<br>';
  824. if (! empty($conf->societe->enabled))
  825. {
  826. if ($object->socid > 0) $text.=$langs->trans("UserWillBeExternalUser");
  827. else $text.=$langs->trans("UserWillBeInternalUser");
  828. }
  829. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("CreateDolibarrLogin"),$text,"confirm_create_user",$formquestion,'yes');
  830. }
  831. print '<table class="border" width="100%">';
  832. $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';
  833. // Ref
  834. print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
  835. print $form->showrefnav($object, 'id', $linkback);
  836. print '</td></tr>';
  837. // Name
  838. print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
  839. print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td></tr>';
  840. // Company
  841. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  842. {
  843. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td colspan="3">';
  844. if ($object->socid > 0)
  845. {
  846. $objsoc->fetch($object->socid);
  847. print $objsoc->getNomUrl(1);
  848. }
  849. else
  850. {
  851. print $langs->trans("ContactNotLinkedToCompany");
  852. }
  853. print '</td></tr>';
  854. }
  855. // Civility
  856. print '<tr><td width="15%">'.$langs->trans("UserTitle").'</td><td colspan="3">';
  857. print $object->getCivilityLabel();
  858. print '</td></tr>';
  859. // Role
  860. print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td colspan="3">'.$object->poste.'</td>';
  861. // Address
  862. print '<tr><td>'.$langs->trans("Address").'</td><td colspan="3">';
  863. dol_print_address($object->address,'gmap','contact',$object->id);
  864. print '</td></tr>';
  865. // Zip/Town
  866. print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td colspan="3">';
  867. print $object->zip;
  868. if ($object->zip) print '&nbsp;';
  869. print $object->town.'</td></tr>';
  870. // Country
  871. print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
  872. $img=picto_from_langcode($object->country_code);
  873. if ($img) print $img.' ';
  874. print $object->country;
  875. print '</td></tr>';
  876. // State
  877. if (empty($conf->global->SOCIETE_DISABLE_STATE))
  878. {
  879. print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">'.$object->state.'</td>';
  880. }
  881. // Phone
  882. print '<tr><td>'.$langs->trans("PhonePro").'</td><td>'.dol_print_phone($object->phone_pro,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td>';
  883. print '<td>'.$langs->trans("PhonePerso").'</td><td>'.dol_print_phone($object->phone_perso,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td></tr>';
  884. print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td>'.dol_print_phone($object->phone_mobile,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td>';
  885. print '<td>'.$langs->trans("Fax").'</td><td>'.dol_print_phone($object->fax,$object->country_code,$object->id,$object->socid,'AC_FAX').'</td></tr>';
  886. // Email
  887. print '<tr><td>'.$langs->trans("EMail").'</td><td>'.dol_print_email($object->email,$object->id,$object->socid,'AC_EMAIL').'</td>';
  888. if (! empty($conf->mailing->enabled))
  889. {
  890. $langs->load("mails");
  891. print '<td class="nowrap">'.$langs->trans("NbOfEMailingsSend").'</td>';
  892. print '<td><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td>';
  893. }
  894. else
  895. {
  896. print '<td colspan="2">&nbsp;</td>';
  897. }
  898. print '</tr>';
  899. // Instant message and no email
  900. print '<tr><td>'.$langs->trans("IM").'</td><td>'.$object->jabberid.'</td>';
  901. if (!empty($conf->mailing->enabled))
  902. {
  903. print '<td>'.$langs->trans("No_Email").'</td><td>'.yn($object->no_email).'</td>';
  904. }
  905. else
  906. {
  907. print '<td colspan="2">&nbsp;</td>';
  908. }
  909. print '</tr>';
  910. // Skype
  911. if (! empty($conf->skype->enabled))
  912. {
  913. print '<tr><td>'.$langs->trans("Skype").'</td><td colspan="3">'.dol_print_skype($object->skype,0,$object->fk_soc,1).'</td></tr>';
  914. }
  915. print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td colspan="3">';
  916. print $object->LibPubPriv($object->priv);
  917. print '</td></tr>';
  918. // Note Public
  919. print '<tr><td class="tdtop">'.$langs->trans("NotePublic").'</td><td colspan="3">';
  920. print nl2br($object->note_public);
  921. print '</td></tr>';
  922. // Note Private
  923. print '<tr><td class="tdtop">'.$langs->trans("NotePrivate").'</td><td colspan="3">';
  924. print nl2br($object->note_private);
  925. // Statut
  926. print '<tr><td>'.$langs->trans("Status").'</td>';
  927. print '<td>';
  928. print $object->getLibStatut(4);
  929. print '</td>';
  930. print '</tr>'."\n";
  931. // Categories
  932. if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) {
  933. print '<tr><td>' . $langs->trans( "Categories" ) . '</td>';
  934. print '<td colspan="3">';
  935. print $form->showCategories( $object->id, 'contact', 1 );
  936. print '</td></tr>';
  937. }
  938. // Other attributes
  939. $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"');
  940. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  941. print $hookmanager->resPrint;
  942. if (empty($reshook) && ! empty($extrafields->attribute_label))
  943. {
  944. print $object->showOptionals($extrafields);
  945. }
  946. $object->load_ref_elements();
  947. if (! empty($conf->commande->enabled))
  948. {
  949. print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
  950. print $object->ref_commande?$object->ref_commande:$langs->trans("NoContactForAnyOrder");
  951. print '</td></tr>';
  952. }
  953. if (! empty($conf->propal->enabled))
  954. {
  955. print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
  956. print $object->ref_propal?$object->ref_propal:$langs->trans("NoContactForAnyProposal");
  957. print '</td></tr>';
  958. }
  959. if (! empty($conf->contrat->enabled))
  960. {
  961. print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
  962. print $object->ref_contrat?$object->ref_contrat:$langs->trans("NoContactForAnyContract");
  963. print '</td></tr>';
  964. }
  965. if (! empty($conf->facture->enabled))
  966. {
  967. print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
  968. print $object->ref_facturation?$object->ref_facturation:$langs->trans("NoContactForAnyInvoice");
  969. print '</td></tr>';
  970. }
  971. print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
  972. if ($object->user_id)
  973. {
  974. $dolibarr_user=new User($db);
  975. $result=$dolibarr_user->fetch($object->user_id);
  976. print $dolibarr_user->getLoginUrl(1);
  977. }
  978. else print $langs->trans("NoDolibarrAccess");
  979. print '</td></tr>';
  980. print '<tr><td>';
  981. print $langs->trans("ExportCardToFormat").'</td><td colspan="3">';
  982. print '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'">';
  983. print img_picto($langs->trans("VCard"),'vcard.png').' ';
  984. print $langs->trans("VCard");
  985. print '</a>';
  986. print '</td></tr>';
  987. print "</table>";
  988. print dol_fiche_end();
  989. // Barre d'actions
  990. print '<div class="tabsAction">';
  991. $parameters=array();
  992. $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  993. if (empty($reshook))
  994. {
  995. if ($user->rights->societe->contact->creer)
  996. {
  997. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit">'.$langs->trans('Modify').'</a>';
  998. }
  999. if (! $object->user_id && $user->rights->user->user->creer)
  1000. {
  1001. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create_user">'.$langs->trans("CreateDolibarrLogin").'</a>';
  1002. }
  1003. // Activer
  1004. if ($object->statut == 0 && $user->rights->societe->contact->creer)
  1005. {
  1006. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable">'.$langs->trans("Reactivate").'</a>';
  1007. }
  1008. // Desactiver
  1009. if ($object->statut == 1 && $user->rights->societe->contact->creer)
  1010. {
  1011. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&id='.$object->id.'">'.$langs->trans("DisableUser").'</a>';
  1012. }
  1013. // Delete
  1014. if ($user->rights->societe->contact->supprimer)
  1015. {
  1016. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete'.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.$langs->trans('Delete').'</a>';
  1017. }
  1018. }
  1019. print "</div>";
  1020. print "<br>";
  1021. if (! empty($conf->agenda->enabled))
  1022. {
  1023. $objthirdparty=$objsoc;
  1024. $objcon=$object;
  1025. $out='';
  1026. $permok=$user->rights->agenda->myactions->create;
  1027. if ((! empty($objthirdparty->id) || ! empty($objcon->id)) && $permok)
  1028. {
  1029. $out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  1030. if (get_class($objthirdparty) == 'Societe') $out.='&amp;socid='.$objthirdparty->id;
  1031. $out.=(! empty($objcon->id)?'&amp;contactid='.$objcon->id:'').'&amp;backtopage=1&amp;percentage=-1">';
  1032. $out.=$langs->trans("AddAnAction").' ';
  1033. $out.=img_picto($langs->trans("AddAnAction"),'filenew');
  1034. $out.="</a>";
  1035. }
  1036. print load_fiche_titre($langs->trans("TasksHistoryForThisContact"),$out,'');
  1037. print show_actions_todo($conf,$langs,$db,$objsoc,$object);
  1038. print show_actions_done($conf,$langs,$db,$objsoc,$object);
  1039. }
  1040. }
  1041. }
  1042. llxFooter();
  1043. $db->close();