Example #1
0
 public function onSave()
 {
     try {
         $uploadedFile = Input::file('bukti_pembayaran');
         $validationRules = ['max:' . System\Models\File::getMaxFilesize()];
         $validationRules[] = 'mimes:jpg,jpeg,bmp,png';
         $validation = Validator::make(['bukti_pembayaran' => $uploadedFile], ['bukti_pembayaran' => $validationRules]);
         if ($validation->fails()) {
             throw new ValidationException($validation);
         }
         $uploadedPhoto = Input::file('photo_ijazah');
         $validation_photo = Validator::make(['photo_ijazah' => $uploadedPhoto], ['photo_ijazah' => $validationRules]);
         if ($validation_photo->fails()) {
             throw new ValidationException($validation);
         }
         $post = Input::only('tahun_ajaran_id', 'nama_mahasiswa', 'no_hp', 'alamat', 'jurusan', 'nim', 'nama_orang_tua', 'email', 'judul_skripsi', 'tempat_lahir', 'tanggal_lahir');
         $result = PendaftaranWisuda::create($post);
         if ($result) {
             $new_id = $result->id;
             $this->processFileUpload($new_id, $uploadedFile);
             $this->processFileUploadPhoto($new_id, $uploadedPhoto);
             $param = array('nama_mahasiswa' => $post['nama_mahasiswa'], 'result' => true);
             $this->page['result'] = $this->renderPartial('daftarwisudaresult.htm', $param);
         }
     } catch (\Exception $ex) {
         $param = array('result' => false, 'message' => '');
         $this->page['result'] = $this->renderPartial('daftarwisudaresult.htm', $param);
     }
 }
Example #2
0
 public function onSave()
 {
     //$uploadedFile = Input::file('photo');
     try {
         $uploadedFile = Input::file('photo');
         $validationRules = ['max:' . System\Models\File::getMaxFilesize()];
         $validationRules[] = 'mimes:jpg,jpeg,bmp,png';
         $validation = Validator::make(['photo' => $uploadedFile], ['photo' => $validationRules]);
         if ($validation->fails()) {
             throw new ValidationException($validation);
         }
         $post = Input::except('photo');
         $jalur = $this->get_jalur_pendidikan();
         $post['jalur_pendidikan_id'] = $jalur->id;
         $post['no_pendaftaran'] = $this->autonumber('no_pendaftaran', 3, 'PMB');
         $post['kode_generate'] = $this->generate_code();
         $result = IdentitasMahasiswa::create($post);
         if ($result) {
             $new_id = $result->id;
             $this->processFileUpload($new_id, $uploadedFile);
             $param = array('nama_lengkap' => $post['nama_lengkap'], "no_pendaftaran" => $post['no_pendaftaran'], 'kode_generate' => $post['kode_generate'], 'result' => true);
             $this->page['result'] = $this->renderPartial('pmbresult.htm', $param);
         }
     } catch (\Exception $ex) {
         $param = array('result' => false, 'message' => $ex->getMessage());
         $this->page['result'] = $this->renderPartial('pmbresult.htm', $param);
     }
 }
Example #3
0
    public function postUpload($id = '')
    {
        $user = Auth::getUser();
        $record = Ad::whereRaw('id = ? AND user_id = ?', array($id, $user->id))->first();
        if (!$record) {
            return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'user_not_perm')), 500);
        }
        // Check limit photos
        $count = File::whereRaw('attachment_id = ? AND attachment_type = ?', array($id, 'DLNLab\\Classified\\Models\\Ad'))->count();
        if ($count >= CLF_LIMIT_AD_PHOTO) {
            return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'user_not_perm')), 500);
        }
        $result = null;
        if (Input::hasFile('file_data')) {
            try {
                $uploadedFile = Input::file('file_data');
                $validationRules = ['max:' . File::getMaxFilesize()];
                $validationRules[] = 'mimes:jpg,jpeg,bmp,png,gif';
                $validation = Validator::make(['file_data' => $uploadedFile], ['file_data' => $validationRules]);
                if ($validation->fails()) {
                    throw new ValidationException($validation);
                }
                if (!$uploadedFile->isValid()) {
                    throw new SystemException('File is not valid');
                }
                $file = new File();
                $file->data = $uploadedFile;
                $file->field = 'ad_images';
                $file->attachment_id = $id;
                $file->attachment_type = 'DLNLab\\Classified\\Models\\Ad';
                $file->is_public = true;
                $file->save();
                $file->thumb = $file->getThumb(250, 250, ['mode' => 'crop']);
                $result = new \stdClass();
                $result->id = $file->id;
            } catch (Exception $ex) {
                $result = $ex->getMessage();
                return Response::json(array('status' => 'error', 'message' => $result), 500);
            }
        }
        $result->photo_pattern = '<div id="dln_photo_item_' . $file->id . '" data-id="' . $file->id . '" class="dln-photo-item panel panel-default bg-master-lightest sm-m-b-5 sm-m-l-5 sm-m-r-5">
    <div class="panel-body sm-p-t-10 sm-p-l-5 sm-p-r-5 sm-p-b-10">
        <div class="col-xs-12 col-sm-3 sm-p-l-5 sm-p-r-5">
            <img class="img-thumbnail m-b-5" width="100%" src="' . $file->thumb . '">
        </div>
        <div class="col-xs-12 col-sm-9 sm-p-l-5 sm-p-r-5">
            <textarea placeholder="' . trans(CLF_LANG_LABEL . 'noi_dung') . '" id="dln_photo_desc" class="form-control clearfix m-b-10" required maxlength="500">' . $file->desc . '</textarea>
            <a href="javascript:void(0)" class="dln-up-photo btn btn-sm btn-default pull-left m-r-5" data-original-title="' . trans(CLF_LANG_LABEL . 'len') . '" data-toggle="tooltip"><i class="fs-14 fa fa-arrow-up"></i></a>
            <a href="javascript:void(0)" class="dln-down-photo btn btn-sm btn-default pull-left" data-original-title="' . trans(CLF_LANG_LABEL . 'xuong') . '" data-toggle="tooltip"><i class="fs-14 fa fa-arrow-down"></i></a>
            <a href="javascript:void(0)" class="dln-delete-photo btn btn-sm btn-danger pull-right" data-original-title="' . trans(CLF_LANG_LABEL . 'xoa') . '" data-toggle="tooltip"><i class="fs-14 fa fa-trash-o"></i></a>
        </div>
    </div>
</div>';
        return Response::json(response_message(200, $result));
    }
Example #4
0
 protected function checkUploadPostback()
 {
     if (!post('X_BLOG_IMAGE_UPLOAD')) {
         return;
     }
     $uploadedFileName = null;
     try {
         $uploadedFile = Input::file('file');
         if ($uploadedFile) {
             $uploadedFileName = $uploadedFile->getClientOriginalName();
         }
         $validationRules = ['max:' . File::getMaxFilesize()];
         $validationRules[] = 'mimes:jpg,jpeg,bmp,png,gif';
         $validation = Validator::make(['file_data' => $uploadedFile], ['file_data' => $validationRules]);
         if ($validation->fails()) {
             throw new ValidationException($validation);
         }
         if (!$uploadedFile->isValid()) {
             throw new SystemException(Lang::get('cms::lang.asset.file_not_valid'));
         }
         $fileRelation = $this->model->content_images();
         $file = new File();
         $file->data = $uploadedFile;
         $file->is_public = true;
         $file->save();
         $fileRelation->add($file, $this->sessionKey);
         $result = ['file' => $uploadedFileName, 'path' => $file->getPath()];
         $response = Response::make()->setContent($result);
         $response->send();
         die;
     } catch (Exception $ex) {
         $message = $uploadedFileName ? Lang::get('cms::lang.asset.error_uploading_file', ['name' => $uploadedFileName, 'error' => $ex->getMessage()]) : $ex->getMessage();
         $result = ['error' => $message, 'file' => $uploadedFileName];
         $response = Response::make()->setContent($result);
         $response->send();
         die;
     }
 }
Example #5
0
 /**
  * File upload controller
  */
 public function post_files()
 {
     try {
         if (!Input::hasFile('file')) {
             throw new ApplicationException('No file in request');
         }
         $upload = Input::file('file');
         $validationRules = ['max:' . File::getMaxFilesize()];
         $validation = Validator::make(['file' => $upload], ['file' => $validationRules]);
         if ($validation->fails()) {
             throw new ValidationException($validation);
         }
         if (!$upload->isValid()) {
             throw new ApplicationException(sprintf('File %s is not valid.', $upload->getClientOriginalName()));
         }
         $file = new File();
         $file->data = $upload;
         $file->is_public = true;
         $file->save();
         return Response::json(['id' => $file->id], 200);
     } catch (Exception $e) {
         return Response::json($e->getMessage(), 400);
     }
 }
Example #6
0
 /**
  * Checks the current request to see if it is a postback containing a file upload
  * for this particular widget.
  */
 protected function checkUploadPostback()
 {
     if (!($uniqueId = post('X_OCTOBER_FILEUPLOAD')) || $uniqueId != $this->getId()) {
         return;
     }
     try {
         $uploadedFile = Input::file('file_data');
         $validationRules = ['max:' . File::getMaxFilesize()];
         if ($fileTypes = $this->getAcceptedFileTypes()) {
             $validationRules[] = 'mimes:' . $fileTypes;
         }
         $validation = Validator::make(['file_data' => $uploadedFile], ['file_data' => $validationRules]);
         if ($validation->fails()) {
             throw new ValidationException($validation);
         }
         if (!$uploadedFile->isValid()) {
             throw new SystemException('File is not valid');
         }
         $fileRelation = $this->getRelationObject();
         $file = new File();
         $file->data = $uploadedFile;
         $file->is_public = $fileRelation->isPublic();
         $file->save();
         $fileRelation->add($file, $this->sessionKey);
         $file->thumb = $file->getThumb($this->imageWidth, $this->imageHeight, $this->thumbOptions);
         $result = $file;
     } catch (Exception $ex) {
         $result = json_encode(['error' => $ex->getMessage()]);
     }
     header('Content-Type: application/json');
     die($result);
 }
Example #7
0
 /**
  * Checks the current request to see if it is a postback containing a file upload
  * for this particular widget.
  */
 protected function checkUploadPostback()
 {
     if (!($uniqueId = post('X_OCTOBER_FILEUPLOAD')) || $uniqueId != $this->getId()) {
         return;
     }
     try {
         $uploadedFile = Input::file('file_data');
         $isImage = starts_with($this->getDisplayMode(), 'image');
         $validationRules = ['max:' . File::getMaxFilesize()];
         if ($isImage) {
             $validationRules[] = 'mimes:jpg,jpeg,bmp,png,gif';
         }
         $validation = Validator::make(['file_data' => $uploadedFile], ['file_data' => $validationRules]);
         if ($validation->fails()) {
             throw new ValidationException($validation);
         }
         if (!$uploadedFile->isValid()) {
             throw new SystemException('File is not valid');
         }
         $fileRelation = $this->getRelationObject();
         $file = new File();
         $file->data = $uploadedFile;
         $file->is_public = $fileRelation->isPublic();
         $file->save();
         $fileRelation->add($file, $this->sessionKey);
         $file->thumb = $file->getThumb($this->imageWidth, $this->imageHeight, ['mode' => 'crop']);
         $result = $file;
     } catch (Exception $ex) {
         $result = json_encode(['error' => $ex->getMessage()]);
     }
     die($result);
 }
Example #8
0
 /**
  * Checks the current request to see if it is a postback containing a file upload
  * for this particular widget.
  */
 protected function checkUploadPostback()
 {
     if (!($uniqueId = Request::header('X-OCTOBER-FILEUPLOAD')) || $uniqueId != $this->getId()) {
         return;
     }
     try {
         if (!Input::hasFile('file_data')) {
             throw new ApplicationException('File missing from request');
         }
         $uploadedFile = Input::file('file_data');
         $validationRules = ['max:' . File::getMaxFilesize()];
         if ($fileTypes = $this->getAcceptedFileTypes()) {
             $validationRules[] = 'extensions:' . $fileTypes;
         }
         if ($this->mimeTypes) {
             $validationRules[] = 'mimes:' . $this->mimeTypes;
         }
         $validation = Validator::make(['file_data' => $uploadedFile], ['file_data' => $validationRules]);
         if ($validation->fails()) {
             throw new ValidationException($validation);
         }
         if (!$uploadedFile->isValid()) {
             throw new ApplicationException('File is not valid');
         }
         $fileRelation = $this->getRelationObject();
         $file = new File();
         $file->data = $uploadedFile;
         $file->is_public = $fileRelation->isPublic();
         $file->save();
         $fileRelation->add($file, $this->sessionKey);
         $file = $this->decorateFileAttributes($file);
         $result = ['id' => $file->id, 'thumb' => $file->thumbUrl, 'path' => $file->pathUrl];
         Response::json($result, 200)->send();
     } catch (Exception $ex) {
         Response::json($ex->getMessage(), 400)->send();
     }
     exit;
 }
 protected function checkUploadAction()
 {
     if (!($uniqueId = Request::header('X-OCTOBER-FILEUPLOAD')) || $uniqueId != $this->alias) {
         return;
     }
     try {
         if (!Input::hasFile('file_data')) {
             throw new ApplicationException('File missing from request');
         }
         $uploadedFile = Input::file('file_data');
         $validationRules = ['max:' . File::getMaxFilesize()];
         if ($fileTypes = $this->processFileTypes()) {
             $validationRules[] = 'extensions:' . $fileTypes;
         }
         $validation = Validator::make(['file_data' => $uploadedFile], ['file_data' => $validationRules]);
         if ($validation->fails()) {
             throw new ValidationException($validation);
         }
         if (!$uploadedFile->isValid()) {
             throw new ApplicationException(sprintf('File %s is not valid.', $uploadedFile->getClientOriginalName()));
         }
         $file = new File();
         $file->data = $uploadedFile;
         $file->is_public = true;
         $file->save();
         $this->model->{$this->attribute}()->add($file, $this->getSessionKey());
         $file = $this->decorateFileAttributes($file);
         $result = ['id' => $file->id, 'thumb' => $file->thumbUrl, 'path' => $file->pathUrl];
         return Response::json($result, 200);
     } catch (Exception $ex) {
         return Response::json($ex->getMessage(), 400);
     }
 }
 /**
  * Try to get the upload validation rules.
  * First it will try to load the rules declared in the YAML configuration file
  * If there aren't it will try to get the rules declared in the "fileUploadRules" model's method
  * Lastly, it will add the default rules from the original FileUpload form widget.
  *
  * @return array
  */
 protected function setValidationRules()
 {
     $this->fillFromConfig(['rules']);
     if (is_null($this->rules) && method_exists($this->model, 'fileUploadRules')) {
         // The rules will be stored in a different method than the form rules
         $modelRules = $this->model->fileUploadRules();
         if (is_array($modelRules) && array_key_exists($this->fieldName, $modelRules)) {
             $this->rules = $modelRules[$this->fieldName];
         }
     }
     if (is_null($this->rules)) {
         $this->rules = ['max:' . File::getMaxFilesize()];
         if ($fileTypes = $this->getAcceptedFileTypes()) {
             $this->rules[] = 'extensions:' . $fileTypes;
         }
         if ($this->mimeTypes) {
             $this->rules[] = 'mimes:' . $this->mimeTypes;
         }
     }
     return $this->rules;
 }