2009-11-09 12:57:34 +00:00
< ? php
/*
+ ----------------------------------------------------------------------------+
| e107 website system
|
2009-11-18 01:06:08 +00:00
| Copyright ( C ) 2008 - 2009 e107 Inc ( e107 . org )
2009-11-09 12:57:34 +00:00
| http :// e107 . org
2009-11-18 01:06:08 +00:00
|
2009-11-09 12:57:34 +00:00
|
| Released under the terms and conditions of the
| GNU General Public License ( http :// gnu . org ) .
|
| $Source : / cvs_backup / e107_0 . 8 / e107_plugins / faqs / admin_config . php , v $
2009-11-18 01:06:08 +00:00
| $Revision : 1.8 $
| $Date : 2009 - 11 - 18 01 : 05 : 36 $
| $Author : e107coders $
2009-11-09 12:57:34 +00:00
+----------------------------------------------------------------------------+
*/
require_once ( " ../../class2.php " );
if ( ! getperms ( " P " ))
{
header ( " location: " . e_BASE . " index.php " );
exit ;
}
class faq_admin extends e_admin_dispatcher
{
protected $modes = array (
'main' => array (
'controller' => 'faq_main_ui' ,
'path' => null ,
'ui' => 'faq_admin_form_ui' ,
'uipath' => null
),
'cat' => array (
'controller' => 'faq_cat_ui' ,
'path' => null ,
2009-11-12 16:55:50 +00:00
'ui' => 'faq_cat_form_ui' ,
2009-11-09 12:57:34 +00:00
'uipath' => null
)
);
protected $adminMenu = array (
'main/list' => array ( 'caption' => 'FAQs' , 'perm' => '0' ),
'main/create' => array ( 'caption' => 'Create FAQ' , 'perm' => '0' ),
'cat/list' => array ( 'caption' => 'Categories' , 'perm' => '0' ),
2009-11-12 16:55:50 +00:00
'cat/create' => array ( 'caption' => " Create Category " , 'perm' => '0' ),
2009-11-09 12:57:34 +00:00
'main/prefs' => array ( 'caption' => LAN_PREFS , 'perm' => '0' ),
// 'main/custom' => array('caption'=> 'Custom Page', 'perm' => '0')
);
protected $adminMenuAliases = array (
'main/edit' => 'main/list'
);
protected $menuTitle = 'FAQs' ;
}
class faq_cat_ui extends e_admin_ui
{
protected $pluginTitle = 'FAQs' ;
protected $pluginName = 'plugin' ;
protected $table = " faqs_info " ;
protected $pid = " faq_info_id " ;
2009-11-12 16:55:50 +00:00
protected $perPage = 0 ; //no limit
2009-11-09 12:57:34 +00:00
// protected $listQry = "SELECT * FROM #faq_info"; // without any Order or Limit.
// protected $editQry = "SELECT * FROM #faq_info WHERE faq_info_id = {ID}";
protected $fields = array (
2009-11-12 16:55:50 +00:00
'checkboxes' => array ( 'title' => '' , 'type' => null , 'width' => '5%' , 'forced' => TRUE , 'thclass' => 'center' , 'class' => 'center' ),
2009-11-09 12:57:34 +00:00
'faq_info_icon' => array ( 'title' => LAN_ICON , 'type' => 'icon' , 'width' => '5%' , 'thclass' => 'left' ),
2009-11-12 16:55:50 +00:00
'faq_info_id' => array ( 'title' => LAN_ID , 'type' => 'number' , 'width' => '5%' , 'forced' => TRUE ),
2009-11-09 12:57:34 +00:00
'faq_info_title' => array ( 'title' => LAN_TITLE , 'type' => 'text' , 'width' => 'auto' , 'thclass' => 'left' ),
2009-11-12 16:55:50 +00:00
'faq_info_about' => array ( 'title' => LAN_DESCRIPTION , 'type' => 'bbarea' , 'width' => '30%' , 'readParms' => 'expand=...&truncate=50&bb=1' ), // Display name
2009-11-09 12:57:34 +00:00
'faq_info_parent' => array ( 'title' => LAN_CATEGORY , 'type' => 'text' , 'width' => '5%' ),
2009-11-17 08:16:46 +00:00
'faq_info_class' => array ( 'title' => LAN_VISIBILITY , 'type' => 'userclass' , 'width' => 'auto' , 'data' => 'int' ),
2009-11-09 12:57:34 +00:00
'faq_info_order' => array ( 'title' => LAN_ORDER , 'type' => 'text' , 'width' => '5%' , 'thclass' => 'left' ),
2009-11-12 16:55:50 +00:00
'options' => array ( 'title' => LAN_OPTIONS , 'type' => null , 'width' => '10%' , 'forced' => TRUE , 'thclass' => 'center last' , 'class' => 'center' )
2009-11-09 12:57:34 +00:00
);
2009-11-12 16:55:50 +00:00
/**
* Get FAQ Category data
2009-11-17 14:16:47 +00:00
*
2009-11-12 16:55:50 +00:00
* @ param integer $id [ optional ] get category title , false - return whole array
2009-11-17 14:16:47 +00:00
* @ param mixed $default [ optional ] default value if not found ( default 'n/a' )
2009-11-12 16:55:50 +00:00
* @ return
*/
function getFaqCategoryTree ( $id = false , $default = 'n/a' )
{
// TODO get faq category tree
}
2009-11-09 12:57:34 +00:00
}
2009-11-12 16:55:50 +00:00
class faq_cat_form_ui extends e_admin_form_ui
{
public function faq_info_parent ( $curVal , $mode )
{
// TODO - catlist combo without current cat ID in write mode, parents only for batch/filter
// Get UI instance
$controller = $this -> getController ();
switch ( $mode )
{
case 'read' :
return e107 :: getParser () -> toHTML ( $controller -> getFaqCategoryTree ( $curVal ), false , 'TITLE' );
break ;
case 'write' :
return $this -> selectbox ( 'faq_info_parent' , $controller -> getFaqCategoryTree (), $curVal );
break ;
case 'filter' :
case 'batch' :
return $controller -> getFaqCategoryTree ();
break ;
}
}
}
2009-11-09 12:57:34 +00:00
class faq_main_ui extends e_admin_ui
{
//TODO Move to Class above.
protected $pluginTitle = 'FAQs' ;
protected $pluginName = 'faqs' ;
protected $table = " faqs " ;
2009-11-10 19:13:07 +00:00
protected $tableJoin = array (
'u.user' => array ( 'leftField' => 'faq_author' , 'rightField' => 'user_id' , 'fields' => 'user_id,user_loginname,user_name' )
);
2009-11-11 20:57:34 +00:00
// without any Order or Limit.
//protected $listQry = "SELECT * FROM #faqs";
2009-11-09 12:57:34 +00:00
protected $editQry = " SELECT * FROM #faqs WHERE faq_id = { ID} " ;
protected $pid = " faq_id " ;
protected $perPage = 10 ;
protected $batchDelete = true ;
//TODO - finish 'user' type, set 'data' to all editable fields, set 'noedit' for all non-editable fields
protected $fields = array (
'checkboxes' => array ( 'title' => '' , 'type' => null , 'width' => '5%' , 'forced' => TRUE , 'thclass' => 'center' , 'class' => 'center' ),
'faq_id' => array ( 'title' => LAN_ID , 'type' => 'int' , 'width' => '5%' , 'forced' => TRUE ),
2009-11-10 19:13:07 +00:00
'faq_question' => array ( 'title' => " Question " , 'type' => 'text' , 'width' => 'auto' , 'thclass' => 'left first' ), // Display name
'faq_answer' => array ( 'title' => " Answer " , 'type' => 'bbarea' , 'width' => '30%' , 'readParms' => 'expand=...&truncate=50&bb=1' ), // Display name
2009-11-09 16:54:30 +00:00
'faq_parent' => array ( 'title' => " Category " , 'type' => 'method' , 'data' => 'int' , 'width' => '5%' , 'filter' => TRUE , 'batch' => TRUE ),
2009-11-09 12:57:34 +00:00
'faq_comment' => array ( 'title' => " Comment " , 'type' => 'userclass' , 'data' => 'int' , 'width' => 'auto' ), // User id
2009-11-17 08:16:46 +00:00
'faq_datestamp' => array ( 'title' => " datestamp " , 'type' => 'datestamp' , 'data' => 'int' , 'width' => 'auto' , 'noedit' => TRUE ), // User date
2009-11-11 20:57:34 +00:00
'faq_author' => array ( 'title' => LAN_USER , 'type' => 'user' , 'data' => 'int' , 'width' => 'auto' , 'thclass' => 'center' , 'class' => 'center' , 'writeParms' => 'currentInit=1' , 'filter' => true , 'batch' => true , 'nolist' => true ), // Photo
2009-11-10 19:13:07 +00:00
'u.user_name' => array ( 'title' => " User name " , 'type' => 'user' , 'width' => 'auto' , 'noedit' => true , 'readParms' => 'idField=faq_author&link=1' ), // User name
'u.user_loginname' => array ( 'title' => " User login " , 'type' => 'user' , 'width' => 'auto' , 'noedit' => true , 'readParms' => 'idField=faq_author&link=1' ), // User login name
'faq_order' => array ( 'title' => " Order " , 'type' => 'number' , 'data' => 'int' , 'width' => '5%' , 'thclass' => 'center' ), // Real name (no real vetting)
2009-11-09 12:57:34 +00:00
'options' => array ( 'title' => LAN_OPTIONS , 'type' => null , 'forced' => TRUE , 'width' => '10%' , 'thclass' => 'center last' , 'class' => 'center' )
);
// protected $fieldpref = array('checkboxes', 'comment_id', 'comment_item_id', 'comment_author_id', 'comment_author_name', 'comment_subject', 'comment_comment', 'comment_type', 'options');
// optional, if $pluginName == 'core', core prefs will be used, else e107::getPluginConfig($pluginName);
protected $prefs = array (
'add_faq' => array ( 'title' => 'Allow submitting of FAQs by:' , 'type' => 'userclass' ),
'submit_question' => array ( 'title' => 'Allow submitting of Questions by:' , 'type' => 'userclass' ),
'classic_look' => array ( 'title' => 'Use Classic Layout' , 'type' => 'boolean' )
);
2009-11-10 19:13:07 +00:00
/**
* FAQ categories
* @ var array
*/
protected $categories = null ;
2009-11-09 12:57:34 +00:00
2009-11-10 19:13:07 +00:00
/**
* Get FAQ Category data
2009-11-17 14:16:47 +00:00
*
2009-11-10 19:13:07 +00:00
* @ param integer $id [ optional ] get category title , false - return whole array
2009-11-17 14:16:47 +00:00
* @ param mixed $default [ optional ] default value if not found ( default 'n/a' )
* @ return array
2009-11-10 19:13:07 +00:00
*/
function getFaqCategory ( $id = false , $default = 'n/a' )
2009-11-09 12:57:34 +00:00
{
2009-11-10 19:13:07 +00:00
if ( null === $this -> categories ) //auto-retrieve on first call
2009-11-09 12:57:34 +00:00
{
2009-11-10 19:13:07 +00:00
$sql = e107 :: getDb ();
if ( $sql -> db_Select ( 'faqs_info' ))
{
while ( $row = $sql -> db_Fetch ())
{
$this -> categories [ $row [ 'faq_info_id' ]] = $row [ 'faq_info_title' ];
}
}
else
{
$this -> categories = array (); //prevent PHP warnings
}
2009-11-09 12:57:34 +00:00
}
2009-11-10 19:13:07 +00:00
if ( false === $id )
2009-11-09 12:57:34 +00:00
{
2009-11-10 19:13:07 +00:00
return $this -> categories ;
2009-11-09 12:57:34 +00:00
}
2009-11-10 19:13:07 +00:00
return vartrue ( $this -> categories [ $id ], $default );
}
2009-11-09 12:57:34 +00:00
2009-11-10 19:13:07 +00:00
}
2009-11-09 12:57:34 +00:00
2009-11-10 19:13:07 +00:00
class faq_admin_form_ui extends e_admin_form_ui
{
/**
* faq_parent field method
*
* @ param integer $curVal
* @ param string $mode
* @ return mixed
*/
function faq_parent ( $curVal , $mode )
{
// Get UI instance
$controller = $this -> getController ();
switch ( $mode )
{
case 'read' :
return e107 :: getParser () -> toHTML ( $controller -> getFaqCategory ( $curVal ), false , 'TITLE' );
break ;
case 'write' :
return $this -> selectbox ( 'faq_parent' , $controller -> getFaqCategory (), $curVal );
break ;
case 'filter' :
case 'batch' :
return $controller -> getFaqCategory ();
break ;
2009-11-09 12:57:34 +00:00
}
}
}
new faq_admin ();
require_once ( e_ADMIN . " auth.php " );
e107 :: getAdminUI () -> runPage ();
require_once ( e_ADMIN . " footer.php " );
exit ;
?>