card.php 63 KB

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