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
$id = GETPOST('id','int');
$action = GETPOST('action','alpha');
$backtopage = GETPOST('backtopage');
$myparam = GETPOST('myparam','alpha');
// 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
********************************************************************/
// Action to add record
if ($action == 'add')
{
if (GETPOST('cancel'))
{
$urltogo=$backtopage?$backtopage:dol_buildpath('/buildingmanagement/list.php',1);
header("Location: ".$urltogo);
exit;
}
$error=0;
/* object_prop_getpost_prop */
$object->prop1=GETPOST("field1");
$object->prop2=GETPOST("field2");
@@ -90,14 +99,15 @@ if ($action == 'add')
$error++;
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")),'errors');
}
if (! $error)
{
$result=$object->create($user);
if ($result > 0)
{
// Creation OK
header("Location: ".dol_buildpath('/mymodule/list.php',1));
$urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1);
header("Location: ".$urltogo);
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
if ($id && $action == 'edit')
{
@@ -201,6 +296,8 @@ if ($id && $action == 'edit')
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 '<input type="hidden" name="id" value="'.$object->id.'">';
print '<br>';
@@ -218,12 +315,12 @@ if ($id && $action == 'edit')
if ($id && (empty($action) || $action == 'view'))
{
dol_fiche_head();
dol_fiche_end();
// Buttons
print '<div class="tabsAction">'."\n";
$parameters=array();
@@ -248,12 +345,12 @@ if ($id && (empty($action) || $action == 'view'))
}
}
print '</div>'."\n";
// Example 2 : Adding links to objects
// The class must extends CommonObject class to have this method available
//$somethingshown=$object->showLinkedObjectBlock();
}

View File

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

View File

@@ -76,7 +76,8 @@ print '<table width="100%"><tr><td>';
dol_print_object_info($soc);
print '</td></tr></table>';
print '</div>';
dol_fiche_end();
llxFooter();