HEX
Server: Apache/2.4.6 (CentOS) mpm-itk/2.4.7-04 mod_fcgid/2.3.9 PHP/5.4.16
System: Linux dvm.vladweb.ru 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: region-gk.ru (1016)
PHP: 7.3.33
Disabled: NONE
Upload Files
File: /home/temp/yarusvl.ru/adminx/core/SupplierAdmin.php
<?php

require_once('api/Mgc.php');

class SupplierAdmin extends Mgc {
    
    public function fetch() {
        $supplier = new stdClass;
        /*Принимаем инофмрацию о бренде*/
        if($this->request->method('post')) {
            $supplier->id = $this->request->post('id', 'integer');
            $supplier->name = $this->request->post('name');
            $supplier->annotation = $this->request->post('annotation');
            $supplier->login = $this->request->post('login');
            $supplier->password = $this->request->post('password');
            $supplier->description = $this->request->post('description');
            $supplier->visible = $this->request->post('visible', 'boolean');
            
            $supplier->url = trim($this->request->post('url', 'string'));
            $supplier->meta_title = $this->request->post('meta_title');
            $supplier->meta_keywords = $this->request->post('meta_keywords');
            $supplier->meta_description = $this->request->post('meta_description');
            
            $supplier->url = preg_replace("/[\s]+/ui", '', $supplier->url);
            $supplier->url = strtolower(preg_replace("/[^0-9a-z]+/ui", '', $supplier->url));
            if (empty($supplier->url)) {
                $supplier->url = $this->translit_alpha($supplier->name);
            }
            
            // Не допустить одинаковые URL разделов.
            if(($c = $this->suppliers->get_supplier($supplier->url)) && $c->id!=$supplier->id) {
                $this->design->assign('message_error', 'url_exists');
            } elseif(empty($supplier->name)) {
                $this->design->assign('message_error', 'empty_name');
            } elseif(empty($supplier->url)) {
                $this->design->assign('message_error', 'empty_url');
            } else {
                /*Добавляем/обновляем бренд*/
                if(empty($supplier->id)) {
                    $supplier->id = $this->suppliers->add_supplier($supplier);
                    $this->design->assign('message_success', 'added');
                } else {
                    $this->suppliers->update_supplier($supplier->id, $supplier);
                    $this->design->assign('message_success', 'updated');
                }
                
                // Удаление изображения
                if ($this->request->post('delete_image')) {
                    $this->image->delete_image($supplier->id, 'image', 'suppliers', $this->config->original_suppliers_dir, $this->config->resized_suppliers_dir);
                }
                // Загрузка изображения
                $image = $this->request->files('image');
                if (!empty($image['name']) && ($filename = $this->image->upload_image($image['tmp_name'], $image['name'], $this->config->original_suppliers_dir))) {
                    $this->image->delete_image($supplier->id, 'image', 'suppliers', $this->config->original_suppliers_dir, $this->config->resized_suppliers_dir);
                    $this->suppliers->update_supplier($supplier->id, array('image'=>$filename));
                }
                $supplier = $this->suppliers->get_supplier($supplier->id);
            }
        } else {
            $supplier->id = $this->request->get('id', 'integer');
            $supplier = $this->suppliers->get_supplier($supplier->id);
        }
        
        $this->design->assign('supplier', $supplier);
        return  $this->design->fetch('supplier.tpl');
    }
    
}