/Quản lý website trường trung học phổ thông PHP/lc1/modules/download/funcs/main.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien · PHP · 186 lines · 147 code · 31 blank · 8 comment · 15 complexity · 6fb30347f1a86d29b33429c201ca13a8 MD5 · raw file

  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 3-6-2010 0:30
  7. */
  8. if ( ! defined( 'NV_IS_MOD_DOWNLOAD' ) ) die( 'Stop!!!' );
  9. if ( empty( $list_cats ) )
  10. {
  11. $page_title = $module_info['custom_title'];
  12. include ( NV_ROOTDIR . "/includes/header.php" );
  13. echo nv_site_theme( '' );
  14. include ( NV_ROOTDIR . "/includes/footer.php" );
  15. exit();
  16. }
  17. $contents = "";
  18. $download_config = initial_config_data();
  19. $today = mktime( 0, 0, 0, date( "n" ), date( "j" ), date( "Y" ) );
  20. $yesterday = $today - 86400;
  21. //rating
  22. if ( $nv_Request->isset_request( 'rating', 'post' ) )
  23. {
  24. $in = implode( ",", array_keys( $list_cats ) );
  25. $rating = $nv_Request->get_string( 'rating', 'post', '' );
  26. unset( $m );
  27. if ( preg_match( "/^([0-9]+)\_([1-5]+)$/", $rating, $m ) )
  28. {
  29. $id = ( int )$m[1];
  30. $point = ( int )$m[2];
  31. if ( $id and ( $point > 0 and $point < 6 ) )
  32. {
  33. $query = "SELECT `rating_detail` FROM `" . NV_PREFIXLANG . "_" . $module_data . "` WHERE `id`=" . $id . " AND `catid` IN (" . $in . ") AND `status`=1";
  34. $result = $db->sql_query( $query );
  35. $numrows = $db->sql_numrows( $result );
  36. if ( $numrows )
  37. {
  38. $total = $click = 0;
  39. list( $rating_detail ) = $db->sql_fetchrow( $result );
  40. if ( ! empty( $rating_detail ) )
  41. {
  42. $rating_detail = explode( "|", $rating_detail );
  43. $total = ( int )$rating_detail[0];
  44. $click = ( int )$rating_detail[1];
  45. }
  46. $flrt = $nv_Request->get_string( 'flrt', 'session', '' );
  47. $flrt = ! empty( $flrt ) ? unserialize( $flrt ) : array();
  48. if ( $id and ! in_array( $id, $flrt ) )
  49. {
  50. $flrt[] = $id;
  51. $flrt = serialize( $flrt );
  52. $nv_Request->set_Session( 'flrt', $flrt );
  53. $total = $total + $point;
  54. $click ++;
  55. $rating_detail = $total . "|" . $click;
  56. $sql = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "` SET `rating_detail`=" . $db->dbescape( $rating_detail ) . " WHERE `id`=" . $id;
  57. $db->sql_query( $sql );
  58. }
  59. if ( $total and $click )
  60. {
  61. $round = round( $total / $click );
  62. $content = sprintf( $lang_module['rating_string'], $lang_module['file_rating' . $round], $total, $click );
  63. }
  64. else
  65. {
  66. $content = $lang_module['file_rating0'];
  67. }
  68. die( $content );
  69. }
  70. }
  71. }
  72. die( $lang_module['rating_error1'] );
  73. }
  74. $page_title = $mod_title = $module_info['custom_title'];
  75. $key_words = $module_info['keywords'];
  76. // View cat
  77. $new_page = 3;
  78. $array_cats = array();
  79. foreach ( $list_cats as $value )
  80. {
  81. if ( empty( $value['parentid'] ) )
  82. {
  83. $catid_i = $value['id'];
  84. if ( empty( $value['subcats'] ) )
  85. {
  86. $in = "`catid`=" . $catid_i;
  87. }
  88. else
  89. {
  90. $in = $value['subcats'];
  91. $in[] = $catid_i;
  92. $in = implode( ",", $in );
  93. $in = "`catid` IN (" . $in . ")";
  94. }
  95. $sql = "SELECT SQL_CALC_FOUND_ROWS `id`, `catid`, `title`, `alias`, `introtext` , `uploadtime`,
  96. `author_name`, `filesize`, `fileimage`, `view_hits`, `download_hits`, `comment_allow`, `comment_hits`
  97. FROM `" . NV_PREFIXLANG . "_" . $module_data . "` WHERE " . $in . " AND `status`=1
  98. ORDER BY `uploadtime` DESC LIMIT 0, " . $new_page;
  99. $result = $db->sql_query( $sql );
  100. $query = $db->sql_query( "SELECT FOUND_ROWS()" );
  101. list( $all_page ) = $db->sql_fetchrow( $query );
  102. if ( $all_page )
  103. {
  104. $array_item = array();
  105. while ( $row = $db->sql_fetchrow( $result ) )
  106. {
  107. $uploadtime = ( int )$row['uploadtime'];
  108. if ( $uploadtime >= $today )
  109. {
  110. $uploadtime = $lang_module['today'] . ", " . date( "H:i", $row['uploadtime'] );
  111. }
  112. elseif ( $uploadtime >= $yesterday )
  113. {
  114. $uploadtime = $lang_module['yesterday'] . ", " . date( "H:i", $row['uploadtime'] );
  115. }
  116. else
  117. {
  118. $uploadtime = nv_date( "d/m/Y H:i", $row['uploadtime'] );
  119. }
  120. $img = NV_UPLOADS_DIR . $row['fileimage'];
  121. $imageinfo = nv_ImageInfo( NV_ROOTDIR . '/' . $img, 300, true, NV_UPLOADS_REAL_DIR . '/' . $module_name . '/thumb' );
  122. $array_item[$row['id']] = array(
  123. 'id' => ( int )$row['id'], //
  124. 'title' => $row['title'], //
  125. 'introtext' => $row['introtext'], //
  126. 'uploadtime' => $uploadtime, //
  127. 'author_name' => ! empty( $row['author_name'] ) ? $row['author_name'] : $lang_module['unknown'], //
  128. 'filesize' => ! empty( $row['filesize'] ) ? nv_convertfromBytes( $row['filesize'] ) : "", //
  129. 'fileimage' => $imageinfo, //
  130. 'view_hits' => ( int )$row['view_hits'], //
  131. 'download_hits' => ( int )$row['download_hits'], //
  132. 'more_link' => NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $list_cats[$row['catid']]['alias'] . "/" . $row['alias'], //
  133. 'edit_link' => ( defined( 'NV_IS_MODADMIN' ) ) ? NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;edit=1&amp;id=" . ( int )$row['id'] : "", //
  134. 'del_link' => ( defined( 'NV_IS_MODADMIN' ) ) ? NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name : ""
  135. );
  136. if ( $row['comment_allow'] )
  137. {
  138. $array_item[$row['id']]['comment_hits'] = ( int )$row['comment_hits'];
  139. }
  140. }
  141. $array_cats[$catid_i] = array();
  142. $array_cats[$catid_i]['id'] = $value['id'];
  143. $array_cats[$catid_i]['title'] = $value['title'];
  144. $array_cats[$catid_i]['link'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $value['alias'];
  145. $array_cats[$catid_i]['description'] = $list_cats[$value['id']]['description'];
  146. $array_cats[$catid_i]['subcats'] = $list_cats[$value['id']]['subcats'];
  147. $array_cats[$catid_i]['items'] = $array_item;
  148. }
  149. }
  150. }
  151. $contents = theme_main_download( $array_cats, $list_cats, $download_config );
  152. include ( NV_ROOTDIR . "/includes/header.php" );
  153. echo nv_site_theme( $contents );
  154. include ( NV_ROOTDIR . "/includes/footer.php" );
  155. ?>