PageRenderTime 53ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/fichinter/fiche.php

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