card.php 61 KB

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