⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view.php

📁 本代码是为客户联系管理而做的系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
			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>&nbsp;&nbsp;&nbsp;&nbsp;<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="&nbsp;&nbsp;&nbsp;">

		<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="&gt;&gt;" name="to" onClick="shiftArticle('selectFrom','selectInto');this.disabled = true;" >
			</td>
			<td width="30" align="center">
			<input type="button" value="&lt;&lt;" 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();
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -