PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/fichinter/fiche.php

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