示例#1
0
文件: question.php 项目: rayku/rayku
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());
            }
        }
    }
}
示例#2
0
 /* User Online Check - Start */
 $a = new Criteria();
 $a->add(UserPeer::ID, $_COOKIE['expert_' . $i]);
 $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") {
     $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);
示例#3
0
 public function execute($request)
 {
     RaykuCommon::getDatabaseConnection();
     /* @var $currentUser User */
     $currentUser = $this->getUser()->getRaykuUser();
     $userId = $currentUser->getId();
     $this->userId = $currentUser->getId();
     $time = time();
     $_SESSION["rateDisplay"] = 1;
     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 > 2) {
             $close = 21000;
         } else {
             if ($count == 2) {
                 $close = 31000;
             } else {
                 if ($count == 1) {
                     $close = 61000;
                 }
             }
         }
         $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());
         }
         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 = @$_SESSION['tutcourse'];
     if (empty($this->course_id)) {
         $this->course_id = 1;
     }
     if (empty($this->cat)) {
         $this->cat = 1;
     }
     $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);
     }
     $_points = $currentUser->getPoints();
     $newUser = array();
     $i = 0;
     $eachExpertOnlyOnce = array();
     foreach ($experts as $exp) {
         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() . "") or die("Er-1-->" . mysql_error());
         $tutors = mysql_fetch_array($tutorsq);
         $tutor = '';
         $tutor = explode("-", $tutors['course_id']);
         $coursid = $this->course_id;
         if (in_array($coursid, $tutor)) {
             //echo $coursid;
             $_queryCourse = mysql_query("select * from tutor_profile where category = 1 and user_id = " . $exp->getUserId() . "") or die("Er-1-->" . mysql_error());
             //echo "select * from tutor_profile where category = 1 and user_id = ".$exp->getUserId()."";
         }
         if ($_queryCourse && 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)) {
             $userFb = UserFbPeer::retrieveByUserId($new['userid']);
             if ($userFb) {
                 $fb_username = $userFb->getFbUsername();
                 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);
 }
示例#4
0
 /* User Online Check - Start */
 $a = new Criteria();
 $a->add(UserPeer::ID, $_COOKIE['tutor_' . $i]);
 $user = UserPeer::doSelectOne($a);
 $onlinecheck = '';
 if ($user->isOnline()) {
     $onlinecheck = "online";
 }
 if (empty($onlinecheck)) {
     $userGtalk = $user->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") {
     $userFb = UserFbPeer::retrieveByUserId($_COOKIE['tutor_' . $i]);
     if ($userFb) {
         $fb_username = $userFb->getFbUsername();
         $details = BotServiceProvider::createFor(sfConfig::get('app_facebook_url') . "/tutor")->getContent();
         $fbUsers = json_decode($details, true);
         foreach ($fbUsers as $key => $fbUser) {
             if ($fbUser['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);