PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/fichinter/fiche.php

https://github.com/zeert/dolibarr
PHP | 1340 lines | 989 code | 190 blank | 161 comment | 300 complexity | 0d1fb32235ecd064764275bdbb5626b2 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
  5. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/fichinter/fiche.php
  22. * \brief Fichier fiche intervention
  23. * \ingroup ficheinter
  24. */
  25. require("../main.inc.php");
  26. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/fichinter/class/fichinter.class.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/modules/fichinter/modules_fichinter.php");
  29. require_once(DOL_DOCUMENT_ROOT."/core/lib/fichinter.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
  31. if ($conf->projet->enabled)
  32. {
  33. require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php");
  34. require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  35. }
  36. if (! empty($conf->global->FICHEINTER_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php"))
  37. {
  38. require_once(DOL_DOCUMENT_ROOT ."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php");
  39. }
  40. $langs->load("companies");
  41. $langs->load("interventions");
  42. $id = GETPOST('id','int');
  43. $ref = GETPOST('ref','alpha');
  44. $socid = GETPOST('socid','int');
  45. $action = GETPOST('action','alpha');
  46. $confirm = GETPOST('confirm','alpha');
  47. $mesg = GETPOST('msg','alpha');
  48. //PDF
  49. $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  50. $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  51. $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  52. // Security check
  53. if ($user->societe_id) $socid=$user->societe_id;
  54. $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
  55. $object = new Fichinter($db);
  56. /*
  57. * Actions
  58. */
  59. if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer)
  60. {
  61. $object->fetch($id);
  62. $object->fetch_thirdparty();
  63. $result = $object->setValid($user, $conf->fichinter->outputdir);
  64. if ($result >= 0)
  65. {
  66. // Define output language
  67. $outputlangs = $langs;
  68. $newlang='';
  69. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  70. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  71. if (! empty($newlang))
  72. {
  73. $outputlangs = new Translate("",$conf);
  74. $outputlangs->setDefaultLang($newlang);
  75. }
  76. $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs);
  77. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  78. exit;
  79. }
  80. else
  81. {
  82. $mesg='<div class="error">'.$object->error.'</div>';
  83. }
  84. }
  85. else if ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer)
  86. {
  87. $object->fetch($id);
  88. $object->fetch_thirdparty();
  89. $result = $object->setDraft($user);
  90. if ($result >= 0)
  91. {
  92. // Define output language
  93. $outputlangs = $langs;
  94. $newlang='';
  95. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  96. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  97. if (! empty($newlang))
  98. {
  99. $outputlangs = new Translate("",$conf);
  100. $outputlangs->setDefaultLang($newlang);
  101. }
  102. $result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->model:GETPOST('model','apha'), $outputlangs);
  103. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  104. exit;
  105. }
  106. else
  107. {
  108. $mesg='<div class="error">'.$object->error.'</div>';
  109. }
  110. }
  111. else if ($action == 'add' && $user->rights->ficheinter->creer)
  112. {
  113. $object->socid = $socid;
  114. $object->duree = GETPOST('duree','int');
  115. $object->fk_project = GETPOST('projectid','int');
  116. $object->author = $user->id;
  117. $object->description = GETPOST('description','alpha');
  118. $object->ref = $ref;
  119. $object->modelpdf = GETPOST('model','alpha');
  120. $object->note_private = GETPOST('note_private','alpha');
  121. $object->note_public = GETPOST('note_public','alpha');
  122. if ($object->socid > 0)
  123. {
  124. $result = $object->create();
  125. if ($result > 0)
  126. {
  127. $id=$result; // Force raffraichissement sur fiche venant d'etre cree
  128. }
  129. else
  130. {
  131. $langs->load("errors");
  132. $mesg='<div class="error">'.$langs->trans($object->error).'</div>';
  133. $action = 'create';
  134. }
  135. }
  136. else
  137. {
  138. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).'</div>';
  139. $action = 'create';
  140. }
  141. }
  142. else if ($action == 'update' && $user->rights->ficheinter->creer)
  143. {
  144. $object->fetch($id);
  145. $object->socid = $socid;
  146. $object->fk_project = GETPOST('projectid','int');
  147. $object->author = $user->id;
  148. $object->description = GETPOST('description','alpha');
  149. $object->ref = $ref;
  150. $object->update();
  151. }
  152. /*
  153. * Build doc
  154. */
  155. else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou en post
  156. {
  157. $object->fetch($id);
  158. $object->fetch_thirdparty();
  159. $object->fetch_lines();
  160. if (GETPOST('model','alpha'))
  161. {
  162. $object->setDocModel($user, GETPOST('model','alpha'));
  163. }
  164. // Define output language
  165. $outputlangs = $langs;
  166. $newlang='';
  167. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  168. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  169. if (! empty($newlang))
  170. {
  171. $outputlangs = new Translate("",$conf);
  172. $outputlangs->setDefaultLang($newlang);
  173. }
  174. $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs);
  175. if ($result <= 0)
  176. {
  177. dol_print_error($db,$result);
  178. exit;
  179. }
  180. }
  181. // Remove file in doc form
  182. else if ($action == 'remove_file')
  183. {
  184. if ($object->fetch($id))
  185. {
  186. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  187. $object->fetch_thirdparty();
  188. $langs->load("other");
  189. $upload_dir = $conf->ficheinter->dir_output;
  190. $file = $upload_dir . '/' . GETPOST('file');
  191. $ret=dol_delete_file($file,0,0,0,$object);
  192. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  193. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  194. }
  195. }
  196. // Set into a project
  197. else if ($action == 'classin' && $user->rights->ficheinter->creer)
  198. {
  199. $object->fetch($id);
  200. $result=$object->setProject(GETPOST('projectid','int'));
  201. if ($result < 0) dol_print_error($db,$object->error);
  202. }
  203. else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer)
  204. {
  205. $object->fetch($id);
  206. $object->fetch_thirdparty();
  207. $object->delete($user);
  208. Header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter');
  209. exit;
  210. }
  211. else if ($action == 'setdescription' && $user->rights->ficheinter->creer)
  212. {
  213. $object->fetch($id);
  214. $result=$object->set_description($user,GETPOST('description','alpha'));
  215. if ($result < 0) dol_print_error($db,$object->error);
  216. }
  217. else if ($action == 'setnote_public' && $user->rights->ficheinter->creer)
  218. {
  219. $object->fetch($id);
  220. $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
  221. if ($result < 0) dol_print_error($db,$object->error);
  222. }
  223. else if ($action == 'setnote_private' && $user->rights->ficheinter->creer)
  224. {
  225. $object->fetch($id);
  226. $result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES));
  227. if ($result < 0) dol_print_error($db,$object->error);
  228. }
  229. // Add line
  230. else if ($action == "addline" && $user->rights->ficheinter->creer)
  231. {
  232. if (!GETPOST('np_desc','alpha'))
  233. {
  234. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).'</div>';
  235. $error++;
  236. }
  237. if (!GETPOST('durationhour','int') && !GETPOST('durationmin','int'))
  238. {
  239. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Duration")).'</div>';
  240. $error++;
  241. }
  242. if (! $error)
  243. {
  244. $db->begin();
  245. $ret=$object->fetch($id);
  246. $object->fetch_thirdparty();
  247. $desc=GETPOST('np_desc','alpha');
  248. $date_intervention = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int'));
  249. $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int'));
  250. $result=$object->addline(
  251. $id,
  252. $desc,
  253. $date_intervention,
  254. $duration
  255. );
  256. // Define output language
  257. $outputlangs = $langs;
  258. $newlang='';
  259. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  260. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  261. if (! empty($newlang))
  262. {
  263. $outputlangs = new Translate("",$conf);
  264. $outputlangs->setDefaultLang($newlang);
  265. }
  266. if ($result >= 0)
  267. {
  268. $db->commit();
  269. fichinter_create($db, $object, $object->modelpdf, $outputlangs);
  270. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  271. exit;
  272. }
  273. else
  274. {
  275. $mesg=$object->error;
  276. $db->rollback();
  277. }
  278. }
  279. }
  280. // Classify Billed
  281. else if ($action == 'classifybilled' && $user->rights->ficheinter->creer)
  282. {
  283. $object->fetch($id);
  284. $result=$object->setBilled();
  285. if ($result > 0)
  286. {
  287. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  288. exit;
  289. }
  290. else
  291. {
  292. $mesg='<div class="error">'.$object->error.'</div>';
  293. }
  294. }
  295. /*
  296. * Mise a jour d'une ligne d'intervention
  297. */
  298. else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST('save','alpha') == $langs->trans("Save"))
  299. {
  300. $objectline = new FichinterLigne($db);
  301. if ($objectline->fetch(GETPOST('line_id','int')) <= 0)
  302. {
  303. dol_print_error($db);
  304. exit;
  305. }
  306. if ($object->fetch($objectline->fk_fichinter) <= 0)
  307. {
  308. dol_print_error($db);
  309. exit;
  310. }
  311. $object->fetch_thirdparty();
  312. $desc = GETPOST('np_desc','alpha');
  313. $date_inter = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int'));
  314. $duration = convertTime2Seconds(GETPOST('durationhour','int'),GETPOST('durationmin','int'));
  315. $objectline->datei = $date_inter;
  316. $objectline->desc = $desc;
  317. $objectline->duration = $duration;
  318. $result = $objectline->update();
  319. if ($result < 0)
  320. {
  321. dol_print_error($db);
  322. exit;
  323. }
  324. // Define output language
  325. $outputlangs = $langs;
  326. $newlang='';
  327. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  328. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  329. if (! empty($newlang))
  330. {
  331. $outputlangs = new Translate("",$conf);
  332. $outputlangs->setDefaultLang($newlang);
  333. }
  334. fichinter_create($db, $object, $object->modelpdf, $outputlangs);
  335. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  336. exit;
  337. }
  338. /*
  339. * Supprime une ligne d'intervention AVEC confirmation
  340. */
  341. else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->ficheinter->creer)
  342. {
  343. $objectline = new FichinterLigne($db);
  344. if ($objectline->fetch(GETPOST('line_id','int')) <= 0)
  345. {
  346. dol_print_error($db);
  347. exit;
  348. }
  349. $result=$objectline->deleteline();
  350. if ($object->fetch($objectline->fk_fichinter) <= 0)
  351. {
  352. dol_print_error($db);
  353. exit;
  354. }
  355. // Define output language
  356. $outputlangs = $langs;
  357. $newlang='';
  358. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  359. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  360. if (! empty($newlang))
  361. {
  362. $outputlangs = new Translate("",$conf);
  363. $outputlangs->setDefaultLang($newlang);
  364. }
  365. fichinter_create($db, $object, $object->modelpdf, $outputlangs);
  366. }
  367. /*
  368. * Ordonnancement des lignes
  369. */
  370. else if ($action == 'up' && $user->rights->ficheinter->creer)
  371. {
  372. $object->fetch($id);
  373. $object->fetch_thirdparty();
  374. $object->line_up(GETPOST('line_id','int'));
  375. // Define output language
  376. $outputlangs = $langs;
  377. $newlang='';
  378. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  379. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  380. if (! empty($newlang))
  381. {
  382. $outputlangs = new Translate("",$conf);
  383. $outputlangs->setDefaultLang($newlang);
  384. }
  385. fichinter_create($db, $object, $object->modelpdf, $outputlangs);
  386. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int'));
  387. exit;
  388. }
  389. else if ($action == 'down' && $user->rights->ficheinter->creer)
  390. {
  391. $object->fetch($id);
  392. $object->fetch_thirdparty();
  393. $object->line_down(GETPOST('line_id','int'));
  394. // Define output language
  395. $outputlangs = $langs;
  396. $newlang='';
  397. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  398. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  399. if (! empty($newlang))
  400. {
  401. $outputlangs = new Translate("",$conf);
  402. $outputlangs->setDefaultLang($newlang);
  403. }
  404. fichinter_create($db, $object, $object->modelpdf, $outputlangs);
  405. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int'));
  406. exit;
  407. }
  408. /*
  409. * Add file in email form
  410. */
  411. if (GETPOST('addfile','alpha'))
  412. {
  413. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  414. // Set tmp user directory TODO Use a dedicated directory for temp mails files
  415. $vardir=$conf->user->dir_output."/".$user->id;
  416. $upload_dir_tmp = $vardir.'/temp';
  417. dol_add_file_process($upload_dir_tmp,0,0);
  418. $action='presend';
  419. }
  420. /*
  421. * Remove file in email form
  422. */
  423. if (GETPOST('removedfile','alpha'))
  424. {
  425. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  426. // Set tmp user directory
  427. $vardir=$conf->user->dir_output."/".$user->id;
  428. $upload_dir_tmp = $vardir.'/temp';
  429. // TODO Delete only files that was uploaded from email form
  430. dol_remove_file_process(GETPOST('removedfile','alpha'),0);
  431. $action='presend';
  432. }
  433. /*
  434. * Send mail
  435. */
  436. if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send))
  437. {
  438. $langs->load('mails');
  439. if ($object->fetch($id) > 0)
  440. {
  441. // $objectref = dol_sanitizeFileName($object->ref);
  442. // $file = $conf->ficheinter->dir_output . '/' . $objectref . '/' . $objectref . '.pdf';
  443. // if (is_readable($file))
  444. // {
  445. $object->fetch_thirdparty();
  446. if (GETPOST('sendto','alpha'))
  447. {
  448. // Le destinataire a ete fourni via le champ libre
  449. $sendto = GETPOST('sendto','alpha');
  450. $sendtoid = 0;
  451. }
  452. elseif (GETPOST('receiver','alpha') != '-1')
  453. {
  454. // Recipient was provided from combo list
  455. if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
  456. {
  457. $sendto = $object->client->email;
  458. $sendtoid = 0;
  459. }
  460. else // Id du contact
  461. {
  462. $sendto = $object->client->contact_get_email(GETPOST('receiver','alpha'));
  463. $sendtoid = GETPOST('receiver','alpha');
  464. }
  465. }
  466. if (dol_strlen($sendto))
  467. {
  468. $langs->load("commercial");
  469. $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
  470. $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
  471. $message = GETPOST('message','alpha');
  472. $sendtocc = GETPOST('sendtocc','alpha');
  473. $deliveryreceipt = GETPOST('deliveryreceipt','alpha');
  474. if ($action == 'send')
  475. {
  476. if (strlen(GETPOST('subject','alphs'))) $subject = GETPOST('subject','alpha');
  477. else $subject = $langs->transnoentities('Intervention').' '.$object->ref;
  478. $actiontypecode='AC_FICH';
  479. $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
  480. if ($message)
  481. {
  482. $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
  483. $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
  484. $actionmsg.=$message;
  485. }
  486. $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
  487. }
  488. // Create form object
  489. include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
  490. $formmail = new FormMail($db);
  491. $attachedfiles=$formmail->get_attached_files();
  492. $filepath = $attachedfiles['paths'];
  493. $filename = $attachedfiles['names'];
  494. $mimetype = $attachedfiles['mimes'];
  495. // Envoi de la propal
  496. require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php');
  497. $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
  498. if ($mailfile->error)
  499. {
  500. $mesg='<div class="error">'.$mailfile->error.'</div>';
  501. }
  502. else
  503. {
  504. $result=$mailfile->sendfile();
  505. if ($result)
  506. {
  507. $mesg='<div class="ok">'.$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)).'.</div>';
  508. $error=0;
  509. // Initialisation donnees
  510. $object->sendtoid = $sendtoid;
  511. $object->actiontypecode = $actiontypecode;
  512. $object->actionmsg = $actionmsg;
  513. $object->actionmsg2 = $actionmsg2;
  514. $object->fk_element = $object->id;
  515. $object->elementtype = $object->element;
  516. // Appel des triggers
  517. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  518. $interface=new Interfaces($db);
  519. $result=$interface->run_triggers('FICHEINTER_SENTBYMAIL',$object,$user,$langs,$conf);
  520. if ($result < 0) { $error++; $this->errors=$interface->errors; }
  521. // Fin appel triggers
  522. if ($error)
  523. {
  524. dol_print_error($db);
  525. }
  526. else
  527. {
  528. // Redirect here
  529. // This avoid sending mail twice if going out and then back to page
  530. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&msg='.urlencode($mesg));
  531. exit;
  532. }
  533. }
  534. else
  535. {
  536. $langs->load("other");
  537. $mesg='<div class="error">';
  538. if ($mailfile->error)
  539. {
  540. $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
  541. $mesg.='<br>'.$mailfile->error;
  542. }
  543. else
  544. {
  545. $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
  546. }
  547. $mesg.='</div>';
  548. }
  549. }
  550. }
  551. else
  552. {
  553. $langs->load("other");
  554. $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
  555. dol_syslog('Recipient email is empty');
  556. }
  557. /*}
  558. else
  559. {
  560. $langs->load("errors");
  561. $mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
  562. dol_syslog('Failed to read file: '.$file);
  563. }*/
  564. }
  565. else
  566. {
  567. $langs->load("other");
  568. $mesg='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Intervention")).'</div>';
  569. dol_syslog('Impossible de lire les donnees de l\'intervention. Le fichier intervention n\'a peut-etre pas ete genere.');
  570. }
  571. $action='presend';
  572. }
  573. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  574. {
  575. if ($action == 'addcontact' && $user->rights->ficheinter->creer)
  576. {
  577. $result = $object->fetch($id);
  578. if ($result > 0 && $id > 0)
  579. {
  580. $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
  581. $result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha'));
  582. }
  583. if ($result >= 0)
  584. {
  585. Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  586. exit;
  587. }
  588. else
  589. {
  590. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  591. {
  592. $langs->load("errors");
  593. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  594. }
  595. else
  596. {
  597. $mesg = '<div class="error">'.$object->error.'</div>';
  598. }
  599. }
  600. }
  601. // bascule du statut d'un contact
  602. else if ($action == 'swapstatut' && $user->rights->ficheinter->creer)
  603. {
  604. if ($object->fetch($id))
  605. {
  606. $result=$object->swapContactStatus(GETPOST('ligne','int'));
  607. }
  608. else
  609. {
  610. dol_print_error($db);
  611. }
  612. }
  613. // Efface un contact
  614. else if ($action == 'deletecontact' && $user->rights->ficheinter->creer)
  615. {
  616. $object->fetch($id);
  617. $result = $object->delete_contact(GETPOST('lineid','int'));
  618. if ($result >= 0)
  619. {
  620. Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  621. exit;
  622. }
  623. else {
  624. dol_print_error($db);
  625. }
  626. }
  627. }
  628. /*
  629. * View
  630. */
  631. $form = new Form($db);
  632. $formfile = new FormFile($db);
  633. llxHeader();
  634. if ($action == 'create')
  635. {
  636. /*
  637. * Mode creation
  638. * Creation d'une nouvelle fiche d'intervention
  639. */
  640. $soc=new Societe($db);
  641. print_fiche_titre($langs->trans("AddIntervention"));
  642. dol_htmloutput_mesg($mesg);
  643. if (! $conf->global->FICHEINTER_ADDON)
  644. {
  645. dol_print_error($db,$langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"));
  646. exit;
  647. }
  648. $object->date = dol_now();
  649. $obj = $conf->global->FICHEINTER_ADDON;
  650. $obj = "mod_".$obj;
  651. $modFicheinter = new $obj;
  652. $numpr = $modFicheinter->getNextValue($soc, $object);
  653. if ($socid > 0)
  654. {
  655. $soc->fetch($socid);
  656. print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  657. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  658. print '<table class="border" width="100%">';
  659. print '<input type="hidden" name="socid" value='.$soc->id.'>';
  660. print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
  661. print '<input type="hidden" name="action" value="add">';
  662. // Ref
  663. print '<tr><td class="fieldrequired">'.$langs->trans("Ref").'</td>';
  664. print '<td><input name="ref" value="'.$numpr.'"></td></tr>'."\n";
  665. // Description (must be a textarea and not html must be allowed (used in list view)
  666. print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
  667. print '<td>';
  668. print '<textarea name="description" cols="80" rows="'.ROWS_3.'"></textarea>';
  669. print '</td></tr>';
  670. // Project
  671. if ($conf->projet->enabled)
  672. {
  673. $langs->load("project");
  674. print '<tr><td valign="top">'.$langs->trans("Project").'</td><td>';
  675. /* 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
  676. if ($societe->fournisseur==1)
  677. $numprojet=select_projects(-1,$_POST["projectid"],'projectid');
  678. else
  679. $numprojet=select_projects($societe->id,$_POST["projectid"],'projectid');
  680. */
  681. $numprojet=select_projects($soc->id,GETPOST('projectid','int'),'projectid');
  682. if ($numprojet==0)
  683. {
  684. print ' &nbsp; <a href="'.DOL_DOCUMENT_ROOT.'/projet/fiche.php?socid='.$soc->id.'&action=create">'.$langs->trans("AddProject").'</a>';
  685. }
  686. print '</td></tr>';
  687. }
  688. // Model
  689. print '<tr>';
  690. print '<td>'.$langs->trans("DefaultModel").'</td>';
  691. print '<td colspan="2">';
  692. $liste=ModelePDFFicheinter::liste_modeles($db);
  693. print $form->selectarray('model',$liste,$conf->global->FICHEINTER_ADDON_PDF);
  694. print "</td></tr>";
  695. // Public note
  696. print '<tr>';
  697. print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
  698. print '<td valign="top" colspan="2">';
  699. print '<textarea name="note_public" cols="80" rows="'.ROWS_3.'"></textarea>';
  700. print '</td></tr>';
  701. // Private note
  702. if (! $user->societe_id)
  703. {
  704. print '<tr>';
  705. print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
  706. print '<td valign="top" colspan="2">';
  707. print '<textarea name="note_private" cols="80" rows="'.ROWS_3.'"></textarea>';
  708. print '</td></tr>';
  709. }
  710. print '</table>';
  711. print '<center><br>';
  712. print '<input type="submit" class="button" value="'.$langs->trans("CreateDraftIntervention").'">';
  713. print '</center>';
  714. print '</form>';
  715. }
  716. else
  717. {
  718. print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  719. print '<table class="border" width="100%">';
  720. print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>';
  721. print $form->select_company('','socid','',1,1);
  722. print '</td></tr>';
  723. print '</table>';
  724. print '<br><center>';
  725. print '<input type="hidden" name="action" value="create">';
  726. print '<input type="submit" class="button" value="'.$langs->trans("CreateDraftIntervention").'">';
  727. print '</center>';
  728. print '</form>';
  729. }
  730. }
  731. else if ($id > 0 || ! empty($ref))
  732. {
  733. /*
  734. * Affichage en mode visu
  735. */
  736. $object->fetch($id, $ref);
  737. $object->fetch_thirdparty();
  738. $soc=new Societe($db);
  739. $soc->fetch($object->socid);
  740. dol_htmloutput_mesg($mesg);
  741. $head = fichinter_prepare_head($object);
  742. dol_fiche_head($head, 'card', $langs->trans("InterventionCard"), 0, 'intervention');
  743. // Confirmation de la suppression de la fiche d'intervention
  744. if ($action == 'delete')
  745. {
  746. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete','',0,1);
  747. if ($ret == 'html') print '<br>';
  748. }
  749. // Confirmation validation
  750. if ($action == 'validate')
  751. {
  752. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $langs->trans('ConfirmValidateIntervention'), 'confirm_validate','',0,1);
  753. if ($ret == 'html') print '<br>';
  754. }
  755. // Confirmation de la validation de la fiche d'intervention
  756. if ($action == 'modify')
  757. {
  758. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify','',0,1);
  759. if ($ret == 'html') print '<br>';
  760. }
  761. // Confirmation de la suppression d'une ligne d'intervention
  762. if ($action == 'ask_deleteline')
  763. {
  764. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.GETPOST('line_id','int'), $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline','',0,1);
  765. if ($ret == 'html') print '<br>';
  766. }
  767. print '<table class="border" width="100%">';
  768. $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  769. // Ref
  770. print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>';
  771. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  772. print '</td></tr>';
  773. // Third party
  774. print "<tr><td>".$langs->trans("Company")."</td><td>".$object->client->getNomUrl(1)."</td></tr>";
  775. // Duration
  776. print '<tr><td>'.$langs->trans("TotalDuration").'</td>';
  777. print '<td>'.convertSecondToTime($object->duree,'all',$conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
  778. print '</tr>';
  779. // Description (must be a textarea and not html must be allowed (used in list view)
  780. print '<tr><td valign="top">';
  781. print $form->editfieldkey("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea');
  782. print '</td><td colspan="3">';
  783. print $form->editfieldval("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea');
  784. print '</td>';
  785. print '</tr>';
  786. // Project
  787. if ($conf->projet->enabled)
  788. {
  789. $langs->load('projects');
  790. print '<tr>';
  791. print '<td>';
  792. print '<table class="nobordernopadding" width="100%"><tr><td>';
  793. print $langs->trans('Project');
  794. print '</td>';
  795. if ($action != 'classify')
  796. {
  797. print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
  798. print img_edit($langs->trans('SetProject'),1);
  799. print '</a></td>';
  800. }
  801. print '</tr></table>';
  802. print '</td><td colspan="3">';
  803. if ($action == 'classify')
  804. {
  805. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid');
  806. }
  807. else
  808. {
  809. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none');
  810. }
  811. print '</td>';
  812. print '</tr>';
  813. }
  814. // Statut
  815. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
  816. print "</table><br>";
  817. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  818. {
  819. require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
  820. require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
  821. $formcompany= new FormCompany($db);
  822. $blocname = 'contacts';
  823. $title = $langs->trans('ContactsAddresses');
  824. include(DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php');
  825. }
  826. if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  827. {
  828. $blocname = 'notes';
  829. $title = $langs->trans('Notes');
  830. include(DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php');
  831. }
  832. /*
  833. * Lignes d'intervention
  834. */
  835. $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,';
  836. $sql.= ' ft.date as date_intervention';
  837. $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
  838. $sql.= ' WHERE ft.fk_fichinter = '.$object->id;
  839. $sql.= ' ORDER BY ft.rang ASC, ft.rowid';
  840. $resql = $db->query($sql);
  841. if ($resql)
  842. {
  843. $num = $db->num_rows($resql);
  844. $i = 0;
  845. if ($num)
  846. {
  847. print '<table class="noborder" width="100%">';
  848. print '<tr class="liste_titre">';
  849. print '<td>'.$langs->trans('Description').'</td>';
  850. print '<td align="center">'.$langs->trans('Date').'</td>';
  851. print '<td align="right">'.$langs->trans('Duration').'</td>';
  852. print '<td width="48" colspan="3">&nbsp;</td>';
  853. print "</tr>\n";
  854. }
  855. $var=true;
  856. while ($i < $num)
  857. {
  858. $objp = $db->fetch_object($resql);
  859. $var=!$var;
  860. // Ligne en mode visu
  861. if ($action != 'editline' || GETPOST('line_id','int') != $objp->rowid)
  862. {
  863. print '<tr '.$bc[$var].'>';
  864. print '<td>';
  865. print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
  866. print dol_htmlentitiesbr($objp->description);
  867. // Date
  868. print '<td align="center" width="150">'.dol_print_date($db->jdate($objp->date_intervention),'dayhour').'</td>';
  869. // Duration
  870. print '<td align="right" width="150">'.convertSecondToTime($objp->duree).'</td>';
  871. print "</td>\n";
  872. // Icone d'edition et suppression
  873. if ($object->statut == 0 && $user->rights->ficheinter->creer)
  874. {
  875. print '<td align="center">';
  876. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;line_id='.$objp->rowid.'#'.$objp->rowid.'">';
  877. print img_edit();
  878. print '</a>';
  879. print '</td>';
  880. print '<td align="center">';
  881. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=ask_deleteline&amp;line_id='.$objp->rowid.'">';
  882. print img_delete();
  883. print '</a></td>';
  884. if ($num > 1)
  885. {
  886. print '<td align="center">';
  887. if ($i > 0)
  888. {
  889. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=up&amp;line_id='.$objp->rowid.'">';
  890. print img_up();
  891. print '</a>';
  892. }
  893. if ($i < $num-1)
  894. {
  895. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=down&amp;line_id='.$objp->rowid.'">';
  896. print img_down();
  897. print '</a>';
  898. }
  899. print '</td>';
  900. }
  901. }
  902. else
  903. {
  904. print '<td colspan="3">&nbsp;</td>';
  905. }
  906. print '</tr>';
  907. }
  908. // Ligne en mode update
  909. if ($object->statut == 0 && $action == 'editline' && $user->rights->ficheinter->creer && GETPOST('line_id','int') == $objp->rowid)
  910. {
  911. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$objp->rowid.'" method="post">';
  912. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  913. print '<input type="hidden" name="action" value="updateline">';
  914. print '<input type="hidden" name="id" value="'.$object->id.'">';
  915. print '<input type="hidden" name="line_id" value="'.GETPOST('line_id','int').'">';
  916. print '<tr '.$bc[$var].'>';
  917. print '<td>';
  918. print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
  919. // Editeur wysiwyg
  920. require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
  921. $doleditor=new DolEditor('np_desc',$objp->description,'',164,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,70);
  922. $doleditor->Create();
  923. print '</td>';
  924. // Date d'intervention
  925. print '<td align="center" nowrap="nowrap">';
  926. $form->select_date($db->jdate($objp->date_intervention),'di',1,1,0,"date_intervention");
  927. print '</td>';
  928. // Duration
  929. print '<td align="right">';
  930. $form->select_duration('duration',$objp->duree);
  931. print '</td>';
  932. print '<td align="center" colspan="5" valign="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
  933. print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
  934. print '</tr>' . "\n";
  935. print "</form>\n";
  936. }
  937. $i++;
  938. }
  939. $db->free($resql);
  940. /*
  941. * Add line
  942. */
  943. if ($object->statut == 0 && $user->rights->ficheinter->creer && $action <> 'editline')
  944. {
  945. if (! $num) print '<br><table class="noborder" width="100%">';
  946. print '<tr class="liste_titre">';
  947. print '<td>';
  948. print '<a name="add"></a>'; // ancre
  949. print $langs->trans('Description').'</td>';
  950. print '<td align="center">'.$langs->trans('Date').'</td>';
  951. print '<td align="right">'.$langs->trans('Duration').'</td>';
  952. print '<td colspan="4">&nbsp;</td>';
  953. print "</tr>\n";
  954. // Ajout ligne d'intervention
  955. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#add" name="addinter" method="post">';
  956. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  957. print '<input type="hidden" name="id" value="'.$object->id.'">';
  958. print '<input type="hidden" name="action" value="addline">';
  959. $var=false;
  960. print '<tr '.$bc[$var].">\n";
  961. print '<td>';
  962. // editeur wysiwyg
  963. require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
  964. $doleditor=new DolEditor('np_desc',GETPOST('np_desc','alpha'),'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,70);
  965. $doleditor->Create();
  966. print '</td>';
  967. // Date intervention
  968. print '<td align="center" nowrap="nowrap">';
  969. $now=dol_now();
  970. $timearray=dol_getdate($now);
  971. if (!GETPOST('diday','int')) $timewithnohour=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']);
  972. else $timewithnohour=dol_mktime(GETPOST('dihour','int'),GETPOST('dimin','int'), 0,GETPOST('dimonth','int'),GETPOST('diday','int'),GETPOST('diyear','int'));
  973. $form->select_date($timewithnohour,'di',1,1,0,"addinter");
  974. print '</td>';
  975. // Duration
  976. print '<td align="right">';
  977. $form->select_duration('duration',(!GETPOST('durationhour','int') && !GETPOST('durationmin','int'))?3600:(60*60*GETPOST('durationhour','int')+60*GETPOST('durationmin','int')));
  978. print '</td>';
  979. print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="'.$langs->trans('Add').'" name="addline"></td>';
  980. print '</tr>';
  981. print '</form>';
  982. if (! $num) print '</table>';
  983. }
  984. if ($num) print '</table>';
  985. }
  986. else
  987. {
  988. dol_print_error($db);
  989. }
  990. print '</div>';
  991. print "\n";
  992. /*
  993. * Barre d'actions
  994. */
  995. print '<div class="tabsAction">';
  996. if ($user->societe_id == 0)
  997. {
  998. if ($action != 'editdescription')
  999. {
  1000. // Validate
  1001. if ($object->statut == 0 && $user->rights->ficheinter->creer && count($object->lines) > 0)
  1002. {
  1003. print '<a class="butAction" href="fiche.php?id='.$object->id.'&action=validate"';
  1004. print '>'.$langs->trans("Valid").'</a>';
  1005. }
  1006. // Modify
  1007. if ($object->statut == 1 && $user->rights->ficheinter->creer)
  1008. {
  1009. print '<a class="butAction" href="fiche.php?id='.$object->id.'&action=modify"';
  1010. print '>'.$langs->trans("Modify").'</a>';
  1011. }
  1012. // Send
  1013. if ($object->statut > 0)
  1014. {
  1015. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send)
  1016. {
  1017. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
  1018. }
  1019. else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
  1020. }
  1021. // Invoicing
  1022. if ($conf->facture->enabled && $object->statut > 0)
  1023. {
  1024. $langs->load("bills");
  1025. if ($object->statut < 2)
  1026. {
  1027. if ($user->rights->facture->creer) print '<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("CreateBill").'</a>';
  1028. else print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CreateBill").'</a>';
  1029. }
  1030. if (! empty($conf->global->FICHEINTER_CLASSIFY_BILLED))
  1031. {
  1032. if ($object->statut != 2)
  1033. {
  1034. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled">'.$langs->trans("ClassifyBilled").'</a>';
  1035. }
  1036. }
  1037. }
  1038. // Delete
  1039. if (($object->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer)
  1040. {
  1041. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete"';
  1042. print '>'.$langs->trans('Delete').'</a>';
  1043. }
  1044. }
  1045. }
  1046. print '</div>';
  1047. print '<br>';
  1048. if ($action != 'presend')
  1049. {
  1050. print '<table width="100%"><tr><td width="50%" valign="top">';
  1051. /*
  1052. * Built documents
  1053. */
  1054. $filename=dol_sanitizeFileName($object->ref);
  1055. $filedir=$conf->ficheinter->dir_output . "/".$object->ref;
  1056. $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
  1057. $genallowed=$user->rights->ficheinter->creer;
  1058. $delallowed=$user->rights->ficheinter->supprimer;
  1059. $genallowed=1;
  1060. $delallowed=1;
  1061. $var=true;
  1062. //print "<br>\n";
  1063. $somethingshown=$formfile->show_documents('ficheinter',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
  1064. /*
  1065. * Linked object block
  1066. */
  1067. $somethingshown=$object->showLinkedObjectBlock();
  1068. print '</td><td valign="top" width="50%">';
  1069. // List of actions on element
  1070. include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
  1071. $formactions=new FormActions($db);
  1072. $somethingshown=$formactions->showactions($object,'fichinter',$socid);
  1073. print "</td><td>";
  1074. print "&nbsp;</td>";
  1075. print "</tr></table>\n";
  1076. }
  1077. /*
  1078. * Action presend
  1079. */
  1080. if ($action == 'presend')
  1081. {
  1082. $ref = dol_sanitizeFileName($object->ref);
  1083. include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
  1084. $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref);
  1085. $file=$fileparams['fullname'];
  1086. // Build document if it not exists
  1087. if (! $file || ! is_readable($file))
  1088. {
  1089. // Define output language
  1090. $outputlangs = $langs;
  1091. $newlang='';
  1092. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  1093. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  1094. if (! empty($newlang))
  1095. {
  1096. $outputlangs = new Translate("",$conf);
  1097. $outputlangs->setDefaultLang($newlang);
  1098. }
  1099. $result=fichinter_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
  1100. if ($result <= 0)
  1101. {
  1102. dol_print_error($db,$result);
  1103. exit;
  1104. }
  1105. $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref);
  1106. $file=$fileparams['fullname'];
  1107. }
  1108. print '<br>';
  1109. print_titre($langs->trans('SendInterventionByMail'));
  1110. // Create form object
  1111. include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
  1112. $formmail = new FormMail($db);
  1113. $formmail->fromtype = 'user';
  1114. $formmail->fromid = $user->id;
  1115. $formmail->fromname = $user->getFullName($langs);
  1116. $formmail->frommail = $user->email;
  1117. $formmail->withfrom=1;
  1118. $formmail->withto=(!GETPOST('sendto','alpha'))?1:GETPOST('sendto','alpha');
  1119. $formmail->withtosocid=$societe->id;
  1120. $formmail->withtocc=1;
  1121. $formmail->withtoccsocid=0;
  1122. $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
  1123. $formmail->withtocccsocid=0;
  1124. $formmail->withtopic=$langs->trans('SendInterventionRef','__FICHINTERREF__');
  1125. $formmail->withfile=2;
  1126. $formmail->withbody=1;
  1127. $formmail->withdeliveryreceipt=1;
  1128. $formmail->withcancel=1;
  1129. // Tableau des substitutions
  1130. $formmail->substit['__FICHINTERREF__']=$object->ref;
  1131. $formmail->substit['__SIGNATURE__']=$user->signature;
  1132. $formmail->substit['__PERSONALIZED__']='';
  1133. // Tableau des parametres complementaires
  1134. $formmail->param['action']='send';
  1135. $formmail->param['models']='fichinter_send';
  1136. $formmail->param['fichinter_id']=$object->id;
  1137. $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
  1138. // Init list of files
  1139. if (GETPOST("mode")=='init')
  1140. {
  1141. $formmail->clear_attached_files();
  1142. $formmail->add_attached_files($file,basename($file),dol_mimetype($file));
  1143. }
  1144. $formmail->show_form();
  1145. print '<br>';
  1146. }
  1147. }
  1148. llxFooter();
  1149. $db->close();
  1150. ?>