m_iFormId}', false);
EOF
);
}
-
+
public static function DisplayCreationForm(WebPage $oPage, $sClass, $oObjectToClone = null, $aArgs = array(), $aExtraParams = array())
{
- static $iCreationFormId = 0;
-
- $iCreationFormId++;
- $iFieldIndex = 0;
$oAppContext = new ApplicationContext();
- $aDetails = array();
- $aFieldsMap = array();
- $sOperation = ($oObjectToClone == null) ? 'apply_new' : 'apply_clone';
$sClass = ($oObjectToClone == null) ? $sClass : get_class($oObjectToClone);
$sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
- $oPage->add("\n");
- $aNewFieldsMap = array();
- foreach($aFieldsMap as $id => $sFieldCode)
- {
- $aNewFieldsMap[$sFieldCode] = $id;
- }
- $iFieldsCount = count($aFieldsMap);
- $sJsonFieldsMap = json_encode($aNewFieldsMap);
-
- $oPage->add_script("
- // Initializes the object once at the beginning of the page...
- var oWizardHelper = new WizardHelper('$sClass');
- oWizardHelper.SetFieldsMap($sJsonFieldsMap);
- oWizardHelper.SetFieldsCount($iFieldsCount);");
- $oPage->add_ready_script("CheckFields('creation_form_{$iCreationFormId}', false);");
+ return $oObj->DisplayModifyForm( $oPage, $aExtraParams = array());
}
protected static function GetCSSClasses($aCSSClasses)
diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php
index 826741fc7..46c1d590d 100644
--- a/application/displayblock.class.inc.php
+++ b/application/displayblock.class.inc.php
@@ -521,7 +521,15 @@ class DisplayBlock
{
$oAppContext = new ApplicationContext();
$sParams = $oAppContext->GetForLink();
- $sHtml .= $oPage->GetP("".Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass))."\n");
+ $sDefaults = '';
+ if (isset($this->m_aParams['default']))
+ {
+ foreach($this->m_aParams['default'] as $sName => $sValue)
+ {
+ $sDefaults .= '&'.urlencode($sName).'='.urlencode($sValue);
+ }
+ }
+ $sHtml .= $oPage->GetP("".Dict::Format('UI:ClickToCreateNew', Metamodel::GetName($sClass))."\n");
}
}
}
diff --git a/core/dbobject.class.php b/core/dbobject.class.php
index 6d0ee602d..d4b31bb4f 100644
--- a/core/dbobject.class.php
+++ b/core/dbobject.class.php
@@ -915,6 +915,18 @@ abstract class DBObject
$this->m_iKey = $iNewKey;
return $this->DBInsert();
}
+
+ /**
+ * This function is automatically called after cloning an object with the "clone" PHP language construct
+ * The purpose of this method is to reset the appropriate attributes of the object in
+ * order to make sure that the newly cloned object is really distinct from its clone
+ */
+ public function __clone()
+ {
+ $this->m_bIsInDB = false;
+ $this->m_bDirty = true;
+ $this->m_iKey = self::GetNextTempId(get_class($this));
+ }
// To be optionaly overloaded
protected function OnUpdate()
diff --git a/pages/UI.php b/pages/UI.php
index 758df0220..fcfa11b37 100644
--- a/pages/UI.php
+++ b/pages/UI.php
@@ -803,7 +803,20 @@ try
{
$aDefaults[$key] = $value;
}
- cmdbAbstractObject::DisplayCreationForm($oP, $sRealClass, null /* $oObjToClone */, array('default' => $aDefaults));
+ // Set all the default values in an object and clone this "default" object
+ $oObjToClone = MetaModel::NewObject($sRealClass);
+ foreach($aDefaults as $sName => $value)
+ {
+ if (MetaModel::IsValidAttCode($sRealClass, $sName))
+ {
+ $oAttDef = MetaModel::GetAttributeDef($sRealClass, $sName);
+ if ($oAttDef->IsWritable())
+ {
+ $oObjToClone->Set($sName, $value);
+ }
+ }
+ }
+ cmdbAbstractObject::DisplayCreationForm($oP, $sRealClass, $oObjToClone, array('default' => $aDefaults));
$oP->add("\n");
}
else