newticket.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:20k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: newticket.php,v $
- // | $Date: 2004/02/11 01:28:16 $
- // | $Revision: 1.86 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - New ticket creation page.
- // +-------------------------------------------------------------+
- error_reporting(E_ALL ^ E_NOTICE);
- include "./../global.php";
- tech_nav('tickets');
- // default do
- $_REQUEST['do'] = trim($_REQUEST['do']);
- if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
- $_REQUEST['do'] = "start";
- }
- max_limits('tickets');
- ############################### PROCESS NEW TICKET ###############################
- /********************** NEW USER ************************/
- if ($_REQUEST['do'] == "new") {
- if ($_REQUEST['new_user'] == 'new') {
-
- if (!$user['p_create_users']) {
- mistake("You don't have permission to create new users.", 1);
- }
-
- $_REQUEST['username'] = trim($_REQUEST['username']);
- $_REQUEST['email'] = trim($_REQUEST['email']);
- // password
- if (!$_REQUEST['password']) {
- $_REQUEST['password'] = make_pass(8);
- $_REQUEST['password1'] = $_REQUEST['password'];
- } elseif ($_REQUEST['password'] != $_REQUEST['password1']) {
- unset($_REQUEST['password'], $_REQUEST['password1']);
- $error .= "The passwords you have entered do not match.n";
- }
- // empty email
- if (!validate_email($_REQUEST['email'])) {
- $error .= "You have not entered a valid email address.n";
- }
- // empty username
- if (!$_REQUEST['username']) {
- $newusername = 1;
- $_REQUEST['username'] = make_username($_REQUEST['email']);
-
- // username in use
- } else {
- $db->query("
- SELECT id
- FROM user
- WHERE username = '" . mysql_escape_string($_REQUEST[username]) . "'
- ");
- if ($db->num_rows() > 0) {
- $message .= "The username you entered is already in use. Please enter another one.n";
- }
- }
- // email in use
- $db->query("
- SELECT username, id
- FROM user
- WHERE email = '" . mysql_escape_string($_REQUEST[email]) . "'
- ");
- if ($db->num_rows() > 0) {
- $result = $db->row_array();
- $error .= "The email address you entered is already in use by $result[username] (userid $result[id]).n";
- }
- $db->query("
- SELECT userid
- FROM user_email
- WHERE email = '" . mysql_escape_string($_REQUEST['email']) . "'
- ");
- if ($db->num_rows() > 0) {
- $error .= "There is already a user with the email address $_REQUEST[user].n";
- }
- $password_cookie = md5($_REQUEST[password] . uniqid(rand(),1));
- $password_cookie = substr($password_cookie, 0, 8);
- $password_url = md5($password . uniqid(rand(),1) . $session[sessionid]);
- $password_url = substr($password_url, 0, 8);
- $query = "INSERT INTO user SET
- email = '$_REQUEST[email]',
- password = '$_REQUEST[password]',
- password_cookie = '" . mysql_escape_string($password_cookie) . "',
- password_url = '" . mysql_escape_string($password_url) . "',
- username = '$_REQUEST[username]',
- date_registered = '" . mktime() . "'";
- // get the fields that we are expecting to be created
- $db->query("SELECT * FROM user_def WHERE tech_editable");
- while ($user_fields = $db->row_array()) {
- $data = field_def_val($user_fields, $_REQUEST[userfields][$user_fields[name]], $_REQUEST[userfields]["extra" . $user_fields[name]]);
- $query .= ", $user_fields[name] = '" . mysql_escape_string($_REQUEST["userfields[$user_fields[name]"]) . "'";
- }
- // run the query
- if (!$error) {
- $db->query($query);
- $userid = $db->last_id();
- $user_details = $db->query_return("SELECT * FROM user WHERE id = '$userid'");
- $user_created = 1;
- }
- /********************** CURRENT USER ************************/
-
- } else {
-
- // from select menu
- if ($_REQUEST['userchoice'] > 0) {
- $user_details = $db->query_return("
- SELECT *
- FROM user
- WHERE id = '$_REQUEST[userchoice]'
- AND !disabled
- ");
-
- if ($db->num_rows() < 1) {
- $error .= "The user you selected was not found or has been disabled.n";
- }
- // entered username / email address
- } elseif ($_REQUEST['oldusername']) {
- $user_details = $db->query_return("
- SELECT *
- FROM user
- WHERE username = '" . mysql_escape_string($_REQUEST['oldusername']) . "'
- OR email = '" . mysql_escape_string($_REQUEST['oldusername']) . "'
- AND !disabled
- AND email != ''
- AND username != ''
- ");
- if (!$db->num_rows()) {
- $error .= "There was no user found with a username or email address of $_REQUEST[oldusername].n";
- }
- }
- }
- /******************** TICKET CHECKS ******************/
-
- if (!$error) { // errors from user checks
-
- if (!$_REQUEST['usermessage'] AND !$_REQUEST['reply']) { // check message
- $error .= "You have not entered either a user message or a tech message for this ticket.n";
- }
- if (!$_REQUEST['subject']) { // check subject
- $error .= "You have not entered a subject for this ticket.n";
- }
- if (!$_REQUEST['ticket_category']) { // check category
- $error .= "You have not entered a category for this ticket.n";
- }
- }
-
- /******************** CREATE TICKET ******************/
- // errors from user / ticket checks
- if (!$error) {
- if ($_REQUEST['set_awaiting_user']) {
- $await = 0;
- } else {
- $await = 1;
- }
- $authcode = substr(md5(rand(0,100000) . mktime()), 0, 8);
- $subject = xss_check($_REQUEST['subject'], 'user');
- if (!$_REQUEST['close_ticket']) {
- $open = 1;
- }
- $query = "INSERT INTO ticket SET
- category = '" . mysql_escape_string($_REQUEST[ticket_category]) . "',
- priority = '" . mysql_escape_string($_REQUEST[priority]) . "',
- subject = '" . mysql_escape_string($subject) . "',
- userid = '$user_details[id]',
- is_open = '$open',
- awaiting_tech = '$await',
- date_awaiting_toggled = '" . mktime() . "',
- date_opened = '" . mktime() . "',
- date_lastreply_tech = '" . mktime() . "',
- date_lastreply = '" . mktime() . "',
- ref = '" . make_ticket_ref() . "',
- authcode = '$authcode', ";
- if(!$open) {
- $query .= "date_closed = unix_timestamp(), ";
- }
- if ($_REQUEST['tech']) {
- $query .= "tech = '$_REQUEST[tech]' ";
- } elseif ($cat_data['auto_assign_tech']) {
- $query .= "tech = '$cat_data[auto_assign_tech]' ";
- } else {
- $query .= "tech = 0 ";
- }
- $db->query("select * from ticket_def");
- while ($ticket_fields = $db->row_array()) {
- $data = field_def_val($ticket_fields, $_REQUEST[ticket_fields][$ticket_fields[name]], $_REQUEST[ticket_fields]["extra" . $ticket_fields[name]]);
- $query .= ", $ticket_fields[name] = '" . mysql_escape_string($data) . "' ";
- }
- // add new thread to database and get back id
- $db->query($query);
- $id = $db->last_id();
- // Add an entry to the ticket log
- ticketlog($id, 'created');
- if (!$open) {
- ticketlog($id, 'close');
- }
- /////////////////////// ADD MESSAGES TO DATABASE ///////////////////////
-
- if ($_REQUEST['usermessage']) {
-
- $usermessage = xss_check($_REQUEST['usermessage'], 'user');
- $db->query("INSERT INTO ticket_message SET
- message = '" . mysql_escape_string($usermessage) . "',
- ticketid = '$id',
- userid = '$user_details[id]',
- date = '" . mktime() . "'
- ");
- }
- if ($_REQUEST['reply']) {
- $reply = xss_check($_REQUEST['reply'], 'user');
- $db->query("INSERT INTO ticket_message SET
- message = '" . mysql_escape_string($reply) . "',
- ticketid = '$id',
- techid = '$user[id]',
- date = '" . mktime() . "'
- ");
- }
- $ticket = $db->query_return("SELECT * FROM ticket WHERE id = '$id'");
-
- $added = array();
- if (is_array($_FILES)) {
- foreach ($_FILES AS $key => $var) {
-
- // if email later
- if ($_FILES[$key][name] != '') {
- // if email later
- if (validate_attachment($error, $key)) { // add attachment
- $attach = add_attachment($key);
- $db->query("INSERT INTO ticket_attachments SET
- blobid = '$attach[blobid]',
- filename = '" . mysql_escape_string($attach[name]) . "',
- filesize = '" . mysql_escape_string($attach[size]) . "',
- extension = '" . mysql_escape_string($attach[extension]) . "',
- timestamp = '" . mktime() . "',
- toemail = '" . iff($_REQUEST['email'], 1, 0) . "',
- techid = '$user[id]',
- ticketid = '$id'
- ");
- $newid = $db->last_id();
- $attach['id'] = $newid;
- $i++;
- $added[] = $attach;
- ticketlog($id, 'add_attach', $newid, $newid, $attach[name]);
-
- } else {
- $errors .= $error;
- }
- }
- }
- }
- $ticket['usermessage'] = $_REQUEST['usermessage'];
- $ticket['techmessage'] = $_REQUEST['reply'];
- $ticket['message'] = "User's Message:n$_REQUEST[usermessage]nnTech Response:n$_REQUEST[reply]n";
- $db->query("
- REPLACE INTO tech_start_tickets
- SET techid = '$user[id]',
- userid = '$user_details[id]'
- ");
- if ($_REQUEST['email_user'] AND !$await) {
- notify_user('new_tech', $ticket, $user_details, array($_REQUEST[usermessage], $_REQUEST[reply]), $added);
- }
- if ($_REQUEST['tech'] != $user['id']) {
- notify_technicians('assigned', $ticket, $user_details, array($_REQUEST[usermessage], $_REQUEST[reply]), $added);
- } elseif (!$_REQUEST['tech']) {
- notify_technicians('new', $ticket, $user_details, array($_REQUEST[usermessage], $_REQUEST[reply]), $added);
- }
- if ($_REQUEST['create_faq']) {
- $title = urlencode($_REQUEST['subject']);
- $question = urlencode($_REQUEST['usermessage']);
- $answer = urlencode($_REQUEST['reply']);
- jump("../faq/view.php?do=add&title=$title&question=$question&answer=$answer", 'Ticket Created. Redirecting you to the FAQ article addition page.');
- } else {
- jump("ticketview.php?id=$id", 'Ticket Created. Redirecting you to ticket');
- }
- }
- /******************* PROCESS ERRORS ***********************/
- if ($error) {
-
- if ($newpass) { // dont show new passwords
- unset($_REQUEST['password'], $_REQUEST['password1']);
- }
- if ($newusername AND !$usercreated) {
- unset($_REQUEST['username']);
- }
- // have we created the user?
- if ($user_created) {
-
- if ($error) {
- $error = 'The user has been created, but a problem was encountered:nn' . $error;
- }
- $_REQUEST['new_user'] = 'old';
- $_REQUEST['user'] = $_REQUEST['email'];
- }
-
- if ($error) {
- alert($error);
- }
- $repeat = 1;
- $_REQUEST['do'] = 'start';
- }
- }
- ############################### CREATE NEW TICKET ###############################
- if ($_REQUEST['do'] == "start") {
- echo "<form method="post" enctype="multipart/form-data" name="dpreply" id="dpreply" action="newticket.php">" . form_hidden('do', 'new');
- // category information
- $categories[0] = '';
- $db->query("SELECT * FROM ticket_cat ORDER by cat_order");
- while ($cat = $db->row_array()) {
- $categories[$cat[id]] = $cat[name];
- }
- // get priority data
- $priority[0] = '';
- $db->query("SELECT * from ticket_pri ORDER by pri_order");
- while ($pri = $db->row_array()) {
- $priority[$pri[id]] = $pri[name];
- }
- $tech[0] = 'Unassigned';
- $db->query("SELECT * FROM tech ORDER by username");
- while ($result = $db->row_array()) {
- $tech[$result[id]] = $result[username];
- }
- // get current users
- $db->query("SELECT username, id
- FROM user, tech_start_tickets
- WHERE !disabled
- AND tech_start_tickets.userid = user.id
- AND tech_start_tickets.techid = '$user[id]'
- ");
- if ($db->num_rows() > 0) {
- $userselect[0] = '';
- while ($result = $db->row_array()) {
- $userselect[$result['id']] = $result[username];
- }
- }
- if (!$_REQUEST['new_user']) {
- $_REQUEST['new_user'] = 'old';
- }
- if ($_REQUEST['new_user'] == 'old') {
- $old_start = 1;
- $new_start = 0;
- } else {
- $new_start = 1;
- $old_start = 0;
- }
- // are we coming from the comment form? If so prefill the user message
- if ($_REQUEST['commentid']) {
-
- $comment = $db->query_return("SELECT * FROM faq_comments WHERE id = '$_REQUEST[commentid]'");
- $_REQUEST['usermessage'] = $comment['comments'];
- // if we have userid, get username
- if ($comment['userid']) {
- $user = $db->query_return("SELECT username FROM user WHERE id = '$comment[userid]'");
- $_REQUEST['oldusername'] = $user['username'];
-
- // only have email address. Check if there is a username or not
- } elseif ($comment['useremail']) {
- if ($userid = userid_from_email($comment['useremail'])) {
- // we found the user, so get username
- $user = $db->query_return("SELECT username FROM user WHERE id = '$userid'");
- $_REQUEST['oldusername'] = $user['username'];
-
- } else {
- // new user
- $new_user_email = $comment['useremail'];
- $new_start = 1;
- }
- }
- }
- $help = table_thelp('<B>Email / Username for current user</B>', 'Tickets - Starting New', 'Specifying User');
- $bit = form_radio_single('new_user', 'old', $old_start, 'onClick="oc2('0','user_creation');"') . " " . form_input('oldusername', $_REQUEST['oldusername']) . iff(is_array($userselect), " " . form_select('userchoice', $userselect, '', $_REQUEST['userchoice'])) . "$html <a href="#" onClick="openWindow('./../users/quickfind.php?name=dpreply.oldusername', 450, 600, 'userfind')">" . html_image('tech/bul084.gif') . "</a>";
- $table[] = array($help, $bit);
- $help = table_thelp('<B>Email address of new user</B>', 'Tickets - Starting New', 'Specifying User');
- $bit = form_radio_single('new_user', 'new', $new_start, ' onClick="oc2('1','user_creation');"') . " " . form_input('email', $new_user_email);
- $table[] = array($help, $bit);
- $help = table_thelp('<B>Subject</B>', 'Tickets - Starting New', 'Subject');
- $bit = form_input('subject', $_REQUEST['subject']);
- $table[] = array($help, $bit);
- $help = table_thelp('<B>Category</B>', 'Tickets - Starting New', 'Category');
- $bit = form_select('ticket_category', $categories, '', $_REQUEST[ticket_category]);
- $table[] = array($help, $bit);
- $help = table_thelp('<B>Priority</B>', 'Tickets - Starting New', 'Priority');
- $bit = form_select('priority', $priority, '', $_REQUEST[priority]);
- $table[] = array($help, $bit);
- if ($repeat) {
- $starting_techs = $_REQUEST['tech'];
- } else {
- $starting_techs = $user['id'];
- }
- $help = table_thelp('<B>Assigned Technician</B>', 'Tickets - Starting New', 'Assigned Technician');
- $bit = form_select('tech', $tech, '', $starting_techs);
- $table[] = array($help, $bit);
- $help = table_thelp('<B>Attachments</B>', 'Tickets - Starting New', 'Attachment');
- $table[] = array($help, "<input type="file" name="attachment1"><br /><input type="file" name="attachment2"><br /><input type="file" name="attachment3"><br /><input type="file" name="attachment4"><br /><input type="file" name="attachment5">");
- $table[] = table_midheader('Message');
- // sort out old message / signature
- if ($_REQUEST[reply]) {
- $show_message = $_REQUEST[reply];
- } else {
- $show_message = "nn--n$user[signature]";
- }
- $help = thelp('Quick Replies', 'Inserting into Tickets');
- $uhelp = table_thelp('User Message', 'Tickets - Starting New', 'User Message');
- $thelp = table_thelp('Your Message', 'Tickets - Viewing and Responding', 'Your Message');
- $table[] = array(
- '<center>
- <select name="drop" style="width:150" onchange="top.empty.showdata(dpreply.drop.value)"></select><br /><br />
- <select size="10" name="list3" style="width:150"></select><BR />
- <input type="hidden" name="category" value="1">
- <input type="button" onClick="top.empty.godeep(dpreply.list3.value,dpreply.category.value)" value="Insert into Reply"><br /><br /> ' . $help . '
- </center>',
- "<table cellpadding="0" cellspacing="0"><tr>
- <td>$uhelp<b>" .
- form_textarea('usermessage' ,'85', '5', $_REQUEST['usermessage']) . spellcheck_button('dpreply', 'usermessage') .
- "<br />$thelp
- <TEXTAREA NAME="reply" ROWS="12" COLS="85"
- ONSELECT="top.empty.storeCaret(this);"
- ONCLICK="top.empty.storeCaret(this);"
- ONKEYUP="top.empty.storeCaret(this);">$show_message</TEXTAREA>" . spellcheck_button('dpreply', 'reply') . "
- </td> </tr><tr><td colspan="2">
- </td></tr></table>"
- );
- $help = table_thelp('<B>Options</B>', 'Tickets - Starting New', 'Options');
- $table[] = array($help, "
- <table>
- <tr>
- <td>" . form_checkbox_single('create_faq', 1, $_REQUEST['create_faq']) . " Create FAQ article from this ticket</td>
- <td>" . form_checkbox_single('close_ticket', 1, $_REQUEST['close_ticket']) . " Close this ticket</td>
- </tr>
- <tr><td>" . form_checkbox_single('email_user', '1', if_default($_REQUEST['email_user'], $repeat, 1)) . " Email this ticket to the user</td>
- <td>" . form_checkbox_single('set_awaiting_user', '1', if_default($_REQUEST['set_awaiting_user'], $repeat, 1)) . " Set ticket as Awaiting User Response</td>
- </tr>
- </table>");
- // get rest of ticket data
- $db->query("
- SELECT *
- FROM ticket_def
- WHERE tech_editable
- ");
- if ($db->num_rows()) {
- $table[] = table_midheader('Custom Ticket Fields');
- while ($result = $db->row_array()) {
- $result[display_name] = unserialize($result[display_name]);
- $result[display_name] = $result[display_name][$settings[default_language]];
- $result[description] = unserialize($result[description]);
- $result[description] = $result[description][$settings[default_language]];
-
- $table[] = array("<b>" . $result[display_name] . "</b><br />" . $result[description],
- field_def(
- $result,
- 'redo',
- $_REQUEST[ticket_fields][$result[name]],
- $_REQUEST[ticket_fields]["extra" . $result[name]],
- '',
- 'ticket_fields')
- );
- }
- }
- table_header('Create new ticket', '', '', '', 'dpreply', 1);
- table_content('', $table);
- table_footer('', '', "<input type="submit" name="Send" value="Create Ticket">");
- unset($columns, $table);
- ?>
- <SCRIPT langauge="JavaScript">
- top.empty.buildselect();
- top.empty.showdata('0');
- </SCRIPT>
- <?
- ############################### FIELD TO ENTER NEW USER DATA ###############################
- $db->query("SELECT * FROM user_def WHERE tech_editable ORDER BY displayorder");
- $table[] = array(error_marker('username') . '<b>Username</b>', form_input('username', $_REQUEST['username']));
- $table[] = array(error_marker('password') . '<b>Password</b><br />If left empty a random password will be generated', form_password('password', $_REQUEST['password']));
- $table[] = array(error_marker('password1') . '<b>Repeat Password</b>', form_password('password1', $_REQUEST['password1']));
-
- if ($db->num_rows()) {
- $table[] = table_midheader('Custom User Fields');
- }
- while ($result = $db->row_array()) {
- $result[display_name] = unserialize($result[display_name]);
- $result[display_name] = $result[display_name][$settings[default_language]];
- $result[description] = unserialize($result[description]);
- $result[description] = $result[display_name][$settings[description]];
- $bit = field_def(
- $result,
- 'redo',
- $_REQUEST[user_fields][$result[name]],
- $_REQUEST[user_fields]["extra" . $result[name]],
- '',
- 'user_fields'
- );
- $table[] = array("<b>$result[display_name]</b>", $bit);
- }
- echo "<DIV id='user_creation'>";
- table_header('Custom User Fields (Optional)');
- table_content($columns, $table);
- table_footer('', '', "<input type="submit" name="Send" value="Create Ticket">");
- echo "
- <SCRIPT language='javascript'>
- function oc2(element, id) {
- e=document.getElementById(id).style;
- if (element == 0) {
- e.display='none';
- } else {
- e.display='';
- }
- }
- ";
- // display or not display user fields
- if (!$new_start) {
- echo "oc('user_creation')";
- }
- echo "
- </SCRIPT>
- ";
- echo "</form>";
- }
- tech_footer();
- ?>