faq.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:28k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: faq.php,v $
- // | $Date: 2004/02/12 21:16:57 $
- // | $Revision: 1.71 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - FAQ display and search.
- // +-------------------------------------------------------------+
- require_once('./global.php');
- //Nullify WTN-WDYL Team
- // globalise variables
- $global = array (
- array('categoryid', 'number', '0'),
- array('articleid', 'number', '0'),
- );
- rg($global);
- $template_cache = templatecache('HF_header,HF_footer,FAQ_header,FAQ_search,FAQ_home,FAQ_category,FAQ_article_print,FAQ_article,FAQ_subscriptions,FAQ_new,FAQ_search');
- ############################### PERMISSIONS ###############################
- if ($settings[faq_restrict] AND !$session[userid]) {
- error('error_q_a_restrict');
- }
- // category permissions
- $db->query("SELECT catid FROM faq_permissions WHERE groupid = '$session[usergroup]'");
- while ($result = $db->row_array()) {
- $groups[] = $result[catid];
- }
- if (!is_array($groups)) {
- $error_nocats = 1;
- } else {
- $permission = " IN " . array2sql($groups);
- }
- ############################### PDF GENERATION ###############################
- if ($_REQUEST['do'] == 'pdf') {
- if ($_REQUEST['do'] == 'pdf') {
- define('PDF', '1');
- }
- if (!$_REQUEST['categoryid']) {
- $_REQUEST['categoryid'] = 0;
- }
- define('FPDF_FONTPATH','./includes/fpdf/font/');
- require('./includes/fpdf/fpdf.php');
- $pdf = new FPDF('P', 'mm', 'Letter');
- $pdf->Open();
- $pdf->AddPage();
- $pdf->SetTitle('Knowledge Base');
- $pdf->SetCreator('DeskPro v2.0');
- $pdf->SetFont('Times', 'B', 24);
- $pdf->Cell(0, 10, 'Knowledge Base', 0, 1, 'C');
- gen_pdf_faq($_REQUEST[categoryid]);
- $pdf->Output();
- exit;
- }
- ############################### START PAGE ###############################
- $page = 'qanda';
- $navigation = add_navigation('Questions and Answers', 'faq.php');
- // get templates
- $template_cache = templatecache('FAQ_search_category,FAQ_search_articles,FAQ_search,FAQ_related,FAQ_article,FAQ_category_alternate1,FAQ_category_alternate2,FAQ_main_category,FAQ_article_alternate1,FAQ_main,FAQ_main_article,FAQ_article_alternate2,FAQ_nav_bit_category,FAQ_nav_bit_article,FAQ_nav');
- // default do
- $_REQUEST['do'] = trim($_REQUEST['do']);
- if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
- if ($categoryid) {
- $_REQUEST['do'] = "category";
- } else {
- $_REQUEST['do'] = "home";
- }
- }
- ############################### SORT CATEGORY DATA ###############################
- // create a category jump
- $db->query("SELECT * FROM faq_cats
- " . iff ($permission, "WHERE id $permission") . "
- ORDER BY parent,show_order,id
- ");
- while ($cats = $db->row_array()) {
- // generates totals (based on permissions)
- $parents = explode(',', $cats[parentlist]);
- foreach ($parents AS $key => $var) {
- $cattotals[$var] += $cats[articles];
- }
- $cattotals[$cats[id]] += $cats[articles];
-
- // used for "nav bits"
- $categorycache_parent[$cats[parent]][$cats[show_order]][$cats[id]] = $cats[name];
- // used for category data display in templates
- $categorycache_data[$cats[parent]][] = $cats;
-
- // used for categry jump and getting data for category (e.g. name/parent etc)
- $categorycache[$cats[id]] = array(
- 'id' => $cats[id],
- 'parent' => $cats[parent],
- 'order' => $cats[show_order],
- 'name' => $cats[name],
- 'parentlist' =>$cats[parentlist],
- 'parentarray' => split(',', $cats[parentlist])
- );
- }
- $catarray = faq_categoryjump();
- $category_count = count($catarray) - 1;
- $cat_jump = form_select('categoryid', $catarray, $_REQUEST['categoryid']);
- ############################### SEARCH FAQ ###############################
- if ($_REQUEST['do'] == "search") {
- $catarray[0] = $dplang[all_categories];
- $search_cats = form_select('cat', $catarray, -1, '', '', 6);
- give_default($_REQUEST['search_in'], 'all');
- give_default($_REQUEST['search_by'], 'AND');
- if ($_REQUEST['search_by'] == 'AND') {
- $AND = 1;
- $search_option = 'AND';
- } elseif ($_REQUEST['search_by'] == 'OR') {
- $OR = 1;
- $search_option = 'OR';
- } else {
- $PHRASE = 1;
- $search_option = 'PHRASE';
- }
- ///////// sort search words /////////
- if ($_REQUEST['searchwords']) {
-
- if ($OR OR $AND) {
- $tmp = split(' ', $_REQUEST['searchwords']);
- foreach ($tmp AS $key => $var) {
- if (trim($var)) {
- $searchwords[] = trim($var);
- }
- }
- } else {
- // make into an array for later processing
- if (!is_array($_REQUEST['searchwords'])) {
- $searchwords = array($_REQUEST['searchwords']);
- }
- }
- $number_searchwords = count($searchwords);
-
- ///////// make keywords /////////
- if ($_REQUEST['search_in'] == 'all' OR $_REQUEST['search_in'] == 'keywords') {
-
- if ($AND OR $OR OR ($PHRASE AND $number_searchwords == 1)) {
- if (is_array($searchwords)) {
- $db->query("SELECT * FROM faq_keywords WHERE word IN " . array2sql($searchwords) . "");
- while ($result = $db->row_array()) {
- $articles = split(',', $result[articles]);
- foreach ($articles AS $key => $var) {
- if ($var) {
- $keywords[$var][] = $result['word'];
- }
- }
- }
- }
-
- // if matching all unset those that do not match
- if ($AND) {
- if (is_array($keywords)) {
- foreach ($keywords AS $key => $var) {
- if (count($var) != $number_searchwords) {
- unset($keywords[$key]);
- }
- }
- }
- }
- }
- }
- ///////// categories /////////
- if (is_array($_REQUEST['cat'])) {
- if (in_array('0', $_REQUEST['cat'])) {
- unset($_REQUEST['cat']);
- } else {
- $where_category .= "AND category IN " . array2sql($_REQUEST['cat']);
- }
- }
-
- ///////// articles / question / answer /////////
- unset($i);
- // will always be an array
- foreach ($searchwords AS $key => $var) {
- if ($_REQUEST['search_in'] == 'all' OR $_REQUEST['search_in'] == 'titles') {
- $where_title .= iff($i, $search_option) . " title LIKE '%" . addslashes_like($var) . "%'";
- }
- if ($_REQUEST['search_in'] == 'all' OR $_REQUEST['search_in'] == 'questions') {
- $where_question .= iff($i, $search_option) . " question LIKE '%" . addslashes_like($var) . "%'";
- }
- if ($_REQUEST['search_in'] == 'all' OR $_REQUEST['search_in'] == 'answers') {
- $where_answer .= iff($i, $search_option) . " answer LIKE '%" . addslashes_like($var) . "%'";
- }
- $i++;
- }
- // the match can be on any component
- if ($where_title) {
- $where_title = "($where_title)";
- }
- if ($where_question) {
- $where_question = " OR ($where_question)";
- }
- if ($where_answer) {
- $where_answer = " OR ($where_answer)";
- }
- // add keyword article matches
- if (is_array($keywords)) {
- $where_keywords = " OR (faq_articles.id IN " . array2sql(array_keys($keywords)) . ")";
- }
- if (!$where_title) {
- $where_title = '1';
- }
- $query = "
- SELECT faq_articles.*, user.username AS username, tech.username AS username
- FROM faq_articles
- LEFT JOIN tech ON (tech.id = faq_articles.techid_made)
- LEFT JOIN user ON (user.id = faq_articles.userid)
- WHERE
- (
- $where_title
- $where_question
- $where_answer
- $where_keywords
- )
- $where_category
- ";
- $db->query($query);
- while ($result = $db->row_array()) {
- $article_cache[$result[id]] = $result;
- }
- }
- // final processing
- if (is_array($article_cache)) {
- // check permission
- foreach ($article_cache AS $key => $var) {
- if (is_array($categorycache[$var[category]])) {
- // sort votes
- if ($article_cache[$key]['votes']) {
- $article_cache[$key]['rating'] = $article_cache[$key]['rating'] . '%';
- } else {
- $article_cache[$key]['rating'] = ' - ';
- }
- // replace with category name
- $article_cache[$key]['category_name'] = $categorycache[$var[category]]['name'];
- $article[] = $article_cache[$key];
- }
- }
- }
- // show the search form
- $advancedsearch = 1;
- $navigation .= add_navigation('Search', 'faq.php');
- eval(makeeval('header', 'HF_header'));
- eval(makeeval('footer', 'HF_footer'));
- eval(makeeval('faq_header', 'FAQ_header'));
- eval(makeeval('echo', 'FAQ_search'));
- }
-
- ############################### HOME ###############################
- if ($_REQUEST['do'] == "home") {
- $time = mktime() - (60 * 60 * 24 * $settings[faq_days]);
- ///////// sub categories /////////
- if (is_array($categorycache_data[0])) {
- foreach ($categorycache_data[0] AS $key => $tempcat) {
- if ($tempcat[newdate] > $time) {
- $tempcat[is_new] = 1;
- } elseif ($tempcat[editdate] > $time) {
- $tempcat[is_modified] = 1;
- }
- $tempcat[totalarticles] = $cattotals[$tempcat[id]];
- $sub_category[] = $tempcat;
- }
-
- // column widths
- $columns = $settings[faq_columns];
- $catsno = count($sub_category);
- if ($catsno >= $columns) {
- if ($columns) {
- $percentage = 100 / $columns;
- }
- } else {
- if ($catsno) {
- $percentage = 100 / $catsno;
- }
- }
- }
- ///////// get new articles /////////
- if ($settings['faq_front_articles'] AND !$error_nocats) {
- $db->query("
- SELECT title, id, date_modified, date_made, category
- FROM faq_articles
- WHERE (date_made > '$time' OR
- date_modified > '$time')
- " . iff($permission, "AND category $permission") . "
- AND NOT to_validate
- ORDER BY date_made DESC, date_modified DESC
- LIMIT $settings[faq_front_articles]
- ");
- while ($result = $db->row_array()) {
- if ($result['date_made'] > $time) {
- $result['is_new'] = 1;
- } elseif ($result['date_modified'] > $time) {
- $result['is_modified'] = 1;
- }
- $result['category_name'] = $categorycache[$result['category']]['name'];
- if ($result['date_modified']) {
- $result['date'] = our_date($result['date_modified'], 'day');
- } else {
- $result['date'] = our_date($result['date_made'], 'day');
- }
- $changed_articles[] = $result;
- }
- }
- ///////// most popular articles /////////
- /*
- forumla for popular: (from ratings:)
- rating (0,20,40,60,80,100)
- (rating * votes / 10) + votes
- */
- if ($settings['faq_front_articles'] AND !$error_nocats) {
- $db->query("
- SELECT faq_articles.*,
- ((rating * votes / 10) + views) AS score
- FROM faq_articles
- WHERE NOT to_validate
- ORDER BY score DESC
- LIMIT $settings[faq_front_articles]
- ");
- while ($result = $db->row_array()) {
- $result[category_name] = $categorycache[$result[category]]['name'];
- if ($result['date_modified']) {
- $result['date'] = our_date($result['date_modified'], 'day');
- } else {
- $result['date'] = our_date($result['date_made'], 'day');
- }
- $toprate_articles[] = $result;
- }
- }
-
- ///////// finish up / display /////////
- $nav = breadcrumbs($categoryid);
- eval(makeeval('header', 'HF_header'));
- eval(makeeval('footer', 'HF_footer'));
- eval(makeeval('faq_header', 'FAQ_header'));
- eval(makeeval('echo', 'FAQ_home'));
- }
- ############################### CATEGORY ###############################
- if ($_REQUEST['do'] == "category") {
- $time = mktime() - (60 * 60 * 24 * $settings[faq_days]);
- // the category
- $category = $db->query_return("
- SELECT * FROM faq_cats
- WHERE id = '" . intval($categoryid) . "'
- " . iff($permission, "AND id $permission") . "
- ");
- if (!$db->num_rows()) {
- error('error_q_a_category_exist');
- }
- ///////////////////////// subcategories /////////////////////////
- if (is_array($categorycache_data[$_REQUEST[categoryid]])) {
- foreach ($categorycache_data[$_REQUEST[categoryid]] AS $key => $tempcat) {
- if ($tempcat[newdate] > $time) {
- $tempcat[is_new] = 1;
- } elseif ($tempcat[editdate] > $time) {
- $tempcat[is_modified] = 1;
- }
- $tempcat[totalarticles] = $cattotals[$tempcat[id]];
- $sub_category[] = $tempcat;
- }
-
- // widths
- $columns = $settings[faq_columns];
- $catsno = count($sub_category);
- if ($catsno >= $columns) {
- if ($columns) {
- $percentage = 100 / $columns;
- }
- } else {
- if ($catsno) {
- $percentage = 100 / $catsno;
- }
- }
- }
- ///////////////////////// articles /////////////////////////
- $db->query("
- SELECT faq_articles.id, title, rating, date_made, date_modified, faq_cats.name as category FROM faq_articles, faq_cats
- WHERE category = '" . intval($categoryid) . "' AND NOT to_validate AND faq_cats.id = faq_articles.category
- ORDER BY faq_articles.show_order
- ");
-
- $article = array();
- while ($result = $db->row_array()) {
- if ($result[date_made] > $time) {
- $result[is_new] = 1;
- } elseif ($result[date_modified] > $time) {
- $result[is_modified] = 1;
- }
- $article[] = $result;
- }
- ///////////////////////// related categories /////////////////////////
- $db->query("
- SELECT related_cat
- FROM faq_cats_related
- WHERE show_cat = '" . intval($categoryid) . "'
- ");
- while ($result = $db->row_array()) {
- $tempcat = $categorycache[$result[related_cat]];
-
- if (is_array($tempcat)) {
- if ($tempcat[newdate] > $time) {
- $tempcat[is_new] = 1;
- } elseif ($tempcat[editdate] > $time) {
- $tempcat[is_modified] = 1;
- }
- $tempcat[totalarticles] = $cattotals[$tempcat[id]];
- $related_category[] = $tempcat;
- }
- }
- // widths
- if (is_array($related_category)) {
- $columns = $settings[faq_columns];
- $catsno = count($related_category);
- if ($catsno >= $columns) {
- if ($columns) {
- $percentage = 100 / $columns;
- }
- } else {
- if ($catsno) {
- $percentage = 100 / $catsno;
- }
- }
- }
- ///////////////////////// display page /////////////////////////
- $navigation .= breadcrumbs($categoryid);
- eval(makeeval('header', 'HF_header'));
- eval(makeeval('footer', 'HF_footer'));
- eval(makeeval('faq_header', 'FAQ_header'));
- eval(makeeval('echo', 'FAQ_category'));
- }
- ############################### DOWNLOAD ARTICLE ###############################
- if ($_REQUEST['do'] == 'download') {
- $attachment = $db->query_return("
- SELECT *
- FROM faq_attachments
- WHERE id = '" . addslashes($_REQUEST['id']) . "'
- ");
- $article = $db->query_return("
- SELECT faq_articles.*
- FROM faq_articles
- WHERE faq_articles.id = '" . intval($attachment['articleid']) . "'
- " . iff($permission, "AND faq_articles.category $permission") . "
- AND NOT to_validate
- ");
- if ($db->num_rows() < 1) {
- error('error_q_a_article_exist');
- }
- get_attachment($_REQUEST['id'], 'faq_attachments');
- }
- ############################### VIEW ARTICLE / PRINTABLE ARTICLE ###############################
- if ($_REQUEST['do'] == "article" OR $_REQUEST['do'] == "printarticle") {
-
- if (!$articleid) {
- error('error_q_a_article_exist');
- }
- $article = $db->query_return("
- SELECT faq_articles.*
- FROM faq_articles
- WHERE faq_articles.id = '" . intval($articleid) . "'
- " . iff($permission, "AND faq_articles.category $permission") . "
- AND NOT to_validate
- ");
- if ($db->num_rows() < 1) {
- error('error_q_a_article_exist');
- }
- // update number of views
- $db->query("UPDATE faq_articles SET views = views+1 WHERE id = '" . intval($articleid) . "'");
-
- if ($article[date_made] > (mktime() - (60 * 60 * 24 * $settings[faq_days]))) {
- $article[is_new] = 1;
- }
- // sort article elements
- if ($article[date_modified]) {
- $article[date_modified] = our_date($article[date_modified]);
- }
- $article[title] = dp_code($article[title]);
- $article[question] = iff($article[question_html], $article[question], dp_code($article[question]));
- $article[answer] = iff($article[answer_html], $article[answer], dp_code($article[answer]));
- $article[date_made] = our_date($article[date_made]);
- // get names of tech/user who made
- if ($article[techid_made]) {
- $tmp = $db->query_return("SELECT username FROM tech WHERE id = '$article[techid_made]'");
- $article[tech_made] = $tmp['username'];
- } else {
- $tmp = $db->query_return("SELECT username FROM user WHERE id = '$article[userid]'");
- $article[tech_made] = $tmp['username'];
- }
- $tmp = $db->query_return("SELECT username FROM tech WHERE id = '$article[techid_modified]'");
- $article[tech_modified] = $tmp['username'];
- // faq attachments
- $attachments = $db->query_return_array("
- SELECT * FROM faq_attachments WHERE articleid = '" . intval($articleid) . "'
- ");
- // faq attachments
- $db->query("
- SELECT *
- FROM faq_attachments
- WHERE articleid = '" . intval($articleid) . "'
- ");
- while ($result = $db->row_array()) {
- $result['filesize'] = number_format($result['filesize'] / 1024, 2);
- $attachment[] = $result;
- }
- // related articles
- $db->query("
- SELECT faq_articles.*
- FROM faq_articles_related
- LEFT JOIN faq_articles ON (faq_articles_related.related_article = faq_articles.id)
- WHERE show_article = '" . intval($articleid) . "'
- " . iff($permission, "AND faq_articles.category $permission") . "
- AND NOT to_validate
- ");
-
- $related_article = array();
- while ($result = $db->row_array()) {
- if ($result['date_modified']) {
- $result['date'] = our_date($result['date_modified'], 'day');
- } else {
- $result['date'] = our_date($result['date_made'], 'day');
- }
- $related_article[] = $result;
- }
- $navigation .= breadcrumbs($article[category]);
- $navigation .= add_navigation($article[title], "faq.php?do=article&articleid=$article[id]");
-
- // Update the category jump widget to show the current category
- $cat_jump = form_select('categoryid', $catarray, $article['category']);
- $categoryid = $article['category'];
- if ($_REQUEST['do'] == 'printarticle') {
- eval(makeeval('echo', 'FAQ_article_print'));
- } else {
- eval(makeeval('header', 'HF_header'));
- eval(makeeval('footer', 'HF_footer'));
- eval(makeeval('faq_header', 'FAQ_header'));
- eval(makeeval('echo', 'FAQ_article'));
- }
- }
- ############################### NEW ARTICLE (2) ###############################
-
- if ($_REQUEST['do'] == "new2") {
- max_limits('faq');
- if (!$settings['faq_new']) {
- error('error_no_faq_submit');
- }
- if (!$_REQUEST[category]) {
- $error_category = 1;
- $stop = 1;
- }
- if (strlen($_REQUEST[title]) < 10) {
- $error_title = 1;
- $stop = 1;
- }
- if (strlen($_REQUEST[question]) < 10) {
- $error_question = 1;
- $stop = 1;
- }
- if (strlen($_REQUEST[answer]) < 10) {
- $error_answer = 1;
- $stop = 1;
- }
- if (!$stop) {
- $ref = make_ticket_ref('faq_articles');
- $db->query("INSERT INTO faq_articles SET
- title = '" . mysql_escape_string(htmlspecialchars_uni($_REQUEST[title])) . "',
- question = '" . mysql_escape_string(htmlspecialchars_uni($_REQUEST[question])) . "',
- answer = '" . mysql_escape_string(htmlspecialchars_uni($_REQUEST[answer])) . "',
- category = '" . mysql_escape_string(htmlspecialchars_uni($_REQUEST[category])) . "',
- to_validate = '1',
- date_made = " . mktime() . ",
- ref = '" . mysql_escape_string($ref) . "',
- userid = '$session[userid]'
- ");
- $id = $db->last_id();
- // now lets email techs
- $db->query("
- SELECT username, email
- FROM tech
- WHERE email_faq
- ");
- while ($result = $db->row_array()) {
- eval(makeemaileval('message', 'TECHBODY_faq', $subject));
- dp_mail($result[email], $subject, $message);
- }
- jump('faq.php', 'redirect_faq_new', 5);
-
- // fix any errors
- } else {
- $_REQUEST['do'] = "new";
- }
- }
- ############################### NEW ARTICLE ###############################
-
- if ($_REQUEST['do'] == "new") {
- max_limits('faq');
- if (!$settings['faq_new']) {
- error('error_no_faq_submit');
- }
- $subpage = 'newarticle';
- $catarray2 = $catarray;
- unset($catarray2[0]);
- if ($_POST['category']) {
- $thiscategory = $_POST['category'];
- } elseif ($categoryid) {
- $thiscategory = $categoryid; // from category
- }
- $category_select = form_select('category', $catarray2, $thiscategory);
-
- $navigation .= add_navigation($dplang[new_article], "faq.php?do=new");
- eval(makeeval('header', 'HF_header'));
- eval(makeeval('footer', 'HF_footer'));
- eval(makeeval('faq_header', 'FAQ_header'));
- eval(makeeval('echo', 'FAQ_new'));
- }
- ############################### ADD ARTICLE SUBSCRIPTION ###############################
-
- if ($_REQUEST['do'] == "addarticlesub") {
- check_user();
- $articleid = mysql_escape_string($articleid);
- $article = $db->query_return("SELECT category FROM faq_articles WHERE id = '" . intval($articleid) . "'");
- if (!$db->num_rows()) {
- error('error_q_a_article_exist');
- }
- $db->query("
- DELETE FROM faq_subscriptions
- WHERE articleid = '" . intval($articleid) . "'
- AND userid = '$session[userid]'
- ");
-
- $db->query("
- INSERT INTO faq_subscriptions SET
- articleid = '" . intval($articleid) . "',
- userid = '$session[userid]',
- edit = 1
- ");
-
- jump('faq.php?do=subscriptions', 'redirect_faq_subscription');
- }
- ############################### ADD CATEGORY SUBSCRIPTION ###############################
-
- if ($_REQUEST['do'] == "addcategorysub") {
- check_user();
- $category = $db->query_return("
- SELECT * FROM faq_cats
- WHERE id = '" . intval($categoryid) . "'" . iff($permission, "AND id $permission"));
- if (!$db->num_rows()) {
- error('error_q_a_category_exist');
- }
- $db->query("
- DELETE FROM faq_subscriptions WHERE
- catid = '" . intval($categoryid) . "'
- AND userid = '$session[userid]'
- ");
-
- $db->query("
- INSERT INTO faq_subscriptions SET
- catid = '" . intval($categoryid) . "',
- new = 1,
- userid = '$session[userid]'
- ");
-
- jump('faq.php?do=subscriptions', 'redirect_faq_subscription');
- }
- ############################### SUBSCRIPTIONS (2) ###############################
-
- if ($_REQUEST['do'] == "subscriptions2") {
-
- check_user();
- $subpage = 'subscription';
- // need to be logged in
- if (!$session[userid]) {
- login_form();
- }
-
- // delete current data
- $db->query("DELETE FROM faq_subscriptions WHERE userid = '$session[userid]'");
- // deal with categories
- if (is_array($_REQUEST[cat])) {
- foreach($_REQUEST[cat] AS $key => $var) {
- if ($_REQUEST[cat_edit][$key] OR $_REQUEST[cat_new][$key]) {
- $data[] = array(
- $key,
- $_REQUEST[cat_new][$key],
- $_REQUEST[cat_edit][$key],
- $session[userid]
- );
- }
- }
- }
- if (is_array($data)) {
- $db->query(" INSERT INTO faq_subscriptions
- (catid, new, edit, userid)
- VALUES " . insertsql($data) . "
- ");
- }
- unset($data);
- // deal with articles
- if (is_array($_REQUEST[article])) {
- foreach($_REQUEST[article] AS $key => $var) {
- if ($_REQUEST[article_edit][$key] OR $_REQUEST[article_comment][$key]) {
- $data[] = array(
- $key,
- $_REQUEST[article_edit][$key],
- $session[userid]
- );
- }
- }
- }
- if (is_array($data)) {
- $db->query(" INSERT INTO faq_subscriptions
- (articleid, edit , userid)
- VALUES " . insertsql($data) . "
- ");
- }
- // view subscriptions
- $_REQUEST['do'] = "subscriptions";
- }
- ############################### SUBSCRIPTIONS ###############################
-
- if ($_REQUEST['do'] == "subscriptions") {
- check_user();
- $subpage = 'subscription';
- // need to be logged in
- if (!$session[userid]) {
- login_form();
- }
- $category_select = form_select('category', $catarray, $thiscategory);
- function getcatpath($catid) {
- global $categorycache;
- $parent = $categorycache[$catid][parent];
- while ($parent > 0) {
- $nav = " >> " . $categorycache[$parent]['name'] . $nav;
- $parent = $categorycache[$parent]['parent'];
- }
- return $nav;
- }
- // category subscriptions
- $db->query("
- SELECT faq_subscriptions.*, faq_cats.name AS name, faq_articles.*
- FROM faq_subscriptions
- LEFT JOIN faq_cats ON (faq_cats.id = faq_subscriptions.catid)
- LEFT JOIN faq_articles ON (faq_articles.id = faq_subscriptions.articleid)
- WHERE faq_subscriptions.userid = '$session[userid]'
- ORDER by faq_cats.show_order
- ");
- while ($result = $db->row_array()) {
- if (!$result['articleid']) {
- $cat_subscription[] = array(
- 'id' => $result['catid'],
- 'name' => $result['name'],
- 'path' => getcatpath($result['catid']) . " >> $result[name]",
- 'new' => iff($result['new'], ' checked=checked'),
- 'edit' => iff($result['edit'], ' checked=checked')
- );
- } else {
- $article_subscription[] = array(
- 'id' => $result['articleid'],
- 'name' => $result['title'],
- 'category' => $categorycache[$result[category]][name],
- 'category_id' => $result[category],
- 'category_path' => getcatpath($result['category']),
- 'edit' => iff($result['edit'], ' checked=checked')
- );
- }
- }
- $nav = breadcrumbs($cat);
- eval(makeeval('header', 'HF_header'));
- eval(makeeval('footer', 'HF_footer'));
- eval(makeeval('faq_header', 'FAQ_header'));
- eval(makeeval('echo', 'FAQ_subscriptions'));
- }
- #################################### FAQ ONLY FUNCTIONS ###################################
- ###################### FUNCTION FAQ_CATEGORYJUMP() #######################
- function faq_categoryjump($catid=0, $prepend='--') {
- global $categorycache_parent, $jumpbox, $x;
- if (!$x) {
- $jumpbox = array('0' => 'Top Level');
- $x=1;
- }
- if (is_array($categorycache_parent[$catid])) {
- while (list($key,$val) = each($categorycache_parent[$catid])) {
- while (list($categoryid, $category) = each($val)) {
- $jumpbox[$categoryid] = $prepend . " " . $category;
- if (is_array($categorycache_parent[$categoryid])) {
- faq_categoryjump($categoryid, $prepend . "--");
- }
- }
- }
- }
- return $jumpbox;
- }
- ###################### FUNCTION BREADCRUMBS() #######################
- /* creates a bread crumb navigation for categories */
- function breadcrumbs($catid='') {
- global $categorycache, $r;
- while ($catid > 0) {
- $name = $categorycache[$catid]['name'];
- $id = $catid;
- $tmp = add_navigation($name, "faq.php?categoryid=$catid") . $tmp;
- $catid = $categorycache[$catid]['parent'];
- }
- return $tmp;
- }
- ###################### FUNCTION gen_pdf_faq() #######################
- /* recursive function for creating the PDF documentation */
- function gen_pdf_faq($catid, $depth = 0, $section = '', $secnum = 1) {
- global $query, $pdf, $db, $groups;
- switch ($depth) {
- case 0:
- $font = 20;
- break;
- case 1:
- $font = 18;
- break;
- case 2:
- $font = 16;
- break;
- case 3:
- $font = 14;
- break;
- case 4:
- $font = 12;
- break;
- case 5:
- default:
- $font = 10;
- break;
- }
- if (!$catid) {
- $catid = 0;
- } else {
- $secnum = 1;
- }
- $pdepth = $depth + 1;
- if ($section != '') {
- $section .= '.';
- }
- if ($catid > 0 AND (in_array($catid, $groups))) {
- $db->query("SELECT id, name FROM faq_cats WHERE id = '" . mysql_escape_string($catid));
- $result = $db->row_array();
- $pdf->SetFont('Times', 'B', $font);
- $pdf->MultiCell(0, 8, "$section $result[name]n");
- }
- // First, get the subtopics and process them.
- $categories = array();
- $db->query("SELECT id, name FROM faq_cats WHERE parent = '" . mysql_escape_string($catid));
- while ($result = $db->row_array()) {
- $categories[] = $result[id];
- }
- if (is_array($categories)) {
- foreach ($categories AS $key => $val) {
- if ($catid > 0) {
- gen_pdf_faq($val, $depth+1, "$section$secnum", $secnum);
- } else {
- gen_pdf_faq($val, $depth+1, "$secnum", $secnum);
- }
- $secnum++;
- }
- }
- if ($font > 10) {
- $font = $font - 2;
- }
- // Then print all this category's FAQs
- $db->query("SELECT question, answer FROM faq_articles WHERE
- NOT to_validate AND category = '$catid' ORDER BY show_order");
- $count = 0;
- while ($result = $db->row_array()) {
- $count++;
- $pdf->SetFont('Times', 'B', $font);
- $pdf->MultiCell(0, 8, "$section$count: $result[question]n");
- $pdf->SetFont('Times', '', 10);
- $pdf->MultiCell(0, 4, "$result[answer]n");
- }
- return;
- }
- ?>