card.php 64 KB

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