admin_boxes_model.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. class admin_boxes_model extends Model {
  3. public function getBoxes() {
  4. $result = $this->query("select * from azonics_boxes where box_status<>'0';");
  5. return $result;
  6. }
  7. public function loadBox() {
  8. $box_id = $this->escapeString($_REQUEST['id']);
  9. $row = $this->query("select * from azonics_boxes where box_id='".$box_id."';");
  10. return $row[0];
  11. }
  12. public function saveBox() {
  13. $data = $this->escapeArray($_REQUEST);
  14. if ($data['box_id']!='') {
  15. if ($_FILES['box_banner']['tmp_name']!=='') {
  16. $fname = 'banner_'.time().'.jpg';
  17. $path = 'static/uploads/thumbs/';
  18. move_uploaded_file($_FILES['box_banner']['tmp_name'],$path.$fname);
  19. $this->execute("UPDATE azonics_boxes SET box_banner='".$path.$fname."' WHERE box_id='".$data['box_id']."';");
  20. }
  21. $this->execute("update azonics_boxes set "
  22. . "box_title='".$data['box_title']."', "
  23. . "box_subtitle='".$data['box_subtitle']."', "
  24. . "box_subtitle_en='".$data['box_subtitle_en']."', "
  25. . "box_button_text='".$data['box_button_text']."', "
  26. . "box_url='".$data['box_url']."' "
  27. . "where box_id='".$data['box_id']."';");
  28. return true;
  29. }
  30. else {
  31. if ($_FILES['box_banner']['tmp_name']!=='') {
  32. $fname = 'banner_'.time().'.jpg';
  33. $path = 'static/uploads/thumbs/';
  34. move_uploaded_file($_FILES['box_banner']['tmp_name'],$path.$fname);
  35. }
  36. $this->execute("insert into azonics_boxes set "
  37. . "box_title='".$data['box_title']."', "
  38. . "box_subtitle='".$data['box_subtitle']."', "
  39. . "box_subtitle_en='".$data['box_subtitle_en']."', "
  40. . "box_button_text='".$data['box_button_text']."', "
  41. . "box_url='".$data['box_url']."', "
  42. . "box_status='1', box_banner='".$path.$fname."', "
  43. . "box_user='".$_SESSION['admin_user']->admin_id."';");
  44. return true;
  45. }
  46. }
  47. public function deleteBox() {
  48. $box_id = $this->escapeString($_REQUEST['id']);
  49. $this->execute("update azonics_boxes set box_status='0' where box_id='".$box_id."';");
  50. return true;
  51. }
  52. }