@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | /** |
99 | 99 | * Return next value |
100 | 100 | * |
101 | - * @param Societe $objsoc Object third party |
|
101 | + * @param integer $objsoc Object third party |
|
102 | 102 | * @param Object $object Object |
103 | 103 | * @return string Value if OK, 0 if KO |
104 | 104 | */ |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | /** |
137 | 137 | * Renvoie la reference de commande suivante non utilisee |
138 | 138 | * |
139 | - * @param Societe $objsoc Object third party |
|
139 | + * @param integer $objsoc Object third party |
|
140 | 140 | * @param Object $object Object |
141 | 141 | * @return string Texte descripif |
142 | 142 | */ |
@@ -44,7 +44,10 @@ discard block |
||
44 | 44 | { |
45 | 45 | global $conf; |
46 | 46 | |
47 | - if ((float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 5.0) $this->prefix = 'PO'; // We use correct standard code "PO = Purchase Order" |
|
47 | + if ((float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 5.0) { |
|
48 | + $this->prefix = 'PO'; |
|
49 | + } |
|
50 | + // We use correct standard code "PO = Purchase Order" |
|
48 | 51 | } |
49 | 52 | |
50 | 53 | /** |
@@ -96,8 +99,7 @@ discard block |
||
96 | 99 | if (! $coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm)) |
97 | 100 | { |
98 | 101 | return true; |
99 | - } |
|
100 | - else |
|
102 | + } else |
|
101 | 103 | { |
102 | 104 | $langs->load("errors"); |
103 | 105 | $this->error=$langs->trans('ErrorNumRefModel',$max); |
@@ -127,17 +129,28 @@ discard block |
||
127 | 129 | if ($resql) |
128 | 130 | { |
129 | 131 | $obj = $db->fetch_object($resql); |
130 | - if ($obj) $max = intval($obj->max); |
|
131 | - else $max=0; |
|
132 | + if ($obj) { |
|
133 | + $max = intval($obj->max); |
|
134 | + } else { |
|
135 | + $max=0; |
|
136 | + } |
|
132 | 137 | } |
133 | 138 | |
134 | 139 | //$date=time(); |
135 | 140 | $date=$object->date_commande; // Not always defined |
136 | - if (empty($date)) $date=$object->date; // Creation date is order date for suppliers orders |
|
141 | + if (empty($date)) { |
|
142 | + $date=$object->date; |
|
143 | + } |
|
144 | + // Creation date is order date for suppliers orders |
|
137 | 145 | $yymm = strftime("%y%m",$date); |
138 | 146 | |
139 | - if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
140 | - else $num = sprintf("%04s",$max+1); |
|
147 | + if ($max >= (pow(10, 4) - 1)) { |
|
148 | + $num=$max+1; |
|
149 | + } |
|
150 | + // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
151 | + else { |
|
152 | + $num = sprintf("%04s",$max+1); |
|
153 | + } |
|
141 | 154 | |
142 | 155 | return $this->prefix.$yymm."-".$num; |
143 | 156 | } |
@@ -42,117 +42,117 @@ |
||
42 | 42 | */ |
43 | 43 | function __construct() |
44 | 44 | { |
45 | - global $conf; |
|
45 | + global $conf; |
|
46 | 46 | |
47 | - if ((float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 5.0) $this->prefix = 'PO'; // We use correct standard code "PO = Purchase Order" |
|
47 | + if ((float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 5.0) $this->prefix = 'PO'; // We use correct standard code "PO = Purchase Order" |
|
48 | 48 | } |
49 | 49 | |
50 | - /** |
|
51 | - * Return description of numbering module |
|
52 | - * |
|
53 | - * @return string Text with description |
|
54 | - */ |
|
55 | - function info() |
|
56 | - { |
|
57 | - global $langs; |
|
58 | - return $langs->trans("SimpleNumRefModelDesc",$this->prefix); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Renvoi un exemple de numerotation |
|
64 | - * |
|
65 | - * @return string Example |
|
66 | - */ |
|
67 | - function getExample() |
|
68 | - { |
|
69 | - return $this->prefix."0501-0001"; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Test si les numeros deja en vigueur dans la base ne provoquent pas de |
|
75 | - * de conflits qui empechera cette numerotation de fonctionner. |
|
76 | - * |
|
77 | - * @return boolean false si conflit, true si ok |
|
78 | - */ |
|
79 | - function canBeActivated() |
|
80 | - { |
|
81 | - global $conf,$langs,$db; |
|
82 | - |
|
83 | - $coyymm=''; $max=''; |
|
50 | + /** |
|
51 | + * Return description of numbering module |
|
52 | + * |
|
53 | + * @return string Text with description |
|
54 | + */ |
|
55 | + function info() |
|
56 | + { |
|
57 | + global $langs; |
|
58 | + return $langs->trans("SimpleNumRefModelDesc",$this->prefix); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Renvoi un exemple de numerotation |
|
64 | + * |
|
65 | + * @return string Example |
|
66 | + */ |
|
67 | + function getExample() |
|
68 | + { |
|
69 | + return $this->prefix."0501-0001"; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Test si les numeros deja en vigueur dans la base ne provoquent pas de |
|
75 | + * de conflits qui empechera cette numerotation de fonctionner. |
|
76 | + * |
|
77 | + * @return boolean false si conflit, true si ok |
|
78 | + */ |
|
79 | + function canBeActivated() |
|
80 | + { |
|
81 | + global $conf,$langs,$db; |
|
82 | + |
|
83 | + $coyymm=''; $max=''; |
|
84 | 84 | |
85 | 85 | $posindice=8; |
86 | 86 | $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
87 | - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; |
|
87 | + $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; |
|
88 | 88 | $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
89 | - $sql.= " AND entity = ".$conf->entity; |
|
90 | - $resql=$db->query($sql); |
|
91 | - if ($resql) |
|
92 | - { |
|
93 | - $row = $db->fetch_row($resql); |
|
94 | - if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; } |
|
95 | - } |
|
96 | - if (! $coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm)) |
|
97 | - { |
|
98 | - return true; |
|
99 | - } |
|
100 | - else |
|
101 | - { |
|
89 | + $sql.= " AND entity = ".$conf->entity; |
|
90 | + $resql=$db->query($sql); |
|
91 | + if ($resql) |
|
92 | + { |
|
93 | + $row = $db->fetch_row($resql); |
|
94 | + if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; } |
|
95 | + } |
|
96 | + if (! $coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm)) |
|
97 | + { |
|
98 | + return true; |
|
99 | + } |
|
100 | + else |
|
101 | + { |
|
102 | 102 | $langs->load("errors"); |
103 | 103 | $this->error=$langs->trans('ErrorNumRefModel',$max); |
104 | - return false; |
|
105 | - } |
|
106 | - } |
|
104 | + return false; |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Return next value |
|
108 | + /** |
|
109 | + * Return next value |
|
110 | 110 | * |
111 | 111 | * @param Societe $objsoc Object third party |
112 | 112 | * @param Object $object Object |
113 | 113 | * @return string Value if OK, 0 if KO |
114 | - */ |
|
115 | - function getNextValue($objsoc=0,$object='') |
|
116 | - { |
|
117 | - global $db,$conf; |
|
118 | - |
|
119 | - // D'abord on recupere la valeur max |
|
120 | - $posindice=8; |
|
121 | - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
|
122 | - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; |
|
114 | + */ |
|
115 | + function getNextValue($objsoc=0,$object='') |
|
116 | + { |
|
117 | + global $db,$conf; |
|
118 | + |
|
119 | + // D'abord on recupere la valeur max |
|
120 | + $posindice=8; |
|
121 | + $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
|
122 | + $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; |
|
123 | 123 | $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
124 | - $sql.= " AND entity = ".$conf->entity; |
|
124 | + $sql.= " AND entity = ".$conf->entity; |
|
125 | 125 | |
126 | - $resql=$db->query($sql); |
|
127 | - if ($resql) |
|
128 | - { |
|
129 | - $obj = $db->fetch_object($resql); |
|
130 | - if ($obj) $max = intval($obj->max); |
|
131 | - else $max=0; |
|
132 | - } |
|
126 | + $resql=$db->query($sql); |
|
127 | + if ($resql) |
|
128 | + { |
|
129 | + $obj = $db->fetch_object($resql); |
|
130 | + if ($obj) $max = intval($obj->max); |
|
131 | + else $max=0; |
|
132 | + } |
|
133 | 133 | |
134 | 134 | //$date=time(); |
135 | - $date=$object->date_commande; // Not always defined |
|
136 | - if (empty($date)) $date=$object->date; // Creation date is order date for suppliers orders |
|
137 | - $yymm = strftime("%y%m",$date); |
|
135 | + $date=$object->date_commande; // Not always defined |
|
136 | + if (empty($date)) $date=$object->date; // Creation date is order date for suppliers orders |
|
137 | + $yymm = strftime("%y%m",$date); |
|
138 | 138 | |
139 | - if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
140 | - else $num = sprintf("%04s",$max+1); |
|
139 | + if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
140 | + else $num = sprintf("%04s",$max+1); |
|
141 | 141 | |
142 | - return $this->prefix.$yymm."-".$num; |
|
143 | - } |
|
142 | + return $this->prefix.$yymm."-".$num; |
|
143 | + } |
|
144 | 144 | |
145 | 145 | |
146 | - /** |
|
147 | - * Renvoie la reference de commande suivante non utilisee |
|
148 | - * |
|
146 | + /** |
|
147 | + * Renvoie la reference de commande suivante non utilisee |
|
148 | + * |
|
149 | 149 | * @param Societe $objsoc Object third party |
150 | 150 | * @param Object $object Object |
151 | - * @return string Texte descripif |
|
152 | - */ |
|
153 | - function commande_get_num($objsoc=0,$object='') |
|
154 | - { |
|
155 | - return $this->getNextValue($objsoc,$object); |
|
156 | - } |
|
151 | + * @return string Texte descripif |
|
152 | + */ |
|
153 | + function commande_get_num($objsoc=0,$object='') |
|
154 | + { |
|
155 | + return $this->getNextValue($objsoc,$object); |
|
156 | + } |
|
157 | 157 | } |
158 | 158 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * \brief Fichier contenant la classe du modele de numerotation de reference de commande fournisseur Muguet |
24 | 24 | */ |
25 | 25 | |
26 | -require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_order/modules_commandefournisseur.php'; |
|
26 | +require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php'; |
|
27 | 27 | |
28 | 28 | |
29 | 29 | /** |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | */ |
32 | 32 | class mod_commande_fournisseur_muguet extends ModeleNumRefSuppliersOrders |
33 | 33 | { |
34 | - var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
34 | + var $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
35 | 35 | var $error = ''; |
36 | 36 | var $nom = 'Muguet'; |
37 | - var $prefix='CF'; |
|
37 | + var $prefix = 'CF'; |
|
38 | 38 | |
39 | 39 | |
40 | 40 | /** |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | { |
45 | 45 | global $conf; |
46 | 46 | |
47 | - if ((float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 5.0) $this->prefix = 'PO'; // We use correct standard code "PO = Purchase Order" |
|
47 | + if ((float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 5.0) $this->prefix = 'PO'; // We use correct standard code "PO = Purchase Order" |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | function info() |
56 | 56 | { |
57 | 57 | global $langs; |
58 | - return $langs->trans("SimpleNumRefModelDesc",$this->prefix); |
|
58 | + return $langs->trans("SimpleNumRefModelDesc", $this->prefix); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | |
@@ -78,29 +78,29 @@ discard block |
||
78 | 78 | */ |
79 | 79 | function canBeActivated() |
80 | 80 | { |
81 | - global $conf,$langs,$db; |
|
81 | + global $conf, $langs, $db; |
|
82 | 82 | |
83 | - $coyymm=''; $max=''; |
|
83 | + $coyymm = ''; $max = ''; |
|
84 | 84 | |
85 | - $posindice=8; |
|
85 | + $posindice = 8; |
|
86 | 86 | $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
87 | - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; |
|
88 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
89 | - $sql.= " AND entity = ".$conf->entity; |
|
90 | - $resql=$db->query($sql); |
|
87 | + $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; |
|
88 | + $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
89 | + $sql .= " AND entity = ".$conf->entity; |
|
90 | + $resql = $db->query($sql); |
|
91 | 91 | if ($resql) |
92 | 92 | { |
93 | 93 | $row = $db->fetch_row($resql); |
94 | - if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; } |
|
94 | + if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; } |
|
95 | 95 | } |
96 | - if (! $coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm)) |
|
96 | + if (!$coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) |
|
97 | 97 | { |
98 | 98 | return true; |
99 | 99 | } |
100 | 100 | else |
101 | 101 | { |
102 | 102 | $langs->load("errors"); |
103 | - $this->error=$langs->trans('ErrorNumRefModel',$max); |
|
103 | + $this->error = $langs->trans('ErrorNumRefModel', $max); |
|
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | } |
@@ -112,32 +112,32 @@ discard block |
||
112 | 112 | * @param Object $object Object |
113 | 113 | * @return string Value if OK, 0 if KO |
114 | 114 | */ |
115 | - function getNextValue($objsoc=0,$object='') |
|
115 | + function getNextValue($objsoc = 0, $object = '') |
|
116 | 116 | { |
117 | - global $db,$conf; |
|
117 | + global $db, $conf; |
|
118 | 118 | |
119 | 119 | // D'abord on recupere la valeur max |
120 | - $posindice=8; |
|
120 | + $posindice = 8; |
|
121 | 121 | $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
122 | - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; |
|
123 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
124 | - $sql.= " AND entity = ".$conf->entity; |
|
122 | + $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; |
|
123 | + $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
124 | + $sql .= " AND entity = ".$conf->entity; |
|
125 | 125 | |
126 | - $resql=$db->query($sql); |
|
126 | + $resql = $db->query($sql); |
|
127 | 127 | if ($resql) |
128 | 128 | { |
129 | 129 | $obj = $db->fetch_object($resql); |
130 | 130 | if ($obj) $max = intval($obj->max); |
131 | - else $max=0; |
|
131 | + else $max = 0; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | //$date=time(); |
135 | - $date=$object->date_commande; // Not always defined |
|
136 | - if (empty($date)) $date=$object->date; // Creation date is order date for suppliers orders |
|
137 | - $yymm = strftime("%y%m",$date); |
|
135 | + $date = $object->date_commande; // Not always defined |
|
136 | + if (empty($date)) $date = $object->date; // Creation date is order date for suppliers orders |
|
137 | + $yymm = strftime("%y%m", $date); |
|
138 | 138 | |
139 | - if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
140 | - else $num = sprintf("%04s",$max+1); |
|
139 | + if ($max >= (pow(10, 4) - 1)) $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
140 | + else $num = sprintf("%04s", $max + 1); |
|
141 | 141 | |
142 | 142 | return $this->prefix.$yymm."-".$num; |
143 | 143 | } |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | * @param Object $object Object |
151 | 151 | * @return string Texte descripif |
152 | 152 | */ |
153 | - function commande_get_num($objsoc=0,$object='') |
|
153 | + function commande_get_num($objsoc = 0, $object = '') |
|
154 | 154 | { |
155 | - return $this->getNextValue($objsoc,$object); |
|
155 | + return $this->getNextValue($objsoc, $object); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | /** |
103 | 103 | * Return next value |
104 | 104 | * |
105 | - * @param Societe $objsoc Object third party |
|
105 | + * @param integer $objsoc Object third party |
|
106 | 106 | * @param Object $object Object |
107 | 107 | * @return string Value if OK, 0 if KO |
108 | 108 | */ |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | /** |
131 | 131 | * Renvoie la reference de commande suivante non utilisee |
132 | 132 | * |
133 | - * @param Societe $objsoc Object third party |
|
133 | + * @param integer $objsoc Object third party |
|
134 | 134 | * @param Object $object Object |
135 | 135 | * @return string Texte descripif |
136 | 136 | */ |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | var $nom = 'Orchidee'; |
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Renvoi la description du modele de numerotation |
|
42 | - * |
|
43 | - * @return string Texte descripif |
|
44 | - */ |
|
40 | + /** |
|
41 | + * Renvoi la description du modele de numerotation |
|
42 | + * |
|
43 | + * @return string Texte descripif |
|
44 | + */ |
|
45 | 45 | function info() |
46 | - { |
|
47 | - global $conf,$langs; |
|
46 | + { |
|
47 | + global $conf,$langs; |
|
48 | 48 | |
49 | 49 | $langs->load("bills"); |
50 | 50 | $langs->load("admin"); |
@@ -76,20 +76,20 @@ discard block |
||
76 | 76 | $texte.= '</form>'; |
77 | 77 | |
78 | 78 | return $texte; |
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Renvoi un exemple de numerotation |
|
83 | - * |
|
84 | - * @return string Example |
|
85 | - */ |
|
86 | - function getExample() |
|
87 | - { |
|
88 | - global $conf,$langs,$mysoc; |
|
89 | - |
|
90 | - $old_code_client=$mysoc->code_client; |
|
91 | - $mysoc->code_client='CCCCCCCCCC'; |
|
92 | - $numExample = $this->getNextValue($mysoc,''); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Renvoi un exemple de numerotation |
|
83 | + * |
|
84 | + * @return string Example |
|
85 | + */ |
|
86 | + function getExample() |
|
87 | + { |
|
88 | + global $conf,$langs,$mysoc; |
|
89 | + |
|
90 | + $old_code_client=$mysoc->code_client; |
|
91 | + $mysoc->code_client='CCCCCCCCCC'; |
|
92 | + $numExample = $this->getNextValue($mysoc,''); |
|
93 | 93 | $mysoc->code_client=$old_code_client; |
94 | 94 | |
95 | 95 | if (! $numExample) |
@@ -97,17 +97,17 @@ discard block |
||
97 | 97 | $numExample = $langs->trans('NotConfigured'); |
98 | 98 | } |
99 | 99 | return $numExample; |
100 | - } |
|
100 | + } |
|
101 | 101 | |
102 | 102 | /** |
103 | 103 | * Return next value |
104 | 104 | * |
105 | 105 | * @param Societe $objsoc Object third party |
106 | 106 | * @param Object $object Object |
107 | - * @return string Value if OK, 0 if KO |
|
108 | - */ |
|
109 | - function getNextValue($objsoc=0,$object='') |
|
110 | - { |
|
107 | + * @return string Value if OK, 0 if KO |
|
108 | + */ |
|
109 | + function getNextValue($objsoc=0,$object='') |
|
110 | + { |
|
111 | 111 | global $db,$conf; |
112 | 112 | |
113 | 113 | require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
@@ -127,16 +127,16 @@ discard block |
||
127 | 127 | } |
128 | 128 | |
129 | 129 | |
130 | - /** |
|
131 | - * Renvoie la reference de commande suivante non utilisee |
|
132 | - * |
|
130 | + /** |
|
131 | + * Renvoie la reference de commande suivante non utilisee |
|
132 | + * |
|
133 | 133 | * @param Societe $objsoc Object third party |
134 | 134 | * @param Object $object Object |
135 | - * @return string Texte descripif |
|
136 | - */ |
|
137 | - function commande_get_num($objsoc=0,$object='') |
|
138 | - { |
|
139 | - return $this->getNextValue($objsoc,$object); |
|
140 | - } |
|
135 | + * @return string Texte descripif |
|
136 | + */ |
|
137 | + function commande_get_num($objsoc=0,$object='') |
|
138 | + { |
|
139 | + return $this->getNextValue($objsoc,$object); |
|
140 | + } |
|
141 | 141 | } |
142 | 142 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * \brief Fichier contenant la classe du modele de numerotation de reference de commande fournisseur Orchidee |
25 | 25 | */ |
26 | 26 | |
27 | -require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_order/modules_commandefournisseur.php'; |
|
27 | +require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php'; |
|
28 | 28 | |
29 | 29 | |
30 | 30 | /** |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | class mod_commande_fournisseur_orchidee extends ModeleNumRefSuppliersOrders |
34 | 34 | { |
35 | - var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
35 | + var $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
36 | 36 | var $error = ''; |
37 | 37 | var $nom = 'Orchidee'; |
38 | 38 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | function info() |
46 | 46 | { |
47 | - global $conf,$langs; |
|
47 | + global $conf, $langs; |
|
48 | 48 | |
49 | 49 | $langs->load("bills"); |
50 | 50 | $langs->load("admin"); |
@@ -52,28 +52,28 @@ discard block |
||
52 | 52 | $form = new Form($this->db); |
53 | 53 | |
54 | 54 | $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n"; |
55 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
56 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
57 | - $texte.= '<input type="hidden" name="action" value="updateMask">'; |
|
58 | - $texte.= '<input type="hidden" name="maskconstorder" value="COMMANDE_FOURNISSEUR_ORCHIDEE_MASK">'; |
|
59 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
60 | - |
|
61 | - $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Order"),$langs->transnoentities("Order")); |
|
62 | - $tooltip.=$langs->trans("GenericMaskCodes2"); |
|
63 | - $tooltip.=$langs->trans("GenericMaskCodes3"); |
|
64 | - $tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Order"),$langs->transnoentities("Order")); |
|
65 | - $tooltip.=$langs->trans("GenericMaskCodes5"); |
|
55 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
56 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
57 | + $texte .= '<input type="hidden" name="action" value="updateMask">'; |
|
58 | + $texte .= '<input type="hidden" name="maskconstorder" value="COMMANDE_FOURNISSEUR_ORCHIDEE_MASK">'; |
|
59 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
60 | + |
|
61 | + $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Order"), $langs->transnoentities("Order")); |
|
62 | + $tooltip .= $langs->trans("GenericMaskCodes2"); |
|
63 | + $tooltip .= $langs->trans("GenericMaskCodes3"); |
|
64 | + $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Order"), $langs->transnoentities("Order")); |
|
65 | + $tooltip .= $langs->trans("GenericMaskCodes5"); |
|
66 | 66 | |
67 | 67 | // Parametrage du prefix |
68 | - $texte.= '<tr><td>'.$langs->trans("Mask").':</td>'; |
|
69 | - $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskorder" value="'.$conf->global->COMMANDE_FOURNISSEUR_ORCHIDEE_MASK.'">',$tooltip,1,1).'</td>'; |
|
68 | + $texte .= '<tr><td>'.$langs->trans("Mask").':</td>'; |
|
69 | + $texte .= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskorder" value="'.$conf->global->COMMANDE_FOURNISSEUR_ORCHIDEE_MASK.'">', $tooltip, 1, 1).'</td>'; |
|
70 | 70 | |
71 | - $texte.= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>'; |
|
71 | + $texte .= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>'; |
|
72 | 72 | |
73 | - $texte.= '</tr>'; |
|
73 | + $texte .= '</tr>'; |
|
74 | 74 | |
75 | - $texte.= '</table>'; |
|
76 | - $texte.= '</form>'; |
|
75 | + $texte .= '</table>'; |
|
76 | + $texte .= '</form>'; |
|
77 | 77 | |
78 | 78 | return $texte; |
79 | 79 | } |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | */ |
86 | 86 | function getExample() |
87 | 87 | { |
88 | - global $conf,$langs,$mysoc; |
|
88 | + global $conf, $langs, $mysoc; |
|
89 | 89 | |
90 | - $old_code_client=$mysoc->code_client; |
|
91 | - $mysoc->code_client='CCCCCCCCCC'; |
|
92 | - $numExample = $this->getNextValue($mysoc,''); |
|
93 | - $mysoc->code_client=$old_code_client; |
|
90 | + $old_code_client = $mysoc->code_client; |
|
91 | + $mysoc->code_client = 'CCCCCCCCCC'; |
|
92 | + $numExample = $this->getNextValue($mysoc, ''); |
|
93 | + $mysoc->code_client = $old_code_client; |
|
94 | 94 | |
95 | - if (! $numExample) |
|
95 | + if (!$numExample) |
|
96 | 96 | { |
97 | 97 | $numExample = $langs->trans('NotConfigured'); |
98 | 98 | } |
@@ -106,22 +106,22 @@ discard block |
||
106 | 106 | * @param Object $object Object |
107 | 107 | * @return string Value if OK, 0 if KO |
108 | 108 | */ |
109 | - function getNextValue($objsoc=0,$object='') |
|
109 | + function getNextValue($objsoc = 0, $object = '') |
|
110 | 110 | { |
111 | - global $db,$conf; |
|
111 | + global $db, $conf; |
|
112 | 112 | |
113 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
113 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
114 | 114 | |
115 | 115 | // On defini critere recherche compteur |
116 | - $mask=$conf->global->COMMANDE_FOURNISSEUR_ORCHIDEE_MASK; |
|
116 | + $mask = $conf->global->COMMANDE_FOURNISSEUR_ORCHIDEE_MASK; |
|
117 | 117 | |
118 | - if (! $mask) |
|
118 | + if (!$mask) |
|
119 | 119 | { |
120 | - $this->error='NotConfigured'; |
|
120 | + $this->error = 'NotConfigured'; |
|
121 | 121 | return 0; |
122 | 122 | } |
123 | 123 | |
124 | - $numFinal=get_next_value($db,$mask,'commande_fournisseur','ref','',$objsoc,$object->date_commande); |
|
124 | + $numFinal = get_next_value($db, $mask, 'commande_fournisseur', 'ref', '', $objsoc, $object->date_commande); |
|
125 | 125 | |
126 | 126 | return $numFinal; |
127 | 127 | } |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | * @param Object $object Object |
135 | 135 | * @return string Texte descripif |
136 | 136 | */ |
137 | - function commande_get_num($objsoc=0,$object='') |
|
137 | + function commande_get_num($objsoc = 0, $object = '') |
|
138 | 138 | { |
139 | - return $this->getNextValue($objsoc,$object); |
|
139 | + return $this->getNextValue($objsoc, $object); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 |
@@ -226,7 +226,7 @@ |
||
226 | 226 | /** |
227 | 227 | * Update database |
228 | 228 | * |
229 | - * @param User $user User that modify |
|
229 | + * @param integer $user User that modify |
|
230 | 230 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
231 | 231 | * @return int <0 if KO, >0 if OK |
232 | 232 | */ |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | var $datec=''; |
38 | 38 | var $tms=''; |
39 | 39 | var $datep=''; |
40 | - var $amounts=array(); // Array of amounts |
|
41 | - var $amount_capital; // Total amount of payment |
|
40 | + var $amounts=array(); // Array of amounts |
|
41 | + var $amount_capital; // Total amount of payment |
|
42 | 42 | var $amount_insurance; |
43 | 43 | var $amount_interest; |
44 | 44 | var $fk_typepayment; |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Create payment of loan into database. |
68 | - * Use this->amounts to have list of lines for the payment |
|
69 | - * |
|
68 | + * Use this->amounts to have list of lines for the payment |
|
69 | + * |
|
70 | 70 | * @param User $user User making payment |
71 | 71 | * @return int <0 if KO, id of payment if OK |
72 | 72 | */ |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | |
77 | 77 | $error=0; |
78 | 78 | |
79 | - $now=dol_now(); |
|
79 | + $now=dol_now(); |
|
80 | 80 | |
81 | - // Validate parameters |
|
81 | + // Validate parameters |
|
82 | 82 | if (! $this->datepaid) |
83 | 83 | { |
84 | 84 | $this->error='ErrorBadValueForParameter'; |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat); |
99 | 99 | if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif); |
100 | 100 | |
101 | - $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest; |
|
102 | - $totalamount = price2num($totalamount); |
|
101 | + $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest; |
|
102 | + $totalamount = price2num($totalamount); |
|
103 | 103 | |
104 | - // Check parameters |
|
105 | - if ($totalamount == 0) return -1; // Negative amounts are accepted for reject prelevement but not null |
|
104 | + // Check parameters |
|
105 | + if ($totalamount == 0) return -1; // Negative amounts are accepted for reject prelevement but not null |
|
106 | 106 | |
107 | 107 | |
108 | 108 | $this->db->begin(); |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | } |
128 | 128 | else |
129 | 129 | { |
130 | - $this->error=$this->db->lasterror(); |
|
130 | + $this->error=$this->db->lasterror(); |
|
131 | 131 | $error++; |
132 | 132 | } |
133 | 133 | |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | |
136 | 136 | if ($totalamount != 0 && ! $error) |
137 | 137 | { |
138 | - $this->amount_capital=$totalamount; |
|
139 | - $this->total=$totalamount; // deprecated |
|
140 | - $this->db->commit(); |
|
138 | + $this->amount_capital=$totalamount; |
|
139 | + $this->total=$totalamount; // deprecated |
|
140 | + $this->db->commit(); |
|
141 | 141 | return $this->id; |
142 | 142 | } |
143 | 143 | else |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | $sql.= " t.amount_interest,"; |
169 | 169 | $sql.= " t.fk_typepayment,"; |
170 | 170 | $sql.= " t.num_payment,"; |
171 | - $sql.= " t.note_private,"; |
|
172 | - $sql.= " t.note_public,"; |
|
171 | + $sql.= " t.note_private,"; |
|
172 | + $sql.= " t.note_public,"; |
|
173 | 173 | $sql.= " t.fk_bank,"; |
174 | 174 | $sql.= " t.fk_user_creat,"; |
175 | 175 | $sql.= " t.fk_user_modif,"; |
@@ -326,15 +326,15 @@ discard block |
||
326 | 326 | |
327 | 327 | $this->db->begin(); |
328 | 328 | |
329 | - if (! $error) |
|
330 | - { |
|
331 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; |
|
332 | - $sql.= " WHERE type='payment_loan' AND url_id=".$this->id; |
|
329 | + if (! $error) |
|
330 | + { |
|
331 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; |
|
332 | + $sql.= " WHERE type='payment_loan' AND url_id=".$this->id; |
|
333 | 333 | |
334 | - dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
335 | - $resql = $this->db->query($sql); |
|
336 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
337 | - } |
|
334 | + dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
335 | + $resql = $this->db->query($sql); |
|
336 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
337 | + } |
|
338 | 338 | |
339 | 339 | if (! $error) |
340 | 340 | { |
@@ -380,95 +380,95 @@ discard block |
||
380 | 380 | } |
381 | 381 | } |
382 | 382 | |
383 | - /** |
|
384 | - * Add record into bank for payment with links between this bank record and invoices of payment. |
|
385 | - * All payment properties must have been set first like after a call to create(). |
|
386 | - * |
|
387 | - * @param User $user Object of user making payment |
|
388 | - * @param int $fk_loan Id of fk_loan to do link with this payment |
|
389 | - * @param string $mode 'payment_loan' |
|
390 | - * @param string $label Label to use in bank record |
|
391 | - * @param int $accountid Id of bank account to do link with |
|
392 | - * @param string $emetteur_nom Name of transmitter |
|
393 | - * @param string $emetteur_banque Name of bank |
|
394 | - * @return int <0 if KO, >0 if OK |
|
395 | - */ |
|
396 | - function addPaymentToBank($user, $fk_loan, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque) |
|
397 | - { |
|
398 | - global $conf; |
|
399 | - |
|
400 | - $error=0; |
|
401 | - |
|
402 | - if (! empty($conf->banque->enabled)) |
|
403 | - { |
|
404 | - require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; |
|
405 | - |
|
406 | - $acc = new Account($this->db); |
|
407 | - $acc->fetch($accountid); |
|
408 | - |
|
409 | - $total=$this->total; |
|
410 | - if ($mode == 'payment_loan') $total=-$total; |
|
411 | - |
|
412 | - // Insert payment into llx_bank |
|
413 | - $bank_line_id = $acc->addline( |
|
414 | - $this->datepaid, |
|
415 | - $this->paymenttype, // Payment mode id or code ("CHQ or VIR for example") |
|
416 | - $label, |
|
417 | - $total, |
|
418 | - $this->num_payment, |
|
419 | - '', |
|
420 | - $user, |
|
421 | - $emetteur_nom, |
|
422 | - $emetteur_banque |
|
423 | - ); |
|
424 | - |
|
425 | - // Update fk_bank into llx_paiement. |
|
426 | - // We know the payment who generated the account write |
|
427 | - if ($bank_line_id > 0) |
|
428 | - { |
|
429 | - $result=$this->update_fk_bank($bank_line_id); |
|
430 | - if ($result <= 0) |
|
431 | - { |
|
432 | - $error++; |
|
433 | - dol_print_error($this->db); |
|
434 | - } |
|
435 | - |
|
436 | - // Add link 'payment_loan' in bank_url between payment and bank transaction |
|
437 | - $url=''; |
|
438 | - if ($mode == 'payment_loan') $url=DOL_URL_ROOT.'/loan/payment/card.php?id='; |
|
439 | - if ($url) |
|
440 | - { |
|
441 | - $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $mode); |
|
442 | - if ($result <= 0) |
|
443 | - { |
|
444 | - $error++; |
|
445 | - dol_print_error($this->db); |
|
446 | - } |
|
447 | - } |
|
448 | - |
|
449 | - // Add link 'loan' in bank_url between invoice and bank transaction (for each invoice concerned by payment) |
|
450 | - if ($mode == 'payment_loan') |
|
451 | - { |
|
452 | - $result=$acc->add_url_line($bank_line_id, $fk_loan, DOL_URL_ROOT.'/loan/card.php?id=', ($this->label?$this->label:''),'loan'); |
|
453 | - if ($result <= 0) dol_print_error($this->db); |
|
454 | - } |
|
455 | - } |
|
456 | - else |
|
457 | - { |
|
458 | - $this->error=$acc->error; |
|
459 | - $error++; |
|
460 | - } |
|
461 | - } |
|
462 | - |
|
463 | - if (! $error) |
|
464 | - { |
|
465 | - return 1; |
|
466 | - } |
|
467 | - else |
|
468 | - { |
|
469 | - return -1; |
|
470 | - } |
|
471 | - } |
|
383 | + /** |
|
384 | + * Add record into bank for payment with links between this bank record and invoices of payment. |
|
385 | + * All payment properties must have been set first like after a call to create(). |
|
386 | + * |
|
387 | + * @param User $user Object of user making payment |
|
388 | + * @param int $fk_loan Id of fk_loan to do link with this payment |
|
389 | + * @param string $mode 'payment_loan' |
|
390 | + * @param string $label Label to use in bank record |
|
391 | + * @param int $accountid Id of bank account to do link with |
|
392 | + * @param string $emetteur_nom Name of transmitter |
|
393 | + * @param string $emetteur_banque Name of bank |
|
394 | + * @return int <0 if KO, >0 if OK |
|
395 | + */ |
|
396 | + function addPaymentToBank($user, $fk_loan, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque) |
|
397 | + { |
|
398 | + global $conf; |
|
399 | + |
|
400 | + $error=0; |
|
401 | + |
|
402 | + if (! empty($conf->banque->enabled)) |
|
403 | + { |
|
404 | + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; |
|
405 | + |
|
406 | + $acc = new Account($this->db); |
|
407 | + $acc->fetch($accountid); |
|
408 | + |
|
409 | + $total=$this->total; |
|
410 | + if ($mode == 'payment_loan') $total=-$total; |
|
411 | + |
|
412 | + // Insert payment into llx_bank |
|
413 | + $bank_line_id = $acc->addline( |
|
414 | + $this->datepaid, |
|
415 | + $this->paymenttype, // Payment mode id or code ("CHQ or VIR for example") |
|
416 | + $label, |
|
417 | + $total, |
|
418 | + $this->num_payment, |
|
419 | + '', |
|
420 | + $user, |
|
421 | + $emetteur_nom, |
|
422 | + $emetteur_banque |
|
423 | + ); |
|
424 | + |
|
425 | + // Update fk_bank into llx_paiement. |
|
426 | + // We know the payment who generated the account write |
|
427 | + if ($bank_line_id > 0) |
|
428 | + { |
|
429 | + $result=$this->update_fk_bank($bank_line_id); |
|
430 | + if ($result <= 0) |
|
431 | + { |
|
432 | + $error++; |
|
433 | + dol_print_error($this->db); |
|
434 | + } |
|
435 | + |
|
436 | + // Add link 'payment_loan' in bank_url between payment and bank transaction |
|
437 | + $url=''; |
|
438 | + if ($mode == 'payment_loan') $url=DOL_URL_ROOT.'/loan/payment/card.php?id='; |
|
439 | + if ($url) |
|
440 | + { |
|
441 | + $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $mode); |
|
442 | + if ($result <= 0) |
|
443 | + { |
|
444 | + $error++; |
|
445 | + dol_print_error($this->db); |
|
446 | + } |
|
447 | + } |
|
448 | + |
|
449 | + // Add link 'loan' in bank_url between invoice and bank transaction (for each invoice concerned by payment) |
|
450 | + if ($mode == 'payment_loan') |
|
451 | + { |
|
452 | + $result=$acc->add_url_line($bank_line_id, $fk_loan, DOL_URL_ROOT.'/loan/card.php?id=', ($this->label?$this->label:''),'loan'); |
|
453 | + if ($result <= 0) dol_print_error($this->db); |
|
454 | + } |
|
455 | + } |
|
456 | + else |
|
457 | + { |
|
458 | + $this->error=$acc->error; |
|
459 | + $error++; |
|
460 | + } |
|
461 | + } |
|
462 | + |
|
463 | + if (! $error) |
|
464 | + { |
|
465 | + return 1; |
|
466 | + } |
|
467 | + else |
|
468 | + { |
|
469 | + return -1; |
|
470 | + } |
|
471 | + } |
|
472 | 472 | |
473 | 473 | |
474 | 474 | /** |
@@ -86,23 +86,48 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clean parameters |
89 | - if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan); |
|
90 | - if (isset($this->amount_capital)) $this->amount_capital = price2num($this->amount_capital?$this->amount_capital:0); |
|
91 | - if (isset($this->amount_insurance)) $this->amount_insurance = price2num($this->amount_insurance?$this->amount_insurance:0); |
|
92 | - if (isset($this->amount_interest)) $this->amount_interest = price2num($this->amount_interest?$this->amount_interest:0); |
|
93 | - if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); |
|
94 | - if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); |
|
95 | - if (isset($this->note_private)) $this->note_private = trim($this->note_private); |
|
96 | - if (isset($this->note_public)) $this->note_public = trim($this->note_public); |
|
97 | - if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank); |
|
98 | - if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat); |
|
99 | - if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif); |
|
89 | + if (isset($this->fk_loan)) { |
|
90 | + $this->fk_loan = trim($this->fk_loan); |
|
91 | + } |
|
92 | + if (isset($this->amount_capital)) { |
|
93 | + $this->amount_capital = price2num($this->amount_capital?$this->amount_capital:0); |
|
94 | + } |
|
95 | + if (isset($this->amount_insurance)) { |
|
96 | + $this->amount_insurance = price2num($this->amount_insurance?$this->amount_insurance:0); |
|
97 | + } |
|
98 | + if (isset($this->amount_interest)) { |
|
99 | + $this->amount_interest = price2num($this->amount_interest?$this->amount_interest:0); |
|
100 | + } |
|
101 | + if (isset($this->fk_typepayment)) { |
|
102 | + $this->fk_typepayment = trim($this->fk_typepayment); |
|
103 | + } |
|
104 | + if (isset($this->num_payment)) { |
|
105 | + $this->num_payment = trim($this->num_payment); |
|
106 | + } |
|
107 | + if (isset($this->note_private)) { |
|
108 | + $this->note_private = trim($this->note_private); |
|
109 | + } |
|
110 | + if (isset($this->note_public)) { |
|
111 | + $this->note_public = trim($this->note_public); |
|
112 | + } |
|
113 | + if (isset($this->fk_bank)) { |
|
114 | + $this->fk_bank = trim($this->fk_bank); |
|
115 | + } |
|
116 | + if (isset($this->fk_user_creat)) { |
|
117 | + $this->fk_user_creat = trim($this->fk_user_creat); |
|
118 | + } |
|
119 | + if (isset($this->fk_user_modif)) { |
|
120 | + $this->fk_user_modif = trim($this->fk_user_modif); |
|
121 | + } |
|
100 | 122 | |
101 | 123 | $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest; |
102 | 124 | $totalamount = price2num($totalamount); |
103 | 125 | |
104 | 126 | // Check parameters |
105 | - if ($totalamount == 0) return -1; // Negative amounts are accepted for reject prelevement but not null |
|
127 | + if ($totalamount == 0) { |
|
128 | + return -1; |
|
129 | + } |
|
130 | + // Negative amounts are accepted for reject prelevement but not null |
|
106 | 131 | |
107 | 132 | |
108 | 133 | $this->db->begin(); |
@@ -124,8 +149,7 @@ discard block |
||
124 | 149 | if ($resql) |
125 | 150 | { |
126 | 151 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_loan"); |
127 | - } |
|
128 | - else |
|
152 | + } else |
|
129 | 153 | { |
130 | 154 | $this->error=$this->db->lasterror(); |
131 | 155 | $error++; |
@@ -139,8 +163,7 @@ discard block |
||
139 | 163 | $this->total=$totalamount; // deprecated |
140 | 164 | $this->db->commit(); |
141 | 165 | return $this->id; |
142 | - } |
|
143 | - else |
|
166 | + } else |
|
144 | 167 | { |
145 | 168 | $this->error=$this->db->lasterror(); |
146 | 169 | $this->db->rollback(); |
@@ -214,8 +237,7 @@ discard block |
||
214 | 237 | $this->db->free($resql); |
215 | 238 | |
216 | 239 | return 1; |
217 | - } |
|
218 | - else |
|
240 | + } else |
|
219 | 241 | { |
220 | 242 | $this->error="Error ".$this->db->lasterror(); |
221 | 243 | return -1; |
@@ -236,17 +258,39 @@ discard block |
||
236 | 258 | $error=0; |
237 | 259 | |
238 | 260 | // Clean parameters |
239 | - if (isset($this->fk_loan)) $this->fk_loan=trim($this->fk_loan); |
|
240 | - if (isset($this->amount_capital)) $this->amount_capital=trim($this->amount_capital); |
|
241 | - if (isset($this->amount_insurance)) $this->amount_insurance=trim($this->amount_insurance); |
|
242 | - if (isset($this->amount_interest)) $this->amount_interest=trim($this->amount_interest); |
|
243 | - if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); |
|
244 | - if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); |
|
245 | - if (isset($this->note_private)) $this->note=trim($this->note_private); |
|
246 | - if (isset($this->note_public)) $this->note=trim($this->note_public); |
|
247 | - if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); |
|
248 | - if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); |
|
249 | - if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); |
|
261 | + if (isset($this->fk_loan)) { |
|
262 | + $this->fk_loan=trim($this->fk_loan); |
|
263 | + } |
|
264 | + if (isset($this->amount_capital)) { |
|
265 | + $this->amount_capital=trim($this->amount_capital); |
|
266 | + } |
|
267 | + if (isset($this->amount_insurance)) { |
|
268 | + $this->amount_insurance=trim($this->amount_insurance); |
|
269 | + } |
|
270 | + if (isset($this->amount_interest)) { |
|
271 | + $this->amount_interest=trim($this->amount_interest); |
|
272 | + } |
|
273 | + if (isset($this->fk_typepayment)) { |
|
274 | + $this->fk_typepayment=trim($this->fk_typepayment); |
|
275 | + } |
|
276 | + if (isset($this->num_payment)) { |
|
277 | + $this->num_payment=trim($this->num_payment); |
|
278 | + } |
|
279 | + if (isset($this->note_private)) { |
|
280 | + $this->note=trim($this->note_private); |
|
281 | + } |
|
282 | + if (isset($this->note_public)) { |
|
283 | + $this->note=trim($this->note_public); |
|
284 | + } |
|
285 | + if (isset($this->fk_bank)) { |
|
286 | + $this->fk_bank=trim($this->fk_bank); |
|
287 | + } |
|
288 | + if (isset($this->fk_user_creat)) { |
|
289 | + $this->fk_user_creat=trim($this->fk_user_creat); |
|
290 | + } |
|
291 | + if (isset($this->fk_user_modif)) { |
|
292 | + $this->fk_user_modif=trim($this->fk_user_modif); |
|
293 | + } |
|
250 | 294 | |
251 | 295 | // Check parameters |
252 | 296 | // Put here code to add control on parameters values |
@@ -303,8 +347,7 @@ discard block |
||
303 | 347 | } |
304 | 348 | $this->db->rollback(); |
305 | 349 | return -1*$error; |
306 | - } |
|
307 | - else |
|
350 | + } else |
|
308 | 351 | { |
309 | 352 | $this->db->commit(); |
310 | 353 | return 1; |
@@ -372,8 +415,7 @@ discard block |
||
372 | 415 | } |
373 | 416 | $this->db->rollback(); |
374 | 417 | return -1*$error; |
375 | - } |
|
376 | - else |
|
418 | + } else |
|
377 | 419 | { |
378 | 420 | $this->db->commit(); |
379 | 421 | return 1; |
@@ -407,7 +449,9 @@ discard block |
||
407 | 449 | $acc->fetch($accountid); |
408 | 450 | |
409 | 451 | $total=$this->total; |
410 | - if ($mode == 'payment_loan') $total=-$total; |
|
452 | + if ($mode == 'payment_loan') { |
|
453 | + $total=-$total; |
|
454 | + } |
|
411 | 455 | |
412 | 456 | // Insert payment into llx_bank |
413 | 457 | $bank_line_id = $acc->addline( |
@@ -435,7 +479,9 @@ discard block |
||
435 | 479 | |
436 | 480 | // Add link 'payment_loan' in bank_url between payment and bank transaction |
437 | 481 | $url=''; |
438 | - if ($mode == 'payment_loan') $url=DOL_URL_ROOT.'/loan/payment/card.php?id='; |
|
482 | + if ($mode == 'payment_loan') { |
|
483 | + $url=DOL_URL_ROOT.'/loan/payment/card.php?id='; |
|
484 | + } |
|
439 | 485 | if ($url) |
440 | 486 | { |
441 | 487 | $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $mode); |
@@ -450,10 +496,11 @@ discard block |
||
450 | 496 | if ($mode == 'payment_loan') |
451 | 497 | { |
452 | 498 | $result=$acc->add_url_line($bank_line_id, $fk_loan, DOL_URL_ROOT.'/loan/card.php?id=', ($this->label?$this->label:''),'loan'); |
453 | - if ($result <= 0) dol_print_error($this->db); |
|
499 | + if ($result <= 0) { |
|
500 | + dol_print_error($this->db); |
|
501 | + } |
|
454 | 502 | } |
455 | - } |
|
456 | - else |
|
503 | + } else |
|
457 | 504 | { |
458 | 505 | $this->error=$acc->error; |
459 | 506 | $error++; |
@@ -463,8 +510,7 @@ discard block |
||
463 | 510 | if (! $error) |
464 | 511 | { |
465 | 512 | return 1; |
466 | - } |
|
467 | - else |
|
513 | + } else |
|
468 | 514 | { |
469 | 515 | return -1; |
470 | 516 | } |
@@ -486,8 +532,7 @@ discard block |
||
486 | 532 | if ($result) |
487 | 533 | { |
488 | 534 | return 1; |
489 | - } |
|
490 | - else |
|
535 | + } else |
|
491 | 536 | { |
492 | 537 | $this->error=$this->db->error(); |
493 | 538 | return 0; |
@@ -507,16 +552,24 @@ discard block |
||
507 | 552 | |
508 | 553 | $result=''; |
509 | 554 | |
510 | - if (empty($this->ref)) $this->ref=$this->lib; |
|
555 | + if (empty($this->ref)) { |
|
556 | + $this->ref=$this->lib; |
|
557 | + } |
|
511 | 558 | |
512 | 559 | if (!empty($this->id)) |
513 | 560 | { |
514 | 561 | $link = '<a href="'.DOL_URL_ROOT.'/compta/payment/card.php?id='.$this->id.'">'; |
515 | 562 | $linkend='</a>'; |
516 | 563 | |
517 | - if ($withpicto) $result.=($link.img_object($langs->trans("ShowPayment").': '.$this->ref,'payment').$linkend.' '); |
|
518 | - if ($withpicto && $withpicto != 2) $result.=' '; |
|
519 | - if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend; |
|
564 | + if ($withpicto) { |
|
565 | + $result.=($link.img_object($langs->trans("ShowPayment").': '.$this->ref,'payment').$linkend.' '); |
|
566 | + } |
|
567 | + if ($withpicto && $withpicto != 2) { |
|
568 | + $result.=' '; |
|
569 | + } |
|
570 | + if ($withpicto != 2) { |
|
571 | + $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend; |
|
572 | + } |
|
520 | 573 | } |
521 | 574 | |
522 | 575 | return $result; |
@@ -30,15 +30,15 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class PaymentLoan extends CommonObject |
32 | 32 | { |
33 | - public $element='payment_loan'; //!< Id that identify managed objects |
|
34 | - public $table_element='payment_loan'; //!< Name of table without prefix where object is stored |
|
33 | + public $element = 'payment_loan'; //!< Id that identify managed objects |
|
34 | + public $table_element = 'payment_loan'; //!< Name of table without prefix where object is stored |
|
35 | 35 | |
36 | 36 | var $fk_loan; |
37 | - var $datec=''; |
|
38 | - var $tms=''; |
|
39 | - var $datep=''; |
|
40 | - var $amounts=array(); // Array of amounts |
|
41 | - var $amount_capital; // Total amount of payment |
|
37 | + var $datec = ''; |
|
38 | + var $tms = ''; |
|
39 | + var $datep = ''; |
|
40 | + var $amounts = array(); // Array of amounts |
|
41 | + var $amount_capital; // Total amount of payment |
|
42 | 42 | var $amount_insurance; |
43 | 43 | var $amount_interest; |
44 | 44 | var $fk_typepayment; |
@@ -74,22 +74,22 @@ discard block |
||
74 | 74 | { |
75 | 75 | global $conf, $langs; |
76 | 76 | |
77 | - $error=0; |
|
77 | + $error = 0; |
|
78 | 78 | |
79 | - $now=dol_now(); |
|
79 | + $now = dol_now(); |
|
80 | 80 | |
81 | 81 | // Validate parameters |
82 | - if (! $this->datepaid) |
|
82 | + if (!$this->datepaid) |
|
83 | 83 | { |
84 | - $this->error='ErrorBadValueForParameter'; |
|
84 | + $this->error = 'ErrorBadValueForParameter'; |
|
85 | 85 | return -1; |
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clean parameters |
89 | 89 | if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan); |
90 | - if (isset($this->amount_capital)) $this->amount_capital = price2num($this->amount_capital?$this->amount_capital:0); |
|
91 | - if (isset($this->amount_insurance)) $this->amount_insurance = price2num($this->amount_insurance?$this->amount_insurance:0); |
|
92 | - if (isset($this->amount_interest)) $this->amount_interest = price2num($this->amount_interest?$this->amount_interest:0); |
|
90 | + if (isset($this->amount_capital)) $this->amount_capital = price2num($this->amount_capital ? $this->amount_capital : 0); |
|
91 | + if (isset($this->amount_insurance)) $this->amount_insurance = price2num($this->amount_insurance ? $this->amount_insurance : 0); |
|
92 | + if (isset($this->amount_interest)) $this->amount_interest = price2num($this->amount_interest ? $this->amount_interest : 0); |
|
93 | 93 | if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); |
94 | 94 | if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); |
95 | 95 | if (isset($this->note_private)) $this->note_private = trim($this->note_private); |
@@ -110,39 +110,39 @@ discard block |
||
110 | 110 | if ($totalamount != 0) |
111 | 111 | { |
112 | 112 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_loan (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,"; |
113 | - $sql.= " fk_typepayment, num_payment, note_private, note_public, fk_user_creat, fk_bank)"; |
|
114 | - $sql.= " VALUES (".$this->chid.", '".$this->db->idate($now)."',"; |
|
115 | - $sql.= " '".$this->db->idate($this->datepaid)."',"; |
|
116 | - $sql.= " ".$this->amount_capital.","; |
|
117 | - $sql.= " ".$this->amount_insurance.","; |
|
118 | - $sql.= " ".$this->amount_interest.","; |
|
119 | - $sql.= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_private)."', '".$this->db->escape($this->note_public)."', ".$user->id.","; |
|
120 | - $sql.= " 0)"; |
|
113 | + $sql .= " fk_typepayment, num_payment, note_private, note_public, fk_user_creat, fk_bank)"; |
|
114 | + $sql .= " VALUES (".$this->chid.", '".$this->db->idate($now)."',"; |
|
115 | + $sql .= " '".$this->db->idate($this->datepaid)."',"; |
|
116 | + $sql .= " ".$this->amount_capital.","; |
|
117 | + $sql .= " ".$this->amount_insurance.","; |
|
118 | + $sql .= " ".$this->amount_interest.","; |
|
119 | + $sql .= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_private)."', '".$this->db->escape($this->note_public)."', ".$user->id.","; |
|
120 | + $sql .= " 0)"; |
|
121 | 121 | |
122 | 122 | dol_syslog(get_class($this)."::create", LOG_DEBUG); |
123 | - $resql=$this->db->query($sql); |
|
123 | + $resql = $this->db->query($sql); |
|
124 | 124 | if ($resql) |
125 | 125 | { |
126 | 126 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_loan"); |
127 | 127 | } |
128 | 128 | else |
129 | 129 | { |
130 | - $this->error=$this->db->lasterror(); |
|
130 | + $this->error = $this->db->lasterror(); |
|
131 | 131 | $error++; |
132 | 132 | } |
133 | 133 | |
134 | 134 | } |
135 | 135 | |
136 | - if ($totalamount != 0 && ! $error) |
|
136 | + if ($totalamount != 0 && !$error) |
|
137 | 137 | { |
138 | - $this->amount_capital=$totalamount; |
|
139 | - $this->total=$totalamount; // deprecated |
|
138 | + $this->amount_capital = $totalamount; |
|
139 | + $this->total = $totalamount; // deprecated |
|
140 | 140 | $this->db->commit(); |
141 | 141 | return $this->id; |
142 | 142 | } |
143 | 143 | else |
144 | 144 | { |
145 | - $this->error=$this->db->lasterror(); |
|
145 | + $this->error = $this->db->lasterror(); |
|
146 | 146 | $this->db->rollback(); |
147 | 147 | return -1; |
148 | 148 | } |
@@ -158,30 +158,30 @@ discard block |
||
158 | 158 | { |
159 | 159 | global $langs; |
160 | 160 | $sql = "SELECT"; |
161 | - $sql.= " t.rowid,"; |
|
162 | - $sql.= " t.fk_loan,"; |
|
163 | - $sql.= " t.datec,"; |
|
164 | - $sql.= " t.tms,"; |
|
165 | - $sql.= " t.datep,"; |
|
166 | - $sql.= " t.amount_capital,"; |
|
167 | - $sql.= " t.amount_insurance,"; |
|
168 | - $sql.= " t.amount_interest,"; |
|
169 | - $sql.= " t.fk_typepayment,"; |
|
170 | - $sql.= " t.num_payment,"; |
|
171 | - $sql.= " t.note_private,"; |
|
172 | - $sql.= " t.note_public,"; |
|
173 | - $sql.= " t.fk_bank,"; |
|
174 | - $sql.= " t.fk_user_creat,"; |
|
175 | - $sql.= " t.fk_user_modif,"; |
|
176 | - $sql.= " pt.code as type_code, pt.libelle as type_libelle,"; |
|
177 | - $sql.= ' b.fk_account'; |
|
178 | - $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as t"; |
|
179 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id AND pt.entity IN (".getEntity('c_paiement').")"; |
|
180 | - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; |
|
181 | - $sql.= " WHERE t.rowid = ".$id; |
|
161 | + $sql .= " t.rowid,"; |
|
162 | + $sql .= " t.fk_loan,"; |
|
163 | + $sql .= " t.datec,"; |
|
164 | + $sql .= " t.tms,"; |
|
165 | + $sql .= " t.datep,"; |
|
166 | + $sql .= " t.amount_capital,"; |
|
167 | + $sql .= " t.amount_insurance,"; |
|
168 | + $sql .= " t.amount_interest,"; |
|
169 | + $sql .= " t.fk_typepayment,"; |
|
170 | + $sql .= " t.num_payment,"; |
|
171 | + $sql .= " t.note_private,"; |
|
172 | + $sql .= " t.note_public,"; |
|
173 | + $sql .= " t.fk_bank,"; |
|
174 | + $sql .= " t.fk_user_creat,"; |
|
175 | + $sql .= " t.fk_user_modif,"; |
|
176 | + $sql .= " pt.code as type_code, pt.libelle as type_libelle,"; |
|
177 | + $sql .= ' b.fk_account'; |
|
178 | + $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as t"; |
|
179 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id AND pt.entity IN (".getEntity('c_paiement').")"; |
|
180 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; |
|
181 | + $sql .= " WHERE t.rowid = ".$id; |
|
182 | 182 | |
183 | 183 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
184 | - $resql=$this->db->query($sql); |
|
184 | + $resql = $this->db->query($sql); |
|
185 | 185 | if ($resql) |
186 | 186 | { |
187 | 187 | if ($this->db->num_rows($resql)) |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | } |
219 | 219 | else |
220 | 220 | { |
221 | - $this->error="Error ".$this->db->lasterror(); |
|
221 | + $this->error = "Error ".$this->db->lasterror(); |
|
222 | 222 | return -1; |
223 | 223 | } |
224 | 224 | } |
@@ -231,23 +231,23 @@ discard block |
||
231 | 231 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
232 | 232 | * @return int <0 if KO, >0 if OK |
233 | 233 | */ |
234 | - function update($user=0, $notrigger=0) |
|
234 | + function update($user = 0, $notrigger = 0) |
|
235 | 235 | { |
236 | 236 | global $conf, $langs; |
237 | - $error=0; |
|
237 | + $error = 0; |
|
238 | 238 | |
239 | 239 | // Clean parameters |
240 | - if (isset($this->fk_loan)) $this->fk_loan=trim($this->fk_loan); |
|
241 | - if (isset($this->amount_capital)) $this->amount_capital=trim($this->amount_capital); |
|
242 | - if (isset($this->amount_insurance)) $this->amount_insurance=trim($this->amount_insurance); |
|
243 | - if (isset($this->amount_interest)) $this->amount_interest=trim($this->amount_interest); |
|
244 | - if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); |
|
245 | - if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); |
|
246 | - if (isset($this->note_private)) $this->note=trim($this->note_private); |
|
247 | - if (isset($this->note_public)) $this->note=trim($this->note_public); |
|
248 | - if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank); |
|
249 | - if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat); |
|
250 | - if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif); |
|
240 | + if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan); |
|
241 | + if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital); |
|
242 | + if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance); |
|
243 | + if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest); |
|
244 | + if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); |
|
245 | + if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); |
|
246 | + if (isset($this->note_private)) $this->note = trim($this->note_private); |
|
247 | + if (isset($this->note_public)) $this->note = trim($this->note_public); |
|
248 | + if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank); |
|
249 | + if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat); |
|
250 | + if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif); |
|
251 | 251 | |
252 | 252 | // Check parameters |
253 | 253 | // Put here code to add control on parameters values |
@@ -255,32 +255,32 @@ discard block |
||
255 | 255 | // Update request |
256 | 256 | $sql = "UPDATE ".MAIN_DB_PREFIX."payment_loan SET"; |
257 | 257 | |
258 | - $sql.= " fk_loan=".(isset($this->fk_loan)?$this->fk_loan:"null").","; |
|
259 | - $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; |
|
260 | - $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; |
|
261 | - $sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; |
|
262 | - $sql.= " amount_capital=".(isset($this->amount_capital)?$this->amount_capital:"null").","; |
|
263 | - $sql.= " amount_insurance=".(isset($this->amount_insurance)?$this->amount_insurance:"null").","; |
|
264 | - $sql.= " amount_interest=".(isset($this->amount_interest)?$this->amount_interest:"null").","; |
|
265 | - $sql.= " fk_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").","; |
|
266 | - $sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").","; |
|
267 | - $sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").","; |
|
268 | - $sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").","; |
|
269 | - $sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").","; |
|
270 | - $sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").","; |
|
271 | - $sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null").""; |
|
272 | - |
|
273 | - $sql.= " WHERE rowid=".$this->id; |
|
258 | + $sql .= " fk_loan=".(isset($this->fk_loan) ? $this->fk_loan : "null").","; |
|
259 | + $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; |
|
260 | + $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; |
|
261 | + $sql .= " datep=".(dol_strlen($this->datep) != 0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; |
|
262 | + $sql .= " amount_capital=".(isset($this->amount_capital) ? $this->amount_capital : "null").","; |
|
263 | + $sql .= " amount_insurance=".(isset($this->amount_insurance) ? $this->amount_insurance : "null").","; |
|
264 | + $sql .= " amount_interest=".(isset($this->amount_interest) ? $this->amount_interest : "null").","; |
|
265 | + $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment : "null").","; |
|
266 | + $sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").","; |
|
267 | + $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; |
|
268 | + $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").","; |
|
269 | + $sql .= " fk_bank=".(isset($this->fk_bank) ? $this->fk_bank : "null").","; |
|
270 | + $sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat : "null").","; |
|
271 | + $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif : "null").""; |
|
272 | + |
|
273 | + $sql .= " WHERE rowid=".$this->id; |
|
274 | 274 | |
275 | 275 | $this->db->begin(); |
276 | 276 | |
277 | 277 | dol_syslog(get_class($this)."::update", LOG_DEBUG); |
278 | 278 | $resql = $this->db->query($sql); |
279 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
279 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
280 | 280 | |
281 | - if (! $error) |
|
281 | + if (!$error) |
|
282 | 282 | { |
283 | - if (! $notrigger) |
|
283 | + if (!$notrigger) |
|
284 | 284 | { |
285 | 285 | // Uncomment this and change MYOBJECT to your own tag if you |
286 | 286 | // want this action call a trigger. |
@@ -297,13 +297,13 @@ discard block |
||
297 | 297 | // Commit or rollback |
298 | 298 | if ($error) |
299 | 299 | { |
300 | - foreach($this->errors as $errmsg) |
|
300 | + foreach ($this->errors as $errmsg) |
|
301 | 301 | { |
302 | 302 | dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
303 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
303 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
304 | 304 | } |
305 | 305 | $this->db->rollback(); |
306 | - return -1*$error; |
|
306 | + return -1 * $error; |
|
307 | 307 | } |
308 | 308 | else |
309 | 309 | { |
@@ -320,36 +320,36 @@ discard block |
||
320 | 320 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
321 | 321 | * @return int <0 if KO, >0 if OK |
322 | 322 | */ |
323 | - function delete($user, $notrigger=0) |
|
323 | + function delete($user, $notrigger = 0) |
|
324 | 324 | { |
325 | 325 | global $conf, $langs; |
326 | - $error=0; |
|
326 | + $error = 0; |
|
327 | 327 | |
328 | 328 | $this->db->begin(); |
329 | 329 | |
330 | - if (! $error) |
|
330 | + if (!$error) |
|
331 | 331 | { |
332 | 332 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; |
333 | - $sql.= " WHERE type='payment_loan' AND url_id=".$this->id; |
|
333 | + $sql .= " WHERE type='payment_loan' AND url_id=".$this->id; |
|
334 | 334 | |
335 | 335 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
336 | 336 | $resql = $this->db->query($sql); |
337 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
337 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
338 | 338 | } |
339 | 339 | |
340 | - if (! $error) |
|
340 | + if (!$error) |
|
341 | 341 | { |
342 | 342 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan"; |
343 | - $sql.= " WHERE rowid=".$this->id; |
|
343 | + $sql .= " WHERE rowid=".$this->id; |
|
344 | 344 | |
345 | 345 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
346 | 346 | $resql = $this->db->query($sql); |
347 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
347 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
348 | 348 | } |
349 | 349 | |
350 | - if (! $error) |
|
350 | + if (!$error) |
|
351 | 351 | { |
352 | - if (! $notrigger) |
|
352 | + if (!$notrigger) |
|
353 | 353 | { |
354 | 354 | // Uncomment this and change MYOBJECT to your own tag if you |
355 | 355 | // want this action call a trigger. |
@@ -366,13 +366,13 @@ discard block |
||
366 | 366 | // Commit or rollback |
367 | 367 | if ($error) |
368 | 368 | { |
369 | - foreach($this->errors as $errmsg) |
|
369 | + foreach ($this->errors as $errmsg) |
|
370 | 370 | { |
371 | 371 | dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
372 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
372 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
373 | 373 | } |
374 | 374 | $this->db->rollback(); |
375 | - return -1*$error; |
|
375 | + return -1 * $error; |
|
376 | 376 | } |
377 | 377 | else |
378 | 378 | { |
@@ -398,22 +398,22 @@ discard block |
||
398 | 398 | { |
399 | 399 | global $conf; |
400 | 400 | |
401 | - $error=0; |
|
401 | + $error = 0; |
|
402 | 402 | |
403 | - if (! empty($conf->banque->enabled)) |
|
403 | + if (!empty($conf->banque->enabled)) |
|
404 | 404 | { |
405 | 405 | require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; |
406 | 406 | |
407 | 407 | $acc = new Account($this->db); |
408 | 408 | $acc->fetch($accountid); |
409 | 409 | |
410 | - $total=$this->total; |
|
411 | - if ($mode == 'payment_loan') $total=-$total; |
|
410 | + $total = $this->total; |
|
411 | + if ($mode == 'payment_loan') $total = -$total; |
|
412 | 412 | |
413 | 413 | // Insert payment into llx_bank |
414 | 414 | $bank_line_id = $acc->addline( |
415 | 415 | $this->datepaid, |
416 | - $this->paymenttype, // Payment mode id or code ("CHQ or VIR for example") |
|
416 | + $this->paymenttype, // Payment mode id or code ("CHQ or VIR for example") |
|
417 | 417 | $label, |
418 | 418 | $total, |
419 | 419 | $this->num_payment, |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | // We know the payment who generated the account write |
428 | 428 | if ($bank_line_id > 0) |
429 | 429 | { |
430 | - $result=$this->update_fk_bank($bank_line_id); |
|
430 | + $result = $this->update_fk_bank($bank_line_id); |
|
431 | 431 | if ($result <= 0) |
432 | 432 | { |
433 | 433 | $error++; |
@@ -435,11 +435,11 @@ discard block |
||
435 | 435 | } |
436 | 436 | |
437 | 437 | // Add link 'payment_loan' in bank_url between payment and bank transaction |
438 | - $url=''; |
|
439 | - if ($mode == 'payment_loan') $url=DOL_URL_ROOT.'/loan/payment/card.php?id='; |
|
438 | + $url = ''; |
|
439 | + if ($mode == 'payment_loan') $url = DOL_URL_ROOT.'/loan/payment/card.php?id='; |
|
440 | 440 | if ($url) |
441 | 441 | { |
442 | - $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $mode); |
|
442 | + $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $mode); |
|
443 | 443 | if ($result <= 0) |
444 | 444 | { |
445 | 445 | $error++; |
@@ -450,18 +450,18 @@ discard block |
||
450 | 450 | // Add link 'loan' in bank_url between invoice and bank transaction (for each invoice concerned by payment) |
451 | 451 | if ($mode == 'payment_loan') |
452 | 452 | { |
453 | - $result=$acc->add_url_line($bank_line_id, $fk_loan, DOL_URL_ROOT.'/loan/card.php?id=', ($this->label?$this->label:''),'loan'); |
|
453 | + $result = $acc->add_url_line($bank_line_id, $fk_loan, DOL_URL_ROOT.'/loan/card.php?id=', ($this->label ? $this->label : ''), 'loan'); |
|
454 | 454 | if ($result <= 0) dol_print_error($this->db); |
455 | 455 | } |
456 | 456 | } |
457 | 457 | else |
458 | 458 | { |
459 | - $this->error=$acc->error; |
|
459 | + $this->error = $acc->error; |
|
460 | 460 | $error++; |
461 | 461 | } |
462 | 462 | } |
463 | 463 | |
464 | - if (! $error) |
|
464 | + if (!$error) |
|
465 | 465 | { |
466 | 466 | return 1; |
467 | 467 | } |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | } |
491 | 491 | else |
492 | 492 | { |
493 | - $this->error=$this->db->error(); |
|
493 | + $this->error = $this->db->error(); |
|
494 | 494 | return 0; |
495 | 495 | } |
496 | 496 | } |
@@ -502,22 +502,22 @@ discard block |
||
502 | 502 | * @param int $maxlen Max length label |
503 | 503 | * @return string Chaine with URL |
504 | 504 | */ |
505 | - function getNomUrl($withpicto=0,$maxlen=0) |
|
505 | + function getNomUrl($withpicto = 0, $maxlen = 0) |
|
506 | 506 | { |
507 | 507 | global $langs; |
508 | 508 | |
509 | - $result=''; |
|
509 | + $result = ''; |
|
510 | 510 | |
511 | - if (empty($this->ref)) $this->ref=$this->lib; |
|
511 | + if (empty($this->ref)) $this->ref = $this->lib; |
|
512 | 512 | |
513 | 513 | if (!empty($this->id)) |
514 | 514 | { |
515 | 515 | $link = '<a href="'.DOL_URL_ROOT.'/compta/payment/card.php?id='.$this->id.'">'; |
516 | - $linkend='</a>'; |
|
516 | + $linkend = '</a>'; |
|
517 | 517 | |
518 | - if ($withpicto) $result.=($link.img_object($langs->trans("ShowPayment").': '.$this->ref,'payment').$linkend.' '); |
|
519 | - if ($withpicto && $withpicto != 2) $result.=' '; |
|
520 | - if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend; |
|
518 | + if ($withpicto) $result .= ($link.img_object($langs->trans("ShowPayment").': '.$this->ref, 'payment').$linkend.' '); |
|
519 | + if ($withpicto && $withpicto != 2) $result .= ' '; |
|
520 | + if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend; |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | return $result; |
@@ -507,7 +507,7 @@ |
||
507 | 507 | /** |
508 | 508 | * Update object into database |
509 | 509 | * |
510 | - * @param User $user that modifies |
|
510 | + * @param integer $user that modifies |
|
511 | 511 | * @param int $notrigger triggers after, 1=disable triggers |
512 | 512 | * @param int $forceupdateaffiliate update price on each soc child |
513 | 513 | * @return int <0 if KO, >0 if OK |
@@ -75,34 +75,48 @@ discard block |
||
75 | 75 | |
76 | 76 | // Clean parameters |
77 | 77 | |
78 | - if (isset($this->entity)) |
|
79 | - $this->entity = trim($this->entity); |
|
80 | - if (isset($this->fk_product)) |
|
81 | - $this->fk_product = trim($this->fk_product); |
|
82 | - if (isset($this->fk_soc)) |
|
83 | - $this->fk_soc = trim($this->fk_soc); |
|
84 | - if (isset($this->price)) |
|
85 | - $this->price = trim($this->price); |
|
86 | - if (isset($this->price_ttc)) |
|
87 | - $this->price_ttc = trim($this->price_ttc); |
|
88 | - if (isset($this->price_min)) |
|
89 | - $this->price_min = trim($this->price_min); |
|
90 | - if (isset($this->price_min_ttc)) |
|
91 | - $this->price_min_ttc = trim($this->price_min_ttc); |
|
92 | - if (isset($this->price_base_type)) |
|
93 | - $this->price_base_type = trim($this->price_base_type); |
|
94 | - if (isset($this->tva_tx)) |
|
95 | - $this->tva_tx = trim($this->tva_tx); |
|
96 | - if (isset($this->recuperableonly)) |
|
97 | - $this->recuperableonly = trim($this->recuperableonly); |
|
98 | - if (isset($this->localtax1_tx)) |
|
99 | - $this->localtax1_tx = trim($this->localtax1_tx); |
|
100 | - if (isset($this->localtax2_tx)) |
|
101 | - $this->localtax2_tx = trim($this->localtax2_tx); |
|
102 | - if (isset($this->fk_user)) |
|
103 | - $this->fk_user = trim($this->fk_user); |
|
104 | - if (isset($this->import_key)) |
|
105 | - $this->import_key = trim($this->import_key); |
|
78 | + if (isset($this->entity)) { |
|
79 | + $this->entity = trim($this->entity); |
|
80 | + } |
|
81 | + if (isset($this->fk_product)) { |
|
82 | + $this->fk_product = trim($this->fk_product); |
|
83 | + } |
|
84 | + if (isset($this->fk_soc)) { |
|
85 | + $this->fk_soc = trim($this->fk_soc); |
|
86 | + } |
|
87 | + if (isset($this->price)) { |
|
88 | + $this->price = trim($this->price); |
|
89 | + } |
|
90 | + if (isset($this->price_ttc)) { |
|
91 | + $this->price_ttc = trim($this->price_ttc); |
|
92 | + } |
|
93 | + if (isset($this->price_min)) { |
|
94 | + $this->price_min = trim($this->price_min); |
|
95 | + } |
|
96 | + if (isset($this->price_min_ttc)) { |
|
97 | + $this->price_min_ttc = trim($this->price_min_ttc); |
|
98 | + } |
|
99 | + if (isset($this->price_base_type)) { |
|
100 | + $this->price_base_type = trim($this->price_base_type); |
|
101 | + } |
|
102 | + if (isset($this->tva_tx)) { |
|
103 | + $this->tva_tx = trim($this->tva_tx); |
|
104 | + } |
|
105 | + if (isset($this->recuperableonly)) { |
|
106 | + $this->recuperableonly = trim($this->recuperableonly); |
|
107 | + } |
|
108 | + if (isset($this->localtax1_tx)) { |
|
109 | + $this->localtax1_tx = trim($this->localtax1_tx); |
|
110 | + } |
|
111 | + if (isset($this->localtax2_tx)) { |
|
112 | + $this->localtax2_tx = trim($this->localtax2_tx); |
|
113 | + } |
|
114 | + if (isset($this->fk_user)) { |
|
115 | + $this->fk_user = trim($this->fk_user); |
|
116 | + } |
|
117 | + if (isset($this->import_key)) { |
|
118 | + $this->import_key = trim($this->import_key); |
|
119 | + } |
|
106 | 120 | |
107 | 121 | // Check parameters |
108 | 122 | // Put here code to add control on parameters values |
@@ -308,8 +322,12 @@ discard block |
||
308 | 322 | { |
309 | 323 | global $langs; |
310 | 324 | |
311 | - if ( empty($sortfield)) $sortfield = "t.rowid"; |
|
312 | - if ( empty($sortorder)) $sortorder = "DESC"; |
|
325 | + if ( empty($sortfield)) { |
|
326 | + $sortfield = "t.rowid"; |
|
327 | + } |
|
328 | + if ( empty($sortorder)) { |
|
329 | + $sortorder = "DESC"; |
|
330 | + } |
|
313 | 331 | |
314 | 332 | $sql = "SELECT"; |
315 | 333 | $sql .= " t.rowid,"; |
@@ -343,9 +361,11 @@ discard block |
||
343 | 361 | // Manage filter |
344 | 362 | if (count($filter) > 0) { |
345 | 363 | foreach ( $filter as $key => $value ) { |
346 | - if (strpos($key, 'date')) // To allow $filter['YEAR(s.dated)']=>$year |
|
364 | + if (strpos($key, 'date')) { |
|
365 | + // To allow $filter['YEAR(s.dated)']=>$year |
|
347 | 366 | { |
348 | 367 | $sql .= ' AND ' . $key . ' = \'' . $value . '\''; |
368 | + } |
|
349 | 369 | } elseif ($key == 'soc.nom') { |
350 | 370 | $sql .= ' AND ' . $key . ' LIKE \'%' . $value . '%\''; |
351 | 371 | } elseif ($key == 'prod.ref') { |
@@ -356,7 +376,9 @@ discard block |
||
356 | 376 | } |
357 | 377 | } |
358 | 378 | $sql.= $this->db->order($sortfield, $sortorder); |
359 | - if (! empty($limit)) $sql .= ' ' . $this->db->plimit($limit + 1, $offset); |
|
379 | + if (! empty($limit)) { |
|
380 | + $sql .= ' ' . $this->db->plimit($limit + 1, $offset); |
|
381 | + } |
|
360 | 382 | |
361 | 383 | dol_syslog(get_class($this) . "::fetch_all", LOG_DEBUG); |
362 | 384 | $resql = $this->db->query($sql); |
@@ -416,8 +438,12 @@ discard block |
||
416 | 438 | { |
417 | 439 | global $langs; |
418 | 440 | |
419 | - if (! empty($sortfield)) $sortfield = "t.rowid"; |
|
420 | - if (! empty($sortorder)) $sortorder = "DESC"; |
|
441 | + if (! empty($sortfield)) { |
|
442 | + $sortfield = "t.rowid"; |
|
443 | + } |
|
444 | + if (! empty($sortorder)) { |
|
445 | + $sortorder = "DESC"; |
|
446 | + } |
|
421 | 447 | |
422 | 448 | $sql = "SELECT"; |
423 | 449 | $sql .= " t.rowid,"; |
@@ -450,9 +476,11 @@ discard block |
||
450 | 476 | // Manage filter |
451 | 477 | if (count($filter) > 0) { |
452 | 478 | foreach ( $filter as $key => $value ) { |
453 | - if (strpos($key, 'date')) // To allow $filter['YEAR(s.dated)']=>$year |
|
479 | + if (strpos($key, 'date')) { |
|
480 | + // To allow $filter['YEAR(s.dated)']=>$year |
|
454 | 481 | { |
455 | 482 | $sql .= ' AND ' . $key . ' = \'' . $value . '\''; |
483 | + } |
|
456 | 484 | } elseif ($key == 'soc.nom') { |
457 | 485 | $sql .= ' AND ' . $key . ' LIKE \'%' . $value . '%\''; |
458 | 486 | } else { |
@@ -462,7 +490,9 @@ discard block |
||
462 | 490 | } |
463 | 491 | |
464 | 492 | $sql.= $this->db->order($sortfield, $sortorder); |
465 | - if (! empty($limit)) $sql .= ' ' . $this->db->plimit($limit + 1, $offset); |
|
493 | + if (! empty($limit)) { |
|
494 | + $sql .= ' ' . $this->db->plimit($limit + 1, $offset); |
|
495 | + } |
|
466 | 496 | |
467 | 497 | dol_syslog(get_class($this) . "::fetch_all_log", LOG_DEBUG); |
468 | 498 | $resql = $this->db->query($sql); |
@@ -523,34 +553,48 @@ discard block |
||
523 | 553 | |
524 | 554 | // Clean parameters |
525 | 555 | |
526 | - if (isset($this->entity)) |
|
527 | - $this->entity = trim($this->entity); |
|
528 | - if (isset($this->fk_product)) |
|
529 | - $this->fk_product = trim($this->fk_product); |
|
530 | - if (isset($this->fk_soc)) |
|
531 | - $this->fk_soc = trim($this->fk_soc); |
|
532 | - if (isset($this->price)) |
|
533 | - $this->price = trim($this->price); |
|
534 | - if (isset($this->price_ttc)) |
|
535 | - $this->price_ttc = trim($this->price_ttc); |
|
536 | - if (isset($this->price_min)) |
|
537 | - $this->price_min = trim($this->price_min); |
|
538 | - if (isset($this->price_min_ttc)) |
|
539 | - $this->price_min_ttc = trim($this->price_min_ttc); |
|
540 | - if (isset($this->price_base_type)) |
|
541 | - $this->price_base_type = trim($this->price_base_type); |
|
542 | - if (isset($this->tva_tx)) |
|
543 | - $this->tva_tx = trim($this->tva_tx); |
|
544 | - if (isset($this->recuperableonly)) |
|
545 | - $this->recuperableonly = trim($this->recuperableonly); |
|
546 | - if (isset($this->localtax1_tx)) |
|
547 | - $this->localtax1_tx = trim($this->localtax1_tx); |
|
548 | - if (isset($this->localtax2_tx)) |
|
549 | - $this->localtax2_tx = trim($this->localtax2_tx); |
|
550 | - if (isset($this->fk_user)) |
|
551 | - $this->fk_user = trim($this->fk_user); |
|
552 | - if (isset($this->import_key)) |
|
553 | - $this->import_key = trim($this->import_key); |
|
556 | + if (isset($this->entity)) { |
|
557 | + $this->entity = trim($this->entity); |
|
558 | + } |
|
559 | + if (isset($this->fk_product)) { |
|
560 | + $this->fk_product = trim($this->fk_product); |
|
561 | + } |
|
562 | + if (isset($this->fk_soc)) { |
|
563 | + $this->fk_soc = trim($this->fk_soc); |
|
564 | + } |
|
565 | + if (isset($this->price)) { |
|
566 | + $this->price = trim($this->price); |
|
567 | + } |
|
568 | + if (isset($this->price_ttc)) { |
|
569 | + $this->price_ttc = trim($this->price_ttc); |
|
570 | + } |
|
571 | + if (isset($this->price_min)) { |
|
572 | + $this->price_min = trim($this->price_min); |
|
573 | + } |
|
574 | + if (isset($this->price_min_ttc)) { |
|
575 | + $this->price_min_ttc = trim($this->price_min_ttc); |
|
576 | + } |
|
577 | + if (isset($this->price_base_type)) { |
|
578 | + $this->price_base_type = trim($this->price_base_type); |
|
579 | + } |
|
580 | + if (isset($this->tva_tx)) { |
|
581 | + $this->tva_tx = trim($this->tva_tx); |
|
582 | + } |
|
583 | + if (isset($this->recuperableonly)) { |
|
584 | + $this->recuperableonly = trim($this->recuperableonly); |
|
585 | + } |
|
586 | + if (isset($this->localtax1_tx)) { |
|
587 | + $this->localtax1_tx = trim($this->localtax1_tx); |
|
588 | + } |
|
589 | + if (isset($this->localtax2_tx)) { |
|
590 | + $this->localtax2_tx = trim($this->localtax2_tx); |
|
591 | + } |
|
592 | + if (isset($this->fk_user)) { |
|
593 | + $this->fk_user = trim($this->fk_user); |
|
594 | + } |
|
595 | + if (isset($this->import_key)) { |
|
596 | + $this->import_key = trim($this->import_key); |
|
597 | + } |
|
554 | 598 | |
555 | 599 | // Check parameters |
556 | 600 | // Put here code to add a control on parameters values |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * \ingroup produit |
22 | 22 | * \brief File of class to manage predefined price products or services by customer |
23 | 23 | */ |
24 | -require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; |
|
24 | +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * File of class to manage predefined price products or services by customer |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | var $localtax2_type; |
48 | 48 | var $localtax2_tx; |
49 | 49 | var $fk_user; |
50 | - var $lines = array (); |
|
50 | + var $lines = array(); |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Constructor |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | // Insert request |
142 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_customer_price("; |
|
142 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_customer_price("; |
|
143 | 143 | $sql .= "entity,"; |
144 | 144 | $sql .= "datec,"; |
145 | 145 | $sql .= "fk_product,"; |
@@ -159,39 +159,39 @@ discard block |
||
159 | 159 | $sql .= "fk_user,"; |
160 | 160 | $sql .= "import_key"; |
161 | 161 | $sql .= ") VALUES ("; |
162 | - $sql .= " " . $conf->entity . ","; |
|
163 | - $sql .= " '" . $this->db->idate(dol_now()) . "',"; |
|
164 | - $sql .= " " . (! isset($this->fk_product) ? 'NULL' : "'" . $this->db->escape($this->fk_product) . "'") . ","; |
|
165 | - $sql .= " " . (! isset($this->fk_soc) ? 'NULL' : "'" . $this->db->escape($this->fk_soc) . "'") . ","; |
|
166 | - $sql .= " " . (empty($this->price) ? '0' : "'" . $this->db->escape($this->price) . "'") . ","; |
|
167 | - $sql .= " " . (empty($this->price_ttc) ? '0' : "'" . $this->db->escape($this->price_ttc) . "'") . ","; |
|
168 | - $sql .= " " . (empty($this->price_min) ? '0' : "'" . $this->db->escape($this->price_min) . "'") . ","; |
|
169 | - $sql .= " " . (empty($this->price_min_ttc) ? '0' : "'" . $this->db->escape($this->price_min_ttc) . "'") . ","; |
|
170 | - $sql .= " " . (! isset($this->price_base_type) ? 'NULL' : "'" . $this->db->escape($this->price_base_type) . "'") . ","; |
|
162 | + $sql .= " ".$conf->entity.","; |
|
163 | + $sql .= " '".$this->db->idate(dol_now())."',"; |
|
164 | + $sql .= " ".(!isset($this->fk_product) ? 'NULL' : "'".$this->db->escape($this->fk_product)."'").","; |
|
165 | + $sql .= " ".(!isset($this->fk_soc) ? 'NULL' : "'".$this->db->escape($this->fk_soc)."'").","; |
|
166 | + $sql .= " ".(empty($this->price) ? '0' : "'".$this->db->escape($this->price)."'").","; |
|
167 | + $sql .= " ".(empty($this->price_ttc) ? '0' : "'".$this->db->escape($this->price_ttc)."'").","; |
|
168 | + $sql .= " ".(empty($this->price_min) ? '0' : "'".$this->db->escape($this->price_min)."'").","; |
|
169 | + $sql .= " ".(empty($this->price_min_ttc) ? '0' : "'".$this->db->escape($this->price_min_ttc)."'").","; |
|
170 | + $sql .= " ".(!isset($this->price_base_type) ? 'NULL' : "'".$this->db->escape($this->price_base_type)."'").","; |
|
171 | 171 | $sql .= " ".($this->default_vat_code ? "'".$this->db->escape($this->default_vat_code)."'" : "null").","; |
172 | - $sql .= " " . (! isset($this->tva_tx) ? 'NULL' : (empty($this->tva_tx)?0:$this->tva_tx)) . ","; |
|
173 | - $sql .= " " . (! isset($this->recuperableonly) ? 'NULL' : "'" . $this->db->escape($this->recuperableonly) . "'") . ","; |
|
174 | - $sql .= " " . (empty($this->localtax1_type) ? "'0'" : "'" . $this->db->escape($this->localtax1_type) . "'") . ","; |
|
175 | - $sql .= " " . (! isset($this->localtax1_tx) ? 'NULL' : (empty($this->localtax1_tx)?0:$this->localtax1_tx)) . ","; |
|
176 | - $sql .= " " . (empty($this->localtax2_type) ? "'0'" : "'" . $this->db->escape($this->localtax2_type) . "'") . ","; |
|
177 | - $sql .= " " . (! isset($this->localtax2_tx) ? 'NULL' : (empty($this->localtax2_tx)?0:$this->localtax2_tx)) . ","; |
|
178 | - $sql .= " " . $user->id . ","; |
|
179 | - $sql .= " " . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . ""; |
|
172 | + $sql .= " ".(!isset($this->tva_tx) ? 'NULL' : (empty($this->tva_tx) ? 0 : $this->tva_tx)).","; |
|
173 | + $sql .= " ".(!isset($this->recuperableonly) ? 'NULL' : "'".$this->db->escape($this->recuperableonly)."'").","; |
|
174 | + $sql .= " ".(empty($this->localtax1_type) ? "'0'" : "'".$this->db->escape($this->localtax1_type)."'").","; |
|
175 | + $sql .= " ".(!isset($this->localtax1_tx) ? 'NULL' : (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx)).","; |
|
176 | + $sql .= " ".(empty($this->localtax2_type) ? "'0'" : "'".$this->db->escape($this->localtax2_type)."'").","; |
|
177 | + $sql .= " ".(!isset($this->localtax2_tx) ? 'NULL' : (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx)).","; |
|
178 | + $sql .= " ".$user->id.","; |
|
179 | + $sql .= " ".(!isset($this->import_key) ? 'NULL' : "'".$this->db->escape($this->import_key)."'").""; |
|
180 | 180 | $sql .= ")"; |
181 | 181 | |
182 | 182 | $this->db->begin(); |
183 | 183 | |
184 | - dol_syslog(get_class($this) . "::create", LOG_DEBUG); |
|
184 | + dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
185 | 185 | $resql = $this->db->query($sql); |
186 | - if (! $resql) { |
|
187 | - $error ++; |
|
188 | - $this->errors [] = "Error " . $this->db->lasterror(); |
|
186 | + if (!$resql) { |
|
187 | + $error++; |
|
188 | + $this->errors [] = "Error ".$this->db->lasterror(); |
|
189 | 189 | } |
190 | 190 | |
191 | - if (! $error) { |
|
192 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "product_customer_price"); |
|
191 | + if (!$error) { |
|
192 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_customer_price"); |
|
193 | 193 | |
194 | - if (! $notrigger) { |
|
194 | + if (!$notrigger) { |
|
195 | 195 | // Uncomment this and change MYOBJECT to your own tag if you |
196 | 196 | // want this action calls a trigger. |
197 | 197 | |
@@ -204,21 +204,21 @@ discard block |
||
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
207 | - if (! $error) { |
|
207 | + if (!$error) { |
|
208 | 208 | $result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate); |
209 | 209 | if ($result < 0) { |
210 | - $error ++; |
|
210 | + $error++; |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | 214 | // Commit or rollback |
215 | 215 | if ($error) { |
216 | - foreach ( $this->errors as $errmsg ) { |
|
217 | - dol_syslog(get_class($this) . "::create " . $errmsg, LOG_ERR); |
|
218 | - $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); |
|
216 | + foreach ($this->errors as $errmsg) { |
|
217 | + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
|
218 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
219 | 219 | } |
220 | 220 | $this->db->rollback(); |
221 | - return - 1 * $error; |
|
221 | + return -1 * $error; |
|
222 | 222 | } else { |
223 | 223 | $this->db->commit(); |
224 | 224 | return $this->id; |
@@ -256,10 +256,10 @@ discard block |
||
256 | 256 | $sql .= " t.fk_user,"; |
257 | 257 | $sql .= " t.import_key"; |
258 | 258 | |
259 | - $sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price as t"; |
|
260 | - $sql .= " WHERE t.rowid = " . $id; |
|
259 | + $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t"; |
|
260 | + $sql .= " WHERE t.rowid = ".$id; |
|
261 | 261 | |
262 | - dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); |
|
262 | + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
263 | 263 | $resql = $this->db->query($sql); |
264 | 264 | if ($resql) { |
265 | 265 | if ($this->db->num_rows($resql)) { |
@@ -289,8 +289,8 @@ discard block |
||
289 | 289 | |
290 | 290 | return 1; |
291 | 291 | } else { |
292 | - $this->error = "Error " . $this->db->lasterror(); |
|
293 | - return - 1; |
|
292 | + $this->error = "Error ".$this->db->lasterror(); |
|
293 | + return -1; |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | { |
309 | 309 | global $langs; |
310 | 310 | |
311 | - if ( empty($sortfield)) $sortfield = "t.rowid"; |
|
312 | - if ( empty($sortorder)) $sortorder = "DESC"; |
|
311 | + if (empty($sortfield)) $sortfield = "t.rowid"; |
|
312 | + if (empty($sortorder)) $sortorder = "DESC"; |
|
313 | 313 | |
314 | 314 | $sql = "SELECT"; |
315 | 315 | $sql .= " t.rowid,"; |
@@ -333,39 +333,39 @@ discard block |
||
333 | 333 | $sql .= " t.import_key,"; |
334 | 334 | $sql .= " soc.nom as socname,"; |
335 | 335 | $sql .= " prod.ref as prodref"; |
336 | - $sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price as t "; |
|
337 | - $sql .= " ," . MAIN_DB_PREFIX . "product as prod "; |
|
338 | - $sql .= " ," . MAIN_DB_PREFIX . "societe as soc "; |
|
336 | + $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t "; |
|
337 | + $sql .= " ,".MAIN_DB_PREFIX."product as prod "; |
|
338 | + $sql .= " ,".MAIN_DB_PREFIX."societe as soc "; |
|
339 | 339 | $sql .= " WHERE soc.rowid=t.fk_soc "; |
340 | 340 | $sql .= " AND prod.rowid=t.fk_product "; |
341 | - $sql .= " AND prod.entity IN (" . getEntity('product') . ")"; |
|
341 | + $sql .= " AND prod.entity IN (".getEntity('product').")"; |
|
342 | 342 | |
343 | 343 | // Manage filter |
344 | 344 | if (count($filter) > 0) { |
345 | - foreach ( $filter as $key => $value ) { |
|
345 | + foreach ($filter as $key => $value) { |
|
346 | 346 | if (strpos($key, 'date')) // To allow $filter['YEAR(s.dated)']=>$year |
347 | 347 | { |
348 | - $sql .= ' AND ' . $key . ' = \'' . $value . '\''; |
|
348 | + $sql .= ' AND '.$key.' = \''.$value.'\''; |
|
349 | 349 | } elseif ($key == 'soc.nom') { |
350 | - $sql .= ' AND ' . $key . ' LIKE \'%' . $value . '%\''; |
|
350 | + $sql .= ' AND '.$key.' LIKE \'%'.$value.'%\''; |
|
351 | 351 | } elseif ($key == 'prod.ref') { |
352 | - $sql .= ' AND ' . $key . ' LIKE \'%' . $value . '%\''; |
|
352 | + $sql .= ' AND '.$key.' LIKE \'%'.$value.'%\''; |
|
353 | 353 | } else { |
354 | - $sql .= ' AND ' . $key . ' = ' . $value; |
|
354 | + $sql .= ' AND '.$key.' = '.$value; |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | } |
358 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
359 | - if (! empty($limit)) $sql .= ' ' . $this->db->plimit($limit + 1, $offset); |
|
358 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
359 | + if (!empty($limit)) $sql .= ' '.$this->db->plimit($limit + 1, $offset); |
|
360 | 360 | |
361 | - dol_syslog(get_class($this) . "::fetch_all", LOG_DEBUG); |
|
361 | + dol_syslog(get_class($this)."::fetch_all", LOG_DEBUG); |
|
362 | 362 | $resql = $this->db->query($sql); |
363 | 363 | if ($resql) { |
364 | 364 | |
365 | - $this->lines = array (); |
|
365 | + $this->lines = array(); |
|
366 | 366 | $num = $this->db->num_rows($resql); |
367 | 367 | |
368 | - while ( $obj = $this->db->fetch_object($resql) ) { |
|
368 | + while ($obj = $this->db->fetch_object($resql)) { |
|
369 | 369 | |
370 | 370 | $line = new PriceByCustomerLine(); |
371 | 371 | |
@@ -397,8 +397,8 @@ discard block |
||
397 | 397 | |
398 | 398 | return $num; |
399 | 399 | } else { |
400 | - $this->error = "Error " . $this->db->lasterror(); |
|
401 | - return - 1; |
|
400 | + $this->error = "Error ".$this->db->lasterror(); |
|
401 | + return -1; |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | { |
417 | 417 | global $langs; |
418 | 418 | |
419 | - if (! empty($sortfield)) $sortfield = "t.rowid"; |
|
420 | - if (! empty($sortorder)) $sortorder = "DESC"; |
|
419 | + if (!empty($sortfield)) $sortfield = "t.rowid"; |
|
420 | + if (!empty($sortorder)) $sortorder = "DESC"; |
|
421 | 421 | |
422 | 422 | $sql = "SELECT"; |
423 | 423 | $sql .= " t.rowid,"; |
@@ -440,38 +440,38 @@ discard block |
||
440 | 440 | $sql .= " t.import_key,"; |
441 | 441 | $sql .= " soc.nom as socname,"; |
442 | 442 | $sql .= " prod.ref as prodref"; |
443 | - $sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price_log as t "; |
|
444 | - $sql .= " ," . MAIN_DB_PREFIX . "product as prod "; |
|
445 | - $sql .= " ," . MAIN_DB_PREFIX . "societe as soc "; |
|
443 | + $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price_log as t "; |
|
444 | + $sql .= " ,".MAIN_DB_PREFIX."product as prod "; |
|
445 | + $sql .= " ,".MAIN_DB_PREFIX."societe as soc "; |
|
446 | 446 | $sql .= " WHERE soc.rowid=t.fk_soc "; |
447 | 447 | $sql .= " AND prod.rowid=t.fk_product "; |
448 | - $sql .= " AND prod.entity IN (" . getEntity('product') . ")"; |
|
448 | + $sql .= " AND prod.entity IN (".getEntity('product').")"; |
|
449 | 449 | |
450 | 450 | // Manage filter |
451 | 451 | if (count($filter) > 0) { |
452 | - foreach ( $filter as $key => $value ) { |
|
452 | + foreach ($filter as $key => $value) { |
|
453 | 453 | if (strpos($key, 'date')) // To allow $filter['YEAR(s.dated)']=>$year |
454 | 454 | { |
455 | - $sql .= ' AND ' . $key . ' = \'' . $value . '\''; |
|
455 | + $sql .= ' AND '.$key.' = \''.$value.'\''; |
|
456 | 456 | } elseif ($key == 'soc.nom') { |
457 | - $sql .= ' AND ' . $key . ' LIKE \'%' . $value . '%\''; |
|
457 | + $sql .= ' AND '.$key.' LIKE \'%'.$value.'%\''; |
|
458 | 458 | } else { |
459 | - $sql .= ' AND ' . $key . ' = ' . $value; |
|
459 | + $sql .= ' AND '.$key.' = '.$value; |
|
460 | 460 | } |
461 | 461 | } |
462 | 462 | } |
463 | 463 | |
464 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
465 | - if (! empty($limit)) $sql .= ' ' . $this->db->plimit($limit + 1, $offset); |
|
464 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
465 | + if (!empty($limit)) $sql .= ' '.$this->db->plimit($limit + 1, $offset); |
|
466 | 466 | |
467 | - dol_syslog(get_class($this) . "::fetch_all_log", LOG_DEBUG); |
|
467 | + dol_syslog(get_class($this)."::fetch_all_log", LOG_DEBUG); |
|
468 | 468 | $resql = $this->db->query($sql); |
469 | 469 | if ($resql) { |
470 | 470 | |
471 | - $this->lines = array (); |
|
471 | + $this->lines = array(); |
|
472 | 472 | $num = $this->db->num_rows($resql); |
473 | 473 | |
474 | - while ( $obj = $this->db->fetch_object($resql) ) { |
|
474 | + while ($obj = $this->db->fetch_object($resql)) { |
|
475 | 475 | |
476 | 476 | $line = new PriceByCustomerLine(); |
477 | 477 | |
@@ -503,8 +503,8 @@ discard block |
||
503 | 503 | |
504 | 504 | return $num; |
505 | 505 | } else { |
506 | - $this->error = "Error " . $this->db->lasterror(); |
|
507 | - return - 1; |
|
506 | + $this->error = "Error ".$this->db->lasterror(); |
|
507 | + return -1; |
|
508 | 508 | } |
509 | 509 | } |
510 | 510 | |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | |
589 | 589 | // Do a copy of current record into log table |
590 | 590 | // Insert request |
591 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_customer_price_log("; |
|
591 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_customer_price_log("; |
|
592 | 592 | |
593 | 593 | $sql .= "entity,"; |
594 | 594 | $sql .= "datec,"; |
@@ -631,75 +631,75 @@ discard block |
||
631 | 631 | $sql .= " t.fk_user,"; |
632 | 632 | $sql .= " t.import_key"; |
633 | 633 | |
634 | - $sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price as t"; |
|
635 | - $sql .= " WHERE t.rowid = " . $this->id; |
|
634 | + $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t"; |
|
635 | + $sql .= " WHERE t.rowid = ".$this->id; |
|
636 | 636 | |
637 | 637 | $this->db->begin(); |
638 | - dol_syslog(get_class($this) . "::update", LOG_DEBUG); |
|
638 | + dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
639 | 639 | $resql = $this->db->query($sql); |
640 | - if (! $resql) { |
|
641 | - $error ++; |
|
642 | - $this->errors [] = "Error " . $this->db->lasterror(); |
|
640 | + if (!$resql) { |
|
641 | + $error++; |
|
642 | + $this->errors [] = "Error ".$this->db->lasterror(); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | // Update request |
646 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "product_customer_price SET"; |
|
647 | - |
|
648 | - $sql .= " entity=" . $conf->entity . ","; |
|
649 | - $sql .= " datec='" . $this->db->idate(dol_now()) . "',"; |
|
650 | - $sql .= " tms=" . (dol_strlen($this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : 'null') . ","; |
|
651 | - $sql .= " fk_product=" . (isset($this->fk_product) ? $this->fk_product : "null") . ","; |
|
652 | - $sql .= " fk_soc=" . (isset($this->fk_soc) ? $this->fk_soc : "null") . ","; |
|
653 | - $sql .= " price=" . (isset($this->price) ? $this->price : "null") . ","; |
|
654 | - $sql .= " price_ttc=" . (isset($this->price_ttc) ? $this->price_ttc : "null") . ","; |
|
655 | - $sql .= " price_min=" . (isset($this->price_min) ? $this->price_min : "null") . ","; |
|
656 | - $sql .= " price_min_ttc=" . (isset($this->price_min_ttc) ? $this->price_min_ttc : "null") . ","; |
|
657 | - $sql .= " price_base_type=" . (isset($this->price_base_type) ? "'" . $this->db->escape($this->price_base_type) . "'" : "null") . ","; |
|
646 | + $sql = "UPDATE ".MAIN_DB_PREFIX."product_customer_price SET"; |
|
647 | + |
|
648 | + $sql .= " entity=".$conf->entity.","; |
|
649 | + $sql .= " datec='".$this->db->idate(dol_now())."',"; |
|
650 | + $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; |
|
651 | + $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").","; |
|
652 | + $sql .= " fk_soc=".(isset($this->fk_soc) ? $this->fk_soc : "null").","; |
|
653 | + $sql .= " price=".(isset($this->price) ? $this->price : "null").","; |
|
654 | + $sql .= " price_ttc=".(isset($this->price_ttc) ? $this->price_ttc : "null").","; |
|
655 | + $sql .= " price_min=".(isset($this->price_min) ? $this->price_min : "null").","; |
|
656 | + $sql .= " price_min_ttc=".(isset($this->price_min_ttc) ? $this->price_min_ttc : "null").","; |
|
657 | + $sql .= " price_base_type=".(isset($this->price_base_type) ? "'".$this->db->escape($this->price_base_type)."'" : "null").","; |
|
658 | 658 | $sql .= " default_vat_code = ".($this->default_vat_code ? "'".$this->db->escape($this->default_vat_code)."'" : "null").","; |
659 | - $sql .= " tva_tx=" . (isset($this->tva_tx) ? (empty($this->tva_tx)?0:$this->tva_tx) : "null") . ","; |
|
660 | - $sql .= " recuperableonly=" . (isset($this->recuperableonly) ? $this->recuperableonly : "null") . ","; |
|
661 | - $sql .= " localtax1_tx=" . (isset($this->localtax1_tx) ? (empty($this->localtax1_tx)?0:$this->localtax1_tx) : "null") . ","; |
|
662 | - $sql .= " localtax2_tx=" . (isset($this->localtax2_tx) ? (empty($this->localtax2_tx)?0:$this->localtax2_tx) : "null") . ","; |
|
663 | - $sql .= " localtax1_type=" . (! empty($this->localtax1_type) ? "'".$this->db->escape($this->localtax1_type)."'": "'0'") . ","; |
|
664 | - $sql .= " localtax2_type=" . (! empty($this->localtax2_type) ? "'".$this->db->escape($this->localtax2_type)."'": "'0'") . ","; |
|
665 | - $sql .= " fk_user=" . $user->id . ","; |
|
666 | - $sql .= " import_key=" . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null") . ""; |
|
667 | - |
|
668 | - $sql .= " WHERE rowid=" . $this->id; |
|
669 | - |
|
670 | - dol_syslog(get_class($this) . "::update", LOG_DEBUG); |
|
659 | + $sql .= " tva_tx=".(isset($this->tva_tx) ? (empty($this->tva_tx) ? 0 : $this->tva_tx) : "null").","; |
|
660 | + $sql .= " recuperableonly=".(isset($this->recuperableonly) ? $this->recuperableonly : "null").","; |
|
661 | + $sql .= " localtax1_tx=".(isset($this->localtax1_tx) ? (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx) : "null").","; |
|
662 | + $sql .= " localtax2_tx=".(isset($this->localtax2_tx) ? (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx) : "null").","; |
|
663 | + $sql .= " localtax1_type=".(!empty($this->localtax1_type) ? "'".$this->db->escape($this->localtax1_type)."'" : "'0'").","; |
|
664 | + $sql .= " localtax2_type=".(!empty($this->localtax2_type) ? "'".$this->db->escape($this->localtax2_type)."'" : "'0'").","; |
|
665 | + $sql .= " fk_user=".$user->id.","; |
|
666 | + $sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null").""; |
|
667 | + |
|
668 | + $sql .= " WHERE rowid=".$this->id; |
|
669 | + |
|
670 | + dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
671 | 671 | $resql = $this->db->query($sql); |
672 | - if (! $resql) { |
|
673 | - $error ++; |
|
674 | - $this->errors [] = "Error " . $this->db->lasterror(); |
|
672 | + if (!$resql) { |
|
673 | + $error++; |
|
674 | + $this->errors [] = "Error ".$this->db->lasterror(); |
|
675 | 675 | } |
676 | 676 | |
677 | - if (! $error) { |
|
678 | - if (! $notrigger) { |
|
677 | + if (!$error) { |
|
678 | + if (!$notrigger) { |
|
679 | 679 | // Call triggers |
680 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
681 | - $interface=new Interfaces($this->db); |
|
682 | - $result=$interface->run_triggers('PRODUCT_CUSTOMER_PRICE_UPDATE',$this,$user,$langs,$conf); |
|
683 | - if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
680 | + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; |
|
681 | + $interface = new Interfaces($this->db); |
|
682 | + $result = $interface->run_triggers('PRODUCT_CUSTOMER_PRICE_UPDATE', $this, $user, $langs, $conf); |
|
683 | + if ($result < 0) { $error++; $this->errors = $interface->errors; } |
|
684 | 684 | // End call triggers |
685 | 685 | } |
686 | 686 | } |
687 | 687 | |
688 | - if (! $error) { |
|
688 | + if (!$error) { |
|
689 | 689 | $result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate); |
690 | 690 | if ($result < 0) { |
691 | - $error ++; |
|
691 | + $error++; |
|
692 | 692 | } |
693 | 693 | } |
694 | 694 | |
695 | 695 | // Commit or rollback |
696 | 696 | if ($error) { |
697 | - foreach ( $this->errors as $errmsg ) { |
|
698 | - dol_syslog(get_class($this) . "::update " . $errmsg, LOG_ERR); |
|
699 | - $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); |
|
697 | + foreach ($this->errors as $errmsg) { |
|
698 | + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
699 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
700 | 700 | } |
701 | 701 | $this->db->rollback(); |
702 | - return - 1 * $error; |
|
702 | + return -1 * $error; |
|
703 | 703 | } else { |
704 | 704 | $this->db->commit(); |
705 | 705 | return 1; |
@@ -719,37 +719,37 @@ discard block |
||
719 | 719 | |
720 | 720 | // Find all susidiaries |
721 | 721 | $sql = "SELECT s.rowid"; |
722 | - $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; |
|
723 | - $sql .= " WHERE s.parent = " . $this->fk_soc; |
|
724 | - $sql .= " AND s.entity IN (" . getEntity('societe') . ")"; |
|
722 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
723 | + $sql .= " WHERE s.parent = ".$this->fk_soc; |
|
724 | + $sql .= " AND s.entity IN (".getEntity('societe').")"; |
|
725 | 725 | |
726 | - dol_syslog(get_class($this) . "::setPriceOnAffiliateThirdparty", LOG_DEBUG); |
|
726 | + dol_syslog(get_class($this)."::setPriceOnAffiliateThirdparty", LOG_DEBUG); |
|
727 | 727 | $resql = $this->db->query($sql); |
728 | 728 | |
729 | 729 | if ($resql) { |
730 | 730 | |
731 | - $this->lines = array (); |
|
731 | + $this->lines = array(); |
|
732 | 732 | $num = $this->db->num_rows($resql); |
733 | 733 | |
734 | - while ( ($obj = $this->db->fetch_object($resql)) && (empty($error)) ) { |
|
734 | + while (($obj = $this->db->fetch_object($resql)) && (empty($error))) { |
|
735 | 735 | |
736 | 736 | // find if there is an existing line for the product and the subsidiaries |
737 | 737 | $prodsocprice = new Productcustomerprice($this->db); |
738 | 738 | |
739 | - $filter = array ( |
|
740 | - 't.fk_product' => $this->fk_product,'t.fk_soc' => $obj->rowid |
|
739 | + $filter = array( |
|
740 | + 't.fk_product' => $this->fk_product, 't.fk_soc' => $obj->rowid |
|
741 | 741 | ); |
742 | 742 | |
743 | 743 | $result = $prodsocprice->fetch_all('', '', 0, 0, $filter); |
744 | 744 | if ($result < 0) { |
745 | - $error ++; |
|
745 | + $error++; |
|
746 | 746 | $this->error = $prodsocprice->error; |
747 | 747 | } else { |
748 | 748 | |
749 | 749 | // There is one line |
750 | 750 | if (count($prodsocprice->lines) > 0) { |
751 | 751 | // If force update => Update |
752 | - if (! empty($forceupdateaffiliate)) { |
|
752 | + if (!empty($forceupdateaffiliate)) { |
|
753 | 753 | |
754 | 754 | $prodsocpriceupd = new Productcustomerprice($this->db); |
755 | 755 | $prodsocpriceupd->fetch($prodsocprice->lines [0]->id); |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | |
763 | 763 | $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate); |
764 | 764 | if ($result < 0) { |
765 | - $error ++; |
|
765 | + $error++; |
|
766 | 766 | $this->error = $prodsocpriceupd->error; |
767 | 767 | } |
768 | 768 | } |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | |
780 | 780 | $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate); |
781 | 781 | if ($result < 0) { |
782 | - $error ++; |
|
782 | + $error++; |
|
783 | 783 | $this->error = $prodsocpriceupd->error; |
784 | 784 | } |
785 | 785 | } |
@@ -790,11 +790,11 @@ discard block |
||
790 | 790 | if (empty($error)) { |
791 | 791 | return 1; |
792 | 792 | } else { |
793 | - return - 1; |
|
793 | + return -1; |
|
794 | 794 | } |
795 | 795 | } else { |
796 | - $this->error = "Error " . $this->db->lasterror(); |
|
797 | - return - 1; |
|
796 | + $this->error = "Error ".$this->db->lasterror(); |
|
797 | + return -1; |
|
798 | 798 | } |
799 | 799 | } |
800 | 800 | |
@@ -812,8 +812,8 @@ discard block |
||
812 | 812 | |
813 | 813 | $this->db->begin(); |
814 | 814 | |
815 | - if (! $error) { |
|
816 | - if (! $notrigger) { |
|
815 | + if (!$error) { |
|
816 | + if (!$notrigger) { |
|
817 | 817 | // Uncomment this and change MYOBJECT to your own tag if you |
818 | 818 | // want this action calls a trigger. |
819 | 819 | |
@@ -826,26 +826,26 @@ discard block |
||
826 | 826 | } |
827 | 827 | } |
828 | 828 | |
829 | - if (! $error) { |
|
830 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "product_customer_price"; |
|
831 | - $sql .= " WHERE rowid=" . $this->id; |
|
829 | + if (!$error) { |
|
830 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_customer_price"; |
|
831 | + $sql .= " WHERE rowid=".$this->id; |
|
832 | 832 | |
833 | - dol_syslog(get_class($this) . "::delete", LOG_DEBUG); |
|
833 | + dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
834 | 834 | $resql = $this->db->query($sql); |
835 | - if (! $resql) { |
|
836 | - $error ++; |
|
837 | - $this->errors [] = "Error " . $this->db->lasterror(); |
|
835 | + if (!$resql) { |
|
836 | + $error++; |
|
837 | + $this->errors [] = "Error ".$this->db->lasterror(); |
|
838 | 838 | } |
839 | 839 | } |
840 | 840 | |
841 | 841 | // Commit or rollback |
842 | 842 | if ($error) { |
843 | - foreach ( $this->errors as $errmsg ) { |
|
844 | - dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); |
|
845 | - $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); |
|
843 | + foreach ($this->errors as $errmsg) { |
|
844 | + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
845 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
846 | 846 | } |
847 | 847 | $this->db->rollback(); |
848 | - return - 1 * $error; |
|
848 | + return -1 * $error; |
|
849 | 849 | } else { |
850 | 850 | $this->db->commit(); |
851 | 851 | return 1; |
@@ -866,7 +866,7 @@ discard block |
||
866 | 866 | |
867 | 867 | $object = new Productcustomerprice($this->db); |
868 | 868 | |
869 | - $object->context['createfromclone']='createfromclone'; |
|
869 | + $object->context['createfromclone'] = 'createfromclone'; |
|
870 | 870 | |
871 | 871 | $this->db->begin(); |
872 | 872 | |
@@ -884,21 +884,21 @@ discard block |
||
884 | 884 | // Other options |
885 | 885 | if ($result < 0) { |
886 | 886 | $this->error = $object->error; |
887 | - $error ++; |
|
887 | + $error++; |
|
888 | 888 | } |
889 | 889 | |
890 | - if (! $error) { |
|
890 | + if (!$error) { |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | unset($object->context['createfromclone']); |
894 | 894 | |
895 | 895 | // End |
896 | - if (! $error) { |
|
896 | + if (!$error) { |
|
897 | 897 | $this->db->commit(); |
898 | 898 | return $object->id; |
899 | 899 | } else { |
900 | 900 | $this->db->rollback(); |
901 | - return - 1; |
|
901 | + return -1; |
|
902 | 902 | } |
903 | 903 | } |
904 | 904 |
@@ -297,7 +297,7 @@ |
||
297 | 297 | /** |
298 | 298 | * Update object into database |
299 | 299 | * |
300 | - * @param User $user User that modifies |
|
300 | + * @param integer $user User that modifies |
|
301 | 301 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
302 | 302 | * @return int <0 if KO, >0 if OK |
303 | 303 | */ |
@@ -73,12 +73,24 @@ discard block |
||
73 | 73 | |
74 | 74 | // Clean parameters |
75 | 75 | |
76 | - if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product); |
|
77 | - if (isset($this->file_name)) $this->file_name=trim($this->file_name); |
|
78 | - if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author); |
|
79 | - if (isset($this->fk_user_mod)) $this->fk_user_mod=trim($this->fk_user_mod); |
|
80 | - if (isset($this->lang)) $this->lang=trim($this->lang); |
|
81 | - if (isset($this->import_key)) $this->import_key=trim($this->import_key); |
|
76 | + if (isset($this->fk_product)) { |
|
77 | + $this->fk_product=trim($this->fk_product); |
|
78 | + } |
|
79 | + if (isset($this->file_name)) { |
|
80 | + $this->file_name=trim($this->file_name); |
|
81 | + } |
|
82 | + if (isset($this->fk_user_author)) { |
|
83 | + $this->fk_user_author=trim($this->fk_user_author); |
|
84 | + } |
|
85 | + if (isset($this->fk_user_mod)) { |
|
86 | + $this->fk_user_mod=trim($this->fk_user_mod); |
|
87 | + } |
|
88 | + if (isset($this->lang)) { |
|
89 | + $this->lang=trim($this->lang); |
|
90 | + } |
|
91 | + if (isset($this->import_key)) { |
|
92 | + $this->import_key=trim($this->import_key); |
|
93 | + } |
|
82 | 94 | |
83 | 95 | |
84 | 96 | |
@@ -146,8 +158,7 @@ discard block |
||
146 | 158 | } |
147 | 159 | $this->db->rollback(); |
148 | 160 | return -1*$error; |
149 | - } |
|
150 | - else |
|
161 | + } else |
|
151 | 162 | { |
152 | 163 | $this->db->commit(); |
153 | 164 | return $this->id; |
@@ -207,8 +218,7 @@ discard block |
||
207 | 218 | $this->db->free($resql); |
208 | 219 | |
209 | 220 | return 1; |
210 | - } |
|
211 | - else |
|
221 | + } else |
|
212 | 222 | { |
213 | 223 | $this->error="Error ".$this->db->lasterror(); |
214 | 224 | dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); |
@@ -272,7 +282,7 @@ discard block |
||
272 | 282 | |
273 | 283 | if ($conf->global->MAIN_MULTILANGS) { |
274 | 284 | $this->lines[$obj->file_name.'_'.$obj->lang]=$line; |
275 | - }else { |
|
285 | + } else { |
|
276 | 286 | $this->lines[$obj->file_name]=$line; |
277 | 287 | } |
278 | 288 | |
@@ -284,8 +294,7 @@ discard block |
||
284 | 294 | $this->db->free($resql); |
285 | 295 | |
286 | 296 | return 1; |
287 | - } |
|
288 | - else |
|
297 | + } else |
|
289 | 298 | { |
290 | 299 | $this->error="Error ".$this->db->lasterror(); |
291 | 300 | dol_syslog(get_class($this)."::fetch_by_product ".$this->error, LOG_ERR); |
@@ -308,10 +317,18 @@ discard block |
||
308 | 317 | |
309 | 318 | // Clean parameters |
310 | 319 | |
311 | - if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product); |
|
312 | - if (isset($this->file_name)) $this->file_name=trim($this->file_name); |
|
313 | - if (isset($this->fk_user_mod)) $this->fk_user_mod=trim($this->fk_user_mod); |
|
314 | - if (isset($this->lang)) $this->lang=trim($this->lang); |
|
320 | + if (isset($this->fk_product)) { |
|
321 | + $this->fk_product=trim($this->fk_product); |
|
322 | + } |
|
323 | + if (isset($this->file_name)) { |
|
324 | + $this->file_name=trim($this->file_name); |
|
325 | + } |
|
326 | + if (isset($this->fk_user_mod)) { |
|
327 | + $this->fk_user_mod=trim($this->fk_user_mod); |
|
328 | + } |
|
329 | + if (isset($this->lang)) { |
|
330 | + $this->lang=trim($this->lang); |
|
331 | + } |
|
315 | 332 | |
316 | 333 | |
317 | 334 | |
@@ -364,8 +381,7 @@ discard block |
||
364 | 381 | } |
365 | 382 | $this->db->rollback(); |
366 | 383 | return -1*$error; |
367 | - } |
|
368 | - else |
|
384 | + } else |
|
369 | 385 | { |
370 | 386 | $this->db->commit(); |
371 | 387 | return 1; |
@@ -423,8 +439,7 @@ discard block |
||
423 | 439 | } |
424 | 440 | $this->db->rollback(); |
425 | 441 | return -1*$error; |
426 | - } |
|
427 | - else |
|
442 | + } else |
|
428 | 443 | { |
429 | 444 | $this->db->commit(); |
430 | 445 | return 1; |
@@ -487,8 +502,7 @@ discard block |
||
487 | 502 | } |
488 | 503 | $this->db->rollback(); |
489 | 504 | return -1*$error; |
490 | - } |
|
491 | - else |
|
505 | + } else |
|
492 | 506 | { |
493 | 507 | $this->db->commit(); |
494 | 508 | return 1; |
@@ -544,8 +558,7 @@ discard block |
||
544 | 558 | } |
545 | 559 | $this->db->rollback(); |
546 | 560 | return -1*$error; |
547 | - } |
|
548 | - else |
|
561 | + } else |
|
549 | 562 | { |
550 | 563 | $this->db->commit(); |
551 | 564 | return 1; |
@@ -599,8 +612,7 @@ discard block |
||
599 | 612 | { |
600 | 613 | $this->db->commit(); |
601 | 614 | return $object->id; |
602 | - } |
|
603 | - else |
|
615 | + } else |
|
604 | 616 | { |
605 | 617 | $this->db->rollback(); |
606 | 618 | return -1; |
@@ -47,28 +47,28 @@ discard block |
||
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Constructor |
|
52 | - * |
|
53 | - * @param DoliDb $db Database handler |
|
54 | - */ |
|
55 | - function __construct($db) |
|
56 | - { |
|
57 | - $this->db = $db; |
|
58 | - return 1; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Create object into database |
|
64 | - * |
|
65 | - * @param User $user User that creates |
|
66 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
67 | - * @return int <0 if KO, Id of created object if OK |
|
68 | - */ |
|
69 | - function create($user, $notrigger=0) |
|
70 | - { |
|
71 | - global $conf, $langs; |
|
50 | + /** |
|
51 | + * Constructor |
|
52 | + * |
|
53 | + * @param DoliDb $db Database handler |
|
54 | + */ |
|
55 | + function __construct($db) |
|
56 | + { |
|
57 | + $this->db = $db; |
|
58 | + return 1; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Create object into database |
|
64 | + * |
|
65 | + * @param User $user User that creates |
|
66 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
67 | + * @return int <0 if KO, Id of created object if OK |
|
68 | + */ |
|
69 | + function create($user, $notrigger=0) |
|
70 | + { |
|
71 | + global $conf, $langs; |
|
72 | 72 | $error=0; |
73 | 73 | |
74 | 74 | // Clean parameters |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | // Check parameters |
86 | 86 | // Put here code to add control on parameters values |
87 | 87 | |
88 | - // Insert request |
|
88 | + // Insert request |
|
89 | 89 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal_merge_pdf_product("; |
90 | 90 | |
91 | 91 | $sql.= "fk_product,"; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $sql.= "datec"; |
99 | 99 | |
100 | 100 | |
101 | - $sql.= ") VALUES ("; |
|
101 | + $sql.= ") VALUES ("; |
|
102 | 102 | |
103 | 103 | $sql.= " ".(! isset($this->fk_product)?'NULL':"'".$this->db->escape($this->fk_product)."'").","; |
104 | 104 | $sql.= " ".(! isset($this->file_name)?'NULL':"'".$this->db->escape($this->file_name)."'").","; |
@@ -115,34 +115,34 @@ discard block |
||
115 | 115 | $this->db->begin(); |
116 | 116 | |
117 | 117 | dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
118 | - $resql=$this->db->query($sql); |
|
119 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
118 | + $resql=$this->db->query($sql); |
|
119 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
120 | 120 | |
121 | 121 | if (! $error) |
122 | - { |
|
123 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal_merge_pdf_product"); |
|
122 | + { |
|
123 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal_merge_pdf_product"); |
|
124 | 124 | |
125 | 125 | if (! $notrigger) |
126 | 126 | { |
127 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
128 | - // want this action calls a trigger. |
|
129 | - |
|
130 | - //// Call triggers |
|
131 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
132 | - //$interface=new Interfaces($this->db); |
|
133 | - //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); |
|
134 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
135 | - //// End call triggers |
|
127 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
128 | + // want this action calls a trigger. |
|
129 | + |
|
130 | + //// Call triggers |
|
131 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
132 | + //$interface=new Interfaces($this->db); |
|
133 | + //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); |
|
134 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
135 | + //// End call triggers |
|
136 | 136 | } |
137 | - } |
|
137 | + } |
|
138 | 138 | |
139 | - // Commit or rollback |
|
140 | - if ($error) |
|
139 | + // Commit or rollback |
|
140 | + if ($error) |
|
141 | 141 | { |
142 | 142 | foreach($this->errors as $errmsg) |
143 | 143 | { |
144 | - dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
|
145 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
144 | + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
|
145 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
146 | 146 | } |
147 | 147 | $this->db->rollback(); |
148 | 148 | return -1*$error; |
@@ -150,22 +150,22 @@ discard block |
||
150 | 150 | else |
151 | 151 | { |
152 | 152 | $this->db->commit(); |
153 | - return $this->id; |
|
153 | + return $this->id; |
|
154 | 154 | } |
155 | - } |
|
155 | + } |
|
156 | 156 | |
157 | 157 | |
158 | - /** |
|
159 | - * Load object in memory from the database |
|
160 | - * |
|
161 | - * @param int $id Id object |
|
162 | - * @return int <0 if KO, >0 if OK |
|
163 | - */ |
|
164 | - function fetch($id) |
|
165 | - { |
|
166 | - global $langs,$conf; |
|
158 | + /** |
|
159 | + * Load object in memory from the database |
|
160 | + * |
|
161 | + * @param int $id Id object |
|
162 | + * @return int <0 if KO, >0 if OK |
|
163 | + */ |
|
164 | + function fetch($id) |
|
165 | + { |
|
166 | + global $langs,$conf; |
|
167 | 167 | |
168 | - $sql = "SELECT"; |
|
168 | + $sql = "SELECT"; |
|
169 | 169 | $sql.= " t.rowid,"; |
170 | 170 | |
171 | 171 | $sql.= " t.fk_product,"; |
@@ -178,18 +178,18 @@ discard block |
||
178 | 178 | $sql.= " t.import_key"; |
179 | 179 | |
180 | 180 | |
181 | - $sql.= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; |
|
182 | - $sql.= " WHERE t.rowid = ".$id; |
|
181 | + $sql.= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; |
|
182 | + $sql.= " WHERE t.rowid = ".$id; |
|
183 | 183 | |
184 | - dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
|
185 | - $resql=$this->db->query($sql); |
|
186 | - if ($resql) |
|
187 | - { |
|
188 | - if ($this->db->num_rows($resql)) |
|
189 | - { |
|
190 | - $obj = $this->db->fetch_object($resql); |
|
184 | + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
|
185 | + $resql=$this->db->query($sql); |
|
186 | + if ($resql) |
|
187 | + { |
|
188 | + if ($this->db->num_rows($resql)) |
|
189 | + { |
|
190 | + $obj = $this->db->fetch_object($resql); |
|
191 | 191 | |
192 | - $this->id = $obj->rowid; |
|
192 | + $this->id = $obj->rowid; |
|
193 | 193 | |
194 | 194 | $this->fk_product = $obj->fk_product; |
195 | 195 | $this->file_name = $obj->file_name; |
@@ -203,107 +203,107 @@ discard block |
||
203 | 203 | $this->import_key = $obj->import_key; |
204 | 204 | |
205 | 205 | |
206 | - } |
|
207 | - $this->db->free($resql); |
|
208 | - |
|
209 | - return 1; |
|
210 | - } |
|
211 | - else |
|
212 | - { |
|
213 | - $this->error="Error ".$this->db->lasterror(); |
|
214 | - dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); |
|
215 | - return -1; |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Load object in memory from the database |
|
221 | - * |
|
222 | - * @param int $product_id Id object |
|
223 | - * @param string $lang Lang string code |
|
224 | - * @return int <0 if KO, >0 if OK |
|
225 | - */ |
|
226 | - function fetch_by_product($product_id, $lang='') |
|
227 | - { |
|
228 | - global $langs,$conf; |
|
229 | - |
|
230 | - $sql = "SELECT"; |
|
231 | - $sql.= " t.rowid,"; |
|
232 | - |
|
233 | - $sql.= " t.fk_product,"; |
|
234 | - $sql.= " t.file_name,"; |
|
235 | - $sql.= " t.lang,"; |
|
236 | - $sql.= " t.fk_user_author,"; |
|
237 | - $sql.= " t.fk_user_mod,"; |
|
238 | - $sql.= " t.datec,"; |
|
239 | - $sql.= " t.tms,"; |
|
240 | - $sql.= " t.import_key"; |
|
241 | - |
|
242 | - |
|
243 | - $sql.= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; |
|
244 | - $sql.= " WHERE t.fk_product = ".$product_id; |
|
245 | - if ($conf->global->MAIN_MULTILANGS && !empty($lang)) { |
|
246 | - $sql.= " AND t.lang = '".$lang."'"; |
|
247 | - } |
|
248 | - |
|
249 | - dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
|
250 | - $resql=$this->db->query($sql); |
|
251 | - if ($resql) |
|
252 | - { |
|
253 | - if ($this->db->num_rows($resql)) |
|
254 | - { |
|
255 | - while($obj = $this->db->fetch_object($resql)) { |
|
256 | - |
|
257 | - $line = new PropalmergepdfproductLine(); |
|
258 | - |
|
259 | - $line->id = $obj->rowid; |
|
260 | - |
|
261 | - $line->fk_product = $obj->fk_product; |
|
262 | - $line->file_name = $obj->file_name; |
|
263 | - if ($conf->global->MAIN_MULTILANGS) { |
|
264 | - $line->lang = $obj->lang; |
|
265 | - } |
|
266 | - $line->fk_user_author = $obj->fk_user_author; |
|
267 | - $line->fk_user_mod = $obj->fk_user_mod; |
|
268 | - $line->datec = $this->db->jdate($obj->datec); |
|
269 | - $line->tms = $this->db->jdate($obj->tms); |
|
270 | - $line->import_key = $obj->import_key; |
|
271 | - |
|
272 | - |
|
273 | - if ($conf->global->MAIN_MULTILANGS) { |
|
274 | - $this->lines[$obj->file_name.'_'.$obj->lang]=$line; |
|
275 | - }else { |
|
276 | - $this->lines[$obj->file_name]=$line; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - } |
|
284 | - $this->db->free($resql); |
|
285 | - |
|
286 | - return 1; |
|
287 | - } |
|
288 | - else |
|
289 | - { |
|
290 | - $this->error="Error ".$this->db->lasterror(); |
|
291 | - dol_syslog(get_class($this)."::fetch_by_product ".$this->error, LOG_ERR); |
|
292 | - return -1; |
|
293 | - } |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Update object into database |
|
299 | - * |
|
300 | - * @param User $user User that modifies |
|
301 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
302 | - * @return int <0 if KO, >0 if OK |
|
303 | - */ |
|
304 | - function update($user=0, $notrigger=0) |
|
305 | - { |
|
306 | - global $conf, $langs; |
|
206 | + } |
|
207 | + $this->db->free($resql); |
|
208 | + |
|
209 | + return 1; |
|
210 | + } |
|
211 | + else |
|
212 | + { |
|
213 | + $this->error="Error ".$this->db->lasterror(); |
|
214 | + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); |
|
215 | + return -1; |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Load object in memory from the database |
|
221 | + * |
|
222 | + * @param int $product_id Id object |
|
223 | + * @param string $lang Lang string code |
|
224 | + * @return int <0 if KO, >0 if OK |
|
225 | + */ |
|
226 | + function fetch_by_product($product_id, $lang='') |
|
227 | + { |
|
228 | + global $langs,$conf; |
|
229 | + |
|
230 | + $sql = "SELECT"; |
|
231 | + $sql.= " t.rowid,"; |
|
232 | + |
|
233 | + $sql.= " t.fk_product,"; |
|
234 | + $sql.= " t.file_name,"; |
|
235 | + $sql.= " t.lang,"; |
|
236 | + $sql.= " t.fk_user_author,"; |
|
237 | + $sql.= " t.fk_user_mod,"; |
|
238 | + $sql.= " t.datec,"; |
|
239 | + $sql.= " t.tms,"; |
|
240 | + $sql.= " t.import_key"; |
|
241 | + |
|
242 | + |
|
243 | + $sql.= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; |
|
244 | + $sql.= " WHERE t.fk_product = ".$product_id; |
|
245 | + if ($conf->global->MAIN_MULTILANGS && !empty($lang)) { |
|
246 | + $sql.= " AND t.lang = '".$lang."'"; |
|
247 | + } |
|
248 | + |
|
249 | + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
|
250 | + $resql=$this->db->query($sql); |
|
251 | + if ($resql) |
|
252 | + { |
|
253 | + if ($this->db->num_rows($resql)) |
|
254 | + { |
|
255 | + while($obj = $this->db->fetch_object($resql)) { |
|
256 | + |
|
257 | + $line = new PropalmergepdfproductLine(); |
|
258 | + |
|
259 | + $line->id = $obj->rowid; |
|
260 | + |
|
261 | + $line->fk_product = $obj->fk_product; |
|
262 | + $line->file_name = $obj->file_name; |
|
263 | + if ($conf->global->MAIN_MULTILANGS) { |
|
264 | + $line->lang = $obj->lang; |
|
265 | + } |
|
266 | + $line->fk_user_author = $obj->fk_user_author; |
|
267 | + $line->fk_user_mod = $obj->fk_user_mod; |
|
268 | + $line->datec = $this->db->jdate($obj->datec); |
|
269 | + $line->tms = $this->db->jdate($obj->tms); |
|
270 | + $line->import_key = $obj->import_key; |
|
271 | + |
|
272 | + |
|
273 | + if ($conf->global->MAIN_MULTILANGS) { |
|
274 | + $this->lines[$obj->file_name.'_'.$obj->lang]=$line; |
|
275 | + }else { |
|
276 | + $this->lines[$obj->file_name]=$line; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + } |
|
284 | + $this->db->free($resql); |
|
285 | + |
|
286 | + return 1; |
|
287 | + } |
|
288 | + else |
|
289 | + { |
|
290 | + $this->error="Error ".$this->db->lasterror(); |
|
291 | + dol_syslog(get_class($this)."::fetch_by_product ".$this->error, LOG_ERR); |
|
292 | + return -1; |
|
293 | + } |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Update object into database |
|
299 | + * |
|
300 | + * @param User $user User that modifies |
|
301 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
302 | + * @return int <0 if KO, >0 if OK |
|
303 | + */ |
|
304 | + function update($user=0, $notrigger=0) |
|
305 | + { |
|
306 | + global $conf, $langs; |
|
307 | 307 | $error=0; |
308 | 308 | |
309 | 309 | // Clean parameters |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | // Check parameters |
320 | 320 | // Put here code to add a control on parameters values |
321 | 321 | |
322 | - // Update request |
|
323 | - $sql = "UPDATE ".MAIN_DB_PREFIX."propal_merge_pdf_product SET"; |
|
322 | + // Update request |
|
323 | + $sql = "UPDATE ".MAIN_DB_PREFIX."propal_merge_pdf_product SET"; |
|
324 | 324 | |
325 | 325 | $sql.= " fk_product=".(isset($this->fk_product)?$this->fk_product:"null").","; |
326 | 326 | $sql.= " file_name=".(isset($this->file_name)?"'".$this->db->escape($this->file_name)."'":"null").","; |
@@ -330,37 +330,37 @@ discard block |
||
330 | 330 | $sql.= " fk_user_mod=".$user->id; |
331 | 331 | |
332 | 332 | |
333 | - $sql.= " WHERE rowid=".$this->id; |
|
333 | + $sql.= " WHERE rowid=".$this->id; |
|
334 | 334 | |
335 | 335 | $this->db->begin(); |
336 | 336 | |
337 | 337 | dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
338 | - $resql = $this->db->query($sql); |
|
339 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
338 | + $resql = $this->db->query($sql); |
|
339 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
340 | 340 | |
341 | 341 | if (! $error) |
342 | 342 | { |
343 | 343 | if (! $notrigger) |
344 | 344 | { |
345 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
346 | - // want this action calls a trigger. |
|
347 | - |
|
348 | - //// Call triggers |
|
349 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
350 | - //$interface=new Interfaces($this->db); |
|
351 | - //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); |
|
352 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
353 | - //// End call triggers |
|
354 | - } |
|
345 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
346 | + // want this action calls a trigger. |
|
347 | + |
|
348 | + //// Call triggers |
|
349 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
350 | + //$interface=new Interfaces($this->db); |
|
351 | + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); |
|
352 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
353 | + //// End call triggers |
|
354 | + } |
|
355 | 355 | } |
356 | 356 | |
357 | - // Commit or rollback |
|
357 | + // Commit or rollback |
|
358 | 358 | if ($error) |
359 | 359 | { |
360 | 360 | foreach($this->errors as $errmsg) |
361 | 361 | { |
362 | - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
363 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
362 | + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
363 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
364 | 364 | } |
365 | 365 | $this->db->rollback(); |
366 | 366 | return -1*$error; |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | $this->db->commit(); |
371 | 371 | return 1; |
372 | 372 | } |
373 | - } |
|
373 | + } |
|
374 | 374 | |
375 | 375 | |
376 | 376 | /** |
377 | - * Delete object in database |
|
378 | - * |
|
379 | - * @param User $user User that deletes |
|
380 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
381 | - * @return int <0 if KO, >0 if OK |
|
382 | - */ |
|
377 | + * Delete object in database |
|
378 | + * |
|
379 | + * @param User $user User that deletes |
|
380 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
381 | + * @return int <0 if KO, >0 if OK |
|
382 | + */ |
|
383 | 383 | function delete($user, $notrigger=0) |
384 | 384 | { |
385 | 385 | global $conf, $langs; |
@@ -392,34 +392,34 @@ discard block |
||
392 | 392 | if (! $notrigger) |
393 | 393 | { |
394 | 394 | // Uncomment this and change MYOBJECT to your own tag if you |
395 | - // want this action calls a trigger. |
|
396 | - |
|
397 | - //// Call triggers |
|
398 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
399 | - //$interface=new Interfaces($this->db); |
|
400 | - //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); |
|
401 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
402 | - //// End call triggers |
|
395 | + // want this action calls a trigger. |
|
396 | + |
|
397 | + //// Call triggers |
|
398 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
399 | + //$interface=new Interfaces($this->db); |
|
400 | + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); |
|
401 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
402 | + //// End call triggers |
|
403 | 403 | } |
404 | 404 | } |
405 | 405 | |
406 | 406 | if (! $error) |
407 | 407 | { |
408 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; |
|
409 | - $sql.= " WHERE rowid=".$this->id; |
|
408 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; |
|
409 | + $sql.= " WHERE rowid=".$this->id; |
|
410 | 410 | |
411 | - dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
|
412 | - $resql = $this->db->query($sql); |
|
413 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
411 | + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
|
412 | + $resql = $this->db->query($sql); |
|
413 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
414 | 414 | } |
415 | 415 | |
416 | - // Commit or rollback |
|
416 | + // Commit or rollback |
|
417 | 417 | if ($error) |
418 | 418 | { |
419 | 419 | foreach($this->errors as $errmsg) |
420 | 420 | { |
421 | - dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
422 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
421 | + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
422 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
423 | 423 | } |
424 | 424 | $this->db->rollback(); |
425 | 425 | return -1*$error; |
@@ -31,18 +31,18 @@ discard block |
||
31 | 31 | */ |
32 | 32 | class Propalmergepdfproduct extends CommonObject |
33 | 33 | { |
34 | - var $element='propal_merge_pdf_product'; //!< Id that identify managed objects |
|
35 | - var $table_element='propal_merge_pdf_product'; //!< Name of table without prefix where object is stored |
|
34 | + var $element = 'propal_merge_pdf_product'; //!< Id that identify managed objects |
|
35 | + var $table_element = 'propal_merge_pdf_product'; //!< Name of table without prefix where object is stored |
|
36 | 36 | |
37 | 37 | var $fk_product; |
38 | 38 | var $file_name; |
39 | 39 | var $fk_user_author; |
40 | 40 | var $fk_user_mod; |
41 | - var $datec=''; |
|
42 | - var $tms=''; |
|
41 | + var $datec = ''; |
|
42 | + var $tms = ''; |
|
43 | 43 | var $lang; |
44 | 44 | |
45 | - var $lines=array(); |
|
45 | + var $lines = array(); |
|
46 | 46 | |
47 | 47 | |
48 | 48 | |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
67 | 67 | * @return int <0 if KO, Id of created object if OK |
68 | 68 | */ |
69 | - function create($user, $notrigger=0) |
|
69 | + function create($user, $notrigger = 0) |
|
70 | 70 | { |
71 | 71 | global $conf, $langs; |
72 | - $error=0; |
|
72 | + $error = 0; |
|
73 | 73 | |
74 | 74 | // Clean parameters |
75 | 75 | |
76 | - if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product); |
|
77 | - if (isset($this->file_name)) $this->file_name=trim($this->file_name); |
|
78 | - if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author); |
|
79 | - if (isset($this->fk_user_mod)) $this->fk_user_mod=trim($this->fk_user_mod); |
|
80 | - if (isset($this->lang)) $this->lang=trim($this->lang); |
|
81 | - if (isset($this->import_key)) $this->import_key=trim($this->import_key); |
|
76 | + if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product); |
|
77 | + if (isset($this->file_name)) $this->file_name = trim($this->file_name); |
|
78 | + if (isset($this->fk_user_author)) $this->fk_user_author = trim($this->fk_user_author); |
|
79 | + if (isset($this->fk_user_mod)) $this->fk_user_mod = trim($this->fk_user_mod); |
|
80 | + if (isset($this->lang)) $this->lang = trim($this->lang); |
|
81 | + if (isset($this->import_key)) $this->import_key = trim($this->import_key); |
|
82 | 82 | |
83 | 83 | |
84 | 84 | |
@@ -88,41 +88,41 @@ discard block |
||
88 | 88 | // Insert request |
89 | 89 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal_merge_pdf_product("; |
90 | 90 | |
91 | - $sql.= "fk_product,"; |
|
92 | - $sql.= "file_name,"; |
|
91 | + $sql .= "fk_product,"; |
|
92 | + $sql .= "file_name,"; |
|
93 | 93 | if ($conf->global->MAIN_MULTILANGS) { |
94 | - $sql.= "lang,"; |
|
94 | + $sql .= "lang,"; |
|
95 | 95 | } |
96 | - $sql.= "fk_user_author,"; |
|
97 | - $sql.= "fk_user_mod,"; |
|
98 | - $sql.= "datec"; |
|
96 | + $sql .= "fk_user_author,"; |
|
97 | + $sql .= "fk_user_mod,"; |
|
98 | + $sql .= "datec"; |
|
99 | 99 | |
100 | 100 | |
101 | - $sql.= ") VALUES ("; |
|
101 | + $sql .= ") VALUES ("; |
|
102 | 102 | |
103 | - $sql.= " ".(! isset($this->fk_product)?'NULL':"'".$this->db->escape($this->fk_product)."'").","; |
|
104 | - $sql.= " ".(! isset($this->file_name)?'NULL':"'".$this->db->escape($this->file_name)."'").","; |
|
103 | + $sql .= " ".(!isset($this->fk_product) ? 'NULL' : "'".$this->db->escape($this->fk_product)."'").","; |
|
104 | + $sql .= " ".(!isset($this->file_name) ? 'NULL' : "'".$this->db->escape($this->file_name)."'").","; |
|
105 | 105 | if ($conf->global->MAIN_MULTILANGS) { |
106 | - $sql.= " ".(! isset($this->lang)?'NULL':"'".$this->db->escape($this->lang)."'").","; |
|
106 | + $sql .= " ".(!isset($this->lang) ? 'NULL' : "'".$this->db->escape($this->lang)."'").","; |
|
107 | 107 | } |
108 | - $sql.= " ".$user->id.","; |
|
109 | - $sql.= " ".$user->id.","; |
|
110 | - $sql.= " '".$this->db->idate(dol_now())."'"; |
|
108 | + $sql .= " ".$user->id.","; |
|
109 | + $sql .= " ".$user->id.","; |
|
110 | + $sql .= " '".$this->db->idate(dol_now())."'"; |
|
111 | 111 | |
112 | 112 | |
113 | - $sql.= ")"; |
|
113 | + $sql .= ")"; |
|
114 | 114 | |
115 | 115 | $this->db->begin(); |
116 | 116 | |
117 | 117 | dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
118 | - $resql=$this->db->query($sql); |
|
119 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
118 | + $resql = $this->db->query($sql); |
|
119 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
120 | 120 | |
121 | - if (! $error) |
|
121 | + if (!$error) |
|
122 | 122 | { |
123 | 123 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal_merge_pdf_product"); |
124 | 124 | |
125 | - if (! $notrigger) |
|
125 | + if (!$notrigger) |
|
126 | 126 | { |
127 | 127 | // Uncomment this and change MYOBJECT to your own tag if you |
128 | 128 | // want this action calls a trigger. |
@@ -139,13 +139,13 @@ discard block |
||
139 | 139 | // Commit or rollback |
140 | 140 | if ($error) |
141 | 141 | { |
142 | - foreach($this->errors as $errmsg) |
|
142 | + foreach ($this->errors as $errmsg) |
|
143 | 143 | { |
144 | 144 | dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
145 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
145 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
146 | 146 | } |
147 | 147 | $this->db->rollback(); |
148 | - return -1*$error; |
|
148 | + return -1 * $error; |
|
149 | 149 | } |
150 | 150 | else |
151 | 151 | { |
@@ -163,33 +163,33 @@ discard block |
||
163 | 163 | */ |
164 | 164 | function fetch($id) |
165 | 165 | { |
166 | - global $langs,$conf; |
|
166 | + global $langs, $conf; |
|
167 | 167 | |
168 | 168 | $sql = "SELECT"; |
169 | - $sql.= " t.rowid,"; |
|
169 | + $sql .= " t.rowid,"; |
|
170 | 170 | |
171 | - $sql.= " t.fk_product,"; |
|
172 | - $sql.= " t.file_name,"; |
|
173 | - $sql.= " t.lang,"; |
|
174 | - $sql.= " t.fk_user_author,"; |
|
175 | - $sql.= " t.fk_user_mod,"; |
|
176 | - $sql.= " t.datec,"; |
|
177 | - $sql.= " t.tms,"; |
|
178 | - $sql.= " t.import_key"; |
|
171 | + $sql .= " t.fk_product,"; |
|
172 | + $sql .= " t.file_name,"; |
|
173 | + $sql .= " t.lang,"; |
|
174 | + $sql .= " t.fk_user_author,"; |
|
175 | + $sql .= " t.fk_user_mod,"; |
|
176 | + $sql .= " t.datec,"; |
|
177 | + $sql .= " t.tms,"; |
|
178 | + $sql .= " t.import_key"; |
|
179 | 179 | |
180 | 180 | |
181 | - $sql.= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; |
|
182 | - $sql.= " WHERE t.rowid = ".$id; |
|
181 | + $sql .= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; |
|
182 | + $sql .= " WHERE t.rowid = ".$id; |
|
183 | 183 | |
184 | 184 | dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
185 | - $resql=$this->db->query($sql); |
|
185 | + $resql = $this->db->query($sql); |
|
186 | 186 | if ($resql) |
187 | 187 | { |
188 | 188 | if ($this->db->num_rows($resql)) |
189 | 189 | { |
190 | 190 | $obj = $this->db->fetch_object($resql); |
191 | 191 | |
192 | - $this->id = $obj->rowid; |
|
192 | + $this->id = $obj->rowid; |
|
193 | 193 | |
194 | 194 | $this->fk_product = $obj->fk_product; |
195 | 195 | $this->file_name = $obj->file_name; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | } |
211 | 211 | else |
212 | 212 | { |
213 | - $this->error="Error ".$this->db->lasterror(); |
|
213 | + $this->error = "Error ".$this->db->lasterror(); |
|
214 | 214 | dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); |
215 | 215 | return -1; |
216 | 216 | } |
@@ -223,40 +223,40 @@ discard block |
||
223 | 223 | * @param string $lang Lang string code |
224 | 224 | * @return int <0 if KO, >0 if OK |
225 | 225 | */ |
226 | - function fetch_by_product($product_id, $lang='') |
|
226 | + function fetch_by_product($product_id, $lang = '') |
|
227 | 227 | { |
228 | - global $langs,$conf; |
|
228 | + global $langs, $conf; |
|
229 | 229 | |
230 | 230 | $sql = "SELECT"; |
231 | - $sql.= " t.rowid,"; |
|
231 | + $sql .= " t.rowid,"; |
|
232 | 232 | |
233 | - $sql.= " t.fk_product,"; |
|
234 | - $sql.= " t.file_name,"; |
|
235 | - $sql.= " t.lang,"; |
|
236 | - $sql.= " t.fk_user_author,"; |
|
237 | - $sql.= " t.fk_user_mod,"; |
|
238 | - $sql.= " t.datec,"; |
|
239 | - $sql.= " t.tms,"; |
|
240 | - $sql.= " t.import_key"; |
|
233 | + $sql .= " t.fk_product,"; |
|
234 | + $sql .= " t.file_name,"; |
|
235 | + $sql .= " t.lang,"; |
|
236 | + $sql .= " t.fk_user_author,"; |
|
237 | + $sql .= " t.fk_user_mod,"; |
|
238 | + $sql .= " t.datec,"; |
|
239 | + $sql .= " t.tms,"; |
|
240 | + $sql .= " t.import_key"; |
|
241 | 241 | |
242 | 242 | |
243 | - $sql.= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; |
|
244 | - $sql.= " WHERE t.fk_product = ".$product_id; |
|
243 | + $sql .= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; |
|
244 | + $sql .= " WHERE t.fk_product = ".$product_id; |
|
245 | 245 | if ($conf->global->MAIN_MULTILANGS && !empty($lang)) { |
246 | - $sql.= " AND t.lang = '".$lang."'"; |
|
246 | + $sql .= " AND t.lang = '".$lang."'"; |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
250 | - $resql=$this->db->query($sql); |
|
250 | + $resql = $this->db->query($sql); |
|
251 | 251 | if ($resql) |
252 | 252 | { |
253 | 253 | if ($this->db->num_rows($resql)) |
254 | 254 | { |
255 | - while($obj = $this->db->fetch_object($resql)) { |
|
255 | + while ($obj = $this->db->fetch_object($resql)) { |
|
256 | 256 | |
257 | 257 | $line = new PropalmergepdfproductLine(); |
258 | 258 | |
259 | - $line->id = $obj->rowid; |
|
259 | + $line->id = $obj->rowid; |
|
260 | 260 | |
261 | 261 | $line->fk_product = $obj->fk_product; |
262 | 262 | $line->file_name = $obj->file_name; |
@@ -271,9 +271,9 @@ discard block |
||
271 | 271 | |
272 | 272 | |
273 | 273 | if ($conf->global->MAIN_MULTILANGS) { |
274 | - $this->lines[$obj->file_name.'_'.$obj->lang]=$line; |
|
275 | - }else { |
|
276 | - $this->lines[$obj->file_name]=$line; |
|
274 | + $this->lines[$obj->file_name.'_'.$obj->lang] = $line; |
|
275 | + } else { |
|
276 | + $this->lines[$obj->file_name] = $line; |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | } |
288 | 288 | else |
289 | 289 | { |
290 | - $this->error="Error ".$this->db->lasterror(); |
|
290 | + $this->error = "Error ".$this->db->lasterror(); |
|
291 | 291 | dol_syslog(get_class($this)."::fetch_by_product ".$this->error, LOG_ERR); |
292 | 292 | return -1; |
293 | 293 | } |
@@ -301,17 +301,17 @@ discard block |
||
301 | 301 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
302 | 302 | * @return int <0 if KO, >0 if OK |
303 | 303 | */ |
304 | - function update($user=0, $notrigger=0) |
|
304 | + function update($user = 0, $notrigger = 0) |
|
305 | 305 | { |
306 | 306 | global $conf, $langs; |
307 | - $error=0; |
|
307 | + $error = 0; |
|
308 | 308 | |
309 | 309 | // Clean parameters |
310 | 310 | |
311 | - if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product); |
|
312 | - if (isset($this->file_name)) $this->file_name=trim($this->file_name); |
|
313 | - if (isset($this->fk_user_mod)) $this->fk_user_mod=trim($this->fk_user_mod); |
|
314 | - if (isset($this->lang)) $this->lang=trim($this->lang); |
|
311 | + if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product); |
|
312 | + if (isset($this->file_name)) $this->file_name = trim($this->file_name); |
|
313 | + if (isset($this->fk_user_mod)) $this->fk_user_mod = trim($this->fk_user_mod); |
|
314 | + if (isset($this->lang)) $this->lang = trim($this->lang); |
|
315 | 315 | |
316 | 316 | |
317 | 317 | |
@@ -322,25 +322,25 @@ discard block |
||
322 | 322 | // Update request |
323 | 323 | $sql = "UPDATE ".MAIN_DB_PREFIX."propal_merge_pdf_product SET"; |
324 | 324 | |
325 | - $sql.= " fk_product=".(isset($this->fk_product)?$this->fk_product:"null").","; |
|
326 | - $sql.= " file_name=".(isset($this->file_name)?"'".$this->db->escape($this->file_name)."'":"null").","; |
|
325 | + $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").","; |
|
326 | + $sql .= " file_name=".(isset($this->file_name) ? "'".$this->db->escape($this->file_name)."'" : "null").","; |
|
327 | 327 | if ($conf->global->MAIN_MULTILANGS) { |
328 | - $sql.= " lang=".(isset($this->lang)?"'".$this->db->escape($this->lang)."'":"null").","; |
|
328 | + $sql .= " lang=".(isset($this->lang) ? "'".$this->db->escape($this->lang)."'" : "null").","; |
|
329 | 329 | } |
330 | - $sql.= " fk_user_mod=".$user->id; |
|
330 | + $sql .= " fk_user_mod=".$user->id; |
|
331 | 331 | |
332 | 332 | |
333 | - $sql.= " WHERE rowid=".$this->id; |
|
333 | + $sql .= " WHERE rowid=".$this->id; |
|
334 | 334 | |
335 | 335 | $this->db->begin(); |
336 | 336 | |
337 | 337 | dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
338 | 338 | $resql = $this->db->query($sql); |
339 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
339 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
340 | 340 | |
341 | - if (! $error) |
|
341 | + if (!$error) |
|
342 | 342 | { |
343 | - if (! $notrigger) |
|
343 | + if (!$notrigger) |
|
344 | 344 | { |
345 | 345 | // Uncomment this and change MYOBJECT to your own tag if you |
346 | 346 | // want this action calls a trigger. |
@@ -357,13 +357,13 @@ discard block |
||
357 | 357 | // Commit or rollback |
358 | 358 | if ($error) |
359 | 359 | { |
360 | - foreach($this->errors as $errmsg) |
|
360 | + foreach ($this->errors as $errmsg) |
|
361 | 361 | { |
362 | 362 | dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
363 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
363 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
364 | 364 | } |
365 | 365 | $this->db->rollback(); |
366 | - return -1*$error; |
|
366 | + return -1 * $error; |
|
367 | 367 | } |
368 | 368 | else |
369 | 369 | { |
@@ -380,16 +380,16 @@ discard block |
||
380 | 380 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
381 | 381 | * @return int <0 if KO, >0 if OK |
382 | 382 | */ |
383 | - function delete($user, $notrigger=0) |
|
383 | + function delete($user, $notrigger = 0) |
|
384 | 384 | { |
385 | 385 | global $conf, $langs; |
386 | - $error=0; |
|
386 | + $error = 0; |
|
387 | 387 | |
388 | 388 | $this->db->begin(); |
389 | 389 | |
390 | - if (! $error) |
|
390 | + if (!$error) |
|
391 | 391 | { |
392 | - if (! $notrigger) |
|
392 | + if (!$notrigger) |
|
393 | 393 | { |
394 | 394 | // Uncomment this and change MYOBJECT to your own tag if you |
395 | 395 | // want this action calls a trigger. |
@@ -403,26 +403,26 @@ discard block |
||
403 | 403 | } |
404 | 404 | } |
405 | 405 | |
406 | - if (! $error) |
|
406 | + if (!$error) |
|
407 | 407 | { |
408 | 408 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; |
409 | - $sql.= " WHERE rowid=".$this->id; |
|
409 | + $sql .= " WHERE rowid=".$this->id; |
|
410 | 410 | |
411 | 411 | dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
412 | 412 | $resql = $this->db->query($sql); |
413 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
413 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | // Commit or rollback |
417 | 417 | if ($error) |
418 | 418 | { |
419 | - foreach($this->errors as $errmsg) |
|
419 | + foreach ($this->errors as $errmsg) |
|
420 | 420 | { |
421 | 421 | dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
422 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
422 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
423 | 423 | } |
424 | 424 | $this->db->rollback(); |
425 | - return -1*$error; |
|
425 | + return -1 * $error; |
|
426 | 426 | } |
427 | 427 | else |
428 | 428 | { |
@@ -440,16 +440,16 @@ discard block |
||
440 | 440 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
441 | 441 | * @return int <0 if KO, >0 if OK |
442 | 442 | */ |
443 | - function delete_by_product($user, $product_id, $lang_id='', $notrigger=0) |
|
443 | + function delete_by_product($user, $product_id, $lang_id = '', $notrigger = 0) |
|
444 | 444 | { |
445 | 445 | global $conf, $langs; |
446 | - $error=0; |
|
446 | + $error = 0; |
|
447 | 447 | |
448 | 448 | $this->db->begin(); |
449 | 449 | |
450 | - if (! $error) |
|
450 | + if (!$error) |
|
451 | 451 | { |
452 | - if (! $notrigger) |
|
452 | + if (!$notrigger) |
|
453 | 453 | { |
454 | 454 | // Uncomment this and change MYOBJECT to your own tag if you |
455 | 455 | // want this action calls a trigger. |
@@ -463,30 +463,30 @@ discard block |
||
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
466 | - if (! $error) |
|
466 | + if (!$error) |
|
467 | 467 | { |
468 | 468 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; |
469 | - $sql.= " WHERE fk_product=".$product_id; |
|
469 | + $sql .= " WHERE fk_product=".$product_id; |
|
470 | 470 | |
471 | 471 | if ($conf->global->MAIN_MULTILANGS && !empty($lang_id)) { |
472 | - $sql.= " AND lang='".$lang_id."'"; |
|
472 | + $sql .= " AND lang='".$lang_id."'"; |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
476 | 476 | $resql = $this->db->query($sql); |
477 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
477 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | // Commit or rollback |
481 | 481 | if ($error) |
482 | 482 | { |
483 | - foreach($this->errors as $errmsg) |
|
483 | + foreach ($this->errors as $errmsg) |
|
484 | 484 | { |
485 | 485 | dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
486 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
486 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
487 | 487 | } |
488 | 488 | $this->db->rollback(); |
489 | - return -1*$error; |
|
489 | + return -1 * $error; |
|
490 | 490 | } |
491 | 491 | else |
492 | 492 | { |
@@ -504,13 +504,13 @@ discard block |
||
504 | 504 | function delete_by_file($user) |
505 | 505 | { |
506 | 506 | global $conf, $langs; |
507 | - $error=0; |
|
507 | + $error = 0; |
|
508 | 508 | |
509 | 509 | $this->db->begin(); |
510 | 510 | |
511 | - if (! $error) |
|
511 | + if (!$error) |
|
512 | 512 | { |
513 | - if (! $notrigger) |
|
513 | + if (!$notrigger) |
|
514 | 514 | { |
515 | 515 | // Uncomment this and change MYOBJECT to your own tag if you |
516 | 516 | // want this action calls a trigger. |
@@ -524,26 +524,26 @@ discard block |
||
524 | 524 | } |
525 | 525 | } |
526 | 526 | |
527 | - if (! $error) |
|
527 | + if (!$error) |
|
528 | 528 | { |
529 | 529 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; |
530 | - $sql.= " WHERE fk_product=".$this->fk_product." AND file_name='".$this->db->escape($this->file_name)."'"; |
|
530 | + $sql .= " WHERE fk_product=".$this->fk_product." AND file_name='".$this->db->escape($this->file_name)."'"; |
|
531 | 531 | |
532 | 532 | dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
533 | 533 | $resql = $this->db->query($sql); |
534 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
534 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | // Commit or rollback |
538 | 538 | if ($error) |
539 | 539 | { |
540 | - foreach($this->errors as $errmsg) |
|
540 | + foreach ($this->errors as $errmsg) |
|
541 | 541 | { |
542 | 542 | dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
543 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
543 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
544 | 544 | } |
545 | 545 | $this->db->rollback(); |
546 | - return -1*$error; |
|
546 | + return -1 * $error; |
|
547 | 547 | } |
548 | 548 | else |
549 | 549 | { |
@@ -562,40 +562,40 @@ discard block |
||
562 | 562 | */ |
563 | 563 | function createFromClone($fromid) |
564 | 564 | { |
565 | - global $user,$langs; |
|
565 | + global $user, $langs; |
|
566 | 566 | |
567 | - $error=0; |
|
567 | + $error = 0; |
|
568 | 568 | |
569 | - $object=new Propalmergepdfproduct($this->db); |
|
569 | + $object = new Propalmergepdfproduct($this->db); |
|
570 | 570 | |
571 | 571 | $this->db->begin(); |
572 | 572 | |
573 | 573 | // Load source object |
574 | 574 | $object->fetch($fromid); |
575 | - $object->id=0; |
|
576 | - $object->statut=0; |
|
575 | + $object->id = 0; |
|
576 | + $object->statut = 0; |
|
577 | 577 | |
578 | 578 | // Clear fields |
579 | 579 | // ... |
580 | 580 | |
581 | 581 | // Create clone |
582 | - $result=$object->create($user); |
|
582 | + $result = $object->create($user); |
|
583 | 583 | |
584 | 584 | // Other options |
585 | 585 | if ($result < 0) |
586 | 586 | { |
587 | - $this->error=$object->error; |
|
587 | + $this->error = $object->error; |
|
588 | 588 | $error++; |
589 | 589 | } |
590 | 590 | |
591 | - if (! $error) |
|
591 | + if (!$error) |
|
592 | 592 | { |
593 | 593 | |
594 | 594 | |
595 | 595 | } |
596 | 596 | |
597 | 597 | // End |
598 | - if (! $error) |
|
598 | + if (!$error) |
|
599 | 599 | { |
600 | 600 | $this->db->commit(); |
601 | 601 | return $object->id; |
@@ -616,15 +616,15 @@ discard block |
||
616 | 616 | */ |
617 | 617 | function initAsSpecimen() |
618 | 618 | { |
619 | - $this->id=0; |
|
619 | + $this->id = 0; |
|
620 | 620 | |
621 | - $this->fk_product=''; |
|
622 | - $this->file_name=''; |
|
623 | - $this->fk_user_author=''; |
|
624 | - $this->fk_user_mod=''; |
|
625 | - $this->datec=''; |
|
626 | - $this->tms=''; |
|
627 | - $this->import_key=''; |
|
621 | + $this->fk_product = ''; |
|
622 | + $this->file_name = ''; |
|
623 | + $this->fk_user_author = ''; |
|
624 | + $this->fk_user_mod = ''; |
|
625 | + $this->datec = ''; |
|
626 | + $this->tms = ''; |
|
627 | + $this->import_key = ''; |
|
628 | 628 | |
629 | 629 | |
630 | 630 | } |
@@ -643,8 +643,8 @@ discard block |
||
643 | 643 | var $lang; |
644 | 644 | var $fk_user_author; |
645 | 645 | var $fk_user_mod; |
646 | - var $datec=''; |
|
647 | - var $tms=''; |
|
646 | + var $datec = ''; |
|
647 | + var $tms = ''; |
|
648 | 648 | var $import_key; |
649 | 649 | |
650 | 650 | function __construct() { |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | /** |
169 | 169 | * Update object into database |
170 | 170 | * |
171 | - * @param User $user User that modifies |
|
171 | + * @param integer $user User that modifies |
|
172 | 172 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
173 | 173 | * @return int <0 if KO, >0 if OK |
174 | 174 | */ |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | * Update next_update into database |
540 | 540 | * |
541 | 541 | * @param string $next_update Next update to write |
542 | - * @param User $user User that modifies |
|
542 | + * @param integer $user User that modifies |
|
543 | 543 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
544 | 544 | * @return int <0 if KO, >0 if OK |
545 | 545 | */ |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | * Update last_status into database |
584 | 584 | * |
585 | 585 | * @param string $last_status Status to write |
586 | - * @param User $user User that modifies |
|
586 | + * @param integer $user User that modifies |
|
587 | 587 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
588 | 588 | * @return int <0 if KO, >0 if OK |
589 | 589 | */ |
@@ -114,8 +114,7 @@ discard block |
||
114 | 114 | } |
115 | 115 | $this->db->rollback(); |
116 | 116 | return -1*$error; |
117 | - } |
|
118 | - else |
|
117 | + } else |
|
119 | 118 | { |
120 | 119 | $this->db->commit(); |
121 | 120 | return $this->id; |
@@ -152,13 +151,11 @@ discard block |
||
152 | 151 | $this->last_status = $obj->last_status; |
153 | 152 | $this->checkParameters(); |
154 | 153 | return 1; |
155 | - } |
|
156 | - else |
|
154 | + } else |
|
157 | 155 | { |
158 | 156 | return 0; |
159 | 157 | } |
160 | - } |
|
161 | - else |
|
158 | + } else |
|
162 | 159 | { |
163 | 160 | $this->error="Error ".$this->db->lasterror(); |
164 | 161 | return -1; |
@@ -219,8 +216,7 @@ discard block |
||
219 | 216 | } |
220 | 217 | $this->db->rollback(); |
221 | 218 | return -1*$error; |
222 | - } |
|
223 | - else |
|
219 | + } else |
|
224 | 220 | { |
225 | 221 | $this->db->commit(); |
226 | 222 | return 1; |
@@ -275,8 +271,7 @@ discard block |
||
275 | 271 | } |
276 | 272 | $this->db->rollback(); |
277 | 273 | return -1*$error; |
278 | - } |
|
279 | - else |
|
274 | + } else |
|
280 | 275 | { |
281 | 276 | $this->db->commit(); |
282 | 277 | return 1; |
@@ -325,15 +320,28 @@ discard block |
||
325 | 320 | function checkParameters() |
326 | 321 | { |
327 | 322 | // Clean parameters |
328 | - if (isset($this->description)) $this->description=trim($this->description); |
|
329 | - if (isset($this->parameters)) $this->parameters=trim($this->parameters); |
|
330 | - else $this->parameters=""; |
|
331 | - if (isset($this->last_status)) $this->last_status=trim($this->last_status); |
|
323 | + if (isset($this->description)) { |
|
324 | + $this->description=trim($this->description); |
|
325 | + } |
|
326 | + if (isset($this->parameters)) { |
|
327 | + $this->parameters=trim($this->parameters); |
|
328 | + } else { |
|
329 | + $this->parameters=""; |
|
330 | + } |
|
331 | + if (isset($this->last_status)) { |
|
332 | + $this->last_status=trim($this->last_status); |
|
333 | + } |
|
332 | 334 | |
333 | 335 | // Check parameters |
334 | - if (empty($this->type) || !is_numeric($this->type) || !in_array($this->type, $this->types)) $this->type=0; |
|
335 | - if (empty($this->update_interval) || !is_numeric($this->update_interval) || $this->update_interval < 1) $this->update_interval=$this->update_min; |
|
336 | - if (empty($this->next_update) || !is_numeric($this->next_update) || $this->next_update < 0) $this->next_update=0; |
|
336 | + if (empty($this->type) || !is_numeric($this->type) || !in_array($this->type, $this->types)) { |
|
337 | + $this->type=0; |
|
338 | + } |
|
339 | + if (empty($this->update_interval) || !is_numeric($this->update_interval) || $this->update_interval < 1) { |
|
340 | + $this->update_interval=$this->update_min; |
|
341 | + } |
|
342 | + if (empty($this->next_update) || !is_numeric($this->next_update) || $this->next_update < 0) { |
|
343 | + $this->next_update=0; |
|
344 | + } |
|
337 | 345 | } |
338 | 346 | |
339 | 347 | /** |
@@ -369,8 +377,7 @@ discard block |
||
369 | 377 | |
370 | 378 | $this->db->free($resql); |
371 | 379 | return $retarray; |
372 | - } |
|
373 | - else |
|
380 | + } else |
|
374 | 381 | { |
375 | 382 | $this->error=$this->db->error(); |
376 | 383 | return -1; |
@@ -411,8 +418,7 @@ discard block |
||
411 | 418 | |
412 | 419 | $this->db->free($resql); |
413 | 420 | return $retarray; |
414 | - } |
|
415 | - else |
|
421 | + } else |
|
416 | 422 | { |
417 | 423 | $this->error=$this->db->error(); |
418 | 424 | return -1; |
@@ -565,8 +571,7 @@ discard block |
||
565 | 571 | } |
566 | 572 | $this->db->rollback(); |
567 | 573 | return -1*$error; |
568 | - } |
|
569 | - else |
|
574 | + } else |
|
570 | 575 | { |
571 | 576 | $this->db->commit(); |
572 | 577 | return 1; |
@@ -609,8 +614,7 @@ discard block |
||
609 | 614 | } |
610 | 615 | $this->db->rollback(); |
611 | 616 | return -1*$error; |
612 | - } |
|
613 | - else |
|
617 | + } else |
|
614 | 618 | { |
615 | 619 | $this->db->commit(); |
616 | 620 | return 1; |
@@ -29,592 +29,592 @@ |
||
29 | 29 | */ |
30 | 30 | class PriceGlobalVariableUpdater |
31 | 31 | { |
32 | - var $db; //!< To store db handler |
|
33 | - var $error; //!< To return error code (or message) |
|
34 | - var $errors=array(); //!< To return several error codes (or messages) |
|
35 | - var $types=array(0, 1); //!< Updater types |
|
36 | - var $update_min = 5; //!< Minimal update rate |
|
37 | - var $id; |
|
38 | - var $type; |
|
39 | - var $description; |
|
40 | - var $parameters; |
|
41 | - var $fk_variable; |
|
42 | - var $update_interval; //!< Interval in mins |
|
43 | - var $next_update; //!< Next update timestamp |
|
44 | - var $last_status; |
|
45 | - public $table_element = "c_price_global_variable_updater"; |
|
46 | - |
|
47 | - /** |
|
48 | - * Constructor |
|
49 | - * |
|
50 | - * @param DoliDb $db Database handler |
|
51 | - */ |
|
52 | - function __construct($db) |
|
53 | - { |
|
54 | - $this->db = $db; |
|
55 | - return 1; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Create object into database |
|
61 | - * |
|
62 | - * @param User $user User that creates |
|
63 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
64 | - * @return int <0 if KO, Id of created object if OK |
|
65 | - */ |
|
66 | - function create($user, $notrigger=0) |
|
67 | - { |
|
68 | - $error=0; |
|
69 | - |
|
70 | - $this->checkParameters(); |
|
71 | - |
|
72 | - // Insert request |
|
73 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; |
|
74 | - $sql.= "type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
|
75 | - $sql.= ") VALUES ("; |
|
76 | - $sql.= " ".$this->type.","; |
|
77 | - $sql.= " ".(isset($this->description)?"'".$this->db->escape($this->description)."'":"''").","; |
|
78 | - $sql.= " ".(isset($this->parameters)?"'".$this->db->escape($this->parameters)."'":"''").","; |
|
79 | - $sql.= " ".$this->fk_variable.","; |
|
80 | - $sql.= " ".$this->update_interval.","; |
|
81 | - $sql.= " ".$this->next_update.","; |
|
82 | - $sql.= " ".(isset($this->last_status)?"'".$this->db->escape($this->last_status)."'":"''"); |
|
83 | - $sql.= ")"; |
|
84 | - |
|
85 | - $this->db->begin(); |
|
86 | - |
|
87 | - dol_syslog(__METHOD__, LOG_DEBUG); |
|
88 | - $resql=$this->db->query($sql); |
|
89 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
90 | - |
|
91 | - if (! $error) |
|
92 | - { |
|
93 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
|
94 | - |
|
95 | - if (! $notrigger) |
|
96 | - { |
|
97 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
98 | - // want this action calls a trigger. |
|
99 | - |
|
100 | - //// Call triggers |
|
101 | - //$result=$this->call_trigger('MYOBJECT_CREATE',$user); |
|
102 | - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} |
|
103 | - //// End call triggers |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - // Commit or rollback |
|
108 | - if ($error) |
|
109 | - { |
|
110 | - foreach($this->errors as $errmsg) |
|
111 | - { |
|
112 | - dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
|
113 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
114 | - } |
|
115 | - $this->db->rollback(); |
|
116 | - return -1*$error; |
|
117 | - } |
|
118 | - else |
|
119 | - { |
|
120 | - $this->db->commit(); |
|
121 | - return $this->id; |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Load object in memory from the database |
|
128 | - * |
|
129 | - * @param int $id Id object |
|
130 | - * @return int < 0 if KO, 0 if OK but not found, > 0 if OK |
|
131 | - */ |
|
132 | - function fetch($id) |
|
133 | - { |
|
134 | - $sql = "SELECT type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
|
135 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
136 | - $sql.= " WHERE rowid = ".$id; |
|
137 | - |
|
138 | - dol_syslog(__METHOD__); |
|
139 | - $resql=$this->db->query($sql); |
|
140 | - if ($resql) |
|
141 | - { |
|
142 | - $obj = $this->db->fetch_object($resql); |
|
143 | - if ($obj) |
|
144 | - { |
|
145 | - $this->id = $id; |
|
146 | - $this->type = $obj->type; |
|
147 | - $this->description = $obj->description; |
|
148 | - $this->parameters = $obj->parameters; |
|
149 | - $this->fk_variable = $obj->fk_variable; |
|
150 | - $this->update_interval = $obj->update_interval; |
|
151 | - $this->next_update = $obj->next_update; |
|
152 | - $this->last_status = $obj->last_status; |
|
153 | - $this->checkParameters(); |
|
154 | - return 1; |
|
155 | - } |
|
156 | - else |
|
157 | - { |
|
158 | - return 0; |
|
159 | - } |
|
160 | - } |
|
161 | - else |
|
162 | - { |
|
163 | - $this->error="Error ".$this->db->lasterror(); |
|
164 | - return -1; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Update object into database |
|
170 | - * |
|
171 | - * @param User $user User that modifies |
|
172 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
173 | - * @return int <0 if KO, >0 if OK |
|
174 | - */ |
|
175 | - function update($user=0, $notrigger=0) |
|
176 | - { |
|
177 | - $error=0; |
|
178 | - |
|
179 | - $this->checkParameters(); |
|
180 | - |
|
181 | - // Update request |
|
182 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; |
|
183 | - $sql.= " type = ".$this->type.","; |
|
184 | - $sql.= " description = ".(isset($this->description)?"'".$this->db->escape($this->description)."'":"''").","; |
|
185 | - $sql.= " parameters = ".(isset($this->parameters)?"'".$this->db->escape($this->parameters)."'":"''").","; |
|
186 | - $sql.= " fk_variable = ".$this->fk_variable.","; |
|
187 | - $sql.= " update_interval = ".$this->update_interval.","; |
|
188 | - $sql.= " next_update = ".$this->next_update.","; |
|
189 | - $sql.= " last_status = ".(isset($this->last_status)?"'".$this->db->escape($this->last_status)."'":"''"); |
|
190 | - $sql.= " WHERE rowid = ".$this->id; |
|
191 | - |
|
192 | - $this->db->begin(); |
|
193 | - |
|
194 | - dol_syslog(__METHOD__); |
|
195 | - $resql = $this->db->query($sql); |
|
196 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
197 | - |
|
198 | - if (! $error) |
|
199 | - { |
|
200 | - if (! $notrigger) |
|
201 | - { |
|
202 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
203 | - // want this action calls a trigger. |
|
204 | - |
|
205 | - //// Call triggers |
|
206 | - //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); |
|
207 | - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} |
|
208 | - //// End call triggers |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - // Commit or rollback |
|
213 | - if ($error) |
|
214 | - { |
|
215 | - foreach($this->errors as $errmsg) |
|
216 | - { |
|
217 | - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
218 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
219 | - } |
|
220 | - $this->db->rollback(); |
|
221 | - return -1*$error; |
|
222 | - } |
|
223 | - else |
|
224 | - { |
|
225 | - $this->db->commit(); |
|
226 | - return 1; |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Delete object in database |
|
232 | - * |
|
233 | - * @param int $rowid Row id of global variable |
|
234 | - * @param User $user User that deletes |
|
235 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
236 | - * @return int <0 if KO, >0 if OK |
|
237 | - */ |
|
238 | - function delete($rowid, $user, $notrigger=0) |
|
239 | - { |
|
240 | - $error=0; |
|
241 | - |
|
242 | - $this->db->begin(); |
|
243 | - |
|
244 | - if (! $error) |
|
245 | - { |
|
246 | - if (! $notrigger) |
|
247 | - { |
|
248 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
249 | - // want this action calls a trigger. |
|
250 | - |
|
251 | - //// Call triggers |
|
252 | - //$result=$this->call_trigger('MYOBJECT_DELETE',$user); |
|
253 | - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} |
|
254 | - //// End call triggers |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - if (! $error) |
|
259 | - { |
|
260 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
261 | - $sql.= " WHERE rowid = ".$rowid; |
|
262 | - |
|
263 | - dol_syslog(__METHOD__); |
|
264 | - $resql = $this->db->query($sql); |
|
265 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
266 | - } |
|
267 | - |
|
268 | - // Commit or rollback |
|
269 | - if ($error) |
|
270 | - { |
|
271 | - foreach($this->errors as $errmsg) |
|
272 | - { |
|
273 | - dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
|
274 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
275 | - } |
|
276 | - $this->db->rollback(); |
|
277 | - return -1*$error; |
|
278 | - } |
|
279 | - else |
|
280 | - { |
|
281 | - $this->db->commit(); |
|
282 | - return 1; |
|
283 | - } |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Initialise object with example values |
|
288 | - * Id must be 0 if object instance is a specimen |
|
289 | - * |
|
290 | - * @return void |
|
291 | - */ |
|
292 | - function initAsSpecimen() |
|
293 | - { |
|
294 | - $this->id=0; |
|
295 | - $this->type=0; |
|
296 | - $this->description=''; |
|
297 | - $this->parameters=''; |
|
298 | - $this->fk_variable=0; |
|
299 | - $this->update_interval=0; |
|
300 | - $this->next_update=0; |
|
301 | - $this->last_status=''; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Returns the last updated time in string html format, returns "never" if its less than 1 |
|
306 | - * |
|
307 | - * @return string |
|
308 | - */ |
|
309 | - function getLastUpdated() |
|
310 | - { |
|
311 | - global $langs; |
|
312 | - $last = $this->next_update - ($this->update_interval * 60); |
|
313 | - if ($last < 1) { |
|
314 | - return $langs->trans("Never"); |
|
315 | - } |
|
316 | - $status = empty($this->last_status) ? $langs->trans("CorrectlyUpdated") : $this->last_status; |
|
317 | - return $status.'<br>'.dol_print_date($last, '%d/%m/%Y %H:%M:%S'); |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Checks if all parameters are in order |
|
322 | - * |
|
323 | - * @return void |
|
324 | - */ |
|
325 | - function checkParameters() |
|
326 | - { |
|
327 | - // Clean parameters |
|
328 | - if (isset($this->description)) $this->description=trim($this->description); |
|
329 | - if (isset($this->parameters)) $this->parameters=trim($this->parameters); |
|
330 | - else $this->parameters=""; |
|
331 | - if (isset($this->last_status)) $this->last_status=trim($this->last_status); |
|
332 | - |
|
333 | - // Check parameters |
|
334 | - if (empty($this->type) || !is_numeric($this->type) || !in_array($this->type, $this->types)) $this->type=0; |
|
335 | - if (empty($this->update_interval) || !is_numeric($this->update_interval) || $this->update_interval < 1) $this->update_interval=$this->update_min; |
|
336 | - if (empty($this->next_update) || !is_numeric($this->next_update) || $this->next_update < 0) $this->next_update=0; |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * List all price global variables |
|
341 | - * |
|
342 | - * @return array Array of price global variable updaters |
|
343 | - */ |
|
344 | - function listUpdaters() |
|
345 | - { |
|
346 | - $sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
|
347 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
348 | - |
|
349 | - dol_syslog(__METHOD__, LOG_DEBUG); |
|
350 | - $resql=$this->db->query($sql); |
|
351 | - if ($resql) |
|
352 | - { |
|
353 | - $retarray = array(); |
|
354 | - |
|
355 | - while ($record = $this->db->fetch_array($resql)) |
|
356 | - { |
|
357 | - $updater_obj = new PriceGlobalVariableUpdater($this->db); |
|
358 | - $updater_obj->id = $record["rowid"]; |
|
359 | - $updater_obj->type = $record["type"]; |
|
360 | - $updater_obj->description = $record["description"]; |
|
361 | - $updater_obj->parameters = $record["parameters"]; |
|
362 | - $updater_obj->fk_variable = $record["fk_variable"]; |
|
363 | - $updater_obj->update_interval = $record["update_interval"]; |
|
364 | - $updater_obj->next_update = $record["next_update"]; |
|
365 | - $updater_obj->last_status = $record["last_status"]; |
|
366 | - $updater_obj->checkParameters(); |
|
367 | - $retarray[]=$updater_obj; |
|
368 | - } |
|
369 | - |
|
370 | - $this->db->free($resql); |
|
371 | - return $retarray; |
|
372 | - } |
|
373 | - else |
|
374 | - { |
|
375 | - $this->error=$this->db->error(); |
|
376 | - return -1; |
|
377 | - } |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * List all updaters which need to be processed |
|
382 | - * |
|
383 | - * @return array Array of price global variable updaters |
|
384 | - */ |
|
385 | - function listPendingUpdaters() |
|
386 | - { |
|
387 | - $sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
|
388 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
389 | - $sql.= " WHERE next_update < ".dol_now(); |
|
390 | - |
|
391 | - dol_syslog(__METHOD__, LOG_DEBUG); |
|
392 | - $resql=$this->db->query($sql); |
|
393 | - if ($resql) |
|
394 | - { |
|
395 | - $retarray = array(); |
|
396 | - |
|
397 | - while ($record = $this->db->fetch_array($resql)) |
|
398 | - { |
|
399 | - $updater_obj = new PriceGlobalVariableUpdater($this->db); |
|
400 | - $updater_obj->id = $record["rowid"]; |
|
401 | - $updater_obj->type = $record["type"]; |
|
402 | - $updater_obj->description = $record["description"]; |
|
403 | - $updater_obj->parameters = $record["parameters"]; |
|
404 | - $updater_obj->fk_variable = $record["fk_variable"]; |
|
405 | - $updater_obj->update_interval = $record["update_interval"]; |
|
406 | - $updater_obj->next_update = $record["next_update"]; |
|
407 | - $updater_obj->last_status = $record["last_status"]; |
|
408 | - $updater_obj->checkParameters(); |
|
409 | - $retarray[]=$updater_obj; |
|
410 | - } |
|
411 | - |
|
412 | - $this->db->free($resql); |
|
413 | - return $retarray; |
|
414 | - } |
|
415 | - else |
|
416 | - { |
|
417 | - $this->error=$this->db->error(); |
|
418 | - return -1; |
|
419 | - } |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Handles the processing of this updater |
|
424 | - * |
|
425 | - * @return int <0 if KO, 0 if OK but no global variable found, >0 if OK |
|
426 | - */ |
|
427 | - function process() |
|
428 | - { |
|
429 | - global $langs, $user; |
|
430 | - $langs->load("errors"); |
|
431 | - dol_syslog(__METHOD__, LOG_DEBUG); |
|
432 | - |
|
433 | - $this->error = null; |
|
434 | - $this->checkParameters(); |
|
435 | - |
|
436 | - //Try to load the target global variable and abort if fails |
|
437 | - if ($this->fk_variable < 1) { |
|
438 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater5"); |
|
439 | - return 0; |
|
440 | - } |
|
441 | - $price_globals = new PriceGlobalVariable($this->db); |
|
442 | - $res = $price_globals->fetch($this->fk_variable); |
|
443 | - if ($res < 1) { |
|
444 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater5"); |
|
445 | - return 0; |
|
446 | - } |
|
447 | - |
|
448 | - //Process depending of type |
|
449 | - if ($this->type == 0 || $this->type == 1) { |
|
450 | - //Get and check if required parameters are present |
|
451 | - $parameters = json_decode($this->parameters, true); |
|
452 | - if (!isset($parameters)) { |
|
453 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater1", $this->parameters); |
|
454 | - return -1; |
|
455 | - } |
|
456 | - $url = $parameters['URL']; |
|
457 | - if (!isset($url)) { |
|
458 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'URL'); |
|
459 | - return -1; |
|
460 | - } |
|
461 | - $value = $parameters['VALUE']; |
|
462 | - if (!isset($value)) { |
|
463 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'VALUE'); |
|
464 | - return -1; |
|
465 | - } |
|
466 | - $result = ""; |
|
467 | - if ($this->type == 0) { |
|
468 | - // Call JSON request |
|
469 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; |
|
470 | - $tmpresult=getURLContent($url); |
|
471 | - $code=$tmpresult['http_code']; |
|
472 | - $result=$tmpresult['content']; |
|
473 | - |
|
474 | - if (!isset($result)) { |
|
475 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater0", "empty response"); |
|
476 | - return -1; |
|
477 | - } |
|
478 | - if ($code !== 200) { |
|
479 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater0", $code.' '.$tmpresult['curl_error_msg']); |
|
480 | - return -1; |
|
481 | - } |
|
482 | - |
|
483 | - //Decode returned response |
|
484 | - $result = json_decode($result, true); |
|
485 | - } elseif ($this->type == 1) { |
|
486 | - $ns = $parameters['NS']; |
|
487 | - if (!isset($ns)) { |
|
488 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'NS'); |
|
489 | - return -1; |
|
490 | - } |
|
491 | - $method = $parameters['METHOD']; |
|
492 | - if (!isset($method)) { |
|
493 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'METHOD'); |
|
494 | - return -1; |
|
495 | - } |
|
496 | - $data = $parameters['DATA']; |
|
497 | - if (!isset($data)) { |
|
498 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'DATA'); |
|
499 | - return -1; |
|
500 | - } |
|
501 | - |
|
502 | - //SOAP client |
|
503 | - require_once NUSOAP_PATH.'/nusoap.php'; |
|
504 | - $soap_client = new nusoap_client($url); |
|
505 | - $soap_client->soap_defencoding='UTF-8'; |
|
506 | - $soap_client->decodeUTF8(false); |
|
507 | - $result = $soap_client->call($method, $data, $ns,''); |
|
508 | - |
|
509 | - //Check if result is a error |
|
510 | - if ($result === false) { |
|
511 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater4", $soap_client->error_str); |
|
512 | - return -1; |
|
513 | - } |
|
514 | - } |
|
515 | - |
|
516 | - //Explode value and walk for each key in value array to get the relevant key |
|
517 | - $value = explode(',', $value); |
|
518 | - foreach ($value as $key) { |
|
519 | - $result = $result[$key]; |
|
520 | - } |
|
521 | - if (!isset($result)) { |
|
522 | - $this->error = $langs->trans("ErrorGlobalVariableUpdater3"); |
|
523 | - return -1; |
|
524 | - } |
|
525 | - |
|
526 | - //Save data to global and update it |
|
527 | - $price_globals->value = $result; |
|
528 | - $price_globals->update($user); |
|
529 | - } |
|
530 | - return 1; |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Update next_update into database |
|
535 | - * |
|
536 | - * @param string $next_update Next update to write |
|
537 | - * @param User $user User that modifies |
|
538 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
539 | - * @return int <0 if KO, >0 if OK |
|
540 | - */ |
|
541 | - function update_next_update($next_update, $user=0, $notrigger=0) |
|
542 | - { |
|
543 | - $error=0; |
|
544 | - |
|
545 | - $this->next_update = $next_update; |
|
546 | - $this->checkParameters(); |
|
547 | - |
|
548 | - // Update request |
|
549 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; |
|
550 | - $sql.= " next_update = ".$this->next_update; |
|
551 | - $sql.= " WHERE rowid = ".$this->id; |
|
552 | - |
|
553 | - $this->db->begin(); |
|
554 | - |
|
555 | - dol_syslog(__METHOD__); |
|
556 | - $resql = $this->db->query($sql); |
|
557 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
558 | - |
|
559 | - // Commit or rollback |
|
560 | - if ($error) |
|
561 | - { |
|
562 | - foreach($this->errors as $errmsg) |
|
563 | - { |
|
564 | - dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
|
565 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
566 | - } |
|
567 | - $this->db->rollback(); |
|
568 | - return -1*$error; |
|
569 | - } |
|
570 | - else |
|
571 | - { |
|
572 | - $this->db->commit(); |
|
573 | - return 1; |
|
574 | - } |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Update last_status into database |
|
579 | - * |
|
580 | - * @param string $last_status Status to write |
|
581 | - * @param User $user User that modifies |
|
582 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
583 | - * @return int <0 if KO, >0 if OK |
|
584 | - */ |
|
585 | - function update_status($last_status, $user=0, $notrigger=0) |
|
586 | - { |
|
587 | - $error=0; |
|
588 | - |
|
589 | - $this->last_status = $last_status; |
|
590 | - $this->checkParameters(); |
|
591 | - |
|
592 | - // Update request |
|
593 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; |
|
594 | - $sql.= " last_status = ".(isset($this->last_status)?"'".$this->db->escape($this->last_status)."'":"''"); |
|
595 | - $sql.= " WHERE rowid = ".$this->id; |
|
596 | - |
|
597 | - $this->db->begin(); |
|
598 | - |
|
599 | - dol_syslog(__METHOD__); |
|
600 | - $resql = $this->db->query($sql); |
|
601 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
602 | - |
|
603 | - // Commit or rollback |
|
604 | - if ($error) |
|
605 | - { |
|
606 | - foreach($this->errors as $errmsg) |
|
607 | - { |
|
608 | - dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
|
609 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
610 | - } |
|
611 | - $this->db->rollback(); |
|
612 | - return -1*$error; |
|
613 | - } |
|
614 | - else |
|
615 | - { |
|
616 | - $this->db->commit(); |
|
617 | - return 1; |
|
618 | - } |
|
619 | - } |
|
32 | + var $db; //!< To store db handler |
|
33 | + var $error; //!< To return error code (or message) |
|
34 | + var $errors=array(); //!< To return several error codes (or messages) |
|
35 | + var $types=array(0, 1); //!< Updater types |
|
36 | + var $update_min = 5; //!< Minimal update rate |
|
37 | + var $id; |
|
38 | + var $type; |
|
39 | + var $description; |
|
40 | + var $parameters; |
|
41 | + var $fk_variable; |
|
42 | + var $update_interval; //!< Interval in mins |
|
43 | + var $next_update; //!< Next update timestamp |
|
44 | + var $last_status; |
|
45 | + public $table_element = "c_price_global_variable_updater"; |
|
46 | + |
|
47 | + /** |
|
48 | + * Constructor |
|
49 | + * |
|
50 | + * @param DoliDb $db Database handler |
|
51 | + */ |
|
52 | + function __construct($db) |
|
53 | + { |
|
54 | + $this->db = $db; |
|
55 | + return 1; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Create object into database |
|
61 | + * |
|
62 | + * @param User $user User that creates |
|
63 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
64 | + * @return int <0 if KO, Id of created object if OK |
|
65 | + */ |
|
66 | + function create($user, $notrigger=0) |
|
67 | + { |
|
68 | + $error=0; |
|
69 | + |
|
70 | + $this->checkParameters(); |
|
71 | + |
|
72 | + // Insert request |
|
73 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; |
|
74 | + $sql.= "type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
|
75 | + $sql.= ") VALUES ("; |
|
76 | + $sql.= " ".$this->type.","; |
|
77 | + $sql.= " ".(isset($this->description)?"'".$this->db->escape($this->description)."'":"''").","; |
|
78 | + $sql.= " ".(isset($this->parameters)?"'".$this->db->escape($this->parameters)."'":"''").","; |
|
79 | + $sql.= " ".$this->fk_variable.","; |
|
80 | + $sql.= " ".$this->update_interval.","; |
|
81 | + $sql.= " ".$this->next_update.","; |
|
82 | + $sql.= " ".(isset($this->last_status)?"'".$this->db->escape($this->last_status)."'":"''"); |
|
83 | + $sql.= ")"; |
|
84 | + |
|
85 | + $this->db->begin(); |
|
86 | + |
|
87 | + dol_syslog(__METHOD__, LOG_DEBUG); |
|
88 | + $resql=$this->db->query($sql); |
|
89 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
90 | + |
|
91 | + if (! $error) |
|
92 | + { |
|
93 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
|
94 | + |
|
95 | + if (! $notrigger) |
|
96 | + { |
|
97 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
98 | + // want this action calls a trigger. |
|
99 | + |
|
100 | + //// Call triggers |
|
101 | + //$result=$this->call_trigger('MYOBJECT_CREATE',$user); |
|
102 | + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} |
|
103 | + //// End call triggers |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + // Commit or rollback |
|
108 | + if ($error) |
|
109 | + { |
|
110 | + foreach($this->errors as $errmsg) |
|
111 | + { |
|
112 | + dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
|
113 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
114 | + } |
|
115 | + $this->db->rollback(); |
|
116 | + return -1*$error; |
|
117 | + } |
|
118 | + else |
|
119 | + { |
|
120 | + $this->db->commit(); |
|
121 | + return $this->id; |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Load object in memory from the database |
|
128 | + * |
|
129 | + * @param int $id Id object |
|
130 | + * @return int < 0 if KO, 0 if OK but not found, > 0 if OK |
|
131 | + */ |
|
132 | + function fetch($id) |
|
133 | + { |
|
134 | + $sql = "SELECT type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
|
135 | + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
136 | + $sql.= " WHERE rowid = ".$id; |
|
137 | + |
|
138 | + dol_syslog(__METHOD__); |
|
139 | + $resql=$this->db->query($sql); |
|
140 | + if ($resql) |
|
141 | + { |
|
142 | + $obj = $this->db->fetch_object($resql); |
|
143 | + if ($obj) |
|
144 | + { |
|
145 | + $this->id = $id; |
|
146 | + $this->type = $obj->type; |
|
147 | + $this->description = $obj->description; |
|
148 | + $this->parameters = $obj->parameters; |
|
149 | + $this->fk_variable = $obj->fk_variable; |
|
150 | + $this->update_interval = $obj->update_interval; |
|
151 | + $this->next_update = $obj->next_update; |
|
152 | + $this->last_status = $obj->last_status; |
|
153 | + $this->checkParameters(); |
|
154 | + return 1; |
|
155 | + } |
|
156 | + else |
|
157 | + { |
|
158 | + return 0; |
|
159 | + } |
|
160 | + } |
|
161 | + else |
|
162 | + { |
|
163 | + $this->error="Error ".$this->db->lasterror(); |
|
164 | + return -1; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Update object into database |
|
170 | + * |
|
171 | + * @param User $user User that modifies |
|
172 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
173 | + * @return int <0 if KO, >0 if OK |
|
174 | + */ |
|
175 | + function update($user=0, $notrigger=0) |
|
176 | + { |
|
177 | + $error=0; |
|
178 | + |
|
179 | + $this->checkParameters(); |
|
180 | + |
|
181 | + // Update request |
|
182 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; |
|
183 | + $sql.= " type = ".$this->type.","; |
|
184 | + $sql.= " description = ".(isset($this->description)?"'".$this->db->escape($this->description)."'":"''").","; |
|
185 | + $sql.= " parameters = ".(isset($this->parameters)?"'".$this->db->escape($this->parameters)."'":"''").","; |
|
186 | + $sql.= " fk_variable = ".$this->fk_variable.","; |
|
187 | + $sql.= " update_interval = ".$this->update_interval.","; |
|
188 | + $sql.= " next_update = ".$this->next_update.","; |
|
189 | + $sql.= " last_status = ".(isset($this->last_status)?"'".$this->db->escape($this->last_status)."'":"''"); |
|
190 | + $sql.= " WHERE rowid = ".$this->id; |
|
191 | + |
|
192 | + $this->db->begin(); |
|
193 | + |
|
194 | + dol_syslog(__METHOD__); |
|
195 | + $resql = $this->db->query($sql); |
|
196 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
197 | + |
|
198 | + if (! $error) |
|
199 | + { |
|
200 | + if (! $notrigger) |
|
201 | + { |
|
202 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
203 | + // want this action calls a trigger. |
|
204 | + |
|
205 | + //// Call triggers |
|
206 | + //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); |
|
207 | + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} |
|
208 | + //// End call triggers |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + // Commit or rollback |
|
213 | + if ($error) |
|
214 | + { |
|
215 | + foreach($this->errors as $errmsg) |
|
216 | + { |
|
217 | + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
218 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
219 | + } |
|
220 | + $this->db->rollback(); |
|
221 | + return -1*$error; |
|
222 | + } |
|
223 | + else |
|
224 | + { |
|
225 | + $this->db->commit(); |
|
226 | + return 1; |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Delete object in database |
|
232 | + * |
|
233 | + * @param int $rowid Row id of global variable |
|
234 | + * @param User $user User that deletes |
|
235 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
236 | + * @return int <0 if KO, >0 if OK |
|
237 | + */ |
|
238 | + function delete($rowid, $user, $notrigger=0) |
|
239 | + { |
|
240 | + $error=0; |
|
241 | + |
|
242 | + $this->db->begin(); |
|
243 | + |
|
244 | + if (! $error) |
|
245 | + { |
|
246 | + if (! $notrigger) |
|
247 | + { |
|
248 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
249 | + // want this action calls a trigger. |
|
250 | + |
|
251 | + //// Call triggers |
|
252 | + //$result=$this->call_trigger('MYOBJECT_DELETE',$user); |
|
253 | + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} |
|
254 | + //// End call triggers |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + if (! $error) |
|
259 | + { |
|
260 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
261 | + $sql.= " WHERE rowid = ".$rowid; |
|
262 | + |
|
263 | + dol_syslog(__METHOD__); |
|
264 | + $resql = $this->db->query($sql); |
|
265 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
266 | + } |
|
267 | + |
|
268 | + // Commit or rollback |
|
269 | + if ($error) |
|
270 | + { |
|
271 | + foreach($this->errors as $errmsg) |
|
272 | + { |
|
273 | + dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
|
274 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
275 | + } |
|
276 | + $this->db->rollback(); |
|
277 | + return -1*$error; |
|
278 | + } |
|
279 | + else |
|
280 | + { |
|
281 | + $this->db->commit(); |
|
282 | + return 1; |
|
283 | + } |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Initialise object with example values |
|
288 | + * Id must be 0 if object instance is a specimen |
|
289 | + * |
|
290 | + * @return void |
|
291 | + */ |
|
292 | + function initAsSpecimen() |
|
293 | + { |
|
294 | + $this->id=0; |
|
295 | + $this->type=0; |
|
296 | + $this->description=''; |
|
297 | + $this->parameters=''; |
|
298 | + $this->fk_variable=0; |
|
299 | + $this->update_interval=0; |
|
300 | + $this->next_update=0; |
|
301 | + $this->last_status=''; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Returns the last updated time in string html format, returns "never" if its less than 1 |
|
306 | + * |
|
307 | + * @return string |
|
308 | + */ |
|
309 | + function getLastUpdated() |
|
310 | + { |
|
311 | + global $langs; |
|
312 | + $last = $this->next_update - ($this->update_interval * 60); |
|
313 | + if ($last < 1) { |
|
314 | + return $langs->trans("Never"); |
|
315 | + } |
|
316 | + $status = empty($this->last_status) ? $langs->trans("CorrectlyUpdated") : $this->last_status; |
|
317 | + return $status.'<br>'.dol_print_date($last, '%d/%m/%Y %H:%M:%S'); |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Checks if all parameters are in order |
|
322 | + * |
|
323 | + * @return void |
|
324 | + */ |
|
325 | + function checkParameters() |
|
326 | + { |
|
327 | + // Clean parameters |
|
328 | + if (isset($this->description)) $this->description=trim($this->description); |
|
329 | + if (isset($this->parameters)) $this->parameters=trim($this->parameters); |
|
330 | + else $this->parameters=""; |
|
331 | + if (isset($this->last_status)) $this->last_status=trim($this->last_status); |
|
332 | + |
|
333 | + // Check parameters |
|
334 | + if (empty($this->type) || !is_numeric($this->type) || !in_array($this->type, $this->types)) $this->type=0; |
|
335 | + if (empty($this->update_interval) || !is_numeric($this->update_interval) || $this->update_interval < 1) $this->update_interval=$this->update_min; |
|
336 | + if (empty($this->next_update) || !is_numeric($this->next_update) || $this->next_update < 0) $this->next_update=0; |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * List all price global variables |
|
341 | + * |
|
342 | + * @return array Array of price global variable updaters |
|
343 | + */ |
|
344 | + function listUpdaters() |
|
345 | + { |
|
346 | + $sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
|
347 | + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
348 | + |
|
349 | + dol_syslog(__METHOD__, LOG_DEBUG); |
|
350 | + $resql=$this->db->query($sql); |
|
351 | + if ($resql) |
|
352 | + { |
|
353 | + $retarray = array(); |
|
354 | + |
|
355 | + while ($record = $this->db->fetch_array($resql)) |
|
356 | + { |
|
357 | + $updater_obj = new PriceGlobalVariableUpdater($this->db); |
|
358 | + $updater_obj->id = $record["rowid"]; |
|
359 | + $updater_obj->type = $record["type"]; |
|
360 | + $updater_obj->description = $record["description"]; |
|
361 | + $updater_obj->parameters = $record["parameters"]; |
|
362 | + $updater_obj->fk_variable = $record["fk_variable"]; |
|
363 | + $updater_obj->update_interval = $record["update_interval"]; |
|
364 | + $updater_obj->next_update = $record["next_update"]; |
|
365 | + $updater_obj->last_status = $record["last_status"]; |
|
366 | + $updater_obj->checkParameters(); |
|
367 | + $retarray[]=$updater_obj; |
|
368 | + } |
|
369 | + |
|
370 | + $this->db->free($resql); |
|
371 | + return $retarray; |
|
372 | + } |
|
373 | + else |
|
374 | + { |
|
375 | + $this->error=$this->db->error(); |
|
376 | + return -1; |
|
377 | + } |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * List all updaters which need to be processed |
|
382 | + * |
|
383 | + * @return array Array of price global variable updaters |
|
384 | + */ |
|
385 | + function listPendingUpdaters() |
|
386 | + { |
|
387 | + $sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
|
388 | + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
389 | + $sql.= " WHERE next_update < ".dol_now(); |
|
390 | + |
|
391 | + dol_syslog(__METHOD__, LOG_DEBUG); |
|
392 | + $resql=$this->db->query($sql); |
|
393 | + if ($resql) |
|
394 | + { |
|
395 | + $retarray = array(); |
|
396 | + |
|
397 | + while ($record = $this->db->fetch_array($resql)) |
|
398 | + { |
|
399 | + $updater_obj = new PriceGlobalVariableUpdater($this->db); |
|
400 | + $updater_obj->id = $record["rowid"]; |
|
401 | + $updater_obj->type = $record["type"]; |
|
402 | + $updater_obj->description = $record["description"]; |
|
403 | + $updater_obj->parameters = $record["parameters"]; |
|
404 | + $updater_obj->fk_variable = $record["fk_variable"]; |
|
405 | + $updater_obj->update_interval = $record["update_interval"]; |
|
406 | + $updater_obj->next_update = $record["next_update"]; |
|
407 | + $updater_obj->last_status = $record["last_status"]; |
|
408 | + $updater_obj->checkParameters(); |
|
409 | + $retarray[]=$updater_obj; |
|
410 | + } |
|
411 | + |
|
412 | + $this->db->free($resql); |
|
413 | + return $retarray; |
|
414 | + } |
|
415 | + else |
|
416 | + { |
|
417 | + $this->error=$this->db->error(); |
|
418 | + return -1; |
|
419 | + } |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Handles the processing of this updater |
|
424 | + * |
|
425 | + * @return int <0 if KO, 0 if OK but no global variable found, >0 if OK |
|
426 | + */ |
|
427 | + function process() |
|
428 | + { |
|
429 | + global $langs, $user; |
|
430 | + $langs->load("errors"); |
|
431 | + dol_syslog(__METHOD__, LOG_DEBUG); |
|
432 | + |
|
433 | + $this->error = null; |
|
434 | + $this->checkParameters(); |
|
435 | + |
|
436 | + //Try to load the target global variable and abort if fails |
|
437 | + if ($this->fk_variable < 1) { |
|
438 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater5"); |
|
439 | + return 0; |
|
440 | + } |
|
441 | + $price_globals = new PriceGlobalVariable($this->db); |
|
442 | + $res = $price_globals->fetch($this->fk_variable); |
|
443 | + if ($res < 1) { |
|
444 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater5"); |
|
445 | + return 0; |
|
446 | + } |
|
447 | + |
|
448 | + //Process depending of type |
|
449 | + if ($this->type == 0 || $this->type == 1) { |
|
450 | + //Get and check if required parameters are present |
|
451 | + $parameters = json_decode($this->parameters, true); |
|
452 | + if (!isset($parameters)) { |
|
453 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater1", $this->parameters); |
|
454 | + return -1; |
|
455 | + } |
|
456 | + $url = $parameters['URL']; |
|
457 | + if (!isset($url)) { |
|
458 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'URL'); |
|
459 | + return -1; |
|
460 | + } |
|
461 | + $value = $parameters['VALUE']; |
|
462 | + if (!isset($value)) { |
|
463 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'VALUE'); |
|
464 | + return -1; |
|
465 | + } |
|
466 | + $result = ""; |
|
467 | + if ($this->type == 0) { |
|
468 | + // Call JSON request |
|
469 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; |
|
470 | + $tmpresult=getURLContent($url); |
|
471 | + $code=$tmpresult['http_code']; |
|
472 | + $result=$tmpresult['content']; |
|
473 | + |
|
474 | + if (!isset($result)) { |
|
475 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater0", "empty response"); |
|
476 | + return -1; |
|
477 | + } |
|
478 | + if ($code !== 200) { |
|
479 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater0", $code.' '.$tmpresult['curl_error_msg']); |
|
480 | + return -1; |
|
481 | + } |
|
482 | + |
|
483 | + //Decode returned response |
|
484 | + $result = json_decode($result, true); |
|
485 | + } elseif ($this->type == 1) { |
|
486 | + $ns = $parameters['NS']; |
|
487 | + if (!isset($ns)) { |
|
488 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'NS'); |
|
489 | + return -1; |
|
490 | + } |
|
491 | + $method = $parameters['METHOD']; |
|
492 | + if (!isset($method)) { |
|
493 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'METHOD'); |
|
494 | + return -1; |
|
495 | + } |
|
496 | + $data = $parameters['DATA']; |
|
497 | + if (!isset($data)) { |
|
498 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater2", 'DATA'); |
|
499 | + return -1; |
|
500 | + } |
|
501 | + |
|
502 | + //SOAP client |
|
503 | + require_once NUSOAP_PATH.'/nusoap.php'; |
|
504 | + $soap_client = new nusoap_client($url); |
|
505 | + $soap_client->soap_defencoding='UTF-8'; |
|
506 | + $soap_client->decodeUTF8(false); |
|
507 | + $result = $soap_client->call($method, $data, $ns,''); |
|
508 | + |
|
509 | + //Check if result is a error |
|
510 | + if ($result === false) { |
|
511 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater4", $soap_client->error_str); |
|
512 | + return -1; |
|
513 | + } |
|
514 | + } |
|
515 | + |
|
516 | + //Explode value and walk for each key in value array to get the relevant key |
|
517 | + $value = explode(',', $value); |
|
518 | + foreach ($value as $key) { |
|
519 | + $result = $result[$key]; |
|
520 | + } |
|
521 | + if (!isset($result)) { |
|
522 | + $this->error = $langs->trans("ErrorGlobalVariableUpdater3"); |
|
523 | + return -1; |
|
524 | + } |
|
525 | + |
|
526 | + //Save data to global and update it |
|
527 | + $price_globals->value = $result; |
|
528 | + $price_globals->update($user); |
|
529 | + } |
|
530 | + return 1; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Update next_update into database |
|
535 | + * |
|
536 | + * @param string $next_update Next update to write |
|
537 | + * @param User $user User that modifies |
|
538 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
539 | + * @return int <0 if KO, >0 if OK |
|
540 | + */ |
|
541 | + function update_next_update($next_update, $user=0, $notrigger=0) |
|
542 | + { |
|
543 | + $error=0; |
|
544 | + |
|
545 | + $this->next_update = $next_update; |
|
546 | + $this->checkParameters(); |
|
547 | + |
|
548 | + // Update request |
|
549 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; |
|
550 | + $sql.= " next_update = ".$this->next_update; |
|
551 | + $sql.= " WHERE rowid = ".$this->id; |
|
552 | + |
|
553 | + $this->db->begin(); |
|
554 | + |
|
555 | + dol_syslog(__METHOD__); |
|
556 | + $resql = $this->db->query($sql); |
|
557 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
558 | + |
|
559 | + // Commit or rollback |
|
560 | + if ($error) |
|
561 | + { |
|
562 | + foreach($this->errors as $errmsg) |
|
563 | + { |
|
564 | + dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
|
565 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
566 | + } |
|
567 | + $this->db->rollback(); |
|
568 | + return -1*$error; |
|
569 | + } |
|
570 | + else |
|
571 | + { |
|
572 | + $this->db->commit(); |
|
573 | + return 1; |
|
574 | + } |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Update last_status into database |
|
579 | + * |
|
580 | + * @param string $last_status Status to write |
|
581 | + * @param User $user User that modifies |
|
582 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
583 | + * @return int <0 if KO, >0 if OK |
|
584 | + */ |
|
585 | + function update_status($last_status, $user=0, $notrigger=0) |
|
586 | + { |
|
587 | + $error=0; |
|
588 | + |
|
589 | + $this->last_status = $last_status; |
|
590 | + $this->checkParameters(); |
|
591 | + |
|
592 | + // Update request |
|
593 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; |
|
594 | + $sql.= " last_status = ".(isset($this->last_status)?"'".$this->db->escape($this->last_status)."'":"''"); |
|
595 | + $sql.= " WHERE rowid = ".$this->id; |
|
596 | + |
|
597 | + $this->db->begin(); |
|
598 | + |
|
599 | + dol_syslog(__METHOD__); |
|
600 | + $resql = $this->db->query($sql); |
|
601 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
602 | + |
|
603 | + // Commit or rollback |
|
604 | + if ($error) |
|
605 | + { |
|
606 | + foreach($this->errors as $errmsg) |
|
607 | + { |
|
608 | + dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
|
609 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
610 | + } |
|
611 | + $this->db->rollback(); |
|
612 | + return -1*$error; |
|
613 | + } |
|
614 | + else |
|
615 | + { |
|
616 | + $this->db->commit(); |
|
617 | + return 1; |
|
618 | + } |
|
619 | + } |
|
620 | 620 | } |
@@ -29,18 +29,18 @@ discard block |
||
29 | 29 | */ |
30 | 30 | class PriceGlobalVariableUpdater |
31 | 31 | { |
32 | - var $db; //!< To store db handler |
|
33 | - var $error; //!< To return error code (or message) |
|
34 | - var $errors=array(); //!< To return several error codes (or messages) |
|
35 | - var $types=array(0, 1); //!< Updater types |
|
36 | - var $update_min = 5; //!< Minimal update rate |
|
32 | + var $db; //!< To store db handler |
|
33 | + var $error; //!< To return error code (or message) |
|
34 | + var $errors = array(); //!< To return several error codes (or messages) |
|
35 | + var $types = array(0, 1); //!< Updater types |
|
36 | + var $update_min = 5; //!< Minimal update rate |
|
37 | 37 | var $id; |
38 | 38 | var $type; |
39 | 39 | var $description; |
40 | 40 | var $parameters; |
41 | 41 | var $fk_variable; |
42 | - var $update_interval; //!< Interval in mins |
|
43 | - var $next_update; //!< Next update timestamp |
|
42 | + var $update_interval; //!< Interval in mins |
|
43 | + var $next_update; //!< Next update timestamp |
|
44 | 44 | var $last_status; |
45 | 45 | public $table_element = "c_price_global_variable_updater"; |
46 | 46 | |
@@ -63,36 +63,36 @@ discard block |
||
63 | 63 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
64 | 64 | * @return int <0 if KO, Id of created object if OK |
65 | 65 | */ |
66 | - function create($user, $notrigger=0) |
|
66 | + function create($user, $notrigger = 0) |
|
67 | 67 | { |
68 | - $error=0; |
|
68 | + $error = 0; |
|
69 | 69 | |
70 | 70 | $this->checkParameters(); |
71 | 71 | |
72 | 72 | // Insert request |
73 | 73 | $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; |
74 | - $sql.= "type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
|
75 | - $sql.= ") VALUES ("; |
|
76 | - $sql.= " ".$this->type.","; |
|
77 | - $sql.= " ".(isset($this->description)?"'".$this->db->escape($this->description)."'":"''").","; |
|
78 | - $sql.= " ".(isset($this->parameters)?"'".$this->db->escape($this->parameters)."'":"''").","; |
|
79 | - $sql.= " ".$this->fk_variable.","; |
|
80 | - $sql.= " ".$this->update_interval.","; |
|
81 | - $sql.= " ".$this->next_update.","; |
|
82 | - $sql.= " ".(isset($this->last_status)?"'".$this->db->escape($this->last_status)."'":"''"); |
|
83 | - $sql.= ")"; |
|
74 | + $sql .= "type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
|
75 | + $sql .= ") VALUES ("; |
|
76 | + $sql .= " ".$this->type.","; |
|
77 | + $sql .= " ".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "''").","; |
|
78 | + $sql .= " ".(isset($this->parameters) ? "'".$this->db->escape($this->parameters)."'" : "''").","; |
|
79 | + $sql .= " ".$this->fk_variable.","; |
|
80 | + $sql .= " ".$this->update_interval.","; |
|
81 | + $sql .= " ".$this->next_update.","; |
|
82 | + $sql .= " ".(isset($this->last_status) ? "'".$this->db->escape($this->last_status)."'" : "''"); |
|
83 | + $sql .= ")"; |
|
84 | 84 | |
85 | 85 | $this->db->begin(); |
86 | 86 | |
87 | 87 | dol_syslog(__METHOD__, LOG_DEBUG); |
88 | - $resql=$this->db->query($sql); |
|
89 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
88 | + $resql = $this->db->query($sql); |
|
89 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
90 | 90 | |
91 | - if (! $error) |
|
91 | + if (!$error) |
|
92 | 92 | { |
93 | 93 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
94 | 94 | |
95 | - if (! $notrigger) |
|
95 | + if (!$notrigger) |
|
96 | 96 | { |
97 | 97 | // Uncomment this and change MYOBJECT to your own tag if you |
98 | 98 | // want this action calls a trigger. |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | // Commit or rollback |
108 | 108 | if ($error) |
109 | 109 | { |
110 | - foreach($this->errors as $errmsg) |
|
110 | + foreach ($this->errors as $errmsg) |
|
111 | 111 | { |
112 | 112 | dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
113 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
113 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
114 | 114 | } |
115 | 115 | $this->db->rollback(); |
116 | - return -1*$error; |
|
116 | + return -1 * $error; |
|
117 | 117 | } |
118 | 118 | else |
119 | 119 | { |
@@ -132,22 +132,22 @@ discard block |
||
132 | 132 | function fetch($id) |
133 | 133 | { |
134 | 134 | $sql = "SELECT type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
135 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
136 | - $sql.= " WHERE rowid = ".$id; |
|
135 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
136 | + $sql .= " WHERE rowid = ".$id; |
|
137 | 137 | |
138 | 138 | dol_syslog(__METHOD__); |
139 | - $resql=$this->db->query($sql); |
|
139 | + $resql = $this->db->query($sql); |
|
140 | 140 | if ($resql) |
141 | 141 | { |
142 | 142 | $obj = $this->db->fetch_object($resql); |
143 | 143 | if ($obj) |
144 | 144 | { |
145 | - $this->id = $id; |
|
146 | - $this->type = $obj->type; |
|
145 | + $this->id = $id; |
|
146 | + $this->type = $obj->type; |
|
147 | 147 | $this->description = $obj->description; |
148 | - $this->parameters = $obj->parameters; |
|
148 | + $this->parameters = $obj->parameters; |
|
149 | 149 | $this->fk_variable = $obj->fk_variable; |
150 | - $this->update_interval = $obj->update_interval; |
|
150 | + $this->update_interval = $obj->update_interval; |
|
151 | 151 | $this->next_update = $obj->next_update; |
152 | 152 | $this->last_status = $obj->last_status; |
153 | 153 | $this->checkParameters(); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | } |
161 | 161 | else |
162 | 162 | { |
163 | - $this->error="Error ".$this->db->lasterror(); |
|
163 | + $this->error = "Error ".$this->db->lasterror(); |
|
164 | 164 | return -1; |
165 | 165 | } |
166 | 166 | } |
@@ -172,32 +172,32 @@ discard block |
||
172 | 172 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
173 | 173 | * @return int <0 if KO, >0 if OK |
174 | 174 | */ |
175 | - function update($user=0, $notrigger=0) |
|
175 | + function update($user = 0, $notrigger = 0) |
|
176 | 176 | { |
177 | - $error=0; |
|
177 | + $error = 0; |
|
178 | 178 | |
179 | 179 | $this->checkParameters(); |
180 | 180 | |
181 | 181 | // Update request |
182 | 182 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; |
183 | - $sql.= " type = ".$this->type.","; |
|
184 | - $sql.= " description = ".(isset($this->description)?"'".$this->db->escape($this->description)."'":"''").","; |
|
185 | - $sql.= " parameters = ".(isset($this->parameters)?"'".$this->db->escape($this->parameters)."'":"''").","; |
|
186 | - $sql.= " fk_variable = ".$this->fk_variable.","; |
|
187 | - $sql.= " update_interval = ".$this->update_interval.","; |
|
188 | - $sql.= " next_update = ".$this->next_update.","; |
|
189 | - $sql.= " last_status = ".(isset($this->last_status)?"'".$this->db->escape($this->last_status)."'":"''"); |
|
190 | - $sql.= " WHERE rowid = ".$this->id; |
|
183 | + $sql .= " type = ".$this->type.","; |
|
184 | + $sql .= " description = ".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "''").","; |
|
185 | + $sql .= " parameters = ".(isset($this->parameters) ? "'".$this->db->escape($this->parameters)."'" : "''").","; |
|
186 | + $sql .= " fk_variable = ".$this->fk_variable.","; |
|
187 | + $sql .= " update_interval = ".$this->update_interval.","; |
|
188 | + $sql .= " next_update = ".$this->next_update.","; |
|
189 | + $sql .= " last_status = ".(isset($this->last_status) ? "'".$this->db->escape($this->last_status)."'" : "''"); |
|
190 | + $sql .= " WHERE rowid = ".$this->id; |
|
191 | 191 | |
192 | 192 | $this->db->begin(); |
193 | 193 | |
194 | 194 | dol_syslog(__METHOD__); |
195 | 195 | $resql = $this->db->query($sql); |
196 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
196 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
197 | 197 | |
198 | - if (! $error) |
|
198 | + if (!$error) |
|
199 | 199 | { |
200 | - if (! $notrigger) |
|
200 | + if (!$notrigger) |
|
201 | 201 | { |
202 | 202 | // Uncomment this and change MYOBJECT to your own tag if you |
203 | 203 | // want this action calls a trigger. |
@@ -212,13 +212,13 @@ discard block |
||
212 | 212 | // Commit or rollback |
213 | 213 | if ($error) |
214 | 214 | { |
215 | - foreach($this->errors as $errmsg) |
|
215 | + foreach ($this->errors as $errmsg) |
|
216 | 216 | { |
217 | 217 | dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
218 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
218 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
219 | 219 | } |
220 | 220 | $this->db->rollback(); |
221 | - return -1*$error; |
|
221 | + return -1 * $error; |
|
222 | 222 | } |
223 | 223 | else |
224 | 224 | { |
@@ -235,15 +235,15 @@ discard block |
||
235 | 235 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
236 | 236 | * @return int <0 if KO, >0 if OK |
237 | 237 | */ |
238 | - function delete($rowid, $user, $notrigger=0) |
|
238 | + function delete($rowid, $user, $notrigger = 0) |
|
239 | 239 | { |
240 | - $error=0; |
|
240 | + $error = 0; |
|
241 | 241 | |
242 | 242 | $this->db->begin(); |
243 | 243 | |
244 | - if (! $error) |
|
244 | + if (!$error) |
|
245 | 245 | { |
246 | - if (! $notrigger) |
|
246 | + if (!$notrigger) |
|
247 | 247 | { |
248 | 248 | // Uncomment this and change MYOBJECT to your own tag if you |
249 | 249 | // want this action calls a trigger. |
@@ -255,26 +255,26 @@ discard block |
||
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | - if (! $error) |
|
258 | + if (!$error) |
|
259 | 259 | { |
260 | 260 | $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; |
261 | - $sql.= " WHERE rowid = ".$rowid; |
|
261 | + $sql .= " WHERE rowid = ".$rowid; |
|
262 | 262 | |
263 | 263 | dol_syslog(__METHOD__); |
264 | 264 | $resql = $this->db->query($sql); |
265 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
265 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | // Commit or rollback |
269 | 269 | if ($error) |
270 | 270 | { |
271 | - foreach($this->errors as $errmsg) |
|
271 | + foreach ($this->errors as $errmsg) |
|
272 | 272 | { |
273 | 273 | dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
274 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
274 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
275 | 275 | } |
276 | 276 | $this->db->rollback(); |
277 | - return -1*$error; |
|
277 | + return -1 * $error; |
|
278 | 278 | } |
279 | 279 | else |
280 | 280 | { |
@@ -291,14 +291,14 @@ discard block |
||
291 | 291 | */ |
292 | 292 | function initAsSpecimen() |
293 | 293 | { |
294 | - $this->id=0; |
|
295 | - $this->type=0; |
|
296 | - $this->description=''; |
|
297 | - $this->parameters=''; |
|
298 | - $this->fk_variable=0; |
|
299 | - $this->update_interval=0; |
|
300 | - $this->next_update=0; |
|
301 | - $this->last_status=''; |
|
294 | + $this->id = 0; |
|
295 | + $this->type = 0; |
|
296 | + $this->description = ''; |
|
297 | + $this->parameters = ''; |
|
298 | + $this->fk_variable = 0; |
|
299 | + $this->update_interval = 0; |
|
300 | + $this->next_update = 0; |
|
301 | + $this->last_status = ''; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -325,15 +325,15 @@ discard block |
||
325 | 325 | function checkParameters() |
326 | 326 | { |
327 | 327 | // Clean parameters |
328 | - if (isset($this->description)) $this->description=trim($this->description); |
|
329 | - if (isset($this->parameters)) $this->parameters=trim($this->parameters); |
|
330 | - else $this->parameters=""; |
|
331 | - if (isset($this->last_status)) $this->last_status=trim($this->last_status); |
|
328 | + if (isset($this->description)) $this->description = trim($this->description); |
|
329 | + if (isset($this->parameters)) $this->parameters = trim($this->parameters); |
|
330 | + else $this->parameters = ""; |
|
331 | + if (isset($this->last_status)) $this->last_status = trim($this->last_status); |
|
332 | 332 | |
333 | 333 | // Check parameters |
334 | - if (empty($this->type) || !is_numeric($this->type) || !in_array($this->type, $this->types)) $this->type=0; |
|
335 | - if (empty($this->update_interval) || !is_numeric($this->update_interval) || $this->update_interval < 1) $this->update_interval=$this->update_min; |
|
336 | - if (empty($this->next_update) || !is_numeric($this->next_update) || $this->next_update < 0) $this->next_update=0; |
|
334 | + if (empty($this->type) || !is_numeric($this->type) || !in_array($this->type, $this->types)) $this->type = 0; |
|
335 | + if (empty($this->update_interval) || !is_numeric($this->update_interval) || $this->update_interval < 1) $this->update_interval = $this->update_min; |
|
336 | + if (empty($this->next_update) || !is_numeric($this->next_update) || $this->next_update < 0) $this->next_update = 0; |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -344,10 +344,10 @@ discard block |
||
344 | 344 | function listUpdaters() |
345 | 345 | { |
346 | 346 | $sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
347 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
347 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
348 | 348 | |
349 | 349 | dol_syslog(__METHOD__, LOG_DEBUG); |
350 | - $resql=$this->db->query($sql); |
|
350 | + $resql = $this->db->query($sql); |
|
351 | 351 | if ($resql) |
352 | 352 | { |
353 | 353 | $retarray = array(); |
@@ -355,16 +355,16 @@ discard block |
||
355 | 355 | while ($record = $this->db->fetch_array($resql)) |
356 | 356 | { |
357 | 357 | $updater_obj = new PriceGlobalVariableUpdater($this->db); |
358 | - $updater_obj->id = $record["rowid"]; |
|
359 | - $updater_obj->type = $record["type"]; |
|
358 | + $updater_obj->id = $record["rowid"]; |
|
359 | + $updater_obj->type = $record["type"]; |
|
360 | 360 | $updater_obj->description = $record["description"]; |
361 | - $updater_obj->parameters = $record["parameters"]; |
|
361 | + $updater_obj->parameters = $record["parameters"]; |
|
362 | 362 | $updater_obj->fk_variable = $record["fk_variable"]; |
363 | - $updater_obj->update_interval = $record["update_interval"]; |
|
363 | + $updater_obj->update_interval = $record["update_interval"]; |
|
364 | 364 | $updater_obj->next_update = $record["next_update"]; |
365 | 365 | $updater_obj->last_status = $record["last_status"]; |
366 | 366 | $updater_obj->checkParameters(); |
367 | - $retarray[]=$updater_obj; |
|
367 | + $retarray[] = $updater_obj; |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | $this->db->free($resql); |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | } |
373 | 373 | else |
374 | 374 | { |
375 | - $this->error=$this->db->error(); |
|
375 | + $this->error = $this->db->error(); |
|
376 | 376 | return -1; |
377 | 377 | } |
378 | 378 | } |
@@ -385,11 +385,11 @@ discard block |
||
385 | 385 | function listPendingUpdaters() |
386 | 386 | { |
387 | 387 | $sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status"; |
388 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
389 | - $sql.= " WHERE next_update < ".dol_now(); |
|
388 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
389 | + $sql .= " WHERE next_update < ".dol_now(); |
|
390 | 390 | |
391 | 391 | dol_syslog(__METHOD__, LOG_DEBUG); |
392 | - $resql=$this->db->query($sql); |
|
392 | + $resql = $this->db->query($sql); |
|
393 | 393 | if ($resql) |
394 | 394 | { |
395 | 395 | $retarray = array(); |
@@ -397,16 +397,16 @@ discard block |
||
397 | 397 | while ($record = $this->db->fetch_array($resql)) |
398 | 398 | { |
399 | 399 | $updater_obj = new PriceGlobalVariableUpdater($this->db); |
400 | - $updater_obj->id = $record["rowid"]; |
|
401 | - $updater_obj->type = $record["type"]; |
|
400 | + $updater_obj->id = $record["rowid"]; |
|
401 | + $updater_obj->type = $record["type"]; |
|
402 | 402 | $updater_obj->description = $record["description"]; |
403 | - $updater_obj->parameters = $record["parameters"]; |
|
403 | + $updater_obj->parameters = $record["parameters"]; |
|
404 | 404 | $updater_obj->fk_variable = $record["fk_variable"]; |
405 | - $updater_obj->update_interval = $record["update_interval"]; |
|
405 | + $updater_obj->update_interval = $record["update_interval"]; |
|
406 | 406 | $updater_obj->next_update = $record["next_update"]; |
407 | 407 | $updater_obj->last_status = $record["last_status"]; |
408 | 408 | $updater_obj->checkParameters(); |
409 | - $retarray[]=$updater_obj; |
|
409 | + $retarray[] = $updater_obj; |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | $this->db->free($resql); |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | } |
415 | 415 | else |
416 | 416 | { |
417 | - $this->error=$this->db->error(); |
|
417 | + $this->error = $this->db->error(); |
|
418 | 418 | return -1; |
419 | 419 | } |
420 | 420 | } |
@@ -467,9 +467,9 @@ discard block |
||
467 | 467 | if ($this->type == 0) { |
468 | 468 | // Call JSON request |
469 | 469 | include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; |
470 | - $tmpresult=getURLContent($url); |
|
471 | - $code=$tmpresult['http_code']; |
|
472 | - $result=$tmpresult['content']; |
|
470 | + $tmpresult = getURLContent($url); |
|
471 | + $code = $tmpresult['http_code']; |
|
472 | + $result = $tmpresult['content']; |
|
473 | 473 | |
474 | 474 | if (!isset($result)) { |
475 | 475 | $this->error = $langs->trans("ErrorGlobalVariableUpdater0", "empty response"); |
@@ -502,9 +502,9 @@ discard block |
||
502 | 502 | //SOAP client |
503 | 503 | require_once NUSOAP_PATH.'/nusoap.php'; |
504 | 504 | $soap_client = new nusoap_client($url); |
505 | - $soap_client->soap_defencoding='UTF-8'; |
|
505 | + $soap_client->soap_defencoding = 'UTF-8'; |
|
506 | 506 | $soap_client->decodeUTF8(false); |
507 | - $result = $soap_client->call($method, $data, $ns,''); |
|
507 | + $result = $soap_client->call($method, $data, $ns, ''); |
|
508 | 508 | |
509 | 509 | //Check if result is a error |
510 | 510 | if ($result === false) { |
@@ -538,34 +538,34 @@ discard block |
||
538 | 538 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
539 | 539 | * @return int <0 if KO, >0 if OK |
540 | 540 | */ |
541 | - function update_next_update($next_update, $user=0, $notrigger=0) |
|
541 | + function update_next_update($next_update, $user = 0, $notrigger = 0) |
|
542 | 542 | { |
543 | - $error=0; |
|
543 | + $error = 0; |
|
544 | 544 | |
545 | 545 | $this->next_update = $next_update; |
546 | 546 | $this->checkParameters(); |
547 | 547 | |
548 | 548 | // Update request |
549 | 549 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; |
550 | - $sql.= " next_update = ".$this->next_update; |
|
551 | - $sql.= " WHERE rowid = ".$this->id; |
|
550 | + $sql .= " next_update = ".$this->next_update; |
|
551 | + $sql .= " WHERE rowid = ".$this->id; |
|
552 | 552 | |
553 | 553 | $this->db->begin(); |
554 | 554 | |
555 | 555 | dol_syslog(__METHOD__); |
556 | 556 | $resql = $this->db->query($sql); |
557 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
557 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
558 | 558 | |
559 | 559 | // Commit or rollback |
560 | 560 | if ($error) |
561 | 561 | { |
562 | - foreach($this->errors as $errmsg) |
|
562 | + foreach ($this->errors as $errmsg) |
|
563 | 563 | { |
564 | 564 | dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
565 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
565 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
566 | 566 | } |
567 | 567 | $this->db->rollback(); |
568 | - return -1*$error; |
|
568 | + return -1 * $error; |
|
569 | 569 | } |
570 | 570 | else |
571 | 571 | { |
@@ -582,34 +582,34 @@ discard block |
||
582 | 582 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
583 | 583 | * @return int <0 if KO, >0 if OK |
584 | 584 | */ |
585 | - function update_status($last_status, $user=0, $notrigger=0) |
|
585 | + function update_status($last_status, $user = 0, $notrigger = 0) |
|
586 | 586 | { |
587 | - $error=0; |
|
587 | + $error = 0; |
|
588 | 588 | |
589 | 589 | $this->last_status = $last_status; |
590 | 590 | $this->checkParameters(); |
591 | 591 | |
592 | 592 | // Update request |
593 | 593 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; |
594 | - $sql.= " last_status = ".(isset($this->last_status)?"'".$this->db->escape($this->last_status)."'":"''"); |
|
595 | - $sql.= " WHERE rowid = ".$this->id; |
|
594 | + $sql .= " last_status = ".(isset($this->last_status) ? "'".$this->db->escape($this->last_status)."'" : "''"); |
|
595 | + $sql .= " WHERE rowid = ".$this->id; |
|
596 | 596 | |
597 | 597 | $this->db->begin(); |
598 | 598 | |
599 | 599 | dol_syslog(__METHOD__); |
600 | 600 | $resql = $this->db->query($sql); |
601 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
601 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
602 | 602 | |
603 | 603 | // Commit or rollback |
604 | 604 | if ($error) |
605 | 605 | { |
606 | - foreach($this->errors as $errmsg) |
|
606 | + foreach ($this->errors as $errmsg) |
|
607 | 607 | { |
608 | 608 | dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); |
609 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
609 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
610 | 610 | } |
611 | 611 | $this->db->rollback(); |
612 | - return -1*$error; |
|
612 | + return -1 * $error; |
|
613 | 613 | } |
614 | 614 | else |
615 | 615 | { |
@@ -876,7 +876,7 @@ |
||
876 | 876 | * addresses and to sort them by Domain. |
877 | 877 | * |
878 | 878 | * @param string $_type TO, CC, or BCC lists to add addrresses into |
879 | - * @param mixed $_addrList Array or COMMA delimited string of addresses |
|
879 | + * @param string $_addrList Array or COMMA delimited string of addresses |
|
880 | 880 | * @return void |
881 | 881 | * |
882 | 882 | */ |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | * Message Sensitivity |
119 | 119 | */ |
120 | 120 | var $_arySensitivity = array ( false, |
121 | - 'Personal', |
|
122 | - 'Private', |
|
123 | - 'Company Confidential' ); |
|
121 | + 'Personal', |
|
122 | + 'Private', |
|
123 | + 'Company Confidential' ); |
|
124 | 124 | |
125 | 125 | /** |
126 | 126 | * Message Sensitivity |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | * Message Priority |
133 | 133 | */ |
134 | 134 | var $_aryPriority = array ( 'Bulk', |
135 | - 'Highest', |
|
136 | - 'High', |
|
137 | - 'Normal', |
|
138 | - 'Low', |
|
139 | - 'Lowest' ); |
|
135 | + 'Highest', |
|
136 | + 'High', |
|
137 | + 'Normal', |
|
138 | + 'Low', |
|
139 | + 'Lowest' ); |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * Content-Transfer-Encoding |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | * Content-Transfer-Encoding |
149 | 149 | */ |
150 | 150 | var $_smtpsTransEncodeTypes = array( '7bit', // Simple 7-bit ASCII |
151 | - '8bit', // 8-bit coding with line termination characters |
|
152 | - 'base64', // 3 octets encoded into 4 sextets with offset |
|
153 | - 'binary', // Arbitrary binary stream |
|
154 | - 'mac-binhex40', // Macintosh binary to hex encoding |
|
155 | - 'quoted-printable', // Mostly 7-bit, with 8-bit characters encoded as "=HH" |
|
156 | - 'uuencode' ); // UUENCODE encoding |
|
151 | + '8bit', // 8-bit coding with line termination characters |
|
152 | + 'base64', // 3 octets encoded into 4 sextets with offset |
|
153 | + 'binary', // Arbitrary binary stream |
|
154 | + 'mac-binhex40', // Macintosh binary to hex encoding |
|
155 | + 'quoted-printable', // Mostly 7-bit, with 8-bit characters encoded as "=HH" |
|
156 | + 'uuencode' ); // UUENCODE encoding |
|
157 | 157 | |
158 | 158 | /** |
159 | 159 | * Content-Transfer-Encoding |
@@ -229,54 +229,54 @@ discard block |
||
229 | 229 | var $_moreInHeader = ''; |
230 | 230 | |
231 | 231 | |
232 | - /** |
|
233 | - * Set delivery receipt |
|
234 | - * |
|
235 | - * @param int $_val Value |
|
236 | - * @return void |
|
237 | - */ |
|
232 | + /** |
|
233 | + * Set delivery receipt |
|
234 | + * |
|
235 | + * @param int $_val Value |
|
236 | + * @return void |
|
237 | + */ |
|
238 | 238 | function setDeliveryReceipt($_val = 0) |
239 | 239 | { |
240 | 240 | $this->_deliveryReceipt = $_val; |
241 | 241 | } |
242 | 242 | |
243 | - /** |
|
244 | - * get delivery receipt |
|
245 | - * |
|
246 | - * @return int Delivery receipt |
|
247 | - */ |
|
243 | + /** |
|
244 | + * get delivery receipt |
|
245 | + * |
|
246 | + * @return int Delivery receipt |
|
247 | + */ |
|
248 | 248 | function getDeliveryReceipt() |
249 | 249 | { |
250 | 250 | return $this->_deliveryReceipt; |
251 | 251 | } |
252 | 252 | |
253 | - /** |
|
254 | - * Set trackid |
|
255 | - * |
|
256 | - * @param string $_val Value |
|
257 | - * @return void |
|
258 | - */ |
|
253 | + /** |
|
254 | + * Set trackid |
|
255 | + * |
|
256 | + * @param string $_val Value |
|
257 | + * @return void |
|
258 | + */ |
|
259 | 259 | function setTrackId($_val = '') |
260 | 260 | { |
261 | 261 | $this->_trackId = $_val; |
262 | 262 | } |
263 | 263 | |
264 | - /** |
|
265 | - * Set moreInHeader |
|
266 | - * |
|
267 | - * @param string $_val Value |
|
268 | - * @return void |
|
269 | - */ |
|
264 | + /** |
|
265 | + * Set moreInHeader |
|
266 | + * |
|
267 | + * @param string $_val Value |
|
268 | + * @return void |
|
269 | + */ |
|
270 | 270 | function setMoreInHeader($_val = '') |
271 | 271 | { |
272 | 272 | $this->_moreinheader = $_val; |
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
276 | - * get trackid |
|
277 | - * |
|
278 | - * @return string Track id |
|
279 | - */ |
|
276 | + * get trackid |
|
277 | + * |
|
278 | + * @return string Track id |
|
279 | + */ |
|
280 | 280 | function getTrackId() |
281 | 281 | { |
282 | 282 | return $this->_trackId; |
@@ -289,27 +289,27 @@ discard block |
||
289 | 289 | */ |
290 | 290 | function getMoreInHeader() |
291 | 291 | { |
292 | - return $this->_moreinheader; |
|
292 | + return $this->_moreinheader; |
|
293 | 293 | } |
294 | 294 | |
295 | - /** |
|
296 | - * Set errors to |
|
297 | - * |
|
298 | - * @param string $_strErrorsTo Errors to |
|
299 | - * @return void |
|
300 | - */ |
|
295 | + /** |
|
296 | + * Set errors to |
|
297 | + * |
|
298 | + * @param string $_strErrorsTo Errors to |
|
299 | + * @return void |
|
300 | + */ |
|
301 | 301 | function setErrorsTo($_strErrorsTo) |
302 | 302 | { |
303 | 303 | if ( $_strErrorsTo ) |
304 | 304 | $this->_errorsTo = $this->_strip_email($_strErrorsTo); |
305 | 305 | } |
306 | 306 | |
307 | - /** |
|
308 | - * Get errors to |
|
309 | - * |
|
310 | - * @param boolean $_part Variant |
|
311 | - * @return string Errors to |
|
312 | - */ |
|
307 | + /** |
|
308 | + * Get errors to |
|
309 | + * |
|
310 | + * @param boolean $_part Variant |
|
311 | + * @return string Errors to |
|
312 | + */ |
|
313 | 313 | function getErrorsTo($_part = true ) |
314 | 314 | { |
315 | 315 | $_retValue = ''; |
@@ -376,11 +376,11 @@ discard block |
||
376 | 376 | { |
377 | 377 | //See if we can connect to the SMTP server |
378 | 378 | if ($this->socket = @fsockopen( |
379 | - preg_replace('@tls://@i','',$this->getHost()), // Host to 'hit', IP or domain |
|
380 | - $this->getPort(), // which Port number to use |
|
381 | - $this->errno, // actual system level error |
|
382 | - $this->errstr, // and any text that goes with the error |
|
383 | - $this->_smtpTimeout |
|
379 | + preg_replace('@tls://@i','',$this->getHost()), // Host to 'hit', IP or domain |
|
380 | + $this->getPort(), // which Port number to use |
|
381 | + $this->errno, // actual system level error |
|
382 | + $this->errstr, // and any text that goes with the error |
|
383 | + $this->_smtpTimeout |
|
384 | 384 | )) // timeout for reading/writing data over the socket |
385 | 385 | { |
386 | 386 | // Fix from PHP SMTP class by 'Chris Ryan' |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | { |
443 | 443 | if ($usetls) |
444 | 444 | { |
445 | - /* |
|
445 | + /* |
|
446 | 446 | The following dialog illustrates how a client and server can start a TLS STARTTLS session |
447 | 447 | S: <waits for connection on TCP port 25> |
448 | 448 | C: <opens connection> |
@@ -578,13 +578,13 @@ discard block |
||
578 | 578 | // and send it out "single file" |
579 | 579 | foreach ( $this->get_RCPT_list() as $_address ) |
580 | 580 | { |
581 | - /* Note: |
|
581 | + /* Note: |
|
582 | 582 | * BCC email addresses must be listed in the RCPT TO command list, |
583 | 583 | * but the BCC header should not be printed under the DATA command. |
584 | 584 | * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server |
585 | 585 | */ |
586 | 586 | |
587 | - /* |
|
587 | + /* |
|
588 | 588 | * TODO |
589 | 589 | * After each 'RCPT TO:' is sent, we need to make sure it was kosher, |
590 | 590 | * if not, the whole message will fail |
@@ -946,8 +946,8 @@ discard block |
||
946 | 946 | */ |
947 | 947 | function setReplyTo($_strReplyTo) |
948 | 948 | { |
949 | - if ( $_strReplyTo ) |
|
950 | - $this->_msgReplyTo = $this->_strip_email($_strReplyTo); |
|
949 | + if ( $_strReplyTo ) |
|
950 | + $this->_msgReplyTo = $this->_strip_email($_strReplyTo); |
|
951 | 951 | } |
952 | 952 | |
953 | 953 | /** |
@@ -958,14 +958,14 @@ discard block |
||
958 | 958 | */ |
959 | 959 | function getReplyTo($_part = true) |
960 | 960 | { |
961 | - $_retValue = ''; |
|
961 | + $_retValue = ''; |
|
962 | 962 | |
963 | - if ( $_part === true ) |
|
964 | - $_retValue = $this->_msgReplyTo; |
|
965 | - else |
|
966 | - $_retValue = $this->_msgReplyTo[$_part]; |
|
963 | + if ( $_part === true ) |
|
964 | + $_retValue = $this->_msgReplyTo; |
|
965 | + else |
|
966 | + $_retValue = $this->_msgReplyTo[$_part]; |
|
967 | 967 | |
968 | - return $_retValue; |
|
968 | + return $_retValue; |
|
969 | 969 | } |
970 | 970 | |
971 | 971 | /** |
@@ -1309,7 +1309,7 @@ discard block |
||
1309 | 1309 | } |
1310 | 1310 | if (! empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n"; |
1311 | 1311 | if ( $this->getMoreInHeader() ) |
1312 | - $_header .= $this->getMoreInHeader(); // Value must include the "\r\n"; |
|
1312 | + $_header .= $this->getMoreInHeader(); // Value must include the "\r\n"; |
|
1313 | 1313 | |
1314 | 1314 | //$_header .= |
1315 | 1315 | // 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n" |
@@ -1324,11 +1324,11 @@ discard block |
||
1324 | 1324 | |
1325 | 1325 | // @CHANGE LDR |
1326 | 1326 | if ( $this->getDeliveryReceipt() ) |
1327 | - $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n"; |
|
1327 | + $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n"; |
|
1328 | 1328 | if ( $this->getErrorsTo() ) |
1329 | - $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n"; |
|
1329 | + $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n"; |
|
1330 | 1330 | if ( $this->getReplyTo() ) |
1331 | - $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n"; |
|
1331 | + $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n"; |
|
1332 | 1332 | |
1333 | 1333 | $_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n"; |
1334 | 1334 | $_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART?'MAIN_MAIL_USE_MULTI_PART':'No MAIN_MAIL_USE_MULTI_PART') . "\r\n"; |
@@ -1386,7 +1386,7 @@ discard block |
||
1386 | 1386 | */ |
1387 | 1387 | function getBodyContent() |
1388 | 1388 | { |
1389 | - global $conf; |
|
1389 | + global $conf; |
|
1390 | 1390 | |
1391 | 1391 | // Generate a new Boundary string |
1392 | 1392 | $this->_setBoundary(); |
@@ -1506,13 +1506,13 @@ discard block |
||
1506 | 1506 | |
1507 | 1507 | if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part |
1508 | 1508 | { |
1509 | - $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; |
|
1510 | - $content .= "\r\n"; |
|
1511 | - $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; |
|
1509 | + $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; |
|
1510 | + $content .= "\r\n"; |
|
1511 | + $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; |
|
1512 | 1512 | |
1513 | - $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n"; |
|
1514 | - $content.= "\r\n". $_content['dataText'] . "\r\n"; |
|
1515 | - $content.= "--" . $this->_getBoundary('alternative') . "\r\n"; |
|
1513 | + $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n"; |
|
1514 | + $content.= "\r\n". $_content['dataText'] . "\r\n"; |
|
1515 | + $content.= "--" . $this->_getBoundary('alternative') . "\r\n"; |
|
1516 | 1516 | } |
1517 | 1517 | |
1518 | 1518 | $content .= 'Content-Type: ' . $_content['mimeType'] . '; ' |
@@ -1534,7 +1534,7 @@ discard block |
||
1534 | 1534 | |
1535 | 1535 | if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part |
1536 | 1536 | { |
1537 | - $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n"; |
|
1537 | + $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n"; |
|
1538 | 1538 | } |
1539 | 1539 | |
1540 | 1540 | $content .= "\r\n"; |
@@ -1762,8 +1762,8 @@ discard block |
||
1762 | 1762 | |
1763 | 1763 | $server_response = ''; |
1764 | 1764 | |
1765 | - // avoid infinite loop |
|
1766 | - $limit=0; |
|
1765 | + // avoid infinite loop |
|
1766 | + $limit=0; |
|
1767 | 1767 | |
1768 | 1768 | while (substr($server_response,3,1) != ' ' && $limit<100) |
1769 | 1769 | { |
@@ -1773,7 +1773,7 @@ discard block |
||
1773 | 1773 | $_retVal = false; |
1774 | 1774 | break; |
1775 | 1775 | } |
1776 | - $limit++; |
|
1776 | + $limit++; |
|
1777 | 1777 | } |
1778 | 1778 | |
1779 | 1779 | if (! (substr($server_response, 0, 3) == $response)) |
@@ -1816,7 +1816,7 @@ discard block |
||
1816 | 1816 | function _setErr ( $_errNum, $_errMsg ) |
1817 | 1817 | { |
1818 | 1818 | $this->_smtpsErrors[] = array( 'num' => $_errNum, |
1819 | - 'msg' => $_errMsg ); |
|
1819 | + 'msg' => $_errMsg ); |
|
1820 | 1820 | } |
1821 | 1821 | |
1822 | 1822 | /** |
@@ -117,10 +117,10 @@ discard block |
||
117 | 117 | /** |
118 | 118 | * Message Sensitivity |
119 | 119 | */ |
120 | - var $_arySensitivity = array ( false, |
|
120 | + var $_arySensitivity = array(false, |
|
121 | 121 | 'Personal', |
122 | 122 | 'Private', |
123 | - 'Company Confidential' ); |
|
123 | + 'Company Confidential'); |
|
124 | 124 | |
125 | 125 | /** |
126 | 126 | * Message Sensitivity |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | /** |
132 | 132 | * Message Priority |
133 | 133 | */ |
134 | - var $_aryPriority = array ( 'Bulk', |
|
134 | + var $_aryPriority = array('Bulk', |
|
135 | 135 | 'Highest', |
136 | 136 | 'High', |
137 | 137 | 'Normal', |
138 | 138 | 'Low', |
139 | - 'Lowest' ); |
|
139 | + 'Lowest'); |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * Content-Transfer-Encoding |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | /** |
148 | 148 | * Content-Transfer-Encoding |
149 | 149 | */ |
150 | - var $_smtpsTransEncodeTypes = array( '7bit', // Simple 7-bit ASCII |
|
151 | - '8bit', // 8-bit coding with line termination characters |
|
152 | - 'base64', // 3 octets encoded into 4 sextets with offset |
|
153 | - 'binary', // Arbitrary binary stream |
|
154 | - 'mac-binhex40', // Macintosh binary to hex encoding |
|
155 | - 'quoted-printable', // Mostly 7-bit, with 8-bit characters encoded as "=HH" |
|
156 | - 'uuencode' ); // UUENCODE encoding |
|
150 | + var $_smtpsTransEncodeTypes = array('7bit', // Simple 7-bit ASCII |
|
151 | + '8bit', // 8-bit coding with line termination characters |
|
152 | + 'base64', // 3 octets encoded into 4 sextets with offset |
|
153 | + 'binary', // Arbitrary binary stream |
|
154 | + 'mac-binhex40', // Macintosh binary to hex encoding |
|
155 | + 'quoted-printable', // Mostly 7-bit, with 8-bit characters encoded as "=HH" |
|
156 | + 'uuencode'); // UUENCODE encoding |
|
157 | 157 | |
158 | 158 | /** |
159 | 159 | * Content-Transfer-Encoding |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | */ |
301 | 301 | function setErrorsTo($_strErrorsTo) |
302 | 302 | { |
303 | - if ( $_strErrorsTo ) |
|
303 | + if ($_strErrorsTo) |
|
304 | 304 | $this->_errorsTo = $this->_strip_email($_strErrorsTo); |
305 | 305 | } |
306 | 306 | |
@@ -310,11 +310,11 @@ discard block |
||
310 | 310 | * @param boolean $_part Variant |
311 | 311 | * @return string Errors to |
312 | 312 | */ |
313 | - function getErrorsTo($_part = true ) |
|
313 | + function getErrorsTo($_part = true) |
|
314 | 314 | { |
315 | 315 | $_retValue = ''; |
316 | 316 | |
317 | - if ( $_part === true ) |
|
317 | + if ($_part === true) |
|
318 | 318 | $_retValue = $this->_errorsTo; |
319 | 319 | else |
320 | 320 | $_retValue = $this->_errorsTo[$_part]; |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * @param boolean $_vDebug Value for debug |
329 | 329 | * @return void |
330 | 330 | */ |
331 | - function setDebug($_vDebug = false ) |
|
331 | + function setDebug($_vDebug = false) |
|
332 | 332 | { |
333 | 333 | $this->_debug = $_vDebug; |
334 | 334 | } |
@@ -357,29 +357,29 @@ discard block |
||
357 | 357 | // We have to make sure the HOST given is valid |
358 | 358 | // This is done here because '@fsockopen' will not give me this |
359 | 359 | // information if it failes to connect because it can't find the HOST |
360 | - $host=$this->getHost(); |
|
361 | - $usetls = preg_match('@tls://@i',$host); |
|
360 | + $host = $this->getHost(); |
|
361 | + $usetls = preg_match('@tls://@i', $host); |
|
362 | 362 | |
363 | - $host=preg_replace('@tcp://@i','',$host); // Remove prefix |
|
364 | - $host=preg_replace('@ssl://@i','',$host); // Remove prefix |
|
365 | - $host=preg_replace('@tls://@i','',$host); // Remove prefix |
|
363 | + $host = preg_replace('@tcp://@i', '', $host); // Remove prefix |
|
364 | + $host = preg_replace('@ssl://@i', '', $host); // Remove prefix |
|
365 | + $host = preg_replace('@tls://@i', '', $host); // Remove prefix |
|
366 | 366 | |
367 | 367 | // @CHANGE LDR |
368 | 368 | include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
369 | 369 | |
370 | - if ( (! is_ip($host)) && ((gethostbyname($host)) == $host)) |
|
370 | + if ((!is_ip($host)) && ((gethostbyname($host)) == $host)) |
|
371 | 371 | { |
372 | - $this->_setErr(99, $host . ' is either offline or is an invalid host name.'); |
|
372 | + $this->_setErr(99, $host.' is either offline or is an invalid host name.'); |
|
373 | 373 | $_retVal = false; |
374 | 374 | } |
375 | 375 | else |
376 | 376 | { |
377 | 377 | //See if we can connect to the SMTP server |
378 | 378 | if ($this->socket = @fsockopen( |
379 | - preg_replace('@tls://@i','',$this->getHost()), // Host to 'hit', IP or domain |
|
380 | - $this->getPort(), // which Port number to use |
|
381 | - $this->errno, // actual system level error |
|
382 | - $this->errstr, // and any text that goes with the error |
|
379 | + preg_replace('@tls://@i', '', $this->getHost()), // Host to 'hit', IP or domain |
|
380 | + $this->getPort(), // which Port number to use |
|
381 | + $this->errno, // actual system level error |
|
382 | + $this->errstr, // and any text that goes with the error |
|
383 | 383 | $this->_smtpTimeout |
384 | 384 | )) // timeout for reading/writing data over the socket |
385 | 385 | { |
@@ -390,14 +390,14 @@ discard block |
||
390 | 390 | if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0); |
391 | 391 | |
392 | 392 | // Check response from Server |
393 | - if ( $_retVal = $this->server_parse($this->socket, "220") ) |
|
393 | + if ($_retVal = $this->server_parse($this->socket, "220")) |
|
394 | 394 | $_retVal = $this->socket; |
395 | 395 | } |
396 | 396 | // This connection attempt failed. |
397 | 397 | else |
398 | 398 | { |
399 | 399 | // @CHANGE LDR |
400 | - if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort(); |
|
400 | + if (empty($this->errstr)) $this->errstr = 'Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort(); |
|
401 | 401 | $this->_setErr($this->errno, $this->errstr); |
402 | 402 | $_retVal = false; |
403 | 403 | } |
@@ -418,18 +418,18 @@ discard block |
||
418 | 418 | // Send the RFC2554 specified EHLO. |
419 | 419 | // This improvment as provided by 'SirSir' to |
420 | 420 | // accomodate both SMTP AND ESMTP capable servers |
421 | - $host=$this->getHost(); |
|
422 | - $usetls = preg_match('@tls://@i',$host); |
|
421 | + $host = $this->getHost(); |
|
422 | + $usetls = preg_match('@tls://@i', $host); |
|
423 | 423 | |
424 | - $host=preg_replace('@tcp://@i','',$host); // Remove prefix |
|
425 | - $host=preg_replace('@ssl://@i','',$host); // Remove prefix |
|
426 | - $host=preg_replace('@tls://@i','',$host); // Remove prefix |
|
424 | + $host = preg_replace('@tcp://@i', '', $host); // Remove prefix |
|
425 | + $host = preg_replace('@ssl://@i', '', $host); // Remove prefix |
|
426 | + $host = preg_replace('@tls://@i', '', $host); // Remove prefix |
|
427 | 427 | |
428 | - if ($usetls) $host='tls://'.$host; |
|
428 | + if ($usetls) $host = 'tls://'.$host; |
|
429 | 429 | |
430 | 430 | $hosth = $host; |
431 | 431 | |
432 | - if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) |
|
432 | + if (!empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) |
|
433 | 433 | { |
434 | 434 | // If the from to is 'aaa <[email protected]>', we will keep 'ccc.com' |
435 | 435 | $hosth = $this->getFrom('addr'); |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | $hosth = preg_replace('/.*@/', '', $hosth); |
439 | 439 | } |
440 | 440 | |
441 | - if ( $_retVal = $this->socket_send_str('EHLO ' . $hosth, '250') ) |
|
441 | + if ($_retVal = $this->socket_send_str('EHLO '.$hosth, '250')) |
|
442 | 442 | { |
443 | 443 | if ($usetls) |
444 | 444 | { |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | // the answer with list of supported AUTH methods. They may differs between non STARTTLS and with STARTTLS. |
490 | 490 | if (!$_retVal = $this->socket_send_str('EHLO '.$host, '250')) |
491 | 491 | { |
492 | - $this->_setErr(126, '"' . $host . '" does not support authenticated connections.'); |
|
492 | + $this->_setErr(126, '"'.$host.'" does not support authenticated connections.'); |
|
493 | 493 | return $_retVal; |
494 | 494 | } |
495 | 495 | } |
@@ -502,12 +502,12 @@ discard block |
||
502 | 502 | |
503 | 503 | // The error here just means the ID/password combo doesn't work. |
504 | 504 | // There is not a method to determine which is the problem, ID or password |
505 | - if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') ) |
|
505 | + if (!$_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235')) |
|
506 | 506 | $this->_setErr(130, 'Invalid Authentication Credentials.'); |
507 | 507 | } |
508 | 508 | else |
509 | 509 | { |
510 | - $this->_setErr(126, '"' . $host . '" does not support authenticated connections.'); |
|
510 | + $this->_setErr(126, '"'.$host.'" does not support authenticated connections.'); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | return $_retVal; |
@@ -531,10 +531,10 @@ discard block |
||
531 | 531 | $_retVal = false; |
532 | 532 | |
533 | 533 | // Connect to Server |
534 | - if ( $this->socket = $this->_server_connect() ) |
|
534 | + if ($this->socket = $this->_server_connect()) |
|
535 | 535 | { |
536 | 536 | // If a User ID *and* a password is given, assume Authentication is desired |
537 | - if( !empty($this->_smtpsID) && !empty($this->_smtpsPW) ) |
|
537 | + if (!empty($this->_smtpsID) && !empty($this->_smtpsPW)) |
|
538 | 538 | { |
539 | 539 | // Send the RFC2554 specified EHLO. |
540 | 540 | $_retVal = $this->_server_authenticate(); |
@@ -544,16 +544,16 @@ discard block |
||
544 | 544 | else |
545 | 545 | { |
546 | 546 | // Send the RFC821 specified HELO. |
547 | - $host=$this->getHost(); |
|
548 | - $usetls = preg_match('@tls://@i',$host); |
|
547 | + $host = $this->getHost(); |
|
548 | + $usetls = preg_match('@tls://@i', $host); |
|
549 | 549 | |
550 | - $host=preg_replace('@tcp://@i','',$host); // Remove prefix |
|
551 | - $host=preg_replace('@ssl://@i','',$host); // Remove prefix |
|
552 | - $host=preg_replace('@tls://@i','',$host); // Remove prefix |
|
550 | + $host = preg_replace('@tcp://@i', '', $host); // Remove prefix |
|
551 | + $host = preg_replace('@ssl://@i', '', $host); // Remove prefix |
|
552 | + $host = preg_replace('@tls://@i', '', $host); // Remove prefix |
|
553 | 553 | |
554 | 554 | $hosth = $host; |
555 | 555 | |
556 | - if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) |
|
556 | + if (!empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) |
|
557 | 557 | { |
558 | 558 | // If the from to is 'aaa <[email protected]>', we will keep 'ccc.com' |
559 | 559 | $hosth = $this->getFrom('addr'); |
@@ -562,21 +562,21 @@ discard block |
||
562 | 562 | $hosth = preg_replace('/.*@/', '', $hosth); |
563 | 563 | } |
564 | 564 | |
565 | - $_retVal = $this->socket_send_str('HELO ' . $hosth, '250'); |
|
565 | + $_retVal = $this->socket_send_str('HELO '.$hosth, '250'); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | // Well, did we get to the server? |
569 | - if ( $_retVal ) |
|
569 | + if ($_retVal) |
|
570 | 570 | { |
571 | 571 | // From this point onward most server response codes should be 250 |
572 | 572 | // Specify who the mail is from.... |
573 | 573 | // This has to be the raw email address, strip the "name" off |
574 | - $this->socket_send_str('MAIL FROM: ' . $this->getFrom('addr'), '250'); |
|
574 | + $this->socket_send_str('MAIL FROM: '.$this->getFrom('addr'), '250'); |
|
575 | 575 | |
576 | 576 | // 'RCPT TO:' must be given a single address, so this has to loop |
577 | 577 | // through the list of addresses, regardless of TO, CC or BCC |
578 | 578 | // and send it out "single file" |
579 | - foreach ( $this->get_RCPT_list() as $_address ) |
|
579 | + foreach ($this->get_RCPT_list() as $_address) |
|
580 | 580 | { |
581 | 581 | /* Note: |
582 | 582 | * BCC email addresses must be listed in the RCPT TO command list, |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | * mark the last address as "bad" and start the address loop over again. |
593 | 593 | * If any address fails, the entire message fails. |
594 | 594 | */ |
595 | - $this->socket_send_str('RCPT TO: <' . $_address . '>', '250'); |
|
595 | + $this->socket_send_str('RCPT TO: <'.$_address.'>', '250'); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | // Tell the server we are ready to start sending data |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | |
603 | 603 | // Now we are ready for the message... |
604 | 604 | // Ok, all the ingredients are mixed in let's cook this puppy... |
605 | - $this->socket_send_str($this->getHeader().$this->getBodyContent() . "\r\n" . '.', '250'); |
|
605 | + $this->socket_send_str($this->getHeader().$this->getBodyContent()."\r\n".'.', '250'); |
|
606 | 606 | |
607 | 607 | // Now tell the server we are done and close the socket... |
608 | 608 | fputs($this->socket, 'QUIT'); |
@@ -652,13 +652,13 @@ discard block |
||
652 | 652 | $_retVal = true; |
653 | 653 | |
654 | 654 | // if we have a path... |
655 | - if ( ! empty ($_strConfigPath) ) |
|
655 | + if (!empty ($_strConfigPath)) |
|
656 | 656 | { |
657 | 657 | // If the path is not valid, this will NOT generate an error, |
658 | 658 | // it will simply return FALSE. |
659 | - if ( ! @include ( $_strConfigPath ) ) |
|
659 | + if (!@include ($_strConfigPath)) |
|
660 | 660 | { |
661 | - $this->_setErr(110, '"' . $_strConfigPath . '" is not a valid path.'); |
|
661 | + $this->_setErr(110, '"'.$_strConfigPath.'" is not a valid path.'); |
|
662 | 662 | $_retVal = false; |
663 | 663 | } |
664 | 664 | } |
@@ -668,13 +668,13 @@ discard block |
||
668 | 668 | { |
669 | 669 | // Set these properties ONLY if they are set in the php.ini file. |
670 | 670 | // Otherwise the default values will be used. |
671 | - if ( $_host = ini_get('SMTPs') ) |
|
671 | + if ($_host = ini_get('SMTPs')) |
|
672 | 672 | $this->setHost($_host); |
673 | 673 | |
674 | - if ( $_port = ini_get('smtp_port') ) |
|
674 | + if ($_port = ini_get('smtp_port')) |
|
675 | 675 | $this->setPort($_port); |
676 | 676 | |
677 | - if ( $_from = ini_get('sendmail_from') ) |
|
677 | + if ($_from = ini_get('sendmail_from')) |
|
678 | 678 | $this->setFrom($_from); |
679 | 679 | } |
680 | 680 | |
@@ -693,8 +693,8 @@ discard block |
||
693 | 693 | */ |
694 | 694 | function setTransportType($_type = 0) |
695 | 695 | { |
696 | - if ( ( is_numeric($_type) ) && |
|
697 | - ( ( $_type >= 0 ) && ( $_type <= 3 ) ) ) |
|
696 | + if ((is_numeric($_type)) && |
|
697 | + (($_type >= 0) && ($_type <= 3))) |
|
698 | 698 | $this->_transportType = $_type; |
699 | 699 | } |
700 | 700 | |
@@ -736,7 +736,7 @@ discard block |
||
736 | 736 | */ |
737 | 737 | function setHost($_strHost) |
738 | 738 | { |
739 | - if ( $_strHost ) |
|
739 | + if ($_strHost) |
|
740 | 740 | $this->_smtpsHost = $_strHost; |
741 | 741 | } |
742 | 742 | |
@@ -761,8 +761,8 @@ discard block |
||
761 | 761 | */ |
762 | 762 | function setPort($_intPort) |
763 | 763 | { |
764 | - if ( ( is_numeric($_intPort) ) && |
|
765 | - ( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) ) |
|
764 | + if ((is_numeric($_intPort)) && |
|
765 | + (($_intPort >= 1) && ($_intPort <= 65536))) |
|
766 | 766 | $this->_smtpsPort = $_intPort; |
767 | 767 | } |
768 | 768 | |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | */ |
829 | 829 | function setCharSet($_strCharSet) |
830 | 830 | { |
831 | - if ( $_strCharSet ) |
|
831 | + if ($_strCharSet) |
|
832 | 832 | $this->_smtpsCharSet = $_strCharSet; |
833 | 833 | } |
834 | 834 | |
@@ -916,7 +916,7 @@ discard block |
||
916 | 916 | */ |
917 | 917 | function setFrom($_strFrom) |
918 | 918 | { |
919 | - if ( $_strFrom ) |
|
919 | + if ($_strFrom) |
|
920 | 920 | $this->_msgFrom = $this->_strip_email($_strFrom); |
921 | 921 | } |
922 | 922 | |
@@ -930,7 +930,7 @@ discard block |
||
930 | 930 | { |
931 | 931 | $_retValue = ''; |
932 | 932 | |
933 | - if ( $_part === true ) |
|
933 | + if ($_part === true) |
|
934 | 934 | $_retValue = $this->_msgFrom; |
935 | 935 | else |
936 | 936 | $_retValue = $this->_msgFrom[$_part]; |
@@ -946,7 +946,7 @@ discard block |
||
946 | 946 | */ |
947 | 947 | function setReplyTo($_strReplyTo) |
948 | 948 | { |
949 | - if ( $_strReplyTo ) |
|
949 | + if ($_strReplyTo) |
|
950 | 950 | $this->_msgReplyTo = $this->_strip_email($_strReplyTo); |
951 | 951 | } |
952 | 952 | |
@@ -960,7 +960,7 @@ discard block |
||
960 | 960 | { |
961 | 961 | $_retValue = ''; |
962 | 962 | |
963 | - if ( $_part === true ) |
|
963 | + if ($_part === true) |
|
964 | 964 | $_retValue = $this->_msgReplyTo; |
965 | 965 | else |
966 | 966 | $_retValue = $this->_msgReplyTo[$_part]; |
@@ -986,13 +986,13 @@ discard block |
||
986 | 986 | $aryHost = $this->_msgRecipients; |
987 | 987 | |
988 | 988 | // Only run this if we have something |
989 | - if ( !empty ($_addrList )) |
|
989 | + if (!empty ($_addrList)) |
|
990 | 990 | { |
991 | 991 | // $_addrList can be a STRING or an array |
992 | - if ( is_string($_addrList) ) |
|
992 | + if (is_string($_addrList)) |
|
993 | 993 | { |
994 | 994 | // This could be a COMMA delimited string |
995 | - if ( strstr($_addrList, ',') ) |
|
995 | + if (strstr($_addrList, ',')) |
|
996 | 996 | // "explode "list" into an array |
997 | 997 | $_addrList = explode(',', $_addrList); |
998 | 998 | |
@@ -1002,7 +1002,7 @@ discard block |
||
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | // take the array of addresses and split them further |
1005 | - foreach ( $_addrList as $_strAddr ) |
|
1005 | + foreach ($_addrList as $_strAddr) |
|
1006 | 1006 | { |
1007 | 1007 | // Strip off the end '>' |
1008 | 1008 | $_strAddr = str_replace('>', '', $_strAddr); |
@@ -1012,7 +1012,7 @@ discard block |
||
1012 | 1012 | $_tmpaddr = explode('<', $_strAddr); |
1013 | 1013 | |
1014 | 1014 | // We have a "Real Name" and eMail address |
1015 | - if ( count($_tmpaddr) == 2 ) |
|
1015 | + if (count($_tmpaddr) == 2) |
|
1016 | 1016 | { |
1017 | 1017 | $_tmpHost = explode('@', $_tmpaddr[1]); |
1018 | 1018 | $_tmpaddr[0] = trim($_tmpaddr[0], ' ">'); |
@@ -1067,10 +1067,10 @@ discard block |
||
1067 | 1067 | $_tmpAry = explode('<', $_strAddr); |
1068 | 1068 | |
1069 | 1069 | // Do we have a "Real name" |
1070 | - if ( count($_tmpAry) == 2 ) |
|
1070 | + if (count($_tmpAry) == 2) |
|
1071 | 1071 | { |
1072 | 1072 | // We may not really have a "Real Name" |
1073 | - if ( $_tmpAry[0]) |
|
1073 | + if ($_tmpAry[0]) |
|
1074 | 1074 | $_aryEmail['real'] = trim($_tmpAry[0], ' ">'); |
1075 | 1075 | |
1076 | 1076 | $_aryEmail['addr'] = $_tmpAry[1]; |
@@ -1079,10 +1079,10 @@ discard block |
||
1079 | 1079 | $_aryEmail['addr'] = $_tmpAry[0]; |
1080 | 1080 | |
1081 | 1081 | // Pull User Name and Host.tld apart |
1082 | - list($_aryEmail['user'], $_aryEmail['host'] ) = explode('@', $_aryEmail['addr']); |
|
1082 | + list($_aryEmail['user'], $_aryEmail['host']) = explode('@', $_aryEmail['addr']); |
|
1083 | 1083 | |
1084 | 1084 | // Put the brackets back around the address |
1085 | - $_aryEmail['addr'] = '<' . $_aryEmail['addr'] . '>'; |
|
1085 | + $_aryEmail['addr'] = '<'.$_aryEmail['addr'].'>'; |
|
1086 | 1086 | |
1087 | 1087 | return $_aryEmail; |
1088 | 1088 | } |
@@ -1099,17 +1099,17 @@ discard block |
||
1099 | 1099 | /** |
1100 | 1100 | * An array of bares addresses for use with 'RCPT TO:' |
1101 | 1101 | */ |
1102 | - $_RCPT_list=array(); |
|
1102 | + $_RCPT_list = array(); |
|
1103 | 1103 | |
1104 | 1104 | // walk down Recipients array and pull just email addresses |
1105 | - foreach ( $this->_msgRecipients as $_host => $_list ) |
|
1105 | + foreach ($this->_msgRecipients as $_host => $_list) |
|
1106 | 1106 | { |
1107 | - foreach ( $_list as $_subList ) |
|
1107 | + foreach ($_list as $_subList) |
|
1108 | 1108 | { |
1109 | - foreach ( $_subList as $_name => $_addr ) |
|
1109 | + foreach ($_subList as $_name => $_addr) |
|
1110 | 1110 | { |
1111 | 1111 | // build RCPT list |
1112 | - $_RCPT_list[] = $_name . '@' . $_host; |
|
1112 | + $_RCPT_list[] = $_name.'@'.$_host; |
|
1113 | 1113 | } |
1114 | 1114 | } |
1115 | 1115 | } |
@@ -1126,27 +1126,27 @@ discard block |
||
1126 | 1126 | function get_email_list($_which = null) |
1127 | 1127 | { |
1128 | 1128 | // We need to know which address segment to pull |
1129 | - if ( $_which ) |
|
1129 | + if ($_which) |
|
1130 | 1130 | { |
1131 | 1131 | // Make sure we have addresses to process |
1132 | - if ( $this->_msgRecipients ) |
|
1132 | + if ($this->_msgRecipients) |
|
1133 | 1133 | { |
1134 | - $_RCPT_list=array(); |
|
1134 | + $_RCPT_list = array(); |
|
1135 | 1135 | // walk down Recipients array and pull just email addresses |
1136 | - foreach ( $this->_msgRecipients as $_host => $_list ) |
|
1136 | + foreach ($this->_msgRecipients as $_host => $_list) |
|
1137 | 1137 | { |
1138 | - if ( $this->_msgRecipients[$_host][$_which] ) |
|
1138 | + if ($this->_msgRecipients[$_host][$_which]) |
|
1139 | 1139 | { |
1140 | - foreach ( $this->_msgRecipients[$_host][$_which] as $_addr => $_realName ) |
|
1140 | + foreach ($this->_msgRecipients[$_host][$_which] as $_addr => $_realName) |
|
1141 | 1141 | { |
1142 | - if ( $_realName ) // @CHANGE LDR |
|
1142 | + if ($_realName) // @CHANGE LDR |
|
1143 | 1143 | { |
1144 | - $_realName = '"' . $_realName . '"'; |
|
1145 | - $_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>'; |
|
1144 | + $_realName = '"'.$_realName.'"'; |
|
1145 | + $_RCPT_list[] = $_realName.' <'.$_addr.'@'.$_host.'>'; |
|
1146 | 1146 | } |
1147 | 1147 | else |
1148 | 1148 | { |
1149 | - $_RCPT_list[] = $_addr . '@' . $_host; |
|
1149 | + $_RCPT_list[] = $_addr.'@'.$_host; |
|
1150 | 1150 | } |
1151 | 1151 | } |
1152 | 1152 | } |
@@ -1176,7 +1176,7 @@ discard block |
||
1176 | 1176 | */ |
1177 | 1177 | function setTO($_addrTo) |
1178 | 1178 | { |
1179 | - if ( $_addrTo ) |
|
1179 | + if ($_addrTo) |
|
1180 | 1180 | $this->_buildAddrList('to', $_addrTo); |
1181 | 1181 | } |
1182 | 1182 | |
@@ -1198,7 +1198,7 @@ discard block |
||
1198 | 1198 | */ |
1199 | 1199 | function setCC($_strCC) |
1200 | 1200 | { |
1201 | - if ( $_strCC ) |
|
1201 | + if ($_strCC) |
|
1202 | 1202 | $this->_buildAddrList('cc', $_strCC); |
1203 | 1203 | } |
1204 | 1204 | |
@@ -1220,7 +1220,7 @@ discard block |
||
1220 | 1220 | */ |
1221 | 1221 | function setBCC($_strBCC) |
1222 | 1222 | { |
1223 | - if ( $_strBCC ) |
|
1223 | + if ($_strBCC) |
|
1224 | 1224 | $this->_buildAddrList('bcc', $_strBCC); |
1225 | 1225 | } |
1226 | 1226 | |
@@ -1242,7 +1242,7 @@ discard block |
||
1242 | 1242 | */ |
1243 | 1243 | function setSubject($_strSubject = '') |
1244 | 1244 | { |
1245 | - if ( $_strSubject ) |
|
1245 | + if ($_strSubject) |
|
1246 | 1246 | $this->_msgSubject = $_strSubject; |
1247 | 1247 | } |
1248 | 1248 | |
@@ -1265,11 +1265,11 @@ discard block |
||
1265 | 1265 | { |
1266 | 1266 | global $conf; |
1267 | 1267 | |
1268 | - $_header = 'From: ' . $this->getFrom('org') . "\r\n" |
|
1269 | - . 'To: ' . $this->getTO() . "\r\n"; |
|
1268 | + $_header = 'From: '.$this->getFrom('org')."\r\n" |
|
1269 | + . 'To: '.$this->getTO()."\r\n"; |
|
1270 | 1270 | |
1271 | - if ( $this->getCC() ) |
|
1272 | - $_header .= 'Cc: ' . $this->getCC() . "\r\n"; |
|
1271 | + if ($this->getCC()) |
|
1272 | + $_header .= 'Cc: '.$this->getCC()."\r\n"; |
|
1273 | 1273 | |
1274 | 1274 | /* Note: |
1275 | 1275 | * BCC email addresses must be listed in the RCPT TO command list, |
@@ -1282,57 +1282,57 @@ discard block |
||
1282 | 1282 | $_header .= 'Bcc: ' . $this->getBCC() . "\r\n"; |
1283 | 1283 | */ |
1284 | 1284 | |
1285 | - $host=$this->getHost(); |
|
1286 | - $usetls = preg_match('@tls://@i',$host); |
|
1285 | + $host = $this->getHost(); |
|
1286 | + $usetls = preg_match('@tls://@i', $host); |
|
1287 | 1287 | |
1288 | - $host=preg_replace('@tcp://@i','',$host); // Remove prefix |
|
1289 | - $host=preg_replace('@ssl://@i','',$host); // Remove prefix |
|
1290 | - $host=preg_replace('@tls://@i','',$host); // Remove prefix |
|
1288 | + $host = preg_replace('@tcp://@i', '', $host); // Remove prefix |
|
1289 | + $host = preg_replace('@ssl://@i', '', $host); // Remove prefix |
|
1290 | + $host = preg_replace('@tls://@i', '', $host); // Remove prefix |
|
1291 | 1291 | |
1292 | - $host=dol_getprefix('email'); |
|
1292 | + $host = dol_getprefix('email'); |
|
1293 | 1293 | |
1294 | 1294 | //NOTE: Message-ID should probably contain the username of the user who sent the msg |
1295 | - $_header .= 'Subject: ' . $this->getSubject() . "\r\n"; |
|
1296 | - $_header .= 'Date: ' . date("r") . "\r\n"; |
|
1295 | + $_header .= 'Subject: '.$this->getSubject()."\r\n"; |
|
1296 | + $_header .= 'Date: '.date("r")."\r\n"; |
|
1297 | 1297 | |
1298 | 1298 | $trackid = $this->getTrackId(); |
1299 | 1299 | if ($trackid) |
1300 | 1300 | { |
1301 | 1301 | // References is kept in response and Message-ID is returned into In-Reply-To: |
1302 | - $_header .= 'Message-ID: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n"; |
|
1303 | - $_header .= 'References: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n"; |
|
1304 | - $_header .= 'X-Dolibarr-TRACKID: ' . $trackid . "\r\n"; |
|
1302 | + $_header .= 'Message-ID: <'.time().'.SMTPs-dolibarr-'.$trackid.'@'.$host.">\r\n"; |
|
1303 | + $_header .= 'References: <'.time().'.SMTPs-dolibarr-'.$trackid.'@'.$host.">\r\n"; |
|
1304 | + $_header .= 'X-Dolibarr-TRACKID: '.$trackid."\r\n"; |
|
1305 | 1305 | } |
1306 | 1306 | else |
1307 | 1307 | { |
1308 | - $_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n"; |
|
1308 | + $_header .= 'Message-ID: <'.time().'.SMTPs@'.$host.">\r\n"; |
|
1309 | 1309 | } |
1310 | - if (! empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n"; |
|
1311 | - if ( $this->getMoreInHeader() ) |
|
1312 | - $_header .= $this->getMoreInHeader(); // Value must include the "\r\n"; |
|
1310 | + if (!empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: ".$_SERVER['REMOTE_ADDR']."\r\n"; |
|
1311 | + if ($this->getMoreInHeader()) |
|
1312 | + $_header .= $this->getMoreInHeader(); // Value must include the "\r\n"; |
|
1313 | 1313 | |
1314 | 1314 | //$_header .= |
1315 | 1315 | // 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n" |
1316 | 1316 | // 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"; |
1317 | 1317 | |
1318 | - if ( $this->getSensitivity() ) |
|
1319 | - $_header .= 'Sensitivity: ' . $this->getSensitivity() . "\r\n"; |
|
1318 | + if ($this->getSensitivity()) |
|
1319 | + $_header .= 'Sensitivity: '.$this->getSensitivity()."\r\n"; |
|
1320 | 1320 | |
1321 | - if ( $this->_msgPriority != 3 ) |
|
1321 | + if ($this->_msgPriority != 3) |
|
1322 | 1322 | $_header .= $this->getPriority(); |
1323 | 1323 | |
1324 | 1324 | |
1325 | 1325 | // @CHANGE LDR |
1326 | - if ( $this->getDeliveryReceipt() ) |
|
1327 | - $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n"; |
|
1328 | - if ( $this->getErrorsTo() ) |
|
1329 | - $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n"; |
|
1330 | - if ( $this->getReplyTo() ) |
|
1331 | - $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n"; |
|
1326 | + if ($this->getDeliveryReceipt()) |
|
1327 | + $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr')."\r\n"; |
|
1328 | + if ($this->getErrorsTo()) |
|
1329 | + $_header .= 'Errors-To: '.$this->getErrorsTo('addr')."\r\n"; |
|
1330 | + if ($this->getReplyTo()) |
|
1331 | + $_header .= "Reply-To: ".$this->getReplyTo('addr')."\r\n"; |
|
1332 | 1332 | |
1333 | - $_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n"; |
|
1334 | - $_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART?'MAIN_MAIL_USE_MULTI_PART':'No MAIN_MAIL_USE_MULTI_PART') . "\r\n"; |
|
1335 | - $_header .= 'Mime-Version: 1.0' . "\r\n"; |
|
1333 | + $_header .= 'X-Mailer: Dolibarr version '.DOL_VERSION.' (using SMTPs Mailer)'."\r\n"; |
|
1334 | + $_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART ? 'MAIN_MAIL_USE_MULTI_PART' : 'No MAIN_MAIL_USE_MULTI_PART')."\r\n"; |
|
1335 | + $_header .= 'Mime-Version: 1.0'."\r\n"; |
|
1336 | 1336 | |
1337 | 1337 | |
1338 | 1338 | return $_header; |
@@ -1349,7 +1349,7 @@ discard block |
||
1349 | 1349 | { |
1350 | 1350 | //if ( $strContent ) |
1351 | 1351 | //{ |
1352 | - if ( $strType == 'html' ) |
|
1352 | + if ($strType == 'html') |
|
1353 | 1353 | $strMimeType = 'text/html'; |
1354 | 1354 | else |
1355 | 1355 | $strMimeType = 'text/plain'; |
@@ -1366,7 +1366,7 @@ discard block |
||
1366 | 1366 | |
1367 | 1367 | // Make RFC2045 Compliant |
1368 | 1368 | //$strContent = rtrim(chunk_split($strContent)); // Function chunck_split seems ko if not used on a base64 content |
1369 | - $strContent = rtrim(wordwrap($strContent, 75, "\r\n")); // TODO Using this method creates unexpected line break on text/plain content. |
|
1369 | + $strContent = rtrim(wordwrap($strContent, 75, "\r\n")); // TODO Using this method creates unexpected line break on text/plain content. |
|
1370 | 1370 | |
1371 | 1371 | $this->_msgContent[$strType] = array(); |
1372 | 1372 | |
@@ -1374,7 +1374,7 @@ discard block |
||
1374 | 1374 | $this->_msgContent[$strType]['data'] = $strContent; |
1375 | 1375 | $this->_msgContent[$strType]['dataText'] = $strContentAltText; |
1376 | 1376 | |
1377 | - if ( $this->getMD5flag() ) |
|
1377 | + if ($this->getMD5flag()) |
|
1378 | 1378 | $this->_msgContent[$strType]['md5'] = dol_hash($strContent, 3); |
1379 | 1379 | //} |
1380 | 1380 | } |
@@ -1398,49 +1398,49 @@ discard block |
||
1398 | 1398 | $keyCount = count($_types); |
1399 | 1399 | |
1400 | 1400 | // If we have ZERO, we have a problem |
1401 | - if( $keyCount === 0 ) |
|
1401 | + if ($keyCount === 0) |
|
1402 | 1402 | die ("Sorry, no content"); |
1403 | 1403 | |
1404 | 1404 | // If we have ONE, we can use the simple format |
1405 | - else if( $keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) |
|
1405 | + else if ($keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) |
|
1406 | 1406 | { |
1407 | 1407 | $_msgData = $this->_msgContent; |
1408 | 1408 | $_msgData = $_msgData[$_types[0]]; |
1409 | 1409 | |
1410 | - $content = 'Content-Type: ' . $_msgData['mimeType'] . '; charset="' . $this->getCharSet() . '"' . "\r\n" |
|
1411 | - . 'Content-Transfer-Encoding: ' . $this->getTransEncodeType() . "\r\n" |
|
1412 | - . 'Content-Disposition: inline' . "\r\n" |
|
1413 | - . 'Content-Description: message' . "\r\n"; |
|
1410 | + $content = 'Content-Type: '.$_msgData['mimeType'].'; charset="'.$this->getCharSet().'"'."\r\n" |
|
1411 | + . 'Content-Transfer-Encoding: '.$this->getTransEncodeType()."\r\n" |
|
1412 | + . 'Content-Disposition: inline'."\r\n" |
|
1413 | + . 'Content-Description: message'."\r\n"; |
|
1414 | 1414 | |
1415 | - if ( $this->getMD5flag() ) |
|
1416 | - $content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n"; |
|
1415 | + if ($this->getMD5flag()) |
|
1416 | + $content .= 'Content-MD5: '.$_msgData['md5']."\r\n"; |
|
1417 | 1417 | |
1418 | 1418 | $content .= "\r\n" |
1419 | - . $_msgData['data'] . "\r\n"; |
|
1419 | + . $_msgData['data']."\r\n"; |
|
1420 | 1420 | } |
1421 | 1421 | |
1422 | 1422 | // If we have more than ONE, we use the multi-part format |
1423 | - else if( $keyCount >= 1 || ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) |
|
1423 | + else if ($keyCount >= 1 || !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) |
|
1424 | 1424 | { |
1425 | 1425 | // Since this is an actual multi-part message |
1426 | 1426 | // We need to define a content message Boundary |
1427 | 1427 | // NOTE: This was 'multipart/alternative', but Windows based mail servers have issues with this. |
1428 | 1428 | |
1429 | 1429 | //$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"' . "\r\n"; |
1430 | - $content = 'Content-Type: multipart/mixed; boundary="' . $this->_getBoundary('mixed') . '"' . "\r\n"; |
|
1430 | + $content = 'Content-Type: multipart/mixed; boundary="'.$this->_getBoundary('mixed').'"'."\r\n"; |
|
1431 | 1431 | |
1432 | 1432 | // . "\r\n" |
1433 | 1433 | // . 'This is a multi-part message in MIME format.' . "\r\n"; |
1434 | 1434 | $content .= "Content-Transfer-Encoding: 8bit\r\n"; |
1435 | 1435 | $content .= "\r\n"; |
1436 | 1436 | |
1437 | - $content .= "--" . $this->_getBoundary('mixed') . "\r\n"; |
|
1437 | + $content .= "--".$this->_getBoundary('mixed')."\r\n"; |
|
1438 | 1438 | |
1439 | 1439 | if (key_exists('image', $this->_msgContent)) // If inline image found |
1440 | 1440 | { |
1441 | - $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; |
|
1441 | + $content .= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"'."\r\n"; |
|
1442 | 1442 | $content .= "\r\n"; |
1443 | - $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; |
|
1443 | + $content .= "--".$this->_getBoundary('alternative')."\r\n"; |
|
1444 | 1444 | } |
1445 | 1445 | |
1446 | 1446 | |
@@ -1448,93 +1448,93 @@ discard block |
||
1448 | 1448 | |
1449 | 1449 | |
1450 | 1450 | // Loop through message content array |
1451 | - foreach ($this->_msgContent as $type => $_content ) |
|
1451 | + foreach ($this->_msgContent as $type => $_content) |
|
1452 | 1452 | { |
1453 | - if ( $type == 'attachment' ) |
|
1453 | + if ($type == 'attachment') |
|
1454 | 1454 | { |
1455 | 1455 | // loop through all attachments |
1456 | - foreach ( $_content as $_file => $_data ) |
|
1456 | + foreach ($_content as $_file => $_data) |
|
1457 | 1457 | { |
1458 | - $content .= "--" . $this->_getBoundary('mixed') . "\r\n" |
|
1459 | - . 'Content-Disposition: attachment; filename="' . $_data['fileName'] . '"' . "\r\n" |
|
1460 | - . 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['fileName'] . '"' . "\r\n" |
|
1461 | - . 'Content-Transfer-Encoding: base64' . "\r\n" |
|
1462 | - . 'Content-Description: File Attachment' . "\r\n"; |
|
1458 | + $content .= "--".$this->_getBoundary('mixed')."\r\n" |
|
1459 | + . 'Content-Disposition: attachment; filename="'.$_data['fileName'].'"'."\r\n" |
|
1460 | + . 'Content-Type: '.$_data['mimeType'].'; name="'.$_data['fileName'].'"'."\r\n" |
|
1461 | + . 'Content-Transfer-Encoding: base64'."\r\n" |
|
1462 | + . 'Content-Description: File Attachment'."\r\n"; |
|
1463 | 1463 | |
1464 | - if ( $this->getMD5flag() ) |
|
1465 | - $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; |
|
1464 | + if ($this->getMD5flag()) |
|
1465 | + $content .= 'Content-MD5: '.$_data['md5']."\r\n"; |
|
1466 | 1466 | |
1467 | - $content .= "\r\n" . $_data['data'] . "\r\n\r\n"; |
|
1467 | + $content .= "\r\n".$_data['data']."\r\n\r\n"; |
|
1468 | 1468 | } |
1469 | 1469 | } |
1470 | 1470 | // @CHANGE LDR |
1471 | - else if ( $type == 'image' ) |
|
1471 | + else if ($type == 'image') |
|
1472 | 1472 | { |
1473 | 1473 | // loop through all images |
1474 | - foreach ( $_content as $_image => $_data ) |
|
1474 | + foreach ($_content as $_image => $_data) |
|
1475 | 1475 | { |
1476 | - $content .= "--" . $this->_getBoundary('related') . "\r\n"; // always related for an inline image |
|
1476 | + $content .= "--".$this->_getBoundary('related')."\r\n"; // always related for an inline image |
|
1477 | 1477 | |
1478 | - $content .= 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['imageName'] . '"' . "\r\n" |
|
1479 | - . 'Content-Transfer-Encoding: base64' . "\r\n" |
|
1480 | - . 'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n" |
|
1481 | - . 'Content-ID: <' . $_data['cid'] . '> ' . "\r\n"; |
|
1478 | + $content .= 'Content-Type: '.$_data['mimeType'].'; name="'.$_data['imageName'].'"'."\r\n" |
|
1479 | + . 'Content-Transfer-Encoding: base64'."\r\n" |
|
1480 | + . 'Content-Disposition: inline; filename="'.$_data['imageName'].'"'."\r\n" |
|
1481 | + . 'Content-ID: <'.$_data['cid'].'> '."\r\n"; |
|
1482 | 1482 | |
1483 | - if ( $this->getMD5flag() ) |
|
1484 | - $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; |
|
1483 | + if ($this->getMD5flag()) |
|
1484 | + $content .= 'Content-MD5: '.$_data['md5']."\r\n"; |
|
1485 | 1485 | |
1486 | 1486 | $content .= "\r\n" |
1487 | - . $_data['data'] . "\r\n"; |
|
1487 | + . $_data['data']."\r\n"; |
|
1488 | 1488 | } |
1489 | 1489 | |
1490 | 1490 | // always end related and end alternative after inline images |
1491 | - $content.= "--" . $this->_getBoundary('related') . "--" . "\r\n"; |
|
1492 | - $content.= "\r\n" . "--" . $this->_getBoundary('alternative') . "--" . "\r\n"; |
|
1493 | - $content.= "\r\n"; |
|
1491 | + $content .= "--".$this->_getBoundary('related')."--"."\r\n"; |
|
1492 | + $content .= "\r\n"."--".$this->_getBoundary('alternative')."--"."\r\n"; |
|
1493 | + $content .= "\r\n"; |
|
1494 | 1494 | } |
1495 | 1495 | else |
1496 | 1496 | { |
1497 | 1497 | if (key_exists('image', $this->_msgContent)) |
1498 | 1498 | { |
1499 | - $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n"; |
|
1500 | - $content.= "\r\n" . ($_content['dataText']?$_content['dataText']:strip_tags($_content['data'])) . "\r\n"; // Add plain text message |
|
1501 | - $content.= "--" . $this->_getBoundary('alternative') . "\r\n"; |
|
1502 | - $content.= 'Content-Type: multipart/related; boundary="' . $this->_getBoundary('related') . '"' . "\r\n"; |
|
1503 | - $content.= "\r\n"; |
|
1504 | - $content.= "--" . $this->_getBoundary('related') . "\r\n"; |
|
1499 | + $content .= "Content-Type: text/plain; charset=".$this->getCharSet()."\r\n"; |
|
1500 | + $content .= "\r\n".($_content['dataText'] ? $_content['dataText'] : strip_tags($_content['data']))."\r\n"; // Add plain text message |
|
1501 | + $content .= "--".$this->_getBoundary('alternative')."\r\n"; |
|
1502 | + $content .= 'Content-Type: multipart/related; boundary="'.$this->_getBoundary('related').'"'."\r\n"; |
|
1503 | + $content .= "\r\n"; |
|
1504 | + $content .= "--".$this->_getBoundary('related')."\r\n"; |
|
1505 | 1505 | } |
1506 | 1506 | |
1507 | - if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part |
|
1507 | + if (!key_exists('image', $this->_msgContent) && $_content['dataText'] && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part |
|
1508 | 1508 | { |
1509 | - $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; |
|
1509 | + $content .= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"'."\r\n"; |
|
1510 | 1510 | $content .= "\r\n"; |
1511 | - $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; |
|
1511 | + $content .= "--".$this->_getBoundary('alternative')."\r\n"; |
|
1512 | 1512 | |
1513 | - $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n"; |
|
1514 | - $content.= "\r\n". $_content['dataText'] . "\r\n"; |
|
1515 | - $content.= "--" . $this->_getBoundary('alternative') . "\r\n"; |
|
1513 | + $content .= "Content-Type: text/plain; charset=".$this->getCharSet()."\r\n"; |
|
1514 | + $content .= "\r\n".$_content['dataText']."\r\n"; |
|
1515 | + $content .= "--".$this->_getBoundary('alternative')."\r\n"; |
|
1516 | 1516 | } |
1517 | 1517 | |
1518 | - $content .= 'Content-Type: ' . $_content['mimeType'] . '; ' |
|
1518 | + $content .= 'Content-Type: '.$_content['mimeType'].'; ' |
|
1519 | 1519 | // . 'charset="' . $this->getCharSet() . '"'; |
1520 | - . 'charset=' . $this->getCharSet() . ''; |
|
1520 | + . 'charset='.$this->getCharSet().''; |
|
1521 | 1521 | |
1522 | 1522 | // $content .= ( $type == 'html') ? '; name="HTML Part"' : ''; |
1523 | - $content .= "\r\n"; |
|
1523 | + $content .= "\r\n"; |
|
1524 | 1524 | // $content .= 'Content-Transfer-Encoding: '; |
1525 | 1525 | // $content .= ($type == 'html') ? 'quoted-printable' : $this->getTransEncodeType(); |
1526 | 1526 | // $content .= "\r\n" |
1527 | 1527 | // . 'Content-Disposition: inline' . "\r\n" |
1528 | 1528 | // . 'Content-Description: ' . $type . ' message' . "\r\n"; |
1529 | 1529 | |
1530 | - if ( $this->getMD5flag() ) |
|
1531 | - $content .= 'Content-MD5: ' . $_content['md5'] . "\r\n"; |
|
1530 | + if ($this->getMD5flag()) |
|
1531 | + $content .= 'Content-MD5: '.$_content['md5']."\r\n"; |
|
1532 | 1532 | |
1533 | - $content .= "\r\n" . $_content['data'] . "\r\n"; |
|
1533 | + $content .= "\r\n".$_content['data']."\r\n"; |
|
1534 | 1534 | |
1535 | - if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part |
|
1535 | + if (!key_exists('image', $this->_msgContent) && $_content['dataText'] && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part |
|
1536 | 1536 | { |
1537 | - $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n"; |
|
1537 | + $content .= "--".$this->_getBoundary('alternative')."--"."\r\n"; |
|
1538 | 1538 | } |
1539 | 1539 | |
1540 | 1540 | $content .= "\r\n"; |
@@ -1543,7 +1543,7 @@ discard block |
||
1543 | 1543 | |
1544 | 1544 | // Close message boundries |
1545 | 1545 | // $content .= "\r\n--" . $this->_getBoundary() . '--' . "\r\n" ; |
1546 | - $content .= "--" . $this->_getBoundary('mixed') . '--' . "\r\n" ; |
|
1546 | + $content .= "--".$this->_getBoundary('mixed').'--'."\r\n"; |
|
1547 | 1547 | } |
1548 | 1548 | |
1549 | 1549 | return $content; |
@@ -1560,15 +1560,15 @@ discard block |
||
1560 | 1560 | */ |
1561 | 1561 | function setAttachment($strContent, $strFileName = 'unknown', $strMimeType = 'unknown') |
1562 | 1562 | { |
1563 | - if ( $strContent ) |
|
1563 | + if ($strContent) |
|
1564 | 1564 | { |
1565 | - $strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n")); // 76 max is defined into http://tools.ietf.org/html/rfc2047 |
|
1565 | + $strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n")); // 76 max is defined into http://tools.ietf.org/html/rfc2047 |
|
1566 | 1566 | |
1567 | 1567 | $this->_msgContent['attachment'][$strFileName]['mimeType'] = $strMimeType; |
1568 | 1568 | $this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName; |
1569 | 1569 | $this->_msgContent['attachment'][$strFileName]['data'] = $strContent; |
1570 | 1570 | |
1571 | - if ( $this->getMD5flag() ) |
|
1571 | + if ($this->getMD5flag()) |
|
1572 | 1572 | $this->_msgContent['attachment'][$strFileName]['md5'] = dol_hash($strContent, 3); |
1573 | 1573 | } |
1574 | 1574 | } |
@@ -1595,7 +1595,7 @@ discard block |
||
1595 | 1595 | $this->_msgContent['image'][$strImageName]['cid'] = $strImageCid; |
1596 | 1596 | $this->_msgContent['image'][$strImageName]['data'] = $strContent; |
1597 | 1597 | |
1598 | - if ( $this->getMD5flag() ) |
|
1598 | + if ($this->getMD5flag()) |
|
1599 | 1599 | $this->_msgContent['image'][$strImageName]['md5'] = dol_hash($strContent, 3); |
1600 | 1600 | } |
1601 | 1601 | } |
@@ -1615,8 +1615,8 @@ discard block |
||
1615 | 1615 | */ |
1616 | 1616 | function setSensitivity($_value = 0) |
1617 | 1617 | { |
1618 | - if ( ( is_numeric($_value) ) && |
|
1619 | - ( ( $_value >= 0 ) && ( $_value <= 3 ) ) ) |
|
1618 | + if ((is_numeric($_value)) && |
|
1619 | + (($_value >= 0) && ($_value <= 3))) |
|
1620 | 1620 | $this->_msgSensitivity = $_value; |
1621 | 1621 | } |
1622 | 1622 | |
@@ -1648,10 +1648,10 @@ discard block |
||
1648 | 1648 | * @param integer $_value Message Priority |
1649 | 1649 | * @return void |
1650 | 1650 | */ |
1651 | - function setPriority ( $_value = 3 ) |
|
1651 | + function setPriority($_value = 3) |
|
1652 | 1652 | { |
1653 | - if ( ( is_numeric($_value) ) && |
|
1654 | - ( ( $_value >= 0 ) && ( $_value <= 5 ) ) ) |
|
1653 | + if ((is_numeric($_value)) && |
|
1654 | + (($_value >= 0) && ($_value <= 5))) |
|
1655 | 1655 | $this->_msgPriority = $_value; |
1656 | 1656 | } |
1657 | 1657 | |
@@ -1669,9 +1669,9 @@ discard block |
||
1669 | 1669 | */ |
1670 | 1670 | function getPriority() |
1671 | 1671 | { |
1672 | - return 'Importance: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n" |
|
1673 | - . 'Priority: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n" |
|
1674 | - . 'X-Priority: ' . $this->_msgPriority . ' (' . $this->_aryPriority[$this->_msgPriority] . ')' . "\r\n"; |
|
1672 | + return 'Importance: '.$this->_aryPriority[$this->_msgPriority]."\r\n" |
|
1673 | + . 'Priority: '.$this->_aryPriority[$this->_msgPriority]."\r\n" |
|
1674 | + . 'X-Priority: '.$this->_msgPriority.' ('.$this->_aryPriority[$this->_msgPriority].')'."\r\n"; |
|
1675 | 1675 | } |
1676 | 1676 | |
1677 | 1677 | /** |
@@ -1705,7 +1705,7 @@ discard block |
||
1705 | 1705 | */ |
1706 | 1706 | function setXheader($strXdata) |
1707 | 1707 | { |
1708 | - if ( $strXdata ) |
|
1708 | + if ($strXdata) |
|
1709 | 1709 | $this->_msgXheader[] = $strXdata; |
1710 | 1710 | } |
1711 | 1711 | |
@@ -1726,7 +1726,7 @@ discard block |
||
1726 | 1726 | */ |
1727 | 1727 | function _setBoundary() |
1728 | 1728 | { |
1729 | - $this->_smtpsBoundary = "multipart_x." . time() . ".x_boundary"; |
|
1729 | + $this->_smtpsBoundary = "multipart_x.".time().".x_boundary"; |
|
1730 | 1730 | $this->_smtpsRelatedBoundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3); |
1731 | 1731 | $this->_smtpsAlternativeBoundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3); |
1732 | 1732 | } |
@@ -1737,7 +1737,7 @@ discard block |
||
1737 | 1737 | * @param string $type Type of boundary |
1738 | 1738 | * @return string $_smtpsBoundary MIME message Boundary |
1739 | 1739 | */ |
1740 | - function _getBoundary($type='mixed') |
|
1740 | + function _getBoundary($type = 'mixed') |
|
1741 | 1741 | { |
1742 | 1742 | if ($type == 'mixed') return $this->_smtpsBoundary; |
1743 | 1743 | else if ($type == 'related') return $this->_smtpsRelatedBoundary; |
@@ -1763,11 +1763,11 @@ discard block |
||
1763 | 1763 | $server_response = ''; |
1764 | 1764 | |
1765 | 1765 | // avoid infinite loop |
1766 | - $limit=0; |
|
1766 | + $limit = 0; |
|
1767 | 1767 | |
1768 | - while (substr($server_response,3,1) != ' ' && $limit<100) |
|
1768 | + while (substr($server_response, 3, 1) != ' ' && $limit < 100) |
|
1769 | 1769 | { |
1770 | - if (! ($server_response = fgets($socket, 256))) |
|
1770 | + if (!($server_response = fgets($socket, 256))) |
|
1771 | 1771 | { |
1772 | 1772 | $this->_setErr(121, "Couldn't get mail server response codes"); |
1773 | 1773 | $_retVal = false; |
@@ -1776,7 +1776,7 @@ discard block |
||
1776 | 1776 | $limit++; |
1777 | 1777 | } |
1778 | 1778 | |
1779 | - if (! (substr($server_response, 0, 3) == $response)) |
|
1779 | + if (!(substr($server_response, 0, 3) == $response)) |
|
1780 | 1780 | { |
1781 | 1781 | $this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: $server_response"); |
1782 | 1782 | $_retVal = false; |
@@ -1793,13 +1793,13 @@ discard block |
||
1793 | 1793 | * @param string $CRLF CRLF |
1794 | 1794 | * @return boolean|null True or false |
1795 | 1795 | */ |
1796 | - function socket_send_str( $_strSend, $_returnCode = null, $CRLF = "\r\n" ) |
|
1796 | + function socket_send_str($_strSend, $_returnCode = null, $CRLF = "\r\n") |
|
1797 | 1797 | { |
1798 | - if ($this->_debug) $this->log.=$_strSend; // @CHANGE LDR for log |
|
1799 | - fputs($this->socket, $_strSend . $CRLF); |
|
1800 | - if ($this->_debug) $this->log.=' ('.$_returnCode.')' . $CRLF; |
|
1798 | + if ($this->_debug) $this->log .= $_strSend; // @CHANGE LDR for log |
|
1799 | + fputs($this->socket, $_strSend.$CRLF); |
|
1800 | + if ($this->_debug) $this->log .= ' ('.$_returnCode.')'.$CRLF; |
|
1801 | 1801 | |
1802 | - if ( $_returnCode ) |
|
1802 | + if ($_returnCode) |
|
1803 | 1803 | return $this->server_parse($this->socket, $_returnCode); |
1804 | 1804 | } |
1805 | 1805 | |
@@ -1813,10 +1813,10 @@ discard block |
||
1813 | 1813 | * @param string $_errMsg Error Message |
1814 | 1814 | * @return void |
1815 | 1815 | */ |
1816 | - function _setErr ( $_errNum, $_errMsg ) |
|
1816 | + function _setErr($_errNum, $_errMsg) |
|
1817 | 1817 | { |
1818 | - $this->_smtpsErrors[] = array( 'num' => $_errNum, |
|
1819 | - 'msg' => $_errMsg ); |
|
1818 | + $this->_smtpsErrors[] = array('num' => $_errNum, |
|
1819 | + 'msg' => $_errMsg); |
|
1820 | 1820 | } |
1821 | 1821 | |
1822 | 1822 | /** |
@@ -1828,9 +1828,9 @@ discard block |
||
1828 | 1828 | { |
1829 | 1829 | $_errMsg = array(); |
1830 | 1830 | |
1831 | - foreach ( $this->_smtpsErrors as $_err => $_info ) |
|
1831 | + foreach ($this->_smtpsErrors as $_err => $_info) |
|
1832 | 1832 | { |
1833 | - $_errMsg[] = 'Error [' . $_info['num'] .']: '. $_info['msg']; |
|
1833 | + $_errMsg[] = 'Error ['.$_info['num'].']: '.$_info['msg']; |
|
1834 | 1834 | } |
1835 | 1835 | |
1836 | 1836 | return implode("\n", $_errMsg); |
@@ -300,8 +300,9 @@ discard block |
||
300 | 300 | */ |
301 | 301 | function setErrorsTo($_strErrorsTo) |
302 | 302 | { |
303 | - if ( $_strErrorsTo ) |
|
304 | - $this->_errorsTo = $this->_strip_email($_strErrorsTo); |
|
303 | + if ( $_strErrorsTo ) { |
|
304 | + $this->_errorsTo = $this->_strip_email($_strErrorsTo); |
|
305 | + } |
|
305 | 306 | } |
306 | 307 | |
307 | 308 | /** |
@@ -314,10 +315,11 @@ discard block |
||
314 | 315 | { |
315 | 316 | $_retValue = ''; |
316 | 317 | |
317 | - if ( $_part === true ) |
|
318 | - $_retValue = $this->_errorsTo; |
|
319 | - else |
|
320 | - $_retValue = $this->_errorsTo[$_part]; |
|
318 | + if ( $_part === true ) { |
|
319 | + $_retValue = $this->_errorsTo; |
|
320 | + } else { |
|
321 | + $_retValue = $this->_errorsTo[$_part]; |
|
322 | + } |
|
321 | 323 | |
322 | 324 | return $_retValue; |
323 | 325 | } |
@@ -371,8 +373,7 @@ discard block |
||
371 | 373 | { |
372 | 374 | $this->_setErr(99, $host . ' is either offline or is an invalid host name.'); |
373 | 375 | $_retVal = false; |
374 | - } |
|
375 | - else |
|
376 | + } else |
|
376 | 377 | { |
377 | 378 | //See if we can connect to the SMTP server |
378 | 379 | if ($this->socket = @fsockopen( |
@@ -381,23 +382,28 @@ discard block |
||
381 | 382 | $this->errno, // actual system level error |
382 | 383 | $this->errstr, // and any text that goes with the error |
383 | 384 | $this->_smtpTimeout |
384 | - )) // timeout for reading/writing data over the socket |
|
385 | + )) { |
|
386 | + // timeout for reading/writing data over the socket |
|
385 | 387 | { |
386 | 388 | // Fix from PHP SMTP class by 'Chris Ryan' |
387 | 389 | // Sometimes the SMTP server takes a little longer to respond |
388 | 390 | // so we will give it a longer timeout for the first read |
389 | 391 | // Windows still does not have support for this timeout function |
390 | 392 | if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0); |
393 | + } |
|
391 | 394 | |
392 | 395 | // Check response from Server |
393 | - if ( $_retVal = $this->server_parse($this->socket, "220") ) |
|
394 | - $_retVal = $this->socket; |
|
396 | + if ( $_retVal = $this->server_parse($this->socket, "220") ) { |
|
397 | + $_retVal = $this->socket; |
|
398 | + } |
|
395 | 399 | } |
396 | 400 | // This connection attempt failed. |
397 | 401 | else |
398 | 402 | { |
399 | 403 | // @CHANGE LDR |
400 | - if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort(); |
|
404 | + if (empty($this->errstr)) { |
|
405 | + $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort(); |
|
406 | + } |
|
401 | 407 | $this->_setErr($this->errno, $this->errstr); |
402 | 408 | $_retVal = false; |
403 | 409 | } |
@@ -425,7 +431,9 @@ discard block |
||
425 | 431 | $host=preg_replace('@ssl://@i','',$host); // Remove prefix |
426 | 432 | $host=preg_replace('@tls://@i','',$host); // Remove prefix |
427 | 433 | |
428 | - if ($usetls) $host='tls://'.$host; |
|
434 | + if ($usetls) { |
|
435 | + $host='tls://'.$host; |
|
436 | + } |
|
429 | 437 | |
430 | 438 | $hosth = $host; |
431 | 439 | |
@@ -502,10 +510,10 @@ discard block |
||
502 | 510 | |
503 | 511 | // The error here just means the ID/password combo doesn't work. |
504 | 512 | // There is not a method to determine which is the problem, ID or password |
505 | - if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') ) |
|
506 | - $this->_setErr(130, 'Invalid Authentication Credentials.'); |
|
507 | - } |
|
508 | - else |
|
513 | + if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') ) { |
|
514 | + $this->_setErr(130, 'Invalid Authentication Credentials.'); |
|
515 | + } |
|
516 | + } else |
|
509 | 517 | { |
510 | 518 | $this->_setErr(126, '"' . $host . '" does not support authenticated connections.'); |
511 | 519 | } |
@@ -668,14 +676,17 @@ discard block |
||
668 | 676 | { |
669 | 677 | // Set these properties ONLY if they are set in the php.ini file. |
670 | 678 | // Otherwise the default values will be used. |
671 | - if ( $_host = ini_get('SMTPs') ) |
|
672 | - $this->setHost($_host); |
|
679 | + if ( $_host = ini_get('SMTPs') ) { |
|
680 | + $this->setHost($_host); |
|
681 | + } |
|
673 | 682 | |
674 | - if ( $_port = ini_get('smtp_port') ) |
|
675 | - $this->setPort($_port); |
|
683 | + if ( $_port = ini_get('smtp_port') ) { |
|
684 | + $this->setPort($_port); |
|
685 | + } |
|
676 | 686 | |
677 | - if ( $_from = ini_get('sendmail_from') ) |
|
678 | - $this->setFrom($_from); |
|
687 | + if ( $_from = ini_get('sendmail_from') ) { |
|
688 | + $this->setFrom($_from); |
|
689 | + } |
|
679 | 690 | } |
680 | 691 | |
681 | 692 | // Send back what we have |
@@ -694,8 +705,9 @@ discard block |
||
694 | 705 | function setTransportType($_type = 0) |
695 | 706 | { |
696 | 707 | if ( ( is_numeric($_type) ) && |
697 | - ( ( $_type >= 0 ) && ( $_type <= 3 ) ) ) |
|
698 | - $this->_transportType = $_type; |
|
708 | + ( ( $_type >= 0 ) && ( $_type <= 3 ) ) ) { |
|
709 | + $this->_transportType = $_type; |
|
710 | + } |
|
699 | 711 | } |
700 | 712 | |
701 | 713 | /** |
@@ -736,8 +748,9 @@ discard block |
||
736 | 748 | */ |
737 | 749 | function setHost($_strHost) |
738 | 750 | { |
739 | - if ( $_strHost ) |
|
740 | - $this->_smtpsHost = $_strHost; |
|
751 | + if ( $_strHost ) { |
|
752 | + $this->_smtpsHost = $_strHost; |
|
753 | + } |
|
741 | 754 | } |
742 | 755 | |
743 | 756 | /** |
@@ -762,8 +775,9 @@ discard block |
||
762 | 775 | function setPort($_intPort) |
763 | 776 | { |
764 | 777 | if ( ( is_numeric($_intPort) ) && |
765 | - ( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) ) |
|
766 | - $this->_smtpsPort = $_intPort; |
|
778 | + ( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) ) { |
|
779 | + $this->_smtpsPort = $_intPort; |
|
780 | + } |
|
767 | 781 | } |
768 | 782 | |
769 | 783 | /** |
@@ -828,8 +842,9 @@ discard block |
||
828 | 842 | */ |
829 | 843 | function setCharSet($_strCharSet) |
830 | 844 | { |
831 | - if ( $_strCharSet ) |
|
832 | - $this->_smtpsCharSet = $_strCharSet; |
|
845 | + if ( $_strCharSet ) { |
|
846 | + $this->_smtpsCharSet = $_strCharSet; |
|
847 | + } |
|
833 | 848 | } |
834 | 849 | |
835 | 850 | /** |
@@ -859,8 +874,9 @@ discard block |
||
859 | 874 | */ |
860 | 875 | function setTransEncode($_strTransEncode) |
861 | 876 | { |
862 | - if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes)) |
|
863 | - $this->_smtpsTransEncode = $_strTransEncode; |
|
877 | + if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes)) { |
|
878 | + $this->_smtpsTransEncode = $_strTransEncode; |
|
879 | + } |
|
864 | 880 | } |
865 | 881 | |
866 | 882 | /** |
@@ -891,8 +907,9 @@ discard block |
||
891 | 907 | */ |
892 | 908 | function setTransEncodeType($_strTransEncodeType) |
893 | 909 | { |
894 | - if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes)) |
|
895 | - $this->_smtpsTransEncodeType = $_strTransEncodeType; |
|
910 | + if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes)) { |
|
911 | + $this->_smtpsTransEncodeType = $_strTransEncodeType; |
|
912 | + } |
|
896 | 913 | } |
897 | 914 | |
898 | 915 | /** |
@@ -916,8 +933,9 @@ discard block |
||
916 | 933 | */ |
917 | 934 | function setFrom($_strFrom) |
918 | 935 | { |
919 | - if ( $_strFrom ) |
|
920 | - $this->_msgFrom = $this->_strip_email($_strFrom); |
|
936 | + if ( $_strFrom ) { |
|
937 | + $this->_msgFrom = $this->_strip_email($_strFrom); |
|
938 | + } |
|
921 | 939 | } |
922 | 940 | |
923 | 941 | /** |
@@ -930,10 +948,11 @@ discard block |
||
930 | 948 | { |
931 | 949 | $_retValue = ''; |
932 | 950 | |
933 | - if ( $_part === true ) |
|
934 | - $_retValue = $this->_msgFrom; |
|
935 | - else |
|
936 | - $_retValue = $this->_msgFrom[$_part]; |
|
951 | + if ( $_part === true ) { |
|
952 | + $_retValue = $this->_msgFrom; |
|
953 | + } else { |
|
954 | + $_retValue = $this->_msgFrom[$_part]; |
|
955 | + } |
|
937 | 956 | |
938 | 957 | return $_retValue; |
939 | 958 | } |
@@ -946,8 +965,9 @@ discard block |
||
946 | 965 | */ |
947 | 966 | function setReplyTo($_strReplyTo) |
948 | 967 | { |
949 | - if ( $_strReplyTo ) |
|
950 | - $this->_msgReplyTo = $this->_strip_email($_strReplyTo); |
|
968 | + if ( $_strReplyTo ) { |
|
969 | + $this->_msgReplyTo = $this->_strip_email($_strReplyTo); |
|
970 | + } |
|
951 | 971 | } |
952 | 972 | |
953 | 973 | /** |
@@ -960,10 +980,11 @@ discard block |
||
960 | 980 | { |
961 | 981 | $_retValue = ''; |
962 | 982 | |
963 | - if ( $_part === true ) |
|
964 | - $_retValue = $this->_msgReplyTo; |
|
965 | - else |
|
966 | - $_retValue = $this->_msgReplyTo[$_part]; |
|
983 | + if ( $_part === true ) { |
|
984 | + $_retValue = $this->_msgReplyTo; |
|
985 | + } else { |
|
986 | + $_retValue = $this->_msgReplyTo[$_part]; |
|
987 | + } |
|
967 | 988 | |
968 | 989 | return $_retValue; |
969 | 990 | } |
@@ -992,13 +1013,15 @@ discard block |
||
992 | 1013 | if ( is_string($_addrList) ) |
993 | 1014 | { |
994 | 1015 | // This could be a COMMA delimited string |
995 | - if ( strstr($_addrList, ',') ) |
|
996 | - // "explode "list" into an array |
|
1016 | + if ( strstr($_addrList, ',') ) { |
|
1017 | + // "explode "list" into an array |
|
997 | 1018 | $_addrList = explode(',', $_addrList); |
1019 | + } |
|
998 | 1020 | |
999 | 1021 | // Stick it in an array |
1000 | - else |
|
1001 | - $_addrList = array($_addrList); |
|
1022 | + else { |
|
1023 | + $_addrList = array($_addrList); |
|
1024 | + } |
|
1002 | 1025 | } |
1003 | 1026 | |
1004 | 1027 | // take the array of addresses and split them further |
@@ -1070,13 +1093,14 @@ discard block |
||
1070 | 1093 | if ( count($_tmpAry) == 2 ) |
1071 | 1094 | { |
1072 | 1095 | // We may not really have a "Real Name" |
1073 | - if ( $_tmpAry[0]) |
|
1074 | - $_aryEmail['real'] = trim($_tmpAry[0], ' ">'); |
|
1096 | + if ( $_tmpAry[0]) { |
|
1097 | + $_aryEmail['real'] = trim($_tmpAry[0], ' ">'); |
|
1098 | + } |
|
1075 | 1099 | |
1076 | 1100 | $_aryEmail['addr'] = $_tmpAry[1]; |
1101 | + } else { |
|
1102 | + $_aryEmail['addr'] = $_tmpAry[0]; |
|
1077 | 1103 | } |
1078 | - else |
|
1079 | - $_aryEmail['addr'] = $_tmpAry[0]; |
|
1080 | 1104 | |
1081 | 1105 | // Pull User Name and Host.tld apart |
1082 | 1106 | list($_aryEmail['user'], $_aryEmail['host'] ) = explode('@', $_aryEmail['addr']); |
@@ -1139,12 +1163,13 @@ discard block |
||
1139 | 1163 | { |
1140 | 1164 | foreach ( $this->_msgRecipients[$_host][$_which] as $_addr => $_realName ) |
1141 | 1165 | { |
1142 | - if ( $_realName ) // @CHANGE LDR |
|
1166 | + if ( $_realName ) { |
|
1167 | + // @CHANGE LDR |
|
1143 | 1168 | { |
1144 | 1169 | $_realName = '"' . $_realName . '"'; |
1145 | - $_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>'; |
|
1146 | 1170 | } |
1147 | - else |
|
1171 | + $_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>'; |
|
1172 | + } else |
|
1148 | 1173 | { |
1149 | 1174 | $_RCPT_list[] = $_addr . '@' . $_host; |
1150 | 1175 | } |
@@ -1153,14 +1178,12 @@ discard block |
||
1153 | 1178 | } |
1154 | 1179 | |
1155 | 1180 | return implode(', ', $_RCPT_list); |
1156 | - } |
|
1157 | - else |
|
1181 | + } else |
|
1158 | 1182 | { |
1159 | 1183 | $this->_setErr(101, 'No eMail Address for message to be sent to.'); |
1160 | 1184 | return false; |
1161 | 1185 | } |
1162 | - } |
|
1163 | - else |
|
1186 | + } else |
|
1164 | 1187 | { |
1165 | 1188 | $this->_setErr(102, 'eMail type not defined.'); |
1166 | 1189 | return false; |
@@ -1176,8 +1199,9 @@ discard block |
||
1176 | 1199 | */ |
1177 | 1200 | function setTO($_addrTo) |
1178 | 1201 | { |
1179 | - if ( $_addrTo ) |
|
1180 | - $this->_buildAddrList('to', $_addrTo); |
|
1202 | + if ( $_addrTo ) { |
|
1203 | + $this->_buildAddrList('to', $_addrTo); |
|
1204 | + } |
|
1181 | 1205 | } |
1182 | 1206 | |
1183 | 1207 | /** |
@@ -1198,8 +1222,9 @@ discard block |
||
1198 | 1222 | */ |
1199 | 1223 | function setCC($_strCC) |
1200 | 1224 | { |
1201 | - if ( $_strCC ) |
|
1202 | - $this->_buildAddrList('cc', $_strCC); |
|
1225 | + if ( $_strCC ) { |
|
1226 | + $this->_buildAddrList('cc', $_strCC); |
|
1227 | + } |
|
1203 | 1228 | } |
1204 | 1229 | |
1205 | 1230 | /** |
@@ -1220,8 +1245,9 @@ discard block |
||
1220 | 1245 | */ |
1221 | 1246 | function setBCC($_strBCC) |
1222 | 1247 | { |
1223 | - if ( $_strBCC ) |
|
1224 | - $this->_buildAddrList('bcc', $_strBCC); |
|
1248 | + if ( $_strBCC ) { |
|
1249 | + $this->_buildAddrList('bcc', $_strBCC); |
|
1250 | + } |
|
1225 | 1251 | } |
1226 | 1252 | |
1227 | 1253 | /** |
@@ -1242,8 +1268,9 @@ discard block |
||
1242 | 1268 | */ |
1243 | 1269 | function setSubject($_strSubject = '') |
1244 | 1270 | { |
1245 | - if ( $_strSubject ) |
|
1246 | - $this->_msgSubject = $_strSubject; |
|
1271 | + if ( $_strSubject ) { |
|
1272 | + $this->_msgSubject = $_strSubject; |
|
1273 | + } |
|
1247 | 1274 | } |
1248 | 1275 | |
1249 | 1276 | /** |
@@ -1268,8 +1295,9 @@ discard block |
||
1268 | 1295 | $_header = 'From: ' . $this->getFrom('org') . "\r\n" |
1269 | 1296 | . 'To: ' . $this->getTO() . "\r\n"; |
1270 | 1297 | |
1271 | - if ( $this->getCC() ) |
|
1272 | - $_header .= 'Cc: ' . $this->getCC() . "\r\n"; |
|
1298 | + if ( $this->getCC() ) { |
|
1299 | + $_header .= 'Cc: ' . $this->getCC() . "\r\n"; |
|
1300 | + } |
|
1273 | 1301 | |
1274 | 1302 | /* Note: |
1275 | 1303 | * BCC email addresses must be listed in the RCPT TO command list, |
@@ -1302,33 +1330,41 @@ discard block |
||
1302 | 1330 | $_header .= 'Message-ID: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n"; |
1303 | 1331 | $_header .= 'References: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n"; |
1304 | 1332 | $_header .= 'X-Dolibarr-TRACKID: ' . $trackid . "\r\n"; |
1305 | - } |
|
1306 | - else |
|
1333 | + } else |
|
1307 | 1334 | { |
1308 | 1335 | $_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n"; |
1309 | 1336 | } |
1310 | - if (! empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n"; |
|
1311 | - if ( $this->getMoreInHeader() ) |
|
1312 | - $_header .= $this->getMoreInHeader(); // Value must include the "\r\n"; |
|
1337 | + if (! empty($_SERVER['REMOTE_ADDR'])) { |
|
1338 | + $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n"; |
|
1339 | + } |
|
1340 | + if ( $this->getMoreInHeader() ) { |
|
1341 | + $_header .= $this->getMoreInHeader(); |
|
1342 | + } |
|
1343 | + // Value must include the "\r\n"; |
|
1313 | 1344 | |
1314 | 1345 | //$_header .= |
1315 | 1346 | // 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n" |
1316 | 1347 | // 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"; |
1317 | 1348 | |
1318 | - if ( $this->getSensitivity() ) |
|
1319 | - $_header .= 'Sensitivity: ' . $this->getSensitivity() . "\r\n"; |
|
1349 | + if ( $this->getSensitivity() ) { |
|
1350 | + $_header .= 'Sensitivity: ' . $this->getSensitivity() . "\r\n"; |
|
1351 | + } |
|
1320 | 1352 | |
1321 | - if ( $this->_msgPriority != 3 ) |
|
1322 | - $_header .= $this->getPriority(); |
|
1353 | + if ( $this->_msgPriority != 3 ) { |
|
1354 | + $_header .= $this->getPriority(); |
|
1355 | + } |
|
1323 | 1356 | |
1324 | 1357 | |
1325 | 1358 | // @CHANGE LDR |
1326 | - if ( $this->getDeliveryReceipt() ) |
|
1327 | - $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n"; |
|
1328 | - if ( $this->getErrorsTo() ) |
|
1329 | - $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n"; |
|
1330 | - if ( $this->getReplyTo() ) |
|
1331 | - $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n"; |
|
1359 | + if ( $this->getDeliveryReceipt() ) { |
|
1360 | + $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n"; |
|
1361 | + } |
|
1362 | + if ( $this->getErrorsTo() ) { |
|
1363 | + $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n"; |
|
1364 | + } |
|
1365 | + if ( $this->getReplyTo() ) { |
|
1366 | + $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n"; |
|
1367 | + } |
|
1332 | 1368 | |
1333 | 1369 | $_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n"; |
1334 | 1370 | $_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART?'MAIN_MAIL_USE_MULTI_PART':'No MAIN_MAIL_USE_MULTI_PART') . "\r\n"; |
@@ -1349,10 +1385,11 @@ discard block |
||
1349 | 1385 | { |
1350 | 1386 | //if ( $strContent ) |
1351 | 1387 | //{ |
1352 | - if ( $strType == 'html' ) |
|
1353 | - $strMimeType = 'text/html'; |
|
1354 | - else |
|
1355 | - $strMimeType = 'text/plain'; |
|
1388 | + if ( $strType == 'html' ) { |
|
1389 | + $strMimeType = 'text/html'; |
|
1390 | + } else { |
|
1391 | + $strMimeType = 'text/plain'; |
|
1392 | + } |
|
1356 | 1393 | |
1357 | 1394 | // Make RFC821 Compliant, replace bare linefeeds |
1358 | 1395 | $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent); |
@@ -1374,8 +1411,9 @@ discard block |
||
1374 | 1411 | $this->_msgContent[$strType]['data'] = $strContent; |
1375 | 1412 | $this->_msgContent[$strType]['dataText'] = $strContentAltText; |
1376 | 1413 | |
1377 | - if ( $this->getMD5flag() ) |
|
1378 | - $this->_msgContent[$strType]['md5'] = dol_hash($strContent, 3); |
|
1414 | + if ( $this->getMD5flag() ) { |
|
1415 | + $this->_msgContent[$strType]['md5'] = dol_hash($strContent, 3); |
|
1416 | + } |
|
1379 | 1417 | //} |
1380 | 1418 | } |
1381 | 1419 | |
@@ -1398,8 +1436,9 @@ discard block |
||
1398 | 1436 | $keyCount = count($_types); |
1399 | 1437 | |
1400 | 1438 | // If we have ZERO, we have a problem |
1401 | - if( $keyCount === 0 ) |
|
1402 | - die ("Sorry, no content"); |
|
1439 | + if( $keyCount === 0 ) { |
|
1440 | + die ("Sorry, no content"); |
|
1441 | + } |
|
1403 | 1442 | |
1404 | 1443 | // If we have ONE, we can use the simple format |
1405 | 1444 | else if( $keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) |
@@ -1412,8 +1451,9 @@ discard block |
||
1412 | 1451 | . 'Content-Disposition: inline' . "\r\n" |
1413 | 1452 | . 'Content-Description: message' . "\r\n"; |
1414 | 1453 | |
1415 | - if ( $this->getMD5flag() ) |
|
1416 | - $content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n"; |
|
1454 | + if ( $this->getMD5flag() ) { |
|
1455 | + $content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n"; |
|
1456 | + } |
|
1417 | 1457 | |
1418 | 1458 | $content .= "\r\n" |
1419 | 1459 | . $_msgData['data'] . "\r\n"; |
@@ -1436,9 +1476,11 @@ discard block |
||
1436 | 1476 | |
1437 | 1477 | $content .= "--" . $this->_getBoundary('mixed') . "\r\n"; |
1438 | 1478 | |
1439 | - if (key_exists('image', $this->_msgContent)) // If inline image found |
|
1479 | + if (key_exists('image', $this->_msgContent)) { |
|
1480 | + // If inline image found |
|
1440 | 1481 | { |
1441 | 1482 | $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; |
1483 | + } |
|
1442 | 1484 | $content .= "\r\n"; |
1443 | 1485 | $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; |
1444 | 1486 | } |
@@ -1461,8 +1503,9 @@ discard block |
||
1461 | 1503 | . 'Content-Transfer-Encoding: base64' . "\r\n" |
1462 | 1504 | . 'Content-Description: File Attachment' . "\r\n"; |
1463 | 1505 | |
1464 | - if ( $this->getMD5flag() ) |
|
1465 | - $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; |
|
1506 | + if ( $this->getMD5flag() ) { |
|
1507 | + $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; |
|
1508 | + } |
|
1466 | 1509 | |
1467 | 1510 | $content .= "\r\n" . $_data['data'] . "\r\n\r\n"; |
1468 | 1511 | } |
@@ -1480,8 +1523,9 @@ discard block |
||
1480 | 1523 | . 'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n" |
1481 | 1524 | . 'Content-ID: <' . $_data['cid'] . '> ' . "\r\n"; |
1482 | 1525 | |
1483 | - if ( $this->getMD5flag() ) |
|
1484 | - $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; |
|
1526 | + if ( $this->getMD5flag() ) { |
|
1527 | + $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; |
|
1528 | + } |
|
1485 | 1529 | |
1486 | 1530 | $content .= "\r\n" |
1487 | 1531 | . $_data['data'] . "\r\n"; |
@@ -1491,8 +1535,7 @@ discard block |
||
1491 | 1535 | $content.= "--" . $this->_getBoundary('related') . "--" . "\r\n"; |
1492 | 1536 | $content.= "\r\n" . "--" . $this->_getBoundary('alternative') . "--" . "\r\n"; |
1493 | 1537 | $content.= "\r\n"; |
1494 | - } |
|
1495 | - else |
|
1538 | + } else |
|
1496 | 1539 | { |
1497 | 1540 | if (key_exists('image', $this->_msgContent)) |
1498 | 1541 | { |
@@ -1504,9 +1547,11 @@ discard block |
||
1504 | 1547 | $content.= "--" . $this->_getBoundary('related') . "\r\n"; |
1505 | 1548 | } |
1506 | 1549 | |
1507 | - if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part |
|
1550 | + if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) { |
|
1551 | + // Add plain text message part before html part |
|
1508 | 1552 | { |
1509 | 1553 | $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; |
1554 | + } |
|
1510 | 1555 | $content .= "\r\n"; |
1511 | 1556 | $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; |
1512 | 1557 | |
@@ -1527,15 +1572,18 @@ discard block |
||
1527 | 1572 | // . 'Content-Disposition: inline' . "\r\n" |
1528 | 1573 | // . 'Content-Description: ' . $type . ' message' . "\r\n"; |
1529 | 1574 | |
1530 | - if ( $this->getMD5flag() ) |
|
1531 | - $content .= 'Content-MD5: ' . $_content['md5'] . "\r\n"; |
|
1575 | + if ( $this->getMD5flag() ) { |
|
1576 | + $content .= 'Content-MD5: ' . $_content['md5'] . "\r\n"; |
|
1577 | + } |
|
1532 | 1578 | |
1533 | 1579 | $content .= "\r\n" . $_content['data'] . "\r\n"; |
1534 | 1580 | |
1535 | - if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part |
|
1581 | + if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) { |
|
1582 | + // Add plain text message part after html part |
|
1536 | 1583 | { |
1537 | 1584 | $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n"; |
1538 | 1585 | } |
1586 | + } |
|
1539 | 1587 | |
1540 | 1588 | $content .= "\r\n"; |
1541 | 1589 | } |
@@ -1568,8 +1616,9 @@ discard block |
||
1568 | 1616 | $this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName; |
1569 | 1617 | $this->_msgContent['attachment'][$strFileName]['data'] = $strContent; |
1570 | 1618 | |
1571 | - if ( $this->getMD5flag() ) |
|
1572 | - $this->_msgContent['attachment'][$strFileName]['md5'] = dol_hash($strContent, 3); |
|
1619 | + if ( $this->getMD5flag() ) { |
|
1620 | + $this->_msgContent['attachment'][$strFileName]['md5'] = dol_hash($strContent, 3); |
|
1621 | + } |
|
1573 | 1622 | } |
1574 | 1623 | } |
1575 | 1624 | |
@@ -1595,8 +1644,9 @@ discard block |
||
1595 | 1644 | $this->_msgContent['image'][$strImageName]['cid'] = $strImageCid; |
1596 | 1645 | $this->_msgContent['image'][$strImageName]['data'] = $strContent; |
1597 | 1646 | |
1598 | - if ( $this->getMD5flag() ) |
|
1599 | - $this->_msgContent['image'][$strImageName]['md5'] = dol_hash($strContent, 3); |
|
1647 | + if ( $this->getMD5flag() ) { |
|
1648 | + $this->_msgContent['image'][$strImageName]['md5'] = dol_hash($strContent, 3); |
|
1649 | + } |
|
1600 | 1650 | } |
1601 | 1651 | } |
1602 | 1652 | // END @CHANGE LDR |
@@ -1616,8 +1666,9 @@ discard block |
||
1616 | 1666 | function setSensitivity($_value = 0) |
1617 | 1667 | { |
1618 | 1668 | if ( ( is_numeric($_value) ) && |
1619 | - ( ( $_value >= 0 ) && ( $_value <= 3 ) ) ) |
|
1620 | - $this->_msgSensitivity = $_value; |
|
1669 | + ( ( $_value >= 0 ) && ( $_value <= 3 ) ) ) { |
|
1670 | + $this->_msgSensitivity = $_value; |
|
1671 | + } |
|
1621 | 1672 | } |
1622 | 1673 | |
1623 | 1674 | /** |
@@ -1651,8 +1702,9 @@ discard block |
||
1651 | 1702 | function setPriority ( $_value = 3 ) |
1652 | 1703 | { |
1653 | 1704 | if ( ( is_numeric($_value) ) && |
1654 | - ( ( $_value >= 0 ) && ( $_value <= 5 ) ) ) |
|
1655 | - $this->_msgPriority = $_value; |
|
1705 | + ( ( $_value >= 0 ) && ( $_value <= 5 ) ) ) { |
|
1706 | + $this->_msgPriority = $_value; |
|
1707 | + } |
|
1656 | 1708 | } |
1657 | 1709 | |
1658 | 1710 | /** |
@@ -1705,8 +1757,9 @@ discard block |
||
1705 | 1757 | */ |
1706 | 1758 | function setXheader($strXdata) |
1707 | 1759 | { |
1708 | - if ( $strXdata ) |
|
1709 | - $this->_msgXheader[] = $strXdata; |
|
1760 | + if ( $strXdata ) { |
|
1761 | + $this->_msgXheader[] = $strXdata; |
|
1762 | + } |
|
1710 | 1763 | } |
1711 | 1764 | |
1712 | 1765 | /** |
@@ -1739,9 +1792,13 @@ discard block |
||
1739 | 1792 | */ |
1740 | 1793 | function _getBoundary($type='mixed') |
1741 | 1794 | { |
1742 | - if ($type == 'mixed') return $this->_smtpsBoundary; |
|
1743 | - else if ($type == 'related') return $this->_smtpsRelatedBoundary; |
|
1744 | - else if ($type == 'alternative') return $this->_smtpsAlternativeBoundary; |
|
1795 | + if ($type == 'mixed') { |
|
1796 | + return $this->_smtpsBoundary; |
|
1797 | + } else if ($type == 'related') { |
|
1798 | + return $this->_smtpsRelatedBoundary; |
|
1799 | + } else if ($type == 'alternative') { |
|
1800 | + return $this->_smtpsAlternativeBoundary; |
|
1801 | + } |
|
1745 | 1802 | } |
1746 | 1803 | |
1747 | 1804 | /** |
@@ -1795,12 +1852,18 @@ discard block |
||
1795 | 1852 | */ |
1796 | 1853 | function socket_send_str( $_strSend, $_returnCode = null, $CRLF = "\r\n" ) |
1797 | 1854 | { |
1798 | - if ($this->_debug) $this->log.=$_strSend; // @CHANGE LDR for log |
|
1855 | + if ($this->_debug) { |
|
1856 | + $this->log.=$_strSend; |
|
1857 | + } |
|
1858 | + // @CHANGE LDR for log |
|
1799 | 1859 | fputs($this->socket, $_strSend . $CRLF); |
1800 | - if ($this->_debug) $this->log.=' ('.$_returnCode.')' . $CRLF; |
|
1860 | + if ($this->_debug) { |
|
1861 | + $this->log.=' ('.$_returnCode.')' . $CRLF; |
|
1862 | + } |
|
1801 | 1863 | |
1802 | - if ( $_returnCode ) |
|
1803 | - return $this->server_parse($this->socket, $_returnCode); |
|
1864 | + if ( $_returnCode ) { |
|
1865 | + return $this->server_parse($this->socket, $_returnCode); |
|
1866 | + } |
|
1804 | 1867 | } |
1805 | 1868 | |
1806 | 1869 | // ============================================================= |
@@ -536,7 +536,7 @@ |
||
536 | 536 | * Update a livraison line (only extrafields) |
537 | 537 | * |
538 | 538 | * @param int $id Id of line (livraison line) |
539 | - * @param array $array_options extrafields array |
|
539 | + * @param integer $array_options extrafields array |
|
540 | 540 | * @return int <0 if KO, >0 if OK |
541 | 541 | */ |
542 | 542 | function update_line($id, $array_options=0) |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | $error = 0; |
88 | 88 | |
89 | - $now=dol_now(); |
|
89 | + $now=dol_now(); |
|
90 | 90 | |
91 | 91 | /* On positionne en mode brouillon le bon de livraison */ |
92 | 92 | $this->brouillon = 1; |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | $sql.= ", ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null"); |
121 | 121 | $sql.= ", ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null"); |
122 | 122 | $sql.= ", ".(!empty($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null"); |
123 | - $sql.= ", ".(int) $this->fk_incoterms; |
|
124 | - $sql.= ", '".$this->db->escape($this->location_incoterms)."'"; |
|
123 | + $sql.= ", ".(int) $this->fk_incoterms; |
|
124 | + $sql.= ", '".$this->db->escape($this->location_incoterms)."'"; |
|
125 | 125 | $sql.= ")"; |
126 | 126 | |
127 | 127 | dol_syslog("Livraison::create", LOG_DEBUG); |
@@ -260,8 +260,8 @@ discard block |
||
260 | 260 | $sql.=" l.total_ht, l.fk_statut, l.fk_user_valid, l.note_private, l.note_public"; |
261 | 261 | $sql.= ", l.date_delivery, l.fk_address, l.model_pdf"; |
262 | 262 | $sql.= ", el.fk_source as origin_id, el.sourcetype as origin"; |
263 | - $sql.= ', l.fk_incoterms, l.location_incoterms'; |
|
264 | - $sql.= ", i.libelle as libelle_incoterms"; |
|
263 | + $sql.= ', l.fk_incoterms, l.location_incoterms'; |
|
264 | + $sql.= ", i.libelle as libelle_incoterms"; |
|
265 | 265 | $sql.= " FROM ".MAIN_DB_PREFIX."livraison as l"; |
266 | 266 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = l.rowid AND el.targettype = '".$this->db->escape($this->element)."'"; |
267 | 267 | $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON l.fk_incoterms = i.rowid'; |
@@ -337,13 +337,13 @@ discard block |
||
337 | 337 | /** |
338 | 338 | * Validate object and update stock if option enabled |
339 | 339 | * |
340 | - * @param User $user Object user that validate |
|
341 | - * @return int |
|
340 | + * @param User $user Object user that validate |
|
341 | + * @return int |
|
342 | 342 | */ |
343 | 343 | function valid($user) |
344 | 344 | { |
345 | 345 | global $conf, $langs; |
346 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
346 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
347 | 347 | |
348 | 348 | dol_syslog(get_class($this)."::valid begin"); |
349 | 349 | |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | |
352 | 352 | $error = 0; |
353 | 353 | |
354 | - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison->creer)) |
|
355 | - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison_advance->validate))) |
|
354 | + if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison->creer)) |
|
355 | + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison_advance->validate))) |
|
356 | 356 | { |
357 | 357 | if (! empty($conf->global->LIVRAISON_ADDON_NUMBER)) |
358 | 358 | { |
@@ -371,14 +371,14 @@ discard block |
||
371 | 371 | $soc->fetch($this->socid); |
372 | 372 | |
373 | 373 | if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life |
374 | - { |
|
375 | - $numref = $objMod->livraison_get_num($soc,$this); |
|
376 | - } |
|
377 | - else |
|
378 | 374 | { |
379 | - $numref = $this->ref; |
|
380 | - } |
|
381 | - $this->newref = $numref; |
|
375 | + $numref = $objMod->livraison_get_num($soc,$this); |
|
376 | + } |
|
377 | + else |
|
378 | + { |
|
379 | + $numref = $this->ref; |
|
380 | + } |
|
381 | + $this->newref = $numref; |
|
382 | 382 | |
383 | 383 | // Tester si non deja au statut valide. Si oui, on arrete afin d'eviter |
384 | 384 | // de decrementer 2 fois le stock. |
@@ -407,24 +407,24 @@ discard block |
||
407 | 407 | $sql.= " AND fk_statut = 0"; |
408 | 408 | |
409 | 409 | $resql=$this->db->query($sql); |
410 | - if (! $resql) |
|
411 | - { |
|
412 | - dol_print_error($this->db); |
|
413 | - $this->error=$this->db->lasterror(); |
|
414 | - $error++; |
|
415 | - } |
|
416 | - |
|
417 | - if (! $error && ! $notrigger) |
|
418 | - { |
|
419 | - // Call trigger |
|
420 | - $result=$this->call_trigger('DELIVERY_VALIDATE',$user); |
|
421 | - if ($result < 0) $error++; |
|
422 | - // End call triggers |
|
423 | - } |
|
410 | + if (! $resql) |
|
411 | + { |
|
412 | + dol_print_error($this->db); |
|
413 | + $this->error=$this->db->lasterror(); |
|
414 | + $error++; |
|
415 | + } |
|
416 | + |
|
417 | + if (! $error && ! $notrigger) |
|
418 | + { |
|
419 | + // Call trigger |
|
420 | + $result=$this->call_trigger('DELIVERY_VALIDATE',$user); |
|
421 | + if ($result < 0) $error++; |
|
422 | + // End call triggers |
|
423 | + } |
|
424 | 424 | |
425 | 425 | if (! $error) |
426 | 426 | { |
427 | - $this->oldref = $this->ref; |
|
427 | + $this->oldref = $this->ref; |
|
428 | 428 | |
429 | 429 | // Rename directory if dir was a temporary ref |
430 | 430 | if (preg_match('/^[\(]?PROV/i', $this->ref)) |
@@ -441,17 +441,17 @@ discard block |
||
441 | 441 | |
442 | 442 | if (@rename($dirsource, $dirdest)) |
443 | 443 | { |
444 | - dol_syslog("Rename ok"); |
|
445 | - // Rename docs starting with $oldref with $newref |
|
446 | - $listoffiles=dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/')); |
|
447 | - foreach($listoffiles as $fileentry) |
|
448 | - { |
|
449 | - $dirsource=$fileentry['name']; |
|
450 | - $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource); |
|
451 | - $dirsource=$fileentry['path'].'/'.$dirsource; |
|
452 | - $dirdest=$fileentry['path'].'/'.$dirdest; |
|
453 | - @rename($dirsource, $dirdest); |
|
454 | - } |
|
444 | + dol_syslog("Rename ok"); |
|
445 | + // Rename docs starting with $oldref with $newref |
|
446 | + $listoffiles=dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/')); |
|
447 | + foreach($listoffiles as $fileentry) |
|
448 | + { |
|
449 | + $dirsource=$fileentry['name']; |
|
450 | + $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource); |
|
451 | + $dirsource=$fileentry['path'].'/'.$dirsource; |
|
452 | + $dirdest=$fileentry['path'].'/'.$dirdest; |
|
453 | + @rename($dirsource, $dirdest); |
|
454 | + } |
|
455 | 455 | } |
456 | 456 | } |
457 | 457 | } |
@@ -466,16 +466,16 @@ discard block |
||
466 | 466 | dol_syslog(get_class($this)."::valid ok"); |
467 | 467 | } |
468 | 468 | |
469 | - if (! $error) |
|
470 | - { |
|
471 | - $this->db->commit(); |
|
472 | - return 1; |
|
473 | - } |
|
474 | - else |
|
469 | + if (! $error) |
|
470 | + { |
|
471 | + $this->db->commit(); |
|
472 | + return 1; |
|
473 | + } |
|
474 | + else |
|
475 | 475 | { |
476 | - $this->db->rollback(); |
|
477 | - return -1; |
|
478 | - } |
|
476 | + $this->db->rollback(); |
|
477 | + return -1; |
|
478 | + } |
|
479 | 479 | } |
480 | 480 | } |
481 | 481 | } |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | { |
617 | 617 | global $conf, $langs, $user; |
618 | 618 | |
619 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
619 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
620 | 620 | $this->db->begin(); |
621 | 621 | |
622 | 622 | $error=0; |
@@ -660,14 +660,14 @@ discard block |
||
660 | 660 | } |
661 | 661 | } |
662 | 662 | |
663 | - // Call trigger |
|
664 | - $result=$this->call_trigger('DELIVERY_DELETE',$user); |
|
665 | - if ($result < 0) |
|
666 | - { |
|
667 | - $this->db->rollback(); |
|
668 | - return -4; |
|
669 | - } |
|
670 | - // End call triggers |
|
663 | + // Call trigger |
|
664 | + $result=$this->call_trigger('DELIVERY_DELETE',$user); |
|
665 | + if ($result < 0) |
|
666 | + { |
|
667 | + $this->db->rollback(); |
|
668 | + return -4; |
|
669 | + } |
|
670 | + // End call triggers |
|
671 | 671 | |
672 | 672 | return 1; |
673 | 673 | } |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | * Return clicable name (with picto eventually) |
698 | 698 | * |
699 | 699 | * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
700 | - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
|
700 | + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
|
701 | 701 | * @return string Chaine avec URL |
702 | 702 | */ |
703 | 703 | function getNomUrl($withpicto=0, $save_lastsearch_value=-1) |
@@ -711,16 +711,16 @@ discard block |
||
711 | 711 | |
712 | 712 | $url=DOL_URL_ROOT.'/livraison/card.php?id='.$this->id; |
713 | 713 | |
714 | - //if ($option !== 'nolink') |
|
715 | - //{ |
|
716 | - // Add param to save lastsearch_values or not |
|
717 | - $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); |
|
718 | - if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; |
|
719 | - if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; |
|
720 | - //} |
|
714 | + //if ($option !== 'nolink') |
|
715 | + //{ |
|
716 | + // Add param to save lastsearch_values or not |
|
717 | + $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); |
|
718 | + if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; |
|
719 | + if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; |
|
720 | + //} |
|
721 | 721 | |
722 | 722 | |
723 | - $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
|
723 | + $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
|
724 | 724 | $linkend='</a>'; |
725 | 725 | |
726 | 726 | if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
@@ -837,11 +837,11 @@ discard block |
||
837 | 837 | |
838 | 838 | |
839 | 839 | /** |
840 | - * Initialise an instance with random values. |
|
841 | - * Used to build previews or test instances. |
|
842 | - * id must be 0 if object instance is a specimen. |
|
843 | - * |
|
844 | - * @return void |
|
840 | + * Initialise an instance with random values. |
|
841 | + * Used to build previews or test instances. |
|
842 | + * id must be 0 if object instance is a specimen. |
|
843 | + * |
|
844 | + * @return void |
|
845 | 845 | */ |
846 | 846 | function initAsSpecimen() |
847 | 847 | { |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | |
850 | 850 | $now=dol_now(); |
851 | 851 | |
852 | - // Load array of products prodids |
|
852 | + // Load array of products prodids |
|
853 | 853 | $num_prods = 0; |
854 | 854 | $prodids = array(); |
855 | 855 | $sql = "SELECT rowid"; |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; |
31 | 31 | require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; |
32 | 32 | require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; |
33 | -if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
34 | -if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
33 | +if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
34 | +if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
35 | 35 | |
36 | 36 | |
37 | 37 | /** |
@@ -39,16 +39,16 @@ discard block |
||
39 | 39 | */ |
40 | 40 | class Livraison extends CommonObject |
41 | 41 | { |
42 | - public $element="delivery"; |
|
43 | - public $fk_element="fk_livraison"; |
|
44 | - public $table_element="livraison"; |
|
45 | - public $table_element_line="livraisondet"; |
|
42 | + public $element = "delivery"; |
|
43 | + public $fk_element = "fk_livraison"; |
|
44 | + public $table_element = "livraison"; |
|
45 | + public $table_element_line = "livraisondet"; |
|
46 | 46 | |
47 | 47 | var $brouillon; |
48 | 48 | var $socid; |
49 | 49 | var $ref_customer; |
50 | 50 | |
51 | - var $date_delivery; // Date really received |
|
51 | + var $date_delivery; // Date really received |
|
52 | 52 | var $date_creation; |
53 | 53 | var $date_valid; |
54 | 54 | var $model_pdf; |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | |
83 | 83 | dol_syslog("Livraison::create"); |
84 | 84 | |
85 | - if (empty($this->model_pdf)) $this->model_pdf=$conf->global->LIVRAISON_ADDON_PDF; |
|
85 | + if (empty($this->model_pdf)) $this->model_pdf = $conf->global->LIVRAISON_ADDON_PDF; |
|
86 | 86 | |
87 | 87 | $error = 0; |
88 | 88 | |
89 | - $now=dol_now(); |
|
89 | + $now = dol_now(); |
|
90 | 90 | |
91 | 91 | /* On positionne en mode brouillon le bon de livraison */ |
92 | 92 | $this->brouillon = 1; |
@@ -96,36 +96,36 @@ discard block |
||
96 | 96 | $this->db->begin(); |
97 | 97 | |
98 | 98 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraison ("; |
99 | - $sql.= "ref"; |
|
100 | - $sql.= ", entity"; |
|
101 | - $sql.= ", fk_soc"; |
|
102 | - $sql.= ", ref_customer"; |
|
103 | - $sql.= ", date_creation"; |
|
104 | - $sql.= ", fk_user_author"; |
|
105 | - $sql.= ", date_delivery"; |
|
106 | - $sql.= ", fk_address"; |
|
107 | - $sql.= ", note_private"; |
|
108 | - $sql.= ", note_public"; |
|
109 | - $sql.= ", model_pdf"; |
|
110 | - $sql.= ", fk_incoterms, location_incoterms"; |
|
111 | - $sql.= ") VALUES ("; |
|
112 | - $sql.= "'(PROV)'"; |
|
113 | - $sql.= ", ".$conf->entity; |
|
114 | - $sql.= ", ".$this->socid; |
|
115 | - $sql.= ", '".$this->db->escape($this->ref_customer)."'"; |
|
116 | - $sql.= ", '".$this->db->idate($now)."'"; |
|
117 | - $sql.= ", ".$user->id; |
|
118 | - $sql.= ", ".($this->date_delivery?"'".$this->db->idate($this->date_delivery)."'":"null"); |
|
119 | - $sql.= ", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address : "null"); |
|
120 | - $sql.= ", ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null"); |
|
121 | - $sql.= ", ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null"); |
|
122 | - $sql.= ", ".(!empty($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null"); |
|
123 | - $sql.= ", ".(int) $this->fk_incoterms; |
|
124 | - $sql.= ", '".$this->db->escape($this->location_incoterms)."'"; |
|
125 | - $sql.= ")"; |
|
99 | + $sql .= "ref"; |
|
100 | + $sql .= ", entity"; |
|
101 | + $sql .= ", fk_soc"; |
|
102 | + $sql .= ", ref_customer"; |
|
103 | + $sql .= ", date_creation"; |
|
104 | + $sql .= ", fk_user_author"; |
|
105 | + $sql .= ", date_delivery"; |
|
106 | + $sql .= ", fk_address"; |
|
107 | + $sql .= ", note_private"; |
|
108 | + $sql .= ", note_public"; |
|
109 | + $sql .= ", model_pdf"; |
|
110 | + $sql .= ", fk_incoterms, location_incoterms"; |
|
111 | + $sql .= ") VALUES ("; |
|
112 | + $sql .= "'(PROV)'"; |
|
113 | + $sql .= ", ".$conf->entity; |
|
114 | + $sql .= ", ".$this->socid; |
|
115 | + $sql .= ", '".$this->db->escape($this->ref_customer)."'"; |
|
116 | + $sql .= ", '".$this->db->idate($now)."'"; |
|
117 | + $sql .= ", ".$user->id; |
|
118 | + $sql .= ", ".($this->date_delivery ? "'".$this->db->idate($this->date_delivery)."'" : "null"); |
|
119 | + $sql .= ", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address : "null"); |
|
120 | + $sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null"); |
|
121 | + $sql .= ", ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null"); |
|
122 | + $sql .= ", ".(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null"); |
|
123 | + $sql .= ", ".(int) $this->fk_incoterms; |
|
124 | + $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; |
|
125 | + $sql .= ")"; |
|
126 | 126 | |
127 | 127 | dol_syslog("Livraison::create", LOG_DEBUG); |
128 | - $resql=$this->db->query($sql); |
|
128 | + $resql = $this->db->query($sql); |
|
129 | 129 | if ($resql) |
130 | 130 | { |
131 | 131 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."livraison"); |
@@ -133,14 +133,14 @@ discard block |
||
133 | 133 | $numref = "(PROV".$this->id.")"; |
134 | 134 | |
135 | 135 | $sql = "UPDATE ".MAIN_DB_PREFIX."livraison "; |
136 | - $sql.= "SET ref = '".$this->db->escape($numref)."'"; |
|
137 | - $sql.= " WHERE rowid = ".$this->id; |
|
136 | + $sql .= "SET ref = '".$this->db->escape($numref)."'"; |
|
137 | + $sql .= " WHERE rowid = ".$this->id; |
|
138 | 138 | |
139 | 139 | dol_syslog("Livraison::create", LOG_DEBUG); |
140 | - $resql=$this->db->query($sql); |
|
140 | + $resql = $this->db->query($sql); |
|
141 | 141 | if ($resql) |
142 | 142 | { |
143 | - if (! $conf->expedition_bon->enabled) |
|
143 | + if (!$conf->expedition_bon->enabled) |
|
144 | 144 | { |
145 | 145 | $commande = new Commande($this->db); |
146 | 146 | $commande->id = $this->commande_id; |
@@ -151,19 +151,19 @@ discard block |
||
151 | 151 | /* |
152 | 152 | * Insertion des produits dans la base |
153 | 153 | */ |
154 | - $num=count($this->lines); |
|
154 | + $num = count($this->lines); |
|
155 | 155 | for ($i = 0; $i < $num; $i++) |
156 | 156 | { |
157 | - $origin_id=$this->lines[$i]->origin_line_id; |
|
158 | - if (! $origin_id) $origin_id=$this->lines[$i]->commande_ligne_id; // For backward compatibility |
|
157 | + $origin_id = $this->lines[$i]->origin_line_id; |
|
158 | + if (!$origin_id) $origin_id = $this->lines[$i]->commande_ligne_id; // For backward compatibility |
|
159 | 159 | |
160 | - if (! $this->create_line($origin_id, $this->lines[$i]->qty, $this->lines[$i]->fk_product, $this->lines[$i]->description)) |
|
160 | + if (!$this->create_line($origin_id, $this->lines[$i]->qty, $this->lines[$i]->fk_product, $this->lines[$i]->description)) |
|
161 | 161 | { |
162 | 162 | $error++; |
163 | 163 | } |
164 | 164 | } |
165 | 165 | |
166 | - if (! $error && $this->id && $this->origin_id) |
|
166 | + if (!$error && $this->id && $this->origin_id) |
|
167 | 167 | { |
168 | 168 | $ret = $this->add_object_linked(); |
169 | 169 | if (!$ret) |
@@ -171,18 +171,18 @@ discard block |
||
171 | 171 | $error++; |
172 | 172 | } |
173 | 173 | |
174 | - if (! $conf->expedition_bon->enabled) |
|
174 | + if (!$conf->expedition_bon->enabled) |
|
175 | 175 | { |
176 | 176 | // TODO uniformiser les statuts |
177 | - $ret = $this->setStatut(2,$this->origin_id,$this->origin); |
|
178 | - if (! $ret) |
|
177 | + $ret = $this->setStatut(2, $this->origin_id, $this->origin); |
|
178 | + if (!$ret) |
|
179 | 179 | { |
180 | 180 | $error++; |
181 | 181 | } |
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
185 | - if (! $error) |
|
185 | + if (!$error) |
|
186 | 186 | { |
187 | 187 | $this->db->commit(); |
188 | 188 | return $this->id; |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | else |
191 | 191 | { |
192 | 192 | $error++; |
193 | - $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror; |
|
193 | + $this->error = $this->db->lasterror()." - sql=".$this->db->lastqueryerror; |
|
194 | 194 | $this->db->rollback(); |
195 | 195 | return -3; |
196 | 196 | } |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | else |
199 | 199 | { |
200 | 200 | $error++; |
201 | - $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror; |
|
201 | + $this->error = $this->db->lasterror()." - sql=".$this->db->lastqueryerror; |
|
202 | 202 | $this->db->rollback(); |
203 | 203 | return -2; |
204 | 204 | } |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | else |
207 | 207 | { |
208 | 208 | $error++; |
209 | - $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror; |
|
209 | + $this->error = $this->db->lasterror()." - sql=".$this->db->lastqueryerror; |
|
210 | 210 | $this->db->rollback(); |
211 | 211 | return -1; |
212 | 212 | } |
@@ -228,19 +228,19 @@ discard block |
||
228 | 228 | $j = 0; |
229 | 229 | |
230 | 230 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."livraisondet (fk_livraison, fk_origin_line,"; |
231 | - $sql.= " fk_product, description, qty)"; |
|
232 | - $sql.= " VALUES (".$this->id.",".$origin_id.","; |
|
233 | - $sql.= " ".($idprod>0?$idprod:"null").","; |
|
234 | - $sql.= " ".($description?"'".$this->db->escape($description)."'":"null").","; |
|
235 | - $sql.= $qty.")"; |
|
231 | + $sql .= " fk_product, description, qty)"; |
|
232 | + $sql .= " VALUES (".$this->id.",".$origin_id.","; |
|
233 | + $sql .= " ".($idprod > 0 ? $idprod : "null").","; |
|
234 | + $sql .= " ".($description ? "'".$this->db->escape($description)."'" : "null").","; |
|
235 | + $sql .= $qty.")"; |
|
236 | 236 | |
237 | 237 | dol_syslog(get_class($this)."::create_line", LOG_DEBUG); |
238 | - if (! $this->db->query($sql) ) |
|
238 | + if (!$this->db->query($sql)) |
|
239 | 239 | { |
240 | 240 | $error++; |
241 | 241 | } |
242 | 242 | |
243 | - if ($error == 0 ) |
|
243 | + if ($error == 0) |
|
244 | 244 | { |
245 | 245 | return 1; |
246 | 246 | } |
@@ -257,15 +257,15 @@ discard block |
||
257 | 257 | global $conf; |
258 | 258 | |
259 | 259 | $sql = "SELECT l.rowid, l.fk_soc, l.date_creation, l.date_valid, l.ref, l.ref_customer, l.fk_user_author,"; |
260 | - $sql.=" l.total_ht, l.fk_statut, l.fk_user_valid, l.note_private, l.note_public"; |
|
261 | - $sql.= ", l.date_delivery, l.fk_address, l.model_pdf"; |
|
262 | - $sql.= ", el.fk_source as origin_id, el.sourcetype as origin"; |
|
263 | - $sql.= ', l.fk_incoterms, l.location_incoterms'; |
|
264 | - $sql.= ", i.libelle as libelle_incoterms"; |
|
265 | - $sql.= " FROM ".MAIN_DB_PREFIX."livraison as l"; |
|
266 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = l.rowid AND el.targettype = '".$this->db->escape($this->element)."'"; |
|
267 | - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON l.fk_incoterms = i.rowid'; |
|
268 | - $sql.= " WHERE l.rowid = ".$id; |
|
260 | + $sql .= " l.total_ht, l.fk_statut, l.fk_user_valid, l.note_private, l.note_public"; |
|
261 | + $sql .= ", l.date_delivery, l.fk_address, l.model_pdf"; |
|
262 | + $sql .= ", el.fk_source as origin_id, el.sourcetype as origin"; |
|
263 | + $sql .= ', l.fk_incoterms, l.location_incoterms'; |
|
264 | + $sql .= ", i.libelle as libelle_incoterms"; |
|
265 | + $sql .= " FROM ".MAIN_DB_PREFIX."livraison as l"; |
|
266 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = l.rowid AND el.targettype = '".$this->db->escape($this->element)."'"; |
|
267 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON l.fk_incoterms = i.rowid'; |
|
268 | + $sql .= " WHERE l.rowid = ".$id; |
|
269 | 269 | |
270 | 270 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
271 | 271 | $result = $this->db->query($sql); |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | $this->note_private = $obj->note_private; |
291 | 291 | $this->note_public = $obj->note_public; |
292 | 292 | $this->modelpdf = $obj->model_pdf; |
293 | - $this->origin = $obj->origin; // May be 'shipping' |
|
294 | - $this->origin_id = $obj->origin_id; // May be id of shipping |
|
293 | + $this->origin = $obj->origin; // May be 'shipping' |
|
294 | + $this->origin_id = $obj->origin_id; // May be id of shipping |
|
295 | 295 | |
296 | 296 | //Incoterms |
297 | 297 | $this->fk_incoterms = $obj->fk_incoterms; |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | /* |
309 | 309 | * Lignes |
310 | 310 | */ |
311 | - $result=$this->fetch_lines(); |
|
311 | + $result = $this->fetch_lines(); |
|
312 | 312 | if ($result < 0) |
313 | 313 | { |
314 | 314 | return -3; |
@@ -318,14 +318,14 @@ discard block |
||
318 | 318 | } |
319 | 319 | else |
320 | 320 | { |
321 | - $this->error='Delivery with id '.$id.' not found sql='.$sql; |
|
321 | + $this->error = 'Delivery with id '.$id.' not found sql='.$sql; |
|
322 | 322 | dol_syslog(get_class($this).'::fetch Error '.$this->error, LOG_ERR); |
323 | 323 | return -2; |
324 | 324 | } |
325 | 325 | } |
326 | 326 | else |
327 | 327 | { |
328 | - $this->error=$this->db->error(); |
|
328 | + $this->error = $this->db->error(); |
|
329 | 329 | return -1; |
330 | 330 | } |
331 | 331 | } |
@@ -347,19 +347,19 @@ discard block |
||
347 | 347 | |
348 | 348 | $error = 0; |
349 | 349 | |
350 | - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison->creer)) |
|
351 | - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison_advance->validate))) |
|
350 | + if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->livraison->creer)) |
|
351 | + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->livraison_advance->validate))) |
|
352 | 352 | { |
353 | - if (! empty($conf->global->LIVRAISON_ADDON_NUMBER)) |
|
353 | + if (!empty($conf->global->LIVRAISON_ADDON_NUMBER)) |
|
354 | 354 | { |
355 | 355 | // Definition du nom de module de numerotation de commande |
356 | 356 | $modName = $conf->global->LIVRAISON_ADDON_NUMBER; |
357 | 357 | |
358 | - if (is_readable(DOL_DOCUMENT_ROOT .'/core/modules/livraison/'.$modName.'.php')) |
|
358 | + if (is_readable(DOL_DOCUMENT_ROOT.'/core/modules/livraison/'.$modName.'.php')) |
|
359 | 359 | { |
360 | - require_once DOL_DOCUMENT_ROOT .'/core/modules/livraison/'.$modName.'.php'; |
|
360 | + require_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/'.$modName.'.php'; |
|
361 | 361 | |
362 | - $now=dol_now(); |
|
362 | + $now = dol_now(); |
|
363 | 363 | |
364 | 364 | // Recuperation de la nouvelle reference |
365 | 365 | $objMod = new $modName($this->db); |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | |
369 | 369 | if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life |
370 | 370 | { |
371 | - $numref = $objMod->livraison_get_num($soc,$this); |
|
371 | + $numref = $objMod->livraison_get_num($soc, $this); |
|
372 | 372 | } |
373 | 373 | else |
374 | 374 | { |
@@ -379,12 +379,12 @@ discard block |
||
379 | 379 | // Tester si non deja au statut valide. Si oui, on arrete afin d'eviter |
380 | 380 | // de decrementer 2 fois le stock. |
381 | 381 | $sql = "SELECT ref"; |
382 | - $sql.= " FROM ".MAIN_DB_PREFIX."livraison"; |
|
383 | - $sql.= " WHERE ref = '".$this->db->escape($numref)."'"; |
|
384 | - $sql.= " AND fk_statut <> 0"; |
|
385 | - $sql.= " AND entity = ".$conf->entity; |
|
382 | + $sql .= " FROM ".MAIN_DB_PREFIX."livraison"; |
|
383 | + $sql .= " WHERE ref = '".$this->db->escape($numref)."'"; |
|
384 | + $sql .= " AND fk_statut <> 0"; |
|
385 | + $sql .= " AND entity = ".$conf->entity; |
|
386 | 386 | |
387 | - $resql=$this->db->query($sql); |
|
387 | + $resql = $this->db->query($sql); |
|
388 | 388 | if ($resql) |
389 | 389 | { |
390 | 390 | $num = $this->db->num_rows($resql); |
@@ -395,30 +395,30 @@ discard block |
||
395 | 395 | } |
396 | 396 | |
397 | 397 | $sql = "UPDATE ".MAIN_DB_PREFIX."livraison SET"; |
398 | - $sql.= " ref='".$this->db->escape($numref)."'"; |
|
399 | - $sql.= ", fk_statut = 1"; |
|
400 | - $sql.= ", date_valid = '".$this->db->idate($now)."'"; |
|
401 | - $sql.= ", fk_user_valid = ".$user->id; |
|
402 | - $sql.= " WHERE rowid = ".$this->id; |
|
403 | - $sql.= " AND fk_statut = 0"; |
|
404 | - |
|
405 | - $resql=$this->db->query($sql); |
|
406 | - if (! $resql) |
|
398 | + $sql .= " ref='".$this->db->escape($numref)."'"; |
|
399 | + $sql .= ", fk_statut = 1"; |
|
400 | + $sql .= ", date_valid = '".$this->db->idate($now)."'"; |
|
401 | + $sql .= ", fk_user_valid = ".$user->id; |
|
402 | + $sql .= " WHERE rowid = ".$this->id; |
|
403 | + $sql .= " AND fk_statut = 0"; |
|
404 | + |
|
405 | + $resql = $this->db->query($sql); |
|
406 | + if (!$resql) |
|
407 | 407 | { |
408 | 408 | dol_print_error($this->db); |
409 | - $this->error=$this->db->lasterror(); |
|
409 | + $this->error = $this->db->lasterror(); |
|
410 | 410 | $error++; |
411 | 411 | } |
412 | 412 | |
413 | - if (! $error && ! $notrigger) |
|
413 | + if (!$error && !$notrigger) |
|
414 | 414 | { |
415 | 415 | // Call trigger |
416 | - $result=$this->call_trigger('DELIVERY_VALIDATE',$user); |
|
416 | + $result = $this->call_trigger('DELIVERY_VALIDATE', $user); |
|
417 | 417 | if ($result < 0) $error++; |
418 | 418 | // End call triggers |
419 | 419 | } |
420 | 420 | |
421 | - if (! $error) |
|
421 | + if (!$error) |
|
422 | 422 | { |
423 | 423 | $this->oldref = $this->ref; |
424 | 424 | |
@@ -439,13 +439,13 @@ discard block |
||
439 | 439 | { |
440 | 440 | dol_syslog("Rename ok"); |
441 | 441 | // Rename docs starting with $oldref with $newref |
442 | - $listoffiles=dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/')); |
|
443 | - foreach($listoffiles as $fileentry) |
|
442 | + $listoffiles = dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); |
|
443 | + foreach ($listoffiles as $fileentry) |
|
444 | 444 | { |
445 | - $dirsource=$fileentry['name']; |
|
446 | - $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource); |
|
447 | - $dirsource=$fileentry['path'].'/'.$dirsource; |
|
448 | - $dirdest=$fileentry['path'].'/'.$dirdest; |
|
445 | + $dirsource = $fileentry['name']; |
|
446 | + $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); |
|
447 | + $dirsource = $fileentry['path'].'/'.$dirsource; |
|
448 | + $dirdest = $fileentry['path'].'/'.$dirdest; |
|
449 | 449 | @rename($dirsource, $dirdest); |
450 | 450 | } |
451 | 451 | } |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | } |
454 | 454 | |
455 | 455 | // Set new ref and current status |
456 | - if (! $error) |
|
456 | + if (!$error) |
|
457 | 457 | { |
458 | 458 | $this->ref = $numref; |
459 | 459 | $this->statut = 1; |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | dol_syslog(get_class($this)."::valid ok"); |
463 | 463 | } |
464 | 464 | |
465 | - if (! $error) |
|
465 | + if (!$error) |
|
466 | 466 | { |
467 | 467 | $this->db->commit(); |
468 | 468 | return 1; |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | } |
478 | 478 | else |
479 | 479 | { |
480 | - $this->error="Non autorise"; |
|
480 | + $this->error = "Non autorise"; |
|
481 | 481 | dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); |
482 | 482 | return -1; |
483 | 483 | } |
@@ -493,11 +493,11 @@ discard block |
||
493 | 493 | function create_from_sending($user, $sending_id) |
494 | 494 | { |
495 | 495 | $expedition = new Expedition($this->db); |
496 | - $result=$expedition->fetch($sending_id); |
|
496 | + $result = $expedition->fetch($sending_id); |
|
497 | 497 | |
498 | 498 | $this->lines = array(); |
499 | 499 | |
500 | - $num=count($expedition->lines); |
|
500 | + $num = count($expedition->lines); |
|
501 | 501 | for ($i = 0; $i < $num; $i++) |
502 | 502 | { |
503 | 503 | $line = new LivraisonLigne($this->db); |
@@ -519,10 +519,10 @@ discard block |
||
519 | 519 | $this->date_delivery = $expedition->date_delivery; |
520 | 520 | $this->fk_delivery_address = $expedition->fk_delivery_address; |
521 | 521 | $this->socid = $expedition->socid; |
522 | - $this->ref_customer = $expedition->ref_customer; |
|
522 | + $this->ref_customer = $expedition->ref_customer; |
|
523 | 523 | |
524 | 524 | //Incoterms |
525 | - $this->fk_incoterms = $expedition->fk_incoterms; |
|
525 | + $this->fk_incoterms = $expedition->fk_incoterms; |
|
526 | 526 | $this->location_incoterms = $expedition->location_incoterms; |
527 | 527 | |
528 | 528 | return $this->create($user); |
@@ -535,26 +535,26 @@ discard block |
||
535 | 535 | * @param array $array_options extrafields array |
536 | 536 | * @return int <0 if KO, >0 if OK |
537 | 537 | */ |
538 | - function update_line($id, $array_options=0) |
|
538 | + function update_line($id, $array_options = 0) |
|
539 | 539 | { |
540 | 540 | global $conf; |
541 | 541 | $error = 0; |
542 | 542 | |
543 | - if ($id > 0 && !$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used |
|
543 | + if ($id > 0 && !$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used |
|
544 | 544 | { |
545 | 545 | $livraisonline = new LivraisonLigne($this->db); |
546 | - $livraisonline->array_options=$array_options; |
|
547 | - $livraisonline->id=$id; |
|
548 | - $result=$livraisonline->insertExtraFields(); |
|
546 | + $livraisonline->array_options = $array_options; |
|
547 | + $livraisonline->id = $id; |
|
548 | + $result = $livraisonline->insertExtraFields(); |
|
549 | 549 | |
550 | 550 | if ($result < 0) |
551 | 551 | { |
552 | - $this->error[]=$livraisonline->error; |
|
552 | + $this->error[] = $livraisonline->error; |
|
553 | 553 | $error++; |
554 | 554 | } |
555 | 555 | } |
556 | 556 | |
557 | - if (! $error) return 1; |
|
557 | + if (!$error) return 1; |
|
558 | 558 | else return -1; |
559 | 559 | } |
560 | 560 | |
@@ -588,9 +588,9 @@ discard block |
||
588 | 588 | if ($this->statut == 0) |
589 | 589 | { |
590 | 590 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet"; |
591 | - $sql.= " WHERE rowid = ".$lineid; |
|
591 | + $sql .= " WHERE rowid = ".$lineid; |
|
592 | 592 | |
593 | - if ($this->db->query($sql) ) |
|
593 | + if ($this->db->query($sql)) |
|
594 | 594 | { |
595 | 595 | $this->update_price(); |
596 | 596 | |
@@ -615,30 +615,30 @@ discard block |
||
615 | 615 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
616 | 616 | $this->db->begin(); |
617 | 617 | |
618 | - $error=0; |
|
618 | + $error = 0; |
|
619 | 619 | |
620 | 620 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraisondet"; |
621 | - $sql.= " WHERE fk_livraison = ".$this->id; |
|
621 | + $sql .= " WHERE fk_livraison = ".$this->id; |
|
622 | 622 | if ($this->db->query($sql)) |
623 | 623 | { |
624 | 624 | // Delete linked object |
625 | 625 | $res = $this->deleteObjectLinked(); |
626 | 626 | if ($res < 0) $error++; |
627 | 627 | |
628 | - if (! $error) |
|
628 | + if (!$error) |
|
629 | 629 | { |
630 | 630 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison"; |
631 | - $sql.= " WHERE rowid = ".$this->id; |
|
631 | + $sql .= " WHERE rowid = ".$this->id; |
|
632 | 632 | if ($this->db->query($sql)) |
633 | 633 | { |
634 | 634 | $this->db->commit(); |
635 | 635 | |
636 | 636 | // On efface le repertoire de pdf provisoire |
637 | 637 | $ref = dol_sanitizeFileName($this->ref); |
638 | - if (! empty($conf->expedition->dir_output)) |
|
638 | + if (!empty($conf->expedition->dir_output)) |
|
639 | 639 | { |
640 | - $dir = $conf->expedition->dir_output . '/receipt/' . $ref ; |
|
641 | - $file = $dir . '/' . $ref . '.pdf'; |
|
640 | + $dir = $conf->expedition->dir_output.'/receipt/'.$ref; |
|
641 | + $file = $dir.'/'.$ref.'.pdf'; |
|
642 | 642 | if (file_exists($file)) |
643 | 643 | { |
644 | 644 | if (!dol_delete_file($file)) |
@@ -650,14 +650,14 @@ discard block |
||
650 | 650 | { |
651 | 651 | if (!dol_delete_dir($dir)) |
652 | 652 | { |
653 | - $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); |
|
653 | + $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); |
|
654 | 654 | return 0; |
655 | 655 | } |
656 | 656 | } |
657 | 657 | } |
658 | 658 | |
659 | 659 | // Call trigger |
660 | - $result=$this->call_trigger('DELIVERY_DELETE',$user); |
|
660 | + $result = $this->call_trigger('DELIVERY_DELETE', $user); |
|
661 | 661 | if ($result < 0) |
662 | 662 | { |
663 | 663 | $this->db->rollback(); |
@@ -669,21 +669,21 @@ discard block |
||
669 | 669 | } |
670 | 670 | else |
671 | 671 | { |
672 | - $this->error=$this->db->lasterror()." - sql=$sql"; |
|
672 | + $this->error = $this->db->lasterror()." - sql=$sql"; |
|
673 | 673 | $this->db->rollback(); |
674 | 674 | return -3; |
675 | 675 | } |
676 | 676 | } |
677 | 677 | else |
678 | 678 | { |
679 | - $this->error=$this->db->lasterror()." - sql=$sql"; |
|
679 | + $this->error = $this->db->lasterror()." - sql=$sql"; |
|
680 | 680 | $this->db->rollback(); |
681 | 681 | return -2; |
682 | 682 | } |
683 | 683 | } |
684 | 684 | else |
685 | 685 | { |
686 | - $this->error=$this->db->lasterror()." - sql=$sql"; |
|
686 | + $this->error = $this->db->lasterror()." - sql=$sql"; |
|
687 | 687 | $this->db->rollback(); |
688 | 688 | return -1; |
689 | 689 | } |
@@ -696,32 +696,32 @@ discard block |
||
696 | 696 | * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
697 | 697 | * @return string Chaine avec URL |
698 | 698 | */ |
699 | - function getNomUrl($withpicto=0, $save_lastsearch_value=-1) |
|
699 | + function getNomUrl($withpicto = 0, $save_lastsearch_value = -1) |
|
700 | 700 | { |
701 | 701 | global $langs; |
702 | 702 | |
703 | - $result=''; |
|
704 | - $picto='sending'; |
|
703 | + $result = ''; |
|
704 | + $picto = 'sending'; |
|
705 | 705 | |
706 | - $label=$langs->trans("ShowReceiving").': '.$this->ref; |
|
706 | + $label = $langs->trans("ShowReceiving").': '.$this->ref; |
|
707 | 707 | |
708 | - $url=DOL_URL_ROOT.'/livraison/card.php?id='.$this->id; |
|
708 | + $url = DOL_URL_ROOT.'/livraison/card.php?id='.$this->id; |
|
709 | 709 | |
710 | 710 | //if ($option !== 'nolink') |
711 | 711 | //{ |
712 | 712 | // Add param to save lastsearch_values or not |
713 | - $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); |
|
714 | - if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; |
|
715 | - if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; |
|
713 | + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
|
714 | + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; |
|
715 | + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; |
|
716 | 716 | //} |
717 | 717 | |
718 | 718 | |
719 | 719 | $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
720 | - $linkend='</a>'; |
|
720 | + $linkend = '</a>'; |
|
721 | 721 | |
722 | - if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
723 | - if ($withpicto && $withpicto != 2) $result.=' '; |
|
724 | - $result.=$linkstart.$this->ref.$linkend; |
|
722 | + if ($withpicto) $result .= ($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
723 | + if ($withpicto && $withpicto != 2) $result .= ' '; |
|
724 | + $result .= $linkstart.$this->ref.$linkend; |
|
725 | 725 | return $result; |
726 | 726 | } |
727 | 727 | |
@@ -735,12 +735,12 @@ discard block |
||
735 | 735 | $this->lines = array(); |
736 | 736 | |
737 | 737 | $sql = "SELECT ld.rowid, ld.fk_product, ld.description, ld.subprice, ld.total_ht, ld.qty as qty_shipped, ld.fk_origin_line, "; |
738 | - $sql.= " cd.qty as qty_asked, cd.label as custom_label,"; |
|
739 | - $sql.= " p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc"; |
|
740 | - $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld"; |
|
741 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on p.rowid = ld.fk_product"; |
|
742 | - $sql.= " WHERE ld.fk_origin_line = cd.rowid"; |
|
743 | - $sql.= " AND ld.fk_livraison = ".$this->id; |
|
738 | + $sql .= " cd.qty as qty_asked, cd.label as custom_label,"; |
|
739 | + $sql .= " p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc"; |
|
740 | + $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld"; |
|
741 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on p.rowid = ld.fk_product"; |
|
742 | + $sql .= " WHERE ld.fk_origin_line = cd.rowid"; |
|
743 | + $sql .= " AND ld.fk_livraison = ".$this->id; |
|
744 | 744 | |
745 | 745 | dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); |
746 | 746 | $resql = $this->db->query($sql); |
@@ -754,23 +754,23 @@ discard block |
||
754 | 754 | |
755 | 755 | $obj = $this->db->fetch_object($resql); |
756 | 756 | |
757 | - $line->id = $obj->rowid; |
|
758 | - $line->label = $obj->custom_label; |
|
757 | + $line->id = $obj->rowid; |
|
758 | + $line->label = $obj->custom_label; |
|
759 | 759 | $line->description = $obj->description; |
760 | - $line->fk_product = $obj->fk_product; |
|
761 | - $line->qty_asked = $obj->qty_asked; |
|
760 | + $line->fk_product = $obj->fk_product; |
|
761 | + $line->qty_asked = $obj->qty_asked; |
|
762 | 762 | $line->qty_shipped = $obj->qty_shipped; |
763 | 763 | |
764 | - $line->ref = $obj->product_ref; // deprecated |
|
765 | - $line->libelle = $obj->product_label; // deprecated |
|
766 | - $line->product_label = $obj->product_label; // Product label |
|
767 | - $line->product_ref = $obj->product_ref; // Product ref |
|
768 | - $line->product_desc = $obj->product_desc; // Product description |
|
764 | + $line->ref = $obj->product_ref; // deprecated |
|
765 | + $line->libelle = $obj->product_label; // deprecated |
|
766 | + $line->product_label = $obj->product_label; // Product label |
|
767 | + $line->product_ref = $obj->product_ref; // Product ref |
|
768 | + $line->product_desc = $obj->product_desc; // Product description |
|
769 | 769 | $line->product_type = $obj->fk_product_type; |
770 | - $line->fk_origin_line = $obj->fk_origin_line; |
|
770 | + $line->fk_origin_line = $obj->fk_origin_line; |
|
771 | 771 | |
772 | - $line->price = $obj->price; |
|
773 | - $line->total_ht = $obj->total_ht; |
|
772 | + $line->price = $obj->price; |
|
773 | + $line->total_ht = $obj->total_ht; |
|
774 | 774 | |
775 | 775 | $this->lines[$i] = $line; |
776 | 776 | |
@@ -789,9 +789,9 @@ discard block |
||
789 | 789 | * @param int $mode Mode |
790 | 790 | * @return string Label |
791 | 791 | */ |
792 | - function getLibStatut($mode=0) |
|
792 | + function getLibStatut($mode = 0) |
|
793 | 793 | { |
794 | - return $this->LibStatut($this->statut,$mode); |
|
794 | + return $this->LibStatut($this->statut, $mode); |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | /** |
@@ -801,33 +801,33 @@ discard block |
||
801 | 801 | * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
802 | 802 | * @return string Label |
803 | 803 | */ |
804 | - function LibStatut($statut,$mode) |
|
804 | + function LibStatut($statut, $mode) |
|
805 | 805 | { |
806 | 806 | global $langs; |
807 | 807 | |
808 | - if ($mode==0) |
|
808 | + if ($mode == 0) |
|
809 | 809 | { |
810 | - if ($statut==-1) return $langs->trans('StatusDeliveryCanceled'); |
|
811 | - if ($statut==0) return $langs->trans('StatusDeliveryDraft'); |
|
812 | - if ($statut==1) return $langs->trans('StatusDeliveryValidated'); |
|
810 | + if ($statut == -1) return $langs->trans('StatusDeliveryCanceled'); |
|
811 | + if ($statut == 0) return $langs->trans('StatusDeliveryDraft'); |
|
812 | + if ($statut == 1) return $langs->trans('StatusDeliveryValidated'); |
|
813 | 813 | } |
814 | - if ($mode==1) |
|
814 | + if ($mode == 1) |
|
815 | 815 | { |
816 | - if ($statut==-1) return $langs->trans($this->statuts[$statut]); |
|
817 | - if ($statut==0) return $langs->trans($this->statuts[$statut]); |
|
818 | - if ($statut==1) return $langs->trans($this->statuts[$statut]); |
|
816 | + if ($statut == -1) return $langs->trans($this->statuts[$statut]); |
|
817 | + if ($statut == 0) return $langs->trans($this->statuts[$statut]); |
|
818 | + if ($statut == 1) return $langs->trans($this->statuts[$statut]); |
|
819 | 819 | } |
820 | 820 | if ($mode == 4) |
821 | 821 | { |
822 | - if ($statut==-1) return img_picto($langs->trans('StatusDeliveryCanceled'),'statut5').' '.$langs->trans('StatusDeliveryCanceled'); |
|
823 | - if ($statut==0) return img_picto($langs->trans('StatusDeliveryDraft'),'statut0').' '.$langs->trans('StatusDeliveryDraft'); |
|
824 | - if ($statut==1) return img_picto($langs->trans('StatusDeliveryValidated'),'statut4').' '.$langs->trans('StatusDeliveryValidated'); |
|
822 | + if ($statut == -1) return img_picto($langs->trans('StatusDeliveryCanceled'), 'statut5').' '.$langs->trans('StatusDeliveryCanceled'); |
|
823 | + if ($statut == 0) return img_picto($langs->trans('StatusDeliveryDraft'), 'statut0').' '.$langs->trans('StatusDeliveryDraft'); |
|
824 | + if ($statut == 1) return img_picto($langs->trans('StatusDeliveryValidated'), 'statut4').' '.$langs->trans('StatusDeliveryValidated'); |
|
825 | 825 | } |
826 | 826 | if ($mode == 6) |
827 | 827 | { |
828 | - if ($statut==-1) return $langs->trans('StatusDeliveryCanceled').' '.img_picto($langs->trans('StatusDeliveryCanceled'),'statut5'); |
|
829 | - if ($statut==0) return $langs->trans('StatusDeliveryDraft').' '.img_picto($langs->trans('StatusDeliveryDraft'),'statut0'); |
|
830 | - if ($statut==1) return $langs->trans('StatusDeliveryValidated').' '.img_picto($langs->trans('StatusDeliveryValidated'),'statut4'); |
|
828 | + if ($statut == -1) return $langs->trans('StatusDeliveryCanceled').' '.img_picto($langs->trans('StatusDeliveryCanceled'), 'statut5'); |
|
829 | + if ($statut == 0) return $langs->trans('StatusDeliveryDraft').' '.img_picto($langs->trans('StatusDeliveryDraft'), 'statut0'); |
|
830 | + if ($statut == 1) return $langs->trans('StatusDeliveryValidated').' '.img_picto($langs->trans('StatusDeliveryValidated'), 'statut4'); |
|
831 | 831 | } |
832 | 832 | } |
833 | 833 | |
@@ -841,17 +841,17 @@ discard block |
||
841 | 841 | */ |
842 | 842 | function initAsSpecimen() |
843 | 843 | { |
844 | - global $user,$langs,$conf; |
|
844 | + global $user, $langs, $conf; |
|
845 | 845 | |
846 | - $now=dol_now(); |
|
846 | + $now = dol_now(); |
|
847 | 847 | |
848 | 848 | // Load array of products prodids |
849 | 849 | $num_prods = 0; |
850 | 850 | $prodids = array(); |
851 | 851 | $sql = "SELECT rowid"; |
852 | - $sql.= " FROM ".MAIN_DB_PREFIX."product"; |
|
853 | - $sql.= " WHERE entity IN (".getEntity('product').")"; |
|
854 | - $sql.= " AND tosell = 1"; |
|
852 | + $sql .= " FROM ".MAIN_DB_PREFIX."product"; |
|
853 | + $sql .= " WHERE entity IN (".getEntity('product').")"; |
|
854 | + $sql .= " AND tosell = 1"; |
|
855 | 855 | $resql = $this->db->query($sql); |
856 | 856 | if ($resql) |
857 | 857 | { |
@@ -866,16 +866,16 @@ discard block |
||
866 | 866 | } |
867 | 867 | |
868 | 868 | // Initialise parametres |
869 | - $this->id=0; |
|
869 | + $this->id = 0; |
|
870 | 870 | $this->ref = 'SPECIMEN'; |
871 | - $this->specimen=1; |
|
871 | + $this->specimen = 1; |
|
872 | 872 | $this->socid = 1; |
873 | 873 | $this->date_delivery = $now; |
874 | - $this->note_public='Public note'; |
|
875 | - $this->note_private='Private note'; |
|
874 | + $this->note_public = 'Public note'; |
|
875 | + $this->note_private = 'Private note'; |
|
876 | 876 | |
877 | - $i=0; |
|
878 | - $line=new LivraisonLigne($this->db); |
|
877 | + $i = 0; |
|
878 | + $line = new LivraisonLigne($this->db); |
|
879 | 879 | $line->fk_product = $prodids[0]; |
880 | 880 | $line->qty_asked = 10; |
881 | 881 | $line->qty_shipped = 9; |
@@ -899,14 +899,14 @@ discard block |
||
899 | 899 | global $langs; |
900 | 900 | |
901 | 901 | // Get the linked object |
902 | - $this->fetchObjectLinked('','',$this->id,$this->element); |
|
902 | + $this->fetchObjectLinked('', '', $this->id, $this->element); |
|
903 | 903 | //var_dump($this->linkedObjectIds); |
904 | 904 | // Get the product ref and qty in source |
905 | 905 | $sqlSourceLine = "SELECT st.rowid, st.description, st.qty"; |
906 | - $sqlSourceLine.= ", p.ref, p.label"; |
|
907 | - $sqlSourceLine.= " FROM ".MAIN_DB_PREFIX.$this->linkedObjectIds[0]['type']."det as st"; |
|
908 | - $sqlSourceLine.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON st.fk_product = p.rowid"; |
|
909 | - $sqlSourceLine.= " WHERE fk_".$this->linked_object[0]['type']." = ".$this->linked_object[0]['linkid']; |
|
906 | + $sqlSourceLine .= ", p.ref, p.label"; |
|
907 | + $sqlSourceLine .= " FROM ".MAIN_DB_PREFIX.$this->linkedObjectIds[0]['type']."det as st"; |
|
908 | + $sqlSourceLine .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON st.fk_product = p.rowid"; |
|
909 | + $sqlSourceLine .= " WHERE fk_".$this->linked_object[0]['type']." = ".$this->linked_object[0]['linkid']; |
|
910 | 910 | |
911 | 911 | $resultSourceLine = $this->db->query($sqlSourceLine); |
912 | 912 | if ($resultSourceLine) |
@@ -920,15 +920,15 @@ discard block |
||
920 | 920 | |
921 | 921 | // Recupere les lignes de la source deja livrees |
922 | 922 | $sql = "SELECT ld.fk_origin_line, sum(ld.qty) as qty"; |
923 | - $sql.= " FROM ".MAIN_DB_PREFIX."livraisondet as ld, ".MAIN_DB_PREFIX."livraison as l,"; |
|
924 | - $sql.= " ".MAIN_DB_PREFIX.$this->linked_object[0]['type']." as c"; |
|
925 | - $sql.= ", ".MAIN_DB_PREFIX.$this->linked_object[0]['type']."det as cd"; |
|
926 | - $sql.= " WHERE ld.fk_livraison = l.rowid"; |
|
927 | - $sql.= " AND ld.fk_origin_line = cd.rowid"; |
|
928 | - $sql.= " AND cd.fk_".$this->linked_object[0]['type']." = c.rowid"; |
|
929 | - $sql.= " AND cd.fk_".$this->linked_object[0]['type']." = ".$this->linked_object[0]['linkid']; |
|
930 | - $sql.= " AND ld.fk_origin_line = ".$objSourceLine->rowid; |
|
931 | - $sql.= " GROUP BY ld.fk_origin_line"; |
|
923 | + $sql .= " FROM ".MAIN_DB_PREFIX."livraisondet as ld, ".MAIN_DB_PREFIX."livraison as l,"; |
|
924 | + $sql .= " ".MAIN_DB_PREFIX.$this->linked_object[0]['type']." as c"; |
|
925 | + $sql .= ", ".MAIN_DB_PREFIX.$this->linked_object[0]['type']."det as cd"; |
|
926 | + $sql .= " WHERE ld.fk_livraison = l.rowid"; |
|
927 | + $sql .= " AND ld.fk_origin_line = cd.rowid"; |
|
928 | + $sql .= " AND cd.fk_".$this->linked_object[0]['type']." = c.rowid"; |
|
929 | + $sql .= " AND cd.fk_".$this->linked_object[0]['type']." = ".$this->linked_object[0]['linkid']; |
|
930 | + $sql .= " AND ld.fk_origin_line = ".$objSourceLine->rowid; |
|
931 | + $sql .= " GROUP BY ld.fk_origin_line"; |
|
932 | 932 | |
933 | 933 | $result = $this->db->query($sql); |
934 | 934 | $row = $this->db->fetch_row($result); |
@@ -945,13 +945,13 @@ discard block |
||
945 | 945 | } |
946 | 946 | |
947 | 947 | $array[$i]['ref'] = $objSourceLine->ref; |
948 | - $array[$i]['label'] = $objSourceLine->label?$objSourceLine->label:$objSourceLine->description; |
|
948 | + $array[$i]['label'] = $objSourceLine->label ? $objSourceLine->label : $objSourceLine->description; |
|
949 | 949 | } |
950 | - elseif($objSourceLine->qty - $row[1] < 0) |
|
950 | + elseif ($objSourceLine->qty - $row[1] < 0) |
|
951 | 951 | { |
952 | - $array[$i]['qty'] = $objSourceLine->qty - $row[1]. " Erreur livraison !"; |
|
952 | + $array[$i]['qty'] = $objSourceLine->qty - $row[1]." Erreur livraison !"; |
|
953 | 953 | $array[$i]['ref'] = $objSourceLine->ref; |
954 | - $array[$i]['label'] = $objSourceLine->label?$objSourceLine->label:$objSourceLine->description; |
|
954 | + $array[$i]['label'] = $objSourceLine->label ? $objSourceLine->label : $objSourceLine->description; |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | $i++; |
@@ -960,7 +960,7 @@ discard block |
||
960 | 960 | } |
961 | 961 | else |
962 | 962 | { |
963 | - $this->error=$this->db->error()." - sql=$sqlSourceLine"; |
|
963 | + $this->error = $this->db->error()." - sql=$sqlSourceLine"; |
|
964 | 964 | return -1; |
965 | 965 | } |
966 | 966 | } |
@@ -977,11 +977,11 @@ discard block |
||
977 | 977 | if ($user->rights->expedition->creer) |
978 | 978 | { |
979 | 979 | $sql = "UPDATE ".MAIN_DB_PREFIX."livraison"; |
980 | - $sql.= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null'); |
|
981 | - $sql.= " WHERE rowid = ".$this->id; |
|
980 | + $sql .= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null'); |
|
981 | + $sql .= " WHERE rowid = ".$this->id; |
|
982 | 982 | |
983 | 983 | dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG); |
984 | - $resql=$this->db->query($sql); |
|
984 | + $resql = $this->db->query($sql); |
|
985 | 985 | if ($resql) |
986 | 986 | { |
987 | 987 | $this->date_delivery = $date_livraison; |
@@ -989,7 +989,7 @@ discard block |
||
989 | 989 | } |
990 | 990 | else |
991 | 991 | { |
992 | - $this->error=$this->db->error(); |
|
992 | + $this->error = $this->db->error(); |
|
993 | 993 | return -1; |
994 | 994 | } |
995 | 995 | } |
@@ -1009,19 +1009,19 @@ discard block |
||
1009 | 1009 | * @param int $hideref Hide ref |
1010 | 1010 | * @return int 0 if KO, 1 if OK |
1011 | 1011 | */ |
1012 | - public function generateDocument($modele, $outputlangs='',$hidedetails=0,$hidedesc=0,$hideref=0) |
|
1012 | + public function generateDocument($modele, $outputlangs = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
1013 | 1013 | { |
1014 | - global $conf,$user,$langs; |
|
1014 | + global $conf, $user, $langs; |
|
1015 | 1015 | |
1016 | 1016 | $langs->load("deliveries"); |
1017 | 1017 | |
1018 | - if (! dol_strlen($modele)) { |
|
1018 | + if (!dol_strlen($modele)) { |
|
1019 | 1019 | |
1020 | 1020 | $modele = 'typhon'; |
1021 | 1021 | |
1022 | 1022 | if ($this->modelpdf) { |
1023 | 1023 | $modele = $this->modelpdf; |
1024 | - } elseif (! empty($conf->global->LIVRAISON_ADDON_PDF)) { |
|
1024 | + } elseif (!empty($conf->global->LIVRAISON_ADDON_PDF)) { |
|
1025 | 1025 | $modele = $conf->global->LIVRAISON_ADDON_PDF; |
1026 | 1026 | } |
1027 | 1027 | } |
@@ -1066,8 +1066,8 @@ discard block |
||
1066 | 1066 | var $price; |
1067 | 1067 | var $fk_product; |
1068 | 1068 | var $origin_id; |
1069 | - var $label; // Label produit |
|
1070 | - var $description; // Description produit |
|
1069 | + var $label; // Label produit |
|
1070 | + var $description; // Description produit |
|
1071 | 1071 | /** |
1072 | 1072 | * @deprecated |
1073 | 1073 | * @see product_ref |
@@ -1082,8 +1082,8 @@ discard block |
||
1082 | 1082 | public $product_ref; |
1083 | 1083 | public $product_label; |
1084 | 1084 | |
1085 | - public $element='livraisondet'; |
|
1086 | - public $table_element='livraisondet'; |
|
1085 | + public $element = 'livraisondet'; |
|
1086 | + public $table_element = 'livraisondet'; |
|
1087 | 1087 | |
1088 | 1088 | /** |
1089 | 1089 | * Constructor |
@@ -1092,7 +1092,7 @@ discard block |
||
1092 | 1092 | */ |
1093 | 1093 | function __construct($db) |
1094 | 1094 | { |
1095 | - $this->db=$db; |
|
1095 | + $this->db = $db; |
|
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | } |
@@ -30,8 +30,12 @@ discard block |
||
30 | 30 | require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; |
31 | 31 | require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; |
32 | 32 | require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; |
33 | -if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
34 | -if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
33 | +if (! empty($conf->propal->enabled)) { |
|
34 | + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
35 | +} |
|
36 | +if (! empty($conf->commande->enabled)) { |
|
37 | + require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
38 | +} |
|
35 | 39 | |
36 | 40 | |
37 | 41 | /** |
@@ -82,7 +86,9 @@ discard block |
||
82 | 86 | |
83 | 87 | dol_syslog("Livraison::create"); |
84 | 88 | |
85 | - if (empty($this->model_pdf)) $this->model_pdf=$conf->global->LIVRAISON_ADDON_PDF; |
|
89 | + if (empty($this->model_pdf)) { |
|
90 | + $this->model_pdf=$conf->global->LIVRAISON_ADDON_PDF; |
|
91 | + } |
|
86 | 92 | |
87 | 93 | $error = 0; |
88 | 94 | |
@@ -155,7 +161,10 @@ discard block |
||
155 | 161 | for ($i = 0; $i < $num; $i++) |
156 | 162 | { |
157 | 163 | $origin_id=$this->lines[$i]->origin_line_id; |
158 | - if (! $origin_id) $origin_id=$this->lines[$i]->commande_ligne_id; // For backward compatibility |
|
164 | + if (! $origin_id) { |
|
165 | + $origin_id=$this->lines[$i]->commande_ligne_id; |
|
166 | + } |
|
167 | + // For backward compatibility |
|
159 | 168 | |
160 | 169 | if (! $this->create_line($origin_id, $this->lines[$i]->qty, $this->lines[$i]->fk_product, $this->lines[$i]->description)) |
161 | 170 | { |
@@ -186,24 +195,21 @@ discard block |
||
186 | 195 | { |
187 | 196 | $this->db->commit(); |
188 | 197 | return $this->id; |
189 | - } |
|
190 | - else |
|
198 | + } else |
|
191 | 199 | { |
192 | 200 | $error++; |
193 | 201 | $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror; |
194 | 202 | $this->db->rollback(); |
195 | 203 | return -3; |
196 | 204 | } |
197 | - } |
|
198 | - else |
|
205 | + } else |
|
199 | 206 | { |
200 | 207 | $error++; |
201 | 208 | $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror; |
202 | 209 | $this->db->rollback(); |
203 | 210 | return -2; |
204 | 211 | } |
205 | - } |
|
206 | - else |
|
212 | + } else |
|
207 | 213 | { |
208 | 214 | $error++; |
209 | 215 | $this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror; |
@@ -299,7 +305,9 @@ discard block |
||
299 | 305 | $this->libelle_incoterms = $obj->libelle_incoterms; |
300 | 306 | $this->db->free($result); |
301 | 307 | |
302 | - if ($this->statut == 0) $this->brouillon = 1; |
|
308 | + if ($this->statut == 0) { |
|
309 | + $this->brouillon = 1; |
|
310 | + } |
|
303 | 311 | |
304 | 312 | // Retreive all extrafield |
305 | 313 | // fetch optionals attributes and labels |
@@ -315,15 +323,13 @@ discard block |
||
315 | 323 | } |
316 | 324 | |
317 | 325 | return 1; |
318 | - } |
|
319 | - else |
|
326 | + } else |
|
320 | 327 | { |
321 | 328 | $this->error='Delivery with id '.$id.' not found sql='.$sql; |
322 | 329 | dol_syslog(get_class($this).'::fetch Error '.$this->error, LOG_ERR); |
323 | 330 | return -2; |
324 | 331 | } |
325 | - } |
|
326 | - else |
|
332 | + } else |
|
327 | 333 | { |
328 | 334 | $this->error=$this->db->error(); |
329 | 335 | return -1; |
@@ -366,11 +372,12 @@ discard block |
||
366 | 372 | $soc = new Societe($this->db); |
367 | 373 | $soc->fetch($this->socid); |
368 | 374 | |
369 | - if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life |
|
375 | + if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { |
|
376 | + // empty should not happened, but when it occurs, the test save life |
|
370 | 377 | { |
371 | 378 | $numref = $objMod->livraison_get_num($soc,$this); |
372 | - } |
|
373 | - else |
|
379 | + } |
|
380 | + } else |
|
374 | 381 | { |
375 | 382 | $numref = $this->ref; |
376 | 383 | } |
@@ -414,7 +421,9 @@ discard block |
||
414 | 421 | { |
415 | 422 | // Call trigger |
416 | 423 | $result=$this->call_trigger('DELIVERY_VALIDATE',$user); |
417 | - if ($result < 0) $error++; |
|
424 | + if ($result < 0) { |
|
425 | + $error++; |
|
426 | + } |
|
418 | 427 | // End call triggers |
419 | 428 | } |
420 | 429 | |
@@ -466,16 +475,14 @@ discard block |
||
466 | 475 | { |
467 | 476 | $this->db->commit(); |
468 | 477 | return 1; |
469 | - } |
|
470 | - else |
|
478 | + } else |
|
471 | 479 | { |
472 | 480 | $this->db->rollback(); |
473 | 481 | return -1; |
474 | 482 | } |
475 | 483 | } |
476 | 484 | } |
477 | - } |
|
478 | - else |
|
485 | + } else |
|
479 | 486 | { |
480 | 487 | $this->error="Non autorise"; |
481 | 488 | dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); |
@@ -540,9 +547,11 @@ discard block |
||
540 | 547 | global $conf; |
541 | 548 | $error = 0; |
542 | 549 | |
543 | - if ($id > 0 && !$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used |
|
550 | + if ($id > 0 && !$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) { |
|
551 | + // For avoid conflicts if trigger used |
|
544 | 552 | { |
545 | 553 | $livraisonline = new LivraisonLigne($this->db); |
554 | + } |
|
546 | 555 | $livraisonline->array_options=$array_options; |
547 | 556 | $livraisonline->id=$id; |
548 | 557 | $result=$livraisonline->insertExtraFields(); |
@@ -554,8 +563,11 @@ discard block |
||
554 | 563 | } |
555 | 564 | } |
556 | 565 | |
557 | - if (! $error) return 1; |
|
558 | - else return -1; |
|
566 | + if (! $error) { |
|
567 | + return 1; |
|
568 | + } else { |
|
569 | + return -1; |
|
570 | + } |
|
559 | 571 | } |
560 | 572 | |
561 | 573 | |
@@ -595,8 +607,7 @@ discard block |
||
595 | 607 | $this->update_price(); |
596 | 608 | |
597 | 609 | return 1; |
598 | - } |
|
599 | - else |
|
610 | + } else |
|
600 | 611 | { |
601 | 612 | return 0; |
602 | 613 | } |
@@ -623,7 +634,9 @@ discard block |
||
623 | 634 | { |
624 | 635 | // Delete linked object |
625 | 636 | $res = $this->deleteObjectLinked(); |
626 | - if ($res < 0) $error++; |
|
637 | + if ($res < 0) { |
|
638 | + $error++; |
|
639 | + } |
|
627 | 640 | |
628 | 641 | if (! $error) |
629 | 642 | { |
@@ -666,22 +679,19 @@ discard block |
||
666 | 679 | // End call triggers |
667 | 680 | |
668 | 681 | return 1; |
669 | - } |
|
670 | - else |
|
682 | + } else |
|
671 | 683 | { |
672 | 684 | $this->error=$this->db->lasterror()." - sql=$sql"; |
673 | 685 | $this->db->rollback(); |
674 | 686 | return -3; |
675 | 687 | } |
676 | - } |
|
677 | - else |
|
688 | + } else |
|
678 | 689 | { |
679 | 690 | $this->error=$this->db->lasterror()." - sql=$sql"; |
680 | 691 | $this->db->rollback(); |
681 | 692 | return -2; |
682 | 693 | } |
683 | - } |
|
684 | - else |
|
694 | + } else |
|
685 | 695 | { |
686 | 696 | $this->error=$this->db->lasterror()." - sql=$sql"; |
687 | 697 | $this->db->rollback(); |
@@ -711,16 +721,24 @@ discard block |
||
711 | 721 | //{ |
712 | 722 | // Add param to save lastsearch_values or not |
713 | 723 | $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); |
714 | - if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; |
|
715 | - if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; |
|
724 | + if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) { |
|
725 | + $add_save_lastsearch_values=1; |
|
726 | + } |
|
727 | + if ($add_save_lastsearch_values) { |
|
728 | + $url.='&save_lastsearch_values=1'; |
|
729 | + } |
|
716 | 730 | //} |
717 | 731 | |
718 | 732 | |
719 | 733 | $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
720 | 734 | $linkend='</a>'; |
721 | 735 | |
722 | - if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
723 | - if ($withpicto && $withpicto != 2) $result.=' '; |
|
736 | + if ($withpicto) { |
|
737 | + $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
738 | + } |
|
739 | + if ($withpicto && $withpicto != 2) { |
|
740 | + $result.=' '; |
|
741 | + } |
|
724 | 742 | $result.=$linkstart.$this->ref.$linkend; |
725 | 743 | return $result; |
726 | 744 | } |
@@ -807,27 +825,51 @@ discard block |
||
807 | 825 | |
808 | 826 | if ($mode==0) |
809 | 827 | { |
810 | - if ($statut==-1) return $langs->trans('StatusDeliveryCanceled'); |
|
811 | - if ($statut==0) return $langs->trans('StatusDeliveryDraft'); |
|
812 | - if ($statut==1) return $langs->trans('StatusDeliveryValidated'); |
|
828 | + if ($statut==-1) { |
|
829 | + return $langs->trans('StatusDeliveryCanceled'); |
|
830 | + } |
|
831 | + if ($statut==0) { |
|
832 | + return $langs->trans('StatusDeliveryDraft'); |
|
833 | + } |
|
834 | + if ($statut==1) { |
|
835 | + return $langs->trans('StatusDeliveryValidated'); |
|
836 | + } |
|
813 | 837 | } |
814 | 838 | if ($mode==1) |
815 | 839 | { |
816 | - if ($statut==-1) return $langs->trans($this->statuts[$statut]); |
|
817 | - if ($statut==0) return $langs->trans($this->statuts[$statut]); |
|
818 | - if ($statut==1) return $langs->trans($this->statuts[$statut]); |
|
840 | + if ($statut==-1) { |
|
841 | + return $langs->trans($this->statuts[$statut]); |
|
842 | + } |
|
843 | + if ($statut==0) { |
|
844 | + return $langs->trans($this->statuts[$statut]); |
|
845 | + } |
|
846 | + if ($statut==1) { |
|
847 | + return $langs->trans($this->statuts[$statut]); |
|
848 | + } |
|
819 | 849 | } |
820 | 850 | if ($mode == 4) |
821 | 851 | { |
822 | - if ($statut==-1) return img_picto($langs->trans('StatusDeliveryCanceled'),'statut5').' '.$langs->trans('StatusDeliveryCanceled'); |
|
823 | - if ($statut==0) return img_picto($langs->trans('StatusDeliveryDraft'),'statut0').' '.$langs->trans('StatusDeliveryDraft'); |
|
824 | - if ($statut==1) return img_picto($langs->trans('StatusDeliveryValidated'),'statut4').' '.$langs->trans('StatusDeliveryValidated'); |
|
852 | + if ($statut==-1) { |
|
853 | + return img_picto($langs->trans('StatusDeliveryCanceled'),'statut5').' '.$langs->trans('StatusDeliveryCanceled'); |
|
854 | + } |
|
855 | + if ($statut==0) { |
|
856 | + return img_picto($langs->trans('StatusDeliveryDraft'),'statut0').' '.$langs->trans('StatusDeliveryDraft'); |
|
857 | + } |
|
858 | + if ($statut==1) { |
|
859 | + return img_picto($langs->trans('StatusDeliveryValidated'),'statut4').' '.$langs->trans('StatusDeliveryValidated'); |
|
860 | + } |
|
825 | 861 | } |
826 | 862 | if ($mode == 6) |
827 | 863 | { |
828 | - if ($statut==-1) return $langs->trans('StatusDeliveryCanceled').' '.img_picto($langs->trans('StatusDeliveryCanceled'),'statut5'); |
|
829 | - if ($statut==0) return $langs->trans('StatusDeliveryDraft').' '.img_picto($langs->trans('StatusDeliveryDraft'),'statut0'); |
|
830 | - if ($statut==1) return $langs->trans('StatusDeliveryValidated').' '.img_picto($langs->trans('StatusDeliveryValidated'),'statut4'); |
|
864 | + if ($statut==-1) { |
|
865 | + return $langs->trans('StatusDeliveryCanceled').' '.img_picto($langs->trans('StatusDeliveryCanceled'),'statut5'); |
|
866 | + } |
|
867 | + if ($statut==0) { |
|
868 | + return $langs->trans('StatusDeliveryDraft').' '.img_picto($langs->trans('StatusDeliveryDraft'),'statut0'); |
|
869 | + } |
|
870 | + if ($statut==1) { |
|
871 | + return $langs->trans('StatusDeliveryValidated').' '.img_picto($langs->trans('StatusDeliveryValidated'),'statut4'); |
|
872 | + } |
|
831 | 873 | } |
832 | 874 | } |
833 | 875 | |
@@ -938,16 +980,14 @@ discard block |
||
938 | 980 | if ($row[0] == $objSourceLine->rowid) |
939 | 981 | { |
940 | 982 | $array[$i]['qty'] = $objSourceLine->qty - $row[1]; |
941 | - } |
|
942 | - else |
|
983 | + } else |
|
943 | 984 | { |
944 | 985 | $array[$i]['qty'] = $objSourceLine->qty; |
945 | 986 | } |
946 | 987 | |
947 | 988 | $array[$i]['ref'] = $objSourceLine->ref; |
948 | 989 | $array[$i]['label'] = $objSourceLine->label?$objSourceLine->label:$objSourceLine->description; |
949 | - } |
|
950 | - elseif($objSourceLine->qty - $row[1] < 0) |
|
990 | + } elseif($objSourceLine->qty - $row[1] < 0) |
|
951 | 991 | { |
952 | 992 | $array[$i]['qty'] = $objSourceLine->qty - $row[1]. " Erreur livraison !"; |
953 | 993 | $array[$i]['ref'] = $objSourceLine->ref; |
@@ -957,8 +997,7 @@ discard block |
||
957 | 997 | $i++; |
958 | 998 | } |
959 | 999 | return $array; |
960 | - } |
|
961 | - else |
|
1000 | + } else |
|
962 | 1001 | { |
963 | 1002 | $this->error=$this->db->error()." - sql=$sqlSourceLine"; |
964 | 1003 | return -1; |
@@ -986,14 +1025,12 @@ discard block |
||
986 | 1025 | { |
987 | 1026 | $this->date_delivery = $date_livraison; |
988 | 1027 | return 1; |
989 | - } |
|
990 | - else |
|
1028 | + } else |
|
991 | 1029 | { |
992 | 1030 | $this->error=$this->db->error(); |
993 | 1031 | return -1; |
994 | 1032 | } |
995 | - } |
|
996 | - else |
|
1033 | + } else |
|
997 | 1034 | { |
998 | 1035 | return -2; |
999 | 1036 | } |
@@ -334,7 +334,7 @@ |
||
334 | 334 | * |
335 | 335 | * @param string $selected Paper format pre-selected |
336 | 336 | * @param string $htmlname Name of HTML select field |
337 | - * @param string $filter Value to filter on code |
|
337 | + * @param integer $filter Value to filter on code |
|
338 | 338 | * @param int $showempty Add empty value |
339 | 339 | * @return string Return HTML output |
340 | 340 | */ |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | |
88 | 88 | foreach ($langs_available as $key => $value) |
89 | 89 | { |
90 | - $valuetoshow=$value; |
|
91 | - if ($showcode) $valuetoshow=$key.' - '.$value; |
|
90 | + $valuetoshow=$value; |
|
91 | + if ($showcode) $valuetoshow=$key.' - '.$value; |
|
92 | 92 | |
93 | 93 | if ($filter && is_array($filter)) |
94 | 94 | { |
@@ -109,79 +109,79 @@ discard block |
||
109 | 109 | $out.= '</select>'; |
110 | 110 | |
111 | 111 | // Make select dynamic |
112 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
113 | - $out.= ajax_combobox($htmlname); |
|
112 | + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
113 | + $out.= ajax_combobox($htmlname); |
|
114 | 114 | |
115 | 115 | return $out; |
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
119 | - * Return list of available menus (eldy_backoffice, ...) |
|
120 | - * |
|
121 | - * @param string $selected Preselected menu value |
|
122 | - * @param string $htmlname Name of html select |
|
123 | - * @param array $dirmenuarray Array of directories to scan |
|
124 | - * @param string $moreattrib More attributes on html select tag |
|
125 | - * @return integer|null |
|
126 | - */ |
|
127 | - function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib='') |
|
128 | - { |
|
129 | - global $langs,$conf; |
|
119 | + * Return list of available menus (eldy_backoffice, ...) |
|
120 | + * |
|
121 | + * @param string $selected Preselected menu value |
|
122 | + * @param string $htmlname Name of html select |
|
123 | + * @param array $dirmenuarray Array of directories to scan |
|
124 | + * @param string $moreattrib More attributes on html select tag |
|
125 | + * @return integer|null |
|
126 | + */ |
|
127 | + function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib='') |
|
128 | + { |
|
129 | + global $langs,$conf; |
|
130 | 130 | |
131 | - // Clean parameters |
|
131 | + // Clean parameters |
|
132 | 132 | |
133 | 133 | |
134 | - // Check parameters |
|
135 | - if (! is_array($dirmenuarray)) return -1; |
|
134 | + // Check parameters |
|
135 | + if (! is_array($dirmenuarray)) return -1; |
|
136 | 136 | |
137 | 137 | $menuarray=array(); |
138 | - foreach ($conf->file->dol_document_root as $dirroot) |
|
139 | - { |
|
140 | - foreach($dirmenuarray as $dirtoscan) |
|
141 | - { |
|
142 | - $dir=$dirroot.$dirtoscan; |
|
143 | - //print $dir.'<br>'; |
|
144 | - if (is_dir($dir)) |
|
145 | - { |
|
146 | - $handle=opendir($dir); |
|
147 | - if (is_resource($handle)) |
|
148 | - { |
|
149 | - while (($file = readdir($handle))!==false) |
|
150 | - { |
|
151 | - if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index') |
|
152 | - { |
|
153 | - if (preg_match('/lib\.php$/i',$file)) continue; // We exclude library files |
|
154 | - if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
155 | - if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
156 | - if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
157 | - |
|
158 | - $filelib=preg_replace('/\.php$/i','',$file); |
|
159 | - $prefix=''; |
|
160 | - // 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other |
|
161 | - if (preg_match('/^eldy/i',$file)) $prefix='0'; |
|
162 | - else if (preg_match('/^smartphone/i',$file)) $prefix='2'; |
|
163 | - else $prefix='3'; |
|
164 | - |
|
165 | - if ($file == $selected) |
|
166 | - { |
|
167 | - $menuarray[$prefix.'_'.$file]='<option value="'.$file.'" selected>'.$filelib.'</option>'; |
|
168 | - } |
|
169 | - else |
|
170 | - { |
|
171 | - $menuarray[$prefix.'_'.$file]='<option value="'.$file.'">'.$filelib.'</option>'; |
|
172 | - } |
|
173 | - } |
|
174 | - } |
|
175 | - closedir($handle); |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - } |
|
138 | + foreach ($conf->file->dol_document_root as $dirroot) |
|
139 | + { |
|
140 | + foreach($dirmenuarray as $dirtoscan) |
|
141 | + { |
|
142 | + $dir=$dirroot.$dirtoscan; |
|
143 | + //print $dir.'<br>'; |
|
144 | + if (is_dir($dir)) |
|
145 | + { |
|
146 | + $handle=opendir($dir); |
|
147 | + if (is_resource($handle)) |
|
148 | + { |
|
149 | + while (($file = readdir($handle))!==false) |
|
150 | + { |
|
151 | + if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index') |
|
152 | + { |
|
153 | + if (preg_match('/lib\.php$/i',$file)) continue; // We exclude library files |
|
154 | + if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
155 | + if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
156 | + if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
157 | + |
|
158 | + $filelib=preg_replace('/\.php$/i','',$file); |
|
159 | + $prefix=''; |
|
160 | + // 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other |
|
161 | + if (preg_match('/^eldy/i',$file)) $prefix='0'; |
|
162 | + else if (preg_match('/^smartphone/i',$file)) $prefix='2'; |
|
163 | + else $prefix='3'; |
|
164 | + |
|
165 | + if ($file == $selected) |
|
166 | + { |
|
167 | + $menuarray[$prefix.'_'.$file]='<option value="'.$file.'" selected>'.$filelib.'</option>'; |
|
168 | + } |
|
169 | + else |
|
170 | + { |
|
171 | + $menuarray[$prefix.'_'.$file]='<option value="'.$file.'">'.$filelib.'</option>'; |
|
172 | + } |
|
173 | + } |
|
174 | + } |
|
175 | + closedir($handle); |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + } |
|
180 | 180 | ksort($menuarray); |
181 | 181 | |
182 | 182 | // Output combo list of menus |
183 | - print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>'; |
|
184 | - $oldprefix=''; |
|
183 | + print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>'; |
|
184 | + $oldprefix=''; |
|
185 | 185 | foreach ($menuarray as $key => $val) |
186 | 186 | { |
187 | 187 | $tab=explode('_',$key); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | // Affiche titre |
194 | 194 | print '<option value="-1" disabled>'; |
195 | 195 | if ($newprefix=='0') print '-- '.$langs->trans("VersionRecommanded").' --'; |
196 | - if ($newprefix=='1') print '-- '.$langs->trans("VersionExperimental").' --'; |
|
196 | + if ($newprefix=='1') print '-- '.$langs->trans("VersionExperimental").' --'; |
|
197 | 197 | if ($newprefix=='2') print '-- '.$langs->trans("VersionDevelopment").' --'; |
198 | 198 | if ($newprefix=='3') print '-- '.$langs->trans("Other").' --'; |
199 | 199 | print '</option>'; |
@@ -202,67 +202,67 @@ discard block |
||
202 | 202 | print $val."\n"; // Show menu entry |
203 | 203 | } |
204 | 204 | print '</select>'; |
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Return combo list of available menu families |
|
209 | - * |
|
210 | - * @param string $selected Menu pre-selected |
|
211 | - * @param string $htmlname Name of html select |
|
212 | - * @param string[] $dirmenuarray Directories to scan |
|
213 | - * @return void |
|
214 | - */ |
|
215 | - function select_menu_families($selected, $htmlname, $dirmenuarray) |
|
216 | - { |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Return combo list of available menu families |
|
209 | + * |
|
210 | + * @param string $selected Menu pre-selected |
|
211 | + * @param string $htmlname Name of html select |
|
212 | + * @param string[] $dirmenuarray Directories to scan |
|
213 | + * @return void |
|
214 | + */ |
|
215 | + function select_menu_families($selected, $htmlname, $dirmenuarray) |
|
216 | + { |
|
217 | 217 | global $langs,$conf; |
218 | 218 | |
219 | - //$expdevmenu=array('smartphone_backoffice.php','smartphone_frontoffice.php'); // Menu to disable if $conf->global->MAIN_FEATURES_LEVEL is not set |
|
219 | + //$expdevmenu=array('smartphone_backoffice.php','smartphone_frontoffice.php'); // Menu to disable if $conf->global->MAIN_FEATURES_LEVEL is not set |
|
220 | 220 | $expdevmenu=array(); |
221 | 221 | |
222 | 222 | $menuarray=array(); |
223 | 223 | |
224 | 224 | foreach($dirmenuarray as $dirmenu) |
225 | 225 | { |
226 | - foreach ($conf->file->dol_document_root as $dirroot) |
|
227 | - { |
|
228 | - $dir=$dirroot.$dirmenu; |
|
229 | - if (is_dir($dir)) |
|
230 | - { |
|
231 | - $handle=opendir($dir); |
|
232 | - if (is_resource($handle)) |
|
233 | - { |
|
234 | - while (($file = readdir($handle))!==false) |
|
235 | - { |
|
236 | - if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') |
|
237 | - { |
|
238 | - $filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file); |
|
239 | - if (preg_match('/^index/i',$filelib)) continue; |
|
240 | - if (preg_match('/^default/i',$filelib)) continue; |
|
241 | - if (preg_match('/^empty/i',$filelib)) continue; |
|
242 | - if (preg_match('/\.lib/i',$filelib)) continue; |
|
243 | - if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) continue; |
|
244 | - |
|
245 | - $menuarray[$filelib]=1; |
|
246 | - } |
|
247 | - $menuarray['all']=1; |
|
248 | - } |
|
249 | - closedir($handle); |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
226 | + foreach ($conf->file->dol_document_root as $dirroot) |
|
227 | + { |
|
228 | + $dir=$dirroot.$dirmenu; |
|
229 | + if (is_dir($dir)) |
|
230 | + { |
|
231 | + $handle=opendir($dir); |
|
232 | + if (is_resource($handle)) |
|
233 | + { |
|
234 | + while (($file = readdir($handle))!==false) |
|
235 | + { |
|
236 | + if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') |
|
237 | + { |
|
238 | + $filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file); |
|
239 | + if (preg_match('/^index/i',$filelib)) continue; |
|
240 | + if (preg_match('/^default/i',$filelib)) continue; |
|
241 | + if (preg_match('/^empty/i',$filelib)) continue; |
|
242 | + if (preg_match('/\.lib/i',$filelib)) continue; |
|
243 | + if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) continue; |
|
244 | + |
|
245 | + $menuarray[$filelib]=1; |
|
246 | + } |
|
247 | + $menuarray['all']=1; |
|
248 | + } |
|
249 | + closedir($handle); |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | ksort($menuarray); |
256 | 256 | |
257 | 257 | // Affichage liste deroulante des menus |
258 | - print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">'; |
|
259 | - $oldprefix=''; |
|
258 | + print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">'; |
|
259 | + $oldprefix=''; |
|
260 | 260 | foreach ($menuarray as $key => $val) |
261 | 261 | { |
262 | 262 | $tab=explode('_',$key); |
263 | 263 | $newprefix=$tab[0]; |
264 | 264 | print '<option value="'.$key.'"'; |
265 | - if ($key == $selected) |
|
265 | + if ($key == $selected) |
|
266 | 266 | { |
267 | 267 | print ' selected'; |
268 | 268 | } |
@@ -272,21 +272,21 @@ discard block |
||
272 | 272 | print '</option>'."\n"; |
273 | 273 | } |
274 | 274 | print '</select>'; |
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * Return a HTML select list of timezones |
|
280 | - * |
|
281 | - * @param string $selected Menu pre-selectionnee |
|
282 | - * @param string $htmlname Nom de la zone select |
|
283 | - * @return void |
|
284 | - */ |
|
285 | - function select_timezone($selected,$htmlname) |
|
286 | - { |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * Return a HTML select list of timezones |
|
280 | + * |
|
281 | + * @param string $selected Menu pre-selectionnee |
|
282 | + * @param string $htmlname Nom de la zone select |
|
283 | + * @return void |
|
284 | + */ |
|
285 | + function select_timezone($selected,$htmlname) |
|
286 | + { |
|
287 | 287 | global $langs,$conf; |
288 | 288 | |
289 | - print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">'; |
|
289 | + print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">'; |
|
290 | 290 | print '<option value="-1"> </option>'; |
291 | 291 | |
292 | 292 | $arraytz=array( |
@@ -345,24 +345,24 @@ discard block |
||
345 | 345 | $sql = "SELECT code, label, width, height, unit"; |
346 | 346 | $sql.= " FROM ".MAIN_DB_PREFIX."c_paper_format"; |
347 | 347 | $sql.= " WHERE active=1"; |
348 | - if ($filter) $sql.=" AND code LIKE '%".$this->db->escape($filter)."%'"; |
|
349 | - |
|
350 | - $resql=$this->db->query($sql); |
|
351 | - if ($resql) |
|
352 | - { |
|
353 | - $num=$this->db->num_rows($resql); |
|
354 | - $i=0; |
|
355 | - while ($i < $num) |
|
356 | - { |
|
357 | - $obj=$this->db->fetch_object($resql); |
|
358 | - $unitKey = $langs->trans('SizeUnit'.$obj->unit); |
|
359 | - |
|
360 | - $paperformat[$obj->code]= $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey); |
|
361 | - |
|
362 | - $i++; |
|
363 | - } |
|
364 | - } |
|
365 | - else |
|
348 | + if ($filter) $sql.=" AND code LIKE '%".$this->db->escape($filter)."%'"; |
|
349 | + |
|
350 | + $resql=$this->db->query($sql); |
|
351 | + if ($resql) |
|
352 | + { |
|
353 | + $num=$this->db->num_rows($resql); |
|
354 | + $i=0; |
|
355 | + while ($i < $num) |
|
356 | + { |
|
357 | + $obj=$this->db->fetch_object($resql); |
|
358 | + $unitKey = $langs->trans('SizeUnit'.$obj->unit); |
|
359 | + |
|
360 | + $paperformat[$obj->code]= $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey); |
|
361 | + |
|
362 | + $i++; |
|
363 | + } |
|
364 | + } |
|
365 | + else |
|
366 | 366 | { |
367 | 367 | dol_print_error($this->db); |
368 | 368 | return ''; |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | } |
379 | 379 | foreach ($paperformat as $key => $value) |
380 | 380 | { |
381 | - if ($selected == $key) |
|
381 | + if ($selected == $key) |
|
382 | 382 | { |
383 | 383 | $out.= '<option value="'.$key.'" selected>'.$value.'</option>'; |
384 | 384 | } |
@@ -58,59 +58,59 @@ discard block |
||
58 | 58 | * @param int $showcode Add language code into label |
59 | 59 | * @return string Return HTML select string with list of languages |
60 | 60 | */ |
61 | - function select_language($selected='', $htmlname='lang_id', $showauto=0, $filter=null, $showempty='', $showwarning=0, $disabled=0, $morecss='', $showcode=0) |
|
61 | + function select_language($selected = '', $htmlname = 'lang_id', $showauto = 0, $filter = null, $showempty = '', $showwarning = 0, $disabled = 0, $morecss = '', $showcode = 0) |
|
62 | 62 | { |
63 | 63 | global $langs; |
64 | 64 | |
65 | - $langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT,12); |
|
65 | + $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12); |
|
66 | 66 | |
67 | - $out=''; |
|
67 | + $out = ''; |
|
68 | 68 | |
69 | - $out.= '<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled':'').'>'; |
|
69 | + $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled ? ' disabled' : '').'>'; |
|
70 | 70 | if ($showempty) |
71 | 71 | { |
72 | - $out.= '<option value="0"'; |
|
73 | - if ($selected == '') $out.= ' selected'; |
|
74 | - $out.= '>'; |
|
75 | - if ($showempty != '1') $out.=$showempty; |
|
76 | - else $out.=' '; |
|
77 | - $out.='</option>'; |
|
72 | + $out .= '<option value="0"'; |
|
73 | + if ($selected == '') $out .= ' selected'; |
|
74 | + $out .= '>'; |
|
75 | + if ($showempty != '1') $out .= $showempty; |
|
76 | + else $out .= ' '; |
|
77 | + $out .= '</option>'; |
|
78 | 78 | } |
79 | 79 | if ($showauto) |
80 | 80 | { |
81 | - $out.= '<option value="auto"'; |
|
82 | - if ($selected == 'auto') $out.= ' selected'; |
|
83 | - $out.= '>'.$langs->trans("AutoDetectLang").'</option>'; |
|
81 | + $out .= '<option value="auto"'; |
|
82 | + if ($selected == 'auto') $out .= ' selected'; |
|
83 | + $out .= '>'.$langs->trans("AutoDetectLang").'</option>'; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | asort($langs_available); |
87 | 87 | |
88 | 88 | foreach ($langs_available as $key => $value) |
89 | 89 | { |
90 | - $valuetoshow=$value; |
|
91 | - if ($showcode) $valuetoshow=$key.' - '.$value; |
|
90 | + $valuetoshow = $value; |
|
91 | + if ($showcode) $valuetoshow = $key.' - '.$value; |
|
92 | 92 | |
93 | 93 | if ($filter && is_array($filter)) |
94 | 94 | { |
95 | - if ( ! array_key_exists($key, $filter)) |
|
95 | + if (!array_key_exists($key, $filter)) |
|
96 | 96 | { |
97 | - $out.= '<option value="'.$key.'">'.$valuetoshow.'</option>'; |
|
97 | + $out .= '<option value="'.$key.'">'.$valuetoshow.'</option>'; |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | else if ($selected == $key) |
101 | 101 | { |
102 | - $out.= '<option value="'.$key.'" selected>'.$valuetoshow.'</option>'; |
|
102 | + $out .= '<option value="'.$key.'" selected>'.$valuetoshow.'</option>'; |
|
103 | 103 | } |
104 | 104 | else |
105 | 105 | { |
106 | - $out.= '<option value="'.$key.'">'.$valuetoshow.'</option>'; |
|
106 | + $out .= '<option value="'.$key.'">'.$valuetoshow.'</option>'; |
|
107 | 107 | } |
108 | 108 | } |
109 | - $out.= '</select>'; |
|
109 | + $out .= '</select>'; |
|
110 | 110 | |
111 | 111 | // Make select dynamic |
112 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
113 | - $out.= ajax_combobox($htmlname); |
|
112 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
113 | + $out .= ajax_combobox($htmlname); |
|
114 | 114 | |
115 | 115 | return $out; |
116 | 116 | } |
@@ -124,51 +124,51 @@ discard block |
||
124 | 124 | * @param string $moreattrib More attributes on html select tag |
125 | 125 | * @return integer|null |
126 | 126 | */ |
127 | - function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib='') |
|
127 | + function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib = '') |
|
128 | 128 | { |
129 | - global $langs,$conf; |
|
129 | + global $langs, $conf; |
|
130 | 130 | |
131 | 131 | // Clean parameters |
132 | 132 | |
133 | 133 | |
134 | 134 | // Check parameters |
135 | - if (! is_array($dirmenuarray)) return -1; |
|
135 | + if (!is_array($dirmenuarray)) return -1; |
|
136 | 136 | |
137 | - $menuarray=array(); |
|
137 | + $menuarray = array(); |
|
138 | 138 | foreach ($conf->file->dol_document_root as $dirroot) |
139 | 139 | { |
140 | - foreach($dirmenuarray as $dirtoscan) |
|
140 | + foreach ($dirmenuarray as $dirtoscan) |
|
141 | 141 | { |
142 | - $dir=$dirroot.$dirtoscan; |
|
142 | + $dir = $dirroot.$dirtoscan; |
|
143 | 143 | //print $dir.'<br>'; |
144 | 144 | if (is_dir($dir)) |
145 | 145 | { |
146 | - $handle=opendir($dir); |
|
146 | + $handle = opendir($dir); |
|
147 | 147 | if (is_resource($handle)) |
148 | 148 | { |
149 | - while (($file = readdir($handle))!==false) |
|
149 | + while (($file = readdir($handle)) !== false) |
|
150 | 150 | { |
151 | 151 | if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index') |
152 | 152 | { |
153 | - if (preg_match('/lib\.php$/i',$file)) continue; // We exclude library files |
|
154 | - if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
155 | - if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
156 | - if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
153 | + if (preg_match('/lib\.php$/i', $file)) continue; // We exclude library files |
|
154 | + if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i', $file)) continue; // We exclude all menu manager files |
|
155 | + if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i', $file)) continue; // We exclude all menu manager files |
|
156 | + if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i', $file)) continue; // We exclude all menu manager files |
|
157 | 157 | |
158 | - $filelib=preg_replace('/\.php$/i','',$file); |
|
159 | - $prefix=''; |
|
158 | + $filelib = preg_replace('/\.php$/i', '', $file); |
|
159 | + $prefix = ''; |
|
160 | 160 | // 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other |
161 | - if (preg_match('/^eldy/i',$file)) $prefix='0'; |
|
162 | - else if (preg_match('/^smartphone/i',$file)) $prefix='2'; |
|
163 | - else $prefix='3'; |
|
161 | + if (preg_match('/^eldy/i', $file)) $prefix = '0'; |
|
162 | + else if (preg_match('/^smartphone/i', $file)) $prefix = '2'; |
|
163 | + else $prefix = '3'; |
|
164 | 164 | |
165 | 165 | if ($file == $selected) |
166 | 166 | { |
167 | - $menuarray[$prefix.'_'.$file]='<option value="'.$file.'" selected>'.$filelib.'</option>'; |
|
167 | + $menuarray[$prefix.'_'.$file] = '<option value="'.$file.'" selected>'.$filelib.'</option>'; |
|
168 | 168 | } |
169 | 169 | else |
170 | 170 | { |
171 | - $menuarray[$prefix.'_'.$file]='<option value="'.$file.'">'.$filelib.'</option>'; |
|
171 | + $menuarray[$prefix.'_'.$file] = '<option value="'.$file.'">'.$filelib.'</option>'; |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | } |
@@ -180,26 +180,26 @@ discard block |
||
180 | 180 | ksort($menuarray); |
181 | 181 | |
182 | 182 | // Output combo list of menus |
183 | - print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>'; |
|
184 | - $oldprefix=''; |
|
183 | + print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>'; |
|
184 | + $oldprefix = ''; |
|
185 | 185 | foreach ($menuarray as $key => $val) |
186 | 186 | { |
187 | - $tab=explode('_',$key); |
|
188 | - $newprefix=$tab[0]; |
|
189 | - if ($newprefix=='1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) continue; |
|
190 | - if ($newprefix=='2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) continue; |
|
187 | + $tab = explode('_', $key); |
|
188 | + $newprefix = $tab[0]; |
|
189 | + if ($newprefix == '1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) continue; |
|
190 | + if ($newprefix == '2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) continue; |
|
191 | 191 | if ($newprefix != $oldprefix) // Add separators |
192 | 192 | { |
193 | 193 | // Affiche titre |
194 | 194 | print '<option value="-1" disabled>'; |
195 | - if ($newprefix=='0') print '-- '.$langs->trans("VersionRecommanded").' --'; |
|
196 | - if ($newprefix=='1') print '-- '.$langs->trans("VersionExperimental").' --'; |
|
197 | - if ($newprefix=='2') print '-- '.$langs->trans("VersionDevelopment").' --'; |
|
198 | - if ($newprefix=='3') print '-- '.$langs->trans("Other").' --'; |
|
195 | + if ($newprefix == '0') print '-- '.$langs->trans("VersionRecommanded").' --'; |
|
196 | + if ($newprefix == '1') print '-- '.$langs->trans("VersionExperimental").' --'; |
|
197 | + if ($newprefix == '2') print '-- '.$langs->trans("VersionDevelopment").' --'; |
|
198 | + if ($newprefix == '3') print '-- '.$langs->trans("Other").' --'; |
|
199 | 199 | print '</option>'; |
200 | - $oldprefix=$newprefix; |
|
200 | + $oldprefix = $newprefix; |
|
201 | 201 | } |
202 | - print $val."\n"; // Show menu entry |
|
202 | + print $val."\n"; // Show menu entry |
|
203 | 203 | } |
204 | 204 | print '</select>'; |
205 | 205 | } |
@@ -214,37 +214,37 @@ discard block |
||
214 | 214 | */ |
215 | 215 | function select_menu_families($selected, $htmlname, $dirmenuarray) |
216 | 216 | { |
217 | - global $langs,$conf; |
|
217 | + global $langs, $conf; |
|
218 | 218 | |
219 | 219 | //$expdevmenu=array('smartphone_backoffice.php','smartphone_frontoffice.php'); // Menu to disable if $conf->global->MAIN_FEATURES_LEVEL is not set |
220 | - $expdevmenu=array(); |
|
220 | + $expdevmenu = array(); |
|
221 | 221 | |
222 | - $menuarray=array(); |
|
222 | + $menuarray = array(); |
|
223 | 223 | |
224 | - foreach($dirmenuarray as $dirmenu) |
|
224 | + foreach ($dirmenuarray as $dirmenu) |
|
225 | 225 | { |
226 | 226 | foreach ($conf->file->dol_document_root as $dirroot) |
227 | 227 | { |
228 | - $dir=$dirroot.$dirmenu; |
|
228 | + $dir = $dirroot.$dirmenu; |
|
229 | 229 | if (is_dir($dir)) |
230 | 230 | { |
231 | - $handle=opendir($dir); |
|
231 | + $handle = opendir($dir); |
|
232 | 232 | if (is_resource($handle)) |
233 | 233 | { |
234 | - while (($file = readdir($handle))!==false) |
|
234 | + while (($file = readdir($handle)) !== false) |
|
235 | 235 | { |
236 | 236 | if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') |
237 | 237 | { |
238 | - $filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file); |
|
239 | - if (preg_match('/^index/i',$filelib)) continue; |
|
240 | - if (preg_match('/^default/i',$filelib)) continue; |
|
241 | - if (preg_match('/^empty/i',$filelib)) continue; |
|
242 | - if (preg_match('/\.lib/i',$filelib)) continue; |
|
243 | - if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) continue; |
|
244 | - |
|
245 | - $menuarray[$filelib]=1; |
|
238 | + $filelib = preg_replace('/(_backoffice|_frontoffice)?\.php$/i', '', $file); |
|
239 | + if (preg_match('/^index/i', $filelib)) continue; |
|
240 | + if (preg_match('/^default/i', $filelib)) continue; |
|
241 | + if (preg_match('/^empty/i', $filelib)) continue; |
|
242 | + if (preg_match('/\.lib/i', $filelib)) continue; |
|
243 | + if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file, $expdevmenu)) continue; |
|
244 | + |
|
245 | + $menuarray[$filelib] = 1; |
|
246 | 246 | } |
247 | - $menuarray['all']=1; |
|
247 | + $menuarray['all'] = 1; |
|
248 | 248 | } |
249 | 249 | closedir($handle); |
250 | 250 | } |
@@ -256,11 +256,11 @@ discard block |
||
256 | 256 | |
257 | 257 | // Affichage liste deroulante des menus |
258 | 258 | print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">'; |
259 | - $oldprefix=''; |
|
259 | + $oldprefix = ''; |
|
260 | 260 | foreach ($menuarray as $key => $val) |
261 | 261 | { |
262 | - $tab=explode('_',$key); |
|
263 | - $newprefix=$tab[0]; |
|
262 | + $tab = explode('_', $key); |
|
263 | + $newprefix = $tab[0]; |
|
264 | 264 | print '<option value="'.$key.'"'; |
265 | 265 | if ($key == $selected) |
266 | 266 | { |
@@ -282,14 +282,14 @@ discard block |
||
282 | 282 | * @param string $htmlname Nom de la zone select |
283 | 283 | * @return void |
284 | 284 | */ |
285 | - function select_timezone($selected,$htmlname) |
|
285 | + function select_timezone($selected, $htmlname) |
|
286 | 286 | { |
287 | - global $langs,$conf; |
|
287 | + global $langs, $conf; |
|
288 | 288 | |
289 | 289 | print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">'; |
290 | 290 | print '<option value="-1"> </option>'; |
291 | 291 | |
292 | - $arraytz=array( |
|
292 | + $arraytz = array( |
|
293 | 293 | "Pacific/Midway"=>"GMT-11:00", |
294 | 294 | "Pacific/Fakaofo"=>"GMT-10:00", |
295 | 295 | "America/Anchorage"=>"GMT-09:00", |
@@ -336,28 +336,28 @@ discard block |
||
336 | 336 | * @param int $showempty Add empty value |
337 | 337 | * @return string Return HTML output |
338 | 338 | */ |
339 | - function select_paper_format($selected='',$htmlname='paperformat_id',$filter=0,$showempty=0) |
|
339 | + function select_paper_format($selected = '', $htmlname = 'paperformat_id', $filter = 0, $showempty = 0) |
|
340 | 340 | { |
341 | 341 | global $langs; |
342 | 342 | |
343 | 343 | $langs->load("dict"); |
344 | 344 | |
345 | 345 | $sql = "SELECT code, label, width, height, unit"; |
346 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_paper_format"; |
|
347 | - $sql.= " WHERE active=1"; |
|
348 | - if ($filter) $sql.=" AND code LIKE '%".$this->db->escape($filter)."%'"; |
|
346 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_paper_format"; |
|
347 | + $sql .= " WHERE active=1"; |
|
348 | + if ($filter) $sql .= " AND code LIKE '%".$this->db->escape($filter)."%'"; |
|
349 | 349 | |
350 | - $resql=$this->db->query($sql); |
|
350 | + $resql = $this->db->query($sql); |
|
351 | 351 | if ($resql) |
352 | 352 | { |
353 | - $num=$this->db->num_rows($resql); |
|
354 | - $i=0; |
|
353 | + $num = $this->db->num_rows($resql); |
|
354 | + $i = 0; |
|
355 | 355 | while ($i < $num) |
356 | 356 | { |
357 | - $obj=$this->db->fetch_object($resql); |
|
357 | + $obj = $this->db->fetch_object($resql); |
|
358 | 358 | $unitKey = $langs->trans('SizeUnit'.$obj->unit); |
359 | 359 | |
360 | - $paperformat[$obj->code]= $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey); |
|
360 | + $paperformat[$obj->code] = $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey); |
|
361 | 361 | |
362 | 362 | $i++; |
363 | 363 | } |
@@ -367,27 +367,27 @@ discard block |
||
367 | 367 | dol_print_error($this->db); |
368 | 368 | return ''; |
369 | 369 | } |
370 | - $out=''; |
|
370 | + $out = ''; |
|
371 | 371 | |
372 | - $out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">'; |
|
372 | + $out .= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">'; |
|
373 | 373 | if ($showempty) |
374 | 374 | { |
375 | - $out.= '<option value=""'; |
|
376 | - if ($selected == '') $out.= ' selected'; |
|
377 | - $out.= '> </option>'; |
|
375 | + $out .= '<option value=""'; |
|
376 | + if ($selected == '') $out .= ' selected'; |
|
377 | + $out .= '> </option>'; |
|
378 | 378 | } |
379 | 379 | foreach ($paperformat as $key => $value) |
380 | 380 | { |
381 | 381 | if ($selected == $key) |
382 | 382 | { |
383 | - $out.= '<option value="'.$key.'" selected>'.$value.'</option>'; |
|
383 | + $out .= '<option value="'.$key.'" selected>'.$value.'</option>'; |
|
384 | 384 | } |
385 | 385 | else |
386 | 386 | { |
387 | - $out.= '<option value="'.$key.'">'.$value.'</option>'; |
|
387 | + $out .= '<option value="'.$key.'">'.$value.'</option>'; |
|
388 | 388 | } |
389 | 389 | } |
390 | - $out.= '</select>'; |
|
390 | + $out .= '</select>'; |
|
391 | 391 | |
392 | 392 | return $out; |
393 | 393 | } |
@@ -70,16 +70,23 @@ discard block |
||
70 | 70 | if ($showempty) |
71 | 71 | { |
72 | 72 | $out.= '<option value="0"'; |
73 | - if ($selected == '') $out.= ' selected'; |
|
73 | + if ($selected == '') { |
|
74 | + $out.= ' selected'; |
|
75 | + } |
|
74 | 76 | $out.= '>'; |
75 | - if ($showempty != '1') $out.=$showempty; |
|
76 | - else $out.=' '; |
|
77 | + if ($showempty != '1') { |
|
78 | + $out.=$showempty; |
|
79 | + } else { |
|
80 | + $out.=' '; |
|
81 | + } |
|
77 | 82 | $out.='</option>'; |
78 | 83 | } |
79 | 84 | if ($showauto) |
80 | 85 | { |
81 | 86 | $out.= '<option value="auto"'; |
82 | - if ($selected == 'auto') $out.= ' selected'; |
|
87 | + if ($selected == 'auto') { |
|
88 | + $out.= ' selected'; |
|
89 | + } |
|
83 | 90 | $out.= '>'.$langs->trans("AutoDetectLang").'</option>'; |
84 | 91 | } |
85 | 92 | |
@@ -88,7 +95,9 @@ discard block |
||
88 | 95 | foreach ($langs_available as $key => $value) |
89 | 96 | { |
90 | 97 | $valuetoshow=$value; |
91 | - if ($showcode) $valuetoshow=$key.' - '.$value; |
|
98 | + if ($showcode) { |
|
99 | + $valuetoshow=$key.' - '.$value; |
|
100 | + } |
|
92 | 101 | |
93 | 102 | if ($filter && is_array($filter)) |
94 | 103 | { |
@@ -96,12 +105,10 @@ discard block |
||
96 | 105 | { |
97 | 106 | $out.= '<option value="'.$key.'">'.$valuetoshow.'</option>'; |
98 | 107 | } |
99 | - } |
|
100 | - else if ($selected == $key) |
|
108 | + } else if ($selected == $key) |
|
101 | 109 | { |
102 | 110 | $out.= '<option value="'.$key.'" selected>'.$valuetoshow.'</option>'; |
103 | - } |
|
104 | - else |
|
111 | + } else |
|
105 | 112 | { |
106 | 113 | $out.= '<option value="'.$key.'">'.$valuetoshow.'</option>'; |
107 | 114 | } |
@@ -132,7 +139,9 @@ discard block |
||
132 | 139 | |
133 | 140 | |
134 | 141 | // Check parameters |
135 | - if (! is_array($dirmenuarray)) return -1; |
|
142 | + if (! is_array($dirmenuarray)) { |
|
143 | + return -1; |
|
144 | + } |
|
136 | 145 | |
137 | 146 | $menuarray=array(); |
138 | 147 | foreach ($conf->file->dol_document_root as $dirroot) |
@@ -150,23 +159,38 @@ discard block |
||
150 | 159 | { |
151 | 160 | if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index') |
152 | 161 | { |
153 | - if (preg_match('/lib\.php$/i',$file)) continue; // We exclude library files |
|
154 | - if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
155 | - if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
156 | - if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files |
|
162 | + if (preg_match('/lib\.php$/i',$file)) { |
|
163 | + continue; |
|
164 | + } |
|
165 | + // We exclude library files |
|
166 | + if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) { |
|
167 | + continue; |
|
168 | + } |
|
169 | + // We exclude all menu manager files |
|
170 | + if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) { |
|
171 | + continue; |
|
172 | + } |
|
173 | + // We exclude all menu manager files |
|
174 | + if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) { |
|
175 | + continue; |
|
176 | + } |
|
177 | + // We exclude all menu manager files |
|
157 | 178 | |
158 | 179 | $filelib=preg_replace('/\.php$/i','',$file); |
159 | 180 | $prefix=''; |
160 | 181 | // 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other |
161 | - if (preg_match('/^eldy/i',$file)) $prefix='0'; |
|
162 | - else if (preg_match('/^smartphone/i',$file)) $prefix='2'; |
|
163 | - else $prefix='3'; |
|
182 | + if (preg_match('/^eldy/i',$file)) { |
|
183 | + $prefix='0'; |
|
184 | + } else if (preg_match('/^smartphone/i',$file)) { |
|
185 | + $prefix='2'; |
|
186 | + } else { |
|
187 | + $prefix='3'; |
|
188 | + } |
|
164 | 189 | |
165 | 190 | if ($file == $selected) |
166 | 191 | { |
167 | 192 | $menuarray[$prefix.'_'.$file]='<option value="'.$file.'" selected>'.$filelib.'</option>'; |
168 | - } |
|
169 | - else |
|
193 | + } else |
|
170 | 194 | { |
171 | 195 | $menuarray[$prefix.'_'.$file]='<option value="'.$file.'">'.$filelib.'</option>'; |
172 | 196 | } |
@@ -186,16 +210,30 @@ discard block |
||
186 | 210 | { |
187 | 211 | $tab=explode('_',$key); |
188 | 212 | $newprefix=$tab[0]; |
189 | - if ($newprefix=='1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) continue; |
|
190 | - if ($newprefix=='2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) continue; |
|
191 | - if ($newprefix != $oldprefix) // Add separators |
|
213 | + if ($newprefix=='1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) { |
|
214 | + continue; |
|
215 | + } |
|
216 | + if ($newprefix=='2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) { |
|
217 | + continue; |
|
218 | + } |
|
219 | + if ($newprefix != $oldprefix) { |
|
220 | + // Add separators |
|
192 | 221 | { |
193 | 222 | // Affiche titre |
194 | 223 | print '<option value="-1" disabled>'; |
195 | - if ($newprefix=='0') print '-- '.$langs->trans("VersionRecommanded").' --'; |
|
196 | - if ($newprefix=='1') print '-- '.$langs->trans("VersionExperimental").' --'; |
|
197 | - if ($newprefix=='2') print '-- '.$langs->trans("VersionDevelopment").' --'; |
|
198 | - if ($newprefix=='3') print '-- '.$langs->trans("Other").' --'; |
|
224 | + } |
|
225 | + if ($newprefix=='0') { |
|
226 | + print '-- '.$langs->trans("VersionRecommanded").' --'; |
|
227 | + } |
|
228 | + if ($newprefix=='1') { |
|
229 | + print '-- '.$langs->trans("VersionExperimental").' --'; |
|
230 | + } |
|
231 | + if ($newprefix=='2') { |
|
232 | + print '-- '.$langs->trans("VersionDevelopment").' --'; |
|
233 | + } |
|
234 | + if ($newprefix=='3') { |
|
235 | + print '-- '.$langs->trans("Other").' --'; |
|
236 | + } |
|
199 | 237 | print '</option>'; |
200 | 238 | $oldprefix=$newprefix; |
201 | 239 | } |
@@ -236,11 +274,21 @@ discard block |
||
236 | 274 | if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') |
237 | 275 | { |
238 | 276 | $filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file); |
239 | - if (preg_match('/^index/i',$filelib)) continue; |
|
240 | - if (preg_match('/^default/i',$filelib)) continue; |
|
241 | - if (preg_match('/^empty/i',$filelib)) continue; |
|
242 | - if (preg_match('/\.lib/i',$filelib)) continue; |
|
243 | - if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) continue; |
|
277 | + if (preg_match('/^index/i',$filelib)) { |
|
278 | + continue; |
|
279 | + } |
|
280 | + if (preg_match('/^default/i',$filelib)) { |
|
281 | + continue; |
|
282 | + } |
|
283 | + if (preg_match('/^empty/i',$filelib)) { |
|
284 | + continue; |
|
285 | + } |
|
286 | + if (preg_match('/\.lib/i',$filelib)) { |
|
287 | + continue; |
|
288 | + } |
|
289 | + if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) { |
|
290 | + continue; |
|
291 | + } |
|
244 | 292 | |
245 | 293 | $menuarray[$filelib]=1; |
246 | 294 | } |
@@ -267,8 +315,11 @@ discard block |
||
267 | 315 | print ' selected'; |
268 | 316 | } |
269 | 317 | print '>'; |
270 | - if ($key == 'all') print $langs->trans("AllMenus"); |
|
271 | - else print $key; |
|
318 | + if ($key == 'all') { |
|
319 | + print $langs->trans("AllMenus"); |
|
320 | + } else { |
|
321 | + print $key; |
|
322 | + } |
|
272 | 323 | print '</option>'."\n"; |
273 | 324 | } |
274 | 325 | print '</select>'; |
@@ -319,7 +370,9 @@ discard block |
||
319 | 370 | foreach ($arraytz as $lib => $gmt) |
320 | 371 | { |
321 | 372 | print '<option value="'.$lib.'"'; |
322 | - if ($selected == $lib || $selected == $gmt) print ' selected'; |
|
373 | + if ($selected == $lib || $selected == $gmt) { |
|
374 | + print ' selected'; |
|
375 | + } |
|
323 | 376 | print '>'.$gmt.'</option>'."\n"; |
324 | 377 | } |
325 | 378 | print '</select>'; |
@@ -345,7 +398,9 @@ discard block |
||
345 | 398 | $sql = "SELECT code, label, width, height, unit"; |
346 | 399 | $sql.= " FROM ".MAIN_DB_PREFIX."c_paper_format"; |
347 | 400 | $sql.= " WHERE active=1"; |
348 | - if ($filter) $sql.=" AND code LIKE '%".$this->db->escape($filter)."%'"; |
|
401 | + if ($filter) { |
|
402 | + $sql.=" AND code LIKE '%".$this->db->escape($filter)."%'"; |
|
403 | + } |
|
349 | 404 | |
350 | 405 | $resql=$this->db->query($sql); |
351 | 406 | if ($resql) |
@@ -361,8 +416,7 @@ discard block |
||
361 | 416 | |
362 | 417 | $i++; |
363 | 418 | } |
364 | - } |
|
365 | - else |
|
419 | + } else |
|
366 | 420 | { |
367 | 421 | dol_print_error($this->db); |
368 | 422 | return ''; |
@@ -373,7 +427,9 @@ discard block |
||
373 | 427 | if ($showempty) |
374 | 428 | { |
375 | 429 | $out.= '<option value=""'; |
376 | - if ($selected == '') $out.= ' selected'; |
|
430 | + if ($selected == '') { |
|
431 | + $out.= ' selected'; |
|
432 | + } |
|
377 | 433 | $out.= '> </option>'; |
378 | 434 | } |
379 | 435 | foreach ($paperformat as $key => $value) |
@@ -381,8 +437,7 @@ discard block |
||
381 | 437 | if ($selected == $key) |
382 | 438 | { |
383 | 439 | $out.= '<option value="'.$key.'" selected>'.$value.'</option>'; |
384 | - } |
|
385 | - else |
|
440 | + } else |
|
386 | 441 | { |
387 | 442 | $out.= '<option value="'.$key.'">'.$value.'</option>'; |
388 | 443 | } |