123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767 |
- <?php
- // Copyright (C) 2010-2017 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/>
- /**
- * Main page of iTop
- *
- * @copyright Copyright (C) 2010-2017 Combodo SARL
- * @license http://opensource.org/licenses/AGPL-3.0
- */
- /**
- * Displays a popup welcome message, once per session at maximum
- * until the user unchecks the "Display welcome at startup"
- * @param WebPage $oP The current web page for the display
- * @return void
- */
- function DisplayWelcomePopup(WebPage $oP)
- {
- if (!isset($_SESSION['welcome']))
- {
- // Check, only once per session, if the popup should be displayed...
- // If the user did not already ask for hiding it forever
- $bPopup = appUserPreferences::GetPref('welcome_popup', true);
- if ($bPopup)
- {
- $sTemplate = @file_get_contents('../application/templates/welcome_popup.html');
- if ($sTemplate !== false)
- {
- $oTemplate = new DisplayTemplate($sTemplate);
- $oP->add("<div id=\"welcome_popup\">");
- $oTemplate->Render($oP, array());
- $oP->add("<p style=\"float:left\"><input type=\"checkbox\" checked id=\"display_welcome_popup\"/><label for=\"display_welcome_popup\"> ".Dict::S('UI:DisplayThisMessageAtStartup')."</label></p>\n");
- $oP->add("<p style=\"float:right\"><input type=\"button\" value=\"".Dict::S('UI:Button:Ok')."\" onClick=\"$('#welcome_popup').dialog('close');\"/>\n");
- $oP->add("</div>\n");
- $sTitle = addslashes(Dict::S('UI:WelcomeMenu:Title'));
- $oP->add_ready_script(
- <<<EOF
- $('#welcome_popup').dialog( { width:'80%', height: 'auto', title: '$sTitle', autoOpen: true, modal:true,
- close: function() {
- var bDisplay = $('#display_welcome_popup:checked').length;
- SetUserPreference('welcome_popup', bDisplay, true);
- }
- });
- if ($('#welcome_popup').height() > ($(window).height()-70))
- {
- $('#welcome_popup').height($(window).height()-70);
- }
- EOF
- );
- $_SESSION['welcome'] = 'ok';
- }
- }
- }
- }
- /**
- * Apply the 'next-action' to the given object or redirect to the page that prompts for additional information if needed
- * @param $oP WebPage The page for the output
- * @param $oObj CMDBObject The object to process
- * @param $sNextAction string The code of the stimulus for the 'action' (i.e. Transition) to apply
- */
- function ApplyNextAction(Webpage $oP, CMDBObject $oObj, $sNextAction)
- {
- // Here handle the apply stimulus
- $aTransitions = $oObj->EnumTransitions();
- $aStimuli = MetaModel::EnumStimuli(get_class($oObj));
- if (!isset($aTransitions[$sNextAction]))
- {
- // Invalid stimulus
- throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sNextAction, $oObj->GetName(), $oObj->GetStateLabel()));
- }
- // Get the list of missing mandatory fields for the target state, considering only the changes from the previous form (i.e don't prompt twice)
- $aExpectedAttributes = $oObj->GetExpectedAttributes($oObj->GetState(), $sNextAction, true /* $bOnlyNewOnes */);
-
- if (count($aExpectedAttributes) == 0)
- {
- // If all the mandatory fields are already present, just apply the transition silently...
- if ($oObj->ApplyStimulus($sNextAction))
- {
- $oObj->DBUpdate();
- }
- ReloadAndDisplay($oP, $oObj);
- }
- else
- {
- // redirect to the 'stimulus' action
- $oAppContext = new ApplicationContext();
- //echo "<p>Missing Attributes <pre>".print_r($aExpectedAttributes, true)."</pre></p>\n";
-
- $oP->add_header('Location: '.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=stimulus&class='.get_class($oObj).'&stimulus='.$sNextAction.'&id='.$oObj->getKey().'&'.$oAppContext->GetForLink());
- }
- }
- function ReloadAndDisplay($oPage, $oObj, $sMessageId = '', $sMessage = '', $sSeverity = null)
- {
- $oAppContext = new ApplicationContext();
- if ($sMessageId != '')
- {
- cmdbAbstractObject::SetSessionMessage(get_class($oObj), $oObj->GetKey(), $sMessageId, $sMessage, $sSeverity, 0, true /* must not exist */);
- }
- $oPage->add_header('Location: '.utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=details&class='.get_class($oObj).'&id='.$oObj->getKey().'&'.$oAppContext->GetForLink());
- }
- /**
- * Displays the details of an object
- * @param $oP WebPage Page for the output
- * @param $sClass string The name of the class of the object
- * @param $oObj DBObject The object to display
- * @param $id mixed Identifier of the object (name or ID)
- */
- function DisplayDetails($oP, $sClass, $oObj, $id)
- {
- $sClassLabel = MetaModel::GetName($sClass);
- $oSearch = new DBObjectSearch($sClass);
- $oBlock = new DisplayBlock($oSearch, 'search', false);
- $oBlock->Display($oP, 0);
- // The object could be listed, check if it is actually allowed to view it
- $oSet = CMDBObjectSet::FromObject($oObj);
- if (UserRights::IsActionAllowed($sClass, UR_ACTION_READ, $oSet) == UR_ALLOWED_NO)
- {
- throw new SecurityException('User not allowed to view this object', array('class' => $sClass, 'id' => $id));
- }
- $oP->set_title(Dict::Format('UI:DetailsPageTitle', $oObj->GetRawName(), $sClassLabel)); // Set title will take care of the encoding
- $oObj->DisplayDetails($oP);
- }
- /**
- * Display the session messages relative to the object identified by its "message key" (class::id)
- * @param string $sMessageKey
- * @param WebPage $oPage
- */
- function DisplayMessages($sMessageKey, WebPage $oPage)
- {
- if (array_key_exists('obj_messages', $_SESSION) && array_key_exists($sMessageKey, $_SESSION['obj_messages']))
- {
- $aMessages = array();
- $aRanks = array();
- foreach ($_SESSION['obj_messages'][$sMessageKey] as $sMessageId => $aMessageData)
- {
- $sMsgClass = 'message_'.$aMessageData['severity'];
- $aMessages[] = "<div class=\"header_message $sMsgClass\">".$aMessageData['message']."</div>";
- $aRanks[] = $aMessageData['rank'];
- }
- unset($_SESSION['obj_messages'][$sMessageKey]);
- array_multisort($aRanks, $aMessages);
- foreach ($aMessages as $sMessage)
- {
- $oPage->add($sMessage);
- }
- }
- }
- /**
- * Displays the result of a search request
- * @param $oP WebPage Web page for the output
- * @param $oFilter DBSearch The search of objects to display
- * @param $bSearchForm boolean Whether or not to display the search form at the top the page
- * @param $sBaseClass string The base class for the search (can be different from the actual class of the results)
- * @param $sFormat string The format to use for the output: csv or html
- * @param $bDoSearch bool True to display the search results below the search form
- * @param $bSearchFormOpen bool True to display the search form fully expanded (only if $bSearchForm of course)
- */
- function DisplaySearchSet($oP, $oFilter, $bSearchForm = true, $sBaseClass = '', $sFormat = '', $bDoSearch = true, $bSearchFormOpen = false)
- {
- if ($bSearchForm)
- {
- $aParams = array('open' => $bSearchFormOpen);
- if (!empty($sBaseClass))
- {
- $aParams['baseClass'] = $sBaseClass;
- }
- $oBlock = new DisplayBlock($oFilter, 'search', false /* Asynchronous */, $aParams);
- $oBlock->Display($oP, 0);
- }
- if ($bDoSearch)
- {
- if (strtolower($sFormat) == 'csv')
- {
- $oBlock = new DisplayBlock($oFilter, 'csv', false);
- $oBlock->Display($oP, 1);
- // Adjust the size of the Textarea containing the CSV to fit almost all the remaining space
- $oP->add_ready_script(" $('#1>textarea').height($('#1').parent().height() - $('#0').outerHeight() - 30).width( $('#1').parent().width() - 20);"); // adjust the size of the block
- }
- else
- {
- $oBlock = new DisplayBlock($oFilter, 'list', false);
- $oBlock->Display($oP, 1);
- // Breadcrumb
- //$iCount = $oBlock->GetDisplayedCount();
- $sPageId = "ui-search-".$oFilter->GetClass();
- $sLabel = MetaModel::GetName($oFilter->GetClass());
- $oP->SetBreadCrumbEntry($sPageId, $sLabel, '', '', '../images/breadcrumb-search.png');
- }
- }
- }
- /**
- * Displays a form (checkboxes) to select the objects for which to apply a given action
- * Only the objects for which the action is valid can be checked. By default all valid objects are checked
- * @param $oP WebPage The page for output
- * @param $oFilter DBSearch The filter that defines the list of objects
- * @param $sNextOperation string The next operation (code) to be executed when the form is submitted
- * @param $oChecker ActionChecker The helper class/instance used to check for which object the action is valid
- * @return none
- */
- function DisplayMultipleSelectionForm($oP, $oFilter, $sNextOperation, $oChecker, $aExtraFormParams = array())
- {
- $oAppContext = new ApplicationContext();
- $iBulkActionAllowed = $oChecker->IsAllowed();
- $sClass = $oFilter->GetClass();
- $aExtraParams = array('selection_type' => 'multiple', 'selection_mode' => true, 'display_limit' => false, 'menu' => false);
- if ($iBulkActionAllowed == UR_ALLOWED_DEPENDS)
- {
- $aAllowed = array();
- $aExtraParams['selection_enabled'] = $oChecker->GetAllowedIDs();
- }
- else if(UR_ALLOWED_NO)
- {
- throw new ApplicationException(Dict::Format('UI:ActionNotAllowed'));
- }
-
- $oBlock = new DisplayBlock($oFilter, 'list', false);
- $oP->add("<form method=\"post\" action=\"./UI.php\">\n");
- $oP->add("<input type=\"hidden\" name=\"operation\" value=\"$sNextOperation\">\n");
- $oP->add("<input type=\"hidden\" name=\"class\" value=\"".$oFilter->GetClass()."\">\n");
- $oP->add("<input type=\"hidden\" name=\"filter\" value=\"".$oFilter->Serialize()."\">\n");
- $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
- foreach($aExtraFormParams as $sName => $sValue)
- {
- $oP->add("<input type=\"hidden\" name=\"$sName\" value=\"$sValue\">\n");
- }
- $oP->add($oAppContext->GetForForm());
- $oBlock->Display($oP, 1, $aExtraParams);
- $oP->add("<input type=\"button\" value=\"".Dict::S('UI:Button:Cancel')."\" onClick=\"window.history.back()\"> <input type=\"submit\" value=\"".Dict::S('UI:Button:Next')."\">\n");
- $oP->add("</form>\n");
- $oP->add_ready_script("$('#1 table.listResults').trigger('check_all');");
- }
- function DisplayNavigatorListTab($oP, $aResults, $sRelation, $sDirection, $oObj)
- {
- $oP->SetCurrentTab(Dict::S('UI:RelationshipList'));
- $oP->add("<div id=\"impacted_objects\" style=\"width:100%;background-color:#fff;padding:10px;\">");
- $sOldRelation = $sRelation;
- if (($sRelation == 'impacts') && ($sDirection == 'up'))
- {
- $sOldRelation = 'depends on';
- }
- $oP->add("<h1>".MetaModel::GetRelationDescription($sOldRelation).' '.$oObj->GetName()."</h1>\n");
- $oP->add("<div id=\"impacted_objects_lists\">");
- $oP->add('<img src="../images/indicator.gif">');
- /*
- * Content is rendered asynchronously via pages/ajax.render.php?operation=relation_lists
- */
- /*
- $iBlock = 1; // Zero is not a valid blockid
- foreach($aResults as $sListClass => $aObjects)
- {
- $oSet = CMDBObjectSet::FromArray($sListClass, $aObjects);
- $oP->add("<div class=\"page_header\">\n");
- $oP->add("<h2>".MetaModel::GetClassIcon($sListClass)." <span class=\"hilite\">".Dict::Format('UI:Search:Count_ObjectsOf_Class_Found', count($aObjects), Metamodel::GetName($sListClass))."</h2>\n");
- $oP->add("</div>\n");
- $oBlock = DisplayBlock::FromObjectSet($oSet, 'list');
- $oBlock->Display($oP, $iBlock++, array('table_id' => get_class($oObj).'_'.$sRelation.'_'.$sDirection.'_'.$sListClass));
- $oP->P(' '); // Some space ?
- }
- */
- $oP->add("</div>");
- $oP->add("</div>");
- }
- function DisplayNavigatorGroupTab($oP)
- {
- $oP->SetCurrentTab(Dict::S('UI:RelationGroups'));
- $oP->add("<div id=\"impacted_groups\" style=\"width:100%;background-color:#fff;padding:10px;\">");
- $oP->add('<img src="../images/indicator.gif">');
- /*
- * Content is rendered asynchronously via pages/ajax.render.php?operation=relation_groups
- */
- $oP->add("</div>");
- }
- /***********************************************************************************
- *
- * Main user interface page starts here
- *
- ***********************************************************************************/
- try
- {
- require_once('../approot.inc.php');
- require_once(APPROOT.'/application/application.inc.php');
- require_once(APPROOT.'/application/itopwebpage.class.inc.php');
- require_once(APPROOT.'/application/wizardhelper.class.inc.php');
- require_once(APPROOT.'/application/startup.inc.php');
- $operation = utils::ReadParam('operation', '');
- $bPrintable = (utils::ReadParam('printable', 0) == '1');
- $oKPI = new ExecutionKPI();
- $oKPI->ComputeAndReport('Data model loaded');
- $oKPI = new ExecutionKPI();
- require_once(APPROOT.'/application/loginwebpage.class.inc.php');
- $sLoginMessage = LoginWebPage::DoLogin(); // Check user rights and prompt if needed
- $oAppContext = new ApplicationContext();
- $oKPI->ComputeAndReport('User login');
- $oP = new iTopWebPage(Dict::S('UI:WelcomeToITop'), $bPrintable);
- $oP->SetMessage($sLoginMessage);
- // All the following actions use advanced forms that require more javascript to be loaded
- switch($operation)
- {
- case 'new': // Form to create a new object
- case 'modify': // Form to modify an object
- case 'apply_new': // Creation of a new object
- case 'apply_modify': // Applying the modifications to an existing object
- case 'form_for_modify_all': // Form to modify multiple objects (bulk modify)
- case 'bulk_stimulus': // For to apply a stimulus to multiple objects
- case 'stimulus': // Form displayed when applying a stimulus (state change)
- case 'apply_stimulus': // Form displayed when applying a stimulus (state change)
- $oP->add_linked_script("../js/json.js");
- $oP->add_linked_script("../js/forms-json-utils.js");
- $oP->add_linked_script("../js/wizardhelper.js");
- $oP->add_linked_script("../js/wizard.utils.js");
- $oP->add_linked_script("../js/linkswidget.js");
- $oP->add_linked_script("../js/linksdirectwidget.js");
- $oP->add_linked_script("../js/extkeywidget.js");
- $oP->add_linked_script("../js/jquery.blockUI.js");
- break;
- }
-
- switch($operation)
- {
- ///////////////////////////////////////////////////////////////////////////////////////////
-
- case 'details': // Details of an object
- $sClass = utils::ReadParam('class', '');
- $id = utils::ReadParam('id', '');
- if ( empty($sClass) || empty($id))
- {
- throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
- }
- if (is_numeric($id))
- {
- $oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
- }
- else
- {
- $oObj = MetaModel::GetObjectByName($sClass, $id, false /* MustBeFound */);
- }
- if (is_null($oObj))
- {
- // Check anyhow if there is a message for this object (like you've just created it)
- $sMessageKey = $sClass.'::'.$id;
- DisplayMessages($sMessageKey, $oP);
- $oP->set_title(Dict::S('UI:ErrorPageTitle'));
- // Attempt to load the object in archive mode
- utils::PushArchiveMode(true);
- if (is_numeric($id))
- {
- $oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
- }
- else
- {
- $oObj = MetaModel::GetObjectByName($sClass, $id, false /* MustBeFound */);
- }
- utils::PopArchiveMode();
- if (is_null($oObj))
- {
- $oP->P(Dict::S('UI:ObjectDoesNotExist'));
- }
- else
- {
- $oP->P(Dict::S('UI:ObjectArchived'));
- }
- }
- else
- {
- try
- {
- $oObj->Reload();
- }
- catch(Exception $e)
- {
- // Probably not allowed to see this instance of a derived class
-
- // Check anyhow if there is a message for this object (like you've just created it)
- $sMessageKey = $sClass.'::'.$id;
- DisplayMessages($sMessageKey, $oP);
-
- $oObj = null;
- $oP->set_title(Dict::S('UI:ErrorPageTitle'));
- $oP->P(Dict::S('UI:ObjectDoesNotExist'));
- }
- if (!is_null($oObj))
- {
- $sClass = get_class($oObj); // get the leaf class
- $sIcon = MetaModel::GetClassIcon($sClass, false);
- if ($sIcon == '')
- {
- $sIcon = utils::GetAbsoluteUrlAppRoot().'images/breadcrumb_object.png';
- }
- $oP->SetBreadCrumbEntry("ui-details-$sClass-$id", $oObj->Get('friendlyname'), MetaModel::GetName($sClass).': '.$oObj->Get('friendlyname'), '', $sIcon);
- DisplayDetails($oP, $sClass, $oObj, $id);
- }
- }
- break;
- case 'release_lock_and_details':
- $oP->DisableBreadCrumb();
- $sClass = utils::ReadParam('class', '');
- $id = utils::ReadParam('id', '');
- $oObj = MetaModel::GetObject($sClass, $id);
- $sToken = utils::ReadParam('token', '');
- if ($sToken != '')
- {
- iTopOwnershipLock::ReleaseLock($sClass, $id, $sToken);
- }
- cmdbAbstractObject::ReloadAndDisplay($oP, $oObj, array('operation' => 'details'));
- break;
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'search_oql': // OQL query
- $sOQLClass = utils::ReadParam('oql_class', '', false, 'class');
- $sBaseClass = utils::ReadParam('base_class', $sOQLClass, false, 'class');
- $sOQLClause = utils::ReadParam('oql_clause', '', false, 'raw_data');
- $sFormat = utils::ReadParam('format', '');
- $bSearchForm = utils::ReadParam('search_form', true);
- $sTitle = utils::ReadParam('title', 'UI:SearchResultsPageTitle');
- if (empty($sOQLClass))
- {
- throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'oql_class'));
- }
- $oP->set_title(Dict::S($sTitle));
- $oP->add('<h1>'.Dict::S($sTitle).'</h1>');
- $sOQL = "SELECT $sOQLClass $sOQLClause";
- try
- {
- $oFilter = DBObjectSearch::FromOQL($sOQL);
- DisplaySearchSet($oP, $oFilter, $bSearchForm, $sBaseClass, $sFormat);
- }
- catch(CoreException $e)
- {
- $oFilter = new DBObjectSearch($sOQLClass);
- $oSet = new DBObjectSet($oFilter);
- if ($bSearchForm)
- {
- $oBlock = new DisplayBlock($oFilter, 'search', false);
- $oBlock->Display($oP, 0);
- }
- $oP->P('<b>'.Dict::Format('UI:Error:IncorrectOQLQuery_Message', $e->getHtmlDesc()).'</b>');
- }
- catch(Exception $e)
- {
- $oP->P('<b>'.Dict::Format('UI:Error:AnErrorOccuredWhileRunningTheQuery_Message', $e->getMessage()).'</b>');
- }
- break;
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'search_form': // Search form
- $sClass = utils::ReadParam('class', '', false, 'class');
- $sFormat = utils::ReadParam('format', 'html');
- $bSearchForm = utils::ReadParam('search_form', true);
- $bDoSearch = utils::ReadParam('do_search', true);
- if (empty($sClass))
- {
- throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
- }
- $oP->set_title(Dict::S('UI:SearchResultsPageTitle'));
- $oFilter = new DBObjectSearch($sClass);
- DisplaySearchSet($oP, $oFilter, $bSearchForm, '' /* sBaseClass */, $sFormat, $bDoSearch, true /* Search Form Expanded */);
- break;
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'search': // Serialized DBSearch
- $sFilter = utils::ReadParam('filter', '', false, 'raw_data');
- $sFormat = utils::ReadParam('format', '');
- $bSearchForm = utils::ReadParam('search_form', true);
- if (empty($sFilter))
- {
- throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'filter'));
- }
- $oP->set_title(Dict::S('UI:SearchResultsPageTitle'));
- // TO DO: limit the search filter by the user context
- $oFilter = DBSearch::unserialize($sFilter); // TO DO : check that the filter is valid
- DisplaySearchSet($oP, $oFilter, $bSearchForm, '' /* sBaseClass */, $sFormat);
- break;
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'full_text': // Global "google-like" search
- $oP->DisableBreadCrumb();
- $sFullText = trim(utils::ReadParam('text', '', false, 'raw_data'));
- $iTune = utils::ReadParam('tune', 0);
- if (empty($sFullText))
- {
- $oP->p(Dict::S('UI:Search:NoSearch'));
- }
- else
- {
- $iErrors = 0;
- // Check if a class name/label is supplied to limit the search
- $sClassName = '';
- if (preg_match('/^([^\"]+):(.+)$/', $sFullText, $aMatches))
- {
- $sClassName = $aMatches[1];
- if (MetaModel::IsValidClass($sClassName))
- {
- $sFullText = trim($aMatches[2]);
- }
- elseif ($sClassName = MetaModel::GetClassFromLabel($sClassName, false /* => not case sensitive */))
- {
- $sFullText = trim($aMatches[2]);
- }
- }
-
- if (preg_match('/^"(.*)"$/', $sFullText, $aMatches))
- {
- // The text is surrounded by double-quotes, remove the quotes and treat it as one single expression
- $aFullTextNeedles = array($aMatches[1]);
- }
- else
- {
- // Split the text on the blanks and treat this as a search for <word1> AND <word2> AND <word3>
- $aFullTextNeedles = explode(' ', $sFullText);
- }
- // Check the needle length
- $iMinLenth = MetaModel::GetConfig()->Get('full_text_needle_min');
- foreach ($aFullTextNeedles as $sNeedle)
- {
- if (strlen($sNeedle) < $iMinLenth)
- {
- $oP->p(Dict::Format('UI:Search:NeedleTooShort', $sNeedle, $iMinLenth));
- $iErrors++;
- }
- }
- // Sanity check of the accelerators
- $aAccelerators = MetaModel::GetConfig()->Get('full_text_accelerators');
- foreach ($aAccelerators as $sClass => $aAccelerator)
- {
- try
- {
- $bSkip = array_key_exists('skip', $aAccelerator) ? $aAccelerator['skip'] : false;
- if (!$bSkip)
- {
- $oSearch = DBObjectSearch::FromOQL($aAccelerator['query']);
- if ($sClass != $oSearch->GetClass())
- {
- $oP->p("Full text accelerator for class '$sClass': searched class mismatch (".$oSearch->GetClass().")");
- $iErrors++;
- }
- }
- }
- catch (OqlException $e)
- {
- $oP->p("Full text accelerator for class '$sClass': ".$e->getHtmlDesc());
- $iErrors++;
- }
- }
- if ($iErrors == 0)
- {
- $oP->set_title(Dict::S('UI:SearchResultsPageTitle'));
- $sPageId = "ui-global-search";
- $sLabel = Dict::S('UI:SearchResultsTitle');
- $sDescription = Dict::S('UI:SearchResultsTitle+');
- $oP->SetBreadCrumbEntry($sPageId, $sLabel, $sDescription, '', utils::GetAbsoluteUrlAppRoot().'images/search.png');
- $oP->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/tabularfieldsselector.js');
- $oP->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.dragtable.js');
- $oP->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot().'css/dragtable.css');
- $oP->add("<div style=\"padding: 10px;\">\n");
- $oP->add("<div class=\"header_message\" id=\"full_text_progress\" style=\"position: fixed; background-color: #cccccc; opacity: 0.7; padding: 1.5em;\">\n");
- $oP->add('<img id="full_text_indicator" src="../images/indicator.gif"> <span style="padding: 1.5em;">'.Dict::Format('UI:Search:Ongoing', htmlentities($sFullText, ENT_QUOTES, 'UTF-8')).'</span>');
- $oP->add("</div>\n");
- $oP->add("<div id=\"full_text_results\">\n");
- $oP->add("<div id=\"full_text_progress_placeholder\" style=\"padding: 1.5em;\"> </div>\n");
- $oP->add("<h2>".Dict::Format('UI:FullTextSearchTitle_Text', htmlentities($sFullText, ENT_QUOTES, 'UTF-8'))."</h2>");
- $oP->add("</div>\n");
- $oP->add("</div>\n");
- $sJSClass = addslashes($sClassName);
- $sJSNeedles = json_encode($aFullTextNeedles);
- $oP->add_ready_script(
- <<<EOF
- var oParams = {operation: 'full_text_search', position: 0, 'class': '$sJSClass', needles: $sJSNeedles, tune: $iTune};
- $.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', oParams, function(data) {
- $('#full_text_results').append(data);
- });
- EOF
- );
- if ($iTune > 0)
- {
- $oP->add_script("var oTimeStatistics = {};");
- }
- }
- }
- break;
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'modify': // Form to modify an object
- $oP->DisableBreadCrumb();
- $sClass = utils::ReadParam('class', '', false, 'class');
- $id = utils::ReadParam('id', '');
- if ( empty($sClass) || empty($id)) // TO DO: check that the class name is valid !
- {
- throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
- }
- // Check if the user can modify this object
- $oObj = MetaModel::GetObject($sClass, $id, false /* MustBeFound */);
- if (is_null($oObj))
- {
- $oP->set_title(Dict::S('UI:ErrorPageTitle'));
- $oP->P(Dict::S('UI:ObjectDoesNotExist'));
- }
- else
- {
- // The object could be read - check if it is allowed to modify it
- $oSet = CMDBObjectSet::FromObject($oObj);
- if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_NO)
- {
- throw new SecurityException('User not allowed to modify this object', array('class' => $sClass, 'id' => $id));
- }
- // Note: code duplicated to the case 'apply_modify' when a data integrity issue has been found
- $oObj->DisplayModifyForm($oP, array('wizard_container' => 1)); // wizard_container: Display the blue borders and the title above the form
- }
- break;
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'select_for_modify_all': // Select the list of objects to be modified (bulk modify)
- $oP->DisableBreadCrumb();
- $oP->set_title(Dict::S('UI:ModifyAllPageTitle'));
- $sFilter = utils::ReadParam('filter', '', false, 'raw_data');
- if (empty($sFilter))
- {
- throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'filter'));
- }
- // TO DO: limit the search filter by the user context
- $oFilter = DBObjectSearch::unserialize($sFilter); // TO DO : check that the filter is valid
- $sClass = $oFilter->GetClass();
- $oChecker = new ActionChecker($oFilter, UR_ACTION_BULK_MODIFY);
- $oP->add("<h1>".Dict::S('UI:ModifyAllPageTitle')."</h1>\n");
-
- DisplayMultipleSelectionForm($oP, $oFilter, 'form_for_modify_all', $oChecker);
- break;
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'form_for_modify_all': // Form to modify multiple objects (bulk modify)
- $oP->DisableBreadCrumb();
- $sFilter = utils::ReadParam('filter', '', false, 'raw_data');
- $sClass = utils::ReadParam('class', '', false, 'class');
- $oFullSetFilter = DBObjectSearch::unserialize($sFilter);
- $aSelectedObj = utils::ReadMultipleSelection($oFullSetFilter);
- $sCancelUrl = "./UI.php?operation=search&filter=".urlencode($sFilter)."&".$oAppContext->GetForLink();
- $aContext = array('filter' => $sFilter);
- cmdbAbstractObject::DisplayBulkModifyForm($oP, $sClass, $aSelectedObj, 'preview_or_modify_all', $sCancelUrl, array(), $aContext);
- break;
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'preview_or_modify_all': // Preview or apply bulk modify
- $oP->DisableBreadCrumb();
- $sFilter = utils::ReadParam('filter', '', false, 'raw_data');
- // TO DO: limit the search filter by the user context
- $oFilter = DBObjectSearch::unserialize($sFilter); // TO DO : check that the filter is valid
- $oChecker = new ActionChecker($oFilter, UR_ACTION_BULK_MODIFY);
- $sClass = utils::ReadParam('class', '', false, 'class');
- $bPreview = utils::ReadParam('preview_mode', '');
- $sSelectedObj = utils::ReadParam('selectObj', '', false, 'raw_data');
- if ( empty($sClass) || empty($sSelectedObj)) // TO DO: check that the class name is valid !
- {
- throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'selectObj'));
- }
- $aSelectedObj = explode(',', $sSelectedObj);
- $sCancelUrl = "./UI.php?operation=search&filter=".urlencode($sFilter)."&".$oAppContext->GetForLink();
- $aContext = array(
- 'filter' => $sFilter,
- 'selectObj' => $sSelectedObj,
- );
- cmdbAbstractObject::DoBulkModify($oP, $sClass, $aSelectedObj, 'preview_or_modify_all', $bPreview, $sCancelUrl, $aContext);
- break;
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'new': // Form to create a new object
- $oP->DisableBreadCrumb();
- $sClass = utils::ReadParam('class', '', false, 'class');
- $sStateCode = utils::ReadParam('state', '');
- $bCheckSubClass = utils::ReadParam('checkSubclass', true);
- if ( empty($sClass) )
- {
- throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
- }
- /*
- $aArgs = utils::ReadParam('default', array(), false, 'raw_data');
- $aContext = $oAppContext->GetAsHash();
- foreach( $oAppContext->GetNames() as $key)
- {
- $aArgs[$key] = $oAppContext->GetCurrentValue($key);
- }
- */
- // If the specified class has subclasses, ask the user an instance of which class to create
- $aSubClasses = MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL); // Including the specified class itself
- $aPossibleClasses = array();
- $sRealClass = '';
- if ($bCheckSubClass)
- {
- foreach($aSubClasses as $sCandidateClass)
- {
- if (!MetaModel::IsAbstract($sCandidateClass) && (UserRights::IsActionAllowed($sCandidateClass, UR_ACTION_MODIFY) == UR_ALLOWED_YES))
- {
- $aPossibleClasses[$sCandidateClass] = MetaModel::GetName($sCandidateClass);
- }
- }
- // Only one of the subclasses can be instantiated...
- if (count($aPossibleClasses) == 1)
- {
- $aKeys = array_keys($aPossibleClasses);
- $sRealClass = $aKeys[0];
- }
- }
- else
- {
- $sRealClass = $sClass;
- }
-
- if (!empty($sRealClass))
- {
- // Display the creation form
- $sClassLabel = MetaModel::GetName($sRealClass);
- // Note: some code has been duplicated to the case 'apply_new' when a data integrity issue has been found
- $oP->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel));
- $oP->add("<h1>".MetaModel::GetClassIcon($sRealClass)." ".Dict::Format('UI:CreationTitle_Class', $sClassLabel)."</h1>\n");
- $oP->add("<div class=\"wizContainer\">\n");
- // Set all the default values in an object and clone this "default" object
- $oObjToClone = MetaModel::NewObject($sRealClass);
- // 1st - set context values
- $oAppContext->InitObjectFromContext($oObjToClone);
- // 2nd - set values from the page argument 'default'
- $oObjToClone->UpdateObjectFromArg('default');
- cmdbAbstractObject::DisplayCreationForm($oP, $sRealClass, $oObjToClone, array());
- $oP->add("</div>\n");
- }
- else
- {
- // Select the derived class to create
- $sClassLabel = MetaModel::GetName($sClass);
- $oP->add("<h1>".MetaModel::GetClassIcon($sClass)." ".Dict::Format('UI:CreationTitle_Class', $sClassLabel)."</h1>\n");
- $oP->add("<div class=\"wizContainer\">\n");
- $oP->add('<form>');
- $oP->add('<p>'.Dict::Format('UI:SelectTheTypeOf_Class_ToCreate', $sClassLabel));
- $aDefaults = utils::ReadParam('default', array(), false, 'raw_data');
- $oP->add($oAppContext->GetForForm());
- $oP->add("<input type=\"hidden\" name=\"checkSubclass\" value=\"0\">\n");
- $oP->add("<input type=\"hidden\" name=\"state\" value=\"$sStateCode\">\n");
- $oP->add("<input type=\"hidden\" name=\"operation\" value=\"new\">\n");
- foreach($aDefaults as $key => $value)
- {
- if (is_array($value))
- {
- foreach($value as $key2 => $value2)
- {
- if (is_array($value2))
- {
- foreach($value2 as $key3 => $value3)
- {
- $sValue = htmlentities($value3, ENT_QUOTES, 'UTF-8');
- $oP->add("<input type=\"hidden\" name=\"default[$key][$key2][$key3]\" value=\"$sValue\">\n");
- }
- }
- else
- {
- $sValue = htmlentities($value2, ENT_QUOTES, 'UTF-8');
- $oP->add("<input type=\"hidden\" name=\"default[$key][$key2]\" value=\"$sValue\">\n");
- }
- }
- }
- else
- {
- $sValue = htmlentities($value, ENT_QUOTES, 'UTF-8');
- $oP->add("<input type=\"hidden\" name=\"default[$key]\" value=\"$sValue\">\n");
- }
- }
- $oP->add('<select name="class">');
- asort($aPossibleClasses);
- foreach($aPossibleClasses as $sClassName => $sClassLabel)
- {
- $sSelected = ($sClassName == $sClass) ? 'selected' : '';
- $oP->add("<option $sSelected value=\"$sClassName\">$sClassLabel</option>");
- }
- $oP->add('</select>');
- $oP->add(" <input type=\"submit\" value=\"".Dict::S('UI:Button:Apply')."\"></p>");
- $oP->add('</form>');
- $oP->add("</div>\n");
- }
- break;
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'apply_modify': // Applying the modifications to an existing object
- $oP->DisableBreadCrumb();
- $sClass = utils::ReadPostedParam('class', '');
- $sClassLabel = MetaModel::GetName($sClass);
- $id = utils::ReadPostedParam('id', '');
- $sTransactionId = utils::ReadPostedParam('transaction_id', '');
- if ( empty($sClass) || empty($id)) // TO DO: check that the class name is valid !
- {
- throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'id'));
- }
- $bDisplayDetails = true;
- $oObj = MetaModel::GetObject($sClass, $id, false);
- if ($oObj == null)
- {
- $bDisplayDetails = false;
- $oP->set_title(Dict::S('UI:ErrorPageTitle'));
- $oP->P(Dict::S('UI:ObjectDoesNotExist'));
- }
- elseif (!utils::IsTransactionValid($sTransactionId, false))
- {
- $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetRawName(), $sClassLabel)); // Set title will take care of the encoding
- $oP->p("<strong>".Dict::S('UI:Error:ObjectAlreadyUpdated')."</strong>\n");
- }
- else
- {
- $oObj->UpdateObjectFromPostedForm();
- $sMessage = '';
- $sSeverity = 'ok';
- if (!$oObj->IsModified())
- {
- $oP->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $oObj->GetRawName(), $sClassLabel)); // Set title will take care of the encoding
- $sMessage = Dict::Format('UI:Class_Object_NotUpdated', MetaModel::GetName(get_class($oObj)), $oObj->GetName());
- $sSeverity = 'info';
- }
- else
- {
- list($bRes, $aIssues) = $oObj->CheckToWrite();
- if ($bRes)
- {
- try
- {
- CMDBSource::Query('START TRANSACTION');
- $oObj->DBUpdate();
- CMDBSource::Query('COMMIT');
- $sMessage = Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oObj)), $oObj->GetName());
- $sSeverity = 'ok';
- }
- catch(DeleteException $e)
- {
- CMDBSource::Query('ROLLBACK');
- // Say two things: 1) Don't be afraid nothing was modified
- $sMessage = Dict::Format('UI:Class_Object_NotUpdated', MetaModel::GetName(get_class($oObj)), $oObj->GetName());
- $sSeverity = 'info';
- cmdbAbstractObject::SetSessionMessage(get_class($oObj), $oObj->GetKey(), 'UI:Class_Object_NotUpdated', $sMessage, $sSeverity, 0, true /* must not exist */);
- // 2) Ok, there was some trouble indeed
- $sMessage = $e->getMessage();
- $sSeverity = 'error';
- $bDisplayDetails = true;
- }
- utils::RemoveTransaction($sTransactionId);
-
- }
- else
- {
- $bDisplayDetails = false;
- // Found issues, explain and give the user a second chance
- //
- $oObj->DisplayModifyForm($oP, array('wizard_container' => true)); // wizard_container: display the wizard border and the title
- $sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten', implode(', ', $aIssues));
- $oP->add_ready_script("alert('".addslashes($sIssueDesc)."');");
- }
- }
- }
- if ($bDisplayDetails)
- {
- $oObj = MetaModel::GetObject(get_class($oObj), $oObj->GetKey()); //Workaround: reload the object so that the linkedset are displayed properly
- $sNextAction = utils::ReadPostedParam('next_action', '');
- if (!empty($sNextAction))
- {
- ApplyNextAction($oP, $oObj, $sNextAction);
- }
- else
- {
- // Nothing more to do
- ReloadAndDisplay($oP, $oObj, 'update', $sMessage, $sSeverity);
- }
-
- $bLockEnabled = MetaModel::GetConfig()->Get('concurrent_lock_enabled');
- if ($bLockEnabled)
- {
- // Release the concurrent lock, if any
- $sOwnershipToken = utils::ReadPostedParam('ownership_token', null, false, 'raw_data');
- if ($sOwnershipToken !== null)
- {
- // We're done, let's release the lock
- iTopOwnershipLock::ReleaseLock(get_class($oObj), $oObj->GetKey(), $sOwnershipToken);
- }
- }
- }
- break;
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'select_for_deletion': // Select multiple objects for deletion
- $oP->DisableBreadCrumb();
- $sFilter = utils::ReadParam('filter', '', false, 'raw_data');
- if (empty($sFilter))
- {
- throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'filter'));
- }
- $oP->set_title(Dict::S('UI:BulkDeletePageTitle'));
- $oP->add("<h1>".Dict::S('UI:BulkDeleteTitle')."</h1>\n");
- // TO DO: limit the search filter by the user context
- $oFilter = DBSearch::unserialize($sFilter); // TO DO : check that the filter is valid
- $oChecker = new ActionChecker($oFilter, UR_ACTION_BULK_DELETE);
- DisplayMultipleSelectionForm($oP, $oFilter, 'bulk_delete', $oChecker);
- break;
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'bulk_delete_confirmed': // Confirm bulk deletion of objects
- $oP->DisableBreadCrumb();
- $sTransactionId = utils::ReadPostedParam('transaction_id', '');
- if (!utils::IsTransactionValid($sTransactionId))
- {
- throw new ApplicationException(Dict::S('UI:Error:ObjectsAlreadyDeleted'));
- }
- // Fall through
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'delete':
- case 'bulk_delete': // Actual bulk deletion (if confirmed)
- $oP->DisableBreadCrumb();
- $sClass = utils::ReadParam('class', '', false, 'class');
- $sClassLabel = MetaModel::GetName($sClass);
- $aObjects = array();
- if ($operation == 'delete')
- {
- // Single object
- $id = utils::ReadParam('id', '');
- $oObj = MetaModel::GetObject($sClass, $id);
- $aObjects[] = $oObj;
- if (!UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, DBObjectSet::FromObject($oObj)))
- {
- throw new SecurityException(Dict::Format('UI:Error:DeleteNotAllowedOn_Class', $sClassLabel));
- }
- }
- else
- {
- // Several objects
- $sFilter = utils::ReadPostedParam('filter', '');
- $oFullSetFilter = DBObjectSearch::unserialize($sFilter);
- $aSelectObject = utils::ReadMultipleSelection($oFullSetFilter);
- if ( empty($sClass) || empty($aSelectObject)) // TO DO: check that the class name is valid !
- {
- throw new ApplicationException(Dict::Format('UI:Error:2ParametersMissing', 'class', 'selectObject[]'));
- }
- foreach($aSelectObject as $iId)
- {
- $aObjects[] = MetaModel::GetObject($sClass, $iId);
- }
- if (count($aObjects) == 1)
- {
- if (!UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE, DBObjectSet::FromArray($sClass, $aObjects)))
- {
- throw new SecurityException(Dict::Format('UI:Error:BulkDeleteNotAllowedOn_Class', $sClassLabel));
- }
- }
- else
- {
- if (!UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_DELETE, DBObjectSet::FromArray($sClass, $aObjects)))
- {
- throw new SecurityException(Dict::Format('UI:Error:BulkDeleteNotAllowedOn_Class', $sClassLabel));
- }
- $oP->set_title(Dict::S('UI:BulkDeletePageTitle'));
- }
- }
- // Go for the common part... (delete single, delete bulk, delete confirmed)
- cmdbAbstractObject::DeleteObjects($oP, $sClass, $aObjects, ($operation != 'bulk_delete_confirmed'), 'bulk_delete_confirmed');
- break;
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'apply_new': // Creation of a new object
- $oP->DisableBreadCrumb();
- $sClass = utils::ReadPostedParam('class', '', 'class');
- $sClassLabel = MetaModel::GetName($sClass);
- $sTransactionId = utils::ReadPostedParam('transaction_id', '');
- if ( empty($sClass) ) // TO DO: check that the class name is valid !
- {
- throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'class'));
- }
- if (!utils::IsTransactionValid($sTransactionId, false))
- {
- $oP->p("<strong>".Dict::S('UI:Error:ObjectAlreadyCreated')."</strong>\n");
- }
- else
- {
- $oObj = MetaModel::NewObject($sClass);
- $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
- if (!empty($sStateAttCode))
- {
- $sTargetState = utils::ReadPostedParam('obj_state', '');
- if ($sTargetState != '')
- {
- $oObj->Set($sStateAttCode, $sTargetState);
- }
- }
- $oObj->UpdateObjectFromPostedForm();
- }
- if (isset($oObj) && is_object($oObj))
- {
- $sClass = get_class($oObj);
- $sClassLabel = MetaModel::GetName($sClass);
- list($bRes, $aIssues) = $oObj->CheckToWrite();
- if ($bRes)
- {
- $oObj->DBInsertNoReload(); // No need to reload
- utils::RemoveTransaction($sTransactionId);
- $oP->set_title(Dict::S('UI:PageTitle:ObjectCreated'));
-
- // Compute the name, by reloading the object, even if it disappeared from the silo
- $oObj = MetaModel::GetObject($sClass, $oObj->GetKey(), true /* Must be found */, true /* Allow All Data*/);
- $sName = $oObj->GetName();
- $sMessage = Dict::Format('UI:Title:Object_Of_Class_Created', $sName, $sClassLabel);
-
- $sNextAction = utils::ReadPostedParam('next_action', '');
- if (!empty($sNextAction))
- {
- $oP->add("<h1>$sMessage</h1>");
- ApplyNextAction($oP, $oObj, $sNextAction);
- }
- else
- {
- // Nothing more to do
- ReloadAndDisplay($oP, $oObj, 'create', $sMessage, 'ok');
- }
- }
- else
- {
- // Found issues, explain and give the user a second chance
- //
- $oP->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel));
- $oP->add("<h1>".MetaModel::GetClassIcon($sClass)." ".Dict::Format('UI:CreationTitle_Class', $sClassLabel)."</h1>\n");
- $oP->add("<div class=\"wizContainer\">\n");
- cmdbAbstractObject::DisplayCreationForm($oP, $sClass, $oObj);
- $oP->add("</div>\n");
- $sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten', implode(', ', $aIssues));
- $oP->add_ready_script("alert('".addslashes($sIssueDesc)."');");
- }
- }
- break;
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'select_bulk_stimulus': // Form displayed when applying a stimulus to many objects
- $oP->DisableBreadCrumb();
- $sFilter = utils::ReadParam('filter', '', false, 'raw_data');
- $sStimulus = utils::ReadParam('stimulus', '');
- $sState = utils::ReadParam('state', '');
- if (empty($sFilter) || empty($sStimulus) || empty($sState))
- {
- throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'filter', 'stimulus', 'state'));
- }
- $oFilter = DBObjectSearch::unserialize($sFilter);
- $sClass = $oFilter->GetClass();
- $aStimuli = MetaModel::EnumStimuli($sClass);
- $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
- $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
- $oP->set_title($sActionLabel);
- $oP->add('<div class="page_header">');
- $oP->add('<h1>'.MetaModel::GetClassIcon($sClass).' '.$sActionLabel.'</h1>');
- $oP->add('</div>');
- $oChecker = new StimulusChecker($oFilter, $sState, $sStimulus);
- $aExtraFormParams = array('stimulus' => $sStimulus, 'state' => $sState);
- DisplayMultipleSelectionForm($oP, $oFilter, 'bulk_stimulus', $oChecker, $aExtraFormParams);
- break;
-
- case 'bulk_stimulus':
- $oP->DisableBreadCrumb();
- $sFilter = utils::ReadParam('filter', '', false, 'raw_data');
- $sStimulus = utils::ReadParam('stimulus', '');
- $sState = utils::ReadParam('state', '');
- if (empty($sFilter) || empty($sStimulus) || empty($sState))
- {
- throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'filter', 'stimulus', 'state'));
- }
- $oFilter = DBObjectSearch::unserialize($sFilter);
- $sClass = $oFilter->GetClass();
- $aSelectObject = utils::ReadMultipleSelection($oFilter);
- if (count($aSelectObject) == 0)
- {
- // Nothing to do, no object was selected !
- throw new ApplicationException(Dict::S('UI:BulkAction:NoObjectSelected'));
- }
- else
- {
- $aTransitions = MetaModel::EnumTransitions($sClass, $sState);
- $aStimuli = MetaModel::EnumStimuli($sClass);
-
- $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
- $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
- $sTargetState = $aTransitions[$sStimulus]['target_state'];
- $aStates = MetaModel::EnumStates($sClass);
- $aTargetStateDef = $aStates[$sTargetState];
- $oP->set_title(Dict::Format('UI:StimulusModify_N_ObjectsOf_Class', $sActionLabel, count($aSelectObject), $sClass));
- $oP->add('<div class="page_header">');
- $oP->add('<h1>'.MetaModel::GetClassIcon($sClass).' '.Dict::Format('UI:StimulusModify_N_ObjectsOf_Class', $sActionLabel, count($aSelectObject), $sClass).'</h1>');
- $oP->add('</div>');
- $aExpectedAttributes = MetaModel::GetTransitionAttributes($sClass, $sStimulus, $sState);
- $aDetails = array();
- $iFieldIndex = 0;
- $aFieldsMap = array();
- $aValues = array();
- $aObjects = array();
- foreach($aSelectObject as $iId)
- {
- $aObjects[] = MetaModel::GetObject($sClass, $iId);
- }
- $oSet = DBObjectSet::FromArray($sClass, $aObjects);
- $oObj = $oSet->ComputeCommonObject($aValues);
- $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
- $oObj->Set($sStateAttCode,$sTargetState);
- $sReadyScript = '';
- foreach($aExpectedAttributes as $sAttCode => $iExpectCode)
- {
- // Prompt for an attribute if
- // - the attribute must be changed or must be displayed to the user for confirmation
- // - or the field is mandatory and currently empty
- if ( ($iExpectCode & (OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT)) ||
- (($iExpectCode & OPT_ATT_MANDATORY) && ($oObj->Get($sAttCode) == '')) )
- {
- $aAttributesDef = MetaModel::ListAttributeDefs($sClass);
- $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
- $aPrerequisites = MetaModel::GetPrerequisiteAttributes($sClass, $sAttCode); // List of attributes that are needed for the current one
- if (count($aPrerequisites) > 0)
- {
- // When 'enabling' a field, all its prerequisites must be enabled too
- $sFieldList = "['".implode("','", $aPrerequisites)."']";
- $oP->add_ready_script("$('#enable_{$sAttCode}').bind('change', function(evt, sFormId) { return PropagateCheckBox( this.checked, $sFieldList, true); } );\n");
- }
- $aDependents = MetaModel::GetDependentAttributes($sClass, $sAttCode); // List of attributes that are needed for the current one
- if (count($aDependents) > 0)
- {
- // When 'disabling' a field, all its dependent fields must be disabled too
- $sFieldList = "['".implode("','", $aDependents)."']";
- $oP->add_ready_script("$('#enable_{$sAttCode}').bind('change', function(evt, sFormId) { return PropagateCheckBox( this.checked, $sFieldList, false); } );\n");
- }
- $aArgs = array('this' => $oObj);
- $sHTMLValue = cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $oObj->Get($sAttCode), $oObj->GetEditValue($sAttCode), $sAttCode, '', $iExpectCode, $aArgs);
- $sComments = '<input type="checkbox" checked id="enable_'.$sAttCode.'" onClick="ToogleField(this.checked, \''.$sAttCode.'\')"/>';
- if (!isset($aValues[$sAttCode]))
- {
- $aValues[$sAttCode] = array();
- }
- if (count($aValues[$sAttCode]) == 1)
- {
- $sComments .= '<div class="mono_value">1</div>';
- }
- else
- {
- // Non-homogenous value
- $iMaxCount = 5;
- $sTip = "<p><b>".Dict::Format('UI:BulkModify_Count_DistinctValues', count($aValues[$sAttCode]))."</b><ul>";
- $index = 0;
- foreach($aValues[$sAttCode] as $sCurrValue => $aVal)
- {
- $sDisplayValue = empty($aVal['display']) ? '<i>'.Dict::S('Enum:Undefined').'</i>' : str_replace(array("\n", "\r"), " ", $aVal['display']);
- $sTip .= "<li>".Dict::Format('UI:BulkModify:Value_Exists_N_Times', $sDisplayValue, $aVal['count'])."</li>";
- $index++;
- if ($iMaxCount == $index)
- {
- $sTip .= "<li>".Dict::Format('UI:BulkModify:N_MoreValues', count($aValues[$sAttCode]) - $iMaxCount)."</li>";
- break;
- }
- }
- $sTip .= "</ul></p>";
- $sTip = addslashes($sTip);
- $sReadyScript .= "$('#multi_values_$sAttCode').qtip( { content: '$sTip', show: 'mouseover', hide: 'mouseout', style: { name: 'dark', tip: 'leftTop' }, position: { corner: { target: 'rightMiddle', tooltip: 'leftTop' }} } );\n";
- $sComments .= '<div class="multi_values" id="multi_values_'.$sAttCode.'">'.count($aValues[$sAttCode]).'</div>';
- }
- $aDetails[] = array('label' => '<span>'.$oAttDef->GetLabel().'</span>', 'value' => "<span id=\"field_$sAttCode\">$sHTMLValue</span>", 'comments' => $sComments);
- $aFieldsMap[$sAttCode] = $sAttCode;
- $iFieldIndex++;
- }
- }
- $sButtonsPosition = MetaModel::GetConfig()->Get('buttons_position');
- if ($sButtonsPosition == 'bottom')
- {
- // bottom: Displays the ticket details BEFORE the actions
- $oP->add('<div class="ui-widget-content">');
- $oObj->DisplayBareProperties($oP);
- $oP->add('</div>');
- }
- $oP->add("<div class=\"wizContainer\">\n");
- $oP->add("<form id=\"apply_stimulus\" method=\"post\" onSubmit=\"return OnSubmit('apply_stimulus');\">\n");
- $oP->add("<table><tr><td>\n");
- $oP->details($aDetails);
- $oP->add("</td></tr></table>\n");
- $oP->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">\n");
- $oP->add("<input type=\"hidden\" name=\"operation\" value=\"bulk_apply_stimulus\">\n");
- $oP->add("<input type=\"hidden\" name=\"preview_mode\" value=\"1\">\n");
- $oP->add("<input type=\"hidden\" name=\"filter\" value=\"$sFilter\">\n");
- $oP->add("<input type=\"hidden\" name=\"stimulus\" value=\"$sStimulus\">\n");
- $oP->add("<input type=\"hidden\" name=\"state\" value=\"$sState\">\n");
- $oP->add("<input type=\"hidden\" name=\"transaction_id\" value=\"".utils::GetNewTransactionId()."\">\n");
- $oP->add($oAppContext->GetForForm());
- $oP->add("<input type=\"hidden\" name=\"selectObject\" value=\"".implode(',',$aSelectObject)."\">\n");
- $sURL = "./UI.php?operation=search&filter=".urlencode($sFilter)."&".$oAppContext->GetForLink();
- $oP->add("<input type=\"button\" value=\"".Dict::S('UI:Button:Cancel')."\" onClick=\"window.location.href='$sURL'\"> \n");
- $oP->add("<button type=\"submit\" class=\"action\"><span>$sActionLabel</span></button>\n");
- $oP->add("</form>\n");
- $oP->add("</div>\n");
- if ($sButtonsPosition != 'bottom')
- {
- // top or both: Displays the ticket details AFTER the actions
- $oP->add('<div class="ui-widget-content">');
- $oObj->DisplayBareProperties($oP);
- $oP->add('</div>');
- }
- $iFieldsCount = count($aFieldsMap);
- $sJsonFieldsMap = json_encode($aFieldsMap);
-
- $oP->add_script(
- <<<EOF
- // Initializes the object once at the beginning of the page...
- var oWizardHelper = new WizardHelper('$sClass', '', '$sTargetState');
- oWizardHelper.SetFieldsMap($sJsonFieldsMap);
- oWizardHelper.SetFieldsCount($iFieldsCount);
- EOF
- );
- $oP->add_ready_script(
- <<<EOF
- // Starts the validation when the page is ready
- CheckFields('apply_stimulus', false);
- $sReadyScript
- EOF
- );
- }
- break;
-
- case 'bulk_apply_stimulus':
- $oP->DisableBreadCrumb();
- $bPreviewMode = utils::ReadPostedParam('preview_mode', false);
- $sFilter = utils::ReadPostedParam('filter', '', false, 'raw_data');
- $sStimulus = utils::ReadPostedParam('stimulus', '');
- $sState = utils::ReadPostedParam('state', '');
- $sSelectObject = utils::ReadPostedParam('selectObject', '', false, 'raw_data');
- $aSelectObject = explode(',', $sSelectObject);
- if (empty($sFilter) || empty($sStimulus) || empty($sState))
- {
- throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'filter', 'stimulus', 'state'));
- }
- $sTransactionId = utils::ReadPostedParam('transaction_id', '');
- if (!utils::IsTransactionValid($sTransactionId))
- {
- $oP->p(Dict::S('UI:Error:ObjectAlreadyUpdated'));
- }
- else
- {
- // For archiving the modification
- $oFilter = DBObjectSearch::unserialize($sFilter);
- $sClass = $oFilter->GetClass();
- $aObjects = array();
- foreach($aSelectObject as $iId)
- {
- $aObjects[] = MetaModel::GetObject($sClass, $iId);
- }
- $aTransitions = MetaModel::EnumTransitions($sClass, $sState);
- $aStimuli = MetaModel::EnumStimuli($sClass);
-
- $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
- $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
-
- $oP->set_title(Dict::Format('UI:StimulusModify_N_ObjectsOf_Class', $sActionLabel, count($aObjects), $sClass));
- $oP->add('<div class="page_header">');
- $oP->add('<h1>'.MetaModel::GetClassIcon($sClass).' '.Dict::Format('UI:StimulusModify_N_ObjectsOf_Class', $sActionLabel, count($aObjects), $sClass).'</h1>');
- $oP->add('</div>');
-
- $oSet = DBObjectSet::FromArray($sClass, $aObjects);
-
- // For reporting
- $aHeaders = array(
- 'object' => array('label' => MetaModel::GetName($sClass), 'description' => Dict::S('UI:ModifiedObject')),
- 'status' => array('label' => Dict::S('UI:BulkModifyStatus'), 'description' => Dict::S('UI:BulkModifyStatus+')),
- 'errors' => array('label' => Dict::S('UI:BulkModifyErrors'), 'description' => Dict::S('UI:BulkModifyErrors+')),
- );
- $aRows = array();
- while ($oObj = $oSet->Fetch())
- {
- $sError = Dict::S('UI:BulkModifyStatusOk');
- try
- {
- $aTransitions = $oObj->EnumTransitions();
- $aStimuli = MetaModel::EnumStimuli($sClass);
- if (!isset($aTransitions[$sStimulus]))
- {
- throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $oObj->GetName(), $oObj->GetStateLabel()));
- }
- else
- {
- $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
- $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
- $sTargetState = $aTransitions[$sStimulus]['target_state'];
- $aExpectedAttributes = $oObj->GetTransitionAttributes($sStimulus /* cureent state */);
- $aDetails = array();
- $aErrors = array();
- foreach($aExpectedAttributes as $sAttCode => $iExpectCode)
- {
- $iFlags = $oObj->GetTransitionFlags($sAttCode, $sStimulus);
- if (($iExpectCode & (OPT_ATT_MUSTCHANGE|OPT_ATT_MUSTPROMPT)) || ($oObj->Get($sAttCode) == '') )
- {
- $paramValue = utils::ReadPostedParam("attr_$sAttCode", '', 'raw_data');
- if ( ($iFlags & OPT_ATT_SLAVE) && ($paramValue != $oObj->Get($sAttCode)) )
- {
- $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
- $aErrors[] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $oAttDef->GetLabel());
- unset($aExpectedAttributes[$sAttCode]);
- }
- }
- }
-
- $oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $sTargetState);
-
- if (count($aErrors) == 0)
- {
- if ($oObj->ApplyStimulus($sStimulus))
- {
- list($bResult, $aErrors) = $oObj->CheckToWrite();
- $sStatus = $bResult ? Dict::S('UI:BulkModifyStatusModified') : Dict::S('UI:BulkModifyStatusSkipped');
- if ($bResult)
- {
- $oObj->DBUpdate();
- }
- else
- {
- $sError = '<p>'.implode('</p></p>',$aErrors)."</p>\n";
- }
- }
- else
- {
- $sStatus = Dict::S('UI:BulkModifyStatusSkipped');
- $sError = '<p>'.Dict::S('UI:FailedToApplyStimuli')."<p>\n";
- }
- }
- else
- {
- $sStatus = Dict::S('UI:BulkModifyStatusSkipped');
- $sError = '<p>'.implode('</p></p>',$aErrors)."</p>\n";
- }
- }
- }
- catch(Exception $e)
- {
- $sError = $e->getMessage();
- $sStatus = Dict::S('UI:BulkModifyStatusSkipped');
- }
- $aRows[] = array(
- 'object' => $oObj->GetHyperlink(),
- 'status' => $sStatus,
- 'errors' => $sError,
- );
- }
- $oP->Table($aHeaders, $aRows);
- // Back to the list
- $sURL = "./UI.php?operation=search&filter=".urlencode($sFilter)."&".$oAppContext->GetForLink();
- $oP->add('<input type="button" onClick="window.location.href=\''.$sURL.'\'" value="'.Dict::S('UI:Button:Done').'">');
- }
- break;
- case 'stimulus': // Form displayed when applying a stimulus (state change)
- $oP->DisableBreadCrumb();
- $sClass = utils::ReadParam('class', '', false, 'class');
- $id = utils::ReadParam('id', '');
- $sStimulus = utils::ReadParam('stimulus', '');
- if ( empty($sClass) || empty($id) || empty($sStimulus) ) // TO DO: check that the class name is valid !
- {
- throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'class', 'id', 'stimulus'));
- }
- $oObj = MetaModel::GetObject($sClass, $id, false);
- if ($oObj != null)
- {
- $oObj->DisplayStimulusForm($oP, $sStimulus);
- }
- else
- {
- $oP->set_title(Dict::S('UI:ErrorPageTitle'));
- $oP->P(Dict::S('UI:ObjectDoesNotExist'));
- }
- break;
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'apply_stimulus': // Actual state change
- $oP->DisableBreadCrumb();
- $sClass = utils::ReadPostedParam('class', '');
- $id = utils::ReadPostedParam('id', '');
- $sTransactionId = utils::ReadPostedParam('transaction_id', '');
- $sStimulus = utils::ReadPostedParam('stimulus', '');
- if ( empty($sClass) || empty($id) || empty($sStimulus) ) // TO DO: check that the class name is valid !
- {
- throw new ApplicationException(Dict::Format('UI:Error:3ParametersMissing', 'class', 'id', 'stimulus'));
- }
- $oObj = MetaModel::GetObject($sClass, $id, false);
- if ($oObj != null)
- {
- $aTransitions = $oObj->EnumTransitions();
- $aStimuli = MetaModel::EnumStimuli($sClass);
- $sMessage = '';
- $sSeverity = 'ok';
- $bDisplayDetails = true;
- if (!isset($aTransitions[$sStimulus]))
- {
- throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $oObj->GetName(), $oObj->GetStateLabel()));
- }
- if (!utils::IsTransactionValid($sTransactionId))
- {
- $sMessage = Dict::S('UI:Error:ObjectAlreadyUpdated');
- $sSeverity = 'info';
- }
- else
- {
- $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
- $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
- $sTargetState = $aTransitions[$sStimulus]['target_state'];
- $aExpectedAttributes = $oObj->GetTransitionAttributes($sStimulus /*, current state*/);
- $aDetails = array();
- $aErrors = array();
- foreach($aExpectedAttributes as $sAttCode => $iExpectCode)
- {
- $iFlags = $oObj->GetTransitionFlags($sAttCode, $sStimulus);
- if (($iExpectCode & (OPT_ATT_MUSTCHANGE|OPT_ATT_MUSTPROMPT)) || ($oObj->Get($sAttCode) == '') )
- {
- $paramValue = utils::ReadPostedParam("attr_$sAttCode", '', 'raw_data');
- if ( ($iFlags & OPT_ATT_SLAVE) && ($paramValue != $oObj->Get($sAttCode)))
- {
- $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
- $aErrors[] = Dict::Format('UI:AttemptingToChangeASlaveAttribute_Name', $oAttDef->GetLabel());
- unset($aExpectedAttributes[$sAttCode]);
- }
- }
- }
-
- $oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $sTargetState);
-
- if (count($aErrors) == 0)
- {
- $sIssues = '';
- $bApplyStimulus = true;
- list($bRes, $aIssues) = $oObj->CheckToWrite(); // Check before trying to write the object
- if ($bRes)
- {
- try
- {
- $bApplyStimulus = $oObj->ApplyStimulus($sStimulus); // will write the object in the DB
- }
- catch(CoreException $e)
- {
- // Rollback to the previous state... by reloading the object from the database and applying the modifications again
- $oObj = MetaModel::GetObject(get_class($oObj), $oObj->GetKey());
- $oObj->UpdateObjectFromPostedForm('', array_keys($aExpectedAttributes), $sTargetState);
- $sIssues = $e->getMessage();
- }
- }
- else
- {
- $sIssues = implode(' ', $aIssues);
- }
-
- if (!$bApplyStimulus)
- {
- $sMessage = Dict::S('UI:FailedToApplyStimuli');
- $sSeverity = 'error';
- }
- else if ($sIssues != '')
- {
-
- $sOwnershipToken = utils::ReadPostedParam('ownership_token', null, false, 'raw_data');
- if ($sOwnershipToken !== null)
- {
- // Release the concurrent lock, if any, a new lock will be re-acquired by DisplayStimulusForm below
- iTopOwnershipLock::ReleaseLock(get_class($oObj), $oObj->GetKey(), $sOwnershipToken);
- }
-
- $bDisplayDetails = false;
- // Found issues, explain and give the user a second chance
- //
- $oObj->DisplayStimulusForm($oP, $sStimulus);
- $sIssueDesc = Dict::Format('UI:ObjectCouldNotBeWritten',$sIssues);
- $oP->add_ready_script("alert('".addslashes($sIssueDesc)."');");
- }
- else
- {
- $sMessage = Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oObj)), $oObj->GetName());
- $sSeverity = 'ok';
- utils::RemoveTransaction($sTransactionId);
- $bLockEnabled = MetaModel::GetConfig()->Get('concurrent_lock_enabled');
- if ($bLockEnabled)
- {
- // Release the concurrent lock, if any
- $sOwnershipToken = utils::ReadPostedParam('ownership_token', null, false, 'raw_data');
- if ($sOwnershipToken !== null)
- {
- // We're done, let's release the lock
- iTopOwnershipLock::ReleaseLock(get_class($oObj), $oObj->GetKey(), $sOwnershipToken);
- }
- }
- }
- }
- else
- {
- $sMessage = implode('</p><p>', $aErrors);
- $sSeverity = 'error';
- }
- }
- if ($bDisplayDetails)
- {
- ReloadAndDisplay($oP, $oObj, 'apply_stimulus', $sMessage, $sSeverity);
- }
- }
- else
- {
- $oP->set_title(Dict::S('UI:ErrorPageTitle'));
- $oP->P(Dict::S('UI:ObjectDoesNotExist'));
- }
- break;
- ///////////////////////////////////////////////////////////////////////////////////////////
-
- case 'swf_navigator': // Graphical display of the relations "impact" / "depends on"
- require_once(APPROOT.'core/simplegraph.class.inc.php');
- require_once(APPROOT.'core/relationgraph.class.inc.php');
- require_once(APPROOT.'core/displayablegraph.class.inc.php');
- $sClass = utils::ReadParam('class', '', false, 'class');
- $id = utils::ReadParam('id', 0);
- $sRelation = utils::ReadParam('relation', 'impact');
- $sDirection = utils::ReadParam('direction', 'down');
- $iGroupingThreshold = utils::ReadParam('g', 5);
- $oObj = MetaModel::GetObject($sClass, $id);
- $iMaxRecursionDepth = MetaModel::GetConfig()->Get('relations_max_depth', 20);
- $aSourceObjects = array($oObj);
- $oP->set_title(MetaModel::GetRelationDescription($sRelation).' '.$oObj->GetName());
- $sPageId = "ui-relation-graph-".$sClass.'::'.$id;
- $sLabel = $oObj->GetName().' '.MetaModel::GetRelationLabel($sRelation);
- $sDescription = MetaModel::GetRelationDescription($sRelation).' '.$oObj->GetName();
- $oP->SetBreadCrumbEntry($sPageId, $sLabel, $sDescription);
- if ($sRelation == 'depends on')
- {
- $sRelation = 'impacts';
- $sDirection = 'up';
- }
- if ($sDirection == 'up')
- {
- $oRelGraph = MetaModel::GetRelatedObjectsUp($sRelation, $aSourceObjects, $iMaxRecursionDepth);
- }
- else
- {
- $oRelGraph = MetaModel::GetRelatedObjectsDown($sRelation, $aSourceObjects, $iMaxRecursionDepth);
- }
-
- $aResults = $oRelGraph->GetObjectsByClass();
- $oDisplayGraph = DisplayableGraph::FromRelationGraph($oRelGraph, $iGroupingThreshold, ($sDirection == 'down'));
-
- $oP->AddTabContainer('Navigator');
- $oP->SetCurrentTabContainer('Navigator');
-
- $sFirstTab = MetaModel::GetConfig()->Get('impact_analysis_first_tab');
- $sContextKey = "itop-config-mgmt/relation_context/$sClass/$sRelation/$sDirection";
-
- // Check if the current object supports Attachments, similar to AttachmentPlugin::IsTargetObject
- $sClassForAttachment = null;
- $iIdForAttachment = null;
- if (class_exists('Attachment'))
- {
- $aAllowedClasses = MetaModel::GetModuleSetting('itop-attachments', 'allowed_classes', array('Ticket'));
- foreach($aAllowedClasses as $sAllowedClass)
- {
- if ($oObj instanceof $sAllowedClass)
- {
- $iIdForAttachment = $id;
- $sClassForAttachment = $sClass;
- }
- }
- }
- $oP->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/tabularfieldsselector.js');
- $oP->add_linked_script(utils::GetAbsoluteUrlAppRoot().'js/jquery.dragtable.js');
- $oP->add_linked_stylesheet(utils::GetAbsoluteUrlAppRoot().'css/dragtable.css');
-
- // Display the tabs
- if ($sFirstTab == 'list')
- {
- DisplayNavigatorListTab($oP, $aResults, $sRelation, $sDirection, $oObj);
- $oP->SetCurrentTab(Dict::S('UI:RelationshipGraph'));
- $oDisplayGraph->Display($oP, $aResults, $sRelation, $oAppContext, array(), $sClassForAttachment, $iIdForAttachment, $sContextKey, array('this' => $oObj));
- DisplayNavigatorGroupTab($oP);
- }
- else
- {
- $oP->SetCurrentTab(Dict::S('UI:RelationshipGraph'));
- $oDisplayGraph->Display($oP, $aResults, $sRelation, $oAppContext, array(), $sClassForAttachment, $iIdForAttachment, $sContextKey, array('this' => $oObj));
- DisplayNavigatorListTab($oP, $aResults, $sRelation, $sDirection, $oObj);
- DisplayNavigatorGroupTab($oP);
- }
- $oP->SetCurrentTab('');
- break;
-
- ///////////////////////////////////////////////////////////////////////////////////////////
-
- case 'kill_lock':
- $oP->DisableBreadCrumb();
- $sClass = utils::ReadParam('class', '');
- $id = utils::ReadParam('id', '');
- iTopOwnershipLock::KillLock($sClass, $id);
- $oObj = MetaModel::GetObject($sClass, $id);
- ReloadAndDisplay($oP, $oObj, 'concurrent_lock_killed', Dict::S('UI:ConcurrentLockKilled'), 'info');
- break;
-
- ///////////////////////////////////////////////////////////////////////////////////////////
- case 'cancel': // An action was cancelled
- $oP->DisableBreadCrumb();
- $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");
- }
- $oP->error(Dict::Format('UI:Error_Details', $e->getHtmlDesc()));
- $oP->output();
- if (MetaModel::IsLogEnabledIssue())
- {
- if (MetaModel::IsValidClass('EventIssue'))
- {
- try
- {
- $oLog = new EventIssue();
-
- $oLog->Set('message', $e->getMessage());
- $oLog->Set('userinfo', '');
- $oLog->Set('issue', $e->GetIssue());
- $oLog->Set('impact', 'Page could not be displayed');
- $oLog->Set('callstack', $e->getTrace());
- $oLog->Set('data', $e->getContextData());
- $oLog->DBInsertNoReload();
- }
- catch(Exception $e)
- {
- IssueLog::Error("Failed to log issue into the DB");
- }
- }
- IssueLog::Error($e->getMessage());
- }
- // For debugging only
- //throw $e;
- }
- catch(Exception $e)
- {
- require_once(APPROOT.'/setup/setuppage.class.inc.php');
- $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError'));
- $oP->add("<h1>".Dict::S('UI:FatalErrorMessage')."</h1>\n");
- $oP->error(Dict::Format('UI:Error_Details', $e->getMessage()));
- $oP->output();
- if (MetaModel::IsLogEnabledIssue())
- {
- if (MetaModel::IsValidClass('EventIssue'))
- {
- try
- {
- $oLog = new EventIssue();
-
- $oLog->Set('message', $e->getMessage());
- $oLog->Set('userinfo', '');
- $oLog->Set('issue', 'PHP Exception');
- $oLog->Set('impact', 'Page could not be displayed');
- $oLog->Set('callstack', $e->getTrace());
- $oLog->Set('data', array());
- $oLog->DBInsertNoReload();
- }
- catch(Exception $e)
- {
- IssueLog::Error("Failed to log issue into the DB");
- }
- }
- IssueLog::Error($e->getMessage());
- }
- }
|