PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/01.Source/01.CORE/modules/banners/admin/edit_banner.php

http://creative-portal.googlecode.com/
PHP | 220 lines | 179 code | 27 blank | 14 comment | 29 complexity | 08d8b3db1bd03e77fe9ecdec6e680aac 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 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. } elseif ( empty( $pid ) or ! isset( $plans[$pid] ) )
  82. {
  83. $error = $lang_module['plan_not_selected'];
  84. } elseif ( ! empty( $click_url ) and ! nv_is_url( $click_url ) )
  85. {
  86. $error = $lang_module['click_url_invalid'];
  87. }
  88. else
  89. {
  90. if ( isset( $_FILES['banner'] ) and is_uploaded_file( $_FILES['banner']['tmp_name'] ) )
  91. {
  92. @require_once ( NV_ROOTDIR . "/includes/class/upload.class.php" );
  93. $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 );
  94. $upload_info = $upload->save_file( $_FILES['banner'], NV_UPLOADS_REAL_DIR . '/' . $module_name, false );
  95. @unlink( $_FILES['banner']['tmp_name'] );
  96. if ( ! empty( $upload_info['error'] ) )
  97. {
  98. $error = $upload_info['error'];
  99. }
  100. else
  101. {
  102. @chmod( $upload_info['name'], 0644 );
  103. if ( ! empty( $file_name ) and is_file( NV_ROOTDIR . '/' . $file_name ) )
  104. {
  105. @nv_deletefile( NV_ROOTDIR . '/' . $file_name );
  106. }
  107. $file_name = str_replace( NV_ROOTDIR . "/", "", $upload_info['name'] );
  108. $file_ext = $upload_info['ext'];
  109. $file_mime = $upload_info['mime'];
  110. $width = $upload_info['img_info'][0];
  111. $height = $upload_info['img_info'][1];
  112. }
  113. }
  114. if ( empty( $error ) )
  115. {
  116. if ( empty( $publ_date ) )
  117. {
  118. $publtime = NV_CURRENTTIME;
  119. }
  120. else
  121. {
  122. unset( $m );
  123. preg_match( "/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $publ_date, $m );
  124. $publtime = mktime( 0, 0, 0, $m[2], $m[1], $m[3] );
  125. if ( $publtime < $row['add_time'] ) $publtime = $row['add_time'];
  126. }
  127. if ( empty( $exp_date ) )
  128. {
  129. $exptime = 0;
  130. }
  131. else
  132. {
  133. unset( $m );
  134. preg_match( "/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $exp_date, $m );
  135. $exptime = mktime( 23, 59, 59, $m[2], $m[1], $m[3] );
  136. }
  137. if ( $exptime != 0 and $exptime <= $publtime ) $exptime = $publtime;
  138. $sql = "UPDATE `" . NV_BANNERS_ROWS_GLOBALTABLE . "` SET `title`=" . $db->dbescape( $title ) . ", `pid`=" . $pid . ", `clid`=" . $clid . ",
  139. `file_name`=" . $db->dbescape( $file_name ) . ", `file_ext`=" . $db->dbescape( $file_ext ) . ", `file_mime`=" . $db->dbescape( $file_mime ) . ",
  140. `width`=" . $width . ", `height`=" . $height . ", `file_alt`=" . $db->dbescape( $file_alt ) . ", `click_url`=" . $db->dbescape( $click_url ) . ",
  141. `publ_time`=" . $publtime . ", `exp_time`=" . $exptime . " WHERE `id`=" . $id;
  142. $db->sql_query( $sql );
  143. nv_insert_logs( NV_LANG_DATA, $module_name, 'log_edit_banner', "bannerid ".$id, $admin_info['userid'] );
  144. nv_CreateXML_bannerPlan();
  145. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=info_banner&id=" . $id );
  146. die();
  147. }
  148. }
  149. }
  150. else
  151. {
  152. $title = $row['title'];
  153. $pid = $row['pid'];
  154. $clid = $row['clid'];
  155. $file_alt = $row['file_alt'];
  156. $click_url = $row['click_url'];
  157. $publ_date = ! empty( $row['publ_time'] ) ? date( "d.m.Y", $row['publ_time'] ) : "";
  158. $exp_date = ! empty( $row['exp_time'] ) ? date( "d.m.Y", $row['exp_time'] ) : "";
  159. }
  160. if ( $click_url == "" ) $click_url = "http://";
  161. $contents['info'] = ( ! empty( $error ) ) ? $error : $lang_module['edit_banner_info'];
  162. $contents['is_error'] = ( ! empty( $error ) ) ? 1 : 0;
  163. $contents['file_allowed_ext'] = implode( ", ", $contents['file_allowed_ext'] );
  164. $contents['submit'] = $lang_module['edit_banner'];
  165. $contents['action'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=edit_banner&amp;id=" . $id;
  166. $contents['title'] = array( $lang_module['title'], 'title', $title, 255 );
  167. $contents['plan'] = array( $lang_module['in_plan'], 'pid', $plans, $pid );
  168. $contents['client'] = array( $lang_module['of_client'], 'clid', $clients, $clid );
  169. //$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'] );
  170. $contents['file_name'] = array( $lang_module['file_name'], NV_BASE_SITEURL . $file_name, "rel=\"shadowbox;height=" . $height . ";width=" . $width . "\"", NV_BASE_SITEURL . "images/ico_" . $file_ext . ".gif", $lang_global['show_picture'] );
  171. $contents['upload'] = array( sprintf( $lang_module['re_upload'], $contents['file_allowed_ext'] ), 'banner' );
  172. $contents['file_alt'] = array( $lang_module['file_alt'], 'file_alt', $file_alt, 255 );
  173. $contents['click_url'] = array( $lang_module['click_url'], 'click_url', $click_url, 255 );
  174. $contents['publ_date'] = array( $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);" );
  175. $contents['exp_date'] = array( $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);" );
  176. $my_head = "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/popcalendar/popcalendar.js\"></script>\n";
  177. //$my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/highslide/highslide.js\"></script>\n";
  178. //$my_head .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . NV_BASE_SITEURL . "js/highslide/highslide.css\" />\n";
  179. //$my_head .= "<script type=\"text/javascript\">\n";
  180. //$my_head .= " hs.wrapperClassName = 'wide-border';\n";
  181. //$my_head .= "</script>\n";
  182. $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/shadowbox/shadowbox.js\"></script>\n";
  183. $my_head .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . NV_BASE_SITEURL . "js/shadowbox/shadowbox.css\" />\n";
  184. $my_head .= "<script type=\"text/javascript\">\n";
  185. $my_head .= "Shadowbox.init({\n";
  186. //$my_head .= "handleOversize: \"drag\",\n";
  187. //$my_head .= "modal: true\n";
  188. $my_head .= "});\n";
  189. $my_head .= "</script>\n";
  190. include ( NV_ROOTDIR . "/includes/header.php" );
  191. echo nv_admin_theme( nv_edit_banner_theme( $contents ) );
  192. include ( NV_ROOTDIR . "/includes/footer.php" );
  193. ?>