Try the following version of shop_mod_install.php. It seams to work for me. If others report success with it, I'll re-release the new installer as 0.4.0a
Code: Select all
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/shop');
if (!$user->data['is_registered'])
{
if ($user->data['is_bot'])
{
redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
}
login_box('', 'LOGIN');
}
else if ($user->data['user_type'] != USER_FOUNDER)
{
trigger_error('NOT_AUTHORISED');
}
//okay, we're safe to install
$msg_title = 'Shop Mod Installer';
if (!file_exists($phpbb_root_path . 'includes/functions_shop.' . $phpEx))
{
trigger_error('You have to complete the installation instructions in install.xml before running this installer!');
}
include($phpbb_root_path . 'includes/functions_shop.' . $phpEx);
$shop = new shop;
if (!defined('SHOP_VERSION'))
{
//they're running a legacy (pre-installer) version
trigger_error('You have to complete the upgrade instructions before running this installer!');
}
if (SHOP_VERSION != '0.4.0')
{
if (version_compare(SHOP_VERSION, '0.4.0') == -1)
{
trigger_error('You have to complete the upgrade instructions before running this installer!');
}
else
{
trigger_error('This installer is for an older version. Use the installer for version ' . SHOP_VERSION);
}
}
//now we have to figure out what version is currently installed in the database to know if/how to upgrade
if(!$config['shop_mod_version'])
{
//either a fresh install or legacy version
$db->sql_return_on_error(false);
if (!$db->sql_query('SELECT * FROM ' . SHOP_ITEMS_TABLE))
{
$old_version = 0;
}
else
{
//uh oh, legacy version, we'll need some tricks to see which one
if (!$db->sql_query('SELECT * FROM ' . SHOP_ITEMS_USER_TABLE))
{
$old_version = '0.1.0';
}
elseif(!$db->sql_query('SELECT can_trash FROM ' . SHOP_ITEMS_TABLE))
{
$old_version = '0.2.0';
}
else
{
$old_version = '0.3.0';
}
}
$db->sql_return_on_error(false);
}
else
{
$old_version = $config['shop_mod_version'];
}
if ($old_version == SHOP_VERSION)
{
trigger_error('Version ' . SHOP_VERSION . ' already installed.');
}
//now we figure out the cash system in use
if($config['cash_mod'] and $config['points_enable'])
{
//if both systems are detected, give the user the choice as to which to use
switch (request_var('money','none'))
{
case 'cashmod':
$cash = 'cashmod';
break;
case 'simplepoints':
$cash = 'simplepoints';
break;
default:
trigger_error('<form method="GET" action="' . append_sid("{$phpbb_root_path}shop_mod_install.$phpEx") . '">Both Cash Mod and Simple Points have been detected!
Please select which system the shop mod should work with. <select name="money" id="money"><option value="cashmod">Cash Mod</option><option value="simplepoints">Simple Points</option></select>
<input type="submit" value="Choose" /></form>');
break;
}
}
elseif($config['cash_mod'])
{
$cash = 'cashmod';
}
elseif($config['points_enable'])
{
$cash = 'simplepoints';
}
else
{
//If you are using a custom money system besides the two that are supported, comment out the following line in order to proceed with the installation.
trigger_error('Neither Cash Mod nor Simple Points has been detected. One of these must be installed in order to install the shop mod.');
}
if (confirm_box(true))
{
$db->sql_transaction('begin');
//here, we actually do the install or upgrade
$sql = array();
if (!$old_version or version_compare($old_version, '0.3.0', 'le'))
{
//setup config options
set_config('shop_open', 0);
set_config('shoplink_show', 1);
set_config('shop_pm_on_buy', 0);
set_config('shop_shelf_size_sig', 0);
set_config('shop_mod_version', '0.4.0');
set_config('shop_money_system', $cash);
//and acl permissions
permission_setup();
if ($old_version)
{
module_seek_and_destroy();
}
module_setup();
switch ($old_version)
{
case 0:
$sql[] = 'CREATE TABLE `' . SHOP_ITEMS_TABLE . '` (
`item` mediumint(8) unsigned NOT NULL auto_increment,
`name` varchar(100) collate utf8_bin NOT NULL,
`description` varchar(255) collate utf8_bin NOT NULL,
`backend` varchar(255) collate utf8_bin NOT NULL,
`icon` varchar(100) collate utf8_bin NOT NULL,
`icon_width` tinyint(4) NOT NULL default \'0\',
`icon_height` tinyint(4) NOT NULL default \'0\'
`quantity` mediumint(8) unsigned NOT NULL default \'0\',
`price` mediumint(8) unsigned NOT NULL default \'0\',
`sell_price` mediumint(8) unsigned NOT NULL default \'0\',
`item_order` mediumint(8) unsigned NOT NULL default \'0\',
`instant_use` tinyint(1) NOT NULL default \'0\',
`can_sellback` tinyint(1) NOT NULL default \'0\',
`can_trash` tinyint(1) NOT NULL default \'0\',
`can_display` tinyint(1) NOT NULL default \'0\',
PRIMARY KEY (`item`)
) CHARSET=utf8 COLLATE=utf8_bin';
$sql[] = 'CREATE TABLE `' . SHOP_ITEMS_USER_TABLE . '` (
`item_user` mediumint(8) unsigned NOT NULL auto_increment,
`item` mediumint(8) unsigned NOT NULL,
`user` mediumint(8) unsigned NOT NULL,
`quantity_user` mediumint(8) unsigned default NULL,
`shelf_display` tinyint(1) NOT NULL default \'0\',
PRIMARY KEY (`item_user`)
) CHARSET=utf8 COLLATE=utf8_bin';
break;
case '0.1.0':
$sql[] = 'CREATE TABLE ' . SHOP_ITEMS_USER_TABLE . ' ( item_user mediumint(8) unsigned NOT NULL auto_increment, item mediumint(8) unsigned NOT NULL, `user` mediumint(8) unsigned NOT NULL,
quantity_user mediumint(8) unsigned default NULL, PRIMARY KEY (item_user)) CHARSET=utf8 COLLATE=utf8_bin';
$sql[] = 'ALTER TABLE ' . SHOP_ITEMS_TABLE . ' ADD `price` mediumint(8) unsigned NOT NULL default \'0\'';
$sql[] = 'ALTER TABLE ' . SHOP_ITEMS_TABLE . ' ADD `item_order` mediumint(8) unsigned NOT NULL default \'0\'';
//no break
case '0.2.0':
$sql[] = 'ALTER TABLE ' . SHOP_ITEMS_TABLE . ' ADD `backend` varchar(255) collate utf8_bin NOT NULL';
$sql[] = 'ALTER TABLE ' . SHOP_ITEMS_TABLE . ' ADD `sell_price` mediumint(8) unsigned NOT NULL default \'0\'';
$sql[] = 'ALTER TABLE ' . SHOP_ITEMS_TABLE . ' ADD `instant_use` tinyint(1) NOT NULL default \'0\'';
$sql[] = 'ALTER TABLE ' . SHOP_ITEMS_TABLE . ' ADD `can_sellback` tinyint(1) NOT NULL default \'0\'';
$sql[] = 'ALTER TABLE ' . SHOP_ITEMS_TABLE . ' ADD `can_trash` tinyint(1) NOT NULL default \'0\'';
$sql[] = 'UPDATE ' . SHOP_ITEMS_TABLE . ' SET `backend`=\'blank\'';
//no break
case '0.3.0':
$sql[] = 'ALTER TABLE ' . SHOP_ITEMS_TABLE . ' ADD `icon_width` tinyint(4) NOT NULL default \'0\'';
$sql[] = 'ALTER TABLE ' . SHOP_ITEMS_TABLE . ' ADD `icon_height` tinyint(4) NOT NULL default \'0\'';
$sql[] = 'ALTER TABLE ' . SHOP_ITEMS_TABLE . ' ADD `can_display` tinyint(1) NOT NULL default \'0\'';
break;
default:
trigger_error('You shouldn\'t be seeing this. It means something is wrong with the installer. Let me know at phantom AT radoncube.com or post on the mod\'s topic on phpbb.com.');
break;
}
foreach ($sql as $var)
{
$db->sql_query($var);
}
set_icon_dimensions();
if ($oldversion == '0.1.0')
{
resync_item_order();
}
}
//at this point, we're up to 0.4.0
//when we make new versions, we'll do the update here
$db->sql_transaction('confirm');
//clear cache
$cache->destroy('_modules_acp');
$cache->destroy('_modules_ucp');
$cache->destroy('sql', MODULES_TABLE);
require($phpbb_root_path . 'includes/functions_admin.' . $phpEx); //for filelist()
$cachelist = filelist($phpbb_root_path . $img_path, '');
$dh = @opendir($phpbb_root_path . 'cache');
while (($fname = readdir($dh)) !== false)
{
if (is_file($phpbb_root_path . 'cache/' . $fname) and strpos($fname, 'prosilver'))
{
@unlink($phpbb_root_path . 'cache/' . $fname);
}
}
trigger_error('Install Complete!');
}
else
{
$s_hidden_fields = build_hidden_fields(array(
'submit' => true,
)
);
$message = '';
//display mode
$message = 'The installer has detected that it needs to perform ';
if ($oldversion == 0)
{
$message .= 'a fresh install';
}
else
{
$message .= 'an upgrade from version ' . $oldversion;
}
if ($cash == 'cashmod')
{
$message .= ', using the Cash Mod as its money system';
}
elseif ($cash == 'simplepoints')
{
$message .= ', using the Simple Points System as its money system';
}
$message .= '. Is this correct?';
confirm_box(false, $message, $s_hidden_fields);
redirect(append_sid("{$phpbb_root_path}shop_mod_install.$phpEx"));
}
function resync_item_order()
{
global $db;
// this fun snippet of code stolen from acp_icons.php
$sql = 'SELECT item, item_order FROM ' . SHOP_ITEMS_TABLE . ' ORDER BY item_order';
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result))
{
$order = 0;
do
{
++$order;
if ($row['item_order'] != $order)
{
$db->sql_query('UPDATE ' . SHOP_ITEMS_TABLE . " SET item_order = $order WHERE item = " . $row['item']);
}
}
while ($row = $db->sql_fetchrow($result));
}
$db->sql_freeresult($result);
}
function set_icon_dimensions()
{
global $db, $phpbb_root_path;
$img_path = 'images/icons/shop_icons/';
$sql = 'SELECT * FROM ' . SHOP_ITEMS_TABLE;
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
if ($row['icon'] != '0')
{
$img_size = getimagesize($phpbb_root_path . $img_path . '/' . $row['icon']);
$icon_width = $img_size[0];
$icon_height = $img_size[1];
}
else
{
$icon_width = 0;
$icon_height = 0;
}
$sql = 'UPDATE ' . SHOP_ITEMS_TABLE . " SET icon_width = $icon_width, icon_height = $icon_height WHERE item = {$row['item']}";
$db->sql_query($sql);
}
}
function module_setup()
{
global $db;
//ACP modules
$sql = 'SELECT * FROM ' . MODULES_TABLE . " WHERE module_langname = 'ACP_CAT_DOT_MODS'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$sql_ary = array(
'module_enabled' => 1,
'module_display' => 1,
'module_basename' => '',
'module_class' => 'acp',
'parent_id' => $row['module_id'],
'left_id' => $row['right_id'],
'right_id' => $row['right_id'] + 5,
'module_langname' => 'ACP_PHANTOMS_MODS',
'module_mode' => '',
'module_auth' => '',
);
$sql = 'UPDATE ' . MODULES_TABLE . ' SET right_id = right_id + 6 WHERE module_class = \'' . $row['module_class'] . '\' AND right_id >= ' . $row['right_id'];
$db->sql_query($sql);
$sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = left_id + 6 WHERE module_class = \'' . $row['module_class'] . '\' AND left_id > ' . $row['right_id'];
$db->sql_query($sql);
$sql = 'INSERT INTO ' . MODULES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$module_id = $db->sql_nextid();
$sql_ary = array(
'module_enabled' => 1,
'module_display' => 1,
'module_basename' => 'shop_mod',
'module_class' => 'acp',
'parent_id' => $module_id,
'left_id' => $row['right_id'] + 1,
'right_id' => $row['right_id'] + 2,
'module_langname' => 'ACP_SHOP_CONFIG',
'module_mode' => 'config',
'module_auth' => 'acl_a_shop_mod',
);
$sql = 'INSERT INTO ' . MODULES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$sql_ary = array(
'module_enabled' => 1,
'module_display' => 1,
'module_basename' => 'shop_mod',
'module_class' => 'acp',
'parent_id' => $module_id,
'left_id' => $row['right_id'] + 3,
'right_id' => $row['right_id'] + 4,
'module_langname' => 'ACP_SHOP_ITEMS',
'module_mode' => 'items',
'module_auth' => 'acl_a_shop_mod',
);
$sql = 'INSERT INTO ' . MODULES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
//UCP modules
$sql = 'SELECT MAX(right_id) AS total_right FROM ' . MODULES_TABLE . " WHERE module_class = 'ucp'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$sql_ary = array(
'module_enabled' => 1,
'module_display' => 1,
'module_basename' => '',
'module_class' => 'ucp',
'parent_id' => 0,
'left_id' => $row['total_right'] + 1,
'right_id' => $row['total_right'] + 4,
'module_langname' => 'UCP_SHOP',
'module_mode' => '',
'module_auth' => '',
);
$sql = 'INSERT INTO ' . MODULES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$module_id = $db->sql_nextid();
$sql_ary = array(
'module_enabled' => 1,
'module_display' => 1,
'module_basename' => 'shop',
'module_class' => 'ucp',
'parent_id' => $module_id,
'left_id' => $row['total_right'] + 2,
'right_id' => $row['total_right'] + 3,
'module_langname' => 'UCP_SHOP_INVENTORY',
'module_mode' => 'inventory',
'module_auth' => '',
);
$sql = 'INSERT INTO ' . MODULES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
}
function permission_setup()
{
global $db;
//this permission lets admins access the shop mod acp panel
$sql = 'INSERT INTO phpbb_acl_options (auth_option, is_global, is_local, founder_only) VALUES (\'a_shop_mod\', 1, 0, 0)';
$result = $db->sql_query($sql);
$id = $db->sql_nextid();
//give this permission to anyone with the acl_a_board permission
$sql = 'SELECT auth_option_id FROM phpbb_acl_options WHERE auth_option = \'a_board\'';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$auth_id = $row['auth_option_id'];
$tables = array('phpbb_acl_groups', 'phpbb_acl_users', 'phpbb_acl_roles_data');
foreach ($tables as $table)
{
$sql = 'SELECT * FROM ' . $table . " WHERE auth_option_id = '$auth_id'";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$row['auth_option_id'] = $id;
$sql = 'INSERT INTO ' . $table . $db->sql_build_array('INSERT', $row);
$db->sql_query($sql);
}
}
//destroy user permission cache
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_permissions = \'\', user_perm_from = 0';
$db->sql_query($sql);
}
function module_seek_and_destroy()
{
global $db, $cache;
$sql = 'SELECT * FROM ' . MODULES_TABLE . ' WHERE module_basename = \'shop\' or module_basename = \'shop_mod\'';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$sql = 'SELECT * FROM ' . MODULES_TABLE . ' WHERE module_id = ' . $row['module_id'];
$result_2 = $db->sql_query($sql);
$row = $db->sql_fetchrow($result_2);
$sql = 'DELETE FROM ' . MODULES_TABLE . ' WHERE module_id = ' . $row['module_id'];
$db->sql_query($sql);
//check to see if the module left any orphans (there's no reason why it should, the acp only lets categories have children)
if ($row['left_id'] + 1 != $row['right_id'])
{
//let the grandparent adopt the oprhans since we killed the parent (isn't that a nice image)
$sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = left_id -1, right_id = right_id - 1, parent_id = ' . $row['parent_id'] . ' WHERE module_class = \'' . $row['module_class'] . '\' AND left_id BETWEEN ' . $row['left_id'] . ' AND ' . $row['right_id'];
$db->sql_query($sql);
}
$sql = 'UPDATE ' . MODULES_TABLE . ' SET right_id = right_id - 2 WHERE module_class = \'' . $row['module_class'] . '\' AND right_id > ' . $row['right_id'];
$db->sql_query($sql);
$sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = left_id - 2 WHERE module_class = \'' . $row['module_class'] . '\' AND left_id > ' . $row['right_id'];
$db->sql_query($sql);
//if an empty parent class is left behind, get rid of it too
while ($parent_id = $row['parent_id'])
{
$sql = 'SELECT * FROM ' . MODULES_TABLE . ' WHERE module_id = ' . $parent_id;
$result_2 = $db->sql_query($sql);
$row = $db->sql_fetchrow($result_2);
if ($row['left_id'] + 1 != $row['right_id'] or $row['module_langname'] == 'ACP_CAT_DOT_MODS')
{
break;
}
$sql = 'DELETE FROM ' . MODULES_TABLE . ' WHERE module_id = ' . $row['module_id'];
$db->sql_query($sql);
$sql = 'UPDATE ' . MODULES_TABLE . ' SET right_id = right_id - 2 WHERE module_class = \'' . $row['module_class'] . '\' AND right_id > ' . $row['right_id'];
$db->sql_query($sql);
$sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = left_id - 2 WHERE module_class = \'' . $row['module_class'] . '\' AND left_id > ' . $row['right_id'];
$db->sql_query($sql);
}
}
}