/** * Return the percentage of the progressbar by number * @return number * */ public function getProgress() { // get all the inputs, variable init $groupid = Input::json('groupid'); $user = Auth::user(); $userid = $user->id; $result = array(); // get the total tasks $group = Group::find($groupid); $outcome = Outcome::find($group->outcome); $availArray = array_fetch($outcome->tasks->toArray(), 'id'); //print_r(); $countAvailArray = count($availArray); // get the completed tasks $completedTasks = DB::table('user_tasks')->where('user_id', $userid)->where('group_id', $groupid)->where('complete', 1)->get(); $missions = DB::table('groups')->join('outcome_tasks', 'groups.outcome', '=', 'outcome_tasks.outcome_id')->select('outcome_tasks.*')->where('groups.id', '=', $groupid)->orderBy('outcome_tasks.created_at')->get(); // get total likes for team $totalLikes = DB::select('select l.id FROM likes as l, posts as p WHERE p.group_id = ? AND l.post_id = p.id ', array($groupid)); //print_r(count($completedTasks)); $countCompletedTasksArray = count($completedTasks); // calculating the percentage $progress = $countCompletedTasksArray / $countAvailArray * 100; // $startDate = strtotime($missions{0}->created_at); $startDate = strtotime(User::find($user->id)->created_at); $today = strtotime('now'); $result['progress'] = round($progress, 0); $result['total_mission'] = count($missions); // $result['start_date'] = $missions{0}->created_at; $result['start_date'] = $user->created_at; //$result['completed_days'] = floor(($today - $startDate)/(60*60*24))+1; $result['completed_days'] = daysDiff(new DateTime($user->created_at), new DateTime('now')) + 1; $result['completed_missions'] = count($completedTasks); $result['total_likes'] = count($totalLikes); return $result; }
</span> <label>' . $hc_lang_admin['LogCount'] . '</label> <span class="output"> ' . $logins . ' </span> <label>' . $hc_lang_admin['LogFCount'] . '</label> <span class="output"> ' . $fails . ' </span> <label>' . $hc_lang_admin['Login'] . '</label> <span class="output"> ' . stampToDate($lastlogin, $hc_cfg[24] . ' ' . $hc_cfg[23]) . ' </span> <label>' . $hc_lang_admin['PasswordAge'] . '</label> <span class="output"> ' . ($passAge != '' ? daysDiff($passAge, date("Y-m-d")) - 1 : $hc_lang_admin['Unavailable']) . ' <a class="tooltip" data-tip="' . $hc_lang_admin['Tip01'] . '" href="javascript:;" tabindex="-1"><img src="' . AdminRoot . '/img/icons/info.png" width="16" height="16" alt="" /></a> </span> <label>' . $hc_lang_admin['Recent'] . '</label> <div id="logins" class="output"> ' . ($login_history != '' ? $login_history : $hc_lang_admin['Unavailable']) . ' </div> </fieldset>'; } echo ' <input type="submit" name="submit" id="submit" value="' . $hc_lang_admin['Save'] . '" /> </form> <script src="' . CalRoot . '/inc/javascript/validation.js"></script> <script> //<!--
public function getLeaderBoardData() { $input = Input::all(); $userTaskObj = new UserTask(); // DEFINE JSON STRING // create new LeaderBoard Object $leaderBoardObj = new stdClass(); // $input['keycodes'] = '{"teams": [ // {"keycode": "dev001"}, // {"keycode": "mim001"} // ]}'; // decode json string $teamArray = $input['keycodes']; $teamArray = $teamArray['teams']; $returnArray = array(); $teamCounter = 0; foreach ($teamArray as $key => $value) { # code... $group = DB::table('groups')->where('keycode', $value['keycode'])->get(); $totalPlayers = DB::table('users')->where('keycode', $value['keycode'])->count(); // check the group existence if (count($group) > 0) { // run the logic code to get the number of days passed $groupDetails = $group[0]; $timeStartDate = new DateTime(date("Y-m-d", $groupDetails->timestart)); $dayPassed = daysDiff($timeStartDate, new DateTime('now')) + 1; $returnArray[$teamCounter]['teamid'] = $groupDetails->id; $returnArray[$teamCounter]['teamname'] = $groupDetails->name; $returnArray[$teamCounter]['teamPIC'] = SITE_URL . base64_decode($groupDetails->thumbnail); $returnArray[$teamCounter]['daypassed'] = $dayPassed; $returnArray[$teamCounter]['totalPlayers'] = $totalPlayers; /* // DEFINE VARIABLE // */ $totalNumTeamMissions = 0; $totalNumCompletedMissions = 0; $totalNumLikes = 0; $totalNumComments = 0; $totalNumPosts = 0; $day = array(); // loop thru days for ($i = 1; $i <= $dayPassed; $i++) { # code... $date = $timeStartDate->format('Y-m-d'); $returnArray[$teamCounter]['day'][$i]['date'] = $date; // get the number of completed mission on that day $completedTasks = DB::table('user_tasks')->where('group_id', $groupDetails->id)->where('complete', 1)->where('created_at', 'LIKE', $date . '%')->get(); $totalNumCompletedMissions = $totalNumCompletedMissions + count($completedTasks); $day[$i]['completedTasks'] = count($completedTasks); // get the total posts based on groupID $totalPosts = DB::table('posts')->where('group_id', $groupDetails->id)->where('created_at', 'LIKE', $date . '%')->count(); $totalNumPosts = $totalPosts + $totalNumPosts; $day[$i]['totalPosts'] = $totalPosts; // get the total likes , comments each day JOIN 2 tables into one SQL statement $totalLikesArray = DB::select('select l.id FROM likes as l, posts as p WHERE p.group_id = ? AND l.post_id = p.id AND l.created_at LIKE ? ', array($groupDetails->id, $date . '%')); $totalLikes = count($totalLikesArray); $totalNumLikes = $totalLikes + $totalNumLikes; $day[$i]['totalLikes'] = $totalLikes; // get total comment $totalCommentsArray = DB::select('select l.id FROM comments as l, posts as p WHERE p.group_id = ? AND l.post_id = p.id AND l.created_at LIKE ? ', array($groupDetails->id, $date . '%')); $totalComments = count($totalCommentsArray); $totalNumComments = $totalComments + $totalNumComments; $day[$i]['totalComments'] = $totalComments; $timeStartDate->modify('+1 day'); } $returnArray[$teamCounter]['totalNumTeamMissions'] = $userTaskObj->totalTasks($groupDetails->id); $returnArray[$teamCounter]['totalNumCompletedMissions'] = $totalNumCompletedMissions; $returnArray[$teamCounter]['totalNumLikes'] = $totalNumLikes; $returnArray[$teamCounter]['totalNumComments'] = $totalNumComments; $returnArray[$teamCounter]['totalNumPosts'] = $totalNumPosts; $returnArray[$teamCounter]['totalPoints'] = $totalNumComments + $totalNumLikes + $totalNumPosts + $totalNumCompletedMissions * 6; $returnArray[$teamCounter]['score'] = round($returnArray[$teamCounter]['totalPoints'] / $returnArray[$teamCounter]['totalPlayers'] / $returnArray[$teamCounter]['daypassed'], 1); $dayCollection = array($day); $returnArray[$teamCounter]['day'] = $dayCollection[0]; } $teamCounter++; } function compare($a, $b) { $result = null; if ($a['score'] == $b['score']) { if ($a['totalPoints'] = $b['totalPoints']) { $result = 0; } else { $result = $a['totalPoints'] > $b['totalPoints'] ? -1 : 1; } } else { $result = $a['score'] > $b['score'] ? -1 : 1; } return $result; } usort($returnArray, "compare"); $leaderBoardObj->teams = $returnArray; // return json data return $_GET['callback'] . '(' . json_encode($leaderBoardObj) . ')'; // return json_encode($leaderBoardObj); }
/** * Suspend user after * @return number of user affected */ public function accountSuspentionNotificationCron() { $userObj = new stdClass(); // read user data from the database $users = DB::table('users')->where('suspend_after', 1)->get(array('id', 'created_at')); if (sizeof($users) < 1) { print_r('no users found<br/>'); } // loop thru all the users with email_notification enable foreach ($users as $user) { // init role assignment to check wether the user is admin or normal user $role_assignments = DB::table('role_assignments')->where('user_id', $user->id)->where('role_id', 1)->get(); // get the current group id $groupid = DB::table('group_users')->where('user_id', $user->id)->pluck('group_id'); if (count($role_assignments) > 0) { continue; } $userObj->id = $user->id; $userObj->created_at = $user->created_at; // get total tasks $userTaskObj = new UserTask(); $totaltasks = $userTaskObj->totalTasks($groupid); // calculating suspended date 86400 = 1 day ; 432000 = 5 days $totalDaysBeforeSuspention = $totaltasks + 5; $userCreatedTime = new DateTime($user->created_at); $actualDays = $userCreatedTime->modify('+ ' . $totalDaysBeforeSuspention . ' days'); $currentDate = new DateTime(); $interval = daysDiff($actualDays, $currentDate); if ($interval == 0) { $user = User::find($user->id); $user->suspended = 1; $user->save(); } } return "OK - Task Done"; }
<div class="txt" style="width:50%;">' . cOut($row[1]) . '</div> <div class="txt" style="width:18%;" title="' . $email . '">' . ($row[4] != '' || $row[7] > 0 ? $link . '<a href="mailto:' . $email . '">' . $name . '</a>' : $hc_lang_event['Admin']) . '</div> ' . ($row[4] != '' ? '<div class="txt" style="width:12%;">' . ($sinceSubmit > 0 ? $sinceSubmit . ' ' . $hc_lang_event['Days'] . ' ' . $hc_lang_event['Ago'] : $hc_lang_event['Today']) . '</div>' : '<div class="txt" style="width:12%;">N/A</div>') . ' <div class="txt' . ($untilHappens <= 7 ? ' alert' : '') . '" style="width:10%;">' . ($untilHappens >= 0 ? $untilHappens . ' ' . $hc_lang_event['Days'] : $hc_lang_event['Past']) . '</div> <div class="tools" style="width:10%;"> <a href="' . AdminRoot . '/index.php?com=eventpending&eID=' . $row[0] . '"><img src="' . AdminRoot . '/img/icons/edit.png" width="16" height="16" alt="" /></a> <input type="checkbox" name="eventID[]" id="eventID_' . $row[0] . '" value="' . $row[0] . '" /> </div> </li>'; ++$cnt; } } if (hasRows($resultS)) { while ($row = mysql_fetch_row($resultS)) { $sinceSubmit = daysDiff(date("Y-m-d"), $row[4]) - 1; $untilHappens = daysDiff($row[2], date("Y-m-d"), 0) - 1; $name = $row[7] > 0 ? $row[8] : $row[5]; $email = $row[7] > 0 ? $row[9] : $row[6]; $link = $row[7] > 0 ? '<a href="' . AdminRoot . '/index.php?com=useredit&uID=' . $row[7] . '" target="_blank"><img src="' . AdminRoot . '/img/icons/user_edit.png" widt="16" height="16" style="vertical-align:middle;" /></a> ' : ''; if ($curSeries != $row[3]) { $cnt = 0; $curSeries = $row[3]; echo ' <li class="row header uline"> <div style="width:50%;">' . $hc_lang_event['PendingSeries'] . '</div> <div style="width:18%;">' . $hc_lang_event['Author'] . '</div> <div style="width:12%;">' . $hc_lang_event['Submitted'] . '</div> <div style="width:10%;">' . $hc_lang_event['Happens'] . '</div> <div class="tools" style="width:10%;"> <a href="' . AdminRoot . '/index.php?com=eventpending&sID=' . $row[3] . '"><img src="' . AdminRoot . '/img/icons/edit_group.png" width="16" height="16" alt="" /></a> <a href="javascript:;" onclick="deleteSeries(\'' . $row[3] . '\');return false;"><img src="' . AdminRoot . '/img/icons/delete_group.png" width="16" height="16" alt="" /></a>
if (hasRows($result)) { $resultF = doQuery("SELECT COUNT(*) FROM " . HC_TblPrefix . "adminloginhistory WHERE AdminID = '" . cIn(mysql_result($result, 0, 0)) . "' AND LoginTime > subdate(NOW(), INTERVAL 24 HOUR) AND IsFail = 1"); if (mysql_result($resultF, 0, 0) >= $hc_cfg[80]) { header('Location: ' . AdminRoot . '/index.php?lmsg=2'); exit; } else { if (mysql_result($result, 0, 4) == $password) { if (mysql_result($result, 0, 5) > 0) { $_SESSION['AdminLoggedIn'] = true; $_SESSION['AdminPkID'] = mysql_result($result, 0, 0); $_SESSION['AdminFirstName'] = mysql_result($result, 0, 1); $_SESSION['AdminLastName'] = mysql_result($result, 0, 2); $_SESSION['AdminEmail'] = mysql_result($result, 0, 3); $_SESSION['Instructions'] = mysql_result($result, 0, 9); $_SESSION['LangSet'] = strtolower($_POST['langType']); $_SESSION['PasswordWarn'] = mysql_result($result, 0, 12) == '' || $hc_cfg[26] > 0 && daysDiff(mysql_result($result, 0, 12), date("Y-m-d")) >= $hc_cfg[26] ? 1 : 0; if ($hc_cfg[30] == 1) { // MCImageManager Session Variables $_SESSION['isLoggedIn'] = $_SESSION['AdminLoggedIn']; $_SESSION['imagemanager.preview.wwwroot'] = "../../../../uploads"; $_SESSION['imagemanager.preview.urlprefix'] = CalRoot . "/uploads"; $_SESSION['imagemanager.filesystem.rootpath'] = "../../../../uploads"; } elseif ($hc_cfg[30] == 2) { // Moxiemanager Session Variables $_SESSION['moxman_isauth'] = $_SESSION['AdminLoggedIn']; $_SESSION['moxman.filesystem.rootpath'] = CalName . ' Images=../../../../uploads'; $_SESSION['moxman.filesystem.local.urlprefix'] = CalRoot; $_SESSION['moxman.storage.path'] = '../../../../uploads'; } doQuery("UPDATE " . HC_TblPrefix . "admin SET LoginCnt = LoginCnt + 1, PCKey = NULL, Access = '" . cIn(md5(session_id())) . "', LastLogin = NOW() WHERE PkID = '" . cIn($_SESSION['AdminPkID']) . "'"); doQuery("INSERT INTO " . HC_TblPrefix . "adminloginhistory(AdminID, IP, Client, LoginTime) Values('" . $_SESSION['AdminPkID'] . "', '" . cIn(strip_tags($_SERVER["REMOTE_ADDR"])) . "', '" . cIn(strip_tags($_SERVER["HTTP_USER_AGENT"])) . "', NOW())");