diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 75540df892e..b3c7a99d24e 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -58,7 +58,7 @@ class MyObject extends CommonObject public $picto = 'myobject'; - /* + /** * 'type' if the field format, 'label' the translation key, 'enabled' is a condition when the filed must be managed, * 'visible' says if field is visible in list (-1 means not shown by default but can be aded into list to be viewed) * 'notnull' if not null in database @@ -84,8 +84,8 @@ class MyObject extends CommonObject 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>true, 'position'=>1000, 'nullifempty'=>1), ); // END MODULEBUILDER PROPERTIES - - + + // If this object has a subtable with lines diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index c2927885e35..9b3029c659d 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -110,6 +110,8 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { + $error=0; + if ($cancel) { if ($action != 'addlink') @@ -125,19 +127,10 @@ if (empty($reshook)) // Action to add record if ($action == 'add' && ! empty($user->rights->mymodule->create)) { - if ($cancel) - { - $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/myobject_list.php',1); - header("Location: ".$urltogo); - exit; - } - - $error=0; - foreach ($object->fields as $key => $val) { if (in_array($key, array('entity', 'date_creation', 'tms', 'import_key'))) continue; // Ignore special fields - + $object->$key=GETPOST($key,'alpha'); if ($val['notnull'] && $object->$key == '') { @@ -173,20 +166,20 @@ if (empty($reshook)) // Action to update record if ($action == 'update' && ! empty($user->rights->mymodule->create)) { - $error=0; - - $object->prop1=GETPOST("field1"); - $object->prop2=GETPOST("field2"); - - if (empty($object->ref)) - { - $error++; - setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors'); - } + foreach ($object->fields as $key => $val) + { + $object->$key=GETPOST($key,'alpha'); + if (in_array($key, array('entity', 'datec', 'tms'))) continue; + if ($val['notnull'] && $object->$key == '') + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv($val['label'])), null, 'errors'); + } + } if (! $error) { - $result=$object->update($user); + $result=$object->updateCommon($user); if ($result > 0) { $action='view'; @@ -208,7 +201,7 @@ if (empty($reshook)) // Action to delete if ($action == 'confirm_delete' && ! empty($user->rights->mymodule->delete)) { - $result=$object->delete($user); + $result=$object->deleteCommon($user); if ($result > 0) { // Delete OK diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 8d2a5edce34..b0f95ba6ff4 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -510,11 +510,11 @@ while ($i < min($num, $limit)) print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1); print ''; if (! $i) $totalarray['nbfield']++; - if (! empty($val['isameasure'])) - { - if (! $i) $totalarray['pos'][$totalarray['nbfield']]='ef.'.$tmpkey; - $totalarray['val']['ef.'.$tmpkey] += $obj->$tmpkey; - } + if (! empty($val['isameasure'])) + { + if (! $i) $totalarray['pos'][$totalarray['nbfield']]='ef.'.$tmpkey; + $totalarray['val']['ef.'.$tmpkey] += $obj->$tmpkey; + } } } }