faq_include.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:8k
- <?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_include.php,v $
- // | $Date: 2004/02/10 01:34:26 $
- // | $Revision: 1.15 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - Utility functions for FAQ.
- // +-------------------------------------------------------------+
- error_reporting(E_ALL ^ E_NOTICE);
- ###################### function categorycache() #######################
- function categorycache() {
- global $db;
- $db->query("SELECT * FROM faq_cats ORDER BY parent,show_order,id");
- while ($cats = $db->row_array()) {
-
- $categorycache[$cats['id']] = array(
- 'parent' => $cats['parent'],
- 'order' => $cats['show_order'],
- 'name' => $cats['name'],
- 'parentlist' =>$cats['parentlist'],
- 'parentarray' => split(',', $cats['parentlist']),
- 'totalarticles' => $cats['totalarticles'],
- 'articles' => $cats['articles']
- );
- }
- return $categorycache;
- }
- ###################### function catparentcache() ######################
- function catparentcache() {
- global $db;
- $db->query("SELECT * FROM faq_cats ORDER BY parent,show_order,id");
- while ($cats = $db->row_array()) {
- $catparentcache[$cats['parent']][$cats['show_order']][$cats['id']] = $cats['name'];
- }
- return $catparentcache;
- }
- ###################### function catcaches() ######################
- function catcaches() {
- global $db;
- $db->query("SELECT * FROM faq_cats ORDER BY parent,show_order,id");
- while ($cats = $db->row_array()) {
- $categorycache[$cats['id']] = array(
- 'parent' => $cats['parent'],
- 'order' => $cats['show_order'],
- 'name' => $cats['name'],
- 'parentlist' =>$cats['parentlist'],
- 'parentarray' => split(',', $cats['parentlist']),
- 'totalarticles' => $cats['totalarticles'],
- 'articles' => $cats['articles']
- );
- $catparentcache[$cats['parent']][$cats['show_order']][$cats['id']] = $cats['name'];
- }
- return array($categorycache, $catparentcache);
- }
- ###################### function update_counters() #######################
- function update_counters() {
- global $db, $categorycache;
- // get categorycache
- $categorycache = categorycache();
- // get category totals
- $db->query("SELECT COUNT(*) AS total, category FROM faq_articles GROUP BY category");
- while ($result = $db->row_array()) {
- $totals[$result['category']] = $result['total'];
- }
- // reset all totals
- $db->query("UPDATE faq_cats SET articles = '', totalarticles = ''");
- // set totals
- if (is_array($totals)) {
- foreach ($totals AS $catid => $number) {
- if ($categorycache[$catid]['parentlist']) {
- $db->query("UPDATE faq_cats
- SET totalarticles = (totalarticles + $number)
- WHERE id IN (" . $categorycache[$catid]['parentlist'] . ")
- ");
- }
- $db->query("UPDATE faq_cats SET
- articles = '$number',
- totalarticles = (totalarticles + '$number')
- WHERE id = '$catid'
- ");
- }
- }
- }
- ###################### getparents() #######################
- function getparents($catid, $return='') {
- global $categorycache;
- $parent = $categorycache[$catid]['parent'];
- if ($parent) {
- $return .= iff($return, ',') . getparents($parent, $parent);
- }
- return $return;
- }
- ###################### update_parentlist() #######################
- function update_parentlist() {
- global $categorycache, $db;
- $categorycache = categorycache();
- if (is_array($categorycache)) {
- foreach($categorycache AS $catid => $var) {
- $db->query("UPDATE faq_cats SET parentlist = '" . getparents($catid) . "' WHERE id = '$catid'");
- }
- }
- }
- ###################### function delete_kbarticle($id) #######################
-
- function delete_kbarticle($id, $error='') {
- global $db;
-
- $db->query("DELETE FROM faq_articles WHERE id = '$id'");
- $db->query("DELETE FROM faq_articles_related WHERE related_article = '$key' OR show_article = '$id'");
- $db->query("DELETE FROM faq_comments WHERE articleid = '$id'");
- $db->query("DELETE FROM faq_rating WHERE faqid = '$id'");
- $db->query("DELETE FROM faq_subscriptions WHERE articleid = '$id'");
- }
- ###################### function delete_kbcategory($id) #######################
- function delete_kbcategory($id, $error='') {
- global $categorycache, $db;
- // check no subcats
- if (is_array($catparentcache[$id])) {
- return "<LI>You can not delete category " . $categorycache[$id]['name'] . " because it has subcategories. A category must be empty before it can be deleted</LI>";
- }
- // check no articles
- if ($categorycache[$id]['totalarticles'] > 0) {
- return "<LI>You can not delete category " . $categorycache[$id]['name'] . " because it contains articles. A category must be empty before it can be deleted</LI>";
- }
-
- $db->query("DELETE FROM faq_cats WHERE id = '$id'");
- $db->query("DELETE FROM faq_cats_related WHERE related_cat = '$id' OR show_cat = '$id'");
- $db->query("DELETE FROM faq_subscriptions WHERE catid = '$id'");
-
- return "<LI>Category " . $categorycache[$id]['name'] . " deleted";
- }
- ###################### function faq_categoryjump() #######################
- function faq_categoryjump($catid=0, $prepend=NULL) {
- global $catparentcache, $categorycache, $jumpbox;
- // for first time
- if (!$catid) { // add to top level
- $jumpbox = array('0' => 'Top Level');
- // reload caches
- $tmp = catcaches();
- $catparentcache = $tmp[1];
- $categorycache = $tmp[0];
- }
- if (is_array($catparentcache[$catid])) {
- while (list($key,$val) = each($catparentcache[$catid])) {
- while (list($categoryid, $category) = each($val)) {
- $jumpbox[$categoryid] = $prepend . $category . " (" . $categorycache[$categoryid]['articles'] ." / " . $categorycache[$categoryid]['totalarticles'] . ")n";
- if (is_array($catparentcache[$categoryid])) {
- faq_categoryjump($categoryid, $category . "::");
- }
- }
- }
- }
- return $jumpbox;
- }
- #### gen_pdf_faq() ####
- # Recursion to produce a PDF containing all FAQs in the specified
- # category and all categories beneath it.
- function gen_pdf_faq($catid, $depth = 0, $section = '', $secnum = 1) {
- global $query, $pdf, $db;
- 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) {
- $db->query("SELECT id, name FROM faq_cats WHERE id = '$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 = '$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, title 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[title]] $result[question]n");
- $pdf->SetFont('Times', '', 10);
- $pdf->MultiCell(0, 4, "$result[answer]n");
- }
- return;
- }
- ?>