forked from Wavyzz/dolibarr
Squelette plus complet.
This commit is contained in:
@@ -53,6 +53,7 @@ $langs->load("other");
|
|||||||
// Get parameters
|
// Get parameters
|
||||||
$id = GETPOST('id','int');
|
$id = GETPOST('id','int');
|
||||||
$action = GETPOST('action','alpha');
|
$action = GETPOST('action','alpha');
|
||||||
|
$backtopage = GETPOST('backtopage');
|
||||||
$myparam = GETPOST('myparam','alpha');
|
$myparam = GETPOST('myparam','alpha');
|
||||||
|
|
||||||
// Protection if external user
|
// Protection if external user
|
||||||
@@ -77,10 +78,18 @@ if (($id > 0 || ! empty($ref)) && $action != 'add')
|
|||||||
* Put here all code to do according to value of "action" parameter
|
* Put here all code to do according to value of "action" parameter
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
|
||||||
|
// Action to add record
|
||||||
if ($action == 'add')
|
if ($action == 'add')
|
||||||
{
|
{
|
||||||
|
if (GETPOST('cancel'))
|
||||||
|
{
|
||||||
|
$urltogo=$backtopage?$backtopage:dol_buildpath('/buildingmanagement/list.php',1);
|
||||||
|
header("Location: ".$urltogo);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
/* object_prop_getpost_prop */
|
/* object_prop_getpost_prop */
|
||||||
$object->prop1=GETPOST("field1");
|
$object->prop1=GETPOST("field1");
|
||||||
$object->prop2=GETPOST("field2");
|
$object->prop2=GETPOST("field2");
|
||||||
@@ -90,14 +99,15 @@ if ($action == 'add')
|
|||||||
$error++;
|
$error++;
|
||||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")),'errors');
|
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")),'errors');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$result=$object->create($user);
|
$result=$object->create($user);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
// Creation OK
|
// Creation OK
|
||||||
header("Location: ".dol_buildpath('/mymodule/list.php',1));
|
$urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1);
|
||||||
|
header("Location: ".$urltogo);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -113,6 +123,62 @@ if ($action == 'add')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cancel
|
||||||
|
if ($action == 'update' && GETPOST('cancel')) $action='view';
|
||||||
|
|
||||||
|
// Action to update record
|
||||||
|
if ($action == 'update' && ! GETPOST('cancel'))
|
||||||
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$object->prop1=GETPOST("field1");
|
||||||
|
$object->prop2=GETPOST("field2");
|
||||||
|
|
||||||
|
if (empty($object->ref))
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")),'errors');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$result=$object->update($user);
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
$action='view';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Creation KO
|
||||||
|
if (! empty($object->errors)) setEventMessage($object->errors, 'errors');
|
||||||
|
else setEventMessage($object->error, 'errors');
|
||||||
|
$action='edit';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$action='edit';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Action to delete
|
||||||
|
if ($action == 'confirm_delete')
|
||||||
|
{
|
||||||
|
$result=$object->delete($user);
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
// Delete OK
|
||||||
|
setEventMessage($langs->trans("RecordDeleted"));
|
||||||
|
header("Location: ".dol_buildpath('/buildingmanagement/list.php',1));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (! empty($object->errors)) setEventMessage($object->errors,'errors');
|
||||||
|
else setEventMessage($object->error,'errors');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -194,6 +260,35 @@ if ($action == 'list' || empty($id))
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Part to create
|
||||||
|
if ($action == 'create')
|
||||||
|
{
|
||||||
|
print_fiche_titre($langs->trans("NewResidence"));
|
||||||
|
|
||||||
|
dol_fiche_head();
|
||||||
|
|
||||||
|
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||||
|
print '<input type="hidden" name="action" value="add">';
|
||||||
|
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
|
||||||
|
|
||||||
|
print '<table class="border centpercent">'."\n";
|
||||||
|
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
|
||||||
|
print '<input class="flat" type="text" size="36" name="label" value="'.$label.'">';
|
||||||
|
print '</td></tr>';
|
||||||
|
|
||||||
|
print '</table>'."\n";
|
||||||
|
|
||||||
|
print '<br>';
|
||||||
|
|
||||||
|
print '<center><input type="submit" class="button" name="add" value="'.$langs->trans("Create").'"> <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></center>';
|
||||||
|
|
||||||
|
print '</form>';
|
||||||
|
|
||||||
|
dol_fiche_end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Part to edit record
|
// Part to edit record
|
||||||
if ($id && $action == 'edit')
|
if ($id && $action == 'edit')
|
||||||
{
|
{
|
||||||
@@ -201,6 +296,8 @@ if ($id && $action == 'edit')
|
|||||||
|
|
||||||
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||||
print '<input type="hidden" name="action" value="add">';
|
print '<input type="hidden" name="action" value="add">';
|
||||||
|
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
|
||||||
|
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||||
|
|
||||||
|
|
||||||
print '<br>';
|
print '<br>';
|
||||||
@@ -218,12 +315,12 @@ if ($id && $action == 'edit')
|
|||||||
if ($id && (empty($action) || $action == 'view'))
|
if ($id && (empty($action) || $action == 'view'))
|
||||||
{
|
{
|
||||||
dol_fiche_head();
|
dol_fiche_head();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dol_fiche_end();
|
dol_fiche_end();
|
||||||
|
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
print '<div class="tabsAction">'."\n";
|
print '<div class="tabsAction">'."\n";
|
||||||
$parameters=array();
|
$parameters=array();
|
||||||
@@ -248,12 +345,12 @@ if ($id && (empty($action) || $action == 'view'))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
print '</div>'."\n";
|
print '</div>'."\n";
|
||||||
|
|
||||||
|
|
||||||
// Example 2 : Adding links to objects
|
// Example 2 : Adding links to objects
|
||||||
// The class must extends CommonObject class to have this method available
|
// The class must extends CommonObject class to have this method available
|
||||||
//$somethingshown=$object->showLinkedObjectBlock();
|
//$somethingshown=$object->showLinkedObjectBlock();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1301,7 +1301,7 @@ else if ($id > 0 || ! empty($ref))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</table><br>";
|
print "</table>";
|
||||||
|
|
||||||
print '</form>';
|
print '</form>';
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,8 @@ print '<table width="100%"><tr><td>';
|
|||||||
dol_print_object_info($soc);
|
dol_print_object_info($soc);
|
||||||
print '</td></tr></table>';
|
print '</td></tr></table>';
|
||||||
|
|
||||||
print '</div>';
|
|
||||||
|
dol_fiche_end();
|
||||||
|
|
||||||
|
|
||||||
llxFooter();
|
llxFooter();
|
||||||
|
|||||||
Reference in New Issue
Block a user