card.php 64 KB

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