[Phpbbkb-checkins] SF.net SVN: phpbbkb: [42] main/trunk
Status: Alpha
Brought to you by:
markthedaemon
From: <mar...@us...> - 2007-01-26 18:02:51
|
Revision: 42 http://svn.sourceforge.net/phpbbkb/?rev=42&view=rev Author: markthedaemon Date: 2007-01-26 10:02:51 -0800 (Fri, 26 Jan 2007) Log Message: ----------- Adding the KB files as well as commiting a updated lang_kb.php file which includes some initial changes for the language side of things. Added Paths: ----------- main/trunk/admin/admin_kb.php main/trunk/install/kb_install.php main/trunk/kb.php main/trunk/language/lang_english/lang_kb.php main/trunk/templates/subSilver/admin/kb_cats.tpl main/trunk/templates/subSilver/admin/kb_editcat.tpl main/trunk/templates/subSilver/images/Thumbs.db main/trunk/templates/subSilver/images/new-article.gif main/trunk/templates/subSilver/kb_article_posting.tpl main/trunk/templates/subSilver/kb_main.tpl main/trunk/templates/subSilver/kb_previewarticle.tpl main/trunk/templates/subSilver/kb_viewarticle.tpl main/trunk/templates/subSilver/kb_viewcat.tpl Added: main/trunk/admin/admin_kb.php =================================================================== --- main/trunk/admin/admin_kb.php (rev 0) +++ main/trunk/admin/admin_kb.php 2007-01-26 18:02:51 UTC (rev 42) @@ -0,0 +1,727 @@ +<?php +/*************************************************************************** + * admin_kb.php + * ------------------- + * + * copyright: phpBB KB Group + * site: http://www.phpbbknowledgebase.com + * SF Project Page: http://www.sourceforge.net/projects/phpbbkb + * + ***************************************************************************/ + +/*************************************************************************** + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + ***************************************************************************/ + +define('IN_PHPBB', 1); + +if( !empty($setmodules) ) +{ + $file = basename(__FILE__); + $module['KB']['Categories'] = "$file?mode=cats"; + return; +} + +$phpbb_root_path = "./../"; +require($phpbb_root_path . 'extension.inc'); +require('./pagestart.' . $phpEx); + +// Get constants and functions +include($phpbb_root_path . "kb/constants." . $phpEx); +include($phpbb_root_path . "kb/functions." . $phpEx); + +// And language +include($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/lang_kb." . $phpEx); +$mode = $HTTP_GET_VARS['mode']; + +switch($mode) +{ + /* + NOTE: All article editing, deleting, approving and so on will be featured in the ucp for the admin as well, + might integrate it here later but i like it better in ucp. + case "articles": + break; + */ + + case "cats": + $edit = isset($HTTP_GET_VARS['edit']) ? $HTTP_GET_VARS['edit'] : false; + $delete = isset($HTTP_GET_VARS['delete']) ? $HTTP_GET_VARS['delete'] : false; + $add = isset($HTTP_POST_VARS['add']) ? true : false; + if(!$add) + { + $add = isset($HTTP_GET_VARS['add']) ? true : false; + } + $sort = isset($HTTP_GET_VARS['s']) ? $HTTP_GET_VARS['s'] : false; + + if($edit != false) + { + if(!isset($HTTP_POST_VARS['submit'])) + { + $sql = "SELECT * + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_id = '" . $edit . "'"; + if(!$result = $db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't get category from categories table", "", __LINE__, __FILE__, $sql); + } + $cat = $db->sql_fetchrow($result); + + $template->set_filenames(array( + 'body' => 'admin/kb_editcat.tpl') + ); + + $parent = generate_cat_parents($cat['cat_main']); + $s_hidden_fields = "<input type=\"hidden\" name=\"oldparent\" value=\"" . $cat['cat_main'] . "\">"; + + $template->assign_vars(array( + 'L_HEADER' => $lang['kbadm_header_editcat'], + 'L_EXPLAIN' => $lang['kbadm_explain_editcat'], + 'L_CAT_SETTINGS' => $lang['kbadm_cat_settings'], + 'L_CAT_TITLE' => $lang['kbadm_cat_title'], + 'L_CAT_DESCRIPTION' => $lang['kbadm_cat_desc'], + 'L_CAT_PARENT' => $lang['kbadm_cat_parent'], + + 'CAT_TITLE' => $cat['cat_title'], + 'DESCRIPTION' => $cat['cat_desc'], + + 'S_SUBMIT_VALUE' => $lang['kbadm_editcat'], + 'S_PARENT' => $parent, + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_FORUM_ACTION' => append_sid("admin_kb." . $phpEx . "?mode=cats&edit=" . $edit)) + ); + + $template->pparse('body'); + + include('./page_footer_admin.'.$phpEx); + exit; + } + else + { + $error_msg = ''; + + if(!isset($HTTP_POST_VARS['title']) || $HTTP_POST_VARS['title'] == "") + { + $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['kbadm_empty_cat_title'] : $lang['admkb_empty_cat_title']; + } + + if(!isset($HTTP_POST_VARS['desc']) || $HTTP_POST_VARS['desc'] == "") + { + $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['kbadm_empty_cat_desc'] : $lang['admkb_empty_cat_title']; + } + + if($error_msg != '') + { + $sql = "SELECT * + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_id = '" . $edit . "'"; + if(!$result = $db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't get category from categories table", "", __LINE__, __FILE__, $sql); + } + $cat = $db->sql_fetchrow($result); + + $template->set_filenames(array( + 'body' => 'admin/kb_editcat.tpl') + ); + + $parent = generate_cat_parents($cat['cat_main']); + $s_hidden_fields = "<input type=\"hidden\" name=\"oldparent\" value=\"" . $cat['cat_main'] . "\">"; + + $template->set_filenames(array( + 'reg_header' => 'error_body.tpl') + ); + + $template->assign_vars(array( + 'ERROR_MESSAGE' => $error_msg) + ); + + $template->assign_var_from_handle('ERROR_BOX', 'reg_header'); + + $template->assign_vars(array( + 'L_HEADER' => $lang['kbadm_header_editcat'], + 'L_EXPLAIN' => $lang['kbadm_explain_editcat'], + 'L_CAT_SETTINGS' => $lang['kbadm_cat_settings'], + 'L_CAT_TITLE' => $lang['kbadm_cat_title'], + 'L_CAT_DESCRIPTION' => $lang['kbadm_cat_desc'], + 'L_CAT_PARENT' => $lang['kbadm_cat_parent'], + + 'CAT_TITLE' => $cat['cat_title'], + 'DESCRIPTION' => $cat['cat_desc'], + + 'S_SUBMIT_VALUE' => $lang['kbadm_editcat'], + 'S_PARENT' => $parent, + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_FORUM_ACTION' => append_sid("admin_kb." . $phpEx . "?mode=cats&edit=" . $edit)) + ); + + $template->pparse('body'); + + include('./page_footer_admin.'.$phpEx); + exit; + } + else + { + $parent = isset($HTTP_POST_VARS['parent']) ? $HTTP_POST_VARS['parent'] : 0; + + $sql = "UPDATE " . KB_CATEGORIES_TABLE . " + SET cat_main = '" . $parent . "', + cat_title = '" . trim(htmlspecialchars($HTTP_POST_VARS['title'])) . "', + cat_desc = '" . trim(htmlspecialchars($HTTP_POST_VARS['desc'])) . "' + WHERE cat_id = '" . $edit . "'"; + + if(!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't edit category.", "", __LINE__, __FILE__, $sql); + } + + if($HTTP_POST_VARS['oldparent'] != $HTTP_POST_VARS['parent']) + { + // Parent category changed, alter the order + sort_cats("edit", $edit, 0, array(0 => $HTTP_POST_VARS['parent'], 1 => $HTTP_POST_VARS['oldparent'])); + } + + // And a message here somewhere + $message = $lang['kbadm_editcat_success'] . '<br /><br />' . sprintf($lang['kbadm_Click_return_catadmin'], '<a href="' . append_sid("admin_kb." . $phpEx . "?mode=cats") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>'); + + message_die(GENERAL_MESSAGE, $message); + } + } + } + + if($delete != false) + { + $confirm = isset($HTTP_POST_VARS['confirm']) ? true : false; + $cancel = isset($HTTP_POST_VARS['cancel']) ? true : false; + if($cancel) + { + // Redirect back to cat page + + } + elseif(!$confirm) + { + $s_hidden_fields = '<input type="hidden" name="cat_id" value="' . $delete . '" />'; + $l_confirm = $lang['kbadm_confirm_deletecat']; + + // + // Output confirmation page + // + $template->set_filenames(array( + 'confirm_body' => 'confirm_body.tpl') + ); + + $template->assign_vars(array( + 'MESSAGE_TITLE' => $lang['Information'], + 'MESSAGE_TEXT' => $l_confirm, + + 'L_YES' => $lang['Yes'], + 'L_NO' => $lang['No'], + + 'S_CONFIRM_ACTION' => append_sid("admin_kb." . $phpEx . "?mode=cats&delete=true"), + 'S_HIDDEN_FIELDS' => $s_hidden_fields) + ); + + $template->pparse('confirm_body'); + + include('./page_footer_admin.'.$phpEx); + exit; + } + elseif($confirm) // Double check user confirmed + { + $cat_id = $HTTP_POST_VARS['cat_id']; + + // Need lang vars for the errors? + $sql = "DELETE FROM " . KB_CATEGORIES_TABLE . " WHERE cat_id = '" . $cat_id . "'"; + if(!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't delete category from categories table.", "", __LINE__, __FILE__, $sql); + } + + $sql = "DELETE FROM " . KB_ARTICLECATS_TABLE . " WHERE cat_id = '" . $cat_id . "'"; + if(!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't delete category from articlecats table.", "", __LINE__, __FILE__, $sql); + } + + // Delete subcats + $sql = "DELETE FROM " . KB_ARTICLES_TABLE . " WHERE cat_main = '" . $cat_id . "'"; + if(!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't delete subcategories from articlecats table.", "", __LINE__, __FILE__, $sql); + } + + $message = $lang['kbadm_delcat_success'] . '<br /><br />' . sprintf($lang['kbadm_Click_return_catadmin'], '<a href="' . append_sid("admin_kb." . $phpEx . "?mode=cats") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>'); + + // Delete all articles in this category or set cat_id to another one or? I'm not sure how we should handle this? + message_die(GENERAL_MESSAGE, $message); + } + } + + if($add) + { + if(!isset($HTTP_POST_VARS['submit'])) + { + $template->set_filenames(array( + 'body' => 'admin/kb_editcat.tpl') + ); + + $parent = generate_cat_parents(); + $s_hidden_fields = '<input type="hidden" name="add" value="1">'; + + $template->assign_vars(array( + 'L_HEADER' => $lang['kbadm_header_addcat'], + 'L_EXPLAIN' => $lang['kbadm_explain_addcat'], + 'L_CAT_SETTINGS' => $lang['kbadm_cat_settings'], + 'L_CAT_TITLE' => $lang['kbadm_cat_title'], + 'L_CAT_DESCRIPTION' => $lang['kbadm_cat_desc'], + 'L_CAT_PARENT' => $lang['kbadm_cat_parent'], + + 'S_SUBMIT_VALUE' => $lang['kbadm_addcat'], + 'S_PARENT' => $parent, + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_FORUM_ACTION' => append_sid("admin_kb." . $phpEx . "?mode=cats")) + ); + + $template->pparse('body'); + + include('./page_footer_admin.'.$phpEx); + exit; + } + else + { + $error_msg = ''; + + if(!isset($HTTP_POST_VARS['title']) || $HTTP_POST_VARS['title'] == "") + { + $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['kbadm_empty_cat_title'] : $lang['admkb_empty_cat_title']; + } + + if(!isset($HTTP_POST_VARS['desc']) || $HTTP_POST_VARS['desc'] == "") + { + $error_msg .= (!empty($error_msg)) ? '<br />' . $lang['kbadm_empty_cat_desc'] : $lang['admkb_empty_cat_title']; + } + + if($error_msg != '') + { + $template->set_filenames(array( + 'body' => 'admin/kb_editcat.tpl') + ); + + $parent = generate_cat_parents($HTTP_POST_VARS['parent']); + $s_hidden_fields = '<input type="hidden" name="add" value="1">'; + + $template->set_filenames(array( + 'reg_header' => 'error_body.tpl') + ); + + $template->assign_vars(array( + 'ERROR_MESSAGE' => $error_msg) + ); + + $template->assign_var_from_handle('ERROR_BOX', 'reg_header'); + + $template->assign_vars(array( + 'L_HEADER' => $lang['kbadm_header_editcat'], + 'L_EXPLAIN' => $lang['kbadm_explain_editcat'], + 'L_CAT_SETTINGS' => $lang['kbadm_cat_settings'], + 'L_CAT_TITLE' => $lang['kbadm_cat_title'], + 'L_CAT_DESCRIPTION' => $lang['kbadm_cat_desc'], + 'L_CAT_PARENT' => $lang['kbadm_cat_parent'], + + 'CAT_TITLE' => $HTTP_POST_VARS['title'], + 'DESCRIPTION' => $HTTP_POST_VARS['desc'], + + 'S_SUBMIT_VALUE' => $lang['kbadm_addcat'], + 'S_PARENT' => $parent, + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_FORUM_ACTION' => append_sid("admin_kb." . $phpEx . "?mode=cats")) + ); + + $template->pparse('body'); + + include('./page_footer_admin.'.$phpEx); + exit; + } + else + { + $parent = isset($HTTP_POST_VARS['parent']) ? $HTTP_POST_VARS['parent'] : 0; + + $sql = "INSERT INTO " . KB_CATEGORIES_TABLE . " (cat_id, cat_main, cat_title, cat_desc, cat_articles, cat_order) + VALUES ('', '" . $parent . "', '" . trim(htmlspecialchars($HTTP_POST_VARS['title'])) . "', '" . trim(htmlspecialchars($HTTP_POST_VARS['desc'])) . "', '0', '9999');"; + + if(!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't insert new category.", "", __LINE__, __FILE__, $sql); + } + + sort_cats("add", $db->sql_nextid(), 0, $parent); + + // And a message here somewhere + $message = $lang['kbadm_addcat_success'] . '<br /><br />' . sprintf($lang['kbadm_Click_return_catadmin'], '<a href="' . append_sid("admin_kb." . $phpEx . "?mode=cats") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>'); + + message_die(GENERAL_MESSAGE, $message); + } + } + } + + if($sort != false) + { + $sort = explode("|", $sort); + + // ok so ?sort=id|up/down|level + sort_cats("", $sort[0], $sort[1], $sort[2]); // Put id2 in the level argument, nvm that :) + + // And yes yet another message here + $message = $lang['kbadm_sortcat_success'] . '<br /><br />' . sprintf($lang['kbadm_Click_return_catadmin'], '<a href="' . append_sid("admin_kb." . $phpEx . "?mode=cats") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>'); + + message_die(GENERAL_MESSAGE, $message); + } + + // Show categories as list + $cats = get_cats_structure(); + + $template->set_filenames(array( + 'body' => 'admin/kb_cats.tpl') + ); + + $template->assign_vars(array( + 'L_CATEGORIES' => $lang['kb_categories'], + 'L_EDITCAT' => $lang['kbadm_editcat'], + 'L_DELCAT' => $lang['kbadm_delcat'], + 'L_HEADER' => $lang['Categories'], + 'L_EXPLAIN' => $lang['kbadm_maincat_explain']) + ); + + if($total_catrows = count($cats)) + { + for($i = 0; $i < $total_catrows; $i++) + { + // Check if the cat is at the top and therefore cant be moved up + if(($cats[$i - 1]['cat_main'] != $cats[$i]['cat_main']) || (strlen($cats[$i - 1]['cat_id']) == 0)) + { + $movecat_up = $lang['kbadm_movecatup']; + } + else + { + $movecat_up = '<a href="' . append_sid('admin_kb.' . $phpEx . '?mode=cats&s=' . $cats[$i]['cat_id'] . '|up|' . $cats[$i]['cat_main']) . '">' . $lang['kbadm_movecatup'] . '</a>'; + } + + // Check if the cat is at the bottom and therefore cant be moved down + if(($cats[$i + 1]['cat_main'] != $cats[$i]['cat_main']) || (strlen($cats[$i + 1]['cat_id']) == 0)) + { + $movecat_down = $lang['kbadm_movecatdown']; + } + else + { + $movecat_down = '<a href="' . append_sid('admin_kb.' . $phpEx . '?mode=cats&s=' . $cats[$i]['cat_id'] . '|down|' . $cats[$i]['cat_main']) . '">' . $lang['kbadm_movecatdown'] . '</a>'; + } + + // Ok display one cat here + $template->assign_block_vars('catrow', array( + // Name 'nd stuff + 'CAT_TITLE' => $cats[$i]['cat_title'], + 'CAT_DESC' => $cats[$i]['cat_desc'], + + // Links + 'U_EDITCAT' => append_sid("admin_kb." . $phpEx . "?mode=cats&edit=" . $cats[$i]['cat_id']), + 'U_DELCAT' => append_sid("admin_kb." . $phpEx . "?mode=cats&delete=" . $cats[$i]['cat_id']), + // sort=id,id2|up/down|level + 'MOVECAT_UP' => $movecat_up, + 'MOVECAT_DOWN' => $movecat_down, + + // Image + 'FORUM_FOLDER_IMG' => "../" . $images['forum']) // Stolen :D + ); + + if($total_subcats = count($cats[$i]['subcats'])) + { + // Contains subcats, show them + //$template->assign_block_vars('catrow.switch_subcat', array( + //'L_SUBCATS' => $lang['kb_subcats']) + //); + + for($j = 0; $j < $total_subcats; $j++) + { + if(($cats[$i]['subcats'][$j - 1]['cat_main'] != $cats[$i]['subcats'][$j]['cat_main']) || (strlen($cats[$i]['subcats'][$j - 1]['cat_id']) == 0)) + { + $subcatmove_up = $lang['kbadm_movecatup']; + } + else + { + $subcatmove_up = '<a href="' . append_sid('admin_kb.' . $phpEx . '?mode=cats&s=' . $cats[$i]['subcats'][$j]['cat_id'] . '|up') . '">' . $lang['kbadm_movecatup'] . '</a>'; + } + + // Check if the cat is at the bottom and therefore cant be moved down + if(($cats[$i]['subcats'][$j + 1]['cat_main'] != $cats[$i]['subcats'][$j]['cat_main']) || (strlen($cats[$i]['subcats'][$j + 1]['cat_id']) == 0)) + { + $subcatmove_down = $lang['kbadm_movecatdown']; + } + else + { + $subcatmove_down = '<a href="' . append_sid('admin_kb.' . $phpEx . '?mode=cats&s=' . $cats[$i]['subcats'][$j]['cat_id'] . '|down') . '">' . $lang['kbadm_movecatdown'] . '</a>'; + } + + // Show the subcat + $template->assign_block_vars('catrow.subcatrow', array( + 'SUBCAT_TITLE' => $cats[$i]['subcats'][$j]['cat_title'], + 'SUBCAT_DESC' => $cats[$i]['subcats'][$j]['cat_desc'], + + // Links + 'U_EDITSUBCAT' => append_sid("admin_kb." . $phpEx . "?mode=cats&edit=" . $cats[$i]['subcats'][$j]['cat_id']), + 'U_DELSUBCAT' => append_sid("admin_kb." . $phpEx . "?mode=cats&delete=" . $cats[$i]['subcats'][$j]['cat_id']), + // sort=id,id2|up/down|level + 'MOVESUBCAT_UP' => $subcatmove_up, + 'MOVESUBCAT_DOWN' => $subcatmove_down, + + 'TOPIC_FOLDER_IMG' => "../" . $images['folder']) // Stolen :D + ); + } // for subcats + + //$template->assign_block_vars('catrow.switch_subcat_close', array()); + } // if subcats + } // for cats + + $parent = generate_cat_parents(); + $s_hidden_fields = '<input type="hidden" name="add" value="1">'; + + $template->assign_vars(array( + 'L_CAT_SETTINGS' => $lang['kbadm_addcat'], + 'L_CAT_TITLE' => $lang['kbadm_cat_title'], + 'L_CAT_DESCRIPTION' => $lang['kbadm_cat_desc'], + 'L_CAT_PARENT' => $lang['kbadm_cat_parent'], + + 'S_SUBMIT_VALUE' => $lang['kbadm_addcat'], + 'S_PARENT' => $parent, + 'S_HIDDEN_FIELDS' => $s_hidden_fields, + 'S_FORUM_ACTION' => append_sid("admin_kb." . $phpEx . "?mode=cats")) + ); + + $template->pparse('body'); + }// total cats + else + { + message_die(GENERAL_MESSAGE, sprintf($lang['No_kbadm_cats'], '<a href="' . append_sid("admin_kb." . $phpEx . "?mode=cats&add=1") . '">', '</a>')); + } + + include('./page_footer_admin.'.$phpEx); + exit; + break; + + case "auth": // For later use + break; + + case "files": // For later use + break; + + default: // General settings here + break; +} + + +////////////////// +/// FUNCTIONS /// +////////////////// +function generate_cat_parents($selected = false) +{ + global $db, $lang; + + $sql = "SELECT cat_id, cat_title + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_main = '0' + ORDER BY cat_order ASC"; // At the moment only one level of subcats + if(!$result = $db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't get categories from categories table", "", __LINE__, __FILE__, $sql); + } + + $cats = array(); + while($row = $db->sql_fetchrow($result)) + { + $cats[] = $row; + } + + if(!$selected) + { + $parent = '<select name="parent">\n<option value="0" selected="selected">' . $lang['kb_main'] . '</option>\n'; + } + else + { + $parent = '<select name="parent">\n<option value="0">' . $lang['kb_main'] . '</option>\n'; + } + + for($i = 0; $i < count($cats); $i++) + { + if(!$selected) + { + $parent .= '<option value="' . $cats[$i]['cat_id'] . '">' . $cats[$i]['cat_title'] . '</option>\n'; + } + else + { + if($cats[$i]['cat_id'] == $selected) + { + $parent .= '<option value="' . $cats[$i]['cat_id'] . '" selected="selected">' . $cats[$i]['cat_title'] . '</option>\n'; + } + else + { + $parent .= '<option value="' . $cats[$i]['cat_id'] . '">' . $cats[$i]['cat_title'] . '</option>\n'; + } + } + } + + $parent .= "</select>"; + + return $parent; +} + +function sort_cats($type = "", $id = 0, $dir = 0, $level = 0) +{ + global $db; + + if($type == "add") + { + $sql = "SELECT cat_id + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_main = '" . $level . "' + ORDER BY cat_order ASC"; + + if(!$result = $db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't retrieve order data from cat table.", "", __LINE__, __FILE__, $sql); + } + + $cat_number = $db->sql_numrows($result); + + $sql = "UPDATE " . KB_CATEGORIES_TABLE . " + SET cat_order = '" . $cat_number . "' + WHERE cat_id = '" . $id . "'"; + + if(!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't alter categories order.", "", __LINE__, __FILE__, $sql); + } + + return; + } + elseif($type == "edit") + { + // First clean up in the old level where it is gone from + $sql = "SELECT cat_id + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_main = '" . $level[1] . "' + ORDER BY cat_order ASC"; + + if(!$result = $db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't retrieve order data from cat table.", "", __LINE__, __FILE__, $sql); + } + + $sql = ""; + $i = 0; + while($old_cat = $db->sql_fetchrow($result)) + { + $i++; + $sql = "UPDATE " . KB_CATEGORIES_TABLE . " + SET cat_order = '" . $i . "' + WHERE cat_id = '" . $old_cat['cat_id'] . "';\n"; + if(!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't sort old level order in cat table.", "", __LINE__, __FILE__, $sql); + } + } + + // Ok insert it in the back of the new one :) + $sql = "SELECT cat_id + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_main = '" . $level[0] . "' + ORDER BY cat_order ASC"; + + if(!$result = $db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't retrieve order data from cat table.", "", __LINE__, __FILE__, $sql); + } + + $cat_number = $db->sql_numrows($result); + + $sql = "UPDATE " . KB_CATEGORIES_TABLE . " + SET cat_order = '" . $cat_number . "' + WHERE cat_id = '" . $id . "'"; + + if(!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't alter categories order.", "", __LINE__, __FILE__, $sql); + } + + return; + } + else + { + $sql = "SELECT cat_order, cat_main + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_id = '" . $id . "'"; + + if(!$result = $db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't retrieve categories order data.", "", __LINE__, __FILE__, $sql); + } + + $cat = $db->sql_fetchrow($result); + + if($dir == "up") + { + $num = $cat['cat_order'] - 1; + + $sql = "SELECT cat_id, cat_order + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_order = '" . $num . "' + AND cat_main = '" . $cat['cat_main'] . "'"; + + if(!$result = $db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't retrieve categories order data.", "", __LINE__, __FILE__, $sql); + } + + $cat2 = $db->sql_fetchrow($result); + } + elseif($dir == "down") + { + $num = $cat['cat_order'] + 1; + + $sql = "SELECT cat_id, cat_order + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_order = '" . $num . "' + AND cat_main = '" . $cat['cat_main'] . "'"; + + if(!$result = $db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't retrieve categories order data.", "", __LINE__, __FILE__, $sql); + } + + $cat2 = $db->sql_fetchrow($result); + } + + $sql = "UPDATE " . KB_CATEGORIES_TABLE . " + SET cat_order = '" . $cat2['cat_order'] . "' + WHERE cat_id = '" . $id . "'"; + + if(!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't alter categories order data.", "", __LINE__, __FILE__, $sql); + } + + $sql = "UPDATE " . KB_CATEGORIES_TABLE . " + SET cat_order = '" . $cat['cat_order'] . "' + WHERE cat_id = '" . $cat2['cat_id'] . "'"; + + if(!$db->sql_query($sql)) + { + message_die(GENERAL_ERROR, "Couldn't alter categories order data.", "", __LINE__, __FILE__, $sql); + } + + return; + } +} +?> Added: main/trunk/install/kb_install.php =================================================================== --- main/trunk/install/kb_install.php (rev 0) +++ main/trunk/install/kb_install.php 2007-01-26 18:02:51 UTC (rev 42) @@ -0,0 +1,138 @@ +<?php +/*************************************************************************** + * kb_install.php + * ------------------- + * + * copyright: phpBB KB Group + * site: http://www.phpbbknowledgebase.com + * SF Project Page: http://www.sourceforge.net/projects/phpbbkb + * + ***************************************************************************/ + +/*************************************************************************** + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + ***************************************************************************/ + +define('IN_PHPBB', true); +$phpbb_root_path = './'; +include($phpbb_root_path . 'extension.inc'); +include($phpbb_root_path . 'common.' . $phpEx); + +// +// Start session management +// +$userdata = session_pagestart($user_ip, PAGE_INDEX); +init_userprefs($userdata); +// +// End session management +// + + +if( !$userdata['session_logged_in'] ) +{ + $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: '; + header($header_location . append_sid($phpbb_root_path . "login.$phpEx?redirect=kb_install.$phpEx", true)); + exit; +} + +if( $userdata['user_level'] != ADMIN ) +{ + message_die(GENERAL_MESSAGE, 'You are not authorised to access this page'); +} + +$page_title = 'phpBB Knowledge Base MOD'; +include('includes/page_header.' . $phpEx); + +$sql = array(); +$sql[] = "CREATE TABLE " . $table_prefix . "kb_categories ( + cat_id mediumint(8) UNSIGNED NOT NULL auto_increment, + cat_main mediumint(8) UNSIGNED DEFAULT '0', + cat_title varchar(100) NOT NULL, + cat_desc varchar(255) NOT NULL, + cat_articles mediumint(8) UNSIGNED DEFAULT '0', + cat_order mediumint(8) UNSIGNED NOT NULL, + auth_view tinyint(1) NOT NULL default '0', + auth_add tinyint(1) NOT NULL default '0', + auth_edit tinyint(1) NOT NULL default '0', + auth_delete tinyint(1) NOT NULL default '0', + auth_mod tinyint(1) NOT NULL default '0', + auth_comment tinyint(1) NOT NULL default '0', + auth_rate tinyint(1) NOT NULL default '0', + auth_attach tinyint(1) NOT NULL default '0', + PRIMARY KEY (cat_id), + KEY cat_order (cat_order) +)"; + +$sql[] = "CREATE TABLE " . $table_prefix . "kb_articles ( + article_id mediumint(8) UNSIGNED NOT NULL auto_increment, + article_title varchar(100) NOT NULL, + article_desc varchar(255) NOT NULL, + article_author mediumint(8) UNSIGNED NOT NULL, + article_authorname varchar(50) NOT NULL, + article_time int(20) UNSIGNED DEFAULT '0', + article_edittime int(20) UNSIGNED DEFAULT '0', + article_hits mediumint(8) UNSIGNED DEFAULT '0', + article_editby mediumint(8) UNSIGNED DEFAULT '0', + article_status smallint(1) UNSIGNED DEFAULT '0', + bbcode_uid varchar(10) NOT NULL, + enable_sig smallint(1) UNSIGNED DEFAULT '0', + enable_html smallint(1) UNSIGNED DEFAULT '0', + enable_bbcode smallint(1) UNSIGNED DEFAULT '0', + enable_smilies smallint(1) UNSIGNED DEFAULT '0', + article_text text, + PRIMARY KEY (article_id) +)"; + +$sql[] = "CREATE TABLE " . $table_prefix . "kb_articlecats ( + article_id mediumint(8) NOT NULL DEFAULT '0', + cat_id mediumint(8) NOT NULL DEFAULT '0' +)"; + +$sql[] = "CREATE TABLE " . $table_prefix . "kb_auth_access ( + group_id mediumint(8) NOT NULL default '0', + cat_id smallint(5) unsigned NOT NULL default '0', + auth_view tinyint(1) NOT NULL default '0', + auth_add tinyint(1) NOT NULL default '0', + auth_edit tinyint(1) NOT NULL default '0', + auth_delete tinyint(1) NOT NULL default '0', + auth_mod tinyint(1) NOT NULL default '0', + auth_comment tinyint(1) NOT NULL default '0', + auth_rate tinyint(1) NOT NULL default '0', + auth_attach tinyint(1) NOT NULL default '0', + KEY group_id (group_id), + KEY cat_id (cat_id) +)"; + +echo '<table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">'; +echo '<tr><th>Updating the database</th></tr>'; + +for( $i = 0; $i < count($sql); $i++ ) +{ + $msg = '<tr><td class="catLeft" height="28"><span class="forumlink">'; + + if( !$result = $db->sql_query($sql[$i]) ) + { + $error = $db->sql_error(); + $msg .= '<font color="#FF0000"><b>Error:</b></font> ' . $error['message']; + } + else + { + $msg .= '<font color="#00AA00"><b>Successfull</b></font>'; + } + + $msg .= '</span></td><tr><td class="row1"><pre class="genmed">' . $sql[$i] . '</pre></td></tr>'; + echo $msg; +} + +echo '<tr><th height="28">End</th></tr><tr><td class="row1"><span class="genmed">Installation is now finished. Please be sure to delete this file now.<br />'; +echo 'If you have run into any errors, please visit the '. + '<a href="http://www.phpbbknowledgebase.com" target="_blank">phpBB Knowledge Base Forums</a> or the <a href="http://www.phpbb.com/phpBB/viewtopic.php?t=415458" target="_blank">phpBB.com topic</a> and ask someone for help.</span></td></tr>'; +echo '<tr><td class="catBottom" height="28" align="center"><span class="genmed"><a href="' . append_sid($phpbb_root_path . "index.$phpEx") . '">Have a nice day, and thanks for using the phpBB Knowledge Base MODification!</a></span></td></table>'; + +include('includes/page_tail.' . $phpEx); +?> \ No newline at end of file Added: main/trunk/kb.php =================================================================== --- main/trunk/kb.php (rev 0) +++ main/trunk/kb.php 2007-01-26 18:02:51 UTC (rev 42) @@ -0,0 +1,624 @@ +<?php +/*************************************************************************** + * kb.php + * ------------------- + * + * copyright: phpBB KB Group + * site: http://www.phpbbknowledgebase.com + * SF Project Page: http://www.sourceforge.net/projects/phpbbkb + * + ***************************************************************************/ + +/*************************************************************************** + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + ***************************************************************************/ +define('IN_PHPBB', true); +$phpbb_root_path = './'; +include($phpbb_root_path . 'extension.inc'); +include($phpbb_root_path . 'common.' . $phpEx); +include($phpbb_root_path . 'kb/constants.' . $phpEx); // Added these two files, yes i could just add the 10-15 lines it will end with in +include($phpbb_root_path . 'kb/functions.' . $phpEx); // the existing files, but this makes it a lot easier to install/uninstall. +include($phpbb_root_path . 'includes/bbcode.'.$phpEx); + +// +// Start session management +// +$userdata = session_pagestart($user_ip, PAGE_KB); +init_userprefs($userdata); +// +// End session management +// + +// File takes care of the following action set via $pid ($HTTP_GET_VARS['pid']): +// main - views categories, with subcategories listed +// view_cat - views a category, either lists subcategories or articles contained, or both ofc. +// view_article - views an article +// ucp - My idea of this is that it should be the complete possibility for users here. If they are normal users, they can see their own +// articles and if they get approved or not. They can also view their comments, and wether they are approved or not. This should +// also include mod options for admins. Approving/disapproving comments or articles, editing them, so on... +// search - the kb search engine... +// More will come whenever i figure something out. Now i'll start coding. :D // Imladris +include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_kb.' . $phpEx); +$pid = ( isset($HTTP_GET_VARS['pid']) ) ? $HTTP_GET_VARS['pid'] : "main"; + +// Making sure the install file has been removed +if(file_exists($phpbb_root_path . "kb_install." . $phpEx)) +{ + message_die(GENERAL_MESSAGE, $lang['kb_remove_installfile']); +} + +switch($pid) +{ + case "main": + $sql = "SELECT c.cat_id, c.cat_main, c.cat_title, c.cat_desc, c.cat_articles, c.cat_order + FROM " . KB_CATEGORIES_TABLE . " c + WHERE c.cat_main = '0' + ORDER BY c.cat_order ASC"; + if( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query categories list', '', __LINE__, __FILE__, $sql); + } + + $catrows = array(); + while ($row = $db->sql_fetchrow($result)) + { + $catrows[] = $row; + } + + // Start Page output + $page_title = $lang['kb_main']; + include($phpbb_root_path . 'includes/page_header.' . $phpEx); + create_navigation(); + + $template->set_filenames(array( + 'body' => 'kb_main.tpl') + ); + + if($userdata['session_logged_in']) + { + $template->assign_block_vars('switch_add_article', array()); + } + + $template->assign_vars(array( + 'L_CATEGORIES' => $lang['kb_categories'], + 'L_ARTICLES' => $lang['kb_articles'], + 'L_ADD_ARTICLE' => $lang['kb_ucp_articlepost'], + 'U_ADD_ARTICLE' => append_sid("kb." . $phpEx . "?pid=ucp&action=post_article")) + ); + + if($total_catrows = count($catrows)) + { + for($i = 0; $i < $total_catrows; $i++) + { + //$auth = kb_auth("view", $catrows[$i]['cat_id'], $userdata); + + // auth not included in alpha + //if($auth['auth_view']) + //{ + // Ok display one cat here + $template->assign_block_vars('catrow', array( + 'CAT_TITLE' => $catrows[$i]['cat_title'], + 'CAT_DESC' => $catrows[$i]['cat_desc'], + 'CAT_ARTICLES' => $catrows[$i]['cat_articles'], + 'U_VIEWCAT' => append_sid("kb." . $phpEx . "?pid=view_cat&id=" . $catrows[$i]['cat_id']), + 'L_SUBCATS' => $lang['kb_subcats'], + 'FORUM_FOLDER_IMG' => $images['forum']) // Stolen :D + ); + + // Now let's look at subcats + $sql = "SELECT c.cat_id, c.cat_main, c.cat_title, c.cat_order + FROM " . KB_CATEGORIES_TABLE . " c + WHERE c.cat_main = '" . $catrows[$i]['cat_id'] . "' + ORDER BY c.cat_order ASC"; + if( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query subcategories list', '', __LINE__, __FILE__, $sql); + } + + $subcats = array(); + while ($row = $db->sql_fetchrow($result)) + { + $subcats[] = $row; + } + + if($total_subcats = count($subcats)) + { + // Contains subcats, show them + $template->assign_block_vars('catrow.switch_subcats', array()); + + for($j = 0; $j < $total_subcats; $j++) + { + //$auth = kb_auth("view", $subcats[$j]['cat_id'], $userdata); + + // auth not included in alpha + //if($auth['auth_view']) + //{ + // Show the subcat + $k = $j + 1; + $subcat_comma = ( isset($subcats[$k]) ) ? ", " : "."; + $template->assign_block_vars('catrow.subcatrow', array( + 'U_SUBCAT' => append_sid("kb." . $phpEx . "?pid=view_cat&id=" . $subcats[$j]['cat_id']), + 'SUBCAT_TITLE' => $subcats[$j]['cat_title'], + 'SUBCAT_COMMA' => $subcat_comma) + ); + //} // if auth view + } // for subcats + } // if subcats + //} // auth view + } // for cats + }// total cats + else + { + message_die(GENERAL_MESSAGE, $lang['No_kb_cats']); + } + + // + // Generate the page + // + $template->pparse('body'); + + include($phpbb_root_path . 'includes/page_tail.'.$phpEx); + break; + + case "view_cat": + $cat_id = ( isset( $HTTP_GET_VARS['id'] ) ) ? $HTTP_GET_VARS['id'] : false; + if(!$cat_id) + { + message_die(GENERAL_MESSAGE, $lang['kb_cat_noexist']); + } + + // Store the main cat in a variable + $sql = "SELECT * + FROM " . KB_CATEGORIES_TABLE . " + WHERE cat_id = '" . $cat_id . "'"; + if( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query the main category', '', __LINE__, __FILE__, $sql); + } + $cat = $db->sql_fetchrow($result); + + // Let's find subcats + $sql = "SELECT c.cat_id, c.cat_main, c.cat_title, c.cat_desc, c.cat_articles, c.cat_order + FROM " . KB_CATEGORIES_TABLE . " c + WHERE c.cat_main = '$cat_id' + ORDER BY c.cat_order ASC"; + if( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query subcategories list', '', __LINE__, __FILE__, $sql); + } + + $subcats = array(); + while($row = $db->sql_fetchrow($result)) + { + $subcats[] = $row; + } + + // Now articles, the LIKE handles multiple cats + // First handle the sorting + // default is by edit time, other options: -rating, -author, -title + if(isset($HTTP_GET_VARS['sort'])) + { + switch($HTTP_GET_VARS['sort']) + { + case "rating": + // Later + $sort = "ORDER BY a.article_edittime DESC"; + break; + + case "author": + // Later + $sort = "ORDER BY a.article_edittime DESC"; + break; + + case "title": + $sort = "ORDER BY a.article_title"; + break; + + case "time": + default: + $sort = "ORDER BY a.article_edittime DESC"; + break; + } + } + else + { + $sort = "ORDER BY a.article_edittime DESC"; + } + + $sql = "SELECT a.* + FROM " . KB_ARTICLECATS_TABLE . " c, " . KB_ARTICLES_TABLE . " a + WHERE c.cat_id = '$cat_id' + AND c.article_id = a.article_id + $sort"; + if( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query articles.', '', __LINE__, __FILE__, $sql); + } + + $articles = array(); + while($row = $db->sql_fetchrow($result)) + { + $articles[] = $row; + } + + // Start Page output + $page_title = $lang['kb_viewcat'] . ": " . $cat['cat_title']; + include($phpbb_root_path . 'includes/page_header.'.$phpEx); + + if($cat['cat_main'] == "0") + { + create_navigation("viewcat", array( + 0 => $cat['cat_id'], + 1 => $cat['cat_title']) + ); + } + else + { + create_navigation("viewsubcat", array( + 0 => $cat_id, + 1 => $cat['cat_title'], + 2 => $cat['cat_main']) + ); + } + + $template->set_filenames(array( + 'body' => 'kb_viewcat.tpl') + ); + + if($userdata['session_logged_in']) + { + $template->assign_block_vars('switch_add_article', array()); + } + + // Process the whole thing + $template->assign_vars(array( + 'L_VIEWS' => $lang['Views'], + 'L_AUTHOR' => $lang['Author'], + 'L_ARTICLES' => $lang['kb_articles'], + 'L_SUBCATS' => sprintf($lang['kb_viewcat_subcats'], $cat['cat_title']), + 'L_LAST_ACTION' => $lang['kb_last_action'], + 'L_ADD_ARTICLE' => $lang['kb_ucp_articlepost'], + 'U_ADD_ARTICLE' => append_sid("kb." . $phpEx . "?pid=ucp&action=post_article")) + ); + + if( $total_subcats = count($subcats) ) + { + $template->assign_block_vars('switch_subcats', array()); + + // Ok it contains subcats, let's build them. + for($i = 0; $i < $total_subcats; $i++) + { + // Ok display one cat here + $template->assign_block_vars('switch_subcats.catrow', array( + 'CAT_TITLE' => $subcats[$i]['cat_title'], + 'CAT_DESC' => $subcats[$i]['cat_desc'], + 'CAT_ARTICLES' => $subcats[$i]['cat_articles'], + 'U_VIEWCAT' => append_sid("kb." . $phpEx . "?pid=view_cat&id=" . $subcats[$i]['cat_id']), + 'FORUM_FOLDER_IMG' => $images['forum']) // Stolen :D + ); + } + } + + if( $total_articles = count($articles) ) + { + $template->assign_block_vars('switch_articles', array()); + + // Contains articles + for($i = 0; $i < $total_articles; $i++) + { + if($articles[$i]['article_authorname'] == "") + { + $sql = "SELECT username + FROM " . USERS_TABLE . " + WHERE user_id = '" . $articles[$i]['article_author']; + if( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query authorname', '', __LINE__, __FILE__, $sql); + } + + $user = $db->sql_fetchrow($result); + $authorname = $user['username']; + } + else + { + $authorname = $articles[$i]['article_authorname']; + } + $author = "<a href=\"profile." . $phpEx . "?mode=viewprofile&u=" . $articles[$i]['article_author'] . "\">$authorname</a>"; + + $sql = "SELECT username + FROM " . USERS_TABLE . " + WHERE user_id = '" . $articles[$i]['article_editby'] . "'"; + if( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query last edited by\'s username.', '', __LINE__, __FILE__, $sql); + } + + $user = $db->sql_fetchrow($result); + $last_action = sprintf($lang['kb_last_action_row'], "<a href=\"profile." . $phpEx . "?mode=viewprofile&u=" . $articles[$i]['article_editby'] . "\">" . $user['username'] . "</a>", create_date($board_config['default_dateformat'], $articles[$i]['article_edittime'], $board_config['board_timezone'])); + + $template->assign_block_vars('switch_articles.articlerow', array( + 'TOPIC_FOLDER_IMG' => $images['folder'], + 'ARTICLE_TITLE' => $articles[$i]['article_title'], + 'ARTICLE_DESC' => $articles[$i]['article_desc'], + 'ARTICLE_AUTHOR' => $author, + 'ARTICLE_HITS' => $articles[$i]['article_hits'], + 'ARTICLE_LAST_ACTION' => $last_action, + 'U_VIEW_ARTICLE' => append_sid("kb." . $phpEx . "?pid=view_article&cid=" . $cat_id . "&id=" . $articles[$i]['article_id'])) + ); + } + } + + // + // Generate the page + // + $template->pparse('body'); + + include($phpbb_root_path . 'includes/page_tail.'.$phpEx); + break; + + case "view_article": + $cid = ( empty($HTTP_GET_VARS['cid']) ) ? false : $HTTP_GET_VARS['cid']; + $id = ( empty($HTTP_GET_VARS['id']) ) ? false : $HTTP_GET_VARS['id']; + + // Get naughty words :) + $orig_word = array(); + $replacement_word = array(); + obtain_word_list($orig_word, $replacement_word); + + $sql = "SELECT a.*, u.* + FROM " . KB_ARTICLES_TABLE . " a, " . USERS_TABLE . " u + WHERE a.article_id = '$id' + AND a.article_author = u.user_id"; + if( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query article info', '', __LINE__, __FILE__, $sql); + } + + $article = $db->sql_fetchrow($result); + + $sql = "SELECT c.*, ca.* + FROM " . KB_ARTICLECATS_TABLE . " c, " . KB_CATEGORIES_TABLE . " ca + WHERE c.article_id = '$id' + AND ca.cat_id = c.cat_id"; + if( !($result = $db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Could not query article categories.', '', __LINE__, __FILE__, $sql); + } + + // + // These vars are for later use + // + $in_cat = false; + $cats = array(); + while($row = $db->sql_fetchrow($result)) + { + $cats[] = $row; + + if($row['cat_id'] == $cid) + { + $in_cat = true; + $current_cat['cat_title'] = $row['cat_title']; + $current_cat['cat_id'] = $row['cat_id']; + $current_cat['cat_main'] = $row['cat_main']; + } + } + + // + // Check that the given category is true + // + if(!$in_cat) + { + message_die(GENERAL_MESSAGE, "The category specified in GET variables did not exist along with this article in the database."); + } + + $article_title = $article['article_title']; + $article_text = $article['article_text']; + $article_bbcode_uid = $article['bbcode_uid']; + + $user_sig = ( $article['enable_sig'] && $article['user_sig'] != '' && $board_config['allow_sig'] ) ? $article['user_sig'] : ''; + $user_sig_bbcode_uid = $article['user_sig_bbcode_uid']; + + // A lot of copy/paste from viewtopic.php, then shaped for this file ofc :) + // + // If the board has HTML off but the post has HTML + // on then we process it, else leave it alone + // + if ( !$board_config['allow_html'] || !$userdata['user_allowhtml']) + { + if ( $user_sig != '' ) + { + $user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $user_sig); + } + + if ( $article['enable_html'] ) + { + $article_text = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $article_text); + } + } + + // + // Parse message and/or sig for BBCode if reqd + // + if ($user_sig != '' && $user_sig_bbcode_uid != '') + { + $user_sig = ($board_config['allow_bbcode']) ? bbencode_second_pass($user_sig, $user_sig_bbcode_uid) : preg_replace("/\:$user_sig_bbcode_uid/si", '', $user_sig); + } + + if ($article_bbcode_uid != '') + { + $article_text = ($board_config['allow_bbcode']) ? bbencode_second_pass($article_text, $article_bbcode_uid) : preg_replace("/\:$article_bbcode_uid/si", '', $article_text); + } + + if ( $user_sig != '' ) + { + $user_sig = make_clickable($user_sig); + } + $article_text = make_clickable($article_text); + + // + // Parse smilies + // + if ( $board_config['allow_smilies'] ) + { + if ( $article['user_allowsmile'] && $user_sig != '' ) + { + $user_sig = smilies_pass($user_sig); + } + + if ( $article['enable_smilies'] ) + { + $article_text = smilies_pass($article_text); + } + } + + // + // Replace naughty words + // + if (count($orig_word)) + { + $article_title = preg_replace($orig_word, $replacement_word, $article_title); + $article_desc = preg_replace($orig_word, $replacement_word, $article_desc); + + if ($user_sig != '') + { + $user_sig = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $user_sig . '<'), 1, -1)); + } + + $article_text = str_replace('\"', '"', substr(@preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "@preg_replace(\$orig_word, \$replacement_word, '\\0')", '>' . $article_text . '<'), 1, -1)); + } + + // + // Replace newlines (we use this rather than nl2br because + // till recently it wasn't XHTML compliant) + // + if ( $user_sig != '' ) + { + $user_sig = '<br />_________________<br />' . str_replace("\n", "\n<br />\n", $user_sig); + } + + $article_text = str_replace("\n", "\n<br />\n", $article_text); + + // Start Page output + $page_title = $lang['kb_viewarticle'] . " : " . $article_title; + include($phpbb_root_path . 'includes/page_header.' . $phpEx); + + $template->set_filenames(array( + 'body' => 'kb_viewarticle.tpl') + ); + + create_navigation("viewarticle", array( + 0 => $current_cat['cat_id'], + 1 => $current_cat['cat_title'], + 2 => $current_cat['cat_main'], + 3 => $article['article_id'], + 4 => $article_title) + ); + + $posted_by = sprintf($lang['kb_posted_by'], '<a href="' . append_sid('profile.' . $phpEx . '?mode=viewprofile&u=' . $article['article_author']) . '">' . $article['article_authorname'] . '</a>', create_date($board_config['default_dateformat'], $article['article_time'], $board_config['board_timezone']), create_date($board_config['default_dateformat'], $article['article_edittime'], $board_config['board_timezone'])); + + $template->assign_vars(array( + 'U_VIEW_ARTICLE' => append_sid('kb.' . $phpEx . '?pid=view_article&cid=' . $cid . '&id=' . $article['article_id']), + 'ARTICLE_TITLE' => $article_title, + 'ARTICLE_TEXT' => $article_text, + 'POSTED_BY' => $posted_by, + 'SIGNATURE' => $user_sig, + 'L_EDITARTICLE' => $lang['kb_ucp_articleedit'], + 'L_DELETEARTICLE' => $lang['kb_ucp_articledelete'], + + 'U_EDITARTICLE' => append_sid('kb.' . $phpEx . '?pid=ucp&action=edit_article&id=' . $id), + 'U_DELETEARTICLE' => append_sid('kb.' . $phpEx . '?pid=ucp&action=delete_article&id=' . $id)) + ); + + if(($userdata['user_level'] == ADMIN) || ($userdata['user_id'] == $article['article_author'])) + { + $template->assign_block_vars('switch_mod', array()); + } + + // + // Generate the page + // + $template->pparse('body'); + + include($phpbb_root_path . 'includes/page_tail.'.$phpEx); + break; + + case "ucp": + $action = ( isset($HTTP_GET_VARS['action']) ) ? $HTTP_GET_VARS['action'] : ""; + /*include($phpbb_root_path . "kb/ucp_class." . $phpEx); + $ucp = new ucp; + + // Start Page output + $page_title = $ucp->generate_page_title($action); + include($phpbb_root_path . 'includes/page_header.' . $phpEx); + + $ucp->generate_page($action, $HTTP_GET_VARS['id'], $HTTP_GET_VARS['preview']); + */ + // The above have been removed and changed to functions.php + $id = isset($HTTP_GET_VARS['id']) ? $HTTP_GET_VARS['id'] : 0; + $preview = isset($HTTP_POST_VARS['preview']) ? true : false; + + $page_title = ucp_generate_page_title($action); + include($phpbb_root_path . 'includes/page_header.' . $phpEx); + + switch($action) + { + case "articles": + break; + + case "comments": + break; + + case "post_article": + ucp_article_form("post", false, $preview); + break; + + case "edit_article": + ucp_article_form("edit", $id, $preview); + break; + + case "delete_article": + $confirm = isset($HTTP_POST_VARS['confirm']) ? true : false; + ucp_article_delete($id, $confirm); + break; + + case "post_comment": // Only input + break; + + case "edit_comment": + break; + + case "delete_comment": + break; + + default: + break; + } + + // + // Generate the page + // + if($action != "delete_article") + { + $template->pparse('body'); + } + + include($phpbb_root_path . 'includes/page_tail.'.$phpEx); + break; + + case "search": + break; + + case "comment": + // For Adding, deleting and editing comments, this includes rating. + break; + + default: + message_die(GENERAL_MESSAGE, 'Wrong page id defined. No page shown.'); + break; +} +?> \ No newline at end of file Added: main/trunk/language/lang_english/lang_kb.php =================================================================== --- main/trunk/language/lang_english/lang_kb.php (rev 0) +++ main/trunk/language/lang_english/lang_kb.php 2007-01-26 18:02:51 UTC (rev 42) @@ -0,0 +1,97 @@ +<?php +/*************************************************************************** + * lang_kb.php + * ------------------- + * + * copyright: phpBB KB Group + * site: http://www.phpbbknowledgebase.com + * SF Project Page: http://www.sourceforge.net/projects/phpbbkb + * + ***************************************************************************/ + +/*************************************************************************** + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + ***************************************************************************/ + +// Page titles +$lang['kb_main'] = "Knowledge Base Home"; +$lang['kb_viewcat'] = "Viewing Category"; +$lang['kb_viewarticle'] = "Viewing Article"; +$lang['kb_ucp'] = "KB User Control Panel"; +$lang['kb_ucp_articlepost'] = "Post new article"; +$lang['kb_ucp_articleedit'] = "Edit article"; +$lang['kb_ucp_articledelete'] = "Delete article"; + +// Normal Page +$lang['kb_categories'] = "Knowledge Base Categories"; +$lang['kb_articles'] = "Articles"; +$lang['kb_subcats'] = "Subcategories"; +$lang['kb_remove_installfile'] = "Please ensure that you remove the kb_install.php file located in your phpBB root folder. The Knowledge Base Modification <strong>will not</strong> work before the file is removed."; +$lang['No_kb_cats'] = "No Knowledge Base categories have been added."; +$lang['kb_cat_noexist'] = "The category you have chosen does not exist."; + +$lang['kb_viewcat_subcats'] = "Subcategories in %s"; +$lang['kb_last_action'] = "Last action"; +$lang['kb_last_action_row'] = "Last action for this article was comitted by %s on the %s"; + +// Posting Page +$lang['kb_post_article'] = "Post New Article"; +$lang['kb_edit_article'] = "Edit Article"; +$lang['kb_authorname'] = "Author Name"; +$lang['kb_authorname_desc'] = "This is the name that will be displayed, you can leave your forum username here if you require, or replace it with another name."; +$lang['kb_articlename'] = "Article Name"; +$lang['kb_articledesc'] = "Article Description"; +$lang['kb_articlecats'] = "Article Categories"; +$lang['kb_articletext'] = "Article Content"; +$lang['kb_articledesc_desc'] = "Description of your article, max. 255 characters."; +$lang['kb_articlecats_desc'] = "Choose what categories your article will appear in, use Ctrl & Click for multiple."; +$lang['kb_empty_article'] = "The article content you have submitted was empty."; +$lang['kb_empty_article_title'] = "The article title you submitted was empty."; +$lang['kb_empty_cats'] = "The article you submitted had no category defined."; +$lang['kb_empty_article_desc'] = "The article has to contain an article description."; +$lang['kb_added'] = "Your article has been submitted and is awaiting approval."; +$lang['kb_deleted'] = "Your article has been deleted and is now nonexistant."; +$lang['kb_edited'] = "Your article has been edited and is awaiting reapproval."; +$lang['kb_click_view_article'] = "Click %shere%s to view you article."; // Change this later on, they can't view the article yet. +$lang['kb_click_return_ucp'] = "Click %shere%s to go back to the user control panel"; +$lang['kb_posted_by'] = "This article was submitted by %s on %s, it was last updated on %s."; +$lang['kb_confirm_deletearticle'] = "Are you sure you want to delete this article?"; +$lang['kb_articlepreview'] = "Article Preview"; + +// Auth +$lang['kb_edit_noauth'] = "You are not allowed to edit this article."; +$lang['kb_delete_noauth'] = "You are not allowed to delete this article."; + +// Admin +$lang['kbadm_header_editcat'] = "Edit Category"; +$lang['kbadm_explain_editcat'] = "Here you can edit the chosen category, specifying its name, parent category and description."; +$lang['kbadm_cat_settings'] = "Category Properties"; +$lang['kbadm_cat_title'] = "Category Title"; +$lang['kbadm_cat_desc'] = "Category Description"; +$lang['kbadm_cat_parent'] = "Parent Category"; +$lang['kbadm_empty_cat_title'] = "The Category Title submitted was empty."; +$lang['kbadm_empty_cat_desc'] = "The Category Description submitted was empty."; +$lang['kbadm_confirm_deletecat'] = "Are you sure you want to delete this category?"; +$lang['kbadm_Click_return_catadmin'] = "Click %shere%s to return to category administration."; +$lang['kbadm_header_addcat'] = "Add Category"; +$lang['kbadm_explain_addcat'] = "From here you can add a new category."; +$lang['kbadm_addcat'] = "Add"; +$lang['kbadm_editcat'] = "Edit"; + +$lang['kbadm_movecatup'] = "Move Up"; +$lang['kbadm_movecatdown'] = "Move Down"; +$lang['kbadm_delcat'] = "Delete"; +$lang['kbadm_maincat_explain'] = "This is the place where you can move categories up and down, create new ones and edit the already existant."; + +$lang['kbadm_delcat_success'] = "The category has been deleted successfully."; +$lang['kbadm_editcat_success'] = "The category has been edited successfully."; +$lang['kbadm_addcat_success'] = "Your new category has been added."; +$lang['kbadm_sortcat_success'] = "The category has been moved as specified."; + +$lang['No_kbadm_cats'] = "No knowledge base categories has been added. Click %shere%s to create a new one."; +?> \ No newline at end of file Added: main/trunk/templates/subSilver/admin/kb_cats.tpl =================================================================== --- main/trunk/templates/subSilver/admin/kb_cats.tpl (rev 0) +++ main/trunk/templates/subSilver/admin/kb_cats.tpl 2007-01-26 18:02:51 UTC (rev 42) @@ -0,0 +1,66 @@ +<h1>{L_HEADER}</h1> + +<p>{L_EXPLAIN}</p> + +<table width="100%" cellpadding="2" cellspacing="1" border="0" class="forumline"> + <tr> + <th colspan="2" class="thCornerL" height="25" nowrap="nowrap"> {L_CATEGORIES} </th> + <th class="thCornerR" colspan="4" nowrap="nowrap"> </th> + </tr> + <tr> + <td class="catLeft" colspan="2" height="28"><span class="cattitle"> </span></td> + <td class="rowpic" colspan="4" align="right"> </td> + </tr> + <!-- BEGIN catrow --> + <tr> + <td class="row1" align="center" valign="middle" height="50"><img src="{catrow.FORUM_FOLDER_IMG}" width="46" height="25" /></td> + <td class="row1" width="100%" height="50">{catrow.CAT_TITLE}<br /> + </span> <span class="genmed">{catrow.CAT_DESC}</td> + <td class="row1" align="center" valign="middle" height="50" nowrap="nowrap"><span class="genmed"><a href="{catrow.U_EDITCAT}">{L_EDITCAT}</a></span></td> + <td class="row1" align="center" valign="middle" height="50" nowrap="nowrap"><span class="genmed">{catrow.MOVECAT_UP}</span></td> + <td class="row1" align="center" valign="middle" height="50" nowrap="nowrap"><span class="genmed">{catrow.MOVECAT_DOWN}</span></td> + <td class="row1" align="center" valign="middle" height="50" nowrap="nowrap"><span class="genmed"><a href="{catrow.U_DELCAT}">{L_DELCAT}</a></span></td> + </tr> + <!-- BEGIN subcatrow --> + <tr> + <td class="row2" align="center" valign="middle" height="50"><img src="{catrow.subcatrow.TOPIC_FOLDER_IMG}" width="19" height="18" /></td> + <td class="row2" width="100%" height="50">{catrow.subcatrow.SUBCAT_TITLE}<br /> + <span class="genmed">{catrow.subcatrow.SUBCAT_DESC}</span></td> + <td class="row2" align="center" valign="middle" height="50" nowrap="nowrap"><span class="genmed"><a href="{catrow.subcatrow.U_EDITSUBCAT}">{L_EDITCAT}</a></span></td> + <td class="row2" align="center" valign="middle" height="50" nowrap="nowrap"><span class="genmed">{catrow.subcatrow.MOVESUBCAT_UP}</span></td> + <td class="row2" align="center" valign="middle" height="50" nowrap="nowrap"><span class="genmed">{catrow.subcatrow.MOVESUBCAT_DOWN}</span></td> + <td class="row2" align="center" valign="middle" height="50" nowrap="nowrap"><span class="genmed"><a href="{catrow.subcatrow.U_DELSUBCAT}">{L_DELCAT}</a></span></td> + </tr> + <!-- END subcatrow --> + <!-- END catrow --> + <tr> + <td class="catBottom" align="center" valign="middle" colspan="6" height="28"> </td> + </tr> +</table> + +<br clear="all" /> + +<form action="{S_FORUM_ACTION}" method="post"> + <table width="100%" cellpadding="4" cellspacing="1" border="0" class="forumline" align="center"> + <tr> + <th class="thHead" colspan="2">{L_CAT_SETTINGS}</th> + </tr> + <tr> + <td class="row1">{L_CAT_TITLE}</td> + <td class="row2"><input type="text" size="25" name="title" value="" class="post" /></td> + </tr> + <tr> + <td class="row1">{L_CAT_DESCRIPTION}</td> + <td class="row2"><textarea rows="5" cols="45" wrap="virtual" name="desc" class="post"></textarea></td> + </tr> + <tr> + <td class="row1">{L_CAT_PARENT}</td> + <td class="row2">{S_PARENT}</td> + </tr> + <tr> + <td cl... [truncated message content] |