PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/01.Source/01.CORE/modules/download/admin/add.php

http://creative-portal.googlecode.com/
PHP | 366 lines | 317 code | 43 blank | 6 comment | 34 complexity | c1967c415d94b9af88fe9fe6ccc65e64 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 12/9/2010, 22:27
  7. */
  8. if ( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
  9. $page_title = $lang_module['file_addfile'];
  10. $groups_list = nv_groups_list();
  11. $array_who = array(
  12. $lang_global['who_view0'], $lang_global['who_view1'], $lang_global['who_view2']
  13. );
  14. if ( ! empty( $groups_list ) )
  15. {
  16. $array_who[] = $lang_global['who_view3'];
  17. }
  18. $array = array();
  19. $is_error = false;
  20. $error = "";
  21. if ( $nv_Request->isset_request( 'submit', 'post' ) )
  22. {
  23. $array['catid'] = $nv_Request->get_int( 'catid', 'post', 0 );
  24. $array['title'] = filter_text_input( 'title', 'post', '', 1 );
  25. $array['description'] = nv_editor_filter_textarea( 'description', '', NV_ALLOWED_HTML_TAGS );
  26. $array['introtext'] = filter_text_textarea( 'introtext', '', NV_ALLOWED_HTML_TAGS );
  27. $array['author_name'] = filter_text_input( 'author_name', 'post', '', 1 );
  28. $array['author_email'] = filter_text_input( 'author_email', 'post', '' );
  29. $array['author_url'] = filter_text_input( 'author_url', 'post', '' );
  30. $array['fileupload'] = $nv_Request->get_typed_array( 'fileupload', 'post', 'string' );
  31. $array['linkdirect'] = $nv_Request->get_typed_array( 'linkdirect', 'post', 'string' );
  32. $array['version'] = filter_text_input( 'version', 'post', '', 1 );
  33. $array['fileimage'] = filter_text_input( 'fileimage', 'post', '' );
  34. $array['copyright'] = filter_text_input( 'copyright', 'post', '', 1 );
  35. $array['comment_allow'] = $nv_Request->get_int( 'comment_allow', 'post', 0 );
  36. $array['who_comment'] = $nv_Request->get_int( 'who_comment', 'post', 0 );
  37. $array['groups_comment'] = $nv_Request->get_typed_array( 'groups_comment', 'post', 'int' );
  38. $array['is_del_report'] = $nv_Request->get_int( 'is_del_report', 'post', 0 );
  39. if ( ! empty( $array['author_url'] ) )
  40. {
  41. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['author_url'] ) )
  42. {
  43. $array['author_url'] = "http://" . $array['author_url'];
  44. }
  45. }
  46. $array['filesize'] = 0;
  47. if ( ! empty( $array['fileupload'] ) )
  48. {
  49. $fileupload = $array['fileupload'];
  50. $array['fileupload'] = array();
  51. $array['filesize'] = 0;
  52. foreach ( $fileupload as $file )
  53. {
  54. if ( ! empty( $file ) )
  55. {
  56. $file2 = substr( $file, strlen( NV_BASE_SITEURL ) );
  57. if ( file_exists( NV_ROOTDIR . '/' . $file2 ) and ( $filesize = filesize( NV_ROOTDIR . '/' . $file2 ) ) != 0 )
  58. {
  59. $array['fileupload'][] = $file;
  60. $array['filesize'] += $filesize;
  61. }
  62. }
  63. }
  64. }
  65. else
  66. {
  67. $array['fileupload'] = array();
  68. }
  69. if ( ! empty( $array['linkdirect'] ) )
  70. {
  71. $linkdirect = $array['linkdirect'];
  72. $array['linkdirect'] = array();
  73. foreach ( $linkdirect as $links )
  74. {
  75. $linkdirect2 = array();
  76. if ( ! empty( $links ) )
  77. {
  78. $links = nv_nl2br( $links, "<br />" );
  79. $links = explode( "<br />", $links );
  80. $links = array_map( "trim", $links );
  81. $links = array_unique( $links );
  82. foreach ( $links as $link )
  83. {
  84. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $link ) )
  85. {
  86. $link = "http://" . $link;
  87. }
  88. if ( nv_is_url( $link ) )
  89. {
  90. $linkdirect2[] = $link;
  91. }
  92. }
  93. }
  94. if ( ! empty( $linkdirect2 ) )
  95. {
  96. $array['linkdirect'][] = implode( "\n", $linkdirect2 );
  97. }
  98. }
  99. }
  100. else
  101. {
  102. $array['linkdirect'] = array();
  103. }
  104. if ( ! empty( $array['linkdirect'] ) )
  105. {
  106. $array['linkdirect'] = array_unique( $array['linkdirect'] );
  107. }
  108. if ( ! empty( $array['linkdirect'] ) and empty( $array['fileupload'] ) )
  109. {
  110. $array['filesize'] = $nv_Request->get_int( 'filesize', 'post', 0 );
  111. }
  112. $alias = change_alias( $array['title'] );
  113. $sql = "SELECT COUNT(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "` WHERE `alias`=" . $db->dbescape( $alias );
  114. $result = $db->sql_query( $sql );
  115. list( $is_exists ) = $db->sql_fetchrow( $result );
  116. if ( ! $is_exists )
  117. {
  118. $sql = "SELECT COUNT(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_tmp` WHERE `title`=" . $db->dbescape( $array['title'] );
  119. $result = $db->sql_query( $sql );
  120. list( $is_exists ) = $db->sql_fetchrow( $result );
  121. }
  122. if ( empty( $array['title'] ) )
  123. {
  124. $is_error = true;
  125. $error = $lang_module['file_error_title'];
  126. }
  127. elseif ( $is_exists )
  128. {
  129. $is_error = true;
  130. $error = $lang_module['file_title_exists'];
  131. }
  132. elseif ( ! empty( $array['author_email'] ) and ( $check_valid_email = nv_check_valid_email( $array['author_email'] ) ) != "" )
  133. {
  134. $is_error = true;
  135. $error = $check_valid_email;
  136. }
  137. elseif ( ! empty( $array['author_url'] ) and ! nv_is_url( $array['author_url'] ) )
  138. {
  139. $is_error = true;
  140. $error = $lang_module['file_error_author_url'];
  141. }
  142. elseif ( empty( $array['fileupload'] ) and empty( $array['linkdirect'] ) )
  143. {
  144. $is_error = true;
  145. $error = $lang_module['file_error_fileupload'];
  146. }
  147. else
  148. {
  149. $array['introtext'] = ! empty( $array['introtext'] ) ? nv_nl2br( $array['introtext'], "<br />" ) : "";
  150. $array['description'] = ! empty( $array['description'] ) ? nv_editor_nl2br( $array['description'] ) : $array['introtext'];
  151. $array['fileupload'] = ( ! empty( $array['fileupload'] ) ) ? implode( "[NV]", $array['fileupload'] ) : "";
  152. if ( ( ! empty( $array['linkdirect'] ) ) )
  153. {
  154. $array['linkdirect'] = array_map( "nv_nl2br", $array['linkdirect'] );
  155. $array['linkdirect'] = implode( "[NV]", $array['linkdirect'] );
  156. }
  157. else
  158. {
  159. $array['linkdirect'] = "";
  160. }
  161. if ( ! in_array( $array['who_comment'], array_keys( $array_who ) ) )
  162. {
  163. $array['who_comment'] = 0;
  164. }
  165. $array['groups_comment'] = ( ! empty( $array['groups_comment'] ) ) ? implode( ',', $array['groups_comment'] ) : '';
  166. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "` VALUES (
  167. NULL,
  168. " . $array['catid'] . ",
  169. " . $db->dbescape( $array['title'] ) . ",
  170. " . $db->dbescape( $alias ) . ",
  171. " . $db->dbescape( $array['description'] ) . ",
  172. " . $db->dbescape( $array['introtext'] ) . ",
  173. " . NV_CURRENTTIME . ",
  174. " . NV_CURRENTTIME . ",
  175. " . $admin_info['admin_id'] . ",
  176. " . $db->dbescape( $admin_info['username'] ) . ",
  177. " . $db->dbescape( $array['author_name'] ) . ",
  178. " . $db->dbescape( $array['author_email'] ) . ",
  179. " . $db->dbescape( $array['author_url'] ) . ",
  180. " . $db->dbescape( $array['fileupload'] ) . ",
  181. " . $db->dbescape( $array['linkdirect'] ) . ",
  182. " . $db->dbescape( $array['version'] ) . ",
  183. " . $array['filesize'] . ",
  184. " . $db->dbescape( $array['fileimage'] ) . ",
  185. 1,
  186. " . $db->dbescape( $array['copyright'] ) . ",
  187. 0, 0,
  188. " . $array['comment_allow'] . ",
  189. " . $array['who_comment'] . ",
  190. " . $db->dbescape( $array['groups_comment'] ) . ",
  191. 0, '')";
  192. if ( ! $db->sql_query_insert_id( $sql ) )
  193. {
  194. $is_error = true;
  195. $error = $lang_module['file_error2'];
  196. }
  197. else
  198. {
  199. nv_insert_logs( NV_LANG_DATA, $module_name, 'log_add', " ", $admin_info['userid'] );
  200. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  201. exit();
  202. }
  203. }
  204. }
  205. else
  206. {
  207. $array['catid'] = 0;
  208. $array['title'] = $array['description'] = $array['introtext'] = $array['author_name'] = $array['author_email'] = $array['author_url'] = $array['version'] = $array['fileimage'] = "";
  209. $array['fileupload'] = $array['linkdirect'] = $array['groups_comment'] = array();
  210. $array['filesize'] = $array['who_comment'] = 0;
  211. $array['comment_allow'] = 1;
  212. $array['is_del_report'] = 1;
  213. }
  214. if ( ! empty( $array['description'] ) ) $array['description'] = nv_htmlspecialchars( $array['description'] );
  215. if ( ! empty( $array['introtext'] ) ) $array['introtext'] = nv_htmlspecialchars( $array['introtext'] );
  216. if ( ! count( $array['fileupload'] ) ) array_push( $array['fileupload'], "" );
  217. if ( ! count( $array['linkdirect'] ) ) array_push( $array['linkdirect'], "" );
  218. $array['fileupload_num'] = count( $array['fileupload'] );
  219. $array['linkdirect_num'] = count( $array['linkdirect'] );
  220. $listcats = nv_listcats( $array['catid'] );
  221. if ( empty( $listcats ) )
  222. {
  223. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=cat&add=1" );
  224. exit();
  225. }
  226. $array['comment_allow'] = $array['comment_allow'] ? " checked=\"checked\"" : "";
  227. $array['is_del_report'] = $array['is_del_report'] ? " checked=\"checked\"" : "";
  228. $who_comment = $array['who_comment'];
  229. $array['who_comment'] = array();
  230. foreach ( $array_who as $key => $who )
  231. {
  232. $array['who_comment'][] = array( //
  233. 'key' => $key, //
  234. 'title' => $who, //
  235. 'selected' => $key == $who_comment ? " selected=\"selected\"" : "" //
  236. );
  237. }
  238. $groups_comment = $array['groups_comment'];
  239. $array['groups_comment'] = array();
  240. if ( ! empty( $groups_list ) )
  241. {
  242. foreach ( $groups_list as $key => $title )
  243. {
  244. $array['groups_comment'][] = array( //
  245. 'key' => $key, //
  246. 'title' => $title, //
  247. 'checked' => in_array( $key, $groups_comment ) ? " checked=\"checked\"" : "" //
  248. );
  249. }
  250. }
  251. if ( defined( 'NV_EDITOR' ) )
  252. {
  253. require_once ( NV_ROOTDIR . '/' . NV_EDITORSDIR . '/' . NV_EDITOR . '/nv.php' );
  254. }
  255. if ( defined( 'NV_EDITOR' ) and function_exists( 'nv_aleditor' ) )
  256. {
  257. $array['description'] = nv_aleditor( 'description', '100%', '300px', $array['description'] );
  258. }
  259. else
  260. {
  261. $array['description'] = "<textarea style=\"width:100%; height:300px\" name=\"description\" id=\"description\">" . $array['description'] . "</textarea>";
  262. }
  263. $sql = "SELECT `config_value` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_config` WHERE `config_name`='upload_dir'";
  264. $result = $db->sql_query( $sql );
  265. list( $upload_dir ) = $db->sql_fetchrow( $result );
  266. if ( ! $array['filesize'] ) $array['filesize'] = "";
  267. $xtpl = new XTemplate( "content.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  268. $xtpl->assign( 'FORM_ACTION', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=add" );
  269. $xtpl->assign( 'LANG', $lang_module );
  270. $xtpl->assign( 'DATA', $array );
  271. $xtpl->assign( 'NV_BASE_ADMINURL', NV_BASE_ADMINURL );
  272. $xtpl->assign( 'NV_NAME_VARIABLE', NV_NAME_VARIABLE );
  273. $xtpl->assign( 'IMG_DIR', NV_UPLOADS_DIR . '/' . $module_name . '/images' );
  274. $xtpl->assign( 'FILES_DIR', NV_UPLOADS_DIR . '/' . $module_name . '/' . $upload_dir );
  275. if ( ! empty( $error ) )
  276. {
  277. $xtpl->assign( 'ERROR', $error );
  278. $xtpl->parse( 'main.error' );
  279. }
  280. foreach ( $listcats as $cat )
  281. {
  282. $xtpl->assign( 'LISTCATS', $cat );
  283. $xtpl->parse( 'main.catid' );
  284. }
  285. $a = 0;
  286. foreach ( $array['fileupload'] as $file )
  287. {
  288. $xtpl->assign( 'FILEUPLOAD', array(
  289. 'value' => $file, 'key' => $a
  290. ) );
  291. $xtpl->parse( 'main.fileupload' );
  292. $a ++;
  293. }
  294. $a = 0;
  295. foreach ( $array['linkdirect'] as $link )
  296. {
  297. $xtpl->assign( 'LINKDIRECT', array(
  298. 'value' => $link, 'key' => $a
  299. ) );
  300. $xtpl->parse( 'main.linkdirect' );
  301. $a ++;
  302. }
  303. foreach ( $array['who_comment'] as $who )
  304. {
  305. $xtpl->assign( 'WHO_COMMENT', $who );
  306. $xtpl->parse( 'main.who_comment' );
  307. }
  308. if ( ! empty( $array['groups_comment'] ) )
  309. {
  310. foreach ( $array['groups_comment'] as $group )
  311. {
  312. $xtpl->assign( 'GROUPS_COMMENT', $group );
  313. $xtpl->parse( 'main.group_empty.groups_comment' );
  314. }
  315. $xtpl->parse( 'main.group_empty' );
  316. }
  317. $xtpl->parse( 'main' );
  318. $contents = $xtpl->text( 'main' );
  319. include ( NV_ROOTDIR . "/includes/header.php" );
  320. echo nv_admin_theme( $contents );
  321. include ( NV_ROOTDIR . "/includes/footer.php" );
  322. exit();
  323. ?>