function update_thread_status($id) { /* $logfile = 'update_thread_status.log'; if (is_writeable($logfile)) if (!$handle = fopen($logfile, 'a')) { echo "Cannot open file ($filename)"; exit; } // end if else echo "The filename is not writeable"; fwrite($handle, "\n\nBegin Log\n".time()."\n"); */ // select the information from the ticket that was passed to us $sql = "\n\t\tSELECT \n\t\t\ttickets_id as id, \n\t\t\ttickets_status as status, \n\t\t\ttickets_child as child,\t\n\t\t\ttickets_responses\n\t\tFROM \n\t\t\ttickets_tickets \n\t\tWHERE \n\t\t\ttickets_id={$id}\n\t\t"; $result = mysql_query($sql); if (!$result) { $error = "Could not successfully run query ({$sql}) from DB: " . mysql_error() . "\n"; dieLog($error); die; } // end if if (mysql_num_rows($result) == 0) { $error = "ERROR! No such entry found!\n<pre>{$sql}</pre>"; dieLog($error); die; } // end if // we should only pull one entry if (mysql_num_rows($result) > 1) { $error = "GASP! Query found duplicate entries for that ID! We should never get here!\n"; dieLog($error); die; } // end if // create an array out of the row we just pulled $parent = mysql_fetch_assoc($result); // if this is not the parent of the thread, then call the function again using the parent if ($parent["child"] != 0) { update_thread_status($parent["child"]); return; } // end if $sql = "SELECT tickets_id as id, tickets_timestamp as timestamp, tickets_admin as admin \n\t\t\tFROM tickets_tickets WHERE tickets_child = {$id} ORDER BY tickets_timestamp DESC"; $result = mysql_query($sql) or dieLog(mysql_error()); $parent["tickets_responses"] = mysql_num_rows($result); $child = mysql_fetch_assoc($result); // if the last post was made by an admin, change its status to answered if ($child["admin"] == "Admin") { $parent["status"] = 'Answered'; } else { $parent["status"] = 'Open'; } $sql = "UPDATE tickets_tickets SET tickets_status='" . $parent['status'] . "', tickets_responses=" . $parent['tickets_responses'] . ", tickets_latest=" . $child['timestamp'] . " WHERE tickets_id = " . $parent['id']; $result = mysql_query($sql) or dieLog($sql . "\n" . mysql_error()); }
} // AND A NEW RESPONSE AND ATTACHMENT TO THE SYSTEM if ($_POST['submit'] == 'Submit Ticket') { if ($_POST['message'] == '') { $msg = 'Please complete all the fields'; } else { $urgency = explode('|', $_POST['posturgency']); $category = explode('|', $_POST['postdept']); $tickets_reference = $_REQUEST['tickets_reference']; if (!$tickets_reference) { dieLog("No Reference ID"); } $query = "\tINSERT INTO tickets_tickets\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\ttickets_username = '******'sta_name'] . "',\n\t\t\t\t\t\t\ttickets_subject = '" . $_POST['postsubject'] . "',\n\t\t\t\t\t\t\ttickets_timestamp = '" . mktime() . "',\n\t\t\t\t\t\t\ttickets_urgency = '" . $urgency['0'] . "',\n\t\t\t\t\t\t\ttickets_category = '" . $category['0'] . "',\n\t\t\t\t\t\t\ttickets_admin = 'Admin',\n\t\t\t\t\t\t\ttickets_child = '" . $_GET['ticketid'] . "',\n\t\t\t\t\t\t\ttickets_question = '" . $_POST['message'] . "'"; if ($result = sql_query_write($query)) { $tickets_id = mysql_insert_id(); update_thread_status(intval($_GET['ticketid'])); // CHECK THE FILE ATTACHMENT AND DISPLAY ANY ERRORS if ($allowattachments == 'TRUE') { FileUploadsVerification("{$_FILES}(userfile)", mysql_insert_id()); } // MAIL THE PERSON WHO STARTED THE TICKET $socketfrom = "Ticket-" . $tickets_reference . "@" . $socketdomain; $message = "Ticket ID:\t {$tickets_reference} Response\n"; $message .= "Name:\t\t " . $_POST['name'] . "\n"; $message .= "Email:\t " . $_POST['email'] . "\n"; $message .= "Subject:\t " . $_POST['postsubject'] . "\n"; $message .= "Urgency:\t " . $urgency['1'] . "\n"; $message .= "Department:\t " . $category['1'] . "\n"; $message .= "Post Date:\t " . date($dformatemail) . "\n"; $message .= "----------------------------------------------------------------------\n"; $message .= "Message:\n";