PageRenderTime 56ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/fichinter/card.php

https://github.com/atm-maximep/dolibarr
PHP | 1861 lines | 1392 code | 279 blank | 190 comment | 421 complexity | 450db56d13d99996ef3ee92735c6bde8 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0, LGPL-3.0, GPL-2.0, GPL-3.0, CC-BY-SA-4.0, LGPL-2.1
  1. <?php
  2. /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  7. * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
  8. * Copyright (C) 201 Charlie Benke <charlies@patas-monkey.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/fichinter/card.php
  25. * \brief Page of intervention
  26. * \ingroup ficheinter
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. if (! empty($conf->projet->enabled))
  35. {
  36. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  38. }
  39. if ($conf->contrat->enabled)
  40. {
  41. require_once DOL_DOCUMENT_ROOT."/core/class/html.formcontract.class.php";
  42. require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
  43. }
  44. if (! empty($conf->global->FICHEINTER_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php"))
  45. {
  46. require_once DOL_DOCUMENT_ROOT ."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.'.php';
  47. }
  48. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  49. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  50. $langs->load("bills");
  51. $langs->load("companies");
  52. $langs->load("interventions");
  53. $id = GETPOST('id','int');
  54. $ref = GETPOST('ref','alpha');
  55. $socid = GETPOST('socid','int');
  56. $contratid = GETPOST('contratid','int');
  57. $action = GETPOST('action','alpha');
  58. $confirm = GETPOST('confirm','alpha');
  59. $mesg = GETPOST('msg','alpha');
  60. $origin=GETPOST('origin','alpha');
  61. $originid=(GETPOST('originid','int')?GETPOST('originid','int'):GETPOST('origin_id','int')); // For backward compatibility
  62. $note_public = GETPOST('note_public');
  63. $lineid = GETPOST('line_id','int');
  64. //PDF
  65. $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  66. $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  67. $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  68. // Security check
  69. if ($user->societe_id) $socid=$user->societe_id;
  70. $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
  71. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  72. $hookmanager->initHooks(array('interventioncard','globalcard'));
  73. $object = new Fichinter($db);
  74. $extrafields = new ExtraFields($db);
  75. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  76. // Load object
  77. if ($id > 0 || ! empty($ref))
  78. {
  79. $ret=$object->fetch($id, $ref);
  80. if ($ret > 0) $ret=$object->fetch_thirdparty();
  81. if ($ret < 0) dol_print_error('',$object->error);
  82. }
  83. $permissionnote=$user->rights->ficheinter->creer; // Used by the include of actions_setnotes.inc.php
  84. /*
  85. * Actions
  86. */
  87. $parameters=array('socid'=>$socid);
  88. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  89. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  90. include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
  91. if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer)
  92. {
  93. $result = $object->setValid($user);
  94. if ($result >= 0)
  95. {
  96. // Define output language
  97. $outputlangs = $langs;
  98. $newlang='';
  99. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  100. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  101. if (! empty($newlang))
  102. {
  103. $outputlangs = new Translate("",$conf);
  104. $outputlangs->setDefaultLang($newlang);
  105. }
  106. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs);
  107. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  108. exit;
  109. }
  110. else
  111. {
  112. $mesg='<div class="error">'.$object->error.'</div>';
  113. }
  114. }
  115. else if ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer)
  116. {
  117. $result = $object->setDraft($user);
  118. if ($result >= 0)
  119. {
  120. // Define output language
  121. $outputlangs = $langs;
  122. $newlang='';
  123. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  124. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  125. if (! empty($newlang))
  126. {
  127. $outputlangs = new Translate("",$conf);
  128. $outputlangs->setDefaultLang($newlang);
  129. }
  130. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) $result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->model:GETPOST('model','apha'), $outputlangs);
  131. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  132. exit;
  133. }
  134. else
  135. {
  136. $mesg='<div class="error">'.$object->error.'</div>';
  137. }
  138. }
  139. else if ($action == 'add' && $user->rights->ficheinter->creer)
  140. {
  141. $object->socid = $socid;
  142. $object->duration = GETPOST('duration','int');
  143. $object->fk_project = GETPOST('projectid','int');
  144. $object->fk_contrat = GETPOST('contratid','int');
  145. $object->author = $user->id;
  146. $object->description = GETPOST('description');
  147. $object->ref = $ref;
  148. $object->modelpdf = GETPOST('model','alpha');
  149. $object->note_private = GETPOST('note_private');
  150. $object->note_public = GETPOST('note_public');
  151. if ($object->socid > 0)
  152. {
  153. // If creation from another object of another module (Example: origin=propal, originid=1)
  154. if (!empty($origin) && !empty($originid) )
  155. {
  156. // Parse element/subelement (ex: project_task)
  157. $element = $subelement = $_POST['origin'];
  158. if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs))
  159. {
  160. $element = $regs[1];
  161. $subelement = $regs[2];
  162. }
  163. // For compatibility
  164. if ($element == 'order') {
  165. $element = $subelement = 'commande';
  166. }
  167. if ($element == 'propal') {
  168. $element = 'comm/propal'; $subelement = 'propal';
  169. }
  170. if ($element == 'contract') {
  171. $element = $subelement = 'contrat';
  172. }
  173. $object->origin = $origin;
  174. $object->origin_id = $originid;
  175. // Possibility to add external linked objects with hooks
  176. $object->linked_objects[$object->origin] = $object->origin_id;
  177. if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects']))
  178. {
  179. $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
  180. }
  181. // Extrafields
  182. $extrafields = new ExtraFields($db);
  183. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  184. $array_options = $extrafields->getOptionalsFromPost($extralabels);
  185. $object->array_options = $array_options;
  186. $id = $object->create($user);
  187. if ($id > 0)
  188. {
  189. dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
  190. $classname = ucfirst($subelement);
  191. $srcobject = new $classname($db);
  192. dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
  193. $result=$srcobject->fetch($object->origin_id);
  194. if ($result > 0)
  195. {
  196. $srcobject->fetch_thirdparty();
  197. $lines = $srcobject->lines;
  198. if (empty($lines) && method_exists($srcobject,'fetch_lines'))
  199. {
  200. $srcobject->fetch_lines();
  201. $lines = $srcobject->lines;
  202. }
  203. $fk_parent_line=0;
  204. $num=count($lines);
  205. for ($i=0;$i<$num;$i++)
  206. {
  207. $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
  208. if ($product_type == 1 || !empty($conf->global->FICHINTER_PRINT_PRODUCTS)) { //only services except if config includes products
  209. // service prédéfini
  210. if ($lines[$i]->fk_product > 0)
  211. {
  212. // Define output language
  213. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  214. {
  215. $prod = new Product($db);
  216. $prod->id=$lines[$i]->fk_product;
  217. $prod->getMultiLangs();
  218. // We show if duration is present on service (so we get it)
  219. $prod->fetch($lines[$i]->fk_product);
  220. if ($prod->duration_value && $prod->duration_unit == 'h' && $conf->global->FICHINTER_USE_SERVICE_DURATION)
  221. {
  222. $durationproduct=$prod->duration_value * 3600 * $lines[$i]->qty;
  223. }
  224. else
  225. $durationproduct=3600;
  226. $outputlangs = $langs;
  227. $newlang='';
  228. if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
  229. if (empty($newlang)) $newlang=$srcobject->client->default_lang;
  230. if (! empty($newlang))
  231. {
  232. $outputlangs = new Translate("",$conf);
  233. $outputlangs->setDefaultLang($newlang);
  234. }
  235. $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label;
  236. }
  237. else
  238. {
  239. $label = $lines[$i]->product_label;
  240. }
  241. $desc = $label;
  242. $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')';
  243. }
  244. else {
  245. $desc = dol_htmlentitiesbr($lines[$i]->desc);
  246. $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')';
  247. }
  248. $timearray=dol_getdate(mktime());
  249. $date_intervention=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']);
  250. if ($product_type == 1)
  251. { //service
  252. $duration = $durationproduct;
  253. }
  254. else
  255. { //product
  256. $duration = 0;
  257. }
  258. $predef = '';
  259. // Extrafields
  260. $extrafieldsline = new ExtraFields($db);
  261. $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
  262. $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
  263. $result = $object->addline(
  264. $user,
  265. $id,
  266. $desc,
  267. $date_intervention,
  268. $duration,
  269. $array_options
  270. );
  271. if ($result < 0)
  272. {
  273. $error++;
  274. break;
  275. }
  276. }
  277. }
  278. }
  279. else
  280. {
  281. $mesg=$srcobject->error;
  282. $error++;
  283. }
  284. }
  285. else
  286. {
  287. $mesg=$object->error;
  288. $error++;
  289. }
  290. }
  291. else
  292. {
  293. // Extrafields
  294. $extrafields = new ExtraFields($db);
  295. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  296. $array_options = $extrafields->getOptionalsFromPost($extralabels);
  297. $object->array_options = $array_options;
  298. $result = $object->create($user);
  299. if ($result > 0)
  300. {
  301. $id=$result; // Force raffraichissement sur fiche venant d'etre cree
  302. }
  303. else
  304. {
  305. $langs->load("errors");
  306. setEventMessages($object->error, $object->errors, 'errors');
  307. $action = 'create';
  308. }
  309. }
  310. }
  311. else
  312. {
  313. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).'</div>';
  314. $action = 'create';
  315. }
  316. }
  317. else if ($action == 'update' && $user->rights->ficheinter->creer)
  318. {
  319. $object->socid = $socid;
  320. $object->fk_project = GETPOST('projectid','int');
  321. $object->fk_contrat = GETPOST('contratid','int');
  322. $object->author = $user->id;
  323. $object->description = GETPOST('description','alpha');
  324. $object->ref = $ref;
  325. $result=$object->update($user);
  326. if ($result<0) {
  327. setEventMessage($object->error,'errors');
  328. }
  329. }
  330. /*
  331. * Build doc
  332. */
  333. else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou en post
  334. {
  335. $object->fetch_lines();
  336. // Save last template used to generate document
  337. if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
  338. // Define output language
  339. $outputlangs = $langs;
  340. $newlang='';
  341. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  342. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  343. if (! empty($newlang))
  344. {
  345. $outputlangs = new Translate("",$conf);
  346. $outputlangs->setDefaultLang($newlang);
  347. }
  348. $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs);
  349. if ($result <= 0)
  350. {
  351. dol_print_error($db,$result);
  352. exit;
  353. }
  354. }
  355. // Remove file in doc form
  356. else if ($action == 'remove_file')
  357. {
  358. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  359. $object->fetch_thirdparty();
  360. $langs->load("other");
  361. $upload_dir = $conf->ficheinter->dir_output;
  362. $file = $upload_dir . '/' . GETPOST('file');
  363. $ret=dol_delete_file($file,0,0,0,$object);
  364. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  365. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  366. }
  367. // Set into a project
  368. else if ($action == 'classin' && $user->rights->ficheinter->creer)
  369. {
  370. $result=$object->setProject(GETPOST('projectid','int'));
  371. if ($result < 0) dol_print_error($db,$object->error);
  372. }
  373. // Set into a contract
  374. else if ($action == 'setcontrat' && $user->rights->contrat->creer)
  375. {
  376. $result=$object->set_contrat($user,GETPOST('contratid','int'));
  377. if ($result < 0) dol_print_error($db,$object->error);
  378. }
  379. else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer)
  380. {
  381. $result=$object->delete($user);
  382. if ($result<0) {
  383. setEventMessage($object->error,'errors');
  384. }
  385. header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter');
  386. exit;
  387. }
  388. else if ($action == 'setdescription' && $user->rights->ficheinter->creer)
  389. {
  390. $result=$object->set_description($user,GETPOST('description'));
  391. if ($result < 0) dol_print_error($db,$object->error);
  392. }
  393. // Add line
  394. else if ($action == "addline" && $user->rights->ficheinter->creer)
  395. {
  396. if (!GETPOST('np_desc'))
  397. {
  398. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).'</div>';
  399. $error++;
  400. }
  401. if (!GETPOST('durationhour','int') && !GETPOST('durationmin','int'))
  402. {
  403. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Duration")).'</div>';
  404. $error++;
  405. }
  406. if (GETPOST('durationhour','int') >= 24 && GETPOST('durationmin','int') > 0)
  407. {
  408. $mesg='<div class="error">'.$langs->trans("ErrorValueTooHigh").'</div>';
  409. $error++;
  410. }
  411. if (! $error)
  412. {
  413. $db->begin();
  414. $desc=GETPOST('np_desc');
  415. $date_intervention = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int'));
  416. $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int'));
  417. // Extrafields
  418. $extrafieldsline = new ExtraFields($db);
  419. $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
  420. $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
  421. $result=$object->addline(
  422. $user,
  423. $id,
  424. $desc,
  425. $date_intervention,
  426. $duration,
  427. $array_options
  428. );
  429. // Define output language
  430. $outputlangs = $langs;
  431. $newlang='';
  432. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  433. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  434. if (! empty($newlang))
  435. {
  436. $outputlangs = new Translate("",$conf);
  437. $outputlangs->setDefaultLang($newlang);
  438. }
  439. if ($result >= 0)
  440. {
  441. $db->commit();
  442. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs);
  443. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  444. exit;
  445. }
  446. else
  447. {
  448. $mesg=$object->error;
  449. $db->rollback();
  450. }
  451. }
  452. }
  453. // Classify Billed
  454. else if ($action == 'classifybilled' && $user->rights->ficheinter->creer)
  455. {
  456. $result=$object->setStatut(2);
  457. if ($result > 0)
  458. {
  459. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  460. exit;
  461. }
  462. else
  463. {
  464. setEventMessages($object->error, $object->errors, 'errors');
  465. }
  466. }
  467. // Classify Billed
  468. else if ($action == 'classifyunbilled' && $user->rights->ficheinter->creer)
  469. {
  470. $result=$object->setStatut(1);
  471. if ($result > 0)
  472. {
  473. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  474. exit;
  475. }
  476. else
  477. {
  478. $mesg='<div class="error">'.$object->error.'</div>';
  479. }
  480. }
  481. /*
  482. * Mise a jour d'une ligne d'intervention
  483. */
  484. else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST('save','alpha') == $langs->trans("Save"))
  485. {
  486. $objectline = new FichinterLigne($db);
  487. if ($objectline->fetch($lineid) <= 0)
  488. {
  489. dol_print_error($db);
  490. exit;
  491. }
  492. if ($object->fetch($objectline->fk_fichinter) <= 0)
  493. {
  494. dol_print_error($db);
  495. exit;
  496. }
  497. $object->fetch_thirdparty();
  498. $desc = GETPOST('np_desc');
  499. $date_inter = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int'));
  500. $duration = convertTime2Seconds(GETPOST('durationhour','int'),GETPOST('durationmin','int'));
  501. $objectline->datei = $date_inter;
  502. $objectline->desc = $desc;
  503. $objectline->duration = $duration;
  504. // Extrafields
  505. $extrafieldsline = new ExtraFields($db);
  506. $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
  507. $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
  508. $objectline->array_options = $array_options;
  509. $result = $objectline->update($user);
  510. if ($result < 0)
  511. {
  512. dol_print_error($db);
  513. exit;
  514. }
  515. // Define output language
  516. $outputlangs = $langs;
  517. $newlang='';
  518. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  519. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  520. if (! empty($newlang))
  521. {
  522. $outputlangs = new Translate("",$conf);
  523. $outputlangs->setDefaultLang($newlang);
  524. }
  525. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs);
  526. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  527. exit;
  528. }
  529. /*
  530. * Supprime une ligne d'intervention AVEC confirmation
  531. */
  532. else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->ficheinter->creer)
  533. {
  534. $objectline = new FichinterLigne($db);
  535. if ($objectline->fetch($lineid) <= 0)
  536. {
  537. dol_print_error($db);
  538. exit;
  539. }
  540. $result=$objectline->deleteline($user);
  541. if ($object->fetch($objectline->fk_fichinter) <= 0)
  542. {
  543. dol_print_error($db);
  544. exit;
  545. }
  546. // Define output language
  547. $outputlangs = $langs;
  548. $newlang='';
  549. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  550. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  551. if (! empty($newlang))
  552. {
  553. $outputlangs = new Translate("",$conf);
  554. $outputlangs->setDefaultLang($newlang);
  555. }
  556. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs);
  557. }
  558. /*
  559. * Ordonnancement des lignes
  560. */
  561. else if ($action == 'up' && $user->rights->ficheinter->creer)
  562. {
  563. $object->line_up($lineid);
  564. // Define output language
  565. $outputlangs = $langs;
  566. $newlang='';
  567. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  568. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  569. if (! empty($newlang))
  570. {
  571. $outputlangs = new Translate("",$conf);
  572. $outputlangs->setDefaultLang($newlang);
  573. }
  574. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs);
  575. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
  576. exit;
  577. }
  578. else if ($action == 'down' && $user->rights->ficheinter->creer)
  579. {
  580. $object->line_down($lineid);
  581. // Define output language
  582. $outputlangs = $langs;
  583. $newlang='';
  584. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  585. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  586. if (! empty($newlang))
  587. {
  588. $outputlangs = new Translate("",$conf);
  589. $outputlangs->setDefaultLang($newlang);
  590. }
  591. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) fichinter_create($db, $object, $object->modelpdf, $outputlangs);
  592. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
  593. exit;
  594. }
  595. /*
  596. * Add file in email form
  597. */
  598. if (GETPOST('addfile','alpha'))
  599. {
  600. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  601. // Set tmp user directory TODO Use a dedicated directory for temp mails files
  602. $vardir=$conf->user->dir_output."/".$user->id;
  603. $upload_dir_tmp = $vardir.'/temp';
  604. dol_add_file_process($upload_dir_tmp,0,0);
  605. $action='presend';
  606. }
  607. /*
  608. * Remove file in email form
  609. */
  610. if (GETPOST('removedfile','alpha'))
  611. {
  612. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  613. // Set tmp user directory
  614. $vardir=$conf->user->dir_output."/".$user->id;
  615. $upload_dir_tmp = $vardir.'/temp';
  616. // TODO Delete only files that was uploaded from email form
  617. dol_remove_file_process(GETPOST('removedfile','alpha'),0);
  618. $action='presend';
  619. }
  620. /*
  621. * Send mail
  622. */
  623. if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send))
  624. {
  625. $langs->load('mails');
  626. if (GETPOST('sendto','alpha'))
  627. {
  628. // Le destinataire a ete fourni via le champ libre
  629. $sendto = GETPOST('sendto','alpha');
  630. $sendtoid = 0;
  631. }
  632. elseif (GETPOST('receiver','alpha') != '-1')
  633. {
  634. // Recipient was provided from combo list
  635. if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
  636. {
  637. $sendto = $object->client->email;
  638. $sendtoid = 0;
  639. }
  640. else // Id du contact
  641. {
  642. $sendto = $object->client->contact_get_property(GETPOST('receiver'),'email');
  643. $sendtoid = GETPOST('receiver','alpha');
  644. }
  645. }
  646. if (dol_strlen($sendto))
  647. {
  648. $langs->load("commercial");
  649. $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
  650. $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
  651. $message = GETPOST('message');
  652. $sendtocc = GETPOST('sendtocc','alpha');
  653. $deliveryreceipt = GETPOST('deliveryreceipt','alpha');
  654. if ($action == 'send')
  655. {
  656. if (strlen(GETPOST('subject','alphs'))) $subject = GETPOST('subject','alpha');
  657. else $subject = $langs->transnoentities('Intervention').' '.$object->ref;
  658. $actiontypecode='AC_OTH_AUTO';
  659. $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
  660. if ($message)
  661. {
  662. if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
  663. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
  664. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
  665. $actionmsg = dol_concatdesc($actionmsg, $message);
  666. }
  667. $actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref);
  668. }
  669. // Create form object
  670. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  671. $formmail = new FormMail($db);
  672. $attachedfiles=$formmail->get_attached_files();
  673. $filepath = $attachedfiles['paths'];
  674. $filename = $attachedfiles['names'];
  675. $mimetype = $attachedfiles['mimes'];
  676. // Send by email
  677. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  678. $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
  679. if ($mailfile->error)
  680. {
  681. $mesg='<div class="error">'.$mailfile->error.'</div>';
  682. }
  683. else
  684. {
  685. $result=$mailfile->sendfile();
  686. if ($result)
  687. {
  688. $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
  689. setEventMessage($mesg);
  690. $error=0;
  691. // Initialisation donnees
  692. $object->sendtoid = $sendtoid;
  693. $object->actiontypecode = $actiontypecode;
  694. $object->actionmsg = $actionmsg;
  695. $object->actionmsg2 = $actionmsg2;
  696. $object->fk_element = $object->id;
  697. $object->elementtype = $object->element;
  698. // Appel des triggers
  699. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  700. $interface=new Interfaces($db);
  701. $result=$interface->run_triggers('FICHINTER_SENTBYMAIL',$object,$user,$langs,$conf);
  702. if ($result < 0) {
  703. $error++; $object->errors=$interface->errors;
  704. }
  705. // Fin appel triggers
  706. if ($error)
  707. {
  708. dol_print_error($db);
  709. }
  710. else
  711. {
  712. // Redirect here
  713. // This avoid sending mail twice if going out and then back to page
  714. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  715. exit;
  716. }
  717. }
  718. else
  719. {
  720. $langs->load("other");
  721. $mesg='<div class="error">';
  722. if ($mailfile->error)
  723. {
  724. $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
  725. $mesg.='<br>'.$mailfile->error;
  726. }
  727. else
  728. {
  729. $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
  730. }
  731. $mesg.='</div>';
  732. }
  733. }
  734. }
  735. else
  736. {
  737. $langs->load("other");
  738. $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
  739. dol_syslog('Recipient email is empty');
  740. }
  741. $action='presend';
  742. }
  743. else if ($action == 'update_extras')
  744. {
  745. // Fill array 'array_options' with data from update form
  746. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  747. $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
  748. if ($ret < 0) $error++;
  749. if (! $error)
  750. {
  751. // Actions on extra fields (by external module or standard code)
  752. // TODO le hook fait double emploi avec le trigger !!
  753. $hookmanager->initHooks(array('interventiondao'));
  754. $parameters=array('id'=>$object->id);
  755. $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  756. if (empty($reshook))
  757. {
  758. $result=$object->insertExtraFields();
  759. if ($result < 0)
  760. {
  761. $error++;
  762. }
  763. }
  764. else if ($reshook < 0) $error++;
  765. }
  766. if ($error) $action = 'edit_extras';
  767. }
  768. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer)
  769. {
  770. if ($action == 'addcontact')
  771. {
  772. if ($result > 0 && $id > 0)
  773. {
  774. $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
  775. $result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha'));
  776. }
  777. if ($result >= 0)
  778. {
  779. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  780. exit;
  781. }
  782. else
  783. {
  784. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  785. {
  786. $langs->load("errors");
  787. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  788. }
  789. else
  790. {
  791. $mesg = '<div class="error">'.$object->error.'</div>';
  792. }
  793. }
  794. }
  795. // bascule du statut d'un contact
  796. else if ($action == 'swapstatut')
  797. {
  798. $result=$object->swapContactStatus(GETPOST('ligne','int'));
  799. }
  800. // Efface un contact
  801. else if ($action == 'deletecontact')
  802. {
  803. $result = $object->delete_contact(GETPOST('lineid','int'));
  804. if ($result >= 0)
  805. {
  806. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  807. exit;
  808. }
  809. else {
  810. dol_print_error($db);
  811. }
  812. }
  813. }
  814. /*
  815. * View
  816. */
  817. $form = new Form($db);
  818. $formfile = new FormFile($db);
  819. if ($conf->contrat->enabled)
  820. $formcontract = new FormContract($db);
  821. llxHeader('',$langs->trans("Fichinter"));
  822. if ($action == 'create')
  823. {
  824. /*
  825. * Mode creation
  826. * Creation d'une nouvelle fiche d'intervention
  827. */
  828. $soc=new Societe($db);
  829. print_fiche_titre($langs->trans("AddIntervention"));
  830. dol_htmloutput_mesg($mesg);
  831. if ($socid) $res=$soc->fetch($socid);
  832. if (GETPOST('origin') && GETPOST('originid'))
  833. {
  834. // Parse element/subelement (ex: project_task)
  835. $element = $subelement = GETPOST('origin');
  836. if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs))
  837. {
  838. $element = $regs[1];
  839. $subelement = $regs[2];
  840. }
  841. if ($element == 'project')
  842. {
  843. $projectid=GETPOST('originid');
  844. }
  845. else
  846. {
  847. // For compatibility
  848. if ($element == 'order' || $element == 'commande') {
  849. $element = $subelement = 'commande';
  850. }
  851. if ($element == 'propal') {
  852. $element = 'comm/propal'; $subelement = 'propal';
  853. }
  854. if ($element == 'contract') {
  855. $element = $subelement = 'contrat';
  856. }
  857. dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
  858. $classname = ucfirst($subelement);
  859. $objectsrc = new $classname($db);
  860. $objectsrc->fetch(GETPOST('originid'));
  861. if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines'))
  862. {
  863. $objectsrc->fetch_lines();
  864. $lines = $objectsrc->lines;
  865. }
  866. $objectsrc->fetch_thirdparty();
  867. $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:'');
  868. $soc = $objectsrc->client;
  869. $note_private = (! empty($objectsrc->note) ? $objectsrc->note : (! empty($objectsrc->note_private) ? $objectsrc->note_private : GETPOST('note_private')));
  870. $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : GETPOST('note_public'));
  871. // Object source contacts list
  872. $srccontactslist = $objectsrc->liste_contact(-1,'external',1);
  873. }
  874. }
  875. else {
  876. $projectid = GETPOST('projectid','int');
  877. }
  878. if (! $conf->global->FICHEINTER_ADDON)
  879. {
  880. dol_print_error($db,$langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"));
  881. exit;
  882. }
  883. $object->date = dol_now();
  884. $obj = $conf->global->FICHEINTER_ADDON;
  885. $obj = "mod_".$obj;
  886. //$modFicheinter = new $obj;
  887. //$numpr = $modFicheinter->getNextValue($soc, $object);
  888. if ($socid > 0)
  889. {
  890. $soc->fetch($socid);
  891. print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  892. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  893. dol_fiche_head('');
  894. print '<table class="border" width="100%">';
  895. print '<input type="hidden" name="socid" value='.$soc->id.'>';
  896. print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
  897. print '<input type="hidden" name="action" value="add">';
  898. // Ref
  899. print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans("Draft").'</td></tr>';
  900. // Description (must be a textarea and not html must be allowed (used in list view)
  901. print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
  902. print '<td>';
  903. print '<textarea name="description" cols="80" rows="'.ROWS_3.'">'.GETPOST('description').'</textarea>';
  904. print '</td></tr>';
  905. // Project
  906. if (! empty($conf->projet->enabled))
  907. {
  908. $formproject=new FormProjets($db);
  909. $langs->load("project");
  910. print '<tr><td valign="top">'.$langs->trans("Project").'</td><td>';
  911. /* Fix: If a project must be linked to any companies (suppliers or not), project must be not be set as limited to customer but must be not linked to any particular thirdparty
  912. if ($societe->fournisseur==1)
  913. $numprojet=select_projects(-1,$_POST["projectid"],'projectid');
  914. else
  915. $numprojet=select_projects($societe->id,$_POST["projectid"],'projectid');
  916. */
  917. $numprojet=$formproject->select_projects($soc->id,GETPOST('projectid','int'),'projectid');
  918. if ($numprojet==0)
  919. {
  920. print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create">'.$langs->trans("AddProject").'</a>';
  921. }
  922. print '</td></tr>';
  923. }
  924. // Contract
  925. if ($conf->contrat->enabled)
  926. {
  927. $langs->load("contracts");
  928. print '<tr><td valign="top">'.$langs->trans("Contract").'</td><td>';
  929. $numcontrat=$formcontract->select_contract($soc->id,GETPOST('contratid','int'),'contratid',0,1);
  930. if ($numcontrat==0)
  931. {
  932. print ' &nbsp; <a href="'.DOL_URL_ROOT.'/contrat/card.php?socid='.$soc->id.'&action=create">'.$langs->trans("AddContract").'</a>';
  933. }
  934. print '</td></tr>';
  935. }
  936. // Model
  937. print '<tr>';
  938. print '<td>'.$langs->trans("DefaultModel").'</td>';
  939. print '<td colspan="2">';
  940. $liste=ModelePDFFicheinter::liste_modeles($db);
  941. print $form->selectarray('model',$liste,$conf->global->FICHEINTER_ADDON_PDF);
  942. print "</td></tr>";
  943. // Public note
  944. print '<tr>';
  945. print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
  946. print '<td valign="top" colspan="2">';
  947. $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  948. print $doleditor->Create(1);
  949. //print '<textarea name="note_public" cols="80" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
  950. print '</td></tr>';
  951. // Private note
  952. if (!empty($user->societe_id))
  953. {
  954. print '<tr>';
  955. print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
  956. print '<td valign="top" colspan="2">';
  957. $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70);
  958. print $doleditor->Create(1);
  959. //print '<textarea name="note_private" cols="80" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
  960. print '</td></tr>';
  961. }
  962. // Other attributes
  963. $parameters=array('colspan' => ' colspan="2"');
  964. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  965. if (empty($reshook) && ! empty($extrafields->attribute_label))
  966. {
  967. print $object->showOptionals($extrafields,'edit');
  968. }
  969. // Show link to origin object
  970. if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
  971. {
  972. $newclassname=$classname;
  973. if ($newclassname=='Propal') $newclassname='CommercialProposal';
  974. print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
  975. }
  976. print '</table>';
  977. if (is_object($objectsrc))
  978. {
  979. print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
  980. print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
  981. }
  982. dol_fiche_end();
  983. print '<div class="center">';
  984. print '<input type="submit" class="button" value="'.$langs->trans("CreateDraftIntervention").'">';
  985. print '</div>';
  986. print '</form>';
  987. }
  988. else
  989. {
  990. dol_fiche_head('');
  991. print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  992. print '<table class="border" width="100%">';
  993. print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>';
  994. print $form->select_company('','socid','',1,1);
  995. print '</td></tr>';
  996. print '</table>';
  997. dol_fiche_end();
  998. print '<div class="center">';
  999. print '<input type="hidden" name="action" value="create">';
  1000. print '<input type="submit" class="button" value="'.$langs->trans("CreateDraftIntervention").'">';
  1001. print '</div>';
  1002. print '</form>';
  1003. }
  1004. }
  1005. else if ($id > 0 || ! empty($ref))
  1006. {
  1007. /*
  1008. * Affichage en mode visu
  1009. */
  1010. $object->fetch($id, $ref);
  1011. $object->fetch_thirdparty();
  1012. $soc=new Societe($db);
  1013. $soc->fetch($object->socid);
  1014. dol_htmloutput_mesg($mesg);
  1015. $head = fichinter_prepare_head($object);
  1016. dol_fiche_head($head, 'card', $langs->trans("InterventionCard"), 0, 'intervention');
  1017. $formconfirm='';
  1018. // Confirm deletion of intervention
  1019. if ($action == 'delete')
  1020. {
  1021. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete','',0,1);
  1022. }
  1023. // Confirm validation
  1024. if ($action == 'validate')
  1025. {
  1026. // on verifie si l'objet est en numerotation provisoire
  1027. $ref = substr($object->ref, 1, 4);
  1028. if ($ref == 'PROV')
  1029. {
  1030. $numref = $object->getNextNumRef($soc);
  1031. if (empty($numref))
  1032. {
  1033. $error++;
  1034. setEventMessage($object->error, 'errors');
  1035. }
  1036. }
  1037. else
  1038. {
  1039. $numref = $object->ref;
  1040. }
  1041. $text=$langs->trans('ConfirmValidateIntervention',$numref);
  1042. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $text, 'confirm_validate','',1,1);
  1043. }
  1044. // Confirm back to draft
  1045. if ($action == 'modify')
  1046. {
  1047. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify','',0,1);
  1048. }
  1049. // Confirm deletion of line
  1050. if ($action == 'ask_deleteline')
  1051. {
  1052. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.$lineid, $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline','',0,1);
  1053. }
  1054. if (!$formconfirm)
  1055. {
  1056. $parameters=array('lineid'=>$lineid);
  1057. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1058. if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
  1059. elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;
  1060. }
  1061. // Print form confirm
  1062. print $formconfirm;
  1063. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST" name="formfichinter">';
  1064. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1065. if ($action == 'edit_extras') print '<input type="hidden" name="action" value="update_extras">';
  1066. if ($action == 'contrat') print '<input type="hidden" name="action" value="setcontrat">';
  1067. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1068. print '<table class="border" width="100%">';
  1069. $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  1070. // Ref
  1071. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
  1072. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  1073. print '</td></tr>';
  1074. // Third party
  1075. print "<tr><td>".$langs->trans("Company").'</td><td colspan="3">'.$object->client->getNomUrl(1)."</td></tr>";
  1076. if (empty($conf->global->FICHINTER_DISABLE_DETAILS))
  1077. {
  1078. // Duration
  1079. print '<tr><td>'.$langs->trans("TotalDuration").'</td>';
  1080. print '<td colspan="3">'.convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
  1081. print '</tr>';
  1082. }
  1083. // Description (must be a textarea and not html must be allowed (used in list view)
  1084. print '<tr><td valign="top">';
  1085. print $form->editfieldkey("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea');
  1086. print '</td><td colspan="3">';
  1087. print $form->editfieldval("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea:8:80');
  1088. print '</td>';
  1089. print '</tr>';
  1090. // Project
  1091. if (! empty($conf->projet->enabled))
  1092. {
  1093. $langs->load('projects');
  1094. print '<tr>';
  1095. print '<td>';
  1096. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1097. print $langs->trans('Project');
  1098. print '</td>';
  1099. if ($action != 'classify')
  1100. {
  1101. print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
  1102. print img_edit($langs->trans('SetProject'),1);
  1103. print '</a></td>';
  1104. }
  1105. print '</tr></table>';
  1106. print '</td><td colspan="3">';
  1107. if ($action == 'classify')
  1108. {
  1109. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid', 0, 0, 1);
  1110. }
  1111. else
  1112. {
  1113. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none', 0, 0);
  1114. }
  1115. print '</td>';
  1116. print '</tr>';
  1117. }
  1118. // Contrat
  1119. if ($conf->contrat->enabled)
  1120. {
  1121. $langs->load('contrat');
  1122. print '<tr>';
  1123. print '<td>';
  1124. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1125. print $langs->trans('Contract');
  1126. print '</td>';
  1127. if ($action != 'contrat')
  1128. {
  1129. print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=contrat&amp;id='.$object->id.'">';
  1130. print img_edit($langs->trans('SetContract'),1);
  1131. print '</a></td>';
  1132. }
  1133. print '</tr></table>';
  1134. print '</td><td colspan="3">';
  1135. if ($action == 'contrat')
  1136. {
  1137. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  1138. print '<tr><td>';
  1139. $htmlcontract= new Formcontract($db);
  1140. //print "$socid,$selected,$htmlname";
  1141. $htmlcontract->select_contract($object->socid,$object->fk_contrat,'contratid');
  1142. print '</td>';
  1143. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  1144. print '</tr></table>';
  1145. }
  1146. else
  1147. {
  1148. if ($object->fk_contrat)
  1149. {
  1150. $contratstatic = new Contrat($db);
  1151. $contratstatic->fetch($object->fk_contrat);
  1152. //print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
  1153. print $contratstatic->getNomUrl(0,'',1);
  1154. }
  1155. else
  1156. {
  1157. print "&nbsp;";
  1158. }
  1159. }
  1160. print '</td>';
  1161. print '</tr>';
  1162. }
  1163. // Statut
  1164. print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$object->getLibStatut(4).'</td></tr>';
  1165. // Other attributes
  1166. $cols = 3;
  1167. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  1168. print "</table>";
  1169. print '</form>';
  1170. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  1171. {
  1172. $blocname = 'contacts';
  1173. $title = $langs->trans('ContactsAddresses');
  1174. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  1175. }
  1176. if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  1177. {
  1178. $blocname = 'notes';
  1179. $title = $langs->trans('Notes');
  1180. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  1181. }
  1182. if (empty($conf->global->FICHINTER_DISABLE_DETAILS))
  1183. {
  1184. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" name="addinter" method="post">';
  1185. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1186. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1187. if ($action == 'editline')
  1188. {
  1189. print '<input type="hidden" name="action" value="updateline">';
  1190. print '<input type="hidden" name="line_id" value="'.GETPOST('line_id','int').'">';
  1191. }
  1192. else
  1193. {
  1194. print '<input type="hidden" name="action" value="addline">';
  1195. }
  1196. // Intervention lines
  1197. $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,';
  1198. $sql.= ' ft.date as date_intervention';
  1199. $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
  1200. $sql.= ' WHERE ft.fk_fichinter = '.$object->id;
  1201. if (!empty($conf->global->FICHINTER_HIDE_EMPTY_DURATION))
  1202. $sql.= ' AND ft.duree <> 0';
  1203. $sql.= ' ORDER BY ft.rang ASC, ft.rowid';
  1204. $resql = $db->query($sql);
  1205. if ($resql)
  1206. {
  1207. $num = $db->num_rows($resql);
  1208. $i = 0;
  1209. if ($num)
  1210. {
  1211. print '<br>';
  1212. print '<table class="noborder" width="100%">';
  1213. print '<tr class="liste_titre">';
  1214. print '<td>'.$langs->trans('Description').'</td>';
  1215. print '<td align="center">'.$langs->trans('Date').'</td>';
  1216. print '<td align="right">'.$langs->trans('Duration').'</td>';
  1217. print '<td width="48" colspan="3">&nbsp;</td>';
  1218. print "</tr>\n";
  1219. }
  1220. $var=true;
  1221. while ($i < $num)
  1222. {
  1223. $objp = $db->fetch_object($resql);
  1224. $var=!$var;
  1225. // Ligne en mode visu
  1226. if ($action != 'editline' || GETPOST('line_id','int') != $objp->rowid)
  1227. {
  1228. print '<tr '.$bc[$var].'>';
  1229. print '<td>';
  1230. print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
  1231. print dol_htmlentitiesbr($objp->description);
  1232. // Date
  1233. print '<td align="center" width="150">'.dol_print_date($db->jdate($objp->date_intervention),'dayhour').'</td>';
  1234. // Duration
  1235. print '<td align="right" width="150">'.convertSecondToTime($objp->duree).'</td>';
  1236. print "</td>\n";
  1237. // Icone d'edition et suppression
  1238. if ($object->statut == 0 && $user->rights->ficheinter->creer)
  1239. {
  1240. print '<td align="center">';
  1241. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;line_id='.$objp->rowid.'#'.$objp->rowid.'">';
  1242. print img_edit();
  1243. print '</a>';
  1244. print '</td>';
  1245. print '<td align="center">';
  1246. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=ask_deleteline&amp;line_id='.$objp->rowid.'">';
  1247. print img_delete();
  1248. print '</a></td>';
  1249. if ($num > 1)
  1250. {
  1251. print '<td align="center">';
  1252. if ($i > 0)
  1253. {
  1254. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=up&amp;line_id='.$objp->rowid.'">';
  1255. print img_up();
  1256. print '</a>';
  1257. }
  1258. if ($i < $num-1)
  1259. {
  1260. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=down&amp;line_id='.$objp->rowid.'">';
  1261. print img_down();
  1262. print '</a>';
  1263. }
  1264. print '</td>';
  1265. }
  1266. }
  1267. else
  1268. {
  1269. print '<td colspan="3">&nbsp;</td>';
  1270. }
  1271. print '</tr>';
  1272. $line = new FichinterLigne($db);
  1273. $line->fetch($objp->rowid);
  1274. $extrafieldsline = new ExtraFields($db);
  1275. $extralabelslines=$extrafieldsline->fetch_name_optionals_label($line->table_element);
  1276. $line->fetch_optionals($line->rowid, $extralabelslines);
  1277. print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>5));
  1278. }
  1279. // Line in update mode
  1280. if ($object->statut == 0 && $action == 'editline' && $user->rights->ficheinter->creer && GETPOST('line_id','int') == $objp->rowid)
  1281. {
  1282. print '<tr '.$bc[$var].'>';
  1283. print '<td>';
  1284. print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
  1285. // Editeur wysiwyg
  1286. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1287. $doleditor=new DolEditor('np_desc',$objp->description,'',164,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,70);
  1288. $doleditor->Create();
  1289. print '</td>';
  1290. // Date d'intervention
  1291. print '<td align="center" class="nowrap">';
  1292. $form->select_date($db->jdate($objp->date_intervention),'di',1,1,0,"date_intervention");
  1293. print '</td>';
  1294. // Duration
  1295. print '<td align="right">';
  1296. $selectmode='select';
  1297. if (! empty($conf->global->INTERVENTION_ADDLINE_FREEDUREATION)) $selectmode='text';
  1298. $form->select_duration('duration',$objp->duree, $selectmode);
  1299. print '</td>';
  1300. print '<td align="center" colspan="5" valign="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  1301. print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
  1302. print '</tr>' . "\n";
  1303. $line = new FichinterLigne($db);
  1304. $line->fetch($objp->rowid);
  1305. $extrafieldsline = new ExtraFields($db);
  1306. $extralabelslines=$extrafieldsline->fetch_name_optionals_label($line->table_element);
  1307. $line->fetch_optionals($line->rowid, $extralabelslines);
  1308. print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>5));
  1309. }
  1310. $i++;
  1311. }
  1312. $db->free($resql);
  1313. // Add new line
  1314. if ($object->statut == 0 && $user->rights->ficheinter->creer && $action <> 'editline' && empty($conf->global->FICHINTER_DISABLE_DETAILS))
  1315. {
  1316. if (! $num) print '<br><table class="noborder" width="100%">';
  1317. print '<tr class="liste_titre">';
  1318. print '<td>';
  1319. print '<a name="add"></a>'; // ancre
  1320. print $langs->trans('Description').'</td>';
  1321. print '<td align="center">'.$langs->trans('Date').'</td>';
  1322. print '<td align="right">'.$langs->trans('Duration').'</td>';
  1323. print '<td colspan="4">&nbsp;</td>';
  1324. print "</tr>\n";
  1325. $var=false;
  1326. print '<tr '.$bc[$var].">\n";
  1327. print '<td>';
  1328. // editeur wysiwyg
  1329. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1330. $doleditor=new DolEditor('np_desc',GETPOST('np_desc','alpha'),'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,70);
  1331. $doleditor->Create();
  1332. print '</td>';
  1333. // Date intervention
  1334. print '<td align="center" class="nowrap">';
  1335. $now=dol_now();
  1336. $timearray=dol_getdate($now);
  1337. if (! GETPOST('diday','int')) $timewithnohour=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']);
  1338. else $timewithnohour=dol_mktime(GETPOST('dihour','int'),GETPOST('dimin','int'), 0,GETPOST('dimonth','int'),GETPOST('diday','int'),GETPOST('diyear','int'));
  1339. $form->select_date($timewithnohour,'di',1,1,0,"addinter");
  1340. print '</td>';
  1341. // Duration
  1342. print '<td align="right">';
  1343. $selectmode='select';
  1344. if (! empty($conf->global->INTERVENTION_ADDLINE_FREEDUREATION)) $selectmode='text';
  1345. $form->select_duration('duration', (!GETPOST('durationhour','int') && !GETPOST('durationmin','int'))?3600:(60*60*GETPOST('durationhour','int')+60*GETPOST('durationmin','int')), 0, $selectmode);
  1346. print '</td>';
  1347. print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="'.$langs->trans('Add').'" name="addline"></td>';
  1348. print '</tr>';
  1349. //Line extrafield
  1350. $lineadd = new FichinterLigne($db);
  1351. $extrafieldsline = new ExtraFields($db);
  1352. $extralabelslines=$extrafieldsline->fetch_name_optionals_label($lineadd->table_element);
  1353. print $lineadd->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>5));
  1354. if (! $num) print '</table>';
  1355. }
  1356. if ($num) print '</table>';
  1357. }
  1358. else
  1359. {
  1360. dol_print_error($db);
  1361. }
  1362. print '</form>'."\n";
  1363. }
  1364. dol_fiche_end();
  1365. print "\n";
  1366. /*
  1367. * Actions buttons
  1368. */
  1369. print '<div class="tabsAction">';
  1370. $parameters = array();
  1371. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1372. // modified by hook
  1373. if (empty($reshook))
  1374. {
  1375. if ($user->societe_id == 0)
  1376. {
  1377. if ($action != 'editdescription' && ($action != 'presend'))
  1378. {
  1379. // Validate
  1380. if ($object->statut == 0 && $user->rights->ficheinter->creer && (count($object->lines) > 0 || ! empty($conf->global->FICHINTER_DISABLE_DETAILS)))
  1381. {
  1382. print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=validate"';
  1383. print '>'.$langs->trans("Validate").'</a></div>';
  1384. }
  1385. // Modify
  1386. if ($object->statut == 1 && $user->rights->ficheinter->creer)
  1387. {
  1388. print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=modify">';
  1389. if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) print $langs->trans("Modify");
  1390. else print $langs->trans("SetToDraft");
  1391. print '</a></div>';
  1392. }
  1393. // Send
  1394. if ($object->statut > 0)
  1395. {
  1396. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send)
  1397. {
  1398. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a></div>';
  1399. }
  1400. else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a></div>';
  1401. }
  1402. // Event agenda
  1403. if (! empty($conf->global->FICHINTER_ADDLINK_TO_EVENT))
  1404. {
  1405. if (! empty($conf->agenda->enabled) && $object->statut > 0)
  1406. {
  1407. $langs->load("agenda");
  1408. if ($object->statut < 2)
  1409. {
  1410. if ($user->rights->agenda->myactions->create) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'&amp;backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'">'.$langs->trans("AddEvent").'</a></div>';
  1411. else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddEvent").'</a></div>';
  1412. }
  1413. }
  1414. }
  1415. // Proposal
  1416. if (! empty($conf->propal->enabled) && $object->statut > 0)
  1417. {
  1418. $langs->load("propal");
  1419. if ($object->statut < 2)
  1420. {
  1421. if ($user->rights->propal->creer) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddProp").'</a></div>';
  1422. else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddProp").'</a></div>';
  1423. }
  1424. }
  1425. // Invoicing
  1426. if (! empty($conf->facture->enabled) && $object->statut > 0)
  1427. {
  1428. $langs->load("bills");
  1429. if ($object->statut < 2)
  1430. {
  1431. if ($user->rights->facture->creer) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddBill").'</a></div>';
  1432. else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddBill").'</a></div>';
  1433. }
  1434. if (! empty($conf->global->FICHINTER_CLASSIFY_BILLED))
  1435. {
  1436. if ($object->statut != 2)
  1437. {
  1438. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled">'.$langs->trans("InterventionClassifyBilled").'</a></div>';
  1439. }
  1440. else
  1441. {
  1442. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifyunbilled">'.$langs->trans("InterventionClassifyUnBilled").'</a></div>';
  1443. }
  1444. }
  1445. }
  1446. // Delete
  1447. if (($object->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer)
  1448. {
  1449. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete"';
  1450. print '>'.$langs->trans('Delete').'</a></div>';
  1451. }
  1452. }
  1453. }
  1454. }
  1455. print '</div>';
  1456. print '<br>';
  1457. if ($action != 'presend')
  1458. {
  1459. print '<div class="fichecenter"><div class="fichehalfleft">';
  1460. /*
  1461. * Built documents
  1462. */
  1463. $filename=dol_sanitizeFileName($object->ref);
  1464. $filedir=$conf->ficheinter->dir_output . "/".$object->ref;
  1465. $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
  1466. $genallowed=$user->rights->ficheinter->creer;
  1467. $delallowed=$user->rights->ficheinter->supprimer;
  1468. $genallowed=1;
  1469. $delallowed=1;
  1470. $var=true;
  1471. //print "<br>\n";
  1472. $somethingshown=$formfile->show_documents('ficheinter',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
  1473. // Linked object block
  1474. $somethingshown = $form->showLinkedObjectBlock($object);
  1475. // Show links to link elements
  1476. //$linktoelem = $form->showLinkToObjectBlock($object);
  1477. //if ($linktoelem) print '<br>'.$linktoelem;
  1478. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  1479. // List of actions on element
  1480. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1481. $formactions=new FormActions($db);
  1482. $somethingshown=$formactions->showactions($object,'fichinter',$socid);
  1483. print '</div></div></div>';
  1484. }
  1485. /*
  1486. * Action presend
  1487. */
  1488. if (GETPOST('modelselected')) {
  1489. $action = 'presend';
  1490. }
  1491. if ($action == 'presend')
  1492. {
  1493. $ref = dol_sanitizeFileName($object->ref);
  1494. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  1495. $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
  1496. $file=$fileparams['fullname'];
  1497. // Define output language
  1498. $outputlangs = $langs;
  1499. $newlang = '';
  1500. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
  1501. $newlang = $_REQUEST['lang_id'];
  1502. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  1503. $newlang = $object->client->default_lang;
  1504. if (!empty($newlang))
  1505. {
  1506. $outputlangs = new Translate('', $conf);
  1507. $outputlangs->setDefaultLang($newlang);
  1508. $outputlangs->load('interventions');
  1509. }
  1510. // Build document if it not exists
  1511. if (! $file || ! is_readable($file))
  1512. {
  1513. $result=fichinter_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  1514. if ($result <= 0)
  1515. {
  1516. dol_print_error($db,$result);
  1517. exit;
  1518. }
  1519. $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+');
  1520. $file=$fileparams['fullname'];
  1521. }
  1522. print '<br>';
  1523. print_titre($langs->trans('SendInterventionByMail'));
  1524. // Create form object
  1525. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  1526. $formmail = new FormMail($db);
  1527. $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
  1528. $formmail->fromtype = 'user';
  1529. $formmail->fromid = $user->id;
  1530. $formmail->fromname = $user->getFullName($langs);
  1531. $formmail->frommail = $user->email;
  1532. $formmail->withfrom=1;
  1533. $liste=array();
  1534. foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value;
  1535. $formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste;
  1536. $formmail->withtocc=$liste;
  1537. $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
  1538. $formmail->withtopic=$outputlangs->trans('SendInterventionRef','__FICHINTERREF__');
  1539. $formmail->withfile=2;
  1540. $formmail->withbody=1;
  1541. $formmail->withdeliveryreceipt=1;
  1542. $formmail->withcancel=1;
  1543. // Tableau des substitutions
  1544. $formmail->substit['__FICHINTERREF__']=$object->ref;
  1545. $formmail->substit['__SIGNATURE__']=$user->signature;
  1546. $formmail->substit['__PERSONALIZED__']='';
  1547. $formmail->substit['__CONTACTCIVNAME__']='';
  1548. //Find the good contact adress
  1549. $custcontact='';
  1550. $contactarr=array();
  1551. $contactarr=$object->liste_contact(-1,'external');
  1552. if (is_array($contactarr) && count($contactarr)>0) {
  1553. foreach($contactarr as $contact) {
  1554. if ($contact['libelle']==$langs->trans('TypeContact_fichinter_external_CUSTOMER')) {
  1555. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  1556. $contactstatic=new Contact($db);
  1557. $contactstatic->fetch($contact['id']);
  1558. $custcontact=$contactstatic->getFullName($langs,1);
  1559. }
  1560. }
  1561. if (!empty($custcontact)) {
  1562. $formmail->substit['__CONTACTCIVNAME__']=$custcontact;
  1563. }
  1564. }
  1565. // Tableau des parametres complementaires
  1566. $formmail->param['action']='send';
  1567. $formmail->param['models']='fichinter_send';
  1568. $formmail->param['models_id']=GETPOST('modelmailselected','int');
  1569. $formmail->param['fichinter_id']=$object->id;
  1570. $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
  1571. // Init list of files
  1572. if (GETPOST("mode")=='init')
  1573. {
  1574. $formmail->clear_attached_files();
  1575. $formmail->add_attached_files($file,basename($file),dol_mimetype($file));
  1576. }
  1577. print $formmail->get_form();
  1578. print '<br>';
  1579. }
  1580. }
  1581. llxFooter();
  1582. $db->close();