card.php 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620
  1. <?php
  2. /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2019 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@open-dsi.fr>
  9. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  10. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  11. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  12. * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
  13. * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  27. */
  28. /**
  29. * \file htdocs/contact/card.php
  30. * \ingroup societe
  31. * \brief Card of a contact
  32. */
  33. require '../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  47. // Load translation files required by the page
  48. $langs->loadLangs(array('companies', 'users', 'other', 'commercial'));
  49. $mesg = ''; $error = 0; $errors = array();
  50. $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
  51. $confirm = GETPOST('confirm', 'alpha');
  52. $backtopage = GETPOST('backtopage', 'alpha');
  53. $cancel = GETPOST('cancel', 'alpha');
  54. $id = GETPOST('id', 'int');
  55. $socid = GETPOST('socid', 'int');
  56. $object = new Contact($db);
  57. $extrafields = new ExtraFields($db);
  58. // fetch optionals attributes and labels
  59. $extrafields->fetch_name_optionals_label($object->table_element);
  60. $socialnetworks = getArrayOfSocialNetworks();
  61. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  62. $object->getCanvas($id);
  63. $objcanvas = null;
  64. $canvas = (!empty($object->canvas) ? $object->canvas : GETPOST("canvas"));
  65. if (!empty($canvas)) {
  66. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  67. $objcanvas = new Canvas($db, $action);
  68. $objcanvas->getCanvas('contact', 'contactcard', $canvas);
  69. }
  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. if ($id > 0) {
  73. $object->fetch($id);
  74. }
  75. if (!($object->id > 0) && $action == 'view') {
  76. $langs->load("errors");
  77. print($langs->trans('ErrorRecordNotFound'));
  78. exit;
  79. }
  80. $triggermodname = 'CONTACT_MODIFY';
  81. $permissiontoadd = $user->rights->societe->contact->creer;
  82. // Security check
  83. if ($user->socid) {
  84. $socid = $user->socid;
  85. }
  86. $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission
  87. /*
  88. * Actions
  89. */
  90. $parameters = array('id'=>$id, 'objcanvas'=>$objcanvas);
  91. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  92. if ($reshook < 0) {
  93. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  94. }
  95. if (empty($reshook)) {
  96. $backurlforlist = DOL_URL_ROOT.'/contact/list.php';
  97. if (empty($backtopage) || ($cancel && empty($id))) {
  98. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  99. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  100. $backtopage = $backurlforlist;
  101. } else {
  102. $backtopage = DOL_URL_ROOT.'/contact/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  103. }
  104. }
  105. }
  106. if ($cancel) {
  107. if (!empty($backtopageforcancel)) {
  108. header("Location: ".$backtopageforcancel);
  109. exit;
  110. } elseif (!empty($backtopage)) {
  111. header("Location: ".$backtopage);
  112. exit;
  113. }
  114. $action = '';
  115. }
  116. // Creation utilisateur depuis contact
  117. if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) {
  118. // Recuperation contact actuel
  119. $result = $object->fetch($id);
  120. if ($result > 0) {
  121. $db->begin();
  122. // Creation user
  123. $nuser = new User($db);
  124. $result = $nuser->create_from_contact($object, GETPOST("login")); // Do not use GETPOST(alpha)
  125. if ($result > 0) {
  126. $result2 = $nuser->setPassword($user, GETPOST("password"), 0, 0, 1); // Do not use GETPOST(alpha)
  127. if ($result2) {
  128. $db->commit();
  129. } else {
  130. $error = $nuser->error; $errors = $nuser->errors;
  131. $db->rollback();
  132. }
  133. } else {
  134. $error = $nuser->error; $errors = $nuser->errors;
  135. $db->rollback();
  136. }
  137. } else {
  138. $error = $object->error; $errors = $object->errors;
  139. }
  140. }
  141. // Confirmation desactivation
  142. if ($action == 'disable' && !empty($permissiontoadd)) {
  143. $object->fetch($id);
  144. if ($object->setstatus(0) < 0) {
  145. setEventMessages($object->error, $object->errors, 'errors');
  146. } else {
  147. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  148. exit;
  149. }
  150. }
  151. // Confirmation activation
  152. if ($action == 'enable' && !empty($permissiontoadd)) {
  153. $object->fetch($id);
  154. if ($object->setstatus(1) < 0) {
  155. setEventMessages($object->error, $object->errors, 'errors');
  156. } else {
  157. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  158. exit;
  159. }
  160. }
  161. // Add contact
  162. if ($action == 'add' && !empty($permissiontoadd)) {
  163. $db->begin();
  164. if ($canvas) {
  165. $object->canvas = $canvas;
  166. }
  167. $object->entity = (GETPOSTISSET('entity') ?GETPOST('entity', 'int') : $conf->entity);
  168. $object->socid = GETPOST("socid", 'int');
  169. $object->lastname = (string) GETPOST("lastname", 'alpha');
  170. $object->firstname = (string) GETPOST("firstname", 'alpha');
  171. $object->civility_code = (string) GETPOST("civility_code", 'alpha');
  172. $object->poste = (string) GETPOST("poste", 'alpha');
  173. $object->address = (string) GETPOST("address", 'alpha');
  174. $object->zip = (string) GETPOST("zipcode", 'alpha');
  175. $object->town = (string) GETPOST("town", 'alpha');
  176. $object->country_id = (int) GETPOST("country_id", 'int');
  177. $object->state_id = (int) GETPOST("state_id", 'int');
  178. //$object->jabberid = GETPOST("jabberid", 'alpha');
  179. //$object->skype = GETPOST("skype", 'alpha');
  180. //$object->twitter = GETPOST("twitter", 'alpha');
  181. //$object->facebook = GETPOST("facebook", 'alpha');
  182. //$object->linkedin = GETPOST("linkedin", 'alpha');
  183. $object->socialnetworks = array();
  184. if (!empty($conf->socialnetworks->enabled)) {
  185. foreach ($socialnetworks as $key => $value) {
  186. if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
  187. $object->socialnetworks[$key] = (string) GETPOST($key, 'alphanohtml');
  188. }
  189. }
  190. }
  191. $object->email = (string) GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
  192. $object->no_email = GETPOST("no_email", "int");
  193. $object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
  194. $object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
  195. $object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
  196. $object->fax = (string) GETPOST("fax", 'alpha');
  197. $object->priv = GETPOST("priv", 'int');
  198. $object->note_public = (string) GETPOST("note_public", 'restricthtml');
  199. $object->note_private = (string) GETPOST("note_private", 'restricthtml');
  200. $object->roles = GETPOST("roles", 'array');
  201. $object->statut = 1; //Default status to Actif
  202. // Note: Correct date should be completed with location to have exact GM time of birth.
  203. $object->birthday = dol_mktime(0, 0, 0, GETPOST("birthdaymonth", 'int'), GETPOST("birthdayday", 'int'), GETPOST("birthdayyear", 'int'));
  204. $object->birthday_alert = GETPOST("birthday_alert", 'alpha');
  205. //Default language
  206. $object->default_lang = GETPOST('default_lang');
  207. // Fill array 'array_options' with data from add form
  208. $ret = $extrafields->setOptionalsFromPost(null, $object);
  209. if ($ret < 0) {
  210. $error++;
  211. $action = 'create';
  212. }
  213. if (!empty($conf->mailing->enabled) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 && $object->no_email == -1 && !empty($object->email)) {
  214. $error++;
  215. $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
  216. $action = 'create';
  217. }
  218. if (!empty($object->email) && !isValidEMail($object->email)) {
  219. $langs->load("errors");
  220. $error++;
  221. $errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
  222. $action = 'create';
  223. }
  224. if (empty($object->lastname)) {
  225. $error++;
  226. $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
  227. $action = 'create';
  228. }
  229. if (empty($error)) {
  230. $id = $object->create($user);
  231. if ($id <= 0) {
  232. $error++;
  233. $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
  234. $action = 'create';
  235. }
  236. }
  237. if (empty($error)) {
  238. // Categories association
  239. $contcats = GETPOST('contcats', 'array');
  240. if (count($contcats) > 0) {
  241. $result = $object->setCategories($contcats);
  242. if ($result <= 0) {
  243. $error++;
  244. $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
  245. $action = 'create';
  246. }
  247. }
  248. }
  249. if (empty($error) && !empty($conf->mailing->enabled) && !empty($object->email)) {
  250. // Add mass emailing flag into table mailing_unsubscribe
  251. $result = $object->setNoEmail($object->no_email);
  252. if ($result < 0) {
  253. $error++;
  254. $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
  255. $action = 'create';
  256. }
  257. }
  258. if (empty($error) && $id > 0) {
  259. $db->commit();
  260. if (!empty($backtopage)) {
  261. $url = str_replace('__ID__', $id, $backtopage);
  262. } else {
  263. $url = 'card.php?id='.$id;
  264. }
  265. header("Location: ".$url);
  266. exit;
  267. } else {
  268. $db->rollback();
  269. }
  270. }
  271. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->contact->supprimer) {
  272. $result = $object->fetch($id);
  273. $object->oldcopy = clone $object;
  274. $object->old_lastname = (string) GETPOST("old_lastname", 'alpha');
  275. $object->old_firstname = (string) GETPOST("old_firstname", 'alpha');
  276. $result = $object->delete(); // TODO Add $user as first param
  277. if ($result > 0) {
  278. setEventMessages("RecordDeleted", null, 'mesgs');
  279. if ($backurlforlist) {
  280. header("Location: ".$backurlforlist);
  281. exit;
  282. } else {
  283. header("Location: ".DOL_URL_ROOT.'/contact/list.php');
  284. exit;
  285. }
  286. } else {
  287. setEventMessages($object->error, $object->errors, 'errors');
  288. }
  289. }
  290. if ($action == 'update' && empty($cancel) && !empty($permissiontoadd)) {
  291. if (!GETPOST("lastname", 'alpha')) {
  292. $error++; $errors = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
  293. $action = 'edit';
  294. }
  295. if (!empty($conf->mailing->enabled) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 && GETPOST("no_email", "int") == -1 && !empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL))) {
  296. $error++;
  297. $errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email"));
  298. $action = 'edit';
  299. }
  300. if (!empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)) && !isValidEMail(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL))) {
  301. $langs->load("errors");
  302. $error++;
  303. $errors[] = $langs->trans("ErrorBadEMail", GETPOST('email', 'alpha'));
  304. $action = 'edit';
  305. }
  306. if (!$error) {
  307. $contactid = GETPOST("contactid", 'int');
  308. $object->fetch($contactid);
  309. $object->fetchRoles($contactid);
  310. // Photo save
  311. $dir = $conf->societe->multidir_output[$object->entity]."/contact/".$object->id."/photos";
  312. $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
  313. if (GETPOST('deletephoto') && $object->photo) {
  314. $fileimg = $dir.'/'.$object->photo;
  315. $dirthumbs = $dir.'/thumbs';
  316. dol_delete_file($fileimg);
  317. dol_delete_dir_recursive($dirthumbs);
  318. $object->photo = '';
  319. }
  320. if ($file_OK) {
  321. if (image_format_supported($_FILES['photo']['name']) > 0) {
  322. dol_mkdir($dir);
  323. if (@is_dir($dir)) {
  324. $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
  325. $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
  326. if (!($result > 0)) {
  327. $errors[] = "ErrorFailedToSaveFile";
  328. } else {
  329. $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
  330. // Create thumbs
  331. $object->addThumbs($newfile);
  332. }
  333. }
  334. } else {
  335. $errors[] = "ErrorBadImageFormat";
  336. }
  337. } else {
  338. switch ($_FILES['photo']['error']) {
  339. case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
  340. case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
  341. $errors[] = "ErrorFileSizeTooLarge";
  342. break;
  343. case 3: //uploaded file was only partially uploaded
  344. $errors[] = "ErrorFilePartiallyUploaded";
  345. break;
  346. }
  347. }
  348. $object->oldcopy = clone $object;
  349. $object->old_lastname = (string) GETPOST("old_lastname", 'alpha');
  350. $object->old_firstname = (string) GETPOST("old_firstname", 'alpha');
  351. $object->socid = GETPOST("socid", 'int');
  352. $object->lastname = (string) GETPOST("lastname", 'alpha');
  353. $object->firstname = (string) GETPOST("firstname", 'alpha');
  354. $object->civility_code = (string) GETPOST("civility_code", 'alpha');
  355. $object->poste = (string) GETPOST("poste", 'alpha');
  356. $object->address = (string) GETPOST("address", 'alpha');
  357. $object->zip = (string) GETPOST("zipcode", 'alpha');
  358. $object->town = (string) GETPOST("town", 'alpha');
  359. $object->state_id = GETPOST("state_id", 'int');
  360. $object->country_id = GETPOST("country_id", 'int');
  361. $object->email = (string) GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
  362. $object->no_email = GETPOST("no_email", "int");
  363. //$object->jabberid = GETPOST("jabberid", 'alpha');
  364. //$object->skype = GETPOST("skype", 'alpha');
  365. //$object->twitter = GETPOST("twitter", 'alpha');
  366. //$object->facebook = GETPOST("facebook", 'alpha');
  367. //$object->linkedin = GETPOST("linkedin", 'alpha');
  368. $object->socialnetworks = array();
  369. if (!empty($conf->socialnetworks->enabled)) {
  370. foreach ($socialnetworks as $key => $value) {
  371. if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
  372. $object->socialnetworks[$key] = (string) GETPOST($key, 'alphanohtml');
  373. }
  374. }
  375. }
  376. $object->phone_pro = (string) GETPOST("phone_pro", 'alpha');
  377. $object->phone_perso = (string) GETPOST("phone_perso", 'alpha');
  378. $object->phone_mobile = (string) GETPOST("phone_mobile", 'alpha');
  379. $object->fax = (string) GETPOST("fax", 'alpha');
  380. $object->priv = (string) GETPOST("priv", 'int');
  381. $object->note_public = (string) GETPOST("note_public", 'restricthtml');
  382. $object->note_private = (string) GETPOST("note_private", 'restricthtml');
  383. $object->roles = GETPOST("roles", 'array'); // Note GETPOSTISSET("role") is null when combo is empty
  384. //Default language
  385. $object->default_lang = GETPOST('default_lang');
  386. // Fill array 'array_options' with data from add form
  387. $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
  388. if ($ret < 0) {
  389. $error++;
  390. }
  391. if (!$error) {
  392. $result = $object->update($contactid, $user);
  393. if ($result > 0) {
  394. // Categories association
  395. $categories = GETPOST('contcats', 'array');
  396. $object->setCategories($categories);
  397. // Update mass emailing flag into table mailing_unsubscribe
  398. if (GETPOSTISSET('no_email') && $object->email) {
  399. $no_email = GETPOST('no_email', 'int');
  400. $result = $object->setNoEmail($no_email);
  401. if ($result < 0) {
  402. setEventMessages($object->error, $object->errors, 'errors');
  403. $action = 'edit';
  404. }
  405. }
  406. $action = 'view';
  407. } else {
  408. setEventMessages($object->error, $object->errors, 'errors');
  409. $action = 'edit';
  410. }
  411. }
  412. }
  413. if (!$error && empty($errors)) {
  414. if (!empty($backtopage)) {
  415. header("Location: ".$backtopage);
  416. exit;
  417. }
  418. }
  419. }
  420. if ($action == 'setprospectcontactlevel' && !empty($permissiontoadd)) {
  421. $object->fetch($id);
  422. $object->fk_prospectlevel = GETPOST('prospect_contact_level_id', 'alpha');
  423. $result = $object->update($object->id, $user);
  424. if ($result < 0) {
  425. setEventMessages($object->error, $object->errors, 'errors');
  426. }
  427. }
  428. // set communication status
  429. if ($action == 'setstcomm' && !empty($permissiontoadd)) {
  430. $object->fetch($id);
  431. $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
  432. $result = $object->update($object->id, $user);
  433. if ($result < 0) {
  434. setEventMessages($object->error, $object->errors, 'errors');
  435. }
  436. }
  437. // Update extrafields
  438. if ($action == "update_extras" && !empty($permissiontoadd)) {
  439. $object->fetch(GETPOST('id', 'int'));
  440. $attributekey = GETPOST('attribute', 'alpha');
  441. $attributekeylong = 'options_'.$attributekey;
  442. if (GETPOSTISSET($attributekeylong.'day') && GETPOSTISSET($attributekeylong.'month') && GETPOSTISSET($attributekeylong.'year')) {
  443. // This is properties of a date
  444. $object->array_options['options_'.$attributekey] = dol_mktime(GETPOST($attributekeylong.'hour', 'int'), GETPOST($attributekeylong.'min', 'int'), GETPOST($attributekeylong.'sec', 'int'), GETPOST($attributekeylong.'month', 'int'), GETPOST($attributekeylong.'day', 'int'), GETPOST($attributekeylong.'year', 'int'));
  445. //var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit;
  446. } else {
  447. $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, 'alpha');
  448. }
  449. $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
  450. if ($result > 0) {
  451. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  452. $action = 'view';
  453. } else {
  454. setEventMessages($object->error, $object->errors, 'errors');
  455. $action = 'edit_extras';
  456. }
  457. }
  458. // Update extrafields
  459. if ($action == 'update_extras' && ! empty($user->rights->societe->contact->creer)) {
  460. $object->oldcopy = dol_clone($object);
  461. // Fill array 'array_options' with data from update form
  462. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  463. if ($ret < 0) {
  464. $error++;
  465. }
  466. if (!$error) {
  467. $result = $object->insertExtraFields('CONTACT_MODIFY');
  468. if ($result < 0) {
  469. setEventMessages($object->error, $object->errors, 'errors');
  470. $error++;
  471. }
  472. }
  473. if ($error) {
  474. $action = 'edit_extras';
  475. }
  476. }
  477. // Actions to send emails
  478. $triggersendname = 'CONTACT_SENTBYMAIL';
  479. $paramname = 'id';
  480. $mode = 'emailfromcontact';
  481. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  482. }
  483. /*
  484. * View
  485. */
  486. $form = new Form($db);
  487. $formadmin = new FormAdmin($db);
  488. $formcompany = new FormCompany($db);
  489. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  490. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) {
  491. $title = $object->lastname;
  492. }
  493. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  494. llxHeader('', $title, $help_url);
  495. $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  496. $objsoc = new Societe($db);
  497. if ($socid > 0) {
  498. $objsoc->fetch($socid);
  499. }
  500. if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
  501. // -----------------------------------------
  502. // When used with CANVAS
  503. // -----------------------------------------
  504. if (empty($object->error) && $id) {
  505. $object = new Contact($db);
  506. $result = $object->fetch($id);
  507. if ($result <= 0) {
  508. dol_print_error('', $object->error);
  509. }
  510. }
  511. $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
  512. $objcanvas->display_canvas($action); // Show template
  513. } else {
  514. // -----------------------------------------
  515. // When used in standard mode
  516. // -----------------------------------------
  517. // Confirm deleting contact
  518. if ($user->rights->societe->contact->supprimer) {
  519. if ($action == 'delete') {
  520. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id.($backtopage ? '&backtopage='.$backtopage : ''), $langs->trans("DeleteContact"), $langs->trans("ConfirmDeleteContact"), "confirm_delete", '', 0, 1);
  521. }
  522. }
  523. /*
  524. * Onglets
  525. */
  526. $head = array();
  527. if ($id > 0) {
  528. // Si edition contact deja existant
  529. $object = new Contact($db);
  530. $res = $object->fetch($id, $user);
  531. if ($res < 0) {
  532. setEventMessages($object->error, $object->errors, 'errors');
  533. }
  534. $object->fetchRoles();
  535. // Show tabs
  536. $head = contact_prepare_head($object);
  537. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  538. }
  539. if ($user->rights->societe->contact->creer) {
  540. if ($action == 'create') {
  541. /*
  542. * Fiche en mode creation
  543. */
  544. $object->canvas = $canvas;
  545. $object->state_id = GETPOST("state_id", "int");
  546. // We set country_id, country_code and label for the selected country
  547. $object->country_id = GETPOST("country_id") ? GETPOST("country_id", "int") : (empty($objsoc->country_id) ? $mysoc->country_id : $objsoc->country_id);
  548. if ($object->country_id) {
  549. $tmparray = getCountry($object->country_id, 'all');
  550. $object->country_code = $tmparray['code'];
  551. $object->country = $tmparray['label'];
  552. }
  553. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("NewContact") : $langs->trans("NewContactAddress"));
  554. $linkback = '';
  555. print load_fiche_titre($title, $linkback, 'address');
  556. // Show errors
  557. dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
  558. if ($conf->use_javascript_ajax) {
  559. print "\n".'<script type="text/javascript">'."\n";
  560. print 'jQuery(document).ready(function () {
  561. jQuery("#selectcountry_id").change(function() {
  562. document.formsoc.action.value="create";
  563. document.formsoc.submit();
  564. });
  565. $("#copyaddressfromsoc").click(function() {
  566. $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
  567. $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
  568. $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
  569. console.log("Set state_id to '.dol_escape_js($objsoc->state_id).'");
  570. $(\'select[name="state_id"]\').val("'.dol_escape_js($objsoc->state_id).'").trigger("change");
  571. /* set country at end because it will trigger page refresh */
  572. console.log("Set country id to '.dol_escape_js($objsoc->country_id).'");
  573. $(\'select[name="country_id"]\').val("'.dol_escape_js($objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
  574. });
  575. })'."\n";
  576. print '</script>'."\n";
  577. }
  578. print '<form method="post" name="formsoc" action="'.$_SERVER["PHP_SELF"].'">';
  579. print '<input type="hidden" name="token" value="'.newToken().'">';
  580. print '<input type="hidden" name="action" value="add">';
  581. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  582. if (!empty($objsoc)) {
  583. print '<input type="hidden" name="entity" value="'.$objsoc->entity.'">';
  584. }
  585. print dol_get_fiche_head($head, 'card', '', 0, '');
  586. print '<table class="border centpercent">';
  587. // Name
  588. print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
  589. print '<td colspan="3"><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>';
  590. print '</tr>';
  591. print '<tr>';
  592. print '<td><label for="firstname">';
  593. print $form->textwithpicto($langs->trans("Firstname"), $langs->trans("KeepEmptyIfGenericAddress")).'</label></td>';
  594. print '<td colspan="3"><input name="firstname" id="firstname"type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("firstname", 'alpha') ?GETPOST("firstname", 'alpha') : $object->firstname).'"></td>';
  595. print '</tr>';
  596. // Company
  597. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  598. if ($socid > 0) {
  599. print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
  600. print '<td colspan="3" class="maxwidthonsmartphone">';
  601. print $objsoc->getNomUrl(1, 'contact');
  602. print '</td>';
  603. print '<input type="hidden" name="socid" id="socid" value="'.$objsoc->id.'">';
  604. print '</td></tr>';
  605. } else {
  606. print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  607. print img_picto('', 'company').$form->select_company($socid, 'socid', '', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
  608. print '</td></tr>';
  609. }
  610. }
  611. // Civility
  612. print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
  613. print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'alpha') : $object->civility_code, 'civility_code');
  614. print '</td></tr>';
  615. // Job position
  616. print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
  617. print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="255" value="'.dol_escape_htmltag(GETPOSTISSET("poste") ?GETPOST("poste", 'alphanohtml') : $object->poste).'"></td>';
  618. $colspan = 3;
  619. if ($conf->use_javascript_ajax && $socid > 0) {
  620. $colspan = 2;
  621. }
  622. // Address
  623. if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->address)) == 0) {
  624. $object->address = $objsoc->address; // Predefined with third party
  625. }
  626. print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
  627. 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>';
  628. if ($conf->use_javascript_ajax && $socid > 0) {
  629. $rowspan = 3;
  630. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  631. $rowspan++;
  632. }
  633. print '<td class="valignmiddle center" rowspan="'.$rowspan.'">';
  634. print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a>';
  635. print '</td>';
  636. }
  637. print '</tr>';
  638. // Zip / Town
  639. if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->zip)) == 0) {
  640. $object->zip = $objsoc->zip; // Predefined with third party
  641. }
  642. if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->town)) == 0) {
  643. $object->town = $objsoc->town; // Predefined with third party
  644. }
  645. print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
  646. print $formcompany->select_ziptown((GETPOST("zipcode", 'alpha') ? GETPOST("zipcode", 'alpha') : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
  647. print $formcompany->select_ziptown((GETPOST("town", 'alpha') ? GETPOST("town", 'alpha') : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
  648. print '</td></tr>';
  649. // Country
  650. print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
  651. print img_picto('', 'globe-americas', 'class="paddingrightonly"');
  652. print $form->select_country((GETPOST("country_id", 'alpha') ? GETPOST("country_id", 'alpha') : $object->country_id), 'country_id');
  653. if ($user->admin) {
  654. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  655. }
  656. print '</td></tr>';
  657. // State
  658. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  659. 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)) {
  660. print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
  661. } else {
  662. print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="'.$colspan.'" class="maxwidthonsmartphone">';
  663. }
  664. if ($object->country_id) {
  665. print img_picto('', 'state', 'class="pictofixedwidth"');
  666. print $formcompany->select_state(GETPOST("state_id", 'alpha') ? GETPOST("state_id", 'alpha') : $object->state_id, $object->country_code, 'state_id');
  667. } else {
  668. print $countrynotdefined;
  669. }
  670. print '</td></tr>';
  671. }
  672. if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->phone_pro)) == 0) {
  673. $object->phone_pro = $objsoc->phone; // Predefined with third party
  674. }
  675. if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->fax)) == 0) {
  676. $object->fax = $objsoc->fax; // Predefined with third party
  677. }
  678. // Phone / Fax
  679. print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', '', $object, 0).'</td>';
  680. print '<td>';
  681. print img_picto('', 'object_phoning');
  682. print '<input type="text" name="phone_pro" id="phone_pro" class="maxwidth200" value="'.(GETPOSTISSET('phone_pro') ? GETPOST('phone_pro', 'alpha') : $object->phone_pro).'"></td>';
  683. if ($conf->browser->layout == 'phone') {
  684. print '</tr><tr>';
  685. }
  686. print '<td>'.$form->editfieldkey('PhonePerso', 'phone_perso', '', $object, 0).'</td>';
  687. print '<td>';
  688. print img_picto('', 'object_phoning');
  689. print '<input type="text" name="phone_perso" id="phone_perso" class="maxwidth200" value="'.(GETPOSTISSET('phone_perso') ? GETPOST('phone_perso', 'alpha') : $object->phone_perso).'"></td></tr>';
  690. print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', '', $object, 0).'</td>';
  691. print '<td>';
  692. print img_picto('', 'object_phoning_mobile');
  693. print '<input type="text" name="phone_mobile" id="phone_mobile" class="maxwidth200" value="'.(GETPOSTISSET('phone_mobile') ? GETPOST('phone_mobile', 'alpha') : $object->phone_mobile).'"></td>';
  694. if ($conf->browser->layout == 'phone') {
  695. print '</tr><tr>';
  696. }
  697. print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
  698. print '<td>';
  699. print img_picto('', 'object_phoning_fax');
  700. print '<input type="text" name="fax" id="fax" class="maxwidth200" value="'.(GETPOSTISSET('fax') ? GETPOST('fax', 'alpha') : $object->fax).'"></td>';
  701. print '</tr>';
  702. if (((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || !empty($conf->global->CONTACT_USE_COMPANY_ADDRESS)) && dol_strlen(trim($object->email)) == 0) {
  703. $object->email = $objsoc->email; // Predefined with third party
  704. }
  705. // Email
  706. print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '').'</td>';
  707. print '<td>';
  708. print img_picto('', 'object_email');
  709. print '<input type="text" name="email" id="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alpha') : $object->email).'"></td>';
  710. print '</tr>';
  711. // Unsubscribe
  712. if (!empty($conf->mailing->enabled)) {
  713. if ($conf->use_javascript_ajax && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
  714. print "\n".'<script type="text/javascript">'."\n";
  715. print '$(document).ready(function () {
  716. $("#email").keyup(function() {
  717. if ($(this).val()!="") {
  718. $(".noemail").addClass("fieldrequired");
  719. } else {
  720. $(".noemail").removeClass("fieldrequired");
  721. }
  722. });
  723. })'."\n";
  724. print '</script>'."\n";
  725. }
  726. if (!GETPOSTISSET("no_email") && !empty($object->email)) {
  727. $result = $object->getNoEmail();
  728. if ($result < 0) {
  729. setEventMessages($object->error, $object->errors, 'errors');
  730. }
  731. }
  732. print '<tr>';
  733. print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
  734. print '<td>';
  735. print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS), 1, false, ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2));
  736. print '</td>';
  737. print '</tr>';
  738. }
  739. if (!empty($conf->socialnetworks->enabled)) {
  740. foreach ($socialnetworks as $key => $value) {
  741. if ($value['active']) {
  742. print '<tr>';
  743. print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
  744. print '<td colspan="3">';
  745. if (!empty($value['icon'])) {
  746. print '<span class="fa '.$value['icon'].'"></span>';
  747. }
  748. print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET($key) ?GETPOST($key, 'alphanohtml') : (!empty($object->socialnetworks[$key]) ? $object->socialnetworks[$key] : "")).'">';
  749. print '</td>';
  750. print '</tr>';
  751. } elseif (!empty($object->socialnetworks[$key])) {
  752. print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
  753. }
  754. }
  755. }
  756. // Visibility
  757. print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
  758. $selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
  759. print $form->selectarray('priv', $selectarray, (GETPOST("priv", 'alpha') ?GETPOST("priv", 'alpha') : $object->priv), 0);
  760. print '</td></tr>';
  761. //Default language
  762. if (!empty($conf->global->MAIN_MULTILANGS)) {
  763. print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
  764. print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language(GETPOST('default_lang', 'alpha') ? GETPOST('default_lang', 'alpha') : ($object->default_lang ? $object->default_lang : ''), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth200onsmartphone');
  765. print '</td>';
  766. print '</tr>';
  767. }
  768. // Categories
  769. if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
  770. print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td><td colspan="3">';
  771. $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, null, 'parent', null, null, 1);
  772. print img_picto('', 'category').$form->multiselectarray('contcats', $cate_arbo, GETPOST('contcats', 'array'), null, null, null, null, '90%');
  773. print "</td></tr>";
  774. }
  775. // Contact by default
  776. if (!empty($socid)) {
  777. print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
  778. print '<td colspan="3">';
  779. $contactType = $object->listeTypeContacts('external', '', 1);
  780. print $form->multiselectarray('roles', $contactType, array(), 0, 0, 'minwidth500');
  781. print '</td></tr>';
  782. }
  783. // Other attributes
  784. $parameters = array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3, 'colspanvalue' => 3);
  785. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  786. print "</table><br>";
  787. print '<hr style="margin-bottom: 20px">';
  788. // Add personnal information
  789. print load_fiche_titre('<div class="comboperso">'.$langs->trans("PersonalInformations").'</div>', '', '');
  790. print '<table class="border centpercent">';
  791. // Date To Birth
  792. print '<tr><td><label for="birthday">'.$langs->trans("DateOfBirth").'</label></td><td>';
  793. $form = new Form($db);
  794. if ($object->birthday) {
  795. print $form->selectDate($object->birthday, 'birthday', 0, 0, 0, "perso", 1, 0);
  796. } else {
  797. print $form->selectDate('', 'birthday', 0, 0, 1, "perso", 1, 0);
  798. }
  799. print '</td>';
  800. print '<td><label for="birthday_alert">'.$langs->trans("Alert").'</label>: ';
  801. if (!empty($object->birthday_alert)) {
  802. print '<input type="checkbox" name="birthday_alert" id="birthday_alert" checked>';
  803. } else {
  804. print '<input type="checkbox" name="birthday_alert" id="birthday_alert">';
  805. }
  806. print '</td>';
  807. print '</tr>';
  808. print "</table>";
  809. print dol_get_fiche_end();
  810. print $form->buttonsSaveCancel("Add");
  811. print "</form>";
  812. } elseif ($action == 'edit' && !empty($id)) {
  813. /*
  814. * Fiche en mode edition
  815. */
  816. // We set country_id, and country_code label of the chosen country
  817. if (GETPOSTISSET("country_id") || $object->country_id) {
  818. $tmparray = getCountry($object->country_id, 'all');
  819. $object->country_code = $tmparray['code'];
  820. $object->country = $tmparray['label'];
  821. }
  822. $objsoc = new Societe($db);
  823. $objsoc->fetch($object->socid);
  824. // Show errors
  825. dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
  826. if ($conf->use_javascript_ajax) {
  827. print "\n".'<script type="text/javascript">'."\n";
  828. print 'jQuery(document).ready(function () {
  829. jQuery("#selectcountry_id").change(function() {
  830. document.formsoc.action.value="edit";
  831. document.formsoc.submit();
  832. });
  833. $("#copyaddressfromsoc").click(function() {
  834. $(\'textarea[name="address"]\').val("'.dol_escape_js($objsoc->address).'");
  835. $(\'input[name="zipcode"]\').val("'.dol_escape_js($objsoc->zip).'");
  836. $(\'input[name="town"]\').val("'.dol_escape_js($objsoc->town).'");
  837. console.log("Set state_id to '.dol_escape_js($objsoc->state_id).'");
  838. $(\'select[name="state_id"]\').val("'.dol_escape_js($objsoc->state_id).'").trigger("change");
  839. /* set country at end because it will trigger page refresh */
  840. console.log("Set country id to '.dol_escape_js($objsoc->country_id).'");
  841. $(\'select[name="country_id"]\').val("'.dol_escape_js($objsoc->country_id).'").trigger("change"); /* trigger required to update select2 components */
  842. });
  843. })'."\n";
  844. print '</script>'."\n";
  845. }
  846. print '<form enctype="multipart/form-data" method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" name="formsoc">';
  847. print '<input type="hidden" name="token" value="'.newToken().'">';
  848. print '<input type="hidden" name="id" value="'.$id.'">';
  849. print '<input type="hidden" name="action" value="update">';
  850. print '<input type="hidden" name="contactid" value="'.$object->id.'">';
  851. print '<input type="hidden" name="old_lastname" value="'.$object->lastname.'">';
  852. print '<input type="hidden" name="old_firstname" value="'.$object->firstname.'">';
  853. if (!empty($backtopage)) {
  854. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  855. }
  856. print dol_get_fiche_head($head, 'card', $title, 0, 'contact');
  857. print '<table class="border centpercent">';
  858. // Ref/ID
  859. if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
  860. print '<tr><td>'.$langs->trans("ID").'</td><td colspan="3">';
  861. print $object->ref;
  862. print '</td></tr>';
  863. }
  864. // Lastname
  865. print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
  866. print '<td colspan="3"><input name="lastname" id="lastname" type="text" class="minwidth200" maxlength="80" value="'.(GETPOSTISSET("lastname") ? GETPOST("lastname") : $object->lastname).'" autofocus="autofocus"></td>';
  867. print '</tr>';
  868. print '<tr>';
  869. // Firstname
  870. print '<td><label for="firstname">'.$langs->trans("Firstname").'</label></td>';
  871. print '<td colspan="3"><input name="firstname" id="firstname" type="text" class="minwidth200" maxlength="80" value="'.(GETPOSTISSET("firstname") ? GETPOST("firstname") : $object->firstname).'"></td>';
  872. print '</tr>';
  873. // Company
  874. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  875. print '<tr><td><label for="socid">'.$langs->trans("ThirdParty").'</label></td>';
  876. print '<td colspan="3" class="maxwidthonsmartphone">';
  877. print img_picto('', 'company').$form->select_company(GETPOST('socid', 'int') ?GETPOST('socid', 'int') : ($object->socid ? $object->socid : -1), 'socid', '', $langs->trans("SelectThirdParty"));
  878. print '</td>';
  879. print '</tr>';
  880. }
  881. // Civility
  882. print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td colspan="3">';
  883. print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", "aZ09") : $object->civility_code, 'civility_code');
  884. print '</td></tr>';
  885. // Job position
  886. print '<tr><td><label for="title">'.$langs->trans("PostOrFunction").'</label></td>';
  887. print '<td colspan="3"><input name="poste" id="title" type="text" class="minwidth100" maxlength="255" value="'.dol_escape_htmltag(GETPOSTISSET("poste") ? GETPOST("poste", 'alphanohtml') : $object->poste).'"></td></tr>';
  888. // Address
  889. print '<tr><td><label for="address">'.$langs->trans("Address").'</label></td>';
  890. print '<td colspan="3">';
  891. print '<div class="paddingrightonly valignmiddle inline-block quatrevingtpercent">';
  892. print '<textarea class="flat minwidth200 centpercent" name="address" id="address">'.(GETPOSTISSET("address") ? GETPOST("address", 'alphanohtml') : $object->address).'</textarea>';
  893. print '</div><div class="paddingrightonly valignmiddle inline-block">';
  894. if ($conf->use_javascript_ajax) {
  895. print '<a href="#" id="copyaddressfromsoc">'.$langs->trans('CopyAddressFromSoc').'</a><br>';
  896. }
  897. print '</div>';
  898. print '</td>';
  899. // Zip / Town
  900. print '<tr><td><label for="zipcode">'.$langs->trans("Zip").'</label> / <label for="town">'.$langs->trans("Town").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  901. print $formcompany->select_ziptown((GETPOSTISSET("zipcode") ? GETPOST("zipcode") : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6).'&nbsp;';
  902. print $formcompany->select_ziptown((GETPOSTISSET("town") ? GETPOST("town") : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
  903. print '</td></tr>';
  904. // Country
  905. print '<tr><td><label for="selectcountry_id">'.$langs->trans("Country").'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  906. print img_picto('', 'globe-americas', 'class="paddingrightonly"');
  907. print $form->select_country(GETPOSTISSET("country_id") ? GETPOST("country_id") : $object->country_id, 'country_id');
  908. if ($user->admin) {
  909. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  910. }
  911. print '</td></tr>';
  912. // State
  913. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  914. 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)) {
  915. print '<tr><td><label for="state_id">'.$langs->trans('Region-State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  916. } else {
  917. print '<tr><td><label for="state_id">'.$langs->trans('State').'</label></td><td colspan="3" class="maxwidthonsmartphone">';
  918. }
  919. print img_picto('', 'state', 'class="pictofixedwidth"');
  920. print $formcompany->select_state(GETPOSTISSET('state_id') ? GETPOST('state_id', 'alpha') : $object->state_id, $object->country_code, 'state_id');
  921. print '</td></tr>';
  922. }
  923. // Phone
  924. print '<tr><td>'.$form->editfieldkey('PhonePro', 'phone_pro', GETPOST('phone_pro', 'alpha'), $object, 0).'</td>';
  925. print '<td>';
  926. print img_picto('', 'object_phoning');
  927. print '<input type="text" name="phone_pro" id="phone_pro" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_pro') ?GETPOST('phone_pro', 'alpha') : $object->phone_pro).'"></td>';
  928. print '<td>'.$form->editfieldkey('PhonePerso', 'fax', GETPOST('phone_perso', 'alpha'), $object, 0).'</td>';
  929. print '<td>';
  930. print img_picto('', 'object_phoning');
  931. print '<input type="text" name="phone_perso" id="phone_perso" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_perso') ?GETPOST('phone_perso', 'alpha') : $object->phone_perso).'"></td></tr>';
  932. print '<tr><td>'.$form->editfieldkey('PhoneMobile', 'phone_mobile', GETPOST('phone_mobile', 'alpha'), $object, 0, 'string', '').'</td>';
  933. print '<td>';
  934. print img_picto('', 'object_phoning_mobile');
  935. print '<input type="text" name="phone_mobile" id="phone_mobile" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_mobile') ?GETPOST('phone_mobile', 'alpha') : $object->phone_mobile).'"></td>';
  936. print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
  937. print '<td>';
  938. print img_picto('', 'object_phoning_fax');
  939. print '<input type="text" name="fax" id="fax" class="maxwidth200" maxlength="80" value="'.(GETPOSTISSET('phone_fax') ?GETPOST('phone_fax', 'alpha') : $object->fax).'"></td></tr>';
  940. // EMail
  941. print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (!empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
  942. print '<td>';
  943. print img_picto('', 'object_email');
  944. print '<input type="text" name="email" id="email" class="maxwidth100onsmartphone quatrevingtpercent" value="'.(GETPOSTISSET('email') ?GETPOST('email', 'alpha') : $object->email).'"></td>';
  945. if (!empty($conf->mailing->enabled)) {
  946. $langs->load("mails");
  947. print '<td class="nowrap">'.$langs->trans("NbOfEMailingsSend").'</td>';
  948. print '<td>'.$object->getNbOfEMailings().'</td>';
  949. } else {
  950. print '<td colspan="2"></td>';
  951. }
  952. print '</tr>';
  953. // Unsubscribe
  954. if (!empty($conf->mailing->enabled)) {
  955. if ($conf->use_javascript_ajax && isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
  956. print "\n".'<script type="text/javascript">'."\n";
  957. print '
  958. jQuery(document).ready(function () {
  959. function init_check_no_email(input) {
  960. if (input.val()!="") {
  961. $(".noemail").addClass("fieldrequired");
  962. } else {
  963. $(".noemail").removeClass("fieldrequired");
  964. }
  965. }
  966. $("#email").keyup(function() {
  967. init_check_no_email($(this));
  968. });
  969. init_check_no_email($("#email"));
  970. })'."\n";
  971. print '</script>'."\n";
  972. }
  973. if (!GETPOSTISSET("no_email") && !empty($object->email)) {
  974. $result = $object->getNoEmail();
  975. if ($result < 0) {
  976. setEventMessages($object->error, $object->errors, 'errors');
  977. }
  978. }
  979. print '<tr>';
  980. print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
  981. print '<td>';
  982. $useempty = (isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2));
  983. print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $object->no_email), 1, false, $useempty);
  984. print '</td>';
  985. print '</tr>';
  986. }
  987. if (!empty($conf->socialnetworks->enabled)) {
  988. foreach ($socialnetworks as $key => $value) {
  989. if ($value['active']) {
  990. print '<tr>';
  991. print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
  992. print '<td colspan="3">';
  993. if (!empty($value['icon'])) {
  994. print '<span class="fa '.$value['icon'].'"></span>';
  995. }
  996. print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET($key) ?GETPOST($key, 'alphanohtml') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key])).'">';
  997. print '</td>';
  998. print '</tr>';
  999. } elseif (!empty($object->socialnetworks[$key])) {
  1000. print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
  1001. }
  1002. }
  1003. }
  1004. // Visibility
  1005. print '<tr><td><label for="priv">'.$langs->trans("ContactVisibility").'</label></td><td colspan="3">';
  1006. $selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
  1007. print $form->selectarray('priv', $selectarray, $object->priv, 0);
  1008. print '</td></tr>';
  1009. //Default language
  1010. if (!empty($conf->global->MAIN_MULTILANGS)) {
  1011. print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
  1012. print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language(GETPOST('default_lang', 'alpha') ? GETPOST('default_lang', 'alpha') : ($object->default_lang ? $object->default_lang : ''), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth200onsmartphone');
  1013. print '</td>';
  1014. print '</tr>';
  1015. }
  1016. // Note Public
  1017. print '<tr><td class="tdtop"><label for="note_public">'.$langs->trans("NotePublic").'</label></td><td colspan="3">';
  1018. $doleditor = new DolEditor('note_public', $object->note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%');
  1019. print $doleditor->Create(1);
  1020. print '</td></tr>';
  1021. // Note Private
  1022. print '<tr><td class="tdtop"><label for="note_private">'.$langs->trans("NotePrivate").'</label></td><td colspan="3">';
  1023. $doleditor = new DolEditor('note_private', $object->note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%');
  1024. print $doleditor->Create(1);
  1025. print '</td></tr>';
  1026. // Status
  1027. print '<tr><td>'.$langs->trans("Status").'</td>';
  1028. print '<td colspan="3">';
  1029. print $object->getLibStatut(4);
  1030. print '</td></tr>';
  1031. // Categories
  1032. if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
  1033. $arrayselected = array();
  1034. print '<tr><td>'.$form->editfieldkey('Categories', 'contcats', '', $object, 0).'</td>';
  1035. print '<td colspan="3">';
  1036. $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, null, null, null, null, 1);
  1037. $c = new Categorie($db);
  1038. $cats = $c->containing($object->id, 'contact');
  1039. foreach ($cats as $cat) {
  1040. $arrayselected[] = $cat->id;
  1041. }
  1042. print img_picto('', 'category').$form->multiselectarray('contcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
  1043. print "</td></tr>";
  1044. }
  1045. // Contact by default
  1046. if (!empty($object->socid)) {
  1047. print '<tr><td>'.$langs->trans("ContactByDefaultFor").'</td>';
  1048. print '<td colspan="3">';
  1049. print $formcompany->showRoles("roles", $object, 'edit', $object->roles);
  1050. print '</td></tr>';
  1051. }
  1052. // Other attributes
  1053. $parameters = array('colspan' => ' colspan="3"', 'cols'=> '3', 'colspanvalue'=> '3');
  1054. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  1055. $object->load_ref_elements();
  1056. if (!empty($conf->commande->enabled)) {
  1057. print '<tr><td>'.$langs->trans("ContactForOrders").'</td><td colspan="3">';
  1058. print $object->ref_commande ? $object->ref_commande : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyOrder").'</span>');
  1059. print '</td></tr>';
  1060. }
  1061. if (!empty($conf->propal->enabled)) {
  1062. print '<tr><td>'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
  1063. print $object->ref_propal ? $object->ref_propal : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyProposal").'</span>');
  1064. print '</td></tr>';
  1065. }
  1066. if (!empty($conf->contrat->enabled)) {
  1067. print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
  1068. print $object->ref_contrat ? $object->ref_contrat : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyContract").'</span>');
  1069. print '</td></tr>';
  1070. }
  1071. if (isModEnabled('facture')) {
  1072. print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
  1073. print $object->ref_facturation ? $object->ref_facturation : ('<span class="opacitymedium">'.$langs->trans("NoContactForAnyInvoice").'</span>');
  1074. print '</td></tr>';
  1075. }
  1076. // Login Dolibarr
  1077. print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
  1078. if ($object->user_id) {
  1079. $dolibarr_user = new User($db);
  1080. $result = $dolibarr_user->fetch($object->user_id);
  1081. print $dolibarr_user->getLoginUrl(1);
  1082. } else {
  1083. print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
  1084. }
  1085. print '</td></tr>';
  1086. // Photo
  1087. print '<tr>';
  1088. print '<td>'.$langs->trans("PhotoFile").'</td>';
  1089. print '<td colspan="3">';
  1090. if ($object->photo) {
  1091. print $form->showphoto('contact', $object);
  1092. print "<br>\n";
  1093. }
  1094. print '<table class="nobordernopadding">';
  1095. if ($object->photo) {
  1096. print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
  1097. }
  1098. //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
  1099. print '<tr><td>';
  1100. $maxfilesizearray = getMaxFileSizeArray();
  1101. $maxmin = $maxfilesizearray['maxmin'];
  1102. if ($maxmin > 0) {
  1103. print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
  1104. }
  1105. print '<input type="file" class="flat" name="photo" id="photoinput">';
  1106. print '</td></tr>';
  1107. print '</table>';
  1108. print '</td>';
  1109. print '</tr>';
  1110. print '</table>';
  1111. print dol_get_fiche_end();
  1112. print $form->buttonsSaveCancel();
  1113. print "</form>";
  1114. }
  1115. }
  1116. // Select mail models is same action as presend
  1117. if (GETPOST('modelselected', 'alpha')) {
  1118. $action = 'presend';
  1119. }
  1120. // View mode
  1121. if (!empty($id) && $action != 'edit' && $action != 'create') {
  1122. $objsoc = new Societe($db);
  1123. // Show errors
  1124. dol_htmloutput_errors(is_numeric($error) ? '' : $error, $errors);
  1125. print dol_get_fiche_head($head, 'card', $title, -1, 'contact');
  1126. if ($action == 'create_user') {
  1127. // Full firstname and lastname separated with a dot : firstname.lastname
  1128. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1129. $login = dol_buildlogin($object->lastname, $object->firstname);
  1130. $generated_password = '';
  1131. if (!$ldap_sid) { // TODO ldap_sid ?
  1132. require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  1133. $generated_password = getRandomPassword(false);
  1134. }
  1135. $password = $generated_password;
  1136. // Create a form array
  1137. $formquestion = array(
  1138. array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login),
  1139. array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password),
  1140. //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')))
  1141. );
  1142. $text = $langs->trans("ConfirmCreateContact").'<br>';
  1143. if (!empty($conf->societe->enabled)) {
  1144. if ($object->socid > 0) {
  1145. $text .= $langs->trans("UserWillBeExternalUser");
  1146. } else {
  1147. $text .= $langs->trans("UserWillBeInternalUser");
  1148. }
  1149. }
  1150. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes');
  1151. }
  1152. $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1153. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
  1154. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  1155. $morehtmlref .= '</a>';
  1156. $morehtmlref .= '<div class="refidno">';
  1157. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  1158. $objsoc->fetch($object->socid);
  1159. // Thirdparty
  1160. $morehtmlref .= $langs->trans('ThirdParty').' : ';
  1161. if ($objsoc->id > 0) {
  1162. $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
  1163. } else {
  1164. $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
  1165. }
  1166. }
  1167. $morehtmlref .= '</div>';
  1168. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref);
  1169. print '<div class="fichecenter">';
  1170. print '<div class="fichehalfleft">';
  1171. print '<div class="underbanner clearboth"></div>';
  1172. print '<table class="border tableforfield" width="100%">';
  1173. // Civility
  1174. print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td>';
  1175. print $object->getCivilityLabel();
  1176. print '</td></tr>';
  1177. // Job / position
  1178. print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td>'.$object->poste.'</td></tr>';
  1179. // Email
  1180. if (!empty($conf->mailing->enabled)) {
  1181. $langs->load("mails");
  1182. print '<tr><td>'.$langs->trans("NbOfEMailingsSend").'</td>';
  1183. print '<td><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td></tr>';
  1184. }
  1185. // Unsubscribe opt-out
  1186. if (!empty($conf->mailing->enabled)) {
  1187. $result = $object->getNoEmail();
  1188. if ($result < 0) {
  1189. setEventMessages($object->error, $object->errors, 'errors');
  1190. }
  1191. print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
  1192. if ($object->email) {
  1193. print yn($object->no_email);
  1194. } else {
  1195. print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
  1196. }
  1197. print '</td></tr>';
  1198. }
  1199. // Default language
  1200. if (!empty($conf->global->MAIN_MULTILANGS)) {
  1201. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1202. print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
  1203. //$s=picto_from_langcode($object->default_lang);
  1204. //print ($s?$s.' ':'');
  1205. $langs->load("languages");
  1206. $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
  1207. print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
  1208. print $labellang;
  1209. print '</td></tr>';
  1210. }
  1211. print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td>';
  1212. print $object->LibPubPriv($object->priv);
  1213. print '</td></tr>';
  1214. print '</table>';
  1215. print '</div>';
  1216. $object->fetch_thirdparty();
  1217. if (!empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
  1218. if ($object->thirdparty->client == 2 || $object->thirdparty->client == 3) {
  1219. print '<br>';
  1220. print '<div class="underbanner clearboth"></div>';
  1221. print '<table class="border" width="100%">';
  1222. // Level of prospect
  1223. print '<tr><td class="titlefield nowrap">';
  1224. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  1225. print $langs->trans('ProspectLevel');
  1226. print '<td>';
  1227. if ($action != 'editlevel' && $user->rights->societe->contact->creer) {
  1228. print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlevel&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('Modify'), 1).'</a></td>';
  1229. }
  1230. print '</tr></table>';
  1231. print '</td><td>';
  1232. if ($action == 'editlevel') {
  1233. $formcompany->formProspectContactLevel($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_prospectlevel, 'prospect_contact_level_id', 1);
  1234. } else {
  1235. print $object->getLibProspLevel();
  1236. }
  1237. print "</td>";
  1238. print '</tr>';
  1239. // Status of prospection
  1240. $object->loadCacheOfProspStatus();
  1241. print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
  1242. print ' &nbsp; &nbsp; ';
  1243. print '<div class="floatright">';
  1244. foreach ($object->cacheprospectstatus as $key => $val) {
  1245. $titlealt = 'default';
  1246. if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
  1247. $titlealt = $val['label'];
  1248. }
  1249. if ($object->stcomm_id != $val['id']) {
  1250. print '<a class="pictosubstatus" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&stcomm='.urlencode($val['code']).'&action=setstcomm&token='.newToken().'">'.img_action($titlealt, $val['code'], $val['picto']).'</a>';
  1251. }
  1252. }
  1253. print '</div></td></tr>';
  1254. print "</table>";
  1255. print '</div>';
  1256. }
  1257. }
  1258. print '<div class="fichehalfright">';
  1259. print '<div class="underbanner clearboth"></div>';
  1260. print '<table class="border tableforfield centpercent">';
  1261. // Categories
  1262. if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
  1263. print '<tr><td class="titlefield">'.$langs->trans("Categories").'</td>';
  1264. print '<td colspan="3">';
  1265. print $form->showCategories($object->id, Categorie::TYPE_CONTACT, 1);
  1266. print '</td></tr>';
  1267. }
  1268. if (!empty($object->socid)) {
  1269. print '<tr><td class="titlefield">'.$langs->trans("ContactByDefaultFor").'</td>';
  1270. print '<td colspan="3">';
  1271. print $formcompany->showRoles("roles", $object, 'view', $object->roles);
  1272. print '</td></tr>';
  1273. }
  1274. // Other attributes
  1275. $cols = 3;
  1276. $parameters = array('socid'=>$socid);
  1277. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1278. $object->load_ref_elements();
  1279. if (!empty($conf->propal->enabled)) {
  1280. print '<tr><td class="titlefield">'.$langs->trans("ContactForProposals").'</td><td colspan="3">';
  1281. print $object->ref_propal ? $object->ref_propal : $langs->trans("NoContactForAnyProposal");
  1282. print '</td></tr>';
  1283. }
  1284. if (!empty($conf->commande->enabled) || !empty($conf->expedition->enabled)) {
  1285. print '<tr><td>';
  1286. if (!empty($conf->expedition->enabled)) {
  1287. print $langs->trans("ContactForOrdersOrShipments");
  1288. } else {
  1289. print $langs->trans("ContactForOrders");
  1290. }
  1291. print '</td><td colspan="3">';
  1292. $none = $langs->trans("NoContactForAnyOrder");
  1293. if (!empty($conf->expedition->enabled)) {
  1294. $none = $langs->trans("NoContactForAnyOrderOrShipments");
  1295. }
  1296. print $object->ref_commande ? $object->ref_commande : $none;
  1297. print '</td></tr>';
  1298. }
  1299. if (!empty($conf->contrat->enabled)) {
  1300. print '<tr><td>'.$langs->trans("ContactForContracts").'</td><td colspan="3">';
  1301. print $object->ref_contrat ? $object->ref_contrat : $langs->trans("NoContactForAnyContract");
  1302. print '</td></tr>';
  1303. }
  1304. if (isModEnabled('facture')) {
  1305. print '<tr><td>'.$langs->trans("ContactForInvoices").'</td><td colspan="3">';
  1306. print $object->ref_facturation ? $object->ref_facturation : $langs->trans("NoContactForAnyInvoice");
  1307. print '</td></tr>';
  1308. }
  1309. print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
  1310. if ($object->user_id) {
  1311. $dolibarr_user = new User($db);
  1312. $result = $dolibarr_user->fetch($object->user_id);
  1313. print $dolibarr_user->getLoginUrl(-1);
  1314. } else {
  1315. //print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
  1316. if (!$object->user_id && $user->rights->user->user->creer) {
  1317. print '<a class="aaa" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create_user&token='.newToken().'">'.img_picto($langs->trans("CreateDolibarrLogin"), 'add', 'class="pictofixedwidth"').$langs->trans("CreateDolibarrLogin").'</a>';
  1318. }
  1319. }
  1320. print '</td></tr>';
  1321. print "</table>";
  1322. print '</div></div>';
  1323. print '<div style="clear:both"></div>';
  1324. print dol_get_fiche_end();
  1325. /*
  1326. * Action bar
  1327. */
  1328. print '<div class="tabsAction">';
  1329. $parameters = array();
  1330. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1331. if (empty($reshook) && $action != 'presend') {
  1332. if (empty($user->socid)) {
  1333. if (!empty($object->email)) {
  1334. $langs->load("mails");
  1335. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
  1336. } else {
  1337. $langs->load("mails");
  1338. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans('SendMail').'</a></div>';
  1339. }
  1340. }
  1341. if ($user->rights->societe->contact->creer) {
  1342. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
  1343. }
  1344. // Activer
  1345. if ($object->statut == 0 && $user->rights->societe->contact->creer) {
  1346. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Reactivate").'</a>';
  1347. }
  1348. // Desactiver
  1349. if ($object->statut == 1 && $user->rights->societe->contact->creer) {
  1350. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&id='.$object->id.'&token='.newToken().'">'.$langs->trans("DisableUser").'</a>';
  1351. }
  1352. // Delete
  1353. if ($user->rights->societe->contact->supprimer) {
  1354. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().''.($backtopage ? '&backtopage='.urlencode($backtopage) : '').'">'.$langs->trans('Delete').'</a>';
  1355. }
  1356. }
  1357. print "</div>";
  1358. //Select mail models is same action as presend
  1359. if (GETPOST('modelselected')) {
  1360. $action = 'presend';
  1361. }
  1362. if ($action != 'presend') {
  1363. print '<div class="fichecenter"><div class="fichehalfleft">';
  1364. print '</div><div class="fichehalfright">';
  1365. $MAXEVENT = 10;
  1366. $morehtmlright = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/contact/agenda.php?id='.$object->id);
  1367. // List of actions on element
  1368. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1369. $formactions = new FormActions($db);
  1370. $somethingshown = $formactions->showactions($object, 'contact', $object->socid, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
  1371. print '</div></div>';
  1372. }
  1373. // Presend form
  1374. $modelmail = 'contact';
  1375. $defaulttopic = 'Information';
  1376. $diroutput = $conf->societe->dir_output.'/contact/';
  1377. $trackid = 'ctc'.$object->id;
  1378. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  1379. }
  1380. }
  1381. llxFooter();
  1382. $db->close();