PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website bán phụ tùng oto PHP/modules/editnews.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 396 lines | 381 code | 12 blank | 3 comment | 106 complexity | b1b9beb07a6f9786fcc7fcfa67a4d442 MD5 | raw file
  1. <?php
  2. if($_SESSION['id_user']) {
  3. $tpl=new TemplatePower("template/editnews.htm");
  4. $tpl->prepare();
  5. require ("lib/upload.php");
  6. require ("lib/imaging.php");
  7. if($_GET['id']){
  8. // load database
  9. $id=intval($_GET['id']);
  10. $sql="SELECT * FROM raovat WHERE id_raovat=$id";
  11. $db=$DB->query($sql);
  12. if($rs=mysql_fetch_array($db)){
  13. $tpl->assign("name",$rs['name']);
  14. $tpl->assign("price",$rs['price']);
  15. $tpl->assign("don_vi",$rs['don_vi']);
  16. $tpl->assign("title",$rs['title']);
  17. $tpl->assign("intro",$rs['intro']);
  18. $tpl->assign("content",$rs['content']);
  19. if ($rs['small_image']){
  20. if ($rs['small_image'] && file_exists($CONFIG['upload_image_path'].$rs['small_image'])){
  21. $tpl->assign("image","<img hspace='5' vspace='5' src='".$CONFIG['upload_image_path'].$rs['small_image']."' border='0' ><br><input type='checkbox' name='xoa_anh' value='1' class='noborder'>&nbsp;X&#243;a &#7843;nh<br>");
  22. }
  23. }
  24. if($_SESSION['vip']==1){
  25. $tpl->newBlock("vip");
  26. if ($rs['small_image4']){
  27. if ($rs['small_image4'] && file_exists($CONFIG['upload_image_path'].$rs['small_image4'])){
  28. $tpl->assign("image4","<img hspace='5' vspace='5' src='".$CONFIG['upload_image_path'].$rs['small_image4']."' border='0' ><br><input type='checkbox' name='xoa_anh4' value='1' class='noborder'>&nbsp;X&#243;a &#7843;nh<br>");
  29. }
  30. }
  31. if ($rs['small_image1']){
  32. if ($rs['small_image1'] && file_exists($CONFIG['upload_image_path'].$rs['small_image1'])){
  33. $tpl->assign("image1","<img hspace='5' vspace='5' src='".$CONFIG['upload_image_path'].$rs['small_image1']."' border='0' ><br><input type='checkbox' name='xoa_anh1' value='1' class='noborder'>&nbsp;X&#243;a &#7843;nh<br>");
  34. }
  35. }
  36. if ($rs['small_image2']){
  37. if ($rs['small_image2'] && file_exists($CONFIG['upload_image_path'].$rs['small_image2'])){
  38. $tpl->assign("image2","<img hspace='5' vspace='5' src='".$CONFIG['upload_image_path'].$rs['small_image2']."' border='0' ><br><input type='checkbox' name='xoa_anh2' value='1' class='noborder'>&nbsp;X&#243;a &#7843;nh<br>");
  39. }
  40. }
  41. if ($rs['small_image3']){
  42. if ($rs['small_image3'] && file_exists($CONFIG['upload_image_path'].$rs['small_image3'])){
  43. $tpl->assign("image3","<img hspace='5' vspace='5' src='".$CONFIG['upload_image_path'].$rs['small_image3']."' border='0' ><br><input type='checkbox' name='xoa_anh3' value='1' class='noborder'>&nbsp;X&#243;a &#7843;nh<br>");
  44. }
  45. }
  46. }
  47. $sql1="SELECT * FROM catrv WHERE active=1 ORDER BY thu_tu ASC, name ASC";
  48. $db1=$DB->query($sql1);
  49. while($rs1=mysql_fetch_array($db1)){
  50. $tpl->newBlock("category");
  51. if($rs1['id_catrv']==$rs['id_catrv']) $tpl->assign("selected","selected");
  52. $tpl->assign("id_cat",$rs1['id_catrv']);
  53. $tpl->assign("cat_name",$rs1['name']);
  54. }
  55. $sql1="SELECT * FROM ttlienhe WHERE id_raovat='".$rs['id_raovat']."'";
  56. $db1=$DB->query($sql1);
  57. if($rs1=mysql_fetch_array($db1)){
  58. $tpl->newBlock("thongtinlienhe");
  59. $tpl->assign("thongtinkhac",$rs1['ttlienhe']);
  60. }
  61. }
  62. // update database
  63. if($_POST['name']!='' && $_POST['gone']==1){
  64. $a=array();
  65. $a['name'] =compile_post('name');
  66. $a['price'] =compile_post('price');
  67. $a['don_vi'] =compile_post('don_vi');
  68. $a['title'] =compile_post('title');
  69. $a['intro'] =compile_post('intro');
  70. $a['id_catrv'] =compile_post('id_catrv');
  71. $a['content'] =compile_post('content');
  72. $a['id_user'] =0;
  73. $a['id_user_post']=intval($_SESSION['id_user']);
  74. if($_POST['xoa_anh']==1){
  75. $sql="select * from raovat where id_raovat=".$id;
  76. $x=$DB->query($sql);
  77. if ($y=mysql_fetch_array($x))
  78. {
  79. $lastfile=$y['image'];
  80. $lastnormal=$y['normal_image'];
  81. $lastsmall=$y['small_image'];
  82. if ($lastfile||$lastnormal||$lastsmall)
  83. {
  84. if ($lastfile && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile))
  85. {
  86. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile);
  87. }
  88. if ($lastnormal && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastnormal))
  89. {
  90. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastnormal);
  91. }
  92. if ($lastsmall && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall))
  93. {
  94. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall);
  95. }
  96. }
  97. }
  98. $a['image']='';
  99. $a['normal_image']='';
  100. $a['small_image']='';
  101. }
  102. if($_POST['xoa_anh1']==1){
  103. $sql="select * from raovat where id_raovat=".$id;
  104. $x=$DB->query($sql);
  105. if ($y=mysql_fetch_array($x))
  106. {
  107. $lastfile=$y['image1'];
  108. $lastsmall=$y['small_image1'];
  109. if ($lastfile||$lastsmall)
  110. {
  111. if ($lastfile && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile))
  112. {
  113. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile);
  114. }
  115. if ($lastsmall && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall))
  116. {
  117. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall);
  118. }
  119. }
  120. }
  121. $a['image1']='';
  122. $a['small_image1']='';
  123. }
  124. if($_POST['xoa_anh2']==1){
  125. $sql="select * from raovat where id_raovat=".$id;
  126. $x=$DB->query($sql);
  127. if ($y=mysql_fetch_array($x))
  128. {
  129. $lastfile=$y['image2'];
  130. $lastsmall=$y['small_image2'];
  131. if ($lastfile||$lastsmall)
  132. {
  133. if ($lastfile && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile))
  134. {
  135. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile);
  136. }
  137. if ($lastsmall && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall))
  138. {
  139. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall);
  140. }
  141. }
  142. }
  143. $a['image2']='';
  144. $a['small_image2']='';
  145. }
  146. if($_POST['xoa_anh3']==1){
  147. $sql="select * from raovat where id_raovat=".$id;
  148. $x=$DB->query($sql);
  149. if ($y=mysql_fetch_array($x))
  150. {
  151. $lastfile=$y['image3'];
  152. $lastsmall=$y['small_image3'];
  153. if ($lastfile||$lastsmall)
  154. {
  155. if ($lastfile && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile))
  156. {
  157. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile);
  158. }
  159. if ($lastsmall && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall))
  160. {
  161. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall);
  162. }
  163. }
  164. }
  165. $a['image3']='';
  166. $a['small_image3']='';
  167. }
  168. if($_POST['xoa_anh4']==1){
  169. $sql="select * from raovat where id_raovat=".$id;
  170. $x=$DB->query($sql);
  171. if ($y=mysql_fetch_array($x))
  172. {
  173. $lastfile=$y['image4'];
  174. $lastsmall=$y['small_image4'];
  175. if ($lastfile||$lastsmall)
  176. {
  177. if ($lastfile && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile))
  178. {
  179. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile);
  180. }
  181. if ($lastsmall && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall))
  182. {
  183. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall);
  184. }
  185. }
  186. }
  187. $a['image4']='';
  188. $a['small_image4']='';
  189. }
  190. $sql="select * from raovat where id_raovat=".$id;
  191. $x=$DB->query($sql);
  192. if ($y=mysql_fetch_array($x)){
  193. $lastfile=$y['image'];
  194. $lastnormal=$y['normal_image'];
  195. $lastsmall=$y['small_image'];
  196. $lastfile1=$y['image1'];
  197. $lastsmall1=$y['small_image1'];
  198. $lastfile2=$y['image2'];
  199. $lastsmall2=$y['small_image2'];
  200. $lastfile3=$y['image3'];
  201. $lastsmall3=$y['small_image3'];
  202. $lastfile4=$y['image4'];
  203. $lastsmall4=$y['small_image4'];
  204. }
  205. if ($_FILES['image']['size'])
  206. {
  207. if ($lastfile||$lastnormal||$lastsmall)
  208. {
  209. if ($lastfile && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile))
  210. {
  211. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile);
  212. }
  213. if ($lastnormal && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastnormal))
  214. {
  215. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastnormal);
  216. }
  217. if ($lastsmall && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall))
  218. {
  219. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall);
  220. }
  221. }
  222. $in_image=get_new_file_name($_FILES['image']['name'],"raovat_");
  223. $file_upload=new Upload($CONFIG['root_path'].$CONFIG['upload_image_path'],'jpg,gif,png,bmp');
  224. if ($file_upload->upload_file('image',2,$in_image))
  225. {
  226. $a['image']=$file_upload->file_name;
  227. $thumbnail=create_thumb($CONFIG['root_path'].$CONFIG['upload_image_path'], $file_upload->file_name);
  228. if ($thumbnail){
  229. $a['small_image']=$thumbnail['thumb'];
  230. $a['normal_image']=$thumbnail['normal'];
  231. }else{
  232. $msg.="Kh&#244;ng t&#7841;o &#273;&#432;&#7907;c &#7843;nh thumbnail ! Xem l&#7841;i &#273;&#7883;nh d&#7841;ng file !<br>";
  233. }
  234. }else{
  235. $msg.=$file_upload->get_upload_errors()."<br>";
  236. }
  237. }
  238. if ($_FILES['image1']['size'])
  239. {
  240. if ($lastfile1||$lastsmall1)
  241. {
  242. if ($lastfile1 && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile1))
  243. {
  244. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile1);
  245. }
  246. if ($lastsmall1 && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall1))
  247. {
  248. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall1);
  249. }
  250. }
  251. $in_image=get_new_file_name($_FILES['image1']['name'],"raovat_");
  252. $file_upload=new Upload($CONFIG['root_path'].$CONFIG['upload_image_path'],'jpg,gif,png,bmp');
  253. if ($file_upload->upload_file('image1',2,$in_image))
  254. {
  255. $a['image1']=$file_upload->file_name;
  256. $thumbnail=create_thumb($CONFIG['root_path'].$CONFIG['upload_image_path'], $file_upload->file_name);
  257. if ($thumbnail){
  258. $a['small_image1']=$thumbnail['thumb'];
  259. }else{
  260. $msg.="Kh&#244;ng t&#7841;o &#273;&#432;&#7907;c &#7843;nh thumbnail ! Xem l&#7841;i &#273;&#7883;nh d&#7841;ng file !<br>";
  261. }
  262. }else{
  263. $msg.=$file_upload->get_upload_errors()."<br>";
  264. }
  265. }
  266. if ($_FILES['image2']['size'])
  267. {
  268. if ($lastfile2||$lastsmall2)
  269. {
  270. if ($lastfile2 && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile2))
  271. {
  272. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile2);
  273. }
  274. if ($lastsmall2 && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall2))
  275. {
  276. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall2);
  277. }
  278. }
  279. $in_image=get_new_file_name($_FILES['image2']['name'],"raovat_");
  280. $file_upload=new Upload($CONFIG['root_path'].$CONFIG['upload_image_path'],'jpg,gif,png,bmp');
  281. if ($file_upload->upload_file('image2',2,$in_image))
  282. {
  283. $a['image2']=$file_upload->file_name;
  284. $thumbnail=create_thumb($CONFIG['root_path'].$CONFIG['upload_image_path'], $file_upload->file_name);
  285. if ($thumbnail){
  286. $a['small_image2']=$thumbnail['thumb'];
  287. }else{
  288. $msg.="Kh&#244;ng t&#7841;o &#273;&#432;&#7907;c &#7843;nh thumbnail ! Xem l&#7841;i &#273;&#7883;nh d&#7841;ng file !<br>";
  289. }
  290. }else{
  291. $msg.=$file_upload->get_upload_errors()."<br>";
  292. }
  293. }
  294. if ($_FILES['image3']['size'])
  295. {
  296. if ($lastfile3||$lastsmall3)
  297. {
  298. if ($lastfile3 && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile3))
  299. {
  300. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile3);
  301. }
  302. if ($lastsmall3 && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall3))
  303. {
  304. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall3);
  305. }
  306. }
  307. $in_image=get_new_file_name($_FILES['image3']['name'],"raovat_");
  308. $file_upload=new Upload($CONFIG['root_path'].$CONFIG['upload_image_path'],'jpg,gif,png,bmp');
  309. if ($file_upload->upload_file('image3',2,$in_image))
  310. {
  311. $a['image3']=$file_upload->file_name;
  312. $thumbnail=create_thumb($CONFIG['root_path'].$CONFIG['upload_image_path'], $file_upload->file_name);
  313. if ($thumbnail){
  314. $a['small_image3']=$thumbnail['thumb'];
  315. }else{
  316. $msg.="Kh&#244;ng t&#7841;o &#273;&#432;&#7907;c &#7843;nh thumbnail ! Xem l&#7841;i &#273;&#7883;nh d&#7841;ng file !<br>";
  317. }
  318. }else{
  319. $msg.=$file_upload->get_upload_errors()."<br>";
  320. }
  321. }
  322. if ($_FILES['image4']['size'])
  323. {
  324. if ($lastfile4||$lastsmall4)
  325. {
  326. if ($lastfile4 && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile4))
  327. {
  328. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastfile4);
  329. }
  330. if ($lastsmall4 && file_exists($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall4))
  331. {
  332. unlink($CONFIG['root_path'].$CONFIG['upload_image_path'].$lastsmall4);
  333. }
  334. }
  335. $in_image=get_new_file_name($_FILES['image4']['name'],"raovat_");
  336. $file_upload=new Upload($CONFIG['root_path'].$CONFIG['upload_image_path'],'jpg,gif,png,bmp');
  337. if ($file_upload->upload_file('image4',2,$in_image))
  338. {
  339. $a['image4']=$file_upload->file_name;
  340. $thumbnail=create_thumb($CONFIG['root_path'].$CONFIG['upload_image_path'], $file_upload->file_name);
  341. if ($thumbnail){
  342. $a['small_image4']=$thumbnail['thumb'];
  343. }else{
  344. $msg.="Kh&#244;ng t&#7841;o &#273;&#432;&#7907;c &#7843;nh thumbnail ! Xem l&#7841;i &#273;&#7883;nh d&#7841;ng file !<br>";
  345. }
  346. }else{
  347. $msg.=$file_upload->get_upload_errors()."<br>";
  348. }
  349. }
  350. $b=$DB->compile_db_update_string($a);
  351. $sql="UPDATE raovat SET ".$b." WHERE id_raovat=".$id;
  352. $DB->query($sql);
  353. $msg="&#272;&#227; &#273;&#259;ng tin th&#224;nh c&#244;ng!";
  354. if($_POST['radioother']==1){
  355. $sqlx="SELECT * FROM ttlienhe WHERE id_raovat=".$id;
  356. $dbx=$DB->query($sqlx);
  357. if($rsx=mysql_fetch_array($dbx)){
  358. $c=array();
  359. $idinsert=mysql_insert_id();
  360. $c['ttlienhe'] =compile_post('thongtinkhac');
  361. // $c['id_raovat'] =$idinsert;
  362. $d=$DB->compile_db_update_string($c);
  363. $sql="UPDATE ttlienhe SET ".$d." WHERE id_raovat=".$id;
  364. $DB->query($sql);
  365. }else {
  366. $c=array();
  367. $idinsert=mysql_insert_id();
  368. $c['ttlienhe'] =compile_post('thongtinkhac');
  369. $c['id_raovat'] =$id;
  370. $b=$DB->compile_db_insert_string($c);
  371. $sql="INSERT INTO ttlienhe (".$b['FIELD_NAMES'].") VALUES (".$b['FIELD_VALUES'].")";
  372. $DB->query($sql);
  373. }
  374. }
  375. $referbox("?page=list_news","&#272;&#227; s&#7917;a th&#224;nh c&#244;ng !");
  376. }
  377. }
  378. if($msg!=''){
  379. $tpl->newBlock("msg");
  380. $tpl->assign("msg",$msg);
  381. }
  382. }
  383. $tpl->printToScreen();
  384. ?>