PageRenderTime 267ms CodeModel.GetById 49ms app.highlight 152ms RepoModel.GetById 21ms app.codeStats 1ms

/htdocs/fichinter/fiche.php

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