예제 #1
0
function maintSwitch()
{
    //All date and time values stored in mysql should be in UTC.
    global $debug, $message, $success, $Dbc;
    $output = '';
    try {
        if (MODE == 'setMaintMode') {
            if (empty($_POST['maintModeStartTime']) || empty($_POST['maintModeEndTime'])) {
                $params = array($_SESSION['userId'], null, null);
            } else {
                $maintModeStartTime = Adrlist_Time::localToUtc($_POST['maintModeStartTime'], false);
                $maintModeStartTime = $maintModeStartTime->format('Y-m-d H:i:s');
                $maintModeEndTime = Adrlist_Time::localToUtc($_POST['maintModeEndTime'], false);
                $maintModeEndTime = $maintModeEndTime->format('Y-m-d H:i:s');
                $params = array($_SESSION['userId'], $maintModeStartTime, $maintModeEndTime);
            }
            $stmt = $Dbc->prepare("UPDATE\n\tadminControl\nSET\n\tuserId = ?,\n\tmaintModeStartTime = ?,\n\tmaintModeEndTime = ?");
            $stmt->execute($params);
            $success = true;
            pdoError(__LINE__, $stmt, $params, 0);
            returnData();
        } else {
            $stmt = $Dbc->query("SELECT\n\tmaintModeStartTime AS 'maintModeStartTime',\n\tmaintModeEndTime AS 'maintModeEndTime'\nFROM\n\tadminControl");
            $row = $stmt->fetch(PDO::FETCH_ASSOC);
            $startTimeDisplay = TIMESTAMP > strtotime($row['maintModeStartTime']) ? TIMESTAMP : $row['maintModeStartTime'];
            $startTimeDisplay = Adrlist_Time::utcToLocal($startTimeDisplay, false)->format('F d, Y H:i:s');
            $endTimeDisplay = Adrlist_Time::addToDate(TIMESTAMP, 'hour', 1);
            $endTimeDisplay = TIMESTAMP > strtotime($row['maintModeEndTime']) ? $endTimeDisplay : $row['maintModeEndTime'];
            $endTimeDisplay = Adrlist_Time::utcToLocal($endTimeDisplay, false)->format('F d, Y H:i:s');
            $output .= '			<p>
				Maintenance mode will prevent all non-admin user access to the authorized sections of the site. It is highly recommended that this mode be used to perform updates and changes to the site.
			</p>
			<p>
				Both must be valid dates for maint mode to function. All dates are shown in local time according to your saved timezone setting.
			</p>
			<div class="center textCenter">
				<div class="ui-field-contain">
					<label class="bold" for="maintModeStartTime">Start on</label>
					<input type="text" id="maintModeStartTime" value="' . $startTimeDisplay . '">
				</div>
				<button class="ui-btn ui-btn-inline ui-btn-a ui-shadow ui-corner-all" id="clearMaintModeStartTime">Clear</button>
				<div class="ui-field-contain">
					<label class="bold" for="maintModeEndTime">End on</label>
					<input type="text" id="maintModeEndTime" value="' . $endTimeDisplay . '">
				</div>
				<button class="ui-btn ui-btn-inline ui-btn-a ui-shadow ui-corner-all" id="clearMaintModeEndTime">Clear</button>
				<button class="ui-btn ui-btn-inline ui-btn-a ui-shadow ui-corner-all" id="maintModeSave">Save</button>
			</div>
';
        }
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
        returnData();
    }
    return $output;
}
예제 #2
0
function changePlan()
{
    //The user has an active plan and wants to change to another plan.
    global $debug, $message, $success, $Dbc, $returnThis;
    $output = '';
    try {
        //See if the user currently has an active plan or promotion. The userId is a unique field, so only one billing record can exist per user.
        $calculateRefund = Adrlist_Billing::calculateRefund($_SESSION['userId']);
        if (!is_array($calculateRefund)) {
            throw new Adrlist_CustomException('', '$calculateRefund returned false.');
        }
        $debug->printArray($calculateRefund, '$calculateRefund');
        $calculateRefund['refundAmount'] = '$' . $calculateRefund['refundAmount'];
        $beginningDate = Adrlist_Time::utcToLocal($calculateRefund['userPlanArray']['dateAdded'], false)->format('M j, Y');
        //Return a DateTime object.
        $nextBillingDate = Adrlist_Time::addToDate($calculateRefund['userPlanArray']['dateAdded'], $calculateRefund['userPlanArray']['period'], $calculateRefund['userPlanArray']['length']);
        $nextBillingDate = Adrlist_Time::utcToLocal($nextBillingDate, false)->format('M j, Y');
        //Return a DateTime object.
        $output .= '<div class="textMedium textLeft" style="margin:2em;line-height:1.5em">
Please select a new plan. You current plan is <span class="bold">' . $calculateRefund['userPlanArray']['name'] . '</span>.<br>
You will directed to the payment processor to authorize a new payment and will receive a credit in the form of a pro-rated refund for the remainder of the current billing period.
<br>
<br>
' . $calculateRefund['daysRemaining'] . ' of ' . $calculateRefund['billingPeriodDays'] . ' days remaining in this billing period (' . $beginningDate . ' to ' . $nextBillingDate . ').<br>
Refund Amount: ' . $calculateRefund['refundAmount'] . '
</div>' . buildBillingOffers();
        $returnThis['billingOfferId'] = $calculateRefund['userPlanArray']['billingOfferId'];
        $returnThis['output'] = $output;
        $success = true;
        //Work to be done here.
    } catch (Adrlist_CustomException $e) {
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    if (MODE == 'changePlan') {
        returnData();
    }
}
예제 #3
0
function buildAmazonBilling()
{
    global $debug, $message, $success, $Dbc, $returnThis;
    $output = '';
    try {
        //See if the user has an account.
        $accountCheckCountStmt = "SELECT\n\tCOUNT(*) AS 'count'\nFROM\n\tbillingOffers\nJOIN\n\tuserBilling ON userBilling.billingOfferId = billingOffers.billingOfferId\nJOIN\n\tusers ON users.userId = userBilling.userId\nWHERE\n\tbillingOffers.renewable = 1";
        $accountCheckStmt = "SELECT\n\tuserBilling.userId AS 'userId',\n\t(SELECT CONCAT_WS(' ', users.firstName, users.lastName)) as 'userName',\n\tbillingOffers.billingOfferId AS 'billingOfferId',\n\tbillingOffers.offerName AS 'planName',\n\tbillingOffers.period AS 'period',\n\tuserBilling.dateAdded AS 'dateAdded'\nFROM\n\tbillingOffers\nJOIN\n\tuserBilling ON userBilling.billingOfferId = billingOffers.billingOfferId\nJOIN\n\tusers ON users.userId = userBilling.userId\nWHERE\n\tbillingOffers.renewable = 1";
        if (empty($_POST['searchVal'])) {
            $search = false;
            $accountCheckParams = array();
            $accountCheckCountStmt = $Dbc->prepare($accountCheckCountStmt);
        } else {
            $search = true;
            $searchVal = '%' . trim($_POST['searchVal']) . '%';
            $debug->add('$searchval: ' . $searchVal);
            $endStmt = " AND\n\t(users.firstName LIKE ? || users.lastName LIKE ? || billingOffers.offerName LIKE ?)\n";
            $accountCheckStmt .= $endStmt;
            $accountCheckParams = array($searchVal, $searchVal, $searchVal);
            $accountCheckCountStmt = $Dbc->prepare($accountCheckCountStmt . $endStmt);
        }
        $accountCheckCountStmt->execute($accountCheckParams);
        $count = $accountCheckCountStmt->fetch(PDO::FETCH_ASSOC);
        $itemCount = $count['count'];
        $pagination = new Adrlist_Pagination('buildAmazonBilling', 'buildAmazonBilling', $itemCount, 'Search Billing', $search);
        list($offset, $limit) = $pagination->offsetLimit();
        $accountCheckStmt .= "\nLIMIT {$offset}, {$limit}";
        $accountCheckStmt = $Dbc->prepare($accountCheckStmt);
        $accountCheckStmt->execute($accountCheckParams);
        $userPlans = array();
        $foundRows = false;
        while ($row = $accountCheckStmt->fetch(PDO::FETCH_ASSOC)) {
            $foundRows = true;
            //Add the question to the user's support section.
            if ($row['period'] == 'month') {
                $date = Adrlist_Time::addToDate($row['dateAdded'], $row['period'], 1);
                $row[] = $date = $date->format('Y-m-d');
            } elseif ($row['period'] == 'year') {
                $date = Adrlist_Time::addToDate($row['dateAdded'], $row['period'], 1);
                $row[] = $date = $date->format('Y-m-d');
            }
            $userPlans[] = $row;
        }
        $cssWidths = array(3, 20, 10, 20, 5, 20, 20);
        $titleRowArray = array('userId', 'User', 'billingOfferId', 'Plan Name', 'Period', 'Date Added', 'Next Billing Date');
        $buildRows = new Adrlist_BuildRows($titleRowArray, $userPlans, $cssWidths);
        $output .= '<div>
	<input type="text" style="width:20em" id="billingDate"> Date <span class="buttonBlueThin" id="addMonth">Add a Month</span> <input type="text" id="dateDestination">
</div>' . $pagination->output();
        $output .= $foundRows ? $buildRows->output() : '<div class="textCenter" style="margin:1em">No records were found.</div>';
        if (MODE == 'buildAmazonBilling') {
            $success = true;
            $returnThis['holder'] = 'amazonBillingHolder';
            $returnThis['output'] = $output;
        }
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    if (MODE == 'buildAmazonBilling') {
        returnData();
    } else {
        return $output;
    }
}
예제 #4
0
 public static function getUserPlan($userId)
 {
     global $debug, $Dbc;
     try {
         if (empty($userId)) {
             throw new Adrlist_CustomException('', '$userId is empty.');
         } elseif (!is_numeric($userId)) {
             throw new Adrlist_CustomException('', '$userId is not numeric.');
         }
         $checkPlansStmt = $Dbc->prepare("SELECT\n\tbillingOffers.billingOfferId AS 'billingOfferId' ,\n\tbillingOffers.offerName AS 'name' ,\n\tbillingOffers.offerType AS 'type',\n\tbillingOffers.terms AS 'terms',\n\tbillingOffers.offerLength AS 'length',\n\tbillingOffers.period AS 'period',\n\tbillingOffers.renewable AS 'renewable',\n\tbillingOffers.credits AS 'credits',\n\tbillingOffers.startDate AS 'startDate',\n\tbillingOffers.endDate AS 'endDate',\n\tuserBilling.userBillingId AS 'userBillingId',\n\tuserBilling.userBillingActionId AS 'userBillingActionId',\n\tuserBilling.dateAdded AS 'dateAdded'\nFROM\n\tbillingOffers\nJOIN\n\tuserBilling ON userBilling.billingOfferId = billingOffers.billingOfferId AND\n\tuserBilling.userId = ?");
         $checkPlansStmt->execute(array($userId));
         $plansCount = 0;
         $credits = 0;
         while ($row = $checkPlansStmt->fetch(PDO::FETCH_ASSOC)) {
             //Check whether the plan or promotion has expired.
             $expires = Adrlist_Time::addToDate($row['dateAdded'], $row['period'], $row['length']);
             $expires = $expires->getTimestamp();
             $validCredit = false;
             if (empty($row['startDate']) && empty($row['endDate'])) {
                 $validCredit = true;
             } else {
                 if (!empty($row['startDate'])) {
                     $validCredit = strtotime($row['startDate']) <= strtotime($row['dateAdded']) ? true : false;
                 }
                 if (!empty($value['endDate'])) {
                     $validCredit = strtotime($row['endDate']) >= strtotime($row['dateAdded']) ? true : false;
                 }
             }
             if (!$row['renewable'] && $expires < TIMESTAMP) {
                 //A non-renewable plan or promotion has expired.
                 $validCredit = false;
             }
             $row['validCredit'] = $validCredit;
             $credits = $validCredit ? $credits + $row['credits'] : $credits;
             $userBillingInfo[] = $row;
             $plansCount++;
         }
         $userBillingInfo['credits'] = $credits;
         if ($plansCount > 1) {
             throw new Adrlist_CustomException('', 'The user has more than one active plan or promotion, which shouldn\'t be possible.');
         }
     } catch (Adrlist_CustomException $e) {
     } catch (PDOException $e) {
         $debug->add('<pre>' . $e . '</pre>');
         error(__LINE__, '', '');
     }
     return empty($userBillingInfo) ? false : $userBillingInfo;
 }