2006-12-02 04:36:16 +00:00
< ? php
/*
2009-12-09 18:33:43 +00:00
* e107 website system
*
* Copyright ( c ) 2008 - 2009 e107 Inc ( e107 . org )
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Featurebox administration
*
2012-12-15 16:01:31 +01:00
* $URL $
* $Id $
2009-11-24 14:48:34 +00:00
*/
2006-12-02 04:36:16 +00:00
require_once ( " ../../class2.php " );
2008-12-11 21:13:48 +00:00
if ( ! getperms ( " P " ) || ! plugInstalled ( 'featurebox' ))
{
2006-12-02 04:36:16 +00:00
header ( " location: " . e_BASE . " index.php " );
exit ;
}
2013-02-22 20:47:39 -08:00
// e107::includeLan(e_PLUGIN.'featurebox/languages/'.e_LANGUAGE.'_admin_featurebox.php');
// e107::lan('plugin','featurebox',true);
2006-12-02 04:36:16 +00:00
2009-11-24 14:48:34 +00:00
class fb_admin extends e_admin_dispatcher
2008-12-10 22:41:39 +00:00
{
2009-11-24 14:48:34 +00:00
protected $modes = array (
'main' => array (
'controller' => 'fb_main_ui' ,
'path' => null ,
'ui' => 'fb_admin_form_ui' ,
'uipath' => null
),
2009-11-26 17:15:46 +00:00
'category' => array (
'controller' => 'fb_category_ui' ,
2009-11-24 14:48:34 +00:00
'path' => null ,
'ui' => 'fb_cat_form_ui' ,
'uipath' => null
)
);
protected $adminMenu = array (
2013-02-23 04:05:08 -08:00
'main/list' => array ( 'caption' => 'Featurebox List' , 'perm' => 'P' ),
'main/create' => array ( 'caption' => LAN_CREATE , 'perm' => 'P' ),
'category/list' => array ( 'caption' => LAN_CATEGORIES , 'perm' => 'P' ),
2009-11-26 17:15:46 +00:00
'category/create' => array ( 'caption' => " Create Category " , 'perm' => 'P' ),
2009-11-24 14:48:34 +00:00
// 'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => '0'),
// 'main/custom' => array('caption'=> 'Custom Page', 'perm' => '0')
);
protected $adminMenuAliases = array (
2009-11-26 17:15:46 +00:00
'main/edit' => 'main/list' ,
'category/edit' => 'category/list'
2009-11-24 14:48:34 +00:00
);
protected $menuTitle = 'featurebox' ;
2006-12-02 04:36:16 +00:00
}
2009-11-24 14:48:34 +00:00
2009-11-26 17:15:46 +00:00
class fb_category_ui extends e_admin_ui
2009-11-24 14:48:34 +00:00
{
2009-11-26 17:15:46 +00:00
protected $pluginTitle = 'Feature Box' ;
protected $pluginName = 'featurebox' ;
protected $table = " featurebox_category " ;
protected $pid = " fb_category_id " ;
protected $perPage = 0 ; //no limit
2011-08-19 23:44:41 +00:00
2009-11-26 17:15:46 +00:00
protected $fields = array (
2009-12-09 18:33:43 +00:00
'checkboxes' => array ( 'title' => '' , 'type' => null , 'width' => '5%' , 'forced' => TRUE , 'thclass' => 'center' , 'class' => 'center first' ),
'fb_category_id' => array ( 'title' => LAN_ID , 'type' => 'number' , 'data' => 'int' , 'width' => '5%' , 'forced' => TRUE ),
'fb_category_icon' => array ( 'title' => LAN_ICON , 'type' => 'icon' , 'data' => 'str' , 'width' => '5%' , 'thclass' => 'center' , 'class' => 'center' ),
2013-03-08 02:19:18 -08:00
'fb_category_title' => array ( 'title' => LAN_TITLE , 'type' => 'text' , 'data' => 'str' , 'inline' => true , 'width' => 'auto' , 'help' => 'up to 200 characters' , 'thclass' => 'left' ),
'fb_category_template' => array ( 'title' => 'Category template' , 'type' => 'layouts' , 'inline' => true , 'data' => 'str' , 'width' => 'auto' , 'thclass' => 'left' , 'writeParms' => 'plugin=featurebox&id=featurebox_category&merge=1' , 'filter' => true ),
2009-12-09 18:33:43 +00:00
'fb_category_random' => array ( 'title' => 'Random' , 'type' => 'boolean' , 'data' => 'int' , 'width' => '5%' , 'thclass' => 'center' , 'class' => 'center' , 'batch' => true , 'filter' => true ),
2013-02-23 04:05:08 -08:00
'fb_category_class' => array ( 'title' => LAN_VISIBILITY , 'type' => 'userclass' , 'data' => 'int' , 'inline' => true , 'width' => 'auto' , 'filter' => true , 'batch' => true ),
2009-12-09 18:33:43 +00:00
'fb_category_limit' => array ( 'title' => 'Limit' , 'type' => 'number' , 'data' => 'int' , 'width' => '5%' , 'thclass' => 'left' , 'help' => 'number of items to be shown, 0 - show all' ),
2012-06-05 09:14:22 +00:00
'fb_category_parms' => array ( 'title' => 'Parameters (optional)' , 'type' => 'textarea' , 'data' => 'str' , 'width' => 'auto' , 'thclass' => 'left' , 'class' => 'left' , 'writeParms' => 'expand=Advanced&help=Optional Javascript Parameters (format subject to change)' ),
2009-12-09 18:33:43 +00:00
'options' => array ( 'title' => LAN_OPTIONS , 'type' => null , 'width' => '10%' , 'forced' => TRUE , 'thclass' => 'center last' , 'class' => 'center' )
2013-03-13 09:47:48 +02:00
);
public function init ()
{
### Prevent modification of the 'unassigned' system category
if ( $this -> getAction () == 'edit' )
{
$this -> getModel () -> load (( int ) $this -> getId ());
// FIXME lan
if ( $this -> getModel () -> get ( 'fb_category_template' ) === 'unassigned' )
{
e107 :: getMessage () -> addError ( " <strong> " . FBLAN_INSTALL_03 . " </strong> is system category and can't be modified. " , 'default' , true );
$this -> redirect ( 'list' );
}
}
elseif ( $this -> getAction () == 'inline' )
{
$this -> getModel () -> load (( int ) $this -> getId ());
if ( $this -> getModel () -> get ( 'fb_category_template' ) === 'unassigned' )
{
$protocol = ( isset ( $_SERVER [ 'SERVER_PROTOCOL' ]) ? $_SERVER [ 'SERVER_PROTOCOL' ] : 'HTTP/1.0' );
header ( $protocol . ': 403 Forbidden' , true , 403 );
echo " ' " . FBLAN_INSTALL_03 . " ' is system category and can't be modified. " ;
exit ;
}
}
}
2009-11-26 17:15:46 +00:00
2009-11-28 15:34:46 +00:00
/**
* Prevent deletion of categories in use
*/
public function beforeDelete ( $data , $id )
2009-11-26 17:15:46 +00:00
{
2013-03-13 09:47:48 +02:00
// FIXME lan
if ( $data [ 'fb_category_template' ] === 'unassigned' )
{
$this -> getTreeModel () -> addMessageError ( " <strong> " . FBLAN_INSTALL_03 . " </strong> is system category and can't be deleted. " );
return false ;
}
2009-11-28 15:34:46 +00:00
if ( e107 :: getDb () -> db_Count ( 'featurebox' , '(*)' , 'fb_category=' . intval ( $id )))
2009-11-26 17:15:46 +00:00
{
2009-11-28 15:34:46 +00:00
$this -> getTreeModel () -> addMessageWarning ( " Can't delete <strong> { $data [ 'fb_category_title' ] } </strong> - category is in use! " );
return false ;
2009-11-26 17:15:46 +00:00
}
2009-11-28 15:34:46 +00:00
return true ;
}
/**
* Some default values
* TODO - 'default' fields attribute ( default value on init )
*/
public function beforeCreate ( $new_data )
{
if ( ! is_numeric ( $new_data [ 'fb_category_limit' ]))
2009-11-26 17:15:46 +00:00
{
2009-11-28 15:34:46 +00:00
$new_data [ 'fb_category_limit' ] = 1 ;
2009-11-26 17:15:46 +00:00
}
2009-12-12 16:40:41 +00:00
if ( ! varset ( $new_data [ 'fb_category_template' ]))
{
$new_data [ 'fb_category_template' ] = 'default' ;
2013-03-13 09:47:48 +02:00
} var_dump ( $new_data );
2009-12-12 16:40:41 +00:00
return $new_data ;
}
public function beforeUpdate ( $new_data )
{
if ( ! varset ( $new_data [ 'fb_category_template' ]))
{
$new_data [ 'fb_category_template' ] = 'default' ;
}
2009-11-28 15:34:46 +00:00
return $new_data ;
2009-11-26 17:15:46 +00:00
}
/**
2009-11-28 15:34:46 +00:00
* Create error callback
2009-11-26 17:15:46 +00:00
*/
2009-11-28 15:34:46 +00:00
public function onCreateError ( $new_data , $old_data )
2009-11-26 17:15:46 +00:00
{
2009-11-28 15:34:46 +00:00
return $this -> _handleUnique ( $new_data , 'create' );
}
/**
* Create error callback
*/
public function onUpdateError ( $new_data , $old_data , $id )
{
return $this -> _handleUnique ( $new_data , 'update' );
}
/**
* Provide user friendly message on mysql duplicate entry error #1062
* No need of beforeCreate callback and additional SQL query - mysql error number give us
* enough info
* @ return boolean true - suppress model errors
*/
protected function _handleUnique ( $new_data , $mod )
{
if ( $this -> getModel () -> getSqlErrorNumber () == 1062 )
2009-11-26 17:15:46 +00:00
{
2009-12-13 10:28:15 +00:00
$templates = e107 :: getLayouts ( 'featurebox' , 'featurebox_category' , 'front' , '' , true , false );
2009-11-28 15:34:46 +00:00
$msg = e107 :: getMessage ();
2009-12-09 18:33:43 +00:00
$msg -> error ( 'Layout <strong>' . vartrue ( $templates [ $new_data [ 'fb_category_template' ]], 'n/a' ) . '</strong> is in use by another category. Layout should be unique per category. ' );
2009-11-28 15:34:46 +00:00
$msg -> error ( $mod == 'create' ? LAN_CREATED_FAILED : LAN_UPDATED_FAILED );
return ( ! E107_DEBUG_LEVEL ); // suppress messages (TRUE) only when not in debug mod
2009-11-26 17:15:46 +00:00
}
2009-11-28 15:34:46 +00:00
return false ;
2009-11-26 17:15:46 +00:00
}
2006-12-02 04:36:16 +00:00
}
2009-11-24 14:48:34 +00:00
/* class fb_cat_form_ui extends e_admin_form_ui
2006-12-02 04:36:16 +00:00
{
2009-11-24 14:48:34 +00:00
} */
class fb_main_ui extends e_admin_ui
{
2009-11-26 17:15:46 +00:00
//TODO Move to Class above.
protected $pluginTitle = 'Feature Box' ;
protected $pluginName = 'featurebox' ;
protected $table = " featurebox " ;
protected $pid = " fb_id " ;
protected $perPage = 10 ;
protected $batchDelete = true ;
2013-03-13 09:47:48 +02:00
protected $batchCopy = true ;
protected $sortField = 'fb_order' ;
protected $orderStep = 1 ;
protected $listOrder = 'fb_order asc' ;
2009-11-26 17:15:46 +00:00
protected $fields = array (
2009-11-28 15:34:46 +00:00
'checkboxes' => array ( 'title' => '' , 'type' => null , 'width' => '5%' , 'forced' => TRUE , 'thclass' => 'center first' , 'class' => 'center' ),
'fb_id' => array ( 'title' => LAN_ID , 'type' => 'number' , 'data' => 'int' , 'width' => '5%' , 'forced' => TRUE ),
2013-03-19 19:06:35 -07:00
'fb_category' => array ( 'title' => LAN_CATEGORY , 'type' => 'dropdown' , 'inline' => true , 'data' => 'int' , 'width' => '10%' , 'filter' => TRUE , 'batch' => TRUE ),
2013-02-23 04:05:08 -08:00
'fb_title' => array ( 'title' => LAN_TITLE , 'type' => 'text' , 'inline' => true , 'width' => 'auto' , 'thclass' => 'left' ),
2013-03-19 19:06:35 -07:00
'fb_image' => array ( 'title' => " Image " , 'type' => 'image' , 'width' => '100px' , 'readParms' => 'thumb=60&thumb_urlraw=0&thumb_aw=60' ),
2013-03-16 21:21:09 -07:00
'fb_text' => array ( 'title' => FBLAN_08 , 'type' => 'bbarea' , 'width' => '30%' , 'readParms' => 'expand=...&truncate=50&bb=1' , 'writeParms' => 'template=admin' ),
2009-11-28 15:34:46 +00:00
//DEPRECATED 'fb_mode' => array('title'=> FBLAN_12, 'type' => 'dropdown', 'data'=> 'int', 'width' => '5%', 'filter'=>TRUE, 'batch'=>TRUE),
//DEPRECATED 'fb_rendertype' => array('title'=> FBLAN_22, 'type' => 'dropdown', 'data'=> 'int', 'width' => 'auto', 'noedit' => TRUE),
2012-12-15 16:01:31 +01:00
'fb_template' => array ( 'title' => LAN_TEMPLATE , 'type' => 'layouts' , 'data' => 'str' , 'width' => 'auto' , 'writeParms' => 'plugin=featurebox' , 'filter' => true , 'batch' => true ), // Photo
2013-03-16 21:21:09 -07:00
'fb_imageurl' => array ( 'title' => " Image Link " , 'type' => 'url' , 'width' => 'auto' , 'writeParms' => 'size=xxlarge' ),
2013-02-23 04:05:08 -08:00
'fb_class' => array ( 'title' => LAN_VISIBILITY , 'type' => 'userclass' , 'data' => 'int' , 'inline' => true , 'width' => 'auto' , 'filter' => true , 'batch' => true ), // User id
2009-12-10 22:46:46 +00:00
'fb_order' => array ( 'title' => LAN_ORDER , 'type' => 'number' , 'data' => 'int' , 'width' => '5%' ),
2013-03-13 09:47:48 +02:00
'options' => array ( 'title' => LAN_OPTIONS , 'type' => null , 'forced' => TRUE , 'width' => '10%' , 'thclass' => 'center last' , 'class' => 'center' , 'readParms' => 'sort=1' )
2009-11-26 17:15:46 +00:00
);
2009-12-09 18:33:43 +00:00
protected $fieldpref = array ( 'checkboxes' , 'fb_id' , 'fb_category' , 'fb_title' , 'fb_template' , 'fb_class' , 'fb_order' , 'options' );
2009-11-26 17:15:46 +00:00
2009-12-09 18:33:43 +00:00
protected $prefs = array ();
2009-11-24 14:48:34 +00:00
function init ()
2008-12-10 22:41:39 +00:00
{
2009-11-24 14:48:34 +00:00
$categories = array ();
2009-11-26 17:15:46 +00:00
if ( e107 :: getDb () -> db_Select ( 'featurebox_category' ))
2008-12-10 22:41:39 +00:00
{
2009-12-09 18:33:43 +00:00
//$categories[0] = LAN_SELECT;
2009-11-24 14:48:34 +00:00
while ( $row = e107 :: getDb () -> db_Fetch ())
{
2009-11-26 17:15:46 +00:00
$id = $row [ 'fb_category_id' ];
$categories [ $id ] = $row [ 'fb_category_title' ];
2009-11-24 14:48:34 +00:00
}
2008-12-10 22:41:39 +00:00
}
2009-11-28 15:34:46 +00:00
2009-11-24 14:48:34 +00:00
$this -> fields [ 'fb_category' ][ 'writeParms' ] = $categories ;
2009-11-28 15:34:46 +00:00
// DEPRECATED
//$this->fields['fb_rendertype']['writeParms'] = array(FBLAN_23,FBLAN_24);
//$this->fields['fb_mode']['writeParms'] = array(FBLAN_13,FBLAN_14);
2009-11-24 14:48:34 +00:00
$this -> fields [ 'fb_category' ][ 'readParms' ] = $categories ;
2009-11-28 15:34:46 +00:00
// DEPRECATED
//$this->fields['fb_rendertype']['readParms'] = array(FBLAN_23,FBLAN_24);
//$this->fields['fb_mode']['readParms'] = array(FBLAN_13,FBLAN_14);
2006-12-02 04:36:16 +00:00
}
2009-11-24 14:48:34 +00:00
2006-12-02 04:36:16 +00:00
}
2009-11-24 14:48:34 +00:00
class fb_admin_form_ui extends e_admin_form_ui
2006-12-02 04:36:16 +00:00
{
2009-11-24 14:48:34 +00:00
2006-12-02 04:36:16 +00:00
}
2009-11-24 14:48:34 +00:00
new fb_admin ();
2006-12-02 04:36:16 +00:00
2009-11-24 14:48:34 +00:00
require_once ( e_ADMIN . " auth.php " );
e107 :: getAdminUI () -> runPage ();
2006-12-02 04:36:16 +00:00
require_once ( e_ADMIN . " footer.php " );
2009-11-24 14:48:34 +00:00
exit ;
2006-12-02 04:36:16 +00:00
?>