function fetchOrderDetail($id) { require_once PATH_CORE . '/classes/orders.class.php'; require_once PATH_CORE . '/classes/prizes.class.php'; $orderTable = new OrderTable($this->db); $order = $orderTable->getRowObject(); $prizeTable = new PrizeTable($this->db); $prize = $prizeTable->getRowObject(); if ($order->load($id) && $prize->load($order->prizeid) && $order->userid == $this->page->session->u->userid) { switch ($order->status) { default: case 'refunded': $tablecode .= '<tr><td>refunded</td><td>' . $order->dateRefunded . '</td></tr>'; case 'canceled': $tablecode .= '<tr><td>canceled</td><td>' . $order->dateCanceled . '</td></tr>'; case 'shipped': $tablecode .= '<tr><td>shipped</td><td>' . $order->dateShipped . '</td></tr>'; case 'approved': $tablecode .= '<tr><td>approved</td><td>' . $order->dateApproved . '</td></tr>'; case 'submitted': $tablecode .= '<tr><td>submitted</td><td>' . $order->dateSubmitted . '</td></tr>'; } $code = ' <div id="readStoryList"> <div class="panel_block"> <div class="thumb">' . template::buildLinkedRewardPic($prize->id, $prize->thumbnail, 180) . '</div> <div class="storyBlockWrap clearfix"> <p class="storyHead">Order #' . $id . ': ' . template::buildRewardLink($prize->title, $prize->id) . '</p> <div class="storyBlockMeta"> <p class="pointValue">Redeemed ' . $order->pointCost . ' <span class="pts">pts</span></p> </div><!--end "storyBlockMeta"-->' . '<p>Reviewed by: ' . $order->reviewedBy . '</p>' . '<!--<p class="storyCaption">--><p>' . '<table> <tr><th>Status</th><th>Date</th></tr>' . $tablecode . '</table>' . '</p>' . '</div><!--end "storyBlockWrap"--> </div><!--end "panel_block"--> </div><!--end "readStoryList"--> '; } else { $code .= $this->page->buildMessage('error', "There was a problem retreiving your order record", "Invalid order id={$id}, bad prizeid={$prize->id}, or unauthorized userid={$userid}"); } $code = '<div class="">' . $code . '</div>'; //$code .= 'TODO: We did this panel goes here:'; return $code; }
function fetch() { echo "DBTest Page\n"; $code .= $this->userTest(); return $code; // make a new data access object $prizeTable = new PrizeTable($this->db); $prize = $prizeTable->getRowObject(); // $prize = new Prize($this->db); $prize->{'title'} = "Shiny Ball Toy"; $prize->{'description'} = "A shiny ball"; $prize->{'initialStock'} = 3; $prize->{'currentStock'} = 1; $prize->shortName = "ASHortName"; $id = $prize->insert(); echo "New prize id = {$id}\n"; echo "<pre>"; print_r($this->fetchTableRowById("Prizes", $id)); echo "</pre>"; // now change the record we created and update it $prize->{'description'} = "A shiny ball WITH SPIKES"; $prize->{'currentStock'} = 666; $prize->update(); // use a handy logic function we added to the derived class $prize->decreaseStock(); echo "<pre>"; print_r($this->fetchTableRowById("Prizes", $id)); echo "</pre>"; // load a different record by given id $prize->load(2); echo "<pre>"; print_r($this->fetchTableRowById("Prizes", 3)); print_r($prize); echo "</pre>"; // now delete the one we created earlier $prize->id = $id; $prize->delete(); // try to fetch it, find out its gone! echo "<pre>"; print_r($this->fetchTableRowById("Prizes", $id)); echo "</pre>"; $code .= '<div id="pageContent">'; $code .= '</div><!-- end pageContent -->'; return $code; }
if (isset($_GET['mode'])) { $mode = $_GET['mode']; } else { $mode = 'all'; } switch ($mode) { case 'weekly': $where = 'isWeekly=1'; break; case 'grand': $where = 'isGrand>0'; break; default: $where = '1'; } $prize = $pt->getRowObject(); $prizes = $pt->getPrizeList($where, 'dateEnd'); //$prizes['test']=100; foreach ($prizes as $id => $title) { $prize->load($id); echo "<option value='{$prize->id}'>{$prize->title} - {$prize->dateEnd}</option>"; } ?> </select> <div class="spacer"></div> <input type="submit" value="Award" />
function notifyUser($userid, $prizeid, $winEmailTemplate, $winNotTemplate) { $claimURL = URL_CANVAS . "?p=redeem&id={$prizeid}"; $claimLink = "<a href='" . $claimURL . "'>" . $claimURL . "</a>"; $message .= "Prize {$prizeid} awarded to user {$userid}. "; $message .= "User needs to use following link to claim their prize: " . $claimLink; ////////////////////////// // set up data to notify user require_once PATH_CORE . '/classes/user.class.php'; $ut = new UserTable($db); $uit = new UserInfoTable($db); $user = $ut->getRowObject(); $user->load($userid); require_once PATH_CORE . '/classes/prizes.class.php'; $pt = new PrizeTable($db); $prize = $pt->getRowObject(); $prize->load($prizeid); $nameWords = explode(" ", $user->name); require_once PATH_CORE . '/classes/template.class.php'; $templateObj = new template($db); $columns['prizeTitle'] = $prize->title; $columns['claimURL'] = $claimURL; $columns['firstName'] = $nameWords[0]; $callbacks = array(); $winEmail = clone $winEmailTemplate; // i hate php $winNot = clone $winNotTemplate; // construct an email for this specific user $winEmail->email = $user->email; $winEmail->subject = $templateObj->processRow($columns, $winEmailTemplate->subject, $callbacks); $winEmail->body = $templateObj->processRow($columns, $winEmailTemplate->body, $callbacks); // construct notification info $winNot->body = $templateObj->processRow($columns, $winNotTemplate->body, $callbacks); $fbIds = $uit->getFbIdsForUsers(array($user->userid)); $winNot->fbId = $fbIds[0]; //$mailtoText = "mailto:$winEmail->email?subject=$winEmail->subject&body=$winEmail->body"; // do send notifications echo "Mailing {$winEmail->email}..."; sendEmail($winEmail); echo "Notifying {$winNot->fbId}..."; sendNotification($winNot); }
function fetchRewardsRandom($inTeam = false, $limit = 3) { if (!ENABLE_ACTION_REWARDS) { return ''; } $code .= ' <div class="panelBar clearfix"> <h2>' . $this->commonTeam['RewardsPanelTitle'] . '</h2> <div class="bar_link"> ' . $this->buildLink('rewards', 'See all', true, $inTeam) . '</div> </div>'; require_once PATH_CORE . '/classes/prizes.class.php'; $rewards = new rewards($this->db); $prizeTable = new PrizeTable($this->db); $prize = $prizeTable->getRowObject(); $code .= '<div class="list_rewards clearfix">'; if ($prize->loadWhere('isGrand=1')) { $code .= ' <div class="top_reward clearfix"> <div class="thumb">' . template::buildLinkedRewardPic($prize->id, $prize->thumbnail, 90) . '</div> <div class="storyBlockWrap"> <p class="storyHead"><span class="pointValue">One Grand Prize</span><br>' . template::buildRewardLink($prize->title, $prize->id) . '</p> <p>' . $this->templateObj->cleanString($prize->description, 130) . template::buildRewardLink('… more', $prize->id) . '</p> </div> </div>'; } $code .= $rewards->fetchRewardsPanelList('RAND()', $limit, 'WHERE isGrand=0', $this->session->u->eligibility); $code .= '</div>'; if (!$this->session->u->isMember) { $code .= '<p>' . $this->buildLink('signup', $this->commonTeam['JoinTheTeam'], false, $inTeam, 'btn_1') . '</p>'; } $code = '<div class="panel_2 clearfix">' . $code . '</div>'; return $code; }
function fetchRewardDetail($id, $noButtons = false, $shortSummary = false) { $prizeTable = new PrizeTable($this->db); $prize = $prizeTable->getRowObject(); if ($id && $prize->load($id)) { $pointText = !$shortSummary ? $prize->pointCost == 0 ? ($prize->isGrand == 1 ? 'Grand Prize' : '') . ($prize->isGrand > 1 ? 'Runner-up prize' : '') . ($prize->isWeekly > 0 ? 'Weekly prize' : '') : $prize->pointCost . ' <span class="pts">pts</span>' : ''; $code = ' <div class="thumb">' . template::buildLinkedRewardPic($prize->id, $prize->thumbnail, !$shortSummary ? 180 : 120) . '</div> <div class="storyBlockWrap" > <p class="storyHead">' . $prize->title . '</p> <div class="storyBlockMeta"> <p class="pointValue">' . $pointText . '</p>' . (!$shortSummary ? '<p>Sponsored by <a target="_blank" onclick="quickLog(\'extLink\',\'rewards\',' . $id . ',\'' . $prize->sponsorUrl . '\');" href="' . $prize->sponsorUrl . '">' . $prize->sponsor . '</a></p>' : '') . (!$shortSummary ? '<p class="availabilityText">' . $prize->initialStock . ' available, week ending ' . date('F j, Y', strtotime($prize->dateEnd)) . '</p>' : '') . '</div><!--end "storyBlockMeta"--> <!--<p class="storyCaption">--><p>' . $prize->description . ($shortSummary ? '<a href="?p=rewards&id=' . $id . '" onclick="setTeamTab(\'rewards\',' . $id . '); return false;" class="more_link">… more</a>' : '') . '</p> ' . '</div><!--end "storyBlockWrap"--> <p class="">' . ($noButtons || $prize->isGrand || $prize->isWeekly ? '' : '<a class="btn_1" href="?p=redeem&id=' . $id . '" onclick="setTeamTab(\'redeem\',' . $id . '); return false;">' . 'Get it! Redeem my points' . '</a>') . '</p>'; if ($shortSummary) { } else { $code = '<div id="readStoryList"> <div class="panel_block">' . $code . '</div><!--end "panel_block"--> </div><!--end "readStoryList"-->'; } } else { $code .= 'Invalid prize id'; } return $code; }
function buildActionItem($action) { require_once PATH_CORE . '/classes/user.class.php'; require_once PATH_CORE . '/classes/template.class.php'; $uit = new UserInfoTable($this->db); $fbIds = $uit->getFbIdsForUsers(array($action->userid1)); $fbId = $fbIds[0]; if ($action->userid2) { $fbIds2 = $uit->getFbIdsForUsers(array($action->userid2)); $fbId2 = $fbIds2[0]; } if (!$fbId) { // cant return anything or #&*$@! paging gets screwed //$code .= '<div class="hidden">No fbId found for userid '. $action->userid1 . '</div>'; $this->db->log("Action Feed: No fbId found for userid {$action->userid1} performing {$action->action} on {$action->t}"); return ''; //$code; } $ago .= self::getElapsedString(strtotime($action->t)); switch ($action->action) { case 'completedChallenge': $code .= $this->fetchChallengeCompletedFeedItem($action, $fbId, false); // hack for now so the console can access it also //$ct = new ChallengeTable($this->db); break; case 'signup': /*$code .= template::buildLinkedProfilePic($fbIds[0], 'size="square"') .' '. template::buildLinkedProfileName($fbIds[0]) .' joined the action team!'; */ $code .= '<div class="profilePicLarger">' . template::buildLinkedProfilePic($fbIds[0], 'size="square"') . ' ' . '</div> <div class="storyBlockWrap"> <h3><span class="bold">' . template::buildLinkedProfileName($fbIds[0]) . ' joined the ' . SITE_TEAM_TITLE . '!</span> ' . $ago . '</h3> </div><!__end "storyBlockWrap"__>'; break; case 'friendSignup': $code .= '<div class="profilePicLarger">' . template::buildLinkedProfilePic($fbIds[0], 'size="square"') . ' ' . '</div> <div class="storyBlockWrap"> <h3><span class="bold">' . template::buildLinkedProfileName($fbIds[0]) . ' got credit for inviting ' . template::buildLinkedProfileName($fbId2) . '!</span> ' . $ago . '</h3> </div><!__end "storyBlockWrap"__>'; break; case 'chatStory': require_once PATH_CORE . '/classes/content.class.php'; $contentTable = new ContentTable($this->db); $content = $contentTable->getRowObject(); $contentid = $action->itemid; // hack: since jeff put the fbId in itemid2 for chatStory $fbId2 = $action->userid2; if ($content->load($contentid)) { $code .= ' <div class="thumb">' . template::buildLinkedStoryImage($content->imageid, $contentid) . '</div> <div class="storyBlockWrap"> <div class="feed_poster">' . '<div class="avatar">' . template::buildLinkedProfilePic($fbIds[0], 'size="square" with="30" height="30"') . '</div>' . '<div class="avatar">' . template::buildLinkedProfilePic($fbId2, 'size="square" with="30" height="30"') . '</div>' . '<h3><span class="bold">' . template::buildLinkedProfileName($fbIds[0]) . ' chatted with ' . template::buildLinkedProfileName($fbId2) . ' about the story ' . template::buildStoryLink($content->title, $contentid) . '</span> ' . $ago . '</h3> </div> </div><!__end "storyBlockWrap"__>'; } break; //case 'acceptedInvite': // actually want to filter these? // yeah, dont show these //break; //case 'acceptedInvite': // actually want to filter these? // yeah, dont show these //break; case 'redeemed': require_once PATH_CORE . '/classes/prizes.class.php'; $prizeTable = new PrizeTable($this->db); $prize = $prizeTable->getRowObject(); if ($prize->load($action->itemid) && !$prize->isWeekly && !$prize->isGrand) { /* $indefarticle = template::getIndefiniteArticle($prize->title); $code .= template::buildLinkedProfilePic($fbIds[0], 'size="square"') .' '. template::buildLinkedProfileName($fbIds[0]) ." used {$prize->pointCost} points to get $indefarticle " . template::buildRewardLink($prize->title, $prize->id) ."" . template::buildLinkedRewardPic($prize->id, $prize->thumbnail, $width=70); //$code .= ' '. self::getElapsedString(strtotime($action->t)); */ $code .= '<div class="thumb">' . template::buildLinkedRewardPic($prize->id, $prize->thumbnail, $width = 70) . '</div> <div class="storyBlockWrap"> <div class="feed_poster"><div class="avatar">' . template::buildLinkedProfilePic($fbIds[0], 'size="square" with="30" height="30"') . '</div> <h3><span class="bold">' . template::buildLinkedProfileName($fbIds[0]) . ' redeemed <span class="pointValue">' . $prize->pointCost . '<span class="pts"> points</span></span>.</span> ' . $ago . '</h3> </div> <p class="storyHead">' . template::buildRewardLink($prize->title, $prize->id) . ' </p> <p class="storyCaption"></p> </div><!__end "storyBlockWrap"__>'; } else { // debug: //$code .= 'No prize found for id ' . $action->itemid; } break; case 'wonPrize': // implement require_once PATH_CORE . '/classes/prizes.class.php'; $prizeTable = new PrizeTable($this->db); $prize = $prizeTable->getRowObject(); if ($prize->load($action->itemid)) { if ($prize->isWeekly) { $winText = 'won a Weekly Prize!'; } if ($prize->isGrand == 1) { $winText = 'won the Grand Prize and made the planet green with envy!'; } if ($prize->isGrand > 1) { $winText = 'won a Runner-up Prize!'; } $code .= '<div class="thumb">' . template::buildLinkedRewardPic($prize->id, $prize->thumbnail, $width = 70) . '</div> <div class="storyBlockWrap"> <div class="feed_poster"><div class="avatar">' . template::buildLinkedProfilePic($fbIds[0], 'size="square" with="30" height="30"') . '</div> <h3><span class="bold">' . template::buildLinkedProfileName($fbIds[0]) . ' ' . $winText . ' ' . $ago . '</h3> </div> <p class="storyHead">' . template::buildRewardLink($prize->title, $prize->id) . ' </p> <p class="storyCaption"></p> </div><!__end "storyBlockWrap"__>'; } else { // debug: //$code .= 'No prize found for id ' . $action->itemid; } break; break; case 'publishStory': // TODO ? //return ''; //break; // TODO ? //return ''; //break; case 'postBlog': case 'postStory': require_once PATH_CORE . '/classes/content.class.php'; $contentTable = new ContentTable($this->db); $content = $contentTable->getRowObject(); $contentid = $action->itemid; if ($content->load($contentid)) { /*$code .= template::buildLinkedStoryImage($content->imageid, $contentid); $code .= template::buildLinkedProfilePic($fbIds[0], 'size="square"') .' '. template::buildLinkedProfileName($fbIds[0]) .' posted a story'; $code .= '<p>' . template::buildStoryLink($content->title, $contentid) .'</p>'; */ $code .= ' <div class="thumb">' . template::buildLinkedStoryImage($content->imageid, $contentid) . '</div> <div class="storyBlockWrap"> <div class="feed_poster"><div class="avatar">' . template::buildLinkedProfilePic($fbIds[0], 'size="square" with="30" height="30"') . '</div> <h3><span class="bold">' . template::buildLinkedProfileName($fbIds[0]) . ' posted a story</span> ' . $ago . '</h3> </div> <p class="storyHead">' . template::buildStoryLink($content->title, $contentid) . ' </p> <p class="storyCaption">' . $this->templateObj->ellipsis(strip_tags($content->caption, 200)) . ' ' . template::buildStoryLink('...more', $contentid) . '</p> </div><!__end "storyBlockWrap"__>'; //'</li>' } break; case 'vote': // ignore require_once PATH_CORE . '/classes/content.class.php'; $contentTable = new ContentTable($this->db); $content = $contentTable->getRowObject(); $contentid = $action->itemid; // grrrr if ($content->load($contentid)) { $code .= ' <div class="thumb">' . template::buildLinkedStoryImage($content->imageid, $contentid) . '</div> <div class="storyBlockWrap"> <div class="feed_poster">' . '<h3><span class="bold">' . template::buildLinkedProfileName($fbIds[0]) . ' voted on the story ' . template::buildStoryLink($content->title, $contentid) . '</span> ' . $ago . '</h3> </div> </div><!__end "storyBlockWrap"__> '; } break; case 'comment': /* * * <li class="panel_block"> <div class="thumb"><a href="http://www.msnbc.msn.com/id/28529073/"><img src="{URL_BASE}/index.php?p=scaleImg&id=34608&x=185&y=130&fixed=x&crop" /></a> </div> <div class="storyBlockWrap"> <h3><span class="bold"><a href="'.URL_CANVAS.'?p=profile&memberid=1180126201" onclick="return switchPage('profile', '', 1180126201);"><fb:name ifcantsee="Anonymous" uid="1180126201" capitalize="true" firstnameonly="false" linked="false" /></a> commented on the story <a href="#">It's Time to Aim Low</a></span> on Feb 2, 2009</h3> <blockquote> <div class="quotes"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam dolor nunc, vehicula et, tristique sed, auctor et, massa.</p> <p> Nam at purus vitae diam commodo venenatis. Ut leo enim, vestibulum eget, rhoncus in, suscipit laoreet, magna. Aliquam diam. Nunc tempor lorem eget nisl.</p> </div> </blockquote> </div><!__end "storyBlockWrap"__> </li> */ // assume comment->siteContentId is what is stored... require_once PATH_CORE . '/classes/content.class.php'; require_once PATH_CORE . '/classes/comments.class.php'; require_once PATH_CORE . '/classes/video.class.php'; $contentTable = new ContentTable($this->db); $commentTable = new CommentTable($this->db); $videoTable = new VideoTable($this->db); $content = $contentTable->getRowObject(); $comment = $commentTable->getRowObject(); $video = $videoTable->getRowObject(); $commentid = $action->itemid; // grr $contentid = $action->itemid2; // grrrr if ($comment->load($commentid) && $content->load($contentid)) { if ($comment->videoid && $video->load($comment->videoid)) { $quoteContents = '<div style="text-align:center;">' . videos::buildPlayerFromLink($video->embedCode, 160, 100) . '</div>'; } else { $quoteContents = '<p>' . $this->templateObj->ellipsis(strip_tags($comment->comments), 200) . ' ' . template::buildStoryLink('...more', $contentid) . '</p>'; } $code .= ' <div class="thumb">' . template::buildLinkedStoryImage($content->imageid, $contentid) . '</div> <div class="storyBlockWrap"> <div class="feed_poster"><div class="avatar">' . template::buildLinkedProfilePic($fbIds[0], 'size="square" height="30" width="30"') . '</div> <h3><span class="bold">' . template::buildLinkedProfileName($fbIds[0]) . ' commented on the story ' . template::buildStoryLink($content->title, $contentid) . '</span> ' . $ago . '</h3> </div> <blockquote> <div class="quotes">' . $quoteContents . '</div> </blockquote> </div><!__end "storyBlockWrap"__> '; } break; } return $code; }
function processPrizeOrder($prizeid, $userid, &$message) { require_once PATH_CORE . '/classes/user.class.php'; require_once PATH_CORE . '/classes/prizes.class.php'; require_once PATH_CORE . '/classes/orders.class.php'; $orderTable = new OrderTable($this->db); $userTable = new UserTable($this->db); $userInfoTable = new UserInfoTable($this->db); $prizeTable = new PrizeTable($this->db); $user = $userTable->getRowObject(); $userInfo = $userInfoTable->getRowObject(); $prize = $prizeTable->getRowObject(); $order = $orderTable->getRowObject(); if (!$user->load($userid) || !$userInfo->load($userid) || !$prize->load($prizeid)) { $message = "There was an error loading prize and/or user records."; return false; } $userInfoTable->updateUserCachedPointsAndChallenges($userid, $user, $userInfo); // slightly inefficient, calls load again // final check, in case something else happened if (!$this->checkOrderPossible($prize, $user, $userinfo, $message)) { return false; } // everythings ok: if (!($prize->isWeekly || $prize->isGrand)) { $user->cachedPointTotal -= $prize->pointCost; } $prize->currentStock--; $order->userid = $user->userid; $order->prizeid = $prize->id; $order->pointCost = $prize->pointCost; // cache points spent in here for proper recordkeeping. $phpnow = time(); $order->dateSubmitted = date('Y-m-d H:i:s', $phpnow); $order->status = 'submitted'; if (!$order->insert()) { $message = 'Error submitting your order, please email support.'; return false; } $user->update(); $prize->update(); $message .= 'Your order number is #' . $order->id . '.'; // debatable -- should this show up in the log if its a weekly or grand prize? $log = $this->app->getActivityLog(); $log->add($log->serialize(0, $this->page->session->userid, 'redeemed', $_POST['prizeid'], 0)); return $order->id; }