public function actionUpdate($id, $page = null) { if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!isset($_POST['F']) || !is_array($_POST['F'])) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('保存信息错误', self::MSG_ERROR, true); } if ($_POST['F']['ad_categories_name'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('名称不能为空', self::MSG_ERROR, true); } $flag = Yii::app()->db->createCommand()->update('{{game_ad_categories}}', array('ad_categories_name' => $_POST['F']['ad_categories_name'], 'ad_categories_rank' => $_POST['F']['ad_categories_rank']), 'ad_categories_id=:ad_categories_id', array(':ad_categories_id' => $id)); if ($flag) { if (!isset($_GET['ajax'])) { $this->redirect[] = array('text' => '', 'href' => url($this->module->id . '/Ad/Categories/Index')); $this->message('保存成功', self::MSG_SUCCESS, true); } } else { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('保存信息失败', self::MSG_ERROR, true); } } $data = AdCategories::get_one_by_id($id, false); if (empty($data)) { $this->redirect[] = array('text' => '', 'href' => url($this->module->id . '/Ad/Categories/Index')); $this->message('id不存在或已被删除', self::MSG_ERROR, true); } //print_r($data); $this->render('create', array('data' => $data)); }
public function actionCreate() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!isset($_POST['F']) || !is_array($_POST['F'])) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('保存信息错误', self::MSG_ERROR, true); } if ($_POST['F']['ad_position_name'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('名称不能为空', self::MSG_ERROR, true); } if ($_POST['F']['ad_position_identify'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('标识不能为空', self::MSG_ERROR, true); } if ($_POST['F']['ad_position_identify'] == '') { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('标识不能为空', self::MSG_ERROR, true); } if (preg_match("/^[0-9]+.*/", $_POST['F']['ad_position_identify'])) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('标识不能以数字开头', self::MSG_ERROR, true); } $sql = "SELECT `ad_position_identify` FROM {{`ad_position`}} WHERE ad_position_identify=:ad_position_identify AND `ad_position_status`!=:ad_position_status"; $cmd = Yii::app()->db->createCommand($sql); $cmd->execute(array(':ad_position_identify' => $_POST['F']['ad_position_identify'], ":ad_position_status" => AdPosition::STAT_DELETED)); if ($cmd->queryScalar()) { $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('标识不能重复', self::MSG_ERROR, true); } $flag = Yii::app()->db->createCommand()->insert('{{ad_position}}', array('ad_position_id' => 0, 'ad_position_name' => $_POST['F']['ad_position_name'], 'ad_categories_id' => $_POST['F']['ad_categories_id'], 'ad_position_identify' => $_POST['F']['ad_position_identify'], 'ad_position_status' => AdPosition::STAT_NORMAL, 'ad_position_rank' => $_POST['F']['ad_position_rank'], 'ad_position_remark' => $_POST['F']['ad_position_remark'], 'ad_position_width' => $_POST['F']['ad_position_width'], 'ad_position_height' => $_POST['F']['ad_position_height'], 'ad_position_type' => $_POST['F']['ad_position_type'], 'ad_position_dateline' => date("Y-m-d H:i:s"), 'ad_position_target' => $_POST['F']['ad_position_target'], 'ad_position_relative_type' => $_POST['F']['ad_position_relative_type'])); if ($flag) { $ad_position_id = Yii::app()->db->getLastInsertID(); $ad_position_name = $_POST['F']['ad_position_name']; //更新缓存 AdPosition::update_cache(); //记录操作日志 $user = Yii::app()->user; $message = '{user_name}添加广告位{ad_position_name}'; $data = array('user_id' => $user->id, 'user_name' => $user->name, 'ad_position_name' => $ad_position_name, 'addons_data' => array('ad_position_id' => $ad_position_id)); AdminLogs::add($user->id, 'Ad/Position', $ad_position_id, 'Insert', 'success', $message, $data); if (!isset($_GET['ajax'])) { $this->redirect[] = array('text' => '', 'href' => url($this->module->id . '/Ad/Position/Index')); $this->message('添加成功', self::MSG_SUCCESS, true); } } else { //记录操作日志 $user = Yii::app()->user; $message = '{user_name}添加广告位{collect_model_name}失败'; $data = array('user_id' => $user->id, 'user_name' => $user->name, 'ad_position_name' => $ad_position_name, 'addons_data' => array('position' => $_POST['F'])); AdminLogs::add($user->id, 'Ad/Position', $ad_position_id, 'Insert', 'failure', $message, $data); $this->redirect[] = array('text' => '', 'href' => 'javascript:history.go(-1);'); $this->message('添加失败', self::MSG_ERROR, true); } } $data = array('ad_position_id' => 0, 'ad_position_name' => '', 'ad_categories_id' => isset($_GET['ad_categories_id']) ? intval($_GET['ad_categories_id']) : 0, 'ad_position_identify' => '', 'ad_position_rank' => 255, 'ad_position_remark' => '', 'ad_position_width' => '', 'ad_position_height' => '', 'ad_position_type' => 0, 'ad_position_target' => '', 'ad_position_relative_type' => '', 'categories' => AdCategories::Pages(array('allow_cache' => false))); $this->render('create', array('data' => $data)); }
$this->pageTitle = 'Шабашники главная'; $form = $this->beginWidget('CActiveForm', array('id' => 'user-register-form', 'enableAjaxValidation' => false)); ?> <div class="site-category clearfix pull-left"> <div class="site-category__col pull-left white"> <div class="site-category__col-top"> <div class="select-city add-arrow"> <div class="select-city__result">Выбор города</div> <a class="close" href="#">close</a> </div> </div> <div class="site-category__title"><h3>Категории услуг:</h3></div> <ul class="site-category__list"> <?php $i = 1; foreach (AdCategories::model()->findAll() as $category) { if ($i <= 10) { if ($i == 1) { echo '<li class="site-category__item active first"><a href="#sc-tab' . $i . '">' . $category->text . '</a></li>'; } elseif ($i == 10) { echo '<li class="site-category__item last"><a href="#sc-tab01">' . $category->text . '</a></li>'; } else { echo '<li class="site-category__item"><a href="#sc-tab' . $i . '">' . $category->text . '</a></li>'; } $i++; } else { break; } } ?> </ul>