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

/modules/music/admin/addvideo.php

http://nukeviet-music.googlecode.com/
PHP | 421 lines | 352 code | 46 blank | 23 comment | 49 complexity | 9586ec346a81f5486216404f0bf89345 MD5 | raw file
  1. <?php
  2. /**
  3. * @Project NUKEVIET-MUSIC
  4. * @Author Phan Tan Dung (phantandung92@gmail.com)
  5. * @Copyright (C) 2011 Freeware
  6. * @Createdate 26/01/2011
  7. */
  8. if( ! defined( 'NV_IS_MUSIC_ADMIN' ) ) die( 'Stop!!!' );
  9. // Ham kiem tra video co day du thong tin chua
  10. function nv_check_ok_video( $array )
  11. {
  12. global $lang_module;
  13. if( empty( $array['name'] ) ) return $lang_module['video_error_name'];
  14. if( empty( $array['tname'] ) ) return $lang_module['video_error_tname'];
  15. if( empty( $array['theloai'] ) ) return $lang_module['video_error_theloai'];
  16. if( empty( $array['duongdan'] ) ) return $lang_module['video_error_duongdan'];
  17. if( empty( $array['thumb'] ) ) return $lang_module['video_error_thumb'];
  18. return "";
  19. }
  20. $contents = "";
  21. $error = "";
  22. $array = $array_old = array();
  23. $array['name'] = filter_text_input( 'name', 'post', '' );
  24. $array['tname'] = filter_text_input( 'tname', 'post', '' );
  25. $array['casi'] = $nv_Request->get_int( 'casi', 'post', 0 );
  26. $array['casimoi'] = filter_text_input( 'casimoi', 'post', '' );
  27. $array['nhacsi'] = $nv_Request->get_int( 'nhacsi', 'post', 0 );
  28. $array['nhacsimoi'] = filter_text_input( 'nhacsimoi', 'post', '' );
  29. $array['theloai'] = $nv_Request->get_int( 'theloai', 'get,post', 0 );
  30. $array['duongdan'] = $nv_Request->get_string( 'duongdan', 'post', '' );
  31. $array['thumb'] = $nv_Request->get_string( 'thumb', 'post', '' );
  32. $array['listcat'] = $nv_Request->get_typed_array( 'listcat', 'post', 'int' );
  33. // Them ca si va nhac si moi
  34. if( $array['casimoi'] != '' )
  35. {
  36. $array['casi'] = newsinger( change_alias( $array['casimoi'] ), $array['casimoi'] );
  37. if( $array['casi'] === false )
  38. {
  39. $array['casi'] = 0;
  40. $error = $lang_module['error_add_new_singer'];
  41. }
  42. }
  43. if( $array['nhacsimoi'] != '' )
  44. {
  45. $array['nhacsi'] = newauthor( change_alias( $array['nhacsimoi'] ), $array['nhacsimoi'] );
  46. if( $array['nhacsi'] === false )
  47. {
  48. $array['nhacsi'] = 0;
  49. $error = $lang_module['error_add_new_author'];
  50. }
  51. }
  52. $category = get_videocategory();
  53. $allsinger = getallsinger();
  54. $allauthor = getallauthor();
  55. $setting = setting_music();
  56. $id = $nv_Request->get_int( 'id', 'get,post', 0 );
  57. if( $id == 0 )
  58. {
  59. $page_title = $lang_module['video_add'];
  60. }
  61. else
  62. {
  63. $page_title = $lang_module['video_edit'];
  64. $sql = "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_video` WHERE `id`=" . $id;
  65. $result = $db->sql_query( $sql );
  66. $numrow = $db->sql_numrows( $result );
  67. if( $numrow != 1 ) nv_info_die( $lang_global['error_404_title'], $lang_global['error_404_title'], $lang_global['error_404_content'] );
  68. $row = $db->sql_fetchrow( $result );
  69. // Thong tin cu
  70. $array_old['casi'] = $row['casi'];
  71. $array_old['nhacsi'] = $row['nhacsi'];
  72. $array_old['theloai'] = $row['theloai'];
  73. $array_old['listcat'] = $row['listcat'] ? explode( ",", $row['listcat'] ) : array();
  74. if( ! $nv_Request->get_int( 'edit', 'post', 0 ) == 1 )
  75. {
  76. $array['name'] = $row['name'];
  77. $array['tname'] = $row['tname'];
  78. $array['casi'] = $row['casi'];
  79. $array['nhacsi'] = $row['nhacsi'];
  80. $array['theloai'] = $row['theloai'];
  81. $array['thumb'] = $row['thumb'];
  82. $array['duongdan'] = admin_outputURL( $row['server'], $row['duongdan'] );
  83. $array['listcat'] = $row['listcat'];
  84. if( ! empty( $array['listcat'] ) )
  85. {
  86. $array['listcat'] = explode( ",", $array['listcat'] );
  87. }
  88. else
  89. {
  90. $array['listcat'] = array();
  91. }
  92. }
  93. }
  94. // Sua video
  95. if( $nv_Request->get_int( 'edit', 'post', 0 ) == 1 )
  96. {
  97. $error .= nv_check_ok_video( $array );
  98. if( empty( $error ) )
  99. {
  100. $result = $db->sql_query( "SELECT COUNT(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_video` WHERE `casi`=" . $array['casi'] . " AND `tname`=" . $db->dbescape( $array['tname'] ) . " AND `id`!=" . $id );
  101. list( $exist ) = $db->sql_fetchrow( $result );
  102. if( $exist )
  103. {
  104. $error = $lang_module['error_exist_video'];
  105. }
  106. }
  107. if( empty( $error ) )
  108. {
  109. $check_url = creatURL( $array['duongdan'] );
  110. $array['duongdan'] = $check_url['duongdan'];
  111. $array['server'] = $check_url['server'];
  112. $sql = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_video` SET
  113. `name`=" . $db->dbescape( $array['name'] ) . ",
  114. `tname`=" . $db->dbescape( $array['tname'] ) . ",
  115. `casi`=" . $array['casi'] . ",
  116. `nhacsi`=" . $array['nhacsi'] . ",
  117. `theloai`=" . $db->dbescape( $array['theloai'] ) . ",
  118. `listcat`=" . $db->dbescape( implode( ",", $array['listcat'] ) ) . ",
  119. `duongdan`=" . $db->dbescape( $array['duongdan'] ) . ",
  120. `thumb`=" . $db->dbescape( $array['thumb'] ) . ",
  121. `server`=" . $db->dbescape( $array['server'] ) . "
  122. WHERE `id`=" . $id;
  123. $check_update = $db->sql_query( $sql );
  124. if( $check_update )
  125. {
  126. // Cap nhat bai hat cho the loai
  127. // Xac dinh cac chu de cu
  128. $list_old_cat = $array_old['listcat'];
  129. $list_old_cat[] = $array_old['theloai'];
  130. $list_old_cat = array_unique( $list_old_cat );
  131. // Xac dinh chu de moi
  132. $list_new_cat = $array['listcat'];
  133. $list_new_cat[] = $array['theloai'];
  134. $list_new_cat = array_unique( $list_new_cat );
  135. $array_mul = array_diff( $list_new_cat, $list_old_cat );
  136. $array_div = array_diff( $list_old_cat, $list_new_cat );
  137. foreach( $array_mul as $_cid )
  138. {
  139. if( $_cid > 0 ) UpdateVideoCat( $_cid, '+1' );
  140. }
  141. foreach( $array_div as $_cid )
  142. {
  143. if( $_cid > 0 ) UpdateVideoCat( $_cid, '-1' );
  144. }
  145. // Cap nhat so video cua ca si
  146. if( $array_old['casi'] != $array['casi'] )
  147. {
  148. updatesinger( $array_old['casi'], 'numvideo', '-1' );
  149. updatesinger( $array['casi'], 'numvideo', '+1' );
  150. }
  151. // Cap nhat so video cua nhac si
  152. if( $array_old['nhacsi'] != $array['nhacsi'] )
  153. {
  154. updateauthor( $array_old['nhacsi'], 'numvideo', '-1' );
  155. updateauthor( $array['nhacsi'], 'numvideo', '+1' );
  156. }
  157. $db->sql_freeresult();
  158. nv_del_moduleCache( $module_name );
  159. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=videoclip" );
  160. die();
  161. }
  162. else
  163. {
  164. $error = $lang_module['error_save'];
  165. }
  166. }
  167. }
  168. // Them video moi
  169. if( $nv_Request->get_int( 'add', 'post', 0 ) == 1 )
  170. {
  171. $error .= nv_check_ok_video( $array );
  172. // Kiem tra video da co chua
  173. if( empty( $error ) )
  174. {
  175. $result = $db->sql_query( "SELECT COUNT(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_video` WHERE `casi`=" . $array['casi'] . " AND `tname`=" . $db->dbescape( $array['tname'] ) );
  176. list( $exist ) = $db->sql_fetchrow( $result );
  177. if( $exist )
  178. {
  179. $error = $lang_module['error_exist_video'];
  180. }
  181. }
  182. if( empty( $error ) )
  183. {
  184. $check_url = creatURL( $array['duongdan'] );
  185. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_video` VALUES (
  186. NULL,
  187. " . $db->dbescape( $array['name'] ) . ",
  188. " . $db->dbescape( $array['tname'] ) . ",
  189. " . $array['casi'] . ",
  190. " . $array['nhacsi'] . ",
  191. " . $db->dbescape( $array['theloai'] ) . ",
  192. " . $db->dbescape( implode( ",", $array['listcat'] ) ) . ",
  193. " . $db->dbescape( $check_url['duongdan'] ) . ",
  194. " . $db->dbescape( $array['thumb'] ) . " ,
  195. 0,
  196. 1,
  197. " . NV_CURRENTTIME . ",
  198. " . $check_url['server'] . ",
  199. 0,
  200. " . $db->dbescape( "0-" . NV_CURRENTTIME ) . "
  201. )";
  202. if( $db->sql_query_insert_id( $sql ) )
  203. {
  204. // Cap nhat bai hat cho the loai
  205. // Xac dinh chu de moi
  206. $list_new_cat = $array['listcat'];
  207. $list_new_cat[] = $array['theloai'];
  208. $list_new_cat = array_unique( $list_new_cat );
  209. foreach( $list_new_cat as $_cid )
  210. {
  211. if( $_cid > 0 ) UpdateVideoCat( $_cid, '+1' );
  212. }
  213. // Cap nhat so video cua ca si, nhac si
  214. updatesinger( $array['casi'], 'numvideo', '+1' );
  215. updateauthor( $array['nhacsi'], 'numvideo', '+1' );
  216. $db->sql_freeresult();
  217. nv_del_moduleCache( $module_name );
  218. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=videoclip" );
  219. die();
  220. }
  221. else
  222. {
  223. $error = $lang_module['error_save'];
  224. }
  225. }
  226. }
  227. // Hien bao loi
  228. if( $error )
  229. {
  230. $contents .= "<div class=\"quote\" style=\"width: 98%;\"><blockquote class=\"error\"><span>" . $error . "</span></blockquote></div><div class=\"clear\"></div>";
  231. }
  232. // Noi dung trang
  233. $contents .= "
  234. <form method=\"post\" name=\"add_pic\">
  235. <table class=\"tab1\">
  236. <thead>
  237. <tr>
  238. <td colspan=\"2\">
  239. " . $lang_module['video_info'] . "
  240. </td>
  241. </tr>
  242. </thead>
  243. <tbody>
  244. <tr>
  245. <td style=\"width: 150px; background: #eee;\">" . $lang_module['video_name'] . " </td>
  246. <td style=\"background: #eee;\">
  247. <input id=\"idtitle\" name=\"tname\" style=\"width: 470px;\" value=\"" . $array['tname'] . "\" type=\"text\"><img height=\"16\" alt=\"\" onclick=\"get_alias('idtitle','res_get_alias');\" style=\"cursor: pointer; vertical-align: middle;\" width=\"16\" src=\"" . NV_BASE_SITEURL . "images/refresh.png\">
  248. </td>
  249. </tr>
  250. <tr>
  251. <td style=\"width: 150px; background: #eee;\">" . $lang_module['video_name_short'] . "</td>
  252. <td style=\"background: #eee;\">
  253. <input id=\"idalias\" name=\"name\" style=\"width: 470px;\" value=\"" . $array['name'] . "\" type=\"text\" />
  254. </td>
  255. </tr>
  256. <tr>
  257. <td style=\"width: 150px; background: #eee;\">" . $lang_module['singer'] . "</td>
  258. <td style=\"background: #eee;\">
  259. <select name=\"casi\">\n";
  260. foreach( $allsinger as $key => $title )
  261. {
  262. $i = "";
  263. if( $array['casi'] == $key ) $i = "selected=\"selected\"";
  264. $contents .= "<option " . $i . " value=\"" . $key . "\" >" . $title . "</option>\n";
  265. }
  266. $contents .= "</select>
  267. </td>
  268. </tr>
  269. <tr>
  270. <td style=\"width: 150px; background: #eee;\">" . $lang_module['singer_new'] . "</td>
  271. <td style=\"background: #eee;\">
  272. <input id=\"singer_sortname\" name=\"casimoi\" style=\"width: 470px;\" type=\"text\" />
  273. </td>
  274. </tr>
  275. <tr>
  276. <td style=\"width: 150px; background: #eee;\">" . $lang_module['author'] . "</td>
  277. <td style=\"background: #eee;\">
  278. <select name=\"nhacsi\">\n";
  279. foreach( $allauthor as $key => $title )
  280. {
  281. $i = "";
  282. if( $array['nhacsi'] == $key ) $i = "selected=\"selected\"";
  283. $contents .= "<option " . $i . " value=\"" . $key . "\" >" . $title . "</option>\n";
  284. }
  285. $contents .= "</select>
  286. </td>
  287. </tr>
  288. <tr>
  289. <td style=\"width: 150px; background: #eee;\">" . $lang_module['author_new'] . "</td>
  290. <td style=\"background: #eee;\">
  291. <input id=\"singer_sortname\" name=\"nhacsimoi\" style=\"width: 470px;\" type=\"text\" />
  292. </td>
  293. </tr>
  294. <tr>
  295. <td style=\"width: 150px; background: #eee;\">" . $lang_module['category_base'] . "</td>
  296. <td style=\"background: #eee;\">
  297. <select name=\"theloai\">\n";
  298. foreach( $category as $key => $title )
  299. {
  300. $i = "";
  301. if( $array['theloai'] == $key ) $i = "selected=\"selected\"";
  302. $contents .= "<option " . $i . " value=\"" . $key . "\" >" . $title['title'] . "</option>\n";
  303. }
  304. $contents .= "</select>
  305. </td>
  306. </tr>
  307. <tr>
  308. <td style=\"width: 150px; background: #eee;\">
  309. " . $lang_module['category_sub'] . "
  310. </td>
  311. <td style=\"background: #eee;max-height:250px;overflow:auto\">";
  312. foreach( $category as $key => $title )
  313. {
  314. $checked = in_array( $key, $array['listcat'] ) ? " checked=\"checked\"" : "";
  315. $contents .= "<input name=\"listcat[]\" type=\"checkbox\"" . $checked . " value=\"" . $key . "\" />" . $title['title'] . "<br />\n";
  316. }
  317. $contents .= "
  318. </td>
  319. </tr>
  320. <tr>
  321. <td style=\"width: 150px; background: #eee;\">" . $lang_module['link'] . "</td>
  322. <td style=\"background: #eee;\">
  323. <input id=\"duongdan\" name=\"duongdan\" style=\"width: 370px;\" value=\"" . $array['duongdan'] . "\" type=\"text\" />
  324. <input name=\"selectvideo\" type=\"button\" value=\"" . $lang_module['select'] . "\" />
  325. <script type=\"text/javascript\">
  326. $(\"input[name=selectvideo]\").click(function()
  327. {
  328. var area = \"duongdan\"; // return value area
  329. var path = \"" . NV_UPLOADS_DIR . "/" . $module_name . "/" . $setting['root_contain'] . "/video\";
  330. 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' . "\");
  331. return false;
  332. });
  333. </script>
  334. </td>
  335. </tr>
  336. <tr>
  337. <td style=\"width: 150px; background: #eee;\">" . $lang_module['thumb'] . "</td>
  338. <td style=\"background: #eee;\">
  339. <input id=\"thumb\" name=\"thumb\" style=\"width: 370px;\" value=\"" . $array['thumb'] . "\" type=\"text\" readonly=\"readonly\"/>
  340. <input name=\"select\" type=\"button\" value=\"" . $lang_module['select'] . "\" />
  341. <script type=\"text/javascript\">
  342. $(\"input[name=select]\").click(function()
  343. {
  344. var area = \"thumb\"; // return value area
  345. var path = \"" . NV_UPLOADS_DIR . "/" . $module_name . "/clipthumb\";
  346. 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' . "\");
  347. return false;
  348. });
  349. </script>
  350. </td>
  351. </tr>
  352. <tr>
  353. <td colspan=\"2\" align=\"center\" style=\"background: #eee;\">\n
  354. <input name=\"confirm\" value=\"" . $lang_module['save'] . "\" type=\"submit\">\n";
  355. if( $id == 0 ) $contents .= "<input type=\"hidden\" name=\"add\" id=\"add\" value=\"1\">\n";
  356. else $contents .= "<input type=\"hidden\" name=\"edit\" id=\"edit\" value=\"1\">\n";
  357. $contents .= "<span name=\"notice\" style=\"float: right; padding-right: 50px; color: red; font-weight: bold;\"></span>\n
  358. </td>\n
  359. </tr>\n
  360. </tbody>\n
  361. </table>\n
  362. </form>\n";
  363. // Neu ten ngan gon video chua có thi tu dong tao ten
  364. if( empty( $array['ten'] ) )
  365. {
  366. $contents .= "<script type=\"text/javascript\">\n";
  367. $contents .= "$(\"#idtitle\").change(function () {
  368. get_alias('idtitle', 'res_get_alias');
  369. });";
  370. $contents .= "</script>\n";
  371. }
  372. include ( NV_ROOTDIR . "/includes/header.php" );
  373. echo nv_admin_theme( $contents );
  374. include ( NV_ROOTDIR . "/includes/footer.php" );
  375. ?>