card.php 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  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-2017 Regis Houssin <regis.houssin@inodbox.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-2016 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. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  12. * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/contact/card.php
  29. * \ingroup societe
  30. * \brief Card of a contact
  31. */
  32. require '../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  45. // Load translation files required by the page
  46. $langs->loadLangs(array('companies', 'users', 'other', '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. $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. if ($user->societe_id) $socid=$user->societe_id;
  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 page. Note that conf->hooks_modules contains array of hook context
  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','alpha') && ! 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->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
  155. $object->socid = GETPOST("socid",'int');
  156. $object->lastname = GETPOST("lastname",'alpha');
  157. $object->firstname = GETPOST("firstname",'alpha');
  158. $object->civility_id = GETPOST("civility_id",'alpha');
  159. $object->poste = GETPOST("poste",'alpha');
  160. $object->address = GETPOST("address",'alpha');
  161. $object->zip = GETPOST("zipcode",'alpha');
  162. $object->town = GETPOST("town",'alpha');
  163. $object->country_id = GETPOST("country_id",'int');
  164. $object->state_id = GETPOST("state_id",'int');
  165. $object->skype = GETPOST("skype",'alpha');
  166. $object->twitter = GETPOST("twitter",'alpha');
  167. $object->facebook = GETPOST("facebook",'alpha');
  168. $object->email = GETPOST("email",'alpha');
  169. $object->phone_pro = GETPOST("phone_pro",'alpha');
  170. $object->phone_perso = GETPOST("phone_perso",'alpha');
  171. $object->phone_mobile = GETPOST("phone_mobile",'alpha');
  172. $object->fax = GETPOST("fax",'alpha');
  173. $object->jabberid = GETPOST("jabberid",'alpha');
  174. $object->no_email = GETPOST("no_email",'int');
  175. $object->priv = GETPOST("priv",'int');
  176. $object->note_public = GETPOST("note_public",'none');
  177. $object->note_private = GETPOST("note_private",'none');
  178. $object->statut = 1; //Defult status to Actif
  179. // Note: Correct date should be completed with location to have exact GM time of birth.
  180. $object->birthday = dol_mktime(0,0,0,GETPOST("birthdaymonth",'int'),GETPOST("birthdayday",'int'),GETPOST("birthdayyear",'int'));
  181. $object->birthday_alert = GETPOST("birthday_alert",'alpha');
  182. // Fill array 'array_options' with data from add form
  183. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  184. if ($ret < 0)
  185. {
  186. $error++;
  187. $action = 'create';
  188. }
  189. if (! GETPOST("lastname"))
  190. {
  191. $error++; $errors[]=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
  192. $action = 'create';
  193. }
  194. if (! $error)
  195. {
  196. $id = $object->create($user);
  197. if ($id <= 0)
  198. {
  199. $error++; $errors=array_merge($errors,($object->error?array($object->error):$object->errors));
  200. $action = 'create';
  201. } else {
  202. // Categories association
  203. $contcats = GETPOST( 'contcats', 'array');
  204. $object->setCategories($contcats);
  205. }
  206. }
  207. if (! $error && $id > 0)
  208. {
  209. $db->commit();
  210. if (! empty($backtopage)) $url=$backtopage;
  211. else $url='card.php?id='.$id;
  212. header("Location: ".$url);
  213. exit;
  214. }
  215. else
  216. {
  217. $db->rollback();
  218. }
  219. }
  220. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->contact->supprimer)
  221. {
  222. $result=$object->fetch($id);
  223. $object->old_lastname = GETPOST("old_lastname");
  224. $object->old_firstname = GETPOST("old_firstname");
  225. $result = $object->delete();
  226. if ($result > 0)
  227. {
  228. if ($backtopage)
  229. {
  230. header("Location: ".$backtopage);
  231. exit;
  232. }
  233. else
  234. {
  235. header("Location: ".DOL_URL_ROOT.'/contact/list.php');
  236. exit;
  237. }
  238. }
  239. else
  240. {
  241. setEventMessages($object->error,$object->errors,'errors');
  242. }
  243. }
  244. if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
  245. {
  246. if (empty($_POST["lastname"]))
  247. {
  248. $error++; $errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
  249. $action = 'edit';
  250. }
  251. if (! $error)
  252. {
  253. $contactid=GETPOST("contactid",'int');
  254. $object->fetch($contactid);
  255. // Photo save
  256. $dir = $conf->societe->multidir_output[$object->entity]."/contact/".$object->id."/photos";
  257. $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
  258. if (GETPOST('deletephoto') && $object->photo)
  259. {
  260. $fileimg=$dir.'/'.$object->photo;
  261. $dirthumbs=$dir.'/thumbs';
  262. dol_delete_file($fileimg);
  263. dol_delete_dir_recursive($dirthumbs);
  264. $object->photo = '';
  265. }
  266. if ($file_OK)
  267. {
  268. if (image_format_supported($_FILES['photo']['name']) > 0)
  269. {
  270. dol_mkdir($dir);
  271. if (@is_dir($dir))
  272. {
  273. $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
  274. $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
  275. if (! $result > 0)
  276. {
  277. $errors[] = "ErrorFailedToSaveFile";
  278. }
  279. else
  280. {
  281. $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
  282. // Create thumbs
  283. $object->addThumbs($newfile);
  284. }
  285. }
  286. }
  287. else
  288. {
  289. $errors[] = "ErrorBadImageFormat";
  290. }
  291. }
  292. else
  293. {
  294. switch($_FILES['photo']['error'])
  295. {
  296. case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
  297. case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
  298. $errors[] = "ErrorFileSizeTooLarge";
  299. break;
  300. case 3: //uploaded file was only partially uploaded
  301. $errors[] = "ErrorFilePartiallyUploaded";
  302. break;
  303. }
  304. }
  305. $object->oldcopy = clone $object;
  306. $object->old_lastname = GETPOST("old_lastname",'alpha');
  307. $object->old_firstname = GETPOST("old_firstname",'alpha');
  308. $object->socid = GETPOST("socid",'int');
  309. $object->lastname = GETPOST("lastname",'alpha');
  310. $object->firstname = GETPOST("firstname",'alpha');
  311. $object->civility_id = GETPOST("civility_id",'alpha');
  312. $object->poste = GETPOST("poste",'alpha');
  313. $object->address = GETPOST("address",'alpha');
  314. $object->zip = GETPOST("zipcode",'alpha');
  315. $object->town = GETPOST("town",'alpha');
  316. $object->state_id = GETPOST("state_id",'int');
  317. $object->fk_departement = GETPOST("state_id",'int'); // For backward compatibility
  318. $object->country_id = GETPOST("country_id",'int');
  319. $object->email = GETPOST("email",'alpha');
  320. $object->skype = GETPOST("skype",'alpha');
  321. $object->twitter = GETPOST("twitter",'alpha');
  322. $object->facebook = GETPOST("facebook",'alpha');
  323. $object->phone_pro = GETPOST("phone_pro",'alpha');
  324. $object->phone_perso = GETPOST("phone_perso",'alpha');
  325. $object->phone_mobile = GETPOST("phone_mobile",'alpha');
  326. $object->fax = GETPOST("fax",'alpha');
  327. $object->jabberid = GETPOST("jabberid",'alpha');
  328. $object->no_email = GETPOST("no_email",'int');
  329. $object->priv = GETPOST("priv",'int');
  330. $object->note_public = GETPOST("note_public",'none');
  331. $object->note_private = GETPOST("note_private",'none');
  332. // Fill array 'array_options' with data from add form
  333. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  334. if ($ret < 0) $error++;
  335. $result = $object->update($contactid, $user);
  336. if ($result > 0) {
  337. // Categories association
  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. if (! $error && empty($errors))
  351. {
  352. if (! empty($backtopage))
  353. {
  354. header("Location: ".$backtopage);
  355. exit;
  356. }
  357. }
  358. }
  359. }
  360. /*
  361. * View
  362. */
  363. $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  364. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->lastname) $title=$object->lastname;
  365. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  366. llxHeader('', $title, $help_url);
  367. $form = new Form($db);
  368. $formcompany = new FormCompany($db);
  369. $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  370. if ($socid > 0)
  371. {
  372. $objsoc = new Societe($db);
  373. $objsoc->fetch($socid);
  374. }
  375. if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
  376. {
  377. // -----------------------------------------
  378. // When used with CANVAS
  379. // -----------------------------------------
  380. if (empty($object->error) && $id)
  381. {
  382. $object = new Contact($db);
  383. $result=$object->fetch($id);
  384. if ($result <= 0) dol_print_error('',$object->error);
  385. }
  386. $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
  387. $objcanvas->display_canvas($action); // Show template
  388. }
  389. else
  390. {
  391. // -----------------------------------------
  392. // When used in standard mode
  393. // -----------------------------------------
  394. // Confirm deleting contact
  395. if ($user->rights->societe->contact->supprimer)
  396. {
  397. if ($action == 'delete')
  398. {
  399. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage?'&backtopage='.$backtopage:''),$langs->trans("DeleteContact"),$langs->trans("ConfirmDeleteContact"),"confirm_delete",'',0,1);
  400. }
  401. }
  402. /*
  403. * Onglets
  404. */
  405. $head=array();
  406. if ($id > 0)
  407. {
  408. // Si edition contact deja existant
  409. $object = new Contact($db);
  410. $res=$object->fetch($id, $user);
  411. if ($res < 0) { dol_print_error($db,$object->error); exit; }
  412. $res=$object->fetch_optionals();
  413. if ($res < 0) { dol_print_error($db,$object->error); exit; }
  414. // Show tabs
  415. $head = contact_prepare_head($object);
  416. $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  417. }
  418. if ($user->rights->societe->contact->creer)
  419. {
  420. if ($action == 'create')
  421. {
  422. /*
  423. * Fiche en mode creation
  424. */
  425. $object->canvas=$canvas;
  426. $object->state_id = GETPOST("state_id");
  427. // We set country_id, country_code and label for the selected country
  428. $object->country_id=$_POST["country_id"]?GETPOST("country_id"):(empty($objsoc->country_id)?$mysoc->country_id:$objsoc->country_id);
  429. if ($object->country_id)
  430. {
  431. $tmparray=getCountry($object->country_id,'all');
  432. $object->country_code = $tmparray['code'];
  433. $object->country = $tmparray['label'];
  434. }
  435. $title = $addcontact = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
  436. $linkback='';
  437. print load_fiche_titre($title,$linkback,'title_companies.png');
  438. // Affiche les erreurs
  439. dol_htmloutput_errors(is_numeric($error)?'':$error,$errors);
  440. if ($conf->use_javascript_ajax)
  441. {
  442. print "\n".'<script type="text/javascript" language="javascript">'."\n";
  443. print 'jQuery(document).ready(function () {
  444. jQuery("#selectcountry_id").change(function() {
  445. document.formsoc.action.value="create";
  446. document.formsoc.submit();
  447. });
  448. $("#copyaddressfromsoc").click(function() {
  449. $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
  450. $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
  451. $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
  452. console.log("Set state_id to '.dol_escape_js($objsoc->state_id).'");
  453. $(\'select[name="state_id"]\').val("'.dol_escape_js($objsoc->state_id).'").trigger("change");
  454. /* set country at end because it will trigger page refresh */
  455. console.log("Set country id to '.dol_escape_js($objsoc->country_id).'");
  456. $(\'select[name="country_id"]\').val("'.dol_escape_js($objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
  457. });
  458. })'."\n";
  459. print '</script>'."\n";
  460. }
  461. print '<form method="post" name="formsoc" action="'.$_SERVER["PHP_SELF"].'">';
  462. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  463. print '<input type="hidden" name="action" value="add">';
  464. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  465. if (! empty($objsoc)) {
  466. print '<input type="hidden" name="entity" value="'.$objsoc->entity.'">';
  467. }
  468. dol_fiche_head($head, 'card', '', 0, '');
  469. print '<table class="border" width="100%">';
  470. // Name
  471. print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
  472. print '<td><input name="lastname" id="lastname" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("lastname",'alpha')?GETPOST("lastname",'alpha'):$object->lastname).'" autofocus="autofocus"></td>';
  473. print '<td><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
  474. print '<td><input name="firstname" id="firstname"type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("firstname",'alpha')?GETPOST("firstname",'alpha'):$object->firstname).'"></td></tr>';
  475. // Company
  476. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  477. {
  478. if ($socid > 0)
  479. {
  480. print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
  481. print '<td colspan="3" class="maxwidthonsmartphone">';
  482. print $objsoc->getNomUrl(1, 'contact');
  483. print '</td>';
  484. print '<input type="hidden" name="socid" id="socid" value="'.$objsoc->id.'">';
  485. print '</td></tr>';
  486. }
  487. else {
  488. print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  489. print $form->select_company($socid,'socid','','SelectThirdParty');
  490. print '</td></tr>';
  491. }
  492. }
  493. // Civility
  494. print '<tr><td><label for="civility_id">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
  495. print $formcompany->select_civility(GETPOST("civility_id",'alpha')?GETPOST("civility_id",'alpha'):$object->civility_id);
  496. print '</td></tr>';
  497. print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
  498. print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOST("poste",'alpha')?GETPOST("poste",'alpha'):$object->poste).'"></td>';
  499. $colspan=3;
  500. if ($conf->use_javascript_ajax && $socid > 0) $colspan=2;
  501. // Address
  502. 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
  503. print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
  504. print '<td colspan="'.$colspan.'"><textarea class="flat quatrevingtpercent" name="address" id="address" rows="'.ROWS_2.'">'.(GETPOST("address",'alpha')?GETPOST("address",'alpha'):$object->address).'</textarea></td>';
  505. if ($conf->use_javascript_ajax && $socid > 0)
  506. {
  507. $rowspan=3;
  508. if (empty($conf->global->SOCIETE_DISABLE_STATE)) $rowspan++;
  509. print '<td valign="middle" align="center" rowspan="'.$rowspan.'">';
  510. print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a>';
  511. print '</td>';
  512. }
  513. print '</tr>';
  514. // Zip / Town
  515. 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
  516. 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
  517. print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
  518. print $formcompany->select_ziptown((GETPOST("zipcode",'alpha')?GETPOST("zipcode",'alpha'):$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6).'&nbsp;';
  519. print $formcompany->select_ziptown((GETPOST("town",'alpha')?GETPOST("town",'alpha'):$object->town),'town',array('zipcode','selectcountry_id','state_id'));
  520. print '</td></tr>';
  521. // Country
  522. print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
  523. print $form->select_country((GETPOST("country_id",'alpha')?GETPOST("country_id",'alpha'):$object->country_id),'country_id');
  524. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  525. print '</td></tr>';
  526. // State
  527. if (empty($conf->global->SOCIETE_DISABLE_STATE))
  528. {
  529. if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
  530. {
  531. print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
  532. }
  533. else
  534. {
  535. print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
  536. }
  537. if ($object->country_id)
  538. {
  539. print $formcompany->select_state(GETPOST("state_id",'alpha')?GETPOST("state_id",'alpha'):$object->state_id,$object->country_code,'state_id');
  540. }
  541. else
  542. {
  543. print $countrynotdefined;
  544. }
  545. print '</td></tr>';
  546. }
  547. // Phone / Fax
  548. 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
  549. print '<tr><td><label for="phone_pro">'.$langs->trans("PhonePro").'</label></td>';
  550. print '<td><input name="phone_pro" id="phone_pro" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("phone_pro")?GETPOST("phone_pro"):$object->phone_pro).'"></td>';
  551. print '<td><label for="phone_perso">'.$langs->trans("PhonePerso").'</label></td>';
  552. print '<td><input name="phone_perso" id="phone_perso" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("phone_perso")?GETPOST("phone_perso"):$object->phone_perso).'"></td></tr>';
  553. 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
  554. print '<tr><td><label for="phone_mobile">'.$langs->trans("PhoneMobile").'</label></td>';
  555. print '<td><input name="phone_mobile" id="phone_mobile" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("phone_mobile")?GETPOST("phone_mobile"):$object->phone_mobile).'"></td>';
  556. print '<td><label for="fax">'.$langs->trans("Fax").'</label></td>';
  557. print '<td><input name="fax" id="fax" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("fax",'alpha')?GETPOST("fax",'alpha'):$object->fax).'"></td></tr>';
  558. // EMail
  559. 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
  560. print '<tr><td><label for="email">'.$langs->trans("Email").'</label></td>';
  561. print '<td><input name="email" id="email" type="text" class="maxwidth100onsmartphone" value="'.dol_escape_htmltag(GETPOST("email",'alpha')?GETPOST("email",'alpha'):$object->email).'"></td>';
  562. if (! empty($conf->mailing->enabled))
  563. {
  564. print '<td><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
  565. print '<td>'.$form->selectyesno('no_email',(GETPOST("no_email",'alpha')?GETPOST("no_email",'alpha'):$object->no_email), 1).'</td>';
  566. }
  567. else
  568. {
  569. print '<td colspan="2">&nbsp;</td>';
  570. }
  571. print '</tr>';
  572. // Instant message and no email
  573. print '<tr><td><label for="jabberid">'.$langs->trans("IM").'</label></td>';
  574. print '<td colspan="3"><input name="jabberid" id="jabberid" type="text" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("jabberid")?GETPOST("jabberid",'alpha'):$object->jabberid).'"></td></tr>';
  575. if (! empty($conf->socialnetworks->enabled))
  576. {
  577. // Skype
  578. if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
  579. {
  580. print '<tr><td><label for="skype">'.fieldLabel('Skype','skype').'</label></td>';
  581. print '<td colspan="3"><input type="text" name="skype" id="skype" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("skype")?GETPOST("skype",'alpha'):$object->skype).'"></td></tr>';
  582. }
  583. // Twitter
  584. if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
  585. {
  586. print '<tr><td><label for="twitter">'.fieldLabel('Twitter','twitter').'</label></td>';
  587. print '<td colspan="3"><input type="text" name="twitter" id="twitter" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("twitter")?GETPOST("twitter",'alpha'):$object->twitter).'"></td></tr>';
  588. }
  589. // Facebook
  590. if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
  591. {
  592. print '<tr><td><label for="facebook">'.fieldLabel('Facebook','facebook').'</label></td>';
  593. print '<td colspan="3"><input type="text" name="facebook" id="facebook" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("facebook")?GETPOST("facebook",'alpha'):$object->facebook).'"></td></tr>';
  594. }
  595. }
  596. // Visibility
  597. print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
  598. $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
  599. print $form->selectarray('priv',$selectarray,(GETPOST("priv",'alpha')?GETPOST("priv",'alpha'):$object->priv),0);
  600. print '</td></tr>';
  601. // Categories
  602. if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) {
  603. print '<tr><td>' . fieldLabel( 'Categories', 'contcats' ) . '</td><td colspan="3">';
  604. $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, 'parent', null, null, 1 );
  605. print $form->multiselectarray( 'contcats', $cate_arbo, GETPOST( 'contcats', 'array' ), null, null, null,
  606. null, '90%' );
  607. print "</td></tr>";
  608. }
  609. // Other attributes
  610. $parameters=array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3);
  611. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  612. print $hookmanager->resPrint;
  613. if (empty($reshook))
  614. {
  615. print $object->showOptionals($extrafields,'edit');
  616. }
  617. print "</table><br>";
  618. print '<hr style="margin-bottom: 20px">';
  619. // Add personnal information
  620. print load_fiche_titre('<div class="comboperso">'.$langs->trans("PersonalInformations").'</div>','','');
  621. print '<table class="border" width="100%">';
  622. // Date To Birth
  623. print '<tr><td width="20%"><label for="birthday">'.$langs->trans("DateToBirth").'</label></td><td width="30%">';
  624. $form=new Form($db);
  625. if ($object->birthday)
  626. {
  627. print $form->selectDate($object->birthday, 'birthday', 0, 0, 0, "perso", 1, 0);
  628. }
  629. else
  630. {
  631. print $form->selectDate('', 'birthday', 0, 0, 1, "perso", 1, 0);
  632. }
  633. print '</td>';
  634. print '<td colspan="2"><label for="birthday_alert">'.$langs->trans("Alert").'</label>: ';
  635. if ($object->birthday_alert)
  636. {
  637. print '<input type="checkbox" name="birthday_alert" id="birthday_alert" checked></td>';
  638. }
  639. else
  640. {
  641. print '<input type="checkbox" name="birthday_alert" id="birthday_alert"></td>';
  642. }
  643. print '</tr>';
  644. print "</table>";
  645. print dol_fiche_end();
  646. print '<div class="center">';
  647. print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
  648. if (! empty($backtopage))
  649. {
  650. print ' &nbsp; &nbsp; ';
  651. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  652. }
  653. else
  654. {
  655. print ' &nbsp; &nbsp; ';
  656. print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
  657. }
  658. print '</div>';
  659. print "</form>";
  660. }
  661. elseif ($action == 'edit' && ! empty($id))
  662. {
  663. /*
  664. * Fiche en mode edition
  665. */
  666. // We set country_id, and country_code label of the chosen country
  667. if (isset($_POST["country_id"]) || $object->country_id)
  668. {
  669. $tmparray=getCountry($object->country_id,'all');
  670. $object->country_code = $tmparray['code'];
  671. $object->country = $tmparray['label'];
  672. }
  673. $objsoc = new Societe($db);
  674. $objsoc->fetch($object->socid);
  675. // Affiche les erreurs
  676. dol_htmloutput_errors($error,$errors);
  677. if ($conf->use_javascript_ajax)
  678. {
  679. print "\n".'<script type="text/javascript" language="javascript">'."\n";
  680. print 'jQuery(document).ready(function () {
  681. jQuery("#selectcountry_id").change(function() {
  682. document.formsoc.action.value="edit";
  683. document.formsoc.submit();
  684. });
  685. $("#copyaddressfromsoc").click(function() {
  686. $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
  687. $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
  688. $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
  689. console.log("Set state_id to '.dol_escape_js($objsoc->state_id).'");
  690. $(\'select[name="state_id"]\').val("'.dol_escape_js($objsoc->state_id).'").trigger("change");
  691. /* set country at end because it will trigger page refresh */
  692. console.log("Set country id to '.dol_escape_js($objsoc->country_id).'");
  693. $(\'select[name="country_id"]\').val("'.dol_escape_js($objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
  694. });
  695. })'."\n";
  696. print '</script>'."\n";
  697. }
  698. print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" name="formsoc">';
  699. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  700. print '<input type="hidden" name="id" value="'.$id.'">';
  701. print '<input type="hidden" name="action" value="update">';
  702. print '<input type="hidden" name="contactid" value="'.$object->id.'">';
  703. print '<input type="hidden" name="old_lastname" value="'.$object->lastname.'">';
  704. print '<input type="hidden" name="old_firstname" value="'.$object->firstname.'">';
  705. if (! empty($backtopage)) print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  706. dol_fiche_head($head, 'card', $title, 0, 'contact');
  707. print '<table class="border" width="100%">';
  708. // Ref/ID
  709. if (! empty($conf->global->MAIN_SHOW_TECHNICAL_ID))
  710. {
  711. print '<tr><td>'.$langs->trans("ID").'</td><td colspan="3">';
  712. print $object->ref;
  713. print '</td></tr>';
  714. }
  715. // Lastname
  716. print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
  717. print '<td colspan="3"><input name="lastname" id="lastname" type="text" class="minwidth200" maxlength="80" value="'.(isset($_POST["lastname"])?GETPOST("lastname"):$object->lastname).'" autofocus="autofocus"></td>';
  718. print '</tr>';
  719. print '<tr>';
  720. // Firstname
  721. print '<td><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
  722. print '<td colspan="3"><input name="firstname" id="firstname" type="text" class="minwidth200" maxlength="80" value="'.(isset($_POST["firstname"])?GETPOST("firstname"):$object->firstname).'"></td>';
  723. print '</tr>';
  724. // Company
  725. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  726. {
  727. print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
  728. print '<td colspan="3" class="maxwidthonsmartphone">';
  729. print $form->select_company(GETPOST('socid','int')?GETPOST('socid','int'):($object->socid?$object->socid:-1), 'socid', '', $langs->trans("SelectThirdParty"));
  730. print '</td>';
  731. print '</tr>';
  732. }
  733. // Civility
  734. print '<tr><td><label for="civility_id">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
  735. print $formcompany->select_civility(isset($_POST["civility_id"])?GETPOST("civility_id"):$object->civility_id);
  736. print '</td></tr>';
  737. print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
  738. print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="80" value="'.(isset($_POST["poste"])?GETPOST("poste"):$object->poste).'"></td></tr>';
  739. // Address
  740. print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
  741. print '<td colspan="3">';
  742. print '<div class="paddingrightonly valignmiddle inline-block">';
  743. print '<textarea class="flat minwidth200" name="address" id="address">'.(isset($_POST["address"])?GETPOST("address"):$object->address).'</textarea>';
  744. print '</div><div class="paddingrightonly valignmiddle inline-block">';
  745. if ($conf->use_javascript_ajax) print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a><br>';
  746. print '</div>';
  747. print '</td>';
  748. // Zip / Town
  749. print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  750. print $formcompany->select_ziptown((isset($_POST["zipcode"])?GETPOST("zipcode"):$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6).'&nbsp;';
  751. print $formcompany->select_ziptown((isset($_POST["town"])?GETPOST("town"):$object->town),'town',array('zipcode','selectcountry_id','state_id'));
  752. print '</td></tr>';
  753. // Country
  754. print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  755. print $form->select_country(isset($_POST["country_id"])?GETPOST("country_id"):$object->country_id,'country_id');
  756. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  757. print '</td></tr>';
  758. // State
  759. if (empty($conf->global->SOCIETE_DISABLE_STATE))
  760. {
  761. if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
  762. {
  763. print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  764. }
  765. else
  766. {
  767. print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  768. }
  769. print $formcompany->select_state($object->state_id,isset($_POST["country_id"])?GETPOST("country_id"):$object->country_id,'state_id');
  770. print '</td></tr>';
  771. }
  772. // Phone
  773. print '<tr><td><label for="phone_pro">'.$langs->trans("PhonePro").'</label></td>';
  774. print '<td><input name="phone_pro" id="phone_pro" type="text" class="flat maxwidthonsmartphone" maxlength="80" value="'.(isset($_POST["phone_pro"])?GETPOST("phone_pro"):$object->phone_pro).'"></td>';
  775. print '<td><label for="phone_perso">'.$langs->trans("PhonePerso").'</label></td>';
  776. print '<td><input name="phone_perso" id="phone_perso" type="text" class="flat maxwidthonsmartphone" maxlength="80" value="'.(isset($_POST["phone_perso"])?GETPOST("phone_perso"):$object->phone_perso).'"></td></tr>';
  777. print '<tr><td><label for="phone_mobile">'.$langs->trans("PhoneMobile").'</label></td>';
  778. print '<td><input name="phone_mobile" id="phone_mobile" class="flat maxwidthonsmartphone" type="text" maxlength="80" value="'.(isset($_POST["phone_mobile"])?GETPOST("phone_mobile"):$object->phone_mobile).'"></td>';
  779. print '<td><label for="fax">'.$langs->trans("Fax").'</label></td>';
  780. print '<td><input name="fax" id="fax" type="text" class="flat maxwidthonsmartphone" maxlength="80" value="'.(isset($_POST["fax"])?GETPOST("fax"):$object->fax).'"></td></tr>';
  781. // EMail
  782. print '<tr><td><label for="email">'.$langs->trans("EMail").'</label></td>';
  783. print '<td><input name="email" id="email" type="text" class="flat maxwidthonsmartphone" value="'.(isset($_POST["email"])?GETPOST("email"):$object->email).'"></td>';
  784. if (! empty($conf->mailing->enabled))
  785. {
  786. $langs->load("mails");
  787. print '<td class="nowrap">'.$langs->trans("NbOfEMailingsSend").'</td>';
  788. print '<td>'.$object->getNbOfEMailings().'</td>';
  789. }
  790. else
  791. {
  792. print '<td colspan="2">&nbsp;</td>';
  793. }
  794. print '</tr>';
  795. // Jabberid
  796. print '<tr><td><label for="jabberid">'.$langs->trans("IM").'</label></td>';
  797. print '<td><input name="jabberid" id="jabberid" type="text" class="minwidth100" maxlength="80" value="'.(isset($_POST["jabberid"])?$_POST["jabberid"]:$object->jabberid).'"></td>';
  798. if (! empty($conf->mailing->enabled))
  799. {
  800. print '<td><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
  801. print '<td>'.$form->selectyesno('no_email',(isset($_POST["no_email"])?$_POST["no_email"]:$object->no_email), 1).'</td>';
  802. }
  803. else
  804. {
  805. print '<td colspan="2">&nbsp;</td>';
  806. }
  807. print '</tr>';
  808. if (! empty($conf->socialnetworks->enabled))
  809. {
  810. // Skype
  811. if (! empty($conf->global->SOCIALNETWORKS_SKYPE))
  812. {
  813. print '<tr><td><label for="skype">'.fieldLabel('Skype','skype').'</label></td>';
  814. print '<td><input type="text" name="skype" id="skype" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("skype")?GETPOST("skype",'alpha'):$object->skype).'"></td></tr>';
  815. }
  816. // Twitter
  817. if (! empty($conf->global->SOCIALNETWORKS_TWITTER))
  818. {
  819. print '<tr><td><label for="twitter">'.fieldLabel('Twitter','twitter').'</label></td>';
  820. print '<td><input type="text" name="twitter" id="twitter" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET("twitter")?GETPOST("twitter",'alpha'):$object->twitter).'"></td></tr>';
  821. }
  822. // Facebook
  823. if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK))
  824. {
  825. print '<tr><td><label for="facebook">'.fieldLabel('Facebook','facebook').'</label></td>';
  826. print '<td><input type="text" name="facebook" id="facebook" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOST("facebook")?GETPOST("facebook",'alpha'):$object->facebook).'"></td></tr>';
  827. }
  828. }
  829. // Visibility
  830. print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
  831. $selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
  832. print $form->selectarray('priv',$selectarray,$object->priv,0);
  833. print '</td></tr>';
  834. // Note Public
  835. print '<tr><td class="tdtop"><label for="note_public">'.$langs->trans("NotePublic").'</label></td><td colspan="3">';
  836. $doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
  837. print $doleditor->Create(1);
  838. print '</td></tr>';
  839. // Note Private
  840. print '<tr><td class="tdtop"><label for="note_private">'.$langs->trans("NotePrivate").'</label></td><td colspan="3">';
  841. $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
  842. print $doleditor->Create(1);
  843. print '</td></tr>';
  844. // Status
  845. print '<tr><td>'.$langs->trans("Status").'</td>';
  846. print '<td colspan="3">';
  847. print $object->getLibStatut(4);
  848. print '</td></tr>';
  849. // Categories
  850. if (!empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire )) {
  851. print '<tr><td>' . fieldLabel( 'Categories', 'contcats' ) . '</td>';
  852. print '<td colspan="3">';
  853. $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, null, null, null, 1 );
  854. $c = new Categorie( $db );
  855. $cats = $c->containing( $object->id, 'contact' );
  856. foreach ($cats as $cat) {
  857. $arrayselected[] = $cat->id;
  858. }
  859. print $form->multiselectarray( 'contcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%' );
  860. print "</td></tr>";
  861. }
  862. // Other attributes
  863. $parameters=array('colspan' => ' colspan="3"', 'cols'=>3);
  864. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  865. print $hookmanager->resPrint;
  866. if (empty($reshook))
  867. {
  868. print $object->showOptionals($extrafields,'edit');
  869. }
  870. $object->load_ref_elements();
  871. if (! empty($conf->commande->enabled))
  872. {
  873. print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
  874. print $object->ref_commande?$object->ref_commande:$langs->trans("NoContactForAnyOrder");
  875. print '</td></tr>';
  876. }
  877. if (! empty($conf->propal->enabled))
  878. {
  879. print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
  880. print $object->ref_propal?$object->ref_propal:$langs->trans("NoContactForAnyProposal");
  881. print '</td></tr>';
  882. }
  883. if (! empty($conf->contrat->enabled))
  884. {
  885. print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
  886. print $object->ref_contrat?$object->ref_contrat:$langs->trans("NoContactForAnyContract");
  887. print '</td></tr>';
  888. }
  889. if (! empty($conf->facture->enabled))
  890. {
  891. print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
  892. print $object->ref_facturation?$object->ref_facturation:$langs->trans("NoContactForAnyInvoice");
  893. print '</td></tr>';
  894. }
  895. // Login Dolibarr
  896. print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
  897. if ($object->user_id)
  898. {
  899. $dolibarr_user=new User($db);
  900. $result=$dolibarr_user->fetch($object->user_id);
  901. print $dolibarr_user->getLoginUrl(1);
  902. }
  903. else print $langs->trans("NoDolibarrAccess");
  904. print '</td></tr>';
  905. // Photo
  906. print '<tr>';
  907. print '<td>'.$langs->trans("PhotoFile").'</td>';
  908. print '<td colspan="3">';
  909. if ($object->photo) {
  910. print $form->showphoto('contact',$object);
  911. print "<br>\n";
  912. }
  913. print '<table class="nobordernopadding">';
  914. if ($object->photo) print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
  915. //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
  916. print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
  917. print '</table>';
  918. print '</td>';
  919. print '</tr>';
  920. print '</table>';
  921. print dol_fiche_end();
  922. print '<div class="center">';
  923. print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  924. print ' &nbsp; &nbsp; ';
  925. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  926. print '</div>';
  927. print "</form>";
  928. }
  929. }
  930. if (! empty($id) && $action != 'edit' && $action != 'create')
  931. {
  932. $objsoc = new Societe($db);
  933. /*
  934. * Fiche en mode visualisation
  935. */
  936. dol_htmloutput_errors($error,$errors);
  937. dol_fiche_head($head, 'card', $title, -1, 'contact');
  938. if ($action == 'create_user')
  939. {
  940. // Full firstname and lastname separated with a dot : firstname.lastname
  941. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  942. $login=dol_buildlogin($object->lastname,$object->firstname);
  943. $generated_password='';
  944. if (! $ldap_sid) // TODO ldap_sid ?
  945. {
  946. require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  947. $generated_password=getRandomPassword(false);
  948. }
  949. $password=$generated_password;
  950. // Create a form array
  951. $formquestion=array(
  952. array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
  953. array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password),
  954. //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')))
  955. );
  956. $text=$langs->trans("ConfirmCreateContact").'<br>';
  957. if (! empty($conf->societe->enabled))
  958. {
  959. if ($object->socid > 0) $text.=$langs->trans("UserWillBeExternalUser");
  960. else $text.=$langs->trans("UserWillBeInternalUser");
  961. }
  962. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("CreateDolibarrLogin"),$text,"confirm_create_user",$formquestion,'yes');
  963. }
  964. $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  965. $morehtmlref='<div class="refidno">';
  966. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
  967. {
  968. $objsoc->fetch($object->socid);
  969. // Thirdparty
  970. $morehtmlref.=$langs->trans('ThirdParty') . ' : ';
  971. if ($objsoc->id > 0) $morehtmlref.=$objsoc->getNomUrl(1, 'contact');
  972. else $morehtmlref.=$langs->trans("ContactNotLinkedToCompany");
  973. }
  974. $morehtmlref.='</div>';
  975. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  976. print '<div class="fichecenter">';
  977. print '<div class="fichehalfleft">';
  978. print '<div class="underbanner clearboth"></div>';
  979. print '<table class="border tableforfield" width="100%">';
  980. // Civility
  981. print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td>';
  982. print $object->getCivilityLabel();
  983. print '</td></tr>';
  984. // Role
  985. print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td>'.$object->poste.'</td></tr>';
  986. // Email
  987. if (! empty($conf->mailing->enabled))
  988. {
  989. $langs->load("mails");
  990. print '<tr><td>'.$langs->trans("NbOfEMailingsSend").'</td>';
  991. print '<td><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td></tr>';
  992. }
  993. // Instant message and no email
  994. print '<tr><td>'.$langs->trans("IM").'</td><td>'.$object->jabberid.'</td></tr>';
  995. if (!empty($conf->mailing->enabled))
  996. {
  997. print '<tr><td>'.$langs->trans("No_Email").'</td><td>'.yn($object->no_email).'</td></tr>';
  998. }
  999. print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td>';
  1000. print $object->LibPubPriv($object->priv);
  1001. print '</td></tr>';
  1002. print '</table>';
  1003. print '</div>';
  1004. print '<div class="fichehalfright"><div class="ficheaddleft">';
  1005. print '<div class="underbanner clearboth"></div>';
  1006. print '<table class="border tableforfield" width="100%">';
  1007. // Categories
  1008. if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) {
  1009. print '<tr><td class="titlefield">' . $langs->trans("Categories") . '</td>';
  1010. print '<td colspan="3">';
  1011. print $form->showCategories( $object->id, 'contact', 1 );
  1012. print '</td></tr>';
  1013. }
  1014. // Other attributes
  1015. $cols = 3;
  1016. $parameyers=array('socid'=>$socid);
  1017. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  1018. $object->load_ref_elements();
  1019. if (! empty($conf->propal->enabled))
  1020. {
  1021. print '<tr><td class="titlefield">'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
  1022. print $object->ref_propal?$object->ref_propal:$langs->trans("NoContactForAnyProposal");
  1023. print '</td></tr>';
  1024. }
  1025. if (! empty($conf->commande->enabled) || ! empty($conf->expedition->enabled))
  1026. {
  1027. print '<tr><td>';
  1028. if (! empty($conf->expedition->enabled)) { print $langs->trans("ContactForOrdersOrShipments"); }
  1029. else print $langs->trans("ContactForOrders");
  1030. print '</td><td colspan="3">';
  1031. $none=$langs->trans("NoContactForAnyOrder");
  1032. if (! empty($conf->expedition->enabled)) { $none=$langs->trans("NoContactForAnyOrderOrShipments"); }
  1033. print $object->ref_commande?$object->ref_commande:$none;
  1034. print '</td></tr>';
  1035. }
  1036. if (! empty($conf->contrat->enabled))
  1037. {
  1038. print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
  1039. print $object->ref_contrat?$object->ref_contrat:$langs->trans("NoContactForAnyContract");
  1040. print '</td></tr>';
  1041. }
  1042. if (! empty($conf->facture->enabled))
  1043. {
  1044. print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
  1045. print $object->ref_facturation?$object->ref_facturation:$langs->trans("NoContactForAnyInvoice");
  1046. print '</td></tr>';
  1047. }
  1048. print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
  1049. if ($object->user_id)
  1050. {
  1051. $dolibarr_user=new User($db);
  1052. $result=$dolibarr_user->fetch($object->user_id);
  1053. print $dolibarr_user->getLoginUrl(1);
  1054. }
  1055. else print $langs->trans("NoDolibarrAccess");
  1056. print '</td></tr>';
  1057. print '<tr><td>';
  1058. print $langs->trans("VCard").'</td><td colspan="3">';
  1059. print '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'">';
  1060. print img_picto($langs->trans("Download"),'vcard.png').' ';
  1061. print $langs->trans("Download");
  1062. print '</a>';
  1063. print '</td></tr>';
  1064. print "</table>";
  1065. print '</div></div></div>';
  1066. print '<div style="clear:both"></div>';
  1067. print dol_fiche_end();
  1068. // Barre d'actions
  1069. print '<div class="tabsAction">';
  1070. $parameters=array();
  1071. $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1072. if (empty($reshook))
  1073. {
  1074. if ($user->rights->societe->contact->creer)
  1075. {
  1076. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit">'.$langs->trans('Modify').'</a>';
  1077. }
  1078. if (! $object->user_id && $user->rights->user->user->creer)
  1079. {
  1080. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create_user">'.$langs->trans("CreateDolibarrLogin").'</a>';
  1081. }
  1082. // Activer
  1083. if ($object->statut == 0 && $user->rights->societe->contact->creer)
  1084. {
  1085. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable">'.$langs->trans("Reactivate").'</a>';
  1086. }
  1087. // Desactiver
  1088. if ($object->statut == 1 && $user->rights->societe->contact->creer)
  1089. {
  1090. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&id='.$object->id.'">'.$langs->trans("DisableUser").'</a>';
  1091. }
  1092. // Delete
  1093. if ($user->rights->societe->contact->supprimer)
  1094. {
  1095. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete'.($backtopage?'&backtopage='.urlencode($backtopage):'').'">'.$langs->trans('Delete').'</a>';
  1096. }
  1097. }
  1098. print "</div>";
  1099. }
  1100. }
  1101. llxFooter();
  1102. $db->close();