function checkquestion() { luklog('checkquestion function call'); $time = time() - 300; mysql_query("delete from user_expert where status = 7 ") or die("Error5--1" . mysql_error()); $check_time = time(); $_expire_msg = mysql_query("select * from user_expire_msg where expire_time <= '" . $check_time . "'") or die("Error_Expire1" . mysql_error()); if (mysql_num_rows($_expire_msg) > 0) { while ($_row_expire_msg = mysql_fetch_assoc($_expire_msg)) { luklog("Jadziem dla: " . print_r($_row_expire_msg, true)); $_send_expire_msg = mysql_query("select * from user_gtalk where userid=" . $_row_expire_msg['userid']) or die("Error11" . mysql_error()); if (mysql_num_rows($_send_expire_msg) > 0) { $getInfo = mysql_fetch_assoc($_send_expire_msg); $_gtalk_email_id = $getInfo['gtalkid']; $_exp_newline = urlencode("\n"); $_exp_message = $_exp_newline; $_exp_message .= "This%20question%20has%20expired."; $_exp_message .= $_exp_newline; $_gtalk_online_check = BotServiceProvider::createFor(sfConfig::get('app_rayku_url') . ':' . sfConfig::get('app_g_chat_port') . '/status/' . $_gtalk_email_id)->getContent(); if ($_gtalk_online_check != "offline") { $_send_msg = BotServiceProvider::createFor(sfConfig::get('app_rayku_url') . ':' . sfConfig::get('app_g_chat_port') . '/msg/' . $_gtalk_email_id . '/' . $_exp_message)->getContent(); } } $userFb = UserFbPeer::retrieveByUserId($_row_expire_msg['userid']); if ($userFb) { $fb_username = $userFb->getFbUsername(); $details = BotServiceProvider::createFor(sfConfig::get('app_facebook_url') . "/tutor")->getContent(); $Users = json_decode($details, true); foreach ($Users as $key => $user) { if ($user['username'] == $fb_username) { //set POST variables $url = sfConfig::get('app_facebook_url') . '/tutor/' . $user['uid'] . '/message'; $fields = array('message' => $_exp_message); //url-ify the data for the POST foreach ($fields as $key => $value) { $fields_string .= $key . '=' . $value . '&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); //execute post $result = curl_exec($ch); //close connection curl_close($ch); $flag = 1; break; } } } mysql_query("delete from user_expire_msg where userid=" . $_row_expire_msg['userid']) or die("Error_Expire2" . mysql_error()); } } $select = mysql_query("select * from gtalkcron where expire_time <= '" . $check_time . "'") or die("Error1" . mysql_error()); if (mysql_num_rows($select) > 0) { while ($rowvalues = mysql_fetch_assoc($select)) { $updateId = $rowvalues['id'] + 1; $checkprevious = mysql_query("select * from user_expert where id=" . $updateId . " and user_id=" . $rowvalues['userid']) or die("Error" . mysql_error()); if (mysql_num_rows($checkprevious) > 0) { mysql_query("update user_expert set exe_order = 1 where id=" . $updateId) or die("Error2" . mysql_error()); } mysql_query("delete from user_expert where id=" . $rowvalues['id']) or die("Error3" . mysql_error()); mysql_query("delete from gtalkcron where id=" . $rowvalues['id']) or die("Error4" . mysql_error()); } } $query = mysql_query("select * from user_expert where exe_order = 1 and time >= '" . $time . "' and cron = 1") or die("Error5" . mysql_error()); if (mysql_num_rows($query) > 0) { while ($row = mysql_fetch_assoc($query)) { $storetime = time(); $expire_time = ''; $category = mysql_query("select * from category where id = " . $row['category_id'] . "") or die("Error6" . mysql_error()); if (mysql_num_rows($category) > 0) { $rowcategory = mysql_fetch_assoc($category); $subject = $rowcategory['name']; } $userdetail = mysql_query("select * from user where id = " . $row['user_id'] . "") or die("Error7" . mysql_error()); if (mysql_num_rows($userdetail) > 0) { $rowuserdetail = mysql_fetch_assoc($userdetail); $email = $rowuserdetail['email']; } $mail = explode("@", $email); $newMail = explode(".", $mail[1]); if ($newMail[0] == "utoronto") { $school = "University of Toronto"; } else { if ($newMail[1] == "ubc") { $school = "UBC"; } } $length = strlen(trim($row['question'])); if ($length <= 100) { $question = $row['question']; } else { $question = substr(trim($row['question']), 0, 100); } $userTutor = mysql_query("select * from user where id = " . $row['checked_id'] . "") or die("Error9" . mysql_error()); if (mysql_num_rows($userTutor) > 0) { $rowuserTutor = mysql_fetch_assoc($userTutor); $name = $rowuserTutor['name']; $tutorEmail = $rowuserTutor['email']; } $queryRPRate = mysql_query("select * from user_rate where userid=" . $row['checked_id'] . " ") or die("Error10" . mysql_error()); if (mysql_num_rows($queryRPRate)) { $rowRPRate = mysql_fetch_assoc($queryRPRate); $raykuCharge = $rowRPRate['rate']; } else { $raykuCharge = '0.16'; } $final_ques = str_replace(" ", "%20", $question); $school = str_replace(" ", "%20", $school); $newline = urlencode("\n"); $message .= $newline; $message = "A%20" . $school . "%20student%20needs%20your%20help:"; $message .= $newline; $message .= $final_ques . "%20%20%20"; $message .= $newline; $message .= "Connect:%20"; $link = sfConfig::get('app_rayku_url') . "/login/answer?id=" . $row['id']; $message .= urlencode($link); $message .= $newline; $message .= "(earns%20you%20\$" . $raykuCharge . "%2Fminute)"; $message .= $newline; $gtalkquery = mysql_query("select * from user_gtalk where userid=" . $row['checked_id']) or die("Error11" . mysql_error()); $onlinecheck = ''; $flag = 1; if (mysql_num_rows($gtalkquery) > 0) { $status = mysql_fetch_assoc($gtalkquery); $gtalkmail = $status['gtalkid']; $onlinecheck = BotServiceProvider::createFor(sfConfig::get('app_rayku_url') . ':' . sfConfig::get('app_g_chat_port') . '/status/' . $gtalkmail)->getContent(); if ($onlinecheck != "offline") { $testcall = BotServiceProvider::createFor(sfConfig::get('app_rayku_url') . ':' . sfConfig::get('app_g_chat_port') . '/msg/' . $gtalkmail . '/' . $message)->getContent(); $flag = 1; } } $userFb = UserFbPeer::retrieveByUserId($row['checked_id']); if ($userFb) { $fb_username = $userFb->getFbUsername(); $details = BotServiceProvider::createFor(sfConfig::get('app_facebook_url') . "/tutor")->getContent(); $Users = json_decode($details, true); foreach ($Users as $key => $user) { if ($user['username'] == $fb_username) { //set POST variables $url = sfConfig::get('app_facebook_url') . '/tutor/' . $user['uid'] . '/message'; $fields = array('message' => $message); //url-ify the data for the POST foreach ($fields as $key => $value) { $fields_string .= $key . '=' . $value . '&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); //execute post $result = curl_exec($ch); //close connection curl_close($ch); $flag = 1; break; } } } $onlineUsers = BotServiceProvider::createFor(sfConfig::get('app_notification_bot_url') . "/tutor")->getContent(); $_Users = json_decode($onlineUsers, true); foreach ($_Users as $key => $_user) { if ($_user['email'] == $tutorEmail) { $url = sfConfig::get('app_bots_url') . ':' . sfConfig::get('app_mac_server_port') . '/tutor/' . $tutorEmail . '/notification'; $fields = array('link' => urlencode($link), 'body' => urlencode($question), 'grade' => urlencode("student"), 'timeLeft' => '1'); //url-ify the data for the POST foreach ($fields as $key => $value) { $fields_string .= $key . '=' . $value . '&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); //execute post $result = curl_exec($ch); //close connection curl_close($ch); $flag = 1; break; } } if ($flag == 1) { $expire_time = $row['close'] - 11; $expire_time = $expire_time / 1000 + time(); mysql_query("insert into gtalkcron(id,userid,expire_time) values(" . $row['id'] . "," . $row['user_id'] . ", '" . $expire_time . "')") or die("Error12" . mysql_error()); mysql_query("insert into user_expire_msg(userid,expire_time) values(" . $row['checked_id'] . ", '" . $expire_time . "')") or die("Error13" . mysql_error()); mysql_query("update user_expert set cron = 2 where id =" . $row['id']) or die("Error5" . mysql_error()); } } } }
/** * 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); }
public function executeGtalkupdate($request) { $connection = RaykuCommon::getDatabaseConnection(); /* @var $user User */ $user = $this->getUser()->getRaykuUser(); $userGtalk = $user->getUserGtalk(); if (!$userGtalk) { $userGtalk = new UserGtalk(); $userGtalk->setUser($user); } $email = $request->getParameter('gtalkname'); $checkemail = explode("@", $email); if (count($checkemail) == 1) { $email .= '@gmail.com'; } $test = BotServiceProvider::createFor(sfConfig::get('app_rayku_url') . ':' . sfConfig::get('app_g_chat_port') . '/add/' . $email)->getContent(); if ($test) { $_SESSION['adduser'] = 1; } else { $_SESSION['adduser'] = 2; $this->redirect('/dashboard/gtalk'); } $userGtalk->setGtalkid($email); $userGtalk->save(); $this->redirect('/dashboard/gtalk'); }
if (empty($onlinecheck) || $onlinecheck != "online") { $fbUser = UserFbPeer::retrieveByUserId($_COOKIE['expert_' . $i]); if ($fbUser) { $fb_username = $fbUser->getFbUsername(); $details = BotServiceProvider::createFor(sfConfig::get('app_facebook_url') . "/tutor")->getContent(); $Users = json_decode($details, true); foreach ($Users as $key => $user) { if ($user['username'] == $fb_username) { $onlinecheck = 'online'; break; } } } } if (empty($onlinecheck) || $onlinecheck != "online") { $onlineUsers = BotServiceProvider::createFor(sfConfig::get('app_notification_bot_url') . "/tutor")->getContent(); $_Users = json_decode($onlineUsers, true); foreach ($_Users as $key => $_user) { if ($_user['email'] == $users_online->getEmail()) { $onlinecheck = 'online'; break; } } } /* User Online Check - End */ if ($onlinecheck == "online") { ?> <!--list item--> <li class="clearfix"> <div class="tutor-number">
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); }
foreach ($_Users as $key => $_user) { if ($_user['email'] == $expert->getEmail()) { $onlinecheck = 'online'; break; } } } if ($onlinecheck != "online") { $onlinecheck = 'offline'; } // Facebook // $facebookchat = null; $userFb = $expert->getUserFb(); if ($userFb) { $fb_username = $userFb->getFbUsername(); $details = BotServiceProvider::createFor(sfConfig::get('app_facebook_url') . "/tutor")->getContent(); $Users = json_decode($details, true); foreach ($Users as $key => $user) { if ($user['username'] == $fb_username) { $onlinecheck = "online"; $facebookchat = "Facebook Chat"; break; } } } $_Users = json_decode($onlineTutorsByNotificationBot, true); $desktopapplication = null; if (is_array(@$_Users)) { foreach ($_Users as $key => $_user) { if ($_user['email'] == $expert->getEmail()) { $onlinecheck = 'online';
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); }