PageRenderTime 143ms CodeModel.GetById 73ms app.highlight 57ms RepoModel.GetById 1ms app.codeStats 1ms

/htdocs/fichinter/card.php

https://github.com/atm-maximep/dolibarr
PHP | 1861 lines | 1392 code | 279 blank | 190 comment | 421 complexity | 450db56d13d99996ef3ee92735c6bde8 MD5 | raw file

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

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

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