PageRenderTime 140ms CodeModel.GetById 38ms RepoModel.GetById 4ms app.codeStats 1ms

/htdocs/fichinter/fiche.php

https://github.com/abhimanyumohan/dolibarr
PHP | 1739 lines | 1310 code | 249 blank | 180 comment | 411 complexity | 4e023b309a6a54c3a5ba78519a26f3f5 MD5 | raw file
Possible License(s): GPL-3.0, CC-BY-SA-4.0, Apache-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file