card.php 64 KB

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