Passed
Pull Request — master (#2)
by
unknown
26:19
created
dolibarr/htdocs/core/lib/supplier_proposal.lib.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	global $db, $langs, $conf, $user;
35 35
 
36 36
 	// Load translation files required by the page
37
-    $langs->loadLangs(array("supplier_proposal","compta"));
37
+    $langs->loadLangs(array("supplier_proposal", "compta"));
38 38
 
39 39
 	$h = 0;
40 40
 	$head = array();
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
 
47 47
 	if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
48 48
 	{
49
-		$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
49
+		$nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
50 50
 		$head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/contact.php?id='.$object->id;
51 51
 		$head[$h][1] = $langs->trans('ContactsAddresses');
52
-		if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
52
+		if ($nbContact > 0) $head[$h][1] .= ' <span class="badge">'.$nbContact.'</span>';
53 53
 		$head[$h][2] = 'contact';
54 54
 		$h++;
55 55
 	}
@@ -58,28 +58,28 @@  discard block
 block discarded – undo
58 58
     // Entries must be declared in modules descriptor with line
59 59
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
60 60
     // $this->tabs = array('entity:-tabname);   												to remove a tab
61
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'supplier_proposal');
61
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_proposal');
62 62
 
63 63
     if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
64 64
     {
65 65
     	$nbNote = 0;
66
-        if(!empty($object->note_private)) $nbNote++;
67
-		if(!empty($object->note_public)) $nbNote++;
66
+        if (!empty($object->note_private)) $nbNote++;
67
+		if (!empty($object->note_public)) $nbNote++;
68 68
 	    $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/note.php?id='.$object->id;
69 69
 		$head[$h][1] = $langs->trans('Notes');
70
-		if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
70
+		if ($nbNote > 0) $head[$h][1] .= ' <span class="badge">'.$nbNote.'</span>';
71 71
 		$head[$h][2] = 'note';
72 72
 		$h++;
73 73
     }
74 74
 
75 75
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
76 76
     require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
77
-	$upload_dir = $conf->supplier_proposal->dir_output . "/" . dol_sanitizeFileName($object->ref);
78
-	$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
79
-    $nbLinks=Link::count($db, $object->element, $object->id);
77
+	$upload_dir = $conf->supplier_proposal->dir_output."/".dol_sanitizeFileName($object->ref);
78
+	$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
79
+    $nbLinks = Link::count($db, $object->element, $object->id);
80 80
 	$head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$object->id;
81 81
 	$head[$h][1] = $langs->trans('Documents');
82
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
82
+	if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>';
83 83
 	$head[$h][2] = 'document';
84 84
 	$h++;
85 85
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	$head[$h][2] = 'info';
89 89
 	$h++;
90 90
 
91
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'supplier_proposal','remove');
91
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_proposal', 'remove');
92 92
 
93 93
 	return $head;
94 94
 }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	// Entries must be declared in modules descriptor with line
115 115
 	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
116 116
 	// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to remove a tab
117
-	complete_head_from_modules($conf,$langs,null,$head,$h,'supplier_proposal_admin');
117
+	complete_head_from_modules($conf, $langs, null, $head, $h, 'supplier_proposal_admin');
118 118
 
119 119
 	$head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/admin/supplier_proposal_extrafields.php';
120 120
 	$head[$h][1] = $langs->trans("ExtraFields");
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     $head[$h][2] = 'attributeslines';
127 127
     $h++;
128 128
 
129
-	complete_head_from_modules($conf,$langs,null,$head,$h,'supplier_proposal_admin','remove');
129
+	complete_head_from_modules($conf, $langs, null, $head, $h, 'supplier_proposal_admin', 'remove');
130 130
 
131 131
 	return $head;
132 132
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/date.lib.php 1 patch
Spacing   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
  */
34 34
 function get_tz_array()
35 35
 {
36
-    $tzarray=array(
36
+    $tzarray = array(
37 37
         -11=>"Pacific/Midway",
38 38
         -10=>"Pacific/Fakaofo",
39 39
         -9=>"America/Anchorage",
@@ -80,28 +80,28 @@  discard block
 block discarded – undo
80 80
  * @param	string	$refgmtdate		Reference period for timezone (timezone differs on winter and summer. May be 'now', 'winter' or 'summer')
81 81
  * @return 	int						An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer)
82 82
  */
83
-function getServerTimeZoneInt($refgmtdate='now')
83
+function getServerTimeZoneInt($refgmtdate = 'now')
84 84
 {
85 85
     global $conf;
86
-    if (method_exists('DateTimeZone','getOffset'))
86
+    if (method_exists('DateTimeZone', 'getOffset'))
87 87
     {
88 88
         // Method 1 (include daylight)
89
-        $gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref=dol_print_date($gmtnow,'%m'); $dayref=dol_print_date($gmtnow,'%d');
90
-        if ($refgmtdate == 'now') $newrefgmtdate=$yearref.'-'.$monthref.'-'.$dayref;
91
-        elseif ($refgmtdate == 'summer') $newrefgmtdate=$yearref.'-08-01';
92
-        else $newrefgmtdate=$yearref.'-01-01';
93
-        $newrefgmtdate.='T00:00:00+00:00';
89
+        $gmtnow = dol_now('gmt'); $yearref = dol_print_date($gmtnow, '%Y'); $monthref = dol_print_date($gmtnow, '%m'); $dayref = dol_print_date($gmtnow, '%d');
90
+        if ($refgmtdate == 'now') $newrefgmtdate = $yearref.'-'.$monthref.'-'.$dayref;
91
+        elseif ($refgmtdate == 'summer') $newrefgmtdate = $yearref.'-08-01';
92
+        else $newrefgmtdate = $yearref.'-01-01';
93
+        $newrefgmtdate .= 'T00:00:00+00:00';
94 94
         $localtz = new DateTimeZone(getServerTimeZoneString());
95 95
         $localdt = new DateTime($newrefgmtdate, $localtz);
96
-        $tmp=-1*$localtz->getOffset($localdt);
96
+        $tmp = -1 * $localtz->getOffset($localdt);
97 97
         //print $refgmtdate.'='.$tmp;
98 98
     }
99 99
     else
100 100
     {
101
-    	$tmp=0;
102
-    	dol_print_error('','PHP version must be 5.3+');
101
+    	$tmp = 0;
102
+    	dol_print_error('', 'PHP version must be 5.3+');
103 103
     }
104
-    $tz=round(($tmp<0?1:-1)*abs($tmp/3600));
104
+    $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600));
105 105
     return $tz;
106 106
 }
107 107
 
@@ -119,24 +119,24 @@  discard block
 block discarded – undo
119 119
 	global $conf;
120 120
 
121 121
 	if ($duration_value == 0)  return $time;
122
-	if ($duration_unit == 'h') return $time + (3600*$duration_value);
123
-	if ($duration_unit == 'w') return $time + (3600*24*7*$duration_value);
122
+	if ($duration_unit == 'h') return $time + (3600 * $duration_value);
123
+	if ($duration_unit == 'w') return $time + (3600 * 24 * 7 * $duration_value);
124 124
 
125
-	$deltastring='P';
125
+	$deltastring = 'P';
126 126
 
127
-	if ($duration_value > 0){ $deltastring.=abs($duration_value); $sub= false; }
128
-	if ($duration_value < 0){ $deltastring.=abs($duration_value); $sub= true; }
129
-	if ($duration_unit == 'd') { $deltastring.="D"; }
130
-	if ($duration_unit == 'm') { $deltastring.="M"; }
131
-	if ($duration_unit == 'y') { $deltastring.="Y"; }
127
+	if ($duration_value > 0) { $deltastring .= abs($duration_value); $sub = false; }
128
+	if ($duration_value < 0) { $deltastring .= abs($duration_value); $sub = true; }
129
+	if ($duration_unit == 'd') { $deltastring .= "D"; }
130
+	if ($duration_unit == 'm') { $deltastring .= "M"; }
131
+	if ($duration_unit == 'y') { $deltastring .= "Y"; }
132 132
 
133 133
 	$date = new DateTime();
134
-	if (! empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) $date->setTimezone(new DateTimeZone('UTC'));
134
+	if (!empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) $date->setTimezone(new DateTimeZone('UTC'));
135 135
 	$date->setTimestamp($time);
136 136
 	$interval = new DateInterval($deltastring);
137 137
 
138
-	if($sub) $date->sub($interval);
139
-	else $date->add( $interval );
138
+	if ($sub) $date->sub($interval);
139
+	else $date->add($interval);
140 140
 
141 141
 	return $date->getTimestamp();
142 142
 }
@@ -151,9 +151,9 @@  discard block
 block discarded – undo
151 151
  * @return     int						Time into seconds
152 152
  * @see convertSecondToTime
153 153
  */
154
-function convertTime2Seconds($iHours=0, $iMinutes=0, $iSeconds=0)
154
+function convertTime2Seconds($iHours = 0, $iMinutes = 0, $iSeconds = 0)
155 155
 {
156
-	$iResult=($iHours*3600)+($iMinutes*60)+$iSeconds;
156
+	$iResult = ($iHours * 3600) + ($iMinutes * 60) + $iSeconds;
157 157
 	return $iResult;
158 158
 }
159 159
 
@@ -178,30 +178,30 @@  discard block
 block discarded – undo
178 178
  * 	                                		Example: 0 return 00:00, 3600 return 1:00, 86400 return 1d, 90000 return 1 Day 01:00
179 179
  *      @see convertTime2Seconds
180 180
  */
181
-function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
181
+function convertSecondToTime($iSecond, $format = 'all', $lengthOfDay = 86400, $lengthOfWeek = 7)
182 182
 {
183 183
 	global $langs;
184 184
 
185
-	if (empty($lengthOfDay))  $lengthOfDay = 86400;         // 1 day = 24 hours
186
-    if (empty($lengthOfWeek)) $lengthOfWeek = 7;            // 1 week = 7 days
185
+	if (empty($lengthOfDay))  $lengthOfDay = 86400; // 1 day = 24 hours
186
+    if (empty($lengthOfWeek)) $lengthOfWeek = 7; // 1 week = 7 days
187 187
 
188 188
 	if ($format == 'all' || $format == 'allwithouthour' || $format == 'allhour' || $format == 'allhourmin')
189 189
 	{
190
-		if ((int) $iSecond === 0) return '0';	// This is to avoid having 0 return a 12:00 AM for en_US
190
+		if ((int) $iSecond === 0) return '0'; // This is to avoid having 0 return a 12:00 AM for en_US
191 191
 
192
-        $sTime='';
193
-        $sDay=0;
194
-        $sWeek=0;
192
+        $sTime = '';
193
+        $sDay = 0;
194
+        $sWeek = 0;
195 195
 
196 196
 		if ($iSecond >= $lengthOfDay)
197 197
 		{
198
-			for($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay )
198
+			for ($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay)
199 199
 			{
200 200
 				$sDay++;
201
-				$iSecond-=$lengthOfDay;
201
+				$iSecond -= $lengthOfDay;
202 202
 			}
203 203
 			$dayTranslate = $langs->trans("Day");
204
-			if ($iSecond >= ($lengthOfDay*2)) $dayTranslate = $langs->trans("Days");
204
+			if ($iSecond >= ($lengthOfDay * 2)) $dayTranslate = $langs->trans("Days");
205 205
 		}
206 206
 
207 207
 		if ($lengthOfWeek < 7)
@@ -210,66 +210,66 @@  discard block
 block discarded – undo
210 210
             {
211 211
                 if ($sDay >= $lengthOfWeek)
212 212
                 {
213
-                    $sWeek = (int) (($sDay - $sDay % $lengthOfWeek ) / $lengthOfWeek);
213
+                    $sWeek = (int) (($sDay - $sDay % $lengthOfWeek) / $lengthOfWeek);
214 214
                     $sDay = $sDay % $lengthOfWeek;
215 215
                     $weekTranslate = $langs->trans("DurationWeek");
216 216
                     if ($sWeek >= 2) $weekTranslate = $langs->trans("DurationWeeks");
217
-                    $sTime.=$sWeek.' '.$weekTranslate.' ';
217
+                    $sTime .= $sWeek.' '.$weekTranslate.' ';
218 218
                 }
219 219
             }
220 220
 		}
221
-		if ($sDay>0)
221
+		if ($sDay > 0)
222 222
 		{
223 223
 			$dayTranslate = $langs->trans("Day");
224 224
 			if ($sDay > 1) $dayTranslate = $langs->trans("Days");
225
-			$sTime.=$sDay.' '.$dayTranslate.' ';
225
+			$sTime .= $sDay.' '.$dayTranslate.' ';
226 226
 		}
227 227
 
228 228
 		if ($format == 'all')
229 229
 		{
230 230
 			if ($iSecond || empty($sDay))
231 231
 			{
232
-				$sTime.= dol_print_date($iSecond,'hourduration',true);
232
+				$sTime .= dol_print_date($iSecond, 'hourduration', true);
233 233
 			}
234 234
 		}
235 235
 		if ($format == 'allhourmin')
236 236
 		{
237
-		    return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))).':'.sprintf("%02d",((int) floor(($iSecond % 3600)/60)));
237
+		    return sprintf("%02d", ($sWeek * $lengthOfWeek * 24 + $sDay * 24 + (int) floor($iSecond / 3600))).':'.sprintf("%02d", ((int) floor(($iSecond % 3600) / 60)));
238 238
 		}
239 239
 		if ($format == 'allhour')
240 240
 		{
241
-			return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600)));
241
+			return sprintf("%02d", ($sWeek * $lengthOfWeek * 24 + $sDay * 24 + (int) floor($iSecond / 3600)));
242 242
 		}
243 243
 	}
244 244
 	else if ($format == 'hour')	// only hour part
245 245
 	{
246
-		$sTime=dol_print_date($iSecond,'%H',true);
246
+		$sTime = dol_print_date($iSecond, '%H', true);
247 247
 	}
248 248
 	else if ($format == 'fullhour')
249 249
 	{
250 250
 		if (!empty($iSecond)) {
251
-			$iSecond=$iSecond/3600;
251
+			$iSecond = $iSecond / 3600;
252 252
 		}
253 253
 		else {
254
-			$iSecond=0;
254
+			$iSecond = 0;
255 255
 		}
256
-		$sTime=$iSecond;
256
+		$sTime = $iSecond;
257 257
 	}
258 258
 	else if ($format == 'min')	// only min part
259 259
 	{
260
-		$sTime=dol_print_date($iSecond,'%M',true);
260
+		$sTime = dol_print_date($iSecond, '%M', true);
261 261
 	}
262 262
     else if ($format == 'sec')	// only sec part
263 263
     {
264
-        $sTime=dol_print_date($iSecond,'%S',true);
264
+        $sTime = dol_print_date($iSecond, '%S', true);
265 265
     }
266 266
     else if ($format == 'month')	// only month part
267 267
     {
268
-        $sTime=dol_print_date($iSecond,'%m',true);
268
+        $sTime = dol_print_date($iSecond, '%m', true);
269 269
     }
270 270
     else if ($format == 'year')	// only year part
271 271
     {
272
-        $sTime=dol_print_date($iSecond,'%Y',true);
272
+        $sTime = dol_print_date($iSecond, '%Y', true);
273 273
     }
274 274
     return trim($sTime);
275 275
 }
@@ -287,19 +287,19 @@  discard block
 block discarded – undo
287 287
 function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date)
288 288
 {
289 289
 	global $db;
290
-	$sqldate="";
290
+	$sqldate = "";
291 291
 	if ($month_date > 0) {
292 292
 		if ($year_date > 0 && empty($day_date)) {
293
-			$sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, $month_date, false));
294
-			$sqldate.= "' AND '".$db->idate(dol_get_last_day($year_date, $month_date, false))."'";
295
-		} else if ($year_date > 0 && ! empty($day_date)) {
296
-			$sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_date, $day_date, $year_date));
297
-			$sqldate.= "' AND '".$db->idate(dol_mktime(23, 59, 59, $month_date, $day_date, $year_date))."'";
293
+			$sqldate .= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, $month_date, false));
294
+			$sqldate .= "' AND '".$db->idate(dol_get_last_day($year_date, $month_date, false))."'";
295
+		} else if ($year_date > 0 && !empty($day_date)) {
296
+			$sqldate .= " AND ".$datefield." BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_date, $day_date, $year_date));
297
+			$sqldate .= "' AND '".$db->idate(dol_mktime(23, 59, 59, $month_date, $day_date, $year_date))."'";
298 298
 		} else
299
-			$sqldate.= " AND date_format( ".$datefield.", '%m') = '".$db->escape($month_date)."'";
300
-	} else if ($year_date > 0){
301
-		$sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, 1, false));
302
-		$sqldate.= "' AND '".$db->idate(dol_get_last_day($year_date, 12, false))."'";
299
+			$sqldate .= " AND date_format( ".$datefield.", '%m') = '".$db->escape($month_date)."'";
300
+	} else if ($year_date > 0) {
301
+		$sqldate .= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, 1, false));
302
+		$sqldate .= "' AND '".$db->idate(dol_get_last_day($year_date, 12, false))."'";
303 303
 	}
304 304
 	return $sqldate;
305 305
 }
@@ -322,10 +322,10 @@  discard block
 block discarded – undo
322 322
  *
323 323
  *  @see    dol_print_date, dol_mktime, dol_getdate
324 324
  */
325
-function dol_stringtotime($string, $gm=1)
325
+function dol_stringtotime($string, $gm = 1)
326 326
 {
327 327
     // Convert date with format DD/MM/YYY HH:MM:SS. This part of code should not be used.
328
-    if (preg_match('/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i',$string,$reg))
328
+    if (preg_match('/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $string, $reg))
329 329
     {
330 330
         dol_syslog("dol_stringtotime call to function with deprecated parameter format", LOG_WARNING);
331 331
         // Date est au format 'DD/MM/YY' ou 'DD/MM/YY HH:MM:SS'
@@ -336,14 +336,14 @@  discard block
 block discarded – undo
336 336
         $shour = $reg[4];
337 337
         $smin = $reg[5];
338 338
         $ssec = $reg[6];
339
-        if ($syear < 50) $syear+=1900;
340
-        if ($syear >= 50 && $syear < 100) $syear+=2000;
341
-        $string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec);
339
+        if ($syear < 50) $syear += 1900;
340
+        if ($syear >= 50 && $syear < 100) $syear += 2000;
341
+        $string = sprintf("%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
342 342
     }
343 343
     else if (
344
-    	   preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/i',$string,$reg)	// Convert date with format YYYY-MM-DDTHH:MM:SSZ (RFC3339)
345
-    	|| preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i',$string,$reg)	// Convert date with format YYYY-MM-DD HH:MM:SS
346
-   		|| preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/i',$string,$reg)		// Convert date with format YYYYMMDDTHHMMSSZ
344
+    	   preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/i', $string, $reg)	// Convert date with format YYYY-MM-DDTHH:MM:SSZ (RFC3339)
345
+    	|| preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i', $string, $reg)	// Convert date with format YYYY-MM-DD HH:MM:SS
346
+   		|| preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/i', $string, $reg)		// Convert date with format YYYYMMDDTHHMMSSZ
347 347
     )
348 348
     {
349 349
         $syear = $reg[1];
@@ -352,12 +352,12 @@  discard block
 block discarded – undo
352 352
         $shour = $reg[4];
353 353
         $smin = $reg[5];
354 354
         $ssec = $reg[6];
355
-        $string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec);
355
+        $string = sprintf("%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec);
356 356
     }
357 357
 
358
-    $string=preg_replace('/([^0-9])/i','',$string);
359
-    $tmp=$string.'000000';
360
-    $date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),($gm?1:0));
358
+    $string = preg_replace('/([^0-9])/i', '', $string);
359
+    $tmp = $string.'000000';
360
+    $date = dol_mktime(substr($tmp, 8, 2), substr($tmp, 10, 2), substr($tmp, 12, 2), substr($tmp, 4, 2), substr($tmp, 6, 2), substr($tmp, 0, 4), ($gm ? 1 : 0));
361 361
     return $date;
362 362
 }
363 363
 
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
  */
372 372
 function dol_get_prev_day($day, $month, $year)
373 373
 {
374
-	$time=dol_mktime(12,0,0,$month,$day,$year,1,0);
375
-	$time-=24*60*60;
376
-	$tmparray=dol_getdate($time,true);
374
+	$time = dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
375
+	$time -= 24 * 60 * 60;
376
+	$tmparray = dol_getdate($time, true);
377 377
 	return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
378 378
 }
379 379
 
@@ -386,9 +386,9 @@  discard block
 block discarded – undo
386 386
  */
387 387
 function dol_get_next_day($day, $month, $year)
388 388
 {
389
-	$time=dol_mktime(12,0,0,$month,$day,$year,1,0);
390
-	$time+=24*60*60;
391
-	$tmparray=dol_getdate($time,true);
389
+	$time = dol_mktime(12, 0, 0, $month, $day, $year, 1, 0);
390
+	$time += 24 * 60 * 60;
391
+	$tmparray = dol_getdate($time, true);
392 392
 	return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
393 393
 }
394 394
 
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 	}
408 408
 	else
409 409
 	{
410
-		$prev_month = $month-1;
410
+		$prev_month = $month - 1;
411 411
 		$prev_year  = $year;
412 412
 	}
413 413
 	return array('year' => $prev_year, 'month' => $prev_month);
@@ -446,9 +446,9 @@  discard block
 block discarded – undo
446 446
 {
447 447
 	$tmparray = dol_get_first_day_week($day, $month, $year);
448 448
 
449
-	$time=dol_mktime(12,0,0,$month,$tmparray['first_day'],$year,1,0);
450
-	$time-=24*60*60*7;
451
-	$tmparray=dol_getdate($time,true);
449
+	$time = dol_mktime(12, 0, 0, $month, $tmparray['first_day'], $year, 1, 0);
450
+	$time -= 24 * 60 * 60 * 7;
451
+	$tmparray = dol_getdate($time, true);
452 452
 	return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
453 453
 }
454 454
 
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 {
465 465
 	$tmparray = dol_get_first_day_week($day, $month, $year);
466 466
 
467
-	$time=dol_mktime(12,0,0,$tmparray['first_month'],$tmparray['first_day'],$tmparray['first_year'],1,0);
468
-	$time+=24*60*60*7;
469
-	$tmparray=dol_getdate($time,true);
467
+	$time = dol_mktime(12, 0, 0, $tmparray['first_month'], $tmparray['first_day'], $tmparray['first_year'], 1, 0);
468
+	$time += 24 * 60 * 60 * 7;
469
+	$tmparray = dol_getdate($time, true);
470 470
 
471 471
 	return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
472 472
 }
@@ -480,10 +480,10 @@  discard block
 block discarded – undo
480 480
  *                          			Exemple: dol_get_first_day(1970,1,true) will return 0 whatever is TZ, after a dol_print_date will return 1970-01-01 00:00:00
481 481
  *  @return		int						Date for first day, '' if error
482 482
  */
483
-function dol_get_first_day($year,$month=1,$gm=false)
483
+function dol_get_first_day($year, $month = 1, $gm = false)
484 484
 {
485 485
 	if ($year > 9999) return '';
486
-	return dol_mktime(0,0,0,$month,1,$year,$gm);
486
+	return dol_mktime(0, 0, 0, $month, 1, $year, $gm);
487 487
 }
488 488
 
489 489
 
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
  * 	@param		boolean		$gm			False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
495 495
  *	@return		int						Date for first day, '' if error
496 496
  */
497
-function dol_get_last_day($year,$month=12,$gm=false)
497
+function dol_get_last_day($year, $month = 12, $gm = false)
498 498
 {
499 499
 	if ($year > 9999) return '';
500 500
 	if ($month == 12)
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 	}
509 509
 
510 510
 	// On se deplace au debut du mois suivant, et on retire un jour
511
-	$datelim=dol_mktime(23,59,59,$month,1,$year,$gm);
511
+	$datelim = dol_mktime(23, 59, 59, $month, 1, $year, $gm);
512 512
 	$datelim -= (3600 * 24);
513 513
 
514 514
 	return $datelim;
@@ -522,69 +522,69 @@  discard block
 block discarded – undo
522 522
  * 	@param		int		$gm			False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
523 523
  *	@return		array				year,month,week,first_day,first_month,first_year,prev_day,prev_month,prev_year
524 524
  */
525
-function dol_get_first_day_week($day,$month,$year,$gm=false)
525
+function dol_get_first_day_week($day, $month, $year, $gm = false)
526 526
 {
527 527
 	global $conf;
528 528
 
529 529
 	//$day=2; $month=2; $year=2015;
530
-	$date = dol_mktime(0,0,0,$month,$day,$year,$gm);
530
+	$date = dol_mktime(0, 0, 0, $month, $day, $year, $gm);
531 531
 
532 532
 	//Checking conf of start week
533
-	$start_week = (isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1);
533
+	$start_week = (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1);
534 534
 
535
-	$tmparray = dol_getdate($date,true);	// detail of current day
535
+	$tmparray = dol_getdate($date, true); // detail of current day
536 536
 
537 537
 	//Calculate days = offset from current day
538 538
 	$days = $start_week - $tmparray['wday'];
539
- 	if ($days>=1) $days=7-$days;
539
+ 	if ($days >= 1) $days = 7 - $days;
540 540
  	$days = abs($days);
541
-    $seconds = $days*24*60*60;
541
+    $seconds = $days * 24 * 60 * 60;
542 542
 	//print 'start_week='.$start_week.' tmparray[wday]='.$tmparray['wday'].' day offset='.$days.' seconds offset='.$seconds.'<br>';
543 543
 
544 544
     //Get first day of week
545
-    $tmpdaytms = date($tmparray[0])-$seconds; // $tmparray[0] is day of parameters
546
-	$tmpday = date("d",$tmpdaytms);
545
+    $tmpdaytms = date($tmparray[0]) - $seconds; // $tmparray[0] is day of parameters
546
+	$tmpday = date("d", $tmpdaytms);
547 547
 
548 548
 	//Check first day of week is in same month than current day or not
549
-	if ($tmpday>$day)
549
+	if ($tmpday > $day)
550 550
     {
551
-    	$prev_month = $month-1;
552
-		$prev_year  = $year;
551
+    	$prev_month = $month - 1;
552
+		$prev_year = $year;
553 553
 
554
-    	if ($prev_month==0)
554
+    	if ($prev_month == 0)
555 555
     	{
556 556
     		$prev_month = 12;
557
-    		$prev_year  = $year-1;
557
+    		$prev_year  = $year - 1;
558 558
     	}
559 559
     }
560 560
     else
561 561
     {
562 562
     	$prev_month = $month;
563
-		$prev_year  = $year;
563
+		$prev_year = $year;
564 564
     }
565 565
 	$tmpmonth = $prev_month;
566 566
 	$tmpyear = $prev_year;
567 567
 
568 568
 	//Get first day of next week
569
-	$tmptime=dol_mktime(12,0,0,$month,$tmpday,$year,1,0);
570
-	$tmptime-=24*60*60*7;
571
-	$tmparray=dol_getdate($tmptime,true);
572
-    $prev_day   = $tmparray['mday'];
569
+	$tmptime = dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0);
570
+	$tmptime -= 24 * 60 * 60 * 7;
571
+	$tmparray = dol_getdate($tmptime, true);
572
+    $prev_day = $tmparray['mday'];
573 573
 
574 574
     //Check prev day of week is in same month than first day or not
575 575
 	if ($prev_day > $tmpday)
576 576
     {
577
-    	$prev_month = $month-1;
578
-		$prev_year  = $year;
577
+    	$prev_month = $month - 1;
578
+		$prev_year = $year;
579 579
 
580
-    	if ($prev_month==0)
580
+    	if ($prev_month == 0)
581 581
     	{
582 582
     		$prev_month = 12;
583
-    		$prev_year  = $year-1;
583
+    		$prev_year  = $year - 1;
584 584
     	}
585 585
     }
586 586
 
587
-    $week = date("W",dol_mktime(0,0,0,$tmpmonth,$tmpday,$tmpyear,$gm));
587
+    $week = date("W", dol_mktime(0, 0, 0, $tmpmonth, $tmpday, $tmpyear, $gm));
588 588
 
589 589
 	return array('year' => $year, 'month' => $month, 'week' => $week, 'first_day' => $tmpday, 'first_month' => $tmpmonth, 'first_year' => $tmpyear, 'prev_year' => $prev_year, 'prev_month' => $prev_month, 'prev_day' => $prev_day);
590 590
 }
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
  *	@return   	int								Nombre de jours feries
601 601
  *  @see num_between_day, num_open_day
602 602
  */
603
-function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR', $lastday=0)
603
+function num_public_holiday($timestampStart, $timestampEnd, $countrycode = 'FR', $lastday = 0)
604 604
 {
605 605
 	global $conf;
606 606
 
@@ -609,13 +609,13 @@  discard block
 block discarded – undo
609 609
 	// Check to ensure we use correct parameters
610 610
 	if ((($timestampEnd - $timestampStart) % 86400) != 0) return 'ErrorDates must use same hours and must be GMT dates';
611 611
 
612
-	$i=0;
613
-	while (( ($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd) )
612
+	$i = 0;
613
+	while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd))
614 614
 	    && ($i < 50000))		// Loop end when equals (Test on i is a security loop to avoid infinite loop)
615 615
 	{
616
-		$ferie=false;
617
-		$countryfound=0;
618
-		$includesaturdayandsunday=1;
616
+		$ferie = false;
617
+		$countryfound = 0;
618
+		$includesaturdayandsunday = 1;
619 619
 
620 620
 		$jour  = date("d", $timestampStart);
621 621
 		$mois  = date("m", $timestampStart);
@@ -623,42 +623,42 @@  discard block
 block discarded – undo
623 623
 
624 624
 
625 625
 		// Check into var $conf->global->HOLIDAY_MORE_DAYS   MM-DD,YYYY-MM-DD, ...
626
-		if (! empty($conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS))
626
+		if (!empty($conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS))
627 627
 		{
628
-			$arrayofdaystring=explode(',',$conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS);
629
-			foreach($arrayofdaystring as $daystring)
628
+			$arrayofdaystring = explode(',', $conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS);
629
+			foreach ($arrayofdaystring as $daystring)
630 630
 			{
631
-				$tmp=explode('-',$daystring);
631
+				$tmp = explode('-', $daystring);
632 632
 				if ($tmp[2])
633 633
 				{
634
-					if ($tmp[0] == $annee && $tmp[1] == $mois && $tmp[2] == $jour) $ferie=true;
634
+					if ($tmp[0] == $annee && $tmp[1] == $mois && $tmp[2] == $jour) $ferie = true;
635 635
 				}
636 636
 				else
637 637
 				{
638
-					if ($tmp[0] == $mois && $tmp[1] == $jour) $ferie=true;
638
+					if ($tmp[0] == $mois && $tmp[1] == $jour) $ferie = true;
639 639
 				}
640 640
 			}
641 641
 		}
642 642
 
643 643
 		if ($countrycode == 'FR')
644 644
 		{
645
-			$countryfound=1;
645
+			$countryfound = 1;
646 646
 
647 647
 			// Definition of fixed working days
648
-			if($jour == 1 && $mois == 1)   $ferie=true; // 1er january
649
-			if($jour == 1 && $mois == 5)   $ferie=true; // 1er may
650
-			if($jour == 8 && $mois == 5)   $ferie=true; // 5 may
651
-			if($jour == 14 && $mois == 7)  $ferie=true; // 14 july
652
-			if($jour == 15 && $mois == 8)  $ferie=true; // 15 august
653
-			if($jour == 1 && $mois == 11)  $ferie=true; // 1 november
654
-			if($jour == 11 && $mois == 11) $ferie=true; // 11 november
655
-			if($jour == 25 && $mois == 12) $ferie=true; // 25 december
648
+			if ($jour == 1 && $mois == 1)   $ferie = true; // 1er january
649
+			if ($jour == 1 && $mois == 5)   $ferie = true; // 1er may
650
+			if ($jour == 8 && $mois == 5)   $ferie = true; // 5 may
651
+			if ($jour == 14 && $mois == 7)  $ferie = true; // 14 july
652
+			if ($jour == 15 && $mois == 8)  $ferie = true; // 15 august
653
+			if ($jour == 1 && $mois == 11)  $ferie = true; // 1 november
654
+			if ($jour == 11 && $mois == 11) $ferie = true; // 11 november
655
+			if ($jour == 25 && $mois == 12) $ferie = true; // 25 december
656 656
 
657 657
 			// Calculation for easter date
658 658
 			$date_paques = easter_date($annee);
659 659
 			$jour_paques = date("d", $date_paques);
660 660
 			$mois_paques = date("m", $date_paques);
661
-			if($jour_paques == $jour && $mois_paques == $mois) $ferie=true;
661
+			if ($jour_paques == $jour && $mois_paques == $mois) $ferie = true;
662 662
 			// Pâques
663 663
 
664 664
 			// Calculation for the monday of easter date
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
             );
673 673
 			$jour_lundi_ascension = date("d", $date_lundi_paques);
674 674
 			$mois_lundi_ascension = date("m", $date_lundi_paques);
675
-			if($jour_lundi_ascension == $jour && $mois_lundi_ascension == $mois) $ferie=true;
675
+			if ($jour_lundi_ascension == $jour && $mois_lundi_ascension == $mois) $ferie = true;
676 676
 			// Lundi de Pâques
677 677
 
678 678
 			// Calcul du jour de l'ascension (38 days after easter day)
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
             );
687 687
 			$jour_ascension = date("d", $date_ascension);
688 688
 			$mois_ascension = date("m", $date_ascension);
689
-			if($jour_ascension == $jour && $mois_ascension == $mois) $ferie=true;
689
+			if ($jour_ascension == $jour && $mois_ascension == $mois) $ferie = true;
690 690
 			// Ascension
691 691
 
692 692
 			// Calculation of "Pentecote" (11 days after easter day)
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
             );
701 701
 			$jour_pentecote = date("d", $date_pentecote);
702 702
 			$mois_pentecote = date("m", $date_pentecote);
703
-			if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true;
703
+			if ($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie = true;
704 704
 			// "Pentecote"
705 705
 		}
706 706
 
@@ -708,60 +708,60 @@  discard block
 block discarded – undo
708 708
 		// Pentecoste is 50 days after Easter, Ascensione 40
709 709
 		if ($countrycode == 'IT')
710 710
 		{
711
-			$countryfound=1;
711
+			$countryfound = 1;
712 712
 
713 713
 			// Definition des dates feriees fixes
714
-			if($jour == 1 && $mois == 1) $ferie=true; // Capodanno
715
-			if($jour == 6 && $mois == 1) $ferie=true; // Epifania
716
-			if($jour == 25 && $mois == 4) $ferie=true; // Anniversario Liberazione
717
-			if($jour == 1 && $mois == 5) $ferie=true; // Festa del Lavoro
718
-			if($jour == 2 && $mois == 6) $ferie=true; // Festa della Repubblica
719
-			if($jour == 15 && $mois == 8) $ferie=true; // Ferragosto
720
-			if($jour == 1 && $mois == 11) $ferie=true; // Tutti i Santi
721
-			if($jour == 8 && $mois == 12) $ferie=true; // Immacolata Concezione
722
-			if($jour == 25 && $mois == 12) $ferie=true; // 25 decembre
723
-			if($jour == 26 && $mois == 12) $ferie=true; // Santo Stefano
714
+			if ($jour == 1 && $mois == 1) $ferie = true; // Capodanno
715
+			if ($jour == 6 && $mois == 1) $ferie = true; // Epifania
716
+			if ($jour == 25 && $mois == 4) $ferie = true; // Anniversario Liberazione
717
+			if ($jour == 1 && $mois == 5) $ferie = true; // Festa del Lavoro
718
+			if ($jour == 2 && $mois == 6) $ferie = true; // Festa della Repubblica
719
+			if ($jour == 15 && $mois == 8) $ferie = true; // Ferragosto
720
+			if ($jour == 1 && $mois == 11) $ferie = true; // Tutti i Santi
721
+			if ($jour == 8 && $mois == 12) $ferie = true; // Immacolata Concezione
722
+			if ($jour == 25 && $mois == 12) $ferie = true; // 25 decembre
723
+			if ($jour == 26 && $mois == 12) $ferie = true; // Santo Stefano
724 724
 
725 725
 			// Calcul du jour de paques
726 726
 			$date_paques = easter_date($annee);
727 727
 			$jour_paques = date("d", $date_paques);
728 728
 			$mois_paques = date("m", $date_paques);
729
-			if($jour_paques == $jour && $mois_paques == $mois) $ferie=true;
729
+			if ($jour_paques == $jour && $mois_paques == $mois) $ferie = true;
730 730
 			// Paques
731 731
 		}
732 732
 
733 733
 		if ($countrycode == 'IN')
734 734
 		{
735
-			$countryfound=1;
736
-
737
-			if($jour == 1 && $mois == 1) $ferie=true; // New Year's Day
738
-			if($jour == 26 && $mois == 1) $ferie=true; // Republic Day
739
-			if($jour == 1 && $mois == 5) $ferie=true; // May Day
740
-			if($jour == 15 && $mois == 8) $ferie=true; // Independence Day
741
-			if($jour == 2 && $mois == 10) $ferie=true; // Gandhi Jayanti
742
-			if($jour == 25 && $mois == 12) $ferie=true; // Christmas
735
+			$countryfound = 1;
736
+
737
+			if ($jour == 1 && $mois == 1) $ferie = true; // New Year's Day
738
+			if ($jour == 26 && $mois == 1) $ferie = true; // Republic Day
739
+			if ($jour == 1 && $mois == 5) $ferie = true; // May Day
740
+			if ($jour == 15 && $mois == 8) $ferie = true; // Independence Day
741
+			if ($jour == 2 && $mois == 10) $ferie = true; // Gandhi Jayanti
742
+			if ($jour == 25 && $mois == 12) $ferie = true; // Christmas
743 743
 		}
744 744
 
745 745
 		if ($countrycode == 'ES')
746 746
 		{
747
-			$countryfound=1;
747
+			$countryfound = 1;
748 748
 
749 749
 			// Definition des dates feriees fixes
750
-			if($jour == 1 && $mois == 1)   $ferie=true; // Año nuevo
751
-			if($jour == 6 && $mois == 1)   $ferie=true; // Día Reyes
752
-			if($jour == 1 && $mois == 5)   $ferie=true; // 1 Mayo
753
-			if($jour == 15 && $mois == 8)  $ferie=true; // 15 Agosto
754
-			if($jour == 12 && $mois == 10)  $ferie=true; // Día Hispanidad
755
-			if($jour == 1 && $mois == 11)  $ferie=true; // 1 noviembre
756
-			if($jour == 6 && $mois == 12) $ferie=true; // Constitución
757
-			if($jour == 8 && $mois == 12)  $ferie=true; // Inmaculada
758
-			if($jour == 25 && $mois == 12) $ferie=true; // 25 diciembre
750
+			if ($jour == 1 && $mois == 1)   $ferie = true; // Año nuevo
751
+			if ($jour == 6 && $mois == 1)   $ferie = true; // Día Reyes
752
+			if ($jour == 1 && $mois == 5)   $ferie = true; // 1 Mayo
753
+			if ($jour == 15 && $mois == 8)  $ferie = true; // 15 Agosto
754
+			if ($jour == 12 && $mois == 10)  $ferie = true; // Día Hispanidad
755
+			if ($jour == 1 && $mois == 11)  $ferie = true; // 1 noviembre
756
+			if ($jour == 6 && $mois == 12) $ferie = true; // Constitución
757
+			if ($jour == 8 && $mois == 12)  $ferie = true; // Inmaculada
758
+			if ($jour == 25 && $mois == 12) $ferie = true; // 25 diciembre
759 759
 
760 760
 			// Calcul día de Pascua
761 761
 			$date_paques = easter_date($annee);
762 762
 			$jour_paques = date("d", $date_paques);
763 763
 			$mois_paques = date("m", $date_paques);
764
-			if($jour_paques == $jour && $mois_paques == $mois) $ferie=true;
764
+			if ($jour_paques == $jour && $mois_paques == $mois) $ferie = true;
765 765
 			// Paques
766 766
 
767 767
 			// Viernes Santo
@@ -770,37 +770,37 @@  discard block
 block discarded – undo
770 770
                 date("i", $date_paques),
771 771
                 date("s", $date_paques),
772 772
                 date("m", $date_paques),
773
-                date("d", $date_paques) -2,
773
+                date("d", $date_paques) - 2,
774 774
                 date("Y", $date_paques)
775 775
             );
776 776
 			$jour_viernes = date("d", $date_viernes);
777 777
 			$mois_viernes = date("m", $date_viernes);
778
-			if($jour_viernes == $jour && $mois_viernes == $mois) $ferie=true;
778
+			if ($jour_viernes == $jour && $mois_viernes == $mois) $ferie = true;
779 779
 			//Viernes Santo
780 780
 		}
781 781
 
782 782
 		if ($countrycode == 'AT')
783 783
 		{
784
-		    $countryfound=1;
784
+		    $countryfound = 1;
785 785
 
786 786
 		    // Definition des dates feriees fixes
787
-		    if($jour == 1 && $mois == 1)   $ferie=true; // Neujahr
788
-		    if($jour == 6 && $mois == 1)   $ferie=true; // Hl. 3 Koenige
789
-		    if($jour == 1 && $mois == 5)   $ferie=true; // 1. Mai
790
-		    if($jour == 15 && $mois == 8)  $ferie=true; // Mariae Himmelfahrt
791
-		    if($jour == 26 && $mois == 10) $ferie=true; // 26. Oktober
792
-		    if($jour == 1 && $mois == 11)  $ferie=true; // Allerheiligen
793
-		    if($jour == 8 && $mois == 12)  $ferie=true; // Mariae Empfaengnis
794
-		    if($jour == 24 && $mois == 12) $ferie=true; // Heilig abend
795
-		    if($jour == 25 && $mois == 12) $ferie=true; // Christtag
796
-		    if($jour == 26 && $mois == 12) $ferie=true; // Stefanietag
797
-		    if($jour == 31 && $mois == 12) $ferie=true; // Silvester
787
+		    if ($jour == 1 && $mois == 1)   $ferie = true; // Neujahr
788
+		    if ($jour == 6 && $mois == 1)   $ferie = true; // Hl. 3 Koenige
789
+		    if ($jour == 1 && $mois == 5)   $ferie = true; // 1. Mai
790
+		    if ($jour == 15 && $mois == 8)  $ferie = true; // Mariae Himmelfahrt
791
+		    if ($jour == 26 && $mois == 10) $ferie = true; // 26. Oktober
792
+		    if ($jour == 1 && $mois == 11)  $ferie = true; // Allerheiligen
793
+		    if ($jour == 8 && $mois == 12)  $ferie = true; // Mariae Empfaengnis
794
+		    if ($jour == 24 && $mois == 12) $ferie = true; // Heilig abend
795
+		    if ($jour == 25 && $mois == 12) $ferie = true; // Christtag
796
+		    if ($jour == 26 && $mois == 12) $ferie = true; // Stefanietag
797
+		    if ($jour == 31 && $mois == 12) $ferie = true; // Silvester
798 798
 
799 799
 		    // Easter calculation
800 800
 		    $date_paques = easter_date($annee);
801 801
 		    $jour_paques = date("d", $date_paques);
802 802
 		    $mois_paques = date("m", $date_paques);
803
-		    if($jour_paques == $jour && $mois_paques == $mois) $ferie=true;
803
+		    if ($jour_paques == $jour && $mois_paques == $mois) $ferie = true;
804 804
 		    // Easter sunday
805 805
 
806 806
 		    // Monday after easter
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
 		        );
815 815
 		    $jour_eastermonday = date("d", $date_eastermonday);
816 816
 		    $mois_eastermonday = date("m", $date_eastermonday);
817
-		    if($jour_eastermonday == $jour && $mois_eastermonday == $mois) $ferie=true;
817
+		    if ($jour_eastermonday == $jour && $mois_eastermonday == $mois) $ferie = true;
818 818
 		    // Easter monday
819 819
 
820 820
 		    // Christi Himmelfahrt (39 days after easter sunday)
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
 		        );
829 829
 		    $jour_ch = date("d", $date_ch);
830 830
 		    $mois_ch = date("m", $date_ch);
831
-		    if($jour_ch == $jour && $mois_ch == $mois) $ferie=true;
831
+		    if ($jour_ch == $jour && $mois_ch == $mois) $ferie = true;
832 832
 		    // Christi Himmelfahrt
833 833
 
834 834
 		    // Pfingsten (50 days after easter sunday)
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 		        );
843 843
 		    $jour_pentecote = date("d", $date_pentecote);
844 844
 		    $mois_pentecote = date("m", $date_pentecote);
845
-		    if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true;
845
+		    if ($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie = true;
846 846
 		    // Pfingsten
847 847
 
848 848
 		    // Fronleichnam (60 days after easter sunday)
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
 		        );
857 857
 		    $jour_fronleichnam = date("d", $date_fronleichnam);
858 858
 		    $mois_fronleichnam = date("m", $date_fronleichnam);
859
-		    if($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) $ferie=true;
859
+		    if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) $ferie = true;
860 860
 		    // Fronleichnam
861 861
 		}
862 862
 
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 		{
866 866
 			$jour_julien = unixtojd($timestampStart);
867 867
 			$jour_semaine = jddayofweek($jour_julien, 0);
868
-			if($jour_semaine == 0 || $jour_semaine == 6) $ferie=true;
868
+			if ($jour_semaine == 0 || $jour_semaine == 6) $ferie = true;
869 869
 			//Saturday (6) and Sunday (0)
870 870
 		}
871 871
 
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
 		if ($ferie) $nbFerie++;
874 874
 
875 875
 		// Increase number of days (on go up into loop)
876
-		$timestampStart=dol_time_plus_duree($timestampStart, 1, 'd');
876
+		$timestampStart = dol_time_plus_duree($timestampStart, 1, 'd');
877 877
 		//var_dump($jour.' '.$mois.' '.$annee.' '.$timestampStart);
878 878
 
879 879
 		$i++;
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
  *	@return    int								Number of days
893 893
  *  @see also num_public_holiday, num_open_day
894 894
  */
895
-function num_between_day($timestampStart, $timestampEnd, $lastday=0)
895
+function num_between_day($timestampStart, $timestampEnd, $lastday = 0)
896 896
 {
897 897
 	if ($timestampStart < $timestampEnd)
898 898
 	{
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
 		{
905 905
 			$bit = 1;
906 906
 		}
907
-		$nbjours = (int) floor(($timestampEnd - $timestampStart)/(60*60*24)) + 1 - $bit;
907
+		$nbjours = (int) floor(($timestampEnd - $timestampStart) / (60 * 60 * 24)) + 1 - $bit;
908 908
 	}
909 909
 	//print ($timestampEnd - $timestampStart) - $lastday;
910 910
 	return $nbjours;
@@ -922,17 +922,17 @@  discard block
 block discarded – undo
922 922
  *	@return    	int								Number of days or hours
923 923
  *  @see also num_between_day, num_public_holiday
924 924
  */
925
-function num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $country_code='')
925
+function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0, $halfday = 0, $country_code = '')
926 926
 {
927
-	global $langs,$mysoc;
927
+	global $langs, $mysoc;
928 928
 
929
-	if (empty($country_code)) $country_code=$mysoc->country_code;
929
+	if (empty($country_code)) $country_code = $mysoc->country_code;
930 930
 
931 931
 	dol_syslog('num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday.' country_code='.$country_code);
932 932
 
933 933
 	// Check parameters
934
-	if (! is_int($timestampStart) && ! is_float($timestampStart)) return 'ErrorBadParameter_num_open_day';
935
-	if (! is_int($timestampEnd) && ! is_float($timestampEnd)) return 'ErrorBadParameter_num_open_day';
934
+	if (!is_int($timestampStart) && !is_float($timestampStart)) return 'ErrorBadParameter_num_open_day';
935
+	if (!is_int($timestampEnd) && !is_float($timestampEnd)) return 'ErrorBadParameter_num_open_day';
936 936
 
937 937
 	//print 'num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday;
938 938
 	if ($timestampStart < $timestampEnd)
@@ -940,14 +940,14 @@  discard block
 block discarded – undo
940 940
 		$numdays = num_between_day($timestampStart, $timestampEnd, $lastday);
941 941
 		$numholidays = num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday);
942 942
 		$nbOpenDay = $numdays - $numholidays;
943
-		$nbOpenDay.= " " . $langs->trans("Days");
944
-		if ($inhour == 1 && $nbOpenDay <= 3) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort");
943
+		$nbOpenDay .= " ".$langs->trans("Days");
944
+		if ($inhour == 1 && $nbOpenDay <= 3) $nbOpenDay = $nbOpenDay * 24.$langs->trans("HourShort");
945 945
 		return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
946 946
 	}
947 947
 	elseif ($timestampStart == $timestampEnd)
948 948
 	{
949
-		$nbOpenDay=$lastday;
950
-		if ($inhour == 1) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort");
949
+		$nbOpenDay = $lastday;
950
+		if ($inhour == 1) $nbOpenDay = $nbOpenDay * 24.$langs->trans("HourShort");
951 951
 		return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
952 952
 	}
953 953
 	else
@@ -966,9 +966,9 @@  discard block
 block discarded – undo
966 966
  *  @param	int			$short			0=Return long label, 1=Return short label
967 967
  *	@return array						Month string or array if selected < 0
968 968
  */
969
-function monthArray($outputlangs,$short=0)
969
+function monthArray($outputlangs, $short = 0)
970 970
 {
971
-	$montharray = array (
971
+	$montharray = array(
972 972
 	    1  => $outputlangs->trans("Month01"),
973 973
 	    2  => $outputlangs->trans("Month02"),
974 974
 	    3  => $outputlangs->trans("Month03"),
@@ -983,9 +983,9 @@  discard block
 block discarded – undo
983 983
 	    12 => $outputlangs->trans("Month12")
984 984
     );
985 985
 
986
-	if (! empty($short))
986
+	if (!empty($short))
987 987
 	{
988
-		$montharray = array (
988
+		$montharray = array(
989 989
 		    1  => $outputlangs->trans("MonthShort01"),
990 990
 		    2  => $outputlangs->trans("MonthShort02"),
991 991
 		    3  => $outputlangs->trans("MonthShort03"),
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/ecm.lib.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
 
37 37
 	$h = 0;
38 38
 	$head = array();
39
-    $helptext =$langs->trans("ECMAreaDesc").'<br>';
40
-    $helptext.=$langs->trans("ECMAreaDesc2");
39
+    $helptext = $langs->trans("ECMAreaDesc").'<br>';
40
+    $helptext .= $langs->trans("ECMAreaDesc2");
41 41
 
42 42
 	$head[$h][0] = DOL_URL_ROOT.'/ecm/index.php';
43 43
 	$head[$h][1] = $langs->trans("ECMSectionsManual").$form->textwithpicto('', $helptext, 1, 'info', '', 0, 3);
44 44
 	$head[$h][2] = 'index';
45 45
 	$h++;
46 46
 
47
-	if (! empty($conf->global->ECM_AUTO_TREE_ENABLED))
47
+	if (!empty($conf->global->ECM_AUTO_TREE_ENABLED))
48 48
 	{
49 49
 		$head[$h][0] = DOL_URL_ROOT.'/ecm/index_auto.php';
50 50
 		$head[$h][1] = $langs->trans("ECMSectionsAuto").$form->textwithpicto('', $helptext, 1, 'info', '', 0, 3);
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
     // Entries must be declared in modules descriptor with line
57 57
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
58 58
     // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to remove a tab
59
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'ecm');
59
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'ecm');
60 60
 
61
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'ecm','remove');
61
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'ecm', 'remove');
62 62
 
63 63
 	return $head;
64 64
 }
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
  * @param	string	$section	Section
73 73
  * @return  array				Array of tabs to show
74 74
  */
75
-function ecm_prepare_head($object, $module='ecm', $section='')
75
+function ecm_prepare_head($object, $module = 'ecm', $section = '')
76 76
 {
77 77
 	global $langs, $conf, $user;
78 78
 	$h = 0;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/functionsnumtoword.lib.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -33,18 +33,18 @@  discard block
 block discarded – undo
33 33
  * @param	boolean	$centimes		0=no centimes | 1=centimes to translate
34 34
  * @return 	string  				Text of the number
35 35
  */
36
-function dol_convertToWord($num, $langs, $currency=false, $centimes=false)
36
+function dol_convertToWord($num, $langs, $currency = false, $centimes = false)
37 37
 {
38 38
 	global $conf;
39 39
 
40 40
     $num = str_replace(array(',', ' '), '', trim($num));
41
-    if(! $num) {
41
+    if (!$num) {
42 42
         return false;
43 43
     }
44
-	if($centimes && strlen($num) == 1) {
45
-		$num = $num*10;
44
+	if ($centimes && strlen($num) == 1) {
45
+		$num = $num * 10;
46 46
 	}
47
-	$TNum = explode('.',$num);
47
+	$TNum = explode('.', $num);
48 48
     $num = (int) $TNum[0];
49 49
     $words = array();
50 50
     $list1 = array(
@@ -94,24 +94,24 @@  discard block
 block discarded – undo
94 94
     $num_length = strlen($num);
95 95
     $levels = (int) (($num_length + 2) / 3);
96 96
     $max_length = $levels * 3;
97
-    $num = substr('00' . $num, -$max_length);
97
+    $num = substr('00'.$num, -$max_length);
98 98
     $num_levels = str_split($num, 3);
99 99
     $nboflevels = count($num_levels);
100 100
     for ($i = 0; $i < $nboflevels; $i++) {
101 101
         $levels--;
102 102
         $hundreds = (int) ($num_levels[$i] / 100);
103
-        $hundreds = ($hundreds ? ' ' . $list1[$hundreds] . ' '.$langs->transnoentities('hundred') . ( $hundreds == 1 ? '' : 's' ) . ' ': '');
103
+        $hundreds = ($hundreds ? ' '.$list1[$hundreds].' '.$langs->transnoentities('hundred').($hundreds == 1 ? '' : 's').' ' : '');
104 104
         $tens = (int) ($num_levels[$i] % 100);
105 105
         $singles = '';
106
-        if ( $tens < 20 ) {
107
-            $tens = ($tens ? ' ' . $list1[$tens] . ' ' : '' );
106
+        if ($tens < 20) {
107
+            $tens = ($tens ? ' '.$list1[$tens].' ' : '');
108 108
         } else {
109 109
             $tens = (int) ($tens / 10);
110
-            $tens = ' ' . $list2[$tens] . ' ';
110
+            $tens = ' '.$list2[$tens].' ';
111 111
             $singles = (int) ($num_levels[$i] % 10);
112
-            $singles = ' ' . $list1[$singles] . ' ';
112
+            $singles = ' '.$list1[$singles].' ';
113 113
         }
114
-        $words[] = $hundreds . $tens . $singles . ( ( $levels && ( int ) ( $num_levels[$i] ) ) ? ' ' . $list3[$levels] . ' ' : '' );
114
+        $words[] = $hundreds.$tens.$singles.(($levels && (int) ($num_levels[$i])) ? ' '.$list3[$levels].' ' : '');
115 115
     } //end for loop
116 116
     $commas = count($words);
117 117
     if ($commas > 1) {
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
 	// Delete multi whitespaces
122 122
 	$concatWords = trim(preg_replace('/[ ]+/', ' ', $concatWords));
123 123
 
124
-	if(!empty($currency)) {
124
+	if (!empty($currency)) {
125 125
 		$concatWords .= ' '.$currency;
126 126
 	}
127 127
 
128 128
 	// If we need to write cents call again this function for cents
129
-	if(!empty($TNum[1])) {
130
-		if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('and');
129
+	if (!empty($TNum[1])) {
130
+		if (!empty($currency)) $concatWords .= ' '.$langs->transnoentities('and');
131 131
 		$concatWords .= ' '.dol_convertToWord($TNum[1], $langs, $currency, true);
132
-		if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('centimes');
132
+		if (!empty($currency)) $concatWords .= ' '.$langs->transnoentities('centimes');
133 133
 	}
134 134
     return $concatWords;
135 135
 }
@@ -144,61 +144,61 @@  discard block
 block discarded – undo
144 144
  * @param	string	$numorcurrency	'number' or 'amount'
145 145
  * @return 	string  				Text of the number or -1 in case TOO LONG (more than 1000000000000.99)
146 146
  */
147
-function dolNumberToWord($numero, $langs, $numorcurrency='number')
147
+function dolNumberToWord($numero, $langs, $numorcurrency = 'number')
148 148
 {
149 149
 	// If the number is negative convert to positive and return -1 if is too long
150 150
 	if ($numero < 0) $numero *= -1;
151 151
 	if ($numero >= 1000000000001)
152 152
 		return -1;
153 153
 	// Get 2 decimals to cents, another functions round or truncate
154
-	$strnumber = number_format ($numero,10);
155
-	$len=strlen($strnumber);
156
-	for ($i=0; $i<$len; $i++)
154
+	$strnumber = number_format($numero, 10);
155
+	$len = strlen($strnumber);
156
+	for ($i = 0; $i < $len; $i++)
157 157
 	{
158
-		if ($strnumber[$i]=='.') {
159
-			$parte_decimal = $strnumber[$i+1].$strnumber[$i+2];
158
+		if ($strnumber[$i] == '.') {
159
+			$parte_decimal = $strnumber[$i + 1].$strnumber[$i + 2];
160 160
 			break;
161 161
 		}
162 162
 	}
163 163
 
164 164
 	/*In dolibarr 3.6.2 (my current version) doesn't have $langs->default and
165 165
 	in case exist why ask $lang like a parameter?*/
166
-	if (((is_object($langs) && $langs->default == 'es_MX') || (! is_object($langs) && $langs == 'es_MX')) && $numorcurrency == 'currency')
166
+	if (((is_object($langs) && $langs->default == 'es_MX') || (!is_object($langs) && $langs == 'es_MX')) && $numorcurrency == 'currency')
167 167
 	{
168
-		if ($numero>=1 && $numero<2) {
168
+		if ($numero >= 1 && $numero < 2) {
169 169
 			return ("UN PESO ".$parte_decimal." / 100 M.N.");
170 170
 		}
171
-		elseif ($numero>=0 && $numero<1){
171
+		elseif ($numero >= 0 && $numero < 1) {
172 172
 			return ("CERO PESOS ".$parte_decimal." / 100 M.N.");
173 173
 		}
174
-		elseif ($numero>=1000000 && $numero<1000001){
174
+		elseif ($numero >= 1000000 && $numero < 1000001) {
175 175
 			return ("UN MILL&OacuteN DE PESOS ".$parte_decimal." / 100 M.N.");
176 176
 		}
177
-		elseif ($numero>=1000000000000 && $numero<1000000000001){
177
+		elseif ($numero >= 1000000000000 && $numero < 1000000000001) {
178 178
 			return ("UN BILL&OacuteN DE PESOS ".$parte_decimal." / 100 M.N.");
179 179
 		}
180 180
 		else {
181
-			$entexto ="";
181
+			$entexto = "";
182 182
 			$number = $numero;
183
-			if ($number >= 1000000000){
183
+			if ($number >= 1000000000) {
184 184
 				$CdMMillon = (int) ($numero / 100000000000);
185 185
 				$numero = $numero - $CdMMillon * 100000000000;
186 186
 				$DdMMillon = (int) ($numero / 10000000000);
187 187
 				$numero = $numero - $DdMMillon * 10000000000;
188 188
 				$UdMMillon = (int) ($numero / 1000000000);
189 189
 				$numero = $numero - $UdMMillon * 1000000000;
190
-				$entexto .= hundreds2text ($CdMMillon, $DdMMillon, $UdMMillon);
190
+				$entexto .= hundreds2text($CdMMillon, $DdMMillon, $UdMMillon);
191 191
 				$entexto .= " MIL ";
192 192
 			}
193
-			if ($number >= 1000000){
193
+			if ($number >= 1000000) {
194 194
 				$CdMILLON = (int) ($numero / 100000000);
195 195
 				$numero = $numero - $CdMILLON * 100000000;
196 196
 				$DdMILLON = (int) ($numero / 10000000);
197 197
 				$numero = $numero - $DdMILLON * 10000000;
198 198
 				$udMILLON = (int) ($numero / 1000000);
199 199
 				$numero = $numero - $udMILLON * 1000000;
200
-				$entexto .= hundreds2text ($CdMILLON, $DdMILLON, $udMILLON);
201
-				if (!$CdMMillon && !$DdMMillon && !$UdMMillon && !$CdMILLON && !$DdMILLON && $udMILLON==1)
200
+				$entexto .= hundreds2text($CdMILLON, $DdMILLON, $udMILLON);
201
+				if (!$CdMMillon && !$DdMMillon && !$UdMMillon && !$CdMILLON && !$DdMILLON && $udMILLON == 1)
202 202
 					$entexto .= " MILL&OacuteN ";
203 203
 				else
204 204
 					$entexto .= " MILLONES ";
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 				$numero = $numero - $ddm * 10000;
211 211
 				$udm = (int) ($numero / 1000);
212 212
 				$numero = $numero - $udm * 1000;
213
-				$entexto .= hundreds2text ($cdm, $ddm, $udm);
213
+				$entexto .= hundreds2text($cdm, $ddm, $udm);
214 214
 				if ($cdm || $ddm || $udm)
215 215
 					$entexto .= " MIL ";
216 216
 			}
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
 			$numero = $numero - $c * 100;
219 219
 			$d = (int) ($numero / 10);
220 220
 			$u = (int) $numero - $d * 10;
221
-			$entexto .= hundreds2text ($c, $d, $u);
222
-			if (!$cdm && !$ddm && !$udm && !$c && !$d && !$u && $number>1000000)
221
+			$entexto .= hundreds2text($c, $d, $u);
222
+			if (!$cdm && !$ddm && !$udm && !$c && !$d && !$u && $number > 1000000)
223 223
 				$entexto .= " DE";
224 224
 			$entexto .= " PESOS ".$parte_decimal." / 100 M.N.";
225 225
 		}
@@ -237,40 +237,40 @@  discard block
 block discarded – undo
237 237
  */
238 238
 function hundreds2text($hundreds, $tens, $units)
239 239
 {
240
-	if ($hundreds==1 && $tens==0 && $units==0){
240
+	if ($hundreds == 1 && $tens == 0 && $units == 0) {
241 241
 		return "CIEN";
242 242
 	}
243
-	$centenas = array("CIENTO","DOSCIENTOS","TRESCIENTOS","CUATROCIENTOS","QUINIENTOS","SEISCIENTOS","SETECIENTOS","OCHOCIENTOS","NOVECIENTOS");
244
-	$decenas = array("","","TREINTA ","CUARENTA ","CINCUENTA ","SESENTA ","SETENTA ","OCHENTA ","NOVENTA ");
245
-	$veintis = array("VEINTE","VEINTIUN","VEINTID&OacuteS","VEINTITR&EacuteS","VEINTICUATRO","VEINTICINCO","VEINTIS&EacuteIS","VEINTISIETE","VEINTIOCHO","VEINTINUEVE");
246
-	$diecis = array("DIEZ","ONCE","DOCE","TRECE","CATORCE","QUINCE","DIECIS&EacuteIS","DIECISIETE","DIECIOCHO","DIECINUEVE");
247
-    $unidades = array("UN","DOS","TRES","CUATRO","CINCO","SEIS","SIETE","OCHO","NUEVE");
243
+	$centenas = array("CIENTO", "DOSCIENTOS", "TRESCIENTOS", "CUATROCIENTOS", "QUINIENTOS", "SEISCIENTOS", "SETECIENTOS", "OCHOCIENTOS", "NOVECIENTOS");
244
+	$decenas = array("", "", "TREINTA ", "CUARENTA ", "CINCUENTA ", "SESENTA ", "SETENTA ", "OCHENTA ", "NOVENTA ");
245
+	$veintis = array("VEINTE", "VEINTIUN", "VEINTID&OacuteS", "VEINTITR&EacuteS", "VEINTICUATRO", "VEINTICINCO", "VEINTIS&EacuteIS", "VEINTISIETE", "VEINTIOCHO", "VEINTINUEVE");
246
+	$diecis = array("DIEZ", "ONCE", "DOCE", "TRECE", "CATORCE", "QUINCE", "DIECIS&EacuteIS", "DIECISIETE", "DIECIOCHO", "DIECINUEVE");
247
+    $unidades = array("UN", "DOS", "TRES", "CUATRO", "CINCO", "SEIS", "SIETE", "OCHO", "NUEVE");
248 248
 	$entexto = "";
249
-	if ($hundreds!=0){
250
-		$entexto .= $centenas[$hundreds-1];
249
+	if ($hundreds != 0) {
250
+		$entexto .= $centenas[$hundreds - 1];
251 251
 	}
252
-	if ($tens>2){
253
-		if ($hundreds!=0) $entexto .= " ";
254
-		$entexto .= $decenas[$tens-1];
255
-		if ($units!=0){
252
+	if ($tens > 2) {
253
+		if ($hundreds != 0) $entexto .= " ";
254
+		$entexto .= $decenas[$tens - 1];
255
+		if ($units != 0) {
256 256
 			$entexto .= " Y ";
257
-			$entexto .= $unidades[$units-1];
257
+			$entexto .= $unidades[$units - 1];
258 258
 		}
259 259
 		return $entexto;
260 260
 	}
261
-	elseif ($tens==2){
262
-		if ($hundreds!=0) $entexto .= " ";
261
+	elseif ($tens == 2) {
262
+		if ($hundreds != 0) $entexto .= " ";
263 263
 		$entexto .= " ".$veintis[$units];
264 264
 		return $entexto;
265 265
 	}
266
-	elseif ($tens==1){
267
-		if ($hundreds!=0) $entexto .= " ";
266
+	elseif ($tens == 1) {
267
+		if ($hundreds != 0) $entexto .= " ";
268 268
 		$entexto .= $diecis[$units];
269 269
 		return $entexto;
270 270
 	}
271
-	if ($units!=0) {
272
-		if ($hundreds!=0 || $tens!=0) $entexto .= " ";
273
-		$entexto .= $unidades[$units-1];
271
+	if ($units != 0) {
272
+		if ($hundreds != 0 || $tens != 0) $entexto .= " ";
273
+		$entexto .= $unidades[$units - 1];
274 274
 	}
275 275
 	return $entexto;
276 276
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/files.lib.php 1 patch
Spacing   +595 added lines, -595 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  */
35 35
 function dol_basename($pathfile)
36 36
 {
37
-	return preg_replace('/^.*\/([^\/]+)$/','$1',rtrim($pathfile,'/'));
37
+	return preg_replace('/^.*\/([^\/]+)$/', '$1', rtrim($pathfile, '/'));
38 38
 }
39 39
 
40 40
 /**
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
  *  @return	array						Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file',...)
57 57
  *  @see dol_dir_list_indatabase
58 58
  */
59
-function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
59
+function dol_dir_list($path, $types = "all", $recursive = 0, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0, $nohook = 0, $relativename = "", $donotfollowsymlinks = 0)
60 60
 {
61 61
 	global $db, $hookmanager;
62 62
 	global $object;
@@ -64,23 +64,23 @@  discard block
 block discarded – undo
64 64
 	dol_syslog("files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".json_encode($excludefilter));
65 65
 	//print 'xxx'."files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".json_encode($excludefilter);
66 66
 
67
-	$loaddate=($mode==1||$mode==2)?true:false;
68
-	$loadsize=($mode==1||$mode==3)?true:false;
67
+	$loaddate = ($mode == 1 || $mode == 2) ?true:false;
68
+	$loadsize = ($mode == 1 || $mode == 3) ?true:false;
69 69
 
70 70
 	// Clean parameters
71
-	$path=preg_replace('/([\\/]+)$/i','',$path);
72
-	$newpath=dol_osencode($path);
71
+	$path = preg_replace('/([\\/]+)$/i', '', $path);
72
+	$newpath = dol_osencode($path);
73 73
 
74 74
 	$reshook = 0;
75 75
 	$file_list = array();
76 76
 
77
-	if (is_object($hookmanager) && ! $nohook)
77
+	if (is_object($hookmanager) && !$nohook)
78 78
 	{
79
-		$hookmanager->resArray=array();
79
+		$hookmanager->resArray = array();
80 80
 
81 81
 		$hookmanager->initHooks(array('fileslib'));
82 82
 
83
-		$parameters=array(
83
+		$parameters = array(
84 84
 				'path' => $newpath,
85 85
 				'types'=> $types,
86 86
 				'recursive' => $recursive,
@@ -92,63 +92,63 @@  discard block
 block discarded – undo
92 92
 				'loadsize' => $loadsize,
93 93
 				'mode' => $mode
94 94
 		);
95
-		$reshook=$hookmanager->executeHooks('getDirList', $parameters, $object);
95
+		$reshook = $hookmanager->executeHooks('getDirList', $parameters, $object);
96 96
 	}
97 97
 
98 98
 	// $hookmanager->resArray may contain array stacked by other modules
99 99
 	if (empty($reshook))
100 100
 	{
101
-		if (! is_dir($newpath)) return array();
101
+		if (!is_dir($newpath)) return array();
102 102
 
103 103
 		if ($dir = opendir($newpath))
104 104
 		{
105
-			$filedate='';
106
-			$filesize='';
105
+			$filedate = '';
106
+			$filesize = '';
107 107
 
108 108
 			while (false !== ($file = readdir($dir)))        // $file is always a basename (into directory $newpath)
109 109
 			{
110
-				if (! utf8_check($file)) $file=utf8_encode($file);	// To be sure data is stored in utf8 in memory
111
-				$fullpathfile=($newpath?$newpath.'/':'').$file;
110
+				if (!utf8_check($file)) $file = utf8_encode($file); // To be sure data is stored in utf8 in memory
111
+				$fullpathfile = ($newpath ? $newpath.'/' : '').$file;
112 112
 
113
-				$qualified=1;
113
+				$qualified = 1;
114 114
 
115 115
 				// Define excludefilterarray
116
-				$excludefilterarray=array('^\.');
116
+				$excludefilterarray = array('^\.');
117 117
 				if (is_array($excludefilter))
118 118
 				{
119
-					$excludefilterarray=array_merge($excludefilterarray,$excludefilter);
119
+					$excludefilterarray = array_merge($excludefilterarray, $excludefilter);
120 120
 				}
121
-				else if ($excludefilter) $excludefilterarray[]=$excludefilter;
121
+				else if ($excludefilter) $excludefilterarray[] = $excludefilter;
122 122
 				// Check if file is qualified
123
-				foreach($excludefilterarray as $filt)
123
+				foreach ($excludefilterarray as $filt)
124 124
 				{
125 125
 					if (preg_match('/'.$filt.'/i', $file) || preg_match('/'.$filt.'/i', $fullpathfile)) {
126
-						$qualified=0; break;
126
+						$qualified = 0; break;
127 127
 					}
128 128
 				}
129 129
 				//print $fullpathfile.' '.$file.' '.$qualified.'<br>';
130 130
 
131 131
 				if ($qualified)
132 132
 				{
133
-					$isdir=is_dir(dol_osencode($path."/".$file));
133
+					$isdir = is_dir(dol_osencode($path."/".$file));
134 134
 					// Check whether this is a file or directory and whether we're interested in that type
135
-					if ($isdir && (($types=="directories") || ($types=="all") || $recursive))
135
+					if ($isdir && (($types == "directories") || ($types == "all") || $recursive))
136 136
 					{
137 137
 						// Add entry into file_list array
138
-						if (($types=="directories") || ($types=="all"))
138
+						if (($types == "directories") || ($types == "all"))
139 139
 						{
140
-							if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file);
141
-							if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file);
140
+							if ($loaddate || $sortcriteria == 'date') $filedate = dol_filemtime($path."/".$file);
141
+							if ($loadsize || $sortcriteria == 'size') $filesize = dol_filesize($path."/".$file);
142 142
 
143
-							if (! $filter || preg_match('/'.$filter.'/i',$file))	// We do not search key $filter into all $path, only into $file part
143
+							if (!$filter || preg_match('/'.$filter.'/i', $file))	// We do not search key $filter into all $path, only into $file part
144 144
 							{
145
-								preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg);
146
-								$level1name=(isset($reg[1])?$reg[1]:'');
145
+								preg_match('/([^\/]+)\/[^\/]+$/', $path.'/'.$file, $reg);
146
+								$level1name = (isset($reg[1]) ? $reg[1] : '');
147 147
 								$file_list[] = array(
148 148
 										"name" => $file,
149 149
 										"path" => $path,
150 150
 										"level1name" => $level1name,
151
-										"relativename" => ($relativename?$relativename.'/':'').$file,
151
+										"relativename" => ($relativename ? $relativename.'/' : '').$file,
152 152
 										"fullname" => $path.'/'.$file,
153 153
 										"date" => $filedate,
154 154
 										"size" => $filesize,
@@ -160,28 +160,28 @@  discard block
 block discarded – undo
160 160
 						// if we're in a directory and we want recursive behavior, call this function again
161 161
 						if ($recursive)
162 162
 						{
163
-							if (empty($donotfollowsymlinks) || ! is_link($path."/".$file))
163
+							if (empty($donotfollowsymlinks) || !is_link($path."/".$file))
164 164
 							{
165 165
 								//var_dump('eee '. $path."/".$file. ' '.is_dir($path."/".$file).' '.is_link($path."/".$file));
166
-								$file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename!=''?$relativename.'/':'').$file, $donotfollowsymlinks));
166
+								$file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename != '' ? $relativename.'/' : '').$file, $donotfollowsymlinks));
167 167
 							}
168 168
 						}
169 169
 					}
170
-					else if (! $isdir && (($types == "files") || ($types == "all")))
170
+					else if (!$isdir && (($types == "files") || ($types == "all")))
171 171
 					{
172 172
 						// Add file into file_list array
173
-						if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file);
174
-						if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file);
173
+						if ($loaddate || $sortcriteria == 'date') $filedate = dol_filemtime($path."/".$file);
174
+						if ($loadsize || $sortcriteria == 'size') $filesize = dol_filesize($path."/".$file);
175 175
 
176
-						if (! $filter || preg_match('/'.$filter.'/i',$file))	// We do not search key $filter into $path, only into $file
176
+						if (!$filter || preg_match('/'.$filter.'/i', $file))	// We do not search key $filter into $path, only into $file
177 177
 						{
178
-							preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg);
179
-							$level1name=(isset($reg[1])?$reg[1]:'');
178
+							preg_match('/([^\/]+)\/[^\/]+$/', $path.'/'.$file, $reg);
179
+							$level1name = (isset($reg[1]) ? $reg[1] : '');
180 180
 							$file_list[] = array(
181 181
 									"name" => $file,
182 182
 									"path" => $path,
183 183
 									"level1name" => $level1name,
184
-									"relativename" => ($relativename?$relativename.'/':'').$file,
184
+									"relativename" => ($relativename ? $relativename.'/' : '').$file,
185 185
 									"fullname" => $path.'/'.$file,
186 186
 									"date" => $filedate,
187 187
 									"size" => $filesize,
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
 			closedir($dir);
195 195
 
196 196
 			// Obtain a list of columns
197
-			if (! empty($sortcriteria))
197
+			if (!empty($sortcriteria))
198 198
 			{
199
-				$myarray=array();
199
+				$myarray = array();
200 200
 				foreach ($file_list as $key => $row)
201 201
 				{
202
-					$myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:'');
202
+					$myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] : '');
203 203
 				}
204 204
 				// Sort the data
205 205
 				if ($sortorder) array_multisort($myarray, $sortorder, $file_list);
@@ -226,21 +226,21 @@  discard block
 block discarded – undo
226 226
  *  @return	array						Array of array('name'=>'xxx','fullname'=>'/abc/xxx','type'=>'dir|file',...)
227 227
  *  @see dol_dir_list
228 228
  */
229
-function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0)
229
+function dol_dir_list_in_database($path, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0)
230 230
 {
231 231
 	global $conf, $db;
232 232
 
233
-	$sql =" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m,";
234
-	$sql.=" acl, position, share";
235
-	if ($mode) $sql.=", description";
236
-	$sql.=" FROM ".MAIN_DB_PREFIX."ecm_files";
237
-	$sql.=" WHERE filepath = '".$db->escape($path)."'";
238
-	$sql.=" AND entity = ".$conf->entity;
233
+	$sql = " SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m,";
234
+	$sql .= " acl, position, share";
235
+	if ($mode) $sql .= ", description";
236
+	$sql .= " FROM ".MAIN_DB_PREFIX."ecm_files";
237
+	$sql .= " WHERE filepath = '".$db->escape($path)."'";
238
+	$sql .= " AND entity = ".$conf->entity;
239 239
 
240 240
 	$resql = $db->query($sql);
241 241
 	if ($resql)
242 242
 	{
243
-		$file_list=array();
243
+		$file_list = array();
244 244
 		$num = $db->num_rows($resql);
245 245
 		$i = 0;
246 246
 		while ($i < $num)
@@ -248,11 +248,11 @@  discard block
 block discarded – undo
248 248
 			$obj = $db->fetch_object($resql);
249 249
 			if ($obj)
250 250
 			{
251
-				preg_match('/([^\/]+)\/[^\/]+$/',DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename,$reg);
252
-				$level1name=(isset($reg[1])?$reg[1]:'');
251
+				preg_match('/([^\/]+)\/[^\/]+$/', DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename, $reg);
252
+				$level1name = (isset($reg[1]) ? $reg[1] : '');
253 253
 				$file_list[] = array(
254 254
 					"rowid" => $obj->rowid,
255
-					"label" => $obj->label,         // md5
255
+					"label" => $obj->label, // md5
256 256
 					"name" => $obj->filename,
257 257
 					"path" => DOL_DATA_ROOT.'/'.$obj->filepath,
258 258
 					"level1name" => $level1name,
@@ -272,12 +272,12 @@  discard block
 block discarded – undo
272 272
 		}
273 273
 
274 274
 		// Obtain a list of columns
275
-		if (! empty($sortcriteria))
275
+		if (!empty($sortcriteria))
276 276
 		{
277
-			$myarray=array();
277
+			$myarray = array();
278 278
 			foreach ($file_list as $key => $row)
279 279
 			{
280
-				$myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:'');
280
+				$myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] : '');
281 281
 			}
282 282
 			// Sort the data
283 283
 			if ($sortorder) array_multisort($myarray, $sortorder, $file_list);
@@ -309,15 +309,15 @@  discard block
 block discarded – undo
309 309
 
310 310
 	// TODO Remove this when PRODUCT_USE_OLD_PATH_FOR_PHOTO will be removed
311 311
 	global $modulepart;
312
-	if ($modulepart == 'produit' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
312
+	if ($modulepart == 'produit' && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
313 313
 		global $object;
314
-		if (! empty($object->id))
314
+		if (!empty($object->id))
315 315
 		{
316
-			if (! empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos";
317
-			else $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos";
316
+			if (!empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos";
317
+			else $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos";
318 318
 
319
-			$relativedirold = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dirold);
320
-			$relativedirold = preg_replace('/^[\\/]/','',$relativedirold);
319
+			$relativedirold = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dirold);
320
+			$relativedirold = preg_replace('/^[\\/]/', '', $relativedirold);
321 321
 
322 322
 			$filearrayindatabase = array_merge($filearrayindatabase, dol_dir_list_in_database($relativedirold, '', null, 'name', SORT_ASC));
323 323
 		}
@@ -327,38 +327,38 @@  discard block
 block discarded – undo
327 327
 	//var_dump($filearrayindatabase);
328 328
 
329 329
 	// Complete filearray with properties found into $filearrayindatabase
330
-	foreach($filearray as $key => $val)
330
+	foreach ($filearray as $key => $val)
331 331
 	{
332
-		$found=0;
332
+		$found = 0;
333 333
 		// Search if it exists into $filearrayindatabase
334
-		foreach($filearrayindatabase as $key2 => $val2)
334
+		foreach ($filearrayindatabase as $key2 => $val2)
335 335
 		{
336 336
 			if ($filearrayindatabase[$key2]['name'] == $filearray[$key]['name'])
337 337
 			{
338
-				$filearray[$key]['position_name']=($filearrayindatabase[$key2]['position']?$filearrayindatabase[$key2]['position']:'0').'_'.$filearrayindatabase[$key2]['name'];
339
-				$filearray[$key]['position']=$filearrayindatabase[$key2]['position'];
340
-				$filearray[$key]['cover']=$filearrayindatabase[$key2]['cover'];
341
-				$filearray[$key]['acl']=$filearrayindatabase[$key2]['acl'];
342
-				$filearray[$key]['rowid']=$filearrayindatabase[$key2]['rowid'];
343
-				$filearray[$key]['label']=$filearrayindatabase[$key2]['label'];
344
-				$filearray[$key]['share']=$filearrayindatabase[$key2]['share'];
345
-				$found=1;
338
+				$filearray[$key]['position_name'] = ($filearrayindatabase[$key2]['position'] ? $filearrayindatabase[$key2]['position'] : '0').'_'.$filearrayindatabase[$key2]['name'];
339
+				$filearray[$key]['position'] = $filearrayindatabase[$key2]['position'];
340
+				$filearray[$key]['cover'] = $filearrayindatabase[$key2]['cover'];
341
+				$filearray[$key]['acl'] = $filearrayindatabase[$key2]['acl'];
342
+				$filearray[$key]['rowid'] = $filearrayindatabase[$key2]['rowid'];
343
+				$filearray[$key]['label'] = $filearrayindatabase[$key2]['label'];
344
+				$filearray[$key]['share'] = $filearrayindatabase[$key2]['share'];
345
+				$found = 1;
346 346
 				break;
347 347
 			}
348 348
 		}
349 349
 
350
-		if (! $found)    // This happen in transition toward version 6, or if files were added manually into os dir.
350
+		if (!$found)    // This happen in transition toward version 6, or if files were added manually into os dir.
351 351
 		{
352
-			$filearray[$key]['position']='999999';     // File not indexed are at end. So if we add a file, it will not replace an existing position
353
-			$filearray[$key]['cover']=0;
354
-			$filearray[$key]['acl']='';
352
+			$filearray[$key]['position'] = '999999'; // File not indexed are at end. So if we add a file, it will not replace an existing position
353
+			$filearray[$key]['cover'] = 0;
354
+			$filearray[$key]['acl'] = '';
355 355
 
356
-			$rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filearray[$key]['fullname']);
357
-			if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
356
+			$rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filearray[$key]['fullname']);
357
+			if (!preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
358 358
 			{
359 359
 				dol_syslog("list_of_documents We found a file called '".$filearray[$key]['name']."' not indexed into database. We add it");
360 360
 				include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
361
-				$ecmfile=new EcmFiles($db);
361
+				$ecmfile = new EcmFiles($db);
362 362
 
363 363
 				// Add entry into database
364 364
 				$filename = basename($rel_filename);
@@ -368,11 +368,11 @@  discard block
 block discarded – undo
368 368
 
369 369
 				$ecmfile->filepath = $rel_dir;
370 370
 				$ecmfile->filename = $filename;
371
-				$ecmfile->label = md5_file(dol_osencode($filearray[$key]['fullname']));        // $destfile is a full path to file
371
+				$ecmfile->label = md5_file(dol_osencode($filearray[$key]['fullname'])); // $destfile is a full path to file
372 372
 				$ecmfile->fullpath_orig = $filearray[$key]['fullname'];
373 373
 				$ecmfile->gen_or_uploaded = 'unknown';
374
-				$ecmfile->description = '';    // indexed content
375
-				$ecmfile->keyword = '';        // keyword content
374
+				$ecmfile->description = ''; // indexed content
375
+				$ecmfile->keyword = ''; // keyword content
376 376
 				$result = $ecmfile->create($user);
377 377
 				if ($result < 0)
378 378
 				{
@@ -380,12 +380,12 @@  discard block
 block discarded – undo
380 380
 				}
381 381
 				else
382 382
 				{
383
-					$filearray[$key]['rowid']=$result;
383
+					$filearray[$key]['rowid'] = $result;
384 384
 				}
385 385
 			}
386 386
 			else
387 387
 			{
388
-				$filearray[$key]['rowid']=0;     // Should not happened
388
+				$filearray[$key]['rowid'] = 0; // Should not happened
389 389
 			}
390 390
 		}
391 391
 	}
@@ -406,10 +406,10 @@  discard block
 block discarded – undo
406 406
 	global $sortorder;
407 407
 	global $sortfield;
408 408
 
409
-	$sortorder=strtoupper($sortorder);
409
+	$sortorder = strtoupper($sortorder);
410 410
 
411
-	if ($sortorder == 'ASC') { $retup=-1; $retdown=1; }
412
-	else { $retup=1; $retdown=-1; }
411
+	if ($sortorder == 'ASC') { $retup = -1; $retdown = 1; }
412
+	else { $retup = 1; $retdown = -1; }
413 413
 
414 414
 	if ($sortfield == 'name')
415 415
 	{
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
  */
438 438
 function dol_is_dir($folder)
439 439
 {
440
-	$newfolder=dol_osencode($folder);
440
+	$newfolder = dol_osencode($folder);
441 441
 	if (is_dir($newfolder)) return true;
442 442
 	else return false;
443 443
 }
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
  */
451 451
 function dol_is_file($pathoffile)
452 452
 {
453
-	$newpathoffile=dol_osencode($pathoffile);
453
+	$newpathoffile = dol_osencode($pathoffile);
454 454
 	return is_file($newpathoffile);
455 455
 }
456 456
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
  */
463 463
 function dol_is_link($pathoffile)
464 464
 {
465
-	$newpathoffile=dol_osencode($pathoffile);
465
+	$newpathoffile = dol_osencode($pathoffile);
466 466
 	return is_link($newpathoffile);
467 467
 }
468 468
 
@@ -474,10 +474,10 @@  discard block
 block discarded – undo
474 474
  */
475 475
 function dol_is_url($url)
476 476
 {
477
-	$tmpprot=array('file','http','https','ftp','zlib','data','ssh','ssh2','ogg','expect');
478
-	foreach($tmpprot as $prot)
477
+	$tmpprot = array('file', 'http', 'https', 'ftp', 'zlib', 'data', 'ssh', 'ssh2', 'ogg', 'expect');
478
+	foreach ($tmpprot as $prot)
479 479
 	{
480
-		if (preg_match('/^'.$prot.':/i',$url)) return true;
480
+		if (preg_match('/^'.$prot.':/i', $url)) return true;
481 481
 	}
482 482
 	return false;
483 483
 }
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
  */
491 491
 function dol_dir_is_emtpy($folder)
492 492
 {
493
-	$newfolder=dol_osencode($folder);
493
+	$newfolder = dol_osencode($folder);
494 494
 	if (is_dir($newfolder))
495 495
 	{
496 496
 		$handle = opendir($newfolder);
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 		{
500 500
 			$name_array[] = $name;
501 501
 		}
502
-		foreach($name_array as $temp) $folder_content .= $temp;
502
+		foreach ($name_array as $temp) $folder_content .= $temp;
503 503
 
504 504
 		closedir($handle);
505 505
 
@@ -519,24 +519,24 @@  discard block
 block discarded – undo
519 519
  */
520 520
 function dol_count_nb_of_line($file)
521 521
 {
522
-	$nb=0;
522
+	$nb = 0;
523 523
 
524
-	$newfile=dol_osencode($file);
524
+	$newfile = dol_osencode($file);
525 525
 	//print 'x'.$file;
526
-	$fp=fopen($newfile,'r');
526
+	$fp = fopen($newfile, 'r');
527 527
 	if ($fp)
528 528
 	{
529 529
 		while (!feof($fp))
530 530
 		{
531
-			$line=fgets($fp);
531
+			$line = fgets($fp);
532 532
 			// We increase count only if read was success. We need test because feof return true only after fgets so we do n+1 fgets for a file with n lines.
533
-			if (! $line === false) $nb++;
533
+			if (!$line === false) $nb++;
534 534
 		}
535 535
 		fclose($fp);
536 536
 	}
537 537
 	else
538 538
 	{
539
-		$nb=-1;
539
+		$nb = -1;
540 540
 	}
541 541
 
542 542
 	return $nb;
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
  */
552 552
 function dol_filesize($pathoffile)
553 553
 {
554
-	$newpathoffile=dol_osencode($pathoffile);
554
+	$newpathoffile = dol_osencode($pathoffile);
555 555
 	return filesize($newpathoffile);
556 556
 }
557 557
 
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
  */
564 564
 function dol_filemtime($pathoffile)
565 565
 {
566
-	$newpathoffile=dol_osencode($pathoffile);
566
+	$newpathoffile = dol_osencode($pathoffile);
567 567
 	return @filemtime($newpathoffile); // @Is to avoid errors if files does not exists
568 568
 }
569 569
 
@@ -578,31 +578,31 @@  discard block
 block discarded – undo
578 578
  * @return	int							<0 if error, 0 if nothing done (dest file already exists), >0 if OK
579 579
  * @see		dol_copy dolReplaceRegExInFile
580 580
  */
581
-function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0)
581
+function dolReplaceInFile($srcfile, $arrayreplacement, $destfile = '', $newmask = 0, $indexdatabase = 0)
582 582
 {
583 583
 	global $conf;
584 584
 
585 585
 	dol_syslog("files.lib.php::dolReplaceInFile srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." indexdatabase=".$indexdatabase);
586 586
 
587 587
 	if (empty($srcfile)) return -1;
588
-	if (empty($destfile)) $destfile=$srcfile;
588
+	if (empty($destfile)) $destfile = $srcfile;
589 589
 
590
-	$destexists=dol_is_file($destfile);
590
+	$destexists = dol_is_file($destfile);
591 591
 	if (($destfile != $srcfile) && $destexists) return 0;
592 592
 
593
-	$tmpdestfile=$destfile.'.tmp';
593
+	$tmpdestfile = $destfile.'.tmp';
594 594
 
595
-	$newpathofsrcfile=dol_osencode($srcfile);
596
-	$newpathoftmpdestfile=dol_osencode($tmpdestfile);
597
-	$newpathofdestfile=dol_osencode($destfile);
598
-	$newdirdestfile=dirname($newpathofdestfile);
595
+	$newpathofsrcfile = dol_osencode($srcfile);
596
+	$newpathoftmpdestfile = dol_osencode($tmpdestfile);
597
+	$newpathofdestfile = dol_osencode($destfile);
598
+	$newdirdestfile = dirname($newpathofdestfile);
599 599
 
600
-	if ($destexists && ! is_writable($newpathofdestfile))
600
+	if ($destexists && !is_writable($newpathofdestfile))
601 601
 	{
602 602
 		dol_syslog("files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING);
603 603
 		return -1;
604 604
 	}
605
-	if (! is_writable($newdirdestfile))
605
+	if (!is_writable($newdirdestfile))
606 606
 	{
607 607
 		dol_syslog("files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
608 608
 		return -2;
@@ -619,17 +619,17 @@  discard block
 block discarded – undo
619 619
 	@chmod($newpathoftmpdestfile, octdec($newmask));
620 620
 
621 621
 	// Rename
622
-	$result=dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile)?1:0), 0, $indexdatabase);
623
-	if (! $result)
622
+	$result = dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase);
623
+	if (!$result)
624 624
 	{
625 625
 		dol_syslog("files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING);
626 626
 		return -3;
627 627
 	}
628
-	if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
628
+	if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
629 629
 	if (empty($newmask))	// This should no happen
630 630
 	{
631 631
 		dol_syslog("Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING);
632
-		$newmask='0664';
632
+		$newmask = '0664';
633 633
 	}
634 634
 
635 635
 	@chmod($newpathofdestfile, octdec($newmask));
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
  * @return	int							<0 if error, 0 if nothing done (dest file already exists), >0 if OK
649 649
  * @see		dol_copy dolReplaceInFile
650 650
  */
651
-function dolReplaceRegExInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0)
651
+function dolReplaceRegExInFile($srcfile, $arrayreplacement, $destfile = '', $newmask = 0, $indexdatabase = 0)
652 652
 {
653 653
 	// TODO
654 654
 }
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
  * @return	int							<0 if error, 0 if nothing done (dest file already exists and overwriteifexists=0), >0 if OK
664 664
  * @see		dol_delete_file
665 665
  */
666
-function dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
666
+function dol_copy($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1)
667 667
 {
668 668
 	global $conf;
669 669
 
@@ -671,36 +671,36 @@  discard block
 block discarded – undo
671 671
 
672 672
 	if (empty($srcfile) || empty($destfile)) return -1;
673 673
 
674
-	$destexists=dol_is_file($destfile);
675
-	if (! $overwriteifexists && $destexists) return 0;
674
+	$destexists = dol_is_file($destfile);
675
+	if (!$overwriteifexists && $destexists) return 0;
676 676
 
677
-	$newpathofsrcfile=dol_osencode($srcfile);
678
-	$newpathofdestfile=dol_osencode($destfile);
679
-	$newdirdestfile=dirname($newpathofdestfile);
677
+	$newpathofsrcfile = dol_osencode($srcfile);
678
+	$newpathofdestfile = dol_osencode($destfile);
679
+	$newdirdestfile = dirname($newpathofdestfile);
680 680
 
681
-	if ($destexists && ! is_writable($newpathofdestfile))
681
+	if ($destexists && !is_writable($newpathofdestfile))
682 682
 	{
683 683
 		dol_syslog("files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING);
684 684
 		return -1;
685 685
 	}
686
-	if (! is_writable($newdirdestfile))
686
+	if (!is_writable($newdirdestfile))
687 687
 	{
688 688
 		dol_syslog("files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
689 689
 		return -2;
690 690
 	}
691 691
 	// Copy with overwriting if exists
692
-	$result=@copy($newpathofsrcfile, $newpathofdestfile);
692
+	$result = @copy($newpathofsrcfile, $newpathofdestfile);
693 693
 	//$result=copy($newpathofsrcfile, $newpathofdestfile);	// To see errors, remove @
694
-	if (! $result)
694
+	if (!$result)
695 695
 	{
696 696
 		dol_syslog("files.lib.php::dol_copy failed to copy", LOG_WARNING);
697 697
 		return -3;
698 698
 	}
699
-	if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
699
+	if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
700 700
 	if (empty($newmask))	// This should no happen
701 701
 	{
702 702
 		dol_syslog("Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
703
-		$newmask='0664';
703
+		$newmask = '0664';
704 704
 	}
705 705
 
706 706
 	@chmod($newpathofdestfile, octdec($newmask));
@@ -719,44 +719,44 @@  discard block
 block discarded – undo
719 719
  * @return	int							<0 if error, 0 if nothing done (all files already exists and overwriteifexists=0), >0 if OK
720 720
  * @see		dol_copy
721 721
  */
722
-function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null)
722
+function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement = null)
723 723
 {
724 724
 	global $conf;
725 725
 
726
-	$result=0;
726
+	$result = 0;
727 727
 
728 728
 	dol_syslog("files.lib.php::dolCopyDir srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists);
729 729
 
730 730
 	if (empty($srcfile) || empty($destfile)) return -1;
731 731
 
732
-	$destexists=dol_is_dir($destfile);
732
+	$destexists = dol_is_dir($destfile);
733 733
 	//if (! $overwriteifexists && $destexists) return 0;	// The overwriteifexists is for files only, so propagated to dol_copy only.
734 734
 
735
-	if (! $destexists)
735
+	if (!$destexists)
736 736
 	{
737 737
 		// We must set mask just before creating dir, becaause it can be set differently by dol_copy
738 738
 		umask(0);
739
-		$dirmaskdec=octdec($newmask);
740
-		if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK);
741
-		$dirmaskdec |= octdec('0200');  // Set w bit required to be able to create content for recursive subdirs files
739
+		$dirmaskdec = octdec($newmask);
740
+		if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $dirmaskdec = octdec($conf->global->MAIN_UMASK);
741
+		$dirmaskdec |= octdec('0200'); // Set w bit required to be able to create content for recursive subdirs files
742 742
 		dol_mkdir($destfile, '', decoct($dirmaskdec));
743 743
 	}
744 744
 
745
-	$ossrcfile=dol_osencode($srcfile);
746
-	$osdestfile=dol_osencode($destfile);
745
+	$ossrcfile = dol_osencode($srcfile);
746
+	$osdestfile = dol_osencode($destfile);
747 747
 
748 748
 	// Recursive function to copy all subdirectories and contents:
749 749
 	if (is_dir($ossrcfile))
750 750
 	{
751
-		$dir_handle=opendir($ossrcfile);
752
-		while ($file=readdir($dir_handle))
751
+		$dir_handle = opendir($ossrcfile);
752
+		while ($file = readdir($dir_handle))
753 753
 		{
754
-			if ($file != "." && $file != ".." && ! is_link($ossrcfile."/".$file))
754
+			if ($file != "." && $file != ".." && !is_link($ossrcfile."/".$file))
755 755
 			{
756 756
 				if (is_dir($ossrcfile."/".$file))
757 757
 				{
758 758
 					//var_dump("xxx dolCopyDir $srcfile/$file, $destfile/$file, $newmask, $overwriteifexists");
759
-					$tmpresult=dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists, $arrayreplacement);
759
+					$tmpresult = dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists, $arrayreplacement);
760 760
 				}
761 761
 				else
762 762
 				{
@@ -764,12 +764,12 @@  discard block
 block discarded – undo
764 764
 					// Replace destination filename with a new one
765 765
 					if (is_array($arrayreplacement))
766 766
 					{
767
-						foreach($arrayreplacement as $key => $val)
767
+						foreach ($arrayreplacement as $key => $val)
768 768
 						{
769 769
 							$newfile = str_replace($key, $val, $newfile);
770 770
 						}
771 771
 					}
772
-					$tmpresult=dol_copy($srcfile."/".$file, $destfile."/".$newfile, $newmask, $overwriteifexists);
772
+					$tmpresult = dol_copy($srcfile."/".$file, $destfile."/".$newfile, $newmask, $overwriteifexists);
773 773
 				}
774 774
 				// Set result
775 775
 				if ($result > 0 && $tmpresult >= 0)
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
 				}
779 779
 				else
780 780
 				{
781
-					$result=$tmpresult;
781
+					$result = $tmpresult;
782 782
 				}
783 783
 				if ($result < 0) break;
784 784
 			}
@@ -811,31 +811,31 @@  discard block
 block discarded – undo
811 811
  * @return  boolean 		            True if OK, false if KO
812 812
  * @see dol_move_uploaded_file
813 813
  */
814
-function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
814
+function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1)
815 815
 {
816 816
 	global $user, $db, $conf;
817
-	$result=false;
817
+	$result = false;
818 818
 
819 819
 	dol_syslog("files.lib.php::dol_move srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwritifexists=".$overwriteifexists);
820
-	$srcexists=dol_is_file($srcfile);
821
-	$destexists=dol_is_file($destfile);
820
+	$srcexists = dol_is_file($srcfile);
821
+	$destexists = dol_is_file($destfile);
822 822
 
823
-	if (! $srcexists)
823
+	if (!$srcexists)
824 824
 	{
825 825
 		dol_syslog("files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
826 826
 		return false;
827 827
 	}
828 828
 
829
-	if ($overwriteifexists || ! $destexists)
829
+	if ($overwriteifexists || !$destexists)
830 830
 	{
831
-		$newpathofsrcfile=dol_osencode($srcfile);
832
-		$newpathofdestfile=dol_osencode($destfile);
831
+		$newpathofsrcfile = dol_osencode($srcfile);
832
+		$newpathofdestfile = dol_osencode($destfile);
833 833
 
834 834
 		// Check virus
835
-		$testvirusarray=array();
835
+		$testvirusarray = array();
836 836
 		if ($testvirus)
837 837
 		{
838
-			$testvirusarray=dolCheckVirus($newpathofsrcfile);
838
+			$testvirusarray = dolCheckVirus($newpathofsrcfile);
839 839
 			if (count($testvirusarray))
840 840
 			{
841 841
 				dol_syslog("files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING);
@@ -843,15 +843,15 @@  discard block
 block discarded – undo
843 843
 			}
844 844
 		}
845 845
 
846
-		$result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @
847
-		if (! $result)
846
+		$result = @rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @
847
+		if (!$result)
848 848
 		{
849 849
 			if ($destexists)
850 850
 			{
851 851
 				dol_syslog("files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
852 852
 				// We force delete and try again. Rename function sometimes fails to replace dest file with some windows NTFS partitions.
853 853
 				dol_delete_file($destfile);
854
-				$result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @
854
+				$result = @rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @
855 855
 			}
856 856
 			else dol_syslog("files.lib.php::dol_move Failed.", LOG_WARNING);
857 857
 		}
@@ -860,9 +860,9 @@  discard block
 block discarded – undo
860 860
 		if ($result && $indexdatabase)
861 861
 		{
862 862
 			// Rename entry into ecm database
863
-			$rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $srcfile);
864
-			$rel_filetorenameafter = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $destfile);
865
-			if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
863
+			$rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $srcfile);
864
+			$rel_filetorenameafter = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $destfile);
865
+			if (!preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter))     // If not a tmp file
866 866
 			{
867 867
 				$rel_filetorenamebefore = preg_replace('/^[\\/]/', '', $rel_filetorenamebefore);
868 868
 				$rel_filetorenameafter = preg_replace('/^[\\/]/', '', $rel_filetorenameafter);
@@ -871,14 +871,14 @@  discard block
 block discarded – undo
871 871
 				dol_syslog("Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore." after = ".$rel_filetorenameafter, LOG_DEBUG);
872 872
 				include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
873 873
 
874
-				$ecmfiletarget=new EcmFiles($db);
874
+				$ecmfiletarget = new EcmFiles($db);
875 875
 				$resultecmtarget = $ecmfiletarget->fetch(0, '', $rel_filetorenameafter);
876 876
 				if ($resultecmtarget > 0)   // An entry for target name already exists for target, we delete it, a new one will be created.
877 877
 				{
878 878
 					$ecmfiletarget->delete($user);
879 879
 				}
880 880
 
881
-				$ecmfile=new EcmFiles($db);
881
+				$ecmfile = new EcmFiles($db);
882 882
 				$resultecm = $ecmfile->fetch(0, '', $rel_filetorenamebefore);
883 883
 				if ($resultecm > 0)   // If an entry was found for src file, we use it to move entry
884 884
 				{
@@ -900,11 +900,11 @@  discard block
 block discarded – undo
900 900
 
901 901
 					$ecmfile->filepath = $rel_dir;
902 902
 					$ecmfile->filename = $filename;
903
-					$ecmfile->label = md5_file(dol_osencode($destfile));        // $destfile is a full path to file
903
+					$ecmfile->label = md5_file(dol_osencode($destfile)); // $destfile is a full path to file
904 904
 					$ecmfile->fullpath_orig = $srcfile;
905 905
 					$ecmfile->gen_or_uploaded = 'unknown';
906
-					$ecmfile->description = '';    // indexed content
907
-					$ecmfile->keyword = '';        // keyword content
906
+					$ecmfile->description = ''; // indexed content
907
+					$ecmfile->keyword = ''; // keyword content
908 908
 					$resultecm = $ecmfile->create($user);
909 909
 					if ($resultecm < 0)
910 910
 					{
@@ -916,13 +916,13 @@  discard block
 block discarded – undo
916 916
 					setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
917 917
 				}
918 918
 
919
-				if ($resultecm > 0) $result=true;
919
+				if ($resultecm > 0) $result = true;
920 920
 				else $result = false;
921 921
 			}
922 922
 		}
923 923
 
924
-		if (empty($newmask)) $newmask=empty($conf->global->MAIN_UMASK)?'0755':$conf->global->MAIN_UMASK;
925
-		$newmaskdec=octdec($newmask);
924
+		if (empty($newmask)) $newmask = empty($conf->global->MAIN_UMASK) ? '0755' : $conf->global->MAIN_UMASK;
925
+		$newmaskdec = octdec($newmask);
926 926
 		// Currently method is restricted to files (dol_delete_files previously used is for files, and mask usage if for files too)
927 927
 		// to allow mask usage for dir, we shoul introduce a new param "isdir" to 1 to complete newmask like this
928 928
 		// if ($isdir) $newmaskdec |= octdec('0111');  // Set x bit required for directories
@@ -958,16 +958,16 @@  discard block
 block discarded – undo
958 958
 {
959 959
 	global $conf;
960 960
 
961
-	if (! empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
961
+	if (!empty($conf->global->MAIN_ANTIVIRUS_COMMAND))
962 962
 	{
963
-		if (! class_exists('AntiVir')) {
963
+		if (!class_exists('AntiVir')) {
964 964
 			require_once DOL_DOCUMENT_ROOT.'/core/class/antivir.class.php';
965 965
 		}
966
-		$antivir=new AntiVir($db);
966
+		$antivir = new AntiVir($db);
967 967
 		$result = $antivir->dol_avscan_file($src_file);
968 968
 		if ($result < 0)	// If virus or error, we stop here
969 969
 		{
970
-			$reterrors=$antivir->errors;
970
+			$reterrors = $antivir->errors;
971 971
 			return $reterrors;
972 972
 		}
973 973
 	}
@@ -993,20 +993,20 @@  discard block
 block discarded – undo
993 993
  *	@return int       			  		>0 if OK, <0 or string if KO
994 994
  *  @see    dol_move
995 995
  */
996
-function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile')
996
+function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles = 'addedfile')
997 997
 {
998 998
 	global $conf, $db, $user, $langs;
999 999
 	global $object, $hookmanager;
1000 1000
 
1001
-	$reshook=0;
1001
+	$reshook = 0;
1002 1002
 	$file_name = $dest_file;
1003 1003
 
1004 1004
 	if (empty($nohook))
1005 1005
 	{
1006
-		$reshook=$hookmanager->initHooks(array('fileslib'));
1006
+		$reshook = $hookmanager->initHooks(array('fileslib'));
1007 1007
 
1008
-		$parameters=array('dest_file' => $dest_file, 'src_file' => $src_file, 'file_name' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite);
1009
-		$reshook=$hookmanager->executeHooks('moveUploadedFile', $parameters, $object);
1008
+		$parameters = array('dest_file' => $dest_file, 'src_file' => $src_file, 'file_name' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite);
1009
+		$reshook = $hookmanager->executeHooks('moveUploadedFile', $parameters, $object);
1010 1010
 	}
1011 1011
 
1012 1012
 	if (empty($reshook))
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
 		// If an upload error has been reported
1015 1015
 		if ($uploaderrorcode)
1016 1016
 		{
1017
-			switch($uploaderrorcode)
1017
+			switch ($uploaderrorcode)
1018 1018
 			{
1019 1019
 				case UPLOAD_ERR_INI_SIZE:	// 1
1020 1020
 					return 'ErrorFileSizeTooLarge';
@@ -1042,25 +1042,25 @@  discard block
 block discarded – undo
1042 1042
 		// If we need to make a virus scan
1043 1043
 		if (empty($disablevirusscan) && file_exists($src_file))
1044 1044
 		{
1045
-			$checkvirusarray=dolCheckVirus($src_file);
1045
+			$checkvirusarray = dolCheckVirus($src_file);
1046 1046
 			if (count($checkvirusarray))
1047 1047
 			{
1048
-			   dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: result='.$result.' errors='.join(',',$checkvirusarray), LOG_WARNING);
1049
-			   return 'ErrorFileIsInfectedWithAVirus: '.join(',',$checkvirusarray);
1048
+			   dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: result='.$result.' errors='.join(',', $checkvirusarray), LOG_WARNING);
1049
+			   return 'ErrorFileIsInfectedWithAVirus: '.join(',', $checkvirusarray);
1050 1050
 			}
1051 1051
 		}
1052 1052
 
1053 1053
 		// Security:
1054 1054
 		// Disallow file with some extensions. We rename them.
1055 1055
 		// Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code.
1056
-		if (preg_match('/(\.htm|\.html|\.php|\.pl|\.cgi)$/i',$dest_file) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED))
1056
+		if (preg_match('/(\.htm|\.html|\.php|\.pl|\.cgi)$/i', $dest_file) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED))
1057 1057
 		{
1058
-			$file_name.= '.noexe';
1058
+			$file_name .= '.noexe';
1059 1059
 		}
1060 1060
 
1061 1061
 		// Security:
1062 1062
 		// We refuse cache files/dirs, upload using .. and pipes into filenames.
1063
-		if (preg_match('/^\./',$src_file) || preg_match('/\.\./',$src_file) || preg_match('/[<>|]/',$src_file))
1063
+		if (preg_match('/^\./', $src_file) || preg_match('/\.\./', $src_file) || preg_match('/[<>|]/', $src_file))
1064 1064
 		{
1065 1065
 			dol_syslog("Refused to deliver file ".$src_file, LOG_WARNING);
1066 1066
 			return -1;
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
 
1069 1069
 		// Security:
1070 1070
 		// On interdit fichiers caches, remontees de repertoire ainsi que les pipe dans les noms de fichiers.
1071
-		if (preg_match('/^\./',$dest_file) || preg_match('/\.\./',$dest_file) || preg_match('/[<>|]/',$dest_file))
1071
+		if (preg_match('/^\./', $dest_file) || preg_match('/\.\./', $dest_file) || preg_match('/[<>|]/', $dest_file))
1072 1072
 		{
1073 1073
 			dol_syslog("Refused to deliver file ".$dest_file, LOG_WARNING);
1074 1074
 			return -2;
@@ -1078,24 +1078,24 @@  discard block
 block discarded – undo
1078 1078
 	if ($reshook < 0)	// At least one blocking error returned by one hook
1079 1079
 	{
1080 1080
 		$errmsg = join(',', $hookmanager->errors);
1081
-		if (empty($errmsg)) $errmsg = 'ErrorReturnedBySomeHooks';	// Should not occurs. Added if hook is bugged and does not set ->errors when there is error.
1081
+		if (empty($errmsg)) $errmsg = 'ErrorReturnedBySomeHooks'; // Should not occurs. Added if hook is bugged and does not set ->errors when there is error.
1082 1082
 		return $errmsg;
1083 1083
 	}
1084 1084
 	elseif (empty($reshook))
1085 1085
 	{
1086 1086
 		// The file functions must be in OS filesystem encoding.
1087
-		$src_file_osencoded=dol_osencode($src_file);
1088
-		$file_name_osencoded=dol_osencode($file_name);
1087
+		$src_file_osencoded = dol_osencode($src_file);
1088
+		$file_name_osencoded = dol_osencode($file_name);
1089 1089
 
1090 1090
 		// Check if destination dir is writable
1091
-		if (! is_writable(dirname($file_name_osencoded)))
1091
+		if (!is_writable(dirname($file_name_osencoded)))
1092 1092
 		{
1093 1093
 			dol_syslog("Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded)." is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING);
1094 1094
 			return 'ErrorDirNotWritable';
1095 1095
 		}
1096 1096
 
1097 1097
 		// Check if destination file already exists
1098
-		if (! $allowoverwrite)
1098
+		if (!$allowoverwrite)
1099 1099
 		{
1100 1100
 			if (file_exists($file_name_osencoded))
1101 1101
 			{
@@ -1105,21 +1105,21 @@  discard block
 block discarded – undo
1105 1105
 		}
1106 1106
 
1107 1107
 		// Move file
1108
-		$return=move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1108
+		$return = move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1109 1109
 		if ($return)
1110 1110
 		{
1111
-			if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
1111
+			if (!empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
1112 1112
 			dol_syslog("Files.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
1113
-			return 1;	// Success
1113
+			return 1; // Success
1114 1114
 		}
1115 1115
 		else
1116 1116
 		{
1117 1117
 			dol_syslog("Files.lib::dol_move_uploaded_file Failed to move ".$src_file." to ".$file_name, LOG_ERR);
1118
-			return -3;	// Unknown error
1118
+			return -3; // Unknown error
1119 1119
 		}
1120 1120
 	}
1121 1121
 
1122
-	return 1;	// Success
1122
+	return 1; // Success
1123 1123
 }
1124 1124
 
1125 1125
 /**
@@ -1136,7 +1136,7 @@  discard block
 block discarded – undo
1136 1136
  *  @return boolean         		True if no error (file is deleted or if glob is used and there's nothing to delete), False if error
1137 1137
  *  @see dol_delete_dir
1138 1138
  */
1139
-function dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
1139
+function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0, $object = null, $allowdotdot = false, $indexdatabase = 1)
1140 1140
 {
1141 1141
 	global $db, $conf, $user, $langs;
1142 1142
 	global $hookmanager;
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
 
1149 1149
 	// Security:
1150 1150
 	// We refuse transversal using .. and pipes into filenames.
1151
-	if ((! $allowdotdot && preg_match('/\.\./',$file)) || preg_match('/[<>|]/',$file))
1151
+	if ((!$allowdotdot && preg_match('/\.\./', $file)) || preg_match('/[<>|]/', $file))
1152 1152
 	{
1153 1153
 		dol_syslog("Refused to delete file ".$file, LOG_WARNING);
1154 1154
 		return false;
@@ -1158,13 +1158,13 @@  discard block
 block discarded – undo
1158 1158
 	{
1159 1159
 		$hookmanager->initHooks(array('fileslib'));
1160 1160
 
1161
-		$parameters=array(
1161
+		$parameters = array(
1162 1162
 				'GET' => $_GET,
1163 1163
 				'file' => $file,
1164 1164
 				'disableglob'=> $disableglob,
1165 1165
 				'nophperrors' => $nophperrors
1166 1166
 		);
1167
-		$reshook=$hookmanager->executeHooks('deleteFile', $parameters, $object);
1167
+		$reshook = $hookmanager->executeHooks('deleteFile', $parameters, $object);
1168 1168
 	}
1169 1169
 
1170 1170
 	if (empty($nohook) && $reshook != 0) // reshook = 0 to do standard actions, 1 = ok, -1 = ko
@@ -1174,29 +1174,29 @@  discard block
 block discarded – undo
1174 1174
 	}
1175 1175
 	else
1176 1176
 	{
1177
-		$error=0;
1177
+		$error = 0;
1178 1178
 
1179 1179
 		//print "x".$file." ".$disableglob;exit;
1180
-		$file_osencoded=dol_osencode($file);    // New filename encoded in OS filesystem encoding charset
1181
-		if (empty($disableglob) && ! empty($file_osencoded))
1182
-		{
1183
-			$ok=true;
1184
-			$globencoded=str_replace('[','\[',$file_osencoded);
1185
-			$globencoded=str_replace(']','\]',$globencoded);
1186
-			$listofdir=glob($globencoded);
1187
-			if (! empty($listofdir) && is_array($listofdir))
1180
+		$file_osencoded = dol_osencode($file); // New filename encoded in OS filesystem encoding charset
1181
+		if (empty($disableglob) && !empty($file_osencoded))
1182
+		{
1183
+			$ok = true;
1184
+			$globencoded = str_replace('[', '\[', $file_osencoded);
1185
+			$globencoded = str_replace(']', '\]', $globencoded);
1186
+			$listofdir = glob($globencoded);
1187
+			if (!empty($listofdir) && is_array($listofdir))
1188 1188
 			{
1189 1189
 				foreach ($listofdir as $filename)
1190 1190
 				{
1191
-					if ($nophperrors) $ok=@unlink($filename);
1192
-					else $ok=unlink($filename);
1191
+					if ($nophperrors) $ok = @unlink($filename);
1192
+					else $ok = unlink($filename);
1193 1193
 					if ($ok)
1194 1194
 					{
1195 1195
 						dol_syslog("Removed file ".$filename, LOG_DEBUG);
1196 1196
 
1197 1197
 						// Delete entry into ecm database
1198
-						$rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filename);
1199
-						if (! preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete))     // If not a tmp file
1198
+						$rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filename);
1199
+						if (!preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete))     // If not a tmp file
1200 1200
 						{
1201 1201
 							$rel_filetodelete = preg_replace('/^[\\/]/', '', $rel_filetodelete);
1202 1202
 
@@ -1204,7 +1204,7 @@  discard block
 block discarded – undo
1204 1204
 							{
1205 1205
 								dol_syslog("Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
1206 1206
 								include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
1207
-								$ecmfile=new EcmFiles($db);
1207
+								$ecmfile = new EcmFiles($db);
1208 1208
 								$result = $ecmfile->fetch(0, '', $rel_filetodelete);
1209 1209
 								if ($result >= 0 && $ecmfile->id > 0)
1210 1210
 								{
@@ -1226,9 +1226,9 @@  discard block
 block discarded – undo
1226 1226
 		}
1227 1227
 		else
1228 1228
 		{
1229
-			$ok=false;
1230
-			if ($nophperrors) $ok=@unlink($file_osencoded);
1231
-			else $ok=unlink($file_osencoded);
1229
+			$ok = false;
1230
+			if ($nophperrors) $ok = @unlink($file_osencoded);
1231
+			else $ok = unlink($file_osencoded);
1232 1232
 			if ($ok) dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG);
1233 1233
 			else dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING);
1234 1234
 		}
@@ -1246,18 +1246,18 @@  discard block
 block discarded – undo
1246 1246
  *  @return boolean         		True if success, false if error
1247 1247
  *  @see dol_delete_file dol_copy
1248 1248
  */
1249
-function dol_delete_dir($dir,$nophperrors=0)
1249
+function dol_delete_dir($dir, $nophperrors = 0)
1250 1250
 {
1251 1251
 	// Security:
1252 1252
 	// We refuse transversal using .. and pipes into filenames.
1253
-	if (preg_match('/\.\./',$dir) || preg_match('/[<>|]/',$dir))
1253
+	if (preg_match('/\.\./', $dir) || preg_match('/[<>|]/', $dir))
1254 1254
 	{
1255 1255
 		dol_syslog("Refused to delete dir ".$dir, LOG_WARNING);
1256 1256
 		return false;
1257 1257
 	}
1258 1258
 
1259
-	$dir_osencoded=dol_osencode($dir);
1260
-	return ($nophperrors?@rmdir($dir_osencoded):rmdir($dir_osencoded));
1259
+	$dir_osencoded = dol_osencode($dir);
1260
+	return ($nophperrors ? @rmdir($dir_osencoded) : rmdir($dir_osencoded));
1261 1261
 }
1262 1262
 
1263 1263
 /**
@@ -1270,27 +1270,27 @@  discard block
 block discarded – undo
1270 1270
  *  @param  int		$countdeleted   Counter to count nb of elements found really deleted
1271 1271
  *  @return int             		Number of files and directory we try to remove. NB really removed is returned into var by reference $countdeleted.
1272 1272
  */
1273
-function dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
1273
+function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0, &$countdeleted = 0)
1274 1274
 {
1275
-	dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG);
1275
+	dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG);
1276 1276
 	if (dol_is_dir($dir))
1277 1277
 	{
1278
-		$dir_osencoded=dol_osencode($dir);
1278
+		$dir_osencoded = dol_osencode($dir);
1279 1279
 		if ($handle = opendir("$dir_osencoded"))
1280 1280
 		{
1281 1281
 			while (false !== ($item = readdir($handle)))
1282 1282
 			{
1283
-				if (! utf8_check($item)) $item=utf8_encode($item);  // should be useless
1283
+				if (!utf8_check($item)) $item = utf8_encode($item); // should be useless
1284 1284
 
1285 1285
 				if ($item != "." && $item != "..")
1286 1286
 				{
1287
-					if (is_dir(dol_osencode("$dir/$item")) && ! is_link(dol_osencode("$dir/$item")))
1287
+					if (is_dir(dol_osencode("$dir/$item")) && !is_link(dol_osencode("$dir/$item")))
1288 1288
 					{
1289
-						$count=dol_delete_dir_recursive("$dir/$item", $count, $nophperrors, 0, $countdeleted);
1289
+						$count = dol_delete_dir_recursive("$dir/$item", $count, $nophperrors, 0, $countdeleted);
1290 1290
 					}
1291 1291
 					else
1292 1292
 					{
1293
-						$result=dol_delete_file("$dir/$item", 1, $nophperrors);
1293
+						$result = dol_delete_file("$dir/$item", 1, $nophperrors);
1294 1294
 						$count++;
1295 1295
 						if ($result) $countdeleted++;
1296 1296
 						//else print 'Error on '.$item."\n";
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
 
1302 1302
 			if (empty($onlysub))
1303 1303
 			{
1304
-				$result=dol_delete_dir($dir, $nophperrors);
1304
+				$result = dol_delete_dir($dir, $nophperrors);
1305 1305
 				$count++;
1306 1306
 				if ($result) $countdeleted++;
1307 1307
 				//else print 'Error on '.$dir."\n";
@@ -1323,7 +1323,7 @@  discard block
 block discarded – undo
1323 1323
  */
1324 1324
 function dol_delete_preview($object)
1325 1325
 {
1326
-	global $langs,$conf;
1326
+	global $langs, $conf;
1327 1327
 
1328 1328
 	// Define parent dir of elements
1329 1329
 	$element = $object->element;
@@ -1334,54 +1334,54 @@  discard block
 block discarded – undo
1334 1334
 	elseif ($object->element == 'shipping')			$dir = $conf->expedition->dir_output.'/sending';
1335 1335
 	elseif ($object->element == 'delivery')			$dir = $conf->expedition->dir_output.'/receipt';
1336 1336
 	elseif ($object->element == 'fichinter')		$dir = $conf->ficheinter->dir_output;
1337
-	else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output;
1337
+	else $dir = empty($conf->$element->dir_output) ? '' : $conf->$element->dir_output;
1338 1338
 
1339 1339
 	if (empty($dir)) return 'ErrorObjectNoSupportedByFunction';
1340 1340
 
1341 1341
 	$refsan = dol_sanitizeFileName($object->ref);
1342
-	$dir = $dir . "/" . $refsan ;
1343
-	$filepreviewnew = $dir . "/" . $refsan . ".pdf_preview.png";
1344
-	$filepreviewnewbis = $dir . "/" . $refsan . ".pdf_preview-0.png";
1345
-	$filepreviewold = $dir . "/" . $refsan . ".pdf.png";
1342
+	$dir = $dir."/".$refsan;
1343
+	$filepreviewnew = $dir."/".$refsan.".pdf_preview.png";
1344
+	$filepreviewnewbis = $dir."/".$refsan.".pdf_preview-0.png";
1345
+	$filepreviewold = $dir."/".$refsan.".pdf.png";
1346 1346
 
1347 1347
 	// For new preview files
1348 1348
 	if (file_exists($filepreviewnew) && is_writable($filepreviewnew))
1349 1349
 	{
1350
-		if (! dol_delete_file($filepreviewnew,1))
1350
+		if (!dol_delete_file($filepreviewnew, 1))
1351 1351
 		{
1352
-			$object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewnew);
1352
+			$object->error = $langs->trans("ErrorFailedToDeleteFile", $filepreviewnew);
1353 1353
 			return 0;
1354 1354
 		}
1355 1355
 	}
1356 1356
 	if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis))
1357 1357
 	{
1358
-		if (! dol_delete_file($filepreviewnewbis,1))
1358
+		if (!dol_delete_file($filepreviewnewbis, 1))
1359 1359
 		{
1360
-			$object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewnewbis);
1360
+			$object->error = $langs->trans("ErrorFailedToDeleteFile", $filepreviewnewbis);
1361 1361
 			return 0;
1362 1362
 		}
1363 1363
 	}
1364 1364
 	// For old preview files
1365 1365
 	if (file_exists($filepreviewold) && is_writable($filepreviewold))
1366 1366
 	{
1367
-		if (! dol_delete_file($filepreviewold,1))
1367
+		if (!dol_delete_file($filepreviewold, 1))
1368 1368
 		{
1369
-			$object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewold);
1369
+			$object->error = $langs->trans("ErrorFailedToDeleteFile", $filepreviewold);
1370 1370
 			return 0;
1371 1371
 		}
1372 1372
 	}
1373 1373
 	else
1374 1374
 	{
1375
-		$multiple = $filepreviewold . ".";
1375
+		$multiple = $filepreviewold.".";
1376 1376
 		for ($i = 0; $i < 20; $i++)
1377 1377
 		{
1378 1378
 			$preview = $multiple.$i;
1379 1379
 
1380 1380
 			if (file_exists($preview) && is_writable($preview))
1381 1381
 			{
1382
-				if ( ! dol_delete_file($preview,1) )
1382
+				if (!dol_delete_file($preview, 1))
1383 1383
 				{
1384
-					$object->error=$langs->trans("ErrorFailedToOpenFile",$preview);
1384
+					$object->error = $langs->trans("ErrorFailedToOpenFile", $preview);
1385 1385
 					return 0;
1386 1386
 				}
1387 1387
 			}
@@ -1404,10 +1404,10 @@  discard block
 block discarded – undo
1404 1404
 	global $conf;
1405 1405
 
1406 1406
 	// Create meta file
1407
-	if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) return 0;	// By default, no metafile.
1407
+	if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) return 0; // By default, no metafile.
1408 1408
 
1409 1409
 	// Define parent dir of elements
1410
-	$element=$object->element;
1410
+	$element = $object->element;
1411 1411
 
1412 1412
 	if ($object->element == 'order_supplier')		$dir = $conf->fournisseur->dir_output.'/commande';
1413 1413
 	elseif ($object->element == 'invoice_supplier')	$dir = $conf->fournisseur->dir_output.'/facture';
@@ -1415,17 +1415,17 @@  discard block
 block discarded – undo
1415 1415
 	elseif ($object->element == 'shipping')			$dir = $conf->expedition->dir_output.'/sending';
1416 1416
 	elseif ($object->element == 'delivery')			$dir = $conf->expedition->dir_output.'/receipt';
1417 1417
 	elseif ($object->element == 'fichinter')		$dir = $conf->ficheinter->dir_output;
1418
-	else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output;
1418
+	else $dir = empty($conf->$element->dir_output) ? '' : $conf->$element->dir_output;
1419 1419
 
1420 1420
 	if ($dir)
1421 1421
 	{
1422 1422
 		$object->fetch_thirdparty();
1423 1423
 
1424 1424
 		$objectref = dol_sanitizeFileName($object->ref);
1425
-		$dir = $dir . "/" . $objectref;
1426
-		$file = $dir . "/" . $objectref . ".meta";
1425
+		$dir = $dir."/".$objectref;
1426
+		$file = $dir."/".$objectref.".meta";
1427 1427
 
1428
-		if (! is_dir($dir))
1428
+		if (!is_dir($dir))
1429 1429
 		{
1430 1430
 			dol_mkdir($dir);
1431 1431
 		}
@@ -1433,29 +1433,29 @@  discard block
 block discarded – undo
1433 1433
 		if (is_dir($dir))
1434 1434
 		{
1435 1435
 			$nblignes = count($object->lines);
1436
-			$client = $object->thirdparty->name . " " . $object->thirdparty->address . " " . $object->thirdparty->zip . " " . $object->thirdparty->town;
1437
-			$meta = "REFERENCE=\"" . $object->ref . "\"
1438
-			DATE=\"" . dol_print_date($object->date,'') . "\"
1439
-			NB_ITEMS=\"" . $nblignes . "\"
1440
-			CLIENT=\"" . $client . "\"
1441
-			AMOUNT_EXCL_TAX=\"" . $object->total_ht . "\"
1442
-			AMOUNT=\"" . $object->total_ttc . "\"\n";
1443
-
1444
-			for ($i = 0 ; $i < $nblignes ; $i++)
1436
+			$client = $object->thirdparty->name." ".$object->thirdparty->address." ".$object->thirdparty->zip." ".$object->thirdparty->town;
1437
+			$meta = "REFERENCE=\"".$object->ref."\"
1438
+			DATE=\"" . dol_print_date($object->date, '')."\"
1439
+			NB_ITEMS=\"" . $nblignes."\"
1440
+			CLIENT=\"" . $client."\"
1441
+			AMOUNT_EXCL_TAX=\"" . $object->total_ht."\"
1442
+			AMOUNT=\"" . $object->total_ttc."\"\n";
1443
+
1444
+			for ($i = 0; $i < $nblignes; $i++)
1445 1445
 			{
1446 1446
 				//Pour les articles
1447
-				$meta .= "ITEM_" . $i . "_QUANTITY=\"" . $object->lines[$i]->qty . "\"
1448
-				ITEM_" . $i . "_AMOUNT_WO_TAX=\"" . $object->lines[$i]->total_ht . "\"
1449
-				ITEM_" . $i . "_VAT=\"" .$object->lines[$i]->tva_tx . "\"
1450
-				ITEM_" . $i . "_DESCRIPTION=\"" . str_replace("\r\n","",nl2br($object->lines[$i]->desc)) . "\"
1447
+				$meta .= "ITEM_".$i."_QUANTITY=\"".$object->lines[$i]->qty."\"
1448
+				ITEM_" . $i."_AMOUNT_WO_TAX=\"".$object->lines[$i]->total_ht."\"
1449
+				ITEM_" . $i."_VAT=\"".$object->lines[$i]->tva_tx."\"
1450
+				ITEM_" . $i."_DESCRIPTION=\"".str_replace("\r\n", "", nl2br($object->lines[$i]->desc))."\"
1451 1451
 				";
1452 1452
 			}
1453 1453
 		}
1454 1454
 
1455
-		$fp = fopen($file,"w");
1456
-		fputs($fp,$meta);
1455
+		$fp = fopen($file, "w");
1456
+		fputs($fp, $meta);
1457 1457
 		fclose($fp);
1458
-		if (! empty($conf->global->MAIN_UMASK))
1458
+		if (!empty($conf->global->MAIN_UMASK))
1459 1459
 		@chmod($file, octdec($conf->global->MAIN_UMASK));
1460 1460
 
1461 1461
 		return 1;
@@ -1478,26 +1478,26 @@  discard block
 block discarded – undo
1478 1478
  * @param   string  $trackid                Track id (used to prefix name of session vars to avoid conflict)
1479 1479
  * @return	void
1480 1480
  */
1481
-function dol_init_file_process($pathtoscan='', $trackid='')
1481
+function dol_init_file_process($pathtoscan = '', $trackid = '')
1482 1482
 {
1483
-	$listofpaths=array();
1484
-	$listofnames=array();
1485
-	$listofmimes=array();
1483
+	$listofpaths = array();
1484
+	$listofnames = array();
1485
+	$listofmimes = array();
1486 1486
 
1487 1487
 	if ($pathtoscan)
1488 1488
 	{
1489
-		$listoffiles=dol_dir_list($pathtoscan,'files');
1490
-		foreach($listoffiles as $key => $val)
1489
+		$listoffiles = dol_dir_list($pathtoscan, 'files');
1490
+		foreach ($listoffiles as $key => $val)
1491 1491
 		{
1492
-			$listofpaths[]=$val['fullname'];
1493
-			$listofnames[]=$val['name'];
1494
-			$listofmimes[]=dol_mimetype($val['name']);
1492
+			$listofpaths[] = $val['fullname'];
1493
+			$listofnames[] = $val['name'];
1494
+			$listofmimes[] = dol_mimetype($val['name']);
1495 1495
 		}
1496 1496
 	}
1497
-	$keytoavoidconflict = empty($trackid)?'':'-'.$trackid;
1498
-	$_SESSION["listofpaths".$keytoavoidconflict]=join(';',$listofpaths);
1499
-	$_SESSION["listofnames".$keytoavoidconflict]=join(';',$listofnames);
1500
-	$_SESSION["listofmimes".$keytoavoidconflict]=join(';',$listofmimes);
1497
+	$keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid;
1498
+	$_SESSION["listofpaths".$keytoavoidconflict] = join(';', $listofpaths);
1499
+	$_SESSION["listofnames".$keytoavoidconflict] = join(';', $listofnames);
1500
+	$_SESSION["listofmimes".$keytoavoidconflict] = join(';', $listofmimes);
1501 1501
 }
1502 1502
 
1503 1503
 
@@ -1516,13 +1516,13 @@  discard block
 block discarded – undo
1516 1516
  * @param	int		$generatethumbs			1=Generate also thumbs for uploaded image files
1517 1517
  * @return	int                             <=0 if KO, >0 if OK
1518 1518
  */
1519
-function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1)
1519
+function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesession = 0, $varfiles = 'addedfile', $savingdocmask = '', $link = null, $trackid = '', $generatethumbs = 1)
1520 1520
 {
1521
-	global $db,$user,$conf,$langs;
1521
+	global $db, $user, $conf, $langs;
1522 1522
 
1523 1523
 	$res = 0;
1524 1524
 
1525
-	if (! empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error']
1525
+	if (!empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error']
1526 1526
 	{
1527 1527
 		dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession.' savingdocmask='.$savingdocmask, LOG_DEBUG);
1528 1528
 		if (dol_mkdir($upload_dir) >= 0)
@@ -1541,13 +1541,13 @@  discard block
 block discarded – undo
1541 1541
 			for ($i = 0; $i < $nbfile; $i++)
1542 1542
 			{
1543 1543
 				// Define $destfull (path to file including filename) and $destfile (only filename)
1544
-				$destfull=$upload_dir . "/" . $TFile['name'][$i];
1545
-				$destfile=$TFile['name'][$i];
1544
+				$destfull = $upload_dir."/".$TFile['name'][$i];
1545
+				$destfile = $TFile['name'][$i];
1546 1546
 
1547 1547
 				if ($savingdocmask)
1548 1548
 				{
1549
-					$destfull=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask);
1550
-					$destfile=preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask);
1549
+					$destfull = $upload_dir."/".preg_replace('/__file__/', $TFile['name'][$i], $savingdocmask);
1550
+					$destfile = preg_replace('/__file__/', $TFile['name'][$i], $savingdocmask);
1551 1551
 				}
1552 1552
 
1553 1553
 				// dol_sanitizeFileName the file name and lowercase extension
@@ -1608,7 +1608,7 @@  discard block
 block discarded – undo
1608 1608
 					{
1609 1609
 						setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
1610 1610
 					}
1611
-					else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload))	// Files infected by a virus
1611
+					else if (preg_match('/ErrorFileIsInfectedWithAVirus/', $resupload))	// Files infected by a virus
1612 1612
 					{
1613 1613
 						setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors');
1614 1614
 					}
@@ -1625,7 +1625,7 @@  discard block
 block discarded – undo
1625 1625
 			}
1626 1626
 		}
1627 1627
 	} elseif ($link) {
1628
-		require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
1628
+		require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
1629 1629
 		$linkObject = new Link($db);
1630 1630
 		$linkObject->entity = $conf->entity;
1631 1631
 		$linkObject->url = $link;
@@ -1660,33 +1660,33 @@  discard block
 block discarded – undo
1660 1660
  * @param   string  $trackid                Track id (used to prefix name of session vars to avoid conflict)
1661 1661
  * @return	void
1662 1662
  */
1663
-function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=1,$trackid='')
1663
+function dol_remove_file_process($filenb, $donotupdatesession = 0, $donotdeletefile = 1, $trackid = '')
1664 1664
 {
1665
-	global $db,$user,$conf,$langs,$_FILES;
1665
+	global $db, $user, $conf, $langs, $_FILES;
1666 1666
 
1667
-	$keytodelete=$filenb;
1667
+	$keytodelete = $filenb;
1668 1668
 	$keytodelete--;
1669 1669
 
1670
-	$listofpaths=array();
1671
-	$listofnames=array();
1672
-	$listofmimes=array();
1673
-	$keytoavoidconflict = empty($trackid)?'':'-'.$trackid;
1674
-	if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
1675
-	if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
1676
-	if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
1670
+	$listofpaths = array();
1671
+	$listofnames = array();
1672
+	$listofmimes = array();
1673
+	$keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid;
1674
+	if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]);
1675
+	if (!empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]);
1676
+	if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]);
1677 1677
 
1678 1678
 	if ($keytodelete >= 0)
1679 1679
 	{
1680
-		$pathtodelete=$listofpaths[$keytodelete];
1681
-		$filetodelete=$listofnames[$keytodelete];
1682
-		if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete,1);  // The delete of ecm database is inside the function dol_delete_file
1683
-		else $result=0;
1680
+		$pathtodelete = $listofpaths[$keytodelete];
1681
+		$filetodelete = $listofnames[$keytodelete];
1682
+		if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete, 1); // The delete of ecm database is inside the function dol_delete_file
1683
+		else $result = 0;
1684 1684
 		if ($result >= 0)
1685 1685
 		{
1686 1686
 			if (empty($donotdeletefile))
1687 1687
 			{
1688 1688
 				$langs->load("other");
1689
-				setEventMessages($langs->trans("FileWasRemoved",$filetodelete), null, 'mesgs');
1689
+				setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs');
1690 1690
 			}
1691 1691
 			if (empty($donotupdatesession))
1692 1692
 			{
@@ -1712,29 +1712,29 @@  discard block
 block discarded – undo
1712 1712
  *  @param		int		$setsharekey	Set also the share key
1713 1713
  *	@return		int						<0 if KO, 0 if nothing done, >0 if OK
1714 1714
  */
1715
-function addFileIntoDatabaseIndex($dir, $file, $fullpathorig='', $mode='uploaded', $setsharekey=0)
1715
+function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uploaded', $setsharekey = 0)
1716 1716
 {
1717 1717
 	global $db, $user;
1718 1718
 
1719 1719
 	$result = 0;
1720 1720
 
1721
-	$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
1721
+	$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $dir);
1722 1722
 
1723
-	if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir))     // If not a tmp dir
1723
+	if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir))     // If not a tmp dir
1724 1724
 	{
1725 1725
 		$filename = basename($file);
1726 1726
 		$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
1727 1727
 		$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
1728 1728
 
1729 1729
 		include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
1730
-		$ecmfile=new EcmFiles($db);
1730
+		$ecmfile = new EcmFiles($db);
1731 1731
 		$ecmfile->filepath = $rel_dir;
1732 1732
 		$ecmfile->filename = $filename;
1733
-		$ecmfile->label = md5_file(dol_osencode($dir.'/'.$file));	// MD5 of file content
1733
+		$ecmfile->label = md5_file(dol_osencode($dir.'/'.$file)); // MD5 of file content
1734 1734
 		$ecmfile->fullpath_orig = $fullpathorig;
1735 1735
 		$ecmfile->gen_or_uploaded = $mode;
1736
-		$ecmfile->description = '';    // indexed content
1737
-		$ecmfile->keyword = '';        // keyword content
1736
+		$ecmfile->description = ''; // indexed content
1737
+		$ecmfile->keyword = ''; // keyword content
1738 1738
 		if ($setsharekey)
1739 1739
 		{
1740 1740
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
@@ -1760,7 +1760,7 @@  discard block
 block discarded – undo
1760 1760
  *  @param		string	$mode			How file was created ('uploaded', 'generated', ...)
1761 1761
  *	@return		int						<0 if KO, 0 if nothing done, >0 if OK
1762 1762
  */
1763
-function deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded')
1763
+function deleteFilesIntoDatabaseIndex($dir, $file, $mode = 'uploaded')
1764 1764
 {
1765 1765
 	global $conf, $db, $user;
1766 1766
 
@@ -1774,32 +1774,32 @@  discard block
 block discarded – undo
1774 1774
 
1775 1775
 	$db->begin();
1776 1776
 
1777
-	$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
1777
+	$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $dir);
1778 1778
 
1779 1779
 	$filename = basename($file);
1780 1780
 	$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
1781 1781
 	$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
1782 1782
 
1783
-	if (! $error)
1783
+	if (!$error)
1784 1784
 	{
1785
-		$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'ecm_files';
1786
-		$sql.= ' WHERE entity = '.$conf->entity;
1787
-		$sql.= " AND filepath = '" . $db->escape($rel_dir) . "'";
1788
-		if ($file) $sql.= " AND filename = '" . $db->escape($file) . "'";
1789
-		if ($mode) $sql.= " AND gen_or_uploaded = '" . $db->escape($mode) . "'";
1785
+		$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'ecm_files';
1786
+		$sql .= ' WHERE entity = '.$conf->entity;
1787
+		$sql .= " AND filepath = '".$db->escape($rel_dir)."'";
1788
+		if ($file) $sql .= " AND filename = '".$db->escape($file)."'";
1789
+		if ($mode) $sql .= " AND gen_or_uploaded = '".$db->escape($mode)."'";
1790 1790
 
1791 1791
 		$resql = $db->query($sql);
1792 1792
 		if (!$resql)
1793 1793
 		{
1794 1794
 			$error++;
1795
-			dol_syslog(__METHOD__ . ' ' . $db->lasterror(), LOG_ERR);
1795
+			dol_syslog(__METHOD__.' '.$db->lasterror(), LOG_ERR);
1796 1796
 		}
1797 1797
 	}
1798 1798
 
1799 1799
 	// Commit or rollback
1800 1800
 	if ($error) {
1801 1801
 		$db->rollback();
1802
-		return - 1 * $error;
1802
+		return -1 * $error;
1803 1803
 	} else {
1804 1804
 		$db->commit();
1805 1805
 		return 1;
@@ -1816,16 +1816,16 @@  discard block
 block discarded – undo
1816 1816
  *  @param	string	$fileoutput	Output filename
1817 1817
  *  @return	int					<0 if KO, 0=Nothing done, >0 if OK
1818 1818
  */
1819
-function dol_convert_file($fileinput, $ext='png', $fileoutput='')
1819
+function dol_convert_file($fileinput, $ext = 'png', $fileoutput = '')
1820 1820
 {
1821 1821
 	global $langs;
1822 1822
 
1823 1823
 	if (class_exists('Imagick'))
1824 1824
 	{
1825
-		$image=new Imagick();
1825
+		$image = new Imagick();
1826 1826
 		try {
1827 1827
 			$ret = $image->readImage($fileinput);
1828
-		} catch(Exception $e) {
1828
+		} catch (Exception $e) {
1829 1829
 			dol_syslog("Failed to read image using Imagick. Try to install package 'apt-get install ghostscript'.", LOG_WARNING);
1830 1830
 			return 0;
1831 1831
 		}
@@ -1834,11 +1834,11 @@  discard block
 block discarded – undo
1834 1834
 			$ret = $image->setImageFormat($ext);
1835 1835
 			if ($ret)
1836 1836
 			{
1837
-				if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext;
1837
+				if (empty($fileoutput)) $fileoutput = $fileinput.".".$ext;
1838 1838
 
1839 1839
 				$count = $image->getNumberImages();
1840 1840
 
1841
-				if (! dol_is_file($fileoutput) || is_writeable($fileoutput))
1841
+				if (!dol_is_file($fileoutput) || is_writeable($fileoutput))
1842 1842
 				{
1843 1843
 					$ret = $image->writeImages($fileoutput, true);
1844 1844
 				}
@@ -1874,20 +1874,20 @@  discard block
 block discarded – undo
1874 1874
  * @param 	string	$mode			'gz' or 'bz' or 'zip'
1875 1875
  * @return	int						<0 if KO, >0 if OK
1876 1876
  */
1877
-function dol_compress_file($inputfile, $outputfile, $mode="gz")
1877
+function dol_compress_file($inputfile, $outputfile, $mode = "gz")
1878 1878
 {
1879
-	$foundhandler=0;
1879
+	$foundhandler = 0;
1880 1880
 
1881 1881
 	try
1882 1882
 	{
1883 1883
 		$data = implode("", file(dol_osencode($inputfile)));
1884
-		if ($mode == 'gz')     { $foundhandler=1; $compressdata = gzencode($data, 9); }
1885
-		elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); }
1884
+		if ($mode == 'gz') { $foundhandler = 1; $compressdata = gzencode($data, 9); }
1885
+		elseif ($mode == 'bz') { $foundhandler = 1; $compressdata = bzcompress($data, 9); }
1886 1886
 		elseif ($mode == 'zip')
1887 1887
 		{
1888 1888
 			if (defined('ODTPHP_PATHTOPCLZIP'))
1889 1889
 			{
1890
-				$foundhandler=1;
1890
+				$foundhandler = 1;
1891 1891
 
1892 1892
 				include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
1893 1893
 				$archive = new PclZip($outputfile);
@@ -1906,7 +1906,7 @@  discard block
 block discarded – undo
1906 1906
 		}
1907 1907
 		else
1908 1908
 		{
1909
-			dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR);
1909
+			dol_syslog("Try to zip with format ".$mode." with no handler for this format", LOG_ERR);
1910 1910
 			return -2;
1911 1911
 		}
1912 1912
 	}
@@ -1914,8 +1914,8 @@  discard block
 block discarded – undo
1914 1914
 	{
1915 1915
 		global $langs, $errormsg;
1916 1916
 		$langs->load("errors");
1917
-		dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
1918
-		$errormsg=$langs->trans("ErrorFailedToWriteInDir");
1917
+		dol_syslog("Failed to open file ".$outputfile, LOG_ERR);
1918
+		$errormsg = $langs->trans("ErrorFailedToWriteInDir");
1919 1919
 		return -1;
1920 1920
 	}
1921 1921
 }
@@ -1927,7 +1927,7 @@  discard block
 block discarded – undo
1927 1927
  * @param 	string	$outputdir		Target dir name
1928 1928
  * @return 	array					array('error'=>'Error code') or array() if no error
1929 1929
  */
1930
-function dol_uncompress($inputfile,$outputdir)
1930
+function dol_uncompress($inputfile, $outputdir)
1931 1931
 {
1932 1932
 	global $langs;
1933 1933
 
@@ -1936,20 +1936,20 @@  discard block
 block discarded – undo
1936 1936
 		dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.", so we use Pclzip to unzip into ".$outputdir);
1937 1937
 		include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
1938 1938
 		$archive = new PclZip($inputfile);
1939
-		$result=$archive->extract(PCLZIP_OPT_PATH, $outputdir);
1939
+		$result = $archive->extract(PCLZIP_OPT_PATH, $outputdir);
1940 1940
 		//var_dump($result);
1941
-		if (! is_array($result) && $result <= 0) return array('error'=>$archive->errorInfo(true));
1941
+		if (!is_array($result) && $result <= 0) return array('error'=>$archive->errorInfo(true));
1942 1942
 		else
1943 1943
 		{
1944
-			$ok=1; $errmsg='';
1944
+			$ok = 1; $errmsg = '';
1945 1945
 			// Loop on each file to check result for unzipping file
1946
-			foreach($result as $key => $val)
1946
+			foreach ($result as $key => $val)
1947 1947
 			{
1948 1948
 				if ($val['status'] == 'path_creation_fail')
1949 1949
 				{
1950 1950
 					$langs->load("errors");
1951
-					$ok=0;
1952
-					$errmsg=$langs->trans("ErrorFailToCreateDir", $val['filename']);
1951
+					$ok = 0;
1952
+					$errmsg = $langs->trans("ErrorFailToCreateDir", $val['filename']);
1953 1953
 					break;
1954 1954
 				}
1955 1955
 			}
@@ -1988,24 +1988,24 @@  discard block
 block discarded – undo
1988 1988
  * @param 	string	$mode			'zip'
1989 1989
  * @return	int						<0 if KO, >0 if OK
1990 1990
  */
1991
-function dol_compress_dir($inputdir, $outputfile, $mode="zip")
1991
+function dol_compress_dir($inputdir, $outputfile, $mode = "zip")
1992 1992
 {
1993
-	$foundhandler=0;
1993
+	$foundhandler = 0;
1994 1994
 
1995 1995
 	dol_syslog("Try to zip dir ".$inputdir." into ".$outputdir." mode=".$mode);
1996 1996
 
1997
-	if (! dol_is_dir(dirname($outputfile)) || ! is_writable(dirname($outputfile)))
1997
+	if (!dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile)))
1998 1998
 	{
1999 1999
 		global $langs, $errormsg;
2000 2000
 		$langs->load("errors");
2001
-		$errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile);
2001
+		$errormsg = $langs->trans("ErrorFailedToWriteInDir", $outputfile);
2002 2002
 		return -3;
2003 2003
 	}
2004 2004
 
2005 2005
 	try
2006 2006
 	{
2007
-		if ($mode == 'gz')     { $foundhandler=0; }
2008
-		elseif ($mode == 'bz') { $foundhandler=0; }
2007
+		if ($mode == 'gz') { $foundhandler = 0; }
2008
+		elseif ($mode == 'bz') { $foundhandler = 0; }
2009 2009
 		elseif ($mode == 'zip')
2010 2010
 		{
2011 2011
 			/*if (defined('ODTPHP_PATHTOPCLZIP'))
@@ -2021,7 +2021,7 @@  discard block
 block discarded – undo
2021 2021
             else*/
2022 2022
 			if (class_exists('ZipArchive'))
2023 2023
 			{
2024
-				$foundhandler=1;
2024
+				$foundhandler = 1;
2025 2025
 
2026 2026
 				// Initialize archive object
2027 2027
 				$zip = new ZipArchive();
@@ -2055,9 +2055,9 @@  discard block
 block discarded – undo
2055 2055
 			}
2056 2056
 		}
2057 2057
 
2058
-		if (! $foundhandler)
2058
+		if (!$foundhandler)
2059 2059
 		{
2060
-			dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR);
2060
+			dol_syslog("Try to zip with format ".$mode." with no handler for this format", LOG_ERR);
2061 2061
 			return -2;
2062 2062
 		}
2063 2063
 		else
@@ -2071,7 +2071,7 @@  discard block
 block discarded – undo
2071 2071
 		$langs->load("errors");
2072 2072
 		dol_syslog("Failed to open file ".$outputfile, LOG_ERR);
2073 2073
 		dol_syslog($e->getMessage(), LOG_ERR);
2074
-		$errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile);
2074
+		$errormsg = $langs->trans("ErrorFailedToWriteInDir", $outputfile);
2075 2075
 		return -1;
2076 2076
 	}
2077 2077
 }
@@ -2088,9 +2088,9 @@  discard block
 block discarded – undo
2088 2088
  * @param	int			$mode			0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only
2089 2089
  * @return	string						Full path to most recent file
2090 2090
  */
2091
-function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('(\.meta|_preview.*\.png)$','^\.'),$nohook=false,$mode='')
2091
+function dol_most_recent_file($dir, $regexfilter = '', $excludefilter = array('(\.meta|_preview.*\.png)$', '^\.'), $nohook = false, $mode = '')
2092 2092
 {
2093
-	$tmparray=dol_dir_list($dir,'files',0,$regexfilter,$excludefilter,'date',SORT_DESC,$mode,$nohook);
2093
+	$tmparray = dol_dir_list($dir, 'files', 0, $regexfilter, $excludefilter, 'date', SORT_DESC, $mode, $nohook);
2094 2094
 	return $tmparray[0];
2095 2095
 }
2096 2096
 
@@ -2106,278 +2106,278 @@  discard block
 block discarded – undo
2106 2106
  * @return	mixed						Array with access information : 'accessallowed' & 'sqlprotectagainstexternals' & 'original_file' (as a full path name)
2107 2107
  * @see restrictedArea
2108 2108
  */
2109
-function dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser='', $refname='', $mode='read')
2109
+function dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser = '', $refname = '', $mode = 'read')
2110 2110
 {
2111 2111
 	global $conf, $db, $user;
2112 2112
 	global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2113 2113
 
2114
-	if (! is_object($fuser)) $fuser=$user;
2114
+	if (!is_object($fuser)) $fuser = $user;
2115 2115
 
2116 2116
 	if (empty($modulepart)) return 'ErrorBadParameter';
2117 2117
 	if (empty($entity))
2118 2118
 	{
2119
-		if (empty($conf->multicompany->enabled)) $entity=1;
2120
-		else $entity=0;
2119
+		if (empty($conf->multicompany->enabled)) $entity = 1;
2120
+		else $entity = 0;
2121 2121
 	}
2122 2122
 	// Fix modulepart
2123
-	if ($modulepart == 'users') $modulepart='user';
2123
+	if ($modulepart == 'users') $modulepart = 'user';
2124 2124
 
2125 2125
 	dol_syslog('modulepart='.$modulepart.' original_file='.$original_file.' entity='.$entity);
2126 2126
 	// We define $accessallowed and $sqlprotectagainstexternals
2127
-	$accessallowed=0;
2128
-	$sqlprotectagainstexternals='';
2129
-	$ret=array();
2127
+	$accessallowed = 0;
2128
+	$sqlprotectagainstexternals = '';
2129
+	$ret = array();
2130 2130
 
2131 2131
 	// Find the subdirectory name as the reference. For exemple original_file='10/myfile.pdf' -> refname='10'
2132
-	if (empty($refname)) $refname=basename(dirname($original_file)."/");
2132
+	if (empty($refname)) $refname = basename(dirname($original_file)."/");
2133 2133
 
2134 2134
 	$relative_original_file = $original_file;
2135 2135
 
2136 2136
 	// Define possible keys to use for permission check
2137
-	$lire='lire'; $read='read'; $download='download';
2137
+	$lire = 'lire'; $read = 'read'; $download = 'download';
2138 2138
 	if ($mode == 'write')
2139 2139
 	{
2140
-		$lire='creer'; $read='write'; $download='upload';
2140
+		$lire = 'creer'; $read = 'write'; $download = 'upload';
2141 2141
 	}
2142 2142
 
2143 2143
 	// Wrapping for miscellaneous medias files
2144 2144
 	if ($modulepart == 'medias' && !empty($dolibarr_main_data_root))
2145 2145
 	{
2146 2146
 		if (empty($entity) || empty($conf->medias->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2147
-		$accessallowed=1;
2148
-		$original_file=$conf->medias->multidir_output[$entity].'/'.$original_file;
2147
+		$accessallowed = 1;
2148
+		$original_file = $conf->medias->multidir_output[$entity].'/'.$original_file;
2149 2149
 	}
2150 2150
 	// Wrapping for *.log files, like when used with url http://.../document.php?modulepart=logs&file=dolibarr.log
2151 2151
 	elseif ($modulepart == 'logs' && !empty($dolibarr_main_data_root))
2152 2152
 	{
2153
-		$accessallowed=($user->admin && basename($original_file) == $original_file && preg_match('/^dolibarr.*\.log$/', basename($original_file)));
2154
-		$original_file=$dolibarr_main_data_root.'/'.$original_file;
2153
+		$accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match('/^dolibarr.*\.log$/', basename($original_file)));
2154
+		$original_file = $dolibarr_main_data_root.'/'.$original_file;
2155 2155
 	}
2156 2156
 	// Wrapping for *.zip files, like when used with url http://.../document.php?modulepart=packages&file=module_myfile.zip
2157 2157
 	elseif ($modulepart == 'packages' && !empty($dolibarr_main_data_root))
2158 2158
 	{
2159 2159
 		// Dir for custom dirs
2160
-		$tmp=explode(',', $dolibarr_main_document_root_alt);
2160
+		$tmp = explode(',', $dolibarr_main_document_root_alt);
2161 2161
 		$dirins = $tmp[0];
2162 2162
 
2163
-		$accessallowed=($user->admin && preg_match('/^module_.*\.zip$/', basename($original_file)));
2164
-		$original_file=$dirins.'/'.$original_file;
2163
+		$accessallowed = ($user->admin && preg_match('/^module_.*\.zip$/', basename($original_file)));
2164
+		$original_file = $dirins.'/'.$original_file;
2165 2165
 	}
2166 2166
 	// Wrapping for some images
2167 2167
 	elseif ($modulepart == 'mycompany' && !empty($conf->mycompany->dir_output))
2168 2168
 	{
2169
-		$accessallowed=1;
2170
-		$original_file=$conf->mycompany->dir_output.'/'.$original_file;
2169
+		$accessallowed = 1;
2170
+		$original_file = $conf->mycompany->dir_output.'/'.$original_file;
2171 2171
 	}
2172 2172
 	// Wrapping for users photos
2173 2173
 	elseif ($modulepart == 'userphoto' && !empty($conf->user->dir_output))
2174 2174
 	{
2175
-		$accessallowed=1;
2176
-		$original_file=$conf->user->dir_output.'/'.$original_file;
2175
+		$accessallowed = 1;
2176
+		$original_file = $conf->user->dir_output.'/'.$original_file;
2177 2177
 	}
2178 2178
 	// Wrapping for members photos
2179 2179
 	elseif ($modulepart == 'memberphoto' && !empty($conf->adherent->dir_output))
2180 2180
 	{
2181
-		$accessallowed=1;
2182
-		$original_file=$conf->adherent->dir_output.'/'.$original_file;
2181
+		$accessallowed = 1;
2182
+		$original_file = $conf->adherent->dir_output.'/'.$original_file;
2183 2183
 	}
2184 2184
 	// Wrapping pour les apercu factures
2185 2185
 	elseif ($modulepart == 'apercufacture' && !empty($conf->facture->dir_output))
2186 2186
 	{
2187
-		if ($fuser->rights->facture->{$lire}) $accessallowed=1;
2188
-		$original_file=$conf->facture->dir_output.'/'.$original_file;
2187
+		if ($fuser->rights->facture->{$lire}) $accessallowed = 1;
2188
+		$original_file = $conf->facture->dir_output.'/'.$original_file;
2189 2189
 	}
2190 2190
 	// Wrapping pour les apercu propal
2191 2191
 	elseif ($modulepart == 'apercupropal' && !empty($conf->propal->multidir_output[$entity]))
2192 2192
 	{
2193
-		if ($fuser->rights->propale->{$lire}) $accessallowed=1;
2194
-		$original_file=$conf->propal->multidir_output[$entity].'/'.$original_file;
2193
+		if ($fuser->rights->propale->{$lire}) $accessallowed = 1;
2194
+		$original_file = $conf->propal->multidir_output[$entity].'/'.$original_file;
2195 2195
 	}
2196 2196
 	// Wrapping pour les apercu commande
2197 2197
 	elseif ($modulepart == 'apercucommande' && !empty($conf->commande->dir_output))
2198 2198
 	{
2199
-		if ($fuser->rights->commande->{$lire}) $accessallowed=1;
2200
-		$original_file=$conf->commande->dir_output.'/'.$original_file;
2199
+		if ($fuser->rights->commande->{$lire}) $accessallowed = 1;
2200
+		$original_file = $conf->commande->dir_output.'/'.$original_file;
2201 2201
 	}
2202 2202
 	// Wrapping pour les apercu intervention
2203 2203
 	elseif (($modulepart == 'apercufichinter' || $modulepart == 'apercuficheinter') && !empty($conf->ficheinter->dir_output))
2204 2204
 	{
2205
-		if ($fuser->rights->ficheinter->{$lire}) $accessallowed=1;
2206
-		$original_file=$conf->ficheinter->dir_output.'/'.$original_file;
2205
+		if ($fuser->rights->ficheinter->{$lire}) $accessallowed = 1;
2206
+		$original_file = $conf->ficheinter->dir_output.'/'.$original_file;
2207 2207
 	}
2208 2208
 	// Wrapping pour les apercu conat
2209 2209
 	elseif (($modulepart == 'apercucontract') && !empty($conf->contrat->dir_output))
2210 2210
 	{
2211
-		if ($fuser->rights->contrat->{$lire}) $accessallowed=1;
2212
-		$original_file=$conf->contrat->dir_output.'/'.$original_file;
2211
+		if ($fuser->rights->contrat->{$lire}) $accessallowed = 1;
2212
+		$original_file = $conf->contrat->dir_output.'/'.$original_file;
2213 2213
 	}
2214 2214
 	// Wrapping pour les apercu supplier proposal
2215 2215
 	elseif (($modulepart == 'apercusupplier_proposal' || $modulepart == 'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output))
2216 2216
 	{
2217
-		if ($fuser->rights->supplier_proposal->{$lire}) $accessallowed=1;
2218
-		$original_file=$conf->supplier_proposal->dir_output.'/'.$original_file;
2217
+		if ($fuser->rights->supplier_proposal->{$lire}) $accessallowed = 1;
2218
+		$original_file = $conf->supplier_proposal->dir_output.'/'.$original_file;
2219 2219
 	}
2220 2220
 	// Wrapping pour les apercu supplier order
2221 2221
 	elseif (($modulepart == 'apercusupplier_order' || $modulepart == 'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output))
2222 2222
 	{
2223
-		if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1;
2224
-		$original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file;
2223
+		if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed = 1;
2224
+		$original_file = $conf->fournisseur->commande->dir_output.'/'.$original_file;
2225 2225
 	}
2226 2226
 	// Wrapping pour les apercu supplier invoice
2227 2227
 	elseif (($modulepart == 'apercusupplier_invoice' || $modulepart == 'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output))
2228 2228
 	{
2229
-		if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1;
2230
-		$original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file;
2229
+		if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed = 1;
2230
+		$original_file = $conf->fournisseur->facture->dir_output.'/'.$original_file;
2231 2231
 	}
2232 2232
 	// Wrapping pour les apercu supplier invoice
2233 2233
 	elseif (($modulepart == 'apercuexpensereport') && !empty($conf->expensereport->dir_output))
2234 2234
 	{
2235
-		if ($fuser->rights->expensereport->{$lire}) $accessallowed=1;
2236
-		$original_file=$conf->expensereport->dir_output.'/'.$original_file;
2235
+		if ($fuser->rights->expensereport->{$lire}) $accessallowed = 1;
2236
+		$original_file = $conf->expensereport->dir_output.'/'.$original_file;
2237 2237
 	}
2238 2238
 	// Wrapping pour les images des stats propales
2239 2239
 	elseif ($modulepart == 'propalstats' && !empty($conf->propal->multidir_temp[$entity]))
2240 2240
 	{
2241
-		if ($fuser->rights->propale->{$lire}) $accessallowed=1;
2242
-		$original_file=$conf->propal->multidir_temp[$entity].'/'.$original_file;
2241
+		if ($fuser->rights->propale->{$lire}) $accessallowed = 1;
2242
+		$original_file = $conf->propal->multidir_temp[$entity].'/'.$original_file;
2243 2243
 	}
2244 2244
 	// Wrapping pour les images des stats commandes
2245 2245
 	elseif ($modulepart == 'orderstats' && !empty($conf->commande->dir_temp))
2246 2246
 	{
2247
-		if ($fuser->rights->commande->{$lire}) $accessallowed=1;
2248
-		$original_file=$conf->commande->dir_temp.'/'.$original_file;
2247
+		if ($fuser->rights->commande->{$lire}) $accessallowed = 1;
2248
+		$original_file = $conf->commande->dir_temp.'/'.$original_file;
2249 2249
 	}
2250 2250
 	elseif ($modulepart == 'orderstatssupplier' && !empty($conf->fournisseur->dir_output))
2251 2251
 	{
2252
-		if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1;
2253
-		$original_file=$conf->fournisseur->commande->dir_temp.'/'.$original_file;
2252
+		if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed = 1;
2253
+		$original_file = $conf->fournisseur->commande->dir_temp.'/'.$original_file;
2254 2254
 	}
2255 2255
 	// Wrapping pour les images des stats factures
2256 2256
 	elseif ($modulepart == 'billstats' && !empty($conf->facture->dir_temp))
2257 2257
 	{
2258
-		if ($fuser->rights->facture->{$lire}) $accessallowed=1;
2259
-		$original_file=$conf->facture->dir_temp.'/'.$original_file;
2258
+		if ($fuser->rights->facture->{$lire}) $accessallowed = 1;
2259
+		$original_file = $conf->facture->dir_temp.'/'.$original_file;
2260 2260
 	}
2261 2261
 	elseif ($modulepart == 'billstatssupplier' && !empty($conf->fournisseur->dir_output))
2262 2262
 	{
2263
-		if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1;
2264
-		$original_file=$conf->fournisseur->facture->dir_temp.'/'.$original_file;
2263
+		if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed = 1;
2264
+		$original_file = $conf->fournisseur->facture->dir_temp.'/'.$original_file;
2265 2265
 	}
2266 2266
 	// Wrapping pour les images des stats expeditions
2267 2267
 	elseif ($modulepart == 'expeditionstats' && !empty($conf->expedition->dir_temp))
2268 2268
 	{
2269
-		if ($fuser->rights->expedition->{$lire}) $accessallowed=1;
2270
-		$original_file=$conf->expedition->dir_temp.'/'.$original_file;
2269
+		if ($fuser->rights->expedition->{$lire}) $accessallowed = 1;
2270
+		$original_file = $conf->expedition->dir_temp.'/'.$original_file;
2271 2271
 	}
2272 2272
 	// Wrapping pour les images des stats expeditions
2273 2273
 	elseif ($modulepart == 'tripsexpensesstats' && !empty($conf->deplacement->dir_temp))
2274 2274
 	{
2275
-		if ($fuser->rights->deplacement->{$lire}) $accessallowed=1;
2276
-		$original_file=$conf->deplacement->dir_temp.'/'.$original_file;
2275
+		if ($fuser->rights->deplacement->{$lire}) $accessallowed = 1;
2276
+		$original_file = $conf->deplacement->dir_temp.'/'.$original_file;
2277 2277
 	}
2278 2278
 	// Wrapping pour les images des stats expeditions
2279 2279
 	elseif ($modulepart == 'memberstats' && !empty($conf->adherent->dir_temp))
2280 2280
 	{
2281
-		if ($fuser->rights->adherent->{$lire}) $accessallowed=1;
2282
-		$original_file=$conf->adherent->dir_temp.'/'.$original_file;
2281
+		if ($fuser->rights->adherent->{$lire}) $accessallowed = 1;
2282
+		$original_file = $conf->adherent->dir_temp.'/'.$original_file;
2283 2283
 	}
2284 2284
 	// Wrapping pour les images des stats produits
2285
-	elseif (preg_match('/^productstats_/i',$modulepart) && !empty($conf->product->dir_temp))
2285
+	elseif (preg_match('/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp))
2286 2286
 	{
2287
-		if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) $accessallowed=1;
2288
-		$original_file=(!empty($conf->product->multidir_temp[$entity])?$conf->product->multidir_temp[$entity]:$conf->service->multidir_temp[$entity]).'/'.$original_file;
2287
+		if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) $accessallowed = 1;
2288
+		$original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).'/'.$original_file;
2289 2289
 	}
2290 2290
 	// Wrapping for taxes
2291 2291
 	elseif ($modulepart == 'tax' && !empty($conf->tax->dir_output))
2292 2292
 	{
2293
-		if ($fuser->rights->tax->charges->{$lire}) $accessallowed=1;
2294
-		$original_file=$conf->tax->dir_output.'/'.$original_file;
2293
+		if ($fuser->rights->tax->charges->{$lire}) $accessallowed = 1;
2294
+		$original_file = $conf->tax->dir_output.'/'.$original_file;
2295 2295
 	}
2296 2296
 	// Wrapping for events
2297 2297
 	elseif ($modulepart == 'actions' && !empty($conf->agenda->dir_output))
2298 2298
 	{
2299
-		if ($fuser->rights->agenda->myactions->{$read}) $accessallowed=1;
2300
-		$original_file=$conf->agenda->dir_output.'/'.$original_file;
2299
+		if ($fuser->rights->agenda->myactions->{$read}) $accessallowed = 1;
2300
+		$original_file = $conf->agenda->dir_output.'/'.$original_file;
2301 2301
 	}
2302 2302
 	// Wrapping for categories
2303 2303
 	elseif ($modulepart == 'category' && !empty($conf->categorie->dir_output))
2304 2304
 	{
2305 2305
 		if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2306
-		if ($fuser->rights->categorie->{$lire}) $accessallowed=1;
2307
-		$original_file=$conf->categorie->multidir_output[$entity].'/'.$original_file;
2306
+		if ($fuser->rights->categorie->{$lire}) $accessallowed = 1;
2307
+		$original_file = $conf->categorie->multidir_output[$entity].'/'.$original_file;
2308 2308
 	}
2309 2309
 	// Wrapping pour les prelevements
2310 2310
 	elseif ($modulepart == 'prelevement' && !empty($conf->prelevement->dir_output))
2311 2311
 	{
2312
-		if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i',$original_file)) $accessallowed=1;
2313
-		$original_file=$conf->prelevement->dir_output.'/'.$original_file;
2312
+		if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i', $original_file)) $accessallowed = 1;
2313
+		$original_file = $conf->prelevement->dir_output.'/'.$original_file;
2314 2314
 	}
2315 2315
 	// Wrapping pour les graph energie
2316 2316
 	elseif ($modulepart == 'graph_stock' && !empty($conf->stock->dir_temp))
2317 2317
 	{
2318
-		$accessallowed=1;
2319
-		$original_file=$conf->stock->dir_temp.'/'.$original_file;
2318
+		$accessallowed = 1;
2319
+		$original_file = $conf->stock->dir_temp.'/'.$original_file;
2320 2320
 	}
2321 2321
 	// Wrapping pour les graph fournisseurs
2322 2322
 	elseif ($modulepart == 'graph_fourn' && !empty($conf->fournisseur->dir_temp))
2323 2323
 	{
2324
-		$accessallowed=1;
2325
-		$original_file=$conf->fournisseur->dir_temp.'/'.$original_file;
2324
+		$accessallowed = 1;
2325
+		$original_file = $conf->fournisseur->dir_temp.'/'.$original_file;
2326 2326
 	}
2327 2327
 	// Wrapping pour les graph des produits
2328 2328
 	elseif ($modulepart == 'graph_product' && !empty($conf->product->dir_temp))
2329 2329
 	{
2330
-		$accessallowed=1;
2331
-		$original_file=$conf->product->multidir_temp[$entity].'/'.$original_file;
2330
+		$accessallowed = 1;
2331
+		$original_file = $conf->product->multidir_temp[$entity].'/'.$original_file;
2332 2332
 	}
2333 2333
 	// Wrapping pour les code barre
2334 2334
 	elseif ($modulepart == 'barcode')
2335 2335
 	{
2336
-		$accessallowed=1;
2336
+		$accessallowed = 1;
2337 2337
 		// If viewimage is called for barcode, we try to output an image on the fly, with no build of file on disk.
2338 2338
 		//$original_file=$conf->barcode->dir_temp.'/'.$original_file;
2339
-		$original_file='';
2339
+		$original_file = '';
2340 2340
 	}
2341 2341
 	// Wrapping pour les icones de background des mailings
2342 2342
 	elseif ($modulepart == 'iconmailing' && !empty($conf->mailing->dir_temp))
2343 2343
 	{
2344
-		$accessallowed=1;
2345
-		$original_file=$conf->mailing->dir_temp.'/'.$original_file;
2344
+		$accessallowed = 1;
2345
+		$original_file = $conf->mailing->dir_temp.'/'.$original_file;
2346 2346
 	}
2347 2347
 	// Wrapping pour le scanner
2348 2348
 	elseif ($modulepart == 'scanner_user_temp' && !empty($conf->scanner->dir_temp))
2349 2349
 	{
2350
-		$accessallowed=1;
2351
-		$original_file=$conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file;
2350
+		$accessallowed = 1;
2351
+		$original_file = $conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file;
2352 2352
 	}
2353 2353
 	// Wrapping pour les images fckeditor
2354 2354
 	elseif ($modulepart == 'fckeditor' && !empty($conf->fckeditor->dir_output))
2355 2355
 	{
2356
-		$accessallowed=1;
2357
-		$original_file=$conf->fckeditor->dir_output.'/'.$original_file;
2356
+		$accessallowed = 1;
2357
+		$original_file = $conf->fckeditor->dir_output.'/'.$original_file;
2358 2358
 	}
2359 2359
 
2360 2360
 	// Wrapping for users
2361 2361
 	else if ($modulepart == 'user' && !empty($conf->user->dir_output))
2362 2362
 	{
2363
-		$canreaduser=(! empty($fuser->admin) || $fuser->rights->user->user->{$lire});
2364
-		if ($fuser->id == (int) $refname) { $canreaduser=1; } // A user can always read its own card
2365
-		if ($canreaduser || preg_match('/^specimen/i',$original_file))
2363
+		$canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire});
2364
+		if ($fuser->id == (int) $refname) { $canreaduser = 1; } // A user can always read its own card
2365
+		if ($canreaduser || preg_match('/^specimen/i', $original_file))
2366 2366
 		{
2367
-			$accessallowed=1;
2367
+			$accessallowed = 1;
2368 2368
 		}
2369
-		$original_file=$conf->user->dir_output.'/'.$original_file;
2369
+		$original_file = $conf->user->dir_output.'/'.$original_file;
2370 2370
 	}
2371 2371
 
2372 2372
 	// Wrapping for third parties
2373 2373
 	else if (($modulepart == 'company' || $modulepart == 'societe') && !empty($conf->societe->dir_output))
2374 2374
 	{
2375 2375
 		if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2376
-		if ($fuser->rights->societe->{$lire} || preg_match('/^specimen/i',$original_file))
2376
+		if ($fuser->rights->societe->{$lire} || preg_match('/^specimen/i', $original_file))
2377 2377
 		{
2378
-			$accessallowed=1;
2378
+			$accessallowed = 1;
2379 2379
 		}
2380
-		$original_file=$conf->societe->multidir_output[$entity].'/'.$original_file;
2380
+		$original_file = $conf->societe->multidir_output[$entity].'/'.$original_file;
2381 2381
 		$sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$db->escape($refname)."' AND entity IN (".getEntity('societe').")";
2382 2382
 	}
2383 2383
 
@@ -2387,246 +2387,246 @@  discard block
 block discarded – undo
2387 2387
 		if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2388 2388
 		if ($fuser->rights->societe->{$lire})
2389 2389
 		{
2390
-			$accessallowed=1;
2390
+			$accessallowed = 1;
2391 2391
 		}
2392
-		$original_file=$conf->societe->multidir_output[$entity].'/contact/'.$original_file;
2392
+		$original_file = $conf->societe->multidir_output[$entity].'/contact/'.$original_file;
2393 2393
 	}
2394 2394
 
2395 2395
 	// Wrapping for invoices
2396 2396
 	else if (($modulepart == 'facture' || $modulepart == 'invoice') && !empty($conf->facture->dir_output))
2397 2397
 	{
2398
-		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2398
+		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2399 2399
 		{
2400
-			$accessallowed=1;
2400
+			$accessallowed = 1;
2401 2401
 		}
2402
-		$original_file=$conf->facture->dir_output.'/'.$original_file;
2402
+		$original_file = $conf->facture->dir_output.'/'.$original_file;
2403 2403
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2404 2404
 	}
2405 2405
 	// Wrapping for mass actions
2406 2406
 	else if ($modulepart == 'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity]))
2407 2407
 	{
2408
-		if ($fuser->rights->propal->{$lire} || preg_match('/^specimen/i',$original_file))
2408
+		if ($fuser->rights->propal->{$lire} || preg_match('/^specimen/i', $original_file))
2409 2409
 		{
2410
-			$accessallowed=1;
2410
+			$accessallowed = 1;
2411 2411
 		}
2412
-		$original_file=$conf->propal->multidir_output[$entity].'/temp/massgeneration/'.$user->id.'/'.$original_file;
2412
+		$original_file = $conf->propal->multidir_output[$entity].'/temp/massgeneration/'.$user->id.'/'.$original_file;
2413 2413
 	}
2414 2414
 	else if ($modulepart == 'massfilesarea_orders')
2415 2415
 	{
2416
-		if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file))
2416
+		if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i', $original_file))
2417 2417
 		{
2418
-			$accessallowed=1;
2418
+			$accessallowed = 1;
2419 2419
 		}
2420
-		$original_file=$conf->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2420
+		$original_file = $conf->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2421 2421
 	}
2422 2422
 	else if ($modulepart == 'massfilesarea_invoices')
2423 2423
 	{
2424
-		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2424
+		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2425 2425
 		{
2426
-			$accessallowed=1;
2426
+			$accessallowed = 1;
2427 2427
 		}
2428
-		$original_file=$conf->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2428
+		$original_file = $conf->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2429 2429
 	}
2430 2430
 	else if ($modulepart == 'massfilesarea_expensereport')
2431 2431
 	{
2432
-		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2432
+		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2433 2433
 		{
2434
-			$accessallowed=1;
2434
+			$accessallowed = 1;
2435 2435
 		}
2436
-		$original_file=$conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2436
+		$original_file = $conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2437 2437
 	}
2438 2438
 	else if ($modulepart == 'massfilesarea_interventions')
2439 2439
 	{
2440
-		if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file))
2440
+		if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i', $original_file))
2441 2441
 		{
2442
-			$accessallowed=1;
2442
+			$accessallowed = 1;
2443 2443
 		}
2444
-		$original_file=$conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2444
+		$original_file = $conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2445 2445
 	}
2446 2446
 	else if ($modulepart == 'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output))
2447 2447
 	{
2448
-		if ($fuser->rights->supplier_proposal->{$lire} || preg_match('/^specimen/i',$original_file))
2448
+		if ($fuser->rights->supplier_proposal->{$lire} || preg_match('/^specimen/i', $original_file))
2449 2449
 		{
2450
-			$accessallowed=1;
2450
+			$accessallowed = 1;
2451 2451
 		}
2452
-		$original_file=$conf->supplier_proposal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2452
+		$original_file = $conf->supplier_proposal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2453 2453
 	}
2454 2454
 	else if ($modulepart == 'massfilesarea_supplier_order')
2455 2455
 	{
2456
-		if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file))
2456
+		if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i', $original_file))
2457 2457
 		{
2458
-			$accessallowed=1;
2458
+			$accessallowed = 1;
2459 2459
 		}
2460
-		$original_file=$conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2460
+		$original_file = $conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2461 2461
 	}
2462 2462
 	else if ($modulepart == 'massfilesarea_supplier_invoice')
2463 2463
 	{
2464
-		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2464
+		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2465 2465
 		{
2466
-			$accessallowed=1;
2466
+			$accessallowed = 1;
2467 2467
 		}
2468
-		$original_file=$conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2468
+		$original_file = $conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2469 2469
 	}
2470 2470
 	else if ($modulepart == 'massfilesarea_contract' && !empty($conf->contrat->dir_output))
2471 2471
 	{
2472
-		if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file))
2472
+		if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i', $original_file))
2473 2473
 		{
2474
-			$accessallowed=1;
2474
+			$accessallowed = 1;
2475 2475
 		}
2476
-		$original_file=$conf->contrat->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2476
+		$original_file = $conf->contrat->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2477 2477
 	}
2478 2478
 
2479 2479
 	// Wrapping for interventions
2480 2480
 	else if (($modulepart == 'fichinter' || $modulepart == 'ficheinter') && !empty($conf->ficheinter->dir_output))
2481 2481
 	{
2482
-		if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file))
2482
+		if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i', $original_file))
2483 2483
 		{
2484
-			$accessallowed=1;
2484
+			$accessallowed = 1;
2485 2485
 		}
2486
-		$original_file=$conf->ficheinter->dir_output.'/'.$original_file;
2486
+		$original_file = $conf->ficheinter->dir_output.'/'.$original_file;
2487 2487
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2488 2488
 	}
2489 2489
 
2490 2490
 	// Wrapping pour les deplacements et notes de frais
2491 2491
 	else if ($modulepart == 'deplacement' && !empty($conf->deplacement->dir_output))
2492 2492
 	{
2493
-		if ($fuser->rights->deplacement->{$lire} || preg_match('/^specimen/i',$original_file))
2493
+		if ($fuser->rights->deplacement->{$lire} || preg_match('/^specimen/i', $original_file))
2494 2494
 		{
2495
-			$accessallowed=1;
2495
+			$accessallowed = 1;
2496 2496
 		}
2497
-		$original_file=$conf->deplacement->dir_output.'/'.$original_file;
2497
+		$original_file = $conf->deplacement->dir_output.'/'.$original_file;
2498 2498
 		//$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2499 2499
 	}
2500 2500
 	// Wrapping pour les propales
2501 2501
 	else if (($modulepart == 'propal' || $modulepart == 'propale') && !empty($conf->propal->multidir_output[$entity]))
2502 2502
 	{
2503
-		if ($fuser->rights->propale->{$lire} || preg_match('/^specimen/i',$original_file))
2503
+		if ($fuser->rights->propale->{$lire} || preg_match('/^specimen/i', $original_file))
2504 2504
 		{
2505
-			$accessallowed=1;
2505
+			$accessallowed = 1;
2506 2506
 		}
2507
-		$original_file=$conf->propal->multidir_output[$entity].'/'.$original_file;
2507
+		$original_file = $conf->propal->multidir_output[$entity].'/'.$original_file;
2508 2508
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."propal WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2509 2509
 	}
2510 2510
 
2511 2511
 	// Wrapping pour les commandes
2512 2512
 	else if (($modulepart == 'commande' || $modulepart == 'order') && !empty($conf->commande->dir_output))
2513 2513
 	{
2514
-		if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file))
2514
+		if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i', $original_file))
2515 2515
 		{
2516
-			$accessallowed=1;
2516
+			$accessallowed = 1;
2517 2517
 		}
2518
-		$original_file=$conf->commande->dir_output.'/'.$original_file;
2518
+		$original_file = $conf->commande->dir_output.'/'.$original_file;
2519 2519
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."commande WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2520 2520
 	}
2521 2521
 
2522 2522
 	// Wrapping pour les projets
2523 2523
 	else if ($modulepart == 'project' && !empty($conf->projet->dir_output))
2524 2524
 	{
2525
-		if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file))
2525
+		if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i', $original_file))
2526 2526
 		{
2527
-			$accessallowed=1;
2527
+			$accessallowed = 1;
2528 2528
 		}
2529
-		$original_file=$conf->projet->dir_output.'/'.$original_file;
2529
+		$original_file = $conf->projet->dir_output.'/'.$original_file;
2530 2530
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")";
2531 2531
 	}
2532 2532
 	else if ($modulepart == 'project_task' && !empty($conf->projet->dir_output))
2533 2533
 	{
2534
-		if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file))
2534
+		if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i', $original_file))
2535 2535
 		{
2536
-			$accessallowed=1;
2536
+			$accessallowed = 1;
2537 2537
 		}
2538
-		$original_file=$conf->projet->dir_output.'/'.$original_file;
2538
+		$original_file = $conf->projet->dir_output.'/'.$original_file;
2539 2539
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")";
2540 2540
 	}
2541 2541
 
2542 2542
 	// Wrapping pour les commandes fournisseurs
2543 2543
 	else if (($modulepart == 'commande_fournisseur' || $modulepart == 'order_supplier') && !empty($conf->fournisseur->commande->dir_output))
2544 2544
 	{
2545
-		if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file))
2545
+		if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i', $original_file))
2546 2546
 		{
2547
-			$accessallowed=1;
2547
+			$accessallowed = 1;
2548 2548
 		}
2549
-		$original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file;
2549
+		$original_file = $conf->fournisseur->commande->dir_output.'/'.$original_file;
2550 2550
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2551 2551
 	}
2552 2552
 
2553 2553
 	// Wrapping pour les factures fournisseurs
2554 2554
 	else if (($modulepart == 'facture_fournisseur' || $modulepart == 'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output))
2555 2555
 	{
2556
-		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2556
+		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2557 2557
 		{
2558
-			$accessallowed=1;
2558
+			$accessallowed = 1;
2559 2559
 		}
2560
-		$original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file;
2560
+		$original_file = $conf->fournisseur->facture->dir_output.'/'.$original_file;
2561 2561
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture_fourn WHERE facnumber='".$db->escape($refname)."' AND entity=".$conf->entity;
2562 2562
 	}
2563 2563
 	// Wrapping pour les rapport de paiements
2564 2564
 	else if ($modulepart == 'supplier_payment')
2565 2565
 	{
2566
-		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2566
+		if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2567 2567
 		{
2568
-			$accessallowed=1;
2568
+			$accessallowed = 1;
2569 2569
 		}
2570
-		$original_file=$conf->fournisseur->payment->dir_output.'/'.$original_file;
2570
+		$original_file = $conf->fournisseur->payment->dir_output.'/'.$original_file;
2571 2571
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."paiementfournisseur WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2572 2572
 	}
2573 2573
 
2574 2574
 	// Wrapping pour les rapport de paiements
2575 2575
 	else if ($modulepart == 'facture_paiement' && !empty($conf->facture->dir_output))
2576 2576
 	{
2577
-		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file))
2577
+		if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file))
2578 2578
 		{
2579
-			$accessallowed=1;
2579
+			$accessallowed = 1;
2580 2580
 		}
2581
-		if ($fuser->societe_id > 0) $original_file=$conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file;
2582
-		else $original_file=$conf->facture->dir_output.'/payments/'.$original_file;
2581
+		if ($fuser->societe_id > 0) $original_file = $conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file;
2582
+		else $original_file = $conf->facture->dir_output.'/payments/'.$original_file;
2583 2583
 	}
2584 2584
 
2585 2585
 	// Wrapping for accounting exports
2586 2586
 	else if ($modulepart == 'export_compta' && !empty($conf->accounting->dir_output))
2587 2587
 	{
2588
-		if ($fuser->rights->accounting->bind->write || preg_match('/^specimen/i',$original_file))
2588
+		if ($fuser->rights->accounting->bind->write || preg_match('/^specimen/i', $original_file))
2589 2589
 		{
2590
-			$accessallowed=1;
2590
+			$accessallowed = 1;
2591 2591
 		}
2592
-		$original_file=$conf->accounting->dir_output.'/'.$original_file;
2592
+		$original_file = $conf->accounting->dir_output.'/'.$original_file;
2593 2593
 	}
2594 2594
 
2595 2595
 	// Wrapping pour les expedition
2596 2596
 	else if ($modulepart == 'expedition' && !empty($conf->expedition->dir_output))
2597 2597
 	{
2598
-		if ($fuser->rights->expedition->{$lire} || preg_match('/^specimen/i',$original_file))
2598
+		if ($fuser->rights->expedition->{$lire} || preg_match('/^specimen/i', $original_file))
2599 2599
 		{
2600
-			$accessallowed=1;
2600
+			$accessallowed = 1;
2601 2601
 		}
2602
-		$original_file=$conf->expedition->dir_output."/sending/".$original_file;
2602
+		$original_file = $conf->expedition->dir_output."/sending/".$original_file;
2603 2603
 	}
2604 2604
 	// Wrapping pour les bons de livraison
2605 2605
 	else if ($modulepart == 'livraison' && !empty($conf->expedition->dir_output))
2606 2606
 	{
2607
-		if ($fuser->rights->expedition->livraison->{$lire} || preg_match('/^specimen/i',$original_file))
2607
+		if ($fuser->rights->expedition->livraison->{$lire} || preg_match('/^specimen/i', $original_file))
2608 2608
 		{
2609
-			$accessallowed=1;
2609
+			$accessallowed = 1;
2610 2610
 		}
2611
-		$original_file=$conf->expedition->dir_output."/receipt/".$original_file;
2611
+		$original_file = $conf->expedition->dir_output."/receipt/".$original_file;
2612 2612
 	}
2613 2613
 
2614 2614
 	// Wrapping pour les actions
2615 2615
 	else if ($modulepart == 'actions' && !empty($conf->agenda->dir_output))
2616 2616
 	{
2617
-		if ($fuser->rights->agenda->myactions->{$read} || preg_match('/^specimen/i',$original_file))
2617
+		if ($fuser->rights->agenda->myactions->{$read} || preg_match('/^specimen/i', $original_file))
2618 2618
 		{
2619
-			$accessallowed=1;
2619
+			$accessallowed = 1;
2620 2620
 		}
2621
-		$original_file=$conf->agenda->dir_output.'/'.$original_file;
2621
+		$original_file = $conf->agenda->dir_output.'/'.$original_file;
2622 2622
 	}
2623 2623
 
2624 2624
 	// Wrapping pour les actions
2625 2625
 	else if ($modulepart == 'actionsreport' && !empty($conf->agenda->dir_temp))
2626 2626
 	{
2627
-		if ($fuser->rights->agenda->allactions->{$read} || preg_match('/^specimen/i',$original_file))
2627
+		if ($fuser->rights->agenda->allactions->{$read} || preg_match('/^specimen/i', $original_file))
2628 2628
 		{
2629
-			$accessallowed=1;
2629
+			$accessallowed = 1;
2630 2630
 		}
2631 2631
 		$original_file = $conf->agenda->dir_temp."/".$original_file;
2632 2632
 	}
@@ -2635,65 +2635,65 @@  discard block
 block discarded – undo
2635 2635
 	else if ($modulepart == 'product' || $modulepart == 'produit' || $modulepart == 'service' || $modulepart == 'produit|service')
2636 2636
 	{
2637 2637
 		if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2638
-		if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match('/^specimen/i',$original_file))
2638
+		if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match('/^specimen/i', $original_file))
2639 2639
 		{
2640
-			$accessallowed=1;
2640
+			$accessallowed = 1;
2641 2641
 		}
2642
-		if (! empty($conf->product->enabled)) $original_file=$conf->product->multidir_output[$entity].'/'.$original_file;
2643
-		elseif (! empty($conf->service->enabled)) $original_file=$conf->service->multidir_output[$entity].'/'.$original_file;
2642
+		if (!empty($conf->product->enabled)) $original_file = $conf->product->multidir_output[$entity].'/'.$original_file;
2643
+		elseif (!empty($conf->service->enabled)) $original_file = $conf->service->multidir_output[$entity].'/'.$original_file;
2644 2644
 	}
2645 2645
 
2646 2646
 	// Wrapping pour les lots produits
2647 2647
 	else if ($modulepart == 'product_batch' || $modulepart == 'produitlot')
2648 2648
 	{
2649 2649
 		if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided');
2650
-		if (($fuser->rights->produit->{$lire} ) || preg_match('/^specimen/i',$original_file))
2650
+		if (($fuser->rights->produit->{$lire} ) || preg_match('/^specimen/i', $original_file))
2651 2651
 		{
2652
-			$accessallowed=1;
2652
+			$accessallowed = 1;
2653 2653
 		}
2654
-		if (! empty($conf->productbatch->enabled)) $original_file=$conf->productbatch->multidir_output[$entity].'/'.$original_file;
2654
+		if (!empty($conf->productbatch->enabled)) $original_file = $conf->productbatch->multidir_output[$entity].'/'.$original_file;
2655 2655
 	}
2656 2656
 
2657 2657
 	// Wrapping pour les contrats
2658 2658
 	else if ($modulepart == 'contract' && !empty($conf->contrat->dir_output))
2659 2659
 	{
2660
-		if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file))
2660
+		if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i', $original_file))
2661 2661
 		{
2662
-			$accessallowed=1;
2662
+			$accessallowed = 1;
2663 2663
 		}
2664
-		$original_file=$conf->contrat->dir_output.'/'.$original_file;
2664
+		$original_file = $conf->contrat->dir_output.'/'.$original_file;
2665 2665
 		$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."contrat WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('contract').")";
2666 2666
 	}
2667 2667
 
2668 2668
 	// Wrapping pour les dons
2669 2669
 	else if ($modulepart == 'donation' && !empty($conf->don->dir_output))
2670 2670
 	{
2671
-		if ($fuser->rights->don->{$lire} || preg_match('/^specimen/i',$original_file))
2671
+		if ($fuser->rights->don->{$lire} || preg_match('/^specimen/i', $original_file))
2672 2672
 		{
2673
-			$accessallowed=1;
2673
+			$accessallowed = 1;
2674 2674
 		}
2675
-		$original_file=$conf->don->dir_output.'/'.$original_file;
2675
+		$original_file = $conf->don->dir_output.'/'.$original_file;
2676 2676
 	}
2677 2677
 
2678 2678
 	// Wrapping pour les dons
2679 2679
 	else if ($modulepart == 'dolresource' && !empty($conf->resource->dir_output))
2680 2680
 	{
2681
-		if ($fuser->rights->resource->{$read} || preg_match('/^specimen/i',$original_file))
2681
+		if ($fuser->rights->resource->{$read} || preg_match('/^specimen/i', $original_file))
2682 2682
 		{
2683
-			$accessallowed=1;
2683
+			$accessallowed = 1;
2684 2684
 		}
2685
-		$original_file=$conf->resource->dir_output.'/'.$original_file;
2685
+		$original_file = $conf->resource->dir_output.'/'.$original_file;
2686 2686
 	}
2687 2687
 
2688 2688
 	// Wrapping pour les remises de cheques
2689 2689
 	else if ($modulepart == 'remisecheque' && !empty($conf->banque->dir_output))
2690 2690
 	{
2691
-		if ($fuser->rights->banque->{$lire} || preg_match('/^specimen/i',$original_file))
2691
+		if ($fuser->rights->banque->{$lire} || preg_match('/^specimen/i', $original_file))
2692 2692
 		{
2693
-			$accessallowed=1;
2693
+			$accessallowed = 1;
2694 2694
 		}
2695 2695
 
2696
-		$original_file=$conf->bank->dir_output.'/checkdeposits/'.$original_file;		// original_file should contains relative path so include the get_exdir result
2696
+		$original_file = $conf->bank->dir_output.'/checkdeposits/'.$original_file; // original_file should contains relative path so include the get_exdir result
2697 2697
 	}
2698 2698
 
2699 2699
 	// Wrapping for bank
@@ -2701,9 +2701,9 @@  discard block
 block discarded – undo
2701 2701
 	{
2702 2702
 		if ($fuser->rights->banque->{$lire})
2703 2703
 		{
2704
-			$accessallowed=1;
2704
+			$accessallowed = 1;
2705 2705
 		}
2706
-		$original_file=$conf->bank->dir_output.'/'.$original_file;
2706
+		$original_file = $conf->bank->dir_output.'/'.$original_file;
2707 2707
 	}
2708 2708
 
2709 2709
 	// Wrapping for export module
@@ -2711,62 +2711,62 @@  discard block
 block discarded – undo
2711 2711
 	{
2712 2712
 		// Aucun test necessaire car on force le rep de download sur
2713 2713
 		// le rep export qui est propre a l'utilisateur
2714
-		$accessallowed=1;
2715
-		$original_file=$conf->export->dir_temp.'/'.$fuser->id.'/'.$original_file;
2714
+		$accessallowed = 1;
2715
+		$original_file = $conf->export->dir_temp.'/'.$fuser->id.'/'.$original_file;
2716 2716
 	}
2717 2717
 
2718 2718
 	// Wrapping for import module
2719 2719
 	else if ($modulepart == 'import' && !empty($conf->import->dir_temp))
2720 2720
 	{
2721
-		$accessallowed=1;
2722
-		$original_file=$conf->import->dir_temp.'/'.$original_file;
2721
+		$accessallowed = 1;
2722
+		$original_file = $conf->import->dir_temp.'/'.$original_file;
2723 2723
 	}
2724 2724
 
2725 2725
 	// Wrapping pour l'editeur wysiwyg
2726 2726
 	else if ($modulepart == 'editor' && !empty($conf->fckeditor->dir_output))
2727 2727
 	{
2728
-		$accessallowed=1;
2729
-		$original_file=$conf->fckeditor->dir_output.'/'.$original_file;
2728
+		$accessallowed = 1;
2729
+		$original_file = $conf->fckeditor->dir_output.'/'.$original_file;
2730 2730
 	}
2731 2731
 
2732 2732
 	// Wrapping for backups
2733 2733
 	else if ($modulepart == 'systemtools' && !empty($conf->admin->dir_output))
2734 2734
 	{
2735
-		if ($fuser->admin) $accessallowed=1;
2736
-		$original_file=$conf->admin->dir_output.'/'.$original_file;
2735
+		if ($fuser->admin) $accessallowed = 1;
2736
+		$original_file = $conf->admin->dir_output.'/'.$original_file;
2737 2737
 	}
2738 2738
 
2739 2739
 	// Wrapping for upload file test
2740 2740
 	else if ($modulepart == 'admin_temp' && !empty($conf->admin->dir_temp))
2741 2741
 	{
2742
-		if ($fuser->admin) $accessallowed=1;
2743
-		$original_file=$conf->admin->dir_temp.'/'.$original_file;
2742
+		if ($fuser->admin) $accessallowed = 1;
2743
+		$original_file = $conf->admin->dir_temp.'/'.$original_file;
2744 2744
 	}
2745 2745
 
2746 2746
 	// Wrapping pour BitTorrent
2747 2747
 	else if ($modulepart == 'bittorrent' && !empty($conf->bittorrent->dir_output))
2748 2748
 	{
2749
-		$accessallowed=1;
2750
-		$dir='files';
2751
-		if (dol_mimetype($original_file) == 'application/x-bittorrent') $dir='torrents';
2752
-		$original_file=$conf->bittorrent->dir_output.'/'.$dir.'/'.$original_file;
2749
+		$accessallowed = 1;
2750
+		$dir = 'files';
2751
+		if (dol_mimetype($original_file) == 'application/x-bittorrent') $dir = 'torrents';
2752
+		$original_file = $conf->bittorrent->dir_output.'/'.$dir.'/'.$original_file;
2753 2753
 	}
2754 2754
 
2755 2755
 	// Wrapping pour Foundation module
2756 2756
 	else if ($modulepart == 'member' && !empty($conf->adherent->dir_output))
2757 2757
 	{
2758
-		if ($fuser->rights->adherent->{$lire} || preg_match('/^specimen/i',$original_file))
2758
+		if ($fuser->rights->adherent->{$lire} || preg_match('/^specimen/i', $original_file))
2759 2759
 		{
2760
-			$accessallowed=1;
2760
+			$accessallowed = 1;
2761 2761
 		}
2762
-		$original_file=$conf->adherent->dir_output.'/'.$original_file;
2762
+		$original_file = $conf->adherent->dir_output.'/'.$original_file;
2763 2763
 	}
2764 2764
 
2765 2765
 	// Wrapping for Scanner
2766 2766
 	else if ($modulepart == 'scanner_user_temp' && !empty($conf->scanner->dir_temp))
2767 2767
 	{
2768
-		$accessallowed=1;
2769
-		$original_file=$conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file;
2768
+		$accessallowed = 1;
2769
+		$original_file = $conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file;
2770 2770
 	}
2771 2771
 
2772 2772
 	// GENERIC Wrapping
@@ -2776,89 +2776,89 @@  discard block
 block discarded – undo
2776 2776
 	// If modulepart=module				Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart
2777 2777
 	else
2778 2778
 	{
2779
-		if (preg_match('/^specimen/i',$original_file))	$accessallowed=1;    // If link to a file called specimen. Test must be done before changing $original_file int full path.
2780
-		if ($fuser->admin) $accessallowed=1;    // If user is admin
2779
+		if (preg_match('/^specimen/i', $original_file))	$accessallowed = 1; // If link to a file called specimen. Test must be done before changing $original_file int full path.
2780
+		if ($fuser->admin) $accessallowed = 1; // If user is admin
2781 2781
 
2782 2782
 		// Define $accessallowed
2783
-		if (preg_match('/^([a-z]+)_user_temp$/i',$modulepart,$reg))
2783
+		if (preg_match('/^([a-z]+)_user_temp$/i', $modulepart, $reg))
2784 2784
 		{
2785 2785
 			if (empty($conf->{$reg[1]}->dir_temp))	// modulepart not supported
2786 2786
 			{
2787
-				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2787
+				dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2788 2788
 				exit;
2789 2789
 			}
2790
-			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1;
2791
-			$original_file=$conf->{$reg[1]}->dir_temp.'/'.$fuser->id.'/'.$original_file;
2790
+			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed = 1;
2791
+			$original_file = $conf->{$reg[1]}->dir_temp.'/'.$fuser->id.'/'.$original_file;
2792 2792
 		}
2793
-		else if (preg_match('/^([a-z]+)_temp$/i',$modulepart,$reg))
2793
+		else if (preg_match('/^([a-z]+)_temp$/i', $modulepart, $reg))
2794 2794
 		{
2795 2795
 			if (empty($conf->{$reg[1]}->dir_temp))	// modulepart not supported
2796 2796
 			{
2797
-				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2797
+				dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2798 2798
 				exit;
2799 2799
 			}
2800
-			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1;
2801
-			$original_file=$conf->{$reg[1]}->dir_temp.'/'.$original_file;
2800
+			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed = 1;
2801
+			$original_file = $conf->{$reg[1]}->dir_temp.'/'.$original_file;
2802 2802
 		}
2803
-		else if (preg_match('/^([a-z]+)_user$/i',$modulepart,$reg))
2803
+		else if (preg_match('/^([a-z]+)_user$/i', $modulepart, $reg))
2804 2804
 		{
2805 2805
 			if (empty($conf->{$reg[1]}->dir_output))	// modulepart not supported
2806 2806
 			{
2807
-				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2807
+				dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2808 2808
 				exit;
2809 2809
 			}
2810
-			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1;
2811
-			$original_file=$conf->{$reg[1]}->dir_output.'/'.$fuser->id.'/'.$original_file;
2810
+			if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed = 1;
2811
+			$original_file = $conf->{$reg[1]}->dir_output.'/'.$fuser->id.'/'.$original_file;
2812 2812
 		}
2813 2813
 		else if (preg_match('/^massfilesarea_([a-z]+)$/i', $modulepart, $reg))
2814 2814
 		{
2815 2815
 			if (empty($conf->{$reg[1]}->dir_output))	// modulepart not supported
2816 2816
 			{
2817
-				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2817
+				dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2818 2818
 				exit;
2819 2819
 			}
2820 2820
 			if ($fuser->rights->{$reg[1]}->{$lire} || preg_match('/^specimen/i', $original_file))
2821 2821
 			{
2822
-				$accessallowed=1;
2822
+				$accessallowed = 1;
2823 2823
 			}
2824
-			$original_file=$conf->{$reg[1]}->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2824
+			$original_file = $conf->{$reg[1]}->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file;
2825 2825
 		}
2826 2826
 		else
2827 2827
 		{
2828 2828
 			if (empty($conf->$modulepart->dir_output))	// modulepart not supported
2829 2829
 			{
2830
-				dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2830
+				dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')');
2831 2831
 				exit;
2832 2832
 			}
2833 2833
 
2834
-			$perm=GETPOST('perm');
2835
-			$subperm=GETPOST('subperm');
2834
+			$perm = GETPOST('perm');
2835
+			$subperm = GETPOST('subperm');
2836 2836
 			if ($perm || $subperm)
2837 2837
 			{
2838
-				if (($perm && ! $subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) $accessallowed=1;
2839
-				$original_file=$conf->$modulepart->dir_output.'/'.$original_file;
2838
+				if (($perm && !$subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) $accessallowed = 1;
2839
+				$original_file = $conf->$modulepart->dir_output.'/'.$original_file;
2840 2840
 			}
2841 2841
 			else
2842 2842
 			{
2843
-				if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) $accessallowed=1;
2844
-				$original_file=$conf->$modulepart->dir_output.'/'.$original_file;
2843
+				if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) $accessallowed = 1;
2844
+				$original_file = $conf->$modulepart->dir_output.'/'.$original_file;
2845 2845
 			}
2846 2846
 		}
2847 2847
 
2848 2848
 		// For modules who wants to manage different levels of permissions for documents
2849 2849
 		$subPermCategoryConstName = strtoupper($modulepart).'_SUBPERMCATEGORY_FOR_DOCUMENTS';
2850
-		if (! empty($conf->global->$subPermCategoryConstName))
2850
+		if (!empty($conf->global->$subPermCategoryConstName))
2851 2851
 		{
2852 2852
 			$subPermCategory = $conf->global->$subPermCategoryConstName;
2853
-			if (! empty($subPermCategory) && (($fuser->rights->$modulepart->$subPermCategory->{$lire}) || ($fuser->rights->$modulepart->$subPermCategory->{$read}) || ($fuser->rights->$modulepart->$subPermCategory->{$download})))
2853
+			if (!empty($subPermCategory) && (($fuser->rights->$modulepart->$subPermCategory->{$lire}) || ($fuser->rights->$modulepart->$subPermCategory->{$read}) || ($fuser->rights->$modulepart->$subPermCategory->{$download})))
2854 2854
 			{
2855
-				$accessallowed=1;
2855
+				$accessallowed = 1;
2856 2856
 			}
2857 2857
 		}
2858 2858
 
2859 2859
 		// Define $sqlprotectagainstexternals for modules who want to protect access using a SQL query.
2860 2860
 		$sqlProtectConstName = strtoupper($modulepart).'_SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS';
2861
-		if (! empty($conf->global->$sqlProtectConstName))	// If module want to define its own $sqlprotectagainstexternals
2861
+		if (!empty($conf->global->$sqlProtectConstName))	// If module want to define its own $sqlprotectagainstexternals
2862 2862
 		{
2863 2863
 			// Example: mymodule__SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS = "SELECT fk_soc FROM ".MAIN_DB_PREFIX.$modulepart." WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity;
2864 2864
 			eval('$sqlprotectagainstexternals = "'.$conf->global->$sqlProtectConstName.'";');
@@ -2884,8 +2884,8 @@  discard block
 block discarded – undo
2884 2884
  */
2885 2885
 function dol_filecache($directory, $filename, $object)
2886 2886
 {
2887
-	if (! dol_is_dir($directory)) dol_mkdir($directory);
2888
-	$cachefile = $directory . $filename;
2887
+	if (!dol_is_dir($directory)) dol_mkdir($directory);
2888
+	$cachefile = $directory.$filename;
2889 2889
 	file_put_contents($cachefile, serialize($object), LOCK_EX);
2890 2890
 	@chmod($cachefile, 0644);
2891 2891
 }
@@ -2901,8 +2901,8 @@  discard block
 block discarded – undo
2901 2901
 function dol_cache_refresh($directory, $filename, $cachetime)
2902 2902
 {
2903 2903
 	$now = dol_now();
2904
-	$cachefile = $directory . $filename;
2905
-	$refresh = !file_exists($cachefile) || ($now-$cachetime) > dol_filemtime($cachefile);
2904
+	$cachefile = $directory.$filename;
2905
+	$refresh = !file_exists($cachefile) || ($now - $cachetime) > dol_filemtime($cachefile);
2906 2906
 	return $refresh;
2907 2907
 }
2908 2908
 
@@ -2915,7 +2915,7 @@  discard block
 block discarded – undo
2915 2915
  */
2916 2916
 function dol_readcachefile($directory, $filename)
2917 2917
 {
2918
-	$cachefile = $directory . $filename;
2918
+	$cachefile = $directory.$filename;
2919 2919
 	$object = unserialize(file_get_contents($cachefile));
2920 2920
 	return $object;
2921 2921
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/expedition.lib.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 function expedition_prepare_head(Expedition $object)
36 36
 {
37 37
 	global $langs, $conf, $user;
38
-	if (! empty($conf->expedition->enabled)) $langs->load("sendings");
38
+	if (!empty($conf->expedition->enabled)) $langs->load("sendings");
39 39
 	$langs->load("orders");
40 40
 
41 41
 	$h = 0;
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
 	
49 49
 	$head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
50 50
 	$head[$h][1] = $langs->trans("Shipment");
51
-	$hselected=$h;
51
+	$hselected = $h;
52 52
 	$h++;
53 53
 	
54
-	if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
54
+	if (!empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
55 55
 	{
56 56
 		$head[$h][0] = DOL_URL_ROOT."/admin/livraison.php";
57 57
 		$head[$h][1] = $langs->trans("Receivings");
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	}
60 60
 	
61 61
 
62
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'order','remove');
62
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'order', 'remove');
63 63
 
64 64
     return $head;
65 65
 }
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	$h++;
84 84
 	
85 85
 	
86
-	if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
86
+	if (!empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
87 87
 	{
88 88
 		$head[$h][0] = DOL_URL_ROOT."/admin/expedition.php";
89 89
 		$head[$h][1] = $langs->trans("Shipment");
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	}
93 93
 	
94 94
 	
95
-	if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
95
+	if (!empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
96 96
 	{
97 97
 	$head[$h][0] = DOL_URL_ROOT.'/admin/expedition_extrafields.php';
98 98
 	$head[$h][1] = $langs->trans("ExtraFields");
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	$h++;
101 101
 	}
102 102
 	
103
-	if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
103
+	if (!empty($conf->global->MAIN_SUBMODULE_EXPEDITION))
104 104
 	{
105 105
 	$head[$h][0] = DOL_URL_ROOT.'/admin/expeditiondet_extrafields.php';
106 106
 	$head[$h][1] = $langs->trans("ExtraFieldsLines");
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	$h++;
109 109
 	}
110 110
 	
111
-	if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
111
+	if (!empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
112 112
 	{
113 113
 		$head[$h][0] = DOL_URL_ROOT."/admin/livraison.php";
114 114
 		$head[$h][1] = $langs->trans("Receivings");
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 		$h++;
117 117
 	}
118 118
 	
119
-	if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
119
+	if (!empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
120 120
 	{
121 121
 		$head[$h][0] = DOL_URL_ROOT.'/admin/livraison_extrafields.php';
122 122
 		$head[$h][1] = $langs->trans("ExtraFields");
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		$h++;
125 125
 	}
126 126
 	
127
-	if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
127
+	if (!empty($conf->global->MAIN_SUBMODULE_LIVRAISON))
128 128
 	{
129 129
 		$head[$h][0] = DOL_URL_ROOT.'/admin/livraisondet_extrafields.php';
130 130
 		$head[$h][1] = $langs->trans("ExtraFieldsLines");
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	
135 135
 	
136 136
 	
137
-	complete_head_from_modules($conf,$langs,null,$head,$h,'expedition_admin','remove');
137
+	complete_head_from_modules($conf, $langs, null, $head, $h, 'expedition_admin', 'remove');
138 138
 
139 139
 	return $head;
140 140
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/fourn.lib.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 
46 46
 	if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
47 47
 	{
48
-	    $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
48
+	    $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
49 49
 	    $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/contact.php?facid='.$object->id;
50 50
 		$head[$h][1] = $langs->trans('ContactsAddresses');
51
-		if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
51
+		if ($nbContact > 0) $head[$h][1] .= ' <span class="badge">'.$nbContact.'</span>';
52 52
 		$head[$h][2] = 'contact';
53 53
 		$h++;
54 54
 	}
@@ -57,28 +57,28 @@  discard block
 block discarded – undo
57 57
     // Entries must be declared in modules descriptor with line
58 58
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
59 59
     // $this->tabs = array('entity:-tabname);   												to remove a tab
60
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'supplier_invoice');
60
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice');
61 61
 
62 62
     if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
63 63
     {
64 64
     	$nbNote = 0;
65
-        if(!empty($object->note_private)) $nbNote++;
66
-		if(!empty($object->note_public)) $nbNote++;
65
+        if (!empty($object->note_private)) $nbNote++;
66
+		if (!empty($object->note_public)) $nbNote++;
67 67
     	$head[$h][0] = DOL_URL_ROOT.'/fourn/facture/note.php?facid='.$object->id;
68 68
     	$head[$h][1] = $langs->trans('Notes');
69
-		if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
69
+		if ($nbNote > 0) $head[$h][1] .= ' <span class="badge">'.$nbNote.'</span>';
70 70
     	$head[$h][2] = 'note';
71 71
     	$h++;
72 72
     }
73 73
 
74 74
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
75 75
     require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
76
-	$upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'invoice_supplier').$object->ref;
77
-	$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
78
-    $nbLinks=Link::count($db, $object->element, $object->id);
76
+	$upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$object->ref;
77
+	$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
78
+    $nbLinks = Link::count($db, $object->element, $object->id);
79 79
 	$head[$h][0] = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$object->id;
80 80
 	$head[$h][1] = $langs->trans('Documents');
81
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
81
+	if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>';
82 82
 	$head[$h][2] = 'documents';
83 83
 	$h++;
84 84
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	$head[$h][2] = 'info';
88 88
 	$h++;
89 89
 
90
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'supplier_invoice','remove');
90
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'remove');
91 91
 
92 92
     return $head;
93 93
 }
@@ -113,15 +113,15 @@  discard block
 block discarded – undo
113 113
 
114 114
 	if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
115 115
 	{
116
-	    $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
116
+	    $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
117 117
 	    $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/contact.php?id='.$object->id;
118 118
 		$head[$h][1] = $langs->trans('ContactsAddresses');
119
-		if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
119
+		if ($nbContact > 0) $head[$h][1] .= ' <span class="badge">'.$nbContact.'</span>';
120 120
 		$head[$h][2] = 'contact';
121 121
 		$h++;
122 122
 	}
123 123
 
124
-	if (! empty($conf->stock->enabled) && (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)))
124
+	if (!empty($conf->stock->enabled) && (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)))
125 125
 	{
126 126
 		$langs->load("stocks");
127 127
 		$head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$object->id;
@@ -134,41 +134,41 @@  discard block
 block discarded – undo
134 134
     // Entries must be declared in modules descriptor with line
135 135
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
136 136
     // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to remove a tab
137
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'supplier_order');
137
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order');
138 138
 
139 139
     if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
140 140
     {
141 141
     	$nbNote = 0;
142
-        if(!empty($object->note_private)) $nbNote++;
143
-		if(!empty($object->note_public)) $nbNote++;
142
+        if (!empty($object->note_private)) $nbNote++;
143
+		if (!empty($object->note_public)) $nbNote++;
144 144
     	$head[$h][0] = DOL_URL_ROOT.'/fourn/commande/note.php?id='.$object->id;
145 145
     	$head[$h][1] = $langs->trans("Notes");
146
-		if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
146
+		if ($nbNote > 0) $head[$h][1] .= ' <span class="badge">'.$nbNote.'</span>';
147 147
     	$head[$h][2] = 'note';
148 148
     	$h++;
149 149
     }
150 150
 
151 151
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
152 152
     require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
153
-	$upload_dir = $conf->fournisseur->dir_output . "/commande/" . dol_sanitizeFileName($object->ref);
154
-	$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
155
-    $nbLinks=Link::count($db, $object->element, $object->id);
153
+	$upload_dir = $conf->fournisseur->dir_output."/commande/".dol_sanitizeFileName($object->ref);
154
+	$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
155
+    $nbLinks = Link::count($db, $object->element, $object->id);
156 156
 	$head[$h][0] = DOL_URL_ROOT.'/fourn/commande/document.php?id='.$object->id;
157 157
 	$head[$h][1] = $langs->trans('Documents');
158
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
158
+	if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>';
159 159
 	$head[$h][2] = 'documents';
160 160
 	$h++;
161 161
 
162 162
 	$head[$h][0] = DOL_URL_ROOT.'/fourn/commande/info.php?id='.$object->id;
163
-	$head[$h][1].= $langs->trans("Events");
164
-	if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
163
+	$head[$h][1] .= $langs->trans("Events");
164
+	if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read)))
165 165
 	{
166
-	    $head[$h][1].= '/';
167
-	    $head[$h][1].= $langs->trans("Agenda");
166
+	    $head[$h][1] .= '/';
167
+	    $head[$h][1] .= $langs->trans("Agenda");
168 168
 	}
169 169
 	$head[$h][2] = 'info';
170 170
 	$h++;
171
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'supplier_order', 'remove');
171
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'remove');
172 172
 	return $head;
173 173
 }
174 174
 
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 	$head[$h][2] = 'supplierpayment';
200 200
 	$h++;
201 201
 
202
-	complete_head_from_modules($conf,$langs,null,$head,$h,'supplierorder_admin');
202
+	complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin');
203 203
 
204 204
 	$head[$h][0] = DOL_URL_ROOT.'/admin/supplierorder_extrafields.php';
205 205
 	$head[$h][1] = $langs->trans("ExtraFieldsSupplierOrders");
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 	$head[$h][2] = 'supplierinvoicedet';
224 224
 	$h++;
225 225
 
226
-	complete_head_from_modules($conf,$langs,null,$head,$h,'supplierorder_admin','remove');
226
+	complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin', 'remove');
227 227
 
228 228
 	return $head;
229 229
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/pdf.lib.php 1 patch
Spacing   +576 added lines, -576 removed lines patch added patch discarded remove patch
@@ -41,34 +41,34 @@  discard block
 block discarded – undo
41 41
  */
42 42
 function pdf_getFormat(Translate $outputlangs = null)
43 43
 {
44
-	global $conf,$db;
44
+	global $conf, $db;
45 45
 
46 46
 	// Default value if setup was not done and/or entry into c_paper_format not defined
47
-	$width=210; $height=297; $unit='mm';
47
+	$width = 210; $height = 297; $unit = 'mm';
48 48
 
49 49
 	if (empty($conf->global->MAIN_PDF_FORMAT))
50 50
 	{
51 51
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
52
-		$pdfformat=dol_getDefaultFormat($outputlangs);
52
+		$pdfformat = dol_getDefaultFormat($outputlangs);
53 53
 	}
54
-	else $pdfformat=$conf->global->MAIN_PDF_FORMAT;
54
+	else $pdfformat = $conf->global->MAIN_PDF_FORMAT;
55 55
 
56
-	$sql="SELECT code, label, width, height, unit FROM ".MAIN_DB_PREFIX."c_paper_format";
57
-	$sql.=" WHERE code = '".$pdfformat."'";
58
-	$resql=$db->query($sql);
56
+	$sql = "SELECT code, label, width, height, unit FROM ".MAIN_DB_PREFIX."c_paper_format";
57
+	$sql .= " WHERE code = '".$pdfformat."'";
58
+	$resql = $db->query($sql);
59 59
 	if ($resql)
60 60
 	{
61
-		$obj=$db->fetch_object($resql);
61
+		$obj = $db->fetch_object($resql);
62 62
 		if ($obj)
63 63
 		{
64
-			$width=(int) $obj->width;
65
-			$height=(int) $obj->height;
66
-			$unit=$obj->unit;
64
+			$width = (int) $obj->width;
65
+			$height = (int) $obj->height;
66
+			$unit = $obj->unit;
67 67
 		}
68 68
 	}
69 69
 
70 70
 	//print "pdfformat=".$pdfformat." width=".$width." height=".$height." unit=".$unit;
71
-	return array('width'=>$width,'height'=>$height,'unit'=>$unit);
71
+	return array('width'=>$width, 'height'=>$height, 'unit'=>$unit);
72 72
 }
73 73
 
74 74
 /**
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
  *      @param  string		$pagetype       'P' or 'l'
80 80
  *      @return TCPDF						PDF object
81 81
  */
82
-function pdf_getInstance($format='',$metric='mm',$pagetype='P')
82
+function pdf_getInstance($format = '', $metric = 'mm', $pagetype = 'P')
83 83
 {
84 84
 	global $conf;
85 85
 
86 86
 	// Define constant for TCPDF
87
-	if (! defined('K_TCPDF_EXTERNAL_CONFIG'))
87
+	if (!defined('K_TCPDF_EXTERNAL_CONFIG'))
88 88
 	{
89
-		define('K_TCPDF_EXTERNAL_CONFIG',1);	// this avoid using tcpdf_config file
89
+		define('K_TCPDF_EXTERNAL_CONFIG', 1); // this avoid using tcpdf_config file
90 90
 		define('K_PATH_CACHE', DOL_DATA_ROOT.'/admin/temp/');
91 91
 		define('K_PATH_URL_CACHE', DOL_DATA_ROOT.'/admin/temp/');
92 92
 		dol_mkdir(K_PATH_CACHE);
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		define('HEAD_MAGNIFICATION', 1.1);
114 114
 		define('K_CELL_HEIGHT_RATIO', 1.25);
115 115
 		define('K_TITLE_MAGNIFICATION', 1.3);
116
-		define('K_SMALL_RATIO', 2/3);
116
+		define('K_SMALL_RATIO', 2 / 3);
117 117
 		define('K_THAI_TOPCHARS', true);
118 118
 		define('K_TCPDF_CALLS_IN_HTML', true);
119 119
 		define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 	//$format=array($arrayformat['width'],$arrayformat['height']);
130 130
 	//$metric=$arrayformat['unit'];
131 131
 
132
-	$pdfa=false;											// PDF-1.3
133
-	if (! empty($conf->global->PDF_USE_1A)) $pdfa=true;		// PDF1/A
132
+	$pdfa = false; // PDF-1.3
133
+	if (!empty($conf->global->PDF_USE_1A)) $pdfa = true; // PDF1/A
134 134
 
135
-	if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format,true,'UTF-8',false,$pdfa);
136
-	else $pdf = new TCPDF($pagetype,$metric,$format,true,'UTF-8',false,$pdfa);
135
+	if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype, $metric, $format, true, 'UTF-8', false, $pdfa);
136
+	else $pdf = new TCPDF($pagetype, $metric, $format, true, 'UTF-8', false, $pdfa);
137 137
 
138 138
 	// Protection and encryption of pdf
139
-	if (! empty($conf->global->PDF_SECURITY_ENCRYPTION))
139
+	if (!empty($conf->global->PDF_SECURITY_ENCRYPTION))
140 140
 	{
141 141
 		/* Permission supported by TCPDF
142 142
 		- print : Print the document;
@@ -151,22 +151,22 @@  discard block
 block discarded – undo
151 151
 		*/
152 152
 
153 153
 		// For TCPDF, we specify permission we want to block
154
-		$pdfrights = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS)?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS, true):array('modify','copy')); // Json format in llx_const
154
+		$pdfrights = (!empty($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS) ?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS, true) : array('modify', 'copy')); // Json format in llx_const
155 155
 
156 156
 		// Password for the end user
157
-		$pdfuserpass = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_USERPASS)?$conf->global->PDF_SECURITY_ENCRYPTION_USERPASS:'');
157
+		$pdfuserpass = (!empty($conf->global->PDF_SECURITY_ENCRYPTION_USERPASS) ? $conf->global->PDF_SECURITY_ENCRYPTION_USERPASS : '');
158 158
 
159 159
 		// Password of the owner, created randomly if not defined
160
-		$pdfownerpass = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS)?$conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS:null);
160
+		$pdfownerpass = (!empty($conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS) ? $conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS : null);
161 161
 
162 162
 		// For encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit
163
-		$encstrength = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH)?$conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH:0);
163
+		$encstrength = (!empty($conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH) ? $conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH : 0);
164 164
 
165 165
 		// Array of recipients containing public-key certificates ('c') and permissions ('p').
166 166
 		// For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print')))
167
-		$pubkeys = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS)?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS, true):null); // Json format in llx_const
167
+		$pubkeys = (!empty($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS) ?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS, true) : null); // Json format in llx_const
168 168
 
169
-		$pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass,$encstrength,$pubkeys);
169
+		$pdf->SetProtection($pdfrights, $pdfuserpass, $pdfownerpass, $encstrength, $pubkeys);
170 170
 	}
171 171
 
172 172
 	return $pdf;
@@ -202,14 +202,14 @@  discard block
 block discarded – undo
202 202
 {
203 203
 	global $conf;
204 204
 
205
-	if (! empty($conf->global->MAIN_PDF_FORCE_FONT)) return $conf->global->MAIN_PDF_FORCE_FONT;
205
+	if (!empty($conf->global->MAIN_PDF_FORCE_FONT)) return $conf->global->MAIN_PDF_FORCE_FONT;
206 206
 
207
-	$font='Helvetica'; // By default, for FPDI, or ISO language on TCPDF
207
+	$font = 'Helvetica'; // By default, for FPDI, or ISO language on TCPDF
208 208
 	if (class_exists('TCPDF'))  // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
209 209
 	{
210
-		if ($outputlangs->trans('FONTFORPDF')!='FONTFORPDF')
210
+		if ($outputlangs->trans('FONTFORPDF') != 'FONTFORPDF')
211 211
 		{
212
-			$font=$outputlangs->trans('FONTFORPDF');
212
+			$font = $outputlangs->trans('FONTFORPDF');
213 213
 		}
214 214
 	}
215 215
 	return $font;
@@ -223,10 +223,10 @@  discard block
 block discarded – undo
223 223
  */
224 224
 function pdf_getPDFFontSize($outputlangs)
225 225
 {
226
-	$size=10;                   // By default, for FPDI or ISO language on TCPDF
226
+	$size = 10; // By default, for FPDI or ISO language on TCPDF
227 227
 	if (class_exists('TCPDF'))  // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
228 228
 	{
229
-		if ($outputlangs->trans('FONTSIZEFORPDF')!='FONTSIZEFORPDF')
229
+		if ($outputlangs->trans('FONTSIZEFORPDF') != 'FONTSIZEFORPDF')
230 230
 		{
231 231
 			$size = (int) $outputlangs->trans('FONTSIZEFORPDF');
232 232
 		}
@@ -245,14 +245,14 @@  discard block
 block discarded – undo
245 245
 function pdf_getHeightForLogo($logo, $url = false)
246 246
 {
247 247
 	global $conf;
248
-	$height=(empty($conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT)?22:$conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT);
249
-	$maxwidth=130;
248
+	$height = (empty($conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT) ? 22 : $conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT);
249
+	$maxwidth = 130;
250 250
 	include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
251
-	$tmp=dol_getImageSize($logo, $url);
251
+	$tmp = dol_getImageSize($logo, $url);
252 252
 	if ($tmp['height'])
253 253
 	{
254
-		$width=round($height*$tmp['width']/$tmp['height']);
255
-		if ($width > $maxwidth) $height=$height*$maxwidth/$width;
254
+		$width = round($height * $tmp['width'] / $tmp['height']);
255
+		if ($width > $maxwidth) $height = $height * $maxwidth / $width;
256 256
 	}
257 257
 	//print $tmp['width'].' '.$tmp['height'].' '.$width; exit;
258 258
 	return $height;
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
     //var_dump($start_y);
276 276
     $start_page = $pdf->getPage();
277 277
     // call printing functions with content
278
-    $pdf->writeHTMLCell(0, 0, 0, $start_y, $htmlcontent, 0, 1, false, true, 'J',true);
278
+    $pdf->writeHTMLCell(0, 0, 0, $start_y, $htmlcontent, 0, 1, false, true, 'J', true);
279 279
     // get the new Y
280 280
     $end_y = $pdf->GetY();
281 281
     $end_page = $pdf->getPage();
@@ -286,9 +286,9 @@  discard block
 block discarded – undo
286 286
     }
287 287
     else
288 288
     {
289
-        for ($page=$start_page; $page <= $end_page; ++$page) {
289
+        for ($page = $start_page; $page <= $end_page; ++$page) {
290 290
         	$pdf->setPage($page);
291
-        	$tmpm=$pdf->getMargins();
291
+        	$tmpm = $pdf->getMargins();
292 292
         	$tMargin = $tmpm['top'];
293 293
         	if ($page == $start_page) {
294 294
         		// first page
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
  * @param   int                 $includealias   1=Include alias name after name
317 317
  * @return  string                              String with name of thirdparty (+ alias if requested)
318 318
  */
319
-function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
319
+function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias = 0)
320 320
 {
321 321
     global $conf;
322 322
 
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 
326 326
 	if ($thirdparty instanceof Societe) {
327 327
 		$socname .= $thirdparty->name;
328
-		if (($includealias || ! empty($conf->global->PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME)) && !empty($thirdparty->name_alias)) {
328
+		if (($includealias || !empty($conf->global->PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME)) && !empty($thirdparty->name_alias)) {
329 329
 		    $socname .= "\n".$thirdparty->name_alias;
330 330
 		}
331 331
 	} elseif ($thirdparty instanceof Contact) {
@@ -350,28 +350,28 @@  discard block
 block discarded – undo
350 350
  *      @param  Object      $object             Object we want to build document for
351 351
  * 		@return	string							String with full address
352 352
  */
353
-function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$targetcontact='',$usecontact=0,$mode='source',$object=null)
353
+function pdf_build_address($outputlangs, $sourcecompany, $targetcompany = '', $targetcontact = '', $usecontact = 0, $mode = 'source', $object = null)
354 354
 {
355 355
 	global $conf, $hookmanager;
356 356
 
357
-	if ($mode == 'source' && ! is_object($sourcecompany)) return -1;
358
-	if ($mode == 'target' && ! is_object($targetcompany)) return -1;
357
+	if ($mode == 'source' && !is_object($sourcecompany)) return -1;
358
+	if ($mode == 'target' && !is_object($targetcompany)) return -1;
359 359
 
360
-	if (! empty($sourcecompany->state_id) && empty($sourcecompany->departement)) $sourcecompany->departement=getState($sourcecompany->state_id); //TODO deprecated
361
-	if (! empty($sourcecompany->state_id) && empty($sourcecompany->state))       $sourcecompany->state=getState($sourcecompany->state_id);
362
-	if (! empty($sourcecompany->state_id) && !isset($sourcecompany->departement_id))   $sourcecompany->departement_id=getState($sourcecompany->state_id,'2');
363
-	if (! empty($targetcompany->state_id) && empty($targetcompany->departement)) $targetcompany->departement=getState($targetcompany->state_id); //TODO deprecated
364
-	if (! empty($targetcompany->state_id) && empty($targetcompany->state))       $targetcompany->state=getState($targetcompany->state_id);
365
-	if (! empty($targetcompany->state_id) && !isset($targetcompany->departement_id))   $targetcompany->departement_id=getState($targetcompany->state_id,'2');
360
+	if (!empty($sourcecompany->state_id) && empty($sourcecompany->departement)) $sourcecompany->departement = getState($sourcecompany->state_id); //TODO deprecated
361
+	if (!empty($sourcecompany->state_id) && empty($sourcecompany->state))       $sourcecompany->state = getState($sourcecompany->state_id);
362
+	if (!empty($sourcecompany->state_id) && !isset($sourcecompany->departement_id))   $sourcecompany->departement_id = getState($sourcecompany->state_id, '2');
363
+	if (!empty($targetcompany->state_id) && empty($targetcompany->departement)) $targetcompany->departement = getState($targetcompany->state_id); //TODO deprecated
364
+	if (!empty($targetcompany->state_id) && empty($targetcompany->state))       $targetcompany->state = getState($targetcompany->state_id);
365
+	if (!empty($targetcompany->state_id) && !isset($targetcompany->departement_id))   $targetcompany->departement_id = getState($targetcompany->state_id, '2');
366 366
 
367
-	$reshook=0;
367
+	$reshook = 0;
368 368
 	$stringaddress = '';
369 369
 	if (is_object($hookmanager))
370 370
 	{
371
-		$parameters = array('sourcecompany'=>&$sourcecompany,'targetcompany'=>&$targetcompany,'targetcontact'=>$targetcontact,'outputlangs'=>$outputlangs,'mode'=>$mode,'usecontact'=>$usecontact);
372
-		$action='';
373
-		$reshook = $hookmanager->executeHooks('pdf_build_address',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
374
-		$stringaddress.=$hookmanager->resPrint;
371
+		$parameters = array('sourcecompany'=>&$sourcecompany, 'targetcompany'=>&$targetcompany, 'targetcontact'=>$targetcontact, 'outputlangs'=>$outputlangs, 'mode'=>$mode, 'usecontact'=>$usecontact);
372
+		$action = '';
373
+		$reshook = $hookmanager->executeHooks('pdf_build_address', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
374
+		$stringaddress .= $hookmanager->resPrint;
375 375
 	}
376 376
 	if (empty($reshook))
377 377
 	{
@@ -380,71 +380,71 @@  discard block
 block discarded – undo
380 380
     		$withCountry = 0;
381 381
     		if (!empty($sourcecompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) $withCountry = 1;
382 382
 
383
-    		$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($sourcecompany, $withCountry, "\n", $outputlangs))."\n";
383
+    		$stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($sourcecompany, $withCountry, "\n", $outputlangs))."\n";
384 384
 
385 385
     		if (empty($conf->global->MAIN_PDF_DISABLESOURCEDETAILS))
386 386
     		{
387 387
     			// Phone
388
-    			if ($sourcecompany->phone) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("PhoneShort").": ".$outputlangs->convToOutputCharset($sourcecompany->phone);
388
+    			if ($sourcecompany->phone) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("PhoneShort").": ".$outputlangs->convToOutputCharset($sourcecompany->phone);
389 389
     			// Fax
390
-    			if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->phone ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
390
+    			if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->phone ? " - " : "\n") : '').$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
391 391
     			// EMail
392
-    			if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
392
+    			if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
393 393
     			// Web
394
-    			if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
394
+    			if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
395 395
     		}
396 396
     		// Intra VAT
397
-    		if (! empty($conf->global->MAIN_TVAINTRA_IN_SOURCE_ADDRESS))
397
+    		if (!empty($conf->global->MAIN_TVAINTRA_IN_SOURCE_ADDRESS))
398 398
     		{
399
-    			if ($sourcecompany->tva_intra) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($sourcecompany->tva_intra);
399
+    			if ($sourcecompany->tva_intra) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($sourcecompany->tva_intra);
400 400
     		}
401 401
     		// Professionnal Ids
402
-    		if (! empty($conf->global->MAIN_PROFID1_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof1))
402
+    		if (!empty($conf->global->MAIN_PROFID1_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof1))
403 403
     		{
404
-    			$tmp=$outputlangs->transcountrynoentities("ProfId1",$sourcecompany->country_code);
405
-    			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
406
-    			$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof1);
404
+    			$tmp = $outputlangs->transcountrynoentities("ProfId1", $sourcecompany->country_code);
405
+    			if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
406
+    			$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof1);
407 407
     		}
408
-    		if (! empty($conf->global->MAIN_PROFID2_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof2))
408
+    		if (!empty($conf->global->MAIN_PROFID2_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof2))
409 409
     		{
410
-    			$tmp=$outputlangs->transcountrynoentities("ProfId2",$sourcecompany->country_code);
411
-    			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
412
-    			$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof2);
410
+    			$tmp = $outputlangs->transcountrynoentities("ProfId2", $sourcecompany->country_code);
411
+    			if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
412
+    			$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof2);
413 413
     		}
414
-    		if (! empty($conf->global->MAIN_PROFID3_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof3))
414
+    		if (!empty($conf->global->MAIN_PROFID3_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof3))
415 415
     		{
416
-    			$tmp=$outputlangs->transcountrynoentities("ProfId3",$sourcecompany->country_code);
417
-    			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
418
-    			$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof3);
416
+    			$tmp = $outputlangs->transcountrynoentities("ProfId3", $sourcecompany->country_code);
417
+    			if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
418
+    			$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof3);
419 419
     		}
420
-    		if (! empty($conf->global->MAIN_PROFID4_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof4))
420
+    		if (!empty($conf->global->MAIN_PROFID4_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof4))
421 421
     		{
422
-    			$tmp=$outputlangs->transcountrynoentities("ProfId4",$sourcecompany->country_code);
423
-    			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
424
-    			$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof4);
422
+    			$tmp = $outputlangs->transcountrynoentities("ProfId4", $sourcecompany->country_code);
423
+    			if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
424
+    			$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof4);
425 425
     		}
426
-    		if (! empty($conf->global->MAIN_PROFID5_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof5))
426
+    		if (!empty($conf->global->MAIN_PROFID5_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof5))
427 427
     		{
428
-    			$tmp=$outputlangs->transcountrynoentities("ProfId5",$sourcecompany->country_code);
429
-    			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
430
-    			$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof5);
428
+    			$tmp = $outputlangs->transcountrynoentities("ProfId5", $sourcecompany->country_code);
429
+    			if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
430
+    			$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof5);
431 431
     		}
432
-    		if (! empty($conf->global->MAIN_PROFID6_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof6))
432
+    		if (!empty($conf->global->MAIN_PROFID6_IN_SOURCE_ADDRESS) && !empty($sourcecompany->idprof6))
433 433
     		{
434
-    			$tmp=$outputlangs->transcountrynoentities("ProfId6",$sourcecompany->country_code);
435
-    			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
436
-    			$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof6);
434
+    			$tmp = $outputlangs->transcountrynoentities("ProfId6", $sourcecompany->country_code);
435
+    			if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
436
+    			$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof6);
437 437
     		}
438 438
     	}
439 439
 
440
-    	if ($mode == 'target' || preg_match('/targetwithdetails/',$mode))
440
+    	if ($mode == 'target' || preg_match('/targetwithdetails/', $mode))
441 441
     	{
442 442
     		if ($usecontact)
443 443
     		{
444
-    			$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1));
444
+    			$stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs, 1));
445 445
 
446 446
     			if (!empty($targetcontact->address)) {
447
-    				$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcontact));
447
+    				$stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($targetcontact));
448 448
     			} else {
449 449
     				$companytouseforaddress = $targetcompany;
450 450
 
@@ -455,73 +455,73 @@  discard block
 block discarded – undo
455 455
 						$companytouseforaddress = $targetcontact->thirdparty;
456 456
 					}
457 457
 
458
-					$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($companytouseforaddress));
458
+					$stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($companytouseforaddress));
459 459
 				}
460 460
     			// Country
461 461
     			if (!empty($targetcontact->country_code) && $targetcontact->country_code != $sourcecompany->country_code) {
462
-    				$stringaddress.= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->country_code));
462
+    				$stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->country_code));
463 463
     			}
464 464
     			else if (empty($targetcontact->country_code) && !empty($targetcompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) {
465
-    				$stringaddress.= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
465
+    				$stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
466 466
     			}
467 467
 
468
-    			if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/',$mode))
468
+    			if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/', $mode))
469 469
     			{
470 470
     				// Phone
471
-    			    if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/',$mode))
471
+    			    if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/', $mode))
472 472
     			    {
473
-        				if (! empty($targetcontact->phone_pro) || ! empty($targetcontact->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ";
474
-        				if (! empty($targetcontact->phone_pro)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_pro);
475
-        				if (! empty($targetcontact->phone_pro) && ! empty($targetcontact->phone_mobile)) $stringaddress .= " / ";
476
-        				if (! empty($targetcontact->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_mobile);
473
+        				if (!empty($targetcontact->phone_pro) || !empty($targetcontact->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Phone").": ";
474
+        				if (!empty($targetcontact->phone_pro)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_pro);
475
+        				if (!empty($targetcontact->phone_pro) && !empty($targetcontact->phone_mobile)) $stringaddress .= " / ";
476
+        				if (!empty($targetcontact->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_mobile);
477 477
     			    }
478 478
     				// Fax
479
-    			    if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/',$mode))
479
+    			    if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/', $mode))
480 480
     			    {
481
-                        if ($targetcontact->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcontact->fax);
481
+                        if ($targetcontact->fax) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcontact->fax);
482 482
     			    }
483 483
     				// EMail
484
-    			    if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/',$mode))
484
+    			    if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/', $mode))
485 485
     			    {
486
-                        if ($targetcontact->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcontact->email);
486
+                        if ($targetcontact->email) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcontact->email);
487 487
     			    }
488 488
     				// Web
489
-    			    if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/',$mode))
489
+    			    if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/', $mode))
490 490
     			    {
491
-                        if ($targetcontact->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcontact->url);
491
+                        if ($targetcontact->url) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcontact->url);
492 492
     			    }
493 493
     			}
494 494
     		}
495 495
     		else
496 496
     		{
497
-    			$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcompany));
497
+    			$stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($targetcompany));
498 498
     			// Country
499
-    			if (!empty($targetcompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
499
+    			if (!empty($targetcompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
500 500
 
501
-    			if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/',$mode))
501
+    			if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/', $mode))
502 502
     			{
503 503
     				// Phone
504
-    			    if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/',$mode))
504
+    			    if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/', $mode))
505 505
     			    {
506
-    			    	if (! empty($targetcompany->phone) || ! empty($targetcompany->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ";
507
-	    				if (! empty($targetcompany->phone)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone);
508
-    					if (! empty($targetcompany->phone) && ! empty($targetcompany->phone_mobile)) $stringaddress .= " / ";
509
-    					if (! empty($targetcompany->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone_mobile);
506
+    			    	if (!empty($targetcompany->phone) || !empty($targetcompany->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Phone").": ";
507
+	    				if (!empty($targetcompany->phone)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone);
508
+    					if (!empty($targetcompany->phone) && !empty($targetcompany->phone_mobile)) $stringaddress .= " / ";
509
+    					if (!empty($targetcompany->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone_mobile);
510 510
     			    }
511 511
     				// Fax
512
-    			    if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/',$mode))
512
+    			    if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/', $mode))
513 513
     			    {
514
-    			    	if ($targetcompany->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcompany->fax);
514
+    			    	if ($targetcompany->fax) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcompany->fax);
515 515
     			    }
516 516
     				// EMail
517
-    			    if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/',$mode))
517
+    			    if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/', $mode))
518 518
     			    {
519
-    			    	if ($targetcompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcompany->email);
519
+    			    	if ($targetcompany->email) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcompany->email);
520 520
     			    }
521 521
     				// Web
522
-    			    if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/',$mode))
522
+    			    if (!empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/', $mode))
523 523
     			    {
524
-    			    	if ($targetcompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcompany->url);
524
+    			    	if ($targetcompany->url) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcompany->url);
525 525
     			    }
526 526
     			}
527 527
     		}
@@ -529,57 +529,57 @@  discard block
 block discarded – undo
529 529
     		// Intra VAT
530 530
     		if (empty($conf->global->MAIN_TVAINTRA_NOT_IN_ADDRESS))
531 531
     		{
532
-    			if ($targetcompany->tva_intra) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
532
+    			if ($targetcompany->tva_intra) $stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
533 533
     		}
534 534
 
535 535
     		// Professionnal Ids
536
-    		if (! empty($conf->global->MAIN_PROFID1_IN_ADDRESS) && ! empty($targetcompany->idprof1))
536
+    		if (!empty($conf->global->MAIN_PROFID1_IN_ADDRESS) && !empty($targetcompany->idprof1))
537 537
     		{
538
-    			$tmp=$outputlangs->transcountrynoentities("ProfId1",$targetcompany->country_code);
539
-    			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
540
-    			$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
538
+    			$tmp = $outputlangs->transcountrynoentities("ProfId1", $targetcompany->country_code);
539
+    			if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
540
+    			$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
541 541
     		}
542
-    		if (! empty($conf->global->MAIN_PROFID2_IN_ADDRESS) && ! empty($targetcompany->idprof2))
542
+    		if (!empty($conf->global->MAIN_PROFID2_IN_ADDRESS) && !empty($targetcompany->idprof2))
543 543
     		{
544
-    			$tmp=$outputlangs->transcountrynoentities("ProfId2",$targetcompany->country_code);
545
-    			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
546
-    			$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
544
+    			$tmp = $outputlangs->transcountrynoentities("ProfId2", $targetcompany->country_code);
545
+    			if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
546
+    			$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
547 547
     		}
548
-    		if (! empty($conf->global->MAIN_PROFID3_IN_ADDRESS) && ! empty($targetcompany->idprof3))
548
+    		if (!empty($conf->global->MAIN_PROFID3_IN_ADDRESS) && !empty($targetcompany->idprof3))
549 549
     		{
550
-    			$tmp=$outputlangs->transcountrynoentities("ProfId3",$targetcompany->country_code);
551
-    			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
552
-    			$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
550
+    			$tmp = $outputlangs->transcountrynoentities("ProfId3", $targetcompany->country_code);
551
+    			if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
552
+    			$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
553 553
     		}
554
-    		if (! empty($conf->global->MAIN_PROFID4_IN_ADDRESS) && ! empty($targetcompany->idprof4))
554
+    		if (!empty($conf->global->MAIN_PROFID4_IN_ADDRESS) && !empty($targetcompany->idprof4))
555 555
     		{
556
-    			$tmp=$outputlangs->transcountrynoentities("ProfId4",$targetcompany->country_code);
557
-    			if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
558
-    			$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
556
+    			$tmp = $outputlangs->transcountrynoentities("ProfId4", $targetcompany->country_code);
557
+    			if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
558
+    			$stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
559 559
     		}
560
-    		if (! empty($conf->global->MAIN_PROFID5_IN_ADDRESS) && ! empty($targetcompany->idprof5))
560
+    		if (!empty($conf->global->MAIN_PROFID5_IN_ADDRESS) && !empty($targetcompany->idprof5))
561 561
     		{
562
-    		    $tmp=$outputlangs->transcountrynoentities("ProfId5",$targetcompany->country_code);
563
-    		    if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
564
-    		    $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof5);
562
+    		    $tmp = $outputlangs->transcountrynoentities("ProfId5", $targetcompany->country_code);
563
+    		    if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
564
+    		    $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof5);
565 565
     		}
566
-    		if (! empty($conf->global->MAIN_PROFID6_IN_ADDRESS) && ! empty($targetcompany->idprof6))
566
+    		if (!empty($conf->global->MAIN_PROFID6_IN_ADDRESS) && !empty($targetcompany->idprof6))
567 567
     		{
568
-    		    $tmp=$outputlangs->transcountrynoentities("ProfId6",$targetcompany->country_code);
569
-    		    if (preg_match('/\((.+)\)/',$tmp,$reg)) $tmp=$reg[1];
570
-    		    $stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof6);
568
+    		    $tmp = $outputlangs->transcountrynoentities("ProfId6", $targetcompany->country_code);
569
+    		    if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp = $reg[1];
570
+    		    $stringaddress .= ($stringaddress ? "\n" : '').$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof6);
571 571
     		}
572 572
 
573 573
     		// Public note
574
-    		if (! empty($conf->global->MAIN_PUBLIC_NOTE_IN_ADDRESS))
574
+    		if (!empty($conf->global->MAIN_PUBLIC_NOTE_IN_ADDRESS))
575 575
     		{
576
-    		    if ($mode == 'source' && ! empty($sourcecompany->note_public))
576
+    		    if ($mode == 'source' && !empty($sourcecompany->note_public))
577 577
         		{
578
-        		    $stringaddress.=($stringaddress ? "\n" : '' ).dol_string_nohtmltag($sourcecompany->note_public);
578
+        		    $stringaddress .= ($stringaddress ? "\n" : '').dol_string_nohtmltag($sourcecompany->note_public);
579 579
         		}
580
-        		if (($mode == 'target' || preg_match('/targetwithdetails/',$mode)) && ! empty($targetcompany->note_public))
580
+        		if (($mode == 'target' || preg_match('/targetwithdetails/', $mode)) && !empty($targetcompany->note_public))
581 581
         		{
582
-        		    $stringaddress.=($stringaddress ? "\n" : '' ).dol_string_nohtmltag($targetcompany->note_public);
582
+        		    $stringaddress .= ($stringaddress ? "\n" : '').dol_string_nohtmltag($targetcompany->note_public);
583 583
         		}
584 584
     		}
585 585
     	}
@@ -597,16 +597,16 @@  discard block
 block discarded – undo
597 597
  * 		@param		int			$page_height	Height of page
598 598
  *      @return	void
599 599
  */
600
-function pdf_pagehead(&$pdf,$outputlangs,$page_height)
600
+function pdf_pagehead(&$pdf, $outputlangs, $page_height)
601 601
 {
602 602
 	global $conf;
603 603
 
604 604
 	// Add a background image on document
605
-	if (! empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF))		// Warning, this option make TCPDF generation being crazy and some content disappeared behind the image
605
+	if (!empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF))		// Warning, this option make TCPDF generation being crazy and some content disappeared behind the image
606 606
 	{
607
-		$pdf->SetAutoPageBreak(0,0);	// Disable auto pagebreak before adding image
608
-		$pdf->Image($conf->mycompany->dir_output.'/logos/'.$conf->global->MAIN_USE_BACKGROUND_ON_PDF, (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_X)?$conf->global->MAIN_USE_BACKGROUND_ON_PDF_X:0), (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y)?$conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y:0), 0, $page_height);
609
-		$pdf->SetAutoPageBreak(1,0);	// Restore pagebreak
607
+		$pdf->SetAutoPageBreak(0, 0); // Disable auto pagebreak before adding image
608
+		$pdf->Image($conf->mycompany->dir_output.'/logos/'.$conf->global->MAIN_USE_BACKGROUND_ON_PDF, (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_X) ? $conf->global->MAIN_USE_BACKGROUND_ON_PDF_X : 0), (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y) ? $conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y : 0), 0, $page_height);
609
+		$pdf->SetAutoPageBreak(1, 0); // Restore pagebreak
610 610
 	}
611 611
 }
612 612
 
@@ -620,11 +620,11 @@  discard block
 block discarded – undo
620 620
  *	@param	int         $onlykey       1=Do not calculate some heavy values of keys (performance enhancement when we need only the keys), 2=Values are truncated and html sanitized (to use for help tooltip)
621 621
  *	@return	array						Array of substitutions
622 622
  */
623
-function pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
623
+function pdf_getSubstitutionArray($outputlangs, $exclude = null, $object = null, $onlykey = 0)
624 624
 {
625 625
     $substitutionarray = getCommonSubstitutionArray($outputlangs, $onlykey, $exclude, $object);
626
-    $substitutionarray['__FROM_NAME__']='__FROM_NAME__';
627
-    $substitutionarray['__FROM_EMAIL__']='__FROM_EMAIL__';
626
+    $substitutionarray['__FROM_NAME__'] = '__FROM_NAME__';
627
+    $substitutionarray['__FROM_EMAIL__'] = '__FROM_EMAIL__';
628 628
     return $substitutionarray;
629 629
 }
630 630
 
@@ -645,35 +645,35 @@  discard block
 block discarded – undo
645 645
 	global $langs, $mysoc, $user;
646 646
 
647 647
 	// Print Draft Watermark
648
-	if ($unit=='pt') $k=1;
649
-	elseif ($unit=='mm') $k=72/25.4;
650
-	elseif ($unit=='cm') $k=72/2.54;
651
-	elseif ($unit=='in') $k=72;
648
+	if ($unit == 'pt') $k = 1;
649
+	elseif ($unit == 'mm') $k = 72 / 25.4;
650
+	elseif ($unit == 'cm') $k = 72 / 2.54;
651
+	elseif ($unit == 'in') $k = 72;
652 652
 
653 653
 	// Make substitution
654
-	$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, null);
654
+	$substitutionarray = pdf_getSubstitutionArray($outputlangs, null, null);
655 655
 	complete_substitutions_array($substitutionarray, $outputlangs, null);
656
-	$text=make_substitutions($text, $substitutionarray, $outputlangs);
657
-	$text=$outputlangs->convToOutputCharset($text);
658
-
659
-	$savx=$pdf->getX(); $savy=$pdf->getY();
660
-
661
-	$watermark_angle=atan($h/$w)/2;
662
-	$watermark_x_pos=0;
663
-	$watermark_y_pos=$h/3;
664
-	$watermark_x=$w/2;
665
-	$watermark_y=$h/3;
666
-	$pdf->SetFont('','B',40);
667
-	$pdf->SetTextColor(255,192,203);
656
+	$text = make_substitutions($text, $substitutionarray, $outputlangs);
657
+	$text = $outputlangs->convToOutputCharset($text);
658
+
659
+	$savx = $pdf->getX(); $savy = $pdf->getY();
660
+
661
+	$watermark_angle = atan($h / $w) / 2;
662
+	$watermark_x_pos = 0;
663
+	$watermark_y_pos = $h / 3;
664
+	$watermark_x = $w / 2;
665
+	$watermark_y = $h / 3;
666
+	$pdf->SetFont('', 'B', 40);
667
+	$pdf->SetTextColor(255, 192, 203);
668 668
 	//rotate
669
-	$pdf->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm',cos($watermark_angle),sin($watermark_angle),-sin($watermark_angle),cos($watermark_angle),$watermark_x*$k,($h-$watermark_y)*$k,-$watermark_x*$k,-($h-$watermark_y)*$k));
669
+	$pdf->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm', cos($watermark_angle), sin($watermark_angle), -sin($watermark_angle), cos($watermark_angle), $watermark_x * $k, ($h - $watermark_y) * $k, -$watermark_x * $k, -($h - $watermark_y) * $k));
670 670
 	//print watermark
671
-	$pdf->SetXY($watermark_x_pos,$watermark_y_pos);
672
-	$pdf->Cell($w-20,25,$outputlangs->convToOutputCharset($text),"",2,"C",0);
671
+	$pdf->SetXY($watermark_x_pos, $watermark_y_pos);
672
+	$pdf->Cell($w - 20, 25, $outputlangs->convToOutputCharset($text), "", 2, "C", 0);
673 673
 	//antirotate
674 674
 	$pdf->_out('Q');
675 675
 
676
-	$pdf->SetXY($savx,$savy);
676
+	$pdf->SetXY($savx, $savy);
677 677
 }
678 678
 
679 679
 
@@ -689,43 +689,43 @@  discard block
 block discarded – undo
689 689
  *  @param	int			$default_font_size		Default font size
690 690
  *  @return	float                               The Y PDF position
691 691
  */
692
-function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account,$onlynumber=0,$default_font_size=10)
692
+function pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber = 0, $default_font_size = 10)
693 693
 {
694 694
 	global $mysoc, $conf;
695 695
 
696 696
 	require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbank.class.php';
697 697
 
698
-	$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
699
-	$diffsizecontent=(empty($conf->global->PDF_DIFFSIZE_CONTENT)?4:$conf->global->PDF_DIFFSIZE_CONTENT);
698
+	$diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
699
+	$diffsizecontent = (empty($conf->global->PDF_DIFFSIZE_CONTENT) ? 4 : $conf->global->PDF_DIFFSIZE_CONTENT);
700 700
 	$pdf->SetXY($curx, $cury);
701 701
 
702 702
 	if (empty($onlynumber))
703 703
 	{
704
-		$pdf->SetFont('','B',$default_font_size - $diffsizetitle);
704
+		$pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
705 705
 		$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0);
706
-		$cury+=4;
706
+		$cury += 4;
707 707
 	}
708 708
 
709 709
 	$outputlangs->load("banks");
710 710
 
711 711
 	// Use correct name of bank id according to country
712
-	$bickey="BICNumber";
713
-	if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
712
+	$bickey = "BICNumber";
713
+	if ($account->getCountryCode() == 'IN') $bickey = "SWIFT";
714 714
 
715 715
 	// Get format of bank account according to its country
716
-	$usedetailedbban=$account->useDetailedBBAN();
716
+	$usedetailedbban = $account->useDetailedBBAN();
717 717
 
718 718
 	//$onlynumber=0; $usedetailedbban=1; // For tests
719 719
 	if ($usedetailedbban)
720 720
 	{
721
-		$savcurx=$curx;
721
+		$savcurx = $curx;
722 722
 
723 723
 		if (empty($onlynumber))
724 724
 		{
725
-			$pdf->SetFont('','',$default_font_size - $diffsizecontent);
725
+			$pdf->SetFont('', '', $default_font_size - $diffsizecontent);
726 726
 			$pdf->SetXY($curx, $cury);
727
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
728
-			$cury+=3;
727
+			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': '.$outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
728
+			$cury += 3;
729 729
 		}
730 730
 
731 731
 		if (empty($conf->global->PDF_BANK_HIDE_NUMBER_SHOW_ONLY_BICIBAN))    // Note that some countries still need bank number, BIC/IBAN not enougth for them
@@ -735,13 +735,13 @@  discard block
 block discarded – undo
735 735
 		    // desk = code guichet (FR), used only when $usedetailedbban = 1
736 736
 		    // number = account number
737 737
 		    // key = check control key used only when $usedetailedbban = 1
738
-    		if (empty($onlynumber)) $pdf->line($curx+1, $cury+1, $curx+1, $cury+6);
738
+    		if (empty($onlynumber)) $pdf->line($curx + 1, $cury + 1, $curx + 1, $cury + 6);
739 739
 
740 740
 
741 741
 			foreach ($account->getFieldsToShow() as $val)
742 742
 			{
743
-				$pdf->SetXY($curx, $cury+4);
744
-				$pdf->SetFont('','',$default_font_size - 3);
743
+				$pdf->SetXY($curx, $cury + 4);
744
+				$pdf->SetFont('', '', $default_font_size - 3);
745 745
 
746 746
 				if ($val == 'BankCode') {
747 747
 					// Bank code
@@ -778,54 +778,54 @@  discard block
 block discarded – undo
778 778
 				}
779 779
     		}
780 780
 
781
-    		$curx=$savcurx;
782
-    		$cury+=8;
781
+    		$curx = $savcurx;
782
+    		$cury += 8;
783 783
 		}
784 784
 	}
785 785
 	else
786 786
 	{
787
-		$pdf->SetFont('','B',$default_font_size - $diffsizecontent);
787
+		$pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
788 788
 		$pdf->SetXY($curx, $cury);
789
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
790
-		$cury+=3;
789
+		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': '.$outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
790
+		$cury += 3;
791 791
 
792
-		$pdf->SetFont('','B',$default_font_size - $diffsizecontent);
792
+		$pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
793 793
 		$pdf->SetXY($curx, $cury);
794
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("BankAccountNumber").': ' . $outputlangs->convToOutputCharset($account->number), 0, 'L', 0);
795
-		$cury+=3;
794
+		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("BankAccountNumber").': '.$outputlangs->convToOutputCharset($account->number), 0, 'L', 0);
795
+		$cury += 3;
796 796
 
797
-		if ($diffsizecontent <= 2) $cury+=1;
797
+		if ($diffsizecontent <= 2) $cury += 1;
798 798
 	}
799 799
 
800
-	$pdf->SetFont('','',$default_font_size - $diffsizecontent);
800
+	$pdf->SetFont('', '', $default_font_size - $diffsizecontent);
801 801
 
802
-	if (empty($onlynumber) && ! empty($account->domiciliation))
802
+	if (empty($onlynumber) && !empty($account->domiciliation))
803 803
 	{
804 804
 		$pdf->SetXY($curx, $cury);
805
-		$val=$outputlangs->transnoentities("Residence").': ' . $outputlangs->convToOutputCharset($account->domiciliation);
805
+		$val = $outputlangs->transnoentities("Residence").': '.$outputlangs->convToOutputCharset($account->domiciliation);
806 806
 		$pdf->MultiCell(100, 3, $val, 0, 'L', 0);
807 807
 		//$nboflines=dol_nboflines_bis($val,120);
808 808
 		//$cury+=($nboflines*3)+2;
809
-		$tmpy=$pdf->getStringHeight(100, $val);
810
-		$cury+=$tmpy;
809
+		$tmpy = $pdf->getStringHeight(100, $val);
810
+		$cury += $tmpy;
811 811
 	}
812 812
 
813
-	if (! empty($account->proprio))
813
+	if (!empty($account->proprio))
814 814
 	{
815 815
 		$pdf->SetXY($curx, $cury);
816
-		$val=$outputlangs->transnoentities("BankAccountOwner").': ' . $outputlangs->convToOutputCharset($account->proprio);
816
+		$val = $outputlangs->transnoentities("BankAccountOwner").': '.$outputlangs->convToOutputCharset($account->proprio);
817 817
 		$pdf->MultiCell(100, 3, $val, 0, 'L', 0);
818
-		$tmpy=$pdf->getStringHeight(100, $val);
819
-		$cury+=$tmpy;
820
-		$cur+=1;
818
+		$tmpy = $pdf->getStringHeight(100, $val);
819
+		$cury += $tmpy;
820
+		$cur += 1;
821 821
 	}
822 822
 
823
-	else if (! $usedetailedbban) $cury+=1;
823
+	else if (!$usedetailedbban) $cury += 1;
824 824
 
825 825
 	// Use correct name of bank id according to country
826 826
 	$ibankey = FormBank::getIBANLabel($account);
827 827
 
828
-	if (! empty($account->iban))
828
+	if (!empty($account->iban))
829 829
 	{
830 830
 		//Remove whitespaces to ensure we are dealing with the format we expect
831 831
 		$ibanDisplay_temp = str_replace(' ', '', $outputlangs->convToOutputCharset($account->iban));
@@ -835,20 +835,20 @@  discard block
 block discarded – undo
835 835
 		for ($i = 0; $i < $nbIbanDisplay_temp; $i++)
836 836
 		{
837 837
 			$ibanDisplay .= $ibanDisplay_temp[$i];
838
-			if($i%4 == 3 && $i > 0)	$ibanDisplay .= " ";
838
+			if ($i % 4 == 3 && $i > 0)	$ibanDisplay .= " ";
839 839
 		}
840 840
 
841
-		$pdf->SetFont('','B',$default_font_size - 3);
841
+		$pdf->SetFont('', 'B', $default_font_size - 3);
842 842
 		$pdf->SetXY($curx, $cury);
843
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities($ibankey).': ' . $ibanDisplay, 0, 'L', 0);
844
-		$cury+=3;
843
+		$pdf->MultiCell(100, 3, $outputlangs->transnoentities($ibankey).': '.$ibanDisplay, 0, 'L', 0);
844
+		$cury += 3;
845 845
 	}
846 846
 
847
-	if (! empty($account->bic))
847
+	if (!empty($account->bic))
848 848
 	{
849
-		$pdf->SetFont('','B',$default_font_size - 3);
849
+		$pdf->SetFont('', 'B', $default_font_size - 3);
850 850
 		$pdf->SetXY($curx, $cury);
851
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities($bickey).': ' . $outputlangs->convToOutputCharset($account->bic), 0, 'L', 0);
851
+		$pdf->MultiCell(100, 3, $outputlangs->transnoentities($bickey).': '.$outputlangs->convToOutputCharset($account->bic), 0, 'L', 0);
852 852
 	}
853 853
 
854 854
 	return $pdf->getY();
@@ -869,79 +869,79 @@  discard block
 block discarded – undo
869 869
  *  @param	int			$hidefreetext	1=Hide free text, 0=Show free text
870 870
  * 	@return	int							Return height of bottom margin including footer text
871 871
  */
872
-function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object,$showdetails=0,$hidefreetext=0)
872
+function pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails = 0, $hidefreetext = 0)
873 873
 {
874
-	global $conf,$user,$mysoc;
874
+	global $conf, $user, $mysoc;
875 875
 
876 876
 	$outputlangs->load("dict");
877
-	$line='';
877
+	$line = '';
878 878
 
879
-	$dims=$pdf->getPageDimensions();
879
+	$dims = $pdf->getPageDimensions();
880 880
 
881 881
 	// Line of free text
882
-	if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext))
882
+	if (empty($hidefreetext) && !empty($conf->global->$paramfreetext))
883 883
 	{
884
-		$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
884
+		$substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
885 885
 		// More substitution keys
886
-		$substitutionarray['__FROM_NAME__']=$fromcompany->name;
887
-		$substitutionarray['__FROM_EMAIL__']=$fromcompany->email;
886
+		$substitutionarray['__FROM_NAME__'] = $fromcompany->name;
887
+		$substitutionarray['__FROM_EMAIL__'] = $fromcompany->email;
888 888
 		complete_substitutions_array($substitutionarray, $outputlangs, $object);
889
-		$newfreetext=make_substitutions($conf->global->$paramfreetext, $substitutionarray, $outputlangs);
889
+		$newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray, $outputlangs);
890 890
 
891 891
 		// Make a change into HTML code to allow to include images from medias directory.
892 892
 		// <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&amp;entity=1&amp;file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
893 893
 		// become
894 894
 		// <img alt="" src="'.DOL_DATA_ROOT.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
895
-		$newfreetext=preg_replace('/(<img.*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)("[^\/]*\/>)/', '\1'.DOL_DATA_ROOT.'/medias/\2\3', $newfreetext);
895
+		$newfreetext = preg_replace('/(<img.*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)("[^\/]*\/>)/', '\1'.DOL_DATA_ROOT.'/medias/\2\3', $newfreetext);
896 896
 
897
-		$line.=$outputlangs->convToOutputCharset($newfreetext);
897
+		$line .= $outputlangs->convToOutputCharset($newfreetext);
898 898
 	}
899 899
 
900 900
 	// First line of company infos
901
-	$line1=""; $line2=""; $line3=""; $line4="";
901
+	$line1 = ""; $line2 = ""; $line3 = ""; $line4 = "";
902 902
 
903 903
 		if ($showdetails == 1 || $showdetails == 3)
904 904
 	{
905 905
 		// Company name
906 906
 		if ($fromcompany->name)
907 907
 		{
908
-			$line1.=($line1?" - ":"").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name;
908
+			$line1 .= ($line1 ? " - " : "").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name;
909 909
 		}
910 910
 		// Address
911 911
 		if ($fromcompany->address)
912 912
 		{
913
-			$line1.=($line1?" - ":"").str_replace("\n", ", ", $fromcompany->address);
913
+			$line1 .= ($line1 ? " - " : "").str_replace("\n", ", ", $fromcompany->address);
914 914
 		}
915 915
 		// Zip code
916 916
 		if ($fromcompany->zip)
917 917
 		{
918
-			$line1.=($line1?" - ":"").$fromcompany->zip;
918
+			$line1 .= ($line1 ? " - " : "").$fromcompany->zip;
919 919
 		}
920 920
 		// Town
921 921
 		if ($fromcompany->town)
922 922
 		{
923
-			$line1.=($line1?" ":"").$fromcompany->town;
923
+			$line1 .= ($line1 ? " " : "").$fromcompany->town;
924 924
 		}
925 925
 		// Phone
926 926
 		if ($fromcompany->phone)
927 927
 		{
928
-			$line2.=($line2?" - ":"").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone;
928
+			$line2 .= ($line2 ? " - " : "").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone;
929 929
 		}
930 930
 		// Fax
931 931
 		if ($fromcompany->fax)
932 932
 		{
933
-			$line2.=($line2?" - ":"").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax;
933
+			$line2 .= ($line2 ? " - " : "").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax;
934 934
 		}
935 935
 
936 936
 		// URL
937 937
 		if ($fromcompany->url)
938 938
 		{
939
-			$line2.=($line2?" - ":"").$fromcompany->url;
939
+			$line2 .= ($line2 ? " - " : "").$fromcompany->url;
940 940
 		}
941 941
 		// Email
942 942
 		if ($fromcompany->email)
943 943
 		{
944
-			$line2.=($line2?" - ":"").$fromcompany->email;
944
+			$line2 .= ($line2 ? " - " : "").$fromcompany->email;
945 945
 		}
946 946
 	}
947 947
 	if ($showdetails == 2 || $showdetails == 3 || ($fromcompany->country_code == 'DE'))
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
 		// Managers
950 950
 		if ($fromcompany->managers)
951 951
 		{
952
-			$line2.=($line2?" - ":"").$fromcompany->managers;
952
+			$line2 .= ($line2 ? " - " : "").$fromcompany->managers;
953 953
 		}
954 954
 	}
955 955
 
@@ -957,144 +957,144 @@  discard block
 block discarded – undo
957 957
 	// Juridical status
958 958
 	if ($fromcompany->forme_juridique_code)
959 959
 	{
960
-		$line3.=($line3?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
960
+		$line3 .= ($line3 ? " - " : "").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
961 961
 	}
962 962
 	// Capital
963 963
 	if ($fromcompany->capital)
964 964
 	{
965 965
 		$tmpamounttoshow = price2num($fromcompany->capital); // This field is a free string
966
-		if (is_numeric($tmpamounttoshow) && $tmpamounttoshow > 0) $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",price($tmpamounttoshow, 0, $outputlangs, 0, 0, 0, $conf->currency));
967
-		else $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf",$tmpamounttoshow,$outputlangs);
966
+		if (is_numeric($tmpamounttoshow) && $tmpamounttoshow > 0) $line3 .= ($line3 ? " - " : "").$outputlangs->transnoentities("CapitalOf", price($tmpamounttoshow, 0, $outputlangs, 0, 0, 0, $conf->currency));
967
+		else $line3 .= ($line3 ? " - " : "").$outputlangs->transnoentities("CapitalOf", $tmpamounttoshow, $outputlangs);
968 968
 	}
969 969
 	// Prof Id 1
970
-	if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
970
+	if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2))
971 971
 	{
972
-		$field=$outputlangs->transcountrynoentities("ProfId1",$fromcompany->country_code);
973
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
974
-		$line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
972
+		$field = $outputlangs->transcountrynoentities("ProfId1", $fromcompany->country_code);
973
+		if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
974
+		$line3 .= ($line3 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
975 975
 	}
976 976
 	// Prof Id 2
977 977
 	if ($fromcompany->idprof2)
978 978
 	{
979
-		$field=$outputlangs->transcountrynoentities("ProfId2",$fromcompany->country_code);
980
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
981
-		$line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
979
+		$field = $outputlangs->transcountrynoentities("ProfId2", $fromcompany->country_code);
980
+		if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
981
+		$line3 .= ($line3 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
982 982
 	}
983 983
 
984 984
 	// Line 4 of company infos
985 985
 	// Prof Id 3
986 986
 	if ($fromcompany->idprof3)
987 987
 	{
988
-		$field=$outputlangs->transcountrynoentities("ProfId3",$fromcompany->country_code);
989
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
990
-		$line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
988
+		$field = $outputlangs->transcountrynoentities("ProfId3", $fromcompany->country_code);
989
+		if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
990
+		$line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof3);
991 991
 	}
992 992
 	// Prof Id 4
993 993
 	if ($fromcompany->idprof4)
994 994
 	{
995
-		$field=$outputlangs->transcountrynoentities("ProfId4",$fromcompany->country_code);
996
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
997
-		$line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
995
+		$field = $outputlangs->transcountrynoentities("ProfId4", $fromcompany->country_code);
996
+		if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
997
+		$line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof4);
998 998
 	}
999 999
 	// Prof Id 5
1000 1000
 	if ($fromcompany->idprof5)
1001 1001
 	{
1002
-		$field=$outputlangs->transcountrynoentities("ProfId5",$fromcompany->country_code);
1003
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
1004
-		$line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof5);
1002
+		$field = $outputlangs->transcountrynoentities("ProfId5", $fromcompany->country_code);
1003
+		if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
1004
+		$line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof5);
1005 1005
 	}
1006 1006
 	// Prof Id 6
1007 1007
 	if ($fromcompany->idprof6)
1008 1008
 	{
1009
-		$field=$outputlangs->transcountrynoentities("ProfId6",$fromcompany->country_code);
1010
-		if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1];
1011
-		$line4.=($line4?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof6);
1009
+		$field = $outputlangs->transcountrynoentities("ProfId6", $fromcompany->country_code);
1010
+		if (preg_match('/\((.*)\)/i', $field, $reg)) $field = $reg[1];
1011
+		$line4 .= ($line4 ? " - " : "").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof6);
1012 1012
 	}
1013 1013
 	// IntraCommunautary VAT
1014 1014
 	if ($fromcompany->tva_intra != '')
1015 1015
 	{
1016
-		$line4.=($line4?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
1016
+		$line4 .= ($line4 ? " - " : "").$outputlangs->transnoentities("VATIntraShort").": ".$outputlangs->convToOutputCharset($fromcompany->tva_intra);
1017 1017
 	}
1018 1018
 
1019
-	$pdf->SetFont('','',7);
1020
-	$pdf->SetDrawColor(224,224,224);
1019
+	$pdf->SetFont('', '', 7);
1020
+	$pdf->SetDrawColor(224, 224, 224);
1021 1021
 
1022 1022
 	// The start of the bottom of this page footer is positioned according to # of lines
1023
-	$freetextheight=0;
1023
+	$freetextheight = 0;
1024 1024
 	if ($line)	// Free text
1025 1025
 	{
1026 1026
 		//$line="sample text<br>\nfd<strong>sf</strong>sdf<br>\nghfghg<br>";
1027 1027
 	    if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
1028 1028
 		{
1029
-			$width=20000; $align='L';	// By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
1030
-    		if (! empty($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT)) {
1031
-    			$width=200; $align='C';
1029
+			$width = 20000; $align = 'L'; // By default, ask a manual break: We use a large value 20000, to not have automatic wrap. This make user understand, he need to add CR on its text.
1030
+    		if (!empty($conf->global->MAIN_USE_AUTOWRAP_ON_FREETEXT)) {
1031
+    			$width = 200; $align = 'C';
1032 1032
     		}
1033
-		    $freetextheight=$pdf->getStringHeight($width,$line);
1033
+		    $freetextheight = $pdf->getStringHeight($width, $line);
1034 1034
 		}
1035 1035
 		else
1036 1036
 		{
1037
-            $freetextheight=pdfGetHeightForHtmlContent($pdf,dol_htmlentitiesbr($line, 1, 'UTF-8', 0));      // New method (works for HTML content)
1037
+            $freetextheight = pdfGetHeightForHtmlContent($pdf, dol_htmlentitiesbr($line, 1, 'UTF-8', 0)); // New method (works for HTML content)
1038 1038
             //print '<br>'.$freetextheight;exit;
1039 1039
 		}
1040 1040
 	}
1041 1041
 
1042
-	$marginwithfooter=$marge_basse + $freetextheight + (! empty($line1)?3:0) + (! empty($line2)?3:0) + (! empty($line3)?3:0) + (! empty($line4)?3:0);
1043
-	$posy=$marginwithfooter+0;
1042
+	$marginwithfooter = $marge_basse + $freetextheight + (!empty($line1) ? 3 : 0) + (!empty($line2) ? 3 : 0) + (!empty($line3) ? 3 : 0) + (!empty($line4) ? 3 : 0);
1043
+	$posy = $marginwithfooter + 0;
1044 1044
 
1045 1045
 	if ($line)	// Free text
1046 1046
 	{
1047
-		$pdf->SetXY($dims['lm'],-$posy);
1047
+		$pdf->SetXY($dims['lm'], -$posy);
1048 1048
 		if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))   // by default
1049 1049
 		{
1050 1050
             $pdf->MultiCell(0, 3, $line, 0, $align, 0);
1051 1051
 		}
1052 1052
 		else
1053 1053
 		{
1054
-            $pdf->writeHTMLCell($pdf->page_largeur - $pdf->margin_left - $pdf->margin_right, $freetextheight, $dims['lm'], $dims['hk']-$marginwithfooter, dol_htmlentitiesbr($line, 1, 'UTF-8', 0));
1054
+            $pdf->writeHTMLCell($pdf->page_largeur - $pdf->margin_left - $pdf->margin_right, $freetextheight, $dims['lm'], $dims['hk'] - $marginwithfooter, dol_htmlentitiesbr($line, 1, 'UTF-8', 0));
1055 1055
 		}
1056
-		$posy-=$freetextheight;
1056
+		$posy -= $freetextheight;
1057 1057
 	}
1058 1058
 
1059 1059
 	$pdf->SetY(-$posy);
1060
-	$pdf->line($dims['lm'], $dims['hk']-$posy, $dims['wk']-$dims['rm'], $dims['hk']-$posy);
1060
+	$pdf->line($dims['lm'], $dims['hk'] - $posy, $dims['wk'] - $dims['rm'], $dims['hk'] - $posy);
1061 1061
 	$posy--;
1062 1062
 
1063
-	if (! empty($line1))
1063
+	if (!empty($line1))
1064 1064
 	{
1065
-		$pdf->SetFont('','B',7);
1066
-		$pdf->SetXY($dims['lm'],-$posy);
1067
-		$pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line1, 0, 'C', 0);
1068
-		$posy-=3;
1069
-		$pdf->SetFont('','',7);
1065
+		$pdf->SetFont('', 'B', 7);
1066
+		$pdf->SetXY($dims['lm'], -$posy);
1067
+		$pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line1, 0, 'C', 0);
1068
+		$posy -= 3;
1069
+		$pdf->SetFont('', '', 7);
1070 1070
 	}
1071 1071
 
1072
-	if (! empty($line2))
1072
+	if (!empty($line2))
1073 1073
 	{
1074
-		$pdf->SetFont('','B',7);
1075
-		$pdf->SetXY($dims['lm'],-$posy);
1076
-		$pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line2, 0, 'C', 0);
1077
-		$posy-=3;
1078
-		$pdf->SetFont('','',7);
1074
+		$pdf->SetFont('', 'B', 7);
1075
+		$pdf->SetXY($dims['lm'], -$posy);
1076
+		$pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line2, 0, 'C', 0);
1077
+		$posy -= 3;
1078
+		$pdf->SetFont('', '', 7);
1079 1079
 	}
1080 1080
 
1081
-	if (! empty($line3))
1081
+	if (!empty($line3))
1082 1082
 	{
1083
-		$pdf->SetXY($dims['lm'],-$posy);
1084
-		$pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line3, 0, 'C', 0);
1083
+		$pdf->SetXY($dims['lm'], -$posy);
1084
+		$pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line3, 0, 'C', 0);
1085 1085
 	}
1086 1086
 
1087
-	if (! empty($line4))
1087
+	if (!empty($line4))
1088 1088
 	{
1089
-		$posy-=3;
1090
-		$pdf->SetXY($dims['lm'],-$posy);
1091
-		$pdf->MultiCell($dims['wk']-$dims['rm']-$dims['lm'], 2, $line4, 0, 'C', 0);
1089
+		$posy -= 3;
1090
+		$pdf->SetXY($dims['lm'], -$posy);
1091
+		$pdf->MultiCell($dims['wk'] - $dims['rm'] - $dims['lm'], 2, $line4, 0, 'C', 0);
1092 1092
 	}
1093 1093
 
1094 1094
 	// Show page nb only on iso languages (so default Helvetica font)
1095 1095
 	if (strtolower(pdf_getPDFFont($outputlangs)) == 'helvetica')
1096 1096
 	{
1097
-		$pdf->SetXY($dims['wk']-$dims['rm']-15, -$posy);
1097
+		$pdf->SetXY($dims['wk'] - $dims['rm'] - 15, -$posy);
1098 1098
 		//print 'xxx'.$pdf->PageNo().'-'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
1099 1099
 		$pdf->MultiCell(15, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
1100 1100
 	}
@@ -1116,22 +1116,22 @@  discard block
 block discarded – undo
1116 1116
  *	@param	string		$default_font_size	Font size
1117 1117
  *	@return	float                           The Y PDF position
1118 1118
  */
1119
-function pdf_writeLinkedObjects(&$pdf,$object,$outputlangs,$posx,$posy,$w,$h,$align,$default_font_size)
1119
+function pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
1120 1120
 {
1121
-	$linkedobjects = pdf_getLinkedObjects($object,$outputlangs);
1122
-	if (! empty($linkedobjects))
1121
+	$linkedobjects = pdf_getLinkedObjects($object, $outputlangs);
1122
+	if (!empty($linkedobjects))
1123 1123
 	{
1124
-		foreach($linkedobjects as $linkedobject)
1124
+		foreach ($linkedobjects as $linkedobject)
1125 1125
 		{
1126 1126
 		    $reftoshow = $linkedobject["ref_title"].' : '.$linkedobject["ref_value"];
1127
-		    if (! empty($linkedobject["date_value"]))
1127
+		    if (!empty($linkedobject["date_value"]))
1128 1128
 		    {
1129 1129
 		        $reftoshow .= ' / '.$linkedobject["date_value"];
1130 1130
 		    }
1131 1131
 
1132
-			$posy+=3;
1133
-			$pdf->SetXY($posx,$posy);
1134
-			$pdf->SetFont('','', $default_font_size - 2);
1132
+			$posy += 3;
1133
+			$pdf->SetXY($posx, $posy);
1134
+			$pdf->SetFont('', '', $default_font_size - 2);
1135 1135
 			$pdf->MultiCell($w, $h, $reftoshow, '', $align);
1136 1136
 		}
1137 1137
 	}
@@ -1155,29 +1155,29 @@  discard block
 block discarded – undo
1155 1155
  * 	@param	int				$issupplierline		Is it a line for a supplier object ?
1156 1156
  * 	@return	string
1157 1157
  */
1158
-function pdf_writelinedesc(&$pdf,$object,$i,$outputlangs,$w,$h,$posx,$posy,$hideref=0,$hidedesc=0,$issupplierline=0)
1158
+function pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1159 1159
 {
1160 1160
 	global $db, $conf, $langs, $hookmanager;
1161 1161
 
1162
-	$reshook=0;
1163
-	$result='';
1162
+	$reshook = 0;
1163
+	$result = '';
1164 1164
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1165 1165
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1166 1166
 	{
1167 1167
 		$special_code = $object->lines[$i]->special_code;
1168
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1169
-		$parameters = array('pdf'=>$pdf,'i'=>$i,'outputlangs'=>$outputlangs,'w'=>$w,'h'=>$h,'posx'=>$posx,'posy'=>$posy,'hideref'=>$hideref,'hidedesc'=>$hidedesc,'issupplierline'=>$issupplierline,'special_code'=>$special_code);
1170
-		$action='';
1171
-		$reshook=$hookmanager->executeHooks('pdf_writelinedesc',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1168
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1169
+		$parameters = array('pdf'=>$pdf, 'i'=>$i, 'outputlangs'=>$outputlangs, 'w'=>$w, 'h'=>$h, 'posx'=>$posx, 'posy'=>$posy, 'hideref'=>$hideref, 'hidedesc'=>$hidedesc, 'issupplierline'=>$issupplierline, 'special_code'=>$special_code);
1170
+		$action = '';
1171
+		$reshook = $hookmanager->executeHooks('pdf_writelinedesc', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1172 1172
 
1173
-		if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1173
+		if (!empty($hookmanager->resPrint)) $result .= $hookmanager->resPrint;
1174 1174
 	}
1175 1175
 	if (empty($reshook))
1176 1176
 	{
1177
-		$labelproductservice=pdf_getlinedesc($object,$i,$outputlangs,$hideref,$hidedesc,$issupplierline);
1177
+		$labelproductservice = pdf_getlinedesc($object, $i, $outputlangs, $hideref, $hidedesc, $issupplierline);
1178 1178
 		// Description
1179
-		$pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J',true);
1180
-		$result.=$labelproductservice;
1179
+		$pdf->writeHTMLCell($w, $h, $posx, $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J', true);
1180
+		$result .= $labelproductservice;
1181 1181
 	}
1182 1182
 	return $result;
1183 1183
 }
@@ -1193,16 +1193,16 @@  discard block
 block discarded – undo
1193 1193
  *  @param  int			$issupplierline      Is it a line for a supplier object ?
1194 1194
  *  @return string       				     String with line
1195 1195
  */
1196
-function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0)
1196
+function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
1197 1197
 {
1198 1198
 	global $db, $conf, $langs;
1199 1199
 
1200
-	$idprod=(! empty($object->lines[$i]->fk_product)?$object->lines[$i]->fk_product:false);
1201
-	$label=(! empty($object->lines[$i]->label)?$object->lines[$i]->label:(! empty($object->lines[$i]->product_label)?$object->lines[$i]->product_label:''));
1202
-	$desc=(! empty($object->lines[$i]->desc)?$object->lines[$i]->desc:(! empty($object->lines[$i]->description)?$object->lines[$i]->description:''));
1203
-	$ref_supplier=(! empty($object->lines[$i]->ref_supplier)?$object->lines[$i]->ref_supplier:(! empty($object->lines[$i]->ref_fourn)?$object->lines[$i]->ref_fourn:''));    // TODO Not yet saved for supplier invoices, only supplier orders
1204
-	$note=(! empty($object->lines[$i]->note)?$object->lines[$i]->note:'');
1205
-	$dbatch=(! empty($object->lines[$i]->detail_batch)?$object->lines[$i]->detail_batch:false);
1200
+	$idprod = (!empty($object->lines[$i]->fk_product) ? $object->lines[$i]->fk_product : false);
1201
+	$label = (!empty($object->lines[$i]->label) ? $object->lines[$i]->label : (!empty($object->lines[$i]->product_label) ? $object->lines[$i]->product_label : ''));
1202
+	$desc = (!empty($object->lines[$i]->desc) ? $object->lines[$i]->desc : (!empty($object->lines[$i]->description) ? $object->lines[$i]->description : ''));
1203
+	$ref_supplier = (!empty($object->lines[$i]->ref_supplier) ? $object->lines[$i]->ref_supplier : (!empty($object->lines[$i]->ref_fourn) ? $object->lines[$i]->ref_fourn : '')); // TODO Not yet saved for supplier invoices, only supplier orders
1204
+	$note = (!empty($object->lines[$i]->note) ? $object->lines[$i]->note : '');
1205
+	$dbatch = (!empty($object->lines[$i]->detail_batch) ? $object->lines[$i]->detail_batch : false);
1206 1206
 
1207 1207
 	if ($issupplierline)
1208 1208
 	{
@@ -1219,9 +1219,9 @@  discard block
 block discarded – undo
1219 1219
 	{
1220 1220
 		$prodser->fetch($idprod);
1221 1221
 		// If a predefined product and multilang and on other lang, we renamed label with label translated
1222
-		if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
1222
+		if (!empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
1223 1223
 		{
1224
-			$translatealsoifmodified=(! empty($conf->global->MAIN_MULTILANG_TRANSLATE_EVEN_IF_MODIFIED));	// By default if value was modified manually, we keep it (no translation because we don't have it)
1224
+			$translatealsoifmodified = (!empty($conf->global->MAIN_MULTILANG_TRANSLATE_EVEN_IF_MODIFIED)); // By default if value was modified manually, we keep it (no translation because we don't have it)
1225 1225
 
1226 1226
 			// TODO Instead of making a compare to see if param was modified, check that content contains reference translation. If yes, add the added part to the new translation
1227 1227
 			// ($textwasmodified is replaced with $textwasmodifiedorcompleted and we add completion).
@@ -1229,63 +1229,63 @@  discard block
 block discarded – undo
1229 1229
 			// Set label
1230 1230
 			// If we want another language, and if label is same than default language (we did force it to a specific value), we can use translation.
1231 1231
 			//var_dump($outputlangs->defaultlang.' - '.$langs->defaultlang.' - '.$label.' - '.$prodser->label);exit;
1232
-			$textwasmodified=($label == $prodser->label);
1233
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && ($textwasmodified || $translatealsoifmodified))     $label=$prodser->multilangs[$outputlangs->defaultlang]["label"];
1232
+			$textwasmodified = ($label == $prodser->label);
1233
+			if (!empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && ($textwasmodified || $translatealsoifmodified))     $label = $prodser->multilangs[$outputlangs->defaultlang]["label"];
1234 1234
 
1235 1235
 			// Set desc
1236 1236
 			// Manage HTML entities description test because $prodser->description is store with htmlentities but $desc no
1237
-			$textwasmodified=false;
1237
+			$textwasmodified = false;
1238 1238
 			if (!empty($desc) && dol_textishtml($desc) && !empty($prodser->description) && dol_textishtml($prodser->description)) {
1239
-				$textwasmodified=(strpos(dol_html_entity_decode($desc,ENT_QUOTES | ENT_HTML401),dol_html_entity_decode($prodser->description,ENT_QUOTES | ENT_HTML401))!==false);
1239
+				$textwasmodified = (strpos(dol_html_entity_decode($desc, ENT_QUOTES | ENT_HTML401), dol_html_entity_decode($prodser->description, ENT_QUOTES | ENT_HTML401)) !== false);
1240 1240
 			} else {
1241
-				$textwasmodified=($desc == $prodser->description);
1241
+				$textwasmodified = ($desc == $prodser->description);
1242 1242
 			}
1243
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && ($textwasmodified || $translatealsoifmodified))  $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
1243
+			if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && ($textwasmodified || $translatealsoifmodified))  $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"];
1244 1244
 
1245 1245
 			// Set note
1246
-			$textwasmodified=($note == $prodser->note);
1247
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && ($textwasmodified || $translatealsoifmodified))  $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
1246
+			$textwasmodified = ($note == $prodser->note);
1247
+			if (!empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && ($textwasmodified || $translatealsoifmodified))  $note = $prodser->multilangs[$outputlangs->defaultlang]["note"];
1248 1248
 		}
1249 1249
 	}
1250 1250
 
1251 1251
 	// Description short of product line
1252
-	$libelleproduitservice=$label;
1252
+	$libelleproduitservice = $label;
1253 1253
 
1254 1254
 	// Description long of product line
1255
-	if (! empty($desc) && ($desc != $label))
1255
+	if (!empty($desc) && ($desc != $label))
1256 1256
 	{
1257 1257
 		if ($libelleproduitservice && empty($hidedesc))
1258 1258
 		{
1259
-			$libelleproduitservice.='__N__';
1259
+			$libelleproduitservice .= '__N__';
1260 1260
 		}
1261 1261
 
1262 1262
 		if ($desc == '(CREDIT_NOTE)' && $object->lines[$i]->fk_remise_except)
1263 1263
 		{
1264
-			$discount=new DiscountAbsolute($db);
1264
+			$discount = new DiscountAbsolute($db);
1265 1265
 			$discount->fetch($object->lines[$i]->fk_remise_except);
1266
-			$sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
1267
-			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
1266
+			$sourceref = !empty($discount->discount_type) ? $discount->ref_invoive_supplier_source : $discount->ref_facture_source;
1267
+			$libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $sourceref);
1268 1268
 		}
1269 1269
 		elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except)
1270 1270
 		{
1271
-			$discount=new DiscountAbsolute($db);
1271
+			$discount = new DiscountAbsolute($db);
1272 1272
 			$discount->fetch($object->lines[$i]->fk_remise_except);
1273
-			$sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
1274
-			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref);
1273
+			$sourceref = !empty($discount->discount_type) ? $discount->ref_invoive_supplier_source : $discount->ref_facture_source;
1274
+			$libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $sourceref);
1275 1275
 			// Add date of deposit
1276
-			if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
1276
+			if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec, 'day', '', $outputlangs).')';
1277 1277
 		}
1278 1278
 		if ($desc == '(EXCESS RECEIVED)' && $object->lines[$i]->fk_remise_except)
1279 1279
 		{
1280
-			$discount=new DiscountAbsolute($db);
1280
+			$discount = new DiscountAbsolute($db);
1281 1281
 			$discount->fetch($object->lines[$i]->fk_remise_except);
1282
-			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
1282
+			$libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived", $discount->ref_facture_source);
1283 1283
 		}
1284 1284
 		elseif ($desc == '(EXCESS PAID)' && $object->lines[$i]->fk_remise_except)
1285 1285
 		{
1286
-			$discount=new DiscountAbsolute($db);
1286
+			$discount = new DiscountAbsolute($db);
1287 1287
 			$discount->fetch($object->lines[$i]->fk_remise_except);
1288
-			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
1288
+			$libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid", $discount->ref_invoice_supplier_source);
1289 1289
 		}
1290 1290
 		else
1291 1291
 		{
@@ -1295,17 +1295,17 @@  discard block
 block discarded – undo
1295 1295
 				{
1296 1296
 					if (!empty($conf->global->MAIN_DOCUMENTS_DESCRIPTION_FIRST))
1297 1297
 					{
1298
-						$libelleproduitservice=$desc."\n".$libelleproduitservice;
1298
+						$libelleproduitservice = $desc."\n".$libelleproduitservice;
1299 1299
 					}
1300 1300
 					else
1301 1301
 					{
1302
-						$libelleproduitservice.=$desc;
1302
+						$libelleproduitservice .= $desc;
1303 1303
 					}
1304 1304
 				}
1305 1305
 			}
1306 1306
 			else
1307 1307
 			{
1308
-				$libelleproduitservice.=$desc;
1308
+				$libelleproduitservice .= $desc;
1309 1309
 			}
1310 1310
 		}
1311 1311
 	}
@@ -1313,7 +1313,7 @@  discard block
 block discarded – undo
1313 1313
 	// We add ref of product (and supplier ref if defined)
1314 1314
 	$prefix_prodserv = "";
1315 1315
 	$ref_prodserv = "";
1316
-	if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS))   // In standard mode, we do not show this
1316
+	if (!empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS))   // In standard mode, we do not show this
1317 1317
 	{
1318 1318
 		if ($prodser->isService())
1319 1319
 		{
@@ -1332,11 +1332,11 @@  discard block
 block discarded – undo
1332 1332
 			if ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 1)
1333 1333
 				$ref_prodserv = $ref_supplier;
1334 1334
 			elseif ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 2)
1335
-				$ref_prodserv = $ref_supplier. ' ('.$outputlangs->transnoentitiesnoconv("InternalRef").' '.$prodser->ref.')';
1335
+				$ref_prodserv = $ref_supplier.' ('.$outputlangs->transnoentitiesnoconv("InternalRef").' '.$prodser->ref.')';
1336 1336
 			else	// Common case
1337 1337
 			{
1338 1338
 				$ref_prodserv = $prodser->ref; // Show local ref
1339
-				if ($ref_supplier) $ref_prodserv.= ($prodser->ref?' (':'').$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.($prodser->ref?')':'');
1339
+				if ($ref_supplier) $ref_prodserv .= ($prodser->ref ? ' (' : '').$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.($prodser->ref ? ')' : '');
1340 1340
 			}
1341 1341
 		}
1342 1342
 		else
@@ -1344,71 +1344,71 @@  discard block
 block discarded – undo
1344 1344
 			$ref_prodserv = $prodser->ref; // Show local ref only
1345 1345
 		}
1346 1346
 
1347
-		if (! empty($libelleproduitservice) && ! empty($ref_prodserv)) $ref_prodserv .= " - ";
1347
+		if (!empty($libelleproduitservice) && !empty($ref_prodserv)) $ref_prodserv .= " - ";
1348 1348
 	}
1349 1349
 
1350
-	if(!empty($ref_prodserv) && !empty($conf->global->ADD_HTML_FORMATING_INTO_DESC_DOC)){ $ref_prodserv = '<b>'.$ref_prodserv.'</b>'; }
1351
-	$libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
1350
+	if (!empty($ref_prodserv) && !empty($conf->global->ADD_HTML_FORMATING_INTO_DESC_DOC)) { $ref_prodserv = '<b>'.$ref_prodserv.'</b>'; }
1351
+	$libelleproduitservice = $prefix_prodserv.$ref_prodserv.$libelleproduitservice;
1352 1352
 
1353 1353
 	// Add an additional description for the category products
1354
-	if (! empty($conf->global->CATEGORY_ADD_DESC_INTO_DOC) && $idprod && ! empty($conf->categorie->enabled))
1354
+	if (!empty($conf->global->CATEGORY_ADD_DESC_INTO_DOC) && $idprod && !empty($conf->categorie->enabled))
1355 1355
 	{
1356 1356
 		include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1357
-		$categstatic=new Categorie($db);
1357
+		$categstatic = new Categorie($db);
1358 1358
 		// recovering the list of all the categories linked to product
1359
-		$tblcateg=$categstatic->containing($idprod, Categorie::TYPE_PRODUCT);
1359
+		$tblcateg = $categstatic->containing($idprod, Categorie::TYPE_PRODUCT);
1360 1360
 		foreach ($tblcateg as $cate)
1361 1361
 		{
1362 1362
 			// Adding the descriptions if they are filled
1363
-			$desccateg=$cate->add_description;
1363
+			$desccateg = $cate->add_description;
1364 1364
 			if ($desccateg)
1365
-				$libelleproduitservice.='__N__'.$desccateg;
1365
+				$libelleproduitservice .= '__N__'.$desccateg;
1366 1366
 		}
1367 1367
 	}
1368 1368
 
1369
-	if (! empty($object->lines[$i]->date_start) || ! empty($object->lines[$i]->date_end))
1369
+	if (!empty($object->lines[$i]->date_start) || !empty($object->lines[$i]->date_end))
1370 1370
 	{
1371
-		$format='day';
1371
+		$format = 'day';
1372 1372
 		// Show duration if exists
1373 1373
 		if ($object->lines[$i]->date_start && $object->lines[$i]->date_end)
1374 1374
 		{
1375
-			$period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs),dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
1375
+			$period = '('.$outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs), dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
1376 1376
 		}
1377
-		if ($object->lines[$i]->date_start && ! $object->lines[$i]->date_end)
1377
+		if ($object->lines[$i]->date_start && !$object->lines[$i]->date_end)
1378 1378
 		{
1379
-			$period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')';
1379
+			$period = '('.$outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($object->lines[$i]->date_start, $format, false, $outputlangs)).')';
1380 1380
 		}
1381
-		if (! $object->lines[$i]->date_start && $object->lines[$i]->date_end)
1381
+		if (!$object->lines[$i]->date_start && $object->lines[$i]->date_end)
1382 1382
 		{
1383
-			$period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
1383
+			$period = '('.$outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($object->lines[$i]->date_end, $format, false, $outputlangs)).')';
1384 1384
 		}
1385 1385
 		//print '>'.$outputlangs->charset_output.','.$period;
1386
-		if(!empty($conf->global->ADD_HTML_FORMATING_INTO_DESC_DOC)){
1387
-		    $libelleproduitservice.= '<b style="color:#333666;" ><em>'."__N__</b> ".$period.'</em>';
1388
-		}else{
1389
-		$libelleproduitservice.="__N__".$period;
1386
+		if (!empty($conf->global->ADD_HTML_FORMATING_INTO_DESC_DOC)) {
1387
+		    $libelleproduitservice .= '<b style="color:#333666;" ><em>'."__N__</b> ".$period.'</em>';
1388
+		} else {
1389
+		$libelleproduitservice .= "__N__".$period;
1390 1390
 		}
1391 1391
 		//print $libelleproduitservice;
1392 1392
 	}
1393 1393
 
1394 1394
 	if ($dbatch)
1395 1395
 	{
1396
-		$format='day';
1396
+		$format = 'day';
1397 1397
 		foreach ($dbatch as $detail)
1398 1398
 		{
1399
-			$dte=array();
1400
-			if ($detail->eatby) $dte[]=$outputlangs->transnoentitiesnoconv('printEatby',dol_print_date($detail->eatby, $format, false, $outputlangs));
1401
-			if ($detail->sellby) $dte[]=$outputlangs->transnoentitiesnoconv('printSellby',dol_print_date($detail->sellby, $format, false, $outputlangs));
1402
-			if ($detail->batch) $dte[]=$outputlangs->transnoentitiesnoconv('printBatch',$detail->batch);
1403
-			$dte[]=$outputlangs->transnoentitiesnoconv('printQty',$detail->qty);
1404
-			$libelleproduitservice.= "__N__  ".implode(" - ", $dte);
1399
+			$dte = array();
1400
+			if ($detail->eatby) $dte[] = $outputlangs->transnoentitiesnoconv('printEatby', dol_print_date($detail->eatby, $format, false, $outputlangs));
1401
+			if ($detail->sellby) $dte[] = $outputlangs->transnoentitiesnoconv('printSellby', dol_print_date($detail->sellby, $format, false, $outputlangs));
1402
+			if ($detail->batch) $dte[] = $outputlangs->transnoentitiesnoconv('printBatch', $detail->batch);
1403
+			$dte[] = $outputlangs->transnoentitiesnoconv('printQty', $detail->qty);
1404
+			$libelleproduitservice .= "__N__  ".implode(" - ", $dte);
1405 1405
 		}
1406 1406
 	}
1407 1407
 
1408 1408
 	// Now we convert \n into br
1409
-	if (dol_textishtml($libelleproduitservice)) $libelleproduitservice=preg_replace('/__N__/','<br>',$libelleproduitservice);
1410
-	else $libelleproduitservice=preg_replace('/__N__/',"\n",$libelleproduitservice);
1411
-	$libelleproduitservice=dol_htmlentitiesbr($libelleproduitservice,1);
1409
+	if (dol_textishtml($libelleproduitservice)) $libelleproduitservice = preg_replace('/__N__/', '<br>', $libelleproduitservice);
1410
+	else $libelleproduitservice = preg_replace('/__N__/', "\n", $libelleproduitservice);
1411
+	$libelleproduitservice = dol_htmlentitiesbr($libelleproduitservice, 1);
1412 1412
 
1413 1413
 	return $libelleproduitservice;
1414 1414
 }
@@ -1422,25 +1422,25 @@  discard block
 block discarded – undo
1422 1422
  *  @param	int			$hidedetails		Hide details (0=no, 1=yes, 2=just special lines)
1423 1423
  * 	@return	string
1424 1424
  */
1425
-function pdf_getlinenum($object,$i,$outputlangs,$hidedetails=0)
1425
+function pdf_getlinenum($object, $i, $outputlangs, $hidedetails = 0)
1426 1426
 {
1427 1427
 	global $hookmanager;
1428 1428
 
1429
-	$reshook=0;
1430
-	$result='';
1429
+	$reshook = 0;
1430
+	$result = '';
1431 1431
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1432 1432
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1433 1433
 	{
1434 1434
 		$special_code = $object->lines[$i]->special_code;
1435
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1436
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1437
-		$action='';
1438
-		$reshook = $hookmanager->executeHooks('pdf_getlinenum',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1439
-		$result.=$hookmanager->resPrint;
1435
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1436
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1437
+		$action = '';
1438
+		$reshook = $hookmanager->executeHooks('pdf_getlinenum', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1439
+		$result .= $hookmanager->resPrint;
1440 1440
 	}
1441 1441
 	if (empty($reshook))
1442 1442
 	{
1443
-		$result.=dol_htmlentitiesbr($object->lines[$i]->num);
1443
+		$result .= dol_htmlentitiesbr($object->lines[$i]->num);
1444 1444
 	}
1445 1445
 	return $result;
1446 1446
 }
@@ -1455,25 +1455,25 @@  discard block
 block discarded – undo
1455 1455
  *  @param	int			$hidedetails		Hide details (0=no, 1=yes, 2=just special lines)
1456 1456
  * 	@return	string
1457 1457
  */
1458
-function pdf_getlineref($object,$i,$outputlangs,$hidedetails=0)
1458
+function pdf_getlineref($object, $i, $outputlangs, $hidedetails = 0)
1459 1459
 {
1460 1460
 	global $hookmanager;
1461 1461
 
1462
-	$reshook=0;
1463
-	$result='';
1462
+	$reshook = 0;
1463
+	$result = '';
1464 1464
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1465 1465
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1466 1466
 	{
1467 1467
 		$special_code = $object->lines[$i]->special_code;
1468
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1469
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1470
-		$action='';
1471
-		$reshook = $hookmanager->executeHooks('pdf_getlineref',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1472
-		$result.=$hookmanager->resPrint;
1468
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1469
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1470
+		$action = '';
1471
+		$reshook = $hookmanager->executeHooks('pdf_getlineref', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1472
+		$result .= $hookmanager->resPrint;
1473 1473
 	}
1474 1474
 	if (empty($reshook))
1475 1475
 	{
1476
-		$result.=dol_htmlentitiesbr($object->lines[$i]->product_ref);
1476
+		$result .= dol_htmlentitiesbr($object->lines[$i]->product_ref);
1477 1477
 	}
1478 1478
 	return $result;
1479 1479
 }
@@ -1487,25 +1487,25 @@  discard block
 block discarded – undo
1487 1487
  *  @param	int			$hidedetails		Hide details (0=no, 1=yes, 2=just special lines)
1488 1488
  * 	@return	string
1489 1489
  */
1490
-function pdf_getlineref_supplier($object,$i,$outputlangs,$hidedetails=0)
1490
+function pdf_getlineref_supplier($object, $i, $outputlangs, $hidedetails = 0)
1491 1491
 {
1492 1492
 	global $hookmanager;
1493 1493
 
1494
-	$reshook=0;
1495
-	$result='';
1494
+	$reshook = 0;
1495
+	$result = '';
1496 1496
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1497 1497
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1498 1498
 	{
1499 1499
 		$special_code = $object->lines[$i]->special_code;
1500
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1501
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1502
-		$action='';
1503
-		$reshook = $hookmanager->executeHooks('pdf_getlineref_supplier',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1504
-		$result.=$hookmanager->resPrint;
1500
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1501
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1502
+		$action = '';
1503
+		$reshook = $hookmanager->executeHooks('pdf_getlineref_supplier', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1504
+		$result .= $hookmanager->resPrint;
1505 1505
 	}
1506 1506
 	if (empty($reshook))
1507 1507
 	{
1508
-		$result.=dol_htmlentitiesbr($object->lines[$i]->ref_supplier);
1508
+		$result .= dol_htmlentitiesbr($object->lines[$i]->ref_supplier);
1509 1509
 	}
1510 1510
 	return $result;
1511 1511
 }
@@ -1519,51 +1519,51 @@  discard block
 block discarded – undo
1519 1519
  *  @param	int			$hidedetails		Hide details (0=no, 1=yes, 2=just special lines)
1520 1520
  * 	@return	string
1521 1521
  */
1522
-function pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
1522
+function pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails = 0)
1523 1523
 {
1524 1524
 	global $conf, $hookmanager, $mysoc;
1525 1525
 
1526
-	$result='';
1527
-	$reshook=0;
1526
+	$result = '';
1527
+	$reshook = 0;
1528 1528
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1529 1529
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduce this test in the pdf_xxx function if you don't want your hook to run
1530 1530
 	{
1531 1531
 		$special_code = $object->lines[$i]->special_code;
1532
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1533
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1534
-		$action='';
1535
-		$reshook = $hookmanager->executeHooks('pdf_getlinevatrate',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1532
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1533
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1534
+		$action = '';
1535
+		$reshook = $hookmanager->executeHooks('pdf_getlinevatrate', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1536 1536
 
1537
-		if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1537
+		if (!empty($hookmanager->resPrint)) $result .= $hookmanager->resPrint;
1538 1538
 	}
1539 1539
 	if (empty($reshook))
1540 1540
 	{
1541 1541
 		if (empty($hidedetails) || $hidedetails > 1)
1542 1542
 		{
1543
-			$tmpresult='';
1543
+			$tmpresult = '';
1544 1544
 
1545
-			$tmpresult.=vatrate($object->lines[$i]->tva_tx, 0, $object->lines[$i]->info_bits, -1);
1545
+			$tmpresult .= vatrate($object->lines[$i]->tva_tx, 0, $object->lines[$i]->info_bits, -1);
1546 1546
 			if (empty($conf->global->MAIN_PDF_MAIN_HIDE_SECOND_TAX))
1547 1547
 			{
1548 1548
 				if ($object->lines[$i]->total_localtax1 != 0)
1549 1549
 				{
1550
-					if (preg_replace('/[\s0%]/','',$tmpresult)) $tmpresult.='/';
1551
-					else $tmpresult='';
1552
-					$tmpresult.=vatrate(abs($object->lines[$i]->localtax1_tx), 0);
1550
+					if (preg_replace('/[\s0%]/', '', $tmpresult)) $tmpresult .= '/';
1551
+					else $tmpresult = '';
1552
+					$tmpresult .= vatrate(abs($object->lines[$i]->localtax1_tx), 0);
1553 1553
 				}
1554 1554
 			}
1555 1555
 			if (empty($conf->global->MAIN_PDF_MAIN_HIDE_THIRD_TAX))
1556 1556
 			{
1557 1557
 				if ($object->lines[$i]->total_localtax2 != 0)
1558 1558
 				{
1559
-					if (preg_replace('/[\s0%]/','',$tmpresult)) $tmpresult.='/';
1560
-					else $tmpresult='';
1561
-					$tmpresult.=vatrate(abs($object->lines[$i]->localtax2_tx), 0);
1559
+					if (preg_replace('/[\s0%]/', '', $tmpresult)) $tmpresult .= '/';
1560
+					else $tmpresult = '';
1561
+					$tmpresult .= vatrate(abs($object->lines[$i]->localtax2_tx), 0);
1562 1562
 				}
1563 1563
 			}
1564
-			$tmpresult.= '%';
1564
+			$tmpresult .= '%';
1565 1565
 
1566
-			$result.=$tmpresult;
1566
+			$result .= $tmpresult;
1567 1567
 		}
1568 1568
 	}
1569 1569
 	return $result;
@@ -1578,32 +1578,32 @@  discard block
 block discarded – undo
1578 1578
  *  @param	int			$hidedetails		Hide details (0=no, 1=yes, 2=just special lines)
1579 1579
  * 	@return	string
1580 1580
  */
1581
-function pdf_getlineupexcltax($object,$i,$outputlangs,$hidedetails=0)
1581
+function pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails = 0)
1582 1582
 {
1583 1583
 	global $conf, $hookmanager;
1584 1584
 
1585
-	$sign=1;
1586
-	if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1585
+	$sign = 1;
1586
+	if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign = -1;
1587 1587
 
1588
-	$result='';
1589
-	$reshook=0;
1588
+	$result = '';
1589
+	$reshook = 0;
1590 1590
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1591 1591
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1592 1592
 	{
1593 1593
 		$special_code = $object->lines[$i]->special_code;
1594
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1595
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1596
-		$action='';
1597
-		$reshook = $hookmanager->executeHooks('pdf_getlineupexcltax',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1594
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1595
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1596
+		$action = '';
1597
+		$reshook = $hookmanager->executeHooks('pdf_getlineupexcltax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1598 1598
 
1599
-		if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1599
+		if (!empty($hookmanager->resPrint)) $result .= $hookmanager->resPrint;
1600 1600
 	}
1601 1601
 	if (empty($reshook))
1602 1602
 	{
1603 1603
 		if (empty($hidedetails) || $hidedetails > 1)
1604 1604
 		{
1605 1605
 			$subprice = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_subprice : $object->lines[$i]->subprice);
1606
-			$result.=price($sign * $subprice, 0, $outputlangs);
1606
+			$result .= price($sign * $subprice, 0, $outputlangs);
1607 1607
 		}
1608 1608
 	}
1609 1609
 	return $result;
@@ -1618,29 +1618,29 @@  discard block
 block discarded – undo
1618 1618
  *  @param	int			$hidedetails		Hide value (0 = no,	1 = yes, 2 = just special lines)
1619 1619
  *  @return	string
1620 1620
  */
1621
-function pdf_getlineupwithtax($object,$i,$outputlangs,$hidedetails=0)
1621
+function pdf_getlineupwithtax($object, $i, $outputlangs, $hidedetails = 0)
1622 1622
 {
1623
-	global $hookmanager,$conf;
1623
+	global $hookmanager, $conf;
1624 1624
 
1625
-	$sign=1;
1626
-	if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1625
+	$sign = 1;
1626
+	if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign = -1;
1627 1627
 
1628
-	$result='';
1629
-	$reshook=0;
1628
+	$result = '';
1629
+	$reshook = 0;
1630 1630
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1631 1631
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1632 1632
 	{
1633 1633
 		$special_code = $object->lines[$i]->special_code;
1634
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1635
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1636
-		$action='';
1637
-		$reshook = $hookmanager->executeHooks('pdf_getlineupwithtax',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1634
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1635
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1636
+		$action = '';
1637
+		$reshook = $hookmanager->executeHooks('pdf_getlineupwithtax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1638 1638
 
1639
-		if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1639
+		if (!empty($hookmanager->resPrint)) $result .= $hookmanager->resPrint;
1640 1640
 	}
1641 1641
 	if (empty($reshook))
1642 1642
 	{
1643
-		if (empty($hidedetails) || $hidedetails > 1) $result.=price($sign * (($object->lines[$i]->subprice) + ($object->lines[$i]->subprice)*($object->lines[$i]->tva_tx)/100), 0, $outputlangs);
1643
+		if (empty($hidedetails) || $hidedetails > 1) $result .= price($sign * (($object->lines[$i]->subprice) + ($object->lines[$i]->subprice) * ($object->lines[$i]->tva_tx) / 100), 0, $outputlangs);
1644 1644
 	}
1645 1645
 	return $result;
1646 1646
 }
@@ -1654,27 +1654,27 @@  discard block
 block discarded – undo
1654 1654
  *  @param	int			$hidedetails		Hide details (0=no, 1=yes, 2=just special lines)
1655 1655
  *  @return	string
1656 1656
  */
1657
-function pdf_getlineqty($object,$i,$outputlangs,$hidedetails=0)
1657
+function pdf_getlineqty($object, $i, $outputlangs, $hidedetails = 0)
1658 1658
 {
1659 1659
 	global $hookmanager;
1660 1660
 
1661
-	$result='';
1662
-	$reshook=0;
1661
+	$result = '';
1662
+	$reshook = 0;
1663 1663
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1664 1664
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1665 1665
 	{
1666 1666
 		$special_code = $object->lines[$i]->special_code;
1667
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1668
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1669
-		$action='';
1670
-		$reshook = $hookmanager->executeHooks('pdf_getlineqty',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1667
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1668
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1669
+		$action = '';
1670
+		$reshook = $hookmanager->executeHooks('pdf_getlineqty', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1671 1671
 
1672
-		if(!empty($hookmanager->resPrint)) $result=$hookmanager->resPrint;
1672
+		if (!empty($hookmanager->resPrint)) $result = $hookmanager->resPrint;
1673 1673
 	}
1674 1674
     if (empty($reshook))
1675 1675
 	{
1676 1676
 	   if ($object->lines[$i]->special_code == 3) return '';
1677
-	   if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty;
1677
+	   if (empty($hidedetails) || $hidedetails > 1) $result .= $object->lines[$i]->qty;
1678 1678
 	}
1679 1679
 	return $result;
1680 1680
 }
@@ -1688,27 +1688,27 @@  discard block
 block discarded – undo
1688 1688
  *  @param	int			$hidedetails		Hide details (0=no, 1=yes, 2=just special lines)
1689 1689
  * 	@return	string
1690 1690
  */
1691
-function pdf_getlineqty_asked($object,$i,$outputlangs,$hidedetails=0)
1691
+function pdf_getlineqty_asked($object, $i, $outputlangs, $hidedetails = 0)
1692 1692
 {
1693 1693
 	global $hookmanager;
1694 1694
 
1695
-	$reshook=0;
1696
-	$result='';
1695
+	$reshook = 0;
1696
+	$result = '';
1697 1697
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1698 1698
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1699 1699
 	{
1700 1700
 		$special_code = $object->lines[$i]->special_code;
1701
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1702
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1703
-		$action='';
1704
-		$reshook = $hookmanager->executeHooks('pdf_getlineqty_asked',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1701
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1702
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1703
+		$action = '';
1704
+		$reshook = $hookmanager->executeHooks('pdf_getlineqty_asked', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1705 1705
 
1706
-		if (!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1706
+		if (!empty($hookmanager->resPrint)) $result .= $hookmanager->resPrint;
1707 1707
 	}
1708 1708
 	if (empty($reshook))
1709 1709
 	{
1710 1710
         if ($object->lines[$i]->special_code == 3) return '';
1711
-        if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty_asked;
1711
+        if (empty($hidedetails) || $hidedetails > 1) $result .= $object->lines[$i]->qty_asked;
1712 1712
 	}
1713 1713
 	return $result;
1714 1714
 }
@@ -1722,27 +1722,27 @@  discard block
 block discarded – undo
1722 1722
  *  @param	int			$hidedetails		Hide details (0=no, 1=yes, 2=just special lines)
1723 1723
  * 	@return	string
1724 1724
  */
1725
-function pdf_getlineqty_shipped($object,$i,$outputlangs,$hidedetails=0)
1725
+function pdf_getlineqty_shipped($object, $i, $outputlangs, $hidedetails = 0)
1726 1726
 {
1727 1727
 	global $hookmanager;
1728 1728
 
1729
-	$reshook=0;
1730
-	$result='';
1729
+	$reshook = 0;
1730
+	$result = '';
1731 1731
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1732 1732
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1733 1733
 	{
1734 1734
 		$special_code = $object->lines[$i]->special_code;
1735
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1736
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1737
-		$action='';
1738
-		$reshook = $hookmanager->executeHooks('pdf_getlineqty_shipped',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1735
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1736
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1737
+		$action = '';
1738
+		$reshook = $hookmanager->executeHooks('pdf_getlineqty_shipped', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1739 1739
 
1740
-		if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1740
+		if (!empty($hookmanager->resPrint)) $result .= $hookmanager->resPrint;
1741 1741
 	}
1742 1742
 	if (empty($reshook))
1743 1743
 	{
1744 1744
         if ($object->lines[$i]->special_code == 3) return '';
1745
-	    if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->qty_shipped;
1745
+	    if (empty($hidedetails) || $hidedetails > 1) $result .= $object->lines[$i]->qty_shipped;
1746 1746
 	}
1747 1747
 	return $result;
1748 1748
 }
@@ -1756,27 +1756,27 @@  discard block
 block discarded – undo
1756 1756
  *  @param	int			$hidedetails		Hide details (0=no, 1=yes, 2=just special lines)
1757 1757
  * 	@return	string
1758 1758
  */
1759
-function pdf_getlineqty_keeptoship($object,$i,$outputlangs,$hidedetails=0)
1759
+function pdf_getlineqty_keeptoship($object, $i, $outputlangs, $hidedetails = 0)
1760 1760
 {
1761 1761
 	global $hookmanager;
1762 1762
 
1763
-	$reshook=0;
1764
-    $result='';
1763
+	$reshook = 0;
1764
+    $result = '';
1765 1765
     //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1766 1766
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1767 1767
 	{
1768 1768
 		$special_code = $object->lines[$i]->special_code;
1769
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1770
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1771
-		$action='';
1772
-		$reshook = $hookmanager->executeHooks('pdf_getlineqty_keeptoship',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1769
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1770
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1771
+		$action = '';
1772
+		$reshook = $hookmanager->executeHooks('pdf_getlineqty_keeptoship', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1773 1773
 
1774
-		if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1774
+		if (!empty($hookmanager->resPrint)) $result .= $hookmanager->resPrint;
1775 1775
 	}
1776 1776
 	if (empty($reshook))
1777 1777
 	{
1778 1778
         if ($object->lines[$i]->special_code == 3) return '';
1779
-		if (empty($hidedetails) || $hidedetails > 1) $result.=($object->lines[$i]->qty_asked - $object->lines[$i]->qty_shipped);
1779
+		if (empty($hidedetails) || $hidedetails > 1) $result .= ($object->lines[$i]->qty_asked - $object->lines[$i]->qty_shipped);
1780 1780
 	}
1781 1781
 	return $result;
1782 1782
 }
@@ -1795,8 +1795,8 @@  discard block
 block discarded – undo
1795 1795
 {
1796 1796
 	global $langs;
1797 1797
 
1798
-	$reshook=0;
1799
-    $result='';
1798
+	$reshook = 0;
1799
+    $result = '';
1800 1800
     //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1801 1801
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1802 1802
 	{
@@ -1811,14 +1811,14 @@  discard block
 block discarded – undo
1811 1811
 			'special_code' => $special_code
1812 1812
 		);
1813 1813
 		$action = '';
1814
-		$reshook = $hookmanager->executeHooks('pdf_getlineunit', $parameters, $object, $action);    // Note that $action and $object may have been modified by some hooks
1814
+		$reshook = $hookmanager->executeHooks('pdf_getlineunit', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1815 1815
 
1816
-		if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1816
+		if (!empty($hookmanager->resPrint)) $result .= $hookmanager->resPrint;
1817 1817
 	}
1818 1818
 	if (empty($reshook))
1819 1819
 	{
1820 1820
         if ($object->lines[$i]->special_code == 3) return '';
1821
-	    if (empty($hidedetails) || $hidedetails > 1) $result.=$langs->transnoentitiesnoconv($object->lines[$i]->getLabelOfUnit('short'));
1821
+	    if (empty($hidedetails) || $hidedetails > 1) $result .= $langs->transnoentitiesnoconv($object->lines[$i]->getLabelOfUnit('short'));
1822 1822
 	}
1823 1823
 	return $result;
1824 1824
 }
@@ -1833,29 +1833,29 @@  discard block
 block discarded – undo
1833 1833
  *  @param	int			$hidedetails		Hide details (0=no, 1=yes, 2=just special lines)
1834 1834
  * 	@return	string
1835 1835
  */
1836
-function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0)
1836
+function pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails = 0)
1837 1837
 {
1838 1838
 	global $hookmanager;
1839 1839
 
1840 1840
 	include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1841 1841
 
1842
-	$reshook=0;
1843
-	$result='';
1842
+	$reshook = 0;
1843
+	$result = '';
1844 1844
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1845 1845
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1846 1846
 	{
1847 1847
 		$special_code = $object->lines[$i]->special_code;
1848
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1849
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1850
-		$action='';
1851
-		$reshook = $hookmanager->executeHooks('pdf_getlineremisepercent',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1848
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1849
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1850
+		$action = '';
1851
+		$reshook = $hookmanager->executeHooks('pdf_getlineremisepercent', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1852 1852
 
1853
-		if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1853
+		if (!empty($hookmanager->resPrint)) $result .= $hookmanager->resPrint;
1854 1854
 	}
1855 1855
 	if (empty($reshook))
1856 1856
 	{
1857 1857
         if ($object->lines[$i]->special_code == 3) return '';
1858
-	    if (empty($hidedetails) || $hidedetails > 1) $result.=dol_print_reduction($object->lines[$i]->remise_percent,$outputlangs);
1858
+	    if (empty($hidedetails) || $hidedetails > 1) $result .= dol_print_reduction($object->lines[$i]->remise_percent, $outputlangs);
1859 1859
 	}
1860 1860
 	return $result;
1861 1861
 }
@@ -1875,8 +1875,8 @@  discard block
 block discarded – undo
1875 1875
 	if (empty($hookmanager)) global $hookmanager;
1876 1876
 	global $conf;
1877 1877
 
1878
-	$reshook=0;
1879
-    $result='';
1878
+	$reshook = 0;
1879
+    $result = '';
1880 1880
     //if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1881 1881
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1882 1882
 	{
@@ -1884,9 +1884,9 @@  discard block
 block discarded – undo
1884 1884
 		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1885 1885
 		$parameters = array('i' => $i, 'outputlangs' => $outputlangs, 'hidedetails' => $hidedetails, 'special_code' => $special_code);
1886 1886
 		$action = '';
1887
-		$reshook = $hookmanager->executeHooks('pdf_getlineprogress', $parameters, $object, $action);    // Note that $action and $object may have been modified by some hooks
1887
+		$reshook = $hookmanager->executeHooks('pdf_getlineprogress', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1888 1888
 
1889
-		if(!empty($hookmanager->resPrint)) return $hookmanager->resPrint;
1889
+		if (!empty($hookmanager->resPrint)) return $hookmanager->resPrint;
1890 1890
 	}
1891 1891
 	if (empty($reshook))
1892 1892
 	{
@@ -1900,10 +1900,10 @@  discard block
 block discarded – undo
1900 1900
 				{
1901 1901
 			 		$prev_progress = $object->lines[$i]->get_prev_progress($object->id);
1902 1902
 				}
1903
-			 	$result = ($object->lines[$i]->situation_percent - $prev_progress) . '%';
1903
+			 	$result = ($object->lines[$i]->situation_percent - $prev_progress).'%';
1904 1904
 			}
1905 1905
 			else
1906
-				$result = $object->lines[$i]->situation_percent . '%';
1906
+				$result = $object->lines[$i]->situation_percent.'%';
1907 1907
 	  	}
1908 1908
 	}
1909 1909
 	return $result;
@@ -1918,25 +1918,25 @@  discard block
 block discarded – undo
1918 1918
  *  @param	int			$hidedetails		Hide details (0=no, 1=yes, 2=just special lines)
1919 1919
  * 	@return	string							Return total of line excl tax
1920 1920
  */
1921
-function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0)
1921
+function pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails = 0)
1922 1922
 {
1923 1923
 	global $conf, $hookmanager;
1924 1924
 
1925
-	$sign=1;
1926
-	if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1925
+	$sign = 1;
1926
+	if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign = -1;
1927 1927
 
1928
-	$reshook=0;
1929
-	$result='';
1928
+	$reshook = 0;
1929
+	$result = '';
1930 1930
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1931 1931
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1932 1932
 	{
1933 1933
 		$special_code = $object->lines[$i]->special_code;
1934
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1935
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code, 'sign'=>$sign);
1936
-		$action='';
1937
-		$reshook = $hookmanager->executeHooks('pdf_getlinetotalexcltax',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1934
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1935
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code, 'sign'=>$sign);
1936
+		$action = '';
1937
+		$reshook = $hookmanager->executeHooks('pdf_getlinetotalexcltax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1938 1938
 
1939
-		if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1939
+		if (!empty($hookmanager->resPrint)) $result .= $hookmanager->resPrint;
1940 1940
 	}
1941 1941
     if (empty($reshook))
1942 1942
     {
@@ -1956,10 +1956,10 @@  discard block
 block discarded – undo
1956 1956
 					$prev_progress = $object->lines[$i]->get_prev_progress($object->id);
1957 1957
 					$progress = ($object->lines[$i]->situation_percent - $prev_progress) / 100;
1958 1958
         		}
1959
-				$result.=price($sign * ($total_ht/($object->lines[$i]->situation_percent/100)) * $progress, 0, $outputlangs);
1959
+				$result .= price($sign * ($total_ht / ($object->lines[$i]->situation_percent / 100)) * $progress, 0, $outputlangs);
1960 1960
         	}
1961 1961
         	else
1962
-			$result.=price($sign * $total_ht, 0, $outputlangs);
1962
+			$result .= price($sign * $total_ht, 0, $outputlangs);
1963 1963
 	}
1964 1964
     }
1965 1965
 	return $result;
@@ -1974,33 +1974,33 @@  discard block
 block discarded – undo
1974 1974
  *  @param	int			$hidedetails		Hide value (0 = no, 1 = yes, 2 = just special lines)
1975 1975
  *  @return	string							Return total of line incl tax
1976 1976
  */
1977
-function pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails=0)
1977
+function pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails = 0)
1978 1978
 {
1979
-	global $hookmanager,$conf;
1979
+	global $hookmanager, $conf;
1980 1980
 
1981
-	$sign=1;
1982
-	if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
1981
+	$sign = 1;
1982
+	if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign = -1;
1983 1983
 
1984
-	$reshook=0;
1985
-	$result='';
1984
+	$reshook = 0;
1985
+	$result = '';
1986 1986
 	//if (is_object($hookmanager) && ( (isset($object->lines[$i]->product_type) && $object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line) ) )
1987 1987
 	if (is_object($hookmanager))   // Old code is commented on preceding line. Reproduct this test in the pdf_xxx function if you don't want your hook to run
1988 1988
 	{
1989 1989
 		$special_code = $object->lines[$i]->special_code;
1990
-		if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1991
-		$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
1992
-		$action='';
1993
-		$reshook = $hookmanager->executeHooks('pdf_getlinetotalwithtax',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
1990
+		if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
1991
+		$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
1992
+		$action = '';
1993
+		$reshook = $hookmanager->executeHooks('pdf_getlinetotalwithtax', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1994 1994
 
1995
-		if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint;
1995
+		if (!empty($hookmanager->resPrint)) $result .= $hookmanager->resPrint;
1996 1996
 	}
1997 1997
 	if (empty($reshook))
1998 1998
 	{
1999 1999
 		if ($object->lines[$i]->special_code == 3)
2000 2000
     	{
2001
-    		$result.=$outputlangs->transnoentities("Option");
2001
+    		$result .= $outputlangs->transnoentities("Option");
2002 2002
     	}
2003
-		elseif (empty($hidedetails) || $hidedetails > 1) $result.=price($sign * ($object->lines[$i]->total_ht) + ($object->lines[$i]->total_ht)*($object->lines[$i]->tva_tx)/100, 0, $outputlangs);
2003
+		elseif (empty($hidedetails) || $hidedetails > 1) $result .= price($sign * ($object->lines[$i]->total_ht) + ($object->lines[$i]->total_ht) * ($object->lines[$i]->tva_tx) / 100, 0, $outputlangs);
2004 2004
 	}
2005 2005
 	return $result;
2006 2006
 }
@@ -2014,36 +2014,36 @@  discard block
 block discarded – undo
2014 2014
  * 	@return	integer
2015 2015
  *  @deprecated Not used by Dolibarr core, so will be removed.
2016 2016
  */
2017
-function pdf_getTotalQty($object,$type,$outputlangs)
2017
+function pdf_getTotalQty($object, $type, $outputlangs)
2018 2018
 {
2019 2019
 	global $hookmanager;
2020 2020
 
2021
-	$total=0;
2022
-	$nblignes=count($object->lines);
2021
+	$total = 0;
2022
+	$nblignes = count($object->lines);
2023 2023
 
2024 2024
 	// Loop on each lines
2025
-	for ($i = 0 ; $i < $nblignes ; $i++)
2025
+	for ($i = 0; $i < $nblignes; $i++)
2026 2026
 	{
2027 2027
 		if ($object->lines[$i]->special_code != 3)
2028 2028
 		{
2029
-			if ($type=='all')
2029
+			if ($type == 'all')
2030 2030
 			{
2031 2031
 				$total += $object->lines[$i]->qty;
2032 2032
 			}
2033
-			else if ($type==9 && is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line)))
2033
+			else if ($type == 9 && is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line)))
2034 2034
 			{
2035 2035
 				$special_code = $object->lines[$i]->special_code;
2036
-				if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2037
-				$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
2038
-				$action='';
2039
-				$reshook = $hookmanager->executeHooks('pdf_getTotalQty',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
2036
+				if (!empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
2037
+				$parameters = array('i'=>$i, 'outputlangs'=>$outputlangs, 'hidedetails'=>$hidedetails, 'special_code'=>$special_code);
2038
+				$action = '';
2039
+				$reshook = $hookmanager->executeHooks('pdf_getTotalQty', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2040 2040
 				return $hookmanager->resPrint;
2041 2041
 			}
2042
-			else if ($type==0 && $object->lines[$i]->product_type == 0)
2042
+			else if ($type == 0 && $object->lines[$i]->product_type == 0)
2043 2043
 			{
2044 2044
 				$total += $object->lines[$i]->qty;
2045 2045
 			}
2046
-			else if ($type==1 && $object->lines[$i]->product_type == 1)
2046
+			else if ($type == 1 && $object->lines[$i]->product_type == 1)
2047 2047
 			{
2048 2048
 				$total += $object->lines[$i]->qty;
2049 2049
 			}
@@ -2061,15 +2061,15 @@  discard block
 block discarded – undo
2061 2061
  * 	@param	Translate	$outputlangs	Object lang for output
2062 2062
  * 	@return	array                       Linked objects
2063 2063
  */
2064
-function pdf_getLinkedObjects($object,$outputlangs)
2064
+function pdf_getLinkedObjects($object, $outputlangs)
2065 2065
 {
2066 2066
 	global $hookmanager;
2067 2067
 
2068
-	$linkedobjects=array();
2068
+	$linkedobjects = array();
2069 2069
 
2070 2070
 	$object->fetchObjectLinked();
2071 2071
 
2072
-	foreach($object->linkedObjects as $objecttype => $objects)
2072
+	foreach ($object->linkedObjects as $objecttype => $objects)
2073 2073
 	{
2074 2074
 	    if ($objecttype == 'facture')
2075 2075
 	    {
@@ -2079,63 +2079,63 @@  discard block
 block discarded – undo
2079 2079
 		{
2080 2080
 			$outputlangs->load('propal');
2081 2081
 
2082
-			foreach($objects as $elementobject)
2082
+			foreach ($objects as $elementobject)
2083 2083
 			{
2084 2084
 				$linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefProposal");
2085 2085
 				$linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
2086 2086
 				$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DatePropal");
2087
-				$linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs);
2087
+				$linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date, 'day', '', $outputlangs);
2088 2088
 			}
2089 2089
 		}
2090 2090
 		else if ($objecttype == 'commande' || $objecttype == 'supplier_order')
2091 2091
 		{
2092 2092
 			$outputlangs->load('orders');
2093
-			foreach($objects as $elementobject)
2093
+			foreach ($objects as $elementobject)
2094 2094
 			{
2095 2095
 				$linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder");
2096
-				$linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref) . ($elementobject->ref_client ? ' ('.$elementobject->ref_client.')' : '') . ($elementobject->ref_supplier ? ' ('.$elementobject->ref_supplier.')' : '');
2096
+				$linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref).($elementobject->ref_client ? ' ('.$elementobject->ref_client.')' : '').($elementobject->ref_supplier ? ' ('.$elementobject->ref_supplier.')' : '');
2097 2097
 				$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate");
2098
-				$linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date,'day','',$outputlangs);
2098
+				$linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date, 'day', '', $outputlangs);
2099 2099
 			}
2100 2100
 		}
2101 2101
 		else if ($objecttype == 'contrat')
2102 2102
 		{
2103 2103
 			$outputlangs->load('contracts');
2104
-			foreach($objects as $elementobject)
2104
+			foreach ($objects as $elementobject)
2105 2105
 			{
2106 2106
 				$linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefContract");
2107 2107
 				$linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
2108 2108
 				$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateContract");
2109
-				$linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date_contrat,'day','',$outputlangs);
2109
+				$linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date_contrat, 'day', '', $outputlangs);
2110 2110
 			}
2111 2111
 		}
2112 2112
 		else if ($objecttype == 'shipping')
2113 2113
 		{
2114 2114
 			$outputlangs->loadLangs(array("orders", "sendings"));
2115 2115
 
2116
-			foreach($objects as $x => $elementobject)
2116
+			foreach ($objects as $x => $elementobject)
2117 2117
 			{
2118
-			    $order=null;
2118
+			    $order = null;
2119 2119
 			    // We concat this record info into fields xxx_value. title is overwrote.
2120 2120
 			    if (empty($object->linkedObjects['commande']) && $object->element != 'commande')	// There is not already a link to order and object is not the order, so we show also info with order
2121 2121
 			    {
2122 2122
 			        $elementobject->fetchObjectLinked();
2123
-			        if (! empty($elementobject->linkedObjects['commande'])) $order = reset($elementobject->linkedObjects['commande']);
2123
+			        if (!empty($elementobject->linkedObjects['commande'])) $order = reset($elementobject->linkedObjects['commande']);
2124 2124
 			    }
2125
-			    if (! is_object($order))
2125
+			    if (!is_object($order))
2126 2126
 			    {
2127 2127
 			        $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefSending");
2128
-			        if (! empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'].=' / ';
2129
-			        $linkedobjects[$objecttype]['ref_value'].= $outputlangs->transnoentities($elementobject->ref);
2128
+			        if (!empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'] .= ' / ';
2129
+			        $linkedobjects[$objecttype]['ref_value'] .= $outputlangs->transnoentities($elementobject->ref);
2130 2130
 			        //$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateShipment");
2131 2131
 			        //if (! empty($linkedobjects[$objecttype]['date_value'])) $linkedobjects[$objecttype]['date_value'].=' / ';
2132 2132
 			        //$linkedobjects[$objecttype]['date_value'].= dol_print_date($elementobject->date_delivery,'day','',$outputlangs);
2133 2133
 			    }
2134 2134
 			    else
2135 2135
 			    {
2136
-			        $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder") . ' / ' . $outputlangs->transnoentities("RefSending");
2137
-			        if (empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'] = $outputlangs->convToOutputCharset($order->ref) . ($order->ref_client ? ' ('.$order->ref_client.')' : '');
2138
-			        $linkedobjects[$objecttype]['ref_value'].= ' / ' . $outputlangs->transnoentities($elementobject->ref);
2136
+			        $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder").' / '.$outputlangs->transnoentities("RefSending");
2137
+			        if (empty($linkedobjects[$objecttype]['ref_value'])) $linkedobjects[$objecttype]['ref_value'] = $outputlangs->convToOutputCharset($order->ref).($order->ref_client ? ' ('.$order->ref_client.')' : '');
2138
+			        $linkedobjects[$objecttype]['ref_value'] .= ' / '.$outputlangs->transnoentities($elementobject->ref);
2139 2139
 			        //$linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate") . ($elementobject->date_delivery ? ' / ' . $outputlangs->transnoentities("DateShipment") : '');
2140 2140
 			        //if (empty($linkedobjects[$objecttype]['date_value'])) $linkedobjects[$objecttype]['date_value'] = dol_print_date($order->date,'day','',$outputlangs);
2141 2141
 			        //$linkedobjects[$objecttype]['date_value'].= ($elementobject->date_delivery ? ' / ' . dol_print_date($elementobject->date_delivery,'day','',$outputlangs) : '');
@@ -2148,9 +2148,9 @@  discard block
 block discarded – undo
2148 2148
 	if (is_object($hookmanager))
2149 2149
 	{
2150 2150
 		$parameters = array('linkedobjects' => $linkedobjects, 'outputlangs'=>$outputlangs);
2151
-		$action='';
2152
-		$hookmanager->executeHooks('pdf_getLinkedObjects',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
2153
-		if (! empty($hookmanager->resArray)) $linkedobjects = $hookmanager->resArray;
2151
+		$action = '';
2152
+		$hookmanager->executeHooks('pdf_getLinkedObjects', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2153
+		if (!empty($hookmanager->resArray)) $linkedobjects = $hookmanager->resArray;
2154 2154
 	}
2155 2155
 
2156 2156
 	return $linkedobjects;
@@ -2167,22 +2167,22 @@  discard block
 block discarded – undo
2167 2167
 {
2168 2168
 	global $conf;
2169 2169
 
2170
-	$maxwidth=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);
2171
-	$maxheight=(empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT)?32:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT);
2170
+	$maxwidth = (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);
2171
+	$maxheight = (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT) ? 32 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_HEIGHT);
2172 2172
 	include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
2173
-	$tmp=dol_getImageSize($realpath);
2173
+	$tmp = dol_getImageSize($realpath);
2174 2174
 	if ($tmp['height'])
2175 2175
 	{
2176
-		$width=(int) round($maxheight*$tmp['width']/$tmp['height']);	// I try to use maxheight
2176
+		$width = (int) round($maxheight * $tmp['width'] / $tmp['height']); // I try to use maxheight
2177 2177
 		if ($width > $maxwidth)	// Pb with maxheight, so i use maxwidth
2178 2178
 		{
2179
-			$width=$maxwidth;
2180
-			$height=(int) round($maxwidth*$tmp['height']/$tmp['width']);
2179
+			$width = $maxwidth;
2180
+			$height = (int) round($maxwidth * $tmp['height'] / $tmp['width']);
2181 2181
 		}
2182 2182
 		else	// No pb with maxheight
2183 2183
 		{
2184
-			$height=$maxheight;
2184
+			$height = $maxheight;
2185 2185
 		}
2186 2186
 	}
2187
-	return array('width'=>$width,'height'=>$height);
2187
+	return array('width'=>$width, 'height'=>$height);
2188 2188
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/price.lib.php 1 patch
Spacing   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -82,47 +82,47 @@  discard block
 block discarded – undo
82 82
  * 						25=multicurrency_total_tax1 for total_ht
83 83
  *                      26=multicurrency_total_tax2 for total_ht
84 84
  */
85
-function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = '', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0)
85
+function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = '', $localtaxes_array = '', $progress = 100, $multicurrency_tx = 1, $pu_devise = 0)
86 86
 {
87
-	global $conf,$mysoc,$db;
87
+	global $conf, $mysoc, $db;
88 88
 
89
-	$result=array();
89
+	$result = array();
90 90
 
91 91
 	// Clean parameters
92
-	if (empty($info_bits)) $info_bits=0;
93
-	if (empty($txtva)) $txtva=0;
94
-	if (empty($seller) || ! is_object($seller))
92
+	if (empty($info_bits)) $info_bits = 0;
93
+	if (empty($txtva)) $txtva = 0;
94
+	if (empty($seller) || !is_object($seller))
95 95
 	{
96 96
 		dol_syslog("Price.lib::calcul_price_total Warning: function is called with parameter seller that is missing", LOG_WARNING);
97
-		if (! is_object($mysoc))	// mysoc may be not defined (during migration process)
97
+		if (!is_object($mysoc))	// mysoc may be not defined (during migration process)
98 98
 		{
99
-			$mysoc=new Societe($db);
99
+			$mysoc = new Societe($db);
100 100
 			$mysoc->setMysoc($conf);
101 101
 		}
102
-		$seller=$mysoc;	// If sell is done to a customer, $seller is not provided, we use $mysoc
102
+		$seller = $mysoc; // If sell is done to a customer, $seller is not provided, we use $mysoc
103 103
 		//var_dump($seller->country_id);exit;
104 104
 	}
105
-	if (empty($localtaxes_array) || ! is_array($localtaxes_array))
105
+	if (empty($localtaxes_array) || !is_array($localtaxes_array))
106 106
 	{
107 107
 		dol_syslog("Price.lib::calcul_price_total Warning: function is called with parameter localtaxes_array that is missing", LOG_WARNING);
108 108
 	}
109 109
 	// Too verbose. Enable for debug only
110 110
 	//dol_syslog("Price.lib::calcul_price_total qty=".$qty." pu=".$pu." remiserpercent_ligne=".$remise_percent_ligne." txtva=".$txtva." uselocaltax1_rate=".$uselocaltax1_rate." uselocaltax2_rate=".$uselocaltax2_rate.' remise_percent_global='.$remise_percent_global.' price_base_type='.$ice_base_type.' type='.$type.' progress='.$progress);
111 111
 
112
-	$countryid=$seller->country_id;
112
+	$countryid = $seller->country_id;
113 113
 
114
-	if (is_numeric($uselocaltax1_rate)) $uselocaltax1_rate=(float) $uselocaltax1_rate;
115
-	if (is_numeric($uselocaltax2_rate)) $uselocaltax2_rate=(float) $uselocaltax2_rate;
114
+	if (is_numeric($uselocaltax1_rate)) $uselocaltax1_rate = (float) $uselocaltax1_rate;
115
+	if (is_numeric($uselocaltax2_rate)) $uselocaltax2_rate = (float) $uselocaltax2_rate;
116 116
 
117
-	if ($uselocaltax1_rate < 0) $uselocaltax1_rate=$seller->localtax1_assuj;
118
-	if ($uselocaltax2_rate < 0) $uselocaltax2_rate=$seller->localtax2_assuj;
117
+	if ($uselocaltax1_rate < 0) $uselocaltax1_rate = $seller->localtax1_assuj;
118
+	if ($uselocaltax2_rate < 0) $uselocaltax2_rate = $seller->localtax2_assuj;
119 119
 
120 120
 	//var_dump($uselocaltax1_rate.' - '.$uselocaltax2_rate);
121 121
 	dol_syslog('Price.lib::calcul_price_total qty='.$qty.' pu='.$pu.' remise_percent_ligne='.$remise_percent_ligne.' txtva='.$txtva.' uselocaltax1_rate='.$uselocaltax1_rate.' uselocaltax2_rate='.$uselocaltax2_rate.' remise_percent_global='.$remise_percent_global.' price_base_type='.$price_base_type.' type='.$type.' progress='.$progress);
122 122
 
123 123
     // Now we search localtaxes information ourself (rates and types).
124
-	$localtax1_type=0;
125
-	$localtax2_type=0;
124
+	$localtax1_type = 0;
125
+	$localtax2_type = 0;
126 126
 
127 127
 	if (is_array($localtaxes_array))
128 128
 	{
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 	else	// deprecated method. values and type for localtaxes must be provided by caller and loaded with getLocalTaxesFromRate
135 135
 	{
136 136
 		$sql = "SELECT taux, localtax1, localtax2, localtax1_type, localtax2_type";
137
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as cv";
138
-		$sql.= " WHERE cv.taux = ".$txtva;
139
-		$sql.= " AND cv.fk_pays = ".$countryid;
137
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as cv";
138
+		$sql .= " WHERE cv.taux = ".$txtva;
139
+		$sql .= " AND cv.fk_pays = ".$countryid;
140 140
 		dol_syslog("Price.lib::calcul_price_total search vat information using old deprecated method", LOG_WARNING);
141 141
 		$resql = $db->query($sql);
142 142
 		if ($resql)
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 			$obj = $db->fetch_object($resql);
145 145
 			if ($obj)
146 146
 			{
147
-				$localtax1_rate=$obj->localtax1;
148
-				$localtax2_rate=$obj->localtax2;
149
-				$localtax1_type=$obj->localtax1_type;
150
-				$localtax2_type=$obj->localtax2_type;
147
+				$localtax1_rate = $obj->localtax1;
148
+				$localtax2_rate = $obj->localtax2;
149
+				$localtax1_type = $obj->localtax1_type;
150
+				$localtax2_type = $obj->localtax2_type;
151 151
 				//var_dump($localtax1_rate.' '.$localtax2_rate.' '.$localtax1_type.' '.$localtax2_type);exit;
152 152
 			}
153 153
 		}
@@ -156,14 +156,14 @@  discard block
 block discarded – undo
156 156
 
157 157
 	// pu calculation from pu_devise if pu empty
158 158
 	if (empty($pu) && !empty($pu_devise)) {
159
-		if (! empty($multicurrency_tx)) $pu = $pu_devise / $multicurrency_tx;
159
+		if (!empty($multicurrency_tx)) $pu = $pu_devise / $multicurrency_tx;
160 160
 		else
161 161
 		{
162 162
 			dol_syslog('Price.lib::calcul_price_total function called with bad parameters combination (multicurrency_tx empty when pu_devise not) ', LOG_ERR);
163 163
 			return array();
164 164
 		}
165 165
 	}
166
-	if ($pu === '') $pu=0;
166
+	if ($pu === '') $pu = 0;
167 167
 	// pu_devise calculation from pu
168 168
 	if (empty($pu_devise) && !empty($multicurrency_tx)) {
169 169
 		if (is_numeric($pu) && is_numeric($multicurrency_tx)) $pu_devise = $pu * $multicurrency_tx;
@@ -176,20 +176,20 @@  discard block
 block discarded – undo
176 176
 
177 177
 	// initialize total (may be HT or TTC depending on price_base_type)
178 178
 	$tot_sans_remise = $pu * $qty * $progress / 100;
179
-	$tot_avec_remise_ligne = $tot_sans_remise       * (1 - ($remise_percent_ligne / 100));
179
+	$tot_avec_remise_ligne = $tot_sans_remise * (1 - ($remise_percent_ligne / 100));
180 180
 	$tot_avec_remise       = $tot_avec_remise_ligne * (1 - ($remise_percent_global / 100));
181 181
 
182 182
 	// initialize result array
183
-	for ($i=0; $i <= 15; $i++) $result[$i] = 0;
183
+	for ($i = 0; $i <= 15; $i++) $result[$i] = 0;
184 184
 
185 185
 	// if there's some localtax including vat, we calculate localtaxes (we will add later)
186 186
 
187 187
     //If input unit price is 'HT', we need to have the totals with main VAT for a correct calculation
188 188
     if ($price_base_type != 'TTC')
189 189
     {
190
-    	$tot_sans_remise_wt = price2num($tot_sans_remise * (1 + ($txtva / 100)),'MU');
191
-    	$tot_avec_remise_wt = price2num($tot_avec_remise * (1 + ($txtva / 100)),'MU');
192
-    	$pu_wt = price2num($pu * (1 + ($txtva / 100)),'MU');
190
+    	$tot_sans_remise_wt = price2num($tot_sans_remise * (1 + ($txtva / 100)), 'MU');
191
+    	$tot_avec_remise_wt = price2num($tot_avec_remise * (1 + ($txtva / 100)), 'MU');
192
+    	$pu_wt = price2num($pu * (1 + ($txtva / 100)), 'MU');
193 193
     }
194 194
     else
195 195
     {
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
 
201 201
 	//print 'rr'.$price_base_type.'-'.$txtva.'-'.$tot_sans_remise_wt."-".$pu_wt."-".$uselocaltax1_rate."-".$localtax1_rate."-".$localtax1_type."\n";
202 202
 
203
-    $localtaxes = array(0,0,0);
203
+    $localtaxes = array(0, 0, 0);
204 204
     $apply_tax = false;
205
-  	switch($localtax1_type) {
205
+  	switch ($localtax1_type) {
206 206
       case '2':     // localtax on product or service
207 207
         $apply_tax = true;
208 208
         break;
@@ -215,18 +215,18 @@  discard block
 block discarded – undo
215 215
     }
216 216
 
217 217
     if ($uselocaltax1_rate && $apply_tax) {
218
-  		$result[14] = price2num(($tot_sans_remise_wt * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise_wt, 'MT');
218
+  		$result[14] = price2num(($tot_sans_remise_wt * (1 + ($localtax1_rate / 100))) - $tot_sans_remise_wt, 'MT');
219 219
   		$localtaxes[0] += $result[14];
220 220
 
221
-  		$result[9] = price2num(($tot_avec_remise_wt * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise_wt, 'MT');
221
+  		$result[9] = price2num(($tot_avec_remise_wt * (1 + ($localtax1_rate / 100))) - $tot_avec_remise_wt, 'MT');
222 222
   		$localtaxes[1] += $result[9];
223 223
 
224
-  		$result[11] = price2num(($pu_wt * (1 + ( $localtax1_rate / 100))) - $pu_wt, 'MU');
224
+  		$result[11] = price2num(($pu_wt * (1 + ($localtax1_rate / 100))) - $pu_wt, 'MU');
225 225
   		$localtaxes[2] += $result[11];
226 226
     }
227 227
 
228 228
     $apply_tax = false;
229
-  	switch($localtax2_type) {
229
+  	switch ($localtax2_type) {
230 230
       case '2':     // localtax on product or service
231 231
         $apply_tax = true;
232 232
         break;
@@ -238,13 +238,13 @@  discard block
 block discarded – undo
238 238
         break;
239 239
     }
240 240
     if ($uselocaltax2_rate && $apply_tax) {
241
-  		$result[15] = price2num(($tot_sans_remise_wt * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise_wt, 'MT');
241
+  		$result[15] = price2num(($tot_sans_remise_wt * (1 + ($localtax2_rate / 100))) - $tot_sans_remise_wt, 'MT');
242 242
   		$localtaxes[0] += $result[15];
243 243
 
244
-  		$result[10] = price2num(($tot_avec_remise_wt * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise_wt, 'MT');
244
+  		$result[10] = price2num(($tot_avec_remise_wt * (1 + ($localtax2_rate / 100))) - $tot_avec_remise_wt, 'MT');
245 245
   		$localtaxes[1] += $result[10];
246 246
 
247
-  		$result[12] = price2num(($pu_wt * (1 + ( $localtax2_rate / 100))) - $pu_wt, 'MU');
247
+  		$result[12] = price2num(($pu_wt * (1 + ($localtax2_rate / 100))) - $pu_wt, 'MU');
248 248
   		$localtaxes[2] += $result[12];
249 249
     }
250 250
 
@@ -253,36 +253,36 @@  discard block
 block discarded – undo
253 253
 	{
254 254
 		// We work to define prices using the price without tax
255 255
 		$result[6] = price2num($tot_sans_remise, 'MT');
256
-		$result[8] = price2num($tot_sans_remise * (1 + ( (($info_bits & 1)?0:$txtva) / 100)) + $localtaxes[0], 'MT');	// Selon TVA NPR ou non
257
-		$result8bis= price2num($tot_sans_remise * (1 + ( $txtva / 100)) + $localtaxes[0], 'MT');	// Si TVA consideree normale (non NPR)
256
+		$result[8] = price2num($tot_sans_remise * (1 + ((($info_bits & 1) ? 0 : $txtva) / 100)) + $localtaxes[0], 'MT'); // Selon TVA NPR ou non
257
+		$result8bis = price2num($tot_sans_remise * (1 + ($txtva / 100)) + $localtaxes[0], 'MT'); // Si TVA consideree normale (non NPR)
258 258
 		$result[7] = price2num($result8bis - ($result[6] + $localtaxes[0]), 'MT');
259 259
 
260 260
 		$result[0] = price2num($tot_avec_remise, 'MT');
261
-		$result[2] = price2num($tot_avec_remise * (1 + ( (($info_bits & 1)?0:$txtva) / 100)) + $localtaxes[1], 'MT');	// Selon TVA NPR ou non
262
-		$result2bis= price2num($tot_avec_remise * (1 + ( $txtva / 100)) + $localtaxes[1], 'MT');	// Si TVA consideree normale (non NPR)
263
-		$result[1] = price2num($result2bis - ($result[0] + $localtaxes[1]), 'MT');	// Total VAT = TTC - (HT + localtax)
261
+		$result[2] = price2num($tot_avec_remise * (1 + ((($info_bits & 1) ? 0 : $txtva) / 100)) + $localtaxes[1], 'MT'); // Selon TVA NPR ou non
262
+		$result2bis = price2num($tot_avec_remise * (1 + ($txtva / 100)) + $localtaxes[1], 'MT'); // Si TVA consideree normale (non NPR)
263
+		$result[1] = price2num($result2bis - ($result[0] + $localtaxes[1]), 'MT'); // Total VAT = TTC - (HT + localtax)
264 264
 
265 265
 		$result[3] = price2num($pu, 'MU');
266
-		$result[5] = price2num($pu * (1 + ( (($info_bits & 1)?0:$txtva) / 100)) + $localtaxes[2], 'MU');	// Selon TVA NPR ou non
267
-		$result5bis= price2num($pu * (1 + ($txtva / 100)) + $localtaxes[2], 'MU');	// Si TVA consideree normale (non NPR)
266
+		$result[5] = price2num($pu * (1 + ((($info_bits & 1) ? 0 : $txtva) / 100)) + $localtaxes[2], 'MU'); // Selon TVA NPR ou non
267
+		$result5bis = price2num($pu * (1 + ($txtva / 100)) + $localtaxes[2], 'MU'); // Si TVA consideree normale (non NPR)
268 268
 		$result[4] = price2num($result5bis - ($result[3] + $localtaxes[2]), 'MU');
269 269
 	}
270 270
 	else
271 271
 	{
272 272
 		// We work to define prices using the price with tax
273 273
 		$result[8] = price2num($tot_sans_remise + $localtaxes[0], 'MT');
274
-		$result[6] = price2num($tot_sans_remise / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT');	// Selon TVA NPR ou non
275
-		$result6bis= price2num($tot_sans_remise / (1 + ($txtva / 100)), 'MT');	// Si TVA consideree normale (non NPR)
274
+		$result[6] = price2num($tot_sans_remise / (1 + ((($info_bits & 1) ? 0 : $txtva) / 100)), 'MT'); // Selon TVA NPR ou non
275
+		$result6bis = price2num($tot_sans_remise / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
276 276
 		$result[7] = price2num($result[8] - ($result6bis + $localtaxes[0]), 'MT');
277 277
 
278 278
 		$result[2] = price2num($tot_avec_remise + $localtaxes[1], 'MT');
279
-		$result[0] = price2num($tot_avec_remise / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MT');	// Selon TVA NPR ou non
280
-		$result0bis= price2num($tot_avec_remise / (1 + ($txtva / 100)), 'MT');	// Si TVA consideree normale (non NPR)
281
-		$result[1] = price2num($result[2] - ($result0bis + $localtaxes[1]), 'MT');	// Total VAT = TTC - (HT + localtax)
279
+		$result[0] = price2num($tot_avec_remise / (1 + ((($info_bits & 1) ? 0 : $txtva) / 100)), 'MT'); // Selon TVA NPR ou non
280
+		$result0bis = price2num($tot_avec_remise / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normale (non NPR)
281
+		$result[1] = price2num($result[2] - ($result0bis + $localtaxes[1]), 'MT'); // Total VAT = TTC - (HT + localtax)
282 282
 
283 283
 		$result[5] = price2num($pu + $localtaxes[2], 'MU');
284
-		$result[3] = price2num($pu / (1 + ((($info_bits & 1)?0:$txtva) / 100)), 'MU');	// Selon TVA NPR ou non
285
-		$result3bis= price2num($pu / (1 + ($txtva / 100)), 'MU');	// Si TVA consideree normale (non NPR)
284
+		$result[3] = price2num($pu / (1 + ((($info_bits & 1) ? 0 : $txtva) / 100)), 'MU'); // Selon TVA NPR ou non
285
+		$result3bis = price2num($pu / (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normale (non NPR)
286 286
 		$result[4] = price2num($result[5] - ($result3bis + $localtaxes[2]), 'MU');
287 287
 	}
288 288
 
@@ -291,13 +291,13 @@  discard block
 block discarded – undo
291 291
     //If input unit price is 'TTC', we need to have the totals without main VAT for a correct calculation
292 292
     if ($price_base_type == 'TTC')
293 293
     {
294
-    	$tot_sans_remise= price2num($tot_sans_remise / (1 + ($txtva / 100)),'MU');
295
-    	$tot_avec_remise= price2num($tot_avec_remise / (1 + ($txtva / 100)),'MU');
296
-    	$pu = price2num($pu / (1 + ($txtva / 100)),'MU');
294
+    	$tot_sans_remise = price2num($tot_sans_remise / (1 + ($txtva / 100)), 'MU');
295
+    	$tot_avec_remise = price2num($tot_avec_remise / (1 + ($txtva / 100)), 'MU');
296
+    	$pu = price2num($pu / (1 + ($txtva / 100)), 'MU');
297 297
     }
298 298
 
299 299
 	$apply_tax = false;
300
-    switch($localtax1_type) {
300
+    switch ($localtax1_type) {
301 301
       case '1':     // localtax on product or service
302 302
         $apply_tax = true;
303 303
         break;
@@ -309,18 +309,18 @@  discard block
 block discarded – undo
309 309
         break;
310 310
     }
311 311
     if ($uselocaltax1_rate && $apply_tax) {
312
-  		$result[14] = price2num(($tot_sans_remise * (1 + ( $localtax1_rate / 100))) - $tot_sans_remise, 'MT');	// amount tax1 for total_ht_without_discount
313
-  		$result[8] += $result[14];																				// total_ttc_without_discount + tax1
312
+  		$result[14] = price2num(($tot_sans_remise * (1 + ($localtax1_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax1 for total_ht_without_discount
313
+  		$result[8] += $result[14]; // total_ttc_without_discount + tax1
314 314
 
315
-  		$result[9] = price2num(($tot_avec_remise * (1 + ( $localtax1_rate / 100))) - $tot_avec_remise, 'MT');	// amount tax1 for total_ht
316
-  		$result[2] += $result[9];																				// total_ttc + tax1
315
+  		$result[9] = price2num(($tot_avec_remise * (1 + ($localtax1_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax1 for total_ht
316
+  		$result[2] += $result[9]; // total_ttc + tax1
317 317
 
318
-  		$result[11] = price2num(($pu * (1 + ( $localtax1_rate / 100))) - $pu, 'MU');							// amount tax1 for pu_ht
319
-  		$result[5] += $result[11];																				// pu_ht + tax1
318
+  		$result[11] = price2num(($pu * (1 + ($localtax1_rate / 100))) - $pu, 'MU'); // amount tax1 for pu_ht
319
+  		$result[5] += $result[11]; // pu_ht + tax1
320 320
     }
321 321
 
322 322
     $apply_tax = false;
323
-  	switch($localtax2_type) {
323
+  	switch ($localtax2_type) {
324 324
       case '1':     // localtax on product or service
325 325
         $apply_tax = true;
326 326
         break;
@@ -332,34 +332,34 @@  discard block
 block discarded – undo
332 332
         break;
333 333
     }
334 334
     if ($uselocaltax2_rate && $apply_tax) {
335
-  		$result[15] = price2num(($tot_sans_remise * (1 + ( $localtax2_rate / 100))) - $tot_sans_remise, 'MT');	// amount tax2 for total_ht_without_discount
336
-  		$result[8] += $result[15];																				// total_ttc_without_discount + tax2
335
+  		$result[15] = price2num(($tot_sans_remise * (1 + ($localtax2_rate / 100))) - $tot_sans_remise, 'MT'); // amount tax2 for total_ht_without_discount
336
+  		$result[8] += $result[15]; // total_ttc_without_discount + tax2
337 337
 
338
-  		$result[10] = price2num(($tot_avec_remise * (1 + ( $localtax2_rate / 100))) - $tot_avec_remise, 'MT');	// amount tax2 for total_ht
339
-  		$result[2] += $result[10];																				// total_ttc + tax2
338
+  		$result[10] = price2num(($tot_avec_remise * (1 + ($localtax2_rate / 100))) - $tot_avec_remise, 'MT'); // amount tax2 for total_ht
339
+  		$result[2] += $result[10]; // total_ttc + tax2
340 340
 
341
-  		$result[12] = price2num(($pu * (1 + ( $localtax2_rate / 100))) - $pu, 'MU');							// amount tax2 for pu_ht
342
-  		$result[5] += $result[12];																				// pu_ht + tax2
341
+  		$result[12] = price2num(($pu * (1 + ($localtax2_rate / 100))) - $pu, 'MU'); // amount tax2 for pu_ht
342
+  		$result[5] += $result[12]; // pu_ht + tax2
343 343
     }
344 344
 
345 345
 	// If rounding is not using base 10 (rare)
346
-	if (! empty($conf->global->MAIN_ROUNDING_RULE_TOT))
346
+	if (!empty($conf->global->MAIN_ROUNDING_RULE_TOT))
347 347
 	{
348 348
 		if ($price_base_type == 'HT')
349 349
 		{
350
-			$result[0]=round($result[0]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
351
-			$result[1]=round($result[1]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
352
-			$result[2]=price2num($result[0]+$result[1], 'MT');
353
-			$result[9]=round($result[9]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
354
-			$result[10]=round($result[10]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
350
+			$result[0] = round($result[0] / $conf->global->MAIN_ROUNDING_RULE_TOT, 0) * $conf->global->MAIN_ROUNDING_RULE_TOT;
351
+			$result[1] = round($result[1] / $conf->global->MAIN_ROUNDING_RULE_TOT, 0) * $conf->global->MAIN_ROUNDING_RULE_TOT;
352
+			$result[2] = price2num($result[0] + $result[1], 'MT');
353
+			$result[9] = round($result[9] / $conf->global->MAIN_ROUNDING_RULE_TOT, 0) * $conf->global->MAIN_ROUNDING_RULE_TOT;
354
+			$result[10] = round($result[10] / $conf->global->MAIN_ROUNDING_RULE_TOT, 0) * $conf->global->MAIN_ROUNDING_RULE_TOT;
355 355
 		}
356 356
 		else
357 357
 		{
358
-			$result[1]=round($result[1]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
359
-			$result[2]=round($result[2]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
360
-			$result[0]=price2num($result[2]-$result[1], 'MT');
361
-			$result[9]=round($result[9]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
362
-			$result[10]=round($result[10]/$conf->global->MAIN_ROUNDING_RULE_TOT, 0)*$conf->global->MAIN_ROUNDING_RULE_TOT;
358
+			$result[1] = round($result[1] / $conf->global->MAIN_ROUNDING_RULE_TOT, 0) * $conf->global->MAIN_ROUNDING_RULE_TOT;
359
+			$result[2] = round($result[2] / $conf->global->MAIN_ROUNDING_RULE_TOT, 0) * $conf->global->MAIN_ROUNDING_RULE_TOT;
360
+			$result[0] = price2num($result[2] - $result[1], 'MT');
361
+			$result[9] = round($result[9] / $conf->global->MAIN_ROUNDING_RULE_TOT, 0) * $conf->global->MAIN_ROUNDING_RULE_TOT;
362
+			$result[10] = round($result[10] / $conf->global->MAIN_ROUNDING_RULE_TOT, 0) * $conf->global->MAIN_ROUNDING_RULE_TOT;
363 363
 		}
364 364
 	}
365 365
 
Please login to merge, or discard this patch.