Admin Forum functions
| > Module written by Matt Mecham
| > Date started: 17th March 2002
|
| > Module Version Number: 1.0.0
+--------------------------------------------------------------------------
*/
if ( ! defined( 'IN_ACP' ) )
{
print "
Incorrect access
You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
exit();
}
$idx = new ad_groups();
class ad_groups {
var $base_url;
function ad_groups() {
global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
//---------------------------------------
// Kill globals - globals bad, Homer good.
//---------------------------------------
$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
foreach ( $tmp_in as $k => $v )
{
unset($$k);
}
//---------------------------------------
switch($IN['code'])
{
case 'doadd':
$this->save_group('add');
break;
case 'add':
$this->group_form('add');
break;
case 'edit':
$this->group_form('edit');
break;
case 'doedit':
$this->save_group('edit');
break;
case 'delete':
$this->delete_form();
break;
case 'dodelete':
$this->do_delete();
break;
//-------------------------
case 'fedit':
$this->forum_perms();
break;
case 'pdelete':
$this->delete_mask();
break;
case 'dofedit':
$this->do_forum_perms();
break;
case 'permsplash':
$this->permsplash();
break;
case 'view_perm_users':
$this->view_perm_users();
break;
case 'remove_mask':
$this->remove_mask();
break;
case 'preview_forums':
$this->preview_forums();
break;
case 'dopermadd':
$this->add_new_perm();
break;
case 'donameedit':
$this->edit_name_perm();
break;
//-------------------------
default:
$this->main_screen();
break;
}
}
//+---------------------------------------------------------------------------------
//
// Member group /forum mask permission form thingy doodle do yes. Viewing Perm users
//
//+---------------------------------------------------------------------------------
function delete_mask()
{
global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
//+-------------------------------------------
// Check for a valid ID
//+-------------------------------------------
if ($IN['id'] == "")
{
$ADMIN->error("Could not resolve the permission mask setty doodle thingy ID, please try again");
}
$DB->query("DELETE FROM ibf_forum_perms WHERE perm_id='".$IN['id']."'");
$old_id = intval($IN['id']);
//+-------------------------------------------
// Remove from forums...
//+-------------------------------------------
$get = $DB->query("SELECT id, read_perms, reply_perms, start_perms, upload_perms FROM ibf_forums");
while( $f = $DB->fetch_row($get) )
{
$d_str = "";
$d_arr = array();
foreach( array( 'read_perms', 'reply_perms', 'start_perms', 'upload_perms' ) as $perm_bit )
{
if ($f[ $perm_bit ] != '*')
{
if ( preg_match( "/(^|,)".$old_id."(,|$)/", $f[ $perm_bit ]) )
{
$f[ $perm_bit ] = preg_replace( "/(^|,)".$old_id."(,|$)/", "\\1\\2", $f[ $perm_bit ] );
$d_arr[ $perm_bit ] = $this->clean_perms( $f[ $perm_bit ] );
}
}
}
// Do we have anything to save?
if ( count($d_arr) > 0 )
{
$d_str = $DB->compile_db_update_string( $d_arr );
// Sure?..
if ( strlen($d_str) > 5)
{
$save = $DB->query("UPDATE ibf_forums SET $d_str WHERE id={$f['id']}");
}
}
}
$this->permsplash();
}
//+---------------------------------------------------------------------------------
function add_new_perm()
{
global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
$IN['new_perm_name'] = trim($IN['new_perm_name']);
if ($IN['new_perm_name'] == "")
{
$ADMIN->error("You must enter a name");
}
$copy_id = $IN['new_perm_copy'];
//+-------------------------------------------
// UPDATE DB
//+-------------------------------------------
$DB->query("INSERT INTO ibf_forum_perms SET perm_name='".$IN['new_perm_name']."'");
$new_id = $DB->get_insert_id();
if ( $copy_id != 'none' )
{
//+-------------------------------------------
// Add new mask to forum accesses
//+-------------------------------------------
$old_id = intval($copy_id);
if ( ($new_id > 0) and ($old_id > 0) )
{
$get = $DB->query("SELECT id, read_perms, reply_perms, start_perms, upload_perms FROM ibf_forums");
while( $f = $DB->fetch_row($get) )
{
$d_str = "";
$d_arr = array();
foreach( array( 'read_perms', 'reply_perms', 'start_perms', 'upload_perms' ) as $perm_bit )
{
if ($f[ $perm_bit ] != '*')
{
if ( preg_match( "/(^|,)".$old_id."(,|$)/", $f[ $perm_bit ]) )
{
$d_arr[ $perm_bit ] = $this->clean_perms( $f[ $perm_bit ] ) . ",".$new_id;
}
}
}
// Do we have anything to save?
if ( count($d_arr) > 0 )
{
$d_str = $DB->compile_db_update_string( $d_arr );
// Sure?..
if ( strlen($d_str) > 5)
{
$save = $DB->query("UPDATE ibf_forums SET $d_str WHERE id={$f['id']}");
}
}
}
}
}
$this->permsplash();
}
//-_-_-_-_-_-_-_-_-
//_-_-_-_-_-_-_-_-_
//Now that's pretty
function preview_forums()
{
global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
//+-------------------------------------------
// Check for a valid ID
//+-------------------------------------------
if ($IN['id'] == "")
{
$ADMIN->error("Could not resolve the permission mask setty doodle thingy ID, please try again");
}
$DB->query("SELECT * FROM ibf_forum_perms WHERE perm_id='".$IN['id']."'");
if ( ! $perms = $DB->fetch_row() )
{
$ADMIN->error("Could not resolve the permission mask setty doodle thingy ID, please try again");
}
//+-------------------------------------------
// What we doin'?
//+-------------------------------------------
switch( $IN['t'] )
{
case 'start':
$human_type = 'Start Topics';
$code_word = 'start_perms';
break;
case 'reply':
$human_type = 'Reply To Topics';
$code_word = 'reply_perms';
break;
default:
$human_type = 'View Forum';
$code_word = 'read_perms';
break;
}
//+-------------------------------------------
// Get all members using that ID then!
//+-------------------------------------------
$SKIN->td_header[] = array( "$human_type" , "100%" );
//+-------------------------------
$ADMIN->html .= $SKIN->start_table( "Preview using: " . $perms['perm_name'] );
$last_cat_id = -1;
$DB->query("SELECT f.id as forum_id, f.parent_id, f.subwrap, f.sub_can_post, f.name as forum_name, f.position, f.read_perms, f.start_perms, f.reply_perms, c.id as cat_id, c.name
FROM ibf_forums f
LEFT JOIN ibf_categories c ON (c.id=f.category)
ORDER BY c.position, f.position");
$forum_keys = array();
$cat_keys = array();
$children = array();
$subs = array();
$the_html = "";
$perm_id = intval($IN['id']);
while ( $i = $DB->fetch_row() )
{
if ($i['subwrap'] == 1 and $i['sub_can_post'] != 1)
{
$forum_keys[ $i['cat_id'] ][$i['forum_id']] = " - {$i['forum_name']}\n";
}
else
{
if ($i[ $code_word ] == '*')
{
if ($i['parent_id'] > 0)
{
$children[ $i['parent_id'] ][] = " ---- {$i['forum_name']}\n";
}
else
{
$forum_keys[ $i['cat_id'] ][$i['forum_id']] = " - {$i['forum_name']}\n";
}
}
else if (preg_match( "/(^|,)".$perm_id."(,|$)/", $i[ $code_word ]) )
{
if ($i['parent_id'] > 0)
{
$children[ $i['parent_id'] ][] = " ---- {$i['forum_name']}\n";
}
else
{
$forum_keys[ $i['cat_id'] ][$i['forum_id']] = " - {$i['forum_name']}\n";
}
}
else
{
//-------------------------------------
// CAN'T ACCESS
//-------------------------------------
if ($i['parent_id'] > 0)
{
$children[ $i['parent_id'] ][] = " ---- {$i['forum_name']}\n";
}
else
{
$forum_keys[ $i['cat_id'] ][$i['forum_id']] = " - {$i['forum_name']}\n";
}
}
}
if ($last_cat_id != $i['cat_id'])
{
// Make sure cats with hidden forums are not shown in forum jump
$cat_keys[ $i['cat_id'] ] = "{$i['name']}\n";
$last_cat_id = $i['cat_id'];
}
}
foreach($cat_keys as $cat_id => $cat_text)
{
if ( is_array( $forum_keys[$cat_id] ) && count( $forum_keys[$cat_id] ) > 0 )
{
$the_html .= $cat_text;
foreach($forum_keys[$cat_id] as $idx => $forum_text)
{
$the_html .= $forum_text;
if (count($children[$idx]) > 0)
{
foreach($children[$idx] as $ii => $tt)
{
$the_html .= $tt;
}
}
}
}
}
$the_html = str_replace( "\n", " \n", $the_html );
$ADMIN->html .= $SKIN->add_td_row( array( $the_html ) );
$ADMIN->html .= $SKIN->end_table();
//----------------------------------------------------------------------------------------
$ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code' , 'preview_forums' ),
2 => array( 'act' , 'group' ),
3 => array( 'id' , $IN['id'] ),
) );
$SKIN->td_header[] = array( " " , "60%" );
$SKIN->td_header[] = array( " " , "40%" );
$ADMIN->html .= $SKIN->start_table( "Legend & Info" );
$ADMIN->html .= $SKIN->add_td_row( array(
"Can $human_type for this forum",
""
) );
$ADMIN->html .= $SKIN->add_td_row( array(
"CANNOT $human_type for this forum",
""
) );
$ADMIN->html .= $SKIN->add_td_row( array(
"Test with...",
$SKIN->form_dropdown( 't',
array( 0 => array( 'start', 'Start Topics' ),
1 => array( 'reply', 'Reply To Topics' ),
2 => array( 'read' , 'Read Forum' ),
), $IN['t'] )
) );
$ADMIN->html .= $SKIN->end_form( "Update" );
$ADMIN->html .= $SKIN->end_table();
$ADMIN->print_popup();
}
//===========================================================================
function remove_mask()
{
global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
//+-------------------------------------------
// Check for a valid ID
//+-------------------------------------------
if ($IN['id'] == "")
{
$ADMIN->error("Could not resolve the member ID, please try again");
}
//+-------------------------------------------
// Get, check and reset
//+-------------------------------------------
$DB->query("SELECT id, name, org_perm_id FROM ibf_members WHERE id=".intval($IN['id']));
if ( ! $mem = $DB->fetch_row() )
{
$ADMIN->error("Could not resolve the member ID, please try again");
}
if ( $IN['pid'] == 'all' )
{
$DB->query("UPDATE ibf_members SET org_perm_id=0 WHERE id=".intval($IN['id']));
}
else
{
$IN['pid'] = intval($IN['pid']);
$pid_array = explode( ",", $mem['org_perm_id'] );
if ( count($pid_array) < 2 )
{
$DB->query("UPDATE ibf_members SET org_perm_id=0 WHERE id=".intval($IN['id']));
}
else
{
$new_arr = array();
foreach( $pid_array as $sid )
{
if ( $sid != $IN['pid'] )
{
$new_arr[] = $sid;
}
}
$DB->query("UPDATE ibf_members SET org_perm_id='".implode(",",$new_arr)."' WHERE id=".intval($IN['id']));
}
}
//+-------------------------------------------
// Get all members using that ID then!
//+-------------------------------------------
$SKIN->td_header[] = array( " " , "100%" );
//+-------------------------------
$ADMIN->html .= $SKIN->start_table( "Result" );
$ADMIN->html .= $SKIN->add_td_row( array( "Removed the custom permission mask from {$mem['name']}.",
) );
$ADMIN->html .= $SKIN->end_table();
$ADMIN->print_popup();
}
//===========================================================================
function view_perm_users()
{
global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
//+-------------------------------------------
// Check for a valid ID
//+-------------------------------------------
if ($IN['id'] == "")
{
$ADMIN->error("Could not resolve the permission mask setty doodle thingy ID, please try again");
}
$DB->query("SELECT * FROM ibf_forum_perms WHERE perm_id='".$IN['id']."'");
if ( ! $perms = $DB->fetch_row() )
{
$ADMIN->error("Could not resolve the permission mask setty doodle thingy ID, please try again");
}
//+-------------------------------------------
// Get all members using that ID then!
//+-------------------------------------------
$SKIN->td_header[] = array( "User Details" , "50%" );
$SKIN->td_header[] = array( "Action" , "50%" );
//+-------------------------------
$ADMIN->html .= "";
//+-------------------------------
$ADMIN->html .= $SKIN->start_table( "Members using: " . $perms['perm_name'] );
$outer = $DB->query("SELECT id, name, email, posts, org_perm_id FROM ibf_members WHERE (org_perm_id IS NOT NULL AND org_perm_id <> 0) ORDER BY name");
while( $r = $DB->fetch_row($outer) )
{
$exp_pid = explode( ",", $r['org_perm_id'] );
foreach( explode( ",", $r['org_perm_id'] ) as $pid )
{
if ( $pid == $IN['id'] )
{
if ( count($exp_pid) > 1 )
{
$extra = "
Also using: ";
$DB->query("SELECT * FROM ibf_forum_perms WHERE perm_id IN ({$r['org_perm_id']}) AND perm_id <> {$IN['id']}");
while ( $mr = $DB->fetch_row() )
{
$extra .= $mr['perm_name'].",";
}
$extra = preg_replace( "/,$/", "", $extra );
$extra .= "";
}
else
{
$extra = "";
}
$ADMIN->html .= $SKIN->add_td_row( array( "
Edit Member",
) );
}
}
}
$ADMIN->html .= $SKIN->end_table();
$ADMIN->print_popup();
}
//+---------------------------------------------------------------------------------
//
// Member group /forum mask permission form thingy doodle do yes.
//
//+---------------------------------------------------------------------------------
function permsplash()
{
global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
$ADMIN->page_title = "Forum Permission Mask [ HOME ]";
$ADMIN->page_detail = "You can manage your forum permission masks from this section.";
$ADMIN->page_detail .= " Used by Groups relates to the member groups that use this permission mask
Used by Members relates to the number of members that have this permission mask set to over ride the group used permission mask
Preview the forums this mask has access to in a quick, convenient format
";
//+-------------------------------------------
// Get the names for the perm masks w/id
//+-------------------------------------------
$perms = array();
$DB->query("SELECT * FROM ibf_forum_perms");
while( $r = $DB->fetch_row() )
{
$perms[ $r['perm_id'] ] = $r['perm_name'];
}
//+-------------------------------------------
// Get the number of members using this mask
// as an over ride
//+-------------------------------------------
$mems = array();
$DB->query("SELECT COUNT(id) as count, org_perm_id FROM ibf_members WHERE (org_perm_id IS NOT NULL AND org_perm_id <> 0) GROUP by org_perm_id");
while( $r = $DB->fetch_row() )
{
if ( strstr($r['org_perm_id'] , "," ) )
{
foreach( explode( ",", $r['org_perm_id'] ) as $pid )
{
$mems[ $pid ] += $r['count'];
}
}
else
{
$mems[ $r['org_perm_id'] ] += $r['count'];
}
}
//+-------------------------------------------
// Get the member group names and the mask
// they use
//+-------------------------------------------
$groups = array();
$DB->query("SELECT g_id, g_title, g_perm_id FROM ibf_groups");
while( $r = $DB->fetch_row() )
{
if ( strstr($r['g_perm_id'] , "," ) )
{
foreach( explode( ",", $r['g_perm_id'] ) as $pid )
{
$groups[ $pid ][] = $r['g_title'];
}
}
else
{
$groups[ $r['g_perm_id'] ][] = $r['g_title'];
}
}
//+-------------------------------------------
// Print the splash screen
//+-------------------------------------------
$SKIN->td_header[] = array( "Mask Name" , "20%" );
$SKIN->td_header[] = array( "Used by Group(s)" , "20%" );
$SKIN->td_header[] = array( "Used by Mem(s)" , "20%" );
$SKIN->td_header[] = array( "Preview" , "10%" );
$SKIN->td_header[] = array( "Edit" , "15%" );
$SKIN->td_header[] = array( "Delete" , "15%" );
//+-------------------------------
$ADMIN->html .= $SKIN->js_pop_win();
//+-------------------------------
$ADMIN->html .= $SKIN->start_table( "Forum Permission Masks" );
foreach( $perms as $id => $name )
{
$groups_used = "";
$is_active = 0;
if ( is_array( $groups[ $id ] ) )
{
foreach( $groups[ $id ] as $bleh => $g_title )
{
$groups_used .= $g_title . " ";
}
$is_active = 1;
}
else
{
$groups_used = "