Просмотр файла admin/admin_attachments.php

Размер файла: 38.42Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. define('IN_PHPBB', true);
  7.  
  8. if( !empty($setmodules) )
  9. {
  10. $filename = basename(__FILE__);
  11. $module['Attachments']['Manage'] = $filename . '?mode=manage';
  12. $module['Attachments']['Shadow_attachments'] = $filename . '?mode=shadow';
  13. $module['Extensions']['Special_categories'] = $filename . '?mode=cats';
  14. $module['Attachments']['Quota_limits'] = $filename . '?mode=quota';
  15. return;
  16. }
  17.  
  18. $phpbb_root_path = '../';
  19. require($phpbb_root_path . 'extension.inc');
  20. require('pagestart.' . $phpEx);
  21.  
  22. @include_once($phpbb_root_path . 'attach_mod/includes/constants.'.$phpEx);
  23. include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
  24. @include_once($phpbb_root_path . 'attach_mod/includes/functions_attach.'.$phpEx);
  25.  
  26. if (!intval($attach_config['allow_ftp_upload']))
  27. {
  28. if ( ($attach_config['upload_dir'][0] == '/') || ( ($attach_config['upload_dir'][0] != '/') && ($attach_config['upload_dir'][1] == ':') ) )
  29. {
  30. $upload_dir = $attach_config['upload_dir'];
  31. }
  32. else
  33. {
  34. $upload_dir = '../' . $attach_config['upload_dir'];
  35. }
  36. }
  37. else
  38. {
  39. $upload_dir = $attach_config['download_path'];
  40. }
  41.  
  42. include($phpbb_root_path . 'attach_mod/includes/functions_selects.' . $phpEx);
  43. include($phpbb_root_path . 'attach_mod/includes/functions_admin.' . $phpEx);
  44.  
  45. if (!isset($lang['Test_settings_successful']))
  46. {
  47. include_attach_lang();
  48. }
  49.  
  50. $mode = get_var('mode', '');
  51. $e_mode = get_var('e_mode', '');
  52. $size = get_var('size', '');
  53. $quota_size = get_var('quota_size', '');
  54. $pm_size = get_var('pm_size', '');
  55.  
  56. $submit = (isset($HTTP_POST_VARS['submit'])) ? TRUE : FALSE;
  57. $check_upload = (isset($HTTP_POST_VARS['settings'])) ? TRUE : FALSE;
  58. $check_image_cat = (isset($HTTP_POST_VARS['cat_settings'])) ? TRUE : FALSE;
  59. $search_imagick = (isset($HTTP_POST_VARS['search_imagick'])) ? TRUE : FALSE;
  60.  
  61. $sql = 'SELECT *
  62. FROM ' . ATTACH_CONFIG_TABLE;
  63. if (!$result = $db->sql_query($sql))
  64. {
  65. message_die(GENERAL_ERROR, 'Could not find Attachment Config Table', '', __LINE__, __FILE__, $sql);
  66. }
  67.  
  68. while ($row = $db->sql_fetchrow($result))
  69. {
  70. $config_name = $row['config_name'];
  71. $config_value = $row['config_value'];
  72.  
  73. $new_attach[$config_name] = get_var($config_name, trim($attach_config[$config_name]));
  74.  
  75. if (!$size && !$submit && $config_name == 'max_filesize')
  76. {
  77. $size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b');
  78. }
  79.  
  80. if (!$quota_size && !$submit && $config_name == 'attachment_quota')
  81. {
  82. $quota_size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b');
  83. }
  84.  
  85. if (!$pm_size && !$submit && $config_name == 'max_filesize_pm')
  86. {
  87. $pm_size = ($attach_config[$config_name] >= 1048576) ? 'mb' : (($attach_config[$config_name] >= 1024) ? 'kb' : 'b');
  88. }
  89.  
  90. if (!$submit && ($config_name == 'max_filesize' || $config_name == 'attachment_quota' || $config_name == 'max_filesize_pm'))
  91. {
  92. if ($new_attach[$config_name] >= 1048576)
  93. {
  94. $new_attach[$config_name] = round($new_attach[$config_name] / 1048576 * 100) / 100;
  95. }
  96. else if ($new_attach[$config_name] >= 1024)
  97. {
  98. $new_attach[$config_name] = round($new_attach[$config_name] / 1024 * 100) / 100;
  99. }
  100. }
  101.  
  102. if ($submit && ($mode == 'manage' || $mode == 'cats'))
  103. {
  104. if ($config_name == 'max_filesize')
  105. {
  106. $old = $new_attach[$config_name];
  107. $new_attach[$config_name] = ($size == 'kb') ? round($new_attach[$config_name] * 1024) : (($size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name]);
  108. }
  109. if ($config_name == 'attachment_quota')
  110. {
  111. $old = $new_attach[$config_name];
  112. $new_attach[$config_name] = ( $quota_size == 'kb' ) ? round($new_attach[$config_name] * 1024) : ( ($quota_size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name] );
  113. }
  114.  
  115. if ($config_name == 'max_filesize_pm')
  116. {
  117. $old = $new_attach[$config_name];
  118. $new_attach[$config_name] = ( $pm_size == 'kb' ) ? round($new_attach[$config_name] * 1024) : ( ($pm_size == 'mb') ? round($new_attach[$config_name] * 1048576) : $new_attach[$config_name] );
  119. }
  120.  
  121. if ($config_name == 'ftp_server' || $config_name == 'ftp_path' || $config_name == 'download_path')
  122. {
  123. $value = trim($new_attach[$config_name]);
  124.  
  125. if ($value[strlen($value)-1] == '/')
  126. {
  127. $value[strlen($value)-1] = ' ';
  128. }
  129. $new_attach[$config_name] = trim($value);
  130. }
  131. if ($config_name == 'max_filesize')
  132. {
  133. $old_size = $attach_config[$config_name];
  134. $new_size = $new_attach[$config_name];
  135.  
  136. if ($old_size != $new_size)
  137. {
  138. $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
  139. SET max_filesize = ' . (int) $new_size . '
  140. WHERE max_filesize = ' . (int) $old_size;
  141.  
  142. if (!($result_2 = $db->sql_query($sql)))
  143. {
  144. message_die(GENERAL_ERROR, 'Could not update Extension Group informations', '', __LINE__, __FILE__, $sql);
  145. }
  146. }
  147.  
  148. $sql = "UPDATE " . ATTACH_CONFIG_TABLE . "
  149. SET config_value = '" . attach_mod_sql_escape($new_attach[$config_name]) . "'
  150. WHERE config_name = '" . attach_mod_sql_escape($config_name) . "'";
  151. }
  152. else
  153. {
  154. $sql = "UPDATE " . ATTACH_CONFIG_TABLE . "
  155. SET config_value = '" . attach_mod_sql_escape($new_attach[$config_name]) . "'
  156. WHERE config_name = '" . attach_mod_sql_escape($config_name) . "'";
  157. }
  158.  
  159. if (!$db->sql_query($sql))
  160. {
  161. message_die(GENERAL_ERROR, 'Failed to update attachment configuration for ' . $config_name, '', __LINE__, __FILE__, $sql);
  162. }
  163. if ($config_name == 'max_filesize' || $config_name == 'attachment_quota' || $config_name == 'max_filesize_pm')
  164. {
  165. $new_attach[$config_name] = $old;
  166. }
  167. }
  168. }
  169. $db->sql_freeresult($result);
  170.  
  171. $cache_dir = $phpbb_root_path . '/cache';
  172. $cache_file = $cache_dir . '/attach_config.php';
  173.  
  174. if ((file_exists($cache_dir)) && (is_dir($cache_dir)))
  175. {
  176. if (file_exists($cache_file))
  177. {
  178. @unlink($cache_file);
  179. }
  180. }
  181.  
  182. $select_size_mode = size_select('size', $size);
  183. $select_quota_size_mode = size_select('quota_size', $quota_size);
  184. $select_pm_size_mode = size_select('pm_size', $pm_size);
  185.  
  186. if ($search_imagick)
  187. {
  188. $imagick = '';
  189. if (eregi('convert', $imagick))
  190. {
  191. return true;
  192. }
  193. else if ($imagick != 'none')
  194. {
  195. if (!eregi('WIN', PHP_OS))
  196. {
  197. $retval = @exec('whereis convert');
  198. $paths = explode(' ', $retval);
  199.  
  200. if (is_array($paths))
  201. {
  202. for ($i = 0; $i < sizeof($paths); $i++)
  203. {
  204. $path = basename($paths[$i]);
  205.  
  206. if ($path == 'convert')
  207. {
  208. $imagick = $paths[$i];
  209. }
  210. }
  211. }
  212. }
  213. else if (eregi('WIN', PHP_OS))
  214. {
  215. $path = 'c:/imagemagick/convert.exe';
  216.  
  217. if (@file_exists(@amod_realpath($path)))
  218. {
  219. $imagick = $path;
  220. }
  221. }
  222. }
  223.  
  224. if (@file_exists(@amod_realpath(trim($imagick))))
  225. {
  226. $new_attach['img_imagick'] = trim($imagick);
  227. }
  228. else
  229. {
  230. $new_attach['img_imagick'] = '';
  231. }
  232. }
  233.  
  234. if ($check_upload)
  235. {
  236. $attach_config = array();
  237.  
  238. $sql = 'SELECT *
  239. FROM ' . ATTACH_CONFIG_TABLE;
  240.  
  241. if (!($result = $db->sql_query($sql)))
  242. {
  243. message_die(GENERAL_ERROR, 'Could not find Attachment Config Table', '', __LINE__, __FILE__, $sql);
  244. }
  245.  
  246. $row = $db->sql_fetchrowset($result);
  247. $num_rows = $db->sql_numrows($result);
  248. $db->sql_freeresult($result);
  249.  
  250. for ($i = 0; $i < $num_rows; $i++)
  251. {
  252. $attach_config[$row[$i]['config_name']] = trim($row[$i]['config_value']);
  253. }
  254.  
  255. if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':'))
  256. {
  257. $upload_dir = $attach_config['upload_dir'];
  258. }
  259. else
  260. {
  261. $upload_dir = $phpbb_root_path . $attach_config['upload_dir'];
  262. }
  263.  
  264. $error = false;
  265.  
  266. if (intval($attach_config['allow_ftp_upload']) == 0)
  267. {
  268. if (!@file_exists(@amod_realpath($upload_dir)))
  269. {
  270. $error = true;
  271. $error_msg = sprintf($lang['Directory_does_not_exist'], $attach_config['upload_dir']) . '<br />';
  272. }
  273. if (!$error && !is_dir($upload_dir))
  274. {
  275. $error = TRUE;
  276. $error_msg = sprintf($lang['Directory_is_not_a_dir'], $attach_config['upload_dir']) . '<br />';
  277. }
  278. if (!$error)
  279. {
  280. if ( !($fp = @fopen($upload_dir . '/0_000000.000', 'w')) )
  281. {
  282. $error = TRUE;
  283. $error_msg = sprintf($lang['Directory_not_writeable'], $attach_config['upload_dir']) . '<br />';
  284. }
  285. else
  286. {
  287. @fclose($fp);
  288. unlink_attach($upload_dir . '/0_000000.000');
  289. }
  290. }
  291. }
  292. else
  293. {
  294. $server = ( empty($attach_config['ftp_server']) ) ? 'localhost' : $attach_config['ftp_server'];
  295.  
  296. $conn_id = @ftp_connect($server);
  297.  
  298. if (!$conn_id)
  299. {
  300. $error = TRUE;
  301. $error_msg = sprintf($lang['Ftp_error_connect'], $server) . '<br />';
  302. }
  303.  
  304. $login_result = @ftp_login($conn_id, $attach_config['ftp_user'], $attach_config['ftp_pass']);
  305.  
  306. if ( (!$login_result) && (!$error) )
  307. {
  308. $error = TRUE;
  309. $error_msg = sprintf($lang['Ftp_error_login'], $attach_config['ftp_user']) . '<br />';
  310. }
  311. if (!@ftp_pasv($conn_id, intval($attach_config['ftp_pasv_mode'])))
  312. {
  313. $error = TRUE;
  314. $error_msg = $lang['Ftp_error_pasv_mode'];
  315. }
  316.  
  317. if (!$error)
  318. {
  319. $tmpfname = @tempnam('/tmp', 't0000');
  320.  
  321. @unlink($tmpfname);
  322.  
  323. $fp = @fopen($tmpfname, 'w');
  324.  
  325. @fwrite($fp, 'test');
  326.  
  327. @fclose($fp);
  328.  
  329. $result = @ftp_chdir($conn_id, $attach_config['ftp_path']);
  330.  
  331. if (!$result)
  332. {
  333. $error = TRUE;
  334. $error_msg = sprintf($lang['Ftp_error_path'], $attach_config['ftp_path']) . '<br />';
  335. }
  336. else
  337. {
  338. $res = @ftp_put($conn_id, 't0000', $tmpfname, FTP_ASCII);
  339. if (!$res)
  340. {
  341. $error = TRUE;
  342. $error_msg = sprintf($lang['Ftp_error_upload'], $attach_config['ftp_path']) . '<br />';
  343. }
  344. else
  345. {
  346. $res = @ftp_delete($conn_id, 't0000');
  347.  
  348. if (!$res)
  349. {
  350. $error = TRUE;
  351. $error_msg = sprintf($lang['Ftp_error_delete'], $attach_config['ftp_path']) . '<br />';
  352. }
  353. }
  354. }
  355.  
  356. @ftp_quit($conn_id);
  357.  
  358. @unlink($tmpfname);
  359. }
  360. }
  361. if (!$error)
  362. {
  363. message_die(GENERAL_MESSAGE, $lang['Test_settings_successful'] . '<br /><br />' . sprintf($lang['Click_return_attach_config'], '<a href="' . append_sid("admin_attachments.$phpEx?mode=manage") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>'));
  364. }
  365. }
  366.  
  367. if ($submit && $mode == 'manage')
  368. {
  369. if (!$error)
  370. {
  371. message_die(GENERAL_MESSAGE, $lang['Attach_config_updated'] . '<br /><br />' . sprintf($lang['Click_return_attach_config'], '<a href="' . append_sid("admin_attachments.$phpEx?mode=manage") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>'));
  372. }
  373. }
  374.  
  375. if ($mode == 'manage')
  376. {
  377. $template->set_filenames(array(
  378. 'body' => 'admin/attach_manage_body.tpl')
  379. );
  380.  
  381. $yes_no_switches = array('disable_mod', 'allow_pm_attach', 'allow_ftp_upload', 'attachment_topic_review', 'display_order', 'show_apcp', 'ftp_pasv_mode');
  382.  
  383. for ($i = 0; $i < sizeof($yes_no_switches); $i++)
  384. {
  385. eval("\$" . $yes_no_switches[$i] . "_yes = ( \$new_attach['" . $yes_no_switches[$i] . "'] != '0' ) ? 'checked=\"checked\"' : '';");
  386. eval("\$" . $yes_no_switches[$i] . "_no = ( \$new_attach['" . $yes_no_switches[$i] . "'] == '0' ) ? 'checked=\"checked\"' : '';");
  387. }
  388.  
  389. if (!function_exists('ftp_connect'))
  390. {
  391. $template->assign_block_vars('switch_no_ftp', array());
  392. }
  393. else
  394. {
  395. $template->assign_block_vars('switch_ftp', array());
  396. }
  397.  
  398. $template->assign_vars(array(
  399. 'L_MANAGE_TITLE' => $lang['Attach_settings'],
  400. 'L_MANAGE_EXPLAIN' => $lang['Manage_attachments_explain'],
  401. 'L_ATTACHMENT_SETTINGS' => $lang['Attach_settings'],
  402. 'L_ATTACHMENT_FILESIZE_SETTINGS'=> $lang['Attach_filesize_settings'],
  403. 'L_ATTACHMENT_NUMBER_SETTINGS' => $lang['Attach_number_settings'],
  404. 'L_ATTACHMENT_OPTIONS_SETTINGS' => $lang['Attach_options_settings'],
  405. 'L_ATTACHMENT_FTP_SETTINGS' => $lang['ftp_info'],
  406. 'L_NO_FTP_EXTENSIONS' => $lang['No_ftp_extensions_installed'],
  407. 'L_UPLOAD_DIR' => $lang['Upload_directory'],
  408. 'L_UPLOAD_DIR_EXPLAIN' => $lang['Upload_directory_explain'],
  409. 'L_ATTACHMENT_IMG_PATH' => $lang['Attach_img_path'],
  410. 'L_IMG_PATH_EXPLAIN' => $lang['Attach_img_path_explain'],
  411. 'L_ATTACHMENT_TOPIC_ICON' => $lang['Attach_topic_icon'],
  412. 'L_TOPIC_ICON_EXPLAIN' => $lang['Attach_topic_icon_explain'],
  413. 'L_DISPLAY_ORDER' => $lang['Attach_display_order'],
  414. 'L_DISPLAY_ORDER_EXPLAIN' => $lang['Attach_display_order_explain'],
  415. 'L_YES' => $lang['Yes'],
  416. 'L_NO' => $lang['No'],
  417. 'L_DESC' => $lang['Sort_Descending'],
  418. 'L_ASC' => $lang['Sort_Ascending'],
  419. 'L_SUBMIT' => $lang['Submit'],
  420. 'L_RESET' => $lang['Reset'],
  421. 'L_MAX_FILESIZE' => $lang['Max_filesize_attach'],
  422. 'L_MAX_FILESIZE_EXPLAIN' => $lang['Max_filesize_attach_explain'],
  423. 'L_ATTACH_QUOTA' => $lang['Attach_quota'],
  424. 'L_ATTACH_QUOTA_EXPLAIN' => $lang['Attach_quota_explain'],
  425. 'L_DEFAULT_QUOTA_LIMIT' => $lang['Default_quota_limit'],
  426. 'L_DEFAULT_QUOTA_LIMIT_EXPLAIN' => $lang['Default_quota_limit_explain'],
  427. 'L_MAX_FILESIZE_PM' => $lang['Max_filesize_pm'],
  428. 'L_MAX_FILESIZE_PM_EXPLAIN' => $lang['Max_filesize_pm_explain'],
  429. 'L_MAX_ATTACHMENTS' => $lang['Max_attachments'],
  430. 'L_MAX_ATTACHMENTS_EXPLAIN' => $lang['Max_attachments_explain'],
  431. 'L_MAX_ATTACHMENTS_PM' => $lang['Max_attachments_pm'],
  432. 'L_MAX_ATTACHMENTS_PM_EXPLAIN' => $lang['Max_attachments_pm_explain'],
  433. 'L_DISABLE_MOD' => $lang['Disable_mod'],
  434. 'L_DISABLE_MOD_EXPLAIN' => $lang['Disable_mod_explain'],
  435. 'L_PM_ATTACH' => $lang['PM_Attachments'],
  436. 'L_PM_ATTACH_EXPLAIN' => $lang['PM_Attachments_explain'],
  437. 'L_FTP_UPLOAD' => $lang['Ftp_upload'],
  438. 'L_FTP_UPLOAD_EXPLAIN' => $lang['Ftp_upload_explain'],
  439. 'L_ATTACHMENT_TOPIC_REVIEW' => $lang['Attachment_topic_review'],
  440. 'L_ATTACHMENT_TOPIC_REVIEW_EXPLAIN' => $lang['Attachment_topic_review_explain'],
  441. 'L_ATTACHMENT_FTP_PATH' => $lang['Attach_ftp_path'],
  442. 'L_ATTACHMENT_FTP_USER' => $lang['ftp_username'],
  443. 'L_ATTACHMENT_FTP_PASS' => $lang['ftp_password'],
  444. 'L_ATTACHMENT_FTP_PATH_EXPLAIN' => $lang['Attach_ftp_path_explain'],
  445. 'L_ATTACHMENT_FTP_SERVER' => $lang['Ftp_server'],
  446. 'L_ATTACHMENT_FTP_SERVER_EXPLAIN' => $lang['Ftp_server_explain'],
  447. 'L_FTP_PASSIVE_MODE' => $lang['Ftp_passive_mode'],
  448. 'L_FTP_PASSIVE_MODE_EXPLAIN' => $lang['Ftp_passive_mode_explain'],
  449. 'L_DOWNLOAD_PATH' => $lang['Ftp_download_path'],
  450. 'L_DOWNLOAD_PATH_EXPLAIN' => $lang['Ftp_download_path_explain'],
  451. 'L_SHOW_APCP' => $lang['Show_apcp'],
  452. 'L_SHOW_APCP_EXPLAIN' => $lang['Show_apcp_explain'],
  453. 'L_TEST_SETTINGS' => $lang['Test_settings'],
  454.  
  455. 'S_ATTACH_ACTION' => append_sid('admin_attachments.' . $phpEx . '?mode=manage'),
  456. 'S_FILESIZE' => $select_size_mode,
  457. 'S_FILESIZE_QUOTA' => $select_quota_size_mode,
  458. 'S_FILESIZE_PM' => $select_pm_size_mode,
  459. 'S_DEFAULT_UPLOAD_LIMIT'=> default_quota_limit_select('default_upload_quota', intval(trim($new_attach['default_upload_quota']))),
  460. 'S_DEFAULT_PM_LIMIT' => default_quota_limit_select('default_pm_quota', intval(trim($new_attach['default_pm_quota']))),
  461. 'L_UPLOAD_QUOTA' => $lang['Upload_quota'],
  462. 'L_PM_QUOTA' => $lang['Pm_quota'],
  463.  
  464. 'UPLOAD_DIR' => $new_attach['upload_dir'],
  465. 'ATTACHMENT_IMG_PATH' => $new_attach['upload_img'],
  466. 'TOPIC_ICON' => $new_attach['topic_icon'],
  467. 'MAX_FILESIZE' => $new_attach['max_filesize'],
  468. 'ATTACHMENT_QUOTA' => $new_attach['attachment_quota'],
  469. 'MAX_FILESIZE_PM' => $new_attach['max_filesize_pm'],
  470. 'MAX_ATTACHMENTS' => $new_attach['max_attachments'],
  471. 'MAX_ATTACHMENTS_PM' => $new_attach['max_attachments_pm'],
  472. 'FTP_SERVER' => $new_attach['ftp_server'],
  473. 'FTP_PATH' => $new_attach['ftp_path'],
  474. 'FTP_USER' => $new_attach['ftp_user'],
  475. 'FTP_PASS' => $new_attach['ftp_pass'],
  476. 'DOWNLOAD_PATH' => $new_attach['download_path'],
  477. 'DISABLE_MOD_YES' => $disable_mod_yes,
  478. 'DISABLE_MOD_NO' => $disable_mod_no,
  479. 'PM_ATTACH_YES' => $allow_pm_attach_yes,
  480. 'PM_ATTACH_NO' => $allow_pm_attach_no,
  481. 'FTP_UPLOAD_YES' => $allow_ftp_upload_yes,
  482. 'FTP_UPLOAD_NO' => $allow_ftp_upload_no,
  483. 'FTP_PASV_MODE_YES' => $ftp_pasv_mode_yes,
  484. 'FTP_PASV_MODE_NO' => $ftp_pasv_mode_no,
  485. 'TOPIC_REVIEW_YES' => $attachment_topic_review_yes,
  486. 'TOPIC_REVIEW_NO' => $attachment_topic_review_no,
  487. 'DISPLAY_ORDER_ASC' => $display_order_yes,
  488. 'DISPLAY_ORDER_DESC' => $display_order_no,
  489. 'SHOW_APCP_YES' => $show_apcp_yes,
  490. 'SHOW_APCP_NO' => $show_apcp_no)
  491. );
  492. }
  493.  
  494. if ($submit && $mode == 'shadow')
  495. {
  496. $attach_file_list = get_var('attach_file_list', array(''));
  497. for ($i = 0; $i < sizeof($attach_file_list); $i++)
  498. {
  499. unlink_attach($attach_file_list[$i]);
  500. unlink_attach($attach_file_list[$i], MODE_THUMBNAIL);
  501. }
  502.  
  503. $attach_id_list = get_var('attach_id_list', array(0));
  504.  
  505. $attach_id_sql = implode(', ', $attach_id_list);
  506.  
  507. if ($attach_id_sql != '')
  508. {
  509. $sql = 'DELETE
  510. FROM ' . ATTACHMENTS_DESC_TABLE . '
  511. WHERE attach_id IN (' . $attach_id_sql . ')';
  512.  
  513. if (!$result = $db->sql_query($sql))
  514. {
  515. message_die(GENERAL_ERROR, 'Could not delete attachment entries', '', __LINE__, __FILE__, $sql);
  516. }
  517.  
  518. $sql = 'DELETE
  519. FROM ' . ATTACHMENTS_TABLE . '
  520. WHERE attach_id IN (' . $attach_id_sql . ')';
  521.  
  522. if (!$result = $db->sql_query($sql))
  523. {
  524. message_die(GENERAL_ERROR, 'Could not delete attachment entries', '', __LINE__, __FILE__, $sql);
  525. }
  526. }
  527.  
  528. $message = $lang['Attach_config_updated'] . '<br /><br />' . sprintf($lang['Click_return_attach_config'], '<a href="' . append_sid("admin_attachments.$phpEx?mode=shadow") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
  529.  
  530. message_die(GENERAL_MESSAGE, $message);
  531. }
  532.  
  533. if ($mode == 'shadow')
  534. {
  535. @set_time_limit(0);
  536.  
  537. $template->set_filenames(array(
  538. 'body' => 'admin/attach_shadow.tpl')
  539. );
  540.  
  541. $shadow_attachments = array();
  542. $shadow_row = array();
  543.  
  544. $template->assign_vars(array(
  545. 'L_SHADOW_TITLE' => $lang['Shadow_attachments'],
  546. 'L_SHADOW_EXPLAIN' => $lang['Shadow_attachments_explain'],
  547. 'L_EXPLAIN_FILE' => $lang['Shadow_attachments_file_explain'],
  548. 'L_EXPLAIN_ROW' => $lang['Shadow_attachments_row_explain'],
  549. 'L_ATTACHMENT' => $lang['Attachment'],
  550. 'L_COMMENT' => $lang['File_comment'],
  551. 'L_DELETE' => $lang['Delete'],
  552. 'L_DELETE_MARKED' => $lang['Delete_marked'],
  553. 'L_MARK_ALL' => $lang['Mark_all'],
  554. 'L_UNMARK_ALL' => $lang['Unmark_all'],
  555. 'S_HIDDEN' => $hidden,
  556. 'S_ATTACH_ACTION' => append_sid('admin_attachments.' . $phpEx . '?mode=shadow'))
  557. );
  558.  
  559. $table_attachments = array();
  560. $assign_attachments = array();
  561. $file_attachments = array();
  562.  
  563. $sql = 'SELECT attach_id, physical_filename, comment
  564. FROM ' . ATTACHMENTS_DESC_TABLE . '
  565. ORDER BY attach_id';
  566.  
  567. if (!($result = $db->sql_query($sql)))
  568. {
  569. message_die(GENERAL_ERROR, 'Could not get attachment informations', '', __LINE__, __FILE__, $sql);
  570. }
  571.  
  572. $i = 0;
  573. while ($row = $db->sql_fetchrow($result))
  574. {
  575. $table_attachments['attach_id'][$i] = (int) $row['attach_id'];
  576. $table_attachments['physical_filename'][$i] = basename($row['physical_filename']);
  577. $table_attachments['comment'][$i] = $row['comment'];
  578. $i++;
  579. }
  580. $db->sql_freeresult($result);
  581.  
  582. $sql = 'SELECT attach_id
  583. FROM ' . ATTACHMENTS_TABLE . '
  584. GROUP BY attach_id';
  585.  
  586. if (!($result = $db->sql_query($sql)))
  587. {
  588. message_die(GENERAL_ERROR, 'Could not get attachment informations', '', __LINE__, __FILE__, $sql);
  589. }
  590.  
  591. while ($row = $db->sql_fetchrow($result))
  592. {
  593. $assign_attachments[] = intval($row['attach_id']);
  594. }
  595. $db->sql_freeresult($result);
  596.  
  597. $file_attachments = collect_attachments();
  598.  
  599. $shadow_attachments = array();
  600. $shadow_row = array();
  601.  
  602. for ($i = 0; $i < sizeof($file_attachments); $i++)
  603. {
  604. if (sizeof($table_attachments['attach_id']) > 0)
  605. {
  606. if ($file_attachments[$i] != '')
  607. {
  608. if (!in_array(trim($file_attachments[$i]), $table_attachments['physical_filename']) )
  609. {
  610. $shadow_attachments[] = trim($file_attachments[$i]);
  611. $file_attachments[$i] = '';
  612. }
  613. }
  614. }
  615. else
  616. {
  617. if ($file_attachments[$i] != '')
  618. {
  619. $shadow_attachments[] = trim($file_attachments[$i]);
  620. $file_attachments[$i] = '';
  621. }
  622. }
  623. }
  624.  
  625. for ($i = 0; $i < sizeof($assign_attachments); $i++)
  626. {
  627. if (!in_array($assign_attachments[$i], $table_attachments['attach_id']))
  628. {
  629. $shadow_row['attach_id'][] = $assign_attachments[$i];
  630. $shadow_row['physical_filename'][] = $assign_attachments[$i];
  631. $shadow_row['comment'][] = $lang['Empty_file_entry'];
  632. }
  633. }
  634.  
  635. for ($i = 0; $i < sizeof($table_attachments['attach_id']); $i++)
  636. {
  637. if ($table_attachments['physical_filename'][$i] != '')
  638. {
  639. if ( !in_array(trim($table_attachments['physical_filename'][$i]), $file_attachments))
  640. {
  641. $shadow_row['attach_id'][] = $table_attachments['attach_id'][$i];
  642. $shadow_row['physical_filename'][] = trim($table_attachments['physical_filename'][$i]);
  643. $shadow_row['comment'][] = $table_attachments['comment'][$i];
  644.  
  645. $table_attachments['attach_id'][$i] = 0;
  646. $table_attachments['physical_filename'][$i] = '';
  647. $table_attachments['comment'][$i] = '';
  648. }
  649. }
  650. }
  651.  
  652. for ($i = 0; $i < sizeof($table_attachments['attach_id']); $i++)
  653. {
  654. if ($table_attachments['attach_id'][$i])
  655. {
  656. if (!entry_exists($table_attachments['attach_id'][$i]))
  657. {
  658. $shadow_row['attach_id'][] = $table_attachments['attach_id'][$i];
  659. $shadow_row['physical_filename'][] = trim($table_attachments['physical_filename'][$i]);
  660. $shadow_row['comment'][] = $table_attachments['comment'][$i];
  661. }
  662. }
  663. }
  664.  
  665. for ($i = 0; $i < sizeof($shadow_attachments); $i++)
  666. {
  667. $template->assign_block_vars('file_shadow_row', array(
  668. 'ATTACH_ID' => $shadow_attachments[$i],
  669. 'ATTACH_FILENAME' => $shadow_attachments[$i],
  670. 'ATTACH_COMMENT' => $lang['No_file_comment_available'],
  671. 'U_ATTACHMENT' => $upload_dir . '/' . basename($shadow_attachments[$i]))
  672. );
  673. }
  674.  
  675. for ($i = 0; $i < sizeof($shadow_row['attach_id']); $i++)
  676. {
  677. $template->assign_block_vars('table_shadow_row', array(
  678. 'ATTACH_ID' => $shadow_row['attach_id'][$i],
  679. 'ATTACH_FILENAME' => basename($shadow_row['physical_filename'][$i]),
  680. 'ATTACH_COMMENT' => (trim($shadow_row['comment'][$i]) == '') ? $lang['No_file_comment_available'] : trim($shadow_row['comment'][$i]))
  681. );
  682. }
  683. }
  684.  
  685. if ($submit && $mode == 'cats')
  686. {
  687. if (!$error)
  688. {
  689. message_die(GENERAL_MESSAGE, $lang['Attach_config_updated'] . '<br /><br />' . sprintf($lang['Click_return_attach_config'], '<a href="' . append_sid("admin_attachments.$phpEx?mode=cats") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>'));
  690. }
  691. }
  692.  
  693. if ($mode == 'cats')
  694. {
  695. $template->set_filenames(array(
  696. 'body' => 'admin/attach_cat_body.tpl')
  697. );
  698.  
  699. $s_assigned_group_images = $lang['None'];
  700. $s_assigned_group_streams = $lang['None'];
  701. $s_assigned_group_flash = $lang['None'];
  702. $sql = 'SELECT group_name, cat_id
  703. FROM ' . EXTENSION_GROUPS_TABLE . '
  704. WHERE cat_id > 0
  705. ORDER BY cat_id';
  706.  
  707. $s_assigned_group_images = array();
  708. $s_assigned_group_streams = array();
  709. $s_assigned_group_flash = array();
  710.  
  711. if (!($result = $db->sql_query($sql)))
  712. {
  713. message_die(GENERAL_ERROR, 'Could not get Group Names from ' . EXTENSION_GROUPS_TABLE, '', __LINE__, __FILE__, $sql);
  714. }
  715.  
  716. $row = $db->sql_fetchrowset($result);
  717. $db->sql_freeresult($result);
  718.  
  719. for ($i = 0; $i < sizeof($row); $i++)
  720. {
  721. if ($row[$i]['cat_id'] == IMAGE_CAT)
  722. {
  723. $s_assigned_group_images[] = $row[$i]['group_name'];
  724. }
  725. else if ($row[$i]['cat_id'] == STREAM_CAT)
  726. {
  727. $s_assigned_group_streams[] = $row[$i]['group_name'];
  728. }
  729. else if ($row[$i]['cat_id'] == SWF_CAT)
  730. {
  731. $s_assigned_group_flash[] = $row[$i]['group_name'];
  732. }
  733. }
  734.  
  735. $display_inlined_yes = ( $new_attach['img_display_inlined'] != '0' ) ? 'checked="checked"' : '';
  736. $display_inlined_no = ( $new_attach['img_display_inlined'] == '0' ) ? 'checked="checked"' : '';
  737.  
  738. $create_thumbnail_yes = ( $new_attach['img_create_thumbnail'] != '0' ) ? 'checked="checked"' : '';
  739. $create_thumbnail_no = ( $new_attach['img_create_thumbnail'] == '0' ) ? 'checked="checked"' : '';
  740.  
  741. $use_gd2_yes = ( $new_attach['use_gd2'] != '0' ) ? 'checked="checked"' : '';
  742. $use_gd2_no = ( $new_attach['use_gd2'] == '0' ) ? 'checked="checked"' : '';
  743.  
  744. if (!is_imagick() && !@extension_loaded('gd'))
  745. {
  746. $new_attach['img_create_thumbnail'] = '0';
  747. }
  748. else
  749. {
  750. $template->assign_block_vars('switch_thumbnail_support', array());
  751. }
  752.  
  753. $template->assign_vars(array(
  754. 'L_MANAGE_CAT_TITLE' => $lang['Manage_categories'],
  755. 'L_MANAGE_CAT_EXPLAIN' => $lang['Manage_categories_explain'],
  756. 'L_SETTINGS_CAT_IMAGES' => $lang['Settings_cat_images'],
  757. 'L_SETTINGS_CAT_STREAM' => $lang['Settings_cat_streams'],
  758. 'L_SETTINGS_CAT_FLASH' => $lang['Settings_cat_flash'],
  759. 'L_ASSIGNED_GROUP' => $lang['Assigned_group'],
  760.  
  761. 'L_DISPLAY_INLINED' => $lang['Display_inlined'],
  762. 'L_DISPLAY_INLINED_EXPLAIN' => $lang['Display_inlined_explain'],
  763. 'L_MAX_IMAGE_SIZE' => $lang['Max_image_size'],
  764. 'L_MAX_IMAGE_SIZE_EXPLAIN' => $lang['Max_image_size_explain'],
  765. 'L_IMAGE_LINK_SIZE' => $lang['Image_link_size'],
  766. 'L_IMAGE_LINK_SIZE_EXPLAIN' => $lang['Image_link_size_explain'],
  767. 'L_CREATE_THUMBNAIL' => $lang['Image_create_thumbnail'],
  768. 'L_CREATE_THUMBNAIL_EXPLAIN' => $lang['Image_create_thumbnail_explain'],
  769. 'L_MIN_THUMB_FILESIZE' => $lang['Image_min_thumb_filesize'],
  770. 'L_MIN_THUMB_FILESIZE_EXPLAIN' => $lang['Image_min_thumb_filesize_explain'],
  771. 'L_IMAGICK_PATH' => $lang['Image_imagick_path'],
  772. 'L_IMAGICK_PATH_EXPLAIN' => $lang['Image_imagick_path_explain'],
  773. 'L_SEARCH_IMAGICK' => $lang['Image_search_imagick'],
  774. 'L_BYTES' => $lang['Bytes'],
  775. 'L_TEST_SETTINGS' => $lang['Test_settings'],
  776. 'L_YES' => $lang['Yes'],
  777. 'L_NO' => $lang['No'],
  778. 'L_SUBMIT' => $lang['Submit'],
  779. 'L_RESET' => $lang['Reset'],
  780. 'L_USE_GD2' => $lang['Use_gd2'],
  781. 'L_USE_GD2_EXPLAIN' => $lang['Use_gd2_explain'],
  782.  
  783. 'IMAGE_MAX_HEIGHT' => $new_attach['img_max_height'],
  784. 'IMAGE_MAX_WIDTH' => $new_attach['img_max_width'],
  785. 'IMAGE_LINK_HEIGHT' => $new_attach['img_link_height'],
  786. 'IMAGE_LINK_WIDTH' => $new_attach['img_link_width'],
  787. 'IMAGE_MIN_THUMB_FILESIZE' => $new_attach['img_min_thumb_filesize'],
  788. 'IMAGE_IMAGICK_PATH' => $new_attach['img_imagick'],
  789.  
  790. 'DISPLAY_INLINED_YES' => $display_inlined_yes,
  791. 'DISPLAY_INLINED_NO' => $display_inlined_no,
  792. 'CREATE_THUMBNAIL_YES' => $create_thumbnail_yes,
  793. 'CREATE_THUMBNAIL_NO' => $create_thumbnail_no,
  794.  
  795. 'USE_GD2_YES' => $use_gd2_yes,
  796. 'USE_GD2_NO' => $use_gd2_no,
  797.  
  798. 'S_ASSIGNED_GROUP_IMAGES' => implode(', ', $s_assigned_group_images),
  799. 'S_ATTACH_ACTION' => append_sid('admin_attachments.' . $phpEx . '?mode=cats'))
  800. );
  801. }
  802.  
  803. if ($check_image_cat)
  804. {
  805. $attach_config = array();
  806.  
  807. $sql = 'SELECT *
  808. FROM ' . ATTACH_CONFIG_TABLE;
  809.  
  810. if (!($result = $db->sql_query($sql)))
  811. {
  812. message_die(GENERAL_ERROR, 'Could not find Attachment Config Table', '', __LINE__, __FILE__, $sql);
  813. }
  814.  
  815. $row = $db->sql_fetchrowset($result);
  816. $num_rows = $db->sql_numrows($result);
  817. $db->sql_freeresult($result);
  818.  
  819. for ($i = 0; $i < $num_rows; $i++)
  820. {
  821. $attach_config[$row[$i]['config_name']] = trim($row[$i]['config_value']);
  822. }
  823.  
  824. if ($attach_config['upload_dir'][0] == '/' || ($attach_config['upload_dir'][0] != '/' && $attach_config['upload_dir'][1] == ':'))
  825. {
  826. $upload_dir = $attach_config['upload_dir'];
  827. }
  828. else
  829. {
  830. $upload_dir = $phpbb_root_path . $attach_config['upload_dir'];
  831. }
  832. $upload_dir = $upload_dir . '/' . THUMB_DIR;
  833.  
  834. $error = false;
  835.  
  836. if (intval($attach_config['allow_ftp_upload']) == 0 && intval($attach_config['img_create_thumbnail']) == 1)
  837. {
  838. if (!@file_exists(@amod_realpath($upload_dir)))
  839. {
  840. @mkdir($upload_dir, 0755);
  841. @chmod($upload_dir, 0777);
  842. if (!@file_exists(@amod_realpath($upload_dir)))
  843. {
  844. $error = TRUE;
  845. $error_msg = sprintf($lang['Directory_does_not_exist'], $upload_dir) . '<br />';
  846. }
  847.  
  848. }
  849. if (!$error && !is_dir($upload_dir))
  850. {
  851. $error = TRUE;
  852. $error_msg = sprintf($lang['Directory_is_not_a_dir'], $upload_dir) . '<br />';
  853. }
  854. if (!$error)
  855. {
  856. if ( !($fp = @fopen($upload_dir . '/0_000000.000', 'w')) )
  857. {
  858. $error = TRUE;
  859. $error_msg = sprintf($lang['Directory_not_writeable'], $upload_dir) . '<br />';
  860. }
  861. else
  862. {
  863. @fclose($fp);
  864. @unlink($upload_dir . '/0_000000.000');
  865. }
  866. }
  867. }
  868. else if (intval($attach_config['allow_ftp_upload']) && intval($attach_config['img_create_thumbnail']))
  869. {
  870. $server = ( empty($attach_config['ftp_server']) ) ? 'localhost' : $attach_config['ftp_server'];
  871.  
  872. $conn_id = @ftp_connect($server);
  873.  
  874. if (!$conn_id)
  875. {
  876. $error = TRUE;
  877. $error_msg = sprintf($lang['Ftp_error_connect'], $server) . '<br />';
  878. }
  879.  
  880. $login_result = @ftp_login($conn_id, $attach_config['ftp_user'], $attach_config['ftp_pass']);
  881.  
  882. if (!$login_result && !$error)
  883. {
  884. $error = TRUE;
  885. $error_msg = sprintf($lang['Ftp_error_login'], $attach_config['ftp_user']) . '<br />';
  886. }
  887. if (!@ftp_pasv($conn_id, intval($attach_config['ftp_pasv_mode'])))
  888. {
  889. $error = TRUE;
  890. $error_msg = $lang['Ftp_error_pasv_mode'];
  891. }
  892.  
  893. if (!$error)
  894. {
  895. $tmpfname = @tempnam('/tmp', 't0000');
  896.  
  897. @unlink($tmpfname); // unlink for safety on php4.0.3+
  898.  
  899. $fp = @fopen($tmpfname, 'w');
  900.  
  901. @fwrite($fp, 'test');
  902.  
  903. @fclose($fp);
  904.  
  905. $result = @ftp_chdir($conn_id, $attach_config['ftp_path'] . '/' . THUMB_DIR);
  906. if (!$result)
  907. {
  908. @ftp_mkdir($conn_id, $attach_config['ftp_path'] . '/' . THUMB_DIR);
  909. }
  910. $result = @ftp_chdir($conn_id, $attach_config['ftp_path'] . '/' . THUMB_DIR);
  911.  
  912. if (!$result)
  913. {
  914. $error = TRUE;
  915. $error_msg = sprintf($lang['Ftp_error_path'], $attach_config['ftp_path'] . '/' . THUMB_DIR) . '<br />';
  916. }
  917. else
  918. {
  919. $res = @ftp_put($conn_id, 't0000', $tmpfname, FTP_ASCII);
  920. if (!$res)
  921. {
  922. $error = TRUE;
  923. $error_msg = sprintf($lang['Ftp_error_upload'], $attach_config['ftp_path'] . '/' . THUMB_DIR) . '<br />';
  924. }
  925. else
  926. {
  927. $res = @ftp_delete($conn_id, 't0000');
  928.  
  929. if (!$res)
  930. {
  931. $error = TRUE;
  932. $error_msg = sprintf($lang['Ftp_error_delete'], $attach_config['ftp_path'] . '/' . THUMB_DIR) . '<br />';
  933. }
  934. }
  935. }
  936.  
  937. @ftp_quit($conn_id);
  938.  
  939. @unlink($tmpfname);
  940. }
  941. }
  942. if (!$error)
  943. {
  944. message_die(GENERAL_MESSAGE, $lang['Test_settings_successful'] . '<br /><br />' . sprintf($lang['Click_return_attach_config'], '<a href="' . append_sid("admin_attachments.$phpEx?mode=cats") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>'));
  945. }
  946. }
  947.  
  948.  
  949.  
  950. if ($submit && $mode == 'quota')
  951. {
  952. $quota_change_list = get_var('quota_change_list', array(0));
  953. $quota_desc_list = get_var('quota_desc_list', array(''));
  954. $filesize_list = get_var('max_filesize_list', array(0));
  955. $size_select_list = get_var('size_select_list', array(''));
  956.  
  957. $allowed_list = array();
  958.  
  959. for ($i = 0; $i < sizeof($quota_change_list); $i++)
  960. {
  961. $filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : ( ($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i] );
  962.  
  963. $sql = 'UPDATE ' . QUOTA_LIMITS_TABLE . "
  964. SET quota_desc = '" . attach_mod_sql_escape($quota_desc_list[$i]) . "', quota_limit = " . (int) $filesize_list[$i] . "
  965. WHERE quota_limit_id = " . (int) $quota_change_list[$i];
  966. if (!($db->sql_query($sql)))
  967. {
  968. message_die(GENERAL_ERROR, 'Couldn\'t update Quota Limits', '', __LINE__, __FILE__, $sql);
  969. }
  970. }
  971.  
  972. $quota_id_list = get_var('quota_id_list', array(0));
  973.  
  974. $quota_id_sql = implode(', ', $quota_id_list);
  975.  
  976. if ($quota_id_sql != '')
  977. {
  978. $sql = 'DELETE
  979. FROM ' . QUOTA_LIMITS_TABLE . '
  980. WHERE quota_limit_id IN (' . $quota_id_sql . ')';
  981.  
  982. if (!($result = $db->sql_query($sql)))
  983. {
  984. message_die(GENERAL_ERROR, 'Could not delete Quota Limits', '', __LINE__, __FILE__, $sql);
  985. }
  986.  
  987. $sql = 'DELETE
  988. FROM ' . QUOTA_TABLE . '
  989. WHERE quota_limit_id IN (' . $quota_id_sql . ')';
  990.  
  991. if (!($result = $db->sql_query($sql)))
  992. {
  993. message_die(GENERAL_ERROR, 'Could not delete Quotas', '', __LINE__, __FILE__, $sql);
  994. }
  995. }
  996.  
  997. $quota_desc = get_var('quota_description', '');
  998. $filesize = get_var('add_max_filesize', 0);
  999. $size_select = get_var('add_size_select', '');
  1000. $add = ( isset($HTTP_POST_VARS['add_quota_check']) ) ? TRUE : FALSE;
  1001.  
  1002. if ($quota_desc != '' && $add)
  1003. {
  1004. $sql = 'SELECT quota_desc
  1005. FROM ' . QUOTA_LIMITS_TABLE;
  1006. if (!($result = $db->sql_query($sql)))
  1007. {
  1008. message_die(GENERAL_ERROR, 'Could not query Quota Limits Table', '', __LINE__, __FILE__, $sql);
  1009. }
  1010. $row = $db->sql_fetchrowset($result);
  1011. $num_rows = $db->sql_numrows($result);
  1012. $db->sql_freeresult($result);
  1013.  
  1014. if ($num_rows > 0)
  1015. {
  1016. for ($i = 0; $i < $num_rows; $i++)
  1017. {
  1018. if ($row[$i]['quota_desc'] == $quota_desc)
  1019. {
  1020. $error = TRUE;
  1021. if( isset($error_msg) )
  1022. {
  1023. $error_msg .= '<br />';
  1024. }
  1025. $error_msg .= sprintf($lang['Quota_limit_exist'], $extension_group);
  1026. }
  1027. }
  1028. }
  1029. if (!$error)
  1030. {
  1031. $filesize = ($size_select == 'kb' ) ? round($filesize * 1024) : ( ($size_select == 'mb') ? round($filesize * 1048576) : $filesize );
  1032. $sql = "INSERT INTO " . QUOTA_LIMITS_TABLE . " (quota_desc, quota_limit)
  1033. VALUES ('" . attach_mod_sql_escape($quota_desc) . "', " . (int) $filesize . ")";
  1034. if (!($db->sql_query($sql)))
  1035. {
  1036. message_die(GENERAL_ERROR, 'Could not add Quota Limit', '', __LINE__, __FILE__, $sql);
  1037. }
  1038. }
  1039.  
  1040. }
  1041.  
  1042. if (!$error)
  1043. {
  1044. $message = $lang['Attach_config_updated'] . '<br /><br />' . sprintf($lang['Click_return_attach_config'], '<a href="' . append_sid("admin_attachments.$phpEx?mode=quota") . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_admin_index'], '<a href="' . append_sid("index.$phpEx?pane=right") . '">', '</a>');
  1045.  
  1046. message_die(GENERAL_MESSAGE, $message);
  1047. }
  1048.  
  1049. }
  1050.  
  1051. if ($mode == 'quota')
  1052. {
  1053. $template->set_filenames(array(
  1054. 'body' => 'admin/attach_quota_body.tpl')
  1055. );
  1056.  
  1057. $max_add_filesize = $attach_config['max_filesize'];
  1058. $size = ($max_add_filesize >= 1048576) ? 'mb' : ( ($max_add_filesize >= 1024) ? 'kb' : 'b' );
  1059.  
  1060. if ($max_add_filesize >= 1048576)
  1061. {
  1062. $max_add_filesize = round($max_add_filesize / 1048576 * 100) / 100;
  1063. }
  1064. else if ( $max_add_filesize >= 1024)
  1065. {
  1066. $max_add_filesize = round($max_add_filesize / 1024 * 100) / 100;
  1067. }
  1068.  
  1069. $template->assign_vars(array(
  1070. 'L_MANAGE_QUOTAS_TITLE' => $lang['Manage_quotas'],
  1071. 'L_MANAGE_QUOTAS_EXPLAIN' => $lang['Manage_quotas_explain'],
  1072. 'L_SUBMIT' => $lang['Submit'],
  1073. 'L_RESET' => $lang['Reset'],
  1074. 'L_EDIT' => $lang['Edit'],
  1075. 'L_VIEW' => $lang['View'],
  1076. 'L_DESCRIPTION' => $lang['Description'],
  1077. 'L_SIZE' => $lang['Max_filesize_attach'],
  1078. 'L_ADD_NEW' => $lang['Add_new'],
  1079. 'L_DELETE' => $lang['Delete'],
  1080. 'MAX_FILESIZE' => $max_add_filesize,
  1081.  
  1082. 'S_FILESIZE' => size_select('add_size_select', $size),
  1083. 'L_REMOVE_SELECTED' => $lang['Remove_selected'],
  1084.  
  1085. 'S_ATTACH_ACTION' => append_sid('admin_attachments.' . $phpEx . '?mode=quota'))
  1086. );
  1087.  
  1088. $sql = "SELECT * FROM " . QUOTA_LIMITS_TABLE . " ORDER BY quota_limit DESC";
  1089.  
  1090. if (!($result = $db->sql_query($sql)))
  1091. {
  1092. message_die(GENERAL_ERROR, 'Could not get quota limits', '', __LINE__, __FILE__, $sql);
  1093. }
  1094. $rows = $db->sql_fetchrowset($result);
  1095. $db->sql_freeresult($result);
  1096.  
  1097. for ($i = 0; $i < sizeof($rows); $i++)
  1098. {
  1099. $size_format = ($rows[$i]['quota_limit'] >= 1048576) ? 'mb' : ( ($rows[$i]['quota_limit'] >= 1024) ? 'kb' : 'b' );
  1100.  
  1101. if ($rows[$i]['quota_limit'] >= 1048576)
  1102. {
  1103. $rows[$i]['quota_limit'] = round($rows[$i]['quota_limit'] / 1048576 * 100) / 100;
  1104. }
  1105. else if($rows[$i]['quota_limit'] >= 1024)
  1106. {
  1107. $rows[$i]['quota_limit'] = round($rows[$i]['quota_limit'] / 1024 * 100) / 100;
  1108. }
  1109.  
  1110. $template->assign_block_vars('limit_row', array(
  1111. 'QUOTA_NAME' => $rows[$i]['quota_desc'],
  1112. 'QUOTA_ID' => $rows[$i]['quota_limit_id'],
  1113. 'S_FILESIZE' => size_select('size_select_list[]', $size_format),
  1114. 'U_VIEW' => append_sid("admin_attachments.$phpEx?mode=$mode&amp;e_mode=view_quota&amp;quota_id=" . $rows[$i]['quota_limit_id']),
  1115. 'MAX_FILESIZE' => $rows[$i]['quota_limit'])
  1116. );
  1117. }
  1118. }
  1119.  
  1120. if ($mode == 'quota' && $e_mode == 'view_quota')
  1121. {
  1122. $quota_id = get_var('quota_id', 0);
  1123. if (!$quota_id)
  1124. {
  1125. message_die(GENERAL_MESSAGE, 'Invalid Call');
  1126. }
  1127.  
  1128. $template->assign_block_vars('switch_quota_limit_desc', array());
  1129.  
  1130. $sql = "SELECT * FROM " . QUOTA_LIMITS_TABLE . " WHERE quota_limit_id = " . (int) $quota_id . " LIMIT 1";
  1131.  
  1132. if (!($result = $db->sql_query($sql)))
  1133. {
  1134. message_die(GENERAL_ERROR, 'Could not get quota limits', '', __LINE__, __FILE__, $sql);
  1135. }
  1136. $row = $db->sql_fetchrow($result);
  1137. $db->sql_freeresult($result);
  1138.  
  1139. $template->assign_vars(array(
  1140. 'L_QUOTA_LIMIT_DESC' => $row['quota_desc'],
  1141. 'L_ASSIGNED_USERS' => $lang['Assigned_users'],
  1142. 'L_ASSIGNED_GROUPS' => $lang['Assigned_groups'],
  1143. 'L_UPLOAD_QUOTA' => $lang['Upload_quota'],
  1144. 'L_PM_QUOTA' => $lang['Pm_quota'])
  1145. );
  1146. $sql = 'SELECT q.user_id, u.username, q.quota_type
  1147. FROM ' . QUOTA_TABLE . ' q, ' . USERS_TABLE . ' u
  1148. WHERE q.quota_limit_id = ' . (int) $quota_id . '
  1149. AND q.user_id <> 0
  1150. AND q.user_id = u.user_id';
  1151.  
  1152. if (!($result = $db->sql_query($sql)))
  1153. {
  1154. message_die(GENERAL_ERROR, 'Could not get quota limits', '', __LINE__, __FILE__, $sql);
  1155. }
  1156. $rows = $db->sql_fetchrowset($result);
  1157. $num_rows = $db->sql_numrows($result);
  1158. $db->sql_freeresult($result);
  1159.  
  1160. for ($i = 0; $i < $num_rows; $i++)
  1161. {
  1162. if ($rows[$i]['quota_type'] == QUOTA_UPLOAD_LIMIT)
  1163. {
  1164. $template->assign_block_vars('users_upload_row', array(
  1165. 'USER_ID' => $rows[$i]['user_id'],
  1166. 'USERNAME' => $rows[$i]['username'])
  1167. );
  1168. }
  1169. else if ($rows[$i]['quota_type'] == QUOTA_PM_LIMIT)
  1170. {
  1171. $template->assign_block_vars('users_pm_row', array(
  1172. 'USER_ID' => $rows[$i]['user_id'],
  1173. 'USERNAME' => $rows[$i]['username'])
  1174. );
  1175. }
  1176. }
  1177.  
  1178. $sql = 'SELECT q.group_id, g.group_name, q.quota_type
  1179. FROM ' . QUOTA_TABLE . ' q, ' . GROUPS_TABLE . ' g
  1180. WHERE q.quota_limit_id = ' . (int) $quota_id . '
  1181. AND q.group_id <> 0
  1182. AND q.group_id = g.group_id';
  1183.  
  1184. if (!($result = $db->sql_query($sql)))
  1185. {
  1186. message_die(GENERAL_ERROR, 'Could not get quota limits', '', __LINE__, __FILE__, $sql);
  1187. }
  1188. $rows = $db->sql_fetchrowset($result);
  1189. $num_rows = $db->sql_numrows($result);
  1190. $db->sql_freeresult($result);
  1191.  
  1192. for ($i = 0; $i < $num_rows; $i++)
  1193. {
  1194. if ($rows[$i]['quota_type'] == QUOTA_UPLOAD_LIMIT)
  1195. {
  1196. $template->assign_block_vars('groups_upload_row', array(
  1197. 'GROUP_ID' => $rows[$i]['group_id'],
  1198. 'GROUPNAME' => $rows[$i]['group_name'])
  1199. );
  1200. }
  1201. else if ($rows[$i]['quota_type'] == QUOTA_PM_LIMIT)
  1202. {
  1203. $template->assign_block_vars('groups_pm_row', array(
  1204. 'GROUP_ID' => $rows[$i]['group_id'],
  1205. 'GROUPNAME' => $rows[$i]['group_name'])
  1206. );
  1207. }
  1208. }
  1209. }
  1210.  
  1211.  
  1212. if ($error)
  1213. {
  1214. $template->set_filenames(array(
  1215. 'reg_header' => 'error_body.tpl')
  1216. );
  1217. $template->assign_vars(array(
  1218. 'ERROR_MESSAGE' => $error_msg)
  1219. );
  1220. $template->assign_var_from_handle('ERROR_BOX', 'reg_header');
  1221. }
  1222.  
  1223. $template->pparse('body');
  1224.  
  1225. include('page_footer_admin.'.$phpEx);
  1226.  
  1227. ?>