(a little test for later merges)
[phpbb.git] / phpBB / includes / acp / acp_attachments.php
blob849c076f0eeafa702784cc90cd18cbc2b57fafc4
1 <?php
2 /**
4 * @package acp
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 if (!defined('IN_PHPBB'))
16 exit;
19 /**
20 * @package acp
22 class acp_attachments
24 var $u_action;
25 var $new_config;
27 function main($id, $mode)
29 global $db, $user, $auth, $template, $cache;
30 global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
32 $user->add_lang(array('posting', 'viewtopic', 'acp/attachments'));
34 $error = $notify = array();
35 $submit = (isset($_POST['submit'])) ? true : false;
36 $action = request_var('action', '');
38 $form_key = 'acp_attach';
39 add_form_key($form_key);
41 if ($submit && !check_form_key($form_key))
43 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
46 switch ($mode)
48 case 'attach':
49 $l_title = 'ACP_ATTACHMENT_SETTINGS';
50 break;
52 case 'extensions':
53 $l_title = 'ACP_MANAGE_EXTENSIONS';
54 break;
56 case 'ext_groups':
57 $l_title = 'ACP_EXTENSION_GROUPS';
58 break;
60 case 'orphan':
61 $l_title = 'ACP_ORPHAN_ATTACHMENTS';
62 break;
64 default:
65 trigger_error('NO_MODE', E_USER_ERROR);
66 break;
69 $this->tpl_name = 'acp_attachments';
70 $this->page_title = $l_title;
72 $template->assign_vars(array(
73 'L_TITLE' => $user->lang[$l_title],
74 'L_TITLE_EXPLAIN' => $user->lang[$l_title . '_EXPLAIN'],
75 'U_ACTION' => $this->u_action)
78 switch ($mode)
80 case 'attach':
82 include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
84 $sql = 'SELECT group_name, cat_id
85 FROM ' . EXTENSION_GROUPS_TABLE . '
86 WHERE cat_id > 0
87 ORDER BY cat_id';
88 $result = $db->sql_query($sql);
90 $s_assigned_groups = array();
91 while ($row = $db->sql_fetchrow($result))
93 $s_assigned_groups[$row['cat_id']][] = $row['group_name'];
95 $db->sql_freeresult($result);
97 $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']) . ']';
99 $display_vars = array(
100 'title' => 'ACP_ATTACHMENT_SETTINGS',
101 'vars' => array(
102 'legend1' => 'ACP_ATTACHMENT_SETTINGS',
104 'img_max_width' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
105 'img_max_height' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
106 'img_link_width' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
107 'img_link_height' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
109 'allow_attachments' => array('lang' => 'ALLOW_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
110 'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
111 'upload_path' => array('lang' => 'UPLOAD_DIR', 'validate' => 'wpath', 'type' => 'text:25:100', 'explain' => true),
112 'display_order' => array('lang' => 'DISPLAY_ORDER', 'validate' => 'bool', 'type' => 'custom', 'method' => 'display_order', 'explain' => true),
113 'attachment_quota' => array('lang' => 'ATTACH_QUOTA', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
114 'max_filesize' => array('lang' => 'ATTACH_MAX_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
115 'max_filesize_pm' => array('lang' => 'ATTACH_MAX_PM_FILESIZE','validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true),
116 'max_attachments' => array('lang' => 'MAX_ATTACHMENTS', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false),
117 'max_attachments_pm' => array('lang' => 'MAX_ATTACHMENTS_PM', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false),
118 'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
119 'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true),
120 'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
121 'check_attachment_content' => array('lang' => 'CHECK_CONTENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
124 'legend2' => $l_legend_cat_images,
125 'img_display_inlined' => array('lang' => 'DISPLAY_INLINED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
126 'img_create_thumbnail' => array('lang' => 'CREATE_THUMBNAIL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
127 'img_max_thumb_width' => array('lang' => 'MAX_THUMB_WIDTH', 'validate' => 'int', 'type' => 'text:7:15', 'explain' => true, 'append' => ' px'),
128 'img_min_thumb_filesize' => array('lang' => 'MIN_THUMB_FILESIZE', 'validate' => 'int', 'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
129 '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>'),
130 'img_max' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),
131 'img_link' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'),
135 $this->new_config = $config;
136 $cfg_array = (isset($_REQUEST['config'])) ? request_var('config', array('' => '')) : $this->new_config;
137 $error = array();
139 // We validate the complete config if whished
140 validate_config_vars($display_vars['vars'], $cfg_array, $error);
142 // Do not write values if there is an error
143 if (sizeof($error))
145 $submit = false;
148 // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
149 foreach ($display_vars['vars'] as $config_name => $null)
151 if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
153 continue;
156 $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
158 if (in_array($config_name, array('attachment_quota', 'max_filesize', 'max_filesize_pm')))
160 $size_var = request_var($config_name, '');
161 $this->new_config[$config_name] = $config_value = ($size_var == 'kb') ? round($config_value * 1024) : (($size_var == 'mb') ? round($config_value * 1048576) : $config_value);
164 if ($submit)
166 set_config($config_name, $config_value);
170 $this->perform_site_list();
172 if ($submit)
174 add_log('admin', 'LOG_CONFIG_ATTACH');
176 // Check Settings
177 $this->test_upload($error, $this->new_config['upload_path'], false);
179 if (!sizeof($error))
181 trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
185 $template->assign_var('S_ATTACHMENT_SETTINGS', true);
187 if ($action == 'imgmagick')
189 $this->new_config['img_imagick'] = $this->search_imagemagick();
192 // We strip eventually manual added convert program, we only want the patch
193 if ($this->new_config['img_imagick'])
195 // Change path separator
196 $this->new_config['img_imagick'] = str_replace('\\', '/', $this->new_config['img_imagick']);
197 $this->new_config['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $this->new_config['img_imagick']);
199 // Check for trailing slash
200 if (substr($this->new_config['img_imagick'], -1) !== '/')
202 $this->new_config['img_imagick'] .= '/';
206 $supported_types = get_supported_image_types();
208 // Check Thumbnail Support
209 if (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format'])))
211 $this->new_config['img_create_thumbnail'] = 0;
214 $template->assign_vars(array(
215 'U_SEARCH_IMAGICK' => $this->u_action . '&amp;action=imgmagick',
216 'S_THUMBNAIL_SUPPORT' => (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format']))) ? false : true)
219 // Secure Download Options - Same procedure as with banning
220 $allow_deny = ($this->new_config['secure_allow_deny']) ? 'ALLOWED' : 'DISALLOWED';
222 $sql = 'SELECT *
223 FROM ' . SITELIST_TABLE;
224 $result = $db->sql_query($sql);
226 $defined_ips = '';
227 $ips = array();
229 while ($row = $db->sql_fetchrow($result))
231 $value = ($row['site_ip']) ? $row['site_ip'] : $row['site_hostname'];
232 if ($value)
234 $defined_ips .= '<option' . (($row['ip_exclude']) ? ' class="sep"' : '') . ' value="' . $row['site_id'] . '">' . $value . '</option>';
235 $ips[$row['site_id']] = $value;
238 $db->sql_freeresult($result);
240 $template->assign_vars(array(
241 'S_SECURE_DOWNLOADS' => $this->new_config['secure_downloads'],
242 'S_DEFINED_IPS' => ($defined_ips != '') ? true : false,
243 'S_WARNING' => (sizeof($error)) ? true : false,
245 'WARNING_MSG' => implode('<br />', $error),
246 'DEFINED_IPS' => $defined_ips,
248 'L_SECURE_TITLE' => $user->lang['DEFINE_' . $allow_deny . '_IPS'],
249 'L_IP_EXCLUDE' => $user->lang['EXCLUDE_FROM_' . $allow_deny . '_IP'],
250 'L_REMOVE_IPS' => $user->lang['REMOVE_' . $allow_deny . '_IPS'])
253 // Output relevant options
254 foreach ($display_vars['vars'] as $config_key => $vars)
256 if (!is_array($vars) && strpos($config_key, 'legend') === false)
258 continue;
261 if (strpos($config_key, 'legend') !== false)
263 $template->assign_block_vars('options', array(
264 'S_LEGEND' => true,
265 'LEGEND' => (isset($user->lang[$vars])) ? $user->lang[$vars] : $vars)
268 continue;
271 $type = explode(':', $vars['type']);
273 $l_explain = '';
274 if ($vars['explain'] && isset($vars['lang_explain']))
276 $l_explain = (isset($user->lang[$vars['lang_explain']])) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
278 else if ($vars['explain'])
280 $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
283 $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
284 if (empty($content))
286 continue;
289 $template->assign_block_vars('options', array(
290 'KEY' => $config_key,
291 'TITLE' => $user->lang[$vars['lang']],
292 'S_EXPLAIN' => $vars['explain'],
293 'TITLE_EXPLAIN' => $l_explain,
294 'CONTENT' => $content,
298 unset($display_vars['vars'][$config_key]);
301 break;
303 case 'extensions':
305 if ($submit || isset($_POST['add_extension_check']))
307 if ($submit)
309 // Change Extensions ?
310 $extension_change_list = request_var('extension_change_list', array(0));
311 $group_select_list = request_var('group_select', array(0));
313 // Generate correct Change List
314 $extensions = array();
316 for ($i = 0, $size = sizeof($extension_change_list); $i < $size; $i++)
318 $extensions[$extension_change_list[$i]]['group_id'] = $group_select_list[$i];
321 $sql = 'SELECT *
322 FROM ' . EXTENSIONS_TABLE . '
323 ORDER BY extension_id';
324 $result = $db->sql_query($sql);
326 while ($row = $db->sql_fetchrow($result))
328 if ($row['group_id'] != $extensions[$row['extension_id']]['group_id'])
330 $sql = 'UPDATE ' . EXTENSIONS_TABLE . '
331 SET group_id = ' . (int) $extensions[$row['extension_id']]['group_id'] . '
332 WHERE extension_id = ' . $row['extension_id'];
333 $db->sql_query($sql);
335 add_log('admin', 'LOG_ATTACH_EXT_UPDATE', $row['extension']);
338 $db->sql_freeresult($result);
340 // Delete Extension?
341 $extension_id_list = request_var('extension_id_list', array(0));
343 if (sizeof($extension_id_list))
345 $sql = 'SELECT extension
346 FROM ' . EXTENSIONS_TABLE . '
347 WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
348 $result = $db->sql_query($sql);
350 $extension_list = '';
351 while ($row = $db->sql_fetchrow($result))
353 $extension_list .= ($extension_list == '') ? $row['extension'] : ', ' . $row['extension'];
355 $db->sql_freeresult($result);
357 $sql = 'DELETE
358 FROM ' . EXTENSIONS_TABLE . '
359 WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
360 $db->sql_query($sql);
362 add_log('admin', 'LOG_ATTACH_EXT_DEL', $extension_list);
366 // Add Extension?
367 $add_extension = strtolower(request_var('add_extension', ''));
368 $add_extension_group = request_var('add_group_select', 0);
369 $add = (isset($_POST['add_extension_check'])) ? true : false;
371 if ($add_extension && $add)
373 if (!sizeof($error))
375 $sql = 'SELECT extension_id
376 FROM ' . EXTENSIONS_TABLE . "
377 WHERE extension = '" . $db->sql_escape($add_extension) . "'";
378 $result = $db->sql_query($sql);
380 if ($row = $db->sql_fetchrow($result))
382 $error[] = sprintf($user->lang['EXTENSION_EXIST'], $add_extension);
384 $db->sql_freeresult($result);
386 if (!sizeof($error))
388 $sql_ary = array(
389 'group_id' => $add_extension_group,
390 'extension' => $add_extension
393 $db->sql_query('INSERT INTO ' . EXTENSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
394 add_log('admin', 'LOG_ATTACH_EXT_ADD', $add_extension);
399 if (!sizeof($error))
401 $notify[] = $user->lang['EXTENSIONS_UPDATED'];
404 $cache->destroy('_extensions');
407 $template->assign_vars(array(
408 'S_EXTENSIONS' => true,
409 'ADD_EXTENSION' => (isset($add_extension)) ? $add_extension : '',
410 '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'))
413 $sql = 'SELECT *
414 FROM ' . EXTENSIONS_TABLE . '
415 ORDER BY group_id, extension';
416 $result = $db->sql_query($sql);
418 if ($row = $db->sql_fetchrow($result))
420 $old_group_id = $row['group_id'];
423 $s_spacer = false;
425 $current_group_id = $row['group_id'];
426 if ($old_group_id != $current_group_id)
428 $s_spacer = true;
429 $old_group_id = $current_group_id;
432 $template->assign_block_vars('extensions', array(
433 'S_SPACER' => $s_spacer,
434 'EXTENSION_ID' => $row['extension_id'],
435 'EXTENSION' => $row['extension'],
436 'GROUP_OPTIONS' => $this->group_select('group_select[]', $row['group_id']))
439 while ($row = $db->sql_fetchrow($result));
441 $db->sql_freeresult($result);
443 break;
445 case 'ext_groups':
447 $template->assign_var('S_EXTENSION_GROUPS', true);
449 if ($submit)
451 $action = request_var('action', '');
452 $group_id = request_var('g', 0);
454 if ($action != 'add' && $action != 'edit')
456 trigger_error('NO_MODE', E_USER_ERROR);
459 if (!$group_id && $action == 'edit')
461 trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
464 if ($group_id)
466 $sql = 'SELECT *
467 FROM ' . EXTENSION_GROUPS_TABLE . "
468 WHERE group_id = $group_id";
469 $result = $db->sql_query($sql);
470 $ext_row = $db->sql_fetchrow($result);
471 $db->sql_freeresult($result);
473 if (!$ext_row)
475 trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
478 else
480 $ext_row = array();
483 $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
484 $new_group_name = ($action == 'add') ? $group_name : (($ext_row['group_name'] != $group_name) ? $group_name : '');
486 if (!$group_name)
488 $error[] = $user->lang['NO_EXT_GROUP_NAME'];
491 // Check New Group Name
492 if ($new_group_name)
494 $sql = 'SELECT group_id
495 FROM ' . EXTENSION_GROUPS_TABLE . "
496 WHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($new_group_name)) . "'";
497 $result = $db->sql_query($sql);
499 if ($db->sql_fetchrow($result))
501 $error[] = sprintf($user->lang['EXTENSION_GROUP_EXIST'], $new_group_name);
503 $db->sql_freeresult($result);
506 if (!sizeof($error))
508 // Ok, build the update/insert array
509 $upload_icon = request_var('upload_icon', 'no_image');
510 $size_select = request_var('size_select', 'b');
511 $forum_select = request_var('forum_select', false);
512 $allowed_forums = request_var('allowed_forums', array(0));
513 $allow_in_pm = (isset($_POST['allow_in_pm'])) ? true : false;
514 $max_filesize = request_var('max_filesize', 0);
515 $max_filesize = ($size_select == 'kb') ? round($max_filesize * 1024) : (($size_select == 'mb') ? round($max_filesize * 1048576) : $max_filesize);
516 $allow_group = (isset($_POST['allow_group'])) ? true : false;
518 if ($max_filesize == $config['max_filesize'])
520 $max_filesize = 0;
523 if (!sizeof($allowed_forums))
525 $forum_select = false;
528 $group_ary = array(
529 'group_name' => $group_name,
530 'cat_id' => request_var('special_category', ATTACHMENT_CATEGORY_NONE),
531 'allow_group' => ($allow_group) ? 1 : 0,
532 'upload_icon' => ($upload_icon == 'no_image') ? '' : $upload_icon,
533 'max_filesize' => $max_filesize,
534 'allowed_forums'=> ($forum_select) ? serialize($allowed_forums) : '',
535 'allow_in_pm' => ($allow_in_pm) ? 1 : 0,
538 if ($action == 'add')
540 $group_ary['download_mode'] = INLINE_LINK;
543 $sql = ($action == 'add') ? 'INSERT INTO ' . EXTENSION_GROUPS_TABLE . ' ' : 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET ';
544 $sql .= $db->sql_build_array((($action == 'add') ? 'INSERT' : 'UPDATE'), $group_ary);
545 $sql .= ($action == 'edit') ? " WHERE group_id = $group_id" : '';
547 $db->sql_query($sql);
549 if ($action == 'add')
551 $group_id = $db->sql_nextid();
554 add_log('admin', 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), $group_name);
557 $extension_list = request_var('extensions', array(0));
559 if ($action == 'edit' && sizeof($extension_list))
561 $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
562 SET group_id = 0
563 WHERE group_id = $group_id";
564 $db->sql_query($sql);
567 if (sizeof($extension_list))
569 $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
570 SET group_id = $group_id
571 WHERE " . $db->sql_in_set('extension_id', $extension_list);
572 $db->sql_query($sql);
575 $cache->destroy('_extensions');
577 if (!sizeof($error))
579 $notify[] = $user->lang['SUCCESS_EXTENSION_GROUP_' . strtoupper($action)];
583 $cat_lang = array(
584 ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'],
585 ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'],
586 ATTACHMENT_CATEGORY_WM => $user->lang['CAT_WM_FILES'],
587 ATTACHMENT_CATEGORY_RM => $user->lang['CAT_RM_FILES'],
588 ATTACHMENT_CATEGORY_FLASH => $user->lang['CAT_FLASH_FILES'],
589 ATTACHMENT_CATEGORY_QUICKTIME => $user->lang['CAT_QUICKTIME_FILES'],
592 $group_id = request_var('g', 0);
593 $action = (isset($_POST['add'])) ? 'add' : $action;
595 switch ($action)
597 case 'delete':
599 if (confirm_box(true))
601 $sql = 'SELECT group_name
602 FROM ' . EXTENSION_GROUPS_TABLE . "
603 WHERE group_id = $group_id";
604 $result = $db->sql_query($sql);
605 $group_name = (string) $db->sql_fetchfield('group_name');
606 $db->sql_freeresult($result);
608 $sql = 'DELETE
609 FROM ' . EXTENSION_GROUPS_TABLE . "
610 WHERE group_id = $group_id";
611 $db->sql_query($sql);
613 // Set corresponding Extensions to a pending Group
614 $sql = 'UPDATE ' . EXTENSIONS_TABLE . "
615 SET group_id = 0
616 WHERE group_id = $group_id";
617 $db->sql_query($sql);
619 add_log('admin', 'LOG_ATTACH_EXTGROUP_DEL', $group_name);
621 $cache->destroy('_extensions');
623 trigger_error($user->lang['EXTENSION_GROUP_DELETED'] . adm_back_link($this->u_action));
625 else
627 confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
628 'i' => $id,
629 'mode' => $mode,
630 'group_id' => $group_id,
631 'action' => 'delete',
632 )));
635 break;
637 case 'edit':
639 if (!$group_id)
641 trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
644 $sql = 'SELECT *
645 FROM ' . EXTENSION_GROUPS_TABLE . "
646 WHERE group_id = $group_id";
647 $result = $db->sql_query($sql);
648 $ext_group_row = $db->sql_fetchrow($result);
649 $db->sql_freeresult($result);
651 $forum_ids = (!$ext_group_row['allowed_forums']) ? array() : unserialize(trim($ext_group_row['allowed_forums']));
653 // no break;
655 case 'add':
657 if ($action == 'add')
659 $ext_group_row = array(
660 'group_name' => utf8_normalize_nfc(request_var('group_name', '', true)),
661 'cat_id' => 0,
662 'allow_group' => 1,
663 'allow_in_pm' => 1,
664 'upload_icon' => '',
665 'max_filesize' => 0,
668 $forum_ids = array();
671 $extensions = array();
673 $sql = 'SELECT *
674 FROM ' . EXTENSIONS_TABLE . "
675 WHERE group_id = $group_id
676 OR group_id = 0
677 ORDER BY extension";
678 $result = $db->sql_query($sql);
679 $extensions = $db->sql_fetchrowset($result);
680 $db->sql_freeresult($result);
682 if ($ext_group_row['max_filesize'] == 0)
684 $ext_group_row['max_filesize'] = (int) $config['max_filesize'];
687 $max_filesize = get_formatted_filesize($ext_group_row['max_filesize'], false, array('mb', 'kb', 'b'));
688 $size_format = $max_filesize['si_identifier'];
689 $ext_group_row['max_filesize'] = $max_filesize['value'];
691 $img_path = $config['upload_icons_path'];
693 $filename_list = '';
694 $no_image_select = false;
696 $imglist = filelist($phpbb_root_path . $img_path);
698 if (!empty($imglist['']))
700 $imglist = array_values($imglist);
701 $imglist = $imglist[0];
703 foreach ($imglist as $key => $img)
705 if (!$ext_group_row['upload_icon'])
707 $no_image_select = true;
708 $selected = '';
710 else
712 $selected = ($ext_group_row['upload_icon'] == $img) ? ' selected="selected"' : '';
715 if (strlen($img) > 255)
717 continue;
720 $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . htmlspecialchars($img) . '</option>';
724 $i = 0;
725 $assigned_extensions = '';
726 foreach ($extensions as $num => $row)
728 if ($row['group_id'] == $group_id && $group_id)
730 $assigned_extensions .= ($i) ? ', ' . $row['extension'] : $row['extension'];
731 $i++;
735 $s_extension_options = '';
736 foreach ($extensions as $row)
738 $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>';
741 $template->assign_vars(array(
742 'PHPBB_ROOT_PATH' => $phpbb_root_path,
743 'IMG_PATH' => $img_path,
744 'ACTION' => $action,
745 'GROUP_ID' => $group_id,
746 'GROUP_NAME' => $ext_group_row['group_name'],
747 'ALLOW_GROUP' => $ext_group_row['allow_group'],
748 'ALLOW_IN_PM' => $ext_group_row['allow_in_pm'],
749 'UPLOAD_ICON_SRC' => $phpbb_root_path . $img_path . '/' . $ext_group_row['upload_icon'],
750 'EXTGROUP_FILESIZE' => $ext_group_row['max_filesize'],
751 'ASSIGNED_EXTENSIONS' => $assigned_extensions,
753 'S_CATEGORY_SELECT' => $this->category_select('special_category', $group_id, 'category'),
754 'S_EXT_GROUP_SIZE_OPTIONS' => size_select_options($size_format),
755 'S_EXTENSION_OPTIONS' => $s_extension_options,
756 'S_FILENAME_LIST' => $filename_list,
757 'S_EDIT_GROUP' => true,
758 'S_NO_IMAGE' => $no_image_select,
759 'S_FORUM_IDS' => (sizeof($forum_ids)) ? true : false,
761 'U_EXTENSIONS' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;mode=extensions"),
762 'U_BACK' => $this->u_action,
764 'L_LEGEND' => $user->lang[strtoupper($action) . '_EXTENSION_GROUP'])
767 $s_forum_id_options = '';
769 /** @todo use in-built function **/
771 $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
772 FROM ' . FORUMS_TABLE . '
773 ORDER BY left_id ASC';
774 $result = $db->sql_query($sql, 600);
776 $right = $cat_right = $padding_inc = 0;
777 $padding = $forum_list = $holding = '';
778 $padding_store = array('0' => '');
780 while ($row = $db->sql_fetchrow($result))
782 if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
784 // Non-postable forum with no subforums, don't display
785 continue;
788 if (!$auth->acl_get('f_list', $row['forum_id']))
790 // if the user does not have permissions to list this forum skip
791 continue;
794 if ($row['left_id'] < $right)
796 $padding .= '&nbsp; &nbsp;';
797 $padding_store[$row['parent_id']] = $padding;
799 else if ($row['left_id'] > $right + 1)
801 $padding = empty($padding_store[$row['parent_id']]) ? '' : $padding_store[$row['parent_id']];
804 $right = $row['right_id'];
806 $selected = (in_array($row['forum_id'], $forum_ids)) ? ' selected="selected"' : '';
808 if ($row['left_id'] > $cat_right)
810 // make sure we don't forget anything
811 $s_forum_id_options .= $holding;
812 $holding = '';
815 if ($row['right_id'] - $row['left_id'] > 1)
817 $cat_right = max($cat_right, $row['right_id']);
819 $holding .= '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
821 else
823 $s_forum_id_options .= $holding . '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
824 $holding = '';
828 if ($holding)
830 $s_forum_id_options .= $holding;
833 $db->sql_freeresult($result);
834 unset($padding_store);
836 $template->assign_vars(array(
837 'S_FORUM_ID_OPTIONS' => $s_forum_id_options)
840 break;
843 $sql = 'SELECT *
844 FROM ' . EXTENSION_GROUPS_TABLE . '
845 ORDER BY allow_group DESC, allow_in_pm DESC, group_name';
846 $result = $db->sql_query($sql);
848 $old_allow_group = $old_allow_pm = 1;
849 while ($row = $db->sql_fetchrow($result))
851 $s_add_spacer = ($old_allow_group != $row['allow_group'] || $old_allow_pm != $row['allow_in_pm']) ? true : false;
853 $template->assign_block_vars('groups', array(
854 'S_ADD_SPACER' => $s_add_spacer,
855 'S_ALLOWED_IN_PM' => ($row['allow_in_pm']) ? true : false,
856 'S_GROUP_ALLOWED' => ($row['allow_group']) ? true : false,
858 'U_EDIT' => $this->u_action . "&amp;action=edit&amp;g={$row['group_id']}",
859 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;g={$row['group_id']}",
861 'GROUP_NAME' => $row['group_name'],
862 'CATEGORY' => $cat_lang[$row['cat_id']],
866 $old_allow_group = $row['allow_group'];
867 $old_allow_pm = $row['allow_in_pm'];
869 $db->sql_freeresult($result);
871 break;
873 case 'orphan':
875 if ($submit)
877 $delete_files = (isset($_POST['delete'])) ? array_keys(request_var('delete', array('' => 0))) : array();
878 $add_files = (isset($_POST['add'])) ? array_keys(request_var('add', array('' => 0))) : array();
879 $post_ids = request_var('post_id', array('' => 0));
881 if (sizeof($delete_files))
883 $sql = 'SELECT *
884 FROM ' . ATTACHMENTS_TABLE . '
885 WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
886 AND is_orphan = 1';
887 $result = $db->sql_query($sql);
889 $delete_files = array();
890 while ($row = $db->sql_fetchrow($result))
892 phpbb_unlink($row['physical_filename'], 'file');
894 if ($row['thumbnail'])
896 phpbb_unlink($row['physical_filename'], 'thumbnail');
899 $delete_files[$row['attach_id']] = $row['real_filename'];
901 $db->sql_freeresult($result);
904 if (sizeof($delete_files))
906 $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
907 WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files));
908 $db->sql_query($sql);
910 add_log('admin', 'LOG_ATTACH_ORPHAN_DEL', implode(', ', $delete_files));
911 $notify[] = sprintf($user->lang['LOG_ATTACH_ORPHAN_DEL'], implode(', ', $delete_files));
914 $upload_list = array();
915 foreach ($add_files as $attach_id)
917 if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id]))
919 $upload_list[$attach_id] = $post_ids[$attach_id];
922 unset($add_files);
924 if (sizeof($upload_list))
926 $template->assign_var('S_UPLOADING_FILES', true);
928 $sql = 'SELECT forum_id, forum_name
929 FROM ' . FORUMS_TABLE;
930 $result = $db->sql_query($sql);
932 $forum_names = array();
933 while ($row = $db->sql_fetchrow($result))
935 $forum_names[$row['forum_id']] = $row['forum_name'];
937 $db->sql_freeresult($result);
939 $sql = 'SELECT forum_id, topic_id, post_id, poster_id
940 FROM ' . POSTS_TABLE . '
941 WHERE ' . $db->sql_in_set('post_id', $upload_list);
942 $result = $db->sql_query($sql);
944 $post_info = array();
945 while ($row = $db->sql_fetchrow($result))
947 $post_info[$row['post_id']] = $row;
949 $db->sql_freeresult($result);
951 // Select those attachments we want to change...
952 $sql = 'SELECT *
953 FROM ' . ATTACHMENTS_TABLE . '
954 WHERE ' . $db->sql_in_set('attach_id', array_keys($upload_list)) . '
955 AND is_orphan = 1';
956 $result = $db->sql_query($sql);
958 $files_added = $space_taken = 0;
959 while ($row = $db->sql_fetchrow($result))
961 $post_row = $post_info[$upload_list[$row['attach_id']]];
963 $template->assign_block_vars('upload', array(
964 'FILE_INFO' => sprintf($user->lang['UPLOADING_FILE_TO'], $row['real_filename'], $post_row['post_id']),
965 'S_DENIED' => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? true : false,
966 'L_DENIED' => (!$auth->acl_get('f_attach', $post_row['forum_id'])) ? sprintf($user->lang['UPLOAD_DENIED_FORUM'], $forum_names[$row['forum_id']]) : '')
969 if (!$auth->acl_get('f_attach', $post_row['forum_id']))
971 continue;
974 // Adjust attachment entry
975 $sql_ary = array(
976 'in_message' => 0,
977 'is_orphan' => 0,
978 'poster_id' => $post_row['poster_id'],
979 'post_msg_id' => $post_row['post_id'],
980 'topic_id' => $post_row['topic_id'],
983 $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
984 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
985 WHERE attach_id = ' . $row['attach_id'];
986 $db->sql_query($sql);
988 $sql = 'UPDATE ' . POSTS_TABLE . '
989 SET post_attachment = 1
990 WHERE post_id = ' . $post_row['post_id'];
991 $db->sql_query($sql);
993 $sql = 'UPDATE ' . TOPICS_TABLE . '
994 SET topic_attachment = 1
995 WHERE topic_id = ' . $post_row['topic_id'];
996 $db->sql_query($sql);
998 $space_taken += $row['filesize'];
999 $files_added++;
1001 add_log('admin', 'LOG_ATTACH_FILEUPLOAD', $post_row['post_id'], $row['real_filename']);
1003 $db->sql_freeresult($result);
1005 if ($files_added)
1007 set_config_count('upload_dir_size', $space_taken, true);
1008 set_config_count('num_files', $files_added, true);
1013 $template->assign_vars(array(
1014 'S_ORPHAN' => true)
1017 // Just get the files with is_orphan set and older than 3 hours
1018 $sql = 'SELECT *
1019 FROM ' . ATTACHMENTS_TABLE . '
1020 WHERE is_orphan = 1
1021 AND filetime < ' . (time() - 3*60*60) . '
1022 ORDER BY filetime DESC';
1023 $result = $db->sql_query($sql);
1025 while ($row = $db->sql_fetchrow($result))
1027 $template->assign_block_vars('orphan', array(
1028 'FILESIZE' => get_formatted_filesize($row['filesize']),
1029 'FILETIME' => $user->format_date($row['filetime']),
1030 'REAL_FILENAME' => utf8_basename($row['real_filename']),
1031 'PHYSICAL_FILENAME' => utf8_basename($row['physical_filename']),
1032 'ATTACH_ID' => $row['attach_id'],
1033 'POST_IDS' => (!empty($post_ids[$row['attach_id']])) ? $post_ids[$row['attach_id']] : '',
1034 'U_FILE' => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id']))
1037 $db->sql_freeresult($result);
1039 break;
1042 if (sizeof($error))
1044 $template->assign_vars(array(
1045 'S_WARNING' => true,
1046 'WARNING_MSG' => implode('<br />', $error))
1050 if (sizeof($notify))
1052 $template->assign_vars(array(
1053 'S_NOTIFY' => true,
1054 'NOTIFY_MSG' => implode('<br />', $notify))
1060 * Build Select for category items
1062 function category_select($select_name, $group_id = false, $key = '')
1064 global $db, $user;
1066 $types = array(
1067 ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'],
1068 ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'],
1069 ATTACHMENT_CATEGORY_WM => $user->lang['CAT_WM_FILES'],
1070 ATTACHMENT_CATEGORY_RM => $user->lang['CAT_RM_FILES'],
1071 ATTACHMENT_CATEGORY_FLASH => $user->lang['CAT_FLASH_FILES'],
1072 ATTACHMENT_CATEGORY_QUICKTIME => $user->lang['CAT_QUICKTIME_FILES'],
1075 if ($group_id)
1077 $sql = 'SELECT cat_id
1078 FROM ' . EXTENSION_GROUPS_TABLE . '
1079 WHERE group_id = ' . (int) $group_id;
1080 $result = $db->sql_query($sql);
1082 $cat_type = (!($row = $db->sql_fetchrow($result))) ? ATTACHMENT_CATEGORY_NONE : $row['cat_id'];
1084 $db->sql_freeresult($result);
1086 else
1088 $cat_type = ATTACHMENT_CATEGORY_NONE;
1091 $group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
1093 foreach ($types as $type => $mode)
1095 $selected = ($type == $cat_type) ? ' selected="selected"' : '';
1096 $group_select .= '<option value="' . $type . '"' . $selected . '>' . $mode . '</option>';
1099 $group_select .= '</select>';
1101 return $group_select;
1105 * Extension group select
1107 function group_select($select_name, $default_group = false, $key = '')
1109 global $db, $user;
1111 $group_select = '<select name="' . $select_name . '"' . (($key) ? ' id="' . $key . '"' : '') . '>';
1113 $sql = 'SELECT group_id, group_name
1114 FROM ' . EXTENSION_GROUPS_TABLE . '
1115 ORDER BY group_name';
1116 $result = $db->sql_query($sql);
1118 $group_name = array();
1119 while ($row = $db->sql_fetchrow($result))
1121 $group_name[] = $row;
1123 $db->sql_freeresult($result);
1125 $row['group_id'] = 0;
1126 $row['group_name'] = $user->lang['NOT_ASSIGNED'];
1127 $group_name[] = $row;
1129 for ($i = 0; $i < sizeof($group_name); $i++)
1131 if ($default_group === false)
1133 $selected = ($i == 0) ? ' selected="selected"' : '';
1135 else
1137 $selected = ($group_name[$i]['group_id'] == $default_group) ? ' selected="selected"' : '';
1140 $group_select .= '<option value="' . $group_name[$i]['group_id'] . '"' . $selected . '>' . $group_name[$i]['group_name'] . '</option>';
1143 $group_select .= '</select>';
1145 return $group_select;
1149 * Search Imagick
1151 function search_imagemagick()
1153 $imagick = '';
1155 $exe = ((defined('PHP_OS')) && (preg_match('#^win#i', PHP_OS))) ? '.exe' : '';
1157 $magic_home = getenv('MAGICK_HOME');
1159 if (empty($magic_home))
1161 $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/');
1162 $path_locations = str_replace('\\', '/', (explode(($exe) ? ';' : ':', getenv('PATH'))));
1164 $locations = array_merge($path_locations, $locations);
1166 foreach ($locations as $location)
1168 // The path might not end properly, fudge it
1169 if (substr($location, -1) !== '/')
1171 $location .= '/';
1174 if (@file_exists($location) && @is_readable($location . 'mogrify' . $exe) && @filesize($location . 'mogrify' . $exe) > 3000)
1176 $imagick = str_replace('\\', '/', $location);
1177 continue;
1181 else
1183 $imagick = str_replace('\\', '/', $magic_home);
1186 return $imagick;
1190 * Test Settings
1192 function test_upload(&$error, $upload_dir, $create_directory = false)
1194 global $user, $phpbb_root_path;
1196 // Does the target directory exist, is it a directory and writable.
1197 if ($create_directory)
1199 if (!file_exists($phpbb_root_path . $upload_dir))
1201 @mkdir($phpbb_root_path . $upload_dir, 0777);
1202 phpbb_chmod($phpbb_root_path . $upload_dir, CHMOD_READ | CHMOD_WRITE);
1206 if (!file_exists($phpbb_root_path . $upload_dir))
1208 $error[] = sprintf($user->lang['NO_UPLOAD_DIR'], $upload_dir);
1209 return;
1212 if (!is_dir($phpbb_root_path . $upload_dir))
1214 $error[] = sprintf($user->lang['UPLOAD_NOT_DIR'], $upload_dir);
1215 return;
1218 if (!is_writable($phpbb_root_path . $upload_dir))
1220 $error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir);
1221 return;
1226 * Perform operations on sites for external linking
1228 function perform_site_list()
1230 global $db, $user;
1232 if (isset($_REQUEST['securesubmit']))
1234 // Grab the list of entries
1235 $ips = request_var('ips', '');
1236 $ip_list = array_unique(explode("\n", $ips));
1237 $ip_list_log = implode(', ', $ip_list);
1239 $ip_exclude = (!empty($_POST['ipexclude'])) ? 1 : 0;
1241 $iplist = array();
1242 $hostlist = array();
1244 foreach ($ip_list as $item)
1246 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))
1248 // Don't ask about all this, just don't ask ... !
1249 $ip_1_counter = $ip_range_explode[1];
1250 $ip_1_end = $ip_range_explode[5];
1252 while ($ip_1_counter <= $ip_1_end)
1254 $ip_2_counter = ($ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[2] : 0;
1255 $ip_2_end = ($ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[6];
1257 if ($ip_2_counter == 0 && $ip_2_end == 254)
1259 $ip_2_counter = 256;
1260 $ip_2_fragment = 256;
1262 $iplist[] = "'$ip_1_counter.*'";
1265 while ($ip_2_counter <= $ip_2_end)
1267 $ip_3_counter = ($ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[3] : 0;
1268 $ip_3_end = ($ip_2_counter < $ip_2_end || $ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[7];
1270 if ($ip_3_counter == 0 && $ip_3_end == 254)
1272 $ip_3_counter = 256;
1273 $ip_3_fragment = 256;
1275 $iplist[] = "'$ip_1_counter.$ip_2_counter.*'";
1278 while ($ip_3_counter <= $ip_3_end)
1280 $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;
1281 $ip_4_end = ($ip_3_counter < $ip_3_end || $ip_2_counter < $ip_2_end) ? 254 : $ip_range_explode[8];
1283 if ($ip_4_counter == 0 && $ip_4_end == 254)
1285 $ip_4_counter = 256;
1286 $ip_4_fragment = 256;
1288 $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.*'";
1291 while ($ip_4_counter <= $ip_4_end)
1293 $iplist[] = "'$ip_1_counter.$ip_2_counter.$ip_3_counter.$ip_4_counter'";
1294 $ip_4_counter++;
1296 $ip_3_counter++;
1298 $ip_2_counter++;
1300 $ip_1_counter++;
1303 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)))
1305 $iplist[] = "'" . trim($item) . "'";
1307 else if (preg_match('#^([\w\-_]\.?){2,}$#is', trim($item)))
1309 $hostlist[] = "'" . trim($item) . "'";
1311 else if (preg_match("#^([a-z0-9\-\*\._/]+?)$#is", trim($item)))
1313 $hostlist[] = "'" . trim($item) . "'";
1317 $sql = 'SELECT site_ip, site_hostname
1318 FROM ' . SITELIST_TABLE . "
1319 WHERE ip_exclude = $ip_exclude";
1320 $result = $db->sql_query($sql);
1322 if ($row = $db->sql_fetchrow($result))
1324 $iplist_tmp = array();
1325 $hostlist_tmp = array();
1328 if ($row['site_ip'])
1330 if (strlen($row['site_ip']) > 40)
1332 continue;
1335 $iplist_tmp[] = "'" . $row['site_ip'] . "'";
1337 else if ($row['site_hostname'])
1339 if (strlen($row['site_hostname']) > 255)
1341 continue;
1344 $hostlist_tmp[] = "'" . $row['site_hostname'] . "'";
1346 // break;
1348 while ($row = $db->sql_fetchrow($result));
1350 $iplist = array_unique(array_diff($iplist, $iplist_tmp));
1351 $hostlist = array_unique(array_diff($hostlist, $hostlist_tmp));
1352 unset($iplist_tmp);
1353 unset($hostlist_tmp);
1355 $db->sql_freeresult($result);
1357 if (sizeof($iplist))
1359 foreach ($iplist as $ip_entry)
1361 $sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_ip, ip_exclude)
1362 VALUES ($ip_entry, $ip_exclude)";
1363 $db->sql_query($sql);
1367 if (sizeof($hostlist))
1369 foreach ($hostlist as $host_entry)
1371 $sql = 'INSERT INTO ' . SITELIST_TABLE . " (site_hostname, ip_exclude)
1372 VALUES ($host_entry, $ip_exclude)";
1373 $db->sql_query($sql);
1377 if (!empty($ip_list_log))
1379 // Update log
1380 $log_entry = ($ip_exclude) ? 'LOG_DOWNLOAD_EXCLUDE_IP' : 'LOG_DOWNLOAD_IP';
1381 add_log('admin', $log_entry, $ip_list_log);
1384 trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
1386 else if (isset($_POST['unsecuresubmit']))
1388 $unip_sql = request_var('unip', array(0));
1390 if (sizeof($unip_sql))
1392 $l_unip_list = '';
1394 // Grab details of ips for logging information later
1395 $sql = 'SELECT site_ip, site_hostname
1396 FROM ' . SITELIST_TABLE . '
1397 WHERE ' . $db->sql_in_set('site_id', $unip_sql);
1398 $result = $db->sql_query($sql);
1400 while ($row = $db->sql_fetchrow($result))
1402 $l_unip_list .= (($l_unip_list != '') ? ', ' : '') . (($row['site_ip']) ? $row['site_ip'] : $row['site_hostname']);
1404 $db->sql_freeresult($result);
1406 $sql = 'DELETE FROM ' . SITELIST_TABLE . '
1407 WHERE ' . $db->sql_in_set('site_id', $unip_sql);
1408 $db->sql_query($sql);
1410 add_log('admin', 'LOG_DOWNLOAD_REMOVE_IP', $l_unip_list);
1413 trigger_error($user->lang['SECURE_DOWNLOAD_UPDATE_SUCCESS'] . adm_back_link($this->u_action));
1418 * Write display_order config field
1420 function display_order($value, $key = '')
1422 $radio_ary = array(0 => 'DESCENDING', 1 => 'ASCENDING');
1424 return h_radio('config[display_order]', $radio_ary, $value, $key);
1428 * Adjust all three max_filesize config vars for display
1430 function max_filesize($value, $key = '')
1432 // Determine size var and adjust the value accordingly
1433 $filesize = get_formatted_filesize($value, false, array('mb', 'kb', 'b'));
1434 $size_var = $filesize['si_identifier'];
1435 $value = $filesize['value'];
1437 return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
1441 * Write secure_allow_deny config field
1443 function select_allow_deny($value, $key = '')
1445 $radio_ary = array(1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW');
1447 return h_radio('config[' . $key . ']', $radio_ary, $value, $key);