function fetchFeedScoreLog($filter_userid, $currentPage = 1, $rowsPerPage = 10)
 {
     // userid is passed in because there is no session when refreshed with Ajax
     require_once PATH_CORE . '/classes/log.class.php';
     $lt = new LogTable($this->db);
     $logaction = $lt->getRowObject();
     $startRow = ($currentPage - 1) * $rowsPerPage;
     // replace rows per page
     $actionIdList = $this->db->query("SELECT SQL_CALC_FOUND_ROWS\t\n\t\t\t\t\tChallengesCompleted.id AS id,fbId,dateSubmitted,\n\t\t\t\t\tshortName, logid, pointsAwarded\n\t\t\tFROM ChallengesCompleted,UserInfo,Challenges \n\t\t\tWHERE ChallengesCompleted.status='awarded' \n\t\t\t\tAND ChallengesCompleted.userid=UserInfo.userid\n\t\t\t\tAND ChallengesCompleted.challengeid = Challenges.id \n\t\t\t\tAND UserInfo.userid={$filter_userid}\t\t\t\t\n\t\t\tORDER BY dateSubmitted DESC " . ($rowsPerPage ? "LIMIT {$startRow}," . $rowsPerPage . ";" : ";"));
     // $this->page->rowsPerPage
     $rowTotal = $this->templateObj->db->countFoundRows();
     if ($this->db->countQ($actionIdList) > 0) {
         while ($data = $this->db->readQ($actionIdList)) {
             /*$debugcomment .= "<div class='hidden'> logid=$data->logid, ccid=$data->id </div>";
             		$code .= "<li id='actionFeedItem'>$debugcomment</li>"; // hack for now 
             		*/
             $showCompletedChallengeEntry = true;
             if ($data->logid) {
                 if ($logaction->load($data->logid)) {
                     if ($logaction->action != 'completedChallenge') {
                         $actionitemcode = $this->buildActionItem($logaction);
                         if ($actionitemcode != '') {
                             $showCompletedChallengeEntry = false;
                             // suppress it if we can build a nicer display
                             $pointText = '<div class="storyBlockWrap"><p class="storyCaption"><span class="pointValue"> for ' . $data->pointsAwarded . '<span class="pts"> points </span></span></p></div>';
                             $code .= '<li id="actionFeedItem">' . $actionitemcode . $pointText . '</li>';
                         }
                     }
                 }
             }
             if ($showCompletedChallengeEntry) {
                 $action->itemid = $data->id;
                 $action->t = $data->dateSubmitted;
                 $code .= '<li id="actionFeedItem">' . $this->fetchChallengeCompletedFeedItem($action, $data->fbId, true, true) . '</li>';
             }
         }
         $code = '<div class="list_stories"><ul>' . $code . '</ul></div>';
     } else {
         $code .= $this->emptyLogMessage;
     }
     $pagingHTML = $this->feedPaging($currentPage, $rowTotal, $rowsPerPage, '', 'refreshFeed');
     // later put back page->rowsPerPage
     $code .= $pagingHTML;
     return $code;
 }
 function approveChallenge($completedid, $pointsAwarded, &$code, $dontLog = false)
 {
     // changes completed record to approved, awards points, logs the completion
     $cc = $this->getRowObject();
     $ct = new ChallengeTable($this->db);
     $challenge = $ct->getRowObject();
     require_once PATH_CORE . '/classes/user.class.php';
     $uit = new UserInfoTable($this->db);
     $ui = $uit->getRowObject();
     $ut = new UserTable($this->db);
     $u = $ut->getRowObject();
     if (!($cc->load($completedid) && $challenge->load($cc->challengeid) && $ui->load($cc->userid) && $u->load($cc->userid))) {
         $code .= 'Couldnt find submission matching id ' . $completedid . ' or challenge matching id ' . $cc->challengeid . ' or user matching id ' . $cc->userid;
         return false;
     }
     if ($challenge->remainingCompletions < 1 && $challenge->initialCompletions != 0) {
         $code .= 'This challenge has no remaining global completions';
         return false;
     }
     // get total user completions of this challenges
     $q = $this->db->query("SELECT SQL_CALC_FOUND_ROWS * \n\t\t\tFROM ChallengesCompleted WHERE challengeid={$cc->challengeid} \n\t\t\t\t\t\t\t\t\t\tAND userid={$cc->userid} \n\t\t\t\t\t\t\t\t\t\tAND status='awarded'\n\t\t\t\t\t\t\t\t\t\tAND dateSubmitted>=DATE_SUB(CURDATE(),INTERVAL 1 DAY); \n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t");
     $userCompletionsLast24Hours = $this->db->countQ($q);
     $q = $this->db->query("SELECT SQL_CALC_FOUND_ROWS * \n\t\t\tFROM ChallengesCompleted WHERE challengeid={$cc->challengeid} \n\t\t\t\t\t\t\t\t\t\tAND userid={$cc->userid} \n\t\t\t\t\t\t\t\t\t\tAND status='awarded'");
     $userCompletions = $this->db->countQ($q);
     $code .= 'User completed this challenge ' . $userCompletions . ' times total, ' . $userCompletionsLast24Hours . ' times today...';
     if ($userCompletions >= $challenge->maxUserCompletions && $challenge->maxUserCompletions != 0) {
         $code .= 'User not allowed to complete this challenge again';
         return false;
     }
     if ($userCompletionsLast24Hours >= $challenge->maxUserCompletionsPerDay && $challenge->maxUserCompletionsPerDay != 0) {
         $code .= 'User not allowed to complete this challenge again today';
         return false;
     }
     if ($userCompletions == 0) {
         $ui->cachedChallengesCompleted++;
         $ui->update();
     }
     if (!$dontLog) {
         require_once PATH_CORE . '/classes/log.class.php';
         $lt = new LogTable($this->db);
         $log = $lt->getRowObject();
         $log->action = 'completedChallenge';
         $log->userid1 = $cc->userid;
         $log->itemid = $completedid;
         $log->dateCreated = date('Y-m-d H:i:s', time());
         $log->insert();
         $cc->logid = $log->id;
         // for consistency, link with the log entry
     }
     $cc->status = 'awarded';
     $cc->pointsAwarded = $pointsAwarded;
     $cc->dateAwarded = date('Y-m-d H:i:s', time());
     $cc->update();
     $challenge->remainingCompletions--;
     $challenge->update();
     $u->cachedPointTotal += $pointsAwarded;
     $u->update();
     $code .= 'Challenge completion approved.';
     return true;
 }
 function userWonPrize($userid, $prizeid)
 {
     require_once PATH_CORE . '/classes/log.class.php';
     $lt = new LogTable($this->db);
     $log = $lt->getRowObject();
     return $log->loadWhere("action='wonPrize' AND userid1={$userid} AND itemid={$prizeid}");
 }