Example #1
0
 public function SaveFile($name)
 {
     if (move_uploaded_file($_FILES[$this->filename]["tmp_name"], ROOT . 'web/files/' . $name)) {
         Site::Message('Файл Успешно загружен');
     } else {
         Site::Error('Ошибка загрузки файла');
     }
 }
Example #2
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]);
     }
 }
Example #3
0
 public function IndexAction()
 {
     if (User::isLogged()) {
         Site::Message('Вы уже вошли в систему');
         $this->Route();
     } elseif (Request::isPosted('loguser')) {
         User::LoginByPass(Request::post('loguser', '', 'mail'), Request::post('logpass', '', 'safe'));
         if (!User::isLogged()) {
             Site::Error('Неверный логин или пароль');
             $this->Render();
         } else {
             Site::Message('Вы успешно вошли в систему');
             if (!User::admin()) {
                 $this->Route('profile');
             } else {
                 $this->Route();
             }
         }
     } else {
         $this->Render();
     }
 }
 public function ConfirmlogoAction()
 {
     $company = CompanyModel::GetObj()->id(User::company());
     if ($company->id > 0) {
         $this->render('confirmlogo', ['logo' => $company->logo]);
     } else {
         Site::Error('Непредвиденная ошибка');
         $this->route();
     }
 }
Example #5
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();
     }
 }