PageRenderTime 24ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Quản lý website quảng cáo PHP/admin/content_news_m.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 264 lines | 234 code | 30 blank | 0 comment | 31 complexity | 02ebe2c0db09fc42a5aa72ec89d51b0e MD5 | raw file
  1. <script type="text/javascript" src="../jscripts/FCKeditor/fckeditor.js"></script>
  2. <script type="text/javascript">
  3. window.onload = function()
  4. {
  5. var oFCKeditor = new FCKeditor('txtshort') ;
  6. oFCKeditor.BasePath = "../jscripts/FCKeditor/" ;
  7. oFCKeditor.Width = "720" ;
  8. oFCKeditor.Height = "250" ;
  9. oFCKeditor.ReplaceTextarea() ;
  10. var oFCKeditor1 = new FCKeditor('txtlong') ;
  11. oFCKeditor1.BasePath = "../jscripts/FCKeditor/" ;
  12. oFCKeditor1.Width = "720" ;
  13. oFCKeditor1.Height = "400" ;
  14. oFCKeditor1.ReplaceTextarea() ;
  15. }
  16. </script>
  17. <? // Config
  18. $codeSelect = $multiLanguage == 0 ? "code='".$_lang."_news'" : "code='vn_news' or code='en_news'";
  19. $tableCategoryConfig = 'tbl_content_category';
  20. $tableConfig = 'tbl_content';
  21. $actConfig = 'news';
  22. $arraySourceCombo = getArrayCombo($tableCategoryConfig,'id','name',$codeSelect);
  23. ?>
  24. <?
  25. if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  26. echo '<script language="javascript" src="../lib/scripts/editor.js"></script>';
  27. else
  28. echo '<script language="javascript" src="../lib/scripts/moz/editor.js"></script>'?>
  29. <script language="javascript">
  30. function btnSave_onclick(){
  31. if(test_empty(document.frmForm.txtName.value)){
  32. alert('Hãy nhập "tên" !');
  33. document.frmForm.txtName.focus();
  34. return false;
  35. }
  36. if(test_integer(document.frmForm.txtSort.value)){
  37. alert('"Thứ tự sắp xếp" phải là số !');
  38. document.frmForm.txtSort.focus();
  39. return false;
  40. }
  41. return true;
  42. }
  43. </script>
  44. <? $errMsg =''?>
  45. <?
  46. $path = "../images/content";
  47. $pathdb = "images/content";
  48. if (isset($_POST['btnSave'])){
  49. $code = isset($_POST['txtCode']) ? trim($_POST['txtCode']) : '';
  50. $name = isset($_POST['txtName']) ? trim($_POST['txtName']) : '';
  51. $parent = $_POST['ddCat'];
  52. $subject = isset($_POST['txtSubject']) ? trim($_POST['txtSubject']) : '';
  53. $detail_short = isset($_POST['txtshort']) ? trim($_POST['txtshort']) : '';
  54. $detail = isset($_POST['txtlong']) ? trim($_POST['txtlong']) : '';
  55. $sort = isset($_POST['txtSort']) ? trim($_POST['txtSort']) : 0;
  56. $status = $_POST['chkStatus']!='' ? 1 : 0;
  57. $catInfo = getRecord($tableCategoryConfig, 'id='.$parent);
  58. $lang = $catInfo['lang'];
  59. if ($name=="") $errMsg .= "Hãy nhập tên danh mục !<br>";
  60. $errMsg .= checkUpload($_FILES["txtImage"],".jpg;.gif;.bmp",500*1024,0);
  61. $errMsg .= checkUpload($_FILES["txtImageLarge"],".jpg;.gif;.bmp",1024*1024,0);
  62. if ($errMsg==''){
  63. if (!empty($_POST['id'])){
  64. $oldid = $_POST['id'];
  65. $sql = "update ".$tableConfig." set code='".$code."',name='".$name."', parent='".$parent."',subject='".$subject."',detail_short='".$detail_short."',detail='".$detail."', sort='".$sort."', status='".$status."',last_modified=now(), lang='".$lang."' where id='".$oldid."'";
  66. }else{
  67. $sql = "insert into ".$tableConfig." (code, name, parent, subject, detail_short, detail, sort, status, date_added, last_modified, lang) values ('".$code."','".$name."','".$parent."','".$subject."','".$detail_short."','".$detail."','".$sort."','".$status."',now(),now(),'".$lang."')";
  68. }
  69. if (mysql_query($sql,$conn)){
  70. if(empty($_POST['id'])) $oldid = mysql_insert_id();
  71. $r = getRecord($tableConfig,"id=".$oldid);
  72. $sqlUpdateField = "";
  73. if ($_POST['chkClearImg']==''){
  74. $extsmall=getFileExtention($_FILES['txtImage']['name']);
  75. if (makeUpload($_FILES['txtImage'],"$path/".$actConfig."_s".$oldid.$extsmall)){
  76. @chmod("$path/".$actConfig."_s".$oldid.$extsmall, 0777);
  77. $sqlUpdateField = " image='$pathdb/".$actConfig."_s".$oldid.$extsmall."' ";
  78. }
  79. }else{
  80. if(file_exists('../'.$r['image'])) @unlink('../'.$r['image']);
  81. $sqlUpdateField = " image='' ";
  82. }
  83. if ($_POST['chkClearImgLarge']==''){
  84. $extlarge=getFileExtention($_FILES['txtImageLarge']['name']);
  85. if (makeUpload($_FILES['txtImageLarge'],"$path/".$actConfig."_l".$oldid.$extlarge)){
  86. @chmod("$path/".$actConfig."_l".$oldid.$extlarge, 0777);
  87. if($sqlUpdateField != "") $sqlUpdateField .= ",";
  88. $sqlUpdateField .= " image_large='$pathdb/".$actConfig."_l".$oldid.$extlarge."' ";
  89. }
  90. }else{
  91. if(file_exists('../'.$r['image_large'])) @unlink('../'.$r['image_large']);
  92. if($sqlUpdateField != "") $sqlUpdateField .= ",";
  93. $sqlUpdateField .= " image_large='' ";
  94. }
  95. if($sqlUpdateField!='') {
  96. $sqlUpdate = "update ".$tableConfig." set $sqlUpdateField where id='".$oldid."'";
  97. mysql_query($sqlUpdate,$conn);
  98. }
  99. }else{
  100. $errMsg = "Không thể cập nhật !";
  101. }
  102. }
  103. if ($errMsg == '')
  104. echo '<script>window.location="./?act='.$actConfig.'&cat='.$_REQUEST['cat'].'&page='.$_REQUEST['page'].'&code=1"</script>';
  105. }else{
  106. if (isset($_GET['id'])){
  107. $oldid=$_GET['id'];
  108. $page = $_GET['page'];
  109. $sql = "select * from ".$tableConfig." where id='".$oldid."'";
  110. if ($result = mysql_query($sql,$conn)) {
  111. $row=mysql_fetch_array($result);
  112. $code = $row['code'];
  113. $name = $row['name'];
  114. $parent = $row['parent'];
  115. $subject = $row['subject'];
  116. $detail_short = $row['detail_short'];
  117. $detail = $row['detail'];
  118. $image = $row['image'];
  119. $image_large = $row['image_large'];
  120. $sort = $row['sort'];
  121. $status = $row['status'];
  122. $date_added = $row['date_added'];
  123. $last_modified = $row['last_modified'];
  124. }
  125. }
  126. }
  127. ?>
  128. <form method="post" name="frmForm" enctype="multipart/form-data" action="./">
  129. <input type="hidden" name="txtSubject" id="txtSubject">
  130. <input type="hidden" name="txtDetailShort" id="txtDetailShort">
  131. <input type="hidden" name="txtDetail" id="txtDetail">
  132. <input type="hidden" name="act" value="<?=$actConfig?>_m">
  133. <input type="hidden" name="id" value="<?=$_REQUEST['id']?>">
  134. <input type="hidden" name="page" value="<?=$_REQUEST['page']?>">
  135. <table border="1" cellpadding="0" cellspacing="0" bordercolor="#0069A8" width="100%">
  136. <tr>
  137. <td width="45%">
  138. <table border="0" cellpadding="2" bordercolor="#111111" width="100%" cellspacing="0">
  139. <tr><td height="10"></td></tr>
  140. <tr>
  141. <td colspan="3" align="center">
  142. <table width="100%">
  143. <? if($image!='' || $image_large!=''){?>
  144. <tr>
  145. <td width="15%"></td>
  146. <td width="40%" align="center" class="smallfont">
  147. <? if ($image!=''){ echo '<img border="0" src="../'.$image.'" width="100"><br><br>Hình (kích thước nhỏ)';}?>
  148. </td>
  149. <td width="40%" align="center" class="smallfont">
  150. <? if ($image_large!=''){ echo '<img border="0" src="../'.$image_large.'" width="100"><br><br>Hình (kích thước lớn)';}?>
  151. </td>
  152. <td width="15%"></td>
  153. </tr>
  154. <? }else{echo '<tr><td colspan="3" class="smallfont" align="center">Chưa có hình ảnh !</td></tr>';}?>
  155. <tr><td colspan="4" height="10"></td></tr>
  156. <tr><td colspan="4" height="1" bgcolor="#999999"></td></tr>
  157. <tr><td colspan="4" height="10"></td></tr>
  158. </table>
  159. </td>
  160. </tr>
  161. <tr>
  162. <td width="15%" class="smallfont" align="right">Tên tin t&#7913;c </td>
  163. <td width="1%" class="smallfont" align="center"><font color="#FF0000">*</font></td>
  164. <td width="83%" class="smallfont">
  165. <input value="<?=$name?>" type="text" name="txtName" class="textbox" size="34">
  166. </td>
  167. </tr>
  168. <tr>
  169. <td width="15%" class="smallfont" align="right">Hình ( nhỏ)</td>
  170. <td width="1%" class="smallfont" align="center"></td>
  171. <td width="83%" class="smallfont">
  172. <input type="file" name="txtImage" class="textbox" size="34">
  173. <input type="checkbox" name="chkClearImg" value="on">
  174. Xóa bỏ hình ảnh
  175. (width =132 height =97 )(jpg,gif,bmp)</td>
  176. </tr>
  177. <tr>
  178. <td width="15%" class="smallfont" align="right">Hình ( lớn)</td>
  179. <td width="1%" class="smallfont" align="center"></td>
  180. <td width="83%" class="smallfont">
  181. <input type="file" name="txtImageLarge" class="textbox" size="34">
  182. <input type="checkbox" name="chkClearImgLarge" value="on">
  183. Xóa bỏ hình ảnh
  184. (width =200 height =180)(jpg,gif,bmp)</td>
  185. </tr>
  186. <tr>
  187. <td width="15%" class="smallfont" align="right"> tả ngắn</td>
  188. <td width="1%" class="smallfont" align="center"></td>
  189. <td width="83%" class="smallfont">
  190. <textarea name="txtshort" cols="80" rows="10" id="txtshort"><?=$detail_short?></textarea>
  191. </td>
  192. </tr>
  193. <tr>
  194. <td width="15%" class="smallfont" align="right">Thông tin chi tiết</td>
  195. <td width="1%" class="smallfont" align="center"></td>
  196. <td width="83%" class="smallfont">
  197. <textarea name="txtlong" cols="80" rows="10" id="txtlong"><?=$detail?></textarea>
  198. </td>
  199. </tr>
  200. <tr>
  201. <td width="15%" class="smallfont" align="right">Thuộc danh mục</td>
  202. <td width="1%" class="smallfont" align="center"></td>
  203. <td width="83%" class="smallfont">
  204. <?=comboCategory('ddCat',$arraySourceCombo,'smallfont',$parent,0)?>
  205. </td>
  206. </tr>
  207. <tr>
  208. <td width="15%" class="smallfont" align="right">Thứ tự sắp xếp</td>
  209. <td width="1%" class="smallfont" align="right"></td>
  210. <td width="83%" class="smallfont">
  211. <input value="<?=$sort?>" type="text" name="txtSort" class="textbox" size="34">
  212. </td>
  213. </tr>
  214. <tr>
  215. <td width="15%" class="smallfont" align="right">Không hiển thị</td>
  216. <td width="1%" class="smallfont" align="center"></td>
  217. <td width="83%" class="smallfont">
  218. <input type="checkbox" name="chkStatus" value="on" <? if ($status>0) echo 'checked' ?>>
  219. </td>
  220. </tr>
  221. <tr>
  222. <td width="15%" class="smallfont"></td>
  223. <td width="1%" class="smallfont" align="center"></td>
  224. <td width="83%" class="smallfont">
  225. <input type="submit" name="btnSave" VALUE="Cập nhật" class=button onclick="return btnSave_onclick()">
  226. <input type="reset" class=button value="Nhập lại">
  227. </td>
  228. </tr>
  229. </table>
  230. </td>
  231. </tr>
  232. </table>
  233. </form>
  234. <? if($errMsg!=''){echo '<p align=center class="err">'.$errMsg.'<br></p>';}?>