Skip to content

Commit

Permalink
New: task #10538: Add filter on expiration date of subscription for f…
Browse files Browse the repository at this point in the history
…oundation module email selector.

Fix: Postgresql compatibility.
  • Loading branch information
eldy committed Aug 12, 2010
1 parent ef04398 commit 11041ce
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 26 deletions.
5 changes: 4 additions & 1 deletion ChangeLog
Expand Up @@ -5,6 +5,9 @@ English Dolibarr ChangeLog
For users:
- New: When sending supplier orders by mail, a text is predefined.
- New: Upgrade process works with Postgresql.
- New: Task #10538: Add filter on expiration date of subscription for
foundation module email selector.
- Fix: Better Postgresql compatibility.

For developer:
- Qual: Renamed some fields into database to be more internationnal.
Expand All @@ -20,7 +23,7 @@ For users:
- New: Can reopen a refused/canceled supplier order.
- New: Add Gant diagramm on project module.
- New: Add a new mode for automatic stock increase: Can be increased
on dispatching of products from a supplier order receipt.
on dispatching of products from a supplier order receipt.
- New: Can set a past delay to limit calendar export.
- New: Can attach files on emailing campaigns.
- New: Add statistics on trips and expenses module.
Expand Down
3 changes: 3 additions & 0 deletions htdocs/comm/mailing/cibles.php
Expand Up @@ -83,9 +83,12 @@
{
require_once($file);

// We fill $filtersarray. Using this variable is now deprecated.
// Kept for backward compatibility.
$filtersarray=array();
if (isset($_POST["filter"])) $filtersarray[0]=$_POST["filter"];

// Add targets into database
$obj = new $classname($db);
$result=$obj->add_to_target($_GET["rowid"],$filtersarray);
}
Expand Down
Expand Up @@ -196,10 +196,12 @@ function getNbOfRecipients($filter=1,$option='')
*/
function formFilter()
{
global $langs;

$s='';
$s.='<select name="filter" class="flat">';
$s.='<option value="0">&nbsp;</option>';
if (sizeof($this->arrayofproducts)) $s.='<option value="0">&nbsp;</option>';
else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>';
foreach($this->arrayofproducts as $key => $val)
{
$s.='<option value="'.$key.'">'.$val.'</option>';
Expand Down
42 changes: 29 additions & 13 deletions htdocs/includes/modules/mailings/fraise.modules.php
Expand Up @@ -21,16 +21,17 @@
/**
\file htdocs/includes/modules/mailings/fraise.modules.php
\ingroup mailing
\brief Fichier de la classe permettant de g�n�rer la liste de destinataires Fraise
\brief File of class to generate target according to rule Fraise
\version $Id$
*/

include_once DOL_DOCUMENT_ROOT.'/includes/modules/mailings/modules_mailings.php';
include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';


/**
* \class mailing_fraise
* \brief Classe permettant de generer la liste des destinataires Fraise
* \brief Class to generate target according to rule Fraise
*/
class mailing_fraise extends MailingTargets
{
Expand Down Expand Up @@ -97,13 +98,23 @@ function formFilter()
global $langs;
$langs->load("members");

$form=new Form($this->db);

$s='';
$s.=$langs->trans("Status").': ';
$s.='<select name="filter" class="flat">';
$s.='<option value="none">&nbsp;</option>';
$s.='<option value="-1">'.$langs->trans("MemberStatusDraft").'</option>';
$s.='<option value="1a">'.$langs->trans("MemberStatusActiveShort").' ('.$langs->trans("MemberStatusPaidShort").')</option>';
$s.='<option value="1b">'.$langs->trans("MemberStatusActiveShort").' ('.$langs->trans("MemberStatusActiveLateShort").')</option>';
$s.='<option value="0">'.$langs->trans("MemberStatusResiliatedShort").'</option>';
$s.='</select>';
$s.='<br>';
$s.=$langs->trans("DateEndSubscription").': ';
$s.=$langs->trans("After").' > '.$form->select_date(-1,'subscriptionafter',0,0,1,'fraise',1,0,1,0);
$s.=' &nbsp; ';
$s.=$langs->trans("Before").' < '.$form->select_date(-1,'subscriptionbefore',0,0,1,'fraise',1,0,1,0);

return $s;
}

Expand All @@ -120,33 +131,38 @@ function url($id)

/**
* \brief Ajoute destinataires dans table des cibles
* \param mailing_id Id du mailing concern�
* \param filterarray Requete sql de selection des destinataires
* \param mailing_id Id du mailing concerne
* \param filterarray Param to filter sql request. Deprecated. Should use $_POST instead.
* \return int < 0 si erreur, nb ajout si ok
*/
function add_to_target($mailing_id,$filtersarray=array())
{
global $langs;
global $langs,$_POST;
$langs->load("members");

$cibles = array();
$now=dol_now();

$dateendsubscriptionafter=dol_mktime($_POST['subscriptionafterhour'],$_POST['subscriptionaftermin'],$_POST['subscriptionaftersec'],$_POST['subscriptionaftermonth'],$_POST['subscriptionafterday'],$_POST['subscriptionafteryear']);
$dateendsubscriptionbefore=dol_mktime($_POST['subscriptionbeforehour'],$_POST['subscriptionbeforemin'],$_POST['subscriptionbeforesec'],$_POST['subscriptionbeforemonth'],$_POST['subscriptionbeforeday'],$_POST['subscriptionbeforeyear']);

// La requete doit retourner: id, email, fk_contact, name, firstname
$sql = "SELECT a.rowid as id, a.email as email, null as fk_contact, ";
$sql.= " a.nom as name, a.prenom as firstname,";
$sql.= " a.datefin"; // Other fields
$sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
$sql.= " WHERE a.email IS NOT NULL";
foreach($filtersarray as $key)
{
if ($key == '-1') $sql.= " AND a.statut=-1";
if ($key == '1a') $sql.= " AND a.statut=1 AND datefin >= ".$this->db->idate(mktime());
if ($key == '1b') $sql.= " AND a.statut=1 AND datefin < ".$this->db->idate(mktime());
if ($key == '0') $sql.= " AND a.statut=0";
}
if (isset($_POST["filter"]) && $_POST["filter"] == '-1') $sql.= " AND a.statut=-1";
if (isset($_POST["filter"]) && $_POST["filter"] == '1a') $sql.= " AND a.statut=1 AND datefin >= '".$this->db->idate($now)."'";
if (isset($_POST["filter"]) && $_POST["filter"] == '1b') $sql.= " AND a.statut=1 AND datefin < '".$this->db->idate($now)."'";
if (isset($_POST["filter"]) && $_POST["filter"] == '0') $sql.= " AND a.statut=0";
if ($dateendsubscriptionafter > 0) $sql.=" AND datefin > '".$this->db->idate($dateendsubscriptionafter)."'";
if ($dateendsubscriptionbefore > 0) $sql.=" AND datefin < '".$this->db->idate($dateendsubscriptionbefore)."'";
$sql.= " ORDER BY a.email";
//print $sql;

// Stocke destinataires dans cibles
// Add targets into table
dol_syslog("fraise.modules.php sql=".$sql);
$result=$this->db->query($sql);
if ($result)
{
Expand Down
5 changes: 4 additions & 1 deletion htdocs/includes/modules/mailings/framboise.modules.php
Expand Up @@ -162,7 +162,6 @@ function formFilter()

$s='';
$s.='<select name="filter" class="flat">';
$s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>';

# Show categories
$sql = "SELECT rowid, label, type, visible";
Expand All @@ -177,6 +176,10 @@ function formFilter()
if ($resql)
{
$num = $this->db->num_rows($resql);

if ($num) $s.='<option value="0">&nbsp;</option>';
else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>';

$i = 0;
while ($i < $num)
{
Expand Down
5 changes: 4 additions & 1 deletion htdocs/includes/modules/mailings/kiwi.modules.php
Expand Up @@ -162,7 +162,6 @@ function formFilter()

$s='';
$s.='<select name="filter" class="flat">';
$s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>';

# Show categories
$sql = "SELECT rowid, label, type, visible";
Expand All @@ -177,6 +176,10 @@ function formFilter()
if ($resql)
{
$num = $this->db->num_rows($resql);

if ($num) $s.='<option value="0">&nbsp;</option>';
else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>';

$i = 0;
while ($i < $num)
{
Expand Down
11 changes: 5 additions & 6 deletions htdocs/includes/modules/mailings/modules_mailings.php
Expand Up @@ -144,12 +144,11 @@ function add_to_target($mailing_id, $cibles)
$sql .= " nom, prenom, email, other, url)";
$sql .= " VALUES (".$mailing_id.",";
$sql .= (empty($cibles[$i]['fk_contact']) ? '0' : "'".$cibles[$i]['fk_contact']."'") .",";
$sql .= "'".addslashes($cibles[$i]['name'])."',";
$sql .= "'".addslashes($cibles[$i]['firstname'])."',";
$sql .= "'".addslashes($cibles[$i]['email'])."',";
$sql .= "'".addslashes($cibles[$i]['other'])."',";
$sql .= "'".addslashes($cibles[$i]['url'])."')";

$sql .= "'".$this->db->escape($cibles[$i]['name'])."',";
$sql .= "'".$this->db->escape($cibles[$i]['firstname'])."',";
$sql .= "'".$this->db->escape($cibles[$i]['email'])."',";
$sql .= "'".$this->db->escape($cibles[$i]['other'])."',";
$sql .= "'".$this->db->escape($cibles[$i]['url'])."')";
$result=$this->db->query($sql);
if ($result)
{
Expand Down
6 changes: 4 additions & 2 deletions htdocs/includes/modules/mailings/poire.modules.php
Expand Up @@ -109,8 +109,6 @@ function formFilter()

$s='';
$s.='<select name="filter" class="flat">';
$s.='<option value="all">'.$langs->trans("ContactsAllShort").'</option>';
$s.='<option value="prospects">'.$langs->trans("ThirdPartyProspects").'</option>';
# Add prospect of a particular level
$sql = "SELECT code, label";
$sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
Expand All @@ -120,6 +118,10 @@ function formFilter()
if ($resql)
{
$num = $this->db->num_rows($resql);
if ($num) $s.='<option value="all">&nbsp;</option>';
else $s.='<option value="all">'.$langs->trans("ContactsAllShort").'</option>';
$s.='<option value="prospects">'.$langs->trans("ThirdPartyProspects").'</option>';

$i = 0;
while ($i < $num)
{
Expand Down
2 changes: 1 addition & 1 deletion htdocs/lib/databases/pgsql.lib.php
Expand Up @@ -623,7 +623,7 @@ function order($sortfield=0,$sortorder=0)
*/
function escape($stringtoencode)
{
return addslashes($stringtoencode);
return pg_escape_string($stringtoencode);
}


Expand Down

0 comments on commit 11041ce

Please sign in to comment.