Location: PHPKode > projects > Bcom > bcom-1.99.1/bcom/channelmanager.php
<?
/*
 Name: channel manager
 Filename: channelmanager.php
 Author(s): Tim Gunn
 Version: 2.0.0
 Purpose:
 	Manages channels. (needs work).
*/

require_once('lib/libmain.inc');
bcom_init('NORMAL');

require_once('lib/libgeneral.inc');
require_once('lib/libui.inc');
require_once('lib/libchannels.inc');

manager_start('channel');
iheader('title=Channel manager');
$bar = 1;

if(isset($action)) {
    if($action == 'addgroup') {
		print '<H3>Adding Group to '.group_getname($groupid).'</H3>
		<TABLE CELLSPACING="2" CELLPADDING="2" BORDER="0"><FORM METHOD="POST" ACTION="'.$PHP_SELF.'">
		<TR><TH>New Group Name</TH><TH>Commands</TH></TR>
		<TR><TD CLASS="bar1">'.ui_textbox('name','').'</TD>
		<TD CLASS="bar1">'.formbutton('addgroup','add-group').formbutton('exit','exit').'</TD></TR>
		<INPUT TYPE="HIDDEN" NAME="parent" VALUE="'.$groupid.'">
		<INPUT TYPE="HIDDEN" NAME="action" VALUE="addgroupnow">
		</FORM></TABLE>';
		ui_end();
    }
    if($action == 'addgroupnow') {
		if(waspressed('addgroup')) {
		    $id = group_add($_CURR_BTYPE,$name,$parent);
		    group_select($id);
		    $X_GROUPID[$_CURR_BTYPE] = $id;
		}
		$display = 'groups';
    }
    if($action == 'movetogroup') {
		if(isset($channelid)) {
		    ui_movetogroup('channel',$channelid);
		}
    }
    if($action == 'movegroup') {
		if(isset($groupid)) {
	    	ui_movegroup('channel',$groupid);
		}
    }
    if($action == 'deletegroup') {
    	if(getfullauth('group',$groupid) && $groupid != $BTYPE['defgroup'][$_CURR_BTYPE]) {	
	    	group_delete($groupid);
		}
		$display = 'groups'; $groupid = $BTYPE['defgroup'][$_CURR_BTYPE];
    }
    if($action == 'deletechannel') {
		if(getfullauth('channel',$channelid)) {
	    	channel_delete($channelid);
		}
		$display = 'channels';
    }
    if($action == 'savechannel') {
		if(waspressed('save') || waspressed('saveexit')) {
	    	if(getwriteauth('channel',$channelid,0)) {
	        	channel_setval($channelid,'c_name',$c_name);
				$savefunc = $_CHNTYPE[channel_getval($channelid,'c_type')]['ef'].'_save';
	    		if(function_exists($savefunc)) {
					$savefunc($channelid);
				}
			}
		}
	
		if(waspressed('create')) {
			if(getwriteauth('group',$X_GROUPID[$_CURR_BTYPE])) {
				$channelid = channel_new($c_name,$c_type,$X_GROUPID[$_CURR_BTYPE]);
				debug_print("$c_name,$c_type, ".group_getname($X_GROUPID[$_CURR_BTYPE]));
			}
		}
		if(!waspressed('exit') && !waspressed('saveexit')) { $action = 'editchannel'; }
    }
    if($action == 'newchannel') {
		print '<FORM METHOD="POST" ACTION="'.$PHP_SELF.'"><TABLE CELLPADDING="2" CELLSPACING="2" BORDER="0">
		<INPUT TYPE="HIDDEN" NAME="newchannel" VALUE="1">
		<INPUT TYPE="HIDDEN" NAME="action" VALUE="savechannel">
		<TR><TH>Channel Name</TH><TH>Channel Type</TH><TH>Group</TH><TH>Commands</TH></TR>
		<TR>
		<TD CLASS="bar1">'.ui_textbox('c_name','').'</TD>
		<TD CLASS="bar1"><SELECT NAME="c_type">';
		foreach($_CHNTYPE as $type => $data) {
			if($data['ic'] != 1) {
				print '<OPTION VALUE="'.$type.'">'.$data['cn'];
			}
		}
		print '</SELECT></TD>
		<TD CLASS="bar1">'.group_getname($X_GROUPID[$_CURR_BTYPE]).'</TD>
		<TD CLASS="bar1">
		'.formbutton('create','create').'
		'.formbutton('exit','exit').'
		</TD>
		</TR>
		</TABLE>';
		ui_end();
    }
    if($action == 'editchannel' && getwriteauth('channel',$channelid)) {
    	if(function_exists($_CHNTYPE[channel_getval($channelid,'c_type')]['ef'])) {
	    	$_CHNTYPE[channel_getval($channelid,'c_type')]['ef']($channelid);
		}
		else
		{
	    	print '<FORM METHOD="POST" ACTION="'.$PHP_SELF.'"><TABLE CELLPADDING="2" CELLSPACING="2" BORDER="0">
	    	<INPUT TYPE="HIDDEN" NAME="channelid" VALUE="'.$channelid.'">
	    	<INPUT TYPE="HIDDEN" NAME="action" VALUE="savechannel">
	    	<TR><TH>Save</TH><TH>Channel Name</TH><TH>Group</TH></TR>
	    	<TR>
	    	<TD CLASS="bar1">
	    	'.formbutton('save','save').'
	    	'.formbutton('saveexit','save-and-exit').'
	    	'.formbutton('exit','exit').'
	    	</TD><TD CLASS="bar1">'.ui_textbox('c_name',channel_getval($channelid,'c_name')).'</TD>
	    	<TD CLASS="bar1">'.group_getname(channel_getval($channelid,'c_group')).'</TD>
	    	</TR>
	    	</TABLE></FORM>';
		}
		ui_end();
    }
}

$menu = array('channels'=>'Channels','groups'=>'Channel groups');
ui_displaymenu($PHP_SELF.'?display',$menu,'channels');

print '<BR>';

if($display == 'channels') {
    $listsize = getuseroption('general','defaultlistsize',25); $where = 0; $count = 0;
    $result = manager_mainnav_start('SELECT * FROM channel_main WHERE c_group = '.$X_GROUPID[$_CURR_BTYPE].' ORDER BY c_name ASC');
    $total = bsql_numrows($result);
    ui_listnav($liststart[$_CURR_BTYPE],$total,$listsize);
    if($total > 0) {
		bsql_jumprows($result,$liststart[$_CURR_BTYPE]-1);
		print '<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="2" WIDTH="100%">
		<TR><TH>Channel</TH><TH>Type</TH><TH>Group</TH><TH>Commands</TH></TR>';
		while(($row = bsql_getrow($result)) && ($count < $listsize))
		{
	    	$count++;
	    	if($bar == 1) { $bar = 2; } else { $bar = 1; }
	    	if(getreadauth('channel',$row['c_id'],0)) { 
				if(!isset($_CHNTYPE[$row['c_type']])) {
					$_CHNTYPE[$row['c_type']]['cn'] = 'unknown type ('.$row['c_type'].')';
				}
				if($row['c_name'] == '')  { $row['c_name'] = '(no name)'; }
				print '<TR>
				<TD CLASS=bar'.$bar.' NOWRAP><A HREF="'.$PHP_SELF.'?channelid='.$row['c_id'].'">'.htmlspecialchars($row['c_name']).'</A></TD>
				<TD CLASS=bar'.$bar.' NOWRAP><A HREF="'.$PHP_SELF.'?channelid='.$row['c_id'].'">'.$_CHNTYPE[$row['c_type']]['cn'].'</A></TD>
				<TD CLASS=bar'.$bar.' NOWRAP>'.group_getname($row['c_group'],'trail',$PHP_SELF.'?set_groupid=').'&nbsp;</TD>
				<TD CLASS=bar'.$bar.' NOWRAP>'.getbutton('edit',$PHP_SELF.'?action=editchannel&channelid='.$row['c_id']);
				if(getfullauth('channel',$row['c_id'],0)) {
		    		print getbutton('move','javascript:bopenwindow(\'channelmanager.php?action=movetogroup&channelid='.$row['c_id'].'&uinotitle=1\',\'MoveChannel\',400,300)');
		    		print getbutton('delete',$PHP_SELF.'?action=deletechannel&channelid='.$row['c_id'],'Are you sure you wish to delete this channel?\n'.addslashes($row['c_name']));
				}
				print '</TD></TR>';
	    	} else {
	        	print '<TR><TD CLASS=bar'.$bar.' COLSPAN=4><DIV ALIGN="CENTER">no access</DIV></TD></TR>';
	    	}
		}
    }
    manager_mainnav_end();
}

function channelgroup ($id,$desc,$auth)
{
    global $PHP_SELF,$BTYPE,$_CURR_BTYPE;
    $crow = bsql_quickrow('SELECT count(*) FROM channel_main WHERE c_group = '.$id);
    print '<TD CLASS=bar'.$GLOBALS['bar'].'>'.$crow[0].'</TD><TD CLASS="bar'.$GLOBALS['bar'].'">'.$auth.'</TD><TD CLASS=bar'.$GLOBALS['bar'].'>';
    if($auth == 'full' || $auth == 'write') {
    	print getbutton('add-group',$PHP_SELF.'?action=addgroup&groupid='.$id);
		print getbutton('edit',$PHP_SELF.'?action=editgroup&groupid='.$id);
    }
    if($auth == 'full') {
		if($id != $BTYPE['defgroup'][$_CURR_BTYPE]) {
	    	print getbutton('move','javascript:bopenwindow(\'channelmanager.php?action=movegroup&groupid='.$id.'&uinotitle=1\',\'MoveGroup\',400,300)');
	    	print getbutton('delete',$PHP_SELF.'?action=deletegroup&groupid='.$id,'Are you sure you wish to delete this group?\nIt contains '.$crow[0].' channels.\nAll groups and channels under this group will also be deleted.');
		}
		print getbutton('security','securitymanager.php?action=editobject&objecttype=group&objectid='.$id);
    }
}

if($display == 'groups')
{
    $BCOM_RETURN = '<A HREF="'.$PHP_SELF.'?display=groups">Back to Channel Groups</A>';
    session_register('BCOM_RETURN');
    
    $bar = 1;
    print '<BR><BR><TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2>
    <TR><TH>Name</TH><TH># of channels</TH><TH>Access</TH><TH>Commands</TH></TR>';
    ui_grouplist (0,'channel',$PHP_SELF.'?display=groups&set_groupid=','channelgroup');
    print '</TABLE>';
}

ui_autodisplay();

ui_end();
Return current item: Bcom