public function actionUpload()
 {
     parent::actionUpload();
     $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 = Occupation::model()->findByPk((int) $data[0]);
                 if ($model === null) {
                     $model = new Occupation();
                 }
                 $model->occupationid = (int) $data[0];
                 $model->occupationname = $data[1];
                 $model->recordstatus = (int) $data[2];
                 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;
 }
 public function actionCreate_occ()
 {
     $model = new Occupation();
     if (isset($_POST['Occupation'])) {
         $cat = Occupation::model()->countByAttributes(array('cat_id' => $_POST['Occupation']['cat_id'], 'name' => $_POST['Occupation']['name']));
         if ($cat <= 0) {
             $templ = Occupation::model()->findByAttributes(array('cat_id' => $_POST['Occupation']['cat_id']));
             $model->name = $_POST['Occupation']['name'];
             $model->cat_id = $_POST['Occupation']['cat_id'];
             $model->templ = $templ->templ;
             if ($model->save()) {
                 Yii::app()->user->setFlash('create_occ', '1');
                 //$this->redirect(array('/register/step3/uid/'.$_POST['uid'],'add'=>1));
                 $this->actionAdd_occ($model->id, $_POST['uid']);
             } else {
                 print_r($model->getErrors());
             }
         } else {
             Yii::app()->user->setFlash('add_occ', '1');
             //$this->redirect(array('/register/step3/uid/'.$_POST['uid']));
             $this->actionAdd_occ($cat->id, $_POST['uid']);
         }
     }
 }