Pagina 1 van 1

Links

Geplaatst: 16 mar 2005, 22:11
door PHP Freak
Hai allemaal, ik had link mod geinstaleerd, toen ik klaar was wou ik wat links toevoegen, na dat ik dat heb gedaan ging ik effe kijken, en toen stonden ze er niet op :? :?:
wie weet wat ik moet doen :?:
heb alles gedaan wat er op stond

Mod
http://www.phpbbhacks.com/download.php?id=2048
Demo
http://mods.db9.dk/links.php
ik denk dat er nog andere mensen zijn met dit probleempje :oops:

alvast Thx :wink:

Geplaatst: 16 mar 2005, 22:41
door Bee
http://mods.db9.dk/viewtopic.php?t=5165
Lost dat het op? Ik zie er verder weinig info over.

Geplaatst: 17 mar 2005, 08:48
door PHP Freak
ik krijg steeds deze fout
Parse error: parse error, expecting `')'' in /data/members/free/tripod/nl/k/a/r/karim4life/htdocs/admin/admin_db_utilities.php on line 695

en dit is mijn admin_db_utilities.php

Code: Selecteer alles

<?php
/***************************************************************************
 *                             admin_links.php
 *                            -------------------
 *   begin                :  Sep 17, 2003
 *   copyright            : (C) 2003 Niels Chr. Rød
 *   email                : ncr@db9.dk
 *   ver                  : 0.9.5
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   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.
 *
 ***************************************************************************/

define('IN_PHPBB', 1);

if( !empty($setmodules) )
{
	$file = basename(__FILE__);
	$module['Links']['Manage'] = $file;
	return;
}

//
// Load default header
//
$phpbb_root_path = "./../";
require($phpbb_root_path . 'extension.inc');
require('./pagestart.' . $phpEx);
//
include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_links.' . $phpEx);


//
// Mode setting
//
$mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] :
( (isset($HTTP_GET_VARS['mode']) ) ? $HTTP_GET_VARS['mode'] : '');

$cat = ( isset($HTTP_POST_VARS['cat']) ) ? intval($HTTP_POST_VARS['cat']) :
((isset($HTTP_GET_VARS['cat'])) ? intval($HTTP_GET_VARS['cat']) : 0);
$sub = ( isset($HTTP_POST_VARS['sub']) ) ? intval($HTTP_POST_VARS['sub']) :
((isset($HTTP_GET_VARS['sub'])) ? intval($HTTP_GET_VARS['sub']) : 0);
$id = ( isset($HTTP_POST_VARS['id']) ) ? intval($HTTP_POST_VARS['id']) :
((isset($HTTP_GET_VARS['id'])) ? intval($HTTP_GET_VARS['id']) : 0);

if ($mode=='delete')
{
	if ($sub==0 && $id==0)
	{
		//delete a complate cat
		$sql = "DELETE FROM ".LINKS_TABLE." WHERE link_cat=$cat";
	} else
	if ($id==0)
	{
		//delete a sub cat
		$sql = "DELETE FROM ".LINKS_TABLE." WHERE link_cat=$cat AND link_sub=$sub";
	} else
	{
		//delete a link
		$sql = "DELETE FROM ".LINKS_TABLE." WHERE link_cat=$cat AND link_sub=$sub AND link_id=$id";
	}
	if( !$result = $db->sql_query($sql) )
	{
		message_die(GENERAL_ERROR, "Couldn't delete links ", "", __LINE__, __FILE__, $sql);
	}
} else
if ($mode=="up" || $mode=="down")
{
	if ($sub==0 && $id==0)
	{
		//move a complate cat
		$update_field = "cat";
		$where_sql= "link_cat=";
	} else
	if ($id==0)
	{
		//move a sub cat
		$update_field = "sub";
		$where_sql= "link_cat=$cat AND link_sub=";
	} else
	{
		//move a link up
		$update_field = "id";
		$where_sql= "link_cat=$cat AND link_sub=$sub AND link_id=";
	}
	if ($mode=='up')
	{
		$dir="-1";
		if ($$update_field==1)
		{
			message_die(GENERAL_MESSAGE, "Can't move that");
		}
	} else
	{
		$dir="+1";
	}
	$sql_1 = "UPDATE ".LINKS_TABLE." SET link_$update_field='-1' WHERE $where_sql $$update_field $dir";
	eval("\$sql_1=\"$sql_1\";");
	$sql_2 = "UPDATE ".LINKS_TABLE." SET link_$update_field=link_$update_field $dir WHERE $where_sql $$update_field";
	eval("\$sql_2=\"$sql_2\";");
	$sql_3 = "UPDATE ".LINKS_TABLE." SET link_$update_field=$$update_field WHERE $where_sql '-1'";
	eval("\$sql_3=\"$sql_3\";");
	if( !$result = $db->sql_query($sql_1) )
	{
		message_die(GENERAL_ERROR, "Couldn't move $update_field step 1 ", "", __LINE__, __FILE__, $sql_1);
	}
	if( !$result = $db->sql_query($sql_2) )
	{
		message_die(GENERAL_ERROR, "Couldn't move $update_field step 2 ", "", __LINE__, __FILE__, $sql_2);
	}
	if( !$result = $db->sql_query($sql_3) )
	{
		message_die(GENERAL_ERROR, "Couldn't move $update_field step 3 ", "", __LINE__, __FILE__, $sql_3);
	}
} else
if ($mode=='edit_submit')
{
	$cat_old = ( isset($HTTP_POST_VARS['cat_old']) ) ? intval($HTTP_POST_VARS['cat_old']) :
	((isset($HTTP_GET_VARS['cat_old'])) ? intval($HTTP_GET_VARS['cat_old']) : 0);
	$sub_old = ( isset($HTTP_POST_VARS['sub_old']) ) ? intval($HTTP_POST_VARS['sub_old']) :
	((isset($HTTP_GET_VARS['sub_old'])) ? intval($HTTP_GET_VARS['sub_old']) : 0);
	$id_old = ( isset($HTTP_POST_VARS['id_old']) ) ? intval($HTTP_POST_VARS['id_old']) :
	((isset($HTTP_GET_VARS['id_old'])) ? intval($HTTP_GET_VARS['id_old']) : 0);


	$cat_sub =  (( isset($HTTP_POST_VARS['cat_sub']) ) ? $HTTP_POST_VARS['cat_sub'] :
		((isset($HTTP_GET_VARS['cat_sub'])) ? $HTTP_GET_VARS['cat_sub'] : '0,0'));
	list($cat,$sub)  = explode(",",$cat_sub);

	$cat_sub_sql = (isset($HTTP_POST_VARS['cat_sub']) || isset($HTTP_GET_VARS['cat_sub'])) ? ", link_cat='$cat', link_sub='$sub'" : "";

	$link_name = ( isset($HTTP_POST_VARS['link_name']) ) ? $HTTP_POST_VARS['link_name'] :
	((isset($HTTP_GET_VARS['link_name'])) ? $HTTP_GET_VARS['link_name'] : 0);

	$link_level = ( isset($HTTP_POST_VARS['link_level']) ) ? intval($HTTP_POST_VARS['link_level']) :
	((isset($HTTP_GET_VARS['link_level'])) ? intval($HTTP_GET_VARS['link_level']) : 0);
	$link_level_type = ( isset($HTTP_POST_VARS['link_level_type']) ) ? intval($HTTP_POST_VARS['link_level_type']) :
	((isset($HTTP_GET_VARS['link_level_type'])) ? intval($HTTP_GET_VARS['link_level_type']) : 0);
	$level_sql = (isset($HTTP_POST_VARS['link_level']) || isset($HTTP_GET_VARS['link_level'])) ?
	", link_level='$link_level', link_level_type='$link_level_type'" : "";

	$active_sql = (isset($HTTP_POST_VARS['link_active'])) ? "link_active='".(( $HTTP_POST_VARS['link_active'] == 1 ) ? TRUE : 0)."'," : "";

	$link_url = ( isset($HTTP_POST_VARS['link_url']) ) ? $HTTP_POST_VARS['link_url'] :
	((isset($HTTP_GET_VARS['link_url'])) ? $HTTP_GET_VARS['link_url'] : '');
	$url_sql = ( isset($HTTP_POST_VARS['link_url']) || isset($HTTP_GET_VARS['link_url'])) ? ", link_url='".addslashes($link_url)."'" : "";


	$sql="UPDATE ".LINKS_TABLE." SET $active_sql
	link_name='".addslashes($link_name)."' $url_sql $level_sql $cat_sub_sql
	WHERE link_cat='$cat_old' AND link_sub='$sub_old' AND link_id='$id_old'";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Couldn't update cat/sub/link", "", __LINE__, __FILE__, $sql);
	}
	// if this was a sub cat, then move links if needed
	if ($cat!=$cat_old && !$id_old)
	{
		$sql="UPDATE ".LINKS_TABLE." SET link_cat='$cat', link_sub='$sub' WHERE link_cat='$cat_old' AND link_sub='$sub_old'";
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, "Couldn't move links to new cat", "", __LINE__, __FILE__, $sql);
		}
	}
} else
if ($mode=='new_link')
{
	$link_name = ( isset($HTTP_POST_VARS['link_name']) ) ? $HTTP_POST_VARS['link_name'] :
	((isset($HTTP_GET_VARS['link_name'])) ? $HTTP_GET_VARS['link_name'] : 0);
	$sql="SELECT MAX(link_cat) as cat, MAX(link_sub) as sub, max(link_id) as id FROM ".LINKS_TABLE." WHERE link_cat>0 AND link_sub>0 GROUP BY link_cat ORDER BY link_cat DESC LIMIT 1";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Couldn't fetch cat/sub/link count info", "", __LINE__, __FILE__, $sql);
	}
	if ($db->sql_numrows())
	{
		$count_info = $db->sql_fetchrow($result);
	} else
	{
		message_die(GENERAL_ERROR, "It seams, that you are trying to add a link when no sub category exist, please add one as the first");
	} 

	$sql = "INSERT INTO ". LINKS_TABLE ." (link_active, link_level, link_level_type, link_name, link_cat, link_sub, link_id) VALUES ('0','-1','2','".addslashes($link_name)."' ,".intval($count_info['cat']).",".intval($count_info['sub']).",".($count_info['id']+1).")";

	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Couldn't insert new link", "", __LINE__, __FILE__, $sql);
	}
} else
if ($mode=='new_sub')
{
	$link_name = ( isset($HTTP_POST_VARS['link_name']) ) ? $HTTP_POST_VARS['link_name'] :
	((isset($HTTP_GET_VARS['link_name'])) ? $HTTP_GET_VARS['link_name'] : 0);
	$sql="SELECT MAX(link_cat) as cat, MAX(link_sub) as sub, max(link_id) as id FROM ".LINKS_TABLE." GROUP BY link_cat ORDER BY link_cat DESC LIMIT 1";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Couldn't fetch cat/sub/link count info", "", __LINE__, __FILE__, $sql);
	}

	if ($db->sql_numrows())
	{
		$count_info = $db->sql_fetchrow($result);
	} else
	{
		message_die(GENERAL_ERROR, "It seams, that you are trying to add a sub category when no category exist, please add one as the first");
	}
	$sql = "INSERT INTO ". LINKS_TABLE ." (link_active, link_level, link_level_type, link_name, link_cat, link_sub, link_id) VALUES ('1','-1','2','".addslashes($link_name)."' ,".$count_info['cat'].",".($count_info['sub']+1).",'0')";

	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Couldn't insert new sub", "", __LINE__, __FILE__, $sql);
	}
} else
if ($mode=='new_cat')
{
	$link_name = ( isset($HTTP_POST_VARS['link_name']) ) ? $HTTP_POST_VARS['link_name'] :
	((isset($HTTP_GET_VARS['link_name'])) ? $HTTP_GET_VARS['link_name'] : 0);
	$sql="SELECT MAX(link_cat) as cat, MAX(link_sub) as sub, max(link_id) as id FROM ".LINKS_TABLE." GROUP BY link_cat ORDER BY link_cat DESC LIMIT 1";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Couldn't fetch cat/sub/link count info", "", __LINE__, __FILE__, $sql);
	}
	$count_info = $db->sql_fetchrow($result);

	$sql = "INSERT INTO ". LINKS_TABLE ." (link_active, link_level, link_level_type, link_name, link_cat, link_sub, link_id) VALUES ('1','-1','2','".addslashes($link_name)."' ,".($count_info['cat']+1).",'0','0')";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Couldn't insert new cat", "", __LINE__, __FILE__, $sql);
	}
}




if ($mode=='edit')
{
	// get the link
	$sql="SELECT * FROM ".LINKS_TABLE." WHERE link_cat='$cat' AND link_sub='$sub' AND link_id='$id'";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Couldn't query links cat", "", __LINE__, __FILE__, $sql);
	}
	$link_info = $db->sql_fetchrow($result);
	$sql="SELECT link_cat as cat, MAX(link_sub) as sub, max(link_id) as id FROM ".LINKS_TABLE." GROUP BY link_cat";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Couldn't fetch cat/sub/link count info", "", __LINE__, __FILE__, $sql);
	}
	while($temp = $db->sql_fetchrow($result))
	{
		$count_info[$temp['cat']] = $temp;
	}

	// get all cat/sub's
	$sql="SELECT * FROM ".LINKS_TABLE." WHERE link_id=0 ORDER BY link_cat, link_sub";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, "Couldn't query links cat", "", __LINE__, __FILE__, $sql);
	}
	$cat_select = '<select name="cat_sub">';
	while ( $row = $db->sql_fetchrow($result) )
	{
		if ($row['link_sub']==0 && $row['link_name']!=$cat_name)
		{
			$cat_name =  $row['link_name'];
			if (!$link_info['link_id'])
			{
				$selected = ( $row['link_cat'] == $cat ) ? ' selected="selected">* ' : '>';
				$sub_value = ($row['link_cat']==$link_info['link_cat']) ? $link_info['link_sub'] : ($count_info[$row['link_cat']]['sub']+1);
				$cat_select .= '<option value="' . $row['link_cat'].',' .$sub_value .'"' . $selected . $cat_name  . '</option>';
			}
		} else
		{
			if ($link_info['link_id'])
			{
				$selected = ( $row['link_cat'].','.$row['link_sub'] == $cat.','.$sub ) ? ' selected="selected">* ' : '>';
				$cat_select .= '<option value="' . $row['link_cat'].',' .$row['link_sub']. '"' . $selected . $cat_name .' - '.$row['link_name'] . '</option>';
			}
		}
	}
	$cat_select .= "</select>";

	$n='-1';
	$s_level='<select name="link_level">';
	while ( $lang['Link_level'][$n] )
	{
		$s_level.= ( $link_info['link_level']==$n ) ? 
		'<option value="'.$n.'" SELECTED>* '.$lang['Link_level'][$n] : 
		'<option value="'.$n.'" >'.$lang['Link_level'][$n];
		$n++;
	}
	$s_level .='</select>';			
	$n=0;
	$s_level_type = '<select name="link_level_type">';
	while ( $lang['Link_level_type'][$n] )
	{
	$s_level_type.= ( $link_info['link_level_type']==$n ) ? 
		'<option value="'.$n.'" SELECTED>* '.$lang['Link_level_type'][$n] : 
		'<option value="'.$n.'" >'.$lang['Link_level_type'][$n];
		$n++;
	}
	$s_level_type .='</select>';			
	$link_is_active = ( $link_info['link_active'] ) ? "checked=\"checked\"" : "";
	$link_is_not_active = ( !$link_info['link_active'] ) ? "checked=\"checked\"" : "";

	$hidden_fields = '<input type="hidden" name="mode" value="edit_submit" />';
	$hidden_fields .= '<input type="hidden" name="cat_old" value="' . $cat . '" />';
	$hidden_fields .= '<input type="hidden" name="sub_old" value="' . $sub . '" />';
	$hidden_fields .= '<input type="hidden" name="id_old" value="' . $id . '" />';
	$template->set_filenames(array( 
		'body' => 'admin/link_edit_body.tpl'));
	// enable extra if sub or link
	if ($link_info['link_sub'])
	{
		$template->assign_block_vars('switch_limit_2', array());
		// enable extra if link
		if ($link_info['link_id'])
		{
			$template->assign_block_vars('switch_limit', array());
		}
	}


	$template->assign_vars(array( 
		'L_LINK_TITLE' => $lang['Edit'],
		'L_LINK_EXPLAIN' => ($link_info['link_id']==0) ? (($link_info['link_sub']==0) ? $lang['Link_edit_cat_explain'] : $lang['Link_edit_sub_explain'] ) : $lang['Link_edit_explain'],
		'L_LINK_NAME' => $lang['Link_name'],
		'L_LINK_URL' => $lang['Link_url'],
		'L_LINK_URL_EXPLAIN' => $lang['Link_url_explain'],
		'L_SUBMIT' => $lang['Submit'],
		'L_RESET' => $lang['Reset'],
		'L_YES' => $lang['Yes'],
		'L_NO' => $lang['No'],
		'L_CATEGORY' => $lang['Link_category'],

		'L_LINK_ACTIVATE' => $lang['Link_activate'], 
		'LINK_NOT_ACTIVE' => $link_is_not_active,
		'LINK_ACTIVE' => $link_is_active,
		'LINK_URL' => $link_info['link_url'],
		'LINK_NAME' => $link_info['link_name'],

		'S_CAT_LIST' => $cat_select,
		'S_HIDDEN_FIELDS' => $hidden_fields,
		'L_LINK_SHOW_TO' => $lang['Show_to_users'],
		'L_LINK_SHOW_TO_EXPLAIN' => $lang['Show_to_users_explain'],
		'S_LINK_SHOW_TO' => sprintf($lang['Show_to_users_select'],$s_level_type,$s_level)
	));

} else
{
	$template->set_filenames(array( 
		'body' => 'admin/links_body.tpl'));

	$template->assign_vars(array( 
		'L_NEW_CAT' => $lang['Link_add_cat'],
		'L_NEW_SUB' => $lang['Link_add_sub'],
		'L_NEW_LINK' => $lang['Link_add_link'],
		'L_SUBMIT' => $lang['Submit'],
	
		'L_LINKS' => $lang['Links'],
		'L_EDIT' => $lang['Edit'], 
		'L_DELETE' => $lang['Delete'], 
		'L_DOWN' => $lang['Move_down'],
		'L_UP' => $lang['Move_up'],
		'S_NEW_LINK' => append_sid("admin_links.$phpEx?mode=new_link&$identifyer"),
		'S_NEW_SUB' => append_sid("admin_links.$phpEx?mode=new_sub&$identifyer"),
		'S_NEW_CAT' => append_sid("admin_links.$phpEx?mode=new_cat&$identifyer")
	));
	$sql = "SELECT * FROM ".LINKS_TABLE." ORDER BY link_cat , link_sub, link_id";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not get shoutbox information', '', __LINE__, __FILE__, $sql);
	}
	$links = $db->sql_fetchrowset($result);
	$i=0;
	if (!empty($links))
	{
		while (list ($id,$link) = each($links))
		{
			if ($link['link_id']==0)
			{
				if ($link['link_sub']==0)
				{
					// new cat
					$template->assign_block_vars('row', array());
					$identifyer = "id=".$link['link_id']."&cat=".$link['link_cat']."&sub=".$link['link_sub'];
					$template->assign_block_vars('row.cat', array(
						'CAT_NAME' => $link['link_name'],
						'DELETE' => append_sid("admin_links.$phpEx?mode=delete&$identifyer"),
						'EDIT' => append_sid("admin_links.$phpEx?mode=edit&$identifyer"),
						'UP' => append_sid("admin_links.$phpEx?mode=up&$identifyer"),
						'DOWN' => append_sid("admin_links.$phpEx?mode=down&$identifyer")));
				} else
				{
					$identifyer = "id=".$link['link_id']."&cat=".$link['link_cat']."&sub=".$link['link_sub'];
					$template->assign_block_vars('row.cat.sub', array(
						'SUB_NAME' => $link['link_name'],
						'DELETE' => append_sid("admin_links.$phpEx?mode=delete&$identifyer"),
						'EDIT' => append_sid("admin_links.$phpEx?mode=edit&$identifyer"),
						'UP' => append_sid("admin_links.$phpEx?mode=up&$identifyer"),
						'DOWN' => append_sid("admin_links.$phpEx?mode=down&$identifyer")));
				}
			} else
			{
				$l_id++;
				$identifyer = "id=".$link['link_id']."&cat=".$link['link_cat']."&sub=".$link['link_sub'];
				$row_color = ( !($l_id % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
				$row_class = ( !($l_id % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
				$template->assign_block_vars('row.cat.sub.link', array(
					'LINK_NAME' => $link['link_name'],
					'LINK_URL' => $link['link_url'],
					'DELETE' => append_sid("admin_links.$phpEx?mode=delete&$identifyer"),
					'EDIT' => append_sid("admin_links.$phpEx?mode=edit&$identifyer"),
					'UP' => append_sid("admin_links.$phpEx?mode=up&$identifyer"),
					'DOWN' => append_sid("admin_links.$phpEx?mode=down&$identifyer"),
					'ROW_COLOR' => '#' . $row_color,
					'ROW_CLASS' => $row_class));
			}	
		}
	}
}
$template->pparse('body');
include('./page_footer_admin.'.$phpEx);

?>

thx bee effe kijken wat hij heeft veranderd :D

Geplaatst: 17 mar 2005, 10:13
door Luuk
Uhm, dit ziet er meer uit als admin_links.php :lol:

Geplaatst: 17 mar 2005, 10:35
door PHP Freak
srry verkeerde :oops:

Code: Selecteer alles

<?php
/***************************************************************************
*                             admin_db_utilities.php
*                              -------------------
*     begin                : Thu May 31, 2001
*     copyright            : (C) 2001 The phpBB Group
*     email                : support@phpbb.com
*
*     $Id: admin_db_utilities.php,v 1.42.2.10 2003/03/04 21:02:19 acydburn Exp $
*
****************************************************************************/

/***************************************************************************
 *
 *   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.
 *
 ***************************************************************************/

/***************************************************************************
*	We will attempt to create a file based backup of all of the data in the
*	users phpBB database.  The resulting file should be able to be imported by
*	the db_restore.php function, or by using the mysql command_line
*
*	Some functions are adapted from the upgrade_20.php script and others
*	adapted from the unoficial phpMyAdmin 2.2.0.
***************************************************************************/

define('IN_PHPBB', 1);

if( !empty($setmodules) )
{
	$filename = basename(__FILE__);
	$module['General']['Backup_DB'] = $filename . "?perform=backup";

	$file_uploads = (@phpversion() >= '4.0.0') ? @ini_get('file_uploads') : @get_cfg_var('file_uploads');

	if( (empty($file_uploads) || $file_uploads != 0) && (strtolower($file_uploads) != 'off') && (@phpversion() != '4.0.4pl1') )
	{
		$module['General']['Restore_DB'] = $filename . "?perform=restore";
	}

	return;
}

//
// Load default header
//
$no_page_header = TRUE;
$phpbb_root_path = "./../";
require($phpbb_root_path . 'extension.inc');
require('./pagestart.' . $phpEx);
include($phpbb_root_path . 'includes/sql_parse.'.$phpEx);

//
// Set VERBOSE to 1  for debugging info..
//
define("VERBOSE", 0);

//
// Increase maximum execution time, but don't complain about it if it isn't
// allowed.
//
@set_time_limit(1200);

// -----------------------
// The following functions are adapted from phpMyAdmin and upgrade_20.php
//
function gzip_PrintFourChars($Val)
{
	for ($i = 0; $i < 4; $i ++)
	{
		$return .= chr($Val % 256);
		$Val = floor($Val / 256);
	}
	return $return;
} 



//
// This function is used for grabbing the sequences for postgres...
//
function pg_get_sequences($crlf, $backup_type)
{
	global $db;

	$get_seq_sql = "SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*'
		AND relkind = 'S' ORDER BY relname";

	$seq = $db->sql_query($get_seq_sql);

	if( !$num_seq = $db->sql_numrows($seq) )
	{

		$return_val = "# No Sequences Found $crlf";

	}
	else
	{
		$return_val = "# Sequences $crlf";
		$i_seq = 0;

		while($i_seq < $num_seq)
		{
			$row = $db->sql_fetchrow($seq);
			$sequence = $row['relname'];

			$get_props_sql = "SELECT * FROM $sequence";
			$seq_props = $db->sql_query($get_props_sql);

			if($db->sql_numrows($seq_props) > 0)
			{
				$row1 = $db->sql_fetchrow($seq_props);

				if($backup_type == 'structure')
				{
					$row['last_value'] = 1;
				}

				$return_val .= "CREATE SEQUENCE $sequence start " . $row['last_value'] . ' increment ' . $row['increment_by'] . ' maxvalue ' . $row['max_value'] . ' minvalue ' . $row['min_value'] . ' cache ' . $row['cache_value'] . "; $crlf";

			}  // End if numrows > 0

			if(($row['last_value'] > 1) && ($backup_type != 'structure'))
			{
				$return_val .= "SELECT NEXTVALE('$sequence'); $crlf";
				unset($row['last_value']);
			}

			$i_seq++;

		} // End while..

	} // End else...

	return $returnval;

} // End function...

//
// The following functions will return the "CREATE TABLE syntax for the
// varying DBMS's
//
// This function returns, will return the table def's for postgres...
//
function get_table_def_postgresql($table, $crlf)
{
	global $drop, $db;

	$schema_create = "";
	//
	// Get a listing of the fields, with their associated types, etc.
	//

	$field_query = "SELECT a.attnum, a.attname AS field, t.typname as type, a.attlen AS length, a.atttypmod as lengthvar, a.attnotnull as notnull
		FROM pg_class c, pg_attribute a, pg_type t
		WHERE c.relname = '$table'
			AND a.attnum > 0
			AND a.attrelid = c.oid
			AND a.atttypid = t.oid
		ORDER BY a.attnum";
	$result = $db->sql_query($field_query);

	if(!$result)
	{
		message_die(GENERAL_ERROR, "Failed in get_table_def (show fields)", "", __LINE__, __FILE__, $field_query);
	} // end if..

	if ($drop == 1)
	{
		$schema_create .= "DROP TABLE $table;$crlf";
	} // end if

	//
	// Ok now we actually start building the SQL statements to restore the tables
	//

	$schema_create .= "CREATE TABLE $table($crlf";

	while ($row = $db->sql_fetchrow($result))
	{
		//
		// Get the data from the table
		//
		$sql_get_default = "SELECT d.adsrc AS rowdefault
			FROM pg_attrdef d, pg_class c
			WHERE (c.relname = '$table')
				AND (c.oid = d.adrelid)
				AND d.adnum = " . $row['attnum'];
		$def_res = $db->sql_query($sql_get_default);

		if (!$def_res)
		{
			unset($row['rowdefault']);
		}
		else
		{
			$row['rowdefault'] = @pg_result($def_res, 0, 'rowdefault');
		}

		if ($row['type'] == 'bpchar')
		{
			// Internally stored as bpchar, but isn't accepted in a CREATE TABLE statement.
			$row['type'] = 'char';
		}

		$schema_create .= '	' . $row['field'] . ' ' . $row['type'];

		if (eregi('char', $row['type']))
		{
			if ($row['lengthvar'] > 0)
			{
				$schema_create .= '(' . ($row['lengthvar'] -4) . ')';
			}
		}

		if (eregi('numeric', $row['type']))
		{
			$schema_create .= '(';
			$schema_create .= sprintf("%s,%s", (($row['lengthvar'] >> 16) & 0xffff), (($row['lengthvar'] - 4) & 0xffff));
			$schema_create .= ')';
		}

		if (!empty($row['rowdefault']))
		{
			$schema_create .= ' DEFAULT ' . $row['rowdefault'];
		}

		if ($row['notnull'] == 't')
		{
			$schema_create .= ' NOT NULL';
		}

		$schema_create .= ",$crlf";

	}
	//
	// Get the listing of primary keys.
	//

	$sql_pri_keys = "SELECT ic.relname AS index_name, bc.relname AS tab_name, ta.attname AS column_name, i.indisunique AS unique_key, i.indisprimary AS primary_key
		FROM pg_class bc, pg_class ic, pg_index i, pg_attribute ta, pg_attribute ia
		WHERE (bc.oid = i.indrelid)
			AND (ic.oid = i.indexrelid)
			AND (ia.attrelid = i.indexrelid)
			AND	(ta.attrelid = bc.oid)
			AND (bc.relname = '$table')
			AND (ta.attrelid = i.indrelid)
			AND (ta.attnum = i.indkey[ia.attnum-1])
		ORDER BY index_name, tab_name, column_name ";
	$result = $db->sql_query($sql_pri_keys);

	if(!$result)
	{
		message_die(GENERAL_ERROR, "Failed in get_table_def (show fields)", "", __LINE__, __FILE__, $sql_pri_keys);
	}

	while ( $row = $db->sql_fetchrow($result))
	{
		if ($row['primary_key'] == 't')
		{
			if (!empty($primary_key))
			{
				$primary_key .= ', ';
			}

			$primary_key .= $row['column_name'];
			$primary_key_name = $row['index_name'];

		}
		else
		{
			//
			// We have to store this all this info because it is possible to have a multi-column key...
			// we can loop through it again and build the statement
			//
			$index_rows[$row['index_name']]['table'] = $table;
			$index_rows[$row['index_name']]['unique'] = ($row['unique_key'] == 't') ? ' UNIQUE ' : '';
			$index_rows[$row['index_name']]['column_names'] .= $row['column_name'] . ', ';
		}
	}

	if (!empty($index_rows))
	{
		while(list($idx_name, $props) = each($index_rows))
		{
			$props['column_names'] = ereg_replace(", $", "" , $props['column_names']);
			$index_create .= 'CREATE ' . $props['unique'] . " INDEX $idx_name ON $table (" . $props['column_names'] . ");$crlf";
		}
	}

	if (!empty($primary_key))
	{
		$schema_create .= "	CONSTRAINT $primary_key_name PRIMARY KEY ($primary_key),$crlf";
	}

	//
	// Generate constraint clauses for CHECK constraints
	//
	$sql_checks = "SELECT rcname as index_name, rcsrc
		FROM pg_relcheck, pg_class bc
		WHERE rcrelid = bc.oid
			AND bc.relname = '$table'
			AND NOT EXISTS (
				SELECT *
					FROM pg_relcheck as c, pg_inherits as i
					WHERE i.inhrelid = pg_relcheck.rcrelid
						AND c.rcname = pg_relcheck.rcname
						AND c.rcsrc = pg_relcheck.rcsrc
						AND c.rcrelid = i.inhparent
			)";
	$result = $db->sql_query($sql_checks);

	if (!$result)
	{
		message_die(GENERAL_ERROR, "Failed in get_table_def (show fields)", "", __LINE__, __FILE__, $sql_checks);
	}

	//
	// Add the constraints to the sql file.
	//
	while ($row = $db->sql_fetchrow($result))
	{
		$schema_create .= '	CONSTRAINT ' . $row['index_name'] . ' CHECK ' . $row['rcsrc'] . ",$crlf";
	}

	$schema_create = ereg_replace(',' . $crlf . '$', '', $schema_create);
	$index_create = ereg_replace(',' . $crlf . '$', '', $index_create);

	$schema_create .= "$crlf);$crlf";

	if (!empty($index_create))
	{
		$schema_create .= $index_create;
	}

	//
	// Ok now we've built all the sql return it to the calling function.
	//
	return (stripslashes($schema_create));

}

//
// This function returns the "CREATE TABLE" syntax for mysql dbms...
//
function get_table_def_mysql($table, $crlf)
{
	global $drop, $db;

	$schema_create = "";
	$field_query = "SHOW FIELDS FROM $table";
	$key_query = "SHOW KEYS FROM $table";

	//
	// If the user has selected to drop existing tables when doing a restore.
	// Then we add the statement to drop the tables....
	//
	if ($drop == 1)
	{
		$schema_create .= "DROP TABLE IF EXISTS $table;$crlf";
	}

	$schema_create .= "CREATE TABLE $table($crlf";

	//
	// Ok lets grab the fields...
	//
	$result = $db->sql_query($field_query);
	if(!$result)
	{
		message_die(GENERAL_ERROR, "Failed in get_table_def (show fields)", "", __LINE__, __FILE__, $field_query);
	}

	while ($row = $db->sql_fetchrow($result))
	{
		$schema_create .= '	' . $row['Field'] . ' ' . $row['Type'];

		if(!empty($row['Default']))
		{
			$schema_create .= ' DEFAULT \'' . $row['Default'] . '\'';
		}

		if($row['Null'] != "YES")
		{
			$schema_create .= ' NOT NULL';
		}

		if($row['Extra'] != "")
		{
			$schema_create .= ' ' . $row['Extra'];
		}

		$schema_create .= ",$crlf";
	}
	//
	// Drop the last ',$crlf' off ;)
	//
	$schema_create = ereg_replace(',' . $crlf . '$', "", $schema_create);

	//
	// Get any Indexed fields from the database...
	//
	$result = $db->sql_query($key_query);
	if(!$result)
	{
		message_die(GENERAL_ERROR, "FAILED IN get_table_def (show keys)", "", __LINE__, __FILE__, $key_query);
	}

	while($row = $db->sql_fetchrow($result))
	{
		$kname = $row['Key_name'];

		if(($kname != 'PRIMARY') && ($row['Non_unique'] == 0))
		{
			$kname = "UNIQUE|$kname";
		}

		if(!is_array($index[$kname]))
		{
			$index[$kname] = array();
		}

		$index[$kname][] = $row['Column_name'];
	}

	while(list($x, $columns) = @each($index))
	{
		$schema_create .= ", $crlf";

		if($x == 'PRIMARY')
		{
			$schema_create .= '	PRIMARY KEY (' . implode($columns, ', ') . ')';
		}
		elseif (substr($x,0,6) == 'UNIQUE')
		{
			$schema_create .= '	UNIQUE ' . substr($x,7) . ' (' . implode($columns, ', ') . ')';
		}
		else
		{
			$schema_create .= "	KEY $x (" . implode($columns, ', ') . ')';
		}
	}

	$schema_create .= "$crlf);";

	if(get_magic_quotes_runtime())
	{
		return(stripslashes($schema_create));
	}
	else
	{
		return($schema_create);
	}

} // End get_table_def_mysql


//
// This fuction will return a tables create definition to be used as an sql
// statement.
//
//
// The following functions Get the data from the tables and format it as a
// series of INSERT statements, for each different DBMS...
// After every row a custom callback function $handler gets called.
// $handler must accept one parameter ($sql_insert);
//
//
// Here is the function for postgres...
//
function get_table_content_postgresql($table, $handler)
{
	global $db;

	//
	// Grab all of the data from current table.
	//

	$result = $db->sql_query("SELECT * FROM $table");

	if (!$result)
	{
		message_die(GENERAL_ERROR, "Failed in get_table_content (select *)", "", __LINE__, __FILE__, "SELECT * FROM $table");
	}

	$i_num_fields = $db->sql_numfields($result);

	for ($i = 0; $i < $i_num_fields; $i++)
	{
		$aryType[] = $db->sql_fieldtype($i, $result);
		$aryName[] = $db->sql_fieldname($i, $result);
	}

	$iRec = 0;

	while($row = $db->sql_fetchrow($result))
	{
		unset($schema_vals);
		unset($schema_fields);
		unset($schema_insert);
		//
		// Build the SQL statement to recreate the data.
		//
		for($i = 0; $i < $i_num_fields; $i++)
		{
			$strVal = $row[$aryName[$i]];
			if (eregi("char|text|bool", $aryType[$i]))
			{
				$strQuote = "'";
				$strEmpty = "";
				$strVal = addslashes($strVal);
			}
			elseif (eregi("date|timestamp", $aryType[$i]))
			{
				if ($empty($strVal))
				{
					$strQuote = "";
				}
				else
				{
					$strQuote = "'";
				}
			}
			else
			{
				$strQuote = "";
				$strEmpty = "NULL";
			}

			if (empty($strVal) && $strVal != "0")
			{
				$strVal = $strEmpty;
			}

			$schema_vals .= " $strQuote$strVal$strQuote,";
			$schema_fields .= " $aryName[$i],";

		}

		$schema_vals = ereg_replace(",$", "", $schema_vals);
		$schema_vals = ereg_replace("^ ", "", $schema_vals);
		$schema_fields = ereg_replace(",$", "", $schema_fields);
		$schema_fields = ereg_replace("^ ", "", $schema_fields);

		//
		// Take the ordered fields and their associated data and build it
		// into a valid sql statement to recreate that field in the data.
		//
		$schema_insert = "INSERT INTO $table ($schema_fields) VALUES($schema_vals);";

		$handler(trim($schema_insert));
	}

	return(true);

}// end function get_table_content_postgres...

//
// This function is for getting the data from a mysql table.
//

function get_table_content_mysql($table, $handler)
{
	global $db;

	// Grab the data from the table.
	if (!($result = $db->sql_query("SELECT * FROM $table")))
	{
		message_die(GENERAL_ERROR, "Failed in get_table_content (select *)", "", __LINE__, __FILE__, "SELECT * FROM $table");
	}

	// Loop through the resulting rows and build the sql statement.
	if ($row = $db->sql_fetchrow($result))
	{
		$handler("\n#\n# Table Data for $table\n#\n");
		$field_names = array();

		// Grab the list of field names.
		$num_fields = $db->sql_numfields($result);
		$table_list = '(';
		for ($j = 0; $j < $num_fields; $j++)
		{
			$field_names[$j] = $db->sql_fieldname($j, $result);
			$table_list .= (($j > 0) ? ', ' : '') . $field_names[$j];
			
		}
		$table_list .= ')';

		do
		{
			// Start building the SQL statement.
			$schema_insert = "INSERT INTO $table $table_list VALUES(";

			// Loop through the rows and fill in data for each column
			for ($j = 0; $j < $num_fields; $j++)
			{
				$schema_insert .= ($j > 0) ? ', ' : '';

				if(!isset($row[$field_names[$j]]))
				{
					//
					// If there is no data for the column set it to null.
					// There was a problem here with an extra space causing the
					// sql file not to reimport if the last column was null in
					// any table.  Should be fixed now :) JLH
					//
					$schema_insert .= 'NULL';
				}
				elseif ($row[$field_names[$j]] != '')
				{
					$schema_insert .= '\'' . addslashes($row[$field_names[$j]]) . '\'';
				}
				else
				{
					$schema_insert .= '\'\'';
				}
			}

			$schema_insert .= ');';

			// Go ahead and send the insert statement to the handler function.
			$handler(trim($schema_insert));

		}
		while ($row = $db->sql_fetchrow($result));
	}

	return(true);
}

function output_table_content($content)
{
	global $tempfile;

	//fwrite($tempfile, $content . "\n");
	//$backup_sql .= $content . "\n";
	echo $content ."\n";
	return;
}
//
// End Functions
// -------------


//
// Begin program proper
//
if( isset($HTTP_GET_VARS['perform']) || isset($HTTP_POST_VARS['perform']) )
{
	$perform = (isset($HTTP_POST_VARS['perform'])) ? $HTTP_POST_VARS['perform'] : $HTTP_GET_VARS['perform'];

	switch($perform)
	{
		case 'backup':

			$error = false;
			switch(SQL_LAYER)
			{
				case 'oracle':
					$error = true;
					break;
				case 'db2':
					$error = true;
					break;
				case 'msaccess':
					$error = true;
					break;
				case 'mssql':
				case 'mssql-odbc':
					$error = true;
					break;
			}

			if ($error)
			{
				include('./page_header_admin.'.$phpEx);

				$template->set_filenames(array(
					"body" => "admin/admin_message_body.tpl")
				);

				$template->assign_vars(array(
					"MESSAGE_TITLE" => $lang['Information'],
					"MESSAGE_TEXT" => $lang['Backups_not_supported'])
				);

				$template->pparse("body");

				include('./page_footer_admin.'.$phpEx);
			}
			$tables = array($tables[] = 'links';'auth_access', 'banlist', 'categories', 'config', 'disallow', 'forums', 'forum_prune', 'groups', 'posts', 'posts_text', 'privmsgs', 'privmsgs_text', 'ranks', 'search_results', 'search_wordlist', 'search_wordmatch', 'sessions', 'smilies', 'themes', 'themes_name', 'topics', 'topics_watch', 'user_group', 'users', 'vote_desc', 'vote_results', 'vote_voters', 'words');
                                                $tables[] = 'shout';

			$additional_tables = (isset($HTTP_POST_VARS['additional_tables'])) ? $HTTP_POST_VARS['additional_tables'] : ( (isset($HTTP_GET_VARS['additional_tables'])) ? $HTTP_GET_VARS['additional_tables'] : "" );

			$backup_type = (isset($HTTP_POST_VARS['backup_type'])) ? $HTTP_POST_VARS['backup_type'] : ( (isset($HTTP_GET_VARS['backup_type'])) ? $HTTP_GET_VARS['backup_type'] : "" );

			$gzipcompress = (!empty($HTTP_POST_VARS['gzipcompress'])) ? $HTTP_POST_VARS['gzipcompress'] : ( (!empty($HTTP_GET_VARS['gzipcompress'])) ? $HTTP_GET_VARS['gzipcompress'] : 0 );

			$drop = (!empty($HTTP_POST_VARS['drop'])) ? intval($HTTP_POST_VARS['drop']) : ( (!empty($HTTP_GET_VARS['drop'])) ? intval($HTTP_GET_VARS['drop']) : 0 );

			if(!empty($additional_tables))
			{
				if(ereg(",", $additional_tables))
				{
					$additional_tables = split(",", $additional_tables);

					for($i = 0; $i < count($additional_tables); $i++)
					{
						$tables[] = trim($additional_tables[$i]);
					}

				}
				else
				{
					$tables[] = trim($additional_tables);
				}
			}

			if( !isset($HTTP_POST_VARS['backupstart']) && !isset($HTTP_GET_VARS['backupstart']))
			{
				include('./page_header_admin.'.$phpEx);

				$template->set_filenames(array(
					"body" => "admin/db_utils_backup_body.tpl")
				);	
				$s_hidden_fields = "<input type=\"hidden\" name=\"perform\" value=\"backup\" /><input type=\"hidden\" name=\"drop\" value=\"1\" /><input type=\"hidden\" name=\"perform\" value=\"$perform\" />";

				$template->assign_vars(array(
					"L_DATABASE_BACKUP" => $lang['Database_Utilities'] . " : " . $lang['Backup'],
					"L_BACKUP_EXPLAIN" => $lang['Backup_explain'],
					"L_FULL_BACKUP" => $lang['Full_backup'],
					"L_STRUCTURE_BACKUP" => $lang['Structure_backup'],
					"L_DATA_BACKUP" => $lang['Data_backup'],
					"L_ADDITIONAL_TABLES" => $lang['Additional_tables'],
					"L_START_BACKUP" => $lang['Start_backup'],
					"L_BACKUP_OPTIONS" => $lang['Backup_options'],
					"L_GZIP_COMPRESS" => $lang['Gzip_compress'],
					"L_NO" => $lang['No'],
					"L_YES" => $lang['Yes'],

					"S_HIDDEN_FIELDS" => $s_hidden_fields,
					"S_DBUTILS_ACTION" => append_sid("admin_db_utilities.$phpEx"))
				);
				$template->pparse("body");

				break;

			}
			else if( !isset($HTTP_POST_VARS['startdownload']) && !isset($HTTP_GET_VARS['startdownload']) )
			{
				if(is_array($additional_tables))
				{
					$additional_tables = implode(',', $additional_tables);
				}
				$template->set_filenames(array(
					"body" => "admin/admin_message_body.tpl")
				);

				$template->assign_vars(array(
					"META" => '<meta http-equiv="refresh" content="2;url=' . append_sid("admin_db_utilities.$phpEx?perform=backup&additional_tables=" . quotemeta($additional_tables) . "&backup_type=$backup_type&drop=1&backupstart=1&gzipcompress=$gzipcompress&startdownload=1") . '">',

					"MESSAGE_TITLE" => $lang['Database_Utilities'] . " : " . $lang['Backup'],
					"MESSAGE_TEXT" => $lang['Backup_download'])
				);

				include('./page_header_admin.'.$phpEx);

				$template->pparse("body");

				include('./page_footer_admin.'.$phpEx);

			}
			header("Pragma: no-cache");
			$do_gzip_compress = FALSE;
			if( $gzipcompress )
			{
				$phpver = phpversion();

				if($phpver >= "4.0")
				{
					if(extension_loaded("zlib"))
					{
						$do_gzip_compress = TRUE;
					}
				}
			}
			if($do_gzip_compress)
			{
				@ob_start();
				@ob_implicit_flush(0);
				header("Content-Type: application/x-gzip; name=\"phpbb_db_backup.sql.gz\"");
				header("Content-disposition: attachment; filename=phpbb_db_backup.sql.gz");
			}
			else
			{
				header("Content-Type: text/x-delimtext; name=\"phpbb_db_backup.sql\"");
				header("Content-disposition: attachment; filename=phpbb_db_backup.sql");
			}

			//
			// Build the sql script file...
			//
			echo "#\n";
			echo "# phpBB Backup Script\n";
			echo "# Dump of tables for $dbname\n";
			echo "#\n# DATE : " .  gmdate("d-m-Y H:i:s", time()) . " GMT\n";
			echo "#\n";

			if(SQL_LAYER == 'postgresql')
			{
				 echo "\n" . pg_get_sequences("\n", $backup_type);
			}
			for($i = 0; $i < count($tables); $i++)
			{
				$table_name = $tables[$i];

				switch (SQL_LAYER)
				{
					case 'postgresql':
						$table_def_function = "get_table_def_postgresql";
						$table_content_function = "get_table_content_postgresql";
						break;

					case 'mysql':
					case 'mysql4':
						$table_def_function = "get_table_def_mysql";
						$table_content_function = "get_table_content_mysql";
						break;
				}

				if($backup_type != 'data')
				{
					echo "#\n# TABLE: " . $table_prefix . $table_name . "\n#\n";
					echo $table_def_function($table_prefix . $table_name, "\n") . "\n";
				}

				if($backup_type != 'structure')
				{
					$table_content_function($table_prefix . $table_name, "output_table_content");
				}
			}
			
			if($do_gzip_compress)
			{
				$Size = ob_get_length();
				$Crc = crc32(ob_get_contents());
				$contents = gzcompress(ob_get_contents());
				ob_end_clean();
				echo "\x1f\x8b\x08\x00\x00\x00\x00\x00".substr($contents, 0, strlen($contents) - 4).gzip_PrintFourChars($Crc).gzip_PrintFourChars($Size);
			}
			exit;

			break;

		case 'restore':
			if(!isset($HTTP_POST_VARS['restore_start']))
			{
				//
				// Define Template files...
				//
				include('./page_header_admin.'.$phpEx);

				$template->set_filenames(array(
					"body" => "admin/db_utils_restore_body.tpl")
				);

				$s_hidden_fields = "<input type=\"hidden\" name=\"perform\" value=\"restore\" /><input type=\"hidden\" name=\"perform\" value=\"$perform\" />";

				$template->assign_vars(array(
					"L_DATABASE_RESTORE" => $lang['Database_Utilities'] . " : " . $lang['Restore'],
					"L_RESTORE_EXPLAIN" => $lang['Restore_explain'],
					"L_SELECT_FILE" => $lang['Select_file'],
					"L_START_RESTORE" => $lang['Start_Restore'],

					"S_DBUTILS_ACTION" => append_sid("admin_db_utilities.$phpEx"),
					"S_HIDDEN_FIELDS" => $s_hidden_fields)
				);
				$template->pparse("body");

				break;

			}
			else
			{
				//
				// Handle the file upload ....
				// If no file was uploaded report an error...
				//
				$backup_file_name = (!empty($HTTP_POST_FILES['backup_file']['name'])) ? $HTTP_POST_FILES['backup_file']['name'] : "";
				$backup_file_tmpname = ($HTTP_POST_FILES['backup_file']['tmp_name'] != "none") ? $HTTP_POST_FILES['backup_file']['tmp_name'] : "";
				$backup_file_type = (!empty($HTTP_POST_FILES['backup_file']['type'])) ? $HTTP_POST_FILES['backup_file']['type'] : "";

				if($backup_file_tmpname == "" || $backup_file_name == "")
				{
					message_die(GENERAL_MESSAGE, $lang['Restore_Error_no_file']);
				}
				//
				// If I file was actually uploaded, check to make sure that we
				// are actually passed the name of an uploaded file, and not
				// a hackers attempt at getting us to process a local system
				// file.
				//
				if( file_exists(phpbb_realpath($backup_file_tmpname)) )
				{
					if( preg_match("/^(text\/[a-zA-Z]+)|(application\/(x\-)?gzip(\-compressed)?)|(application\/octet-stream)$/is", $backup_file_type) )
					{
						if( preg_match("/\.gz$/is",$backup_file_name) )
						{
							$do_gzip_compress = FALSE;
							$phpver = phpversion();
							if($phpver >= "4.0")
							{
								if(extension_loaded("zlib"))
								{
									$do_gzip_compress = TRUE;
								}
							}

							if($do_gzip_compress)
							{
								$gz_ptr = gzopen($backup_file_tmpname, 'rb');
								$sql_query = "";
								while( !gzeof($gz_ptr) )
								{
									$sql_query .= gzgets($gz_ptr, 100000);
								}
							}
							else
							{
								message_die(GENERAL_ERROR, $lang['Restore_Error_decompress']);
							}
						}
						else
						{
							$sql_query = fread(fopen($backup_file_tmpname, 'r'), filesize($backup_file_tmpname));
						}
						//
						// Comment this line out to see if this fixes the stuff...
						//
						//$sql_query = stripslashes($sql_query);
					}
					else
					{
						message_die(GENERAL_ERROR, $lang['Restore_Error_filename'] ." $backup_file_type $backup_file_name");
					}
				}
				else
				{
					message_die(GENERAL_ERROR, $lang['Restore_Error_uploading']);
				}

				if($sql_query != "")
				{
					// Strip out sql comments...
					$sql_query = remove_remarks($sql_query);
					$pieces = split_sql_file($sql_query, ";");

					$sql_count = count($pieces);
					for($i = 0; $i < $sql_count; $i++)
					{
						$sql = trim($pieces[$i]);

						if(!empty($sql) and $sql[0] != "#")
						{
							if(VERBOSE == 1)
							{
								echo "Executing: $sql\n<br>";
								flush();
							}

							$result = $db->sql_query($sql);

							if(!$result && ( !(SQL_LAYER == 'postgresql' && eregi("drop table", $sql) ) ) )
							{
								message_die(GENERAL_ERROR, "Error importing backup file", "", __LINE__, __FILE__, $sql);
							}
						}
					}
				}

				include('./page_header_admin.'.$phpEx);

				$template->set_filenames(array(
					"body" => "admin/admin_message_body.tpl")
				);

				$message = $lang['Restore_success'];

				$template->assign_vars(array(
					"MESSAGE_TITLE" => $lang['Database_Utilities'] . " : " . $lang['Restore'],
					"MESSAGE_TEXT" => $message)
				);

				$template->pparse("body");
				break;
			}
			break;
	}
}

include('./page_footer_admin.'.$phpEx);

?>


Geplaatst: 17 mar 2005, 10:47
door Luuk
Verander

Code: Selecteer alles

         $tables = array($tables[] = 'links';'auth_access', 'banlist', 'categories', 'config', 'disallow', 'forums', 'forum_prune', 'groups', 'posts', 'posts_text', 'privmsgs', 'privmsgs_text', 'ranks', 'search_results', 'search_wordlist', 'search_wordmatch', 'sessions', 'smilies', 'themes', 'themes_name', 'topics', 'topics_watch', 'user_group', 'users', 'vote_desc', 'vote_results', 'vote_voters', 'words');
eens in

Code: Selecteer alles

         $tables = array('auth_access', 'banlist', 'categories', 'config', 'disallow', 'forums', 'forum_prune', 'groups', 'posts', 'posts_text', 'privmsgs', 'privmsgs_text', 'ranks', 'search_results', 'search_wordlist', 'search_wordmatch', 'sessions', 'smilies', 'themes', 'themes_name', 'topics', 'topics_watch', 'user_group', 'users', 'vote_desc', 'vote_results', 'vote_voters', 'words');
		 $tables[] = 'links';

Geplaatst: 17 mar 2005, 11:35
door PHP Freak
Thx :wink:
alleen Parse error: parse error, expecting `')'' in /data/members/free/tripod/nl/k/a/r/karim4life/htdocs/admin/admin_db_utilities.php on line 695 is weg, maar ik krijg geen links te zien :oops: :cry: op mijn site, het enigen wat ik zie is dit No Links

Geplaatst: 17 mar 2005, 20:11
door Luuk
Je moet denk ik eerst een link maken in links.php oid.