12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760 |
- <?php
- /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
- * Copyright (C) 2011-2020 Juanjo Menent <jmenent@2byte.es>
- * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
- * Copyright (C) 2014-2018 Ferran Marcet <fmarcet@2byte.es>
- * Copyright (C) 2014-2022 Charlene Benke <charlene@patas-monkey.com>
- * Copyright (C) 2015-2016 Abbes Bahfir <bafbes@gmail.com>
- * Copyright (C) 2018-2022 Philippe Grand <philippe.grand@atoo-net.com>
- * Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
- * Copyright (C) 2023 Benjamin Grembi <benjamin@oarces.fr>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/fichinter/card.php
- * \brief Page of intervention
- * \ingroup ficheinter
- */
- // Load Dolibarr environment
- require '../main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
- require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
- if (isModEnabled('project')) {
- require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
- }
- if (isModEnabled('contrat')) {
- require_once DOL_DOCUMENT_ROOT."/core/class/html.formcontract.class.php";
- require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
- }
- if (!empty($conf->global->FICHEINTER_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php")) {
- require_once DOL_DOCUMENT_ROOT."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.'.php';
- }
- require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
- // Load translation files required by the page
- $langs->loadLangs(array('bills', 'companies', 'interventions', 'stocks'));
- $id = GETPOST('id', 'int');
- $ref = GETPOST('ref', 'alpha');
- $ref_client = GETPOST('ref_client', 'alpha');
- $socid = (int) GETPOST('socid', 'int');
- $contratid = (int) GETPOST('contratid', 'int');
- $action = GETPOST('action', 'alpha');
- $cancel = GETPOST('cancel', 'alpha');
- $confirm = GETPOST('confirm', 'alpha');
- $backtopage = GETPOST('backtopage', 'alpha');
- $mesg = GETPOST('msg', 'alpha');
- $origin = GETPOST('origin', 'alpha');
- $originid = (GETPOST('originid', 'int') ?GETPOST('originid', 'int') : GETPOST('origin_id', 'int')); // For backward compatibility
- $note_public = GETPOST('note_public', 'restricthtml');
- $note_private = GETPOST('note_private', 'restricthtml');
- $lineid = GETPOST('line_id', 'int');
- $error = 0;
- //PDF
- $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
- $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
- $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
- // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
- $hookmanager->initHooks(array('interventioncard', 'globalcard'));
- $object = new Fichinter($db);
- $extrafields = new ExtraFields($db);
- $objectsrc = null;
- $extrafields->fetch_name_optionals_label($object->table_element);
- // Load object
- if ($id > 0 || !empty($ref)) {
- $ret = $object->fetch($id, $ref);
- if ($ret > 0) {
- $ret = $object->fetch_thirdparty();
- }
- if ($ret < 0) {
- dol_print_error('', $object->error);
- }
- }
- // Security check
- if ($user->socid) {
- $socid = $user->socid;
- }
- $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
- $permissionnote = $user->hasRight('ficheinter', 'creer'); // Used by the include of actions_setnotes.inc.php
- $permissiondellink = $user->hasRight('ficheinter', 'creer'); // Used by the include of actions_dellink.inc.php
- $permissiontodelete = (($object->statut == Fichinter::STATUS_DRAFT && $user->hasRight('ficheinter', 'creer')) || $user->rights->ficheinter->supprimer);
- $usercancreate = $user->hasRight('ficheinter', 'creer');
- /*
- * Actions
- */
- $parameters = array('socid'=>$socid);
- $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
- if ($reshook < 0) {
- setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
- }
- if (empty($reshook)) {
- $backurlforlist = DOL_URL_ROOT.'/fichinter/list.php';
- if (empty($backtopage) || ($cancel && empty($id))) {
- if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
- if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
- $backtopage = $backurlforlist;
- } else {
- $backtopage = DOL_URL_ROOT.'/fichinter/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
- }
- }
- }
- if ($cancel) {
- if (!empty($backtopageforcancel)) {
- header("Location: ".$backtopageforcancel);
- exit;
- } elseif (!empty($backtopage)) {
- header("Location: ".$backtopage);
- exit;
- }
- $action = '';
- }
- include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
- include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
- // Action clone object
- if ($action == 'confirm_clone' && $confirm == 'yes' && $user->hasRight('ficheinter', 'creer')) {
- if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
- setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
- } else {
- if ($object->id > 0) {
- // Because createFromClone modifies the object, we must clone it so that we can restore it later
- $orig = clone $object;
- $result = $object->createFromClone($user, $socid);
- if ($result > 0) {
- header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
- exit;
- } else {
- setEventMessages($object->error, $object->errors, 'errors');
- $object = $orig;
- $action = '';
- }
- }
- }
- }
- if ($action == 'confirm_validate' && $confirm == 'yes' && $user->hasRight('ficheinter', 'creer')) {
- $result = $object->setValid($user);
- if ($result >= 0) {
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- // Define output language
- $outputlangs = $langs;
- $newlang = '';
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
- $newlang = GETPOST('lang_id', 'aZ09');
- }
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
- $newlang = $object->thirdparty->default_lang;
- }
- if (!empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
- }
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
- } else {
- $mesg = $object->error;
- }
- } elseif ($action == 'confirm_modify' && $confirm == 'yes' && $user->hasRight('ficheinter', 'creer')) {
- $result = $object->setDraft($user);
- if ($result >= 0) {
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- // Define output language
- $outputlangs = $langs;
- $newlang = '';
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
- $newlang = GETPOST('lang_id', 'aZ09');
- }
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
- $newlang = $object->thirdparty->default_lang;
- }
- if (!empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
- }
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
- } else {
- $mesg = $object->error;
- }
- } elseif ($action == 'add' && $user->hasRight('ficheinter', 'creer')) {
- $selectedLines = GETPOST('toselect', 'array');
- $object->socid = $socid;
- $object->duration = (int) GETPOST('duration', 'int');
- $object->fk_project = (int) GETPOST('projectid', 'int');
- $object->fk_contrat = (int) GETPOST('contratid', 'int');
- $object->author = $user->id;
- $object->description = GETPOST('description', 'restricthtml');
- $object->ref = $ref;
- $object->ref_client = $ref_client;
- $object->model_pdf = GETPOST('model', 'alpha');
- $object->note_private = GETPOST('note_private', 'restricthtml');
- $object->note_public = GETPOST('note_public', 'restricthtml');
- if ($object->socid > 0) {
- // If creation from another object of another module (Example: origin=propal, originid=1)
- if (!empty($origin) && !empty($originid)) {
- // Parse element/subelement (ex: project_task)
- $regs = array();
- $element = $subelement = GETPOST('origin', 'alphanohtml');
- if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin', 'alphanohtml'), $regs)) {
- $element = $regs[1];
- $subelement = $regs[2];
- }
- // For compatibility
- if ($element == 'order') {
- $element = $subelement = 'commande';
- }
- if ($element == 'propal') {
- $element = 'comm/propal'; $subelement = 'propal';
- }
- if ($element == 'contract') {
- $element = $subelement = 'contrat';
- }
- $object->origin = $origin;
- $object->origin_id = $originid;
- // Possibility to add external linked objects with hooks
- $object->linked_objects[$object->origin] = $object->origin_id;
- if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) {
- $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
- }
- // Extrafields
- // Fill array 'array_options' with data from add form
- $ret = $extrafields->setOptionalsFromPost(null, $object);
- if ($ret < 0) {
- $error++;
- $action = 'create';
- }
- //$array_options = $extrafields->getOptionalsFromPost($object->table_element);
- //$object->array_options = $array_options;
- $id = $object->create($user);
- if ($id > 0) {
- dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
- $classname = ucfirst($subelement);
- $srcobject = new $classname($db);
- dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
- $result = $srcobject->fetch($object->origin_id);
- if ($result > 0) {
- $srcobject->fetch_thirdparty();
- $lines = $srcobject->lines;
- if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
- $srcobject->fetch_lines();
- $lines = $srcobject->lines;
- }
- if (is_array($lines)) {
- $num = count($lines);
- for ($i = 0; $i < $num; $i++) {
- if (!in_array($lines[$i]->id, $selectedLines)) {
- continue; // Skip unselected lines
- }
- $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : Product::TYPE_PRODUCT);
- if ($product_type == Product::TYPE_SERVICE || !empty($conf->global->FICHINTER_PRINT_PRODUCTS)) { //only services except if config includes products
- $duration = 3600; // Default to one hour
- // Predefined products & services
- if ($lines[$i]->fk_product > 0) {
- $prod = new Product($db);
- $prod->id = $lines[$i]->fk_product;
- // Define output language
- if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
- $prod->getMultiLangs();
- // We show if duration is present on service (so we get it)
- $prod->fetch($lines[$i]->fk_product);
- $outputlangs = $langs;
- $newlang = '';
- if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
- $newlang = GETPOST('lang_id', 'aZ09');
- }
- if (empty($newlang)) {
- $newlang = $srcobject->thirdparty->default_lang;
- }
- if (!empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label;
- } else {
- $prod->fetch($lines[$i]->fk_product);
- $label = $lines[$i]->product_label;
- }
- if ($prod->duration_value && $conf->global->FICHINTER_USE_SERVICE_DURATION) {
- switch ($prod->duration_unit) {
- default:
- case 'h':
- $mult = 3600;
- break;
- case 'd':
- $mult = 3600 * 24;
- break;
- case 'w':
- $mult = 3600 * 24 * 7;
- break;
- case 'm':
- $mult = (int) 3600 * 24 * (365 / 12); // Average month duration
- break;
- case 'y':
- $mult = 3600 * 24 * 365;
- break;
- }
- $duration = $prod->duration_value * $mult * $lines[$i]->qty;
- }
- $desc = $lines[$i]->product_ref;
- $desc .= ' - ';
- $desc .= $label;
- $desc .= '<br>';
- }
- // Common part (predefined or free line)
- $desc .= dol_htmlentitiesbr($lines[$i]->desc);
- $desc .= '<br>';
- $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')';
- $timearray = dol_getdate(dol_now());
- $date_intervention = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
- if ($product_type == Product::TYPE_PRODUCT) {
- $duration = 0;
- }
- $predef = '';
- // Extrafields
- $extrafields->fetch_name_optionals_label($object->table_element_line);
- $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
- $result = $object->addline(
- $user,
- $id,
- $desc,
- $date_intervention,
- $duration,
- $array_options
- );
- if ($result < 0) {
- $error++;
- break;
- }
- }
- }
- }
- } else {
- $langs->load("errors");
- setEventMessages($srcobject->error, $srcobject->errors, 'errors');
- $action = 'create';
- $error++;
- }
- } else {
- $langs->load("errors");
- setEventMessages($object->error, $object->errors, 'errors');
- $action = 'create';
- $error++;
- }
- } else {
- // Fill array 'array_options' with data from add form
- $ret = $extrafields->setOptionalsFromPost(null, $object);
- if ($ret < 0) {
- $error++;
- $action = 'create';
- }
- if (!$error) {
- // Extrafields
- $array_options = $extrafields->getOptionalsFromPost($object->table_element);
- $object->array_options = $array_options;
- $result = $object->create($user);
- if ($result > 0) {
- $id = $result; // Force raffraichissement sur fiche venant d'etre cree
- } else {
- $langs->load("errors");
- setEventMessages($object->error, $object->errors, 'errors');
- $action = 'create';
- $error++;
- }
- }
- }
- } else {
- $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty"));
- $action = 'create';
- $error++;
- }
- } elseif ($action == 'update' && $user->hasRight('ficheinter', 'creer')) {
- $object->socid = $socid;
- $object->fk_project = (int) GETPOST('projectid', 'int');
- $object->fk_contrat = (int) GETPOST('contratid', 'int');
- $object->author = $user->id;
- $object->description = GETPOST('description', 'restricthtml');
- $object->ref = $ref;
- $object->ref_client = $ref_client;
- $result = $object->update($user);
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- } elseif ($action == 'classin' && $user->hasRight('ficheinter', 'creer')) {
- // Set into a project
- $result = $object->setProject(GETPOST('projectid', 'int'));
- if ($result < 0) {
- dol_print_error($db, $object->error);
- }
- } elseif ($action == 'setcontract' && $user->hasRight('contrat', 'creer')) {
- // Set into a contract
- $result = $object->set_contrat($user, GETPOST('contratid', 'int'));
- if ($result < 0) {
- dol_print_error($db, $object->error);
- }
- } elseif ($action == 'setref_client' && $user->hasRight('ficheinter', 'creer')) {
- // Positionne ref client
- $result = $object->setRefClient($user, GETPOST('ref_client', 'alpha'));
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer) {
- $result = $object->delete($user);
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter&restore_lastsearch_values=1');
- exit;
- } elseif ($action == 'setdescription' && $user->hasRight('ficheinter', 'creer')) {
- $result = $object->set_description($user, GETPOST('description'));
- if ($result < 0) {
- dol_print_error($db, $object->error);
- }
- } elseif ($action == "addline" && $user->hasRight('ficheinter', 'creer')) {
- // Add line
- if (!GETPOST('np_desc', 'restricthtml') && empty($conf->global->FICHINTER_EMPTY_LINE_DESC)) {
- $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description"));
- $error++;
- }
- if (empty($conf->global->FICHINTER_WITHOUT_DURATION) && !GETPOST('durationhour', 'int') && !GETPOST('durationmin', 'int')) {
- $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Duration"));
- $error++;
- }
- if (empty($conf->global->FICHINTER_WITHOUT_DURATION) && GETPOST('durationhour', 'int') >= 24 && GETPOST('durationmin', 'int') > 0) {
- $mesg = $langs->trans("ErrorValueTooHigh");
- $error++;
- }
- if (!$error) {
- $db->begin();
- $desc = GETPOST('np_desc', 'restricthtml');
- $date_intervention = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int'));
- $duration = empty($conf->global->FICHINTER_WITHOUT_DURATION) ? convertTime2Seconds(GETPOST('durationhour', 'int'), GETPOST('durationmin', 'int')) : 0;
- // Extrafields
- $extrafields->fetch_name_optionals_label($object->table_element_line);
- $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
- $result = $object->addline(
- $user,
- $id,
- $desc,
- $date_intervention,
- $duration,
- $array_options
- );
- // Define output language
- $outputlangs = $langs;
- $newlang = '';
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
- $newlang = GETPOST('lang_id', 'aZ09');
- }
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
- $newlang = $object->thirdparty->default_lang;
- }
- if (!empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- if ($result >= 0) {
- $db->commit();
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- fichinter_create($db, $object, $object->model_pdf, $outputlangs);
- }
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
- } else {
- $mesg = $object->error;
- $db->rollback();
- }
- }
- } elseif ($action == 'classifybilled' && $user->hasRight('ficheinter', 'creer')) {
- // Classify Billed
- $result = $object->setStatut(Fichinter::STATUS_BILLED);
- if ($result > 0) {
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
- } else {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- } elseif ($action == 'classifyunbilled' && $user->hasRight('ficheinter', 'creer')) {
- // Classify unbilled
- $result = $object->setStatut(Fichinter::STATUS_VALIDATED);
- if ($result > 0) {
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
- } else {
- $mesg = $object->error;
- }
- } elseif ($action == 'classifydone' && $user->hasRight('ficheinter', 'creer')) {
- // Classify Done
- $result = $object->setStatut(Fichinter::STATUS_CLOSED);
- if ($result > 0) {
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
- } else {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- } elseif ($action == 'confirm_reopen' && $user->hasRight('ficheinter', 'creer')) {
- // Reopen
- $result = $object->setStatut(Fichinter::STATUS_VALIDATED);
- if ($result > 0) {
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
- } else {
- $mesg = $object->error;
- }
- } elseif ($action == 'updateline' && $user->hasRight('ficheinter', 'creer') && GETPOST('save', 'alpha')) {
- // Mise a jour d'une ligne d'intervention
- $objectline = new FichinterLigne($db);
- if ($objectline->fetch($lineid) <= 0) {
- dol_print_error($db);
- exit;
- }
- if ($object->fetch($objectline->fk_fichinter) <= 0) {
- dol_print_error($db);
- exit;
- }
- $object->fetch_thirdparty();
- $desc = GETPOST('np_desc', 'restricthtml');
- $date_inter = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int'));
- $duration = convertTime2Seconds(GETPOST('durationhour', 'int'), GETPOST('durationmin', 'int'));
- $objectline->date = $date_inter;
- $objectline->desc = $desc;
- $objectline->duration = $duration;
- // Extrafields
- $extrafields->fetch_name_optionals_label($object->table_element_line);
- $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
- $objectline->array_options = array_merge($objectline->array_options, $array_options);
- $result = $objectline->update($user);
- if ($result < 0) {
- dol_print_error($db);
- exit;
- }
- // Define output language
- $outputlangs = $langs;
- $newlang = '';
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
- $newlang = GETPOST('lang_id', 'aZ09');
- }
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
- $newlang = $object->thirdparty->default_lang;
- }
- if (!empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- fichinter_create($db, $object, $object->model_pdf, $outputlangs);
- }
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
- } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->hasRight('ficheinter', 'creer')) {
- // Supprime une ligne d'intervention AVEC confirmation
- $objectline = new FichinterLigne($db);
- if ($objectline->fetch($lineid) <= 0) {
- dol_print_error($db);
- exit;
- }
- $result = $objectline->deleteline($user);
- if ($object->fetch($objectline->fk_fichinter) <= 0) {
- dol_print_error($db);
- exit;
- }
- // Define output language
- $outputlangs = $langs;
- $newlang = '';
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
- $newlang = GETPOST('lang_id', 'aZ09');
- }
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
- $newlang = $object->thirdparty->default_lang;
- }
- if (!empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- fichinter_create($db, $object, $object->model_pdf, $outputlangs);
- }
- } elseif ($action == 'up' && $user->hasRight('ficheinter', 'creer')) {
- // Set position of lines
- $object->line_up($lineid);
- // Define output language
- $outputlangs = $langs;
- $newlang = '';
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
- $newlang = GETPOST('lang_id', 'aZ09');
- }
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
- $newlang = $object->thirdparty->default_lang;
- }
- if (!empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- fichinter_create($db, $object, $object->model_pdf, $outputlangs);
- }
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
- exit;
- } elseif ($action == 'down' && $user->hasRight('ficheinter', 'creer')) {
- $object->line_down($lineid);
- // Define output language
- $outputlangs = $langs;
- $newlang = '';
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
- $newlang = GETPOST('lang_id', 'aZ09');
- }
- if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
- $newlang = $object->thirdparty->default_lang;
- }
- if (!empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- fichinter_create($db, $object, $object->model_pdf, $outputlangs);
- }
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
- exit;
- }
- // Actions when printing a doc from card
- include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
- // Actions to send emails
- $triggersendname = 'FICHINTER_SENTBYMAIL';
- $autocopy = 'MAIN_MAIL_AUTOCOPY_FICHINTER_TO';
- $trackid = 'int'.$object->id;
- include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
- // Actions to build doc
- $upload_dir = $conf->ficheinter->dir_output;
- $permissiontoadd = $user->rights->ficheinter->creer;
- include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
- if ($action == 'update_extras') {
- $object->oldcopy = dol_clone($object);
- // Fill array 'array_options' with data from update form
- $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
- if ($ret < 0) {
- $error++;
- }
- if (!$error) {
- // Actions on extra fields
- $result = $object->insertExtraFields('INTERVENTION_MODIFY');
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- $error++;
- }
- }
- if ($error) {
- $action = 'edit_extras';
- }
- }
- if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->hasRight('ficheinter', 'creer')) {
- if ($action == 'addcontact') {
- if ($result > 0 && $id > 0) {
- $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
- $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
- $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
- }
- if ($result >= 0) {
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
- exit;
- } else {
- if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
- $langs->load("errors");
- $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
- } else {
- $mesg = $object->error;
- }
- }
- } elseif ($action == 'swapstatut') {
- // bascule du statut d'un contact
- $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
- } elseif ($action == 'deletecontact') {
- // Efface un contact
- $result = $object->delete_contact(GETPOST('lineid', 'int'));
- if ($result >= 0) {
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
- exit;
- } else {
- dol_print_error($db);
- }
- }
- }
- }
- /*
- * View
- */
- $form = new Form($db);
- $formfile = new FormFile($db);
- if (isModEnabled('contrat')) {
- $formcontract = new FormContract($db);
- }
- if (isModEnabled('project')) {
- $formproject = new FormProjets($db);
- }
- $help_url = 'EN:Module_Interventions';
- llxHeader('', $langs->trans("Intervention"), $help_url);
- if ($action == 'create') {
- // Create new intervention
- $soc = new Societe($db);
- print load_fiche_titre($langs->trans("AddIntervention"), '', 'intervention');
- if ($error > 0) {
- dol_htmloutput_errors($mesg);
- } else {
- dol_htmloutput_mesg($mesg);
- }
- if ($socid) {
- $res = $soc->fetch($socid);
- }
- if (GETPOST('origin', 'alphanohtml') && GETPOST('originid', 'int')) {
- // Parse element/subelement (ex: project_task)
- $regs = array();
- $element = $subelement = GETPOST('origin', 'alphanohtml');
- if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin', 'alphanohtml'), $regs)) {
- $element = $regs[1];
- $subelement = $regs[2];
- }
- if ($element == 'project') {
- $projectid = GETPOST('originid', 'int');
- } else {
- // For compatibility
- if ($element == 'order' || $element == 'commande') {
- $element = $subelement = 'commande';
- }
- if ($element == 'propal') {
- $element = 'comm/propal'; $subelement = 'propal';
- }
- if ($element == 'contract') {
- $element = $subelement = 'contrat';
- }
- dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
- $classname = ucfirst($subelement);
- $objectsrc = new $classname($db);
- $objectsrc->fetch(GETPOST('originid'));
- if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
- $objectsrc->fetch_lines();
- $lines = $objectsrc->lines;
- }
- $objectsrc->fetch_thirdparty();
- $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
- $soc = $objectsrc->thirdparty;
- $note_private = (!empty($objectsrc->note) ? $objectsrc->note : (!empty($objectsrc->note_private) ? $objectsrc->note_private : GETPOST('note_private', 'restricthtml')));
- $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public : GETPOST('note_public', 'restricthtml'));
- // Replicate extrafields
- $objectsrc->fetch_optionals();
- $object->array_options = $objectsrc->array_options;
- // Object source contacts list
- $srccontactslist = $objectsrc->liste_contact(-1, 'external', 1);
- }
- } else {
- $projectid = GETPOST('projectid', 'int');
- }
- if (!$conf->global->FICHEINTER_ADDON) {
- dol_print_error($db, $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"));
- exit;
- }
- $object->date = dol_now();
- $obj = $conf->global->FICHEINTER_ADDON;
- $obj = "mod_".$obj;
- //$modFicheinter = new $obj;
- //$numpr = $modFicheinter->getNextValue($soc, $object);
- if ($socid > 0) {
- $soc = new Societe($db);
- $soc->fetch($socid);
- print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="socid" value='.$soc->id.'>';
- print '<input type="hidden" name="action" value="add">';
- print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
- print dol_get_fiche_head('');
- print '<table class="border centpercent">';
- print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("ThirdParty").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
- // Ref
- print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans("Draft").'</td></tr>';
- // Ref customer
- print '<tr class="field_ref_client"><td class="titlefieldcreate">'.$langs->trans('RefCustomer').'</td><td class="valuefieldcreate">';
- print '<input type="text" name="ref_client" value="'.GETPOST('ref_client').'"></td>';
- print '</tr>';
- // Description (must be a textarea and not html must be allowed (used in list view)
- print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
- print '<td>';
- print '<textarea name="description" class="quatrevingtpercent" rows="'.ROWS_3.'">'.GETPOST('description').'</textarea>';
- print '</td></tr>';
- // Project
- if (isModEnabled('project')) {
- $formproject = new FormProjets($db);
- $langs->load("project");
- print '<tr><td>'.$langs->trans("Project").'</td><td>';
- /* 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
- if ($societe->fournisseur==1)
- $numprojet=select_projects(-1, GETPOST("projectid", 'int'), 'projectid');
- else
- $numprojet=select_projects($societe->id, GETPOST("projectid", 'int'), 'projectid');
- */
- $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid');
- if ($numprojet == 0) {
- print ' <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>';
- }
- print '</td></tr>';
- }
- // Contract
- if (isModEnabled('contrat')) {
- $langs->load("contracts");
- print '<tr><td>'.$langs->trans("Contract").'</td><td>';
- $numcontrat = $formcontract->select_contract($soc->id, GETPOST('contratid', 'int'), 'contratid', 0, 1, 1);
- if ($numcontrat == 0) {
- print ' <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>';
- }
- print '</td></tr>';
- }
- // Model
- print '<tr>';
- print '<td>'.$langs->trans("DefaultModel").'</td>';
- print '<td>';
- $liste = ModelePDFFicheinter::liste_modeles($db);
- print $form->selectarray('model', $liste, $conf->global->FICHEINTER_ADDON_PDF);
- print "</td></tr>";
- // Public note
- print '<tr>';
- print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
- print '<td>';
- $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%');
- print $doleditor->Create(1);
- //print '<textarea name="note_public" cols="80" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
- print '</td></tr>';
- // Private note
- if (empty($user->socid)) {
- print '<tr>';
- print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
- print '<td>';
- $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%');
- print $doleditor->Create(1);
- //print '<textarea name="note_private" cols="80" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
- print '</td></tr>';
- }
- // Other attributes
- $parameters = array();
- $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- if (empty($reshook)) {
- print $object->showOptionals($extrafields, 'create');
- }
- // Show link to origin object
- if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
- $newclassname = $classname;
- if ($newclassname == 'Propal') {
- $newclassname = 'CommercialProposal';
- }
- print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
- // Amount
- /* Hide amount because we only copy services so amount may differ than source
- print '<tr><td>' . $langs->trans('AmountHT') . '</td><td>' . price($objectsrc->total_ht) . '</td></tr>';
- print '<tr><td>' . $langs->trans('AmountVAT') . '</td><td>' . price($objectsrc->total_tva) . "</td></tr>";
- if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) // Localtax1 RE
- {
- print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax1) . "</td></tr>";
- }
- if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2 IRPF
- {
- print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax2) . "</td></tr>";
- }
- print '<tr><td>' . $langs->trans('AmountTTC') . '</td><td>' . price($objectsrc->total_ttc) . "</td></tr>";
- if (isModEnabled("multicurrency"))
- {
- print '<tr><td>' . $langs->trans('MulticurrencyAmountHT') . '</td><td>' . price($objectsrc->multicurrency_total_ht) . '</td></tr>';
- print '<tr><td>' . $langs->trans('MulticurrencyAmountVAT') . '</td><td>' . price($objectsrc->multicurrency_total_tva) . "</td></tr>";
- print '<tr><td>' . $langs->trans('MulticurrencyAmountTTC') . '</td><td>' . price($objectsrc->multicurrency_total_ttc) . "</td></tr>";
- }
- */
- }
- print '</table>';
- if (is_object($objectsrc)) {
- print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
- print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
- } elseif ($origin == 'project' && !empty($projectid)) {
- print '<input type="hidden" name="projectid" value="'.$projectid.'">';
- }
- print dol_get_fiche_end();
- print $form->buttonsSaveCancel("CreateDraftIntervention");
- // Show origin lines
- if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
- $title = $langs->trans('Services');
- print load_fiche_titre($title);
- print '<div class="div-table-responsive-no-min">';
- print '<table class="noborder centpercent">';
- $objectsrc->printOriginLinesList(empty($conf->global->FICHINTER_PRINT_PRODUCTS) ? 'services' : ''); // Show only service, except if option FICHINTER_PRINT_PRODUCTS is on
- print '</table>';
- print '</div>';
- }
- print '</form>';
- } else {
- print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="create">'; // We go back to create action
- print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
- print dol_get_fiche_head('');
- if (is_object($objectsrc)) {
- print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
- print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
- } elseif ($origin == 'project' && !empty($projectid)) {
- print '<input type="hidden" name="projectid" value="'.$projectid.'">';
- }
- print '<table class="border centpercent">';
- print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>';
- print $form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, null, 0, 'minwidth300');
- 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>';
- print '</td></tr>';
- print '</table>';
- print dol_get_fiche_end();
- print $form->buttonsSaveCancel("CreateDraftIntervention");
- print '</form>';
- }
- } elseif ($id > 0 || !empty($ref)) {
- // View mode
- $object->fetch($id, $ref);
- $object->fetch_thirdparty();
- $soc = new Societe($db);
- $soc->fetch($object->socid);
- if ($error > 0) {
- dol_htmloutput_errors($mesg);
- } else {
- dol_htmloutput_mesg($mesg);
- }
- $head = fichinter_prepare_head($object);
- print dol_get_fiche_head($head, 'card', $langs->trans("InterventionCard"), -1, 'intervention');
- $formconfirm = '';
- // Confirm deletion of intervention
- if ($action == 'delete') {
- $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete', '', 0, 1);
- }
- // Confirm validation
- if ($action == 'validate') {
- // on verifie si l'objet est en numerotation provisoire
- $ref = substr($object->ref, 1, 4);
- if ($ref == 'PROV') {
- $numref = $object->getNextNumRef($soc);
- if (empty($numref)) {
- $error++;
- setEventMessages($object->error, $object->errors, 'errors');
- }
- } else {
- $numref = $object->ref;
- }
- $text = $langs->trans('ConfirmValidateIntervention', $numref);
- $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $text, 'confirm_validate', '', 1, 1);
- }
- // Confirm back to draft
- if ($action == 'modify') {
- $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify', '', 0, 1);
- }
- // Confirm back to open
- if ($action == 'reopen') {
- $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReopenIntervention', $object->ref), 'confirm_reopen', '', 0, 1);
- }
- // Confirm deletion of line
- if ($action == 'ask_deleteline') {
- $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.$lineid, $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline', '', 0, 1);
- }
- // Clone confirmation
- if ($action == 'clone') {
- // Create an array for form
- $formquestion = array(
- // 'text' => $langs->trans("ConfirmClone"),
- // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
- // 1),
- // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
- // => 1),
- array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '', '', 0, 0, null, 0, 'minwidth200')));
- // Paiement incomplet. On demande si motif = escompte ou autre
- $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneIntervention', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
- }
- if (!$formconfirm) {
- $parameters = array('formConfirm' => $formconfirm, 'lineid'=>$lineid);
- $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- if (empty($reshook)) {
- $formconfirm .= $hookmanager->resPrint;
- } elseif ($reshook > 0) {
- $formconfirm = $hookmanager->resPrint;
- }
- }
- // Print form confirm
- print $formconfirm;
- // Intervention card
- $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
- $morehtmlref = '<div class="refidno">';
- // Ref customer
- $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', 0, 1);
- $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1);
- // Thirdparty
- $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
- // Project
- if (isModEnabled('project')) {
- $langs->load("projects");
- $morehtmlref .= '<br>';
- if ($usercancreate) {
- $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
- if ($action != 'classify') {
- $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
- }
- $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
- } else {
- if (!empty($object->fk_project)) {
- $proj = new Project($db);
- $proj->fetch($object->fk_project);
- $morehtmlref .= $proj->getNomUrl(1);
- if ($proj->title) {
- $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
- }
- }
- }
- }
- $morehtmlref .= '</div>';
- dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
- print '<div class="fichecenter">';
- print '<div class="fichehalfleft">';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border tableforfield centpercent">';
- if (!empty($conf->global->FICHINTER_USE_PLANNED_AND_DONE_DATES)) {
- // Date Start
- print '<tr><td class="titlefield">'.$langs->trans("Dateo").'</td>';
- print '<td>';
- print $object->dateo ? dol_print_date($object->dateo, 'daytext') : ' ';
- print '</td>';
- print '</tr>';
- // Date End
- print '<tr><td>'.$langs->trans("Datee").'</td>';
- print '<td>';
- print $object->datee ? dol_print_date($object->datee, 'daytext') : ' ';
- print '</td>';
- print '</tr>';
- // Date Terminate/close
- print '<tr><td>'.$langs->trans("Datet").'</td>';
- print '<td>';
- print $object->datet ? dol_print_date($object->datet, 'daytext') : ' ';
- print '</td>';
- print '</tr>';
- }
- // Description (must be a textarea and not html must be allowed (used in list view)
- print '<tr><td class="titlefield">';
- print $form->editfieldkey("Description", 'description', $object->description, $object, $user->rights->ficheinter->creer, 'textarea');
- print '</td><td>';
- print $form->editfieldval("Description", 'description', $object->description, $object, $user->rights->ficheinter->creer, 'textarea:8');
- print '</td>';
- print '</tr>';
- // Contract
- if (isModEnabled('contrat')) {
- $langs->load('contracts');
- print '<tr>';
- print '<td>';
- print '<table class="nobordernopadding centpercent"><tr><td>';
- print $langs->trans('Contract');
- print '</td>';
- if ($action != 'contrat') {
- print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=contrat&id='.$object->id.'">';
- print img_edit($langs->trans('SetContract'), 1);
- print '</a></td>';
- }
- print '</tr></table>';
- print '</td><td>';
- if ($action == 'contrat') {
- $formcontract = new Formcontract($db);
- $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contrat, 'contratid', 0, 1, 1);
- } else {
- if ($object->fk_contrat) {
- $contratstatic = new Contrat($db);
- $contratstatic->fetch($object->fk_contrat);
- //print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
- print $contratstatic->getNomUrl(0, '', 1);
- } else {
- print " ";
- }
- }
- print '</td>';
- print '</tr>';
- }
- // Other attributes
- $cols = 2;
- include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
- print '</table>';
- print '</div>';
- print '<div class="fichehalfright">';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border tableforfield centpercent">';
- if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
- // Duration in time
- print '<tr><td class="titlefield">'.$langs->trans("TotalDuration").'</td>';
- print '<td>'.convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).' ('.convertDurationtoHour($object->duration, "s").' '.$langs->trans("h").')</td>';
- print '</tr>';
- }
- print "</table>";
- print '</div>';
- print '</div>';
- print '<div class="clearboth"></div><br>';
- if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
- $blocname = 'contacts';
- $title = $langs->trans('ContactsAddresses');
- include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
- }
- if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
- $blocname = 'notes';
- $title = $langs->trans('Notes');
- include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
- }
- // Line of interventions
- if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
- print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" name="addinter" method="post">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="id" value="'.$object->id.'">';
- if ($action == 'editline') {
- print '<input type="hidden" name="action" value="updateline">';
- print '<input type="hidden" name="line_id" value="'.GETPOST('line_id', 'int').'">';
- } else {
- print '<input type="hidden" name="action" value="addline">';
- }
- print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
- // Intervention lines
- $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,';
- $sql .= ' ft.date as date_intervention';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
- $sql .= ' WHERE ft.fk_fichinter = '.((int) $object->id);
- if (!empty($conf->global->FICHINTER_HIDE_EMPTY_DURATION)) {
- $sql .= ' AND ft.duree <> 0';
- }
- $sql .= ' ORDER BY ft.rang ASC, ft.date ASC, ft.rowid';
- $resql = $db->query($sql);
- if ($resql) {
- $num = $db->num_rows($resql);
- $i = 0;
- if ($num) {
- print '<br>';
- print '<table class="noborder centpercent">';
- print '<tr class="liste_titre">';
- // No.
- if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
- print '<td width="5" class="center linecolnum"></td>';
- }
- print '<td class="liste_titre">'.$langs->trans('Description').'</td>';
- print '<td class="liste_titre center">'.$langs->trans('Date').'</td>';
- print '<td class="liste_titre right">'.(empty($conf->global->FICHINTER_WITHOUT_DURATION) ? $langs->trans('Duration') : '').'</td>';
- print '<td class="liste_titre"> </td>';
- print '<td class="liste_titre"> </td>';
- print "</tr>\n";
- }
- while ($i < $num) {
- $objp = $db->fetch_object($resql);
- // Ligne en mode visu
- if ($action != 'editline' || GETPOST('line_id', 'int') != $objp->rowid) {
- print '<tr class="oddeven">';
- // No.
- if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
- print '<td class="center linecolnum">'.($i + 1).'</td>';
- }
- print '<td>';
- print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
- print dol_htmlentitiesbr($objp->description);
- $objectline = new FichinterLigne($db);
- $objectline->fetch($objp->rowid);
- $objectline->fetch_optionals();
- $extrafields->fetch_name_optionals_label($objectline->table_element);
- if (!empty($extrafields)) {
- $temps = $objectline->showOptionals($extrafields, 'view', array(), '', '', 1, 'line');
- if (!empty($temps)) {
- print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
- print $temps;
- print '</div>';
- }
- }
- print '</td>';
- // Date
- 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>';
- // Duration
- print '<td class="right" width="150">'.(empty($conf->global->FICHINTER_WITHOUT_DURATION) ?convertSecondToTime($objp->duree) : '').'</td>';
- print "</td>\n";
- // Icon to edit and delete
- if ($object->statut == 0 && $user->hasRight('ficheinter', 'creer')) {
- print '<td class="center">';
- print '<a class="editfielda marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&line_id='.$objp->rowid.'#'.$objp->rowid.'">';
- print img_edit();
- print '</a>';
- print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=ask_deleteline&token='.newToken().'&line_id='.$objp->rowid.'">';
- print img_delete();
- print '</a></td>';
- print '<td class="center">';
- if ($num > 1) {
- if ($i > 0) {
- print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=up&token='.newToken().'&line_id='.$objp->rowid.'">';
- print img_up();
- print '</a>';
- }
- if ($i < $num - 1) {
- print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=down&token='.newToken().'&line_id='.$objp->rowid.'">';
- print img_down();
- print '</a>';
- }
- }
- print '</td>';
- } else {
- print '<td colspan="2"> </td>';
- }
- print '</tr>';
- }
- // Line in update mode
- if ($object->statut == 0 && $action == 'editline' && $user->hasRight('ficheinter', 'creer') && GETPOST('line_id', 'int') == $objp->rowid) {
- print '<tr class="oddeven nohover">';
- // No.
- if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
- print '<td class="center linecolnum">'.($i + 1).'</td>';
- }
- print '<td>';
- print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
- // Editeur wysiwyg
- require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
- $doleditor = new DolEditor('np_desc', $objp->description, '', 164, 'dolibarr_details', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_DETAILS'), ROWS_2, '90%');
- $doleditor->Create();
- $objectline = new FichinterLigne($db);
- $objectline->fetch($objp->rowid);
- $objectline->fetch_optionals();
- $extrafields->fetch_name_optionals_label($objectline->table_element);
- if (!empty($extrafields)) {
- $temps = $objectline->showOptionals($extrafields, 'edit', array(), '', '', 1, 'line');
- if (!empty($temps)) {
- print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
- print $temps;
- print '</div>';
- }
- }
- print '</td>';
- // Date d'intervention
- print '<td class="center nowrap">';
- if (!empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR)) {
- print $form->selectDate($db->jdate($objp->date_intervention), 'di', 0, 0, 0, "date_intervention");
- } else {
- print $form->selectDate($db->jdate($objp->date_intervention), 'di', 1, 1, 0, "date_intervention");
- }
- print '</td>';
- // Duration
- print '<td class="right">';
- if (empty($conf->global->FICHINTER_WITHOUT_DURATION)) {
- $selectmode = 'select';
- if (!empty($conf->global->INTERVENTION_ADDLINE_FREEDUREATION)) {
- $selectmode = 'text';
- }
- $form->select_duration('duration', $objp->duree, 0, $selectmode);
- }
- print '</td>';
- print '<td class="center" colspan="5" valign="center">';
- print '<input type="submit" class="button buttongen marginbottomonly button-save" name="save" value="'.$langs->trans("Save").'">';
- print '<input type="submit" class="button buttongen marginbottomonly button-cancel" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
- print '</tr>'."\n";
- }
- $i++;
- }
- $db->free($resql);
- // Add new line
- if ($object->statut == 0 && $user->hasRight('ficheinter', 'creer') && $action <> 'editline' && empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
- if (!$num) {
- print '<br>';
- print '<table class="noborder centpercent">';
- print '<tr class="liste_titre">';
- // No.
- if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
- print '<td width="5" class="center linecolnum"></td>';
- }
- print '<td>';
- print '<a name="add"></a>'; // ancre
- print $langs->trans('Description').'</td>';
- print '<td class="center">'.$langs->trans('Date').'</td>';
- print '<td class="right">'.(empty($conf->global->FICHINTER_WITHOUT_DURATION) ? $langs->trans('Duration') : '').'</td>';
- print '<td colspan="3"> </td>';
- print "</tr>\n";
- }
- print '<tr class="oddeven nohover">'."\n";
- // No.
- if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
- print '<td class="center linecolnum">'.($i + 1).'</td>';
- }
- print '<td>';
- // editeur wysiwyg
- if (empty($conf->global->FICHINTER_EMPTY_LINE_DESC)) {
- require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
- $doleditor = new DolEditor('np_desc', GETPOST('np_desc', 'restricthtml'), '', 100, 'dolibarr_details', '', false, true, !empty($conf->global->FCKEDITOR_ENABLE_DETAILS), ROWS_2, '90%');
- $doleditor->Create();
- }
- $objectline = new FichinterLigne($db);
- $extrafields->fetch_name_optionals_label($objectline->table_element);
- if (is_object($objectline)) {
- $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
- if (!empty($temps)) {
- print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
- print $temps;
- print '</div>';
- }
- }
- print '</td>';
- // Date intervention
- print '<td class="center nowrap">';
- $now = dol_now();
- $timearray = dol_getdate($now);
- if (!GETPOST('diday', 'int')) {
- $timewithnohour = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
- } else {
- $timewithnohour = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int'));
- }
- if (!empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR)) {
- print $form->selectDate($timewithnohour, 'di', 0, 0, 0, "addinter");
- } else {
- print $form->selectDate($timewithnohour, 'di', 1, 1, 0, "addinter");
- }
- print '</td>';
- // Duration
- print '<td class="right">';
- if (empty($conf->global->FICHINTER_WITHOUT_DURATION)) {
- $selectmode = 'select';
- if (!empty($conf->global->INTERVENTION_ADDLINE_FREEDUREATION)) {
- $selectmode = 'text';
- }
- $form->select_duration('duration', (!GETPOST('durationhour', 'int') && !GETPOST('durationmin', 'int')) ? 3600 : (60 * 60 * GETPOST('durationhour', 'int') + 60 * GETPOST('durationmin', 'int')), 0, $selectmode);
- }
- print '</td>';
- print '<td class="center" valign="middle" colspan="3"><input type="submit" class="button button-add" value="'.$langs->trans('Add').'" name="addline"></td>';
- print '</tr>';
- if (!$num) {
- print '</table>';
- }
- }
- if ($num) {
- print '</table>';
- }
- } else {
- dol_print_error($db);
- }
- print '</form>'."\n";
- }
- print dol_get_fiche_end();
- print "\n";
- /*
- * Actions buttons
- */
- print '<div class="tabsAction">';
- $parameters = array();
- $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
- // modified by hook
- if (empty($reshook)) {
- if ($user->socid == 0) {
- if ($action != 'editdescription' && ($action != 'presend')) {
- // Validate
- if ($object->statut == Fichinter::STATUS_DRAFT && (count($object->lines) > 0 || !empty($conf->global->FICHINTER_DISABLE_DETAILS))) {
- if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight('ficheinter', 'creer')) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->ficheinter_advance->validate)) {
- print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=validate">'.$langs->trans("Validate").'</a></div>';
- } else {
- print '<div class="inline-block divButActionRefused"><span class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</span></div>';
- }
- }
- // Modify
- if ($object->statut == Fichinter::STATUS_VALIDATED && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight('ficheinter', 'creer')) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->ficheinter_advance->unvalidate))) {
- print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=modify">';
- if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
- print $langs->trans("Modify");
- } else {
- print $langs->trans("SetToDraft");
- }
- print '</a></div>';
- }
- // Reopen
- if ($object->statut >= Fichinter::STATUS_CLOSED) {
- if ($user->rights->ficheinter->creer) {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans('Reopen').'</a></div>';
- } else {
- print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Reopen').'</a></div>';
- }
- }
- // Send
- if (empty($user->socid)) {
- if ($object->statut > Fichinter::STATUS_DRAFT) {
- if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send) {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
- } else {
- print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>';
- }
- }
- }
- // Create intervention model
- if ($conf->global->MAIN_FEATURES_LEVEL >= 1 && $object->statut == Fichinter::STATUS_DRAFT && $user->hasRight('ficheinter', 'creer') && (count($object->lines) > 0)) {
- print '<div class="inline-block divButAction">';
- print '<a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$object->id.'&action=create&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id).'">'.$langs->trans("ChangeIntoRepeatableIntervention").'</a>';
- print '</div>';
- }
- // Proposal
- if (isModEnabled("service") && isModEnabled("propal") && $object->statut > Fichinter::STATUS_DRAFT) {
- $langs->load("propal");
- if ($object->statut < Fichinter::STATUS_BILLED) {
- if ($user->rights->propal->creer) {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddProp").'</a></div>';
- } else {
- print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddProp").'</a></div>';
- }
- }
- }
- // Invoicing
- if (isModEnabled('facture') && $object->statut > Fichinter::STATUS_DRAFT) {
- $langs->load("bills");
- if ($object->statut < Fichinter::STATUS_BILLED) {
- if ($user->hasRight('facture', 'creer')) {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddBill").'</a></div>';
- } else {
- print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddBill").'</a></div>';
- }
- }
- if (!empty($conf->global->FICHINTER_CLASSIFY_BILLED)) { // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
- if ($object->statut != Fichinter::STATUS_BILLED) {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifybilled&token='.newToken().'">'.$langs->trans("InterventionClassifyBilled").'</a></div>';
- } else {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifyunbilled&token='.newToken().'">'.$langs->trans("InterventionClassifyUnBilled").'</a></div>';
- }
- }
- }
- // Done
- if (empty($conf->global->FICHINTER_CLASSIFY_BILLED) && $object->statut > Fichinter::STATUS_DRAFT && $object->statut < Fichinter::STATUS_CLOSED) {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifydone&token='.newToken().'">'.$langs->trans("InterventionClassifyDone").'</a></div>';
- }
- // Clone
- if ($user->rights->ficheinter->creer) {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken().'&object=ficheinter">'.$langs->trans("ToClone").'</a></div>';
- }
- // Delete
- print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
- }
- }
- }
- print '</div>';
- if ($action != 'presend') {
- print '<div class="fichecenter"><div class="fichehalfleft">';
- /*
- * Built documents
- */
- $filename = dol_sanitizeFileName($object->ref);
- $filedir = $conf->ficheinter->dir_output."/".$filename;
- $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
- $genallowed = $user->rights->ficheinter->lire;
- $delallowed = $user->rights->ficheinter->creer;
- print $formfile->showdocuments('ficheinter', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
- // Show links to link elements
- $linktoelem = $form->showLinkToObjectBlock($object, null, array('fichinter'));
- $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
- // Show direct download link
- if ($object->statut != Fichinter::STATUS_DRAFT && !empty($conf->global->FICHINTER_ALLOW_EXTERNAL_DOWNLOAD)) {
- print '<br><!-- Link to download main doc -->'."\n";
- print showDirectDownloadLink($object).'<br>';
- }
- // Show online signature link
- if ($object->statut != Fichinter::STATUS_DRAFT && !empty($conf->global->FICHINTER_ALLOW_ONLINE_SIGN)) {
- print '<br><!-- Link to sign -->';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
- print showOnlineSignatureUrl('fichinter', $object->ref).'<br>';
- }
- print '</div><div class="fichehalfright">';
- $MAXEVENT = 10;
- $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/fichinter/agenda.php?id='.$object->id);
- // List of actions on element
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
- $formactions = new FormActions($db);
- $somethingshown = $formactions->showactions($object, 'fichinter', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
- print '</div></div>';
- }
- // Select mail models is same action as presend
- if (GETPOST('modelselected')) {
- $action = 'presend';
- }
- // Presend form
- $modelmail = 'fichinter_send';
- $defaulttopic = 'SendInterventionRef';
- $diroutput = $conf->ficheinter->dir_output;
- $trackid = 'int'.$object->id;
- include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
- }
- llxFooter();
- $db->close();
|