ReadAllParams(PORTAL_ALL_PARAMS);
+ $aParameters = $oP->ReadAllParams(PORTAL_ALL_PARAMS.',template_id');
+
if ($iSvcId != null)
{
$aParameters['service_id'] = $iSvcId;
@@ -230,17 +221,130 @@ EOF
{
$aParameters['servicesubcategory_id'] = $iSubSvcId;
}
+
+ $iDefaultTemplate = isset($aParameters['template_id']) ? $aParameters['template_id'] : 0;
+ if (MetaModel::IsValidClass('Template'))
+ {
+ $oSearch = DBObjectSearch::FromOQL(REQUEST_TEMPLATE_QUERY);
+ $oSearch->AllowAllData();
+ $oSet = new CMDBObjectSet($oSearch, array(), array(
+ 'service_id' => $aParameters['service_id'],
+ 'servicesubcategory_id' => $aParameters['servicesubcategory_id']
+ ));
+ if ($oSet->Count() == 0)
+ {
+ RequestCreationForm($oP, $oUserOrg, $aParameters['service_id'], $aParameters['servicesubcategory_id']);
+ return;
+ }
+ elseif ($oSet->Count() == 1)
+ {
+ $oTemplate = $oSet->Fetch();
+ $iTemplateId = $oTemplate->GetKey();
+ RequestCreationForm($oP, $oUserOrg, $aParameters['service_id'], $aParameters['servicesubcategory_id'], $iTemplateId);
+ return;
+ }
+
+ $oServiceSubCategory = MetaModel::GetObject('ServiceSubcategory', $aParameters['servicesubcategory_id'], false);
+ if (is_object($oServiceSubCategory))
+ {
+ $oP->add("\n");
+ }
+ else
+ {
+ $oP->p("Error: Invalid servicesubcategory_id = ".$aParameters['servicesubcategory_id']);
+ }
+ }
+ else
+ {
+ RequestCreationForm($oP, $oUserOrg, $aParameters['service_id'], $aParameters['servicesubcategory_id']);
+ return;
+ }
+}
+
+/**
+ * Displays the form for the final step of the UserRequest creation
+ * @param WebPage $oP The current web page for the form output
+ * @param Organization $oUserOrg The organization of the current user
+ * @param integer $iSvcId The identifier of the service (fall through when there is only one service)
+ * @param integer $iSubSvcId The identifier of the sub-service (fall through when there is only one sub-service)
+ * @param integer $iTemplateId The identifier of the template (fall through when there is only one template)
+ * @return void
+ */
+function RequestCreationForm($oP, $oUserOrg, $iSvcId = null, $iSubSvcId = null, $iTemplateId = null)
+{
+ $oP->add_script(
+<<ReadAllParams(PORTAL_ALL_PARAMS.',template_id');
+ if ($iSvcId != null)
+ {
+ $aParameters['service_id'] = $iSvcId;
+ }
+ if ($iSubSvcId != null)
+ {
+ $aParameters['servicesubcategory_id'] = $iSubSvcId;
+ }
+ if ($iTemplateId != null)
+ {
+ $aParameters['template_id'] = $iTemplateId;
+ }
// Example: $aList = array('title', 'description', 'impact', 'emergency');
$aList = explode(',', PORTAL_REQUEST_FORM_ATTRIBUTES);
$sDescription = '';
- if (isset($aParameters['template_id']))
+ if (isset($aParameters['template_id']) && ($aParameters['template_id'] != 0))
{
+ $aTemplateFields = array();
$oTemplate = MetaModel::GetObject('Template', $aParameters['template_id'], false);
if (is_object($oTemplate))
{
- $sDescription = htmlentities($oTemplate->Get('template'), ENT_QUOTES, 'UTF-8');
+ $oFieldSearch = DBObjectSearch::FromOQL('SELECT TemplateField WHERE template_id = :template_id');
+ $oFieldSearch->AllowAllData();
+ $oFieldSet = new DBObjectSet($oFieldSearch, array('order' => true), array('template_id' => $oTemplate->GetKey()));
+ while($oField = $oFieldSet->Fetch())
+ {
+ $sAttCode = $oField->Get('code');
+ if (isset($aParameters[$sAttCode]))
+ {
+ $oField->Set('initial_value', $aParameters[$sAttCode]);
+ }
+ $aTemplateFields[$sAttCode] = $oField;
+ }
}
}
@@ -286,7 +390,27 @@ EOF
$sValue = "".$oRequest->GetFormElementForField($oP, get_class($oRequest), $sAttCode, $oAttDef, $value, '', 'attr_'.$sAttCode, '', $iFlags, $aArgs).'';
$aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sValue);
}
- $aDetails[] = array('label' => MetaModel::GetLabel('UserRequest', PORTAL_ATTCODE_LOG), 'value' => '');
+// The log must be requested in the constant PORTAL_REQUEST_FORM_ATTRIBUTES
+// $aDetails[] = array('label' => MetaModel::GetLabel('UserRequest', PORTAL_ATTCODE_LOG), 'value' => '');
+
+ if (!empty($aTemplateFields))
+ {
+ foreach ($aTemplateFields as $sAttCode => $oField)
+ {
+ if (!in_array($sAttCode, $aList))
+ {
+ $sValue = $oField->GetFormElement($oP, get_class($oRequest));
+ if ($oField->Get('input_type') == 'hidden')
+ {
+ $aHidden[] = $sValue;
+ }
+ else
+ {
+ $aDetails[] = array('label' => $oField->GetAsHTML('label'), 'value' => $sValue);
+ }
+ }
+ }
+ }
$oP->add_linked_script("../js/json.js");
$oP->add_linked_script("../js/forms-json-utils.js");
@@ -297,7 +421,7 @@ EOF
$oP->add_linked_script("../js/jquery.blockUI.js");
$oP->add("