diff --git a/htdocs/societe/notify/fiche.php b/htdocs/societe/notify/fiche.php index 90761c9f2f9..5787094a038 100644 --- a/htdocs/societe/notify/fiche.php +++ b/htdocs/societe/notify/fiche.php @@ -34,8 +34,12 @@ $langs->load("mails"); $langs->load("admin"); $langs->load("other"); +$socid = GETPOST("socid",'int'); +$action = GETPOST('action'); +$contactid=GETPOST('contactid'); // May be an int or 'thirdparty' +$actionid=GETPOST('actionid'); + // Security check -$socid = isset($_GET["socid"])?$_GET["socid"]:''; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe','',''); @@ -49,38 +53,69 @@ $pagenext = $page + 1; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="c.name"; +$now=dol_now(); + /* * Action */ // Add a notification -if ($_POST["action"] == 'add') +// Add a notification +if ($action == 'add') { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def"; - $sql .= " WHERE fk_soc=".$socid." AND fk_contact=".$_POST["contactid"]." AND fk_action=".$_POST["actionid"]; - if ($db->query($sql)) - { - $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"].")"; + $error=0; - if ($db->query($sql)) - { + if (empty($contactid)) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Contact")).'
'; + $error++; + } + if ($actionid <= 0) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Action")).'
'; + $error++; + } - } - else - { - dol_print_error($db); - } - } - else - { - dol_print_error($db); - } + if (! $error) + { + $db->begin(); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def"; + $sql .= " WHERE fk_soc=".$socid." AND fk_contact=".$contactid." AND fk_action=".$actionid; + if ($db->query($sql)) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_soc, fk_contact, fk_action)"; + $sql .= " VALUES ('".$db->idate($now)."',".$socid.",".$contactid.",".$actionid.")"; + + if ($db->query($sql)) + { + + } + else + { + $error++; + dol_print_error($db); + } + } + else + { + dol_print_error($db); + } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + } + } } // Remove a notification -if ($_GET["action"] == 'delete') +if ($action == 'delete') { $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def where rowid=".$_GET["actid"].";"; $db->query($sql); @@ -97,9 +132,9 @@ $form = new Form($db); llxHeader(); $soc = new Societe($db); -$soc->id = $socid; +$result=$soc->fetch($socid); -if ( $soc->fetch($soc->id) ) +if ($result > 0) { $html = new Form($db); $langs->load("other"); @@ -116,6 +151,30 @@ if ( $soc->fetch($soc->id) ) print $form->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom'); print ''; + // Prefix + if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field + { + print ''.$langs->trans('Prefix').''.$object->prefix_comm.''; + } + + if ($object->client) + { + print ''; + print $langs->trans('CustomerCode').''; + print $object->code_client; + if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; + print ''; + } + + if ($object->fournisseur) + { + print ''; + print $langs->trans('SupplierCode').''; + print $object->code_fournisseur; + if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; + print ''; + } + print ''.$langs->trans("NbOfActiveNotifications").''; print ''; $sql = "SELECT COUNT(n.rowid) as nb"; @@ -154,7 +213,8 @@ if ( $soc->fetch($soc->id) ) print '
'; print ''; - + print ''; + // Line with titles print ''; print ''; @@ -162,8 +222,8 @@ if ( $soc->fetch($soc->id) ) print_liste_field_titre($langs->trans("Contact"),"fiche.php","c.name",'',$param,'"width="45%"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Action"),"fiche.php","a.titre",'',$param,'"width="35%"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Type"),"fiche.php","",'',$param,'"width="10%"',$sortfield,$sortorder); - print ''; - print ''; + print_liste_field_titre(''); + print ''; $var=false; if (count($soc->thirdparty_and_contact_email_array()) > 0) @@ -205,7 +265,8 @@ if ( $soc->fetch($soc->id) ) print ''; print '
'; - + dol_htmloutput_mesg($mesg); + // List of active notifications print_fiche_titre($langs->trans("ListOfActiveNotifications"),'',''); $var=true; @@ -346,6 +407,7 @@ if ( $soc->fetch($soc->id) ) print '
 
'; } +else dol_print_error('','RecordNotFound'); $db->close();