/** * iTop User Portal main page * * @copyright Copyright (C) 2010-2013 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ require_once('../approot.inc.php'); require_once(APPROOT.'/application/application.inc.php'); require_once(APPROOT.'/application/nicewebpage.class.inc.php'); require_once(APPROOT.'/application/wizardhelper.class.inc.php'); /** * Helper to determine the supported types of tickets */ function GetTicketClasses() { $aClasses = array(); foreach (explode(',', MetaModel::GetConfig()->Get('portal_tickets')) as $sRawClass) { $sRawClass = trim($sRawClass); if (!MetaModel::IsValidClass($sRawClass)) { throw new Exception("Class '$sRawClass' is not a valid class, please review your configuration (portal_tickets)"); } if (!MetaModel::IsParentClass('Ticket', $sRawClass)) { throw new Exception("Class '$sRawClass' does not inherit from Ticket, please review your configuration (portal_tickets)"); } $aClasses[] = $sRawClass; } return $aClasses; } /** * Helper to protect the portal against malicious usages * Throws an exception if the current user is not allowed to view the object details */ function ValidateObject($oObject) { if (IsPowerUser()) { $sValidationDefine = 'PORTAL_'.strtoupper(get_class($oObject)).'_DISPLAY_POWERUSER_QUERY'; } else { $sValidationDefine = 'PORTAL_'.strtoupper(get_class($oObject)).'_DISPLAY_QUERY'; } if (defined($sValidationDefine)) { $sValidationOql = constant($sValidationDefine); $oSearch = DBObjectSearch::FromOQL($sValidationOql); $oSearch->AddCondition('id', $oObject->GetKey()); if ($iUser = UserRights::GetContactId()) { $oContact = MetaModel::GetObject('Contact', $iUser); $aArgs = $oContact->ToArgs('contact'); } else { $aArgs = array(); } $oSet = new DBObjectSet($oSearch, array(), $aArgs); if ($oSet->Count() == 0) { throw new SecurityException('You are not allowed to access the object '.get_class($oObject).'::'.$oObject->GetKey()); } } } /** * Helper to get the relevant constant */ function GetConstant($sClass, $sName) { $sConstName = 'PORTAL_'.strtoupper($sClass).'_'.$sName; if (defined($sConstName)) { return constant($sConstName); } else { throw new Exception("Missing portal constant '$sConstName'"); } } /** * Helper to determine the ticket class given the service subcategory */ function ComputeClass($iSubSvcId) { $aClasses = GetTicketClasses(); if ((PORTAL_SET_TYPE_FROM == '') || (PORTAL_TYPE_TO_CLASS == '')) { // return the first enabled class $sClass = reset($aClasses); } else { $oServiceSubcat = MetaModel::GetObject('ServiceSubcategory', $iSubSvcId, true, true /* allow all data*/); $sTicketType = $oServiceSubcat->Get(PORTAL_SET_TYPE_FROM); $aMapping = json_decode(PORTAL_TYPE_TO_CLASS, true); if (!array_key_exists($sTicketType, $aMapping)) { throw new Exception("Ticket type '$sTicketType' not found in the mapping (".implode(', ', array_keys($aMapping))."). Please contact your administrator."); } $sClass = $aMapping[$sTicketType]; if (!in_array($sClass, $aClasses)) { throw new Exception("Service subcategory #$iSubSvcId has a ticket type ($sClass) that is not known by the portal, please contact your administrator."); } } return $sClass; } /** * Helper to limit the service categories depending on the current settings */ function RestrictSubcategories(&$oSearch) { $aMapping = (PORTAL_TYPE_TO_CLASS == '') ? array() : json_decode(PORTAL_TYPE_TO_CLASS, true); foreach($aMapping as $sTicketType => $sClass) { if (!in_array($sClass, GetTicketClasses())) { // Exclude this value for the result set $oSearch->AddCondition(PORTAL_SET_TYPE_FROM, $sTicketType, '!='); } } } /** * Displays the portal main menu * @param WebPage $oP The current web page * @return void */ function DisplayMainMenu(WebPage $oP) { $oP->AddMenuButton('showongoing', 'Portal:ShowOngoing', '../portal/index.php?operation=show_ongoing'); $oP->AddMenuButton('newrequest', 'Portal:CreateNewRequest', '../portal/index.php?operation=create_request'); $oP->AddMenuButton('showclosed', 'Portal:ShowClosed', '../portal/index.php?operation=show_closed'); if (UserRights::CanChangePassword()) { $oP->AddMenuButton('change_pwd', 'Portal:ChangeMyPassword', '../portal/index.php?loginop=change_pwd'); } } /** * Displays the current tickets * @param WebPage $oP The current web page * @return void */ function ShowOngoingTickets(WebPage $oP) { $oP->add("
"); $oP->p(" ".$oService->GetAsHTML('description')." |
"); $oP->add(""); $oP->add(" | "); $oP->add("");
$oP->add(" "); $oP->add(" ".$oSubService->GetAsHTML('description')." "); $oP->add(" | ");
$oP->add("
"); $oP->p(""); $oP->add(" | "); $oP->add(""); $oP->p(""); $oP->p($oTemplate->GetAsHTML('description')); $oP->add(" | "); $oP->add("
'); $oP->DisplayObjectDetails($oObj, $aAttList['col:left']); $oP->add(' | '); $oP->add(''); $oP->DisplayObjectDetails($oObj, $aAttList['col:right']); $oP->add(' | '); $oP->add('
'); $oP->DisplayObjectDetails($oObj, $aAttList['centered']); $oP->add(' | '); $oP->add('|
'); $oAttPlugin = new AttachmentPlugIn(); if ($bEditAttachments) { $oAttPlugin->EnableDelete(false); $oAttPlugin->OnDisplayRelations($oObj, $oP, true /* edit */); } else { $oAttPlugin->OnDisplayRelations($oObj, $oP, false /* read */); } $oP->add(' | '); $oP->add('|
'); //$oP->add(" |