2
0
forked from Wavyzz/dolibarr

Squelette plus complet.

This commit is contained in:
Laurent Destailleur
2014-08-15 21:18:56 +02:00
parent 8eac8c0c84
commit 2eb01cfbf9
3 changed files with 111 additions and 13 deletions

View File

@@ -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,8 +78,16 @@ 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 */
@@ -97,7 +106,8 @@ if ($action == 'add')
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").'"> &nbsp; <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>';

View File

@@ -1301,7 +1301,7 @@ else if ($id > 0 || ! empty($ref))
} }
} }
print "</table><br>"; print "</table>";
print '</form>'; print '</form>';

View File

@@ -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();