mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 17:48:43 +02:00
@@ -519,7 +519,7 @@ abstract class cmdbAbstractObject extends CMDBObject
|
||||
{
|
||||
foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode => $oAttDef)
|
||||
{
|
||||
if (($sAttCode != 'finalclass') && $oAttDef->IsScalar())
|
||||
if ((($oAttDef->IsExternalField()) || ($oAttDef->IsWritable())) && $oAttDef->IsScalar())
|
||||
{
|
||||
$aList[$sClassName][$sAttCode] = $oAttDef;
|
||||
}
|
||||
@@ -892,38 +892,37 @@ abstract class cmdbAbstractObject extends CMDBObject
|
||||
$oPage->add("<form id=\"form_{$iFormId}\" enctype=\"multipart/form-data\" method=\"post\" onSubmit=\"return CheckMandatoryFields('form_{$iFormId}')\">\n");
|
||||
foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode=>$oAttDef)
|
||||
{
|
||||
if ('finalclass' == $sAttCode) // finalclass is a reserved word, hardcoded !
|
||||
if ($oAttDef->IsWritable())
|
||||
{
|
||||
// Do nothing, the class field is always hidden, it cannot be edited
|
||||
}
|
||||
else if ($sStateAttCode == $sAttCode)
|
||||
{
|
||||
// State attribute is always read-only from the UI
|
||||
$sHTMLValue = $this->GetStateLabel();
|
||||
$aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue);
|
||||
}
|
||||
else if (!$oAttDef->IsExternalField())
|
||||
{
|
||||
$iFlags = $this->GetAttributeFlags($sAttCode);
|
||||
if ($iFlags & OPT_ATT_HIDDEN)
|
||||
if ($sStateAttCode == $sAttCode)
|
||||
{
|
||||
// Attribute is hidden, do nothing
|
||||
// State attribute is always read-only from the UI
|
||||
$sHTMLValue = $this->GetStateLabel();
|
||||
$aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($iFlags & OPT_ATT_READONLY)
|
||||
$iFlags = $this->GetAttributeFlags($sAttCode);
|
||||
if ($iFlags & OPT_ATT_HIDDEN)
|
||||
{
|
||||
// Attribute is read-only
|
||||
$sHTMLValue = $this->GetAsHTML($sAttCode);
|
||||
// Attribute is hidden, do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
$sValue = $this->Get($sAttCode);
|
||||
$sDisplayValue = $this->GetEditValue($sAttCode);
|
||||
$aArgs = array('this' => $this);
|
||||
$sHTMLValue = self::GetFormElementForField($oPage, get_class($this), $sAttCode, $oAttDef, $sValue, $sDisplayValue, '', '', $iFlags, $aArgs);
|
||||
if ($iFlags & OPT_ATT_READONLY)
|
||||
{
|
||||
// Attribute is read-only
|
||||
$sHTMLValue = $this->GetAsHTML($sAttCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sValue = $this->Get($sAttCode);
|
||||
$sDisplayValue = $this->GetEditValue($sAttCode);
|
||||
$aArgs = array('this' => $this);
|
||||
$sHTMLValue = self::GetFormElementForField($oPage, get_class($this), $sAttCode, $oAttDef, $sValue, $sDisplayValue, '', '', $iFlags, $aArgs);
|
||||
}
|
||||
$aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue);
|
||||
}
|
||||
$aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -965,17 +964,13 @@ abstract class cmdbAbstractObject extends CMDBObject
|
||||
|
||||
foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef)
|
||||
{
|
||||
if ('finalclass' == $sAttCode) // finalclass is a reserved word, hardcoded !
|
||||
{
|
||||
// Do nothing, the class field is always hidden, it cannot be edited
|
||||
}
|
||||
else if ($sStateAttCode == $sAttCode)
|
||||
if ($sStateAttCode == $sAttCode)
|
||||
{
|
||||
// State attribute is always read-only from the UI
|
||||
$sHTMLValue = $oObjectToClone->GetStateLabel();
|
||||
$aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue);
|
||||
}
|
||||
else if (!$oAttDef->IsExternalField())
|
||||
else if ((!$oAttDef->IsExternalField()) && ($oAttDef->IsWritable()) )
|
||||
{
|
||||
$sValue = ($oObjectToClone == null) ? '' : $oObjectToClone->Get($sAttCode);
|
||||
$sDisplayValue = ($oObjectToClone == null) ? '' : $oObjectToClone->GetEditValue($sAttCode);
|
||||
|
||||
@@ -38,9 +38,9 @@ class UIWizard
|
||||
$sJSHandlerCode = ''; // Javascript code to be executed each time this step of the wizard is entered
|
||||
foreach($aStep as $sAttCode)
|
||||
{
|
||||
if ($sAttCode != 'finalclass') // Do not display the attribute that stores the actual class name
|
||||
$oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
|
||||
if ($oAttDef->IsWritable())
|
||||
{
|
||||
$oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
|
||||
$sAttLabel = $oAttDef->GetLabel();
|
||||
$iOptions = isset($aStates[$this->m_sTargetState]['attribute_list'][$sAttCode]) ? $aStates[$this->m_sTargetState]['attribute_list'][$sAttCode] : 0;
|
||||
|
||||
@@ -153,7 +153,7 @@ $sJSHandlerCode
|
||||
{
|
||||
$oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
|
||||
if (!$oAttDef->IsExternalField() && !$oAttDef->IsNullAllowed() &&
|
||||
($sAttCode != 'finalclass') && ($sAttCode != $sStateAttCode) )
|
||||
$oAttDef->IsWritable() && ($sAttCode != $sStateAttCode) )
|
||||
{
|
||||
$aMandatoryAttributes[$sAttCode] = OPT_ATT_MANDATORY;
|
||||
}
|
||||
|
||||
45
pages/UI.php
45
pages/UI.php
@@ -766,16 +766,7 @@ try
|
||||
$bObjectModified = false;
|
||||
foreach(MetaModel::ListAttributeDefs(get_class($oObj)) as $sAttCode=>$oAttDef)
|
||||
{
|
||||
$iFlags = $oObj->GetAttributeFlags($sAttCode);
|
||||
if ($iFlags & (OPT_ATT_HIDDEN | OPT_ATT_READONLY))
|
||||
{
|
||||
// Non-visible, or read-only attribute, do nothing
|
||||
}
|
||||
else if ($sAttCode == 'finalclass')
|
||||
{
|
||||
// This very specific field is read-only
|
||||
}
|
||||
else if ($oAttDef->IsLinkSet())
|
||||
if ($oAttDef->IsLinkSet())
|
||||
{
|
||||
// Link set, the data is a set of link objects, encoded in JSON
|
||||
$aAttributes[$sAttCode] = trim(utils::ReadPostedParam("attr_$sAttCode", ''));
|
||||
@@ -787,17 +778,6 @@ try
|
||||
$bObjectModified = true;
|
||||
}
|
||||
}
|
||||
else if ($oAttDef->GetEditClass() == 'Document')
|
||||
{
|
||||
// There should be an uploaded file with the named attr_<attCode>
|
||||
$oDocument = utils::ReadPostedDocument('file_'.$sAttCode);
|
||||
if (!$oDocument->IsEmpty())
|
||||
{
|
||||
// A new file has been uploaded
|
||||
$oObj->Set($sAttCode, $oDocument);
|
||||
$bObjectModified = true;
|
||||
}
|
||||
}
|
||||
else if (!$oAttDef->IsExternalField())
|
||||
{
|
||||
$rawValue = utils::ReadPostedParam("attr_$sAttCode", null);
|
||||
@@ -812,6 +792,25 @@ try
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($oAttDef->IsWritable())
|
||||
{
|
||||
$iFlags = $oObj->GetAttributeFlags($sAttCode);
|
||||
if ($iFlags & (OPT_ATT_HIDDEN | OPT_ATT_READONLY))
|
||||
{
|
||||
// Non-visible, or read-only attribute, do nothing
|
||||
}
|
||||
else if ($oAttDef->GetEditClass() == 'Document')
|
||||
{
|
||||
// There should be an uploaded file with the named attr_<attCode>
|
||||
$oDocument = utils::ReadPostedDocument('file_'.$sAttCode);
|
||||
if (!$oDocument->IsEmpty())
|
||||
{
|
||||
// A new file has been uploaded
|
||||
$oObj->Set($sAttCode, $oDocument);
|
||||
$bObjectModified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$bObjectModified)
|
||||
{
|
||||
@@ -954,9 +953,7 @@ try
|
||||
$sStateAttCode = MetaModel::GetStateAttributeCode(get_class($oObj));
|
||||
foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef)
|
||||
{
|
||||
if ( ('finalclass' != $sAttCode) && // finalclass is a reserved word, hardcoded !
|
||||
($sStateAttCode != $sAttCode) &&
|
||||
(!$oAttDef->IsExternalField()) )
|
||||
if ( ($oAttDef->IsWritable()) )
|
||||
{
|
||||
$value = utils::ReadPostedParam('attr_'.$sAttCode, '');
|
||||
$oObj->Set($sAttCode, $value);
|
||||
|
||||
@@ -9,11 +9,14 @@ require_once('../application/csvpage.class.inc.php');
|
||||
/**
|
||||
* Helper function to build the mapping drop-down list for a field
|
||||
*/
|
||||
function GetMappingForField($sClassName, $sFieldName, $iFieldIndex)
|
||||
function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMode = false)
|
||||
{
|
||||
$aChoices = array('' => '-- select one --');
|
||||
$aChoices[':none:'] = '------ n/a ------';
|
||||
$aChoices['id'] = 'id (Primary Key)';
|
||||
$aChoices = array('' => Dict::S('UI:CSVImport:MappingSelectOne'));
|
||||
$aChoices[':none:'] = Dict::S('UI:CSVImport:MappingNotApplicable');
|
||||
if ($bAdvancedMode)
|
||||
{
|
||||
$aChoices['id'] = Dict::S('UI:CSVImport:idField');
|
||||
}
|
||||
foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode => $oAttDef)
|
||||
{
|
||||
if ($oAttDef->IsExternalKey())
|
||||
@@ -44,6 +47,10 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex)
|
||||
{
|
||||
$sSelected = ' selected';
|
||||
}
|
||||
if ((!$bAdvancedMode) && ($sAttCode == ':none:') && ($sFieldName == 'id'))
|
||||
{
|
||||
$sSelected = ' selected';
|
||||
}
|
||||
$sHtml .= "<option value=\"$sAttCode\"$sSelected>$sLabel</option>\n";
|
||||
}
|
||||
$sHtml .= "</select>\n";
|
||||
@@ -85,13 +92,13 @@ switch($sOperation)
|
||||
$iTarget = count($aData);
|
||||
if ($iTarget == 0)
|
||||
{
|
||||
$oPage->p("Empty data set..., please provide some data!");
|
||||
$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("<h3>Data Preview</h3>\n");
|
||||
$oPage->p("<h3>".Dict::S('UI:Title:DataPreview')."</h3>\n");
|
||||
$oPage->p("<div style=\"overflow-y:auto\">\n");
|
||||
$oPage->add("<table cellspacing=\"0\" style=\"overflow-y:auto\">");
|
||||
$iMaxIndex= 10; // Display maximum 10 lines for the preview
|
||||
@@ -121,7 +128,7 @@ switch($sOperation)
|
||||
$oPage->add("</div>\n");
|
||||
if($iNbCols == 1)
|
||||
{
|
||||
$oPage->p('<img src="../images/error.png"> Error: The data contains only one column. Did you select the appropriate separator character ?');
|
||||
$oPage->p('<img src="../images/error.png"> '.Dict::S('UI:CSVImport:ErrorOnlyOneColumn'));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -139,13 +146,14 @@ switch($sOperation)
|
||||
$bFirstLineAsHeader = utils::ReadParam('header_line', true);
|
||||
$sData = stripslashes(utils::ReadParam('csvdata', true));
|
||||
$sClassName = utils::ReadParam('class_name', '');
|
||||
$bAdvanced = utils::ReadParam('advanced', false);
|
||||
|
||||
$oCSVParser = new CSVParser($sData, $sSeparator, $sTextQualifier);
|
||||
$aData = $oCSVParser->ToArray($iLinesToSkip);
|
||||
$iTarget = count($aData);
|
||||
if ($iTarget == 0)
|
||||
{
|
||||
$oPage->p("Empty data set..., please provide some data!");
|
||||
$oPage->p(Dict::S('UI:CSVImport:NoData'));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -167,19 +175,19 @@ switch($sOperation)
|
||||
$index= 1;
|
||||
foreach($aFirstLine as $sField)
|
||||
{
|
||||
$aHeader[] = 'Field'+$index;
|
||||
$aHeader[] = Dict::Format('UI:CSVImport:FieldName', $index);
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
$oPage->add("<table>\n");
|
||||
$oPage->add('<tr>');
|
||||
$oPage->add("<th>Fields</th><th>Mapping</th><th> </th><th>Search ?</th><th>Data line 1</th><th>Data line 2</th>");
|
||||
$oPage->add('<th>'.Dict::S('UI:CSVImport:HeaderFields').'</th><th>'.Dict::S('UI:CSVImport:HeaderMappings').'</th><th> </th><th>'.Dict::S('UI:CSVImport:HeaderSearch').'</th><th>'.Dict::S('UI:CSVImport:DataLine1').'</th><th>'.Dict::S('UI:CSVImport:DataLine2').'</th>');
|
||||
$oPage->add('</tr>');
|
||||
foreach($aHeader as $sField)
|
||||
{
|
||||
$oPage->add('<tr>');
|
||||
$oPage->add("<th>$sField</th>");
|
||||
$oPage->add('<td>'.GetMappingForField($sClassName, $sField, $index).'</td>');
|
||||
$oPage->add('<td>'.GetMappingForField($sClassName, $sField, $index, $bAdvanced).'</td>');
|
||||
$oPage->add('<td> </td>');
|
||||
$oPage->add('<td><input id="search_'.$index.'" type="checkbox" name="search_field['.$index.']" value="1" /></td>');
|
||||
$oPage->add('<td>'.(isset($aData[$iStartLine][$index-1]) ? htmlentities($aData[$iStartLine][$index-1], ENT_QUOTES, 'UTF-8') : ' ').'</td>');
|
||||
@@ -188,6 +196,15 @@ switch($sOperation)
|
||||
$index++;
|
||||
}
|
||||
$oPage->add("</table>\n");
|
||||
$aReconciliationKeys = MetaModel::GetReconcKeys($sClassName);
|
||||
$sDefaultKeys = '"'.implode('", "',$aReconciliationKeys).'"';
|
||||
$oPage->add_ready_script(
|
||||
<<<EOF
|
||||
$('select[name^=field]').change( DoCheckMapping );
|
||||
aDefaultKeys = new Array($sDefaultKeys);
|
||||
DoCheckMapping();
|
||||
EOF
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user