コード例 #1
0
ファイル: admin.php プロジェクト: Burick/altercpa
function admin_module($core)
{
    $module = $core->get['m'] ? $core->get['m'] : null;
    $id = $core->post['id'] ? (int) $core->post['id'] : ($core->get['id'] ? (int) $core->get['id'] : 0);
    $page = $core->get['page'] > 0 ? (int) $core->get['page'] : 1;
    $message = $core->get['message'] ? $core->get['message'] : null;
    switch ($module) {
        case 'files':
            $d = opendir(DIR_NEWS);
            $files = array();
            while ($f = readdir($d)) {
                if (is_file(DIR_NEWS . $f)) {
                    $files[] = $f;
                }
            }
            closedir($d);
            sort($files);
            $core->tpl->load('body', 'files');
            $core->tpl->vars('body', array('upload' => $core->url('a', 'file-add', 0)));
            foreach ($files as $f) {
                $core->tpl->block('body', 'file', array('url' => sprintf(PATH_NEWS, $f), 'size' => mkb_out(filesize(DIR_NEWS . $f)), 'time' => date('d.m.Y H:i:s', filemtime(DIR_NEWS . $f)), 'name' => $f, 'del' => $core->url('a', 'file-del', 0) . '?name=' . $f));
            }
            $core->tpl->output('body');
            $core->_die();
            // Users List
        // Users List
        case 'users':
            switch ($message) {
                case 'add-ok':
                    $core->info('info', 'done_user_add');
                    break;
                case 'edit-ok':
                    $core->info('info', 'done_user_edit');
                    break;
                case 'del-ok':
                    $core->info('info', 'done_user_del');
                    break;
                case 'add-e':
                    $core->info('error', 'error_user_add');
                    break;
                case 'edit-e':
                    $core->info('error', 'error_user_edit');
                    break;
                case 'del-e':
                    $core->info('error', 'error_user_del');
                    break;
                case 'del-a':
                    $core->info('error', 'error_user_root');
                    break;
            }
            if ($id) {
                $user = $core->db->row("SELECT * FROM " . DB_USER . " WHERE user_id = '{$id}' LIMIT 1");
                $core->mainline->add($core->lang['admin_user_h'], $core->url('m', 'users'));
                $core->mainline->add($user['user_name']);
                $core->header();
                $work = array();
                foreach ($core->lang['user_works'] as $i => $v) {
                    $work[] = array('name' => $v, 'value' => $i, 'select' => $user['user_work'] == $i);
                }
                $comps = $core->wmsale->get('comps');
                $comp = array(array('name' => '---', 'value' => 0));
                foreach ($comps as $i => $c) {
                    $comp[] = array('name' => $c, 'value' => $i, 'select' => $i == $user['user_comp']);
                }
                $exts = $core->wmsale->get('exts');
                $ext = array(array('name' => '---', 'value' => 0));
                foreach ($exts as $i => $c) {
                    $ext[] = array('name' => $c, 'value' => $i, 'select' => $i == $user['user_ext']);
                }
                $title = $core->lang['user_edit'];
                $action = $core->url('a', 'user-edit', $id);
                $method = 'post';
                $field = array(array('type' => 'text', 'length' => 100, 'name' => 'name', 'head' => $core->lang['user_name'], 'descr' => $core->lang['user_name_d'], 'value' => $user['user_name']), array('type' => 'text', 'length' => 100, 'name' => 'email', 'head' => $core->lang['user_email'], 'descr' => $core->lang['user_email_d'], 'value' => $user['user_mail']), array('type' => 'text', 'length' => 32, 'name' => 'pass', 'head' => $core->lang['user_pass'], 'descr' => $core->lang['user_pass_d']), array('type' => 'checkbox', 'name' => 'level', 'head' => $core->lang['user_level'], 'descr' => $core->lang['user_level_d'], 'checked' => $user['user_level']), array('type' => 'checkbox', 'name' => 'ban', 'head' => $core->lang['user_ban'], 'descr' => $core->lang['user_ban_d'], 'checked' => $user['user_ban']), array('type' => 'checkbox', 'name' => 'warn', 'head' => $core->lang['user_warn'], 'descr' => $core->lang['user_warn_d'], 'checked' => $user['user_warn']), array('type' => 'checkbox', 'name' => 'vip', 'head' => $core->lang['comp_vip'], 'descr' => $core->lang['comp_vip_d'], 'checked' => $user['user_vip']), array('type' => 'select', 'name' => 'work', 'head' => $core->lang['user_work'], 'descr' => $core->lang['user_work_d'], 'value' => $work), array('type' => 'select', 'name' => 'comp', 'head' => $core->lang['company'], 'value' => $comp), array('type' => 'select', 'name' => 'ext', 'head' => $core->lang['agency'], 'value' => $ext), array('type' => 'checkbox', 'name' => 'compad', 'head' => $core->lang['user_compad'], 'descr' => $core->lang['user_compad_d'], 'checked' => $user['user_compad']), array('type' => 'checkbox', 'name' => 'call', 'head' => $core->lang['user_call'], 'descr' => $core->lang['user_call_d'], 'checked' => $user['user_call']), array('type' => 'checkbox', 'name' => 'shave', 'head' => $core->lang['user_shave'], 'descr' => $core->lang['user_shave_d'], 'checked' => $user['user_shave']), array('type' => 'text', 'length' => 5, 'name' => 'tariff', 'head' => $core->lang['tariff'], 'value' => $user['user_tariff']), array('type' => 'text', 'length' => 7, 'name' => 'money', 'head' => $core->lang['user_money'], 'descr' => $core->lang['user_money_d']));
                $button = array(array('type' => 'submit', 'value' => $core->lang['save']));
                $core->form('useredit', $action, $method, $title, $field, $button);
                $core->footer();
            } else {
                $today = date('Ymd');
                $m1m = date('Ymd', strtotime('-2 weeks'));
                $m2m = date('Ymd', strtotime('-1 months'));
                $where = array();
                if (isset($core->get['s']) && $core->get['s']) {
                    require_once PATH_CORE . 'search.php';
                    $search = new SearchWords($core->get['s']);
                    if ($s = $search->get()) {
                        $where[] = $search->field(array('user_name', 'user_mail'));
                    } else {
                        $s = false;
                    }
                } else {
                    $s = false;
                }
                if (isset($core->get['c']) && $core->get['c']) {
                    $c = (int) $core->get['c'];
                    $where[] = "user_comp = '{$c}'";
                } else {
                    $c = false;
                }
                if (isset($core->get['l']) && $core->get['l'] != '') {
                    $l = (int) $core->get['l'];
                    $where[] = "user_work = '{$l}'";
                } else {
                    $l = null;
                }
                $where = count($where) ? implode(' AND ', $where) : '1';
                $sh = 30;
                $st = $sh * ($page - 1);
                $users = $core->db->field("SELECT COUNT(*) FROM " . DB_USER . " WHERE {$where}");
                $user = $users ? $core->db->data("SELECT * FROM " . DB_USER . " WHERE {$where} ORDER BY user_work DESC, user_id ASC LIMIT {$st}, {$sh}") : array();
                $comp = $core->wmsale->get('comps');
                $ext = $core->wmsale->get('exts');
                $core->mainline->add($core->lang['admin_user_h'], $core->url('m', 'users'));
                $core->header();
                $core->tpl->load('body', 'users');
                $core->tpl->vars('body', array('title' => $core->lang['admin_user_h'], 'text' => $core->text->lines($core->lang['admin_user_t']), 'name' => $core->lang['user'], 'email' => $core->lang['email'], 'vip' => $core->lang['iamvip'], 'level' => $core->lang['level'], 'comp' => $core->lang['company'], 'name' => $core->lang['user'], 'info' => $core->lang['cash'], 'action' => $core->lang['action'], 'enter' => $core->lang['enter'], 'edit' => $core->lang['edit'], 'del' => $core->lang['del'], 'confirm' => $core->lang['confirm'], 's' => $s, 'pages' => pages($core->url('m', 'users?') . ($c ? 'c=' . $c . '&' : '') . ($l !== null ? 'l=' . $l . '&' : '') . ($s ? 's=' . $s : ''), $users, $sh, $page), 'shown' => sprintf($core->lang['shown'], $st + 1, min($st + $sh, $users), $users), 'search' => $core->lang['search'], 'find' => $core->lang['find']));
                foreach ($comp as $ci => $cn) {
                    $core->tpl->block('body', 'comp', array('name' => $cn, 'value' => $ci, 'select' => $c == $ci ? 'selected="selected"' : ''));
                }
                foreach ($core->lang['user_works'] as $li => $ln) {
                    $core->tpl->block('body', 'level', array('name' => $ln, 'value' => $li, 'select' => $l !== null && $l == $li ? 'selected="selected"' : ''));
                }
                foreach ($user as &$i) {
                    $key = $i['user_id'] . md5(crypto::encode($i['user_mail'] . $i['user_pass'], $core->crypto));
                    $core->tpl->block('body', 'user', array('id' => $i['user_id'], 'name' => $search ? $search->highlight($i['user_name']) : $i['user_name'], 'email' => $search ? $search->highlight($i['user_mail']) : $i['user_mail'], 'mailto' => $i['user_mail'], 'vip' => $i['user_vip'] ? $core->lang['iamvip'] : '', 'level' => $i['user_level'] ? '<b class="boss" title="' . $core->lang['admin'] . '">' . $core->lang['user_works'][$i['user_work']] . '</b>' : $core->lang['user_works'][$i['user_work']], 'icon' => $i['user_ban'] ? 'block' : ($i['user_warn'] ? 'isua' : 'isok'), 'u_level' => $core->url('m', 'users?l=') . $i['user_work'] . ($c ? '&c=' . $c : '') . ($s ? '&s=' . $s : ''), 'enter' => sprintf($i['user_ref'] == 119 || $i['user_sub'] == 119 || $i['user_id'] == 119 ? $core->lang['mail_recover_r'] : $core->lang['mail_recover_u'], $key), 'cash' => rur($i['user_cash']), 'flw' => (int) $i['user_flw'], 'flwa' => (int) $i['user_flwa'], 'cr' => $i['user_cr'] < 10 ? sprintf("%0.2f", $i['user_cr']) : sprintf("%0.1f", $i['user_cr']), 'crc' => $i['user_cr'] < 10 ? $i['user_cr'] < 5 ? 'green' : 'yellow' : ($i['user_cr'] > 20 ? 'red fat' : 'red'), 'epc' => rur($i['user_epc']), 'comp' => $i['user_comp'] ? $i['user_compad'] ? '<b class="boss" title="' . $core->lang['admin'] . '">' . $comp[$i['user_comp']] . '</b>' : $comp[$i['user_comp']] : ($i['user_ref'] ? $core->user->get($i['user_ref'], 'user_name') : $ext[$i['user_ext']]), 'sclass' => $i['supp_last'] ? $i['supp_admin'] ? 'suppst-new' : ($i['supp_type'] ? $i['supp_new'] ? 'suppst-ur' : 'suppst-ok' : 'suppst-ua') : 'help', 'u_comp' => $core->url('m', 'users?c=') . $i['user_comp'] . ($l !== null ? '&l=' . $l : '') . ($s ? '&s=' . $s : ''), 'support' => $core->url('i', 'support', $i['user_id']), 'orders' => $core->url('m', 'order') . '?wm=' . $i['user_id'], 'url' => $core->url('i', 'users', $i['user_id']), 'edit' => $core->url('i', 'users', $i['user_id']), 'del' => $core->url('a', 'user-del', $i['user_id']), 'ip' => $i['user_ip'] ? int2ip($i['user_ip']) : '', 'date' => $i['user_date'] ? date2form($i['user_date']) : '', 'dclass' => $i['user_date'] == $today ? 'fat green' : ($i['user_date'] < $m1m ? $i['user_date'] < $m2m ? 'red' : 'yellow' : '')));
                }
                unset($d);
                $core->tpl->output('body');
                $title = $core->lang['user_add'];
                $action = $core->url('a', 'user-add', 0);
                $method = 'post';
                $field = array(array('type' => 'text', 'length' => 100, 'name' => 'name', 'head' => $core->lang['user_name'], 'descr' => $core->lang['user_name_d']), array('type' => 'text', 'length' => 100, 'name' => 'email', 'head' => $core->lang['user_email'], 'descr' => $core->lang['user_email_d']), array('type' => 'pass', 'length' => 32, 'name' => 'pass', 'head' => $core->lang['user_pass'], 'descr' => $core->lang['user_pass_d']));
                $button = array(array('type' => 'submit', 'value' => $core->lang['save']));
                $core->form('useradd', $action, $method, $title, $field, $button);
                $core->footer('admin');
            }
            $core->_die();
            // Offers
        // Offers
        case 'offer':
            switch ($message) {
                case 'add-ok':
                    $core->info('info', 'done_offer_add');
                    break;
                case 'edit-ok':
                    $core->info('info', 'done_offer_edit');
                    break;
                case 'del-ok':
                    $core->info('info', 'done_offer_del');
                    break;
                case 'add-e':
                    $core->info('error', 'error_offer_add');
                    break;
                case 'edit-e':
                    $core->info('error', 'error_offer_edit');
                    break;
                case 'del-e':
                    $core->info('error', 'error_offer_del');
                    break;
            }
            if ($id) {
                $offer = $core->db->row("SELECT * FROM " . DB_OFFER . " WHERE offer_id = '{$id}' LIMIT 1");
                $mrt = $offer['offer_mrt'] ? unserialize($offer['offer_mrt']) : array();
                $comps = $core->wmsale->get('comps');
                $payment = array();
                foreach ($core->lang['offer_payments'] as $v => $n) {
                    $payment[] = array('name' => $n, 'value' => $v, 'select' => $v == $offer['offer_payment']);
                }
                $core->mainline->add($core->lang['offers_h'], $core->url('m', 'offer'));
                $core->mainline->add($offer['offer_name']);
                $core->header();
                $title = $core->lang['offer_edit_h'];
                $action = $core->url('a', 'offer-edit', $id);
                $method = 'post';
                $field = array(array('type' => 'line', 'value' => $core->text->lines($core->lang['offer_edit_t'])), array('type' => 'text', 'length' => 100, 'name' => 'name', 'head' => $core->lang['name'], 'value' => $offer['offer_name']), array('type' => 'text', 'length' => 200, 'name' => 'descr', 'head' => $core->lang['offer_descr'], 'descr' => $core->lang['offer_descr_d'], 'value' => $offer['offer_descr']), array('type' => 'textarea', 'rows' => 4, 'name' => 'text', 'head' => $core->lang['offer_text'], 'descr' => $core->lang['offer_text_d'], 'value' => $offer['offer_text']), array('type' => 'mces', 'name' => 'info', 'head' => $core->lang['offer_info'], 'descr' => $core->lang['offer_info_d'], 'value' => $offer['offer_info']), array('type' => 'text', 'length' => 100, 'name' => 'price', 'head' => $core->lang['price'], 'value' => $offer['offer_price']), array('type' => 'file', 'name' => 'image', 'head' => $core->lang['logo'], 'descr' => 'JPEG 320x180px'), array('type' => 'text', 'length' => 100, 'name' => 'country', 'head' => $core->lang['offer_country'], 'descr' => $core->lang['offer_country_d'], 'value' => $offer['offer_country']), array('type' => 'checkbox', 'name' => 'active', 'head' => $core->lang['active'], 'descr' => $core->lang['offer_active_d'], 'checked' => $offer['offer_active']), array('type' => 'checkbox', 'name' => 'vars', 'head' => $core->lang['offer_vars'], 'descr' => $core->lang['offer_vars_d'], 'checked' => $offer['offer_vars']), array('type' => 'checkbox', 'name' => 'delivery', 'head' => $core->lang['offer_delivery'], 'descr' => $core->lang['offer_delivery_d'], 'checked' => $offer['offer_delivery']), array('type' => 'select', 'name' => 'payment', 'head' => $core->lang['offer_payment'], 'descr' => $core->lang['offer_payment_d'], 'value' => $payment), array('type' => 'head', 'value' => $core->lang['offer_mr_h']), array('type' => 'checkbox', 'name' => 'mr', 'head' => $core->lang['offer_mr'], 'descr' => $core->lang['offer_mr_d'], 'checked' => $offer['offer_mr']), array('type' => 'textarea', 'rows' => 4, 'name' => 'script', 'head' => $core->lang['offer_script'], 'descr' => $core->lang['offer_script_d'], 'value' => $offer['offer_script']));
                foreach ($comps as $i => $n) {
                    $field[] = array('type' => 'text', 'name' => "mrt[{$i}]", 'head' => $n, 'descr' => $core->lang['offer_mrt_d'], 'value' => $mrt[$i]);
                }
                $button = array(array('type' => 'submit', 'value' => $core->lang['save']));
                $core->form('offeredit', $action, $method, $title, $field, $button);
                $core->footer();
            } else {
                $offer = $core->db->data("SELECT * FROM " . DB_OFFER . " ORDER BY offer_name ASC");
                $core->mainline->add($core->lang['offers_h'], $core->url('m', 'offer'));
                $core->header();
                $core->tpl->load('body', 'safelist');
                $core->tpl->vars('body', array('title' => $core->lang['offers_h'], 'text' => $core->text->lines($core->lang['offers_t']), 'name' => $core->lang['name'], 'info' => $core->lang['price'], 'action' => $core->lang['action'], 'edit' => $core->lang['edit'], 'del' => $core->lang['del'], 'confirm' => $core->lang['confirms']));
                foreach ($offer as &$i) {
                    $act = $i['offer_active'] ? '<span class="icon sm rf isok"></span>' : '';
                    $core->tpl->block('body', 'item', array('id' => $i['offer_id'], 'name' => $i['offer_name'], 'more' => $act . '<small>' . rur($i['offer_price']) . '</small>', 'info' => ($i['offer_vars'] ? '<a href="' . $core->url('i', 'offer-vars', $i['offer_id']) . '" class="variant">' . $core->lang['variants'] . '</a>' : '') . ' <a href="' . $core->url('i', 'offer-price', $i['offer_id']) . '" class="money">' . $core->lang['price'] . '</a> <a href="' . $core->url('i', 'offer-pars', $i['offer_id']) . '" class="param">' . $core->lang['params'] . '</a>', 'url' => $core->url('i', 'offer-sites', $i['offer_id']), 'edit' => $core->url('i', 'offer', $i['offer_id']), 'del' => $core->url('a', 'offer-del', $i['offer_id'])));
                }
                unset($d);
                $core->tpl->output('body');
                $title = $core->lang['offer_add_h'];
                $action = $core->url('a', 'offer-add', 0);
                $method = 'post';
                $field = array(array('type' => 'line', 'value' => $core->text->lines($core->lang['offer_add_t'])), array('type' => 'text', 'length' => 100, 'name' => 'name', 'head' => $core->lang['name']), array('type' => 'text', 'length' => 32, 'name' => 'price', 'head' => $core->lang['price']));
                $button = array(array('type' => 'submit', 'value' => $core->lang['create']));
                $core->form('offeradd', $action, $method, $title, $field, $button);
                $core->footer('admin');
            }
            $core->_die();
        case 'offer-price':
            if (!$id) {
                $core->go($core->url('m', 'offer'));
            }
            $offer = $core->db->row("SELECT * FROM " . DB_OFFER . " WHERE offer_id = '{$id}' LIMIT 1");
            $prices = unserialize($offer['offer_prt']);
            $core->mainline->add($core->lang['offers_h'], $core->url('m', 'offer'));
            $core->mainline->add(sprintf($core->lang['offer_price_h'], $offer['offer_name']));
            $core->header();
            $core->tpl->load('body', 'price');
            $core->tpl->vars('body', array('title' => sprintf($core->lang['offer_price_h'], $offer['offer_name']), 'u_save' => $core->url('a', 'offer-price', $id), 'save' => $core->lang['save']));
            $core->tpl->block('body', 'type', array('name' => $core->lang['offer_prices_base']));
            $core->tpl->block('body', 'type.price', array('name' => $core->lang['offer_price_main'], 'wmn' => 'wmb', 'wmv' => $offer['offer_wm'] ? $offer['offer_wm'] : '', 'wmun' => 'wmub', 'wmuv' => $offer['offer_wmu'] ? $offer['offer_wmu'] : '', 'payn' => 'payb', 'payv' => $offer['offer_pay'] ? $offer['offer_pay'] : '', 'pyun' => 'pyub', 'pyuv' => $offer['offer_pyu'] ? $offer['offer_pyu'] : '', 'refn' => 'refb', 'refv' => $offer['offer_ref'] ? $offer['offer_ref'] : ''));
            $core->tpl->block('body', 'type.price.ref');
            $core->tpl->block('body', 'type.price', array('name' => $core->lang['offer_price_vip'], 'wmn' => 'wmv', 'wmv' => $offer['offer_wm_vip'] ? $offer['offer_wm_vip'] : '', 'wmun' => 'wmuv', 'wmuv' => $offer['offer_wmu_vip'] ? $offer['offer_wmu_vip'] : '', 'payn' => 'payv', 'payv' => $offer['offer_pay_vip'] ? $offer['offer_pay_vip'] : '', 'pyun' => 'pyuv', 'pyuv' => $offer['offer_pyu_vip'] ? $offer['offer_pyu_vip'] : '', 'refn' => 'refv', 'refv' => $offer['offer_ref_vip'] ? $offer['offer_ref_vip'] : ''));
            $core->tpl->block('body', 'type.price.ref');
            $core->tpl->block('body', 'type.price', array('name' => $core->lang['offer_price_ext'], 'cls' => 'dark', 'wmn' => 'wme', 'wmv' => $offer['offer_wm_ext'] ? $offer['offer_wm_ext'] : '', 'wmun' => 'wmue', 'wmuv' => $offer['offer_wmu_ext'] ? $offer['offer_wmu_ext'] : '', 'payn' => 'paye', 'payv' => $offer['offer_pay_ext'] ? $offer['offer_pay_ext'] : '', 'pyun' => 'pyue', 'pyuv' => $offer['offer_pyu_ext'] ? $offer['offer_pyu_ext'] : ''));
            $comps = $core->wmsale->get('comps');
            if ($comps) {
                $core->tpl->block('body', 'type', array('name' => $core->lang['offer_prices_comp']));
                foreach ($comps as $i => $c) {
                    $uc = $core->wmsale->get('comp', $i, 'user_id');
                    $core->tpl->block('body', 'type.price', array('name' => $c, 'wmn' => "wm[{$uc}]", 'wmv' => $prices[$uc][0] ? $prices[$uc][0] : '', 'wmun' => "wmu[{$uc}]", 'wmuv' => $prices[$uc][3] ? $prices[$uc][3] : '', 'payn' => "pay[{$uc}]", 'payv' => $prices[$uc][1] ? $prices[$uc][1] : '', 'pyun' => "pyu[{$uc}]", 'pyuv' => $prices[$uc][4] ? $prices[$uc][4] : '', 'refn' => "ref[{$uc}]", 'refv' => $prices[$uc][2] ? $prices[$uc][2] : ''));
                    $core->tpl->block('body', 'type.price.ref');
                }
            }
            $exts = $core->wmsale->get('exts');
            if ($exts) {
                $core->tpl->block('body', 'type', array('name' => $core->lang['offer_prices_ext']));
                foreach ($exts as $i => $c) {
                    $uc = $core->wmsale->get('ext', $i, 'user_id');
                    $core->tpl->block('body', 'type.price', array('name' => $c, 'cls' => 'dark', 'wmn' => "wm[{$uc}]", 'wmv' => $prices[$uc][0] ? $prices[$uc][0] : '', 'wmun' => "wmu[{$uc}]", 'wmuv' => $prices[$uc][3] ? $prices[$uc][3] : '', 'payn' => "pay[{$uc}]", 'payv' => $prices[$uc][1] ? $prices[$uc][1] : '', 'pyun' => "pyu[{$uc}]", 'pyuv' => $prices[$uc][4] ? $prices[$uc][4] : ''));
                }
            }
            $refs = $core->db->icol("SELECT user_id, user_name FROM " . DB_USER . " WHERE user_work = -2 ORDER BY user_name ASC");
            if ($refs) {
                $core->tpl->block('body', 'type', array('name' => $core->lang['offer_prices_ref']));
                foreach ($refs as $uc => $c) {
                    $core->tpl->block('body', 'type.price', array('name' => $c, 'wmn' => "wm[{$uc}]", 'wmv' => $prices[$uc][0] ? $prices[$uc][0] : '', 'wmun' => "wmu[{$uc}]", 'wmuv' => $prices[$uc][3] ? $prices[$uc][3] : '', 'payn' => "pay[{$uc}]", 'payv' => $prices[$uc][1] ? $prices[$uc][1] : '', 'pyun' => "pyu[{$uc}]", 'pyuv' => $prices[$uc][4] ? $prices[$uc][4] : '', 'refn' => "ref[{$uc}]", 'refv' => $prices[$uc][2] ? $prices[$uc][2] : ''));
                    $core->tpl->block('body', 'type.price.ref');
                }
            }
            $vips = $core->db->icol("SELECT user_id, user_name FROM " . DB_USER . " WHERE user_vip = 1 AND user_work IN ( 0, 2 ) ORDER BY user_name ASC");
            if ($vips) {
                $core->tpl->block('body', 'type', array('name' => $core->lang['offer_prices_vip']));
                foreach ($vips as $uc => $c) {
                    $core->tpl->block('body', 'type.price', array('name' => $c, 'wmn' => "wm[{$uc}]", 'wmv' => $prices[$uc][0] ? $prices[$uc][0] : '', 'wmun' => "wmu[{$uc}]", 'wmuv' => $prices[$uc][3] ? $prices[$uc][3] : '', 'payn' => "pay[{$uc}]", 'payv' => $prices[$uc][1] ? $prices[$uc][1] : '', 'pyun' => "pyu[{$uc}]", 'pyuv' => $prices[$uc][4] ? $prices[$uc][4] : '', 'refn' => "ref[{$uc}]", 'refv' => $prices[$uc][2] ? $prices[$uc][2] : ''));
                    $core->tpl->block('body', 'type.price.ref');
                }
            }
            $core->tpl->output('body');
            $core->footer();
            $core->_die();
        case 'offer-pars':
            if (!$id) {
                $core->go($core->url('m', 'offer'));
            }
            $offer = $core->db->row("SELECT * FROM " . DB_OFFER . " WHERE offer_id = '{$id}' LIMIT 1");
            $pars = unserialize($offer['offer_pars']);
            $core->mainline->add($core->lang['offers_h'], $core->url('m', 'offer'));
            $core->mainline->add(sprintf($core->lang['offer_pars_h'], $offer['offer_name']));
            $core->header();
            $core->tpl->load('body', 'param');
            $core->tpl->vars('body', array('title' => sprintf($core->lang['offer_pars_h'], $offer['offer_name']), 'u_save' => $core->url('a', 'offer-param', $id), 'shave' => $pars['shave'] ? $pars['shave'] : '', 'save' => $core->lang['save']));
            $i = 1;
            foreach ($pars as $k => $v) {
                if (substr($k, 0, 5) != 'shave') {
                    $core->tpl->block('body', 'param', array('id' => $i, 'name' => $k, 'val' => $v ? $v : ''));
                    $i++;
                }
            }
            $i = 111;
            $comps = $core->wmsale->get('comps');
            foreach ($comps as $n => $c) {
                $core->tpl->block('body', 'shave', array('id' => $i, 'name' => $c, 'param' => 'shave' . $n, 'val' => $pars['shave' . $n] ? $pars['shave' . $n] : ''));
                $i++;
            }
            $core->tpl->output('body');
            $core->footer();
            $core->_die();
        case 'offer-vars':
            switch ($message) {
                case 'edit-ok':
                    $core->info('info', 'done_offer_var_edit');
                    break;
                case 'del-ok':
                    $core->info('info', 'done_offer_var_del');
                    break;
                case 'add-e':
                    $core->info('error', 'error_offer_var_add');
                    break;
                case 'edit-e':
                    $core->info('error', 'error_offer_var_edit');
                    break;
                case 'del-e':
                    $core->info('error', 'error_offer_var_del');
                    break;
            }
            if (!$id) {
                $core->go($core->url('m', 'offer'));
            }
            $offer = $core->db->row("SELECT * FROM " . DB_OFFER . " WHERE offer_id = '{$id}' LIMIT 1");
            if (!$offer['offer_vars']) {
                $core->go($core->url('m', 'offer'));
            }
            $vars = $core->db->data("SELECT * FROM " . DB_VARS . " WHERE offer_id = '{$id}' ORDER BY var_name ASC");
            $core->mainline->add($core->lang['offers_h'], $core->url('m', 'offer'));
            $core->mainline->add(sprintf($core->lang['offer_vars_h'], $offer['offer_name']));
            $core->header();
            $core->tpl->load('body', 'list');
            $core->tpl->vars('body', array('title' => sprintf($core->lang['offer_vars_h'], $offer['offer_name']), 'text' => $core->text->lines($core->lang['offer_vars_t']), 'name' => $core->lang['name'], 'info' => $core->lang['price'], 'action' => $core->lang['action'], 'edit' => $core->lang['edit'], 'del' => $core->lang['del'], 'confirm' => $core->lang['confirm']));
            foreach ($vars as &$i) {
                $core->tpl->block('body', 'item', array('id' => $i['var_id'], 'name' => $i['var_name'], 'info' => rur($i['var_price']), 'url' => $core->url('i', 'offer-var', $i['var_id']), 'edit' => $core->url('i', 'offer-var', $i['var_id']), 'del' => $core->url('a', 'offer-var-del', $i['var_id'])));
            }
            unset($d);
            $core->tpl->output('body');
            $title = $core->lang['offer_var_add_h'];
            $action = $core->url('a', 'offer-var-add', $id);
            $method = 'post';
            $field = array(array('type' => 'line', 'value' => $core->text->lines($core->lang['offer_var_add_t'])), array('type' => 'text', 'length' => 100, 'name' => 'name', 'head' => $core->lang['name']), array('type' => 'text', 'length' => 32, 'name' => 'price', 'head' => $core->lang['price']));
            $button = array(array('type' => 'submit', 'value' => $core->lang['create']));
            $core->form('offervaradd', $action, $method, $title, $field, $button);
            $core->footer();
            $core->_die();
        case 'offer-var':
            switch ($message) {
                case 'add-ok':
                    $core->info('info', 'done_offer_var_add');
                    break;
                case 'add-e':
                    $core->info('error', 'error_offer_var_add');
                    break;
            }
            if (!$id) {
                $core->go($core->url('m', 'offer'));
            }
            $vari = $core->db->row("SELECT * FROM " . DB_VARS . " WHERE var_id = '{$id}' LIMIT 1");
            $offer = $core->db->row("SELECT * FROM " . DB_OFFER . " WHERE offer_id = '" . $vari['offer_id'] . "' LIMIT 1");
            $core->mainline->add($core->lang['offers_h'], $core->url('m', 'offer'));
            $core->mainline->add(sprintf($core->lang['offer_vars_h'], $offer['offer_name']), $core->url('i', 'offer-vars', $offer['offer_id']));
            $core->mainline->add($vari['var_name']);
            $core->header();
            $title = $core->lang['offer_var_edit_h'];
            $action = $core->url('a', 'offer-var-edit', $id);
            $method = 'post';
            $field = array(array('type' => 'line', 'value' => $core->text->lines($core->lang['offer_var_edit_t'])), array('type' => 'text', 'length' => 100, 'name' => 'name', 'head' => $core->lang['name'], 'value' => $vari['var_name']), array('type' => 'text', 'length' => 100, 'name' => 'short', 'head' => $core->lang['offer_short'], 'descr' => $core->lang['offer_short_d'], 'value' => $vari['var_short']), array('type' => 'text', 'length' => 10, 'name' => 'price', 'head' => $core->lang['price'], 'value' => $vari['var_price']));
            $button = array(array('type' => 'submit', 'value' => $core->lang['save']));
            $core->form('offeredit', $action, $method, $title, $field, $button);
            $core->footer();
            $core->_die();
        case 'offer-sites':
            switch ($message) {
                case 'edit-ok':
                    $core->info('info', 'done_offer_site_edit');
                    break;
                case 'del-ok':
                    $core->info('info', 'done_offer_site_del');
                    break;
                case 'add-e':
                    $core->info('error', 'error_offer_site_add');
                    break;
                case 'edit-e':
                    $core->info('error', 'error_offer_site_edit');
                    break;
                case 'del-e':
                    $core->info('error', 'error_offer_site_del');
                    break;
            }
            if (!$id) {
                $core->go($core->url('m', 'offer'));
            }
            $offer = $core->wmsale->get('offer', $id);
            $comp = $core->wmsale->get('comps');
            $sites = $core->db->data("SELECT * FROM " . DB_SITE . " WHERE offer_id = '{$id}' ORDER BY site_type, site_url ASC");
            $core->mainline->add($core->lang['offers_h'], $core->url('m', 'offer'));
            $core->mainline->add(sprintf($core->lang['offer_sites_h'], $offer['offer_name']));
            $core->header();
            $core->tpl->load('body', 'list');
            $core->tpl->vars('body', array('title' => sprintf($core->lang['offer_sites_h'], $offer['offer_name']), 'text' => $core->text->lines(sprintf($core->lang['offer_sites_t'], $core->url('a', 'offer-site-list', $id), $core->url('a', 'offer-site-renew', $id))), 'name' => $core->lang['name'], 'info' => $core->lang['company'], 'action' => $core->lang['action'], 'edit' => $core->lang['edit'], 'del' => $core->lang['del'], 'confirm' => $core->lang['confirm']));
            foreach ($sites as &$i) {
                $act = $i['site_default'] ? '<span class="icon sm rf isok"></span>' : '';
                $core->tpl->block('body', 'item', array('id' => $i['site_id'], 'name' => $i['site_url'], 'more' => $act . sprintf('<small>(<a target="_blank" href="http://%s/">%s</a>)</small>', $i['site_url'], $core->lang['site_types'][$i['site_type']]), 'info' => $comp[$i['comp_id']], 'url' => $core->url('i', 'offer-site', $i['site_id']), 'edit' => $core->url('i', 'offer-site', $i['site_id']), 'del' => $core->url('a', 'offer-site-del', $i['site_id'])));
            }
            unset($d);
            $core->tpl->output('body');
            $title = $core->lang['offer_site_add_h'];
            $action = $core->url('a', 'offer-site-add', $id);
            $method = 'post';
            $field = array(array('type' => 'line', 'value' => $core->text->lines($core->lang['offer_site_add_t'])), array('type' => 'text', 'length' => 100, 'name' => 'url', 'head' => $core->lang['offer_url'], 'descr' => $core->lang['offer_url_d']));
            $button = array(array('type' => 'submit', 'value' => $core->lang['create']));
            $core->form('offersiteadd', $action, $method, $title, $field, $button);
            $core->footer();
            $core->_die();
        case 'offer-site':
            switch ($message) {
                case 'add-ok':
                    $core->info('info', 'done_offer_site_add');
                    break;
                case 'add-e':
                    $core->info('error', 'error_offer_site_add');
                    break;
            }
            if (!$id) {
                $core->go($core->url('m', 'offer'));
            }
            $site = $core->wmsale->get('site', $id);
            $offer = $core->wmsale->get('offer', $site['offer_id']);
            $comps = $core->wmsale->get('comps');
            $core->mainline->add($core->lang['offers_h'], $core->url('m', 'offer'));
            $core->mainline->add(sprintf($core->lang['offer_sites_h'], $offer['offer_name']), $core->url('i', 'offer-sites', $offer['offer_id']));
            $core->mainline->add($site['site_url']);
            $core->header();
            $comp = array();
            foreach ($comps as $cv => $cn) {
                $comp[] = array('name' => $cn, 'value' => $cv, 'select' => $cv == $site['comp_id']);
            }
            $mobs = array();
            foreach ($core->lang['site_mobiles'] as $mi => $mv) {
                $mobs[] = array('name' => $mv, 'value' => $mi, 'select' => $mi == $site['site_mobile']);
            }
            $title = $core->lang['offer_site_edit_h'];
            $action = $core->url('a', 'offer-site-edit', $id);
            $method = 'post';
            $field = array(array('type' => 'line', 'value' => $core->text->lines($core->lang['offer_site_edit_t'])), array('type' => 'text', 'length' => 100, 'name' => 'url', 'head' => $core->lang['offer_url'], 'descr' => $core->lang['offer_url_d'], 'value' => $site['site_url']), array('type' => 'text', 'length' => 100, 'name' => 'key', 'head' => $core->lang['offer_key'], 'descr' => $core->lang['offer_key_d'], 'value' => $site['site_key']), array('type' => 'select', 'name' => 'comp', 'head' => $core->lang['company'], 'value' => $comp), array('type' => 'select', 'name' => 'mobile', 'head' => $core->lang['site_mobile'], 'descr' => $core->lang['site_mobile_d'], 'value' => $mobs), array('type' => 'checkbox', 'name' => 'type', 'head' => $core->lang['site_type'], 'descr' => $core->lang['site_type_d'], 'checked' => $site['site_type']), array('type' => 'checkbox', 'name' => 'default', 'head' => $core->lang['site_default'], 'descr' => $core->lang['site_default_d'], 'checked' => $site['site_default']), array('type' => 'checkbox', 'name' => 'comph', 'head' => $core->lang['site_comp'], 'descr' => $core->lang['site_comp_d'], 'checked' => $site['site_comp']));
            $button = array(array('type' => 'submit', 'value' => $core->lang['save']));
            $core->form('offeredit', $action, $method, $title, $field, $button);
            $core->footer();
            $core->_die();
        case 'integration':
            if ($id) {
                $comp = $core->wmsale->get('comp', $id);
                $flds = unserialize($comp['int_add_field']);
                $fld = '';
                if ($flds) {
                    foreach ($flds as $k => $v) {
                        $fld .= "{$k} {$v}\n";
                    }
                }
                $fld = trim($fld);
                $flds2 = unserialize($comp['int_chk_field']);
                $fld2 = '';
                if ($flds2) {
                    foreach ($flds2 as $k => $v) {
                        $fld2 .= "{$k} {$v}\n";
                    }
                }
                $fld2 = trim($fld2);
                $format = array();
                foreach ($core->lang['comp_int_formats'] as $v => $n) {
                    $format[] = array('name' => $n, 'value' => $v, 'select' => $v == $comp['int_chk_format']);
                }
                $core->mainline->add($core->lang['admin_comp_h'], $core->url('m', 'comps'));
                $core->mainline->add($comp['comp_name']);
                $core->header();
                $title = $core->lang['comp_int_h'];
                $action = $core->url('a', 'comps-int', $id);
                $method = 'post';
                $field = array(array('type' => 'line', 'value' => $core->text->lines($core->lang['comp_int_t'])), array('type' => 'checkbox', 'name' => 'add', 'head' => $core->lang['comp_int_add'], 'descr' => $core->lang['comp_int_add_d'], 'checked' => $comp['int_add']), array('type' => 'text', 'length' => 200, 'name' => 'add_url', 'head' => $core->lang['comp_int_add_url'], 'descr' => $core->lang['comp_int_add_url_d'], 'value' => htmlspecialchars($comp['int_add_url'])), array('type' => 'code', 'name' => 'add_pre', 'head' => $core->lang['comp_int_pre'], 'value' => $comp['int_add_pre']), array('type' => 'textarea', 'rows' => 5, 'name' => 'add_field', 'head' => $core->lang['comp_int_add_field'], 'descr' => $core->lang['comp_int_add_field_d'], 'value' => $fld), array('type' => 'code', 'lang' => 'javascript', 'name' => 'add_code', 'head' => $core->lang['comp_int_add_code'], 'descr' => $core->lang['comp_int_add_code_d'], 'value' => $comp['int_add_code']), array('type' => 'checkbox', 'name' => 'chk', 'head' => $core->lang['comp_int_chk'], 'descr' => $core->lang['comp_int_chk_d'], 'checked' => $comp['int_chk']), array('type' => 'text', 'length' => 200, 'name' => 'chk_url', 'head' => $core->lang['comp_int_chk_url'], 'descr' => $core->lang['comp_int_chk_url_d'], 'value' => htmlspecialchars($comp['int_chk_url'])), array('type' => 'code', 'name' => 'chk_pre', 'head' => $core->lang['comp_int_pre'], 'value' => $comp['int_chk_pre']), array('type' => 'textarea', 'rows' => 5, 'name' => 'chk_field', 'head' => $core->lang['comp_int_chk_field'], 'descr' => $core->lang['comp_int_chk_field_d'], 'value' => $fld2), array('type' => 'text', 'length' => 5, 'name' => 'chk_count', 'head' => $core->lang['comp_int_chk_count'], 'descr' => $core->lang['comp_int_chk_count_d'], 'value' => $comp['int_chk_count']), array('type' => 'select', 'name' => 'chk_format', 'head' => $core->lang['comp_int_chk_format'], 'value' => $format), array('type' => 'code', 'lang' => 'javascript', 'name' => 'chk_code', 'head' => $core->lang['comp_int_chk_code'], 'descr' => $core->lang['comp_int_chk_code_d'], 'value' => $comp['int_chk_code']));
                $button = array(array('type' => 'submit', 'value' => $core->lang['save']));
                $core->form('integrate', $action, $method, $title, $field, $button);
                $core->footer();
                $core->_die();
            }
        case 'comps':
            switch ($message) {
                case 'add-ok':
                    $core->info('info', 'done_comps_add');
                    break;
                case 'edit-ok':
                    $core->info('info', 'done_comps_edit');
                    break;
                case 'del-ok':
                    $core->info('info', 'done_comps_del');
                    break;
                case 'add-e':
                    $core->info('error', 'error_comps_add');
                    break;
                case 'edit-e':
                    $core->info('error', 'error_comps_edit');
                    break;
                case 'del-e':
                    $core->info('error', 'error_comps_del');
                    break;
                case 'del-a':
                    $core->info('error', 'error_comps_root');
                    break;
            }
            if ($id) {
                $comp = $core->db->row("SELECT * FROM " . DB_COMP . " WHERE comp_id = '{$id}' LIMIT 1");
                $user = array(array('name' => '&mdash; ' . $core->lang['comp_free'] . ' &mdash;', 'value' => 0));
                $users = $core->db->icol("SELECT user_id, user_name FROM " . DB_USER . " WHERE user_comp = '{$id}' AND user_compad = 1 ORDER BY user_name ASC");
                foreach ($users as $u => $n) {
                    $user[] = array('name' => $n, 'value' => $u, 'select' => $u == $comp['user_id']);
                }
                $core->mainline->add($core->lang['admin_comp_h'], $core->url('m', 'comps'));
                $core->mainline->add($comp['comp_name']);
                $core->header();
                $title = $core->lang['comp_edit'];
                $action = $core->url('a', 'comps-edit', $id);
                $method = 'post';
                $field = array(array('type' => 'line', 'value' => $core->text->lines($core->lang['comp_info_t'])), array('type' => 'select', 'name' => 'user', 'head' => $core->lang['comp_user'], 'descr' => $core->lang['comp_user_d'], 'value' => $user), array('type' => 'text', 'length' => 100, 'name' => 'name', 'head' => $core->lang['name'], 'value' => $comp['comp_name']), array('type' => 'text', 'length' => 100, 'name' => 'fio', 'head' => $core->lang['comp_name'], 'descr' => $core->lang['comp_name_d'], 'value' => $comp['comp_fio']), array('type' => 'text', 'length' => 100, 'name' => 'phone', 'head' => $core->lang['phone'], 'value' => $comp['comp_phone']), array('type' => 'text', 'length' => 100, 'name' => 'addr', 'head' => $core->lang['address'], 'descr' => $core->lang['comp_addr_d'], 'value' => $comp['comp_addr']), array('type' => 'text', 'length' => 8, 'name' => 'index', 'head' => $core->lang['index'], 'descr' => $core->lang['comp_index_d'], 'value' => $comp['comp_index']), array('type' => 'head', 'value' => $core->lang['comp_banking']), array('type' => 'text', 'length' => 100, 'name' => 'bank', 'head' => $core->lang['comp_bank'], 'descr' => $core->lang['comp_bank_d'], 'value' => $comp['comp_bank']), array('type' => 'text', 'length' => 15, 'name' => 'bik', 'head' => $core->lang['comp_bik'], 'value' => $comp['comp_bik']), array('type' => 'text', 'length' => 30, 'name' => 'acc', 'head' => $core->lang['comp_acc'], 'value' => $comp['comp_acc']), array('type' => 'text', 'length' => 30, 'name' => 'ks', 'head' => $core->lang['comp_ks'], 'value' => $comp['comp_ks']), array('type' => 'text', 'length' => 15, 'name' => 'inn', 'head' => $core->lang['comp_inn'], 'descr' => $core->lang['comp_inn_d'], 'value' => $comp['comp_inn']), array('type' => 'head', 'value' => $core->lang['comp_delivery']), array('type' => 'text', 'length' => 30, 'name' => 'spsr', 'head' => $core->lang['comp_spsr'], 'descr' => $core->lang['comp_spsr_d'], 'value' => $comp['comp_spsr']), array('type' => 'text', 'length' => 50, 'name' => 'spsr_login', 'head' => $core->lang['login'], 'value' => $comp['comp_spsr_login']), array('type' => 'text', 'length' => 50, 'name' => 'spsr_pass', 'head' => $core->lang['pass'], 'value' => $comp['comp_spsr_pass']), array('type' => 'text', 'length' => 50, 'name' => 'spsr_from', 'head' => $core->lang['city'], 'value' => $comp['comp_spsr_from']), array('type' => 'head', 'value' => $core->lang['comp_sms']), array('type' => 'checkbox', 'name' => 'sms_accept', 'head' => $core->lang['comp_sms_accept'], 'descr' => $core->lang['comp_sms_accept_d'], 'checked' => $comp['sms_accept']), array('type' => 'checkbox', 'name' => 'sms_post', 'head' => $core->lang['comp_sms_post'], 'descr' => $core->lang['comp_sms_post_d'], 'checked' => $comp['sms_post']), array('type' => 'checkbox', 'name' => 'sms_spsr', 'head' => $core->lang['comp_sms_spsr'], 'descr' => $core->lang['comp_sms_spsr_d'], 'checked' => $comp['sms_spsr']), array('type' => 'checkbox', 'name' => 'sms_rupo', 'head' => $core->lang['comp_sms_rupo'], 'descr' => $core->lang['comp_sms_rupo_d'], 'checked' => $comp['sms_rupo']), array('type' => 'checkbox', 'name' => 'autoaccept', 'head' => $core->lang['comp_autoaccept'], 'descr' => $core->lang['comp_autoaccept_d'], 'checked' => $comp['autoaccept']), array('type' => 'text', 'name' => 'callscheme', 'head' => $core->lang['comp_callscheme'], 'descr' => $core->lang['comp_callscheme_d'], 'value' => $comp['callscheme']), array('type' => 'head', 'value' => $core->lang['comp_pays']), array('type' => 'mces', 'name' => 'pay_info', 'head' => $core->lang['comp_pay'], 'descr' => $core->lang['comp_pay_d'], 'value' => $comp['pay_info']), array('type' => 'text', 'length' => 13, 'name' => 'pay_wmr', 'head' => $core->lang['comp_wmr'], 'value' => $comp['pay_wmr']), array('type' => 'text', 'length' => 64, 'name' => 'pay_wmk', 'head' => $core->lang['comp_wmk'], 'value' => $comp['pay_wmk']), array('type' => 'text', 'length' => 64, 'name' => 'pay_ymr', 'head' => $core->lang['comp_ymr'], 'value' => $comp['pay_ymr']), array('type' => 'text', 'length' => 64, 'name' => 'pay_ymk', 'head' => $core->lang['comp_ymk'], 'value' => $comp['pay_ymk']));
                $button = array(array('type' => 'submit', 'value' => $core->lang['save']));
                $core->form('comp', $action, $method, $title, $field, $button);
                $core->footer();
            } else {
                $comps = $core->db->data("SELECT comp_id, comp_name, comp_vip, user_id FROM " . DB_COMP . " ORDER BY comp_name ASC");
                $core->mainline->add($core->lang['admin_comp_h'], $core->url('m', 'comps'));
                $core->header();
                $core->tpl->load('body', 'safelist');
                $core->tpl->vars('body', array('title' => $core->lang['admin_comp_h'], 'text' => $core->text->lines($core->lang['admin_comp_t']), 'name' => $core->lang['name'], 'info' => $core->lang['cash'], 'action' => $core->lang['action'], 'edit' => $core->lang['edit'], 'del' => $core->lang['del'], 'confirm' => $core->lang['confirms']));
                foreach ($comps as &$i) {
                    $cash = $i['user_id'] ? rur($core->user->get($i['user_id'], 'user_cash')) : $core->lang['comp_free'];
                    $core->tpl->block('body', 'item', array('id' => $i['comp_id'], 'name' => $i['comp_name'], 'more' => ($i['comp_vip'] ? $core->lang['iamvip'] : '') . ' <small>(<a href="' . $core->url('i', 'integration', $i['comp_id']) . '">' . $core->lang['comp_int'] . '</a>)</small>', 'info' => $cash, 'url' => $core->url('i', 'comps', $i['comp_id']), 'edit' => $core->url('i', 'comps', $i['comp_id']), 'del' => $core->url('a', 'comps-del', $i['comp_id'])));
                }
                unset($d);
                $core->tpl->output('body');
                $title = $core->lang['comp_add'];
                $action = $core->url('a', 'comps-add', '');
                $method = 'post';
                $field = array(array('type' => 'text', 'length' => 100, 'name' => 'name', 'head' => $core->lang['name'], 'descr' => $core->lang['comp_add_d']));
                $button = array(array('type' => 'submit', 'value' => $core->lang['create']));
                $core->form('compadd', $action, $method, $title, $field, $button);
                $core->footer('admin');
            }
            $core->_die();
        case 'ext':
            switch ($message) {
                case 'add-ok':
                    $core->info('info', 'done_add');
                    break;
                case 'edit-ok':
                    $core->info('info', 'done_edit');
                    break;
                case 'del-ok':
                    $core->info('info', 'done_del');
                    break;
                case 'add-e':
                    $core->info('error', 'error_add');
                    break;
                case 'edit-e':
                    $core->info('error', 'error_edit');
                    break;
                case 'del-e':
                    $core->info('error', 'error_del');
                    break;
            }
            if ($id) {
                $ext = $core->db->row("SELECT * FROM " . DB_EXT . " WHERE ext_id = '{$id}' LIMIT 1");
                $user = array(array('name' => '&mdash; ' . $core->lang['comp_free'] . ' &mdash;', 'value' => 0));
                $users = $core->db->icol("SELECT user_id, user_name FROM " . DB_USER . " WHERE user_ext = '{$id}' ORDER BY user_name ASC");
                foreach ($users as $u => $n) {
                    $user[] = array('name' => $n, 'value' => $u, 'select' => $u == $ext['user_id']);
                }
                $core->mainline->add($core->lang['admin_ext_h'], $core->url('m', 'ext'));
                $core->mainline->add($ext['ext_name']);
                $core->header();
                $title = $core->lang['ext_edit'];
                $action = $core->url('a', 'ext-edit', $id);
                $method = 'post';
                $field = array(array('type' => 'text', 'length' => 100, 'name' => 'name', 'head' => $core->lang['name'], 'value' => $ext['ext_name']), array('type' => 'text', 'length' => 100, 'name' => 'key', 'head' => $core->lang['ext_key'], 'value' => $ext['ext_key']), array('type' => 'select', 'name' => 'user', 'head' => $core->lang['ext_user'], 'descr' => $core->lang['ext_user_d'], 'value' => $user), array('type' => 'head', 'value' => $core->lang['ext_url']), array('type' => 'line', 'value' => $core->lang['ext_url_d']), array('type' => 'text', 'length' => 200, 'name' => 'url_new', 'head' => $core->lang['ext_new'], 'value' => $ext['url_new']), array('type' => 'text', 'length' => 200, 'name' => 'url_nc', 'head' => $core->lang['ext_nc'], 'value' => $ext['url_nc']), array('type' => 'text', 'length' => 200, 'name' => 'url_rc', 'head' => $core->lang['ext_rc'], 'value' => $ext['url_rc']), array('type' => 'text', 'length' => 200, 'name' => 'url_acc', 'head' => $core->lang['ext_acc'], 'value' => $ext['url_acc']), array('type' => 'text', 'length' => 200, 'name' => 'url_dec', 'head' => $core->lang['ext_dec'], 'value' => $ext['url_dec']), array('type' => 'text', 'length' => 200, 'name' => 'url_pay', 'head' => $core->lang['ext_pay'], 'value' => $ext['url_pay']), array('type' => 'text', 'length' => 200, 'name' => 'url_ret', 'head' => $core->lang['ext_ret'], 'value' => $ext['url_ret']), array('type' => 'text', 'length' => 200, 'name' => 'url_del', 'head' => $core->lang['ext_del'], 'value' => $ext['url_del']), array('type' => 'head', 'value' => $core->lang['ext_code']), array('type' => 'code', 'lang' => 'php', 'name' => 'code_offer', 'head' => $core->lang['ext_code_offer'], 'value' => $ext['code_offer']), array('type' => 'code', 'lang' => 'php', 'name' => 'code_accept', 'head' => $core->lang['ext_code_accept'], 'value' => $ext['code_accept']));
                $button = array(array('type' => 'submit', 'value' => $core->lang['save']));
                $core->form('ext', $action, $method, $title, $field, $button);
                $core->footer();
            } else {
                $exts = $core->db->data("SELECT ext_id, ext_name, user_id FROM " . DB_EXT . " ORDER BY ext_name ASC");
                $core->mainline->add($core->lang['admin_ext_h'], $core->url('m', 'ext'));
                $core->header();
                $core->tpl->load('body', 'safelist');
                $core->tpl->vars('body', array('title' => $core->lang['admin_ext_h'], 'text' => $core->text->lines($core->lang['admin_ext_t']), 'name' => $core->lang['name'], 'info' => $core->lang['cash'], 'action' => $core->lang['action'], 'edit' => $core->lang['edit'], 'del' => $core->lang['del'], 'confirm' => $core->lang['confirms']));
                foreach ($exts as &$i) {
                    $cash = $i['user_id'] ? rur($core->user->get($i['user_id'], 'user_cash')) : $core->lang['ext_free'];
                    $core->tpl->block('body', 'item', array('id' => $i['ext_id'], 'name' => $i['ext_name'], 'info' => $cash, 'url' => $core->url('i', 'ext', $i['ext_id']), 'edit' => $core->url('i', 'ext', $i['ext_id']), 'del' => $core->url('a', 'ext-del', $i['ext_id'])));
                }
                unset($d);
                $core->tpl->output('body');
                $title = $core->lang['ext_add'];
                $action = $core->url('a', 'ext-add', '');
                $method = 'post';
                $field = array(array('type' => 'text', 'length' => 100, 'name' => 'name', 'head' => $core->lang['name'], 'descr' => $core->lang['ext_add_d']));
                $button = array(array('type' => 'submit', 'value' => $core->lang['create']));
                $core->form('extadd', $action, $method, $title, $field, $button);
                $core->footer();
            }
            $core->_die();
            // Money-Out Operations
        // Money-Out Operations
        case 'outs':
            switch ($message) {
                case 'acc-ok':
                    $core->info('info', 'done_out_acc');
                    break;
                case 'dec-ok':
                    $core->info('info', 'done_out_dec');
                    break;
                case 'acc-e':
                    $core->info('error', 'error_out_acc');
                    break;
                case 'dec-e':
                    $core->info('error', 'error_out_dec');
                    break;
            }
            $trs = $core->db->data("SELECT * FROM " . DB_CASH . "  WHERE cash_type = 4 ORDER BY user_id ASC, cash_time DESC");
            if (count($trs)) {
                $ui = $s = array();
                foreach ($trs as &$t) {
                    $ui[] = $t['user_id'];
                    $s[$t['user_id']] += $t['cash_value'];
                }
                unset($t);
                $ui = implode(',', array_unique($ui));
                $u = $core->db->icol("SELECT user_id, user_name FROM " . DB_USER . " WHERE user_id IN ( {$ui} )");
                $bo = $core->db->icol("SELECT wm_id, COUNT(*) FROM " . DB_ORDER . " WHERE wm_id IN ( {$ui} ) AND order_check = 1 GROUP BY wm_id");
            } else {
                $u = $bo = $s = array();
            }
            $core->mainline->add($core->lang['menu_outs'], $core->url('m', 'outs'));
            $core->header();
            $core->tpl->load('body', 'outs');
            $core->tpl->vars('body', array('user' => $core->lang['user'], 'accept' => $core->lang['do'], 'decline' => $core->lang['decline'], 'cash' => $core->lang['cash'], 'pay' => $core->lang['pay'], 'time' => $core->lang['date'], 'action' => $core->lang['action'], 'cancel' => $core->lang['cancel'], 'confirma' => $core->lang['oconfirma'], 'confirmd' => $core->lang['oconfirmd'], 'nofins' => $core->lang['noout'], 'u_bulk' => $core->url('a', 'out-bulk', 0)));
            if (count($trs)) {
                $ou = 0;
                foreach ($trs as &$c) {
                    if ($ou != $c['user_id']) {
                        $ou = $c['user_id'];
                        $core->tpl->block('body', 'user', array('id' => $ou, 'user' => $u[$ou], 'orders' => $bo[$ou], 'uu' => $core->url('i', 'users', $ou), 'value' => sprintf("%0.2f", abs($s[$ou]))));
                        if ($bo[$ou]) {
                            $core->tpl->block('body', 'user.bad');
                        }
                    }
                    $core->tpl->block('body', 'user.fin', array('id' => $c['cash_id'], 'wmr' => $c['cash_descr'], 'value' => sprintf("%0.2f", abs($c['cash_value'])), 'accept' => $core->url('a', 'out-accept', $c['cash_id']), 'decline' => $core->url('a', 'out-decline', $c['cash_id']), 'time' => smartdate($c['cash_time'])));
                }
                unset($t, $trs);
            } else {
                $core->tpl->block('body', 'nofin', array());
            }
            $core->tpl->output('body');
            $core->footer();
            $core->_die();
            //
            // News
            //
        //
        // News
        //
        case 'news-add':
            $core->mainline->add($core->lang['news'], $core->url('m', 'news'));
            $core->mainline->add($core->lang['news_add_h']);
            $core->header();
            $groups = array();
            foreach ($core->lang['news_groups'] as $v => $nm) {
                $groups[] = array('name' => $nm, 'value' => $v);
            }
            $title = $core->lang['news_add_h'];
            $action = $core->url('a', 'news-add', '');
            $method = 'post';
            $field = array(array('type' => 'line', 'value' => $core->text->lines($core->lang['news_t'])), array('type' => 'text', 'length' => 100, 'name' => 'title', 'head' => $core->lang['title']), array('type' => 'mcea', 'name' => 'text', 'head' => $core->lang['text']), array('type' => 'select', 'name' => 'group', 'head' => $core->lang['news_group'], 'value' => $groups), array('type' => 'checkbox', 'name' => 'vip', 'head' => $core->lang['news_vip'], 'descr' => $core->lang['news_vip_d']), array('type' => 'checkbox', 'name' => 'send', 'head' => $core->lang['news_send'], 'descr' => $core->lang['news_send_d']));
            $button = array(array('type' => 'submit', 'value' => $core->lang['create']));
            $core->form('news', $action, $method, $title, $field, $button);
            $core->footer();
            $core->_die();
        case 'news':
            if ($id) {
                $n = $core->db->row("SELECT * FROM " . DB_NEWS . " WHERE news_id = '{$id}' LIMIT 1");
                $core->mainline->add($core->lang['news'], $core->url('m', 'news'));
                $core->mainline->add($core->lang['news_edit_h']);
                $core->header();
                $groups = array();
                foreach ($core->lang['news_groups'] as $v => $nm) {
                    $groups[] = array('name' => $nm, 'value' => $v, 'select' => $v == $n['news_group']);
                }
                $title = $core->lang['news_edit_h'];
                $action = $core->url('a', 'news-edit', $id);
                $method = 'post';
                $field = array(array('type' => 'line', 'value' => $core->text->lines($core->lang['news_t'])), array('type' => 'text', 'length' => 100, 'name' => 'title', 'head' => $core->lang['title'], 'value' => $n['news_title']), array('type' => 'mcea', 'name' => 'text', 'head' => $core->lang['text'], 'value' => $n['news_text']), array('type' => 'select', 'name' => 'group', 'head' => $core->lang['news_group'], 'value' => $groups), array('type' => 'checkbox', 'name' => 'vip', 'head' => $core->lang['news_vip'], 'descr' => $core->lang['news_vip_d'], 'checked' => $n['news_vip']), array('type' => 'checkbox', 'name' => 'send', 'head' => $core->lang['news_send'], 'descr' => $core->lang['news_send_d']));
                $button = array(array('type' => 'submit', 'value' => $core->lang['save']));
                $core->form('news', $action, $method, $title, $field, $button);
                $core->footer();
                $core->_die();
            }
            break;
        case 'support':
            if ($id) {
                require_once PATH_LIB . 'support.php';
                $user = $core->user->get($id);
                $core->mainline->add($core->lang['support'], $core->url('m', 'support'));
                $core->mainline->add($user['user_name']);
                $core->header();
                $core->tpl->load('body', 'message');
                $core->tpl->vars('body', array('title' => $core->lang['support'], 'add' => $core->lang['send'], 'nomessage1' => $core->lang['support_nm1'], 'nomessage2' => $core->lang['support_nm2'], 'showmore' => $core->lang['support_more'], 'placeholder' => $core->lang['support_ph_admin'], 'u_load' => $core->url('a', 'supp-show', $id), 'u_add' => $core->url('a', 'supp-add', $id), 'mc' => 0));
                $core->tpl->block('body', 'face');
                $mn = $mx = 0;
                $messages = support_show($core, $id, 1, 0);
                if ($mc = count($messages)) {
                    foreach ($messages as &$m) {
                        $core->tpl->block('body', 'msg', $m);
                        if ($m['uid'] == $id) {
                            $core->tpl->block('body', 'msg.admin', array('u' => $user['user_mail']));
                        }
                        $mx = max($mx, $m['id']);
                        $mn = $mn ? min($mn, $m['id']) : $m['id'];
                    }
                    unset($m);
                    $core->tpl->block('body', 'more');
                } else {
                    $core->tpl->block('body', 'face.nomsg');
                }
                $core->tpl->vars('body', array('mn' => $mn, 'mx' => $mx));
                $core->tpl->output('body');
                $core->footer();
            } else {
                $core->mainline->add($core->lang['support_h'], $core->url('m', 'support'));
                $core->header();
                $show = 30;
                $start = ($page - 1) * $show;
                $supp = $core->db->data("SELECT * FROM " . DB_USER . " WHERE supp_last != 0 ORDER BY supp_last DESC LIMIT {$start}, {$show}");
                $sc = $core->db->field("SELECT COUNT(*) FROM " . DB_USER . " WHERE supp_last != 0");
                $core->tpl->load('body', 'support');
                $core->tpl->vars('body', array('title' => $core->lang['support_h'], 'text' => $core->text->lines($core->lang['support_t']), 'name' => $core->lang['name'], 'url' => $core->lang['url'], 'action' => $core->lang['action'], 'status' => $core->lang['status'], 'time' => $core->lang['time'], 'user' => $core->lang['user'], 'view' => $core->lang['view']));
                foreach ($supp as &$s) {
                    $core->tpl->block('body', 'supp', array('link' => $core->url('i', 'support', $s['user_id']), 'id' => $s['user_id'], 'time' => smartdate($s['supp_last']), 'name' => $s['user_name'], 'user' => $s['supp_name'], 'status' => $s['supp_admin'] ? sprintf($core->lang['support_new'], $s['supp_admin']) : ($s['supp_type'] ? $s['supp_new'] ? $core->lang['support_ur'] : $core->lang['support_ok'] : $core->lang['support_ua']), 'uclass' => $s['supp_type'] ? 'user-alt' : 'user-blue', 'sclass' => $s['supp_admin'] ? 'new' : ($s['supp_type'] ? $s['supp_new'] ? 'ur' : 'ok' : 'ua'), 'vclass' => $s['supp_admin'] ? 'new' : 'no'));
                }
                unset($supp, $s);
                $core->tpl->output('body');
                $core->footer();
            }
            $core->_die();
        case 'business':
            if (!$id) {
                $id = date('Ym');
            }
            if ($id < 10000) {
                $id *= 100;
            }
            $year = round($id / 100);
            $month = $id % 100;
            if ($month) {
                $f = strtotime("{$year}-{$month}-01");
                $e = strtotime("+ 1 month", $f);
            } else {
                $f = strtotime("{$year}-01-01");
                $e = strtotime("+ 1 year", $f);
            }
            $balance = array();
            $money = $core->db->icol("SELECT cash_type, SUM(cash_value) FROM " . DB_CASH . " WHERE cash_time BETWEEN '{$f}' AND '{$e}' GROUP BY cash_type");
            foreach ($core->lang['cash_type'] as $i => &$v) {
                $balance[$i] = $money[$i] * $core->lang['cash_balance'][$i];
            }
            $debt = $core->db->icol("SELECT user_name, user_cash FROM " . DB_USER . " WHERE user_work = 1 AND user_cash < 0 ORDER BY user_cash DESC");
            $cred = $core->db->icol("SELECT user_name, user_cash FROM " . DB_USER . " WHERE user_work IN ( 0, 2 )AND user_cash > 0 ORDER BY user_cash ASC");
            $exts = $core->db->icol("SELECT user_name, user_cash FROM " . DB_USER . " WHERE user_work = -1 AND user_cash > 0 ORDER BY user_cash ASC");
            $core->mainline->add($core->lang['menu_business']);
            $core->header();
            $core->tpl->load('body', 'business');
            $core->tpl->vars('body', array('u_trans' => $core->url('m', 'trans'), 'trans' => $core->lang['menu_trans'], 'years' => $core->lang['year'], 'months' => $core->lang['month'], 'cat' => $core->lang['business_cat'], 'total' => $core->lang['business_total'], 'summ' => $core->lang['cash'], 'balance' => $core->lang['business_balance'], 'm_balance' => rur(array_sum($balance)), 'user' => $core->lang['user'], 'debt' => $core->lang['debt_list'], 'cred' => $core->lang['cred_list'], 'nodebts' => $core->lang['debt_no'], 'nocreds' => $core->lang['cred_no'], 'cred_balance' => $core->lang['cred_balance'], 'cred_wait' => $core->lang['cred_wait'], 'd_balance' => rur(abs($dt = array_sum($debt))), 'c_balance' => rur($ct = array_sum($cred)), 'c_ext' => rur($et = array_sum($exts)), 'c_wait' => rur(abs($money[4])), 'c_total' => rur($ct + $et + abs($money[4]))));
            if ($dt) {
                $core->tpl->block('body', 'dt');
            }
            if ($ct) {
                $core->tpl->block('body', 'ct');
            }
            if ($et) {
                $core->tpl->block('body', 'et');
            }
            if ($money[4]) {
                $core->tpl->block('body', 'morecred');
            }
            for ($y = 2014; $y <= date('Y'); $y++) {
                $core->tpl->block('body', 'year', array('class' => $y == $year ? 'current' : '', 'mclass' => $y == $year ? 'primary' : 'info', 'url' => $core->url('i', 'business', $y), 'text' => $y));
            }
            for ($m = 1; $m < 13; $m++) {
                $core->tpl->block('body', 'month', array('class' => $m == $month ? 'current' : '', 'mclass' => $m == $month ? 'primary' : 'info', 'url' => $core->url('i', 'business', sprintf("%04d%02d", $year, $m)), 'text' => $core->lang['months'][$m]));
            }
            foreach ($core->lang['cash_type'] as $i => &$v) {
                $core->tpl->block('body', 'cash', array('id' => $i, 'name' => $v, 'summ' => rur($money[$i]), 'balance' => rur($balance[$i])));
            }
            unset($v);
            if (count($debt)) {
                foreach ($debt as $n => $s) {
                    $core->tpl->block('body', 'debt', array('name' => $n, 'summ' => rur(abs($s))));
                }
            } else {
                $core->tpl->block('body', 'nodebt');
            }
            if (count($cred)) {
                foreach ($cred as $n => $s) {
                    $core->tpl->block('body', 'cred', array('name' => $n, 'summ' => rur(abs($s))));
                }
            } elseif (!$money[4]) {
                $core->tpl->block('body', 'nocred');
            }
            if (count($exts)) {
                foreach ($exts as $n => $s) {
                    $core->tpl->block('body', 'ext', array('name' => $n, 'summ' => rur(abs($s))));
                }
            } elseif (!$money[4]) {
                $core->tpl->block('body', 'noext');
            }
            $core->tpl->output('body');
            $title = $core->lang['exit_h'];
            $action = $core->url('a', 'saw', 0);
            $method = 'post';
            $field = array(array('type' => 'line', 'value' => $core->text->lines($core->lang['exit_t'])), array('type' => 'text', 'length' => 6, 'name' => 'sum', 'head' => $core->lang['exit_sum'], 'descr' => sprintf($core->lang['exit_sum_d'], rur(array_sum($balance))), 'value' => $catname));
            $users = $core->db->data("SELECT user_id, user_name, user_mail FROM " . DB_USER . " WHERE user_level = 1 ORDER BY user_name ASC");
            foreach ($users as $u) {
                $field[] = array('type' => 'checkbox', 'name' => 'user[]', 'value' => $u['user_id'], 'head' => $u['user_name'], 'descr' => $u['user_mail'], 'checked' => 1);
            }
            $button = array(array('type' => 'submit', 'value' => $core->lang['exit_process']));
            $core->form('chainsaw', $action, $method, $title, $field, $button);
            $core->footer();
            $core->_die();
        case 'trans':
            switch ($message) {
                case 'del':
                    $core->info('info', 'trans_del');
                    break;
            }
            $where = array();
            // Search
            if (isset($core->get['s']) && $core->get['s']) {
                require_once PATH_CORE . 'search.php';
                $search = new SearchWords($core->get['s']);
                if ($s = $search->get()) {
                    $where[] = $search->field(array('cash_descr'));
                } else {
                    $s = false;
                }
            } else {
                $s = false;
            }
            // Date filtering
            if ($d = $core->get['d']) {
                $dd = explode('-', $d);
                $ds = mktime(0, 0, 0, $dd[1], $dd[2], $dd[0]);
                $de = mktime(23, 59, 59, $dd[1], $dd[2], $dd[0]);
                $where[] = "( cash_time BETWEEN '{$ds}' AND '{$de}' )";
            } else {
                $d = false;
            }
            // User filtering
            if (isset($core->get['f']) && $core->get['f'] != '') {
                $f = (int) $core->get['f'];
                $where[] = "user_id = '{$f}'";
            } else {
                $f = false;
            }
            // Type filtering
            if (isset($core->get['t']) && $core->get['t'] != '') {
                $t = (int) $core->get['t'];
                $where[] = "cash_type = '{$t}'";
            } else {
                $t = false;
            }
            $where = count($where) ? implode(' AND ', $where) : '1';
            $sh = 50;
            $st = $sh * ($page - 1);
            $trc = $core->db->field("SELECT COUNT(*) FROM " . DB_CASH . " WHERE {$where}");
            $trs = $trc ? $core->db->data("SELECT * FROM " . DB_CASH . " WHERE {$where} ORDER BY cash_time DESC LIMIT {$st}, {$sh}") : array();
            if ($trc) {
                $ui = array();
                foreach ($trs as &$tq) {
                    $ui[] = $tq['user_id'];
                }
                unset($tq);
                $ui = implode(',', array_unique($ui));
                $u = $core->db->icol("SELECT user_id, user_name FROM " . DB_USER . " WHERE user_id IN ( {$ui} )");
            } else {
                $u = array();
            }
            $core->mainline->add($core->lang['menu_trans'], $core->url('m', 'trans'));
            $core->header();
            $core->tpl->load('body', 'trans');
            $core->tpl->vars('body', array('user' => $core->lang['user'], 'type' => $core->lang['type'], 'cash' => $core->lang['cash'], 'status' => $core->lang['status'], 'time' => $core->lang['time'], 'del' => $core->lang['del'], 'confirm' => $core->lang['confirm'], 'd' => $d, 'f' => $f, 's' => $search ? $search->get() : $s, 'pages' => pages($core->url('m', 'trans?') . ($f ? 'f=' . $f . '&' : '') . ($d ? 'd=' . $d . '&' : '') . ($t ? 't=' . $t . '&' : '') . ($s ? 's=' . $s . '&' : ''), $trc, $sh, $page), 'shown' => sprintf($core->lang['shown'], $st + 1, min($st + $sh, $trc), $trc), 'filter' => $core->lang['filter'], 'date' => $core->lang['date'], 'search' => $core->lang['search'], 'find' => $core->lang['find']));
            if ($f) {
                $core->tpl->block('body', 'user');
                $core->tpl->vars('body', array('user' => $core->lang['user'], 'u' => $u[$f], 'reset' => $core->url('m', 'trans?') . ($d ? 'd=' . $d . '&' : '') . ($s ? 's=' . $s . '&' : '')));
            }
            foreach ($core->lang['cash_type'] as $i => $st) {
                $core->tpl->block('body', 'type', array('name' => $st, 'value' => $i, 'select' => $t == $i ? 'selected="selected"' : ''));
            }
            if (count($trs)) {
                foreach ($trs as &$c) {
                    $core->tpl->block('body', 'fin', array('user' => $u[$c['user_id']], 'uu' => $core->url('m', 'trans') . '?f=' . $c['user_id'], 'type' => $core->lang['cash_type'][$c['cash_type']], 'tid' => $c['cash_type'], 'descr' => $c['cash_descr'] ? '(' . ($search ? $search->highlight($c['cash_descr']) : $c['cash_descr']) . ')' : '', 'value' => rur($c['cash_value']), 'del' => $core->url('a', 'trans-del', $c['cash_id']), 'time' => smartdate($c['cash_time'])));
                }
                unset($t, $trs);
            } else {
                $core->tpl->block('body', 'nofin', array());
            }
            $core->tpl->output('body');
            $core->footer();
            $core->_die();
        case 'analytics':
            $today = date('Ymd');
            $yest = date('Ymd', strtotime('-1 day'));
            $day7 = date('Ymd', strtotime('-7 days'));
            $day30 = date('Ymd', strtotime('-30 days'));
            if (isset($core->get['to']) && $core->get['to']) {
                $to = form2date($core->get['to']);
                if ($to > $today) {
                    $to = $today;
                }
            } else {
                $to = $today;
            }
            if (isset($core->get['from']) && $core->get['from']) {
                $from = form2date($core->get['from']);
                if ($from > $to) {
                    $from = $to;
                }
            } else {
                $from = $today;
            }
            $ff = strtotime(date2form($from) . ' 00:00:00');
            $tt = strtotime(date2form($to) . ' 23:59:59');
            $where = array("( order_time BETWEEN '{$ff}' AND '{$tt}' )");
            if (isset($core->get['o']) && $core->get['o']) {
                $o = (int) $core->get['o'];
                $where[] = "offer_id = '{$o}'";
            } else {
                $o = false;
            }
            if (isset($core->get['c']) && $core->get['c']) {
                $c = (int) $core->get['c'];
                $where[] = "comp_id = '{$c}'";
            } else {
                $c = false;
            }
            if (isset($core->get['a']) && $core->get['a']) {
                $a = true;
            } else {
                $a = false;
            }
            $where = implode(' AND ', $where);
            $offers = $core->wmsale->get('offers');
            $comps = $core->wmsale->get('comps');
            $comp = $user = $site = $flow = $ext = $offer = $man = $uf = $os = $cm = array();
            $total = $em = array('st0' => 0, 'st1' => 0, 'st2' => 0, 'st3' => 0, 'st4' => 0, 'st5' => 0, 'st6' => 0, 'st91' => 0, 'st92' => 0, 'st101' => 0, 'st102' => 0, 'st111' => 0, 'st112' => 0, 'st12' => 0, 'dc1' => 0, 'dc2' => 0, 'dc3' => 0, 'dc4' => 0, 'dc5' => 0, 'dc6' => 0, 'dc7' => 0, 'dc8' => 0, 'mi' => 0, 'mo' => 0, 'mt' => 0);
            $oq = $core->db->start("SELECT offer_id, comp_id, wm_id, ext_id, ext_src, site_id, user_id, flow_id, order_status, order_reason, order_shave, order_delivery, order_count FROM " . DB_ORDER . " WHERE {$where}");
            while ($q = $core->db->one($oq)) {
                // Processing stats
                $process = array(&$total);
                if ($q['flow_id']) {
                    $userid = $q['wm_id'];
                    if (!isset($flow[$q['flow_id']])) {
                        $flow[$q['flow_id']] = $em;
                    }
                    $process[] =& $flow[$q['flow_id']];
                    $uf[$userid][] = $q['flow_id'];
                    $uf[$userid] = array_unique($uf[$userid]);
                } elseif ($q['ext_id']) {
                    $userid = $q['wm_id'] ? $q['wm_id'] : (int) $core->wmsale->get('ext', $q['ext_id'], 'user_id');
                    if ($userid && $q['ext_src']) {
                        if (!isset($ext[$userid])) {
                            $ext[$userid] = array();
                        }
                        if (!isset($ext[$userid][$q['ext_src']])) {
                            $ext[$userid][$q['ext_src']] = $em;
                        }
                        $process[] =& $ext[$userid][$q['ext_src']];
                    }
                } else {
                    $userid = 0;
                }
                if (!$userid) {
                    $userid = $q['wm_id'];
                }
                if (!isset($user[$userid])) {
                    $user[$userid] = $em;
                }
                $process[] =& $user[$userid];
                if (!isset($comp[$q['comp_id']])) {
                    $comp[$q['comp_id']] = $em;
                }
                $process[] =& $comp[$q['comp_id']];
                if (!isset($offer[$q['offer_id']])) {
                    $offer[$q['offer_id']] = $em;
                }
                $process[] =& $offer[$q['offer_id']];
                if (($a || $o) && $q['site_id']) {
                    $os[$q['offer_id']][] = $q['site_id'];
                    $os[$q['offer_id']] = array_unique($os[$q['offer_id']]);
                    if (!isset($site[$q['site_id']])) {
                        $site[$q['site_id']] = $em;
                    }
                    $process[] =& $site[$q['site_id']];
                }
                if ($c && $q['user_id']) {
                    $cs[$q['comp_id']][] = $q['user_id'];
                    $cs[$q['comp_id']] = array_unique($cs[$q['comp_id']]);
                    if (!isset($man[$q['user_id']])) {
                        $man[$q['user_id']] = $em;
                    }
                    $process[] =& $man[$q['user_id']];
                }
                // Increments for stats
                $incs = array();
                if ($q['order_status'] == 12) {
                    $incs['st12'] = 1;
                } elseif ($q['order_status'] > 5) {
                    $incs['st6'] = 1;
                    if ($q['order_status'] == 8) {
                        $incs['st9' . $q['order_delivery']] = 1;
                    }
                    if ($q['order_status'] == 9) {
                        $incs['st9' . $q['order_delivery']] = 1;
                    }
                    if ($q['order_status'] == 10) {
                        $incs['st10' . $q['order_delivery']] = 1;
                    }
                    if ($q['order_status'] == 11) {
                        $incs['st11' . $q['order_delivery']] = 1;
                    }
                    $cu = $core->wmsale->get('comp', $q['comp_id'], 'user_id');
                    $of = $core->wmsale->get('offer', $q['offer_id']);
                    $mn = $core->wmsale->price($q['offer_id'], array($userid, $cu));
                    $incs['mo'] = $userid ? $mn['wmp'] : 0;
                    $incs['mi'] = $cu ? $mn['pay'] : 0;
                    if ($q['order_count'] > 1) {
                        if ($userid && $mn['wmu']) {
                            $incs['mo'] += $mn['wmu'] * ($q['order_count'] - 1);
                        }
                        if ($cu && $mn['pyu']) {
                            $incs['mi'] += $mn['pyu'] * ($q['order_count'] - 1);
                        }
                    }
                    if ($q['order_shave']) {
                        $incs['mo'] = 0;
                        if ($q['order_shave'] == 1) {
                            $incs['mi'] = 0;
                        }
                    }
                    $incs['mt'] = $incs['mi'] - $incs['mo'];
                } elseif ($q['order_status'] == 5) {
                    $incs['st5'] = 1;
                    $incs['dc' . $q['order_reason']] = 1;
                } else {
                    $incs['st0'] = 1;
                    $incs['st' . $q['order_status']] = 1;
                }
                // Increment all
                foreach ($process as &$p) {
                    foreach ($incs as $i => $v) {
                        $p[$i] += $v;
                    }
                }
            }
            $core->db->stop($oq);
            ksort($user);
            ksort($comp);
            ksort($offer);
            ksort($man);
            ksort($site);
            ksort($flow);
            $core->mainline->add($core->lang['menu_analytics'], $core->url('m', 'analytics'));
            $core->header();
            $core->tpl->load('body', 'analytics');
            $core->tpl->vars('body', array('name' => $core->lang['name'], 'user' => $core->lang['user'], 'comp' => $core->lang['company'], 'offer' => $core->lang['offer'], 'show' => $core->lang['show'], 'wait' => $core->lang['stat_wait'], 'accept' => $core->lang['stat_accept'], 'cancel' => $core->lang['stat_cancel'], 'from' => date2form($from), 'to' => date2form($to), 'today' => $core->lang['anal_today'], 'yest' => $core->lang['anal_yest'], 'day7' => $core->lang['anal_day7'], 'day30' => $core->lang['anal_day30'], 'all' => $a ? $core->lang['anal_short'] : $core->lang['anal_full'], 'u_all' => $core->url('m', 'analytics?from=') . date2form($from) . '&to=' . date2form($to) . ($o ? '&o=' . $o : '') . ($c ? '&c=' . $c : '') . ($a ? '' : '&a=1'), 'u_today' => $core->url('m', 'analytics?from=') . date2form($today) . '&to=' . date2form($today) . ($o ? '&o=' . $o : '') . ($c ? '&c=' . $c : '') . ($a ? '&a=1' : ''), 'u_yest' => $core->url('m', 'analytics?from=') . date2form($yest) . '&to=' . date2form($yest) . ($o ? '&o=' . $o : '') . ($c ? '&c=' . $c : '') . ($a ? '&a=1' : ''), 'u_day7' => $core->url('m', 'analytics?from=') . date2form($day7) . '&to=' . date2form($today) . ($o ? '&o=' . $o : '') . ($c ? '&c=' . $c : '') . ($a ? '&a=1' : ''), 'u_day30' => $core->url('m', 'analytics?from=') . date2form($day30) . '&to=' . date2form($today) . ($o ? '&o=' . $o : '') . ($c ? '&c=' . $c : '') . ($a ? '&a=1' : ''), 'count' => $core->lang['anal_count'], 'income' => $core->lang['anal_income'], 'outcome' => $core->lang['anal_outcome'], 'total' => $core->lang['anal_total']));
            foreach ($core->lang['statuso'] as $i => $v) {
                $core->tpl->vars('body', array('st' . $i => $v));
            }
            foreach ($core->lang['reasono'] as $i => $v) {
                $core->tpl->vars('body', array('rs' . $i => $v));
            }
            foreach ($core->lang['reasonm'] as $i => $v) {
                $core->tpl->vars('body', array('rm' . $i => $v));
            }
            foreach ($offers as $of => $n) {
                $core->tpl->block('body', 'offer', array('name' => $n, 'value' => $of, 'select' => $of == $o ? 'selected="selected"' : ''));
            }
            foreach ($comps as $cm => $n) {
                $core->tpl->block('body', 'comp', array('name' => $n, 'value' => $cm, 'select' => $cm == $c ? 'selected="selected"' : ''));
            }
            foreach ($comp as $i => &$z) {
                $z['name'] = $comps[$i];
                $z['vip'] = $core->wmsale->get('comp', $i, 'comp_vip') ? $core->lang['iamvip'] : '';
                if ($c) {
                    foreach ($cs[$i] as $f) {
                        $man[$f]['name'] = '&mdash; ' . $core->user->get($f, 'user_name');
                    }
                }
            }
            unset($z);
            function nameusort($aaaa, $bbbb)
            {
                return strcmp($aaaa['name'], $bbbb['name']);
            }
            foreach ($user as $i => &$z) {
                $z['name'] = $i ? $core->user->get($i, 'user_name') : $core->lang['anal_search'];
                $z['vip'] = $i ? $core->user->get($i, 'user_vip') ? $core->lang['iamvip'] : '' : '';
                $z['ext'] = $i ? $core->user->get($i, 'user_ext') ? $core->lang['iamext'] : '' : '';
                if ($ext[$i]) {
                    foreach ($ext[$i] as $n => &$ff) {
                        $ff['name'] = '&mdash; ' . $n;
                    }
                    ksort($ext[$i]);
                } elseif ($a && $uf[$i]) {
                    foreach ($uf[$i] as $f) {
                        $flow[$f]['name'] = '&mdash; ' . $core->wmsale->get('flow', $f, 'flow_name');
                    }
                }
            }
            unset($z);
            $sites = $core->wmsale->get('lands');
            foreach ($offer as $i => &$z) {
                $z['name'] = $offers[$i];
                if (($a || $o) && $os[$i]) {
                    foreach ($os[$i] as $f) {
                        $site[$f]['name'] = '&mdash; ' . $sites[$f];
                    }
                }
            }
            unset($z);
            uasort($comp, 'nameusort');
            uasort($user, 'nameusort');
            uasort($offer, 'nameusort');
            $core->tpl->block('body', 'bl');
            $total['name'] = $core->lang['total'];
            $core->tpl->block('body', 'bl.row', analytics_line($total));
            $core->tpl->block('body', 'bl');
            $core->tpl->block('body', 'bl.t', array('name' => $core->lang['anal_comps']));
            foreach ($comp as $i => $z) {
                $core->tpl->block('body', 'bl.row', analytics_line($z));
                if ($c) {
                    foreach ($cs[$i] as $f) {
                        $core->tpl->block('body', 'bl.row', analytics_line($man[$f]));
                    }
                }
            }
            $core->tpl->block('body', 'bl');
            $core->tpl->block('body', 'bl.t', array('name' => $core->lang['anal_users']));
            foreach ($user as $i => $z) {
                $core->tpl->block('body', 'bl.row', analytics_line($z));
                if ($a && $uf[$i]) {
                    foreach ($uf[$i] as $f) {
                        $core->tpl->block('body', 'bl.row', analytics_line($flow[$f]));
                    }
                }
                if ($a && $ext[$i]) {
                    foreach ($ext[$i] as $f) {
                        $core->tpl->block('body', 'bl.row', analytics_line($f));
                    }
                }
            }
            $core->tpl->block('body', 'bl');
            $core->tpl->block('body', 'bl.t', array('name' => $core->lang['anal_offer']));
            foreach ($offer as $i => $z) {
                $core->tpl->block('body', 'bl.row', analytics_line($z));
                if ($a || $o) {
                    foreach ($os[$i] as $f) {
                        $core->tpl->block('body', 'bl.row', analytics_line($site[$f]));
                    }
                }
            }
            $core->tpl->output('body');
            $core->footer();
            $core->_die();
        case 'dynamics':
            $today = date('Ymd');
            $day7 = date('Ymd', strtotime('-7 days'));
            $day30 = date('Ymd', strtotime('-30 days'));
            $day90 = date('Ymd', strtotime('-90 days'));
            if (isset($core->get['to']) && $core->get['to']) {
                $to = form2date($core->get['to']);
                if ($to > $today) {
                    $to = $today;
                }
            } else {
                $to = $today;
            }
            if (isset($core->get['from']) && $core->get['from']) {
                $from = form2date($core->get['from']);
                if ($from > $to) {
                    $from = $to;
                }
            } else {
                $from = $day30;
            }
            $ff = strtotime(date2form($from) . ' 00:00:00');
            $tt = strtotime(date2form($to) . ' 23:59:59');
            $stats = array();
            $oq = $core->db->start("SELECT cash_time, cash_value FROM " . DB_CASH . " WHERE cash_type IN ( 2, 3, 6 ) AND cash_time BETWEEN '{$ff}' AND '{$tt}'");
            while ($q = $core->db->one($oq)) {
                if (!$q['cash_value']) {
                    continue;
                }
                $d = date('Ymd', $q['cash_time']);
                $v = -$q['cash_value'];
                if (!$stats[$d]) {
                    $stats[$d] = array('i' => 0, 'o' => 0);
                }
                $stats[$d][$v > 0 ? 'i' : 'o'] += $v;
            }
            $core->db->stop($oq);
            krsort($stats);
            foreach ($stats as &$s) {
                $s['t'] = $s['i'] + $s['o'];
            }
            unset($s);
            reset($stats);
            list($d, $s) = each($stats);
            while (1) {
                $d1 = $d;
                $s1 = $s;
                list($d, $s) = each($stats);
                if (!$d) {
                    break;
                }
                $stats[$d1]['d'] = $s1['t'] - $s['t'];
            }
            reset($stats);
            $core->mainline->add($core->lang['dynamics'], $core->url('m', 'dynamics'));
            $core->header();
            $core->tpl->load('body', 'dynamics');
            $core->tpl->vars('body', array('date' => $core->lang['date'], 'income' => $core->lang['anal_income'], 'outcome' => $core->lang['anal_outcome'], 'total' => $core->lang['anal_total'], 'from' => date2form($from), 'to' => date2form($to), 'show' => $core->lang['show'], 'u_analytics' => $core->url('m', 'analytics'), 'analytics' => $core->lang['menu_analytics'], 'day7' => $core->lang['anal_day7'], 'day30' => $core->lang['anal_day30'], 'day90' => $core->lang['anal_day90'], 'u_day7' => $core->url('m', 'dynamics?from=') . date2form($day7) . '&to=' . date2form($today), 'u_day30' => $core->url('m', 'dynamics?from=') . date2form($day30) . '&to=' . date2form($today), 'u_day90' => $core->url('m', 'dynamics?from=') . date2form($day90) . '&to=' . date2form($today)));
            foreach ($stats as $d => $s) {
                $core->tpl->block('body', 'date', array('day' => date2form($d), 'wd' => $core->lang['weekday'][date('w', strtotime(date2form($d)))], 'in' => rur($s['i']), 'out' => rur($s['o']), 'total' => rur($s['t']), 'delta' => rur($s['d'])));
            }
            ksort($stats);
            foreach ($stats as $d => $s) {
                $core->tpl->block('body', 'gr', array('smd' => substr($d, 6, 2) . '.' . substr($d, 4, 2), 'smt' => abs($s['t'])));
            }
            $core->tpl->output('body');
            $core->footer();
            $core->_die();
    }
    return false;
}
コード例 #2
0
ファイル: orders.php プロジェクト: Burick/altercpa
function order_module($core)
{
    $module = $core->get['m'] ? $core->get['m'] : null;
    $id = $core->post['id'] ? (int) $core->post['id'] : ($core->get['id'] ? (int) $core->get['id'] : 0);
    $page = $core->get['page'] > 0 ? (int) $core->get['page'] : 1;
    $message = $core->get['message'] ? $core->get['message'] : null;
    if ($module == 'courier') {
        return order_courier($core);
    }
    if ($module == 'delivery') {
        return order_delivery($core);
    }
    if ($module == 'security') {
        return order_security($core);
    }
    if ($module && $module != 'order') {
        return false;
    }
    switch ($message) {
        case 'save':
            $core->info('info', 'done_order_save');
            break;
        case 'send':
            $core->info('info', 'done_order_send');
            break;
        case 'pack':
            $core->info('info', 'done_order_pack');
            break;
        case 'done':
            $core->info('info', 'done_order_done');
            break;
        case 'arrive':
            $core->info('info', 'done_order_arrive');
            break;
        case 'del':
            $core->info('info', 'done_order_del');
            break;
        case 'pickup':
            $core->info('error', 'error_order_pickup');
            break;
        case 'nocode':
            $core->info('error', 'error_order_nocode');
            break;
        case 'error':
            $core->info('error', 'error_order_smth');
            break;
        case 'access':
            $core->info('error', 'access_denied');
            break;
    }
    // Edit order
    if ($id) {
        // Order, offer and variants
        $order = $core->db->row("SELECT * FROM " . DB_ORDER . " WHERE order_id = '{$id}' LIMIT 1");
        if ($order['user_id'] != $core->user->id && $order['comp_id'] != $core->user->comp && $core->user->level < 1 && !$core->user->call) {
            $core->go($core->url('mm', '', 'access'));
        }
        $offer = $core->wmsale->get('offer', $order['offer_id']);
        $site = $order['site_id'] ? $core->wmsale->get('site', $order['site_id'], 'site_url') : false;
        $space = ($core->user->level || $core->user->call) && $order['space_id'] ? $core->wmsale->get('site', $order['space_id'], 'site_url') : false;
        $vars = $offer['offer_vars'] ? $core->wmsale->get('vars', $offer['offer_id']) : false;
        $oips = $core->db->field("SELECT COUNT(*) FROM " . DB_ORDER . " WHERE order_ip = '" . $order['order_ip'] . "'" . ($core->user->level || $core->user->call ? '' : " AND comp_id = '" . $order['comp_id'] . "'"));
        $ophs = $core->db->field("SELECT COUNT(*) FROM " . DB_ORDER . " WHERE order_phone = '" . $order['order_phone'] . "'" . ($core->user->level || $core->user->call ? '' : " AND comp_id = '" . $order['comp_id'] . "'"));
        $order['items'] = $order['order_items'] ? unserialize($order['order_items']) : array();
        $user = $core->user->get($order['wm_id']);
        $callscheme = ($callscheme = $core->wmsale->get('comp', $core->user->comp, 'callscheme')) ? $callscheme : 'tel:+%s';
        $ophone = $core->db->row("SELECT * FROM " . DB_PDB . " WHERE `phone` = '" . substr($order['order_phone'], 1, 6) . "' LIMIT 1");
        if ($ophone) {
            $ophone['type'] = $ophone['operator'];
            $ophone['place'] = $ophone['region'];
            if ($ophone['city']) {
                $ophone['place'] .= ', ' . $ophone['city'];
            }
        }
        $addr = $order['order_addr'];
        if ($order['order_street']) {
            $addr = $order['order_street'] . ', ' . $addr;
        }
        if ($order['order_city']) {
            $addr = $order['order_city'] . ', ' . $addr;
        }
        if ($order['order_area']) {
            $addr = $order['order_area'] . ', ' . $addr;
        }
        // Store
        if ($vars) {
            $store = array();
            $stores = $core->db->data("SELECT var_id, store_count FROM " . DB_STORE . " WHERE offer_id = '" . $order['offer_id'] . "' AND comp_id = '" . $order['comp_id'] . "'");
            foreach ($stores as $s) {
                $store[$s['var_id']] = $s['store_count'];
            }
        } else {
            $store = (int) $core->db->field("SELECT store_count FROM " . DB_STORE . " WHERE offer_id = '" . $order['offer_id'] . "' AND comp_id = '" . $order['comp_id'] . "' LIMIT 1");
        }
        // Parameters
        if ($offer['offer_paramurl'] && $order['order_meta']) {
            $cache = sprintf(PATH_CACHE, md5($order['order_meta']));
            if (!file_exists($cache)) {
                $post = unserialize($order['order_meta']);
                $form = curl($offer['offer_paramurl'], $post);
                file_put_contents($cache, $form);
            } else {
                $form = file_get_contents($cache);
            }
        } else {
            $form = null;
        }
        // Page Header
        $core->mainline->add($core->lang['orders_h'], $core->url('m', 'order'));
        $core->mainline->add($offer['offer_name']);
        $core->mainline->add($order['order_name']);
        $core->header();
        $core->tpl->load('body', 'order');
        $core->tpl->vars('body', $offer);
        $core->tpl->vars('body', $order);
        $core->tpl->vars('body', array('order' => $core->lang['order'], 'save' => $core->lang['order_save'], 'next' => $core->lang['order_save_next'], 'u_edit' => $core->url('a', 'order-edit', $id), 'action' => $core->lang['order_work_action'], 'mark' => $core->lang['order_marks'], 'source' => $core->lang['source'], 'site' => $core->lang['site'], 'space' => $core->lang['stat_spaces'], 'store' => $core->lang['store'], 'count' => $core->lang['count'], 'price' => $core->lang['price'], 'more_price' => $core->lang['order_more'], 'total' => $core->lang['total'], 'name' => $core->lang['name'], 'fio' => $core->lang['username'], 'address' => $core->lang['address'], 'address_d' => $core->lang['order_addr_d'], 'street' => $core->lang['street'], 'city' => $core->lang['city'], 'area' => $core->lang['area'], 'phone' => $core->lang['phone'], 'index' => $core->lang['index'], 'present' => $core->lang['present'], 'present_d' => $core->lang['present_d'], 'call' => $core->lang['call'], 'track' => $core->lang['track'], 'checkaddr' => $core->lang['order_checkaddr'], 'delivery' => $core->lang['deliver'], 'discount' => $core->lang['discount'], 'packdocs' => $core->lang['order_pack_docs'], 'country' => $order['order_country'] ? $order['order_country'] : ($order['geoip_country'] ? $order['geoip_country'] : 'zz'), 'callscheme' => $callscheme, 'phone_call' => sprintf($callscheme, $order['order_phone']), 'phone_ok_c' => $order['order_phone_ok'] ? 'phone-ok' : 'phone-bad', 'phone_ok_t' => $order['order_phone_ok'] ? 'ok' : '!!', 'form' => $form, 'status' => $core->lang['statuso'][$order['order_status']], 'date' => smartdate($order['order_time']), 'u_addr' => '/addr.php?addr=', 'u_spsr' => $core->url('a', 'order-spsr', 0), 'u_rupost' => $core->url('a', 'order-rupost', 0), 'fulladdr' => $addr, 'r' => $core->server['HTTP_REFERER'], 'site_url' => $site, 'space_url' => $space, 'paid_type' => $core->lang['order_paid'][$order['paid_ok']], 'paid_date' => smartdate($order['paid_time']), 'paid_info' => $core->text->lines($order['paid_from']), 'u_phone' => $core->url('a', 'order-phone', 0) . '?phone=', 'phone_info' => $ophone ? sprintf("%s (%s)", $ophone['type'], $ophone['place']) : '', 'order_ip' => int2ip($order['order_ip']), 'ipwarn' => $oips > 1 ? sprintf($core->lang['order_ipwarn'], $core->url('m', 'order?s=') . int2ip($order['order_ip']), $oips) : '', 'phwarn' => $ophs > 1 ? sprintf($core->lang['order_phwarn'], $core->url('m', 'order?s=') . $order['order_phone'], $ophs) : '', 'wm_name' => $order['wm_id'] ? $user['user_level'] ? '<b>' . $user['user_name'] . '</b>' : $user['user_name'] : $core->lang['order_src_sh'], 'wm_class' => $order['wm_id'] ? $order['ext_id'] ? 'ext' : ($user['user_ban'] ? 'warn' : ($user['user_warn'] ? 'ua' : ($user['user_vip'] ? 'vip' : 'user'))) : 'search', 'wm_src' => $order['flow_id'] ? sprintf($core->lang['order_src_f'], $order['flow_id']) : ($order['ext_src'] ? sprintf($core->lang['order_src_e'], $user['user_id'], $order['ext_src']) : '')));
        // Spacer landing
        if ($site) {
            $core->tpl->block('body', 'site');
        }
        if ($space) {
            $core->tpl->block('body', 'space');
        }
        if ($form) {
            $core->tpl->block('body', 'form');
        }
        if ($order['paid_ok']) {
            $core->tpl->block('body', 'paid');
        }
        if ($order['order_file']) {
            $core->tpl->block('body', 'file');
        }
        // WM info
        if ($order['wm_id'] && !$order['ext_id']) {
            $core->tpl->block('body', 'ofm', array('v' => $user['user_mail']));
            if ($user['user_wmr']) {
                $core->tpl->block('body', 'ofw', array('v' => $user['user_wmr']));
            }
        }
        // Edit ability
        $canedit = $order['order_status'] > 1 && $order['order_status'] < 5 || $order['order_status'] == 6 || $order['order_status'] == 7;
        if ($canedit) {
            $core->tpl->block('body', 'edit');
            if ($offer['offer_delivery']) {
                $core->tpl->block('body', 'edit.delivery');
            }
        } else {
            $core->tpl->block('body', 'view');
            if ($order['order_comment']) {
                $core->tpl->block('body', 'comment');
            }
        }
        // Package documents
        if ($order['order_status'] == 6 && $order['order_delivery'] == 1) {
            $core->tpl->block('body', 'docs', array('u' => $core->url('a', 'order-docs', $order['order_id'])));
        }
        // Tracking code
        if ($order['order_status'] == 7 || $order['order_status'] == 8) {
            $core->tpl->block('body', 'track');
        }
        if ($order['order_status'] > 7 && $order['order_status'] < 10 || $order['order_status'] == 11) {
            $core->tpl->block('body', 'delpro', array('cls' => $order['track_status'] ? $order['order_status'] == 9 ? 'green' : 'blue' : 'red', 'check' => sprintf($core->lang['track_check'], smartdate($order['track_check'])), 'info' => $order['track_status'] ? sprintf("%s: %s", $order['track_date'], $order['track_status']) : $core->lang['track_wait'], 'url' => sprintf($core->lang['deliveru'][$order['order_delivery']], $order['track_code'])));
        }
        // Variants of offer
        if ($vars) {
            $ndprice = 0;
            foreach ($vars as $v) {
                $core->tpl->block('body', 'item', array('id' => $v['var_id'], 'name' => $v['var_name'], 'price' => $v['var_price'], 'count' => (int) $order['items'][$v['var_id']], 'total' => $v['var_price'] * (int) $order['items'][$v['var_id']], 'store' => (int) $store[$v['var_id']]));
                if ($canedit) {
                    $core->tpl->block('body', 'item.edit');
                } else {
                    $core->tpl->block('body', 'item.view');
                }
                $ndprice += $v['var_price'] * (int) $order['items'][$v['var_id']];
            }
        } else {
            $core->tpl->block('body', 'item', array('id' => $offer['offer_id'], 'name' => $offer['offer_name'], 'price' => $offer['offer_price'], 'count' => (int) $order['order_count'], 'total' => $offer['offer_price'] * (int) $order['order_count'], 'store' => (int) $store));
            if ($canedit) {
                $core->tpl->block('body', 'item.edit');
            } else {
                $core->tpl->block('body', 'item.view');
            }
            $ndprice = $offer['offer_price'] * (int) $order['order_count'];
        }
        // Discounts
        if ($canedit) {
            foreach ($core->lang['discounts'] as $i => $n) {
                $core->tpl->block('body', 'dcedit', array('id' => $i, 'name' => $n, 'total' => ceil($ndprice * ((100 - $i) / 100)), 'check' => $i == $order['order_discount'] ? 'checked="checked"' : ''));
            }
        } else {
            $core->tpl->block('body', 'dcview', array('name' => $core->lang['discounts'][$order['order_discount']], 'price' => $order['order_discount'], 'total' => $ndprice * ((100 - $order['order_discount']) / 100)));
        }
        // Delivery
        if ($offer['offer_delivery']) {
            $core->tpl->block('body', 'delivery');
            if ($canedit) {
                $core->tpl->block('body', 'delivery.moreedit');
                foreach ($core->lang['delivery'] as $i => $n) {
                    $core->tpl->block('body', 'delivery.edit', array('id' => $i, 'name' => $n, 'price' => $core->lang['deliverp'][$i], 'total' => $core->lang['deliverp'][$i], 'check' => $i == $order['order_delivery'] ? 'checked="checked"' : ''));
                }
            } else {
                if ($order['order_more']) {
                    $core->tpl->block('body', 'delivery.moreview');
                }
                $core->tpl->block('body', 'delivery.view', array('name' => $core->lang['delivery'][$order['order_delivery']], 'price' => $core->lang['deliverp'][$order['order_delivery']], 'total' => $core->lang['deliverp'][$order['order_delivery']]));
            }
        }
        // Actions
        if ($order['order_status'] > 1 && $order['order_status'] < 5) {
            $actions = array('order_call_basic' => array('ok' => $core->lang['order_call_ok']), 'order_call_re' => array(), 'order_call_no' => array(), 'cancel' => array());
            if ($core->user->level || $core->user->shave) {
                $actions['order_call_basic']['shave'] = $core->lang['order_call_shave'];
            }
            foreach ($core->lang['recallo'] as $k => $v) {
                $actions['order_call_re']['re' . $k] = $v;
            }
            foreach ($core->lang['nocallo'] as $k => $v) {
                $actions['order_call_no']['no' . $k] = $v;
            }
            foreach ($core->lang['reasono'] as $k => $v) {
                $actions['cancel']['cancel' . $k] = $v;
            }
        } elseif ($order['order_status'] == 6) {
            $actions = array('order_pack_o' => $core->lang['packingo']);
        } elseif ($order['order_status'] == 7) {
            $actions = array('order_send_o' => $core->lang['sendingo']);
        } elseif ($order['order_status'] == 8) {
            $actions = array('order_deliver_o' => $core->lang['delivero']);
        } elseif ($order['order_status'] == 9) {
            $actions = array('order_pay_o' => $core->lang['payo']);
        } else {
            $actions = false;
        }
        // Actions block
        if ($actions) {
            $core->tpl->block('body', 'actions');
            foreach ($actions as $b => $a) {
                $core->tpl->block('body', 'actions.block', array('name' => $core->lang[$b]));
                foreach ($a as $v => $n) {
                    $core->tpl->block('body', 'actions.block.a', array('n' => $n, 'v' => $v));
                }
            }
        }
        // Marks
        if ($order['order_status'] > 1 && $order['order_status'] < 5) {
            $marks = array('banip' => sprintf($core->lang['order_ban_ip'], int2ip($order['order_ip'])), 'banphone' => sprintf($core->lang['order_ban_phone'], $order['order_phone']));
            if ($oips > 1) {
                $ooips = $core->db->field("SELECT COUNT(*) FROM " . DB_ORDER . " WHERE order_id != '{$id}' AND order_ip = '" . $order['order_ip'] . "' AND order_status < 5 AND comp_id = '" . $order['comp_id'] . "'");
                if ($ooips) {
                    $marks['delip'] = sprintf($core->lang['order_del_ip'], $ooips);
                }
            }
            if ($ophs > 1) {
                $oophs = $core->db->field("SELECT COUNT(*) FROM " . DB_ORDER . " WHERE order_id != '{$id}' AND order_phone = '" . $order['order_phone'] . "' AND order_status < 5 AND comp_id = '" . $order['comp_id'] . "'");
                if ($oophs) {
                    $marks['delphone'] = sprintf($core->lang['order_del_phone'], $oophs);
                }
            }
        } else {
            $marks = array();
        }
        // Checking marks
        if ($order['order_status'] > 1 && $order['order_status'] < 10 && $order['order_status'] != 5) {
            if ($order['order_check']) {
                $marks['uncheck'] = $core->lang['order_uncheck'];
            } else {
                $marks['check'] = $core->lang['order_tocheck'];
            }
        }
        // Marks block
        if ($marks) {
            $core->tpl->block('body', 'marks');
            foreach ($marks as $v => $n) {
                $core->tpl->block('body', 'marks.mk', array('n' => $n, 'v' => $v));
            }
        }
        // Button blocks
        if ($order['order_status'] == 1) {
            $core->tpl->block('body', 'pickup', array('u' => $core->url('a', 'order-pickup', $id), 't' => $core->lang['order_pick_up'], 'c' => $core->lang['order_pick_confirm']));
        }
        if ($order['order_status'] != 5 && $order['order_status'] > 1 && $order['order_status'] < 10) {
            $core->tpl->block('body', 'buttons');
        }
        if ($order['geoip_country']) {
            $geoip = $order['geoip_city'] ? $order['geoip_city'] : '';
            if ($order['geoip_region']) {
                $geoip .= ', ' . $order['geoip_region'];
            }
            if ($order['geoip_district']) {
                $geoip .= ', ' . $order['geoip_district'];
            }
            $geoip = trim($geoip, ', ');
            if (!$geoip) {
                $geoip = $order['geoip_country'];
            }
            if ($order['geoip_lat'] && $order['geoip_lng']) {
                $geoip = '<a target="_blank" href="http://maps.yandex.ru/?ll=' . $order['geoip_lng'] . '%2C' . $order['geoip_lat'] . '">' . $geoip . '</a>';
            }
            $core->tpl->vars('body', array('order_country' => $geoip));
        }
        $core->tpl->output('body');
        $core->footer();
    } else {
        $where = array();
        // User filter
        if ($core->user->level || $core->user->call) {
            if (isset($core->get['c']) && $core->get['c']) {
                $c = (int) $core->get['c'];
                $where[] = "comp_id = '{$c}'";
            } else {
                $c = false;
            }
        } else {
            if (isset($core->get['a']) && ($a = (int) $core->get['a'])) {
                $where[] = "user_id = '" . $core->user->id . "'";
            } else {
                $where[] = "comp_id = '" . $core->user->comp . "'";
            }
            $manager = $core->wmsale->get('mans', $core->user->comp);
            $manager[0] = '———';
        }
        // WebMaster and Source Filters
        if (isset($core->get['wm']) && $core->get['wm']) {
            $wm = (int) $core->get['wm'];
            $where[] = "wm_id = '{$wm}'";
        } else {
            $wm = false;
        }
        if (isset($core->get['src']) && $core->get['src']) {
            $src = $core->text->link($core->get['src']);
            $where[] = "ext_src = '{$src}'";
        } else {
            $src = false;
        }
        // Search
        if (isset($core->get['s']) && $core->get['s']) {
            $s = $core->text->line($core->get['s']);
            if (preg_match('#^([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)$#i', $s) && ($ips = ip2int($s))) {
                $where[] = " order_ip = '{$ips}' ";
            } elseif (preg_match('#^[0-9]{11}$#i', $s)) {
                $where[] = " order_phone = '{$s}' ";
            } else {
                require_once PATH_CORE . 'search.php';
                $search = new SearchWords($core->get['s']);
                if ($s = $search->get()) {
                    $where[] = $search->field(array('order_name', 'order_addr', 'order_street', 'order_city', 'order_area'));
                } else {
                    $s = false;
                }
            }
        } else {
            $s = false;
        }
        // Status filtering
        if (isset($core->get['f']) && $core->get['f'] != '') {
            $f = (int) $core->get['f'];
            if ($f < 0) {
                switch ($f) {
                    case -1:
                        $where[] = "order_status NOT IN ( 5, 12 )";
                        break;
                    case -2:
                        $where[] = "order_status < 5";
                        break;
                    case -3:
                        $where[] = "order_status > 5 AND order_status < 12";
                        break;
                    default:
                        $f = '';
                }
            } else {
                $where[] = "order_status = '{$f}'";
            }
        } else {
            $f = '';
        }
        // Offer filtering
        if (isset($core->get['o']) && $core->get['o']) {
            $o = (int) $core->get['o'];
            $where[] = "offer_id = '{$o}'";
        } else {
            $o = false;
        }
        // Date filtering
        if ($d = $core->get['d']) {
            $dd = explode('-', $d);
            $ds = mktime(0, 0, 0, $dd[1], $dd[2], $dd[0]);
            $de = mktime(23, 59, 59, $dd[1], $dd[2], $dd[0]);
            $where[] = "( order_time BETWEEN '{$ds}' AND '{$de}' )";
        } else {
            $d = false;
        }
        $where = count($where) ? implode(' AND ', $where) : '1';
        $csv = $core->get['mode'] == 'csv' ? 1 : 0;
        $ipsl = $phsl = array();
        if (!$csv) {
            $sh = 20;
            $st = $sh * ($page - 1);
            $orders = $core->db->field("SELECT COUNT(*) FROM " . DB_ORDER . " WHERE {$where}");
            $order = $orders ? $core->db->data("SELECT * FROM " . DB_ORDER . " WHERE {$where} ORDER BY order_status ASC, order_time DESC LIMIT {$st}, {$sh}") : false;
            foreach ($order as &$ooo) {
                $ipsl[] = $ooo['order_ip'];
                $phls[] = $ooo['order_phone'];
            }
            unset($ooo);
        } else {
            $order = $core->db->data("SELECT * FROM " . DB_ORDER . " WHERE {$where} ORDER BY order_status ASC, order_time DESC");
        }
        $company = $core->user->comp ? $core->wmsale->get('comp', $core->user->comp) : false;
        $offer = $core->wmsale->get('offers');
        $vars = array();
        // Check for the bans
        if ($ipls || $phls) {
            require_once PATH . 'lib/ban.php';
            $banip = check_ip_bans($core, $ipls);
            $banph = check_phone_bans($core, $phls);
        } else {
            $banip = $banph = array();
        }
        $core->mainline->add($core->lang['orders_h'], $core->url('m', 'order'));
        if (!$csv) {
            $core->header();
        }
        $core->tpl->load('body', $csv ? 'csv-index' : 'index');
        $core->tpl->vars('body', array('title' => $core->lang['orders_h'], 'text' => $core->text->lines($core->lang['orders_t']), 'offer' => $core->lang['offer'], 'phone' => $core->lang['phone'], 'name' => $core->lang['username'], 'address' => $core->lang['address'], 'time' => $core->lang['time'], 'price' => $core->lang['price'], 'status' => $core->lang['status'], 'action' => $core->lang['action'], 'pay' => $core->lang['pay'], 'edit' => $core->lang['edit'], 'del' => $core->lang['del'], 'confirm' => $core->lang['confirma'], 'call_confirm' => $core->lang['order_call_confirm'], 'call_default' => $core->lang['order_call_action'], 'call_ok' => $core->lang['order_call_ok'], 'call_re' => $core->lang['order_call_re'], 'call_no' => $core->lang['order_call_no'], 'pickup' => $core->lang['order_pick_up'], 'pick_confirm' => $core->lang['order_pick_confirm'], 'packed' => $core->lang['order_packed'], 'packdocs' => $core->lang['order_pack_docs'], 'pack_confirm' => $core->lang['order_pack_confirm'], 'track_code' => $core->lang['track_code'], 'track_send' => $core->lang['track_send'], 'track_confirm' => $core->lang['track_confirm'], 'info' => $core->lang['inf'], 'work' => $core->lang['order_work'], 'pack' => $core->lang['order_pack'], 'cancel' => $core->lang['order_cancel'], 'later' => $core->lang['order_later'], 'showall' => $core->lang['order_showall'], 'company' => $core->lang['company'], 'd' => $d, 's' => $search ? $search->get() : $s, 'wm' => $wm, 'src' => $src, 'pages' => pages($core->url('m', '?') . ($f ? 'f=' . $f . '&' : '') . ($d ? 'd=' . $d . '&' : '') . ($s ? 's=' . $s . '&' : '') . ($a ? 'a=' . $a . '&' : '') . ($c ? 'c=' . $c . '&' : '') . ($o ? 'o=' . $o . '&' : '') . ($wm ? 'wm=' . $wm . '&' : '') . ($src ? 'src=' . $src . '&' : ''), $orders, $sh, $page), 'shown' => sprintf($core->lang['shown'], $st + 1, min($st + $sh, $orders), $orders), 'filter' => $core->lang['filter'], 'date' => $core->lang['date'], 'search' => $core->lang['search'], 'find' => $core->lang['find'], 'u_pickup' => $core->url('a', 'order-pickup', ''), 'o_pickup' => $core->lang['order_pick_up_smth'], 'u_courier' => $core->url('m', 'courier'), 'courier' => $core->lang['order_courier'], 'u_csv' => $core->url('m', '?mode=csv&') . ($f ? 'f=' . $f . '&' : '') . ($d ? 'd=' . $d . '&' : '') . ($s ? 's=' . $s . '&' : '') . ($a ? 'a=' . $a . '&' : '') . ($c ? 'c=' . $c . '&' : '') . ($o ? 'o=' . $o . '&' : '') . ($wm ? 'wm=' . $wm . '&' : '') . ($src ? 'src=' . $src . '&' : ''), 'esend' => $core->lang['order_esend'], 'es_confirm' => $core->lang['order_es_confirm'], 'o_1' => $f == -1 ? 'selected="selected"' : '', 'o_2' => $f == -2 ? 'selected="selected"' : '', 'o_3' => $f == -3 ? 'selected="selected"' : ''));
        if ($company['comp_spsr']) {
            $core->tpl->block('body', 'couriers');
        }
        if ($core->user->work < 2) {
            $core->tpl->block('body', 'pickitup');
        }
        foreach ($core->lang['statuso'] as $i => $st) {
            $core->tpl->block('body', 'status', array('name' => $st, 'value' => $i, 'select' => $f != '' && $f == $i ? 'selected="selected"' : ''));
        }
        $comp = $core->wmsale->get('comps');
        if ($core->user->level || $core->user->call) {
            $core->tpl->block('body', 'comps');
            foreach ($comp as $ci => $cn) {
                $core->tpl->block('body', 'comps.c', array('name' => $cn, 'value' => $ci, 'select' => $c == $ci ? 'selected="selected"' : ''));
            }
        } else {
            $core->tpl->block('body', 'all', array('a' => $a ? 'checked="checked"' : ''));
        }
        foreach ($offer as $i => $of) {
            $core->tpl->block('body', 'offer', array('name' => $of, 'value' => $i, 'select' => $o == $i ? 'selected="selected"' : ''));
        }
        $callscheme = ($callscheme = $core->wmsale->get('comp', $core->user->comp, 'callscheme')) ? $callscheme : 'tel:+%s';
        if ($order) {
            foreach ($order as &$r) {
                $addr = $r['order_addr'];
                if ($r['order_street']) {
                    $addr = $r['order_street'] . ', ' . $addr;
                }
                if ($r['order_city']) {
                    $addr = $r['order_city'] . ', ' . $addr;
                }
                if ($r['order_area']) {
                    $addr = $r['order_area'] . ', ' . $addr;
                }
                $addr = trim($addr, ', ');
                $uid = $r['wm_id'];
                $user = $uid ? $core->user->get($uid) : array();
                $core->tpl->block('body', 'ord', array('oid' => $r['offer_id'], 'offer' => $offer[$r['offer_id']], 'id' => $r['order_id'], 'ip' => int2ip($r['order_ip']), 'ip_class' => $banip[$r['order_ip']] ? $banip[$r['order_ip']] < 10 ? 'yellow' : 'red' : 'green', 'country' => $r['order_country'] ? $r['order_country'] : ($r['geoip_country'] ? $r['geoip_country'] : 'zz'), 'name' => $search ? $search->highlight($r['order_name']) : $r['order_name'], 'addr' => $search ? $search->highlight($addr) : $addr, 'index' => $r['order_index'], 'comment' => $r['order_comment'], 'phone' => $search ? $search->highlight($r['order_phone']) : $r['order_phone'], 'phone_call' => sprintf($callscheme, $r['order_phone']), 'phone_ok' => $r['order_phone_ok'] ? 'ok' : 'bad', 'phone_class' => $banph[$r['order_phone']] ? $banph[$r['order_phone']] < 10 ? 'yellow' : 'red' : 'green', 'count' => $r['order_count'], 'price' => rur($r['order_price']), 'price_csv' => (int) $r['order_price'], 'time' => smartdate($r['order_time']), 'stid' => $r['order_status'], 'status' => $core->lang['statuso'][$r['order_status']], 'edit' => $core->url('i', 'order', $r['order_id']), 'actcls' => $r['order_status'] < 5 || $r['order_status'] == 7 ? 'cb' : '', 'manager' => $manager[$r['user_id']], 'paid' => $r['paid_ok'], 'paidinfo' => $core->lang['order_paid'][$r['paid_ok']] . ($r['paid_time'] ? ' - ' . smartdate($r['paid_time']) : ''), 'calls' => $r['order_calls'] ? sprintf(' <small title="%s" class="red">(%s)</small>', $core->lang['order_calls'], $r['order_calls']) : '', 'delivery' => $r['order_delivery'], 'delivern' => $core->lang['delivers'][$r['order_delivery']], 'uid' => $uid, 'uname' => $uid ? $user['user_level'] ? '<b>' . $user['user_name'] . '</b>' : $user['user_name'] : $core->lang['order_src_sh'], 'uclass' => $r['order_check'] ? 'warn' : ($uid ? $r['ext_id'] ? 'ext' : ($user['user_vip'] ? 'vip' : 'user') : 'search')));
                if ($r['order_status'] == 1) {
                    $core->tpl->block('body', 'ord.pickup', array('u' => $core->url('a', 'order-pickup', $r['order_id'])));
                    if ($core->user->level || $core->user->call) {
                        $core->tpl->block('body', 'ord.pickup.move', array('u' => $core->url('a', 'order-move', $r['order_id'])));
                        foreach ($comp as $v => $n) {
                            $core->tpl->block('body', 'ord.pickup.move.comp', array('val' => $v, 'name' => $n));
                        }
                    }
                }
                if ($r['order_status'] > 1 && $r['order_status'] < 5) {
                    $core->tpl->block('body', 'ord.call', array('action' => $core->url('a', 'order-call', $r['order_id'])));
                    foreach ($core->lang['recallo'] as $v => $n) {
                        $core->tpl->block('body', 'ord.call.re', array('val' => $v, 'name' => $n));
                    }
                    foreach ($core->lang['nocallo'] as $v => $n) {
                        $core->tpl->block('body', 'ord.call.no', array('val' => $v, 'name' => $n));
                    }
                    foreach ($core->lang['reasono'] as $v => $n) {
                        $core->tpl->block('body', 'ord.call.cancel', array('val' => $v, 'name' => $n));
                    }
                }
                if ($r['order_status'] == 5) {
                    $core->tpl->block('body', 'ord.cancel', array('reason' => $r['order_reason'] ? $core->lang['reasono'][$r['order_reason']] : ($r['order_comment'] ? sprintf($core->lang['noreason_comment'], $r['order_comment']) : $core->lang['noreason'])));
                }
                if ($r['order_status'] == 6) {
                    $items = $r['order_items'] ? unserialize($r['order_items']) : false;
                    $iline = '';
                    if ($items) {
                        if (!count($vars[$r['offer_id']])) {
                            $vrs = $core->wmsale->get('vars', $r['offer_id']);
                            $vars[$r['offer_id']] = array();
                            foreach ($vrs as $w) {
                                $vars[$r['offer_id']][$w['var_id']] = $w['var_short'];
                            }
                        }
                        foreach ($items as $k => $x) {
                            $iline .= ' ' . $vars[$r['offer_id']][$k] . ': ' . $x . ' ';
                        }
                    }
                    $core->tpl->block('body', 'ord.pack', array('docs' => $core->url('a', 'order-docs', $r['order_id']), 'done' => $core->url('a', 'order-packed', $r['order_id']), 'items' => $iline));
                    if ($r['order_delivery'] == 1) {
                        $core->tpl->block('body', 'ord.pack.doc');
                    }
                }
                if ($r['order_status'] == 7) {
                    $core->tpl->block('body', 'ord.send', array('u' => $core->url('a', 'order-send', $r['order_id'])));
                    if ($r['order_delivery'] > 1) {
                        $core->tpl->block('body', 'ord.esend', array('u' => $core->url('a', 'order-esend', $r['order_id']), 'nc' => $r['order_courier'] ? 'new' : 'deliver', 'nu' => $core->url('a', $r['order_courier'] ? 'order-snew' : 'order-sold', $r['order_id']), 'nt' => $r['order_courier'] ? $core->lang['order_spsr_new'] : $core->lang['order_spsr_old']));
                    }
                }
                if ($r['order_status'] == 8 || $r['order_status'] == 9 || $r['order_status'] == 11) {
                    $core->tpl->block('body', 'ord.track', array('cls' => $r['track_status'] ? $r['order_status'] == 9 ? 'green' : 'blue' : 'red', 'check' => sprintf($core->lang['track_check'], smartdate($r['track_check'])), 'info' => $r['track_status'] ? sprintf("%s: %s", $r['track_date'], $r['track_status']) : $core->lang['track_wait'], 'url' => sprintf($core->lang['deliveru'][$r['order_delivery']], $r['track_code'])));
                    if ($r['order_status'] == 8) {
                        $core->tpl->block('body', 'ord.track.confirm', array('c' => $core->lang['order_arrive_conf'], 't' => $core->lang['order_arrived'], 'u' => $core->url('a', 'order-arrive', $r['order_id'])));
                    }
                    if ($r['order_status'] == 9) {
                        $core->tpl->block('body', 'ord.track.confirm', array('c' => $core->lang['order_payd_conf'], 't' => $core->lang['order_payd'], 'u' => $core->url('a', 'order-done', $r['order_id'])));
                    }
                }
                if ($core->user->level || $core->user->call) {
                    $core->tpl->block('body', 'ord.comp', array('id' => $r['comp_id'], 'name' => $comp[$r['comp_id']]));
                } else {
                    $core->tpl->block('body', 'ord.ip');
                }
            }
        }
        unset($r, $order);
        if ($core->user->work < 2 && $page < 2 && !($s || $f || $d || $a || $wm || $src)) {
            $recall = $core->user->call ? $core->db->data("SELECT * FROM " . DB_ORDER . " WHERE order_status IN ( 3, 4 ) AND order_recall < '" . time() . "'") : $core->db->data("SELECT * FROM " . DB_ORDER . " WHERE order_status IN ( 3, 4 ) AND order_recall < '" . time() . "' AND ( comp_id = '" . $core->user->comp . "' OR user_id = '" . $core->user->id . "' )");
            if ($recall) {
                $callscheme = ($callscheme = $core->wmsale->get('comp', $core->user->comp, 'callscheme')) ? $callscheme : 'tel:+%s';
                $core->tpl->block('body', 'recall', array('text' => $core->text->lines($core->lang['recall_t'])));
                foreach ($recall as &$r) {
                    $core->tpl->block('body', 'recall.ord', array('offer' => $offer[$r['offer_id']], 'id' => $r['order_id'], 'name' => $search ? $search->highlight($r['order_name']) : $r['order_name'], 'addr' => $search ? $search->highlight($r['order_addr']) : $r['order_addr'], 'index' => $r['order_index'], 'phone' => $search ? $search->highlight($r['order_phone']) : $r['order_phone'], 'phone_call' => sprintf($callscheme, $r['order_phone']), 'phone_ok' => $r['order_phone_ok'] ? 'ok' : 'bad', 'count' => $r['order_count'], 'price' => rur($r['order_price']), 'time' => smartdate($r['order_time']), 'stid' => $r['order_status'], 'status' => $core->lang['statuso'][$r['order_status']], 'calls' => $r['order_calls'] ? sprintf(' <small title="%s" class="red">(%s)</small>', $core->lang['order_calls'], $r['order_calls']) : '', 'action' => $core->url('a', 'order-call', $r['order_id']), 'edit' => $core->url('i', 'order', $r['order_id'])));
                    foreach ($core->lang['recallo'] as $v => $n) {
                        $core->tpl->block('body', 'recall.ord.re', array('val' => $v, 'name' => $n));
                    }
                    foreach ($core->lang['nocallo'] as $v => $n) {
                        $core->tpl->block('body', 'recall.ord.no', array('val' => $v, 'name' => $n));
                    }
                    foreach ($core->lang['reasono'] as $v => $n) {
                        $core->tpl->block('body', 'recall.ord.cancel', array('val' => $v, 'name' => $n));
                    }
                }
                unset($r, $recall);
            }
        }
        if ($csv) {
            header('Content-type: text/csv; charset=windows-1251');
            header('Content-disposition: attachment; filename=orders.csv');
            $core->tpl->output('body', 'windows-1251//IGNORE');
        } else {
            $core->tpl->output('body');
            $core->footer();
        }
    }
    $core->_die();
}