From 1b9dcca62389ec5e62d0d8825da5873eafb59762 Mon Sep 17 00:00:00 2001
From: filip <filip@ispconfig3>
Date: Mon, 4 Oct 2010 13:01:44 +0000
Subject: [PATCH] Added manage questions functionality to FAQ for admin.

---
 interface/web/help/faq_delete.php             |  2 +-
 .../web/help/faq_manage_questions_list.php    | 20 ++++++++
 interface/web/help/form/faq.tform.php         |  2 +-
 interface/web/help/lib/lang/cz.lng            |  1 +
 .../lib/lang/cz_faq_manage_questions_list.lng | 10 ++++
 interface/web/help/lib/lang/en.lng            |  2 +-
 .../lib/lang/en_faq_manage_questions_list.lng | 10 ++++
 interface/web/help/lib/module.conf.php        | 23 +++++----
 interface/web/help/list/faq_list.php          |  2 +-
 .../help/list/faq_manage_questions_list.php   | 47 +++++++++++++++++++
 .../templates/faq_manage_questions_list.htm   | 43 +++++++++++++++++
 11 files changed, 148 insertions(+), 14 deletions(-)
 create mode 100644 interface/web/help/faq_manage_questions_list.php
 create mode 100644 interface/web/help/lib/lang/cz_faq_manage_questions_list.lng
 create mode 100644 interface/web/help/lib/lang/en_faq_manage_questions_list.lng
 create mode 100644 interface/web/help/list/faq_manage_questions_list.php
 create mode 100644 interface/web/help/templates/faq_manage_questions_list.htm

diff --git a/interface/web/help/faq_delete.php b/interface/web/help/faq_delete.php
index 4f6ad6128..2e501d493 100644
--- a/interface/web/help/faq_delete.php
+++ b/interface/web/help/faq_delete.php
@@ -1,7 +1,7 @@
 <?php
 
 // From and List definition files
-$list_def_file = 'list/faq_list.php';
+$list_def_file = 'list/faq_manage_questions_list.php';
 $tform_def_file = 'form/faq.tform.php';
 
 // Include the base libraries
diff --git a/interface/web/help/faq_manage_questions_list.php b/interface/web/help/faq_manage_questions_list.php
new file mode 100644
index 000000000..ad34619ab
--- /dev/null
+++ b/interface/web/help/faq_manage_questions_list.php
@@ -0,0 +1,20 @@
+<?php
+require_once('../../lib/config.inc.php');
+require_once('../../lib/app.inc.php');
+
+//* Path to the list definition file
+$list_def_file = "list/faq_manage_questions_list.php";
+
+//* Check permissions for module
+$app->auth->check_module_permissions('help');
+
+//* Loading the class
+$app->uses('listform_actions');
+
+//* Optional limit
+#$app->listform_actions->SQLExtWhere = "recipient_id = ".$_SESSION['s']['user']['userid'];
+
+//* Start the form rendering and action ahndling
+$app->listform_actions->onLoad();
+
+?>
diff --git a/interface/web/help/form/faq.tform.php b/interface/web/help/form/faq.tform.php
index 9b1b338d9..276b9d814 100644
--- a/interface/web/help/form/faq.tform.php
+++ b/interface/web/help/form/faq.tform.php
@@ -27,7 +27,7 @@ $form['db_history']		= 'no';
 $form['tab_default']	= 'message';
 
 // The name of the default list file of this form
-$form['list_default']	= 'faq_list.php';
+$form['list_default']	= 'faq_manage_questions_list.php';
 
 // Use the internal authentication system for this table. This should
 // be set to 'yes' in most cases, otherwise 'no'.
diff --git a/interface/web/help/lib/lang/cz.lng b/interface/web/help/lib/lang/cz.lng
index cce16cbc9..18f8f210b 100644
--- a/interface/web/help/lib/lang/cz.lng
+++ b/interface/web/help/lib/lang/cz.lng
@@ -9,5 +9,6 @@ $wb['Version'] = 'Verze';
 $wb['Frequently Asked Questions'] = 'Často kladené dotazy';
 $wb['FAQ Sections'] = 'Sekce FAQ';
 $wb['Manage Sections'] = 'Spravovat sekce';
+$wb['Manage Questions'] = 'Spravovat dotazy';
 $wb['Add a Question & Answer Pair'] = 'Přidat otázku a odpověď';
 ?>
diff --git a/interface/web/help/lib/lang/cz_faq_manage_questions_list.lng b/interface/web/help/lib/lang/cz_faq_manage_questions_list.lng
new file mode 100644
index 000000000..ba625696a
--- /dev/null
+++ b/interface/web/help/lib/lang/cz_faq_manage_questions_list.lng
@@ -0,0 +1,10 @@
+<?php
+$wb['faq_question_txt'] = "Otázka";
+$wb['faq_section_name_txt'] = "Název sekce";
+$wb['faq_delete_txt'] = "Smazat";
+$wb['faq_edit_txt'] = "Upravit";
+$wb['faq_sections_txt'] = "Sekce";
+$wb['faq_faq_questions_txt'] = "Často kladené dotazy";
+$wb['faq_new_question_txt'] = "Přidat nový dotaz";
+?>
+
diff --git a/interface/web/help/lib/lang/en.lng b/interface/web/help/lib/lang/en.lng
index 4e8184f0c..f90fb13e9 100644
--- a/interface/web/help/lib/lang/en.lng
+++ b/interface/web/help/lib/lang/en.lng
@@ -10,6 +10,6 @@ $wb['Frequently Asked Questions'] = 'Frequently Asked Questions';
 $wb['FAQ Sections'] = 'FAQ Sections';
 $wb['Manage Sections'] = 'Manage Sections';
 $wb['Add a Question & Answer Pair'] = 'Add a Question & Answer Pair';
-
+$wb['Manage Questions'] = 'Manage Questions';
 
 ?>
diff --git a/interface/web/help/lib/lang/en_faq_manage_questions_list.lng b/interface/web/help/lib/lang/en_faq_manage_questions_list.lng
new file mode 100644
index 000000000..ada708c7d
--- /dev/null
+++ b/interface/web/help/lib/lang/en_faq_manage_questions_list.lng
@@ -0,0 +1,10 @@
+<?php
+$wb['faq_question_txt'] = "Question";
+$wb['faq_section_name_txt'] = "Section";
+$wb['faq_delete_txt'] = "Delete";
+$wb['faq_edit_txt'] = "Edit";
+$wb['faq_sections_txt'] = "Section";
+$wb['faq_faq_questions_txt'] = "Frequently Asked Questions";
+$wb['faq_new_question_txt'] = "Add a new question & answer pair";
+?>
+
diff --git a/interface/web/help/lib/module.conf.php b/interface/web/help/lib/module.conf.php
index ff8da153c..1d590c78f 100644
--- a/interface/web/help/lib/module.conf.php
+++ b/interface/web/help/lib/module.conf.php
@@ -46,21 +46,24 @@ $module['nav'][] = array( 'title' => 'Support',
 $itemsfaq = array();
 //* admin's tools
 if($_SESSION['s']['user']['typ'] == 'admin') {
-	$itemsfaq[] = array( 	'title'		=> 'Add a Question & Answer Pair',
+	$itemsfaq[] = array( 	'title'		=> 'Manage Questions',
 							'target'	=> 'content',
-							'link'		=> 'help/faq_edit.php');
+							'link'		=> 'help/faq_manage_questions_list.php');
 	$itemsfaq[] = array( 	'title'		=> 'Manage Sections',
 							'target'	=> 'content',
 							'link'		=> 'help/faq_sections_list.php');
 }
-$sql = "SELECT * FROM help_faq_sections";
-$res = $app->db->queryAllRecords($sql);
-//* all the content sections
-if(is_array($res)) {
-	foreach($res as $v) {
-		$itemsfaq[] = array( 	'title'		=> $v['hfs_name'],
-								'target'	=> 'content',
-								'link'		=> 'help/faq_list.php?hfs_id='.$v['hfs_id']);
+else
+{ //* the user
+	$sql = "SELECT * FROM help_faq_sections";
+	$res = $app->db->queryAllRecords($sql);
+	//* all the content sections
+	if(is_array($res)) {
+		foreach($res as $v) {
+			$itemsfaq[] = array( 	'title'		=> $v['hfs_name'],
+									'target'	=> 'content',
+									'link'		=> 'help/faq_list.php?hfs_id='.$v['hfs_id']);
+		}
 	}
 }
 
diff --git a/interface/web/help/list/faq_list.php b/interface/web/help/list/faq_list.php
index b5dc346a4..0893e90ce 100644
--- a/interface/web/help/list/faq_list.php
+++ b/interface/web/help/list/faq_list.php
@@ -16,7 +16,7 @@ $liste['table_idx'] = 'hf_id';
 $liste['records_per_page']= 100;
 
 // Script File of the list
-$liste['file'] = 'faq_list.php';
+$liste['file'] = 'faq_manage_questions_list.php';
 
 // Script file of the edit form
 $liste['edit_file'] = 'faq_edit.php';
diff --git a/interface/web/help/list/faq_manage_questions_list.php b/interface/web/help/list/faq_manage_questions_list.php
new file mode 100644
index 000000000..6bff574ef
--- /dev/null
+++ b/interface/web/help/list/faq_manage_questions_list.php
@@ -0,0 +1,47 @@
+<?php
+
+// Name of the list
+$liste['name'] = 'faq_manage_questions';
+
+// Database table
+$liste['table'] = 'help_faq';
+
+// Index index field of the database table
+$liste['table_idx'] = 'hf_id';
+
+// Search Field Prefix
+#$liste['search_prefix'] = 'search_';
+
+// Records per page
+$liste['records_per_page']= 30;
+
+// Script File of the list
+$liste['file'] = 'faq_manage_questions_list.php';
+
+// Script file of the edit form
+$liste['edit_file'] = 'faq_edit.php';
+
+// Script File of the delete script
+$liste['delete_file'] = 'faq_delete.php';
+
+// Paging Template
+$liste['paging_tpl'] = 'templates/paging.tpl.htm';
+
+// Enable auth
+$liste['auth'] = 'yes';
+
+
+$liste["item"][] = array(   'field'     => "hf_section",
+                            'datatype'  => "VARCHAR",
+                            'formtype'  => "SELECT",
+                            'op'        => "=",
+                            'prefix'    => "",
+                            'suffix'    => "",
+                            'datasource'    => array (  'type'  => 'SQL',
+														'querystring' => 'SELECT a.hf_section, b.hfs_name FROM help_faq a, help_faq_sections b WHERE (a.hf_section = b.hfs_id)',
+                                                        'keyfield'=> 'hf_section',
+                                                        'valuefield'=> 'hfs_name'
+                                                      ),
+                            'width'     => "",
+                            'value'     => "");
+?>
diff --git a/interface/web/help/templates/faq_manage_questions_list.htm b/interface/web/help/templates/faq_manage_questions_list.htm
new file mode 100644
index 000000000..57bae476a
--- /dev/null
+++ b/interface/web/help/templates/faq_manage_questions_list.htm
@@ -0,0 +1,43 @@
+<h2>{tmpl_var name="faq_faq_questions_txt"}</h2>
+  <div class="pnl_toolsarea">
+    <fieldset><legend>{tmpl_var name="toolsarea_head_txt"}</legend>
+      <div class="buttons">
+<button class="iconstxt icoAdd" type="button" onclick="loadContent('help/faq_edit.php');">
+          <span>{tmpl_var name="faq_new_question_txt"}</span>
+        </button>
+      </div>
+    </fieldset>
+  </div>
+
+<div class="pnl_listarea">
+<fieldset><legend><tmpl_var name="faq_sections_txt"></legend>
+<table class="list">
+	<thead>
+          <tr>
+            <th class="tbl_col_active" scope="col">{tmpl_var name="faq_question_txt"}</th>
+            <th class="tbl_col_active" scope="col">{tmpl_var name="faq_section_name_txt"}</th>
+            <th class="tbl_col_server_id" scope="col">{tmpl_var name="faq_delete_txt"}</th>
+            <th class="tbl_col_domain" scope="col">{tmpl_var name="faq_edit_txt"}</th>
+          </tr>
+	</thead>
+
+
+<tmpl_loop name="records">
+<tr>
+	<td>{tmpl_var name='hf_question'}</td>
+	<td>{tmpl_var name='hf_section'}</td>
+	<td>
+		<div class="buttons icons16">
+			<a class="icons16 icoDelete" href="javascript: del_record('help/faq_delete.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}','{tmpl_var name='delete_confirmation'}');">
+			<span>{tmpl_var name="faq_delete_txt"}</span></a> </div>
+	</td>
+	<td>
+ 		<a href="#" onClick="loadContent('help/faq_edit.php?id={tmpl_var name='id'}');">{tmpl_var name="faq_edit_txt"}</a>
+	</td>
+</tr>
+</tmpl_loop>
+
+
+</table>
+</fieldset>
+</div>
-- 
GitLab