card.php 66 KB

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