function buildBilling()
{
    //Build the billing info including credits and expiration date.
    global $debug, $message, $success, $Dbc, $returnThis;
    $output = '';
    try {
        if (empty($_SESSION['userId'])) {
            throw new Adrlist_CustomException('', '$_SESSION[\'userId\'] is empty.');
        }
        //Refresh credits.
        reconcileLists($_SESSION['userId']);
        $userPlan = Adrlist_Billing::getUserPlan($_SESSION['userId']);
        $purchasedPlan = false;
        $hiddenRows = array();
        $billingOutput = '';
        $foundRows = false;
        if (count($userPlan) > 1) {
            $nameLength = 0;
            $billingPlansArray = array();
            $billingPlansHiddenArray = array();
            foreach ($userPlan as $key => $value) {
                $debug->add('key: ' . $key);
                if (is_numeric($key) && $value['validCredit']) {
                    $foundRows = true;
                    if ($value['validCredit']) {
                        $purchasedPlan = $value['type'] == 'plan' ? true : $purchasedPlan;
                    }
                    $newDate = Adrlist_Time::addToDate($value['dateAdded'], $value['period'], $value['length']);
                    $newDate = Adrlist_Time::utcToLocal($newDate, false)->format('F j, Y');
                    if ($value['type'] == 'plan') {
                        $nextBillingDate = $newDate;
                        $expires = 'N/A';
                    } else {
                        $nextBillingDate = 'N/A';
                        $expires = $newDate;
                    }
                    $nameLength = strlen($value['name']) > $nameLength ? strlen($value['name']) * 0.8 : $nameLength;
                    $billingOutput .= '
<div class="columnParent">
	<div class="break">
		<div class="columnLeft" style="font-weight:none">
			Billing Plan:
		</div>
		<div class="columnRight">
			' . $value['name'] . '
		</div>
	</div>
	<div class="break">
		<div class="columnLeft">
			Next Billing Date:
		</div>
		<div class="columnRight">
			' . $nextBillingDate . '
		</div>
	</div>
	<div class="break">
		<div class="columnLeft">
			Credits:
		</div>
		<div class="columnRight">
			' . $value['credits'] . '
		</div>
	</div>
	<div class="break">
		<div class="columnLeft">
			Expires:
		</div>
		<div class="columnRight">
			' . $expires . '
		</div>
	</div>
</div>
<button class="ui-btn ui-mini ui-btn-icon-right ui-icon-carat-r ui-btn-inline ui-corner-all"  toggle="planTerms' . $value['userBillingId'] . '">Plan Terms</button>
<div class="hide" id="planTerms' . $value['userBillingId'] . '">
	<div class="textLeft" style="margin:1em"><br>
		' . nl2br($value['terms']) . '
	</div>
</div>';
                    /*Currently not used.
                    					$name = '<button class="ui-btn ui-mini ui-btn-icon-right ui-icon-carat-r ui-btn-inline ui-corner-all" toggle="billingPlanAction' . $value['userBillingId'] . '">' . $value['name'] . '</button>';
                    					$billingPlansArray[$value['userBillingId']] = array(
                    						$name,
                    						$nextBillingDate,
                    						$value['credits'],
                    						$expires
                    					);
                    					$billingPlanActions = '<div class="break">Plan Actions</div>
                    <button class="changePaymentCard ui-btn ui-btn-inline ui-corner-all ui-mini"><i class="fa fa-credit-card" ></i>Change Payment Card</button><button class="changePlan ui-btn ui-btn-inline ui-corner-all ui-mini"><i class="fa fa-credit-card" ></i>Change Plan</button>
                    
                    <button class="ui-btn ui-mini ui-btn-icon-right ui-icon-carat-r ui-btn-inline ui-corner-all"  toggle="planTerms' . $value['userBillingId'] . '">Plan Terms</button>
                    <div class="hide" id="planTerms' . $value['userBillingId'] . '">
                    	<div class="textLeft" style="margin:1em"><br>
                    		' . nl2br($value['terms']) . '
                    	</div>
                    </div>';
                    					$billingPlansHiddenArray[$value['userBillingId']] = array('billingPlanAction' . $value['userBillingId'],$billingPlanActions);*/
                }
            }
            /*if($foundRows){
            			$titleArray = array(
            				array('Name'),
            				array('Next Billing Date',1),
            				array('Credits',2),
            				array('Expires',3)
            			);
            			$buildBillingRows = new Adrlist_BuildRows('billingPlans',$titleArray,$billingPlansArray);
            			$buildBillingRows->addHiddenRows($billingPlansHiddenArray);
            			$billingOutput .= $buildBillingRows->output();
            		}*/
        }
        if (!$foundRows) {
            $billingOutput = '<div style="margin:1em">This account doesn\'t have any active plans or promotions.</div>';
        }
        $billingOutput .= $purchasedPlan ? '<button class="changePaymentCard ui-btn ui-btn-inline ui-corner-all ui-mini"><i class="fa fa-credit-card" ></i>Change Payment Card</button><button class="changePlan ui-btn ui-btn-inline ui-corner-all ui-mini"><i class="fa fa-credit-card" ></i>Change Plan</button>
' : '<button class="ui-btn ui-btn-icon-left ui-btn-inline ui-corner-all ui-mini ui-shadow" id="addCredits">Add Credits</button>';
        $output .= '<button class="buildBillingHistory ui-btn ui-btn-icon-left ui-btn-inline ui-corner-all ui-icon-clock ui-mini ui-shadow">Billing History</button><div class="myAccountTitle textCenter">
	Billing
</div>
<div class="textCenter">
' . $billingOutput . '
	<div class="columnParent">
		<div class="break">
			<div class="columnLeft" style="font-weight:none">
				Credits:
			</div>
			<div class="columnRight">
				' . $_SESSION['credits'] . '
			</div>
		</div>
		<div class="break">
			<div class="columnLeft">
				Active Lists:
			</div>
			<div class="columnRight">
				' . $_SESSION['activeLists'] . '
			</div>
		</div>
		<div class="hr2"></div>
		<div class="break">
			<div class="columnLeft">
				Credit Balance:
			</div>
			<div class="columnRight">
				' . ($_SESSION['credits'] - $_SESSION['activeLists']) . '
			</div>
		</div>
	</div>
</div>';
        if (MODE == 'buildBilling') {
            $success = true;
            $returnThis['buildBilling'] = $output;
        }
    } catch (Adrlist_CustomException $e) {
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    if (MODE == 'buildBilling') {
        returnData();
    } else {
        return $output;
    }
}
Beispiel #2
0
     setSessionVariables($row);
 }
 if (isset($_SESSION['siteRoleId']) && empty($_SESSION['siteRoleId'])) {
     //The user has been implicitley denied access to the site.
     destroySession();
     header('Location: ' . LINKLOGIN . '/?logout=1');
 } elseif ($_SESSION['auth']) {
     //The user is logged in.
     $debug->add('6');
     define('NAME', $_SESSION['firstName'] . ' ' . $_SESSION['lastName'], 1);
     //getMaintMode();
     if ($_SESSION['siteRoleId'] == 5) {
         setcookie('noGoogleAnalytics', 'donotcountme', time() + 60 * 60 * 24 * 365, COOKIEPATH, COOKIEDOMAIN, false);
         //1 year
     }
     reconcileLists($_SESSION['userId']);
     //Reconcile lists credit balance.
     //Update the cookie
     if (empty($uniqueId)) {
         setcookie(UNIQUECOOKIE, $_SESSION[UNIQUECOOKIE], time() + 60 * 60 * 24 * 365, COOKIEPATH, COOKIEDOMAIN, false);
         //1 year
         $debug->add('Just set ' . UNIQUECOOKIE . ' cookie.');
     } else {
         setcookie(UNIQUECOOKIE, $uniqueId, time() + 60 * 60 * 24 * 365, COOKIEPATH, COOKIEDOMAIN, false);
         //1 year
     }
     if (stripos($_SERVER['PHP_SELF'], '/login/') !== false) {
         //If the user is on the login page, redirect to the admin section.
         $debug->add('9');
         if (empty($row['viewListOnLogin'])) {
             $location = empty($message) ? LINKADRLISTS : LINKADRLISTS . '?message=' . $message;
function unlockList()
{
    global $debug, $message, $success, $Dbc, $returnThis;
    try {
        if (empty($_POST['listId'])) {
            throw new Adrlist_CustomException('', '$_POST[\'listId\'] is empty.');
        } elseif (empty($_SESSION['credits'])) {
            throw new Adrlist_CustomException('You don\'t have any credits. Credits can be purchased in <a href="' . LINKMYACCOUNT . '" data-ajax="false">My Account</a>', '$_SESSION[\'credits\'] is empty.');
        }
        $listInfo = getListInfo($_SESSION['userId'], $_POST['listId']);
        if ($listInfo['listRoleId'] < 4) {
            throw new Adrlist_CustomException('Your role does not allow you to unlock this list.', '$listInfo[\'listRoleId\']: ' . $listInfo['listRoleId']);
        }
        $unlockStmt = $Dbc->prepare("UPDATE\n\tlists\nSET\n\tlocked = 0\nWHERE\n\tlistId = ?");
        $unlockStmt->execute(array($_POST['listId']));
        updateListHist($_POST['listId']);
        $locked = reconcileLists($_SESSION['userId']);
        if (MODE == 'unlockList') {
            $success = true;
            $returnThis['locked'] = $locked;
            $returnThis['buildLists'] = buildLists();
        }
    } catch (Adrlist_CustomException $e) {
    } catch (PDOException $e) {
        error(__LINE__, '', '<pre>' . $e . '</pre>');
    }
    if (MODE == 'unlockList') {
        returnData();
    }
}