Esempio n. 1
0
 /**
  * This is the default 'view' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionUpload()
 {
     throw new CHttpException(404, "CSV Upload is currently disabled");
     $CsvFile = new CsvFile();
     $dataLength = null;
     $Results = null;
     $Uploads = null;
     if (isset($_POST['CsvFile'])) {
         $CsvFile->organisation_id = $_POST['CsvFile']['organisation_id'];
         $CsvFile->data = CUploadedFile::getInstance($CsvFile, 'data');
         $subPath = 'original/to-process';
         $folderPath = Yii::app()->basePath . '/../../protected-file-uploads/' . $subPath . '/';
         if (!is_writable($folderPath)) {
             throw new CHttpException(500, 'Folder "' . $folderPath . '" needs to be made writable (0755).');
         }
         if ($CsvFile->save()) {
             $filename = $folderPath . $CsvFile->uuid . ".csv";
             $CsvFile->data->saveAs($filename);
             Yii::app()->user->setFlash('success', 'Thanks, your CSV has been successfully uploaded and we will process it shortly.');
         }
     }
     $Upload = null;
     $Organisation = null;
     if (isset(Yii::app()->user->getUser()->organisation->id)) {
         //if there is an organisation, get previous uploads
         $Uploads = CsvFile::model()->findAll(array('condition' => 'organisation_id = :organisation_id', 'params' => array(':organisation_id' => Yii::app()->user->getUser()->organisation->id)));
         $Organisation = Yii::app()->user->getUser()->organisation;
     }
     $this->pageTitle = 'Data | ' . Yii::app()->name;
     $this->breadcrumbs = array('Data');
     $this->render('upload', array('Success' => $Saved, 'CsvFile' => $CsvFile, 'Results' => $Results, 'Organisation' => $Organisation, 'Uploads' => $Uploads));
 }