public function cron() { global $dbh, $postvar, $getvar, $instance; if ($dbh->config("p2hcheck") == "") { // Probably a new install. Cron has never run before. $dbh->updateConfig("p2hcheck", "0:0:0"); } $checkdate = explode(":", $dbh->config("p2hcheck")); if ($checkdate === array($dbh->config("p2hcheck"))) { $dbh->updateConfig("p2hcheck", $dbh->config("p2hcheck") . ":0:0"); $checkdate = explode(":", $dbh->config("p2hcheck")); } elseif (array_key_exists(1, $checkdate)) { if ($checkdate[1] == "") { $dbh->updateConfig("p2hcheck", $checkdate[0] . ":0:0"); $checkdate = explode(":", $dbh->config("p2hcheck")); } } // If today is the last day of the month (and hasn't been run yet) if (date("d") == date("t") && ((int) $checkdate[0] < (int) date("m") || (int) $checkdate[0] == (int) date("m") && $checkdate[2] == "0")) { $users_query = $dbh->select("users"); while ($users_data = $dbh->fetch_array($users_query)) { //Skip this user if its marked as a free user. if ($users_data['freeuser']) { continue; } $ptype = type::packagetype($users_data['pid']); if ($ptype == "p2h") { $fuser = type::userAdditional($users_data['id']); $forum = type::additional($users_data['pid'], 'forum'); $this->con = $this->forumCon($forum); $posts = coupons::totalposts($users_data['id']); $mposts = $this->getMonthly($users_data['pid'], $users_data['id']); if ($posts < $mposts) { // If the user haven't posted enough... $user = $dbh->client($users_data['id']); $grace_period = $dbh->config("p2hgraceperiod"); //The grace period in days $grace_period = $grace_period * 24 * 60 * 60; if (strtotime(date("Y-m-d") . " 00:00:00") > $users_data['signup'] + $grace_period) { //This gives the user a grace period. // Suspend the user. server::suspend($users_data['id'], "Only posted {$posts} post out of the required {$mposts} monthly posts"); // Output to the cron. echo "<strong>" . $user['user'] . " (" . $fuser['fuser'] . "):</strong> Suspended for not posting the required amount. ({$posts} out of {$mposts})<br />"; } } } } // We're done for this month. Prepare for the next. if (date("m") == 12) { $checkmonth = "0"; } else { $checkmonth = date("m"); } } elseif ((int) date("d") == $dbh->config("p2hwarndate") && (int) $checkdate[1] != 1) { $users_query = $dbh->select("users"); while ($users_data = $dbh->fetch_array($users_query)) { //Skip this user if its marked as a free user. if ($users_data['freeuser']) { continue; } $ptype = type::packagetype($users_data['pid']); if ($ptype == "p2h") { $fuser = type::userAdditional($users_data['id']); $forum = type::additional($users_data['pid'], 'forum'); $this->con = $this->forumCon($forum); $posts = coupons::totalposts($users_data['id']); $posts_text = main::s($posts, " Post"); $mposts = $this->getMonthly($users_data['pid'], $users_data['id']); $mposts_text = main::s($mposts, " post"); $config_url_data = $dbh->select("p2h", array("forumname", "=", $forum)); $furl = $config_url_data['value']; // If the user hasn't posted enough yet $grace_period = $dbh->config("p2hgraceperiod"); //The grace period in days $grace_period = $grace_period * 24 * 60 * 60; $userinfo = $dbh->client($users_data['id']); $signup_date = $userinfo['signup']; if (date("m") != date("m", $signup_date + $grace_period)) { //If they won't be suspended on this months check, then we don't need to warn them. $no_email = 1; } if ($posts < $mposts && !$no_email) { $emaildata = email::emailTemplate("p2h-low-post-warning"); $p2hwarning_array['USERPOSTS'] = $posts; $p2hwarning_array['MONTHLY'] = $mposts; $p2hwarning_array['URL'] = $furl; // Warn the user that they still have some more posting to do! email::send($users_data['email'], $emaildata['subject'], $emaildata['content'], $p2hwarning_array); // Output to the cron. echo "<strong>" . $users_data['user'] . " (" . $fuser['fuser'] . "):</strong> Warned for not yet posting the required monthly amount. ({$posts_text} posted out of {$mposts_text}/month)<br />"; } } } // This prevents the post warnings from being sent again today/this month. $dbh->updateConfig("p2hcheck", $checkdate[0] . ":1:0"); } }
private function SuspendClient($client) { global $dbh, $postvar, $getvar, $instance; if (!$postvar['submitreason']) { $reason_array['WARNTEXT'] = 'Please state your reason for suspending this client. Leave it blank if you just feel like suspending them for the fun of it.'; $reason_array['ACTION'] = 'suspending'; $reason_array['ACTIONBUTT'] = 'Suspend Client'; $clientview_array['BOX'] = ""; $clientview_array['CONTENT'] = style::replaceVar("tpl/admin/clients/reason.tpl", $reason_array); return $clientview_array; } else { $command = server::suspend($client['id'], $postvar['reason']); if ($command === true) { main::redirect("?page=users&sub=search&do=" . $client['id']); } else { main::errors($command); } } }
public function cron() { global $dbh, $postvar, $getvar, $instance; $packages_query = $dbh->select("packages", array("type" => "paid"), 0, 0, 1); $packages_num_rows = $dbh->num_rows($packages_query); //Do we have paid packages? if ($packages_num_rows) { while ($packages_data = $dbh->fetch_array($packages_query)) { $i++; //Do we have multiple packages and aren't on the last one? if ($packages_data < $i) { //Did we already pull one package? If so, we don't set the flag for the parenthesis. if ($pulled_one) { $where[] = array("pid", "=", $packages_data['id'], "OR"); //We are on the first listing of the paid packages, so we set the flag for the opening parenthesis and mark it that we pulled one already. } else { $where[] = array("pid", "=", $packages_data['id'], "OR", 1); $pulled_one = 1; } } else { //Are we on the last listing of paid listings? If so, we close the parenthesis by setting that flag. if ($pulled_one) { $where[] = array("pid", "=", $packages_data['id'], "", 1); //We only had one listing, so we don't use parenthesis and we don't use "OR." } else { $where[] = array("pid", "=", $packages_data['id']); } } //So we can later grab the package's information without needing to repull this data. $packages_info[$packages_data['id']] = $packages_data; } $time = time(); //Look at every last invoice. $invoices_query = $dbh->select("invoices"); while ($invoices_data = $dbh->fetch_array($invoices_query)) { $uid = $invoices_data['uid']; $client = $dbh->client($uid); //Skip this invoice if it belongs to a user marked as a free user. if ($client['freeuser']) { continue; } //If the invoice is older than 30 days and we haven't issued a new invoice yet... (This makes sure the user is still on the package //before issuing a new invoice for it.) if ($time > $invoices_data['created'] + 2592000 && !in_array($uid, $invoiced_to) && $invoices_data['pid'] == $client['pid']) { $pack_additional = type::additional($client['pid']); $amount = coupons::get_discount("paid", $pack_additional['monthly'], $client['user']); invoice::create($uid, $amount, $time, "Your hosting package invoice for this billing cycle. Package: " . $packages_info[$client['pid']]['name']); $invoiced_to[] = $uid; //Track what clients have been sent a new invoice. } $lastmonth = $time - 2592000; $suspenddays = $dbh->config('suspensiondays'); $terminationdays = $suspenddays + $dbh->config('terminationdays'); $suspendseconds = $suspenddays * 24 * 60 * 60; $terminateseconds = $dbh->config('terminationdays') * 24 * 60 * 60; //If we have an unpaid bill that's greater than $0 and it's past it's due date... if ($invoices_data['due'] < $time and $invoices_data['is_paid'] == 0 && $invoices_data['amount'] > 0) { //If we have a bill that's overdue by $terminationdays + $suspenddays, then we terminate the account... if ($time - $suspendseconds - $terminateseconds > $invoices_data['due']) { server::terminate($uid, "Your account was overdue for more than " . $terminationdays . " days."); $checked_term = 1; //If we have a bill that's overdue by $suspenddays and the client is active, then we suspend them... //Just an FYI, if I start(ed) charging for this script, check The Pirate Bay for this script as I always upload my payware stuff there since I know not everyone can afford to pay me. } elseif ($time - $suspendseconds > $invoices_data['due'] && $client['status'] == '1') { server::suspend($uid, "Your account is overdue. Please log in and pay your invoice to bring your account out of suspension."); } } } //If the user does not have an invoice yet and never had one, this will create one for them. The portion above //handles creating NEW invoices. (It checks for outdated ones and such.) $users_query = $dbh->select("users", $where, 0, 0, 1); while ($users_data = $dbh->fetch_array($users_query)) { //Skip this user if its marked as a free user. if ($users_data['freeuser']) { continue; } $invoice_data = $dbh->select("invoices", array("pid", "=", $users_data['pid'])); if (!$invoice_data['id']) { $monthly = type::additional($users_data['pid']); $amount = $monthly['monthly']; $amount = coupons::get_discount("paid", $amount, $users_data['id']); invoice::create($users_data['id'], $amount, $time + 30 * 24 * 60 * 60, "Your hosting package invoice for this billing cycle. Package: " . $packages_info[$users_data['pid']]['name']); // Create Invoice +30 Days } } } }