@@ -20,11 +20,22 @@ discard block |
||
20 | 20 | * \brief File to return Ajax response on set extra parameters of elements |
21 | 21 | */ |
22 | 22 | |
23 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal |
|
24 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); |
|
25 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); |
|
26 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
27 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
|
23 | +if (! defined('NOTOKENRENEWAL')) { |
|
24 | + define('NOTOKENRENEWAL','1'); |
|
25 | +} |
|
26 | +// Disables token renewal |
|
27 | +if (! defined('NOREQUIREMENU')) { |
|
28 | + define('NOREQUIREMENU','1'); |
|
29 | +} |
|
30 | +if (! defined('NOREQUIREHTML')) { |
|
31 | + define('NOREQUIREHTML','1'); |
|
32 | +} |
|
33 | +if (! defined('NOREQUIREAJAX')) { |
|
34 | + define('NOREQUIREAJAX','1'); |
|
35 | +} |
|
36 | +if (! defined('NOREQUIRESOC')) { |
|
37 | + define('NOREQUIRESOC','1'); |
|
38 | +} |
|
28 | 39 | |
29 | 40 | include '../../main.inc.php'; |
30 | 41 | |
@@ -51,20 +62,13 @@ discard block |
||
51 | 62 | $classpath = $subelement = $element; |
52 | 63 | |
53 | 64 | // For compatibility |
54 | - if ($element == 'order' || $element == 'commande') { $classpath = $subelement = 'commande'; } |
|
55 | - else if ($element == 'propal') { $classpath = 'comm/propal'; $subelement = 'propal'; } |
|
56 | - else if ($element == 'facture') { $classpath = 'compta/facture'; $subelement = 'facture'; } |
|
57 | - else if ($element == 'contract') { $classpath = $subelement = 'contrat'; } |
|
58 | - else if ($element == 'shipping') { $classpath = $subelement = 'expedition'; } |
|
59 | - else if ($element == 'deplacement') { $classpath = 'compta/deplacement'; $subelement = 'deplacement'; } |
|
60 | - else if ($element == 'order_supplier') { $classpath = 'fourn'; $subelement = 'fournisseur.commande'; } |
|
61 | - else if ($element == 'invoice_supplier') { $classpath = 'fourn'; $subelement = 'fournisseur.facture'; } |
|
65 | + if ($element == 'order' || $element == 'commande') { $classpath = $subelement = 'commande'; } else if ($element == 'propal') { $classpath = 'comm/propal'; $subelement = 'propal'; } else if ($element == 'facture') { $classpath = 'compta/facture'; $subelement = 'facture'; } else if ($element == 'contract') { $classpath = $subelement = 'contrat'; } else if ($element == 'shipping') { $classpath = $subelement = 'expedition'; } else if ($element == 'deplacement') { $classpath = 'compta/deplacement'; $subelement = 'deplacement'; } else if ($element == 'order_supplier') { $classpath = 'fourn'; $subelement = 'fournisseur.commande'; } else if ($element == 'invoice_supplier') { $classpath = 'fourn'; $subelement = 'fournisseur.facture'; } |
|
62 | 66 | |
63 | 67 | dol_include_once('/'.$classpath.'/class/'.$subelement.'.class.php'); |
64 | 68 | |
65 | - if ($element == 'order_supplier') { $classname = 'CommandeFournisseur'; } |
|
66 | - else if ($element == 'invoice_supplier') { $classname = 'FactureFournisseur'; } |
|
67 | - else $classname = ucfirst($subelement); |
|
69 | + if ($element == 'order_supplier') { $classname = 'CommandeFournisseur'; } else if ($element == 'invoice_supplier') { $classname = 'FactureFournisseur'; } else { |
|
70 | + $classname = ucfirst($subelement); |
|
71 | + } |
|
68 | 72 | |
69 | 73 | $object = new $classname($db); |
70 | 74 | $object->fetch($id); |
@@ -75,15 +75,16 @@ |
||
75 | 75 | setEventMessages($printer->error, $printer->errors); |
76 | 76 | setEventMessages($langs->transnoentitiesnoconv("FileWasSentToPrinter", basename(GETPOST('file', 'alpha'))).' '.$langs->transnoentitiesnoconv("ViaModule").' '.$printer->name, null); |
77 | 77 | } |
78 | - } |
|
79 | - catch(Exception $e) |
|
78 | + } catch(Exception $e) |
|
80 | 79 | { |
81 | 80 | $ret = 1; |
82 | 81 | setEventMessages($e->getMessage(), null, 'errors'); |
83 | 82 | } |
84 | 83 | } |
85 | 84 | } |
86 | - if ($printerfound==0) setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings'); |
|
85 | + if ($printerfound==0) { |
|
86 | + setEventMessages($langs->trans("NoActivePrintingModuleFound", $langs->transnoentities("Module64000Name")), null, 'warnings'); |
|
87 | + } |
|
87 | 88 | } else { |
88 | 89 | setEventMessages($langs->trans("NoModuleFound"), null, 'warnings'); |
89 | 90 | } |
@@ -23,12 +23,24 @@ |
||
23 | 23 | |
24 | 24 | define('NOLOGIN',1); |
25 | 25 | |
26 | -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER',1); |
|
27 | -if (! defined('NOREQUIREDB')) define('NOREQUIREDB',1); |
|
28 | -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN',1); |
|
29 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); |
|
30 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC',1); |
|
31 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); |
|
26 | +if (! defined('NOREQUIREUSER')) { |
|
27 | + define('NOREQUIREUSER',1); |
|
28 | +} |
|
29 | +if (! defined('NOREQUIREDB')) { |
|
30 | + define('NOREQUIREDB',1); |
|
31 | +} |
|
32 | +if (! defined('NOREQUIRETRAN')) { |
|
33 | + define('NOREQUIRETRAN',1); |
|
34 | +} |
|
35 | +if (! defined('NOREQUIREMENU')) { |
|
36 | + define('NOREQUIREMENU',1); |
|
37 | +} |
|
38 | +if (! defined('NOREQUIRESOC')) { |
|
39 | + define('NOREQUIRESOC',1); |
|
40 | +} |
|
41 | +if (! defined('NOTOKENRENEWAL')) { |
|
42 | + define('NOTOKENRENEWAL',1); |
|
43 | +} |
|
32 | 44 | |
33 | 45 | require_once '../main.inc.php'; |
34 | 46 |
@@ -11,11 +11,13 @@ discard block |
||
11 | 11 | $sql="SELECT name, label, type, param, fieldcomputed, fielddefault FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = '".$keyforselect."' AND type != 'separate' AND entity IN (0, ".$conf->entity.')'; |
12 | 12 | //print $sql; |
13 | 13 | $resql=$this->db->query($sql); |
14 | -if ($resql) // This can fail when class is used on old database (during migration for example) |
|
14 | +if ($resql) { |
|
15 | + // This can fail when class is used on old database (during migration for example) |
|
15 | 16 | { |
16 | 17 | while ($obj=$this->db->fetch_object($resql)) |
17 | 18 | { |
18 | 19 | $fieldname=$keyforaliasextra.'.'.$obj->name; |
20 | +} |
|
19 | 21 | $fieldlabel=ucfirst($obj->label); |
20 | 22 | $typeFilter="Text"; |
21 | 23 | $typefield=preg_replace('/\(.*$/', '', $obj->type); // double(24,8) -> double |
@@ -41,7 +43,9 @@ discard block |
||
41 | 43 | $tmpkeys=array_keys($tmpparam['options']); |
42 | 44 | $tmp=array_shift($tmpkeys); |
43 | 45 | } |
44 | - if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp; |
|
46 | + if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) { |
|
47 | + $typeFilter="List:".$tmp; |
|
48 | + } |
|
45 | 49 | break; |
46 | 50 | } |
47 | 51 | if ($obj->type!='separate') |
@@ -54,10 +54,12 @@ discard block |
||
54 | 54 | $error++; |
55 | 55 | } |
56 | 56 | |
57 | -if (! $error && $massaction == 'confirm_presend' && ! GETPOST('sendmail')) // If we do not choose button send (for example when we change template or limit), we must not send email, but keep on send email form |
|
57 | +if (! $error && $massaction == 'confirm_presend' && ! GETPOST('sendmail')) { |
|
58 | + // If we do not choose button send (for example when we change template or limit), we must not send email, but keep on send email form |
|
58 | 59 | { |
59 | 60 | $massaction='presend'; |
60 | 61 | } |
62 | +} |
|
61 | 63 | if (! $error && $massaction == 'confirm_presend') |
62 | 64 | { |
63 | 65 | $resaction = ''; |
@@ -73,8 +75,12 @@ discard block |
||
73 | 75 | if (! $error) |
74 | 76 | { |
75 | 77 | $thirdparty=new Societe($db); |
76 | - if ($objecttmp->element == 'expensereport') $thirdparty=new User($db); |
|
77 | - if ($objecttmp->element == 'holiday') $thirdparty=new User($db); |
|
78 | + if ($objecttmp->element == 'expensereport') { |
|
79 | + $thirdparty=new User($db); |
|
80 | + } |
|
81 | + if ($objecttmp->element == 'holiday') { |
|
82 | + $thirdparty=new User($db); |
|
83 | + } |
|
78 | 84 | |
79 | 85 | $objecttmp=new $objectclass($db); |
80 | 86 | foreach($toselect as $toselectid) |
@@ -85,9 +91,15 @@ discard block |
||
85 | 91 | { |
86 | 92 | $listofobjectid[$toselectid]=$toselectid; |
87 | 93 | $thirdpartyid=($objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid); |
88 | - if ($objecttmp->element == 'societe') $thirdpartyid=$objecttmp->id; |
|
89 | - if ($objecttmp->element == 'expensereport') $thirdpartyid=$objecttmp->fk_user_author; |
|
90 | - if ($objecttmp->element == 'holiday') $thirdpartyid=$objecttmp->fk_user; |
|
94 | + if ($objecttmp->element == 'societe') { |
|
95 | + $thirdpartyid=$objecttmp->id; |
|
96 | + } |
|
97 | + if ($objecttmp->element == 'expensereport') { |
|
98 | + $thirdpartyid=$objecttmp->fk_user_author; |
|
99 | + } |
|
100 | + if ($objecttmp->element == 'holiday') { |
|
101 | + $thirdpartyid=$objecttmp->fk_user; |
|
102 | + } |
|
91 | 103 | $listofobjectthirdparties[$thirdpartyid]=$thirdpartyid; |
92 | 104 | $listofobjectref[$thirdpartyid][$toselectid]=$objecttmp; |
93 | 105 | } |
@@ -105,12 +117,17 @@ discard block |
||
105 | 117 | $receiver=$_POST['receiver']; |
106 | 118 | if (! is_array($receiver)) |
107 | 119 | { |
108 | - if (empty($receiver) || $receiver == '-1') $receiver=array(); |
|
109 | - else $receiver=array($receiver); |
|
120 | + if (empty($receiver) || $receiver == '-1') { |
|
121 | + $receiver=array(); |
|
122 | + } else { |
|
123 | + $receiver=array($receiver); |
|
124 | + } |
|
110 | 125 | } |
111 | - if (! trim($_POST['sendto']) && count($receiver) == 0 && count($listofobjectthirdparties) == 1) // if only one recipient, receiver is mandatory |
|
126 | + if (! trim($_POST['sendto']) && count($receiver) == 0 && count($listofobjectthirdparties) == 1) { |
|
127 | + // if only one recipient, receiver is mandatory |
|
112 | 128 | { |
113 | 129 | $error++; |
130 | + } |
|
114 | 131 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Recipient")), null, 'warnings'); |
115 | 132 | $massaction='presend'; |
116 | 133 | } |
@@ -151,13 +168,16 @@ discard block |
||
151 | 168 | foreach($receiver as $key=>$val) |
152 | 169 | { |
153 | 170 | // Recipient was provided from combo list |
154 | - if ($val == 'thirdparty') // Id of third party or user |
|
171 | + if ($val == 'thirdparty') { |
|
172 | + // Id of third party or user |
|
155 | 173 | { |
156 | 174 | $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>'; |
157 | 175 | } |
158 | - elseif ($val && method_exists($thirdparty, 'contact_get_property')) // Id of contact |
|
176 | + } elseif ($val && method_exists($thirdparty, 'contact_get_property')) { |
|
177 | + // Id of contact |
|
159 | 178 | { |
160 | 179 | $tmparray[] = $thirdparty->contact_get_property((int) $val,'email'); |
180 | + } |
|
161 | 181 | $sendtoid[] = $val; |
162 | 182 | } |
163 | 183 | } |
@@ -168,8 +188,11 @@ discard block |
||
168 | 188 | $receivercc=$_POST['receivercc']; |
169 | 189 | if (! is_array($receivercc)) |
170 | 190 | { |
171 | - if ($receivercc == '-1') $receivercc=array(); |
|
172 | - else $receivercc=array($receivercc); |
|
191 | + if ($receivercc == '-1') { |
|
192 | + $receivercc=array(); |
|
193 | + } else { |
|
194 | + $receivercc=array($receivercc); |
|
195 | + } |
|
173 | 196 | } |
174 | 197 | $tmparray=array(); |
175 | 198 | if (trim($_POST['sendtocc'])) |
@@ -181,13 +204,16 @@ discard block |
||
181 | 204 | foreach($receivercc as $key=>$val) |
182 | 205 | { |
183 | 206 | // Recipient was provided from combo list |
184 | - if ($val == 'thirdparty') // Id of third party |
|
207 | + if ($val == 'thirdparty') { |
|
208 | + // Id of third party |
|
185 | 209 | { |
186 | 210 | $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>'; |
187 | 211 | } |
188 | - elseif ($val) // Id du contact |
|
212 | + } elseif ($val) { |
|
213 | + // Id du contact |
|
189 | 214 | { |
190 | 215 | $tmparray[] = $thirdparty->contact_get_property((int) $val,'email'); |
216 | + } |
|
191 | 217 | //$sendtoid[] = $val; TODO Add also id of contact in CC ? |
192 | 218 | } |
193 | 219 | } |
@@ -226,15 +252,16 @@ discard block |
||
226 | 252 | } |
227 | 253 | |
228 | 254 | // Test recipient |
229 | - if (empty($sendto)) // For the case, no recipient were set (multi thirdparties send) |
|
255 | + if (empty($sendto)) { |
|
256 | + // For the case, no recipient were set (multi thirdparties send) |
|
230 | 257 | { |
231 | 258 | if ($objectobj->element == 'expensereport') |
232 | 259 | { |
233 | 260 | $fuser = new User($db); |
261 | + } |
|
234 | 262 | $fuser->fetch($objectobj->fk_user_author); |
235 | 263 | $sendto = $fuser->email; |
236 | - } |
|
237 | - else |
|
264 | + } else |
|
238 | 265 | { |
239 | 266 | $objectobj->fetch_thirdparty(); |
240 | 267 | $sendto = $objectobj->thirdparty->email; |
@@ -271,8 +298,7 @@ discard block |
||
271 | 298 | 'names'=>array_merge($attachedfiles['names'],array($filename)), |
272 | 299 | 'mimes'=>array_merge($attachedfiles['mimes'],array($mime)) |
273 | 300 | ); |
274 | - } |
|
275 | - else |
|
301 | + } else |
|
276 | 302 | { |
277 | 303 | $nbignored++; |
278 | 304 | $langs->load("errors"); |
@@ -298,19 +324,15 @@ discard block |
||
298 | 324 | $fromtype = GETPOST('fromtype'); |
299 | 325 | if ($fromtype === 'user') { |
300 | 326 | $from = $user->getFullName($langs) .' <'.$user->email.'>'; |
301 | - } |
|
302 | - elseif ($fromtype === 'company') { |
|
327 | + } elseif ($fromtype === 'company') { |
|
303 | 328 | $from = $conf->global->MAIN_INFO_SOCIETE_NOM .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; |
304 | - } |
|
305 | - elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { |
|
329 | + } elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { |
|
306 | 330 | $tmp=explode(',', $user->email_aliases); |
307 | 331 | $from = trim($tmp[($reg[1] - 1)]); |
308 | - } |
|
309 | - elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { |
|
332 | + } elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { |
|
310 | 333 | $tmp=explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES); |
311 | 334 | $from = trim($tmp[($reg[1] - 1)]); |
312 | - } |
|
313 | - elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { |
|
335 | + } elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { |
|
314 | 336 | $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE rowid = '.(int) $reg[1]; |
315 | 337 | $resql = $db->query($sql); |
316 | 338 | $obj = $db->fetch_object($resql); |
@@ -318,8 +340,7 @@ discard block |
||
318 | 340 | { |
319 | 341 | $from = $obj->label.' <'.$obj->email.'>'; |
320 | 342 | } |
321 | - } |
|
322 | - else { |
|
343 | + } else { |
|
323 | 344 | $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; |
324 | 345 | } |
325 | 346 | |
@@ -328,12 +349,24 @@ discard block |
||
328 | 349 | $message = GETPOST('message','none'); |
329 | 350 | |
330 | 351 | $sendtobcc = GETPOST('sendtoccc'); |
331 | - if ($objectclass == 'Propal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)); |
|
332 | - if ($objectclass == 'Commande') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)); |
|
333 | - if ($objectclass == 'Facture') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)); |
|
334 | - if ($objectclass == 'Supplier_Proposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO)); |
|
335 | - if ($objectclass == 'CommandeFournisseur') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO)); |
|
336 | - if ($objectclass == 'FactureFournisseur') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO)); |
|
352 | + if ($objectclass == 'Propal') { |
|
353 | + $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)); |
|
354 | + } |
|
355 | + if ($objectclass == 'Commande') { |
|
356 | + $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)); |
|
357 | + } |
|
358 | + if ($objectclass == 'Facture') { |
|
359 | + $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)); |
|
360 | + } |
|
361 | + if ($objectclass == 'Supplier_Proposal') { |
|
362 | + $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO)); |
|
363 | + } |
|
364 | + if ($objectclass == 'CommandeFournisseur') { |
|
365 | + $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO)); |
|
366 | + } |
|
367 | + if ($objectclass == 'FactureFournisseur') { |
|
368 | + $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO)); |
|
369 | + } |
|
337 | 370 | |
338 | 371 | // $listofqualifiedobj is array with key = object id and value is instance of qualified objects, for the current thirdparty (but thirdparty property is not loaded yet) |
339 | 372 | $oneemailperrecipient=(GETPOST('oneemailperrecipient')=='on'?1:0); |
@@ -345,8 +378,7 @@ discard block |
||
345 | 378 | { |
346 | 379 | $looparray[$key]->thirdparty = $thirdparty; |
347 | 380 | } |
348 | - } |
|
349 | - else |
|
381 | + } else |
|
350 | 382 | { |
351 | 383 | $objectforloop=new $objectclass($db); |
352 | 384 | $objectforloop->thirdparty = $thirdparty; |
@@ -354,10 +386,12 @@ discard block |
||
354 | 386 | } |
355 | 387 | //var_dump($looparray);exit; |
356 | 388 | |
357 | - foreach ($looparray as $objecttmp) // $objecttmp is a real object or an empty object if we choose to send one email per thirdparty instead of one per record |
|
389 | + foreach ($looparray as $objecttmp) { |
|
390 | + // $objecttmp is a real object or an empty object if we choose to send one email per thirdparty instead of one per record |
|
358 | 391 | { |
359 | 392 | // Make substitution in email content |
360 | 393 | $substitutionarray=getCommonSubstitutionArray($langs, 0, null, $objecttmp); |
394 | + } |
|
361 | 395 | $substitutionarray['__ID__'] = ($oneemailperrecipient ? join(', ',array_keys($listofqualifiedobj)) : $objecttmp->id); |
362 | 396 | $substitutionarray['__REF__'] = ($oneemailperrecipient ? join(', ',$listofqualifiedref) : $objecttmp->ref); |
363 | 397 | $substitutionarray['__EMAIL__'] = $thirdparty->email; |
@@ -385,19 +419,36 @@ discard block |
||
385 | 419 | if ($oneemailperrecipient) |
386 | 420 | { |
387 | 421 | $trackid='thi'.$thirdparty->id; |
388 | - if ($objecttmp->element == 'expensereport') $trackid='use'.$thirdparty->id; |
|
389 | - if ($objecttmp->element == 'holiday') $trackid='use'.$thirdparty->id; |
|
390 | - } |
|
391 | - else |
|
422 | + if ($objecttmp->element == 'expensereport') { |
|
423 | + $trackid='use'.$thirdparty->id; |
|
424 | + } |
|
425 | + if ($objecttmp->element == 'holiday') { |
|
426 | + $trackid='use'.$thirdparty->id; |
|
427 | + } |
|
428 | + } else |
|
392 | 429 | { |
393 | 430 | $trackid=strtolower(get_class($objecttmp)); |
394 | - if (get_class($objecttmp)=='Contrat') $trackid='con'; |
|
395 | - if (get_class($objecttmp)=='Propal') $trackid='pro'; |
|
396 | - if (get_class($objecttmp)=='Commande') $trackid='ord'; |
|
397 | - if (get_class($objecttmp)=='Facture') $trackid='inv'; |
|
398 | - if (get_class($objecttmp)=='Supplier_Proposal') $trackid='spr'; |
|
399 | - if (get_class($objecttmp)=='CommandeFournisseur') $trackid='sor'; |
|
400 | - if (get_class($objecttmp)=='FactureFournisseur') $trackid='sin'; |
|
431 | + if (get_class($objecttmp)=='Contrat') { |
|
432 | + $trackid='con'; |
|
433 | + } |
|
434 | + if (get_class($objecttmp)=='Propal') { |
|
435 | + $trackid='pro'; |
|
436 | + } |
|
437 | + if (get_class($objecttmp)=='Commande') { |
|
438 | + $trackid='ord'; |
|
439 | + } |
|
440 | + if (get_class($objecttmp)=='Facture') { |
|
441 | + $trackid='inv'; |
|
442 | + } |
|
443 | + if (get_class($objecttmp)=='Supplier_Proposal') { |
|
444 | + $trackid='spr'; |
|
445 | + } |
|
446 | + if (get_class($objecttmp)=='CommandeFournisseur') { |
|
447 | + $trackid='sor'; |
|
448 | + } |
|
449 | + if (get_class($objecttmp)=='FactureFournisseur') { |
|
450 | + $trackid='sin'; |
|
451 | + } |
|
401 | 452 | |
402 | 453 | $trackid.=$objecttmp->id; |
403 | 454 | } |
@@ -410,8 +461,7 @@ discard block |
||
410 | 461 | if ($mailfile->error) |
411 | 462 | { |
412 | 463 | $resaction.='<div class="error">'.$mailfile->error.'</div>'; |
413 | - } |
|
414 | - else |
|
464 | + } else |
|
415 | 465 | { |
416 | 466 | $result=$mailfile->sendfile(); |
417 | 467 | if ($result) |
@@ -433,7 +483,9 @@ discard block |
||
433 | 483 | $actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto; |
434 | 484 | if ($message) |
435 | 485 | { |
436 | - if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc); |
|
486 | + if ($sendtocc) { |
|
487 | + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc); |
|
488 | + } |
|
437 | 489 | $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject); |
438 | 490 | $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":"); |
439 | 491 | $actionmsg = dol_concatdesc($actionmsg, $message); |
@@ -448,14 +500,30 @@ discard block |
||
448 | 500 | $objectobj->elementtype = $objectobj->element; |
449 | 501 | |
450 | 502 | $triggername = strtoupper(get_class($objectobj)) .'_SENTBYMAIL'; |
451 | - if ($triggername == 'SOCIETE_SENTBYMAIL') $triggername = 'COMPANY_SENTBYEMAIL'; |
|
452 | - if ($triggername == 'CONTRAT_SENTBYMAIL') $triggername = 'CONTRACT_SENTBYEMAIL'; |
|
453 | - if ($triggername == 'COMMANDE_SENTBYMAIL') $triggername = 'ORDER_SENTBYEMAIL'; |
|
454 | - if ($triggername == 'FACTURE_SENTBYMAIL') $triggername = 'BILL_SENTBYMAIL'; |
|
455 | - if ($triggername == 'EXPEDITION_SENTBYMAIL') $triggername = 'SHIPPING_SENTBYEMAIL'; |
|
456 | - if ($triggername == 'COMMANDEFOURNISSEUR_SENTBYMAIL') $triggername = 'ORDER_SUPPLIER_SENTBYMAIL'; |
|
457 | - if ($triggername == 'FACTUREFOURNISSEUR_SENTBYMAIL') $triggername = 'BILL_SUPPLIER_SENTBYEMAIL'; |
|
458 | - if ($triggername == 'SUPPLIERPROPOSAL_SENTBYMAIL') $triggername = 'PROPOSAL_SUPPLIER_SENTBYEMAIL'; |
|
503 | + if ($triggername == 'SOCIETE_SENTBYMAIL') { |
|
504 | + $triggername = 'COMPANY_SENTBYEMAIL'; |
|
505 | + } |
|
506 | + if ($triggername == 'CONTRAT_SENTBYMAIL') { |
|
507 | + $triggername = 'CONTRACT_SENTBYEMAIL'; |
|
508 | + } |
|
509 | + if ($triggername == 'COMMANDE_SENTBYMAIL') { |
|
510 | + $triggername = 'ORDER_SENTBYEMAIL'; |
|
511 | + } |
|
512 | + if ($triggername == 'FACTURE_SENTBYMAIL') { |
|
513 | + $triggername = 'BILL_SENTBYMAIL'; |
|
514 | + } |
|
515 | + if ($triggername == 'EXPEDITION_SENTBYMAIL') { |
|
516 | + $triggername = 'SHIPPING_SENTBYEMAIL'; |
|
517 | + } |
|
518 | + if ($triggername == 'COMMANDEFOURNISSEUR_SENTBYMAIL') { |
|
519 | + $triggername = 'ORDER_SUPPLIER_SENTBYMAIL'; |
|
520 | + } |
|
521 | + if ($triggername == 'FACTUREFOURNISSEUR_SENTBYMAIL') { |
|
522 | + $triggername = 'BILL_SUPPLIER_SENTBYEMAIL'; |
|
523 | + } |
|
524 | + if ($triggername == 'SUPPLIERPROPOSAL_SENTBYMAIL') { |
|
525 | + $triggername = 'PROPOSAL_SUPPLIER_SENTBYEMAIL'; |
|
526 | + } |
|
459 | 527 | |
460 | 528 | if (! empty($triggername)) |
461 | 529 | { |
@@ -475,16 +543,14 @@ discard block |
||
475 | 543 | |
476 | 544 | $nbsent++; |
477 | 545 | } |
478 | - } |
|
479 | - else |
|
546 | + } else |
|
480 | 547 | { |
481 | 548 | $langs->load("other"); |
482 | 549 | if ($mailfile->error) |
483 | 550 | { |
484 | 551 | $resaction.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); |
485 | 552 | $resaction.='<br><div class="error">'.$mailfile->error.'</div>'; |
486 | - } |
|
487 | - else |
|
553 | + } else |
|
488 | 554 | { |
489 | 555 | $resaction.='<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>'; |
490 | 556 | } |
@@ -506,8 +572,7 @@ discard block |
||
506 | 572 | //setEventMessages($langs->trans("EMailSentToNRecipients", $nbsent.'/'.count($toselect)), null, 'mesgs'); |
507 | 573 | setEventMessages($langs->trans("EMailSentForNElements", $nbsent.'/'.count($toselect)), null, 'mesgs'); |
508 | 574 | setEventMessages($resaction, null, 'mesgs'); |
509 | - } |
|
510 | - else |
|
575 | + } else |
|
511 | 576 | { |
512 | 577 | //setEventMessages($langs->trans("EMailSentToNRecipients", 0), null, 'warnings'); // May be object has no generated PDF file |
513 | 578 | setEventMessages($resaction, null, 'warnings'); |
@@ -534,10 +599,15 @@ discard block |
||
534 | 599 | foreach($orders as $id_order) |
535 | 600 | { |
536 | 601 | $cmd = new Commande($db); |
537 | - if ($cmd->fetch($id_order) <= 0) continue; |
|
602 | + if ($cmd->fetch($id_order) <= 0) { |
|
603 | + continue; |
|
604 | + } |
|
538 | 605 | |
539 | 606 | $objecttmp = new Facture($db); |
540 | - if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. |
|
607 | + if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) { |
|
608 | + $objecttmp = $TFactThird[$cmd->socid]; |
|
609 | + } |
|
610 | + // If option "one bill per third" is set, we use already created order. |
|
541 | 611 | else { |
542 | 612 | |
543 | 613 | $objecttmp->socid = $cmd->socid; |
@@ -558,7 +628,9 @@ discard block |
||
558 | 628 | |
559 | 629 | $res = $objecttmp->create($user); |
560 | 630 | |
561 | - if($res > 0) $nb_bills_created++; |
|
631 | + if($res > 0) { |
|
632 | + $nb_bills_created++; |
|
633 | + } |
|
562 | 634 | } |
563 | 635 | |
564 | 636 | if ($objecttmp->id > 0) |
@@ -611,28 +683,38 @@ discard block |
||
611 | 683 | { |
612 | 684 | $result=$objecttmp->insert_discount($discountid); |
613 | 685 | //$result=$discount->link_to_invoice($lineid,$id); |
614 | - } |
|
615 | - else |
|
686 | + } else |
|
616 | 687 | { |
617 | 688 | setEventMessages($discount->error, $discount->errors, 'errors'); |
618 | 689 | $error++; |
619 | 690 | break; |
620 | 691 | } |
621 | - } |
|
622 | - else |
|
692 | + } else |
|
623 | 693 | { |
624 | 694 | // Positive line |
625 | 695 | $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); |
626 | 696 | // Date start |
627 | 697 | $date_start=false; |
628 | - if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue; |
|
629 | - if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; |
|
630 | - if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; |
|
698 | + if ($lines[$i]->date_debut_prevue) { |
|
699 | + $date_start=$lines[$i]->date_debut_prevue; |
|
700 | + } |
|
701 | + if ($lines[$i]->date_debut_reel) { |
|
702 | + $date_start=$lines[$i]->date_debut_reel; |
|
703 | + } |
|
704 | + if ($lines[$i]->date_start) { |
|
705 | + $date_start=$lines[$i]->date_start; |
|
706 | + } |
|
631 | 707 | //Date end |
632 | 708 | $date_end=false; |
633 | - if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue; |
|
634 | - if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; |
|
635 | - if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; |
|
709 | + if ($lines[$i]->date_fin_prevue) { |
|
710 | + $date_end=$lines[$i]->date_fin_prevue; |
|
711 | + } |
|
712 | + if ($lines[$i]->date_fin_reel) { |
|
713 | + $date_end=$lines[$i]->date_fin_reel; |
|
714 | + } |
|
715 | + if ($lines[$i]->date_end) { |
|
716 | + $date_end=$lines[$i]->date_end; |
|
717 | + } |
|
636 | 718 | // Reset fk_parent_line for no child products and special product |
637 | 719 | if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) |
638 | 720 | { |
@@ -675,8 +757,7 @@ discard block |
||
675 | 757 | if ($result > 0) |
676 | 758 | { |
677 | 759 | $lineid=$result; |
678 | - } |
|
679 | - else |
|
760 | + } else |
|
680 | 761 | { |
681 | 762 | $lineid=0; |
682 | 763 | $error++; |
@@ -694,8 +775,11 @@ discard block |
||
694 | 775 | |
695 | 776 | //$cmd->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module. |
696 | 777 | |
697 | - if(!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $objecttmp; |
|
698 | - else $TFact[$objecttmp->id] = $objecttmp; |
|
778 | + if(!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) { |
|
779 | + $TFactThird[$cmd->socid] = $objecttmp; |
|
780 | + } else { |
|
781 | + $TFact[$objecttmp->id] = $objecttmp; |
|
782 | + } |
|
699 | 783 | } |
700 | 784 | |
701 | 785 | // Build doc with all invoices |
@@ -734,34 +818,79 @@ discard block |
||
734 | 818 | |
735 | 819 | // Make a redirect to avoid to bill twice if we make a refresh or back |
736 | 820 | $param=''; |
737 | - if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); |
|
738 | - if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); |
|
739 | - if ($sall) $param.='&sall='.urlencode($sall); |
|
740 | - if ($socid > 0) $param.='&socid='.urlencode($socid); |
|
741 | - if ($viewstatut != '') $param.='&viewstatut='.urlencode($viewstatut); |
|
742 | - if ($search_orderday) $param.='&search_orderday='.urlencode($search_orderday); |
|
743 | - if ($search_ordermonth) $param.='&search_ordermonth='.urlencode($search_ordermonth); |
|
744 | - if ($search_orderyear) $param.='&search_orderyear='.urlencode($search_orderyear); |
|
745 | - if ($search_deliveryday) $param.='&search_deliveryday='.urlencode($search_deliveryday); |
|
746 | - if ($search_deliverymonth) $param.='&search_deliverymonth='.urlencode($search_deliverymonth); |
|
747 | - if ($search_deliveryyear) $param.='&search_deliveryyear='.urlencode($search_deliveryyear); |
|
748 | - if ($search_ref) $param.='&search_ref='.urlencode($search_ref); |
|
749 | - if ($search_company) $param.='&search_company='.urlencode($search_company); |
|
750 | - if ($search_ref_customer) $param.='&search_ref_customer='.urlencode($search_ref_customer); |
|
751 | - if ($search_user > 0) $param.='&search_user='.urlencode($search_user); |
|
752 | - if ($search_sale > 0) $param.='&search_sale='.urlencode($search_sale); |
|
753 | - if ($search_total_ht != '') $param.='&search_total_ht='.urlencode($search_total_ht); |
|
754 | - if ($search_total_vat != '') $param.='&search_total_vat='.urlencode($search_total_vat); |
|
755 | - if ($search_total_ttc != '') $param.='&search_total_ttc='.urlencode($search_total_ttc); |
|
756 | - if ($search_project_ref >= 0) $param.="&search_project_ref=".urlencode($search_project_ref); |
|
757 | - if ($show_files) $param.='&show_files=' .urlencode($show_files); |
|
758 | - if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); |
|
759 | - if ($billed != '') $param.='&billed='.urlencode($billed); |
|
821 | + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { |
|
822 | + $param.='&contextpage='.urlencode($contextpage); |
|
823 | + } |
|
824 | + if ($limit > 0 && $limit != $conf->liste_limit) { |
|
825 | + $param.='&limit='.urlencode($limit); |
|
826 | + } |
|
827 | + if ($sall) { |
|
828 | + $param.='&sall='.urlencode($sall); |
|
829 | + } |
|
830 | + if ($socid > 0) { |
|
831 | + $param.='&socid='.urlencode($socid); |
|
832 | + } |
|
833 | + if ($viewstatut != '') { |
|
834 | + $param.='&viewstatut='.urlencode($viewstatut); |
|
835 | + } |
|
836 | + if ($search_orderday) { |
|
837 | + $param.='&search_orderday='.urlencode($search_orderday); |
|
838 | + } |
|
839 | + if ($search_ordermonth) { |
|
840 | + $param.='&search_ordermonth='.urlencode($search_ordermonth); |
|
841 | + } |
|
842 | + if ($search_orderyear) { |
|
843 | + $param.='&search_orderyear='.urlencode($search_orderyear); |
|
844 | + } |
|
845 | + if ($search_deliveryday) { |
|
846 | + $param.='&search_deliveryday='.urlencode($search_deliveryday); |
|
847 | + } |
|
848 | + if ($search_deliverymonth) { |
|
849 | + $param.='&search_deliverymonth='.urlencode($search_deliverymonth); |
|
850 | + } |
|
851 | + if ($search_deliveryyear) { |
|
852 | + $param.='&search_deliveryyear='.urlencode($search_deliveryyear); |
|
853 | + } |
|
854 | + if ($search_ref) { |
|
855 | + $param.='&search_ref='.urlencode($search_ref); |
|
856 | + } |
|
857 | + if ($search_company) { |
|
858 | + $param.='&search_company='.urlencode($search_company); |
|
859 | + } |
|
860 | + if ($search_ref_customer) { |
|
861 | + $param.='&search_ref_customer='.urlencode($search_ref_customer); |
|
862 | + } |
|
863 | + if ($search_user > 0) { |
|
864 | + $param.='&search_user='.urlencode($search_user); |
|
865 | + } |
|
866 | + if ($search_sale > 0) { |
|
867 | + $param.='&search_sale='.urlencode($search_sale); |
|
868 | + } |
|
869 | + if ($search_total_ht != '') { |
|
870 | + $param.='&search_total_ht='.urlencode($search_total_ht); |
|
871 | + } |
|
872 | + if ($search_total_vat != '') { |
|
873 | + $param.='&search_total_vat='.urlencode($search_total_vat); |
|
874 | + } |
|
875 | + if ($search_total_ttc != '') { |
|
876 | + $param.='&search_total_ttc='.urlencode($search_total_ttc); |
|
877 | + } |
|
878 | + if ($search_project_ref >= 0) { |
|
879 | + $param.="&search_project_ref=".urlencode($search_project_ref); |
|
880 | + } |
|
881 | + if ($show_files) { |
|
882 | + $param.='&show_files=' .urlencode($show_files); |
|
883 | + } |
|
884 | + if ($optioncss != '') { |
|
885 | + $param.='&optioncss='.urlencode($optioncss); |
|
886 | + } |
|
887 | + if ($billed != '') { |
|
888 | + $param.='&billed='.urlencode($billed); |
|
889 | + } |
|
760 | 890 | |
761 | 891 | header("Location: ".$_SERVER['PHP_SELF'].'?'.$param); |
762 | 892 | exit; |
763 | - } |
|
764 | - else |
|
893 | + } else |
|
765 | 894 | { |
766 | 895 | $db->rollback(); |
767 | 896 | $action='create'; |
@@ -785,8 +914,9 @@ discard block |
||
785 | 914 | { |
786 | 915 | |
787 | 916 | $cmd = new Commande($db); |
788 | - if ($cmd->fetch($id_order) <= 0) |
|
789 | - continue; |
|
917 | + if ($cmd->fetch($id_order) <= 0) { |
|
918 | + continue; |
|
919 | + } |
|
790 | 920 | |
791 | 921 | if ($cmd->statut != Commande::STATUS_VALIDATED) |
792 | 922 | { |
@@ -794,28 +924,28 @@ discard block |
||
794 | 924 | setEventMessages($langs->trans("ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref), null, 'errors'); |
795 | 925 | $error++; |
796 | 926 | break; |
927 | + } else { |
|
928 | + $result = $cmd->cancel(); |
|
797 | 929 | } |
798 | - else |
|
799 | - $result = $cmd->cancel(); |
|
800 | 930 | |
801 | 931 | if ($result < 0) |
802 | 932 | { |
803 | 933 | setEventMessages($cmd->error, $cmd->errors, 'errors'); |
804 | 934 | $error++; |
805 | 935 | break; |
936 | + } else { |
|
937 | + $nbok++; |
|
806 | 938 | } |
807 | - else |
|
808 | - $nbok++; |
|
809 | 939 | } |
810 | 940 | if (!$error) |
811 | 941 | { |
812 | - if ($nbok > 1) |
|
813 | - setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
814 | - else |
|
815 | - setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
942 | + if ($nbok > 1) { |
|
943 | + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
944 | + } else { |
|
945 | + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
946 | + } |
|
816 | 947 | $db->commit(); |
817 | - } |
|
818 | - else |
|
948 | + } else |
|
819 | 949 | { |
820 | 950 | $db->rollback(); |
821 | 951 | } |
@@ -852,8 +982,13 @@ discard block |
||
852 | 982 | } |
853 | 983 | |
854 | 984 | $arrayofinclusion=array(); |
855 | - foreach($listofobjectref as $tmppdf) $arrayofinclusion[]='^'.preg_quote(dol_sanitizeFileName($tmppdf),'/').'\.pdf$'; |
|
856 | - foreach($listofobjectref as $tmppdf) $arrayofinclusion[]='^'.preg_quote(dol_sanitizeFileName($tmppdf),'/').'_[a-zA-Z0-9-_]+\.pdf$'; // To include PDF generated from ODX files |
|
985 | + foreach($listofobjectref as $tmppdf) { |
|
986 | + $arrayofinclusion[]='^'.preg_quote(dol_sanitizeFileName($tmppdf),'/').'\.pdf$'; |
|
987 | + } |
|
988 | + foreach($listofobjectref as $tmppdf) { |
|
989 | + $arrayofinclusion[]='^'.preg_quote(dol_sanitizeFileName($tmppdf),'/').'_[a-zA-Z0-9-_]+\.pdf$'; |
|
990 | + } |
|
991 | + // To include PDF generated from ODX files |
|
857 | 992 | $listoffiles = dol_dir_list($uploaddir,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true); |
858 | 993 | |
859 | 994 | // build list of files with full path |
@@ -874,8 +1009,12 @@ discard block |
||
874 | 1009 | // Define output language (Here it is not used because we do only merging existing PDF) |
875 | 1010 | $outputlangs = $langs; |
876 | 1011 | $newlang=''; |
877 | - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
878 | - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$objecttmp->thirdparty->default_lang; |
|
1012 | + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) { |
|
1013 | + $newlang=GETPOST('lang_id','aZ09'); |
|
1014 | + } |
|
1015 | + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { |
|
1016 | + $newlang=$objecttmp->thirdparty->default_lang; |
|
1017 | + } |
|
879 | 1018 | if (! empty($newlang)) |
880 | 1019 | { |
881 | 1020 | $outputlangs = new Translate("",$conf); |
@@ -894,11 +1033,18 @@ discard block |
||
894 | 1033 | // Save merged file |
895 | 1034 | if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED) |
896 | 1035 | { |
897 | - if ($option=='late') $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late"))); |
|
898 | - else $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))); |
|
1036 | + if ($option=='late') { |
|
1037 | + $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late"))); |
|
1038 | + } else { |
|
1039 | + $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))); |
|
1040 | + } |
|
1041 | + } |
|
1042 | + if ($year) { |
|
1043 | + $filename.='_'.$year; |
|
1044 | + } |
|
1045 | + if ($month) { |
|
1046 | + $filename.='_'.$month; |
|
899 | 1047 | } |
900 | - if ($year) $filename.='_'.$year; |
|
901 | - if ($month) $filename.='_'.$month; |
|
902 | 1048 | |
903 | 1049 | if (count($files)>0) |
904 | 1050 | { |
@@ -913,18 +1059,17 @@ discard block |
||
913 | 1059 | $cmd = 'pdftk '.escapeshellarg($input_files).' cat output '.escapeshellarg($file); |
914 | 1060 | exec($cmd); |
915 | 1061 | |
916 | - if (! empty($conf->global->MAIN_UMASK)) |
|
917 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
1062 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
1063 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
1064 | + } |
|
918 | 1065 | |
919 | 1066 | $langs->load("exports"); |
920 | 1067 | setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs'); |
921 | - } |
|
922 | - else |
|
1068 | + } else |
|
923 | 1069 | { |
924 | 1070 | setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors'); |
925 | 1071 | } |
926 | - } |
|
927 | - else { |
|
1072 | + } else { |
|
928 | 1073 | // Create empty PDF |
929 | 1074 | $formatarray=pdf_getFormat(); |
930 | 1075 | $page_largeur = $formatarray['width']; |
@@ -940,7 +1085,9 @@ discard block |
||
940 | 1085 | } |
941 | 1086 | $pdf->SetFont(pdf_getPDFFont($outputlangs)); |
942 | 1087 | |
943 | - if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); |
|
1088 | + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) { |
|
1089 | + $pdf->SetCompression(false); |
|
1090 | + } |
|
944 | 1091 | |
945 | 1092 | // Add all others |
946 | 1093 | foreach($files as $file) |
@@ -966,23 +1113,30 @@ discard block |
||
966 | 1113 | // Save merged file |
967 | 1114 | if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED) |
968 | 1115 | { |
969 | - if ($option=='late') $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late"))); |
|
970 | - else $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))); |
|
1116 | + if ($option=='late') { |
|
1117 | + $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late"))); |
|
1118 | + } else { |
|
1119 | + $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))); |
|
1120 | + } |
|
1121 | + } |
|
1122 | + if ($year) { |
|
1123 | + $filename.='_'.$year; |
|
1124 | + } |
|
1125 | + if ($month) { |
|
1126 | + $filename.='_'.$month; |
|
971 | 1127 | } |
972 | - if ($year) $filename.='_'.$year; |
|
973 | - if ($month) $filename.='_'.$month; |
|
974 | 1128 | if ($pagecount) |
975 | 1129 | { |
976 | 1130 | $now=dol_now(); |
977 | 1131 | $file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf'; |
978 | 1132 | $pdf->Output($file,'F'); |
979 | - if (! empty($conf->global->MAIN_UMASK)) |
|
980 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
1133 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
1134 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
1135 | + } |
|
981 | 1136 | |
982 | 1137 | $langs->load("exports"); |
983 | 1138 | setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs'); |
984 | - } |
|
985 | - else |
|
1139 | + } else |
|
986 | 1140 | { |
987 | 1141 | setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors'); |
988 | 1142 | } |
@@ -998,8 +1152,11 @@ discard block |
||
998 | 1152 | $upload_dir = $diroutputmassaction; |
999 | 1153 | $file = $upload_dir . '/' . GETPOST('file'); |
1000 | 1154 | $ret=dol_delete_file($file); |
1001 | - if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs'); |
|
1002 | - else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors'); |
|
1155 | + if ($ret) { |
|
1156 | + setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs'); |
|
1157 | + } else { |
|
1158 | + setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors'); |
|
1159 | + } |
|
1003 | 1160 | $action=''; |
1004 | 1161 | } |
1005 | 1162 | |
@@ -1039,16 +1196,15 @@ discard block |
||
1039 | 1196 | setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref), null, 'errors'); |
1040 | 1197 | $error++; |
1041 | 1198 | break; |
1042 | - } |
|
1043 | - elseif ($result < 0) |
|
1199 | + } elseif ($result < 0) |
|
1044 | 1200 | { |
1045 | 1201 | setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); |
1046 | 1202 | $error++; |
1047 | 1203 | break; |
1204 | + } else { |
|
1205 | + $nbok++; |
|
1048 | 1206 | } |
1049 | - else $nbok++; |
|
1050 | - } |
|
1051 | - else |
|
1207 | + } else |
|
1052 | 1208 | { |
1053 | 1209 | setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); |
1054 | 1210 | $error++; |
@@ -1058,11 +1214,13 @@ discard block |
||
1058 | 1214 | |
1059 | 1215 | if (! $error) |
1060 | 1216 | { |
1061 | - if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
1062 | - else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
1217 | + if ($nbok > 1) { |
|
1218 | + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
1219 | + } else { |
|
1220 | + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
1221 | + } |
|
1063 | 1222 | $db->commit(); |
1064 | - } |
|
1065 | - else |
|
1223 | + } else |
|
1066 | 1224 | { |
1067 | 1225 | $db->rollback(); |
1068 | 1226 | } |
@@ -1083,10 +1241,10 @@ discard block |
||
1083 | 1241 | setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); |
1084 | 1242 | $error++; |
1085 | 1243 | break; |
1086 | - } else |
|
1087 | - $nbok++; |
|
1088 | - } |
|
1089 | - else { |
|
1244 | + } else { |
|
1245 | + $nbok++; |
|
1246 | + } |
|
1247 | + } else { |
|
1090 | 1248 | setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); |
1091 | 1249 | $error++; |
1092 | 1250 | break; |
@@ -1094,13 +1252,13 @@ discard block |
||
1094 | 1252 | } |
1095 | 1253 | |
1096 | 1254 | if (!$error) { |
1097 | - if ($nbok > 1) |
|
1098 | - setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
1099 | - else |
|
1100 | - setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
1255 | + if ($nbok > 1) { |
|
1256 | + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
1257 | + } else { |
|
1258 | + setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs'); |
|
1259 | + } |
|
1101 | 1260 | $db->commit(); |
1102 | - } |
|
1103 | - else { |
|
1261 | + } else { |
|
1104 | 1262 | $db->rollback(); |
1105 | 1263 | } |
1106 | 1264 | } |
@@ -1137,18 +1295,21 @@ discard block |
||
1137 | 1295 | } |
1138 | 1296 | } |
1139 | 1297 | |
1140 | - if (in_array($objecttmp->element, array('societe', 'member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1); |
|
1141 | - else $result = $objecttmp->delete($user); |
|
1298 | + if (in_array($objecttmp->element, array('societe', 'member'))) { |
|
1299 | + $result = $objecttmp->delete($objecttmp->id, $user, 1); |
|
1300 | + } else { |
|
1301 | + $result = $objecttmp->delete($user); |
|
1302 | + } |
|
1142 | 1303 | |
1143 | 1304 | if ($result <= 0) |
1144 | 1305 | { |
1145 | 1306 | setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); |
1146 | 1307 | $error++; |
1147 | 1308 | break; |
1309 | + } else { |
|
1310 | + $nbok++; |
|
1148 | 1311 | } |
1149 | - else $nbok++; |
|
1150 | - } |
|
1151 | - else |
|
1312 | + } else |
|
1152 | 1313 | { |
1153 | 1314 | setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); |
1154 | 1315 | $error++; |
@@ -1158,11 +1319,13 @@ discard block |
||
1158 | 1319 | |
1159 | 1320 | if (! $error) |
1160 | 1321 | { |
1161 | - if ($nbok > 1) setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); |
|
1162 | - else setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); |
|
1322 | + if ($nbok > 1) { |
|
1323 | + setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); |
|
1324 | + } else { |
|
1325 | + setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); |
|
1326 | + } |
|
1163 | 1327 | $db->commit(); |
1164 | - } |
|
1165 | - else |
|
1328 | + } else |
|
1166 | 1329 | { |
1167 | 1330 | $db->rollback(); |
1168 | 1331 | } |
@@ -1185,9 +1348,17 @@ discard block |
||
1185 | 1348 | $outputlangs = $langs; |
1186 | 1349 | $newlang=''; |
1187 | 1350 | |
1188 | - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
1189 | - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) $newlang=$objecttmp->thirdparty->default_lang; // for proposal, order, invoice, ... |
|
1190 | - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->default_lang)) $newlang=$objecttmp->default_lang; // for thirdparty |
|
1351 | + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) { |
|
1352 | + $newlang=GETPOST('lang_id','aZ09'); |
|
1353 | + } |
|
1354 | + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) { |
|
1355 | + $newlang=$objecttmp->thirdparty->default_lang; |
|
1356 | + } |
|
1357 | + // for proposal, order, invoice, ... |
|
1358 | + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->default_lang)) { |
|
1359 | + $newlang=$objecttmp->default_lang; |
|
1360 | + } |
|
1361 | + // for thirdparty |
|
1191 | 1362 | if (! empty($newlang)) |
1192 | 1363 | { |
1193 | 1364 | $outputlangs = new Translate("",$conf); |
@@ -1195,10 +1366,18 @@ discard block |
||
1195 | 1366 | } |
1196 | 1367 | |
1197 | 1368 | // To be sure vars is defined |
1198 | - if (empty($hidedetails)) $hidedetails=0; |
|
1199 | - if (empty($hidedesc)) $hidedesc=0; |
|
1200 | - if (empty($hideref)) $hideref=0; |
|
1201 | - if (empty($moreparams)) $moreparams=null; |
|
1369 | + if (empty($hidedetails)) { |
|
1370 | + $hidedetails=0; |
|
1371 | + } |
|
1372 | + if (empty($hidedesc)) { |
|
1373 | + $hidedesc=0; |
|
1374 | + } |
|
1375 | + if (empty($hideref)) { |
|
1376 | + $hideref=0; |
|
1377 | + } |
|
1378 | + if (empty($moreparams)) { |
|
1379 | + $moreparams=null; |
|
1380 | + } |
|
1202 | 1381 | |
1203 | 1382 | $result= $objecttmp->generateDocument($objecttmp->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); |
1204 | 1383 | |
@@ -1207,10 +1386,10 @@ discard block |
||
1207 | 1386 | setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); |
1208 | 1387 | $error++; |
1209 | 1388 | break; |
1389 | + } else { |
|
1390 | + $nbok++; |
|
1210 | 1391 | } |
1211 | - else $nbok++; |
|
1212 | - } |
|
1213 | - else |
|
1392 | + } else |
|
1214 | 1393 | { |
1215 | 1394 | setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); |
1216 | 1395 | $error++; |
@@ -1220,11 +1399,13 @@ discard block |
||
1220 | 1399 | |
1221 | 1400 | if (! $error) |
1222 | 1401 | { |
1223 | - if ($nbok > 1) setEventMessages($langs->trans("RecordsGenerated", $nbok), null, 'mesgs'); |
|
1224 | - else setEventMessages($langs->trans("RecordGenerated", $nbok), null, 'mesgs'); |
|
1402 | + if ($nbok > 1) { |
|
1403 | + setEventMessages($langs->trans("RecordsGenerated", $nbok), null, 'mesgs'); |
|
1404 | + } else { |
|
1405 | + setEventMessages($langs->trans("RecordGenerated", $nbok), null, 'mesgs'); |
|
1406 | + } |
|
1225 | 1407 | $db->commit(); |
1226 | - } |
|
1227 | - else |
|
1408 | + } else |
|
1228 | 1409 | { |
1229 | 1410 | $db->rollback(); |
1230 | 1411 | } |
@@ -1234,7 +1415,9 @@ discard block |
||
1234 | 1415 | $parameters['uploaddir']=$uploaddir; |
1235 | 1416 | |
1236 | 1417 | $reshook=$hookmanager->executeHooks('doMassActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
1237 | -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
1418 | +if ($reshook < 0) { |
|
1419 | + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
1420 | +} |
|
1238 | 1421 | |
1239 | 1422 | |
1240 | 1423 |
@@ -18,13 +18,27 @@ |
||
18 | 18 | * Library javascript to enable Browser notifications |
19 | 19 | */ |
20 | 20 | |
21 | -if (!defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); |
|
22 | -if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); |
|
23 | -if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1); |
|
24 | -if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); |
|
25 | -if (!defined('NOLOGIN')) define('NOLOGIN', 1); |
|
26 | -if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1); |
|
27 | -if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1); |
|
21 | +if (!defined('NOREQUIREUSER')) { |
|
22 | + define('NOREQUIREUSER', '1'); |
|
23 | +} |
|
24 | +if (!defined('NOREQUIRESOC')) { |
|
25 | + define('NOREQUIRESOC', '1'); |
|
26 | +} |
|
27 | +if (!defined('NOCSRFCHECK')) { |
|
28 | + define('NOCSRFCHECK', 1); |
|
29 | +} |
|
30 | +if (!defined('NOTOKENRENEWAL')) { |
|
31 | + define('NOTOKENRENEWAL', 1); |
|
32 | +} |
|
33 | +if (!defined('NOLOGIN')) { |
|
34 | + define('NOLOGIN', 1); |
|
35 | +} |
|
36 | +if (!defined('NOREQUIREMENU')) { |
|
37 | + define('NOREQUIREMENU', 1); |
|
38 | +} |
|
39 | +if (!defined('NOREQUIREHTML')) { |
|
40 | + define('NOREQUIREHTML', 1); |
|
41 | +} |
|
28 | 42 | |
29 | 43 | require_once '../../main.inc.php'; |
30 | 44 |
@@ -24,14 +24,28 @@ discard block |
||
24 | 24 | |
25 | 25 | //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language |
26 | 26 | //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); |
27 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
|
27 | +if (! defined('NOREQUIRESOC')) { |
|
28 | + define('NOREQUIRESOC','1'); |
|
29 | +} |
|
28 | 30 | //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations |
29 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1); |
|
30 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); |
|
31 | -if (! defined('NOLOGIN')) define('NOLOGIN',1); |
|
32 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); |
|
33 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1); |
|
34 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
31 | +if (! defined('NOCSRFCHECK')) { |
|
32 | + define('NOCSRFCHECK',1); |
|
33 | +} |
|
34 | +if (! defined('NOTOKENRENEWAL')) { |
|
35 | + define('NOTOKENRENEWAL',1); |
|
36 | +} |
|
37 | +if (! defined('NOLOGIN')) { |
|
38 | + define('NOLOGIN',1); |
|
39 | +} |
|
40 | +if (! defined('NOREQUIREMENU')) { |
|
41 | + define('NOREQUIREMENU',1); |
|
42 | +} |
|
43 | +if (! defined('NOREQUIREHTML')) { |
|
44 | + define('NOREQUIREHTML',1); |
|
45 | +} |
|
46 | +if (! defined('NOREQUIREAJAX')) { |
|
47 | + define('NOREQUIREAJAX','1'); |
|
48 | +} |
|
35 | 49 | |
36 | 50 | session_cache_limiter('public'); |
37 | 51 | |
@@ -40,8 +54,11 @@ discard block |
||
40 | 54 | // Define javascript type |
41 | 55 | top_httphead('text/javascript; charset=UTF-8'); |
42 | 56 | // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access. |
43 | -if (empty($dolibarr_nocache)) header('Cache-Control: max-age=10800, public, must-revalidate'); |
|
44 | -else header('Cache-Control: no-cache'); |
|
57 | +if (empty($dolibarr_nocache)) { |
|
58 | + header('Cache-Control: max-age=10800, public, must-revalidate'); |
|
59 | +} else { |
|
60 | + header('Cache-Control: no-cache'); |
|
61 | +} |
|
45 | 62 | |
46 | 63 | ?> |
47 | 64 |
@@ -21,13 +21,27 @@ discard block |
||
21 | 21 | * \brief File that include javascript functions for timepicker |
22 | 22 | */ |
23 | 23 | |
24 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
|
25 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1); |
|
26 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); |
|
27 | -if (! defined('NOLOGIN')) define('NOLOGIN',1); |
|
28 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); |
|
29 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1); |
|
30 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
24 | +if (! defined('NOREQUIRESOC')) { |
|
25 | + define('NOREQUIRESOC','1'); |
|
26 | +} |
|
27 | +if (! defined('NOCSRFCHECK')) { |
|
28 | + define('NOCSRFCHECK',1); |
|
29 | +} |
|
30 | +if (! defined('NOTOKENRENEWAL')) { |
|
31 | + define('NOTOKENRENEWAL',1); |
|
32 | +} |
|
33 | +if (! defined('NOLOGIN')) { |
|
34 | + define('NOLOGIN',1); |
|
35 | +} |
|
36 | +if (! defined('NOREQUIREMENU')) { |
|
37 | + define('NOREQUIREMENU',1); |
|
38 | +} |
|
39 | +if (! defined('NOREQUIREHTML')) { |
|
40 | + define('NOREQUIREHTML',1); |
|
41 | +} |
|
42 | +if (! defined('NOREQUIREAJAX')) { |
|
43 | + define('NOREQUIREAJAX','1'); |
|
44 | +} |
|
31 | 45 | |
32 | 46 | session_cache_limiter('public'); |
33 | 47 | |
@@ -36,8 +50,11 @@ discard block |
||
36 | 50 | // Define javascript type |
37 | 51 | top_httphead('text/javascript; charset=UTF-8'); |
38 | 52 | // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access. |
39 | -if (empty($dolibarr_nocache)) header('Cache-Control: max-age=10800, public, must-revalidate'); |
|
40 | -else header('Cache-Control: no-cache'); |
|
53 | +if (empty($dolibarr_nocache)) { |
|
54 | + header('Cache-Control: max-age=10800, public, must-revalidate'); |
|
55 | +} else { |
|
56 | + header('Cache-Control: no-cache'); |
|
57 | +} |
|
41 | 58 | ?> |
42 | 59 | |
43 | 60 | // For JQuery Timepicker |
@@ -61,4 +78,6 @@ discard block |
||
61 | 78 | }); |
62 | 79 | |
63 | 80 | <?php |
64 | -if (is_object($db)) $db->close(); |
|
81 | +if (is_object($db)) { |
|
82 | + $db->close(); |
|
83 | +} |
@@ -31,8 +31,11 @@ discard block |
||
31 | 31 | { |
32 | 32 | if (! empty($_FILES)) |
33 | 33 | { |
34 | - if (is_array($_FILES['userfile']['tmp_name'])) $userfiles=$_FILES['userfile']['tmp_name']; |
|
35 | - else $userfiles=array($_FILES['userfile']['tmp_name']); |
|
34 | + if (is_array($_FILES['userfile']['tmp_name'])) { |
|
35 | + $userfiles=$_FILES['userfile']['tmp_name']; |
|
36 | + } else { |
|
37 | + $userfiles=array($_FILES['userfile']['tmp_name']); |
|
38 | + } |
|
36 | 39 | |
37 | 40 | foreach($userfiles as $key => $userfile) |
38 | 41 | { |
@@ -41,8 +44,7 @@ discard block |
||
41 | 44 | $error++; |
42 | 45 | if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2){ |
43 | 46 | setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors'); |
44 | - } |
|
45 | - else { |
|
47 | + } else { |
|
46 | 48 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors'); |
47 | 49 | } |
48 | 50 | } |
@@ -52,20 +54,20 @@ discard block |
||
52 | 54 | { |
53 | 55 | // Define if we have to generate thumbs or not |
54 | 56 | $generatethumbs = 1; |
55 | - if (GETPOST('section_dir')) $generatethumbs=0; |
|
57 | + if (GETPOST('section_dir')) { |
|
58 | + $generatethumbs=0; |
|
59 | + } |
|
56 | 60 | |
57 | 61 | if (! empty($upload_dirold) && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
58 | 62 | { |
59 | 63 | $result = dol_add_file_process($upload_dirold, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs); |
60 | - } |
|
61 | - elseif (! empty($upload_dir)) |
|
64 | + } elseif (! empty($upload_dir)) |
|
62 | 65 | { |
63 | 66 | $result = dol_add_file_process($upload_dir, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs); |
64 | 67 | } |
65 | 68 | } |
66 | 69 | } |
67 | -} |
|
68 | -elseif (GETPOST('linkit','none') && ! empty($conf->global->MAIN_UPLOAD_DOC)) |
|
70 | +} elseif (GETPOST('linkit','none') && ! empty($conf->global->MAIN_UPLOAD_DOC)) |
|
69 | 71 | { |
70 | 72 | $link = GETPOST('link', 'alpha'); |
71 | 73 | if ($link) |
@@ -82,25 +84,34 @@ discard block |
||
82 | 84 | if ($action == 'confirm_deletefile' && $confirm == 'yes') |
83 | 85 | { |
84 | 86 | $urlfile = GETPOST('urlfile', 'alpha', 0, null, null, 1); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). |
85 | - if (GETPOST('section', 'alpha')) // For a delete from the ECM module, upload_dir is ECM root dir and urlfile contains relative path from upload_dir |
|
87 | + if (GETPOST('section', 'alpha')) { |
|
88 | + // For a delete from the ECM module, upload_dir is ECM root dir and urlfile contains relative path from upload_dir |
|
86 | 89 | { |
87 | 90 | $file = $upload_dir . (preg_match('/\/$/', $upload_dir) ? '' : '/') . $urlfile; |
88 | 91 | } |
89 | - else // For a delete from the file manager into another module, or from documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile. |
|
92 | + } else // For a delete from the file manager into another module, or from documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile. |
|
90 | 93 | { |
91 | 94 | $urlfile=basename($urlfile); |
92 | 95 | $file = $upload_dir . (preg_match('/\/$/', $upload_dir) ? '' : '/') . $urlfile; |
93 | - if (! empty($upload_dirold)) $fileold = $upload_dirold . "/" . $urlfile; |
|
96 | + if (! empty($upload_dirold)) { |
|
97 | + $fileold = $upload_dirold . "/" . $urlfile; |
|
98 | + } |
|
94 | 99 | } |
95 | 100 | $linkid = GETPOST('linkid', 'int'); |
96 | 101 | |
97 | - if ($urlfile) // delete of a file |
|
102 | + if ($urlfile) { |
|
103 | + // delete of a file |
|
98 | 104 | { |
99 | - $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine |
|
105 | + $dir = dirname($file).'/'; |
|
106 | + } |
|
107 | + // Chemin du dossier contenant l'image d'origine |
|
100 | 108 | $dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette (if file is an image) |
101 | 109 | |
102 | 110 | $ret = dol_delete_file($file, 0, 0, 0, (is_object($object)?$object:null)); |
103 | - if (! empty($fileold)) dol_delete_file($fileold, 0, 0, 0, (is_object($object)?$object:null)); // Delete file using old path |
|
111 | + if (! empty($fileold)) { |
|
112 | + dol_delete_file($fileold, 0, 0, 0, (is_object($object)?$object:null)); |
|
113 | + } |
|
114 | + // Delete file using old path |
|
104 | 115 | |
105 | 116 | // Si elle existe, on efface la vignette |
106 | 117 | if (preg_match('/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i',$file,$regs)) |
@@ -118,12 +129,16 @@ discard block |
||
118 | 129 | } |
119 | 130 | } |
120 | 131 | |
121 | - if ($ret) setEventMessages($langs->trans("FileWasRemoved", $urlfile), null, 'mesgs'); |
|
122 | - else setEventMessages($langs->trans("ErrorFailToDeleteFile", $urlfile), null, 'errors'); |
|
123 | - } |
|
124 | - elseif ($linkid) // delete of external link |
|
132 | + if ($ret) { |
|
133 | + setEventMessages($langs->trans("FileWasRemoved", $urlfile), null, 'mesgs'); |
|
134 | + } else { |
|
135 | + setEventMessages($langs->trans("ErrorFailToDeleteFile", $urlfile), null, 'errors'); |
|
136 | + } |
|
137 | + } elseif ($linkid) { |
|
138 | + // delete of external link |
|
125 | 139 | { |
126 | 140 | require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; |
141 | + } |
|
127 | 142 | $link = new Link($db); |
128 | 143 | $link->id = $linkid; |
129 | 144 | $link->fetch(); |
@@ -147,15 +162,13 @@ discard block |
||
147 | 162 | { |
148 | 163 | header('Location: ' . $backtopage); |
149 | 164 | exit; |
150 | - } |
|
151 | - else |
|
165 | + } else |
|
152 | 166 | { |
153 | 167 | header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(GETPOST('section_dir','alpha')?'§ion_dir='.urlencode(GETPOST('section_dir','alpha')):'').(!empty($withproject)?'&withproject=1':'')); |
154 | 168 | exit; |
155 | 169 | } |
156 | 170 | } |
157 | -} |
|
158 | -elseif ($action == 'confirm_updateline' && GETPOST('save','alpha') && GETPOST('link', 'alpha')) |
|
171 | +} elseif ($action == 'confirm_updateline' && GETPOST('save','alpha') && GETPOST('link', 'alpha')) |
|
159 | 172 | { |
160 | 173 | require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; |
161 | 174 | $langs->load('link'); |
@@ -175,13 +188,11 @@ discard block |
||
175 | 188 | { |
176 | 189 | setEventMessages($langs->trans("ErrorFailedToUpdateLink", $link->label), null, 'mesgs'); |
177 | 190 | } |
178 | - } |
|
179 | - else |
|
191 | + } else |
|
180 | 192 | { |
181 | 193 | //error fetching |
182 | 194 | } |
183 | -} |
|
184 | -elseif ($action == 'renamefile' && GETPOST('renamefilesave','alpha')) |
|
195 | +} elseif ($action == 'renamefile' && GETPOST('renamefilesave','alpha')) |
|
185 | 196 | { |
186 | 197 | // For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile. |
187 | 198 | if (! empty($upload_dir)) |
@@ -220,7 +231,9 @@ discard block |
||
220 | 231 | // When we rename a file from the file manager in ecm, we must not regenerate thumbs (not a problem, we do pass here) |
221 | 232 | // When we rename a file from the website module, we must not regenerate thumbs (module = medias in such a case) |
222 | 233 | // but when we rename from a tab "Documents", we must regenerate thumbs |
223 | - if (GETPOST('modulepart') == 'medias') $generatethumbs=0; |
|
234 | + if (GETPOST('modulepart') == 'medias') { |
|
235 | + $generatethumbs=0; |
|
236 | + } |
|
224 | 237 | |
225 | 238 | if ($generatethumbs) |
226 | 239 | { |
@@ -234,14 +247,12 @@ discard block |
||
234 | 247 | } |
235 | 248 | |
236 | 249 | setEventMessages($langs->trans("FileRenamed"), null); |
237 | - } |
|
238 | - else |
|
250 | + } else |
|
239 | 251 | { |
240 | 252 | $langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now. |
241 | 253 | setEventMessages($langs->trans("ErrorFailToRenameFile", $filenamefrom, $filenameto), null, 'errors'); |
242 | 254 | } |
243 | - } |
|
244 | - else |
|
255 | + } else |
|
245 | 256 | { |
246 | 257 | $langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now. |
247 | 258 | setEventMessages($langs->trans("ErrorDestinationAlreadyExists", $filenameto), null, 'errors'); |
@@ -268,8 +279,7 @@ discard block |
||
268 | 279 | require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
269 | 280 | $ecmfile->share = getRandomPassword(true); |
270 | 281 | } |
271 | - } |
|
272 | - else |
|
282 | + } else |
|
273 | 283 | { |
274 | 284 | $ecmfile->share = ''; |
275 | 285 | } |