2006-12-02 04:36:16 +00:00
< ? php
/*
2008-12-02 00:32:30 +00:00
* e107 website system
*
* Copyright ( C ) 2001 - 2008 e107 Inc ( e107 . org )
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Administrators Management
*
* $Source : / cvs_backup / e107_0 . 8 / e107_admin / administrator . php , v $
2009-08-05 14:22:15 +00:00
* $Revision : 1.13 $
* $Date : 2009 - 08 - 05 14 : 22 : 15 $
2009-07-23 15:21:41 +00:00
* $Author : e107coders $
2008-12-20 15:23:48 +00:00
*
2006-12-02 04:36:16 +00:00
*/
2008-12-20 15:23:48 +00:00
2006-12-02 04:36:16 +00:00
require_once ( '../class2.php' );
if ( ! getperms ( '3' ))
{
2008-12-20 15:23:48 +00:00
header ( 'Location:' . SITEURL . 'index.php' );
2006-12-02 04:36:16 +00:00
exit ;
}
2008-12-20 15:23:48 +00:00
if ( isset ( $_POST [ 'go_back' ]))
{ //return to listing - clear all posted data
header ( 'Location:' . e_ADMIN_ABS . e_PAGE );
exit ;
}
2006-12-02 04:36:16 +00:00
$e_sub_cat = 'admin' ;
require_once ( 'auth.php' );
2008-12-20 15:23:48 +00:00
require_once ( e_HANDLER . " form_handler.php " );
require_once ( e_HANDLER . " message_handler.php " );
$frm = new e_form ( true );
$emessage = & eMessage :: getInstance ();
2008-10-20 21:52:38 +00:00
$action = '' ;
$sub_action = - 1 ;
2006-12-02 04:36:16 +00:00
if ( e_QUERY )
{
$tmp = explode ( " . " , e_QUERY );
2008-10-20 21:52:38 +00:00
$action = $tmp [ 0 ]; // Used when called from elsewhere
2008-12-20 15:23:48 +00:00
$sub_action = varset ( $tmp [ 1 ], - 1 ); // User ID
2006-12-02 04:36:16 +00:00
unset ( $tmp );
}
2008-10-20 21:52:38 +00:00
2006-12-02 04:36:16 +00:00
if ( isset ( $_POST [ 'update_admin' ]))
2008-10-20 21:52:38 +00:00
{ // Permissions updated
$modID = intval ( $_POST [ 'a_id' ]);
if ( $modID == 0 )
{
exit ;
}
$sql -> db_Select ( " user " , " * " , " user_id= " . $modID );
2006-12-02 04:36:16 +00:00
$row = $sql -> db_Fetch ();
$a_name = $row [ 'user_name' ];
$perm = " " ;
foreach ( $_POST [ 'perms' ] as $value )
{
2008-10-20 21:52:38 +00:00
$value = $tp -> toDB ( $value );
if ( $value == " 0 " )
{
if ( ! getperms ( '0' )) { $value = " " ; break ; }
2009-04-27 08:11:04 +00:00
$perm = " 0 " ; break ;
2008-10-20 21:52:38 +00:00
}
2006-12-02 04:36:16 +00:00
2008-10-20 21:52:38 +00:00
if ( $value )
{
$perm .= $value . " . " ;
}
2006-12-02 04:36:16 +00:00
}
2008-12-20 15:23:48 +00:00
admin_update ( $sql -> db_Update ( " user " , " user_perms=' { $perm } ' WHERE user_id=' { $modID } ' " ), 'update' , sprintf ( ADMSLAN_2 , $tp -> toDB ( $_POST [ 'ad_name' ])), false , false );
2008-10-20 21:52:38 +00:00
$logMsg = str_replace ( array ( '--ID--' , '--NAME--' ), array ( $modID , $a_name ), ADMSLAN_72 ) . $perm ;
2008-12-20 15:23:48 +00:00
$admin_log -> log_event ( 'ADMIN_01' , $logMsg , E_LOG_INFORMATIVE , '' );
2008-10-20 21:52:38 +00:00
unset ( $modID , $ad_name , $a_perms );
2006-12-02 04:36:16 +00:00
}
2008-10-20 21:52:38 +00:00
if ( isset ( $_POST [ 'edit_admin' ]) || $action == " edit " )
2006-12-02 04:36:16 +00:00
{
$edid = array_keys ( $_POST [ 'edit_admin' ]);
2008-10-20 21:52:38 +00:00
$theid = intval (( $sub_action < 0 ) ? $edid [ 0 ] : $sub_action );
if (( ! $sql -> db_Select ( " user " , " * " , " user_id= " . $theid ))
|| ! ( $row = $sql -> db_Fetch ()))
{
2008-12-20 15:23:48 +00:00
$emessage -> add ( " Couldn't find user ID: { $theid } , { $sub_action } , { $edid [ 0 ] } " , E_MESSAGE_DEBUG ); // Debug code - shouldn't be executed
2008-10-20 21:52:38 +00:00
}
2006-12-02 04:36:16 +00:00
}
2008-10-20 21:52:38 +00:00
if ( isset ( $_POST [ 'del_admin' ]) && count ( $_POST [ 'del_admin' ]))
2006-12-02 04:36:16 +00:00
{
$delid = array_keys ( $_POST [ 'del_admin' ]);
2008-10-20 21:52:38 +00:00
$aID = intval ( $delid [ 0 ]);
$sql -> db_Select ( " user " , " * " , " user_id= " . $aID );
2006-12-02 04:36:16 +00:00
$row = $sql -> db_Fetch ();
if ( $row [ 'user_id' ] == 1 )
2008-12-20 15:23:48 +00:00
{ // Can't delete main admin
$text = $row [ 'user_name' ] . " " . ADMSLAN_6 . "
2006-12-02 04:36:16 +00:00
< br />< br />
2008-12-20 15:23:48 +00:00
< a href = '".e_ADMIN_ABS."administrator.php' > " .ADMSLAN_4. " </ a > " ;
$emessage -> add ( $text , E_MESSAGE_ERROR );
$ns -> tablerender ( LAN_ERROR , $emessage -> render ());
2006-12-02 04:36:16 +00:00
require_once ( " footer.php " );
exit ;
}
2008-12-20 15:23:48 +00:00
admin_update ( $sql -> db_Update ( " user " , " user_admin=0, user_perms='' WHERE user_id= " . $aID ), 'update' , ADMSLAN_61 , LAN_DELETED_FAILED , false );
2008-10-20 21:52:38 +00:00
$logMsg = str_replace ( array ( '--ID--' , '--NAME--' ), array ( $aID , $row [ 'user_name' ]), ADMSLAN_73 );
2008-12-20 15:23:48 +00:00
$admin_log -> log_event ( 'ADMIN_02' , $logMsg , E_LOG_INFORMATIVE , '' );
2006-12-02 04:36:16 +00:00
}
2008-10-20 21:52:38 +00:00
if ( isset ( $_POST [ 'edit_admin' ]) || $action == " edit " )
{
2006-12-02 04:36:16 +00:00
edit_administrator ( $row );
2008-10-20 21:52:38 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
show_admins ();
}
2008-10-20 21:52:38 +00:00
function show_admins ()
{
2008-12-20 15:23:48 +00:00
global $sql , $emessage , $e107 , $frm ;
2006-12-02 04:36:16 +00:00
$sql -> db_Select ( " user " , " * " , " user_admin='1' " );
2008-12-20 15:23:48 +00:00
$text = "
2006-12-02 04:36:16 +00:00
< form action = '".e_SELF."' method = 'post' id = 'del_administrator' >
2008-12-20 15:23:48 +00:00
< fieldset id = 'core-administrator-list' >
< legend class = 'e-hideme' > " .ADMSLAN_13. " </ legend >
< table cellpadding = '0' cellspacing = '0' class = 'adminlist' >
< colgroup span = '4' >
< col style = 'width: 5%' ></ col >
< col style = 'width: 20%' ></ col >
< col style = 'width: 65%' ></ col >
< col style = 'width: 10%' ></ col >
</ colgroup >
< thead >
< tr >
< th > ID </ th >
< th > " .ADMSLAN_56. " </ th >
< th > " .ADMSLAN_18. " </ th >
< th class = 'center last' > " .LAN_OPTIONS. " </ th >
</ tr >
</ thead >
< tbody >
" ;
2006-12-02 04:36:16 +00:00
while ( $row = $sql -> db_Fetch ())
{
2008-12-20 15:23:48 +00:00
//$permtxt = "";
$text .= "
< tr >
< td > " . $row['user_id'] . " </ td >
< td >< a href = '".$e107->url->getUrl(' core : user ', ' main ', "func=profile&id={$row[' user_id ']}")."' > " . $row['user_name'] . " </ a ></ td >
< td >
" .renderperms( $row['user_perms'] , $row['user_id'] , " words " ). "
</ td >
< td class = 'center' >
" ;
2006-12-02 04:36:16 +00:00
if ( $row [ 'user_id' ] != " 1 " )
{
$text .= "
2008-12-20 15:23:48 +00:00
" . $frm->submit_image ( " edit_admin [{ $row [ 'user_id' ]}] " , 'edit', 'edit', LAN_EDIT). "
" . $frm->submit_image ( " del_admin [{ $row [ 'user_id' ]}] " , 'del', 'delete', $e107->tp ->toJS(ADMSLAN_59. " ? [ " . $row['user_name'] . " ] " )). "
" ;
2006-12-02 04:36:16 +00:00
}
2008-12-20 15:23:48 +00:00
$text .= "
</ td >
</ tr >
" ;
2006-12-02 04:36:16 +00:00
}
2008-12-20 15:23:48 +00:00
$text .= "
</ tbody >
</ table >
" . $frm->hidden ('del_administrator_confirm','1'). "
</ fieldset >
</ form >
2006-12-02 04:36:16 +00:00
2008-12-20 15:23:48 +00:00
" ;
$e107 -> ns -> tablerender ( ADMSLAN_13 , $emessage -> render () . $text );
2006-12-02 04:36:16 +00:00
}
2008-10-20 21:52:38 +00:00
function edit_administrator ( $row )
{
2008-12-20 15:23:48 +00:00
global $sql , $e107 , $pref , $frm ;
2006-12-02 04:36:16 +00:00
$lanlist = explode ( " , " , e_LANLIST );
$a_id = $row [ 'user_id' ];
$ad_name = $row [ 'user_name' ];
$a_perms = $row [ 'user_perms' ];
2008-12-20 15:23:48 +00:00
$text = "
< form method = 'post' action = '".e_SELF."' id = 'myform' >
< fieldset id = 'core-administrator-edit' >
< legend class = 'e-hideme' > " .ADMSLAN_52. " </ legend >
< table cellpadding = '0' cellspacing = '0' class = 'adminform' >
< colgroup span = '2' >
< col class = 'col-label' />
< col class = 'col-control' />
</ colgroup >
< tbody >
< tr >
< td class = 'label' > " .ADMSLAN_16. " : </ td >
< td class = 'control' >
" . $ad_name . "
< input type = 'hidden' name = 'ad_name' size = '60' value = '{$ad_name}' />
</ td >
</ tr >
< tr >
< td class = 'label' > " .ADMSLAN_18. " </ td >
< td class = 'control' >
2006-12-02 04:36:16 +00:00
2008-12-20 15:23:48 +00:00
" ;
//XXX Lan - General
$text .= "
< div class = 'field-section' >
< h4 > " .ADMSLAN_74. " </ h4 >
" ;
$text .= checkb ( " 1 " , $a_perms , ADMSLAN_19 ); // Alter site preferences
$text .= checkb ( " 2 " , $a_perms , ADMSLAN_20 ); // Alter Menus
$text .= checkb ( " 3 " , $a_perms , ADMSLAN_21 ); // Modify administrator permissions
$text .= checkb ( " 4 " , $a_perms , ADMSLAN_22 ); // Moderate users/bans etc
2009-08-05 14:22:15 +00:00
$text .= checkb ( " 5 " , $a_perms , ADMSLAN_23 ); // create/edit custom pages
$text .= checkb ( " J " , $a_perms , ADMSLAN_41 ); // create/edit custom menus
2008-12-20 15:23:48 +00:00
$text .= checkb ( " Q " , $a_perms , ADMSLAN_24 ); // Manage download categories
$text .= checkb ( " 6 " , $a_perms , ADMSLAN_25 ); // Upload /manage files
$text .= checkb ( " Y " , $a_perms , ADMSLAN_67 ); // file inspector
$text .= checkb ( " O " , $a_perms , ADMSLAN_68 ); // notify
$text .= checkb ( " 7 " , $a_perms , ADMSLAN_26 ); // Oversee news categories
// $text .= checkb("8", $a_perms, ADMSLAN_27); // Oversee link categories
$text .= checkb ( " C " , $a_perms , ADMSLAN_64 ); // Clear Cache - Previously moderate chatbox
$text .= checkb ( " 9 " , $a_perms , ADMSLAN_28 ); // Take site down for maintenance
$text .= checkb ( " W " , $a_perms , ADMSLAN_65 ); // Configure mail settings and mailout
$text .= checkb ( " D " , $a_perms , ADMSLAN_29 ); // Manage banners
// $text .= checkb("E", $a_perms, ADMSLAN_30); // Configure news feed headlines - now plugin
$text .= checkb ( " F " , $a_perms , ADMSLAN_31 ); // Configure emoticons
$text .= checkb ( " G " , $a_perms , ADMSLAN_32 ); // Configure front page content
$text .= checkb ( " S " , $a_perms , ADMSLAN_33 ); // Configure system logs (previously log/stats - now plugin)
$text .= checkb ( " T " , $a_perms , ADMSLAN_34 ); // Configure meta tags
$text .= checkb ( " V " , $a_perms , ADMSLAN_35 ); // Configure public file uploads
$text .= checkb ( " X " , $a_perms , ADMSLAN_66 ); // Configure Search
$text .= checkb ( " A " , $a_perms , ADMSLAN_36 ); // Configure Image Settings (Previously Moderate forums - NOW PLUGIN)
$text .= checkb ( " B " , $a_perms , ADMSLAN_37 ); // Moderate comments
$text .= checkb ( " H " , $a_perms , ADMSLAN_39 ); // Post news
$text .= checkb ( " I " , $a_perms , ADMSLAN_40 ); // Post links
2009-08-05 14:22:15 +00:00
2008-12-20 15:23:48 +00:00
// $text .= checkb("K", $a_perms, ADMSLAN_42); // Post reviews - NOW PLUGIN
$text .= checkb ( " L " , $a_perms , ADMSLAN_43 ); // Configure URLs
$text .= checkb ( " R " , $a_perms , ADMSLAN_44 ); // Post downloads
$text .= checkb ( " U " , $a_perms , ADMSLAN_45 ); // Schedule Tasks
$text .= checkb ( " M " , $a_perms , ADMSLAN_46 ); // Welcome message
$text .= checkb ( " N " , $a_perms , ADMSLAN_47 ); // Moderate submitted news
2006-12-02 04:36:16 +00:00
$text .= "
2008-12-20 15:23:48 +00:00
</ div >
< div class = 'field-section' >
< h4 > " .ADLAN_CL_7. " </ h4 > " ;
$text .= checkb ( " Z " , $a_perms , ADMSLAN_62 ); // Plugin Manager
2006-12-02 04:36:16 +00:00
$sql -> db_Select ( " plugin " , " * " , " plugin_installflag='1' " );
while ( $row = $sql -> db_Fetch ())
{
2008-12-20 15:23:48 +00:00
$text .= checkb ( " P " . $row [ 'plugin_id' ], $a_perms , LAN_PLUGIN . " - " . $e107 -> tp -> toHTML ( $row [ 'plugin_name' ] , FALSE , 'RAWTEXT,defs' ));
2006-12-02 04:36:16 +00:00
}
2008-12-20 15:23:48 +00:00
$text .= "
</ div > " ;
2006-12-02 04:36:16 +00:00
// Language Rights.. --------------
if ( $pref [ 'multilanguage' ])
{
sort ( $lanlist );
2008-12-20 15:23:48 +00:00
$text .= "
< div class = 'field-section' >
< h4 > " .ADLAN_132. " </ h4 > " ;
$text .= checkb ( $pref [ 'sitelanguage' ], $a_perms , $pref [ 'sitelanguage' ]);
2006-12-02 04:36:16 +00:00
foreach ( $lanlist as $langval )
{
2008-12-20 15:23:48 +00:00
//$langname = $langval;
2006-12-02 04:36:16 +00:00
$langval = ( $langval == $pref [ 'sitelanguage' ]) ? " " : $langval ;
if ( $langval )
{
2008-12-20 15:23:48 +00:00
$text .= checkb ( $langval , $a_perms , $langval );
2006-12-02 04:36:16 +00:00
}
}
2008-12-20 15:23:48 +00:00
$text .= "
</ div > " ;
2006-12-02 04:36:16 +00:00
}
// -------------------------
if ( getperms ( '0' ))
{
2008-12-20 15:23:48 +00:00
$text .= "
< div class = 'field-section' >
< h4 > " .ADMSLAN_58. " </ h4 > " ;
$text .= checkb ( " 0 " , $a_perms , ADMSLAN_58 );
$text .= "
</ div > " ;
2006-12-02 04:36:16 +00:00
}
2008-12-20 15:23:48 +00:00
$text .= "
< div class = 'field-section' >
" . $frm->admin_button ('check_all', 'jstarget:perms', 'action', LAN_CHECKALL). "
" . $frm->admin_button ('uncheck_all', 'jstarget:perms', 'action', LAN_UNCHECKALL). "
</ div >
</ td >
</ tr >
</ tbody >
</ table >
< div class = 'buttons-bar center' >
< input type = 'hidden' name = 'a_id' value = '{$a_id}' />
" . $frm->admin_button ('update_admin', ADMSLAN_52, 'update'). "
" . $frm->admin_button ('go_back', ADMSLAN_70). "
</ div >
</ fieldset >
</ form >
" ;
2006-12-02 04:36:16 +00:00
2008-12-20 15:23:48 +00:00
$e107 -> ns -> tablerender ( ADMSLAN_52 , $text );
2006-12-02 04:36:16 +00:00
}
require_once ( " footer.php " );
2008-12-20 15:23:48 +00:00
function checkb ( $arg , $perms , $label = '' )
2006-12-02 04:36:16 +00:00
{
2008-12-20 15:23:48 +00:00
global $frm ;
$par = " <div class='field-spacer'> " ;
$par .= $frm -> checkbox ( 'perms[]' , $arg , getperms ( $arg , $perms ));
if ( $label )
2006-12-02 04:36:16 +00:00
{
2008-12-20 15:23:48 +00:00
$par .= $frm -> label ( $label , 'perms[]' , $arg );
2006-12-02 04:36:16 +00:00
}
2008-12-20 15:23:48 +00:00
$par .= " </div> " ;
2006-12-02 04:36:16 +00:00
return $par ;
}
2008-12-20 15:23:48 +00:00
function renderperms ( $perm , $id )
2008-10-20 21:52:38 +00:00
{
2008-12-20 15:23:48 +00:00
global $pref , $pt , $e107 ;
2008-10-20 21:52:38 +00:00
if ( $perm == " 0 " )
{
2006-12-02 04:36:16 +00:00
return ADMSLAN_58 ;
}
2009-07-23 15:21:41 +00:00
$sql2 = e107 :: getDb ( 'sql2' );
2006-12-02 04:36:16 +00:00
$lanlist = explode ( " , " , e_LANLIST );
2008-10-20 21:52:38 +00:00
if ( ! $pt )
{
2006-12-02 04:36:16 +00:00
$pt [ " 1 " ] = ADMSLAN_19 ;
$pt [ " 2 " ] = ADMSLAN_20 ;
$pt [ " 3 " ] = ADMSLAN_21 ;
$pt [ " 4 " ] = ADMSLAN_22 ; // Moderate users/bans etc
2009-08-05 14:22:15 +00:00
$pt [ " 5 " ] = ADMSLAN_23 ; // create/edit custom pages
$pt [ " J " ] = ADMSLAN_41 ; // create/edit custom menus
2006-12-02 04:36:16 +00:00
$pt [ " Q " ] = ADMSLAN_24 ; // Manage download categories
$pt [ " 6 " ] = ADMSLAN_25 ; // Upload /manage files
$pt [ " Y " ] = ADMSLAN_67 ; // file inspector
$pt [ " O " ] = ADMSLAN_68 ; // notify
$pt [ " 7 " ] = ADMSLAN_26 ;
$pt [ " 8 " ] = ADMSLAN_27 ;
$pt [ " C " ] = ADMSLAN_64 ;
$pt [ " 9 " ] = ADMSLAN_28 ;
$pt [ " W " ] = ADMSLAN_65 ;
$pt [ " D " ] = ADMSLAN_29 ;
$pt [ " E " ] = ADMSLAN_30 ;
$pt [ " F " ] = ADMSLAN_31 ;
$pt [ " G " ] = ADMSLAN_32 ;
$pt [ " S " ] = ADMSLAN_33 ;
$pt [ " T " ] = ADMSLAN_34 ;
$pt [ " V " ] = ADMSLAN_35 ;
$pt [ " X " ] = ADMSLAN_66 ;
$pt [ " A " ] = ADMSLAN_36 ; // Configure Image Settings
$pt [ " B " ] = ADMSLAN_37 ;
$pt [ " H " ] = ADMSLAN_39 ;
$pt [ " I " ] = ADMSLAN_40 ;
$pt [ " L " ] = ADMSLAN_43 ;
$pt [ " R " ] = ADMSLAN_44 ;
$pt [ " U " ] = ADMSLAN_45 ;
$pt [ " M " ] = ADMSLAN_46 ;
$pt [ " N " ] = ADMSLAN_47 ;
$pt [ " Z " ] = ADMSLAN_62 ;
2008-12-20 15:23:48 +00:00
2006-12-02 04:36:16 +00:00
$sql2 -> db_Select ( " plugin " , " * " , " plugin_installflag='1' " );
2008-10-20 21:52:38 +00:00
while ( $row2 = $sql2 -> db_Fetch ())
{
2008-12-20 15:23:48 +00:00
$pt [( " P " . $row2 [ 'plugin_id' ])] = LAN_PLUGIN . " - " . $e107 -> tp -> toHTML ( $row2 [ 'plugin_name' ], FALSE , 'RAWTEXT,defs' );
2006-12-02 04:36:16 +00:00
}
}
$tmp = explode ( " . " , $perm );
$langperm = " " ;
2008-10-20 21:52:38 +00:00
foreach ( $tmp as $pms )
{
if ( in_array ( $pms , $lanlist ))
{
2006-12-02 04:36:16 +00:00
$langperm .= $pms . " " ;
2008-10-20 21:52:38 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
$permtxt [] = $pms ;
2008-10-20 21:52:38 +00:00
if ( $pt [ $pms ])
{
2006-12-02 04:36:16 +00:00
$ptext [] = $pt [ $pms ];
}
}
}
$ret = implode ( " " , $permtxt );
2008-10-20 21:52:38 +00:00
if ( $pref [ 'multilanguage' ])
{
2008-12-20 15:23:48 +00:00
$ret .= $langperm ;
2006-12-02 04:36:16 +00:00
}
2008-12-20 15:23:48 +00:00
$text = "
< div onclick = \ " e107Helper.toggle('id_ { $id } ') \" class='e-pointer' title=' " . ADMSLAN_71 . " '> { $ret } </div>
< div id = 'id_{$id}' class = 'e-hideme' >< ul >< li > " .implode( " </ li >< li > " , $ptext ). " </ li ></ ul ></ div >
" ;
2006-12-02 04:36:16 +00:00
return $text ;
2008-12-20 15:23:48 +00:00
}
2006-12-02 04:36:16 +00:00
2008-12-20 15:23:48 +00:00
/**
* Handle page DOM within the page header
*
* @ return string JS source
*/
function headerjs ()
{
require_once ( e_HANDLER . 'js_helper.php' );
$ret = "
< script type = 'text/javascript' >
//add required core lan - delete confirm message
( '".LAN_JSCONFIRM."' ) . addModLan ( 'core' , 'delete_confirm' );
</ script >
< script type = 'text/javascript' src = '".e_FILE_ABS."jslib/core/admin.js' ></ script >
" ;
2006-12-02 04:36:16 +00:00
2008-12-20 15:23:48 +00:00
return $ret ;
2006-12-02 04:36:16 +00:00
}
2008-12-20 15:23:48 +00:00
?>