public function control()
 {
     $this->redirectToSternIndiaEndPoint();
     $config = Config::getInstance();
     if (isset($_POST['upload']) && $_POST['upload'] == 'Upload') {
         $target_dir = new FileSystem('upload/');
         $file = new File('foo', $target_dir);
         $name = date('D_d_m_Y_H_m_s_');
         $name = $name . $file->getName();
         $file->setName($name);
         $config = Config::getInstance();
         $file->addValidations(array(new Mimetype($config->getMimeTypes()), new Size('5M')));
         $data = array('name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5());
         try {
             // /Profiler::debugPoint(true,__METHOD__, __FILE__, __LINE__,$data);
             $file->upload();
             //Profiler::debugPoint(true,__METHOD__, __FILE__, __LINE__,$data);
         } catch (Exception $e) {
             $errors = $file->getErrors();
         }
         $csvReader = new CSVReader();
         $destinationFile = $target_dir->directory . $file->getNameWithExtension();
         $data = $csvReader->parse_file($destinationFile);
         //$country= DAOFactory::getDAO('LocationDAO');
         foreach ($data as $loc_arr) {
             Utils::processLocation($loc_arr);
         }
         //Profiler::debugPoint(true,__METHOD__, __FILE__, __LINE__);
         $target_dir = "uploads/";
         $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
         $uploadOk = 1;
         $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
         // Check if image file is a actual image or fake image
         if (isset($_POST["submit"])) {
             $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
             if ($check !== false) {
                 echo "File is an image - " . $check["mime"] . ".";
                 $uploadOk = 1;
             } else {
                 echo "File is not an image.";
                 $uploadOk = 0;
             }
         }
     }
     return $this->generateView();
 }
Example #2
0
 /**
  *  Редактирование язика
  */
 public function anyEdit()
 {
     $id = (int) $this->getRequestParam('id') ?: null;
     if (Arr::get($this->getPostData(), 'submit') !== null) {
         //Редактирование данных в базе
         $data = Arr::extract($this->getPostData(), ['name', 'iso', 'status']);
         try {
             // Загрузка картинки
             $file = new UploadFile('image', new FileSystem('uploads/images'));
             // Optionally you can rename the file on upload
             $file->setName(uniqid());
             // Validate file upload
             $file->addValidations(array(new UploadMimeType(['image/png', 'image/jpg', 'image/gif']), new UploadSize('50M')));
             // Try to upload file
             try {
                 // Success!
                 $file->upload();
                 $data['flag'] = $file->getNameWithExtension();
             } catch (Exception $e) {
                 // Fail!
                 Message::instance()->warning($file->getErrors());
             }
             // здесь надо использовать QueryBuilder потому-что стадартни update исползует метод Baum-а
             Capsule::table('langs')->whereId($id)->update($data);
             Event::fire('Admin.languageUpdate');
         } catch (QueryException $e) {
             Message::instance()->warning('Language was not editing');
         }
     }
     $item = LangModel::find($id);
     if (empty($item)) {
         throw new HttpException(404, json_encode(['errorMessage' => 'Incorrect Language']));
     }
     // отправка в шаблон
     $this->layout->content = View::make('back/languages/edit')->with('item', $item);
 }
Example #3
0
 /**
  * Редактирование пункта меню
  */
 public function anyEdit()
 {
     $id = (int) $this->getRequestParam('id') ?: null;
     $model = MenuItemModel::find($id);
     $entityModel = $model->entities()->first();
     if (empty($model)) {
         throw new HttpException(404, json_encode(['errorMessage' => 'Incorrect Article']));
     }
     if (Arr::get($this->getPostData(), 'submit') !== null) {
         $data = Arr::extract($this->getPostData(), ['slug', 'icon', 'parentId', 'status', 'entity', 'content']);
         $parent = MenuItemModel::find($data['parentId']);
         // Транзакция для Записание данных в базу
         try {
             Capsule::connection()->transaction(function () use($data, $model, $parent, $entityModel) {
                 // Загрузка картинки
                 $file = new UploadFile('image', new FileSystem('uploads/images'));
                 // Optionally you can rename the file on upload
                 $file->setName(uniqid());
                 // Validate file upload
                 $file->addValidations(array(new UploadMimeType(['image/png', 'image/jpg', 'image/gif']), new UploadSize('50M')));
                 // Try to upload file
                 try {
                     // Success!
                     $file->upload();
                     $data['icon'] = $file->getNameWithExtension();
                 } catch (Exception $e) {
                     // Fail!
                     Message::instance()->warning($file->getErrors());
                 }
                 $entityModel->update(['text' => $data['entity']]);
                 foreach ($data['content'] as $iso => $d) {
                     $langId = Lang::instance()->getLang($iso)['id'];
                     EntityTranslationModel::updateOrCreate(['id' => $d['id']], ['text' => $d['text'], 'lang_id' => $langId, 'entity_id' => $entityModel->id]);
                 }
                 Event::fire('Admin.entitiesUpdate');
                 // если нету нового изображения оставить прежний
                 $data['icon'] ?: $model->icon;
                 $model->update(['slug' => $data['slug'], 'status' => $data['status'], 'icon' => $data['icon']]);
                 if ($parent) {
                     $model->makeChildOf($parent);
                 } else {
                     $model->makeRoot($parent);
                 }
             });
             Message::instance()->success('Menu Item was successfully edited');
         } catch (Exception $e) {
             Message::instance()->warning('Menu Item was don\'t edited');
         }
     }
     $model = MenuItemModel::find($id);
     $entityModel = $model->entities()->first();
     // Загрузка контента для каждово языка
     $contents = [];
     foreach (Lang::instance()->getLangsExcept(Lang::DEFAULT_LANGUAGE) as $iso => $lang) {
         $contents[$iso] = $entityModel->translations()->where('lang_id', '=', $lang['id'])->first();
     }
     $this->layout->content = View::make('back/menus/edit')->with('node', $model::getNode())->with('item', $model)->with('contents', $contents);
 }