public function actionUploadImage($id)
 {
     $page = $this->loadModel($id);
     $attributes = array('name' => "", 'fileType' => AttachedFile::FILE_TYPE_SIMPLE_ATTACH, 'attachType' => AttachedFile::ATTACH_TYPE_FILE);
     $file = AttachedFileHelper::uploadFile(new AttachedFile(), $attributes, get_class($page), $page->id, CUploadedFile::getInstanceByName("file"));
     echo CHtml::image($file->getSrc());
 }
 public function actionCreate()
 {
     //        if (!Yii::app()->user->checkAccess('administrator')) {
     //            throw new Http403Exception();
     //        }
     $wizard = PublicSurveyRequestWizard::loadWizard();
     $surveyRequest = new UserSurveyRequest();
     //SurveyRequestHelper::loadSurveyRequestOfCurrentUser();
     if (Yii::app()->request->isPostRequest) {
         $successRequest = true;
         if ($wizardPost = Yii::app()->request->getPost(get_class($wizard->current()))) {
             if (!empty($_FILES[get_class($wizard->current())])) {
                 foreach (array_keys($_FILES[get_class($wizard->current())]["name"]) as $fileAttrName) {
                     $wizard->current()->{$fileAttrName} = CUploadedFile::getInstance($wizard->current(), $fileAttrName);
                 }
             }
             $wizard->setCurrentData($wizardPost);
             if (Yii::app()->request->getPost('next')) {
                 if ($successRequest = $wizard->current()->validate()) {
                     $wizard->next();
                 }
             }
             if (Yii::app()->request->getPost('prev')) {
                 $wizard->prev(true);
             }
             if (Yii::app()->request->getPost('start')) {
                 if ($successRequest = $wizard->current()->validate()) {
                     $surveyRequest = $this->saveSurveyRequest($wizard, $surveyRequest);
                     $surveyRequest->status = UserSurveyRequest::STATUS_WAITING;
                     $surveyRequest->save();
                     foreach ($wizard->getFiles() as $name => $file) {
                         $attributes = array('name' => $name, 'fileType' => AttachedFile::FILE_TYPE_SIMPLE_ATTACH, 'attachType' => AttachedFile::ATTACH_TYPE_FILE);
                         AttachedFileHelper::uploadFile(new AttachedFile(), $attributes, get_class($surveyRequest), $surveyRequest->id, $file);
                     }
                     $mail = new YiiMailer();
                     $mail->setFrom(Yii::app()->params['noReplyEmail']);
                     $mail->setTo(Yii::app()->params['notificationEmail']);
                     $mail->setSubject('Создание нового брифа');
                     $mail->setView('surveyCreated');
                     $mail->setData(array('controller' => $this, 'wizard' => $wizard, 'surveyRequest' => $surveyRequest));
                     $filesToAttachment = array();
                     foreach ($surveyRequest->files as $file) {
                         $filesToAttachment[$file->filePath] = $file->name;
                     }
                     $mail->setAttachment($filesToAttachment);
                     if (!$mail->send()) {
                         error_log('Cannot send email about survey: ' . $mail->getError());
                     }
                     Yii::app()->user->setFlash('success', "Запрос на создание проекта успешно отправлен. Специалист BCGroup свяжется с Вами в течение дня.");
                     $wizard = new PublicSurveyRequestWizard();
                 }
             }
         }
         if (Yii::app()->request->getPost('save')) {
             $this->saveSurveyRequest($wizard, $surveyRequest);
         } else {
             $wizard->temporarySave();
         }
         if ($successRequest) {
             $this->redirect('create');
         }
     }
     $this->layout = 'publicMain';
     $this->render("create", array('wizard' => $wizard));
 }
Пример #3
0
 public function actionUpdate($id, $location)
 {
     if (!Yii::app()->user->checkAccess('survey.attachFile') && !Yii::app()->user->checkAccess('survey.vicidial')) {
         throw new Http403Exception();
     }
     $survey = $this->loadModel($id, $location);
     if (!$survey->surveyInfo) {
         $surveyInfo = new SurveyInfo();
         $surveyInfo->surveyId = $survey->id;
         $surveyInfo->surveyType = get_class($survey);
         $survey->surveyInfo = $surveyInfo;
     }
     $attachedFile = new AttachedFile();
     if (isset($_POST['AttachedFile'])) {
         if (!Yii::app()->user->checkAccess('survey.attachFile')) {
             throw new Http403Exception();
         }
         $attachedFile = AttachedFileHelper::uploadFile($attachedFile, $_POST['AttachedFile'], get_class($survey), $survey->sid, CUploadedFile::getInstance($attachedFile, 'file'));
         if ($attachedFile->save()) {
             $this->redirect(array('update', 'id' => $survey->sid, 'location' => get_class($survey)));
         }
     }
     if (isset($_POST['SurveyInfo'])) {
         if (!Yii::app()->user->checkAccess('survey.vicidial')) {
             throw new Http403Exception();
         }
         if (isset($_POST['save'])) {
             $survey->surveyInfo->setAttributes($_POST['SurveyInfo']);
             if ($survey->surveyInfo->save()) {
                 $this->redirect(array('update', 'id' => $survey->sid, 'location' => get_class($survey)));
             }
         } elseif (isset($_POST['prepare_audio'])) {
             if ($survey->surveyInfo && $survey->surveyInfo->vicidialCampaign) {
                 $campaign_id = $survey->surveyInfo->vicidialCampaign->campaign_id;
                 $campaign_name = $survey->surveyInfo->vicidialCampaign->campaign_name;
                 if (FTPApiHelper::prepareFile($campaign_id, $campaign_name)) {
                     Yii::app()->user->setFlash('success', 'Запрос на создание архива с аудиозаписями успешно отправлен.');
                 } else {
                     Yii::app()->user->setFlash('error', 'Ошибка при создании архива с аудиозаписями, обратитесь с разработчику.');
                 }
             } else {
                 Yii::app()->user->setFlash('error', 'Ошибка при создании архива с аудиозаписями, опрос не связан с проектом в vicidial.');
             }
         }
     }
     $this->render("update", array('model' => $survey, 'newAttachedFile' => $attachedFile));
 }