Location: PHPKode > projects > Tech Tickets > technician/LaunchDataExport.php
<?php header("Content-Type: application/vnd.ms-excel; name='excel'"); ?>
<?php header("Content-disposition:  attachment; filename=" .date("Y-m-d").".xls"); ?>
<?php require_once('../include/connections.php'); ?>
<?php

if($_POST){
	$farchived = $_POST["e-archived"];
	$fid = $_POST["e-id"];
	$fuser = $_POST["e-user"];
	$fstatus = $_POST["e-status"];
	$furgency = $_POST["e-urgency"];
	$fsubject = $_POST["e-subject"];
	$ffdate = $_POST["e-fdate"];
	$ftdate = $_POST["e-tdate"];
	$ftech = $_POST["e-tech"];
	$fvendor = $_POST["e-vendor"];
	$fuserid = $_POST["e-userid"];
	
}else{
	$farchived = 0;
	$fid = "";
	$fuser = "";
	$fstatus = "";
	$furgency = "";
	$fsubject = "";
	$ffdate = "";
	$ftdate = "";
	$ftech = "";
	$fvendor = "";
	$fuserid = "";
}

$sql = "SELECT t.tt_id, t.parent_tt_id, t.p_id, date_format(datetimestamp,'%m-%d-%Y %r') as datetimestamp, t.status, t.subject, t.comment, t.urgency, u.FirstName, u.LastName, CONCAT(ut.FirstName, ' ', ut.LastName) as assignedtech ";
$sql .= "FROM tt_tickets t LEFT OUTER JOIN tt_users u ON u.UserID = t.p_id LEFT OUTER JOIN tt_users ut ON ut.UserID = t.tech_id ";
$sql .= "WHERE parent_tt_id = 0 ";
if($farchived != 1){$sql .= " AND archived = $farchived ";}
if($fid != "")	   {$sql .= " AND tt_id LIKE '$fid' ";}
if($fuser != "")   {$sql .= " AND CONCAT(u.FirstName, ' ', u.LastName) LIKE '%$fuser%' ";}
if($fstatus != "") {$sql .= " AND t.status LIKE '%$fstatus%' ";}
if($furgency != ""){$sql .= " AND t.urgency LIKE '$furgency' ";}
if($fsubject != ""){$sql .= " AND t.subject LIKE '%$fsubject%' ";}
if($ffdate != "")  {$sql .= " AND t.datetimestamp BETWEEN '".date("Y-m-d",strtotime($ffdate))."' AND '".date("Y-m-d",strtotime($ftdate))."' ";}
if($ftech != "")   {$sql .= " AND ut.UserID = '$ftech' ";}
if($fvendor != "") {$sql .= " AND t.cl_id = '$fvendor' ";}
if($fuserid != "") {$sql .= " AND u.UserID = '$fuserid' ";}
$sql .= "ORDER BY t.tt_id DESC";

//$sql = urldecode($_POST["sql"]);
//$sql = "SELECT tt_id, parent_tt_id, cl_id, p_id, date_format(datetimestamp,'%m-%d-%Y %r') as datetimestamp, status, subject, urgency FROM tt_tickets WHERE parent_tt_id = 0 AND p_id = 1  AND date_format(datetimestamp,'%m/%d/%Y') BETWEEN '04/01/2006' AND '05/06/2006' ORDER BY tt_id DESC";

mysql_select_db($database, $conn);
$rs = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($rs);
$rowcount = mysql_num_rows($rs);
$colcount = mysql_num_fields($rs);
?>	

<table border="1">
	<tr> 
		<td bgcolor="#666666"> <div align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">TT ID</font></div></td>
		<td bgcolor="#666666"> <div align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">User</font></div></td>
        <td bgcolor="#666666"> <div align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Status</font></div></td>
        <td bgcolor="#666666"> <div align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Subject</font></div></td>
		<td bgcolor="#666666"> <div align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Comment</font></div></td>
        <td bgcolor="#666666"> <div align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Urgency</font></div></td>
		<td bgcolor="#666666"> <div align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Submitted</font></div></td>
		<td bgcolor="#666666"> <div align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Assigned Tech</font></div></td>
    </tr>
	<?php do { ?>
	<tr bgcolor="#FFFFFF">
		<?php $ttid = $row['tt_id'];?>
        <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $ttid; ?></font></td>  
		<td nowrap><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['FirstName'] . " " . $row['LastName']; ?></font></td>
		<td>
		  	<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
			<?php 
			if($row['status'] == "O"){ 
				echo "Open";
			} elseif($row['status'] == "C"){ 
				echo "Closed";
			} elseif($row['status'] == "E"){
				echo "Escalated";
			} 
			?>
			</font>
		</td>
        <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['subject']; ?></font></td>
		<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo str_replace("<br>",chr(10),$row['comment']); ?></font></td>
        <td>
		  	<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
			<?php 
		  	if ($row['urgency'] == "N"){
				echo "Next Visit";
			}elseif ($row['urgency'] == "A"){
				echo "ASAP";
			}elseif ($row['urgency'] == "E"){
				echo "Emergency";
			}else{
				echo "";
			}
		    ?>
		</td>
		<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['datetimestamp']; ?></font></td>
		<td nowrap><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row['assignedtech'] ; ?></font></td>
	</tr>
	<?php } while ($row = mysql_fetch_assoc($rs)); ?>
</table>	
Return current item: Tech Tickets