diff --git a/pages/ajax.csvimport.php b/pages/ajax.csvimport.php
index a56885031c..090c808a9e 100644
--- a/pages/ajax.csvimport.php
+++ b/pages/ajax.csvimport.php
@@ -208,202 +208,210 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo
return $sHtml;
}
-require_once(APPROOT.'/application/startup.inc.php');
-
-require_once(APPROOT.'/application/loginwebpage.class.inc.php');
-LoginWebPage::DoLogin(); // Check user rights and prompt if needed
-
-
-$sOperation = utils::ReadParam('operation', '');
-
-switch($sOperation)
+try
{
- case 'parser_preview':
- $oPage = new ajax_page("");
- $oPage->no_cache();
- $sSeparator = utils::ReadParam('separator', ',');
- if ($sSeparator == 'tab') $sSeparator = "\t";
- $sTextQualifier = utils::ReadParam('qualifier', '"');
- $iLinesToSkip = utils::ReadParam('nb_lines_skipped', 0);
- $bFirstLineAsHeader = utils::ReadParam('header_line', true);
- $sEncoding = utils::ReadParam('encoding', 'UTF-8');
- $sData = stripslashes(utils::ReadParam('csvdata', true));
- $oCSVParser = new CSVParser($sData, $sSeparator, $sTextQualifier);
- $aData = $oCSVParser->ToArray($iLinesToSkip);
- $iTarget = count($aData);
- if ($iTarget == 0)
+ require_once(APPROOT.'/application/startup.inc.php');
+
+ require_once(APPROOT.'/application/loginwebpage.class.inc.php');
+ LoginWebPage::DoLogin(); // Check user rights and prompt if needed
+
+
+ $sOperation = utils::ReadParam('operation', '');
+
+ switch($sOperation)
{
- $oPage->p(Dict::S('UI:CSVImport:NoData'));
- }
- else
- {
- $sMaxLen = (strlen(''.$iTarget) < 3) ? 3 : strlen(''.$iTarget); // Pad line numbers to the appropriate number of chars, but at least 3
- $sFormat = '%0'.$sMaxLen.'d';
- $oPage->p("
".Dict::S('UI:Title:DataPreview')." \n");
- $oPage->p("\n");
- $oPage->add("
");
- $iMaxIndex= 10; // Display maximum 10 lines for the preview
- $index = 1;
- foreach($aData as $aRow)
+ case 'parser_preview':
+ $oPage = new ajax_page("");
+ $oPage->no_cache();
+ $sSeparator = utils::ReadParam('separator', ',');
+ if ($sSeparator == 'tab') $sSeparator = "\t";
+ $sTextQualifier = utils::ReadParam('qualifier', '"');
+ $iLinesToSkip = utils::ReadParam('nb_lines_skipped', 0);
+ $bFirstLineAsHeader = utils::ReadParam('header_line', true);
+ $sEncoding = utils::ReadParam('encoding', 'UTF-8');
+ $sData = stripslashes(utils::ReadParam('csvdata', true));
+ $oCSVParser = new CSVParser($sData, $sSeparator, $sTextQualifier);
+ $aData = $oCSVParser->ToArray($iLinesToSkip);
+ $iTarget = count($aData);
+ if ($iTarget == 0)
{
- $sCSSClass = 'csv_row'.($index % 2);
- if ( ($bFirstLineAsHeader) && ($index == 1))
+ $oPage->p(Dict::S('UI:CSVImport:NoData'));
+ }
+ else
+ {
+ $sMaxLen = (strlen(''.$iTarget) < 3) ? 3 : strlen(''.$iTarget); // Pad line numbers to the appropriate number of chars, but at least 3
+ $sFormat = '%0'.$sMaxLen.'d';
+ $oPage->p("".Dict::S('UI:Title:DataPreview')." \n");
+ $oPage->p("\n");
+ $oPage->add("
");
+ $iMaxIndex= 10; // Display maximum 10 lines for the preview
+ $index = 1;
+ foreach($aData as $aRow)
{
- $oPage->add("".sprintf($sFormat, $index)." ");
- $oPage->add(implode(' ', $aRow));
- $oPage->add(" \n");
- $iNbCols = count($aRow);
-
+ $sCSSClass = 'csv_row'.($index % 2);
+ if ( ($bFirstLineAsHeader) && ($index == 1))
+ {
+ $oPage->add("".sprintf($sFormat, $index)." ");
+ $oPage->add(implode(' ', $aRow));
+ $oPage->add(" \n");
+ $iNbCols = count($aRow);
+
+ }
+ else
+ {
+ if ($index == 1) $iNbCols = count($aRow);
+ $oPage->add("".sprintf($sFormat, $index)." ");
+ $oPage->add(implode(' ', $aRow));
+ $oPage->add(" \n");
+ }
+ $index++;
+ if ($index > $iMaxIndex) break;
+ }
+ $oPage->add("
\n");
+ $oPage->add("
\n");
+ if($iNbCols == 1)
+ {
+ $oPage->p(' '.Dict::S('UI:CSVImport:ErrorOnlyOneColumn'));
}
else
{
- if ($index == 1) $iNbCols = count($aRow);
- $oPage->add("".sprintf($sFormat, $index)." ");
- $oPage->add(implode(' ', $aRow));
- $oPage->add(" \n");
+ $oPage->p(' ');
}
- $index++;
- if ($index > $iMaxIndex) break;
}
- $oPage->add("
\n");
- $oPage->add("
\n");
- if($iNbCols == 1)
- {
- $oPage->p(' '.Dict::S('UI:CSVImport:ErrorOnlyOneColumn'));
- }
- else
- {
- $oPage->p(' ');
- }
- }
- break;
+ break;
- case 'display_mapping_form':
- $oPage = new ajax_page("");
- $oPage->no_cache();
- $sSeparator = utils::ReadParam('separator', ',');
- $sTextQualifier = utils::ReadParam('qualifier', '"');
- $iLinesToSkip = utils::ReadParam('nb_lines_skipped', 0);
- $bFirstLineAsHeader = utils::ReadParam('header_line', false);
- $sData = stripslashes(utils::ReadParam('csvdata', ''));
- $sClassName = utils::ReadParam('class_name', '');
- $bAdvanced = utils::ReadParam('advanced', false);
- $sEncoding = utils::ReadParam('encoding', 'UTF-8');
- $oCSVParser = new CSVParser($sData, $sSeparator, $sTextQualifier);
- $aData = $oCSVParser->ToArray($iLinesToSkip);
- $iTarget = count($aData);
- if ($iTarget == 0)
- {
- $oPage->p(Dict::S('UI:CSVImport:NoData'));
- }
- else
- {
- $oPage->add("");
- $aFirstLine = $aData[0]; // Use the first row to determine the number of columns
- $iStartLine = 0;
- $iNbColumns = count($aFirstLine);
- if ($bFirstLineAsHeader)
+ case 'display_mapping_form':
+ $oPage = new ajax_page("");
+ $oPage->no_cache();
+ $sSeparator = utils::ReadParam('separator', ',');
+ $sTextQualifier = utils::ReadParam('qualifier', '"');
+ $iLinesToSkip = utils::ReadParam('nb_lines_skipped', 0);
+ $bFirstLineAsHeader = utils::ReadParam('header_line', false);
+ $sData = stripslashes(utils::ReadParam('csvdata', ''));
+ $sClassName = utils::ReadParam('class_name', '');
+ $bAdvanced = utils::ReadParam('advanced', false);
+ $sEncoding = utils::ReadParam('encoding', 'UTF-8');
+ $oCSVParser = new CSVParser($sData, $sSeparator, $sTextQualifier);
+ $aData = $oCSVParser->ToArray($iLinesToSkip);
+ $iTarget = count($aData);
+ if ($iTarget == 0)
{
- $iStartLine = 1;
- foreach($aFirstLine as $sField)
- {
- $aHeader[] = $sField;
- }
+ $oPage->p(Dict::S('UI:CSVImport:NoData'));
}
else
{
- // Build some conventional name for the fields: field1...fieldn
- $index= 1;
- foreach($aFirstLine as $sField)
+ $oPage->add("");
+ $aFirstLine = $aData[0]; // Use the first row to determine the number of columns
+ $iStartLine = 0;
+ $iNbColumns = count($aFirstLine);
+ if ($bFirstLineAsHeader)
{
- $aHeader[] = Dict::Format('UI:CSVImport:FieldName', $index);
+ $iStartLine = 1;
+ foreach($aFirstLine as $sField)
+ {
+ $aHeader[] = $sField;
+ }
+ }
+ else
+ {
+ // Build some conventional name for the fields: field1...fieldn
+ $index= 1;
+ foreach($aFirstLine as $sField)
+ {
+ $aHeader[] = Dict::Format('UI:CSVImport:FieldName', $index);
+ $index++;
+ }
+ }
+ $oPage->add("\n");
+ $aReconciliationKeys = MetaModel::GetReconcKeys($sClassName);
+ $aMoreReconciliationKeys = array(); // Store: key => void to automatically remove duplicates
+ foreach($aReconciliationKeys as $sAttCode)
{
- // An external key is specified as a reconciliation key: this means that all the reconciliation
- // keys of this class are proposed to identify the target object
- $aMoreReconciliationKeys = array_merge($aMoreReconciliationKeys, GetMappingsForExtKey($sAttCode, $oAttDef, $bAdvanced));
+ $oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
+ if ($oAttDef->IsExternalKey())
+ {
+ // An external key is specified as a reconciliation key: this means that all the reconciliation
+ // keys of this class are proposed to identify the target object
+ $aMoreReconciliationKeys = array_merge($aMoreReconciliationKeys, GetMappingsForExtKey($sAttCode, $oAttDef, $bAdvanced));
+ }
+ elseif($oAttDef->IsExternalField())
+ {
+ // An external field is specified as a reconciliation key, translate the field into a field on the target class
+ // since external fields are not writable, and thus never appears in the mapping form
+ $sKeyAttCode = $oAttDef->GetKeyAttCode();
+ $sTargetAttCode = $oAttDef->GetExtAttCode();
+ $aMoreReconciliationKeys[$sKeyAttCode.'->'.$sTargetAttCode] = '';
+ }
}
- elseif($oAttDef->IsExternalField())
- {
- // An external field is specified as a reconciliation key, translate the field into a field on the target class
- // since external fields are not writable, and thus never appears in the mapping form
- $sKeyAttCode = $oAttDef->GetKeyAttCode();
- $sTargetAttCode = $oAttDef->GetExtAttCode();
- $aMoreReconciliationKeys[$sKeyAttCode.'->'.$sTargetAttCode] = '';
- }
- }
- $sDefaultKeys = '"'.implode('", "',array_merge($aReconciliationKeys, array_keys($aMoreReconciliationKeys))).'"';
- $oPage->add_ready_script(
+ $sDefaultKeys = '"'.implode('", "',array_merge($aReconciliationKeys, array_keys($aMoreReconciliationKeys))).'"';
+ $oPage->add_ready_script(
<<AddCondition('id', 0, '='); // Make sure we create an empty set
- $oSet = new CMDBObjectSet($oSearch);
- $sResult = cmdbAbstractObject::GetSetAsCSV($oSet, array('showMandatoryFields' => true));
- //$aCSV = explode("\n", $sCSV);
- // If there are more than one line, let's assume that the first line is a comment and skip it.
- //if (count($aCSV) > 1)
- //{
- // $sResult = $aCSV[0];
- //}
- //else
- //{
- // $sResult = $sCSV;
- //}
+ }
+ break;
- $sClassDisplayName = MetaModel::GetName($sClassName);
- $sDisposition = utils::ReadParam('disposition', 'inline');
- if ($sDisposition == 'attachment')
- {
- $oPage = new CSVPage("");
- $oPage->add_header("Content-type: text/csv; charset=utf-8");
- $oPage->add_header("Content-disposition: attachment; filename=\"{$sClassDisplayName}.csv\"");
- $oPage->no_cache();
- $oPage->add($sResult);
+ case 'get_csv_template':
+ $sClassName = utils::ReadParam('class_name');
+ $oSearch = new DBObjectSearch($sClassName);
+ $oSearch->AddCondition('id', 0, '='); // Make sure we create an empty set
+ $oSet = new CMDBObjectSet($oSearch);
+ $sResult = cmdbAbstractObject::GetSetAsCSV($oSet, array('showMandatoryFields' => true));
+ //$aCSV = explode("\n", $sCSV);
+ // If there are more than one line, let's assume that the first line is a comment and skip it.
+ //if (count($aCSV) > 1)
+ //{
+ // $sResult = $aCSV[0];
+ //}
+ //else
+ //{
+ // $sResult = $sCSV;
+ //}
+
+ $sClassDisplayName = MetaModel::GetName($sClassName);
+ $sDisposition = utils::ReadParam('disposition', 'inline');
+ if ($sDisposition == 'attachment')
+ {
+ $oPage = new CSVPage("");
+ $oPage->add_header("Content-type: text/csv; charset=utf-8");
+ $oPage->add_header("Content-disposition: attachment; filename=\"{$sClassDisplayName}.csv\"");
+ $oPage->no_cache();
+ $oPage->add($sResult);
+ }
+ else
+ {
+ $oPage = new ajax_page("");
+ $oPage->no_cache();
+ $oPage->add(' '.$sClassDisplayName.'.csv
');
+ $oPage->add('
');
+ }
+ break;
}
- else
- {
- $oPage = new ajax_page("");
- $oPage->no_cache();
- $oPage->add(' '.$sClassDisplayName.'.csv
');
- $oPage->add('
');
- }
- break;
+ $oPage->output();
}
-$oPage->output();
+catch (Exception $e)
+{
+ IssueLog::Error($e->getMessage());
+}
+
?>
diff --git a/pages/ajax.render.php b/pages/ajax.render.php
index 83b38fcdf0..4be97c77eb 100644
--- a/pages/ajax.render.php
+++ b/pages/ajax.render.php
@@ -31,367 +31,377 @@ require_once(APPROOT.'/application/wizardhelper.class.inc.php');
require_once(APPROOT.'/application/ui.linkswidget.class.inc.php');
require_once(APPROOT.'/application/ui.autocompletewidget.class.inc.php');
-require_once(APPROOT.'/application/startup.inc.php');
-require_once(APPROOT.'/application/user.preferences.class.inc.php');
-
-require_once(APPROOT.'/application/loginwebpage.class.inc.php');
-LoginWebPage::DoLogin(false /* bMustBeAdmin */, true /* IsAllowedToPortalUsers */); // Check user rights and prompt if needed
-
-$oPage = new ajax_page("");
-$oPage->no_cache();
-
-$operation = utils::ReadParam('operation', '');
-$sFilter = stripslashes(utils::ReadParam('filter', ''));
-$sEncoding = utils::ReadParam('encoding', 'serialize');
-$sClass = utils::ReadParam('class', 'MissingAjaxParam');
-$sStyle = utils::ReadParam('style', 'list');
-
-switch($operation)
+try
{
- case 'addObjects':
- require_once(APPROOT.'/application/uilinkswizard.class.inc.php');
- $sClass = utils::ReadParam('class', '', 'get');
- $sLinkedClass = utils::ReadParam('linkedClass', '');
- $sLinkageAttr = utils::ReadParam('linkageAttr', '');
- $iObjectId = utils::ReadParam('objectId', '');
- $oLinksWizard = new UILinksWizard($sClass, $sLinkageAttr, $iObjectId, $sLinkedClass);
- $oLinksWizard->DisplayAddForm($oPage);
- break;
+ require_once(APPROOT.'/application/startup.inc.php');
+ require_once(APPROOT.'/application/user.preferences.class.inc.php');
- // ui.linkswidget
- case 'searchObjectsToAdd':
- $sRemoteClass = utils::ReadParam('sRemoteClass', '');
- $sAttCode = utils::ReadParam('sAttCode', '');
- $iInputId = utils::ReadParam('iInputId', '');
- $sSuffix = utils::ReadParam('sSuffix', '');
- $bDuplicates = (utils::ReadParam('bDuplicates', 'false') == 'false') ? false : true;
- $aAlreadyLinked = utils::ReadParam('aAlreadyLinked', array());
- $oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
- $oWidget->SearchObjectsToAdd($oPage, $sRemoteClass, $aAlreadyLinked);
- break;
+ require_once(APPROOT.'/application/loginwebpage.class.inc.php');
+ LoginWebPage::DoLogin(false /* bMustBeAdmin */, true /* IsAllowedToPortalUsers */); // Check user rights and prompt if needed
- // ui.autocompletewidget
- case 'searchObjectsToSelect':
- $sTargetClass = utils::ReadParam('sRemoteClass', '');
- $sAttCode = utils::ReadParam('sAttCode', '');
- $iInputId = utils::ReadParam('iInputId', '');
- $sSuffix = utils::ReadParam('sSuffix', '');
- $sJson = utils::ReadParam('json', '');
- $oWizardHelper = WizardHelper::FromJSON($sJson);
- $oObj = $oWizardHelper->GetTargetObject();
- $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array('this' => $oObj));
- $oWidget = new UIAutocompleteWidget($sAttCode, $sClass, '', $aAllowedValues, $oObj->Get($sAttCode), $iInputId, $sSuffix, '');
- $oWidget->SearchObjectsToSelect($oPage, $sTargetClass);
- break;
+ $oPage = new ajax_page("");
+ $oPage->no_cache();
+
+ $operation = utils::ReadParam('operation', '');
+ $sFilter = stripslashes(utils::ReadParam('filter', ''));
+ $sEncoding = utils::ReadParam('encoding', 'serialize');
+ $sClass = utils::ReadParam('class', 'MissingAjaxParam');
+ $sStyle = utils::ReadParam('style', 'list');
- // ui.autocompletewidget
- case 'objectCreationForm':
- $sTargetClass = utils::ReadParam('sRemoteClass', '');
- $sAttCode = utils::ReadParam('sAttCode', '');
- $iInputId = utils::ReadParam('iInputId', '');
- $sSuffix = utils::ReadParam('sSuffix', '');
- $sJson = utils::ReadParam('json', '');
- $oWizardHelper = WizardHelper::FromJSON($sJson);
- $oObj = $oWizardHelper->GetTargetObject();
- $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array('this' => $oObj));
- $oWidget = new UIAutocompleteWidget($sAttCode, $sClass, '', $aAllowedValues, $oObj->Get($sAttCode), $iInputId, $sSuffix, '');
- $oWidget->GetObjectCreationForm($oPage);
- break;
-
- // ui.autocompletewidget
- case 'doCreateObject':
- $sTargetClass = utils::ReadParam('sRemoteClass', '');
- $sAttCode = utils::ReadParam('sAttCode', '');
- $iInputId = utils::ReadParam('iInputId', '');
- $sSuffix = utils::ReadParam('sSuffix', '');
- $sJson = utils::ReadParam('json', '');
- $oWizardHelper = WizardHelper::FromJSON($sJson);
- $oObj = $oWizardHelper->GetTargetObject();
- $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array('this' => $oObj));
- // The iInputId of the autocomplete is the prefix for the form used to create the target object
- $oWidget = new UIAutocompleteWidget($sAttCode, $sClass, '', $aAllowedValues, null, $iInputId, $sSuffix, $oWizardHelper->GetFormPrefix());
- $aResult = $oWidget->DoCreateObject($oPage);
- echo json_encode($aResult);
- break;
-
- // ui.autocompletewidget
- case 'getObjectName':
- $sTargetClass = utils::ReadParam('sTargetClass', '');
- $sAttCode = utils::ReadParam('sAttCode', '');
- $iInputId = utils::ReadParam('iInputId', '');
- $iObjectId = utils::ReadParam('iObjectId', '');
- $sSuffix = utils::ReadParam('sSuffix', '');
- $oWidget = new UIAutocompleteWidget($sAttCode, $sClass, '', array(), '', $iInputId, $sSuffix, '');
- $sName = $oWidget->GetObjectName($iObjectId);
- echo json_encode(array('name' => $sName));
- break;
-
- // ui.linkswidget
- case 'doAddObjects':
- $sAttCode = utils::ReadParam('sAttCode', '');
- $iInputId = utils::ReadParam('iInputId', '');
- $sSuffix = utils::ReadParam('sSuffix', '');
- $bDuplicates = (utils::ReadParam('bDuplicates', 'false') == 'false') ? false : true;
- $aLinkedObjectIds = utils::ReadParam('selectObject', array());
- $oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
- $oWidget->DoAddObjects($oPage, $aLinkedObjectIds);
- break;
+ switch($operation)
+ {
+ case 'addObjects':
+ require_once(APPROOT.'/application/uilinkswizard.class.inc.php');
+ $sClass = utils::ReadParam('class', '', 'get');
+ $sLinkedClass = utils::ReadParam('linkedClass', '');
+ $sLinkageAttr = utils::ReadParam('linkageAttr', '');
+ $iObjectId = utils::ReadParam('objectId', '');
+ $oLinksWizard = new UILinksWizard($sClass, $sLinkageAttr, $iObjectId, $sLinkedClass);
+ $oLinksWizard->DisplayAddForm($oPage);
+ break;
- case 'wizard_helper_preview':
- $sJson = utils::ReadParam('json_obj', '');
- $oWizardHelper = WizardHelper::FromJSON($sJson);
- $oObj = $oWizardHelper->GetTargetObject();
- $oObj->DisplayBareProperties($oPage);
- break;
+ // ui.linkswidget
+ case 'searchObjectsToAdd':
+ $sRemoteClass = utils::ReadParam('sRemoteClass', '');
+ $sAttCode = utils::ReadParam('sAttCode', '');
+ $iInputId = utils::ReadParam('iInputId', '');
+ $sSuffix = utils::ReadParam('sSuffix', '');
+ $bDuplicates = (utils::ReadParam('bDuplicates', 'false') == 'false') ? false : true;
+ $aAlreadyLinked = utils::ReadParam('aAlreadyLinked', array());
+ $oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
+ $oWidget->SearchObjectsToAdd($oPage, $sRemoteClass, $aAlreadyLinked);
+ break;
+
+ // ui.autocompletewidget
+ case 'searchObjectsToSelect':
+ $sTargetClass = utils::ReadParam('sRemoteClass', '');
+ $sAttCode = utils::ReadParam('sAttCode', '');
+ $iInputId = utils::ReadParam('iInputId', '');
+ $sSuffix = utils::ReadParam('sSuffix', '');
+ $sJson = utils::ReadParam('json', '');
+ $oWizardHelper = WizardHelper::FromJSON($sJson);
+ $oObj = $oWizardHelper->GetTargetObject();
+ $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array('this' => $oObj));
+ $oWidget = new UIAutocompleteWidget($sAttCode, $sClass, '', $aAllowedValues, $oObj->Get($sAttCode), $iInputId, $sSuffix, '');
+ $oWidget->SearchObjectsToSelect($oPage, $sTargetClass);
+ break;
- case 'wizard_helper':
- $sJson = utils::ReadParam('json_obj', '');
- $oWizardHelper = WizardHelper::FromJSON($sJson);
- $oObj = $oWizardHelper->GetTargetObject();
- $sClass = $oWizardHelper->GetTargetClass();
- foreach($oWizardHelper->GetFieldsForDefaultValue() as $sAttCode)
- {
- $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
- $defaultValue = $oAttDef->GetDefaultValue();
- $oWizardHelper->SetDefaultValue($sAttCode, $defaultValue);
- $oObj->Set($sAttCode, $defaultValue);
- }
- $sFormPrefix = $oWizardHelper->GetFormPrefix();
- foreach($oWizardHelper->GetFieldsForAllowedValues() as $sAttCode)
- {
- $sId = $oWizardHelper->GetIdForField($sAttCode);
- if ($sId != '')
+ // ui.autocompletewidget
+ case 'objectCreationForm':
+ $sTargetClass = utils::ReadParam('sRemoteClass', '');
+ $sAttCode = utils::ReadParam('sAttCode', '');
+ $iInputId = utils::ReadParam('iInputId', '');
+ $sSuffix = utils::ReadParam('sSuffix', '');
+ $sJson = utils::ReadParam('json', '');
+ $oWizardHelper = WizardHelper::FromJSON($sJson);
+ $oObj = $oWizardHelper->GetTargetObject();
+ $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array('this' => $oObj));
+ $oWidget = new UIAutocompleteWidget($sAttCode, $sClass, '', $aAllowedValues, $oObj->Get($sAttCode), $iInputId, $sSuffix, '');
+ $oWidget->GetObjectCreationForm($oPage);
+ break;
+
+ // ui.autocompletewidget
+ case 'doCreateObject':
+ $sTargetClass = utils::ReadParam('sRemoteClass', '');
+ $sAttCode = utils::ReadParam('sAttCode', '');
+ $iInputId = utils::ReadParam('iInputId', '');
+ $sSuffix = utils::ReadParam('sSuffix', '');
+ $sJson = utils::ReadParam('json', '');
+ $oWizardHelper = WizardHelper::FromJSON($sJson);
+ $oObj = $oWizardHelper->GetTargetObject();
+ $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array('this' => $oObj));
+ // The iInputId of the autocomplete is the prefix for the form used to create the target object
+ $oWidget = new UIAutocompleteWidget($sAttCode, $sClass, '', $aAllowedValues, null, $iInputId, $sSuffix, $oWizardHelper->GetFormPrefix());
+ $aResult = $oWidget->DoCreateObject($oPage);
+ echo json_encode($aResult);
+ break;
+
+ // ui.autocompletewidget
+ case 'getObjectName':
+ $sTargetClass = utils::ReadParam('sTargetClass', '');
+ $sAttCode = utils::ReadParam('sAttCode', '');
+ $iInputId = utils::ReadParam('iInputId', '');
+ $iObjectId = utils::ReadParam('iObjectId', '');
+ $sSuffix = utils::ReadParam('sSuffix', '');
+ $oWidget = new UIAutocompleteWidget($sAttCode, $sClass, '', array(), '', $iInputId, $sSuffix, '');
+ $sName = $oWidget->GetObjectName($iObjectId);
+ echo json_encode(array('name' => $sName));
+ break;
+
+ // ui.linkswidget
+ case 'doAddObjects':
+ $sAttCode = utils::ReadParam('sAttCode', '');
+ $iInputId = utils::ReadParam('iInputId', '');
+ $sSuffix = utils::ReadParam('sSuffix', '');
+ $bDuplicates = (utils::ReadParam('bDuplicates', 'false') == 'false') ? false : true;
+ $aLinkedObjectIds = utils::ReadParam('selectObject', array());
+ $oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
+ $oWidget->DoAddObjects($oPage, $aLinkedObjectIds);
+ break;
+
+ case 'wizard_helper_preview':
+ $sJson = utils::ReadParam('json_obj', '');
+ $oWizardHelper = WizardHelper::FromJSON($sJson);
+ $oObj = $oWizardHelper->GetTargetObject();
+ $oObj->DisplayBareProperties($oPage);
+ break;
+
+ case 'wizard_helper':
+ $sJson = utils::ReadParam('json_obj', '');
+ $oWizardHelper = WizardHelper::FromJSON($sJson);
+ $oObj = $oWizardHelper->GetTargetObject();
+ $sClass = $oWizardHelper->GetTargetClass();
+ foreach($oWizardHelper->GetFieldsForDefaultValue() as $sAttCode)
{
- // 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);
- $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 immediatly validate the field when we reload it
- $oPage->add_ready_script("$('#$sId').trigger('validate');");
- $oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
+ $defaultValue = $oAttDef->GetDefaultValue();
+ $oWizardHelper->SetDefaultValue($sAttCode, $defaultValue);
+ $oObj->Set($sAttCode, $defaultValue);
}
- }
- $oPage->add_script("oWizardHelper{$sFormPrefix}.m_oData=".$oWizardHelper->ToJSON().";\noWizardHelper{$sFormPrefix}.UpdateFields();\n");
- break;
-
- case 'ajax':
- if ($sFilter != "")
- {
- $sExtraParams = stripslashes(utils::ReadParam('extra_params', ''));
- $aExtraParams = array();
- if (!empty($sExtraParams))
+ $sFormPrefix = $oWizardHelper->GetFormPrefix();
+ foreach($oWizardHelper->GetFieldsForAllowedValues() as $sAttCode)
{
- $aExtraParams = json_decode(str_replace("'", '"', $sExtraParams), true /* associative array */);
+ $sId = $oWizardHelper->GetIdForField($sAttCode);
+ if ($sId != '')
+ {
+ // 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);
+ $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 immediatly validate the field when we reload it
+ $oPage->add_ready_script("$('#$sId').trigger('validate');");
+ $oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
+ }
}
- if ($sEncoding == 'oql')
+ $oPage->add_script("oWizardHelper{$sFormPrefix}.m_oData=".$oWizardHelper->ToJSON().";\noWizardHelper{$sFormPrefix}.UpdateFields();\n");
+ break;
+
+ case 'ajax':
+ if ($sFilter != "")
{
- $oFilter = CMDBSearchFilter::FromOQL($sFilter);
+ $sExtraParams = stripslashes(utils::ReadParam('extra_params', ''));
+ $aExtraParams = array();
+ if (!empty($sExtraParams))
+ {
+ $aExtraParams = json_decode(str_replace("'", '"', $sExtraParams), true /* associative array */);
+ }
+ if ($sEncoding == 'oql')
+ {
+ $oFilter = CMDBSearchFilter::FromOQL($sFilter);
+ }
+ else
+ {
+ $oFilter = CMDBSearchFilter::unserialize($sFilter);
+ }
+ $oDisplayBlock = new DisplayBlock($oFilter, $sStyle, false);
+ $oDisplayBlock->RenderContent($oPage, $aExtraParams);
}
else
{
- $oFilter = CMDBSearchFilter::unserialize($sFilter);
+ $oPage->p("Invalid query (empty filter).");
}
- $oDisplayBlock = new DisplayBlock($oFilter, $sStyle, false);
- $oDisplayBlock->RenderContent($oPage, $aExtraParams);
- }
- else
- {
- $oPage->p("Invalid query (empty filter).");
- }
- break;
-
- case 'details':
- $key = utils::ReadParam('id', 0);
- $oFilter = new DBObjectSearch($sClass);
- $oFilter->AddCondition('id', $key, '=');
- $oDisplayBlock = new DisplayBlock($oFilter, 'details', false);
- $oDisplayBlock->RenderContent($oPage);
- break;
-
- case 'preview':
- $key = utils::ReadParam('id', 0);
- $oFilter = new DBObjectSearch($sClass);
- $oFilter->AddCondition('id', $key, '=');
- $oDisplayBlock = new DisplayBlock($oFilter, 'preview', false);
- $oDisplayBlock->RenderContent($oPage);
- break;
-
- case 'pie_chart':
- $sGroupBy = utils::ReadParam('group_by', '');
- if ($sFilter != '')
- {
- if ($sEncoding == 'oql')
+ break;
+
+ case 'details':
+ $key = utils::ReadParam('id', 0);
+ $oFilter = new DBObjectSearch($sClass);
+ $oFilter->AddCondition('id', $key, '=');
+ $oDisplayBlock = new DisplayBlock($oFilter, 'details', false);
+ $oDisplayBlock->RenderContent($oPage);
+ break;
+
+ case 'preview':
+ $key = utils::ReadParam('id', 0);
+ $oFilter = new DBObjectSearch($sClass);
+ $oFilter->AddCondition('id', $key, '=');
+ $oDisplayBlock = new DisplayBlock($oFilter, 'preview', false);
+ $oDisplayBlock->RenderContent($oPage);
+ break;
+
+ case 'pie_chart':
+ $sGroupBy = utils::ReadParam('group_by', '');
+ if ($sFilter != '')
{
- $oFilter = CMDBSearchFilter::FromOQL($sFilter);
+ if ($sEncoding == 'oql')
+ {
+ $oFilter = CMDBSearchFilter::FromOQL($sFilter);
+ }
+ else
+ {
+ $oFilter = CMDBSearchFilter::unserialize($sFilter);
+ }
+ $oDisplayBlock = new DisplayBlock($oFilter, 'pie_chart_ajax', false);
+ $oDisplayBlock->RenderContent($oPage, array('group_by' => $sGroupBy));
}
else
{
- $oFilter = CMDBSearchFilter::unserialize($sFilter);
- }
- $oDisplayBlock = new DisplayBlock($oFilter, 'pie_chart_ajax', false);
- $oDisplayBlock->RenderContent($oPage, array('group_by' => $sGroupBy));
- }
- else
- {
-
- $oPage->add("\n3d pie \n.");
- }
- break;
-
- case 'open_flash_chart':
- $aParams = utils::ReadParam('params', array());
- if ($sFilter != '')
- {
- $oFilter = CMDBSearchFilter::unserialize($sFilter);
- $oDisplayBlock = new DisplayBlock($oFilter, 'open_flash_chart_ajax', false);
- $oDisplayBlock->RenderContent($oPage, $aParams);
- }
- else
- {
-
- $oPage->add("\n3d pie \n.");
- }
- break;
-
- case 'modal_details':
- $key = utils::ReadParam('id', 0);
- $oFilter = new DBObjectSearch($sClass);
- $oFilter->AddCondition('id', $key, '=');
- $oPage->Add("Object Details
\n");
- $oDisplayBlock = new DisplayBlock($oFilter, 'details', false);
- $oDisplayBlock->RenderContent($oPage);
- $oPage->Add(" \n");
- break;
- case 'ui.linkswidget':
- /*
- $sClass = utils::ReadParam('sclass', 'bizContact');
- $sAttCode = utils::ReadParam('attCode', 'name');
- $sOrg = utils::ReadParam('org_id', '');
- $sName = utils::ReadParam('q', '');
- $iMaxCount = utils::ReadParam('max', 30);
- UILinksWidget::Autocomplete($oPage, $sClass, $sAttCode, $sName, $iMaxCount);
- */
- break;
-
- case 'ui.linkswidget.linkedset':
- /*
- $sClass = utils::ReadParam('sclass', 'bizContact');
- $sJSONSet = stripslashes(utils::ReadParam('sset', ''));
- $sExtKeyToMe = utils::ReadParam('sextkeytome', '');
- $sExtKeyToRemote = utils::ReadParam('sextkeytoremote', '');
- $iObjectId = utils::ReadParam('id', -1);
- UILinksWidget::RenderSet($oPage, $sClass, $sJSONSet, $sExtKeyToMe, $sExtKeyToRemote, $iObjectId);
- $iFieldId = utils::ReadParam('myid', '-1');
- $oPage->add_ready_script("$('#{$iFieldId}').trigger('validate');");
- */
- break;
-
- case 'autocomplete':
- $key = utils::ReadParam('id', 0);
- $sClass = utils::ReadParam('sclass', 'bizContact');
- $sAttCode = utils::ReadParam('attCode', 'name');
- $sOrg = utils::ReadParam('org_id', '');
- $sName = utils::ReadParam('q', '');
- $iMaxCount = utils::ReadParam('max', 30);
- $aArgs = array();
- if (!empty($key))
- {
- if ($oThis = MetaModel::GetObject($sClass, $key))
- {
- $aArgs['*this*'] = $oThis;
- $aArgs['this'] = $oThis;
+ $oPage->add("\n3d pie \n.");
}
- }
- $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs, $sName);
- $iCount = 0;
- foreach($aAllowedValues as $key => $value)
- {
- $oPage->add($value."|".$key."\n");
- }
- break;
+ break;
+
+ case 'open_flash_chart':
+ $aParams = utils::ReadParam('params', array());
+ if ($sFilter != '')
+ {
+ $oFilter = CMDBSearchFilter::unserialize($sFilter);
+ $oDisplayBlock = new DisplayBlock($oFilter, 'open_flash_chart_ajax', false);
+ $oDisplayBlock->RenderContent($oPage, $aParams);
+ }
+ else
+ {
+
+ $oPage->add("\n3d pie \n.");
+ }
+ break;
- case 'link':
- $sClass = utils::ReadParam('sclass', 'logInfra');
- $sAttCode = utils::ReadParam('attCode', 'name');
- //$sOrg = utils::ReadParam('org_id', '');
- $sName = utils::ReadParam('q', '');
- $iMaxCount = utils::ReadParam('max', 30);
- $iCount = 0;
- $oFilter = new DBObjectSearch($sClass);
- $oFilter->AddCondition($sAttCode, $sName, 'Begins with');
- //$oFilter->AddCondition('org_id', $sOrg, '=');
- $oSet = new CMDBObjectSet($oFilter, array($sAttCode => true));
- while( ($iCount < $iMaxCount) && ($oObj = $oSet->fetch()) )
- {
- $oPage->add($oObj->GetAsHTML($sAttCode)."|".$oObj->GetKey()."\n");
- $iCount++;
- }
- break;
+ case 'modal_details':
+ $key = utils::ReadParam('id', 0);
+ $oFilter = new DBObjectSearch($sClass);
+ $oFilter->AddCondition('id', $key, '=');
+ $oPage->Add("Object Details
\n");
+ $oDisplayBlock = new DisplayBlock($oFilter, 'details', false);
+ $oDisplayBlock->RenderContent($oPage);
+ $oPage->Add(" \n");
+ break;
+
+ case 'ui.linkswidget':
+ /*
+ $sClass = utils::ReadParam('sclass', 'bizContact');
+ $sAttCode = utils::ReadParam('attCode', 'name');
+ $sOrg = utils::ReadParam('org_id', '');
+ $sName = utils::ReadParam('q', '');
+ $iMaxCount = utils::ReadParam('max', 30);
+ UILinksWidget::Autocomplete($oPage, $sClass, $sAttCode, $sName, $iMaxCount);
+ */
+ break;
+
+ case 'ui.linkswidget.linkedset':
+ /*
+ $sClass = utils::ReadParam('sclass', 'bizContact');
+ $sJSONSet = stripslashes(utils::ReadParam('sset', ''));
+ $sExtKeyToMe = utils::ReadParam('sextkeytome', '');
+ $sExtKeyToRemote = utils::ReadParam('sextkeytoremote', '');
+ $iObjectId = utils::ReadParam('id', -1);
+ UILinksWidget::RenderSet($oPage, $sClass, $sJSONSet, $sExtKeyToMe, $sExtKeyToRemote, $iObjectId);
+ $iFieldId = utils::ReadParam('myid', '-1');
+ $oPage->add_ready_script("$('#{$iFieldId}').trigger('validate');");
+ */
+ break;
+
+ case 'autocomplete':
+ $key = utils::ReadParam('id', 0);
+ $sClass = utils::ReadParam('sclass', 'bizContact');
+ $sAttCode = utils::ReadParam('attCode', 'name');
+ $sOrg = utils::ReadParam('org_id', '');
+ $sName = utils::ReadParam('q', '');
+ $iMaxCount = utils::ReadParam('max', 30);
+ $aArgs = array();
+ if (!empty($key))
+ {
+ if ($oThis = MetaModel::GetObject($sClass, $key))
+ {
+ $aArgs['*this*'] = $oThis;
+ $aArgs['this'] = $oThis;
+ }
+ }
+ $aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs, $sName);
+ $iCount = 0;
+ foreach($aAllowedValues as $key => $value)
+ {
+ $oPage->add($value."|".$key."\n");
+ }
+ break;
+
+ case 'link':
+ $sClass = utils::ReadParam('sclass', 'logInfra');
+ $sAttCode = utils::ReadParam('attCode', 'name');
+ //$sOrg = utils::ReadParam('org_id', '');
+ $sName = utils::ReadParam('q', '');
+ $iMaxCount = utils::ReadParam('max', 30);
+ $iCount = 0;
+ $oFilter = new DBObjectSearch($sClass);
+ $oFilter->AddCondition($sAttCode, $sName, 'Begins with');
+ //$oFilter->AddCondition('org_id', $sOrg, '=');
+ $oSet = new CMDBObjectSet($oFilter, array($sAttCode => true));
+ while( ($iCount < $iMaxCount) && ($oObj = $oSet->fetch()) )
+ {
+ $oPage->add($oObj->GetAsHTML($sAttCode)."|".$oObj->GetKey()."\n");
+ $iCount++;
+ }
+ break;
+
+ case 'create':
+ case 'create_menu':
+ $sClass = utils::ReadParam('class', '');
+ $sFilter = utils::ReadParam('filter', '');
+ menuNode::DisplayCreationForm($oPage, $sClass, $sFilter);
+ break;
- case 'create':
- case 'create_menu':
- $sClass = utils::ReadParam('class', '');
- $sFilter = utils::ReadParam('filter', '');
- menuNode::DisplayCreationForm($oPage, $sClass, $sFilter);
- break;
+ case 'combo_options':
+ $oFilter = CMDBSearchFilter::FromOQL($sFilter);
+ $oSet = new CMDBObjectSet($oFilter);
+ while( $oObj = $oSet->fetch())
+ {
+ $oPage->add(''.$oObj->GetName().' ');
+ }
+ break;
+
+ case 'display_document':
+ $id = utils::ReadParam('id', '');
+ $sField = utils::ReadParam('field', '');
+ if (!empty($sClass) && !empty($id) && !empty($sField))
+ {
+ DownloadDocument($oPage, $sClass, $id, $sField, 'inline');
+ }
+ break;
+
+ case 'download_document':
+ $id = utils::ReadParam('id', '');
+ $sField = utils::ReadParam('field', '');
+ if (!empty($sClass) && !empty($id) && !empty($sField))
+ {
+ DownloadDocument($oPage, $sClass, $id, $sField, 'attachement');
+ }
+ break;
+
+ case 'search_form':
+ $sClass = utils::ReadParam('className', '');
+ $sRootClass = utils::ReadParam('baseClass', '');
+ $currentId = utils::ReadParam('currentId', '');
+ $oFilter = new DBObjectSearch($sClass);
+ $oSet = new CMDBObjectSet($oFilter);
+ $sHtml = cmdbAbstractObject::GetSearchForm($oPage, $oSet, array('currentId' => $currentId, 'baseClass' => $sRootClass));
+ $oPage->add($sHtml);
+ break;
+
+ case 'set_pref':
+ $sCode = utils::ReadPostedParam('code', '');
+ $sValue = utils::ReadPostedParam('value', '');
+ appUserPreferences::SetPref($sCode, $sValue);
+ break;
+
+ case 'erase_all_pref':
+ // Can be useful in case a user got some corrupted prefs...
+ appUserPreferences::ClearPreferences();
+ break;
+
+ default:
+ $oPage->p("Invalid query.");
+ }
- case 'combo_options':
- $oFilter = CMDBSearchFilter::FromOQL($sFilter);
- $oSet = new CMDBObjectSet($oFilter);
- while( $oObj = $oSet->fetch())
- {
- $oPage->add(''.$oObj->GetName().' ');
- }
- break;
-
- case 'display_document':
- $id = utils::ReadParam('id', '');
- $sField = utils::ReadParam('field', '');
- if (!empty($sClass) && !empty($id) && !empty($sField))
- {
- DownloadDocument($oPage, $sClass, $id, $sField, 'inline');
- }
- break;
-
- case 'download_document':
- $id = utils::ReadParam('id', '');
- $sField = utils::ReadParam('field', '');
- if (!empty($sClass) && !empty($id) && !empty($sField))
- {
- DownloadDocument($oPage, $sClass, $id, $sField, 'attachement');
- }
- break;
-
- case 'search_form':
- $sClass = utils::ReadParam('className', '');
- $sRootClass = utils::ReadParam('baseClass', '');
- $currentId = utils::ReadParam('currentId', '');
- $oFilter = new DBObjectSearch($sClass);
- $oSet = new CMDBObjectSet($oFilter);
- $sHtml = cmdbAbstractObject::GetSearchForm($oPage, $oSet, array('currentId' => $currentId, 'baseClass' => $sRootClass));
- $oPage->add($sHtml);
- break;
-
- case 'set_pref':
- $sCode = utils::ReadPostedParam('code', '');
- $sValue = utils::ReadPostedParam('value', '');
- appUserPreferences::SetPref($sCode, $sValue);
- break;
-
- case 'erase_all_pref':
- // Can be useful in case a user got some corrupted prefs...
- appUserPreferences::ClearPreferences();
- break;
-
- default:
- $oPage->p("Invalid query.");
+ $oPage->output();
}
-$oPage->output();
+catch (Exception $e)
+{
+ IssueLog::Error($e->getMessage());
+}
+
+
/**
* Downloads a document to the browser, either as 'inline' or 'attachment'