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; } }
public function do_upgrade($upgradeid, $mode, $no_errors_out = 0) { global $dbh, $postvar, $getvar, $instance; //$mode // //Init - When the upgrade info is added, we call this function. //Update - When cron or an admin does something with this function, we check to see if various tasks are ready to be performed. //Flag meaning: // //IMMEDIATE UPGRADE FLAGS // //0 - Upgrade is immediate. //5 - If admin approves the upgrade, then the upgrade will be immediate. // //6 - If admin approves the upgrade, then the new account will be created on the new server and the // admin will know that they are moving to a new server so they can manually close the old account // when they're ready. // //7 - The new account on the new server will be immediately created and the admin will be notified that // the user is switching servers. // //NEXT MONTH UPGRADE FLAGS // //1 - Cron will upgrade them next month. //2 - If admin approves this, then it will be set to 1 for cron to upgrade them next month. //3 - The admin will be notified that the user wishes to be upgraded and if they approve it, // then an account on the new server will be created so they can migrate to the new server. // the admin can opt to switch the account over before next month if they both agree and the // switch will be made in the admin area manually. // //4 - Cron will create a new account on the new server next month and inform the admin that the // user is changing to the new server. // $upgrade_data = $dbh->select("upgrade", array("id", "=", $upgradeid)); $userid = $upgrade_data['uid']; $newpack = $upgrade_data['newpack']; $flags = $upgrade_data['flags']; $created = $upgrade_data['created']; $coupcode = $upgrade_data['coupcode']; $user_data = main::uidtopack($userid); $current_pack_type = $user_data['packages']['type']; $current_pack_name = $user_data['packages']['name']; $current_pack_id = $user_data['packages']['id']; $user_info = $dbh->select("users", array("id", "=", $userid)); $user_email = $user_info['email']; $username = $user_info['user']; $new_plan_data = $dbh->select("packages", array("id", "=", $newpack)); $newpack_name = $new_plan_data['name']; $new_plan_additional = type::additional($newpack); $new_server_data = $dbh->select("servers", array("id", "=", $new_plan_data['server'])); $new_server_name = $new_server_data['name']; $old_server_data = $dbh->select("servers", array("id", "=", $user_data['packages']['server'])); $old_server_name = $old_server_data['name']; switch ($flags) { case "0": $upgrade = 1; break; case "1": $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; } break; case "2": if ($mode = "Init") { $admin_approval = 1; } else { //If its already the day for the upgrade, then we can do the upgrade now. $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; } if (!$upgrade) { $dbh->update("upgrade", array("flags" => "1"), array("id", "=", $upgradeid), "1"); } } break; case "3": if ($mode = "Init") { $admin_approval = 1; $new_server = 1; } else { //If its already the day for the upgrade, then we can do the upgrade now. $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; $new_server = 1; } if (!$upgrade) { $dbh->update("upgrade", array("flags", "=", "4"), array("id", "=", $upgradeid), "1"); } } break; case "4": //If its already the day for the upgrade, then we can do the upgrade now. $upgrade_today = self::upgrade_today($current_pack_type, $userid); if ($upgrade_today) { $upgrade = 1; $new_server = 1; $admin_inform = 1; } break; case "5": if ($mode = "Init") { $admin_approval = 1; $immediate = 1; } else { $upgrade = 1; } break; case "6": if ($mode = "Init") { $admin_approval = 1; $new_server = 1; $immediate = 1; } else { $upgrade = 1; $new_server = 1; } break; case "7": $upgrade = 1; $new_server = 1; $admin_inform = 1; break; } $adminmsg_array['USER'] = $username; $adminmsg_array['NEWPLAN'] = $newpack_name; $adminmsg_array['OLDPLAN'] = $current_pack_name; $adminmsg_array['NEWSERVER'] = $new_server_name; $adminmsg_array['OLDSERVER'] = $old_server_name; if ($immediate) { $adminmsg_array['NEXTMONTH_IMMEDIATELY'] = "immediately"; } else { $adminmsg_array['NEXTMONTH_IMMEDIATELY'] = "next billing cycle"; } $url = $dbh->config("url"); if (ADMINDIR) { $admin_dir = ADMINDIR; } else { $admin_dir = "admin"; } $adminmsg_array['APPROVE_LINK'] = $url . $admin_dir . "/?page=users&sub=upgrade"; if ($upgrade) { if ($new_plan_data['type'] == "paid") { $new_invoice_text = " A new invoice has been generated."; if ($current_pack_type == "paid" && $user_data['additional']['monthly'] >= $new_plan_additional['monthly']) { unset($new_invoice_text); } } $serverfile = server::createServer($newpack); if ($new_server) { $new_serv_pass_for_email = time(); $domsub = "sub"; //Checks to see if the domain contains 3 or more segments and fails if there are more than 3 and if the last one two aren't TLD portions, it fails, //so we can see if this is a subdomain this way. if (check::domain($user_data['user_data']['domain'])) { $domsub = "dom"; } $done = $serverfile->signup(type::packageserver($newpack), $new_plan_data['reseller'], $username, $user_email, $new_serv_pass_for_email, $user_data['user_data']['domain'], type::packageBackend($newpack), $domsub); if ($done === true) { if ($new_plan_data['reseller']) { $uemaildata = email::emailTemplate("upgrade-newserv-resell-welcome"); } else { $uemaildata = email::emailTemplate("upgrade-newserv-welcome"); } $change_tht = 1; main::errors("Your upgrade request has been completed. An email has been sent to you detailing your upgraded account on the new server." . $new_invoice_text); } else { return false; } } else { if ($serverfile->canupgrade) { $done = $serverfile->do_upgrade($new_plan_data['server'], type::packageBackend($newpack), $username); if ($done === true) { if ($new_plan_data['reseller']) { $uemaildata = email::emailTemplate("upgrade-resell-welcome"); } else { $uemaildata = email::emailTemplate("upgrade-welcome"); } $change_tht = 1; main::errors("Your upgrade request has been completed. An email has been sent to you detailing your upgraded account." . $new_invoice_text); } else { return false; } } else { $emaildata = email::emailTemplate("manual-upgrade-request"); main::errors("Your upgrade request has been added and the administrator has been emailed."); } } if ($uemaildata) { $welcomeemail_array['USER'] = $username; $welcomeemail_array['EMAIL'] = $user_email; $welcomeemail_array['PACKAGE'] = $newpack_name; $welcomeemail_array['SERVERIP'] = $new_server_data['ip']; $welcomeemail_array['LNAME'] = $user_info['lastname']; $welcomeemail_array['FNAME'] = $user_info['firstname']; $welcomeemail_array['CPPORT'] = $new_server_data['port']; $welcomeemail_array['PASS'] = $new_serv_pass_for_email; $welcomeemail_array['RESELLERPORT'] = $new_server_data['resellerport']; $welcomeemail_array['NAMESERVERS'] = nl2br($new_server_data['nameservers']); $welcomeemail_array['DOMAIN'] = $user_data['user_data']['domain']; email::send($user_email, $uemaildata['subject'], $uemaildata['content'], $welcomeemail_array); } } else { main::errors("Your upgrade request has been added."); } //Now we need to send the admin a dozen emails. lol FIRE! Nah, we'll only ever send them one email at a time. ;) if ($admin_approval) { if ($new_server) { $emaildata = email::emailTemplate("upgrade-newserv-adminval"); } else { $emaildata = email::emailTemplate("upgrade-adminval"); } } if ($admin_inform) { $emaildata = email::emailTemplate("notify-upgrade-new-server"); } if (!$emaildata && $change_tht) { $emaildata = email::emailTemplate("notify-upgrade"); } if ($emaildata) { email::staff($emaildata['subject'], $emaildata['content'], $adminmsg_array); } if ($change_tht) { main::thtlog("Client Upgraded", "Upgraded from " . $current_pack_name . " to " . $newpack_name, $userid, ""); if ($current_pack_type == "paid") { unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", ""); $dbh->update("invoices", array("pid" => $current_pack_id), $where); } if ($new_plan_data['type'] != "p2h") { $dbh->delete("coupons_p2h", array("uid", "=", $userid)); } $user_pack_data = $user_data['user_data']; $users_update = array("pid" => $newpack, "domain" => $user_pack_data['domain'], "additional" => $user_pack_data['additional']); $dbh->update("users", $users_update, array("id", "=", $userid), "1"); $dbh->update("users_bak", $users_update, array("id", "=", $userid), "1"); if ($current_pack_type == "paid") { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupons_used_query = $dbh->select("coupons_used", $where, 0, 0, 1); while ($coupons_used_data = $dbh->fetch_array($coupons_used_query)) { $had_coupons .= $coupons_used_data['coupcode'] . ","; $couponvals .= $coupons_used_data['paiddisc'] . ","; } $had_coupons = substr($had_coupons, 0, strlen($had_coupons) - 1); $couponvals = substr($couponvals, 0, strlen($couponvals) - 1); if (!$had_coupons) { $had_coupons = "0"; $couponvals = "0"; } $invoices_update = array("changed_plan" => "1", "hadcoupons" => $had_coupons, "couponvals" => $couponvals); unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("hadcoupons", "=", ""); $dbh->update("invoices", $invoices_update, $where); } $multi_coupons = $dbh->config("multicoupons"); if ($coupcode || $new_plan_data['type'] == "free") { if (!$multi_coupons || $new_plan_data['type'] == "free") { $coupons_used_update = array("disabled" => "2", "datedisabled" => time()); $dbh->update("coupons_used", $coupons_used_update, array("user", "=", $userid)); } } if ($new_plan_data['type'] != "free") { if ($new_plan_data['type'] == "paid") { unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $current_pack_id); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if ($user_data['additional']['monthly'] < $new_plan_additional['monthly'] && $current_pack_type == "paid" && $last_invoice) { unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $current_pack_id); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if (!$multi_coupons) { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $current_coupon = $dbh->select("coupons_used", $where); $coupcode = $current_coupon['coupcode']; coupons::remove_coupon($current_coupon['id'], $newpack, $last_invoice['id'], $userid); } else { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupons_used_query = $dbh->select("coupons_used", $where, 0, 0, 1); while ($coupons_used_data = $dbh->fetch_array($coupons_used_query)) { $use_coupons[] = $coupons_used_data['coupcode']; coupons::remove_coupon($coupons_used_data['id'], $newpack, $last_invoice['id'], $userid); } } unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $current_pack_id); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); $invoice_update_array = array("amount" => $new_plan_additional['monthly'], "due" => $last_invoice['due'] + 7 * 24 * 60 * 60, "pid" => $newpack, "hadcoupons" => "", "couponvals" => "", "changed_plan" => "0", "is_paid" => "0"); $where[] = array("id", "=", $last_invoice['id']); $dbh->update("invoices", $invoice_update_array, $where); } else { $amount = $new_plan_additional['monthly']; if (!$coupcode) { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupcode = $dbh->select("coupons_used", $where); $coupcode = $coupcode['coupcode']; } $coupon_data = coupons::coupon_data($coupcode); $coupon_data['paiddisc'] = coupons::percent_to_value("paid", "paidtype", "paiddisc", $amount); if ($multi_coupons) { $amount = coupons::get_discount("paid", $amount, $userid) - $coupon_data['paiddisc']; } else { $amount = max(0, $amount - $coupon_data['paiddisc']); } $due = time() + 2592000; $notes = "Your hosting package invoice for this billing cycle. Package: " . $newpack_name; invoice::create($userid, $amount, $due, $notes); $last_invoice = $dbh->select("invoices", array("uid", "=", $userid), array("id", "DESC"), "1"); $dbh->update("invoices", array("pid" => $newpack), array("id", "=", $last_invoice['id']), "1"); unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $newpack); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if (!$multi_coupons) { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $current_coupon = $dbh->select("coupons_used", $where); coupons::remove_coupon($current_coupon['id'], $newpack, $last_invoice['id'], $userid); } else { unset($where); $where[] = array("user", "=", $userid, "AND"); $where[] = array("disabled", "=", "0"); $coupons_used_query = $dbh->select("coupons_used", $where, 0, 0, 1); while ($coupons_used_data = $dbh->fetch_array($coupons_used_query)) { $use_coupons[] = $coupons_used_data['coupcode']; coupons::remove_coupon($coupons_used_data['id'], $newpack, $last_invoice['id'], $userid); } } } } unset($where); $where[] = array("uid", "=", $userid, "AND"); $where[] = array("pid", "=", $newpack); $last_invoice = $dbh->select("invoices", $where, array("id", "DESC"), "1"); if ($coupcode) { $coupon_data = $dbh->select("coupons", array("coupcode", "=", $coupcode)); coupons::use_coupon($coupon_data['id'], $newpack, $last_invoice['id'], $userid, "orders"); } if ($multi_coupons && $use_coupons) { for ($i = 0; $i < count($use_coupons); $i++) { $coupcode = $use_coupons[$i]; $coupon_data = $dbh->select("coupons", array("coupcode", "=", $coupcode)); coupons::use_coupon($coupon_data['id'], $newpack, $last_invoice['id'], $userid, "orders"); } } } //We now remove the upgrade stub. $dbh->delete("upgrade", array("uid", "=", $userid)); } unset($where); $where[] = array("amount", "=", "0", "OR"); $where[] = array("amount", "=", "0.00"); $dbh->update("invoices", array("is_paid" => "1"), $where); if (!$no_errors_out) { echo "<ERRORS>"; } }
public function unsuspend($id, $noemail = 0) { global $dbh, $postvar, $getvar, $instance; unset($where); $where[] = array("id", "=", $id, "AND"); $where[] = array("status", "=", "2", "OR", 1); $where[] = array("status", "=", "3", "OR"); $where[] = array("status", "=", "4", "", 1); $users_data = $dbh->select("users", $where); if (!$users_data['id']) { $error_array['Error'] = "That package doesn't exist or cannot be unsuspended!"; $error_array['User PID'] = $id; main::error($error_array); return; } else { $server = type::packageserver($users_data['pid']); $serverfile = self::createServer($users_data['pid']); if ($serverfile->unsuspend($users_data['user'], $server) == true) { if (!$noemail) { $emaildata = email::emailTemplate("account-unsuspended"); email::send($users_data['email'], $emaildata['subject'], $emaildata['content']); $package_server_data = $dbh->select("servers", array("id", "=", type::packageserver($client['pid']))); $admin_notifyunsuspend = email::emailTemplate("notify-admin-of-unsuspension"); $notifyunsuspend_array['USER'] = $users_data['user']; $notifyunsuspend_array['SERV_TYPE'] = $package_server_data['type']; $notifyunsuspend_array['SERV_NAME'] = $package_server_data['name']; email::staff($admin_notifyunsuspend['subject'], $admin_notifyunsuspend['content'], $notifyunsuspend_array); } $dbh->update("users_bak", array("status" => "1"), array("id", "=", $users_data['id'])); $dbh->update("users", array("status" => "1"), array("id", "=", $users_data['id'])); main::thtlog("Client Account Unsuspended", "Unsuspended", $users_data['id']); return true; } else { return false; } } }