$ticid = $_REQUEST['tic_id'];
$thread_type = "R";
$poster = $current_user->user_login;
$source = "Web";
$admin_response = @Format::stripslashes($_REQUEST['message']);
///from post to thread-table to variable to email
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date("Y-m-d g:i:s");
///EST (todo's - add option to WP osT-Settings)
$ost_wpdb->insert($thread_table, array('pid' => $pid, 'ticket_id' => $ticid, 'staff_id' => $staffid, 'thread_type' => $thread_type, 'poster' => $poster, 'source' => $source, 'title' => "", 'body' => key4ce_wpetss_forum_text($admin_response), 'ip_address' => $ipaddress, 'created' => $date), array('%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s'));
$thread_id = $ost_wpdb->insert_id;
// File Table Entry Code Start Here By Pratik Maniar on 02/08/2014
if (!empty($_FILES['file']['name'][0])) {
    $fileids = array();
    for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
        $fullfinalpath = key4ce_getKeyValue('uploadpath');
        $key4ce_generateHashKey = key4ce_generateHashKey(33);
        $key4ce_generateHashSignature = key4ce_generateHashSignature(33);
        $dir_name = substr($key4ce_generateHashKey, 0, 1);
        $structure = $fullfinalpath . "/" . $dir_name;
        if (!is_dir($structure)) {
            mkdir($structure, 0355);
        }
        $alowaray = explode(".", str_replace(' ', '', $fileextesnions));
        $strplc = str_replace(".", "", str_replace(' ', '', $fileextesnions));
        $allowedExts = explode(",", $strplc);
        $allowextscnt = count($allowedExts);
        $temp = explode(".", $_FILES['file']['name'][$i]);
        $extension = end($temp);
        //return uploaded file extension
        $newfilename = $key4ce_generateHashKey;
                ?>
"/>
                                            <input type="hidden" name="type" value="<?php 
                echo $filedetails->type;
                ?>
"/>
                                            <input type="hidden" name="name" value="<?php 
                echo $filedetails->name;
                ?>
"/>
                                            <input type="hidden" name="h" value="<?php 
                echo session_id();
                ?>
"/>
<input type="hidden" name="filepath" value="<?php 
                echo key4ce_getKeyValue('uploadpath');
                ?>
"/>
                                            <span class="key4ce_Icon key4ce_attachment"></span><input type="submit" name="download" value="<?php 
                echo $filedetails->name;
                ?>
">
                                        </form>
                                        <?php 
            }
        }
        ?>
                            </td>
                        </tr>
                    </tbody>
                </table>
<?php

/* Template Name: new_ticket.php */
if ($keyost_version == 193) {
    $attachement_status = key4ce_getKeyValue('allow_attachments');
    $max_user_file_uploads = key4ce_getKeyValue('max_user_file_uploads');
    $max_file_size = key4ce_getKeyValue('max_file_size');
    $fileextesnions = key4ce_getKeyValue('allowed_filetypes');
} else {
    $fileconfig = key4ce_FileConfigValue();
    $filedata = json_decode($fileconfig);
    $attachement_status = $filedata->attachments;
    $max_user_file_uploads = $filedata->max;
    $max_file_size = $filedata->size;
    $fileextesnions = $filedata->extensions;
}
$alowaray = explode(".", str_replace(' ', '', $fileextesnions));
$strplc = str_replace(".", "", str_replace(' ', '', $fileextesnions));
$allowedExts = explode(",", $strplc);
function add_quotes($str)
{
    return sprintf("'%s'", $str);
}
$extimp = implode(',', array_map('add_quotes', $allowedExts));
$finalary = "'" . $extimp . "'";
?>
<script language="javascript" src="<?php 
echo plugin_dir_url(__FILE__) . '../js/jquery_1_7_2.js';
?>
"></script>
<script type="text/javascript">
<?php 
if ($keyost_usercloseticket == 0) {
    ?>
<style>
#key4ce_ticket_menu1{width: 8.5% !important;}#key4ce_ticket_list1{width: 8.5% !important;}#key4ce_ticket_menu2{width: 47% !important;}#key4ce_ticket_list2{width: 47% !important;}#key4ce_ticket_menu4{width:11% !important;}
#key4ce_ticket_list4{width:11% !important;}
#key4ce_ticket_menu5{width:11% !important;}
#key4ce_ticket_list5{width:11% !important;}
#key4ce_ticket_menu6{width:250px !important;}
#key4ce_ticket_list6{width:250px !important;}
</style>
<?php 
}
$time_format = key4ce_getKeyValue('time_format');
$date_format = key4ce_getKeyValue('date_format');
$datetime_format = key4ce_getKeyValue('datetime_format');
if (isset($_POST['close'])) {
    $close_ticket_list = $_POST['tickets'];
    $i = 0;
    foreach ($close_ticket_list as $close_ticket) {
        if ($keyost_version == 194 || $keyost_version == 195 || $keyost_version == 1951) {
            $ost_wpdb->update($ticket_table, array('status_id' => '3'), array('ticket_id' => $close_ticket), array('%s'));
        } else {
            $ost_wpdb->update($ticket_table, array('status' => 'closed'), array('ticket_id' => $close_ticket), array('%s'));
        }
        $i++;
    }
    echo "<div style=' color: red;font-size: 15px;font-weight: bold;margin-top: 20px;text-align: center;'>" . _e("{$i} record(s) has been closed successfully", 'key4ce-osticket-bridge') . "</div>";
    echo "<script>window.location.href=location.href;</script>";
}
if (@$list_opt) {
    $adminmessage .= "Subject: " . $sub . "<br />";
    $adminmessage .= "<br />----------------------<br />";
    $adminmessage .= "Message: " . $user_message . "";
    $adminmessage .= "<br />----------------------<br /><br />";
    $adminmessage .= "To respond to the ticket, please login to the support ticket system.";
    $adminmessage .= "<br /><br />";
    $adminmessage .= "" . site_url() . "";
    $adminmessage .= "<br />";
    $adminmessage .= "Your friendly Customer Support System ";
    $headers = 'From: ' . $title . ' <' . $adem . ">\r\n";
    add_filter('wp_mail_content_type', create_function('', 'return "text/html"; '));
    wp_mail($os_admin_email_admin, $subject, key4ce_wpetss_forum_text('<div style="display: none;">-- do not reply below this line -- <br/><br/></div>' . $adminmessage), $headers);
}
//Email Notification to Department Of Staff Added by Pratik Maniar on 28-04-2014 Start Here
///Email osticket Department - a new ticket has been created
if (key4ce_getKeyValue('ticket_alert_dept_members') == 1 && key4ce_getKeyValue('ticket_alert_active') == 1) {
    $staff_details = $ost_wpdb->get_results("SELECT email,firstname,lastname FROM {$ost_staff} WHERE `dept_id` ={$dep_id}");
    $department_staff = count($staff_details);
    if ($department_staff > 0) {
        foreach ($staff_details as $staff) {
            $staff_firstname = $staff->firstname;
            $staff_lastname = $staff->lastname;
            $staff_email = $staff->email;
            $subject = $sub;
            $deptmessage = "Hello {$staff_firstname} {$staff_lastname},<br />A new ticket has been created.<br /><br />";
            $deptmessage .= "Ticket ID #" . $ticketid . "";
            $deptmessage .= "<br />----------------------<br />";
            $deptmessage .= "Name: " . $username . "<br />";
            $deptmessage .= "Email: " . $usermail . "<br />";
            $deptmessage .= "Priority: " . $priordesc . "<br />";
            $deptmessage .= "Department: " . $dept_name . "<br />";
require_once WP_PLUGIN_DIR . '/key4ce-osticket-bridge/admin/db-settings.php';
require_once WP_PLUGIN_DIR . '/key4ce-osticket-bridge/includes/functions.php';
$dept_opt = $ost_wpdb->get_results("SELECT dept_name,dept_id FROM {$dept_table} where ispublic=1");
wp_enqueue_script('ost-bridge-validate', plugins_url('../js/validate.js', __FILE__));
// Start File system changes
$fileconfig = key4ce_FileConfigValue();
$filedata = json_decode($fileconfig);
if ($keyost_version == 193) {
    $attachement_status = key4ce_getKeyValue('allow_attachments');
    $max_user_file_uploads = key4ce_getKeyValue('max_user_file_uploads');
    $agent_max_file_size = key4ce_getKeyValue('max_staff_file_uploads');
    $fileextesnions = key4ce_getKeyValue('allowed_filetypes');
} else {
    $attachement_status = $filedata->attachments;
    $max_user_file_uploads = $filedata->max;
    $agent_max_file_size = key4ce_getKeyValue('max_file_size');
    $fileextesnions = $filedata->extensions;
}
// End file system changes
$alowaray = explode(".", str_replace(' ', '', $fileextesnions));
$strplc = str_replace(".", "", str_replace(' ', '', $fileextesnions));
$allowedExts = explode(",", $strplc);
function add_quotes($str)
{
    return sprintf("'%s'", $str);
}
$extimp = implode(',', array_map('add_quotes', $allowedExts));
$finalary = "'" . $extimp . "'";
$args = array('blog_id' => $GLOBALS['blog_id'], 'role' => '', 'meta_key' => '', 'meta_value' => '', 'meta_compare' => '', 'meta_query' => array(), 'include' => array(), 'exclude' => array(), 'orderby' => 'login', 'order' => 'ASC', 'offset' => '', 'search' => '', 'number' => '', 'count_total' => false, 'fields' => 'all', 'who' => '');
global $wpdb;
$WPusersData = $wpdb->get_results("SELECT user_nicename,user_email FROM " . $wpdb->prefix . "users", ARRAY_A);
      <?php 
if ($attachement_status == 1 || $attachement_status == true) {
    if (key4ce_getPluginValue('Attachments on the filesystem') == 1) {
        ?>
            <tr><td>
                    <div id="addinput">
                        <p>
                            <span style="color:#000;"><?php 
        echo __("Attachment 1:", 'key4ce-osticket-bridge');
        ?>
</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="file" id="p_new" name="file[]" onchange="return checkFile(this);"/>&nbsp;&nbsp;&nbsp;<a href="#" id="addNew"><?php 
        echo __("Add", 'key4ce-osticket-bridge');
        ?>
</a>&nbsp;&nbsp;&nbsp;<span style="color: red;font-size: 11px;"><?php 
        echo __("Max file upload size :", 'key4ce-osticket-bridge');
        echo key4ce_getKeyValue('max_file_size') * 0.0009765625 * 0.0009765625;
        ?>
MB</span>
                        </p>
                    </div>
                </td></tr>
    <?php 
    } else {
        ?>
	 <tr><td><?php 
        echo __("Attachments on the Filesystem plugin can be downloaded here:", 'key4ce-osticket-bridge');
        ?>
 <a href="http://osticket.com/download/go?dl=plugin%2Fstorage-fs.phar" title="Attachement Filesystem Plugin" target="_blank"><?php 
        echo __("Attachement Filesystem Plugin", 'key4ce-osticket-bridge');
        ?>
</a></td></tr>