function userTest()
 {
     echo "\nDBTest User Test Page\n";
     require_once PATH_CORE . '/classes/user.class.php';
     $userTable = new UserTable($this->db);
     // TODO: cache instances of the tables globally
     $userInfoTable = new UserInfoTable($this->db);
     $user = $userTable->getRowObject();
     $userInfo = $userInfoTable->getRowObject();
     $isAppAuthorized = 0;
     $fbId = 666669;
     // create a test user
     $user->isAppAuthorized = $isAppAuthorized;
     if ($user->insert()) {
         // inserted ok
         echo '<p>created $user:<pre>' . print_r($user, true) . '</pre>';
         //$name = 'userid';
         //$user->{$name} = 1001;
         //$user->{'userid'} = 1001;
         echo "userid = {$user->userid}\n";
         if ($userInfo->createFromUser($user, $fbId)) {
             echo 'Created new user info\\n';
             echo "Primary keys should be equal: " . $user->userid . " ?= " . $userInfo->userid . ".\n";
             echo '<p>$userInfo:<pre>' . print_r($userInfo, true) . '</pre>';
             $userInfoTest = $userInfoTable->getRowObject();
             $userInfoTest->loadFromFbId($fbId);
             echo '<p>loaded user info debug: $userInfo:<pre>' . print_r($userInfoTest, true) . '</pre>';
             $userInfoTest->age = 111;
             $userInfoTest->update();
             $userInfoTest->loadFromFbId($fbId);
             echo '<p>updated user info debug: $userInfo:<pre>' . print_r($userInfoTest, true) . '</pre>';
             $user->name = "Roger Rabit";
             $user->update();
             // inserted ok
             echo '<p>updated $user:<pre>' . print_r($user, true) . '</pre>';
         } else {
             echo "Failed to create UserInfo row\n";
         }
     } else {
         echo "Failed to insert user!\n";
     }
     return $code;
 }
 function revokeAutomaticChallengeAward($userid, $shortname)
 {
     require_once PATH_CORE . '/classes/user.class.php';
     $challengeTable = new ChallengeTable($db);
     $userTable = new UserTable($db);
     $userInfoTable = new UserInfoTable($db);
     $completedTable = $this;
     $user = $userTable->getRowObject();
     $userInfo = $userInfoTable->getRowObject();
     $challenge = $challengeTable->getRowObject();
     $completed = $completedTable->getRowObject();
     $ccid;
     $res = $this->db->query("SELECT SQL_CALC_FOUND_ROWS ChallengesCompleted.id AS ccid \n\t\t\t\t\t\t\t\t\tFROM ChallengesCompleted,Challenges \n\t\t\t\t\t\t\t\t\t\tWHERE userid={$userid} \n\t\t\t\t\t\t\t\t\t\t\tAND Challenges.id = challengeid \n\t\t\t\t\t\t\t\t\t\t\tAND Challenges.shortName='{$shortname}'\n\t\t\t\t\t\t\t\t\t\t\tAND ChallengesCompleted.status='awarded';");
     if ($this->db->countQ($res)) {
         $data = $this->db->readQ($res);
     } else {
         return false;
     }
     $ccid = $data->ccid;
     if (!$completed->load($ccid)) {
         return false;
     }
     $completed->pointsAwarded = 0;
     $completed->dateAwarded = date('Y-m-d H:i:s', time());
     $completed->update();
     return true;
 }
 function ajaxBanStoryPoster(&$app = null, $cid = 0, $userid = 0)
 {
     // to do - make sure user is admin
     // cid - cid of user to ban
     $contentTable = new ContentTable($this->db);
     $c = $contentTable->getRowObject();
     $c->load($cid);
     if ($c->userid != $userid) {
         $this->db->update("Content", "isBlocked=1", "userid=" . $c->userid);
         // block all stories by this user
         $this->db->update("Comments", "isBlocked=1", "userid=" . $c->userid);
         // block all comments by this user
         require_once PATH_CORE . '/classes/user.class.php';
         $uit = new UserInfoTable($this->db);
         $ut = new UserTable($this->db);
         $u = $ut->getRowObject();
         $ui = $uit->getRowObject();
         $u->load($c->userid);
         // block story
         $c->isBlocked = 1;
         $c->update();
         // block user
         $u->isBlocked = 1;
         $u->update();
         $ui->load($c->userid);
         $facebook = $app->loadFacebookLibrary();
         $this->db->log('To Ban ' . $ui->fbId);
         //$facebook->api_client->admin_banUsers($ui->fbId);
         // load facebook library - call ban api
         $code = 'Ban complete.';
     } else {
         $code = 'Error: Trying to ban yourself again, huh?';
     }
     return $code;
 }
 function checkSubmitSiteChallenge($log)
 {
     //echo 'log action:' . $log->action . '<br>';
     if (!(array_search($log->action, array_keys(self::$siteChallengeActions)) === false)) {
         //echo 'found action in siteChallengeActions<br>';
         require_once PATH_CORE . '/classes/challenges.class.php';
         $ct = new ChallengeCompletedTable($this->db);
         if (!$ct->submitAutomaticChallenge($log->userid1, $log->action, &$statuscode, self::$siteChallengeActions[$log->action], $log->id)) {
             //echo $statuscode; // TODO: take this out when done testing
             //$this->db->log($statuscode);
         }
         //echo $statuscode; // TODO: take this out when done testing
         //$this->db->log("checkSubmitSiteChallenge $log->action: $statuscode dontLog: ".self::$siteChallengeActions[$log->action]);
         //$this->db->log(print_r(self::$siteChallengeActions, true));
         // update cached user vars for select site actions
         require_once PATH_CORE . '/classes/user.class.php';
         $ut = new UserTable($this->db);
         $uit = new UserInfoTable($this->db);
         $user = $ut->getRowObject();
         $userinfo = $uit->getRowObject();
         switch ($log->action) {
             case 'invite':
                 if ($userinfo->load($log->userid1)) {
                     $userinfo->cachedFriendsInvited++;
                     $userinfo->update();
                 }
                 break;
             case 'comment':
                 if ($user->load($log->userid1)) {
                     $user->cachedCommentsPosted++;
                     $user->update();
                 }
                 break;
             case 'postStory':
             case 'postBlog':
                 if ($user->load($log->userid1)) {
                     $user->cachedStoriesPosted++;
                     $user->update();
                 }
                 break;
             default:
                 break;
         }
     }
 }
 function loadStory($wire = null, $feed = null)
 {
     $this->db->log('entering loadStory ');
     $this->db->log($wire);
     // post a story from a feed to Content table for the user who owns the bookmark feed
     $this->psObj->refreshUrl($wire->url);
     // $id is feed id, $wire is serialized newswire object, $feed->userid is posted by userid
     // clean headlines
     $wire->title = $this->psObj->cleanTitle($wire->title);
     $this->db->log('clean title:' . $wire->title);
     // check for duplicates from final url or initial url or title
     $error = false;
     $cleanUrl = $this->psObj->cleanUrl($wire->url);
     $isDup = $this->db->queryC("SELECT siteContentId FROM Content WHERE url = '" . $wire->url . "' OR url = '" . $cleanUrl . "' OR title = '" . $wire->title . "'");
     if ($isDup === false) {
         $wire->url = $cleanUrl;
         $this->psObj->log('Cleaned url: ' . $cleanUrl . ' <= ' . $wire->url);
         // load user wire record
         $this->db->log('not a dup');
         require_once PATH_CORE . '/classes/user.class.php';
         $userTable = new UserTable($this->db);
         $user = $userTable->getRowObject();
         // to do if $feed->userid==0 use admin
         if ($feed->userid == 0) {
             $user->loadWhere("isAdmin=1");
         } else {
             $user->load($feed->userid);
         }
         // create temporary content item, temp permalink
         require_once PATH_CORE . '/classes/utilities.class.php';
         $utilObj = new utilities();
         require_once PATH_CORE . '/classes/content.class.php';
         $cObj = new content($this->db);
         // clean caption, strip tags, trim for length
         $wire->caption = $utilObj->shorten($wire->caption, LENGTH_LONG_CAPTION);
         $wire->source = $this->stripit(parse_url($wire->url, PHP_URL_HOST));
         // create permalink
         $wire->permalink = $cObj->buildPermalink($wire->title);
         // get images, check size of each and pick most likely candidate with minimum
         require_once PATH_CORE . '/classes/remotefile.class.php';
         $rfObj = new remotePageProperty($wire->url);
         $imgArr = $this->psObj->parseImages($rfObj, 7500);
         // 7500 is min jpg size for automatically selecting images
         // $this->db->log($imgArr);
         if (count($imgArr) > 0) {
             $wire->imageUrl = $imgArr[0];
         } else {
             $wire->imageUrl = '';
         }
         // serialize the content
         $isBlogEntry = 0;
         $story = $cObj->serialize(0, $wire->title, $wire->caption, $wire->source, $wire->url, $wire->permalink, $user->ncUid, $user->name, $user->userid, '', 1, 0, 0, $wire->imageUrl, 0, $isBlogEntry, 1);
         //$this->db->log($story);
         // add to content by this userid
         $siteContentId = $cObj->add($story);
         if ($siteContentId !== false) {
             require_once PATH_CORE . '/classes/log.class.php';
             $this->logObj = new log($this->db);
             // add to user journal
             $logItem = $this->logObj->serialize(0, $user->userid, 'postStory', $siteContentId);
             $inLog = $this->logObj->update($logItem);
             if ($inLog) {
                 $logItem = $this->logObj->serialize(0, $user->userid, 'vote', $siteContentId);
                 $inLog = $this->logObj->update($logItem);
             }
         }
         // set new story loaded flag - so that features can be updated
         $this->newStoryLoaded = true;
     } else {
         $error = true;
     }
 }
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 updateUserCachedPoints($fbId, $always = false)
 {
     require_once PATH_CORE . '/classes/user.class.php';
     $userTable = new UserTable($this->db);
     $user = $userTable->getRowObject();
     $userinfoTable = new UserInfoTable($this->db);
     $userinfo = $userinfoTable->getRowObject();
     if ($userinfo->loadWhere("fbId={$fbId} " . ($always ? "" : "AND DATE_ADD(lastUpdateCachedPointsAndChallenges, INTERVAL 1 HOUR) < NOW()"))) {
         $userinfoTable->updateUserCachedPointsAndChallenges($userinfo->userid, &$user, &$userinfo, $weekOf);
     }
 }
 function initFormDataFromDatabase($userid)
 {
     $fdata = new stdClass();
     require_once PATH_CORE . '/classes/user.class.php';
     $userTable = new UserTable($this->db);
     $userInfoTable = new UserInfoTable($this->db);
     $user = $userTable->getRowObject();
     $userinfo = $userInfoTable->getRowObject();
     //dbRowObject::$debug = 1;
     if (!$user->load($this->session->userid) || !$userinfo->load($this->session->userid)) {
         $fdata->alert = 'Fatal error: userid not found in database';
         $fdata->result = false;
         echo 'Error loading user table entries.';
         return $fdata;
     }
     $fdata->age = $userinfo->age;
     $fdata->city = $userinfo->city;
     $fdata->state = $userinfo->state;
     $fdata->country = $userinfo->country;
     $fdata->address1 = $userinfo->address1;
     $fdata->address2 = $userinfo->address2;
     $fdata->zip = $userinfo->zip;
     $fdata->gender = $userinfo->gender;
     //$userinfo->birthdate = ''; // TODO
     $fdata->name = $user->name;
     $fdata->email = $user->email;
     $fdata->optInStudy = $user->optInStudy;
     $fdata->optInEmail = $user->optInEmail;
     $fdata->optInSMS = $user->optInSMS;
     $fdata->optInProfile = $user->optInProfile;
     $fdata->optInFeed = $user->optInFeed;
     $fdata->noCommentNotify = $userinfo->noCommentNotify;
     $fdata->acceptRules = $user->acceptRules;
     require_once PATH_CORE . '/classes/subscriptions.class.php';
     $subTable = new SubscriptionsTable($this->db);
     $sub = $subTable->getRowObject();
     if ($sub->loadWhere("userid=" . $this->session->userid)) {
         $fdata->rxFeatures = $sub->rxFeatures;
         $fdata->rxMode = $sub->rxMode;
     } else {
         $fdata->rxFeatures = 1;
         $fdata->rxMode = 'notification';
     }
     return $fdata;
 }
 function initializeUserInfo($fbId = 0, $isAppAuthorized = 0)
 {
     // adds a record for this user in the Facebook app userinfo table
     require_once PATH_CORE . '/classes/user.class.php';
     $userTable = new UserTable($this->db);
     // TODO: cache instances of the tables globally
     $userInfoTable = new UserInfoTable($this->db);
     $user = $userTable->getRowObject();
     $userInfo = $userInfoTable->getRowObject();
     //dbRowObject::$debug = true;
     $debug = false;
     if ($debug) {
         echo 'entered session::initializeUserInfo()\\n';
     }
     // create new users
     $user->isAppAuthorized = $isAppAuthorized;
     $user->votePower = 1;
     if ($user->insert()) {
         // inserted ok
         if ($debug) {
             echo '<p>created $user:<pre>' . print_r($user, true) . '</pre>';
         }
         if ($userInfo->createFromUser($user, $fbId)) {
             //*
             if ($debug) {
                 echo 'Created new user info\\n';
                 echo '<p>$userInfo:<pre>' . print_r($userInfo, true) . '</pre>';
             }
             //*/
             $userInfoTest = $userInfoTable->getRowObject();
             $userInfoTest->loadFromFbId($fbId);
             if ($debug) {
                 echo '<p>fetched user info debug: $userInfo:<pre>' . print_r($userInfoTest, true) . '</pre>';
             }
             // populate subscription settings for the new user
             require_once PATH_CORE . '/classes/subscriptions.class.php';
             $subTable = new SubscriptionsTable($this->db);
             $sub = $subTable->getRowObject();
             $sub->userid = $user->userid;
             $sub->rxFeatures = 1;
             $sub->rxMode = 'notification';
             $sub->insert();
         } else {
             if ($debug) {
                 echo "Failed to create UserInfo row:<br>";
                 echo '<p>$userInfo:<pre>' . print_r($userInfo, true) . '</pre>';
             }
             return false;
         }
     } else {
         if ($debug) {
             echo "Failed to insert user!\n";
         }
         return false;
     }
     // merge necessary session data into a results object and return it
     $data->isMember = $user->isMember;
     $data->isBlocked = $user->isBlocked;
     $data->isAdmin = $user->isAdmin;
     $data->name = $userInfo->name;
     $data->userid = $userInfo->userid;
     // .. etc
     return $data;
     /*   
     	echo "<p>session->fbId: {$this->app->session->fbId}</p>";
     	$userInfo->loadFromFbId($this->app->session->fbId);
     	
     	echo '<p>$userInfo:<pre>'. print_r($userInfo).'</pre>';
     	
     	if ($userInfo->userid && $user->load($userInfo->userid))
     		{
     		$code .= 'Found a user...';
     */
 }
 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;
 }
 static function processChallengeSubmit(&$code, &$passback)
 {
     //$debug = $_POST['debugSubmit']; // NEVER TURN ON FOR LIVE SITE
     echo '<h2>Processing, please wait...</h2>';
     if ($debug) {
         echo "POST<pre>" . print_r($_POST, true) . "</pre>";
     }
     // TODO: grab session keys from post, validate session
     $passback .= "&text={$_POST['text']}";
     $passback .= "&embedCode={$_POST['embedCode']}";
     if ($debug) {
         echo $passback;
     }
     if (isset($_POST['challengeid']) && $_POST['challengeid']) {
         $challengeid = $_POST['challengeid'];
     } else {
         $code = "There was no challenge id present in your submission";
         return false;
     }
     if (isset($_POST['text'])) {
         $evidence = $_POST['text'];
     } else {
         $evidence = '';
         /*$code = "Your text submission was empty."; return false;*/
     }
     if (isset($_POST['userid']) && $_POST['userid']) {
         $userid = $_POST['userid'];
     } else {
         $code = 'Either you aren\'t a registered user or your session is expired. Please return to the home page or sign in to facebook again.';
         return false;
     }
     require_once PATH_CORE . '/classes/db.class.php';
     $db = new cloudDatabase();
     // create a CompletedChallenges object
     //$userid = $this->page->session->userid;
     /*	if (!$userid)
     		{
     			echo "<pre>" . print_r($this->page->session, true) . "</pre>";	
     			
     			return "Could not get userid from session."; 
     		}*/
     require_once PATH_CORE . '/classes/user.class.php';
     require_once PATH_CORE . '/classes/challenges.class.php';
     $challengeTable = new ChallengeTable($db);
     $userTable = new UserTable($db);
     $userInfoTable = new UserInfoTable($db);
     $completedTable = new ChallengeCompletedTable($db);
     $user = $userTable->getRowObject();
     $userInfo = $userInfoTable->getRowObject();
     $challenge = $challengeTable->getRowObject();
     $completed = $completedTable->getRowObject();
     dbRowObject::$debug = $debug;
     $user->load($userid);
     $userInfo->load($userid);
     $challenge->load($challengeid);
     // validate challenge submission info
     // validate eligibility, date, membership
     if ($challenge->remainingCompletions <= 0 && $challenge->initialCompletions > 0) {
         $code = 'This challenge can no longer be completed for credit.';
         return false;
     }
     if (!ChallengeTable::userIsEligible($challenge->eligibility, $user->eligibility)) {
         $code = 'We\'re sorry, you are not eligible to receive credit for this challenge.';
         return false;
     }
     if (preg_match("/text/i", $challenge->requires) && !($evidence != '')) {
         $code = 'Sorry, you need to convince us you actually did this!';
         return false;
     }
     //if () //  TODO: now is between date start and end
     $now = time();
     $dateStart = strtotime($challenge->dateStart);
     $dateEnd = strtotime($challenge->dateEnd);
     if ($now > $dateEnd) {
         $code = 'Sorry, you are too late to receive credit for this challenge!';
         return false;
     }
     if ($now < $dateStart) {
         $code = 'Sorry, you can\'t receive credit for this challenge yet -- try again later!';
         return false;
     }
     // if () TODO: check user maximum by querying order histor
     // more...
     // everythings ok:
     $challenge->remainingCompletions--;
     $completed->userid = $user->userid;
     $completed->challengeid = $challenge->id;
     $phpnow = time();
     $completed->dateSubmitted = date('Y-m-d H:i:s', $phpnow);
     $completed->status = 'submitted';
     $completed->evidence = $evidence;
     $completed->comments = $evidence;
     // editors will review these later
     /*
      * The following code is a bit tricky. There are two things going on. The first is that photos
      * or videos are being checked for and their records are being created, but we have 
      * tentatively created a CompleteChallenge record first so they can back-reference it
      * 
      * If a required photo or video turns out not to have appeared, we have to then return an error 
      * and delete the CC record.
      * 
      * An extra wrinkle is that if both video and photo are in the requires field, we can accept 
      * one or the other.
      * 
      */
     // Create the completed to attach to the media records...
     if (!$completed->insert()) {
         $code = 'Internal error submitting your evidence, please try again.';
         return false;
     }
     if (preg_match("/photo/i", $challenge->requires) || preg_match("/optionalphoto/i", $challenge->requires)) {
         if ($photoFilename = self::processChallengeSubmitPhoto($userid, $completed->id)) {
             if (!preg_match("/\\.(jpg|png|gif|jpeg?)\$/i", $photoFilename)) {
                 $msg = 'Sorry, your photo did not appear to be of type jpg, png, or gif.';
                 $error = true;
             } else {
                 // create photo in our db
                 require_once PATH_CORE . '/classes/photo.class.php';
                 $photoTable = new PhotoTable($db);
                 $photoTable->createPhotoForCompletedChallenge($userid, $completed->id, $photoFilename, 'Photo submitted for ' . $challenge->title);
                 $photoSubmitted = true;
                 // indicate that a photo was found
             }
         } else {
             if (!preg_match("/optionalphoto/i", $challenge->requires)) {
                 $msg = 'No photo submitted';
                 $error = true;
             }
         }
     }
     //$passback .= "&photo1={$photoFilename}"; // wont be correct filename, actually quite complicated to make this work properly
     //echo $passback;
     if (preg_match("/video/i", $challenge->requires)) {
         if ($videoEmbedCode = self::processChallengeSubmitVideo($userid, $completed->id)) {
             // create photo in our db
             require_once PATH_CORE . '/classes/video.class.php';
             $videoTable = new VideoTable($db);
             $videoTable->createVideoForCompletedChallenge($userid, $completed->id, $videoEmbedCode, 'Video submitted for ' . $challenge->title);
             $videoSubmitted = true;
             // indicate video found
         } else {
             $msg = 'You must enter a YouTube video url.';
             $error = true;
         }
     }
     // HACK: now handle the case where both photo and video boxes appeared, and only one was entered
     if ($photoSubmitted or $videoSubmitted) {
         $error = false;
     }
     // set the $error flag set by the other one to false if one of them was sucessfully created
     if ($error) {
         $completed->delete();
         // delete the temporary CC record
         $code = $msg;
         return false;
     }
     $challenge->update();
     require_once PATH_CORE . '/classes/template.class.php';
     $code .= 'We have received your submission for the challenge <b>' . $challenge->title . '</b>  (reference number #' . $completed->id . ')';
     dbRowObject::$debug = 0;
     // NEVER TURN ON FOR LIVE SITE
     // for testing purposes -- approve free points right away
     if ($challenge->shortName == 'testPoints10k') {
         $code2 = '';
         if (!$completedTable->approveChallenge($completed->id, $challenge->pointValue, &$code2, false)) {
             $code = $code2;
             return false;
         } else {
             $code = 'Free points awarded!';
         }
     }
     return true;
 }
 function remoteSerialize($data)
 {
     // take comment from NewsCloud
     // look up postedById and get local userid
     require_once PATH_CORE . '/classes/user.class.php';
     $userTable = new UserTable($this->db);
     $user = $userTable->getRowObject();
     $user->load($data[uid]);
     if (!$user) {
         $userid = $user->userid;
     } else {
         $userid = 0;
     }
     require_once PATH_CORE . '/classes/content.class.php';
     $contentTable = new ContentTable($this->db);
     $content = $contentTable->getRowObject();
     $content->load($data[contentid], 'contentid');
     if (!$content) {
         $siteContentId = $content->siteContentId;
     } else {
         $siteContentId = 0;
     }
     // look up contentid and get local siteContentId
     $data = $this->serialize(0, $data[commentid], $siteContentId, $data[contentid], $data[comments], $data[uid], $userid, $data[member_name], $data[date]);
     return $data;
 }
Exemplo n.º 13
0
function initializeUserInfo($fbId = 0)
{
    global $db;
    // adds a record for this user in the Facebook app userinfo table
    require_once PATH_CORE . '/classes/user.class.php';
    $userTable = new UserTable($db);
    // TODO: cache instances of the tables globally
    $userInfoTable = new UserInfoTable($db);
    $user = $userTable->getRowObject();
    $userInfo = $userInfoTable->getRowObject();
    //dbRowObject::$debug = true;
    $debug = true;
    if ($debug) {
        echo 'entered postAuth::initializeUserInfo()\\n';
    }
    // create new users
    $user->isAppAuthorized = 1;
    $user->votePower = 1;
    if ($user->insert()) {
        // inserted ok
        if ($debug) {
            echo '<p>created $user:<pre>' . print_r($user, true) . '</pre>';
        }
        if ($userInfo->createFromUser($user, $fbId)) {
            //*
            if ($debug) {
                echo 'Created new user info\\n';
                echo '<p>$userInfo:<pre>' . print_r($userInfo, true) . '</pre>';
            }
            //*/
            $userInfoTest = $userInfoTable->getRowObject();
            $userInfoTest->loadFromFbId($fbId);
            // populate subscription settings for the new user
            require_once PATH_CORE . '/classes/subscriptions.class.php';
            $subTable = new SubscriptionsTable($db);
            $sub = $subTable->getRowObject();
            $sub->userid = $user->userid;
            $sub->rxFeatures = 1;
            $sub->rxMode = 'notification';
            $sub->insert();
            if ($debug) {
                echo '<p>fetched user info debug: $userInfo:<pre>' . print_r($userInfoTest, true) . '</pre>';
            }
        } else {
            if ($debug) {
                echo "Failed to create UserInfo row:<br>";
                echo '<p>$userInfo:<pre>' . print_r($userInfo, true) . '</pre>';
            }
        }
    } else {
        if ($debug) {
            echo "Failed to insert user!\n";
        }
    }
}
 function buildCommentBox($isAjax = false)
 {
     $code = '';
     require_once PATH_CORE . '/classes/user.class.php';
     $userTable = new UserTable($this->db);
     $userInfoTable = new UserInfoTable($this->db);
     $user = $userTable->getRowObject();
     $userinfo = $userInfoTable->getRowObject();
     $user->loadWhere("isAdmin=1");
     $userinfo->load($user->userid);
     $code .= '<fb:comments xid="' . CACHE_PREFIX . '_microComments" canpost="true" candelete="true" simple="true" numposts="3" showform="true" publish_feed="false" quiet="true" send_notification_uid="' . $userinfo->fbId . '"></fb:comments>';
     // callbackurl="'.URL_CALLBACK.'?p=ajax&m=ideasRefreshComments&id='.$id.'"
     if (!$isAjax) {
         $code = '<div id="commentBox">' . $code . '</div>';
     }
     return $code;
 }
		 ('22','fbApp_info_changed_url','',null),
		 ('25','fbApp_edit_url','',null),
		 ('27','fbApp_desktop',null,'0'),
		 ('13','fbApp_private_install',null,'0'),
		 ('30','fbApp_default_column',null,'1'),
		 ('34','fbApp_base_domain','',null),
		*/
// Add admin user
$q = $db->query("SELECT * FROM User WHERE isAdmin=1");
if ($db->countQ($q) == 0) {
    echo 'Adding ' . SUPPORT_ADMIN . ' as administrator...<br />';
    require_once PATH_CORE . '/classes/user.class.php';
    $userTable = new UserTable($db);
    // TODO: cache instances of the tables globally
    $userInfoTable = new UserInfoTable($db);
    $user = $userTable->getRowObject();
    $userInfo = $userInfoTable->getRowObject();
    // create new users
    $user->name = SITE_TITLE . ' Administrator';
    $user->isAppAuthorized = 1;
    $user->votePower = 1;
    $user->isAdmin = 1;
    $user->authLevel = 'member';
    $user->eligibility = 'team';
    $user->email = SUPPORT_ADMIN;
    $user->ncUid = rand(0, 99999);
    // deprecated column, but must be set
    if ($user->insert()) {
        // inserted ok
        if ($userInfo->createFromUser($user, 0)) {
            require_once PATH_CORE . '/classes/subscriptions.class.php';
Exemplo n.º 16
0
 static function loadUserFromFbId($db, $fbId, &$user, &$userinfo)
 {
     $userInfoTable = new UserInfoTable($db);
     $userTable = new UserTable($db);
     // TODO: cache instances of the tables globally
     $user = $userTable->getRowObject();
     $userinfo = $userInfoTable->getRowObject();
     // load the ui record for the fbId and if it succeeds, the corresponding user record
     return $userinfo->loadFromFbId($fbId) && $user->load($userinfo->userid);
 }
 function rewardBetaTesters()
 {
     $testers = array();
     require_once PATH_CORE . '/classes/user.class.php';
     require_once PATH_CORE . '/classes/challenges.class.php';
     $ct = new ChallengeCompletedTable($this->db);
     $cc = $ct->getRowObject();
     $challengeTable = new ChallengeTable($this->db);
     $betaTestChallenge = $challengeTable->getRowObject();
     if (!$betaTestChallenge->loadWhere("shortName='betaTest'")) {
         echo "Couldn't find betaTest challenge";
         return false;
     }
     $userTable = new UserTable($this->db);
     $user = $userTable->getRowObject();
     $backdate = "2009-02-28 00:00:00";
     foreach ($testers as $email) {
         if ($user->loadWhere("email='{$email}'")) {
             echo "User {$user->name}, {$email} found...";
             $statuscode = '';
             if (!$ct->submitAutomaticChallenge($user->userid, 'betaTest', &$statuscode, false)) {
                 echo "Challenge approval failure: {$statuscode}";
             } else {
                 echo $statuscode;
                 // TODO: take this out when done testing
                 //$this->db->log($statuscode);
                 // now backdate it!
                 if ($cc->loadWhere("userid={$user->userid} AND challengeid={$betaTestChallenge->id}")) {
                     //$cc->dateSubmitted = $backdate; // can leave this probably
                     $cc->dateAwarded = $backdate;
                     $cc->update();
                     echo "...backdated succesfully";
                 } else {
                     echo "Couldnt find CC to backdate!";
                 }
             }
         } else {
             echo "No user found with email {$email}.";
         }
         echo "<br />";
     }
 }
 function debugNukeUser()
 {
     require_once PATH_CORE . '/classes/user.class.php';
     $userTable = new UserTable($this->db);
     $userInfoTable = new UserInfoTable($this->db);
     $user = $userTable->getRowObject();
     $userInfo = $userInfoTable->getRowObject();
     if ($user->load($this->page->session->userid)) {
         $user->delete();
         $code .= 'User entry deleted...';
     }
     if ($userInfo->load($this->page->session->userid)) {
         $userInfo->delete();
         $code .= 'UserInfo entry deleted...';
     }
     return $code;
 }