Beispiel #1
0
 public function acp_form($serverId = null)
 {
     global $dbh, $postvar, $getvar, $instance;
     if ($serverId) {
         $servers_data = $dbh->select("servers", array("id", "=", $serverId));
     }
     $yesno_opts[] = array("Yes", 1);
     $yesno_opts[] = array("No", 0);
     $text = "API Port:";
     $help = "The port for THT to use to talk to the server on.<br><br>Standard ports:<br>ZPanel: 80 = HTTP / 443 = HTTPS<br>WHM: 2086 = HTTP / 2087 = HTTPS<br>Kloxo: 7778 = HTTP / 7777 = HTTPS<br>DA: 2222 = HTTP / 2222 = HTTPS";
     $input_type = "input";
     $values = $servers_data['apiport'];
     $name = "apiport";
     $response .= main::tr($text, $help, $input_type, $values, $name);
     $text = "Connect via HTTPS?";
     $help = "Should THT connect to the server via HTTPS?";
     $input_type = "select";
     $values = main::dropdown("https", $yesno_opts, $servers_data['https']);
     $response .= main::tr($text, $help, $input_type, $values);
     $text = "Username:"******"Username to connect to the server";
     $input_type = "input";
     $values = $servers_data['user'];
     $name = "user";
     $response .= main::tr($text, $help, $input_type, $values, $name);
     $text = "Access Hash:";
     $help = "Access hash to connect to the server";
     $input_type = "textarea";
     $values = $servers_data['accesshash'];
     $name = "hash";
     $response .= main::tr($text, $help, $input_type, $values, $name);
     return $response;
 }
Beispiel #2
0
 public function acp_form($serverId = null)
 {
     global $dbh, $postvar, $getvar, $instance;
     if ($serverId) {
         $servers_data = $dbh->select("servers", array("id", "=", $serverId));
     }
     $yesno_opts[] = array("Yes", 1);
     $yesno_opts[] = array("No", 0);
     $text = "API Port:";
     $help = "The port for THT to use to talk to the server on.<br><br>Standard ports:<br>2222 = HTTP / 2222 = HTTPS";
     $input_type = "input";
     $values = $servers_data['apiport'];
     $name = "apiport";
     $response .= main::tr($text, $help, $input_type, $values, $name);
     $text = "Connect via HTTPS?";
     $help = "Should THT connect to the server via HTTPS?";
     $input_type = "select";
     $values = main::dropdown("https", $yesno_opts, $servers_data['https']);
     $response .= main::tr($text, $help, $input_type, $values);
     $text = "Username:"******"Username to connect to the server";
     $input_type = "input";
     $values = $servers_data['user'];
     $name = "user";
     $response .= main::tr($text, $help, $input_type, $values, $name);
     $text = "Password:"******"Password to connect to the server";
     $input_type = "password";
     $values = $servers_data['pass'];
     $name = "pass";
     $response .= main::tr($text, $help, $input_type, $values, $name);
     return $response;
 }
Beispiel #3
0
 public function acp_form($serverId = null)
 {
     global $dbh, $postvar, $getvar, $instance;
     if ($serverId) {
         $servers_data = $dbh->select("servers", array("id", "=", $serverId));
     }
     $yesno_opts[] = array("Yes", 1);
     $yesno_opts[] = array("No", 0);
     $text = "API Port:";
     $help = "The port for THT to use to talk to the server on.<br><br>Standard ports:<br>7778 = HTTP / 7777 = HTTPS";
     $input_type = "input";
     $values = $servers_data['apiport'];
     $name = "apiport";
     $response .= main::tr($text, $help, $input_type, $values, $name);
     $text = "Connect via HTTPS?";
     $help = "Should THT connect to the server via HTTPS?";
     $input_type = "select";
     $values = main::dropdown("https", $yesno_opts, $servers_data['https']);
     $response .= main::tr($text, $help, $input_type, $values);
     $text = "Username:"******"Username to connect to the server";
     $input_type = "input";
     $values = $servers_data['user'];
     $name = "user";
     $response .= main::tr($text, $help, $input_type, $values, $name);
     $text = "Password:"******"Password to connect to the server";
     $input_type = "password";
     $values = $servers_data['pass'];
     $name = "pass";
     $response .= main::tr($text, $help, $input_type, $values, $name);
     $text = "DNS Template:";
     $help = "The DNS template for creating new domains with - Check out the documentation for your control panel for more information.";
     $input_type = "input";
     $values = $servers_data['dnstemplate'] == "" ? $this->dnstemplate : $servers_data['dnstemplate'];
     $name = "nstmp";
     $response .= main::tr($text, $help, $input_type, $values, $name);
     $text = "Backend Welcome Email Too?";
     $help = "Should the server's welcome email be sent out in addition to THT's welcome email?";
     $input_type = "select";
     $values = main::dropdown("welcome", $yesno_opts, $servers_data['welcome']);
     $response .= main::tr($text, $help, $input_type, $values);
     return $response;
 }
Beispiel #4
0
 public function import()
 {
     global $dbh, $postvar, $getvar, $instance;
     if (!$_POST) {
         $servers_query = $dbh->select("servers", array("type", "=", "zpanel"), 0, 0, 1);
         while ($servers_data = $dbh->fetch_array($servers_query)) {
             $values[] = array($servers_data['name'], $servers_data['id']);
         }
         $zpanel_array['DROPDOWN'] = main::dropdown("server", $values);
         echo style::replaceVar("tpl/admin/import/zpanel.tpl", $zpanel_array);
     } elseif ($_POST) {
         $postvar['server'] = $postvar['server'];
         //Hack to make sure we post the 'server' field as it doesn't post if it's empty.
         check::empty_fields();
         if (main::errors()) {
             echo "<ERRORS>";
         } else {
             $n = 0;
             include INC . "/servers/zpanel.php";
             $zpanel = new zpanel($postvar['server']);
             $zpanel_accounts = $zpanel->listaccs($postvar['server']);
             foreach ($zpanel_accounts as $zpanel_data) {
                 $packages_data = $dbh->select("packages", array("backend", "=", $zpanel_data['package']));
                 $users_data = $dbh->select("users", array("user", "=", $zpanel_data['user']));
                 if (!$packages_data['id']) {
                     $packages_insert = array("name" => $zpanel_data['package'], "backend" => $zpanel_data['package'], "description" => "Imported from ZPanel: " . $zpanel_data['package'], "type" => "free", "server" => $postvar['server'], "admin" => "1");
                     $dbh->insert("packages", $packages_insert);
                 }
                 $new_packages_data = $dbh->select("packages", array("backend", "=", $zpanel_data['package']));
                 if (!$users_data['id']) {
                     $salt = crypto::salt();
                     $newpass = crypto::passhash(rand(), $salt);
                     $users_insert = array("user" => $zpanel_data['user'], "zpanel_uid" => $zpanel_data['user'], "email" => $zpanel_data['user'], "password" => $zpanel_data['user'], "salt" => $zpanel_data['user'], "signup" => $zpanel_data['user'], "status" => $zpanel_data['user'], "domain" => $zpanel_data['user'], "pid" => $zpanel_data['user']);
                     $dbh->insert("users", $users_insert);
                     $dbh->insert("users_bak", $users_insert);
                     $n++;
                 }
             }
             echo $n . " Accounts have been imported";
         }
     }
 }
Beispiel #5
0
 private function ViewClient($client)
 {
     global $dbh, $postvar, $getvar, $instance;
     $client_details_array['DATE'] = main::convertdate("n/d/Y", $client['signup']);
     $client_details_array['EMAIL'] = $client['email'];
     $client_details_array['UPGRADEINFO'] = "";
     $existing_upgrade = $dbh->select("upgrade", array("uid", "=", $client['id']));
     $all_packs_query = $dbh->select("packages", array("is_disabled", "=", "0"), array("type", "ASC"), 0, 1);
     while ($all_packs_data = $dbh->fetch_array($all_packs_query)) {
         $additional = type::additional($all_packs_data['id']);
         $monthly = $additional['monthly'];
         $signup = $additional['signup'];
         unset($info);
         if ($all_packs_data['type'] == "p2h") {
             $info = "[Signup Posts: " . $signup . ", Monthly Posts: " . $monthly . "] ";
         } elseif ($all_packs_data['type'] == "paid") {
             $info = "[" . main::money($monthly) . "] ";
         }
         $packages[] = array("[" . $all_packs_data['type'] . "] " . $info . $all_packs_data['name'], $all_packs_data['id']);
         if ($existing_upgrade && $existing_upgrade['newpack'] == $all_packs_data['id']) {
             if ($all_packs_data['admin']) {
                 $admin = " after you approve them";
             }
             if ($existing_upgrade['flags'] && $existing_upgrade['flags'] < 5) {
                 $next_cycle = " next billing cycle";
             }
             $client_details_array['UPGRADEINFO'] = "NOTE: This user is slated for an upgrade to \"" . $all_packs_data['name'] . "\"" . $next_cycle . $admin . ".<br><br>";
         }
     }
     $client_details_array['PACKAGE'] = main::dropdown("newpackage", $packages, $client['pid']);
     $client_details_array['USER'] = $client['user'];
     $client_details_array['DOMAIN'] = $client['domain'];
     $client_details_array['CLIENTIP'] = $client['ip'];
     $client_details_array['FIRSTNAME'] = $client['firstname'];
     $client_details_array['LASTNAME'] = $client['lastname'];
     $client_details_array['ADDRESS'] = $client['address'];
     $client_details_array['CITY'] = $client['city'];
     $client_details_array['STATE'] = $client['state'];
     $client_details_array['ZIP'] = $client['zip'];
     $client_details_array['COUNTRY'] = strtolower($client['country']);
     $client_details_array['FULLCOUNTRY'] = main::country_code_to_country($client['country']);
     $client_details_array['PHONE'] = $client['phone'];
     unset($where);
     $where[] = array("uid", "=", $client['id'], "AND");
     $where[] = array("is_paid", "=", "0");
     $invoices_query = $dbh->select("invoices", $where, 0, 0, 1);
     $client_details_array['INVOICES'] = $dbh->num_rows($invoices_query);
     switch ($client['status']) {
         default:
             $client_details_array['STATUS'] = "Other";
             break;
         case "1":
             $client_details_array['STATUS'] = "Active";
             break;
         case "2":
             $client_details_array['STATUS'] = "Suspended";
             break;
         case "3":
             $client_details_array['STATUS'] = "Awaiting Validation";
             break;
         case "4":
             $client_details_array['STATUS'] = "Awaiting Payment";
             break;
         case "5":
             $client_details_array['STATUS'] = "Awaiting Email Confirmation";
             break;
         case "9":
             $client_details_array['STATUS'] = "Cancelled";
             break;
     }
     $class = type::packagetype($client['pid']);
     $packtype = $instance->packtypes[$class];
     if (method_exists($packtype, "acpBox")) {
         $box = $packtype->acpBox();
         $clientview_array['BOX'] = main::sub($box[0], $box[1]);
     } else {
         $clientview_array['BOX'] = "";
     }
     $clientview_array['CONTENT'] = style::replaceVar("tpl/admin/clients/client-details.tpl", $client_details_array);
     return $clientview_array;
 }
Beispiel #6
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     if (is_numeric($getvar['dellogid'])) {
         $dbh->delete("logs", array("id", "=", $getvar['dellogid']), "1");
         main::errors("Log entry deleted.");
     }
     if (is_numeric($getvar['removeall'])) {
         if ($getvar['confirm'] != '1') {
             main::errors("Are you sure you wish to remove ALL log entries?   <a href = '?page=logs&removeall=" . $getvar['removeall'] . "&confirm=1'>Yes</a>    |    <a href = '?page=logs'>No</a>");
         } else {
             $dbh->delete("logs", 0, 0, 1);
             main::thtlog("Logs Cleared", "All Logs were removed.", $_SESSION['user'], "", "staff");
             main::redirect("?page=logs");
         }
     }
     if (is_numeric($getvar['logid'])) {
         $loginfo = $dbh->select("logs", array("id", "=", $getvar['logid']));
         $admin_log_view_array['MESSAGE'] = $loginfo['message'];
         echo style::replaceVar("tpl/admin/logs/admin-log-view.tpl", $admin_log_view_array);
     } else {
         $per_page = $getvar['limit'];
         $start = $getvar['start'];
         if (!$postvar['show']) {
             $show = $getvar['show'];
         } else {
             $show = $postvar['show'];
             $start = 0;
         }
         if (!$show) {
             $show = "all";
         }
         if (!$per_page) {
             $per_page = 10;
         }
         if (!$start) {
             $start = 0;
         }
         if ($show != "all") {
             $logs_query = $dbh->select("logs", array("logtype", "=", $show), array("logtime", "DESC"), $start . ", " . $per_page, 1);
         } else {
             $logs_query = $dbh->select("logs", 0, array("logtime", "DESC"), $start . ", " . $per_page, 1);
         }
         $all_logs_query = $dbh->select("logs");
         $num_logs = $dbh->num_rows($all_logs_query);
         $pages = ceil($num_logs / $per_page);
         if ($num_logs == 0) {
             $admin_logs_list_array['LOGS'] = "";
             $admin_logs_list_array['PAGING'] = "";
             main::errors("No logs found.");
         } else {
             while ($logs_data = $dbh->fetch_array($logs_query)) {
                 $message_data = explode("<", substr($logs_data['message'], 0, 100));
                 $admin_log_item_array['USER'] = $logs_data['loguser'];
                 $admin_log_item_array['DATE'] = main::convertdate("n/d/Y", $logs_data['logtime']);
                 $admin_log_item_array['TIME'] = main::convertdate("g:i A", $logs_data['logtime']);
                 $admin_log_item_array['MESSAGE'] = $message_data[0];
                 $admin_log_item_array['LOGID'] = $logs_data['id'];
                 $admin_logs_list_array['LOGS'] .= style::replaceVar("tpl/admin/logs/admin-log-item.tpl", $admin_log_item_array);
             }
         }
         if ($start != 0) {
             $back_page = $start - $per_page;
             $admin_logs_list_array['PAGING'] = '<a href="?page=logs&show=' . $show . '&start=' . $back_page . '&limit=' . $per_page . '">BACK</a>&nbsp;';
         }
         for ($i = 1; $i <= $pages; $i++) {
             $start_link = $per_page * ($i - 1);
             if ($start_link == $start) {
                 $admin_logs_list_array['PAGING'] .= '&nbsp;<b>' . $i . '</b>&nbsp;';
             } else {
                 $admin_logs_list_array['PAGING'] .= '&nbsp;<a href="?page=logs&show=' . $show . '&start=' . $start_link . '&limit=' . $per_page . '">' . $i . '</a>&nbsp;';
             }
         }
         if (($start + $per_page) / $per_page < $pages && $pages != 1) {
             $next_page = $start + $per_page;
             $admin_logs_list_array['PAGING'] .= '&nbsp;<a href="?page=logs&show=' . $show . '&start=' . $next_page . '&limit=' . $per_page . '">NEXT</a>';
         }
         $shown = array();
         $log_type_values[] = array("Show All", "all");
         $logs_query = $dbh->select("logs", 0, array("logtype", "ASC"), 0, 1);
         while ($logs_data = $dbh->fetch_array($logs_query)) {
             if (!in_array($logs_data['logtype'], $shown)) {
                 $log_type_values[] = array($logs_data['logtype'], $logs_data['logtype']);
                 $shown[] = $logs_data['logtype'];
             }
         }
         $admin_logs_list_array['SHOW_TYPE'] = main::dropdown("show", $log_type_values);
         echo style::replaceVar("tpl/admin/logs/admin-logs-list.tpl", $admin_logs_list_array);
     }
 }
Beispiel #7
0
                $server_type = type::packageserver($pack);
                $serverfile = server::createServer($server_type);
                $can_create_subs = $serverfile->subdomains;
                if ($can_create_subs == false) {
                    $maincontent = main::table("Subdomain Error", "Sorry, but the server for this package doesn't allow subdomains to be used without a unique domain present on the account.  If you'd like to\n                                                                   use a domain, please go back and select the domain option.");
                } else {
                    $subdomains_query = $dbh->select("subdomains", array("server", "=", $server_type), array("subdomain", "ASC"), 0, 1);
                    while ($subdomains_data = $dbh->fetch_array($subdomains_query)) {
                        $subdomains[] = array($subdomains_data['domain'], $subdomains_data['domain']);
                    }
                    if ($postvar['csub2']) {
                        $subtld = $postvar['csub2'];
                    } else {
                        $subtld = $subdomains[0]['domain'];
                    }
                    $subdomain_array['SUBDOMTLDLIST'] = main::dropdown("csub2", $subdomains, $subtld);
                    $order_form_array['DOMORSUB'] = style::replaceVar("tpl/order/subdomain.tpl", $subdomain_array);
                }
            }
        }
    }
    //Spit out the page
    if (!$maincontent) {
        $maincontent = style::replaceVar("tpl/order/order-form.tpl", $order_form_array);
    }
    echo '<div>';
    echo $maincontent;
    echo '</div>';
}
echo '</div>';
echo style::get("footer.tpl");
Beispiel #8
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     if ($getvar['mode'] == 'ticketsall') {
         $no_tickets_msg = "You currently have no tickets.";
         $view_mode_text = "<center><i><u><a href=\"?page=tickets\" title=\"View open tickets\">View open tickets</a></u></i></center>";
     } else {
         $where[] = array("status", "!=", "3", "AND");
         $no_tickets_msg = "You currently have no new tickets! <i><u><a href=\"?page=tickets&mode=ticketsall\" title=\"View all tickets.\">View all tickets</a></u></i>";
         $view_mode_text = "<center><i><u><a href=\"?page=tickets&mode=ticketsall\" title=\"View all tickets\">View all tickets</a></u></i></center>";
     }
     if (!$getvar['do']) {
         $where[] = array("reply", "=", "0");
         $tickets_query = $dbh->select("tickets", $where, array("time", "DESC"), 0, 1);
         if (!$dbh->num_rows($tickets_query)) {
             echo $no_tickets_msg;
         } else {
             if ($getvar['mode'] == 'ticketsall') {
                 echo "<div style=\"display: none;\" id=\"nun-tickets\">You currently have no tickets!</div>";
             } else {
                 echo "<div style=\"display: none;\" id=\"nun-tickets\">You currently have no new tickets!</div>";
             }
             $num_rows = $dbh->num_rows($tickets_query);
             echo style::replaceVar("tpl/admin/tickets/tickets-js.tpl", array('NUM_TICKETS' => $num_rows));
             while ($tickets_data = $dbh->fetch_array($tickets_query)) {
                 $ticket_view_box_array['TITLE'] = $tickets_data['title'];
                 $ticket_view_box_array['UPDATE'] = $this->lastUpdated($tickets_data['id']);
                 $ticket_view_box_array['STATUS'] = $tickets_data['status'];
                 $ticket_view_box_array['STATUSMSG'] = $this->status($tickets_data['status']);
                 $ticket_view_box_array['ID'] = $tickets_data['id'];
                 $ticket_view_box_array['URGENCYTEXT'] = $tickets_data['urgency'];
                 $ticket_view_box_array['URGENCY_CLASS'] = strtolower(str_replace(" ", "_", $tickets_data['urgency']));
                 echo style::replaceVar("tpl/admin/tickets/ticket-view-box.tpl", $ticket_view_box_array);
             }
             echo $view_mode_text;
         }
     } else {
         unset($where);
         $where[] = array("id", "=", $getvar['do'], "OR");
         $where[] = array("ticketid", "=", $getvar['do']);
         $tickets_query = $dbh->select("tickets", $where, array("time", "ASC"), 0, 1);
         if (!$dbh->num_rows($tickets_query)) {
             echo "That ticket doesn't exist!";
         } else {
             if ($_POST) {
                 check::empty_fields(array("admin"));
                 if (!main::errors()) {
                     $time = time();
                     $tickets_insert = array("title" => $postvar['title'], "content" => $postvar['content'], "time" => $time, "userid" => $_SESSION['user'], "reply" => "1", "ticketid" => $getvar['do'], "staff" => "1");
                     $dbh->insert("tickets", $tickets_insert);
                     main::errors("Reply has been added!");
                     $last_ticket_data = $dbh->select("tickets", array("time", "=", $time), 0, "1");
                     $tickets_data = $dbh->fetch_array($tickets_query);
                     $client = $dbh->staff($_SESSION['user']);
                     $user = $dbh->client($tickets_data['userid']);
                     $template = email::emailTemplate("ticket-staff-responded");
                     $clientresponse_array['TITLE'] = $tickets_data['title'];
                     $clientresponse_array['STAFF'] = $client['name'];
                     $clientresponse_array['CONTENT'] = $postvar['content'];
                     $clientresponse_array['LINK'] = $dbh->config("url") . "/client/?page=tickets&sub=view&do=" . $last_ticket_data['ticketid'];
                     email::send($user['email'], $template['subject'], $template['content'], $clientresponse_array);
                     main::redirect("?page=tickets&sub=view&do=" . $getvar['do']);
                 }
             }
             $tickets_data = $dbh->fetch_array($tickets_query);
             $view_ticket_array['AUTHOR'] = $this->determineAuthor($tickets_data['userid'], $tickets_data['staff']);
             $view_ticket_array['TIME'] = main::convertdate("n/d/Y - g:i A", $tickets_data['time']);
             $view_ticket_array['NUMREPLIES'] = $dbh->num_rows($tickets_query) - 1;
             $view_ticket_array['UPDATED'] = $this->lastUpdated($tickets_data['id']);
             $view_ticket_array['ORIG'] = $this->showReply($tickets_data['id']);
             $view_ticket_array['URGENCY'] = $tickets_data['urgency'];
             $view_ticket_array['STATUS'] = $this->status($tickets_data['status']);
             switch ($tickets_data['status']) {
                 case "1":
                     $view_ticket_array['STATUSCOLOR'] = "779500";
                     break;
                 case "2":
                     $view_ticket_array['STATUSCOLOR'] = "FF9500";
                     break;
                 case "3":
                     $view_ticket_array['STATUSCOLOR'] = "FF0000";
                     break;
                 default:
                     $view_ticket_array['STATUSCOLOR'] = "000000";
                     break;
             }
             $view_ticket_array['REPLIES'] = "";
             $n = 0;
             while ($reply = $dbh->fetch_array($tickets_query)) {
                 if (!$n) {
                     $view_ticket_array['REPLIES'] .= "<br /><b>Replies</b>";
                 }
                 $view_ticket_array['REPLIES'] .= $this->showReply($reply['id']);
                 $n++;
             }
             $view_ticket_array['ADDREPLY'] .= "<br /><b>Change Ticket Status</b>";
             $values[] = array("Open", 1);
             $values[] = array("On Hold", 2);
             $values[] = array("Closed", 3);
             $change_status_array['DROPDOWN'] = main::dropdown("status", $values, $tickets_data['status'], 0);
             $change_status_array['ID'] = $tickets_data['id'];
             $view_ticket_array['ADDREPLY'] .= style::replaceVar("tpl/tickets/change-status.tpl", $change_status_array);
             $view_ticket_array['ADDREPLY'] .= "<br /><b>Add Reply</b>";
             $add_reply_array['TITLE'] = "RE: " . $tickets_data['title'];
             $view_ticket_array['ADDREPLY'] .= style::replaceVar("tpl/tickets/add-reply.tpl", $add_reply_array);
             echo style::replaceVar("tpl/tickets/view-ticket.tpl", $view_ticket_array);
         }
     }
 }
Beispiel #9
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     switch ($getvar['sub']) {
         default:
             if ($_POST) {
                 check::empty_fields();
                 if (!main::errors()) {
                     $time = time();
                     $tickets_insert = array("title" => $postvar['title'], "content" => $postvar['content'], "urgency" => $postvar['urgency'], "time" => $time, "userid" => $_SESSION['cuser']);
                     $dbh->insert("tickets", $tickets_insert);
                     $last_ticket_data = $dbh->select("tickets", array("time", "=", $time), 0, "1");
                     $template = email::emailTemplate("new-ticket");
                     $newticket_array['TITLE'] = $postvar['title'];
                     $newticket_array['URGENCY'] = $postvar['urgency'];
                     $newticket_array['CONTENT'] = $postvar['content'];
                     $newticket_array['LINK'] = $dbh->config("url") . ADMINDIR . "/?page=tickets&sub=view&do=" . $last_ticket_data['id'];
                     email::staff($template['subject'], $template['content'], $newticket_array);
                     main::errors("Ticket has been added!");
                 }
             }
             echo style::replaceVar("tpl/client/tickets/add-ticket.tpl");
             break;
         case "view":
             if (is_numeric($getvar['deltid'])) {
                 $userid = $_SESSION['cuser'];
                 $tid = $getvar['deltid'];
                 unset($where);
                 $where[] = array("id", "=", $tid, "AND");
                 $where[] = array("userid", "=", $userid);
                 $user_check = $dbh->select("tickets", $where, 0, "1", 1);
                 $user_check_rows = $dbh->num_rows($user_check);
                 if ($user_check_rows == "0") {
                     echo "<font color = '#FF0000'>This ticket is not yours to delete or does not exist.</font><br>";
                 } else {
                     unset($where);
                     $where[] = array("id", "=", $tid, "OR");
                     $where[] = array("ticketid", "=", $tid);
                     $dbh->delete("tickets", $where);
                 }
             }
             if (!$getvar['do']) {
                 unset($where);
                 $where[] = array("userid", "=", $_SESSION['cuser'], "AND");
                 $where[] = array("reply", "=", "0");
                 $tickets_query = $dbh->select("tickets", $where, 0, 0, 1);
                 if (!$dbh->num_rows($tickets_query)) {
                     echo "You currently have no tickets!";
                 } else {
                     while ($tickets_data = $dbh->fetch_array($tickets_query)) {
                         $ticket_view_box_array['TITLE'] = $tickets_data['title'];
                         $ticket_view_box_array['UPDATE'] = $this->lastUpdated($tickets_data['id']);
                         $ticket_view_box_array['ID'] = $tickets_data['id'];
                         $ticket_view_box_array['STATUS'] = $tickets_data['status'];
                         $ticket_view_box_array['STATUSMSG'] = $this->status($tickets_data['status']);
                         echo style::replaceVar("tpl/client/tickets/ticket-view-box.tpl", $ticket_view_box_array);
                     }
                 }
             } else {
                 unset($where);
                 $where[] = array("id", "=", $getvar['do'], "OR");
                 $where[] = array("ticketid", "=", $getvar['do']);
                 $tickets_query = $dbh->select("tickets", $where, array("time", "ASC"), 0, 1);
                 if (!$dbh->num_rows($tickets_query)) {
                     echo "That ticket doesn't exist!";
                 } else {
                     if ($_POST) {
                         check::empty_fields();
                         if (!main::errors()) {
                             $time = time();
                             $tickets_insert = array("title" => $postvar['title'], "content" => $postvar['content'], "time" => $time, "userid" => $_SESSION['cuser'], "reply" => "1", "ticketid" => $getvar['do']);
                             $dbh->insert("tickets", $tickets_insert);
                             $last_ticket_data = $dbh->select("tickets", array("time", "=", $time), 0, "1");
                             $tickets_data = $dbh->fetch_array($tickets_query);
                             $client = $dbh->client($_SESSION['cuser']);
                             $template = email::emailTemplate("ticket-client-responded");
                             $newresponse_array['TITLE'] = $tickets_data['title'];
                             $newresponse_array['USER'] = $client['user'];
                             $newresponse_array['CONTENT'] = $postvar['content'];
                             $newresponse_array['LINK'] = $dbh->config("url") . ADMINDIR . "/?page=tickets&sub=view&do=" . $last_ticket_data['ticketid'];
                             email::staff($template['subject'], $template['content'], $newresponse_array);
                             main::redirect("?page=tickets&sub=view&do=" . $getvar['do']);
                         }
                     }
                     $tickets_data = $dbh->fetch_array($tickets_query);
                     $view_ticket_array['AUTHOR'] = $this->determineAuthor($tickets_data['userid'], $tickets_data['staff']);
                     $view_ticket_array['TIME'] = main::convertdate("n/d/Y - g:i A", $tickets_data['time']);
                     $view_ticket_array['NUMREPLIES'] = $dbh->num_rows($tickets_query) - 1;
                     $view_ticket_array['UPDATED'] = $this->lastUpdated($tickets_data['id']);
                     $view_ticket_array['ORIG'] = $this->showReply($tickets_data['id']);
                     $view_ticket_array['URGENCY'] = $tickets_data['urgency'];
                     $view_ticket_array['STATUS'] = $this->status($tickets_data['status']);
                     switch ($tickets_data['status']) {
                         case "1":
                             $view_ticket_array['STATUSCOLOR'] = "779500";
                             break;
                         case "2":
                             $view_ticket_array['STATUSCOLOR'] = "FF9500";
                             break;
                         case "3":
                             $view_ticket_array['STATUSCOLOR'] = "FF0000";
                             break;
                         default:
                             $view_ticket_array['STATUSCOLOR'] = "000000";
                             break;
                     }
                     $n = 0;
                     $view_ticket_array['REPLIES'] = "";
                     while ($reply = $dbh->fetch_array($tickets_query)) {
                         if (!$n) {
                             $view_ticket_array['REPLIES'] .= "<br /><b>Replies</b>";
                         }
                         $view_ticket_array['REPLIES'] .= $this->showReply($reply['id']);
                         $n++;
                     }
                     $view_ticket_array['ADDREPLY'] .= "<br /><b>Change Ticket Status</b>";
                     $values[] = array("Open", 1);
                     $values[] = array("On Hold", 2);
                     $values[] = array("Closed", 3);
                     $client_change_status_array['DROPDOWN'] = main::dropdown("status", $values, $tickets_data['status'], 0);
                     $client_change_status_array['ID'] = $tickets_data['id'];
                     $view_ticket_array['ADDREPLY'] .= style::replaceVar("tpl/tickets/change-status.tpl", $client_change_status_array);
                     $view_ticket_array['ADDREPLY'] .= "<br /><b>Add Reply</b>";
                     $add_reply_array['TITLE'] = "RE: " . $tickets_data['title'];
                     $view_ticket_array['ADDREPLY'] .= style::replaceVar("tpl/tickets/add-reply.tpl", $add_reply_array);
                     echo style::replaceVar("tpl/tickets/view-ticket.tpl", $view_ticket_array);
                 }
             }
             break;
     }
 }