1

Тема: Как в опцию засунуть значение

Всем привет, вот обычный селект и в нем опции, но мне надо не много другое
Мне надо взять значение поля и перетащить его в опцию, но я не знаю как

$opt['mix']      = array('2' => __('category 2', 'catalog'), 
                                  '2' => __('category 2', 'catalog'), 
                                  '3' => __('category 2', 'catalog'), 
                                  '4' => __('category 3', 'catalog'), 
                                  '5' => __('category 4', 'catalog'), 
                                  '6' => __('category 5', 'catalog'));

 $post['mix_1']   = (Request::post('catalog_mix_1'))       ? Request::post('catalog_mix_1')       : $data['mix_1'];

Поделиться

2

Re: Как в опцию засунуть значение

$opt['mix'] это обычный массив php, который используется для вывода опций в селекте, поэтому и дописывать в него нужно как в обычный массив:

Либо

$opt['mix'][] = (Request::post('catalog_mix_1')) ? Request::post('catalog_mix_1') : $data['mix_1'];

Либо

$opt['mix']['свое значение'] = (Request::post('catalog_mix_1')) ? Request::post('catalog_mix_1') : $data['mix_1'];
Спасибо говорим плюсиком в репутацию. Так виднее smile

Поделиться

3

Re: Как в опцию засунуть значение

Смотри что у меня за идея, я пытаюсь создать сортировку на js с помощью плагина MixItUp.

Суть:
Ты создаешь подкатегорию в которой есть такие поля как:
mix 1, mix 2, mix 3...
Которые могут допустим означать сортировку по товарной марке.

Потом я добавляю товар где есть селект опции

$opt['mix']      = array('2' => __('category 2', 'catalog'), 

со значениями подкатегории (mix 1, mix 2, mix 3).

Короче говоря создаешь в подкатегории выбор сортировки и выводишь её в добавление товара.

И в этом у меня трабл я не могу вывести из подкатегории в добавление товара значения.

Поделиться

4 (2015-07-14 05:52:36 отредактировано HiS)

Re: Как в опцию засунуть значение

Сейчас попробую сделать из того что ты написал, не получается я слишком слаб в php hmm

<?php
Navigation::add(__('Catalog', 'catalog'), 'content', 'catalog', 10);
Action::add('admin_pre_render','CatalogAdmin::ajaxQuery');
class CatalogAdmin extends Backend {
    public static function main() {
        $opt['site_url']  = Option::get('siteurl');
        $errors           = array();
        $opt['status']    = array('available' => __('Available', 'catalog'), 'absent' => __('Absent', 'catalog'));
        $opt['mix']       = array('mix_1' => __('category 1', 'catalog'), 
                                  'mix_2' => __('category 2', 'catalog'), 
                                  'mix_3' => __('category 3', 'catalog'), 
                                  'mix_4' => __('category 4', 'catalog'), 
                                  'mix_5' => __('category 5', 'catalog'));
        // add table
        $items            = new Table('cat_items');
        $folders          = new Table('cat_folder');
        $tags             = new Table('cat_tag');
        $users            = new Table('users');
        $user = $users->select('[id='.Session::get('user_id').']', null);
        $user['firstname'] = Html::toText($user['firstname']);
        $user['lastname']  = Html::toText($user['lastname']);
        if (isset($user['firstname']) && trim($user['firstname']) !== '') {
            if (trim($user['lastname']) !== '') $lastname = ' '.$user['lastname']; else $lastname = '';
            $author = $user['firstname'] . $lastname;
        } else {
            $author = Session::get('user_login');
        }
        if (Request::get('action')) {
            switch (Request::get('action')) {
                case "settings":
                if (Request::post('catalog_submit_settings_cancel')) {
                    Request::redirect('index.php?id=catalog');
                }
                if (Request::post('catalog_submit_settings')) {
                    if (Security::check(Request::post('csrf'))) {
                        Option::update(array(
                            'catalog_limit'       => (int)Request::post('limit'),
                            'catalog_limit_admin' => (int)Request::post('limit_admin'),
                            'catalog_w'           => (int)Request::post('width_thumb'),
                            'catalog_h'           => (int)Request::post('height_thumb'),
                            'catalog_wmax'        => (int)Request::post('width_orig'),
                            'catalog_hmax'        => (int)Request::post('height_orig'),
                            'catalog_resize'      => (string)Request::post('resize'),
                            'catalog_template'    => (string)Request::post('pattern')
                        ));
                        Notification::set('success', __('Your changes have been saved', 'catalog'));
                        Request::redirect('index.php?id=catalog&action=settings');
                    } else { die('csrf detected!'); }
                }
                View::factory('catalog/views/backend/settings')->display();
                break;
                case "tag":
                if (Request::post('catalog_submit_tag_cancel')) {
                    Request::redirect('index.php?id=catalog');
                }
                if (Request::post('catalog_save_tag')) {
                    if (Security::check(Request::post('csrf'))) {
                        $id = (int)Request::post('edit_uid');
                        $data = array(
                            'title'        => Request::post('catalog_title'),
                            'sorting'      => (int)Request::post('catalog_sort')
                        );
                        if ($id > 0) {
                            if($tags->updateWhere('[id='.$id.']', $data)) {
                                Notification::set('success', __('Tag <i>:item</i> have been saved.', 'catalog', array(':item' => Request::post('catalog_title'))));
                            }
                        } else {
                            if($tags->insert($data)) {
                                Notification::set('success', __('New tag <i>:item</i> have been added.', 'catalog', array(':item' => Request::post('catalog_title'))));
                            }
                        }
                        Request::redirect('index.php?id=catalog&action=tag');
                    } else { die('csrf detected!'); }
                }
                $records_all = $tags->select(null, 'all');
                $records_sort = Arr::subvalSort($records_all, 'sorting');
                View::factory('catalog/views/backend/tag')
                    ->assign('items', $records_sort)
                    ->display();
                break;
                case "items":
                $limit = Option::get('catalog_limit_admin');
                $id = (int)Request::get('catalog_id');
                $records_all = $items->select('[catalog="'.$id.'"]', 'all', null, array('name', 'article', 'price', 'img', 'title', 'h1', 'description', 'keywords', 'slug', 'date', 'author', 'mix', 'status', 'catalog', 'hits'));
                $opt['catalog'] = $folders->select('[id='.$id.']', null);
                $cnt = count($records_all);
                $opt['pages'] = ceil($cnt/$limit);
                $opt['cid'] = (Request::get('catalog_id')) ? (int)Request::get('catalog_id') : 1;
                $opt['page'] = (Request::get('page')) ? (int)Request::get('page') : 1;
                $opt['sort'] = (Request::get('sort')) ? (string)Request::get('sort') : 'date';
                $opt['order'] = (Request::get('order') and Request::get('order')=='ASC') ? 'ASC' : 'DESC';
                if ($opt['page'] < 1) { $opt['page'] = 1; }
                elseif ($opt['page'] > $opt['pages']) { $opt['page'] = $opt['pages']; }
                $start = ($opt['page']-1)*$limit;
                $records_sort = Arr::subvalSort($records_all, $opt['sort'], $opt['order']);
                if($cnt>0) $records = array_slice($records_sort, $start, $limit);
                else $records = array();
                View::factory('catalog/views/backend/items')
                    ->assign('items', $records)
                    ->assign('opt', $opt)
                    ->display();
                break;
                case "cat_add":
                if (Request::post('exit')) {
                    Request::redirect('index.php?id=catalog');
                }
                $tag_list = $tags->select(null, 'all', null, array('id', 'title'));
                if (count($tag_list) == 0) {
                    Notification::set('error', __('Add tag for create catalog', 'catalog'));
                    Request::redirect('index.php?id=catalog&action=tag');
                }  else {
                    $opt['tags'] = array();
                    foreach ($tag_list as $row) {
                        $opt['tags'][$row['id']] = $row['title'];
                    }
                }
                if (Request::post('add_catalog') || Request::post('add_catalog_and_exit')) {
                    if (Security::check(Request::post('csrf'))) {
                        if (count($errors) == 0) {
                            $data = array(
                                'title'         => (string)Request::post('catalog_title'),
                                'slug'          => Security::safeName(Request::post('catalog_slug'), '-', true),
                                'description'   => (string)Request::post('catalog_description'),
                                'keywords'      => (string)Request::post('catalog_keywords'),
                                'mix_1'            => (string)Request::post('catalog_mix_1'),
                                'mix_2'            => (string)Request::post('catalog_mix_2'),
                                'mix_3'            => (string)Request::post('catalog_mix_3'),
                                'mix_4'            => (string)Request::post('catalog_mix_4'),
                                'mix_5'            => (string)Request::post('catalog_mix_5'),
                                'parent'        => 0
                            );
                            if($folders->insert($data)) {
                                $last_id = $folders->lastId();
                                File::setContent(STORAGE . DS . 'catalog' . DS .'catalog.'. $last_id .'.txt', XML::safe(Request::post('editor')));
                                CatalogAdmin::UploadImage('cat_'.$last_id, $_FILES);
                                Notification::set('success', __('New catalog <i>:catalog</i> have been added.', 'catalog', array(':catalog' => $data['title'])));
                            }
                            if (Request::post('add_catalog')) {
                                Request::redirect('index.php?id=catalog&action=cat_edit&catalog_id='.$last_id);
                            } else {
                                Request::redirect('index.php?id=catalog');
                            }
                        }
                    } else { die('csrf detected!'); }
                }
                $post['slug']          = (Request::post('catalog_slug'))        ? Request::post('catalog_slug')        : '';
                $post['title']         = (Request::post('catalog_title'))       ? Request::post('catalog_title')       : '';
                $post['mix_1']         = (Request::post('catalog_mix_1'))       ? Request::post('catalog_mix_1')       : '';
                $post['mix_2']         = (Request::post('catalog_mix_2'))       ? Request::post('catalog_mix_2')       : '';
                $post['mix_3']         = (Request::post('catalog_mix_3'))       ? Request::post('catalog_mix_3')       : '';
                $post['mix_4']         = (Request::post('catalog_mix_4'))       ? Request::post('catalog_mix_4')       : '';
                $post['mix_5']         = (Request::post('catalog_mix_5'))       ? Request::post('catalog_mix_5')       : '';
                $post['description']   = (Request::post('catalog_description')) ? Request::post('catalog_description') : '';
                $post['keywords']      = (Request::post('catalog_keywords'))    ? Request::post('catalog_keywords')    : '';
                View::factory('catalog/views/backend/cat_add')
                    ->assign('post', $post)
                    ->assign('opt', $opt)
                    ->assign('errors', $errors)
                    ->display();
                break;
                case "cat_edit":
                if(Request::get('catalog_id')) {
                    if (Request::post('edit_catalog') || Request::post('edit_catalog_and_exit')) {
                        if (Security::check(Request::post('csrf'))) {
                            if (count($errors) == 0) {
                                $data = array(
                                    'title'         => (string)Request::post('catalog_title'),
                                    'slug'          => Security::safeName(Request::post('catalog_slug'), '-', true),
                                    'mix_1'            => (string)Request::post('catalog_mix_1'),
                                    'mix_2'            => (string)Request::post('catalog_mix_2'),
                                    'mix_3'            => (string)Request::post('catalog_mix_3'),
                                    'mix_4'            => (string)Request::post('catalog_mix_4'),
                                    'mix_5'            => (string)Request::post('catalog_mix_5'),
                                    'description'   => (string)Request::post('catalog_description'),
                                    'keywords'      => (string)Request::post('catalog_keywords'),
                                    'tags'          => (int)Request::post('catalog_tag'),
                                    'parent' => 0
                                );
                                $id = (int)Request::post('catalog_id');
                                if($folders->updateWhere('[id='.$id.']', $data)) {
                                    CatalogAdmin::UploadImage('cat_'.$id, $_FILES);
                                    File::setContent(STORAGE . DS . 'catalog' . DS .'catalog.'. $id .'.txt', XML::safe(Request::post('editor')));
                                    Notification::set('success', __('Your changes to the catalog <i>:catalog</i> have been saved.', 'catalog', array(':catalog' => Request::post('catalog_title'))));
                                }
                                if (Request::post('edit_catalog_and_exit')) {
                                    Request::redirect('index.php?id=catalog');
                                } else {
                                    Request::redirect('index.php?id=catalog&action=cat_edit&catalog_id='.$id);
                                }
                            }
                        } else { die('csrf detected!'); }
                    }
                    $tag_list = $tags->select(null, 'all', null, array('id', 'title'));
                    $opt['tags'] = array();
                    foreach ($tag_list as $row) {
                        $opt['tags'][$row['id']] = $row['title'];
                    }
                    $post['cid'] = (int)Request::get('catalog_id');
                    $data = $folders->select('[id="'.$post['cid'].'"]', null);
                    if($data) {
                        $post['slug']          = (Request::post('catalog_slug'))        ? Request::post('catalog_slug')        : $data['slug'];
                        $post['title']         = (Request::post('catalog_title'))       ? Request::post('catalog_title')       : $data['title'];
                        $post['mix_1']         = (Request::post('catalog_mix_1'))       ? Request::post('catalog_mix_1')       : $data['mix_1'];
                        $post['mix_2']         = (Request::post('catalog_mix_2'))       ? Request::post('catalog_mix_2')       : $data['mix_2'];
                        $post['mix_3']         = (Request::post('catalog_mix_3'))       ? Request::post('catalog_mix_3')       : $data['mix_3'];
                        $post['mix_4']         = (Request::post('catalog_mix_4'))       ? Request::post('catalog_mix_4')       : $data['mix_4'];
                        $post['mix_5']         = (Request::post('catalog_mix_5'))       ? Request::post('catalog_mix_5')       : $data['mix_5'];
                        $post['description']   = (Request::post('catalog_description')) ? Request::post('catalog_description') : $data['description'];
                        $post['keywords']      = (Request::post('catalog_keywords'))    ? Request::post('catalog_keywords')    : $data['keywords'];
                        $post['tags']          = (Request::post('catalog_tags'))        ? Request::post('catalog_tag')         : $data['tags'];
                        View::factory('catalog/views/backend/cat_edit')
                            ->assign('post', $post)
                            ->assign('opt', $opt)
                            ->assign('errors', $errors)
                            ->display();
                    }
                }
                break;
                case "add":
                $opt['cid'] = (int)Request::get('catalog_id');
                $folder = $folders->select('[id='.$opt['cid'].']', null);
                $opt['title'] = $folder['title'];
                if (Request::post('exit')) {
                    Request::redirect('index.php?id=catalog&action=items&catalog_id='.$opt['cid']);
                }
                if (Request::post('add_item') || Request::post('add_item_and_exit')) {
                    if (Security::check(Request::post('csrf'))) {
                        if (Valid::date(Request::post('catalog_date'))) $date = strtotime(Request::post('catalog_date'));
                        else $date = time();
                        if (count($errors) == 0) {
                            $data = array(
                                'title'        => Request::post('catalog_title'),
                                'article'      => Request::post('catalog_article'),
                                'price'        => Request::post('catalog_price'),
                                'number'       => Request::post('catalog_number'),
                                'mix'          => Request::post('catalog_mix'),
                                'status'       => Request::post('catalog_status'),
                                'volume'       => Request::post('catalog_volume'),
                                'img'          => Request::post('catalog_img'),
                                'short'        => Request::post('catalog_short'),
                                'h1'           => Request::post('catalog_h1'),
                                'description'  => Request::post('catalog_description'),
                                'keywords'     => Request::post('catalog_keywords'),
                                'date'         => $date,
                                'author'       => $author,
                                'catalog'      => $opt['cid'],
                                'hits' => 0
                            );
                            if($items->insert($data)) {
                                $last_id = $items->lastId();
                                File::setContent(STORAGE . DS . 'catalog' . DS . 'item.' . $last_id . '.txt', XML::safe(Request::post('editor')));
                                CatalogAdmin::UploadImage($last_id, $_FILES);
                                Notification::set('success', __('New item <i>:item</i> have been added.', 'catalog', array(':item' => Request::post('catalog_title'))));
                            }
                            if (Request::post('add_item') && isset($last_id)) {
                                Request::redirect('index.php?id=catalog&action=edit&item_id='.$last_id);
                            } else {
                                Request::redirect('index.php?id=catalog&action=items&catalog_id='.$opt['cid']);
                            }
                        }
                    } else { die('csrf detected!'); }
                }
                $post['title']        = (Request::post('catalog_title'))       ? Request::post('catalog_title')       : '';
                $post['article']      = (Request::post('catalog_article'))     ? Request::post('catalog_article')     : '';
                $post['price']        = (Request::post('catalog_price'))       ? Request::post('catalog_price')       : '';
                $post['number']       = (Request::post('catalog_number'))      ? Request::post('catalog_number')      : '';
                $post['mix']          = (Request::post('catalog_mix'))         ? Request::post('catalog_mix')         : '';
                $post['volume']       = (Request::post('catalog_volume'))      ? Request::post('catalog_volume')      : '';
                $post['img']          = (Request::post('catalog_img'))         ? Request::post('catalog_img')         : '';
                $post['short']        = (Request::post('catalog_short'))       ? Request::post('catalog_short')       : '';
                $post['h1']           = (Request::post('catalog_h1'))          ? Request::post('catalog_h1')          : '';
                $post['description']  = (Request::post('catalog_description')) ? Request::post('catalog_description') : '';
                $post['keywords']     = (Request::post('catalog_keywords'))    ? Request::post('catalog_keywords')    : '';
                $opt['date'] = Date::format(time(), 'Y-m-d H:i:s');
                Notification::setNow('catalog', 'catalog');
                View::factory('catalog/views/backend/add')
                    ->assign('post', $post)
                    ->assign('opt', $opt)
                    ->assign('errors', $errors)
                    ->display();
                break;
                case "edit":
                if(Request::get('item_id')) {
                    if (Request::post('edit_item') || Request::post('edit_item_and_exit')) {
                        if (Security::check(Request::post('csrf'))) {
                            if (Valid::date(Request::post('catalog_date'))) $date = strtotime(Request::post('catalog_date'));
                            else $date = time();
                            $id = (int)Request::post('item_id');
                            if (count($errors) == 0) {
                                $data = array(
                                    'title'        => Request::post('catalog_title'),
                                    'article'      => Request::post('catalog_article'),
                                    'price'        => Request::post('catalog_price'),
                                    'number'       => Request::post('catalog_number'),
                                    'mix'          => Request::post('catalog_mix'),
                                    'status'       => Request::post('catalog_status'),
                                    'volume'       => Request::post('catalog_volume'),
                                    'img'          => Request::post('catalog_img'),
                                    'short'        => Request::post('catalog_short'),
                                    'h1'           => Request::post('catalog_h1'),
                                    'description'  => Request::post('catalog_description'),
                                    'keywords'     => Request::post('catalog_keywords'),
                                    'date'         => $date,
                                    'author'       => $author
                                );
                                if($items->updateWhere('[id='.$id.']', $data)) {
                                    CatalogAdmin::UploadImage($id, $_FILES);
                                    File::setContent(STORAGE . DS . 'catalog' . DS . 'item.' . $id . '.txt', XML::safe(Request::post('editor')));
                                    Notification::set('success', __('Your changes to the item <i>:item</i> have been saved.', 'catalog', array(':item' =>Request::post('catalog_title'))));
                                }
                                if (Request::post('edit_item_and_exit')) {  
                                    Request::redirect('index.php?id=catalog&action=items&catalog_id='.Request::post('cat_id'));
                                } else {
                                    Request::redirect('index.php?id=catalog&action=edit&item_id='.$id);
                                }
                            }
                        }
                    }
                    $opt['id'] = (int)Request::get('item_id');
                    $data = $items->select('[id="'.$opt['id'].'"]', null);
                    if($data) {
                        $item_content = File::getContent(STORAGE . DS . 'catalog' . DS . 'item.' . $opt['id'] . '.txt');
                        $opt['cid'] = $data['catalog'];
                        $post['title']         = (Request::post('catalog_title'))       ? Request::post('catalog_title')       : $data['title'];
                        $post['article']       = (Request::post('catalog_article'))     ? Request::post('catalog_article')     : $data['article'];
                        $post['price']         = (Request::post('catalog_price'))       ? Request::post('catalog_price')       : $data['price'];
                        $post['number']        = (Request::post('catalog_number'))      ? Request::post('catalog_number')      : $data['number'];
                        $post['mix']           = (Request::post('catalog_mix'))         ? Request::post('catalog_mix')         : $data['mix'];
                        $post['status']        = (Request::post('catalog_status'))      ? Request::post('catalog_status')      : $data['status'];
                        $post['volume']        = (Request::post('catalog_volume'))      ? Request::post('catalog_volume')      : $data['volume'];
                        $post['img']           = (Request::post('catalog_img'))         ? Request::post('catalog_img')         : $data['img'];
                        $post['short']         = (Request::post('catalog_short'))       ? Request::post('catalog_short')       : $data['short'];
                        $post['h1']            = (Request::post('catalog_h1'))          ? Request::post('catalog_h1')          : $data['h1'];
                        $post['keywords']      = (Request::post('catalog_keywords'))    ? Request::post('catalog_keywords')    : $data['keywords'];
                        $post['description']   = (Request::post('catalog_description')) ? Request::post('catalog_description') : $data['description'];
                        $post['date']          = (Request::post('catalog_date'))        ? Request::post('catalog_date')        : $data['date'];
                        $opt['date'] = Date::format($post['date'], 'Y-m-d H:i:s');
                        if ((int)Request::get('upload') > 0)  {
                            Notification::setNow('upload', 'catalog');
                        }
                        else {
                            Notification::setNow('catalog', 'catalog');
                        }
                        View::factory('catalog/views/backend/edit')
                            ->assign('post', $post)
                            ->assign('opt', $opt)
                            ->assign('errors', $errors)
                            ->display();
                    }
                }
                break;
                case "delete":
                if (Request::get('catalog_id')) {
                    if (Security::check(Request::get('token'))) {
                        $id = (int)Request::get('catalog_id');
                        $data = $folders->select('[id='.$id.']', null);
                        if ($folders->deleteWhere('[id='.$id.']')) {
                            File::delete($opt['dir'] . $id . '.jpg');
                            File::delete($opt['dir']. 'thumbnail' . DS . $id . '.jpg');
                            File::delete(STORAGE . DS . 'catalog' . DS . 'catalog.' . $id . '.txt');
                            Notification::set('success', __('Catalog <i>:catalog</i> deleted', 'catalog', array(':catalog' => $data['title'])));
                        }
                        $data = $items->select('[catalog='.$id.']');
                        if (count($data) > 0)
                        {
                            foreach ($data as $item)
                            {
                                if ($items->deleteWhere('[id='.$item['id'].']')) {
                                    File::delete($opt['dir'] . $item['id'] . '.jpg');
                                    File::delete($opt['dir']. 'thumbnail' . DS . $item['id'] . '.jpg');
                                    File::delete(STORAGE . DS . 'catalog' . DS . 'item.' . $item['id'] . '.txt');
                                }
                            }
                        }
                        Request::redirect('index.php?id=catalog');
                    } else { die('csrf detected!'); }
                }
                if (Request::get('item_id')) {
                    if (Security::check(Request::get('token'))) {
                        $id = (int)Request::get('item_id');
                        $data = $items->select('[id='.$id.']', null);
                        if ($items->deleteWhere('[id='.$id.']')) {
                            File::delete($opt['dir'] . $id . '.jpg');
                            File::delete($opt['dir']. 'thumbnail' . DS . $id . '.jpg');
                            File::delete(STORAGE . DS . 'catalog' . DS . 'item.' . $id . '.txt');
                            Notification::set('success', __('Item in <i>:catalog</i> deleted', 'catalog', array(':catalog' => Html::toText($data['title']))));
                        }
                        Request::redirect('index.php?id=catalog&action=items&catalog_id='.$data['catalog']);
                    } else {die('csrf detected!'); }
                }
                if (Request::get('tag_id')) {
                    if (Security::check(Request::get('token'))) {
                        $id      = (int)Request::get('tag_id');
                        $data    = $tags->select('[id='.$id.']', null);
                        $folder  = $folders->select('[tag='.$id.']', null);
                        if (count($folder) > 0) {
                            Notification::set('error', __('You can not remove the tag :tag, as it contained elements.', 'catalog', array(':tag' => Html::toText($data['title']))));
                        }
                        else {
                            if ($tags->deleteWhere('[id='.$id.']')) {
                                Notification::set('success', __('Tag <i>:tag</i> deleted', 'catalog', array(':tag' => Html::toText($data['title']))));
                            }
                        }
                        Request::redirect('index.php?id=catalog&action=items&action=tag');
                    } else { die('csrf detected!'); }
                }
                break;
            }
        } else {
            $limit = Option::get('catalog_limit_admin');
            $records_all = $folders->select(null, 'all', null, array('title', 'slug', 'mix_1', 'mix_2', 'mix_3', 'mix_4', 'mix_5', 'tags'));
            $count_catalog = count($records_all);
            $opt['pages'] = ceil($count_catalog/$limit);
            $opt['page'] = (Request::get('page')) ? (int)Request::get('page') : 1;
//            $sort = (Request::get('sort')) ? (string)Request::get('sort') : 'date';
//            $order = (Request::get('order') and Request::get('order')=='ASC') ? 'ASC' : 'DESC';
            if ($opt['page'] < 1) { $opt['page'] = 1; }
            elseif ($opt['page'] > $opt['pages']) { $opt['page'] = $opt['pages']; }
            $start = ($opt['page']-1)*$limit;
//            $records_sort = Arr::subvalSort($records_all, $sort, $order);
            $records_sort = $records_all;
            if($count_catalog>0) $records = array_slice($records_sort, $start, $limit);
            else $records = array();
            View::factory('catalog/views/backend/index')
                ->assign('items', $records)
                ->assign('opt', $opt)
//                ->assign('sort', $sort)
//                ->assign('order', $order)
                ->display();
        }
    }
    public static function UploadImage($uid, $_FILES) {
        $dir = ROOT . DS . 'public' . DS . 'uploads' . DS . 'catalog' . DS;
        if ($_FILES['cat_file']) {
            if($_FILES['cat_file']['type'] == 'image/jpeg' ||
                $_FILES['cat_file']['type'] == 'image/png' ||
                $_FILES['cat_file']['type'] == 'image/gif') {
                $img  = Image::factory($_FILES['cat_file']['tmp_name']);
                $file['wmax']   = (int)Option::get('catalog_wmax');
                $file['hmax']   = (int)Option::get('catalog_hmax');
                $file['w']      = (int)Option::get('catalog_w');
                $file['h']      = (int)Option::get('catalog_h');
                $file['resize'] = Option::get('catalog_resize');
                DevAdmin::ReSize($img, $dir, $uid.'.jpg', $file);
            }
        }
    }
    /**
     *  Ajax save
     */
    public static function ajaxQuery() {
        $tags = new Table('cat_tag');
        $dir = ROOT . DS . 'public' . DS . 'uploads' . DS . 'popps' . DS;
        $id = (int)Request::get('tid');
        if (Request::get('edit') == 'tag') {
            if ($id == 0)
            {
                echo json_encode(array('id'=>$id,'h3'=>__('Add tag', 'catalog')));
                exit();
            }
            $item = $tags->select('[id="'.$id.'"]', null);
            if ($item != null)
            {
                $json_data = array ('id'=>$id,'title'=>$item['title'],'sort'=>$item['sorting'],'h3'=>__('Edit tag', 'catalog'));
            }
            else
            {
                $json_data = array ('id'=>$id,'title'=>'','sort'=>'','h3'=>__('Edit tag', 'catalog'));
            }
            echo json_encode($json_data);
            exit();
        }
    }
    /**
     * Form Component Save
     */
    public static function formComponentSave() {
        if (Request::post('catalog_component_save')) {
            if (Security::check(Request::post('csrf'))) {
                Option::update('catalog_template', Request::post('catalog_form_template'));
                Request::redirect('index.php?id=themes');
            }
        }
    }
    /**
     * Form Component
     */
    public static function formComponent() {
        $_templates = Themes::getTemplates();
        foreach($_templates as $template) {
            $t = basename($template, '.template.php');
            $templates[$t] = $t;
        }
        echo (
            Form::open().
                Form::hidden('csrf', Security::token()).
                Form::label('catalog_form_template', __('Catalog template', 'catalog')).
                Form::select('catalog_form_template', $templates, Option::get('catalog_template')).
                Html::br().
                Form::submit('catalog_component_save', __('Save', 'catalog'), array('class' => 'btn')).
                Form::close()
        );
    }
}

Поделиться