コード例 #1
0
ファイル: List.php プロジェクト: thezawad/vakuum
 public function setOrder($order_by, $order)
 {
     $this->plist = NULL;
     if ($order_by == 'ac') {
         if ($order != 'asc') {
             $order = 'desc';
         }
         $key = 'user_list_' . $order_by . '_' . $order . '_' . $this->getCurrentPage();
         $cache = MDL_Cache::getInstance();
         if (!isset($cache->{$key})) {
             $sql = 'select `user_id` from ' . DB_TABLE_USER;
             $db = BFL_Database::getInstance();
             $stmt = $db->factory($sql);
             $stmt->execute();
             $user_records = array();
             while ($user = $stmt->fetch()) {
                 $user_records[] = new MDL_User_Record(new MDL_User($user['user_id']));
             }
             $this->tmp_order = $order;
             usort($user_records, array($this, 'cmpByAccepted'));
             unset($this->tmp_order);
             $users = array();
             foreach ($user_records as $user_record) {
                 $users[] = $user_record->getUser();
             }
             $cache->{$key} = $users;
         }
         $users = $cache->{$key};
         $this->plist = $this->separatePage($users);
     }
 }
コード例 #2
0
ファイル: BFL_Database.php プロジェクト: thezawad/vakuum
 /**
  * getInstance
  * @return BFL_Database
  */
 public static function getInstance()
 {
     if (NULL === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
コード例 #3
0
ファイル: Edit.php プロジェクト: thezawad/vakuum
 public static function forceAvailable($judger_id)
 {
     $meta = array('`judger_available` = 1 ');
     $db = BFL_Database::getInstance();
     $stmt = $db->update(DB_TABLE_JUDGER, $meta, 'where `judger_id`=:judger_id');
     $stmt->bindParam(':judger_id', $judger_id);
     $stmt->execute();
 }
コード例 #4
0
ファイル: Verify.php プロジェクト: thezawad/vakuum
 public static function checkUserName($user_name)
 {
     $db = BFL_Database::getInstance();
     $stmt = $db->factory('select count(*) as `exist` from ' . DB_TABLE_USER . ' where `user_name`=:user_name');
     $stmt->bindParam(':user_name', $user_name);
     $stmt->execute();
     $rs = $stmt->fetch();
     return $rs['exist'] == 0;
 }
コード例 #5
0
ファイル: Edit.php プロジェクト: thezawad/vakuum
 public static function delete($record_id)
 {
     $db = BFL_Database::getInstance();
     $stmt = $db->delete(DB_TABLE_RECORD, 'where `record_id`=:record_id');
     $stmt->bindParam(':record_id', $record_id);
     $stmt->execute();
     $stmt = $db->delete(DB_TABLE_RECORDMETA, 'where `rmeta_record_id`=:record_id');
     $stmt->bindParam(':record_id', $record_id);
     $stmt->execute();
 }
コード例 #6
0
ファイル: Show.php プロジェクト: thezawad/vakuum
 /**
  * getProblemName
  * @param int $prob_id
  * @return array
  */
 public static function getProblemName($prob_id)
 {
     $db = BFL_Database::getInstance();
     $stmt = $db->factory('select `prob_name`,`prob_title` from ' . DB_TABLE_PROB . ' WHERE `prob_id` = :prob_id');
     $stmt->bindParam(':prob_id', $prob_id);
     $stmt->execute();
     $rs = $stmt->fetch();
     if (empty($rs)) {
         throw new MDL_Exception_Problem(MDL_Exception_Problem::NOTFOUND);
     }
     return $rs;
 }
コード例 #7
0
ファイル: Set.php プロジェクト: thezawad/vakuum
    /**
     * @return MDL_Judger
     */
    public static function getAvailableJudger()
    {
        $db = BFL_Database::getInstance();
        $stmt = $db->factory('select * from ' . DB_TABLE_JUDGER . ' where `judger_enabled` = 1
				and `judger_available` = 1 order by judger_priority asc');
        $stmt->execute();
        $judger = $stmt->fetch();
        if (empty($judger)) {
            return NULL;
        }
        return new MDL_Judger($judger['judger_id']);
    }
コード例 #8
0
ファイル: Detail.php プロジェクト: thezawad/vakuum
 public static function getUserName($user_id)
 {
     $db = BFL_Database::getInstance();
     $stmt = $db->factory('select `user_name`,`user_nickname` from ' . DB_TABLE_USER . ' WHERE `user_id` = :user_id');
     $stmt->bindParam(':user_id', $user_id);
     $stmt->execute();
     $rs = $stmt->fetch();
     if (empty($rs)) {
         throw new MDL_Exception_User(MDL_Exception_User::INVALID_USER_ID);
     }
     return $rs;
 }
コード例 #9
0
ファイル: Data.php プロジェクト: thezawad/vakuum
 /**
  * getNextProblemID
  * @return int
  */
 public static function getNextProblemID()
 {
     $db = BFL_Database::getInstance();
     $stmt = $db->factory('select MAX(`prob_id`) as maxid from ' . DB_TABLE_PROB);
     $stmt->execute();
     $rs = $stmt->fetch();
     if (empty($rs)) {
         $prob_id = 1001;
     } else {
         $prob_id = $rs['maxid'] + 1;
     }
     return $prob_id;
 }
コード例 #10
0
ファイル: Edit.php プロジェクト: thezawad/vakuum
 /**
  * remove
  * @param int $prob_id
  * @return void
  */
 public static function remove($prob_id)
 {
     $db = BFL_Database::getInstance();
     $stmt = $db->delete(DB_TABLE_PROB, 'where `prob_id`=:prob_id');
     $stmt->bindParam(':prob_id', $prob_id);
     $stmt->execute();
     $stmt = $db->delete(DB_TABLE_PROBMETA, 'where `pmeta_prob_id`=:prob_id');
     $stmt->bindParam(':prob_id', $prob_id);
     $stmt->execute();
     $records = MDL_Problem_List::getRecords($prob_id);
     foreach ($records as $record) {
         MDL_Record_Edit::delete($record['record_id']);
     }
 }
コード例 #11
0
ファイル: MDL_Record.php プロジェクト: thezawad/vakuum
 protected function initializeRecord()
 {
     $db = BFL_Database::getInstance();
     $stmt = $db->factory('select * from ' . DB_TABLE_RECORD . ' where `record_id`=:record_id');
     $stmt->bindValue(':record_id', $this->getID());
     $stmt->execute();
     $record = $stmt->fetch();
     if (empty($record)) {
         throw new MDL_Exception_Record(MDL_Exception_Record::INVALID_RECORD_ID);
     }
     $this->problem = new MDL_Problem($record['record_prob_id']);
     $this->user = new MDL_User($record['record_user_id']);
     $this->judger = new MDL_Judger($record['record_judger_id']);
 }
コード例 #12
0
ファイル: MDL_User.php プロジェクト: thezawad/vakuum
 protected function getNamesByID()
 {
     $db = BFL_Database::getInstance();
     $stmt = $db->factory('select * from ' . DB_TABLE_USER . ' WHERE `user_id` = :user_id');
     $stmt->bindValue(':user_id', $this->getID());
     $stmt->execute();
     $rs = $stmt->fetch();
     if (empty($rs)) {
         throw new MDL_Exception_User(MDL_Exception_User::INVALID_USER_ID);
     }
     $this->user_name = $rs['user_name'];
     $this->user_nickname = $rs['user_nickname'];
     $this->user_password = $rs['user_password'];
 }
コード例 #13
0
ファイル: MDL_Contest.php プロジェクト: thezawad/vakuum
 public function getContestUsers()
 {
     if ($this->contest_users == NULL) {
         $db = BFL_Database::getInstance();
         $stmt = $db->factory('select cmeta_user_id from ' . DB_TABLE_CONTESTMETA . 'where `cmeta_contest_id`=:contest_id and `cmeta_key`="sign_up_time" ');
         $stmt->bindValue(':contest_id', $this->contest_id);
         $stmt->execute();
         $this->contest_users = array();
         while ($user_item = $stmt->fetch()) {
             $user_id = $user_item['cmeta_user_id'];
             $this->contest_users[] = new MDL_Contest_User($this, new MDL_User($user_id));
         }
     }
     return $this->contest_users;
 }
コード例 #14
0
ファイル: MDL_List.php プロジェクト: thezawad/vakuum
 protected function updateList()
 {
     $sql = $this->sql_prefix;
     $stmt = BFL_Database::getInstance()->factory($sql);
     $stmt->execute();
     $item_count = $stmt->rowCount();
     $this->item_count = $item_count;
     $current_page = $this->getCurrentPage();
     if ($current_page > $this->getPageCount()) {
         throw new MDL_Exception_List(MDL_Exception_List::INVALID_PAGE);
     }
     $page_size = $this->getPageSize();
     $offset = $page_size * ($current_page - 1);
     //Fetch list with LIMIT
     $sql .= " LIMIT {$offset},{$page_size}";
     $stmt = BFL_Database::getInstance()->factory($sql);
     $stmt->execute();
     $this->list = $stmt->fetchAll();
 }
コード例 #15
0
ファイル: Auth.php プロジェクト: thezawad/vakuum
 /**
  * Do user authentication and set Session
  *
  * @return boolean whether succeeded to login
  */
 public static function login($user_info)
 {
     //Compute the hash code of the password submited by user
     $user_password_hash = self::passwordEncrypt($user_info['user_password']);
     //Do datebase query to get the hash code of the password
     $db = BFL_Database::getInstance();
     $stmt = $db->factory('select `user_id`,`user_password` from ' . DB_TABLE_USER . ' WHERE `user_name` = :user_name');
     $stmt->bindParam(':user_name', $user_info['user_name']);
     $stmt->execute();
     $rs = $stmt->fetch();
     if (empty($rs)) {
         throw new MDL_Exception_User_Passport(MDL_Exception_User_Passport::INVALID_USER_NAME);
     }
     if ($rs['user_password'] != $user_password_hash) {
         throw new MDL_Exception_User_Passport(MDL_Exception_User_Passport::INVALID_USER_PASSWORD);
     }
     //Set user session
     MDL_ACL::getInstance()->setUser(new MDL_User($rs['user_id']));
 }
コード例 #16
0
ファイル: Process.php プロジェクト: thezawad/vakuum
 public static function getTask()
 {
     //find records whose record_judger_id = 0
     $db = BFL_Database::getInstance();
     $stmt = $db->factory('select `record_id`,`record_prob_id` from ' . DB_TABLE_RECORD . ' where `record_judger_id` = 0 order by `record_id` asc');
     $stmt->execute();
     $task = $stmt->fetch();
     if (!$task) {
         return array();
     }
     $record_meta = new MDL_Record_Meta($task['record_id']);
     $task['language'] = $record_meta->getVar('lang');
     $task['source'] = $record_meta->getVar('source');
     $submit_time = $record_meta->getVar('submit_time');
     $task['task_name'] = 'vkm_' . $task['record_id'];
     $prob_names = MDL_Problem_Show::getProblemName($task['record_prob_id']);
     $task['prob_name'] = $prob_names['prob_name'];
     unset($task['record_prob_id']);
     return $task;
 }
コード例 #17
0
ファイル: Record.php プロジェクト: thezawad/vakuum
 public function getRecords()
 {
     if ($this->records === NULL) {
         $user_id = $this->getUser()->getID();
         $cache_key = 'user_records_' . $user_id;
         $cache = MDL_Cache::getInstance();
         if (!isset($cache->{$cache_key})) {
             $db = BFL_Database::getInstance();
             $stmt = $db->factory('select `record_id` from ' . DB_TABLE_RECORD . ' where `record_user_id`=:user_id');
             $stmt->bindValue(':user_id', $user_id);
             $stmt->execute();
             $records = array();
             while ($rs = $stmt->fetch()) {
                 $records[] = new MDL_Record($rs['record_id'], MDL_Record::GET_ALL);
             }
             $cache->{$cache_key} = $records;
         }
         $records = $cache->{$cache_key};
         $this->records = $records;
     }
     return $this->records;
 }
コード例 #18
0
ファイル: MDL_GlobalControl.php プロジェクト: thezawad/vakuum
 /**
  *
  * @param Exception $exception
  */
 public static function exceptionHandler($exception)
 {
     //撤銷數據庫改動
     $db = BFL_Database::getInstance();
     $db->rollback();
     if ($exception instanceof MDL_Exception) {
         $desc = BFL_Serializer::transmitEncode($exception->getDesc());
         MDL_Locator::getInstance()->redirect(self::$error_page, NULL, '?' . $desc);
     } else {
         if (DEBUG) {
             echo $exception->getMessage();
             $error_massage = $exception->getTraceAsString();
         } else {
             if ($exception instanceof PDOException) {
                 $error_massage = "DB Error";
             } else {
                 $error_massage = "Vakuum Error";
             }
         }
         die($error_massage);
     }
 }
コード例 #19
0
ファイル: Abstract.php プロジェクト: thezawad/vakuum
 protected function writeVar($key, $value, $action)
 {
     $db = BFL_Database::getInstance();
     switch ($action) {
         case self::ADD:
             $meta = array($this->key_name => ':key', $this->value_name => ':value');
             $meta = array_merge($meta, $this->idmeta);
             $stmt = $db->insert($this->table_name, $meta);
             $stmt->bindParam(':key', $key);
             $stmt->bindParam(':value', $value);
             break;
         case self::MODIFY:
             $meta = array("`{$this->value_name}` = :value");
             $condition = "WHERE `{$this->key_name}`=:key and {$this->condition}";
             $stmt = $db->update($this->table_name, $meta, $condition);
             $stmt->bindParam(':key', $key);
             $stmt->bindParam(':value', $value);
             break;
         case self::REMOVE:
             $stmt = $db->delete($this->table_name, "where `{$this->key_name}`=:key and {$this->condition}");
             $stmt->bindParam(':key', $key);
             break;
         default:
             throw new MDL_Exception_Meta(MDL_Exception_Meta::INVALID_WRITE_ACTION);
     }
     $stmt->execute();
 }
コード例 #20
0
ファイル: MDL_Problem.php プロジェクト: thezawad/vakuum
 public function getRecords()
 {
     $db = BFL_Database::getInstance();
     $stmt = $db->factory('select `record_id` from ' . DB_TABLE_RECORD . ' where `record_prob_id`=:prob_id');
     $stmt->bindValue(':prob_id', $this->getID());
     $stmt->execute();
     $records = array();
     while ($rs = $stmt->fetch()) {
         $records[] = new MDL_Record($rs['record_id']);
     }
     return $records;
 }
コード例 #21
0
ファイル: Edit.php プロジェクト: thezawad/vakuum
 public static function remove($user_id)
 {
     $db = BFL_Database::getInstance();
     $stmt = $db->delete(DB_TABLE_USER, 'where `user_id`=:user_id');
     $stmt->bindParam(':user_id', $user_id);
     $stmt->execute();
     $stmt = $db->delete(DB_TABLE_USERMETA, 'where `umeta_user_id`=:user_id');
     $stmt->bindParam(':user_id', $user_id);
     $stmt->execute();
     $stmt = $db->factory('select `record_id` from ' . DB_TABLE_RECORD . ' where `record_user_id`=:user_id');
     $stmt->bindParam(':user_id', $user_id);
     $stmt->execute();
     $records = $stmt->fetchAll();
     $stmt = NULL;
     foreach ($records as $record) {
         MDL_Record_Edit::delete($record['record_id']);
     }
 }
コード例 #22
0
ファイル: bootstrap.php プロジェクト: thezawad/vakuum
<?php

require_once 'library/global.php';
require_once 'library/BFL/BFL_Loader.php';
//初始化自動加載器
BFL_Loader::setBFLPath('./library/BFL/');
BFL_Loader::setControllerPath('./library/application/controller/');
BFL_Loader::setModelPath('./library/application/model/');
//初始化計時器
BFL_Timer::initialize();
//設置運行時全局變量
BFL_Register::setVar('password_encode_word', PWD_ENCWORD);
BFL_Register::setVar('db_info', getDBInfo());
//初始化數據庫事務處理
$db = BFL_Database::getInstance();
$db->beginTransaction();
//初始化參數表
$config = MDL_Config::getInstance();
//設置全局異常捕捉函數
set_exception_handler(array('MDL_GlobalControl', 'exceptionHandler'));
//設置退出回調函數
register_shutdown_function(array('MDL_GlobalControl', 'shutdownHandler'));
//檢查地址綁定
$bind_address = $config->getVar('site_address');
if ($bind_address != '' && $bind_address != BFL_General::getServerAddress()) {
    BFL_Controller::redirect($bind_address);
}
//初始化用戶會話
MDL_ACL::getInstance()->initialize(SESSION_PREFIX, 'guest');
MDL_User_Auth::getLoginedUserInformation();
//加載插件
コード例 #23
0
ファイル: MDL_Judger.php プロジェクト: thezawad/vakuum
 private function turn($judger_available)
 {
     $db = BFL_Database::getInstance();
     $meta = array('`judger_available` = :judger_available');
     if ($judger_available == 0) {
         $meta[] = '`judger_count` = `judger_count` + 1';
     }
     $stmt = $db->update(DB_TABLE_JUDGER, $meta, 'where `judger_id`=:judger_id');
     $stmt->bindValue(':judger_available', $judger_available);
     $stmt->bindValue(':judger_id', $this->getID());
     $stmt->execute();
 }
コード例 #24
0
ファイル: Record.php プロジェクト: thezawad/vakuum
 public static function resetRecord($record_id)
 {
     $db = BFL_Database::getInstance();
     $stmt = $db->update(DB_TABLE_RECORD, '`record_judger_id` = 0', 'where `record_id`=:record_id');
     $stmt->bindParam(':record_id', $record_id);
     $stmt->execute();
     $record_meta = new MDL_Record_Meta($record_id);
     $meta = array('status' => self::STATUS_WAITING, 'result' => '', 'memory' => '0', 'time' => '0', 'score' => 0.0);
     $record_meta->setVars($meta);
 }
コード例 #25
0
ファイル: Abstract.php プロジェクト: thezawad/vakuum
 protected function getDatabaseQueryCount()
 {
     return BFL_Database::getInstance()->getQueryCount();
 }