@@ -30,21 +30,21 @@ discard block |
||
30 | 30 | class modBlockedLog extends DolibarrModules |
31 | 31 | { |
32 | 32 | /** |
33 | - * Constructor. Define names, constants, directories, boxes, permissions |
|
34 | - * |
|
35 | - * @param DoliDB $db Database handler |
|
33 | + * Constructor. Define names, constants, directories, boxes, permissions |
|
34 | + * |
|
35 | + * @param DoliDB $db Database handler |
|
36 | 36 | */ |
37 | 37 | function __construct($db) |
38 | 38 | { |
39 | - global $langs, $conf, $mysoc; |
|
39 | + global $langs, $conf, $mysoc; |
|
40 | 40 | |
41 | 41 | $this->db = $db; |
42 | 42 | $this->numero = 3200; |
43 | 43 | // Key text used to identify module (for permissions, menus, etc...) |
44 | 44 | $this->rights_class = 'blockedlog'; |
45 | 45 | |
46 | - // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' |
|
47 | - // It is used to group modules in module setup page |
|
46 | + // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' |
|
47 | + // It is used to group modules in module setup page |
|
48 | 48 | $this->family = "base"; |
49 | 49 | // Module position in the family on 2 digits ('01', '10', '20', ...) |
50 | 50 | $this->module_position = '75'; |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | |
68 | 68 | // Dependancies |
69 | 69 | //------------- |
70 | - $this->hidden = false; // A condition to disable module |
|
71 | - $this->depends = array('always'=>'modFacture'); // List of modules id that must be enabled if this module is enabled |
|
70 | + $this->hidden = false; // A condition to disable module |
|
71 | + $this->depends = array('always'=>'modFacture'); // List of modules id that must be enabled if this module is enabled |
|
72 | 72 | $this->requiredby = array(); // List of modules id to disable if this one is disabled |
73 | - $this->conflictwith = array(); // List of modules id this module is in conflict with |
|
73 | + $this->conflictwith = array(); // List of modules id this module is in conflict with |
|
74 | 74 | $this->langfiles = array('blockedlog'); |
75 | 75 | |
76 | 76 | $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
@@ -91,14 +91,14 @@ discard block |
||
91 | 91 | //var_dump($this->automatic_activation); |
92 | 92 | |
93 | 93 | $this->always_enabled = (!empty($conf->blockedlog->enabled) |
94 | - && !empty($conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY) |
|
95 | - && in_array($mysoc->country_code, explode(',', $conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY)) |
|
96 | - && $this->alreadyUsed(1)); |
|
94 | + && !empty($conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY) |
|
95 | + && in_array($mysoc->country_code, explode(',', $conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY)) |
|
96 | + && $this->alreadyUsed(1)); |
|
97 | 97 | |
98 | 98 | // Constants |
99 | 99 | //----------- |
100 | 100 | $this->const = array( |
101 | - 1=>array('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY', 'chaine', 'FR', 'This is list of country code where the module may be mandatory', 0, 'current', 0) |
|
101 | + 1=>array('BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY', 'chaine', 'FR', 'This is list of country code where the module may be mandatory', 0, 'current', 0) |
|
102 | 102 | ); |
103 | 103 | |
104 | 104 | // New pages on tabs |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | function alreadyUsed() |
149 | 149 | { |
150 | 150 | |
151 | - require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; |
|
152 | - $b=new BlockedLog($this->db); |
|
153 | - return $b->alreadyUsed(1); |
|
151 | + require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; |
|
152 | + $b=new BlockedLog($this->db); |
|
153 | + return $b->alreadyUsed(1); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | |
@@ -164,87 +164,87 @@ discard block |
||
164 | 164 | */ |
165 | 165 | function init($options='') |
166 | 166 | { |
167 | - global $conf, $user; |
|
168 | - |
|
169 | - $sql = array(); |
|
170 | - |
|
171 | - // If already used, we add an entry to show we enable module |
|
172 | - require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; |
|
173 | - |
|
174 | - $object=new stdClass(); |
|
175 | - $object->id = 1; |
|
176 | - $object->element = 'module'; |
|
177 | - $object->ref = 'systemevent'; |
|
178 | - $object->entity = $conf->entity; |
|
179 | - $object->date = dol_now(); |
|
180 | - |
|
181 | - $b=new BlockedLog($this->db); |
|
182 | - $result = $b->setObjectData($object, 'MODULE_SET', 0); |
|
183 | - if ($result < 0) |
|
184 | - { |
|
185 | - $this->error = $b->error; |
|
186 | - $this->errors = $b->erros; |
|
187 | - return 0; |
|
188 | - } |
|
189 | - |
|
190 | - $res = $b->create($user); |
|
191 | - if ($res<=0) { |
|
192 | - $this->error = $b->error; |
|
193 | - $this->errors = $b->errors; |
|
194 | - return $res; |
|
195 | - } |
|
196 | - |
|
197 | - return $this->_init($sql, $options); |
|
167 | + global $conf, $user; |
|
168 | + |
|
169 | + $sql = array(); |
|
170 | + |
|
171 | + // If already used, we add an entry to show we enable module |
|
172 | + require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; |
|
173 | + |
|
174 | + $object=new stdClass(); |
|
175 | + $object->id = 1; |
|
176 | + $object->element = 'module'; |
|
177 | + $object->ref = 'systemevent'; |
|
178 | + $object->entity = $conf->entity; |
|
179 | + $object->date = dol_now(); |
|
180 | + |
|
181 | + $b=new BlockedLog($this->db); |
|
182 | + $result = $b->setObjectData($object, 'MODULE_SET', 0); |
|
183 | + if ($result < 0) |
|
184 | + { |
|
185 | + $this->error = $b->error; |
|
186 | + $this->errors = $b->erros; |
|
187 | + return 0; |
|
188 | + } |
|
189 | + |
|
190 | + $res = $b->create($user); |
|
191 | + if ($res<=0) { |
|
192 | + $this->error = $b->error; |
|
193 | + $this->errors = $b->errors; |
|
194 | + return $res; |
|
195 | + } |
|
196 | + |
|
197 | + return $this->_init($sql, $options); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
201 | - * Function called when module is disabled. |
|
202 | - * The remove function removes tabs, constants, boxes, permissions and menus from Dolibarr database. |
|
203 | - * Data directories are not deleted |
|
204 | - * |
|
205 | - * @param string $options Options when enabling module ('', 'noboxes') |
|
206 | - * @return int 1 if OK, 0 if KO |
|
207 | - */ |
|
201 | + * Function called when module is disabled. |
|
202 | + * The remove function removes tabs, constants, boxes, permissions and menus from Dolibarr database. |
|
203 | + * Data directories are not deleted |
|
204 | + * |
|
205 | + * @param string $options Options when enabling module ('', 'noboxes') |
|
206 | + * @return int 1 if OK, 0 if KO |
|
207 | + */ |
|
208 | 208 | function remove($options = '') |
209 | 209 | { |
210 | 210 | |
211 | - global $conf, $user; |
|
212 | - |
|
213 | - $sql = array(); |
|
214 | - |
|
215 | - // If already used, we add an entry to show we enable module |
|
216 | - require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; |
|
217 | - |
|
218 | - $object=new stdClass(); |
|
219 | - $object->id = 1; |
|
220 | - $object->element = 'module'; |
|
221 | - $object->ref = 'systemevent'; |
|
222 | - $object->entity = $conf->entity; |
|
223 | - $object->date = dol_now(); |
|
224 | - |
|
225 | - $b=new BlockedLog($this->db); |
|
226 | - $result = $b->setObjectData($object, 'MODULE_RESET', 0); |
|
227 | - if ($result < 0) |
|
228 | - { |
|
229 | - $this->error = $b->error; |
|
230 | - $this->errors = $b->erros; |
|
231 | - return 0; |
|
232 | - } |
|
233 | - |
|
234 | - if ($b->alreadyUsed(1)) |
|
235 | - { |
|
236 | - $res = $b->create($user, '0000000000'); // If already used for something else than SET or UNSET, we log with error |
|
237 | - } |
|
238 | - else |
|
239 | - { |
|
240 | - $res = $b->create($user); |
|
241 | - } |
|
242 | - if ($res<=0) { |
|
243 | - $this->error = $b->error; |
|
244 | - $this->errors = $b->errors; |
|
245 | - return $res; |
|
246 | - } |
|
247 | - |
|
248 | - return $this->_remove($sql, $options); |
|
211 | + global $conf, $user; |
|
212 | + |
|
213 | + $sql = array(); |
|
214 | + |
|
215 | + // If already used, we add an entry to show we enable module |
|
216 | + require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; |
|
217 | + |
|
218 | + $object=new stdClass(); |
|
219 | + $object->id = 1; |
|
220 | + $object->element = 'module'; |
|
221 | + $object->ref = 'systemevent'; |
|
222 | + $object->entity = $conf->entity; |
|
223 | + $object->date = dol_now(); |
|
224 | + |
|
225 | + $b=new BlockedLog($this->db); |
|
226 | + $result = $b->setObjectData($object, 'MODULE_RESET', 0); |
|
227 | + if ($result < 0) |
|
228 | + { |
|
229 | + $this->error = $b->error; |
|
230 | + $this->errors = $b->erros; |
|
231 | + return 0; |
|
232 | + } |
|
233 | + |
|
234 | + if ($b->alreadyUsed(1)) |
|
235 | + { |
|
236 | + $res = $b->create($user, '0000000000'); // If already used for something else than SET or UNSET, we log with error |
|
237 | + } |
|
238 | + else |
|
239 | + { |
|
240 | + $res = $b->create($user); |
|
241 | + } |
|
242 | + if ($res<=0) { |
|
243 | + $this->error = $b->error; |
|
244 | + $this->errors = $b->errors; |
|
245 | + return $res; |
|
246 | + } |
|
247 | + |
|
248 | + return $this->_remove($sql, $options); |
|
249 | 249 | } |
250 | 250 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * \ingroup blockedlog |
23 | 23 | * \brief Description and activation file for module BlockedLog |
24 | 24 | */ |
25 | -include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; |
|
25 | +include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php'; |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Class to describe a BlockedLog module |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | // Module position in the family on 2 digits ('01', '10', '20', ...) |
50 | 50 | $this->module_position = '75'; |
51 | 51 | // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
52 | - $this->name = preg_replace('/^mod/i','',get_class($this)); |
|
52 | + $this->name = preg_replace('/^mod/i', '', get_class($this)); |
|
53 | 53 | $this->description = "Enable a log on some business events into a non reversible log. This module may be mandatory for some countries."; |
54 | 54 | // Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
55 | 55 | $this->version = 'dolibarr'; |
56 | 56 | // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) |
57 | 57 | $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
58 | 58 | // Name of image file used for this module. |
59 | - $this->picto='technic'; |
|
59 | + $this->picto = 'technic'; |
|
60 | 60 | |
61 | 61 | // Data directories to create when module is enabled |
62 | 62 | $this->dirs = array(); |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | |
68 | 68 | // Dependancies |
69 | 69 | //------------- |
70 | - $this->hidden = false; // A condition to disable module |
|
71 | - $this->depends = array('always'=>'modFacture'); // List of modules id that must be enabled if this module is enabled |
|
72 | - $this->requiredby = array(); // List of modules id to disable if this one is disabled |
|
73 | - $this->conflictwith = array(); // List of modules id this module is in conflict with |
|
70 | + $this->hidden = false; // A condition to disable module |
|
71 | + $this->depends = array('always'=>'modFacture'); // List of modules id that must be enabled if this module is enabled |
|
72 | + $this->requiredby = array(); // List of modules id to disable if this one is disabled |
|
73 | + $this->conflictwith = array(); // List of modules id this module is in conflict with |
|
74 | 74 | $this->langfiles = array('blockedlog'); |
75 | 75 | |
76 | - $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
77 | - $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
76 | + $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
77 | + $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
78 | 78 | $this->warnings_unactivation = array('FR'=>'BlockedLogAreRequiredByYourCountryLegislation'); |
79 | 79 | |
80 | 80 | // Currently, activation is not automatic because only companies (in France) making invoices to non business customers must |
@@ -111,31 +111,31 @@ discard block |
||
111 | 111 | |
112 | 112 | // Permissions |
113 | 113 | // ----------------- |
114 | - $this->rights = array(); // Permission array used by this module |
|
114 | + $this->rights = array(); // Permission array used by this module |
|
115 | 115 | |
116 | - $r=0; |
|
117 | - $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) |
|
118 | - $this->rights[$r][1] = 'Read archived events and fingerprints'; // Permission label |
|
119 | - $this->rights[$r][3] = 0; // Permission by default for new user (0/1) |
|
120 | - $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->mymodule->level1->level2) |
|
116 | + $r = 0; |
|
117 | + $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) |
|
118 | + $this->rights[$r][1] = 'Read archived events and fingerprints'; // Permission label |
|
119 | + $this->rights[$r][3] = 0; // Permission by default for new user (0/1) |
|
120 | + $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->mymodule->level1->level2) |
|
121 | 121 | $this->rights[$r][5] = ''; |
122 | 122 | |
123 | 123 | // Main menu entries |
124 | 124 | // ----------------- |
125 | - $r=0; |
|
126 | - $this->menu[$r]=array( |
|
127 | - 'fk_menu'=>'fk_mainmenu=tools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode |
|
125 | + $r = 0; |
|
126 | + $this->menu[$r] = array( |
|
127 | + 'fk_menu'=>'fk_mainmenu=tools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode |
|
128 | 128 | 'mainmenu'=>'tools', |
129 | 129 | 'leftmenu'=>'blockedlogbrowser', |
130 | - 'type'=>'left', // This is a Left menu entry |
|
130 | + 'type'=>'left', // This is a Left menu entry |
|
131 | 131 | 'titre'=>'BrowseBlockedLog', |
132 | 132 | 'url'=>'/blockedlog/admin/blockedlog_list.php?mainmenu=tools&leftmenu=blockedlogbrowser', |
133 | - 'langs'=>'blockedlog', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. |
|
133 | + 'langs'=>'blockedlog', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. |
|
134 | 134 | 'position'=>200, |
135 | - 'enabled'=>'$conf->blockedlog->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. |
|
136 | - 'perms'=>'$user->rights->blockedlog->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules |
|
135 | + 'enabled'=>'$conf->blockedlog->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. |
|
136 | + 'perms'=>'$user->rights->blockedlog->read', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules |
|
137 | 137 | 'target'=>'', |
138 | - 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both |
|
138 | + 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both |
|
139 | 139 | $r++; |
140 | 140 | } |
141 | 141 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | { |
150 | 150 | |
151 | 151 | require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; |
152 | - $b=new BlockedLog($this->db); |
|
152 | + $b = new BlockedLog($this->db); |
|
153 | 153 | return $b->alreadyUsed(1); |
154 | 154 | } |
155 | 155 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param string $options Options when enabling module ('', 'noboxes') |
163 | 163 | * @return int 1 if OK, 0 if KO |
164 | 164 | */ |
165 | - function init($options='') |
|
165 | + function init($options = '') |
|
166 | 166 | { |
167 | 167 | global $conf, $user; |
168 | 168 | |
@@ -171,14 +171,14 @@ discard block |
||
171 | 171 | // If already used, we add an entry to show we enable module |
172 | 172 | require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; |
173 | 173 | |
174 | - $object=new stdClass(); |
|
174 | + $object = new stdClass(); |
|
175 | 175 | $object->id = 1; |
176 | 176 | $object->element = 'module'; |
177 | 177 | $object->ref = 'systemevent'; |
178 | 178 | $object->entity = $conf->entity; |
179 | 179 | $object->date = dol_now(); |
180 | 180 | |
181 | - $b=new BlockedLog($this->db); |
|
181 | + $b = new BlockedLog($this->db); |
|
182 | 182 | $result = $b->setObjectData($object, 'MODULE_SET', 0); |
183 | 183 | if ($result < 0) |
184 | 184 | { |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | } |
189 | 189 | |
190 | 190 | $res = $b->create($user); |
191 | - if ($res<=0) { |
|
191 | + if ($res <= 0) { |
|
192 | 192 | $this->error = $b->error; |
193 | 193 | $this->errors = $b->errors; |
194 | 194 | return $res; |
@@ -215,14 +215,14 @@ discard block |
||
215 | 215 | // If already used, we add an entry to show we enable module |
216 | 216 | require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; |
217 | 217 | |
218 | - $object=new stdClass(); |
|
218 | + $object = new stdClass(); |
|
219 | 219 | $object->id = 1; |
220 | 220 | $object->element = 'module'; |
221 | 221 | $object->ref = 'systemevent'; |
222 | 222 | $object->entity = $conf->entity; |
223 | 223 | $object->date = dol_now(); |
224 | 224 | |
225 | - $b=new BlockedLog($this->db); |
|
225 | + $b = new BlockedLog($this->db); |
|
226 | 226 | $result = $b->setObjectData($object, 'MODULE_RESET', 0); |
227 | 227 | if ($result < 0) |
228 | 228 | { |
@@ -233,13 +233,13 @@ discard block |
||
233 | 233 | |
234 | 234 | if ($b->alreadyUsed(1)) |
235 | 235 | { |
236 | - $res = $b->create($user, '0000000000'); // If already used for something else than SET or UNSET, we log with error |
|
236 | + $res = $b->create($user, '0000000000'); // If already used for something else than SET or UNSET, we log with error |
|
237 | 237 | } |
238 | 238 | else |
239 | 239 | { |
240 | 240 | $res = $b->create($user); |
241 | 241 | } |
242 | - if ($res<=0) { |
|
242 | + if ($res <= 0) { |
|
243 | 243 | $this->error = $b->error; |
244 | 244 | $this->errors = $b->errors; |
245 | 245 | return $res; |
@@ -234,8 +234,7 @@ |
||
234 | 234 | if ($b->alreadyUsed(1)) |
235 | 235 | { |
236 | 236 | $res = $b->create($user, '0000000000'); // If already used for something else than SET or UNSET, we log with error |
237 | - } |
|
238 | - else |
|
237 | + } else |
|
239 | 238 | { |
240 | 239 | $res = $b->create($user); |
241 | 240 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | class mailing_fraise extends MailingTargets |
35 | 35 | { |
36 | 36 | var $name='FundationMembers'; // Identifiant du module mailing |
37 | - // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
37 | + // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
38 | 38 | var $desc='Foundation members with emails'; |
39 | 39 | // Set to 1 if selector is available for admin users only |
40 | 40 | var $require_admin=0; |
@@ -175,24 +175,24 @@ discard block |
||
175 | 175 | $resql = $this->db->query($sql); |
176 | 176 | if ($resql) |
177 | 177 | { |
178 | - $num = $this->db->num_rows($resql); |
|
178 | + $num = $this->db->num_rows($resql); |
|
179 | 179 | |
180 | - $s.='<option value="0"> </option>'; |
|
181 | - if (! $num) $s.='<option value="0" disabled>'.$langs->trans("NoCategoriesDefined").'</option>'; |
|
180 | + $s.='<option value="0"> </option>'; |
|
181 | + if (! $num) $s.='<option value="0" disabled>'.$langs->trans("NoCategoriesDefined").'</option>'; |
|
182 | 182 | |
183 | - $i = 0; |
|
184 | - while ($i < $num) |
|
185 | - { |
|
186 | - $obj = $this->db->fetch_object($resql); |
|
183 | + $i = 0; |
|
184 | + while ($i < $num) |
|
185 | + { |
|
186 | + $obj = $this->db->fetch_object($resql); |
|
187 | 187 | |
188 | - $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle'); |
|
189 | - $s.='</option>'; |
|
190 | - $i++; |
|
191 | - } |
|
188 | + $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle'); |
|
189 | + $s.='</option>'; |
|
190 | + $i++; |
|
191 | + } |
|
192 | 192 | } |
193 | 193 | else |
194 | 194 | { |
195 | - dol_print_error($this->db); |
|
195 | + dol_print_error($this->db); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | $s.='</select>'; |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | function add_to_target($mailing_id) |
231 | 231 | { |
232 | 232 | // phpcs:enable |
233 | - global $langs,$_POST; |
|
233 | + global $langs,$_POST; |
|
234 | 234 | |
235 | - // Load translation files required by the page |
|
235 | + // Load translation files required by the page |
|
236 | 236 | $langs->loadLangs(array("members","companies")); |
237 | 237 | |
238 | 238 | $cibles = array(); |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; |
249 | 249 | if ($_POST['filter_category']) |
250 | 250 | { |
251 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as cm ON cm.fk_member = a.rowid"; |
|
252 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON c.rowid = cm.fk_categorie"; |
|
251 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as cm ON cm.fk_member = a.rowid"; |
|
252 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON c.rowid = cm.fk_categorie"; |
|
253 | 253 | } |
254 | 254 | $sql.= " , ".MAIN_DB_PREFIX."adherent_type as ta"; |
255 | 255 | $sql.= " WHERE a.entity IN (".getEntity('member').") AND a.email <> ''"; // Note that null != '' is false |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | */ |
34 | 34 | class mailing_fraise extends MailingTargets |
35 | 35 | { |
36 | - var $name='FundationMembers'; // Identifiant du module mailing |
|
36 | + var $name = 'FundationMembers'; // Identifiant du module mailing |
|
37 | 37 | // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
38 | - var $desc='Foundation members with emails'; |
|
38 | + var $desc = 'Foundation members with emails'; |
|
39 | 39 | // Set to 1 if selector is available for admin users only |
40 | - var $require_admin=0; |
|
40 | + var $require_admin = 0; |
|
41 | 41 | |
42 | - var $require_module=array('adherent'); |
|
43 | - var $picto='user'; |
|
42 | + var $require_module = array('adherent'); |
|
43 | + var $picto = 'user'; |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @var DoliDB Database handler. |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | $langs->load("members"); |
74 | 74 | |
75 | 75 | // Array for requests for statistics board |
76 | - $statssql=array(); |
|
76 | + $statssql = array(); |
|
77 | 77 | |
78 | - $statssql[0] ="SELECT '".$this->db->escape($langs->trans("FundationMembers"))."' as label, count(*) as nb"; |
|
79 | - $statssql[0].=" FROM ".MAIN_DB_PREFIX."adherent where statut = 1 and entity IN (".getEntity('member').")"; |
|
78 | + $statssql[0] = "SELECT '".$this->db->escape($langs->trans("FundationMembers"))."' as label, count(*) as nb"; |
|
79 | + $statssql[0] .= " FROM ".MAIN_DB_PREFIX."adherent where statut = 1 and entity IN (".getEntity('member').")"; |
|
80 | 80 | |
81 | 81 | return $statssql; |
82 | 82 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param string $sql Requete sql de comptage |
91 | 91 | * @return int Nb of recipients |
92 | 92 | */ |
93 | - function getNbOfRecipients($sql='') |
|
93 | + function getNbOfRecipients($sql = '') |
|
94 | 94 | { |
95 | 95 | $sql = "SELECT count(distinct(a.email)) as nb"; |
96 | 96 | $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a"; |
@@ -112,42 +112,42 @@ discard block |
||
112 | 112 | global $conf, $langs; |
113 | 113 | |
114 | 114 | // Load translation files required by the page |
115 | - $langs->loadLangs(array("members","companies","categories")); |
|
115 | + $langs->loadLangs(array("members", "companies", "categories")); |
|
116 | 116 | |
117 | - $form=new Form($this->db); |
|
117 | + $form = new Form($this->db); |
|
118 | 118 | |
119 | - $s=''; |
|
119 | + $s = ''; |
|
120 | 120 | |
121 | 121 | // Status |
122 | - $s.=$langs->trans("Status").': '; |
|
123 | - $s.='<select name="filter" class="flat">'; |
|
124 | - $s.='<option value="none"> </option>'; |
|
125 | - $s.='<option value="-1">'.$langs->trans("MemberStatusDraft").'</option>'; |
|
126 | - $s.='<option value="1a">'.$langs->trans("MemberStatusActiveShort").' ('.$langs->trans("MemberStatusPaidShort").')</option>'; |
|
127 | - $s.='<option value="1b">'.$langs->trans("MemberStatusActiveShort").' ('.$langs->trans("MemberStatusActiveLateShort").')</option>'; |
|
128 | - $s.='<option value="0">'.$langs->trans("MemberStatusResiliatedShort").'</option>'; |
|
129 | - $s.='</select> '; |
|
130 | - $s.=$langs->trans("Type").': '; |
|
131 | - $s.='<select name="filter_type" class="flat">'; |
|
122 | + $s .= $langs->trans("Status").': '; |
|
123 | + $s .= '<select name="filter" class="flat">'; |
|
124 | + $s .= '<option value="none"> </option>'; |
|
125 | + $s .= '<option value="-1">'.$langs->trans("MemberStatusDraft").'</option>'; |
|
126 | + $s .= '<option value="1a">'.$langs->trans("MemberStatusActiveShort").' ('.$langs->trans("MemberStatusPaidShort").')</option>'; |
|
127 | + $s .= '<option value="1b">'.$langs->trans("MemberStatusActiveShort").' ('.$langs->trans("MemberStatusActiveLateShort").')</option>'; |
|
128 | + $s .= '<option value="0">'.$langs->trans("MemberStatusResiliatedShort").'</option>'; |
|
129 | + $s .= '</select> '; |
|
130 | + $s .= $langs->trans("Type").': '; |
|
131 | + $s .= '<select name="filter_type" class="flat">'; |
|
132 | 132 | $sql = "SELECT rowid, libelle, statut"; |
133 | - $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type"; |
|
134 | - $sql.= " WHERE entity IN (".getEntity('member_type').")"; |
|
135 | - $sql.= " ORDER BY rowid"; |
|
133 | + $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type"; |
|
134 | + $sql .= " WHERE entity IN (".getEntity('member_type').")"; |
|
135 | + $sql .= " ORDER BY rowid"; |
|
136 | 136 | $resql = $this->db->query($sql); |
137 | 137 | if ($resql) |
138 | 138 | { |
139 | 139 | $num = $this->db->num_rows($resql); |
140 | 140 | |
141 | - $s.='<option value="0"> </option>'; |
|
142 | - if (! $num) $s.='<option value="0" disabled="disabled">'.$langs->trans("NoCategoriesDefined").'</option>'; |
|
141 | + $s .= '<option value="0"> </option>'; |
|
142 | + if (!$num) $s .= '<option value="0" disabled="disabled">'.$langs->trans("NoCategoriesDefined").'</option>'; |
|
143 | 143 | |
144 | 144 | $i = 0; |
145 | 145 | while ($i < $num) |
146 | 146 | { |
147 | 147 | $obj = $this->db->fetch_object($resql); |
148 | 148 | |
149 | - $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->libelle,38,'middle'); |
|
150 | - $s.='</option>'; |
|
149 | + $s .= '<option value="'.$obj->rowid.'">'.dol_trunc($obj->libelle, 38, 'middle'); |
|
150 | + $s .= '</option>'; |
|
151 | 151 | $i++; |
152 | 152 | } |
153 | 153 | } |
@@ -156,20 +156,20 @@ discard block |
||
156 | 156 | dol_print_error($this->db); |
157 | 157 | } |
158 | 158 | |
159 | - $s.='</select>'; |
|
159 | + $s .= '</select>'; |
|
160 | 160 | |
161 | - $s.=' '; |
|
161 | + $s .= ' '; |
|
162 | 162 | |
163 | - $s.=$langs->trans("Category").': '; |
|
164 | - $s.='<select name="filter_category" class="flat">'; |
|
163 | + $s .= $langs->trans("Category").': '; |
|
164 | + $s .= '<select name="filter_category" class="flat">'; |
|
165 | 165 | |
166 | 166 | // Show categories |
167 | 167 | $sql = "SELECT rowid, label, type, visible"; |
168 | - $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; |
|
169 | - $sql.= " WHERE type = 3"; // We keep only categories for members |
|
168 | + $sql .= " FROM ".MAIN_DB_PREFIX."categorie"; |
|
169 | + $sql .= " WHERE type = 3"; // We keep only categories for members |
|
170 | 170 | // $sql.= " AND visible > 0"; // We ignore the property visible because member's categories does not use this property (only products categories use it). |
171 | - $sql.= " AND entity = ".$conf->entity; |
|
172 | - $sql.= " ORDER BY label"; |
|
171 | + $sql .= " AND entity = ".$conf->entity; |
|
172 | + $sql .= " ORDER BY label"; |
|
173 | 173 | |
174 | 174 | //print $sql; |
175 | 175 | $resql = $this->db->query($sql); |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | { |
178 | 178 | $num = $this->db->num_rows($resql); |
179 | 179 | |
180 | - $s.='<option value="0"> </option>'; |
|
181 | - if (! $num) $s.='<option value="0" disabled>'.$langs->trans("NoCategoriesDefined").'</option>'; |
|
180 | + $s .= '<option value="0"> </option>'; |
|
181 | + if (!$num) $s .= '<option value="0" disabled>'.$langs->trans("NoCategoriesDefined").'</option>'; |
|
182 | 182 | |
183 | 183 | $i = 0; |
184 | 184 | while ($i < $num) |
185 | 185 | { |
186 | 186 | $obj = $this->db->fetch_object($resql); |
187 | 187 | |
188 | - $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle'); |
|
189 | - $s.='</option>'; |
|
188 | + $s .= '<option value="'.$obj->rowid.'">'.dol_trunc($obj->label, 38, 'middle'); |
|
189 | + $s .= '</option>'; |
|
190 | 190 | $i++; |
191 | 191 | } |
192 | 192 | } |
@@ -195,14 +195,14 @@ discard block |
||
195 | 195 | dol_print_error($this->db); |
196 | 196 | } |
197 | 197 | |
198 | - $s.='</select>'; |
|
198 | + $s .= '</select>'; |
|
199 | 199 | |
200 | 200 | |
201 | - $s.='<br>'; |
|
202 | - $s.=$langs->trans("DateEndSubscription").': '; |
|
203 | - $s.=$langs->trans("After").' > '.$form->selectDate(-1,'subscriptionafter',0,0,1,'fraise',1,0,0); |
|
204 | - $s.=' '; |
|
205 | - $s.=$langs->trans("Before").' < '.$form->selectDate(-1,'subscriptionbefore',0,0,1,'fraise',1,0,0); |
|
201 | + $s .= '<br>'; |
|
202 | + $s .= $langs->trans("DateEndSubscription").': '; |
|
203 | + $s .= $langs->trans("After").' > '.$form->selectDate(-1, 'subscriptionafter', 0, 0, 1, 'fraise', 1, 0, 0); |
|
204 | + $s .= ' '; |
|
205 | + $s .= $langs->trans("Before").' < '.$form->selectDate(-1, 'subscriptionbefore', 0, 0, 1, 'fraise', 1, 0, 0); |
|
206 | 206 | |
207 | 207 | return $s; |
208 | 208 | } |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | */ |
217 | 217 | function url($id) |
218 | 218 | { |
219 | - return '<a href="'.DOL_URL_ROOT.'/adherents/card.php?rowid='.$id.'">'.img_object('',"user").'</a>'; |
|
219 | + return '<a href="'.DOL_URL_ROOT.'/adherents/card.php?rowid='.$id.'">'.img_object('', "user").'</a>'; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | |
@@ -230,49 +230,49 @@ discard block |
||
230 | 230 | function add_to_target($mailing_id) |
231 | 231 | { |
232 | 232 | // phpcs:enable |
233 | - global $langs,$_POST; |
|
233 | + global $langs, $_POST; |
|
234 | 234 | |
235 | 235 | // Load translation files required by the page |
236 | - $langs->loadLangs(array("members","companies")); |
|
236 | + $langs->loadLangs(array("members", "companies")); |
|
237 | 237 | |
238 | 238 | $cibles = array(); |
239 | - $now=dol_now(); |
|
239 | + $now = dol_now(); |
|
240 | 240 | |
241 | - $dateendsubscriptionafter=dol_mktime($_POST['subscriptionafterhour'],$_POST['subscriptionaftermin'],$_POST['subscriptionaftersec'],$_POST['subscriptionaftermonth'],$_POST['subscriptionafterday'],$_POST['subscriptionafteryear']); |
|
242 | - $dateendsubscriptionbefore=dol_mktime($_POST['subscriptionbeforehour'],$_POST['subscriptionbeforemin'],$_POST['subscriptionbeforesec'],$_POST['subscriptionbeforemonth'],$_POST['subscriptionbeforeday'],$_POST['subscriptionbeforeyear']); |
|
241 | + $dateendsubscriptionafter = dol_mktime($_POST['subscriptionafterhour'], $_POST['subscriptionaftermin'], $_POST['subscriptionaftersec'], $_POST['subscriptionaftermonth'], $_POST['subscriptionafterday'], $_POST['subscriptionafteryear']); |
|
242 | + $dateendsubscriptionbefore = dol_mktime($_POST['subscriptionbeforehour'], $_POST['subscriptionbeforemin'], $_POST['subscriptionbeforesec'], $_POST['subscriptionbeforemonth'], $_POST['subscriptionbeforeday'], $_POST['subscriptionbeforeyear']); |
|
243 | 243 | |
244 | 244 | // La requete doit retourner: id, email, fk_contact, name, firstname |
245 | 245 | $sql = "SELECT a.rowid as id, a.email as email, null as fk_contact, "; |
246 | - $sql.= " a.lastname, a.firstname,"; |
|
247 | - $sql.= " a.datefin, a.civility as civility_id, a.login, a.societe"; // Other fields |
|
248 | - $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a"; |
|
246 | + $sql .= " a.lastname, a.firstname,"; |
|
247 | + $sql .= " a.datefin, a.civility as civility_id, a.login, a.societe"; // Other fields |
|
248 | + $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a"; |
|
249 | 249 | if ($_POST['filter_category']) |
250 | 250 | { |
251 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as cm ON cm.fk_member = a.rowid"; |
|
252 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON c.rowid = cm.fk_categorie"; |
|
251 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as cm ON cm.fk_member = a.rowid"; |
|
252 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON c.rowid = cm.fk_categorie"; |
|
253 | 253 | } |
254 | - $sql.= " , ".MAIN_DB_PREFIX."adherent_type as ta"; |
|
255 | - $sql.= " WHERE a.entity IN (".getEntity('member').") AND a.email <> ''"; // Note that null != '' is false |
|
256 | - $sql.= " AND a.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$this->db->escape($mailing_id).")"; |
|
254 | + $sql .= " , ".MAIN_DB_PREFIX."adherent_type as ta"; |
|
255 | + $sql .= " WHERE a.entity IN (".getEntity('member').") AND a.email <> ''"; // Note that null != '' is false |
|
256 | + $sql .= " AND a.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$this->db->escape($mailing_id).")"; |
|
257 | 257 | // Filter on status |
258 | - if (isset($_POST["filter"]) && $_POST["filter"] == '-1') $sql.= " AND a.statut=-1"; |
|
259 | - if (isset($_POST["filter"]) && $_POST["filter"] == '1a') $sql.= " AND a.statut=1 AND a.datefin >= '".$this->db->idate($now)."'"; |
|
260 | - if (isset($_POST["filter"]) && $_POST["filter"] == '1b') $sql.= " AND a.statut=1 AND (a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."')"; |
|
261 | - if (isset($_POST["filter"]) && $_POST["filter"] == '0') $sql.= " AND a.statut=0"; |
|
258 | + if (isset($_POST["filter"]) && $_POST["filter"] == '-1') $sql .= " AND a.statut=-1"; |
|
259 | + if (isset($_POST["filter"]) && $_POST["filter"] == '1a') $sql .= " AND a.statut=1 AND a.datefin >= '".$this->db->idate($now)."'"; |
|
260 | + if (isset($_POST["filter"]) && $_POST["filter"] == '1b') $sql .= " AND a.statut=1 AND (a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."')"; |
|
261 | + if (isset($_POST["filter"]) && $_POST["filter"] == '0') $sql .= " AND a.statut=0"; |
|
262 | 262 | // Filter on date |
263 | - if ($dateendsubscriptionafter > 0) $sql.=" AND datefin > '".$this->db->idate($dateendsubscriptionafter)."'"; |
|
264 | - if ($dateendsubscriptionbefore > 0) $sql.=" AND datefin < '".$this->db->idate($dateendsubscriptionbefore)."'"; |
|
265 | - $sql.= " AND a.fk_adherent_type = ta.rowid"; |
|
263 | + if ($dateendsubscriptionafter > 0) $sql .= " AND datefin > '".$this->db->idate($dateendsubscriptionafter)."'"; |
|
264 | + if ($dateendsubscriptionbefore > 0) $sql .= " AND datefin < '".$this->db->idate($dateendsubscriptionbefore)."'"; |
|
265 | + $sql .= " AND a.fk_adherent_type = ta.rowid"; |
|
266 | 266 | // Filter on type |
267 | - if ($_POST['filter_type']) $sql.= " AND ta.rowid='".$_POST['filter_type']."'"; |
|
267 | + if ($_POST['filter_type']) $sql .= " AND ta.rowid='".$_POST['filter_type']."'"; |
|
268 | 268 | // Filter on category |
269 | - if ($_POST['filter_category']) $sql.= " AND c.rowid='".$_POST['filter_category']."'"; |
|
270 | - $sql.= " ORDER BY a.email"; |
|
269 | + if ($_POST['filter_category']) $sql .= " AND c.rowid='".$_POST['filter_category']."'"; |
|
270 | + $sql .= " ORDER BY a.email"; |
|
271 | 271 | //print $sql; |
272 | 272 | |
273 | 273 | // Add targets into table |
274 | 274 | dol_syslog(get_class($this)."::add_to_target", LOG_DEBUG); |
275 | - $result=$this->db->query($sql); |
|
275 | + $result = $this->db->query($sql); |
|
276 | 276 | if ($result) |
277 | 277 | { |
278 | 278 | $num = $this->db->num_rows($result); |
@@ -294,8 +294,8 @@ discard block |
||
294 | 294 | 'firstname' => $obj->firstname, |
295 | 295 | 'other' => |
296 | 296 | ($langs->transnoentities("Login").'='.$obj->login).';'. |
297 | - ($langs->transnoentities("UserTitle").'='.($obj->civility_id?$langs->transnoentities("Civility".$obj->civility_id):'')).';'. |
|
298 | - ($langs->transnoentities("DateEnd").'='.dol_print_date($this->db->jdate($obj->datefin),'day')).';'. |
|
297 | + ($langs->transnoentities("UserTitle").'='.($obj->civility_id ? $langs->transnoentities("Civility".$obj->civility_id) : '')).';'. |
|
298 | + ($langs->transnoentities("DateEnd").'='.dol_print_date($this->db->jdate($obj->datefin), 'day')).';'. |
|
299 | 299 | ($langs->transnoentities("Company").'='.$obj->societe), |
300 | 300 | 'source_url' => $this->url($obj->id), |
301 | 301 | 'source_id' => $obj->id, |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | else |
312 | 312 | { |
313 | 313 | dol_syslog($this->db->error()); |
314 | - $this->error=$this->db->error(); |
|
314 | + $this->error = $this->db->error(); |
|
315 | 315 | return -1; |
316 | 316 | } |
317 | 317 |
@@ -139,7 +139,9 @@ discard block |
||
139 | 139 | $num = $this->db->num_rows($resql); |
140 | 140 | |
141 | 141 | $s.='<option value="0"> </option>'; |
142 | - if (! $num) $s.='<option value="0" disabled="disabled">'.$langs->trans("NoCategoriesDefined").'</option>'; |
|
142 | + if (! $num) { |
|
143 | + $s.='<option value="0" disabled="disabled">'.$langs->trans("NoCategoriesDefined").'</option>'; |
|
144 | + } |
|
143 | 145 | |
144 | 146 | $i = 0; |
145 | 147 | while ($i < $num) |
@@ -150,8 +152,7 @@ discard block |
||
150 | 152 | $s.='</option>'; |
151 | 153 | $i++; |
152 | 154 | } |
153 | - } |
|
154 | - else |
|
155 | + } else |
|
155 | 156 | { |
156 | 157 | dol_print_error($this->db); |
157 | 158 | } |
@@ -178,7 +179,9 @@ discard block |
||
178 | 179 | $num = $this->db->num_rows($resql); |
179 | 180 | |
180 | 181 | $s.='<option value="0"> </option>'; |
181 | - if (! $num) $s.='<option value="0" disabled>'.$langs->trans("NoCategoriesDefined").'</option>'; |
|
182 | + if (! $num) { |
|
183 | + $s.='<option value="0" disabled>'.$langs->trans("NoCategoriesDefined").'</option>'; |
|
184 | + } |
|
182 | 185 | |
183 | 186 | $i = 0; |
184 | 187 | while ($i < $num) |
@@ -189,8 +192,7 @@ discard block |
||
189 | 192 | $s.='</option>'; |
190 | 193 | $i++; |
191 | 194 | } |
192 | - } |
|
193 | - else |
|
195 | + } else |
|
194 | 196 | { |
195 | 197 | dol_print_error($this->db); |
196 | 198 | } |
@@ -255,18 +257,34 @@ discard block |
||
255 | 257 | $sql.= " WHERE a.entity IN (".getEntity('member').") AND a.email <> ''"; // Note that null != '' is false |
256 | 258 | $sql.= " AND a.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$this->db->escape($mailing_id).")"; |
257 | 259 | // Filter on status |
258 | - if (isset($_POST["filter"]) && $_POST["filter"] == '-1') $sql.= " AND a.statut=-1"; |
|
259 | - if (isset($_POST["filter"]) && $_POST["filter"] == '1a') $sql.= " AND a.statut=1 AND a.datefin >= '".$this->db->idate($now)."'"; |
|
260 | - if (isset($_POST["filter"]) && $_POST["filter"] == '1b') $sql.= " AND a.statut=1 AND (a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."')"; |
|
261 | - if (isset($_POST["filter"]) && $_POST["filter"] == '0') $sql.= " AND a.statut=0"; |
|
260 | + if (isset($_POST["filter"]) && $_POST["filter"] == '-1') { |
|
261 | + $sql.= " AND a.statut=-1"; |
|
262 | + } |
|
263 | + if (isset($_POST["filter"]) && $_POST["filter"] == '1a') { |
|
264 | + $sql.= " AND a.statut=1 AND a.datefin >= '".$this->db->idate($now)."'"; |
|
265 | + } |
|
266 | + if (isset($_POST["filter"]) && $_POST["filter"] == '1b') { |
|
267 | + $sql.= " AND a.statut=1 AND (a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."')"; |
|
268 | + } |
|
269 | + if (isset($_POST["filter"]) && $_POST["filter"] == '0') { |
|
270 | + $sql.= " AND a.statut=0"; |
|
271 | + } |
|
262 | 272 | // Filter on date |
263 | - if ($dateendsubscriptionafter > 0) $sql.=" AND datefin > '".$this->db->idate($dateendsubscriptionafter)."'"; |
|
264 | - if ($dateendsubscriptionbefore > 0) $sql.=" AND datefin < '".$this->db->idate($dateendsubscriptionbefore)."'"; |
|
273 | + if ($dateendsubscriptionafter > 0) { |
|
274 | + $sql.=" AND datefin > '".$this->db->idate($dateendsubscriptionafter)."'"; |
|
275 | + } |
|
276 | + if ($dateendsubscriptionbefore > 0) { |
|
277 | + $sql.=" AND datefin < '".$this->db->idate($dateendsubscriptionbefore)."'"; |
|
278 | + } |
|
265 | 279 | $sql.= " AND a.fk_adherent_type = ta.rowid"; |
266 | 280 | // Filter on type |
267 | - if ($_POST['filter_type']) $sql.= " AND ta.rowid='".$_POST['filter_type']."'"; |
|
281 | + if ($_POST['filter_type']) { |
|
282 | + $sql.= " AND ta.rowid='".$_POST['filter_type']."'"; |
|
283 | + } |
|
268 | 284 | // Filter on category |
269 | - if ($_POST['filter_category']) $sql.= " AND c.rowid='".$_POST['filter_category']."'"; |
|
285 | + if ($_POST['filter_category']) { |
|
286 | + $sql.= " AND c.rowid='".$_POST['filter_category']."'"; |
|
287 | + } |
|
270 | 288 | $sql.= " ORDER BY a.email"; |
271 | 289 | //print $sql; |
272 | 290 | |
@@ -307,8 +325,7 @@ discard block |
||
307 | 325 | |
308 | 326 | $i++; |
309 | 327 | } |
310 | - } |
|
311 | - else |
|
328 | + } else |
|
312 | 329 | { |
313 | 330 | dol_syslog($this->db->error()); |
314 | 331 | $this->error=$this->db->error(); |
@@ -37,22 +37,22 @@ discard block |
||
37 | 37 | public $db; |
38 | 38 | |
39 | 39 | /** |
40 | - * @var string Error code (or message) |
|
41 | - */ |
|
42 | - public $error=''; |
|
40 | + * @var string Error code (or message) |
|
41 | + */ |
|
42 | + public $error=''; |
|
43 | 43 | |
44 | 44 | public $tooltip=''; |
45 | 45 | |
46 | 46 | |
47 | 47 | /** |
48 | - * Constructor |
|
49 | - * |
|
50 | - * @param DoliDB $db Database handler |
|
51 | - */ |
|
52 | - function __construct($db) |
|
53 | - { |
|
48 | + * Constructor |
|
49 | + * |
|
50 | + * @param DoliDB $db Database handler |
|
51 | + */ |
|
52 | + function __construct($db) |
|
53 | + { |
|
54 | 54 | $this->db = $db; |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Return description of email selector |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Return number of records for email selector |
|
79 | + * Return number of records for email selector |
|
80 | 80 | * |
81 | 81 | * @return integer Example |
82 | 82 | */ |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | } |
102 | 102 | else |
103 | 103 | { |
104 | - $this->error=$this->db->lasterror(); |
|
104 | + $this->error=$this->db->lasterror(); |
|
105 | 105 | return -1; |
106 | 106 | } |
107 | 107 | } |
@@ -162,51 +162,51 @@ discard block |
||
162 | 162 | function add_to_target($mailing_id, $cibles) |
163 | 163 | { |
164 | 164 | // phpcs:enable |
165 | - global $conf; |
|
165 | + global $conf; |
|
166 | 166 | |
167 | - $this->db->begin(); |
|
167 | + $this->db->begin(); |
|
168 | 168 | |
169 | 169 | // Insert emailing targets from array into database |
170 | 170 | $j = 0; |
171 | 171 | $num = count($cibles); |
172 | 172 | foreach ($cibles as $targetarray) |
173 | 173 | { |
174 | - if (! empty($targetarray['email'])) // avoid empty email address |
|
175 | - { |
|
176 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles"; |
|
177 | - $sql.= " (fk_mailing,"; |
|
178 | - $sql.= " fk_contact,"; |
|
179 | - $sql.= " lastname, firstname, email, other, source_url, source_id,"; |
|
180 | - $sql.= " tag,"; |
|
181 | - $sql.= " source_type)"; |
|
182 | - $sql.= " VALUES (".$mailing_id.","; |
|
183 | - $sql.= (empty($targetarray['fk_contact']) ? '0' : "'".$targetarray['fk_contact']."'") .","; |
|
184 | - $sql.= "'".$this->db->escape($targetarray['lastname'])."',"; |
|
185 | - $sql.= "'".$this->db->escape($targetarray['firstname'])."',"; |
|
186 | - $sql.= "'".$this->db->escape($targetarray['email'])."',"; |
|
187 | - $sql.= "'".$this->db->escape($targetarray['other'])."',"; |
|
188 | - $sql.= "'".$this->db->escape($targetarray['source_url'])."',"; |
|
189 | - $sql.= (empty($targetarray['source_id']) ? 'null' : "'".$this->db->escape($targetarray['source_id'])."'").","; |
|
190 | - $sql .= "'".$this->db->escape(dol_hash($targetarray['email'].';'.$targetarray['lastname'].';'.$mailing_id.';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY))."',"; |
|
191 | - $sql .= "'".$this->db->escape($targetarray['source_type'])."')"; |
|
192 | - dol_syslog(get_class($this)."::".__METHOD__,LOG_DEBUG); |
|
193 | - $result=$this->db->query($sql); |
|
194 | - if ($result) |
|
195 | - { |
|
196 | - $j++; |
|
197 | - } |
|
198 | - else |
|
199 | - { |
|
200 | - if ($this->db->errno() != 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
201 | - { |
|
202 | - // Si erreur autre que doublon |
|
203 | - dol_syslog($this->db->error()); |
|
204 | - $this->error=$this->db->error(); |
|
205 | - $this->db->rollback(); |
|
206 | - return -1; |
|
207 | - } |
|
208 | - } |
|
209 | - } |
|
174 | + if (! empty($targetarray['email'])) // avoid empty email address |
|
175 | + { |
|
176 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles"; |
|
177 | + $sql.= " (fk_mailing,"; |
|
178 | + $sql.= " fk_contact,"; |
|
179 | + $sql.= " lastname, firstname, email, other, source_url, source_id,"; |
|
180 | + $sql.= " tag,"; |
|
181 | + $sql.= " source_type)"; |
|
182 | + $sql.= " VALUES (".$mailing_id.","; |
|
183 | + $sql.= (empty($targetarray['fk_contact']) ? '0' : "'".$targetarray['fk_contact']."'") .","; |
|
184 | + $sql.= "'".$this->db->escape($targetarray['lastname'])."',"; |
|
185 | + $sql.= "'".$this->db->escape($targetarray['firstname'])."',"; |
|
186 | + $sql.= "'".$this->db->escape($targetarray['email'])."',"; |
|
187 | + $sql.= "'".$this->db->escape($targetarray['other'])."',"; |
|
188 | + $sql.= "'".$this->db->escape($targetarray['source_url'])."',"; |
|
189 | + $sql.= (empty($targetarray['source_id']) ? 'null' : "'".$this->db->escape($targetarray['source_id'])."'").","; |
|
190 | + $sql .= "'".$this->db->escape(dol_hash($targetarray['email'].';'.$targetarray['lastname'].';'.$mailing_id.';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY))."',"; |
|
191 | + $sql .= "'".$this->db->escape($targetarray['source_type'])."')"; |
|
192 | + dol_syslog(get_class($this)."::".__METHOD__,LOG_DEBUG); |
|
193 | + $result=$this->db->query($sql); |
|
194 | + if ($result) |
|
195 | + { |
|
196 | + $j++; |
|
197 | + } |
|
198 | + else |
|
199 | + { |
|
200 | + if ($this->db->errno() != 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
201 | + { |
|
202 | + // Si erreur autre que doublon |
|
203 | + dol_syslog($this->db->error()); |
|
204 | + $this->error=$this->db->error(); |
|
205 | + $this->db->rollback(); |
|
206 | + return -1; |
|
207 | + } |
|
208 | + } |
|
209 | + } |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | dol_syslog(get_class($this)."::".__METHOD__.": mailing ".$j." targets added"); |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | $result=$this->db->query($sql); |
238 | 238 | if (! $result) |
239 | 239 | { |
240 | - dol_print_error($this->db); |
|
240 | + dol_print_error($this->db); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | $this->update_nb($mailing_id); |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @var string Error code (or message) |
41 | 41 | */ |
42 | - public $error=''; |
|
42 | + public $error = ''; |
|
43 | 43 | |
44 | - public $tooltip=''; |
|
44 | + public $tooltip = ''; |
|
45 | 45 | |
46 | 46 | |
47 | 47 | /** |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | global $langs, $form; |
65 | 65 | |
66 | 66 | $langs->load("mails"); |
67 | - $transstring="MailingModuleDesc".$this->name; |
|
68 | - $s=''; |
|
67 | + $transstring = "MailingModuleDesc".$this->name; |
|
68 | + $s = ''; |
|
69 | 69 | |
70 | - if ($langs->trans($this->name) != $this->name) $s=$langs->trans($this->name); |
|
71 | - elseif ($langs->trans($transstring) != $transstring) $s=$langs->trans($transstring); |
|
72 | - else $s=$this->desc; |
|
70 | + if ($langs->trans($this->name) != $this->name) $s = $langs->trans($this->name); |
|
71 | + elseif ($langs->trans($transstring) != $transstring) $s = $langs->trans($transstring); |
|
72 | + else $s = $this->desc; |
|
73 | 73 | |
74 | 74 | if ($this->tooltip && is_object($form)) $s .= ' '.$form->textwithpicto('', $langs->trans($this->tooltip), 1, 1); |
75 | 75 | return $s; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | function getNbOfRecipients($sql) |
95 | 95 | { |
96 | - $result=$this->db->query($sql); |
|
96 | + $result = $this->db->query($sql); |
|
97 | 97 | if ($result) |
98 | 98 | { |
99 | 99 | $obj = $this->db->fetch_object($result); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | } |
102 | 102 | else |
103 | 103 | { |
104 | - $this->error=$this->db->lasterror(); |
|
104 | + $this->error = $this->db->lasterror(); |
|
105 | 105 | return -1; |
106 | 106 | } |
107 | 107 | } |
@@ -130,18 +130,18 @@ discard block |
||
130 | 130 | // Mise a jour nombre de destinataire dans table des mailings |
131 | 131 | $sql = "SELECT COUNT(*) nb FROM ".MAIN_DB_PREFIX."mailing_cibles"; |
132 | 132 | $sql .= " WHERE fk_mailing = ".$mailing_id; |
133 | - $result=$this->db->query($sql); |
|
133 | + $result = $this->db->query($sql); |
|
134 | 134 | if ($result) |
135 | 135 | { |
136 | - $obj=$this->db->fetch_object($result); |
|
137 | - $nb=$obj->nb; |
|
136 | + $obj = $this->db->fetch_object($result); |
|
137 | + $nb = $obj->nb; |
|
138 | 138 | |
139 | 139 | $sql = "UPDATE ".MAIN_DB_PREFIX."mailing"; |
140 | 140 | $sql .= " SET nbemail = ".$nb." WHERE rowid = ".$mailing_id; |
141 | 141 | if (!$this->db->query($sql)) |
142 | 142 | { |
143 | 143 | dol_syslog($this->db->error()); |
144 | - $this->error=$this->db->error(); |
|
144 | + $this->error = $this->db->error(); |
|
145 | 145 | return -1; |
146 | 146 | } |
147 | 147 | } |
@@ -171,26 +171,26 @@ discard block |
||
171 | 171 | $num = count($cibles); |
172 | 172 | foreach ($cibles as $targetarray) |
173 | 173 | { |
174 | - if (! empty($targetarray['email'])) // avoid empty email address |
|
174 | + if (!empty($targetarray['email'])) // avoid empty email address |
|
175 | 175 | { |
176 | 176 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles"; |
177 | - $sql.= " (fk_mailing,"; |
|
178 | - $sql.= " fk_contact,"; |
|
179 | - $sql.= " lastname, firstname, email, other, source_url, source_id,"; |
|
180 | - $sql.= " tag,"; |
|
181 | - $sql.= " source_type)"; |
|
182 | - $sql.= " VALUES (".$mailing_id.","; |
|
183 | - $sql.= (empty($targetarray['fk_contact']) ? '0' : "'".$targetarray['fk_contact']."'") .","; |
|
184 | - $sql.= "'".$this->db->escape($targetarray['lastname'])."',"; |
|
185 | - $sql.= "'".$this->db->escape($targetarray['firstname'])."',"; |
|
186 | - $sql.= "'".$this->db->escape($targetarray['email'])."',"; |
|
187 | - $sql.= "'".$this->db->escape($targetarray['other'])."',"; |
|
188 | - $sql.= "'".$this->db->escape($targetarray['source_url'])."',"; |
|
189 | - $sql.= (empty($targetarray['source_id']) ? 'null' : "'".$this->db->escape($targetarray['source_id'])."'").","; |
|
177 | + $sql .= " (fk_mailing,"; |
|
178 | + $sql .= " fk_contact,"; |
|
179 | + $sql .= " lastname, firstname, email, other, source_url, source_id,"; |
|
180 | + $sql .= " tag,"; |
|
181 | + $sql .= " source_type)"; |
|
182 | + $sql .= " VALUES (".$mailing_id.","; |
|
183 | + $sql .= (empty($targetarray['fk_contact']) ? '0' : "'".$targetarray['fk_contact']."'").","; |
|
184 | + $sql .= "'".$this->db->escape($targetarray['lastname'])."',"; |
|
185 | + $sql .= "'".$this->db->escape($targetarray['firstname'])."',"; |
|
186 | + $sql .= "'".$this->db->escape($targetarray['email'])."',"; |
|
187 | + $sql .= "'".$this->db->escape($targetarray['other'])."',"; |
|
188 | + $sql .= "'".$this->db->escape($targetarray['source_url'])."',"; |
|
189 | + $sql .= (empty($targetarray['source_id']) ? 'null' : "'".$this->db->escape($targetarray['source_id'])."'").","; |
|
190 | 190 | $sql .= "'".$this->db->escape(dol_hash($targetarray['email'].';'.$targetarray['lastname'].';'.$mailing_id.';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY))."',"; |
191 | 191 | $sql .= "'".$this->db->escape($targetarray['source_type'])."')"; |
192 | - dol_syslog(get_class($this)."::".__METHOD__,LOG_DEBUG); |
|
193 | - $result=$this->db->query($sql); |
|
192 | + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
|
193 | + $result = $this->db->query($sql); |
|
194 | 194 | if ($result) |
195 | 195 | { |
196 | 196 | $j++; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | { |
202 | 202 | // Si erreur autre que doublon |
203 | 203 | dol_syslog($this->db->error()); |
204 | - $this->error=$this->db->error(); |
|
204 | + $this->error = $this->db->error(); |
|
205 | 205 | $this->db->rollback(); |
206 | 206 | return -1; |
207 | 207 | } |
@@ -234,8 +234,8 @@ discard block |
||
234 | 234 | $sql .= " WHERE fk_mailing=".$mailing_id." AND email IN (SELECT mu.email FROM ".MAIN_DB_PREFIX."mailing_unsubscribe AS mu WHERE mu.entity IN ('".getEntity('mailing')."'))"; |
235 | 235 | |
236 | 236 | dol_syslog(get_class($this)."::".__METHOD__.":mailing update status to display emails that do not want to be contacted anymore", LOG_DEBUG); |
237 | - $result=$this->db->query($sql); |
|
238 | - if (! $result) |
|
237 | + $result = $this->db->query($sql); |
|
238 | + if (!$result) |
|
239 | 239 | { |
240 | 240 | dol_print_error($this->db); |
241 | 241 | } |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles"; |
261 | 261 | $sql .= " WHERE fk_mailing = ".$mailing_id; |
262 | 262 | |
263 | - if (! $this->db->query($sql)) |
|
263 | + if (!$this->db->query($sql)) |
|
264 | 264 | { |
265 | 265 | dol_syslog($this->db->error()); |
266 | 266 | } |
@@ -67,11 +67,17 @@ discard block |
||
67 | 67 | $transstring="MailingModuleDesc".$this->name; |
68 | 68 | $s=''; |
69 | 69 | |
70 | - if ($langs->trans($this->name) != $this->name) $s=$langs->trans($this->name); |
|
71 | - elseif ($langs->trans($transstring) != $transstring) $s=$langs->trans($transstring); |
|
72 | - else $s=$this->desc; |
|
70 | + if ($langs->trans($this->name) != $this->name) { |
|
71 | + $s=$langs->trans($this->name); |
|
72 | + } elseif ($langs->trans($transstring) != $transstring) { |
|
73 | + $s=$langs->trans($transstring); |
|
74 | + } else { |
|
75 | + $s=$this->desc; |
|
76 | + } |
|
73 | 77 | |
74 | - if ($this->tooltip && is_object($form)) $s .= ' '.$form->textwithpicto('', $langs->trans($this->tooltip), 1, 1); |
|
78 | + if ($this->tooltip && is_object($form)) { |
|
79 | + $s .= ' '.$form->textwithpicto('', $langs->trans($this->tooltip), 1, 1); |
|
80 | + } |
|
75 | 81 | return $s; |
76 | 82 | } |
77 | 83 | |
@@ -98,8 +104,7 @@ discard block |
||
98 | 104 | { |
99 | 105 | $obj = $this->db->fetch_object($result); |
100 | 106 | return $obj->nb; |
101 | - } |
|
102 | - else |
|
107 | + } else |
|
103 | 108 | { |
104 | 109 | $this->error=$this->db->lasterror(); |
105 | 110 | return -1; |
@@ -144,8 +149,7 @@ discard block |
||
144 | 149 | $this->error=$this->db->error(); |
145 | 150 | return -1; |
146 | 151 | } |
147 | - } |
|
148 | - else { |
|
152 | + } else { |
|
149 | 153 | return -1; |
150 | 154 | } |
151 | 155 | return $nb; |
@@ -171,9 +175,11 @@ discard block |
||
171 | 175 | $num = count($cibles); |
172 | 176 | foreach ($cibles as $targetarray) |
173 | 177 | { |
174 | - if (! empty($targetarray['email'])) // avoid empty email address |
|
178 | + if (! empty($targetarray['email'])) { |
|
179 | + // avoid empty email address |
|
175 | 180 | { |
176 | 181 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_cibles"; |
182 | + } |
|
177 | 183 | $sql.= " (fk_mailing,"; |
178 | 184 | $sql.= " fk_contact,"; |
179 | 185 | $sql.= " lastname, firstname, email, other, source_url, source_id,"; |
@@ -194,8 +200,7 @@ discard block |
||
194 | 200 | if ($result) |
195 | 201 | { |
196 | 202 | $j++; |
197 | - } |
|
198 | - else |
|
203 | + } else |
|
199 | 204 | { |
200 | 205 | if ($this->db->errno() != 'DB_ERROR_RECORD_ALREADY_EXISTS') |
201 | 206 | { |
@@ -24,77 +24,77 @@ discard block |
||
24 | 24 | */ |
25 | 25 | class mailing_thirdparties extends MailingTargets |
26 | 26 | { |
27 | - var $name='ThirdPartiesByCategories'; |
|
28 | - // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
29 | - var $desc="Third parties (by categories)"; |
|
30 | - var $require_admin=0; |
|
27 | + var $name='ThirdPartiesByCategories'; |
|
28 | + // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
29 | + var $desc="Third parties (by categories)"; |
|
30 | + var $require_admin=0; |
|
31 | 31 | |
32 | - var $require_module=array("societe"); // This module allows to select by categories must be also enabled if category module is not activated |
|
33 | - var $picto='company'; |
|
32 | + var $require_module=array("societe"); // This module allows to select by categories must be also enabled if category module is not activated |
|
33 | + var $picto='company'; |
|
34 | 34 | |
35 | - /** |
|
35 | + /** |
|
36 | 36 | * @var DoliDB Database handler. |
37 | 37 | */ |
38 | 38 | public $db; |
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * Constructor |
|
43 | - * |
|
44 | - * @param DoliDB $db Database handler |
|
45 | - */ |
|
46 | - function __construct($db) |
|
47 | - { |
|
48 | - global $conf, $langs; |
|
41 | + /** |
|
42 | + * Constructor |
|
43 | + * |
|
44 | + * @param DoliDB $db Database handler |
|
45 | + */ |
|
46 | + function __construct($db) |
|
47 | + { |
|
48 | + global $conf, $langs; |
|
49 | 49 | $langs->load("companies"); |
50 | 50 | |
51 | - $this->db=$db; |
|
52 | - } |
|
51 | + $this->db=$db; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
56 | - /** |
|
57 | - * This is the main function that returns the array of emails |
|
58 | - * |
|
59 | - * @param int $mailing_id Id of mailing. No need to use it. |
|
60 | - * @return int <0 if error, number of emails added if ok |
|
61 | - */ |
|
62 | - function add_to_target($mailing_id) |
|
63 | - { |
|
56 | + /** |
|
57 | + * This is the main function that returns the array of emails |
|
58 | + * |
|
59 | + * @param int $mailing_id Id of mailing. No need to use it. |
|
60 | + * @return int <0 if error, number of emails added if ok |
|
61 | + */ |
|
62 | + function add_to_target($mailing_id) |
|
63 | + { |
|
64 | 64 | // phpcs:enable |
65 | - global $conf, $langs; |
|
66 | - |
|
67 | - $cibles = array(); |
|
68 | - |
|
69 | - // Select the third parties from category |
|
70 | - if (empty($_POST['filter'])) |
|
71 | - { |
|
72 | - $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, null as label"; |
|
73 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
74 | - $sql.= " WHERE s.email <> ''"; |
|
75 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
76 | - $sql.= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
77 | - } |
|
78 | - else |
|
79 | - { |
|
80 | - $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; |
|
81 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_societe as cs, ".MAIN_DB_PREFIX."categorie as c"; |
|
82 | - $sql.= " WHERE s.email <> ''"; |
|
83 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
84 | - $sql.= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
85 | - $sql.= " AND cs.fk_soc = s.rowid"; |
|
86 | - $sql.= " AND c.rowid = cs.fk_categorie"; |
|
87 | - $sql.= " AND c.rowid='".$this->db->escape($_POST['filter'])."'"; |
|
88 | - $sql.= " UNION "; |
|
89 | - $sql.= "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; |
|
90 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_fournisseur as cs, ".MAIN_DB_PREFIX."categorie as c"; |
|
91 | - $sql.= " WHERE s.email <> ''"; |
|
92 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
93 | - $sql.= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
94 | - $sql.= " AND cs.fk_soc = s.rowid"; |
|
95 | - $sql.= " AND c.rowid = cs.fk_categorie"; |
|
96 | - $sql.= " AND c.rowid='".$this->db->escape($_POST['filter'])."'"; |
|
97 | - } |
|
65 | + global $conf, $langs; |
|
66 | + |
|
67 | + $cibles = array(); |
|
68 | + |
|
69 | + // Select the third parties from category |
|
70 | + if (empty($_POST['filter'])) |
|
71 | + { |
|
72 | + $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, null as label"; |
|
73 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
74 | + $sql.= " WHERE s.email <> ''"; |
|
75 | + $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
76 | + $sql.= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
77 | + } |
|
78 | + else |
|
79 | + { |
|
80 | + $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; |
|
81 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_societe as cs, ".MAIN_DB_PREFIX."categorie as c"; |
|
82 | + $sql.= " WHERE s.email <> ''"; |
|
83 | + $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
84 | + $sql.= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
85 | + $sql.= " AND cs.fk_soc = s.rowid"; |
|
86 | + $sql.= " AND c.rowid = cs.fk_categorie"; |
|
87 | + $sql.= " AND c.rowid='".$this->db->escape($_POST['filter'])."'"; |
|
88 | + $sql.= " UNION "; |
|
89 | + $sql.= "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; |
|
90 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_fournisseur as cs, ".MAIN_DB_PREFIX."categorie as c"; |
|
91 | + $sql.= " WHERE s.email <> ''"; |
|
92 | + $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
93 | + $sql.= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
94 | + $sql.= " AND cs.fk_soc = s.rowid"; |
|
95 | + $sql.= " AND c.rowid = cs.fk_categorie"; |
|
96 | + $sql.= " AND c.rowid='".$this->db->escape($_POST['filter'])."'"; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | $addDescription= ""; |
100 | 100 | if (isset($_POST["filter_client"]) && $_POST["filter_client"] <> '-1') |
@@ -143,149 +143,149 @@ discard block |
||
143 | 143 | $sql.= " ORDER BY email"; |
144 | 144 | |
145 | 145 | // Stock recipients emails into targets table |
146 | - $result=$this->db->query($sql); |
|
147 | - if ($result) |
|
148 | - { |
|
149 | - $num = $this->db->num_rows($result); |
|
150 | - $i = 0; |
|
151 | - $j = 0; |
|
152 | - |
|
153 | - dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found"); |
|
154 | - |
|
155 | - $old = ''; |
|
156 | - while ($i < $num) |
|
157 | - { |
|
158 | - $obj = $this->db->fetch_object($result); |
|
159 | - if ($old <> $obj->email) |
|
160 | - { |
|
161 | - $otherTxt= ($obj->label?$langs->transnoentities("Category").'='.$obj->label:''); |
|
162 | - if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) |
|
163 | - { |
|
164 | - $otherTxt.= ";"; |
|
165 | - } |
|
166 | - $otherTxt.= $addDescription; |
|
167 | - $cibles[$j] = array( |
|
168 | - 'email' => $obj->email, |
|
169 | - 'fk_contact' => $obj->fk_contact, |
|
170 | - 'lastname' => $obj->name, // For a thirdparty, we must use name |
|
171 | - 'firstname' => '', // For a thirdparty, lastname is '' |
|
172 | - 'other' => $otherTxt, |
|
146 | + $result=$this->db->query($sql); |
|
147 | + if ($result) |
|
148 | + { |
|
149 | + $num = $this->db->num_rows($result); |
|
150 | + $i = 0; |
|
151 | + $j = 0; |
|
152 | + |
|
153 | + dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found"); |
|
154 | + |
|
155 | + $old = ''; |
|
156 | + while ($i < $num) |
|
157 | + { |
|
158 | + $obj = $this->db->fetch_object($result); |
|
159 | + if ($old <> $obj->email) |
|
160 | + { |
|
161 | + $otherTxt= ($obj->label?$langs->transnoentities("Category").'='.$obj->label:''); |
|
162 | + if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) |
|
163 | + { |
|
164 | + $otherTxt.= ";"; |
|
165 | + } |
|
166 | + $otherTxt.= $addDescription; |
|
167 | + $cibles[$j] = array( |
|
168 | + 'email' => $obj->email, |
|
169 | + 'fk_contact' => $obj->fk_contact, |
|
170 | + 'lastname' => $obj->name, // For a thirdparty, we must use name |
|
171 | + 'firstname' => '', // For a thirdparty, lastname is '' |
|
172 | + 'other' => $otherTxt, |
|
173 | 173 | 'source_url' => $this->url($obj->id), |
174 | 174 | 'source_id' => $obj->id, |
175 | 175 | 'source_type' => 'thirdparty' |
176 | - ); |
|
177 | - $old = $obj->email; |
|
178 | - $j++; |
|
179 | - } |
|
176 | + ); |
|
177 | + $old = $obj->email; |
|
178 | + $j++; |
|
179 | + } |
|
180 | + |
|
181 | + $i++; |
|
182 | + } |
|
183 | + } |
|
184 | + else |
|
185 | + { |
|
186 | + dol_syslog($this->db->error()); |
|
187 | + $this->error=$this->db->error(); |
|
188 | + return -1; |
|
189 | + } |
|
190 | + |
|
191 | + return parent::add_to_target($mailing_id, $cibles); |
|
192 | + } |
|
193 | + |
|
180 | 194 | |
181 | - $i++; |
|
182 | - } |
|
183 | - } |
|
184 | - else |
|
185 | - { |
|
186 | - dol_syslog($this->db->error()); |
|
187 | - $this->error=$this->db->error(); |
|
188 | - return -1; |
|
189 | - } |
|
195 | + /** |
|
196 | + * On the main mailing area, there is a box with statistics. |
|
197 | + * If you want to add a line in this report you must provide an |
|
198 | + * array of SQL request that returns two field: |
|
199 | + * One called "label", One called "nb". |
|
200 | + * |
|
201 | + * @return array Array with SQL requests |
|
202 | + */ |
|
203 | + function getSqlArrayForStats() |
|
204 | + { |
|
205 | + // CHANGE THIS: Optionnal |
|
206 | + |
|
207 | + //var $statssql=array(); |
|
208 | + //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL"; |
|
209 | + return array(); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Return here number of distinct emails returned by your selector. |
|
215 | + * For example if this selector is used to extract 500 different |
|
216 | + * emails from a text file, this function must return 500. |
|
217 | + * |
|
218 | + * @param string $sql Requete sql de comptage |
|
219 | + * @return int Nb of recipients |
|
220 | + */ |
|
221 | + function getNbOfRecipients($sql='') |
|
222 | + { |
|
223 | + global $conf; |
|
190 | 224 | |
191 | - return parent::add_to_target($mailing_id, $cibles); |
|
192 | - } |
|
225 | + $sql = "SELECT count(distinct(s.email)) as nb"; |
|
226 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
227 | + $sql.= " WHERE s.email != ''"; |
|
228 | + $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
193 | 229 | |
230 | + // La requete doit retourner un champ "nb" pour etre comprise |
|
231 | + // par parent::getNbOfRecipients |
|
232 | + return parent::getNbOfRecipients($sql); |
|
233 | + } |
|
194 | 234 | |
195 | 235 | /** |
196 | - * On the main mailing area, there is a box with statistics. |
|
197 | - * If you want to add a line in this report you must provide an |
|
198 | - * array of SQL request that returns two field: |
|
199 | - * One called "label", One called "nb". |
|
200 | - * |
|
201 | - * @return array Array with SQL requests |
|
202 | - */ |
|
203 | - function getSqlArrayForStats() |
|
204 | - { |
|
205 | - // CHANGE THIS: Optionnal |
|
206 | - |
|
207 | - //var $statssql=array(); |
|
208 | - //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL"; |
|
209 | - return array(); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Return here number of distinct emails returned by your selector. |
|
215 | - * For example if this selector is used to extract 500 different |
|
216 | - * emails from a text file, this function must return 500. |
|
217 | - * |
|
218 | - * @param string $sql Requete sql de comptage |
|
219 | - * @return int Nb of recipients |
|
220 | - */ |
|
221 | - function getNbOfRecipients($sql='') |
|
222 | - { |
|
223 | - global $conf; |
|
224 | - |
|
225 | - $sql = "SELECT count(distinct(s.email)) as nb"; |
|
226 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
227 | - $sql.= " WHERE s.email != ''"; |
|
228 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
229 | - |
|
230 | - // La requete doit retourner un champ "nb" pour etre comprise |
|
231 | - // par parent::getNbOfRecipients |
|
232 | - return parent::getNbOfRecipients($sql); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * This is to add a form filter to provide variant of selector |
|
237 | - * If used, the HTML select must be called "filter" |
|
238 | - * |
|
239 | - * @return string A html select zone |
|
240 | - */ |
|
241 | - function formFilter() |
|
242 | - { |
|
243 | - global $conf, $langs; |
|
244 | - |
|
245 | - $langs->load("companies"); |
|
246 | - |
|
247 | - $s=$langs->trans("Categories").': '; |
|
248 | - $s.='<select name="filter" class="flat">'; |
|
249 | - |
|
250 | - // Show categories |
|
251 | - $sql = "SELECT rowid, label, type, visible"; |
|
252 | - $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; |
|
253 | - $sql.= " WHERE type in (1,2)"; // We keep only categories for suppliers and customers/prospects |
|
254 | - // $sql.= " AND visible > 0"; // We ignore the property visible because third party's categories does not use this property (only products categories use it). |
|
255 | - $sql.= " AND entity = ".$conf->entity; |
|
256 | - $sql.= " ORDER BY label"; |
|
257 | - |
|
258 | - //print $sql; |
|
259 | - $resql = $this->db->query($sql); |
|
260 | - if ($resql) |
|
261 | - { |
|
262 | - $num = $this->db->num_rows($resql); |
|
263 | - |
|
264 | - if (empty($conf->categorie->enabled)) $num=0; // Force empty list if category module is not enabled |
|
265 | - |
|
266 | - if ($num) $s.='<option value="0"> </option>'; |
|
267 | - else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
268 | - |
|
269 | - $i = 0; |
|
270 | - while ($i < $num) |
|
271 | - { |
|
272 | - $obj = $this->db->fetch_object($resql); |
|
273 | - |
|
274 | - $type=''; |
|
275 | - if ($obj->type == 1) $type=$langs->trans("Supplier"); |
|
276 | - if ($obj->type == 2) $type=$langs->trans("Customer"); |
|
277 | - $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle'); |
|
278 | - if ($type) $s.=' ('.$type.')'; |
|
279 | - $s.='</option>'; |
|
280 | - $i++; |
|
281 | - } |
|
282 | - } |
|
283 | - else |
|
284 | - { |
|
285 | - dol_print_error($this->db); |
|
286 | - } |
|
287 | - |
|
288 | - $s.='</select> '; |
|
236 | + * This is to add a form filter to provide variant of selector |
|
237 | + * If used, the HTML select must be called "filter" |
|
238 | + * |
|
239 | + * @return string A html select zone |
|
240 | + */ |
|
241 | + function formFilter() |
|
242 | + { |
|
243 | + global $conf, $langs; |
|
244 | + |
|
245 | + $langs->load("companies"); |
|
246 | + |
|
247 | + $s=$langs->trans("Categories").': '; |
|
248 | + $s.='<select name="filter" class="flat">'; |
|
249 | + |
|
250 | + // Show categories |
|
251 | + $sql = "SELECT rowid, label, type, visible"; |
|
252 | + $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; |
|
253 | + $sql.= " WHERE type in (1,2)"; // We keep only categories for suppliers and customers/prospects |
|
254 | + // $sql.= " AND visible > 0"; // We ignore the property visible because third party's categories does not use this property (only products categories use it). |
|
255 | + $sql.= " AND entity = ".$conf->entity; |
|
256 | + $sql.= " ORDER BY label"; |
|
257 | + |
|
258 | + //print $sql; |
|
259 | + $resql = $this->db->query($sql); |
|
260 | + if ($resql) |
|
261 | + { |
|
262 | + $num = $this->db->num_rows($resql); |
|
263 | + |
|
264 | + if (empty($conf->categorie->enabled)) $num=0; // Force empty list if category module is not enabled |
|
265 | + |
|
266 | + if ($num) $s.='<option value="0"> </option>'; |
|
267 | + else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
268 | + |
|
269 | + $i = 0; |
|
270 | + while ($i < $num) |
|
271 | + { |
|
272 | + $obj = $this->db->fetch_object($resql); |
|
273 | + |
|
274 | + $type=''; |
|
275 | + if ($obj->type == 1) $type=$langs->trans("Supplier"); |
|
276 | + if ($obj->type == 2) $type=$langs->trans("Customer"); |
|
277 | + $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle'); |
|
278 | + if ($type) $s.=' ('.$type.')'; |
|
279 | + $s.='</option>'; |
|
280 | + $i++; |
|
281 | + } |
|
282 | + } |
|
283 | + else |
|
284 | + { |
|
285 | + dol_print_error($this->db); |
|
286 | + } |
|
287 | + |
|
288 | + $s.='</select> '; |
|
289 | 289 | $s.= $langs->trans('ProspectCustomer'); |
290 | 290 | $s.=': <select name="filter_client" class="flat">'; |
291 | 291 | $s.= '<option value="-1"> </option>'; |
@@ -308,19 +308,19 @@ discard block |
||
308 | 308 | $s.='<option value="-1"> </option>'; |
309 | 309 | $s.='<option value="1" selected>'.$langs->trans("Enabled").'</option>'; |
310 | 310 | $s.='<option value="0">'.$langs->trans("Disabled").'</option>'; |
311 | - $s.='</select>'; |
|
312 | - return $s; |
|
313 | - } |
|
311 | + $s.='</select>'; |
|
312 | + return $s; |
|
313 | + } |
|
314 | 314 | |
315 | 315 | |
316 | 316 | /** |
317 | - * Can include an URL link on each record provided by selector shown on target page. |
|
318 | - * |
|
317 | + * Can include an URL link on each record provided by selector shown on target page. |
|
318 | + * |
|
319 | 319 | * @param int $id ID |
320 | - * @return string Url link |
|
321 | - */ |
|
322 | - function url($id) |
|
323 | - { |
|
324 | - return '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$id.'">'.img_object('',"company").'</a>'; |
|
325 | - } |
|
320 | + * @return string Url link |
|
321 | + */ |
|
322 | + function url($id) |
|
323 | + { |
|
324 | + return '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$id.'">'.img_object('',"company").'</a>'; |
|
325 | + } |
|
326 | 326 | } |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | */ |
25 | 25 | class mailing_thirdparties extends MailingTargets |
26 | 26 | { |
27 | - var $name='ThirdPartiesByCategories'; |
|
27 | + var $name = 'ThirdPartiesByCategories'; |
|
28 | 28 | // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
29 | - var $desc="Third parties (by categories)"; |
|
30 | - var $require_admin=0; |
|
29 | + var $desc = "Third parties (by categories)"; |
|
30 | + var $require_admin = 0; |
|
31 | 31 | |
32 | - var $require_module=array("societe"); // This module allows to select by categories must be also enabled if category module is not activated |
|
33 | - var $picto='company'; |
|
32 | + var $require_module = array("societe"); // This module allows to select by categories must be also enabled if category module is not activated |
|
33 | + var $picto = 'company'; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * @var DoliDB Database handler. |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | global $conf, $langs; |
49 | 49 | $langs->load("companies"); |
50 | 50 | |
51 | - $this->db=$db; |
|
51 | + $this->db = $db; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | |
@@ -70,80 +70,80 @@ discard block |
||
70 | 70 | if (empty($_POST['filter'])) |
71 | 71 | { |
72 | 72 | $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, null as label"; |
73 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
74 | - $sql.= " WHERE s.email <> ''"; |
|
75 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
76 | - $sql.= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
73 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
74 | + $sql .= " WHERE s.email <> ''"; |
|
75 | + $sql .= " AND s.entity IN (".getEntity('societe').")"; |
|
76 | + $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
77 | 77 | } |
78 | 78 | else |
79 | 79 | { |
80 | 80 | $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; |
81 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_societe as cs, ".MAIN_DB_PREFIX."categorie as c"; |
|
82 | - $sql.= " WHERE s.email <> ''"; |
|
83 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
84 | - $sql.= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
85 | - $sql.= " AND cs.fk_soc = s.rowid"; |
|
86 | - $sql.= " AND c.rowid = cs.fk_categorie"; |
|
87 | - $sql.= " AND c.rowid='".$this->db->escape($_POST['filter'])."'"; |
|
88 | - $sql.= " UNION "; |
|
89 | - $sql.= "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; |
|
90 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_fournisseur as cs, ".MAIN_DB_PREFIX."categorie as c"; |
|
91 | - $sql.= " WHERE s.email <> ''"; |
|
92 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
93 | - $sql.= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
94 | - $sql.= " AND cs.fk_soc = s.rowid"; |
|
95 | - $sql.= " AND c.rowid = cs.fk_categorie"; |
|
96 | - $sql.= " AND c.rowid='".$this->db->escape($_POST['filter'])."'"; |
|
81 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_societe as cs, ".MAIN_DB_PREFIX."categorie as c"; |
|
82 | + $sql .= " WHERE s.email <> ''"; |
|
83 | + $sql .= " AND s.entity IN (".getEntity('societe').")"; |
|
84 | + $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
85 | + $sql .= " AND cs.fk_soc = s.rowid"; |
|
86 | + $sql .= " AND c.rowid = cs.fk_categorie"; |
|
87 | + $sql .= " AND c.rowid='".$this->db->escape($_POST['filter'])."'"; |
|
88 | + $sql .= " UNION "; |
|
89 | + $sql .= "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; |
|
90 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_fournisseur as cs, ".MAIN_DB_PREFIX."categorie as c"; |
|
91 | + $sql .= " WHERE s.email <> ''"; |
|
92 | + $sql .= " AND s.entity IN (".getEntity('societe').")"; |
|
93 | + $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
94 | + $sql .= " AND cs.fk_soc = s.rowid"; |
|
95 | + $sql .= " AND c.rowid = cs.fk_categorie"; |
|
96 | + $sql .= " AND c.rowid='".$this->db->escape($_POST['filter'])."'"; |
|
97 | 97 | } |
98 | 98 | |
99 | - $addDescription= ""; |
|
99 | + $addDescription = ""; |
|
100 | 100 | if (isset($_POST["filter_client"]) && $_POST["filter_client"] <> '-1') |
101 | 101 | { |
102 | - $sql.= " AND s.client=" . $_POST["filter_client"]; |
|
103 | - $addDescription= $langs->trans('ProspectCustomer')."="; |
|
102 | + $sql .= " AND s.client=".$_POST["filter_client"]; |
|
103 | + $addDescription = $langs->trans('ProspectCustomer')."="; |
|
104 | 104 | if ($_POST["filter_client"] == 0) |
105 | 105 | { |
106 | - $addDescription.= $langs->trans('NorProspectNorCustomer'); |
|
106 | + $addDescription .= $langs->trans('NorProspectNorCustomer'); |
|
107 | 107 | } |
108 | 108 | elseif ($_POST["filter_client"] == 1) |
109 | 109 | { |
110 | - $addDescription.= $langs->trans('Customer'); |
|
110 | + $addDescription .= $langs->trans('Customer'); |
|
111 | 111 | } |
112 | 112 | elseif ($_POST["filter_client"] == 2) |
113 | 113 | { |
114 | - $addDescription.= $langs->trans('Prospect'); |
|
114 | + $addDescription .= $langs->trans('Prospect'); |
|
115 | 115 | } |
116 | 116 | elseif ($_POST["filter_client"] == 3) |
117 | 117 | { |
118 | - $addDescription.= $langs->trans('ProspectCustomer'); |
|
118 | + $addDescription .= $langs->trans('ProspectCustomer'); |
|
119 | 119 | } |
120 | 120 | else |
121 | 121 | { |
122 | - $addDescription.= "Unknown status ".$_POST["filter_client"]; |
|
122 | + $addDescription .= "Unknown status ".$_POST["filter_client"]; |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | if (isset($_POST["filter_status"])) |
126 | 126 | { |
127 | 127 | if (strlen($addDescription) > 0) |
128 | 128 | { |
129 | - $addDescription.= ";"; |
|
129 | + $addDescription .= ";"; |
|
130 | 130 | } |
131 | - $addDescription.= $langs->trans("Status")."="; |
|
131 | + $addDescription .= $langs->trans("Status")."="; |
|
132 | 132 | if ($_POST["filter_status"] == '1') |
133 | 133 | { |
134 | - $sql.= " AND s.status=1"; |
|
135 | - $addDescription.= $langs->trans("Enabled"); |
|
134 | + $sql .= " AND s.status=1"; |
|
135 | + $addDescription .= $langs->trans("Enabled"); |
|
136 | 136 | } |
137 | 137 | else |
138 | 138 | { |
139 | - $sql.= " AND s.status=0"; |
|
140 | - $addDescription.= $langs->trans("Disabled"); |
|
139 | + $sql .= " AND s.status=0"; |
|
140 | + $addDescription .= $langs->trans("Disabled"); |
|
141 | 141 | } |
142 | 142 | } |
143 | - $sql.= " ORDER BY email"; |
|
143 | + $sql .= " ORDER BY email"; |
|
144 | 144 | |
145 | 145 | // Stock recipients emails into targets table |
146 | - $result=$this->db->query($sql); |
|
146 | + $result = $this->db->query($sql); |
|
147 | 147 | if ($result) |
148 | 148 | { |
149 | 149 | $num = $this->db->num_rows($result); |
@@ -158,17 +158,17 @@ discard block |
||
158 | 158 | $obj = $this->db->fetch_object($result); |
159 | 159 | if ($old <> $obj->email) |
160 | 160 | { |
161 | - $otherTxt= ($obj->label?$langs->transnoentities("Category").'='.$obj->label:''); |
|
161 | + $otherTxt = ($obj->label ? $langs->transnoentities("Category").'='.$obj->label : ''); |
|
162 | 162 | if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) |
163 | 163 | { |
164 | - $otherTxt.= ";"; |
|
164 | + $otherTxt .= ";"; |
|
165 | 165 | } |
166 | - $otherTxt.= $addDescription; |
|
166 | + $otherTxt .= $addDescription; |
|
167 | 167 | $cibles[$j] = array( |
168 | 168 | 'email' => $obj->email, |
169 | 169 | 'fk_contact' => $obj->fk_contact, |
170 | - 'lastname' => $obj->name, // For a thirdparty, we must use name |
|
171 | - 'firstname' => '', // For a thirdparty, lastname is '' |
|
170 | + 'lastname' => $obj->name, // For a thirdparty, we must use name |
|
171 | + 'firstname' => '', // For a thirdparty, lastname is '' |
|
172 | 172 | 'other' => $otherTxt, |
173 | 173 | 'source_url' => $this->url($obj->id), |
174 | 174 | 'source_id' => $obj->id, |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | else |
185 | 185 | { |
186 | 186 | dol_syslog($this->db->error()); |
187 | - $this->error=$this->db->error(); |
|
187 | + $this->error = $this->db->error(); |
|
188 | 188 | return -1; |
189 | 189 | } |
190 | 190 | |
@@ -218,14 +218,14 @@ discard block |
||
218 | 218 | * @param string $sql Requete sql de comptage |
219 | 219 | * @return int Nb of recipients |
220 | 220 | */ |
221 | - function getNbOfRecipients($sql='') |
|
221 | + function getNbOfRecipients($sql = '') |
|
222 | 222 | { |
223 | 223 | global $conf; |
224 | 224 | |
225 | 225 | $sql = "SELECT count(distinct(s.email)) as nb"; |
226 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
227 | - $sql.= " WHERE s.email != ''"; |
|
228 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
226 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
227 | + $sql .= " WHERE s.email != ''"; |
|
228 | + $sql .= " AND s.entity IN (".getEntity('societe').")"; |
|
229 | 229 | |
230 | 230 | // La requete doit retourner un champ "nb" pour etre comprise |
231 | 231 | // par parent::getNbOfRecipients |
@@ -244,16 +244,16 @@ discard block |
||
244 | 244 | |
245 | 245 | $langs->load("companies"); |
246 | 246 | |
247 | - $s=$langs->trans("Categories").': '; |
|
248 | - $s.='<select name="filter" class="flat">'; |
|
247 | + $s = $langs->trans("Categories").': '; |
|
248 | + $s .= '<select name="filter" class="flat">'; |
|
249 | 249 | |
250 | 250 | // Show categories |
251 | 251 | $sql = "SELECT rowid, label, type, visible"; |
252 | - $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; |
|
253 | - $sql.= " WHERE type in (1,2)"; // We keep only categories for suppliers and customers/prospects |
|
252 | + $sql .= " FROM ".MAIN_DB_PREFIX."categorie"; |
|
253 | + $sql .= " WHERE type in (1,2)"; // We keep only categories for suppliers and customers/prospects |
|
254 | 254 | // $sql.= " AND visible > 0"; // We ignore the property visible because third party's categories does not use this property (only products categories use it). |
255 | - $sql.= " AND entity = ".$conf->entity; |
|
256 | - $sql.= " ORDER BY label"; |
|
255 | + $sql .= " AND entity = ".$conf->entity; |
|
256 | + $sql .= " ORDER BY label"; |
|
257 | 257 | |
258 | 258 | //print $sql; |
259 | 259 | $resql = $this->db->query($sql); |
@@ -261,22 +261,22 @@ discard block |
||
261 | 261 | { |
262 | 262 | $num = $this->db->num_rows($resql); |
263 | 263 | |
264 | - if (empty($conf->categorie->enabled)) $num=0; // Force empty list if category module is not enabled |
|
264 | + if (empty($conf->categorie->enabled)) $num = 0; // Force empty list if category module is not enabled |
|
265 | 265 | |
266 | - if ($num) $s.='<option value="0"> </option>'; |
|
267 | - else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
266 | + if ($num) $s .= '<option value="0"> </option>'; |
|
267 | + else $s .= '<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
268 | 268 | |
269 | 269 | $i = 0; |
270 | 270 | while ($i < $num) |
271 | 271 | { |
272 | 272 | $obj = $this->db->fetch_object($resql); |
273 | 273 | |
274 | - $type=''; |
|
275 | - if ($obj->type == 1) $type=$langs->trans("Supplier"); |
|
276 | - if ($obj->type == 2) $type=$langs->trans("Customer"); |
|
277 | - $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle'); |
|
278 | - if ($type) $s.=' ('.$type.')'; |
|
279 | - $s.='</option>'; |
|
274 | + $type = ''; |
|
275 | + if ($obj->type == 1) $type = $langs->trans("Supplier"); |
|
276 | + if ($obj->type == 2) $type = $langs->trans("Customer"); |
|
277 | + $s .= '<option value="'.$obj->rowid.'">'.dol_trunc($obj->label, 38, 'middle'); |
|
278 | + if ($type) $s .= ' ('.$type.')'; |
|
279 | + $s .= '</option>'; |
|
280 | 280 | $i++; |
281 | 281 | } |
282 | 282 | } |
@@ -285,30 +285,30 @@ discard block |
||
285 | 285 | dol_print_error($this->db); |
286 | 286 | } |
287 | 287 | |
288 | - $s.='</select> '; |
|
289 | - $s.= $langs->trans('ProspectCustomer'); |
|
290 | - $s.=': <select name="filter_client" class="flat">'; |
|
291 | - $s.= '<option value="-1"> </option>'; |
|
288 | + $s .= '</select> '; |
|
289 | + $s .= $langs->trans('ProspectCustomer'); |
|
290 | + $s .= ': <select name="filter_client" class="flat">'; |
|
291 | + $s .= '<option value="-1"> </option>'; |
|
292 | 292 | if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) |
293 | 293 | { |
294 | - $s.= '<option value="2">'.$langs->trans('Prospect').'</option>'; |
|
294 | + $s .= '<option value="2">'.$langs->trans('Prospect').'</option>'; |
|
295 | 295 | } |
296 | 296 | if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) { |
297 | - $s.= '<option value="3">'.$langs->trans('ProspectCustomer').'</option>'; |
|
297 | + $s .= '<option value="3">'.$langs->trans('ProspectCustomer').'</option>'; |
|
298 | 298 | } |
299 | 299 | if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) { |
300 | - $s.= '<option value="1">'.$langs->trans('Customer').'</option>'; |
|
300 | + $s .= '<option value="1">'.$langs->trans('Customer').'</option>'; |
|
301 | 301 | } |
302 | - $s.= '<option value="0">'.$langs->trans('NorProspectNorCustomer').'</option>'; |
|
302 | + $s .= '<option value="0">'.$langs->trans('NorProspectNorCustomer').'</option>'; |
|
303 | 303 | |
304 | - $s.='</select> '; |
|
304 | + $s .= '</select> '; |
|
305 | 305 | |
306 | - $s.=$langs->trans("Status"); |
|
307 | - $s.=': <select name="filter_status" class="flat">'; |
|
308 | - $s.='<option value="-1"> </option>'; |
|
309 | - $s.='<option value="1" selected>'.$langs->trans("Enabled").'</option>'; |
|
310 | - $s.='<option value="0">'.$langs->trans("Disabled").'</option>'; |
|
311 | - $s.='</select>'; |
|
306 | + $s .= $langs->trans("Status"); |
|
307 | + $s .= ': <select name="filter_status" class="flat">'; |
|
308 | + $s .= '<option value="-1"> </option>'; |
|
309 | + $s .= '<option value="1" selected>'.$langs->trans("Enabled").'</option>'; |
|
310 | + $s .= '<option value="0">'.$langs->trans("Disabled").'</option>'; |
|
311 | + $s .= '</select>'; |
|
312 | 312 | return $s; |
313 | 313 | } |
314 | 314 | |
@@ -321,6 +321,6 @@ discard block |
||
321 | 321 | */ |
322 | 322 | function url($id) |
323 | 323 | { |
324 | - return '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$id.'">'.img_object('',"company").'</a>'; |
|
324 | + return '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$id.'">'.img_object('', "company").'</a>'; |
|
325 | 325 | } |
326 | 326 | } |
@@ -74,8 +74,7 @@ discard block |
||
74 | 74 | $sql.= " WHERE s.email <> ''"; |
75 | 75 | $sql.= " AND s.entity IN (".getEntity('societe').")"; |
76 | 76 | $sql.= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
77 | - } |
|
78 | - else |
|
77 | + } else |
|
79 | 78 | { |
80 | 79 | $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label"; |
81 | 80 | $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."categorie_societe as cs, ".MAIN_DB_PREFIX."categorie as c"; |
@@ -104,20 +103,16 @@ discard block |
||
104 | 103 | if ($_POST["filter_client"] == 0) |
105 | 104 | { |
106 | 105 | $addDescription.= $langs->trans('NorProspectNorCustomer'); |
107 | - } |
|
108 | - elseif ($_POST["filter_client"] == 1) |
|
106 | + } elseif ($_POST["filter_client"] == 1) |
|
109 | 107 | { |
110 | 108 | $addDescription.= $langs->trans('Customer'); |
111 | - } |
|
112 | - elseif ($_POST["filter_client"] == 2) |
|
109 | + } elseif ($_POST["filter_client"] == 2) |
|
113 | 110 | { |
114 | 111 | $addDescription.= $langs->trans('Prospect'); |
115 | - } |
|
116 | - elseif ($_POST["filter_client"] == 3) |
|
112 | + } elseif ($_POST["filter_client"] == 3) |
|
117 | 113 | { |
118 | 114 | $addDescription.= $langs->trans('ProspectCustomer'); |
119 | - } |
|
120 | - else |
|
115 | + } else |
|
121 | 116 | { |
122 | 117 | $addDescription.= "Unknown status ".$_POST["filter_client"]; |
123 | 118 | } |
@@ -133,8 +128,7 @@ discard block |
||
133 | 128 | { |
134 | 129 | $sql.= " AND s.status=1"; |
135 | 130 | $addDescription.= $langs->trans("Enabled"); |
136 | - } |
|
137 | - else |
|
131 | + } else |
|
138 | 132 | { |
139 | 133 | $sql.= " AND s.status=0"; |
140 | 134 | $addDescription.= $langs->trans("Disabled"); |
@@ -180,8 +174,7 @@ discard block |
||
180 | 174 | |
181 | 175 | $i++; |
182 | 176 | } |
183 | - } |
|
184 | - else |
|
177 | + } else |
|
185 | 178 | { |
186 | 179 | dol_syslog($this->db->error()); |
187 | 180 | $this->error=$this->db->error(); |
@@ -261,10 +254,16 @@ discard block |
||
261 | 254 | { |
262 | 255 | $num = $this->db->num_rows($resql); |
263 | 256 | |
264 | - if (empty($conf->categorie->enabled)) $num=0; // Force empty list if category module is not enabled |
|
257 | + if (empty($conf->categorie->enabled)) { |
|
258 | + $num=0; |
|
259 | + } |
|
260 | + // Force empty list if category module is not enabled |
|
265 | 261 | |
266 | - if ($num) $s.='<option value="0"> </option>'; |
|
267 | - else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
262 | + if ($num) { |
|
263 | + $s.='<option value="0"> </option>'; |
|
264 | + } else { |
|
265 | + $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
266 | + } |
|
268 | 267 | |
269 | 268 | $i = 0; |
270 | 269 | while ($i < $num) |
@@ -272,15 +271,20 @@ discard block |
||
272 | 271 | $obj = $this->db->fetch_object($resql); |
273 | 272 | |
274 | 273 | $type=''; |
275 | - if ($obj->type == 1) $type=$langs->trans("Supplier"); |
|
276 | - if ($obj->type == 2) $type=$langs->trans("Customer"); |
|
274 | + if ($obj->type == 1) { |
|
275 | + $type=$langs->trans("Supplier"); |
|
276 | + } |
|
277 | + if ($obj->type == 2) { |
|
278 | + $type=$langs->trans("Customer"); |
|
279 | + } |
|
277 | 280 | $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle'); |
278 | - if ($type) $s.=' ('.$type.')'; |
|
281 | + if ($type) { |
|
282 | + $s.=' ('.$type.')'; |
|
283 | + } |
|
279 | 284 | $s.='</option>'; |
280 | 285 | $i++; |
281 | 286 | } |
282 | - } |
|
283 | - else |
|
287 | + } else |
|
284 | 288 | { |
285 | 289 | dol_print_error($this->db); |
286 | 290 | } |
@@ -25,278 +25,278 @@ |
||
25 | 25 | */ |
26 | 26 | class mailing_advthirdparties extends MailingTargets |
27 | 27 | { |
28 | - var $name='ThirdPartyAdvancedTargeting'; |
|
29 | - // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
30 | - var $desc="Third parties"; |
|
31 | - var $require_admin=0; |
|
28 | + var $name='ThirdPartyAdvancedTargeting'; |
|
29 | + // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
30 | + var $desc="Third parties"; |
|
31 | + var $require_admin=0; |
|
32 | 32 | |
33 | - var $require_module=array("none"); // This module should not be displayed as Selector in mailling |
|
34 | - var $picto='company'; |
|
33 | + var $require_module=array("none"); // This module should not be displayed as Selector in mailling |
|
34 | + var $picto='company'; |
|
35 | 35 | |
36 | - /** |
|
36 | + /** |
|
37 | 37 | * @var DoliDB Database handler. |
38 | 38 | */ |
39 | 39 | public $db; |
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Constructor |
|
44 | - * |
|
45 | - * @param DoliDB $db Database handler |
|
46 | - */ |
|
47 | - function __construct($db) |
|
48 | - { |
|
49 | - $this->db=$db; |
|
50 | - } |
|
42 | + /** |
|
43 | + * Constructor |
|
44 | + * |
|
45 | + * @param DoliDB $db Database handler |
|
46 | + */ |
|
47 | + function __construct($db) |
|
48 | + { |
|
49 | + $this->db=$db; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | 53 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
54 | - /** |
|
55 | - * This is the main function that returns the array of emails |
|
56 | - * |
|
57 | - * @param int $mailing_id Id of mailing. No need to use it. |
|
58 | - * @param array $socid Array of id soc to add |
|
59 | - * @param int $type_of_target Defined in advtargetemailing.class.php |
|
60 | - * @param array $contactid Array of contact id to add |
|
61 | - * @return int <0 if error, number of emails added if ok |
|
62 | - */ |
|
63 | - function add_to_target_spec($mailing_id,$socid,$type_of_target, $contactid) |
|
64 | - { |
|
54 | + /** |
|
55 | + * This is the main function that returns the array of emails |
|
56 | + * |
|
57 | + * @param int $mailing_id Id of mailing. No need to use it. |
|
58 | + * @param array $socid Array of id soc to add |
|
59 | + * @param int $type_of_target Defined in advtargetemailing.class.php |
|
60 | + * @param array $contactid Array of contact id to add |
|
61 | + * @return int <0 if error, number of emails added if ok |
|
62 | + */ |
|
63 | + function add_to_target_spec($mailing_id,$socid,$type_of_target, $contactid) |
|
64 | + { |
|
65 | 65 | // phpcs:enable |
66 | - global $conf, $langs; |
|
67 | - |
|
68 | - dol_syslog(get_class($this)."::add_to_target socid=".var_export($socid,true).' contactid='.var_export($contactid,true)); |
|
69 | - |
|
70 | - $cibles = array(); |
|
71 | - |
|
72 | - if (($type_of_target==1) || ($type_of_target==3)) { |
|
73 | - // Select the third parties from category |
|
74 | - if (count($socid)>0) |
|
75 | - { |
|
76 | - $sql= "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact"; |
|
77 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s LEFT OUTER JOIN ".MAIN_DB_PREFIX."societe_extrafields se ON se.fk_object=s.rowid"; |
|
78 | - $sql.= " WHERE s.entity IN (".getEntity('societe').")"; |
|
79 | - $sql.= " AND s.rowid IN (".implode(',',$socid).")"; |
|
80 | - $sql.= " ORDER BY email"; |
|
81 | - |
|
82 | - // Stock recipients emails into targets table |
|
83 | - $result=$this->db->query($sql); |
|
84 | - if ($result) |
|
85 | - { |
|
86 | - $num = $this->db->num_rows($result); |
|
87 | - $i = 0; |
|
88 | - |
|
89 | - dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found", LOG_DEBUG); |
|
90 | - |
|
91 | - $old = ''; |
|
92 | - while ($i < $num) |
|
93 | - { |
|
94 | - $obj = $this->db->fetch_object($result); |
|
95 | - |
|
96 | - if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) { |
|
97 | - if (!array_key_exists($obj->email, $cibles)) { |
|
98 | - $cibles[$obj->email] = array( |
|
99 | - 'email' => $obj->email, |
|
100 | - 'fk_contact' => $obj->fk_contact, |
|
101 | - 'name' => $obj->name, |
|
102 | - 'firstname' => $obj->firstname, |
|
103 | - 'other' => '', |
|
104 | - 'source_url' => $this->url($obj->id,'thirdparty'), |
|
105 | - 'source_id' => $obj->id, |
|
106 | - 'source_type' => 'thirdparty' |
|
107 | - ); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - $i++; |
|
112 | - } |
|
113 | - } |
|
114 | - else |
|
115 | - { |
|
116 | - dol_syslog($this->db->error()); |
|
117 | - $this->error=$this->db->error(); |
|
118 | - return -1; |
|
119 | - } |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - if (($type_of_target==1) || ($type_of_target==2) || ($type_of_target==4)) { |
|
124 | - // Select the third parties from category |
|
125 | - if (count($socid)>0 || count($contactid)>0) |
|
126 | - { |
|
127 | - $sql= "SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname"; |
|
128 | - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as socp"; |
|
129 | - $sql.= " WHERE socp.entity IN (".getEntity('socpeople').")"; |
|
130 | - if (count($contactid)>0) { |
|
131 | - $sql.= " AND socp.rowid IN (".implode(',',$contactid).")"; |
|
132 | - } |
|
133 | - if (count($socid)>0) { |
|
134 | - $sql.= " AND socp.fk_soc IN (".implode(',',$socid).")"; |
|
135 | - } |
|
136 | - $sql.= " ORDER BY email"; |
|
137 | - |
|
138 | - // Stock recipients emails into targets table |
|
139 | - $result=$this->db->query($sql); |
|
140 | - if ($result) |
|
141 | - { |
|
142 | - $num = $this->db->num_rows($result); |
|
143 | - $i = 0; |
|
144 | - |
|
145 | - dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found"); |
|
146 | - |
|
147 | - $old = ''; |
|
148 | - while ($i < $num) |
|
149 | - { |
|
150 | - $obj = $this->db->fetch_object($result); |
|
151 | - |
|
152 | - if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) { |
|
153 | - if (!array_key_exists($obj->email, $cibles)) { |
|
154 | - $cibles[$obj->email] = array( |
|
155 | - 'email' => $obj->email, |
|
156 | - 'fk_contact' =>$obj->id, |
|
157 | - 'lastname' => $obj->lastname, |
|
158 | - 'firstname' => $obj->firstname, |
|
159 | - 'other' => '', |
|
160 | - 'source_url' => $this->url($obj->id,'contact'), |
|
161 | - 'source_id' => $obj->id, |
|
162 | - 'source_type' => 'contact' |
|
163 | - ); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - $i++; |
|
168 | - } |
|
169 | - } |
|
170 | - else |
|
171 | - { |
|
172 | - dol_syslog($this->db->error()); |
|
173 | - $this->error=$this->db->error(); |
|
174 | - return -1; |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - dol_syslog(get_class($this)."::add_to_target mailing cibles=".var_export($cibles,true), LOG_DEBUG); |
|
181 | - return parent::add_to_target($mailing_id, $cibles); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * On the main mailing area, there is a box with statistics. |
|
187 | - * If you want to add a line in this report you must provide an |
|
188 | - * array of SQL request that returns two field: |
|
189 | - * One called "label", One called "nb". |
|
190 | - * |
|
191 | - * @return array Array with SQL requests |
|
192 | - */ |
|
193 | - function getSqlArrayForStats() |
|
194 | - { |
|
195 | - // CHANGE THIS: Optionnal |
|
196 | - |
|
197 | - //var $statssql=array(); |
|
198 | - //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL"; |
|
199 | - return array(); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Return here number of distinct emails returned by your selector. |
|
205 | - * For example if this selector is used to extract 500 different |
|
206 | - * emails from a text file, this function must return 500. |
|
207 | - * |
|
208 | - * @param string $sql Not use here |
|
209 | - * @return int Nb of recipients |
|
210 | - */ |
|
211 | - function getNbOfRecipients($sql='') |
|
212 | - { |
|
213 | - global $conf; |
|
214 | - |
|
215 | - $sql = "SELECT count(distinct(s.email)) as nb"; |
|
216 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
217 | - $sql.= " WHERE s.email != ''"; |
|
218 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
219 | - |
|
220 | - // La requete doit retourner un champ "nb" pour etre comprise |
|
221 | - // par parent::getNbOfRecipients |
|
222 | - return parent::getNbOfRecipients($sql); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * This is to add a form filter to provide variant of selector |
|
227 | - * If used, the HTML select must be called "filter" |
|
228 | - * |
|
229 | - * @return string A html select zone |
|
230 | - */ |
|
231 | - function formFilter() |
|
232 | - { |
|
233 | - global $conf, $langs; |
|
234 | - |
|
235 | - $langs->load("companies"); |
|
236 | - |
|
237 | - $s=''; |
|
238 | - $s.='<select name="filter" class="flat">'; |
|
239 | - |
|
240 | - // Show categories |
|
241 | - $sql = "SELECT rowid, label, type, visible"; |
|
242 | - $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; |
|
243 | - $sql.= " WHERE type in (1,2)"; // We keep only categories for suppliers and customers/prospects |
|
244 | - // $sql.= " AND visible > 0"; // We ignore the property visible because third party's categories does not use this property (only products categories use it). |
|
245 | - $sql.= " AND entity = ".$conf->entity; |
|
246 | - $sql.= " ORDER BY label"; |
|
247 | - |
|
248 | - //print $sql; |
|
249 | - $resql = $this->db->query($sql); |
|
250 | - if ($resql) |
|
251 | - { |
|
252 | - $num = $this->db->num_rows($resql); |
|
253 | - |
|
254 | - if (empty($conf->categorie->enabled)) $num=0; // Force empty list if category module is not enabled |
|
255 | - |
|
256 | - if ($num) $s.='<option value="0"> </option>'; |
|
257 | - else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
258 | - |
|
259 | - $i = 0; |
|
260 | - while ($i < $num) |
|
261 | - { |
|
262 | - $obj = $this->db->fetch_object($resql); |
|
263 | - |
|
264 | - $type=''; |
|
265 | - if ($obj->type == 1) $type=$langs->trans("Supplier"); |
|
266 | - if ($obj->type == 2) $type=$langs->trans("Customer"); |
|
267 | - $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle'); |
|
268 | - if ($type) $s.=' ('.$type.')'; |
|
269 | - $s.='</option>'; |
|
270 | - $i++; |
|
271 | - } |
|
272 | - } |
|
273 | - else |
|
274 | - { |
|
275 | - dol_print_error($this->db); |
|
276 | - } |
|
277 | - |
|
278 | - $s.='</select>'; |
|
279 | - return $s; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * Can include an URL link on each record provided by selector shown on target page. |
|
285 | - * |
|
286 | - * @param int $id ID |
|
287 | - * @param string $type type |
|
288 | - * @return string Url link |
|
289 | - */ |
|
290 | - function url($id,$type) |
|
291 | - { |
|
292 | - if ($type=='thirdparty') { |
|
293 | - $companystatic=new Societe($this->db); |
|
294 | - $companystatic->fetch($id); |
|
295 | - return $companystatic->getNomUrl(0, '', 0, 1); |
|
296 | - } elseif ($type=='contact') { |
|
297 | - $contactstatic=new Contact($this->db); |
|
298 | - $contactstatic->fetch($id); |
|
299 | - return $contactstatic->getNomUrl(0, '', 0, '', -1, 1); |
|
300 | - } |
|
301 | - } |
|
66 | + global $conf, $langs; |
|
67 | + |
|
68 | + dol_syslog(get_class($this)."::add_to_target socid=".var_export($socid,true).' contactid='.var_export($contactid,true)); |
|
69 | + |
|
70 | + $cibles = array(); |
|
71 | + |
|
72 | + if (($type_of_target==1) || ($type_of_target==3)) { |
|
73 | + // Select the third parties from category |
|
74 | + if (count($socid)>0) |
|
75 | + { |
|
76 | + $sql= "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact"; |
|
77 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s LEFT OUTER JOIN ".MAIN_DB_PREFIX."societe_extrafields se ON se.fk_object=s.rowid"; |
|
78 | + $sql.= " WHERE s.entity IN (".getEntity('societe').")"; |
|
79 | + $sql.= " AND s.rowid IN (".implode(',',$socid).")"; |
|
80 | + $sql.= " ORDER BY email"; |
|
81 | + |
|
82 | + // Stock recipients emails into targets table |
|
83 | + $result=$this->db->query($sql); |
|
84 | + if ($result) |
|
85 | + { |
|
86 | + $num = $this->db->num_rows($result); |
|
87 | + $i = 0; |
|
88 | + |
|
89 | + dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found", LOG_DEBUG); |
|
90 | + |
|
91 | + $old = ''; |
|
92 | + while ($i < $num) |
|
93 | + { |
|
94 | + $obj = $this->db->fetch_object($result); |
|
95 | + |
|
96 | + if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) { |
|
97 | + if (!array_key_exists($obj->email, $cibles)) { |
|
98 | + $cibles[$obj->email] = array( |
|
99 | + 'email' => $obj->email, |
|
100 | + 'fk_contact' => $obj->fk_contact, |
|
101 | + 'name' => $obj->name, |
|
102 | + 'firstname' => $obj->firstname, |
|
103 | + 'other' => '', |
|
104 | + 'source_url' => $this->url($obj->id,'thirdparty'), |
|
105 | + 'source_id' => $obj->id, |
|
106 | + 'source_type' => 'thirdparty' |
|
107 | + ); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + $i++; |
|
112 | + } |
|
113 | + } |
|
114 | + else |
|
115 | + { |
|
116 | + dol_syslog($this->db->error()); |
|
117 | + $this->error=$this->db->error(); |
|
118 | + return -1; |
|
119 | + } |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + if (($type_of_target==1) || ($type_of_target==2) || ($type_of_target==4)) { |
|
124 | + // Select the third parties from category |
|
125 | + if (count($socid)>0 || count($contactid)>0) |
|
126 | + { |
|
127 | + $sql= "SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname"; |
|
128 | + $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as socp"; |
|
129 | + $sql.= " WHERE socp.entity IN (".getEntity('socpeople').")"; |
|
130 | + if (count($contactid)>0) { |
|
131 | + $sql.= " AND socp.rowid IN (".implode(',',$contactid).")"; |
|
132 | + } |
|
133 | + if (count($socid)>0) { |
|
134 | + $sql.= " AND socp.fk_soc IN (".implode(',',$socid).")"; |
|
135 | + } |
|
136 | + $sql.= " ORDER BY email"; |
|
137 | + |
|
138 | + // Stock recipients emails into targets table |
|
139 | + $result=$this->db->query($sql); |
|
140 | + if ($result) |
|
141 | + { |
|
142 | + $num = $this->db->num_rows($result); |
|
143 | + $i = 0; |
|
144 | + |
|
145 | + dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found"); |
|
146 | + |
|
147 | + $old = ''; |
|
148 | + while ($i < $num) |
|
149 | + { |
|
150 | + $obj = $this->db->fetch_object($result); |
|
151 | + |
|
152 | + if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) { |
|
153 | + if (!array_key_exists($obj->email, $cibles)) { |
|
154 | + $cibles[$obj->email] = array( |
|
155 | + 'email' => $obj->email, |
|
156 | + 'fk_contact' =>$obj->id, |
|
157 | + 'lastname' => $obj->lastname, |
|
158 | + 'firstname' => $obj->firstname, |
|
159 | + 'other' => '', |
|
160 | + 'source_url' => $this->url($obj->id,'contact'), |
|
161 | + 'source_id' => $obj->id, |
|
162 | + 'source_type' => 'contact' |
|
163 | + ); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + $i++; |
|
168 | + } |
|
169 | + } |
|
170 | + else |
|
171 | + { |
|
172 | + dol_syslog($this->db->error()); |
|
173 | + $this->error=$this->db->error(); |
|
174 | + return -1; |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + dol_syslog(get_class($this)."::add_to_target mailing cibles=".var_export($cibles,true), LOG_DEBUG); |
|
181 | + return parent::add_to_target($mailing_id, $cibles); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * On the main mailing area, there is a box with statistics. |
|
187 | + * If you want to add a line in this report you must provide an |
|
188 | + * array of SQL request that returns two field: |
|
189 | + * One called "label", One called "nb". |
|
190 | + * |
|
191 | + * @return array Array with SQL requests |
|
192 | + */ |
|
193 | + function getSqlArrayForStats() |
|
194 | + { |
|
195 | + // CHANGE THIS: Optionnal |
|
196 | + |
|
197 | + //var $statssql=array(); |
|
198 | + //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL"; |
|
199 | + return array(); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Return here number of distinct emails returned by your selector. |
|
205 | + * For example if this selector is used to extract 500 different |
|
206 | + * emails from a text file, this function must return 500. |
|
207 | + * |
|
208 | + * @param string $sql Not use here |
|
209 | + * @return int Nb of recipients |
|
210 | + */ |
|
211 | + function getNbOfRecipients($sql='') |
|
212 | + { |
|
213 | + global $conf; |
|
214 | + |
|
215 | + $sql = "SELECT count(distinct(s.email)) as nb"; |
|
216 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
217 | + $sql.= " WHERE s.email != ''"; |
|
218 | + $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
219 | + |
|
220 | + // La requete doit retourner un champ "nb" pour etre comprise |
|
221 | + // par parent::getNbOfRecipients |
|
222 | + return parent::getNbOfRecipients($sql); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * This is to add a form filter to provide variant of selector |
|
227 | + * If used, the HTML select must be called "filter" |
|
228 | + * |
|
229 | + * @return string A html select zone |
|
230 | + */ |
|
231 | + function formFilter() |
|
232 | + { |
|
233 | + global $conf, $langs; |
|
234 | + |
|
235 | + $langs->load("companies"); |
|
236 | + |
|
237 | + $s=''; |
|
238 | + $s.='<select name="filter" class="flat">'; |
|
239 | + |
|
240 | + // Show categories |
|
241 | + $sql = "SELECT rowid, label, type, visible"; |
|
242 | + $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; |
|
243 | + $sql.= " WHERE type in (1,2)"; // We keep only categories for suppliers and customers/prospects |
|
244 | + // $sql.= " AND visible > 0"; // We ignore the property visible because third party's categories does not use this property (only products categories use it). |
|
245 | + $sql.= " AND entity = ".$conf->entity; |
|
246 | + $sql.= " ORDER BY label"; |
|
247 | + |
|
248 | + //print $sql; |
|
249 | + $resql = $this->db->query($sql); |
|
250 | + if ($resql) |
|
251 | + { |
|
252 | + $num = $this->db->num_rows($resql); |
|
253 | + |
|
254 | + if (empty($conf->categorie->enabled)) $num=0; // Force empty list if category module is not enabled |
|
255 | + |
|
256 | + if ($num) $s.='<option value="0"> </option>'; |
|
257 | + else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
258 | + |
|
259 | + $i = 0; |
|
260 | + while ($i < $num) |
|
261 | + { |
|
262 | + $obj = $this->db->fetch_object($resql); |
|
263 | + |
|
264 | + $type=''; |
|
265 | + if ($obj->type == 1) $type=$langs->trans("Supplier"); |
|
266 | + if ($obj->type == 2) $type=$langs->trans("Customer"); |
|
267 | + $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle'); |
|
268 | + if ($type) $s.=' ('.$type.')'; |
|
269 | + $s.='</option>'; |
|
270 | + $i++; |
|
271 | + } |
|
272 | + } |
|
273 | + else |
|
274 | + { |
|
275 | + dol_print_error($this->db); |
|
276 | + } |
|
277 | + |
|
278 | + $s.='</select>'; |
|
279 | + return $s; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * Can include an URL link on each record provided by selector shown on target page. |
|
285 | + * |
|
286 | + * @param int $id ID |
|
287 | + * @param string $type type |
|
288 | + * @return string Url link |
|
289 | + */ |
|
290 | + function url($id,$type) |
|
291 | + { |
|
292 | + if ($type=='thirdparty') { |
|
293 | + $companystatic=new Societe($this->db); |
|
294 | + $companystatic->fetch($id); |
|
295 | + return $companystatic->getNomUrl(0, '', 0, 1); |
|
296 | + } elseif ($type=='contact') { |
|
297 | + $contactstatic=new Contact($this->db); |
|
298 | + $contactstatic->fetch($id); |
|
299 | + return $contactstatic->getNomUrl(0, '', 0, '', -1, 1); |
|
300 | + } |
|
301 | + } |
|
302 | 302 | } |
@@ -25,13 +25,13 @@ discard block |
||
25 | 25 | */ |
26 | 26 | class mailing_advthirdparties extends MailingTargets |
27 | 27 | { |
28 | - var $name='ThirdPartyAdvancedTargeting'; |
|
28 | + var $name = 'ThirdPartyAdvancedTargeting'; |
|
29 | 29 | // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
30 | - var $desc="Third parties"; |
|
31 | - var $require_admin=0; |
|
30 | + var $desc = "Third parties"; |
|
31 | + var $require_admin = 0; |
|
32 | 32 | |
33 | - var $require_module=array("none"); // This module should not be displayed as Selector in mailling |
|
34 | - var $picto='company'; |
|
33 | + var $require_module = array("none"); // This module should not be displayed as Selector in mailling |
|
34 | + var $picto = 'company'; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @var DoliDB Database handler. |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | function __construct($db) |
48 | 48 | { |
49 | - $this->db=$db; |
|
49 | + $this->db = $db; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | |
@@ -60,27 +60,27 @@ discard block |
||
60 | 60 | * @param array $contactid Array of contact id to add |
61 | 61 | * @return int <0 if error, number of emails added if ok |
62 | 62 | */ |
63 | - function add_to_target_spec($mailing_id,$socid,$type_of_target, $contactid) |
|
63 | + function add_to_target_spec($mailing_id, $socid, $type_of_target, $contactid) |
|
64 | 64 | { |
65 | 65 | // phpcs:enable |
66 | 66 | global $conf, $langs; |
67 | 67 | |
68 | - dol_syslog(get_class($this)."::add_to_target socid=".var_export($socid,true).' contactid='.var_export($contactid,true)); |
|
68 | + dol_syslog(get_class($this)."::add_to_target socid=".var_export($socid, true).' contactid='.var_export($contactid, true)); |
|
69 | 69 | |
70 | 70 | $cibles = array(); |
71 | 71 | |
72 | - if (($type_of_target==1) || ($type_of_target==3)) { |
|
72 | + if (($type_of_target == 1) || ($type_of_target == 3)) { |
|
73 | 73 | // Select the third parties from category |
74 | - if (count($socid)>0) |
|
74 | + if (count($socid) > 0) |
|
75 | 75 | { |
76 | - $sql= "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact"; |
|
77 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s LEFT OUTER JOIN ".MAIN_DB_PREFIX."societe_extrafields se ON se.fk_object=s.rowid"; |
|
78 | - $sql.= " WHERE s.entity IN (".getEntity('societe').")"; |
|
79 | - $sql.= " AND s.rowid IN (".implode(',',$socid).")"; |
|
80 | - $sql.= " ORDER BY email"; |
|
76 | + $sql = "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact"; |
|
77 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT OUTER JOIN ".MAIN_DB_PREFIX."societe_extrafields se ON se.fk_object=s.rowid"; |
|
78 | + $sql .= " WHERE s.entity IN (".getEntity('societe').")"; |
|
79 | + $sql .= " AND s.rowid IN (".implode(',', $socid).")"; |
|
80 | + $sql .= " ORDER BY email"; |
|
81 | 81 | |
82 | 82 | // Stock recipients emails into targets table |
83 | - $result=$this->db->query($sql); |
|
83 | + $result = $this->db->query($sql); |
|
84 | 84 | if ($result) |
85 | 85 | { |
86 | 86 | $num = $this->db->num_rows($result); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | 'name' => $obj->name, |
102 | 102 | 'firstname' => $obj->firstname, |
103 | 103 | 'other' => '', |
104 | - 'source_url' => $this->url($obj->id,'thirdparty'), |
|
104 | + 'source_url' => $this->url($obj->id, 'thirdparty'), |
|
105 | 105 | 'source_id' => $obj->id, |
106 | 106 | 'source_type' => 'thirdparty' |
107 | 107 | ); |
@@ -114,29 +114,29 @@ discard block |
||
114 | 114 | else |
115 | 115 | { |
116 | 116 | dol_syslog($this->db->error()); |
117 | - $this->error=$this->db->error(); |
|
117 | + $this->error = $this->db->error(); |
|
118 | 118 | return -1; |
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
123 | - if (($type_of_target==1) || ($type_of_target==2) || ($type_of_target==4)) { |
|
123 | + if (($type_of_target == 1) || ($type_of_target == 2) || ($type_of_target == 4)) { |
|
124 | 124 | // Select the third parties from category |
125 | - if (count($socid)>0 || count($contactid)>0) |
|
125 | + if (count($socid) > 0 || count($contactid) > 0) |
|
126 | 126 | { |
127 | - $sql= "SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname"; |
|
128 | - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as socp"; |
|
129 | - $sql.= " WHERE socp.entity IN (".getEntity('socpeople').")"; |
|
130 | - if (count($contactid)>0) { |
|
131 | - $sql.= " AND socp.rowid IN (".implode(',',$contactid).")"; |
|
127 | + $sql = "SELECT socp.rowid as id, socp.email as email, socp.lastname as lastname, socp.firstname as firstname"; |
|
128 | + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as socp"; |
|
129 | + $sql .= " WHERE socp.entity IN (".getEntity('socpeople').")"; |
|
130 | + if (count($contactid) > 0) { |
|
131 | + $sql .= " AND socp.rowid IN (".implode(',', $contactid).")"; |
|
132 | 132 | } |
133 | - if (count($socid)>0) { |
|
134 | - $sql.= " AND socp.fk_soc IN (".implode(',',$socid).")"; |
|
133 | + if (count($socid) > 0) { |
|
134 | + $sql .= " AND socp.fk_soc IN (".implode(',', $socid).")"; |
|
135 | 135 | } |
136 | - $sql.= " ORDER BY email"; |
|
136 | + $sql .= " ORDER BY email"; |
|
137 | 137 | |
138 | 138 | // Stock recipients emails into targets table |
139 | - $result=$this->db->query($sql); |
|
139 | + $result = $this->db->query($sql); |
|
140 | 140 | if ($result) |
141 | 141 | { |
142 | 142 | $num = $this->db->num_rows($result); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | 'lastname' => $obj->lastname, |
158 | 158 | 'firstname' => $obj->firstname, |
159 | 159 | 'other' => '', |
160 | - 'source_url' => $this->url($obj->id,'contact'), |
|
160 | + 'source_url' => $this->url($obj->id, 'contact'), |
|
161 | 161 | 'source_id' => $obj->id, |
162 | 162 | 'source_type' => 'contact' |
163 | 163 | ); |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | else |
171 | 171 | { |
172 | 172 | dol_syslog($this->db->error()); |
173 | - $this->error=$this->db->error(); |
|
173 | + $this->error = $this->db->error(); |
|
174 | 174 | return -1; |
175 | 175 | } |
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | 179 | |
180 | - dol_syslog(get_class($this)."::add_to_target mailing cibles=".var_export($cibles,true), LOG_DEBUG); |
|
180 | + dol_syslog(get_class($this)."::add_to_target mailing cibles=".var_export($cibles, true), LOG_DEBUG); |
|
181 | 181 | return parent::add_to_target($mailing_id, $cibles); |
182 | 182 | } |
183 | 183 | |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | * @param string $sql Not use here |
209 | 209 | * @return int Nb of recipients |
210 | 210 | */ |
211 | - function getNbOfRecipients($sql='') |
|
211 | + function getNbOfRecipients($sql = '') |
|
212 | 212 | { |
213 | 213 | global $conf; |
214 | 214 | |
215 | 215 | $sql = "SELECT count(distinct(s.email)) as nb"; |
216 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
217 | - $sql.= " WHERE s.email != ''"; |
|
218 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
216 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
217 | + $sql .= " WHERE s.email != ''"; |
|
218 | + $sql .= " AND s.entity IN (".getEntity('societe').")"; |
|
219 | 219 | |
220 | 220 | // La requete doit retourner un champ "nb" pour etre comprise |
221 | 221 | // par parent::getNbOfRecipients |
@@ -234,16 +234,16 @@ discard block |
||
234 | 234 | |
235 | 235 | $langs->load("companies"); |
236 | 236 | |
237 | - $s=''; |
|
238 | - $s.='<select name="filter" class="flat">'; |
|
237 | + $s = ''; |
|
238 | + $s .= '<select name="filter" class="flat">'; |
|
239 | 239 | |
240 | 240 | // Show categories |
241 | 241 | $sql = "SELECT rowid, label, type, visible"; |
242 | - $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; |
|
243 | - $sql.= " WHERE type in (1,2)"; // We keep only categories for suppliers and customers/prospects |
|
242 | + $sql .= " FROM ".MAIN_DB_PREFIX."categorie"; |
|
243 | + $sql .= " WHERE type in (1,2)"; // We keep only categories for suppliers and customers/prospects |
|
244 | 244 | // $sql.= " AND visible > 0"; // We ignore the property visible because third party's categories does not use this property (only products categories use it). |
245 | - $sql.= " AND entity = ".$conf->entity; |
|
246 | - $sql.= " ORDER BY label"; |
|
245 | + $sql .= " AND entity = ".$conf->entity; |
|
246 | + $sql .= " ORDER BY label"; |
|
247 | 247 | |
248 | 248 | //print $sql; |
249 | 249 | $resql = $this->db->query($sql); |
@@ -251,22 +251,22 @@ discard block |
||
251 | 251 | { |
252 | 252 | $num = $this->db->num_rows($resql); |
253 | 253 | |
254 | - if (empty($conf->categorie->enabled)) $num=0; // Force empty list if category module is not enabled |
|
254 | + if (empty($conf->categorie->enabled)) $num = 0; // Force empty list if category module is not enabled |
|
255 | 255 | |
256 | - if ($num) $s.='<option value="0"> </option>'; |
|
257 | - else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
256 | + if ($num) $s .= '<option value="0"> </option>'; |
|
257 | + else $s .= '<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
258 | 258 | |
259 | 259 | $i = 0; |
260 | 260 | while ($i < $num) |
261 | 261 | { |
262 | 262 | $obj = $this->db->fetch_object($resql); |
263 | 263 | |
264 | - $type=''; |
|
265 | - if ($obj->type == 1) $type=$langs->trans("Supplier"); |
|
266 | - if ($obj->type == 2) $type=$langs->trans("Customer"); |
|
267 | - $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle'); |
|
268 | - if ($type) $s.=' ('.$type.')'; |
|
269 | - $s.='</option>'; |
|
264 | + $type = ''; |
|
265 | + if ($obj->type == 1) $type = $langs->trans("Supplier"); |
|
266 | + if ($obj->type == 2) $type = $langs->trans("Customer"); |
|
267 | + $s .= '<option value="'.$obj->rowid.'">'.dol_trunc($obj->label, 38, 'middle'); |
|
268 | + if ($type) $s .= ' ('.$type.')'; |
|
269 | + $s .= '</option>'; |
|
270 | 270 | $i++; |
271 | 271 | } |
272 | 272 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | dol_print_error($this->db); |
276 | 276 | } |
277 | 277 | |
278 | - $s.='</select>'; |
|
278 | + $s .= '</select>'; |
|
279 | 279 | return $s; |
280 | 280 | } |
281 | 281 | |
@@ -287,14 +287,14 @@ discard block |
||
287 | 287 | * @param string $type type |
288 | 288 | * @return string Url link |
289 | 289 | */ |
290 | - function url($id,$type) |
|
290 | + function url($id, $type) |
|
291 | 291 | { |
292 | - if ($type=='thirdparty') { |
|
293 | - $companystatic=new Societe($this->db); |
|
292 | + if ($type == 'thirdparty') { |
|
293 | + $companystatic = new Societe($this->db); |
|
294 | 294 | $companystatic->fetch($id); |
295 | 295 | return $companystatic->getNomUrl(0, '', 0, 1); |
296 | - } elseif ($type=='contact') { |
|
297 | - $contactstatic=new Contact($this->db); |
|
296 | + } elseif ($type == 'contact') { |
|
297 | + $contactstatic = new Contact($this->db); |
|
298 | 298 | $contactstatic->fetch($id); |
299 | 299 | return $contactstatic->getNomUrl(0, '', 0, '', -1, 1); |
300 | 300 | } |
@@ -110,8 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | $i++; |
112 | 112 | } |
113 | - } |
|
114 | - else |
|
113 | + } else |
|
115 | 114 | { |
116 | 115 | dol_syslog($this->db->error()); |
117 | 116 | $this->error=$this->db->error(); |
@@ -166,8 +165,7 @@ discard block |
||
166 | 165 | |
167 | 166 | $i++; |
168 | 167 | } |
169 | - } |
|
170 | - else |
|
168 | + } else |
|
171 | 169 | { |
172 | 170 | dol_syslog($this->db->error()); |
173 | 171 | $this->error=$this->db->error(); |
@@ -251,10 +249,16 @@ discard block |
||
251 | 249 | { |
252 | 250 | $num = $this->db->num_rows($resql); |
253 | 251 | |
254 | - if (empty($conf->categorie->enabled)) $num=0; // Force empty list if category module is not enabled |
|
252 | + if (empty($conf->categorie->enabled)) { |
|
253 | + $num=0; |
|
254 | + } |
|
255 | + // Force empty list if category module is not enabled |
|
255 | 256 | |
256 | - if ($num) $s.='<option value="0"> </option>'; |
|
257 | - else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
257 | + if ($num) { |
|
258 | + $s.='<option value="0"> </option>'; |
|
259 | + } else { |
|
260 | + $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
261 | + } |
|
258 | 262 | |
259 | 263 | $i = 0; |
260 | 264 | while ($i < $num) |
@@ -262,15 +266,20 @@ discard block |
||
262 | 266 | $obj = $this->db->fetch_object($resql); |
263 | 267 | |
264 | 268 | $type=''; |
265 | - if ($obj->type == 1) $type=$langs->trans("Supplier"); |
|
266 | - if ($obj->type == 2) $type=$langs->trans("Customer"); |
|
269 | + if ($obj->type == 1) { |
|
270 | + $type=$langs->trans("Supplier"); |
|
271 | + } |
|
272 | + if ($obj->type == 2) { |
|
273 | + $type=$langs->trans("Customer"); |
|
274 | + } |
|
267 | 275 | $s.='<option value="'.$obj->rowid.'">'.dol_trunc($obj->label,38,'middle'); |
268 | - if ($type) $s.=' ('.$type.')'; |
|
276 | + if ($type) { |
|
277 | + $s.=' ('.$type.')'; |
|
278 | + } |
|
269 | 279 | $s.='</option>'; |
270 | 280 | $i++; |
271 | 281 | } |
272 | - } |
|
273 | - else |
|
282 | + } else |
|
274 | 283 | { |
275 | 284 | dol_print_error($this->db); |
276 | 285 | } |
@@ -30,133 +30,133 @@ |
||
30 | 30 | */ |
31 | 31 | class mailing_xinputuser extends MailingTargets |
32 | 32 | { |
33 | - var $name='EmailsFromUser'; // Identifiant du module mailing |
|
34 | - // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
35 | - var $desc='EMails input by user'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouv�e |
|
36 | - var $require_module=array(); // Module mailing actif si modules require_module actifs |
|
37 | - var $require_admin=0; // Module mailing actif pour user admin ou non |
|
38 | - var $picto='generic'; |
|
39 | - var $tooltip='UseFormatInputEmailToTarget'; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Constructor |
|
44 | - * |
|
45 | - * @param DoliDB $db Database handler |
|
46 | - */ |
|
47 | - function __construct($db) |
|
48 | - { |
|
49 | - $this->db=$db; |
|
50 | - } |
|
33 | + var $name='EmailsFromUser'; // Identifiant du module mailing |
|
34 | + // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
35 | + var $desc='EMails input by user'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouv�e |
|
36 | + var $require_module=array(); // Module mailing actif si modules require_module actifs |
|
37 | + var $require_admin=0; // Module mailing actif pour user admin ou non |
|
38 | + var $picto='generic'; |
|
39 | + var $tooltip='UseFormatInputEmailToTarget'; |
|
51 | 40 | |
52 | 41 | |
53 | 42 | /** |
54 | - * On the main mailing area, there is a box with statistics. |
|
55 | - * If you want to add a line in this report you must provide an |
|
56 | - * array of SQL request that returns two field: |
|
57 | - * One called "label", One called "nb". |
|
58 | - * |
|
59 | - * @return array Array with SQL requests |
|
60 | - */ |
|
61 | - function getSqlArrayForStats() |
|
62 | - { |
|
63 | - global $langs; |
|
64 | - $langs->load("users"); |
|
65 | - |
|
66 | - $statssql=array(); |
|
67 | - return $statssql; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Return here number of distinct emails returned by your selector. |
|
73 | - * For example if this selector is used to extract 500 different |
|
74 | - * emails from a text file, this function must return 500. |
|
75 | - * |
|
76 | - * @param string $sql Sql request to count |
|
77 | - * @return string '' means NA |
|
78 | - */ |
|
79 | - function getNbOfRecipients($sql='') |
|
80 | - { |
|
81 | - return ''; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Renvoie url lien vers fiche de la source du destinataire du mailing |
|
87 | - * |
|
43 | + * Constructor |
|
44 | + * |
|
45 | + * @param DoliDB $db Database handler |
|
46 | + */ |
|
47 | + function __construct($db) |
|
48 | + { |
|
49 | + $this->db=$db; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * On the main mailing area, there is a box with statistics. |
|
55 | + * If you want to add a line in this report you must provide an |
|
56 | + * array of SQL request that returns two field: |
|
57 | + * One called "label", One called "nb". |
|
58 | + * |
|
59 | + * @return array Array with SQL requests |
|
60 | + */ |
|
61 | + function getSqlArrayForStats() |
|
62 | + { |
|
63 | + global $langs; |
|
64 | + $langs->load("users"); |
|
65 | + |
|
66 | + $statssql=array(); |
|
67 | + return $statssql; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Return here number of distinct emails returned by your selector. |
|
73 | + * For example if this selector is used to extract 500 different |
|
74 | + * emails from a text file, this function must return 500. |
|
75 | + * |
|
76 | + * @param string $sql Sql request to count |
|
77 | + * @return string '' means NA |
|
78 | + */ |
|
79 | + function getNbOfRecipients($sql='') |
|
80 | + { |
|
81 | + return ''; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Renvoie url lien vers fiche de la source du destinataire du mailing |
|
87 | + * |
|
88 | 88 | * @param int $id ID |
89 | - * @return string Url lien |
|
90 | - */ |
|
91 | - function url($id) |
|
92 | - { |
|
93 | - return ''; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings |
|
99 | - * |
|
100 | - * @return string Retourne zone select |
|
101 | - */ |
|
102 | - function formFilter() |
|
103 | - { |
|
104 | - global $langs; |
|
105 | - |
|
106 | - $s=''; |
|
107 | - $s.='<input type="text" name="xinputuser" class="flat minwidth300" value="'.GETPOST("xinputuser").'">'; |
|
108 | - return $s; |
|
109 | - } |
|
89 | + * @return string Url lien |
|
90 | + */ |
|
91 | + function url($id) |
|
92 | + { |
|
93 | + return ''; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings |
|
99 | + * |
|
100 | + * @return string Retourne zone select |
|
101 | + */ |
|
102 | + function formFilter() |
|
103 | + { |
|
104 | + global $langs; |
|
105 | + |
|
106 | + $s=''; |
|
107 | + $s.='<input type="text" name="xinputuser" class="flat minwidth300" value="'.GETPOST("xinputuser").'">'; |
|
108 | + return $s; |
|
109 | + } |
|
110 | 110 | |
111 | 111 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
112 | - /** |
|
113 | - * Ajoute destinataires dans table des cibles |
|
114 | - * |
|
115 | - * @param int $mailing_id Id of emailing |
|
116 | - * @return int < 0 si erreur, nb ajout si ok |
|
117 | - */ |
|
118 | - function add_to_target($mailing_id) |
|
119 | - { |
|
112 | + /** |
|
113 | + * Ajoute destinataires dans table des cibles |
|
114 | + * |
|
115 | + * @param int $mailing_id Id of emailing |
|
116 | + * @return int < 0 si erreur, nb ajout si ok |
|
117 | + */ |
|
118 | + function add_to_target($mailing_id) |
|
119 | + { |
|
120 | 120 | // phpcs:enable |
121 | - global $conf,$langs,$_FILES; |
|
121 | + global $conf,$langs,$_FILES; |
|
122 | 122 | |
123 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
123 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
124 | 124 | |
125 | - $tmparray=explode(';',GETPOST('xinputuser')); |
|
126 | - $email=$tmparray[0]; |
|
127 | - $lastname=$tmparray[1]; |
|
128 | - $firstname=$tmparray[2]; |
|
129 | - $other=$tmparray[3]; |
|
125 | + $tmparray=explode(';',GETPOST('xinputuser')); |
|
126 | + $email=$tmparray[0]; |
|
127 | + $lastname=$tmparray[1]; |
|
128 | + $firstname=$tmparray[2]; |
|
129 | + $other=$tmparray[3]; |
|
130 | 130 | |
131 | - $cibles=array(); |
|
131 | + $cibles=array(); |
|
132 | 132 | if (! empty($email)) |
133 | 133 | { |
134 | - if (isValidEMail($email)) |
|
135 | - { |
|
136 | - $cibles[] = array( |
|
137 | - 'email' => $email, |
|
138 | - 'lastname' => $lastname, |
|
139 | - 'firstname' => $firstname, |
|
140 | - 'other' => $other, |
|
134 | + if (isValidEMail($email)) |
|
135 | + { |
|
136 | + $cibles[] = array( |
|
137 | + 'email' => $email, |
|
138 | + 'lastname' => $lastname, |
|
139 | + 'firstname' => $firstname, |
|
140 | + 'other' => $other, |
|
141 | 141 | 'source_url' => '', |
142 | 142 | 'source_id' => '', |
143 | 143 | 'source_type' => 'file' |
144 | - ); |
|
145 | - |
|
146 | - return parent::add_to_target($mailing_id, $cibles); |
|
147 | - } |
|
148 | - else |
|
149 | - { |
|
150 | - $langs->load("errors"); |
|
151 | - $this->error = $langs->trans("ErrorBadEMail",$email); |
|
152 | - return -1; |
|
153 | - } |
|
154 | - } |
|
155 | - else |
|
156 | - { |
|
144 | + ); |
|
145 | + |
|
146 | + return parent::add_to_target($mailing_id, $cibles); |
|
147 | + } |
|
148 | + else |
|
149 | + { |
|
150 | + $langs->load("errors"); |
|
151 | + $this->error = $langs->trans("ErrorBadEMail",$email); |
|
152 | + return -1; |
|
153 | + } |
|
154 | + } |
|
155 | + else |
|
156 | + { |
|
157 | 157 | $langs->load("errors"); |
158 | 158 | $this->error = $langs->trans("ErrorBadEmail",$email); |
159 | - return -1; |
|
160 | - } |
|
161 | - } |
|
159 | + return -1; |
|
160 | + } |
|
161 | + } |
|
162 | 162 | } |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class mailing_xinputuser extends MailingTargets |
32 | 32 | { |
33 | - var $name='EmailsFromUser'; // Identifiant du module mailing |
|
33 | + var $name = 'EmailsFromUser'; // Identifiant du module mailing |
|
34 | 34 | // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
35 | - var $desc='EMails input by user'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouv�e |
|
36 | - var $require_module=array(); // Module mailing actif si modules require_module actifs |
|
37 | - var $require_admin=0; // Module mailing actif pour user admin ou non |
|
38 | - var $picto='generic'; |
|
39 | - var $tooltip='UseFormatInputEmailToTarget'; |
|
35 | + var $desc = 'EMails input by user'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouv�e |
|
36 | + var $require_module = array(); // Module mailing actif si modules require_module actifs |
|
37 | + var $require_admin = 0; // Module mailing actif pour user admin ou non |
|
38 | + var $picto = 'generic'; |
|
39 | + var $tooltip = 'UseFormatInputEmailToTarget'; |
|
40 | 40 | |
41 | 41 | |
42 | 42 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | function __construct($db) |
48 | 48 | { |
49 | - $this->db=$db; |
|
49 | + $this->db = $db; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | global $langs; |
64 | 64 | $langs->load("users"); |
65 | 65 | |
66 | - $statssql=array(); |
|
66 | + $statssql = array(); |
|
67 | 67 | return $statssql; |
68 | 68 | } |
69 | 69 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param string $sql Sql request to count |
77 | 77 | * @return string '' means NA |
78 | 78 | */ |
79 | - function getNbOfRecipients($sql='') |
|
79 | + function getNbOfRecipients($sql = '') |
|
80 | 80 | { |
81 | 81 | return ''; |
82 | 82 | } |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | { |
104 | 104 | global $langs; |
105 | 105 | |
106 | - $s=''; |
|
107 | - $s.='<input type="text" name="xinputuser" class="flat minwidth300" value="'.GETPOST("xinputuser").'">'; |
|
106 | + $s = ''; |
|
107 | + $s .= '<input type="text" name="xinputuser" class="flat minwidth300" value="'.GETPOST("xinputuser").'">'; |
|
108 | 108 | return $s; |
109 | 109 | } |
110 | 110 | |
@@ -118,18 +118,18 @@ discard block |
||
118 | 118 | function add_to_target($mailing_id) |
119 | 119 | { |
120 | 120 | // phpcs:enable |
121 | - global $conf,$langs,$_FILES; |
|
121 | + global $conf, $langs, $_FILES; |
|
122 | 122 | |
123 | 123 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
124 | 124 | |
125 | - $tmparray=explode(';',GETPOST('xinputuser')); |
|
126 | - $email=$tmparray[0]; |
|
127 | - $lastname=$tmparray[1]; |
|
128 | - $firstname=$tmparray[2]; |
|
129 | - $other=$tmparray[3]; |
|
125 | + $tmparray = explode(';', GETPOST('xinputuser')); |
|
126 | + $email = $tmparray[0]; |
|
127 | + $lastname = $tmparray[1]; |
|
128 | + $firstname = $tmparray[2]; |
|
129 | + $other = $tmparray[3]; |
|
130 | 130 | |
131 | - $cibles=array(); |
|
132 | - if (! empty($email)) |
|
131 | + $cibles = array(); |
|
132 | + if (!empty($email)) |
|
133 | 133 | { |
134 | 134 | if (isValidEMail($email)) |
135 | 135 | { |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | else |
149 | 149 | { |
150 | 150 | $langs->load("errors"); |
151 | - $this->error = $langs->trans("ErrorBadEMail",$email); |
|
151 | + $this->error = $langs->trans("ErrorBadEMail", $email); |
|
152 | 152 | return -1; |
153 | 153 | } |
154 | 154 | } |
155 | 155 | else |
156 | 156 | { |
157 | 157 | $langs->load("errors"); |
158 | - $this->error = $langs->trans("ErrorBadEmail",$email); |
|
158 | + $this->error = $langs->trans("ErrorBadEmail", $email); |
|
159 | 159 | return -1; |
160 | 160 | } |
161 | 161 | } |
@@ -144,15 +144,13 @@ |
||
144 | 144 | ); |
145 | 145 | |
146 | 146 | return parent::add_to_target($mailing_id, $cibles); |
147 | - } |
|
148 | - else |
|
147 | + } else |
|
149 | 148 | { |
150 | 149 | $langs->load("errors"); |
151 | 150 | $this->error = $langs->trans("ErrorBadEMail",$email); |
152 | 151 | return -1; |
153 | 152 | } |
154 | - } |
|
155 | - else |
|
153 | + } else |
|
156 | 154 | { |
157 | 155 | $langs->load("errors"); |
158 | 156 | $this->error = $langs->trans("ErrorBadEmail",$email); |
@@ -32,421 +32,421 @@ |
||
32 | 32 | */ |
33 | 33 | class mailing_contacts1 extends MailingTargets |
34 | 34 | { |
35 | - var $name='ContactCompanies'; // Identifiant du module mailing |
|
36 | - // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
37 | - var $desc='Contacts of thirdparties (prospects, customers, suppliers...)'; |
|
38 | - var $require_module=array("societe"); // Module mailing actif si modules require_module actifs |
|
39 | - var $require_admin=0; // Module mailing actif pour user admin ou non |
|
40 | - var $picto='contact'; |
|
41 | - |
|
42 | - /** |
|
35 | + var $name='ContactCompanies'; // Identifiant du module mailing |
|
36 | + // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
37 | + var $desc='Contacts of thirdparties (prospects, customers, suppliers...)'; |
|
38 | + var $require_module=array("societe"); // Module mailing actif si modules require_module actifs |
|
39 | + var $require_admin=0; // Module mailing actif pour user admin ou non |
|
40 | + var $picto='contact'; |
|
41 | + |
|
42 | + /** |
|
43 | 43 | * @var DoliDB Database handler. |
44 | 44 | */ |
45 | 45 | public $db; |
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * Constructor |
|
50 | - * |
|
51 | - * @param DoliDB $db Database handler |
|
52 | - */ |
|
53 | - function __construct($db) |
|
54 | - { |
|
55 | - $this->db=$db; |
|
56 | - } |
|
48 | + /** |
|
49 | + * Constructor |
|
50 | + * |
|
51 | + * @param DoliDB $db Database handler |
|
52 | + */ |
|
53 | + function __construct($db) |
|
54 | + { |
|
55 | + $this->db=$db; |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | 59 | /** |
60 | - * On the main mailing area, there is a box with statistics. |
|
61 | - * If you want to add a line in this report you must provide an |
|
62 | - * array of SQL request that returns two field: |
|
63 | - * One called "label", One called "nb". |
|
64 | - * |
|
65 | - * @return string[] Array with SQL requests |
|
66 | - */ |
|
67 | - function getSqlArrayForStats() |
|
68 | - { |
|
69 | - global $conf, $langs; |
|
70 | - |
|
71 | - $langs->load("commercial"); |
|
72 | - |
|
73 | - $statssql=array(); |
|
74 | - $statssql[0] = "SELECT '".$langs->trans("NbOfCompaniesContacts")."' as label,"; |
|
75 | - $statssql[0].= " count(distinct(c.email)) as nb"; |
|
76 | - $statssql[0].= " FROM ".MAIN_DB_PREFIX."socpeople as c"; |
|
77 | - $statssql[0].= " WHERE c.entity IN (".getEntity('socpeople').")"; |
|
78 | - $statssql[0].= " AND c.email != ''"; // Note that null != '' is false |
|
79 | - $statssql[0].= " AND c.no_email = 0"; |
|
80 | - $statssql[0].= " AND c.statut = 1"; |
|
81 | - |
|
82 | - return $statssql; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Return here number of distinct emails returned by your selector. |
|
88 | - * For example if this selector is used to extract 500 different |
|
89 | - * emails from a text file, this function must return 500. |
|
90 | - * |
|
91 | - * @param string $sql Requete sql de comptage |
|
92 | - * @return int |
|
93 | - */ |
|
94 | - function getNbOfRecipients($sql='') |
|
95 | - { |
|
96 | - global $conf; |
|
97 | - |
|
98 | - $sql = "SELECT count(distinct(c.email)) as nb"; |
|
99 | - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c"; |
|
100 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc"; |
|
101 | - $sql.= " WHERE c.entity IN (".getEntity('socpeople').")"; |
|
102 | - $sql.= " AND c.email != ''"; // Note that null != '' is false |
|
103 | - $sql.= " AND c.no_email = 0"; |
|
104 | - $sql.= " AND c.statut = 1"; |
|
105 | - |
|
106 | - // The request must return a field called "nb" to be understandable by parent::getNbOfRecipients |
|
107 | - return parent::getNbOfRecipients($sql); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings |
|
113 | - * |
|
114 | - * @return string Retourne zone select |
|
115 | - */ |
|
116 | - function formFilter() |
|
117 | - { |
|
118 | - global $langs; |
|
119 | - |
|
120 | - // Load translation files required by the page |
|
60 | + * On the main mailing area, there is a box with statistics. |
|
61 | + * If you want to add a line in this report you must provide an |
|
62 | + * array of SQL request that returns two field: |
|
63 | + * One called "label", One called "nb". |
|
64 | + * |
|
65 | + * @return string[] Array with SQL requests |
|
66 | + */ |
|
67 | + function getSqlArrayForStats() |
|
68 | + { |
|
69 | + global $conf, $langs; |
|
70 | + |
|
71 | + $langs->load("commercial"); |
|
72 | + |
|
73 | + $statssql=array(); |
|
74 | + $statssql[0] = "SELECT '".$langs->trans("NbOfCompaniesContacts")."' as label,"; |
|
75 | + $statssql[0].= " count(distinct(c.email)) as nb"; |
|
76 | + $statssql[0].= " FROM ".MAIN_DB_PREFIX."socpeople as c"; |
|
77 | + $statssql[0].= " WHERE c.entity IN (".getEntity('socpeople').")"; |
|
78 | + $statssql[0].= " AND c.email != ''"; // Note that null != '' is false |
|
79 | + $statssql[0].= " AND c.no_email = 0"; |
|
80 | + $statssql[0].= " AND c.statut = 1"; |
|
81 | + |
|
82 | + return $statssql; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Return here number of distinct emails returned by your selector. |
|
88 | + * For example if this selector is used to extract 500 different |
|
89 | + * emails from a text file, this function must return 500. |
|
90 | + * |
|
91 | + * @param string $sql Requete sql de comptage |
|
92 | + * @return int |
|
93 | + */ |
|
94 | + function getNbOfRecipients($sql='') |
|
95 | + { |
|
96 | + global $conf; |
|
97 | + |
|
98 | + $sql = "SELECT count(distinct(c.email)) as nb"; |
|
99 | + $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c"; |
|
100 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc"; |
|
101 | + $sql.= " WHERE c.entity IN (".getEntity('socpeople').")"; |
|
102 | + $sql.= " AND c.email != ''"; // Note that null != '' is false |
|
103 | + $sql.= " AND c.no_email = 0"; |
|
104 | + $sql.= " AND c.statut = 1"; |
|
105 | + |
|
106 | + // The request must return a field called "nb" to be understandable by parent::getNbOfRecipients |
|
107 | + return parent::getNbOfRecipients($sql); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings |
|
113 | + * |
|
114 | + * @return string Retourne zone select |
|
115 | + */ |
|
116 | + function formFilter() |
|
117 | + { |
|
118 | + global $langs; |
|
119 | + |
|
120 | + // Load translation files required by the page |
|
121 | 121 | $langs->loadLangs(array("commercial","companies","suppliers","categories")); |
122 | 122 | |
123 | - $s=''; |
|
123 | + $s=''; |
|
124 | 124 | |
125 | - // Add filter on job position |
|
126 | - $sql = "SELECT sp.poste, count(distinct(sp.email)) AS nb"; |
|
127 | - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; |
|
128 | - $sql.= " WHERE sp.entity IN (".getEntity('socpeople').")"; |
|
129 | - /*$sql.= " AND sp.email != ''"; // Note that null != '' is false |
|
125 | + // Add filter on job position |
|
126 | + $sql = "SELECT sp.poste, count(distinct(sp.email)) AS nb"; |
|
127 | + $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; |
|
128 | + $sql.= " WHERE sp.entity IN (".getEntity('socpeople').")"; |
|
129 | + /*$sql.= " AND sp.email != ''"; // Note that null != '' is false |
|
130 | 130 | $sql.= " AND sp.no_email = 0"; |
131 | 131 | $sql.= " AND sp.statut = 1";*/ |
132 | - $sql.= " AND (sp.poste IS NOT NULL AND sp.poste != '')"; |
|
133 | - $sql.= " GROUP BY sp.poste"; |
|
134 | - $sql.= " ORDER BY sp.poste"; |
|
135 | - $resql = $this->db->query($sql); |
|
136 | - |
|
137 | - $s.=$langs->trans("PostOrFunction").': '; |
|
138 | - $s.='<select name="filter_jobposition" class="flat">'; |
|
139 | - $s.='<option value="all"> </option>'; |
|
140 | - if ($resql) |
|
141 | - { |
|
142 | - $num = $this->db->num_rows($resql); |
|
143 | - $i = 0; |
|
144 | - while ($i < $num) |
|
145 | - { |
|
146 | - $obj = $this->db->fetch_object($resql); |
|
147 | - $s.='<option value="'.dol_escape_htmltag($obj->poste).'">'.dol_escape_htmltag($obj->poste).' ('.$obj->nb.')</option>'; |
|
148 | - $i++; |
|
149 | - } |
|
150 | - } |
|
151 | - else dol_print_error($this->db); |
|
152 | - $s.='</select>'; |
|
153 | - |
|
154 | - $s.=' '; |
|
155 | - |
|
156 | - // Filter on contact category |
|
157 | - $s .= $langs->trans("ContactCategoriesShort").': '; |
|
158 | - $sql = "SELECT c.label, count(distinct(sp.email)) AS nb"; |
|
159 | - $sql.= " FROM "; |
|
160 | - $sql.= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
161 | - $sql.= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
162 | - $sql.= " ".MAIN_DB_PREFIX."categorie_contact as cs"; |
|
163 | - $sql.= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
164 | - //$sql.= " AND sp.no_email = 0"; |
|
165 | - //$sql.= " AND sp.email != ''"; |
|
166 | - //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; |
|
167 | - $sql.= " AND cs.fk_categorie = c.rowid"; |
|
168 | - $sql.= " AND cs.fk_socpeople = sp.rowid"; |
|
169 | - $sql.= " GROUP BY c.label"; |
|
170 | - $sql.= " ORDER BY c.label"; |
|
171 | - $resql = $this->db->query($sql); |
|
172 | - |
|
173 | - $s.='<select name="filter_category" class="flat">'; |
|
174 | - $s.='<option value="all"> </option>'; |
|
175 | - if ($resql) |
|
176 | - { |
|
177 | - $num = $this->db->num_rows($resql); |
|
178 | - if ($num) |
|
179 | - { |
|
180 | - $i = 0; |
|
181 | - while ($i < $num) |
|
182 | - { |
|
183 | - $obj = $this->db->fetch_object($resql); |
|
184 | - $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
185 | - $i++; |
|
186 | - } |
|
187 | - } |
|
188 | - else |
|
189 | - { |
|
190 | - $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactWithCategoryFound").'</option>'; |
|
191 | - } |
|
192 | - } |
|
193 | - else dol_print_error($this->db); |
|
194 | - $s.='</select>'; |
|
195 | - |
|
196 | - $s.='<br>'; |
|
197 | - |
|
198 | - // Add prospect of a particular level |
|
199 | - $s.=$langs->trans("NatureOfThirdParty").': '; |
|
200 | - $s.='<select name="filter" class="flat">'; |
|
201 | - $sql = "SELECT code, label"; |
|
202 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel"; |
|
203 | - $sql.= " WHERE active > 0"; |
|
204 | - $sql.= " ORDER BY label"; |
|
205 | - $resql = $this->db->query($sql); |
|
206 | - if ($resql) |
|
207 | - { |
|
208 | - $num = $this->db->num_rows($resql); |
|
209 | - if ($num) $s.='<option value="all"> </option>'; |
|
210 | - else $s.='<option value="all">'.$langs->trans("ContactsAllShort").'</option>'; |
|
211 | - $s.='<option value="prospects">'.$langs->trans("ThirdPartyProspects").'</option>'; |
|
212 | - |
|
213 | - $i = 0; |
|
214 | - while ($i < $num) |
|
215 | - { |
|
216 | - $obj = $this->db->fetch_object($resql); |
|
217 | - $level=$langs->trans($obj->code); |
|
218 | - if ($level == $obj->code) $level=$langs->trans($obj->label); |
|
219 | - $s.='<option value="prospectslevel'.$obj->code.'">'.$langs->trans("ThirdPartyProspects").' ('.$langs->trans("ProspectLevelShort").'='.$level.')</option>'; |
|
220 | - $i++; |
|
221 | - } |
|
222 | - } |
|
223 | - else dol_print_error($this->db); |
|
224 | - $s.='<option value="customers">'.$langs->trans("ThirdPartyCustomers").'</option>'; |
|
225 | - //$s.='<option value="customersidprof">'.$langs->trans("ThirdPartyCustomersWithIdProf12",$langs->trans("ProfId1"),$langs->trans("ProfId2")).'</option>'; |
|
226 | - $s.='<option value="suppliers">'.$langs->trans("ThirdPartySuppliers").'</option>'; |
|
227 | - $s.='</select>'; |
|
228 | - |
|
229 | - $s.= ' '; |
|
230 | - |
|
231 | - // Filter on thirdparty category |
|
232 | - $s .= $langs->trans("CustomersProspectsCategoriesShort").': '; |
|
233 | - $sql = "SELECT c.label, count(distinct(sp.email)) AS nb"; |
|
234 | - $sql.= " FROM "; |
|
235 | - $sql.= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
236 | - $sql.= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
237 | - $sql.= " ".MAIN_DB_PREFIX."categorie_societe as cs"; |
|
238 | - $sql.= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
239 | - //$sql.= " AND sp.no_email = 0"; |
|
240 | - //$sql.= " AND sp.email != ''"; |
|
241 | - //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; |
|
242 | - $sql.= " AND cs.fk_categorie = c.rowid"; |
|
243 | - $sql.= " AND cs.fk_soc = sp.fk_soc"; |
|
244 | - $sql.= " GROUP BY c.label"; |
|
245 | - $sql.= " ORDER BY c.label"; |
|
246 | - $resql = $this->db->query($sql); |
|
247 | - |
|
248 | - $s.='<select name="filter_category_customer" class="flat">'; |
|
249 | - $s.='<option value="all"> </option>'; |
|
250 | - if ($resql) |
|
251 | - { |
|
252 | - $num = $this->db->num_rows($resql); |
|
253 | - if ($num) |
|
254 | - { |
|
255 | - $i = 0; |
|
256 | - while ($i < $num) |
|
257 | - { |
|
258 | - $obj = $this->db->fetch_object($resql); |
|
259 | - $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
260 | - $i++; |
|
261 | - } |
|
262 | - } |
|
263 | - else |
|
264 | - { |
|
265 | - $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>'; |
|
266 | - } |
|
267 | - } |
|
268 | - else dol_print_error($this->db); |
|
269 | - $s.='</select>'; |
|
270 | - |
|
271 | - $s.= ' '; |
|
272 | - |
|
273 | - // Filter on thirdparty category |
|
274 | - $s .= $langs->trans("SuppliersCategoriesShort").': '; |
|
275 | - $sql = "SELECT c.label, count(distinct(sp.email)) AS nb"; |
|
276 | - $sql.= " FROM "; |
|
277 | - $sql.= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
278 | - $sql.= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
279 | - $sql.= " ".MAIN_DB_PREFIX."categorie_fournisseur as cs"; |
|
280 | - $sql.= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
281 | - //$sql.= " AND sp.no_email = 0"; |
|
282 | - //$sql.= " AND sp.email != ''"; |
|
283 | - //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; |
|
284 | - $sql.= " AND cs.fk_categorie = c.rowid"; |
|
285 | - $sql.= " AND cs.fk_soc = sp.fk_soc"; |
|
286 | - $sql.= " GROUP BY c.label"; |
|
287 | - $sql.= " ORDER BY c.label"; |
|
288 | - $resql = $this->db->query($sql); |
|
289 | - |
|
290 | - $s.='<select name="filter_category_supplier" class="flat">'; |
|
291 | - $s.='<option value="all"> </option>'; |
|
292 | - if ($resql) |
|
293 | - { |
|
294 | - $num = $this->db->num_rows($resql); |
|
295 | - if ($num) |
|
296 | - { |
|
297 | - $i = 0; |
|
298 | - while ($i < $num) |
|
299 | - { |
|
300 | - $obj = $this->db->fetch_object($resql); |
|
301 | - $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
302 | - $i++; |
|
303 | - } |
|
304 | - } |
|
305 | - else |
|
306 | - { |
|
307 | - $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>'; |
|
308 | - } |
|
309 | - } |
|
310 | - else dol_print_error($this->db); |
|
311 | - $s.='</select>'; |
|
312 | - |
|
313 | - return $s; |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * Renvoie url lien vers fiche de la source du destinataire du mailing |
|
319 | - * |
|
132 | + $sql.= " AND (sp.poste IS NOT NULL AND sp.poste != '')"; |
|
133 | + $sql.= " GROUP BY sp.poste"; |
|
134 | + $sql.= " ORDER BY sp.poste"; |
|
135 | + $resql = $this->db->query($sql); |
|
136 | + |
|
137 | + $s.=$langs->trans("PostOrFunction").': '; |
|
138 | + $s.='<select name="filter_jobposition" class="flat">'; |
|
139 | + $s.='<option value="all"> </option>'; |
|
140 | + if ($resql) |
|
141 | + { |
|
142 | + $num = $this->db->num_rows($resql); |
|
143 | + $i = 0; |
|
144 | + while ($i < $num) |
|
145 | + { |
|
146 | + $obj = $this->db->fetch_object($resql); |
|
147 | + $s.='<option value="'.dol_escape_htmltag($obj->poste).'">'.dol_escape_htmltag($obj->poste).' ('.$obj->nb.')</option>'; |
|
148 | + $i++; |
|
149 | + } |
|
150 | + } |
|
151 | + else dol_print_error($this->db); |
|
152 | + $s.='</select>'; |
|
153 | + |
|
154 | + $s.=' '; |
|
155 | + |
|
156 | + // Filter on contact category |
|
157 | + $s .= $langs->trans("ContactCategoriesShort").': '; |
|
158 | + $sql = "SELECT c.label, count(distinct(sp.email)) AS nb"; |
|
159 | + $sql.= " FROM "; |
|
160 | + $sql.= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
161 | + $sql.= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
162 | + $sql.= " ".MAIN_DB_PREFIX."categorie_contact as cs"; |
|
163 | + $sql.= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
164 | + //$sql.= " AND sp.no_email = 0"; |
|
165 | + //$sql.= " AND sp.email != ''"; |
|
166 | + //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; |
|
167 | + $sql.= " AND cs.fk_categorie = c.rowid"; |
|
168 | + $sql.= " AND cs.fk_socpeople = sp.rowid"; |
|
169 | + $sql.= " GROUP BY c.label"; |
|
170 | + $sql.= " ORDER BY c.label"; |
|
171 | + $resql = $this->db->query($sql); |
|
172 | + |
|
173 | + $s.='<select name="filter_category" class="flat">'; |
|
174 | + $s.='<option value="all"> </option>'; |
|
175 | + if ($resql) |
|
176 | + { |
|
177 | + $num = $this->db->num_rows($resql); |
|
178 | + if ($num) |
|
179 | + { |
|
180 | + $i = 0; |
|
181 | + while ($i < $num) |
|
182 | + { |
|
183 | + $obj = $this->db->fetch_object($resql); |
|
184 | + $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
185 | + $i++; |
|
186 | + } |
|
187 | + } |
|
188 | + else |
|
189 | + { |
|
190 | + $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactWithCategoryFound").'</option>'; |
|
191 | + } |
|
192 | + } |
|
193 | + else dol_print_error($this->db); |
|
194 | + $s.='</select>'; |
|
195 | + |
|
196 | + $s.='<br>'; |
|
197 | + |
|
198 | + // Add prospect of a particular level |
|
199 | + $s.=$langs->trans("NatureOfThirdParty").': '; |
|
200 | + $s.='<select name="filter" class="flat">'; |
|
201 | + $sql = "SELECT code, label"; |
|
202 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel"; |
|
203 | + $sql.= " WHERE active > 0"; |
|
204 | + $sql.= " ORDER BY label"; |
|
205 | + $resql = $this->db->query($sql); |
|
206 | + if ($resql) |
|
207 | + { |
|
208 | + $num = $this->db->num_rows($resql); |
|
209 | + if ($num) $s.='<option value="all"> </option>'; |
|
210 | + else $s.='<option value="all">'.$langs->trans("ContactsAllShort").'</option>'; |
|
211 | + $s.='<option value="prospects">'.$langs->trans("ThirdPartyProspects").'</option>'; |
|
212 | + |
|
213 | + $i = 0; |
|
214 | + while ($i < $num) |
|
215 | + { |
|
216 | + $obj = $this->db->fetch_object($resql); |
|
217 | + $level=$langs->trans($obj->code); |
|
218 | + if ($level == $obj->code) $level=$langs->trans($obj->label); |
|
219 | + $s.='<option value="prospectslevel'.$obj->code.'">'.$langs->trans("ThirdPartyProspects").' ('.$langs->trans("ProspectLevelShort").'='.$level.')</option>'; |
|
220 | + $i++; |
|
221 | + } |
|
222 | + } |
|
223 | + else dol_print_error($this->db); |
|
224 | + $s.='<option value="customers">'.$langs->trans("ThirdPartyCustomers").'</option>'; |
|
225 | + //$s.='<option value="customersidprof">'.$langs->trans("ThirdPartyCustomersWithIdProf12",$langs->trans("ProfId1"),$langs->trans("ProfId2")).'</option>'; |
|
226 | + $s.='<option value="suppliers">'.$langs->trans("ThirdPartySuppliers").'</option>'; |
|
227 | + $s.='</select>'; |
|
228 | + |
|
229 | + $s.= ' '; |
|
230 | + |
|
231 | + // Filter on thirdparty category |
|
232 | + $s .= $langs->trans("CustomersProspectsCategoriesShort").': '; |
|
233 | + $sql = "SELECT c.label, count(distinct(sp.email)) AS nb"; |
|
234 | + $sql.= " FROM "; |
|
235 | + $sql.= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
236 | + $sql.= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
237 | + $sql.= " ".MAIN_DB_PREFIX."categorie_societe as cs"; |
|
238 | + $sql.= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
239 | + //$sql.= " AND sp.no_email = 0"; |
|
240 | + //$sql.= " AND sp.email != ''"; |
|
241 | + //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; |
|
242 | + $sql.= " AND cs.fk_categorie = c.rowid"; |
|
243 | + $sql.= " AND cs.fk_soc = sp.fk_soc"; |
|
244 | + $sql.= " GROUP BY c.label"; |
|
245 | + $sql.= " ORDER BY c.label"; |
|
246 | + $resql = $this->db->query($sql); |
|
247 | + |
|
248 | + $s.='<select name="filter_category_customer" class="flat">'; |
|
249 | + $s.='<option value="all"> </option>'; |
|
250 | + if ($resql) |
|
251 | + { |
|
252 | + $num = $this->db->num_rows($resql); |
|
253 | + if ($num) |
|
254 | + { |
|
255 | + $i = 0; |
|
256 | + while ($i < $num) |
|
257 | + { |
|
258 | + $obj = $this->db->fetch_object($resql); |
|
259 | + $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
260 | + $i++; |
|
261 | + } |
|
262 | + } |
|
263 | + else |
|
264 | + { |
|
265 | + $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>'; |
|
266 | + } |
|
267 | + } |
|
268 | + else dol_print_error($this->db); |
|
269 | + $s.='</select>'; |
|
270 | + |
|
271 | + $s.= ' '; |
|
272 | + |
|
273 | + // Filter on thirdparty category |
|
274 | + $s .= $langs->trans("SuppliersCategoriesShort").': '; |
|
275 | + $sql = "SELECT c.label, count(distinct(sp.email)) AS nb"; |
|
276 | + $sql.= " FROM "; |
|
277 | + $sql.= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
278 | + $sql.= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
279 | + $sql.= " ".MAIN_DB_PREFIX."categorie_fournisseur as cs"; |
|
280 | + $sql.= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
281 | + //$sql.= " AND sp.no_email = 0"; |
|
282 | + //$sql.= " AND sp.email != ''"; |
|
283 | + //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; |
|
284 | + $sql.= " AND cs.fk_categorie = c.rowid"; |
|
285 | + $sql.= " AND cs.fk_soc = sp.fk_soc"; |
|
286 | + $sql.= " GROUP BY c.label"; |
|
287 | + $sql.= " ORDER BY c.label"; |
|
288 | + $resql = $this->db->query($sql); |
|
289 | + |
|
290 | + $s.='<select name="filter_category_supplier" class="flat">'; |
|
291 | + $s.='<option value="all"> </option>'; |
|
292 | + if ($resql) |
|
293 | + { |
|
294 | + $num = $this->db->num_rows($resql); |
|
295 | + if ($num) |
|
296 | + { |
|
297 | + $i = 0; |
|
298 | + while ($i < $num) |
|
299 | + { |
|
300 | + $obj = $this->db->fetch_object($resql); |
|
301 | + $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
302 | + $i++; |
|
303 | + } |
|
304 | + } |
|
305 | + else |
|
306 | + { |
|
307 | + $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>'; |
|
308 | + } |
|
309 | + } |
|
310 | + else dol_print_error($this->db); |
|
311 | + $s.='</select>'; |
|
312 | + |
|
313 | + return $s; |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * Renvoie url lien vers fiche de la source du destinataire du mailing |
|
319 | + * |
|
320 | 320 | * @param int $id ID |
321 | - * @return string Url lien |
|
322 | - */ |
|
323 | - function url($id) |
|
324 | - { |
|
325 | - return '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$id.'">'.img_object('',"contact").'</a>'; |
|
326 | - } |
|
321 | + * @return string Url lien |
|
322 | + */ |
|
323 | + function url($id) |
|
324 | + { |
|
325 | + return '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$id.'">'.img_object('',"contact").'</a>'; |
|
326 | + } |
|
327 | 327 | |
328 | 328 | |
329 | 329 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
330 | - /** |
|
331 | - * Ajoute destinataires dans table des cibles |
|
332 | - * |
|
333 | - * @param int $mailing_id Id of emailing |
|
334 | - * @return int <0 si erreur, nb ajout si ok |
|
335 | - */ |
|
336 | - function add_to_target($mailing_id) |
|
337 | - { |
|
330 | + /** |
|
331 | + * Ajoute destinataires dans table des cibles |
|
332 | + * |
|
333 | + * @param int $mailing_id Id of emailing |
|
334 | + * @return int <0 si erreur, nb ajout si ok |
|
335 | + */ |
|
336 | + function add_to_target($mailing_id) |
|
337 | + { |
|
338 | 338 | // phpcs:enable |
339 | - global $conf, $langs; |
|
340 | - |
|
341 | - $filter = GETPOST('filter','alpha'); |
|
342 | - $filter_jobposition = GETPOST('filter_jobposition','alpha'); |
|
343 | - $filter_category = GETPOST('filter_category','alpha'); |
|
344 | - $filter_category_customer = GETPOST('filter_category_customer','alpha'); |
|
345 | - $filter_category_supplier = GETPOST('filter_category_supplier','alpha'); |
|
346 | - |
|
347 | - $cibles = array(); |
|
348 | - |
|
349 | - // List prospects levels |
|
350 | - $prospectlevel=array(); |
|
351 | - $sql = "SELECT code, label"; |
|
352 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel"; |
|
353 | - $sql.= " WHERE active > 0"; |
|
354 | - $sql.= " ORDER BY label"; |
|
355 | - $resql = $this->db->query($sql); |
|
356 | - if ($resql) |
|
357 | - { |
|
358 | - $num = $this->db->num_rows($resql); |
|
359 | - $i = 0; |
|
360 | - while ($i < $num) |
|
361 | - { |
|
362 | - $obj = $this->db->fetch_object($resql); |
|
363 | - $prospectlevel[$obj->code]=$obj->label; |
|
364 | - $i++; |
|
365 | - } |
|
366 | - } |
|
367 | - else dol_print_error($this->db); |
|
368 | - |
|
369 | - // Request must return: id, email, fk_contact, lastname, firstname, other |
|
370 | - $sql = "SELECT sp.rowid as id, sp.email as email, sp.rowid as fk_contact, sp.lastname, sp.firstname, sp.civility as civility_id, sp.poste as jobposition,"; |
|
371 | - $sql.= " s.nom as companyname"; |
|
372 | - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; |
|
373 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc"; |
|
374 | - if ($filter_category <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c"; |
|
375 | - if ($filter_category <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_contact as cs"; |
|
376 | - if ($filter_category_customer <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c2"; |
|
377 | - if ($filter_category_customer <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as c2s"; |
|
378 | - if ($filter_category_supplier <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c3"; |
|
379 | - if ($filter_category_supplier <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_fournisseur as c3s"; |
|
380 | - $sql.= " WHERE sp.entity IN (".getEntity('socpeople').")"; |
|
381 | - $sql.= " AND sp.email <> ''"; |
|
382 | - $sql.= " AND sp.no_email = 0"; |
|
383 | - $sql.= " AND sp.statut = 1"; |
|
384 | - $sql.= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
385 | - // Filter on category |
|
386 | - if ($filter_category <> 'all') $sql.= " AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid"; |
|
387 | - if ($filter_category <> 'all') $sql.= " AND c.label = '".$this->db->escape($filter_category)."'"; |
|
388 | - if ($filter_category_customer <> 'all') $sql.= " AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc"; |
|
389 | - if ($filter_category_customer <> 'all') $sql.= " AND c2.label = '".$this->db->escape($filter_category_customer)."'"; |
|
390 | - if ($filter_category_supplier <> 'all') $sql.= " AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc"; |
|
391 | - if ($filter_category_supplier <> 'all') $sql.= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'"; |
|
392 | - // Filter on nature |
|
393 | - $key = $filter; |
|
394 | - { |
|
395 | - //print "xx".$key; |
|
396 | - if ($key == 'prospects') $sql.= " AND s.client=2"; |
|
397 | - foreach($prospectlevel as $codelevel=>$valuelevel) if ($key == 'prospectslevel'.$codelevel) $sql.= " AND s.fk_prospectlevel='".$codelevel."'"; |
|
398 | - if ($key == 'customers') $sql.= " AND s.client=1"; |
|
399 | - if ($key == 'suppliers') $sql.= " AND s.fournisseur=1"; |
|
400 | - } |
|
401 | - // Filter on job position |
|
402 | - $key = $filter_jobposition; |
|
403 | - if (! empty($key) && $key != 'all') $sql.= " AND sp.poste ='".$this->db->escape($key)."'"; |
|
404 | - $sql.= " ORDER BY sp.email"; |
|
405 | - //print "wwwwwwx".$sql; |
|
406 | - |
|
407 | - // Stocke destinataires dans cibles |
|
408 | - $result=$this->db->query($sql); |
|
409 | - if ($result) |
|
410 | - { |
|
411 | - $num = $this->db->num_rows($result); |
|
412 | - $i = 0; |
|
413 | - $j = 0; |
|
414 | - |
|
415 | - dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found"); |
|
416 | - |
|
417 | - $old = ''; |
|
418 | - while ($i < $num) |
|
419 | - { |
|
420 | - $obj = $this->db->fetch_object($result); |
|
421 | - if ($old <> $obj->email) |
|
422 | - { |
|
423 | - $cibles[$j] = array( |
|
424 | - 'email' => $obj->email, |
|
425 | - 'fk_contact' => $obj->fk_contact, |
|
426 | - 'lastname' => $obj->lastname, |
|
427 | - 'firstname' => $obj->firstname, |
|
428 | - 'other' => |
|
339 | + global $conf, $langs; |
|
340 | + |
|
341 | + $filter = GETPOST('filter','alpha'); |
|
342 | + $filter_jobposition = GETPOST('filter_jobposition','alpha'); |
|
343 | + $filter_category = GETPOST('filter_category','alpha'); |
|
344 | + $filter_category_customer = GETPOST('filter_category_customer','alpha'); |
|
345 | + $filter_category_supplier = GETPOST('filter_category_supplier','alpha'); |
|
346 | + |
|
347 | + $cibles = array(); |
|
348 | + |
|
349 | + // List prospects levels |
|
350 | + $prospectlevel=array(); |
|
351 | + $sql = "SELECT code, label"; |
|
352 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel"; |
|
353 | + $sql.= " WHERE active > 0"; |
|
354 | + $sql.= " ORDER BY label"; |
|
355 | + $resql = $this->db->query($sql); |
|
356 | + if ($resql) |
|
357 | + { |
|
358 | + $num = $this->db->num_rows($resql); |
|
359 | + $i = 0; |
|
360 | + while ($i < $num) |
|
361 | + { |
|
362 | + $obj = $this->db->fetch_object($resql); |
|
363 | + $prospectlevel[$obj->code]=$obj->label; |
|
364 | + $i++; |
|
365 | + } |
|
366 | + } |
|
367 | + else dol_print_error($this->db); |
|
368 | + |
|
369 | + // Request must return: id, email, fk_contact, lastname, firstname, other |
|
370 | + $sql = "SELECT sp.rowid as id, sp.email as email, sp.rowid as fk_contact, sp.lastname, sp.firstname, sp.civility as civility_id, sp.poste as jobposition,"; |
|
371 | + $sql.= " s.nom as companyname"; |
|
372 | + $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; |
|
373 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc"; |
|
374 | + if ($filter_category <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c"; |
|
375 | + if ($filter_category <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_contact as cs"; |
|
376 | + if ($filter_category_customer <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c2"; |
|
377 | + if ($filter_category_customer <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as c2s"; |
|
378 | + if ($filter_category_supplier <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c3"; |
|
379 | + if ($filter_category_supplier <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_fournisseur as c3s"; |
|
380 | + $sql.= " WHERE sp.entity IN (".getEntity('socpeople').")"; |
|
381 | + $sql.= " AND sp.email <> ''"; |
|
382 | + $sql.= " AND sp.no_email = 0"; |
|
383 | + $sql.= " AND sp.statut = 1"; |
|
384 | + $sql.= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
385 | + // Filter on category |
|
386 | + if ($filter_category <> 'all') $sql.= " AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid"; |
|
387 | + if ($filter_category <> 'all') $sql.= " AND c.label = '".$this->db->escape($filter_category)."'"; |
|
388 | + if ($filter_category_customer <> 'all') $sql.= " AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc"; |
|
389 | + if ($filter_category_customer <> 'all') $sql.= " AND c2.label = '".$this->db->escape($filter_category_customer)."'"; |
|
390 | + if ($filter_category_supplier <> 'all') $sql.= " AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc"; |
|
391 | + if ($filter_category_supplier <> 'all') $sql.= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'"; |
|
392 | + // Filter on nature |
|
393 | + $key = $filter; |
|
394 | + { |
|
395 | + //print "xx".$key; |
|
396 | + if ($key == 'prospects') $sql.= " AND s.client=2"; |
|
397 | + foreach($prospectlevel as $codelevel=>$valuelevel) if ($key == 'prospectslevel'.$codelevel) $sql.= " AND s.fk_prospectlevel='".$codelevel."'"; |
|
398 | + if ($key == 'customers') $sql.= " AND s.client=1"; |
|
399 | + if ($key == 'suppliers') $sql.= " AND s.fournisseur=1"; |
|
400 | + } |
|
401 | + // Filter on job position |
|
402 | + $key = $filter_jobposition; |
|
403 | + if (! empty($key) && $key != 'all') $sql.= " AND sp.poste ='".$this->db->escape($key)."'"; |
|
404 | + $sql.= " ORDER BY sp.email"; |
|
405 | + //print "wwwwwwx".$sql; |
|
406 | + |
|
407 | + // Stocke destinataires dans cibles |
|
408 | + $result=$this->db->query($sql); |
|
409 | + if ($result) |
|
410 | + { |
|
411 | + $num = $this->db->num_rows($result); |
|
412 | + $i = 0; |
|
413 | + $j = 0; |
|
414 | + |
|
415 | + dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found"); |
|
416 | + |
|
417 | + $old = ''; |
|
418 | + while ($i < $num) |
|
419 | + { |
|
420 | + $obj = $this->db->fetch_object($result); |
|
421 | + if ($old <> $obj->email) |
|
422 | + { |
|
423 | + $cibles[$j] = array( |
|
424 | + 'email' => $obj->email, |
|
425 | + 'fk_contact' => $obj->fk_contact, |
|
426 | + 'lastname' => $obj->lastname, |
|
427 | + 'firstname' => $obj->firstname, |
|
428 | + 'other' => |
|
429 | 429 | ($langs->transnoentities("ThirdParty").'='.$obj->companyname).';'. |
430 | 430 | ($langs->transnoentities("UserTitle").'='.($obj->civility_id?$langs->transnoentities("Civility".$obj->civility_id):'')).';'. |
431 | 431 | ($langs->transnoentities("JobPosition").'='.$obj->jobposition), |
432 | - 'source_url' => $this->url($obj->id), |
|
432 | + 'source_url' => $this->url($obj->id), |
|
433 | 433 | 'source_id' => $obj->id, |
434 | 434 | 'source_type' => 'contact' |
435 | - ); |
|
436 | - $old = $obj->email; |
|
437 | - $j++; |
|
438 | - } |
|
439 | - |
|
440 | - $i++; |
|
441 | - } |
|
442 | - } |
|
443 | - else |
|
444 | - { |
|
445 | - dol_syslog($this->db->error()); |
|
446 | - $this->error=$this->db->error(); |
|
447 | - return -1; |
|
448 | - } |
|
449 | - |
|
450 | - return parent::add_to_target($mailing_id, $cibles); |
|
451 | - } |
|
435 | + ); |
|
436 | + $old = $obj->email; |
|
437 | + $j++; |
|
438 | + } |
|
439 | + |
|
440 | + $i++; |
|
441 | + } |
|
442 | + } |
|
443 | + else |
|
444 | + { |
|
445 | + dol_syslog($this->db->error()); |
|
446 | + $this->error=$this->db->error(); |
|
447 | + return -1; |
|
448 | + } |
|
449 | + |
|
450 | + return parent::add_to_target($mailing_id, $cibles); |
|
451 | + } |
|
452 | 452 | } |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | */ |
33 | 33 | class mailing_contacts1 extends MailingTargets |
34 | 34 | { |
35 | - var $name='ContactCompanies'; // Identifiant du module mailing |
|
35 | + var $name = 'ContactCompanies'; // Identifiant du module mailing |
|
36 | 36 | // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
37 | - var $desc='Contacts of thirdparties (prospects, customers, suppliers...)'; |
|
38 | - var $require_module=array("societe"); // Module mailing actif si modules require_module actifs |
|
39 | - var $require_admin=0; // Module mailing actif pour user admin ou non |
|
40 | - var $picto='contact'; |
|
37 | + var $desc = 'Contacts of thirdparties (prospects, customers, suppliers...)'; |
|
38 | + var $require_module = array("societe"); // Module mailing actif si modules require_module actifs |
|
39 | + var $require_admin = 0; // Module mailing actif pour user admin ou non |
|
40 | + var $picto = 'contact'; |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * @var DoliDB Database handler. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | */ |
53 | 53 | function __construct($db) |
54 | 54 | { |
55 | - $this->db=$db; |
|
55 | + $this->db = $db; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | |
@@ -70,14 +70,14 @@ discard block |
||
70 | 70 | |
71 | 71 | $langs->load("commercial"); |
72 | 72 | |
73 | - $statssql=array(); |
|
73 | + $statssql = array(); |
|
74 | 74 | $statssql[0] = "SELECT '".$langs->trans("NbOfCompaniesContacts")."' as label,"; |
75 | - $statssql[0].= " count(distinct(c.email)) as nb"; |
|
76 | - $statssql[0].= " FROM ".MAIN_DB_PREFIX."socpeople as c"; |
|
77 | - $statssql[0].= " WHERE c.entity IN (".getEntity('socpeople').")"; |
|
78 | - $statssql[0].= " AND c.email != ''"; // Note that null != '' is false |
|
79 | - $statssql[0].= " AND c.no_email = 0"; |
|
80 | - $statssql[0].= " AND c.statut = 1"; |
|
75 | + $statssql[0] .= " count(distinct(c.email)) as nb"; |
|
76 | + $statssql[0] .= " FROM ".MAIN_DB_PREFIX."socpeople as c"; |
|
77 | + $statssql[0] .= " WHERE c.entity IN (".getEntity('socpeople').")"; |
|
78 | + $statssql[0] .= " AND c.email != ''"; // Note that null != '' is false |
|
79 | + $statssql[0] .= " AND c.no_email = 0"; |
|
80 | + $statssql[0] .= " AND c.statut = 1"; |
|
81 | 81 | |
82 | 82 | return $statssql; |
83 | 83 | } |
@@ -91,17 +91,17 @@ discard block |
||
91 | 91 | * @param string $sql Requete sql de comptage |
92 | 92 | * @return int |
93 | 93 | */ |
94 | - function getNbOfRecipients($sql='') |
|
94 | + function getNbOfRecipients($sql = '') |
|
95 | 95 | { |
96 | 96 | global $conf; |
97 | 97 | |
98 | - $sql = "SELECT count(distinct(c.email)) as nb"; |
|
99 | - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c"; |
|
100 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc"; |
|
101 | - $sql.= " WHERE c.entity IN (".getEntity('socpeople').")"; |
|
102 | - $sql.= " AND c.email != ''"; // Note that null != '' is false |
|
103 | - $sql.= " AND c.no_email = 0"; |
|
104 | - $sql.= " AND c.statut = 1"; |
|
98 | + $sql = "SELECT count(distinct(c.email)) as nb"; |
|
99 | + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c"; |
|
100 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = c.fk_soc"; |
|
101 | + $sql .= " WHERE c.entity IN (".getEntity('socpeople').")"; |
|
102 | + $sql .= " AND c.email != ''"; // Note that null != '' is false |
|
103 | + $sql .= " AND c.no_email = 0"; |
|
104 | + $sql .= " AND c.statut = 1"; |
|
105 | 105 | |
106 | 106 | // The request must return a field called "nb" to be understandable by parent::getNbOfRecipients |
107 | 107 | return parent::getNbOfRecipients($sql); |
@@ -118,25 +118,25 @@ discard block |
||
118 | 118 | global $langs; |
119 | 119 | |
120 | 120 | // Load translation files required by the page |
121 | - $langs->loadLangs(array("commercial","companies","suppliers","categories")); |
|
121 | + $langs->loadLangs(array("commercial", "companies", "suppliers", "categories")); |
|
122 | 122 | |
123 | - $s=''; |
|
123 | + $s = ''; |
|
124 | 124 | |
125 | 125 | // Add filter on job position |
126 | 126 | $sql = "SELECT sp.poste, count(distinct(sp.email)) AS nb"; |
127 | - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; |
|
128 | - $sql.= " WHERE sp.entity IN (".getEntity('socpeople').")"; |
|
127 | + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; |
|
128 | + $sql .= " WHERE sp.entity IN (".getEntity('socpeople').")"; |
|
129 | 129 | /*$sql.= " AND sp.email != ''"; // Note that null != '' is false |
130 | 130 | $sql.= " AND sp.no_email = 0"; |
131 | 131 | $sql.= " AND sp.statut = 1";*/ |
132 | - $sql.= " AND (sp.poste IS NOT NULL AND sp.poste != '')"; |
|
133 | - $sql.= " GROUP BY sp.poste"; |
|
134 | - $sql.= " ORDER BY sp.poste"; |
|
132 | + $sql .= " AND (sp.poste IS NOT NULL AND sp.poste != '')"; |
|
133 | + $sql .= " GROUP BY sp.poste"; |
|
134 | + $sql .= " ORDER BY sp.poste"; |
|
135 | 135 | $resql = $this->db->query($sql); |
136 | 136 | |
137 | - $s.=$langs->trans("PostOrFunction").': '; |
|
138 | - $s.='<select name="filter_jobposition" class="flat">'; |
|
139 | - $s.='<option value="all"> </option>'; |
|
137 | + $s .= $langs->trans("PostOrFunction").': '; |
|
138 | + $s .= '<select name="filter_jobposition" class="flat">'; |
|
139 | + $s .= '<option value="all"> </option>'; |
|
140 | 140 | if ($resql) |
141 | 141 | { |
142 | 142 | $num = $this->db->num_rows($resql); |
@@ -144,34 +144,34 @@ discard block |
||
144 | 144 | while ($i < $num) |
145 | 145 | { |
146 | 146 | $obj = $this->db->fetch_object($resql); |
147 | - $s.='<option value="'.dol_escape_htmltag($obj->poste).'">'.dol_escape_htmltag($obj->poste).' ('.$obj->nb.')</option>'; |
|
147 | + $s .= '<option value="'.dol_escape_htmltag($obj->poste).'">'.dol_escape_htmltag($obj->poste).' ('.$obj->nb.')</option>'; |
|
148 | 148 | $i++; |
149 | 149 | } |
150 | 150 | } |
151 | 151 | else dol_print_error($this->db); |
152 | - $s.='</select>'; |
|
152 | + $s .= '</select>'; |
|
153 | 153 | |
154 | - $s.=' '; |
|
154 | + $s .= ' '; |
|
155 | 155 | |
156 | 156 | // Filter on contact category |
157 | 157 | $s .= $langs->trans("ContactCategoriesShort").': '; |
158 | 158 | $sql = "SELECT c.label, count(distinct(sp.email)) AS nb"; |
159 | - $sql.= " FROM "; |
|
160 | - $sql.= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
161 | - $sql.= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
162 | - $sql.= " ".MAIN_DB_PREFIX."categorie_contact as cs"; |
|
163 | - $sql.= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
159 | + $sql .= " FROM "; |
|
160 | + $sql .= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
161 | + $sql .= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
162 | + $sql .= " ".MAIN_DB_PREFIX."categorie_contact as cs"; |
|
163 | + $sql .= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
164 | 164 | //$sql.= " AND sp.no_email = 0"; |
165 | 165 | //$sql.= " AND sp.email != ''"; |
166 | 166 | //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; |
167 | - $sql.= " AND cs.fk_categorie = c.rowid"; |
|
168 | - $sql.= " AND cs.fk_socpeople = sp.rowid"; |
|
169 | - $sql.= " GROUP BY c.label"; |
|
170 | - $sql.= " ORDER BY c.label"; |
|
167 | + $sql .= " AND cs.fk_categorie = c.rowid"; |
|
168 | + $sql .= " AND cs.fk_socpeople = sp.rowid"; |
|
169 | + $sql .= " GROUP BY c.label"; |
|
170 | + $sql .= " ORDER BY c.label"; |
|
171 | 171 | $resql = $this->db->query($sql); |
172 | 172 | |
173 | - $s.='<select name="filter_category" class="flat">'; |
|
174 | - $s.='<option value="all"> </option>'; |
|
173 | + $s .= '<select name="filter_category" class="flat">'; |
|
174 | + $s .= '<option value="all"> </option>'; |
|
175 | 175 | if ($resql) |
176 | 176 | { |
177 | 177 | $num = $this->db->num_rows($resql); |
@@ -181,72 +181,72 @@ discard block |
||
181 | 181 | while ($i < $num) |
182 | 182 | { |
183 | 183 | $obj = $this->db->fetch_object($resql); |
184 | - $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
184 | + $s .= '<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
185 | 185 | $i++; |
186 | 186 | } |
187 | 187 | } |
188 | 188 | else |
189 | 189 | { |
190 | - $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactWithCategoryFound").'</option>'; |
|
190 | + $s .= '<option value="-1" disabled="disabled">'.$langs->trans("NoContactWithCategoryFound").'</option>'; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | else dol_print_error($this->db); |
194 | - $s.='</select>'; |
|
194 | + $s .= '</select>'; |
|
195 | 195 | |
196 | - $s.='<br>'; |
|
196 | + $s .= '<br>'; |
|
197 | 197 | |
198 | 198 | // Add prospect of a particular level |
199 | - $s.=$langs->trans("NatureOfThirdParty").': '; |
|
200 | - $s.='<select name="filter" class="flat">'; |
|
199 | + $s .= $langs->trans("NatureOfThirdParty").': '; |
|
200 | + $s .= '<select name="filter" class="flat">'; |
|
201 | 201 | $sql = "SELECT code, label"; |
202 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel"; |
|
203 | - $sql.= " WHERE active > 0"; |
|
204 | - $sql.= " ORDER BY label"; |
|
202 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel"; |
|
203 | + $sql .= " WHERE active > 0"; |
|
204 | + $sql .= " ORDER BY label"; |
|
205 | 205 | $resql = $this->db->query($sql); |
206 | 206 | if ($resql) |
207 | 207 | { |
208 | 208 | $num = $this->db->num_rows($resql); |
209 | - if ($num) $s.='<option value="all"> </option>'; |
|
210 | - else $s.='<option value="all">'.$langs->trans("ContactsAllShort").'</option>'; |
|
211 | - $s.='<option value="prospects">'.$langs->trans("ThirdPartyProspects").'</option>'; |
|
209 | + if ($num) $s .= '<option value="all"> </option>'; |
|
210 | + else $s .= '<option value="all">'.$langs->trans("ContactsAllShort").'</option>'; |
|
211 | + $s .= '<option value="prospects">'.$langs->trans("ThirdPartyProspects").'</option>'; |
|
212 | 212 | |
213 | 213 | $i = 0; |
214 | 214 | while ($i < $num) |
215 | 215 | { |
216 | 216 | $obj = $this->db->fetch_object($resql); |
217 | - $level=$langs->trans($obj->code); |
|
218 | - if ($level == $obj->code) $level=$langs->trans($obj->label); |
|
219 | - $s.='<option value="prospectslevel'.$obj->code.'">'.$langs->trans("ThirdPartyProspects").' ('.$langs->trans("ProspectLevelShort").'='.$level.')</option>'; |
|
217 | + $level = $langs->trans($obj->code); |
|
218 | + if ($level == $obj->code) $level = $langs->trans($obj->label); |
|
219 | + $s .= '<option value="prospectslevel'.$obj->code.'">'.$langs->trans("ThirdPartyProspects").' ('.$langs->trans("ProspectLevelShort").'='.$level.')</option>'; |
|
220 | 220 | $i++; |
221 | 221 | } |
222 | 222 | } |
223 | 223 | else dol_print_error($this->db); |
224 | - $s.='<option value="customers">'.$langs->trans("ThirdPartyCustomers").'</option>'; |
|
224 | + $s .= '<option value="customers">'.$langs->trans("ThirdPartyCustomers").'</option>'; |
|
225 | 225 | //$s.='<option value="customersidprof">'.$langs->trans("ThirdPartyCustomersWithIdProf12",$langs->trans("ProfId1"),$langs->trans("ProfId2")).'</option>'; |
226 | - $s.='<option value="suppliers">'.$langs->trans("ThirdPartySuppliers").'</option>'; |
|
227 | - $s.='</select>'; |
|
226 | + $s .= '<option value="suppliers">'.$langs->trans("ThirdPartySuppliers").'</option>'; |
|
227 | + $s .= '</select>'; |
|
228 | 228 | |
229 | - $s.= ' '; |
|
229 | + $s .= ' '; |
|
230 | 230 | |
231 | 231 | // Filter on thirdparty category |
232 | 232 | $s .= $langs->trans("CustomersProspectsCategoriesShort").': '; |
233 | 233 | $sql = "SELECT c.label, count(distinct(sp.email)) AS nb"; |
234 | - $sql.= " FROM "; |
|
235 | - $sql.= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
236 | - $sql.= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
237 | - $sql.= " ".MAIN_DB_PREFIX."categorie_societe as cs"; |
|
238 | - $sql.= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
234 | + $sql .= " FROM "; |
|
235 | + $sql .= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
236 | + $sql .= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
237 | + $sql .= " ".MAIN_DB_PREFIX."categorie_societe as cs"; |
|
238 | + $sql .= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
239 | 239 | //$sql.= " AND sp.no_email = 0"; |
240 | 240 | //$sql.= " AND sp.email != ''"; |
241 | 241 | //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; |
242 | - $sql.= " AND cs.fk_categorie = c.rowid"; |
|
243 | - $sql.= " AND cs.fk_soc = sp.fk_soc"; |
|
244 | - $sql.= " GROUP BY c.label"; |
|
245 | - $sql.= " ORDER BY c.label"; |
|
242 | + $sql .= " AND cs.fk_categorie = c.rowid"; |
|
243 | + $sql .= " AND cs.fk_soc = sp.fk_soc"; |
|
244 | + $sql .= " GROUP BY c.label"; |
|
245 | + $sql .= " ORDER BY c.label"; |
|
246 | 246 | $resql = $this->db->query($sql); |
247 | 247 | |
248 | - $s.='<select name="filter_category_customer" class="flat">'; |
|
249 | - $s.='<option value="all"> </option>'; |
|
248 | + $s .= '<select name="filter_category_customer" class="flat">'; |
|
249 | + $s .= '<option value="all"> </option>'; |
|
250 | 250 | if ($resql) |
251 | 251 | { |
252 | 252 | $num = $this->db->num_rows($resql); |
@@ -256,39 +256,39 @@ discard block |
||
256 | 256 | while ($i < $num) |
257 | 257 | { |
258 | 258 | $obj = $this->db->fetch_object($resql); |
259 | - $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
259 | + $s .= '<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
260 | 260 | $i++; |
261 | 261 | } |
262 | 262 | } |
263 | 263 | else |
264 | 264 | { |
265 | - $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>'; |
|
265 | + $s .= '<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>'; |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | else dol_print_error($this->db); |
269 | - $s.='</select>'; |
|
269 | + $s .= '</select>'; |
|
270 | 270 | |
271 | - $s.= ' '; |
|
271 | + $s .= ' '; |
|
272 | 272 | |
273 | 273 | // Filter on thirdparty category |
274 | 274 | $s .= $langs->trans("SuppliersCategoriesShort").': '; |
275 | 275 | $sql = "SELECT c.label, count(distinct(sp.email)) AS nb"; |
276 | - $sql.= " FROM "; |
|
277 | - $sql.= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
278 | - $sql.= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
279 | - $sql.= " ".MAIN_DB_PREFIX."categorie_fournisseur as cs"; |
|
280 | - $sql.= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
276 | + $sql .= " FROM "; |
|
277 | + $sql .= " ".MAIN_DB_PREFIX."socpeople as sp,"; |
|
278 | + $sql .= " ".MAIN_DB_PREFIX."categorie as c,"; |
|
279 | + $sql .= " ".MAIN_DB_PREFIX."categorie_fournisseur as cs"; |
|
280 | + $sql .= " WHERE sp.statut = 1"; // Note that null != '' is false |
|
281 | 281 | //$sql.= " AND sp.no_email = 0"; |
282 | 282 | //$sql.= " AND sp.email != ''"; |
283 | 283 | //$sql.= " AND sp.entity IN (".getEntity('socpeople').")"; |
284 | - $sql.= " AND cs.fk_categorie = c.rowid"; |
|
285 | - $sql.= " AND cs.fk_soc = sp.fk_soc"; |
|
286 | - $sql.= " GROUP BY c.label"; |
|
287 | - $sql.= " ORDER BY c.label"; |
|
284 | + $sql .= " AND cs.fk_categorie = c.rowid"; |
|
285 | + $sql .= " AND cs.fk_soc = sp.fk_soc"; |
|
286 | + $sql .= " GROUP BY c.label"; |
|
287 | + $sql .= " ORDER BY c.label"; |
|
288 | 288 | $resql = $this->db->query($sql); |
289 | 289 | |
290 | - $s.='<select name="filter_category_supplier" class="flat">'; |
|
291 | - $s.='<option value="all"> </option>'; |
|
290 | + $s .= '<select name="filter_category_supplier" class="flat">'; |
|
291 | + $s .= '<option value="all"> </option>'; |
|
292 | 292 | if ($resql) |
293 | 293 | { |
294 | 294 | $num = $this->db->num_rows($resql); |
@@ -298,17 +298,17 @@ discard block |
||
298 | 298 | while ($i < $num) |
299 | 299 | { |
300 | 300 | $obj = $this->db->fetch_object($resql); |
301 | - $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
301 | + $s .= '<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
|
302 | 302 | $i++; |
303 | 303 | } |
304 | 304 | } |
305 | 305 | else |
306 | 306 | { |
307 | - $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>'; |
|
307 | + $s .= '<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>'; |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | else dol_print_error($this->db); |
311 | - $s.='</select>'; |
|
311 | + $s .= '</select>'; |
|
312 | 312 | |
313 | 313 | return $s; |
314 | 314 | } |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | */ |
323 | 323 | function url($id) |
324 | 324 | { |
325 | - return '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$id.'">'.img_object('',"contact").'</a>'; |
|
325 | + return '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$id.'">'.img_object('', "contact").'</a>'; |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | |
@@ -338,20 +338,20 @@ discard block |
||
338 | 338 | // phpcs:enable |
339 | 339 | global $conf, $langs; |
340 | 340 | |
341 | - $filter = GETPOST('filter','alpha'); |
|
342 | - $filter_jobposition = GETPOST('filter_jobposition','alpha'); |
|
343 | - $filter_category = GETPOST('filter_category','alpha'); |
|
344 | - $filter_category_customer = GETPOST('filter_category_customer','alpha'); |
|
345 | - $filter_category_supplier = GETPOST('filter_category_supplier','alpha'); |
|
341 | + $filter = GETPOST('filter', 'alpha'); |
|
342 | + $filter_jobposition = GETPOST('filter_jobposition', 'alpha'); |
|
343 | + $filter_category = GETPOST('filter_category', 'alpha'); |
|
344 | + $filter_category_customer = GETPOST('filter_category_customer', 'alpha'); |
|
345 | + $filter_category_supplier = GETPOST('filter_category_supplier', 'alpha'); |
|
346 | 346 | |
347 | 347 | $cibles = array(); |
348 | 348 | |
349 | 349 | // List prospects levels |
350 | - $prospectlevel=array(); |
|
350 | + $prospectlevel = array(); |
|
351 | 351 | $sql = "SELECT code, label"; |
352 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel"; |
|
353 | - $sql.= " WHERE active > 0"; |
|
354 | - $sql.= " ORDER BY label"; |
|
352 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel"; |
|
353 | + $sql .= " WHERE active > 0"; |
|
354 | + $sql .= " ORDER BY label"; |
|
355 | 355 | $resql = $this->db->query($sql); |
356 | 356 | if ($resql) |
357 | 357 | { |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | while ($i < $num) |
361 | 361 | { |
362 | 362 | $obj = $this->db->fetch_object($resql); |
363 | - $prospectlevel[$obj->code]=$obj->label; |
|
363 | + $prospectlevel[$obj->code] = $obj->label; |
|
364 | 364 | $i++; |
365 | 365 | } |
366 | 366 | } |
@@ -368,44 +368,44 @@ discard block |
||
368 | 368 | |
369 | 369 | // Request must return: id, email, fk_contact, lastname, firstname, other |
370 | 370 | $sql = "SELECT sp.rowid as id, sp.email as email, sp.rowid as fk_contact, sp.lastname, sp.firstname, sp.civility as civility_id, sp.poste as jobposition,"; |
371 | - $sql.= " s.nom as companyname"; |
|
372 | - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; |
|
373 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc"; |
|
374 | - if ($filter_category <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c"; |
|
375 | - if ($filter_category <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_contact as cs"; |
|
376 | - if ($filter_category_customer <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c2"; |
|
377 | - if ($filter_category_customer <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as c2s"; |
|
378 | - if ($filter_category_supplier <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c3"; |
|
379 | - if ($filter_category_supplier <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_fournisseur as c3s"; |
|
380 | - $sql.= " WHERE sp.entity IN (".getEntity('socpeople').")"; |
|
381 | - $sql.= " AND sp.email <> ''"; |
|
382 | - $sql.= " AND sp.no_email = 0"; |
|
383 | - $sql.= " AND sp.statut = 1"; |
|
384 | - $sql.= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
371 | + $sql .= " s.nom as companyname"; |
|
372 | + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; |
|
373 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc"; |
|
374 | + if ($filter_category <> 'all') $sql .= ", ".MAIN_DB_PREFIX."categorie as c"; |
|
375 | + if ($filter_category <> 'all') $sql .= ", ".MAIN_DB_PREFIX."categorie_contact as cs"; |
|
376 | + if ($filter_category_customer <> 'all') $sql .= ", ".MAIN_DB_PREFIX."categorie as c2"; |
|
377 | + if ($filter_category_customer <> 'all') $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c2s"; |
|
378 | + if ($filter_category_supplier <> 'all') $sql .= ", ".MAIN_DB_PREFIX."categorie as c3"; |
|
379 | + if ($filter_category_supplier <> 'all') $sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as c3s"; |
|
380 | + $sql .= " WHERE sp.entity IN (".getEntity('socpeople').")"; |
|
381 | + $sql .= " AND sp.email <> ''"; |
|
382 | + $sql .= " AND sp.no_email = 0"; |
|
383 | + $sql .= " AND sp.statut = 1"; |
|
384 | + $sql .= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
385 | 385 | // Filter on category |
386 | - if ($filter_category <> 'all') $sql.= " AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid"; |
|
387 | - if ($filter_category <> 'all') $sql.= " AND c.label = '".$this->db->escape($filter_category)."'"; |
|
388 | - if ($filter_category_customer <> 'all') $sql.= " AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc"; |
|
389 | - if ($filter_category_customer <> 'all') $sql.= " AND c2.label = '".$this->db->escape($filter_category_customer)."'"; |
|
390 | - if ($filter_category_supplier <> 'all') $sql.= " AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc"; |
|
391 | - if ($filter_category_supplier <> 'all') $sql.= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'"; |
|
386 | + if ($filter_category <> 'all') $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid"; |
|
387 | + if ($filter_category <> 'all') $sql .= " AND c.label = '".$this->db->escape($filter_category)."'"; |
|
388 | + if ($filter_category_customer <> 'all') $sql .= " AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc"; |
|
389 | + if ($filter_category_customer <> 'all') $sql .= " AND c2.label = '".$this->db->escape($filter_category_customer)."'"; |
|
390 | + if ($filter_category_supplier <> 'all') $sql .= " AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc"; |
|
391 | + if ($filter_category_supplier <> 'all') $sql .= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'"; |
|
392 | 392 | // Filter on nature |
393 | 393 | $key = $filter; |
394 | 394 | { |
395 | 395 | //print "xx".$key; |
396 | - if ($key == 'prospects') $sql.= " AND s.client=2"; |
|
397 | - foreach($prospectlevel as $codelevel=>$valuelevel) if ($key == 'prospectslevel'.$codelevel) $sql.= " AND s.fk_prospectlevel='".$codelevel."'"; |
|
398 | - if ($key == 'customers') $sql.= " AND s.client=1"; |
|
399 | - if ($key == 'suppliers') $sql.= " AND s.fournisseur=1"; |
|
396 | + if ($key == 'prospects') $sql .= " AND s.client=2"; |
|
397 | + foreach ($prospectlevel as $codelevel=>$valuelevel) if ($key == 'prospectslevel'.$codelevel) $sql .= " AND s.fk_prospectlevel='".$codelevel."'"; |
|
398 | + if ($key == 'customers') $sql .= " AND s.client=1"; |
|
399 | + if ($key == 'suppliers') $sql .= " AND s.fournisseur=1"; |
|
400 | 400 | } |
401 | 401 | // Filter on job position |
402 | 402 | $key = $filter_jobposition; |
403 | - if (! empty($key) && $key != 'all') $sql.= " AND sp.poste ='".$this->db->escape($key)."'"; |
|
404 | - $sql.= " ORDER BY sp.email"; |
|
403 | + if (!empty($key) && $key != 'all') $sql .= " AND sp.poste ='".$this->db->escape($key)."'"; |
|
404 | + $sql .= " ORDER BY sp.email"; |
|
405 | 405 | //print "wwwwwwx".$sql; |
406 | 406 | |
407 | 407 | // Stocke destinataires dans cibles |
408 | - $result=$this->db->query($sql); |
|
408 | + $result = $this->db->query($sql); |
|
409 | 409 | if ($result) |
410 | 410 | { |
411 | 411 | $num = $this->db->num_rows($result); |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | 'firstname' => $obj->firstname, |
428 | 428 | 'other' => |
429 | 429 | ($langs->transnoentities("ThirdParty").'='.$obj->companyname).';'. |
430 | - ($langs->transnoentities("UserTitle").'='.($obj->civility_id?$langs->transnoentities("Civility".$obj->civility_id):'')).';'. |
|
430 | + ($langs->transnoentities("UserTitle").'='.($obj->civility_id ? $langs->transnoentities("Civility".$obj->civility_id) : '')).';'. |
|
431 | 431 | ($langs->transnoentities("JobPosition").'='.$obj->jobposition), |
432 | 432 | 'source_url' => $this->url($obj->id), |
433 | 433 | 'source_id' => $obj->id, |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | else |
444 | 444 | { |
445 | 445 | dol_syslog($this->db->error()); |
446 | - $this->error=$this->db->error(); |
|
446 | + $this->error = $this->db->error(); |
|
447 | 447 | return -1; |
448 | 448 | } |
449 | 449 |
@@ -147,8 +147,9 @@ discard block |
||
147 | 147 | $s.='<option value="'.dol_escape_htmltag($obj->poste).'">'.dol_escape_htmltag($obj->poste).' ('.$obj->nb.')</option>'; |
148 | 148 | $i++; |
149 | 149 | } |
150 | + } else { |
|
151 | + dol_print_error($this->db); |
|
150 | 152 | } |
151 | - else dol_print_error($this->db); |
|
152 | 153 | $s.='</select>'; |
153 | 154 | |
154 | 155 | $s.=' '; |
@@ -184,13 +185,13 @@ discard block |
||
184 | 185 | $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
185 | 186 | $i++; |
186 | 187 | } |
187 | - } |
|
188 | - else |
|
188 | + } else |
|
189 | 189 | { |
190 | 190 | $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactWithCategoryFound").'</option>'; |
191 | 191 | } |
192 | + } else { |
|
193 | + dol_print_error($this->db); |
|
192 | 194 | } |
193 | - else dol_print_error($this->db); |
|
194 | 195 | $s.='</select>'; |
195 | 196 | |
196 | 197 | $s.='<br>'; |
@@ -206,8 +207,11 @@ discard block |
||
206 | 207 | if ($resql) |
207 | 208 | { |
208 | 209 | $num = $this->db->num_rows($resql); |
209 | - if ($num) $s.='<option value="all"> </option>'; |
|
210 | - else $s.='<option value="all">'.$langs->trans("ContactsAllShort").'</option>'; |
|
210 | + if ($num) { |
|
211 | + $s.='<option value="all"> </option>'; |
|
212 | + } else { |
|
213 | + $s.='<option value="all">'.$langs->trans("ContactsAllShort").'</option>'; |
|
214 | + } |
|
211 | 215 | $s.='<option value="prospects">'.$langs->trans("ThirdPartyProspects").'</option>'; |
212 | 216 | |
213 | 217 | $i = 0; |
@@ -215,12 +219,15 @@ discard block |
||
215 | 219 | { |
216 | 220 | $obj = $this->db->fetch_object($resql); |
217 | 221 | $level=$langs->trans($obj->code); |
218 | - if ($level == $obj->code) $level=$langs->trans($obj->label); |
|
222 | + if ($level == $obj->code) { |
|
223 | + $level=$langs->trans($obj->label); |
|
224 | + } |
|
219 | 225 | $s.='<option value="prospectslevel'.$obj->code.'">'.$langs->trans("ThirdPartyProspects").' ('.$langs->trans("ProspectLevelShort").'='.$level.')</option>'; |
220 | 226 | $i++; |
221 | 227 | } |
228 | + } else { |
|
229 | + dol_print_error($this->db); |
|
222 | 230 | } |
223 | - else dol_print_error($this->db); |
|
224 | 231 | $s.='<option value="customers">'.$langs->trans("ThirdPartyCustomers").'</option>'; |
225 | 232 | //$s.='<option value="customersidprof">'.$langs->trans("ThirdPartyCustomersWithIdProf12",$langs->trans("ProfId1"),$langs->trans("ProfId2")).'</option>'; |
226 | 233 | $s.='<option value="suppliers">'.$langs->trans("ThirdPartySuppliers").'</option>'; |
@@ -259,13 +266,13 @@ discard block |
||
259 | 266 | $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
260 | 267 | $i++; |
261 | 268 | } |
262 | - } |
|
263 | - else |
|
269 | + } else |
|
264 | 270 | { |
265 | 271 | $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>'; |
266 | 272 | } |
273 | + } else { |
|
274 | + dol_print_error($this->db); |
|
267 | 275 | } |
268 | - else dol_print_error($this->db); |
|
269 | 276 | $s.='</select>'; |
270 | 277 | |
271 | 278 | $s.= ' '; |
@@ -301,13 +308,13 @@ discard block |
||
301 | 308 | $s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>'; |
302 | 309 | $i++; |
303 | 310 | } |
304 | - } |
|
305 | - else |
|
311 | + } else |
|
306 | 312 | { |
307 | 313 | $s.='<option value="-1" disabled="disabled">'.$langs->trans("NoContactLinkedToThirdpartieWithCategoryFound").'</option>'; |
308 | 314 | } |
315 | + } else { |
|
316 | + dol_print_error($this->db); |
|
309 | 317 | } |
310 | - else dol_print_error($this->db); |
|
311 | 318 | $s.='</select>'; |
312 | 319 | |
313 | 320 | return $s; |
@@ -363,44 +370,79 @@ discard block |
||
363 | 370 | $prospectlevel[$obj->code]=$obj->label; |
364 | 371 | $i++; |
365 | 372 | } |
373 | + } else { |
|
374 | + dol_print_error($this->db); |
|
366 | 375 | } |
367 | - else dol_print_error($this->db); |
|
368 | 376 | |
369 | 377 | // Request must return: id, email, fk_contact, lastname, firstname, other |
370 | 378 | $sql = "SELECT sp.rowid as id, sp.email as email, sp.rowid as fk_contact, sp.lastname, sp.firstname, sp.civility as civility_id, sp.poste as jobposition,"; |
371 | 379 | $sql.= " s.nom as companyname"; |
372 | 380 | $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; |
373 | 381 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc"; |
374 | - if ($filter_category <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c"; |
|
375 | - if ($filter_category <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_contact as cs"; |
|
376 | - if ($filter_category_customer <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c2"; |
|
377 | - if ($filter_category_customer <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as c2s"; |
|
378 | - if ($filter_category_supplier <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie as c3"; |
|
379 | - if ($filter_category_supplier <> 'all') $sql.= ", ".MAIN_DB_PREFIX."categorie_fournisseur as c3s"; |
|
382 | + if ($filter_category <> 'all') { |
|
383 | + $sql.= ", ".MAIN_DB_PREFIX."categorie as c"; |
|
384 | + } |
|
385 | + if ($filter_category <> 'all') { |
|
386 | + $sql.= ", ".MAIN_DB_PREFIX."categorie_contact as cs"; |
|
387 | + } |
|
388 | + if ($filter_category_customer <> 'all') { |
|
389 | + $sql.= ", ".MAIN_DB_PREFIX."categorie as c2"; |
|
390 | + } |
|
391 | + if ($filter_category_customer <> 'all') { |
|
392 | + $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as c2s"; |
|
393 | + } |
|
394 | + if ($filter_category_supplier <> 'all') { |
|
395 | + $sql.= ", ".MAIN_DB_PREFIX."categorie as c3"; |
|
396 | + } |
|
397 | + if ($filter_category_supplier <> 'all') { |
|
398 | + $sql.= ", ".MAIN_DB_PREFIX."categorie_fournisseur as c3s"; |
|
399 | + } |
|
380 | 400 | $sql.= " WHERE sp.entity IN (".getEntity('socpeople').")"; |
381 | 401 | $sql.= " AND sp.email <> ''"; |
382 | 402 | $sql.= " AND sp.no_email = 0"; |
383 | 403 | $sql.= " AND sp.statut = 1"; |
384 | 404 | $sql.= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
385 | 405 | // Filter on category |
386 | - if ($filter_category <> 'all') $sql.= " AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid"; |
|
387 | - if ($filter_category <> 'all') $sql.= " AND c.label = '".$this->db->escape($filter_category)."'"; |
|
388 | - if ($filter_category_customer <> 'all') $sql.= " AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc"; |
|
389 | - if ($filter_category_customer <> 'all') $sql.= " AND c2.label = '".$this->db->escape($filter_category_customer)."'"; |
|
390 | - if ($filter_category_supplier <> 'all') $sql.= " AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc"; |
|
391 | - if ($filter_category_supplier <> 'all') $sql.= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'"; |
|
406 | + if ($filter_category <> 'all') { |
|
407 | + $sql.= " AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid"; |
|
408 | + } |
|
409 | + if ($filter_category <> 'all') { |
|
410 | + $sql.= " AND c.label = '".$this->db->escape($filter_category)."'"; |
|
411 | + } |
|
412 | + if ($filter_category_customer <> 'all') { |
|
413 | + $sql.= " AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc"; |
|
414 | + } |
|
415 | + if ($filter_category_customer <> 'all') { |
|
416 | + $sql.= " AND c2.label = '".$this->db->escape($filter_category_customer)."'"; |
|
417 | + } |
|
418 | + if ($filter_category_supplier <> 'all') { |
|
419 | + $sql.= " AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc"; |
|
420 | + } |
|
421 | + if ($filter_category_supplier <> 'all') { |
|
422 | + $sql.= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'"; |
|
423 | + } |
|
392 | 424 | // Filter on nature |
393 | 425 | $key = $filter; |
394 | 426 | { |
395 | 427 | //print "xx".$key; |
396 | - if ($key == 'prospects') $sql.= " AND s.client=2"; |
|
397 | - foreach($prospectlevel as $codelevel=>$valuelevel) if ($key == 'prospectslevel'.$codelevel) $sql.= " AND s.fk_prospectlevel='".$codelevel."'"; |
|
398 | - if ($key == 'customers') $sql.= " AND s.client=1"; |
|
399 | - if ($key == 'suppliers') $sql.= " AND s.fournisseur=1"; |
|
428 | + if ($key == 'prospects') { |
|
429 | + $sql.= " AND s.client=2"; |
|
430 | + } |
|
431 | + foreach($prospectlevel as $codelevel=>$valuelevel) { |
|
432 | + if ($key == 'prospectslevel'.$codelevel) $sql.= " AND s.fk_prospectlevel='".$codelevel."'"; |
|
433 | + } |
|
434 | + if ($key == 'customers') { |
|
435 | + $sql.= " AND s.client=1"; |
|
436 | + } |
|
437 | + if ($key == 'suppliers') { |
|
438 | + $sql.= " AND s.fournisseur=1"; |
|
439 | + } |
|
400 | 440 | } |
401 | 441 | // Filter on job position |
402 | 442 | $key = $filter_jobposition; |
403 | - if (! empty($key) && $key != 'all') $sql.= " AND sp.poste ='".$this->db->escape($key)."'"; |
|
443 | + if (! empty($key) && $key != 'all') { |
|
444 | + $sql.= " AND sp.poste ='".$this->db->escape($key)."'"; |
|
445 | + } |
|
404 | 446 | $sql.= " ORDER BY sp.email"; |
405 | 447 | //print "wwwwwwx".$sql; |
406 | 448 | |
@@ -439,8 +481,7 @@ discard block |
||
439 | 481 | |
440 | 482 | $i++; |
441 | 483 | } |
442 | - } |
|
443 | - else |
|
484 | + } else |
|
444 | 485 | { |
445 | 486 | dol_syslog($this->db->error()); |
446 | 487 | $this->error=$this->db->error(); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | // CHANGE THIS: Put here a description of your selector module. |
31 | 31 | // This label is used if no translation is found for key MailingModuleDescXXX where XXX=name is found |
32 | 32 | var $desc='Put here a description'; |
33 | - // CHANGE THIS: Set to 1 if selector is available for admin users only |
|
33 | + // CHANGE THIS: Set to 1 if selector is available for admin users only |
|
34 | 34 | var $require_admin=0; |
35 | 35 | // CHANGE THIS: Add a tooltip language key to add a tooltip help icon after the email target selector |
36 | 36 | var $tooltip='MyTooltipLangKey'; |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | |
46 | 46 | |
47 | 47 | // CHANGE THIS: Constructor name must be called mailing_xxx with xxx=name of your selector |
48 | - /** |
|
49 | - * Constructor |
|
50 | - * |
|
51 | - * @param DoliDB $db Database handler |
|
52 | - */ |
|
48 | + /** |
|
49 | + * Constructor |
|
50 | + * |
|
51 | + * @param DoliDB $db Database handler |
|
52 | + */ |
|
53 | 53 | function __construct($db) |
54 | 54 | { |
55 | 55 | $this->db=$db; |
@@ -68,38 +68,38 @@ discard block |
||
68 | 68 | // phpcs:enable |
69 | 69 | $target = array(); |
70 | 70 | |
71 | - // CHANGE THIS |
|
72 | - // ----- Your code start here ----- |
|
71 | + // CHANGE THIS |
|
72 | + // ----- Your code start here ----- |
|
73 | 73 | |
74 | - // You must fill the $target array with record like this |
|
75 | - // $target[0]=array('email'=>'email_0','name'=>'name_0','firstname'=>'firstname_0', 'other'=>'other_0'); |
|
76 | - // ... |
|
77 | - // $target[n]=array('email'=>'email_n','name'=>'name_n','firstname'=>'firstname_n', 'other'=>'other_n'); |
|
74 | + // You must fill the $target array with record like this |
|
75 | + // $target[0]=array('email'=>'email_0','name'=>'name_0','firstname'=>'firstname_0', 'other'=>'other_0'); |
|
76 | + // ... |
|
77 | + // $target[n]=array('email'=>'email_n','name'=>'name_n','firstname'=>'firstname_n', 'other'=>'other_n'); |
|
78 | 78 | |
79 | - // Example: $target[0]=array('email'=>'[email protected]', 'name'=>'Doe', 'firstname'=>'John', 'other'=>'Other information'); |
|
79 | + // Example: $target[0]=array('email'=>'[email protected]', 'name'=>'Doe', 'firstname'=>'John', 'other'=>'Other information'); |
|
80 | 80 | |
81 | - // ----- Your code end here ----- |
|
81 | + // ----- Your code end here ----- |
|
82 | 82 | |
83 | 83 | return parent::add_to_target($mailing_id, $target); |
84 | 84 | } |
85 | 85 | |
86 | 86 | |
87 | 87 | /** |
88 | - * On the main mailing area, there is a box with statistics. |
|
89 | - * If you want to add a line in this report you must provide an |
|
90 | - * array of SQL request that returns two field: |
|
91 | - * One called "label", One called "nb". |
|
92 | - * |
|
93 | - * @return array Array with SQL requests |
|
94 | - */ |
|
95 | - function getSqlArrayForStats() |
|
96 | - { |
|
97 | - // CHANGE THIS: Optionnal |
|
98 | - |
|
99 | - //var $statssql=array(); |
|
88 | + * On the main mailing area, there is a box with statistics. |
|
89 | + * If you want to add a line in this report you must provide an |
|
90 | + * array of SQL request that returns two field: |
|
91 | + * One called "label", One called "nb". |
|
92 | + * |
|
93 | + * @return array Array with SQL requests |
|
94 | + */ |
|
95 | + function getSqlArrayForStats() |
|
96 | + { |
|
97 | + // CHANGE THIS: Optionnal |
|
98 | + |
|
99 | + //var $statssql=array(); |
|
100 | 100 | //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL"; |
101 | - return array(); |
|
102 | - } |
|
101 | + return array(); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | 105 | /** |
@@ -26,17 +26,17 @@ discard block |
||
26 | 26 | class mailing_example extends MailingTargets |
27 | 27 | { |
28 | 28 | // CHANGE THIS: Put here a name not already used |
29 | - var $name='example'; |
|
29 | + var $name = 'example'; |
|
30 | 30 | // CHANGE THIS: Put here a description of your selector module. |
31 | 31 | // This label is used if no translation is found for key MailingModuleDescXXX where XXX=name is found |
32 | - var $desc='Put here a description'; |
|
32 | + var $desc = 'Put here a description'; |
|
33 | 33 | // CHANGE THIS: Set to 1 if selector is available for admin users only |
34 | - var $require_admin=0; |
|
34 | + var $require_admin = 0; |
|
35 | 35 | // CHANGE THIS: Add a tooltip language key to add a tooltip help icon after the email target selector |
36 | - var $tooltip='MyTooltipLangKey'; |
|
36 | + var $tooltip = 'MyTooltipLangKey'; |
|
37 | 37 | |
38 | - var $require_module=array(); |
|
39 | - var $picto=''; |
|
38 | + var $require_module = array(); |
|
39 | + var $picto = ''; |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @var DoliDB Database handler. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | */ |
53 | 53 | function __construct($db) |
54 | 54 | { |
55 | - $this->db=$db; |
|
55 | + $this->db = $db; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param string $sql Requete sql de comptage |
111 | 111 | * @return int|string Number of recipient or '?' |
112 | 112 | */ |
113 | - function getNbOfRecipients($sql='') |
|
113 | + function getNbOfRecipients($sql = '') |
|
114 | 114 | { |
115 | 115 | // CHANGE THIS: Optionnal |
116 | 116 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | { |
130 | 130 | // CHANGE THIS: Optionnal |
131 | 131 | |
132 | - $s=''; |
|
132 | + $s = ''; |
|
133 | 133 | return $s; |
134 | 134 | } |
135 | 135 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | class mailing_thirdparties_services_expired extends MailingTargets |
24 | 24 | { |
25 | 25 | var $name='DolibarrContractsLinesExpired'; |
26 | - // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
26 | + // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
|
27 | 27 | var $desc='Third parties with expired contract\'s lines'; |
28 | 28 | var $require_admin=0; |
29 | 29 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | function __construct($db) |
47 | 47 | { |
48 | - global $conf; |
|
48 | + global $conf; |
|
49 | 49 | |
50 | 50 | $this->db=$db; |
51 | 51 | |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | $product=''; |
96 | 96 | if ($key == '0') |
97 | 97 | { |
98 | - $this->error = "Error: You must choose a filter"; |
|
99 | - $this->errors[] = $this->error; |
|
100 | - return $this->error; |
|
98 | + $this->error = "Error: You must choose a filter"; |
|
99 | + $this->errors[] = $this->error; |
|
100 | + return $this->error; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $product=$this->arrayofproducts[$key]; |
@@ -131,17 +131,17 @@ discard block |
||
131 | 131 | if ($old <> $obj->email) |
132 | 132 | { |
133 | 133 | $cibles[$j] = array( |
134 | - 'email' => $obj->email, |
|
135 | - 'lastname' => $obj->name, // For thirdparties, lastname must be name |
|
134 | + 'email' => $obj->email, |
|
135 | + 'lastname' => $obj->name, // For thirdparties, lastname must be name |
|
136 | 136 | 'firstname' => '', // For thirdparties, firstname is '' |
137 | - 'other' => |
|
137 | + 'other' => |
|
138 | 138 | ('DateStart='.dol_print_date($this->db->jdate($obj->date_ouverture),'day')).';'. |
139 | 139 | ('DateEnd='.dol_print_date($this->db->jdate($obj->date_fin_validite),'day')).';'. |
140 | 140 | ('Contract='.$obj->fk_contrat).';'. |
141 | 141 | ('ContactLine='.$obj->cdid), |
142 | - 'source_url' => $this->url($obj->id), |
|
143 | - 'source_id' => $obj->id, |
|
144 | - 'source_type' => 'thirdparty' |
|
142 | + 'source_url' => $this->url($obj->id), |
|
143 | + 'source_id' => $obj->id, |
|
144 | + 'source_type' => 'thirdparty' |
|
145 | 145 | ); |
146 | 146 | $old = $obj->email; |
147 | 147 | $j++; |
@@ -22,20 +22,20 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class mailing_thirdparties_services_expired extends MailingTargets |
24 | 24 | { |
25 | - var $name='DolibarrContractsLinesExpired'; |
|
25 | + var $name = 'DolibarrContractsLinesExpired'; |
|
26 | 26 | // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found |
27 | - var $desc='Third parties with expired contract\'s lines'; |
|
28 | - var $require_admin=0; |
|
27 | + var $desc = 'Third parties with expired contract\'s lines'; |
|
28 | + var $require_admin = 0; |
|
29 | 29 | |
30 | - var $require_module=array('contrat'); |
|
31 | - var $picto='company'; |
|
30 | + var $require_module = array('contrat'); |
|
31 | + var $picto = 'company'; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @var DoliDB Database handler. |
35 | 35 | */ |
36 | 36 | public $db; |
37 | 37 | |
38 | - var $arrayofproducts=array(); |
|
38 | + var $arrayofproducts = array(); |
|
39 | 39 | |
40 | 40 | |
41 | 41 | /** |
@@ -47,16 +47,16 @@ discard block |
||
47 | 47 | { |
48 | 48 | global $conf; |
49 | 49 | |
50 | - $this->db=$db; |
|
50 | + $this->db = $db; |
|
51 | 51 | |
52 | - $this->arrayofproducts=array(); |
|
52 | + $this->arrayofproducts = array(); |
|
53 | 53 | |
54 | 54 | // List of services |
55 | 55 | $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product"; |
56 | - $sql.= " WHERE entity IN (".getEntity('product').")"; |
|
57 | - if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $sql.= " AND fk_product_type = 1"; // By default, only services |
|
58 | - $sql.= " ORDER BY ref"; |
|
59 | - $result=$this->db->query($sql); |
|
56 | + $sql .= " WHERE entity IN (".getEntity('product').")"; |
|
57 | + if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $sql .= " AND fk_product_type = 1"; // By default, only services |
|
58 | + $sql .= " ORDER BY ref"; |
|
59 | + $result = $this->db->query($sql); |
|
60 | 60 | if ($result) |
61 | 61 | { |
62 | 62 | $num = $this->db->num_rows($result); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | { |
68 | 68 | $obj = $this->db->fetch_object($result); |
69 | 69 | $i++; |
70 | - $this->arrayofproducts[$i]=$obj->ref; |
|
70 | + $this->arrayofproducts[$i] = $obj->ref; |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | else |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | function add_to_target($mailing_id) |
88 | 88 | { |
89 | 89 | // phpcs:enable |
90 | - $key=GETPOST('filter','int'); |
|
90 | + $key = GETPOST('filter', 'int'); |
|
91 | 91 | |
92 | 92 | $cibles = array(); |
93 | 93 | $j = 0; |
94 | 94 | |
95 | - $product=''; |
|
95 | + $product = ''; |
|
96 | 96 | if ($key == '0') |
97 | 97 | { |
98 | 98 | $this->error = "Error: You must choose a filter"; |
@@ -100,23 +100,23 @@ discard block |
||
100 | 100 | return $this->error; |
101 | 101 | } |
102 | 102 | |
103 | - $product=$this->arrayofproducts[$key]; |
|
103 | + $product = $this->arrayofproducts[$key]; |
|
104 | 104 | |
105 | - $now=dol_now(); |
|
105 | + $now = dol_now(); |
|
106 | 106 | |
107 | 107 | // La requete doit retourner: id, email, name |
108 | 108 | $sql = "SELECT s.rowid as id, s.email, s.nom as name, cd.rowid as cdid, cd.date_ouverture, cd.date_fin_validite, cd.fk_contrat"; |
109 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c"; |
|
110 | - $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p"; |
|
111 | - $sql.= " WHERE s.entity IN (".getEntity('societe').")"; |
|
112 | - $sql.= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
113 | - $sql.= " AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''"; |
|
114 | - $sql.= " AND cd.statut= 4 AND cd.fk_product=p.rowid AND p.ref = '".$product."'"; |
|
115 | - $sql.= " AND cd.date_fin_validite < '".$this->db->idate($now)."'"; |
|
116 | - $sql.= " ORDER BY s.email"; |
|
109 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c"; |
|
110 | + $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p"; |
|
111 | + $sql .= " WHERE s.entity IN (".getEntity('societe').")"; |
|
112 | + $sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".$mailing_id.")"; |
|
113 | + $sql .= " AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''"; |
|
114 | + $sql .= " AND cd.statut= 4 AND cd.fk_product=p.rowid AND p.ref = '".$product."'"; |
|
115 | + $sql .= " AND cd.date_fin_validite < '".$this->db->idate($now)."'"; |
|
116 | + $sql .= " ORDER BY s.email"; |
|
117 | 117 | |
118 | 118 | // Stocke destinataires dans cibles |
119 | - $result=$this->db->query($sql); |
|
119 | + $result = $this->db->query($sql); |
|
120 | 120 | if ($result) |
121 | 121 | { |
122 | 122 | $num = $this->db->num_rows($result); |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | { |
133 | 133 | $cibles[$j] = array( |
134 | 134 | 'email' => $obj->email, |
135 | - 'lastname' => $obj->name, // For thirdparties, lastname must be name |
|
136 | - 'firstname' => '', // For thirdparties, firstname is '' |
|
135 | + 'lastname' => $obj->name, // For thirdparties, lastname must be name |
|
136 | + 'firstname' => '', // For thirdparties, firstname is '' |
|
137 | 137 | 'other' => |
138 | - ('DateStart='.dol_print_date($this->db->jdate($obj->date_ouverture),'day')).';'. |
|
139 | - ('DateEnd='.dol_print_date($this->db->jdate($obj->date_fin_validite),'day')).';'. |
|
138 | + ('DateStart='.dol_print_date($this->db->jdate($obj->date_ouverture), 'day')).';'. |
|
139 | + ('DateEnd='.dol_print_date($this->db->jdate($obj->date_fin_validite), 'day')).';'. |
|
140 | 140 | ('Contract='.$obj->fk_contrat).';'. |
141 | 141 | ('ContactLine='.$obj->cdid), |
142 | 142 | 'source_url' => $this->url($obj->id), |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | else |
154 | 154 | { |
155 | 155 | dol_syslog($this->db->lasterror()); |
156 | - $this->error=$this->db->lasterror(); |
|
156 | + $this->error = $this->db->lasterror(); |
|
157 | 157 | return -1; |
158 | 158 | } |
159 | 159 | |
@@ -189,22 +189,22 @@ discard block |
||
189 | 189 | * @param string $sql SQL request to use to count |
190 | 190 | * @return int Number of recipients |
191 | 191 | */ |
192 | - function getNbOfRecipients($sql='') |
|
192 | + function getNbOfRecipients($sql = '') |
|
193 | 193 | { |
194 | - $now=dol_now(); |
|
194 | + $now = dol_now(); |
|
195 | 195 | |
196 | 196 | // Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table"); |
197 | 197 | // Example: return 500; |
198 | 198 | $sql = "SELECT count(*) as nb"; |
199 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c"; |
|
200 | - $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p"; |
|
201 | - $sql.= " WHERE s.entity IN (".getEntity('societe').")"; |
|
202 | - $sql.= " AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''"; |
|
203 | - $sql.= " AND cd.statut= 4 AND cd.fk_product=p.rowid"; |
|
204 | - $sql.= " AND p.ref IN ('".join("','",$this->arrayofproducts)."')"; |
|
205 | - $sql.= " AND cd.date_fin_validite < '".$this->db->idate($now)."'"; |
|
199 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c"; |
|
200 | + $sql .= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."product as p"; |
|
201 | + $sql .= " WHERE s.entity IN (".getEntity('societe').")"; |
|
202 | + $sql .= " AND s.rowid = c.fk_soc AND cd.fk_contrat = c.rowid AND s.email != ''"; |
|
203 | + $sql .= " AND cd.statut= 4 AND cd.fk_product=p.rowid"; |
|
204 | + $sql .= " AND p.ref IN ('".join("','", $this->arrayofproducts)."')"; |
|
205 | + $sql .= " AND cd.date_fin_validite < '".$this->db->idate($now)."'"; |
|
206 | 206 | |
207 | - $a=parent::getNbOfRecipients($sql); |
|
207 | + $a = parent::getNbOfRecipients($sql); |
|
208 | 208 | |
209 | 209 | return $a; |
210 | 210 | } |
@@ -219,15 +219,15 @@ discard block |
||
219 | 219 | { |
220 | 220 | global $langs; |
221 | 221 | |
222 | - $s=$langs->trans("ProductOrService"); |
|
223 | - $s.='<select name="filter" class="flat">'; |
|
224 | - if (count($this->arrayofproducts)) $s.='<option value="0"> </option>'; |
|
225 | - else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
226 | - foreach($this->arrayofproducts as $key => $val) |
|
222 | + $s = $langs->trans("ProductOrService"); |
|
223 | + $s .= '<select name="filter" class="flat">'; |
|
224 | + if (count($this->arrayofproducts)) $s .= '<option value="0"> </option>'; |
|
225 | + else $s .= '<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
226 | + foreach ($this->arrayofproducts as $key => $val) |
|
227 | 227 | { |
228 | - $s.='<option value="'.$key.'">'.$val.'</option>'; |
|
228 | + $s .= '<option value="'.$key.'">'.$val.'</option>'; |
|
229 | 229 | } |
230 | - $s.='</select>'; |
|
230 | + $s .= '</select>'; |
|
231 | 231 | return $s; |
232 | 232 | } |
233 | 233 | |
@@ -240,6 +240,6 @@ discard block |
||
240 | 240 | */ |
241 | 241 | function url($id) |
242 | 242 | { |
243 | - return '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$id.'">'.img_object('',"company").'</a>'; |
|
243 | + return '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$id.'">'.img_object('', "company").'</a>'; |
|
244 | 244 | } |
245 | 245 | } |
@@ -54,7 +54,10 @@ discard block |
||
54 | 54 | // List of services |
55 | 55 | $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product"; |
56 | 56 | $sql.= " WHERE entity IN (".getEntity('product').")"; |
57 | - if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $sql.= " AND fk_product_type = 1"; // By default, only services |
|
57 | + if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) { |
|
58 | + $sql.= " AND fk_product_type = 1"; |
|
59 | + } |
|
60 | + // By default, only services |
|
58 | 61 | $sql.= " ORDER BY ref"; |
59 | 62 | $result=$this->db->query($sql); |
60 | 63 | if ($result) |
@@ -69,8 +72,7 @@ discard block |
||
69 | 72 | $i++; |
70 | 73 | $this->arrayofproducts[$i]=$obj->ref; |
71 | 74 | } |
72 | - } |
|
73 | - else |
|
75 | + } else |
|
74 | 76 | { |
75 | 77 | dol_print_error($this->db); |
76 | 78 | } |
@@ -149,8 +151,7 @@ discard block |
||
149 | 151 | |
150 | 152 | $i++; |
151 | 153 | } |
152 | - } |
|
153 | - else |
|
154 | + } else |
|
154 | 155 | { |
155 | 156 | dol_syslog($this->db->lasterror()); |
156 | 157 | $this->error=$this->db->lasterror(); |
@@ -221,8 +222,11 @@ discard block |
||
221 | 222 | |
222 | 223 | $s=$langs->trans("ProductOrService"); |
223 | 224 | $s.='<select name="filter" class="flat">'; |
224 | - if (count($this->arrayofproducts)) $s.='<option value="0"> </option>'; |
|
225 | - else $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
225 | + if (count($this->arrayofproducts)) { |
|
226 | + $s.='<option value="0"> </option>'; |
|
227 | + } else { |
|
228 | + $s.='<option value="0">'.$langs->trans("ContactsAllShort").'</option>'; |
|
229 | + } |
|
226 | 230 | foreach($this->arrayofproducts as $key => $val) |
227 | 231 | { |
228 | 232 | $s.='<option value="'.$key.'">'.$val.'</option>'; |