Example #1
0
/**
 * Imports page data from request parameters.
 * @param  string $source Source request method for parameters
 * @param  array  $rpage  Existing page data from database
 * @param  array  $auth   Permissions array
 * @return array          Page data
 */
function cot_page_import($source = 'POST', $rpage = array(), $auth = array())
{
    global $cfg, $db_pages, $cot_extrafields, $usr, $sys;
    if (count($auth) == 0) {
        $auth = cot_page_auth($rpage['page_cat']);
    }
    if ($source == 'D' || $source == 'DIRECT') {
        // A trick so we don't have to affect every line below
        global $_PATCH;
        $_PATCH = $rpage;
        $source = 'PATCH';
    }
    $rpage['page_cat'] = cot_import('rpagecat', $source, 'TXT');
    $rpage['page_keywords'] = cot_import('rpagekeywords', $source, 'TXT');
    $rpage['page_alias'] = cot_import('rpagealias', $source, 'TXT');
    $rpage['page_title'] = cot_import('rpagetitle', $source, 'TXT');
    $rpage['page_desc'] = cot_import('rpagedesc', $source, 'TXT');
    $rpage['page_text'] = cot_import('rpagetext', $source, 'HTM');
    $rpage['page_parser'] = cot_import('rpageparser', $source, 'ALP');
    $rpage['page_author'] = cot_import('rpageauthor', $source, 'TXT');
    $rpage['page_file'] = intval(cot_import('rpagefile', $source, 'INT'));
    $rpage['page_url'] = cot_import('rpageurl', $source, 'TXT');
    $rpage['page_size'] = (int) cot_import('rpagesize', $source, 'INT');
    $rpage['page_file'] = $rpage['page_file'] == 0 && !empty($rpage['page_url']) ? 1 : $rpage['page_file'];
    $rpagedatenow = cot_import('rpagedatenow', $source, 'BOL');
    $rpage['page_date'] = cot_import_date('rpagedate', true, false, $source);
    $rpage['page_date'] = $rpagedatenow || is_null($rpage['page_date']) ? $sys['now'] : (int) $rpage['page_date'];
    $rpage['page_begin'] = (int) cot_import_date('rpagebegin');
    $rpage['page_expire'] = (int) cot_import_date('rpageexpire');
    $rpage['page_expire'] = $rpage['page_expire'] <= $rpage['page_begin'] ? 0 : $rpage['page_expire'];
    $rpage['page_updated'] = $sys['now'];
    $rpage['page_keywords'] = cot_import('rpagekeywords', $source, 'TXT');
    $rpage['page_metatitle'] = cot_import('rpagemetatitle', $source, 'TXT');
    $rpage['page_metadesc'] = cot_import('rpagemetadesc', $source, 'TXT');
    $rpublish = cot_import('rpublish', $source, 'ALP');
    // For backwards compatibility
    $rpage['page_state'] = $rpublish == 'OK' ? 0 : cot_import('rpagestate', $source, 'INT');
    if ($auth['isadmin'] && isset($rpage['page_ownerid'])) {
        $rpage['page_count'] = cot_import('rpagecount', $source, 'INT');
        $rpage['page_ownerid'] = cot_import('rpageownerid', $source, 'INT');
        $rpage['page_filecount'] = cot_import('rpagefilecount', $source, 'INT');
    } else {
        $rpage['page_ownerid'] = $usr['id'];
    }
    $parser_list = cot_get_parsers();
    if (empty($rpage['page_parser']) || !in_array($rpage['page_parser'], $parser_list) || $rpage['page_parser'] != 'none' && !cot_auth('plug', $rpage['page_parser'], 'W')) {
        $rpage['page_parser'] = isset($sys['parser']) ? $sys['parser'] : $cfg['page']['parser'];
    }
    // Extra fields
    foreach ($cot_extrafields[$db_pages] as $exfld) {
        $rpage['page_' . $exfld['field_name']] = cot_import_extrafields('rpage' . $exfld['field_name'], $exfld, $source, $rpage['page_' . $exfld['field_name']]);
    }
    return $rpage;
}
Example #2
0
 $ruser['user_name'] = cot_import('rusername', 'P', 'TXT', 100, TRUE);
 $ruser['user_email'] = cot_import('ruseremail', 'P', 'TXT', 64, TRUE);
 $rpassword1 = cot_import('rpassword1', 'P', 'HTM', 32);
 $rpassword2 = cot_import('rpassword2', 'P', 'HTM', 32);
 $ruser['user_country'] = cot_import('rcountry', 'P', 'TXT');
 $ruser['user_timezone'] = cot_import('rusertimezone', 'P', 'TXT');
 $ruser['user_timezone'] = !$ruser['user_timezone'] ? $cfg['defaulttimezone'] : $ruser['user_timezone'];
 $ruser['user_gender'] = cot_import('rusergender', 'P', 'TXT');
 $ruser['user_email'] = mb_strtolower($ruser['user_email']);
 // Extra fields
 if (!empty(cot::$extrafields[cot::$db->users])) {
     foreach (cot::$extrafields[cot::$db->users] as $exfld) {
         $ruser['user_' . $exfld['field_name']] = cot_import_extrafields('ruser' . $exfld['field_name'], $exfld, 'P', '', 'user_');
     }
 }
 $ruser['user_birthdate'] = cot_import_date('ruserbirthdate', false);
 if (!is_null($ruser['user_birthdate']) && $ruser['user_birthdate'] > cot::$sys['now']) {
     cot_error('pro_invalidbirthdate', 'ruserbirthdate');
 }
 $user_exists = (bool) cot::$db->query("SELECT user_id FROM " . cot::$db->users . " WHERE user_name = ? LIMIT 1", array($ruser['user_name']))->fetch();
 $email_exists = (bool) cot::$db->query("SELECT user_id FROM " . cot::$db->users . " WHERE user_email = ? LIMIT 1", array($ruser['user_email']))->fetch();
 if (preg_match('/&#\\d+;/', $ruser['user_name']) || preg_match('/[<>#\'"\\/]/', $ruser['user_name'])) {
     cot_error('aut_invalidloginchars', 'rusername');
 }
 if (mb_strlen($ruser['user_name']) < 2) {
     cot_error('aut_usernametooshort', 'rusername');
 }
 if (mb_strlen($rpassword1) < 4) {
     cot_error('aut_passwordtooshort', 'rpassword1');
 }
 if (!cot_check_email($ruser['user_email'])) {
Example #3
0
switch ($rs['setlimit']) {
    case 1:
        $rs['setfrom'] = $sys['now'] - 1209600;
        break;
    case 2:
        $rs['setfrom'] = $sys['now'] - 2592000;
        break;
    case 3:
        $rs['setfrom'] = $sys['now'] - 7776000;
        break;
    case 4:
        $rs['setfrom'] = $sys['now'] - 31536000;
        break;
    case 5:
        $rs['setfrom'] = cot_import_date($rs['rfrom']);
        $rs['setto'] = cot_import_date($rs['rto']);
        break;
    default:
        break;
}
/* === Hook === */
foreach (cot_getextplugins('search.first') as $pl) {
    include $pl;
}
/* ===== */
if (($tab == 'pag' || empty($tab)) && cot_module_active('page') && $cfg['plugin']['search']['pagesearch']) {
    // Making the category list
    $pages_cat_list['all'] = $L['plu_allcategories'];
    foreach ($structure['page'] as $cat => $x) {
        if ($cat != 'all' && $cat != 'system' && cot_auth('page', $cat, 'R') && $x['group'] == 0) {
            $pages_cat_list[$cat] = $x['tpath'];
Example #4
0
switch ($rs['setlimit']) {
    case 1:
        $rs['setfrom'] = $sys['now'] - 1209600;
        break;
    case 2:
        $rs['setfrom'] = $sys['now'] - 2592000;
        break;
    case 3:
        $rs['setfrom'] = $sys['now'] - 7776000;
        break;
    case 4:
        $rs['setfrom'] = $sys['now'] - 31536000;
        break;
    case 5:
        $rs['setfrom'] = cot_import_date('rfrom', true, false, 'G');
        $rs['setto'] = cot_import_date('rto', true, false, 'G');
        break;
    default:
        break;
}
/* === Hook === */
foreach (cot_getextplugins('search.first') as $pl) {
    include $pl;
}
/* ===== */
if (($tab == 'pag' || empty($tab)) && cot_module_active('page') && $cfg['plugin']['search']['pagesearch']) {
    // Making the category list
    $pages_cat_list['all'] = $L['plu_allcategories'];
    foreach ($structure['page'] as $cat => $x) {
        if ($cat != 'all' && $cat != 'system' && cot_auth('page', $cat, 'R') && $x['group'] == 0) {
            $pages_cat_list[$cat] = $x['tpath'];
Example #5
0
 /**
  * Редактирование рассылки
  * @return string
  * @throws Exception
  */
 public function editAction()
 {
     global $cot_extrafields, $admintitle, $adminpath;
     $id = cot_import('id', 'G', 'INT');
     // id Рассылки
     $act = cot_import('act', 'G', 'ALP');
     if (empty($act)) {
         $act = cot_import('act', 'P', 'ALP');
     }
     $adminpath[] = array(cot_url('admin', array('m' => 'subscribe')), cot::$L['subscribe_subscribes']);
     /* === Hook === */
     foreach (cot_getextplugins('subscribe.admin.edit.first') as $pl) {
         include $pl;
     }
     /* ===== */
     if (!$id) {
         $item = new subscribe_model_Subscribe();
         $admintitle = cot::$L['subscribe_add_new'];
         $adminpath[] = array(cot_url('admin', array('m' => 'subscribe', 'a' => 'edit')), $admintitle);
     } else {
         $item = subscribe_model_Subscribe::getById($id);
         if (!$item) {
             cot_error(cot::$L['subscribe_err_not_found']);
             cot_redirect(cot_url('admin', array('m' => 'subscribe'), '', true));
         }
         if ($act == 'clone') {
             $id = null;
             $item = clone $item;
             $admintitle = cot::$L['subscribe_add_new'];
             $adminpath[] = array(cot_url('admin', array('m' => 'subscribe', 'a' => 'edit')), $admintitle);
         } else {
             $admintitle = $item->title . " [" . cot::$L['Edit'] . "]";
             $adminpath[] = array(cot_url('admin', array('m' => 'subscribe', 'a' => 'edit', 'id' => $item->id)), $admintitle);
         }
     }
     // Сохранение
     if ($act == 'save') {
         unset($_POST['id'], $_POST['user'], $_POST['x'], $_POST['act']);
         /* === Hook === */
         foreach (cot_getextplugins('subscribe.admin.save.first') as $pl) {
             include $pl;
         }
         /* ===== */
         $data = $_POST;
         $data['next_run'] = cot_import_date('next_run');
         if (!empty($data['next_run'])) {
             $data['next_run'] = date('Y-m-d H:i:s', $data['next_run']);
         }
         $item->setData($data);
         /* === Hook === */
         foreach (cot_getextplugins('subscribe.admin.save.validate') as $pl) {
             include $pl;
         }
         /* ===== */
         // There is some errors
         if (!$item->validate() || cot_error_found()) {
             $urlParams = array('m' => 'subscribe', 'a' => 'edit');
             if ($item->id > 0) {
                 $urlParams['id'] = $item->id;
             }
             cot_redirect(cot_url('admin', $urlParams, '', true));
         }
         $isNew = $item->id == 0;
         // Перерасчет времени следующего запуска
         // Делать это в админке при редактировании рассылки и при выполнении рассылки
         // А то могут быть коллизии
         $recalculate = true;
         if (!empty($item->next_run)) {
             $tmp = strtotime($item->next_run);
             if ($tmp > cot::$sys['now']) {
                 $recalculate = false;
             }
         }
         if ($recalculate) {
             $item->next_run = $item->getNextRunDate();
         }
         // Сохранение
         if ($item->save()) {
             cot_message(cot::$L['Saved']);
             $urlParams = array('m' => 'subscribe', 'a' => 'edit', 'id' => $item->id);
             $redirectUrl = cot_url('admin', $urlParams, '', true);
             /* === Hook === */
             foreach (cot_getextplugins('subscribe.admin.save.done') as $pl) {
                 include $pl;
             }
             /* ===== */
             // Редирект на станицу рассылки
             cot_redirect($redirectUrl);
         }
     }
     // 'input_textarea_editor', 'input_textarea_medieditor', 'input_textarea_minieditor', ''
     $editor = 'input_textarea_editor';
     /* === Hook === */
     foreach (cot_getextplugins('subscribe.admin.edit.main') as $pl) {
         include $pl;
     }
     /* ===== */
     $nextRun = 0;
     if (!empty($item->next_run)) {
         $nextRun = strtotime($item->next_run);
     }
     $formElements = array('hidden' => array('element' => cot_inputbox('hidden', 'act', 'save')), 'title' => array('element' => cot_inputbox('text', 'title', $item->rawValue('title')), 'required' => true, 'label' => subscribe_model_Subscribe::fieldLabel('title')), 'alias' => array('element' => cot_inputbox('text', 'alias', $item->rawValue('alias')), 'label' => subscribe_model_Subscribe::fieldLabel('alias')), 'admin_note' => array('element' => cot_textarea('admin_note', $item->rawValue('admin_note'), 5, 120, ''), 'label' => subscribe_model_Subscribe::fieldLabel('admin_note')), 'from_mail' => array('element' => cot_inputbox('text', 'from_mail', $item->rawValue('from_mail')), 'label' => subscribe_model_Subscribe::fieldLabel('from_mail'), 'hint' => cot::$L['subscribe_from_mail_hint']), 'from_title' => array('element' => cot_inputbox('text', 'from_title', $item->rawValue('from_title')), 'label' => subscribe_model_Subscribe::fieldLabel('from_title')), 'subject' => array('element' => cot_inputbox('text', 'subject', $item->rawValue('subject')), 'label' => subscribe_model_Subscribe::fieldLabel('subject')), 'description' => array('element' => cot_textarea('description', $item->rawValue('description'), 5, 120, '', $editor), 'label' => subscribe_model_Subscribe::fieldLabel('description')), 'content_url' => array('element' => cot_inputbox('text', 'content_url', $item->rawValue('content_url')), 'label' => subscribe_model_Subscribe::fieldLabel('content_url'), 'hint' => cot::$L['subscribe_content_url_hint']), 'text' => array('element' => cot_textarea('text', $item->rawValue('text'), 5, 120, '', $editor), 'label' => subscribe_model_Subscribe::fieldLabel('text'), 'hint' => cot::$L['subscribe_text_hint']), 'next_run' => array('element' => cot_selectbox_date($nextRun, 'long', 'next_run'), 'label' => subscribe_model_Subscribe::fieldLabel('next_run'), 'hint' => cot::$L['subscribe_next_run_hint'] . " " . cot::$usr['timetext']), 'sched_mday' => array('element' => cot_inputbox('text', 'sched_mday', $item->rawValue('sched_mday')), 'label' => subscribe_model_Subscribe::fieldLabel('sched_mday'), 'hint' => cot::$L['subscribe_sched_mday_hint']), 'sched_wday' => array('element' => cot_inputbox('text', 'sched_wday', $item->rawValue('sched_wday')), 'label' => subscribe_model_Subscribe::fieldLabel('sched_wday'), 'hint' => cot::$L['subscribe_sched_wday_hint']), 'sched_time' => array('element' => cot_inputbox('text', 'sched_time', $item->rawValue('sched_time')), 'label' => subscribe_model_Subscribe::fieldLabel('sched_time'), 'hint' => cot::$L['subscribe_sched_time_hint']), 'active' => array('element' => cot_checkbox($item->rawValue('active'), 'active', subscribe_model_Subscribe::fieldLabel('active'))), 'periodical' => array('element' => cot_checkbox($item->rawValue('periodical'), 'periodical', subscribe_model_Subscribe::fieldLabel('periodical'))), 'sort' => array('element' => cot_inputbox('text', 'sort', $item->rawValue('sort')), 'label' => subscribe_model_Subscribe::fieldLabel('sort')));
     if (!empty($cot_extrafields[cot::$db->subscribe])) {
         // Extra fields for subscribe
         foreach ($cot_extrafields[cot::$db->subscribe] as $exfld) {
             $fName = $exfld['field_name'];
             $formElements[$fName] = array('element' => cot_build_extrafields($fName, $exfld, $item->rawValue($fName)));
             if ($exfld['field_type'] !== 'checkbox') {
                 isset(cot::$L['subscribe_' . $exfld['field_name'] . '_title']) ? cot::$L['subscribe_' . $exfld['field_name'] . '_title'] : subscribe_model_Subscribe::fieldLabel($fName);
             }
         }
     }
     $subscribers = subscribe_model_Subscriber::count(array(array('subscribe', $item->id)));
     $activeSubscribers = subscribe_model_Subscriber::count(array(array('subscribe', $item->id), array('active', 1)));
     $actionParams = array('m' => 'subscribe', 'a' => 'edit');
     if ($item->id > 0) {
         $actionParams['id'] = $item->id;
     }
     $template = array('subscribe', 'admin', 'edit');
     $view = new View();
     $view->page_title = $admintitle;
     $view->item = $item;
     $view->subscribers = $subscribers;
     $view->activeSubscribers = $activeSubscribers;
     $view->formElements = $formElements;
     $view->formAction = cot_url('admin', $actionParams);
     /* === Hook === */
     foreach (cot_getextplugins('subscribe.admin.edit.view') as $pl) {
         include $pl;
     }
     /* ===== */
     return $view->render($template);
 }
Example #6
0
 public function editAction()
 {
     global $structure, $cot_extrafields, $db_structure;
     $id = cot_import('id', 'G', 'INT');
     // id Объявления
     $c = cot_import('c', 'G', 'TXT');
     $act = cot_import('act', 'G', 'ALP');
     if (empty($act)) {
         $act = cot_import('act', 'P', 'ALP');
     }
     /* === Hook === */
     foreach (cot_getextplugins('advboard.edit.first') as $pl) {
         include $pl;
     }
     /* ===== */
     // Права на любую категорию доски объявлений
     list(cot::$usr['auth_read'], cot::$usr['auth_write'], cot::$usr['isadmin']) = cot_auth('advboard', 'any');
     cot_block(cot::$usr['auth_write']);
     if (!$c || !isset($structure['advboard'][$c])) {
         cot_die_message(404, TRUE);
     }
     $category = $structure['advboard'][$c];
     $category['config'] = cot::$cfg['advboard']['cat_' . $c];
     $category['code'] = $c;
     // Extra fields for structure
     foreach ($cot_extrafields[$db_structure] as $exfld) {
         $uname = $exfld['field_name'];
         $val = $structure['advboard'][$c][$exfld['field_name']];
         $category[$uname . '_title'] = isset(cot::$L['structure_' . $exfld['field_name'] . '_title']) ? cot::$L['structure_' . $exfld['field_name'] . '_title'] : $exfld['field_description'];
         $category[$uname] = cot_build_extrafields_data('structure', $exfld, $val);
         $category[$uname . '_value'] = $val;
     }
     $published = 0;
     if (!$id) {
         $advert = new advboard_model_Advert();
         $advert->category = $c;
         $advert->user = cot::$usr['id'];
     } else {
         $advert = advboard_model_Advert::getById($id);
         if (!$advert) {
             cot_die_message(404, TRUE);
         }
         if (!cot::$usr['isadmin']) {
             if ($advert->user != cot::$usr['id']) {
                 cot_die_message(404, TRUE);
             }
         }
         if ($c != $advert->category && isset($structure['advboard'][$advert->category])) {
             $tmp = array('c' => $advert->category, 'a' => 'edit', 'id' => $advert->id);
             if (!empty($act)) {
                 $tmp['act'] = $act;
             }
             cot_redirect(cot_url('advboard', array('c' => $advert->category, 'a' => 'edit', 'id' => $advert->id), '', true));
         }
         if ($act == 'clone') {
             $id = null;
             $advert = clone $advert;
             // Установить статус и пользователя нового объекта
             $advert->user = cot::$usr['id'];
             $advert->state = advboard_model_Advert::DRAFT;
         }
         $published = $advert->state < 2 ? 1 : 0;
     }
     //Проверим права на категорию:
     list(cot::$usr['auth_read'], cot::$usr['auth_write'], cot::$usr['isadmin'], cot::$usr['auth_upload']) = cot_auth('advboard', $c, 'RWA1');
     if ($structure['advboard'][$c]['locked'] && !cot::$usr['isadmin']) {
         cot_die_message(602, TRUE);
     } elseif ($advert->id == 0) {
         // Если у пользователя нет прав на подачу объявления, то ищем категорию куда он может подать оьбъявление
         if (!cot::$usr['auth_write']) {
             foreach ($structure['advboard'] as $catCode => $catRow) {
                 $auth_write = cot_auth('advboard', $catCode, 'W');
                 if ($auth_write) {
                     cot_redirect(cot_url('advboard', array('c' => $catCode, 'a' => 'edit'), '', true));
                 }
             }
         }
         cot_block(cot::$usr['auth_write']);
     }
     // Владелец объявления
     $user = array();
     if ($advert->user > 0) {
         $user = cot_user_data($advert->user);
     }
     $periodItems = adv_periodItems($c);
     // Сохранение
     if ($act == 'save') {
         unset($_POST['id'], $_POST['user']);
         cot_shield_protect();
         /* === Hook === */
         foreach (cot_getextplugins('advboard.save.first') as $pl) {
             include $pl;
         }
         /* ===== */
         // импортировать даты
         $begin = (int) cot_import_date('begin');
         $expire = (int) cot_import_date('expire');
         if ($begin == 0) {
             $begin = !empty($advert->begin) ? $advert->begin : cot::$sys['now'];
         }
         // Пересчитать период публикации объявления
         if ($expire == 0 && cot::$cfg['advboard']['cat_' . $c]['maxPeriod'] > 0) {
             $period = cot_import('period', 'P', 'INT');
             $maxPeriod = max($periodItems);
             if (empty($period)) {
                 $period = $maxPeriod;
             }
             if (!cot::$usr['isadmin'] && $period > $maxPeriod) {
                 $period = $maxPeriod;
             }
             if ($period > 0) {
                 $expire = $begin + $period * 86400;
             }
         }
         if ($category['config']['title_require']) {
             $advert->setValidator('title', 'required');
         }
         // Валидатор 'allowemptytext'
         if (!$category['config']['allowemptytext']) {
             $advert->setValidator('text', 'required');
         }
         if ($category['config']['phone_require']) {
             // проверить надичие заполненного поля в профиле пользователя - владельца
             if (empty($user['user_phone'])) {
                 $advert->setValidator('phone', 'required');
             }
         }
         if ($category['config']['city_require']) {
             // Проверить наличие заполненного города (id или названия) в профиле владельца
             if (empty($user['user_city_name']) && empty($user['user_city'])) {
                 if (cot_plugin_active('regioncity')) {
                     $advert->setValidator('city', function ($value) {
                         $value = (int) $value;
                         if ($value == 0) {
                             return cot::$L['field_required'] . ': ' . advboard_model_Advert::fieldLabel('city');
                         }
                         return true;
                     });
                 } else {
                     $advert->setValidator('city_name', 'required');
                 }
             }
         }
         if (cot::$usr['id'] == 0) {
             $advert->setValidator('person', 'required');
             // Email
             $email = cot_import('email', 'P', 'TXT');
             if (cot::$cfg['advboard']['guestEmailRequire']) {
                 if ($email == '') {
                     cot_error(cot::$L['advboard_err_noemail'], 'email');
                 }
             }
             if ($email != '') {
                 $tmp = advert_checkEmail($email);
                 if ($tmp !== true) {
                     cot_error($tmp, 'email');
                 }
             }
             // Капча
             if (cot::$cfg['advboard']['guestUseCaptcha']) {
                 $verify = cot_import('verify', 'P', 'TXT');
                 if (!cot_captcha_validate($verify)) {
                     cot_error(cot::$L['captcha_verification_failed'], 'verify');
                 }
             }
         }
         $advert->setData($_POST);
         $advert->begin = $begin;
         $advert->expire = $expire;
         if (!cot::$usr['isadmin']) {
             if (!cot::$cfg['advboard']['cat_' . $c]['allowSticky']) {
                 $advert->sticky = 0;
             }
             if (cot::$usr['id'] == 0) {
                 $advert->sticky = 0;
             }
             // гости не дают срочных объявлений
         }
         $advert->category = $c;
         if (empty($advert->user) || !cot::$usr['isadmin']) {
             $advert->user = cot::$usr['id'];
         }
         $published = cot_import('published', 'P', 'BOL');
         if (!$published) {
             $advert->state = advboard_model_Advert::DRAFT;
         } elseif (cot::$usr['isadmin'] || cot_auth('advboard', $c, '2')) {
             $advert->state = advboard_model_Advert::PUBLISHED;
         } else {
             $advert->state = advboard_model_Advert::AWAITING_MODERATION;
         }
         /* === Hook === */
         foreach (cot_getextplugins('advboard.save.validate') as $pl) {
             include $pl;
         }
         /* ===== */
         // There is some errors
         if (!$advert->validate() || cot_error_found()) {
             $urlParams = array('c' => $c, 'a' => 'edit');
             if ($advert->id > 0) {
                 $urlParams['id'] = $advert->id;
             }
             cot_redirect(cot_url('advboard', $urlParams, '', true));
         }
         if (empty($advert->sort)) {
             $advert->sort = cot::$sys['now'];
         }
         $isNew = $advert->id == 0;
         // Сохранение
         if ($advert->save()) {
             // Для незарега запомним id страницы для чтого, чтобы он мог ее отредактировать в пределах сесии
             if ($isNew) {
                 if (cot::$usr['id'] == 0) {
                     if (empty($_SESSION['advboard'])) {
                         $_SESSION['advboard'] = array();
                     }
                     if (!in_array($id, $_SESSION['advboard'])) {
                         $_SESSION['advboard'][] = $advert->id;
                     }
                 }
                 if ($advert->state == advboard_model_Advert::PUBLISHED) {
                     cot_message(cot::$L['advboard_created']);
                 }
             } else {
                 if ($advert->state == advboard_model_Advert::PUBLISHED) {
                     cot_message(cot::$L['advboard_updated']);
                 }
             }
             if ($advert->state == advboard_model_Advert::AWAITING_MODERATION) {
                 cot_message(cot::$L['advboard_awaiting_moderation']);
             } elseif ($advert->state == advboard_model_Advert::DRAFT) {
                 cot_message(cot::$L['Saved']);
             }
             $redirectUrl = $advert->getUrl(true);
             /* === Hook === */
             foreach (cot_getextplugins('advboard.save.done') as $pl) {
                 include $pl;
             }
             /* ===== */
             // Редирект на станицу объявления
             cot_redirect($redirectUrl);
         }
     }
     $crumbs = cot_structure_buildpath('advboard', $c);
     if (cot::$cfg['advboard']['firstCrumb']) {
         array_unshift($crumbs, array(cot_url('advboard'), cot::$L['advboard_ads']));
     }
     if (!$id) {
         $crumbs[] = $title = cot::$L['advboard_add_new'];
         cot::$out['subtitle'] = $title;
     } else {
         $crumbs[] = array($advert->url, $advert->title);
         $crumbs[] = cot::$L['Edit'];
         $title = cot::$L['advboard_advert'] . ' #' . $advert->id;
         if (!empty($advert->title)) {
             $title = $advert->title;
         }
         $title .= ': ' . cot::$L['Edit'];
         if (!empty(cot::$out['subtitle'])) {
             $title .= ' - ' . cot::$out['subtitle'];
         }
         cot::$out['subtitle'] = $title;
     }
     // Elemets placeholders
     $placeHolder_Person = '';
     $placeHolder_Phone = '';
     $placeHolder_Email = '';
     $placeHolder_City = '';
     //if($advboard->user == cot::$usr['id'] && cot::$usr['id'] > 0) {
     if (!empty($user)) {
         // Контакное лицо
         $placeHolder_Person = cot_user_full_name($user);
         // Телефон
         if (!empty($user['user_phone'])) {
             $placeHolder_Phone = $user['user_phone'];
         }
         // email
         if (!$user['user_hideemail']) {
             $placeHolder_Email = $user['user_email'];
         }
         // город
         if (!empty($user['user_city_name'])) {
             $placeHolder_City = $user['user_city_name'];
         }
     }
     // 'input_textarea_editor', 'input_textarea_medieditor', 'input_textarea_minieditor', ''
     $editor = 'input_textarea_editor';
     /* === Hook === */
     foreach (cot_getextplugins('advboard.edit.main') as $pl) {
         include $pl;
     }
     /* ===== */
     $minYear = date('Y');
     $maxYear = $minYear + 30;
     $price = $advert->rawValue('price');
     if ($price <= 0) {
         $price = '';
     }
     $formElements = array('hidden' => array('element' => cot_inputbox('hidden', 'act', 'save')), 'category' => array('element' => cot_selectbox_structure('advboard', $advert->category, 'category'), 'label' => advboard_model_Advert::fieldLabel('category')), 'price' => array('element' => cot_inputbox('text', 'price', $price), 'label' => advboard_model_Advert::fieldLabel('price'), 'hint' => cot::$L['advboard_price_hint']), 'title' => array('element' => cot_inputbox('text', 'title', $advert->rawValue('title')), 'required' => true, 'label' => advboard_model_Advert::fieldLabel('title')), 'description' => array('element' => cot_inputbox('text', 'description', $advert->rawValue('description')), 'label' => advboard_model_Advert::fieldLabel('description')), 'text' => array('element' => cot_textarea('text', $advert->rawValue('text'), 5, 120, '', $editor), 'label' => advboard_model_Advert::fieldLabel('text')), 'person' => array('element' => cot_inputbox('text', 'person', $advert->rawValue('person'), array('class' => 'form-control', 'placeholder' => $placeHolder_Person)), 'label' => advboard_model_Advert::fieldLabel('person'), 'required' => cot::$usr['id'] == 0), 'email' => array('element' => cot_inputbox('text', 'email', $advert->rawValue('email'), array('class' => 'form-control', 'placeholder' => $placeHolder_Email)), 'label' => advboard_model_Advert::fieldLabel('email')), 'city' => array('element' => cot_inputbox('text', 'city_name', $advert->rawValue('city_name'), array('class' => 'form-control', 'placeholder' => $placeHolder_City)), 'label' => advboard_model_Advert::fieldLabel('city_name'), 'required' => $category['config']['city_require']), 'phone' => array('element' => cot_inputbox('text', 'phone', $advert->rawValue('phone'), array('class' => 'form-control', 'placeholder' => $placeHolder_Phone)), 'label' => advboard_model_Advert::fieldLabel('phone'), 'required' => $category['config']['phone_require']), 'sticky' => array('element' => cot_checkbox($advert->sticky, 'sticky', advboard_model_Advert::fieldLabel('sticky')), 'label' => advboard_model_Advert::fieldLabel('sticky')), 'published' => array('element' => cot_checkbox($published, 'published', cot::$L['advboard_published'] . '?'), 'label' => cot::$L['advboard_published'] . '?'), 'begin' => array('element' => cot_selectbox_date($advert->begin, 'long', 'begin', $maxYear, $minYear), 'label' => advboard_model_Advert::fieldLabel('begin')), 'expire' => array('element' => cot_selectbox_date($advert->expire, 'long', 'expire', $maxYear, $minYear), 'label' => advboard_model_Advert::fieldLabel('expire')), 'sort' => array('element' => cot_selectbox_date($advert->sort, 'long', 'sort', $maxYear, $minYear), 'label' => advboard_model_Advert::fieldLabel('sort')), 'period' => array('element' => cot_selectbox('', 'period', $periodItems, array(), false), 'label' => cot::$L['advboard_period']));
     if (!empty($cot_extrafields[cot::$db->advboard])) {
         // Extra fields for ads
         foreach ($cot_extrafields[cot::$db->advboard] as $exfld) {
             $fName = $exfld['field_name'];
             $formElements[$fName] = array('element' => cot_build_extrafields($fName, $exfld, $advert->rawValue($fName)));
             if ($exfld['field_type'] !== 'checkbox') {
                 $formElements[$fName]['label'] = isset(cot::$L['advboard_' . $exfld['field_name'] . '_title']) ? cot::$L['advboard_' . $exfld['field_name'] . '_title'] : advboard_model_Advert::fieldLabel($fName);
             }
         }
     }
     if (cot_plugin_active('regioncity')) {
         $formElements['city']['element'] = rec_select2_city('city', $advert->rawValue('city'), true, array('class' => 'form-control', 'placeholder' => $placeHolder_City));
     }
     if ($category['config']['city_require']) {
         $formElements['city']['required'] = true;
     }
     if ($category['config']['phone_require']) {
         $formElements['phone']['required'] = true;
     }
     // Hints
     if (!empty($user)) {
         // Контакное лицо
         $formElements['person']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . cot_user_full_name($user);
         // Телефон
         if (!empty($user['user_phone'])) {
             $formElements['phone']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . $user['user_phone'];
         }
         // email
         if (!$user['user_hideemail']) {
             $formElements['email']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . $user['user_email'];
         }
         // город
         if (!empty($user['user_city_name'])) {
             $formElements['city']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . $user['user_city_name'];
         }
     }
     if (!cot::$usr['isadmin']) {
         unset($formElements['begin']);
         unset($formElements['expire']);
         unset($formElements['sort']);
         if (cot::$usr['id'] == 0) {
             if (cot::$cfg['advboard']['guestEmailRequire']) {
                 $formElements['email']['required'] = true;
             }
             // Гости не дают срочных объявлений
             unset($formElements['sticky']);
             // Капча
             if (cot::$cfg['advboard']['guestUseCaptcha']) {
                 $formElements['verify'] = array('element' => cot_inputbox('text', 'verify'), 'img' => cot_captcha_generate(), 'label' => cot::$L['advboard_captcha'], 'required' => true);
             }
         }
         if (!cot::$cfg['advboard']['cat_' . $c]['allowSticky'] && isset($formElements['sticky'])) {
             unset($formElements['sticky']);
         }
     } else {
         // Администратор напрямую указывает дату окончания публикации
         unset($formElements['period']);
     }
     $actionParams = array('a' => 'edit', 'c' => $advert->category);
     if ($advert->id > 0) {
         $actionParams['id'] = $advert->id;
     }
     $view = new View();
     $view->breadcrumbs = cot_breadcrumbs($crumbs, cot::$cfg['homebreadcrumb'], true);
     $view->page_title = $title;
     $view->category = $category;
     $view->advert = $advert;
     $view->user = $user;
     $view->formElements = $formElements;
     $view->formAction = cot_url('advboard', $actionParams);
     /* === Hook === */
     foreach (cot_getextplugins('advboard.edit.view') as $pl) {
         include $pl;
     }
     /* ===== */
     return $view->render(array('advboard', 'edit', $structure['advboard'][$c]['tpl']));
 }
Example #7
0
 public function clearAction()
 {
     $sort = cot_import('s', 'G', 'TXT');
     // order field name
     $way = cot_import('w', 'G', 'ALP', 4);
     // order way (asc, desc)
     $f = cot_import('f', 'G', 'ARR');
     // filters
     $f['date_from'] = cot_import_date('f_df', true, false, 'G');
     $f['date_to'] = cot_import_date('f_dt', true, false, 'G');
     $sort = empty($sort) ? 't.date' : $sort;
     $way = empty($way) || !in_array($way, array('asc', 'desc')) ? 'desc' : $way;
     $urlParams = array('m' => 'brs', 'n' => 'track');
     if ($sort != 't.date') {
         $urlParams['s'] = $sort;
     }
     if ($way != 'desc') {
         $urlParams['w'] = $way;
     }
     $where = array();
     $params = array();
     $baWhere = array();
     if (!empty($f)) {
         foreach ($f as $key => $val) {
             $val = trim(cot_import($val, 'D', 'TXT'));
             if (empty($val) && $val !== '0') {
                 continue;
             }
             if (in_array($key, array('b.title'))) {
                 $kkey = str_replace('.', '_', $key);
                 $params[$kkey] = "%{$val}%";
                 $baWhere[] = "{$key} LIKE :{$kkey}";
                 $urlParams["f[{$key}]"] = $val;
             } elseif ($key == 'date_from') {
                 if ($f[$key] == 0) {
                     continue;
                 }
                 $where['filter'][] = "date >= '" . date('Y-m-d H:i:s', $f[$key]) . "'";
                 $urlParams["f_df[year]"] = cot_date('Y', $f[$key]);
                 $urlParams["f_df[month]"] = cot_date('m', $f[$key]);
                 $urlParams["f_df[day]"] = cot_date('d', $f[$key]);
             } elseif ($key == 'date_to') {
                 if ($f[$key] == 0) {
                     continue;
                 }
                 $where['filter'][] = "date <= '" . date('Y-m-d H:i:s', $f[$key]) . "'";
                 $urlParams["f_dt[year]"] = cot_date('Y', $f[$key]);
                 $urlParams["f_dt[month]"] = cot_date('m', $f[$key]);
                 $urlParams["f_dt[day]"] = cot_date('d', $f[$key]);
             } else {
                 $kkey = str_replace('.', '_', $key);
                 $params[$kkey] = $val;
                 if (mb_strpos($key, 'b.') === 0) {
                     $baWhere[] = "{$key} = :{$kkey}";
                 } else {
                     $where['filter'][] = "{$key} = :{$kkey}";
                 }
                 $urlParams["f[{$key}]"] = $val;
             }
         }
         empty($where['filter']) || ($where['filter'] = implode(' AND ', $where['filter']));
     } else {
         $f = array();
     }
     if (!empty($baWhere)) {
         $where['banners'] = "banner IN (SELECT b.id FROM " . cot::$db->banners . " AS b WHERE " . implode(' AND ', $baWhere) . " )";
     }
     $where = implode(' AND ', $where);
     $res = cot::$db->delete(cot::$db->banner_tracks, $where, $params);
     if ($res > 0) {
         cot_message(sprintf(cot::$L['brs_deleted_records'], $res));
     } else {
         cot_message(cot::$L['brs_deleted_no']);
     }
     cot_redirect(cot_url('admin', $urlParams, '', true));
 }
Example #8
0
/**
 * Imports Extra fields data
 *
 * @param string $inputname Variable name (or value for source=D)
 * @param array $extrafields Extra fields data
 * @param string $source Source type: G (GET), P (POST), C (COOKIE) or D (variable filtering)
 * @param string $oldvalue Old value of extrafield
 * @return string
 */
function cot_import_extrafields($inputname, $extrafield, $source = 'P', $oldvalue = '')
{
    global $L;
    switch ($extrafield['field_type']) {
        case 'input':
            $import = $extrafield['field_parse'] == 'Text' ? cot_import($inputname, $source, 'TXT') : cot_import($inputname, $source, 'HTM');
            if (!empty($extrafield['field_params']) && !is_null($import) && !preg_match($extrafield['field_params'], $import)) {
                $L['field_pregmatch_' . $extrafield['field_name']] = isset($L['field_pregmatch_' . $extrafield['field_name']]) ? $L['field_pregmatch_' . $extrafield['field_name']] : $L['field_pregmatch'];
                cot_error('field_pregmatch_' . $extrafield['field_name'], $inputname);
            }
            break;
        case 'inputint':
        case 'range':
            $extrafield['field_params'] = str_replace(array(' , ', ', ', ' ,'), ',', $extrafield['field_params']);
            $import = cot_import($inputname, $source, 'INT');
            if (!is_null($import) && !empty($extrafield['field_params'])) {
                list($min, $max) = explode(",", $extrafield['field_params'], 2);
                $min = (int) $min;
                $max = (int) $max;
                if ($import < $min || $import > $max) {
                    cot_error('field_range_' . $extrafield['field_name'], $inputname);
                }
            }
            break;
        case 'currency':
        case 'double':
            $extrafield['field_params'] = str_replace(array(' , ', ', ', ' ,'), ',', $extrafield['field_params']);
            $import = cot_import($inputname, $source, 'NUM');
            if (!is_null($import)) {
                $import = floatval($import);
            }
            if (!is_null($import) && !empty($extrafield['field_params'])) {
                list($min, $max) = explode(",", $extrafield['field_params'], 2);
                $min = (int) $min;
                $max = (int) $max;
                if ($import < $min || $import > $max) {
                    cot_error('field_range_' . $extrafield['field_name'], $inputname);
                }
            }
            break;
        case 'textarea':
            $import = cot_import($inputname, $source, 'HTM');
            break;
        case 'select':
        case 'radio':
            $extrafield['field_variants'] = str_replace(array(' , ', ', ', ' ,'), ',', $extrafield['field_variants']);
            $opt_array = explode(",", trim($extrafield['field_variants']));
            $import = cot_import($inputname, $source, 'HTM');
            if (!is_null($import) && !in_array(trim($import), $opt_array)) {
                $L['field_notinarray_' . $extrafield['field_name']] = isset($L['field_notinarray_' . $extrafield['field_name']]) ? $L['field_notinarray_' . $extrafield['field_name']] : $L['field_notinarray'];
                cot_error('field_notinarray_' . $extrafield['field_name'], $inputname);
            }
            break;
        case 'checkbox':
            $import = cot_import($inputname, $source, 'BOL');
            break;
        case 'datetime':
            $extrafield['field_params'] = str_replace(array(' , ', ', ', ' ,'), ',', $extrafield['field_params']);
            list($min, $max) = explode(",", $extrafield['field_params'], 2);
            $import = cot_import_date($inputname, true, false, $source);
            if (!is_null($import) && ((int) $min > 0 || (int) $max > 0)) {
                list($s_year, $s_month, $s_day, $s_hour, $s_minute) = explode('-', @date('Y-m-d-H-i', $import));
                if ($min > $s_year) {
                    $import = mktime($s_hour, $s_minute, 0, $s_month, $s_day, $min);
                }
                if ($max < $s_year) {
                    $import = mktime($s_hour, $s_minute, 0, $s_month, $s_day, $max);
                }
            }
            break;
        case 'country':
            $import = cot_import($inputname, $source, 'ALP');
            break;
        case 'checklistbox':
            $import = cot_import($inputname, $source, 'ARR');
            $extrafield['field_variants'] = str_replace(array(' , ', ', ', ' ,'), ',', $extrafield['field_variants']);
            $opt_array = explode(',', trim($extrafield['field_variants']));
            if (count($import) < 1) {
                $import = null;
            } elseif (count($import) == 1 && isset($import['nullval'])) {
                $import = array();
            } else {
                unset($import['nullval']);
                foreach ($import as $k => $v) {
                    $import[$k] = cot_import($v, 'D', 'HTM');
                    if (!is_null($import[$k]) && !in_array($import[$k], $opt_array)) {
                        $L['field_notinarray_' . $extrafield['field_name']] = isset($L['field_notinarray_' . $extrafield['field_name']]) ? $L['field_notinarray_' . $extrafield['field_name']] : $L['field_notinarray'];
                        cot_error('field_notinarray_' . $extrafield['field_name'], $inputname);
                    }
                }
            }
            if (is_array($import)) {
                $import = implode(',', $import);
            }
            break;
        case 'file':
            global $lang, $cot_translit, $exfldfiles, $exfldsize, $cfg, $uploadfiles, $pl;
            if ($source == 'P' || $source == 'POST') {
                $import = $_FILES[$inputname];
                $import['delete'] = cot_import('rdel_' . $inputname, 'P', 'BOL') ? 1 : 0;
            } elseif ($source == 'D') {
                $import = $inputname;
            }
            /* === Hook === */
            foreach (cot_getextplugins('extrafields.import.file.first') as $pl) {
                include $pl;
            }
            /* ===== */
            if (is_array($import) && !$import['error'] && !empty($import['name'])) {
                $fname = mb_substr($import['name'], 0, mb_strrpos($import['name'], '.'));
                $ext = mb_strtolower(mb_substr($import['name'], mb_strrpos($import['name'], '.') + 1));
                //check extension
                $extrafield['field_variants'] = str_replace(array(' , ', ', ', ' ,'), ',', mb_strtolower($extrafield['field_variants']));
                $ext_array = explode(",", trim($extrafield['field_variants']));
                if (empty($extrafield['field_variants']) || in_array($ext, $ext_array)) {
                    if ($lang != 'en' && file_exists(cot_langfile('translit', 'core'))) {
                        require_once cot_langfile('translit', 'core');
                        $fname = is_array($cot_translit) ? strtr($fname, $cot_translit) : '';
                    }
                    $fname = str_replace(array(' ', '  ', '__'), '_', $fname);
                    $fname = preg_replace('#[^a-zA-Z0-9\\-_\\.\\ \\+]#', '', $fname);
                    $fname = str_replace('..', '.', $fname);
                    $fname = str_replace('__', '_', $fname);
                    $fname = empty($fname) ? cot_unique() : $fname;
                    // Generate unique file name. Old file - must be removed any way
                    $extrafield['field_params'] = !empty($extrafield['field_params']) ? $extrafield['field_params'] : $cfg['extrafield_files_dir'];
                    $extrafield['field_params'] .= mb_substr($extrafield['field_params'], -1) == '/' ? '' : '/';
                    if (file_exists("{$extrafield['field_params']}{$fname}.{$ext}")) {
                        $fname = $inputname . '_' . date("YmjGis") . '_' . $fname;
                    }
                    $fname .= '.' . $ext;
                    $file['old'] = !empty($oldvalue) && ($import['delete'] || $import['tmp_name']) ? $extrafield['field_params'] . $oldvalue : '';
                    $file['field'] = $extrafield['field_name'];
                    $file['tmp'] = !$import['delete'] ? $import['tmp_name'] : '';
                    $file['new'] = !$import['delete'] ? $extrafield['field_params'] . $fname : '';
                    /* === Hook === */
                    foreach (cot_getextplugins('extrafields.import.file.done') as $pl) {
                        include $pl;
                    }
                    /* ===== */
                    $exfldsize[$extrafield['field_name']] = $import['size'];
                    $uploadfiles[] = $file;
                    $import = $fname;
                } else {
                    cot_error('field_extension_' . $extrafield['field_name'], $inputname);
                    $exfldsize[$extrafield['field_name']] = null;
                    $import = null;
                }
            } elseif (is_array($import) && $import['delete']) {
                $exfldsize[$extrafield['field_name']] = 0;
                $import = '';
                $extrafield['field_params'] = !empty($extrafield['field_params']) ? $extrafield['field_params'] : $cfg['extrafield_files_dir'];
                $file['old'] = !empty($oldvalue) ? "{$extrafield['field_params']}/{$oldvalue}" : '';
                $file['field'] = $extrafield['field_name'];
                $uploadfiles[] = $file;
            } else {
                $exfldsize[$extrafield['field_name']] = null;
                $import = null;
            }
            break;
        case 'filesize':
            global $exfldsize;
            $import = $exfldsize[$extrafield['field_variants']];
            break;
    }
    if ((is_null($import) || $import === '') && $extrafield['field_required']) {
        $fname = !empty($extrafield['field_description']) ? $extrafield['field_description'] : $extrafield['field_name'];
        $msg = isset($L['field_required_' . $extrafield['field_name']]) ? 'field_required_' . $extrafield['field_name'] : $L['field_required'] . ': ' . $fname;
        cot_error($msg, $inputname);
    }
    return $import;
}
Example #9
0
 /**
  * Создание / редактирование купона
  * @todo произвольный урл баннера
  * @return string
  */
 public function editAction()
 {
     global $admintitle, $adminpath, $structure, $cot_import_filters;
     $adminpath[] = array(cot_url('admin', array('m' => 'brs')), cot::$L['brs_banners']);
     if (empty($structure['brs'])) {
         cot_error(cot::$L['brs_category_no']);
     }
     $id = cot_import('id', 'G', 'INT');
     $act = cot_import('act', 'P', 'ALP');
     if (!$id) {
         $id = 0;
         $item = new brs_model_Banner();
         $admintitle = $title = cot::$L['brs_banner_new'];
         $adminpath[] = array(cot_url('admin', array('m' => 'brs', 'a' => 'edit')), cot::$L['brs_banner_new']);
     } else {
         $item = brs_model_Banner::getById($id);
         if (!$item) {
             cot_error(cot::$L['brs_err_not_found']);
             cot_redirect(cot_url('admin', array('m' => 'brs'), '', true));
         }
         $title = htmlspecialchars($item->title) . ' [' . cot::$L['Edit'] . ']';
         $admintitle = cot::$L['brs_banner_edit'];
         $adminpath[] = array(cot_url('admin', array('m' => 'brs', 'a' => 'edit', 'id' => $id)), $title);
     }
     if ($act == 'save') {
         unset($_POST['id']);
         $data = $_POST;
         $nullDate = date('Y-m-d H:i:s', 0);
         // 1970-01-01 00:00:00
         // Импортируем файл
         $file = brs_importFile('file', $item->file);
         $delFile = cot_import('del_file', 'P', 'BOL') ? 1 : 0;
         if ($delFile) {
             $data['file'] = '';
         }
         // Импортируем даты
         $data['publish_up'] = cot_import_date('publish_up');
         if (!empty($data['publish_up'])) {
             $data['publish_up'] = date('Y-m-d H:i:s', $data['publish_up']);
         } else {
             $data['publish_up'] = $nullDate;
         }
         $data['publish_down'] = cot_import_date('publish_down');
         if (!empty($data['publish_down'])) {
             $data['publish_down'] = date('Y-m-d H:i:s', $data['publish_down']);
         } else {
             $data['publish_down'] = $nullDate;
         }
         $bannerType = cot_import('banner_type', 'P', 'INT');
         unset($data['banner_type']);
         if (isset($data['client'])) {
             $data['client'] = (int) $data['client'];
         }
         // Отключим html-фильтры для установк произвольного кода:
         $tmp = $cot_import_filters['HTM'] = array();
         $item->setData($data);
         if ($bannerType == brs_model_Banner::TYPE_CUSTOM) {
             $item->type = $bannerType;
         }
         $cot_import_filters['HTM'] = $tmp;
         if (!empty($file)) {
             $fileProps = brs_fileProperties($file);
             if (empty($fileProps)) {
                 $item->type = brs_model_Banner::TYPE_UNKNOWN;
                 cot_error(cot::$L['brs_err_inv_file_type'], 'file');
             } else {
                 if (empty($item->width)) {
                     $item->width = $fileProps['width'];
                 }
                 if (empty($item->height)) {
                     $item->height = $fileProps['height'];
                 }
                 if ($item->type != brs_model_Banner::TYPE_CUSTOM) {
                     $item->type = $fileProps['type'];
                 }
                 if ($fileProps['type'] == brs_model_Banner::TYPE_UNKNOWN) {
                     $item->type = brs_model_Banner::TYPE_UNKNOWN;
                     cot_error(cot::$L['brs_err_inv_file_type'], 'file');
                 }
             }
         } elseif ($bannerType != brs_model_Banner::TYPE_CUSTOM) {
             // Если файл не передан
             if ($delFile) {
                 $item->type = brs_model_Banner::TYPE_UNKNOWN;
             } elseif (!empty($item->file)) {
                 $item->type = brs_type($item->file);
             }
         }
         $item->validate();
         $backUrl = array('m' => 'brs', 'a' => 'edit');
         if ($item->id > 0) {
             $backUrl['id'] = $item->id;
         }
         if (!cot_error_found()) {
             if (!empty($file)) {
                 $item->file = $file;
             }
             if ($id = $item->save()) {
                 cot_message(cot::$L['Saved']);
             } else {
                 // Удалим загруженный файл
                 if (!empty($file) && file_exists($file)) {
                     unlink($file);
                 }
             }
             $backUrl['id'] = $item->id;
             cot_redirect(cot_url('admin', $backUrl, '', true));
         } else {
             // Удалим загруженный файл
             if (!empty($file) && file_exists($file)) {
                 unlink($file);
             }
             cot_redirect(cot_url('admin', $backUrl, '', true));
         }
     }
     $deleteUrl = '';
     if ($item->id > 0) {
         $deleteUrl = cot_confirm_url(cot_url('admin', array('m' => 'brs', 'a' => 'delete', 'id' => $item->id)), 'admin');
     }
     $types = array('0' => cot::$L['brs_type_file'], brs_model_Banner::TYPE_CUSTOM => cot::$L['brs_custom_code']);
     $clients = brs_model_Client::keyValPairs();
     if (!$clients) {
         $clients = array();
     }
     $purchase = array(brs_model_Client::PURCHASE_DEFAULT => cot::$L['brs_client_default'], brs_model_Client::PURCHASE_UNLIMITED => cot::$L['brs_unlimited'], brs_model_Client::PURCHASE_YEARLY => cot::$L['brs_pt_yearly'], brs_model_Client::PURCHASE_MONTHLY => cot::$L['brs_pt_monthly'], brs_model_Client::PURCHASE_WEEKLY => cot::$L['brs_pt_weekly'], brs_model_Client::PURCHASE_DAILY => cot::$L['brs_pt_daily']);
     $track = array(-1 => cot::$L['brs_client_default'], 0 => cot::$L['No'], 1 => cot::$L['Yes']);
     $formFile = cot_inputbox('file', 'file', $item->file);
     if (!empty($item->file)) {
         $formFile .= cot_checkbox(false, 'del_file', cot::$L['Delete']);
     }
     $published = $item->published;
     if ($item->id == 0 && !isset($_POST['published'])) {
         $published = 1;
     }
     $showForm = true;
     if (empty($structure['brs'])) {
         $showForm = false;
     }
     $bannerType = 0;
     if ($item->type == brs_model_Banner::TYPE_CUSTOM) {
         $bannerType = brs_model_Banner::TYPE_CUSTOM;
     }
     /* === Hook === */
     foreach (cot_getextplugins('brs.admin.edit.main') as $pl) {
         include $pl;
     }
     /* ===== */
     $formElements = array('hidden' => array('element' => cot_inputbox('hidden', 'act', 'save')), 'title' => array('element' => cot_inputbox('text', 'title', $item->rawValue('title')), 'required' => true, 'label' => brs_model_Banner::fieldLabel('title')), 'category' => array('element' => cot_selectbox_structure('brs', $item->rawValue('category'), 'category', '', false, false), 'required' => true, 'label' => brs_model_Banner::fieldLabel('category')), 'type' => array('element' => cot_selectbox($bannerType, 'banner_type', array_keys($types), array_values($types), false), 'label' => brs_model_Banner::fieldLabel('type')), 'file' => array('element' => $formFile, 'label' => brs_model_Banner::fieldLabel('file')), 'width' => array('element' => cot_inputbox('text', 'width', $item->width), 'label' => brs_model_Banner::fieldLabel('width')), 'height' => array('element' => cot_inputbox('text', 'height', $item->height), 'label' => brs_model_Banner::fieldLabel('height')), 'alt' => array('element' => cot_inputbox('text', 'alt', $item->alt), 'label' => brs_model_Banner::fieldLabel('alt')), 'customcode' => array('element' => cot_textarea('customcode', $item->customcode, 5, 60), 'label' => brs_model_Banner::fieldLabel('customcode')), 'clickurl' => array('element' => cot_inputbox('text', 'clickurl', $item->clickurl), 'label' => brs_model_Banner::fieldLabel('clickurl')), 'description' => array('element' => cot_textarea('description', $item->description, 5, 60), 'label' => brs_model_Banner::fieldLabel('description')), 'sticky' => array('element' => cot_checkbox($item->sticky, 'sticky', brs_model_Banner::fieldLabel('sticky')), 'hint' => cot::$L['brs_sticky_tip']), 'publish_up' => array('element' => cot_selectbox_date(cot_date2stamp($item->publish_up, 'auto'), 'long', 'publish_up'), 'label' => brs_model_Banner::fieldLabel('publish_up')), 'publish_down' => array('element' => cot_selectbox_date(cot_date2stamp($item->publish_down, 'auto'), 'long', 'publish_down'), 'label' => brs_model_Banner::fieldLabel('publish_down')), 'imptotal' => array('element' => cot_inputbox('text', 'imptotal', $item->imptotal), 'label' => brs_model_Banner::fieldLabel('imptotal'), 'hint' => '0 - ' . cot::$L['brs_unlimited']), 'impressions' => array('element' => cot_inputbox('text', 'impressions', $item->impressions), 'label' => brs_model_Banner::fieldLabel('impressions')), 'clicks' => array('element' => cot_inputbox('text', 'clicks', $item->clicks), 'label' => brs_model_Banner::fieldLabel('clicks')), 'client' => array('element' => cot_selectbox($item->rawValue('client'), 'client', array_keys($clients), array_values($clients), true), 'label' => brs_model_Banner::fieldLabel('client')), 'purchase_type' => array('element' => cot_selectbox($item->rawValue('purchase_type'), 'purchase_type', array_keys($purchase), array_values($purchase), false), 'label' => brs_model_Banner::fieldLabel('purchase_type')), 'track_impressions' => array('element' => cot_selectbox($item->rawValue('track_impressions'), 'track_impressions', array_keys($track), array_values($track), false), 'label' => brs_model_Banner::fieldLabel('track_impressions'), 'hint' => cot::$L['brs_track_impressions_hint']), 'track_clicks' => array('element' => cot_selectbox($item->rawValue('track_clicks'), 'track_clicks', array_keys($track), array_values($track), false), 'label' => brs_model_Banner::fieldLabel('track_clicks'), 'hint' => cot::$L['brs_track_clicks_hint']), 'published' => array('element' => cot_checkbox($published, 'published', brs_model_Banner::fieldLabel('published'))));
     // Превью загруженного файла
     $banner_image = '';
     if (!empty($item->file)) {
         $type = $item->type;
         $imgArr = array(brs_model_Banner::TYPE_IMAGE, brs_model_Banner::TYPE_FLASH);
         if (in_array($item->type, $imgArr)) {
             $w = $item->width;
             $h = $item->height;
         } else {
             $fileProps = brs_fileProperties($item->file);
             if (!empty($fileProps)) {
                 $type = $fileProps['type'];
                 $w = $fileProps['width'];
                 $h = $fileProps['height'];
             }
         }
         if (in_array($type, $imgArr)) {
             // расчитаем размеры картинки:
             if ($h > 100) {
                 $k = $w / $h;
                 $h = 100;
                 $w = intval($h * $k);
             }
             if ($type == brs_model_Banner::TYPE_IMAGE) {
                 $rc = 'banner_image_admin';
             } elseif ($type == brs_model_Banner::TYPE_FLASH) {
                 $rc = 'banner_flash_admin';
             }
             $image = cot_rc($rc, array('file' => $item->file, 'alt' => $item->alt, 'width' => $w, 'height' => $h));
             $banner_image = cot_rc('admin_banner', array('banner' => $image));
         } else {
             // Просто выведем путь к файлу:
             $banner_image = cot_rc('admin_banner', array('banner' => $item->file));
         }
     }
     // /Превью загруженного файла
     $actionParams = array('m' => 'brs', 'a' => 'edit');
     if ($item->id > 0) {
         $actionParams['id'] = $item->id;
     }
     $template = array('brs', 'admin', 'edit');
     $view = new View();
     $view->page_title = $title;
     $view->showForm = $showForm;
     $view->item = $item;
     $view->deleteUrl = $deleteUrl;
     $view->banner_image = $banner_image;
     $view->formElements = $formElements;
     $view->formAction = cot_url('admin', $actionParams);
     /* === Hook === */
     foreach (cot_getextplugins('brs.admin.edit.view') as $pl) {
         include $pl;
     }
     /* ===== */
     return $view->render($template);
 }