/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new PhoneModel(); $message = ""; $errorList = array(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['source_name'], $_POST['group_id'])) { $fileName = _APP_PATH_ . DS . "data" . DS . "tmp" . DS . $_POST['source_name']; $group_id = $_POST['group_id']; //$fileName = "D:\\chacha_cloud\\src\\trunk\chacha\data\\tmp\\20120713170547_phone_list.xls"; try { require_once 'excel_reader2.php'; $data = new Spreadsheet_Excel_Reader($fileName, true, "UTF-8"); // khoi tao doi tuong doc file excel $rowsnum = $data->rowcount($sheet_index = 0); // lay so hang cua sheet $colsnum = $data->colcount($sheet_index = 0); // lay so cot cua sheet for ($i = 2; $i <= $rowsnum; $i++) { // doc tu hang so 2 vi hang 1 la tieu de roi! $phoneNum = $data->val($i, 1); // xuat cot so 1 va cot so 2 tren cung 1 hang // check so dien thoai xem co dung cua Vinaphone ko try { $phoneNum = Formatter::formatPhone($phoneNum); if (Formatter::isVinaphoneNumber($phoneNum)) { $model->phone = "{$phoneNum}"; $model->group_id = $group_id; $model->status = 0; $model->created_time = date("Y-m-d H:i:s"); var_dump($model->phone); try { if ($model->save()) { $message = yii::t('SpamModule', 'Upload thành công'); } else { print_r($model->getErrors()); exit; } } catch (Exception $exc) { echo $exc->getTrace(); } } else { //echo so dien thoai ko dung $errorList[] = $phoneNum; } } catch (Exception $exc) { echo $exc->getMessage(); } } } catch (Exception $exc) { echo $exc->getMessage(); } } $uploadModel = new XUploadForm(); $tmpArr = GroupModel::model()->findAll(); $smsGroup = array(); foreach ($tmpArr as $smsG) { $smsGroup[$smsG->id] = $smsG->name; } $this->render('create', array('model' => $model, 'uploadModel' => $uploadModel, 'message' => $message, 'smsGroup' => $smsGroup, 'errorList' => $errorList)); }