Modifications du planning.

Contribuer au projet de part vos connaissances: PHP, HTML, CSS, SQL, JS ....
Répondre
Ptitvincou
Gsup LEVEL 1
Messages : 28
Enregistré le : lun. 18 févr. 2013 18:23

Modification du planning : ajout des dates de résolution estimées comme "événements" et trie par technicien

Pour infos mes besoins étaient ceux ci: avoir un planning des interventions estimées pour chaque technicien avec une vue pour chacun afin de l'imprimer.

Ce que font mes modifs:
Tous les tickets enregistrés ou modifiés avec une date estimée sont ajoutées au planning a 7h00 le matin (par fainéantise). Par défaut tous les évènements sont affichés mais on peut sélectionner un technicien.
Petit plus: quand on supprime un ticket l’événement disparait du planning ce qui si je ne me trompe pas n’était pas le cas auparavant.

dans les pages:
-ticket.php: modification a la ligne 70 -> 73 et 155 -> 176

-newticket.php: modification a la ligne 77 -> 84

-planning.php: modification a la ligne 82 -> 116 puis pour chaque <td> de chaque jour (ex: lignes 195 -> 214)


J'ai encadré les lignes modifiées par des "// ############ vincent" sauf pour les <td> de planning.php ...
Si vous avez une adresse mail vers laquelle je peux transférer le code source sinon voir ci-dessous :

A COPIER DANS NOTEPAD++ pour la correspondance des lignes ....

ticket.php:

Code : Tout sélectionner

<?php
/*
Author: Flox
FileName: ticket.php
Description: page to edit ticket
Version: 1.6
Last update: 24/01/2012
*/

// initialize variables 
if(!isset($userreg)) $userreg = ''; 
if(!isset($category)) $category = ''; 
if(!isset($subcat)) $subcat = ''; 
if(!isset($title)) $title = ''; 
if(!isset($date_hope)) $date_hope = ''; 
if(!isset($date_create)) $date_create = ''; 
if(!isset($dateres)) $dateres = ''; 
if(!isset($description)) $description = ''; 
if(!isset($resolution)) $resolution = ''; 
if(!isset($priority)) $priority = '';
if(!isset($dateres)) $dateres = '';
if(!isset($percentage)) $percentage = '';
if(!isset($id)) $id = '';
if(!isset($id_in)) $id_in = '';
if(!isset($save)) $save = '';
if(!isset($techread)) $teachread = '';
if(!isset($next)) $next = '';
if(!isset($previous)) $previous = '';
if(!isset($_GET['action'])) $_GET['action'] = '';
if(!isset($user)) $user = '';
if(!isset($globalrow['time'])) $globalrow['time'] = '';
if(!isset($_POST['mail'])) $_POST['mail'] = '';
if(!isset($_POST['upload'])) $_POST['upload'] = '';
if(!isset($_POST['title'])) $_POST['title'] = '';
if(!isset($_POST['description'])) $_POST['description'] = '';
if(!isset($_POST['resolution'])) $_POST['resolution'] = '';
if(!isset($_POST['Submit'])) $_POST['Submit'] = '';
if(!isset($_POST['subcat'])) $_POST['subcat'] = '';
if(!isset($_POST['user'])) $_POST['user'] = '';
if(!isset($_POST['modify'])) $_POST['modify'] = '';
if(!isset($_POST['quit'])) $_POST['quit'] = '';
if(!isset($_POST['date_create'])) $_POST['date_create'] = '';
if(!isset($_POST['date_hope'])) $_POST['date_hope'] = '';
if(!isset($_POST['date_res'])) $_POST['date_res'] = '';
if(!isset($_POST['priority'])) $_POST['priority'] = '';
if(!isset($_POST['criticality'])) $_POST['criticality'] = '';
if(!isset($_POST['category'])) $_POST['category'] = '';
if(!isset($_POST['time'])) $_POST['time'] = '';
if(!isset($_POST['time_hope'])) $_POST['time_hope'] = '';
if(!isset($_POST['state'])) $_POST['state'] = '';
if(!isset($_POST['cancel'])) $_POST['cancel'] = '';
if(!isset($_POST['technician'])) $_POST['technician'] = '';

// find current date & hour 
$hour = date("H:i");
$date = date("d/m/Y");
$today = "$date $hour";

//action print
if ($_GET['action']=="print") echo '<body onload="window.print();"> </body>';

//action delete
if ($_GET['action']=="delete") 
{
//disable ticket
$query = "UPDATE tincidents SET disable='1' WHERE id LIKE '$_GET[id]'";
$exec = mysql_query($query) or die('Erreur SQL !<br /><br />'.mysql_error());


//#################VINCENT
$query = "UPDATE tevents SET disable='1' WHERE incident LIKE '$_GET[id]'";
$exec = mysql_query($query) or die('Erreur SQL !<br /><br />'.mysql_error());
//FIN VINCENT

//redirect
echo "<div id=\"erreur\"><img src=\"./images/delete_max.png\" border=\"0\" /> Ticket supprimé.</div>";
	// redirect
	echo "<SCRIPT LANGUAGE='JavaScript'>
			<!--
			function redirect()
			{
			window.location='./index.php?page=dashboard&techid=$_SESSION[user_id]&state=1'
			}
			setTimeout('redirect()',$rparameters[time_display_msg]);
			-->
			</SCRIPT>";
}

//Master query
$globalquery = mysql_query("SELECT * FROM tincidents WHERE id LIKE '$_GET[id]'");
$globalrow=mysql_fetch_array($globalquery); 

//Database inputs if submit
if($_POST['modify']||$_POST['quit']||$_POST['mail']||$_POST['upload']||$save=="1") 
{
	// special char in sql query
	$_POST['description']  = str_replace('\\','\\\\',$_POST['description']);
	$_POST['resolution']  = str_replace("\\","\\\\",$_POST['resolution']);
	$_POST['title']  = str_replace("\\","\\\\",$_POST['title']);	
	$_POST['description'] = str_replace("'","\'",$_POST['description']); 
	$_POST['resolution']  = str_replace("'","\'",$_POST['resolution']); 
	$_POST['title']  = str_replace("'","\'",$_POST['title']); 
	$_POST['title']  = str_replace(chr(34),"\'",$_POST['title']);  
	
	// Include technician transfert 
	if ($_POST['technician']!=$globalrow['technician'] && $_POST['technician']!='')
	{
	$q1= mysql_query("SELECT * FROM tusers where id = $globalrow[technician]");
	$r1=mysql_fetch_array($q1); 
	$q2 = mysql_query("SELECT * FROM tusers where id = $_POST[technician]");
	$r2=mysql_fetch_array($q2);
	if ($globalrow['technician']=='0')
		{
		$_POST['resolution']="$today: Attribution de l\'incident à $r2[firstname] $r2[lastname].
$_POST[resolution]";
		} else {
		$_POST['resolution']="$_POST[resolution]
$today: Transfert de l\'incident de $r1[firstname] $r1[lastname] à $r2[firstname] $r2[lastname]. ";
		}
	}
	//AUTO modify state from 5 to 1 if technician change
	if ($_POST['technician']!=''&& $globalrow['state']=='5') $_POST['state']='1';
	
	//insert resolution date if state is res
	if ($_POST['state']=='3' && $globalrow['date_res']=='0000-00-00') $dateres=date("Y-m-d"); else $dateres=$_POST['date_res'];
	
	//unread ticket case when creator is not techncian 
	if($_POST['technician']!=$globalrow['technician']) $techread=0; else $techread=1;
	
	//unread ticket case when it's an unassigned ticket.
	if($globalrow['technician']=='') $techread=1;
	
	//Update ticket
	$query = "UPDATE tincidents SET 
	user='$_POST[user]',
	technician='$_POST[technician]',
	title='$_POST[title]',
	description='$_POST[description]',
	resolution='$_POST[resolution]',
	date_create='$_POST[date_create]',
	date_hope='$_POST[date_hope]',
	date_res='$dateres',
	priority='$_POST[priority]',
	criticality='$_POST[criticality]',
	state='$_POST[state]',
	time='$_POST[time]',
	time_hope='$_POST[time_hope]',
	category='$_POST[category]',
	subcat='$_POST[subcat]',
	techread='$techread'
	WHERE
	id LIKE '$_GET[id]'";
	$exec = mysql_query($query) or die('Erreur SQL !<br /><br />'.mysql_error());
	
//#################VINCENT
	$dateModifiee = $_POST['date_hope'].' 07:00:00';
	
	$query = mysql_query("SELECT * FROM `tevents` WHERE incident LIKE '$_GET[id]'"); 
	// si il y a un enregistrement a modifier 
	if(mysql_num_rows($query) >= 1)
	{
		$query_vincent = "UPDATE tevents SET date_start= '$dateModifiee' WHERE incident LIKE '$_GET[id]'";
		$exec_vincent = mysql_query($query_vincent) or die('Erreur SQL !<br /><br />'.mysql_error());
	}
	else // on le creer
	{
		if($_POST['date_hope'])
		{
			$dateModifiee = $_POST['date_hope'].' 07:00:00';
			$query_vincent= "INSERT INTO tevents (technician,incident,date_start,date_end,type,disable) VALUES ('$_POST[technician]','$_GET[id]','$dateModifiee','','3','0')";
			$exec_vincent = mysql_query($query_vincent) or die('Erreur SQL !<br />'.mysql_error());
		}
	}
	
	
//##############FIN VINCENT
	
	
	//uploading files
	include "./core/upload.php";
	
	//auto send mail
	if($rparameters['mail_auto']==1&&($_POST['upload']=='')){include('./core/auto_mail.php');}
	
	// redirect
	if ($_POST['quit'])
	{
		//select redirect page
		if ($_GET['state']=="1") {$www = "./index.php?page=dashboard&techid=$_SESSION[user_id]&state=1";} 
		else if ($_GET['state']=="2") {$www = "./index.php?page=dashboard&techid=$_SESSION[user_id]&state=2";}
		else {$www = "./index.php?page=dashboard&techid=$_SESSION[user_id]&state=1";}
			
		echo '<script language="Javascript">
		<!--
		document.location.replace("'.$www.'");
		// -->
		</script>';
	}
	echo "<div id=\"valide\"><img src=\"./images/save.png\" border=\"0\" /> Ticket sauvegardé.</div>";
	
	// send mail
	if($_POST['mail'])
	{
		// redirect
		$www = "./index.php?page=preview_mail&id=$_GET[id]";
		echo '<script language="Javascript">
		<!--
		document.location.replace("'.$www.'");
		// -->
		</script>';
	}
	

	// redirect
	echo "<SCRIPT LANGUAGE='JavaScript'>
			<!--
			function redirect()
			{
			window.location='./index.php?page=ticket&id=$_GET[id]'
			}
			setTimeout('redirect()',$rparameters[time_display_msg]);
			-->
			</SCRIPT>";
}
if($_POST['cancel']) 
{
echo "<div id=\"erreur\"><img src=\"./images/delete_max.png\" border=\"0\" /> Annulation pas de modification.</div>";
echo "<SCRIPT LANGUAGE='JavaScript'>
			<!--
			function redirect()
			{
			window.location='./index.php?page=dashboard&techid=$_GET[techid]&state=$_GET[state]'
			}
			setTimeout('redirect()',$rparameters[time_display_msg]);
			-->
			</SCRIPT>";
}
  
//unread ticket technician
if (($globalrow['techread']=="0")&&($globalrow['technician']==$_SESSION['user_id'])) 
{
	$query = "UPDATE tincidents SET techread='1' WHERE id='$_GET[id]'";
	$exec = mysql_query($query) or die('Erreur SQL !<br /><br />'.mysql_error());
}
//find previous and next ticket
$query = mysql_query("SELECT MIN(id) FROM tincidents WHERE id > '$_GET[id]' AND id IN (SELECT id FROM tincidents WHERE technician='$techid' AND state='$state' AND id not like '$_GET[id]')");
$next = mysql_fetch_array($query);
$query = mysql_query("SELECT MAX(id) FROM tincidents WHERE id < '$_GET[id]' AND id IN (SELECT id FROM tincidents WHERE technician='$techid' AND state='$state' AND id not like '$_GET[id]')");
$previous = mysql_fetch_array($query);

//percentage calc of ticket resolution
if ($globalrow['time_hope']!=0)
{
	$percentage=($globalrow['time']*100)/$globalrow['time_hope'];
	$percentage=round($percentage);
	if (($globalrow['time']!='1') && ($globalrow['time_hope']!='1') && ($globalrow['time_hope']>=$globalrow['time'])) $percentage="<font size=\"2\"><i>($percentage%)</i></font>"; else $percentage='';
}
?>

<div id="catalogue">
	<form name="form" enctype="multipart/form-data" method="post" action="" id="thisform">
		<h2 class="sec_head"><img src="./images/ticket-icon.png" /> Edition du ticket n°<?php echo "$_GET[id]   $percentage"; ?> &nbsp;&nbsp;
		<?php 
		//Display clock if alarm 
		$query = mysql_query("SELECT * FROM tevents WHERE incident='$_GET[id]' and disable='0'");
		$alarm = mysql_fetch_array($query);
		if($alarm) echo '<img title="Alame activée le '.$alarm['date_start'].'" src="./images/clock2.png" />';
		
		if($previous[0]!='') echo"		<a href=\"./index.php?page=ticket&id=$previous[0]&state=$state&techid=$techid\"><img border=\"0\" title=\"Ticket précédent\" src=\"./images/left.png\" /></a>&nbsp;"; 
		if($next[0]!='') echo"	<a href=\"./index.php?page=ticket&id=$next[0]&state=$state&techid=$techid \"><img border=\"0\" title=\"Ticket suivant\" src=\"./images/right.png\" /></a>";
		if ($rright['ticket_delete']!=0) echo '<a href="./index.php?page=ticket&id='.$_GET['id'].'&action=delete"><img align="right" style="margin:2px 10px 0px 0px; border-style: none;" alt="img" src="./images/delete_max.png" title="Supprimer ce ticket" /></a>';

		?>
		<a target="_blank" href="./index.php?page=ticket&id=<?php echo $_GET['id']; ?>&action=print"><img align="right" style="margin:2px 10px 0px 0px; border-style: none;" alt="img" src="./images/print.png" title="Imprimer" /></a>
		<?php if (($rright['planning']!=0) && ($rparameters['planning']==1))  echo "<img align=\"right\" style=\"margin:2px 10px 0px 0px; border-style: none;\"  alt=\"img\" src=\"./images/planning.png\" title=\"Planifier une intervention pour ce ticket\" onClick=\"window.open('./event_add.php?id=$_GET[id]&technician=$_SESSION[user_id]&planning=1','useradd','width=400,height=300')\"/></a>"; ?>
		<img align="right" style="margin:2px 10px 0px 0px; border-style: none;"  alt="img" src="./images/event.png" title="Créer un rappel pour ce ticket" onClick="window.open('./event_add.php?id=<?php echo $_GET['id']; ?>&technician=<?php echo $_SESSION['user_id']; ?>','useradd','width=350,height=300')"/></a>
		</h2>
		<br />
		<label  for="user">Demandeur:</label>
		<select class="textfield" id="user" name="user" onchange="submit();">
		   	<?php
			$query = mysql_query("SELECT * FROM `tusers` WHERE disable='0' ORDER BY lastname ASC, firstname ASC");
			while ($row=mysql_fetch_array($query)) {echo "<option value=\"$row[id]\">$row[lastname] $row[firstname]</option>";}
			//user selection
			if ($_POST['user'])	{$user=$_POST['user'];}	else {$user=$globalrow['user'];}
			$query = mysql_query("SELECT * FROM tusers WHERE id LIKE $user");
			$row = mysql_fetch_array($query);
			echo "<option selected value=\"$user\">$row[lastname] $row[firstname]</option>";
			?>
		</select>
		<img title="Ajouter un utilisateur" src="./images/plus.png" style="border-style: none" alt="img" value='useradd' onClick="window.open('./newticket_useradd.php','useradd','width=420,height=230')" />
		<img title="Modifier un utilisateur" src="./images/edit.png" style="border-style: none" alt="img" value='useredit' onClick="window.open('./newticket_useradd.php?id=<?php echo $globalrow['user']; ?>','useredit','width=420,height=230')" />
		<input title="Actualiser la liste" border="0" src="./images/actualiser.png" type="image" value="submit" align="absmiddle" /> 
	<?php
		//Display phone number if exist
		if ($_POST['user']) 
		{
			$query = mysql_query("SELECT * FROM `tusers` WHERE id LIKE '$_POST[user]'"); 
		}
		else
		{
			$query = mysql_query("SELECT * FROM `tusers` WHERE id LIKE '$globalrow[user]'"); 
		}
		$row=mysql_fetch_array($query);
		if ($row['phone']!="") echo "&nbsp;&nbsp;<img src=\"./images/tel.png\" border=\"0\" /> <b>$row[phone]</b>";
		if ($row['mail']!="") echo "&nbsp;<img title=\"$row[mail]\" src=\"./images/mail_min.png\" border=\"0\" />";
		
		//other demands for this user 
		if($_POST['user']) $umodif=$_POST['user']; else  $umodif=$globalrow['user'];
		$qn = mysql_query("SELECT count(*) FROM `tincidents` WHERE user LIKE '$umodif' and (state='1' OR state='2') and id NOT LIKE $_GET[id] and disable=0"); 
		while ($rn=mysql_fetch_array($qn))
		$rnn=$rn[0];
		if ($rnn!=0) echo "&nbsp;&nbsp;<i>(";
		$c=0;
		$q = mysql_query("SELECT * FROM `tincidents` WHERE user LIKE '$umodif' and (state='1' OR state='2') and id NOT LIKE $_GET[id] and disable=0"); 
		while (($r=mysql_fetch_array($q)) && ($c<7)) {	
			$c=$c+1;
			echo "<a title=\"$r[title]\" href=\"./index.php?page=ticket&id=$r[id]\">$r[id]</a>";
			if ($c<$rnn) echo ",";
			if ($c==7) echo "...";
		}  
		if ($rnn!=0) echo ")</i>";
		?>
		<br />
		<label for="technician">Technicien:</label>
		<select class="textfield" id="technician" name="technician" >
		   	<?php
			if ($_POST['technician'])
			{
				echo "coucou";
				$querytech = mysql_query("SELECT * FROM `tusers` WHERE disable='0' and id LIKE '$_POST[technician]' ");
			} else {
				$querytech = mysql_query("SELECT * FROM `tusers` WHERE disable='0' and id LIKE '$globalrow[technician]' ");		
			}
			$row=mysql_fetch_array($querytech);
			echo "<option value=\"$row[id]\" selected >$row[lastname] $row[firstname]</option>"; 
			$query = mysql_query("SELECT * FROM `tusers` WHERE disable='0' and profile LIKE '0' and id!='$globalrow[technician]' ORDER BY lastname ASC, firstname ASC") ;
			while ($row=mysql_fetch_array($query)) {echo "<option value=\"$row[id]\">$row[lastname] $row[firstname] </option>";} 
			?>
		</select>
		<?php
		if (($globalrow['creator']!=$globalrow['technician']) && ($globalrow['creator']!="0") )
		{
			// select creator name
			$query = mysql_query("SELECT firstname FROM `tusers` WHERE id LIKE '$globalrow[creator]'");
			$row=mysql_fetch_array($query);
			echo "<img src=\"./images/admin.png\" border=\"0\" /> Ouvert par $row[0]";
		}
		?>
		<br />
		<label for="category">Catégorie:</label>
		<select class="textfield" id="category" name="category" onchange="submit();">
		<?php
			$query= mysql_query("SELECT * FROM `tcategory` order by name ");
			while ($row=mysql_fetch_array($query)) 
			{
				echo "<option value=\"$row[id]\">$row[name]</option>";
				if ($_POST['category'])
				{
					if ($_POST['category']==$row['id']) echo "<option value=\"$row[id]\" selected>$row[name]</option>";
				}
				else
				{
					if ($globalrow['category']==$row['id']) echo "<option value=\"$row[id]\" selected>$row[name]</option>";
				}
			}
			if ($globalrow['category']==0 && $_POST['category']==0) echo "<option value=\"\" selected></option>";
		?>
		</select>
		<select class="textfield" id="subcat" name="subcat" >
		<?php
			if ($_POST['category'])
			{$query= mysql_query("SELECT * FROM `tsubcat` WHERE cat LIKE '$_POST[category]' order by name ASC");}
			else
			{$query= mysql_query("SELECT * FROM `tsubcat` WHERE cat LIKE '$globalrow[category]' order by name ASC");}
			
			while ($row=mysql_fetch_array($query)) 
			{
				echo "<option value=\"$row[id]\">$row[name]</option>";
				if ($_POST['subcat'])
				{
					if ($_POST['subcat']==$row['id']) echo "<option value=\"$row[id]\" selected>$row[name]</option>";
				}
				else
				{
					if ($globalrow['subcat']==$row['id']) echo "<option value=\"$row[id]\" selected>$row[name]</option>";
				}
			} 
			if ($globalrow['subcat']==0 && $_POST['subcat']==0) echo "<option value=\"\" selected></option>";
		?>
		</select>
		<img title="Ajouter une categorie" src="./images/plus.png" style="border-style: none" alt="img" value='useradd' onClick="window.open('./edit_categories.php?cat=<?php echo $globalrow['category']; ?>','useradd','width=400,height=200')" />
		<img title="Modifier une categorie" src="./images/edit.png" style="border-style: none" alt="img" value='useredit' onClick="window.open('./edit_categories.php?cat=<?php echo $_POST['category']; ?>&subcat=<?php echo $_POST['subcat']; ?>','useredit','width=400,height=200')" />
		<input title="Actualiser la liste" border="0" src="./images/actualiser.png" type="image" value="submit" align="absmiddle" /> 
		<br />
		<label for="title">Titre:</label>
		<input class="textfield" name="title" id="title" type="text" size="50"  value="<?php if ($_POST['title']) echo $_POST['title']; else echo $globalrow['title']; ?>" />
		<br />
		<label for="description">Descritption:</label>
		<br />
		<textarea class="textfield" id="description" name="description" cols="100" rows="2" ><?php if ($_POST['description']) echo $_POST['description']; else echo $globalrow['description']; ?></textarea>
		<?php include "./attachement.php";?>
		<br /><br />
		<label for="resolution">Résolution:</label>
		<br />
		&nbsp;&nbsp;<img title="Insérer la date et l'heure du jour" src="./images/date.png" onclick="insertAtCaret('resolution','<?php if ($uid!=$globalrow['technician'])  echo "$today $reqfname[firstname]:"; else echo "$today: ";?>');" /><br />
		<textarea class="textfield" id="resolution" name="resolution" cols="100" rows="2" ><?php if ($_POST['resolution']) echo $_POST['resolution']; else echo $globalrow['resolution']; ?></textarea>
		<br />
		<label for="date_create">Date de la demande:</label>
		<input style="display: inline;" class="textfield" type='text' name='date_create' value="<?php if ($_POST['date_create']) echo $_POST['date_create']; else echo $globalrow['date_create']; ?>" ><img src="./images/calendar.png" value='Calendrier' onClick="window.open('components/mycalendar/mycalendar.php?form=form&elem=date_create','Calendrier','width=400,height=400')">
		<br />
		<label for="date_hope">Date de résolution estimée:</label>
		<input style="display: inline;" class="textfield" type='text' name='date_hope'  value="<?php  if ($_POST['date_hope']) echo $_POST['date_hope']; else echo $globalrow['date_hope']; ?>" ><img src="./images/calendar.png" value='Calendrier' onClick="window.open('components/mycalendar/mycalendar.php?form=form&elem=date_hope','Calendrier','width=400,height=400')">
		<?php
			//display warning if hope date is passed
			$date_hope=$globalrow['date_hope'];
			$querydiff=mysql_query("SELECT DATEDIFF(NOW(), '$date_hope') "); 
			$resultdiff=mysql_fetch_array($querydiff);
			if ($resultdiff[0]>0 && ($globalrow['state']!="3" && $globalrow['state']!="4")) echo "<img border=\"0\" title=\"Date de résolution dépassée de $resultdiff[0] jours de retard\" src=\"./images/warning_min.png\" />";
			
		?>
		<br />
		<?php
			if ($globalrow['date_res']!="0000-00-00")
			{
				echo "
					<label for=\"date_res\">Date de résolution :</label>
					<input style=\"display: inline;\" class=\"textfield\" type='text' name='date_res'  value=".$globalrow['date_res']."  >
					<br />
				";
			}
		?>
		<label for="time">Temps passé:</label>
		<select class="textfield" id="time" name="time" >
		<?php
			$query = mysql_query("SELECT * FROM `ttime` order by min ASC");
			while ($row=mysql_fetch_array($query)) 
			{
				echo '<option value="'.$row['min'].'">'.$row['name'].'</option>';
				if (($_POST['time']==$row['min'])||($globalrow['time']==$row['min'])) echo '<option selected value="'.$row['min'].'">'.$row['name'].'</option>'; 
			}
		?>
		</select>
		<br />
		<label for="time">Temps estimé:</label>
		<select class="textfield" id="time_hope" name="time_hope" >
		<?php
			$query = mysql_query("SELECT * FROM `ttime` order by min ASC");
			while ($row=mysql_fetch_array($query)) 
			{
				echo '<option value="'.$row['min'].'">'.$row['name'].'</option>';
				if (($_POST['time_hope']==$row['min'])||($globalrow['time_hope']==$row['min'])) echo '<option selected value="'.$row['min'].'">'.$row['name'].'</option>'; 
			}
		?>
		</select>
		<?php
			//display error if time hope < time pass
		
			if (($globalrow['time_hope']<$globalrow['time']) && $globalrow['state']!='3') echo "<img border=\"0\" title=\"La durée estimée est inférieur à la durée dèja passé.\" src=\"./images/critical_min.png\" />";
			
		?>
		<br />
		<label for="priority">Priorité:</label>
		<select class="textfield" id="priority" name="priority" >
		   	<?php
			if ($_POST['priority'])
			{
				$query = mysql_query("SELECT * FROM `tpriority` WHERE number LIKE '$_POST[priority]'");
				$row=mysql_fetch_array($query);
				echo "<option value=\"$_POST[priority]\" selected >$row[name]</option>";
			}
			else
			{
				$query = mysql_query("SELECT * FROM `tpriority` WHERE number LIKE '$globalrow[priority]'");
				$row=mysql_fetch_array($query);
				echo "<option value=\"$globalrow[priority]\" selected >$row[name]</option>";
			}			
			$query = mysql_query("SELECT * FROM `tpriority`");
			while ($row=mysql_fetch_array($query)) echo "<option value=\"$row[number]\">$row[name]</option>"; 
			?>			
		</select>
		<br />
		<label for="priority">Criticité:</label>
		<select class="textfield" id="criticality" name="criticality" >
		   	<?php
			if ($_POST['criticality'])
			{
				$query = mysql_query("SELECT * FROM `tcriticality` WHERE id LIKE '$_POST[criticality]'");
				$row=mysql_fetch_array($query);
				echo "<option value=\"$_POST[criticality]\" selected >$row[name]</option>";
			}
			else
			{
				$query = mysql_query("SELECT * FROM `tcriticality` WHERE id LIKE '$globalrow[criticality]'");
				$row=mysql_fetch_array($query);
				echo "<option value=\"$globalrow[criticality]\" selected >$row[name]</option>";
			}			
			$query = mysql_query("SELECT * FROM `tcriticality` ORDER BY number");
			while ($row=mysql_fetch_array($query)) echo "<option value=\"$row[id]\">$row[name]</option>"; 
			?>			
		</select>
		<?php
		//Display criticality picture
		$query = mysql_query("SELECT * FROM `tcriticality` WHERE id LIKE '$globalrow[criticality]'");
		$row=mysql_fetch_array($query);
		echo "<img style=\"border-style: none\" alt=\"img\" src=\"./images/critical_$row[color].png\" />";
		?>
		<br />
		<label for="state">État:</label>
		<select class="textfield" id="state"  name="state" >
		   	<?php
			if ($_POST['state'])
			{
				$query = mysql_query("SELECT * FROM `tstates` WHERE id LIKE '$_POST[state]'");
				$row=mysql_fetch_array($query);
				echo "<option value=\"$_POST[state]\" selected >$row[name]</option>";
			}
			else
			{
				$query = mysql_query("SELECT * FROM `tstates` WHERE id LIKE '$globalrow[state]'");
				$row=mysql_fetch_array($query);
				echo "<option value=\"$globalrow[state]\" selected >$row[name]</option>";
			}			
			$query = mysql_query("SELECT * FROM `tstates` ORDER BY number");
			while ($row=mysql_fetch_array($query)) echo "<option value=\"$row[id]\">$row[name]</option>"; 
			?>
		</select>
		<img style="border-style: none" alt="img" src="./images/<?php echo $globalrow['state']; ?>.png" />
		<br /><br /><br />
		<div  class="buttons">
			<button name="modify" value="Enregistrer" type="submit"  class="positive"  id="modify">
				<img src="images/apply2.png" alt=""/>
				Enregistrer
			</button>
			
			<button name="quit" value="Enregistrer et Fermer" type="submit" class="positive" id="quit">	
				<img src="images/apply2.png" alt=""/>
				Enregistrer et Fermer
			</button>

			<button value="Mail" type="submit" class="regular" name="mail" id="mail">
			 <img src="images/mail_icn.png" alt=""/>
				Envoyer un mail
			</button>

			<button value="cancel" type="submit" class="negative" name="cancel" id="cancel">
				<img src="images/cross.png" alt=""/>
				Annuler
			</button>
		</div>
<br /><br /><br />

	</form>
</div>



<!-- Script allow autogrow textareas -->
<script>
$('textarea').ata();
</script>

<script type="text/javascript">
        // jQuery en action
        jQuery.noConflict();
        jQuery('#jquery').addClass('jquery');

        // Prototype en action
        $('prototype').addClassName('prototype');
</script>

<SCRIPT language="Javascript">
function insertAtCaret(areaId,text) {
	var txtarea = document.getElementById(areaId);
	var scrollPos = txtarea.scrollTop;
	var strPos = 0;
	var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? 
		"ff" : (document.selection ? "ie" : false ) );
	if (br == "ie") { 
		txtarea.focus();
		var range = document.selection.createRange();
		range.moveStart ('character', -txtarea.value.length);
		strPos = range.text.length;
	}
	else if (br == "ff") strPos = txtarea.selectionStart;
	
	var front = (txtarea.value).substring(0,strPos);  
	var back = (txtarea.value).substring(strPos,txtarea.value.length); 
	txtarea.value=front+text+back;
	strPos = strPos + text.length;
	if (br == "ie") { 
		txtarea.focus();
		var range = document.selection.createRange();
		range.moveStart ('character', -txtarea.value.length);
		range.moveStart ('character', strPos);
		range.moveEnd ('character', 0);
		range.select();
	}
	else if (br == "ff") {
		txtarea.selectionStart = strPos;
		txtarea.selectionEnd = strPos;
		txtarea.focus();
	}
	txtarea.scrollTop = scrollPos;
}
</SCRIPT>
newticket.php

Code : Tout sélectionner

<?php
/*
Author: Flox
FileName: newticket.php
Description: page to create ticket
Version: 1.5
Last update: 15/01/2013
*/

// initialize variables 
if(!isset($userreg)) $userreg = ''; 
if(!isset($category)) $category = ''; 
if(!isset($subcat)) $subcat = ''; 
if(!isset($title)) $title = ''; 
if(!isset($date_hope)) $date_hope = ''; 
if(!isset($description)) $description = ''; 
if(!isset($resolution)) $resolution = ''; 
if(!isset($priority)) $priority = '';
if(!isset($dateres)) $dateres = '';
if(!isset($id)) $id = '';
if(!isset($id_in)) $id_in = '';
if(!isset($globalrow['time'])) $globalrow['time'] = '';
if(!isset($_POST['mail'])) $_POST['mail'] = '';
if(!isset($_POST['upload'])) $_POST['upload'] = '';
if(!isset($_POST['description'])) $_POST['description'] = '';
if(!isset($_POST['resolution'])) $_POST['resolution'] = '';
if(!isset($_POST['save'])) $_POST['save'] = '';
if(!isset($_POST['quit'])) $_POST['quit'] = '';
if(!isset($_POST['subcat'])) $_POST['subcat'] = '';
if(!isset($_POST['user'])) $_POST['user'] = '';
if(!isset($_POST['time'])) $_POST['time'] = '';
if(!isset($_POST['time_hope'])) $_POST['time_hope'] = '';
if(!isset($_POST['priority'])) $_POST['priority'] = '';
if(!isset($_POST['criticality'])) $_POST['criticality'] = '';
if(!isset($_POST['state'])) $_POST['state'] = '';
if(!isset($_POST['title'])) $_POST['title'] = '';
if(!isset($_POST['date_hope'])) $_POST['date_hope'] = '';
if(!isset($_POST['category'])) $_POST['category'] = '';
if(!isset($_SESSION['user_id'])) $_SESSION['user_id'] = '';
if(!isset($_GET['category'])) $_GET['category'] = '';
if(!isset($_GET['subcat'])) $_GET['subcat'] = '';

//Default values
if(!isset($_POST['technician'])) $_POST['technician'] = $_SESSION['user_id'];


// find incident number  
$query = mysql_query("SELECT MAX(id) FROM tincidents");
$row=mysql_fetch_array($query);
$number =$row[0]+1;

// find current date & hour 
$hour = date("H:i");
$date = date("d/m/Y");
$today = "$date $hour: ";

//Database inputs if submit
if($_POST['save']||$_POST['mail']||$_POST['quit']||$_POST['upload']) 
{
	// special char in sql query
	$_POST['description']  = str_replace('\\','\\\\',$_POST['description']);
	$_POST['resolution']  = str_replace("\\","\\\\",$_POST['resolution']);
	$_POST['title']  = str_replace("\\","\\\\",$_POST['title']);
	$_POST['description'] = str_replace("'","\'",$_POST['description']); 
	$_POST['resolution']  = str_replace("'","\'",$_POST['resolution']); 
	$_POST['title']  = str_replace("'","\'",$_POST['title']);	
	
	//insert resolution date if state is res
	if ($_POST['state']=='3') $dateres=date("Y-m-d");
	
	//unread ticket case when creator is not technician
	if($_POST['technician']!= $_SESSION['user_id']) $techread=0; else $techread=1;
	
	$query= "INSERT INTO tincidents (user,technician,title,description,resolution,date_create,date_hope,date_res,priority,criticality,state,creator,time,time_hope,category,subcat,techread) VALUES ('$_POST[user]','$_POST[technician]','$_POST[title]','$_POST[description]','$_POST[resolution]','$_POST[date_create]','$_POST[date_hope]','$dateres','$_POST[priority]','$_POST[criticality]','$_POST[state]','$_SESSION[user_id]','$_POST[time]','$_POST[time_hope]','$_POST[category]','$_POST[subcat]','$techread')";
	$exec = mysql_query($query) or die('Erreur SQL !<br />'.mysql_error());
	
	//##############################Vincent
	if($_POST['date_hope'])
	{
		$dateModifiee = $_POST['date_hope'].' 07:00:00';
		$query_vincent= "INSERT INTO tevents (technician,incident,date_start,date_end,type,disable) VALUES ('$_POST[technician]','$number','$dateModifiee','','3','0')";
		$exec_vincent = mysql_query($query_vincent) or die('Erreur SQL !<br />'.mysql_error());
	}
	//############################fin de vincent
	
	// files upload  
	include "./core/upload.php";
	
	//auto send mail
	if(($rparameters['mail_auto']==1)&&($_POST['upload']=='')){include('./core/auto_mail.php');}
	
	// send mail
	if($_POST['mail'])
	{
		// redirect
		$www = "./index.php?page=preview_mail&id=$number";
		echo '<script language="Javascript">
		<!--
		document.location.replace("'.$www.'");
		// -->
		</script>';
	}
	else if ($_POST['quit'])
	{
		echo "<div id=\"valide\"><img src=\"./images/save.png\" border=\"0\" /> Ticket sauvegardé.</div>";
		 // redirect
		$www = "./index.php?page=dashboard&techid=$_SESSION[user_id]&state=1";
		echo "<SCRIPT LANGUAGE='JavaScript'>
			<!--
			function redirect()
			{
			window.location='$www'
			}
			setTimeout('redirect()',$rparameters[time_display_msg]);
			-->
			</SCRIPT>";
	}
	else if ($_POST['save']||$_POST['upload']!='')
	{
		echo "<div id=\"valide\"><img src=\"./images/save.png\" border=\"0\" /> Ticket sauvegardé.</div>";
		 // redirect
		$www = "./index.php?page=ticket&id=$number";
		echo "<SCRIPT LANGUAGE='JavaScript'>
			<!--
			function redirect()
			{
			window.location='$www'
			}
			setTimeout('redirect()',$rparameters[time_display_msg]);
			-->
			</SCRIPT>";
	}
}
?>
<div id="catalogue">
	<form name="thisform" enctype="multipart/form-data" method="post" action="" id="thisform">
		<h2 class="sec_head"><img src="./images/create-ticket-icon.png" />
			Ouverture du ticket n°<?php echo $number; ?>
			<img align="right" title="Créer ce ticket à partir d'un modèle d'incident" src="./images/template.png" style="border-style: none" alt="img" value='useradd' onClick="window.open('./newticket_template.php?id=<?php echo $number; ?>&uid=<?php echo $_SESSION['user_id']; ?>','useradd','width=400,height=130')" />
		</h2>
		<br />
		<label for="user">Demandeur:</label>
		<select class="textfield" id="user" name="user" onchange="submit();">
		   	<?php
			//case for url parameter $user
			if ($userreg)
			{
				$query= mysql_query("SELECT * FROM `tusers` where id like '$userreg' ");
				$row=mysql_fetch_array($query);
				echo "<option value=$row[id] selected>$row[lastname] $row[firstname] </option>";
			}
			$query = mysql_query("SELECT * FROM `tusers` WHERE disable='0' ORDER BY lastname ASC, firstname ASC");
			while ($row=mysql_fetch_array($query)) echo "<option value=\"$row[id]\">$row[lastname] $row[firstname]</option>"; 
			$query = mysql_query("SELECT * FROM tusers WHERE id LIKE '$_POST[user]'");
			$row = mysql_fetch_array($query);
			if ($userreg=="") {echo "<option selected value=\"$_POST[user]\">$row[lastname] $row[firstname] </option>";}
			?>
		</select>
		<img title="Ajouter un utilisateur" src="./images/plus.png" style="border-style: none" alt="img" value='useradd' onClick="window.open('./newticket_useradd.php','useradd','width=420,height=230')" />
		<img title="Modifier un utilisateur" src="./images/edit.png" style="border-style: none" alt="img" value='useredit' onClick="window.open('./newticket_useradd.php?id=<?php echo $_POST['user']; ?>','useredit','width=420,height=230')" />
		<input title="Actualiser la liste" border="0" src="./images/actualiser.png" type="image" value="submit" align="absmiddle" /> 
		<?php
		//Display phone number if exist
		$post_user=$_POST['user'];
		$query = mysql_query("SELECT * FROM `tusers` WHERE id LIKE '$post_user' or  id LIKE '$userreg'");
		$row=mysql_fetch_array($query);
		if ($row['phone']!="") echo "&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"./images/tel.png\" border=\"0\" /> <b>$row[phone]</b>&nbsp;";
		if ($row['mail']!="") echo '<img title="L\'adresse mail est bien renseignée.('.$row['mail'].')" src="./images/mail_min.png" style="border-style: none" alt="img" />';
		
		//other demands for this user 
		if($_POST['user'])
		{
			$qn = mysql_query("SELECT count(*) FROM `tincidents` WHERE user LIKE '$_POST[user]' and (state='1' OR state='2') and disable=0"); 
			while ($rn=mysql_fetch_array($qn))
			$rnn=$rn[0];
			if ($rnn!=0) echo "&nbsp;&nbsp;<i>(";
			$c=0;
			$q = mysql_query("SELECT * FROM `tincidents` WHERE user LIKE '$_POST[user]' and (state='1' OR state='2') and disable=0"); 
			while (($r=mysql_fetch_array($q)) && ($c<7)) {	
				$c=$c+1;
				echo "<a title=\"$r[title]\" href=\"./index.php?page=ticket&id=$r[id]\">$r[id]</a>";
				if ($c<$rnn) echo ",";
				if ($c==7) echo "...";
			}  
			if ($rnn!=0) echo ")</i>";
		}
		?>
		<br />
		<label for="technician">Technicien:</label>
		<select class="textfield" id="technician" name="technician" onchange="submit();">
		   	<?php
			if ($_POST['technician']!='')
			{
				$querytech = mysql_query("SELECT * FROM `tusers` WHERE disable='0' and id LIKE '$_POST[technician]' ");
				$row=mysql_fetch_array($querytech);
				echo "<option value=\"$row[id]\" selected >$row[lastname] $row[firstname]</option>"; 
				echo "<option value=\"\">Aucun</option>";
			
			} else {
				echo "<option value=\"\" Selected>Aucun</option>";
			}
			
			$query = mysql_query("SELECT * FROM `tusers` WHERE disable='0' and profile LIKE '0' and id!='$_SESSION[user_id]' ORDER BY lastname ASC, firstname ASC");
			while ($row=mysql_fetch_array($query)) {echo "<option value=\"$row[id]\">$row[lastname] $row[firstname]</option>";} 
			?>
		</select>
		<br />
		<label for="category">Catégorie:</label>
		<select class="textfield" id="category" name="category" onchange="submit();">
		   	<?php
			//case for url parameter $category for reload list
			if ($_GET['category']) 
			{
				$query= mysql_query("SELECT * FROM `tcategory` where id like '$_GET[category]' ");
				$row=mysql_fetch_array($query);
				echo '<option value='.$row['id'].'selected>'.$row['name'].'</option>';
			}
			else {echo '<option value='.$row['id'].'selected>'.$row['name'].'</option>';}
			
			$query= mysql_query("SELECT * FROM `tcategory` order by name ");
			while ($row=mysql_fetch_array($query)) 
			{
				echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
				if ($_POST['category']==$row['id']) echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
			}
			?>
		</select>
		<select class="textfield" id="subcat" name="subcat" onchange="submit();">
		   	<?php
			if ($_GET['subcat']) 
			{
				$query= mysql_query("SELECT * FROM tsubcat WHERE id='$_POST[subcat]' ");
				$row=mysql_fetch_array($query);
				echo '<option value='.$row['id'].'selected>'.$row['name'].'</option>';
			}
			$query= mysql_query("SELECT * FROM `tsubcat` WHERE cat LIKE '$_POST[category]' order by name ASC");
			while ($row=mysql_fetch_array($query)) 
			{
				echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
				if ($_POST['subcat']==$row['id']) echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
			} 
			?>
		</select>
		<img title="Ajouter une categorie" src="./images/plus.png" style="border-style: none" alt="img" value='useradd' onClick="window.open('./edit_categories.php?cat=<?php echo $_POST['category']; ?>','useradd','width=400,height=200')" />
		<img title="Modifier une categorie" src="./images/edit.png" style="border-style: none" alt="img" value='useredit' onClick="window.open('./edit_categories.php?cat=<?php echo $_POST['category']; ?>&subcat=<?php echo $_POST['subcat']; ?>','useredit','width=400,height=200')" />
		<input title="Actualiser la liste" border="0" src="./images/actualiser.png" type="image" value="submit" align="absmiddle" /> 
		<br />
		<label for="title">Titre:</label>
		<input class="textfield" name="title" id="title" type="text" size="50" value="<?php echo $_POST['title']; ?>"/>
		<br /><br />
		<label for="description">Description:</label>
		<br />
		<textarea class="textfield" id="description" name="description" cols="100" rows="2"  ><?php echo $_POST['description']; ?></textarea>
		<?php include "./attachement.php"; ?>
		<br /><br />
		<label for="resolution">Résolution:</label>
		<br />&nbsp;&nbsp;<img title="Insérer la date et l'heure du jour" src="./images/date.png" onclick="insertAtCaret('resolution','<?php echo $today; ?>');" />
		<textarea class="textfield" id="resolution" name="resolution" cols="100" rows="2"><?php echo $_POST['resolution']; ?></textarea>
		<br />
		<label for="date_create">Date de la demande:</label>
		<input style="display:inline;" class="textfield" type='text' name='date_create'  value="<?php echo date("Y-m-d");?>" />
		<img src="./images/calendar.png" value='Calendrier' onClick="window.open('components/mycalendar/mycalendar.php?form=thisform&elem=date_create','Calendrier','width=400,height=400')" />
		<br />
		<label for="date_hope">Date de résolution estimée:</label>
		<input style="display: inline;" class="textfield" type='text' name='date_hope'  value="<?php echo $_POST['date_hope']; ?>" />
		<img src="./images/calendar.png" value='Calendrier' onClick="window.open('components/mycalendar/mycalendar.php?form=thisform&elem=date_hope','Calendrier','width=400,height=400')" />
		<br />
		<label for="time">Temps passé:</label>
		<select class="textfield" id="time" name="time" > 
			<?php
			$query = mysql_query("SELECT * FROM `ttime` order by min ASC");
			while ($row=mysql_fetch_array($query)) {
				echo '<option value="'.$row['min'].'">'.$row['name'].'</option>';
				if ($_POST['time']==$row['min']) echo '<option selected value="'.$row['min'].'">'.$row['name'].'</option>'; 
			}
			?>
		</select>
		<br />
		<label for="time">Temps estimé:</label>
		<select class="textfield" id="time_hope" name="time_hope" > 
			<?php
			$query = mysql_query("SELECT * FROM `ttime` order by min ASC");
			while ($row=mysql_fetch_array($query)) {
				echo '<option value="'.$row['min'].'">'.$row['name'].'</option>';
				if ($_POST['time_hope']==$row['min']) echo '<option selected value="'.$row['min'].'">'.$row['name'].'</option>'; 
			}
			?>
		</select>
		<br />
		<label for="priority">Priorité:</label>
		<select class="textfield" id="priority" name="priority" >
		   	<?php
			$query = mysql_query("SELECT * FROM `tpriority` order by number ASC");
			while ($row=mysql_fetch_array($query)) {
				echo '<option value="'.$row['number'].'">'.$row['name'].'</option>'; 
				if ($_POST['priority']==$row['number']) echo '<option value="'.$row['number'].'">'.$row['name'].'</option>'; 
			}
			$q= mysql_query("SELECT * FROM `tpriority` where number=(select max(number) from tpriority)");
			$row=mysql_fetch_array($q);
			 echo '<option selected value="'.$row['number'].'">'.$row['name'].'</option>'; 
			?>		
		</select>
		<br />
		<label for="criticality">Criticité:</label>
		<select class="textfield" id="criticality" name="criticality" >
		   	<?php
			$query = mysql_query("SELECT * FROM `tcriticality` order by number ASC");
			while ($row=mysql_fetch_array($query)) {
				echo '<option value="'.$row['id'].'">'.$row['name'].'</option>'; 
				if ($_POST['priority']==$row['id']) echo '<option value="'.$row['id'].'">'.$row['name'].'</option>'; 
			}
			$q= mysql_query("SELECT * FROM `tcriticality` where number=(select max(number) from tcriticality)");
			$row=mysql_fetch_array($q);
			 echo '<option selected value="'.$row['id'].'">'.$row['name'].'</option>'; 
			?>		
		</select>
		<br />
		<label for="state">Etat:</label>
		<select class="textfield" id="state" name="state"  >
		   	<?php
			$query = mysql_query("SELECT * FROM `tstates` ORDER BY number");
			while ($row=mysql_fetch_array($query)) {
				echo '<option value="'.$row['id'].'">'.$row['name'].'</option>'; 
				if ($_POST['state']==$row['id']) {
					echo '<option selected value="'.$row['id'].'">'.$row['name'].'</option>';
				} elseif ($row['id']==1) {
					echo '<option selected value="'.$row['id'].'">'.$row['name'].'</option>';
				}
			}
			
			?>
		</select>
		<br />
<div  class="buttons">
<br /><br />
			<button name="save" value="Enregistrer" type="submit"  class="positive"  id="save">
				<img src="images/apply2.png" alt=""/>
				Enregistrer
			</button>
			
			<button name="quit" value="Enregistrer et Fermer" type="submit" class="positive" id="quit">	
				<img src="images/apply2.png" alt=""/>
				Enregistrer et Fermer
			</button>

			<button name="mail" value="Mail" type="submit" class="regular" name="mail" id="mail">
			 <img src="images/mail_icn.png" alt=""/>
				Envoyer un mail
			</button>

			<button name="cancel" value="cancel" type="submit" class="negative" name="cancel" id="cancel">
				<img src="images/cross.png" alt=""/>
				Annuler
			</button>
			<br /><br /><br /><br />
</div>

	</form>
</div>

<!-- Script allow autogrow textareas -->
<script type="text/javascript">
$('textarea').ata();
</script>

<script type="text/javascript">
        // jQuery en action
        jQuery.noConflict();
        jQuery('#jquery').addClass('jquery');

        // Prototype en action
        $('prototype').addClassName('prototype');
</script>

<SCRIPT type="text/javascript">
function insertAtCaret(areaId,text) {
	var txtarea = document.getElementById(areaId);
	var scrollPos = txtarea.scrollTop;
	var strPos = 0;
	var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? 
		"ff" : (document.selection ? "ie" : false ) );
	if (br == "ie") { 
		txtarea.focus();
		var range = document.selection.createRange();
		range.moveStart ('character', -txtarea.value.length);
		strPos = range.text.length;
	}
	else if (br == "ff") strPos = txtarea.selectionStart;
	
	var front = (txtarea.value).substring(0,strPos);  
	var back = (txtarea.value).substring(strPos,txtarea.value.length); 
	txtarea.value=front+text+back;
	strPos = strPos + text.length;
	if (br == "ie") { 
		txtarea.focus();
		var range = document.selection.createRange();
		range.moveStart ('character', -txtarea.value.length);
		range.moveStart ('character', strPos);
		range.moveEnd ('character', 0);
		range.select();
	}
	else if (br == "ff") {
		txtarea.selectionStart = strPos;
		txtarea.selectionEnd = strPos;
		txtarea.focus();
	}
	txtarea.scrollTop = scrollPos;
}
</SCRIPT>
Ptitvincou
Gsup LEVEL 1
Messages : 28
Enregistré le : lun. 18 févr. 2013 18:23

planning.php

Code : Tout sélectionner

<?php
/*
Author: Flox
File name: planning.php
Description: display planning
Version: 1.0
Creation date: 28/12/2012
Last update: 24/01/2013
*/

// initialize variables 
if(!isset($_GET['view'])) $_GET['view'] = '';
if(!isset($mon_color)) $mon_color = '';
if(!isset($tue_color)) $tue_color = '';
if(!isset($wed_color)) $wed_color = '';
if(!isset($thu_color)) $thu_color = '';
if(!isset($fri_color)) $fri_color = '';
if(!isset($sat_color)) $sat_color = '';
if(!isset($sun_color)) $sun_color = '';
if(!isset($cursor)) $cursor = '';
if(!isset($previous)) $previous = '';
if(!isset($next)) $next = '';

if(!isset($_GET['next'])) $_GET['next'] = '';
if(!isset($_GET['previous'])) $_GET['previous'] = '';
if(!isset($_GET['cursor'])) $_GET['cursor'] = '';
if(!isset($_GET['delete'])) $_GET['delete'] = '';

//default settings
if ($_GET['view']=='') $_GET['view']="week";
if ($next=='') $next=0;
if ($previous=='') $previous=0;


//calc dates
$cursor=$_GET['cursor']+$_GET['next']-+$_GET['previous'];
$current = date("Y-m-d H:i");
$week = date("W")-1 + $cursor;
$year = date("Y");

$monday=strtotime('First Monday January '.$year.' +'.($week-1).' Week');
$tuesday=strtotime('First Tuesday January '.$year.' +'.($week-1).' Week');
$wednesday=strtotime('First Wednesday January '.$year.' +'.($week).' Week');
$thursday=strtotime('First Thursday January '.$year.' +'.($week).' Week');
$friday=strtotime('First Friday January '.$year.' +'.($week).' Week');
$saturday=strtotime('First Saturday January '.$year.' +'.($week).' Week');
$sunday=strtotime('First Sunday January '.$year.' +'.($week).' Week');

$frday = array ('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
$frmonth = array ('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre');


//Delete events
if($_GET['delete']!='')
{
//disable ticket
$query = "DELETE FROM tevents WHERE incident=$_GET[delete]";
$exec = mysql_query($query) or die('Erreur SQL !<br /><br />'.mysql_error());
}



//Display Head
echo "<h2 class=\"sec_head\"> "; 

if ($_GET['view']=='day') echo 'Planning du '.$frday[date('w')].' '.date("d/m/Y"); 
if ($_GET['view']=='week') echo 'Planning du '.date("d/m/Y", strtotime('First Monday January '.$year.' +'.($week-1).' Week')).' au '.date("d/m/Y", strtotime('First Monday January '.$year.' +'.$week.' Week -1 day')); 

echo "</h2>";
echo'
<br />
<div id="downmenu">
		<ul>
			<li '; if ($_GET['view']=="week") echo "class=\"active\""; echo '><a href="./index.php?page=planning&view=week">Semaine</a></li>
		</ul>
</div>
		&nbsp;&nbsp;
		<a href="./index.php?page=planning&view=week&cursor='.$cursor.'&previous=1"><img alt="img" src="./images/left.png" title="Semaine précédente" /></a>
		<a href="./index.php?page=planning&view=week&cursor='.$cursor.'&next=1"><img alt="img" src="./images/right.png" title="Semaine suivante" /></a>

';
//######################################vincent
if($_POST['vincent_technician'])
{
	$vincent_technician=$_POST['vincent_technician'];
	//Select name of technician
	$vincent_querytech= mysql_query("SELECT * FROM tusers WHERE id = $vincent_technician"); 
	$vincent_resulttech=mysql_fetch_array($vincent_querytech);
	echo '<h2><br />Technicien sélectionné: '.$vincent_resulttech['firstname'].'</h2>';
}
else
{
	$vincent_technician='%';
}
?>
<center>
	<form method="post" action="" name="technician">
		<br />
		<select name="vincent_technician" onchange=submit()>
			<?php
			$query = mysql_query("SELECT * FROM tusers WHERE profile=0 and disable=0");				
			while ($row=mysql_fetch_array($query)) {
				if ($row['id'] == $_POST['tech']) $selected1="selected" ;
				if ($row['id'] == $_POST['tech']) $find="1" ;
				echo "<option value=\"$row[id]\" $selected1>$row[firstname] $row[lastname]</option>"; 
				$selected1="";
			} 
			echo "<option value=\"%\" >Tous les techniciens</option>";
			if ($find!="1") echo "<option value=\"%\" selected>Tous les techniciens</option>";												
			?>
		</select> 
	</form>
</center>
<?php

//################################################ fin vincent


////////////////////////////////////////////////////////////WEEK VIEW//////////////////////////////////////////////////////////////////
if ($_GET['view']=='week') 
{
	$period='Semaine '.date("W"); 
	$date=date("Y-m-d");
	//find day for display green on currrent day
	if(date("D")=='Mon' && date("j")==date("d", $monday)) $mon_color='bgcolor="#CEF6CE"';
	if(date("D")=='Tue' && date("j")==date("d", $tuesday)) $tue_color='bgcolor="#CEF6CE"';
	if(date("D")=='Wed' && date("j")==date("d", $wednesday)) $wed_color='bgcolor="#CEF6CE"';
	if(date("D")=='Thu' && date("j")==date("d", $thursday)) $thu_color='bgcolor="#CEF6CE"';
	if(date("D")=='Fri' && date("j")==date("d", $friday)) $fri_color='bgcolor="#CEF6CE"';

	$sat_color='bgcolor="#F2F5A9"';
	$sun_color='bgcolor="#F2F5A9"';
	
	echo"<table>";
	echo '<th colspan="8">Semaine '.date("W", strtotime('First Monday January '.$year.' +'.($week-1).' Week')).' </th>';
	//Display first Line
	echo '<tr>
			<td></td>
			<td '.$mon_color.' align="center">
				<b>
				'.$frday[date("w", $monday)].'
				'.date("d", $monday).'
				'.$frmonth[date("m", $monday)-1].' 
				</b>
			</td>
			<td '.$tue_color.' align="center">
				<b>
				'.$frday[date("w", $tuesday)].'
				'.date("d", $tuesday).'
				'.$frmonth[date("m", $tuesday)-1].' 
				</b>
			</td>
			<td '.$wed_color.' align="center">
				<b>
				'.$frday[date("w", $wednesday)].'
				'.date("d", $wednesday).'
				'.$frmonth[date("m", $wednesday)-1].' 
				</b>
			</td>
			<td '.$thu_color.' align="center">
				<b>
				'.$frday[date("w", $thursday)].'
				'.date("d", $thursday).'
				'.$frmonth[date("m", $thursday)-1].' 
				</b>
			</td>
			<td '.$fri_color.' align="center">
				<b>
				'.$frday[date("w", $friday)].'
				'.date("d", $friday).'
				'.$frmonth[date("m", $friday)-1].' 
				</b>
			</td>
			<td '.$sat_color.' align="center">
				<b>
				'.$frday[date("w", $saturday)].'
				'.date("d", $saturday).'
				'.$frmonth[date("m", $saturday)-1].' 
				</b>
			</td>
			<td '.$sun_color.' align="center">
				<b>
				'.$frday[date("w", $sunday)].'
				'.date("d", $sunday).'
				'.$frmonth[date("m", $sunday)-1].' 
				</b>
			</td align="center">
	</tr>';
	//Display each time line
	for ($i = 7; $i <= 19; $i++) 
	{ 
		echo '
		<tr>
			<td><b>'.$i.'h</b></td>
			<td '.$mon_color.'>';
				// find Monday date
				$date=date("Y-m-d", strtotime('First Monday January '.$year.' +'.($week-1).' Week'));
				if($vincent_technician!='%')// si un technicien est selectionné
				{
					$query= mysql_query("SELECT * FROM tevents WHERE technician=$vincent_technician AND disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				} else { // si pas de techniciens selectionné on affiche tous les events
					$query= mysql_query("SELECT * FROM tevents WHERE disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				}
				while($row= mysql_fetch_array($query))
				{
					if ($row['incident']!='')
					{
						if ($row['type']==1) $type='<img src="./images/clock2.png" border="0" />'; else $type='<img src="./images/planning.png" border="0" />';
						$query= mysql_query( "SELECT * FROM `tincidents` WHERE id=$row[incident] ");
						$row = mysql_fetch_array($query);
						echo '<a title="Voir le ticket '.$row['id'].'" href="./index.php?page=ticket&id='.$row['id'].'">'.$type.' '.$row['title'].'</a>';
						echo '<a title="Supprimer cet évenement" href="./index.php?page=planning&view='.$_GET['view'].'&cursor='.$_GET['cursor'].'&next='.$_GET['next'].'&delete='.$row['id'].'"><img src="./images/delete.png" /></a>';
					}
				}
			echo '
			</td>
			<td '.$tue_color.' >';
				// find Tuesday date
				$date=date("Y-m-d", strtotime('First Tuesday January '.$year.' +'.($week-1).' Week'));
				if($vincent_technician!='%')
				{
					$query= mysql_query("SELECT * FROM tevents WHERE technician=$vincent_technician AND disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				} else {
					$query= mysql_query("SELECT * FROM tevents WHERE disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				}
				//$row = mysql_fetch_array($query);
				while($row= mysql_fetch_array($query))
				{	
					if ($row['incident']!='')
					{
						if ($row['type']==1) $type='<img src="./images/clock2.png" border="0" />'; else $type='<img src="./images/planning.png" border="0" />';
						$query2= mysql_query( "SELECT * FROM `tincidents` WHERE id=$row[incident] ");
						$row2 = mysql_fetch_array($query2);
						echo '<a title="Voir le ticket '.$row2['id'].'" href="./index.php?page=ticket&id='.$row2['id'].'">'.$type.' '.$row2['title'].'</a>';
						echo '<a title="Supprimer cet évenement" href="./index.php?page=planning&view='.$_GET['view'].'&cursor='.$_GET['cursor'].'&next='.$_GET['next'].'&delete='.$row2['id'].'"><img src="./images/delete.png" /></a><br />';
					}
				}
			echo '
			</td>
			<td '.$wed_color.'>';
				// find Wednesday date
				$date=date("Y-m-d", strtotime('First Wednesday January '.$year.' +'.($week).' Week'));
				if($vincent_technician!='%')
				{
					$query= mysql_query("SELECT * FROM tevents WHERE technician=$vincent_technician AND disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				} else {
					$query= mysql_query("SELECT * FROM tevents WHERE disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				}
				//$row = mysql_fetch_array($query);
				while($row= mysql_fetch_array($query))
				{	
					if ($row['incident']!='')
					{
						if ($row['type']==1) $type='<img src="./images/clock2.png" border="0" />'; else $type='<img src="./images/planning.png" border="0" />';
						$query2= mysql_query( "SELECT * FROM `tincidents` WHERE id=$row[incident] ");
						$row2 = mysql_fetch_array($query2);
						echo '<a title="Voir le ticket '.$row2['id'].'" href="./index.php?page=ticket&id='.$row2['id'].'">'.$type.' '.$row2['title'].'</a>';
						echo '<a title="Supprimer cet évenement" href="./index.php?page=planning&view='.$_GET['view'].'&cursor='.$_GET['cursor'].'&next='.$_GET['next'].'&delete='.$row2['id'].'"><img src="./images/delete.png" /></a><br />';
					}
				}
			echo '
			</td>
			<td '.$thu_color.'>';
				// find Tursday date
				$date=date("Y-m-d", strtotime('First Thursday January '.$year.' +'.($week).' Week'));
				if($vincent_technician!='%')
				{
					$query= mysql_query("SELECT * FROM tevents WHERE technician=$vincent_technician AND disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				} else {
					$query= mysql_query("SELECT * FROM tevents WHERE disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				}
				//$row = mysql_fetch_array($query);
				while($row= mysql_fetch_array($query))
				{	
					if ($row['incident']!='')
					{
						if ($row['type']==1) $type='<img src="./images/clock2.png" border="0" />'; else $type='<img src="./images/planning.png" border="0" />';
						$query2= mysql_query( "SELECT * FROM `tincidents` WHERE id=$row[incident] ");
						$row2 = mysql_fetch_array($query2);
						echo '<a title="Voir le ticket '.$row2['id'].'" href="./index.php?page=ticket&id='.$row2['id'].'">'.$type.' '.$row2['title'].'</a>';
						echo '<a title="Supprimer cet évenement" href="./index.php?page=planning&view='.$_GET['view'].'&cursor='.$_GET['cursor'].'&next='.$_GET['next'].'&delete='.$row2['id'].'"><img src="./images/delete.png" /></a><br />';
					}
				}
			echo '
			</td>
			<td '.$fri_color.'>';
				// find Friday date
				$date=date("Y-m-d", strtotime('First Friday January '.$year.' +'.($week).' Week'));
				if($vincent_technician!='%')
				{
					$query= mysql_query("SELECT * FROM tevents WHERE technician=$vincent_technician AND disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				} else {
					$query= mysql_query("SELECT * FROM tevents WHERE disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				}
				//$row = mysql_fetch_array($query);
				while($row= mysql_fetch_array($query))
				{	
					if ($row['incident']!='')
					{
						if ($row['type']==1) $type='<img src="./images/clock2.png" border="0" />'; else $type='<img src="./images/planning.png" border="0" />';
						$query2= mysql_query( "SELECT * FROM `tincidents` WHERE id=$row[incident] ");
						$row2 = mysql_fetch_array($query2);
						echo '<a title="Voir le ticket '.$row2['id'].'" href="./index.php?page=ticket&id='.$row2['id'].'">'.$type.' '.$row2['title'].'</a>';
						echo '<a title="Supprimer cet évenement" href="./index.php?page=planning&view='.$_GET['view'].'&cursor='.$_GET['cursor'].'&next='.$_GET['next'].'&delete='.$row2['id'].'"><img src="./images/delete.png" /></a><br />';
					}
				}
			echo '
			</td>
			<td '.$sat_color.'>';
				// find Saturday date
				$date=date("Y-m-d", strtotime('First Saturday January '.$year.' +'.($week).' Week'));
				if($vincent_technician!='%')
				{
					$query= mysql_query("SELECT * FROM tevents WHERE technician=$vincent_technician AND disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				} else {
					$query= mysql_query("SELECT * FROM tevents WHERE disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				}
				//$row = mysql_fetch_array($query);
				while($row= mysql_fetch_array($query))
				{	
					if ($row['incident']!='')
					{
						if ($row['type']==1) $type='<img src="./images/clock2.png" border="0" />'; else $type='<img src="./images/planning.png" border="0" />';
						$query2= mysql_query( "SELECT * FROM `tincidents` WHERE id=$row[incident] ");
						$row2 = mysql_fetch_array($query2);
						echo '<a title="Voir le ticket '.$row2['id'].'" href="./index.php?page=ticket&id='.$row2['id'].'">'.$type.' '.$row2['title'].'</a>';
						echo '<a title="Supprimer cet évenement" href="./index.php?page=planning&view='.$_GET['view'].'&cursor='.$_GET['cursor'].'&next='.$_GET['next'].'&delete='.$row2['id'].'"><img src="./images/delete.png" /></a><br />';
					}
				}
			echo '
			</td>
			<td '.$sun_color.'>';
				// find Sunday date
				$date=date("Y-m-d", strtotime('First Sunday January '.$year.' +'.($week).' Week'));
				if($vincent_technician!='%')
				{
					$query= mysql_query("SELECT * FROM tevents WHERE technician=$vincent_technician AND disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				} else {
					$query= mysql_query("SELECT * FROM tevents WHERE disable!=1 AND (date_start='$date $i:00' OR date_end='$date $i:00' OR (date_start<'$date $i:00' AND date_end>'$date $i:00'))");
				}
				//$row = mysql_fetch_array($query);
				while($row= mysql_fetch_array($query))
				{	
					if ($row['incident']!='')
					{
						if ($row['type']==1) $type='<img src="./images/clock2.png" border="0" />'; else $type='<img src="./images/planning.png" border="0" />';
						$query2= mysql_query( "SELECT * FROM `tincidents` WHERE id=$row[incident]");
						$row2 = mysql_fetch_array($query2);
						echo '<a title="Voir le ticket '.$row2['id'].'" href="./index.php?page=ticket&id='.$row2['id'].'">'.$type.' '.$row2['title'].'</a>';
						echo '<a title="Supprimer cet évenement" href="./index.php?page=planning&view='.$_GET['view'].'&cursor='.$_GET['cursor'].'&next='.$_GET['next'].'&delete='.$row2['id'].'"><img src="./images/delete.png" /></a><br />';
					}
				}
			echo '
			</td>
		</tr>';
	}
		
	echo "</table>";
} 
?>
jerocobo
Gsup LEVEL 0
Messages : 6
Enregistré le : lun. 20 sept. 2021 17:52

Merci pour la contribution. Je le trouve très utile. :mrgreen:
Répondre