PageRenderTime 60ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/01.Source/01.CORE/modules/weblinks/admin/content.php

http://creative-portal.googlecode.com/
PHP | 238 lines | 216 code | 14 blank | 8 comment | 27 complexity | 1d9fc5754d6d8ea03484597c3b2b51d2 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 2-9-2010 14:43
  7. */
  8. if ( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
  9. function check_url ( $id, $url )
  10. {
  11. global $db, $module_data;
  12. $sql = "SELECT count(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_rows` WHERE `id` != '" . $id . "' AND `url` = '" . $url . "'";
  13. list( $numurl ) = $db->sql_fetchrow( $db->sql_query( $sql ) );
  14. $msg = ( $numurl > 0 ) ? false : true;
  15. return $msg;
  16. }
  17. function check_title ( $title )
  18. {
  19. global $db, $module_data;
  20. $sql = 'SELECT title FROM `' . NV_PREFIXLANG . '_' . $module_data . '_rows` WHERE title = "' . $title . '"';
  21. $numtitle = $db->sql_numrows( $db->sql_query( $sql ) );
  22. $msg = ( $numtitle > 0 ) ? false : true;
  23. return $msg;
  24. }
  25. $rowcat = array(
  26. "id" => "", "catid" => "", "title" => "", "alias" => "", "url" => "", "urlimg" => "", "description" => "", "add_time" => "", "edit_time" => "", "hits_total" => "", "status" => 1
  27. );
  28. $error = "";
  29. $id = $nv_Request->get_int( 'id', 'post,get', 0 );
  30. $submit = $nv_Request->get_string( 'submit', 'post' );
  31. if ( ! empty( $submit ) )
  32. {
  33. $error = 0;
  34. $catid = $nv_Request->get_int( 'catid', 'post', 0 );
  35. $title = filter_text_input( 'title', 'post', '', 1 );
  36. $alias = filter_text_input( 'alias', 'post', '', 1 );
  37. $parentid = $nv_Request->get_int( 'parentid', 'post', 0 );
  38. $alias = ( $alias == "" ) ? change_alias( $title ) : change_alias( $alias );
  39. $url = filter_text_input( 'url', 'post', '' );
  40. $image = filter_text_input( 'image', 'post', '' );
  41. if ( ! nv_is_url( $image ) and file_exists( NV_DOCUMENT_ROOT . $image ) )
  42. {
  43. $lu = strlen( NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" );
  44. if ( substr( $image, 0, $lu ) == NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" )
  45. {
  46. $image = substr( $image, $lu );
  47. }
  48. }
  49. $admin_phone = "";
  50. $admin_email = "";
  51. $note = "";
  52. $description = filter_text_textarea( 'description', '', NV_ALLOWED_HTML_TAGS );
  53. $description = ( defined( 'NV_EDITOR' ) ) ? nv_editor_nl2br( $description ) : nv_nl2br( $description, '<br />' );
  54. $status = ( $nv_Request->get_int( 'status', 'post' ) == 1 ) ? 1 : 0;
  55. //check url
  56. if ( empty( $url ) || ! nv_is_url( $url ) || ! check_url( $id, $url ) )
  57. {
  58. $error = $lang_module['error_url'];
  59. }
  60. elseif ( empty( $title ) )
  61. {
  62. $error = $lang_module['error_title'];
  63. }
  64. elseif ( strip_tags( $description ) == "" )
  65. {
  66. $error = $lang_module['error_description'];
  67. }
  68. else
  69. {
  70. if ( $id > 0 )
  71. {
  72. $query = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_rows` SET `catid`=" . $catid . ", `title`=" . $db->dbescape( $title ) . ", `alias` = " . $db->dbescape( $alias ) . ", `url` = " . $db->dbescape( $url ) . ", `urlimg` = " . $db->dbescape( $image ) . ", `description`=" . $db->dbescape( $description ) . ", `edit_time` = UNIX_TIMESTAMP(), `status`=" . $status . " WHERE `id` =" . $id . "";
  73. $db->sql_query( $query );
  74. if ( $db->sql_affectedrows() > 0 )
  75. {
  76. nv_insert_logs( NV_LANG_DATA, $module_name, 'log_edit_content', "id ".$id, $admin_info['userid'] );
  77. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "" );
  78. die();
  79. }
  80. else
  81. {
  82. $error = $lang_module['errorsave'];
  83. }
  84. $db->sql_freeresult();
  85. }
  86. else
  87. {
  88. $query = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_rows` (`id`, `catid`, `title`, `alias`, `url`, `urlimg`, `admin_phone`, `admin_email`, `note`, `description`, `add_time`, `edit_time`, `hits_total`, `status`)
  89. VALUES (NULL, '" . $catid . "', " . $db->dbescape( $title ) . ", " . $db->dbescape( $alias ) . ", " . $db->dbescape( $url ) . ", " . $db->dbescape( $image ) . ", '" . $admin_phone . "', '" . $admin_email . "', " . $db->dbescape( $note ) . ", " . $db->dbescape( $description ) . ", UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '0', " . $status . ")";
  90. if ( $db->sql_query_insert_id( $query ) )
  91. {
  92. nv_insert_logs( NV_LANG_DATA, $module_name, 'log_add_content', " ", $admin_info['userid'] );
  93. $db->sql_freeresult();
  94. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "" );
  95. die();
  96. }
  97. else
  98. {
  99. $error = $lang_module['errorsave'];
  100. }
  101. }
  102. }
  103. $rowcat['id'] = $id;
  104. $rowcat['url'] = $url;
  105. $rowcat['title'] = $title;
  106. $rowcat['urlimg'] = $image;
  107. $rowcat['description'] = $description;
  108. }
  109. elseif ( $id > 0 )
  110. {
  111. $query = $db->sql_query( "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_rows` WHERE `id`=" . $id . "" );
  112. $rowcat = $db->sql_fetchrow( $query );
  113. if ( $rowcat['id'] > 0 )
  114. {
  115. $page_title = $lang_module['weblink_edit_link'];
  116. }
  117. }
  118. if ( empty( $rowcat['id'] ) )
  119. {
  120. $page_title = $lang_module['weblink_add_link'];
  121. }
  122. $rowcat['description'] = ( defined( 'NV_EDITOR' ) ) ? nv_editor_br2nl( $rowcat['description'] ) : nv_br2nl( $rowcat['description'] ); // dung de lay data tu CSDL
  123. $rowcat['description'] = nv_htmlspecialchars( $rowcat['description'] ); // dung de dua vao editor
  124. if ( ! empty( $rowcat['urlimg'] ) and ! nv_is_url( $rowcat['urlimg'] ) )
  125. {
  126. $rowcat['urlimg'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $rowcat['urlimg'];
  127. }
  128. if ( defined( 'NV_EDITOR' ) )
  129. {
  130. require_once ( NV_ROOTDIR . '/' . NV_EDITORSDIR . '/' . NV_EDITOR . '/nv.php' );
  131. }
  132. $contents = "";
  133. if ( $error != "" )
  134. {
  135. $contents .= "<div class=\"quote\" style=\"width:780px;\">\n";
  136. $contents .= "<blockquote class=\"error\"><span>" . $error . "</span></blockquote>\n";
  137. $contents .= "</div>\n";
  138. $contents .= "<div class=\"clear\"></div>\n";
  139. }
  140. $contents .= "<div id=\"list_mods\">";
  141. $contents .= "<form action=\"" . NV_BASE_ADMINURL . "index.php\" method=\"post\">";
  142. // post header parameter
  143. $contents .= "<input type=\"hidden\" name =\"" . NV_NAME_VARIABLE . "\"value=\"" . $module_name . "\" />";
  144. $contents .= "<input type=\"hidden\" name =\"" . NV_OP_VARIABLE . "\"value=\"" . $op . "\" />";
  145. $contents .= "<input type=\"hidden\" name =\"id\" value=\"" . $id . "\" />";
  146. $contents .= "<table class=\"tab2\" cellspacing=\"5\" cellpadding=\"5\">\n";
  147. $contents .= "<tr>";
  148. $contents .= "<td align=\"right\" style=\"width: 150px;\">" . $lang_module['weblink_add_title'] . ": </td>\n";
  149. $contents .= "<td><input type=\"text\" name=\"title\" id=\"webtitle\" style=\"width:550px\" value=\"" . $rowcat['title'] . "\"/></td>\n";
  150. $contents .= "</tr>";
  151. $contents .= "<tr>";
  152. $contents .= "<td valign=\"top\" align=\"right\">" . $lang_module['weblink_add_url'] . ": </td>\n";
  153. $contents .= "<td><input style=\"width: 550px\" name=\"url\" id= \"url\" type=\"text\" value=\"" . $rowcat['url'] . "\" maxlength=\"255\" /></td>\n";
  154. $contents .= "</tr>";
  155. $contents .= "<tr>";
  156. $contents .= "<td valign=\"top\" align=\"right\">" . $lang_module['weblink_add_parent'] . ": </td>\n";
  157. $contents .= "<td>\n";
  158. $contents .= "<select name=\"catid\">\n";
  159. $querysubcat = $db->sql_query( "SELECT catid, parentid, title FROM `" . NV_PREFIXLANG . "_" . $module_data . "_cat` ORDER BY `parentid`, `weight` ASC" );
  160. $array_cat = array();
  161. while ( $row = $db->sql_fetchrow( $querysubcat ) )
  162. {
  163. $selected = ( intval( $row['catid'] ) == intval( $rowcat["catid"] ) ) ? 'selected' : '';
  164. $array_cat[$row['catid']] = $row['title'];
  165. $title = $row["title"];
  166. if ( intval( $row['parentid'] ) > 0 )
  167. {
  168. $title = $array_cat[$row['parentid']] . " ->" . $row["title"];
  169. }
  170. $contents .= "<option value=\"" . $row["catid"] . "\" " . $selected . ">" . $title . "</option>\n";
  171. }
  172. $contents .= "</select>\n";
  173. $contents .= "</td>\n";
  174. $contents .= "</tr>";
  175. if ( $id > 0 )
  176. {
  177. $contents .= "<tr>";
  178. $contents .= "<td valign=\"top\" align=\"right\">" . $lang_module['alias'] . ": </td>\n";
  179. $contents .= "<td><input style=\"width: 200px\" name=\"alias\" type=\"text\" value=\"" . $rowcat['alias'] . "\" maxlength=\"255\" /></td>\n";
  180. $contents .= "</tr>";
  181. }
  182. $contents .= "<tr>";
  183. $contents .= "<td valign=\"top\" align=\"right\">" . $lang_module['weblink_add_image'] . ": </td>\n";
  184. $contents .= "<td>";
  185. $contents .= '<input style="width:400px" type="text" name="image" id="image" value="' . $rowcat['urlimg'] . '"/>';
  186. $contents .= '<input type="button" value="Browse Server" name="selectimg"/>
  187. <script type="text/javascript">
  188. $("input[name=selectimg]").click(function(){
  189. var area = "image";
  190. var path= "' . NV_UPLOADS_DIR . '/' . $module_name . '";
  191. nv_open_browse_file("' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=upload&popup=1&area=" + area+"&path="+path, "NVImg", "850", "500","resizable=no,scrollbars=no,toolbar=no,location=no,status=no");
  192. return false;
  193. });
  194. </script> ';
  195. $contents .= "</td>";
  196. $contents .= "</tr>";
  197. $contents .= "<tr>";
  198. $contents .= "<td align=\"right\">" . $lang_module['weblink_description'] . ": </td>\n";
  199. $contents .= "<td>";
  200. if ( defined( 'NV_EDITOR' ) and function_exists( 'nv_aleditor' ) )
  201. {
  202. $contents .= nv_aleditor( "description", '700px', '300px', $rowcat['description'] );
  203. }
  204. else
  205. {
  206. $contents .= "<textarea style=\"width: 650px\" name=\"description\" id=\"description\" cols=\"20\" rows=\"8\">" . $rowcat['description'] . "</textarea>";
  207. }
  208. $contents .= "</td>\n";
  209. $contents .= "</tr>";
  210. $contents .= "<tr>";
  211. $contents .= "<td valign=\"top\" align=\"right\">" . $lang_module['weblink_inhome'] . ": </td>\n";
  212. $checked = ( intval( $rowcat['status'] ) == 1 ) ? 'checked' : '';
  213. $contents .= "<td><label><input name=\"status\" type=\"checkbox\" value=\"1\" checked=\"" . $checked . "\" />" . $lang_module['weblink_yes'] . "</label></td>\n";
  214. $contents .= "</tr>";
  215. $contents .= "<tr>";
  216. $contents .= "<td align=\"left\" colspan=\"2\"><input name=\"submit\" style=\"width:80px;margin-left:110px\" type=\"submit\" value=\"" . $lang_module['weblink_submit'] . "\" /></td>\n";
  217. $contents .= "</tr>";
  218. $contents .= "</table>";
  219. $contents .= "</form>\n";
  220. $contents .= "</div>\n";
  221. include ( NV_ROOTDIR . "/includes/header.php" );
  222. echo nv_admin_theme( $contents );
  223. include ( NV_ROOTDIR . "/includes/footer.php" );
  224. ?>