Файл: adultscript-2.0.3-pro/files/admin/modules/adv/components/group_add.php
Строк: 64
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_adv_group_add
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$errors = array();
$messages = array();
$group = array('adv_group_name' => '', 'adv_group_desc' => '', 'adv_group_slug' => '',
'adv_rotate' => 0, 'status' => 1);
if (isset($_POST['submit_group_add'])) {
$filter = VF::factory('filter');
$name = $filter->get('adv_group_name');
$desc = $filter->get('adv_group_desc');
$slug = $filter->get('adv_group_slug');
$rotate = (int) trim($_POST['adv_rotate']);
$status = (int) trim($_POST['status']);
if ($name == '') {
$errors[] = 'Please enter advertising group name!';
} elseif (strlen($name) > 100) {
$errors[] = 'Advertising group name can contain maximum 100 characters!';
} else {
$group['adv_group_name'] = $name;
}
if ($desc != '') {
if (strlen($desc) > 255) {
$errors[] = 'Advertising group description can contain maximum 255 characters!';
} else {
$group['adv_group_desc'] = $desc;
}
}
if ($slug == '') {
$errors[] = 'Please enter the advertising group slug identifier!';
} elseif (!preg_match('/[A-za-z0-9_-]+/', $slug)) {
$errors[] = 'Advertising group slug identifier can contain only letters, numbers, dashes and underscores!';
} elseif (strlen($slug) > 50) {
$errors[] = 'Advertising group slug identifier can contain maximum 50 characters!';
} else {
$db->query("SELECT adv_group_id FROM #__adv_groups WHERE adv_group_slug = '".$db->escape($slug)."' LIMIT 1");
if ($db->affected_rows()) {
$errors[] = 'Advertising group slug identifier is already used as a identifier for another group!';
} else {
$group['adv_group_slug'] = $slug;
}
}
$group['adv_rotate'] = $rotate;
$group['status'] = $status;
if (!$errors) {
$db->query("INSERT INTO #__adv_groups
SET adv_group_name = '".$db->escape($name)."',
adv_group_desc = '".$db->escape($desc)."',
adv_group_slug = '".$db->escape($slug)."',
adv_rotate = '".$rotate."',
status = '".$status."'");
$messages[] = 'Advertising group was added!';
}
}
$tpl = VF::factory('template');
$tpl->menu = 'adv';
$tpl->submenu = 'adv_group_add';
$tpl->meta_title = 'Admin::Advertising::Group::Add';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->group = $group;
$tpl->load(array('header', 'adv_group_add', 'footer'));
$tpl->display();
}
}
?>