<?php
// +---------------------------------------------------------------------------+
// | Universal Geeklog Plugin 1.0 |
// +---------------------------------------------------------------------------+
// | admin/index.php |
// | Administration page. |
// | |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2002 by the following authors: |
// | |
// | Author: |
// | Constructed with the Universal Plugin |
// | Copyright (C) 2002 by the following authors: |
// | Tom Willett - hide@address.com |
// | Blaine Lang - hide@address.com |
// | The Universal Plugin is based on prior work by: |
// | Tony Bibbs - hide@address.com |
// +---------------------------------------------------------------------------+
// | Replace all geekddb with the name of your plugin and you have a skeletal |
// | admin page. |
// +---------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
//
require_once('lib-common.php');
// Only let admin users access this page
if (!SEC_hasRights('geekddb.admin')) {
// Someone is trying to illegally access this page
COM_errorLog("Someone has tried to illegally access the geekddb Admin page. User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: $REMOTE_ADDR",1);
$display = COM_siteHeader();
$display .= COM_startBlock($LANG_DB00['access_denied']);
$display .= $LANG_DB00['access_denied_msg'];
$display .= COM_endBlock();
$display .= COM_siteFooter(true);
echo $display;
exit;
}
//end access check */
/**
* Main
*/
$display = COM_siteHeader();
$T = new Template($_CONF['path'] . 'plugins/geekddb/templates');
$T->set_file('admin', 'admin.thtml');
$T->set_var('site_url',$_CONF['site_url']);
$T->set_var('site_admin_url', $_CONF['site_admin_url']);
$T->set_var('header', $LANG_DB00['admin']);
$T->set_var('plugin','geekddb');
// include config, functions, common, check_table and header
include ($_CONF['path'] . 'plugins/geekddb/config.php');
include ($_CONF['path'] . 'plugins/geekddb/functions.php');
include ($_CONF['path'] . 'plugins/geekddb/common.php');
//include ($_CONF['path'] . 'plugins/geekddb/templates/header_admin.php');
function edittable($table_name)
{
global $_TABLES, $_USER, $LANG21, $_CONF, $LANG_ACCESS, $_GDDB_CONF ;
$sql = "select * from " . $_TABLES['geekDDB_tables'] . " where table_name = '" . $table_name ."'" ;
//echo $sql ;
$result = DB_query("$sql");
$A = DB_fetchArray($result);
$access = SEC_hasAccess($A['owner_id'],$A['group_id'],$A['perm_owner'],$A['perm_group'],$A['perm_members'],$A['perm_anon']);
/* DEV Debug
echo "<hr>" ;
echo $access ;
echo "<pre>" ;
print_r($A) ;
echo "</pre>" ;
// end debug*/
// This needs to be changed from using block terms to geekDDB terms
if ($access == "1" || $access == "0") {
$retval .= COM_startBlock($LANG21[44])
.$LANG21[45]
.COM_endBlock();
return $retval;
}
$table_templates = new Template($_CONF['path'] . 'plugins/geekddb/templates/admin');
$table_templates->set_var('lang_accessrights', $LANG_ACCESS['accessrights']);
$table_templates->set_var('lang_owner', $LANG_ACCESS['owner']);
$table_templates->set_var('owner_username', DB_getItem($_TABLES['users'],'username',"uid = '{$A['owner_id']}'"));
$table_templates->set_var('owner_id', $A['owner_id']);
$table_templates->set_var('lang_group', $LANG_ACCESS['group']);
$usergroups = SEC_getUserGroups();
$groupdd = '';
if ($access == 3) {
$groupdd .= '<select name="group_id">' . LB;
for ($i = 0; $i < count($usergroups); $i++) {
$groupdd .= '<option value="'.$usergroups[key($usergroups)].'"';
if ($A['group_id'] == $usergroups[key($usergroups)]) {
$groupdd .= ' selected="selected"';
}
$groupdd .= '>'.key($usergroups).'</option>' . LB;
next($usergroups);
}
$groupdd .= '</select>' . LB;
} else {
// They can't set the group then
$groupdd.= DB_getItem($_TABLES['groups'],'grp_name',"grp_id = '{$A['group_id']}'")
.'<input type="hidden" name="group_id" value="'.$A['group_id'].'">';
}
$table_templates->set_file('editor','tableeditor.thtml');
$table_templates->set_var('site_url', $_CONF['site_url']);
$table_templates->set_var('change_table_form', DDB_getChangeTableHTML()) ; ;
$table_templates->set_var('form_action', $PHP_SELF);
$table_templates->set_var('table_name', $table_name);
$table_templates->set_var('group_dropdown', $groupdd);
$table_templates->set_var('DDB_permissionsHTML' , DDB_getPermissionHTML($A['is_enabled'], $A['enable_insert_table'], $A['enable_edit_table'], $A['enable_delete_table'], $A['enable_details_table'])) ;
$table_templates->set_var('lang_permissions', $LANG_ACCESS['permissions']);
$table_templates->set_var('lang_perm_key', $LANG_ACCESS['permissionskey']);
$table_templates->set_var('permissions_editor', SEC_getPermissionsHTML($A['perm_owner'],$A['perm_group'],$A['perm_members'],$A['perm_anon']));
$table_templates->set_var('lang_permissions_msg', $LANG_ACCESS['permmsg']);
// print_r($table_templates) ;
$table_templates->parse('output', 'editor');
$retval .= $table_templates->finish($table_templates->get_var('output'));
return $retval;
} // end edittable function
function savetable($table_name, $owner_id,$group_id, $enable_insert, $enable_edit, $enable_delete, $enable_detail, $perm_owner,$perm_group,$perm_members,$perm_anon,$is_enabled)
{
global $_TABLES, $_CONF,$LANG21,$LANG01,$_POST, $PHP_SELF;
list($perm_owner,$perm_group,$perm_members,$perm_anon) = SEC_getPermissionValues($perm_owner,$perm_group,$perm_members,$perm_anon);
DB_save($_TABLES['geekDDB_tables'], 'table_name,owner_id,group_id,enable_insert_table,enable_edit_table,enable_delete_table,enable_details_table,perm_owner,perm_group,perm_members,perm_anon,is_enabled',
"'$table_name', '$owner_id','$group_id', '$enable_insert', '$enable_edit', '$enable_delete', '$enable_detail' ,'$perm_owner','$perm_group','$perm_members','$perm_anon','$is_enabled'"
,$PHP_SELF. '?function=edittable&table_name=' . $table_name);
echo "saved" ;
}
switch($function){
case "edittable" :
echo edittable($table_name) ;
break ;
case "set_permissions" :
print_r($_POST) ;
savetable($_POST['table_name'],$_POST['owner_id'],$_POST['group_id'],$_POST['enable_insert'],$_POST['enable_edit'],$_POST['enable_delete'], $_POST['enable_detail'],$_POST['perm_owner'],$_POST['perm_group'],$_POST['perm_members'],$_POST['perm_anon'],$_POST['is_enabled']) ;
break ;
default:
echo DDB_getChangeTableHTML() ;
break;
} // end switch
// include footer
//include ($_CONF['path'] . 'plugins/geekddb/templates/footer_admin.php');
// $T->parse('output','admin');
// $display .= $T->finish($T->get_var('output'));
$display = COM_siteFooter(true);
echo $display;
echo "<pre>" ;
print_r($_REQUEST) ;
?>