/** * Executes index action */ public function executeIndex() { unset($_SESSION['dash_hidden']); unset($_SESSION['subject']); unset($_SESSION['edu']); unset($_SESSION['course_id']); unset($_SESSION['name']); unset($_SESSION['course_code']); unset($_SESSION['year']); unset($_SESSION['grade']); unset($_SESSION['question']); if (!empty($_COOKIE["timer"])) { $this->redirect('/dashboard/rating'); } $connection = RaykuCommon::getDatabaseConnection(); /* @var $raykuUser User */ $raykuUser = $this->getUser()->getRaykuUser(); $c = new Criteria(); $c->addJoin(ExpertCategoryPeer::USER_ID, UserTutorPeer::USERID, Criteria::INNER_JOIN); $rankexperts = ExpertCategoryPeer::doSelect($c); $rankUsers = array(); $ji = 0; $eachExpertOnlyOnce = array(); foreach ($rankexperts as $exp) { if (in_array($exp->getUserId(), $eachExpertOnlyOnce)) { continue; } $eachExpertOnlyOnce[] = $exp->getUserId(); $query = mysql_query("select * from user_score where user_id=" . $exp->getUserId(), $connection) or die(mysql_error()); $score = mysql_fetch_assoc($query); if ($score['score'] != 0) { $dv = new Criteria(); $dv->add(UserPeer::ID, $exp->getUserId()); $_thisUser = UserPeer::doSelectOne($dv); $rankUsers[$ji] = array("score" => $score['score'], "userid" => $exp->getUserId(), "createdat" => $_thisUser->getCreatedAt()); $ji++; } } asort($rankUsers); arsort($rankUsers); $this->rankUsers = $rankUsers; $queryScore = mysql_query("select * from user_score where user_id =" . $raykuUser->getId() . " and score >= 125 and status = 0", $connection) or die(mysql_error()); $this->changeUserType = null; if (mysql_num_rows($queryScore) > 0) { $this->changeUserType = 1; } }
/** * all members database */ public function execute($request) { RaykuCommon::getDatabaseConnection(); $logedUserId = $_SESSION['symfony/user/sfUser/attributes']['symfony/user/sfUser/attributes']['user_id']; $currentUser = $this->getUser()->getRaykuUser(); $userId = $currentUser->getId(); $this->userId = $currentUser->getId(); /* Clearing Cookies if($_COOKIE['onoff'] != 1) { for($u=$_COOKIE['cookcount'];$u>=1;$u--) { $cookname = 'tutor_'.$u; setcookie($cookname,'', time()-3600, "/"); } setcookie("tutorcount",'', time()-3600, "/"); setcookie("cookcount",'', time()-3600, "/"); } /* Clearing Cookies */ $time = time(); if (!empty($_POST['hidden'])) { $count = count($_POST['checkbox']); /* Clearing Cookies */ for ($u = $_COOKIE['cookcount']; $u >= 1; $u--) { $cookname = 'tutor_' . $u; $this->getResponse()->setCookie($cookname, '', time() - 3600, '/', sfConfig::get('app_cookies_domain')); } $this->getResponse()->setCookie("tutorcount", '', time() - 3600, '/', sfConfig::get('app_cookies_domain')); $this->getResponse()->setCookie("cookcount", '', time() - 3600, '/', sfConfig::get('app_cookies_domain')); /* Clearing Cookies */ if ($count == 4) { $close = 46000; $_SESSION['connected_tutors'] = 4; } if ($count == 3) { $close = 46000; $_SESSION['connected_tutors'] = 3; } else { if ($count == 2) { $close = 61000; $_SESSION['connected_tutors'] = 2; } else { if ($count == 1) { $close = 61000; $_SESSION['connected_tutors'] = 1; } else { $close = 61000; $_SESSION['connected_tutors'] = 1; } } } $j = 0; for ($i = 0; $i < $count; $i++) { mysql_query("INSERT INTO `user_expert` (`user_id`, `checked_id`, `category_id`, `question`, `exe_order`, `time`, status, close) VALUES ('" . $userId . "', '" . $_POST['checkbox'][$i] . "', '5', 'To be discussed','" . ++$j . "', '" . $time . "', 1, " . $close . ") ") or die(mysql_error()); } /* Notify same tutor again */ $l = 0; $source = 'tutorlist'; mysql_query("DELETE FROM `student_questions` WHERE user_id=" . $userId . ""); for ($i = 0; $i < $count; $i++) { mysql_query("INSERT INTO `student_questions` (`user_id`, `checked_id`, `category_id`, `question`, `exe_order`, `time`, status, close, source) VALUES ('" . $userId . "', '" . $_POST['checkbox'][$i] . "', '5', 'To be discussed','" . ++$l . "', '" . $time . "', 1, " . $close . ", '" . $source . "') ") or die(mysql_error()); } setcookie("asker_que", $_SESSION['question'], time() + 600, "/", sfConfig::get('app_cookies_domain')); $this->getResponse()->setCookie("redirection", 1, time() + 600, '/', sfConfig::get('app_cookies_domain')); $this->getResponse()->setCookie("forumsub", 1, time() + 600, '/', sfConfig::get('app_cookies_domain')); $this->redirect('expertmanager/connect'); } $this->cat = $this->getRequestParameter('category'); $this->course_id = $this->getRequestParameter('course'); if (empty($this->course_id)) { $this->course_id = 1; } if (empty($this->cat)) { $this->cat = 1; } $queryPoints = mysql_query("select * from user where id=" . $userId) or die("Error In rate" . mysql_error()); if (mysql_num_rows($queryPoints) > 0) { $rowPoints = mysql_fetch_assoc($queryPoints); $_points = $rowPoints['points']; } $c = new Criteria(); $c->addJoin(ExpertCategoryPeer::USER_ID, UserTutorPeer::USERID, Criteria::INNER_JOIN); if ($this->cat == 5) { $experts = ExpertCategoryPeer::doSelect($c); } else { $c->add(ExpertCategoryPeer::CATEGORY_ID, $this->cat); $experts = ExpertCategoryPeer::doSelect($c); } $newUser = array(); $i = 0; $eachExpertOnlyOnce = array(); foreach ($experts as $exp) { if (in_array($exp->getUserId(), $eachExpertOnlyOnce)) { continue; } $eachExpertOnlyOnce[] = $exp->getUserId(); $_queryCourse = mysql_query("select * from expert_course where user_id =" . $exp->getUserId() . " and category_id = 1 and course_id = " . $this->course_id . " ") or die("Er-1-->" . mysql_error()); if (mysql_num_rows($_queryCourse) > 0) { $query = mysql_query("select * from user_score where user_id=" . $exp->getUserId()) or die(mysql_error()); $score = mysql_fetch_assoc($query); if ($score['score'] != 0) { if (false) { //$_points == '' || $_points == '0.00' Temporary hack $emptyRCquery = mysql_query("select * from user_rate where userid=" . $exp->getUserId() . " and (rate = 0.00 || rate = 0) ") or die("Error In rate" . mysql_error()); if (mysql_num_rows($emptyRCquery) > 0) { $dv = new Criteria(); $dv->add(UserPeer::ID, $exp->getUserId()); $_thisUser = UserPeer::doSelectOne($dv); $newUser[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt()); $i++; } } else { $dv = new Criteria(); $dv->add(UserPeer::ID, $exp->getUserId()); $_thisUser = UserPeer::doSelectOne($dv); $newUser[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt()); $i++; } } } } asort($newUser); arsort($newUser); $this->rankCheckUsers = $newUser; ////if no online expert available redirecting to the board page $onlineusers = array(); $offlineusers = array(); $newOnlineUser = array(); $newOfflineUser = array(); $j = 0; $k = 0; $facebookResponse = BotServiceProvider::createFor(sfConfig::get('app_facebook_url') . "/tutor")->getContent(); $facebookUsers = json_decode($facebookResponse, true); $botResponse = BotServiceProvider::createFor(sfConfig::get('app_notification_bot_url') . "/tutor")->getContent(); $botUsers = json_decode($botResponse, true); foreach ($newUser as $new) { $a = new Criteria(); $a->add(UserPeer::ID, $new['userid']); $users_online = UserPeer::doSelectOne($a); $onlinecheck = ''; if ($users_online->isOnline()) { $onlinecheck = "online"; } if (empty($onlinecheck)) { $userGtalk = $users_online->getUserGtalk(); if ($userGtalk) { $onlinecheck = BotServiceProvider::createFor(sfConfig::get('app_rayku_url') . ':' . sfConfig::get('app_g_chat_port') . '/status/' . $userGtalk->getGtalkid())->getContent(); } } if ((empty($onlinecheck) || $onlinecheck != "online") && is_array($facebookUsers)) { $fb_query = mysql_query("select * from user_fb where userid=" . $new['userid']) or die(mysql_error()); if (mysql_num_rows($fb_query) > 0) { $fbRow = mysql_fetch_assoc($fb_query); $fb_username = $fbRow['fb_username']; foreach ($facebookUsers as $key => $user) { if ($user['username'] == $fb_username) { $onlinecheck = 'online'; break; } } } } if ((empty($onlinecheck) || $onlinecheck != "online") && is_array($botUsers)) { foreach ($botUsers as $key => $_user) { if ($_user['email'] == $users_online->getEmail()) { $onlinecheck = 'online'; break; } } } if ($onlinecheck == "online") { $onlineusers[$j] = $new['userid']; $newOnlineUser[$j] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']); $j++; } elseif ($users_online->isOnline()) { $newOnlineUser[$j] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']); $onlineusers[$j] = $new['userid']; $j++; } else { $newOfflineUser[$k] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']); $offlineusers[$k] = $new['userid']; $k++; } } $this->newOnlineUser = $newOnlineUser; $this->newOfflineUser = $newOfflineUser; $this->_checkOnlineUsers = $onlineusers; ///////////////////////////////////////////////////// if (isset($_COOKIE["onoff"]) && $_COOKIE["onoff"] == 1) { if (!empty($_COOKIE["school"])) { $cookieSchool = array(); $m = 0; foreach ($newOnlineUser as $new) { $b = new Criteria(); $b->add(UserPeer::ID, $new['userid']); $schoolusers = UserPeer::doSelectOne($b); $mail = explode("@", $schoolusers->getEmail()); $newMail = explode(".", $mail[1]); if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) { $cookieSchool[$m] = $new; $m++; } } $this->expert_cats = $cookieSchool; } else { $this->expert_cats = $newOnlineUser; } } else { if (isset($_COOKIE["onoff"]) && $_COOKIE["onoff"] == 2) { if (!empty($_COOKIE["school"])) { $cookieSchool = array(); $m = 0; foreach ($newOfflineUser as $new) { $b = new Criteria(); $b->add(UserPeer::ID, $new['userid']); $schoolusers = UserPeer::doSelectOne($b); $mail = explode("@", $schoolusers->getEmail()); $newMail = explode(".", $mail[1]); if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) { $cookieSchool[$m] = $new; $m++; } } $this->expert_cats = $cookieSchool; } else { $this->expert_cats = $newOfflineUser; } } else { if (!empty($_COOKIE["school"])) { $cookieSchool = array(); $m = 0; foreach ($newUser as $new) { $b = new Criteria(); $b->add(UserPeer::ID, $new['userid']); $schoolusers = UserPeer::doSelectOne($b); $mail = explode("@", $schoolusers->getEmail()); $newMail = explode(".", $mail[1]); if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) { $cookieSchool[$m] = $new; $m++; } } $this->expert_cats = $cookieSchool; } else { $this->expert_cats = $newUser; } } } $this->tutorsCount = count($this->expert_cats); $c = new Criteria(); $c->add(CategoryPeer::ID, $this->cat); $this->e = CategoryPeer::doSelectOne($c); }
/** * Action to display login page */ public function executeIndex() { $connection = RaykuCommon::getDatabaseConnection(); if ($this->getRequestParameter('username') == null) { $this->redirect("/dashboard"); } $c = new Criteria(); $c->add(UserPeer::USERNAME, $this->getRequestParameter('username')); $user = UserPeer::doSelectOne($c); $this->user = $user; $this->tutor_id = $user->getId(); $c = new Criteria(); $c->addJoin(ExpertCategoryPeer::USER_ID, UserTutorPeer::USERID, Criteria::INNER_JOIN); $rankexperts = ExpertCategoryPeer::doSelect($c); $rankUsers = array(); $ji = 0; $eachExpertOnlyOnce = array(); $rankScore = array(); /** * @todo this loop parses all experts only to later use only one of them in template - fix this */ foreach ($rankexperts as $exp) { if (in_array($exp->getUserId(), $eachExpertOnlyOnce)) { continue; } $eachExpertOnlyOnce[] = $exp->getUserId(); $query = mysql_query("select * from user_score where user_id=" . $exp->getUserId(), $connection) or die(mysql_error()); $score = mysql_fetch_assoc($query); if ($score['score'] != 0) { $dv = new Criteria(); $dv->add(UserPeer::ID, $exp->getUserId()); $_thisUser = UserPeer::doSelectOne($dv); $rankUsers[$ji] = array("score" => $score['score'], "userid" => $exp->getUserId(), "createdat" => $_thisUser->getCreatedAt()); $ji++; } } asort($rankUsers); arsort($rankUsers); $this->rankUsers = $rankUsers; ////////////////////////////// if (!empty($_GET['expert_id'])) { $_expert_id = !empty($_GET['expert_id']) ? $_GET['expert_id'] : 0; $userId = $this->getUser()->getRaykuUserId(); if ($_expert_id) { $query = mysql_query("select * from expert_subscribers where expert_id = " . $_expert_id . " and user_id =" . $userId, $connection) or die(mysql_error()); if (mysql_num_rows($query) == 0) { $_query = mysql_query("insert into expert_subscribers(expert_id, user_id) values(" . $_expert_id . ", " . $userId . ")", $connection) or die("Error--->" . mysql_error()); $queryScore = mysql_query("select * from user_score where user_id =" . $_expert_id, $connection) or die(mysql_error()); $rowScore = mysql_fetch_assoc($queryScore); $newScore = ''; $newScore = $rowScore['score'] + 10; mysql_query("update user_score set score = " . $newScore . " where user_id =" . $_expert_id, $connection) or die(mysql_error()); } } $this->redirect("/tutor/" . $user->getUsername()); } if ($this->getRequestParameter('content') != null) { $this->expertid = $this->getUser()->getRaykuUser()->getId(); $this->expertusr = $this->getUser()->getRaykuUser()->getUsername(); $this->content = $this->getRequestParameter('content'); $c = new Criteria(); $c->add(ExpertsPromoTextPeer::EXP_ID, $this->expertid); $expertstext = ExpertsPromoTextPeer::doSelectOne($c); if ($expertstext != null) { $expertstext->setContent($this->content); $expertstext->save(); } else { $promo = new ExpertsPromoText(); $promo->setExpId($this->expertid); $promo->setContent($this->content); $promo->save(); } } $this->expert = $user; $f = new Criteria(); $f->add(PostPeer::POSTER_ID, $user->getId()); $f->add(PostPeer::BEST_RESPONSE, '1'); $f->addDescendingOrderByColumn('ID'); $this->bestResponses = PostPeer::doSelect($f); $f->setLimit(6); $this->best_responses = PostPeer::doSelect($f); $expertId = $user->getId(); $userId = $this->getUser()->getRaykuUserId(); $this->currentUser = $this->getUser()->getRaykuUser(); // last n whiteboard sessions $cLastSessions = new Criteria(); if ($userId != $expertId) { $cPublicA = $cLastSessions->getNewCriterion(WhiteboardChatPeer::EXPERT_ID, $expertId); $cPublicB = $cLastSessions->getNewCriterion(WhiteboardChatPeer::IS_PUBLIC, true); $cPublicC = $cLastSessions->getNewCriterion(WhiteboardChatPeer::ASKER_ID, $userId); $cPublicB->addOr($cPublicC); $cPublicA->addAnd($cPublicB); } else { $cPublicA = $cLastSessions->getNewCriterion(WhiteboardChatPeer::EXPERT_ID, $userId); $cPublicB = $cLastSessions->getNewCriterion(WhiteboardChatPeer::ASKER_ID, $userId); $cPublicA->addOr($cPublicB); } $cLastSessions->add($cPublicA); $cLastSessions->add(WhiteboardChatPeer::STARTED_AT, null, Criteria::ISNOTNULL); $cLastSessions->addDescendingOrderByColumn(WhiteboardChatPeer::ID); $this->totalSessions = WhiteboardChatPeer::doSelect($cLastSessions); $cLastSessions->setLimit(3); $this->lastSessions = WhiteboardChatPeer::doSelect($cLastSessions); }
</strong> </div> <div class="points" style="font-weight:normal;color:#666;margin-top:4px;">RP: <strong> <?php $query = mysql_query("select * from user where id=" . $logedUserId . " ", $connection) or die(mysql_error()); $detailPoints = mysql_fetch_assoc($query); echo $detailPoints['points']; ?> </strong> </div> <!-- Expert Rank --> <?php $c = new Criteria(); $c->addJoin(ExpertCategoryPeer::USER_ID, UserTutorPeer::USERID, Criteria::INNER_JOIN); $rankexperts = ExpertCategoryPeer::doSelect($c); $rankUsers = array(); $ji = 0; $eachExpertOnlyOnce = array(); foreach ($rankexperts as $exp) { if (in_array($exp->getUserId(), $eachExpertOnlyOnce)) { continue; } $eachExpertOnlyOnce[] = $exp->getUserId(); $query = mysql_query("select * from user_score where user_id=" . $exp->getUserId(), $connection) or die(mysql_error()); $score = mysql_fetch_assoc($query); if ($score['score'] != 0) { $rankUsers[$ji] = array("score" => $score['score'], "userid" => $exp->getUserId()); $ji++; } }
public function execute($request) { $connection = RaykuCommon::getDatabaseConnection(); $logedUserId = $_SESSION['symfony/user/sfUser/attributes']['symfony/user/sfUser/attributes']['user_id']; $currentUser = $this->getUser()->getRaykuUser(); $userId = $currentUser->getId(); $this->userId = $currentUser->getId(); $time = time(); if (empty($_SESSION["course_id"])) { $_SESSION["course_id"] = '1'; } $this->cat = $this->getRequestParameter('category'); $this->course_id = $this->getRequestParameter('course'); if (empty($this->course_id)) { if (!empty($_SESSION['course_id'])) { $this->course_id = $_SESSION['course_id']; } else { $this->course_id = 1; } } else { $_SESSION['course_id'] = $this->course_id; } if (empty($this->cat)) { if (!empty($_SESSION['subject'])) { $this->cat = $_SESSION['subject']; } else { $this->cat = 1; } } else { $_SESSION['subject'] = $this->cat; } $logedUserId = $_SESSION['symfony/user/sfUser/attributes']['symfony/user/sfUser/attributes']['user_id']; $c = new Criteria(); $c->addJoin(ExpertCategoryPeer::USER_ID, UserTutorPeer::USERID, Criteria::INNER_JOIN); if ($this->cat == 5) { $experts = ExpertCategoryPeer::doSelect($c); } else { $c->add(ExpertCategoryPeer::CATEGORY_ID, $this->cat); $experts = ExpertCategoryPeer::doSelect($c); } $queryPoints = mysql_query("select * from user where id = " . $userId, $connection) or die("Error In rate" . mysql_error()); if (mysql_num_rows($queryPoints) > 0) { $rowPoints = mysql_fetch_assoc($queryPoints); $_points = $rowPoints['points']; } $newUser = array(); $i = 0; $eachExpertOnlyOnce = array(); foreach ($experts as $exp) { if ($userId != $exp->getUserId()) { if (in_array($exp->getUserId(), $eachExpertOnlyOnce)) { continue; } $eachExpertOnlyOnce[] = $exp->getUserId(); /* Testing - Student match with Tutors */ $_queryCourse = ''; $tutorsq = mysql_query("select * from tutor_profile where category = 1 and user_id = " . $exp->getUserId() . "", $connection) or die("Er-1-->" . mysql_error()); $tutors = mysql_fetch_array($tutorsq); $tutor = ''; $tutor = explode("-", $tutors['course_id']); if (in_array($_SESSION["course_id"], $tutor)) { $_queryCourse = mysql_query("select * from tutor_profile where category = 1 and user_id = " . $exp->getUserId() . "", $connection) or die("Er-1-->" . mysql_error()); //echo "select * from tutor_profile where category = 1 and user_id = ".$exp->getUserId().""; } if (@mysql_num_rows($_queryCourse) > 0) { $query = mysql_query("select * from user_score where user_id = " . $exp->getUserId(), $connection) or die(mysql_error()); $score = mysql_fetch_assoc($query); if ($score['score'] != 0) { if ($_points == '' || $_points == '0.00') { $emptyRCquery = mysql_query("select * from user_rate where userid = " . $exp->getUserId() . " and (rate = 0.00 || rate = 0) ", $connection) or die("Error In rate" . mysql_error()); if (mysql_num_rows($emptyRCquery) > 0) { $dv = new Criteria(); $dv->add(UserPeer::ID, $exp->getUserId()); $_thisUser = UserPeer::doSelectOne($dv); $rankUsersFinal[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt()); $newUser[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt()); $i++; } } else { $dv = new Criteria(); $dv->add(UserPeer::ID, $exp->getUserId()); $_thisUser = UserPeer::doSelectOne($dv); $rankUsersFinal[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt()); $newUser[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt()); $i++; } } } } } asort($newUser); arsort($newUser); asort($rankUsersFinal); arsort($rankUsersFinal); $this->rankCheckUsers = $rankUsersFinal; ////if no online expert available redirecting to the board page // // ant-edit remove for now $onlineusers = array(); $offlineusers = array(); $newOnlineUser = array(); $newOfflineUser = array(); $j = 0; $k = 0; // $facebookTutors = BotServiceProvider::createFor("http://facebook.rayku.com/tutor")->getContent(); // $onlineTutorsByNotificationBot = BotServiceProvider::createFor("http://notification-bot.rayku.com/tutor")->getContent(); foreach ($newUser as $new) { $a = new Criteria(); $a->add(UserPeer::ID, $new['userid']); $users_online = UserPeer::doSelectOne($a); $onlinecheck = ''; if ($users_online->isOnline()) { $onlinecheck = "online"; } // ant-edit remove for now if (empty($onlinecheck)) { $userGtalk = $users_online->getUserGtalk(); if ($userGtalk) { $onlinecheck = BotServiceProvider::createFor(sfConfig::get('app_rayku_url') . ':' . sfConfig::get('app_g_chat_port') . '/status/' . $userGtalk->getGtalkid())->getContent(); // echo 'hello ' . $onlinecheck ; } } // if (empty($onlinecheck) || ($onlinecheck != "online")) { // $userFb = UserFbPeer::retrieveByUserId($new['userid']); // if ($userFb) { // $fb_username = $userFb->getFbUsername(); // $Users = json_decode($facebookTutors, true); // foreach ($Users as $key => $user) { // if ($user['username'] == $fb_username) { // $onlinecheck = 'online'; // break; // } // } // } // } // if (empty($onlinecheck) || ($onlinecheck != "online")) { // $_Users = json_decode($onlineTutorsByNotificationBot, true); // foreach ($_Users as $key => $_user) { // if ($_user['email'] == $users_online->getEmail()) { // $onlinecheck = 'online'; // break; // } // } // } if ($onlinecheck == "online") { $onlineusers[$j] = $new['userid']; $newOnlineUser[$j] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']); $j++; } elseif ($users_online->isOnline()) { $newOnlineUser[$j] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']); $onlineusers[$j] = $new['userid']; $j++; } else { $newOfflineUser[$k] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']); $offlineusers[$k] = $new['userid']; $k++; } } $this->newOnlineUser = $newOnlineUser; $this->newOfflineUser = $newOfflineUser; $this->_checkOnlineUsers = $onlineusers; if (count($onlineusers) < 1) { $this->redirect('/forum/newthread/' . $_SESSION['subject'] . '?exp_online = 1'); } $onoff = isset($_COOKIE["onoff"]) ? $_COOKIE["onoff"] : null; if ($onoff == 1) { if (!empty($_COOKIE["school"])) { $cookieSchool = array(); $m = 0; foreach ($newOnlineUser as $new) { $b = new Criteria(); $b->add(UserPeer::ID, $new['userid']); $schoolusers = UserPeer::doSelectOne($b); $mail = explode("@", $schoolusers->getEmail()); $newMail = explode(".", $mail[1]); if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) { $cookieSchool[$m] = $new; $m++; } } $this->expert_cats = $cookieSchool; } else { $this->expert_cats = $newOnlineUser; } } else { if ($onoff == 2) { if (!empty($_COOKIE["school"])) { $cookieSchool = array(); $m = 0; foreach ($newOfflineUser as $new) { $b = new Criteria(); $b->add(UserPeer::ID, $new['userid']); $schoolusers = UserPeer::doSelectOne($b); $mail = explode("@", $schoolusers->getEmail()); $newMail = explode(".", $mail[1]); if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) { $cookieSchool[$m] = $new; $m++; } } $this->expert_cats = $cookieSchool; } else { $this->expert_cats = $newOfflineUser; } } else { if (!empty($_COOKIE["school"])) { $cookieSchool = array(); $m = 0; foreach ($newUser as $new) { $b = new Criteria(); $b->add(UserPeer::ID, $new['userid']); $schoolusers = UserPeer::doSelectOne($b); $mail = explode("@", $schoolusers->getEmail()); $newMail = explode(".", $mail[1]); if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) { $cookieSchool[$m] = $new; $m++; } } $this->expert_cats = $cookieSchool; } else { $this->expert_cats = $newUser; } } } $this->tutorsCount = count($this->expert_cats); $c = new Criteria(); $c->add(CategoryPeer::ID, $this->cat); $this->e = CategoryPeer::doSelectOne($c); }
public function execute($request) { $connection = RaykuCommon::getDatabaseConnection(); $logedUserId = $_SESSION['symfony/user/sfUser/attributes']['symfony/user/sfUser/attributes']['user_id']; $currentUser = $this->getUser()->getRaykuUser(); $userId = $currentUser->getId(); $this->userId = $currentUser->getId(); $time = time(); $this->cat = $this->getRequestParameter('category'); $this->course_id = $this->getRequestParameter('course'); if (empty($this->course_id)) { if (!empty($_SESSION['course_id'])) { $this->course_id = $_SESSION['course_id']; } else { $this->course_id = 1; } } else { $_SESSION['course_id'] = $this->course_id; } if (empty($this->cat)) { if (!empty($_SESSION['subject'])) { $this->cat = $_SESSION['subject']; } else { $this->cat = 1; } } else { $_SESSION['subject'] = $this->cat; } if (empty($_SESSION["course_id"])) { $_SESSION["course_id"] = '1'; } /* Quick Registration Users - Listing Tutors */ if ($this->studentFromQuickRegistrationAskingAQuestion()) { $_dash_question = ''; $_dash_course_id = ''; $_school = ''; $_dash_education = ''; $_dash_code_id = ''; $_dash_year = ''; $_SESSION['subject'] = 1; $_dash_education = $_SESSION['edu']; $_dash_course_id = $_SESSION['course_id']; if ($_dash_course_id) { $queryCname = mysql_query("select * from courses where id ='" . $_dash_course_id . "'", $connection) or die(mysql_error()); $rowCoursename = mysql_fetch_array($queryCname); $_SESSION['course_name_sess'] = $rowCoursename['course_name']; } if (strtolower($_SESSION['year']) != "Choose year") { $_dash_year = trim($_SESSION['year']); } elseif (strtolower($_SESSION['grade']) != "Choose grade") { $_dash_year = trim($_SESSION['grade']); } $c = new Criteria(); $c->add(UserQuestionTagPeer::CATEGORY_ID, 1); $c->add(UserQuestionTagPeer::USER_ID, $userId); $c->add(UserQuestionTagPeer::COURSE_ID, $_dash_course_id); $c->add(UserQuestionTagPeer::COURSE_CODE, $_dash_code_id); $c->add(UserQuestionTagPeer::EDUCATION, $_dash_education); $c->add(UserQuestionTagPeer::SCHOOL, $_school); $c->add(UserQuestionTagPeer::YEAR, $_dash_year); $userQuestionTag = UserQuestionTagPeer::doSelectOne($c); if ($userQuestionTag) { $userQuestionTag->delete(); } $userQuestionTag = new UserQuestionTag(); $userQuestionTag->setUserId($userId); $userQuestionTag->setCategoryId(1); $userQuestionTag->setCourseId($_dash_course_id); $userQuestionTag->setCourseCode($_dash_code_id); $userQuestionTag->setEducation($_dash_education); $userQuestionTag->setSchool($_school); $userQuestionTag->setYear($_dash_year); $userQuestionTag->setQuestion($_SESSION['question']); $userQuestionTag->save(); } else { if ($this->loggedStudentAsksAQuestion()) { $_dash_question = ''; $_dash_course_id = ''; $_school = ''; $_dash_education = ''; $_dash_code_id = ''; $_dash_year = ''; $_dash_question = $_POST['question']; $_SESSION['question'] = $_dash_question; $_SESSION['subject'] = 1; if (!empty($_POST['course_category_hidden'])) { $course_name = trim($_POST['course_category_hidden']); $_SESSION['course_name_sess'] = $course_name; $_queryCourse = mysql_query("select * from courses where course_name ='" . $course_name . "' ", $connection) or die(mysql_error()); $_rowCourse = mysql_fetch_assoc($_queryCourse); $_dash_course_id = $_rowCourse['id']; $_SESSION["course_id"] = $_dash_course_id; } $_dash_education = $_POST['edu']; /* Student Confirmation */ $_SESSION['edu'] = $_dash_education; if (strtolower($_POST['year_hidden']) != "choose year") { $_dash_year = trim($_POST['year_hidden']); /* student confirmation */ $_SESSION['year'] = $_dash_year; } elseif (strtolower($_POST['grade_hidden']) != "choose grade") { $_dash_year = trim($_POST['grade_hidden']); /* student confirmation */ $_SESSION['grade'] = $_dash_year; } $c = new Criteria(); $c->add(UserQuestionTagPeer::CATEGORY_ID, 1); $c->add(UserQuestionTagPeer::USER_ID, $userId); $c->add(UserQuestionTagPeer::COURSE_ID, $_dash_course_id); $c->add(UserQuestionTagPeer::COURSE_CODE, $_dash_code_id); $c->add(UserQuestionTagPeer::EDUCATION, $_dash_education); $c->add(UserQuestionTagPeer::SCHOOL, $_school); $c->add(UserQuestionTagPeer::YEAR, $_dash_year); $userQuestionTag = UserQuestionTagPeer::doSelectOne($c); if ($userQuestionTag) { $userQuestionTag->delete(); } $userQuestionTag = new UserQuestionTag(); $userQuestionTag->setUserId($userId); $userQuestionTag->setCategoryId(1); $userQuestionTag->setCourseId($_dash_course_id); $userQuestionTag->setCourseCode($_dash_code_id); $userQuestionTag->setEducation($_dash_education); $userQuestionTag->setSchool($_school); $userQuestionTag->setYear($_dash_year); $userQuestionTag->setQuestion($_POST['question']); $userQuestionTag->save(); } } /** * @todo - below block of code could be extracted to separate action */ if (!empty($_POST['hidden'])) { $count = count($_POST['checkbox']); /* Clearing Cookies */ if (isset($_COOKIE['cookcount'])) { for ($u = $_COOKIE['cookcount']; $u >= 1; $u--) { $cookname = 'expert_' . $u; setcookie($cookname, '', time() - 3600, "/", sfConfig::get('app_cookies_domain')); } } setcookie("expertscount", '', time() - 3600, "/", sfConfig::get('app_cookies_domain')); setcookie("cooktotal", '', time() - 3600, "/", sfConfig::get('app_cookies_domain')); /* Clearing Cookies */ if ($count == 4) { $close = 46000; $_SESSION['connected_tutors'] = 4; } else { if ($count == 3) { $close = 46000; $_SESSION['connected_tutors'] = 3; } else { if ($count == 2) { $close = 61000; $_SESSION['connected_tutors'] = 2; } else { if ($count == 1) { $close = 61000; $_SESSION['connected_tutors'] = 1; } else { $close = 61000; $_SESSION['connected_tutors'] = 1; } } } } $j = 0; $c = new Criteria(); $c->add(UserQuestionTagPeer::USER_ID, $userId); $c->addDescendingOrderByColumn(UserQuestionTagPeer::ID); $userQuestionTag = UserQuestionTagPeer::doSelectOne($c); $course_code = ''; $year = ''; $course_id = '1'; $school = ''; if ($userQuestionTag) { $course_id = $userQuestionTag->getCourseId(); $course_code = $userQuestionTag->getCourseCode(); $year = $userQuestionTag->getYear(); $school = $userQuestionTag->getSchool(); if ($userQuestionTag->getEducation() == 2) { $school = "High School"; } } // this is where the sql injection error is happening, fix this // escape single quotes for ($i = 0; $i < $count; $i++) { mysql_query("INSERT INTO `user_expert` (`user_id`, `checked_id`, `category_id`, course_id, `question`, `exe_order`, `time`,course_code, year, school, status, close) VALUES ('" . mysql_real_escape_string($userId) . "', '" . mysql_real_escape_string($_POST['checkbox'][$i]) . "', " . mysql_real_escape_string($this->cat) . ", " . mysql_real_escape_string($course_id) . ",'" . mysql_real_escape_string($_SESSION['question']) . "','" . mysql_real_escape_string(++$j) . "', '" . mysql_real_escape_string($time) . "', '" . mysql_real_escape_string($course_code) . "', '" . mysql_real_escape_string($year) . "', '" . mysql_real_escape_string($school) . "', 1, " . mysql_real_escape_string($close) . ") ", $connection) or die("Error In Insert-->" . mysql_error()); } /* Notify same tutor again */ $l = 0; $source = 'expertmanager'; mysql_query("DELETE FROM `student_questions` WHERE user_id = " . $userId . "", $connection); for ($i = 0; $i < $count; $i++) { $question = new StudentQuestion(); $question->setStudentId($userId); $question->setTutorId($_POST['checkbox'][$i]); $question->setCategoryId($this->cat); $question->setCourseId($course_id); $question->setQuestion($_SESSION['question']); $question->setExeOrder(++$l); $question->setTime($time); $question->setCourseCode($course_code); $question->setYear($year); $question->setSchool($school); $question->setStatus(1); $question->setClose($close); $question->setSource($source); $question->save(); } setcookie("asker_que", urldecode($_SESSION['question']), time() + 600, "/", sfConfig::get('app_cookies_domain')); $this->getResponse()->setCookie("redirection", 1, time() + 600, '/', sfConfig::get('app_cookies_domain')); $this->getResponse()->setCookie("forumsub", $_SESSION['subject'], time() + 600, '/', sfConfig::get('app_cookies_domain')); $this->redirect('expertmanager/connect'); } $logedUserId = $_SESSION['symfony/user/sfUser/attributes']['symfony/user/sfUser/attributes']['user_id']; $c = new Criteria(); $c->addJoin(ExpertCategoryPeer::USER_ID, UserTutorPeer::USERID, Criteria::INNER_JOIN); if ($this->cat == 5) { $experts = ExpertCategoryPeer::doSelect($c); } else { $c->add(ExpertCategoryPeer::CATEGORY_ID, $this->cat); $experts = ExpertCategoryPeer::doSelect($c); } $queryPoints = mysql_query("select * from user where id = " . $userId, $connection) or die("Error In rate" . mysql_error()); if (mysql_num_rows($queryPoints) > 0) { $rowPoints = mysql_fetch_assoc($queryPoints); $_points = $rowPoints['points']; } $newUser = array(); $i = 0; $eachExpertOnlyOnce = array(); foreach ($experts as $exp) { if ($userId != $exp->getUserId()) { if (in_array($exp->getUserId(), $eachExpertOnlyOnce)) { continue; } $eachExpertOnlyOnce[] = $exp->getUserId(); $_queryCourse = ''; $tutorsq = mysql_query("select * from tutor_profile where category = 1 and user_id = " . $exp->getUserId() . "", $connection) or die("Er-1-->" . mysql_error()); $tutors = mysql_fetch_array($tutorsq); $tutor = ''; $tutor = explode("-", $tutors['course_id']); if (in_array($_SESSION["course_id"], $tutor)) { $_queryCourse = mysql_query("select * from tutor_profile where category = 1 and user_id = " . $exp->getUserId() . "", $connection) or die("Er-1-->" . mysql_error()); } if ($_queryCourse && mysql_num_rows($_queryCourse) > 0) { $query = mysql_query("select * from user_score where user_id = " . $exp->getUserId(), $connection) or die(mysql_error()); $score = mysql_fetch_assoc($query); if ($score['score'] != 0) { if ($_points == '' || $_points == '0.00') { $emptyRCquery = mysql_query("select * from user_rate where userid = " . $exp->getUserId() . " and (rate = 0.00 || rate = 0) ", $connection) or die("Error In rate" . mysql_error()); if (mysql_num_rows($emptyRCquery) > 0) { $dv = new Criteria(); $dv->add(UserPeer::ID, $exp->getUserId()); $_thisUser = UserPeer::doSelectOne($dv); $rankUsersFinal[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt()); $newUser[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt()); $i++; } } else { $dv = new Criteria(); $dv->add(UserPeer::ID, $exp->getUserId()); $_thisUser = UserPeer::doSelectOne($dv); $rankUsersFinal[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt()); $newUser[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt()); $i++; } } } } } asort($newUser); arsort($newUser); asort($rankUsersFinal); arsort($rankUsersFinal); $this->rankCheckUsers = $rankUsersFinal; ////if no online expert available redirecting to the board page // // ant-edit get rid of adding notification bots right now $onlineusers = array(); $offlineusers = array(); $newOnlineUser = array(); $newOfflineUser = array(); $j = 0; $k = 0; // $facebookTutors = BotServiceProvider::createFor("http://facebook.rayku.com/tutor")->getContent(); // $onlineTutorsByNotificationBot = BotServiceProvider::createFor("http://notification-bot.rayku.com/tutor")->getContent(); // $Users = json_decode($facebookTutors, true); // $_Users = json_decode($onlineTutorsByNotificationBot, true); //Iterate through every user and check if they are online (either on fb gchat local rayku etc... foreach ($newUser as $new) { $a = new Criteria(); $a->add(UserPeer::ID, $new['userid']); $users_online = UserPeer::doSelectOne($a); $onlinecheck = ''; if ($users_online->isOnline()) { $onlinecheck = "online"; } // // ant-edit get rid of gtalk users for now if (empty($onlinecheck)) { $userGtalk = $users_online->getUserGtalk(); if ($userGtalk) { $onlinecheck = BotServiceProvider::createFor(sfConfig::get('app_rayku_url') . ':' . sfConfig::get('app_g_chat_port') . '/status/' . $userGtalk->getGtalkid())->getContent(); } } // if ((empty($onlinecheck) || ($onlinecheck != "online")) && is_array($Users)) { // $userFb = UserFbPeer::retrieveByUserId($new['userid']); // if ($userFb) { // $fb_username = $userFb->getFbUsername(); // foreach ($Users as $key => $user) { // if ($user['username'] == $fb_username) { // $onlinecheck = 'online'; // break; // } // } // } // } // if ((empty($onlinecheck) || ($onlinecheck != "online")) && is_array($_Users)) { // foreach ($_Users as $key => $_user) { // if ($_user['email'] == $users_online->getEmail()) { // $onlinecheck = 'online'; // break; // } // } // } //if user was online then store ; if ($onlinecheck == "online") { $onlineusers[$j] = $new['userid']; $newOnlineUser[$j] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']); $j++; } elseif ($users_online->isOnline()) { $newOnlineUser[$j] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']); $onlineusers[$j] = $new['userid']; $j++; } else { $newOfflineUser[$k] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']); $offlineusers[$k] = $new['userid']; $k++; } } $this->newOnlineUser = $newOnlineUser; $this->newOfflineUser = $newOfflineUser; $this->_checkOnlineUsers = $onlineusers; if (count($onlineusers) < 1) { $this->redirect('http://' . RaykuCommon::getCurrentHttpDomain() . '/forum/newthread/' . $_SESSION['subject'] . '?exp_online = 1'); } $onoff = isset($_COOKIE['onoff']) ? $_COOKIE['onoff'] : null; if ($onoff == 1) { if (!empty($_COOKIE["school"])) { $cookieSchool = array(); $m = 0; foreach ($newOnlineUser as $new) { $b = new Criteria(); $b->add(UserPeer::ID, $new['userid']); $schoolusers = UserPeer::doSelectOne($b); $mail = explode("@", $schoolusers->getEmail()); $newMail = explode(".", $mail[1]); if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) { $cookieSchool[$m] = $new; $m++; } } $this->expert_cats = $cookieSchool; } else { $this->expert_cats = $newOnlineUser; } } else { if ($onoff == 2) { if (!empty($_COOKIE["school"])) { $cookieSchool = array(); $m = 0; foreach ($newOfflineUser as $new) { $b = new Criteria(); $b->add(UserPeer::ID, $new['userid']); $schoolusers = UserPeer::doSelectOne($b); $mail = explode("@", $schoolusers->getEmail()); $newMail = explode(".", $mail[1]); if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) { $cookieSchool[$m] = $new; $m++; } } $this->expert_cats = $cookieSchool; } else { $this->expert_cats = $newOfflineUser; } } else { if (!empty($_COOKIE["school"])) { $cookieSchool = array(); $m = 0; foreach ($newUser as $new) { $b = new Criteria(); $b->add(UserPeer::ID, $new['userid']); $schoolusers = UserPeer::doSelectOne($b); $mail = explode("@", $schoolusers->getEmail()); $newMail = explode(".", $mail[1]); if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) { $cookieSchool[$m] = $new; $m++; } } $this->expert_cats = $cookieSchool; } else { $this->expert_cats = $newUser; } } } $this->tutorsCount = count($this->expert_cats); $c = new Criteria(); $c->add(CategoryPeer::ID, $this->cat); $this->e = CategoryPeer::doSelectOne($c); }
/** * Gets an array of ExpertCategory objects which contain a foreign key that references this object. * * If this collection has already been initialized with an identical Criteria, it returns the collection. * Otherwise if this Category has previously been saved, it will retrieve * related ExpertCategorys from storage. If this Category is new, it will return * an empty collection or the current collection, the criteria is ignored on a new object. * * @param PropelPDO $con * @param Criteria $criteria * @return array ExpertCategory[] * @throws PropelException */ public function getExpertCategorys($criteria = null, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(CategoryPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collExpertCategorys === null) { if ($this->isNew()) { $this->collExpertCategorys = array(); } else { $criteria->add(ExpertCategoryPeer::CATEGORY_ID, $this->id); ExpertCategoryPeer::addSelectColumns($criteria); $this->collExpertCategorys = ExpertCategoryPeer::doSelect($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(ExpertCategoryPeer::CATEGORY_ID, $this->id); ExpertCategoryPeer::addSelectColumns($criteria); if (!isset($this->lastExpertCategoryCriteria) || !$this->lastExpertCategoryCriteria->equals($criteria)) { $this->collExpertCategorys = ExpertCategoryPeer::doSelect($criteria, $con); } } } $this->lastExpertCategoryCriteria = $criteria; return $this->collExpertCategorys; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(ExpertCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(ExpertCategoryPeer::DATABASE_NAME); $criteria->add(ExpertCategoryPeer::ID, $pks, Criteria::IN); $objs = ExpertCategoryPeer::doSelect($criteria, $con); } return $objs; }