PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/01.Source/01.CORE/modules/video/admin/add_img.php

http://creative-portal.googlecode.com/
PHP | 206 lines | 173 code | 27 blank | 6 comment | 26 complexity | de878dc2560a4f9667c1f8229851b59e 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 7-17-2010 14:43
  7. */
  8. if ( ! defined( 'NV_IS_ALBUMS_ADMIN' ) )
  9. {
  10. die( 'Stop!!!' );
  11. }
  12. if ( defined( 'NV_EDITOR' ) )
  13. {
  14. require_once ( NV_ROOTDIR . '/' . NV_EDITORSDIR . '/' . NV_EDITOR . '/nv.php' );
  15. }
  16. $id = $nv_Request->get_int( 'id', 'get', 0 );
  17. if ( $id == 0 )
  18. {
  19. $page_title = $lang_module['add_pic'];
  20. }
  21. else
  22. {
  23. $page_title = $lang_module['edit_pic'];
  24. }
  25. $error = "";
  26. $xtpl = new XTemplate( "upload.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_name );
  27. $adb = new albumdb();
  28. $max_x = 120;
  29. $max_y = 100;
  30. $data = array();
  31. $data['albumid'] = $nv_Request->get_int( 'idb', 'get', 0 );
  32. $data['is_show'] = 0;
  33. if ( $id != 0 )
  34. {
  35. $sql = "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_picture` WHERE pictureid = '" . $id . "'";
  36. $result = $db->sql_query( $sql );
  37. $data = $db->sql_fetchrow( $result );
  38. $data['v_path'] = $data['vpath'];
  39. }
  40. if ( $nv_Request->get_int( 'add', 'post' ) == 1 )
  41. {
  42. $data['name'] = filter_text_input( 'name', 'post', '', 1 );
  43. $data['alias'] = change_alias( $data['name'] );
  44. $thumb_name = "";
  45. $data['albumid'] = $nv_Request->get_int( 'album', 'post' );
  46. $data['path'] = filter_text_input( 'pic_path', 'post', '', 0 );
  47. $data['v_path'] = filter_text_input( 'v_path', 'post', '', 0 );
  48. $data['description'] = filter_text_textarea( 'description', '', NV_ALLOWED_HTML_TAGS );
  49. $data['is_show'] = filter_text_input('is_show', 'post', '0', 0);
  50. if ( ! empty( $data['v_path'] ) and file_exists( NV_DOCUMENT_ROOT . $data['v_path'] ) )
  51. {
  52. $lu = strlen( NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name );
  53. $data['v_path'] = substr( $data['v_path'], $lu );
  54. }
  55. elseif ( ! nv_is_url( $data['v_path'] ) and ! empty( $data['v_path'] ) )
  56. {
  57. $data['v_path'] = "";
  58. }
  59. if ( ! empty( $data['path'] ) and file_exists( NV_DOCUMENT_ROOT . $data['path'] ) )
  60. {
  61. $homeimgfile = NV_DOCUMENT_ROOT . $data['path'];
  62. require_once ( NV_ROOTDIR . "/includes/class/image.class.php" );
  63. $basename = basename( $homeimgfile );
  64. $image = new image( $homeimgfile, NV_MAX_WIDTH, NV_MAX_HEIGHT );
  65. $image->resizeXY( $max_x, $max_y );
  66. $image->save( NV_UPLOADS_REAL_DIR . '/' . $module_name . '/thumb', $basename );
  67. $image_info = $image->create_Image_info;
  68. $image->close();
  69. $thumb_name = str_replace( NV_UPLOADS_REAL_DIR . '/' . $module_name . '/', '', $image_info['src'] );
  70. $lu = strlen( NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name );
  71. $data['path'] = substr( $data['path'], $lu );
  72. }
  73. elseif ( ! nv_is_url( $data['path'] ) and ! empty( $data['path'] ) )
  74. {
  75. $data['path'] = "";
  76. }
  77. if ( $data['albumid'] > 0 )
  78. {
  79. if ( empty( $data['name'] ) )
  80. {
  81. $error = $lang_module['err_null_name'];
  82. }
  83. else
  84. {
  85. if ( empty( $data['v_path'] ) )
  86. {
  87. $error = $lang_module['err_null_path'];
  88. }
  89. elseif ( empty( $error ) )
  90. {
  91. if ( $id == 0 )
  92. {
  93. $num = $db->sql_numrows( $adb->getAlbumImgs( $data['albumid'] ) );
  94. if ( empty( $data['name'] ) )
  95. {
  96. list( $mo, $data['name'] ) = split( '[/.]', $data['path'] ); //
  97. }
  98. if ( $adb->addNewImg( $data['name'], $data['alias'], $data['path'], nv_editor_nl2br( $data['description'] ), $thumb_name, $data['albumid'], $num + 1, $data['v_path'], $data['is_show'] ) )
  99. {
  100. $adb->update_numphoto( $data['albumid'] );
  101. $adb->freeResult();
  102. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=listimg&idb=" . $data['albumid'] );
  103. die();
  104. }
  105. else
  106. {
  107. $error = $lang_module['err_save_img'];
  108. }
  109. }
  110. else
  111. {
  112. if ( $adb->updateImgInfo( $data['pictureid'], $data['name'], $data['alias'], $data['path'], nv_editor_nl2br( $data['description'] ), $thumb_name, $data['albumid'], $data['v_path'],$data['is_show'] ) )
  113. {
  114. $adb->update_numphoto( $data['albumid'] );
  115. $adb->freeResult();
  116. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=listimg&idb=" . $data['albumid'] );
  117. die();
  118. }
  119. else
  120. {
  121. $error = $lang_module['err_save_img'];
  122. }
  123. }
  124. }
  125. }
  126. }
  127. else
  128. {
  129. $error = $lang_module['empt_album'];
  130. }
  131. }
  132. if ( ! empty( $data['path'] ) and file_exists( NV_UPLOADS_REAL_DIR . "/" . $module_name . $data['path'] ) )
  133. {
  134. $data['path'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . $data['path'];
  135. }
  136. if ( ! empty( $data['v_path'] ) and file_exists( NV_UPLOADS_REAL_DIR . "/" . $module_name . $data['v_path'] ) )
  137. {
  138. $data['v_path'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . $data['v_path'];
  139. }
  140. if ( $error != "" )
  141. {
  142. $xtpl->assign( 'ERR', $error );
  143. $xtpl->parse( 'main.err' );
  144. }
  145. $xtpl->assign( 'LANG', $lang_module );
  146. if ( ! empty( $data ) )
  147. {
  148. $xtpl->assign( 'DATA', $data );
  149. $is_show = ($data['is_show'])?("checked=\"checked\""):("");
  150. $xtpl->assign('IS_SHOW', $is_show);
  151. }
  152. if ( ! empty( $data['description'] ) )
  153. {
  154. $xtpl->assign( 'EDITOR', nv_aleditor( 'description', '100%', '300px', $data['description'] ) );
  155. }
  156. else
  157. {
  158. $xtpl->assign( 'EDITOR', nv_aleditor( 'description', '100%', '300px', "" ) );
  159. }
  160. $xtpl->assign( 'NV_NAME', NV_NAME_VARIABLE );
  161. $xtpl->assign( 'MOD_NAME', $module_name );
  162. $albums = $adb->getAllAlbums();
  163. while ( $album = $db->sql_fetchrow( $albums ) )
  164. {
  165. $xtpl->assign( 'albumid', $album['albumid'] );
  166. $xtpl->assign( 'name', $album['name'] );
  167. $select = ( $data['albumid'] == $album['albumid'] ) ? "selected=\"selected\"" : "";
  168. $xtpl->assign( 'SELECT', $select );
  169. $xtpl->parse( 'main.album' );
  170. }
  171. $xtpl->assign( 'PATH', NV_UPLOADS_DIR . '/' . $module_name );
  172. $xtpl->assign( 'PATH_V', NV_UPLOADS_DIR . '/' . $module_name . "/vid" );
  173. $xtpl->assign( 'BROWSER', NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=upload&popup=1&area=" + area+"&path="+path+"&type="+type, "NVImg", "850", "400","resizable=no,scrollbars=no,toolbar=no,location=no,status=no' );
  174. $xtpl->parse( 'main' );
  175. $contents = $xtpl->text( 'main' );
  176. include ( NV_ROOTDIR . "/includes/header.php" );
  177. echo nv_admin_theme( $contents );
  178. include ( NV_ROOTDIR . "/includes/footer.php" );
  179. ?>