summaryrefslogtreecommitdiffstats
path: root/application/modules/backend/controllers/MenuController.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/modules/backend/controllers/MenuController.php')
-rw-r--r--application/modules/backend/controllers/MenuController.php210
1 files changed, 210 insertions, 0 deletions
diff --git a/application/modules/backend/controllers/MenuController.php b/application/modules/backend/controllers/MenuController.php
new file mode 100644
index 0000000..f8c6a7f
--- /dev/null
+++ b/application/modules/backend/controllers/MenuController.php
@@ -0,0 +1,210 @@
+<?php
+
+class Backend_MenuController extends Zend_Controller_Action
+{
+ private $_mmenus;
+ private $_mmenu_entries;
+ private $_mmenu_assignments;
+ private $_mmenu_assignment_iprules;
+ private $_mmenu_assignment_bmrules;
+
+ private $_logger;
+
+ public function init()
+ {
+ $this->_helper->layout->disableLayout();
+ #$this->_helper->viewRenderer->setNoRender();
+
+ $this->_mmenus = new Model_Menus();
+ $this->_mmenu_entries = new Model_Menuentries();
+ $this->_mmenu_assignments = new Model_Menuassignments();
+ $this->_mmenu_assignment_iprules = new Model_Menuassignmentip();
+ $this->_mmenu_assignment_bmrules = new Model_Menuassignmentbm();
+
+
+ $this->_logger = new Zend_Log();
+ $w = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../data/debug.log');
+
+ $this->_logger->addWriter($w);
+ }
+
+ public function indexAction()
+ {
+ // action body
+ }
+
+ public function listentriesAction()
+ {
+ $mid = $this->getRequest()->getParam('id');
+ $s = $this->_mmenu_entries->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
+ $s->setIntegrityCheck(false)
+ ->where('menu_id = ?', $mid)
+ ->joinLeft(array('s' => 'systems'), 's.id = menu_entries.system_id',
+ array('s_name' => 'name',
+ 's_external_id' => 'external_id',
+ 's_source' => 'source'))
+ ->order('entry_order');
+ $data = $this->_mmenu_entries->fetchAll($s)->toArray();
+ $this->view->listdata = $data;
+ }
+
+ public function listAction()
+ {
+ $data = $this->_mmenus->fetchAll()->toArray();
+ $this->view->listdata = $data;
+ }
+
+ public function addAction()
+ {
+ $this->_helper->viewRenderer->setNoRender();
+ $name = $this->getRequest()->getParam("name");
+ $description = $this->getRequest()->getParam("description");
+
+ #TODO: make themes selectable
+ $db_data = array(
+ "name" => $name,
+ "description" => $description,
+ "theme" => "openslx"
+ );
+
+ $this->_mmenus->insert($db_data);
+
+ }
+
+ public function delAction()
+ {
+ $this->_helper->viewRenderer->setNoRender();
+
+ $id = $this->getRequest()->getParam("id");
+
+ $w = $this->_mmenus->getAdapter()->quoteInto('id = ?', $id);
+ $this->_mmenus->delete($w);
+
+ $w = $this->_mmenu_entries->getAdapter()->quoteInto('menu_id = ?', $id);
+ $this->_mmenu_entries->delete($w);
+
+ }
+
+ public function addentryAction()
+ {
+ $this->_helper->viewRenderer->setNoRender();
+
+ $menu = $this->getRequest()->getParam("menu");
+ $system = $this->getRequest()->getParam("system");
+ $altCaptionSet = $this->getRequest()->getParam("altCaptionSet");
+ $altCaption = ($altCaptionSet) ? $this->getRequest()->getParam("altCaption") : null;
+ $altAppendSet = $this->getRequest()->getParam("altAppendSet");
+ $altAppend = ($altAppendSet) ? $this->getRequest()->getParam("altAppend") : null;
+
+ $db_data = array(
+ "menu_id" => $menu,
+ "system_id" => $system,
+ "overwrite_caption" => $altCaptionSet,
+ "overwrite_append" => $altAppendSet,
+ "alternative_caption" => $altCaption,
+ "alternative_append" => $altAppend
+ );
+
+ $this->_mmenu_entries->insert($db_data);
+
+ }
+
+ public function saveentryorderAction() {
+ $this->_helper->viewRenderer->setNoRender();
+ $data = $this->getRequest()->getParam("data");
+
+ $data = explode(';', $data);
+ foreach ($data as $d) {
+ if (!empty($d)) {
+ list($id, $order) = explode(':', $d);
+ $db_data = array(
+ 'entry_order' => $order
+ );
+ $w = $this->_mmenu_entries->getAdapter()->quoteInto('id = ?', $id);
+ $this->_mmenu_entries->update($db_data, $w);
+ }
+ }
+
+ }
+
+ public function delentryAction()
+ {
+ $this->_helper->viewRenderer->setNoRender();
+
+ $id = $this->getRequest()->getParam("id");
+
+ $w = $this->_mmenu_entries->getAdapter()->quoteInto('id = ?', $id);
+ $this->_mmenu_entries->delete($w);
+ }
+
+ public function listassignmentsAction()
+ {
+ $l = $this->_logger;
+ $s = $this->_mmenu_assignments->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
+ $s->setIntegrityCheck(false)
+ ->joinLeft(array('m' => 'menus'), 'm.id = menu_assignments.menu_id',
+ array('m_name' => 'name'))
+ ->joinLeft(array('i' => 'menu_assignment_iprules'), 'i.menu_assignment_rule = menu_assignments.id',
+ array('i_ip' => 'ip',
+ 'i_netmask' => 'netmask'))
+ ->joinLeft(array('b' => 'menu_assignment_bmrules'), 'b.menu_assignment_rule = menu_assignments.id',
+ array('b_bootmedia_id' => 'bootmedia_id'))
+ ->joinLeft(array('bm' => 'bootmedia'), 'bm.id = b.bootmedia_id',
+ array('b_name' => 'name'))
+ ->order(array('menu_id', 'i_netmask', 'b_bootmedia'));
+ $l->info('[menucontroller] '. $s->assemble());
+ $data = $this->_mmenu_assignments->fetchAll($s)->toArray();
+ $this->view->listdata = $data;
+ }
+
+ public function addassignmentAction()
+ {
+ $this->_helper->viewRenderer->setNoRender();
+
+ $name = $this->getRequest()->getParam("name");
+ $menu = $this->getRequest()->getParam("menu");
+ $bootmedia = $this->getRequest()->getParam("bootmedia");
+ $ip = $this->getRequest()->getParam("ip");
+
+ if (empty($ip) || !strpos($ip, "/")) {
+ $ip = ""; $netmask="";
+ } else {
+ list($ip, $netmask) = explode("/", $ip);
+ }
+
+ $db_data = array(
+ 'name' => $name,
+ 'menu_id' => $menu
+ );
+
+ $id = (int)$this->_mmenu_assignments->insert($db_data);
+
+ if ($bootmedia != "all") {
+ $db_data = array (
+ 'menu_assignment_rule' => $id,
+ 'bootmedia_id' => $bootmedia
+ );
+ $this->_mmenu_assignment_bmrules->insert($db_data);
+ }
+
+ if (!empty($ip)) {
+ $db_data = array (
+ 'menu_assignment_rule' => $id,
+ 'ip' => $ip,
+ 'netmask' => $netmask
+ );
+ $this->_mmenu_assignment_iprules->insert($db_data);
+ }
+
+ }
+
+}
+
+
+
+
+
+
+
+
+