PageRenderTime 25ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 156 lines | 137 code | 13 blank | 6 comment | 20 complexity | f52944e70df5d410dfb282287fc87f66 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/25/2010 21:7
  7. */
  8. if ( ! defined( 'NV_IS_MOD_BANNERS' ) ) die( 'Stop!!!' );
  9. $page_title = $module_info['custom_title'];
  10. global $global_config, $module_name, $module_info, $lang_module;
  11. $my_head = "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/popcalendar/popcalendar.js\"></script>";
  12. if ( defined( 'NV_IS_BANNER_CLIENT' ) )
  13. {
  14. $upload_blocked = "";
  15. $file_allowed_ext = array();
  16. if ( preg_match( "/images/", $banner_client_info['uploadtype'] ) )
  17. {
  18. $file_allowed_ext[] = "images";
  19. }
  20. if ( preg_match( "/flash/", $banner_client_info['uploadtype'] ) )
  21. {
  22. $file_allowed_ext[] = "flash";
  23. }
  24. if ( empty( $file_allowed_ext ) )
  25. {
  26. $upload_blocked = $lang_module['upload_blocked'];
  27. include ( NV_ROOTDIR . "/includes/header.php" );
  28. echo nv_site_theme( $upload_blocked );
  29. include ( NV_ROOTDIR . "/includes/footer.php" );
  30. exit();
  31. }
  32. $xtpl = new XTemplate( "addads.tpl", NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file );
  33. $xtpl->assign( 'LANG', $lang_module );
  34. $xtpl->assign( 'NV_BASE_URLSITE', NV_BASE_SITEURL );
  35. $xtpl->assign( 'clientinfo_link', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=clientinfo" );
  36. $xtpl->assign( 'clientinfo_addads', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=addads" );
  37. $xtpl->assign( 'clientinfo_stats', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=stats" );
  38. $xtpl->parse( 'main.management' );
  39. if ( $nv_Request->isset_request( 'confirm', 'post' ) )
  40. {
  41. $error = array();
  42. $title = filter_text_input( 'title', 'post', '', 1 );
  43. $blockid = filter_text_input( 'block', 'post', '', 1 );
  44. $description = filter_text_input( 'description', 'post', '', 1 );
  45. $url = filter_text_input( 'url', 'post', '', 0 );
  46. $begintime = filter_text_input( 'begintime', 'post', '', 1 );
  47. $endtime = filter_text_input( 'endtime', 'post', '', 1 );
  48. if ( ! empty( $begintime ) and ! preg_match( "/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $begintime ) ) $begintime = "";
  49. if ( ! empty( $endtime ) and ! preg_match( "/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $endtime ) ) $endtime = "";
  50. if ( $url == "http://" ) $url = "";
  51. if ( empty( $title ) )
  52. {
  53. $error[] = $lang_module['title_empty'];
  54. }
  55. elseif ( empty( $blockid ) )
  56. {
  57. $error[] = $lang_module['plan_not_selected'];
  58. }
  59. elseif ( ! empty( $url ) and ! nv_is_url( $url ) )
  60. {
  61. $error[] = $lang_module['click_url_invalid'];
  62. }
  63. elseif ( ! isset( $_FILES["image"] ) )
  64. {
  65. $error[] = $lang_module['file_upload_empty'];
  66. }
  67. else
  68. {
  69. @require_once ( NV_ROOTDIR . "/includes/class/upload.class.php" );
  70. $upload = new upload( $file_allowed_ext, $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, NV_MAX_WIDTH, NV_MAX_HEIGHT );
  71. $upload_info = $upload->save_file( $_FILES['image'], NV_UPLOADS_REAL_DIR . '/' . NV_BANNER_DIR, false );
  72. @unlink( $_FILES['image']['tmp_name'] );
  73. if ( ! empty( $upload_info['error'] ) )
  74. {
  75. $error[] = $upload_info['error'];
  76. }
  77. }
  78. if ( ! empty( $error ) )
  79. {
  80. $xtpl->assign( 'errorinfo', implode( '<br/>', $error ) );
  81. }
  82. else
  83. {
  84. $file_name = $upload_info['basename'];
  85. $file_ext = $upload_info['ext'];
  86. $file_mime = $upload_info['mime'];
  87. $width = $upload_info['img_info'][0];
  88. $height = $upload_info['img_info'][1];
  89. if ( empty( $begintime ) )
  90. {
  91. $begintime = NV_CURRENTTIME;
  92. }
  93. else
  94. {
  95. unset( $m );
  96. preg_match( "/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $begintime, $m );
  97. $begintime = mktime( 0, 0, 0, $m[2], $m[1], $m[3] );
  98. if ( $begintime < NV_CURRENTTIME ) $begintime = NV_CURRENTTIME;
  99. }
  100. if ( empty( $endtime ) )
  101. {
  102. $endtime = 0;
  103. }
  104. else
  105. {
  106. unset( $m );
  107. preg_match( "/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $endtime, $m );
  108. $endtime = mktime( 23, 59, 59, $m[2], $m[1], $m[3] );
  109. }
  110. if ( $endtime != 0 and $endtime <= $begintime ) $endtime = $begintime;
  111. $sql = "INSERT INTO `" . NV_BANNERS_ROWS_GLOBALTABLE . "` (`id`, `title`, `pid`, `clid`, `file_name`, `file_ext`, `file_mime`, `width`, `height`, `file_alt`, `click_url`, `file_name_tmp`, `file_alt_tmp`, `click_url_tmp`, `add_time`, `publ_time`, `exp_time`, `hits_total`, `act`, `weight`) VALUES
  112. (NULL, " . $db->dbescape( $title ) . ", " . $blockid . ", " . $banner_client_info['id'] . ", " . $db->dbescape( $file_name ) . ", " . $db->dbescape( $file_ext ) . ", " . $db->dbescape( $file_mime ) . ",
  113. " . $width . ", " . $height . ", " . $db->dbescape( $description ) . ", " . $db->dbescape( $url ) . ", '', '', '', " . NV_CURRENTTIME . ", " . $begintime . ", " . $endtime . ",
  114. 0, 3,0)";
  115. $id = $db->sql_query_insert_id( $sql );
  116. if ( $id )
  117. {
  118. $xtpl->assign( 'pagetitle', $lang_module['addads_success'] . '<meta http-equiv="refresh" content="2;url=' . nv_url_rewrite( NV_BASE_SITEURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name, true ) . '">' );
  119. }
  120. }
  121. }
  122. else
  123. {
  124. $xtpl->assign( 'pagetitle', $lang_module['addads_pagetitle'] );
  125. }
  126. $result = $db->sql_query( "SELECT `id`,`title`, `blang` FROM `" . NV_BANNERS_PLANS_GLOBALTABLE . "` ORDER BY `blang`, `title` ASC" );
  127. while ( $row = $db->sql_fetchrow( $result ) )
  128. {
  129. $row['title'] .= ' (' . ( empty( $row['blang'] ) ? $lang_module['addads_block_lang_all'] : $lang_array[$row['blang']] ) . ')';
  130. $xtpl->assign( 'blockitem', $row );
  131. $xtpl->parse( 'main.blockitem' );
  132. }
  133. $xtpl->parse( 'main' );
  134. $contents .= $xtpl->text( 'main' );
  135. }
  136. else
  137. {
  138. $contents .= $lang_module['addads_require_login'];
  139. }
  140. include ( NV_ROOTDIR . "/includes/header.php" );
  141. echo nv_site_theme( $contents );
  142. include ( NV_ROOTDIR . "/includes/footer.php" );
  143. ?>