Example #1
0
 public function EditAction()
 {
     $id = intval(Request::GetPart(3));
     $product = ProductModel::GetObj()->where('id = ? AND company_id = ?', [0 => $id, 1 => $this->company->id]);
     if (Request::isposted('name')) {
         $product->name = Request::post('name');
         $product->about = Request::post('about');
         $product->company_id = $this->company->id;
         $file = new File('pic', 7);
         if ($file->isLoaded()) {
             if (!$file->checktype(['jpg', 'jpeg', 'bmp', 'gif', 'png'])) {
                 Site::Error('Неверный тип файла');
             } else {
                 $new_name = $file->getnewname();
                 $file->SaveResizedImage($new_name, 200, 0);
                 $file->SaveResizedImage('s_' . $new_name, 100, 0);
                 //Если файл лого уже существует
                 if ($product->pic != '') {
                     if (file_exists(ROOT . '/web/files/' . $product->pic)) {
                         unlink(ROOT . '/web/files/' . $product->pic);
                     }
                     if (file_exists(ROOT . '/web/files/s_' . $product->pic)) {
                         unlink(ROOT . '/web/files/s_' . $product->pic);
                     }
                 }
                 $product->pic = $new_name;
             }
         }
         if ($product->name != '') {
             if ($product->id == 0) {
                 Site::Message('Продукция успешно добавлена в каталог');
             } else {
                 Site::Message('Продукция успешно отредактирована');
             }
             $product->save();
             $this->IndexAction();
         } else {
             Site::Message('Наименование продукции обязательно для заполения');
             $this->Render('edit', ['product' => $product, 'company' => $this->company]);
         }
     } else {
         $this->Render('edit', ['product' => $product, 'company' => $this->company]);
     }
 }
 public function SetlogoAction()
 {
     $file = new File('logo', 7);
     if ($file->isLoaded()) {
         if (!$file->checktype(['jpg', 'jpeg', 'bmp', 'gif', 'png'])) {
             Site::Error('Неверный тип файла');
             $this->render('logo');
         } else {
             $new_name = $file->getnewname();
             $file->SaveResizedImage($new_name, 200, 200);
             $file->SaveResizedImage('s_' . $new_name, 100, 100);
             //Если файл лого уже существует
             $company = CompanyModel::GetObj()->id(User::company());
             if (file_exists(ROOT . '/web/files/' . $company->logo) and $company->logo != '') {
                 unlink(ROOT . '/web/files/' . $company->logo);
                 unlink(ROOT . '/web/files/s_' . $company->logo);
             }
             $this->company->logo = $new_name;
             $this->company->save();
             $this->ConfirmlogoAction();
         }
     } else {
         Site::Message('Ошибка загрузки файла, попробуйте ещё раз');
         $this->render('logo');
     }
 }
Example #3
0
 public function SetlogoAction()
 {
     $file = new File('logo', 7);
     if ($file->isLoaded()) {
         if (!$file->checktype(['jpg', 'jpeg', 'bmp', 'gif', 'png'])) {
             Site::Error('Неверный тип файла');
             $this->IndexAction();
         } else {
             $new_name = $file->getnewname();
             $file->SaveResizedImage($new_name, 200, 0);
             $file->SaveResizedImage('s_' . $new_name, 100, 0);
             if (file_exists(ROOT . '/web/files/' . $this->company->logo) and $this->company->logo != '') {
                 unlink(ROOT . '/web/files/' . $this->company->logo);
                 unlink(ROOT . '/web/files/s_' . $this->company->logo);
             }
             $this->company->logo = $new_name;
             $this->company->save();
             $this->IndexAction();
         }
     } else {
         Site::Message('Ошибка загрузки файла, попробуйте ещё раз');
         $this->IndexAction();
     }
 }