function admin_news_create() { if (isset($_REQUEST['create'])) { $news = new News(); $news->title = $_REQUEST['title']; $news->content = $_REQUEST['content']; $news->tags = $_REQUEST['tags']; $news->protected = $_REQUEST['protected']; $news->custom_sidebar = $_POST['custom_sidebar']; if ($_POST['start_date_check'] == 1) { $news->start_date = strtotime($_POST['start_date']['year'] . "-" . $_POST['start_date']['month'] . "-" . $_POST['start_date']['day'] . " " . str_pad($_POST['start_date']['hour'], 2, "0", STR_PAD_LEFT) . ":" . str_pad($_POST['start_date']['minute'], 2, "0", STR_PAD_LEFT) . "" . $_POST['start_date']['meridiem']); } else { $news->start_date = 0; } if ($_POST['end_date_check'] == 1) { $news->end_date = strtotime($_POST['end_date']['year'] . "-" . $_POST['end_date']['month'] . "-" . $_POST['end_date']['day'] . " " . str_pad($_POST['end_date']['hour'], 2, "0", STR_PAD_LEFT) . ":" . str_pad($_POST['end_date']['minute'], 2, "0", STR_PAD_LEFT) . "" . $_POST['end_date']['meridiem']); } else { $news->end_date = 0; } $news->save(); $news->created_on = date("Y-m-d H:i:s", strtotime($_POST['created_on']['year'] . "-" . $_POST['created_on']['month'] . "-" . $_POST['created_on']['day'] . " " . str_pad($_POST['created_on']['hour'], 2, "0", STR_PAD_LEFT) . ":" . str_pad($_POST['created_on']['minute'], 2, "0", STR_PAD_LEFT) . "" . $_POST['created_on']['meridiem'])); $news->save(); render('news_list'); return true; } render(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'update' page. */ public function actionCreate() { $model = new News(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); // set attributes from get if (isset($_GET['News'])) { $model->attributes = $_GET['News']; } if (isset($_POST['News'])) { $model->attributes = $_POST['News']; if (isset($_FILES)) { $model->image = "jpeg"; } if ($model->save()) { if (isset($_FILES)) { move_uploaded_file($_FILES["images"]["tmp_name"], Yii::getPathOfAlias('webroot') . "/../uploads/filestorage/news/elements/" . $model->id . '.jpeg'); $this->chgImg(Yii::getPathOfAlias('webroot') . "/../uploads/filestorage/news/elements/", $model->id . '.jpeg', "small-" . $model->id . '.jpeg'); } $url = isset($_POST['go_to_list']) ? $this->listUrl('index') : $this->itemUrl('update', $model->id); $this->redirect($url); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($idTree) { $modelTree = Tree::model()->find('id=:id AND module=:module AND organization=:organization', array(':id' => $idTree, ':module' => 'news', ':organization' => Yii::app()->session['code_no'])); if ($modelTree === null) { throw new CHttpException(404, 'Страница не найдена.'); } if (!(Yii::app()->user->admin || Access::model()->checkAccessUserForTree($idTree))) { throw new CHttpException(403, 'Доступ запрещен.'); } $model = new News(); $model->id_tree = $idTree; $model->flag_enable = true; $model->date_start_pub = date('d.m.Y'); $model->date_end_pub = date('01.m.Y', PHP_INT_MAX); $model->author = Yii::app()->user->name; $model->general_page = 0; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['News'])) { $model->attributes = $_POST['News']; $model->log_change = LogChange::setLog($model->log_change, 'создание'); if ($model->save()) { // сохраняем файлы $model->saveFiles($model->id, $idTree); // сохраняем изображения $model->saveImages($model->id, $idTree); // сохраняем миниатюра изображения $model->saveThumbailForNews($model); $this->redirect(array('view', 'id' => $model->id, 'idTree' => $idTree)); } } $this->render('create', array('model' => $model, 'idTree' => $idTree)); }
public function actionCreates() { $model = new News(); $file = new File(); $model->member_id = Yii::app()->user->id; $model->create_at = date('Y-m-d H:i:s'); $model->update_at = date('Y-m-d H:i:s'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['News']) && isset($_POST['File'])) { $model->attributes = $_POST['News']; $file->attributes = $_POST['File']; $model->pic = 'noimage.jpg'; $model->validate(); $file->validate(); if ($model->getErrors() == null && $file->getErrors() == null) { $file->file = CUploadedFile::getInstance($file, 'file'); if ($file->file != null) { $filename = time() . '.' . $file->file->getExtensionName(); $file->file->saveAs(Yii::app()->params['pathUpload'] . $filename); $model->pic = $filename; } else { $model->pic = 'noimage.jpg'; } if ($model->save()) { $this->redirect(array('view', 'id' => $model->news_id)); } } } $this->render('create', array('model' => $model, 'file' => $file)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new News(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['News'])) { $model->attributes = $_POST['News']; if ($model->save()) { if (!empty($model->img)) { $photo = $model->img; $img = Yii::app()->image->load($_SERVER['DOCUMENT_ROOT'] . '/userfiles/editor/images/' . $photo); $pname = 'news_' . $model->id . '_' . $photo; $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/original/' . $pname); $img->resize(600, 600); $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/large/' . $pname); $img->resize(200, 200); $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/medium/' . $pname); $img->resize(100, 100); $img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/small/' . $pname); $model->img = $pname; $model->update(); } if (isset($_POST['savebutton'])) { $this->redirect($this->createUrl('index', array('News_page' => $_GET['News_page'], 'msg' => '[!] Новость успешно создана', 'msgtype' => 'success'))); } else { $this->redirect($this->createUrl('update', array('id' => $model->id, 'msg' => '[!] Новость успешно создана', 'msgtype' => 'success'))); } } else { $model->date = $model->viewDate(); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. * * @return void */ public function actionCreate() { $model = new News(); if (($data = Yii::app()->getRequest()->getPost('News')) !== null) { $model->setAttributes($data); if ($model->save()) { Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('NewsModule.news', 'News article was created!')); $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create'])); } } $languages = $this->yupe->getLanguagesList(); //если добавляем перевод $id = (int) Yii::app()->getRequest()->getQuery('id'); $lang = Yii::app()->getRequest()->getQuery('lang'); if (!empty($id) && !empty($lang)) { $news = News::model()->findByPk($id); if (null === $news) { Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('NewsModule.news', 'Targeting news was not found!')); $this->redirect(['/news/newsBackend/create']); } if (!array_key_exists($lang, $languages)) { Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('NewsModule.news', 'Language was not found!')); $this->redirect(['/news/newsBackend/create']); } Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('NewsModule.news', 'You inserting translation for {lang} language', ['{lang}' => $languages[$lang]])); $model->setAttributes(['lang' => $lang, 'slug' => $news->slug, 'date' => $news->date, 'category_id' => $news->category_id, 'title' => $news->title]); } else { $model->setAttributes(['date' => date('d-m-Y'), 'lang' => Yii::app()->getLanguage()]); } $this->render('create', ['model' => $model, 'languages' => $languages]); }
public function add_news() { $this->_checkPermission(); $data = $_POST['news']; Flash::set('postdata', $data); $image = $_POST['upload']; $path = str_replace('..', '', $image['path']); $overwrite = false; // verification if (empty($data['title'])) { Flash::set('error', __('You have to specify a news title!')); redirect(get_url('news/create')); } // if (empty($data['url'])){ // Flash::set('error', __('You have to specify the URL!')); // redirect(get_url('news/create')); // } if (isset($_FILES)) { // no image file selected if (empty($_FILES['upload_file']['name'])) { Flash::set('error', __('You have to select a image to be uploaded!')); redirect(get_url('news/create')); } } else { Flash::set('error', __('You have to select a image to be uploaded!')); redirect(get_url('news/create')); } $news = new News($data); $news->created_by_id = AuthUser::getId(); $news->created_on = date('Y-m-d H:i:s'); if (!$news->save()) { Flash::set('error', __('Promo is not added!')); redirect(get_url('news/create')); } else { if (isset($_FILES)) { $news_id = $news->lastInsertId(); $file = $this->upload_file($_FILES['upload_file']['name'], FILES_DIR . '/promo/images/', $_FILES['upload_file']['tmp_name'], $overwrite, $news_id); if ($file === false) { Flash::set('error', __('Promo image has not been uploaded!')); } //Add Image to database $data = $_POST['news']; Flash::set('post_data', (object) $data); $news = Record::findByIdFrom('News', $news_id); if (!$news->update('News', array('filename' => $file), 'id=' . $news_id)) { Flash::set('error', __('Image has not been updated.')); } else { Flash::set('success', __('Promo has been updated!')); if (isset($_POST['commit'])) { redirect(get_url('news')); } else { redirect(get_url('news/view/' . $news->id)); } } } Flash::set('success', __('Promo has been added!')); } redirect(get_url('news')); }
public function actionAddRandomNews() { $news = new News(); $news->title = "Item #" . rand(1, 10000); $news->created_on = time(); $news->save(); echo "OK"; }
static function addNew($titre, $image, $texte) { $new = new News(); $new->titre = $titre; $new->image = "Vue/Image/" . $image; $new->contenu = $texte; $new->date = date("Y-m-d H:i:s"); $new->save(); }
protected function actionAdd() { $addart = new View('view/forms.php'); $addart->display(); if (isset($_POST['text']) && isset($_POST['title'])) { $article = new News(); $article->title = $_POST['title']; $article->text = $_POST['text']; $article->save(); } }
public function testUniqueTitle() { $news = new News(); $news->title = 'News'; $news->body = 'FooBar'; $this->assertTrue($news->save()); $news = new News(); $news->body = 'Ananas'; $news->title = 'News'; $this->assertFalse($news->save()); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new News(); if (isset($_POST['News'])) { $model->attributes = $_POST['News']; if ($model->save()) { Yii::app()->user->setFlash('success', '创建成功'); $this->redirect(array('update', 'id' => $model->n_id)); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new News(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['News'])) { $model->attributes = $_POST['News']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function run() { DB::table('news')->delete(); $user = User::all()->first(); $news = new News(); $news->title = "The first discount"; $news->description = "Neque molestiae nobis ex sint incidunt animi. Ipsa eum repellat quisquam quasi dolorem sapiente porro repellat. Praesentium non enim quod corrupti maxime impedit illum. Minus ea quo labore et. Quas quia laudantium fuga est. Nihil exercitationem nam incidunt rerum animi repellat. Sit sapiente temporibus voluptate in. Rerum consequatur non sed delectus pariatur harum accusantium sint. Repellendus explicabo sapiente itaque ipsum. Saepe ipsum assumenda voluptatem aut. Ut rerum enim qui facere. Et quod ipsam id amet. Error id molestiae aut ut sit ducimus."; $news->save(); $news = new News(); $news->title = "The second discount"; $news->description = "Neque molestiae nobis ex sint incidunt animi. Ipsa eum repellat quisquam quasi dolorem sapiente porro repellat. Praesentium non enim quod corrupti maxime impedit illum. Minus ea quo labore et. Quas quia laudantium fuga est. Nihil exercitationem nam incidunt rerum animi repellat. Sit sapiente temporibus voluptate in. Rerum consequatur non sed delectus pariatur harum accusantium sint. Repellendus explicabo sapiente itaque ipsum. Saepe ipsum assumenda voluptatem aut. Ut rerum enim qui facere. Et quod ipsam id amet. Error id molestiae aut ut sit ducimus."; $news->save(); }
/** * @test */ public function create() { $model = News::model(); $this->assertInstanceOf('News', $model); $model = new News(); $model->attributes = array('category_id' => 1, 'enabled' => true); $this->assertFalse($model->save()); $model = new News(); $model->attributes = array('event_date' => '2013-08-21', 'category_id' => 1); $this->assertFalse($model->save()); $model = new News(); $model->attributes = array('event_date' => '2013-08-21', 'category_id' => 1, 'enabled' => true); $this->assertTrue($model->save()); }
public function actionAdd() { $model = new News; if(isset($_POST['News'])) { $model->attributes = $_POST['News']; if($model->save()){ Yii::app()->user->setFlash('success','添加成功!'); $this->redirect(array('list')); } } Yii::app()->session['myurl'] = $this->createUrl('add'); $this->render('add',array('model'=>$model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new News(); if (isset($_POST['News'])) { $model->attributes = $_POST['News']; if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('main', 'Данные успешно сохранены!')); $this->redirect(array('update', 'id' => $model->id)); } else { Yii::app()->user->setFlash('error', Yii::t('main', 'Ошибка сохранения данных!')); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new News(); $model->attributes = $_POST['News']; // var_dump($model); if (isset($_POST['News'])) { if ($model->save()) { // var_dump($_POST); // exit; $this->redirect(array('admin')); } } $this->render('create', array('model' => $model)); }
public function post_add() { $data = Input::json(); $news = new News(); $news->expired = $data->tanggal . ' ' . $data->jam; $news->priority = $data->priority; $news->message = $data->message; $news->pool_id = $data->pool_id; $news->user_id = Auth::user()->id; $news->to_user_id = $data->to_user_id; $news->msg_type = $data->msg_type; $news->save(); return json_encode(array('msg' => 'Pesan berhasil di kirim')); }
public function actionCreate() { $model = new News(); if (isset($_POST['News']) || isset($_POST['Page'])) { try { if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } catch (Exception $e) { $model->addError('', $e->getMessage()); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new News(); $this->layout = '//layouts/header_user'; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['News'])) { $model->attributes = $_POST['News']; $model->date = CDateTimeParser::parse($model->date, 'dd.MM.yyyy'); if ($model->save()) { $this->redirect(array('admin')); } } $this->render('create', array('model' => $model)); }
/** * Elmenti az új hírt. */ public function actionAddNews() { if (!Yii::app()->user->getId() || Yii::app()->user->level < 1) { throw new CHttpException(403, 'A funkció használatához be kell jelentkeznie és legalább 1-es szintű hozzáférésre van szüksége'); } $model = new News(); $model->user_id = Yii::app()->user->getId(); $model->subject_id = $_POST["subject_id"]; $model->title = $_POST["title"]; $model->contents = $_POST["contents"]; $model->date_created = new CDbExpression("NOW()"); $model->date_updated = new CDbExpression("NOW()"); $model->save(); $this->redirect(Yii::app()->createUrl("site/index")); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new News(); $imageModel = new NewsImages(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['News'])) { $model->attributes = $_POST['News']; $model->cover_id = 0; if ($model->save()) { $this->redirect(array('index')); } } $this->render('create', array('model' => $model, 'titleListNews' => $this->config->title, 'imageModel' => $imageModel)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new News(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['News'])) { $model->attributes = $_POST['News']; if ($model->save()) { Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('news', 'Новость добавлена!')); $this->redirect(array('view', 'id' => $model->id)); } } $model->date = date('d.m.Y'); $this->render('create', array('model' => $model)); }
public function actionCreate() { $this->breadcrumbs = array_merge($this->breadcrumbs, array('Создание новости')); $this->pageTitle = Yii::t('app', 'Создание новости'); $model = new News(); if (Yii::app()->request->getPost('News')) { $model->attributes = Yii::app()->request->getPost('News'); if ($model->validate()) { if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('app', 'Новость успешно добавлена')); Yii::app()->request->redirect($this->createUrl('index')); } } } $this->render('create', array('model' => $model)); }
public function generateNewsForPolitico() { // force generation of another news related to politico in case skip is activated // we need the news related to the politician for the politician page $n = new News(); $n->setGeneratorModel(get_class($this)); $n->setGeneratorPrimaryKeys(serialize($this->getPrimaryKeysArray())); $n->setRelatedMonitorableModel('OppPolitico'); $n->setRelatedMonitorableId($this->getOppCarica()->getPoliticoId()); if ($this->getCreatedAt() != null) { $n->setCreatedAt($this->getCreatedAt()); } $n->setDate($this->getNewsDate()); $n->setPriority(2); $n->save(); }
public function postCreateNews() { /* validate input */ $validator = Validator::make(Input::all(), array("title" => "required", "description" => "required")); /* if validated */ if ($validator->passes()) { /* get input */ $news = new News(); $news->title = Input::get("title"); $news->description = Input::get("description"); $news->save(); return Redirect::to('admin/news/create_news')->with('message', 'News added!')->with('news', $news); } else { return Redirect::to('admin/news/create_news')->withErrors($validator); } // end validation }
public function actionAdd() { $model = new News(); $model->user_id = $this->user->id; $model->date = time(); $model->status = News::STATUS_HIDE; // $model->unsetAttributes(); if (isset($_POST['News'])) { $model->attributes = $_POST['News']; if ($model->save()) { Yii::app()->user->setFlash('success', '新加新闻成功'); $this->redirect(array('/board/news/index')); } } $model->formatDate(); $this->render('edit', array('model' => $model)); }
public function create() { $rules = array('title' => 'required|min:3', 'content' => 'required|min:3'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::route('admin.news.create')->withErrors($validator)->With(Input::all()); } else { $news = new News(); $news->title = Input::get('title'); $news->content = Input::get('content'); $news->active = Input::get('active'); $news->user_id = Auth::user()->id; if ($news->save()) { return Redirect::route('admin.news.index')->with('success', Lang::get('messages.news_created')); } } return Redirect::route('admin.news.index')->with('success', Lang::get('messages.news_created')); }
public function actionCreate() { if (Yii::app()->user->checkAccess('createNews') == false) { throw new CHttpException(403); } $cases = new News(); if (isset($_POST['News'])) { $cases->attributes = Yii::app()->request->getPost('News'); if ($cases->validate() && $cases->save()) { $this->setFlashMessage(strtr('<strong>{link}</strong> 成功案例添加成功', array('{link}' => CHtml::link($cases->title, array('view', 'id' => $cases->primaryKey))))); $this->redirect($this->getReturnUrl()); } } else { $cases->release_date = date('Y-m-d'); $cases->is_released = 1; } $this->breadcrumbs = array('成功案例' => array('index'), '添加'); $this->render('create', array('cases' => $cases, 'returnUrl' => $this->getReturnUrl())); }