public function actionSubscribe()
 {
     /*if(!isset($_SERVER['SERVER_NAME']) || $_SERVER['SERVER_NAME'] != 'msisdn.chacha.vn'){
           $this->redirect('/site/error404');
       }*/
     $userPhone = Yii::app()->user->getState('msisdn');
     $userSub = $this->userSub;
     //WapUserSubscribeModel::model()->findByAttributes(array('user_phone' => $userPhone, 'status' => UserSubscribeModel::ACTIVE));
     $confirm = Yii::app()->request->getParam('confirm', 0);
     $source = Yii::app()->request->getParam('source', 'buzzcity');
     $source = strtoupper($source);
     $result = null;
     $userObj = null;
     if ($confirm == 0) {
         $write = 1;
         if (isset($_SESSION[$source])) {
             // check time giua 2 lan visit co > 15 giay hay ko
             $latest_time = $_SESSION[$source];
             $now = date("Y-m-d H:i:s");
             $diff = strtotime($now) - strtotime($latest_time);
             if (intval($diff) < 15) {
                 $write = 0;
             }
         }
         if ($write == 1) {
             // log to table log_ads_click
             $log = new LogAdsClickModel();
             $ip = $_SERVER["REMOTE_ADDR"];
             $is3G = 0;
             if (Yii::app()->user->getState('is3G')) {
                 $is3G = 1;
             }
             $log->logAdsWap($userPhone, $source, $ip, $is3G);
             // set session value
             $_SESSION[$source] = date("Y-m-d H:i:s");
         }
     }
     $destUrl = Yii::app()->request->getParam('url', Yii::app()->homeUrl);
     //$destUrl = urldecode($destUrl);
     if ($userSub) {
         $this->redirect($destUrl);
     }
     $isPromotion = WapUserSubscribeModel::model()->checkPromotion($userPhone);
     if ($isPromotion) {
         $confirm = 1;
     }
     if ($confirm == 1) {
         try {
             $phone = $userPhone;
             if (!isset($phone) || !Formatter::isVinaphoneNumber($phone)) {
                 $result = new stdClass();
                 $result->errorCode = 401;
                 $result->message = WapUserSubscribeModel::model()->getCustomMetaData('3G_TEXT');
             } else {
                 //anti flood request
                 if (!isset($_SESSION)) {
                     session_start();
                 }
                 //time_nanosleep(0, 500000000);
                 $token = Yii::app()->request->csrfToken;
                 $ssid = session_id();
                 $sql = "INSERT INTO user_phone_subscribe_unduplicate(phone,ssid,token,created_time,status)\n\t\t\t\t\tVALUE('{$userPhone}','{$ssid}','{$token}',NOW(),0)\n\t\t\t\t\t";
                 $connDB = VegaCommonFunctions::getConnectMysql();
                 $res1 = mysql_query($sql);
                 mysql_close($connDB);
                 if ($res1) {
                     $bmUrl = yii::app()->params['bmConfig']['remote_wsdl'];
                     $client = new SoapClient($bmUrl, array('trace' => 1));
                     $params = array('phone' => $userPhone, 'package' => 'CHACHAFUN', 'source' => 'wap', 'promotion' => '', 'bundle' => 0, 'smsId' => null, 'note_event' => $source);
                     $result = $client->__soapCall('userRegister', $params);
                     $timeClear = date('Y-m-d H:i:s', time() - 60 * 5);
                     $sql = "DELETE FROM user_phone_subscribe_unduplicate WHERE created_time<='{$timeClear}'";
                     $res2 = Yii::app()->db->createCommand($sql)->execute();
                 } else {
                     $log = new KLogger("SUBS_DUPLICATE_EXCEPTION", KLogger::INFO);
                     $log->LogInfo("Ex:" . $userPhone, false);
                     $this->redirect($destUrl);
                     exit;
                 }
             }
             if ($result->errorCode == 0 || $result->errorCode == '0') {
                 //$userObj = WapUserSubscribeModel::model()->findByAttributes(array('user_phone' => $userPhone));
                 if ($isPromotion) {
                     Yii::app()->user->setState('DK_MA_MSG', 'Quý khách có 7 ngày vàng trải nghiệm dịch vụ: Nghe, xem, tải MIỄN PHÍ toàn bộ nội dung và miễn cước data (3G/GPRS~30.000đ/ngày).Tặng kèm gói miễn phí tải nhạc chuông và quà tặng âm nhạc. Để từ chối nhận KM Quý khách soạn HUY CHACHA gửi 9234');
                 }
                 $this->redirect($destUrl);
             }
         } catch (Exception $e) {
             $log = new KLogger("SUBS_EXCEPTION", KLogger::INFO);
             $log->LogInfo("Ex:" . $e->getMessage(), false);
             //Yii::log($e->getMessage(), "error", "exeption.BMException");
             $this->redirect($destUrl);
             exit;
         }
     } else {
         $log = new KLogger("SUBS_NOT_PROMOTION", KLogger::INFO);
         $log->LogInfo($userPhone, false);
     }
     $this->renderPartial("subscribe_adv", array('userObj' => $userObj, 'result' => $result, 'confirm' => $confirm, 'source' => strtolower($source), 'isPromotion' => $isPromotion, 'destUrl' => $destUrl));
 }
 /**
  * Log nhan dien thue bao
  * @param string $phone
  * @param string $type
  */
 public static function _logDetectMSISDN($phone, $type, $channel = 'wap', $deviceId = null)
 {
     if (!isset($deviceId)) {
         $deviceId = yii::app()->session['deviceId'];
     }
     // log to file
     $xAddress = isset($_SERVER['HTTP_X_IPADDRESS']) ? $_SERVER['HTTP_X_IPADDRESS'] : '';
     VegaCommonFunctions::logFile('PHONE:' . $phone . ' |-|REMOTE_ADDR:' . $_SERVER['REMOTE_ADDR'] . ' |-| HTTP_X_IPADDRESS:' . $xAddress . ' |-|DEVICE:' . Yii::app()->session['deviceId'], 'detectMsisdn', $type);
     $os = self::$_os;
     // log to DB
     $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
     $userSubscribe = UserSubscribeModel::model()->get($phone);
     //get user_subscribe record by phone
     $packageId = $userSubscribe ? $userSubscribe->package_id : 0;
     $event = $userSubscribe ? $userSubscribe->event : '';
     $referral = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
     $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : "";
     LogDetectMsisdnModel::model()->logDetect($phone, $_SERVER['REMOTE_ADDR'], $deviceId, $channel, 1, $type, $os, $userAgent, $packageId, $event, $referral, $uri);
 }