/** @function __construct() builds the menu base elements
  * @param $Host the host to work across or null otherwise
  * @return void
  */
 public function __construct($Host = null)
 {
     parent::__construct();
     $this->loglevel = 'loglevel=' . $this->FOGCore->getSetting('FOG_KERNEL_LOGLEVEL');
     // Setups of the basic construct for the menu system.
     $StorageNode = current($this->getClass('StorageNodeManager')->find(array('isEnabled' => 1, 'isMaster' => 1)));
     // Sets up the default values stored in the server. Lines 51 - 64
     $webserver = $this->FOGCore->resolveHostname($this->FOGCore->getSetting('FOG_WEB_HOST'));
     $webroot = '/' . ltrim(rtrim($this->FOGCore->getSetting('FOG_WEB_ROOT'), '/'), '/') . '/';
     $this->web = "{$webserver}{$webroot}";
     $this->bootexittype = $this->FOGCore->getSetting('FOG_BOOT_EXIT_TYPE') == 'exit' ? 'exit' : ($this->FOGCore->getSetting('FOG_BOOT_EXIT_TYPE') == 'sanboot' ? 'sanboot --no-describe --drive 0x80' : ($this->FOGCore->getSetting('FOG_BOOT_EXIT_TYPE') == 'grub' ? 'chain -ar http://' . rtrim($this->web, '/') . '/service/ipxe/grub.exe --config-file="rootnoverify (hd0);chainloader +1"' : 'exit'));
     $ramsize = $this->FOGCore->getSetting('FOG_KERNEL_RAMDISK_SIZE');
     $dns = $this->FOGCore->getSetting('FOG_PXE_IMAGE_DNSADDRESS');
     $keymap = $this->FOGCore->getSetting('FOG_KEYMAP');
     $memdisk = 'memdisk';
     $memtest = $this->FOGCore->getSetting('FOG_MEMTEST_KERNEL');
     // Default bzImage and imagefile based on arch received.
     $bzImage = $_REQUEST['arch'] == 'x86_64' ? $this->FOGCore->getSetting('FOG_TFTP_PXE_KERNEL') : $this->FOGCore->getSetting('FOG_TFTP_PXE_KERNEL_32');
     $kernel = $bzImage;
     $imagefile = $_REQUEST['arch'] == 'x86_64' ? $this->FOGCore->getSetting('FOG_PXE_BOOT_IMAGE') : $this->FOGCore->getSetting('FOG_PXE_BOOT_IMAGE_32');
     $initrd = $imagefile;
     // Adjust file info if host is valid.
     if ($Host && $Host->isValid()) {
         $Host->get('kernel') ? $bzImage = $Host->get('kernel') : null;
         $kernel = $bzImage;
         $this->HookManager->processEvent('BOOT_ITEM_NEW_SETTINGS', array('Host' => &$Host, 'StorageGroup' => &$StorageGroup, 'StorageNode' => &$StorageNode, 'memtest' => &$memtest, 'memdisk' => &$memdisk, 'bzImage' => &$bzImage, 'initrd' => &$initrd, 'webroot' => &$webroot, 'imagefile' => &$imagefile));
     }
     // Sets the key sequence.  Only used if the hidden menu option is selected.
     $keySequence = $this->FOGCore->getSetting('FOG_KEY_SEQUENCE');
     if ($keySequence) {
         $this->KS = new KeySequence($keySequence);
     }
     // menu Access sets if the menu is displayed.  Menu access is a url get variable if a user has specified hidden menu it will override if menuAccess is set.
     if (!$_REQUEST['menuAccess']) {
         $this->hiddenmenu = $this->FOGCore->getSetting('FOG_PXE_MENU_HIDDEN');
     }
     $timeout = ($this->hiddenmenu ? $this->FOGCore->getSetting('FOG_PXE_HIDDENMENU_TIMEOUT') : $this->FOGCore->getSetting('FOG_PXE_MENU_TIMEOUT')) * 1000;
     $this->timeout = $timeout;
     // Generate the URL to boot from.
     $this->booturl = "http://{$webserver}{$webroot}service";
     // Store the host call into class global.
     $this->Host = $Host;
     // Capone menu setup.
     $CaponePlugInst = $_SESSION['capone'];
     $DMISet = $CaponePlugInst ? $this->FOGCore->getSetting('FOG_PLUGIN_CAPONE_DMI') : false;
     // If it is installed store the needed elements into variables.
     if ($CaponePlugInst) {
         $this->storage = $this->FOGCore->resolveHostname($StorageNode->get('ip'));
         $this->path = $StorageNode->get('path');
         $this->shutdown = $this->FOGCore->getSetting('FOG_PLUGIN_CAPONE_SHUTDOWN');
     }
     // Create menu item if not exists and Capone is installed as well as the DMI is specified.
     if ($CaponePlugInst && $DMISet) {
         // Check for fog.capone if the pxe menu entry exists.
         $PXEMenuItem = current($this->getClass('PXEMenuOptionsManager')->find(array('name' => 'fog.capone')));
         // If it does exist, generate the updated arguments for each call.
         if ($PXEMenuItem && $PXEMenuItem->isValid()) {
             $PXEMenuItem->set('args', "mode=capone shutdown={$this->shutdown} storage={$this->storage}:{$this->path}");
         } else {
             $PXEMenuItem = new PXEMenuOptions(array('name' => 'fog.capone', 'description' => 'Capone Deploy', 'args' => "mode=capone shutdown={$this->shutdown} storage={$this->storage}:{$this->path}", 'params' => null, 'default' => '0', 'regMenu' => '2'));
         }
         $PXEMenuItem->save();
     }
     // Specify the default calls.
     $this->memdisk = "kernel {$memdisk}";
     $this->memtest = "initrd {$memtest}";
     $this->kernel = "kernel {$bzImage} {$this->loglevel} initrd={$initrd} root=/dev/ram0 rw ramdisk_size={$ramsize} keymap={$keymap} web={$webserver}{$webroot} consoleblank=0" . ($this->FOGCore->getSetting('FOG_KERNEL_DEBUG') ? ' debug' : '');
     $this->initrd = "imgfetch {$imagefile}";
     // Set the default line based on all the menu entries and only the one with the default set.
     $defMenuItem = current($this->getClass('PXEMenuOptionsManager')->find(array('default' => 1)));
     $this->defaultChoice = "choose --default " . ($defMenuItem && $defMenuItem->isValid() ? $defMenuItem->get('name') : 'fog.local') . (!$this->hiddenmenu ? " --timeout {$timeout}" : " --timeout 0") . ' target && goto ${target}';
     // Register the success of the boot to the database:
     $iPXE = current($this->getClass('iPXEManager')->find(array('product' => $_REQUEST['product'], 'manufacturer' => $_REQUEST['manufacturer'], 'file' => $_REQUEST['filename'])));
     if ($iPXE && $iPXE->isValid()) {
         if ($iPXE->get('failure')) {
             $iPXE->set('failure', 0);
         }
         if (!$iPXE->get('success')) {
             $iPXE->set('success', 1);
         }
         if (!$iPXE->get('version')) {
             $iPXE->set('version', $_REQUEST['ipxever']);
         }
     } else {
         if (!$iPXE || !$iPXE->isValid()) {
             $iPXE = new iPXE(array('product' => $_REQUEST['product'], 'manufacturer' => $_REQUEST['manufacturer'], 'mac' => $Host && $Host->isValid() ? $Host->get('mac') : 'no mac', 'success' => 1, 'file' => $_REQUEST['filename'], 'version' => $_REQUEST['ipxever']));
         }
     }
     $iPXE->save();
     if ($_REQUEST['username'] && $_REQUEST['password']) {
         $this->verifyCreds();
     } else {
         if ($_REQUEST['delconf']) {
             $this->delHost();
         } else {
             if ($_REQUEST['key']) {
                 $this->keyset();
             } else {
                 if ($_REQUEST['sessname']) {
                     $this->sesscheck();
                 } else {
                     if ($_REQUEST['aprvconf']) {
                         $this->approveHost();
                     } else {
                         if (!$Host || !$Host->isValid()) {
                             $this->printDefault();
                         } else {
                             $this->getTasking();
                         }
                     }
                 }
             }
         }
     }
 }
 public function new_menu_post()
 {
     try {
         // Error checking
         // At the least, you should have an item and a description.
         if (!$_REQUEST['menu_item']) {
             throw new Exception(_('Menu Item or title cannot be blank'));
         }
         if (!$_REQUEST['menu_description']) {
             throw new Exception(_('A description needs to be set'));
         }
         $Menu = new PXEMenuOptions(array('name' => $_REQUEST['menu_item'], 'description' => $_REQUEST['menu_description'], 'params' => $_REQUEST['menu_params'], 'regMenu' => $_REQUEST['menu_regmenu'], 'args' => $_REQUEST['menu_options']));
         if ($Menu->save()) {
             $this->FOGCore->setMessage($Menu->get('name') . ' ' . _('successfully added, editing now'));
         }
         // Set all other menus that are default to non-default value.
         if ($_REQUEST['menu_default']) {
             foreach ($this->getClass('PXEMenuOptionsManager')->find('', '', 'id') as $MenusRemoveDefault) {
                 $MenusRemoveDefault->set('default', 0)->save();
             }
             $Menu->set('default', 1)->save();
         }
     } catch (Exception $e) {
         $this->FOGCore->setMessage($e->getMessage());
     }
     $this->FOGCore->redirect("?node={$this->node}&sub=customize-edit#{$Menu->get(name)}");
 }