/application/classes/Controller/Admin/Administration/Logs.php

https://bitbucket.org/chrispiechowicz/zepto · PHP · 102 lines · 77 code · 18 blank · 7 comment · 9 complexity · e33cbc3bfb1e1554d4f11559d09b3e6c MD5 · raw file

  1. <?php
  2. class Controller_Admin_Administration_Logs extends Controller_Admin_App
  3. {
  4. public function before()
  5. {
  6. parent::before();
  7. // check access
  8. $this->admin->access("administration/logs");
  9. // create unit
  10. $this->unit = new Admin_Unit(Config::get("admin#logs")->as_array());
  11. // add to breadcrumb
  12. Breadcrumb::add(Language::get("admin/units/unit.".$this->unit->name), Url::base().$this->unit->url);
  13. }
  14. public function action_index()
  15. {
  16. // create actionbar
  17. if ($this->admin->checkPermissions($this->unit->key, "deleteall"))
  18. $this->actionbar->add(array("link" => Url::base().$this->unit->url."deleteall", "title" => Language::get($this->unit->url."/label.deleteall"), "image" => "delete"));
  19. // create filter form
  20. $filterform = new Form(Url::base().$this->unit->url, "get");
  21. if ($this->unit->filterbar)
  22. {
  23. foreach ($this->unit->filterbar as $item)
  24. $filterform->add($item);
  25. }
  26. $this->filterbar->setForm($filterform->render("inline"));
  27. $this->filterbar->setClearLink(URL::base().$this->unit->url);
  28. // create pagination
  29. $pagination = Paginator::factory(array("items_per_page" => $this->unit->items_per_page, "show_sum" => TRUE, "show_label" => TRUE))->total($this->db->getSum($this->unit->table, $filterform->getFilter()));
  30. // create grid
  31. $rows = $this->db->getRows($this->unit->table, $filterform->getFilter(), Admin_Sort::get($this->unit->sort_fields, $this->unit->default_sort), $pagination->offset(), $this->unit->items_per_page);
  32. if ($rows)
  33. {
  34. $grid = new Admin_Grid($rows, array_merge(Config::get("lib#grid")->as_array(), array("grid_change" => $this->unit->grid_change, "grid_change_url" => $this->unit->grid_change_url)));
  35. foreach ($this->unit->grid as $item)
  36. {
  37. if($item["sort"])
  38. $item["title"] = Admin_Sort::link($item["key"], $this->unit->url, $item["title"], $this->unit->default_sort);
  39. $grid->add(array_merge(Config::get("lib#grid/row"), $item));
  40. }
  41. $grid = $grid->render();
  42. }
  43. else
  44. $grid = Language::get($this->unit->url."label.norows");
  45. $this->template->content = $this->actionbar->render().$this->filterbar->render().Notice::render().$grid.$pagination->render();
  46. }
  47. public function action_change()
  48. {
  49. if (Input::isPost($this->request))
  50. {
  51. if (Input::post("rows") && is_array(Input::post("rows")))
  52. {
  53. $rows = Input::post("rows");
  54. if (Input::post("delete_x"))
  55. {
  56. $this->admin->access($this->unit->key, "delete");
  57. foreach ($rows as $item)
  58. $this->db->delete($this->unit->table, array("id", "=", $item));
  59. Notice::add(Dlog::SUCCESS, Language::get($this->unit->url."/label.change_success"));
  60. }
  61. }
  62. }
  63. $this->redirect($this->unit->url);
  64. }
  65. public function action_deleteall()
  66. {
  67. $this->admin->access($this->unit->key, "deleteall");
  68. $this->db->delete($this->unit->table);
  69. Notice::add(Dlog::SUCCESS, Language::get($this->unit->url."/label.deleteall_success"));
  70. $this->redirect($this->unit->url);
  71. }
  72. public function action_info()
  73. {
  74. $this->admin->access($this->unit->key, "info");
  75. $id = $this->request->param("id");
  76. $row = $this->db->getRow($this->unit->table, array("id", "=", $id));
  77. if (!$row)
  78. $this->redirect($this->unit->url);
  79. Breadcrumb::add(Language::get($this->unit->url."/label.info"), Url::base().$this->unit->url."/info/".$id);
  80. $this->actionbar->add(array("link" => Url::base().$this->unit->url, "title" => Language::get($this->unit->url."/label.return"), "image" => "return"));
  81. $this->template->content = $this->actionbar->render().View::factory("admin/units/log", $row);
  82. }
  83. }
  84. ?>