Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: Add new category under Articles form  (Read 2452 times)

centered

  • Guest
Add new category under Articles form
« on: February 22, 2008, 05:55:29 pm »

This mod is to add a new category when you are creating a new article, so one wouldn't have to a) create a category, create an article.  You can do it in one page!

no language variable yet...

0. back up

1. in form_articles find the first line, add the next:
Code: [Select]
$frm_submit = l('submit');
// add
$frm_art_cat = $_SESSION['temp']['addcategory'];
$frm_cat_sef = cleanSEF($_SESSION['temp']['cat_seftitle']);

2. further down same thing:
Code: [Select]
if ($contents != 'page_new' && $edit_option != 3) {
// add
echo html_input('text', 'addcategory', 'as', $frm_add_cat, 'Add new category or choose below', '', 'onchange="genSEF(this,document.forms[\'post\'].cat_seftitle)"', 'onkeyup="genSEF(this,document.forms[\'post\'].cat_seftitle)"', '', '', '', '', '', '', '', '');
echo '<div style="display: none;">';
echo html_input('text', 'cat_seftitle', 'as', $frm_cat_sef, l('sef_title'), '', '', '', '', '', '', '', '', '', '');
echo '</div>';

3. In processing, find the first two lines, add the next:
Code: [Select]
if ($_SESSION[db('website').'Logged_In'] != token()) {echo notification(1,l('error_not_logged_in'),'home');}
else {
// add
$addcategory = clean($_POST['addcategory']);
$cat_sef = $_POST['cat_seftitle'];

4. further down find :    case(isset($_POST['add_article'])):
Follow the comments:
Code: [Select]
case(isset($_POST['add_article'])):
// add
if (!empty($addcategory)) {
mysql_query("INSERT INTO ".db('prefix')."categories(name, seftitle, published) VALUES('$addcategory', '$cat_sef', 'YES')");
$cat = retrieve('id','categories','name',$addcategory);
mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta) VALUES('$title', '$seftitle', '$text', '$date', '$cat', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta')");
} else {

mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta) VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta')");

}
// end add
break;
case(isset($_POST['edit_article'])):
if ($fpost_enabled == true) {$future = " date = '$date',";}


// add
if (!empty($addcategory)) {
mysql_query("INSERT INTO ".db('prefix')."categories(name, seftitle, published) VALUES('$addcategory', '$cat_sef', 'YES')");
$cat = retrieve('id','categories','name',$addcategory);
mysql_query("UPDATE ".db('prefix')."articles SET title='$title', seftitle = '$seftitle', text = '$text',".$future." category = '$cat', position = '$position', displaytitle = '$display_title', displayinfo = '$display_info', commentable = '$commentable', published = '$publish_article', description_meta = '$description_meta', keywords_meta = '$keywords_meta' WHERE id = '$id' LIMIT 1;");
} else {


mysql_query("UPDATE ".db('prefix')."articles SET title='$title', seftitle = '$seftitle', text = '$text',".$future." category = '$category', position = '$position', displaytitle = '$display_title', displayinfo = '$display_info', commentable = '$commentable', published = '$publish_article', description_meta = '$description_meta', keywords_meta = '$keywords_meta' WHERE id = '$id' LIMIT 1;");

}
// end add

break;
case(isset($_POST['delete_article'])):
mysql_query("DELETE FROM ".db('prefix')."articles WHERE id = $id LIMIT 1;");
mysql_query("DELETE FROM ".db('prefix')."comments WHERE articleid = $id LIMIT 1;");
break;
}
echo notification(0,'',$link); unset($_SESSION['temp']);
}

Need some error checking and all that jazz.  Can anyone help out?
« Last Edit: February 22, 2008, 06:38:18 pm by equilni »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: Add new category under Articles form
« Reply #1 on: February 22, 2008, 06:29:35 pm »

@ EQ... it would be nice if you could provide an intro paragraph or two at the start of this project that explains what its purpose is and what it does... etc. so that other members will see what it is about.  ;)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

centered

  • Guest
Re: Add new category under Articles form
« Reply #2 on: February 22, 2008, 06:38:31 pm »

Added, thanks!
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Add new category under Articles form
« Reply #3 on: February 22, 2008, 06:41:29 pm »

Yes! em... I guess this is what you're after? Really good, Jason. Articles and categories go hand-in.hand anyway, so, very nice addition. This would be one for the core if we hadn't already closed the book... ;D

« Last Edit: February 22, 2008, 06:43:18 pm by Fred K (agentsmith) »
Logged

centered

  • Guest
Re: Add new category under Articles form
« Reply #4 on: March 17, 2008, 12:39:47 pm »

Fred,  have you tested this out further?

Has anyone else tested this out further?
Logged

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
Re: Add new category under Articles form
« Reply #5 on: March 17, 2008, 02:11:25 pm »

I guess, I'll have to test the code later, because further modification of sNews pages will need this, so one could create a category index page AND a new category from one place.
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Add new category under Articles form
« Reply #6 on: March 17, 2008, 03:41:31 pm »

I haven't tested it further, no. It worked smashingly so I've been busy with things that don't... you know. ;)
Logged