public function actionUpload()
 {
     parent::actionUpload();
     Yii::import("ext.EAjaxUpload.qqFileUploader");
     $folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
     // folder for uploaded files
     $allowedExtensions = array("csv");
     $sizeLimit = (int) Yii::app()->params['sizeLimit'];
     // maximum file size in bytes
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
     $result = $uploader->handleUpload($folder, true);
     $row = 0;
     if (($handle = fopen($folder . $uploader->file->getName(), "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
             if ($row > 0) {
                 $model = Absrule::model()->findByPk((int) $data[0]);
                 if ($model === null) {
                     $model = new Absrule();
                 }
                 $model->absruleid = (int) $data[0];
                 $model->absscheduleid = (int) $data[1];
                 $model->difftimein = $data[2];
                 $model->difftimeout = $data[3];
                 $model->absstatusid = (int) $data[4];
                 $model->recordstatus = 1;
                 try {
                     if (!$model->save()) {
                         $errormessage = $model->getErrors();
                         if (Yii::app()->request->isAjaxRequest) {
                             echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
                         }
                     }
                 } catch (Exception $e) {
                     $errormessage = $e->getMessage();
                     if (Yii::app()->request->isAjaxRequest) {
                         echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
                     }
                 }
             }
             $row++;
         }
         fclose($handle);
     }
     $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     echo $result;
 }
 /**
  * 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 the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Absrule::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }