PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/NukeViet3.3/modules/download/admin/filequeue.php

http://nuke-viet.googlecode.com/
PHP | 786 lines | 674 code | 99 blank | 13 comment | 96 complexity | 5fb293b48031fc66221ac2cfdf519038 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES.,JSC. All rights reserved
  6. * @Createdate 2-9-2010 14:43
  7. */
  8. if ( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
  9. //Edit - accept file
  10. if ( $nv_Request->isset_request( 'edit', 'get' ) )
  11. {
  12. $page_title = $lang_module['download_filequeue'];
  13. $id = $nv_Request->get_int( 'id', 'get', 0 );
  14. if ( ! $id )
  15. {
  16. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=filequeue" );
  17. exit();
  18. }
  19. $query = "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_tmp` WHERE `id`=" . $id;
  20. $result = $db->sql_query( $query );
  21. $numrows = $db->sql_numrows( $result );
  22. if ( $numrows != 1 )
  23. {
  24. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=filequeue" );
  25. exit();
  26. }
  27. $row = $db->sql_fetchrow( $result );
  28. $groups_list = nv_groups_list();
  29. $array_who = array( $lang_global['who_view0'], $lang_global['who_view1'], $lang_global['who_view2'] );
  30. if ( ! empty( $groups_list ) )
  31. {
  32. $array_who[] = $lang_global['who_view3'];
  33. }
  34. $sql = "SELECT `config_value` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_config` WHERE `config_name`='upload_dir'";
  35. $result = $db->sql_query( $sql );
  36. list( $upload_dir ) = $db->sql_fetchrow( $result );
  37. $array = array();
  38. $is_error = false;
  39. $error = "";
  40. if ( $nv_Request->isset_request( 'submit', 'post' ) )
  41. {
  42. $array['catid'] = $nv_Request->get_int( 'catid', 'post', 0 );
  43. $array['title'] = filter_text_input( 'title', 'post', '', 1 );
  44. $array['description'] = nv_editor_filter_textarea( 'description', '', NV_ALLOWED_HTML_TAGS );
  45. $array['introtext'] = filter_text_textarea( 'introtext', '', NV_ALLOWED_HTML_TAGS );
  46. $array['user_name'] = filter_text_input( 'user_name', 'post', '', 1 );
  47. $array['author_name'] = filter_text_input( 'author_name', 'post', '', 1 );
  48. $array['author_email'] = filter_text_input( 'author_email', 'post', '' );
  49. $array['author_url'] = filter_text_input( 'author_url', 'post', '' );
  50. $array['fileupload'] = ! empty( $row['fileupload'] ) ? explode( "[NV]", $row['fileupload'] ) : array();
  51. if( ! empty( $array['fileupload'] ) )
  52. {
  53. $fileupload = $array['fileupload'];
  54. $array['fileupload'] = array();
  55. foreach( $fileupload as $file )
  56. {
  57. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['fileimage'] ) )
  58. {
  59. $file = NV_BASE_SITEURL . NV_UPLOADS_DIR . $file;
  60. }
  61. $array['fileupload'][] = $file;
  62. }
  63. }
  64. $array['fileupload2'] = $nv_Request->get_typed_array( 'fileupload2', 'post', 'string' );
  65. $array['linkdirect'] = $nv_Request->get_typed_array( 'linkdirect', 'post', 'string' );
  66. $array['version'] = filter_text_input( 'version', 'post', '', 1 );
  67. $array['filesize'] = $nv_Request->get_int( 'filesize', 'post', 0 );
  68. $array['fileimage'] = $row['fileimage'];
  69. if( ! empty( $array['fileimage'] ) )
  70. {
  71. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['fileimage'] ) )
  72. {
  73. $array['fileimage'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . $array['fileimage'];
  74. }
  75. }
  76. $array['fileimage2'] = filter_text_input( 'fileimage2', 'post', '' );
  77. $array['copyright'] = filter_text_input( 'copyright', 'post', '', 1 );
  78. $array['comment_allow'] = $nv_Request->get_int( 'comment_allow', 'post', 0 );
  79. $array['who_comment'] = $nv_Request->get_int( 'who_comment', 'post', 0 );
  80. $array['groups_comment'] = $nv_Request->get_typed_array( 'groups_comment', 'post', 'int' );
  81. // Sort image
  82. if ( ! empty ( $array['fileimage'] ) )
  83. {
  84. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['fileimage'] ) )
  85. {
  86. $array['fileimage'] = substr ( $array['fileimage'], strlen ( NV_BASE_SITEURL . NV_UPLOADS_DIR ) );
  87. }
  88. }
  89. if ( ! empty ( $array['fileimage2'] ) )
  90. {
  91. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['fileimage2'] ) )
  92. {
  93. $array['fileimage2'] = substr ( $array['fileimage2'], strlen ( NV_BASE_SITEURL . NV_UPLOADS_DIR ) );
  94. }
  95. }
  96. if ( ! empty( $array['author_url'] ) )
  97. {
  98. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['author_url'] ) )
  99. {
  100. $array['author_url'] = "http://" . $array['author_url'];
  101. }
  102. }
  103. if ( ! empty( $array['fileupload2'] ) )
  104. {
  105. $fileupload2 = $array['fileupload2'];
  106. $array['fileupload2'] = array();
  107. $array['filesize'] = 0;
  108. foreach ( $fileupload2 as $file )
  109. {
  110. if ( ! empty( $file ) )
  111. {
  112. $file2 = substr( $file, strlen( NV_BASE_SITEURL ) );
  113. if ( file_exists( NV_ROOTDIR . '/' . $file2 ) and ( $filesize = filesize( NV_ROOTDIR . '/' . $file2 ) ) != 0 )
  114. {
  115. $array['fileupload2'][] = substr ( $file, strlen ( NV_BASE_SITEURL . NV_UPLOADS_DIR ) );
  116. $array['filesize'] += $filesize;
  117. }
  118. }
  119. }
  120. }
  121. else
  122. {
  123. $array['fileupload2'] = array();
  124. }
  125. if ( empty( $array['fileupload2'] ) )
  126. {
  127. if ( ! empty( $array['fileupload'] ) )
  128. {
  129. $fileupload = $array['fileupload'];
  130. $array['fileupload'] = array();
  131. $array['filesize'] = 0;
  132. foreach ( $fileupload as $file )
  133. {
  134. if ( ! empty( $file ) )
  135. {
  136. $file2 = substr( $file, strlen( NV_BASE_SITEURL ) );
  137. if ( file_exists( NV_ROOTDIR . '/' . $file2 ) and ( $filesize = filesize( NV_ROOTDIR . '/' . $file2 ) ) != 0 )
  138. {
  139. $array['fileupload'][] = substr ( $file, strlen ( NV_BASE_SITEURL . NV_UPLOADS_DIR ) );
  140. $array['filesize'] += $filesize;
  141. }
  142. }
  143. }
  144. }
  145. else
  146. {
  147. $array['fileupload'] = array();
  148. }
  149. }
  150. if ( ! empty( $array['linkdirect'] ) )
  151. {
  152. $linkdirect = $array['linkdirect'];
  153. $array['linkdirect'] = array();
  154. foreach ( $linkdirect as $links )
  155. {
  156. $linkdirect = array();
  157. if ( ! empty( $links ) )
  158. {
  159. $links = nv_nl2br( $links, "<br />" );
  160. $links = explode( "<br />", $links );
  161. $links = array_map( "trim", $links );
  162. $links = array_unique( $links );
  163. foreach ( $links as $link )
  164. {
  165. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $link ) )
  166. {
  167. $link = "http://" . $link;
  168. }
  169. if ( nv_is_url( $link ) )
  170. {
  171. $linkdirect[] = $link;
  172. }
  173. }
  174. }
  175. if ( ! empty( $linkdirect ) )
  176. {
  177. $array['linkdirect'][] = implode( "\n", $linkdirect );
  178. }
  179. }
  180. }
  181. else
  182. {
  183. $array['linkdirect'] = array();
  184. }
  185. if ( ! empty( $array['linkdirect'] ) )
  186. {
  187. $array['linkdirect'] = array_unique( $array['linkdirect'] );
  188. }
  189. $sql = "SELECT COUNT(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "` WHERE `title`=" . $db->dbescape( $array['title'] );
  190. $result = $db->sql_query( $sql );
  191. list( $is_exists ) = $db->sql_fetchrow( $result );
  192. if ( empty( $array['title'] ) )
  193. {
  194. $is_error = true;
  195. $error = $lang_module['file_error_title'];
  196. }
  197. elseif ( $is_exists )
  198. {
  199. $is_error = true;
  200. $error = $lang_module['file_title_exists'];
  201. }
  202. elseif ( ! empty( $array['author_email'] ) and ( $check_valid_email = nv_check_valid_email( $array['author_email'] ) ) != "" )
  203. {
  204. $is_error = true;
  205. $error = $check_valid_email;
  206. }
  207. elseif ( ! empty( $array['author_url'] ) and ! nv_is_url( $array['author_url'] ) )
  208. {
  209. $is_error = true;
  210. $error = $lang_module['file_error_author_url'];
  211. }
  212. elseif ( empty( $array['fileupload'] ) and empty( $array['linkdirect'] ) and empty( $array['fileupload2'] ) )
  213. {
  214. $is_error = true;
  215. $error = $lang_module['file_error_fileupload'];
  216. }
  217. else
  218. {
  219. $alias = change_alias( $array['title'] );
  220. $array['description'] = nv_editor_nl2br( $array['description'] );
  221. $array['introtext'] = nv_nl2br( $array['introtext'], "<br />" );
  222. if ( ! in_array( $array['who_comment'], array_keys( $array_who ) ) )
  223. {
  224. $array['who_comment'] = 0;
  225. }
  226. $array['groups_comment'] = ( ! empty( $array['groups_comment'] ) ) ? implode( ',', $array['groups_comment'] ) : '';
  227. if ( $row['user_id'] )
  228. {
  229. $array['user_name'] = $row['user_name'];
  230. }
  231. if ( ! empty( $array['fileupload2'] ) )
  232. {
  233. $array['fileupload'] = $array['fileupload2'];
  234. }
  235. elseif ( ! empty( $array['fileupload'] ) )
  236. {
  237. $fileupload = $array['fileupload'];
  238. $array['fileupload'] = array();
  239. foreach ( $fileupload as $file )
  240. {
  241. $file = NV_UPLOADS_DIR . $file;
  242. $newfile = basename( $file );
  243. if ( preg_match( "/(.*)(\.[a-zA-Z0-9]{32})(\.[a-zA-Z]+)$/", $newfile, $m ) )
  244. {
  245. $newfile = $m[1] . $m[3];
  246. }
  247. $newfile2 = $newfile;
  248. $i = 1;
  249. while ( file_exists( NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $upload_dir . '/' . $newfile2 ) )
  250. {
  251. $newfile2 = preg_replace( '/(.*)(\.[a-zA-Z]+)$/', '\1_' . $i . '\2', $newfile );
  252. ++$i;
  253. }
  254. if ( @nv_copyfile( NV_ROOTDIR . '/' . $file, NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $upload_dir . '/' . $newfile2 ) )
  255. {
  256. $array['fileupload'][] = '/' . $module_name . '/' . $upload_dir . '/' . $newfile2;
  257. }
  258. }
  259. }
  260. $array['fileupload'] = ( ! empty( $array['fileupload'] ) ) ? implode( "[NV]", $array['fileupload'] ) : "";
  261. if ( ( ! empty( $array['linkdirect'] ) ) )
  262. {
  263. $array['linkdirect'] = array_map( "nv_nl2br", $array['linkdirect'] );
  264. $array['linkdirect'] = implode( "[NV]", $array['linkdirect'] );
  265. }
  266. else
  267. {
  268. $array['linkdirect'] = "";
  269. }
  270. if ( ! empty( $array['fileimage2'] ) )
  271. {
  272. $array['fileimage'] = $array['fileimage2'];
  273. }
  274. elseif ( ! empty( $array['fileimage'] ) )
  275. {
  276. $fileimage = NV_UPLOADS_DIR . $array['fileimage'];
  277. $array['fileimage'] = "";
  278. if ( file_exists( NV_ROOTDIR . '/' . $fileimage ) )
  279. {
  280. $newfile = basename( $fileimage );
  281. if ( preg_match( "/(.*)(\.[a-zA-Z0-9]{32})(\.[a-zA-Z]+)$/", $newfile, $m ) )
  282. {
  283. $newfile = $m[1] . $m[3];
  284. }
  285. $newfile2 = $newfile;
  286. $i = 1;
  287. while ( file_exists( NV_UPLOADS_REAL_DIR . '/' . $module_name . '/images/' . $newfile2 ) )
  288. {
  289. $newfile2 = preg_replace( '/(.*)(\.[a-zA-Z]+)$/', '\1_' . $i . '\2', $newfile );
  290. ++$i;
  291. }
  292. if ( @nv_copyfile( NV_ROOTDIR . '/' . $fileimage, NV_UPLOADS_REAL_DIR . '/' . $module_name . '/images/' . $newfile2 ) )
  293. {
  294. $array['fileimage'] = '/' . $module_name . '/images/' . $newfile2;
  295. }
  296. }
  297. }
  298. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "` VALUES (
  299. NULL,
  300. " . $array['catid'] . ",
  301. " . $db->dbescape( $array['title'] ) . ",
  302. " . $db->dbescape( $alias ) . ",
  303. " . $db->dbescape( $array['description'] ) . ",
  304. " . $db->dbescape( $array['introtext'] ) . ",
  305. " . $row['uploadtime'] . ",
  306. " . NV_CURRENTTIME . ",
  307. " . $row['user_id'] . ",
  308. " . $db->dbescape( $array['user_name'] ) . ",
  309. " . $db->dbescape( $array['author_name'] ) . ",
  310. " . $db->dbescape( $array['author_email'] ) . ",
  311. " . $db->dbescape( $array['author_url'] ) . ",
  312. " . $db->dbescape( $array['fileupload'] ) . ",
  313. " . $db->dbescape( $array['linkdirect'] ) . ",
  314. " . $db->dbescape( $array['version'] ) . ",
  315. " . $array['filesize'] . ",
  316. " . $db->dbescape( $array['fileimage'] ) . ",
  317. 1,
  318. " . $db->dbescape( $array['copyright'] ) . ",
  319. 0, 0,
  320. " . $array['comment_allow'] . ",
  321. " . $array['who_comment'] . ",
  322. " . $db->dbescape( $array['groups_comment'] ) . ",
  323. 0, '')";
  324. if ( ! $db->sql_query_insert_id( $sql ) )
  325. {
  326. $is_error = true;
  327. $error = $lang_module['file_error2'];
  328. }
  329. else
  330. {
  331. if ( ! empty( $row['fileupload'] ) )
  332. {
  333. $row['fileupload'] = explode( "[NV]", $row['fileupload'] );
  334. foreach ( $row['fileupload'] as $fileupload )
  335. {
  336. $fileupload = NV_UPLOADS_DIR . $fileupload;
  337. if ( file_exists( NV_ROOTDIR . '/' . $fileupload ) )
  338. {
  339. @nv_deletefile( NV_ROOTDIR . '/' . $fileupload );
  340. }
  341. }
  342. }
  343. if(empty( $row['fileimage'] ))
  344. {
  345. $fileimage = NV_UPLOADS_DIR . $row['fileimage'];
  346. if ( file_exists( NV_ROOTDIR . '/' . $fileimage ) )
  347. {
  348. @nv_deletefile( NV_ROOTDIR . '/' . $fileimage );
  349. }
  350. }
  351. $sql = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_tmp` WHERE `id`=" . $id;
  352. $db->sql_query( $sql );
  353. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=filequeue" );
  354. exit();
  355. }
  356. }
  357. }
  358. else
  359. {
  360. $array['catid'] = ( int )$row['catid'];
  361. $array['title'] = $row['title'];
  362. $array['description'] = nv_editor_br2nl( $row['description'] );
  363. $array['introtext'] = nv_br2nl( $row['introtext'] );
  364. $array['user_name'] = $row['user_name'];
  365. $array['author_name'] = $row['author_name'];
  366. $array['author_email'] = $row['author_email'];
  367. $array['author_url'] = $row['author_url'];
  368. $array['fileupload'] = $row['fileupload'];
  369. $array['fileupload2'] = array();
  370. $array['linkdirect'] = $row['linkdirect'];
  371. $array['version'] = $row['version'];
  372. $array['filesize'] = ( int )$row['filesize'];
  373. $array['fileimage'] = $row['fileimage'];
  374. $array['fileimage2'] = "";
  375. $array['copyright'] = $row['copyright'];
  376. $array['comment_allow'] = 1;
  377. $array['who_comment'] = 0;
  378. $array['groups_comment'] = array();
  379. $array['fileupload'] = ! empty( $array['fileupload'] ) ? explode( "[NV]", $array['fileupload'] ) : array();
  380. if ( ! empty( $array['linkdirect'] ) )
  381. {
  382. $array['linkdirect'] = explode( "[NV]", $array['linkdirect'] );
  383. $array['linkdirect'] = array_map( "nv_br2nl", $array['linkdirect'] );
  384. }
  385. else
  386. {
  387. $array['linkdirect'] = array();
  388. }
  389. }
  390. $array['id'] = ( int )$row['id'];
  391. if ( ! empty( $array['description'] ) ) $array['description'] = nv_htmlspecialchars( $array['description'] );
  392. if ( ! empty( $array['introtext'] ) ) $array['introtext'] = nv_htmlspecialchars( $array['introtext'] );
  393. //Rebuild fileupload
  394. if( ! empty( $array['fileupload'] ) )
  395. {
  396. $fileupload = $array['fileupload'];
  397. $array['fileupload'] = array();
  398. foreach( $fileupload as $tmp )
  399. {
  400. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $tmp ) )
  401. {
  402. $tmp = NV_BASE_SITEURL . NV_UPLOADS_DIR . $tmp;
  403. }
  404. $array['fileupload'][] = $tmp;
  405. }
  406. }
  407. if( ! empty( $array['fileupload2'] ) )
  408. {
  409. $fileupload2 = $array['fileupload2'];
  410. $array['fileupload2'] = array();
  411. foreach( $fileupload2 as $tmp )
  412. {
  413. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $tmp ) )
  414. {
  415. $tmp = NV_BASE_SITEURL . NV_UPLOADS_DIR . $tmp;
  416. }
  417. $array['fileupload2'][] = $tmp;
  418. }
  419. }
  420. if ( ! sizeof( $array['fileupload2'] ) ) array_push( $array['fileupload2'], "" );
  421. if ( ! sizeof( $array['linkdirect'] ) ) array_push( $array['linkdirect'], "" );
  422. $array['fileupload2_num'] = sizeof( $array['fileupload2'] );
  423. $array['linkdirect_num'] = sizeof( $array['linkdirect'] );
  424. // Build fileimage
  425. if ( ! empty ( $array['fileimage'] ) )
  426. {
  427. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['fileimage'] ) )
  428. {
  429. $array['fileimage'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . $array['fileimage'];
  430. }
  431. }
  432. if ( ! empty ( $array['fileimage2'] ) )
  433. {
  434. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['fileimage2'] ) )
  435. {
  436. $array['fileimage2'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . $array['fileimage2'];
  437. }
  438. }
  439. $listcats = nv_listcats( $array['catid'] );
  440. if ( empty( $listcats ) )
  441. {
  442. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=cat&add=1" );
  443. exit();
  444. }
  445. $array['comment_allow'] = $array['comment_allow'] ? " checked=\"checked\"" : "";
  446. $who_comment = $array['who_comment'];
  447. $array['who_comment'] = array();
  448. foreach ( $array_who as $key => $who )
  449. {
  450. $array['who_comment'][] = array( //
  451. 'key' => $key, //
  452. 'title' => $who, //
  453. 'selected' => $key == $who_comment ? " selected=\"selected\"" : "" //
  454. );
  455. }
  456. $groups_comment = $array['groups_comment'];
  457. $array['groups_comment'] = array();
  458. if ( ! empty( $groups_list ) )
  459. {
  460. foreach ( $groups_list as $key => $title )
  461. {
  462. $array['groups_comment'][] = array( //
  463. 'key' => $key, //
  464. 'title' => $title, //
  465. 'checked' => in_array( $key, $groups_comment ) ? " checked=\"checked\"" : "" //
  466. );
  467. }
  468. }
  469. if ( defined( 'NV_EDITOR' ) )
  470. {
  471. require_once ( NV_ROOTDIR . '/' . NV_EDITORSDIR . '/' . NV_EDITOR . '/nv.php' );
  472. }
  473. if ( defined( 'NV_EDITOR' ) and nv_function_exists( 'nv_aleditor' ) )
  474. {
  475. $array['description'] = nv_aleditor( 'description', '100%', '300px', $array['description'] );
  476. }
  477. else
  478. {
  479. $array['description'] = "<textarea style=\"width:100%; height:300px\" name=\"description\" id=\"description\">" . $array['description'] . "</textarea>";
  480. }
  481. if ( ! $array['filesize'] ) $array['filesize'] = "";
  482. $xtpl = new XTemplate( "filequeue_edit.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  483. $xtpl->assign( 'FORM_ACTION', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $op . "&amp;edit=1&amp;id=" . $id );
  484. $xtpl->assign( 'LANG', $lang_module );
  485. $xtpl->assign( 'DATA', $array );
  486. $xtpl->assign( 'NV_BASE_ADMINURL', NV_BASE_ADMINURL );
  487. $xtpl->assign( 'NV_NAME_VARIABLE', NV_NAME_VARIABLE );
  488. $xtpl->assign( 'IMG_DIR', NV_UPLOADS_DIR . '/' . $module_name . '/images' );
  489. $xtpl->assign( 'FILES_DIR', NV_UPLOADS_DIR . '/' . $module_name . '/' . $upload_dir );
  490. if ( ! empty( $error ) )
  491. {
  492. $xtpl->assign( 'ERROR', $error );
  493. $xtpl->parse( 'main.error' );
  494. }
  495. foreach ( $listcats as $cat )
  496. {
  497. $xtpl->assign( 'LISTCATS', $cat );
  498. $xtpl->parse( 'main.catid' );
  499. }
  500. if ( ! empty( $array['fileupload'] ) )
  501. {
  502. $a = 0;
  503. foreach ( $array['fileupload'] as $file )
  504. {
  505. $xtpl->assign( 'FILEUPLOAD', array( 'value' => $file, 'key' => $a ) );
  506. $xtpl->parse( 'main.fileupload' );
  507. ++$a;
  508. }
  509. $xtpl->parse( 'main.if_fileupload' );
  510. }
  511. $a = 0;
  512. foreach ( $array['fileupload2'] as $file )
  513. {
  514. $xtpl->assign( 'FILEUPLOAD2', array( 'value' => $file, 'key' => $a ) );
  515. $xtpl->parse( 'main.fileupload2' );
  516. ++$a;
  517. }
  518. $a = 0;
  519. foreach ( $array['linkdirect'] as $link )
  520. {
  521. $xtpl->assign( 'LINKDIRECT', array( 'value' => $link, 'key' => $a ) );
  522. $xtpl->parse( 'main.linkdirect' );
  523. ++$a;
  524. }
  525. if ( ! empty( $array['fileimage'] ) )
  526. {
  527. $xtpl->parse( 'main.fileimage.if_fileimage' );
  528. $xtpl->parse( 'main.fileimage' );
  529. }
  530. foreach ( $array['who_comment'] as $who )
  531. {
  532. $xtpl->assign( 'WHO_COMMENT', $who );
  533. $xtpl->parse( 'main.who_comment' );
  534. }
  535. if ( ! empty( $array['groups_comment'] ) )
  536. {
  537. foreach ( $array['groups_comment'] as $group )
  538. {
  539. $xtpl->assign( 'GROUPS_COMMENT', $group );
  540. $xtpl->parse( 'main.group_empty.groups_comment' );
  541. }
  542. $xtpl->parse( 'main.group_empty' );
  543. }
  544. $xtpl->parse( 'main' );
  545. $contents = $xtpl->text( 'main' );
  546. include ( NV_ROOTDIR . "/includes/header.php" );
  547. echo nv_admin_theme( $contents );
  548. include ( NV_ROOTDIR . "/includes/footer.php" );
  549. exit;
  550. }
  551. //Delete file
  552. if ( $nv_Request->isset_request( 'del', 'post' ) )
  553. {
  554. if ( ! defined( 'NV_IS_AJAX' ) ) die( 'Wrong URL' );
  555. $id = $nv_Request->get_int( 'id', 'post', 0 );
  556. if ( ! $id )
  557. {
  558. die( "NO" );
  559. }
  560. $query = "SELECT `fileupload`, `fileimage` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_tmp` WHERE `id`=" . $id;
  561. $result = $db->sql_query( $query );
  562. $numrows = $db->sql_numrows( $result );
  563. if ( $numrows != 1 )
  564. {
  565. die( "NO" );
  566. }
  567. list( $fileupload, $fileimage ) = $db->sql_fetchrow( $result );
  568. if ( ! empty( $fileupload ) )
  569. {
  570. $fileupload = explode( "[NV]", $fileupload );
  571. foreach ( $fileupload as $file )
  572. {
  573. $file = NV_UPLOADS_DIR . $file;
  574. if ( file_exists( NV_ROOTDIR . '/' . $file ) )
  575. {
  576. @nv_deletefile( NV_ROOTDIR . '/' . $file );
  577. }
  578. }
  579. }
  580. if ( ! empty( $fileimage ) )
  581. {
  582. $fileimage = NV_UPLOADS_DIR . $fileimage;
  583. if ( file_exists( NV_ROOTDIR . '/' . $fileimage ) )
  584. {
  585. @nv_deletefile( NV_ROOTDIR . '/' . $fileimage );
  586. }
  587. }
  588. $sql = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_tmp` WHERE `id`=" . $id;
  589. $db->sql_query( $sql );
  590. die( "OK" );
  591. }
  592. //All del
  593. if ( $nv_Request->isset_request( 'alldel', 'post' ) )
  594. {
  595. if ( ! defined( 'NV_IS_AJAX' ) ) die( 'Wrong URL' );
  596. $query = "SELECT `fileupload`, `fileimage` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_tmp`";
  597. $result = $db->sql_query( $query );
  598. $numrows = $db->sql_numrows( $result );
  599. if ( ! $numrows )
  600. {
  601. die( "NO" );
  602. }
  603. while ( list( $fileupload, $fileimage ) = $db->sql_fetchrow( $result ) )
  604. {
  605. if ( ! empty( $fileupload ) )
  606. {
  607. $fileupload = explode( "[NV]", $fileupload );
  608. foreach ( $fileupload as $file )
  609. {
  610. $file = NV_UPLOADS_DIR . $file;
  611. if ( file_exists( NV_ROOTDIR . '/' . $file ) )
  612. {
  613. @nv_deletefile( NV_ROOTDIR . '/' . $file );
  614. }
  615. }
  616. }
  617. if ( ! empty( $fileimage ) )
  618. {
  619. $fileimage = NV_UPLOADS_DIR . $fileimage;
  620. if ( file_exists( NV_ROOTDIR . '/' . $fileimage ) )
  621. {
  622. @nv_deletefile( NV_ROOTDIR . '/' . $fileimage );
  623. }
  624. }
  625. }
  626. $sql = "TRUNCATE TABLE `" . NV_PREFIXLANG . "_" . $module_data . "_tmp`";
  627. $db->sql_query( $sql );
  628. die( "OK" );
  629. }
  630. //List files
  631. $page_title = $lang_module['download_filequeue'];
  632. $sql = "FROM `" . NV_PREFIXLANG . "_" . $module_data . "_tmp`";
  633. $sql1 = "SELECT COUNT(*) " . $sql;
  634. $result1 = $db->sql_query( $sql1 );
  635. list( $all_file ) = $db->sql_fetchrow( $result1 );
  636. if ( ! $all_file )
  637. {
  638. $contents = "<div style=\"padding-top:15px;text-align:center\">\n";
  639. $contents .= "<strong>" . $lang_module['filequeue_empty'] . "</strong>";
  640. $contents .= "</div>\n";
  641. $contents .= "<meta http-equiv=\"refresh\" content=\"2;url=" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "\" />";
  642. include ( NV_ROOTDIR . "/includes/header.php" );
  643. echo nv_admin_theme( $contents );
  644. include ( NV_ROOTDIR . "/includes/footer.php" );
  645. exit;
  646. }
  647. $listcats = nv_listcats( 0 );
  648. if ( empty( $listcats ) )
  649. {
  650. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=cat&add=1" );
  651. exit();
  652. }
  653. $sql2 = "SELECT * " . $sql . " ORDER BY `uploadtime` DESC";
  654. $result2 = $db->sql_query( $sql2 );
  655. $array = array();
  656. while ( $row = $db->sql_fetchrow( $result2 ) )
  657. {
  658. $array[$row['id']] = array( //
  659. 'id' => ( int )$row['id'], //
  660. 'title' => $row['title'], //
  661. 'cattitle' => $listcats[$row['catid']]['title'], //
  662. 'catlink' => NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;catid=" . $row['catid'], //
  663. 'uploadtime' => nv_date( "d/m/Y H:i", $row['uploadtime'] ), //
  664. );
  665. }
  666. $xtpl = new XTemplate( "filequeue.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  667. $xtpl->assign( 'LANG', $lang_module );
  668. $xtpl->assign( 'GLANG', $lang_global );
  669. $xtpl->assign( 'TABLE_CAPTION', $page_title );
  670. if ( ! empty( $array ) )
  671. {
  672. $a = 0;
  673. foreach ( $array as $row )
  674. {
  675. $xtpl->assign( 'CLASS', $a % 2 == 1 ? " class=\"second\"" : "" );
  676. $xtpl->assign( 'ROW', $row );
  677. $xtpl->assign( 'EDIT_URL', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=filequeue&amp;edit=1&amp;id=" . $row['id'] );
  678. $xtpl->parse( 'main.row' );
  679. ++$a;
  680. }
  681. }
  682. $xtpl->parse( 'main' );
  683. $contents = $xtpl->text( 'main' );
  684. include ( NV_ROOTDIR . "/includes/header.php" );
  685. echo nv_admin_theme( $contents );
  686. include ( NV_ROOTDIR . "/includes/footer.php" );
  687. ?>