view.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:25k
- <?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: view.php,v $
- // | $Date: 2004/02/10 01:34:26 $
- // | $Revision: 1.51 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - FAQ article viewer.
- // +-------------------------------------------------------------+
- error_reporting(E_ALL ^ E_NOTICE);
- include "./../global.php";
- // default do
- $_REQUEST['do'] = trim($_REQUEST['do']);
- if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
- $_REQUEST['do'] = "view";
- }
- // globalise variables
- $global = array (
- array('articleid')
- );
- rg($global);
- include ("./faq_include.php");
- if ($_REQUEST['do'] == 'delcomment' AND $_REQUEST['comment']) {
- if ($user['p_delete_c_k']) {
- $db->query("DELETE FROM faq_comments WHERE id = '$_REQUEST[comment]'");
- alert("Comment deleted.");
- } else {
- alert("You don't have permission to delete comments.");
- }
- $_REQUEST['do'] = 'view';
- }
- if (!$_REQUEST['articleid'] AND !$_REQUEST['do'] == 'add' AND !$_REQUEST['do'] == 'add2') {
- mistake('An article ID was not specified.');
- exit;
- }
- /******************************************************************************
- // ADD ARTICLE
- ******************************************************************************/
- if ($_REQUEST['do'] == "add2") { // validation (will lose data but can only get here by bypassing javascript)
- max_limits('faq');
- if (($_REQUEST['title'] == '') OR ($_REQUEST['question'] == '') OR ($_REQUEST['answer'] == '') OR ($_REQUEST['category'] == '')) {
- jump('view.php?do=add', 'You left either the title, question, category or answer empty');
- exit();
- } elseif (!$user['p_add_k']) {
- nopermission('add articles');
- } else { // insert into article
- $ref = make_ticket_ref('faq_articles');
- $checks = xss_check(array(
- $_REQUEST['title'],
- $_REQUEST['answer'],
- $_REQUEST['question'],
- $_REQUEST['question_html'],
- $_REQUEST['answer_html']), 'user');
- $db->query("INSERT INTO faq_articles SET
- title = '" . mysql_escape_string($checks[0]) . "',
- category = '" . mysql_escape_string($_REQUEST['category']) . "',
- answer = '" . mysql_escape_string($checks[1]) . "',
- question = '" . mysql_escape_string($checks[2]) . "',
- question_html = '" . mysql_escape_string($checks[3]) . "',
- answer_html = '" . mysql_escape_string($checks[4]) . "',
- keywords = '" . mysql_escape_string($_REQUEST['hidListVals']) . "',
- show_order = '" . mysql_escape_string($_REQUEST['order']) . "',
- date_made = '" . mktime() . "',
- ref = '" . mysql_escape_string($ref) . "',
- techid_made = $user[id]
- ");
- $id = $db->last_id();
- // update category dates
- $result = $db->query_return("SELECT parentlist FROM faq_cats WHERE id = '$_REQUEST[category]'");
- $parentlist = iff($result['parentlist'], $result['parentlist'] . ",$_REQUEST[category]", $_REQUEST['category']);
-
- $db->query("UPDATE faq_cats SET
- newdate = " . mktime() . ",
- totalarticles = (totalarticles + 1)
- WHERE id IN ($parentlist)
- ");
-
- $db->query("UPDATE faq_cats SET
- articles = (articles + 1)
- WHERE id = '$_REQUEST[category]'
- ");
- // sort out keywords
- $_REQUEST['hidListVals'] = explode(',', $_REQUEST['hidListVals']);
- // add article to this keyword if keyword exists
- if (is_array($_REQUEST['hidListVals'])) {
-
- $keyword_data = $db->query_return_array("SELECT word FROM faq_keywords WHERE word IN " . array2sql($_REQUEST['hidListVals']) . "");
-
- if ($db->num_rows()) {
- foreach ($keyword_data AS $result) {
- $update_words[] = $result['word'];
- $db->query("UPDATE faq_keywords SET articles = CONCAT(articles, ',$id') WHERE word = '$result[word]'");
- }
- }
- }
- if (is_array($_REQUEST['hidListVals'])) {
- foreach ($_REQUEST['hidListVals'] AS $key => $var) {
- if (!(@in_array($var, $update_words))) {
- $keywords[$var] = $id;
- }
- }
- // new keywords
- if (is_array($keywords)) {
- $db->query("INSERT INTO faq_keywords (word, articles) VALUES " . insertsql($keywords));
- }
- }
- // sort out attachment
- if (validate_attachment($error)) {
- $attach = add_attachment();
- $db->query("INSERT INTO faq_attachments SET
- blobid = '$attach[blobid]',
- filename = '" . mysql_escape_string($attach['name']) . "',
- filesize = '" . mysql_escape_string($attach['size']) . "',
- extension = '" . mysql_escape_string($attach['extension']) . "',
- timestamp = '" . mktime() . "',
- techid = '$user[id]',
- articleid = '$id'
- ");
- }
- $tmp = split(';', $_REQUEST['selectBoxBString']);
-
- if (is_array($tmp)) {
- foreach ($tmp AS $key => $var) {
- if ($var) {
- $array[] = array($var, $id);
- }
- }
- }
- if (is_array($array)) {
- $temp = insertsql($array);
- $db->query(" INSERT INTO faq_articles_related
- (related_article, show_article)
- VALUES " . insertsql($array) . "
- ");
- }
- $subs = $db->query_return_array("SELECT * FROM faq_subscriptions WHERE catid = '$_REQUEST[category]' AND new");
- if (is_array($subs)) {
- // Do notifications
- foreach ($subs AS $key => $val) {
- $user_details = $db->query_return("SELECT * FROM user WHERE id = '$val[userid]'");
- if ($db->num_rows()) {
- $category = $db->query_return_array("SELECT * FROM faq_cats WHERE id = '$_REQUEST[category]'");
- $article = $db->query_return("SELECT * FROM faq_articles WHERE id = '$id'");
- $user_details = update_user_details($user_details);
- eval(makeemaileval('message', 'BODY_category_updated', $subject));
- dp_mail($user_details['email'], $subject, $message);
- }
- }
- }
- jump("view.php?do=view&articleid=$id", 'FAQ entry added');
- }
- }
- /******************************************************************************
- // EDIT ARTICLE
- ******************************************************************************/
- // validation (will loose data but can only get here by bypassing javascript)
- if ($_REQUEST['do'] == "update") {
- if (($_REQUEST['title'] == '') OR ($_REQUEST['question'] == '') OR ($_REQUEST['answer'] == '') OR ($_REQUEST['category'] == '')) {
- jump("view.php?do=view&articleid=$articleid", 'You left either the title, question or answer empty');
-
- }
- if (!$user['p_edit_k']) {
- nopermission('edit articles');
- }
- $article = $db->query_return("
- SELECT faq_articles.*, faq_cats.parentlist AS parentlist
- FROM faq_articles
- LEFT JOIN faq_cats ON (faq_cats.id = faq_articles.category)
- WHERE faq_articles.id = '$_REQUEST[articleid]'
- ");
- if ($db->num_rows() < 1) {
- jump("index.php", 'The article you are trying to update does not exist');
- }
- //////////////// KEYWORDS ////////////////
- if ((trim($_REQUEST['hidListVals']) != '') OR (trim($article['keywords']) != '')) {
- $keywords_new = explode(',', $_REQUEST['hidListVals']);
- $keywords_old = explode(',', $article['keywords']);
- $keywords_all = array_unique(array_merge($keywords_new, $keywords_old));
- if (is_array($keywords_all)) {
-
- // get current data we are changing
- $db->query("SELECT * FROM faq_keywords WHERE word IN " . array2sql($keywords_all) . "");
- while ($result = $db->row_array()) {
-
- // get array of articles for this word
- $keyword_articles = split(',', $result['articles']);
- // remove this article (we do this as standard because we just add it back in again anyway)
- $var = array_search($_REQUEST['articleid'], $keyword_articles);
- if ($var!==null && $var!==false) {
- unset($keyword_articles[$var]);
- }
- $new_data[$result['word']] = $keyword_articles;
- }
- }
- // now we add the $keywords_new entries
- foreach ($keywords_new AS $key => $var) {
- $new_data[$var][] = $_REQUEST['articleid'];
- }
- foreach ($new_data AS $key1 => $var1) {
- // now rebuild back into standard format
- foreach ($var1 AS $key2 => $var2) {
- $thearticles .= $var2 . ',';
- }
- $thearticles = substr($thearticles, 0, -1);
- $keyword_data[$key1] = $thearticles;
- unset($thearticles);
- }
- }
-
- if (is_array($keyword_data)) {
- $db->query("REPLACE INTO faq_keywords (word,articles) VALUES " . insertsql($keyword_data) . "");
- }
- // if we have removed the article, and there is now no articles for that word we need to delete the word
- $db->query("DELETE FROM faq_keywords WHERE articles = ''");
- //////////////// ARTICLE FIELDS ////////////////
- $checks = xss_check(array(
- $_REQUEST['title'],
- $_REQUEST['answer'],
- $_REQUEST['question'],
- $_REQUEST['question_html'],
- $_REQUEST['answer_html']), 'tech');
- $db->query("
- UPDATE faq_articles SET
- title = '" . mysql_escape_string($checks[0]) . "',
- category = '" . mysql_escape_string($_REQUEST['category']) . "',
- answer = '" . mysql_escape_string($checks[1]) . "',
- question_html = '" . mysql_escape_string($checks[3]) . "',
- answer_html = '" . mysql_escape_string($checks[4]) . "',
- question = '" . mysql_escape_string($checks[2]) . "',
- keywords = '" . mysql_escape_string($_REQUEST['hidListVals']) . "',
- show_order = '" . mysql_escape_string($_REQUEST['order']) . "',
- date_modified = '" . mktime() . "',
- techid_modified = '$user[id]'
- WHERE id = '$_REQUEST[articleid]'
- ");
- //////////////// CATEGORY TOTALS ////////////////
- if ($article['category'] != $_REQUEST['category']) { // reduce old parents by 1
- if ($article['parentlist']) {
- $db->query("UPDATE faq_cats SET
- totalarticles = (totalarticles - 1)
- WHERE id IN ($article[parentlist])
- ");
- }
- // increase new parents by 1
- $result = $db->query_return("SELECT parentlist FROM faq_cats WHERE id = '$_REQUEST[category]'");
- if ($result['parentlist']) {
- $db->query("UPDATE faq_cats SET
- newdate = " . mktime() . ",
- totalarticles = (totalarticles + 1)
- WHERE id IN ($result[parentlist])
- ");
- }
- // update new category
- $db->query("UPDATE faq_cats SET
- totalarticles = (totalarticles + 1),
- articles = (articles + 1)
- WHERE id = $_REQUEST[category]
- ");
- // update old category
- $db->query("UPDATE faq_cats SET
- totalarticles = (totalarticles - 1),
- articles = (articles - 1)
- WHERE id = $article[category]
- ");
- }
- //////////////// RELATED ARTICLES ////////////////
- $db->query("DELETE FROM faq_articles_related WHERE show_article = '$_REQUEST[articleid]'");
- $tmp = split(';', $_REQUEST['selectBoxBString']);
-
- if (is_array($tmp)) {
- foreach ($tmp AS $key => $var) {
- if ($var) {
- $array[] = array($var, $_REQUEST['articleid']);
- }
- }
- }
- if (is_array($array)) {
-
- $temp = insertsql($array);
- $db->query(" INSERT INTO faq_articles_related
- (related_article, show_article)
- VALUES " . insertsql($array) . "
- ");
- }
- //////////////// CATEGORY DATES ////////////////
- // update category dates
- $result = $db->query_return("SELECT parentlist FROM faq_cats WHERE id = '$_REQUEST[category]'");
- $parentlist = iff($result['parentlist'], $result['parentlist'] . ",$_REQUEST[category]", $_REQUEST['category']);
- $db->query("UPDATE faq_cats SET editdate = '" . mktime() . "' WHERE id IN ($parentlist)");
- // sort out attachment
- if (validate_attachment($error)) {
-
- // add attachment
- $attach = add_attachment();
- // add information to ticket table
- $db->query("INSERT INTO faq_attachments SET
- blobid = '$attach[blobid]',
- filename = '" . mysql_escape_string($attach['name']) . "',
- filesize = '" . mysql_escape_string($attach['size']) . "',
- extension = '" . mysql_escape_string($attach['extension']) . "',
- timestamp = '" . mktime() . "',
- techid = '$user[id]',
- articleid = '$articleid'
- ");
- }
- $subs = $db->query_return_array("SELECT * FROM faq_subscriptions WHERE (catid = '$_REQUEST[category]' AND new) OR (articleid = $_REQUEST[articleid] AND edit)");
- if ($db->num_rows()) {
- // Do notifications
- foreach ($subs AS $key => $val) {
- $user_details = $db->query_return("SELECT * FROM user WHERE id = '$val[userid]'");
- if ($db->num_rows()) {
- $category = $db->query_return_array("SELECT * FROM faq_cats WHERE id = '$_REQUEST[category]'");
- $article = $db->query_return_array("SELECT * FROM faq_articles WHERE id = '$articleid'");
- $user_details = update_user_details($user_details);
- eval(makeemaileval('message', 'BODY_article_changed', $subject));
- dp_mail($user_details['email'], $subject, $message);
- }
- }
- }
- alert('Article Updated');
- $_REQUEST['do'] = 'view';
- }
- /******************************************************************************
- // VIEW ARTICLE
- ******************************************************************************/
- if ($_REQUEST['do'] == "view" OR $_REQUEST['do'] == "add") {
- if ($_REQUEST['do'] == 'add') {
- max_limits('faq');
- $db->query("SELECT id FROM faq_cats LIMIT 0,1");
- if (!$db->num_rows()) {
- mistake('You must create a category before creating an article');
- }
- }
-
- // get article data
- if ($_REQUEST['do'] == "view") {
- if (!$articleid) {
- mistake("No article was specified to view.");
- }
- $article = $db->query_return("SELECT * FROM faq_articles WHERE id = '$articleid'");
- if (!$db->num_rows()) {
- mistake("The article could not be found.");
- }
- }
- if ($_REQUEST['do'] == 'add') {
- $article['title'] = $_REQUEST['title'];
- $article['question'] = $_REQUEST['question'];
- $article['answer'] = $_REQUEST['answer'];
- }
- tech_nav('faq');
- ############################### TOP NAVIGATION ###############################
- $catarray = faq_categoryjump();
- unset($catarray[0]);
- if ($_REQUEST['do'] == "view") {
- $catid = $article['category'];
- $parent = $categorycache[$catid]['parent'];
- while ($parent > 0) {
- $nav = " >> <a href="index.php?catid=" . $parent . "">" . $categorycache[$parent]['name'] . "</a>" . $nav;
- $parent = $categorycache[$parent]['parent'];
- }
- $nav = "<a href="index.php">Top</a>" . $nav;
- if ($catid != "0") {
- $nav .= " >> <a href="index.php?catid=$catid">" . $categorycache[$catid]['name'] . "</a>";
- }
- $nav = $nav . " >> " . $article['title'];
- echo "<BR><B>$nav</b><br /><br />";
- }
- ############################### ARTICLE FIELDS ###############################
-
- echo "<form id="faqform" name="faqform" enctype="multipart/form-data" method="post" action="view.php" onSubmit="postThis();selectBoxToString('selectFrom','selectBoxAString');selectBoxToString('selectInto','selectBoxBString');">";
- $table[] = array('<b>Category</b>', form_select('category', $catarray, '', iff($_REQUEST['catid'], $article['category'], $article['category'])));
- $table[] = array('<b>Title</b>', form_input('title', $article['title'], '50'));
- $table[] = array(
- "<b>Question</b><br /><br />" .
- wysiwyg('faqform', 'question', 'View in HTML editor', 'question') .'<br><br><br>' . form_checkbox_single('question_html', 1, $article['question_html']) . "<b>Treat question as HTML</b>",
- form_textarea('question', 70, 10, $article['question'])
- );
- $table[] = array(
- "<b>Answer</b><br /><br />" .
- wysiwyg('faqform', 'answer', 'View in HTML editor', 'answer') .'<br><br><br>' . form_checkbox_single('answer_html', 1, $article['answer_html']) . "<b>Treat answer as HTML</b>",
- form_textarea('answer', 70, 10, $article['answer'])
- );
- $keywords = "
- <table border="0" cellspacing="0" cellpadding="0">
- <tr><td>
- <select name="cmbAdd" size="10" multiple="multiple" style="width:200px" onDblClick="return removeFromList()"></select>
- </td><td> <input name="Button" type="button" onClick="return removeFromList()" value=" Remove "></td></tr><tr><td>
- <br /><input type="text" name="txtAdd" tabindex="0" /><input type=hidden name="hidListVals" value="$article[keywords]"><input name="Add" type="button" tabindex="1" onClick="return addToList()" value=" Add "/>
- </td></tr><tr><td>
- </td></tr></table>";
- $table[] = array('<b>Key Words</b><br /><br />Add multiple keywords at once by<br />seperating with commas', $keywords);
- if ($_REQUEST['do'] == 'view') {
- echo form_hidden('do', 'update');
- echo form_hidden('articleid', $articleid);
- $title = 'Update the FAQ article';
- } else {
- echo form_hidden('do', 'add2');
- $title = 'Create new FAQ article';
- }
- echo form_hidden('answer_html', '');
- echo form_hidden('question_html', '');
- echo form_hidden('selectBoxAString', '');
- echo form_hidden('selectBoxBString', '');
- table_header($title);
- table_content('', $table);
- table_footer();
- echo get_javascript('keywords.js');
- unset($table);
- ############################### RELATED ARTICLES ###############################
- function print_main($arg) {
- global $cats, $y, $cat_ref;
- if (!$y) {
- $y = '0';
- }
- $cat_ref[$cats[0][$arg][id]] = "$y";
- $data = "categoryArray[$y] = new Array('" . $cats[0][$arg]['name'] . "',-1,0,0);n";
- $y++;
- return $data;
- }
-
- function print_subs($arg) {
- global $cats, $y, $cat_ref;
- foreach ($arg as $key => $val) {
- $cat_ref[$arg[$key]['id']] = $y;
- $data .= "categoryArray[$y] = new Array('" . addslashes_js($arg[$key]['name']) . "'," . $cat_ref[$arg[$key]['parent']] . ",0,0);n";
- $y++;
- if (is_array($cats[$arg[$key]['id']])) {
- $data .= print_subs($cats[$arg[$key]['id']], $delim);
- }
- }
- return $data;
- }
- // get related articles
- $db->query("SELECT * FROM faq_articles_related WHERE show_article = '$articleid'");
- while ($result = $db->row_array()) {
- $related[] = $result['related_article'];
- }
- // get cats
- $db->query("SELECT * from faq_cats ORDER by parent, show_order");
- while ($result = $db->row_array()) {
- $cats[$result['parent']][] = array(
- "name" => $result['name'],
- "id" => $result['id'],
- "parent" => $result['parent']
- );
- }
-
- for ($i=0; $i<count($cats[0]); $i++) {
- $data .= print_main($i);
- if (is_array($cats[$cats[0][$i]['id']])) {
- $data .= print_subs($cats[$cats[0][$i]['id']]);
- }
- }
- // get articles
- $y = 0;
- $z = 1;
- $db->query("SELECT id, category, title FROM faq_articles ORDER by category, show_order");
- while ($result = $db->row_array()) {
- $data .= "articleArray[$y] = new Array('" . addslashes_js($result['title']) . "','$result[id];$y;'," . $cat_ref[$result['category']] . ",'" .
- iff(@in_array($result[id], $related), 'selectInto', 'selectFrom') . "');n";
- $y++;
- }
- $columns = array('Title', 'Delete Relation');
- table_header('Related Articles');
- table_html(0, 1);
- echo get_javascript('swapbox.js');
- ?>
-
- <input type="hidden" name="whitespace" value=" ">
- <script language="javascript">
-
- var categoryArray = new Array();
- var articleArray = new Array();
- <?php echo $data; ?>
- </script>
- <table border="0" cellpadding="2" cellspacing="0" align="center">
- <tr>
-
- <td>
- <select name="selectFrom" size="10" style="width: 70mm" onChange="document.forms['faqform'].elements['displayTrail'].value = getArticleTrail(this.selectedIndex,this.name); document.forms['faqform'].elements['selectInto'].selectedIndex = -1; if(this.options[this.selectedIndex].value != '')document.forms['faqform'].elements['to'].disabled = false;else document.forms['faqform'].elements['to'].disabled = true; document.forms['faqform'].elements['back'].disabled = true;"></select>
- </td>
-
- <td width="30" align="center">
- <input type="button" value=">>" name="to" onClick="shiftArticle('selectFrom','selectInto');this.disabled = true;" >
- </td>
- <td width="30" align="center">
- <input type="button" value="<<" name="back" onClick="shiftArticle('selectInto','selectFrom');this.disabled = true;">
- </td>
- <td>
- <select name="selectInto" size="10" style="width: 70mm" onChange="document.forms['faqform'].elements['displayTrail'].value = getArticleTrail(this.selectedIndex,this.name); document.forms['faqform'].elements['selectFrom'].selectedIndex = -1; if(this.options[this.selectedIndex].value != '')document.forms['faqform'].elements['back'].disabled = false; else document.forms['faqform'].elements['back'].disabled = true; document.forms['faqform'].elements['to'].disabled = true;">
- </select>
- </td>
- </tr>
- <tr>
- <td colspan="4" align="center"><input type="text" name="displayTrail" value="" size="90"></td>
- </tr>
- </table>
- <SCRIPT LANGUAGE="JavaScript">
- fillSelectBox(-1,'');
- document.forms['faqform'].elements['back'].disabled = true;
- document.forms['faqform'].elements['to'].disabled = true;
- retrieveVals();
- </SCRIPT>
- <?php
- table_html(0, 2);
- table_footer();
- ############################### ATTACHMENTS ###############################
- echo "<table width="100%" cellpadding="3"><tr><td valign="top">";
- table_header('Add Attachment');
- table_content('', array("<input type="file" name="attachment">"));
- table_footer();
- unset($table);
- echo "</td>";
-
- if ($_REQUEST['do'] == 'view') {
- echo "<td valign="top">";
- $db->query("SELECT filesize, id, filename, blobid, extension FROM faq_attachments WHERE articleid = '$articleid'");
-
- while ($attachment = $db->row_array()) {
- $attachment['filesize'] = number_format($attachment['filesize'] / 1024, 2);
- $table[] = array(
- $attachment['filename'],
- $attachment['filesize'] . " kb",
- "<a href="attachment.php?do=download&id=$attachment[id]&articleid=$articleid">download</a>",
- jprompt('Are you sure you want to delete this attachment?', "attachment.php?do=delete&id=$attachment[id]&articleid=$articleid", 'Delete Attachment'));
- }
- table_header('Current Attachments');
- table_content(array('Filename', 'Size', 'Download', 'Delete'), $table);
- table_footer();
- unset($table);
- echo "</td></tr></table>";
- } else {
- echo "</td></tr></table>";
- }
- ############################### COMMENTS ###############################
- if ($_REQUEST['do'] == "view") {
- $db->query("
- SELECT faq_comments.id as id, userid, useremail, comments, articleid, user.username, user.email
- FROM faq_comments
- LEFT JOIN user ON (faq_comments.userid = user.id)
- WHERE articleid = '$articleid'
- ");
- while ($comment = $db->row_array()) {
- if ($comment[userid]) {
- $show_name = "<a href="./../users/view.php?id=$comment[userid]">$comment[username]</a>";
- } else {
- $show_name = $comment[useremail];
- }
- $table[] = array(
- $comment['comments'],
- $show_name,
- iff($user['p_delete_c_k'],
- jprompt('Are you sure you want to delete this comment?', "view.php?do=delcomment&articleid=$articleid&comment=$comment[id]", 'Delete Comment'),
- "<FONT COLOR="GRAY">Delete Comment</FONT>"
- ),
- "<a href="./../tickets/newticket.php?commentid=$comment[id]">Create Ticket</a>"
- );
- }
- $columns = array('Comments', 'Submitter', 'Delete', 'Create Ticket');
- table_header('Comments from users about this article', '', '', '', 'AddForm');
- table_content($columns, $table, $extra, '', $top);
- table_footer();
- unset($table, $columns);
- $db->query("
- SELECT faq_rating.*
- FROM faq_rating
- WHERE faqid = '$articleid'
- ");
- while ($result = $db->row_array()) {
- $ratings[$result[rating]]++;
- $ratings_count++;
- $ratings_total = $ratings_total + $result[rating];
- }
- if ($ratings_total) {
- $ratings_avg = $ratings_total / $ratings_count;
- }
- give_default($ratings[0], '0');
- give_default($ratings[20], '0');
- give_default($ratings[40], '0');
- give_default($ratings[60], '0');
- give_default($ratings[80], '0');
- give_default($ratings[100], '0');
- $columns = array('0%', '20%', '40%', '60%', '80%', '100%');
- $table[] = array("$ratings[0]", "$ratings[20]", "$ratings[40]", "$ratings[60]", "$ratings[80]", "$ratings[100]");
- if ($ratings_total) {
- $table[] = array("The average rating is <b>" . round($ratings_avg) . "</b>%");
- }
- table_header('Faq Article Ratings');
- table_content($columns, $table);
- table_footer();
- }
- ############################### FINISH FORM ###############################
-
- echo "
- <script language="javascript">
- var error = '';
-
- function validateit() {
- if (document.faqform.title.value == '') {
- error += 'You have not entered a title\n';
- }
- if (document.faqform.answer.value == '') {
- error += 'You have not entered an answer\n';
- }
- if (document.faqform.question.value == '') {
- error += 'You have not entered a question\n';
- }
- if (error) {
- alert(error);
- error = '';
- return false;
- }
- }
- </script>
- ";
- if ($_REQUEST['do'] == 'view') {
- echo "<input type="submit" name="Update Article" value="Update Article" onclick="return validateit()">";
- } else {
- echo "<input type="submit" name="Create New Article" value="Create New Article" onclick="return validateit()">";
- }
- }
- tech_footer();
- ?>