Completed
Branch develop (c604ce)
by
unknown
32:31
created
htdocs/compta/deplacement/class/deplacementstats.class.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
 	 *
46 46
 	 * @param 	DoliDB		$db		   Database handler
47 47
 	 * @param 	int			$socid	   Id third party
48
-     * @param   mixed		$userid    Id user for filter or array of user ids
48
+     * @param   integer		$userid    Id user for filter or array of user ids
49 49
 	 * @return 	void
50 50
 	 */
51 51
 	function __construct($db, $socid=0, $userid=0)
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,8 +66,11 @@
 block discarded – undo
66 66
 		{
67 67
 			$this->where.=" AND fk_soc = ".$this->socid;
68 68
 		}
69
-		if (is_array($this->userid) && count($this->userid) > 0) $this->where.=' AND fk_user IN ('.join(',',$this->userid).')';
70
-        else if ($this->userid > 0) $this->where.=' AND fk_user = '.$this->userid;
69
+		if (is_array($this->userid) && count($this->userid) > 0) {
70
+			$this->where.=' AND fk_user IN ('.join(',',$this->userid).')';
71
+		} else if ($this->userid > 0) {
72
+        	$this->where.=' AND fk_user = '.$this->userid;
73
+        }
71 74
 	}
72 75
 
73 76
 
Please login to merge, or discard this patch.
htdocs/core/class/html.formintervention.class.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@
 block discarded – undo
50 50
 	 *	@param  string	$htmlname   Nom de la zone html
51 51
 	 *	@param	int		$maxlength	Maximum length of label
52 52
 	 *	@param	int		$showempty	Show empty line
53
-	 *	@return int         		Nbre of project if OK, <0 if KO
53
+	 *	@return string         		Nbre of project if OK, <0 if KO
54 54
 	 */
55 55
 	function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1)
56 56
 	{
Please login to merge, or discard this patch.
Braces   +15 added lines, -12 removed lines patch added patch discarded remove patch
@@ -66,8 +66,11 @@  discard block
 block discarded – undo
66 66
 		$sql.= " WHERE f.entity = ".$conf->entity;
67 67
 		if ($socid != '')
68 68
 		{
69
-			if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
70
-			else $sql.= " AND f.fk_soc = ".$socid;
69
+			if ($socid == '0') {
70
+				$sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
71
+			} else {
72
+				$sql.= " AND f.fk_soc = ".$socid;
73
+			}
71 74
 		}
72 75
 
73 76
 		dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG);
@@ -75,7 +78,9 @@  discard block
 block discarded – undo
75 78
 		if ($resql)
76 79
 		{
77 80
 			$out.='<select id="interventionid" class="flat" name="'.$htmlname.'">';
78
-			if ($showempty) $out.='<option value="0">&nbsp;</option>';
81
+			if ($showempty) {
82
+				$out.='<option value="0">&nbsp;</option>';
83
+			}
79 84
 			$num = $db->num_rows($resql);
80 85
 			$i = 0;
81 86
 			if ($num)
@@ -87,15 +92,13 @@  discard block
 block discarded – undo
87 92
 					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
88 93
 					{
89 94
 						// Do nothing
90
-					}
91
-					else
95
+					} else
92 96
 					{
93 97
 						$labeltoshow=dol_trunc($obj->ref,18);
94 98
 						if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
95 99
 						{
96 100
 							$out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
97
-						}
98
-						else
101
+						} else
99 102
 						{
100 103
 							$disabled=0;
101 104
 							if (! $obj->fk_statut > 0)
@@ -112,11 +115,12 @@  discard block
 block discarded – undo
112 115
 							if ($hideunselectables && $disabled)
113 116
 							{
114 117
 								$resultat='';
115
-							}
116
-							else
118
+							} else
117 119
 							{
118 120
 								$resultat='<option value="'.$obj->rowid.'"';
119
-								if ($disabled) $resultat.=' disabled';
121
+								if ($disabled) {
122
+									$resultat.=' disabled';
123
+								}
120 124
 								$resultat.='>'.$labeltoshow;
121 125
 								$resultat.='</option>';
122 126
 							}
@@ -129,8 +133,7 @@  discard block
 block discarded – undo
129 133
 			$out.='</select>';
130 134
 			$db->free($resql);
131 135
 			return $out;
132
-		}
133
-		else
136
+		} else
134 137
 		{
135 138
 			dol_print_error($db);
136 139
 			return '';
Please login to merge, or discard this patch.
htdocs/core/class/html.formmargin.class.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
 	 *
52 52
 	 * 	@param	CommonObject	$object			Object we want to get margin information for
53 53
 	 * 	@param 	boolean			$force_price	True of not
54
-	 * 	@return array							Array with info
54
+	 * 	@return integer							Array with info
55 55
 	 */
56 56
 	function getMarginInfosArray($object, $force_price=false)
57 57
 	{
Please login to merge, or discard this patch.
Braces   +69 added lines, -48 removed lines patch added patch discarded remove patch
@@ -83,10 +83,12 @@  discard block
 block discarded – undo
83 83
 			{
84 84
 				require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
85 85
 				$product = new ProductFournisseur($db);
86
-				if ($product->fetch_product_fournisseur_price($line->fk_fournprice))
87
-					$line->pa_ht = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
88
-				if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0)
89
-					$line->pa_ht += $product->fourn_unitcharges;
86
+				if ($product->fetch_product_fournisseur_price($line->fk_fournprice)) {
87
+									$line->pa_ht = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
88
+				}
89
+				if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0) {
90
+									$line->pa_ht += $product->fourn_unitcharges;
91
+				}
90 92
 			}
91 93
 			// si prix d'achat non renseigné et devrait l'être, alors prix achat = prix vente
92 94
 			if ((!isset($line->pa_ht) || $line->pa_ht == 0) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) {
@@ -111,8 +113,7 @@  discard block
 block discarded – undo
111 113
 					//}
112 114
 					//else
113 115
 						$marginInfos['margin_on_products'] += $pv - $pa;
114
-				}
115
-				elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service
116
+				} elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service
116 117
 					$marginInfos['pa_services'] += $pa;
117 118
 					$marginInfos['pv_services'] += $pv;
118 119
 					$marginInfos['pa_total'] +=  $pa;
@@ -122,13 +123,11 @@  discard block
 block discarded – undo
122 123
 					//	$marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa);
123 124
 					//else
124 125
 						$marginInfos['margin_on_services'] += $pv - $pa;
125
-				}
126
-				elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total
126
+				} elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total
127 127
 					$marginInfos['pa_total'] += $pa;
128 128
 					$marginInfos['pv_total'] += $pv;
129 129
 				}
130
-			}
131
-			else {
130
+			} else {
132 131
 				$type=$line->product_type?$line->product_type:$line->fk_product_type;
133 132
 				if ($type == 0) {  // product
134 133
 					$marginInfos['pa_products'] += $pa;
@@ -144,8 +143,7 @@  discard block
 block discarded – undo
144 143
 					//{
145 144
 					    $marginInfos['margin_on_products'] += $pv - $pa;
146 145
 					//}
147
-				}
148
-				elseif ($type == 1) {  // service
146
+				} elseif ($type == 1) {  // service
149 147
 					$marginInfos['pa_services'] += $pa;
150 148
 					$marginInfos['pv_services'] += $pv;
151 149
 					$marginInfos['pa_total'] +=  $pa;
@@ -158,25 +156,31 @@  discard block
 block discarded – undo
158 156
 				}
159 157
 			}
160 158
 		}
161
-		if ($marginInfos['pa_products'] > 0)
162
-			$marginInfos['margin_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pa_products'];
163
-		if ($marginInfos['pv_products'] > 0)
164
-			$marginInfos['mark_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pv_products'];
159
+		if ($marginInfos['pa_products'] > 0) {
160
+					$marginInfos['margin_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pa_products'];
161
+		}
162
+		if ($marginInfos['pv_products'] > 0) {
163
+					$marginInfos['mark_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pv_products'];
164
+		}
165 165
 
166
-		if ($marginInfos['pa_services'] > 0)
167
-			$marginInfos['margin_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pa_services'];
168
-		if ($marginInfos['pv_services'] > 0)
169
-			$marginInfos['mark_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pv_services'];
166
+		if ($marginInfos['pa_services'] > 0) {
167
+					$marginInfos['margin_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pa_services'];
168
+		}
169
+		if ($marginInfos['pv_services'] > 0) {
170
+					$marginInfos['mark_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pv_services'];
171
+		}
170 172
 
171 173
 		// if credit note, margin = -1 * (abs(selling_price) - buying_price)
172 174
 		//if ($marginInfos['pv_total'] < 0)
173 175
 		//	$marginInfos['total_margin'] = -1 * (abs($marginInfos['pv_total']) - $marginInfos['pa_total']);
174 176
 		//else
175 177
 			$marginInfos['total_margin'] = $marginInfos['pv_total'] - $marginInfos['pa_total'];
176
-		if ($marginInfos['pa_total'] > 0)
177
-			$marginInfos['total_margin_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pa_total'];
178
-		if ($marginInfos['pv_total'] > 0)
179
-			$marginInfos['total_mark_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pv_total'];
178
+		if ($marginInfos['pa_total'] > 0) {
179
+					$marginInfos['total_margin_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pa_total'];
180
+		}
181
+		if ($marginInfos['pv_total'] > 0) {
182
+					$marginInfos['total_mark_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pv_total'];
183
+		}
180 184
 
181 185
 		return $marginInfos;
182 186
 	}
@@ -192,17 +196,23 @@  discard block
 block discarded – undo
192 196
 	{
193 197
 		global $langs, $conf, $user;
194 198
 
195
-    	if (! empty($user->societe_id)) return;
199
+    	if (! empty($user->societe_id)) {
200
+    		return;
201
+    	}
196 202
 
197
-    	if (! $user->rights->margins->liretous) return;
203
+    	if (! $user->rights->margins->liretous) {
204
+    		return;
205
+    	}
198 206
 
199 207
         $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
200 208
 
201 209
 		$marginInfo = $this->getMarginInfosArray($object, $force_price);
202 210
 
203
-		if (! empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON))	// TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better
211
+		if (! empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) {
212
+			// TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better
204 213
 		{
205 214
 			print $langs->trans('ShowMarginInfos').' : ';
215
+		}
206 216
 	        $hidemargininfos = $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW'];
207 217
 	    	print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'':'hideobject').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>';
208 218
 	    	print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'hideobject':'').'">'.img_picto($langs->trans("Enabled"),'switch_on').'</span>';
@@ -211,7 +221,9 @@  discard block
 block discarded – undo
211 221
         	    $("span#showMarginInfos").click(function() { $.getScript( "'.dol_buildpath('/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 0); $(".margininfos").show(); $("span#showMarginInfos").addClass("hideobject"); $("span#hideMarginInfos").removeClass("hideobject");})});
212 222
         	    $("span#hideMarginInfos").click(function() { $.getScript( "'.dol_buildpath('/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 1); $(".margininfos").hide(); $("span#hideMarginInfos").addClass("hideobject"); $("span#showMarginInfos").removeClass("hideobject");})});
213 223
       	        });</script>';
214
-    	    if (!empty($hidemargininfos)) print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>';
224
+    	    if (!empty($hidemargininfos)) {
225
+    	    	print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>';
226
+    	    }
215 227
 		}
216 228
 
217 229
 		print '<!-- Margin table -->'."\n";
@@ -219,15 +231,18 @@  discard block
 block discarded – undo
219 231
 		print '<tr class="liste_titre">';
220 232
 		print '<td class="liste_titre">'.$langs->trans('Margins').'</td>';
221 233
 		print '<td class="liste_titre" align="right">'.$langs->trans('SellingPrice').'</td>';
222
-		if ($conf->global->MARGIN_TYPE == "1")
223
-			print '<td class="liste_titre" align="right">'.$langs->trans('BuyingPrice').'</td>';
224
-		else
225
-			print '<td class="liste_titre" align="right">'.$langs->trans('CostPrice').'</td>';
234
+		if ($conf->global->MARGIN_TYPE == "1") {
235
+					print '<td class="liste_titre" align="right">'.$langs->trans('BuyingPrice').'</td>';
236
+		} else {
237
+					print '<td class="liste_titre" align="right">'.$langs->trans('CostPrice').'</td>';
238
+		}
226 239
 		print '<td class="liste_titre" align="right">'.$langs->trans('Margin').'</td>';
227
-		if (! empty($conf->global->DISPLAY_MARGIN_RATES))
228
-			print '<td class="liste_titre" align="right">'.$langs->trans('MarginRate').'</td>';
229
-		if (! empty($conf->global->DISPLAY_MARK_RATES))
230
-			print '<td class="liste_titre" align="right">'.$langs->trans('MarkRate').'</td>';
240
+		if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
241
+					print '<td class="liste_titre" align="right">'.$langs->trans('MarginRate').'</td>';
242
+		}
243
+		if (! empty($conf->global->DISPLAY_MARK_RATES)) {
244
+					print '<td class="liste_titre" align="right">'.$langs->trans('MarkRate').'</td>';
245
+		}
231 246
 		print '</tr>';
232 247
 
233 248
 		if (! empty($conf->product->enabled))
@@ -238,10 +253,12 @@  discard block
 block discarded – undo
238 253
 			print '<td align="right">'.price($marginInfo['pv_products'], null, null, null, null, $rounding).'</td>';
239 254
 			print '<td align="right">'.price($marginInfo['pa_products'], null, null, null, null, $rounding).'</td>';
240 255
 			print '<td align="right">'.price($marginInfo['margin_on_products'], null, null, null, null, $rounding).'</td>';
241
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
242
-				print '<td align="right">'.(($marginInfo['margin_rate_products'] == '')?'':price($marginInfo['margin_rate_products'], null, null, null, null, $rounding).'%').'</td>';
243
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
244
-				print '<td align="right">'.(($marginInfo['mark_rate_products'] == '')?'':price($marginInfo['mark_rate_products'], null, null, null, null, $rounding).'%').'</td>';
256
+			if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
257
+							print '<td align="right">'.(($marginInfo['margin_rate_products'] == '')?'':price($marginInfo['margin_rate_products'], null, null, null, null, $rounding).'%').'</td>';
258
+			}
259
+			if (! empty($conf->global->DISPLAY_MARK_RATES)) {
260
+							print '<td align="right">'.(($marginInfo['mark_rate_products'] == '')?'':price($marginInfo['mark_rate_products'], null, null, null, null, $rounding).'%').'</td>';
261
+			}
245 262
 			print '</tr>';
246 263
 		}
247 264
 
@@ -252,10 +269,12 @@  discard block
 block discarded – undo
252 269
 			print '<td align="right">'.price($marginInfo['pv_services'], null, null, null, null, $rounding).'</td>';
253 270
 			print '<td align="right">'.price($marginInfo['pa_services'], null, null, null, null, $rounding).'</td>';
254 271
 			print '<td align="right">'.price($marginInfo['margin_on_services'], null, null, null, null, $rounding).'</td>';
255
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
256
-				print '<td align="right">'.(($marginInfo['margin_rate_services'] == '')?'':price($marginInfo['margin_rate_services'], null, null, null, null, $rounding).'%').'</td>';
257
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
258
-				print '<td align="right">'.(($marginInfo['mark_rate_services'] == '')?'':price($marginInfo['mark_rate_services'], null, null, null, null, $rounding).'%').'</td>';
272
+			if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
273
+							print '<td align="right">'.(($marginInfo['margin_rate_services'] == '')?'':price($marginInfo['margin_rate_services'], null, null, null, null, $rounding).'%').'</td>';
274
+			}
275
+			if (! empty($conf->global->DISPLAY_MARK_RATES)) {
276
+							print '<td align="right">'.(($marginInfo['mark_rate_services'] == '')?'':price($marginInfo['mark_rate_services'], null, null, null, null, $rounding).'%').'</td>';
277
+			}
259 278
 			print '</tr>';
260 279
 		}
261 280
 
@@ -266,10 +285,12 @@  discard block
 block discarded – undo
266 285
 			print '<td align="right">'.price($marginInfo['pv_total'], null, null, null, null, $rounding).'</td>';
267 286
 			print '<td align="right">'.price($marginInfo['pa_total'], null, null, null, null, $rounding).'</td>';
268 287
 			print '<td align="right">'.price($marginInfo['total_margin'], null, null, null, null, $rounding).'</td>';
269
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
270
-				print '<td align="right">'.(($marginInfo['total_margin_rate'] == '')?'':price($marginInfo['total_margin_rate'], null, null, null, null, $rounding).'%').'</td>';
271
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
272
-				print '<td align="right">'.(($marginInfo['total_mark_rate'] == '')?'':price($marginInfo['total_mark_rate'], null, null, null, null, $rounding).'%').'</td>';
288
+			if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
289
+							print '<td align="right">'.(($marginInfo['total_margin_rate'] == '')?'':price($marginInfo['total_margin_rate'], null, null, null, null, $rounding).'%').'</td>';
290
+			}
291
+			if (! empty($conf->global->DISPLAY_MARK_RATES)) {
292
+							print '<td align="right">'.(($marginInfo['total_mark_rate'] == '')?'':price($marginInfo['total_mark_rate'], null, null, null, null, $rounding).'%').'</td>';
293
+			}
273 294
 			print '</tr>';
274 295
 		}
275 296
 		print '</table>';
Please login to merge, or discard this patch.
htdocs/core/class/rssparser.class.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -151,7 +151,7 @@
 block discarded – undo
151 151
     /**
152 152
      * getLastFetchDate
153 153
      *
154
-     * @return string
154
+     * @return integer
155 155
      */
156 156
     public function getLastFetchDate()
157 157
     {
Please login to merge, or discard this patch.
Braces   +148 added lines, -107 removed lines patch added patch discarded remove patch
@@ -211,19 +211,19 @@  discard block
 block discarded – undo
211 211
                 $foundintocache=1;
212 212
 
213 213
                 $this->_lastfetchdate=$filedate;
214
-            }
215
-            else
214
+            } else
216 215
             {
217 216
                 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
218 217
             }
219 218
         }
220 219
 
221 220
         // Load file into $str
222
-        if ($foundintocache)    // Cache file found and is not too old
221
+        if ($foundintocache) {
222
+        	// Cache file found and is not too old
223 223
         {
224 224
             $str = file_get_contents($newpathofdestfile);
225 225
         }
226
-        else
226
+        } else
227 227
         {
228 228
             try {
229 229
                 ini_set("user_agent","Dolibarr ERP-CRM RSS reader");
@@ -231,14 +231,17 @@  discard block
 block discarded – undo
231 231
                 ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
232 232
 
233 233
                 $opts = array('http'=>array('method'=>"GET"));
234
-                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
235
-                if (! empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
234
+                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) {
235
+                	$opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
236
+                }
237
+                if (! empty($conf->global->MAIN_PROXY_USE)) {
238
+                	$opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
239
+                }
236 240
                 //var_dump($opts);exit;
237 241
                 $context = stream_context_create($opts);
238 242
 
239 243
                 $str = file_get_contents($this->_urlRSS, false, $context);
240
-            }
241
-            catch (Exception $e) {
244
+            } catch (Exception $e) {
242 245
                 print 'Error retrieving URL '.$this->urlRSS.' - '.$e->getMessage();
243 246
             }
244 247
         }
@@ -251,8 +254,7 @@  discard block
 block discarded – undo
251 254
 	            //print 'xx'.LIBXML_NOCDATA;
252 255
 	            libxml_use_internal_errors(false);
253 256
 	            $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
254
-	        }
255
-	        else
257
+	        } else
256 258
 	        {
257 259
 	            $xmlparser=xml_parser_create('');
258 260
 	            if (!is_resource($xmlparser)) {
@@ -276,18 +278,21 @@  discard block
 block discarded – undo
276 278
             if (empty($foundintocache) && $cachedir)
277 279
             {
278 280
                 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
279
-                if (! dol_is_dir($cachedir)) dol_mkdir($cachedir);
281
+                if (! dol_is_dir($cachedir)) {
282
+                	dol_mkdir($cachedir);
283
+                }
280 284
                 $fp = fopen($newpathofdestfile, 'w');
281 285
                 if ($fp)
282 286
                 {
283 287
                 	fwrite($fp, $str);
284 288
                 	fclose($fp);
285
-                	if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
289
+                	if (! empty($conf->global->MAIN_UMASK)) {
290
+                		$newmask=$conf->global->MAIN_UMASK;
291
+                	}
286 292
                 	@chmod($newpathofdestfile, octdec($newmask));
287 293
 
288 294
 	                $this->_lastfetchdate=$nowgmt;
289
-                }
290
-                else
295
+                } else
291 296
                 {
292 297
                 	print 'Error, failed to open file '.$newpathofdestfile.' for write';
293 298
                 }
@@ -295,10 +300,14 @@  discard block
 block discarded – undo
295 300
 
296 301
             unset($str);    // Free memory
297 302
 
298
-            if (empty($rss->_format))    // If format not detected automatically
303
+            if (empty($rss->_format)) {
304
+            	// If format not detected automatically
299 305
             {
300 306
                 $rss->_format='rss';
301
-                if (empty($rss->channel)) $rss->_format='atom';
307
+            }
308
+                if (empty($rss->channel)) {
309
+                	$rss->_format='atom';
310
+                }
302 311
             }
303 312
 
304 313
             $items=array();
@@ -309,58 +318,114 @@  discard block
 block discarded – undo
309 318
                 //var_dump($rss);
310 319
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
311 320
                 {
312
-                    if (!empty($rss->channel->language))      $this->_language = (string) $rss->channel->language;
313
-                    if (!empty($rss->channel->generator))     $this->_generator = (string) $rss->channel->generator;
314
-                    if (!empty($rss->channel->copyright))     $this->_copyright = (string) $rss->channel->copyright;
315
-                    if (!empty($rss->channel->lastbuilddate)) $this->_lastbuilddate = (string) $rss->channel->lastbuilddate;
316
-                    if (!empty($rss->channel->image->url[0])) $this->_imageurl = (string) $rss->channel->image->url[0];
317
-                    if (!empty($rss->channel->link))		  $this->_link = (string) $rss->channel->link;
318
-                    if (!empty($rss->channel->title))         $this->_title = (string) $rss->channel->title;
319
-                    if (!empty($rss->channel->description))	  $this->_description = (string) $rss->channel->description;
320
-                }
321
-                else
321
+                    if (!empty($rss->channel->language)) {
322
+                    	$this->_language = (string) $rss->channel->language;
323
+                    }
324
+                    if (!empty($rss->channel->generator)) {
325
+                    	$this->_generator = (string) $rss->channel->generator;
326
+                    }
327
+                    if (!empty($rss->channel->copyright)) {
328
+                    	$this->_copyright = (string) $rss->channel->copyright;
329
+                    }
330
+                    if (!empty($rss->channel->lastbuilddate)) {
331
+                    	$this->_lastbuilddate = (string) $rss->channel->lastbuilddate;
332
+                    }
333
+                    if (!empty($rss->channel->image->url[0])) {
334
+                    	$this->_imageurl = (string) $rss->channel->image->url[0];
335
+                    }
336
+                    if (!empty($rss->channel->link)) {
337
+                    	$this->_link = (string) $rss->channel->link;
338
+                    }
339
+                    if (!empty($rss->channel->title)) {
340
+                    	$this->_title = (string) $rss->channel->title;
341
+                    }
342
+                    if (!empty($rss->channel->description)) {
343
+                    	$this->_description = (string) $rss->channel->description;
344
+                    }
345
+                } else
322 346
                 {
323 347
                     //var_dump($rss->channel);
324
-                    if (!empty($rss->channel['language']))      $this->_language = (string) $rss->channel['language'];
325
-                    if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
326
-                    if (!empty($rss->channel['copyright']))     $this->_copyright = (string) $rss->channel['copyright'];
327
-                    if (!empty($rss->channel['lastbuilddate'])) $this->_lastbuilddate = (string) $rss->channel['lastbuilddate'];
328
-                    if (!empty($rss->image['url']))             $this->_imageurl = (string) $rss->image['url'];
329
-                    if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
330
-                    if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
331
-                    if (!empty($rss->channel['description']))   $this->_description = (string) $rss->channel['description'];
348
+                    if (!empty($rss->channel['language'])) {
349
+                    	$this->_language = (string) $rss->channel['language'];
350
+                    }
351
+                    if (!empty($rss->channel['generator'])) {
352
+                    	$this->_generator = (string) $rss->channel['generator'];
353
+                    }
354
+                    if (!empty($rss->channel['copyright'])) {
355
+                    	$this->_copyright = (string) $rss->channel['copyright'];
356
+                    }
357
+                    if (!empty($rss->channel['lastbuilddate'])) {
358
+                    	$this->_lastbuilddate = (string) $rss->channel['lastbuilddate'];
359
+                    }
360
+                    if (!empty($rss->image['url'])) {
361
+                    	$this->_imageurl = (string) $rss->image['url'];
362
+                    }
363
+                    if (!empty($rss->channel['link'])) {
364
+                    	$this->_link = (string) $rss->channel['link'];
365
+                    }
366
+                    if (!empty($rss->channel['title'])) {
367
+                    	$this->_title = (string) $rss->channel['title'];
368
+                    }
369
+                    if (!empty($rss->channel['description'])) {
370
+                    	$this->_description = (string) $rss->channel['description'];
371
+                    }
332 372
                 }
333 373
 
334
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item;    // With simplexml
335
-                else $items=$rss->items;                                                              // With xmlparse
374
+                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) {
375
+                	$items=$rss->channel->item;
376
+                }
377
+                // With simplexml
378
+                else {
379
+                	$items=$rss->items;
380
+                }
381
+                // With xmlparse
336 382
                 //var_dump($items);exit;
337
-            }
338
-            else if ($rss->_format == 'atom')
383
+            } else if ($rss->_format == 'atom')
339 384
             {
340 385
                 //var_dump($rss);
341 386
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
342 387
                 {
343
-                    if (!empty($rss->generator))     $this->_generator = (string) $rss->generator;
344
-                    if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified;
345
-                    if (!empty($rss->link->href))    $this->_link = (string) $rss->link->href;
346
-                    if (!empty($rss->title))         $this->_title = (string) $rss->title;
347
-                    if (!empty($rss->description))	 $this->_description = (string) $rss->description;
348
-                }
349
-                else
388
+                    if (!empty($rss->generator)) {
389
+                    	$this->_generator = (string) $rss->generator;
390
+                    }
391
+                    if (!empty($rss->lastbuilddate)) {
392
+                    	$this->_lastbuilddate = (string) $rss->modified;
393
+                    }
394
+                    if (!empty($rss->link->href)) {
395
+                    	$this->_link = (string) $rss->link->href;
396
+                    }
397
+                    if (!empty($rss->title)) {
398
+                    	$this->_title = (string) $rss->title;
399
+                    }
400
+                    if (!empty($rss->description)) {
401
+                    	$this->_description = (string) $rss->description;
402
+                    }
403
+                } else
350 404
                 {
351 405
                     //if (!empty($rss->channel['rss_language']))      $this->_language = (string) $rss->channel['rss_language'];
352
-                    if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
406
+                    if (!empty($rss->channel['generator'])) {
407
+                    	$this->_generator = (string) $rss->channel['generator'];
408
+                    }
353 409
                     //if (!empty($rss->channel['rss_copyright']))     $this->_copyright = (string) $rss->channel['rss_copyright'];
354
-                    if (!empty($rss->channel['modified'])) $this->_lastbuilddate = (string) $rss->channel['modified'];
410
+                    if (!empty($rss->channel['modified'])) {
411
+                    	$this->_lastbuilddate = (string) $rss->channel['modified'];
412
+                    }
355 413
                     //if (!empty($rss->image['rss_url']))             $this->_imageurl = (string) $rss->image['rss_url'];
356
-                    if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
357
-                    if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
414
+                    if (!empty($rss->channel['link'])) {
415
+                    	$this->_link = (string) $rss->channel['link'];
416
+                    }
417
+                    if (!empty($rss->channel['title'])) {
418
+                    	$this->_title = (string) $rss->channel['title'];
419
+                    }
358 420
                     //if (!empty($rss->channel['rss_description']))   $this->_description = (string) $rss->channel['rss_description'];
359 421
                 }
360 422
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))  {
361 423
                     $tmprss=xml2php($rss); $items=$tmprss['entry'];
362 424
                 } // With simplexml
363
-                else $items=$rss->items;                                                              // With xmlparse
425
+                else {
426
+                	$items=$rss->items;
427
+                }
428
+                // With xmlparse
364 429
                 //var_dump($items);exit;
365 430
             }
366 431
 
@@ -382,8 +447,7 @@  discard block
 block discarded – undo
382 447
                             $itemPubDate = (string) $item->pubDate;
383 448
                             $itemId = '';
384 449
                             $itemAuthor = '';
385
-                        }
386
-                        else
450
+                        } else
387 451
                         {
388 452
                             $itemLink = (string) $item['link'];
389 453
                             $itemTitle = (string) $item['title'];
@@ -402,8 +466,7 @@  discard block
 block discarded – undo
402 466
                                 $itemCategory[] = (string) $cat;
403 467
                             }
404 468
                         }
405
-                    }
406
-                    else if ($rss->_format == 'atom')
469
+                    } else if ($rss->_format == 'atom')
407 470
                     {
408 471
                         if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
409 472
                         {
@@ -413,8 +476,7 @@  discard block
 block discarded – undo
413 476
                             $itemPubDate = (string) $item['created'];
414 477
                             $itemId = (string) $item['id'];
415 478
                             $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
416
-                        }
417
-                        else
479
+                        } else
418 480
                         {
419 481
                             $itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
420 482
                             $itemTitle = (string) $item['title'];
@@ -423,8 +485,9 @@  discard block
 block discarded – undo
423 485
                             $itemId = (string) $item['id'];
424 486
                             $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
425 487
                         }
488
+                    } else {
489
+                    	print 'ErrorBadFeedFormat';
426 490
                     }
427
-                    else print 'ErrorBadFeedFormat';
428 491
 
429 492
                     // Add record to result array
430 493
                     $this->_rssarray[$i] = array(
@@ -439,13 +502,15 @@  discard block
 block discarded – undo
439 502
 
440 503
                     $i++;
441 504
 
442
-                    if ($i > $maxNb)    break;    // We get all records we want
505
+                    if ($i > $maxNb) {
506
+                    	break;
507
+                    }
508
+                    // We get all records we want
443 509
                 }
444 510
             }
445 511
 
446 512
             return 1;
447
-        }
448
-        else
513
+        } else
449 514
         {
450 515
             $this->error='ErrorFailedToLoadRSSFile';
451 516
             return -1;
@@ -484,12 +549,10 @@  discard block
 block discarded – undo
484 549
             if ( $el == 'rdf' ) {
485 550
                 $this->_format = 'rss';
486 551
                 $this->feed_version = '1.0';
487
-            }
488
-            elseif ( $el == 'rss' ) {
552
+            } elseif ( $el == 'rss' ) {
489 553
                 $this->_format = 'rss';
490 554
                 $this->feed_version = $attrs['version'];
491
-            }
492
-            elseif ( $el == 'feed' ) {
555
+            } elseif ( $el == 'feed' ) {
493 556
                 $this->_format = 'atom';
494 557
                 $this->feed_version = $attrs['version'];
495 558
                 $this->inchannel = true;
@@ -500,8 +563,7 @@  discard block
 block discarded – undo
500 563
         if ( $el == 'channel' )
501 564
         {
502 565
             $this->inchannel = true;
503
-        }
504
-        elseif ($el == 'item' or $el == 'entry' )
566
+        } elseif ($el == 'item' or $el == 'entry' )
505 567
         {
506 568
             $this->initem = true;
507 569
             if ( isset($attrs['rdf:about']) ) {
@@ -517,9 +579,7 @@  discard block
 block discarded – undo
517 579
         $el == 'textinput' )
518 580
         {
519 581
             $this->intextinput = true;
520
-        }
521
-
522
-        elseif (
582
+        } elseif (
523 583
         $this->_format == 'rss' and
524 584
         $this->current_namespace == '' and
525 585
         $el == 'image' )
@@ -560,8 +620,7 @@  discard block
 block discarded – undo
560 620
             if ( isset($attrs['rel']) && $attrs['rel'] == 'alternate' )
561 621
             {
562 622
                 $link_el = 'link';
563
-            }
564
-            else {
623
+            } else {
565 624
                 $link_el = 'link_' . $attrs['rel'];
566 625
             }
567 626
 
@@ -586,8 +645,7 @@  discard block
 block discarded – undo
586 645
         if ($this->_format == 'atom' and $this->incontent)
587 646
         {
588 647
             $this->append_content($text);
589
-        }
590
-        else
648
+        } else
591 649
         {
592 650
             $current_el = join('_', array_reverse($this->stack));
593 651
             $this->append($current_el, $text);
@@ -610,37 +668,30 @@  discard block
 block discarded – undo
610 668
             $this->items[] = $this->current_item;
611 669
             $this->current_item = array();
612 670
             $this->initem = false;
613
-        }
614
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
671
+        } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
615 672
         {
616 673
             $this->intextinput = false;
617
-        }
618
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
674
+        } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
619 675
         {
620 676
             $this->inimage = false;
621
-        }
622
-        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
677
+        } elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
623 678
         {
624 679
             $this->incontent = false;
625
-        }
626
-        elseif ($el == 'channel' or $el == 'feed' )
680
+        } elseif ($el == 'channel' or $el == 'feed' )
627 681
         {
628 682
             $this->inchannel = false;
629
-        }
630
-        elseif ($this->_format == 'atom' and $this->incontent  ) {
683
+        } elseif ($this->_format == 'atom' and $this->incontent  ) {
631 684
             // balance tags properly
632 685
             // note:  i don't think this is actually neccessary
633 686
             if ( $this->stack[0] == $el )
634 687
             {
635 688
                 $this->append_content("</$el>");
636
-            }
637
-            else {
689
+            } else {
638 690
                 $this->append_content("<$el />");
639 691
             }
640 692
 
641 693
             array_shift($this->stack);
642
-        }
643
-        else {
694
+        } else {
644 695
             array_shift($this->stack);
645 696
         }
646 697
 
@@ -673,8 +724,7 @@  discard block
 block discarded – undo
673 724
     {
674 725
         if ( $this->initem ) {
675 726
             $this->concat($this->current_item[ $this->incontent ], $text);
676
-        }
677
-        elseif ( $this->inchannel ) {
727
+        } elseif ( $this->inchannel ) {
678 728
             $this->concat($this->channel[ $this->incontent ], $text);
679 729
         }
680 730
     }
@@ -695,28 +745,21 @@  discard block
 block discarded – undo
695 745
         {
696 746
             if ( $this->initem ) {
697 747
                 $this->concat($this->current_item[ $this->current_namespace ][ $el ], $text);
698
-            }
699
-            elseif ($this->inchannel) {
748
+            } elseif ($this->inchannel) {
700 749
                 $this->concat($this->channel[ $this->current_namespace][ $el ], $text);
701
-            }
702
-            elseif ($this->intextinput) {
750
+            } elseif ($this->intextinput) {
703 751
                 $this->concat($this->textinput[ $this->current_namespace][ $el ], $text);
704
-            }
705
-            elseif ($this->inimage) {
752
+            } elseif ($this->inimage) {
706 753
                 $this->concat($this->image[ $this->current_namespace ][ $el ], $text);
707 754
             }
708
-        }
709
-        else {
755
+        } else {
710 756
             if ( $this->initem ) {
711 757
                 $this->concat($this->current_item[ $el ], $text);
712
-            }
713
-            elseif ($this->intextinput) {
758
+            } elseif ($this->intextinput) {
714 759
                 $this->concat($this->textinput[ $el ], $text);
715
-            }
716
-            elseif ($this->inimage) {
760
+            } elseif ($this->inimage) {
717 761
                 $this->concat($this->image[ $el ], $text);
718
-            }
719
-            elseif ($this->inchannel) {
762
+            } elseif ($this->inchannel) {
720 763
                 $this->concat($this->channel[ $el ], $text);
721 764
             }
722 765
 
@@ -757,13 +800,11 @@  discard block
 block discarded – undo
757 800
             $array[$key][] = $tmp;
758 801
             $array[$key][] = $child;
759 802
             $tab = true;
760
-        }
761
-        elseif($tab == true)
803
+        } elseif($tab == true)
762 804
         {
763 805
             //Add an element in an existing array
764 806
             $array[$key][] = $child;
765
-        }
766
-        else
807
+        } else
767 808
         {
768 809
             //Add a simple element
769 810
             $array[$key] = $child;
Please login to merge, or discard this patch.
htdocs/core/db/mssql.class.php 2 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
      *  @param  int		$usesavepoint	0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions).
320 320
      *                   		 		Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints.
321 321
      *  @param  string	$type           Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
322
-     *  @return false|resource|true		Resultset of answer
322
+     *  @return resource		Resultset of answer
323 323
 	 */
324 324
 	function query($query,$usesavepoint=0,$type='auto')
325 325
 	{
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
 	 *	Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE
517 517
 	 *
518 518
 	 *	@param	resource	$resultset   Curseur de la requete voulue
519
-	 *	@return int		    Nombre de lignes
519
+	 *	@return string		    Nombre de lignes
520 520
 	 *	@see    num_rows
521 521
 	 */
522 522
 	function affected_rows($resultset)
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
 	 *	Free last resultset used.
536 536
 	 *
537 537
 	 *	@param  resource	$resultset   Curseur de la requete voulue
538
-	 *	@return	bool
538
+	 *	@return	boolean|null
539 539
 	 */
540 540
 	function free($resultset=null)
541 541
 	{
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
 	/**
1016 1016
 	 *	Return list of available charset that can be used to store data in database
1017 1017
 	 *
1018
-	 *	@return		array		List of Charset
1018
+	 *	@return		string		List of Charset
1019 1019
 	 */
1020 1020
 	function getListOfCharacterSet()
1021 1021
 	{
Please login to merge, or discard this patch.
Braces   +107 added lines, -93 removed lines patch added patch discarded remove patch
@@ -90,8 +90,7 @@  discard block
 block discarded – undo
90 90
 			// (La base Dolibarr a ete forcee en this->forcecharset a l'install)
91 91
 			$this->connected = true;
92 92
 			$this->ok = true;
93
-		}
94
-		else
93
+		} else
95 94
 		{
96 95
 			// host, login ou password incorrect
97 96
 			$this->connected = false;
@@ -108,8 +107,7 @@  discard block
 block discarded – undo
108 107
 				$this->database_selected = true;
109 108
 				$this->database_name = $name;
110 109
 				$this->ok = true;
111
-			}
112
-			else
110
+			} else
113 111
 			{
114 112
 				$this->database_selected = false;
115 113
 				$this->database_name = '';
@@ -117,8 +115,7 @@  discard block
 block discarded – undo
117 115
 				$this->error=$this->error();
118 116
 				dol_syslog(get_class($this)."::DoliDBMssql : Erreur Select_db ".$this->error,LOG_ERR);
119 117
 			}
120
-		}
121
-		else
118
+		} else
122 119
 		{
123 120
 			// Pas de selection de base demandee, ok ou ko
124 121
 			$this->database_selected = false;
@@ -165,7 +162,9 @@  discard block
 block discarded – undo
165 162
 	{
166 163
 		dol_syslog(get_class($this)."::connect host=$host, port=$port, login=$login, passwd=--hidden--, name=$name");
167 164
 		$newhost=$host;
168
-		if ($port) $newhost.=':'.$port;
165
+		if ($port) {
166
+			$newhost.=':'.$port;
167
+		}
169 168
 		$this->db  = @mssql_connect($newhost, $login, $passwd);
170 169
 		//force les enregistrement en latin1 si la base est en utf8 par defaut
171 170
 		// Supprime car plante sur mon PHP-Mysql. De plus, la base est forcement en latin1 avec
@@ -196,8 +195,9 @@  discard block
 block discarded – undo
196 195
 		{
197 196
             $version=$this->fetch_array($resql);
198 197
             return $version['computed'];
198
+		} else {
199
+			return '';
199 200
 		}
200
-		else return '';
201 201
 	}
202 202
 
203 203
 	/**
@@ -220,7 +220,9 @@  discard block
 block discarded – undo
220 220
     {
221 221
         if ($this->db)
222 222
         {
223
-          if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
223
+          if ($this->transaction_opened > 0) {
224
+          	dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
225
+          }
224 226
           $this->connected=false;
225 227
           return mssql_close($this->db);
226 228
         }
@@ -248,8 +250,7 @@  discard block
 block discarded – undo
248 250
 				dol_syslog("BEGIN Transaction",LOG_DEBUG);
249 251
 			}
250 252
 			return $ret;
251
-		}
252
-		else
253
+		} else
253 254
 		{
254 255
 			return true;
255 256
 		}
@@ -274,13 +275,11 @@  discard block
 block discarded – undo
274 275
 			{
275 276
 				dol_syslog("COMMIT Transaction",LOG_DEBUG);
276 277
 				return true;
277
-			}
278
-			else
278
+			} else
279 279
 			{
280 280
 				return false;
281 281
 			}
282
-		}
283
-		elseif ($this->transaction_opened > 1)
282
+		} elseif ($this->transaction_opened > 1)
284 283
 		{
285 284
 			return true;
286 285
 		}
@@ -304,8 +303,7 @@  discard block
 block discarded – undo
304 303
 			$ret=mssql_query("ROLLBACK TRANSACTION",$this->db);
305 304
 			dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG);
306 305
 			return $ret;
307
-		}
308
-		elseif ($this->transaction_opened > 1)
306
+		} elseif ($this->transaction_opened > 1)
309 307
 		{
310 308
 			return true;
311 309
 		}
@@ -326,7 +324,9 @@  discard block
 block discarded – undo
326 324
 	{
327 325
 		$query = trim($query);
328 326
 
329
-		if (preg_match('/^--/',$query)) return true;
327
+		if (preg_match('/^--/',$query)) {
328
+			return true;
329
+		}
330 330
 
331 331
 		// Conversion syntaxe MySql vers MSDE.
332 332
 		$query = str_ireplace("now()", "getdate()", $query);
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
                             $query_comp[]=$fld->COLUMN_NAME." IS NOT NULL";
361 361
                         }
362 362
                     }
363
-                    if (! empty($query_comp))
364
-                        $query.=" WHERE ".implode(" AND ",$query_comp);
363
+                    if (! empty($query_comp)) {
364
+                                            $query.=" WHERE ".implode(" AND ",$query_comp);
365
+                    }
365 366
                 }
366
-    		}
367
-    		else
367
+    		} else
368 368
     		{
369 369
     		    if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+PRIMARY\h+KEY\h+(\w+?)\h*\((.+)\)/is', $query, $matches))
370 370
     		    {
@@ -419,14 +419,15 @@  discard block
 block discarded – undo
419 419
 		}
420 420
 		//print "<!--".$query."-->";
421 421
 
422
-		if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG);
422
+		if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) {
423
+			dol_syslog('sql='.$query, LOG_DEBUG);
424
+		}
423 425
 
424 426
 		if (! $this->database_name)
425 427
 		{
426 428
 			// Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE)
427 429
 			$ret = mssql_query($query, $this->db);
428
-		}
429
-		else
430
+		} else
430 431
 		{
431 432
 			$ret = mssql_query($query, $this->db);
432 433
 		}
@@ -449,7 +450,9 @@  discard block
 block discarded – undo
449 450
 				$this->lasterrno = $row["code"];
450 451
 
451 452
 				dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR);
452
-				if ($original_query) dol_syslog(get_class($this)."::query SQL Original query: ".$original_query, LOG_ERR);
453
+				if ($original_query) {
454
+					dol_syslog(get_class($this)."::query SQL Original query: ".$original_query, LOG_ERR);
455
+				}
453 456
 				dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterror." (".$this->lasterrno.")", LOG_ERR);
454 457
 			}
455 458
 			$this->lastquery=$query;
@@ -543,7 +546,9 @@  discard block
 block discarded – undo
543 546
 		// Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion
544 547
 		if (! is_resource($resultset)) { $resultset=$this->_results; }
545 548
 		// Si resultset en est un, on libere la memoire
546
-		if (is_resource($resultset)) mssql_free_result($resultset);
549
+		if (is_resource($resultset)) {
550
+			mssql_free_result($resultset);
551
+		}
547 552
 	}
548 553
 
549 554
 	/**
@@ -581,8 +586,7 @@  discard block
 block discarded – undo
581 586
 		{
582 587
 			// Si il y a eu echec de connexion, $this->db n'est pas valide.
583 588
 			return 'DB_ERROR_FAILED_TO_CONNECT';
584
-		}
585
-		else
589
+		} else
586 590
 		{
587 591
 			// Constants to convert a MSSql error code to a generic Dolibarr error code
588 592
 			$errorcode_map = array(
@@ -633,8 +637,7 @@  discard block
 block discarded – undo
633 637
 		if (! $this->connected) {
634 638
 			// Si il y a eu echec de connexion, $this->db n'est pas valide pour mssql_get_last_message.
635 639
 			return 'Not connected. Check setup parameters in conf/conf.php file and your mssql client and server versions';
636
-		}
637
-		else {
640
+		} else {
638 641
 			return mssql_get_last_message();
639 642
 		}
640 643
 	}
@@ -652,8 +655,7 @@  discard block
 block discarded – undo
652 655
 		if ($res && $data = $this->fetch_array($res))
653 656
 		{
654 657
 			return $data["id"];
655
-		}
656
-		else
658
+		} else
657 659
 		{
658 660
 			return -1;
659 661
 		}
@@ -714,8 +716,9 @@  discard block
 block discarded – undo
714 716
 		{
715 717
             $row=$this->fetch_row($resql);
716 718
             return $row[0];
719
+		} else {
720
+			return '?';
717 721
 		}
718
-		else return '?';
719 722
 	}
720 723
 
721 724
 	/**
@@ -808,26 +811,27 @@  discard block
 block discarded – undo
808 811
 		{
809 812
 			$sqlfields[$i] = $field_name." ";
810 813
 			$sqlfields[$i]  .= $field_desc['type'];
811
-			if( preg_match("/^[^\s]/i",$field_desc['value']))
812
-			$sqlfields[$i]  .= "(".$field_desc['value'].")";
813
-			else if( preg_match("/^[^\s]/i",$field_desc['attribute']))
814
-			$sqlfields[$i]  .= " ".$field_desc['attribute'];
815
-			else if( preg_match("/^[^\s]/i",$field_desc['default']))
814
+			if( preg_match("/^[^\s]/i",$field_desc['value'])) {
815
+						$sqlfields[$i]  .= "(".$field_desc['value'].")";
816
+			} else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) {
817
+						$sqlfields[$i]  .= " ".$field_desc['attribute'];
818
+			} else if( preg_match("/^[^\s]/i",$field_desc['default']))
816 819
 			{
817
-				if(preg_match("/null/i",$field_desc['default']))
818
-				$sqlfields[$i]  .= " default ".$field_desc['default'];
819
-				else
820
-				$sqlfields[$i]  .= " default '".$field_desc['default']."'";
820
+				if(preg_match("/null/i",$field_desc['default'])) {
821
+								$sqlfields[$i]  .= " default ".$field_desc['default'];
822
+				} else {
823
+								$sqlfields[$i]  .= " default '".$field_desc['default']."'";
824
+				}
825
+			} else if( preg_match("/^[^\s]/i",$field_desc['null'])) {
826
+						$sqlfields[$i]  .= " ".$field_desc['null'];
827
+			} else if( preg_match("/^[^\s]/i",$field_desc['extra'])) {
828
+						$sqlfields[$i]  .= " ".$field_desc['extra'];
821 829
 			}
822
-			else if( preg_match("/^[^\s]/i",$field_desc['null']))
823
-			$sqlfields[$i]  .= " ".$field_desc['null'];
824
-
825
-			else if( preg_match("/^[^\s]/i",$field_desc['extra']))
826
-			$sqlfields[$i]  .= " ".$field_desc['extra'];
827 830
 			$i++;
828 831
 		}
829
-		if($primary_key != "")
830
-		$pk = "primary key(".$primary_key.")";
832
+		if($primary_key != "") {
833
+				$pk = "primary key(".$primary_key.")";
834
+		}
831 835
 
832 836
 		if(is_array($unique_keys))
833 837
 		{
@@ -848,19 +852,23 @@  discard block
 block discarded – undo
848 852
 			}
849 853
 		}
850 854
 		$sql .= implode(',',$sqlfields);
851
-		if($primary_key != "")
852
-		$sql .= ",".$pk;
853
-		if(is_array($unique_keys))
854
-		$sql .= ",".implode(',',$sqluq);
855
-		if(is_array($keys))
856
-		$sql .= ",".implode(',',$sqlk);
855
+		if($primary_key != "") {
856
+				$sql .= ",".$pk;
857
+		}
858
+		if(is_array($unique_keys)) {
859
+				$sql .= ",".implode(',',$sqluq);
860
+		}
861
+		if(is_array($keys)) {
862
+				$sql .= ",".implode(',',$sqlk);
863
+		}
857 864
 		$sql .=") type=".$type;
858 865
 
859 866
 		dol_syslog($sql);
860
-		if(! $this -> query($sql))
861
-		return -1;
862
-		else
863
-		return 1;
867
+		if(! $this -> query($sql)) {
868
+				return -1;
869
+		} else {
870
+				return 1;
871
+		}
864 872
 	}
865 873
 
866 874
 	/**
@@ -873,10 +881,11 @@  discard block
 block discarded – undo
873 881
 	{
874 882
 		$sql = "DROP TABLE ".$table;
875 883
 
876
-		if (! $this->query($sql))
877
-			return -1;
878
-		else
879
-			return 1;
884
+		if (! $this->query($sql)) {
885
+					return -1;
886
+		} else {
887
+					return 1;
888
+		}
880 889
 	}
881 890
 
882 891
 	/**
@@ -910,25 +919,31 @@  discard block
 block discarded – undo
910 919
 		// ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
911 920
 		$sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
912 921
 		$sql .= $field_desc['type'];
913
-		if( preg_match("/^[^\s]/i",$field_desc['value']))
914
-		$sql  .= "(".$field_desc['value'].")";
915
-		if( preg_match("/^[^\s]/i",$field_desc['attribute']))
916
-		$sql  .= " ".$field_desc['attribute'];
917
-		if( preg_match("/^[^\s]/i",$field_desc['null']))
918
-		$sql  .= " ".$field_desc['null'];
919
-		if( preg_match("/^[^\s]/i",$field_desc['default']))
920
-		if(preg_match("/null/i",$field_desc['default']))
922
+		if( preg_match("/^[^\s]/i",$field_desc['value'])) {
923
+				$sql  .= "(".$field_desc['value'].")";
924
+		}
925
+		if( preg_match("/^[^\s]/i",$field_desc['attribute'])) {
926
+				$sql  .= " ".$field_desc['attribute'];
927
+		}
928
+		if( preg_match("/^[^\s]/i",$field_desc['null'])) {
929
+				$sql  .= " ".$field_desc['null'];
930
+		}
931
+		if( preg_match("/^[^\s]/i",$field_desc['default'])) {
932
+				if(preg_match("/null/i",$field_desc['default']))
921 933
 		$sql  .= " default ".$field_desc['default'];
922
-		else
923
-		$sql  .= " default '".$field_desc['default']."'";
924
-		if( preg_match("/^[^\s]/i",$field_desc['extra']))
925
-		$sql  .= " ".$field_desc['extra'];
934
+		} else {
935
+				$sql  .= " default '".$field_desc['default']."'";
936
+		}
937
+		if( preg_match("/^[^\s]/i",$field_desc['extra'])) {
938
+				$sql  .= " ".$field_desc['extra'];
939
+		}
926 940
 		$sql .= " ".$field_position;
927 941
 
928
-		if(! $this -> query($sql))
929
-		return -1;
930
-		else
931
-		return 1;
942
+		if(! $this -> query($sql)) {
943
+				return -1;
944
+		} else {
945
+				return 1;
946
+		}
932 947
 	}
933 948
 
934 949
 	/**
@@ -948,10 +963,11 @@  discard block
 block discarded – undo
948 963
 		}
949 964
 
950 965
 		dol_syslog($sql,LOG_DEBUG);
951
-		if (! $this->query($sql))
952
-		return -1;
953
-		else
954
-		return 1;
966
+		if (! $this->query($sql)) {
967
+				return -1;
968
+		} else {
969
+				return 1;
970
+		}
955 971
 	}
956 972
 
957 973
 	/**
@@ -969,8 +985,9 @@  discard block
 block discarded – undo
969 985
 		{
970 986
 			$this->error=$this->lasterror();
971 987
 			return -1;
988
+		} else {
989
+			return 1;
972 990
 		}
973
-		else return 1;
974 991
 	}
975 992
 
976 993
 	/**
@@ -992,8 +1009,7 @@  discard block
 block discarded – undo
992 1009
             if ($this->lasterrno != '15025')
993 1010
             {
994 1011
 	            return -1;
995
-            }
996
-            else
1012
+            } else
997 1013
 			{
998 1014
             	// If user already exists, we continue to set permissions
999 1015
             	dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
@@ -1005,8 +1021,7 @@  discard block
 block discarded – undo
1005 1021
         {
1006 1022
             dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
1007 1023
             return -1;
1008
-        }
1009
-        else
1024
+        } else
1010 1025
         {
1011 1026
             if ($num)
1012 1027
             {
@@ -1155,8 +1170,7 @@  discard block
 block discarded – undo
1155 1170
 	    if (is_array($fields))
1156 1171
 	    {
1157 1172
 	        $where=" IN ('".implode("','",$fields)."')";
1158
-	    }
1159
-	    else
1173
+	    } else
1160 1174
 	    {
1161 1175
 	        $where="='".$this->escape($fields)."'";
1162 1176
 	    }
@@ -1168,9 +1182,9 @@  discard block
 block discarded – undo
1168 1182
 	        {
1169 1183
 	            $result[]=$obj;
1170 1184
 	        }
1185
+	    } else {
1186
+	    	        return false;
1171 1187
 	    }
1172
-	    else
1173
-	        return false;
1174 1188
 
1175 1189
 	    return $result;
1176 1190
 	}
Please login to merge, or discard this patch.
htdocs/core/db/mysqli.class.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -233,7 +233,7 @@
 block discarded – undo
233 233
      * 	@param	int		$usesavepoint	0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions).
234 234
      * 									Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints.
235 235
      *  @param  string	$type           Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
236
-     *	@return	bool|mysqli_result		Resultset of answer
236
+     *	@return	mysqli_result|null		Resultset of answer
237 237
      */
238 238
     function query($query,$usesavepoint=0,$type='auto')
239 239
     {
Please login to merge, or discard this patch.
Braces   +120 added lines, -74 removed lines patch added patch discarded remove patch
@@ -59,8 +59,12 @@  discard block
 block discarded – undo
59 59
         global $conf,$langs;
60 60
 
61 61
         // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static
62
-        if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set;
63
-        if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation;
62
+        if (! empty($conf->db->character_set)) {
63
+        	$this->forcecharset=$conf->db->character_set;
64
+        }
65
+        if (! empty($conf->db->dolibarr_main_db_collation)) {
66
+        	$this->forcecollate=$conf->db->dolibarr_main_db_collation;
67
+        }
64 68
 
65 69
         $this->database_user=$user;
66 70
         $this->database_host=$host;
@@ -111,18 +115,23 @@  discard block
 block discarded – undo
111 115
 
112 116
                 // If client is old latin, we force utf8
113 117
                 $clientmustbe=empty($conf->db->dolibarr_main_db_character_set)?'utf8':$conf->db->dolibarr_main_db_character_set;
114
-                if (preg_match('/latin1/', $clientmustbe)) $clientmustbe='utf8';
118
+                if (preg_match('/latin1/', $clientmustbe)) {
119
+                	$clientmustbe='utf8';
120
+                }
115 121
 
116 122
 				if ($this->db->character_set_name() != $clientmustbe) {
117 123
 					$this->db->set_charset($clientmustbe);	// This set charset, but with a bad collation
118 124
 
119 125
 					$collation = $conf->db->dolibarr_main_db_collation;
120
-					if (preg_match('/latin1/', $collation)) $collation='utf8_unicode_ci';
126
+					if (preg_match('/latin1/', $collation)) {
127
+						$collation='utf8_unicode_ci';
128
+					}
121 129
 
122
-					if (! preg_match('/general/', $collation)) $this->db->query("SET collation_connection = ".$collation);
130
+					if (! preg_match('/general/', $collation)) {
131
+						$this->db->query("SET collation_connection = ".$collation);
132
+					}
123 133
 				}
124
-            }
125
-            else
134
+            } else
126 135
             {
127 136
                 $this->database_selected = false;
128 137
                 $this->database_name = '';
@@ -130,8 +139,7 @@  discard block
 block discarded – undo
130 139
                 $this->error=$this->error();
131 140
                 dol_syslog(get_class($this)."::DoliDBMysqli : Select_db error ".$this->error,LOG_ERR);
132 141
             }
133
-        }
134
-        else
142
+        } else
135 143
         {
136 144
             // Pas de selection de base demandee, ok ou ko
137 145
             $this->database_selected = false;
@@ -140,15 +148,21 @@  discard block
 block discarded – undo
140 148
             {
141 149
             	// If client is old latin, we force utf8
142 150
             	$clientmustbe=empty($conf->db->dolibarr_main_db_character_set)?'utf8':$conf->db->dolibarr_main_db_character_set;
143
-            	if (preg_match('/latin1/', $clientmustbe)) $clientmustbe='utf8';
151
+            	if (preg_match('/latin1/', $clientmustbe)) {
152
+            		$clientmustbe='utf8';
153
+            	}
144 154
 
145 155
 				if ($this->db->character_set_name() != $clientmustbe) {
146 156
 					$this->db->set_charset($clientmustbe);	// This set utf8_general_ci
147 157
 
148 158
 					$collation = $conf->db->dolibarr_main_db_collation;
149
-					if (preg_match('/latin1/', $collation)) $collation='utf8_unicode_ci';
159
+					if (preg_match('/latin1/', $collation)) {
160
+						$collation='utf8_unicode_ci';
161
+					}
150 162
 
151
-					if (! preg_match('/general/', $collation)) $this->db->query("SET collation_connection = ".$collation);
163
+					if (! preg_match('/general/', $collation)) {
164
+						$this->db->query("SET collation_connection = ".$collation);
165
+					}
152 166
 				}
153 167
 			}
154 168
         }
@@ -232,7 +246,9 @@  discard block
 block discarded – undo
232 246
     {
233 247
         if ($this->db)
234 248
         {
235
-	        if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
249
+	        if ($this->transaction_opened > 0) {
250
+	        	dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
251
+	        }
236 252
             $this->connected=false;
237 253
             return $this->db->close();
238 254
         }
@@ -254,14 +270,15 @@  discard block
 block discarded – undo
254 270
 
255 271
         $query = trim($query);
256 272
 
257
-	    if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG);
273
+	    if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) {
274
+	    	dol_syslog('sql='.$query, LOG_DEBUG);
275
+	    }
258 276
 
259 277
         if (! $this->database_name)
260 278
         {
261 279
             // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE)
262 280
             $ret = $this->db->query($query);
263
-        }
264
-        else
281
+        } else
265 282
         {
266 283
             $ret = $this->db->query($query);
267 284
         }
@@ -275,7 +292,10 @@  discard block
 block discarded – undo
275 292
                 $this->lasterror = $this->error();
276 293
                 $this->lasterrno = $this->errno();
277 294
 
278
-				if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR);	// Log of request was not yet done previously
295
+				if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) {
296
+					dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR);
297
+				}
298
+				// Log of request was not yet done previously
279 299
                 dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterrno." ".$this->lasterror, LOG_ERR);
280 300
             }
281 301
             $this->lastquery=$query;
@@ -325,8 +345,7 @@  discard block
 block discarded – undo
325 345
         {
326 346
             if (! is_object($resultset)) { $resultset=$this->_results; }
327 347
             return $resultset->fetch_row();
328
-        }
329
-        else
348
+        } else
330 349
         {
331 350
             // si le curseur est un booleen on retourne la valeur 0
332 351
             return 0;
@@ -375,7 +394,9 @@  discard block
 block discarded – undo
375 394
         // If resultset not provided, we take the last used by connexion
376 395
         if (! is_object($resultset)) { $resultset=$this->_results; }
377 396
         // Si resultset en est un, on libere la memoire
378
-        if (is_object($resultset)) $resultset->free_result();
397
+        if (is_object($resultset)) {
398
+        	$resultset->free_result();
399
+        }
379 400
     }
380 401
 
381 402
     /**
@@ -450,8 +471,7 @@  discard block
 block discarded – undo
450 471
         if (! $this->connected) {
451 472
             // Si il y a eu echec de connexion, $this->db n'est pas valide pour mysqli_error.
452 473
             return 'Not connected. Check setup parameters in conf/conf.php file and your mysql client and server versions';
453
-        }
454
-        else {
474
+        } else {
455 475
             return $this->db->error;
456 476
         }
457 477
     }
@@ -494,8 +514,7 @@  discard block
 block discarded – undo
494 514
             if ($cryptType == 2)
495 515
             {
496 516
                 $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')';
497
-            }
498
-            else if ($cryptType == 1)
517
+            } else if ($cryptType == 1)
499 518
             {
500 519
                 $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')';
501 520
             }
@@ -527,8 +546,7 @@  discard block
 block discarded – undo
527 546
             if ($cryptType == 2)
528 547
             {
529 548
                 $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')';
530
-            }
531
-            else if ($cryptType == 1)
549
+            } else if ($cryptType == 1)
532 550
             {
533 551
                 $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')';
534 552
             }
@@ -550,8 +568,9 @@  discard block
 block discarded – undo
550 568
         {
551 569
             $row=$this->fetch_row($resql);
552 570
             return $row[0];
571
+        } else {
572
+        	return '?';
553 573
         }
554
-        else return '?';
555 574
     }
556 575
 
557 576
     /**
@@ -567,8 +586,12 @@  discard block
 block discarded – undo
567 586
      */
568 587
     function DDLCreateDb($database,$charset='',$collation='',$owner='')
569 588
     {
570
-        if (empty($charset))   $charset=$this->forcecharset;
571
-        if (empty($collation)) $collation=$this->forcecollate;
589
+        if (empty($charset)) {
590
+        	$charset=$this->forcecharset;
591
+        }
592
+        if (empty($collation)) {
593
+        	$collation=$this->forcecollate;
594
+        }
572 595
 
573 596
         // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci
574 597
 		$sql = "CREATE DATABASE `".$this->escape($database)."`";
@@ -598,7 +621,9 @@  discard block
 block discarded – undo
598 621
         $listtables=array();
599 622
 
600 623
         $like = '';
601
-        if ($table) $like = "LIKE '".$table."'";
624
+        if ($table) {
625
+        	$like = "LIKE '".$table."'";
626
+        }
602 627
         $sql="SHOW TABLES FROM ".$database." ".$like.";";
603 628
         //print $sql;
604 629
         $result = $this->query($sql);
@@ -670,8 +695,7 @@  discard block
 block discarded – undo
670 695
 			{
671 696
 				if ((preg_match("/null/i",$field_desc['default'])) || (preg_match("/CURRENT_TIMESTAMP/i",$field_desc['default']))) {
672 697
 					$sqlfields[$i]  .= " default ".$field_desc['default'];
673
-				}
674
-				else {
698
+				} else {
675 699
 					$sqlfields[$i]  .= " default '".$field_desc['default']."'";
676 700
 				}
677 701
 			}
@@ -683,8 +707,9 @@  discard block
 block discarded – undo
683 707
 			}
684 708
             $i++;
685 709
         }
686
-        if($primary_key != "")
687
-        $pk = "primary key(".$primary_key.")";
710
+        if($primary_key != "") {
711
+                $pk = "primary key(".$primary_key.")";
712
+        }
688 713
 
689 714
         if(is_array($unique_keys)) {
690 715
             $i = 0;
@@ -704,18 +729,22 @@  discard block
 block discarded – undo
704 729
             }
705 730
         }
706 731
         $sql .= implode(',',$sqlfields);
707
-        if($primary_key != "")
708
-        $sql .= ",".$pk;
709
-        if($unique_keys != "")
710
-        $sql .= ",".implode(',',$sqluq);
711
-        if(is_array($keys))
712
-        $sql .= ",".implode(',',$sqlk);
732
+        if($primary_key != "") {
733
+                $sql .= ",".$pk;
734
+        }
735
+        if($unique_keys != "") {
736
+                $sql .= ",".implode(',',$sqluq);
737
+        }
738
+        if(is_array($keys)) {
739
+                $sql .= ",".implode(',',$sqlk);
740
+        }
713 741
         $sql .=") engine=".$type;
714 742
 
715
-        if(! $this->query($sql))
716
-        return -1;
717
-        else
718
-        return 1;
743
+        if(! $this->query($sql)) {
744
+                return -1;
745
+        } else {
746
+                return 1;
747
+        }
719 748
     }
720 749
 
721 750
     /**
@@ -728,10 +757,11 @@  discard block
 block discarded – undo
728 757
     {
729 758
     	$sql = "DROP TABLE ".$table;
730 759
 
731
-		if (! $this->query($sql))
732
- 			return -1;
733
-    	else
734
-    		return 1;
760
+		if (! $this->query($sql)) {
761
+		 			return -1;
762
+		} else {
763
+    	    		return 1;
764
+    	}
735 765
     }
736 766
 
737 767
     /**
@@ -765,24 +795,29 @@  discard block
 block discarded – undo
765 795
         // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
766 796
         $sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
767 797
         $sql.= $field_desc['type'];
768
-        if(preg_match("/^[^\s]/i",$field_desc['value']))
769
-            if (! in_array($field_desc['type'],array('date','datetime')))
798
+        if(preg_match("/^[^\s]/i",$field_desc['value'])) {
799
+                    if (! in_array($field_desc['type'],array('date','datetime')))
770 800
             {
771 801
                 $sql.= "(".$field_desc['value'].")";
802
+        }
772 803
             }
773
-        if(preg_match("/^[^\s]/i",$field_desc['attribute']))
774
-        $sql.= " ".$field_desc['attribute'];
775
-        if(preg_match("/^[^\s]/i",$field_desc['null']))
776
-        $sql.= " ".$field_desc['null'];
804
+        if(preg_match("/^[^\s]/i",$field_desc['attribute'])) {
805
+                $sql.= " ".$field_desc['attribute'];
806
+        }
807
+        if(preg_match("/^[^\s]/i",$field_desc['null'])) {
808
+                $sql.= " ".$field_desc['null'];
809
+        }
777 810
         if(preg_match("/^[^\s]/i",$field_desc['default']))
778 811
         {
779
-            if(preg_match("/null/i",$field_desc['default']))
780
-            $sql.= " default ".$field_desc['default'];
781
-            else
782
-            $sql.= " default '".$field_desc['default']."'";
812
+            if(preg_match("/null/i",$field_desc['default'])) {
813
+                        $sql.= " default ".$field_desc['default'];
814
+            } else {
815
+                        $sql.= " default '".$field_desc['default']."'";
816
+            }
817
+        }
818
+        if(preg_match("/^[^\s]/i",$field_desc['extra'])) {
819
+                $sql.= " ".$field_desc['extra'];
783 820
         }
784
-        if(preg_match("/^[^\s]/i",$field_desc['extra']))
785
-        $sql.= " ".$field_desc['extra'];
786 821
         $sql.= " ".$field_position;
787 822
 
788 823
         dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG);
@@ -814,8 +849,7 @@  discard block
 block discarded – undo
814 849
         	{
815 850
         		$sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL";
816 851
         		$this->query($sqlbis);
817
-        	}
818
-        	elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int')
852
+        	} elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int')
819 853
         	{
820 854
         		$sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL";
821 855
         		$this->query($sqlbis);
@@ -826,15 +860,20 @@  discard block
 block discarded – undo
826 860
 
827 861
         if ($field_desc['default'] != '')
828 862
         {
829
-			if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
830
-        	elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'";							// Default not supported on text fields
863
+			if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') {
864
+				$sql.=" DEFAULT ".$this->escape($field_desc['default']);
865
+			} elseif ($field_desc['type'] == 'text') {
866
+        		$sql.=" DEFAULT '".$this->escape($field_desc['default'])."'";
867
+        	}
868
+        	// Default not supported on text fields
831 869
         }
832 870
 
833 871
         dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG);
834
-        if (! $this->query($sql))
835
-        return -1;
836
-        else
837
-        return 1;
872
+        if (! $this->query($sql)) {
873
+                return -1;
874
+        } else {
875
+                return 1;
876
+        }
838 877
     }
839 878
 
840 879
     /**
@@ -875,8 +914,7 @@  discard block
 block discarded – undo
875 914
             if ($this->lasterrno != 'DB_ERROR_USER_ALREADY_EXISTS')
876 915
             {
877 916
             	return -1;
878
-            }
879
-            else
917
+            } else
880 918
 			{
881 919
             	// If user already exists, we continue to set permissions
882 920
             	dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING);
@@ -1042,11 +1080,15 @@  discard block
 block discarded – undo
1042 1080
         $result=array();
1043 1081
 
1044 1082
         $sql='SHOW VARIABLES';
1045
-        if ($filter) $sql.=" LIKE '".$this->escape($filter)."'";
1083
+        if ($filter) {
1084
+        	$sql.=" LIKE '".$this->escape($filter)."'";
1085
+        }
1046 1086
         $resql=$this->query($sql);
1047 1087
         if ($resql)
1048 1088
         {
1049
-        	while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value;
1089
+        	while($obj=$this->fetch_object($resql)) {
1090
+        		$result[$obj->Variable_name]=$obj->Value;
1091
+        	}
1050 1092
         }
1051 1093
 
1052 1094
         return $result;
@@ -1063,11 +1105,15 @@  discard block
 block discarded – undo
1063 1105
         $result=array();
1064 1106
 
1065 1107
         $sql='SHOW STATUS';
1066
-        if ($filter) $sql.=" LIKE '".$this->escape($filter)."'";
1108
+        if ($filter) {
1109
+        	$sql.=" LIKE '".$this->escape($filter)."'";
1110
+        }
1067 1111
         $resql=$this->query($sql);
1068 1112
         if ($resql)
1069 1113
         {
1070
-            while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value;
1114
+            while($obj=$this->fetch_object($resql)) {
1115
+            	$result[$obj->Variable_name]=$obj->Value;
1116
+            }
1071 1117
         }
1072 1118
 
1073 1119
         return $result;
Please login to merge, or discard this patch.
htdocs/core/db/pgsql.class.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 	 * @param	string	$query			SQL query string
465 465
 	 * @param	int		$usesavepoint	0=Default mode, 1=Run a savepoint before and a rollback to savepoint if error (this allow to have some request with errors inside global transactions).
466 466
      * @param   string	$type           Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
467
-	 * @return	false|resource			Resultset of answer
467
+	 * @return	resource|null			Resultset of answer
468 468
 	 */
469 469
 	function query($query,$usesavepoint=0,$type='auto')
470 470
 	{
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
 	 *	Decrypt sensitive data in database
791 791
 	 *
792 792
 	 *	@param	int		$value			Value to decrypt
793
-	 * 	@return	string					Decrypted value if used
793
+	 * 	@return	integer					Decrypted value if used
794 794
 	 */
795 795
 	function decrypt($value)
796 796
 	{
Please login to merge, or discard this patch.
Braces   +160 added lines, -93 removed lines patch added patch discarded remove patch
@@ -67,8 +67,12 @@  discard block
 block discarded – undo
67 67
 		global $conf,$langs;
68 68
 
69 69
         // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static
70
-		if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set;
71
-		if (! empty($conf->db->dolibarr_main_db_collation))	$this->forcecollate=$conf->db->dolibarr_main_db_collation;
70
+		if (! empty($conf->db->character_set)) {
71
+			$this->forcecharset=$conf->db->character_set;
72
+		}
73
+		if (! empty($conf->db->dolibarr_main_db_collation)) {
74
+			$this->forcecollate=$conf->db->dolibarr_main_db_collation;
75
+		}
72 76
 
73 77
 		$this->database_user=$user;
74 78
         $this->database_host=$host;
@@ -104,8 +108,7 @@  discard block
 block discarded – undo
104 108
 		{
105 109
 			$this->connected = true;
106 110
 			$this->ok = true;
107
-		}
108
-		else
111
+		} else
109 112
 		{
110 113
 			// host, login ou password incorrect
111 114
 			$this->connected = false;
@@ -122,8 +125,7 @@  discard block
 block discarded – undo
122 125
 				$this->database_selected = true;
123 126
 				$this->database_name = $name;
124 127
 				$this->ok = true;
125
-			}
126
-			else
128
+			} else
127 129
 			{
128 130
 				$this->database_selected = false;
129 131
 				$this->database_name = '';
@@ -131,8 +133,7 @@  discard block
 block discarded – undo
131 133
 				$this->error=$this->error();
132 134
 				dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Select_db ".$this->error,LOG_ERR);
133 135
 			}
134
-		}
135
-		else
136
+		} else
136 137
 		{
137 138
 			// Pas de selection de base demandee, ok ou ko
138 139
 			$this->database_selected = false;
@@ -172,9 +173,13 @@  discard block
 block discarded – undo
172 173
 
173 174
 		    if ($type == 'auto')
174 175
 		    {
175
-              if (preg_match('/ALTER TABLE/i',$line)) $type='dml';
176
-              else if (preg_match('/CREATE TABLE/i',$line)) $type='dml';
177
-              else if (preg_match('/DROP TABLE/i',$line)) $type='dml';
176
+              if (preg_match('/ALTER TABLE/i',$line)) {
177
+              	$type='dml';
178
+              } else if (preg_match('/CREATE TABLE/i',$line)) {
179
+              	$type='dml';
180
+              } else if (preg_match('/DROP TABLE/i',$line)) {
181
+              	$type='dml';
182
+              }
178 183
 		    }
179 184
 
180 185
     		$line=preg_replace('/ as signed\)/i',' as integer)',$line);
@@ -321,10 +326,12 @@  discard block
 block discarded – undo
321 326
 			// DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable
322 327
 			if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',$line,$reg))
323 328
 			{
324
-				if ($reg[1] == $reg[2])	// If same table, we remove second one
329
+				if ($reg[1] == $reg[2]) {
330
+					// If same table, we remove second one
325 331
 				{
326 332
 					$line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line);
327 333
 				}
334
+				}
328 335
 			}
329 336
 
330 337
 			// Remove () in the tables in FROM if 1 table
@@ -351,7 +358,9 @@  discard block
 block discarded – undo
351 358
 			// By default we do not (should be already done by db->escape function if required
352 359
 			// except for sql insert in data file that are mysql escaped so we removed them to
353 360
 			// be compatible with standard_conforming_strings=on that considers \ as ordinary character).
354
-			if ($unescapeslashquot) $line=preg_replace("/\\\'/","''",$line);
361
+			if ($unescapeslashquot) {
362
+				$line=preg_replace("/\\\'/","''",$line);
363
+			}
355 364
 
356 365
 			//print "type=".$type." newline=".$line."<br>\n";
357 366
 		}
@@ -369,8 +378,11 @@  discard block
 block discarded – undo
369 378
 	 */
370 379
 	function select_db($database)
371 380
 	{
372
-		if ($database == $this->database_name) return true;
373
-		else return false;
381
+		if ($database == $this->database_name) {
382
+			return true;
383
+		} else {
384
+			return false;
385
+		}
374 386
 	}
375 387
 
376 388
 	/**
@@ -397,7 +409,10 @@  discard block
 block discarded – undo
397 409
 		$name = str_replace(array("\\", "'"), array("\\\\", "\\'"), $name);
398 410
 		$port = str_replace(array("\\", "'"), array("\\\\", "\\'"), $port);
399 411
 
400
-		if (! $name) $name="postgres";    // When try to connect using admin user
412
+		if (! $name) {
413
+			$name="postgres";
414
+		}
415
+		// When try to connect using admin user
401 416
 
402 417
 		// try first Unix domain socket (local)
403 418
 		if ((! empty($host) && $host == "socket") && ! defined('NOLOCALSOCKETPGCONNECT'))
@@ -409,8 +424,12 @@  discard block
 block discarded – undo
409 424
 		// if local connection failed or not requested, use TCP/IP
410 425
 		if (! $this->db)
411 426
 		{
412
-		    if (! $host) $host = "localhost";
413
-			if (! $port) $port = 5432;
427
+		    if (! $host) {
428
+		    	$host = "localhost";
429
+		    }
430
+			if (! $port) {
431
+				$port = 5432;
432
+			}
414 433
 
415 434
 			$con_string = "host='".$host."' port='".$port."' dbname='".$name."' user='".$login."' password='".$passwd."'";
416 435
 			$this->db = @pg_connect($con_string);
@@ -463,7 +482,9 @@  discard block
 block discarded – undo
463 482
     {
464 483
         if ($this->db)
465 484
         {
466
-          if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
485
+          if ($this->transaction_opened > 0) {
486
+          	dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
487
+          }
467 488
           $this->connected=false;
468 489
           return pg_close($this->db);
469 490
         }
@@ -498,8 +519,9 @@  discard block
 block discarded – undo
498 519
 				{
499 520
 					$query=preg_replace('/([^\'])([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9])/','\\1\'\\2\'',$query);
500 521
 					dol_syslog("Warning: Bad formed request converted into ".$query,LOG_WARNING);
522
+				} else {
523
+					$loop=false;
501 524
 				}
502
-				else $loop=false;
503 525
 			}
504 526
 		}
505 527
 
@@ -508,30 +530,39 @@  discard block
 block discarded – undo
508 530
 			@pg_query($this->db, 'SAVEPOINT mysavepoint');
509 531
 		}
510 532
 
511
-		if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG);
533
+		if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) {
534
+			dol_syslog('sql='.$query, LOG_DEBUG);
535
+		}
512 536
 
513 537
 		$ret = @pg_query($this->db, $query);
514 538
 
515 539
 		//print $query;
516
-		if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) // Si requete utilisateur, on la sauvegarde ainsi que son resultset
540
+		if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) {
541
+			// Si requete utilisateur, on la sauvegarde ainsi que son resultset
517 542
 		{
518 543
 			if (! $ret)
519 544
 			{
520 545
 			    if ($this->errno() != 'DB_ERROR_25P02')	// Do not overwrite errors if this is a consecutive error
521 546
 			    {
522 547
     				$this->lastqueryerror = $query;
548
+		}
523 549
     				$this->lasterror = $this->error();
524 550
     				$this->lasterrno = $this->errno();
525 551
 
526
-    				if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR);	// Log of request was not yet done previously
552
+    				if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) {
553
+    					dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR);
554
+    				}
555
+    				// Log of request was not yet done previously
527 556
 					dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterror." (".$this->lasterrno.")", LOG_ERR);
528 557
 					dol_syslog(get_class($this)."::query SQL Error usesavepoint = ".$usesavepoint, LOG_ERR);
529 558
 			    }
530 559
 
531
-				if ($usesavepoint && $this->transaction_opened)	// Warning, after that errno will be erased
560
+				if ($usesavepoint && $this->transaction_opened) {
561
+					// Warning, after that errno will be erased
532 562
 				{
533 563
 					@pg_query($this->db, 'ROLLBACK TO SAVEPOINT mysavepoint');
534 564
 				}
565
+				}
535 566
 			}
536 567
 			$this->lastquery=$query;
537 568
 			$this->_results = $ret;
@@ -621,7 +652,9 @@  discard block
 block discarded – undo
621 652
         // If resultset not provided, we take the last used by connexion
622 653
 		if (! is_resource($resultset)) { $resultset=$this->_results; }
623 654
 		// Si resultset en est un, on libere la memoire
624
-		if (is_resource($resultset)) pg_free_result($resultset);
655
+		if (is_resource($resultset)) {
656
+			pg_free_result($resultset);
657
+		}
625 658
 	}
626 659
 
627 660
 
@@ -635,10 +668,17 @@  discard block
 block discarded – undo
635 668
 	function plimit($limit=0,$offset=0)
636 669
 	{
637 670
 		global $conf;
638
-        if (empty($limit)) return "";
639
-		if ($limit < 0) $limit=$conf->liste_limit;
640
-		if ($offset > 0) return " LIMIT ".$limit." OFFSET ".$offset." ";
641
-		else return " LIMIT $limit ";
671
+        if (empty($limit)) {
672
+        	return "";
673
+        }
674
+		if ($limit < 0) {
675
+			$limit=$conf->liste_limit;
676
+		}
677
+		if ($offset > 0) {
678
+			return " LIMIT ".$limit." OFFSET ".$offset." ";
679
+		} else {
680
+			return " LIMIT $limit ";
681
+		}
642 682
 	}
643 683
 
644 684
 
@@ -688,8 +728,7 @@  discard block
 block discarded – undo
688 728
 		if (! $this->connected) {
689 729
 			// Si il y a eu echec de connexion, $this->db n'est pas valide.
690 730
 			return 'DB_ERROR_FAILED_TO_CONNECT';
691
-		}
692
-		else {
731
+		} else {
693 732
 			// Constants to convert error code to a generic Dolibarr error code
694 733
 			$errorcode_map = array(
695 734
 			1004 => 'DB_ERROR_CANNOT_CREATE',
@@ -844,8 +883,12 @@  discard block
 block discarded – undo
844 883
 	 */
845 884
 	function DDLCreateDb($database,$charset='',$collation='',$owner='')
846 885
 	{
847
-	    if (empty($charset))   $charset=$this->forcecharset;
848
-		if (empty($collation)) $collation=$this->forcecollate;
886
+	    if (empty($charset)) {
887
+	    	$charset=$this->forcecharset;
888
+	    }
889
+		if (empty($collation)) {
890
+			$collation=$this->forcecollate;
891
+		}
849 892
 
850 893
 		// Test charset match LC_TYPE (pgsql error otherwise)
851 894
 		//print $charset.' '.setlocale(LC_CTYPE,'0'); exit;
@@ -868,7 +911,9 @@  discard block
 block discarded – undo
868 911
 		$listtables=array();
869 912
 
870 913
 		$like = '';
871
-		if ($table) $like = " AND table_name LIKE '".$table."'";
914
+		if ($table) {
915
+			$like = " AND table_name LIKE '".$table."'";
916
+		}
872 917
 		$result = pg_query($this->db, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'".$like." ORDER BY table_name");
873 918
         if ($result)
874 919
         {
@@ -944,26 +989,27 @@  discard block
 block discarded – undo
944 989
 		{
945 990
 			$sqlfields[$i] = $field_name." ";
946 991
 			$sqlfields[$i]  .= $field_desc['type'];
947
-			if( preg_match("/^[^\s]/i",$field_desc['value']))
948
-			$sqlfields[$i]  .= "(".$field_desc['value'].")";
949
-			else if( preg_match("/^[^\s]/i",$field_desc['attribute']))
950
-			$sqlfields[$i]  .= " ".$field_desc['attribute'];
951
-			else if( preg_match("/^[^\s]/i",$field_desc['default']))
992
+			if( preg_match("/^[^\s]/i",$field_desc['value'])) {
993
+						$sqlfields[$i]  .= "(".$field_desc['value'].")";
994
+			} else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) {
995
+						$sqlfields[$i]  .= " ".$field_desc['attribute'];
996
+			} else if( preg_match("/^[^\s]/i",$field_desc['default']))
952 997
 			{
953
-				if(preg_match("/null/i",$field_desc['default']))
954
-				$sqlfields[$i]  .= " default ".$field_desc['default'];
955
-				else
956
-				$sqlfields[$i]  .= " default '".$field_desc['default']."'";
998
+				if(preg_match("/null/i",$field_desc['default'])) {
999
+								$sqlfields[$i]  .= " default ".$field_desc['default'];
1000
+				} else {
1001
+								$sqlfields[$i]  .= " default '".$field_desc['default']."'";
1002
+				}
1003
+			} else if( preg_match("/^[^\s]/i",$field_desc['null'])) {
1004
+						$sqlfields[$i]  .= " ".$field_desc['null'];
1005
+			} else if( preg_match("/^[^\s]/i",$field_desc['extra'])) {
1006
+						$sqlfields[$i]  .= " ".$field_desc['extra'];
957 1007
 			}
958
-			else if( preg_match("/^[^\s]/i",$field_desc['null']))
959
-			$sqlfields[$i]  .= " ".$field_desc['null'];
960
-
961
-			else if( preg_match("/^[^\s]/i",$field_desc['extra']))
962
-			$sqlfields[$i]  .= " ".$field_desc['extra'];
963 1008
 			$i++;
964 1009
 		}
965
-		if($primary_key != "")
966
-		$pk = "primary key(".$primary_key.")";
1010
+		if($primary_key != "") {
1011
+				$pk = "primary key(".$primary_key.")";
1012
+		}
967 1013
 
968 1014
 		if(is_array($unique_keys))
969 1015
 		{
@@ -984,19 +1030,23 @@  discard block
 block discarded – undo
984 1030
 			}
985 1031
 		}
986 1032
 		$sql .= implode(',',$sqlfields);
987
-		if($primary_key != "")
988
-		$sql .= ",".$pk;
989
-		if(is_array($unique_keys))
990
-		$sql .= ",".implode(',',$sqluq);
991
-		if(is_array($keys))
992
-		$sql .= ",".implode(',',$sqlk);
1033
+		if($primary_key != "") {
1034
+				$sql .= ",".$pk;
1035
+		}
1036
+		if(is_array($unique_keys)) {
1037
+				$sql .= ",".implode(',',$sqluq);
1038
+		}
1039
+		if(is_array($keys)) {
1040
+				$sql .= ",".implode(',',$sqlk);
1041
+		}
993 1042
 		$sql .=") type=".$type;
994 1043
 
995 1044
 		dol_syslog($sql,LOG_DEBUG);
996
-		if(! $this->query($sql))
997
-		return -1;
998
-		else
999
-		return 1;
1045
+		if(! $this->query($sql)) {
1046
+				return -1;
1047
+		} else {
1048
+				return 1;
1049
+		}
1000 1050
 	}
1001 1051
 
1002 1052
 	/**
@@ -1009,10 +1059,11 @@  discard block
 block discarded – undo
1009 1059
 	{
1010 1060
 		$sql = "DROP TABLE ".$table;
1011 1061
 
1012
-		if (! $this->query($sql))
1013
-			return -1;
1014
-		else
1015
-			return 1;
1062
+		if (! $this->query($sql)) {
1063
+					return -1;
1064
+		} else {
1065
+					return 1;
1066
+		}
1016 1067
 	}
1017 1068
 
1018 1069
 	/**
@@ -1050,7 +1101,9 @@  discard block
 block discarded – undo
1050 1101
 	{
1051 1102
 		$sql ="SELECT attname FROM pg_attribute, pg_type WHERE typname = '".$table."' AND attrelid = typrelid";
1052 1103
 		$sql.=" AND attname NOT IN ('cmin', 'cmax', 'ctid', 'oid', 'tableoid', 'xmin', 'xmax')";
1053
-		if ($field) $sql.= " AND attname = '".$field."'";
1104
+		if ($field) {
1105
+			$sql.= " AND attname = '".$field."'";
1106
+		}
1054 1107
 
1055 1108
 		dol_syslog($sql,LOG_DEBUG);
1056 1109
 		$this->_results = $this->query($sql);
@@ -1072,27 +1125,33 @@  discard block
 block discarded – undo
1072 1125
 		// ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
1073 1126
 		$sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
1074 1127
 		$sql .= $field_desc['type'];
1075
-		if(preg_match("/^[^\s]/i",$field_desc['value']))
1076
-		    if (! in_array($field_desc['type'],array('int','date','datetime')))
1128
+		if(preg_match("/^[^\s]/i",$field_desc['value'])) {
1129
+				    if (! in_array($field_desc['type'],array('int','date','datetime')))
1077 1130
 		    {
1078 1131
 		        $sql.= "(".$field_desc['value'].")";
1132
+		}
1079 1133
 		    }
1080
-		if (preg_match("/^[^\s]/i",$field_desc['attribute']))
1081
-		$sql .= " ".$field_desc['attribute'];
1082
-		if (preg_match("/^[^\s]/i",$field_desc['null']))
1083
-		$sql .= " ".$field_desc['null'];
1084
-		if (preg_match("/^[^\s]/i",$field_desc['default']))
1085
-		if (preg_match("/null/i",$field_desc['default']))
1134
+		if (preg_match("/^[^\s]/i",$field_desc['attribute'])) {
1135
+				$sql .= " ".$field_desc['attribute'];
1136
+		}
1137
+		if (preg_match("/^[^\s]/i",$field_desc['null'])) {
1138
+				$sql .= " ".$field_desc['null'];
1139
+		}
1140
+		if (preg_match("/^[^\s]/i",$field_desc['default'])) {
1141
+				if (preg_match("/null/i",$field_desc['default']))
1086 1142
 		$sql .= " default ".$field_desc['default'];
1087
-		else
1088
-		$sql .= " default '".$field_desc['default']."'";
1089
-		if (preg_match("/^[^\s]/i",$field_desc['extra']))
1090
-		$sql .= " ".$field_desc['extra'];
1143
+		} else {
1144
+				$sql .= " default '".$field_desc['default']."'";
1145
+		}
1146
+		if (preg_match("/^[^\s]/i",$field_desc['extra'])) {
1147
+				$sql .= " ".$field_desc['extra'];
1148
+		}
1091 1149
 		$sql .= " ".$field_position;
1092 1150
 
1093 1151
 		dol_syslog($sql,LOG_DEBUG);
1094
-		if(! $this -> query($sql))
1095
-			return -1;
1152
+		if(! $this -> query($sql)) {
1153
+					return -1;
1154
+		}
1096 1155
 		return 1;
1097 1156
 	}
1098 1157
 
@@ -1119,8 +1178,7 @@  discard block
 block discarded – undo
1119 1178
         	{
1120 1179
         		$sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL";
1121 1180
         		$this->query($sqlbis);
1122
-        	}
1123
-        	elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int')
1181
+        	} elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int')
1124 1182
         	{
1125 1183
         		$sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL";
1126 1184
         		$this->query($sqlbis);
@@ -1129,13 +1187,18 @@  discard block
 block discarded – undo
1129 1187
 
1130 1188
 		if ($field_desc['default'] != '')
1131 1189
 		{
1132
-			if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']);
1133
-        	elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'";							// Default not supported on text fields
1190
+			if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') {
1191
+				$sql.=" DEFAULT ".$this->escape($field_desc['default']);
1192
+			} elseif ($field_desc['type'] == 'text') {
1193
+        		$sql.=" DEFAULT '".$this->escape($field_desc['default'])."'";
1194
+        	}
1195
+        	// Default not supported on text fields
1134 1196
 		}
1135 1197
 
1136 1198
 		dol_syslog($sql,LOG_DEBUG);
1137
-		if (! $this->query($sql))
1138
-			return -1;
1199
+		if (! $this->query($sql)) {
1200
+					return -1;
1201
+		}
1139 1202
 		return 1;
1140 1203
 	}
1141 1204
 
@@ -1170,8 +1233,9 @@  discard block
 block discarded – undo
1170 1233
 		{
1171 1234
             $liste=$this->fetch_array($resql);
1172 1235
 		    return $liste['server_encoding'];
1236
+		} else {
1237
+			return '';
1173 1238
 		}
1174
-		else return '';
1175 1239
 	}
1176 1240
 
1177 1241
 	/**
@@ -1211,8 +1275,9 @@  discard block
 block discarded – undo
1211 1275
 		{
1212 1276
 		    $liste=$this->fetch_array($resql);
1213 1277
 			return $liste['lc_collate'];
1278
+		} else {
1279
+			return '';
1214 1280
 		}
1215
-		else return '';
1216 1281
 	}
1217 1282
 
1218 1283
 	/**
@@ -1251,8 +1316,7 @@  discard block
 block discarded – undo
1251 1316
 		if (file_exists('/usr/bin/pg_dump'))
1252 1317
 		{
1253 1318
 		    $fullpathofdump='/usr/bin/pg_dump';
1254
-		}
1255
-		else
1319
+		} else
1256 1320
 		{
1257 1321
             // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande
1258 1322
 		    $resql=$this->query('SHOW data_directory');
@@ -1282,8 +1346,7 @@  discard block
 block discarded – undo
1282 1346
         if (file_exists('/usr/bin/'.$tool))
1283 1347
         {
1284 1348
             $fullpathofdump='/usr/bin/'.$tool;
1285
-        }
1286
-        else
1349
+        } else
1287 1350
         {
1288 1351
             // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande
1289 1352
             $resql=$this->query('SHOW data_directory');
@@ -1309,11 +1372,15 @@  discard block
 block discarded – undo
1309 1372
 		$result=array();
1310 1373
 
1311 1374
 		$resql='select name,setting from pg_settings';
1312
-		if ($filter) $resql.=" WHERE name = '".$this->escape($filter)."'";
1375
+		if ($filter) {
1376
+			$resql.=" WHERE name = '".$this->escape($filter)."'";
1377
+		}
1313 1378
 		$resql=$this->query($resql);
1314 1379
 		if ($resql)
1315 1380
 		{
1316
-			while ($obj=$this->fetch_object($resql)) $result[$obj->name]=$obj->setting;
1381
+			while ($obj=$this->fetch_object($resql)) {
1382
+				$result[$obj->name]=$obj->setting;
1383
+			}
1317 1384
 		}
1318 1385
 
1319 1386
 		return $result;
Please login to merge, or discard this patch.
htdocs/core/db/sqlite3.class.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1449,7 +1449,7 @@
 block discarded – undo
1449 1449
      *
1450 1450
      * @param int	$daynr							???
1451 1451
      * @param bool	$sunday_first_day_of_week		???
1452
-     * @return int
1452
+     * @return double
1453 1453
      */
1454 1454
     private static function calc_weekday($daynr, $sunday_first_day_of_week) {
1455 1455
       $ret = floor(($daynr + 5 + ($sunday_first_day_of_week ? 1 : 0)) % 7);
Please login to merge, or discard this patch.
Braces   +117 added lines, -84 removed lines patch added patch discarded remove patch
@@ -62,8 +62,12 @@  discard block
 block discarded – undo
62 62
         global $conf;
63 63
 
64 64
         // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static
65
-        if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set;
66
-        if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation;
65
+        if (! empty($conf->db->character_set)) {
66
+        	$this->forcecharset=$conf->db->character_set;
67
+        }
68
+        if (! empty($conf->db->dolibarr_main_db_collation)) {
69
+        	$this->forcecollate=$conf->db->dolibarr_main_db_collation;
70
+        }
67 71
 
68 72
         $this->database_user=$user;
69 73
         $this->database_host=$host;
@@ -111,8 +115,7 @@  discard block
 block discarded – undo
111 115
             $this->addCustomFunction('WEEKDAY');
112 116
             $this->addCustomFunction('date_format');
113 117
             //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
114
-        }
115
-        else
118
+        } else
116 119
         {
117 120
             // host, login ou password incorrect
118 121
             $this->connected = false;
@@ -149,9 +152,13 @@  discard block
 block discarded – undo
149 152
         {
150 153
             if ($type == 'auto')
151 154
             {
152
-              if (preg_match('/ALTER TABLE/i',$line)) $type='dml';
153
-              else if (preg_match('/CREATE TABLE/i',$line)) $type='dml';
154
-              else if (preg_match('/DROP TABLE/i',$line)) $type='dml';
155
+              if (preg_match('/ALTER TABLE/i',$line)) {
156
+              	$type='dml';
157
+              } else if (preg_match('/CREATE TABLE/i',$line)) {
158
+              	$type='dml';
159
+              } else if (preg_match('/DROP TABLE/i',$line)) {
160
+              	$type='dml';
161
+              }
155 162
             }
156 163
 
157 164
             if ($type == 'dml')
@@ -272,9 +279,11 @@  discard block
 block discarded – undo
272 279
             // DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable
273 280
             if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',$line,$reg))
274 281
             {
275
-				if ($reg[1] == $reg[2])	// If same table, we remove second one
282
+				if ($reg[1] == $reg[2]) {
283
+					// If same table, we remove second one
276 284
                 {
277 285
                     $line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line);
286
+				}
278 287
                 }
279 288
             }
280 289
 
@@ -329,7 +338,9 @@  discard block
 block discarded – undo
329 338
         dol_syslog(get_class($this)."::connect name=".$name,LOG_DEBUG);
330 339
 
331 340
         $dir=$main_data_dir;
332
-        if (empty($dir)) $dir=DOL_DATA_ROOT;
341
+        if (empty($dir)) {
342
+        	$dir=DOL_DATA_ROOT;
343
+        }
333 344
         // With sqlite, port must be in connect parameters
334 345
         //if (! $newport) $newport=3306;
335 346
         $database_name = $dir.'/database_'.$name.'.sdb';
@@ -338,8 +349,7 @@  discard block
 block discarded – undo
338 349
             //$this->db = new PDO("sqlite:".$dir.'/database_'.$name.'.sdb');
339 350
 			$this->db = new SQLite3($database_name);
340 351
             //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
341
-        }
342
-        catch(Exception $e)
352
+        } catch(Exception $e)
343 353
         {
344 354
             $this->error=  self::LABEL.' '.$e->getMessage().' current dir='.$database_name;
345 355
             return '';
@@ -382,7 +392,9 @@  discard block
 block discarded – undo
382 392
     {
383 393
         if ($this->db)
384 394
         {
385
-            if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
395
+            if ($this->transaction_opened > 0) {
396
+            	dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR);
397
+            }
386 398
             $this->connected=false;
387 399
             $this->db->close();
388 400
             unset($this->db);    // Clean this->db
@@ -458,8 +470,7 @@  discard block
 block discarded – undo
458 470
             if ($ret) {
459 471
                 $ret->queryString = $query;
460 472
             }
461
-        }
462
-        catch(Exception $e)
473
+        } catch(Exception $e)
463 474
         {
464 475
             $this->error=$this->db->lastErrorMsg();
465 476
         }
@@ -537,8 +548,7 @@  discard block
 block discarded – undo
537 548
         {
538 549
             if (! is_object($resultset)) { $resultset=$this->_results; }
539 550
             return $resultset->fetchArray(SQLITE3_NUM);
540
-        }
541
-        else
551
+        } else
542 552
         {
543 553
             // si le curseur est un booleen on retourne la valeur 0
544 554
             return false;
@@ -597,7 +607,9 @@  discard block
 block discarded – undo
597 607
         // If resultset not provided, we take the last used by connexion
598 608
         if (! is_object($resultset)) { $resultset=$this->_results; }
599 609
         // Si resultset en est un, on libere la memoire
600
-        if ($resultset && is_object($resultset)) $resultset->finalize();
610
+        if ($resultset && is_object($resultset)) {
611
+        	$resultset->finalize();
612
+        }
601 613
     }
602 614
 
603 615
     /**
@@ -621,8 +633,7 @@  discard block
 block discarded – undo
621 633
         if (! $this->connected) {
622 634
             // Si il y a eu echec de connexion, $this->db n'est pas valide.
623 635
             return 'DB_ERROR_FAILED_TO_CONNECT';
624
-        }
625
-        else {
636
+        } else {
626 637
             // Constants to convert error code to a generic Dolibarr error code
627 638
             /*$errorcode_map = array(
628 639
             1004 => 'DB_ERROR_CANNOT_CREATE',
@@ -659,14 +670,21 @@  discard block
 block discarded – undo
659 670
             $errno=$this->db->lastErrorCode();
660 671
 			if ($errno=='HY000' || $errno == 0)
661 672
             {
662
-                if (preg_match('/table.*already exists/i',$this->error))     return 'DB_ERROR_TABLE_ALREADY_EXISTS';
663
-                elseif (preg_match('/index.*already exists/i',$this->error)) return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS';
664
-                elseif (preg_match('/syntax error/i',$this->error))          return 'DB_ERROR_SYNTAX';
673
+                if (preg_match('/table.*already exists/i',$this->error)) {
674
+                	return 'DB_ERROR_TABLE_ALREADY_EXISTS';
675
+                } elseif (preg_match('/index.*already exists/i',$this->error)) {
676
+                	return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS';
677
+                } elseif (preg_match('/syntax error/i',$this->error)) {
678
+                	return 'DB_ERROR_SYNTAX';
679
+                }
665 680
             }
666 681
             if ($errno=='23000')
667 682
             {
668
-                if (preg_match('/column.* not unique/i',$this->error))       return 'DB_ERROR_RECORD_ALREADY_EXISTS';
669
-                elseif (preg_match('/PRIMARY KEY must be unique/i',$this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS';
683
+                if (preg_match('/column.* not unique/i',$this->error)) {
684
+                	return 'DB_ERROR_RECORD_ALREADY_EXISTS';
685
+                } elseif (preg_match('/PRIMARY KEY must be unique/i',$this->error)) {
686
+                	return 'DB_ERROR_RECORD_ALREADY_EXISTS';
687
+                }
670 688
             }
671 689
             if ($errno > 1) {
672 690
                 // TODO Voir la liste des messages d'erreur
@@ -686,8 +704,7 @@  discard block
 block discarded – undo
686 704
         if (! $this->connected) {
687 705
             // Si il y a eu echec de connexion, $this->db n'est pas valide pour sqlite_error.
688 706
             return 'Not connected. Check setup parameters in conf/conf.php file and your sqlite version';
689
-        }
690
-        else {
707
+        } else {
691 708
             return $this->error;
692 709
         }
693 710
     }
@@ -729,8 +746,7 @@  discard block
 block discarded – undo
729 746
             if ($cryptType == 2)
730 747
             {
731 748
                 $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')';
732
-            }
733
-            else if ($cryptType == 1)
749
+            } else if ($cryptType == 1)
734 750
             {
735 751
                 $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')';
736 752
             }
@@ -762,8 +778,7 @@  discard block
 block discarded – undo
762 778
             if ($cryptType == 2)
763 779
             {
764 780
                 $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')';
765
-            }
766
-            else if ($cryptType == 1)
781
+            } else if ($cryptType == 1)
767 782
             {
768 783
                 $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')';
769 784
             }
@@ -797,8 +812,12 @@  discard block
 block discarded – undo
797 812
      */
798 813
     function DDLCreateDb($database,$charset='',$collation='',$owner='')
799 814
     {
800
-        if (empty($charset))   $charset=$this->forcecharset;
801
-        if (empty($collation)) $collation=$this->forcecollate;
815
+        if (empty($charset)) {
816
+        	$charset=$this->forcecharset;
817
+        }
818
+        if (empty($collation)) {
819
+        	$collation=$this->forcecollate;
820
+        }
802 821
 
803 822
         // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci
804 823
         $sql = 'CREATE DATABASE '.$database;
@@ -828,7 +847,9 @@  discard block
 block discarded – undo
828 847
         $listtables=array();
829 848
 
830 849
         $like = '';
831
-        if ($table) $like = "LIKE '".$table."'";
850
+        if ($table) {
851
+        	$like = "LIKE '".$table."'";
852
+        }
832 853
         $sql="SHOW TABLES FROM ".$database." ".$like.";";
833 854
         //print $sql;
834 855
         $result = $this->query($sql);
@@ -891,26 +912,27 @@  discard block
 block discarded – undo
891 912
         {
892 913
             $sqlfields[$i] = $field_name." ";
893 914
             $sqlfields[$i]  .= $field_desc['type'];
894
-            if( preg_match("/^[^\s]/i",$field_desc['value']))
895
-            $sqlfields[$i]  .= "(".$field_desc['value'].")";
896
-            else if( preg_match("/^[^\s]/i",$field_desc['attribute']))
897
-            $sqlfields[$i]  .= " ".$field_desc['attribute'];
898
-            else if( preg_match("/^[^\s]/i",$field_desc['default']))
915
+            if( preg_match("/^[^\s]/i",$field_desc['value'])) {
916
+                        $sqlfields[$i]  .= "(".$field_desc['value'].")";
917
+            } else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) {
918
+                        $sqlfields[$i]  .= " ".$field_desc['attribute'];
919
+            } else if( preg_match("/^[^\s]/i",$field_desc['default']))
899 920
             {
900
-                if(preg_match("/null/i",$field_desc['default']))
901
-                $sqlfields[$i]  .= " default ".$field_desc['default'];
902
-                else
903
-                $sqlfields[$i]  .= " default '".$field_desc['default']."'";
921
+                if(preg_match("/null/i",$field_desc['default'])) {
922
+                                $sqlfields[$i]  .= " default ".$field_desc['default'];
923
+                } else {
924
+                                $sqlfields[$i]  .= " default '".$field_desc['default']."'";
925
+                }
926
+            } else if( preg_match("/^[^\s]/i",$field_desc['null'])) {
927
+                        $sqlfields[$i]  .= " ".$field_desc['null'];
928
+            } else if( preg_match("/^[^\s]/i",$field_desc['extra'])) {
929
+                        $sqlfields[$i]  .= " ".$field_desc['extra'];
904 930
             }
905
-            else if( preg_match("/^[^\s]/i",$field_desc['null']))
906
-            $sqlfields[$i]  .= " ".$field_desc['null'];
907
-
908
-            else if( preg_match("/^[^\s]/i",$field_desc['extra']))
909
-            $sqlfields[$i]  .= " ".$field_desc['extra'];
910 931
             $i++;
911 932
         }
912
-        if($primary_key != "")
913
-        $pk = "primary key(".$primary_key.")";
933
+        if($primary_key != "") {
934
+                $pk = "primary key(".$primary_key.")";
935
+        }
914 936
 
915 937
         if(is_array($unique_keys))
916 938
         {
@@ -931,17 +953,21 @@  discard block
 block discarded – undo
931 953
             }
932 954
         }
933 955
         $sql .= implode(',',$sqlfields);
934
-        if($primary_key != "")
935
-        $sql .= ",".$pk;
936
-        if(is_array($unique_keys))
937
-        $sql .= ",".implode(',',$sqluq);
938
-        if(is_array($keys))
939
-        $sql .= ",".implode(',',$sqlk);
956
+        if($primary_key != "") {
957
+                $sql .= ",".$pk;
958
+        }
959
+        if(is_array($unique_keys)) {
960
+                $sql .= ",".implode(',',$sqluq);
961
+        }
962
+        if(is_array($keys)) {
963
+                $sql .= ",".implode(',',$sqlk);
964
+        }
940 965
         $sql .=") type=".$type;
941 966
 
942 967
         dol_syslog($sql,LOG_DEBUG);
943
-        if(! $this -> query($sql))
944
-            return -1;
968
+        if(! $this -> query($sql)) {
969
+                    return -1;
970
+        }
945 971
         return 1;
946 972
     }
947 973
 
@@ -955,10 +981,11 @@  discard block
 block discarded – undo
955 981
     {
956 982
     	$sql = "DROP TABLE ".$table;
957 983
 
958
-    	if (! $this->query($sql))
959
-    		return -1;
960
-    	else
961
-    		return 1;
984
+    	if (! $this->query($sql)) {
985
+    	    		return -1;
986
+    	} else {
987
+    	    		return 1;
988
+    	}
962 989
     }
963 990
 
964 991
     /**
@@ -992,24 +1019,29 @@  discard block
 block discarded – undo
992 1019
         // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment');
993 1020
         $sql= "ALTER TABLE ".$table." ADD ".$field_name." ";
994 1021
         $sql.= $field_desc['type'];
995
-        if(preg_match("/^[^\s]/i",$field_desc['value']))
996
-        if (! in_array($field_desc['type'],array('date','datetime')))
1022
+        if(preg_match("/^[^\s]/i",$field_desc['value'])) {
1023
+                if (! in_array($field_desc['type'],array('date','datetime')))
997 1024
         {
998 1025
             $sql.= "(".$field_desc['value'].")";
999 1026
         }
1000
-        if(preg_match("/^[^\s]/i",$field_desc['attribute']))
1001
-        $sql.= " ".$field_desc['attribute'];
1002
-        if(preg_match("/^[^\s]/i",$field_desc['null']))
1003
-        $sql.= " ".$field_desc['null'];
1027
+        }
1028
+        if(preg_match("/^[^\s]/i",$field_desc['attribute'])) {
1029
+                $sql.= " ".$field_desc['attribute'];
1030
+        }
1031
+        if(preg_match("/^[^\s]/i",$field_desc['null'])) {
1032
+                $sql.= " ".$field_desc['null'];
1033
+        }
1004 1034
         if(preg_match("/^[^\s]/i",$field_desc['default']))
1005 1035
         {
1006
-            if(preg_match("/null/i",$field_desc['default']))
1007
-            $sql.= " default ".$field_desc['default'];
1008
-            else
1009
-            $sql.= " default '".$field_desc['default']."'";
1036
+            if(preg_match("/null/i",$field_desc['default'])) {
1037
+                        $sql.= " default ".$field_desc['default'];
1038
+            } else {
1039
+                        $sql.= " default '".$field_desc['default']."'";
1040
+            }
1041
+        }
1042
+        if(preg_match("/^[^\s]/i",$field_desc['extra'])) {
1043
+                $sql.= " ".$field_desc['extra'];
1010 1044
         }
1011
-        if(preg_match("/^[^\s]/i",$field_desc['extra']))
1012
-        $sql.= " ".$field_desc['extra'];
1013 1045
         $sql.= " ".$field_position;
1014 1046
 
1015 1047
         dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG);
@@ -1037,8 +1069,9 @@  discard block
 block discarded – undo
1037 1069
         }
1038 1070
 
1039 1071
         dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG);
1040
-        if (! $this->query($sql))
1041
-            return -1;
1072
+        if (! $this->query($sql)) {
1073
+                    return -1;
1074
+        }
1042 1075
         return 1;
1043 1076
     }
1044 1077
 
@@ -1236,8 +1269,7 @@  discard block
 block discarded – undo
1236 1269
                 $obj = $this->fetch_row($resql);
1237 1270
                 //dol_syslog(get_class($this)."::select_db getServerParametersValues $var=". print_r($obj, true), LOG_DEBUG);
1238 1271
                 $result[$var] = $obj[0];
1239
-            }
1240
-            else {
1272
+            } else {
1241 1273
                 // TODO Récupérer le message
1242 1274
                 $result[$var] = 'FAIL';
1243 1275
             }
@@ -1304,11 +1336,12 @@  discard block
 block discarded – undo
1304 1336
      */
1305 1337
     private static function calc_daynr($year, $month, $day) {
1306 1338
         $y = $year;
1307
-        if ($y == 0 && $month == 0) return 0;
1339
+        if ($y == 0 && $month == 0) {
1340
+        	return 0;
1341
+        }
1308 1342
         $num = (365* $y + 31 * ($month - 1) + $day);
1309 1343
         if ($month <= 2) {
1310
-            $y--; }
1311
-        else {
1344
+            $y--; } else {
1312 1345
             $num -= floor(($month * 4 + 23) / 10);
1313 1346
         }
1314 1347
         $temp = floor(($y / 100 + 1) * 3 / 4);
@@ -1360,8 +1393,9 @@  discard block
 block discarded – undo
1360 1393
 
1361 1394
         if ($month == 1 && $day <= 7-$weekday)
1362 1395
         {
1363
-            if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)))
1364
-                return 0;
1396
+            if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4))) {
1397
+                            return 0;
1398
+            }
1365 1399
             $week_year= 1;
1366 1400
             $calc_year--;
1367 1401
             $first_daynr-= ($days=self::calc_days_in_year($calc_year));
@@ -1370,8 +1404,7 @@  discard block
 block discarded – undo
1370 1404
 
1371 1405
       if (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)) {
1372 1406
         $days= $daynr - ($first_daynr+ (7-$weekday));
1373
-      }
1374
-      else {
1407
+      } else {
1375 1408
         $days= $daynr - ($first_daynr - $weekday);
1376 1409
       }
1377 1410
 
Please login to merge, or discard this patch.
htdocs/core/filemanagerdol/connectors/php/util.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
  * Returns true if file contain insecure HTML code at the beginning.
131 131
  *
132 132
  * @param string $filePath absolute path to file
133
- * @return boolean
133
+ * @return string
134 134
  */
135 135
 function DetectHtml( $filePath )
136 136
 {
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
  *
201 201
  * @param 	string 	$filePath 		Absolute path to file
202 202
  * @param 	string 	$extension 		File extension
203
- * @return 	boolean					True or false
203
+ * @return 	string					True or false
204 204
  */
205 205
 function IsImageValid( $filePath, $extension )
206 206
 {
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -87,8 +87,7 @@  discard block
 block discarded – undo
87 87
 	if ( defined('PHP_OS') )
88 88
 	{
89 89
 		$os = PHP_OS ;
90
-	}
91
-	else
90
+	} else
92 91
 	{
93 92
 		$os = php_uname();
94 93
 	}
@@ -96,8 +95,7 @@  discard block
 block discarded – undo
96 95
 	if (strtoupper(substr($os, 0, 3)) === 'WIN' || FindBadUtf8($value))
97 96
 	{
98 97
 		return (utf8_encode(htmlspecialchars($value)));
99
-	}
100
-	else
98
+	} else
101 99
 	{
102 100
 		return (htmlspecialchars($value));
103 101
 	}
Please login to merge, or discard this patch.