Task #10786: works for internal users in setup module

This commit is contained in:
Juanjo Menent 2010-12-07 20:57:34 +00:00
parent a9ee54d9cc
commit 21d35ccda8
8 changed files with 76 additions and 26 deletions

View File

@ -56,7 +56,7 @@ if ($_GET["action"] == "set")
if ($_GET["action"] == "addnotif")
{
$bon = new BonPrelevement($db);
$bon->AddNotification($_POST["user"],$_POST["action"]);
$bon->AddNotification($db,$_POST["user"],$_POST["action"]);
Header("Location: prelevement.php");
exit;
@ -173,21 +173,33 @@ if ($conf->global->MAIN_MODULE_NOTIFICATION)
{
$langs->load("mails");
print_titre($langs->trans("Notifications"));
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=addnotif">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("User").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print '<td align="right">'.$langs->trans("Action").'</td>';
print "</tr>\n";
print '<tr class="impair"><td align="left">';
print $html->select_users(0,'user',0);
print '</td>';
print '<td>';
print '<select name="action">';
$sql = "SELECT rowid, code, titre";
$sql = "SELECT rowid, name, firstname, fk_societe, email";
$sql.= " FROM ".MAIN_DB_PREFIX."user";
$sql.= " WHERE entity IN (0,".$conf->entity.")";
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$var = true;
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$var=!$var;
if (!$obj->fk_societe)
{
$username= $obj->firstname.' '.$obj->name;
$internalusers[$obj->rowid] = $username;
}
$i++;
}
$db->free($resql);
}
$sql = "SELECT rowid, code, titre";
$sql.= " FROM ".MAIN_DB_PREFIX."action_def";
$sql.= " WHERE objet_type = 'withdraw'";
$resql = $db->query($sql);
@ -199,11 +211,31 @@ if ($conf->global->MAIN_MODULE_NOTIFICATION)
while ($i < $num)
{
$obj = $db->fetch_object($resql);
print '<option value="'.$obj->code.'">'.$obj->titre.'</option>';
$label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->titre);
$actions[$obj->rowid]=$label;
$i++;
}
$db->free($resql);
}
print '</select></td>';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=addnotif">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("User").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print '<td align="right">'.$langs->trans("Action").'</td>';
print "</tr>\n";
print '<tr class="impair"><td align="left">';
print $html->selectarray('user',$internalusers);// select_users(0,'user',0);
print '</td>';
print '<td>';
print $html->selectarray('action',$actions);// select_users(0,'user',0);
print '</td>';
print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td></tr>';
}
// List of current notifications for objet_type='withdraw'
@ -212,7 +244,7 @@ $sql.= ", nd.rowid, ad.code, ad.titre";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
$sql.= ", ".MAIN_DB_PREFIX."notify_def as nd";
$sql.= ", ".MAIN_DB_PREFIX."action_def as ad";
$sql.= " WHERE u.rowid = nd.fk_soc AND nd.fk_action = ad.rowid";
$sql.= " WHERE u.rowid = nd.fk_user AND nd.fk_action = ad.rowid";
$sql.= " AND ad.objet_type = 'withdraw'";
$sql.= " AND u.entity IN (0,".$conf->entity.")";
$resql = $db->query($sql);
@ -228,7 +260,8 @@ if ($resql)
print "<tr $bc[$var]>";
print '<td>'.$obj->firstname." ".$obj->name.'</td>';
print '<td>'.$obj->titre.'</td>';
$label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->titre);
print '<td>'.$label.'</td>';
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=deletenotif&amp;notif='.$obj->rowid.'">'.img_delete().'</a></td>';
print '</tr>';
$i++;

View File

@ -1145,7 +1145,7 @@ class BonPrelevement extends CommonObject
$result = 0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def";
$sql .= " WHERE fk_soc=".$user." AND AND fk_action=".$action;
$sql .= " WHERE fk_user=".$user." AND fk_action=".$action;
if ($this->db->query($sql))
{
@ -1163,15 +1163,16 @@ class BonPrelevement extends CommonObject
* @param action notification action
* @return int 0 if OK, <0 if KO
*/
function AddNotification($user, $action)
function AddNotification($db, $user, $action)
{
$result = 0;
if ($this->DeleteNotification($user, $action) == 0)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_soc, fk_contact, fk_action)";
$sql .= " VALUES (".$db->idate(mktime()).",".$user.", '',".$action.")";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
$sql .= " VALUES (".$db->idate(mktime()).",".$user.", 'NULL', 'NULL', ".$action.")";
dol_syslog("adnotiff: ".$sql);
if ($this->db->query($sql))
{
$result = 0;

View File

@ -5,7 +5,7 @@
-- Copyright (C) 2004 Guillaume Delecourt <guillaume.delecourt@opensides.be>
-- Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
-- Copyright (C) 2010 Juanjo Menentn <jmenent@2byte.es>
-- Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -41,3 +41,4 @@ insert into llx_action_def (rowid,code,titre,description,objet_type) values (5,'
insert into llx_action_def (rowid,code,titre,description,objet_type) values (6,'NOTIFY_VAL_PROPAL','Validation proposition client','Executed when a commercial proposal is validated','propal');
insert into llx_action_def (rowid,code,titre,description,objet_type) values (7,'NOTIFY_TRN_WITHDRAW','Transmission prélèvement','Executed when a withdrawal is transmited','withdraw');
insert into llx_action_def (rowid,code,titre,description,objet_type) values (8,'NOTIFY_CRD_WITHDRAW','Créditer prélèvement','Executed when a withdrawal is credited','withdraw');
insert into llx_action_def (rowid,code,titre,description,objet_type) values (9,'NOTIFY_EMT_WITHDRAW','Emission prélèvement','Executed when a withdrawal is emited','withdraw');

View File

@ -31,6 +31,9 @@ Notify_NOTIFY_APP_ORDER_SUPPLIER=Aprovació comanda a proveïdor
Notify_NOTIFY_REF_ORDER_SUPPLIER=Rebuig comanda a proveïdor
Notify_NOTIFY_VAL_ORDER=Validació comanda client
Notify_NOTIFY_VAL_PROPAL=Validació pressupost client
Notify_NOTIFY_TRN_WITHDRAW=Transmissió domiciliació
Notify_NOTIFY_CRD_WITHDRAW=Abonament domiciliació
Notify_NOTIFY_EMT_WITHDRAW=Emissió domiciliació
NbOfAttachedFiles=Número arxius/documents adjunts
TotalSizeOfAttachedFiles=Mida total dels arxius/documents adjunts
MaxSize=Tamany màxim

View File

@ -31,6 +31,9 @@ Notify_NOTIFY_APP_ORDER_SUPPLIER=Supplier order approved
Notify_NOTIFY_REF_ORDER_SUPPLIER=Supplier order refused
Notify_NOTIFY_VAL_ORDER=Customer order validated
Notify_NOTIFY_VAL_PROPAL=Customer proposal validated
Notify_NOTIFY_TRN_WITHDRAW=Transmission withdrawal
Notify_NOTIFY_CRD_WITHDRAW=Credit withdrawal
Notify_NOTIFY_EMT_WITHDRAW=Isue withdrawal
NbOfAttachedFiles=Number of attached files/documents
TotalSizeOfAttachedFiles=Total size of attached files/documents
MaxSize=Maximum size

View File

@ -31,6 +31,9 @@ Notify_NOTIFY_APP_ORDER_SUPPLIER=Aprobación pedido a proveedor
Notify_NOTIFY_REF_ORDER_SUPPLIER=Rechazo pedido a proveedor
Notify_NOTIFY_VAL_ORDER=Validación pedido cliente
Notify_NOTIFY_VAL_PROPAL=Validación presupuesto cliente
Notify_NOTIFY_TRN_WITHDRAW=Transmisión domiciliación
Notify_NOTIFY_CRD_WITHDRAW=Abono domiciliación
Notify_NOTIFY_EMT_WITHDRAW=Emisión domiciliación
NbOfAttachedFiles=Número archivos/documentos adjuntos
TotalSizeOfAttachedFiles=Tamaño total de los archivos/documentos adjuntos
MaxSize=Tamaño máximo

View File

@ -31,6 +31,9 @@ Notify_NOTIFY_APP_ORDER_SUPPLIER=Aprobación pedido a proveedor
Notify_NOTIFY_REF_ORDER_SUPPLIER=Rechazo pedido a proveedor
Notify_NOTIFY_VAL_ORDER=Validación pedido cliente
Notify_NOTIFY_VAL_PROPAL=Validación presupuesto cliente
Notify_NOTIFY_TRN_WITHDRAW=Transmisión domiciliación
Notify_NOTIFY_CRD_WITHDRAW=Abono domiciliación
Notify_NOTIFY_EMT_WITHDRAW=Emisión domiciliación
NbOfAttachedFiles=Número archivos/documentos adjuntos
TotalSizeOfAttachedFiles=Tamaño total de los archivos/documentos adjuntos
MaxSize=Tamaño máximo

View File

@ -31,6 +31,9 @@ Notify_NOTIFY_APP_ORDER_SUPPLIER=Approbation commande fournisseur
Notify_NOTIFY_REF_ORDER_SUPPLIER=Refus commande fournisseur
Notify_NOTIFY_VAL_ORDER=Validation commande client
Notify_NOTIFY_VAL_PROPAL=Validation proposition commerciale client
Notify_NOTIFY_TRN_WITHDRAW=Transmission prélèvement
Notify_NOTIFY_CRD_WITHDRAW=Créditer prélèvement
Notify_NOTIFY_EMT_WITHDRAW=Emission prélèvement
NbOfAttachedFiles=Nombre de fichiers/documents liés
TotalSizeOfAttachedFiles=Taille total fichiers/documents liés
MaxSize=Taille maximum