PageRenderTime 5ms CodeModel.GetById 4ms app.highlight 89ms RepoModel.GetById 1ms app.codeStats 1ms

/htdocs/fichinter/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 1347 lines | 991 code | 192 blank | 164 comment | 298 complexity | 9052ac1e48a61bc2b0af6434954ff499 MD5 | raw file
   1<?php
   2/* Copyright (C) 2002-2007	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
   3 * Copyright (C) 2004-2012	Laurent Destailleur		<eldy@users.sourceforge.net>
   4 * Copyright (C) 2005-2012	Regis Houssin			<regis.houssin@capnetworks.com>
   5 * Copyright (C) 2011-2012  Juanjo Menent			<jmenent@2byte.es>
   6 *
   7 * This program is free software; you can redistribute it and/or modify
   8 * it under the terms of the GNU General Public License as published by
   9 * the Free Software Foundation; either version 3 of the License, or
  10 * (at your option) any later version.
  11 *
  12 * This program is distributed in the hope that it will be useful,
  13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15 * GNU General Public License for more details.
  16 *
  17 * You should have received a copy of the GNU General Public License
  18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 */
  20
  21/**
  22 *	\file       htdocs/fichinter/fiche.php
  23 *	\brief      Fichier fiche intervention
  24 *	\ingroup    ficheinter
  25 */
  26
  27require '../main.inc.php';
  28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  29require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  30require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
  31require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
  32require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33if (! empty($conf->projet->enabled))
  34{
  35    require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  36    require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  37}
  38if (! empty($conf->global->FICHEINTER_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php"))
  39{
  40    require_once DOL_DOCUMENT_ROOT ."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.'.php';
  41}
  42
  43$langs->load("companies");
  44$langs->load("interventions");
  45
  46$id			= GETPOST('id','int');
  47$ref		= GETPOST('ref','alpha');
  48$socid		= GETPOST('socid','int');
  49$action		= GETPOST('action','alpha');
  50$confirm	= GETPOST('confirm','alpha');
  51$mesg		= GETPOST('msg','alpha');
  52
  53//PDF
  54$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  55$hidedesc 	 = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ?  1 : 0));
  56$hideref 	 = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  57
  58// Security check
  59if ($user->societe_id) $socid=$user->societe_id;
  60$result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
  61
  62// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  63$hookmanager->initHooks(array('interventioncard'));
  64
  65$object = new Fichinter($db);
  66
  67
  68/*
  69 * Actions
  70 */
  71
  72if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer)
  73{
  74    $object->fetch($id);
  75    $object->fetch_thirdparty();
  76
  77    $result = $object->setValid($user);
  78    if ($result >= 0)
  79    {
  80        // Define output language
  81        $outputlangs = $langs;
  82        $newlang='';
  83        if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
  84        if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  85        if (! empty($newlang))
  86        {
  87            $outputlangs = new Translate();
  88            $outputlangs->setDefaultLang($newlang);
  89        }
  90        $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs);
  91        header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  92        exit;
  93    }
  94    else
  95    {
  96        $mesg='<div class="error">'.$object->error.'</div>';
  97    }
  98}
  99
 100else if ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer)
 101{
 102    $object->fetch($id);
 103    $object->fetch_thirdparty();
 104
 105    $result = $object->setDraft($user);
 106    if ($result >= 0)
 107    {
 108        // Define output language
 109        $outputlangs = $langs;
 110        $newlang='';
 111        if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
 112        if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 113        if (! empty($newlang))
 114        {
 115            $outputlangs = new Translate();
 116            $outputlangs->setDefaultLang($newlang);
 117        }
 118        $result=fichinter_create($db, $object, (!GETPOST('model','alpha'))?$object->model:GETPOST('model','apha'), $outputlangs);
 119        header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
 120        exit;
 121    }
 122    else
 123    {
 124        $mesg='<div class="error">'.$object->error.'</div>';
 125    }
 126}
 127
 128else if ($action == 'add' && $user->rights->ficheinter->creer)
 129{
 130    $object->socid			= $socid;
 131    $object->duree			= GETPOST('duree','int');
 132    $object->fk_project		= GETPOST('projectid','int');
 133    $object->author			= $user->id;
 134    $object->description	= GETPOST('description');
 135    $object->ref			= $ref;
 136    $object->modelpdf		= GETPOST('model','alpha');
 137    $object->note_private	= GETPOST('note_private');
 138    $object->note_public	= GETPOST('note_public');
 139
 140    if ($object->socid > 0)
 141    {
 142        $result = $object->create();
 143        if ($result > 0)
 144        {
 145            $id=$result;      // Force raffraichissement sur fiche venant d'etre cree
 146        }
 147        else
 148        {
 149            $langs->load("errors");
 150            $mesg='<div class="error">'.$langs->trans($object->error).'</div>';
 151            $action = 'create';
 152        }
 153    }
 154    else
 155    {
 156        $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).'</div>';
 157        $action = 'create';
 158    }
 159}
 160
 161else if ($action == 'update' && $user->rights->ficheinter->creer)
 162{
 163    $object->fetch($id);
 164
 165    $object->socid			= $socid;
 166    $object->fk_project		= GETPOST('projectid','int');
 167    $object->author			= $user->id;
 168    $object->description	= GETPOST('description','alpha');
 169    $object->ref			= $ref;
 170
 171    $object->update();
 172}
 173
 174/*
 175 * Build doc
 176 */
 177else if ($action == 'builddoc' && $user->rights->ficheinter->creer)	// En get ou en post
 178{
 179    $object->fetch($id);
 180    $object->fetch_thirdparty();
 181    $object->fetch_lines();
 182
 183    if (GETPOST('model','alpha'))
 184    {
 185        $object->setDocModel($user, GETPOST('model','alpha'));
 186    }
 187
 188    // Define output language
 189    $outputlangs = $langs;
 190    $newlang='';
 191    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
 192    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 193    if (! empty($newlang))
 194    {
 195        $outputlangs = new Translate();
 196        $outputlangs->setDefaultLang($newlang);
 197    }
 198    $result=fichinter_create($db, $object, GETPOST('model','alpha'), $outputlangs);
 199    if ($result <= 0)
 200    {
 201        dol_print_error($db,$result);
 202        exit;
 203    }
 204}
 205
 206// Remove file in doc form
 207else if ($action == 'remove_file')
 208{
 209	if ($object->fetch($id))
 210	{
 211		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 212
 213		$object->fetch_thirdparty();
 214
 215		$langs->load("other");
 216		$upload_dir = $conf->ficheinter->dir_output;
 217		$file = $upload_dir . '/' . GETPOST('file');
 218		$ret=dol_delete_file($file,0,0,0,$object);
 219		if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
 220		else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
 221	}
 222}
 223
 224// Set into a project
 225else if ($action == 'classin' && $user->rights->ficheinter->creer)
 226{
 227    $object->fetch($id);
 228    $result=$object->setProject(GETPOST('projectid','int'));
 229    if ($result < 0) dol_print_error($db,$object->error);
 230}
 231
 232else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer)
 233{
 234	$object->fetch($id);
 235	$object->fetch_thirdparty();
 236	$object->delete($user);
 237
 238    header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter');
 239    exit;
 240}
 241
 242else if ($action == 'setdescription' && $user->rights->ficheinter->creer)
 243{
 244    $object->fetch($id);
 245    $result=$object->set_description($user,GETPOST('description'));
 246    if ($result < 0) dol_print_error($db,$object->error);
 247}
 248else if ($action == 'setnote_public' && $user->rights->ficheinter->creer)
 249{
 250    $object->fetch($id);
 251    $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
 252    if ($result < 0) dol_print_error($db,$object->error);
 253}
 254else if ($action == 'setnote_private' && $user->rights->ficheinter->creer)
 255{
 256    $object->fetch($id);
 257    $result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES));
 258    if ($result < 0) dol_print_error($db,$object->error);
 259}
 260
 261// Add line
 262else if ($action == "addline" && $user->rights->ficheinter->creer)
 263{
 264    if (!GETPOST('np_desc'))
 265    {
 266        $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).'</div>';
 267        $error++;
 268    }
 269    if (!GETPOST('durationhour','int') && !GETPOST('durationmin','int'))
 270    {
 271        $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Duration")).'</div>';
 272        $error++;
 273    }
 274    if (! $error)
 275    {
 276		$db->begin();
 277
 278        $ret=$object->fetch($id);
 279        $object->fetch_thirdparty();
 280
 281        $desc=GETPOST('np_desc');
 282        $date_intervention = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int'));
 283        $duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int'));
 284
 285        $result=$object->addline(
 286            $id,
 287            $desc,
 288            $date_intervention,
 289            $duration
 290        );
 291
 292        // Define output language
 293        $outputlangs = $langs;
 294        $newlang='';
 295        if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
 296        if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 297        if (! empty($newlang))
 298        {
 299            $outputlangs = new Translate();
 300            $outputlangs->setDefaultLang($newlang);
 301        }
 302
 303		if ($result >= 0)
 304		{
 305			$db->commit();
 306
 307        	fichinter_create($db, $object, $object->modelpdf, $outputlangs);
 308        	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
 309        	exit;
 310		}
 311		else
 312		{
 313			$mesg=$object->error;
 314			$db->rollback();
 315		}
 316    }
 317}
 318
 319// Classify Billed
 320else if ($action == 'classifybilled' && $user->rights->ficheinter->creer)
 321{
 322    $object->fetch($id);
 323	$result=$object->setBilled();
 324	if ($result > 0)
 325	{
 326        header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
 327        exit;
 328	}
 329	else
 330	{
 331        $mesg='<div class="error">'.$object->error.'</div>';
 332	}
 333}
 334
 335/*
 336 *  Mise a jour d'une ligne d'intervention
 337 */
 338else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST('save','alpha') == $langs->trans("Save"))
 339{
 340    $objectline = new FichinterLigne($db);
 341    if ($objectline->fetch(GETPOST('line_id','int')) <= 0)
 342    {
 343        dol_print_error($db);
 344        exit;
 345    }
 346
 347    if ($object->fetch($objectline->fk_fichinter) <= 0)
 348    {
 349        dol_print_error($db);
 350        exit;
 351    }
 352    $object->fetch_thirdparty();
 353
 354    $desc		= GETPOST('np_desc');
 355    $date_inter	= dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int'));
 356    $duration	= convertTime2Seconds(GETPOST('durationhour','int'),GETPOST('durationmin','int'));
 357
 358    $objectline->datei		= $date_inter;
 359    $objectline->desc		= $desc;
 360    $objectline->duration	= $duration;
 361    $result = $objectline->update();
 362    if ($result < 0)
 363    {
 364        dol_print_error($db);
 365        exit;
 366    }
 367
 368    // Define output language
 369    $outputlangs = $langs;
 370    $newlang='';
 371    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
 372    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 373    if (! empty($newlang))
 374    {
 375        $outputlangs = new Translate();
 376        $outputlangs->setDefaultLang($newlang);
 377    }
 378    fichinter_create($db, $object, $object->modelpdf, $outputlangs);
 379
 380    header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
 381    exit;
 382}
 383
 384/*
 385 *  Supprime une ligne d'intervention AVEC confirmation
 386 */
 387else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->ficheinter->creer)
 388{
 389	$objectline = new FichinterLigne($db);
 390	if ($objectline->fetch(GETPOST('line_id','int')) <= 0)
 391	{
 392		dol_print_error($db);
 393		exit;
 394	}
 395	$result=$objectline->deleteline();
 396
 397	if ($object->fetch($objectline->fk_fichinter) <= 0)
 398	{
 399		dol_print_error($db);
 400		exit;
 401	}
 402
 403	// Define output language
 404	$outputlangs = $langs;
 405	$newlang='';
 406	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
 407	if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 408	if (! empty($newlang))
 409	{
 410		$outputlangs = new Translate();
 411		$outputlangs->setDefaultLang($newlang);
 412	}
 413	fichinter_create($db, $object, $object->modelpdf, $outputlangs);
 414}
 415
 416/*
 417 * Ordonnancement des lignes
 418 */
 419
 420else if ($action == 'up' && $user->rights->ficheinter->creer)
 421{
 422    $object->fetch($id);
 423    $object->fetch_thirdparty();
 424    $object->line_up(GETPOST('line_id','int'));
 425
 426    // Define output language
 427    $outputlangs = $langs;
 428    $newlang='';
 429    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
 430    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 431    if (! empty($newlang))
 432    {
 433        $outputlangs = new Translate();
 434        $outputlangs->setDefaultLang($newlang);
 435    }
 436    fichinter_create($db, $object, $object->modelpdf, $outputlangs);
 437    header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int'));
 438    exit;
 439}
 440
 441else if ($action == 'down' && $user->rights->ficheinter->creer)
 442{
 443    $object->fetch($id);
 444    $object->fetch_thirdparty();
 445    $object->line_down(GETPOST('line_id','int'));
 446
 447    // Define output language
 448    $outputlangs = $langs;
 449    $newlang='';
 450    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','alpha')) $newlang=GETPOST('lang_id','alpha');
 451    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 452    if (! empty($newlang))
 453    {
 454        $outputlangs = new Translate();
 455        $outputlangs->setDefaultLang($newlang);
 456    }
 457    fichinter_create($db, $object, $object->modelpdf, $outputlangs);
 458    header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.GETPOST('line_id','int'));
 459    exit;
 460}
 461
 462
 463/*
 464 * Add file in email form
 465 */
 466if (GETPOST('addfile','alpha'))
 467{
 468    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 469
 470    // Set tmp user directory TODO Use a dedicated directory for temp mails files
 471    $vardir=$conf->user->dir_output."/".$user->id;
 472    $upload_dir_tmp = $vardir.'/temp';
 473
 474    dol_add_file_process($upload_dir_tmp,0,0);
 475    $action='presend';
 476}
 477
 478/*
 479 * Remove file in email form
 480 */
 481if (GETPOST('removedfile','alpha'))
 482{
 483    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 484
 485    // Set tmp user directory
 486    $vardir=$conf->user->dir_output."/".$user->id;
 487    $upload_dir_tmp = $vardir.'/temp';
 488
 489	// TODO Delete only files that was uploaded from email form
 490    dol_remove_file_process(GETPOST('removedfile','alpha'),0);
 491    $action='presend';
 492}
 493
 494/*
 495 * Send mail
 496 */
 497if ($action == 'send' && ! GETPOST('cancel','alpha') && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send))
 498{
 499    $langs->load('mails');
 500
 501    if ($object->fetch($id) > 0)
 502    {
 503//        $objectref = dol_sanitizeFileName($object->ref);
 504//        $file = $conf->ficheinter->dir_output . '/' . $objectref . '/' . $objectref . '.pdf';
 505
 506//        if (is_readable($file))
 507//        {
 508            $object->fetch_thirdparty();
 509
 510            if (GETPOST('sendto','alpha'))
 511            {
 512                // Le destinataire a ete fourni via le champ libre
 513                $sendto = GETPOST('sendto','alpha');
 514                $sendtoid = 0;
 515            }
 516            elseif (GETPOST('receiver','alpha') != '-1')
 517            {
 518                // Recipient was provided from combo list
 519                if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
 520                {
 521                    $sendto = $object->client->email;
 522                    $sendtoid = 0;
 523                }
 524                else    // Id du contact
 525                {
 526                    $sendto = $object->client->contact_get_email(GETPOST('receiver','alpha'));
 527                    $sendtoid = GETPOST('receiver','alpha');
 528                }
 529            }
 530
 531            if (dol_strlen($sendto))
 532            {
 533                $langs->load("commercial");
 534
 535                $from				= GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
 536                $replyto			= GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
 537                $message			= GETPOST('message','alpha');
 538                $sendtocc			= GETPOST('sendtocc','alpha');
 539                $deliveryreceipt	= GETPOST('deliveryreceipt','alpha');
 540
 541                if ($action == 'send')
 542                {
 543                    if (strlen(GETPOST('subject','alphs'))) $subject = GETPOST('subject','alpha');
 544                    else $subject = $langs->transnoentities('Intervention').' '.$object->ref;
 545                    $actiontypecode='AC_FICH';
 546                    $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
 547                    if ($message)
 548                    {
 549                        $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
 550                        $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
 551                        $actionmsg.=$message;
 552                    }
 553                    $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
 554                }
 555
 556                // Create form object
 557                include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
 558                $formmail = new FormMail($db);
 559
 560                $attachedfiles=$formmail->get_attached_files();
 561                $filepath = $attachedfiles['paths'];
 562                $filename = $attachedfiles['names'];
 563                $mimetype = $attachedfiles['mimes'];
 564
 565                // Envoi de la propal
 566                require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
 567                $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
 568                if ($mailfile->error)
 569                {
 570                    $mesg='<div class="error">'.$mailfile->error.'</div>';
 571                }
 572                else
 573                {
 574                    $result=$mailfile->sendfile();
 575                    if ($result)
 576                    {
 577                        $mesg='<div class="ok">'.$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)).'.</div>';
 578
 579                        $error=0;
 580
 581                        // Initialisation donnees
 582                        $object->sendtoid		= $sendtoid;
 583                        $object->actiontypecode	= $actiontypecode;
 584                        $object->actionmsg 		= $actionmsg;
 585                        $object->actionmsg2		= $actionmsg2;
 586                        $object->fk_element		= $object->id;
 587						$object->elementtype	= $object->element;
 588
 589                        // Appel des triggers
 590                        include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
 591                        $interface=new Interfaces($db);
 592                        $result=$interface->run_triggers('FICHEINTER_SENTBYMAIL',$object,$user,$langs,$conf);
 593                        if ($result < 0) { $error++; $this->errors=$interface->errors; }
 594                        // Fin appel triggers
 595
 596                        if ($error)
 597                        {
 598                            dol_print_error($db);
 599                        }
 600                        else
 601                        {
 602                            // Redirect here
 603                            // This avoid sending mail twice if going out and then back to page
 604                            header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&msg='.urlencode($mesg));
 605                            exit;
 606                        }
 607                    }
 608                    else
 609                    {
 610                        $langs->load("other");
 611                        $mesg='<div class="error">';
 612                        if ($mailfile->error)
 613                        {
 614                            $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
 615                            $mesg.='<br>'.$mailfile->error;
 616                        }
 617                        else
 618                        {
 619                            $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
 620                        }
 621                        $mesg.='</div>';
 622                    }
 623                }
 624            }
 625            else
 626            {
 627                $langs->load("other");
 628                $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
 629                dol_syslog('Recipient email is empty');
 630            }
 631		/*}
 632        else
 633        {
 634            $langs->load("errors");
 635            $mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
 636            dol_syslog('Failed to read file: '.$file);
 637        }*/
 638    }
 639    else
 640    {
 641        $langs->load("other");
 642        $mesg='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Intervention")).'</div>';
 643        dol_syslog('Impossible de lire les donnees de l\'intervention. Le fichier intervention n\'a peut-etre pas ete genere.');
 644    }
 645
 646    $action='presend';
 647}
 648
 649if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer)
 650{
 651	if ($action == 'addcontact')
 652	{
 653		$result = $object->fetch($id);
 654
 655		if ($result > 0 && $id > 0)
 656		{
 657			$contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
 658			$result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha'));
 659		}
 660
 661		if ($result >= 0)
 662		{
 663			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 664			exit;
 665		}
 666		else
 667		{
 668			if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 669			{
 670				$langs->load("errors");
 671				$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
 672			}
 673			else
 674			{
 675				$mesg = '<div class="error">'.$object->error.'</div>';
 676			}
 677		}
 678	}
 679
 680	// bascule du statut d'un contact
 681	else if ($action == 'swapstatut')
 682	{
 683		if ($object->fetch($id))
 684		{
 685			$result=$object->swapContactStatus(GETPOST('ligne','int'));
 686		}
 687		else
 688		{
 689			dol_print_error($db);
 690		}
 691	}
 692
 693	// Efface un contact
 694	else if ($action == 'deletecontact')
 695	{
 696		$object->fetch($id);
 697		$result = $object->delete_contact(GETPOST('lineid','int'));
 698
 699		if ($result >= 0)
 700		{
 701			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 702			exit;
 703		}
 704		else {
 705			dol_print_error($db);
 706		}
 707	}
 708}
 709
 710
 711/*
 712 * View
 713 */
 714
 715$form = new Form($db);
 716$formfile = new FormFile($db);
 717
 718llxHeader();
 719
 720if ($action == 'create')
 721{
 722    /*
 723     * Mode creation
 724     * Creation d'une nouvelle fiche d'intervention
 725     */
 726
 727    $soc=new Societe($db);
 728
 729    print_fiche_titre($langs->trans("AddIntervention"));
 730
 731    dol_htmloutput_mesg($mesg);
 732
 733    if (! $conf->global->FICHEINTER_ADDON)
 734    {
 735        dol_print_error($db,$langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"));
 736        exit;
 737    }
 738
 739    $object->date = dol_now();
 740
 741    $obj = $conf->global->FICHEINTER_ADDON;
 742    $obj = "mod_".$obj;
 743
 744    $modFicheinter = new $obj;
 745    $numpr = $modFicheinter->getNextValue($soc, $object);
 746
 747    if ($socid > 0)
 748    {
 749    	$soc->fetch($socid);
 750
 751        print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
 752        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 753
 754        print '<table class="border" width="100%">';
 755
 756        print '<input type="hidden" name="socid" value='.$soc->id.'>';
 757        print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
 758
 759        print '<input type="hidden" name="action" value="add">';
 760
 761        // Ref
 762        print '<tr><td class="fieldrequired">'.$langs->trans("Ref").'</td>';
 763        print '<td><input name="ref" value="'.$numpr.'"></td></tr>'."\n";
 764
 765        // Description (must be a textarea and not html must be allowed (used in list view)
 766        print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
 767        print '<td>';
 768        print '<textarea name="description" cols="80" rows="'.ROWS_3.'"></textarea>';
 769        print '</td></tr>';
 770
 771        // Project
 772        if (! empty($conf->projet->enabled))
 773        {
 774            $langs->load("project");
 775
 776            print '<tr><td valign="top">'.$langs->trans("Project").'</td><td>';
 777            /* 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
 778            if ($societe->fournisseur==1)
 779            	$numprojet=select_projects(-1,$_POST["projectid"],'projectid');
 780            else
 781            	$numprojet=select_projects($societe->id,$_POST["projectid"],'projectid');
 782            	*/
 783            $numprojet=select_projects($soc->id,GETPOST('projectid','int'),'projectid');
 784            if ($numprojet==0)
 785            {
 786                print ' &nbsp; <a href="'.DOL_DOCUMENT_ROOT.'/projet/fiche.php?socid='.$soc->id.'&action=create">'.$langs->trans("AddProject").'</a>';
 787            }
 788            print '</td></tr>';
 789        }
 790
 791        // Model
 792        print '<tr>';
 793        print '<td>'.$langs->trans("DefaultModel").'</td>';
 794        print '<td colspan="2">';
 795        $liste=ModelePDFFicheinter::liste_modeles($db);
 796        print $form->selectarray('model',$liste,$conf->global->FICHEINTER_ADDON_PDF);
 797        print "</td></tr>";
 798
 799        // Public note
 800        print '<tr>';
 801        print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
 802        print '<td valign="top" colspan="2">';
 803        print '<textarea name="note_public" cols="80" rows="'.ROWS_3.'"></textarea>';
 804        print '</td></tr>';
 805
 806        // Private note
 807        if (! $user->societe_id)
 808        {
 809        	print '<tr>';
 810        	print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
 811        	print '<td valign="top" colspan="2">';
 812        	print '<textarea name="note_private" cols="80" rows="'.ROWS_3.'"></textarea>';
 813        	print '</td></tr>';
 814        }
 815
 816        // Other attributes
 817        $parameters=array('colspan' => ' colspan="2"');
 818        $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
 819
 820        print '</table>';
 821
 822        print '<center><br>';
 823        print '<input type="submit" class="button" value="'.$langs->trans("CreateDraftIntervention").'">';
 824        print '</center>';
 825
 826        print '</form>';
 827    }
 828    else
 829    {
 830        print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
 831        print '<table class="border" width="100%">';
 832        print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>';
 833        print $form->select_company('','socid','',1,1);
 834        print '</td></tr>';
 835        print '</table>';
 836
 837        print '<br><center>';
 838        print '<input type="hidden" name="action" value="create">';
 839        print '<input type="submit" class="button" value="'.$langs->trans("CreateDraftIntervention").'">';
 840        print '</center>';
 841
 842        print '</form>';
 843    }
 844
 845}
 846else if ($id > 0 || ! empty($ref))
 847{
 848    /*
 849     * Affichage en mode visu
 850     */
 851
 852	$object->fetch($id, $ref);
 853    $object->fetch_thirdparty();
 854
 855    $soc=new Societe($db);
 856    $soc->fetch($object->socid);
 857
 858    dol_htmloutput_mesg($mesg);
 859
 860    $head = fichinter_prepare_head($object);
 861
 862    dol_fiche_head($head, 'card', $langs->trans("InterventionCard"), 0, 'intervention');
 863
 864    // Confirmation de la suppression de la fiche d'intervention
 865    if ($action == 'delete')
 866    {
 867        $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete','',0,1);
 868        if ($ret == 'html') print '<br>';
 869    }
 870
 871    // Confirmation validation
 872    if ($action == 'validate')
 873    {
 874        $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $langs->trans('ConfirmValidateIntervention'), 'confirm_validate','',0,1);
 875        if ($ret == 'html') print '<br>';
 876    }
 877
 878    // Confirmation de la validation de la fiche d'intervention
 879    if ($action == 'modify')
 880    {
 881        $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify','',0,1);
 882        if ($ret == 'html') print '<br>';
 883    }
 884
 885    // Confirmation de la suppression d'une ligne d'intervention
 886    if ($action == 'ask_deleteline')
 887    {
 888        $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.GETPOST('line_id','int'), $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline','',0,1);
 889        if ($ret == 'html') print '<br>';
 890    }
 891
 892    print '<table class="border" width="100%">';
 893
 894    $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
 895
 896    // Ref
 897    print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td>';
 898    print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
 899    print '</td></tr>';
 900
 901    // Third party
 902    print "<tr><td>".$langs->trans("Company")."</td><td>".$object->client->getNomUrl(1)."</td></tr>";
 903
 904    // Duration
 905    print '<tr><td>'.$langs->trans("TotalDuration").'</td>';
 906    print '<td>'.convertSecondToTime($object->duree, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
 907    print '</tr>';
 908
 909    // Description (must be a textarea and not html must be allowed (used in list view)
 910    print '<tr><td valign="top">';
 911    print $form->editfieldkey("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea');
 912    print '</td><td colspan="3">';
 913    print $form->editfieldval("Description",'description',$object->description,$object,$user->rights->ficheinter->creer,'textarea');
 914    print '</td>';
 915    print '</tr>';
 916
 917    // Project
 918    if (! empty($conf->projet->enabled))
 919    {
 920        $langs->load('projects');
 921        print '<tr>';
 922        print '<td>';
 923
 924        print '<table class="nobordernopadding" width="100%"><tr><td>';
 925        print $langs->trans('Project');
 926        print '</td>';
 927        if ($action != 'classify')
 928        {
 929            print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
 930            print img_edit($langs->trans('SetProject'),1);
 931            print '</a></td>';
 932        }
 933        print '</tr></table>';
 934        print '</td><td colspan="3">';
 935        if ($action == 'classify')
 936        {
 937            $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid');
 938        }
 939        else
 940        {
 941            $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none');
 942        }
 943        print '</td>';
 944        print '</tr>';
 945    }
 946
 947    // Statut
 948    print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
 949
 950    // Other attributes
 951    $parameters=array('colspan' => ' colspan="3"');
 952    $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
 953
 954    print "</table><br>";
 955
 956    if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
 957    {
 958    	$blocname = 'contacts';
 959    	$title = $langs->trans('ContactsAddresses');
 960    	include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
 961    }
 962
 963	if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
 964    {
 965    	$blocname = 'notes';
 966    	$title = $langs->trans('Notes');
 967    	include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
 968    }
 969
 970    /*
 971     * Lignes d'intervention
 972     */
 973    $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,';
 974    $sql.= ' ft.date as date_intervention';
 975    $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
 976    $sql.= ' WHERE ft.fk_fichinter = '.$object->id;
 977    $sql.= ' ORDER BY ft.rang ASC, ft.rowid';
 978
 979    $resql = $db->query($sql);
 980    if ($resql)
 981    {
 982        $num = $db->num_rows($resql);
 983        $i = 0;
 984
 985        if ($num)
 986        {
 987            print '<table class="noborder" width="100%">';
 988
 989            print '<tr class="liste_titre">';
 990            print '<td>'.$langs->trans('Description').'</td>';
 991            print '<td align="center">'.$langs->trans('Date').'</td>';
 992            print '<td align="right">'.$langs->trans('Duration').'</td>';
 993            print '<td width="48" colspan="3">&nbsp;</td>';
 994            print "</tr>\n";
 995        }
 996        $var=true;
 997        while ($i < $num)
 998        {
 999            $objp = $db->fetch_object($resql);
1000            $var=!$var;
1001
1002            // Ligne en mode visu
1003            if ($action != 'editline' || GETPOST('line_id','int') != $objp->rowid)
1004            {
1005                print '<tr '.$bc[$var].'>';
1006                print '<td>';
1007                print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
1008                print dol_htmlentitiesbr($objp->description);
1009
1010                // Date
1011                print '<td align="center" width="150">'.dol_print_date($db->jdate($objp->date_intervention),'dayhour').'</td>';
1012
1013                // Duration
1014                print '<td align="right" width="150">'.convertSecondToTime($objp->duree).'</td>';
1015
1016                print "</td>\n";
1017
1018
1019                // Icone d'edition et suppression
1020                if ($object->statut == 0  && $user->rights->ficheinter->creer)
1021                {
1022                    print '<td align="center">';
1023                    print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;line_id='.$objp->rowid.'#'.$objp->rowid.'">';
1024                    print img_edit();
1025                    print '</a>';
1026                    print '</td>';
1027                    print '<td align="center">';
1028                    print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=ask_deleteline&amp;line_id='.$objp->rowid.'">';
1029                    print img_delete();
1030                    print '</a></td>';
1031                    if ($num > 1)
1032                    {
1033                        print '<td align="center">';
1034                        if ($i > 0)
1035                        {
1036                            print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=up&amp;line_id='.$objp->rowid.'">';
1037                            print img_up();
1038                            print '</a>';
1039                        }
1040                        if ($i < $num-1)
1041                        {
1042                            print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=down&amp;line_id='.$objp->rowid.'">';
1043                            print img_down();
1044                            print '</a>';
1045                        }
1046                        print '</td>';
1047                    }
1048                }
1049                else
1050                {
1051                    print '<td colspan="3">&nbsp;</td>';
1052                }
1053
1054                print '</tr>';
1055            }
1056
1057            // Ligne en mode update
1058            if ($object->statut == 0 && $action == 'editline' && $user->rights->ficheinter->creer && GETPOST('line_id','int') == $objp->rowid)
1059            {
1060                print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$objp->rowid.'" method="post">';
1061                print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1062                print '<input type="hidden" name="action" value="updateline">';
1063                print '<input type="hidden" name="id" value="'.$object->id.'">';
1064                print '<input type="hidden" name="line_id" value="'.GETPOST('line_id','int').'">';
1065                print '<tr '.$bc[$var].'>';
1066                print '<td>';
1067                print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
1068
1069                // Editeur wysiwyg
1070                require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1071                $doleditor=new DolEditor('np_desc',$objp->description,'',164,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,70);
1072                $doleditor->Create();
1073                print '</td>';
1074
1075                // Date d'intervention
1076                print '<td align="center" nowrap="nowrap">';
1077                $form->select_date($db->jdate($objp->date_intervention),'di',1,1,0,"date_intervention");
1078                print '</td>';
1079
1080                // Duration
1081                print '<td align="right">';
1082                $form->select_duration('duration',$objp->duree);
1083                print '</td>';
1084
1085                print '<td align="center" colspan="5" valign="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
1086                print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
1087                print '</tr>' . "\n";
1088
1089                print "</form>\n";
1090            }
1091
1092            $i++;
1093        }
1094
1095        $db->free($resql);
1096
1097        /*
1098         * Add line
1099         */
1100        if ($object->statut == 0 && $user->rights->ficheinter->creer && $action <> 'editline')
1101        {
1102            if (! $num) print '<br><table class="noborder" width="100%">';
1103
1104            print '<tr class="liste_titre">';
1105            print '<td>';
1106            print '<a name="add"></a>'; // ancre
1107            print $langs->trans('Description').'</td>';
1108            print '<td align="center">'.$langs->trans('Date').'</td>';
1109            print '<td align="right">'.$langs->trans('Duration').'</td>';
1110
1111            print '<td colspan="4">&nbsp;</td>';
1112            print "</tr>\n";
1113
1114            // Ajout ligne d'intervention
1115            print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#add" name="addinter" method="post">';
1116            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1117            print '<input type="hidden" name="id" value="'.$object->id.'">';
1118            print '<input type="hidden" name="action" value="addline">';
1119
1120            $var=false;
1121
1122            print '<tr '.$bc[$var].">\n";
1123            print '<td>';
1124            // editeur wysiwyg
1125            require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1126            $doleditor=new DolEditor('np_desc',GETPOST('np_desc','alpha'),'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,ROWS_2,70);
1127            $doleditor->Create();
1128            print '</td>';
1129
1130            // Date intervention
1131            print '<td align="center" nowrap="nowrap">';
1132            $now=dol_now();
1133            $timearray=dol_getdate($now);
1134            if (!GETPOST('diday','int')) $timewithnohour=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']);
1135            else $timewithnohour=dol_mktime(GETPOST('dihour','int'),GETPOST('dimin','int'), 0,GETPOST('dimonth','int'),GETPOST('diday','int'),GETPOST('diyear','int'));
1136            $form->select_date($timewithnohour,'di',1,1,0,"addinter");
1137            print '</td>';
1138
1139            // Duration
1140            print '<td align="right">';
1141            $form->select_duration('duration',(!GETPOST('durationhour','int') && !GETPOST('durationmin','int'))?3600:(60*60*GETPOST('durationhour','int')+60*GETPOST('durationmin','int')));
1142            print '</td>';
1143
1144            print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="'.$langs->trans('Add').'" name="addline"></td>';
1145            print '</tr>';
1146
1147            print '</form>';
1148
1149            if (! $num) print '</table>';
1150        }
1151
1152        if ($num) print '</table>';
1153    }
1154    else
1155    {
1156        dol_print_error($db);
1157    }
1158
1159    print '</div>';
1160    print "\n";
1161
1162
1163    /*
1164     * Barre d'actions
1165     */
1166    print '<div class="tabsAction">';
1167
1168    if ($user->societe_id == 0)
1169    {
1170        if ($action != 'editdescription')
1171        {
1172            // Validate
1173            if ($object->statut == 0 && $user->rights->ficheinter->creer && count($object->lines) > 0)
1174            {
1175                print '<a class="butAction" href="fiche.php?id='.$object->id.'&action=validate"';
1176                print '>'.$langs->trans("Valid").'</a>';
1177            }
1178
1179            // Modify
1180            if ($object->statut == 1 && $user->rights->ficheinter->creer)
1181            {
1182                print '<a class="butAction" href="fiche.php?id='.$object->id.'&action=modify"';
1183                print '>'.$langs->trans("Modify").'</a>';
1184            }
1185
1186            // Send
1187            if ($object->statut > 0)
1188            {
1189                if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send)
1190                {
1191                    print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
1192                }
1193                else print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
1194            }
1195
1196        	// Invoicing
1197			if (! empty($conf->facture->enabled) && $object->statut > 0)
1198            {
1199				$langs->load("bills");
1200                if ($object->statut < 2)
1201                {
1202					if ($user->rights->facture->creer) print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
1203					else print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("CreateBill").'</a>';
1204                }
1205
1206                if (! empty($conf->global->FICHEINTER_CLASSIFY_BILLED))
1207                {
1208	                if ($object->statut != 2)
1209					{
1210						print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=classifybilled">'.$langs->trans("ClassifyBilled").'</a>';
1211					}
1212	            }
1213            }
1214
1215            // Delete
1216            if (($object->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer)
1217            {
1218                print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete"';
1219                print '>'.$langs->trans('Delete').'</a>';
1220            }
1221
1222        }
1223    }
1224
1225    print '</div>';
1226    print '<br>';
1227
1228    if ($action != 'presend')
1229    {
1230        print '<table width="100%"><tr><td width="50%" valign="top">';
1231        /*
1232         * Built documents
1233         */
1234        $filename=dol_sanitizeFileName($object->ref);
1235        $filedir=$conf->ficheinter->dir_output . "/".$object->ref;
1236        $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
1237        $genallowed=$user->rights->ficheinter->creer;
1238        $delallowed=$user->rights->ficheinter->supprimer;
1239        $genallowed=1;
1240        $delallowed=1;
1241
1242        $var=true;
1243
1244        //print "<br>\n";
1245        $somethingshown=$formfile->show_documents('ficheinter',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang);
1246
1247    	/*
1248    	 * Linked object block
1249    	 */
1250    	$somethingshown=$object->showLinkedObjectBlock();
1251
1252    	print '</td><td valign="top" width="50%">';
1253    	// List of actions on element
1254    	include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1255    	$formactions=new FormActions($db);
1256    	$somethingshown=$formactions->showactions($object,'fichinter',$socid);
1257        print "</td><td>";
1258        print "&nbsp;</td>";
1259        print "</tr></table>\n";
1260    }
1261
1262
1263    /*
1264     * Action presend
1265     */
1266    if ($action == 'presend')
1267    {
1268        $ref = dol_sanitizeFileName($object->ref);
1269        include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1270        $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref);
1271        $file=$fileparams['fullname'];
1272
1273        // Build document if it not exists
1274        if (! $file || ! is_readable($file))
1275        {
1276            // Define output language
1277            $outputlangs = $langs;
1278            $newlang='';
1279            if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
1280            if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
1281            if (! empty($newlang))
1282            {
1283                $outputlangs = new Translate();
1284                $outputlangs->setDefaultLang($newlang);
1285            }
1286
1287            $result=fichinter_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1288            if ($result <= 0)
1289            {
1290                dol_print_error($db,$result);
1291                exit;
1292            }
1293            $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref);
1294            $file=$fileparams['fullname'];
1295        }
1296
1297        print '<br>';
1298        print_titre($langs->trans('SendInterventionByMail'));
1299
1300        // Create form object
1301        include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1302        $formmail = new FormMail($db);
1303        $formmail->fromtype = 'user';
1304        $formmail->fromid   = $user->id;
1305        $formmail->fromname = $user->getFullName($langs);
1306        $formmail->frommail = $user->email;
1307        $formmail->withfrom=1;
1308        $formmail->withto=(!GETPOST('sendto','alpha'))?1:GETPOST('sendto','alpha');
1309        $formmail->withtosocid=$societe->id;
1310        $formmail->withtocc=1;
1311        $formmail->withtoccsocid=0;
1312        $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
1313        $formmail->withtocccsocid=0;
1314        $formmail->withtopic=$langs->trans('SendInterventionRef','__FICHINTERREF__');
1315        $formmail->withfile=2;
1316        $formmail->withbody=1;
1317        $formmail->withdeliveryreceipt=1;
1318        $formmail->withcancel=1;
1319
1320        // Tableau des substitutions
1321        $formmail->substit['__FICHINTERREF__']=$object->ref;
1322        $formmail->substit['__SIGNATURE__']=$user->signature;
1323        $formmail->substit['__PERSONALIZED__']='';
1324        // Tableau des parametres complementaires
1325        $formmail->param['action']='send';
1326        $formmail->param['models']='fichinter_send';
1327        $formmail->param['fichinter_id']=$object->id;
1328        $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
1329
1330        // Init list of files
1331        if (GETPOST("mode")=='init')
1332        {
1333            $formmail->clear_attached_files();
1334            $formmail->add_attached_files($file,basename($file),dol_mimetype($file));
1335        }
1336
1337        $formmail->show_form();
1338
1339        print '<br>';
1340    }
1341}
1342
1343
1344llxFooter();
1345
1346$db->close();
1347?>