예제 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Notices();
     $model->setScenario('create');
     //int_r($_FILES);exit;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $path = Yii::app()->basePath . '/../uploads';
     if (!is_dir($path)) {
         mkdir($path);
     }
     if (isset($_POST['Notices'])) {
         $model->attributes = $_POST['Notices'];
         $model->user_id = Yii::app()->User->Id;
         $user = User::model()->findByPk(Yii::app()->User->Id);
         $state = State::model()->findByAttributes(array('statecode' => $user->statecode));
         $dist = District::model()->findByAttributes(array('distcode' => $user->distcode));
         $est = Establishments::model()->findByAttributes(array('id' => $user->est_id));
         $model->state = $state->statename;
         $model->district_court_complex = $dist->distname;
         $model->establishment = $est->est_name;
         $model->notice_date = date("Y-m-d H:i:s", time());
         $user = User::model()->findByPk(Yii::app()->User->Id);
         $model->judge_name = $user->judge;
         $court_no = CourtT::model()->findAllByAttributes(array('judge_id' => $user->judge_id));
         $court = '';
         foreach ($court_no as $i) {
             $court = $i['court_no'];
             break;
         }
         $model->court = $court;
         if ($model->validate($_POST['Notices'])) {
             //exit("ASd");
             if (@(!empty($_FILES['Notices']['name']['pdf_file']))) {
                 $model->pdf_file = $_POST['Notices']['pdf_file'];
                 $model->pdf_file = CUploadedFile::getInstance($model, 'pdf_file');
                 //$filename = time() . '_' . str_replace(' ', '_', strtolower($model->pdf_file));
                 if ($_POST['Notices']['notice_type'] == "Advertisment") {
                     $type = 1;
                 } elseif ($_POST['Notices']['notice_type'] == "Sale Notices") {
                     $type = 2;
                 } else {
                     $type = 3;
                 }
                 $filename = $type . "-" . str_replace(' ', '_', $_POST['Notices']['case_type']) . "-" . date("d-m-Y_H:i:s", time()) . ".pdf";
                 $model->pdf_file->saveAs($path . '/' . $filename);
                 $model->pdf_file = $filename;
                 $model->created = date("Y-m-d H:i:s", time());
                 $model->notice_date = date("Y-m-d H:i:s", strtotime($model->notice_date));
                 $model->appear_date = date("Y-m-d H:i:s", strtotime($model->appear_date));
             }
         }
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }