fix travis

This commit is contained in:
Florian HENRY 2016-04-01 17:09:03 +02:00
parent ae51321040
commit 038b928ea4
3 changed files with 236 additions and 234 deletions

View File

@ -35,9 +35,9 @@ class AdvanceTargetingMailing extends CommonObject
var $errors = array(); //!< To return several error codes (or messages)
var $element='advtargetemailing'; //!< Id that identify managed objects
var $table_element='advtargetemailing'; //!< Name of table without prefix where object is stored
var $id;
var $name;
var $entity;
var $fk_mailing;
@ -46,12 +46,12 @@ class AdvanceTargetingMailing extends CommonObject
var $datec='';
var $fk_user_mod;
var $tms='';
var $select_target_type = array();
var $type_statuscommprospect=array();
var $thirdparty_lines;
var $contact_lines;
/**
* Constructor
@ -62,10 +62,10 @@ class AdvanceTargetingMailing extends CommonObject
{
global $langs;
$langs->load('customers');
$this->db = $db;
$this->select_target_type = array('2'=>$langs->trans('Contacts'),'1'=>$langs->trans('Contacts').'+'.$langs->trans('ThirdParty'),
$this->select_target_type = array('2'=>$langs->trans('Contacts'),'1'=>$langs->trans('Contacts').'+'.$langs->trans('ThirdParty'),
'3'=>$langs->trans('ThirdParty'),
);
$this->type_statuscommprospect=array(
@ -74,8 +74,8 @@ class AdvanceTargetingMailing extends CommonObject
1=>$langs->trans("StatusProspect1"),
2=>$langs->trans("StatusProspect2"),
3=>$langs->trans("StatusProspect3"));
return 1;
}
@ -90,22 +90,22 @@ class AdvanceTargetingMailing extends CommonObject
{
global $conf, $langs;
$error=0;
// Clean parameters
if (isset($this->fk_mailing)) $this->fk_mailing=trim($this->fk_mailing);
if (isset($this->name)) $this->name=trim($this->name);
if (isset($this->filtervalue)) $this->filtervalue=trim($this->filtervalue);
if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
if (isset($this->fk_user_mod)) $this->fk_user_mod=trim($this->fk_user_mod);
// Check parameters
// Put here code to add control on parameters values
// Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."advtargetemailing(";
$sql.= "name,";
$sql.= "entity,";
$sql.= "fk_mailing,";
@ -113,10 +113,10 @@ class AdvanceTargetingMailing extends CommonObject
$sql.= "fk_user_author,";
$sql.= "datec,";
$sql.= "fk_user_mod";
$sql.= ") VALUES (";
$sql.= " ".(! isset($this->name)?'NULL':"'".$this->db->escape($this->name)."'").",";
$sql.= " ".$conf->entity.",";
$sql.= " ".(! isset($this->fk_mailing)?'NULL':"'".$this->fk_mailing."'").",";
@ -124,25 +124,25 @@ class AdvanceTargetingMailing extends CommonObject
$sql.= " ".$user->id.",";
$sql.= " ".$this->db->idate(dol_now()).",";
$sql.= " ".$user->id;
$sql.= ")";
$this->db->begin();
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
if (! $error)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."advtargetemailing");
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
//// Call triggers
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
//$interface=new Interfaces($this->db);
@ -151,7 +151,7 @@ class AdvanceTargetingMailing extends CommonObject
//// End call triggers
}
}
// Commit or rollback
if ($error)
{
@ -169,7 +169,7 @@ class AdvanceTargetingMailing extends CommonObject
return $this->id;
}
}
/**
* Load object in memory from the database
*
@ -181,7 +181,7 @@ class AdvanceTargetingMailing extends CommonObject
global $langs;
$sql = "SELECT";
$sql.= " t.rowid,";
$sql.= " t.name,";
$sql.= " t.entity,";
$sql.= " t.fk_mailing,";
@ -193,7 +193,7 @@ class AdvanceTargetingMailing extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."advtargetemailing as t";
$sql.= " WHERE t.rowid = ".$id;
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
@ -201,9 +201,9 @@ class AdvanceTargetingMailing extends CommonObject
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->name = $obj->name;
$this->entity = $obj->entity;
$this->fk_mailing = $obj->fk_mailing;
@ -212,10 +212,10 @@ class AdvanceTargetingMailing extends CommonObject
$this->datec = $this->db->jdate($obj->datec);
$this->fk_user_mod = $obj->fk_user_mod;
$this->tms = $this->db->jdate($obj->tms);
}
$this->db->free($resql);
return 1;
}
else
@ -225,7 +225,7 @@ class AdvanceTargetingMailing extends CommonObject
return -1;
}
}
/**
* Load object in memory from the database
*
@ -237,7 +237,7 @@ class AdvanceTargetingMailing extends CommonObject
global $langs;
$sql = "SELECT";
$sql.= " t.rowid,";
$sql.= " t.name,";
$sql.= " t.entity,";
$sql.= " t.fk_mailing,";
@ -246,14 +246,14 @@ class AdvanceTargetingMailing extends CommonObject
$sql.= " t.datec,";
$sql.= " t.fk_user_mod,";
$sql.= " t.tms";
$sql.= " FROM ".MAIN_DB_PREFIX."advtargetemailing as t";
if (!empty($id)) {
$sql.= " WHERE t.fk_mailing = ".$id;
}else {
$sql.= " WHERE t.fk_mailing = ".$this->fk_mailing;
}
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
@ -261,9 +261,9 @@ class AdvanceTargetingMailing extends CommonObject
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->name = $obj->name;
$this->entity = $obj->entity;
$this->fk_mailing = $obj->fk_mailing;
@ -272,10 +272,10 @@ class AdvanceTargetingMailing extends CommonObject
$this->datec = $this->db->jdate($obj->datec);
$this->fk_user_mod = $obj->fk_user_mod;
$this->tms = $this->db->jdate($obj->tms);
}
$this->db->free($resql);
return 1;
}
else
@ -285,7 +285,7 @@ class AdvanceTargetingMailing extends CommonObject
return -1;
}
}
/**
* Update object into database
*
@ -297,43 +297,43 @@ class AdvanceTargetingMailing extends CommonObject
{
global $conf, $langs;
$error=0;
// Clean parameters
if (isset($this->fk_mailing)) $this->fk_mailing=trim($this->fk_mailing);
if (isset($this->name)) $this->name=trim($this->name);
if (isset($this->filtervalue)) $this->filtervalue=trim($this->filtervalue);
if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
if (isset($this->fk_user_mod)) $this->fk_user_mod=trim($this->fk_user_mod);
// Check parameters
// Put here code to add a control on parameters values
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."advtargetemailing SET";
$sql.= " name=".(isset($this->name)?"'".$this->db->escape($this->name)."'":"''").",";
$sql.= " entity=".$conf->entity.",";
$sql.= " fk_mailing=".(isset($this->fk_mailing)?$this->fk_mailing:"null").",";
$sql.= " filtervalue=".(isset($this->filtervalue)?"'".$this->db->escape($this->filtervalue)."'":"null").",";
$sql.= " fk_user_mod=".$user->id;
$sql.= " WHERE rowid=".$this->id;
$this->db->begin();
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
if (! $error)
{
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
//// Call triggers
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
//$interface=new Interfaces($this->db);
@ -342,7 +342,7 @@ class AdvanceTargetingMailing extends CommonObject
//// End call triggers
}
}
// Commit or rollback
if ($error)
{
@ -360,7 +360,7 @@ class AdvanceTargetingMailing extends CommonObject
return 1;
}
}
/**
* Delete object in database
*
@ -372,16 +372,16 @@ class AdvanceTargetingMailing extends CommonObject
{
global $conf, $langs;
$error=0;
$this->db->begin();
if (! $error)
{
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
//// Call triggers
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
//$interface=new Interfaces($this->db);
@ -390,17 +390,17 @@ class AdvanceTargetingMailing extends CommonObject
//// End call triggers
}
}
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."advtargetemailing";
$sql.= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::delete sql=".$sql);
$resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
}
// Commit or rollback
if ($error)
{
@ -418,11 +418,11 @@ class AdvanceTargetingMailing extends CommonObject
return 1;
}
}
/**
* Save query in database to retreive it
*
*
* @param User $user User that deletes
* @param array $arrayquery All element to Query
* @return int <0 if KO, >0 if OK
@ -437,15 +437,15 @@ class AdvanceTargetingMailing extends CommonObject
if ($result<0) {
return -1;
}
if (!empty($this->id)) {
if (!empty($this->id)) {
$this->update($user);
}else {
$this->create($user);
}
}
}
/**
* Load object in memory from database
@ -461,22 +461,22 @@ class AdvanceTargetingMailing extends CommonObject
$sql.= " t.rowid";
$sql.= " FROM " . MAIN_DB_PREFIX . "societe as t";
$sql.= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "societe_extrafields as te ON te.fk_object=t.rowid ";
$sqlwhere=array();
$sqlwhere[]= 't.entity IN ('.getEntity('societe',1).')';
if (count($arrayquery)>0) {
if (array_key_exists('cust_saleman', $arrayquery)) {
$sql.= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as saleman ON saleman.fk_soc=t.rowid ";
}
if (array_key_exists('cust_categ', $arrayquery)) {
$sql.= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "categorie_societe as custcateg ON custcateg.fk_societe=t.rowid ";
}
if (!empty($arrayquery['cust_name'])) {
$sqlwhere[]= $this->transformToSQL('t.nom',$arrayquery['cust_name']);
}
if (!empty($arrayquery['cust_code'])) {
@ -525,14 +525,14 @@ class AdvanceTargetingMailing extends CommonObject
if (!empty($arrayquery['cust_language']) && count($arrayquery['cust_language'])>0) {
$sqlwhere[]= " (t.default_lang IN ('".implode("','",$arrayquery['cust_language'])."'))";
}
//Standard Extrafield feature
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
// fetch optionals attributes and labels
dol_include_once('/core/class/extrafields.class.php');
$extrafields = new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label('societe');
foreach($extralabels as $key=>$val) {
if (($extrafields->attribute_type[$key] == 'varchar') ||
@ -584,7 +584,7 @@ class AdvanceTargetingMailing extends CommonObject
while( $i < $num)
{
$obj = $this->db->fetch_object($resql);
$this->thirdparty_lines[$i] = $obj->rowid;
$i++;
@ -599,7 +599,7 @@ class AdvanceTargetingMailing extends CommonObject
return -1;
}
}
/**
* Load object in memory from database
*
@ -609,22 +609,22 @@ class AdvanceTargetingMailing extends CommonObject
function query_contact($arrayquery)
{
global $langs,$conf;
$sql = "SELECT";
$sql.= " t.rowid";
$sql.= " FROM " . MAIN_DB_PREFIX . "socpeople as t";
$sql.= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "socpeople_extrafields as te ON te.fk_object=t.rowid ";
$sqlwhere=array();
$sqlwhere[]= 't.entity IN ('.getEntity('socpeople',1).')';
if (count($arrayquery)>0) {
if (array_key_exists('contact_categ', $arrayquery)) {
$sql.= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "categorie_contact as contactcateg ON contactcateg.fk_socpeople=t.rowid ";
}
if (!empty($arrayquery['contact_lastname'])) {
$sqlwhere[]=$this->transformToSQL('t.lastname',$arrayquery['contact_lastname']);
}
@ -652,16 +652,16 @@ class AdvanceTargetingMailing extends CommonObject
if (!empty($arrayquery['contact_categ']) && count($arrayquery['contact_categ'])>0) {
$sqlwhere[]= " (contactcateg.fk_categorie IN (".implode(",",$arrayquery['contact_categ'])."))";
}
//Standard Extrafield feature
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
// fetch optionals attributes and labels
dol_include_once('/core/class/extrafields.class.php');
$extrafields = new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label('socpeople');
foreach($extralabels as $key=>$val) {
if (($extrafields->attribute_type[$key] == 'varchar') ||
($extrafields->attribute_type[$key] == 'text')) {
if (!empty($arrayquery['options_'.$key.'_cnct'])) {
@ -692,37 +692,37 @@ class AdvanceTargetingMailing extends CommonObject
$sqlwhere[]= " (te.".$key." LIKE '".$arrayquery['options_'.$key.'_cnct']."')";
}
}
}
}
if (count($sqlwhere)>0) $sql.= " WHERE ".implode(" AND ",$sqlwhere);
}
dol_syslog(get_class($this) . "::query_contact sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$this->contact_lines = array();
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
{
while( $i < $num)
{
$obj = $this->db->fetch_object($resql);
$this->contact_lines[$i] = $obj->rowid;
$i++;
}
}
$this->db->free($resql);
return $num;
} else {
$this->error = "Error " . $this->db->lasterror();
@ -730,25 +730,25 @@ class AdvanceTargetingMailing extends CommonObject
return -1;
}
}
/**
* Parse criteria to return a SQL qury formated
*
* @param string $column_to_test column to test
* @param string $criteria Use %% as magic caracters. For exemple to find all item like <b>jean, joe, jim</b>, you can input <b>j%%</b>, you can also use ; as separator for value,
* and use ! for except this value.
* and use ! for except this value.
* For exemple jean;joe;jim%%;!jimo;!jima%> will target all jean, joe, start with jim but not jimo and not everythnig taht start by jima
* @return int <0 if KO, >0 if OK
*/
public function transformToSQL($column_to_test,$criteria) {
$return_sql_criteria = '(';
//This is a multiple value test
if (preg_match('/;/',$criteria)) {
$return_sql_not_like=array();
$return_sql_like=array();
$criteria_array=explode(';',$criteria);
foreach($criteria_array as $inter_criteria) {
if (preg_match('/!/',$inter_criteria)) {
@ -757,24 +757,22 @@ class AdvanceTargetingMailing extends CommonObject
$return_sql_like[]= '('.$column_to_test.' LIKE \''.$inter_criteria.'\')';
}
}
if (count($return_sql_like)>0) {
$return_sql_criteria .= '(' . implode (' OR ', $return_sql_like) .')';
}
if (count($return_sql_not_like)>0) {
$return_sql_criteria .= ' AND (' . implode (' AND ', $return_sql_not_like).')';
}
}else {
$return_sql_criteria .= $column_to_test . ' LIKE \''.$this->db->escape($criteria).'\'';
}
$return_sql_criteria .= ')';
return $return_sql_criteria;
}
}
?>
}

View File

@ -27,7 +27,7 @@
class FormAdvTargetEmailing extends Form {
var $db;
var $error;
/**
* Constructor
*
@ -35,24 +35,23 @@ class FormAdvTargetEmailing extends Form {
*/
function __construct($db) {
global $langs;
$this->db = $db;
return 1;
}
/**
* Affiche un champs select contenant une liste
*
* @param int $selected_array à preselectionner
* @param array $selected_array à preselectionner
* @param string $htmlname select field
* @param int $showempty empty field
* @return string select field
*/
function multiselect_prospection_status($selected_array, $htmlname = 'cust_prospect_status') {
function multiselect_prospection_status($selected_array = array(), $htmlname = 'cust_prospect_status') {
global $conf, $langs;
$options_array = array ();
$sql = "SELECT code, label";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_prospectlevel";
$sql .= " WHERE active > 0";
@ -64,12 +63,12 @@ class FormAdvTargetEmailing extends Form {
$i = 0;
while ( $i < $num ) {
$obj = $this->db->fetch_object ( $resql );
$level = $langs->trans ( $obj->code );
if ($level == $obj->code)
$level = $langs->trans ( $obj->label );
$options_array [$obj->code] = $level;
$i ++;
}
} else {
@ -77,39 +76,39 @@ class FormAdvTargetEmailing extends Form {
}
return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
}
/**
* Return combo list of activated countries, into language of user
*
* @param string $htmlname of html select object
* @param string $selected or Code or Label of preselected country
* @param array $selected or Code or Label of preselected country
* @return string HTML string with select
*/
function multiselect_country($htmlname = 'country_id', $selected_array=array()) {
global $conf, $langs;
$langs->load ( "dict" );
$out = '';
$countryArray = array ();
$label = array ();
$options_array = array ();
$sql = "SELECT rowid, code as code_iso, label";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_country";
$sql .= " WHERE active = 1 AND code<>''";
$sql .= " ORDER BY code ASC";
dol_syslog ( get_class ( $this ) . "::select_country sql=" . $sql );
$resql = $this->db->query ( $sql );
if ($resql) {
$num = $this->db->num_rows ( $resql );
$i = 0;
if ($num) {
$foundselected = false;
while ( $i < $num ) {
$obj = $this->db->fetch_object ( $resql );
$countryArray [$i] ['rowid'] = $obj->rowid;
@ -118,39 +117,39 @@ class FormAdvTargetEmailing extends Form {
$label [$i] = $countryArray [$i] ['label'];
$i ++;
}
array_multisort ( $label, SORT_ASC, $countryArray );
foreach ( $countryArray as $row ) {
$label = dol_trunc ( $row ['label'], $maxlength, 'middle' );
if ($row ['code_iso'])
$label .= ' (' . $row ['code_iso'] . ')';
$options_array [$row ['rowid']] = $label;
}
}
} else {
dol_print_error ( $this->db );
}
return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
}
/**
* Return select list for categories (to use in form search selectors)
*
* @param string $selected value
* @param string $htmlname of combo list (example: 'search_sale')
* @param User $user user
* @param unknown $htmlname
* @param array $selected_array
* @param unknown $user
* @return string combo list code
*/
function multiselectselect_salesrepresentatives($htmlname, $selected_array, $user) {
function multiselectselect_salesrepresentatives($htmlname, $selected_array=array(), $user) {
global $conf;
$options_array = array ();
$sql_usr .= "SELECT DISTINCT u2.rowid, u2.lastname as name, u2.firstname, u2.login";
$sql_usr .= " FROM " . MAIN_DB_PREFIX . "user as u2, " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
$sql_usr .= " WHERE u2.entity IN (0," . $conf->entity . ")";
@ -160,40 +159,39 @@ class FormAdvTargetEmailing extends Form {
$sql_usr .= " AND u2.statut<>0 ";
$sql_usr .= " ORDER BY name ASC";
// print $sql_usr;exit;
$resql_usr = $this->db->query ( $sql_usr );
if ($resql_usr) {
while ( $obj_usr = $this->db->fetch_object ( $resql_usr ) ) {
$label = $obj_usr->firstname . " " . $obj_usr->name . " (" . $obj_usr->login . ')';
$options_array [$obj_usr->rowid] = $label;
}
$this->db->free ( $resql_usr );
} else {
dol_print_error ( $this->db );
}
return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
}
/**
* Return select list for categories (to use in form search selectors)
*
* @param string $selected value
* @param string $htmlname of combo list (example: 'search_sale')
* @param User $user user
* @param array $selected_array
* @return string combo list code
*/
function multiselectselect_language($htmlname, $selected_array) {
function multiselectselect_language($htmlname='', $selected_array=array()) {
global $conf,$langs;
$options_array = array ();
$langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT,12);
foreach ($langs_available as $key => $value)
{
$label = $value;
@ -202,30 +200,31 @@ class FormAdvTargetEmailing extends Form {
asort($options_array);
return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
}
/**
* Return multiselect list of entities for extrafeild type sellist
* Return multiselect list of entities for extrafeild type sellist
*
* @param string $htmlname select
* @param array $options_array to manage
* @param array $selected_array to manage
* @return string combo list code
* @param unknown $htmlname
* @param array $sqlqueryparam
* @param array $selected_array
*
* @return string HTML combo
*/
function advMultiselectarray_selllist($htmlname, $sqlqueryparam = array(), $selected_array = array()) {
if (is_array ( $sqlqueryparam )) {
$options_array=array();
$param_list = array_keys ( $sqlqueryparam );
$InfoFieldList = explode ( ":", $param_list [0] );
// 0 1 : tableName
// 1 2 : label field name Nom du champ contenant le libelle
// 2 3 : key fields name (if differ of rowid)
// 3 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
$keyList = 'rowid';
if (count ( $InfoFieldList ) >= 3) {
if (strpos ( $InfoFieldList [3], 'extra.' ) !== false) {
$keyList = 'main.' . $InfoFieldList [2] . ' as rowid';
@ -233,11 +232,11 @@ class FormAdvTargetEmailing extends Form {
$keyList = $InfoFieldList [2] . ' as rowid';
}
}
$sql = 'SELECT ' . $keyList . ', ' . $InfoFieldList [1];
$sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList [0];
if (! empty ( $InfoFieldList [3] )) {
// We have to join on extrafield table
if (strpos ( $InfoFieldList [3], 'extra' ) !== false) {
$sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList [0] . '_extrafields as extra';
@ -250,17 +249,17 @@ class FormAdvTargetEmailing extends Form {
$sql .= " ORDER BY nom";
}
// $sql.= ' WHERE entity = '.$conf->entity;
dol_syslog ( get_class ( $this ) . '::advMultiselectarray_selllist sql=' . $sql );
$resql = $this->db->query ( $sql );
if ($resql) {
$num = $this->db->num_rows ( $resql );
$i = 0;
if ($num) {
while ( $i < $num ) {
$obj = $this->db->fetch_object ( $resql );
$labeltoshow = dol_trunc ( $obj->$InfoFieldList [1], 90 );
$labeltoshow = dol_trunc ( $obj->$InfoFieldList [1], 90 );
$options_array[$obj->rowid]=$labeltoshow;
$i ++;
}
@ -268,33 +267,33 @@ class FormAdvTargetEmailing extends Form {
$this->db->free ( $resql );
}
}
return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
}
/**
* Return combo list with people title
*
* @param string $selected Title preselected
* @param string $htmlname Name of HTML select combo field
* @return void
* @return string HTML combo
*/
function multiselect_civility($htmlname='civilite_id',$selected_array = array())
{
global $conf,$langs,$user;
$langs->load("dict");
$options_array=array();
$sql = "SELECT rowid, code, label as civilite, active FROM ".MAIN_DB_PREFIX."c_civility";
$sql.= " WHERE active = 1";
dol_syslog("Form::select_civility sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
@ -304,23 +303,23 @@ class FormAdvTargetEmailing extends Form {
$obj = $this->db->fetch_object($resql);
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
$label= ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->civilite!='-'?$obj->civilite:''));
$options_array[$obj->code]=$label;
$i++;
}
}
}
else
{
dol_print_error($this->db);
}
return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
}
/**
* Return multiselect list of entities.
*
@ -328,11 +327,11 @@ class FormAdvTargetEmailing extends Form {
* @param array $options_array to manage
* @param array $selected_array to manage
* @param int $showempty show empty
* @return void
* @return string HTML combo
*/
function advMultiselectarray($htmlname, $options_array = array(), $selected_array = array(), $showempty = 0) {
global $conf, $langs;
$return = '<script type="text/javascript" language="javascript">
$(document).ready(function() {
$.extend($.ui.multiselect.locale, {
@ -340,25 +339,25 @@ class FormAdvTargetEmailing extends Form {
removeAll:\'' . $langs->transnoentities ( "RemoveAll" ) . '\',
itemsCount:\'' . $langs->transnoentities ( "ItemsCount" ) . '\'
});
$(function(){
$("#' . $htmlname . '").addClass("' . $htmlname . '").attr("multiple","multiple").attr("name","' . $htmlname . '[]");
$(".multiselect").multiselect({sortable: false, searchable: false});
});
});
</script>';
$return .= '<select id="' . $htmlname . '" class="multiselect" multiple="multiple" name="' . $htmlname . '[]" style="display: none;">';
if ($showempty)
$return .= '<option value="">&nbsp;</option>';
// Find if keys is in selected array value
if (is_array($selected_array) && count($selected_array)>0) {
$intersect_array = array_intersect_key ( $options_array, array_flip ( $selected_array ) );
} else {
$intersect_array=array();
}
if (count ( $options_array ) > 0) {
foreach ( $options_array as $keyoption => $valoption ) {
// If key is in intersect table then it have to e selected
@ -369,63 +368,62 @@ class FormAdvTargetEmailing extends Form {
$selected = '';
}
}
$return .= '<option ' . $selected . ' value="' . $keyoption . '">' . $valoption . '</option>';
}
}
$return .= '</select>';
return $return;
}
/**
* Return combo list with customer categories
*
* @param string $htmlname Name of categorie
* @param array $selected_array value selected
* @return void
* @return string HTML combo
*/
function multiselect_customercategories($htmlname='cust_cat',$selected_array = array())
{
return $this->multiselect_categories($htmlname,$selected_array,2);
}
/**
* Return combo list with customer contact
*
* @param string $htmlname Name of categorie
* @param array $selected_array value selected
* @return void
* @return string HTML combo
*/
function multiselect_contactcategories($htmlname='contact_cat',$selected_array = array())
{
return $this->multiselect_categories($htmlname,$selected_array,4);
}
/**
* Return combo list of categories
*
* @param string $htmlname Name of categorie
* @param array $selected_array value selected
* @return void
* @return string HTML combo
*/
public function multiselect_categories($htmlname='',$selected_array = array(), $type=0)
{
global $conf,$langs,$user;
$langs->load("dict");
$options_array=array();
$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE type=".$type;
dol_syslog(get_class($this)."::multiselectselect_customercategories sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
@ -433,37 +431,44 @@ class FormAdvTargetEmailing extends Form {
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$options_array[$obj->rowid]=$obj->label;
$i++;
}
}
}
else
{
dol_print_error($this->db);
}
return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
}
/**
*
* @param string $htmlname
* @param number $selected
* @param number $showempty
*
* @return string HTML combo
*/
public function select_advtargetemailing_template($htmlname='template_id',$selected=0,$showempty=0) {
global $conf, $user, $langs;
$out = '';
$sql = "SELECT c.rowid, c.name, c.fk_mailing";
$sql .= " FROM " . MAIN_DB_PREFIX . "advtargetemailing as c";
$sql .= " ORDER BY c.name";
dol_syslog ( get_class ( $this ) . "::select_advtargetemailing_template sql=" . $sql, LOG_DEBUG );
$resql = $this->db->query ( $sql );
if ($resql) {
$out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">';
if ($showempty)
$out .= '<option value=""></option>';
@ -476,7 +481,7 @@ class FormAdvTargetEmailing extends Form {
if (empty($label)) {
$label=$obj->fk_mailing;
}
if ($selected > 0 && $selected == $obj->rowid) {
$out .= '<option value="' . $obj->rowid . '" selected="selected">' . $label . '</option>';
} else {

View File

@ -61,7 +61,7 @@ class mailing_advthirdparties extends MailingTargets
global $conf, $langs;
dol_syslog(get_class($this)."::add_to_target socid=".var_export($socid,true).' contactid='.var_export($contactid,true));
$cibles = array();
if (($type_of_target==1) || ($type_of_target==3)) {
@ -74,8 +74,8 @@ class mailing_advthirdparties extends MailingTargets
$sql.= " AND s.rowid IN (".implode(',',$socid).")";
$sql.= " ORDER BY email";
}
dol_syslog(get_class($this)."::add_to_target societe sql=".$sql, LOG_DEBUG);
// Stock recipients emails into targets table
$result=$this->db->query($sql);
@ -83,14 +83,14 @@ class mailing_advthirdparties extends MailingTargets
{
$num = $this->db->num_rows($result);
$i = 0;
dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found", LOG_DEBUG);
$old = '';
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
if (!array_key_exists($obj->email, $cibles)) {
$cibles[$obj->email] = array(
@ -105,7 +105,7 @@ class mailing_advthirdparties extends MailingTargets
);
}
}
$i++;
}
}
@ -116,7 +116,7 @@ class mailing_advthirdparties extends MailingTargets
return -1;
}
}
if (($type_of_target==1) || ($type_of_target==2)) {
// Select the third parties from category
if (count($socid)>0 || count($contactid)>0)
@ -126,14 +126,14 @@ class mailing_advthirdparties extends MailingTargets
$sql.= " WHERE socp.entity IN (".getEntity('societe', 1).")";
if (count($contactid)>0) {
$sql.= " AND socp.rowid IN (".implode(',',$contactid).")";
}
}
if (count($socid)>0) {
$sql.= " AND socp.fk_soc IN (".implode(',',$socid).")";
}
$sql.= " ORDER BY email";
}
dol_syslog(get_class($this)."::add_to_target contact sql=".$sql);
// Stock recipients emails into targets table
$result=$this->db->query($sql);
@ -141,14 +141,14 @@ class mailing_advthirdparties extends MailingTargets
{
$num = $this->db->num_rows($result);
$i = 0;
dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
$old = '';
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
if (!array_key_exists($obj->email, $cibles)) {
$cibles[$obj->email] = array(
@ -163,7 +163,7 @@ class mailing_advthirdparties extends MailingTargets
);
}
}
$i++;
}
}
@ -175,7 +175,7 @@ class mailing_advthirdparties extends MailingTargets
}
}
dol_syslog(get_class($this)."::add_to_target mailing cibles=".var_export($cibles,true), LOG_DEBUG);
return parent::add_to_target($mailing_id, $cibles);
}
@ -283,6 +283,7 @@ class mailing_advthirdparties extends MailingTargets
* Can include an URL link on each record provided by selector shown on target page.
*
* @param int $id ID
* @param string $type type
* @return string Url link
*/
function url($id,$type)
@ -299,5 +300,3 @@ class mailing_advthirdparties extends MailingTargets
}
}
?>