public function actionImportTrainee() { header('Content-Type: text/html; charset=utf-8'); $model = new WUserTrainee(); require_once Yii::app()->basePath . '/components/reader.php'; //require_once Yii::app()->basePath . '/components/SpreadsheetReader_XLSX.php'; date_default_timezone_set('Asia/Saigon'); //var_dump($Filepath); die; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['ok'])) { $data = new Spreadsheet_Excel_Reader(); $data->setOutputEncoding('UTF-8'); $filename = $_FILES["traineeexcel"]["tmp_name"]; //var_dump($filename);exit; if ($_FILES["traineeexcel"]["size"] > 0) { $data->read($filename); //var_dump($data);exit(); for ($x = 3; $x <= count($data->sheets[0]["cells"]); $x++) { $mahocvien = mysql_real_escape_string($data->sheets[0]["cells"][$x][2]); $hovaten = mysql_real_escape_string($data->sheets[0]["cells"][$x][3]); $gioitinh = mysql_real_escape_string($data->sheets[0]["cells"][$x][4]); //echo $question_name;exit(); $birthday = mysql_real_escape_string($data->sheets[0]["cells"][$x][5]); $cmt = mysql_real_escape_string($data->sheets[0]["cells"][$x][6]); //echo $link_group;exit(); $phone = mysql_real_escape_string($data->sheets[0]["cells"][$x][7]); $email = mysql_real_escape_string($data->sheets[0]["cells"][$x][8]); $tencty = mysql_real_escape_string($data->sheets[0]["cells"][$x][9]); $supervisor = mysql_real_escape_string($data->sheets[0]["cells"][$x][10]); $start_datework = mysql_real_escape_string($data->sheets[0]["cells"][$x][11]); $course_intro = mysql_real_escape_string($data->sheets[0]["cells"][$x][12]); $chucvu = mysql_real_escape_string($data->sheets[0]["cells"][$x][13]); $level = mysql_real_escape_string($data->sheets[0]["cells"][$x][14]); $channel_job = mysql_real_escape_string($data->sheets[0]["cells"][$x][15]); $area = mysql_real_escape_string($data->sheets[0]["cells"][$x][16]); $system = mysql_real_escape_string($data->sheets[0]["cells"][$x][17]); $supermarket = mysql_real_escape_string($data->sheets[0]["cells"][$x][18]); $category = mysql_real_escape_string($data->sheets[0]["cells"][$x][19]); $password = CFunction::encrypt('123456', Yii::app()->params->hashkey); $status = 1; $user_group_id = 2; $created_date = time(); $model->username = $mahocvien; $model->password = $password; $model->fullname = $hovaten; $model->sex = $gioitinh; $model->date_birth = date('Y-m-d H:i:s', strtotime($birthday)); $model->cmt = $cmt; $model->email = $email; $model->user_group_id = $user_group_id; $model->company_code = $tencty; $model->supervisor_code = $supervisor; $model->created_date = $created_date; $model->time_startwork = date('Y-m-d H:i:s', strtotime($start_datework)); $model->course_induction_training = $course_intro; $model->position = $chucvu; $model->level = $level; $model->channel_work = $channel_job; $model->region = $area; $model->system = $system; $model->supermarket = $supermarket; $model->category_job = $category; $model->status = $status; $model->save(); } Yii::app()->user->setFlash('success', Yii::t('web/home', 'Import success')); $count = count($data->sheets[0]["cells"]); WHistoryLog::insertHistoryLog('import trainee', 'Trainee', 'Total Trainee:' . $count); $this->redirect(array('wUser/AllTrainee')); } else { Yii::app()->user->setFlash('unsuccess', Yii::t('web/home', 'Please select file have xls extension.')); $this->redirect(array('wUser/ImportTrainee')); } } $this->render('_import', array('model' => $model)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return WHistoryLog the loaded model * @throws CHttpException */ public function loadModel($id) { $model = WHistoryLog::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionHistoryImport() { $listhistory = WHistoryLog::getHistoryLog(); $this->render('historylog', array('list' => $listhistory)); }
public static function insertHistoryLog($action, $component, $event_name) { $model = new WHistoryLog(); $model->user_id = Yii::app()->user->id; $model->action = $action; $model->log_time = time(); $model->group_id = Yii::app()->session['group_id']; $model->ip = $_SERVER['REMOTE_ADDR']; $model->component = $component; $model->event_name = $event_name; if ($model->save()) { return true; } else { return false; } }