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

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

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 246 lines | 205 code | 27 blank | 14 comment | 31 complexity | ff8aa57f07313d53c35c632af1825600 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/14/2010 0:50
  7. */
  8. if ( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
  9. $id = $nv_Request->get_int( 'id', 'get', 0 );
  10. if ( empty( $id ) )
  11. {
  12. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  13. die();
  14. }
  15. $query = "SELECT * FROM `" . NV_BANNERS_ROWS_GLOBALTABLE . "` WHERE `id`=" . $id;
  16. $result = $db->sql_query( $query );
  17. $numrows = $db->sql_numrows( $result );
  18. if ( $numrows != 1 ) die( 'Stop!!!' );
  19. $row = $db->sql_fetchrow( $result );
  20. $file_name = $row['file_name'];
  21. $file_ext = $row['file_ext'];
  22. $file_mime = $row['file_mime'];
  23. $width = $row['width'];
  24. $height = $row['height'];
  25. $page_title = $lang_module['edit_banner'];
  26. $contents = array();
  27. $contents['upload_blocked'] = "";
  28. $contents['file_allowed_ext'] = array();
  29. if ( preg_match( "/images/", NV_ALLOW_FILES_TYPE ) )
  30. {
  31. $contents['file_allowed_ext'][] = "images";
  32. }
  33. if ( preg_match( "/flash/", NV_ALLOW_FILES_TYPE ) )
  34. {
  35. $contents['file_allowed_ext'][] = "flash";
  36. }
  37. if ( empty( $contents['file_allowed_ext'] ) )
  38. {
  39. $contents['upload_blocked'] = $lang_module['upload_blocked'];
  40. include ( NV_ROOTDIR . "/includes/header.php" );
  41. echo nv_admin_theme( nv_edit_banner_theme( $contents ) );
  42. include ( NV_ROOTDIR . "/includes/footer.php" );
  43. exit();
  44. }
  45. $query = "SELECT `id`,`login`,`full_name` FROM `" . NV_BANNERS_CLIENTS_GLOBALTABLE . "` ORDER BY `login` ASC";
  46. $result = $db->sql_query( $query );
  47. $clients = array();
  48. while ( $cl_row = $db->sql_fetchrow( $result ) )
  49. {
  50. $clients[$cl_row['id']] = $cl_row['full_name'] . " (" . $cl_row['login'] . ")";
  51. }
  52. $query = "SELECT `id`,`title`,`blang` FROM `" . NV_BANNERS_PLANS_GLOBALTABLE . "` ORDER BY `blang`, `title` ASC";
  53. $result = $db->sql_query( $query );
  54. $plans = array();
  55. while ( $pl_row = $db->sql_fetchrow( $result ) )
  56. {
  57. $plans[$pl_row['id']] = $pl_row['title'] . " (" . ( ! empty( $pl_row['blang'] ) ? $language_array[$pl_row['blang']]['name'] : $lang_module['blang_all'] ) . ")";
  58. }
  59. if ( empty( $plans ) )
  60. {
  61. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=add_plan" );
  62. die();
  63. }
  64. $error = "";
  65. if ( $nv_Request->get_int( 'save', 'post' ) == '1' )
  66. {
  67. $title = nv_htmlspecialchars( strip_tags( $nv_Request->get_string( 'title', 'post', '' ) ) );
  68. $pid = $nv_Request->get_int( 'pid', 'post', 0 );
  69. $clid = $nv_Request->get_int( 'clid', 'post', 0 );
  70. $file_alt = nv_htmlspecialchars( strip_tags( $nv_Request->get_string( 'file_alt', 'post', '' ) ) );
  71. $click_url = strip_tags( $nv_Request->get_string( 'click_url', 'post', '' ) );
  72. $publ_date = strip_tags( $nv_Request->get_string( 'publ_date', 'post', '' ) );
  73. $exp_date = strip_tags( $nv_Request->get_string( 'exp_date', 'post', '' ) );
  74. if ( ! empty( $publ_date ) and ! preg_match( "/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $publ_date ) ) $publ_date = "";
  75. if ( ! empty( $exp_date ) and ! preg_match( "/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $exp_date ) ) $exp_date = "";
  76. if ( ! empty( $clid ) and ! isset( $clients[$clid] ) ) $clid = 0;
  77. if ( $click_url == "http://" ) $click_url = "";
  78. if ( empty( $title ) )
  79. {
  80. $error = $lang_module['title_empty'];
  81. }
  82. elseif ( empty( $pid ) or ! isset( $plans[$pid] ) )
  83. {
  84. $error = $lang_module['plan_not_selected'];
  85. }
  86. elseif ( ! empty( $click_url ) and ! nv_is_url( $click_url ) )
  87. {
  88. $error = $lang_module['click_url_invalid'];
  89. }
  90. else
  91. {
  92. if ( isset( $_FILES['banner'] ) and is_uploaded_file( $_FILES['banner']['tmp_name'] ) )
  93. {
  94. @require_once ( NV_ROOTDIR . "/includes/class/upload.class.php" );
  95. $upload = new upload( $contents['file_allowed_ext'], $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, NV_MAX_WIDTH, NV_MAX_HEIGHT );
  96. $upload_info = $upload->save_file( $_FILES['banner'], NV_UPLOADS_REAL_DIR . '/' . NV_BANNER_DIR, false );
  97. @unlink( $_FILES['banner']['tmp_name'] );
  98. if ( ! empty( $upload_info['error'] ) )
  99. {
  100. $error = $upload_info['error'];
  101. }
  102. else
  103. {
  104. @chmod( $upload_info['name'], 0644 );
  105. if ( ! empty( $file_name ) and is_file( NV_ROOTDIR . '/' . $file_name ) )
  106. {
  107. @nv_deletefile( NV_ROOTDIR . '/' . $file_name );
  108. }
  109. $file_name = $upload_info['basename'];
  110. $file_ext = $upload_info['ext'];
  111. $file_mime = $upload_info['mime'];
  112. $width = $upload_info['img_info'][0];
  113. $height = $upload_info['img_info'][1];
  114. }
  115. }
  116. if ( empty( $error ) )
  117. {
  118. if ( empty( $publ_date ) )
  119. {
  120. $publtime = NV_CURRENTTIME;
  121. }
  122. else
  123. {
  124. unset( $m );
  125. preg_match( "/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $publ_date, $m );
  126. $publtime = mktime( 0, 0, 0, $m[2], $m[1], $m[3] );
  127. if ( $publtime < $row['add_time'] ) $publtime = $row['add_time'];
  128. }
  129. if ( empty( $exp_date ) )
  130. {
  131. $exptime = 0;
  132. }
  133. else
  134. {
  135. unset( $m );
  136. preg_match( "/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $exp_date, $m );
  137. $exptime = mktime( 23, 59, 59, $m[2], $m[1], $m[3] );
  138. }
  139. if ( $exptime != 0 and $exptime <= $publtime ) $exptime = $publtime;
  140. list( $pid_old ) = $db->sql_fetchrow( $db->sql_query( "SELECT `pid` FROM `" . NV_BANNERS_ROWS_GLOBALTABLE . "` WHERE `id`=" . intval( $id ) . "" ) );
  141. $sql = "UPDATE `" . NV_BANNERS_ROWS_GLOBALTABLE . "` SET `title`=" . $db->dbescape( $title ) . ", `pid`=" . $pid . ", `clid`=" . $clid . ",
  142. `file_name`=" . $db->dbescape( $file_name ) . ", `file_ext`=" . $db->dbescape( $file_ext ) . ", `file_mime`=" . $db->dbescape( $file_mime ) . ",
  143. `width`=" . $width . ", `height`=" . $height . ", `file_alt`=" . $db->dbescape( $file_alt ) . ", `click_url`=" . $db->dbescape( $click_url ) . ",
  144. `publ_time`=" . $publtime . ", `exp_time`=" . $exptime . " WHERE `id`=" . $id;
  145. $db->sql_query( $sql );
  146. if ( $pid_old != $pid )
  147. {
  148. nv_fix_banner_weight( $pid );
  149. nv_fix_banner_weight( $pid_old );
  150. }
  151. nv_insert_logs( NV_LANG_DATA, $module_name, 'log_edit_banner', "bannerid " . $id, $admin_info['userid'] );
  152. nv_CreateXML_bannerPlan();
  153. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=info_banner&id=" . $id );
  154. die();
  155. }
  156. }
  157. }
  158. else
  159. {
  160. $title = $row['title'];
  161. $pid = $row['pid'];
  162. $clid = $row['clid'];
  163. $file_alt = $row['file_alt'];
  164. $click_url = $row['click_url'];
  165. $publ_date = ! empty( $row['publ_time'] ) ? date( "d.m.Y", $row['publ_time'] ) : "";
  166. $exp_date = ! empty( $row['exp_time'] ) ? date( "d.m.Y", $row['exp_time'] ) : "";
  167. }
  168. if ( $click_url == "" ) $click_url = "http://";
  169. $contents['info'] = ( ! empty( $error ) ) ? $error : $lang_module['edit_banner_info'];
  170. $contents['is_error'] = ( ! empty( $error ) ) ? 1 : 0;
  171. $contents['file_allowed_ext'] = implode( ", ", $contents['file_allowed_ext'] );
  172. $contents['submit'] = $lang_module['edit_banner'];
  173. $contents['action'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=edit_banner&amp;id=" . $id;
  174. $contents['title'] = array(
  175. $lang_module['title'], 'title', $title, 255
  176. );
  177. $contents['plan'] = array(
  178. $lang_module['in_plan'], 'pid', $plans, $pid
  179. );
  180. $contents['client'] = array(
  181. $lang_module['of_client'], 'clid', $clients, $clid
  182. );
  183. //$contents['file_name'] = array( $lang_module['file_name'], NV_BASE_SITEURL . $file_name, "return hs.expand(this);", NV_BASE_SITEURL . "images/ico_" . $file_ext . ".gif", $lang_global['show_picture'] );
  184. $contents['file_name'] = array(
  185. $lang_module['file_name'], NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . NV_BANNER_DIR . "/" . $file_name, "rel=\"shadowbox;height=" . $height . ";width=" . $width . "\"", NV_BASE_SITEURL . "images/ico_" . $file_ext . ".gif", $lang_global['show_picture']
  186. );
  187. $contents['upload'] = array(
  188. sprintf( $lang_module['re_upload'], $contents['file_allowed_ext'] ), 'banner'
  189. );
  190. $contents['file_alt'] = array(
  191. $lang_module['file_alt'], 'file_alt', $file_alt, 255
  192. );
  193. $contents['click_url'] = array(
  194. $lang_module['click_url'], 'click_url', $click_url, 255
  195. );
  196. $contents['publ_date'] = array(
  197. $lang_module['publ_date'], 'publ_date', $publ_date, 10, NV_BASE_SITEURL . "images/calendar.jpg", 18, 17, "popCalendar.show(this, 'publ_date', 'dd.mm.yyyy', true);"
  198. );
  199. $contents['exp_date'] = array(
  200. $lang_module['exp_date'], 'exp_date', $exp_date, 10, NV_BASE_SITEURL . "images/calendar.jpg", 18, 17, "popCalendar.show(this, 'exp_date', 'dd.mm.yyyy', true);"
  201. );
  202. $my_head = "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/popcalendar/popcalendar.js\"></script>\n";
  203. //$my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/highslide/highslide.js\"></script>\n";
  204. //$my_head .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . NV_BASE_SITEURL . "js/highslide/highslide.css\" />\n";
  205. //$my_head .= "<script type=\"text/javascript\">\n";
  206. //$my_head .= " hs.wrapperClassName = 'wide-border';\n";
  207. //$my_head .= "</script>\n";
  208. $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/shadowbox/shadowbox.js\"></script>\n";
  209. $my_head .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . NV_BASE_SITEURL . "js/shadowbox/shadowbox.css\" />\n";
  210. $my_head .= "<script type=\"text/javascript\">\n";
  211. $my_head .= "Shadowbox.init({\n";
  212. //$my_head .= "handleOversize: \"drag\",\n";
  213. //$my_head .= "modal: true\n";
  214. $my_head .= "});\n";
  215. $my_head .= "</script>\n";
  216. include ( NV_ROOTDIR . "/includes/header.php" );
  217. echo nv_admin_theme( nv_edit_banner_theme( $contents ) );
  218. include ( NV_ROOTDIR . "/includes/footer.php" );
  219. ?>