PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/NukeViet3.2/modules/download/admin/main.php

http://nuke-viet.googlecode.com/
PHP | 630 lines | 511 code | 85 blank | 34 comment | 65 complexity | 656d4e9a9d1eb0d9e2d3dbfec490a89a 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 file
  10. if ( $nv_Request->isset_request( 'edit', 'get' ) )
  11. {
  12. $report = $nv_Request->isset_request( 'report', 'get' );
  13. $id = $nv_Request->get_int( 'id', 'get', 0 );
  14. if ( $id )
  15. {
  16. $query = "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "` WHERE `id`=" . $id;
  17. $result = $db->sql_query( $query );
  18. $numrows = $db->sql_numrows( $result );
  19. if ( $numrows != 1 )
  20. {
  21. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  22. exit();
  23. }
  24. define( 'IS_EDIT', true );
  25. $page_title = $lang_module['download_editfile'];
  26. $row = $db->sql_fetchrow( $result );
  27. }
  28. else
  29. {
  30. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  31. exit();
  32. }
  33. $groups_list = nv_groups_list();
  34. $array_who = array( $lang_global['who_view0'], $lang_global['who_view1'], $lang_global['who_view2'] );
  35. if ( ! empty( $groups_list ) )
  36. {
  37. $array_who[] = $lang_global['who_view3'];
  38. }
  39. $array = array();
  40. $is_error = false;
  41. $error = "";
  42. if ( $nv_Request->isset_request( 'submit', 'post' ) )
  43. {
  44. $array['catid'] = $nv_Request->get_int( 'catid', 'post', 0 );
  45. $array['title'] = filter_text_input( 'title', 'post', '', 1 );
  46. $array['description'] = nv_editor_filter_textarea( 'description', '', NV_ALLOWED_HTML_TAGS );
  47. $array['introtext'] = filter_text_textarea( 'introtext', '', NV_ALLOWED_HTML_TAGS );
  48. $array['author_name'] = filter_text_input( 'author_name', 'post', '', 1 );
  49. $array['author_email'] = filter_text_input( 'author_email', 'post', '' );
  50. $array['author_url'] = filter_text_input( 'author_url', 'post', '' );
  51. $array['fileupload'] = $nv_Request->get_typed_array( 'fileupload', 'post', 'string' );
  52. $array['linkdirect'] = $nv_Request->get_typed_array( 'linkdirect', 'post', 'string' );
  53. $array['version'] = filter_text_input( 'version', 'post', '', 1 );
  54. $array['fileimage'] = filter_text_input( 'fileimage', 'post', '' );
  55. $array['copyright'] = filter_text_input( 'copyright', 'post', '', 1 );
  56. $array['comment_allow'] = $nv_Request->get_int( 'comment_allow', 'post', 0 );
  57. $array['who_comment'] = $nv_Request->get_int( 'who_comment', 'post', 0 );
  58. $array['groups_comment'] = $nv_Request->get_typed_array( 'groups_comment', 'post', 'int' );
  59. $array['is_del_report'] = $nv_Request->get_int( 'is_del_report', 'post', 0 );
  60. if ( ! empty( $array['author_url'] ) )
  61. {
  62. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['author_url'] ) )
  63. {
  64. $array['author_url'] = "http://" . $array['author_url'];
  65. }
  66. }
  67. $array['filesize'] = 0;
  68. if ( ! empty( $array['fileupload'] ) )
  69. {
  70. $fileupload = $array['fileupload'];
  71. $array['fileupload'] = array();
  72. foreach ( $fileupload as $file )
  73. {
  74. if ( ! empty( $file ) )
  75. {
  76. $file2 = substr( $file, strlen( NV_BASE_SITEURL ) );
  77. if ( file_exists( NV_ROOTDIR . '/' . $file2 ) and ( $filesize = filesize( NV_ROOTDIR . '/' . $file2 ) ) != 0 )
  78. {
  79. $array['fileupload'][] = substr ( $file, strlen ( NV_BASE_SITEURL . NV_UPLOADS_DIR ) );
  80. $array['filesize'] += $filesize;
  81. }
  82. }
  83. }
  84. }
  85. else
  86. {
  87. $array['fileupload'] = array();
  88. }
  89. // Sort image
  90. if ( ! empty ( $array['fileimage'] ) )
  91. {
  92. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['fileimage'] ) )
  93. {
  94. $array['fileimage'] = substr ( $array['fileimage'], strlen ( NV_BASE_SITEURL . NV_UPLOADS_DIR ) );
  95. }
  96. }
  97. if ( ! empty( $array['linkdirect'] ) )
  98. {
  99. $linkdirect = $array['linkdirect'];
  100. $array['linkdirect'] = array();
  101. foreach ( $linkdirect as $links )
  102. {
  103. $linkdirect2 = array();
  104. if ( ! empty( $links ) )
  105. {
  106. $links = nv_nl2br( $links, "<br />" );
  107. $links = explode( "<br />", $links );
  108. $links = array_map( "trim", $links );
  109. $links = array_unique( $links );
  110. foreach ( $links as $link )
  111. {
  112. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $link ) )
  113. {
  114. $link = "http://" . $link;
  115. }
  116. if ( nv_is_url( $link ) )
  117. {
  118. $linkdirect2[] = $link;
  119. }
  120. }
  121. }
  122. if ( ! empty( $linkdirect2 ) )
  123. {
  124. $array['linkdirect'][] = implode( "\n", $linkdirect2 );
  125. }
  126. }
  127. }
  128. else
  129. {
  130. $array['linkdirect'] = array();
  131. }
  132. if ( ! empty( $array['linkdirect'] ) )
  133. {
  134. $array['linkdirect'] = array_unique( $array['linkdirect'] );
  135. }
  136. if ( ! empty( $array['linkdirect'] ) and empty( $array['fileupload'] ) )
  137. {
  138. $array['filesize'] = $nv_Request->get_int( 'filesize', 'post', 0 );
  139. }
  140. $alias = change_alias( $array['title'] );
  141. $sql = "SELECT COUNT(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "` WHERE `id`!=" . $id . " AND `alias`=" . $db->dbescape( $alias );
  142. $result = $db->sql_query( $sql );
  143. list( $is_exists ) = $db->sql_fetchrow( $result );
  144. if ( ! $is_exists )
  145. {
  146. $sql = "SELECT COUNT(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_tmp` WHERE `title`=" . $db->dbescape( $array['title'] );
  147. $result = $db->sql_query( $sql );
  148. list( $is_exists ) = $db->sql_fetchrow( $result );
  149. }
  150. if ( empty( $array['title'] ) )
  151. {
  152. $is_error = true;
  153. $error = $lang_module['file_error_title'];
  154. }
  155. elseif ( $is_exists )
  156. {
  157. $is_error = true;
  158. $error = $lang_module['file_title_exists'];
  159. }
  160. elseif ( ! empty( $array['author_email'] ) and ( $check_valid_email = nv_check_valid_email( $array['author_email'] ) ) != "" )
  161. {
  162. $is_error = true;
  163. $error = $check_valid_email;
  164. }
  165. elseif ( ! empty( $array['author_url'] ) and ! nv_is_url( $array['author_url'] ) )
  166. {
  167. $is_error = true;
  168. $error = $lang_module['file_error_author_url'];
  169. }
  170. elseif ( empty( $array['fileupload'] ) and empty( $array['linkdirect'] ) )
  171. {
  172. $is_error = true;
  173. $error = $lang_module['file_error_fileupload'];
  174. }
  175. else
  176. {
  177. $array['introtext'] = ! empty( $array['introtext'] ) ? nv_nl2br( $array['introtext'], "<br />" ) : "";
  178. $array['description'] = ! empty( $array['description'] ) ? nv_editor_nl2br( $array['description'] ) : $array['introtext'];
  179. $array['fileupload'] = ( ! empty( $array['fileupload'] ) ) ? implode( "[NV]", $array['fileupload'] ) : "";
  180. if ( ( ! empty( $array['linkdirect'] ) ) )
  181. {
  182. $array['linkdirect'] = array_map( "nv_nl2br", $array['linkdirect'] );
  183. $array['linkdirect'] = implode( "[NV]", $array['linkdirect'] );
  184. }
  185. else
  186. {
  187. $array['linkdirect'] = "";
  188. }
  189. if ( ! in_array( $array['who_comment'], array_keys( $array_who ) ) )
  190. {
  191. $array['who_comment'] = 0;
  192. }
  193. $array['groups_comment'] = ( ! empty( $array['groups_comment'] ) ) ? implode( ',', $array['groups_comment'] ) : '';
  194. $sql = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "` SET
  195. `catid`=" . $array['catid'] . ",
  196. `title`=" . $db->dbescape( $array['title'] ) . ",
  197. `alias`=" . $db->dbescape( $alias ) . ",
  198. `description`=" . $db->dbescape( $array['description'] ) . ",
  199. `introtext`=" . $db->dbescape( $array['introtext'] ) . ",
  200. `updatetime`=" . NV_CURRENTTIME . ",
  201. `author_name`=" . $db->dbescape( $array['author_name'] ) . ",
  202. `author_email`=" . $db->dbescape( $array['author_email'] ) . ",
  203. `author_url`=" . $db->dbescape( $array['author_url'] ) . ",
  204. `fileupload`=" . $db->dbescape( $array['fileupload'] ) . ",
  205. `linkdirect`=" . $db->dbescape( $array['linkdirect'] ) . ",
  206. `version`=" . $db->dbescape( $array['version'] ) . ",
  207. `filesize`=" . $array['filesize'] . ",
  208. `fileimage`=" . $db->dbescape( $array['fileimage'] ) . ",
  209. `copyright`=" . $db->dbescape( $array['copyright'] ) . ",
  210. `comment_allow`=" . $array['comment_allow'] . ",
  211. `who_comment`=" . $array['who_comment'] . ",
  212. `groups_comment`=" . $db->dbescape( $array['groups_comment'] ) . "
  213. WHERE `id`=" . $id;
  214. $result = $db->sql_query( $sql );
  215. if ( ! $result )
  216. {
  217. $is_error = true;
  218. $error = $lang_module['file_error1'];
  219. }
  220. else
  221. {
  222. if ( $report and $array['is_del_report'] )
  223. {
  224. $sql = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_report` WHERE `fid`=" . $id;
  225. $db->sql_query( $sql );
  226. }
  227. nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['download_editfile'], $array['title'], $admin_info['userid'] );
  228. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  229. exit();
  230. }
  231. }
  232. $array['fileupload'] = ( ! empty( $array['fileupload'] ) ) ? explode( "[NV]", $array['fileupload'] ) : array();
  233. }
  234. else
  235. {
  236. $array['catid'] = ( int )$row['catid'];
  237. $array['title'] = $row['title'];
  238. $array['description'] = nv_editor_br2nl( $row['description'] );
  239. $array['introtext'] = nv_br2nl( $row['introtext'] );
  240. $array['author_name'] = $row['author_name'];
  241. $array['author_email'] = $row['author_email'];
  242. $array['author_url'] = $row['author_url'];
  243. $array['fileupload'] = $row['fileupload'];
  244. $array['linkdirect'] = $row['linkdirect'];
  245. $array['version'] = $row['version'];
  246. $array['filesize'] = ( int )$row['filesize'];
  247. $array['fileimage'] = $row['fileimage'];
  248. $array['copyright'] = $row['copyright'];
  249. $array['comment_allow'] = ( int )$row['comment_allow'];
  250. $array['who_comment'] = ( int )$row['who_comment'];
  251. $array['groups_comment'] = $row['groups_comment'];
  252. $array['fileupload'] = ! empty( $array['fileupload'] ) ? explode( "[NV]", $array['fileupload'] ) : array();
  253. if ( ! empty( $array['linkdirect'] ) )
  254. {
  255. $array['linkdirect'] = explode( "[NV]", $array['linkdirect'] );
  256. $array['linkdirect'] = array_map( "nv_br2nl", $array['linkdirect'] );
  257. }
  258. else
  259. {
  260. $array['linkdirect'] = array();
  261. }
  262. $array['groups_comment'] = ! empty( $array['groups_comment'] ) ? explode( ",", $array['groups_comment'] ) : array();
  263. $array['is_del_report'] = 1;
  264. }
  265. if ( ! empty( $array['description'] ) ) $array['description'] = nv_htmlspecialchars( $array['description'] );
  266. if ( ! empty( $array['introtext'] ) ) $array['introtext'] = nv_htmlspecialchars( $array['introtext'] );
  267. $array['fileupload_num'] = count( $array['fileupload'] );
  268. $array['linkdirect_num'] = count( $array['linkdirect'] );
  269. // Build fileimage
  270. if ( ! empty ( $array['fileimage'] ) )
  271. {
  272. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['fileimage'] ) )
  273. {
  274. $array['fileimage'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . $array['fileimage'];
  275. }
  276. }
  277. //Rebuild fileupload
  278. if( ! empty( $array['fileupload'] ) )
  279. {
  280. $fileupload = $array['fileupload'];
  281. $array['fileupload'] = array();
  282. foreach( $fileupload as $tmp )
  283. {
  284. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $tmp ) )
  285. {
  286. $tmp = NV_BASE_SITEURL . NV_UPLOADS_DIR . $tmp;
  287. }
  288. $array['fileupload'][] = $tmp;
  289. }
  290. }
  291. if ( ! count( $array['fileupload'] ) ) array_push( $array['fileupload'], "" );
  292. if ( ! count( $array['linkdirect'] ) ) array_push( $array['linkdirect'], "" );
  293. $listcats = nv_listcats( $array['catid'] );
  294. if ( empty( $listcats ) )
  295. {
  296. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=cat&add=1" );
  297. exit();
  298. }
  299. $array['comment_allow'] = $array['comment_allow'] ? " checked=\"checked\"" : "";
  300. $array['is_del_report'] = $array['is_del_report'] ? " checked=\"checked\"" : "";
  301. $who_comment = $array['who_comment'];
  302. $array['who_comment'] = array();
  303. foreach ( $array_who as $key => $who )
  304. {
  305. $array['who_comment'][] = array( //
  306. 'key' => $key, //
  307. 'title' => $who, //
  308. 'selected' => $key == $who_comment ? " selected=\"selected\"" : "" //
  309. );
  310. }
  311. $groups_comment = $array['groups_comment'];
  312. $array['groups_comment'] = array();
  313. if ( ! empty( $groups_list ) )
  314. {
  315. foreach ( $groups_list as $key => $title )
  316. {
  317. $array['groups_comment'][] = array( //
  318. 'key' => $key, //
  319. 'title' => $title, //
  320. 'checked' => in_array( $key, $groups_comment ) ? " checked=\"checked\"" : "" //
  321. );
  322. }
  323. }
  324. if ( defined( 'NV_EDITOR' ) )
  325. {
  326. require_once ( NV_ROOTDIR . '/' . NV_EDITORSDIR . '/' . NV_EDITOR . '/nv.php' );
  327. }
  328. if ( defined( 'NV_EDITOR' ) and nv_function_exists( 'nv_aleditor' ) )
  329. {
  330. $array['description'] = nv_aleditor( 'description', '100%', '300px', $array['description'] );
  331. }
  332. else
  333. {
  334. $array['description'] = "<textarea style=\"width:100%; height:300px\" name=\"description\" id=\"description\">" . $array['description'] . "</textarea>";
  335. }
  336. $sql = "SELECT `config_value` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_config` WHERE `config_name`='upload_dir'";
  337. $result = $db->sql_query( $sql );
  338. list( $upload_dir ) = $db->sql_fetchrow( $result );
  339. if ( ! $array['filesize'] ) $array['filesize'] = "";
  340. $xtpl = new XTemplate( "content.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  341. $report = $report ? "&amp;report=1" : "";
  342. $xtpl->assign( 'FORM_ACTION', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;edit=1&amp;id=" . $id . $report );
  343. $xtpl->assign( 'LANG', $lang_module );
  344. $xtpl->assign( 'DATA', $array );
  345. $xtpl->assign( 'NV_BASE_ADMINURL', NV_BASE_ADMINURL );
  346. $xtpl->assign( 'NV_NAME_VARIABLE', NV_NAME_VARIABLE );
  347. $xtpl->assign( 'IMG_DIR', NV_UPLOADS_DIR . '/' . $module_name . '/images' );
  348. $xtpl->assign( 'FILES_DIR', NV_UPLOADS_DIR . '/' . $module_name . '/' . $upload_dir );
  349. if ( ! empty( $error ) )
  350. {
  351. $xtpl->assign( 'ERROR', $error );
  352. $xtpl->parse( 'main.error' );
  353. }
  354. foreach ( $listcats as $cat )
  355. {
  356. $xtpl->assign( 'LISTCATS', $cat );
  357. $xtpl->parse( 'main.catid' );
  358. }
  359. $a = 0;
  360. foreach ( $array['fileupload'] as $file )
  361. {
  362. $xtpl->assign( 'FILEUPLOAD', array(
  363. 'value' => $file, 'key' => $a
  364. ) );
  365. $xtpl->parse( 'main.fileupload' );
  366. $a ++;
  367. }
  368. $a = 0;
  369. foreach ( $array['linkdirect'] as $link )
  370. {
  371. $xtpl->assign( 'LINKDIRECT', array(
  372. 'value' => $link, 'key' => $a
  373. ) );
  374. $xtpl->parse( 'main.linkdirect' );
  375. $a ++;
  376. }
  377. foreach ( $array['who_comment'] as $who )
  378. {
  379. $xtpl->assign( 'WHO_COMMENT', $who );
  380. $xtpl->parse( 'main.who_comment' );
  381. }
  382. if ( ! empty( $array['groups_comment'] ) )
  383. {
  384. foreach ( $array['groups_comment'] as $group )
  385. {
  386. $xtpl->assign( 'GROUPS_COMMENT', $group );
  387. $xtpl->parse( 'main.group_empty.groups_comment' );
  388. }
  389. $xtpl->parse( 'main.group_empty' );
  390. }
  391. $xtpl->parse( 'main.is_del_report' );
  392. $xtpl->parse( 'main' );
  393. $contents = $xtpl->text( 'main' );
  394. include ( NV_ROOTDIR . "/includes/header.php" );
  395. echo nv_admin_theme( $contents );
  396. include ( NV_ROOTDIR . "/includes/footer.php" );
  397. exit();
  398. }
  399. // Avtive - Deactive
  400. if ( $nv_Request->isset_request( 'changestatus', 'post' ) )
  401. {
  402. if ( ! defined( 'NV_IS_AJAX' ) ) die( 'Wrong URL' );
  403. $id = $nv_Request->get_int( 'id', 'post', 0 );
  404. if ( empty( $id ) ) die( "NO" );
  405. $query = "SELECT `status` FROM `" . NV_PREFIXLANG . "_" . $module_data . "` WHERE `id`=" . $id;
  406. $result = $db->sql_query( $query );
  407. $numrows = $db->sql_numrows( $result );
  408. if ( $numrows != 1 ) die( 'NO' );
  409. list( $status ) = $db->sql_fetchrow( $result );
  410. $status = $status ? 0 : 1;
  411. $sql = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "` SET `status`=" . $status . " WHERE `id`=" . $id;
  412. $db->sql_query( $sql );
  413. die( "OK" );
  414. }
  415. // Delete file
  416. if ( $nv_Request->isset_request( 'del', 'post' ) )
  417. {
  418. if ( ! defined( 'NV_IS_AJAX' ) ) die( 'Wrong URL' );
  419. $id = $nv_Request->get_int( 'id', 'post', 0 );
  420. if ( ! $id ) die( "NO" );
  421. $query = "SELECT `fileupload`, `fileimage`,`title` FROM `" . NV_PREFIXLANG . "_" . $module_data . "` WHERE `id`=" . $id;
  422. $result = $db->sql_query( $query );
  423. $numrows = $db->sql_numrows( $result );
  424. if ( $numrows != 1 ) die( "NO" );
  425. $row = $db->sql_fetchrow( $result );
  426. //Khong xao file vi co the co truong hop file dung chung
  427. /*
  428. if(!empty($fileupload))
  429. {
  430. $fileupload = explode("[NV]",$fileupload);
  431. foreach($fileupload as $file)
  432. {
  433. $file = substr($file,strlen(NV_BASE_SITEURL));
  434. if ( ! empty( $file ) and file_exists( NV_ROOTDIR . '/' . $file ) )
  435. {
  436. @nv_deletefile( NV_ROOTDIR . '/' . $file );
  437. }
  438. }
  439. }
  440. $fileimage = substr($array['fileimage'],strlen(NV_BASE_SITEURL));
  441. if ( ! empty( $fileimage ) and file_exists( NV_ROOTDIR . '/' . $fileimage ) )
  442. {
  443. @nv_deletefile( NV_ROOTDIR . '/' . $fileimage );
  444. }*/
  445. $sql = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_comments` WHERE `fid`=" . $id;
  446. $db->sql_query( $sql );
  447. $sql = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_report` WHERE `fid`=" . $id;
  448. $db->sql_query( $sql );
  449. $sql = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "` WHERE `id`=" . $id;
  450. $db->sql_query( $sql );
  451. nv_insert_logs( NV_LANG_DATA, $module_data, $lang_module['download_filequeue_del'] ,$row['title'], $admin_info['userid'] );
  452. die( "OK" );
  453. }
  454. // List file
  455. $sql = "FROM `" . NV_PREFIXLANG . "_" . $module_data . "`";
  456. $base_url = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name;
  457. $listcats = nv_listcats( 0 );
  458. if ( empty( $listcats ) )
  459. {
  460. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=cat&add=1" );
  461. exit();
  462. }
  463. if ( $nv_Request->isset_request( "catid", "get" ) )
  464. {
  465. $catid = $nv_Request->get_int( 'catid', 'get', 0 );
  466. if ( ! $catid or ! isset( $listcats[$catid] ) )
  467. {
  468. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  469. exit();
  470. }
  471. $page_title = sprintf( $lang_module['file_list_by_cat'], $listcats[$catid]['title'] );
  472. $sql .= " WHERE `catid`=" . $catid;
  473. $base_url .= "&amp;catid=" . $catid;
  474. }
  475. else
  476. {
  477. $page_title = $lang_module['download_filemanager'];
  478. }
  479. $sql1 = "SELECT COUNT(*) " . $sql;
  480. $result1 = $db->sql_query( $sql1 );
  481. list( $all_page ) = $db->sql_fetchrow( $result1 );
  482. if ( ! $all_page )
  483. {
  484. if ( $catid )
  485. {
  486. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  487. exit();
  488. }
  489. else
  490. {
  491. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=add" );
  492. exit();
  493. }
  494. }
  495. $sql .= " ORDER BY `uploadtime` DESC";
  496. $page = $nv_Request->get_int( 'page', 'get', 0 );
  497. $per_page = 30;
  498. $sql2 = "SELECT * " . $sql . " LIMIT " . $page . ", " . $per_page;
  499. $query2 = $db->sql_query( $sql2 );
  500. $array = array();
  501. while ( $row = $db->sql_fetchrow( $query2 ) )
  502. {
  503. $array[$row['id']] = array(
  504. 'id' => ( int )$row['id'], //
  505. 'title' => $row['title'], //
  506. 'cattitle' => $listcats[$row['catid']]['title'], //
  507. 'catlink' => NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;catid=" . $row['catid'], //
  508. 'uploadtime' => nv_date( "d/m/Y H:i", $row['uploadtime'] ), //
  509. 'status' => $row['status'] ? " checked=\"checked\"" : "", //
  510. 'view_hits' => ( int )$row['view_hits'], //
  511. 'download_hits' => ( int )$row['download_hits'], //
  512. 'comment_hits' => ( int )$row['comment_hits'] //
  513. );
  514. }
  515. $generate_page = nv_generate_page( $base_url, $all_page, $per_page, $page );
  516. $xtpl = new XTemplate( "main.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  517. $xtpl->assign( 'LANG', $lang_module );
  518. $xtpl->assign( 'GLANG', $lang_global );
  519. $xtpl->assign( 'TABLE_CAPTION', $page_title );
  520. $xtpl->assign( 'ADD_NEW_FILE', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=add" );
  521. if ( ! empty( $array ) )
  522. {
  523. $a = 0;
  524. foreach ( $array as $row )
  525. {
  526. $xtpl->assign( 'CLASS', $a % 2 == 1 ? " class=\"second\"" : "" );
  527. $xtpl->assign( 'ROW', $row );
  528. $xtpl->assign( 'EDIT_URL', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;edit=1&amp;id=" . $row['id'] );
  529. $xtpl->parse( 'main.row' );
  530. $a ++;
  531. }
  532. }
  533. if ( ! empty( $generate_page ) )
  534. {
  535. $xtpl->assign( 'GENERATE_PAGE', $generate_page );
  536. $xtpl->parse( 'main.generate_page' );
  537. }
  538. $xtpl->parse( 'main' );
  539. $contents = $xtpl->text( 'main' );
  540. include ( NV_ROOTDIR . "/includes/header.php" );
  541. echo nv_admin_theme( $contents );
  542. include ( NV_ROOTDIR . "/includes/footer.php" );
  543. ?>