Fix: Error management when adding notification

This commit is contained in:
Laurent Destailleur 2011-09-02 23:41:55 +00:00
parent 366613bed5
commit 18683c5bf0

View File

@ -52,6 +52,8 @@ $pagenext = $page + 1;
if (! $sortorder) $sortorder="ASC"; if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="c.name"; if (! $sortfield) $sortfield="c.name";
$now=dol_now();
/* /*
* Actions * Actions
@ -60,12 +62,29 @@ if (! $sortfield) $sortfield="c.name";
// Add a notification // Add a notification
if ($action == 'add') if ($action == 'add')
{ {
$error=0;
if (empty($contactid))
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Contact")).'</div>';
$error++;
}
if ($actionid <= 0)
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Action")).'</div>';
$error++;
}
if (! $error)
{
$db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def";
$sql .= " WHERE fk_soc=".$socid." AND fk_contact=".$_POST["contactid"]." AND fk_action=".$_POST["actionid"]; $sql .= " WHERE fk_soc=".$socid." AND fk_contact=".$contactid." AND fk_action=".$actionid;
if ($db->query($sql)) if ($db->query($sql))
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_soc, fk_contact, fk_action)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_soc, fk_contact, fk_action)";
$sql .= " VALUES (".$db->idate(mktime()).",".$socid.",".$_POST["contactid"].",".$_POST["actionid"].")"; $sql .= " VALUES ('".$db->idate($now)."',".$socid.",".$contactid.",".$actionid.")";
if ($db->query($sql)) if ($db->query($sql))
{ {
@ -73,6 +92,7 @@ if ($action == 'add')
} }
else else
{ {
$error++;
dol_print_error($db); dol_print_error($db);
} }
} }
@ -80,6 +100,16 @@ if ($action == 'add')
{ {
dol_print_error($db); dol_print_error($db);
} }
if (! $error)
{
$db->commit();
}
else
{
$db->rollback();
}
}
} }
// Remove a notification // Remove a notification
@ -119,6 +149,30 @@ if ($result > 0)
print $form->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom'); print $form->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom');
print '</td></tr>'; print '</td></tr>';
// Prefix
if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
{
print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
}
if ($object->client)
{
print '<tr><td>';
print $langs->trans('CustomerCode').'</td><td colspan="3">';
print $object->code_client;
if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
print '</td></tr>';
}
if ($object->fournisseur)
{
print '<tr><td>';
print $langs->trans('SupplierCode').'</td><td colspan="3">';
print $object->code_fournisseur;
if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
print '</td></tr>';
}
print '<tr><td width="30%">'.$langs->trans("NbOfActiveNotifications").'</td>'; print '<tr><td width="30%">'.$langs->trans("NbOfActiveNotifications").'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
$sql = "SELECT COUNT(n.rowid) as nb"; $sql = "SELECT COUNT(n.rowid) as nb";
@ -157,6 +211,7 @@ if ($result > 0)
print '<form action="fiche.php?socid='.$socid.'" method="post">'; print '<form action="fiche.php?socid='.$socid.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
// Line with titles // Line with titles
print '<table width="100%" class="noborder">'; print '<table width="100%" class="noborder">';
@ -183,7 +238,6 @@ if ($result > 0)
$label=$langs->trans("Notify_".$notifiedevent['code'])!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label']; $label=$langs->trans("Notify_".$notifiedevent['code'])!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label'];
$actions[$notifiedevent['rowid']]=$label; $actions[$notifiedevent['rowid']]=$label;
} }
print '<input type="hidden" name="action" value="add">';
print '<tr '.$bc[$var].'><td>'; print '<tr '.$bc[$var].'><td>';
print $html->selectarray("contactid",$listofemails); print $html->selectarray("contactid",$listofemails);
print '</td>'; print '</td>';
@ -209,6 +263,7 @@ if ($result > 0)
print '</form>'; print '</form>';
print '<br>'; print '<br>';
dol_htmloutput_mesg($mesg);
// List of active notifications // List of active notifications
print_fiche_titre($langs->trans("ListOfActiveNotifications"),'',''); print_fiche_titre($langs->trans("ListOfActiveNotifications"),'','');