PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/download/admin/filequeue.php

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