card.php 62 KB

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