card.php 64 KB

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