Example #1
0
 public function init()
 {
     parent::init();
     $this->user = Yii::app()->session['user'];
     $this->_table = 'users';
     $this->db = EduDataBase::getConnection();
     $this->layout = null;
 }
Example #2
0
 public function init()
 {
     parent::init();
     $this->user = Yii::app()->session['advertiser'];
     $this->_table = 'users';
     $this->db = EduDataBase::getConnection();
     $this->layout = null;
     Yii::import('application.models.advertiser.*');
 }
 public function emailUnique()
 {
     $db = EduDataBase::getConnection();
     $query = "SELECT * FROM {{users}} WHERE email = :email";
     $values = array(':email' => $this->email);
     $recored = $db->createCommand($query)->bindValues($values)->queryRow();
     if (!empty($recored)) {
         $this->addError('email', 'Email "' . $this->email . '" đã tồn tại rồi');
     }
 }
Example #4
0
 public function init()
 {
     parent::init();
     //        if ($_SERVER['HTTP_HOST'] == 'techz24.com' || $_SERVER['HTTP_HOST'] == 'www.techz24.com') {
     //            $user = Yii::app()->session['user'];
     //            $ip = ip_address();
     //            if (empty($user) && $ip != '118.71.87.162') {
     //                echo '<meta name="robots" content="noindex, nofollow">';
     //                die('Comming soon...');
     //            }
     //        }
     $this->db = EduDataBase::getConnection();
 }
Example #5
0
 public function ruleUnique()
 {
     $action = Yii::app()->controller->action->id;
     $db = EduDataBase::getConnection();
     $query = "SELECT * FROM {{rule}} WHERE rule = :rule";
     if ($action == 'edit') {
         $query .= " AND id <> " . $_GET['id'];
     }
     $values = array(':rule' => $this->rule);
     $recored = $db->createCommand($query)->bindValues($values)->queryRow();
     if (!empty($recored)) {
         $this->addError('rule', 'Nhóm "' . $this->rule . '" đã tồn tại rồi');
     }
 }
Example #6
0
 private function searchVideo($args)
 {
     //ini_set('memory_limit', '-1');
     $db2 = EduDataBase::getConnection('db2');
     if (isset($args[1])) {
         $query = "SELECT * FROM {{video_search}} WHERE is_run = 0 ORDER BY id " . $args[1] . " LIMIT 1";
     } else {
         $query = "SELECT * FROM {{video_search}} WHERE is_run = 0 LIMIT 1";
     }
     $row = $db2->createCommand($query)->queryRow();
     if (empty($row)) {
         die('Het du lieu roi');
     }
     $query = "SELECT * FROM {{video_source}}";
     $list = $db2->createCommand($query)->queryAll();
     $list_source = array();
     $search_result = array();
     $total_source = 0;
     $count_run = 0;
     echo "Tim kiem video: " . $row['keywords'] . "\n";
     foreach ($list as $item) {
         //`video_search_id`, `source_id`, `html_data`
         $result = $this->findVideo($item, $row);
         if ($result == false) {
             continue;
         }
         $have_data = $result['have_data'];
         unset($result['have_data']);
         yii_insert_row('source_html', $result, 'db2', true);
         if ($have_data == 1) {
             $total_source++;
         }
         $count_run++;
         $search_result[$item['id']] = $have_data;
     }
     //`search_result`, `total_source`, `is_run`
     $update = "UPDATE {{video_search}} SET count_run = :count_run, search_result = :search_result, total_source = :total_source, is_run = :is_run WHERE id = :id";
     $values = array(':search_result' => json_encode($search_result), ':total_source' => $total_source, ':is_run' => 1, ':count_run' => $count_run, ':id' => $row['id']);
     $db2->createCommand($update)->bindValues($values)->execute();
     echo "Done\n\n";
     sleep(1);
     echo "------------------------------------------------\n";
     echo "Chay them lan nua\n";
     echo "------------------------------------------------\n";
     $args[0] = 'search';
     $this->run($args);
 }
 public function init()
 {
     parent::init();
     $this->db = EduDataBase::getConnection();
     $this->user = Yii::app()->session['advertiser'];
     if (empty($this->user)) {
         $query_string = '?dest=' . base64_encode($_SERVER['REQUEST_URI']);
         $redirect = '/advertiser/login/index' . $query_string;
         $this->redirect($redirect);
     }
     //chon ngon ngu cho site
     //        $lang = 'vi';
     //        Yii::app()->sourceLanguage = '00';
     //        Yii::app()->language = $lang;
     Yii::import('application.models.advertiser.*');
     Yii::app()->setSystemViewPath(ROOT_PATH . '/protected/views/system');
 }
Example #8
0
 private function zipLanguageData($lang_id)
 {
     $query = "SELECT * FROM {{languages}} WHERE id = " . $lang_id;
     $db_global = EduDataBase::getConnection('db_global');
     $language = $db_global->createCommand($query)->queryRow();
     if (empty($language)) {
         echo "Khong ton tai ngon ngu voi id = " . $lang_id . "\n";
         die;
     }
     $font_version = $language['font_version'];
     $audio_version = $language['audio_version'];
     //kiem tra neu co file cu thi xoa di
     $zip_filename = 'language_' . $lang_id . '.zip';
     $file_zip = PRIVATE_TMP_PATH . '/' . $zip_filename;
     if (file_exists($file_zip)) {
         @unlink($file_zip);
     }
     $zip = new ZipArchive();
     $zip->open($file_zip, ZipArchive::CREATE);
     //copy game audio
     $game_audio_path = GAME_AUDIO_PATH . '/' . $lang_id . '/' . $audio_version;
     if (is_dir($game_audio_path)) {
         $paths = array();
         $dir = new DirectoryIterator($game_audio_path);
         foreach ($dir as $fileinfo) {
             if (!$fileinfo->isDot() && $fileinfo->isFile()) {
                 $file = $game_audio_path . '/' . $fileinfo->getFilename();
                 $key = str_replace(GAME_AUDIO_PATH . '/', '', $file);
                 $paths[$key] = $file;
             }
         }
         if (!empty($paths)) {
             foreach ($paths as $localname => $filename) {
                 $zip->addFile($filename, 'gameaudio/' . $localname);
             }
         }
         echo "Copy xong game audio\n";
     }
     $fonts_path = FONT_PATH . '/' . $lang_id . '/' . $font_version;
     if (is_dir($fonts_path)) {
         $paths = array();
         $dir = new DirectoryIterator($fonts_path);
         foreach ($dir as $fileinfo) {
             if (!$fileinfo->isDot() && $fileinfo->isFile()) {
                 $file = $fonts_path . '/' . $fileinfo->getFilename();
                 $key = str_replace(FONT_PATH . '/', '', $file);
                 $paths[$key] = $file;
             }
         }
         if (!empty($paths)) {
             foreach ($paths as $localname => $filename) {
                 $zip->addFile($filename, 'fonts/' . $localname);
             }
         }
         echo "Copy xong fonts\n";
     }
     $zip->close();
     echo "Tao file zip: " . $file_zip . " thanh cong\n";
 }
Example #9
0
 public function init()
 {
     parent::init();
     $this->db = EduDataBase::getConnection();
     $this->_controller = Yii::app()->getController();
 }
Example #10
0
 private function PushAndroid()
 {
     $os_type = 2;
     $db = EduDataBase::getConnection('db_global');
     $query = "SELECT * FROM {{push_queue}} WHERE is_push = 0 AND os = " . $os_type;
     $row = $db->createCommand($query)->queryRow();
     if (empty($row)) {
         die("Da het push queue\n");
     }
     $push_queue_id = $row['id'];
     $registrationIds = array($row['device_token']);
     $msg = array('payload' => array('aps' => array('body' => 'Edu push', 'alert' => $row['message']), 'some_extra_key' => '+1'));
     $fields = array('registration_ids' => $registrationIds, 'data' => $msg);
     $appInfo = $this->getAppInfo($row['app_id']);
     $headers = array('Authorization: key=' . $appInfo['api_access_key'], 'Content-Type: application/json');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
     $result = curl_exec($ch);
     curl_close($ch);
     var_dump($result);
     echo "\n";
     $info = json_decode($result, true);
     if ($info['failure'] == 1) {
         $query = "UPDATE {{push}} SET uninstall = 1 WHERE device_token = :device_token";
         $values = array(':device_token' => $row['device_token']);
         $db_device = EduDataBase::getConnection('db_device');
         $db_device->createCommand($query)->bindValues($values)->execute();
     }
     $query = "UPDATE {{push_queue}} SET is_push = 1 WHERE id = " . $push_queue_id;
     $db->createCommand($query)->execute();
     sleep(1);
     $args[0] = 'android';
     $this->run($args);
 }
Example #11
0
function yii_update_row($table, $params, $condition = '1', $db = 'db')
{
    if (empty($table)) {
        throw new Exception('Vui long nhap ten bang');
    }
    if (empty($params)) {
        throw new Exception('Vui long nhap du lieu de thuc thi cau lenh update');
    }
    $fields = array_keys($params);
    $query = "UPDATE {{" . $table . "}} SET ";
    $tags = array();
    foreach ($fields as $field) {
        $tags[] = '`' . $field . '`' . ' = :' . $field;
    }
    $query .= implode(', ', $tags) . " WHERE " . $condition;
    $database = EduDataBase::getConnection($db);
    $values = array();
    foreach ($params as $key => $vl) {
        $values[':' . $key] = trim($vl);
    }
    return $database->createCommand($query)->bindValues($values)->execute();
}
Example #12
0
 public function init()
 {
     parent::init();
     $this->db = EduDataBase::getConnection();
     $this->db_crawler = EduDataBase::getConnection('db_crawler');
 }