Location: PHPKode > projects > Tech Tickets > technician/tt_addnew.php
<?php include("../include/secure.php"); ?>
<?php
$p_id = $_SESSION['pid'];
$firstname = $_SESSION['firstname'];
?>
<?php require_once('../include/connections.php'); ?>
<?php
mysql_select_db($database, $conn);

//if($HTTP_GET_VARS['cl_id']=="") {$criteria="1";} else {$criteria=$HTTP_GET_VARS['cl_id'];}
//$query_person_list = "SELECT id, firstname, lastname FROM mgw_contacts WHERE companyid = $criteria ORDER BY lastname ASC";
$query_person_list = "SELECT UserID as id, firstname, lastname FROM tt_users ORDER BY LastName ASC";
$person_list = mysql_query($query_person_list, $conn) or die(mysql_error());
$row_person_list = mysql_fetch_assoc($person_list);
$totalRows_person_list = mysql_num_rows($person_list);

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

if(isset($HTTP_POST_VARS['comment'])){$comment_and_signature = $HTTP_POST_VARS['comment'] . "<br><br>By: " . $firstname;}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO tt_tickets (p_id, status, subject, comment, urgency, bywho) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($HTTP_POST_VARS['p_id'], "int"),
                       GetSQLValueString($HTTP_POST_VARS['status'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['subject'], "text"),
                       GetSQLValueString($comment_and_signature, "text"),
                       GetSQLValueString($HTTP_POST_VARS['urgency'], "text"),
                       GetSQLValueString($HTTP_POST_VARS['bywho'], "text"));

  $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());

	if ($HTTP_POST_VARS['urgency']=="E"  or $HTTP_POST_VARS['urgency'] == "A") {
		$Esubject = "Tech Ticket from ".$firstname.".  Subject: ".$HTTP_POST_VARS['subject'];
		$Ebody = $HTTP_POST_VARS['comment'];
		mail($EmailTo,$Esubject,$Ebody,'From:'.$EmailFrom);
	}
	//get client email address
	mysql_select_db($database, $conn);
	$query_client_email = "SELECT Email FROM tt_users WHERE UserID = " . $HTTP_POST_VARS['p_id'];
	$client_email = mysql_query($query_client_email, $conn) or die(mysql_error());
	$row_client_email = mysql_fetch_assoc($client_email);
	$totalRows_client_email = mysql_num_rows($client_email);
	//mail client confirmation
	//echo "SEND EMAIL TO: ". $row_client_email['Email']."<br>FROM: $EmailFrom";
	$Esubject = "Tech Ticket Created";
	$Ebody = "
We have created a tech ticket at $CompanyName.

We will process your ticket according to the urgency selected.
Please do not hesitate to contact us by phone if your issue is an emergency.  $CompanyPhone. 

Thanks,
$CompanyName
--------
Your ticket text follows:
" . $HTTP_POST_VARS['comment'];
	
	mail($row_client_email['Email'],$Esubject,$Ebody,'From: '.$EmailFrom);
	
  $insertGoTo = "tt_view_open.php";
  if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<SCRIPT LANGUAGE="JavaScript">
function ChangeDD(clid)
{
	window.location = "tt_addnew.php?cl_id=" + clid;
}
</SCRIPT>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>Tickets</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<link href="../include/style.css" type="text/css" rel="stylesheet" />
</head>

<body topmargin="0">
<?php include("header.php"); ?>
<table width="100%" bgcolor="#efefef">
<tr><td align="right"><?php echo "Welcome " . $_SESSION["firstname"]; ?></td></tr>
</table>

      <h1 align="center"><font face="Verdana, Arial, Helvetica, sans-serif">Add New Ticket</font></h1>
      
      <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
        <table align="center">
          <tr valign="baseline"> 
            <td valign="top" bgcolor="#999999"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Person</font></strong></td>
            <td bgcolor="#CCCCCC"><select name="p_id">
                <?php
do {  
?>
                <option value="<?php echo $row_person_list['id'] ?>" <?php if ($row_person_list['id'] = $p_id){ echo "selected";}  ?>><?php echo $row_person_list['lastname'] . ", " . $row_person_list['firstname']?></option>
                <?php
} while ($row_person_list = mysql_fetch_assoc($person_list));
  $rows = mysql_num_rows($person_list);
  if($rows > 0) {
      mysql_data_seek($person_list, 0);
	  $row_person_list = mysql_fetch_assoc($person_list);
  }
?>
              </select>
            </td>
          </tr>
          <tr valign="baseline"> 
            <td valign="top" bgcolor="#999999"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Subject</font></strong></td>
            <td bgcolor="#CCCCCC"> <input type="text" name="subject" value="" size="50"></td>
          </tr>
          <tr valign="baseline"> 
            <td valign="top" bgcolor="#999999"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Comment</font></strong></td>
            <td bgcolor="#CCCCCC"> <textarea name="comment" rows="10" cols="50"></textarea></td>
          </tr>
          <tr valign="baseline"> 
            <td valign="top" bgcolor="#999999"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Urgency</font></strong></td>
            <td bgcolor="#CCCCCC"> <p> 
                <select name="urgency">
                  <option value="N">Next Visit</option>
                  <option value="A">ASAP</option>
                  <option value="E">Emergency</option>
                </select>
              </p>
              <p> <font size="1" face="Verdana, Arial, Helvetica, sans-serif">Emergency=we 
                will be emailed immediately<br>
                ASAP=we will be emailed<br>
                Next Visit=the technician will address this issue on the next 
                visit</font></p></td>
          </tr>
          <tr valign="baseline" bgcolor="#CCCCCC"> 
            <td colspan="2" align="right" nowrap> <div align="center"> 
                <input type="submit" value="Submit Ticket">
              </div></td>
          </tr>
        </table>
        <input type="hidden" name="t_p_id" value="<?php echo $p_id ?>">
        <input type="hidden" name="status" value="P">
        <input type="hidden" name="bywho" value="C">
        <input type="hidden" name="MM_insert" value="form1">
      </form>
      <p>&nbsp;</p>
  <p>&nbsp;</p>
  
<?php include("footer.php"); ?>
</body>
</html>
<?php

mysql_free_result($person_list);
?>


Return current item: Tech Tickets