card.php 55 KB

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