/**
  * Displays one step of the wizard
  */
 public function DisplayWizardStep($aStep, $iStepIndex, &$iMaxInputId, &$aFieldsMap, $bFinishEnabled = false, $aArgs = array())
 {
     if ($iStepIndex == 1) {
         $this->m_oPage->add("<form method=\"post\" enctype=\"multipart/form-data\" action=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/UI.php\">\n");
     }
     $this->m_oPage->add("<div class=\"wizContainer\" id=\"wizStep{$iStepIndex}\" style=\"display:none;\">\n");
     $this->m_oPage->add("<a name=\"step{$iStepIndex}\" />\n");
     $aStates = MetaModel::EnumStates($this->m_sClass);
     $aDetails = array();
     $sJSHandlerCode = '';
     // Javascript code to be executed each time this step of the wizard is entered
     foreach ($aStep as $sAttCode) {
         $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
         if ($oAttDef->IsWritable()) {
             $sAttLabel = $oAttDef->GetLabel();
             $iOptions = isset($aStates[$this->m_sTargetState]['attribute_list'][$sAttCode]) ? $aStates[$this->m_sTargetState]['attribute_list'][$sAttCode] : 0;
             $aPrerequisites = $oAttDef->GetPrerequisiteAttributes();
             if ($iOptions & (OPT_ATT_MANDATORY | OPT_ATT_MUSTCHANGE | OPT_ATT_MUSTPROMPT)) {
                 $aFields[$sAttCode] = array();
                 foreach ($aPrerequisites as $sCode) {
                     $aFields[$sAttCode][$sCode] = '';
                 }
             }
             if (count($aPrerequisites) > 0) {
                 $aOptions[] = 'Prerequisites: ' . implode(', ', $aPrerequisites);
             }
             $sFieldFlag = $iOptions & (OPT_ATT_MANDATORY | OPT_ATT_MUSTCHANGE) || !$oAttDef->IsNullAllowed() ? ' <span class="hilite">*</span>' : '';
             $oDefaultValuesSet = $oAttDef->GetDefaultValue();
             // @@@ TO DO: get the object's current value if the object exists
             $sHTMLValue = cmdbAbstractObject::GetFormElementForField($this->m_oPage, $this->m_sClass, $sAttCode, $oAttDef, $oDefaultValuesSet, '', "att_{$iMaxInputId}", '', $iOptions, $aArgs);
             $aFieldsMap["att_{$iMaxInputId}"] = $sAttCode;
             $aDetails[] = array('label' => '<span title="' . $oAttDef->GetDescription() . '">' . $oAttDef->GetLabel() . $sFieldFlag . '</span>', 'value' => "<span id=\"field_att_{$iMaxInputId}\">{$sHTMLValue}</span>");
             if ($oAttDef->GetValuesDef() != null) {
                 $sJSHandlerCode .= "\toWizardHelper.RequestAllowedValues('{$sAttCode}');\n";
             }
             if ($oAttDef->GetDefaultValue() != null) {
                 $sJSHandlerCode .= "\toWizardHelper.RequestDefaultValue('{$sAttCode}');\n";
             }
             if ($oAttDef->IsLinkSet()) {
                 $sJSHandlerCode .= "\toLinkWidgetatt_{$iMaxInputId}.Init();";
             }
             $iMaxInputId++;
         }
     }
     //$aDetails[] = array('label' => '', 'value' => '<input type="button" value="Next &gt;&gt;">');
     $this->m_oPage->details($aDetails);
     $sBackButtonDisabled = $iStepIndex <= 1 ? 'disabled' : '';
     $sDisabled = $bFinishEnabled ? '' : 'disabled';
     $nbSteps = count($this->m_aWizardSteps['mandatory']) + count($this->m_aWizardSteps['optional']);
     $this->m_oPage->add("<div style=\"text-align:center\">\r\n\t\t<input type=\"button\" value=\"" . Dict::S('UI:Button:Back') . "\" {$sBackButtonDisabled} onClick=\"GoToStep({$iStepIndex}, {$iStepIndex} - 1)\" />\r\n\t\t<input type=\"button\" value=\"" . Dict::S('UI:Button:Next') . "\" onClick=\"GoToStep({$iStepIndex}, 1+{$iStepIndex})\" />\r\n\t\t<input type=\"button\" value=\"" . Dict::S('UI:Button:Finish') . "\" {$sDisabled} onClick=\"GoToStep({$iStepIndex}, 1+{$nbSteps})\" />\r\n\t\t</div>\n");
     $this->m_oPage->add_script("\r\nfunction OnEnterStep{$iStepIndex}()\r\n{\r\n\toWizardHelper.ResetQuery();\r\n\toWizardHelper.UpdateWizard();\r\n\t\r\n{$sJSHandlerCode}\r\n\r\n\toWizardHelper.AjaxQueryServer();\r\n}\r\n");
     $this->m_oPage->add("</div>\n\n");
 }
    public function DisplayStimulusForm(WebPage $oPage, $sStimulus)
    {
        $sClass = get_class($this);
        $iKey = $this->GetKey();
        $aTransitions = $this->EnumTransitions();
        $aStimuli = MetaModel::EnumStimuli($sClass);
        if (!isset($aTransitions[$sStimulus])) {
            // Invalid stimulus
            throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $this->GetName(), $this->GetStateLabel()));
        }
        // Check for concurrent access lock
        $LockEnabled = MetaModel::GetConfig()->Get('concurrent_lock_enabled');
        $sOwnershipToken = null;
        if ($LockEnabled) {
            $sOwnershipToken = utils::ReadPostedParam('ownership_token', null, false, 'raw_data');
            $aLockInfo = iTopOwnershipLock::AcquireLock($sClass, $iKey);
            if ($aLockInfo['success']) {
                $sOwnershipToken = $aLockInfo['token'];
                $sOwnershipDate = $aLockInfo['acquired'];
            } else {
                $oOwner = $aLockInfo['lock']->GetOwner();
                // If the object is locked by the current user, it's worth trying again, since
                // the lock may be released by 'onunload' which is called AFTER loading the current page.
                //$bTryAgain = $oOwner->GetKey() == UserRights::GetUserId();
                self::ReloadAndDisplay($oPage, $this, array('operation' => 'stimulus', 'stimulus' => $sStimulus));
                return;
            }
        }
        $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
        $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
        $aTransition = $aTransitions[$sStimulus];
        $sTargetState = $aTransition['target_state'];
        $aTargetStates = MetaModel::EnumStates($sClass);
        $oPage->add("<div class=\"page_header\">\n");
        $oPage->add("<h1>{$sActionLabel} - <span class=\"hilite\">{$this->GetName()}</span></h1>\n");
        $oPage->set_title($sActionLabel);
        $oPage->add("</div>\n");
        $aTargetState = $aTargetStates[$sTargetState];
        $aExpectedAttributes = $aTargetState['attribute_list'];
        $oPage->add("<h1>{$sActionDetails}</h1>\n");
        $sButtonsPosition = MetaModel::GetConfig()->Get('buttons_position');
        if ($sButtonsPosition == 'bottom') {
            // bottom: Displays the ticket details BEFORE the actions
            $oPage->add('<div class="ui-widget-content">');
            $this->DisplayBareProperties($oPage);
            $oPage->add('</div>');
        }
        $oPage->add("<div class=\"wizContainer\">\n");
        $oPage->add("<form id=\"apply_stimulus\" method=\"post\" onSubmit=\"return OnSubmit('apply_stimulus');\">\n");
        $aDetails = array();
        $iFieldIndex = 0;
        $aFieldsMap = array();
        // The list of candidate fields is made of the ordered list of "details" attributes + other attributes
        $aAttributes = array();
        foreach ($this->FlattenZList(MetaModel::GetZListItems($sClass, 'details')) as $sAttCode) {
            $aAttributes[$sAttCode] = true;
        }
        foreach (MetaModel::GetAttributesList($sClass) as $sAttCode) {
            if (!array_key_exists($sAttCode, $aAttributes)) {
                $aAttributes[$sAttCode] = true;
            }
        }
        // Order the fields based on their dependencies, set the fields for which there is only one possible value
        // and perform this in the order of dependencies to avoid dead-ends
        $aDeps = array();
        foreach ($aAttributes as $sAttCode => $trash) {
            $aDeps[$sAttCode] = MetaModel::GetPrerequisiteAttributes($sClass, $sAttCode);
        }
        $aList = $this->OrderDependentFields($aDeps);
        foreach ($aList as $sAttCode) {
            // Consider only the "expected" fields for the target state
            if (array_key_exists($sAttCode, $aExpectedAttributes)) {
                $iExpectCode = $aExpectedAttributes[$sAttCode];
                // 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 && $this->Get($sAttCode) == '') {
                    $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
                    $aArgs = array('this' => $this);
                    // If the field is mandatory, set it to the only possible value
                    if (!$oAttDef->IsNullAllowed() || $iExpectCode & OPT_ATT_MANDATORY) {
                        if ($oAttDef->IsExternalKey()) {
                            $oAllowedValues = MetaModel::GetAllowedValuesAsObjectSet($sClass, $sAttCode, $aArgs);
                            if ($oAllowedValues->Count() == 1) {
                                $oRemoteObj = $oAllowedValues->Fetch();
                                $this->Set($sAttCode, $oRemoteObj->GetKey());
                            }
                        } else {
                            $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
                            if (count($aAllowedValues) == 1) {
                                $aValues = array_keys($aAllowedValues);
                                $this->Set($sAttCode, $aValues[0]);
                            }
                        }
                    }
                    $sHTMLValue = cmdbAbstractObject::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $this->Get($sAttCode), $this->GetEditValue($sAttCode), 'att_' . $iFieldIndex, '', $iExpectCode, $aArgs);
                    $aDetails[] = array('label' => '<span>' . $oAttDef->GetLabel() . '</span>', 'value' => "<span id=\"field_att_{$iFieldIndex}\">{$sHTMLValue}</span>");
                    $aFieldsMap[$sAttCode] = 'att_' . $iFieldIndex;
                    $iFieldIndex++;
                }
            }
        }
        $oPage->add('<table><tr><td>');
        $oPage->details($aDetails);
        $oPage->add('</td></tr></table>');
        $oPage->add("<input type=\"hidden\" name=\"id\" value=\"" . $this->GetKey() . "\" id=\"id\">\n");
        $aFieldsMap['id'] = 'id';
        $oPage->add("<input type=\"hidden\" name=\"class\" value=\"{$sClass}\">\n");
        $oPage->add("<input type=\"hidden\" name=\"operation\" value=\"apply_stimulus\">\n");
        $oPage->add("<input type=\"hidden\" name=\"stimulus\" value=\"{$sStimulus}\">\n");
        $iTransactionId = utils::GetNewTransactionId();
        $oPage->add("<input type=\"hidden\" name=\"transaction_id\" value=\"" . $iTransactionId . "\">\n");
        if ($sOwnershipToken !== null) {
            $oPage->add("<input type=\"hidden\" name=\"ownership_token\" value=\"" . htmlentities($sOwnershipToken, ENT_QUOTES, 'UTF-8') . "\">\n");
        }
        $oAppContext = new ApplicationContext();
        $oPage->add($oAppContext->GetForForm());
        $oPage->add("<button type=\"button\" class=\"action cancel\" onClick=\"BackToDetails('{$sClass}', " . $this->GetKey() . ", '', '{$sOwnershipToken}')\"><span>" . Dict::S('UI:Button:Cancel') . "</span></button>&nbsp;&nbsp;&nbsp;&nbsp;\n");
        $oPage->add("<button type=\"submit\" class=\"action\"><span>{$sActionLabel}</span></button>\n");
        $oPage->add("</form>\n");
        $oPage->add("</div>\n");
        if ($sButtonsPosition != 'top') {
            // bottom or both: Displays the ticket details AFTER the actions
            $oPage->add('<div class="ui-widget-content">');
            $this->DisplayBareProperties($oPage);
            $oPage->add('</div>');
        }
        $iFieldsCount = count($aFieldsMap);
        $sJsonFieldsMap = json_encode($aFieldsMap);
        $oPage->add_script(<<<EOF
\t\t// Initializes the object once at the beginning of the page...
\t\tvar oWizardHelper = new WizardHelper('{$sClass}', '', '{$sTargetState}');
\t\toWizardHelper.SetFieldsMap({$sJsonFieldsMap});
\t\toWizardHelper.SetFieldsCount({$iFieldsCount});
EOF
);
        $sJSToken = json_encode($sOwnershipToken);
        $oPage->add_ready_script(<<<EOF
\t\t// Starts the validation when the page is ready
\t\tCheckFields('apply_stimulus', false);
\t\t\$(window).unload(function() { return OnUnload('{$iTransactionId}', '{$sClass}', {$iKey}, {$sJSToken}) } );
EOF
);
        if ($sOwnershipToken !== null) {
            $this->GetOwnershipJSHandler($oPage, $sOwnershipToken);
        }
    }
Beispiel #3
0
                 $sHTMLValue = "<span id=\"field_{$sId}\">" . $oObj->GetAsHTML($sAttCode);
                 $sHTMLValue .= '<input type="hidden" id="' . $sId . '" name="attr_' . $sFormPrefix . $sAttCode . '" value="' . htmlentities($oObj->Get($sAttCode), ENT_QUOTES, 'UTF-8') . '"/></span>';
                 $oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
             } else {
                 // It may happen that the field we'd like to update does not
                 // exist in the form. For example, if the field should be hidden/read-only
                 // in the current state of the object
                 $value = $oObj->Get($sAttCode);
                 $displayValue = $oObj->GetEditValue($sAttCode);
                 $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
                 if (!$oAttDef->IsWritable()) {
                     // Even non-writable fields (like AttributeExternal) can be refreshed
                     $sHTMLValue = $oObj->GetAsHTML($sAttCode);
                 } else {
                     $iFlags = MetaModel::GetAttributeFlags($sClass, $oObj->GetState(), $sAttCode);
                     $sHTMLValue = cmdbAbstractObject::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value, $displayValue, $sId, '', $iFlags, array('this' => $oObj, 'formPrefix' => $sFormPrefix));
                     // Make sure that we immediately validate the field when we reload it
                     $oPage->add_ready_script("\$('#{$sId}').trigger('validate');");
                 }
                 $oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
             }
         }
     }
     $oPage->add_script("oWizardHelper{$sFormPrefix}.m_oData=" . $oWizardHelper->ToJSON() . ";\noWizardHelper{$sFormPrefix}.UpdateFields();\n");
     break;
 case 'obj_creation_form':
     $oPage->SetContentType('text/html');
     $sJson = utils::ReadParam('json_obj', '', false, 'raw_data');
     $oWizardHelper = WizardHelper::FromJSON($sJson);
     $oObj = $oWizardHelper->GetTargetObject();
     $sClass = $oWizardHelper->GetTargetClass();
 public function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
 {
     if (!$this->IsNew()) {
         $oPage->SetCurrentTab(Dict::S('Core:SynchroAttributes'));
         $oAttributeSet = $this->Get('attribute_list');
         $aAttributes = array();
         while ($oAttribute = $oAttributeSet->Fetch()) {
             $aAttributes[$oAttribute->Get('attcode')] = $oAttribute;
         }
         // Columns of the form
         $aAttribs = array();
         foreach (array('attcode', 'reconciliation', 'update', 'update_policy', 'reconciliation_attcode') as $s) {
             $aAttribs[$s] = array('label' => Dict::S("Core:SynchroAtt:{$s}"), "description" => Dict::S("Core:SynchroAtt:{$s}+"));
         }
         // Rows of the form
         $aValues = array();
         foreach (MetaModel::ListAttributeDefs($this->GetTargetClass()) as $sAttCode => $oAttDef) {
             if ($oAttDef->IsWritable()) {
                 if (isset($aAttributes[$sAttCode])) {
                     $oAttribute = $aAttributes[$sAttCode];
                 } else {
                     if ($oAttDef->IsExternalKey()) {
                         $oAttribute = new SynchroAttExtKey();
                         $oAttribute->Set('reconciliation_attcode', '');
                         // Blank means by pkey
                     } elseif ($oAttDef->IsLinkSet() && $oAttDef->IsIndirect()) {
                         $oAttribute = new SynchroAttLinkSet();
                         // Todo - add these settings into the form
                         $oAttribute->Set('row_separator', MetaModel::GetConfig()->Get('link_set_item_separator'));
                         $oAttribute->Set('attribute_separator', MetaModel::GetConfig()->Get('link_set_attribute_separator'));
                         $oAttribute->Set('value_separator', MetaModel::GetConfig()->Get('link_set_value_separator'));
                         $oAttribute->Set('attribute_qualifier', MetaModel::GetConfig()->Get('link_set_attribute_qualifier'));
                     } elseif ($oAttDef->IsScalar()) {
                         $oAttribute = new SynchroAttribute();
                     } else {
                         $oAttribute = null;
                     }
                     if (!is_null($oAttribute)) {
                         $oAttribute->Set('sync_source_id', $this->GetKey());
                         $oAttribute->Set('attcode', $sAttCode);
                         $oAttribute->Set('reconcile', MetaModel::IsReconcKey($this->GetTargetClass(), $sAttCode) ? 1 : 0);
                         $oAttribute->Set('update', 1);
                         $oAttribute->Set('update_policy', 'master_locked');
                     }
                 }
                 if (!is_null($oAttribute)) {
                     if (!$bEditMode) {
                         // Read-only mode
                         $aRow['reconciliation'] = $oAttribute->Get('reconcile') == 1 ? Dict::S('Core:SynchroReconcile:Yes') : Dict::S('Core:SynchroReconcile:No');
                         $aRow['update'] = $oAttribute->Get('update') == 1 ? Dict::S('Core:SynchroUpdate:Yes') : Dict::S('Core:SynchroUpdate:No');
                         $aRow['attcode'] = MetaModel::GetLabel($this->GetTargetClass(), $oAttribute->Get('attcode')) . ' (' . $oAttribute->Get('attcode') . ')';
                         $aRow['update_policy'] = $oAttribute->GetAsHTML('update_policy');
                         if ($oAttDef->IsExternalKey()) {
                             $aRow['reconciliation_attcode'] = $oAttribute->GetAsHTML('reconciliation_attcode');
                         } else {
                             $aRow['reconciliation_attcode'] = '&nbsp;';
                         }
                     } else {
                         // Edit mode
                         $sAttCode = $oAttribute->Get('attcode');
                         $sChecked = $oAttribute->Get('reconcile') == 1 ? 'checked' : '';
                         $aRow['reconciliation'] = "<input type=\"checkbox\" name=\"reconciliation[{$sAttCode}]\" {$sChecked}/>";
                         $sChecked = $oAttribute->Get('update') == 1 ? 'checked' : '';
                         $aRow['update'] = "<input type=\"checkbox\" name=\"update[{$sAttCode}]\" {$sChecked}/>";
                         $aRow['attcode'] = MetaModel::GetLabel($this->GetTargetClass(), $oAttribute->Get('attcode')) . ' (' . $oAttribute->Get('attcode') . ')';
                         $oUpdateAttDef = MetaModel::GetAttributeDef(get_class($oAttribute), 'update_policy');
                         $aRow['update_policy'] = cmdbAbstractObject::GetFormElementForField($oPage, get_class($oAttribute), 'update_policy', $oUpdateAttDef, $oAttribute->Get('update_policy'), '', 'update_policy_' . $sAttCode, "[{$sAttCode}]");
                         if ($oAttDef->IsExternalKey()) {
                             $aRow['reconciliation_attcode'] = $oAttribute->GetReconciliationFormElement($oAttDef->GetTargetClass(), "attr_reconciliation_attcode[{$sAttCode}]");
                         } else {
                             $aRow['reconciliation_attcode'] = '&nbsp;';
                         }
                     }
                     $aValues[] = $aRow;
                 }
             }
         }
         $oPage->p(Dict::Format('Class:SynchroDataSource:DataTable', $this->GetDataTable()));
         $oPage->Table($aAttribs, $aValues);
         $this->DisplayStatusTab($oPage);
     }
     parent::DisplayBareRelations($oPage, $bEditMode);
 }
Beispiel #5
0
/**
 * Create form to apply a stimulus
 * @param WebPage $oP The current web page
 * @param Object $oObj The target object
 * @param String $sStimulusCode Stimulus that will be applied
 * @param Array $aEditAtt List of attributes to edit
 * @return void
 */
function MakeStimulusForm(WebPage $oP, $oObj, $sStimulusCode, $aEditAtt)
{
    static $bHasStimulusForm = false;
    $sDialogId = $sStimulusCode . "_dialog";
    $sFormId = $sStimulusCode . "_form";
    $sCancelButtonLabel = Dict::S('UI:Button:Cancel');
    $oP->add('<div id="' . $sDialogId . '" style="display: none;">');
    $sClass = get_class($oObj);
    $oP->add('<form id="' . $sFormId . '" method="post">');
    $sTransactionId = utils::GetNewTransactionId();
    $oP->add("<input type=\"hidden\" id=\"transaction_id\" name=\"transaction_id\" value=\"{$sTransactionId}\">\n");
    $oP->add("<input type=\"hidden\" name=\"class\" value=\"{$sClass}\">");
    $oP->add("<input type=\"hidden\" name=\"id\" value=\"" . $oObj->GetKey() . "\">");
    $oP->add("<input type=\"hidden\" name=\"operation\" value=\"update_request\">");
    $oP->add("<input type=\"hidden\" id=\"stimulus_to_apply\" name=\"apply_stimulus\" value=\"{$sStimulusCode}\">\n");
    foreach ($aEditAtt as $sAttCode) {
        $sValue = $oObj->Get($sAttCode);
        $sDisplayValue = $oObj->GetEditValue($sAttCode);
        $aArgs = array('this' => $oObj, 'formPrefix' => '');
        $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
        $sInputId = 'input_' . $sAttCode;
        $sHTMLValue = "<span id=\"field_{$sStimulusCode}_{$sInputId}\">" . cmdbAbstractObject::GetFormElementForField($oP, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', 0, $aArgs) . '</span>';
        $oP->add('<h1>' . MetaModel::GetLabel($sClass, $sAttCode) . '</h1>');
        $oP->add($sHTMLValue);
    }
    $oP->add('</form>');
    $oP->add('</div>');
    if (!$bHasStimulusForm) {
        $bHasStimulusForm = true;
        $oP->add_script(<<<EOF

function RunStimulusDialog(sStimulusCode, sTitle, sOkButtonLabel)
{
\tvar sWidth = 'auto';
\tif (sStimulusCode == 'ev_reopen')
\t{
\t\t// Avoid having a dialog spanning the complete width of the window
\t\t// just because it contains a CaseLog entry
\t\tsWidth = '80%';
\t}
\t\t\t\t
\t\$('#'+sStimulusCode+'_dialog').dialog({
\t\theight: 'auto',
\t\twidth: sWidth,
\t\tmodal: true,
\t\ttitle: sTitle,
\t\tbuttons: [
\t\t{ text: sOkButtonLabel, click: function() {
\t\t\t\$(this).find('#'+sStimulusCode+'_form').submit();
\t\t} },
\t\t{ text: "{$sCancelButtonLabel}", click: function() {
\t\t\t\$(this).dialog( "close" );
\t\t} }
\t\t]
\t});
\t// Start the validation
\tCheckFields(sStimulusCode+'_form', false);
\t\$('#'+sStimulusCode+'_form').submit( function() {
\t\treturn OnSubmit(sStimulusCode+'_form');
\t});
}
EOF
);
    }
}
    public function DisplayStimulusForm(WebPage $oPage, $sStimulus)
    {
        $sClass = get_class($this);
        $aTransitions = $this->EnumTransitions();
        $aStimuli = MetaModel::EnumStimuli($sClass);
        if (!isset($aTransitions[$sStimulus])) {
            // Invalid stimulus
            throw new ApplicationException(Dict::Format('UI:Error:Invalid_Stimulus_On_Object_In_State', $sStimulus, $this->GetName(), $this->GetStateLabel()));
        }
        $sActionLabel = $aStimuli[$sStimulus]->GetLabel();
        $sActionDetails = $aStimuli[$sStimulus]->GetDescription();
        $aTransition = $aTransitions[$sStimulus];
        $sTargetState = $aTransition['target_state'];
        $aTargetStates = MetaModel::EnumStates($sClass);
        $oPage->add("<div class=\"page_header\">\n");
        $oPage->add("<h1>{$sActionLabel} - <span class=\"hilite\">{$this->GetName()}</span></h1>\n");
        $oPage->set_title($sActionLabel);
        $oPage->add("</div>\n");
        $aTargetState = $aTargetStates[$sTargetState];
        $aExpectedAttributes = $aTargetState['attribute_list'];
        $oPage->add("<h1>{$sActionDetails}</h1>\n");
        $sButtonsPosition = MetaModel::GetConfig()->Get('buttons_position');
        if ($sButtonsPosition == 'bottom') {
            // bottom: Displays the ticket details BEFORE the actions
            $oPage->add('<div class="ui-widget-content">');
            $this->DisplayBareProperties($oPage);
            $oPage->add('</div>');
        }
        $oPage->add("<div class=\"wizContainer\">\n");
        $oPage->add("<form id=\"apply_stimulus\" method=\"post\" onSubmit=\"return OnSubmit('apply_stimulus');\">\n");
        $aDetails = array();
        $iFieldIndex = 0;
        $aFieldsMap = array();
        $aDetailsList = $this->FlattenZList(MetaModel::GetZListItems($sClass, 'details'));
        // Order the fields based on their dependencies, set the fields for which there is only one possible value
        // and perform this in the order of dependencies to avoid dead-ends
        $aDeps = array();
        foreach ($aDetailsList as $sAttCode) {
            $aDeps[$sAttCode] = MetaModel::GetPrequisiteAttributes($sClass, $sAttCode);
        }
        $aList = $this->OrderDependentFields($aDeps);
        foreach ($aList as $sAttCode) {
            // Consider only the "expected" fields for the target state
            if (array_key_exists($sAttCode, $aExpectedAttributes)) {
                $iExpectCode = $aExpectedAttributes[$sAttCode];
                // 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 && $this->Get($sAttCode) == '') {
                    $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
                    $aArgs = array('this' => $this);
                    // If the field is mandatory, set it to the only possible value
                    if (!$oAttDef->IsNullAllowed() || $iExpectCode & OPT_ATT_MANDATORY) {
                        if ($oAttDef->IsExternalKey()) {
                            $oAllowedValues = MetaModel::GetAllowedValuesAsObjectSet($sClass, $sAttCode, $aArgs);
                            if ($oAllowedValues->Count() == 1) {
                                $oRemoteObj = $oAllowedValues->Fetch();
                                $this->Set($sAttCode, $oRemoteObj->GetKey());
                            }
                        } else {
                            $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
                            if (count($aAllowedValues) == 1) {
                                $aValues = array_keys($aAllowedValues);
                                $this->Set($sAttCode, $aValues[0]);
                            }
                        }
                    }
                    $sHTMLValue = cmdbAbstractObject::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $this->Get($sAttCode), $this->GetEditValue($sAttCode), 'att_' . $iFieldIndex, '', $iExpectCode, $aArgs);
                    $aDetails[] = array('label' => '<span>' . $oAttDef->GetLabel() . '</span>', 'value' => "<span id=\"field_att_{$iFieldIndex}\">{$sHTMLValue}</span>");
                    $aFieldsMap[$sAttCode] = 'att_' . $iFieldIndex;
                    $iFieldIndex++;
                }
            }
        }
        $oPage->add('<table><tr><td>');
        $oPage->details($aDetails);
        $oPage->add('</td></tr></table>');
        $oPage->add("<input type=\"hidden\" name=\"id\" value=\"" . $this->GetKey() . "\" id=\"id\">\n");
        $aFieldsMap['id'] = 'id';
        $oPage->add("<input type=\"hidden\" name=\"class\" value=\"{$sClass}\">\n");
        $oPage->add("<input type=\"hidden\" name=\"operation\" value=\"apply_stimulus\">\n");
        $oPage->add("<input type=\"hidden\" name=\"stimulus\" value=\"{$sStimulus}\">\n");
        $oPage->add("<input type=\"hidden\" name=\"transaction_id\" value=\"" . utils::GetNewTransactionId() . "\">\n");
        $oAppContext = new ApplicationContext();
        $oPage->add($oAppContext->GetForForm());
        $oPage->add("<button type=\"button\" class=\"action\" onClick=\"BackToDetails('{$sClass}', " . $this->GetKey() . ")\"><span>" . Dict::S('UI:Button:Cancel') . "</span></button>&nbsp;&nbsp;&nbsp;&nbsp;\n");
        $oPage->add("<button type=\"submit\" class=\"action\"><span>{$sActionLabel}</span></button>\n");
        $oPage->add("</form>\n");
        $oPage->add("</div>\n");
        if ($sButtonsPosition != 'top') {
            // bottom or both: Displays the ticket details AFTER the actions
            $oPage->add('<div class="ui-widget-content">');
            $this->DisplayBareProperties($oPage);
            $oPage->add('</div>');
        }
        $iFieldsCount = count($aFieldsMap);
        $sJsonFieldsMap = json_encode($aFieldsMap);
        $oPage->add_script(<<<EOF
\t\t// Initializes the object once at the beginning of the page...
\t\tvar oWizardHelper = new WizardHelper('{$sClass}', '', '{$sTargetState}');
\t\toWizardHelper.SetFieldsMap({$sJsonFieldsMap});
\t\toWizardHelper.SetFieldsCount({$iFieldsCount});
EOF
);
        $oPage->add_ready_script(<<<EOF
\t\t// Starts the validation when the page is ready
\t\tCheckFields('apply_stimulus', false);
EOF
);
    }
Beispiel #7
0
 $aPrerequisites = MetaModel::GetPrequisiteAttributes($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++;
    /**
     * A one-row form for editing a link record
     * @param WebPage $oP Web page used for the ouput
     * @param DBObject $oLinkedObj The object to which all the elements of the linked set refer to
     * @param mixed $linkObjOrId Either the object linked or a unique number for new link records to add
     * @param Hash $aArgs Extra context arguments
     * @return string The HTML fragment of the one-row form
     */
    protected function GetFormRow(WebPage $oP, DBObject $oLinkedObj, $linkObjOrId = null, $aArgs = array(), $oCurrentObj)
    {
        $sPrefix = "{$this->m_sAttCode}{$this->m_sNameSuffix}";
        $aRow = array();
        $aFieldsMap = array();
        if (is_object($linkObjOrId) && !$linkObjOrId->IsNew()) {
            $key = $linkObjOrId->GetKey();
            $iRemoteObjKey = $linkObjOrId->Get($this->m_sExtKeyToRemote);
            $sPrefix .= "[{$key}][";
            $sNameSuffix = "]";
            // To make a tabular form
            $aArgs['prefix'] = $sPrefix;
            $aArgs['wizHelper'] = "oWizardHelper{$this->m_iInputId}{$key}";
            $aArgs['this'] = $linkObjOrId;
            $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onClick=\"oWidget" . $this->m_iInputId . ".OnSelectChange();\" value=\"{$key}\">";
            $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"attr_{$sPrefix}id{$sNameSuffix}\" value=\"{$key}\">";
            foreach ($this->m_aEditableFields as $sFieldCode) {
                $sFieldId = $this->m_iInputId . '_' . $sFieldCode . '[' . $linkObjOrId->GetKey() . ']';
                $sSafeId = utils::GetSafeId($sFieldId);
                $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sFieldCode);
                $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, $linkObjOrId->Get($sFieldCode), '', $sSafeId, $sNameSuffix, 0, $aArgs);
                $aFieldsMap[$sFieldCode] = $sSafeId;
            }
            $sState = $linkObjOrId->GetState();
        } else {
            // form for creating a new record
            if (is_object($linkObjOrId)) {
                // New link existing only in memory
                $oNewLinkObj = $linkObjOrId;
                $iRemoteObjKey = $oNewLinkObj->Get($this->m_sExtKeyToRemote);
                $oRemoteObj = MetaModel::GetObject($this->m_sRemoteClass, $iRemoteObjKey);
                $oNewLinkObj->Set($this->m_sExtKeyToMe, $oCurrentObj);
                // Setting the extkey with the object also fills the related external fields
                $linkObjOrId = -$iRemoteObjKey;
            } else {
                $iRemoteObjKey = -$linkObjOrId;
                $oNewLinkObj = MetaModel::NewObject($this->m_sLinkedClass);
                $oRemoteObj = MetaModel::GetObject($this->m_sRemoteClass, -$linkObjOrId);
                $oNewLinkObj->Set($this->m_sExtKeyToRemote, $oRemoteObj);
                // Setting the extkey with the object alsoo fills the related external fields
                $oNewLinkObj->Set($this->m_sExtKeyToMe, $oCurrentObj);
                // Setting the extkey with the object also fills the related external fields
            }
            $sPrefix .= "[{$linkObjOrId}][";
            $sNameSuffix = "]";
            // To make a tabular form
            $aArgs['prefix'] = $sPrefix;
            $aArgs['wizHelper'] = "oWizardHelper{$this->m_iInputId}_" . -$linkObjOrId;
            $aArgs['this'] = $oNewLinkObj;
            $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onClick=\"oWidget" . $this->m_iInputId . ".OnSelectChange();\" value=\"{$linkObjOrId}\">";
            $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"attr_{$sPrefix}id{$sNameSuffix}\" value=\"\">";
            foreach ($this->m_aEditableFields as $sFieldCode) {
                $sFieldId = $this->m_iInputId . '_' . $sFieldCode . '[' . $linkObjOrId . ']';
                $sSafeId = utils::GetSafeId($sFieldId);
                $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sFieldCode);
                $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, $oNewLinkObj->Get($sFieldCode), '', $sSafeId, $sNameSuffix, 0, $aArgs);
                $aFieldsMap[$sFieldCode] = $sSafeId;
            }
            $sState = '';
            $oP->add_script(<<<EOF
\$(".date-pick").datepicker({
\t\tshowOn: 'button',
\t\tbuttonImage: '../images/calendar.png',
\t\tbuttonImageOnly: true,
\t\tdateFormat: 'yy-mm-dd',
\t\tconstrainInput: false,
\t\tchangeMonth: true,
\t\tchangeYear: true
\t});
\$(".datetime-pick").datepicker({
\t\tshowOn: 'button',
\t\tbuttonImage: '../images/calendar.png',
\t\tbuttonImageOnly: true,
\t\tdateFormat: 'yy-mm-dd 00:00:00',
\t\tconstrainInput: false,
\t\tchangeMonth: true,
\t\tchangeYear: true
});
EOF
);
        }
        $sExtKeyToMeId = utils::GetSafeId($sPrefix . $this->m_sExtKeyToMe);
        $aFieldsMap[$this->m_sExtKeyToMe] = $sExtKeyToMeId;
        $aRow['form::checkbox'] .= "<input type=\"hidden\" id=\"{$sExtKeyToMeId}\" value=\"" . $oCurrentObj->GetKey() . "\">";
        $sExtKeyToRemoteId = utils::GetSafeId($sPrefix . $this->m_sExtKeyToRemote);
        $aFieldsMap[$this->m_sExtKeyToRemote] = $sExtKeyToRemoteId;
        $aRow['form::checkbox'] .= "<input type=\"hidden\" id=\"{$sExtKeyToRemoteId}\" value=\"{$iRemoteObjKey}\">";
        $iFieldsCount = count($aFieldsMap);
        $sJsonFieldsMap = json_encode($aFieldsMap);
        $oP->add_script(<<<EOF
var {$aArgs['wizHelper']} = new WizardHelper('{$this->m_sLinkedClass}', '', '{$sState}');
{$aArgs['wizHelper']}.SetFieldsMap({$sJsonFieldsMap});
{$aArgs['wizHelper']}.SetFieldsCount({$iFieldsCount});
EOF
);
        $aRow['static::key'] = $oLinkedObj->GetHyperLink();
        foreach (MetaModel::GetZListItems($this->m_sRemoteClass, 'list') as $sFieldCode) {
            $aRow['static::' . $sFieldCode] = $oLinkedObj->GetAsHTML($sFieldCode);
        }
        return $aRow;
    }
 protected function GetFormRow($oP, $oLinkedObj, $currentLink = null)
 {
     $aRow = array();
     if (is_object($currentLink)) {
         $key = $currentLink->GetKey();
         $sNameSuffix = "[{$key}]";
         // To make a tabular form
         $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onChange=\"OnSelectChange();\" value=\"{$key}\">";
         $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"linkId[{$key}]\" value=\"{$key}\">";
         foreach ($this->m_aEditableFields as $sFieldCode) {
             $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sFieldCode);
             $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sClass, $sFieldCode, $oAttDef, $currentLink->Get($sFieldCode), '', $key, $sNameSuffix);
         }
     } else {
         // form for creating a new record
         $sNameSuffix = "[{$currentLink}]";
         // To make a tabular form
         $aRow['form::checkbox'] = "<input class=\"selection\" type=\"checkbox\" onChange=\"OnSelectChange();\" value=\"{$currentLink}\">";
         $aRow['form::checkbox'] .= "<input type=\"hidden\" name=\"linkId[{$currentLink}]\" value=\"{$currentLink}\">";
         foreach ($this->m_aEditableFields as $sFieldCode) {
             $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sFieldCode);
             $aRow[$sFieldCode] = cmdbAbstractObject::GetFormElementForField($oP, $this->m_sClass, $sFieldCode, $oAttDef, '', '', '', $sNameSuffix);
         }
     }
     foreach (MetaModel::GetZListItems($this->m_sLinkedClass, 'list') as $sFieldCode) {
         $aRow['static::' . $sFieldCode] = $oLinkedObj->GetAsHTML($sFieldCode);
     }
     return $aRow;
 }