<?php
/* Copyright (C) 2012-2021		Charlene Benke		<charlene@patas-monkey.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 *	\file	   custom/myschedule/tabs/user.php
 *	\brief	  List of all interventionnal myscheduled
 *	\ingroup	mySchedule
 */
$res=@include("../../main.inc.php");					// For root directory
if (! $res && file_exists($_SERVER['DOCUMENT_ROOT']."/main.inc.php"))
	$res=@include($_SERVER['DOCUMENT_ROOT']."/main.inc.php"); // Use on dev env only
if (! $res) $res=@include("../../../main.inc.php");		// For "custom" directory

require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';

require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';

dol_include_once('/myschedule/class/myschedule.class.php');
dol_include_once('/myschedule/core/lib/myschedule.lib.php');

$langs->load("user");
$langs->load("myschedule@myschedule");

// Security check
$id=GETPOST('id', 'int');
if ($user->admin == 0)
	$id=$user->id;

$socid=GETPOST('socid', 'int');

// Security check
$canreaduser=(! empty($user->admin) || $user->rights->user->user->lire);
if ($user->societe_id > 0)
	$socid = $user->societe_id;
$feature2='user';
if ($user->id == $id) {
	$feature2=''; 
	$canreaduser=1; 
} // A user can always read its own card
if (!$canreaduser) {
	$result = restrictedArea($user, 'user', $id, '&user', $feature2);
}
if ($user->id <> $id && ! $canreaduser) accessforbidden();

$search_ref=GETPOST('search_ref', "alpha");

$sortfield = GETPOST('sortfield', 'alpha');
$sortorder = GETPOST('sortorder', 'alpha');
$page = GETPOST('page')?GETPOST('page', 'int'):0;
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;

if (! $sortorder) $sortorder="DESC";
if (! $sortfield) $sortfield="ft.date";


$limit = $conf->liste_limit;

$choiceperiod= GETPOST('choiceperiod')?GETPOST('choiceperiod', 'alpha'):$conf->global->MYSCHEDULE_PeriodFilter;
$firstdayweek= GETPOST('firstdayweek')?strtotime( GETPOST('firstdayweek', 'alpha')):"";

$statutinter=GETPOST('statutinter')?GETPOST('statutinter', 'array'):explode(",","nouser,notmade,notplanned,made");

$dolstatut=GETPOST('dolstatut')?GETPOST('dolstatut', 'int'):-1;

$periodyear=GETPOST('periodyear', 'int');
if (!$periodyear)
	$periodyear=date('Y');

$periodyearmonth=GETPOST('periodyearmonth', 'int');
if (!$periodyearmonth)
	$periodyearmonth=date('Y');

$periodmonth=GETPOST('periodmonth', 'int');
if (! $periodmonth )
	$periodmonth=date('m');

$periodday=GETPOST('perioddday', 'int');
if ( $periodday ){
	$periodmonth=GETPOST('perioddmonth', 'int');;
	$periodyear=GETPOST('perioddyear', 'int');;
}

$periodweek=GETPOST('periodweek', 'int');
if (!$periodweek)
	$periodweek=date('W');

if ($choiceperiod == 'week') {
	if ($firstdayweek == "") 
		$firstdayweek = firstdayweek($periodweek, $periodyear);
	else
		$periodweek = date("W", $firstdayweek);

	$periodmonth=date('m', $firstdayweek);
	$lastdayweek = strtotime(date("Y-m-d", strtotime(date('d-m-Y', $firstdayweek)))." +6 day"); 

	$fullcalendarfirstday=date("Y-m-d", $firstdayweek);
	$fullcalendarlastday=date("Y-m-d", $lastdayweek);	
} 
if ($choiceperiod=='month') {
	$fullcalendarfirstday=date("Y-m-d", dol_mktime(0, 0, 0, $periodmonth, 1, $periodyearmonth));
	$fullcalendarlastday=date("Y-m-d", dol_mktime(0, 0, 0, $periodmonth, 30, $periodyearmonth));
} 

if ($choiceperiod=='day') {
	$fullcalendarfirstday=date("Y-m-d", dol_mktime(0, 0, 0, $periodmonth, $periodday, $periodyearmonth));
	$fullcalendarlastday=date("Y-m-d", dol_mktime(0, 0, 0, $periodmonth, $periodday, $periodyearmonth));
} 

$form = new Form($db);
$formother = new FormOther($db);


$title=$langs->trans("User").' - '.$langs->trans("mySchedule");
$help_url='https://wiki.patas-monkey.com/index.php?title=MySchedule';

llxHeader('', $title, $help_url);

$object = new User($db);
$result = $object->fetch($id);


$head = user_prepare_head($object);

dol_fiche_head($head, 'myschedule', $langs->trans("ThirdParty"), 0, 'company');

$linkback = '<a href="'.DOL_URL_ROOT.'/user/index.php">'.$langs->trans("BackToList").'</a>';

$urlPeriodFilter = "&filterbystatut=".implode(",", $statutinter);
$urlPeriodFilter.= "&choiceperiod=".$choiceperiod;
$urlPeriodFilter.= "&periodyear=".$periodyear;
$urlPeriodFilter.= "&periodyearmonth=".$periodyearmonth;
$urlPeriodFilter.= "&periodmonth=".$periodmonth;
$urlPeriodFilter.= "&periodweek=".$periodweek;
$urlPeriodFilter.= "&dolstatut=".$dolstatut;
if ($periodsoc > 0)
	$urlPeriodFilter.= "&periodsoc=".$periodsoc;
if ($periodcontact > 0)
	$urlPeriodFilter.= "&periodcontact=".$periodcontact;
if ($search_ref)
	$urlPeriodFilter.= "&search_ref=".$search_ref;

dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin, 'rowid', 'ref', $morehtmlref, $urlPeriodFilter);

print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '</div>';
dol_fiche_end();
/*
 * Show object in view mode
 */
print load_fiche_titre($title, "", 'myschedule@myschedule');
$showempty=1;

$contextpage='myscheduleuserlist';


// construction de la structure des champs
// la ref de l'inter, le tiers et l'état sont toujours présent dans la liste
$arrayfields=array(

	's.address'=>array('label'=>$langs->trans("Adress"), 'checked'=>0),
	's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>0),
	's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0),
	's.phone'=>array('label'=>$langs->trans("SocPhone"), 'checked'=>0),
	's.email'=>array('label'=>$langs->trans("SocEmail"), 'checked'=>0),
	's.note_public'=>array('label'=>$langs->trans("SocNotePublic"), 'checked'=>0),
	's.note_private'=>array('label'=>$langs->trans("SocNotePrivate"), 'checked'=>0),

	'f.description'=>array('label'=>$langs->trans("DescrInter"), 'checked'=>1),
	'f.note_public'=>array('label'=>$langs->trans("FInterNotePublic"), 'checked'=>0),
	'f.note_private'=>array('label'=>$langs->trans("FInterNotePrivate"), 'checked'=>0),

	'ft.date'=>array('label'=>$langs->trans("DateIntervention"), 'checked'=>1, ),
	'ft.duree'=>array('label'=>$langs->trans("Duration"), 'checked'=>1, ),
	'ft.description'=>array('label'=>$langs->trans("Description"), 'checked'=>1),

	'affecteduser'=>array('label'=>$langs->trans("AffectedUser"), 'checked'=>1),
	'affectedcontact'=>array('label'=>$langs->trans("AffectedContact"), 'checked'=>1)
);

print '<form method="post" name=formsearch action="'.$_SERVER["PHP_SELF"].'">'."\n";
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<table class="noborder noborderbottom" >';
print '<tr class="liste_titre">';
print '<th align=left colspan=4 >'.$langs->trans("Filters").'</th>';
print "</tr>\n";

print '<tr >';
print '<td valign=top>';
print '<table>';
print '<tr><td><input type=radio '.($choiceperiod=="none"?"checked":"").' name=choiceperiod value="none"></td><td>';
print $langs->trans("NoPeriodFilter");
print '</td></tr>';

print '<tr><td><input type=radio '.($choiceperiod=="day"?"checked":"").' name=choiceperiod value="day"></td><td>';
if ($periodday!="")
	$periodday =  $periodyear."-".$periodmonth."-".$periodday;
print $form->selectDate( $periodday, 'periodd',  0,  0,  0, "formsearch", 1);
print '</td></tr>';

print '<tr><td><input type=radio '.($choiceperiod=="week"?"checked":"").' name=choiceperiod value="week"></td><td>';
print $formother->selectyear($periodyear, 'periodyear');
print select_week($periodweek, 'periodweek');
print '</td></tr>';
print '<tr><td><input type=radio '.($choiceperiod=="month"?"checked":"").' name=choiceperiod value="month"></td><td>';
print $formother->selectyear($periodyearmonth, 'periodyearmonth');
print $formother->select_month($periodmonth, 'periodmonth', 0, 1, "");
print '</td></tr>';

print '</table>';
print '</td>';

// filtre sur la société
print '<td valign=top>';
print '<input type=hidden name=id value='.$id.'>';
print '<table>';
print "<tr><td>".$langs->trans("Ref")."</td><td>";
print "<input type=text name=search_ref value='".$search_ref."'>";
print "</td></tr>";

// on ne voit que ses intervention ou celle des collabs dont on est le suppérieur
$filteruser="";
if ($user->admin == 0 && $user->rights->myschedule->alluser == 0)
	$filteruser=" AND (u.rowid = ".$user->id." OR fk_user=".$user->id.")";
print '<tr><td>'.$langs->trans("Users")."</td><td>"; 
print $form->select_dolusers(
			$id, 'userid', $showempty,
			'', 1, '', '', 0, 0, 0, $filteruser
);
print "</td></tr>";
print "<tr><td>".$langs->trans("ThirdParty")."</td><td>";
print $form->select_company($periodsoc, 'periodsoc', '', $showempty);
print "</td></tr>";

$showFonction=0;
$showSoc=1;
print '<tr><td>'.$langs->trans("Contact")."</td><td>"; 
print $form->selectcontacts(0, $periodcontact, 'periodcontact', $showempty, '', '',  $showFonction, '',  false, $showSoc);
print "</td></tr>";

print '</table>';
print '</td>';

print '<td valign=top align=right>';
print '<table width=100%>';
print '<tr><td bgcolor="'.$conf->global->MYSCHEDULE_colornouser.'" title="'.$langs->trans("InfoNoUserAffected").'">';
print '<input name="statutinter[]" value="nouser"  '.(in_array("nouser", $statutinter)?" checked ":0).' type=checkbox>';
print $langs->trans("NoUserAffected")."</td>\n";
print '<td bgcolor="'.$conf->global->MYSCHEDULE_colornotmade.'" title="'.$langs->trans("InfoNotYetMade").'">';
print '<input name="statutinter[]" value="notmade"  '.(in_array("notmade", $statutinter)?" checked ":0).' type=checkbox>';
print $langs->trans("NotYetMade")."</td></tr>\n";
print '<tr><td bgcolor="'.$conf->global->MYSCHEDULE_colornotplanned.'" title="'.$langs->trans("InfoNotYetPlanned").'">';
print '<input name="statutinter[]" value="notplanned" '.(in_array("notplanned", $statutinter)?" checked ":0).' type=checkbox>';
print $langs->trans("NotYetPlanned")."</td>\n";
print '<td bgcolor="'.$conf->global->MYSCHEDULE_colormade.'" title="'.$langs->trans("InfoMade").'">';
print '<input name="statutinter[]" value="made" '.(in_array("made", $statutinter)?" checked ":0).' type=checkbox>';
print  $langs->trans("Made")."</td></tr>\n";

print '<tr><td></td></tr>';

print "<tr><td align=left>".$langs->trans("Status")." : ";
$statutArray = array(
	'0'=>$langs->trans('Draft'), 
	'1'=>$langs->trans('Validate'),
	'2'=>$langs->trans('StatusInterInvoiced'),
	'3'=>$langs->trans('Closed')
);
print $form->selectarray('dolstatut', $statutArray, $dolstatut, $showempty );
print '</td><td align=right>';
print '<input type=submit class="button" name="select" value="'.$langs->trans("Search").'">';

print "</td></tr>";

print "</table>";
print '</td>';
print '<td valign=bottom align=right>';

print "</td>";
print "</tr>\n";
print "</table>";
print '<br>';


include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';

$sql = 'SELECT f.ref, f.description as descinter, f.fk_soc, ft.rowid, ft.fk_fichinter, ';
$sql.= ' f.note_public as f_note_pub, f.note_private as f_note_priv,';

$sql.= ' ft.description, ft.duree, ft.rang, ft.date as date_intervention, f.fk_statut,';
$sql.= ' s.address, s.zip, s.town, s.email, s.phone, ';
$sql.= ' s.note_public as s_note_pub, s.note_private as s_note_priv';

$sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft, '.MAIN_DB_PREFIX.'fichinter as f';
$sql.= ' , '.MAIN_DB_PREFIX.'societe as s';
$sql.= ' , '.MAIN_DB_PREFIX.'element_contact as ec  , '.MAIN_DB_PREFIX.'c_type_contact as ctc';
$sql.= ' , '.MAIN_DB_PREFIX.'user as u ';
if ($choiceperiod != 'none') {
	$sql.= ' WHERE date_format(ft.date, "%Y-%m-%d") >= "'.$fullcalendarfirstday.'"';
	$sql.= ' AND date_format(ft.date, "%Y-%m-%d") <= "'.$fullcalendarlastday.'"';
} else
	$sql.= ' WHERE ft.date is not null';

$sql.= ' AND ft.fk_fichinter = f.rowid';
$sql.= ' AND f.fk_soc= s.rowid';

if ($search_ref)
	$sql.= ' AND f.ref = '.$search_ref;

if ($dolstatut > 0) 
	$sql.= ' AND f.fk_statut = '.$dolstatut;

$sql.= ' AND f.rowid = ec.element_id AND ec.fk_c_type_contact = ctc.rowid';
$sql.= ' AND ctc.element="fichinter" and source="internal"';
$sql.= ' AND ec.fk_socpeople = u.rowid';
$sql.= ' AND u.rowid='.$id;
$sql.= " ORDER BY ".$sortfield." ".$sortorder;

$resql = $db->query($sql);
if ($resql) {
	$num = $db->num_rows($resql);
	$j = 0;

	$urlparam="&amp;id=".$id.$urlPeriodFilter;
	$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;

	// This also change content of $arrayfields
	$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	
	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';

	print '<table width=100% class="noborder tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
	print "<tr class='liste_titre'>";
	print_liste_field_titre(
					$langs->trans("Ref"), $_SERVER["PHP_SELF"], "f.ref", 
					"", $urlparam, 'width=10%', $sortfield, $sortorder
	);
	print_liste_field_titre(
		$langs->trans("Company"), $_SERVER["PHP_SELF"], 's.nom', 
		"", $urlparam, '', $sortfield, $sortorder
	);

	if (! empty($arrayfields['s.note_public']['checked'])) {
		print_liste_field_titre(
						$arrayfields['s.note_public']['label'], $_SERVER["PHP_SELF"], "s.note_public", "",
						$urlparam, '', $sortfield, $sortorder
		);	
	}
	if (! empty($arrayfields['s.note_private']['checked'])) {
		print_liste_field_titre(
						$arrayfields['s.note_private']['label'], $_SERVER["PHP_SELF"], "s.note_private", "",
						$urlparam, '', $sortfield, $sortorder
		);	
	}

	if (! empty($arrayfields['f.description']['checked'])) {
		print_liste_field_titre(
			$langs->trans("DescInter"), $_SERVER["PHP_SELF"], 'f.description', 
			"", $urlparam, '', $sortfield, $sortorder
		);
	}

	if (! empty($arrayfields['f.note_public']['checked'])) {
		print_liste_field_titre(
						$arrayfields['f.note_public']['label'], $_SERVER["PHP_SELF"], "f.note_public", "",
						$urlparam, '', $sortfield, $sortorder
		);	
	}
	if (! empty($arrayfields['f.note_private']['checked'])) {
		print_liste_field_titre(
						$arrayfields['f.note_private']['label'], $_SERVER["PHP_SELF"], "f.note_private", "",
						$urlparam, '', $sortfield, $sortorder
		);	
	}

	if (! empty($arrayfields['ft.date']['checked'])) {
		print_liste_field_titre(
						$arrayfields['ft.date']['label'], $_SERVER["PHP_SELF"], "ft.date", "",
						$urlparam, '', $sortfield, $sortorder
		);	
	}
	if (! empty($arrayfields['ft.duree']['checked'])) {
		print_liste_field_titre(
						$arrayfields['ft.duree']['label'], $_SERVER["PHP_SELF"], "ft.duree", "",
						$urlparam, "align=right", $sortfield, $sortorder
		);	
	}

	if (! empty($arrayfields['ft.description']['checked'])) {
		print_liste_field_titre(
						$arrayfields['ft.description']['label'], $_SERVER["PHP_SELF"], "ft.description", "",
						$urlparam, '', $sortfield, $sortorder
		);	
	}


	$contactWidth='';
	if ($conf->global->MYSCHEDULE_nbcontactonlist > 0)
		$contactWidth='width=15%';

	if (! empty($arrayfields['affecteduser']['checked'])) {
			print_liste_field_titre(
			$langs->trans("AffectedUser"), $_SERVER["PHP_SELF"], "", 
			"", $urlparam, $contactWidth, $sortfield, $sortorder
		);
	}
	if (! empty($arrayfields['affectedcontact']['checked'])) {
		print_liste_field_titre(
			$langs->trans("AffectedContact"), $_SERVER["PHP_SELF"], "", 
			"", $urlparam, $contactWidth, $sortfield, $sortorder
		);
	}
	print_liste_field_titre(
					$langs->trans("Status"), $_SERVER["PHP_SELF"], "f.fk_statut", 
					"", $urlparam, 'width=80px align="right"', $sortfield, $sortorder
	);

	print_liste_field_titre(
		$selectedfields, $_SERVER["PHP_SELF"], "", '', '',
		'align="right"', $sortfield, $sortorder, 'maxwidthsearch '
	);


	print "</tr>\n";

	$object = new Fichinter($db);
	$fichinterdet_schedule = new fichinterdet_schedule($db);
	$userstatic=new User($db);
	$contactstatic=new Contact($db);

	while ($j < $num) {
		$objp = $db->fetch_object($resql);
		$object->fetch($objp->fk_fichinter);
		$object->fetch_thirdparty();
		$tab = $object->liste_contact(-1, 'internal');
		$nbUser=count($tab);
		$title="";
		// la gestion des utilisateur
		$nbUser = count($tab);
		if ($nbUser > 0) {

			$totalPlanned= 0;
			$totalMade= 0;
			$bshowelement=false;

			// champs contenant les ids des inter et contact ainsi que le temps associé
			foreach($tab as $userinter) {
				$ret = $userstatic->fetch($userinter['id']);
				$title.="<div  style='float:left;width:99%;'><div style='display: inline-block;'>".$userstatic->getnomUrl(1, "", 0, 1)."</div>";
				 //.' ('.$userinter['libelle'].')'."<br>";

				// on récupère ce qui a été saisie pour cet user/inter
				//$ret = $fichinterdet_schedule->fetch(0, $userinter['id'], $objp->rowid);
				$sql = 'SELECT rowid, fk_product, duration_planned, duration_made';
				$sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet_schedule';
				$sql.= ' WHERE fk_fichinterdet = '.$objp->rowid;
				$sql.= ' AND fk_user = '.$userinter['id'];
				$reusersql = $db->query($sql);
				$planned = 0;
				$default = "";
				$made = 0;
				if ($reusersql) {
					$objuser = $db->fetch_object($reusersql);
					$planned = $objuser->duration_planned;
					$made = ($objuser->duration_made!=0?$objuser->duration_made:0);

					$title.=" (".convertSecondToTime($planned, "allhourmin", 86400);
					if ($made)
						$title.='/'.convertSecondToTime($made, "allhourmin", 86400);
					$title.=')';
					$totalPlanned+= $planned;
					$totalMade+= $made;
				}
				$title.="</div>";
			}
		}
		$tabcontact = $object->liste_contact(-1, 'external');
		$listContact="";
		// la gestion des contacts
		$nbcontact = count($tabcontact);
		if ($nbcontact > 0) {
			// champs contenant les ids des inter et contact ainsi que le temps associé
			foreach($tabcontact as $contactInter) {
				$ret = $contactstatic->fetch($contactInter['id']);
				$listContact.="<div  style='float:left;width:99%;'>";
				$listContact.="<div style='display: inline-block;'>".$contactstatic->getnomUrl(1)."</div>";
				$listContact.="</div>";
			}
		}

		$bshowelement=false;
		$textColor="black";
		// si pas de collaborateur
		if ($nbUser == 0){
			$bgcolor="#".$conf->global->MYSCHEDULE_colornouser;
			if(in_array('nouser', $statutinter))
				$bshowelement=true;
		} elseif ($totalPlanned < $objp->duree || $ret == 0) {
			$bgcolor="#".$conf->global->MYSCHEDULE_colornotplanned;
			if(in_array('notplanned', $statutinter))
				$bshowelement=true;
		} elseif($totalPlanned >= $objp->duree && $made == 0){
				$bgcolor="#".$conf->global->MYSCHEDULE_colornotmade;
			if(in_array('notmade', $statutinter))
				$bshowelement=true;
		} elseif($made > 0){
			$bgcolor="#".$conf->global->MYSCHEDULE_colormade;
			if(in_array('made', $statutinter))
				$bshowelement=true;
		} else {
			$bgcolor="#C0C0C0";
			if(in_array('made', $statutinter))
				$bshowelement=true;
		}

		if($bshowelement) {
			print '<tr ><td nowrap valign=top>';
			print $object->getNomUrl(1);
			print '</td><td valign=top>';
			//var_dump($object);
			print $object->thirdparty->getNomUrl(1);
			if (! empty($arrayfields['s.address']['checked']))
				print "<br>".$object->thirdparty->address;
			if (!empty($arrayfields['s.zip']['checked']) || !empty($arrayfields['s.town']['checked'])) {
				print "<br>";
				if (!empty($arrayfields['s.zip']['checked']))
					print $object->thirdparty->zip;
				if (!empty($arrayfields['s.town']['checked']))
				print "&nbsp;".$object->thirdparty->town;
			}
			if (!empty($arrayfields['s.phone']['checked']) || !empty($arrayfields['s.email']['checked'])) {
				print "<br>";
				if (!empty($arrayfields['s.phone']['checked']))
					print $object->thirdparty->phone;
				if (!empty($arrayfields['s.email']['checked']))
				print "&nbsp;".$object->thirdparty->email;
			}

			// on ajoute les infos supp si elle sont demandé

			print '</td>';
			if (! empty($arrayfields['f.description']['checked']))
				print '<td valign=top>'.$objp->descinter.'</td>';

			if (! empty($arrayfields['ft.date']['checked'])) {
				print '<td align=left  valign=top>';
				$datedebevent =$db->jdate($objp->date_intervention);
				print date("d", $datedebevent)."/".date("m", $datedebevent)."/".date("Y", $datedebevent);
				print " - ".date("H", $datedebevent).":".date("i", $datedebevent);
				print '</td>';
			}
			
			if (! empty($arrayfields['ft.duree']['checked'])) {
				print '<td align=right  valign=top>';
				$dureehour = round($objp->duree/3600, 0, PHP_ROUND_HALF_DOWN);
				$dureemin =  ($objp->duree - ($dureehour*3600)) / 60;
				if ($dureemin < 10) 
					$dureemin = "0".$dureemin;
				print $dureehour.":".$dureemin;
				print '</td>';
			}
			if (! empty($arrayfields['ft.description']['checked']))
				print '<td valign=top>'.$objp->description.'</td>';

			if (! empty($arrayfields['affecteduser']['checked'])) {
				print '<td  valign=top>';
				if ($nbUser > $conf->global->MYSCHEDULE_nbcontactonlist)
					print img_picto($title, 'object_group', ' class="classfortooltip"' );
				else
					print $title;
				print '</td>';
			}

			if (! empty($arrayfields['affectedcontact']['checked'])) {
				print '<td valign=top align=left>';
				// on affiche la liste des contacts dans un tooltip si il sont trop nombreux
				if ($nbcontact> $conf->global->MYSCHEDULE_nbcontactonlist)
					print img_picto($listContact, 'object_group', ' class="classfortooltip"' );
				else
					print $listContact;
				print '</td>';
			}
			print '<td colspan=2 style="background-color:'.$bgcolor.';" valign=top align=right>';
			print $object->getLibStatut(2);
			print '</td></tr>';
		}
		$j++;
	}
	print '</table >';
}
print '</form>';


llxFooter();
$db->close();