Esempio n. 1
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     if ($_POST) {
         check::empty_fields();
         if (!main::errors()) {
             $user = $dbh->staff($_SESSION['user']);
             if (!$user['password']) {
                 main::errors("Wrong username!?");
             } else {
                 if (crypto::passhash($postvar['old'], $user['salt']) == $user['password']) {
                     if ($postvar['new'] != $postvar['confirm']) {
                         main::errors("Your passwords don't match!");
                     } else {
                         $salt = crypto::salt();
                         $newpass = crypto::passhash($postvar['new'], $salt);
                         $update_staff = array("password" => $newpass, "salt" => $salt);
                         $dbh->update("staff", $update_staff, array("id", "=", $_SESSION['user']));
                         main::errors("Password changed!");
                     }
                 } else {
                     main::errors("Your old password was wrong!");
                 }
             }
         }
     }
     echo style::replaceVar("tpl/admin/change-admin-password.tpl");
 }
Esempio n. 2
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     if (!$dbh->config("delacc")) {
         die('This feature has been disabled.');
     } else {
         if ($_POST) {
             $user = $_SESSION['cuser'];
             $pass = $postvar['password'];
             $client = $dbh->client($user);
             unset($where);
             $where[] = array("is_paid", "=", "0", "AND");
             $where[] = array("uid", "=", $user);
             $balance_query = $dbh->select("invoices", $where, 0, "1", 1);
             if ($dbh->num_rows($balance_query) != 0) {
                 main::errors("You can't close your account with an outstanding balance.  Please contact an administrator for assistance or pay any unpaid invoices.");
             }
             if (crypto::passhash($pass, $client['salt']) == $client['password']) {
                 if (server::terminate($client['id'], "", 1)) {
                     main::errors("Your account has been cancelled successfully.");
                     session_destroy();
                 } else {
                     main::errors("Your account wasn't cancelled.  Please try again or contact your system administrator.");
                 }
             } else {
                 main::errors("The password entered is incorrect.");
             }
         }
         echo style::replaceVar("tpl/client/delete-account.tpl");
     }
 }
Esempio n. 3
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     $client_data = $dbh->client($_SESSION['cuser']);
     $packages_data = $dbh->select("packages", array("id", "=", $client_data['pid']));
     $view_package_array['USER'] = $client_data['user'];
     $view_package_array['SIGNUP'] = main::convertdate("n/d/Y", $client_data['signup']);
     $view_package_array['DOMAIN'] = $client_data['domain'];
     $view_package_array['PACKAGE'] = $packages_data['name'] . " <a href = '?page=upgrade'>Change</a>";
     $view_package_array['DESCRIPTION'] = $packages_data['description'];
     if ($_POST) {
         if (crypto::passhash($postvar['currentpass'], $client_data['salt']) == $client_data['password']) {
             if ($postvar['newpass'] == $postvar['cpass']) {
                 $cmd = main::changeClientPassword($client_data['id'], $postvar['newpass']);
                 if ($cmd === true) {
                     main::errors("Details updated!");
                 } else {
                     main::errors((string) $cmd);
                 }
             } else {
                 main::errors("Your passwords don't match!");
             }
         } else {
             main::errors("Your current password wasn't correct!");
         }
     }
     echo style::replaceVar("tpl/client/view-package.tpl", $view_package_array);
 }
Esempio n. 4
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     $version_info = main::latest_version();
     $current_version = $version_info['THT'];
     $new_version_download = $version_info['THT_DL'];
     $running_version = $dbh->config('version');
     $install_check = $this->checkDir(INC . "../install/");
     $conf_check = $this->checkPerms(INC . "/conf.inc.php");
     if ($current_version == $running_version) {
         $updatemsg = "<span style='color:green'>Up-To-Date</span>";
         $upgrademsg = "";
     } else {
         $updatemsg = "<span style='color:red'>Upgrade Avaliable</span>";
         $upgrademsg = "<div class='warn'><img src='../themes/icons/error.png' alt='' /> There is a new version ({$current_version}) avaliable! <a href = '" . $new_version_download . "' target = '_blank'>Please download it here</a> and upgrade!</div>";
     }
     unset($current_version);
     unset($running_version);
     $stats['VERSION'] = $dbh->config('version');
     $stats['THEME'] = $dbh->config('theme');
     $stats['CENABLED'] = main::cleaninteger($dbh->config('cenabled'));
     $stats['SVID'] = main::cleaninteger($dbh->config('show_version_id'));
     $stats['SENABLED'] = main::cleaninteger($dbh->config('senabled'));
     $stats['DEFAULT'] = $dbh->config('default_page');
     $stats['EMETHOD'] = $dbh->config('emailmethod');
     $stats['SIGNENABLE'] = main::cleaninteger($dbh->config('general'));
     $stats['MULTI'] = main::cleaninteger($dbh->config('multiple'));
     $stats['UPDATE'] = $updatemsg;
     $stats['UPG_BOX'] = $upgrademsg;
     $stats_box = style::replaceVar('tpl/admin/home/stats.tpl', $stats);
     $content = '<strong>Welcome to your Admin Dashboard!</strong><br />Welcome to the dashboard of your Admin Control Panel. In this area you can do the tasks that you need to complete such as manage servers, create packages, manage users.<br />
             Here, you can also change the look and feel of your THT Installation. If you require any help, be sure to ask at the <a href="http://thehostingtool.com/forum" title="THT Community is the official stop for THT Support, THT Modules, Developer Center and more! Visit our growing community now!" class="tooltip">THT Community</a><br /><br />' . $stats_box . '<br />' . $install_check . $conf_check . '</div></div>';
     echo $content;
     if ($_POST) {
         $dbh->update("admin_notes", array("notes" => $postvar['admin_notes']), array("id", "=", "1"));
         main::errors("Settings Updated!");
         main::done();
     }
     $notes_data = $dbh->select("admin_notes", array("id", "=", "1"));
     $notepad_array['NOTEPAD'] = $notes_data['notes'];
     $content_notepad = style::replaceVar('tpl/admin/home/notepad.tpl', $notepad_array);
     echo '<br />';
     echo main::table('Admin Notepad', $content_notepad, 'auto', 'auto');
     $news = main::sub("<strong>Add the THT RSS Feed!</strong>", '<a href="http://thehostingtool.com/forum/syndication.php?fid=2" target="_blank" class="tooltip" title="Add the THT RSS Feed!"><img src="<URL>themes/icons/feed.png" /></a>');
     $rss_feed = @file_get_contents("http://thehostingtool.com/forum/syndication.php?fid=2&limit=3");
     if ($rss_feed !== false) {
         $xml = new SimpleXMLElement($rss_feed);
         foreach ($xml->channel->item as $item) {
             $newsitem_array['title'] = $item->title;
             $newsitem_array['author'] = "THT";
             $newsitem_array['link'] = $item->link;
             $newsitem_array['TIME'] = main::convertdate("n/d/Y", strtotime($item->pubDate));
             $newsitem_array['SUMMARY'] = $item->description;
             $news .= style::replaceVar('tpl/admin/home/news-item.tpl', $newsitem_array);
         }
     }
     echo "<br />";
     echo main::table('THT News & Updates', $news);
 }
Esempio n. 5
0
 public function empty_fields($omit = array())
 {
     global $dbh, $postvar, $getvar, $instance;
     foreach ($postvar as $key => $value) {
         if ($value == "" && !$n && !in_array($key, $omit)) {
             main::errors("Please fill in all the fields!");
             $n++;
         }
     }
 }
Esempio n. 6
0
 public function conf_perms()
 {
     if (is_writable(INC . "/conf.inc.php")) {
         if (main::perms(INC . "/conf.inc.php", 0444)) {
             main::errors("Configuration File made unwritable.");
         } else {
             main::errors("Failed to make the configuration file unwritable.");
         }
     } else {
         main::errors("Configuration File is already unwritable.");
     }
     echo style::replaceVar('tpl/admin/system/perms-tools.tpl');
 }
Esempio n. 7
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";
         }
     }
 }
Esempio n. 8
0
 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>";
     }
 }
Esempio n. 9
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     switch ($getvar['sub']) {
         default:
             if ($_POST) {
                 check::empty_fields();
                 foreach ($postvar as $key => $value) {
                     $broke = explode("_", $key);
                     if ($broke[0] == "pages") {
                         $postvar['perms'][$broke[1]] = $value;
                     }
                 }
                 if (!main::errors()) {
                     $staff_query = $dbh->select("staff", array("user", "=", $postvar['user']), 0, "1", 1);
                     if (!check::email($postvar['email'])) {
                         main::errors("Your email is the wrong format or is already in use by another staff member or client.");
                     } elseif ($postvar['pass'] != $postvar['conpass']) {
                         main::errors("Passwords don't match!");
                     } elseif ($dbh->num_rows($staff_query) >= 1) {
                         main::errors("That account already exists!");
                     } else {
                         if ($postvar['perms']) {
                             foreach ($postvar['perms'] as $key => $value) {
                                 if ($n) {
                                     $perms .= ",";
                                 }
                                 if ($value == "1") {
                                     $perms .= $key;
                                 }
                                 $n++;
                             }
                         }
                         $salt = crypto::salt();
                         $password = crypto::passhash($postvar['pass'], $salt);
                         $staff_insert = array("user" => $postvar['user'], "name" => $postvar['name'], "email" => $postvar['email'], "password" => $password, "salt" => $salt, "perms" => $perms, "tzadjust" => $postvar['tzones']);
                         $dbh->insert("staff", $staff_insert);
                         main::errors("Account added!");
                     }
                 }
             }
             $acpnav_query = $dbh->select("acpnav", array("link", "!=", "home"), array("id", "ASC"), 0, 1);
             $add_staff_member_array['PAGES'] = '<table width="100%" border="0" cellspacing="0" cellpadding="1">';
             while ($acpnav_data = $dbh->fetch_array($acpnav_query)) {
                 $add_staff_member_array['PAGES'] .= '<tr><td width="30%" align="left">' . $acpnav_data['visual'] . ':</td><td><input name="pages_' . $acpnav_data['id'] . '" id="pages_' . $acpnav_data['id'] . '" type="checkbox" value="1" /></td></tr>';
             }
             $add_staff_member_array['PAGES'] .= '<tr><td width="30%" align="left">Paid Configuration:</td><td><input name="pages_paid" id="pages_paid" type="checkbox" value="1" /></td></tr>';
             $add_staff_member_array['PAGES'] .= '<tr><td width="30%" align="left">P2H Forums:</td><td><input name="pages_p2h" id="pages_p2h" type="checkbox" value="1" /></td></tr>';
             $add_staff_member_array['PAGES'] .= "</table>";
             $add_staff_member_array['TZADJUST'] = main::tzlist();
             echo style::replaceVar("tpl/admin/staff/add-staff-member.tpl", $add_staff_member_array);
             break;
         case "edit":
             if (isset($getvar['do'])) {
                 $staff_data = $dbh->select("staff", array("id", "=", $getvar['do']));
                 if (!$staff_data["user"]) {
                     echo "That account doesn't exist!";
                 } else {
                     if ($_POST) {
                         check::empty_fields();
                         foreach ($postvar as $key => $value) {
                             $broke = explode("_", $key);
                             if ($broke[0] == "pages") {
                                 $postvar['perms'][$broke[1]] = $value;
                             }
                         }
                         if (!main::errors()) {
                             if (!check::email($postvar['email'], $getvar['do'], "staff")) {
                                 main::errors("Your email is the wrong format or is already in use by another staff member or client.");
                             } else {
                                 if ($postvar['perms']) {
                                     foreach ($postvar['perms'] as $key => $value) {
                                         if ($n) {
                                             $perms .= ",";
                                         }
                                         if ($value == "1") {
                                             $perms .= $key;
                                         }
                                         $n++;
                                     }
                                 }
                                 $staff_update = array("email" => $postvar['email'], "name" => $postvar['name'], "perms" => $perms, "tzadjust" => $postvar['tzones'], "user" => $postvar['user']);
                                 $dbh->update("staff", $staff_update, array("id", "=", $getvar['do']));
                                 //Staff account edit complete
                                 main::done();
                             }
                         }
                     }
                     $edit_staff_member_array['USER'] = $staff_data['user'];
                     $edit_staff_member_array['EMAIL'] = $staff_data['email'];
                     $edit_staff_member_array['NAME'] = $staff_data['name'];
                     $edit_staff_member_array['TZADJUST'] = main::tzlist($staff_data['tzadjust']);
                     $acpnav_query = $dbh->select("acpnav", array("link", "!=", "home"), array("id", "ASC"), 0, 1);
                     $edit_staff_member_array['PAGES'] = '<table width="100%" border="0" cellspacing="0" cellpadding="1">';
                     while ($acpnav_data = $dbh->fetch_array($acpnav_query)) {
                         if (!main::checkPerms($acpnav_data['id'], $staff_data['id'])) {
                             $checked = 'checked="checked"';
                         }
                         $edit_staff_member_array['PAGES'] .= '<tr><td width="30%" align="left">' . $acpnav_data['visual'] . ':</td><td><input name="pages_' . $acpnav_data['id'] . '" id="pages_' . $acpnav_data['id'] . '" type="checkbox" value="1" ' . $checked . '/></td></tr>' . "\n";
                         $checked = NULL;
                     }
                     if (substr_count($staff_data['perms'], "paid") == '1') {
                         $paid_check = 'checked="checked"';
                     }
                     if (substr_count($staff_data['perms'], "p2h") == '1') {
                         $p2h_check = 'checked="checked"';
                     }
                     $edit_staff_member_array['PAGES'] .= '<tr><td width="30%" align="left">Paid Configuration:</td><td><input name="pages_paid" id="pages_paid" type="checkbox" value="1" ' . $paid_check . '/></td></tr>' . "\n";
                     $edit_staff_member_array['PAGES'] .= '<tr><td width="30%" align="left">P2H Forums:</td><td><input name="pages_p2h" id="pages_p2h" type="checkbox" value="1" ' . $p2h_check . '/></td></tr>' . "\n";
                     $edit_staff_member_array['PAGES'] .= "</table>";
                     echo style::replaceVar("tpl/admin/staff/edit-staff-member.tpl", $edit_staff_member_array);
                 }
             } else {
                 $staff_query = $dbh->select("staff");
                 if ($dbh->num_rows($staff_query) == 0) {
                     echo "There are no staff accounts to edit!";
                 } else {
                     echo "<ERRORS>";
                     while ($staff_data = $dbh->fetch_array($staff_query)) {
                         echo main::sub("<strong>" . $staff_data['user'] . "</strong>", '<a href="?page=staff&sub=edit&do=' . $staff_data['id'] . '"><img src="' . URL . 'themes/icons/pencil.png"></a>');
                     }
                 }
             }
             break;
         case "delete":
             $staff_query = $dbh->select("staff");
             if ($getvar['do'] && $dbh->num_rows($staff_query) > 1) {
                 $dbh->delete("staff", array("id", "=", $getvar['do']));
                 main::errors("Staff Account Deleted!");
             } elseif ($getvar['do']) {
                 main::errors("Theres only one staff account!");
             }
             if ($dbh->num_rows($staff_query) == 0) {
                 echo "There are no staff accounts to edit!";
             } else {
                 $staff_query = $dbh->select("staff");
                 //This pulls the current staff list after deletion.
                 echo "<ERRORS>";
                 while ($staff_data = $dbh->fetch_array($staff_query)) {
                     echo main::sub("<strong>" . $staff_data['user'] . "</strong>", '<a href="?page=staff&sub=delete&do=' . $staff_data['id'] . '"><img src="' . URL . 'themes/icons/delete.png"></a>');
                 }
             }
             break;
     }
 }
Esempio n. 10
0
 public function clientPage()
 {
     global $dbh, $postvar, $getvar, $instance;
     if (is_numeric($getvar['remove'])) {
         coupons::remove_p2h_coupon($getvar['remove']);
         main::redirect("?page=type&type=p2h&sub=forums");
         exit;
     }
     if ($_POST['submitaddcoupon']) {
         if (!$postvar['addcoupon']) {
             main::errors("Please enter a coupon code.");
         } else {
             $coupcode = $postvar['addcoupon'];
             $pack_data = main::uidtopack();
             $packid = $pack_data['packages']['id'];
             $multi_coupons = $dbh->config("multicoupons");
             $coupon_info = coupons::coupon_data($coupcode);
             $coupid = $coupon_info['id'];
             $use_coupon = coupons::use_coupon($coupid, $packid);
             if (!$use_coupon) {
                 if (!$multi_coupons) {
                     main::errors("Coupon code entered was invalid or you're already using a coupon.");
                 } else {
                     main::errors("Coupon code entered was invalid.");
                 }
             } else {
                 main::redirect("?page=type&type=p2h&sub=forums");
             }
         }
     }
     $userid = $_SESSION['cuser'];
     $client = $dbh->client($userid);
     $forum = type::additional($client['pid'], 'forum');
     $user = type::userAdditional($client['id']);
     $fdetails = $this->forumdata($forum);
     $this->con = $this->forumCon($forum);
     $posts = $this->checkMonthly($fdetails['forumtype'], $user['fuser'], $fdetails['prefix']);
     $total_posts = coupons::totalposts($userid);
     $p2h_payments = $dbh->select("coupons_p2h", array("uid", "=", $userid));
     $package_info = main::uidtopack($userid);
     $user_posts = $this->userposts($package_info['packages']['id'], $package_info['user_data']['id']);
     $monthly = $this->getMonthly($client['pid']);
     if (empty($p2h_payments)) {
         $p2h_pay_array = array("uid" => $userid, "amt_paid" => $user_posts, "txn" => $package_info['uadditional']['fuser'], "datepaid" => time(), "gateway" => $package_info['additional']['forum']);
         $dbh->insert("coupons_p2h", $p2h_pay_array);
         $p2h_payments = $dbh->select("coupons_p2h", array("uid", "=", $userid));
     }
     $amt_paid = $p2h_payments['amt_paid'];
     $txn = $p2h_payments['txn'];
     $datepaid = $p2h_payments['datepaid'];
     $gateway = $p2h_payments['gateway'];
     $amt_paid = explode(",", $amt_paid);
     $txn = explode(",", $txn);
     $datepaid = explode(",", $datepaid);
     $gateway = explode(",", $gateway);
     for ($i = 0; $i < count($amt_paid); $i++) {
         if ($txn[$i] == $package_info['uadditional']['fuser']) {
             if ($amt_paid[$i] != $user_posts) {
                 $reload = 1;
             }
             $amt_paid[$i] = $user_posts;
             $datepaid[$i] = time();
         }
         $p2h_data = $dbh->select("p2h", array("id", "=", $gateway[$i]));
         $transaction_list_array['PAIDAMOUNT'] = main::s($amt_paid[$i], " Post");
         $transaction_list_array['TXN'] = $txn[$i];
         $transaction_list_array['PAIDDATE'] = main::convertdate("n/d/Y", $datepaid[$i]);
         $transaction_list_array['GATEWAY'] = str_replace(",", "", $p2h_data['forumname']);
         $invoice_transactions_array['TXNS'] .= style::replaceVar("tpl/invoices/transaction-list.tpl", $transaction_list_array);
         $paidamts = $paidamts . "," . $amt_paid[$i];
         $paidtxn = $paidtxn . "," . $txn[$i];
         $paiddate = $paiddate . "," . $datepaid[$i];
         $paidgateway = $paidgateway . "," . $gateway[$i];
     }
     $paidamts = substr($paidamts, 1, strlen($paidamts));
     $paidtxn = substr($paidtxn, 1, strlen($paidtxn));
     $paiddate = substr($paiddate, 1, strlen($paiddate));
     $paidgateway = substr($paidgateway, 1, strlen($paidgateway));
     $p2h_pay_array = array("amt_paid" => $paidamts, "txn" => $paidtxn, "datepaid" => $paiddate, "gateway" => $paidgateway);
     $where[] = array("uid", "=", $userid);
     $dbh->update("coupons_p2h", $p2h_pay_array, $where);
     if ($reload) {
         main::redirect("?page=type&type=p2h&sub=forums");
     }
     $invoice_transactions_array['TOTALPAID'] = main::s($total_posts, " Post");
     $posts_array['TRANSACTIONS'] = style::replaceVar("tpl/invoices/invoice-transactions.tpl", $invoice_transactions_array);
     $pack_monthly = $package_info['additional']['monthly'];
     $coupon_total = $pack_monthly - coupons::get_discount("p2hmonthly", $pack_monthly, $userid);
     $balance = max(0, $monthly - $total_posts);
     unset($where);
     $where[] = array("user", "=", $_SESSION['cuser'], "AND");
     $where[] = array("disabled", "=", "0");
     $coupons_used_query = $dbh->select("coupons_used", $where, array("id", "ASC"), 0, 1);
     while ($coupons_used_data = $dbh->fetch_array($coupons_used_query)) {
         $valid_coupon = coupons::check_expire($coupons_used_data['coupcode']);
         if ($valid_coupon) {
             $multipost_text = main::s($coupons_used_data['p2hmonthlydisc'], " Post");
             $coupons_list_array['COUPONAMOUNT'] = $multipost_text;
             $coupons_list_array['COUPCODE'] = $coupons_used_data['coupcode'];
             $coupons_list_array['REMOVE'] = $balance == 0 ? "" : '(<a href = "?page=type&type=p2h&sub=forums&remove=' . $coupons_used_data['id'] . '">Remove</a>)';
             $posts_array['COUPONSLIST'] .= style::replaceVar("tpl/client/coupons/coupons-list.tpl", $coupons_list_array);
         }
     }
     if (!$posts_array['COUPONSLIST']) {
         $posts_array['COUPONSLIST'] = "<tr><td></td><td align = 'center'>None</td></tr>";
     }
     if ($total_posts >= $monthly) {
         $postedcolour = "#779500";
     } else {
         $postedcolour = "#FF7800";
     }
     if ($balance == "0") {
         $posts_array['ADDCOUPONS'] = "";
         $posts_array['PAIDSTATUS'] = "<font color = '#779500'>Paid</font>";
     } else {
         $posts_array['ADDCOUPONS'] = style::replaceVar("tpl/client/coupons/add-coupons.tpl");
         $posts_array['PAIDSTATUS'] = "<font color = '#FF7800'>Unpaid</font>";
     }
     $posts_array['POSTEDCOLOUR'] = $postedcolour;
     $posts_array['BASEAMOUNT'] = main::s($pack_monthly, " Post");
     $posts_array['COUPONTOTAL'] = main::s($coupon_total, " Post");
     $posts_array['USERPOSTED'] = main::s(str_replace("-", "−", $total_posts), " Post");
     $posts_array['TOTALAMOUNT'] = main::s($balance, " Post");
     echo style::replaceVar("tpl/client/coupons/posts.tpl", $posts_array);
 }
Esempio n. 11
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     $client = $dbh->client($_SESSION['cuser']);
     $edit_account_array['USER'] = $client['user'];
     $edit_account_array['EMAIL'] = $client['email'];
     $edit_account_array['DOMAIN'] = $client['domain'];
     $edit_account_array['FIRSTNAME'] = $client['firstname'];
     $edit_account_array['LASTNAME'] = $client['lastname'];
     $edit_account_array['ADDRESS'] = $client['address'];
     $edit_account_array['CITY'] = $client['city'];
     $edit_account_array['STATE'] = $client['state'];
     $edit_account_array['ZIP'] = $client['zip'];
     $edit_account_array['PHONE'] = $client['phone'];
     $edit_account_array['TZADJUST'] = main::tzlist($client['tzadjust']);
     $edit_account_array['DISP'] = "<div>";
     $edit_account_array['COUNTRY'] = main::countries(1, $client['country']) . '<a title="Your country." class="tooltip"><img src="<ICONDIR>information.png" /></a>';
     if ($_POST) {
         if (!check::email($postvar['email'], $_SESSION['cuser'])) {
             main::errors("Your email is the wrong format!");
         }
         if (!check::state($postvar['state'])) {
             main::errors("Please enter a valid state!");
         }
         if (!check::address($postvar['address'])) {
             main::errors("Please enter a valid address!");
         }
         if (!check::phone($postvar['phone'])) {
             main::errors("Please enter a valid phone number!");
         }
         if (!check::zip($postvar['zip'])) {
             main::errors("Please enter a valid zip/postal code!");
         }
         if (!check::city($postvar['city'])) {
             main::errors("Please enter a valid city!");
         }
         if (!check::firstname($postvar['firstname'])) {
             main::errors("Please enter a valid first name!");
         }
         if (!check::lastname($postvar['lastname'])) {
             main::errors("Please enter a valid time last name!");
         }
         if (!main::errors()) {
             if ($postvar['country']) {
                 $country_q = "";
             }
             $users_update = array("email" => $postvar['email'], "state" => $postvar['state'], "address" => $postvar['address'], "phone" => $postvar['phone'], "zip" => $postvar['zip'], "city" => $postvar['city'], "tzadjust" => $postvar['tzones'], "firstname" => $postvar['firstname'], "lastname" => $postvar['lastname'], "country" => $postvar['country']);
             $dbh->update("users", $users_update, array("id", "=", $_SESSION['cuser']));
             if ($postvar['change']) {
                 $client = $dbh->client($_SESSION['cuser']);
                 if (crypto::passhash($postvar['currentpass'], $client['salt']) == $client['password']) {
                     if ($postvar['newpass'] === $postvar['cpass']) {
                         $cmd = main::changeClientPassword($_SESSION['cuser'], $postvar['newpass']);
                         if ($cmd === true) {
                             main::errors("Details updated!");
                         } else {
                             main::errors((string) $cmd);
                         }
                     } else {
                         main::errors("Your passwords don't match!");
                     }
                 } else {
                     main::errors("Your current password is incorrect.");
                 }
             } else {
                 $edit_account_array['DISP'] = "<div style=\"display:none;\">";
                 main::errors("Details updated!");
             }
         }
     }
     echo style::replaceVar("tpl/client/edit-account.tpl", $edit_account_array);
 }
Esempio n. 12
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     $upackinfo = main::uidtopack();
     $currentpack = $upackinfo['user_data']['pid'];
     $packsid = $postvar['packs'];
     if (!$packsid) {
         $packsid = $getvar['package'];
     }
     unset($where);
     if (is_numeric($packsid)) {
         $where[] = array("id", "=", $packsid, "AND");
     } else {
         $where[] = array("is_hidden", "=", "0", "AND");
     }
     $where[] = array("is_disabled", "=", "0", "AND");
     $where[] = array("id", "!=", $currentpack);
     $packages_order[] = array("type", "ASC");
     $packages_order[] = array("name", "ASC");
     $packages_query = $dbh->select("packages", $where, $packages_order, 0, 1);
     $upgrade_array['PACK'] = "";
     while ($packages_data = $dbh->fetch_array($packages_query)) {
         $additional = type::additional($packages_data['id']);
         $monthly = $additional['monthly'];
         $signup = $additional['signup'];
         unset($info);
         if ($packages_data['type'] == "p2h") {
             $info = "[Signup Posts: " . $signup . ", Monthly Posts: " . $monthly . "] ";
             $contribution = "<strong>Signup Posts:</strong> " . $signup . "<br><strong>Monthly Posts:</strong> " . $monthly;
         } elseif ($packages_data['type'] == "paid") {
             $info = "[" . main::money($monthly) . "] ";
             $contribution = main::money($monthly);
         } else {
             $contribution = "Free";
         }
         $packages[] = array("[" . $packages_data['type'] . "] " . $info . $packages_data['name'], $packages_data['id']);
         if ($packsid && $packsid == $packages_data['id']) {
             $prorate = upgrade::prorate($packages_data['id'], $postvar['coupon']);
             $package_array['DISABLED'] = "";
             if ($prorate == "inelegible") {
                 main::errors("You are currently not elegible for the plan selected because you do not have enough posts.<br><br>");
                 $package_array['DISABLED'] = "disabled";
             }
             if ($prorate == "owe") {
                 main::errors("You have outstanding charges on your account and can only upgrade your paid package.  Your charges are outstanding!  Keep up the good work.  lol<br><br>");
                 $package_array['DISABLED'] = "disabled";
             }
             if ($prorate == "oweposts") {
                 main::errors("You still owe your required monthly posts and can only upgrade to a paid plan until you finish your posting quota.  Our forum is a lot of fun, so come join us!  =)<br><br>");
                 $package_array['DISABLED'] = "disabled";
             }
             if ($prorate == "next" || $prorate == "check next") {
                 main::errors("If you choose this package, you'll be upgraded at the start of your next billing cycle.  If you do not wish to wait, please contact us.<br><br>");
                 $next_month = 1;
             }
             if (is_numeric($prorate) && $prorate > 0) {
                 $contribution .= " (You pay only <font color = '#FF0055'>" . main::money($prorate) . "</font> more today to upgrade.)";
             }
             if ($prorate == "check" || $prorate == "check next" || $prorate == "check now") {
                 $fuser = $postvar['fuser'];
                 $fpass = $postvar['fpass'];
                 $forum_credentials_array['FUSER'] = $fuser;
                 $forum_credentials_array['FPASS'] = $fpass;
                 $package_array['FORUMINFO'] = style::replaceVar("tpl/upgrade/forum-credentials.tpl", $forum_credentials_array);
             } else {
                 if ($packages_data['type'] == "p2h") {
                     $fuser = $upackinfo['uadditional']['fuser'];
                     $fpass = $upackinfo['uadditional']['fpass'];
                     $no_fcheck = 1;
                 }
                 $package_array['FORUMINFO'] = "";
             }
             $coupon_entry_array['COUPCODE'] = "";
             $coupon_entry_array['COUPTEXT'] = "";
             $coupon_entry_array['COUPCODEVALID'] = "";
             if ($packages_data['type'] == "p2h" && $prorate != "owe") {
                 //Paid users can enter them when they pay the invoice and free users don't need coupons.
                 $coupcode = $postvar['coupon'];
                 $validcoupon = $postvar['validcoupon'];
                 if ($postvar['addcoupon']) {
                     $uname = main::uname($_SESSION['cuser']);
                     if ($coupcode) {
                         $response = coupons::validate_coupon($coupcode, "orders", $uname, $packsid);
                         if ($response) {
                             $coup_data = coupons::coupon_data($coupcode);
                             $discount = $coup_data['p2hinitdisc'];
                             $multi_coupons = $dbh->config("multicoupons");
                             if ($multi_coupons) {
                                 $discount = $discount + upgrade::get_init_discount();
                             }
                             $total_posts = coupons::totalposts($_SESSION['cuser'], $packages_data['id']) + $discount;
                             if ($total_posts < $signup) {
                                 $error = 1;
                                 main::errors("You are currently not elegible for the plan selected because you do not have enough posts.<br><br>");
                                 $package_array['DISABLED'] = "disabled";
                                 $coupon_entry_array['COUPCODEVALID'] = "";
                             } else {
                                 $prorate = upgrade::prorate($packages_data['id'], $coupcode);
                                 if ($prorate == "next" || $prorate == "check next" || $prorate == "inelegible") {
                                     //We know they're eligible or they wouldn't be at this stage.  It just doesn't check existing coupons.
                                     main::errors("If you choose this package, you'll be upgraded at the start of your next billing cycle.  If you do not wish to wait, please contact us.<br><br>");
                                     $next_month = 1;
                                 } else {
                                     unset($_SESSION['errors']);
                                 }
                                 $package_array['DISABLED'] = "";
                                 $coupon_entry_array['COUPCODEVALID'] = $coupcode;
                             }
                             $coupon_entry_array['COUPTEXT'] = $response;
                             $coupon_entry_array['COUPCODE'] = $coupcode;
                         } else {
                             $coupon_entry_array['COUPTEXT'] = "<font color = '#FF0055'>The code entered was invalid.</font>";
                             $coupon_entry_array['COUPCODEVALID'] = "invalid";
                         }
                     } else {
                         $coupon_entry_array['COUPTEXT'] = "<font color = '#FF0055'>The code entered was invalid.</font>";
                         $coupon_entry_array['COUPCODEVALID'] = "invalid";
                     }
                 } else {
                     $coupon_entry_array['COUPTEXT'] = "";
                     $coupon_entry_array['COUPCODE'] = $coupcode;
                     $coupon_entry_array['COUPCODEVALID'] = $validcoupon;
                 }
                 $package_array['COUPONS'] = style::replaceVar("tpl/upgrade/coupon-entry.tpl", $coupon_entry_array);
             } else {
                 $package_array['COUPONS'] = "";
             }
             $package_array['CONTRIBUTION'] = $contribution;
             $package_array['PACKID'] = $packages_data['id'];
             $package_array['PACKNAME'] = $packages_data['name'];
             $package_array['PACKDESC'] = $packages_data['description'];
             $package_array['ADMIN'] = $packages_data['admin'] == "1" ? "Yes" : "No";
             $package_array['RESELLER'] = $packages_data['reseller'] == "1" ? "Yes" : "No";
             $package_array['SERVER'] = $packages_data['server'] != $upackinfo['packages']['server'] ? "Yes" : "No";
             $package_array['TYPE'] = $packages_data['type'] == "p2h" ? strtoupper($packages_data['type']) : ucfirst($packages_data['type']);
             if ($postvar['submitchange']) {
                 //Someone cheated and modified the code to re-enable the button.  This stops all that.
                 if ($package_array['DISABLED'] == "disabled") {
                     main::redirect("?page=upgrade");
                     return;
                 }
                 if ((!$fuser || !$fpass) && $packages_data['type'] == "p2h" && !$no_fcheck) {
                     $error = 1;
                     main::errors("Please enter your forum username and password to continue.<br><br>");
                 }
                 if ($fuser && $fpass && $packages_data['type'] == "p2h" && !$no_fcheck) {
                     $p2h = $instance->packtypes["p2h"];
                     $response = $p2h->checkSignup($fuser, $fpass, $postvar['packs'], $postvar['validcoupon']);
                     switch ($response) {
                         case "3":
                             $error = 1;
                             main::errors("The username, " . $fuser . ", does not exist.<br><br>");
                             break;
                         case "4":
                             $error = 1;
                             main::errors("Invalid password.<br><br>");
                             break;
                         default:
                             //We add this now so the post checks can use it and it also tacks it to the user's account for future reference.
                             $new_additional = "fuser="******",fpass=0";
                             $dbh->update("users", array("additional" => $new_additional), array("id", "=", $upackinfo['user_data']['id']), "1");
                             break;
                     }
                 }
                 if (!$error) {
                     if ($validcoupon && $validcoupon != "invalid") {
                         $coup_data = coupons::coupon_data($validcoupon);
                         $discount = $coup_data['p2hinitdisc'];
                         $db_coupcode = $validcoupon;
                     }
                     $multi_coupons = $dbh->config("multicoupons");
                     if ($multi_coupons) {
                         $discount = $discount + upgrade::get_init_discount();
                     }
                     if ($packages_data['type'] == "p2h") {
                         $total_posts = coupons::totalposts($_SESSION['cuser'], $packages_data['id']) + $discount;
                         if ($total_posts < $signup) {
                             $error = 1;
                             main::errors("You are currently not elegible for the plan selected because you do not have enough posts.<br><br>");
                         }
                     }
                     if (!$error) {
                         //The user is elegible to upgrade and all checks have passed.
                         if ($packages_data['admin']) {
                             $admin = 1;
                         }
                         if ($packages_data['server'] != $upackinfo['packages']['server']) {
                             $different_server = 1;
                         }
                         //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.
                         //
                         if ($next_month) {
                             $flags = "1";
                             if ($admin) {
                                 $flags = "2";
                                 if ($different_server) {
                                     $flags = "3";
                                 }
                             } else {
                                 if ($different_server) {
                                     $flags = "4";
                                 }
                             }
                         } else {
                             $flags = "0";
                             if ($admin) {
                                 $flags = "5";
                                 if ($different_server) {
                                     $flags = "6";
                                 }
                             } else {
                                 if ($different_server) {
                                     $flags = "7";
                                 }
                             }
                         }
                         $pending_upgrade = $dbh->select("upgrade", array("uid", "=", $_SESSION['cuser']));
                         //When the upgrade is finished, the entry is removed.
                         if ($pending_upgrade['id']) {
                             $upgrade_update = array("uid" => $_SESSION['cuser'], "newpack" => $packsid, "flags" => $flags, "created" => time(), "coupcode" => $db_coupcode);
                             $dbh->update("upgrade", $upgrade_update, array("id", "=", $pending_upgrade['id']), "1");
                         } else {
                             $upgrade_insert = array("uid" => $_SESSION['cuser'], "newpack" => $packsid, "flags" => $flags, "created" => time(), "coupcode" => $db_coupcode);
                             $dbh->insert("upgrade", $upgrade_insert);
                         }
                         $pending_upgrade = $dbh->select("upgrade", array("uid", "=", $_SESSION['cuser']));
                         $response = upgrade::do_upgrade($pending_upgrade['id'], "Init");
                         if ($response === false) {
                             echo "Your upgrade could not be completed as dialed.  Please check with your admin and try your upgrade again later.  The following tones are for the deaf community in hopes that they'll be able to hear again.  BEEEEEEEEEEEEEEEEEEEEEEEEP!!!!!!!!";
                         } else {
                             echo $response;
                         }
                         return;
                     }
                 }
             }
         }
     }
     if ($packsid) {
         $upgrade_array['PACK'] = style::replaceVar("tpl/upgrade/package.tpl", $package_array);
     } else {
         $select_package_array['PACKS'] = main::dropDown("packs", $packages, '', 0);
         $upgrade_array['PACK'] = style::replaceVar("tpl/upgrade/select-package.tpl", $select_package_array);
     }
     echo style::replaceVar("tpl/upgrade/upgrade.tpl", $upgrade_array);
     $page_shown = 1;
     //The page doesn't show if they refresh it after the upgrade since the loop checks if they're upgrading to the same package they are on and fails if they are.
     if (!$page_shown) {
         main::redirect("?page=upgrade");
     }
 }
Esempio n. 13
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     switch ($getvar['sub']) {
         default:
             if ($_POST) {
                 $no_check_fields = array("last_tld_update", "otherdefault");
                 check::empty_fields($no_check_fields);
                 if ($postvar['url'] && substr($postvar['url'], -1, 1) != "/") {
                     $postvar['url'] = $postvar['url'] . "/";
                 }
                 if ($postvar['default_page'] && $postvar['default_page'] == "-other-") {
                     if (!$postvar['otherdefault']) {
                         main::errors("Please enter the default directory to redirect to.");
                     } else {
                         if (is_dir("../" . $postvar['otherdefault'])) {
                             $postvar['default_page'] = $postvar['otherdefault'];
                         } else {
                             main::errors("The default directory entered does not exist.");
                         }
                     }
                 }
                 if ($postvar['last_tld_update'] == "never") {
                     $dbh->updateConfig("last_tld_update", "never");
                 } else {
                     unset($postvar['last_tld_update']);
                 }
                 if (!main::errors()) {
                     foreach ($postvar as $key => $value) {
                         $dbh->updateConfig($key, $value);
                     }
                     main::errors("Settings Updated!");
                 }
             }
             $general_settings_array['NAME'] = $dbh->config("name");
             $general_settings_array['URL'] = $dbh->config("url");
             $general_settings_array['RECURL'] = $_SERVER['HTTP_HOST'];
             $values[] = array("Order Form", "order");
             $values[] = array("Client Area", "client");
             $values[] = array("Knowledge Base", "support");
             $values[] = array("Other", "-other-");
             if ($dbh->config('default_page') != ADMINDIR && $dbh->config('default_page') != "order" && $dbh->config('default_page') != "client") {
                 $general_settings_array['DEFAULT_PAGE'] = main::dropDown("default_page", $values, "-other-");
                 $general_settings_array['OTHERDEFAULT'] = $dbh->config('default_page');
             } else {
                 $general_settings_array['OTHERDEFAULT'] = "";
                 $general_settings_array['DEFAULT_PAGE'] = main::dropDown('default_page', $values, $dbh->config('default_page'));
             }
             $IANA_queue_values[] = array("No", "");
             $IANA_queue_values[] = array("Yes", "never");
             $general_settings_array['QUEUE_IANA'] = main::dropDown("last_tld_update", $IANA_queue_values, $dbh->config("last_tld_update"));
             $general_settings_array['TLD_UPDATE_DAYS'] = $dbh->config("tld_update_days");
             echo style::replaceVar("tpl/admin/settings/general-settings.tpl", $general_settings_array);
             break;
         case "security":
             //security settings
             if ($_POST) {
                 check::empty_fields();
                 if (!check::email($postvar['email_for_cron'], 0, 0, 1)) {
                     main::errors("Please verify that the email you're using for cron output is of a valid format.");
                 }
                 if (!main::errors()) {
                     foreach ($postvar as $key => $value) {
                         $dbh->updateConfig($key, $value);
                     }
                     main::errors("Settings Updated!");
                 }
             }
             $values[] = array("Yes", "1");
             $values[] = array("No", "0");
             $security_settings_array['SHOW_VERSION_ID'] = main::dropDown("show_version_id", $values, $dbh->config("show_version_id"));
             $security_settings_array['SHOW_PAGE_GENTIME'] = main::dropDown("show_page_gentime", $values, $dbh->config("show_page_gentime"));
             $security_settings_array['SHOW_FOOTER'] = main::dropDown("show_footer", $values, $dbh->config("show_footer"));
             $security_settings_array['SHOW_ERRORS'] = main::dropDown("show_errors", $values, $dbh->config("show_errors"));
             $security_settings_array['EMAIL_ON_CRON'] = main::dropDown("emailoncron", $values, $dbh->config("emailoncron"));
             $security_settings_array['EMAIL_FOR_CRON'] = $dbh->config("email_for_cron");
             $security_settings_array['SESSION_TIMEOUT'] = $dbh->config("session_timeout");
             echo style::replaceVar("tpl/admin/settings/security-settings.tpl", $security_settings_array);
             break;
         case "tos":
             if ($_POST) {
                 check::empty_fields();
                 if (!main::errors()) {
                     $dbh->updateConfig("tos", $postvar['tos']);
                     main::errors("Settings Updated!");
                 }
             }
             $tos_array['TOS'] = $dbh->config("tos");
             echo style::replaceVar("tpl/admin/settings/tos.tpl", $tos_array);
             break;
         case "signup":
             if ($_POST) {
                 check::empty_fields();
                 if (!main::errors()) {
                     foreach ($postvar as $key => $value) {
                         $dbh->updateConfig($key, $value);
                     }
                     main::errors("Settings Updated!");
                 }
             }
             $values[] = array("Enabled", "1");
             $values[] = array("Disabled", "0");
             $signup_settings_array['MULTIPLE'] = main::dropDown("multiple", $values, $dbh->config("multiple"));
             $signup_settings_array['TLDONLY'] = main::dropDown("tldonly", $values, $dbh->config("tldonly"));
             $signup_settings_array['GENERAL'] = main::dropDown("general", $values, $dbh->config("general"));
             $signup_settings_array['MESSAGE'] = $dbh->config("message");
             echo style::replaceVar("tpl/admin/settings/signup-settings.tpl", $signup_settings_array);
             break;
         case "client":
             if ($_POST) {
                 $no_check_fields = array("alerts");
                 check::empty_fields($no_check_fields);
                 if (!main::errors()) {
                     foreach ($postvar as $key => $value) {
                         $dbh->updateConfig($key, $value);
                     }
                     main::errors("Settings Updated!");
                 }
             }
             $values[] = array("Enabled", "1");
             $values[] = array("Disabled", "0");
             $client_area_settings_array['DELACC'] = main::dropDown("delacc", $values, $dbh->config("delacc"));
             $client_area_settings_array['ENABLED'] = main::dropDown("cenabled", $values, $dbh->config("cenabled"));
             $client_area_settings_array['ALERTS'] = $dbh->config("alerts");
             echo style::replaceVar("tpl/admin/settings/client-area-settings.tpl", $client_area_settings_array);
             break;
         case "support":
             if ($_POST) {
                 check::empty_fields();
                 if (!main::errors()) {
                     foreach ($postvar as $key => $value) {
                         $dbh->updateConfig($key, $value);
                     }
                     main::errors("Settings Updated!");
                 }
             }
             $values[] = array("Enabled", "1");
             $values[] = array("Disabled", "0");
             $support_settings_array['ENABLED'] = main::dropDown("senabled", $values, $dbh->config("senabled"));
             $support_settings_array['MESSAGE'] = $dbh->config("smessage");
             echo style::replaceVar("tpl/admin/settings/support-settings.tpl", $support_settings_array);
             break;
         case "email":
             if ($_POST) {
                 check::empty_fields();
                 if (!main::errors()) {
                     foreach ($postvar as $key => $value) {
                         $dbh->updateConfig($key, $value);
                     }
                     main::errors("Settings Updated!");
                 }
             }
             $values[] = array("PHP Mail", "php");
             $values[] = array("SMTP", "smtp");
             $email_settings_array['METHOD'] = main::dropDown("emailmethod", $values, $dbh->config("emailmethod"), 0);
             $email_settings_array['EMAILFROM'] = $dbh->config("emailfrom");
             $email_settings_array['SMTP_HOST'] = $dbh->config("smtp_host");
             $email_settings_array['SMTP_USER'] = $dbh->config("smtp_user");
             $email_settings_array['SMTP_PASS'] = $dbh->config("smtp_password");
             $email_settings_array['SMTP_PORT'] = $dbh->config("smtp_port");
             echo style::replaceVar("tpl/admin/settings/email-settings.tpl", $email_settings_array);
             break;
     }
 }
Esempio n. 14
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);
         }
     }
 }
Esempio n. 15
0
 private function ChangePassword($client)
 {
     global $dbh, $postvar, $getvar, $instance;
     $change_password_array['MSG'] = "This will change the user's password in THT and the control panel.<br><br>";
     if ($_POST) {
         if (empty($postvar['passwd'])) {
             main::errors('A password was not provided.');
         } else {
             $command = main::changeClientPassword($client['id'], $postvar['passwd']);
             if ($command === true) {
                 main::errors('Password changed!');
             } else {
                 main::errors($command);
             }
         }
     }
     $clientview_array['BOX'] = "";
     $clientview_array['CONTENT'] = style::replaceVar("tpl/admin/clients/change-password.tpl", $change_password_array);
     return $clientview_array;
 }
Esempio n. 16
0
 public function validate_admin_form($add_edit)
 {
     global $dbh, $postvar, $getvar, $instance;
     $no_check_fields = array("monthsgoodfor", "expiredate", "limitedcoupons", "unlimitedcoupons", "neverexpire", "username", "paiddisc", "p2hinitdisc", "p2hmonthlydisc", "coupid");
     check::empty_fields($no_check_fields);
     if (!main::errors()) {
         $postvar = $postvar;
         $coupon_code_check = self::coupon_data($postvar['coupcode']);
         if (!empty($coupon_code_check) && $add_edit == 'add') {
             $error = "The coupon code already exists in the database.<br>";
         }
         if (is_numeric($postvar['coupcode'])) {
             $error = "The coupon code cannot be fully numeric.<br>";
         }
         if ($postvar['unlimitedcoupons']) {
             $postvar['limitedcoupons'] = "";
         } else {
             if (!main::isint($postvar['limitedcoupons'])) {
                 $error = "Please enter the number of times the coupon may be used or check unlimited.<br>";
             } elseif ($postvar['limitedcoupons'] <= 0) {
                 $error = "Please enter a number greater than 0 for the number of times the coupon may be used or check unlimited.<br>";
             }
         }
         if ($postvar['goodfor'] == 'months' && (!$postvar['monthsgoodfor'] || !main::isint($postvar['monthsgoodfor']))) {
             $error .= "Please specify the number of months the coupon is good for when applied.  The months must not be specified as a decimal.<br>";
         } else {
             if ($postvar['goodfor'] != 'months') {
                 unset($postvar['monthsgoodfor']);
             }
         }
         if (!$postvar['expiredate'] && !$postvar['neverexpire']) {
             $error .= "Please enter an expiration date or check the box for never expire.<br>";
         }
         if (!$postvar['packages'] && !$postvar['allpacks']) {
             $error .= "Please choose packages for this coupon or check the box for all packages.<br>";
         }
         if ($postvar['expiredate'] && !$postvar['neverexpire']) {
             $date_blowed_up = explode("/", $postvar['expiredate']);
             if (count($date_blowed_up) != 3 || !main::isint($date_blowed_up[0]) || !main::isint($date_blowed_up[1]) || !main::isint($date_blowed_up[2]) || strlen($date_blowed_up[0]) != 2 || strlen($date_blowed_up[1]) != 2 || strlen($date_blowed_up[2]) != 4 || $date_blowed_up[0] > 12 || $date_blowed_up[1] > 31) {
                 $error .= "Please enter a valid expiration date in the format MM/DD/YYYY or check the box to have the coupon never expire.<br>";
             }
         }
         if ($postvar['userselect'] == 'newuser' && !$postvar['username']) {
             $error .= "Please enter the new user's username who should be allowed to use this coupon.<br>";
         }
         if (!$postvar['paiddisc'] && !$postvar['p2hinitdisc'] && !$postvar['p2hmonthlydisc']) {
             $error .= "You must enter the paid discount amount or you must enter the P2H initial discount and/or the P2H monthly discount.<br>";
         } else {
             if (!$postvar['paiddisc']) {
                 $postvar['paiddisc'] = "0";
                 $postvar['paidtype'] = "0";
             }
             if (!$postvar['p2hinitdisc']) {
                 $postvar['p2hinitdisc'] = "0";
                 $postvar['p2hinittype'] = "0";
             }
             if (!$postvar['p2hmonthlydisc']) {
                 $postvar['p2hmonthlydisc'] = "0";
                 $postvar['p2hmonthlytype'] = "0";
             }
             $postvar['paiddisc'] = str_replace(array(" ", ","), array("", "."), $postvar['paiddisc']);
             if (!is_numeric($postvar['paiddisc'])) {
                 $error .= "The paid discount amount must be given as a number for paid packages.  (Ex. 1.99)<br>";
             }
             if (!main::isint($postvar['p2hinitdisc']) || !main::isint($postvar['p2hmonthlydisc'])) {
                 $error .= "The P2H post discounts must be given as a whole number for p2h packages.<br>";
             }
         }
         if (!$error) {
             if ($postvar['neverexpire']) {
                 $postvar['expiredate'] = "99/99/9999";
             }
             if ($postvar['userselect'] == 'newuser') {
                 $postvar['userselect'] = $postvar['username'];
             }
             if ($postvar['allpacks']) {
                 $postvar['packages'] = "all";
                 $packages_query = $dbh->select("packages", array("type", "!=", "free"), 0, 0, 1);
                 while ($packages_data = $dbh->fetch_array($packages_query)) {
                     $packtype .= $packages_data['type'] . ",";
                 }
             } else {
                 foreach ($postvar['packages'] as $key => $val) {
                     $packs .= $val . ",";
                     $packtype .= type::packagetype($val) . ",";
                 }
                 $postvar['packages'] = substr($packs, 0, -1);
             }
             if (substr_count($packtype, "paid") && $postvar['paiddisc'] == "0") {
                 $error .= "You selected at least one paid package.  Please enter a discount amount greater than 0 for the paid discount field.<br>";
             }
             if (substr_count($packtype, "p2h") && $postvar['p2hinitdisc'] == "0" && $postvar['p2hmonthlydisc'] == "0") {
                 $error .= "You selected at least one p2h package.  Please enter a discount amount greater than 0 for at least one of the post discount fields.<br>";
             }
             if (substr_count($packtype, "paid") && !substr_count($packtype, "p2h")) {
                 $postvar['p2hinitdisc'] = "0";
                 $postvar['p2hmonthlydisc'] = "0";
                 $postvar['p2hinittype'] = "0";
                 $postvar['p2hmonthlytype'] = "0";
             }
             if (!substr_count($packtype, "paid") && substr_count($packtype, "p2h")) {
                 $postvar['paiddisc'] = "0";
                 $postvar['paidtype'] = "0";
             }
             if (!$error) {
                 if ($add_edit == "add") {
                     $coupons_insert = array("paidtype" => $postvar['paidtype'], "p2hinittype" => $postvar['p2hinittype'], "p2hmonthlytype" => $postvar['p2hmonthlytype'], "limited" => $postvar['limitedcoupons'], "coupname" => $postvar['name'], "shortdesc" => $postvar['shortdesc'], "coupcode" => $postvar['coupcode'], "area" => $postvar['area'], "goodfor" => $postvar['goodfor'], "monthsgoodfor" => $postvar['monthsgoodfor'], "expiredate" => $postvar['expiredate'], "user" => $postvar['userselect'], "packages" => $postvar['packages'], "paiddisc" => $postvar['paiddisc'], "p2hinitdisc" => $postvar['p2hinitdisc'], "p2hmonthlydisc" => $postvar['p2hmonthlydisc']);
                     $dbh->insert("coupons", $coupons_insert);
                     $error = "The coupon has been added successfully!";
                 } else {
                     $coupons_update = array("paidtype" => $postvar['paidtype'], "p2hinittype" => $postvar['p2hinittype'], "p2hmonthlytype" => $postvar['p2hmonthlytype'], "limited" => $postvar['limitedcoupons'], "coupname" => $postvar['name'], "shortdesc" => $postvar['shortdesc'], "coupcode" => $postvar['coupcode'], "area" => $postvar['area'], "goodfor" => $postvar['goodfor'], "monthsgoodfor" => $postvar['monthsgoodfor'], "expiredate" => $postvar['expiredate'], "user" => $postvar['userselect'], "packages" => $postvar['packages'], "paiddisc" => $postvar['paiddisc'], "p2hinitdisc" => $postvar['p2hinitdisc'], "p2hmonthlydisc" => $postvar['p2hmonthlydisc']);
                     $dbh->update("coupons", $coupons_update, array("id", "=", $add_edit), "1");
                     $error = "The coupon has been edited successfully!";
                 }
             }
         }
     }
     return $error;
 }
Esempio n. 17
0
 public function acpPage()
 {
     global $dbh, $postvar, $getvar, $instance;
     if ($_POST) {
         check::empty_fields(array("password", "paypalsandemail"));
         if (!main::errors()) {
             if (is_numeric($postvar['susdays']) && is_numeric($postvar['termdays'])) {
                 $dbh->updateConfig("suspensiondays", $postvar['susdays']);
                 $dbh->updateConfig("terminationdays", $postvar['termdays']);
                 $dbh->updateConfig("currency", $postvar['currency']);
                 $dbh->updateConfig("currency_format", $postvar['currency_format']);
                 $dbh->updateConfig("paypalemail", $postvar['paypalemail']);
                 $dbh->updateConfig("paypalmode", $postvar['paypalmode']);
                 $dbh->updateConfig("paypalsandemail", $postvar['paypalsandemail']);
                 main::errors("Values have been updated!");
             } else {
                 main::errors("Please enter a valid value!");
             }
         }
     }
     $currency_values[] = array("Pound Sterling", "GBP");
     $currency_values[] = array("US Dollars", "USD");
     $currency_values[] = array("Australian Dollars", "AUD");
     $currency_values[] = array("Canadian Dollars", "CAD");
     $currency_values[] = array("Euros", "EUR");
     $currency_values[] = array("Yen", "JPY");
     $currency_values[] = array("New Zealand Dollar", "NZD");
     $currency_values[] = array("Swiss Franc", "CHF");
     $currency_values[] = array("Hong Kong Dollar", "HKD");
     $currency_values[] = array("Singapore Dollar", "SGD");
     $currency_values[] = array("Swedish Krona", "SEK");
     $currency_values[] = array("Danish Krone", "DKK");
     $currency_values[] = array("Polish Zloty", "PLN");
     $currency_values[] = array("Norwegian Krone", "NOK");
     $currency_values[] = array("Hungarian Forint", "HUF");
     $currency_values[] = array("Czech Koruna", "CZK");
     $currency_values[] = array("Israeli Shekel", "ILS");
     $currency_values[] = array("Mexican Peso", "MXN");
     $paypal_values[] = array("Live", "live");
     $paypal_values[] = array("Sandbox", "sandbox");
     $currency_format_values[] = array("1,000.99", ".");
     $currency_format_values[] = array("1 000,99", ",");
     $paid_configuration_array['CURRENCY'] = main::dropDown("currency", $currency_values, $dbh->config("currency"));
     $paid_configuration_array['CURRENCY_FORMAT'] = main::dropDown("currency_format", $currency_format_values, $dbh->config("currency_format"));
     $paid_configuration_array['PAYPALMODE'] = main::dropDown("paypalmode", $paypal_values, $dbh->config("paypalmode"));
     $paid_configuration_array['PAYPALSANDEMAIL'] = $dbh->config("paypalsandemail");
     $paid_configuration_array['SUSDAYS'] = $dbh->config("suspensiondays");
     $paid_configuration_array['TERDAYS'] = $dbh->config("terminationdays");
     $paid_configuration_array['PAYPALEMAIL'] = $dbh->config("paypalemail");
     echo style::replaceVar("tpl/admin/paid-configuration.tpl", $paid_configuration_array);
 }
Esempio n. 18
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     if (!automod::checkDir(INC . "/automod")) {
         main::errors("Please create the /includes/automod directory and make it writable.");
     }
     if (!automod::checkPerms(INC . "/automod")) {
         main::errors("Please make the /includes/automod directory writable.  (0777)");
     }
     switch ($getvar['sub']) {
         case "added":
             $mods_exist = $dbh->select("automod_mods", 0, array("mod_name", "ASC"));
             $mods_exist = $dbh->num_rows($mods_exist);
             if ($mods_exist > 0) {
                 if (is_numeric($getvar['view'])) {
                     $mod_vals = automod::module_data($getvar['view']);
                     if (automod::installed_tht_is_reworked()) {
                         $THT_VERS = $dbh->config("version") . " Reworked";
                     } else {
                         $THT_VERS = $dbh->config("version");
                     }
                     $mod_vals['mod_thtversion'] = str_replace("rework3d", "Reworked", strtolower($mod_vals['mod_thtversion']));
                     $mod_vals['mod_thtversion'] = str_replace("reworked", "Reworked", strtolower($mod_vals['mod_thtversion']));
                     $viewmod_array['ID'] = $mod_vals['id'];
                     $viewmod_array['NAME'] = $mod_vals['mod_name'];
                     $viewmod_array['MODVERSION'] = $mod_vals['mod_version'];
                     $viewmod_array['VERSION'] = $THT_VERS;
                     $viewmod_array['THTVERSION'] = $mod_vals['mod_thtversion'];
                     $viewmod_array['LICENSE'] = $mod_vals['mod_license'];
                     $viewmod_array['AUTHOR'] = $mod_vals['mod_author'];
                     $viewmod_array['SUPPORT'] = $mod_vals['mod_support'];
                     $viewmod_array['AUTHLINK'] = $mod_vals['mod_link'];
                     $viewmod_array['PROJWEB'] = $mod_vals['mod_projectpage'];
                     $viewmod_array['RECOMMENDATIONS'] = automod::recommendations();
                     $viewmod_array['DESCRIPTION'] = nl2br($mod_vals['mod_descrip']);
                     $viewmod_array['DIY'] = $mod_vals['mod_diy'];
                     echo style::replaceVar("tpl/automod/view-module.tpl", $viewmod_array);
                 } else {
                     $mod_query = $dbh->select("automod_mods", 0, array("mod_name", "ASC"));
                     while ($mod_vals = $dbh->fetch_array($mod_query)) {
                         $listmods_array['ID'] = $mod_vals['id'];
                         $listmods_array['NAME'] = $mod_vals['mod_name'];
                         unset($elipses);
                         if (strlen($mod_vals['mod_descrip']) > 250) {
                             $elipses = " <b>...</b>";
                         }
                         $listmods_array['DESCRIPTION'] = nl2br(htmlentities(substr($mod_vals['mod_descrip'], 0, 250)) . $elipses);
                         echo style::replaceVar("tpl/automod/list-modules.tpl", $listmods_array);
                     }
                 }
             } else {
                 echo "No modules installed.";
             }
             break;
         case "install":
             if ($getvar['install']) {
                 //Install a module
                 if ($getvar['confirm'] == '1') {
                     automod::completeinstall($getvar['install']);
                 } else {
                     automod::install_mod($getvar['install']);
                 }
             } elseif ($getvar['reminstall']) {
                 //Remove a module's directory
                 $reminstall = $getvar['reminstall'];
                 if ($postvar['confirm']) {
                     if ($postvar['yes']) {
                         automod::rmfulldir(INC . "/automod/" . $reminstall);
                         main::redirect("?page=automod&sub=install");
                     } else {
                         main::redirect("?page=automod&sub=install");
                     }
                 } else {
                     $warning_array['HIDDEN'] = "<input type = 'hidden' name = 'confirm' value = 'confirm'>";
                     echo style::replaceVar("tpl/warning.tpl", $warning_array);
                 }
             } else {
                 //Add a module to be installed
                 automod::processaddmod();
             }
             break;
         case "uninstall":
             $mods_exist = $dbh->select("automod_mods", 0, array("mod_name", "ASC"));
             $mods_exist = $dbh->num_rows($mods_exist);
             if ($mods_exist > 0) {
                 if (is_numeric($getvar['uninstall'])) {
                     if ($getvar['confirm'] == '1') {
                         if (!$postvar['remove'] && !$postvar['rename']) {
                             $mode = '1';
                         }
                         if ($postvar['remove'] && $postvar['rename']) {
                             $mode = '2';
                         }
                         if ($postvar['remove'] && !$postvar['rename']) {
                             $mode = '3';
                         }
                         if (!$postvar['remove'] && $postvar['rename']) {
                             $mode = '4';
                         }
                         automod::completeuninstall($getvar['uninstall'], $mode);
                     } else {
                         automod::uninstall_mod($getvar['uninstall']);
                     }
                 } else {
                     $mod_query = $dbh->select("automod_mods", 0, array("mod_name", "ASC"));
                     while ($mod_vals = $dbh->fetch_array($mod_query)) {
                         $listmods_array['ID'] = $mod_vals['id'];
                         $listmods_array['NAME'] = $mod_vals['mod_name'];
                         unset($elipses);
                         if (strlen($mod_vals['mod_descrip']) > 250) {
                             $elipses = " <b>...</b>";
                         }
                         $listmods_array['DESCRIPTION'] = nl2br(htmlentities(substr($mod_vals['mod_descrip'], 0, 250)) . $elipses);
                         echo style::replaceVar("tpl/automod/list-modules.tpl", $listmods_array);
                     }
                 }
             } else {
                 echo "No modules installed.";
             }
             break;
         case "updates":
             automod::updates_check();
             break;
     }
 }
Esempio n. 19
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     switch ($getvar['sub']) {
         default:
             if ($_POST['add']) {
                 $no_check_array = array("admin", "groupid", "sendwelcome", "welcomesubject", "welcomebody");
                 check::empty_fields($no_check_array);
                 $ZserverID = $postvar['server'];
                 unset($where);
                 $where[] = array("id", "=", $ZserverID, "AND");
                 $where[] = array("type", "=", "zpanel");
                 $servers_query = $dbh->select("servers", $where, 0, 0, 1);
                 if ($dbh->num_rows($servers_query) == 1) {
                     $zpanel_srv = 1;
                 }
                 //Hack to make sure the Group ID isn't 0 on ZPanel
                 if ($zpanel_srv && ($postvar["groupid"] == 0 || $postvar["backend"] == 0)) {
                     main::errors(" ZPanel server packages must include a Group ID for the package and the a backend package ID that's greater than 0. See the info bubbles for help.");
                 }
                 if ($postvar["monthly"] && !is_numeric($postvar["monthly"]) || $postvar["signup"] && !is_numeric($postvar["signup"])) {
                     main::errors("Please enter a positive number for the cost or posts fields.");
                 }
                 if (!main::errors()) {
                     $not_additional_array = array("add", "name", "backend", "description", "type", "server", "admin", "groupid", "sendwelcome", "welcomesubject", "welcomebody", $GLOBALS['csrf']['input-name']);
                     foreach ($postvar as $key => $value) {
                         if (!in_array($key, $not_additional_array)) {
                             if ($n) {
                                 $additional .= ",";
                             }
                             $additional .= $key . "=" . str_replace(array(" ", ","), array("", "."), $value);
                             $n++;
                         }
                     }
                     $packages_insert = array("name" => $postvar['name'], "backend" => $postvar['backend'], "description" => $postvar['description'], "type" => $postvar['type'], "server" => $postvar['server'], "admin" => $postvar['admin'], "is_hidden" => $postvar['hidden'], "is_disabled" => $postvar['disabled'], "additional" => $additional, "reseller" => $postvar['reseller'], "groupid" => $postvar['groupid'], "send_email" => $postvar['sendwelcome'], "email_subject" => $postvar['welcomesubject'], "email_body" => $postvar['welcomebody']);
                     $dbh->insert("packages", $packages_insert);
                     main::errors("Package has been added!<br>");
                 }
             }
             if ($_POST['packserver'] || $_POST['add']) {
                 $servers_data = $dbh->select("servers", array("id", "=", $postvar['server']), 0, "1");
                 $serverfile = server::createServer(0, $servers_data['type']);
                 $package_fields = $serverfile->acp_packages_form();
                 $add_package_array['TYPE_FORM'] = type::acpPadd($postvar['type']);
                 $add_package_array['TYPE'] = $postvar['type'];
                 $add_package_array['PACKAGES_FIELDS'] = $package_fields;
                 $add_package_array['SERVER'] = $postvar['server'];
                 echo style::replaceVar("tpl/admin/packages/add-package.tpl", $add_package_array);
                 break;
             }
             $servers_query = $dbh->select("servers");
             if ($dbh->num_rows($servers_query) == 0) {
                 echo "There are no servers, you need to add a server first!";
                 return;
             }
             while ($servers_data = $dbh->fetch_array($servers_query)) {
                 $values[] = array($servers_data['name'], $servers_data['id']);
             }
             $p2h_query = $dbh->select("p2h");
             $p2h_data = $dbh->num_rows($p2h_query);
             if ($p2h_data != "0") {
                 $package_server_array['P2HOPTION'] = '<option value="p2h">Post 2 Host</option>';
             } else {
                 $package_server_array['P2HOPTION'] == "";
             }
             $package_server_array['SERVER'] = main::dropDown("server", $values);
             echo "This will only add the package to THT, not create the package on the backend for you.<br><br>";
             echo style::replaceVar("tpl/admin/packages/package-server.tpl", $package_server_array);
             break;
         case "edit":
             if (isset($getvar['do'])) {
                 $packages_query = $dbh->select("packages", array("id", "=", $getvar['do']), 0, 0, 1);
                 if ($dbh->num_rows($packages_query) == 0) {
                     echo "That package doesn't exist!";
                 } else {
                     if ($_POST) {
                         $no_check_array = array("admin", "groupid", "sendwelcome", "welcomesubject", "welcomebody");
                         check::empty_fields($no_check_array);
                         $ZserverID = $postvar['server'];
                         unset($where);
                         $where[] = array("id", "=", $ZserverID, "AND");
                         $where[] = array("type", "=", "zpanel");
                         $servers_query = $dbh->select("servers", $where, 0, 0, 1);
                         if ($dbh->num_rows($servers_query) == 1) {
                             $zpanel_srv = 1;
                         }
                         //Hack to make sure the Group ID isn't 0 on ZPanel
                         if ($zpanel_srv && ($postvar["groupid"] == 0 || $postvar["backend"] == 0)) {
                             main::errors(" ZPanel server packages must include a Group ID for the package and the a backend package ID that's greater than 0. See the info bubbles for help.");
                         }
                         if ($postvar["monthly"] && !is_numeric($postvar["monthly"]) || $postvar["signup"] && !is_numeric($postvar["signup"])) {
                             main::errors("Please enter a positive number for the cost or posts fields.");
                         }
                         if (!main::errors()) {
                             $not_additional_array = array("edit", "name", "backend", "description", "type", "server", "admin", "groupid", "sendwelcome", "welcomesubject", "welcomebody", $GLOBALS['csrf']['input-name']);
                             foreach ($postvar as $key => $value) {
                                 if (!in_array($key, $not_additional_array)) {
                                     if ($n) {
                                         $additional .= ",";
                                     }
                                     $additional .= $key . "=" . str_replace(array(" ", ","), array("", "."), $value);
                                     $n++;
                                 }
                             }
                             if ($postvar['sendwelcome'] && (!$postvar['welcomesubject'] || !$postvar['welcomebody'])) {
                                 $serverid = $postvar['server'];
                                 $server_type_data = $dbh->select("servers", array("id", "=", $serverid));
                                 $server_type = $server_type_data['type'];
                                 if ($server_type == "zpanel") {
                                     include INC . "/servers/" . $server_type . ".php";
                                     $server = new $server_type();
                                     $server_subject_def = server::email_subject;
                                     $server_body_def = server::email_body;
                                     if (!$postvar['welcomesubject']) {
                                         $postvar['welcomesubject'] = $server_subject_def;
                                     }
                                     if (!$postvar['welcomebody']) {
                                         $postvar['welcomebody'] = $server_body_def;
                                     }
                                 }
                             }
                             $packages_update = array("name" => $postvar['name'], "backend" => $postvar['backend'], "description" => $postvar['description'], "server" => $postvar['server'], "admin" => $postvar['admin'], "additional" => $additional, "reseller" => $postvar['reseller'], "is_hidden" => $postvar['hidden'], "is_disabled" => $postvar['disabled'], "type" => $postvar['type'], "groupid" => $postvar['groupid'], "send_email" => $postvar['sendwelcome'], "email_subject" => $postvar['welcomesubject'], "email_body" => $postvar['welcomebody']);
                             $dbh->update("packages", $packages_update, array("id", "=", $getvar['do']));
                             //Package edit complete.
                             main::done();
                         }
                     }
                     $packages_data = $dbh->fetch_array($packages_query);
                     $edit_package_array['BACKEND'] = $packages_data['backend'];
                     $edit_package_array['DESCRIPTION'] = $packages_data['description'];
                     $edit_package_array['NAME'] = $packages_data['name'];
                     $edit_package_array['URL'] = $dbh->config("url");
                     $edit_package_array['ID'] = $packages_data['id'];
                     if ($packages_data['admin'] == 1) {
                         $edit_package_array['ADMIN_CHECKED'] = 'checked="checked"';
                     } else {
                         $edit_package_array['ADMIN_CHECKED'] = "";
                     }
                     if ($packages_data['reseller'] == 1) {
                         $edit_package_array['RESELLER_CHECKED'] = 'checked="checked"';
                     } else {
                         $edit_package_array['RESELLER_CHECKED'] = "";
                     }
                     if ($packages_data['is_hidden'] == 1) {
                         $edit_package_array['HIDDEN_CHECKED'] = 'checked="checked"';
                     } else {
                         $edit_package_array['HIDDEN_CHECKED'] = "";
                     }
                     if ($packages_data['is_disabled'] == 1) {
                         $edit_package_array['DISABLED_CHECKED'] = 'checked="checked"';
                     } else {
                         $edit_package_array['DISABLED_CHECKED'] = "";
                     }
                     $serverfile = server::createServer($getvar['do']);
                     $package_fields = $serverfile->acp_packages_form($getvar['do']);
                     $edit_package_array['PACKAGES_FIELDS'] = $package_fields;
                     $p2h_query = $dbh->select("p2h");
                     $p2h_data = $dbh->num_rows($p2h_query);
                     $edit_package_array['TYPE'] = $packages_data['type'];
                     $additional = $packages_data['additional'];
                     $edit_package_array['TYPE_FORM'] = type::acpPedit($packages_data['type'], $additional, $packages_data['type']);
                     if ($packages_data['type'] == "p2h" && $p2h_data == "0") {
                         $edit_package_array['TYPE_FORM'] = "";
                     }
                     $servers_query = $dbh->select("servers");
                     while ($servers_data = $dbh->fetch_array($servers_query)) {
                         $values[] = array($servers_data['name'], $servers_data['id']);
                     }
                     $edit_package_array['SERVER'] = $packages_data['server'];
                     echo "This will only edit the package on THT, not edit the package on the backend for you.<br><br>";
                     echo style::replaceVar("tpl/admin/packages/edit-package.tpl", $edit_package_array);
                 }
             } else {
                 $packages_query = $dbh->select("packages");
                 if ($dbh->num_rows($packages_query) == 0) {
                     echo "There are no packages to edit!";
                 } else {
                     echo "<ERRORS>";
                     while ($packages_data = $dbh->fetch_array($packages_query)) {
                         echo main::sub("<strong>" . $packages_data['name'] . "</strong>", '<a href="?page=packages&sub=edit&do=' . $packages_data['id'] . '"><img src="' . URL . 'themes/icons/pencil.png"></a>');
                         $n++;
                     }
                 }
             }
             break;
         case "delete":
             if ($getvar['do']) {
                 $dbh->delete("packages", array("id", "=", $getvar['do']));
                 main::errors("Package has been Deleted.<br>");
             }
             $packages_query = $dbh->select("packages");
             if ($dbh->num_rows($packages_query) == 0) {
                 echo "There are no packages to delete.";
             } else {
                 echo "<ERRORS>This will only delete the package on THT, not delete the package on the backend for you.<br><br>";
                 while ($packages_data = $dbh->fetch_array($packages_query)) {
                     echo main::sub("<strong>" . $packages_data['name'] . "</strong>", '<a href="?page=packages&sub=delete&do=' . $packages_data['id'] . '"><img src="' . URL . 'themes/icons/delete.png"></a>');
                     $n++;
                 }
             }
             break;
     }
 }
Esempio n. 20
0
        }
        echo '<div align="center">' . main::table("Admin Area - Reset Password", style::replaceVar("tpl/admin/login/admin-password-reset.tpl"), "300px") . '</div>';
        echo style::get("footer.tpl");
    } else {
        define("SUB", "Login");
        define("INFO", "<b>Welcome to <NAME></b><br>" . SUB);
        if ($_POST) {
            // If user submitts form
            if (main::staffLogin($postvar['user'], $postvar['pass'])) {
                $queryString = $_SERVER["QUERY_STRING"];
                if ($queryString == "") {
                    $queryString = "page=home";
                }
                main::redirect(URL . ADMINDIR . "/?" . $queryString);
            } else {
                main::errors("Incorrect username or password!");
            }
        }
        echo style::get("header.tpl");
        echo '<div align="center">' . main::table("Admin Area - Login", style::replaceVar("tpl/admin/login/admin-login.tpl"), "300px") . '</div>';
        echo style::get("footer.tpl");
    }
} elseif ($_SESSION['logged']) {
    if (!$getvar['page']) {
        $getvar['page'] = "home";
    } elseif ($getvar['page'] == "logout") {
        session_destroy();
        main::redirect("?page=home");
    }
    $content = acp();
    echo style::get("header.tpl");
Esempio n. 21
0
 }
 if ($postvar['csub2'] || $postvar['csub']) {
     if (!check::domain($postvar['csub2'])) {
         main::errors(nl2br("Your domain is in the wrong format.  Domains must be alphanumerical and have a valid TLD.  (Domain suffix)"));
     } else {
         if (!ctype_alnum($postvar['csub'])) {
             main::errors(nl2br("Your chosen subdomain must be alphanumerical."));
         }
         $domain = $postvar['csub2'];
         $subdomain = $postvar['csub'];
     }
 }
 if (!check::extra_fields()) {
     main::errors(nl2br("The fields in step 4 contain invalid characters.  (>, <, or #)"));
 }
 if (main::errors()) {
     $order_form_array['ERRORS'] = style::replaceVar("tpl/order/errors.tpl", array()) . "<br><br>";
 } else {
     foreach ($postvar as $key => $value) {
         $key_exp = explode("_", $key);
         if ($key_exp[0] == "type") {
             if ($n) {
                 $additional .= ",";
             }
             if ($key == "type_fpass") {
                 $value = 0;
             }
             $additional .= $key_exp[1] . "=" . $value;
             $n++;
         }
     }
Esempio n. 22
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     if (is_numeric($getvar['view'])) {
         //Show the invoice
         unset($where);
         $where[] = array("uid", "=", $_SESSION['cuser'], "AND");
         $where[] = array("id", "=", $getvar['view']);
         $invoice_info_top = $dbh->select("invoices", $where);
         $pack_data_top = main::uidtopack();
         if (!$invoice_info_top['pid']) {
             $dbh->update("invoices", array("pid" => $pack_data_top['user_data']['pid']), array("id", "=", $invoice_info_top['id']));
             $invoice_info_top['pid'] = $pack_data_top['user_data']['pid'];
         }
         if ($_POST['submitaddcoupon']) {
             if (!$postvar['addcoupon']) {
                 main::errors("Please enter a coupon code or click the checkout button.");
             } else {
                 $coupcode = $postvar['addcoupon'];
                 $user = main::uname($_SESSION['cuser']);
                 $pack_data = main::uidtopack();
                 if ($invoice_info_top['pid'] != $pack_data['user_data']['pid']) {
                     $pack_data = upgrade::pidtobak($invoice_info_top['pid']);
                 }
                 $packid = $pack_data['packages']['id'];
                 $multi_coupons = $dbh->config("multicoupons");
                 $coupon_info = coupons::coupon_data($coupcode);
                 $coupid = $coupon_info['id'];
                 $use_coupon = coupons::use_coupon($coupid, $packid, $getvar['view']);
                 if (!$use_coupon) {
                     if (!$multi_coupons) {
                         main::errors("Coupon code entered was invalid or you're already using a coupon.");
                     } else {
                         main::errors("Coupon code entered was invalid.");
                     }
                 } else {
                     main::redirect("?page=invoices&view=" . $getvar['view']);
                 }
             }
         }
         unset($where);
         $where[] = array("uid", "=", $_SESSION['cuser'], "AND");
         $where[] = array("id", "=", $getvar['view']);
         $invoice_info = $dbh->select("invoices", $where);
         if (empty($invoice_info)) {
             main::redirect("?page=invoices");
             exit;
         }
         $package = $dbh->select("packages", array("id", "=", $invoice_info['pid']));
         $monthly = type::additional($package['id']);
         $subtotal = $monthly['monthly'];
         if (is_numeric($getvar['remove'])) {
             $remove_id = $getvar['remove'];
             $remove = coupons::remove_coupon($remove_id, $package['id'], $invoice_info['id'], $_SESSION['cuser']);
             main::redirect("?page=invoices&view=" . $invoice_info['id']);
             exit;
         }
         $total_paid_real = coupons::totalpaid($getvar['view']);
         if ($total_paid_real < 0) {
             $total_paid = "0.00";
         } else {
             $total_paid = $total_paid_real;
         }
         $acct_balance = coupons::get_discount("paid", $subtotal) - $total_paid_real;
         if ($acct_balance < 0) {
             $acct_balance = "0.00";
         }
         $acct_balance = main::addzeros($acct_balance);
         if ($acct_balance == 0 && $invoice_info['is_paid'] == '0') {
             $dbh->update("invoices", array("is_paid" => "1"), array("id", "=", $invoice_info['id']), "1");
             main::redirect("?page=invoices&view=" . $invoice_info['id']);
         }
         if ($acct_balance > 0 && $invoice_info['is_paid'] == '1') {
             $dbh->update("invoices", array("is_paid" => "0"), array("id", "=", $invoice_info['id']), "1");
             main::redirect("?page=invoices&view=" . $invoice_info['id']);
         }
         if ($_POST['checkout']) {
             $postvar['paythis'] = str_replace(array(" ", ","), array("", "."), $postvar['paythis']);
             if (!is_numeric($postvar['paythis'])) {
                 main::errors("Please enter the amount you wish to pay today.");
             } else {
                 if ($postvar['paythis'] > $acct_balance || $acct_balance <= 0) {
                     main::errors("You can't pay more than you owe.  =)");
                 } else {
                     $dbh->update("invoices", array("pay_now" => $postvar['paythis']), array("id", "=", $getvar['view']));
                     main::redirect("?page=invoices&iid=" . $getvar['view']);
                     exit;
                 }
             }
         }
         $created = $invoice_info['created'];
         $thirty_days = 30 * 24 * 60 * 60;
         $orig_due = $created + $thirty_days;
         if (main::convertdate("n/d/Y", $invoice_info['due']) != main::convertdate("n/d/Y", $created + $thirty_days)) {
             $due_text = " (Originally " . main::convertdate("n/d/Y", $orig_due) . ")";
         }
         $due = main::convertdate("n/d/Y", $invoice_info['due']);
         $client = $dbh->client($_SESSION['cuser']);
         $invoice_transactions_array['TOTALAMOUNT'] = main::money($acct_balance);
         $invoice_transactions_array['TOTALPAID'] = main::money($total_paid);
         $pay_invoice_array['TOTALAMT'] = main::money($acct_balance);
         $pay_invoice_array['PAYBALANCE'] = $acct_balance;
         $pay_invoice_array['CURRSYMBOL'] = main::money($acct_balance, "", 1);
         $pay_invoice_array['PACKID'] = $invoice_info['pid'];
         $pay_invoice_array['USER'] = $client['user'];
         $view_invoice_array['ID'] = $invoice_info['id'];
         $view_invoice_array['DUE'] = $due . $due_text;
         $view_invoice_array['PACKDUE'] = $due;
         $view_invoice_array['CREATED'] = main::convertdate("n/d/Y", $created);
         $view_invoice_array['BASEAMOUNT'] = $invoice_info['amount'] != $subtotal ? main::money($invoice_info['amount']) . " (Package price: " . main::money($subtotal) . ")" : main::money($invoice_info['amount']);
         $view_invoice_array['BALANCE'] = main::money($acct_balance);
         $view_invoice_array['COUPONTOTAL'] = main::money($subtotal - coupons::get_discount("paid", $subtotal));
         $view_invoice_array['UNAME'] = $client['user'];
         $view_invoice_array['FNAME'] = $client['firstname'];
         $view_invoice_array['LNAME'] = $client['lastname'];
         $view_invoice_array['ADDRESS'] = $client['address'];
         $view_invoice_array['CITY'] = $client['city'];
         $view_invoice_array['STATE'] = $client['state'];
         $view_invoice_array['ZIP'] = $client['zip'];
         $view_invoice_array['COUNTRY'] = strtoupper($client['country']);
         $view_invoice_array['DOMAIN'] = $client['domain'];
         $view_invoice_array['PACKAGE'] = $package['name'];
         $view_invoice_array['STATUS'] = $invoice_info["is_paid"] == 1 ? "<font color = '#779500'>Paid</font>" : "<font color = '#FF7800'>Unpaid</font>";
         if ($invoice_info['changed_plan'] && $invoice_info['hadcoupons']) {
             $coupon_list = explode(",", $invoice_info['hadcoupons']);
             $coupon_values = explode(",", $invoice_info['couponvals']);
             if ($coupon_list) {
                 for ($i = 0; $i < count($coupon_list); $i++) {
                     $coupons_list_array['COUPONAMOUNT'] = main::money($coupon_values[$i]);
                     $coupons_list_array['COUPCODE'] = $coupon_list[$i];
                     $coupons_list_array['REMOVE'] = "";
                     $view_invoice_array['COUPONSLIST'] .= style::replaceVar("tpl/invoices/coupons-list.tpl", $coupons_list_array);
                     $coup_total = $coup_total + $coupon_values[$i];
                 }
                 $view_invoice_array['COUPONTOTAL'] = main::money(min($subtotal, $coup_total));
             }
         } else {
             unset($where);
             $where[] = array("user", "=", $client['id'], "AND");
             $where[] = array("disabled", "=", "0");
             $coupons_query = $dbh->select("coupons_used", $where, array("id", "ASC"), 0, 1);
             while ($coupons_used_fetch = $dbh->fetch_array($coupons_query)) {
                 $valid_coupon = coupons::check_expire($coupons_used_fetch['coupcode'], $client['id']);
                 if ($valid_coupon) {
                     $coupons_list_array['COUPONAMOUNT'] = main::money($coupons_used_fetch['paiddisc']);
                     $coupons_list_array['COUPCODE'] = $coupons_used_fetch['coupcode'];
                     $coupons_list_array['REMOVE'] = $invoice_info['is_paid'] == 1 ? "" : '(<a href = "?page=invoices&view=' . $invoice_info['id'] . '&remove=' . $coupons_used_fetch['id'] . '">Remove</a>)';
                     $view_invoice_array['COUPONSLIST'] .= style::replaceVar("tpl/invoices/coupons-list.tpl", $coupons_list_array);
                 }
             }
             if (!$view_invoice_array['COUPONSLIST']) {
                 $view_invoice_array['COUPONSLIST'] = "<tr><td></td><td align = 'center'>None</td></tr>";
             }
         }
         $amt_paid = $invoice_info['amt_paid'];
         $txn = $invoice_info['txn'];
         $datepaid = $invoice_info['datepaid'];
         $gateway = $invoice_info['gateway'];
         $amt_paid = explode(",", $amt_paid);
         $txn = explode(",", $txn);
         $datepaid = explode(",", $datepaid);
         $gateway = explode(",", $gateway);
         $view_invoice_array['TRANSACTIONS'] = "";
         for ($i = 0; $i < count($amt_paid); $i++) {
             $paid_this = $paid_this + $amt_paid[$i];
             $transaction_list_array['PAIDAMOUNT'] = main::money($amt_paid[$i]);
             $transaction_list_array['TXN'] = $txn[$i];
             $transaction_list_array['PAIDDATE'] = main::convertdate("n/d/Y", $datepaid[$i]);
             $transaction_list_array['GATEWAY'] = $gateway[$i];
             $invoice_transactions_array['TXNS'] .= style::replaceVar("tpl/invoices/transaction-list.tpl", $transaction_list_array);
         }
         if ($invoice_info["is_paid"]) {
             if (!$invoice_info['amt_paid']) {
                 $invoice_transactions_array['TXNS'] = "<tr><td colspan = '4' align = 'center'><b>--- None ---</b></td></tr>";
             }
             $view_invoice_array['TRANSACTIONS'] = style::replaceVar("tpl/invoices/invoice-transactions.tpl", $invoice_transactions_array);
         } else {
             if ($invoice_info['amt_paid']) {
                 $view_invoice_array['TRANSACTIONS'] = style::replaceVar("tpl/invoices/invoice-transactions.tpl", $invoice_transactions_array);
             }
             $view_invoice_array['TRANSACTIONS'] .= style::replaceVar("tpl/client/invoices/pay-invoice.tpl", $pay_invoice_array);
         }
         echo style::replaceVar("tpl/invoices/view-invoice.tpl", $view_invoice_array);
     } else {
         //Show the list of invoices
         $pack_info = main::uidtopack();
         $invoices_query = $dbh->select("invoices", array("uid", "=", $_SESSION['cuser']), array("id", "DESC"), 0, 1);
         $client_page_array['LIST'] = "";
         while ($invoices_data = $dbh->fetch_array($invoices_query)) {
             if (!$invoices_data['pid']) {
                 $dbh->update("invoices", array("pid" => $pack_info['user_data']['pid']), array("id", "=", $invoices_data['id']));
                 $invoices_data['pid'] = $pack_info['user_data']['pid'];
             }
             if ($invoices_data['pid'] != $pack_info['user_data']['pid']) {
                 $pack_info = upgrade::pidtobak($invoices_data['pid']);
             }
             $monthly = $pack_info['additional']['monthly'];
             $invoice_list_item_array['ID'] = $invoices_data['id'];
             $invoice_list_item_array['USERFIELD'] = "";
             $invoice_list_item_array['DUE'] = main::convertdate("n/d/Y", $invoices_data['due']);
             $invoice_list_item_array['CREATED'] = main::convertdate("n/d/Y", $invoices_data['created']);
             $invoice_list_item_array["PAID"] = $invoices_data["is_paid"] == 1 ? "<font color = '#779500'>Paid</font>" : "<font color = '#FF7800'>Unpaid</font>";
             $invoice_list_item_array['AMOUNT'] = main::money($invoices_data['amount']);
             $invoice_list_item_array['AMTPAID'] = main::money(coupons::totalpaid($invoices_data['id']));
             $client_page_array['LIST'] .= style::replaceVar("tpl/invoices/invoice-list-item.tpl", $invoice_list_item_array);
         }
         $client_page_array['NUM'] = $dbh->num_rows($invoices_query);
         if ($client_page_array['NUM'] == 0) {
             $client_page_array['LIST'] = "<tr>\n<td colspan = '6' align = 'center'>You currently do not have any invoices.</td>\n</tr>";
         }
         echo style::replaceVar("tpl/client/invoices/client-page.tpl", $client_page_array);
     }
 }
Esempio n. 23
0
 private function MassMailClients()
 {
     global $dbh, $postvar, $getvar, $instance;
     if ($_POST) {
         check::empty_fields();
         if (!main::errors()) {
             $users_query = $dbh->select("users");
             while ($users_data = $dbh->fetch_array($users_query)) {
                 $result = email::send($users_data['email'], $postvar['msgsubject'], $postvar['msgcontent']);
                 if (!$result) {
                     $error = true;
                 }
             }
             if (!$error) {
                 main::errors("The email has been sent to all your clients.");
             } else {
                 main::errors("Houston, you have problems.  Check the THT Log to find out what all went wrong.");
             }
         }
     }
     echo style::replaceVar("tpl/admin/mail/mass-email.tpl");
 }
Esempio n. 24
0
 private function edit_article()
 {
     global $dbh, $postvar, $getvar, $instance;
     $cats_query = $dbh->select("cats");
     if (!$dbh->num_rows($cats_query)) {
         echo "You need to add a category before you add an article.";
         return;
     }
     if ($_POST['edit']) {
         check::empty_fields();
         if (!main::errors()) {
             $articles_update = array("name" => $postvar['editname'], "content" => $postvar['editdescription'], "catid" => $postvar['catid']);
             $dbh->update("articles", $articles_update, array("id", "=", $getvar['id']));
             main::errors("Article Edited!");
         }
     }
     if ($getvar['del']) {
         $dbh->delete("articles", array("id", "=", $getvar['del']));
         main::errors("Article Deleted!");
     }
     if (main::isint($getvar['categoryid'])) {
         $show_cat[] = array("catid", "=", $getvar['categoryid']);
     }
     if (!main::isint($getvar['id'])) {
         $list_articles_array['BOXES'] = "";
         $articles_query = $dbh->select("articles", $show_cat, 0, 0, 1);
         if ($dbh->num_rows($articles_query)) {
             while ($articles_data = $dbh->fetch_array($articles_query)) {
                 $edit_article_box_array['NAME'] = $articles_data['name'];
                 $edit_article_box_array['ID'] = $articles_data['id'];
                 $list_articles_array['BOXES'] .= style::replaceVar("tpl/admin/kb/edit-article-box.tpl", $edit_article_box_array);
             }
         }
         echo style::replaceVar("tpl/admin/kb/list-articles.tpl", $list_articles_array);
     } else {
         $cats_query = $dbh->select("cats");
         while ($cat = $dbh->fetch_array($cats_query)) {
             $values[] = array($cat['name'], $cat['id']);
         }
         $article_data = $dbh->select("articles", array("id", "=", $getvar['id']), 0, "1");
         $edit_article_array['NAME'] = $article_data['name'];
         $edit_article_array['DESCRIPTION'] = $article_data['content'];
         $edit_article_array['DROPDOWN'] = main::dropDown("catid", $values, $article_data['catid']);
         echo style::replaceVar("tpl/admin/kb/edit-article.tpl", $edit_article_array);
     }
 }
Esempio n. 25
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     if (main::isint(str_replace("P2H-", "", $getvar['view']))) {
         //Display the invoice
         if (substr_count($getvar['view'], "P2H-")) {
             $p2hid = str_replace("P2H-", "", $getvar['view']);
             $userid = $dbh->select("users", array("id", "=", $p2hid));
             $userid = $userid['id'];
             $userdata = coupons::admin_userdata($userid);
         } else {
             $invoiceid = $getvar['view'];
             $invoice_data_top = $dbh->select("invoices", array("id", "=", $invoiceid));
             $pid = $invoice_data_top['pid'];
             $userid = $invoice_data_top['uid'];
             $uidtopack = main::uidtopack($userid, $pid);
             if (!$pid) {
                 $dbh->update("invoices", array("pid" => $uidtopack['pid']), array("id", "=", $invoice_data_top['id']));
             }
             $userdata = coupons::admin_userdata($userid);
         }
         if ($_POST['submitaddcoupon']) {
             if (!$postvar['addcoupon']) {
                 main::errors("Please enter a coupon code.");
             } else {
                 $coupcode = $postvar['addcoupon'];
                 $user = main::uname($userid);
                 $pack_data = main::uidtopack($userid, $pid);
                 $packid = $pack_data['packages']['id'];
                 $multi_coupons = $dbh->config("multicoupons");
                 if ($p2hid) {
                     $monthly = $pack_data['additional']['monthly'];
                     $monthly = coupons::get_discount("p2hmonthly", $monthly, $userid);
                     $total_posted = coupons::totalposts($userid);
                     $amt_owed = max(0, $monthly - $total_posted);
                 } else {
                     $invoice_info = $dbh->select("invoices", array("id", "=", $invoiceid));
                     if ($invoice_info['pid'] != $pack_data['pid']) {
                         $pack_data = upgrade::pidtobak($invoice_info['pid'], $invoice_info["uid"]);
                     }
                     $total_paid = coupons::totalpaid($invoiceid);
                     $amt_owed = max(0, $invoice_info['amount'] - $total_paid);
                 }
                 if ($amt_owed == 0) {
                     main::errors("The user's balance is already paid in full, so you can't add another coupon.");
                 } else {
                     $coupon_info = coupons::coupon_data($coupcode);
                     $coupid = $coupon_info['id'];
                     $use_coupon = coupons::use_coupon($coupid, $packid, $invoiceid, $userid);
                     if (!$use_coupon) {
                         if (!$multi_coupons) {
                             main::errors("Coupon code entered was invalid or user is already using a coupon.  You can give them a credit instead.");
                         } else {
                             main::errors("Coupon code entered was invalid or the user is already using this coupon.");
                         }
                     } else {
                         main::redirect("?page=invoices&view=" . $getvar['view']);
                     }
                 }
             }
         }
         if ($_POST['submitcredit']) {
             $postvar['credit'] = str_replace(array(" ", ","), array("", "."), $postvar['credit']);
             if (!is_numeric($postvar['credit'])) {
                 main::errors("Please enter the amount to be credited or debited.");
             } else {
                 if ($postvar['creditreason']) {
                     $creditreason = $postvar['creditreason'];
                     $creditreason = ' <a title="' . $creditreason . '" class="tooltip"><img src="<URL>themes/icons/information.png"></a>';
                     $creditreason = str_replace(",", "", $creditreason);
                     //Can't have commas, no way no how!  ;)  lol  We need to be able to explode(",", $invoice_info['txn']);
                 }
                 if ($p2hid) {
                     $credit_fee = $postvar['credit'];
                 } else {
                     $credit_fee = main::addzeros($postvar['credit']);
                 }
                 if ($credit_fee != 0) {
                     if (substr_count($credit_fee, "-")) {
                         $creditfee_lable = "CHARGE";
                     } else {
                         $creditfee_lable = "CREDIT";
                     }
                     $packinfo = main::uidtopack($userid, $pid);
                     if (!$packinfo['user_data']['pid'] && !$p2hid) {
                         $packinfo = upgrade::pidtobak($pid, $userid);
                     }
                     $monthly = $packinfo['additional']['monthly'];
                     if ($p2hid) {
                         $amt_owed = max(0, $monthly - coupons::totalposts($userid));
                     } else {
                         $amt_owed = max(0, $monthly - coupons::totalpaid($invoiceid));
                     }
                     if ($amt_owed == 0 && $creditfee_lable == "CREDIT") {
                         main::errors("The user's balance is already paid in full, so you can't add a credit.");
                     } else {
                         if ($p2hid) {
                             $p2h_info = $dbh->select("coupons_p2h", array("uid", "=", $userid));
                             if ($p2h_info['datepaid']) {
                                 $comma = ",";
                             }
                             $datepaid = $p2h_info['datepaid'] . $comma . time();
                             $txn = $p2h_info['txn'] . $comma . $creditfee_lable . $creditreason;
                             $amt_paid = $p2h_info['amt_paid'] . $comma . $credit_fee;
                             $gateway = $p2h_info['gateway'] . $comma . "INTERNAL";
                             $update_coupons_p2h = array("datepaid" => $datepaid, "txn" => $txn, "amt_paid" => $amt_paid, "gateway" => $gateway);
                             $dbh->update("coupons_p2h", $update_coupons_p2h, array("uid", "=", $userid), "1");
                         } else {
                             $invoice_info = $dbh->select("invoices", array("id", "=", $invoiceid));
                             if ($invoice_info['pid'] != $packinfo['pid']) {
                                 $pack_info = upgrade::pidtobak($invoice_info['pid'], $invoice_info["uid"]);
                             }
                             if ($invoice_info['datepaid']) {
                                 $comma = ",";
                             }
                             $datepaid = $invoice_info['datepaid'] . $comma . time();
                             $txn = $invoice_info['txn'] . $comma . $creditfee_lable . $creditreason;
                             $amt_paid = $invoice_info['amt_paid'] . $comma . $credit_fee;
                             $gateway = $invoice_info['gateway'] . $comma . "INTERNAL";
                             $update_invoices = array("datepaid" => $datepaid, "txn" => $txn, "amt_paid" => $amt_paid, "gateway" => $gateway);
                             $dbh->update("invoices", $update_invoices, array("id", "=", $invoiceid), "1");
                         }
                         main::redirect("?page=invoices&view=" . $getvar['view']);
                     }
                 }
             }
         }
         if ($_POST['submitpayarrange']) {
             $invoice_info = $dbh->select("invoices", array("id", "=", $invoiceid));
             $duedate = $invoice_info['due'];
             $days_modify = $postvar['days'];
             $days_modify = $days_modify * 24 * 60 * 60;
             if ($postvar['addsub'] == "add") {
                 $new_due_date = $duedate + $days_modify;
             } else {
                 $new_due_date = $duedate - $days_modify;
             }
             $dbh->update("invoices", array("due" => $new_due_date), array("id", "=", $invoiceid), "1");
             main::redirect("?page=invoices&view=" . $getvar['view']);
         }
         if ($p2hid) {
             $p2h_info = $dbh->select("users", array("id", "=", $p2hid));
         } else {
             $invoice_info = $dbh->select("invoices", array("id", "=", $invoiceid));
         }
         if (empty($invoice_info) && empty($p2h_info)) {
             main::redirect("?page=invoices");
             exit;
         }
         if ($getvar['deleteinv']) {
             if ($postvar['yes']) {
                 if ($p2hid) {
                     $dbh->delete("coupons_p2h", array("uid", "=", $userid), "1");
                     main::redirect("?page=invoices&view=" . $getvar['view']);
                 } else {
                     $dbh->delete("invoices", array("id", "=", $invoiceid), "1");
                     main::redirect("?page=invoices");
                 }
             } elseif ($postvar['no']) {
                 main::redirect("?page=invoices&view=" . $getvar['view']);
             } else {
                 $warning_array['HIDDEN'] = "<input type = 'hidden' name = 'confirm' value = 'confirm'>";
                 echo style::replaceVar("tpl/warning.tpl", $warning_array);
                 $warning_page = '1';
             }
         }
         if ($userdata['removed'] == 1) {
             $upackage = $dbh->select("users_bak", array("id", "=", $userid));
         } else {
             $upackage = $dbh->select("users", array("id", "=", $userid));
         }
         if (!$p2hid) {
             $package = $dbh->select("packages", array("id", "=", $invoice_info['pid']));
         } else {
             $package = $dbh->select("packages", array("id", "=", $upackage['pid']));
         }
         $monthly = type::additional($package['id']);
         $subtotal = $monthly['monthly'];
         if (is_numeric($getvar['remove'])) {
             $remove_id = $getvar['remove'];
             if ($p2hid) {
                 coupons::remove_p2h_coupon($remove_id, $userid);
             } else {
                 coupons::remove_coupon($remove_id, $package['id'], $invoice_info['id'], $userid);
             }
             main::redirect("?page=invoices&view=" . $getvar['view']);
             exit;
         }
         if ($p2hid) {
             $due = date("m/t/Y");
             $created = date("m/1/Y");
             $p2h = $instance->packtypes["p2h"];
             $monthly_with_disc = coupons::get_discount("p2hmonthly", $subtotal, $userid);
             $total_posts = $p2h->userposts($package['id'], $p2hid);
             $total_paid = coupons::totalposts($userid);
             if (empty($total_paid)) {
                 $total_paid = 0;
             }
             if (empty($total_posts)) {
                 $total_posts = 0;
             }
             $acct_balance = max(0, $monthly_with_disc - $total_paid);
             $view_invoice_array['BASEAMOUNT'] = $invoice_info['amount'] != $subtotal ? main::s($invoice_info['amount'], " Post") . " (Package price: " . main::s($subtotal, " Post") . ")" : main::s($invoice_info['amount'], " Post");
             $view_invoice_array['COUPONTOTAL'] = main::s($subtotal - $monthly_with_disc, " Post");
             $invoice_transactions_array['TOTALAMOUNT'] = main::s($acct_balance, " Post");
             $invoice_transactions_array['TOTALPAID'] = main::s($total_paid, " Post");
             $admin_ops_array['TOTALAMT'] = main::s($acct_balance, " Post");
             $admin_ops_array['DELRESET'] = "Reset";
             $admin_ops_modify_array['CREDIT'] = $acct_balance;
             $admin_ops_modify_array['CURRSYMBOL'] = "";
             $admin_ops_modify_array['POSTS'] = " Posts";
         } else {
             $created = $invoice_info['created'];
             $thirty_days = 30 * 24 * 60 * 60;
             $orig_due = $created + $thirty_days;
             if ($getvar['resetpayarange']) {
                 $dbh->update("invoices", array("due" => $orig_due), array("id", "=", $invoiceid), "1");
                 main::redirect("?page=invoices&view=" . $invoiceid);
             }
             if (main::convertdate("n/d/Y", $invoice_info['due']) != main::convertdate("n/d/Y", $created + $thirty_days)) {
                 $due_text = " (Originally " . main::convertdate("n/d/Y", $orig_due) . ") - <a href = '?page=invoices&view=" . $invoiceid . "&resetpayarange=1'>Reset</a>";
             }
             $due = main::convertdate("n/d/Y", $invoice_info['due']);
             $created = main::convertdate("n/d/Y", $created);
             $total_paid_real = coupons::totalpaid($invoiceid);
             if ($total_paid_real < 0) {
                 $total_paid = "0.00";
             } else {
                 $total_paid = $total_paid_real;
             }
             $acct_balance = $invoice_info['amount'] - $total_paid_real;
             $acct_balance = main::addzeros($acct_balance);
             if ($acct_balance < 0) {
                 $acct_balance = "0.00";
             }
             if ($acct_balance == 0 && $invoice_info['is_paid'] == '0') {
                 $dbh->update("invoices", array("is_paid" => "1"), array("id", "=", $invoice_info['id']), "1");
                 unset($where);
                 $where[] = array("id", "=", $invoice_info['uid'], "AND");
                 $where[] = array("status", "=", "4");
                 $dbh->update("users", array("status" => "1"), $where, "1");
                 unset($where);
                 $where[] = array("id", "=", $invoice_info['uid'], "AND");
                 $where[] = array("status", "=", "4");
                 $dbh->update("users", array("status" => "1"), $where, "1");
                 main::redirect("?page=invoices&view=" . $invoiceid);
             }
             if ($acct_balance > 0 && $invoice_info['is_paid'] == '1') {
                 $dbh->update("invoices", array("is_paid" => "0"), array("id", "=", $invoice_info['id']), "1");
                 main::redirect("?page=invoices&view=" . $invoiceid);
             }
             $view_invoice_array['BASEAMOUNT'] = $invoice_info['amount'] != $subtotal ? main::money($invoice_info['amount']) . " (Package price: " . main::money($subtotal) . ")" : main::money($invoice_info['amount']);
             $view_invoice_array['COUPONTOTAL'] = main::money($subtotal - coupons::get_discount("paid", $subtotal, $userid));
             $invoice_transactions_array['TOTALAMOUNT'] = main::money($acct_balance);
             $invoice_transactions_array['TOTALPAID'] = main::money($total_paid);
             $admin_ops_array['TOTALAMT'] = main::money($acct_balance);
             $admin_ops_array['DELRESET'] = "Delete";
             $admin_ops_modify_array['CREDIT'] = $acct_balance;
             $admin_ops_modify_array['CURRSYMBOL'] = main::money($acct_balance, "", 1) . " ";
             $admin_ops_modify_array['POSTS'] = "";
         }
         $view_invoice_array['ID'] = $getvar['view'];
         $view_invoice_array['DUE'] = $due . $due_text;
         $view_invoice_array['PACKDUE'] = $due;
         $view_invoice_array['CREATED'] = $created;
         $view_invoice_array['UNAME'] = $userdata['user'];
         $view_invoice_array['FNAME'] = $userdata['firstname'];
         $view_invoice_array['LNAME'] = $userdata['lastname'];
         $view_invoice_array['ADDRESS'] = $userdata['address'];
         $view_invoice_array['CITY'] = $userdata['city'];
         $view_invoice_array['STATE'] = $userdata['state'];
         $view_invoice_array['ZIP'] = $userdata['zip'];
         $view_invoice_array['COUNTRY'] = strtoupper($userdata['country']);
         $view_invoice_array['DOMAIN'] = $upackage['domain'];
         $view_invoice_array['PACKAGE'] = $package['name'];
         $view_invoice_array['STATUS'] = $acct_balance == 0 ? "<font color = '#779500'>Paid</font>" : "<font color = '#FF7800'>Unpaid</font>";
         if ($invoice_info['changed_plan'] && $invoice_info['hadcoupons']) {
             $coupon_list = explode(",", $invoice_info['hadcoupons']);
             $coupon_values = explode(",", $invoice_info['couponvals']);
             if ($coupon_list) {
                 for ($i = 0; $i < count($coupon_list); $i++) {
                     $coupons_list_array['COUPONAMOUNT'] = main::money($coupon_values[$i]);
                     $coupons_list_array['COUPCODE'] = $coupon_list[$i];
                     $coupons_list_array['REMOVE'] = "";
                     $view_invoice_array['COUPONSLIST'] .= style::replaceVar("tpl/invoices/coupons-list.tpl", $coupons_list_array);
                     $coup_total = $coup_total + $coupon_values[$i];
                 }
                 $view_invoice_array['COUPONTOTAL'] = main::money(min($subtotal, $coup_total));
             }
         } else {
             unset($where);
             $where[] = array("user", "=", $userid, "AND");
             $where[] = array("disabled", "=", "0");
             $coupons_query = $dbh->select("coupons_used", $where, array("id", "ASC"), 0, 1);
             while ($coupons_used_fetch = $dbh->fetch_array($coupons_query)) {
                 $valid_coupon = coupons::check_expire($coupons_used_fetch['coupcode'], $userid);
                 if ($valid_coupon) {
                     if ($p2hid) {
                         $coupamt = main::s($coupons_used_fetch['p2hmonthlydisc'], " Post");
                     } else {
                         $coupamt = main::money($coupons_used_fetch['paiddisc']);
                     }
                     $coupons_list_array['COUPONAMOUNT'] = $coupamt;
                     $coupons_list_array['COUPCODE'] = $coupons_used_fetch['coupcode'];
                     $coupons_list_array['REMOVE'] = $userdata['removed'] == 1 ? "" : '(<a href = "?page=invoices&view=' . $getvar['view'] . '&remove=' . $coupons_used_fetch['id'] . '">Remove</a>)';
                     $view_invoice_array['COUPONSLIST'] .= style::replaceVar("tpl/invoices/coupons-list.tpl", $coupons_list_array);
                 }
             }
         }
         if (!$view_invoice_array['COUPONSLIST']) {
             $view_invoice_array['COUPONSLIST'] = "<tr><td></td><td align = 'center'>None</td></tr>";
         }
         if ($p2hid) {
             $p2h_payments = $dbh->select("coupons_p2h", array("uid", "=", $userid));
             $package_info = main::uidtopack($userid);
             if (empty($p2h_payments)) {
                 $p2h_pay_array = array("uid" => $userid, "amt_paid" => $total_posts, "txn" => $package_info['uadditional']['fuser'], "datepaid" => time(), "gateway" => $package_info['additional']['forum']);
                 $dbh->insert("coupons_p2h", $p2h_pay_array);
                 $p2h_payments = $dbh->select("coupons_p2h", array("uid", "=", $userid));
             }
             $amt_paid = $p2h_payments['amt_paid'];
             $txn = $p2h_payments['txn'];
             $datepaid = $p2h_payments['datepaid'];
             $gateway = $p2h_payments['gateway'];
         } else {
             $amt_paid = $invoice_info['amt_paid'];
             $txn = $invoice_info['txn'];
             $datepaid = $invoice_info['datepaid'];
             $gateway = $invoice_info['gateway'];
         }
         $amt_paid = explode(",", $amt_paid);
         $txn = explode(",", $txn);
         $datepaid = explode(",", $datepaid);
         $gateway = explode(",", $gateway);
         $remnum = 1;
         for ($i = 0; $i < count($amt_paid); $i++) {
             unset($remtxn);
             if ($gateway[$i] == "INTERNAL" && !$userdata['removed']) {
                 $remtxn = ' <a href = "?page=invoices&view=' . $getvar['view'] . '&remtxn=' . $remnum . '">[Delete]</a>';
             }
             if ($txn[$i] == $package_info['uadditional']['fuser']) {
                 if ($amt_paid[$i] != $total_posts) {
                     $reload = 1;
                 }
                 $amt_paid[$i] = $total_posts;
                 $datepaid[$i] = time();
             }
             $paid_this = $paid_this + $amt_paid[$i];
             if ($p2hid) {
                 $transaction_list_array['PAIDAMOUNT'] = main::s(str_replace("-", "−", $amt_paid[$i]), " Post") . $remtxn;
             } else {
                 $transaction_list_array['PAIDAMOUNT'] = main::money($amt_paid[$i]) . $remtxn;
             }
             $transaction_list_array['TXN'] = $txn[$i];
             $transaction_list_array['PAIDDATE'] = main::convertdate("n/d/Y", $datepaid[$i]);
             $transaction_list_array['GATEWAY'] = $gateway[$i];
             $invoice_transactions_array['TXNS'] .= style::replaceVar("tpl/invoices/transaction-list.tpl", $transaction_list_array);
             if ($getvar['remtxn'] != $i + 1) {
                 $paidamts = $paidamts . "," . $amt_paid[$i];
                 $paidtxn = $paidtxn . "," . $txn[$i];
                 $paiddate = $paiddate . "," . $datepaid[$i];
                 $paidgateway = $paidgateway . "," . $gateway[$i];
             }
             $remnum++;
         }
         if ($p2hid) {
             $paidamts = substr($paidamts, 1, strlen($paidamts));
             $paidtxn = substr($paidtxn, 1, strlen($paidtxn));
             $paiddate = substr($paiddate, 1, strlen($paiddate));
             $paidgateway = substr($paidgateway, 1, strlen($paidgateway));
             $p2h_pay_array = array("amt_paid" => $paidamts, "txn" => $paidtxn, "datepaid" => $paiddate, "gateway" => $paidgateway);
             unset($where);
             $where[] = array("uid", "=", $userid);
             $dbh->update("coupons_p2h", $p2h_pay_array, $where);
             if ($getvar['remtxn'] || $reload) {
                 main::redirect("?page=invoices&view=" . $getvar['view']);
             }
         } else {
             if ($getvar['remtxn']) {
                 $paidamts = substr($paidamts, 1, strlen($paidamts));
                 $paidtxn = substr($paidtxn, 1, strlen($paidtxn));
                 $paiddate = substr($paiddate, 1, strlen($paiddate));
                 $paidgateway = substr($paidgateway, 1, strlen($paidgateway));
                 $update_invoices = array("amt_paid" => $paidamts, "txn" => $paidtxn, "datepaid" => $paiddate, "gateway" => $paidgateway);
                 $dbh->update("invoices", $update_invoices, array("id", "=", $invoiceid), "1");
                 main::redirect("?page=invoices&view=" . $invoiceid);
             }
         }
         if ($invoice_info['amt_paid'] || $p2hid) {
             $view_invoice_array['TRANSACTIONS'] = style::replaceVar("tpl/invoices/invoice-transactions.tpl", $invoice_transactions_array);
         }
         $addsub[] = array("Add", "add");
         $addsub[] = array("Subtract", "subtract");
         $days[] = array("1 Day", "1");
         for ($num = 2; $num < 31; $num++) {
             $days[] = array($num . " Days", $num);
         }
         $payment_arrangments_array['ADDSUB'] = main::dropDown("addsub", $addsub, "add", 0);
         $payment_arrangments_array['DAYS'] = main::dropDown("days", $days, 1, 0);
         if ($userdata['removed'] == 1) {
             $admin_ops_array['MODIFYFUNCS'] = '
                     <tr>
                      <td align="center" colspan = "2"><font color = "#FF0055"><strong>The owner of this invoice has been dismembered.  Er... I mean the member who owned this invoice has been removed.</strong></font></td>
                     </tr>';
         } else {
             if (!$p2hid) {
                 $admin_ops_modify_array['PAYARRANGE'] = style::replaceVar("tpl/admin/invoices/payment-arrangments.tpl", $payment_arrangments_array);
             } else {
                 $admin_ops_modify_array['PAYARRANGE'] = "";
             }
             $admin_ops_array['MODIFYFUNCS'] = style::replaceVar("tpl/admin/invoices/admin-ops-modify.tpl", $admin_ops_modify_array);
             if ($invoice_info['changed_plan']) {
                 $admin_ops_array['MODIFYFUNCS'] .= '
                     <tr>
                      <td align="center" colspan = "2"><font color = "#FF0055"><strong>The owner of this invoice has upgraded their account and this is an invoice from an old account.</strong></font></td>
                     </tr>';
             }
         }
         $view_invoice_array['TRANSACTIONS'] .= style::replaceVar("tpl/admin/invoices/admin-ops.tpl", $admin_ops_array);
         if (!$warning_page) {
             echo style::replaceVar("tpl/invoices/view-invoice.tpl", $view_invoice_array);
         }
     } else {
         //Display the invoice list
         //Status search
         $showstatus = "all";
         if ($postvar['submitstatus']) {
             $showstatus = $postvar['status'];
         }
         //End ststus search
         //Type search
         $showtype = "all";
         if ($postvar['submittype']) {
             $showtype = $postvar['invtype'];
         }
         //End type search
         $users[] = array("All", "all");
         $users[] = array("Orphans", "orphans");
         $users_query = $dbh->select("users", 0, array("user", "ASC"));
         while ($users_data = $dbh->fetch_array($users_query)) {
             $users[] = array($users_data['user'], $users_data['id']);
         }
         //User search
         $users_default = "all";
         if ($postvar['submitusers']) {
             $users_default = $postvar['users'];
             if ($users_default != "all" && $users_default != "orphans") {
                 $show_user = array("uid", "=", $users_default);
                 $show_p2h_user_where = array("id", "=", $users_default, "AND");
                 $username = main::uname($users_default);
                 $for_user = "******" . $username;
             }
         }
         //End user search
         $num_invoices = 0;
         $num_paid = 0;
         $num_unpaid = 0;
         $total_unpaid = 0;
         if ($showtype == "all" || $showtype == "p2h") {
             $p2h_query = $dbh->select("packages", array("type", "=", "p2h"), 0, 0, 1);
             while ($p2h_data = $dbh->fetch_array($p2h_query)) {
                 $show_p2h_user_where[] = array("pid", "=", $p2h_data['id']);
                 $user_query = $dbh->select("users", $show_p2h_user_where, 0, 0, 1);
                 while ($user_data = $dbh->fetch_array($user_query)) {
                     unset($user_show);
                     unset($orphaned);
                     $user_show = main::uname($user_data["id"]);
                     if (!$user_show) {
                         $user_show = '<font color = "FF0055">ORPHANED</font>';
                         $orphaned = 1;
                     }
                     if ($orphaned && $users_default == "orphans" || $users_default != "orphans") {
                         $pack_info = main::uidtopack($user_data['id']);
                         $p2h = $instance->packtypes["p2h"];
                         $monthly = $pack_info['additional']['monthly'];
                         $monthly_with_disc = coupons::get_discount("p2hmonthly", $monthly, $user_data['id']);
                         $userposts = coupons::totalposts($user_data['id']);
                         $invoice_list_item_array['ID'] = "P2H-" . $user_data['id'];
                         $invoice_list_item_array['USERFIELD'] = '<td width="100" align="center">' . $user_show . '</td>';
                         $invoice_list_item_array['DUE'] = main::convertdate("n/d/Y", mktime(date("H"), date("i"), date("s"), date("n"), date("t"), date("Y")));
                         $invoice_list_item_array['CREATED'] = main::convertdate("n/d/Y", mktime(date("H"), date("i"), date("s"), date("n"), 1, date("Y")));
                         $invoice_list_item_array['AMOUNT'] = main::s($monthly, " Post");
                         $invoice_list_item_array['AMTPAID'] = main::s($userposts, " Post");
                         if ($showstatus == "unpaid" || $showstatus == "all") {
                             if ($monthly_with_disc - $userposts > 0) {
                                 $pulled = 1;
                                 $invoice_list_item_array["PAID"] = "<font color = '#FF7800'>Unpaid</font>";
                                 $admin_page_array['LIST'] .= style::replaceVar("tpl/invoices/invoice-list-item.tpl", $invoice_list_item_array);
                             }
                         }
                         if ($showstatus == "paid" || $showstatus == "all" && !$pulled) {
                             if ($monthly_with_disc - $userposts <= 0) {
                                 $invoice_list_item_array["PAID"] = "<font color = '#779500'>Paid</font>";
                                 $admin_page_array['LIST'] .= style::replaceVar("tpl/invoices/invoice-list-item.tpl", $invoice_list_item_array);
                             }
                         }
                         if ($monthly_with_disc - $userposts > 0) {
                             $total_unpaid = $total_unpaid + 1;
                         }
                         $pulled = 0;
                         $num_invoices = $num_invoices + 1;
                     }
                 }
             }
         }
         if ($showtype == "all" || $showtype == "paid") {
             $invoices_query = $dbh->select("invoices", $show_user, array("id", "DESC"), 0, 1);
             while ($invoices_data = $dbh->fetch_array($invoices_query)) {
                 unset($user_show);
                 unset($orphaned);
                 unset($invoice_locked);
                 $user_show = main::uname($invoices_data["uid"]);
                 if (!$user_show) {
                     $user_show = '<font color = "FF0055">ORPHANED</font>';
                     $orphaned = 1;
                 }
                 if ($orphaned && $users_default == "orphans" || $users_default != "orphans") {
                     $pack_info = main::uidtopack($invoices_data["uid"], $invoices_data['pid']);
                     if (!$invoices_data['pid']) {
                         $dbh->update("invoices", array("pid" => $pack_info['user_data']['pid']), array("id", "=", $invoices_data['id']));
                         $invoices_data['pid'] = $pack_info['user_data']['pid'];
                     }
                     if ($invoices_data['pid'] != $pack_info['user_data']['pid']) {
                         $pack_info = upgrade::pidtobak($invoices_data['pid'], $invoices_data["uid"]);
                     }
                     $invoice_list_item_array['ID'] = $invoices_data['id'];
                     $invoice_list_item_array['USERFIELD'] = '<td width="100" align="center">' . $user_show . '</td>';
                     $invoice_list_item_array['DUE'] = main::convertdate("n/d/Y", $invoices_data['due']);
                     $invoice_list_item_array['CREATED'] = main::convertdate("n/d/Y", $invoices_data['created']);
                     $total_paid_real = coupons::totalpaid($invoices_data['id']);
                     $invoice_list_item_array['AMOUNT'] = main::money($invoices_data['amount']);
                     $invoice_list_item_array['AMTPAID'] = main::money($total_paid_real);
                     if ($showstatus == "unpaid" || $showstatus == "all") {
                         if ($invoices_data["is_paid"] == 0) {
                             $pulled = 1;
                             $invoice_list_item_array["PAID"] = "<font color = '#FF7800'>Unpaid</font>" . $invoice_locked;
                             $admin_page_array['LIST'] .= style::replaceVar("tpl/invoices/invoice-list-item.tpl", $invoice_list_item_array);
                         }
                     }
                     if ($showstatus == "paid" || $showstatus == "all" && !$pulled) {
                         if ($invoices_data["is_paid"] == 1) {
                             $invoice_list_item_array["PAID"] = "<font color = '#779500'>Paid</font>" . $invoice_locked;
                             $admin_page_array['LIST'] .= style::replaceVar("tpl/invoices/invoice-list-item.tpl", $invoice_list_item_array);
                         }
                     }
                     if ($invoices_data["is_paid"] == 0) {
                         $total_unpaid = $total_unpaid + 1;
                     }
                     $pulled = 0;
                     $num_invoices = $num_invoices + 1;
                 }
             }
         }
         if (!$admin_page_array['LIST']) {
             $admin_page_array['LIST'] = "<tr>\n<td colspan = '7' align = 'center'>There are not currently any invoices to show.</td>\n</tr>";
         }
         $statusopts[] = array("All", "all");
         $statusopts[] = array("Unpaid", "unpaid");
         $statusopts[] = array("Paid", "paid");
         $typeopts[] = array("All", "all");
         $typeopts[] = array("P2H", "p2h");
         $typeopts[] = array("Paid", "paid");
         $admin_page_array['USERS'] = main::dropDown("users", $users, $users_default, 0);
         $admin_page_array['TYPEOPTS'] = main::dropDown("invtype", $typeopts, $showtype, 0);
         $admin_page_array['STATUSOPTS'] = main::dropDown("status", $statusopts, $showstatus, 0);
         $admin_page_array['FORUSER'] = $for_user;
         $admin_page_array['NUM'] = $num_invoices;
         $admin_page_array['NUMPAID'] = $num_invoices - $total_unpaid;
         $admin_page_array['NUMUNPAID'] = $total_unpaid;
         echo style::replaceVar("tpl/admin/invoices/admin-page.tpl", $admin_page_array);
     }
 }
Esempio n. 26
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     switch ($getvar['sub']) {
         default:
             if ($_POST) {
                 check::empty_fields();
                 if (!main::errors()) {
                     $subdomains_insert = array("domain" => $postvar['domain'], "server" => $postvar['server']);
                     $dbh->insert("subdomains", $subdomains_insert);
                     main::errors("Subdomain domain has been added!");
                 }
             }
             $servers_query = $dbh->select("servers");
             if ($dbh->num_rows($servers_query) == 0) {
                 echo "There are no servers, you need to add a server first!";
                 return;
             }
             while ($servers_data = $dbh->fetch_array($servers_query)) {
                 $values[] = array($servers_data['name'], $servers_data['id']);
             }
             $add_subdomain_array['SERVER'] = main::dropDown("server", $values);
             echo style::replaceVar("tpl/admin/subdomains/add-subdomain.tpl", $add_subdomain_array);
             break;
         case "edit":
             if (isset($getvar['do'])) {
                 $subdomains_data = $dbh->select("subdomains", array("id", "=", $getvar['do']));
                 if (!$subdomains_data['id']) {
                     echo "That subdomain domain doesn't exist!";
                 } else {
                     if ($_POST) {
                         check::empty_fields();
                         if (!main::errors()) {
                             $subdomains_update = array("domain" => $postvar['domain'], "server" => $postvar['server']);
                             $dbh->update("subdomains", $subdomains_update, array("id", "=", $getvar['do']));
                             //Subdomain added
                             main::done();
                         }
                     }
                     $edit_subdomain_array['DOMAIN'] = $subdomains_data['domain'];
                     $servers_query = $dbh->select("servers");
                     while ($servers_data = $dbh->fetch_array($servers_query)) {
                         $values[] = array($servers_data['name'], $servers_data['id']);
                     }
                     $edit_subdomain_array['SERVER'] = main::dropDown("server", $values, $servers_data['server']);
                     echo style::replaceVar("tpl/admin/subdomains/edit-subdomain.tpl", $edit_subdomain_array);
                 }
             } else {
                 $subdomains_query = $dbh->select("subdomains");
                 if ($dbh->num_rows($subdomains_query) == 0) {
                     echo "There are no subdomain domains to edit!";
                 } else {
                     echo "<ERRORS>";
                     while ($subdomains_data = $dbh->fetch_array($subdomains_query)) {
                         echo main::sub("<strong>" . $subdomains_data['domain'] . "</strong>", '<a href="?page=sub&sub=edit&do=' . $subdomains_data['id'] . '"><img src="' . URL . 'themes/icons/pencil.png"></a>');
                     }
                 }
             }
             break;
         case "delete":
             if (isset($getvar['do'])) {
                 $dbh->delete("subdomains", array("id", "=", $getvar['do']));
                 main::errors("Subdomain Deleted!");
             }
             $subdomains_query = $dbh->select("subdomains");
             if ($dbh->num_rows($subdomains_query) == 0) {
                 echo "There are no subdomain domains to delete!";
             } else {
                 echo "<ERRORS>";
                 while ($subdomains_data = $dbh->fetch_array($subdomains_query)) {
                     echo main::sub("<strong>" . $subdomains_data['domain'] . "</strong>", '<a href="?page=sub&sub=delete&do=' . $subdomains_data['id'] . '"><img src="' . URL . 'themes/icons/delete.png"></a>');
                 }
             }
             break;
     }
 }
Esempio n. 27
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);
     }
 }
Esempio n. 28
0
 public function content()
 {
     global $dbh, $postvar, $getvar, $instance;
     switch ($getvar['sub']) {
         default:
             if ($_POST['add']) {
                 $no_check_array = array("resellerport", "welcome", "nstmp", "passtoo", "resellerid");
                 check::empty_fields($no_check_array);
                 if (!main::errors()) {
                     $servers_insert = array("ip" => $postvar['ip'], "resellerport" => $postvar['resellerport'], "port" => $postvar['port'], "nameservers" => $postvar['nameservers'], "name" => $postvar['name'], "host" => $postvar['host'], "user" => $postvar['user'], "accesshash" => $postvar['hash'], "type" => $postvar['type'], "dnstemplate" => $postvar['nstmp'], "welcome" => $postvar['welcome'], "pass" => $postvar['pass'], "reseller_id" => $postvar['resellerid'], "https" => $postvar['https'], "apiport" => $postvar['apiport']);
                     $dbh->insert("servers", $servers_insert);
                     main::errors("Server has been added!");
                 }
             }
             if ($_POST['addtype'] || $_POST['add']) {
                 $serverfile = server::createServer(0, $postvar['type']);
                 $server_fields = $serverfile->acp_form();
                 $add_server_array['SERVER_FIELDS'] = $server_fields;
                 $add_server_array['TYPE'] = $postvar['type'];
                 echo style::replaceVar("tpl/admin/servers/add-server.tpl", $add_server_array);
                 break;
             }
             $files = main::folderFiles(INC . "/servers/");
             foreach ($files as $value) {
                 include INC . "/servers/" . $value;
                 $fname = explode(".", $value);
                 $stype = new $fname[0]();
                 $values[] = array($stype->name, $fname[0]);
             }
             $server_type_array['TYPE'] = main::dropDown("type", $values, 0);
             echo style::replaceVar("tpl/admin/servers/server-type.tpl", $server_type_array);
             break;
         case "view":
             if (isset($getvar['do'])) {
                 $servers_query = $dbh->select("servers", array("id", "=", $getvar['do']), 0, 0, 1);
                 if ($dbh->num_rows($servers_query) == 0) {
                     echo "That server doesn't exist!";
                 } else {
                     if ($_POST) {
                         check::empty_fields();
                         if (!main::errors()) {
                             $servers_update = array("name" => $postvar['name'], "host" => $postvar['host'], "reseller_id" => $postvar['resellerid'], "user" => $postvar['user'], "pass" => $postvar['pass'], "accesshash" => $postvar['hash'], "port" => $postvar['port'], "resellerport" => $postvar['resellerport'], "nameservers" => $postvar['nameservers'], "ip" => $postvar['ip'], "dnstemplate" => $postvar['nstmp'], "welcome" => $postvar['welcome'], "https" => $postvar['https'], "apiport" => $postvar['apiport']);
                             $dbh->update("servers", $servers_update, array("id", "=", $getvar['do']), 1);
                             //Server edit complete
                             main::done();
                         }
                     }
                     $servers_data = $dbh->fetch_array($servers_query);
                     $serverfile = server::createServer(0, $servers_data['type']);
                     $server_fields = $serverfile->acp_form($getvar['do']);
                     $edit_server_array['NAME'] = $servers_data['name'];
                     $edit_server_array['HOST'] = $servers_data['host'];
                     $edit_server_array['SERVERIP'] = $servers_data['ip'];
                     $edit_server_array['RESELLERPORT'] = $servers_data['resellerport'];
                     $edit_server_array['PORT'] = $servers_data['port'];
                     $edit_server_array['NAMESERVERS'] = $servers_data['nameservers'];
                     $edit_server_array['SERVER_FIELDS'] = $server_fields;
                     echo style::replaceVar("tpl/admin/servers/edit-server.tpl", $edit_server_array);
                 }
             } else {
                 $servers_query = $dbh->select("servers");
                 if ($dbh->num_rows($servers_query) == 0) {
                     echo "There are no servers to view!";
                 } else {
                     echo "<ERRORS>";
                     while ($servers_data = $dbh->fetch_array($servers_query)) {
                         echo main::sub("<strong>" . $servers_data['name'] . "</strong>", '<a href="?page=servers&sub=view&do=' . $servers_data['id'] . '"><img src="' . URL . 'themes/icons/magnifier.png"></a>');
                     }
                 }
             }
             break;
         case "delete":
             if ($getvar['do']) {
                 $dbh->delete("servers", array("id", "=", $getvar['do']));
                 main::errors("Server Deleted!");
             }
             $servers_query = $dbh->select("servers");
             if ($dbh->num_rows($servers_query) == 0) {
                 echo "There are no servers to delete!";
             } else {
                 echo "<ERRORS>";
                 while ($servers_data = $dbh->fetch_array($servers_query)) {
                     echo main::sub("<strong>" . $servers_data['name'] . "</strong>", '<a href="?page=servers&sub=delete&do=' . $servers_data['id'] . '"><img src="' . URL . 'themes/icons/delete.png"></a>');
                 }
             }
             break;
         case "test":
             if (isset($getvar["do"])) {
                 $result = server::testConnection($getvar["do"]);
                 if ($result === true) {
                     echo '<div style="text-align:center;padding-top:10px;">' . style::notice(true, "Connected to the server successfully!") . "</div>";
                 } else {
                     echo '<div style="text-align:center;">' . style::notice(false, "Couldn't connect to the server...") . "</div>";
                     echo '<strong>Error:</strong><pre>' . (string) $result . '</pre>';
                 }
             } else {
                 $servers_query = $dbh->select("servers");
                 if ($dbh->num_rows($servers_query) == 0) {
                     echo "There are no servers to view!";
                 } else {
                     echo "Caution: Some servers are set to automatically ban the IP address of this server (" . $_SERVER['SERVER_ADDR'] . ") after a certain number of failed logins.<br />";
                     while ($servers_data = $dbh->fetch_array($servers_query)) {
                         echo main::sub("<strong>" . $servers_data['name'] . "</strong>", '<a href="?page=servers&sub=test&do=' . $servers_data['id'] . '"><img src="' . URL . 'themes/icons/server_chart.png"></a>');
                     }
                 }
             }
             break;
         case "status":
             $server_status_array['EXTRA'] = '';
             if (!main::canRun('shell_exec')) {
                 $server_status_array['EXTRA'] = 'Some statistics could not be provided because shell_exec has been disabled.<br>';
             }
             $server = $_SERVER['HTTP_HOST'];
             $server_status_array['OS'] = php_uname();
             $server_status_array['DISTRO'] = '';
             if (php_uname('s') == 'Linux') {
                 $distro = main::getLinuxDistro();
                 if ($distro) {
                     $server_status_array['DISTRO'] = '<tr><td><strong>Linux Distro:</strong></td><td> ' . $distro . ' </td></tr>';
                 }
             }
             $server_status_array['SOFTWARE'] = getenv('SERVER_SOFTWARE');
             $server_status_array['PHP_VERSION'] = phpversion();
             $server_status_array['MYSQL_VERSION'] = '';
             $mysqlVersion = $dbh->version();
             if ($mysqlVersion) {
                 $server_status_array['MYSQL_VERSION'] = '<tr><td><strong>MySQL Version:</strong><br><br></td><td> ' . $mysqlVersion . ' <br><br></td></tr>';
             }
             $server_status_array['SERVER'] = $server;
             echo style::replaceVar('tpl/admin/servers/server-status.tpl', $server_status_array);
             break;
         case "phpinfo":
             echo server::show_phpinfo();
             break;
     }
 }
Esempio n. 29
0
 private function EditTemplate($tpl, $ext)
 {
     global $dbh, $postvar, $getvar, $instance;
     $filetochange = INC . "/../themes/" . $dbh->config('theme') . "/" . $tpl . "." . $ext;
     if ($_POST) {
         file_put_contents($filetochange, stripslashes(str_replace(array("&lt;IMG>", "-%-INFO-%-"), array("<IMG>", "%INFO%"), $postvar['contents'])));
         main::errors($tpl . '.' . $ext . ' Modified.');
     }
     $tpl_editor_array['CONTENT'] = str_replace(array("<IMG>", "%INFO%"), array("&lt;IMG>", "-%-INFO-%-"), htmlentities(file_get_contents($filetochange)));
     if (is_writable($filetochange)) {
         $tpl_editor_array['NOTICE'] = '';
     } else {
         $tpl_editor_array['NOTICE'] = style::notice(false, "In order to make changes to this file, please make it writable.");
     }
     return style::replaceVar('tpl/admin/lof/' . $tpl . '-editor.tpl', $tpl_editor_array);
 }
Esempio n. 30
0
    if (FOLDER != "install") {
        $navbar_query = $dbh->select("navbar", 0, array("sortorder", "ASC"));
        while ($navbar_data = $dbh->fetch_array($navbar_query)) {
            $navigation_link_array['ID'] = "nav_" . $navbar_data['name'];
            $navigation_link_array['LINK'] = $navbar_data['link'];
            $navigation_link_array['ICON'] = $navbar_data['icon'];
            $navigation_link_array['NAME'] = $navbar_data['visual'];
            $navigation .= style::replaceVar("tpl/navigation-link.tpl", $navigation_link_array);
        }
    }
}
/**********************************************************************/
$page_data = preg_replace("/<THT TITLE>/si", NAME . " :: " . PAGE . " - " . SUB, $page_data);
$page_data = preg_replace("/<NAME>/si", NAME, $page_data);
$page_data = preg_replace("/<CSS>/si", self::css(), $page_data);
$page_data = preg_replace("/<JAVASCRIPT>/si", self::javascript(), $page_data);
$page_data = preg_replace("/<WYSIWYG_EDITOR>/si", "<URL>includes/tinymce/tinymce.min.js", $page_data);
$page_data = preg_replace("/<WYSIWYG_PLUGS>/si", "advlist autolink autoresize hr link searchreplace table", $page_data);
$page_data = preg_replace("/<WYSIWYG_LANG>/si", "", $page_data);
$page_data = preg_replace("/<MENU>/si", $navigation, $page_data);
$page_data = preg_replace("/<URL>/si", URL, $page_data);
$page_data = preg_replace("/<AJAX>/si", URL . "includes/ajax.php", $page_data);
$page_data = preg_replace("/<IMG>/si", URL . "themes/" . THEME . "/images/", $page_data);
$page_data = preg_replace("/<ICONDIR>/si", URL . "themes/icons/", $page_data);
$page_data = preg_replace("/<PAGEGEN>/si", $pagegen, $page_data);
$page_data = preg_replace("/<COPYRIGHT>/si", '<div id="footer">Powered by <a href="http://thehostingtool.com/" target="_blank">TheHostingTool</a> ' . $version . '</div>', $page_data);
$page_data = preg_replace("/<ERRORS>/si", '<span class="errors">' . main::errors() . '</span>', $page_data);
$page_data = preg_replace("/%INFO%/si", INFO, $page_data);
$page_data = preg_replace("/-%-INFO-%-/si", "%INFO%", $page_data);
$page_data = preg_replace("/<CSRF_NAME>/si", $GLOBALS['csrf']['input-name'], $page_data);
$page_data = preg_replace("/<ADMINDIR>/si", ADMINDIR, $page_data);