includes/acp/acp_attachments.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/acp/acp_attachments.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,1459 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package acp
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +* @ignore
    1.16 +*/
    1.17 +if (!defined('IN_PHPBB'))
    1.18 +{
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 +* @package acp
    1.24 +*/
    1.25 +class acp_attachments
    1.26 +{
    1.27 +	var $u_action;
    1.28 +	var $new_config;
    1.29 +
    1.30 +	function main($id, $mode)
    1.31 +	{
    1.32 +		global $db, $user, $auth, $template, $cache;
    1.33 +		global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
    1.34 +
    1.35 +		$user->add_lang(array('posting', 'viewtopic', 'acp/attachments'));
    1.36 +
    1.37 +		$error = $notify = array();
    1.38 +		$submit = (isset($_POST['submit'])) ? true : false;
    1.39 +		$action = request_var('action', '');
    1.40 +
    1.41 +		$form_key = 'acp_attach';
    1.42 +		add_form_key($form_key);
    1.43 +
    1.44 +		if ($submit && !check_form_key($form_key))
    1.45 +		{
    1.46 +			trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
    1.47 +		}
    1.48 +
    1.49 +		switch ($mode)
    1.50 +		{
    1.51 +			case 'attach':
    1.52 +				$l_title = 'ACP_ATTACHMENT_SETTINGS';
    1.53 +			break;
    1.54 +
    1.55 +			case 'extensions':
    1.56 +				$l_title = 'ACP_MANAGE_EXTENSIONS';
    1.57 +			break;
    1.58 +
    1.59 +			case 'ext_groups':
    1.60 +				$l_title = 'ACP_EXTENSION_GROUPS';
    1.61 +			break;
    1.62 +
    1.63 +			case 'orphan':
    1.64 +				$l_title = 'ACP_ORPHAN_ATTACHMENTS';
    1.65 +			break;
    1.66 +
    1.67 +			default:
    1.68 +				trigger_error('NO_MODE', E_USER_ERROR);
    1.69 +			break;
    1.70 +		}
    1.71 +
    1.72 +		$this->tpl_name = 'acp_attachments';
    1.73 +		$this->page_title = $l_title;
    1.74 +
    1.75 +		$template->assign_vars(array(
    1.76 +			'L_TITLE'			=> $user->lang[$l_title],
    1.77 +			'L_TITLE_EXPLAIN'	=> $user->lang[$l_title . '_EXPLAIN'],
    1.78 +			'U_ACTION'			=> $this->u_action)
    1.79 +		);
    1.80 +
    1.81 +		switch ($mode)
    1.82 +		{
    1.83 +			case 'attach':
    1.84 +
    1.85 +				include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
    1.86 +
    1.87 +				$sql = 'SELECT group_name, cat_id
    1.88 +					FROM ' . EXTENSION_GROUPS_TABLE . '
    1.89 +					WHERE cat_id > 0
    1.90 +					ORDER BY cat_id';
    1.91 +				$result = $db->sql_query($sql);
    1.92 +
    1.93 +				$s_assigned_groups = array();
    1.94 +				while ($row = $db->sql_fetchrow($result))
    1.95 +				{
    1.96 +					$row['group_name'] = (isset($user->lang['EXT_GROUP_' . $row['group_name']])) ? $user->lang['EXT_GROUP_' . $row['group_name']] : $row['group_name'];
    1.97 +					$s_assigned_groups[$row['cat_id']][] = $row['group_name'];
    1.98 +				}
    1.99 +				$db->sql_freeresult($result);
   1.100 +
   1.101 +				$l_legend_cat_images = $user->lang['SETTINGS_CAT_IMAGES'] . ' [' . $user->lang['ASSIGNED_GROUP'] . ': ' . ((!empty($s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE])) ? implode(', ', $s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) : $user->lang['NO_EXT_GROUP']) . ']';
   1.102 +
   1.103 +				$display_vars = array(
   1.104 +					'title'	=> 'ACP_ATTACHMENT_SETTINGS',
   1.105 +					'vars'	=> array(
   1.106 +						'legend1'				=> 'ACP_ATTACHMENT_SETTINGS',
   1.107 +
   1.108 +						'img_max_width'			=> array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
   1.109 +						'img_max_height'		=> array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
   1.110 +						'img_link_width'		=> array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
   1.111 +						'img_link_height'		=> array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
   1.112 +
   1.113 +						'allow_attachments'		=> array('lang' => 'ALLOW_ATTACHMENTS',		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => false),
   1.114 +						'allow_pm_attach'		=> array('lang' => 'ALLOW_PM_ATTACHMENTS',	'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => false),
   1.115 +						'upload_path'			=> array('lang' => 'UPLOAD_DIR',			'validate' => 'wpath',	'type' => 'text:25:100', 'explain' => true),
   1.116 +						'display_order'			=> array('lang' => 'DISPLAY_ORDER',			'validate' => 'bool',	'type' => 'custom', 'method' => 'display_order', 'explain' => true),
   1.117 +						'attachment_quota'		=> array('lang' => 'ATTACH_QUOTA',			'validate' => 'string',	'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
   1.118 +						'max_filesize'			=> array('lang' => 'ATTACH_MAX_FILESIZE',	'validate' => 'string',	'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
   1.119 +						'max_filesize_pm'		=> array('lang' => 'ATTACH_MAX_PM_FILESIZE','validate' => 'string',	'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
   1.120 +						'max_attachments'		=> array('lang' => 'MAX_ATTACHMENTS',		'validate' => 'int',	'type' => 'text:3:3', 'explain' => false),
   1.121 +						'max_attachments_pm'	=> array('lang' => 'MAX_ATTACHMENTS_PM',	'validate' => 'int',	'type' => 'text:3:3', 'explain' => false),
   1.122 +						'secure_downloads'		=> array('lang' => 'SECURE_DOWNLOADS',		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
   1.123 +						'secure_allow_deny'		=> array('lang' => 'SECURE_ALLOW_DENY',		'validate' => 'int',	'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true),
   1.124 +						'secure_allow_empty_referer'	=> array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
   1.125 +						'check_attachment_content' 		=> array('lang' => 'CHECK_CONTENT', 'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
   1.126 +
   1.127 +
   1.128 +						'legend2'					=> $l_legend_cat_images,
   1.129 +						'img_display_inlined'		=> array('lang' => 'DISPLAY_INLINED',		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
   1.130 +						'img_create_thumbnail'		=> array('lang' => 'CREATE_THUMBNAIL',		'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
   1.131 +						'img_max_thumb_width'		=> array('lang' => 'MAX_THUMB_WIDTH',		'validate' => 'int',	'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
   1.132 +						'img_min_thumb_filesize'	=> array('lang' => 'MIN_THUMB_FILESIZE',	'validate' => 'int',	'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
   1.133 +						'img_imagick'				=> array('lang' => 'IMAGICK_PATH',			'validate' => 'string',	'type' => 'text:20:200', 'explain' => true, 'append' => '&nbsp;&nbsp;<span>[ <a href="' . $this->u_action . '&amp;action=imgmagick">' . $user->lang['SEARCH_IMAGICK'] . '</a> ]</span>'),
   1.134 +						'img_max'					=> array('lang' => 'MAX_IMAGE_SIZE',		'validate' => 'int',	'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
   1.135 +						'img_link'					=> array('lang' => 'IMAGE_LINK_SIZE',		'validate' => 'int',	'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
   1.136 +					)
   1.137 +				);
   1.138 +
   1.139 +				$this->new_config = $config;
   1.140 +				$cfg_array = (isset($_REQUEST['config'])) ? request_var('config', array('' => '')) : $this->new_config;
   1.141 +				$error = array();
   1.142 +
   1.143 +				// We validate the complete config if whished
   1.144 +				validate_config_vars($display_vars['vars'], $cfg_array, $error);
   1.145 +
   1.146 +				// Do not write values if there is an error
   1.147 +				if (sizeof($error))
   1.148 +				{
   1.149 +					$submit = false;
   1.150 +				}
   1.151 +
   1.152 +				// We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
   1.153 +				foreach ($display_vars['vars'] as $config_name => $null)
   1.154 +				{
   1.155 +					if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
   1.156 +					{
   1.157 +						continue;
   1.158 +					}
   1.159 +
   1.160 +					$this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
   1.161 +
   1.162 +					if (in_array($config_name, array('attachment_quota', 'max_filesize', 'max_filesize_pm')))
   1.163 +					{
   1.164 +						$size_var = request_var($config_name, '');
   1.165 +						$this->new_config[$config_name] = $config_value = ($size_var == 'kb') ? round($config_value * 1024) : (($size_var == 'mb') ? round($config_value * 1048576) : $config_value);
   1.166 +					}
   1.167 +
   1.168 +					if ($submit)
   1.169 +					{
   1.170 +						set_config($config_name, $config_value);
   1.171 +					}
   1.172 +				}
   1.173 +
   1.174 +				$this->perform_site_list();
   1.175 +
   1.176 +				if ($submit)
   1.177 +				{
   1.178 +					add_log('admin', 'LOG_CONFIG_ATTACH');
   1.179 +
   1.180 +					// Check Settings
   1.181 +					$this->test_upload($error, $this->new_config['upload_path'], false);
   1.182 +
   1.183 +					if (!sizeof($error))
   1.184 +					{
   1.185 +						trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
   1.186 +					}
   1.187 +				}
   1.188 +
   1.189 +				$template->assign_var('S_ATTACHMENT_SETTINGS', true);
   1.190 +
   1.191 +				if ($action == 'imgmagick')
   1.192 +				{
   1.193 +					$this->new_config['img_imagick'] = $this->search_imagemagick();
   1.194 +				}
   1.195 +
   1.196 +				// We strip eventually manual added convert program, we only want the patch
   1.197 +				if ($this->new_config['img_imagick'])
   1.198 +				{
   1.199 +					// Change path separator
   1.200 +					$this->new_config['img_imagick'] = str_replace('\\', '/', $this->new_config['img_imagick']);
   1.201 +					$this->new_config['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $this->new_config['img_imagick']);
   1.202 +
   1.203 +					// Check for trailing slash
   1.204 +					if (substr($this->new_config['img_imagick'], -1) !== '/')
   1.205 +					{
   1.206 +						$this->new_config['img_imagick'] .= '/';
   1.207 +					}
   1.208 +				}
   1.209 +
   1.210 +				$supported_types = get_supported_image_types();
   1.211 +
   1.212 +				// Check Thumbnail Support
   1.213 +				if (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format'])))
   1.214 +				{
   1.215 +					$this->new_config['img_create_thumbnail'] = 0;
   1.216 +				}
   1.217 +
   1.218 +				$template->assign_vars(array(
   1.219 +					'U_SEARCH_IMAGICK'		=> $this->u_action . '&amp;action=imgmagick',
   1.220 +					'S_THUMBNAIL_SUPPORT'	=> (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format']))) ? false : true)
   1.221 +				);
   1.222 +
   1.223 +				// Secure Download Options - Same procedure as with banning
   1.224 +				$allow_deny = ($this->new_config['secure_allow_deny']) ? 'ALLOWED' : 'DISALLOWED';
   1.225 +
   1.226 +				$sql = 'SELECT *
   1.227 +					FROM ' . SITELIST_TABLE;
   1.228 +				$result = $db->sql_query($sql);
   1.229 +
   1.230 +				$defined_ips = '';
   1.231 +				$ips = array();
   1.232 +
   1.233 +				while ($row = $db->sql_fetchrow($result))
   1.234 +				{
   1.235 +					$value = ($row['site_ip']) ? $row['site_ip'] : $row['site_hostname'];
   1.236 +					if ($value)
   1.237 +					{
   1.238 +						$defined_ips .= '<option' . (($row['ip_exclude']) ? ' class="sep"' : '') . ' value="' . $row['site_id'] . '">' . $value . '</option>';
   1.239 +						$ips[$row['site_id']] = $value;
   1.240 +					}
   1.241 +				}
   1.242 +				$db->sql_freeresult($result);
   1.243 +
   1.244 +				$template->assign_vars(array(
   1.245 +					'S_SECURE_DOWNLOADS'	=> $this->new_config['secure_downloads'],
   1.246 +					'S_DEFINED_IPS'			=> ($defined_ips != '') ? true : false,
   1.247 +					'S_WARNING'				=> (sizeof($error)) ? true : false,
   1.248 +
   1.249 +					'WARNING_MSG'			=> implode('<br />', $error),
   1.250 +					'DEFINED_IPS'			=> $defined_ips,
   1.251 +
   1.252 +					'L_SECURE_TITLE'		=> $user->lang['DEFINE_' . $allow_deny . '_IPS'],
   1.253 +					'L_IP_EXCLUDE'			=> $user->lang['EXCLUDE_FROM_' . $allow_deny . '_IP'],
   1.254 +					'L_REMOVE_IPS'			=> $user->lang['REMOVE_' . $allow_deny . '_IPS'])
   1.255 +				);
   1.256 +
   1.257 +				// Output relevant options
   1.258 +				foreach ($display_vars['vars'] as $config_key => $vars)
   1.259 +				{
   1.260 +					if (!is_array($vars) && strpos($config_key, 'legend') === false)
   1.261 +					{
   1.262 +						continue;
   1.263 +					}
   1.264 +
   1.265 +					if (strpos($config_key, 'legend') !== false)
   1.266 +					{
   1.267 +						$template->assign_block_vars('options', array(
   1.268 +							'S_LEGEND'		=> true,
   1.269 +							'LEGEND'		=> (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars)
   1.270 +						);
   1.271 +
   1.272 +						continue;
   1.273 +					}
   1.274 +
   1.275 +					$type = explode(':', $vars['type']);
   1.276 +
   1.277 +					$l_explain = '';
   1.278 +					if ($vars['explain'] && isset($vars['lang_explain']))
   1.279 +					{
   1.280 +						$l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
   1.281 +					}
   1.282 +					else if ($vars['explain'])
   1.283 +					{
   1.284 +						$l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
   1.285 +					}
   1.286 +
   1.287 +					$content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
   1.288 +					if (empty($content))
   1.289 +					{
   1.290 +						continue;
   1.291 +					}
   1.292 +
   1.293 +					$template->assign_block_vars('options', array(
   1.294 +						'KEY'			=> $config_key,
   1.295 +						'TITLE'			=> $user->lang[$vars['lang']],
   1.296 +						'S_EXPLAIN'		=> $vars['explain'],
   1.297 +						'TITLE_EXPLAIN'	=> $l_explain,
   1.298 +						'CONTENT'		=> $content,
   1.299 +						)
   1.300 +					);
   1.301 +
   1.302 +					unset($display_vars['vars'][$config_key]);
   1.303 +				}
   1.304 +
   1.305 +			break;
   1.306 +
   1.307 +			case 'extensions':
   1.308 +
   1.309 +				if ($submit || isset($_POST['add_extension_check']))
   1.310 +				{
   1.311 +					if ($submit)
   1.312 +					{
   1.313 +						// Change Extensions ?
   1.314 +						$extension_change_list	= request_var('extension_change_list', array(0));
   1.315 +						$group_select_list		= request_var('group_select', array(0));
   1.316 +
   1.317 +						// Generate correct Change List
   1.318 +						$extensions = array();
   1.319 +
   1.320 +						for ($i = 0, $size = sizeof($extension_change_list); $i < $size; $i++)
   1.321 +						{
   1.322 +							$extensions[$extension_change_list[$i]]['group_id'] = $group_select_list[$i];
   1.323 +						}
   1.324 +
   1.325 +						$sql = 'SELECT *
   1.326 +							FROM ' . EXTENSIONS_TABLE . '
   1.327 +							ORDER BY extension_id';
   1.328 +						$result = $db->sql_query($sql);
   1.329 +
   1.330 +						while ($row = $db->sql_fetchrow($result))
   1.331 +						{
   1.332 +							if ($row['group_id'] != $extensions[$row['extension_id']]['group_id'])
   1.333 +							{
   1.334 +								$sql = 'UPDATE ' . EXTENSIONS_TABLE . '
   1.335 +									SET group_id = ' . (int) $extensions[$row['extension_id']]['group_id'] . '
   1.336 +									WHERE extension_id = ' . $row['extension_id'];
   1.337 +								$db->sql_query($sql);
   1.338 +
   1.339 +								add_log('admin', 'LOG_ATTACH_EXT_UPDATE', $row['extension']);
   1.340 +							}
   1.341 +						}
   1.342 +						$db->sql_freeresult($result);
   1.343 +
   1.344 +						// Delete Extension?
   1.345 +						$extension_id_list = request_var('extension_id_list', array(0));
   1.346 +
   1.347 +						if (sizeof($extension_id_list))
   1.348 +						{
   1.349 +							$sql = 'SELECT extension
   1.350 +								FROM ' . EXTENSIONS_TABLE . '
   1.351 +								WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
   1.352 +							$result = $db->sql_query($sql);
   1.353 +
   1.354 +							$extension_list = '';
   1.355 +							while ($row = $db->sql_fetchrow($result))
   1.356 +							{
   1.357 +								$extension_list .= ($extension_list == '') ? $row['extension'] : ', ' . $row['extension'];
   1.358 +							}
   1.359 +							$db->sql_freeresult($result);
   1.360 +
   1.361 +							$sql = 'DELETE
   1.362 +								FROM ' . EXTENSIONS_TABLE . '
   1.363 +								WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
   1.364 +							$db->sql_query($sql);
   1.365 +
   1.366 +							add_log('admin', 'LOG_ATTACH_EXT_DEL', $extension_list);
   1.367 +						}
   1.368 +					}
   1.369 +
   1.370 +					// Add Extension?
   1.371 +					$add_extension			= strtolower(request_var('add_extension', ''));
   1.372 +					$add_extension_group	= request_var('add_group_select', 0);
   1.373 +					$add					= (isset($_POST['add_extension_check'])) ? true : false;
   1.374 +
   1.375 +					if ($add_extension && $add)
   1.376 +					{
   1.377 +						if (!sizeof($error))
   1.378 +						{
   1.379 +							$sql = 'SELECT extension_id
   1.380 +								FROM ' . EXTENSIONS_TABLE . "
   1.381 +								WHERE extension = '" . $db->sql_escape($add_extension) . "'";
   1.382 +							$result = $db->sql_query($sql);
   1.383 +
   1.384 +							if ($row = $db->sql_fetchrow($result))
   1.385 +							{
   1.386 +								$error[] = sprintf($user->lang['EXTENSION_EXIST'], $add_extension);
   1.387 +							}
   1.388 +							$db->sql_freeresult($result);
   1.389 +
   1.390 +							if (!sizeof($error))
   1.391 +							{
   1.392 +								$sql_ary = array(
   1.393 +									'group_id'	=>	$add_extension_group,
   1.394 +									'extension'	=>	$add_extension
   1.395 +								);
   1.396 +
   1.397 +								$db->sql_query('INSERT INTO ' . EXTENSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
   1.398 +								add_log('admin', 'LOG_ATTACH_EXT_ADD', $add_extension);
   1.399 +							}
   1.400 +						}
   1.401 +					}
   1.402 +
   1.403 +					if (!sizeof($error))
   1.404 +					{
   1.405 +						$notify[] = $user->lang['EXTENSIONS_UPDATED'];
   1.406 +					}
   1.407 +
   1.408 +					$cache->destroy('_extensions');
   1.409 +				}
   1.410 +
   1.411 +				$template->assign_vars(array(
   1.412 +					'S_EXTENSIONS'			=> true,
   1.413 +					'ADD_EXTENSION'			=> (isset($add_extension)) ? $add_extension : '',
   1.414 +					'GROUP_SELECT_OPTIONS'	=> (isset($_POST['add_extension_check'])) ? $this->group_select('add_group_select', $add_extension_group, 'extension_group') : $this->group_select('add_group_select', false, 'extension_group'))
   1.415 +				);
   1.416 +
   1.417 +				$sql = 'SELECT *
   1.418 +					FROM ' . EXTENSIONS_TABLE . '
   1.419 +					ORDER BY group_id, extension';
   1.420 +				$result = $db->sql_query($sql);
   1.421 +
   1.422 +				if ($row = $db->sql_fetchrow($result))
   1.423 +				{
   1.424 +					$old_group_id = $row['group_id'];
   1.425 +					do
   1.426 +					{
   1.427 +						$s_spacer = false;
   1.428 +
   1.429 +						$current_group_id = $row['group_id'];
   1.430 +						if ($old_group_id != $current_group_id)
   1.431 +						{
   1.432 +							$s_spacer = true;
   1.433 +							$old_group_id = $current_group_id;
   1.434 +						}
   1.435 +
   1.436 +						$template->assign_block_vars('extensions', array(
   1.437 +							'S_SPACER'		=> $s_spacer,
   1.438 +							'EXTENSION_ID'	=> $row['extension_id'],
   1.439 +							'EXTENSION'		=> $row['extension'],
   1.440 +							'GROUP_OPTIONS'	=> $this->group_select('group_select[]', $row['group_id']))
   1.441 +						);
   1.442 +					}
   1.443 +					while ($row = $db->sql_fetchrow($result));
   1.444 +				}
   1.445 +				$db->sql_freeresult($result);
   1.446 +
   1.447 +			break;
   1.448 +
   1.449 +			case 'ext_groups':
   1.450 +
   1.451 +				$template->assign_var('S_EXTENSION_GROUPS', true);
   1.452 +
   1.453 +				if ($submit)
   1.454 +				{
   1.455 +					$action = request_var('action', '');
   1.456 +					$group_id = request_var('g', 0);
   1.457 +
   1.458 +					if ($action != 'add' && $action != 'edit')
   1.459 +					{
   1.460 +						trigger_error('NO_MODE', E_USER_ERROR);
   1.461 +					}
   1.462 +
   1.463 +					if (!$group_id && $action == 'edit')
   1.464 +					{
   1.465 +						trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
   1.466 +					}
   1.467 +
   1.468 +					if ($group_id)
   1.469 +					{
   1.470 +						$sql = 'SELECT *
   1.471 +							FROM ' . EXTENSION_GROUPS_TABLE . "
   1.472 +							WHERE group_id = $group_id";
   1.473 +						$result = $db->sql_query($sql);
   1.474 +						$ext_row = $db->sql_fetchrow($result);
   1.475 +						$db->sql_freeresult($result);
   1.476 +
   1.477 +						if (!$ext_row)
   1.478 +						{
   1.479 +							trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
   1.480 +						}
   1.481 +					}
   1.482 +					else
   1.483 +					{
   1.484 +						$ext_row = array();
   1.485 +					}
   1.486 +
   1.487 +					$group_name = utf8_normalize_nfc(request_var('group_name', '', true));
   1.488 +					$new_group_name = ($action == 'add') ? $group_name : (($ext_row['group_name'] != $group_name) ? $group_name : '');
   1.489 +
   1.490 +					if (!$group_name)
   1.491 +					{
   1.492 +						$error[] = $user->lang['NO_EXT_GROUP_NAME'];
   1.493 +					}
   1.494 +
   1.495 +					// Check New Group Name
   1.496 +					if ($new_group_name)
   1.497 +					{
   1.498 +						$sql = 'SELECT group_id
   1.499 +							FROM ' . EXTENSION_GROUPS_TABLE . "
   1.500 +							WHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($new_group_name)) . "'";
   1.501 +						if ($group_id)
   1.502 +						{
   1.503 +							$sql .= ' AND group_id <> ' . $group_id;
   1.504 +						}
   1.505 +						$result = $db->sql_query($sql);
   1.506 +
   1.507 +						if ($db->sql_fetchrow($result))
   1.508 +						{
   1.509 +							$error[] = sprintf($user->lang['EXTENSION_GROUP_EXIST'], $new_group_name);
   1.510 +						}
   1.511 +						$db->sql_freeresult($result);
   1.512 +					}
   1.513 +
   1.514 +					if (!sizeof($error))
   1.515 +					{
   1.516 +						// Ok, build the update/insert array
   1.517 +						$upload_icon	= request_var('upload_icon', 'no_image');
   1.518 +						$size_select	= request_var('size_select', 'b');
   1.519 +						$forum_select	= request_var('forum_select', false);
   1.520 +						$allowed_forums	= request_var('allowed_forums', array(0));
   1.521 +						$allow_in_pm	= (isset($_POST['allow_in_pm'])) ? true : false;
   1.522 +						$max_filesize	= request_var('max_filesize', 0);
   1.523 +						$max_filesize	= ($size_select == 'kb') ? round($max_filesize * 1024) : (($size_select == 'mb') ? round($max_filesize * 1048576) : $max_filesize);
   1.524 +						$allow_group	= (isset($_POST['allow_group'])) ? true : false;
   1.525 +
   1.526 +						if ($max_filesize == $config['max_filesize'])
   1.527 +						{
   1.528 +							$max_filesize = 0;
   1.529 +						}
   1.530 +
   1.531 +						if (!sizeof($allowed_forums))
   1.532 +						{
   1.533 +							$forum_select = false;
   1.534 +						}
   1.535 +
   1.536 +						$group_ary = array(
   1.537 +							'group_name'	=> $group_name,
   1.538 +							'cat_id'		=> request_var('special_category', ATTACHMENT_CATEGORY_NONE),
   1.539 +							'allow_group'	=> ($allow_group) ? 1 : 0,
   1.540 +							'upload_icon'	=> ($upload_icon == 'no_image') ? '' : $upload_icon,
   1.541 +							'max_filesize'	=> $max_filesize,
   1.542 +							'allowed_forums'=> ($forum_select) ? serialize($allowed_forums) : '',
   1.543 +							'allow_in_pm'	=> ($allow_in_pm) ? 1 : 0,
   1.544 +						);
   1.545 +
   1.546 +						if ($action == 'add')
   1.547 +						{
   1.548 +							$group_ary['download_mode'] = INLINE_LINK;
   1.549 +						}
   1.550 +
   1.551 +						$sql = ($action == 'add') ? 'INSERT INTO ' . EXTENSION_GROUPS_TABLE . ' ' : 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET ';
   1.552 +						$sql .= $db->sql_build_array((($action == 'add') ? 'INSERT' : 'UPDATE'), $group_ary);
   1.553 +						$sql .= ($action == 'edit') ? " WHERE group_id = $group_id" : '';
   1.554 +
   1.555 +						$db->sql_query($sql);
   1.556 +
   1.557 +						if ($action == 'add')
   1.558 +						{
   1.559 +							$group_id = $db->sql_nextid();
   1.560 +						}
   1.561 +
   1.562 +						$group_name = (isset($user->lang['EXT_GROUP_' . $group_name])) ? $user->lang['EXT_GROUP_' . $group_name] : $group_name;
   1.563 +						add_log('admin', 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), $group_name);
   1.564 +					}
   1.565 +
   1.566 +					$extension_list = request_var('extensions', array(0));
   1.567 +
   1.568 +					if ($action == 'edit' && sizeof($extension_list))
   1.569 +					{
   1.570 +						$sql = 'UPDATE ' . EXTENSIONS_TABLE . "
   1.571 +							SET group_id = 0
   1.572 +							WHERE group_id = $group_id";
   1.573 +						$db->sql_query($sql);
   1.574 +					}
   1.575 +
   1.576 +					if (sizeof($extension_list))
   1.577 +					{
   1.578 +						$sql = 'UPDATE ' . EXTENSIONS_TABLE . "
   1.579 +							SET group_id = $group_id
   1.580 +							WHERE " . $db->sql_in_set('extension_id', $extension_list);
   1.581 +						$db->sql_query($sql);
   1.582 +					}
   1.583 +
   1.584 +					$cache->destroy('_extensions');
   1.585 +
   1.586 +					if (!sizeof($error))
   1.587 +					{
   1.588 +						$notify[] = $user->lang['SUCCESS_EXTENSION_GROUP_' . strtoupper($action)];
   1.589 +					}
   1.590 +				}
   1.591 +
   1.592 +				$cat_lang = array(
   1.593 +					ATTACHMENT_CATEGORY_NONE		=> $user->lang['NO_FILE_CAT'],
   1.594 +					ATTACHMENT_CATEGORY_IMAGE		=> $user->lang['CAT_IMAGES'],
   1.595 +					ATTACHMENT_CATEGORY_WM			=> $user->lang['CAT_WM_FILES'],
   1.596 +					ATTACHMENT_CATEGORY_RM			=> $user->lang['CAT_RM_FILES'],
   1.597 +					ATTACHMENT_CATEGORY_FLASH		=> $user->lang['CAT_FLASH_FILES'],
   1.598 +					ATTACHMENT_CATEGORY_QUICKTIME	=> $user->lang['CAT_QUICKTIME_FILES'],
   1.599 +				);
   1.600 +
   1.601 +				$group_id = request_var('g', 0);
   1.602 +				$action = (isset($_POST['add'])) ? 'add' : $action;
   1.603 +
   1.604 +				switch ($action)
   1.605 +				{
   1.606 +					case 'delete':
   1.607 +
   1.608 +						if (confirm_box(true))
   1.609 +						{
   1.610 +							$sql = 'SELECT group_name
   1.611 +								FROM ' . EXTENSION_GROUPS_TABLE . "
   1.612 +								WHERE group_id = $group_id";
   1.613 +							$result = $db->sql_query($sql);
   1.614 +							$group_name = (string) $db->sql_fetchfield('group_name');
   1.615 +							$db->sql_freeresult($result);
   1.616 +
   1.617 +							$sql = 'DELETE
   1.618 +								FROM ' . EXTENSION_GROUPS_TABLE . "
   1.619 +								WHERE group_id = $group_id";
   1.620 +							$db->sql_query($sql);
   1.621 +
   1.622 +							// Set corresponding Extensions to a pending Group
   1.623 +							$sql = 'UPDATE ' . EXTENSIONS_TABLE . "
   1.624 +								SET group_id = 0
   1.625 +								WHERE group_id = $group_id";
   1.626 +							$db->sql_query($sql);
   1.627 +
   1.628 +							add_log('admin', 'LOG_ATTACH_EXTGROUP_DEL', $group_name);
   1.629 +
   1.630 +							$cache->destroy('_extensions');
   1.631 +
   1.632 +							trigger_error($user->lang['EXTENSION_GROUP_DELETED'] . adm_back_link($this->u_action));
   1.633 +						}
   1.634 +						else
   1.635 +						{
   1.636 +							confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
   1.637 +								'i'			=> $id,
   1.638 +								'mode'		=> $mode,
   1.639 +								'group_id'	=> $group_id,
   1.640 +								'action'	=> 'delete',
   1.641 +							)));
   1.642 +						}
   1.643 +
   1.644 +					break;
   1.645 +
   1.646 +					case 'edit':
   1.647 +
   1.648 +						if (!$group_id)
   1.649 +						{
   1.650 +							trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
   1.651 +						}
   1.652 +
   1.653 +						$sql = 'SELECT *
   1.654 +							FROM ' . EXTENSION_GROUPS_TABLE . "
   1.655 +							WHERE group_id = $group_id";
   1.656 +						$result = $db->sql_query($sql);
   1.657 +						$ext_group_row = $db->sql_fetchrow($result);
   1.658 +						$db->sql_freeresult($result);
   1.659 +
   1.660 +						$forum_ids = (!$ext_group_row['allowed_forums']) ? array() : unserialize(trim($ext_group_row['allowed_forums']));
   1.661 +
   1.662 +					// no break;
   1.663 +
   1.664 +					case 'add':
   1.665 +
   1.666 +						if ($action == 'add')
   1.667 +						{
   1.668 +							$ext_group_row = array(
   1.669 +								'group_name'	=> utf8_normalize_nfc(request_var('group_name', '', true)),
   1.670 +								'cat_id'		=> 0,
   1.671 +								'allow_group'	=> 1,
   1.672 +								'allow_in_pm'	=> 1,
   1.673 +								'upload_icon'	=> '',
   1.674 +								'max_filesize'	=> 0,
   1.675 +							);
   1.676 +
   1.677 +							$forum_ids = array();
   1.678 +						}
   1.679 +
   1.680 +						$extensions = array();
   1.681 +
   1.682 +						$sql = 'SELECT *
   1.683 +							FROM ' . EXTENSIONS_TABLE . "
   1.684 +							WHERE group_id = $group_id
   1.685 +								OR group_id = 0
   1.686 +							ORDER BY extension";
   1.687 +						$result = $db->sql_query($sql);
   1.688 +						$extensions = $db->sql_fetchrowset($result);
   1.689 +						$db->sql_freeresult($result);
   1.690 +
   1.691 +						if ($ext_group_row['max_filesize'] == 0)
   1.692 +						{
   1.693 +							$ext_group_row['max_filesize'] = (int) $config['max_filesize'];
   1.694 +						}
   1.695 +
   1.696 +						$max_filesize = get_formatted_filesize($ext_group_row['max_filesize'], false, array('mb', 'kb', 'b'));
   1.697 +						$size_format = $max_filesize['si_identifier'];
   1.698 +						$ext_group_row['max_filesize'] = $max_filesize['value'];
   1.699 +
   1.700 +						$img_path = $config['upload_icons_path'];
   1.701 +
   1.702 +						$filename_list = '';
   1.703 +						$no_image_select = false;
   1.704 +
   1.705 +						$imglist = filelist($phpbb_root_path . $img_path);
   1.706 +
   1.707 +						if (!empty($imglist['']))
   1.708 +						{
   1.709 +							$imglist = array_values($imglist);
   1.710 +							$imglist = $imglist[0];
   1.711 +
   1.712 +							foreach ($imglist as $key => $img)
   1.713 +							{
   1.714 +								if (!$ext_group_row['upload_icon'])
   1.715 +								{
   1.716 +									$no_image_select = true;
   1.717 +									$selected = '';
   1.718 +								}
   1.719 +								else
   1.720 +								{
   1.721 +									$selected = ($ext_group_row['upload_icon'] == $img) ? ' selected="selected"' : '';
   1.722 +								}
   1.723 +
   1.724 +								if (strlen($img) > 255)
   1.725 +								{
   1.726 +									continue;
   1.727 +								}
   1.728 +
   1.729 +								$filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . htmlspecialchars($img) . '</option>';
   1.730 +							}
   1.731 +						}
   1.732 +
   1.733 +						$i = 0;
   1.734 +						$assigned_extensions = '';
   1.735 +						foreach ($extensions as $num => $row)
   1.736 +						{
   1.737 +							if ($row['group_id'] == $group_id && $group_id)
   1.738 +							{
   1.739 +								$assigned_extensions .= ($i) ? ', ' . $row['extension'] : $row['extension'];
   1.740 +								$i++;
   1.741 +							}
   1.742 +						}
   1.743 +
   1.744 +						$s_extension_options = '';
   1.745 +						foreach ($extensions as $row)
   1.746 +						{
   1.747 +							$s_extension_options .= '<option' . ((!$row['group_id']) ? ' class="disabled"' : '') . ' value="' . $row['extension_id'] . '"' . (($row['group_id'] == $group_id && $group_id) ? ' selected="selected"' : '') . '>' . $row['extension'] . '</option>';
   1.748 +						}
   1.749 +
   1.750 +						$template->assign_vars(array(
   1.751 +							'PHPBB_ROOT_PATH'		=> $phpbb_root_path,
   1.752 +							'IMG_PATH'				=> $img_path,
   1.753 +							'ACTION'				=> $action,
   1.754 +							'GROUP_ID'				=> $group_id,
   1.755 +							'GROUP_NAME'			=> $ext_group_row['group_name'],
   1.756 +							'ALLOW_GROUP'			=> $ext_group_row['allow_group'],
   1.757 +							'ALLOW_IN_PM'			=> $ext_group_row['allow_in_pm'],
   1.758 +							'UPLOAD_ICON_SRC'		=> $phpbb_root_path . $img_path . '/' . $ext_group_row['upload_icon'],
   1.759 +							'EXTGROUP_FILESIZE'		=> $ext_group_row['max_filesize'],
   1.760 +							'ASSIGNED_EXTENSIONS'	=> $assigned_extensions,
   1.761 +
   1.762 +							'S_CATEGORY_SELECT'			=> $this->category_select('special_category', $group_id, 'category'),
   1.763 +							'S_EXT_GROUP_SIZE_OPTIONS'	=> size_select_options($size_format),
   1.764 +							'S_EXTENSION_OPTIONS'		=> $s_extension_options,
   1.765 +							'S_FILENAME_LIST'			=> $filename_list,
   1.766 +							'S_EDIT_GROUP'				=> true,
   1.767 +							'S_NO_IMAGE'				=> $no_image_select,
   1.768 +							'S_FORUM_IDS'				=> (sizeof($forum_ids)) ? true : false,
   1.769 +
   1.770 +							'U_EXTENSIONS'		=> append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=extensions"),
   1.771 +							'U_BACK'			=> $this->u_action,
   1.772 +
   1.773 +							'L_LEGEND'			=> $user->lang[strtoupper($action) . '_EXTENSION_GROUP'])
   1.774 +						);
   1.775 +
   1.776 +						$s_forum_id_options = '';
   1.777 +
   1.778 +						/** @todo use in-built function **/
   1.779 +
   1.780 +						$sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
   1.781 +							FROM ' . FORUMS_TABLE . '
   1.782 +							ORDER BY left_id ASC';
   1.783 +						$result = $db->sql_query($sql, 600);
   1.784 +
   1.785 +						$right = $cat_right = $padding_inc = 0;
   1.786 +						$padding = $forum_list = $holding = '';
   1.787 +						$padding_store = array('0' => '');
   1.788 +
   1.789 +						while ($row = $db->sql_fetchrow($result))
   1.790 +						{
   1.791 +							if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
   1.792 +							{
   1.793 +								// Non-postable forum with no subforums, don't display
   1.794 +								continue;
   1.795 +							}
   1.796 +
   1.797 +							if (!$auth->acl_get('f_list', $row['forum_id']))
   1.798 +							{
   1.799 +								// if the user does not have permissions to list this forum skip
   1.800 +								continue;
   1.801 +							}
   1.802 +
   1.803 +							if ($row['left_id'] < $right)
   1.804 +							{
   1.805 +								$padding .= '&nbsp; &nbsp;';
   1.806 +								$padding_store[$row['parent_id']] = $padding;
   1.807 +							}
   1.808 +							else if ($row['left_id'] > $right + 1)
   1.809 +							{
   1.810 +								$padding = empty($padding_store[$row['parent_id']]) ? '' : $padding_store[$row['parent_id']];
   1.811 +							}
   1.812 +
   1.813 +							$right = $row['right_id'];
   1.814 +
   1.815 +							$selected = (in_array($row['forum_id'], $forum_ids)) ? ' selected="selected"' : '';
   1.816 +
   1.817 +							if ($row['left_id'] > $cat_right)
   1.818 +							{
   1.819 +								// make sure we don't forget anything
   1.820 +								$s_forum_id_options .= $holding;
   1.821 +								$holding = '';
   1.822 +							}
   1.823 +
   1.824 +							if ($row['right_id'] - $row['left_id'] > 1)
   1.825 +							{
   1.826 +								$cat_right = max($cat_right, $row['right_id']);
   1.827 +
   1.828 +								$holding .= '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
   1.829 +							}
   1.830 +							else
   1.831 +							{
   1.832 +								$s_forum_id_options .= $holding . '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
   1.833 +								$holding = '';
   1.834 +							}
   1.835 +						}
   1.836 +
   1.837 +						if ($holding)
   1.838 +						{
   1.839 +							$s_forum_id_options .= $holding;
   1.840 +						}
   1.841 +
   1.842 +						$db->sql_freeresult($result);
   1.843 +						unset($padding_store);
   1.844 +
   1.845 +						$template->assign_vars(array(
   1.846 +							'S_FORUM_ID_OPTIONS'	=> $s_forum_id_options)
   1.847 +						);
   1.848 +
   1.849 +					break;
   1.850 +				}
   1.851 +
   1.852 +				$sql = 'SELECT *
   1.853 +					FROM ' . EXTENSION_GROUPS_TABLE . '
   1.854 +					ORDER BY allow_group DESC, allow_in_pm DESC, group_name';
   1.855 +				$result = $db->sql_query($sql);
   1.856 +
   1.857 +				$old_allow_group = $old_allow_pm = 1;
   1.858 +				while ($row = $db->sql_fetchrow($result))
   1.859 +				{
   1.860 +					$s_add_spacer = ($old_allow_group != $row['allow_group'] || $old_allow_pm != $row['allow_in_pm']) ? true : false;
   1.861 +
   1.862 +					$template->assign_block_vars('groups', array(
   1.863 +						'S_ADD_SPACER'		=> $s_add_spacer,
   1.864 +						'S_ALLOWED_IN_PM'	=> ($row['allow_in_pm']) ? true : false,
   1.865 +						'S_GROUP_ALLOWED'	=> ($row['allow_group']) ? true : false,
   1.866 +
   1.867 +						'U_EDIT'		=> $this->u_action . "&amp;action=edit&amp;g={$row['group_id']}",
   1.868 +						'U_DELETE'		=> $this->u_action . "&amp;action=delete&amp;g={$row['group_id']}",
   1.869 +
   1.870 +						'GROUP_NAME'	=> (isset($user->lang['EXT_GROUP_' . $row['group_name']])) ? $user->lang['EXT_GROUP_' . $row['group_name']] : $row['group_name'],
   1.871 +						'CATEGORY'		=> $cat_lang[$row['cat_id']],
   1.872 +						)
   1.873 +					);
   1.874 +
   1.875 +					$old_allow_group = $row['allow_group'];
   1.876 +					$old_allow_pm = $row['allow_in_pm'];
   1.877 +				}
   1.878 +				$db->sql_freeresult($result);
   1.879 +
   1.880 +			break;
   1.881 +
   1.882 +			case 'orphan':
   1.883 +
   1.884 +				if ($submit)
   1.885 +				{
   1.886 +					$delete_files = (isset($_POST['delete'])) ? array_keys(request_var('delete', array('' => 0))) : array();
   1.887 +					$add_files = (isset($_POST['add'])) ? array_keys(request_var('add', array('' => 0))) : array();
   1.888 +					$post_ids = request_var('post_id', array('' => 0));
   1.889 +
   1.890 +					if (sizeof($delete_files))
   1.891 +					{
   1.892 +						$sql = 'SELECT *
   1.893 +							FROM ' . ATTACHMENTS_TABLE . '
   1.894 +							WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
   1.895 +								AND is_orphan = 1';
   1.896 +						$result = $db->sql_query($sql);
   1.897 +
   1.898 +						$delete_files = array();
   1.899 +						while ($row = $db->sql_fetchrow($result))
   1.900 +						{
   1.901 +							phpbb_unlink($row['physical_filename'], 'file');
   1.902 +
   1.903 +							if ($row['thumbnail'])
   1.904 +							{
   1.905 +								phpbb_unlink($row['physical_filename'], 'thumbnail');
   1.906 +							}
   1.907 +
   1.908 +							$delete_files[$row['attach_id']] = $row['real_filename'];
   1.909 +						}
   1.910 +						$db->sql_freeresult($result);
   1.911 +					}
   1.912 +
   1.913 +					if (sizeof($delete_files))
   1.914 +					{
   1.915 +						$sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
   1.916 +							WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files));
   1.917 +						$db->sql_query($sql);
   1.918 +
   1.919 +						add_log('admin', 'LOG_ATTACH_ORPHAN_DEL', implode(', ', $delete_files));
   1.920 +						$notify[] = sprintf($user->lang['LOG_ATTACH_ORPHAN_DEL'], implode(', ', $delete_files));
   1.921 +					}
   1.922 +
   1.923 +					$upload_list = array();
   1.924 +					foreach ($add_files as $attach_id)
   1.925 +					{
   1.926 +						if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id]))
   1.927 +						{
   1.928 +							$upload_list[$attach_id] = $post_ids[$attach_id];
   1.929 +						}
   1.930 +					}
   1.931 +					unset($add_files);
   1.932 +
   1.933 +					if (sizeof($upload_list))
   1.934 +					{
   1.935 +						$template->assign_var('S_UPLOADING_FILES', true);
   1.936 +
   1.937 +						$sql = 'SELECT forum_id, forum_name
   1.938 +							FROM ' . FORUMS_TABLE;
   1.939 +						$result = $db->sql_query($sql);
   1.940 +
   1.941 +						$forum_names = array();
   1.942 +						while ($row = $db->sql_fetchrow($result))
   1.943 +						{
   1.944 +							$forum_names[$row['forum_id']] = $row['forum_name'];
   1.945 +						}
   1.946 +						$db->sql_freeresult($result);
   1.947 +
   1.948 +						$sql = 'SELECT forum_id, topic_id, post_id, poster_id
   1.949 +							FROM ' . POSTS_TABLE . '
   1.950 +							WHERE ' . $db->sql_in_set('post_id', $upload_list);
   1.951 +						$result = $db->sql_query($sql);
   1.952 +
   1.953 +						$post_info = array();
   1.954 +						while ($row = $db->sql_fetchrow($result))
   1.955 +						{
   1.956 +							$post_info[$row['post_id']] = $row;
   1.957 +						}
   1.958 +						$db->sql_freeresult($result);
   1.959 +
   1.960 +						// Select those attachments we want to change...
   1.961 +						$sql = 'SELECT *
   1.962 +							FROM ' . ATTACHMENTS_TABLE . '
   1.963 +							WHERE ' . $db->sql_in_set('attach_id', array_keys($upload_list)) . '
   1.964 +								AND is_orphan = 1';
   1.965 +						$result = $db->sql_query($sql);
   1.966 +
   1.967 +						$files_added = $space_taken = 0;
   1.968 +						while ($row = $db->sql_fetchrow($result))
   1.969 +						{
   1.970 +							$post_row = $post_info[$upload_list[$row['attach_id']]];
   1.971 +
   1.972 +							$template->assign_block_vars('upload', array(
   1.973 +								'FILE_INFO'		=> sprintf($user->lang['UPLOADING_FILE_TO'], $row['real_filename'], $post_row['post_id']),
   1.974 +								'S_DENIED'		=> (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? true : false,
   1.975 +								'L_DENIED'		=> (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? sprintf($user->lang['UPLOAD_DENIED_FORUM'], $forum_names[$row['forum_id']]) : '')
   1.976 +							);
   1.977 +
   1.978 +							if (!$auth->acl_get('f_attach', $post_row['forum_id']))
   1.979 +							{
   1.980 +								continue;
   1.981 +							}
   1.982 +
   1.983 +							// Adjust attachment entry
   1.984 +							$sql_ary = array(
   1.985 +								'in_message'	=> 0,
   1.986 +								'is_orphan'		=> 0,
   1.987 +								'poster_id'		=> $post_row['poster_id'],
   1.988 +								'post_msg_id'	=> $post_row['post_id'],
   1.989 +								'topic_id'		=> $post_row['topic_id'],
   1.990 +							);
   1.991 +
   1.992 +							$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
   1.993 +								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
   1.994 +								WHERE attach_id = ' . $row['attach_id'];
   1.995 +							$db->sql_query($sql);
   1.996 +
   1.997 +							$sql = 'UPDATE ' . POSTS_TABLE . '
   1.998 +								SET post_attachment = 1
   1.999 +								WHERE post_id = ' . $post_row['post_id'];
  1.1000 +							$db->sql_query($sql);
  1.1001 +
  1.1002 +							$sql = 'UPDATE ' . TOPICS_TABLE . '
  1.1003 +								SET topic_attachment = 1
  1.1004 +								WHERE topic_id = ' . $post_row['topic_id'];
  1.1005 +							$db->sql_query($sql);
  1.1006 +
  1.1007 +							$space_taken += $row['filesize'];
  1.1008 +							$files_added++;
  1.1009 +
  1.1010 +							add_log('admin', 'LOG_ATTACH_FILEUPLOAD', $post_row['post_id'], $row['real_filename']);
  1.1011 +						}
  1.1012 +						$db->sql_freeresult($result);
  1.1013 +
  1.1014 +						if ($files_added)
  1.1015 +						{
  1.1016 +							set_config_count('upload_dir_size', $space_taken, true);
  1.1017 +							set_config_count('num_files', $files_added, true);
  1.1018 +						}
  1.1019 +					}
  1.1020 +				}
  1.1021 +
  1.1022 +				$template->assign_vars(array(
  1.1023 +					'S_ORPHAN'		=> true)
  1.1024 +				);
  1.1025 +
  1.1026 +				// Just get the files with is_orphan set and older than 3 hours
  1.1027 +				$sql = 'SELECT *
  1.1028 +					FROM ' . ATTACHMENTS_TABLE . '
  1.1029 +					WHERE is_orphan = 1
  1.1030 +						AND filetime < ' . (time() - 3*60*60) . '
  1.1031 +					ORDER BY filetime DESC';
  1.1032 +				$result = $db->sql_query($sql);
  1.1033 +
  1.1034 +				while ($row = $db->sql_fetchrow($result))
  1.1035 +				{
  1.1036 +					$template->assign_block_vars('orphan', array(
  1.1037 +						'FILESIZE'			=> get_formatted_filesize($row['filesize']),
  1.1038 +						'FILETIME'			=> $user->format_date($row['filetime']),
  1.1039 +						'REAL_FILENAME'		=> utf8_basename($row['real_filename']),
  1.1040 +						'PHYSICAL_FILENAME'	=> utf8_basename($row['physical_filename']),
  1.1041 +						'ATTACH_ID'			=> $row['attach_id'],
  1.1042 +						'POST_IDS'			=> (!empty($post_ids[$row['attach_id']])) ? $post_ids[$row['attach_id']] : '',
  1.1043 +						'U_FILE'			=> append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id']))
  1.1044 +					);
  1.1045 +				}
  1.1046 +				$db->sql_freeresult($result);
  1.1047 +
  1.1048 +			break;
  1.1049 +		}
  1.1050 +
  1.1051 +		if (sizeof($error))
  1.1052 +		{
  1.1053 +			$template->assign_vars(array(
  1.1054 +				'S_WARNING'		=> true,
  1.1055 +				'WARNING_MSG'	=> implode('<br />', $error))
  1.1056 +			);
  1.1057 +		}
  1.1058 +
  1.1059 +		if (sizeof($notify))
  1.1060 +		{
  1.1061 +			$template->assign_vars(array(
  1.1062 +				'S_NOTIFY'		=> true,
  1.1063 +				'NOTIFY_MSG'	=> implode('<br />', $notify))
  1.1064 +			);
  1.1065 +		}
  1.1066 +	}
  1.1067 +
  1.1068 +	/**
  1.1069 +	* Build Select for category items
  1.1070 +	*/
  1.1071 +	function category_select($select_name, $group_id = false, $key = '')
  1.1072 +	{
  1.1073 +		global $db, $user;
  1.1074 +
  1.1075 +		$types = array(
  1.1076 +			ATTACHMENT_CATEGORY_NONE		=> $user->lang['NO_FILE_CAT'],
  1.1077 +			ATTACHMENT_CATEGORY_IMAGE		=> $user->lang['CAT_IMAGES'],
  1.1078 +			ATTACHMENT_CATEGORY_WM			=> $user->lang['CAT_WM_FILES'],
  1.1079 +			ATTACHMENT_CATEGORY_RM			=> $user->lang['CAT_RM_FILES'],
  1.1080 +			ATTACHMENT_CATEGORY_FLASH		=> $user->lang['CAT_FLASH_FILES'],
  1.1081 +			ATTACHMENT_CATEGORY_QUICKTIME	=> $user->lang['CAT_QUICKTIME_FILES'],
  1.1082 +		);
  1.1083 +
  1.1084 +		if ($group_id)
  1.1085 +		{
  1.1086 +			$sql = 'SELECT cat_id
  1.1087 +				FROM ' . EXTENSION_GROUPS_TABLE . '
  1.1088 +				WHERE group_id = ' . (int) $group_id;
  1.1089 +			$result = $db->sql_query($sql);
  1.1090 +
  1.1091 +			$cat_type = (!($row = $db->sql_fetchrow($result))) ? ATTACHMENT_CATEGORY_NONE : $row['cat_id'];
  1.1092 +
  1.1093 +			$db->sql_freeresult($result);
  1.1094 +		}
  1.1095 +		else
  1.1096 +		{
  1.1097 +			$cat_type = ATTACHMENT_CATEGORY_NONE;
  1.1098 +		}
  1.1099 +
  1.1100 +		$group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
  1.1101 +
  1.1102 +		foreach ($types as $type => $mode)
  1.1103 +		{
  1.1104 +			$selected = ($type == $cat_type) ? ' selected="selected"' : '';
  1.1105 +			$group_select .= '<option value="' . $type . '"' . $selected . '>' . $mode . '</option>';
  1.1106 +		}
  1.1107 +
  1.1108 +		$group_select .= '</select>';
  1.1109 +
  1.1110 +		return $group_select;
  1.1111 +	}
  1.1112 +
  1.1113 +	/**
  1.1114 +	* Extension group select
  1.1115 +	*/
  1.1116 +	function group_select($select_name, $default_group = false, $key = '')
  1.1117 +	{
  1.1118 +		global $db, $user;
  1.1119 +
  1.1120 +		$group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
  1.1121 +
  1.1122 +		$sql = 'SELECT group_id, group_name
  1.1123 +			FROM ' . EXTENSION_GROUPS_TABLE . '
  1.1124 +			ORDER BY group_name';
  1.1125 +		$result = $db->sql_query($sql);
  1.1126 +
  1.1127 +		$group_name = array();
  1.1128 +		while ($row = $db->sql_fetchrow($result))
  1.1129 +		{
  1.1130 +			$row['group_name'] = (isset($user->lang['EXT_GROUP_' . $row['group_name']])) ? $user->lang['EXT_GROUP_' . $row['group_name']] : $row['group_name'];
  1.1131 +			$group_name[] = $row;
  1.1132 +		}
  1.1133 +		$db->sql_freeresult($result);
  1.1134 +
  1.1135 +		$row['group_id'] = 0;
  1.1136 +		$row['group_name'] = $user->lang['NOT_ASSIGNED'];
  1.1137 +		$group_name[] = $row;
  1.1138 +
  1.1139 +		for ($i = 0; $i < sizeof($group_name); $i++)
  1.1140 +		{
  1.1141 +			if ($default_group === false)
  1.1142 +			{
  1.1143 +				$selected = ($i == 0) ? ' selected="selected"' : '';
  1.1144 +			}
  1.1145 +			else
  1.1146 +			{
  1.1147 +				$selected = ($group_name[$i]['group_id'] == $default_group) ? ' selected="selected"' : '';
  1.1148 +			}
  1.1149 +
  1.1150 +			$group_select .= '<option value="' . $group_name[$i]['group_id'] . '"' . $selected . '>' . $group_name[$i]['group_name'] . '</option>';
  1.1151 +		}
  1.1152 +
  1.1153 +		$group_select .= '</select>';
  1.1154 +
  1.1155 +		return $group_select;
  1.1156 +	}
  1.1157 +
  1.1158 +	/**
  1.1159 +	* Search Imagick
  1.1160 +	*/
  1.1161 +	function search_imagemagick()
  1.1162 +	{
  1.1163 +		$imagick = '';
  1.1164 +
  1.1165 +		$exe = ((defined('PHP_OS')) && (preg_match('#^win#i', PHP_OS))) ? '.exe' : '';
  1.1166 +
  1.1167 +		$magic_home = getenv('MAGICK_HOME');
  1.1168 +
  1.1169 +		if (empty($magic_home))
  1.1170 +		{
  1.1171 +			$locations = array('C:/WINDOWS/', 'C:/WINNT/', 'C:/WINDOWS/SYSTEM/', 'C:/WINNT/SYSTEM/', 'C:/WINDOWS/SYSTEM32/', 'C:/WINNT/SYSTEM32/', '/usr/bin/', '/usr/sbin/', '/usr/local/bin/', '/usr/local/sbin/', '/opt/', '/usr/imagemagick/', '/usr/bin/imagemagick/');
  1.1172 +			$path_locations = str_replace('\\', '/', (explode(($exe) ? ';' : ':', getenv('PATH'))));
  1.1173 +
  1.1174 +			$locations = array_merge($path_locations, $locations);
  1.1175 +
  1.1176 +			foreach ($locations as $location)
  1.1177 +			{
  1.1178 +				// The path might not end properly, fudge it
  1.1179 +				if (substr($location, -1) !== '/')
  1.1180 +				{
  1.1181 +					$location .= '/';
  1.1182 +				}
  1.1183 +
  1.1184 +				if (@file_exists($location) && @is_readable($location . 'mogrify' . $exe) && @filesize($location . 'mogrify' . $exe) > 3000)
  1.1185 +				{
  1.1186 +					$imagick = str_replace('\\', '/', $location);
  1.1187 +					continue;
  1.1188 +				}
  1.1189 +			}
  1.1190 +		}
  1.1191 +		else
  1.1192 +		{
  1.1193 +			$imagick = str_replace('\\', '/', $magic_home);
  1.1194 +		}
  1.1195 +
  1.1196 +		return $imagick;
  1.1197 +	}
  1.1198 +
  1.1199 +	/**
  1.1200 +	* Test Settings
  1.1201 +	*/
  1.1202 +	function test_upload(&$error, $upload_dir, $create_directory = false)
  1.1203 +	{
  1.1204 +		global $user, $phpbb_root_path;
  1.1205 +
  1.1206 +		// Does the target directory exist, is it a directory and writable.
  1.1207 +		if ($create_directory)
  1.1208 +		{
  1.1209 +			if (!file_exists($phpbb_root_path . $upload_dir))
  1.1210 +			{
  1.1211 +				@mkdir($phpbb_root_path . $upload_dir, 0777);
  1.1212 +				phpbb_chmod($phpbb_root_path . $upload_dir, CHMOD_READ | CHMOD_WRITE);
  1.1213 +			}
  1.1214 +		}
  1.1215 +
  1.1216 +		if (!file_exists($phpbb_root_path . $upload_dir))
  1.1217 +		{
  1.1218 +			$error[] = sprintf($user->lang['NO_UPLOAD_DIR'], $upload_dir);
  1.1219 +			return;
  1.1220 +		}
  1.1221 +
  1.1222 +		if (!is_dir($phpbb_root_path . $upload_dir))
  1.1223 +		{
  1.1224 +			$error[] = sprintf($user->lang['UPLOAD_NOT_DIR'], $upload_dir);
  1.1225 +			return;
  1.1226 +		}
  1.1227 +
  1.1228 +		if (!phpbb_is_writable($phpbb_root_path . $upload_dir))
  1.1229 +		{
  1.1230 +			$error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir);
  1.1231 +			return;
  1.1232 +		}
  1.1233 +	}
  1.1234 +
  1.1235 +	/**
  1.1236 +	* Perform operations on sites for external linking
  1.1237 +	*/
  1.1238 +	function perform_site_list()
  1.1239 +	{
  1.1240 +		global $db, $user;
  1.1241 +
  1.1242 +		if (isset($_REQUEST['securesubmit']))
  1.1243 +		{
  1.1244 +			// Grab the list of entries
  1.1245 +			$ips = request_var('ips', '');
  1.1246 +			$ip_list = array_unique(explode("\n", $ips));
  1.1247 +			$ip_list_log = implode(', ', $ip_list);
  1.1248 +
  1.1249 +			$ip_exclude = (!empty($_POST['ipexclude'])) ? 1 : 0;
  1.1250 +
  1.1251 +			$iplist = array();
  1.1252 +			$hostlist = array();
  1.1253 +
  1.1254 +			foreach ($ip_list as $item)
  1.1255 +			{
  1.1256 +				if (preg_match('#^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})[ ]*\-[ ]*([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$#', trim($item), $ip_range_explode))
  1.1257 +				{
  1.1258 +					// Don't ask about all this, just don't ask ... !
  1.1259 +					$ip_1_counter = $ip_range_explode[1];
  1.1260 +					$ip_1_end = $ip_range_explode[5];
  1.1261 +
  1.1262 +					while ($ip_1_counter <= $ip_1_end)
  1.1263 +					{
  1.1264 +						$ip_2_counter = ($ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[2] : 0;
  1.1265 +						$ip_2_end = ($ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[6];
  1.1266 +
  1.1267 +						if ($ip_2_counter == 0 && $ip_2_end == 254)
  1.1268 +						{
  1.1269 +							$ip_2_counter = 256;
  1.1270 +							$ip_2_fragment = 256;
  1.1271 +
  1.1272 +							$iplist[] = "'$ip_1_counter.*'";
  1.1273 +						}
  1.1274 +
  1.1275 +						while ($ip_2_counter <= $ip_2_end)
  1.1276 +						{
  1.1277 +							$ip_3_counter = ($ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[3] : 0;
  1.1278 +							$ip_3_end = ($ip_2_counter < $ip_2_end || $ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[7];
  1.1279 +
  1.1280 +							if ($ip_3_counter == 0 && $ip_3_end == 254)
  1.1281 +							{
  1.1282 +								$ip_3_counter = 256;
  1.1283 +								$ip_3_fragment = 256;
  1.1284 +
  1.1285 +								$iplist[] = "'$ip_1_counter.$ip_2_counter.*'";
  1.1286 +							}
  1.1287 +
  1.1288 +							while ($ip_3_counter <= $ip_3_end)
  1.1289 +							{
  1.1290 +								$ip_4_counter = ($ip_3_counter == $ip_range_explode[3] && $ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[4] : 0;
  1.1291 +								$ip_4_end = ($ip_3_counter < $ip_3_end || $ip_2_counter < $ip_2_end) ? 254 : $ip_range_explode[8];
  1.1292 +
  1.1293 +								if ($ip_4_counter == 0 && $ip_4_end == 254)
  1.1294 +								{
  1.1295 +									$ip_4_counter = 256;
  1.1296 +									$ip_4_fragment = 256;
  1.1297 +
  1.1298 +									$iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.*'";
  1.1299 +								}
  1.1300 +
  1.1301 +								while ($ip_4_counter <= $ip_4_end)
  1.1302 +								{
  1.1303 +									$iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.$ip_4_counter'";
  1.1304 +									$ip_4_counter++;
  1.1305 +								}
  1.1306 +								$ip_3_counter++;
  1.1307 +							}
  1.1308 +							$ip_2_counter++;
  1.1309 +						}
  1.1310 +						$ip_1_counter++;
  1.1311 +					}
  1.1312 +				}
  1.1313 +				else if (preg_match('#^([0-9]{1,3})\.([0-9\*]{1,3})\.([0-9\*]{1,3})\.([0-9\*]{1,3})$#', trim($item)) || preg_match('#^[a-f0-9:]+\*?$#i', trim($item)))
  1.1314 +				{
  1.1315 +					$iplist[] = "'" . trim($item) . "'";
  1.1316 +				}
  1.1317 +				else if (preg_match('#^([\w\-_]\.?){2,}$#is', trim($item)))
  1.1318 +				{
  1.1319 +					$hostlist[] = "'" . trim($item) . "'";
  1.1320 +				}
  1.1321 +				else if (preg_match("#^([a-z0-9\-\*\._/]+?)$#is", trim($item)))
  1.1322 +				{
  1.1323 +					$hostlist[] = "'" . trim($item) . "'";
  1.1324 +				}
  1.1325 +			}
  1.1326 +
  1.1327 +			$sql = 'SELECT site_ip, site_hostname
  1.1328 +				FROM ' . SITELIST_TABLE . "
  1.1329 +				WHERE ip_exclude = $ip_exclude";
  1.1330 +			$result = $db->sql_query($sql);
  1.1331 +
  1.1332 +			if ($row = $db->sql_fetchrow($result))
  1.1333 +			{
  1.1334 +				$iplist_tmp = array();
  1.1335 +				$hostlist_tmp = array();
  1.1336 +				do
  1.1337 +				{
  1.1338 +					if ($row['site_ip'])
  1.1339 +					{
  1.1340 +						if (strlen($row['site_ip']) > 40)
  1.1341 +						{
  1.1342 +							continue;
  1.1343 +						}
  1.1344 +
  1.1345 +						$iplist_tmp[] = "'" . $row['site_ip'] . "'";
  1.1346 +					}
  1.1347 +					else if ($row['site_hostname'])
  1.1348 +					{
  1.1349 +						if (strlen($row['site_hostname']) > 255)
  1.1350 +						{
  1.1351 +							continue;
  1.1352 +						}
  1.1353 +
  1.1354 +						$hostlist_tmp[] = "'" . $row['site_hostname'] . "'";
  1.1355 +					}
  1.1356 +					// break;
  1.1357 +				}
  1.1358 +				while ($row = $db->sql_fetchrow($result));
  1.1359 +
  1.1360 +				$iplist = array_unique(array_diff($iplist, $iplist_tmp));
  1.1361 +				$hostlist = array_unique(array_diff($hostlist, $hostlist_tmp));
  1.1362 +				unset($iplist_tmp);
  1.1363 +				unset($hostlist_tmp);
  1.1364 +			}
  1.1365 +			$db->sql_freeresult($result);
  1.1366 +
  1.1367 +			if (sizeof($iplist))
  1.1368 +			{
  1.1369 +				foreach ($iplist as $ip_entry)
  1.1370 +				{
  1.1371 +					$sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_ip, ip_exclude)
  1.1372 +						VALUES ($ip_entry, $ip_exclude)";
  1.1373 +					$db->sql_query($sql);
  1.1374 +				}
  1.1375 +			}
  1.1376 +
  1.1377 +			if (sizeof($hostlist))
  1.1378 +			{
  1.1379 +				foreach ($hostlist as $host_entry)
  1.1380 +				{
  1.1381 +					$sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_hostname, ip_exclude)
  1.1382 +						VALUES ($host_entry, $ip_exclude)";
  1.1383 +					$db->sql_query($sql);
  1.1384 +				}
  1.1385 +			}
  1.1386 +
  1.1387 +			if (!empty($ip_list_log))
  1.1388 +			{
  1.1389 +				// Update log
  1.1390 +				$log_entry = ($ip_exclude) ? 'LOG_DOWNLOAD_EXCLUDE_IP' : 'LOG_DOWNLOAD_IP';
  1.1391 +				add_log('admin', $log_entry, $ip_list_log);
  1.1392 +			}
  1.1393 +
  1.1394 +			trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
  1.1395 +		}
  1.1396 +		else if (isset($_POST['unsecuresubmit']))
  1.1397 +		{
  1.1398 +			$unip_sql = request_var('unip', array(0));
  1.1399 +
  1.1400 +			if (sizeof($unip_sql))
  1.1401 +			{
  1.1402 +				$l_unip_list = '';
  1.1403 +
  1.1404 +				// Grab details of ips for logging information later
  1.1405 +				$sql = 'SELECT site_ip, site_hostname
  1.1406 +					FROM ' . SITELIST_TABLE . '
  1.1407 +					WHERE ' . $db->sql_in_set('site_id', $unip_sql);
  1.1408 +				$result = $db->sql_query($sql);
  1.1409 +
  1.1410 +				while ($row = $db->sql_fetchrow($result))
  1.1411 +				{
  1.1412 +					$l_unip_list .= (($l_unip_list != '') ? ', ' : '') . (($row['site_ip']) ? $row['site_ip'] : $row['site_hostname']);
  1.1413 +				}
  1.1414 +				$db->sql_freeresult($result);
  1.1415 +
  1.1416 +				$sql = 'DELETE FROM ' . SITELIST_TABLE . '
  1.1417 +					WHERE ' . $db->sql_in_set('site_id', $unip_sql);
  1.1418 +				$db->sql_query($sql);
  1.1419 +
  1.1420 +				add_log('admin', 'LOG_DOWNLOAD_REMOVE_IP', $l_unip_list);
  1.1421 +			}
  1.1422 +
  1.1423 +			trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
  1.1424 +		}
  1.1425 +	}
  1.1426 +
  1.1427 +	/**
  1.1428 +	* Write display_order config field
  1.1429 +	*/
  1.1430 +	function display_order($value, $key = '')
  1.1431 +	{
  1.1432 +		$radio_ary = array(0 => 'DESCENDING', 1 => 'ASCENDING');
  1.1433 +
  1.1434 +		return h_radio('config[display_order]', $radio_ary, $value, $key);
  1.1435 +	}
  1.1436 +
  1.1437 +	/**
  1.1438 +	* Adjust all three max_filesize config vars for display
  1.1439 +	*/
  1.1440 +	function max_filesize($value, $key = '')
  1.1441 +	{
  1.1442 +		// Determine size var and adjust the value accordingly
  1.1443 +		$filesize = get_formatted_filesize($value, false, array('mb', 'kb', 'b'));
  1.1444 +		$size_var = $filesize['si_identifier'];
  1.1445 +		$value = $filesize['value'];
  1.1446 +
  1.1447 +		return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
  1.1448 +	}
  1.1449 +
  1.1450 +	/**
  1.1451 +	* Write secure_allow_deny config field
  1.1452 +	*/
  1.1453 +	function select_allow_deny($value, $key = '')
  1.1454 +	{
  1.1455 +		$radio_ary = array(1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW');
  1.1456 +
  1.1457 +		return h_radio('config[' . $key . ']', $radio_ary, $value, $key);
  1.1458 +	}
  1.1459 +
  1.1460 +}
  1.1461 +
  1.1462 +?>
  1.1463 \ No newline at end of file