public function PopulateChildMenus() { foreach (ApplicationMenu::GetChildren($this->GetIndex()) as $aMenu) { $index = $aMenu['index']; $oMenu = ApplicationMenu::GetMenuNode($index); $oMenu->PopulateChildMenus(); } }
public function DisplayMenu() { // Display the menu $oAppContext = new ApplicationContext(); $iAccordionIndex = 0; ApplicationMenu::DisplayMenu($this, $oAppContext->GetAsHash()); }
ApplicationMenu::LoadAdditionalMenus(); $index = ApplicationMenu::GetMenuIndexById($sMenuId); $oMenu = ApplicationMenu::GetMenuNode($index); if ($oMenu instanceof DashboardMenuNode) { $oDashboard = $oMenu->GetDashboard(); $oPage->TrashUnexpectedOutput(); $oPage->SetContentType('text/xml'); $oPage->SetContentDisposition('attachment', $oMenu->GetLabel() . '.xml'); $oPage->add($oDashboard->ToXml()); } break; case 'import_dashboard': $sMenuId = utils::ReadParam('id', '', false, 'raw_data'); ApplicationMenu::LoadAdditionalMenus(); $index = ApplicationMenu::GetMenuIndexById($sMenuId); $oMenu = ApplicationMenu::GetMenuNode($index); $aResult = array('error' => ''); try { if ($oMenu instanceof DashboardMenuNode) { $oDoc = utils::ReadPostedDocument('dashboard_upload_file'); $oDashboard = $oMenu->GetDashboard(); $oDashboard->FromXml($oDoc->GetData()); $oDashboard->Save(); } else { $aResult['error'] = 'Dashboard id="' . $sMenuId . '" not found.'; } } catch (DOMException $e) { $aResult = array('error' => Dict::S('UI:Error:InvalidDashboardFile')); } catch (Exception $e) { $aResult = array('error' => $e->getMessage()); }
<?php // Copyright (C) 2010-2012 Combodo SARL // // This file is part of iTop. // // iTop is free software; you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // iTop is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with iTop. If not, see <http://www.gnu.org/licenses/> // Starting with iTop 1.2 you can restrict the list of organizations displayed in the drop-down list // by specifying a query as shown below. Note that this is NOT a security settings, since the // choice 'All Organizations' will always be available in the menu ApplicationMenu::SetFavoriteSiloQuery('SELECT Organization');
} $oP->SetCurrentTab(''); break; /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// case 'cancel': // An action was cancelled $oP->set_title(Dict::S('UI:OperationCancelled')); $oP->add('<h1>' . Dict::S('UI:OperationCancelled') . '</h1>'); break; /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// default: // Menu node rendering (templates) ApplicationMenu::LoadAdditionalMenus(); $oMenuNode = ApplicationMenu::GetMenuNode(ApplicationMenu::GetMenuIndexById(ApplicationMenu::GetActiveNodeId())); if (is_object($oMenuNode)) { $oMenuNode->RenderContent($oP, $oAppContext->GetAsHash()); $oP->set_title($oMenuNode->GetLabel()); } /////////////////////////////////////////////////////////////////////////////////////////// } DisplayWelcomePopup($oP); $oP->output(); } catch (CoreException $e) { require_once APPROOT . '/setup/setuppage.class.inc.php'; $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError')); if ($e instanceof SecurityException) { $oP->add("<h1>" . Dict::S('UI:SystemIntrusion') . "</h1>\n"); } else { $oP->add("<h1>" . Dict::S('UI:FatalErrorMessage') . "</h1>\n");
public static function GetDashletCreationForm($sOQL = null) { $oForm = new DesignerForm(); // Get the list of all 'dashboard' menus in which we can insert a dashlet $aAllMenus = ApplicationMenu::ReflectionMenuNodes(); $aAllowedDashboards = array(); foreach ($aAllMenus as $idx => $aMenu) { $oMenu = $aMenu['node']; $sParentId = $aMenu['parent']; if ($oMenu instanceof DashboardMenuNode) { $sMenuLabel = $oMenu->GetTitle(); $sParentLabel = Dict::S('Menu:' . $sParentId); if ($sParentLabel != $sMenuLabel) { $aAllowedDashboards[$oMenu->GetMenuId()] = $sParentLabel . ' - ' . $sMenuLabel; } else { $aAllowedDashboards[$oMenu->GetMenuId()] = $sMenuLabel; } } } asort($aAllowedDashboards); $aKeys = array_keys($aAllowedDashboards); // Select the first one by default $sDefaultDashboard = $aKeys[0]; $oField = new DesignerComboField('menu_id', Dict::S('UI:DashletCreation:Dashboard'), $sDefaultDashboard); $oField->SetAllowedValues($aAllowedDashboards); $oField->SetMandatory(true); $oForm->AddField($oField); // Get the list of possible dashlets that support a creation from // an OQL $aDashlets = array(); foreach (get_declared_classes() as $sDashletClass) { if (is_subclass_of($sDashletClass, 'Dashlet')) { $oReflection = new ReflectionClass($sDashletClass); if (!$oReflection->isAbstract()) { $aCallSpec = array($sDashletClass, 'CanCreateFromOQL'); $bShorcutMode = call_user_func($aCallSpec); if ($bShorcutMode) { $aCallSpec = array($sDashletClass, 'GetInfo'); $aInfo = call_user_func($aCallSpec); $aDashlets[$sDashletClass] = array('label' => $aInfo['label'], 'class' => $sDashletClass, 'icon' => $aInfo['icon']); } } } } $oSelectorField = new DesignerFormSelectorField('dashlet_class', Dict::S('UI:DashletCreation:DashletType'), ''); $oForm->AddField($oSelectorField); foreach ($aDashlets as $sDashletClass => $aDashletInfo) { $oSubForm = new DesignerForm(); $oMetaModel = new ModelReflectionRuntime(); $oDashlet = new $sDashletClass($oMetaModel, 0); $oDashlet->GetPropertiesFieldsFromOQL($oSubForm, $sOQL); $oSelectorField->AddSubForm($oSubForm, $aDashletInfo['label'], $aDashletInfo['class']); } $oField = new DesignerBooleanField('open_editor', Dict::S('UI:DashletCreation:EditNow'), true); $oForm->AddField($oField); return $oForm; }
/** * Merge standard menu items with plugin provided menus items */ public static function GetPopupMenuItems($oPage, $iMenuId, $param, &$aActions, $sTableId = null, $sDataTableId = null) { // 1st - add standard built-in menu items // switch ($iMenuId) { case iPopupMenuExtension::MENU_OBJLIST_TOOLKIT: // $param is a DBObjectSet $oAppContext = new ApplicationContext(); $sContext = $oAppContext->GetForLink(); $sDataTableId = is_null($sDataTableId) ? '' : $sDataTableId; $sUIPage = cmdbAbstractObject::ComputeStandardUIPage($param->GetFilter()->GetClass()); $sOQL = addslashes($param->GetFilter()->ToOQL(true)); $sFilter = urlencode($param->GetFilter()->serialize()); $sUrl = utils::GetAbsoluteUrlAppRoot() . "pages/{$sUIPage}?operation=search&filter=" . $sFilter . "&{$sContext}"; $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot() . 'js/tabularfieldsselector.js'); $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot() . 'js/jquery.dragtable.js'); $oPage->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot() . 'css/dragtable.css'); $aResult = array(new SeparatorPopupMenuItem(), new URLPopupMenuItem('UI:Menu:EMail', Dict::S('UI:Menu:EMail'), "mailto:?body=" . urlencode($sUrl) . ' ')); if (UserRights::IsActionAllowed($param->GetFilter()->GetClass(), UR_ACTION_BULK_READ, $param) && (UR_ALLOWED_YES || UR_ALLOWED_DEPENDS)) { // Bulk export actions $aResult[] = new JSPopupMenuItem('UI:Menu:CSVExport', Dict::S('UI:Menu:CSVExport'), "ExportListDlg('{$sOQL}', '{$sDataTableId}', 'csv', " . json_encode(Dict::S('UI:Menu:CSVExport')) . ")"); $aResult[] = new JSPopupMenuItem('UI:Menu:ExportXLSX', Dict::S('ExcelExporter:ExportMenu'), "ExportListDlg('{$sOQL}', '{$sDataTableId}', 'xlsx', " . json_encode(Dict::S('ExcelExporter:ExportMenu')) . ")"); $aResult[] = new JSPopupMenuItem('UI:Menu:ExportPDF', Dict::S('UI:Menu:ExportPDF'), "ExportListDlg('{$sOQL}', '{$sDataTableId}', 'pdf', " . json_encode(Dict::S('UI:Menu:ExportPDF')) . ")"); } $aResult[] = new JSPopupMenuItem('UI:Menu:AddToDashboard', Dict::S('UI:Menu:AddToDashboard'), "DashletCreationDlg('{$sOQL}')"); $aResult[] = new JSPopupMenuItem('UI:Menu:ShortcutList', Dict::S('UI:Menu:ShortcutList'), "ShortcutListDlg('{$sOQL}', '{$sDataTableId}', '{$sContext}')"); break; case iPopupMenuExtension::MENU_OBJDETAILS_ACTIONS: // $param is a DBObject $oObj = $param; $sOQL = "SELECT " . get_class($oObj) . " WHERE id=" . $oObj->GetKey(); $oFilter = DBObjectSearch::FromOQL($sOQL); $sFilter = $oFilter->serialize(); $sUrl = ApplicationContext::MakeObjectUrl(get_class($oObj), $oObj->GetKey()); $sUIPage = cmdbAbstractObject::ComputeStandardUIPage(get_class($oObj)); $oAppContext = new ApplicationContext(); $sContext = $oAppContext->GetForLink(); $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot() . 'js/tabularfieldsselector.js'); $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot() . 'js/jquery.dragtable.js'); $oPage->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot() . 'css/dragtable.css'); $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot() . 'js/tabularfieldsselector.js'); $oPage->add_linked_script(utils::GetAbsoluteUrlAppRoot() . 'js/jquery.dragtable.js'); $oPage->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot() . 'css/dragtable.css'); $aResult = array(new SeparatorPopupMenuItem(), new URLPopupMenuItem('UI:Menu:EMail', Dict::S('UI:Menu:EMail'), "mailto:?subject=" . urlencode($oObj->GetRawName()) . "&body=" . urlencode($sUrl) . ' '), new JSPopupMenuItem('UI:Menu:CSVExport', Dict::S('UI:Menu:CSVExport'), "ExportListDlg('{$sOQL}', '', 'csv', " . json_encode(Dict::S('UI:Menu:CSVExport')) . ")"), new JSPopupMenuItem('UI:Menu:ExportXLSX', Dict::S('ExcelExporter:ExportMenu'), "ExportListDlg('{$sOQL}', '', 'xlsx', " . json_encode(Dict::S('ExcelExporter:ExportMenu')) . ")")); break; case iPopupMenuExtension::MENU_DASHBOARD_ACTIONS: // $param is a Dashboard $oAppContext = new ApplicationContext(); $aParams = $oAppContext->GetAsHash(); $sMenuId = ApplicationMenu::GetActiveNodeId(); $sDlgTitle = addslashes(Dict::S('UI:ImportDashboardTitle')); $sDlgText = addslashes(Dict::S('UI:ImportDashboardText')); $sCloseBtn = addslashes(Dict::S('UI:Button:Cancel')); $aResult = array(new SeparatorPopupMenuItem(), new URLPopupMenuItem('UI:ExportDashboard', Dict::S('UI:ExportDashBoard'), utils::GetAbsoluteUrlAppRoot() . 'pages/ajax.render.php?operation=export_dashboard&id=' . $sMenuId), new JSPopupMenuItem('UI:ImportDashboard', Dict::S('UI:ImportDashBoard'), "UploadDashboard({dashboard_id: '{$sMenuId}', title: '{$sDlgTitle}', text: '{$sDlgText}', close_btn: '{$sCloseBtn}' })")); break; default: // Unknown type of menu, do nothing $aResult = array(); } foreach ($aResult as $oMenuItem) { $aActions[$oMenuItem->GetUID()] = $oMenuItem->GetMenuItem(); } // Invoke the plugins // foreach (MetaModel::EnumPlugins('iPopupMenuExtension') as $oExtensionInstance) { if (is_object($param) && !$param instanceof DBObject) { $tmpParam = clone $param; // In case the parameter is an DBObjectSet, clone it to prevent alterations } else { $tmpParam = $param; } foreach ($oExtensionInstance->EnumItems($iMenuId, $tmpParam) as $oMenuItem) { if (is_object($oMenuItem)) { $aActions[$oMenuItem->GetUID()] = $oMenuItem->GetMenuItem(); foreach ($oMenuItem->GetLinkedScripts() as $sLinkedScript) { $oPage->add_linked_script($sLinkedScript); } } } } }
/** * Displays the user's changeable preferences * @param $oP WebPage The web page used for the output */ function DisplayPreferences($oP) { $oAppContext = new ApplicationContext(); $sURL = utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php?' . $oAppContext->GetForLink(); $oP->add('<div class="page_header"><h1><img style="vertical-align:middle" src="../images/preferences.png"/> ' . Dict::S('UI:Preferences') . "</h1></div>\n"); $oP->add('<div id="user_prefs" style="max-width:800px; min-width:400px;">'); ////////////////////////////////////////////////////////////////////////// // // User Language selection // ////////////////////////////////////////////////////////////////////////// $oP->add('<fieldset><legend>' . Dict::S('UI:FavoriteLanguage') . '</legend>'); $oP->add('<form method="post">'); $aLanguages = Dict::GetLanguages(); $aSortedlang = array(); foreach ($aLanguages as $sCode => $aLang) { if (MetaModel::GetConfig()->Get('demo_mode')) { if ($sCode != Dict::GetUserLanguage()) { // Demo mode: only the current user language is listed in the available choices continue; } } $aSortedlang[$aLang['description']] = $sCode; } ksort($aSortedlang); $oP->add('<p>' . Dict::S('UI:Favorites:SelectYourLanguage') . ' <select name="language">'); foreach ($aSortedlang as $sCode) { $sSelected = $sCode == Dict::GetUserLanguage() ? 'selected' : ''; $oP->add('<option value="' . $sCode . '" ' . $sSelected . '/>' . $aLanguages[$sCode]['description'] . ' (' . $aLanguages[$sCode]['localized_description'] . ')</option>'); } $oP->add('</select></p>'); $oP->add('<input type="hidden" name="operation" value="apply_language"/>'); $oP->add($oAppContext->GetForForm()); $oP->add('<p><input type="button" onClick="window.location.href=\'' . $sURL . '\'" value="' . Dict::S('UI:Button:Cancel') . '"/>'); $oP->add(' '); $oP->add('<input type="submit" value="' . Dict::S('UI:Button:Apply') . '"/></p>'); $oP->add('</form>'); $oP->add('</fieldset>'); ////////////////////////////////////////////////////////////////////////// // // Other (miscellaneous) settings // ////////////////////////////////////////////////////////////////////////// $oP->add('<fieldset><legend>' . Dict::S('UI:FavoriteOtherSettings') . '</legend>'); $oP->add('<form method="post" onsubmit="return ValidateOtherSettings()">'); $iDefaultPageSize = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit()); $oP->add('<p>' . Dict::Format('UI:Favorites:Default_X_ItemsPerPage', '<input id="default_page_size" name="default_page_size" type="text" size="3" value="' . $iDefaultPageSize . '"/><span id="v_default_page_size"></span>') . '</p>'); $oP->add('<input type="hidden" name="operation" value="apply_others"/>'); $oP->add($oAppContext->GetForForm()); $oP->add('<p><input type="button" onClick="window.location.href=\'' . $sURL . '\'" value="' . Dict::S('UI:Button:Cancel') . '"/>'); $oP->add(' '); $oP->add('<input id="other_submit" type="submit" value="' . Dict::S('UI:Button:Apply') . '"/></p>'); $oP->add('</form>'); $oP->add('</fieldset>'); $oP->add_script(<<<EOF function ValidateOtherSettings() { \tvar sPageLength = \$('#default_page_size').val(); \tvar iPageLength = parseInt(sPageLength , 10); \tif (/^[0-9]+\$/.test(sPageLength) && (iPageLength > 0)) \t{ \t\t\$('#v_default_page_size').html(''); \t\t\$('#other_submit').removeAttr('disabled'); \t\treturn true; \t} \telse \t{ \t\t\$('#v_default_page_size').html('<img src="../images/validation_error.png"/>'); \t\t\$('#other_submit').attr('disabled', 'disabled'); \t\treturn false; \t} } EOF ); ////////////////////////////////////////////////////////////////////////// // // Favorite Organizations // ////////////////////////////////////////////////////////////////////////// $oP->add('<fieldset><legend>' . Dict::S('UI:FavoriteOrganizations') . '</legend>'); $oP->p(Dict::S('UI:FavoriteOrganizations+')); $oP->add('<form method="post">'); // Favorite organizations: the organizations listed in the drop-down menu $sOQL = ApplicationMenu::GetFavoriteSiloQuery(); $oFilter = DBObjectSearch::FromOQL($sOQL); $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oP, 1, array('menu' => false, 'selection_mode' => true, 'selection_type' => 'multiple', 'cssCount' => '.selectedCount', 'table_id' => 'user_prefs')); $oP->add($oAppContext->GetForForm()); $oP->add('<input type="hidden" name="operation" value="apply"/>'); $oP->add('<p><input type="button" onClick="window.location.href=\'' . $sURL . '\'" value="' . Dict::S('UI:Button:Cancel') . '"/>'); $oP->add(' '); $oP->add('<input type="submit" value="' . Dict::S('UI:Button:Apply') . '"/></p>'); $oP->add('</form>'); $oP->add('</fieldset>'); $aFavoriteOrgs = appUserPreferences::GetPref('favorite_orgs', null); if ($aFavoriteOrgs == null) { // All checked $oP->add_ready_script(<<<EOF \tif (\$('#user_prefs table.pagination').length > 0) \t{ \t\t// paginated display, restore the selection \t\tvar pager = \$('#user_prefs form .pager'); \t\t\$(':input[name=selectionMode]', pager).val('negative'); \t\t\$('#user_prefs table.listResults').trigger('load_selection'); \t} \telse \t{ \t\t\$('#user_prefs table.listResults').trigger('check_all'); \t} EOF ); } else { $sChecked = implode('","', $aFavoriteOrgs); $oP->add_ready_script(<<<EOF \tvar aChecked = ["{$sChecked}"]; \tif (\$('#user_prefs table.pagination').length > 0) \t{ \t\t// paginated display, restore the selection \t\tvar pager = \$('#user_prefs form .pager'); \t\t\$(':input[name=selectionMode]', pager).val('positive'); \t\tfor (i=0; i<aChecked.length; i++) \t\t{ \t\t\tpager.append('<input type="hidden" name="storedSelection[]" id="'+aChecked[i]+'" value="'+aChecked[i]+'"/>'); \t\t} \t\t\$('#user_prefs table.listResults').trigger('load_selection'); \t\t \t} \telse \t{ \t\t\$('#user_prefs form :checkbox[name^=selectObject]').each( function() \t\t\t{ \t\t\t\tif (\$.inArray(\$(this).val(), aChecked) > -1) \t\t\t\t{ \t\t\t\t\t\$(this).attr('checked', true); \t\t\t\t\t\$(this).trigger('change'); \t\t\t\t} \t\t\t}); \t} EOF ); } ////////////////////////////////////////////////////////////////////////// // // Shortcuts // ////////////////////////////////////////////////////////////////////////// $oP->add('<fieldset><legend>' . Dict::S('Menu:MyShortcuts') . '</legend>'); //$oP->p(Dict::S('UI:Menu:MyShortcuts+')); $oBMSearch = new DBObjectSearch('Shortcut'); $oBMSearch->AddCondition('user_id', UserRights::GetUserId(), '='); //$aExtraParams = array('menu' => false, 'toolkit_menu' => false, 'display_limit' => false, 'localize_values' => $bLocalize, 'zlist' => 'details'); $aExtraParams = array(); $oBlock = new DisplayBlock($oBMSearch, 'list', false, $aExtraParams); $oBlock->Display($oP, 'shortcut_list', array('view_link' => false, 'menu' => false, 'toolkit_menu' => false, 'selection_mode' => true, 'selection_type' => 'multiple', 'cssCount' => '#shortcut_selection_count', 'table_id' => 'user_prefs_shortcuts')); $oP->add('<p>'); $oSet = new DBObjectSet($oBMSearch); if ($oSet->Count() > 0) { $sButtons = '<img src="../images/tv-item-last.gif">'; $sButtons .= ' '; $sButtons .= '<button id="shortcut_btn_rename">' . Dict::S('UI:Button:Rename') . '</button>'; $sButtons .= ' '; $sButtons .= '<button id="shortcut_btn_delete">' . Dict::S('UI:Button:Delete') . '</button>'; // Selection count updated by the pager, and used to enable buttons $oP->add('<input type="hidden" id="shortcut_selection_count"/>'); $oP->add('</fieldset>'); $sConfirmDelete = addslashes(Dict::S('UI:ShortcutDelete:Confirm')); $oP->add_ready_script(<<<EOF function OnShortcutBtnRename() { \tvar oParams = \$('#datatable_shortcut_list').datatable('GetMultipleSelectionParams'); \toParams.operation = 'shortcut_rename_dlg'; \t\$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', oParams, function(data){ \t\t\$('body').append(data); \t}); \treturn false; } function OnShortcutBtnDelete() { \tif (confirm('{$sConfirmDelete}')) \t{ \t\tvar oParams = \$('#datatable_shortcut_list').datatable('GetMultipleSelectionParams'); \t\toParams.operation = 'shortcut_delete_go'; \t\t\$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', oParams, function(data){ \t\t\t\$('body').append(data); \t\t}); \t} \treturn false; } function OnSelectionCountChange() { \tvar iCountSelected = \$("#shortcut_selection_count").val(); \tif (iCountSelected == 0) \t{ \t\t\$('#shortcut_btn_rename').attr('disabled', 'disabled'); \t\t\$('#shortcut_btn_delete').attr('disabled', 'disabled'); \t} \telse if (iCountSelected == 1) \t{ \t\t\$('#shortcut_btn_rename').removeAttr('disabled'); \t\t\$('#shortcut_btn_delete').removeAttr('disabled'); \t} \telse \t{ \t\t\$('#shortcut_btn_rename').attr('disabled', 'disabled'); \t\t\$('#shortcut_btn_delete').removeAttr('disabled'); \t} } var oUpperCheckBox = \$('#datatable_shortcut_list .checkAll').first(); oUpperCheckBox.parent().width(oUpperCheckBox.width() + 2); \$('#datatable_shortcut_list').append('<tr><td colspan="2"> {$sButtons}</td></tr>'); \$('#shortcut_selection_count').bind('change', OnSelectionCountChange); \$('#shortcut_btn_rename').bind('click', OnShortcutBtnRename); \$('#shortcut_btn_delete').bind('click', OnShortcutBtnDelete); OnSelectionCountChange(); EOF ); } // if count > 0 ////////////////////////////////////////////////////////////////////////// // // Footer // $oP->add('</div>'); $oP->add_ready_script("\$('#fav_page_length').bind('keyup change', function(){ ValidateOtherSettings(); })"); }