Test Failed
Branch develop (86e751)
by Laurent
34:11
created
htdocs/core/lib/geturl.lib.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
  * @param	string    $param			    Parameters of URL (x=value1&y=value2) or may be a formated content with PUTALREADYFORMATED
30 30
  * @param	integer   $followlocation		1=Follow location, 0=Do not follow
31 31
  * @param	string[]  $addheaders			Array of string to add into header. Example: ('Accept: application/xrds+xml', ....)
32
- * @return	array						    Returns an associative array containing the response from the server array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...)
32
+ * @return	string						    Returns an associative array containing the response from the server array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...)
33 33
  */
34 34
 function getURLContent($url,$postorget='GET',$param='',$followlocation=1,$addheaders=array())
35 35
 {
Please login to merge, or discard this patch.
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -33,25 +33,25 @@  discard block
 block discarded – undo
33 33
  */
34 34
 function getURLContent($url,$postorget='GET',$param='',$followlocation=1,$addheaders=array())
35 35
 {
36
-    //declaring of global variables
37
-    global $conf, $langs;
38
-    $USE_PROXY=empty($conf->global->MAIN_PROXY_USE)?0:$conf->global->MAIN_PROXY_USE;
39
-    $PROXY_HOST=empty($conf->global->MAIN_PROXY_HOST)?0:$conf->global->MAIN_PROXY_HOST;
40
-    $PROXY_PORT=empty($conf->global->MAIN_PROXY_PORT)?0:$conf->global->MAIN_PROXY_PORT;
41
-    $PROXY_USER=empty($conf->global->MAIN_PROXY_USER)?0:$conf->global->MAIN_PROXY_USER;
42
-    $PROXY_PASS=empty($conf->global->MAIN_PROXY_PASS)?0:$conf->global->MAIN_PROXY_PASS;
36
+	//declaring of global variables
37
+	global $conf, $langs;
38
+	$USE_PROXY=empty($conf->global->MAIN_PROXY_USE)?0:$conf->global->MAIN_PROXY_USE;
39
+	$PROXY_HOST=empty($conf->global->MAIN_PROXY_HOST)?0:$conf->global->MAIN_PROXY_HOST;
40
+	$PROXY_PORT=empty($conf->global->MAIN_PROXY_PORT)?0:$conf->global->MAIN_PROXY_PORT;
41
+	$PROXY_USER=empty($conf->global->MAIN_PROXY_USER)?0:$conf->global->MAIN_PROXY_USER;
42
+	$PROXY_PASS=empty($conf->global->MAIN_PROXY_PASS)?0:$conf->global->MAIN_PROXY_PASS;
43 43
 
44 44
 	dol_syslog("getURLContent postorget=".$postorget." URL=".$url." param=".$param);
45 45
 
46
-    //setting the curl parameters.
47
-    $ch = curl_init();
46
+	//setting the curl parameters.
47
+	$ch = curl_init();
48 48
 
49
-    /*print $API_Endpoint."-".$API_version."-".$PAYPAL_API_USER."-".$PAYPAL_API_PASSWORD."-".$PAYPAL_API_SIGNATURE."<br>";
49
+	/*print $API_Endpoint."-".$API_version."-".$PAYPAL_API_USER."-".$PAYPAL_API_PASSWORD."-".$PAYPAL_API_SIGNATURE."<br>";
50 50
      print $USE_PROXY."-".$gv_ApiErrorURL."<br>";
51 51
      print $nvpStr;
52 52
      exit;*/
53
-    curl_setopt($ch, CURLOPT_URL, $url);
54
-    curl_setopt($ch, CURLOPT_VERBOSE, 1);
53
+	curl_setopt($ch, CURLOPT_URL, $url);
54
+	curl_setopt($ch, CURLOPT_VERBOSE, 1);
55 55
 	curl_setopt($ch, CURLOPT_USERAGENT, 'Dolibarr geturl function');
56 56
 
57 57
 	@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ($followlocation?true:false));   // We use @ here because this may return warning if safe mode is on or open_basedir is on
@@ -64,99 +64,99 @@  discard block
 block discarded – undo
64 64
 	if (! empty($conf->global->MAIN_CURL_SSLVERSION)) curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION);
65 65
 	//curl_setopt($ch, CURLOPT_SSLVERSION, 6); for tls 1.2
66 66
 
67
-    //turning off the server and peer verification(TrustManager Concept).
68
-    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
69
-    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
70
-
71
-    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)?5:$conf->global->MAIN_USE_CONNECT_TIMEOUT);
72
-    curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT)?30:$conf->global->MAIN_USE_RESPONSE_TIMEOUT);
73
-
74
-    //curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);	// PHP 5.5
75
-    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);		// We want response
76
-    if ($postorget == 'POST')
77
-    {
78
-    	curl_setopt($ch, CURLOPT_POST, 1);	// POST
79
-    	curl_setopt($ch, CURLOPT_POSTFIELDS, $param);	// Setting param x=a&y=z as POST fields
80
-    }
81
-    else if ($postorget == 'PUT')
82
-    {
83
-    	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT'
84
-    	if (! is_array($param)) parse_str($param, $array_param);
85
-    	else
86
-    	{
87
-    	    dol_syslog("parameter param must be a string", LOG_WARNING);
88
-    	    $array_param=$param;
89
-    	}
90
-    	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param));	// Setting param x=a&y=z as PUT fields
91
-    }
92
-    else if ($postorget == 'PUTALREADYFORMATED')
93
-    {
94
-    	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT'
95
-    	curl_setopt($ch, CURLOPT_POSTFIELDS, $param);	// param = content of post, like a xml string
96
-    }
97
-    else if ($postorget == 'HEAD')
98
-    {
99
-    	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD'
100
-    	curl_setopt($ch, CURLOPT_NOBODY, true);
101
-    }
102
-    else if ($postorget == 'DELETE')
103
-    {
104
-    	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');	// POST
105
-    }
106
-    else
107
-    {
108
-    	curl_setopt($ch, CURLOPT_POST, 0);			// GET
109
-    }
110
-
111
-    //if USE_PROXY constant set at begin of this method.
112
-    if ($USE_PROXY)
113
-    {
114
-        dol_syslog("getURLContent set proxy to ".$PROXY_HOST. ":" . $PROXY_PORT." - ".$PROXY_USER. ":" . $PROXY_PASS);
115
-        //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10
116
-        curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT);
117
-        if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS);
118
-    }
119
-
120
-    //getting response from server
121
-    $response = curl_exec($ch);
122
-
123
-    $request = curl_getinfo($ch, CURLINFO_HEADER_OUT);	// Reading of request must be done after sending request
124
-
125
-    dol_syslog("getURLContent request=".$request);
126
-    dol_syslog("getURLContent response=".$response);
127
-
128
-    $rep=array();
129
-    if (curl_errno($ch))
130
-    {
131
-        // Ad keys to $rep
132
-        $rep['content']=$response;
133
-
134
-        // moving to display page to display curl errors
67
+	//turning off the server and peer verification(TrustManager Concept).
68
+	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
69
+	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
70
+
71
+	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)?5:$conf->global->MAIN_USE_CONNECT_TIMEOUT);
72
+	curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT)?30:$conf->global->MAIN_USE_RESPONSE_TIMEOUT);
73
+
74
+	//curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);	// PHP 5.5
75
+	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);		// We want response
76
+	if ($postorget == 'POST')
77
+	{
78
+		curl_setopt($ch, CURLOPT_POST, 1);	// POST
79
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $param);	// Setting param x=a&y=z as POST fields
80
+	}
81
+	else if ($postorget == 'PUT')
82
+	{
83
+		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT'
84
+		if (! is_array($param)) parse_str($param, $array_param);
85
+		else
86
+		{
87
+			dol_syslog("parameter param must be a string", LOG_WARNING);
88
+			$array_param=$param;
89
+		}
90
+		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param));	// Setting param x=a&y=z as PUT fields
91
+	}
92
+	else if ($postorget == 'PUTALREADYFORMATED')
93
+	{
94
+		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT'
95
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $param);	// param = content of post, like a xml string
96
+	}
97
+	else if ($postorget == 'HEAD')
98
+	{
99
+		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD'
100
+		curl_setopt($ch, CURLOPT_NOBODY, true);
101
+	}
102
+	else if ($postorget == 'DELETE')
103
+	{
104
+		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');	// POST
105
+	}
106
+	else
107
+	{
108
+		curl_setopt($ch, CURLOPT_POST, 0);			// GET
109
+	}
110
+
111
+	//if USE_PROXY constant set at begin of this method.
112
+	if ($USE_PROXY)
113
+	{
114
+		dol_syslog("getURLContent set proxy to ".$PROXY_HOST. ":" . $PROXY_PORT." - ".$PROXY_USER. ":" . $PROXY_PASS);
115
+		//curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10
116
+		curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT);
117
+		if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS);
118
+	}
119
+
120
+	//getting response from server
121
+	$response = curl_exec($ch);
122
+
123
+	$request = curl_getinfo($ch, CURLINFO_HEADER_OUT);	// Reading of request must be done after sending request
124
+
125
+	dol_syslog("getURLContent request=".$request);
126
+	dol_syslog("getURLContent response=".$response);
127
+
128
+	$rep=array();
129
+	if (curl_errno($ch))
130
+	{
131
+		// Ad keys to $rep
132
+		$rep['content']=$response;
133
+
134
+		// moving to display page to display curl errors
135 135
 		$rep['curl_error_no']=curl_errno($ch);
136
-        $rep['curl_error_msg']=curl_error($ch);
136
+		$rep['curl_error_msg']=curl_error($ch);
137 137
 
138 138
 		dol_syslog("getURLContent response array is ".join(',',$rep));
139
-    }
140
-    else
141
-    {
142
-    	$info = curl_getinfo($ch);
143
-
144
-    	// Ad keys to $rep
145
-    	$rep = $info;
146
-    	//$rep['header_size']=$info['header_size'];
147
-    	//$rep['http_code']=$info['http_code'];
148
-    	dol_syslog("getURLContent http_code=".$rep['http_code']);
149
-
150
-        // Add more keys to $rep
151
-        $rep['content']=$response;
152
-    	$rep['curl_error_no']='';
153
-    	$rep['curl_error_msg']='';
154
-
155
-    	//closing the curl
156
-        curl_close($ch);
157
-    }
158
-
159
-    return $rep;
139
+	}
140
+	else
141
+	{
142
+		$info = curl_getinfo($ch);
143
+
144
+		// Ad keys to $rep
145
+		$rep = $info;
146
+		//$rep['header_size']=$info['header_size'];
147
+		//$rep['http_code']=$info['http_code'];
148
+		dol_syslog("getURLContent http_code=".$rep['http_code']);
149
+
150
+		// Add more keys to $rep
151
+		$rep['content']=$response;
152
+		$rep['curl_error_no']='';
153
+		$rep['curl_error_msg']='';
154
+
155
+		//closing the curl
156
+		curl_close($ch);
157
+	}
158
+
159
+	return $rep;
160 160
 }
161 161
 
162 162
 
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -31,15 +31,15 @@  discard block
 block discarded – undo
31 31
  * @param	string[]  $addheaders			Array of string to add into header. Example: ('Accept: application/xrds+xml', ....)
32 32
  * @return	array						    Returns an associative array containing the response from the server array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...)
33 33
  */
34
-function getURLContent($url,$postorget='GET',$param='',$followlocation=1,$addheaders=array())
34
+function getURLContent($url, $postorget = 'GET', $param = '', $followlocation = 1, $addheaders = array())
35 35
 {
36 36
     //declaring of global variables
37 37
     global $conf, $langs;
38
-    $USE_PROXY=empty($conf->global->MAIN_PROXY_USE)?0:$conf->global->MAIN_PROXY_USE;
39
-    $PROXY_HOST=empty($conf->global->MAIN_PROXY_HOST)?0:$conf->global->MAIN_PROXY_HOST;
40
-    $PROXY_PORT=empty($conf->global->MAIN_PROXY_PORT)?0:$conf->global->MAIN_PROXY_PORT;
41
-    $PROXY_USER=empty($conf->global->MAIN_PROXY_USER)?0:$conf->global->MAIN_PROXY_USER;
42
-    $PROXY_PASS=empty($conf->global->MAIN_PROXY_PASS)?0:$conf->global->MAIN_PROXY_PASS;
38
+    $USE_PROXY = empty($conf->global->MAIN_PROXY_USE) ? 0 : $conf->global->MAIN_PROXY_USE;
39
+    $PROXY_HOST = empty($conf->global->MAIN_PROXY_HOST) ? 0 : $conf->global->MAIN_PROXY_HOST;
40
+    $PROXY_PORT = empty($conf->global->MAIN_PROXY_PORT) ? 0 : $conf->global->MAIN_PROXY_PORT;
41
+    $PROXY_USER = empty($conf->global->MAIN_PROXY_USER) ? 0 : $conf->global->MAIN_PROXY_USER;
42
+    $PROXY_PASS = empty($conf->global->MAIN_PROXY_PASS) ? 0 : $conf->global->MAIN_PROXY_PASS;
43 43
 
44 44
 	dol_syslog("getURLContent postorget=".$postorget." URL=".$url." param=".$param);
45 45
 
@@ -54,45 +54,45 @@  discard block
 block discarded – undo
54 54
     curl_setopt($ch, CURLOPT_VERBOSE, 1);
55 55
 	curl_setopt($ch, CURLOPT_USERAGENT, 'Dolibarr geturl function');
56 56
 
57
-	@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ($followlocation?true:false));   // We use @ here because this may return warning if safe mode is on or open_basedir is on
57
+	@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ($followlocation ?true:false)); // We use @ here because this may return warning if safe mode is on or open_basedir is on
58 58
 
59 59
 	if (count($addheaders)) curl_setopt($ch, CURLOPT_HTTPHEADER, $addheaders);
60
-	curl_setopt($ch, CURLINFO_HEADER_OUT, true);	// To be able to retrieve request header and log it
60
+	curl_setopt($ch, CURLINFO_HEADER_OUT, true); // To be able to retrieve request header and log it
61 61
 
62 62
 	// By default use tls decied by PHP.
63 63
 	// You can force, if supported a version like TLSv1 or TLSv1.2
64
-	if (! empty($conf->global->MAIN_CURL_SSLVERSION)) curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION);
64
+	if (!empty($conf->global->MAIN_CURL_SSLVERSION)) curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION);
65 65
 	//curl_setopt($ch, CURLOPT_SSLVERSION, 6); for tls 1.2
66 66
 
67 67
     //turning off the server and peer verification(TrustManager Concept).
68 68
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
69 69
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
70 70
 
71
-    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)?5:$conf->global->MAIN_USE_CONNECT_TIMEOUT);
72
-    curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT)?30:$conf->global->MAIN_USE_RESPONSE_TIMEOUT);
71
+    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT) ? 5 : $conf->global->MAIN_USE_CONNECT_TIMEOUT);
72
+    curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT) ? 30 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
73 73
 
74 74
     //curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);	// PHP 5.5
75
-    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);		// We want response
75
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // We want response
76 76
     if ($postorget == 'POST')
77 77
     {
78
-    	curl_setopt($ch, CURLOPT_POST, 1);	// POST
79
-    	curl_setopt($ch, CURLOPT_POSTFIELDS, $param);	// Setting param x=a&y=z as POST fields
78
+    	curl_setopt($ch, CURLOPT_POST, 1); // POST
79
+    	curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // Setting param x=a&y=z as POST fields
80 80
     }
81 81
     else if ($postorget == 'PUT')
82 82
     {
83 83
     	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT'
84
-    	if (! is_array($param)) parse_str($param, $array_param);
84
+    	if (!is_array($param)) parse_str($param, $array_param);
85 85
     	else
86 86
     	{
87 87
     	    dol_syslog("parameter param must be a string", LOG_WARNING);
88
-    	    $array_param=$param;
88
+    	    $array_param = $param;
89 89
     	}
90
-    	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param));	// Setting param x=a&y=z as PUT fields
90
+    	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param)); // Setting param x=a&y=z as PUT fields
91 91
     }
92 92
     else if ($postorget == 'PUTALREADYFORMATED')
93 93
     {
94 94
     	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT'
95
-    	curl_setopt($ch, CURLOPT_POSTFIELDS, $param);	// param = content of post, like a xml string
95
+    	curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // param = content of post, like a xml string
96 96
     }
97 97
     else if ($postorget == 'HEAD')
98 98
     {
@@ -101,41 +101,41 @@  discard block
 block discarded – undo
101 101
     }
102 102
     else if ($postorget == 'DELETE')
103 103
     {
104
-    	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');	// POST
104
+    	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); // POST
105 105
     }
106 106
     else
107 107
     {
108
-    	curl_setopt($ch, CURLOPT_POST, 0);			// GET
108
+    	curl_setopt($ch, CURLOPT_POST, 0); // GET
109 109
     }
110 110
 
111 111
     //if USE_PROXY constant set at begin of this method.
112 112
     if ($USE_PROXY)
113 113
     {
114
-        dol_syslog("getURLContent set proxy to ".$PROXY_HOST. ":" . $PROXY_PORT." - ".$PROXY_USER. ":" . $PROXY_PASS);
114
+        dol_syslog("getURLContent set proxy to ".$PROXY_HOST.":".$PROXY_PORT." - ".$PROXY_USER.":".$PROXY_PASS);
115 115
         //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10
116
-        curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT);
117
-        if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS);
116
+        curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.":".$PROXY_PORT);
117
+        if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.":".$PROXY_PASS);
118 118
     }
119 119
 
120 120
     //getting response from server
121 121
     $response = curl_exec($ch);
122 122
 
123
-    $request = curl_getinfo($ch, CURLINFO_HEADER_OUT);	// Reading of request must be done after sending request
123
+    $request = curl_getinfo($ch, CURLINFO_HEADER_OUT); // Reading of request must be done after sending request
124 124
 
125 125
     dol_syslog("getURLContent request=".$request);
126 126
     dol_syslog("getURLContent response=".$response);
127 127
 
128
-    $rep=array();
128
+    $rep = array();
129 129
     if (curl_errno($ch))
130 130
     {
131 131
         // Ad keys to $rep
132
-        $rep['content']=$response;
132
+        $rep['content'] = $response;
133 133
 
134 134
         // moving to display page to display curl errors
135
-		$rep['curl_error_no']=curl_errno($ch);
136
-        $rep['curl_error_msg']=curl_error($ch);
135
+		$rep['curl_error_no'] = curl_errno($ch);
136
+        $rep['curl_error_msg'] = curl_error($ch);
137 137
 
138
-		dol_syslog("getURLContent response array is ".join(',',$rep));
138
+		dol_syslog("getURLContent response array is ".join(',', $rep));
139 139
     }
140 140
     else
141 141
     {
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
     	dol_syslog("getURLContent http_code=".$rep['http_code']);
149 149
 
150 150
         // Add more keys to $rep
151
-        $rep['content']=$response;
152
-    	$rep['curl_error_no']='';
153
-    	$rep['curl_error_msg']='';
151
+        $rep['content'] = $response;
152
+    	$rep['curl_error_no'] = '';
153
+    	$rep['curl_error_msg'] = '';
154 154
 
155 155
     	//closing the curl
156 156
         curl_close($ch);
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
  */
170 170
 function getDomainFromURL($url)
171 171
 {
172
-	$tmpdomain = preg_replace('/^https?:\/\//i', '', $url);				// Remove http(s)://
173
-	$tmpdomain = preg_replace('/\/.*$/i', '', $tmpdomain);				// Remove part after domain
174
-	$tmpdomain = preg_replace('/\.[^\.]+$/', '', $tmpdomain);			// Remove first level domain (.com, .net, ...)
175
-	$tmpdomain = preg_replace('/^[^\.]+\./', '', $tmpdomain);			// Remove part www. before domain name
172
+	$tmpdomain = preg_replace('/^https?:\/\//i', '', $url); // Remove http(s)://
173
+	$tmpdomain = preg_replace('/\/.*$/i', '', $tmpdomain); // Remove part after domain
174
+	$tmpdomain = preg_replace('/\.[^\.]+$/', '', $tmpdomain); // Remove first level domain (.com, .net, ...)
175
+	$tmpdomain = preg_replace('/^[^\.]+\./', '', $tmpdomain); // Remove part www. before domain name
176 176
 	return $tmpdomain;
177 177
 }
Please login to merge, or discard this patch.
Braces   +18 added lines, -17 removed lines patch added patch discarded remove patch
@@ -56,12 +56,16 @@  discard block
 block discarded – undo
56 56
 
57 57
 	@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ($followlocation?true:false));   // We use @ here because this may return warning if safe mode is on or open_basedir is on
58 58
 
59
-	if (count($addheaders)) curl_setopt($ch, CURLOPT_HTTPHEADER, $addheaders);
59
+	if (count($addheaders)) {
60
+		curl_setopt($ch, CURLOPT_HTTPHEADER, $addheaders);
61
+	}
60 62
 	curl_setopt($ch, CURLINFO_HEADER_OUT, true);	// To be able to retrieve request header and log it
61 63
 
62 64
 	// By default use tls decied by PHP.
63 65
 	// You can force, if supported a version like TLSv1 or TLSv1.2
64
-	if (! empty($conf->global->MAIN_CURL_SSLVERSION)) curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION);
66
+	if (! empty($conf->global->MAIN_CURL_SSLVERSION)) {
67
+		curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION);
68
+	}
65 69
 	//curl_setopt($ch, CURLOPT_SSLVERSION, 6); for tls 1.2
66 70
 
67 71
     //turning off the server and peer verification(TrustManager Concept).
@@ -77,33 +81,29 @@  discard block
 block discarded – undo
77 81
     {
78 82
     	curl_setopt($ch, CURLOPT_POST, 1);	// POST
79 83
     	curl_setopt($ch, CURLOPT_POSTFIELDS, $param);	// Setting param x=a&y=z as POST fields
80
-    }
81
-    else if ($postorget == 'PUT')
84
+    } else if ($postorget == 'PUT')
82 85
     {
83 86
     	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT'
84
-    	if (! is_array($param)) parse_str($param, $array_param);
85
-    	else
87
+    	if (! is_array($param)) {
88
+    		parse_str($param, $array_param);
89
+    	} else
86 90
     	{
87 91
     	    dol_syslog("parameter param must be a string", LOG_WARNING);
88 92
     	    $array_param=$param;
89 93
     	}
90 94
     	curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param));	// Setting param x=a&y=z as PUT fields
91
-    }
92
-    else if ($postorget == 'PUTALREADYFORMATED')
95
+    } else if ($postorget == 'PUTALREADYFORMATED')
93 96
     {
94 97
     	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT'
95 98
     	curl_setopt($ch, CURLOPT_POSTFIELDS, $param);	// param = content of post, like a xml string
96
-    }
97
-    else if ($postorget == 'HEAD')
99
+    } else if ($postorget == 'HEAD')
98 100
     {
99 101
     	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD'
100 102
     	curl_setopt($ch, CURLOPT_NOBODY, true);
101
-    }
102
-    else if ($postorget == 'DELETE')
103
+    } else if ($postorget == 'DELETE')
103 104
     {
104 105
     	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');	// POST
105
-    }
106
-    else
106
+    } else
107 107
     {
108 108
     	curl_setopt($ch, CURLOPT_POST, 0);			// GET
109 109
     }
@@ -114,7 +114,9 @@  discard block
 block discarded – undo
114 114
         dol_syslog("getURLContent set proxy to ".$PROXY_HOST. ":" . $PROXY_PORT." - ".$PROXY_USER. ":" . $PROXY_PASS);
115 115
         //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10
116 116
         curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT);
117
-        if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS);
117
+        if ($PROXY_USER) {
118
+        	curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS);
119
+        }
118 120
     }
119 121
 
120 122
     //getting response from server
@@ -136,8 +138,7 @@  discard block
 block discarded – undo
136 138
         $rep['curl_error_msg']=curl_error($ch);
137 139
 
138 140
 		dol_syslog("getURLContent response array is ".join(',',$rep));
139
-    }
140
-    else
141
+    } else
141 142
     {
142 143
     	$info = curl_getinfo($ch);
143 144
 
Please login to merge, or discard this patch.
htdocs/livraison/class/livraison.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -536,7 +536,7 @@
 block discarded – undo
536 536
 	 * Update a livraison line (only extrafields)
537 537
 	 *
538 538
 	 * @param 	int		$id					Id of line (livraison line)
539
-	 * @param	array		$array_options		extrafields array
539
+	 * @param	integer		$array_options		extrafields array
540 540
 	 * @return	int							<0 if KO, >0 if OK
541 541
 	 */
542 542
 	function update_line($id, $array_options=0)
Please login to merge, or discard this patch.
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 
87 87
 		$error = 0;
88 88
 
89
-        $now=dol_now();
89
+		$now=dol_now();
90 90
 
91 91
 		/* On positionne en mode brouillon le bon de livraison */
92 92
 		$this->brouillon = 1;
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 		$sql.= ", ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
121 121
 		$sql.= ", ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
122 122
 		$sql.= ", ".(!empty($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null");
123
-        $sql.= ", ".(int) $this->fk_incoterms;
124
-        $sql.= ", '".$this->db->escape($this->location_incoterms)."'";
123
+		$sql.= ", ".(int) $this->fk_incoterms;
124
+		$sql.= ", '".$this->db->escape($this->location_incoterms)."'";
125 125
 		$sql.= ")";
126 126
 
127 127
 		dol_syslog("Livraison::create", LOG_DEBUG);
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
 		$sql.=" l.total_ht, l.fk_statut, l.fk_user_valid, l.note_private, l.note_public";
261 261
 		$sql.= ", l.date_delivery, l.fk_address, l.model_pdf";
262 262
 		$sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
263
-        $sql.= ', l.fk_incoterms, l.location_incoterms';
264
-        $sql.= ", i.libelle as libelle_incoterms";
263
+		$sql.= ', l.fk_incoterms, l.location_incoterms';
264
+		$sql.= ", i.libelle as libelle_incoterms";
265 265
 		$sql.= " FROM ".MAIN_DB_PREFIX."livraison as l";
266 266
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = l.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
267 267
 		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON l.fk_incoterms = i.rowid';
@@ -337,13 +337,13 @@  discard block
 block discarded – undo
337 337
 	/**
338 338
 	 *        Validate object and update stock if option enabled
339 339
 	 *
340
-     *        @param 	User	$user        Object user that validate
341
-     *        @return   int
340
+	 *        @param 	User	$user        Object user that validate
341
+	 *        @return   int
342 342
 	 */
343 343
 	function valid($user)
344 344
 	{
345 345
 		global $conf, $langs;
346
-        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
346
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
347 347
 
348 348
 		dol_syslog(get_class($this)."::valid begin");
349 349
 
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
 
352 352
 		$error = 0;
353 353
 
354
-        if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison->creer))
355
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison_advance->validate)))
354
+		if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison->creer))
355
+	   	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison_advance->validate)))
356 356
 		{
357 357
 			if (! empty($conf->global->LIVRAISON_ADDON_NUMBER))
358 358
 			{
@@ -371,14 +371,14 @@  discard block
 block discarded – undo
371 371
 					$soc->fetch($this->socid);
372 372
 
373 373
 					if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life
374
-		            {
375
-		                $numref = $objMod->livraison_get_num($soc,$this);
376
-		            }
377
-		            else
378 374
 					{
379
-		                $numref = $this->ref;
380
-		            }
381
-            		$this->newref = $numref;
375
+						$numref = $objMod->livraison_get_num($soc,$this);
376
+					}
377
+					else
378
+					{
379
+						$numref = $this->ref;
380
+					}
381
+					$this->newref = $numref;
382 382
 
383 383
 					// Tester si non deja au statut valide. Si oui, on arrete afin d'eviter
384 384
 					// de decrementer 2 fois le stock.
@@ -407,24 +407,24 @@  discard block
 block discarded – undo
407 407
 					$sql.= " AND fk_statut = 0";
408 408
 
409 409
 					$resql=$this->db->query($sql);
410
-			        if (! $resql)
411
-			        {
412
-			            dol_print_error($this->db);
413
-			            $this->error=$this->db->lasterror();
414
-			            $error++;
415
-			        }
416
-
417
-			        if (! $error && ! $notrigger)
418
-			        {
419
-			            // Call trigger
420
-			            $result=$this->call_trigger('DELIVERY_VALIDATE',$user);
421
-			            if ($result < 0) $error++;
422
-			            // End call triggers
423
-			        }
410
+					if (! $resql)
411
+					{
412
+						dol_print_error($this->db);
413
+						$this->error=$this->db->lasterror();
414
+						$error++;
415
+					}
416
+
417
+					if (! $error && ! $notrigger)
418
+					{
419
+						// Call trigger
420
+						$result=$this->call_trigger('DELIVERY_VALIDATE',$user);
421
+						if ($result < 0) $error++;
422
+						// End call triggers
423
+					}
424 424
 
425 425
 					if (! $error)
426 426
 					{
427
-			            $this->oldref = $this->ref;
427
+						$this->oldref = $this->ref;
428 428
 
429 429
 						// Rename directory if dir was a temporary ref
430 430
 						if (preg_match('/^[\(]?PROV/i', $this->ref))
@@ -441,17 +441,17 @@  discard block
 block discarded – undo
441 441
 
442 442
 								if (@rename($dirsource, $dirdest))
443 443
 								{
444
-			                        dol_syslog("Rename ok");
445
-			                        // Rename docs starting with $oldref with $newref
446
-			                        $listoffiles=dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
447
-			                        foreach($listoffiles as $fileentry)
448
-			                        {
449
-			                        	$dirsource=$fileentry['name'];
450
-			                        	$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
451
-			                        	$dirsource=$fileentry['path'].'/'.$dirsource;
452
-			                        	$dirdest=$fileentry['path'].'/'.$dirdest;
453
-			                        	@rename($dirsource, $dirdest);
454
-			                        }
444
+									dol_syslog("Rename ok");
445
+									// Rename docs starting with $oldref with $newref
446
+									$listoffiles=dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
447
+									foreach($listoffiles as $fileentry)
448
+									{
449
+										$dirsource=$fileentry['name'];
450
+										$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
451
+										$dirsource=$fileentry['path'].'/'.$dirsource;
452
+										$dirdest=$fileentry['path'].'/'.$dirdest;
453
+										@rename($dirsource, $dirdest);
454
+									}
455 455
 								}
456 456
 							}
457 457
 						}
@@ -466,16 +466,16 @@  discard block
 block discarded – undo
466 466
 						dol_syslog(get_class($this)."::valid ok");
467 467
 					}
468 468
 
469
-			        if (! $error)
470
-			        {
471
-			            $this->db->commit();
472
-			            return 1;
473
-			        }
474
-			        else
469
+					if (! $error)
470
+					{
471
+						$this->db->commit();
472
+						return 1;
473
+					}
474
+					else
475 475
 					{
476
-			            $this->db->rollback();
477
-			            return -1;
478
-			        }
476
+						$this->db->rollback();
477
+						return -1;
478
+					}
479 479
 				}
480 480
 			}
481 481
 		}
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 	{
617 617
 		global $conf, $langs, $user;
618 618
 
619
-        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
619
+		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
620 620
 		$this->db->begin();
621 621
 
622 622
 		$error=0;
@@ -660,14 +660,14 @@  discard block
 block discarded – undo
660 660
 						}
661 661
 					}
662 662
 
663
-                    // Call trigger
664
-                    $result=$this->call_trigger('DELIVERY_DELETE',$user);
665
-                    if ($result < 0)
666
-                    {
667
-                        $this->db->rollback();
668
-                        return -4;
669
-                    }
670
-                    // End call triggers
663
+					// Call trigger
664
+					$result=$this->call_trigger('DELIVERY_DELETE',$user);
665
+					if ($result < 0)
666
+					{
667
+						$this->db->rollback();
668
+						return -4;
669
+					}
670
+					// End call triggers
671 671
 
672 672
 					return 1;
673 673
 				}
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 	 *	Return clicable name (with picto eventually)
698 698
 	 *
699 699
 	 *	@param	int		$withpicto					0=No picto, 1=Include picto into link, 2=Only picto
700
-     *  @param  int     $save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
700
+	 *  @param  int     $save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
701 701
 	 *	@return	string								Chaine avec URL
702 702
 	 */
703 703
 	function getNomUrl($withpicto=0, $save_lastsearch_value=-1)
@@ -711,16 +711,16 @@  discard block
 block discarded – undo
711 711
 
712 712
 		$url=DOL_URL_ROOT.'/livraison/card.php?id='.$this->id;
713 713
 
714
-        //if ($option !== 'nolink')
715
-        //{
716
-        	// Add param to save lastsearch_values or not
717
-        	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
718
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
719
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
720
-        //}
714
+		//if ($option !== 'nolink')
715
+		//{
716
+			// Add param to save lastsearch_values or not
717
+			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
718
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
719
+			if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
720
+		//}
721 721
 
722 722
 
723
-        $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
723
+		$linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
724 724
 		$linkend='</a>';
725 725
 
726 726
 		if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
@@ -837,11 +837,11 @@  discard block
 block discarded – undo
837 837
 
838 838
 
839 839
 	/**
840
-     *  Initialise an instance with random values.
841
-     *  Used to build previews or test instances.
842
-     *	id must be 0 if object instance is a specimen.
843
-     *
844
-     *  @return	void
840
+	 *  Initialise an instance with random values.
841
+	 *  Used to build previews or test instances.
842
+	 *	id must be 0 if object instance is a specimen.
843
+	 *
844
+	 *  @return	void
845 845
 	 */
846 846
 	function initAsSpecimen()
847 847
 	{
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
 
850 850
 		$now=dol_now();
851 851
 
852
-        // Load array of products prodids
852
+		// Load array of products prodids
853 853
 		$num_prods = 0;
854 854
 		$prodids = array();
855 855
 		$sql = "SELECT rowid";
Please login to merge, or discard this patch.
Spacing   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
33
-if (! empty($conf->propal->enabled))   require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
34
-if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
33
+if (!empty($conf->propal->enabled))   require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
34
+if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
35 35
 
36 36
 
37 37
 /**
@@ -39,16 +39,16 @@  discard block
 block discarded – undo
39 39
  */
40 40
 class Livraison extends CommonObject
41 41
 {
42
-	public $element="delivery";
43
-	public $fk_element="fk_livraison";
44
-	public $table_element="livraison";
45
-	public $table_element_line="livraisondet";
42
+	public $element = "delivery";
43
+	public $fk_element = "fk_livraison";
44
+	public $table_element = "livraison";
45
+	public $table_element_line = "livraisondet";
46 46
 
47 47
 	var $brouillon;
48 48
 	var $socid;
49 49
 	var $ref_customer;
50 50
 
51
-	var $date_delivery;    // Date really received
51
+	var $date_delivery; // Date really received
52 52
 	var $date_creation;
53 53
 	var $date_valid;
54 54
 	var $model_pdf;
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 
83 83
 		dol_syslog("Livraison::create");
84 84
 
85
-		if (empty($this->model_pdf)) $this->model_pdf=$conf->global->LIVRAISON_ADDON_PDF;
85
+		if (empty($this->model_pdf)) $this->model_pdf = $conf->global->LIVRAISON_ADDON_PDF;
86 86
 
87 87
 		$error = 0;
88 88
 
89
-        $now=dol_now();
89
+        $now = dol_now();
90 90
 
91 91
 		/* On positionne en mode brouillon le bon de livraison */
92 92
 		$this->brouillon = 1;
@@ -96,36 +96,36 @@  discard block
 block discarded – undo
96 96
 		$this->db->begin();
97 97
 
98 98
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."livraison (";
99
-		$sql.= "ref";
100
-		$sql.= ", entity";
101
-		$sql.= ", fk_soc";
102
-		$sql.= ", ref_customer";
103
-		$sql.= ", date_creation";
104
-		$sql.= ", fk_user_author";
105
-		$sql.= ", date_delivery";
106
-		$sql.= ", fk_address";
107
-		$sql.= ", note_private";
108
-		$sql.= ", note_public";
109
-		$sql.= ", model_pdf";
110
-		$sql.= ", fk_incoterms, location_incoterms";
111
-		$sql.= ") VALUES (";
112
-		$sql.= "'(PROV)'";
113
-		$sql.= ", ".$conf->entity;
114
-		$sql.= ", ".$this->socid;
115
-		$sql.= ", '".$this->db->escape($this->ref_customer)."'";
116
-		$sql.= ", '".$this->db->idate($now)."'";
117
-		$sql.= ", ".$user->id;
118
-		$sql.= ", ".($this->date_delivery?"'".$this->db->idate($this->date_delivery)."'":"null");
119
-		$sql.= ", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address : "null");
120
-		$sql.= ", ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
121
-		$sql.= ", ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
122
-		$sql.= ", ".(!empty($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null");
123
-        $sql.= ", ".(int) $this->fk_incoterms;
124
-        $sql.= ", '".$this->db->escape($this->location_incoterms)."'";
125
-		$sql.= ")";
99
+		$sql .= "ref";
100
+		$sql .= ", entity";
101
+		$sql .= ", fk_soc";
102
+		$sql .= ", ref_customer";
103
+		$sql .= ", date_creation";
104
+		$sql .= ", fk_user_author";
105
+		$sql .= ", date_delivery";
106
+		$sql .= ", fk_address";
107
+		$sql .= ", note_private";
108
+		$sql .= ", note_public";
109
+		$sql .= ", model_pdf";
110
+		$sql .= ", fk_incoterms, location_incoterms";
111
+		$sql .= ") VALUES (";
112
+		$sql .= "'(PROV)'";
113
+		$sql .= ", ".$conf->entity;
114
+		$sql .= ", ".$this->socid;
115
+		$sql .= ", '".$this->db->escape($this->ref_customer)."'";
116
+		$sql .= ", '".$this->db->idate($now)."'";
117
+		$sql .= ", ".$user->id;
118
+		$sql .= ", ".($this->date_delivery ? "'".$this->db->idate($this->date_delivery)."'" : "null");
119
+		$sql .= ", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address : "null");
120
+		$sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
121
+		$sql .= ", ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
122
+		$sql .= ", ".(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null");
123
+        $sql .= ", ".(int) $this->fk_incoterms;
124
+        $sql .= ", '".$this->db->escape($this->location_incoterms)."'";
125
+		$sql .= ")";
126 126
 
127 127
 		dol_syslog("Livraison::create", LOG_DEBUG);
128
-		$resql=$this->db->query($sql);
128
+		$resql = $this->db->query($sql);
129 129
 		if ($resql)
130 130
 		{
131 131
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."livraison");
@@ -133,14 +133,14 @@  discard block
 block discarded – undo
133 133
 			$numref = "(PROV".$this->id.")";
134 134
 
135 135
 			$sql = "UPDATE ".MAIN_DB_PREFIX."livraison ";
136
-			$sql.= "SET ref = '".$this->db->escape($numref)."'";
137
-			$sql.= " WHERE rowid = ".$this->id;
136
+			$sql .= "SET ref = '".$this->db->escape($numref)."'";
137
+			$sql .= " WHERE rowid = ".$this->id;
138 138
 
139 139
 			dol_syslog("Livraison::create", LOG_DEBUG);
140
-			$resql=$this->db->query($sql);
140
+			$resql = $this->db->query($sql);
141 141
 			if ($resql)
142 142
 			{
143
-				if (! $conf->expedition_bon->enabled)
143
+				if (!$conf->expedition_bon->enabled)
144 144
 				{
145 145
 					$commande = new Commande($this->db);
146 146
 					$commande->id = $this->commande_id;
@@ -151,19 +151,19 @@  discard block
 block discarded – undo
151 151
 				/*
152 152
 				 *  Insertion des produits dans la base
153 153
 				 */
154
-				$num=count($this->lines);
154
+				$num = count($this->lines);
155 155
 				for ($i = 0; $i < $num; $i++)
156 156
 				{
157
-					$origin_id=$this->lines[$i]->origin_line_id;
158
-					if (! $origin_id) $origin_id=$this->lines[$i]->commande_ligne_id;	// For backward compatibility
157
+					$origin_id = $this->lines[$i]->origin_line_id;
158
+					if (!$origin_id) $origin_id = $this->lines[$i]->commande_ligne_id; // For backward compatibility
159 159
 
160
-					if (! $this->create_line($origin_id, $this->lines[$i]->qty, $this->lines[$i]->fk_product, $this->lines[$i]->description))
160
+					if (!$this->create_line($origin_id, $this->lines[$i]->qty, $this->lines[$i]->fk_product, $this->lines[$i]->description))
161 161
 					{
162 162
 						$error++;
163 163
 					}
164 164
 				}
165 165
 
166
-				if (! $error && $this->id && $this->origin_id)
166
+				if (!$error && $this->id && $this->origin_id)
167 167
 				{
168 168
 					$ret = $this->add_object_linked();
169 169
 					if (!$ret)
@@ -171,18 +171,18 @@  discard block
 block discarded – undo
171 171
 						$error++;
172 172
 					}
173 173
 
174
-					if (! $conf->expedition_bon->enabled)
174
+					if (!$conf->expedition_bon->enabled)
175 175
 					{
176 176
 						// TODO uniformiser les statuts
177
-						$ret = $this->setStatut(2,$this->origin_id,$this->origin);
178
-						if (! $ret)
177
+						$ret = $this->setStatut(2, $this->origin_id, $this->origin);
178
+						if (!$ret)
179 179
 						{
180 180
 							$error++;
181 181
 						}
182 182
 					}
183 183
 				}
184 184
 
185
-				if (! $error)
185
+				if (!$error)
186 186
 				{
187 187
 					$this->db->commit();
188 188
 					return $this->id;
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 				else
191 191
 				{
192 192
 					$error++;
193
-					$this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror;
193
+					$this->error = $this->db->lasterror()." - sql=".$this->db->lastqueryerror;
194 194
 					$this->db->rollback();
195 195
 					return -3;
196 196
 				}
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 			else
199 199
 			{
200 200
 				$error++;
201
-				$this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror;
201
+				$this->error = $this->db->lasterror()." - sql=".$this->db->lastqueryerror;
202 202
 				$this->db->rollback();
203 203
 				return -2;
204 204
 			}
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 		else
207 207
 		{
208 208
 			$error++;
209
-			$this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror;
209
+			$this->error = $this->db->lasterror()." - sql=".$this->db->lastqueryerror;
210 210
 			$this->db->rollback();
211 211
 			return -1;
212 212
 		}
@@ -228,19 +228,19 @@  discard block
 block discarded – undo
228 228
 		$j = 0;
229 229
 
230 230
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."livraisondet (fk_livraison, fk_origin_line,";
231
-		$sql.= " fk_product, description, qty)";
232
-		$sql.= " VALUES (".$this->id.",".$origin_id.",";
233
-		$sql.= " ".($idprod>0?$idprod:"null").",";
234
-		$sql.= " ".($description?"'".$this->db->escape($description)."'":"null").",";
235
-		$sql.= $qty.")";
231
+		$sql .= " fk_product, description, qty)";
232
+		$sql .= " VALUES (".$this->id.",".$origin_id.",";
233
+		$sql .= " ".($idprod > 0 ? $idprod : "null").",";
234
+		$sql .= " ".($description ? "'".$this->db->escape($description)."'" : "null").",";
235
+		$sql .= $qty.")";
236 236
 
237 237
 		dol_syslog(get_class($this)."::create_line", LOG_DEBUG);
238
-		if (! $this->db->query($sql) )
238
+		if (!$this->db->query($sql))
239 239
 		{
240 240
 			$error++;
241 241
 		}
242 242
 
243
-		if ($error == 0 )
243
+		if ($error == 0)
244 244
 		{
245 245
 			return 1;
246 246
 		}
@@ -257,15 +257,15 @@  discard block
 block discarded – undo
257 257
 		global $conf;
258 258
 
259 259
 		$sql = "SELECT l.rowid, l.fk_soc, l.date_creation, l.date_valid, l.ref, l.ref_customer, l.fk_user_author,";
260
-		$sql.=" l.total_ht, l.fk_statut, l.fk_user_valid, l.note_private, l.note_public";
261
-		$sql.= ", l.date_delivery, l.fk_address, l.model_pdf";
262
-		$sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
263
-        $sql.= ', l.fk_incoterms, l.location_incoterms';
264
-        $sql.= ", i.libelle as libelle_incoterms";
265
-		$sql.= " FROM ".MAIN_DB_PREFIX."livraison as l";
266
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = l.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
267
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON l.fk_incoterms = i.rowid';
268
-		$sql.= " WHERE l.rowid = ".$id;
260
+		$sql .= " l.total_ht, l.fk_statut, l.fk_user_valid, l.note_private, l.note_public";
261
+		$sql .= ", l.date_delivery, l.fk_address, l.model_pdf";
262
+		$sql .= ", el.fk_source as origin_id, el.sourcetype as origin";
263
+        $sql .= ', l.fk_incoterms, l.location_incoterms';
264
+        $sql .= ", i.libelle as libelle_incoterms";
265
+		$sql .= " FROM ".MAIN_DB_PREFIX."livraison as l";
266
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = l.rowid AND el.targettype = '".$this->db->escape($this->element)."'";
267
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON l.fk_incoterms = i.rowid';
268
+		$sql .= " WHERE l.rowid = ".$id;
269 269
 
270 270
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
271 271
 		$result = $this->db->query($sql);
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
 				$this->note_private         = $obj->note_private;
291 291
 				$this->note_public          = $obj->note_public;
292 292
 				$this->modelpdf             = $obj->model_pdf;
293
-				$this->origin               = $obj->origin;		// May be 'shipping'
294
-				$this->origin_id            = $obj->origin_id;	// May be id of shipping
293
+				$this->origin               = $obj->origin; // May be 'shipping'
294
+				$this->origin_id            = $obj->origin_id; // May be id of shipping
295 295
 
296 296
 				//Incoterms
297 297
 				$this->fk_incoterms = $obj->fk_incoterms;
@@ -305,14 +305,14 @@  discard block
 block discarded – undo
305 305
 				// Retrieve all extrafields for delivery
306 306
 				// fetch optionals attributes and labels
307 307
 				require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
308
-				$extrafields=new ExtraFields($this->db);
309
-				$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
310
-				$this->fetch_optionals($this->id,$extralabels);
308
+				$extrafields = new ExtraFields($this->db);
309
+				$extralabels = $extrafields->fetch_name_optionals_label($this->table_element, true);
310
+				$this->fetch_optionals($this->id, $extralabels);
311 311
 
312 312
 				/*
313 313
 				 * Lignes
314 314
 				 */
315
-				$result=$this->fetch_lines();
315
+				$result = $this->fetch_lines();
316 316
 				if ($result < 0)
317 317
 				{
318 318
 					return -3;
@@ -322,14 +322,14 @@  discard block
 block discarded – undo
322 322
 			}
323 323
 			else
324 324
 			{
325
-				$this->error='Delivery with id '.$id.' not found sql='.$sql;
325
+				$this->error = 'Delivery with id '.$id.' not found sql='.$sql;
326 326
 				dol_syslog(get_class($this).'::fetch Error '.$this->error, LOG_ERR);
327 327
 				return -2;
328 328
 			}
329 329
 		}
330 330
 		else
331 331
 		{
332
-			$this->error=$this->db->error();
332
+			$this->error = $this->db->error();
333 333
 			return -1;
334 334
 		}
335 335
 	}
@@ -351,19 +351,19 @@  discard block
 block discarded – undo
351 351
 
352 352
 		$error = 0;
353 353
 
354
-        if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison->creer))
355
-       	|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->livraison_advance->validate)))
354
+        if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->livraison->creer))
355
+       	|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->livraison_advance->validate)))
356 356
 		{
357
-			if (! empty($conf->global->LIVRAISON_ADDON_NUMBER))
357
+			if (!empty($conf->global->LIVRAISON_ADDON_NUMBER))
358 358
 			{
359 359
 				// Definition du nom de module de numerotation de commande
360 360
 				$modName = $conf->global->LIVRAISON_ADDON_NUMBER;
361 361
 
362
-				if (is_readable(DOL_DOCUMENT_ROOT .'/core/modules/livraison/'.$modName.'.php'))
362
+				if (is_readable(DOL_DOCUMENT_ROOT.'/core/modules/livraison/'.$modName.'.php'))
363 363
 				{
364
-					require_once DOL_DOCUMENT_ROOT .'/core/modules/livraison/'.$modName.'.php';
364
+					require_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/'.$modName.'.php';
365 365
 
366
-					$now=dol_now();
366
+					$now = dol_now();
367 367
 
368 368
 					// Recuperation de la nouvelle reference
369 369
 					$objMod = new $modName($this->db);
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 
373 373
 					if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life
374 374
 		            {
375
-		                $numref = $objMod->livraison_get_num($soc,$this);
375
+		                $numref = $objMod->livraison_get_num($soc, $this);
376 376
 		            }
377 377
 		            else
378 378
 					{
@@ -383,12 +383,12 @@  discard block
 block discarded – undo
383 383
 					// Tester si non deja au statut valide. Si oui, on arrete afin d'eviter
384 384
 					// de decrementer 2 fois le stock.
385 385
 					$sql = "SELECT ref";
386
-					$sql.= " FROM ".MAIN_DB_PREFIX."livraison";
387
-					$sql.= " WHERE ref = '".$this->db->escape($numref)."'";
388
-					$sql.= " AND fk_statut <> 0";
389
-					$sql.= " AND entity = ".$conf->entity;
386
+					$sql .= " FROM ".MAIN_DB_PREFIX."livraison";
387
+					$sql .= " WHERE ref = '".$this->db->escape($numref)."'";
388
+					$sql .= " AND fk_statut <> 0";
389
+					$sql .= " AND entity = ".$conf->entity;
390 390
 
391
-					$resql=$this->db->query($sql);
391
+					$resql = $this->db->query($sql);
392 392
 					if ($resql)
393 393
 					{
394 394
 						$num = $this->db->num_rows($resql);
@@ -399,30 +399,30 @@  discard block
 block discarded – undo
399 399
 					}
400 400
 
401 401
 					$sql = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
402
-					$sql.= " ref='".$this->db->escape($numref)."'";
403
-					$sql.= ", fk_statut = 1";
404
-					$sql.= ", date_valid = '".$this->db->idate($now)."'";
405
-					$sql.= ", fk_user_valid = ".$user->id;
406
-					$sql.= " WHERE rowid = ".$this->id;
407
-					$sql.= " AND fk_statut = 0";
408
-
409
-					$resql=$this->db->query($sql);
410
-			        if (! $resql)
402
+					$sql .= " ref='".$this->db->escape($numref)."'";
403
+					$sql .= ", fk_statut = 1";
404
+					$sql .= ", date_valid = '".$this->db->idate($now)."'";
405
+					$sql .= ", fk_user_valid = ".$user->id;
406
+					$sql .= " WHERE rowid = ".$this->id;
407
+					$sql .= " AND fk_statut = 0";
408
+
409
+					$resql = $this->db->query($sql);
410
+			        if (!$resql)
411 411
 			        {
412 412
 			            dol_print_error($this->db);
413
-			            $this->error=$this->db->lasterror();
413
+			            $this->error = $this->db->lasterror();
414 414
 			            $error++;
415 415
 			        }
416 416
 
417
-			        if (! $error && ! $notrigger)
417
+			        if (!$error && !$notrigger)
418 418
 			        {
419 419
 			            // Call trigger
420
-			            $result=$this->call_trigger('DELIVERY_VALIDATE',$user);
420
+			            $result = $this->call_trigger('DELIVERY_VALIDATE', $user);
421 421
 			            if ($result < 0) $error++;
422 422
 			            // End call triggers
423 423
 			        }
424 424
 
425
-					if (! $error)
425
+					if (!$error)
426 426
 					{
427 427
 			            $this->oldref = $this->ref;
428 428
 
@@ -443,13 +443,13 @@  discard block
 block discarded – undo
443 443
 								{
444 444
 			                        dol_syslog("Rename ok");
445 445
 			                        // Rename docs starting with $oldref with $newref
446
-			                        $listoffiles=dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
447
-			                        foreach($listoffiles as $fileentry)
446
+			                        $listoffiles = dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
447
+			                        foreach ($listoffiles as $fileentry)
448 448
 			                        {
449
-			                        	$dirsource=$fileentry['name'];
450
-			                        	$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
451
-			                        	$dirsource=$fileentry['path'].'/'.$dirsource;
452
-			                        	$dirdest=$fileentry['path'].'/'.$dirdest;
449
+			                        	$dirsource = $fileentry['name'];
450
+			                        	$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
451
+			                        	$dirsource = $fileentry['path'].'/'.$dirsource;
452
+			                        	$dirdest = $fileentry['path'].'/'.$dirdest;
453 453
 			                        	@rename($dirsource, $dirdest);
454 454
 			                        }
455 455
 								}
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 						}
458 458
 
459 459
 						// Set new ref and current status
460
-						if (! $error)
460
+						if (!$error)
461 461
 						{
462 462
 							$this->ref = $numref;
463 463
 							$this->statut = 1;
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
 						dol_syslog(get_class($this)."::valid ok");
467 467
 					}
468 468
 
469
-			        if (! $error)
469
+			        if (!$error)
470 470
 			        {
471 471
 			            $this->db->commit();
472 472
 			            return 1;
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 		}
482 482
 		else
483 483
 		{
484
-			$this->error="Non autorise";
484
+			$this->error = "Non autorise";
485 485
 			dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
486 486
 			return -1;
487 487
 		}
@@ -497,11 +497,11 @@  discard block
 block discarded – undo
497 497
 	function create_from_sending($user, $sending_id)
498 498
 	{
499 499
 		$expedition = new Expedition($this->db);
500
-		$result=$expedition->fetch($sending_id);
500
+		$result = $expedition->fetch($sending_id);
501 501
 
502 502
 		$this->lines = array();
503 503
 
504
-		$num=count($expedition->lines);
504
+		$num = count($expedition->lines);
505 505
 		for ($i = 0; $i < $num; $i++)
506 506
 		{
507 507
 			$line = new LivraisonLigne($this->db);
@@ -523,10 +523,10 @@  discard block
 block discarded – undo
523 523
 		$this->date_delivery        = $expedition->date_delivery;
524 524
 		$this->fk_delivery_address  = $expedition->fk_delivery_address;
525 525
 		$this->socid                = $expedition->socid;
526
-		$this->ref_customer			= $expedition->ref_customer;
526
+		$this->ref_customer = $expedition->ref_customer;
527 527
 
528 528
 		//Incoterms
529
-		$this->fk_incoterms		= $expedition->fk_incoterms;
529
+		$this->fk_incoterms = $expedition->fk_incoterms;
530 530
 		$this->location_incoterms = $expedition->location_incoterms;
531 531
 
532 532
 		return $this->create($user);
@@ -539,26 +539,26 @@  discard block
 block discarded – undo
539 539
 	 * @param	array		$array_options		extrafields array
540 540
 	 * @return	int							<0 if KO, >0 if OK
541 541
 	 */
542
-	function update_line($id, $array_options=0)
542
+	function update_line($id, $array_options = 0)
543 543
 	{
544 544
 		global $conf;
545 545
 		$error = 0;
546 546
 
547
-		if ($id > 0 && !$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
547
+		if ($id > 0 && !$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used
548 548
 		{
549 549
 			$livraisonline = new LivraisonLigne($this->db);
550
-			$livraisonline->array_options=$array_options;
551
-			$livraisonline->id=$id;
552
-			$result=$livraisonline->insertExtraFields();
550
+			$livraisonline->array_options = $array_options;
551
+			$livraisonline->id = $id;
552
+			$result = $livraisonline->insertExtraFields();
553 553
 
554 554
 			if ($result < 0)
555 555
 			{
556
-				$this->error[]=$livraisonline->error;
556
+				$this->error[] = $livraisonline->error;
557 557
 				$error++;
558 558
 			}
559 559
 		}
560 560
 
561
-		if (! $error) return 1;
561
+		if (!$error) return 1;
562 562
 		else return -1;
563 563
 	}
564 564
 
@@ -592,9 +592,9 @@  discard block
 block discarded – undo
592 592
 		if ($this->statut == 0)
593 593
 		{
594 594
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet";
595
-			$sql.= " WHERE rowid = ".$lineid;
595
+			$sql .= " WHERE rowid = ".$lineid;
596 596
 
597
-			if ($this->db->query($sql) )
597
+			if ($this->db->query($sql))
598 598
 			{
599 599
 				$this->update_price();
600 600
 
@@ -619,30 +619,30 @@  discard block
 block discarded – undo
619 619
         require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
620 620
 		$this->db->begin();
621 621
 
622
-		$error=0;
622
+		$error = 0;
623 623
 
624 624
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."livraisondet";
625
-		$sql.= " WHERE fk_livraison = ".$this->id;
625
+		$sql .= " WHERE fk_livraison = ".$this->id;
626 626
 		if ($this->db->query($sql))
627 627
 		{
628 628
 			// Delete linked object
629 629
 			$res = $this->deleteObjectLinked();
630 630
 			if ($res < 0) $error++;
631 631
 
632
-			if (! $error)
632
+			if (!$error)
633 633
 			{
634 634
 				$sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison";
635
-				$sql.= " WHERE rowid = ".$this->id;
635
+				$sql .= " WHERE rowid = ".$this->id;
636 636
 				if ($this->db->query($sql))
637 637
 				{
638 638
 					$this->db->commit();
639 639
 
640 640
 					// On efface le repertoire de pdf provisoire
641 641
 					$ref = dol_sanitizeFileName($this->ref);
642
-					if (! empty($conf->expedition->dir_output))
642
+					if (!empty($conf->expedition->dir_output))
643 643
 					{
644
-						$dir = $conf->expedition->dir_output . '/receipt/' . $ref ;
645
-						$file = $dir . '/' . $ref . '.pdf';
644
+						$dir = $conf->expedition->dir_output.'/receipt/'.$ref;
645
+						$file = $dir.'/'.$ref.'.pdf';
646 646
 						if (file_exists($file))
647 647
 						{
648 648
 							if (!dol_delete_file($file))
@@ -654,14 +654,14 @@  discard block
 block discarded – undo
654 654
 						{
655 655
 							if (!dol_delete_dir($dir))
656 656
 							{
657
-								$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
657
+								$this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
658 658
 								return 0;
659 659
 							}
660 660
 						}
661 661
 					}
662 662
 
663 663
                     // Call trigger
664
-                    $result=$this->call_trigger('DELIVERY_DELETE',$user);
664
+                    $result = $this->call_trigger('DELIVERY_DELETE', $user);
665 665
                     if ($result < 0)
666 666
                     {
667 667
                         $this->db->rollback();
@@ -673,21 +673,21 @@  discard block
 block discarded – undo
673 673
 				}
674 674
 				else
675 675
 				{
676
-					$this->error=$this->db->lasterror()." - sql=$sql";
676
+					$this->error = $this->db->lasterror()." - sql=$sql";
677 677
 					$this->db->rollback();
678 678
 					return -3;
679 679
 				}
680 680
 			}
681 681
 			else
682 682
 			{
683
-				$this->error=$this->db->lasterror()." - sql=$sql";
683
+				$this->error = $this->db->lasterror()." - sql=$sql";
684 684
 				$this->db->rollback();
685 685
 				return -2;
686 686
 			}
687 687
 		}
688 688
 		else
689 689
 		{
690
-			$this->error=$this->db->lasterror()." - sql=$sql";
690
+			$this->error = $this->db->lasterror()." - sql=$sql";
691 691
 			$this->db->rollback();
692 692
 			return -1;
693 693
 		}
@@ -700,32 +700,32 @@  discard block
 block discarded – undo
700 700
      *  @param  int     $save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
701 701
 	 *	@return	string								Chaine avec URL
702 702
 	 */
703
-	function getNomUrl($withpicto=0, $save_lastsearch_value=-1)
703
+	function getNomUrl($withpicto = 0, $save_lastsearch_value = -1)
704 704
 	{
705 705
 		global $langs;
706 706
 
707
-		$result='';
708
-		$picto='sending';
707
+		$result = '';
708
+		$picto = 'sending';
709 709
 
710
-		$label=$langs->trans("ShowReceiving").': '.$this->ref;
710
+		$label = $langs->trans("ShowReceiving").': '.$this->ref;
711 711
 
712
-		$url=DOL_URL_ROOT.'/livraison/card.php?id='.$this->id;
712
+		$url = DOL_URL_ROOT.'/livraison/card.php?id='.$this->id;
713 713
 
714 714
         //if ($option !== 'nolink')
715 715
         //{
716 716
         	// Add param to save lastsearch_values or not
717
-        	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
718
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
719
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
717
+        	$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
718
+        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
719
+        	if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
720 720
         //}
721 721
 
722 722
 
723 723
         $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
724
-		$linkend='</a>';
724
+		$linkend = '</a>';
725 725
 
726
-		if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
727
-		if ($withpicto && $withpicto != 2) $result.=' ';
728
-		$result.=$linkstart.$this->ref.$linkend;
726
+		if ($withpicto) $result .= ($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
727
+		if ($withpicto && $withpicto != 2) $result .= ' ';
728
+		$result .= $linkstart.$this->ref.$linkend;
729 729
 		return $result;
730 730
 	}
731 731
 
@@ -739,12 +739,12 @@  discard block
 block discarded – undo
739 739
 		$this->lines = array();
740 740
 
741 741
 		$sql = "SELECT ld.rowid, ld.fk_product, ld.description, ld.subprice, ld.total_ht, ld.qty as qty_shipped, ld.fk_origin_line, ";
742
-		$sql.= " cd.qty as qty_asked, cd.label as custom_label,";
743
-		$sql.= " p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc";
744
-		$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld";
745
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on p.rowid = ld.fk_product";
746
-		$sql.= " WHERE ld.fk_origin_line = cd.rowid";
747
-		$sql.= " AND ld.fk_livraison = ".$this->id;
742
+		$sql .= " cd.qty as qty_asked, cd.label as custom_label,";
743
+		$sql .= " p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc";
744
+		$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld";
745
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on p.rowid = ld.fk_product";
746
+		$sql .= " WHERE ld.fk_origin_line = cd.rowid";
747
+		$sql .= " AND ld.fk_livraison = ".$this->id;
748 748
 
749 749
 		dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
750 750
 		$resql = $this->db->query($sql);
@@ -758,23 +758,23 @@  discard block
 block discarded – undo
758 758
 
759 759
 				$obj = $this->db->fetch_object($resql);
760 760
 
761
-				$line->id					= $obj->rowid;
762
-				$line->label			= $obj->custom_label;
761
+				$line->id = $obj->rowid;
762
+				$line->label = $obj->custom_label;
763 763
 				$line->description		= $obj->description;
764
-				$line->fk_product		= $obj->fk_product;
765
-				$line->qty_asked		= $obj->qty_asked;
764
+				$line->fk_product = $obj->fk_product;
765
+				$line->qty_asked = $obj->qty_asked;
766 766
 				$line->qty_shipped		= $obj->qty_shipped;
767 767
 
768
-				$line->ref				= $obj->product_ref;		// deprecated
769
-				$line->libelle			= $obj->product_label;		// deprecated
770
-				$line->product_label	= $obj->product_label;		// Product label
771
-				$line->product_ref		= $obj->product_ref;		// Product ref
772
-				$line->product_desc		= $obj->product_desc;		// Product description
768
+				$line->ref = $obj->product_ref; // deprecated
769
+				$line->libelle = $obj->product_label; // deprecated
770
+				$line->product_label	= $obj->product_label; // Product label
771
+				$line->product_ref = $obj->product_ref; // Product ref
772
+				$line->product_desc		= $obj->product_desc; // Product description
773 773
 				$line->product_type		= $obj->fk_product_type;
774
-				$line->fk_origin_line 	= $obj->fk_origin_line;
774
+				$line->fk_origin_line = $obj->fk_origin_line;
775 775
 
776
-				$line->price			= $obj->price;
777
-				$line->total_ht			= $obj->total_ht;
776
+				$line->price = $obj->price;
777
+				$line->total_ht = $obj->total_ht;
778 778
 
779 779
 				$this->lines[$i] = $line;
780 780
 
@@ -793,9 +793,9 @@  discard block
 block discarded – undo
793 793
 	 *  @param	int			$mode		Mode
794 794
 	 *  @return string      			Label
795 795
 	 */
796
-	function getLibStatut($mode=0)
796
+	function getLibStatut($mode = 0)
797 797
 	{
798
-		return $this->LibStatut($this->statut,$mode);
798
+		return $this->LibStatut($this->statut, $mode);
799 799
 	}
800 800
 
801 801
 	/**
@@ -805,33 +805,33 @@  discard block
 block discarded – undo
805 805
 	 *  @param  int			$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
806 806
 	 *  @return string					Label
807 807
 	 */
808
-	function LibStatut($statut,$mode)
808
+	function LibStatut($statut, $mode)
809 809
 	{
810 810
 		global $langs;
811 811
 
812
-		if ($mode==0)
812
+		if ($mode == 0)
813 813
 		{
814
-			if ($statut==-1) return $langs->trans('StatusDeliveryCanceled');
815
-			if ($statut==0)  return $langs->trans('StatusDeliveryDraft');
816
-			if ($statut==1)  return $langs->trans('StatusDeliveryValidated');
814
+			if ($statut == -1) return $langs->trans('StatusDeliveryCanceled');
815
+			if ($statut == 0)  return $langs->trans('StatusDeliveryDraft');
816
+			if ($statut == 1)  return $langs->trans('StatusDeliveryValidated');
817 817
 		}
818
-		if ($mode==1)
818
+		if ($mode == 1)
819 819
 		{
820
-			if ($statut==-1) return $langs->trans($this->statuts[$statut]);
821
-			if ($statut==0)  return $langs->trans($this->statuts[$statut]);
822
-			if ($statut==1)  return $langs->trans($this->statuts[$statut]);
820
+			if ($statut == -1) return $langs->trans($this->statuts[$statut]);
821
+			if ($statut == 0)  return $langs->trans($this->statuts[$statut]);
822
+			if ($statut == 1)  return $langs->trans($this->statuts[$statut]);
823 823
 		}
824 824
 		if ($mode == 4)
825 825
 		{
826
-			if ($statut==-1) return img_picto($langs->trans('StatusDeliveryCanceled'),'statut5').' '.$langs->trans('StatusDeliveryCanceled');
827
-			if ($statut==0)  return img_picto($langs->trans('StatusDeliveryDraft'),'statut0').' '.$langs->trans('StatusDeliveryDraft');
828
-			if ($statut==1)  return img_picto($langs->trans('StatusDeliveryValidated'),'statut4').' '.$langs->trans('StatusDeliveryValidated');
826
+			if ($statut == -1) return img_picto($langs->trans('StatusDeliveryCanceled'), 'statut5').' '.$langs->trans('StatusDeliveryCanceled');
827
+			if ($statut == 0)  return img_picto($langs->trans('StatusDeliveryDraft'), 'statut0').' '.$langs->trans('StatusDeliveryDraft');
828
+			if ($statut == 1)  return img_picto($langs->trans('StatusDeliveryValidated'), 'statut4').' '.$langs->trans('StatusDeliveryValidated');
829 829
 		}
830 830
 		if ($mode == 6)
831 831
 		{
832
-			if ($statut==-1) return $langs->trans('StatusDeliveryCanceled').' '.img_picto($langs->trans('StatusDeliveryCanceled'),'statut5');
833
-			if ($statut==0)  return $langs->trans('StatusDeliveryDraft').' '.img_picto($langs->trans('StatusDeliveryDraft'),'statut0');
834
-			if ($statut==1)  return $langs->trans('StatusDeliveryValidated').' '.img_picto($langs->trans('StatusDeliveryValidated'),'statut4');
832
+			if ($statut == -1) return $langs->trans('StatusDeliveryCanceled').' '.img_picto($langs->trans('StatusDeliveryCanceled'), 'statut5');
833
+			if ($statut == 0)  return $langs->trans('StatusDeliveryDraft').' '.img_picto($langs->trans('StatusDeliveryDraft'), 'statut0');
834
+			if ($statut == 1)  return $langs->trans('StatusDeliveryValidated').' '.img_picto($langs->trans('StatusDeliveryValidated'), 'statut4');
835 835
 		}
836 836
 	}
837 837
 
@@ -845,17 +845,17 @@  discard block
 block discarded – undo
845 845
 	 */
846 846
 	function initAsSpecimen()
847 847
 	{
848
-		global $user,$langs,$conf;
848
+		global $user, $langs, $conf;
849 849
 
850
-		$now=dol_now();
850
+		$now = dol_now();
851 851
 
852 852
         // Load array of products prodids
853 853
 		$num_prods = 0;
854 854
 		$prodids = array();
855 855
 		$sql = "SELECT rowid";
856
-		$sql.= " FROM ".MAIN_DB_PREFIX."product";
857
-		$sql.= " WHERE entity IN (".getEntity('product').")";
858
-		$sql.= " AND tosell = 1";
856
+		$sql .= " FROM ".MAIN_DB_PREFIX."product";
857
+		$sql .= " WHERE entity IN (".getEntity('product').")";
858
+		$sql .= " AND tosell = 1";
859 859
 		$resql = $this->db->query($sql);
860 860
 		if ($resql)
861 861
 		{
@@ -870,16 +870,16 @@  discard block
 block discarded – undo
870 870
 		}
871 871
 
872 872
 		// Initialise parametres
873
-		$this->id=0;
873
+		$this->id = 0;
874 874
 		$this->ref = 'SPECIMEN';
875
-		$this->specimen=1;
875
+		$this->specimen = 1;
876 876
 		$this->socid = 1;
877 877
 		$this->date_delivery = $now;
878
-		$this->note_public='Public note';
879
-		$this->note_private='Private note';
878
+		$this->note_public = 'Public note';
879
+		$this->note_private = 'Private note';
880 880
 
881
-		$i=0;
882
-		$line=new LivraisonLigne($this->db);
881
+		$i = 0;
882
+		$line = new LivraisonLigne($this->db);
883 883
 		$line->fk_product     = $prodids[0];
884 884
 		$line->qty_asked      = 10;
885 885
 		$line->qty_shipped    = 9;
@@ -903,14 +903,14 @@  discard block
 block discarded – undo
903 903
 		global $langs;
904 904
 
905 905
 		// Get the linked object
906
-		$this->fetchObjectLinked('','',$this->id,$this->element);
906
+		$this->fetchObjectLinked('', '', $this->id, $this->element);
907 907
 		//var_dump($this->linkedObjectIds);
908 908
 		// Get the product ref and qty in source
909 909
 		$sqlSourceLine = "SELECT st.rowid, st.description, st.qty";
910
-		$sqlSourceLine.= ", p.ref, p.label";
911
-		$sqlSourceLine.= " FROM ".MAIN_DB_PREFIX.$this->linkedObjectIds[0]['type']."det as st";
912
-		$sqlSourceLine.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON st.fk_product = p.rowid";
913
-		$sqlSourceLine.= " WHERE fk_".$this->linked_object[0]['type']." = ".$this->linked_object[0]['linkid'];
910
+		$sqlSourceLine .= ", p.ref, p.label";
911
+		$sqlSourceLine .= " FROM ".MAIN_DB_PREFIX.$this->linkedObjectIds[0]['type']."det as st";
912
+		$sqlSourceLine .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON st.fk_product = p.rowid";
913
+		$sqlSourceLine .= " WHERE fk_".$this->linked_object[0]['type']." = ".$this->linked_object[0]['linkid'];
914 914
 
915 915
 		$resultSourceLine = $this->db->query($sqlSourceLine);
916 916
 		if ($resultSourceLine)
@@ -924,15 +924,15 @@  discard block
 block discarded – undo
924 924
 
925 925
 				// Recupere les lignes de la source deja livrees
926 926
 				$sql = "SELECT ld.fk_origin_line, sum(ld.qty) as qty";
927
-				$sql.= " FROM ".MAIN_DB_PREFIX."livraisondet as ld, ".MAIN_DB_PREFIX."livraison as l,";
928
-				$sql.= " ".MAIN_DB_PREFIX.$this->linked_object[0]['type']." as c";
929
-				$sql.= ", ".MAIN_DB_PREFIX.$this->linked_object[0]['type']."det as cd";
930
-				$sql.= " WHERE ld.fk_livraison = l.rowid";
931
-				$sql.= " AND ld.fk_origin_line = cd.rowid";
932
-				$sql.= " AND cd.fk_".$this->linked_object[0]['type']." = c.rowid";
933
-				$sql.= " AND cd.fk_".$this->linked_object[0]['type']." = ".$this->linked_object[0]['linkid'];
934
-				$sql.= " AND ld.fk_origin_line = ".$objSourceLine->rowid;
935
-				$sql.= " GROUP BY ld.fk_origin_line";
927
+				$sql .= " FROM ".MAIN_DB_PREFIX."livraisondet as ld, ".MAIN_DB_PREFIX."livraison as l,";
928
+				$sql .= " ".MAIN_DB_PREFIX.$this->linked_object[0]['type']." as c";
929
+				$sql .= ", ".MAIN_DB_PREFIX.$this->linked_object[0]['type']."det as cd";
930
+				$sql .= " WHERE ld.fk_livraison = l.rowid";
931
+				$sql .= " AND ld.fk_origin_line = cd.rowid";
932
+				$sql .= " AND cd.fk_".$this->linked_object[0]['type']." = c.rowid";
933
+				$sql .= " AND cd.fk_".$this->linked_object[0]['type']." = ".$this->linked_object[0]['linkid'];
934
+				$sql .= " AND ld.fk_origin_line = ".$objSourceLine->rowid;
935
+				$sql .= " GROUP BY ld.fk_origin_line";
936 936
 
937 937
 				$result = $this->db->query($sql);
938 938
 				$row = $this->db->fetch_row($result);
@@ -949,13 +949,13 @@  discard block
 block discarded – undo
949 949
 					}
950 950
 
951 951
 					$array[$i]['ref'] = $objSourceLine->ref;
952
-					$array[$i]['label'] = $objSourceLine->label?$objSourceLine->label:$objSourceLine->description;
952
+					$array[$i]['label'] = $objSourceLine->label ? $objSourceLine->label : $objSourceLine->description;
953 953
 				}
954
-				elseif($objSourceLine->qty - $row[1] < 0)
954
+				elseif ($objSourceLine->qty - $row[1] < 0)
955 955
 				{
956
-					$array[$i]['qty'] = $objSourceLine->qty - $row[1]. " Erreur livraison !";
956
+					$array[$i]['qty'] = $objSourceLine->qty - $row[1]." Erreur livraison !";
957 957
 					$array[$i]['ref'] = $objSourceLine->ref;
958
-					$array[$i]['label'] = $objSourceLine->label?$objSourceLine->label:$objSourceLine->description;
958
+					$array[$i]['label'] = $objSourceLine->label ? $objSourceLine->label : $objSourceLine->description;
959 959
 				}
960 960
 
961 961
 					$i++;
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 		}
965 965
 		else
966 966
 		{
967
-			$this->error=$this->db->error()." - sql=$sqlSourceLine";
967
+			$this->error = $this->db->error()." - sql=$sqlSourceLine";
968 968
 			return -1;
969 969
 		}
970 970
 	}
@@ -981,11 +981,11 @@  discard block
 block discarded – undo
981 981
 		if ($user->rights->expedition->creer)
982 982
 		{
983 983
 			$sql = "UPDATE ".MAIN_DB_PREFIX."livraison";
984
-			$sql.= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
985
-			$sql.= " WHERE rowid = ".$this->id;
984
+			$sql .= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null');
985
+			$sql .= " WHERE rowid = ".$this->id;
986 986
 
987 987
 			dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG);
988
-			$resql=$this->db->query($sql);
988
+			$resql = $this->db->query($sql);
989 989
 			if ($resql)
990 990
 			{
991 991
 				$this->date_delivery = $date_livraison;
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
 			}
994 994
 			else
995 995
 			{
996
-				$this->error=$this->db->error();
996
+				$this->error = $this->db->error();
997 997
 				return -1;
998 998
 			}
999 999
 		}
@@ -1013,19 +1013,19 @@  discard block
 block discarded – undo
1013 1013
 	 *  @param     int			$hideref        Hide ref
1014 1014
 	 *  @return    int             				0 if KO, 1 if OK
1015 1015
 	 */
1016
-	public function generateDocument($modele, $outputlangs='',$hidedetails=0,$hidedesc=0,$hideref=0)
1016
+	public function generateDocument($modele, $outputlangs = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1017 1017
 	{
1018
-		global $conf,$user,$langs;
1018
+		global $conf, $user, $langs;
1019 1019
 
1020 1020
 		$langs->load("deliveries");
1021 1021
 
1022
-		if (! dol_strlen($modele)) {
1022
+		if (!dol_strlen($modele)) {
1023 1023
 
1024 1024
 			$modele = 'typhon';
1025 1025
 
1026 1026
 			if ($this->modelpdf) {
1027 1027
 				$modele = $this->modelpdf;
1028
-			} elseif (! empty($conf->global->LIVRAISON_ADDON_PDF)) {
1028
+			} elseif (!empty($conf->global->LIVRAISON_ADDON_PDF)) {
1029 1029
 				$modele = $conf->global->LIVRAISON_ADDON_PDF;
1030 1030
 			}
1031 1031
 		}
@@ -1070,8 +1070,8 @@  discard block
 block discarded – undo
1070 1070
 	var $price;
1071 1071
 	var $fk_product;
1072 1072
 	var $origin_id;
1073
-	var $label;       // Label produit
1074
-	var $description;  // Description produit
1073
+	var $label; // Label produit
1074
+	var $description; // Description produit
1075 1075
 	/**
1076 1076
 	 * @deprecated
1077 1077
 	 * @see product_ref
@@ -1086,8 +1086,8 @@  discard block
 block discarded – undo
1086 1086
 	public $product_ref;
1087 1087
 	public $product_label;
1088 1088
 
1089
-	public $element='livraisondet';
1090
-	public $table_element='livraisondet';
1089
+	public $element = 'livraisondet';
1090
+	public $table_element = 'livraisondet';
1091 1091
 
1092 1092
 	/**
1093 1093
 	 *	Constructor
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
 	 */
1097 1097
 	function __construct($db)
1098 1098
 	{
1099
-		$this->db=$db;
1099
+		$this->db = $db;
1100 1100
 	}
1101 1101
 
1102 1102
 }
Please login to merge, or discard this patch.
Braces   +98 added lines, -61 removed lines patch added patch discarded remove patch
@@ -30,8 +30,12 @@  discard block
 block discarded – undo
30 30
 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
33
-if (! empty($conf->propal->enabled))   require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
34
-if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
33
+if (! empty($conf->propal->enabled)) {
34
+	require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
35
+}
36
+if (! empty($conf->commande->enabled)) {
37
+	require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
38
+}
35 39
 
36 40
 
37 41
 /**
@@ -82,7 +86,9 @@  discard block
 block discarded – undo
82 86
 
83 87
 		dol_syslog("Livraison::create");
84 88
 
85
-		if (empty($this->model_pdf)) $this->model_pdf=$conf->global->LIVRAISON_ADDON_PDF;
89
+		if (empty($this->model_pdf)) {
90
+			$this->model_pdf=$conf->global->LIVRAISON_ADDON_PDF;
91
+		}
86 92
 
87 93
 		$error = 0;
88 94
 
@@ -155,7 +161,10 @@  discard block
 block discarded – undo
155 161
 				for ($i = 0; $i < $num; $i++)
156 162
 				{
157 163
 					$origin_id=$this->lines[$i]->origin_line_id;
158
-					if (! $origin_id) $origin_id=$this->lines[$i]->commande_ligne_id;	// For backward compatibility
164
+					if (! $origin_id) {
165
+						$origin_id=$this->lines[$i]->commande_ligne_id;
166
+					}
167
+					// For backward compatibility
159 168
 
160 169
 					if (! $this->create_line($origin_id, $this->lines[$i]->qty, $this->lines[$i]->fk_product, $this->lines[$i]->description))
161 170
 					{
@@ -186,24 +195,21 @@  discard block
 block discarded – undo
186 195
 				{
187 196
 					$this->db->commit();
188 197
 					return $this->id;
189
-				}
190
-				else
198
+				} else
191 199
 				{
192 200
 					$error++;
193 201
 					$this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror;
194 202
 					$this->db->rollback();
195 203
 					return -3;
196 204
 				}
197
-			}
198
-			else
205
+			} else
199 206
 			{
200 207
 				$error++;
201 208
 				$this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror;
202 209
 				$this->db->rollback();
203 210
 				return -2;
204 211
 			}
205
-		}
206
-		else
212
+		} else
207 213
 		{
208 214
 			$error++;
209 215
 			$this->error=$this->db->lasterror()." - sql=".$this->db->lastqueryerror;
@@ -299,7 +305,9 @@  discard block
 block discarded – undo
299 305
 				$this->libelle_incoterms = $obj->libelle_incoterms;
300 306
 				$this->db->free($result);
301 307
 
302
-				if ($this->statut == 0) $this->brouillon = 1;
308
+				if ($this->statut == 0) {
309
+					$this->brouillon = 1;
310
+				}
303 311
 
304 312
 
305 313
 				// Retrieve all extrafields for delivery
@@ -319,15 +327,13 @@  discard block
 block discarded – undo
319 327
 				}
320 328
 
321 329
 				return 1;
322
-			}
323
-			else
330
+			} else
324 331
 			{
325 332
 				$this->error='Delivery with id '.$id.' not found sql='.$sql;
326 333
 				dol_syslog(get_class($this).'::fetch Error '.$this->error, LOG_ERR);
327 334
 				return -2;
328 335
 			}
329
-		}
330
-		else
336
+		} else
331 337
 		{
332 338
 			$this->error=$this->db->error();
333 339
 			return -1;
@@ -370,11 +376,12 @@  discard block
 block discarded – undo
370 376
 					$soc = new Societe($this->db);
371 377
 					$soc->fetch($this->socid);
372 378
 
373
-					if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life
379
+					if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) {
380
+						// empty should not happened, but when it occurs, the test save life
374 381
 		            {
375 382
 		                $numref = $objMod->livraison_get_num($soc,$this);
376
-		            }
377
-		            else
383
+					}
384
+		            } else
378 385
 					{
379 386
 		                $numref = $this->ref;
380 387
 		            }
@@ -418,7 +425,9 @@  discard block
 block discarded – undo
418 425
 			        {
419 426
 			            // Call trigger
420 427
 			            $result=$this->call_trigger('DELIVERY_VALIDATE',$user);
421
-			            if ($result < 0) $error++;
428
+			            if ($result < 0) {
429
+			            	$error++;
430
+			            }
422 431
 			            // End call triggers
423 432
 			        }
424 433
 
@@ -470,16 +479,14 @@  discard block
 block discarded – undo
470 479
 			        {
471 480
 			            $this->db->commit();
472 481
 			            return 1;
473
-			        }
474
-			        else
482
+			        } else
475 483
 					{
476 484
 			            $this->db->rollback();
477 485
 			            return -1;
478 486
 			        }
479 487
 				}
480 488
 			}
481
-		}
482
-		else
489
+		} else
483 490
 		{
484 491
 			$this->error="Non autorise";
485 492
 			dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
@@ -544,9 +551,11 @@  discard block
 block discarded – undo
544 551
 		global $conf;
545 552
 		$error = 0;
546 553
 
547
-		if ($id > 0 && !$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
554
+		if ($id > 0 && !$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) {
555
+			// For avoid conflicts if trigger used
548 556
 		{
549 557
 			$livraisonline = new LivraisonLigne($this->db);
558
+		}
550 559
 			$livraisonline->array_options=$array_options;
551 560
 			$livraisonline->id=$id;
552 561
 			$result=$livraisonline->insertExtraFields();
@@ -558,8 +567,11 @@  discard block
 block discarded – undo
558 567
 			}
559 568
 		}
560 569
 
561
-		if (! $error) return 1;
562
-		else return -1;
570
+		if (! $error) {
571
+			return 1;
572
+		} else {
573
+			return -1;
574
+		}
563 575
 	}
564 576
 
565 577
 
@@ -599,8 +611,7 @@  discard block
 block discarded – undo
599 611
 				$this->update_price();
600 612
 
601 613
 				return 1;
602
-			}
603
-			else
614
+			} else
604 615
 			{
605 616
 				return 0;
606 617
 			}
@@ -627,7 +638,9 @@  discard block
 block discarded – undo
627 638
 		{
628 639
 			// Delete linked object
629 640
 			$res = $this->deleteObjectLinked();
630
-			if ($res < 0) $error++;
641
+			if ($res < 0) {
642
+				$error++;
643
+			}
631 644
 
632 645
 			if (! $error)
633 646
 			{
@@ -670,22 +683,19 @@  discard block
 block discarded – undo
670 683
                     // End call triggers
671 684
 
672 685
 					return 1;
673
-				}
674
-				else
686
+				} else
675 687
 				{
676 688
 					$this->error=$this->db->lasterror()." - sql=$sql";
677 689
 					$this->db->rollback();
678 690
 					return -3;
679 691
 				}
680
-			}
681
-			else
692
+			} else
682 693
 			{
683 694
 				$this->error=$this->db->lasterror()." - sql=$sql";
684 695
 				$this->db->rollback();
685 696
 				return -2;
686 697
 			}
687
-		}
688
-		else
698
+		} else
689 699
 		{
690 700
 			$this->error=$this->db->lasterror()." - sql=$sql";
691 701
 			$this->db->rollback();
@@ -715,16 +725,24 @@  discard block
 block discarded – undo
715 725
         //{
716 726
         	// Add param to save lastsearch_values or not
717 727
         	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
718
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
719
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
728
+        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) {
729
+        		$add_save_lastsearch_values=1;
730
+        	}
731
+        	if ($add_save_lastsearch_values) {
732
+        		$url.='&save_lastsearch_values=1';
733
+        	}
720 734
         //}
721 735
 
722 736
 
723 737
         $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
724 738
 		$linkend='</a>';
725 739
 
726
-		if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
727
-		if ($withpicto && $withpicto != 2) $result.=' ';
740
+		if ($withpicto) {
741
+			$result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
742
+		}
743
+		if ($withpicto && $withpicto != 2) {
744
+			$result.=' ';
745
+		}
728 746
 		$result.=$linkstart.$this->ref.$linkend;
729 747
 		return $result;
730 748
 	}
@@ -811,27 +829,51 @@  discard block
 block discarded – undo
811 829
 
812 830
 		if ($mode==0)
813 831
 		{
814
-			if ($statut==-1) return $langs->trans('StatusDeliveryCanceled');
815
-			if ($statut==0)  return $langs->trans('StatusDeliveryDraft');
816
-			if ($statut==1)  return $langs->trans('StatusDeliveryValidated');
832
+			if ($statut==-1) {
833
+				return $langs->trans('StatusDeliveryCanceled');
834
+			}
835
+			if ($statut==0) {
836
+				return $langs->trans('StatusDeliveryDraft');
837
+			}
838
+			if ($statut==1) {
839
+				return $langs->trans('StatusDeliveryValidated');
840
+			}
817 841
 		}
818 842
 		if ($mode==1)
819 843
 		{
820
-			if ($statut==-1) return $langs->trans($this->statuts[$statut]);
821
-			if ($statut==0)  return $langs->trans($this->statuts[$statut]);
822
-			if ($statut==1)  return $langs->trans($this->statuts[$statut]);
844
+			if ($statut==-1) {
845
+				return $langs->trans($this->statuts[$statut]);
846
+			}
847
+			if ($statut==0) {
848
+				return $langs->trans($this->statuts[$statut]);
849
+			}
850
+			if ($statut==1) {
851
+				return $langs->trans($this->statuts[$statut]);
852
+			}
823 853
 		}
824 854
 		if ($mode == 4)
825 855
 		{
826
-			if ($statut==-1) return img_picto($langs->trans('StatusDeliveryCanceled'),'statut5').' '.$langs->trans('StatusDeliveryCanceled');
827
-			if ($statut==0)  return img_picto($langs->trans('StatusDeliveryDraft'),'statut0').' '.$langs->trans('StatusDeliveryDraft');
828
-			if ($statut==1)  return img_picto($langs->trans('StatusDeliveryValidated'),'statut4').' '.$langs->trans('StatusDeliveryValidated');
856
+			if ($statut==-1) {
857
+				return img_picto($langs->trans('StatusDeliveryCanceled'),'statut5').' '.$langs->trans('StatusDeliveryCanceled');
858
+			}
859
+			if ($statut==0) {
860
+				return img_picto($langs->trans('StatusDeliveryDraft'),'statut0').' '.$langs->trans('StatusDeliveryDraft');
861
+			}
862
+			if ($statut==1) {
863
+				return img_picto($langs->trans('StatusDeliveryValidated'),'statut4').' '.$langs->trans('StatusDeliveryValidated');
864
+			}
829 865
 		}
830 866
 		if ($mode == 6)
831 867
 		{
832
-			if ($statut==-1) return $langs->trans('StatusDeliveryCanceled').' '.img_picto($langs->trans('StatusDeliveryCanceled'),'statut5');
833
-			if ($statut==0)  return $langs->trans('StatusDeliveryDraft').' '.img_picto($langs->trans('StatusDeliveryDraft'),'statut0');
834
-			if ($statut==1)  return $langs->trans('StatusDeliveryValidated').' '.img_picto($langs->trans('StatusDeliveryValidated'),'statut4');
868
+			if ($statut==-1) {
869
+				return $langs->trans('StatusDeliveryCanceled').' '.img_picto($langs->trans('StatusDeliveryCanceled'),'statut5');
870
+			}
871
+			if ($statut==0) {
872
+				return $langs->trans('StatusDeliveryDraft').' '.img_picto($langs->trans('StatusDeliveryDraft'),'statut0');
873
+			}
874
+			if ($statut==1) {
875
+				return $langs->trans('StatusDeliveryValidated').' '.img_picto($langs->trans('StatusDeliveryValidated'),'statut4');
876
+			}
835 877
 		}
836 878
 	}
837 879
 
@@ -942,16 +984,14 @@  discard block
 block discarded – undo
942 984
 					if ($row[0] == $objSourceLine->rowid)
943 985
 					{
944 986
 						$array[$i]['qty'] = $objSourceLine->qty - $row[1];
945
-					}
946
-					else
987
+					} else
947 988
 					{
948 989
 						$array[$i]['qty'] = $objSourceLine->qty;
949 990
 					}
950 991
 
951 992
 					$array[$i]['ref'] = $objSourceLine->ref;
952 993
 					$array[$i]['label'] = $objSourceLine->label?$objSourceLine->label:$objSourceLine->description;
953
-				}
954
-				elseif($objSourceLine->qty - $row[1] < 0)
994
+				} elseif($objSourceLine->qty - $row[1] < 0)
955 995
 				{
956 996
 					$array[$i]['qty'] = $objSourceLine->qty - $row[1]. " Erreur livraison !";
957 997
 					$array[$i]['ref'] = $objSourceLine->ref;
@@ -961,8 +1001,7 @@  discard block
 block discarded – undo
961 1001
 					$i++;
962 1002
 			}
963 1003
 			return $array;
964
-		}
965
-		else
1004
+		} else
966 1005
 		{
967 1006
 			$this->error=$this->db->error()." - sql=$sqlSourceLine";
968 1007
 			return -1;
@@ -990,14 +1029,12 @@  discard block
 block discarded – undo
990 1029
 			{
991 1030
 				$this->date_delivery = $date_livraison;
992 1031
 				return 1;
993
-			}
994
-			else
1032
+			} else
995 1033
 			{
996 1034
 				$this->error=$this->db->error();
997 1035
 				return -1;
998 1036
 			}
999
-		}
1000
-		else
1037
+		} else
1001 1038
 		{
1002 1039
 			return -2;
1003 1040
 		}
Please login to merge, or discard this patch.
htdocs/core/class/html.formadmin.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -334,7 +334,7 @@
 block discarded – undo
334 334
 	 *
335 335
 	 *    	@param      string	$selected       Paper format pre-selected
336 336
 	 *    	@param      string	$htmlname       Name of HTML select field
337
-	 * 		@param		string	$filter			Value to filter on code
337
+	 * 		@param		integer	$filter			Value to filter on code
338 338
 	 * 		@param		int		$showempty		Add empty value
339 339
 	 * 		@return		string					Return HTML output
340 340
 	 */
Please login to merge, or discard this patch.
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 
88 88
 		foreach ($langs_available as $key => $value)
89 89
 		{
90
-		    $valuetoshow=$value;
91
-		    if ($showcode) $valuetoshow=$key.' - '.$value;
90
+			$valuetoshow=$value;
91
+			if ($showcode) $valuetoshow=$key.' - '.$value;
92 92
 
93 93
 			if ($filter && is_array($filter))
94 94
 			{
@@ -109,79 +109,79 @@  discard block
 block discarded – undo
109 109
 		$out.= '</select>';
110 110
 
111 111
 		// Make select dynamic
112
-        include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
113
-        $out.= ajax_combobox($htmlname);
112
+		include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
113
+		$out.= ajax_combobox($htmlname);
114 114
 
115 115
 		return $out;
116 116
 	}
117 117
 
118 118
 	/**
119
-     *    Return list of available menus (eldy_backoffice, ...)
120
-     *
121
-     *    @param	string		$selected        Preselected menu value
122
-     *    @param    string		$htmlname        Name of html select
123
-     *    @param    array		$dirmenuarray    Array of directories to scan
124
-     *    @param    string		$moreattrib      More attributes on html select tag
125
-     *    @return	integer|null
126
-     */
127
-    function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib='')
128
-    {
129
-        global $langs,$conf;
119
+	 *    Return list of available menus (eldy_backoffice, ...)
120
+	 *
121
+	 *    @param	string		$selected        Preselected menu value
122
+	 *    @param    string		$htmlname        Name of html select
123
+	 *    @param    array		$dirmenuarray    Array of directories to scan
124
+	 *    @param    string		$moreattrib      More attributes on html select tag
125
+	 *    @return	integer|null
126
+	 */
127
+	function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib='')
128
+	{
129
+		global $langs,$conf;
130 130
 
131
-        // Clean parameters
131
+		// Clean parameters
132 132
 
133 133
 
134
-        // Check parameters
135
-        if (! is_array($dirmenuarray)) return -1;
134
+		// Check parameters
135
+		if (! is_array($dirmenuarray)) return -1;
136 136
 
137 137
 		$menuarray=array();
138
-        foreach ($conf->file->dol_document_root as $dirroot)
139
-        {
140
-            foreach($dirmenuarray as $dirtoscan)
141
-            {
142
-                $dir=$dirroot.$dirtoscan;
143
-                //print $dir.'<br>';
144
-                if (is_dir($dir))
145
-                {
146
-    	            $handle=opendir($dir);
147
-    	            if (is_resource($handle))
148
-    	            {
149
-    	                while (($file = readdir($handle))!==false)
150
-    	                {
151
-    	                    if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index')
152
-    	                    {
153
-    	                        if (preg_match('/lib\.php$/i',$file)) continue;	// We exclude library files
154
-    	                        if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) continue;		// We exclude all menu manager files
155
-    	                        if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) continue;	// We exclude all menu manager files
156
-    	                        if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) continue;	// We exclude all menu manager files
157
-
158
-    	                        $filelib=preg_replace('/\.php$/i','',$file);
159
-    	        				$prefix='';
160
-    	        				// 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other
161
-    	        				if (preg_match('/^eldy/i',$file)) $prefix='0';
162
-                                else if (preg_match('/^smartphone/i',$file)) $prefix='2';
163
-    	        				else $prefix='3';
164
-
165
-    	                        if ($file == $selected)
166
-    	                        {
167
-    	        					$menuarray[$prefix.'_'.$file]='<option value="'.$file.'" selected>'.$filelib.'</option>';
168
-    	                        }
169
-    	                        else
170
-    	                        {
171
-    	                            $menuarray[$prefix.'_'.$file]='<option value="'.$file.'">'.$filelib.'</option>';
172
-    	                        }
173
-    	                    }
174
-    	                }
175
-    	                closedir($handle);
176
-    	            }
177
-                }
178
-            }
179
-        }
138
+		foreach ($conf->file->dol_document_root as $dirroot)
139
+		{
140
+			foreach($dirmenuarray as $dirtoscan)
141
+			{
142
+				$dir=$dirroot.$dirtoscan;
143
+				//print $dir.'<br>';
144
+				if (is_dir($dir))
145
+				{
146
+					$handle=opendir($dir);
147
+					if (is_resource($handle))
148
+					{
149
+						while (($file = readdir($handle))!==false)
150
+						{
151
+							if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index')
152
+							{
153
+								if (preg_match('/lib\.php$/i',$file)) continue;	// We exclude library files
154
+								if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) continue;		// We exclude all menu manager files
155
+								if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) continue;	// We exclude all menu manager files
156
+								if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) continue;	// We exclude all menu manager files
157
+
158
+								$filelib=preg_replace('/\.php$/i','',$file);
159
+								$prefix='';
160
+								// 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other
161
+								if (preg_match('/^eldy/i',$file)) $prefix='0';
162
+								else if (preg_match('/^smartphone/i',$file)) $prefix='2';
163
+								else $prefix='3';
164
+
165
+								if ($file == $selected)
166
+								{
167
+									$menuarray[$prefix.'_'.$file]='<option value="'.$file.'" selected>'.$filelib.'</option>';
168
+								}
169
+								else
170
+								{
171
+									$menuarray[$prefix.'_'.$file]='<option value="'.$file.'">'.$filelib.'</option>';
172
+								}
173
+							}
174
+						}
175
+						closedir($handle);
176
+					}
177
+				}
178
+			}
179
+		}
180 180
 		ksort($menuarray);
181 181
 
182 182
 		// Output combo list of menus
183
-        print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
184
-        $oldprefix='';
183
+		print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
184
+		$oldprefix='';
185 185
 		foreach ($menuarray as $key => $val)
186 186
 		{
187 187
 			$tab=explode('_',$key);
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 				// Affiche titre
194 194
 				print '<option value="-1" disabled>';
195 195
 				if ($newprefix=='0') print '-- '.$langs->trans("VersionRecommanded").' --';
196
-                if ($newprefix=='1') print '-- '.$langs->trans("VersionExperimental").' --';
196
+				if ($newprefix=='1') print '-- '.$langs->trans("VersionExperimental").' --';
197 197
 				if ($newprefix=='2') print '-- '.$langs->trans("VersionDevelopment").' --';
198 198
 				if ($newprefix=='3') print '-- '.$langs->trans("Other").' --';
199 199
 				print '</option>';
@@ -202,67 +202,67 @@  discard block
 block discarded – undo
202 202
 			print $val."\n";	// Show menu entry
203 203
 		}
204 204
 		print '</select>';
205
-    }
206
-
207
-    /**
208
-     *  Return combo list of available menu families
209
-     *
210
-     *  @param	string		$selected        Menu pre-selected
211
-     *  @param	string		$htmlname        Name of html select
212
-     *  @param	string[]	$dirmenuarray    Directories to scan
213
-     *  @return	void
214
-     */
215
-    function select_menu_families($selected, $htmlname, $dirmenuarray)
216
-    {
205
+	}
206
+
207
+	/**
208
+	 *  Return combo list of available menu families
209
+	 *
210
+	 *  @param	string		$selected        Menu pre-selected
211
+	 *  @param	string		$htmlname        Name of html select
212
+	 *  @param	string[]	$dirmenuarray    Directories to scan
213
+	 *  @return	void
214
+	 */
215
+	function select_menu_families($selected, $htmlname, $dirmenuarray)
216
+	{
217 217
 		global $langs,$conf;
218 218
 
219
-        //$expdevmenu=array('smartphone_backoffice.php','smartphone_frontoffice.php');  // Menu to disable if $conf->global->MAIN_FEATURES_LEVEL is not set
219
+		//$expdevmenu=array('smartphone_backoffice.php','smartphone_frontoffice.php');  // Menu to disable if $conf->global->MAIN_FEATURES_LEVEL is not set
220 220
 		$expdevmenu=array();
221 221
 
222 222
 		$menuarray=array();
223 223
 
224 224
 		foreach($dirmenuarray as $dirmenu)
225 225
 		{
226
-            foreach ($conf->file->dol_document_root as $dirroot)
227
-            {
228
-                $dir=$dirroot.$dirmenu;
229
-                if (is_dir($dir))
230
-                {
231
-	                $handle=opendir($dir);
232
-	                if (is_resource($handle))
233
-	                {
234
-	        			while (($file = readdir($handle))!==false)
235
-	        			{
236
-	        				if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
237
-	        				{
238
-	        					$filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file);
239
-	        					if (preg_match('/^index/i',$filelib)) continue;
240
-	        					if (preg_match('/^default/i',$filelib)) continue;
241
-	        					if (preg_match('/^empty/i',$filelib)) continue;
242
-	        					if (preg_match('/\.lib/i',$filelib)) continue;
243
-	        					if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) continue;
244
-
245
-	        					$menuarray[$filelib]=1;
246
-	        				}
247
-	        				$menuarray['all']=1;
248
-	        			}
249
-	        			closedir($handle);
250
-	                }
251
-                }
252
-            }
226
+			foreach ($conf->file->dol_document_root as $dirroot)
227
+			{
228
+				$dir=$dirroot.$dirmenu;
229
+				if (is_dir($dir))
230
+				{
231
+					$handle=opendir($dir);
232
+					if (is_resource($handle))
233
+					{
234
+						while (($file = readdir($handle))!==false)
235
+						{
236
+							if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
237
+							{
238
+								$filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file);
239
+								if (preg_match('/^index/i',$filelib)) continue;
240
+								if (preg_match('/^default/i',$filelib)) continue;
241
+								if (preg_match('/^empty/i',$filelib)) continue;
242
+								if (preg_match('/\.lib/i',$filelib)) continue;
243
+								if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) continue;
244
+
245
+								$menuarray[$filelib]=1;
246
+							}
247
+							$menuarray['all']=1;
248
+						}
249
+						closedir($handle);
250
+					}
251
+				}
252
+			}
253 253
 		}
254 254
 
255 255
 		ksort($menuarray);
256 256
 
257 257
 		// Affichage liste deroulante des menus
258
-        print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
259
-        $oldprefix='';
258
+		print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
259
+		$oldprefix='';
260 260
 		foreach ($menuarray as $key => $val)
261 261
 		{
262 262
 			$tab=explode('_',$key);
263 263
 			$newprefix=$tab[0];
264 264
 			print '<option value="'.$key.'"';
265
-            if ($key == $selected)
265
+			if ($key == $selected)
266 266
 			{
267 267
 				print '	selected';
268 268
 			}
@@ -272,21 +272,21 @@  discard block
 block discarded – undo
272 272
 			print '</option>'."\n";
273 273
 		}
274 274
 		print '</select>';
275
-    }
276
-
277
-
278
-    /**
279
-     *  Return a HTML select list of timezones
280
-     *
281
-     *  @param	string		$selected        Menu pre-selectionnee
282
-     *  @param  string		$htmlname        Nom de la zone select
283
-     *  @return	void
284
-     */
285
-    function select_timezone($selected,$htmlname)
286
-    {
275
+	}
276
+
277
+
278
+	/**
279
+	 *  Return a HTML select list of timezones
280
+	 *
281
+	 *  @param	string		$selected        Menu pre-selectionnee
282
+	 *  @param  string		$htmlname        Nom de la zone select
283
+	 *  @return	void
284
+	 */
285
+	function select_timezone($selected,$htmlname)
286
+	{
287 287
 		global $langs,$conf;
288 288
 
289
-        print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
289
+		print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
290 290
 		print '<option value="-1">&nbsp;</option>';
291 291
 
292 292
 		$arraytz=array(
@@ -345,24 +345,24 @@  discard block
 block discarded – undo
345 345
 		$sql = "SELECT code, label, width, height, unit";
346 346
 		$sql.= " FROM ".MAIN_DB_PREFIX."c_paper_format";
347 347
 		$sql.= " WHERE active=1";
348
-        if ($filter) $sql.=" AND code LIKE '%".$this->db->escape($filter)."%'";
349
-
350
-        $resql=$this->db->query($sql);
351
-        if ($resql)
352
-        {
353
-            $num=$this->db->num_rows($resql);
354
-            $i=0;
355
-            while ($i < $num)
356
-            {
357
-                $obj=$this->db->fetch_object($resql);
358
-                $unitKey = $langs->trans('SizeUnit'.$obj->unit);
359
-
360
-                $paperformat[$obj->code]= $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey);
361
-
362
-                $i++;
363
-            }
364
-        }
365
-        else
348
+		if ($filter) $sql.=" AND code LIKE '%".$this->db->escape($filter)."%'";
349
+
350
+		$resql=$this->db->query($sql);
351
+		if ($resql)
352
+		{
353
+			$num=$this->db->num_rows($resql);
354
+			$i=0;
355
+			while ($i < $num)
356
+			{
357
+				$obj=$this->db->fetch_object($resql);
358
+				$unitKey = $langs->trans('SizeUnit'.$obj->unit);
359
+
360
+				$paperformat[$obj->code]= $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey);
361
+
362
+				$i++;
363
+			}
364
+		}
365
+		else
366 366
 		{
367 367
 			dol_print_error($this->db);
368 368
 			return '';
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 		}
379 379
 		foreach ($paperformat as $key => $value)
380 380
 		{
381
-            if ($selected == $key)
381
+			if ($selected == $key)
382 382
 			{
383 383
 				$out.= '<option value="'.$key.'" selected>'.$value.'</option>';
384 384
 			}
Please login to merge, or discard this patch.
Spacing   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -58,59 +58,59 @@  discard block
 block discarded – undo
58 58
 	 *      @param      int         $showcode       Add language code into label
59 59
 	 *      @return		string						Return HTML select string with list of languages
60 60
 	 */
61
-	function select_language($selected='', $htmlname='lang_id', $showauto=0, $filter=null, $showempty='', $showwarning=0, $disabled=0, $morecss='', $showcode=0)
61
+	function select_language($selected = '', $htmlname = 'lang_id', $showauto = 0, $filter = null, $showempty = '', $showwarning = 0, $disabled = 0, $morecss = '', $showcode = 0)
62 62
 	{
63 63
 		global $langs;
64 64
 
65
-		$langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT,12);
65
+		$langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12);
66 66
 
67
-		$out='';
67
+		$out = '';
68 68
 
69
-		$out.= '<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled':'').'>';
69
+		$out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled ? ' disabled' : '').'>';
70 70
 		if ($showempty)
71 71
 		{
72
-			$out.= '<option value="0"';
73
-			if ($selected == '') $out.= ' selected';
74
-			$out.= '>';
75
-			if ($showempty != '1') $out.=$showempty;
76
-			else $out.='&nbsp;';
77
-			$out.='</option>';
72
+			$out .= '<option value="0"';
73
+			if ($selected == '') $out .= ' selected';
74
+			$out .= '>';
75
+			if ($showempty != '1') $out .= $showempty;
76
+			else $out .= '&nbsp;';
77
+			$out .= '</option>';
78 78
 		}
79 79
 		if ($showauto)
80 80
 		{
81
-			$out.= '<option value="auto"';
82
-			if ($selected == 'auto') $out.= ' selected';
83
-			$out.= '>'.$langs->trans("AutoDetectLang").'</option>';
81
+			$out .= '<option value="auto"';
82
+			if ($selected == 'auto') $out .= ' selected';
83
+			$out .= '>'.$langs->trans("AutoDetectLang").'</option>';
84 84
 		}
85 85
 
86 86
 		asort($langs_available);
87 87
 
88 88
 		foreach ($langs_available as $key => $value)
89 89
 		{
90
-		    $valuetoshow=$value;
91
-		    if ($showcode) $valuetoshow=$key.' - '.$value;
90
+		    $valuetoshow = $value;
91
+		    if ($showcode) $valuetoshow = $key.' - '.$value;
92 92
 
93 93
 			if ($filter && is_array($filter))
94 94
 			{
95
-				if ( ! array_key_exists($key, $filter))
95
+				if (!array_key_exists($key, $filter))
96 96
 				{
97
-					$out.= '<option value="'.$key.'">'.$valuetoshow.'</option>';
97
+					$out .= '<option value="'.$key.'">'.$valuetoshow.'</option>';
98 98
 				}
99 99
 			}
100 100
 			else if ($selected == $key)
101 101
 			{
102
-				$out.= '<option value="'.$key.'" selected>'.$valuetoshow.'</option>';
102
+				$out .= '<option value="'.$key.'" selected>'.$valuetoshow.'</option>';
103 103
 			}
104 104
 			else
105 105
 			{
106
-				$out.= '<option value="'.$key.'">'.$valuetoshow.'</option>';
106
+				$out .= '<option value="'.$key.'">'.$valuetoshow.'</option>';
107 107
 			}
108 108
 		}
109
-		$out.= '</select>';
109
+		$out .= '</select>';
110 110
 
111 111
 		// Make select dynamic
112
-        include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
113
-        $out.= ajax_combobox($htmlname);
112
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
113
+        $out .= ajax_combobox($htmlname);
114 114
 
115 115
 		return $out;
116 116
 	}
@@ -124,51 +124,51 @@  discard block
 block discarded – undo
124 124
      *    @param    string		$moreattrib      More attributes on html select tag
125 125
      *    @return	integer|null
126 126
      */
127
-    function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib='')
127
+    function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib = '')
128 128
     {
129
-        global $langs,$conf;
129
+        global $langs, $conf;
130 130
 
131 131
         // Clean parameters
132 132
 
133 133
 
134 134
         // Check parameters
135
-        if (! is_array($dirmenuarray)) return -1;
135
+        if (!is_array($dirmenuarray)) return -1;
136 136
 
137
-		$menuarray=array();
137
+		$menuarray = array();
138 138
         foreach ($conf->file->dol_document_root as $dirroot)
139 139
         {
140
-            foreach($dirmenuarray as $dirtoscan)
140
+            foreach ($dirmenuarray as $dirtoscan)
141 141
             {
142
-                $dir=$dirroot.$dirtoscan;
142
+                $dir = $dirroot.$dirtoscan;
143 143
                 //print $dir.'<br>';
144 144
                 if (is_dir($dir))
145 145
                 {
146
-    	            $handle=opendir($dir);
146
+    	            $handle = opendir($dir);
147 147
     	            if (is_resource($handle))
148 148
     	            {
149
-    	                while (($file = readdir($handle))!==false)
149
+    	                while (($file = readdir($handle)) !== false)
150 150
     	                {
151 151
     	                    if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index')
152 152
     	                    {
153
-    	                        if (preg_match('/lib\.php$/i',$file)) continue;	// We exclude library files
154
-    	                        if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) continue;		// We exclude all menu manager files
155
-    	                        if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) continue;	// We exclude all menu manager files
156
-    	                        if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) continue;	// We exclude all menu manager files
153
+    	                        if (preg_match('/lib\.php$/i', $file)) continue; // We exclude library files
154
+    	                        if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i', $file)) continue; // We exclude all menu manager files
155
+    	                        if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i', $file)) continue; // We exclude all menu manager files
156
+    	                        if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i', $file)) continue; // We exclude all menu manager files
157 157
 
158
-    	                        $filelib=preg_replace('/\.php$/i','',$file);
159
-    	        				$prefix='';
158
+    	                        $filelib = preg_replace('/\.php$/i', '', $file);
159
+    	        				$prefix = '';
160 160
     	        				// 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other
161
-    	        				if (preg_match('/^eldy/i',$file)) $prefix='0';
162
-                                else if (preg_match('/^smartphone/i',$file)) $prefix='2';
163
-    	        				else $prefix='3';
161
+    	        				if (preg_match('/^eldy/i', $file)) $prefix = '0';
162
+                                else if (preg_match('/^smartphone/i', $file)) $prefix = '2';
163
+    	        				else $prefix = '3';
164 164
 
165 165
     	                        if ($file == $selected)
166 166
     	                        {
167
-    	        					$menuarray[$prefix.'_'.$file]='<option value="'.$file.'" selected>'.$filelib.'</option>';
167
+    	        					$menuarray[$prefix.'_'.$file] = '<option value="'.$file.'" selected>'.$filelib.'</option>';
168 168
     	                        }
169 169
     	                        else
170 170
     	                        {
171
-    	                            $menuarray[$prefix.'_'.$file]='<option value="'.$file.'">'.$filelib.'</option>';
171
+    	                            $menuarray[$prefix.'_'.$file] = '<option value="'.$file.'">'.$filelib.'</option>';
172 172
     	                        }
173 173
     	                    }
174 174
     	                }
@@ -180,26 +180,26 @@  discard block
 block discarded – undo
180 180
 		ksort($menuarray);
181 181
 
182 182
 		// Output combo list of menus
183
-        print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
184
-        $oldprefix='';
183
+        print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
184
+        $oldprefix = '';
185 185
 		foreach ($menuarray as $key => $val)
186 186
 		{
187
-			$tab=explode('_',$key);
188
-			$newprefix=$tab[0];
189
-			if ($newprefix=='1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) continue;
190
-			if ($newprefix=='2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) continue;
187
+			$tab = explode('_', $key);
188
+			$newprefix = $tab[0];
189
+			if ($newprefix == '1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) continue;
190
+			if ($newprefix == '2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) continue;
191 191
 			if ($newprefix != $oldprefix)	// Add separators
192 192
 			{
193 193
 				// Affiche titre
194 194
 				print '<option value="-1" disabled>';
195
-				if ($newprefix=='0') print '-- '.$langs->trans("VersionRecommanded").' --';
196
-                if ($newprefix=='1') print '-- '.$langs->trans("VersionExperimental").' --';
197
-				if ($newprefix=='2') print '-- '.$langs->trans("VersionDevelopment").' --';
198
-				if ($newprefix=='3') print '-- '.$langs->trans("Other").' --';
195
+				if ($newprefix == '0') print '-- '.$langs->trans("VersionRecommanded").' --';
196
+                if ($newprefix == '1') print '-- '.$langs->trans("VersionExperimental").' --';
197
+				if ($newprefix == '2') print '-- '.$langs->trans("VersionDevelopment").' --';
198
+				if ($newprefix == '3') print '-- '.$langs->trans("Other").' --';
199 199
 				print '</option>';
200
-				$oldprefix=$newprefix;
200
+				$oldprefix = $newprefix;
201 201
 			}
202
-			print $val."\n";	// Show menu entry
202
+			print $val."\n"; // Show menu entry
203 203
 		}
204 204
 		print '</select>';
205 205
     }
@@ -214,37 +214,37 @@  discard block
 block discarded – undo
214 214
      */
215 215
     function select_menu_families($selected, $htmlname, $dirmenuarray)
216 216
     {
217
-		global $langs,$conf;
217
+		global $langs, $conf;
218 218
 
219 219
         //$expdevmenu=array('smartphone_backoffice.php','smartphone_frontoffice.php');  // Menu to disable if $conf->global->MAIN_FEATURES_LEVEL is not set
220
-		$expdevmenu=array();
220
+		$expdevmenu = array();
221 221
 
222
-		$menuarray=array();
222
+		$menuarray = array();
223 223
 
224
-		foreach($dirmenuarray as $dirmenu)
224
+		foreach ($dirmenuarray as $dirmenu)
225 225
 		{
226 226
             foreach ($conf->file->dol_document_root as $dirroot)
227 227
             {
228
-                $dir=$dirroot.$dirmenu;
228
+                $dir = $dirroot.$dirmenu;
229 229
                 if (is_dir($dir))
230 230
                 {
231
-	                $handle=opendir($dir);
231
+	                $handle = opendir($dir);
232 232
 	                if (is_resource($handle))
233 233
 	                {
234
-	        			while (($file = readdir($handle))!==false)
234
+	        			while (($file = readdir($handle)) !== false)
235 235
 	        			{
236 236
 	        				if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
237 237
 	        				{
238
-	        					$filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file);
239
-	        					if (preg_match('/^index/i',$filelib)) continue;
240
-	        					if (preg_match('/^default/i',$filelib)) continue;
241
-	        					if (preg_match('/^empty/i',$filelib)) continue;
242
-	        					if (preg_match('/\.lib/i',$filelib)) continue;
243
-	        					if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) continue;
244
-
245
-	        					$menuarray[$filelib]=1;
238
+	        					$filelib = preg_replace('/(_backoffice|_frontoffice)?\.php$/i', '', $file);
239
+	        					if (preg_match('/^index/i', $filelib)) continue;
240
+	        					if (preg_match('/^default/i', $filelib)) continue;
241
+	        					if (preg_match('/^empty/i', $filelib)) continue;
242
+	        					if (preg_match('/\.lib/i', $filelib)) continue;
243
+	        					if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file, $expdevmenu)) continue;
244
+
245
+	        					$menuarray[$filelib] = 1;
246 246
 	        				}
247
-	        				$menuarray['all']=1;
247
+	        				$menuarray['all'] = 1;
248 248
 	        			}
249 249
 	        			closedir($handle);
250 250
 	                }
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
 
257 257
 		// Affichage liste deroulante des menus
258 258
         print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
259
-        $oldprefix='';
259
+        $oldprefix = '';
260 260
 		foreach ($menuarray as $key => $val)
261 261
 		{
262
-			$tab=explode('_',$key);
263
-			$newprefix=$tab[0];
262
+			$tab = explode('_', $key);
263
+			$newprefix = $tab[0];
264 264
 			print '<option value="'.$key.'"';
265 265
             if ($key == $selected)
266 266
 			{
@@ -282,14 +282,14 @@  discard block
 block discarded – undo
282 282
      *  @param  string		$htmlname        Nom de la zone select
283 283
      *  @return	void
284 284
      */
285
-    function select_timezone($selected,$htmlname)
285
+    function select_timezone($selected, $htmlname)
286 286
     {
287
-		global $langs,$conf;
287
+		global $langs, $conf;
288 288
 
289 289
         print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
290 290
 		print '<option value="-1">&nbsp;</option>';
291 291
 
292
-		$arraytz=array(
292
+		$arraytz = array(
293 293
 			"Pacific/Midway"=>"GMT-11:00",
294 294
 			"Pacific/Fakaofo"=>"GMT-10:00",
295 295
 			"America/Anchorage"=>"GMT-09:00",
@@ -336,28 +336,28 @@  discard block
 block discarded – undo
336 336
 	 * 		@param		int		$showempty		Add empty value
337 337
 	 * 		@return		string					Return HTML output
338 338
 	 */
339
-	function select_paper_format($selected='',$htmlname='paperformat_id',$filter=0,$showempty=0)
339
+	function select_paper_format($selected = '', $htmlname = 'paperformat_id', $filter = 0, $showempty = 0)
340 340
 	{
341 341
 		global $langs;
342 342
 
343 343
 		$langs->load("dict");
344 344
 
345 345
 		$sql = "SELECT code, label, width, height, unit";
346
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_paper_format";
347
-		$sql.= " WHERE active=1";
348
-        if ($filter) $sql.=" AND code LIKE '%".$this->db->escape($filter)."%'";
346
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_paper_format";
347
+		$sql .= " WHERE active=1";
348
+        if ($filter) $sql .= " AND code LIKE '%".$this->db->escape($filter)."%'";
349 349
 
350
-        $resql=$this->db->query($sql);
350
+        $resql = $this->db->query($sql);
351 351
         if ($resql)
352 352
         {
353
-            $num=$this->db->num_rows($resql);
354
-            $i=0;
353
+            $num = $this->db->num_rows($resql);
354
+            $i = 0;
355 355
             while ($i < $num)
356 356
             {
357
-                $obj=$this->db->fetch_object($resql);
357
+                $obj = $this->db->fetch_object($resql);
358 358
                 $unitKey = $langs->trans('SizeUnit'.$obj->unit);
359 359
 
360
-                $paperformat[$obj->code]= $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey);
360
+                $paperformat[$obj->code] = $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey);
361 361
 
362 362
                 $i++;
363 363
             }
@@ -367,27 +367,27 @@  discard block
 block discarded – undo
367 367
 			dol_print_error($this->db);
368 368
 			return '';
369 369
 		}
370
-		$out='';
370
+		$out = '';
371 371
 
372
-		$out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
372
+		$out .= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
373 373
 		if ($showempty)
374 374
 		{
375
-			$out.= '<option value=""';
376
-			if ($selected == '') $out.= ' selected';
377
-			$out.= '>&nbsp;</option>';
375
+			$out .= '<option value=""';
376
+			if ($selected == '') $out .= ' selected';
377
+			$out .= '>&nbsp;</option>';
378 378
 		}
379 379
 		foreach ($paperformat as $key => $value)
380 380
 		{
381 381
             if ($selected == $key)
382 382
 			{
383
-				$out.= '<option value="'.$key.'" selected>'.$value.'</option>';
383
+				$out .= '<option value="'.$key.'" selected>'.$value.'</option>';
384 384
 			}
385 385
 			else
386 386
 			{
387
-				$out.= '<option value="'.$key.'">'.$value.'</option>';
387
+				$out .= '<option value="'.$key.'">'.$value.'</option>';
388 388
 			}
389 389
 		}
390
-		$out.= '</select>';
390
+		$out .= '</select>';
391 391
 
392 392
 		return $out;
393 393
 	}
Please login to merge, or discard this patch.
Braces   +95 added lines, -40 removed lines patch added patch discarded remove patch
@@ -70,16 +70,23 @@  discard block
 block discarded – undo
70 70
 		if ($showempty)
71 71
 		{
72 72
 			$out.= '<option value="0"';
73
-			if ($selected == '') $out.= ' selected';
73
+			if ($selected == '') {
74
+				$out.= ' selected';
75
+			}
74 76
 			$out.= '>';
75
-			if ($showempty != '1') $out.=$showempty;
76
-			else $out.='&nbsp;';
77
+			if ($showempty != '1') {
78
+				$out.=$showempty;
79
+			} else {
80
+				$out.='&nbsp;';
81
+			}
77 82
 			$out.='</option>';
78 83
 		}
79 84
 		if ($showauto)
80 85
 		{
81 86
 			$out.= '<option value="auto"';
82
-			if ($selected == 'auto') $out.= ' selected';
87
+			if ($selected == 'auto') {
88
+				$out.= ' selected';
89
+			}
83 90
 			$out.= '>'.$langs->trans("AutoDetectLang").'</option>';
84 91
 		}
85 92
 
@@ -88,7 +95,9 @@  discard block
 block discarded – undo
88 95
 		foreach ($langs_available as $key => $value)
89 96
 		{
90 97
 		    $valuetoshow=$value;
91
-		    if ($showcode) $valuetoshow=$key.' - '.$value;
98
+		    if ($showcode) {
99
+		    	$valuetoshow=$key.' - '.$value;
100
+		    }
92 101
 
93 102
 			if ($filter && is_array($filter))
94 103
 			{
@@ -96,12 +105,10 @@  discard block
 block discarded – undo
96 105
 				{
97 106
 					$out.= '<option value="'.$key.'">'.$valuetoshow.'</option>';
98 107
 				}
99
-			}
100
-			else if ($selected == $key)
108
+			} else if ($selected == $key)
101 109
 			{
102 110
 				$out.= '<option value="'.$key.'" selected>'.$valuetoshow.'</option>';
103
-			}
104
-			else
111
+			} else
105 112
 			{
106 113
 				$out.= '<option value="'.$key.'">'.$valuetoshow.'</option>';
107 114
 			}
@@ -132,7 +139,9 @@  discard block
 block discarded – undo
132 139
 
133 140
 
134 141
         // Check parameters
135
-        if (! is_array($dirmenuarray)) return -1;
142
+        if (! is_array($dirmenuarray)) {
143
+        	return -1;
144
+        }
136 145
 
137 146
 		$menuarray=array();
138 147
         foreach ($conf->file->dol_document_root as $dirroot)
@@ -150,23 +159,38 @@  discard block
 block discarded – undo
150 159
     	                {
151 160
     	                    if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index')
152 161
     	                    {
153
-    	                        if (preg_match('/lib\.php$/i',$file)) continue;	// We exclude library files
154
-    	                        if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) continue;		// We exclude all menu manager files
155
-    	                        if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) continue;	// We exclude all menu manager files
156
-    	                        if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) continue;	// We exclude all menu manager files
162
+    	                        if (preg_match('/lib\.php$/i',$file)) {
163
+    	                        	continue;
164
+    	                        }
165
+    	                        // We exclude library files
166
+    	                        if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) {
167
+    	                        	continue;
168
+    	                        }
169
+    	                        // We exclude all menu manager files
170
+    	                        if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) {
171
+    	                        	continue;
172
+    	                        }
173
+    	                        // We exclude all menu manager files
174
+    	                        if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) {
175
+    	                        	continue;
176
+    	                        }
177
+    	                        // We exclude all menu manager files
157 178
 
158 179
     	                        $filelib=preg_replace('/\.php$/i','',$file);
159 180
     	        				$prefix='';
160 181
     	        				// 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other
161
-    	        				if (preg_match('/^eldy/i',$file)) $prefix='0';
162
-                                else if (preg_match('/^smartphone/i',$file)) $prefix='2';
163
-    	        				else $prefix='3';
182
+    	        				if (preg_match('/^eldy/i',$file)) {
183
+    	        					$prefix='0';
184
+    	        				} else if (preg_match('/^smartphone/i',$file)) {
185
+                                	$prefix='2';
186
+                                } else {
187
+    	        					$prefix='3';
188
+    	        				}
164 189
 
165 190
     	                        if ($file == $selected)
166 191
     	                        {
167 192
     	        					$menuarray[$prefix.'_'.$file]='<option value="'.$file.'" selected>'.$filelib.'</option>';
168
-    	                        }
169
-    	                        else
193
+    	                        } else
170 194
     	                        {
171 195
     	                            $menuarray[$prefix.'_'.$file]='<option value="'.$file.'">'.$filelib.'</option>';
172 196
     	                        }
@@ -186,16 +210,30 @@  discard block
 block discarded – undo
186 210
 		{
187 211
 			$tab=explode('_',$key);
188 212
 			$newprefix=$tab[0];
189
-			if ($newprefix=='1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) continue;
190
-			if ($newprefix=='2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) continue;
191
-			if ($newprefix != $oldprefix)	// Add separators
213
+			if ($newprefix=='1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) {
214
+				continue;
215
+			}
216
+			if ($newprefix=='2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) {
217
+				continue;
218
+			}
219
+			if ($newprefix != $oldprefix) {
220
+				// Add separators
192 221
 			{
193 222
 				// Affiche titre
194 223
 				print '<option value="-1" disabled>';
195
-				if ($newprefix=='0') print '-- '.$langs->trans("VersionRecommanded").' --';
196
-                if ($newprefix=='1') print '-- '.$langs->trans("VersionExperimental").' --';
197
-				if ($newprefix=='2') print '-- '.$langs->trans("VersionDevelopment").' --';
198
-				if ($newprefix=='3') print '-- '.$langs->trans("Other").' --';
224
+			}
225
+				if ($newprefix=='0') {
226
+					print '-- '.$langs->trans("VersionRecommanded").' --';
227
+				}
228
+                if ($newprefix=='1') {
229
+                	print '-- '.$langs->trans("VersionExperimental").' --';
230
+                }
231
+				if ($newprefix=='2') {
232
+					print '-- '.$langs->trans("VersionDevelopment").' --';
233
+				}
234
+				if ($newprefix=='3') {
235
+					print '-- '.$langs->trans("Other").' --';
236
+				}
199 237
 				print '</option>';
200 238
 				$oldprefix=$newprefix;
201 239
 			}
@@ -236,11 +274,21 @@  discard block
 block discarded – undo
236 274
 	        				if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
237 275
 	        				{
238 276
 	        					$filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file);
239
-	        					if (preg_match('/^index/i',$filelib)) continue;
240
-	        					if (preg_match('/^default/i',$filelib)) continue;
241
-	        					if (preg_match('/^empty/i',$filelib)) continue;
242
-	        					if (preg_match('/\.lib/i',$filelib)) continue;
243
-	        					if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) continue;
277
+	        					if (preg_match('/^index/i',$filelib)) {
278
+	        						continue;
279
+	        					}
280
+	        					if (preg_match('/^default/i',$filelib)) {
281
+	        						continue;
282
+	        					}
283
+	        					if (preg_match('/^empty/i',$filelib)) {
284
+	        						continue;
285
+	        					}
286
+	        					if (preg_match('/\.lib/i',$filelib)) {
287
+	        						continue;
288
+	        					}
289
+	        					if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) {
290
+	        						continue;
291
+	        					}
244 292
 
245 293
 	        					$menuarray[$filelib]=1;
246 294
 	        				}
@@ -267,8 +315,11 @@  discard block
 block discarded – undo
267 315
 				print '	selected';
268 316
 			}
269 317
 			print '>';
270
-			if ($key == 'all') print $langs->trans("AllMenus");
271
-			else print $key;
318
+			if ($key == 'all') {
319
+				print $langs->trans("AllMenus");
320
+			} else {
321
+				print $key;
322
+			}
272 323
 			print '</option>'."\n";
273 324
 		}
274 325
 		print '</select>';
@@ -319,7 +370,9 @@  discard block
 block discarded – undo
319 370
 		foreach ($arraytz as $lib => $gmt)
320 371
 		{
321 372
 			print '<option value="'.$lib.'"';
322
-			if ($selected == $lib || $selected == $gmt) print ' selected';
373
+			if ($selected == $lib || $selected == $gmt) {
374
+				print ' selected';
375
+			}
323 376
 			print '>'.$gmt.'</option>'."\n";
324 377
 		}
325 378
 		print '</select>';
@@ -345,7 +398,9 @@  discard block
 block discarded – undo
345 398
 		$sql = "SELECT code, label, width, height, unit";
346 399
 		$sql.= " FROM ".MAIN_DB_PREFIX."c_paper_format";
347 400
 		$sql.= " WHERE active=1";
348
-        if ($filter) $sql.=" AND code LIKE '%".$this->db->escape($filter)."%'";
401
+        if ($filter) {
402
+        	$sql.=" AND code LIKE '%".$this->db->escape($filter)."%'";
403
+        }
349 404
 
350 405
         $resql=$this->db->query($sql);
351 406
         if ($resql)
@@ -361,8 +416,7 @@  discard block
 block discarded – undo
361 416
 
362 417
                 $i++;
363 418
             }
364
-        }
365
-        else
419
+        } else
366 420
 		{
367 421
 			dol_print_error($this->db);
368 422
 			return '';
@@ -373,7 +427,9 @@  discard block
 block discarded – undo
373 427
 		if ($showempty)
374 428
 		{
375 429
 			$out.= '<option value=""';
376
-			if ($selected == '') $out.= ' selected';
430
+			if ($selected == '') {
431
+				$out.= ' selected';
432
+			}
377 433
 			$out.= '>&nbsp;</option>';
378 434
 		}
379 435
 		foreach ($paperformat as $key => $value)
@@ -381,8 +437,7 @@  discard block
 block discarded – undo
381 437
             if ($selected == $key)
382 438
 			{
383 439
 				$out.= '<option value="'.$key.'" selected>'.$value.'</option>';
384
-			}
385
-			else
440
+			} else
386 441
 			{
387 442
 				$out.= '<option value="'.$key.'">'.$value.'</option>';
388 443
 			}
Please login to merge, or discard this patch.
htdocs/core/class/html.formcompany.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -416,7 +416,7 @@
 block discarded – undo
416 416
 	 *    Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays.
417 417
 	 *
418 418
 	 *    @param	string		$selected        	Code forme juridique a pre-selectionne
419
-	 *    @param    mixed		$country_codeid		0=liste tous pays confondus, sinon code du pays a afficher
419
+	 *    @param    integer		$country_codeid		0=liste tous pays confondus, sinon code du pays a afficher
420 420
 	 *    @param    string		$filter          	Add a SQL filter on list
421 421
 	 *    @return	void
422 422
 	 *    @deprecated Use print xxx->select_juridicalstatus instead
Please login to merge, or discard this patch.
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -279,9 +279,9 @@  discard block
 block discarded – undo
279 279
 			dol_print_error($this->db);
280 280
 		}
281 281
 
282
-        // Make select dynamic
283
-        include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
284
-        $out .= ajax_combobox($htmlname);
282
+		// Make select dynamic
283
+		include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
284
+		$out .= ajax_combobox($htmlname);
285 285
 
286 286
 		return $out;
287 287
 	}
@@ -431,9 +431,9 @@  discard block
 block discarded – undo
431 431
 	 *
432 432
 	 *    @param	string		$selected        	Preselected code of juridical type
433 433
 	 *    @param    int			$country_codeid     0=list for all countries, otherwise list only country requested
434
-     *    @param    string		$filter          	Add a SQL filter on list
435
-     *    @param	string		$htmlname			HTML name of select
436
-     *    @return	string							String with HTML select
434
+	 *    @param    string		$filter          	Add a SQL filter on list
435
+	 *    @param	string		$htmlname			HTML name of select
436
+	 *    @return	string							String with HTML select
437 437
 	 */
438 438
 	function select_juridicalstatus($selected='', $country_codeid=0, $filter='', $htmlname='forme_juridique_code')
439 439
 	{
@@ -511,9 +511,9 @@  discard block
 block discarded – undo
511 511
 			$out.= '</select>';
512 512
 			if ($user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
513 513
 
514
-		    // Make select dynamic
515
-        	include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
516
-	        $out .= ajax_combobox($htmlname);
514
+			// Make select dynamic
515
+			include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
516
+			$out .= ajax_combobox($htmlname);
517 517
 
518 518
 			$out.= '</div>';
519 519
 		}
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
 	 *  @param  string		$htmlname       Name of HTML form
536 536
 	 * 	@param	array		$limitto		Disable answers that are not id in this array list
537 537
 	 *  @param	int			$forceid		This is to force another object id than object->id
538
-     *  @param	string		$moreparam		String with more param to add into url when noajax search is used.
538
+	 *  @param	string		$moreparam		String with more param to add into url when noajax search is used.
539 539
 	 * 	@return int 						The selected third party ID
540 540
 	 */
541 541
 	function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $moreparam='')
@@ -684,21 +684,21 @@  discard block
 block discarded – undo
684 684
 		}
685 685
 	}
686 686
 
687
-    /**
688
-     *  Return a select list with types of contacts
689
-     *
690
-     *  @param	object		$object         Object to use to find type of contact
691
-     *  @param  string		$selected       Default selected value
692
-     *  @param  string		$htmlname		HTML select name
693
-     *  @param  string		$source			Source ('internal' or 'external')
694
-     *  @param  string		$sortorder		Sort criteria ('position', 'code', ...)
695
-     *  @param  int			$showempty      1=Add en empty line
696
-     *  @param  string      $morecss        Add more css to select component
697
-     *  @return	void
698
-     */
687
+	/**
688
+	 *  Return a select list with types of contacts
689
+	 *
690
+	 *  @param	object		$object         Object to use to find type of contact
691
+	 *  @param  string		$selected       Default selected value
692
+	 *  @param  string		$htmlname		HTML select name
693
+	 *  @param  string		$source			Source ('internal' or 'external')
694
+	 *  @param  string		$sortorder		Sort criteria ('position', 'code', ...)
695
+	 *  @param  int			$showempty      1=Add en empty line
696
+	 *  @param  string      $morecss        Add more css to select component
697
+	 *  @return	void
698
+	 */
699 699
 	function selectTypeContact($object, $selected, $htmlname = 'type', $source='internal', $sortorder='position', $showempty=0, $morecss='')
700 700
 	{
701
-	    global $user, $langs;
701
+		global $user, $langs;
702 702
 
703 703
 		if (is_object($object) && method_exists($object, 'liste_type_contact'))
704 704
 		{
@@ -748,96 +748,96 @@  discard block
 block discarded – undo
748 748
 		return $out;
749 749
 	}
750 750
 
751
-    /**
752
-     *  Return HTML string to use as input of professional id into a HTML page (siren, siret, etc...)
753
-     *
754
-     *  @param	int		$idprof         1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
755
-     *  @param  string	$htmlname       Name of HTML select
756
-     *  @param  string	$preselected    Default value to show
757
-     *  @param  string	$country_code   FR, IT, ...
758
-     *  @param  string  $morecss        More css
759
-     *  @return	string					HTML string with prof id
760
-     */
761
-    function get_input_id_prof($idprof,$htmlname,$preselected,$country_code,$morecss='maxwidth100onsmartphone quatrevingtpercent')
762
-    {
763
-        global $conf,$langs;
764
-
765
-        $formlength=0;
766
-        if (empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
767
-        	if ($country_code == 'FR')
768
-        	{
769
-        		if (isset($idprof)) {
770
-        			if ($idprof==1) $formlength=9;
771
-        			else if ($idprof==2) $formlength=14;
772
-        			else if ($idprof==3) $formlength=5;      // 4 chiffres et 1 lettre depuis janvier
773
-        			else if ($idprof==4) $formlength=32;     // No maximum as we need to include a town name in this id
774
-        		}
775
-        	}
776
-        	else if ($country_code == 'ES')
777
-        	{
778
-        		if ($idprof==1) $formlength=9;  //CIF/NIF/NIE 9 digits
779
-        		if ($idprof==2) $formlength=12; //NASS 12 digits without /
780
-        		if ($idprof==3) $formlength=5;  //CNAE 5 digits
781
-        		if ($idprof==4) $formlength=32; //depend of college
782
-        	}
783
-        }
784
-
785
-        $selected=$preselected;
786
-        if (! $selected && isset($idprof)) {
787
-        	if ($idprof==1 && ! empty($this->idprof1)) $selected=$this->idprof1;
788
-        	else if ($idprof==2 && ! empty($this->idprof2)) $selected=$this->idprof2;
789
-        	else if ($idprof==3 && ! empty($this->idprof3)) $selected=$this->idprof3;
790
-        	else if ($idprof==4 && ! empty($this->idprof4)) $selected=$this->idprof4;
791
-        }
792
-
793
-        $maxlength=$formlength;
794
-        if (empty($formlength)) { $formlength=24; $maxlength=128; }
795
-
796
-        $out = '<input type="text" '.($morecss?'class="'.$morecss.'" ':'').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
797
-
798
-        return $out;
799
-    }
800
-
801
-    /**
802
-     * Return a HTML select with localtax values for thirdparties
803
-     *
804
-     * @param 	int 		$local			LocalTax
805
-     * @param 	int 		$selected		Preselected value
806
-     * @param 	string      $htmlname		HTML select name
807
-     * @return	void
808
-     */
809
-    function select_localtax($local, $selected, $htmlname)
810
-    {
811
-    	$tax=get_localtax_by_third($local);
812
-
813
-    	$num = $this->db->num_rows($tax);
814
-    	$i = 0;
815
-    	if ($num)
816
-    	{
817
-    		$valors=explode(":", $tax);
818
-
819
-    		if (count($valors) > 1)
820
-    		{
821
-    			//montar select
822
-    			print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
823
-    			while ($i <= (count($valors))-1)
824
-    			{
825
-    				if ($selected == $valors[$i])
826
-    				{
827
-    					print '<option value="'.$valors[$i].'" selected>';
828
-    				}
829
-    				else
830
-    				{
831
-    					print '<option value="'.$valors[$i].'">';
832
-    				}
833
-    				print $valors[$i];
834
-    				print '</option>';
835
-    				$i++;
836
-    			}
837
-    			print'</select>';
838
-    		}
839
-    	}
840
-    }
751
+	/**
752
+	 *  Return HTML string to use as input of professional id into a HTML page (siren, siret, etc...)
753
+	 *
754
+	 *  @param	int		$idprof         1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
755
+	 *  @param  string	$htmlname       Name of HTML select
756
+	 *  @param  string	$preselected    Default value to show
757
+	 *  @param  string	$country_code   FR, IT, ...
758
+	 *  @param  string  $morecss        More css
759
+	 *  @return	string					HTML string with prof id
760
+	 */
761
+	function get_input_id_prof($idprof,$htmlname,$preselected,$country_code,$morecss='maxwidth100onsmartphone quatrevingtpercent')
762
+	{
763
+		global $conf,$langs;
764
+
765
+		$formlength=0;
766
+		if (empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
767
+			if ($country_code == 'FR')
768
+			{
769
+				if (isset($idprof)) {
770
+					if ($idprof==1) $formlength=9;
771
+					else if ($idprof==2) $formlength=14;
772
+					else if ($idprof==3) $formlength=5;      // 4 chiffres et 1 lettre depuis janvier
773
+					else if ($idprof==4) $formlength=32;     // No maximum as we need to include a town name in this id
774
+				}
775
+			}
776
+			else if ($country_code == 'ES')
777
+			{
778
+				if ($idprof==1) $formlength=9;  //CIF/NIF/NIE 9 digits
779
+				if ($idprof==2) $formlength=12; //NASS 12 digits without /
780
+				if ($idprof==3) $formlength=5;  //CNAE 5 digits
781
+				if ($idprof==4) $formlength=32; //depend of college
782
+			}
783
+		}
784
+
785
+		$selected=$preselected;
786
+		if (! $selected && isset($idprof)) {
787
+			if ($idprof==1 && ! empty($this->idprof1)) $selected=$this->idprof1;
788
+			else if ($idprof==2 && ! empty($this->idprof2)) $selected=$this->idprof2;
789
+			else if ($idprof==3 && ! empty($this->idprof3)) $selected=$this->idprof3;
790
+			else if ($idprof==4 && ! empty($this->idprof4)) $selected=$this->idprof4;
791
+		}
792
+
793
+		$maxlength=$formlength;
794
+		if (empty($formlength)) { $formlength=24; $maxlength=128; }
795
+
796
+		$out = '<input type="text" '.($morecss?'class="'.$morecss.'" ':'').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
797
+
798
+		return $out;
799
+	}
800
+
801
+	/**
802
+	 * Return a HTML select with localtax values for thirdparties
803
+	 *
804
+	 * @param 	int 		$local			LocalTax
805
+	 * @param 	int 		$selected		Preselected value
806
+	 * @param 	string      $htmlname		HTML select name
807
+	 * @return	void
808
+	 */
809
+	function select_localtax($local, $selected, $htmlname)
810
+	{
811
+		$tax=get_localtax_by_third($local);
812
+
813
+		$num = $this->db->num_rows($tax);
814
+		$i = 0;
815
+		if ($num)
816
+		{
817
+			$valors=explode(":", $tax);
818
+
819
+			if (count($valors) > 1)
820
+			{
821
+				//montar select
822
+				print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
823
+				while ($i <= (count($valors))-1)
824
+				{
825
+					if ($selected == $valors[$i])
826
+					{
827
+						print '<option value="'.$valors[$i].'" selected>';
828
+					}
829
+					else
830
+					{
831
+						print '<option value="'.$valors[$i].'">';
832
+					}
833
+					print $valors[$i];
834
+					print '</option>';
835
+					$i++;
836
+				}
837
+				print'</select>';
838
+			}
839
+		}
840
+	}
841 841
 
842 842
 }
843 843
 
Please login to merge, or discard this patch.
Spacing   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -56,19 +56,19 @@  discard block
 block discarded – undo
56 56
 	 *      @param  string	$filter     Add a SQL filter to select
57 57
 	 *    	@return array      			Array of types
58 58
 	 */
59
-	function typent_array($mode=0, $filter='')
59
+	function typent_array($mode = 0, $filter = '')
60 60
 	{
61
-		global $langs,$mysoc;
61
+		global $langs, $mysoc;
62 62
 
63 63
 		$effs = array();
64 64
 
65 65
 		$sql = "SELECT id, code, libelle";
66
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_typent";
67
-		$sql.= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id)?'0':$mysoc->country_id).")";
68
-		if ($filter) $sql.=" ".$filter;
69
-		$sql.= " ORDER by position, id";
66
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_typent";
67
+		$sql .= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id) ? '0' : $mysoc->country_id).")";
68
+		if ($filter) $sql .= " ".$filter;
69
+		$sql .= " ORDER by position, id";
70 70
 		dol_syslog(get_class($this).'::typent_array', LOG_DEBUG);
71
-		$resql=$this->db->query($sql);
71
+		$resql = $this->db->query($sql);
72 72
 		if ($resql)
73 73
 		{
74 74
 			$num = $this->db->num_rows($resql);
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
 			while ($i < $num)
78 78
 			{
79 79
 				$objp = $this->db->fetch_object($resql);
80
-				if (! $mode) $key=$objp->id;
81
-				else $key=$objp->code;
80
+				if (!$mode) $key = $objp->id;
81
+				else $key = $objp->code;
82 82
 				if ($langs->trans($objp->code) != $objp->code) $effs[$key] = $langs->trans($objp->code);
83 83
 				else $effs[$key] = $objp->libelle;
84
-				if ($effs[$key]=='-') $effs[$key]='';
84
+				if ($effs[$key] == '-') $effs[$key] = '';
85 85
 				$i++;
86 86
 			}
87 87
 			$this->db->free($resql);
@@ -97,17 +97,17 @@  discard block
 block discarded – undo
97 97
 	 *	@param  string	$filter     Add a SQL filter to select
98 98
 	 *  @return array				Array of types d'effectifs
99 99
 	 */
100
-	function effectif_array($mode=0, $filter='')
100
+	function effectif_array($mode = 0, $filter = '')
101 101
 	{
102 102
 		$effs = array();
103 103
 
104 104
 		$sql = "SELECT id, code, libelle";
105 105
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_effectif";
106
-		$sql.= " WHERE active = 1";
107
-		if ($filter) $sql.=" ".$filter;
106
+		$sql .= " WHERE active = 1";
107
+		if ($filter) $sql .= " ".$filter;
108 108
 		$sql .= " ORDER BY id ASC";
109 109
 		dol_syslog(get_class($this).'::effectif_array', LOG_DEBUG);
110
-		$resql=$this->db->query($sql);
110
+		$resql = $this->db->query($sql);
111 111
 		if ($resql)
112 112
 		{
113 113
 			$num = $this->db->num_rows($resql);
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
 			while ($i < $num)
117 117
 			{
118 118
 				$objp = $this->db->fetch_object($resql);
119
-				if (! $mode) $key=$objp->id;
120
-				else $key=$objp->code;
119
+				if (!$mode) $key = $objp->id;
120
+				else $key = $objp->code;
121 121
 
122
-				$effs[$key] = $objp->libelle!='-'?$objp->libelle:'';
122
+				$effs[$key] = $objp->libelle != '-' ? $objp->libelle : '';
123 123
 				$i++;
124 124
 			}
125 125
 			$this->db->free($resql);
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 *	@param	int		$empty			Add empty value in list
138 138
 	 *	@return	void
139 139
 	 */
140
-	function form_prospect_level($page, $selected='', $htmlname='prospect_level_id', $empty=0)
140
+	function form_prospect_level($page, $selected = '', $htmlname = 'prospect_level_id', $empty = 0)
141 141
 	{
142 142
 		global $user, $langs;
143 143
 
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 		print '<input type="hidden" name="action" value="setprospectlevel">';
146 146
 		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
147 147
 
148
-		dol_syslog(get_class($this).'::form_prospect_level',LOG_DEBUG);
148
+		dol_syslog(get_class($this).'::form_prospect_level', LOG_DEBUG);
149 149
 		$sql = "SELECT code, label";
150
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
151
-		$sql.= " WHERE active > 0";
152
-		$sql.= " ORDER BY sortorder";
150
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
151
+		$sql .= " WHERE active > 0";
152
+		$sql .= " ORDER BY sortorder";
153 153
 		$resql = $this->db->query($sql);
154 154
 		if ($resql)
155 155
 		{
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 			print Form::selectarray($htmlname, $options, $selected);
173 173
 		}
174 174
 		else dol_print_error($this->db);
175
-		if (! empty($htmlname) && $user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
175
+		if (!empty($htmlname) && $user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
176 176
 		print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
177 177
 		print '</form>';
178 178
 	}
@@ -189,9 +189,9 @@  discard block
 block discarded – undo
189 189
 	 *   @param     string	$htmlname			Id of department
190 190
 	 *   @return	void
191 191
 	 */
192
-	function select_departement($selected='',$country_codeid=0, $htmlname='state_id')
192
+	function select_departement($selected = '', $country_codeid = 0, $htmlname = 'state_id')
193 193
 	{
194
-		print $this->select_state($selected,$country_codeid, $htmlname);
194
+		print $this->select_state($selected, $country_codeid, $htmlname);
195 195
 	}
196 196
 
197 197
 	/**
@@ -207,81 +207,81 @@  discard block
 block discarded – undo
207 207
 	 * 	  @return	string						String with HTML select
208 208
 	 *    @see select_country
209 209
 	 */
210
-	function select_state($selected='',$country_codeid=0, $htmlname='state_id')
210
+	function select_state($selected = '', $country_codeid = 0, $htmlname = 'state_id')
211 211
 	{
212
-		global $conf,$langs,$user;
212
+		global $conf, $langs, $user;
213 213
 
214
-		dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid,LOG_DEBUG);
214
+		dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid, LOG_DEBUG);
215 215
 
216 216
 		$langs->load("dict");
217 217
 
218
-		$out='';
218
+		$out = '';
219 219
 
220 220
 		// On recherche les departements/cantons/province active d'une region et pays actif
221 221
 		$sql = "SELECT d.rowid, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.nom as region_name FROM";
222
-		$sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
222
+		$sql .= " ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
223 223
 		$sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
224 224
 		$sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
225 225
 		if ($country_codeid && is_numeric($country_codeid))   $sql .= " AND c.rowid = '".$country_codeid."'";
226
-		if ($country_codeid && ! is_numeric($country_codeid)) $sql .= " AND c.code = '".$country_codeid."'";
226
+		if ($country_codeid && !is_numeric($country_codeid)) $sql .= " AND c.code = '".$country_codeid."'";
227 227
 		$sql .= " ORDER BY c.code, d.code_departement";
228 228
 
229 229
 		dol_syslog(get_class($this)."::select_departement", LOG_DEBUG);
230
-		$result=$this->db->query($sql);
230
+		$result = $this->db->query($sql);
231 231
 		if ($result)
232 232
 		{
233
-			if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
234
-			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';
233
+			if (!empty($htmlname)) $out .= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
234
+			if ($country_codeid) $out .= '<option value="0">&nbsp;</option>';
235 235
 			$num = $this->db->num_rows($result);
236 236
 			$i = 0;
237
-			dol_syslog(get_class($this)."::select_departement num=".$num,LOG_DEBUG);
237
+			dol_syslog(get_class($this)."::select_departement num=".$num, LOG_DEBUG);
238 238
 			if ($num)
239 239
 			{
240
-				$country='';
240
+				$country = '';
241 241
 				while ($i < $num)
242 242
 				{
243 243
 					$obj = $this->db->fetch_object($result);
244 244
 					if ($obj->code == '0')		// Le code peut etre une chaine
245 245
 					{
246
-						$out.= '<option value="0">&nbsp;</option>';
246
+						$out .= '<option value="0">&nbsp;</option>';
247 247
 					}
248 248
 					else {
249
-						if (! $country || $country != $obj->country)
249
+						if (!$country || $country != $obj->country)
250 250
 						{
251 251
 							// Affiche la rupture si on est en mode liste multipays
252
-							if (! $country_codeid && $obj->country_code)
252
+							if (!$country_codeid && $obj->country_code)
253 253
 							{
254
-								$out.= '<option value="-1" disabled>----- '.$obj->country." -----</option>\n";
255
-								$country=$obj->country;
254
+								$out .= '<option value="-1" disabled>----- '.$obj->country." -----</option>\n";
255
+								$country = $obj->country;
256 256
 							}
257 257
 						}
258 258
 
259
-						if ((! empty($selected) && $selected == $obj->rowid)
260
-						 || (empty($selected) && ! empty($conf->global->MAIN_FORCE_DEFAULT_STATE_ID) && $conf->global->MAIN_FORCE_DEFAULT_STATE_ID == $obj->rowid))
259
+						if ((!empty($selected) && $selected == $obj->rowid)
260
+						 || (empty($selected) && !empty($conf->global->MAIN_FORCE_DEFAULT_STATE_ID) && $conf->global->MAIN_FORCE_DEFAULT_STATE_ID == $obj->rowid))
261 261
 						{
262
-							$out.= '<option value="'.$obj->rowid.'" selected>';
262
+							$out .= '<option value="'.$obj->rowid.'" selected>';
263 263
 						}
264 264
 						else
265 265
 						{
266
-							$out.= '<option value="'.$obj->rowid.'">';
266
+							$out .= '<option value="'.$obj->rowid.'">';
267 267
 						}
268 268
 						// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
269
-						if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 2) {
270
-							$out.= $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
269
+						if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 2) {
270
+							$out .= $obj->region_name.' - '.$obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
271 271
 						}
272
-						else if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 1) {
273
-							$out.= $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
272
+						else if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 1) {
273
+							$out .= $obj->region_name.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
274 274
 						}
275 275
 						else {
276
-							$out.= $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
276
+							$out .= $obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
277 277
 						}
278
-						$out.= '</option>';
278
+						$out .= '</option>';
279 279
 					}
280 280
 					$i++;
281 281
 				}
282 282
 			}
283
-			if (! empty($htmlname)) $out.= '</select>';
284
-			if (! empty($htmlname) && $user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
283
+			if (!empty($htmlname)) $out .= '</select>';
284
+			if (!empty($htmlname) && $user->admin) $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
285 285
 		}
286 286
 		else
287 287
 		{
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 		}
290 290
 
291 291
         // Make select dynamic
292
-        include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
292
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
293 293
         $out .= ajax_combobox($htmlname);
294 294
 
295 295
 		return $out;
@@ -306,18 +306,18 @@  discard block
 block discarded – undo
306 306
 	 *   @param		string		$htmlname		Name of HTML select field
307 307
 	 *   @return	void
308 308
 	 */
309
-	function select_region($selected='',$htmlname='region_id')
309
+	function select_region($selected = '', $htmlname = 'region_id')
310 310
 	{
311
-		global $conf,$langs;
311
+		global $conf, $langs;
312 312
 		$langs->load("dict");
313 313
 
314 314
 		$sql = "SELECT r.rowid, r.code_region as code, r.nom as label, r.active, c.code as country_code, c.label as country";
315
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c";
316
-		$sql.= " WHERE r.fk_pays=c.rowid AND r.active = 1 and c.active = 1";
317
-		$sql.= " ORDER BY c.code, c.label ASC";
315
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c";
316
+		$sql .= " WHERE r.fk_pays=c.rowid AND r.active = 1 and c.active = 1";
317
+		$sql .= " ORDER BY c.code, c.label ASC";
318 318
 
319 319
 		dol_syslog(get_class($this)."::select_region", LOG_DEBUG);
320
-		$resql=$this->db->query($sql);
320
+		$resql = $this->db->query($sql);
321 321
 		if ($resql)
322 322
 		{
323 323
 			print '<select class="flat" name="'.$htmlname.'">';
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 			$i = 0;
326 326
 			if ($num)
327 327
 			{
328
-				$country='';
328
+				$country = '';
329 329
 				while ($i < $num)
330 330
 				{
331 331
 					$obj = $this->db->fetch_object($resql);
@@ -336,10 +336,10 @@  discard block
 block discarded – undo
336 336
 						if ($country == '' || $country != $obj->country)
337 337
 						{
338 338
 							// Show break
339
-							$key=$langs->trans("Country".strtoupper($obj->country_code));
340
-							$valuetoshow=($key != "Country".strtoupper($obj->country_code))?$obj->country_code." - ".$key:$obj->country;
339
+							$key = $langs->trans("Country".strtoupper($obj->country_code));
340
+							$valuetoshow = ($key != "Country".strtoupper($obj->country_code)) ? $obj->country_code." - ".$key : $obj->country;
341 341
 							print '<option value="-1" disabled>----- '.$valuetoshow." -----</option>\n";
342
-							$country=$obj->country;
342
+							$country = $obj->country;
343 343
 						}
344 344
 
345 345
 						if ($selected > 0 && $selected == $obj->code)
@@ -370,22 +370,22 @@  discard block
 block discarded – undo
370 370
 	 *  @param  string  $morecss        Add more css on SELECT element
371 371
 	 *  @return	string					String with HTML select
372 372
 	 */
373
-	function select_civility($selected='',$htmlname='civility_id',$morecss='maxwidth100')
373
+	function select_civility($selected = '', $htmlname = 'civility_id', $morecss = 'maxwidth100')
374 374
 	{
375
-		global $conf,$langs,$user;
375
+		global $conf, $langs, $user;
376 376
 		$langs->load("dict");
377 377
 
378
-		$out='';
378
+		$out = '';
379 379
 
380 380
 		$sql = "SELECT rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_civility";
381
-		$sql.= " WHERE active = 1";
381
+		$sql .= " WHERE active = 1";
382 382
 
383 383
 		dol_syslog("Form::select_civility", LOG_DEBUG);
384
-		$resql=$this->db->query($sql);
384
+		$resql = $this->db->query($sql);
385 385
 		if ($resql)
386 386
 		{
387
-			$out.= '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
388
-			$out.= '<option value="">&nbsp;</option>';
387
+			$out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
388
+			$out .= '<option value="">&nbsp;</option>';
389 389
 			$num = $this->db->num_rows($resql);
390 390
 			$i = 0;
391 391
 			if ($num)
@@ -395,20 +395,20 @@  discard block
 block discarded – undo
395 395
 					$obj = $this->db->fetch_object($resql);
396 396
 					if ($selected == $obj->code)
397 397
 					{
398
-						$out.= '<option value="'.$obj->code.'" selected>';
398
+						$out .= '<option value="'.$obj->code.'" selected>';
399 399
 					}
400 400
 					else
401 401
 					{
402
-						$out.= '<option value="'.$obj->code.'">';
402
+						$out .= '<option value="'.$obj->code.'">';
403 403
 					}
404 404
 					// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
405
-					$out.= ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->label!='-'?$obj->label:''));
406
-					$out.= '</option>';
405
+					$out .= ($langs->trans("Civility".$obj->code) != "Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
406
+					$out .= '</option>';
407 407
 					$i++;
408 408
 				}
409 409
 			}
410
-			$out.= '</select>';
411
-			if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
410
+			$out .= '</select>';
411
+			if ($user->admin) $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
412 412
 		}
413 413
 		else
414 414
 		{
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 	 *    @deprecated Use print xxx->select_juridicalstatus instead
430 430
 	 *    @see select_juridicalstatus()
431 431
 	 */
432
-	function select_forme_juridique($selected='', $country_codeid=0, $filter='')
432
+	function select_forme_juridique($selected = '', $country_codeid = 0, $filter = '')
433 433
 	{
434 434
 		print $this->select_juridicalstatus($selected, $country_codeid, $filter);
435 435
 	}
@@ -444,12 +444,12 @@  discard block
 block discarded – undo
444 444
      *    @param	string		$htmlname			HTML name of select
445 445
      *    @return	string							String with HTML select
446 446
 	 */
447
-	function select_juridicalstatus($selected='', $country_codeid=0, $filter='', $htmlname='forme_juridique_code')
447
+	function select_juridicalstatus($selected = '', $country_codeid = 0, $filter = '', $htmlname = 'forme_juridique_code')
448 448
 	{
449
-		global $conf,$langs,$user;
449
+		global $conf, $langs, $user;
450 450
 		$langs->load("dict");
451 451
 
452
-		$out='';
452
+		$out = '';
453 453
 
454 454
 		// On recherche les formes juridiques actives des pays actifs
455 455
 		$sql  = "SELECT f.rowid, f.code as code , f.libelle as label, f.active, c.label as country, c.code as country_code";
@@ -461,70 +461,70 @@  discard block
 block discarded – undo
461 461
 		$sql .= " ORDER BY c.code";
462 462
 
463 463
 		dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG);
464
-		$resql=$this->db->query($sql);
464
+		$resql = $this->db->query($sql);
465 465
 		if ($resql)
466 466
 		{
467
-			$out.= '<div id="particulier2" class="visible">';
468
-			$out.= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
469
-			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';	// When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
467
+			$out .= '<div id="particulier2" class="visible">';
468
+			$out .= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
469
+			if ($country_codeid) $out .= '<option value="0">&nbsp;</option>'; // When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
470 470
 
471 471
 			$num = $this->db->num_rows($resql);
472 472
 			if ($num)
473 473
 			{
474 474
 				$i = 0;
475
-				$country=''; $arraydata=array();
475
+				$country = ''; $arraydata = array();
476 476
 				while ($i < $num)
477 477
 				{
478 478
 					$obj = $this->db->fetch_object($resql);
479 479
 
480 480
 					if ($obj->code)		// We exclude empty line, we will add it later
481 481
 					{
482
-						$labelcountry=(($langs->trans("Country".$obj->country_code)!="Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
483
-						$labeljs=(($langs->trans("JuridicalStatus".$obj->code)!="JuridicalStatus".$obj->code) ? $langs->trans("JuridicalStatus".$obj->code) : ($obj->label!='-'?$obj->label:''));	// $obj->label is already in output charset (converted by database driver)
484
-						$arraydata[$obj->code]=array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
482
+						$labelcountry = (($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
483
+						$labeljs = (($langs->trans("JuridicalStatus".$obj->code) != "JuridicalStatus".$obj->code) ? $langs->trans("JuridicalStatus".$obj->code) : ($obj->label != '-' ? $obj->label : '')); // $obj->label is already in output charset (converted by database driver)
484
+						$arraydata[$obj->code] = array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
485 485
 					}
486 486
 					$i++;
487 487
 				}
488 488
 
489
-				$arraydata=dol_sort_array($arraydata, 'label_sort', 'ASC');
489
+				$arraydata = dol_sort_array($arraydata, 'label_sort', 'ASC');
490 490
 				if (empty($country_codeid))	// Introduce empty value (if $country_codeid not empty, empty value was already added)
491 491
 				{
492
-					$arraydata[0]=array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
492
+					$arraydata[0] = array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
493 493
 				}
494 494
 
495
-				foreach($arraydata as $key => $val)
495
+				foreach ($arraydata as $key => $val)
496 496
 				{
497
-					if (! $country || $country != $val['country'])
497
+					if (!$country || $country != $val['country'])
498 498
 					{
499 499
 						// Show break when we are in multi country mode
500 500
 						if (empty($country_codeid) && $val['country_code'])
501 501
 						{
502
-							$out.= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
503
-							$country=$val['country'];
502
+							$out .= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
503
+							$country = $val['country'];
504 504
 						}
505 505
 					}
506 506
 
507 507
 					if ($selected > 0 && $selected == $val['code'])
508 508
 					{
509
-						$out.= '<option value="'.$val['code'].'" selected>';
509
+						$out .= '<option value="'.$val['code'].'" selected>';
510 510
 					}
511 511
 					else
512 512
 					{
513
-						$out.= '<option value="'.$val['code'].'">';
513
+						$out .= '<option value="'.$val['code'].'">';
514 514
 					}
515 515
 					// If translation exists, we use it, otherwise we use default label in database
516
-					$out.= $val['label'];
517
-					$out.= '</option>';
516
+					$out .= $val['label'];
517
+					$out .= '</option>';
518 518
 				}
519 519
 			}
520
-			$out.= '</select>';
521
-			if ($user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
520
+			$out .= '</select>';
521
+			if ($user->admin) $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
522 522
 
523 523
 		    // Make select dynamic
524
-        	include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
524
+        	include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
525 525
 	        $out .= ajax_combobox($htmlname);
526 526
 
527
-			$out.= '</div>';
527
+			$out .= '</div>';
528 528
 		}
529 529
 		else
530 530
 		{
@@ -547,19 +547,19 @@  discard block
 block discarded – undo
547 547
      *  @param	string		$moreparam		String with more param to add into url when noajax search is used.
548 548
 	 * 	@return int 						The selected third party ID
549 549
 	 */
550
-	function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $moreparam='')
550
+	function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany', $limitto = '', $forceid = 0, $moreparam = '')
551 551
 	{
552 552
 		global $conf, $langs;
553 553
 
554
-		if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT))
554
+		if (!empty($conf->use_javascript_ajax) && !empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT))
555 555
 		{
556 556
 			// Use Ajax search
557
-			$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
557
+			$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT) ? $conf->global->COMPANY_USE_SEARCH_TO_SELECT : 2);
558 558
 
559
-			$socid=0; $name='';
559
+			$socid = 0; $name = '';
560 560
 			if ($selected > 0)
561 561
 			{
562
-				$tmpthirdparty=new Societe($this->db);
562
+				$tmpthirdparty = new Societe($this->db);
563 563
 				$result = $tmpthirdparty->fetch($selected);
564 564
 				if ($result > 0)
565 565
 				{
@@ -569,13 +569,13 @@  discard block
 block discarded – undo
569 569
 			}
570 570
 
571 571
 
572
-			$events=array();
572
+			$events = array();
573 573
 			// Add an entry 'method' to say 'yes, we must execute url with param action = method';
574 574
 			// Add an entry 'url' to say which url to execute
575 575
 			// Add an entry htmlname to say which element we must change once url is called
576 576
 			// Add entry params => array('cssid' => 'attr') to say to remov or add attribute attr if answer of url return  0 or >0 lines
577 577
 			// To refresh contacts list on thirdparty list change
578
-			$events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
578
+			$events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php', 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
579 579
 
580 580
 			if (count($events))	// If there is some ajax events to run once selection is done, we add code here to run events
581 581
 			{
@@ -630,21 +630,21 @@  discard block
 block discarded – undo
630 630
 
631 631
 			print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
632 632
 			print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />';
633
-			print ajax_autocompleter(($socid?$socid:-1), $htmlname, DOL_URL_ROOT.'/societe/ajaxcompanies.php', '', $minLength, 0);
633
+			print ajax_autocompleter(($socid ? $socid : -1), $htmlname, DOL_URL_ROOT.'/societe/ajaxcompanies.php', '', $minLength, 0);
634 634
 			return $socid;
635 635
 		}
636 636
 		else
637 637
 		{
638 638
 			// Search to list thirdparties
639 639
 			$sql = "SELECT s.rowid, s.nom as name FROM";
640
-			$sql.= " ".MAIN_DB_PREFIX."societe as s";
641
-			$sql.= " WHERE s.entity IN (".getEntity('societe').")";
640
+			$sql .= " ".MAIN_DB_PREFIX."societe as s";
641
+			$sql .= " WHERE s.entity IN (".getEntity('societe').")";
642 642
 			// For ajax search we limit here. For combo list, we limit later
643 643
 			if (is_array($limitto) && count($limitto))
644 644
 			{
645
-				$sql.= " AND s.rowid IN (".join(',',$limitto).")";
645
+				$sql .= " AND s.rowid IN (".join(',', $limitto).")";
646 646
 			}
647
-			$sql.= " ORDER BY s.nom ASC";
647
+			$sql .= " ORDER BY s.nom ASC";
648 648
 
649 649
 			$resql = $this->db->query($sql);
650 650
 			if ($resql)
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 				print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"';
653 653
 				if ($conf->use_javascript_ajax)
654 654
 				{
655
-					$javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
655
+					$javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid > 0 ? $forceid : $object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
656 656
 					print ' onChange="'.$javaScript.'"';
657 657
 				}
658 658
 				print '>';
@@ -664,22 +664,22 @@  discard block
 block discarded – undo
664 664
 					{
665 665
 						$obj = $this->db->fetch_object($resql);
666 666
 						if ($i == 0) $firstCompany = $obj->rowid;
667
-						$disabled=0;
668
-						if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
667
+						$disabled = 0;
668
+						if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) $disabled = 1;
669 669
 						if ($selected > 0 && $selected == $obj->rowid)
670 670
 						{
671 671
 							print '<option value="'.$obj->rowid.'"';
672 672
 							if ($disabled) print ' disabled';
673
-							print ' selected>'.dol_trunc($obj->name,24).'</option>';
673
+							print ' selected>'.dol_trunc($obj->name, 24).'</option>';
674 674
 							$firstCompany = $obj->rowid;
675 675
 						}
676 676
 						else
677 677
 						{
678 678
 							print '<option value="'.$obj->rowid.'"';
679 679
 							if ($disabled) print ' disabled';
680
-							print '>'.dol_trunc($obj->name,24).'</option>';
680
+							print '>'.dol_trunc($obj->name, 24).'</option>';
681 681
 						}
682
-						$i ++;
682
+						$i++;
683 683
 					}
684 684
 				}
685 685
 				print "</select>\n";
@@ -705,23 +705,23 @@  discard block
 block discarded – undo
705 705
      *  @param  string      $morecss        Add more css to select component
706 706
      *  @return	void
707 707
      */
708
-	function selectTypeContact($object, $selected, $htmlname = 'type', $source='internal', $sortorder='position', $showempty=0, $morecss='')
708
+	function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '')
709 709
 	{
710 710
 	    global $user, $langs;
711 711
 
712 712
 		if (is_object($object) && method_exists($object, 'liste_type_contact'))
713 713
 		{
714 714
 			$lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
715
-			print '<select class="flat valignmiddle'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
715
+			print '<select class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
716 716
 			if ($showempty) print '<option value="0"></option>';
717
-			foreach($lesTypes as $key=>$value)
717
+			foreach ($lesTypes as $key=>$value)
718 718
 			{
719 719
 				print '<option value="'.$key.'"';
720 720
 				if ($key == $selected) print ' selected';
721 721
 				print '>'.$value.'</option>';
722 722
 			}
723 723
 			print "</select>";
724
-			if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
724
+			if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
725 725
 			print "\n";
726 726
 		}
727 727
 	}
@@ -738,21 +738,21 @@  discard block
 block discarded – undo
738 738
 	 *    @param    string      $morecss                More css
739 739
 	 *    @return	string
740 740
 	 */
741
-	function select_ziptown($selected='', $htmlname='zipcode', $fields='', $fieldsize=0, $disableautocomplete=0, $moreattrib='',$morecss='')
741
+	function select_ziptown($selected = '', $htmlname = 'zipcode', $fields = '', $fieldsize = 0, $disableautocomplete = 0, $moreattrib = '', $morecss = '')
742 742
 	{
743 743
 		global $conf;
744 744
 
745
-		$out='';
745
+		$out = '';
746 746
 
747
-		$size='';
748
-		if (!empty($fieldsize)) $size='size="'.$fieldsize.'"';
747
+		$size = '';
748
+		if (!empty($fieldsize)) $size = 'size="'.$fieldsize.'"';
749 749
 
750 750
 		if ($conf->use_javascript_ajax && empty($disableautocomplete))
751 751
 		{
752
-			$out.= ajax_multiautocompleter($htmlname,$fields,DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
753
-			$moreattrib.=' autocomplete="off"';
752
+			$out .= ajax_multiautocompleter($htmlname, $fields, DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
753
+			$moreattrib .= ' autocomplete="off"';
754 754
 		}
755
-		$out.= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss?' '.$morecss:'').'" type="text"'.($moreattrib?' '.$moreattrib:'').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
755
+		$out .= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss ? ' '.$morecss : '').'" type="text"'.($moreattrib ? ' '.$moreattrib : '').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
756 756
 
757 757
 		return $out;
758 758
 	}
@@ -767,42 +767,42 @@  discard block
 block discarded – undo
767 767
      *  @param  string  $morecss        More css
768 768
      *  @return	string					HTML string with prof id
769 769
      */
770
-    function get_input_id_prof($idprof,$htmlname,$preselected,$country_code,$morecss='maxwidth100onsmartphone quatrevingtpercent')
770
+    function get_input_id_prof($idprof, $htmlname, $preselected, $country_code, $morecss = 'maxwidth100onsmartphone quatrevingtpercent')
771 771
     {
772
-        global $conf,$langs;
772
+        global $conf, $langs;
773 773
 
774
-        $formlength=0;
774
+        $formlength = 0;
775 775
         if (empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
776 776
         	if ($country_code == 'FR')
777 777
         	{
778 778
         		if (isset($idprof)) {
779
-        			if ($idprof==1) $formlength=9;
780
-        			else if ($idprof==2) $formlength=14;
781
-        			else if ($idprof==3) $formlength=5;      // 4 chiffres et 1 lettre depuis janvier
782
-        			else if ($idprof==4) $formlength=32;     // No maximum as we need to include a town name in this id
779
+        			if ($idprof == 1) $formlength = 9;
780
+        			else if ($idprof == 2) $formlength = 14;
781
+        			else if ($idprof == 3) $formlength = 5; // 4 chiffres et 1 lettre depuis janvier
782
+        			else if ($idprof == 4) $formlength = 32; // No maximum as we need to include a town name in this id
783 783
         		}
784 784
         	}
785 785
         	else if ($country_code == 'ES')
786 786
         	{
787
-        		if ($idprof==1) $formlength=9;  //CIF/NIF/NIE 9 digits
788
-        		if ($idprof==2) $formlength=12; //NASS 12 digits without /
789
-        		if ($idprof==3) $formlength=5;  //CNAE 5 digits
790
-        		if ($idprof==4) $formlength=32; //depend of college
787
+        		if ($idprof == 1) $formlength = 9; //CIF/NIF/NIE 9 digits
788
+        		if ($idprof == 2) $formlength = 12; //NASS 12 digits without /
789
+        		if ($idprof == 3) $formlength = 5; //CNAE 5 digits
790
+        		if ($idprof == 4) $formlength = 32; //depend of college
791 791
         	}
792 792
         }
793 793
 
794
-        $selected=$preselected;
795
-        if (! $selected && isset($idprof)) {
796
-        	if ($idprof==1 && ! empty($this->idprof1)) $selected=$this->idprof1;
797
-        	else if ($idprof==2 && ! empty($this->idprof2)) $selected=$this->idprof2;
798
-        	else if ($idprof==3 && ! empty($this->idprof3)) $selected=$this->idprof3;
799
-        	else if ($idprof==4 && ! empty($this->idprof4)) $selected=$this->idprof4;
794
+        $selected = $preselected;
795
+        if (!$selected && isset($idprof)) {
796
+        	if ($idprof == 1 && !empty($this->idprof1)) $selected = $this->idprof1;
797
+        	else if ($idprof == 2 && !empty($this->idprof2)) $selected = $this->idprof2;
798
+        	else if ($idprof == 3 && !empty($this->idprof3)) $selected = $this->idprof3;
799
+        	else if ($idprof == 4 && !empty($this->idprof4)) $selected = $this->idprof4;
800 800
         }
801 801
 
802
-        $maxlength=$formlength;
803
-        if (empty($formlength)) { $formlength=24; $maxlength=128; }
802
+        $maxlength = $formlength;
803
+        if (empty($formlength)) { $formlength = 24; $maxlength = 128; }
804 804
 
805
-        $out = '<input type="text" '.($morecss?'class="'.$morecss.'" ':'').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
805
+        $out = '<input type="text" '.($morecss ? 'class="'.$morecss.'" ' : '').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
806 806
 
807 807
         return $out;
808 808
     }
@@ -817,19 +817,19 @@  discard block
 block discarded – undo
817 817
      */
818 818
     function select_localtax($local, $selected, $htmlname)
819 819
     {
820
-    	$tax=get_localtax_by_third($local);
820
+    	$tax = get_localtax_by_third($local);
821 821
 
822 822
     	$num = $this->db->num_rows($tax);
823 823
     	$i = 0;
824 824
     	if ($num)
825 825
     	{
826
-    		$valors=explode(":", $tax);
826
+    		$valors = explode(":", $tax);
827 827
 
828 828
     		if (count($valors) > 1)
829 829
     		{
830 830
     			//montar select
831 831
     			print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
832
-    			while ($i <= (count($valors))-1)
832
+    			while ($i <= (count($valors)) - 1)
833 833
     			{
834 834
     				if ($selected == $valors[$i])
835 835
     				{
Please login to merge, or discard this patch.
Braces   +152 added lines, -79 removed lines patch added patch discarded remove patch
@@ -65,7 +65,9 @@  discard block
 block discarded – undo
65 65
 		$sql = "SELECT id, code, libelle";
66 66
 		$sql.= " FROM ".MAIN_DB_PREFIX."c_typent";
67 67
 		$sql.= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id)?'0':$mysoc->country_id).")";
68
-		if ($filter) $sql.=" ".$filter;
68
+		if ($filter) {
69
+			$sql.=" ".$filter;
70
+		}
69 71
 		$sql.= " ORDER by position, id";
70 72
 		dol_syslog(get_class($this).'::typent_array', LOG_DEBUG);
71 73
 		$resql=$this->db->query($sql);
@@ -77,11 +79,19 @@  discard block
 block discarded – undo
77 79
 			while ($i < $num)
78 80
 			{
79 81
 				$objp = $this->db->fetch_object($resql);
80
-				if (! $mode) $key=$objp->id;
81
-				else $key=$objp->code;
82
-				if ($langs->trans($objp->code) != $objp->code) $effs[$key] = $langs->trans($objp->code);
83
-				else $effs[$key] = $objp->libelle;
84
-				if ($effs[$key]=='-') $effs[$key]='';
82
+				if (! $mode) {
83
+					$key=$objp->id;
84
+				} else {
85
+					$key=$objp->code;
86
+				}
87
+				if ($langs->trans($objp->code) != $objp->code) {
88
+					$effs[$key] = $langs->trans($objp->code);
89
+				} else {
90
+					$effs[$key] = $objp->libelle;
91
+				}
92
+				if ($effs[$key]=='-') {
93
+					$effs[$key]='';
94
+				}
85 95
 				$i++;
86 96
 			}
87 97
 			$this->db->free($resql);
@@ -104,7 +114,9 @@  discard block
 block discarded – undo
104 114
 		$sql = "SELECT id, code, libelle";
105 115
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_effectif";
106 116
 		$sql.= " WHERE active = 1";
107
-		if ($filter) $sql.=" ".$filter;
117
+		if ($filter) {
118
+			$sql.=" ".$filter;
119
+		}
108 120
 		$sql .= " ORDER BY id ASC";
109 121
 		dol_syslog(get_class($this).'::effectif_array', LOG_DEBUG);
110 122
 		$resql=$this->db->query($sql);
@@ -116,8 +128,11 @@  discard block
 block discarded – undo
116 128
 			while ($i < $num)
117 129
 			{
118 130
 				$objp = $this->db->fetch_object($resql);
119
-				if (! $mode) $key=$objp->id;
120
-				else $key=$objp->code;
131
+				if (! $mode) {
132
+					$key=$objp->id;
133
+				} else {
134
+					$key=$objp->code;
135
+				}
121 136
 
122 137
 				$effs[$key] = $objp->libelle!='-'?$objp->libelle:'';
123 138
 				$i++;
@@ -170,9 +185,12 @@  discard block
 block discarded – undo
170 185
 			}
171 186
 
172 187
 			print Form::selectarray($htmlname, $options, $selected);
188
+		} else {
189
+			dol_print_error($this->db);
190
+		}
191
+		if (! empty($htmlname) && $user->admin) {
192
+			print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
173 193
 		}
174
-		else dol_print_error($this->db);
175
-		if (! empty($htmlname) && $user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
176 194
 		print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
177 195
 		print '</form>';
178 196
 	}
@@ -222,16 +240,24 @@  discard block
 block discarded – undo
222 240
 		$sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
223 241
 		$sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
224 242
 		$sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
225
-		if ($country_codeid && is_numeric($country_codeid))   $sql .= " AND c.rowid = '".$country_codeid."'";
226
-		if ($country_codeid && ! is_numeric($country_codeid)) $sql .= " AND c.code = '".$country_codeid."'";
243
+		if ($country_codeid && is_numeric($country_codeid)) {
244
+			$sql .= " AND c.rowid = '".$country_codeid."'";
245
+		}
246
+		if ($country_codeid && ! is_numeric($country_codeid)) {
247
+			$sql .= " AND c.code = '".$country_codeid."'";
248
+		}
227 249
 		$sql .= " ORDER BY c.code, d.code_departement";
228 250
 
229 251
 		dol_syslog(get_class($this)."::select_departement", LOG_DEBUG);
230 252
 		$result=$this->db->query($sql);
231 253
 		if ($result)
232 254
 		{
233
-			if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
234
-			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';
255
+			if (!empty($htmlname)) {
256
+				$out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
257
+			}
258
+			if ($country_codeid) {
259
+				$out.= '<option value="0">&nbsp;</option>';
260
+			}
235 261
 			$num = $this->db->num_rows($result);
236 262
 			$i = 0;
237 263
 			dol_syslog(get_class($this)."::select_departement num=".$num,LOG_DEBUG);
@@ -241,11 +267,12 @@  discard block
 block discarded – undo
241 267
 				while ($i < $num)
242 268
 				{
243 269
 					$obj = $this->db->fetch_object($result);
244
-					if ($obj->code == '0')		// Le code peut etre une chaine
270
+					if ($obj->code == '0') {
271
+						// Le code peut etre une chaine
245 272
 					{
246 273
 						$out.= '<option value="0">&nbsp;</option>';
247 274
 					}
248
-					else {
275
+					} else {
249 276
 						if (! $country || $country != $obj->country)
250 277
 						{
251 278
 							// Affiche la rupture si on est en mode liste multipays
@@ -260,19 +287,16 @@  discard block
 block discarded – undo
260 287
 						 || (empty($selected) && ! empty($conf->global->MAIN_FORCE_DEFAULT_STATE_ID) && $conf->global->MAIN_FORCE_DEFAULT_STATE_ID == $obj->rowid))
261 288
 						{
262 289
 							$out.= '<option value="'.$obj->rowid.'" selected>';
263
-						}
264
-						else
290
+						} else
265 291
 						{
266 292
 							$out.= '<option value="'.$obj->rowid.'">';
267 293
 						}
268 294
 						// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
269 295
 						if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 2) {
270 296
 							$out.= $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
271
-						}
272
-						else if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 1) {
297
+						} else if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 1) {
273 298
 							$out.= $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
274
-						}
275
-						else {
299
+						} else {
276 300
 							$out.= $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
277 301
 						}
278 302
 						$out.= '</option>';
@@ -280,10 +304,13 @@  discard block
 block discarded – undo
280 304
 					$i++;
281 305
 				}
282 306
 			}
283
-			if (! empty($htmlname)) $out.= '</select>';
284
-			if (! empty($htmlname) && $user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
285
-		}
286
-		else
307
+			if (! empty($htmlname)) {
308
+				$out.= '</select>';
309
+			}
310
+			if (! empty($htmlname) && $user->admin) {
311
+				$out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
312
+			}
313
+		} else
287 314
 		{
288 315
 			dol_print_error($this->db);
289 316
 		}
@@ -331,8 +358,7 @@  discard block
 block discarded – undo
331 358
 					$obj = $this->db->fetch_object($resql);
332 359
 					if ($obj->code == 0) {
333 360
 						print '<option value="0">&nbsp;</option>';
334
-					}
335
-					else {
361
+					} else {
336 362
 						if ($country == '' || $country != $obj->country)
337 363
 						{
338 364
 							// Show break
@@ -345,8 +371,7 @@  discard block
 block discarded – undo
345 371
 						if ($selected > 0 && $selected == $obj->code)
346 372
 						{
347 373
 							print '<option value="'.$obj->code.'" selected>'.$obj->label.'</option>';
348
-						}
349
-						else
374
+						} else
350 375
 						{
351 376
 							print '<option value="'.$obj->code.'">'.$obj->label.'</option>';
352 377
 						}
@@ -355,8 +380,7 @@  discard block
 block discarded – undo
355 380
 				}
356 381
 			}
357 382
 			print '</select>';
358
-		}
359
-		else
383
+		} else
360 384
 		{
361 385
 			dol_print_error($this->db);
362 386
 		}
@@ -396,8 +420,7 @@  discard block
 block discarded – undo
396 420
 					if ($selected == $obj->code)
397 421
 					{
398 422
 						$out.= '<option value="'.$obj->code.'" selected>';
399
-					}
400
-					else
423
+					} else
401 424
 					{
402 425
 						$out.= '<option value="'.$obj->code.'">';
403 426
 					}
@@ -408,9 +431,10 @@  discard block
 block discarded – undo
408 431
 				}
409 432
 			}
410 433
 			$out.= '</select>';
411
-			if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
412
-		}
413
-		else
434
+			if ($user->admin) {
435
+				$out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
436
+			}
437
+		} else
414 438
 		{
415 439
 			dol_print_error($this->db);
416 440
 		}
@@ -456,8 +480,12 @@  discard block
 block discarded – undo
456 480
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c";
457 481
 		$sql .= " WHERE f.fk_pays=c.rowid";
458 482
 		$sql .= " AND f.active = 1 AND c.active = 1";
459
-		if ($country_codeid) $sql .= " AND c.code = '".$country_codeid."'";
460
-		if ($filter) $sql .= " ".$filter;
483
+		if ($country_codeid) {
484
+			$sql .= " AND c.code = '".$country_codeid."'";
485
+		}
486
+		if ($filter) {
487
+			$sql .= " ".$filter;
488
+		}
461 489
 		$sql .= " ORDER BY c.code";
462 490
 
463 491
 		dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG);
@@ -466,7 +494,10 @@  discard block
 block discarded – undo
466 494
 		{
467 495
 			$out.= '<div id="particulier2" class="visible">';
468 496
 			$out.= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
469
-			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';	// When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
497
+			if ($country_codeid) {
498
+				$out.= '<option value="0">&nbsp;</option>';
499
+			}
500
+			// When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
470 501
 
471 502
 			$num = $this->db->num_rows($resql);
472 503
 			if ($num)
@@ -477,9 +508,11 @@  discard block
 block discarded – undo
477 508
 				{
478 509
 					$obj = $this->db->fetch_object($resql);
479 510
 
480
-					if ($obj->code)		// We exclude empty line, we will add it later
511
+					if ($obj->code) {
512
+						// We exclude empty line, we will add it later
481 513
 					{
482 514
 						$labelcountry=(($langs->trans("Country".$obj->country_code)!="Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
515
+					}
483 516
 						$labeljs=(($langs->trans("JuridicalStatus".$obj->code)!="JuridicalStatus".$obj->code) ? $langs->trans("JuridicalStatus".$obj->code) : ($obj->label!='-'?$obj->label:''));	// $obj->label is already in output charset (converted by database driver)
484 517
 						$arraydata[$obj->code]=array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
485 518
 					}
@@ -487,10 +520,12 @@  discard block
 block discarded – undo
487 520
 				}
488 521
 
489 522
 				$arraydata=dol_sort_array($arraydata, 'label_sort', 'ASC');
490
-				if (empty($country_codeid))	// Introduce empty value (if $country_codeid not empty, empty value was already added)
523
+				if (empty($country_codeid)) {
524
+					// Introduce empty value (if $country_codeid not empty, empty value was already added)
491 525
 				{
492 526
 					$arraydata[0]=array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
493 527
 				}
528
+				}
494 529
 
495 530
 				foreach($arraydata as $key => $val)
496 531
 				{
@@ -507,8 +542,7 @@  discard block
 block discarded – undo
507 542
 					if ($selected > 0 && $selected == $val['code'])
508 543
 					{
509 544
 						$out.= '<option value="'.$val['code'].'" selected>';
510
-					}
511
-					else
545
+					} else
512 546
 					{
513 547
 						$out.= '<option value="'.$val['code'].'">';
514 548
 					}
@@ -518,15 +552,16 @@  discard block
 block discarded – undo
518 552
 				}
519 553
 			}
520 554
 			$out.= '</select>';
521
-			if ($user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
555
+			if ($user->admin) {
556
+				$out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
557
+			}
522 558
 
523 559
 		    // Make select dynamic
524 560
         	include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
525 561
 	        $out .= ajax_combobox($htmlname);
526 562
 
527 563
 			$out.= '</div>';
528
-		}
529
-		else
564
+		} else
530 565
 		{
531 566
 			dol_print_error($this->db);
532 567
 		}
@@ -577,7 +612,8 @@  discard block
 block discarded – undo
577 612
 			// To refresh contacts list on thirdparty list change
578 613
 			$events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
579 614
 
580
-			if (count($events))	// If there is some ajax events to run once selection is done, we add code here to run events
615
+			if (count($events)) {
616
+				// If there is some ajax events to run once selection is done, we add code here to run events
581 617
 			{
582 618
 				print '<script type="text/javascript">
583 619
 				jQuery(document).ready(function() {
@@ -627,13 +663,13 @@  discard block
 block discarded – undo
627 663
 				});
628 664
 				</script>';
629 665
 			}
666
+			}
630 667
 
631 668
 			print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
632 669
 			print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />';
633 670
 			print ajax_autocompleter(($socid?$socid:-1), $htmlname, DOL_URL_ROOT.'/societe/ajaxcompanies.php', '', $minLength, 0);
634 671
 			return $socid;
635
-		}
636
-		else
672
+		} else
637 673
 		{
638 674
 			// Search to list thirdparties
639 675
 			$sql = "SELECT s.rowid, s.nom as name FROM";
@@ -663,20 +699,27 @@  discard block
 block discarded – undo
663 699
 					while ($i < $num)
664 700
 					{
665 701
 						$obj = $this->db->fetch_object($resql);
666
-						if ($i == 0) $firstCompany = $obj->rowid;
702
+						if ($i == 0) {
703
+							$firstCompany = $obj->rowid;
704
+						}
667 705
 						$disabled=0;
668
-						if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
706
+						if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) {
707
+							$disabled=1;
708
+						}
669 709
 						if ($selected > 0 && $selected == $obj->rowid)
670 710
 						{
671 711
 							print '<option value="'.$obj->rowid.'"';
672
-							if ($disabled) print ' disabled';
712
+							if ($disabled) {
713
+								print ' disabled';
714
+							}
673 715
 							print ' selected>'.dol_trunc($obj->name,24).'</option>';
674 716
 							$firstCompany = $obj->rowid;
675
-						}
676
-						else
717
+						} else
677 718
 						{
678 719
 							print '<option value="'.$obj->rowid.'"';
679
-							if ($disabled) print ' disabled';
720
+							if ($disabled) {
721
+								print ' disabled';
722
+							}
680 723
 							print '>'.dol_trunc($obj->name,24).'</option>';
681 724
 						}
682 725
 						$i ++;
@@ -684,8 +727,7 @@  discard block
 block discarded – undo
684 727
 				}
685 728
 				print "</select>\n";
686 729
 				return $firstCompany;
687
-			}
688
-			else
730
+			} else
689 731
 			{
690 732
 				dol_print_error($this->db);
691 733
 				print 'Error sql';
@@ -713,15 +755,21 @@  discard block
 block discarded – undo
713 755
 		{
714 756
 			$lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
715 757
 			print '<select class="flat valignmiddle'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
716
-			if ($showempty) print '<option value="0"></option>';
758
+			if ($showempty) {
759
+				print '<option value="0"></option>';
760
+			}
717 761
 			foreach($lesTypes as $key=>$value)
718 762
 			{
719 763
 				print '<option value="'.$key.'"';
720
-				if ($key == $selected) print ' selected';
764
+				if ($key == $selected) {
765
+					print ' selected';
766
+				}
721 767
 				print '>'.$value.'</option>';
722 768
 			}
723 769
 			print "</select>";
724
-			if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
770
+			if ($user->admin) {
771
+				print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
772
+			}
725 773
 			print "\n";
726 774
 		}
727 775
 	}
@@ -745,7 +793,9 @@  discard block
 block discarded – undo
745 793
 		$out='';
746 794
 
747 795
 		$size='';
748
-		if (!empty($fieldsize)) $size='size="'.$fieldsize.'"';
796
+		if (!empty($fieldsize)) {
797
+			$size='size="'.$fieldsize.'"';
798
+		}
749 799
 
750 800
 		if ($conf->use_javascript_ajax && empty($disableautocomplete))
751 801
 		{
@@ -776,27 +826,51 @@  discard block
 block discarded – undo
776 826
         	if ($country_code == 'FR')
777 827
         	{
778 828
         		if (isset($idprof)) {
779
-        			if ($idprof==1) $formlength=9;
780
-        			else if ($idprof==2) $formlength=14;
781
-        			else if ($idprof==3) $formlength=5;      // 4 chiffres et 1 lettre depuis janvier
782
-        			else if ($idprof==4) $formlength=32;     // No maximum as we need to include a town name in this id
829
+        			if ($idprof==1) {
830
+        				$formlength=9;
831
+        			} else if ($idprof==2) {
832
+        				$formlength=14;
833
+        			} else if ($idprof==3) {
834
+        				$formlength=5;
835
+        			}
836
+        			// 4 chiffres et 1 lettre depuis janvier
837
+        			else if ($idprof==4) {
838
+        				$formlength=32;
839
+        			}
840
+        			// No maximum as we need to include a town name in this id
783 841
         		}
784
-        	}
785
-        	else if ($country_code == 'ES')
842
+        	} else if ($country_code == 'ES')
786 843
         	{
787
-        		if ($idprof==1) $formlength=9;  //CIF/NIF/NIE 9 digits
788
-        		if ($idprof==2) $formlength=12; //NASS 12 digits without /
789
-        		if ($idprof==3) $formlength=5;  //CNAE 5 digits
790
-        		if ($idprof==4) $formlength=32; //depend of college
844
+        		if ($idprof==1) {
845
+        			$formlength=9;
846
+        		}
847
+        		//CIF/NIF/NIE 9 digits
848
+        		if ($idprof==2) {
849
+        			$formlength=12;
850
+        		}
851
+        		//NASS 12 digits without /
852
+        		if ($idprof==3) {
853
+        			$formlength=5;
854
+        		}
855
+        		//CNAE 5 digits
856
+        		if ($idprof==4) {
857
+        			$formlength=32;
858
+        		}
859
+        		//depend of college
791 860
         	}
792 861
         }
793 862
 
794 863
         $selected=$preselected;
795 864
         if (! $selected && isset($idprof)) {
796
-        	if ($idprof==1 && ! empty($this->idprof1)) $selected=$this->idprof1;
797
-        	else if ($idprof==2 && ! empty($this->idprof2)) $selected=$this->idprof2;
798
-        	else if ($idprof==3 && ! empty($this->idprof3)) $selected=$this->idprof3;
799
-        	else if ($idprof==4 && ! empty($this->idprof4)) $selected=$this->idprof4;
865
+        	if ($idprof==1 && ! empty($this->idprof1)) {
866
+        		$selected=$this->idprof1;
867
+        	} else if ($idprof==2 && ! empty($this->idprof2)) {
868
+        		$selected=$this->idprof2;
869
+        	} else if ($idprof==3 && ! empty($this->idprof3)) {
870
+        		$selected=$this->idprof3;
871
+        	} else if ($idprof==4 && ! empty($this->idprof4)) {
872
+        		$selected=$this->idprof4;
873
+        	}
800 874
         }
801 875
 
802 876
         $maxlength=$formlength;
@@ -834,8 +908,7 @@  discard block
 block discarded – undo
834 908
     				if ($selected == $valors[$i])
835 909
     				{
836 910
     					print '<option value="'.$valors[$i].'" selected>';
837
-    				}
838
-    				else
911
+    				} else
839 912
     				{
840 913
     					print '<option value="'.$valors[$i].'">';
841 914
     				}
Please login to merge, or discard this patch.
htdocs/holiday/class/holiday.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1067,7 +1067,7 @@
 block discarded – undo
1067 1067
      *  Supprime un utilisateur du module Congés Payés
1068 1068
      *
1069 1069
      *  @param	int		$user_id        ID de l'utilisateur à supprimer
1070
-     *  @return boolean      			Vrai si pas d'erreur, faut si Erreur
1070
+     *  @return boolean|null      			Vrai si pas d'erreur, faut si Erreur
1071 1071
      */
1072 1072
     function deleteCPuser($user_id) {
1073 1073
 
Please login to merge, or discard this patch.
Indentation   +1603 added lines, -1603 removed lines patch added patch discarded remove patch
@@ -36,277 +36,403 @@  discard block
 block discarded – undo
36 36
 	public $table_element='holiday';
37 37
 	protected $isnolinkedbythird = 1;     // No field fk_soc
38 38
 	protected $ismultientitymanaged = 0;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
39
-    public $picto = 'holiday';
39
+	public $picto = 'holiday';
40 40
 
41 41
 	/**
42 42
 	 * @deprecated
43 43
 	 * @see id
44 44
 	 */
45
-    var $rowid;
46
-
47
-    var $fk_user;
48
-    var $date_create='';
49
-    var $description;
50
-    var $date_debut='';			// Date start in PHP server TZ
51
-    var $date_fin='';			// Date end in PHP server TZ
52
-    var $date_debut_gmt='';		// Date start in GMT
53
-    var $date_fin_gmt='';		// Date end in GMT
54
-    var $halfday='';
55
-    var $statut='';				// 1=draft, 2=validated, 3=approved
56
-    var $fk_validator;
57
-    var $date_valid='';
58
-    var $fk_user_valid;
59
-    var $date_refuse='';
60
-    var $fk_user_refuse;
61
-    var $date_cancel='';
62
-    var $fk_user_cancel;
63
-    var $detail_refuse='';
64
-    var $fk_type;
65
-
66
-    var $holiday = array();
67
-    var $events = array();
68
-    var $logs = array();
69
-
70
-    var $optName = '';
71
-    var $optValue = '';
72
-    var $optRowid = '';
73
-
74
-
75
-    /**
76
-     *   Constructor
77
-     *
78
-     *   @param		DoliDB		$db      Database handler
79
-     */
80
-    function __construct($db)
81
-    {
82
-        $this->db = $db;
83
-    }
84
-
85
-
86
-    /**
87
-     * Update balance of vacations and check table of users for holidays is complete. If not complete.
88
-     *
89
-     * @return	int			<0 if KO, >0 if OK
90
-     */
91
-    function updateBalance()
92
-    {
93
-    	$this->db->begin();
94
-
95
-	    // Update sold of vocations
96
-	    $result = $this->updateSoldeCP();
97
-
98
-	    // Check nb of users into table llx_holiday_users and update with empty lines
99
-	    //if ($result > 0) $result = $this->verifNbUsers($this->countActiveUsersWithoutCP(), $this->getConfCP('nbUser'));
100
-
101
-	    if ($result >= 0)
102
-	    {
103
-	    	$this->db->commit();
104
-	    	return 1;
105
-	    }
106
-	    else
45
+	var $rowid;
46
+
47
+	var $fk_user;
48
+	var $date_create='';
49
+	var $description;
50
+	var $date_debut='';			// Date start in PHP server TZ
51
+	var $date_fin='';			// Date end in PHP server TZ
52
+	var $date_debut_gmt='';		// Date start in GMT
53
+	var $date_fin_gmt='';		// Date end in GMT
54
+	var $halfday='';
55
+	var $statut='';				// 1=draft, 2=validated, 3=approved
56
+	var $fk_validator;
57
+	var $date_valid='';
58
+	var $fk_user_valid;
59
+	var $date_refuse='';
60
+	var $fk_user_refuse;
61
+	var $date_cancel='';
62
+	var $fk_user_cancel;
63
+	var $detail_refuse='';
64
+	var $fk_type;
65
+
66
+	var $holiday = array();
67
+	var $events = array();
68
+	var $logs = array();
69
+
70
+	var $optName = '';
71
+	var $optValue = '';
72
+	var $optRowid = '';
73
+
74
+
75
+	/**
76
+	 *   Constructor
77
+	 *
78
+	 *   @param		DoliDB		$db      Database handler
79
+	 */
80
+	function __construct($db)
81
+	{
82
+		$this->db = $db;
83
+	}
84
+
85
+
86
+	/**
87
+	 * Update balance of vacations and check table of users for holidays is complete. If not complete.
88
+	 *
89
+	 * @return	int			<0 if KO, >0 if OK
90
+	 */
91
+	function updateBalance()
92
+	{
93
+		$this->db->begin();
94
+
95
+		// Update sold of vocations
96
+		$result = $this->updateSoldeCP();
97
+
98
+		// Check nb of users into table llx_holiday_users and update with empty lines
99
+		//if ($result > 0) $result = $this->verifNbUsers($this->countActiveUsersWithoutCP(), $this->getConfCP('nbUser'));
100
+
101
+		if ($result >= 0)
102
+		{
103
+			$this->db->commit();
104
+			return 1;
105
+		}
106
+		else
107
+		{
108
+			$this->db->rollback();
109
+			return -1;
110
+		}
111
+	}
112
+
113
+	/**
114
+	 *   Créer un congés payés dans la base de données
115
+	 *
116
+	 *   @param		User	$user        	User that create
117
+	 *   @param     int		$notrigger	    0=launch triggers after, 1=disable triggers
118
+	 *   @return    int			         	<0 if KO, Id of created object if OK
119
+	 */
120
+	function create($user, $notrigger=0)
121
+	{
122
+		global $conf;
123
+		$error=0;
124
+
125
+		$now=dol_now();
126
+
127
+		// Check parameters
128
+		if (empty($this->fk_user) || ! is_numeric($this->fk_user) || $this->fk_user < 0) { $this->error="ErrorBadParameterFkUser"; return -1; }
129
+		if (empty($this->fk_validator) || ! is_numeric($this->fk_validator) || $this->fk_validator < 0)  { $this->error="ErrorBadParameterFkValidator"; return -1; }
130
+		if (empty($this->fk_type) || ! is_numeric($this->fk_type) || $this->fk_type < 0) { $this->error="ErrorBadParameterFkType"; return -1; }
131
+
132
+		// Insert request
133
+		$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday(";
134
+		$sql.= "fk_user,";
135
+		$sql.= "date_create,";
136
+		$sql.= "description,";
137
+		$sql.= "date_debut,";
138
+		$sql.= "date_fin,";
139
+		$sql.= "halfday,";
140
+		$sql.= "statut,";
141
+		$sql.= "fk_validator,";
142
+		$sql.= "fk_type,";
143
+		$sql.= "fk_user_create,";
144
+		$sql.= "entity";
145
+		$sql.= ") VALUES (";
146
+		$sql.= "'".$this->db->escape($this->fk_user)."',";
147
+		$sql.= " '".$this->db->idate($now)."',";
148
+		$sql.= " '".$this->db->escape($this->description)."',";
149
+		$sql.= " '".$this->db->idate($this->date_debut)."',";
150
+		$sql.= " '".$this->db->idate($this->date_fin)."',";
151
+		$sql.= " ".$this->halfday.",";
152
+		$sql.= " '1',";
153
+		$sql.= " '".$this->db->escape($this->fk_validator)."',";
154
+		$sql.= " ".$this->fk_type.",";
155
+		$sql.= " ".$user->id.",";
156
+		$sql.= " ".$conf->entity;
157
+		$sql.= ")";
158
+
159
+		$this->db->begin();
160
+
161
+		dol_syslog(get_class($this)."::create", LOG_DEBUG);
162
+		$resql=$this->db->query($sql);
163
+		if (! $resql) {
164
+			$error++; $this->errors[]="Error ".$this->db->lasterror();
165
+		}
166
+
167
+		if (! $error)
168
+		{
169
+			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday");
170
+
171
+			if (! $notrigger)
172
+			{
173
+				// Call trigger
174
+				$result=$this->call_trigger('HOLIDAY_CREATE',$user);
175
+				if ($result < 0) { $error++; }
176
+				// End call triggers
177
+			}
178
+		}
179
+
180
+		// Commit or rollback
181
+		if ($error)
182
+		{
183
+			foreach($this->errors as $errmsg)
184
+			{
185
+				dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
186
+				$this->error.=($this->error?', '.$errmsg:$errmsg);
187
+			}
188
+			$this->db->rollback();
189
+			return -1*$error;
190
+		}
191
+		else
192
+		{
193
+			$this->db->commit();
194
+			return $this->id;
195
+		}
196
+	}
197
+
198
+
199
+	/**
200
+	 *	Load object in memory from database
201
+	 *
202
+	 *  @param	int		$id         Id object
203
+	 *  @return int         		<0 if KO, >0 if OK
204
+	 */
205
+	function fetch($id)
206
+	{
207
+		global $langs;
208
+
209
+		$sql = "SELECT";
210
+		$sql.= " cp.rowid,";
211
+		$sql.= " cp.fk_user,";
212
+		$sql.= " cp.date_create,";
213
+		$sql.= " cp.description,";
214
+		$sql.= " cp.date_debut,";
215
+		$sql.= " cp.date_fin,";
216
+		$sql.= " cp.halfday,";
217
+		$sql.= " cp.statut,";
218
+		$sql.= " cp.fk_validator,";
219
+		$sql.= " cp.date_valid,";
220
+		$sql.= " cp.fk_user_valid,";
221
+		$sql.= " cp.date_refuse,";
222
+		$sql.= " cp.fk_user_refuse,";
223
+		$sql.= " cp.date_cancel,";
224
+		$sql.= " cp.fk_user_cancel,";
225
+		$sql.= " cp.detail_refuse,";
226
+		$sql.= " cp.note_private,";
227
+		$sql.= " cp.note_public,";
228
+		$sql.= " cp.fk_user_create,";
229
+		$sql.= " cp.fk_type,";
230
+		$sql.= " cp.entity";
231
+		$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp";
232
+		$sql.= " WHERE cp.rowid = ".$id;
233
+
234
+		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
235
+		$resql=$this->db->query($sql);
236
+		if ($resql)
237
+		{
238
+			if ($this->db->num_rows($resql))
239
+			{
240
+				$obj = $this->db->fetch_object($resql);
241
+
242
+				$this->id    = $obj->rowid;
243
+				$this->rowid = $obj->rowid;	// deprecated
244
+				$this->ref   = $obj->rowid;
245
+				$this->fk_user = $obj->fk_user;
246
+				$this->date_create = $this->db->jdate($obj->date_create);
247
+				$this->description = $obj->description;
248
+				$this->date_debut = $this->db->jdate($obj->date_debut);
249
+				$this->date_fin = $this->db->jdate($obj->date_fin);
250
+				$this->date_debut_gmt = $this->db->jdate($obj->date_debut,1);
251
+				$this->date_fin_gmt = $this->db->jdate($obj->date_fin,1);
252
+				$this->halfday = $obj->halfday;
253
+				$this->statut = $obj->statut;
254
+				$this->fk_validator = $obj->fk_validator;
255
+				$this->date_valid = $this->db->jdate($obj->date_valid);
256
+				$this->fk_user_valid = $obj->fk_user_valid;
257
+				$this->date_refuse = $this->db->jdate($obj->date_refuse);
258
+				$this->fk_user_refuse = $obj->fk_user_refuse;
259
+				$this->date_cancel = $this->db->jdate($obj->date_cancel);
260
+				$this->fk_user_cancel = $obj->fk_user_cancel;
261
+				$this->detail_refuse = $obj->detail_refuse;
262
+				$this->note_private = $obj->note_private;
263
+				$this->note_public = $obj->note_public;
264
+				$this->fk_user_create = $obj->fk_user_create;
265
+				$this->fk_type = $obj->fk_type;
266
+				$this->entity = $obj->entity;
267
+			}
268
+			$this->db->free($resql);
269
+
270
+			return 1;
271
+		}
272
+		else
273
+		{
274
+			$this->error="Error ".$this->db->lasterror();
275
+			return -1;
276
+		}
277
+	}
278
+
279
+	/**
280
+	 *	List holidays for a particular user
281
+	 *
282
+	 *  @param		int		$user_id    ID of user to list
283
+	 *  @param      string	$order      Sort order
284
+	 *  @param      string	$filter     SQL Filter
285
+	 *  @return     int      			-1 if KO, 1 if OK, 2 if no result
286
+	 */
287
+	function fetchByUser($user_id, $order='', $filter='')
288
+	{
289
+		global $langs, $conf;
290
+
291
+		$sql = "SELECT";
292
+		$sql.= " cp.rowid,";
293
+
294
+		$sql.= " cp.fk_user,";
295
+		$sql.= " cp.fk_type,";
296
+		$sql.= " cp.date_create,";
297
+		$sql.= " cp.description,";
298
+		$sql.= " cp.date_debut,";
299
+		$sql.= " cp.date_fin,";
300
+		$sql.= " cp.halfday,";
301
+		$sql.= " cp.statut,";
302
+		$sql.= " cp.fk_validator,";
303
+		$sql.= " cp.date_valid,";
304
+		$sql.= " cp.fk_user_valid,";
305
+		$sql.= " cp.date_refuse,";
306
+		$sql.= " cp.fk_user_refuse,";
307
+		$sql.= " cp.date_cancel,";
308
+		$sql.= " cp.fk_user_cancel,";
309
+		$sql.= " cp.detail_refuse,";
310
+
311
+		$sql.= " uu.lastname as user_lastname,";
312
+		$sql.= " uu.firstname as user_firstname,";
313
+		$sql.= " uu.login as user_login,";
314
+		$sql.= " uu.statut as user_statut,";
315
+		$sql.= " uu.photo as user_photo,";
316
+
317
+		$sql.= " ua.lastname as validator_lastname,";
318
+		$sql.= " ua.firstname as validator_firstname,";
319
+		$sql.= " ua.login as validator_login,";
320
+		$sql.= " ua.statut as validator_statut,";
321
+		$sql.= " ua.photo as validator_photo";
322
+
323
+		$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
324
+		$sql.= " WHERE cp.entity IN (".getEntity('holiday').")";
325
+		$sql.= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
326
+		$sql.= " AND cp.fk_user = ".$user_id;
327
+
328
+		// Filtre de séléction
329
+		if(!empty($filter)) {
330
+			$sql.= $filter;
331
+		}
332
+
333
+		// Ordre d'affichage du résultat
334
+		if(!empty($order)) {
335
+			$sql.= $order;
336
+		}
337
+
338
+		dol_syslog(get_class($this)."::fetchByUser", LOG_DEBUG);
339
+		$resql=$this->db->query($sql);
340
+
341
+		// Si pas d'erreur SQL
342
+		if ($resql) {
343
+
344
+			$i = 0;
345
+			$tab_result = $this->holiday;
346
+			$num = $this->db->num_rows($resql);
347
+
348
+			// Si pas d'enregistrement
349
+			if(!$num) {
350
+				return 2;
351
+			}
352
+
353
+			// Liste les enregistrements et les ajoutent au tableau
354
+			while($i < $num) {
355
+
356
+				$obj = $this->db->fetch_object($resql);
357
+
358
+				$tab_result[$i]['rowid'] = $obj->rowid;
359
+				$tab_result[$i]['ref'] = $obj->rowid;
360
+				$tab_result[$i]['fk_user'] = $obj->fk_user;
361
+				$tab_result[$i]['fk_type'] = $obj->fk_type;
362
+				$tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
363
+				$tab_result[$i]['description'] = $obj->description;
364
+				$tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
365
+				$tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
366
+				$tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut,1);
367
+				$tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin,1);
368
+				$tab_result[$i]['halfday'] = $obj->halfday;
369
+				$tab_result[$i]['statut'] = $obj->statut;
370
+				$tab_result[$i]['fk_validator'] = $obj->fk_validator;
371
+				$tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid);
372
+				$tab_result[$i]['fk_user_valid'] = $obj->fk_user_valid;
373
+				$tab_result[$i]['date_refuse'] = $this->db->jdate($obj->date_refuse);
374
+				$tab_result[$i]['fk_user_refuse'] = $obj->fk_user_refuse;
375
+				$tab_result[$i]['date_cancel'] = $this->db->jdate($obj->date_cancel);
376
+				$tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
377
+				$tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
378
+
379
+				$tab_result[$i]['user_firstname'] = $obj->user_firstname;
380
+				$tab_result[$i]['user_lastname'] = $obj->user_lastname;
381
+				$tab_result[$i]['user_login'] = $obj->user_login;
382
+				$tab_result[$i]['user_statut'] = $obj->user_statut;
383
+				$tab_result[$i]['user_photo'] = $obj->user_photo;
384
+
385
+				$tab_result[$i]['validator_firstname'] = $obj->validator_firstname;
386
+				$tab_result[$i]['validator_lastname'] = $obj->validator_lastname;
387
+				$tab_result[$i]['validator_login'] = $obj->validator_login;
388
+				$tab_result[$i]['validator_statut'] = $obj->validator_statut;
389
+				$tab_result[$i]['validator_photo'] = $obj->validator_photo;
390
+
391
+				$i++;
392
+			}
393
+
394
+			// Retourne 1 avec le tableau rempli
395
+			$this->holiday = $tab_result;
396
+			return 1;
397
+		}
398
+		else
107 399
 		{
108
-	    	$this->db->rollback();
109
-	    	return -1;
400
+			// Erreur SQL
401
+			$this->error="Error ".$this->db->lasterror();
402
+			return -1;
110 403
 		}
111
-    }
112
-
113
-    /**
114
-     *   Créer un congés payés dans la base de données
115
-     *
116
-     *   @param		User	$user        	User that create
117
-     *   @param     int		$notrigger	    0=launch triggers after, 1=disable triggers
118
-     *   @return    int			         	<0 if KO, Id of created object if OK
119
-     */
120
-    function create($user, $notrigger=0)
121
-    {
122
-        global $conf;
123
-        $error=0;
124
-
125
-        $now=dol_now();
126
-
127
-        // Check parameters
128
-        if (empty($this->fk_user) || ! is_numeric($this->fk_user) || $this->fk_user < 0) { $this->error="ErrorBadParameterFkUser"; return -1; }
129
-        if (empty($this->fk_validator) || ! is_numeric($this->fk_validator) || $this->fk_validator < 0)  { $this->error="ErrorBadParameterFkValidator"; return -1; }
130
-        if (empty($this->fk_type) || ! is_numeric($this->fk_type) || $this->fk_type < 0) { $this->error="ErrorBadParameterFkType"; return -1; }
131
-
132
-        // Insert request
133
-        $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday(";
134
-        $sql.= "fk_user,";
135
-        $sql.= "date_create,";
136
-        $sql.= "description,";
137
-        $sql.= "date_debut,";
138
-        $sql.= "date_fin,";
139
-        $sql.= "halfday,";
140
-        $sql.= "statut,";
141
-        $sql.= "fk_validator,";
142
-        $sql.= "fk_type,";
143
-        $sql.= "fk_user_create,";
144
-        $sql.= "entity";
145
-        $sql.= ") VALUES (";
146
-        $sql.= "'".$this->db->escape($this->fk_user)."',";
147
-        $sql.= " '".$this->db->idate($now)."',";
148
-        $sql.= " '".$this->db->escape($this->description)."',";
149
-        $sql.= " '".$this->db->idate($this->date_debut)."',";
150
-        $sql.= " '".$this->db->idate($this->date_fin)."',";
151
-        $sql.= " ".$this->halfday.",";
152
-        $sql.= " '1',";
153
-        $sql.= " '".$this->db->escape($this->fk_validator)."',";
154
-        $sql.= " ".$this->fk_type.",";
155
-        $sql.= " ".$user->id.",";
156
-        $sql.= " ".$conf->entity;
157
-        $sql.= ")";
158
-
159
-        $this->db->begin();
160
-
161
-        dol_syslog(get_class($this)."::create", LOG_DEBUG);
162
-        $resql=$this->db->query($sql);
163
-        if (! $resql) {
164
-            $error++; $this->errors[]="Error ".$this->db->lasterror();
165
-        }
166
-
167
-        if (! $error)
168
-        {
169
-            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday");
170
-
171
-            if (! $notrigger)
172
-            {
173
-                // Call trigger
174
-                $result=$this->call_trigger('HOLIDAY_CREATE',$user);
175
-                if ($result < 0) { $error++; }
176
-                // End call triggers
177
-            }
178
-        }
179
-
180
-        // Commit or rollback
181
-        if ($error)
182
-        {
183
-            foreach($this->errors as $errmsg)
184
-            {
185
-                dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
186
-                $this->error.=($this->error?', '.$errmsg:$errmsg);
187
-            }
188
-            $this->db->rollback();
189
-            return -1*$error;
190
-        }
191
-        else
192
-        {
193
-            $this->db->commit();
194
-            return $this->id;
195
-        }
196
-    }
197
-
198
-
199
-    /**
200
-     *	Load object in memory from database
201
-     *
202
-     *  @param	int		$id         Id object
203
-     *  @return int         		<0 if KO, >0 if OK
204
-     */
205
-    function fetch($id)
206
-    {
207
-        global $langs;
208
-
209
-        $sql = "SELECT";
210
-        $sql.= " cp.rowid,";
211
-        $sql.= " cp.fk_user,";
212
-        $sql.= " cp.date_create,";
213
-        $sql.= " cp.description,";
214
-        $sql.= " cp.date_debut,";
215
-        $sql.= " cp.date_fin,";
216
-        $sql.= " cp.halfday,";
217
-        $sql.= " cp.statut,";
218
-        $sql.= " cp.fk_validator,";
219
-        $sql.= " cp.date_valid,";
220
-        $sql.= " cp.fk_user_valid,";
221
-        $sql.= " cp.date_refuse,";
222
-        $sql.= " cp.fk_user_refuse,";
223
-        $sql.= " cp.date_cancel,";
224
-        $sql.= " cp.fk_user_cancel,";
225
-        $sql.= " cp.detail_refuse,";
226
-        $sql.= " cp.note_private,";
227
-        $sql.= " cp.note_public,";
228
-        $sql.= " cp.fk_user_create,";
229
-        $sql.= " cp.fk_type,";
230
-        $sql.= " cp.entity";
231
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp";
232
-        $sql.= " WHERE cp.rowid = ".$id;
233
-
234
-        dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
235
-        $resql=$this->db->query($sql);
236
-        if ($resql)
237
-        {
238
-            if ($this->db->num_rows($resql))
239
-            {
240
-                $obj = $this->db->fetch_object($resql);
241
-
242
-                $this->id    = $obj->rowid;
243
-                $this->rowid = $obj->rowid;	// deprecated
244
-                $this->ref   = $obj->rowid;
245
-                $this->fk_user = $obj->fk_user;
246
-                $this->date_create = $this->db->jdate($obj->date_create);
247
-                $this->description = $obj->description;
248
-                $this->date_debut = $this->db->jdate($obj->date_debut);
249
-                $this->date_fin = $this->db->jdate($obj->date_fin);
250
-                $this->date_debut_gmt = $this->db->jdate($obj->date_debut,1);
251
-                $this->date_fin_gmt = $this->db->jdate($obj->date_fin,1);
252
-                $this->halfday = $obj->halfday;
253
-                $this->statut = $obj->statut;
254
-                $this->fk_validator = $obj->fk_validator;
255
-                $this->date_valid = $this->db->jdate($obj->date_valid);
256
-                $this->fk_user_valid = $obj->fk_user_valid;
257
-                $this->date_refuse = $this->db->jdate($obj->date_refuse);
258
-                $this->fk_user_refuse = $obj->fk_user_refuse;
259
-                $this->date_cancel = $this->db->jdate($obj->date_cancel);
260
-                $this->fk_user_cancel = $obj->fk_user_cancel;
261
-                $this->detail_refuse = $obj->detail_refuse;
262
-                $this->note_private = $obj->note_private;
263
-                $this->note_public = $obj->note_public;
264
-                $this->fk_user_create = $obj->fk_user_create;
265
-                $this->fk_type = $obj->fk_type;
266
-                $this->entity = $obj->entity;
267
-            }
268
-            $this->db->free($resql);
269
-
270
-            return 1;
271
-        }
272
-        else
273
-        {
274
-            $this->error="Error ".$this->db->lasterror();
275
-            return -1;
276
-        }
277
-    }
278
-
279
-    /**
280
-     *	List holidays for a particular user
281
-     *
282
-     *  @param		int		$user_id    ID of user to list
283
-     *  @param      string	$order      Sort order
284
-     *  @param      string	$filter     SQL Filter
285
-     *  @return     int      			-1 if KO, 1 if OK, 2 if no result
286
-     */
287
-    function fetchByUser($user_id, $order='', $filter='')
288
-    {
289
-        global $langs, $conf;
290
-
291
-        $sql = "SELECT";
292
-        $sql.= " cp.rowid,";
293
-
294
-        $sql.= " cp.fk_user,";
404
+	}
405
+
406
+	/**
407
+	 *	List all holidays of all users
408
+	 *
409
+	 *  @param      string	$order      Sort order
410
+	 *  @param      string	$filter     SQL Filter
411
+	 *  @return     int      			-1 if KO, 1 if OK, 2 if no result
412
+	 */
413
+	function fetchAll($order,$filter)
414
+	{
415
+		global $langs;
416
+
417
+		$sql = "SELECT";
418
+		$sql.= " cp.rowid,";
419
+
420
+		$sql.= " cp.fk_user,";
295 421
 		$sql.= " cp.fk_type,";
296 422
 		$sql.= " cp.date_create,";
297
-        $sql.= " cp.description,";
298
-        $sql.= " cp.date_debut,";
299
-        $sql.= " cp.date_fin,";
300
-        $sql.= " cp.halfday,";
301
-        $sql.= " cp.statut,";
302
-        $sql.= " cp.fk_validator,";
303
-        $sql.= " cp.date_valid,";
304
-        $sql.= " cp.fk_user_valid,";
305
-        $sql.= " cp.date_refuse,";
306
-        $sql.= " cp.fk_user_refuse,";
307
-        $sql.= " cp.date_cancel,";
308
-        $sql.= " cp.fk_user_cancel,";
309
-        $sql.= " cp.detail_refuse,";
423
+		$sql.= " cp.description,";
424
+		$sql.= " cp.date_debut,";
425
+		$sql.= " cp.date_fin,";
426
+		$sql.= " cp.halfday,";
427
+		$sql.= " cp.statut,";
428
+		$sql.= " cp.fk_validator,";
429
+		$sql.= " cp.date_valid,";
430
+		$sql.= " cp.fk_user_valid,";
431
+		$sql.= " cp.date_refuse,";
432
+		$sql.= " cp.fk_user_refuse,";
433
+		$sql.= " cp.date_cancel,";
434
+		$sql.= " cp.fk_user_cancel,";
435
+		$sql.= " cp.detail_refuse,";
310 436
 
311 437
 		$sql.= " uu.lastname as user_lastname,";
312 438
 		$sql.= " uu.firstname as user_firstname,";
@@ -314,553 +440,427 @@  discard block
 block discarded – undo
314 440
 		$sql.= " uu.statut as user_statut,";
315 441
 		$sql.= " uu.photo as user_photo,";
316 442
 
317
-        $sql.= " ua.lastname as validator_lastname,";
318
-        $sql.= " ua.firstname as validator_firstname,";
319
-        $sql.= " ua.login as validator_login,";
320
-        $sql.= " ua.statut as validator_statut,";
321
-        $sql.= " ua.photo as validator_photo";
443
+		$sql.= " ua.lastname as validator_lastname,";
444
+		$sql.= " ua.firstname as validator_firstname,";
445
+		$sql.= " ua.login as validator_login,";
446
+		$sql.= " ua.statut as validator_statut,";
447
+		$sql.= " ua.photo as validator_photo";
322 448
 
323
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
324
-        $sql.= " WHERE cp.entity IN (".getEntity('holiday').")";
449
+		$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
450
+		$sql.= " WHERE cp.entity IN (".getEntity('holiday').")";
325 451
 		$sql.= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
326
-        $sql.= " AND cp.fk_user = ".$user_id;
327
-
328
-        // Filtre de séléction
329
-        if(!empty($filter)) {
330
-            $sql.= $filter;
331
-        }
332
-
333
-        // Ordre d'affichage du résultat
334
-        if(!empty($order)) {
335
-            $sql.= $order;
336
-        }
337
-
338
-        dol_syslog(get_class($this)."::fetchByUser", LOG_DEBUG);
339
-        $resql=$this->db->query($sql);
340
-
341
-        // Si pas d'erreur SQL
342
-        if ($resql) {
343
-
344
-            $i = 0;
345
-            $tab_result = $this->holiday;
346
-            $num = $this->db->num_rows($resql);
347
-
348
-            // Si pas d'enregistrement
349
-            if(!$num) {
350
-                return 2;
351
-            }
352
-
353
-            // Liste les enregistrements et les ajoutent au tableau
354
-            while($i < $num) {
355
-
356
-                $obj = $this->db->fetch_object($resql);
357
-
358
-                $tab_result[$i]['rowid'] = $obj->rowid;
359
-                $tab_result[$i]['ref'] = $obj->rowid;
360
-                $tab_result[$i]['fk_user'] = $obj->fk_user;
361
-                $tab_result[$i]['fk_type'] = $obj->fk_type;
362
-                $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
363
-                $tab_result[$i]['description'] = $obj->description;
364
-                $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
365
-                $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
366
-                $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut,1);
367
-                $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin,1);
368
-                $tab_result[$i]['halfday'] = $obj->halfday;
369
-                $tab_result[$i]['statut'] = $obj->statut;
370
-                $tab_result[$i]['fk_validator'] = $obj->fk_validator;
371
-                $tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid);
372
-                $tab_result[$i]['fk_user_valid'] = $obj->fk_user_valid;
373
-                $tab_result[$i]['date_refuse'] = $this->db->jdate($obj->date_refuse);
374
-                $tab_result[$i]['fk_user_refuse'] = $obj->fk_user_refuse;
375
-                $tab_result[$i]['date_cancel'] = $this->db->jdate($obj->date_cancel);
376
-                $tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
377
-                $tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
378
-
379
-                $tab_result[$i]['user_firstname'] = $obj->user_firstname;
380
-                $tab_result[$i]['user_lastname'] = $obj->user_lastname;
381
-                $tab_result[$i]['user_login'] = $obj->user_login;
382
-                $tab_result[$i]['user_statut'] = $obj->user_statut;
383
-                $tab_result[$i]['user_photo'] = $obj->user_photo;
384
-
385
-                $tab_result[$i]['validator_firstname'] = $obj->validator_firstname;
386
-                $tab_result[$i]['validator_lastname'] = $obj->validator_lastname;
387
-                $tab_result[$i]['validator_login'] = $obj->validator_login;
388
-                $tab_result[$i]['validator_statut'] = $obj->validator_statut;
389
-                $tab_result[$i]['validator_photo'] = $obj->validator_photo;
390
-
391
-                $i++;
392
-            }
393
-
394
-            // Retourne 1 avec le tableau rempli
395
-            $this->holiday = $tab_result;
396
-            return 1;
397
-        }
398
-        else
399
-        {
400
-            // Erreur SQL
401
-            $this->error="Error ".$this->db->lasterror();
402
-            return -1;
403
-        }
404
-    }
405
-
406
-    /**
407
-     *	List all holidays of all users
408
-     *
409
-     *  @param      string	$order      Sort order
410
-     *  @param      string	$filter     SQL Filter
411
-     *  @return     int      			-1 if KO, 1 if OK, 2 if no result
412
-     */
413
-    function fetchAll($order,$filter)
414
-    {
415
-        global $langs;
416
-
417
-        $sql = "SELECT";
418
-        $sql.= " cp.rowid,";
419
-
420
-        $sql.= " cp.fk_user,";
421
-        $sql.= " cp.fk_type,";
422
-        $sql.= " cp.date_create,";
423
-        $sql.= " cp.description,";
424
-        $sql.= " cp.date_debut,";
425
-        $sql.= " cp.date_fin,";
426
-        $sql.= " cp.halfday,";
427
-        $sql.= " cp.statut,";
428
-        $sql.= " cp.fk_validator,";
429
-        $sql.= " cp.date_valid,";
430
-        $sql.= " cp.fk_user_valid,";
431
-        $sql.= " cp.date_refuse,";
432
-        $sql.= " cp.fk_user_refuse,";
433
-        $sql.= " cp.date_cancel,";
434
-        $sql.= " cp.fk_user_cancel,";
435
-        $sql.= " cp.detail_refuse,";
436
-
437
-        $sql.= " uu.lastname as user_lastname,";
438
-        $sql.= " uu.firstname as user_firstname,";
439
-        $sql.= " uu.login as user_login,";
440
-        $sql.= " uu.statut as user_statut,";
441
-        $sql.= " uu.photo as user_photo,";
442
-
443
-        $sql.= " ua.lastname as validator_lastname,";
444
-        $sql.= " ua.firstname as validator_firstname,";
445
-        $sql.= " ua.login as validator_login,";
446
-        $sql.= " ua.statut as validator_statut,";
447
-        $sql.= " ua.photo as validator_photo";
448
-
449
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
450
-        $sql.= " WHERE cp.entity IN (".getEntity('holiday').")";
451
-        $sql.= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
452
-
453
-        // Filtrage de séléction
454
-        if(!empty($filter)) {
455
-            $sql.= $filter;
456
-        }
457
-
458
-        // Ordre d'affichage
459
-        if(!empty($order)) {
460
-            $sql.= $order;
461
-        }
462
-
463
-        dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
464
-        $resql=$this->db->query($sql);
465
-
466
-        // Si pas d'erreur SQL
467
-        if ($resql) {
468
-
469
-            $i = 0;
470
-            $tab_result = $this->holiday;
471
-            $num = $this->db->num_rows($resql);
472
-
473
-            // Si pas d'enregistrement
474
-            if(!$num) {
475
-                return 2;
476
-            }
477
-
478
-            // On liste les résultats et on les ajoutent dans le tableau
479
-            while($i < $num) {
480
-
481
-                $obj = $this->db->fetch_object($resql);
482
-
483
-                $tab_result[$i]['rowid'] = $obj->rowid;
484
-                $tab_result[$i]['ref'] = $obj->rowid;
485
-                $tab_result[$i]['fk_user'] = $obj->fk_user;
486
-                $tab_result[$i]['fk_type'] = $obj->fk_type;
487
-                $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
488
-                $tab_result[$i]['description'] = $obj->description;
489
-                $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
490
-                $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
491
-                $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut,1);
492
-                $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin,1);
493
-                $tab_result[$i]['halfday'] = $obj->halfday;
494
-                $tab_result[$i]['statut'] = $obj->statut;
495
-                $tab_result[$i]['fk_validator'] = $obj->fk_validator;
496
-                $tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid);
497
-                $tab_result[$i]['fk_user_valid'] = $obj->fk_user_valid;
498
-                $tab_result[$i]['date_refuse'] = $obj->date_refuse;
499
-                $tab_result[$i]['fk_user_refuse'] = $obj->fk_user_refuse;
500
-                $tab_result[$i]['date_cancel'] = $obj->date_cancel;
501
-                $tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
502
-                $tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
503
-
504
-                $tab_result[$i]['user_firstname'] = $obj->user_firstname;
505
-                $tab_result[$i]['user_lastname'] = $obj->user_lastname;
506
-                $tab_result[$i]['user_login'] = $obj->user_login;
507
-                $tab_result[$i]['user_statut'] = $obj->user_statut;
508
-                $tab_result[$i]['user_photo'] = $obj->user_photo;
509
-
510
-                $tab_result[$i]['validator_firstname'] = $obj->validator_firstname;
511
-                $tab_result[$i]['validator_lastname'] = $obj->validator_lastname;
512
-                $tab_result[$i]['validator_login'] = $obj->validator_login;
513
-                $tab_result[$i]['validator_statut'] = $obj->validator_statut;
514
-                $tab_result[$i]['validator_photo'] = $obj->validator_photo;
515
-
516
-                $i++;
517
-            }
518
-            // Retourne 1 et ajoute le tableau à la variable
519
-            $this->holiday = $tab_result;
520
-            return 1;
521
-        }
522
-        else
523
-        {
524
-            // Erreur SQL
525
-            $this->error="Error ".$this->db->lasterror();
526
-            return -1;
527
-        }
528
-    }
529
-
530
-    /**
531
-     *	Update database
532
-     *
533
-     *  @param	User	$user        	User that modify
534
-     *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
535
-     *  @return int         			<0 if KO, >0 if OK
536
-     */
537
-    function update($user=null, $notrigger=0)
538
-    {
539
-        global $conf, $langs;
540
-        $error=0;
541
-
542
-        // Update request
543
-        $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
544
-
545
-        $sql.= " description= '".$this->db->escape($this->description)."',";
546
-
547
-        if(!empty($this->date_debut)) {
548
-            $sql.= " date_debut = '".$this->db->idate($this->date_debut)."',";
549
-        } else {
550
-            $error++;
551
-        }
552
-        if(!empty($this->date_fin)) {
553
-            $sql.= " date_fin = '".$this->db->idate($this->date_fin)."',";
554
-        } else {
555
-            $error++;
556
-        }
557
-       	$sql.= " halfday = ".$this->halfday.",";
558
-        if(!empty($this->statut) && is_numeric($this->statut)) {
559
-            $sql.= " statut = ".$this->statut.",";
560
-        } else {
561
-            $error++;
562
-        }
563
-        if(!empty($this->fk_validator)) {
564
-            $sql.= " fk_validator = '".$this->db->escape($this->fk_validator)."',";
565
-        } else {
566
-            $error++;
567
-        }
568
-        if(!empty($this->date_valid)) {
569
-            $sql.= " date_valid = '".$this->db->idate($this->date_valid)."',";
570
-        } else {
571
-            $sql.= " date_valid = NULL,";
572
-        }
573
-        if(!empty($this->fk_user_valid)) {
574
-            $sql.= " fk_user_valid = '".$this->db->escape($this->fk_user_valid)."',";
575
-        } else {
576
-            $sql.= " fk_user_valid = NULL,";
577
-        }
578
-        if(!empty($this->date_refuse)) {
579
-            $sql.= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
580
-        } else {
581
-            $sql.= " date_refuse = NULL,";
582
-        }
583
-        if(!empty($this->fk_user_refuse)) {
584
-            $sql.= " fk_user_refuse = '".$this->db->escape($this->fk_user_refuse)."',";
585
-        } else {
586
-            $sql.= " fk_user_refuse = NULL,";
587
-        }
588
-        if(!empty($this->date_cancel)) {
589
-            $sql.= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
590
-        } else {
591
-            $sql.= " date_cancel = NULL,";
592
-        }
593
-        if(!empty($this->fk_user_cancel)) {
594
-            $sql.= " fk_user_cancel = '".$this->db->escape($this->fk_user_cancel)."',";
595
-        } else {
596
-            $sql.= " fk_user_cancel = NULL,";
597
-        }
598
-        if(!empty($this->detail_refuse)) {
599
-            $sql.= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
600
-        } else {
601
-            $sql.= " detail_refuse = NULL";
602
-        }
603
-
604
-        $sql.= " WHERE rowid= ".$this->id;
605
-
606
-        $this->db->begin();
607
-
608
-        dol_syslog(get_class($this)."::update", LOG_DEBUG);
609
-        $resql = $this->db->query($sql);
610
-        if (! $resql) {
611
-            $error++; $this->errors[]="Error ".$this->db->lasterror();
612
-        }
613
-
614
-        if (! $error)
615
-        {
616
-            if (! $notrigger)
617
-            {
618
-                // Call trigger
619
-                $result=$this->call_trigger('HOLIDAY_MODIFY',$user);
620
-                if ($result < 0) { $error++; }
621
-                // End call triggers
622
-            }
623
-        }
624
-
625
-        // Commit or rollback
626
-        if ($error)
627
-        {
628
-            foreach($this->errors as $errmsg)
629
-            {
630
-                dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
631
-                $this->error.=($this->error?', '.$errmsg:$errmsg);
632
-            }
633
-            $this->db->rollback();
634
-            return -1*$error;
635
-        }
636
-        else
637
-        {
638
-            $this->db->commit();
639
-            return 1;
640
-        }
641
-    }
642
-
643
-
644
-    /**
645
-     *   Delete object in database
646
-     *
647
-     *	 @param		User	$user        	User that delete
648
-     *   @param     int		$notrigger	    0=launch triggers after, 1=disable triggers
649
-     *	 @return	int						<0 if KO, >0 if OK
650
-     */
651
-    function delete($user, $notrigger=0)
652
-    {
653
-        global $conf, $langs;
654
-        $error=0;
655
-
656
-        $sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday";
657
-        $sql.= " WHERE rowid=".$this->id;
658
-
659
-        $this->db->begin();
660
-
661
-        dol_syslog(get_class($this)."::delete", LOG_DEBUG);
662
-        $resql = $this->db->query($sql);
663
-        if (! $resql) {
664
-            $error++; $this->errors[]="Error ".$this->db->lasterror();
665
-        }
666
-
667
-        if (! $error)
668
-        {
669
-            if (! $notrigger)
670
-            {
671
-                // Call trigger
672
-                $result=$this->call_trigger('HOLIDAY_DELETE',$user);
673
-                if ($result < 0) { $error++; }
674
-                // End call triggers
675
-            }
676
-        }
677
-
678
-        // Commit or rollback
679
-        if ($error)
680
-        {
681
-            foreach($this->errors as $errmsg)
682
-            {
683
-                dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
684
-                $this->error.=($this->error?', '.$errmsg:$errmsg);
685
-            }
686
-            $this->db->rollback();
687
-            return -1*$error;
688
-        }
689
-        else
690
-        {
691
-            $this->db->commit();
692
-            return 1;
693
-        }
694
-    }
695
-
696
-    /**
697
-     *	Check if a user is on holiday (partially or completely) into a period.
698
-     *  This function can be used to avoid to have 2 leave requests on same period for example.
699
-     *  Warning: It consumes a lot of memory because it load in ->holiday all holiday of a dedicated user at each call.
700
-     *
701
-     * 	@param 	int		$fk_user		Id user
702
-     * 	@param 	date	$dateDebut		Start date of period to check
703
-     * 	@param 	date	$dateFin		End date of period to check
704
-     *  @param	int		$halfday		Tag to define how start and end the period to check:
705
-     *  	    						0:Full days, 2:Sart afternoon end monring, -1:Start afternoon, 1:End morning
706
-     * 	@return boolean					False is on holiday at least partially into the period, True is never on holiday during chcked period.
707
-     *  @see verifDateHolidayForTimestamp
708
-     */
709
-    function verifDateHolidayCP($fk_user, $dateDebut, $dateFin, $halfday=0)
710
-    {
711
-        $this->fetchByUser($fk_user,'','');
712
-
713
-        foreach($this->holiday as $infos_CP)
714
-        {
715
-        	if ($infos_CP['statut'] == 4) continue;		// ignore not validated holidays
716
-        	if ($infos_CP['statut'] == 5) continue;		// ignore not validated holidays
717
-
718
-        	// TODO Also use halfday for the check
719
-        	if ($halfday == 0)
720
-        	{
721
-	            if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut'])
722
-	            {
723
-	                return false;
724
-	            }
725
-        	}
726
-            elseif ($halfday == -1)
727
-        	{
728
-	            if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut'])
729
-	            {
730
-	                return false;
731
-	            }
732
-        	}
733
-            elseif ($halfday == 1)
734
-        	{
735
-	            if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut'])
736
-	            {
737
-	                return false;
738
-	            }
739
-        	}
740
-            elseif ($halfday == 2)
741
-        	{
742
-	            if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut'])
743
-	            {
744
-	                return false;
745
-	            }
746
-        	}
747
-        	else
748
-        	{
749
-        		dol_print_error('', 'Bad value of parameter halfday when calling function verifDateHolidayCP');
750
-        	}
751
-        }
752
-
753
-        return true;
754
-    }
755
-
756
-
757
-    /**
758
-     *	Check a user is not on holiday for a particular timestamp
759
-     *
760
-     * 	@param 	int			$fk_user				Id user
761
-     *  @param	timestamp	$timestamp				Time stamp date for a day (YYYY-MM-DD) without hours  (= 12:00AM in english and not 12:00PM that is 12:00)
762
-     * 	@return array								array('morning'=> ,'afternoon'=> ), Boolean is true if user is available for day timestamp.
763
-     *  @see verifDateHolidayCP
764
-     */
765
-    function verifDateHolidayForTimestamp($fk_user, $timestamp)
766
-    {
767
-    	global $langs, $conf;
768
-
769
-    	$isavailablemorning=true;
770
-    	$isavailableafternoon=true;
771
-
772
-    	$sql = "SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday";
773
-    	$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp";
774
-    	$sql.= " WHERE cp.entity IN (".getEntity('holiday').")";
775
-    	$sql.= " AND cp.fk_user = ".(int) $fk_user;
452
+
453
+		// Filtrage de séléction
454
+		if(!empty($filter)) {
455
+			$sql.= $filter;
456
+		}
457
+
458
+		// Ordre d'affichage
459
+		if(!empty($order)) {
460
+			$sql.= $order;
461
+		}
462
+
463
+		dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
464
+		$resql=$this->db->query($sql);
465
+
466
+		// Si pas d'erreur SQL
467
+		if ($resql) {
468
+
469
+			$i = 0;
470
+			$tab_result = $this->holiday;
471
+			$num = $this->db->num_rows($resql);
472
+
473
+			// Si pas d'enregistrement
474
+			if(!$num) {
475
+				return 2;
476
+			}
477
+
478
+			// On liste les résultats et on les ajoutent dans le tableau
479
+			while($i < $num) {
480
+
481
+				$obj = $this->db->fetch_object($resql);
482
+
483
+				$tab_result[$i]['rowid'] = $obj->rowid;
484
+				$tab_result[$i]['ref'] = $obj->rowid;
485
+				$tab_result[$i]['fk_user'] = $obj->fk_user;
486
+				$tab_result[$i]['fk_type'] = $obj->fk_type;
487
+				$tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
488
+				$tab_result[$i]['description'] = $obj->description;
489
+				$tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
490
+				$tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
491
+				$tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut,1);
492
+				$tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin,1);
493
+				$tab_result[$i]['halfday'] = $obj->halfday;
494
+				$tab_result[$i]['statut'] = $obj->statut;
495
+				$tab_result[$i]['fk_validator'] = $obj->fk_validator;
496
+				$tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid);
497
+				$tab_result[$i]['fk_user_valid'] = $obj->fk_user_valid;
498
+				$tab_result[$i]['date_refuse'] = $obj->date_refuse;
499
+				$tab_result[$i]['fk_user_refuse'] = $obj->fk_user_refuse;
500
+				$tab_result[$i]['date_cancel'] = $obj->date_cancel;
501
+				$tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
502
+				$tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
503
+
504
+				$tab_result[$i]['user_firstname'] = $obj->user_firstname;
505
+				$tab_result[$i]['user_lastname'] = $obj->user_lastname;
506
+				$tab_result[$i]['user_login'] = $obj->user_login;
507
+				$tab_result[$i]['user_statut'] = $obj->user_statut;
508
+				$tab_result[$i]['user_photo'] = $obj->user_photo;
509
+
510
+				$tab_result[$i]['validator_firstname'] = $obj->validator_firstname;
511
+				$tab_result[$i]['validator_lastname'] = $obj->validator_lastname;
512
+				$tab_result[$i]['validator_login'] = $obj->validator_login;
513
+				$tab_result[$i]['validator_statut'] = $obj->validator_statut;
514
+				$tab_result[$i]['validator_photo'] = $obj->validator_photo;
515
+
516
+				$i++;
517
+			}
518
+			// Retourne 1 et ajoute le tableau à la variable
519
+			$this->holiday = $tab_result;
520
+			return 1;
521
+		}
522
+		else
523
+		{
524
+			// Erreur SQL
525
+			$this->error="Error ".$this->db->lasterror();
526
+			return -1;
527
+		}
528
+	}
529
+
530
+	/**
531
+	 *	Update database
532
+	 *
533
+	 *  @param	User	$user        	User that modify
534
+	 *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
535
+	 *  @return int         			<0 if KO, >0 if OK
536
+	 */
537
+	function update($user=null, $notrigger=0)
538
+	{
539
+		global $conf, $langs;
540
+		$error=0;
541
+
542
+		// Update request
543
+		$sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
544
+
545
+		$sql.= " description= '".$this->db->escape($this->description)."',";
546
+
547
+		if(!empty($this->date_debut)) {
548
+			$sql.= " date_debut = '".$this->db->idate($this->date_debut)."',";
549
+		} else {
550
+			$error++;
551
+		}
552
+		if(!empty($this->date_fin)) {
553
+			$sql.= " date_fin = '".$this->db->idate($this->date_fin)."',";
554
+		} else {
555
+			$error++;
556
+		}
557
+	   	$sql.= " halfday = ".$this->halfday.",";
558
+		if(!empty($this->statut) && is_numeric($this->statut)) {
559
+			$sql.= " statut = ".$this->statut.",";
560
+		} else {
561
+			$error++;
562
+		}
563
+		if(!empty($this->fk_validator)) {
564
+			$sql.= " fk_validator = '".$this->db->escape($this->fk_validator)."',";
565
+		} else {
566
+			$error++;
567
+		}
568
+		if(!empty($this->date_valid)) {
569
+			$sql.= " date_valid = '".$this->db->idate($this->date_valid)."',";
570
+		} else {
571
+			$sql.= " date_valid = NULL,";
572
+		}
573
+		if(!empty($this->fk_user_valid)) {
574
+			$sql.= " fk_user_valid = '".$this->db->escape($this->fk_user_valid)."',";
575
+		} else {
576
+			$sql.= " fk_user_valid = NULL,";
577
+		}
578
+		if(!empty($this->date_refuse)) {
579
+			$sql.= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
580
+		} else {
581
+			$sql.= " date_refuse = NULL,";
582
+		}
583
+		if(!empty($this->fk_user_refuse)) {
584
+			$sql.= " fk_user_refuse = '".$this->db->escape($this->fk_user_refuse)."',";
585
+		} else {
586
+			$sql.= " fk_user_refuse = NULL,";
587
+		}
588
+		if(!empty($this->date_cancel)) {
589
+			$sql.= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
590
+		} else {
591
+			$sql.= " date_cancel = NULL,";
592
+		}
593
+		if(!empty($this->fk_user_cancel)) {
594
+			$sql.= " fk_user_cancel = '".$this->db->escape($this->fk_user_cancel)."',";
595
+		} else {
596
+			$sql.= " fk_user_cancel = NULL,";
597
+		}
598
+		if(!empty($this->detail_refuse)) {
599
+			$sql.= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
600
+		} else {
601
+			$sql.= " detail_refuse = NULL";
602
+		}
603
+
604
+		$sql.= " WHERE rowid= ".$this->id;
605
+
606
+		$this->db->begin();
607
+
608
+		dol_syslog(get_class($this)."::update", LOG_DEBUG);
609
+		$resql = $this->db->query($sql);
610
+		if (! $resql) {
611
+			$error++; $this->errors[]="Error ".$this->db->lasterror();
612
+		}
613
+
614
+		if (! $error)
615
+		{
616
+			if (! $notrigger)
617
+			{
618
+				// Call trigger
619
+				$result=$this->call_trigger('HOLIDAY_MODIFY',$user);
620
+				if ($result < 0) { $error++; }
621
+				// End call triggers
622
+			}
623
+		}
624
+
625
+		// Commit or rollback
626
+		if ($error)
627
+		{
628
+			foreach($this->errors as $errmsg)
629
+			{
630
+				dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
631
+				$this->error.=($this->error?', '.$errmsg:$errmsg);
632
+			}
633
+			$this->db->rollback();
634
+			return -1*$error;
635
+		}
636
+		else
637
+		{
638
+			$this->db->commit();
639
+			return 1;
640
+		}
641
+	}
642
+
643
+
644
+	/**
645
+	 *   Delete object in database
646
+	 *
647
+	 *	 @param		User	$user        	User that delete
648
+	 *   @param     int		$notrigger	    0=launch triggers after, 1=disable triggers
649
+	 *	 @return	int						<0 if KO, >0 if OK
650
+	 */
651
+	function delete($user, $notrigger=0)
652
+	{
653
+		global $conf, $langs;
654
+		$error=0;
655
+
656
+		$sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday";
657
+		$sql.= " WHERE rowid=".$this->id;
658
+
659
+		$this->db->begin();
660
+
661
+		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
662
+		$resql = $this->db->query($sql);
663
+		if (! $resql) {
664
+			$error++; $this->errors[]="Error ".$this->db->lasterror();
665
+		}
666
+
667
+		if (! $error)
668
+		{
669
+			if (! $notrigger)
670
+			{
671
+				// Call trigger
672
+				$result=$this->call_trigger('HOLIDAY_DELETE',$user);
673
+				if ($result < 0) { $error++; }
674
+				// End call triggers
675
+			}
676
+		}
677
+
678
+		// Commit or rollback
679
+		if ($error)
680
+		{
681
+			foreach($this->errors as $errmsg)
682
+			{
683
+				dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
684
+				$this->error.=($this->error?', '.$errmsg:$errmsg);
685
+			}
686
+			$this->db->rollback();
687
+			return -1*$error;
688
+		}
689
+		else
690
+		{
691
+			$this->db->commit();
692
+			return 1;
693
+		}
694
+	}
695
+
696
+	/**
697
+	 *	Check if a user is on holiday (partially or completely) into a period.
698
+	 *  This function can be used to avoid to have 2 leave requests on same period for example.
699
+	 *  Warning: It consumes a lot of memory because it load in ->holiday all holiday of a dedicated user at each call.
700
+	 *
701
+	 * 	@param 	int		$fk_user		Id user
702
+	 * 	@param 	date	$dateDebut		Start date of period to check
703
+	 * 	@param 	date	$dateFin		End date of period to check
704
+	 *  @param	int		$halfday		Tag to define how start and end the period to check:
705
+	 *  	    						0:Full days, 2:Sart afternoon end monring, -1:Start afternoon, 1:End morning
706
+	 * 	@return boolean					False is on holiday at least partially into the period, True is never on holiday during chcked period.
707
+	 *  @see verifDateHolidayForTimestamp
708
+	 */
709
+	function verifDateHolidayCP($fk_user, $dateDebut, $dateFin, $halfday=0)
710
+	{
711
+		$this->fetchByUser($fk_user,'','');
712
+
713
+		foreach($this->holiday as $infos_CP)
714
+		{
715
+			if ($infos_CP['statut'] == 4) continue;		// ignore not validated holidays
716
+			if ($infos_CP['statut'] == 5) continue;		// ignore not validated holidays
717
+
718
+			// TODO Also use halfday for the check
719
+			if ($halfday == 0)
720
+			{
721
+				if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut'])
722
+				{
723
+					return false;
724
+				}
725
+			}
726
+			elseif ($halfday == -1)
727
+			{
728
+				if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut'])
729
+				{
730
+					return false;
731
+				}
732
+			}
733
+			elseif ($halfday == 1)
734
+			{
735
+				if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut'])
736
+				{
737
+					return false;
738
+				}
739
+			}
740
+			elseif ($halfday == 2)
741
+			{
742
+				if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut'])
743
+				{
744
+					return false;
745
+				}
746
+			}
747
+			else
748
+			{
749
+				dol_print_error('', 'Bad value of parameter halfday when calling function verifDateHolidayCP');
750
+			}
751
+		}
752
+
753
+		return true;
754
+	}
755
+
756
+
757
+	/**
758
+	 *	Check a user is not on holiday for a particular timestamp
759
+	 *
760
+	 * 	@param 	int			$fk_user				Id user
761
+	 *  @param	timestamp	$timestamp				Time stamp date for a day (YYYY-MM-DD) without hours  (= 12:00AM in english and not 12:00PM that is 12:00)
762
+	 * 	@return array								array('morning'=> ,'afternoon'=> ), Boolean is true if user is available for day timestamp.
763
+	 *  @see verifDateHolidayCP
764
+	 */
765
+	function verifDateHolidayForTimestamp($fk_user, $timestamp)
766
+	{
767
+		global $langs, $conf;
768
+
769
+		$isavailablemorning=true;
770
+		$isavailableafternoon=true;
771
+
772
+		$sql = "SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday";
773
+		$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp";
774
+		$sql.= " WHERE cp.entity IN (".getEntity('holiday').")";
775
+		$sql.= " AND cp.fk_user = ".(int) $fk_user;
776 776
    		$sql.= " AND date_debut <= '".$this->db->idate($timestamp)."' AND date_fin >= '".$this->db->idate($timestamp)."'";
777 777
 
778
-    	$resql = $this->db->query($sql);
779
-    	if ($resql)
780
-    	{
781
-    		$num_rows = $this->db->num_rows($resql);	// Note, we can have 2 records if on is morning and the other one is afternoon
782
-    		if ($num_rows > 0)
783
-    		{
784
-	    		$i=0;
785
-	    		while ($i < $num_rows)
786
-	    		{
787
-	    			$obj = $this->db->fetch_object($resql);
788
-
789
-	    			// Note: $obj->halday is  0:Full days, 2:Sart afternoon end morning, -1:Start afternoon, 1:End morning
790
-	    			$arrayofrecord[$obj->rowid]=array('date_start'=>$this->db->jdate($obj->date_start), 'date_end'=>$this->db->jdate($obj->date_end), 'halfday'=>$obj->halfday);
791
-	    			$i++;
792
-	    		}
793
-
794
-    			// We found a record, user is on holiday by default, so is not available is true.
795
-	    		$isavailablemorning = true;
796
-	    		foreach($arrayofrecord as $record)
797
-	    		{
778
+		$resql = $this->db->query($sql);
779
+		if ($resql)
780
+		{
781
+			$num_rows = $this->db->num_rows($resql);	// Note, we can have 2 records if on is morning and the other one is afternoon
782
+			if ($num_rows > 0)
783
+			{
784
+				$i=0;
785
+				while ($i < $num_rows)
786
+				{
787
+					$obj = $this->db->fetch_object($resql);
788
+
789
+					// Note: $obj->halday is  0:Full days, 2:Sart afternoon end morning, -1:Start afternoon, 1:End morning
790
+					$arrayofrecord[$obj->rowid]=array('date_start'=>$this->db->jdate($obj->date_start), 'date_end'=>$this->db->jdate($obj->date_end), 'halfday'=>$obj->halfday);
791
+					$i++;
792
+				}
793
+
794
+				// We found a record, user is on holiday by default, so is not available is true.
795
+				$isavailablemorning = true;
796
+				foreach($arrayofrecord as $record)
797
+				{
798 798
 					if ($timestamp == $record['date_start'] && $record['halfday'] == 2)  continue;
799 799
 					if ($timestamp == $record['date_start'] && $record['halfday'] == -1) continue;
800
-	    			$isavailablemorning = false;
801
-	    			break;
802
-	    		}
803
-    			$isavailableafternoon = true;
804
-	    		foreach($arrayofrecord as $record)
805
-	    		{
800
+					$isavailablemorning = false;
801
+					break;
802
+				}
803
+				$isavailableafternoon = true;
804
+				foreach($arrayofrecord as $record)
805
+				{
806 806
 					if ($timestamp == $record['date_end'] && $record['halfday'] == 2) continue;
807 807
 					if ($timestamp == $record['date_end'] && $record['halfday'] == 1) continue;
808
-	    			$isavailableafternoon = false;
809
-	    			break;
810
-	    		}
811
-    		}
812
-    	}
813
-    	else dol_print_error($this->db);
808
+					$isavailableafternoon = false;
809
+					break;
810
+				}
811
+			}
812
+		}
813
+		else dol_print_error($this->db);
814 814
 
815 815
    		return array('morning'=>$isavailablemorning, 'afternoon'=>$isavailableafternoon);
816
-    }
817
-
818
-
819
-    /**
820
-     *	Return clicable name (with picto eventually)
821
-     *
822
-     *	@param	int			$withpicto					0=_No picto, 1=Includes the picto in the linkn, 2=Picto only
823
-     *  @param  int     	$save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
824
-     *	@return	string									String with URL
825
-     */
826
-    function getNomUrl($withpicto=0, $save_lastsearch_value=-1)
827
-    {
828
-        global $langs;
829
-
830
-        $result='';
831
-        $picto='holiday';
832
-        $label=$langs->trans("Show").': '.$this->ref;
833
-
834
-        $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id;
835
-
836
-        //if ($option != 'nolink')
837
-        //{
838
-        	// Add param to save lastsearch_values or not
839
-        	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
840
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
841
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
842
-        //}
843
-
844
-        $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
845
-        $linkend='</a>';
846
-
847
-        if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
848
-        if ($withpicto && $withpicto != 2) $result.=' ';
849
-        if ($withpicto != 2) $result.=$linkstart.$this->ref.$linkend;
850
-        return $result;
851
-    }
852
-
853
-
854
-    /**
855
-     *	Returns the label status
856
-     *
857
-     *	@param      int		$mode       0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
858
-     *	@return     string      		Label
859
-     */
860
-    function getLibStatut($mode=0)
861
-    {
862
-    	return $this->LibStatut($this->statut, $mode, $this->date_debut);
863
-    }
816
+	}
817
+
818
+
819
+	/**
820
+	 *	Return clicable name (with picto eventually)
821
+	 *
822
+	 *	@param	int			$withpicto					0=_No picto, 1=Includes the picto in the linkn, 2=Picto only
823
+	 *  @param  int     	$save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
824
+	 *	@return	string									String with URL
825
+	 */
826
+	function getNomUrl($withpicto=0, $save_lastsearch_value=-1)
827
+	{
828
+		global $langs;
829
+
830
+		$result='';
831
+		$picto='holiday';
832
+		$label=$langs->trans("Show").': '.$this->ref;
833
+
834
+		$url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id;
835
+
836
+		//if ($option != 'nolink')
837
+		//{
838
+			// Add param to save lastsearch_values or not
839
+			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
840
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
841
+			if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
842
+		//}
843
+
844
+		$linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
845
+		$linkend='</a>';
846
+
847
+		if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
848
+		if ($withpicto && $withpicto != 2) $result.=' ';
849
+		if ($withpicto != 2) $result.=$linkstart.$this->ref.$linkend;
850
+		return $result;
851
+	}
852
+
853
+
854
+	/**
855
+	 *	Returns the label status
856
+	 *
857
+	 *	@param      int		$mode       0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
858
+	 *	@return     string      		Label
859
+	 */
860
+	function getLibStatut($mode=0)
861
+	{
862
+		return $this->LibStatut($this->statut, $mode, $this->date_debut);
863
+	}
864 864
 
865 865
 	/**
866 866
 	 *	Returns the label of a statut
@@ -876,11 +876,11 @@  discard block
 block discarded – undo
876 876
 
877 877
 		if ($mode == 0)
878 878
 		{
879
-            if ($statut == 1) return $langs->trans('DraftCP');
880
-            if ($statut == 2) return $langs->trans('ToReviewCP');
881
-            if ($statut == 3) return $langs->trans('ApprovedCP');
882
-            if ($statut == 4) return $langs->trans('CancelCP');
883
-            if ($statut == 5) return $langs->trans('RefuseCP');
879
+			if ($statut == 1) return $langs->trans('DraftCP');
880
+			if ($statut == 2) return $langs->trans('ToReviewCP');
881
+			if ($statut == 3) return $langs->trans('ApprovedCP');
882
+			if ($statut == 4) return $langs->trans('CancelCP');
883
+			if ($statut == 5) return $langs->trans('RefuseCP');
884 884
 		}
885 885
 		if ($mode == 2)
886 886
 		{
@@ -914,865 +914,865 @@  discard block
 block discarded – undo
914 914
 		}
915 915
 		if ($mode == 6)
916 916
 		{
917
-		    $pictoapproved='statut6';
918
-		    if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4';
919
-		    if ($statut == 1) return $langs->trans('DraftCP').' '.img_picto($langs->trans('DraftCP'),'statut0');				// Draft
920
-		    if ($statut == 2) return $langs->trans('ToReviewCP').' '.img_picto($langs->trans('ToReviewCP'),'statut1');		// Waiting approval
921
-		    if ($statut == 3) return $langs->trans('ApprovedCP').' '.img_picto($langs->trans('ApprovedCP'),$pictoapproved);
922
-		    if ($statut == 4) return $langs->trans('CancelCP').' '.img_picto($langs->trans('CancelCP'),'statut5');
923
-		    if ($statut == 5) return $langs->trans('RefuseCP').' '.img_picto($langs->trans('RefuseCP'),'statut5');
917
+			$pictoapproved='statut6';
918
+			if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4';
919
+			if ($statut == 1) return $langs->trans('DraftCP').' '.img_picto($langs->trans('DraftCP'),'statut0');				// Draft
920
+			if ($statut == 2) return $langs->trans('ToReviewCP').' '.img_picto($langs->trans('ToReviewCP'),'statut1');		// Waiting approval
921
+			if ($statut == 3) return $langs->trans('ApprovedCP').' '.img_picto($langs->trans('ApprovedCP'),$pictoapproved);
922
+			if ($statut == 4) return $langs->trans('CancelCP').' '.img_picto($langs->trans('CancelCP'),'statut5');
923
+			if ($statut == 5) return $langs->trans('RefuseCP').' '.img_picto($langs->trans('RefuseCP'),'statut5');
924 924
 		}
925 925
 
926 926
 		return $statut;
927
-    }
928
-
929
-
930
-    /**
931
-     *   Affiche un select HTML des statuts de congés payés
932
-     *
933
-     *   @param 	int		$selected   int du statut séléctionné par défaut
934
-     *   @return    string				affiche le select des statuts
935
-     */
936
-    function selectStatutCP($selected='') {
937
-
938
-        global $langs;
939
-
940
-        // Liste des statuts
941
-        $name = array('DraftCP','ToReviewCP','ApprovedCP','CancelCP','RefuseCP');
942
-        $nb = count($name)+1;
943
-
944
-        // Select HTML
945
-        $statut = '<select name="select_statut" class="flat">'."\n";
946
-        $statut.= '<option value="-1">&nbsp;</option>'."\n";
947
-
948
-        // Boucle des statuts
949
-        for($i=1; $i < $nb; $i++) {
950
-            if($i==$selected) {
951
-                $statut.= '<option value="'.$i.'" selected>'.$langs->trans($name[$i-1]).'</option>'."\n";
952
-            }
953
-            else {
954
-                $statut.= '<option value="'.$i.'">'.$langs->trans($name[$i-1]).'</option>'."\n";
955
-            }
956
-        }
957
-
958
-        $statut.= '</select>'."\n";
959
-        print $statut;
960
-
961
-    }
962
-
963
-    /**
964
-     *  Met à jour une option du module Holiday Payés
965
-     *
966
-     *  @param	string	$name       name du paramètre de configuration
967
-     *  @param	string	$value      vrai si mise à jour OK sinon faux
968
-     *  @return boolean				ok or ko
969
-     */
970
-    function updateConfCP($name,$value) {
971
-
972
-        $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
973
-        $sql.= " value = '".$value."'";
974
-        $sql.= " WHERE name = '".$name."'";
975
-
976
-        dol_syslog(get_class($this).'::updateConfCP name='.$name.'', LOG_DEBUG);
977
-        $result = $this->db->query($sql);
978
-        if($result) {
979
-            return true;
980
-        }
981
-
982
-        return false;
983
-    }
984
-
985
-    /**
986
-     *  Return value of a conf parameterfor leave module
987
-     *  TODO Move this into llx_const table
988
-     *
989
-     *  @param	string	$name                 Name of parameter
990
-     *  @param  string  $createifnotfound     'stringvalue'=Create entry with string value if not found. For example 'YYYYMMDDHHMMSS'.
991
-     *  @return string      		          Value of parameter. Example: 'YYYYMMDDHHMMSS' or < 0 if error
992
-     */
993
-    function getConfCP($name, $createifnotfound='')
994
-    {
995
-        $sql = "SELECT value";
996
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday_config";
997
-        $sql.= " WHERE name = '".$this->db->escape($name)."'";
998
-
999
-        dol_syslog(get_class($this).'::getConfCP name='.$name.' createifnotfound='.$createifnotfound, LOG_DEBUG);
1000
-        $result = $this->db->query($sql);
1001
-
1002
-        if($result) {
1003
-
1004
-            $obj = $this->db->fetch_object($result);
1005
-            // Return value
1006
-            if (empty($obj))
1007
-            {
1008
-                if ($createifnotfound)
1009
-                {
1010
-                    $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)";
1011
-                    $sql.= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')";
1012
-                    $result = $this->db->query($sql);
1013
-                    if ($result)
1014
-                    {
1015
-                        return $createifnotfound;
1016
-                    }
1017
-                    else
1018
-                    {
1019
-                        $this->error=$this->db->lasterror();
1020
-                        return -2;
1021
-                    }
1022
-                }
1023
-                else
1024
-                {
1025
-                    return '';
1026
-                }
1027
-            }
1028
-            else
1029
-            {
1030
-                return $obj->value;
1031
-            }
1032
-        } else {
1033
-
1034
-            // Erreur SQL
1035
-            $this->error=$this->db->lasterror();
1036
-            return -1;
1037
-        }
1038
-    }
1039
-
1040
-    /**
1041
-     *	Met à jour le timestamp de la dernière mise à jour du solde des CP
1042
-     *
1043
-     *	@param		int		$userID		Id of user
1044
-     *	@param		int		$nbHoliday	Nb of days
1045
-     *  @param		int		$fk_type	Type of vacation
1046
-     *  @return     int					0=Nothing done, 1=OK, -1=KO
1047
-     */
1048
-    function updateSoldeCP($userID='',$nbHoliday='', $fk_type='')
1049
-    {
1050
-        global $user, $langs;
1051
-
1052
-        $error = 0;
1053
-
1054
-        if (empty($userID) && empty($nbHoliday) && empty($fk_type))
1055
-        {
1056
-            $langs->load("holiday");
1057
-
1058
-            // Si mise à jour pour tout le monde en début de mois
927
+	}
928
+
929
+
930
+	/**
931
+	 *   Affiche un select HTML des statuts de congés payés
932
+	 *
933
+	 *   @param 	int		$selected   int du statut séléctionné par défaut
934
+	 *   @return    string				affiche le select des statuts
935
+	 */
936
+	function selectStatutCP($selected='') {
937
+
938
+		global $langs;
939
+
940
+		// Liste des statuts
941
+		$name = array('DraftCP','ToReviewCP','ApprovedCP','CancelCP','RefuseCP');
942
+		$nb = count($name)+1;
943
+
944
+		// Select HTML
945
+		$statut = '<select name="select_statut" class="flat">'."\n";
946
+		$statut.= '<option value="-1">&nbsp;</option>'."\n";
947
+
948
+		// Boucle des statuts
949
+		for($i=1; $i < $nb; $i++) {
950
+			if($i==$selected) {
951
+				$statut.= '<option value="'.$i.'" selected>'.$langs->trans($name[$i-1]).'</option>'."\n";
952
+			}
953
+			else {
954
+				$statut.= '<option value="'.$i.'">'.$langs->trans($name[$i-1]).'</option>'."\n";
955
+			}
956
+		}
957
+
958
+		$statut.= '</select>'."\n";
959
+		print $statut;
960
+
961
+	}
962
+
963
+	/**
964
+	 *  Met à jour une option du module Holiday Payés
965
+	 *
966
+	 *  @param	string	$name       name du paramètre de configuration
967
+	 *  @param	string	$value      vrai si mise à jour OK sinon faux
968
+	 *  @return boolean				ok or ko
969
+	 */
970
+	function updateConfCP($name,$value) {
971
+
972
+		$sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
973
+		$sql.= " value = '".$value."'";
974
+		$sql.= " WHERE name = '".$name."'";
975
+
976
+		dol_syslog(get_class($this).'::updateConfCP name='.$name.'', LOG_DEBUG);
977
+		$result = $this->db->query($sql);
978
+		if($result) {
979
+			return true;
980
+		}
981
+
982
+		return false;
983
+	}
984
+
985
+	/**
986
+	 *  Return value of a conf parameterfor leave module
987
+	 *  TODO Move this into llx_const table
988
+	 *
989
+	 *  @param	string	$name                 Name of parameter
990
+	 *  @param  string  $createifnotfound     'stringvalue'=Create entry with string value if not found. For example 'YYYYMMDDHHMMSS'.
991
+	 *  @return string      		          Value of parameter. Example: 'YYYYMMDDHHMMSS' or < 0 if error
992
+	 */
993
+	function getConfCP($name, $createifnotfound='')
994
+	{
995
+		$sql = "SELECT value";
996
+		$sql.= " FROM ".MAIN_DB_PREFIX."holiday_config";
997
+		$sql.= " WHERE name = '".$this->db->escape($name)."'";
998
+
999
+		dol_syslog(get_class($this).'::getConfCP name='.$name.' createifnotfound='.$createifnotfound, LOG_DEBUG);
1000
+		$result = $this->db->query($sql);
1001
+
1002
+		if($result) {
1003
+
1004
+			$obj = $this->db->fetch_object($result);
1005
+			// Return value
1006
+			if (empty($obj))
1007
+			{
1008
+				if ($createifnotfound)
1009
+				{
1010
+					$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)";
1011
+					$sql.= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')";
1012
+					$result = $this->db->query($sql);
1013
+					if ($result)
1014
+					{
1015
+						return $createifnotfound;
1016
+					}
1017
+					else
1018
+					{
1019
+						$this->error=$this->db->lasterror();
1020
+						return -2;
1021
+					}
1022
+				}
1023
+				else
1024
+				{
1025
+					return '';
1026
+				}
1027
+			}
1028
+			else
1029
+			{
1030
+				return $obj->value;
1031
+			}
1032
+		} else {
1033
+
1034
+			// Erreur SQL
1035
+			$this->error=$this->db->lasterror();
1036
+			return -1;
1037
+		}
1038
+	}
1039
+
1040
+	/**
1041
+	 *	Met à jour le timestamp de la dernière mise à jour du solde des CP
1042
+	 *
1043
+	 *	@param		int		$userID		Id of user
1044
+	 *	@param		int		$nbHoliday	Nb of days
1045
+	 *  @param		int		$fk_type	Type of vacation
1046
+	 *  @return     int					0=Nothing done, 1=OK, -1=KO
1047
+	 */
1048
+	function updateSoldeCP($userID='',$nbHoliday='', $fk_type='')
1049
+	{
1050
+		global $user, $langs;
1051
+
1052
+		$error = 0;
1053
+
1054
+		if (empty($userID) && empty($nbHoliday) && empty($fk_type))
1055
+		{
1056
+			$langs->load("holiday");
1057
+
1058
+			// Si mise à jour pour tout le monde en début de mois
1059 1059
 			$now=dol_now();
1060 1060
 
1061
-            $month = date('m',$now);
1062
-            $newdateforlastupdate = dol_print_date($now, '%Y%m%d%H%M%S');
1061
+			$month = date('m',$now);
1062
+			$newdateforlastupdate = dol_print_date($now, '%Y%m%d%H%M%S');
1063 1063
 
1064
-            // Get month of last update
1065
-            $lastUpdate = $this->getConfCP('lastUpdate', $newdateforlastupdate);
1066
-            $monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
1064
+			// Get month of last update
1065
+			$lastUpdate = $this->getConfCP('lastUpdate', $newdateforlastupdate);
1066
+			$monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
1067 1067
 			//print 'month: '.$month.' lastUpdate:'.$lastUpdate.' monthLastUpdate:'.$monthLastUpdate;exit;
1068 1068
 
1069
-            // Si la date du mois n'est pas la même que celle sauvegardée, on met à jour le timestamp
1070
-            if ($month != $monthLastUpdate)
1071
-            {
1072
-            	$this->db->begin();
1069
+			// Si la date du mois n'est pas la même que celle sauvegardée, on met à jour le timestamp
1070
+			if ($month != $monthLastUpdate)
1071
+			{
1072
+				$this->db->begin();
1073 1073
 
1074
-            	$users = $this->fetchUsers(false,false);
1075
-	            $nbUser = count($users);
1074
+				$users = $this->fetchUsers(false,false);
1075
+				$nbUser = count($users);
1076 1076
 
1077
-                $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1078
-                $sql.= " value = '".$this->db->escape($newdateforlastupdate)."'";
1079
-                $sql.= " WHERE name = 'lastUpdate'";
1080
-                $result = $this->db->query($sql);
1077
+				$sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1078
+				$sql.= " value = '".$this->db->escape($newdateforlastupdate)."'";
1079
+				$sql.= " WHERE name = 'lastUpdate'";
1080
+				$result = $this->db->query($sql);
1081 1081
 
1082 1082
 				$typeleaves=$this->getTypes(1,1);
1083
-    			foreach($typeleaves as $key => $val)
1084
-    			{
1085
-	                // On ajoute x jours à chaque utilisateurs
1086
-	                $nb_holiday = $val['newByMonth'];
1083
+				foreach($typeleaves as $key => $val)
1084
+				{
1085
+					// On ajoute x jours à chaque utilisateurs
1086
+					$nb_holiday = $val['newByMonth'];
1087 1087
 					if (empty($nb_holiday)) $nb_holiday=0;
1088 1088
 
1089 1089
 					if ($nb_holiday > 0)
1090 1090
 					{
1091 1091
 						dol_syslog("We update leavefor everybody for type ".$key, LOG_DEBUG);
1092 1092
 
1093
-		                $i = 0;
1094
-		                while ($i < $nbUser)
1095
-		                {
1096
-		                    $now_holiday = $this->getCPforUser($users[$i]['rowid'], $val['rowid']);
1097
-		                    $new_solde = $now_holiday + $this->getConfCP('nbHolidayEveryMonth');
1093
+						$i = 0;
1094
+						while ($i < $nbUser)
1095
+						{
1096
+							$now_holiday = $this->getCPforUser($users[$i]['rowid'], $val['rowid']);
1097
+							$new_solde = $now_holiday + $this->getConfCP('nbHolidayEveryMonth');
1098 1098
 
1099
-		                    // We add a log for each user
1100
-		                    $this->addLogCP($user->id, $users[$i]['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $new_solde, $val['rowid']);
1099
+							// We add a log for each user
1100
+							$this->addLogCP($user->id, $users[$i]['rowid'], $langs->trans('HolidaysMonthlyUpdate'), $new_solde, $val['rowid']);
1101 1101
 
1102
-		                    $i++;
1103
-		                }
1102
+							$i++;
1103
+						}
1104 1104
 
1105
-		                // Now we update counter for all users at once
1106
-		                $sql2 = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
1107
-		                $sql2.= " nb_holiday = nb_holiday + ".$nb_holiday;
1105
+						// Now we update counter for all users at once
1106
+						$sql2 = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
1107
+						$sql2.= " nb_holiday = nb_holiday + ".$nb_holiday;
1108 1108
 						$sql2.= " WHERE fk_type = ".$val['rowid'];
1109 1109
 
1110
-		                $result= $this->db->query($sql2);
1110
+						$result= $this->db->query($sql2);
1111 1111
 
1112
-		                if (! $result)
1113
-		                {
1114
-		                	dol_print_error($this->db);
1115
-		                	break;
1116
-		                }
1112
+						if (! $result)
1113
+						{
1114
+							dol_print_error($this->db);
1115
+							break;
1116
+						}
1117 1117
 					}
1118 1118
 					else dol_syslog("No change for leave of type ".$key, LOG_DEBUG);
1119
-    			}
1119
+				}
1120 1120
 
1121 1121
 				if ($result)
1122
-	           	{
1123
-	            	$this->db->commit();
1124
-	            	return 1;
1125
-	           	}
1126
-    	       	else
1127
-    	      	{
1128
-    	       		$this->db->rollback();
1129
-    	        	return -1;
1130
-    	       	}
1131
-            }
1132
-
1133
-            return 0;
1134
-        }
1135
-        else
1122
+			   	{
1123
+					$this->db->commit();
1124
+					return 1;
1125
+			   	}
1126
+			   	else
1127
+			  	{
1128
+			   		$this->db->rollback();
1129
+					return -1;
1130
+			   	}
1131
+			}
1132
+
1133
+			return 0;
1134
+		}
1135
+		else
1136 1136
 		{
1137
-            // Mise à jour pour un utilisateur
1138
-            $nbHoliday = price2num($nbHoliday,5);
1139
-
1140
-            $sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users";
1141
-            $sql.= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type;
1142
-            $resql = $this->db->query($sql);
1143
-            if ($resql)
1144
-            {
1145
-            	$num = $this->db->num_rows($resql);
1146
-
1147
-            	if ($num > 0)
1148
-            	{
1149
-		            // Update for user
1150
-		            $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
1151
-		            $sql.= " nb_holiday = ".$nbHoliday;
1152
-		            $sql.= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type;
1153
-		            $result = $this->db->query($sql);
1154
-		            if (! $result)
1155
-		            {
1156
-		            	$error++;
1157
-		            	$this->errors[]=$this->db->lasterror();
1158
-		            }
1159
-            	}
1160
-            	else
1161
-            	{
1162
-		            // Insert for user
1163
-		            $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1164
-		            $sql.= $nbHoliday;
1165
-		            $sql.= ", '".$userID."', ".$fk_type.")";
1166
-		            $result = $this->db->query($sql);
1167
-		            if (! $result)
1168
-		            {
1169
-		            	$error++;
1170
-		            	$this->errors[]=$this->db->lasterror();
1171
-		            }
1172
-            	}
1173
-            }
1174
-            else
1137
+			// Mise à jour pour un utilisateur
1138
+			$nbHoliday = price2num($nbHoliday,5);
1139
+
1140
+			$sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users";
1141
+			$sql.= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type;
1142
+			$resql = $this->db->query($sql);
1143
+			if ($resql)
1175 1144
 			{
1176
-		        $this->errors[]=$this->db->lasterror();
1177
-            	$error++;
1145
+				$num = $this->db->num_rows($resql);
1146
+
1147
+				if ($num > 0)
1148
+				{
1149
+					// Update for user
1150
+					$sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
1151
+					$sql.= " nb_holiday = ".$nbHoliday;
1152
+					$sql.= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type;
1153
+					$result = $this->db->query($sql);
1154
+					if (! $result)
1155
+					{
1156
+						$error++;
1157
+						$this->errors[]=$this->db->lasterror();
1158
+					}
1159
+				}
1160
+				else
1161
+				{
1162
+					// Insert for user
1163
+					$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1164
+					$sql.= $nbHoliday;
1165
+					$sql.= ", '".$userID."', ".$fk_type.")";
1166
+					$result = $this->db->query($sql);
1167
+					if (! $result)
1168
+					{
1169
+						$error++;
1170
+						$this->errors[]=$this->db->lasterror();
1171
+					}
1172
+				}
1173
+			}
1174
+			else
1175
+			{
1176
+				$this->errors[]=$this->db->lasterror();
1177
+				$error++;
1178
+			}
1179
+
1180
+			if (! $error)
1181
+			{
1182
+				return 1;
1183
+			}
1184
+			else
1185
+		   {
1186
+				return -1;
1187
+			}
1188
+		}
1189
+
1190
+	}
1191
+
1192
+	/**
1193
+	 *	Retourne un checked si vrai
1194
+	 *
1195
+	 *  @param	string	$name       name du paramètre de configuration
1196
+	 *  @return string      		retourne checked si > 0
1197
+	 */
1198
+	function getCheckOption($name) {
1199
+
1200
+		$sql = "SELECT value";
1201
+		$sql.= " FROM ".MAIN_DB_PREFIX."holiday_config";
1202
+		$sql.= " WHERE name = '".$name."'";
1203
+
1204
+		$result = $this->db->query($sql);
1205
+
1206
+		if($result) {
1207
+			$obj = $this->db->fetch_object($result);
1208
+
1209
+			// Si la valeur est 1 on retourne checked
1210
+			if($obj->value) {
1211
+				return 'checked';
1178 1212
 			}
1213
+		}
1214
+	}
1179 1215
 
1180
-            if (! $error)
1181
-            {
1182
-            	return 1;
1183
-            }
1184
-            else
1185
-           {
1186
-            	return -1;
1187
-            }
1188
-        }
1189
-
1190
-    }
1191
-
1192
-    /**
1193
-     *	Retourne un checked si vrai
1194
-     *
1195
-     *  @param	string	$name       name du paramètre de configuration
1196
-     *  @return string      		retourne checked si > 0
1197
-     */
1198
-    function getCheckOption($name) {
1199
-
1200
-        $sql = "SELECT value";
1201
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday_config";
1202
-        $sql.= " WHERE name = '".$name."'";
1203
-
1204
-        $result = $this->db->query($sql);
1205
-
1206
-        if($result) {
1207
-            $obj = $this->db->fetch_object($result);
1208
-
1209
-            // Si la valeur est 1 on retourne checked
1210
-            if($obj->value) {
1211
-                return 'checked';
1212
-            }
1213
-        }
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     *  Créer les entrées pour chaque utilisateur au moment de la configuration
1219
-     *
1220
-     *  @param	boolean		$single		Single
1221
-     *  @param	int			$userid		Id user
1222
-     *  @return void
1223
-     */
1224
-    function createCPusers($single=false,$userid='')
1225
-    {
1226
-        // Si c'est l'ensemble des utilisateurs à ajouter
1227
-        if (! $single)
1228
-        {
1229
-        	dol_syslog(get_class($this).'::createCPusers');
1230
-        	$arrayofusers = $this->fetchUsers(false,true);
1231
-
1232
-            foreach($arrayofusers as $users)
1233
-            {
1234
-                $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1235
-                $sql.= " (fk_user, nb_holiday)";
1236
-                $sql.= " VALUES ('".$users['rowid']."','0')";
1237
-
1238
-                $resql=$this->db->query($sql);
1239
-                if (! $resql) dol_print_error($this->db);
1240
-            }
1241
-        }
1242
-        else
1216
+
1217
+	/**
1218
+	 *  Créer les entrées pour chaque utilisateur au moment de la configuration
1219
+	 *
1220
+	 *  @param	boolean		$single		Single
1221
+	 *  @param	int			$userid		Id user
1222
+	 *  @return void
1223
+	 */
1224
+	function createCPusers($single=false,$userid='')
1225
+	{
1226
+		// Si c'est l'ensemble des utilisateurs à ajouter
1227
+		if (! $single)
1243 1228
 		{
1244
-            $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1245
-            $sql.= " (fk_user, nb_holiday)";
1246
-            $sql.= " VALUES ('".$userid."','0')";
1247
-
1248
-            $resql=$this->db->query($sql);
1249
-            if (! $resql) dol_print_error($this->db);
1250
-        }
1251
-    }
1252
-
1253
-    /**
1254
-     *  Supprime un utilisateur du module Congés Payés
1255
-     *
1256
-     *  @param	int		$user_id        ID de l'utilisateur à supprimer
1257
-     *  @return boolean      			Vrai si pas d'erreur, faut si Erreur
1258
-     */
1259
-    function deleteCPuser($user_id) {
1260
-
1261
-        $sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday_users";
1262
-        $sql.= " WHERE fk_user = '".$user_id."'";
1263
-
1264
-        $this->db->query($sql);
1265
-
1266
-    }
1267
-
1268
-
1269
-    /**
1270
-     *  Retourne le solde de congés payés pour un utilisateur
1271
-     *
1272
-     *  @param	int		$user_id    ID de l'utilisateur
1273
-     *  @param	int		$fk_type	Filter on type
1274
-     *  @return float        		Retourne le solde de congés payés de l'utilisateur
1275
-     */
1276
-    function getCPforUser($user_id, $fk_type=0)
1277
-    {
1278
-        $sql = "SELECT nb_holiday";
1279
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users";
1280
-        $sql.= " WHERE fk_user = '".$user_id."'";
1281
-        if ($fk_type > 0) $sql.=" AND fk_type = ".$fk_type;
1282
-
1283
-        dol_syslog(get_class($this).'::getCPforUser', LOG_DEBUG);
1284
-        $result = $this->db->query($sql);
1285
-        if($result)
1286
-        {
1287
-            $obj = $this->db->fetch_object($result);
1288
-            //return number_format($obj->nb_holiday,2);
1289
-            if ($obj) return $obj->nb_holiday;
1290
-            else return null;
1291
-        }
1292
-        else
1229
+			dol_syslog(get_class($this).'::createCPusers');
1230
+			$arrayofusers = $this->fetchUsers(false,true);
1231
+
1232
+			foreach($arrayofusers as $users)
1233
+			{
1234
+				$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1235
+				$sql.= " (fk_user, nb_holiday)";
1236
+				$sql.= " VALUES ('".$users['rowid']."','0')";
1237
+
1238
+				$resql=$this->db->query($sql);
1239
+				if (! $resql) dol_print_error($this->db);
1240
+			}
1241
+		}
1242
+		else
1293 1243
 		{
1294
-            return null;
1295
-        }
1296
-    }
1297
-
1298
-    /**
1299
-     *    Get list of Users or list of vacation balance.
1300
-     *
1301
-     *    @param      boolean			$stringlist	    If true return a string list of id. If false, return an array with detail.
1302
-     *    @param      boolean   		$type			If true, read Dolibarr user list, if false, return vacation balance list.
1303
-     *    @param      string            $filters        Filters
1304
-     *    @return     array|string|int      			Return an array
1305
-     */
1306
-    function fetchUsers($stringlist=true, $type=true, $filters='')
1307
-    {
1308
-    	global $conf;
1309
-
1310
-    	dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG);
1311
-
1312
-        if ($stringlist)
1313
-        {
1314
-            if ($type)
1315
-            {
1316
-                // Si utilisateur de Dolibarr
1317
-
1318
-                $sql = "SELECT u.rowid";
1319
-                $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
1320
-
1321
-                if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1322
-                {
1323
-                	$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1324
-                	$sql.= " WHERE (ug.fk_user = u.rowid";
1325
-                	$sql.= " AND ug.entity = ".$conf->entity.")";
1326
-                	$sql.= " OR u.admin = 1";
1327
-                }
1328
-                else
1329
-                {
1330
-                	$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
1331
-                }
1332
-                $sql.= " AND u.statut > 0";
1333
-                if ($filters) $sql.=$filters;
1334
-
1335
-                $resql=$this->db->query($sql);
1336
-
1337
-                // Si pas d'erreur SQL
1338
-                if ($resql) {
1339
-
1340
-                    $i = 0;
1341
-                    $num = $this->db->num_rows($resql);
1342
-                    $stringlist = '';
1343
-
1344
-                    // Boucles du listage des utilisateurs
1345
-                    while($i < $num)
1346
-                    {
1347
-                        $obj = $this->db->fetch_object($resql);
1348
-
1349
-                        if ($i == 0) {
1350
-                            $stringlist.= $obj->rowid;
1351
-                        } else {
1352
-                            $stringlist.= ', '.$obj->rowid;
1353
-                        }
1354
-
1355
-                        $i++;
1356
-                    }
1357
-                    // Retoune le tableau des utilisateurs
1358
-                    return $stringlist;
1359
-                }
1360
-                else
1361
-                {
1362
-                    // Erreur SQL
1363
-                    $this->error="Error ".$this->db->lasterror();
1364
-                    return -1;
1365
-                }
1366
-
1367
-            }
1368
-            else
1369
-            {
1370
-           		// We want only list of vacation balance for user ids
1371
-                $sql = "SELECT DISTINCT cpu.fk_user";
1372
-                $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1373
-                $sql.= " WHERE cpu.fk_user = u.user";
1374
-                if ($filters) $sql.=$filters;
1375
-
1376
-                $resql=$this->db->query($sql);
1377
-
1378
-                // Si pas d'erreur SQL
1379
-                if ($resql) {
1380
-
1381
-                    $i = 0;
1382
-                    $num = $this->db->num_rows($resql);
1383
-                    $stringlist = '';
1384
-
1385
-                    // Boucles du listage des utilisateurs
1386
-                    while($i < $num)
1387
-                    {
1388
-                        $obj = $this->db->fetch_object($resql);
1389
-
1390
-                        if($i == 0) {
1391
-                            $stringlist.= $obj->fk_user;
1392
-                        } else {
1393
-                            $stringlist.= ', '.$obj->fk_user;
1394
-                        }
1395
-
1396
-                        $i++;
1397
-                    }
1398
-                    // Retoune le tableau des utilisateurs
1399
-                    return $stringlist;
1400
-                }
1401
-                else
1402
-              {
1403
-                    // Erreur SQL
1404
-                    $this->error="Error ".$this->db->lasterror();
1405
-                    return -1;
1406
-                }
1407
-            }
1408
-
1409
-        }
1410
-        else
1411
-        { // Si faux donc return array
1412
-
1413
-            // List for Dolibarr users
1414
-            if ($type)
1415
-            {
1416
-                $sql = "SELECT u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1417
-                $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
1418
-
1419
-                if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1420
-                {
1421
-                	$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1422
-                	$sql.= " WHERE (ug.fk_user = u.rowid";
1423
-                	$sql.= " AND ug.entity = ".$conf->entity.")";
1424
-                	$sql.= " OR u.admin = 1";
1425
-                }
1426
-                else
1427
-                	$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
1428
-
1429
-                $sql.= " AND u.statut > 0";
1430
-                if ($filters) $sql.=$filters;
1431
-
1432
-                $resql=$this->db->query($sql);
1433
-
1434
-                // Si pas d'erreur SQL
1435
-                if ($resql)
1436
-                {
1437
-                    $i = 0;
1438
-                    $tab_result = $this->holiday;
1439
-                    $num = $this->db->num_rows($resql);
1440
-
1441
-                    // Boucles du listage des utilisateurs
1442
-                    while($i < $num) {
1443
-
1444
-                        $obj = $this->db->fetch_object($resql);
1445
-
1446
-                        $tab_result[$i]['rowid'] = $obj->rowid;
1447
-                        $tab_result[$i]['name'] = $obj->lastname;       // deprecated
1448
-                        $tab_result[$i]['lastname'] = $obj->lastname;
1449
-                        $tab_result[$i]['firstname'] = $obj->firstname;
1450
-                        $tab_result[$i]['gender'] = $obj->gender;
1451
-                        $tab_result[$i]['status'] = $obj->statut;
1452
-                        $tab_result[$i]['employee'] = $obj->employee;
1453
-                        $tab_result[$i]['photo'] = $obj->photo;
1454
-                        $tab_result[$i]['fk_user'] = $obj->fk_user;
1455
-                        //$tab_result[$i]['type'] = $obj->type;
1456
-                        //$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
1457
-
1458
-                        $i++;
1459
-                    }
1460
-                    // Retoune le tableau des utilisateurs
1461
-                    return $tab_result;
1462
-                }
1463
-                else
1244
+			$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1245
+			$sql.= " (fk_user, nb_holiday)";
1246
+			$sql.= " VALUES ('".$userid."','0')";
1247
+
1248
+			$resql=$this->db->query($sql);
1249
+			if (! $resql) dol_print_error($this->db);
1250
+		}
1251
+	}
1252
+
1253
+	/**
1254
+	 *  Supprime un utilisateur du module Congés Payés
1255
+	 *
1256
+	 *  @param	int		$user_id        ID de l'utilisateur à supprimer
1257
+	 *  @return boolean      			Vrai si pas d'erreur, faut si Erreur
1258
+	 */
1259
+	function deleteCPuser($user_id) {
1260
+
1261
+		$sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday_users";
1262
+		$sql.= " WHERE fk_user = '".$user_id."'";
1263
+
1264
+		$this->db->query($sql);
1265
+
1266
+	}
1267
+
1268
+
1269
+	/**
1270
+	 *  Retourne le solde de congés payés pour un utilisateur
1271
+	 *
1272
+	 *  @param	int		$user_id    ID de l'utilisateur
1273
+	 *  @param	int		$fk_type	Filter on type
1274
+	 *  @return float        		Retourne le solde de congés payés de l'utilisateur
1275
+	 */
1276
+	function getCPforUser($user_id, $fk_type=0)
1277
+	{
1278
+		$sql = "SELECT nb_holiday";
1279
+		$sql.= " FROM ".MAIN_DB_PREFIX."holiday_users";
1280
+		$sql.= " WHERE fk_user = '".$user_id."'";
1281
+		if ($fk_type > 0) $sql.=" AND fk_type = ".$fk_type;
1282
+
1283
+		dol_syslog(get_class($this).'::getCPforUser', LOG_DEBUG);
1284
+		$result = $this->db->query($sql);
1285
+		if($result)
1286
+		{
1287
+			$obj = $this->db->fetch_object($result);
1288
+			//return number_format($obj->nb_holiday,2);
1289
+			if ($obj) return $obj->nb_holiday;
1290
+			else return null;
1291
+		}
1292
+		else
1293
+		{
1294
+			return null;
1295
+		}
1296
+	}
1297
+
1298
+	/**
1299
+	 *    Get list of Users or list of vacation balance.
1300
+	 *
1301
+	 *    @param      boolean			$stringlist	    If true return a string list of id. If false, return an array with detail.
1302
+	 *    @param      boolean   		$type			If true, read Dolibarr user list, if false, return vacation balance list.
1303
+	 *    @param      string            $filters        Filters
1304
+	 *    @return     array|string|int      			Return an array
1305
+	 */
1306
+	function fetchUsers($stringlist=true, $type=true, $filters='')
1307
+	{
1308
+		global $conf;
1309
+
1310
+		dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG);
1311
+
1312
+		if ($stringlist)
1313
+		{
1314
+			if ($type)
1315
+			{
1316
+				// Si utilisateur de Dolibarr
1317
+
1318
+				$sql = "SELECT u.rowid";
1319
+				$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
1320
+
1321
+				if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1322
+				{
1323
+					$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1324
+					$sql.= " WHERE (ug.fk_user = u.rowid";
1325
+					$sql.= " AND ug.entity = ".$conf->entity.")";
1326
+					$sql.= " OR u.admin = 1";
1327
+				}
1328
+				else
1329
+				{
1330
+					$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
1331
+				}
1332
+				$sql.= " AND u.statut > 0";
1333
+				if ($filters) $sql.=$filters;
1334
+
1335
+				$resql=$this->db->query($sql);
1336
+
1337
+				// Si pas d'erreur SQL
1338
+				if ($resql) {
1339
+
1340
+					$i = 0;
1341
+					$num = $this->db->num_rows($resql);
1342
+					$stringlist = '';
1343
+
1344
+					// Boucles du listage des utilisateurs
1345
+					while($i < $num)
1346
+					{
1347
+						$obj = $this->db->fetch_object($resql);
1348
+
1349
+						if ($i == 0) {
1350
+							$stringlist.= $obj->rowid;
1351
+						} else {
1352
+							$stringlist.= ', '.$obj->rowid;
1353
+						}
1354
+
1355
+						$i++;
1356
+					}
1357
+					// Retoune le tableau des utilisateurs
1358
+					return $stringlist;
1359
+				}
1360
+				else
1464 1361
 				{
1465
-                    // Erreur SQL
1466
-                    $this->errors[]="Error ".$this->db->lasterror();
1467
-                    return -1;
1468
-                }
1469
-            }
1470
-            else
1471
-            {
1362
+					// Erreur SQL
1363
+					$this->error="Error ".$this->db->lasterror();
1364
+					return -1;
1365
+				}
1366
+
1367
+			}
1368
+			else
1369
+			{
1370
+		   		// We want only list of vacation balance for user ids
1371
+				$sql = "SELECT DISTINCT cpu.fk_user";
1372
+				$sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1373
+				$sql.= " WHERE cpu.fk_user = u.user";
1374
+				if ($filters) $sql.=$filters;
1375
+
1376
+				$resql=$this->db->query($sql);
1377
+
1378
+				// Si pas d'erreur SQL
1379
+				if ($resql) {
1380
+
1381
+					$i = 0;
1382
+					$num = $this->db->num_rows($resql);
1383
+					$stringlist = '';
1384
+
1385
+					// Boucles du listage des utilisateurs
1386
+					while($i < $num)
1387
+					{
1388
+						$obj = $this->db->fetch_object($resql);
1389
+
1390
+						if($i == 0) {
1391
+							$stringlist.= $obj->fk_user;
1392
+						} else {
1393
+							$stringlist.= ', '.$obj->fk_user;
1394
+						}
1395
+
1396
+						$i++;
1397
+					}
1398
+					// Retoune le tableau des utilisateurs
1399
+					return $stringlist;
1400
+				}
1401
+				else
1402
+			  {
1403
+					// Erreur SQL
1404
+					$this->error="Error ".$this->db->lasterror();
1405
+					return -1;
1406
+				}
1407
+			}
1408
+
1409
+		}
1410
+		else
1411
+		{ // Si faux donc return array
1412
+
1413
+			// List for Dolibarr users
1414
+			if ($type)
1415
+			{
1416
+				$sql = "SELECT u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1417
+				$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
1418
+
1419
+				if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1420
+				{
1421
+					$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1422
+					$sql.= " WHERE (ug.fk_user = u.rowid";
1423
+					$sql.= " AND ug.entity = ".$conf->entity.")";
1424
+					$sql.= " OR u.admin = 1";
1425
+				}
1426
+				else
1427
+					$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
1428
+
1429
+				$sql.= " AND u.statut > 0";
1430
+				if ($filters) $sql.=$filters;
1431
+
1432
+				$resql=$this->db->query($sql);
1433
+
1434
+				// Si pas d'erreur SQL
1435
+				if ($resql)
1436
+				{
1437
+					$i = 0;
1438
+					$tab_result = $this->holiday;
1439
+					$num = $this->db->num_rows($resql);
1440
+
1441
+					// Boucles du listage des utilisateurs
1442
+					while($i < $num) {
1443
+
1444
+						$obj = $this->db->fetch_object($resql);
1445
+
1446
+						$tab_result[$i]['rowid'] = $obj->rowid;
1447
+						$tab_result[$i]['name'] = $obj->lastname;       // deprecated
1448
+						$tab_result[$i]['lastname'] = $obj->lastname;
1449
+						$tab_result[$i]['firstname'] = $obj->firstname;
1450
+						$tab_result[$i]['gender'] = $obj->gender;
1451
+						$tab_result[$i]['status'] = $obj->statut;
1452
+						$tab_result[$i]['employee'] = $obj->employee;
1453
+						$tab_result[$i]['photo'] = $obj->photo;
1454
+						$tab_result[$i]['fk_user'] = $obj->fk_user;
1455
+						//$tab_result[$i]['type'] = $obj->type;
1456
+						//$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
1457
+
1458
+						$i++;
1459
+					}
1460
+					// Retoune le tableau des utilisateurs
1461
+					return $tab_result;
1462
+				}
1463
+				else
1464
+				{
1465
+					// Erreur SQL
1466
+					$this->errors[]="Error ".$this->db->lasterror();
1467
+					return -1;
1468
+				}
1469
+			}
1470
+			else
1471
+			{
1472 1472
 				// List of vacation balance users
1473
-                $sql = "SELECT cpu.fk_user, cpu.fk_type, cpu.nb_holiday, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1474
-                $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1475
-                $sql.= " WHERE cpu.fk_user = u.rowid";
1476
-                if ($filters) $sql.=$filters;
1477
-
1478
-                $resql=$this->db->query($sql);
1479
-
1480
-                // Si pas d'erreur SQL
1481
-                if ($resql)
1482
-                {
1483
-                    $i = 0;
1484
-                    $tab_result = $this->holiday;
1485
-                    $num = $this->db->num_rows($resql);
1486
-
1487
-                    // Boucles du listage des utilisateurs
1488
-                    while($i < $num)
1489
-                    {
1490
-                        $obj = $this->db->fetch_object($resql);
1491
-
1492
-                        $tab_result[$i]['rowid'] = $obj->fk_user;
1493
-                        $tab_result[$i]['name'] = $obj->lastname;			// deprecated
1494
-                        $tab_result[$i]['lastname'] = $obj->lastname;
1495
-                        $tab_result[$i]['firstname'] = $obj->firstname;
1496
-                        $tab_result[$i]['gender'] = $obj->gender;
1497
-                        $tab_result[$i]['status'] = $obj->statut;
1498
-                        $tab_result[$i]['employee'] = $obj->employee;
1499
-                        $tab_result[$i]['photo'] = $obj->photo;
1500
-                        $tab_result[$i]['fk_user'] = $obj->fk_user;
1501
-
1502
-                        $tab_result[$i]['type'] = $obj->type;
1503
-                        $tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
1504
-
1505
-                        $i++;
1506
-                    }
1507
-                    // Retoune le tableau des utilisateurs
1508
-                    return $tab_result;
1509
-                }
1510
-                else
1473
+				$sql = "SELECT cpu.fk_user, cpu.fk_type, cpu.nb_holiday, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1474
+				$sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1475
+				$sql.= " WHERE cpu.fk_user = u.rowid";
1476
+				if ($filters) $sql.=$filters;
1477
+
1478
+				$resql=$this->db->query($sql);
1479
+
1480
+				// Si pas d'erreur SQL
1481
+				if ($resql)
1511 1482
 				{
1512
-                    // Erreur SQL
1513
-                    $this->error="Error ".$this->db->lasterror();
1514
-                    return -1;
1515
-                }
1516
-            }
1517
-        }
1518
-    }
1519
-
1520
-    /**
1521
-     *	Compte le nombre d'utilisateur actifs dans Dolibarr
1522
-     *
1523
-     *  @return     int      retourne le nombre d'utilisateur
1524
-     */
1525
-    function countActiveUsers()
1526
-    {
1527
-        $sql = "SELECT count(u.rowid) as compteur";
1528
-        $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
1483
+					$i = 0;
1484
+					$tab_result = $this->holiday;
1485
+					$num = $this->db->num_rows($resql);
1486
+
1487
+					// Boucles du listage des utilisateurs
1488
+					while($i < $num)
1489
+					{
1490
+						$obj = $this->db->fetch_object($resql);
1491
+
1492
+						$tab_result[$i]['rowid'] = $obj->fk_user;
1493
+						$tab_result[$i]['name'] = $obj->lastname;			// deprecated
1494
+						$tab_result[$i]['lastname'] = $obj->lastname;
1495
+						$tab_result[$i]['firstname'] = $obj->firstname;
1496
+						$tab_result[$i]['gender'] = $obj->gender;
1497
+						$tab_result[$i]['status'] = $obj->statut;
1498
+						$tab_result[$i]['employee'] = $obj->employee;
1499
+						$tab_result[$i]['photo'] = $obj->photo;
1500
+						$tab_result[$i]['fk_user'] = $obj->fk_user;
1501
+
1502
+						$tab_result[$i]['type'] = $obj->type;
1503
+						$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
1504
+
1505
+						$i++;
1506
+					}
1507
+					// Retoune le tableau des utilisateurs
1508
+					return $tab_result;
1509
+				}
1510
+				else
1511
+				{
1512
+					// Erreur SQL
1513
+					$this->error="Error ".$this->db->lasterror();
1514
+					return -1;
1515
+				}
1516
+			}
1517
+		}
1518
+	}
1519
+
1520
+	/**
1521
+	 *	Compte le nombre d'utilisateur actifs dans Dolibarr
1522
+	 *
1523
+	 *  @return     int      retourne le nombre d'utilisateur
1524
+	 */
1525
+	function countActiveUsers()
1526
+	{
1527
+		$sql = "SELECT count(u.rowid) as compteur";
1528
+		$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
1529 1529
 		$sql.= " WHERE u.statut > 0";
1530 1530
 
1531
-        $result = $this->db->query($sql);
1532
-        $objet = $this->db->fetch_object($result);
1531
+		$result = $this->db->query($sql);
1532
+		$objet = $this->db->fetch_object($result);
1533 1533
 
1534
-        return $objet->compteur;
1535
-    }
1536
-    /**
1537
-     *	Compte le nombre d'utilisateur actifs dans Dolibarr sans CP
1538
-     *
1539
-     *  @return     int      retourne le nombre d'utilisateur
1540
-     */
1541
-    function countActiveUsersWithoutCP() {
1534
+		return $objet->compteur;
1535
+	}
1536
+	/**
1537
+	 *	Compte le nombre d'utilisateur actifs dans Dolibarr sans CP
1538
+	 *
1539
+	 *  @return     int      retourne le nombre d'utilisateur
1540
+	 */
1541
+	function countActiveUsersWithoutCP() {
1542 1542
 
1543
-        $sql = "SELECT count(u.rowid) as compteur";
1544
-        $sql.= " FROM ".MAIN_DB_PREFIX."user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX."holiday_users hu ON (hu.fk_user=u.rowid)";
1543
+		$sql = "SELECT count(u.rowid) as compteur";
1544
+		$sql.= " FROM ".MAIN_DB_PREFIX."user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX."holiday_users hu ON (hu.fk_user=u.rowid)";
1545 1545
 		$sql.= " WHERE u.statut > 0 AND hu.fk_user IS NULL";
1546 1546
 
1547
-        $result = $this->db->query($sql);
1548
-        $objet = $this->db->fetch_object($result);
1549
-
1550
-        return $objet->compteur;
1551
-    }
1552
-
1553
-    /**
1554
-     *  Compare le nombre d'utilisateur actif de Dolibarr à celui des utilisateurs des congés payés
1555
-     *
1556
-     *  @param    int	$userDolibarrWithoutCP	Number of active users in Dolibarr without holidays
1557
-     *  @param    int	$userCP    				Number of active users into table of holidays
1558
-     *  @return   int							<0 if KO, >0 if OK
1559
-     */
1560
-    function verifNbUsers($userDolibarrWithoutCP, $userCP)
1561
-    {
1562
-    	if (empty($userCP)) $userCP=0;
1563
-    	dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
1564
-        return 1;
1565
-    }
1566
-
1567
-
1568
-    /**
1569
-     * addLogCP
1570
-     *
1571
-     * @param 	int		$fk_user_action		Id user creation
1572
-     * @param 	int		$fk_user_update		Id user update
1573
-     * @param 	string	$label				Label
1574
-     * @param 	int		$new_solde			New value
1575
-     * @param	int		$fk_type			Type of vacation
1576
-     * @return 	int							Id of record added, 0 if nothing done, < 0 if KO
1577
-     */
1578
-    function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
1579
-    {
1580
-        global $conf, $langs;
1581
-
1582
-        $error=0;
1583
-
1584
-        $prev_solde = price2num($this->getCPforUser($fk_user_update, $fk_type), 5);
1585
-        $new_solde = price2num($new_solde, 5);
1547
+		$result = $this->db->query($sql);
1548
+		$objet = $this->db->fetch_object($result);
1549
+
1550
+		return $objet->compteur;
1551
+	}
1552
+
1553
+	/**
1554
+	 *  Compare le nombre d'utilisateur actif de Dolibarr à celui des utilisateurs des congés payés
1555
+	 *
1556
+	 *  @param    int	$userDolibarrWithoutCP	Number of active users in Dolibarr without holidays
1557
+	 *  @param    int	$userCP    				Number of active users into table of holidays
1558
+	 *  @return   int							<0 if KO, >0 if OK
1559
+	 */
1560
+	function verifNbUsers($userDolibarrWithoutCP, $userCP)
1561
+	{
1562
+		if (empty($userCP)) $userCP=0;
1563
+		dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
1564
+		return 1;
1565
+	}
1566
+
1567
+
1568
+	/**
1569
+	 * addLogCP
1570
+	 *
1571
+	 * @param 	int		$fk_user_action		Id user creation
1572
+	 * @param 	int		$fk_user_update		Id user update
1573
+	 * @param 	string	$label				Label
1574
+	 * @param 	int		$new_solde			New value
1575
+	 * @param	int		$fk_type			Type of vacation
1576
+	 * @return 	int							Id of record added, 0 if nothing done, < 0 if KO
1577
+	 */
1578
+	function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
1579
+	{
1580
+		global $conf, $langs;
1581
+
1582
+		$error=0;
1583
+
1584
+		$prev_solde = price2num($this->getCPforUser($fk_user_update, $fk_type), 5);
1585
+		$new_solde = price2num($new_solde, 5);
1586 1586
 		//print "$prev_solde == $new_solde";
1587 1587
 
1588
-        if ($prev_solde == $new_solde) return 0;
1588
+		if ($prev_solde == $new_solde) return 0;
1589 1589
 
1590 1590
 		$this->db->begin();
1591 1591
 
1592 1592
 		// Insert request
1593
-        $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_logs (";
1594
-        $sql.= "date_action,";
1595
-        $sql.= "fk_user_action,";
1596
-        $sql.= "fk_user_update,";
1597
-        $sql.= "type_action,";
1598
-        $sql.= "prev_solde,";
1599
-        $sql.= "new_solde,";
1593
+		$sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_logs (";
1594
+		$sql.= "date_action,";
1595
+		$sql.= "fk_user_action,";
1596
+		$sql.= "fk_user_update,";
1597
+		$sql.= "type_action,";
1598
+		$sql.= "prev_solde,";
1599
+		$sql.= "new_solde,";
1600 1600
 		$sql.= "fk_type";
1601
-        $sql.= ") VALUES (";
1602
-        $sql.= " '".$this->db->idate(dol_now())."',";
1603
-        $sql.= " '".$fk_user_action."',";
1604
-        $sql.= " '".$fk_user_update."',";
1605
-        $sql.= " '".$this->db->escape($label)."',";
1606
-        $sql.= " '".$prev_solde."',";
1607
-        $sql.= " '".$new_solde."',";
1608
-        $sql.= " ".$fk_type;
1609
-        $sql.= ")";
1610
-
1611
-        $resql=$this->db->query($sql);
1612
-       	if (! $resql)
1613
-       	{
1614
-       	    $error++; $this->errors[]="Error ".$this->db->lasterror();
1615
-       	}
1616
-
1617
-       	if (! $error)
1618
-       	{
1619
-       	    $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs");
1620
-       	}
1621
-
1622
-       	// Commit or rollback
1623
-       	if ($error)
1624
-       	{
1625
-       	    foreach($this->errors as $errmsg)
1626
-       	    {
1627
-   	            dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR);
1628
-   	            $this->error.=($this->error?', '.$errmsg:$errmsg);
1629
-       	    }
1630
-       	    $this->db->rollback();
1631
-       	    return -1*$error;
1632
-       	}
1633
-       	else
1634
-       	{
1635
-       	    $this->db->commit();
1636
-            return $this->optRowid;
1637
-       	}
1638
-    }
1639
-
1640
-    /**
1641
-     *  Liste le log des congés payés
1642
-     *
1643
-     *  @param	string	$order      Filtrage par ordre
1644
-     *  @param  string	$filter     Filtre de séléction
1645
-     *  @return int         		-1 si erreur, 1 si OK et 2 si pas de résultat
1646
-     */
1647
-    function fetchLog($order,$filter)
1648
-    {
1649
-        global $langs;
1650
-
1651
-        $sql = "SELECT";
1652
-        $sql.= " cpl.rowid,";
1653
-        $sql.= " cpl.date_action,";
1654
-        $sql.= " cpl.fk_user_action,";
1655
-        $sql.= " cpl.fk_user_update,";
1656
-        $sql.= " cpl.type_action,";
1657
-        $sql.= " cpl.prev_solde,";
1658
-        $sql.= " cpl.new_solde,";
1601
+		$sql.= ") VALUES (";
1602
+		$sql.= " '".$this->db->idate(dol_now())."',";
1603
+		$sql.= " '".$fk_user_action."',";
1604
+		$sql.= " '".$fk_user_update."',";
1605
+		$sql.= " '".$this->db->escape($label)."',";
1606
+		$sql.= " '".$prev_solde."',";
1607
+		$sql.= " '".$new_solde."',";
1608
+		$sql.= " ".$fk_type;
1609
+		$sql.= ")";
1610
+
1611
+		$resql=$this->db->query($sql);
1612
+	   	if (! $resql)
1613
+	   	{
1614
+	   		$error++; $this->errors[]="Error ".$this->db->lasterror();
1615
+	   	}
1616
+
1617
+	   	if (! $error)
1618
+	   	{
1619
+	   		$this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs");
1620
+	   	}
1621
+
1622
+	   	// Commit or rollback
1623
+	   	if ($error)
1624
+	   	{
1625
+	   		foreach($this->errors as $errmsg)
1626
+	   		{
1627
+   				dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR);
1628
+   				$this->error.=($this->error?', '.$errmsg:$errmsg);
1629
+	   		}
1630
+	   		$this->db->rollback();
1631
+	   		return -1*$error;
1632
+	   	}
1633
+	   	else
1634
+	   	{
1635
+	   		$this->db->commit();
1636
+			return $this->optRowid;
1637
+	   	}
1638
+	}
1639
+
1640
+	/**
1641
+	 *  Liste le log des congés payés
1642
+	 *
1643
+	 *  @param	string	$order      Filtrage par ordre
1644
+	 *  @param  string	$filter     Filtre de séléction
1645
+	 *  @return int         		-1 si erreur, 1 si OK et 2 si pas de résultat
1646
+	 */
1647
+	function fetchLog($order,$filter)
1648
+	{
1649
+		global $langs;
1650
+
1651
+		$sql = "SELECT";
1652
+		$sql.= " cpl.rowid,";
1653
+		$sql.= " cpl.date_action,";
1654
+		$sql.= " cpl.fk_user_action,";
1655
+		$sql.= " cpl.fk_user_update,";
1656
+		$sql.= " cpl.type_action,";
1657
+		$sql.= " cpl.prev_solde,";
1658
+		$sql.= " cpl.new_solde,";
1659 1659
 		$sql.= " cpl.fk_type";
1660
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday_logs as cpl";
1661
-        $sql.= " WHERE cpl.rowid > 0"; // To avoid error with other search and criteria
1660
+		$sql.= " FROM ".MAIN_DB_PREFIX."holiday_logs as cpl";
1661
+		$sql.= " WHERE cpl.rowid > 0"; // To avoid error with other search and criteria
1662 1662
 
1663
-        // Filtrage de séléction
1664
-        if(!empty($filter)) {
1665
-            $sql.= " ".$filter;
1666
-        }
1663
+		// Filtrage de séléction
1664
+		if(!empty($filter)) {
1665
+			$sql.= " ".$filter;
1666
+		}
1667 1667
 
1668
-        // Ordre d'affichage
1669
-        if(!empty($order)) {
1670
-            $sql.= " ".$order;
1671
-        }
1668
+		// Ordre d'affichage
1669
+		if(!empty($order)) {
1670
+			$sql.= " ".$order;
1671
+		}
1672 1672
 
1673
-        dol_syslog(get_class($this)."::fetchLog", LOG_DEBUG);
1674
-        $resql=$this->db->query($sql);
1673
+		dol_syslog(get_class($this)."::fetchLog", LOG_DEBUG);
1674
+		$resql=$this->db->query($sql);
1675 1675
 
1676
-        // Si pas d'erreur SQL
1676
+		// Si pas d'erreur SQL
1677 1677
   		if ($resql) {
1678 1678
 
1679
-  		    $i = 0;
1680
-  		    $tab_result = $this->logs;
1681
-  		    $num = $this->db->num_rows($resql);
1682
-
1683
-  		    // Si pas d'enregistrement
1684
-  		    if(!$num) {
1685
-                return 2;
1686
-  		    }
1687
-
1688
-  		    // On liste les résultats et on les ajoutent dans le tableau
1689
-  		    while($i < $num) {
1690
-
1691
-  		        $obj = $this->db->fetch_object($resql);
1692
-
1693
-  		        $tab_result[$i]['rowid'] = $obj->rowid;
1694
-  		        $tab_result[$i]['date_action'] = $obj->date_action;
1695
-  		        $tab_result[$i]['fk_user_action'] = $obj->fk_user_action;
1696
-  		        $tab_result[$i]['fk_user_update'] = $obj->fk_user_update;
1697
-  		        $tab_result[$i]['type_action'] = $obj->type_action;
1698
-  		        $tab_result[$i]['prev_solde'] = $obj->prev_solde;
1699
-  		        $tab_result[$i]['new_solde'] = $obj->new_solde;
1700
-  		        $tab_result[$i]['fk_type'] = $obj->fk_type;
1701
-
1702
-  		        $i++;
1703
-  		    }
1704
-  		    // Retourne 1 et ajoute le tableau à la variable
1705
-  		    $this->logs = $tab_result;
1706
-  		    return 1;
1679
+  			$i = 0;
1680
+  			$tab_result = $this->logs;
1681
+  			$num = $this->db->num_rows($resql);
1682
+
1683
+  			// Si pas d'enregistrement
1684
+  			if(!$num) {
1685
+				return 2;
1686
+  			}
1687
+
1688
+  			// On liste les résultats et on les ajoutent dans le tableau
1689
+  			while($i < $num) {
1690
+
1691
+  				$obj = $this->db->fetch_object($resql);
1692
+
1693
+  				$tab_result[$i]['rowid'] = $obj->rowid;
1694
+  				$tab_result[$i]['date_action'] = $obj->date_action;
1695
+  				$tab_result[$i]['fk_user_action'] = $obj->fk_user_action;
1696
+  				$tab_result[$i]['fk_user_update'] = $obj->fk_user_update;
1697
+  				$tab_result[$i]['type_action'] = $obj->type_action;
1698
+  				$tab_result[$i]['prev_solde'] = $obj->prev_solde;
1699
+  				$tab_result[$i]['new_solde'] = $obj->new_solde;
1700
+  				$tab_result[$i]['fk_type'] = $obj->fk_type;
1701
+
1702
+  				$i++;
1703
+  			}
1704
+  			// Retourne 1 et ajoute le tableau à la variable
1705
+  			$this->logs = $tab_result;
1706
+  			return 1;
1707 1707
   		}
1708 1708
   		else
1709 1709
   		{
1710
-  		    // Erreur SQL
1711
-  		    $this->error="Error ".$this->db->lasterror();
1712
-  		    return -1;
1710
+  			// Erreur SQL
1711
+  			$this->error="Error ".$this->db->lasterror();
1712
+  			return -1;
1713 1713
   		}
1714
-    }
1715
-
1716
-
1717
-    /**
1718
-     *  Return array with list of types
1719
-     *
1720
-     *  @param		int		$active		Status of type. -1 = Both
1721
-     *  @param		int		$affect		Filter on affect (a request will change sold or not). -1 = Both
1722
-     *  @return     array	    		Return array with list of types
1723
-     */
1724
-    function getTypes($active=-1, $affect=-1)
1725
-    {
1726
-    	global $mysoc;
1727
-
1728
-    	$sql = "SELECT rowid, code, label, affect, delay, newByMonth";
1729
-    	$sql.= " FROM " . MAIN_DB_PREFIX . "c_holiday_types";
1730
-    	$sql.= " WHERE (fk_country IS NULL OR fk_country = ".$mysoc->country_id.')';
1731
-    	if ($active >= 0) $sql.=" AND active = ".((int) $active);
1732
-    	if ($affect >= 0) $sql.=" AND affect = ".((int) $affect);
1733
-
1734
-    	$result = $this->db->query($sql);
1735
-    	if ($result)
1736
-    	{
1737
-	    	$num = $this->db->num_rows($result);
1738
-	    	if ($num)
1739
-	    	{
1740
-	    		while ($obj = $this->db->fetch_object($result))
1741
-	    		{
1742
-	    			$types[$obj->rowid] = array('rowid'=> $obj->rowid, 'code'=> $obj->code, 'label'=>$obj->label, 'affect'=>$obj->affect, 'delay'=>$obj->delay, 'newByMonth'=>$obj->newByMonth);
1743
-	    		}
1744
-
1745
-	    		return $types;
1746
-	    	}
1747
-    	}
1748
-    	else dol_print_error($this->db);
1749
-
1750
-    	return array();
1751
-    }
1752
-
1753
-
1754
-    /**
1755
-     *  Initialise an instance with random values.
1756
-     *  Used to build previews or test instances.
1757
-     *	id must be 0 if object instance is a specimen.
1758
-     *
1759
-     *  @return	void
1760
-     */
1761
-    function initAsSpecimen()
1762
-    {
1763
-    	global $user,$langs;
1764
-
1765
-    	// Initialise parameters
1766
-    	$this->id=0;
1767
-    	$this->specimen=1;
1768
-
1769
-    	$this->fk_user=1;
1770
-    	$this->description='SPECIMEN description';
1771
-    	$this->date_debut=dol_now();
1772
-    	$this->date_fin=dol_now()+(24*3600);
1773
-    	$this->fk_validator=1;
1774
-    	$this->halfday=0;
1775
-    	$this->fk_type=1;
1776
-    }
1714
+	}
1715
+
1716
+
1717
+	/**
1718
+	 *  Return array with list of types
1719
+	 *
1720
+	 *  @param		int		$active		Status of type. -1 = Both
1721
+	 *  @param		int		$affect		Filter on affect (a request will change sold or not). -1 = Both
1722
+	 *  @return     array	    		Return array with list of types
1723
+	 */
1724
+	function getTypes($active=-1, $affect=-1)
1725
+	{
1726
+		global $mysoc;
1727
+
1728
+		$sql = "SELECT rowid, code, label, affect, delay, newByMonth";
1729
+		$sql.= " FROM " . MAIN_DB_PREFIX . "c_holiday_types";
1730
+		$sql.= " WHERE (fk_country IS NULL OR fk_country = ".$mysoc->country_id.')';
1731
+		if ($active >= 0) $sql.=" AND active = ".((int) $active);
1732
+		if ($affect >= 0) $sql.=" AND affect = ".((int) $affect);
1733
+
1734
+		$result = $this->db->query($sql);
1735
+		if ($result)
1736
+		{
1737
+			$num = $this->db->num_rows($result);
1738
+			if ($num)
1739
+			{
1740
+				while ($obj = $this->db->fetch_object($result))
1741
+				{
1742
+					$types[$obj->rowid] = array('rowid'=> $obj->rowid, 'code'=> $obj->code, 'label'=>$obj->label, 'affect'=>$obj->affect, 'delay'=>$obj->delay, 'newByMonth'=>$obj->newByMonth);
1743
+				}
1744
+
1745
+				return $types;
1746
+			}
1747
+		}
1748
+		else dol_print_error($this->db);
1749
+
1750
+		return array();
1751
+	}
1752
+
1753
+
1754
+	/**
1755
+	 *  Initialise an instance with random values.
1756
+	 *  Used to build previews or test instances.
1757
+	 *	id must be 0 if object instance is a specimen.
1758
+	 *
1759
+	 *  @return	void
1760
+	 */
1761
+	function initAsSpecimen()
1762
+	{
1763
+		global $user,$langs;
1764
+
1765
+		// Initialise parameters
1766
+		$this->id=0;
1767
+		$this->specimen=1;
1768
+
1769
+		$this->fk_user=1;
1770
+		$this->description='SPECIMEN description';
1771
+		$this->date_debut=dol_now();
1772
+		$this->date_fin=dol_now()+(24*3600);
1773
+		$this->fk_validator=1;
1774
+		$this->halfday=0;
1775
+		$this->fk_type=1;
1776
+	}
1777 1777
 
1778 1778
 }
Please login to merge, or discard this patch.
Spacing   +460 added lines, -460 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
  *    \ingroup    holiday
25 25
  *    \brief      Class file of the module paid holiday.
26 26
  */
27
-require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
27
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28 28
 
29 29
 
30 30
 /**
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class Holiday extends CommonObject
34 34
 {
35
-	public $element='holiday';
36
-	public $table_element='holiday';
37
-	protected $isnolinkedbythird = 1;     // No field fk_soc
38
-	protected $ismultientitymanaged = 0;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
35
+	public $element = 'holiday';
36
+	public $table_element = 'holiday';
37
+	protected $isnolinkedbythird = 1; // No field fk_soc
38
+	protected $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
39 39
     public $picto = 'holiday';
40 40
 
41 41
 	/**
@@ -45,22 +45,22 @@  discard block
 block discarded – undo
45 45
     var $rowid;
46 46
 
47 47
     var $fk_user;
48
-    var $date_create='';
48
+    var $date_create = '';
49 49
     var $description;
50
-    var $date_debut='';			// Date start in PHP server TZ
51
-    var $date_fin='';			// Date end in PHP server TZ
52
-    var $date_debut_gmt='';		// Date start in GMT
53
-    var $date_fin_gmt='';		// Date end in GMT
54
-    var $halfday='';
55
-    var $statut='';				// 1=draft, 2=validated, 3=approved
50
+    var $date_debut = ''; // Date start in PHP server TZ
51
+    var $date_fin = ''; // Date end in PHP server TZ
52
+    var $date_debut_gmt = ''; // Date start in GMT
53
+    var $date_fin_gmt = ''; // Date end in GMT
54
+    var $halfday = '';
55
+    var $statut = ''; // 1=draft, 2=validated, 3=approved
56 56
     var $fk_validator;
57
-    var $date_valid='';
57
+    var $date_valid = '';
58 58
     var $fk_user_valid;
59
-    var $date_refuse='';
59
+    var $date_refuse = '';
60 60
     var $fk_user_refuse;
61
-    var $date_cancel='';
61
+    var $date_cancel = '';
62 62
     var $fk_user_cancel;
63
-    var $detail_refuse='';
63
+    var $detail_refuse = '';
64 64
     var $fk_type;
65 65
 
66 66
     var $holiday = array();
@@ -117,61 +117,61 @@  discard block
 block discarded – undo
117 117
      *   @param     int		$notrigger	    0=launch triggers after, 1=disable triggers
118 118
      *   @return    int			         	<0 if KO, Id of created object if OK
119 119
      */
120
-    function create($user, $notrigger=0)
120
+    function create($user, $notrigger = 0)
121 121
     {
122 122
         global $conf;
123
-        $error=0;
123
+        $error = 0;
124 124
 
125
-        $now=dol_now();
125
+        $now = dol_now();
126 126
 
127 127
         // Check parameters
128
-        if (empty($this->fk_user) || ! is_numeric($this->fk_user) || $this->fk_user < 0) { $this->error="ErrorBadParameterFkUser"; return -1; }
129
-        if (empty($this->fk_validator) || ! is_numeric($this->fk_validator) || $this->fk_validator < 0)  { $this->error="ErrorBadParameterFkValidator"; return -1; }
130
-        if (empty($this->fk_type) || ! is_numeric($this->fk_type) || $this->fk_type < 0) { $this->error="ErrorBadParameterFkType"; return -1; }
128
+        if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) { $this->error = "ErrorBadParameterFkUser"; return -1; }
129
+        if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) { $this->error = "ErrorBadParameterFkValidator"; return -1; }
130
+        if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) { $this->error = "ErrorBadParameterFkType"; return -1; }
131 131
 
132 132
         // Insert request
133 133
         $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday(";
134
-        $sql.= "fk_user,";
135
-        $sql.= "date_create,";
136
-        $sql.= "description,";
137
-        $sql.= "date_debut,";
138
-        $sql.= "date_fin,";
139
-        $sql.= "halfday,";
140
-        $sql.= "statut,";
141
-        $sql.= "fk_validator,";
142
-        $sql.= "fk_type,";
143
-        $sql.= "fk_user_create,";
144
-        $sql.= "entity";
145
-        $sql.= ") VALUES (";
146
-        $sql.= "'".$this->db->escape($this->fk_user)."',";
147
-        $sql.= " '".$this->db->idate($now)."',";
148
-        $sql.= " '".$this->db->escape($this->description)."',";
149
-        $sql.= " '".$this->db->idate($this->date_debut)."',";
150
-        $sql.= " '".$this->db->idate($this->date_fin)."',";
151
-        $sql.= " ".$this->halfday.",";
152
-        $sql.= " '1',";
153
-        $sql.= " '".$this->db->escape($this->fk_validator)."',";
154
-        $sql.= " ".$this->fk_type.",";
155
-        $sql.= " ".$user->id.",";
156
-        $sql.= " ".$conf->entity;
157
-        $sql.= ")";
134
+        $sql .= "fk_user,";
135
+        $sql .= "date_create,";
136
+        $sql .= "description,";
137
+        $sql .= "date_debut,";
138
+        $sql .= "date_fin,";
139
+        $sql .= "halfday,";
140
+        $sql .= "statut,";
141
+        $sql .= "fk_validator,";
142
+        $sql .= "fk_type,";
143
+        $sql .= "fk_user_create,";
144
+        $sql .= "entity";
145
+        $sql .= ") VALUES (";
146
+        $sql .= "'".$this->db->escape($this->fk_user)."',";
147
+        $sql .= " '".$this->db->idate($now)."',";
148
+        $sql .= " '".$this->db->escape($this->description)."',";
149
+        $sql .= " '".$this->db->idate($this->date_debut)."',";
150
+        $sql .= " '".$this->db->idate($this->date_fin)."',";
151
+        $sql .= " ".$this->halfday.",";
152
+        $sql .= " '1',";
153
+        $sql .= " '".$this->db->escape($this->fk_validator)."',";
154
+        $sql .= " ".$this->fk_type.",";
155
+        $sql .= " ".$user->id.",";
156
+        $sql .= " ".$conf->entity;
157
+        $sql .= ")";
158 158
 
159 159
         $this->db->begin();
160 160
 
161 161
         dol_syslog(get_class($this)."::create", LOG_DEBUG);
162
-        $resql=$this->db->query($sql);
163
-        if (! $resql) {
164
-            $error++; $this->errors[]="Error ".$this->db->lasterror();
162
+        $resql = $this->db->query($sql);
163
+        if (!$resql) {
164
+            $error++; $this->errors[] = "Error ".$this->db->lasterror();
165 165
         }
166 166
 
167
-        if (! $error)
167
+        if (!$error)
168 168
         {
169 169
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday");
170 170
 
171
-            if (! $notrigger)
171
+            if (!$notrigger)
172 172
             {
173 173
                 // Call trigger
174
-                $result=$this->call_trigger('HOLIDAY_CREATE',$user);
174
+                $result = $this->call_trigger('HOLIDAY_CREATE', $user);
175 175
                 if ($result < 0) { $error++; }
176 176
                 // End call triggers
177 177
             }
@@ -180,13 +180,13 @@  discard block
 block discarded – undo
180 180
         // Commit or rollback
181 181
         if ($error)
182 182
         {
183
-            foreach($this->errors as $errmsg)
183
+            foreach ($this->errors as $errmsg)
184 184
             {
185 185
                 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
186
-                $this->error.=($this->error?', '.$errmsg:$errmsg);
186
+                $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
187 187
             }
188 188
             $this->db->rollback();
189
-            return -1*$error;
189
+            return -1 * $error;
190 190
         }
191 191
         else
192 192
         {
@@ -207,32 +207,32 @@  discard block
 block discarded – undo
207 207
         global $langs;
208 208
 
209 209
         $sql = "SELECT";
210
-        $sql.= " cp.rowid,";
211
-        $sql.= " cp.fk_user,";
212
-        $sql.= " cp.date_create,";
213
-        $sql.= " cp.description,";
214
-        $sql.= " cp.date_debut,";
215
-        $sql.= " cp.date_fin,";
216
-        $sql.= " cp.halfday,";
217
-        $sql.= " cp.statut,";
218
-        $sql.= " cp.fk_validator,";
219
-        $sql.= " cp.date_valid,";
220
-        $sql.= " cp.fk_user_valid,";
221
-        $sql.= " cp.date_refuse,";
222
-        $sql.= " cp.fk_user_refuse,";
223
-        $sql.= " cp.date_cancel,";
224
-        $sql.= " cp.fk_user_cancel,";
225
-        $sql.= " cp.detail_refuse,";
226
-        $sql.= " cp.note_private,";
227
-        $sql.= " cp.note_public,";
228
-        $sql.= " cp.fk_user_create,";
229
-        $sql.= " cp.fk_type,";
230
-        $sql.= " cp.entity";
231
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp";
232
-        $sql.= " WHERE cp.rowid = ".$id;
210
+        $sql .= " cp.rowid,";
211
+        $sql .= " cp.fk_user,";
212
+        $sql .= " cp.date_create,";
213
+        $sql .= " cp.description,";
214
+        $sql .= " cp.date_debut,";
215
+        $sql .= " cp.date_fin,";
216
+        $sql .= " cp.halfday,";
217
+        $sql .= " cp.statut,";
218
+        $sql .= " cp.fk_validator,";
219
+        $sql .= " cp.date_valid,";
220
+        $sql .= " cp.fk_user_valid,";
221
+        $sql .= " cp.date_refuse,";
222
+        $sql .= " cp.fk_user_refuse,";
223
+        $sql .= " cp.date_cancel,";
224
+        $sql .= " cp.fk_user_cancel,";
225
+        $sql .= " cp.detail_refuse,";
226
+        $sql .= " cp.note_private,";
227
+        $sql .= " cp.note_public,";
228
+        $sql .= " cp.fk_user_create,";
229
+        $sql .= " cp.fk_type,";
230
+        $sql .= " cp.entity";
231
+        $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
232
+        $sql .= " WHERE cp.rowid = ".$id;
233 233
 
234 234
         dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
235
-        $resql=$this->db->query($sql);
235
+        $resql = $this->db->query($sql);
236 236
         if ($resql)
237 237
         {
238 238
             if ($this->db->num_rows($resql))
@@ -240,15 +240,15 @@  discard block
 block discarded – undo
240 240
                 $obj = $this->db->fetch_object($resql);
241 241
 
242 242
                 $this->id    = $obj->rowid;
243
-                $this->rowid = $obj->rowid;	// deprecated
243
+                $this->rowid = $obj->rowid; // deprecated
244 244
                 $this->ref   = $obj->rowid;
245 245
                 $this->fk_user = $obj->fk_user;
246 246
                 $this->date_create = $this->db->jdate($obj->date_create);
247 247
                 $this->description = $obj->description;
248 248
                 $this->date_debut = $this->db->jdate($obj->date_debut);
249 249
                 $this->date_fin = $this->db->jdate($obj->date_fin);
250
-                $this->date_debut_gmt = $this->db->jdate($obj->date_debut,1);
251
-                $this->date_fin_gmt = $this->db->jdate($obj->date_fin,1);
250
+                $this->date_debut_gmt = $this->db->jdate($obj->date_debut, 1);
251
+                $this->date_fin_gmt = $this->db->jdate($obj->date_fin, 1);
252 252
                 $this->halfday = $obj->halfday;
253 253
                 $this->statut = $obj->statut;
254 254
                 $this->fk_validator = $obj->fk_validator;
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
         }
272 272
         else
273 273
         {
274
-            $this->error="Error ".$this->db->lasterror();
274
+            $this->error = "Error ".$this->db->lasterror();
275 275
             return -1;
276 276
         }
277 277
     }
@@ -284,59 +284,59 @@  discard block
 block discarded – undo
284 284
      *  @param      string	$filter     SQL Filter
285 285
      *  @return     int      			-1 if KO, 1 if OK, 2 if no result
286 286
      */
287
-    function fetchByUser($user_id, $order='', $filter='')
287
+    function fetchByUser($user_id, $order = '', $filter = '')
288 288
     {
289 289
         global $langs, $conf;
290 290
 
291 291
         $sql = "SELECT";
292
-        $sql.= " cp.rowid,";
293
-
294
-        $sql.= " cp.fk_user,";
295
-		$sql.= " cp.fk_type,";
296
-		$sql.= " cp.date_create,";
297
-        $sql.= " cp.description,";
298
-        $sql.= " cp.date_debut,";
299
-        $sql.= " cp.date_fin,";
300
-        $sql.= " cp.halfday,";
301
-        $sql.= " cp.statut,";
302
-        $sql.= " cp.fk_validator,";
303
-        $sql.= " cp.date_valid,";
304
-        $sql.= " cp.fk_user_valid,";
305
-        $sql.= " cp.date_refuse,";
306
-        $sql.= " cp.fk_user_refuse,";
307
-        $sql.= " cp.date_cancel,";
308
-        $sql.= " cp.fk_user_cancel,";
309
-        $sql.= " cp.detail_refuse,";
310
-
311
-		$sql.= " uu.lastname as user_lastname,";
312
-		$sql.= " uu.firstname as user_firstname,";
313
-		$sql.= " uu.login as user_login,";
314
-		$sql.= " uu.statut as user_statut,";
315
-		$sql.= " uu.photo as user_photo,";
316
-
317
-        $sql.= " ua.lastname as validator_lastname,";
318
-        $sql.= " ua.firstname as validator_firstname,";
319
-        $sql.= " ua.login as validator_login,";
320
-        $sql.= " ua.statut as validator_statut,";
321
-        $sql.= " ua.photo as validator_photo";
322
-
323
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
324
-        $sql.= " WHERE cp.entity IN (".getEntity('holiday').")";
325
-		$sql.= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
326
-        $sql.= " AND cp.fk_user = ".$user_id;
292
+        $sql .= " cp.rowid,";
293
+
294
+        $sql .= " cp.fk_user,";
295
+		$sql .= " cp.fk_type,";
296
+		$sql .= " cp.date_create,";
297
+        $sql .= " cp.description,";
298
+        $sql .= " cp.date_debut,";
299
+        $sql .= " cp.date_fin,";
300
+        $sql .= " cp.halfday,";
301
+        $sql .= " cp.statut,";
302
+        $sql .= " cp.fk_validator,";
303
+        $sql .= " cp.date_valid,";
304
+        $sql .= " cp.fk_user_valid,";
305
+        $sql .= " cp.date_refuse,";
306
+        $sql .= " cp.fk_user_refuse,";
307
+        $sql .= " cp.date_cancel,";
308
+        $sql .= " cp.fk_user_cancel,";
309
+        $sql .= " cp.detail_refuse,";
310
+
311
+		$sql .= " uu.lastname as user_lastname,";
312
+		$sql .= " uu.firstname as user_firstname,";
313
+		$sql .= " uu.login as user_login,";
314
+		$sql .= " uu.statut as user_statut,";
315
+		$sql .= " uu.photo as user_photo,";
316
+
317
+        $sql .= " ua.lastname as validator_lastname,";
318
+        $sql .= " ua.firstname as validator_firstname,";
319
+        $sql .= " ua.login as validator_login,";
320
+        $sql .= " ua.statut as validator_statut,";
321
+        $sql .= " ua.photo as validator_photo";
322
+
323
+        $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
324
+        $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
325
+		$sql .= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
326
+        $sql .= " AND cp.fk_user = ".$user_id;
327 327
 
328 328
         // Filtre de séléction
329
-        if(!empty($filter)) {
330
-            $sql.= $filter;
329
+        if (!empty($filter)) {
330
+            $sql .= $filter;
331 331
         }
332 332
 
333 333
         // Ordre d'affichage du résultat
334
-        if(!empty($order)) {
335
-            $sql.= $order;
334
+        if (!empty($order)) {
335
+            $sql .= $order;
336 336
         }
337 337
 
338 338
         dol_syslog(get_class($this)."::fetchByUser", LOG_DEBUG);
339
-        $resql=$this->db->query($sql);
339
+        $resql = $this->db->query($sql);
340 340
 
341 341
         // Si pas d'erreur SQL
342 342
         if ($resql) {
@@ -346,12 +346,12 @@  discard block
 block discarded – undo
346 346
             $num = $this->db->num_rows($resql);
347 347
 
348 348
             // Si pas d'enregistrement
349
-            if(!$num) {
349
+            if (!$num) {
350 350
                 return 2;
351 351
             }
352 352
 
353 353
             // Liste les enregistrements et les ajoutent au tableau
354
-            while($i < $num) {
354
+            while ($i < $num) {
355 355
 
356 356
                 $obj = $this->db->fetch_object($resql);
357 357
 
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
                 $tab_result[$i]['description'] = $obj->description;
364 364
                 $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
365 365
                 $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
366
-                $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut,1);
367
-                $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin,1);
366
+                $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
367
+                $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
368 368
                 $tab_result[$i]['halfday'] = $obj->halfday;
369 369
                 $tab_result[$i]['statut'] = $obj->statut;
370 370
                 $tab_result[$i]['fk_validator'] = $obj->fk_validator;
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
         else
399 399
         {
400 400
             // Erreur SQL
401
-            $this->error="Error ".$this->db->lasterror();
401
+            $this->error = "Error ".$this->db->lasterror();
402 402
             return -1;
403 403
         }
404 404
     }
@@ -410,58 +410,58 @@  discard block
 block discarded – undo
410 410
      *  @param      string	$filter     SQL Filter
411 411
      *  @return     int      			-1 if KO, 1 if OK, 2 if no result
412 412
      */
413
-    function fetchAll($order,$filter)
413
+    function fetchAll($order, $filter)
414 414
     {
415 415
         global $langs;
416 416
 
417 417
         $sql = "SELECT";
418
-        $sql.= " cp.rowid,";
419
-
420
-        $sql.= " cp.fk_user,";
421
-        $sql.= " cp.fk_type,";
422
-        $sql.= " cp.date_create,";
423
-        $sql.= " cp.description,";
424
-        $sql.= " cp.date_debut,";
425
-        $sql.= " cp.date_fin,";
426
-        $sql.= " cp.halfday,";
427
-        $sql.= " cp.statut,";
428
-        $sql.= " cp.fk_validator,";
429
-        $sql.= " cp.date_valid,";
430
-        $sql.= " cp.fk_user_valid,";
431
-        $sql.= " cp.date_refuse,";
432
-        $sql.= " cp.fk_user_refuse,";
433
-        $sql.= " cp.date_cancel,";
434
-        $sql.= " cp.fk_user_cancel,";
435
-        $sql.= " cp.detail_refuse,";
436
-
437
-        $sql.= " uu.lastname as user_lastname,";
438
-        $sql.= " uu.firstname as user_firstname,";
439
-        $sql.= " uu.login as user_login,";
440
-        $sql.= " uu.statut as user_statut,";
441
-        $sql.= " uu.photo as user_photo,";
442
-
443
-        $sql.= " ua.lastname as validator_lastname,";
444
-        $sql.= " ua.firstname as validator_firstname,";
445
-        $sql.= " ua.login as validator_login,";
446
-        $sql.= " ua.statut as validator_statut,";
447
-        $sql.= " ua.photo as validator_photo";
448
-
449
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
450
-        $sql.= " WHERE cp.entity IN (".getEntity('holiday').")";
451
-        $sql.= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
418
+        $sql .= " cp.rowid,";
419
+
420
+        $sql .= " cp.fk_user,";
421
+        $sql .= " cp.fk_type,";
422
+        $sql .= " cp.date_create,";
423
+        $sql .= " cp.description,";
424
+        $sql .= " cp.date_debut,";
425
+        $sql .= " cp.date_fin,";
426
+        $sql .= " cp.halfday,";
427
+        $sql .= " cp.statut,";
428
+        $sql .= " cp.fk_validator,";
429
+        $sql .= " cp.date_valid,";
430
+        $sql .= " cp.fk_user_valid,";
431
+        $sql .= " cp.date_refuse,";
432
+        $sql .= " cp.fk_user_refuse,";
433
+        $sql .= " cp.date_cancel,";
434
+        $sql .= " cp.fk_user_cancel,";
435
+        $sql .= " cp.detail_refuse,";
436
+
437
+        $sql .= " uu.lastname as user_lastname,";
438
+        $sql .= " uu.firstname as user_firstname,";
439
+        $sql .= " uu.login as user_login,";
440
+        $sql .= " uu.statut as user_statut,";
441
+        $sql .= " uu.photo as user_photo,";
442
+
443
+        $sql .= " ua.lastname as validator_lastname,";
444
+        $sql .= " ua.firstname as validator_firstname,";
445
+        $sql .= " ua.login as validator_login,";
446
+        $sql .= " ua.statut as validator_statut,";
447
+        $sql .= " ua.photo as validator_photo";
448
+
449
+        $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
450
+        $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
451
+        $sql .= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
452 452
 
453 453
         // Filtrage de séléction
454
-        if(!empty($filter)) {
455
-            $sql.= $filter;
454
+        if (!empty($filter)) {
455
+            $sql .= $filter;
456 456
         }
457 457
 
458 458
         // Ordre d'affichage
459
-        if(!empty($order)) {
460
-            $sql.= $order;
459
+        if (!empty($order)) {
460
+            $sql .= $order;
461 461
         }
462 462
 
463 463
         dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
464
-        $resql=$this->db->query($sql);
464
+        $resql = $this->db->query($sql);
465 465
 
466 466
         // Si pas d'erreur SQL
467 467
         if ($resql) {
@@ -471,12 +471,12 @@  discard block
 block discarded – undo
471 471
             $num = $this->db->num_rows($resql);
472 472
 
473 473
             // Si pas d'enregistrement
474
-            if(!$num) {
474
+            if (!$num) {
475 475
                 return 2;
476 476
             }
477 477
 
478 478
             // On liste les résultats et on les ajoutent dans le tableau
479
-            while($i < $num) {
479
+            while ($i < $num) {
480 480
 
481 481
                 $obj = $this->db->fetch_object($resql);
482 482
 
@@ -488,8 +488,8 @@  discard block
 block discarded – undo
488 488
                 $tab_result[$i]['description'] = $obj->description;
489 489
                 $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
490 490
                 $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
491
-                $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut,1);
492
-                $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin,1);
491
+                $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
492
+                $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
493 493
                 $tab_result[$i]['halfday'] = $obj->halfday;
494 494
                 $tab_result[$i]['statut'] = $obj->statut;
495 495
                 $tab_result[$i]['fk_validator'] = $obj->fk_validator;
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
         else
523 523
         {
524 524
             // Erreur SQL
525
-            $this->error="Error ".$this->db->lasterror();
525
+            $this->error = "Error ".$this->db->lasterror();
526 526
             return -1;
527 527
         }
528 528
     }
@@ -534,89 +534,89 @@  discard block
 block discarded – undo
534 534
      *  @param  int		$notrigger	    0=launch triggers after, 1=disable triggers
535 535
      *  @return int         			<0 if KO, >0 if OK
536 536
      */
537
-    function update($user=null, $notrigger=0)
537
+    function update($user = null, $notrigger = 0)
538 538
     {
539 539
         global $conf, $langs;
540
-        $error=0;
540
+        $error = 0;
541 541
 
542 542
         // Update request
543 543
         $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
544 544
 
545
-        $sql.= " description= '".$this->db->escape($this->description)."',";
545
+        $sql .= " description= '".$this->db->escape($this->description)."',";
546 546
 
547
-        if(!empty($this->date_debut)) {
548
-            $sql.= " date_debut = '".$this->db->idate($this->date_debut)."',";
547
+        if (!empty($this->date_debut)) {
548
+            $sql .= " date_debut = '".$this->db->idate($this->date_debut)."',";
549 549
         } else {
550 550
             $error++;
551 551
         }
552
-        if(!empty($this->date_fin)) {
553
-            $sql.= " date_fin = '".$this->db->idate($this->date_fin)."',";
552
+        if (!empty($this->date_fin)) {
553
+            $sql .= " date_fin = '".$this->db->idate($this->date_fin)."',";
554 554
         } else {
555 555
             $error++;
556 556
         }
557
-       	$sql.= " halfday = ".$this->halfday.",";
558
-        if(!empty($this->statut) && is_numeric($this->statut)) {
559
-            $sql.= " statut = ".$this->statut.",";
557
+       	$sql .= " halfday = ".$this->halfday.",";
558
+        if (!empty($this->statut) && is_numeric($this->statut)) {
559
+            $sql .= " statut = ".$this->statut.",";
560 560
         } else {
561 561
             $error++;
562 562
         }
563
-        if(!empty($this->fk_validator)) {
564
-            $sql.= " fk_validator = '".$this->db->escape($this->fk_validator)."',";
563
+        if (!empty($this->fk_validator)) {
564
+            $sql .= " fk_validator = '".$this->db->escape($this->fk_validator)."',";
565 565
         } else {
566 566
             $error++;
567 567
         }
568
-        if(!empty($this->date_valid)) {
569
-            $sql.= " date_valid = '".$this->db->idate($this->date_valid)."',";
568
+        if (!empty($this->date_valid)) {
569
+            $sql .= " date_valid = '".$this->db->idate($this->date_valid)."',";
570 570
         } else {
571
-            $sql.= " date_valid = NULL,";
571
+            $sql .= " date_valid = NULL,";
572 572
         }
573
-        if(!empty($this->fk_user_valid)) {
574
-            $sql.= " fk_user_valid = '".$this->db->escape($this->fk_user_valid)."',";
573
+        if (!empty($this->fk_user_valid)) {
574
+            $sql .= " fk_user_valid = '".$this->db->escape($this->fk_user_valid)."',";
575 575
         } else {
576
-            $sql.= " fk_user_valid = NULL,";
576
+            $sql .= " fk_user_valid = NULL,";
577 577
         }
578
-        if(!empty($this->date_refuse)) {
579
-            $sql.= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
578
+        if (!empty($this->date_refuse)) {
579
+            $sql .= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
580 580
         } else {
581
-            $sql.= " date_refuse = NULL,";
581
+            $sql .= " date_refuse = NULL,";
582 582
         }
583
-        if(!empty($this->fk_user_refuse)) {
584
-            $sql.= " fk_user_refuse = '".$this->db->escape($this->fk_user_refuse)."',";
583
+        if (!empty($this->fk_user_refuse)) {
584
+            $sql .= " fk_user_refuse = '".$this->db->escape($this->fk_user_refuse)."',";
585 585
         } else {
586
-            $sql.= " fk_user_refuse = NULL,";
586
+            $sql .= " fk_user_refuse = NULL,";
587 587
         }
588
-        if(!empty($this->date_cancel)) {
589
-            $sql.= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
588
+        if (!empty($this->date_cancel)) {
589
+            $sql .= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
590 590
         } else {
591
-            $sql.= " date_cancel = NULL,";
591
+            $sql .= " date_cancel = NULL,";
592 592
         }
593
-        if(!empty($this->fk_user_cancel)) {
594
-            $sql.= " fk_user_cancel = '".$this->db->escape($this->fk_user_cancel)."',";
593
+        if (!empty($this->fk_user_cancel)) {
594
+            $sql .= " fk_user_cancel = '".$this->db->escape($this->fk_user_cancel)."',";
595 595
         } else {
596
-            $sql.= " fk_user_cancel = NULL,";
596
+            $sql .= " fk_user_cancel = NULL,";
597 597
         }
598
-        if(!empty($this->detail_refuse)) {
599
-            $sql.= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
598
+        if (!empty($this->detail_refuse)) {
599
+            $sql .= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
600 600
         } else {
601
-            $sql.= " detail_refuse = NULL";
601
+            $sql .= " detail_refuse = NULL";
602 602
         }
603 603
 
604
-        $sql.= " WHERE rowid= ".$this->id;
604
+        $sql .= " WHERE rowid= ".$this->id;
605 605
 
606 606
         $this->db->begin();
607 607
 
608 608
         dol_syslog(get_class($this)."::update", LOG_DEBUG);
609 609
         $resql = $this->db->query($sql);
610
-        if (! $resql) {
611
-            $error++; $this->errors[]="Error ".$this->db->lasterror();
610
+        if (!$resql) {
611
+            $error++; $this->errors[] = "Error ".$this->db->lasterror();
612 612
         }
613 613
 
614
-        if (! $error)
614
+        if (!$error)
615 615
         {
616
-            if (! $notrigger)
616
+            if (!$notrigger)
617 617
             {
618 618
                 // Call trigger
619
-                $result=$this->call_trigger('HOLIDAY_MODIFY',$user);
619
+                $result = $this->call_trigger('HOLIDAY_MODIFY', $user);
620 620
                 if ($result < 0) { $error++; }
621 621
                 // End call triggers
622 622
             }
@@ -625,13 +625,13 @@  discard block
 block discarded – undo
625 625
         // Commit or rollback
626 626
         if ($error)
627 627
         {
628
-            foreach($this->errors as $errmsg)
628
+            foreach ($this->errors as $errmsg)
629 629
             {
630 630
                 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
631
-                $this->error.=($this->error?', '.$errmsg:$errmsg);
631
+                $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
632 632
             }
633 633
             $this->db->rollback();
634
-            return -1*$error;
634
+            return -1 * $error;
635 635
         }
636 636
         else
637 637
         {
@@ -648,28 +648,28 @@  discard block
 block discarded – undo
648 648
      *   @param     int		$notrigger	    0=launch triggers after, 1=disable triggers
649 649
      *	 @return	int						<0 if KO, >0 if OK
650 650
      */
651
-    function delete($user, $notrigger=0)
651
+    function delete($user, $notrigger = 0)
652 652
     {
653 653
         global $conf, $langs;
654
-        $error=0;
654
+        $error = 0;
655 655
 
656 656
         $sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday";
657
-        $sql.= " WHERE rowid=".$this->id;
657
+        $sql .= " WHERE rowid=".$this->id;
658 658
 
659 659
         $this->db->begin();
660 660
 
661 661
         dol_syslog(get_class($this)."::delete", LOG_DEBUG);
662 662
         $resql = $this->db->query($sql);
663
-        if (! $resql) {
664
-            $error++; $this->errors[]="Error ".$this->db->lasterror();
663
+        if (!$resql) {
664
+            $error++; $this->errors[] = "Error ".$this->db->lasterror();
665 665
         }
666 666
 
667
-        if (! $error)
667
+        if (!$error)
668 668
         {
669
-            if (! $notrigger)
669
+            if (!$notrigger)
670 670
             {
671 671
                 // Call trigger
672
-                $result=$this->call_trigger('HOLIDAY_DELETE',$user);
672
+                $result = $this->call_trigger('HOLIDAY_DELETE', $user);
673 673
                 if ($result < 0) { $error++; }
674 674
                 // End call triggers
675 675
             }
@@ -678,13 +678,13 @@  discard block
 block discarded – undo
678 678
         // Commit or rollback
679 679
         if ($error)
680 680
         {
681
-            foreach($this->errors as $errmsg)
681
+            foreach ($this->errors as $errmsg)
682 682
             {
683 683
                 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
684
-                $this->error.=($this->error?', '.$errmsg:$errmsg);
684
+                $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
685 685
             }
686 686
             $this->db->rollback();
687
-            return -1*$error;
687
+            return -1 * $error;
688 688
         }
689 689
         else
690 690
         {
@@ -706,14 +706,14 @@  discard block
 block discarded – undo
706 706
      * 	@return boolean					False is on holiday at least partially into the period, True is never on holiday during chcked period.
707 707
      *  @see verifDateHolidayForTimestamp
708 708
      */
709
-    function verifDateHolidayCP($fk_user, $dateDebut, $dateFin, $halfday=0)
709
+    function verifDateHolidayCP($fk_user, $dateDebut, $dateFin, $halfday = 0)
710 710
     {
711
-        $this->fetchByUser($fk_user,'','');
711
+        $this->fetchByUser($fk_user, '', '');
712 712
 
713
-        foreach($this->holiday as $infos_CP)
713
+        foreach ($this->holiday as $infos_CP)
714 714
         {
715
-        	if ($infos_CP['statut'] == 4) continue;		// ignore not validated holidays
716
-        	if ($infos_CP['statut'] == 5) continue;		// ignore not validated holidays
715
+        	if ($infos_CP['statut'] == 4) continue; // ignore not validated holidays
716
+        	if ($infos_CP['statut'] == 5) continue; // ignore not validated holidays
717 717
 
718 718
         	// TODO Also use halfday for the check
719 719
         	if ($halfday == 0)
@@ -766,34 +766,34 @@  discard block
 block discarded – undo
766 766
     {
767 767
     	global $langs, $conf;
768 768
 
769
-    	$isavailablemorning=true;
770
-    	$isavailableafternoon=true;
769
+    	$isavailablemorning = true;
770
+    	$isavailableafternoon = true;
771 771
 
772 772
     	$sql = "SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday";
773
-    	$sql.= " FROM ".MAIN_DB_PREFIX."holiday as cp";
774
-    	$sql.= " WHERE cp.entity IN (".getEntity('holiday').")";
775
-    	$sql.= " AND cp.fk_user = ".(int) $fk_user;
776
-   		$sql.= " AND date_debut <= '".$this->db->idate($timestamp)."' AND date_fin >= '".$this->db->idate($timestamp)."'";
773
+    	$sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
774
+    	$sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
775
+    	$sql .= " AND cp.fk_user = ".(int) $fk_user;
776
+   		$sql .= " AND date_debut <= '".$this->db->idate($timestamp)."' AND date_fin >= '".$this->db->idate($timestamp)."'";
777 777
 
778 778
     	$resql = $this->db->query($sql);
779 779
     	if ($resql)
780 780
     	{
781
-    		$num_rows = $this->db->num_rows($resql);	// Note, we can have 2 records if on is morning and the other one is afternoon
781
+    		$num_rows = $this->db->num_rows($resql); // Note, we can have 2 records if on is morning and the other one is afternoon
782 782
     		if ($num_rows > 0)
783 783
     		{
784
-	    		$i=0;
784
+	    		$i = 0;
785 785
 	    		while ($i < $num_rows)
786 786
 	    		{
787 787
 	    			$obj = $this->db->fetch_object($resql);
788 788
 
789 789
 	    			// Note: $obj->halday is  0:Full days, 2:Sart afternoon end morning, -1:Start afternoon, 1:End morning
790
-	    			$arrayofrecord[$obj->rowid]=array('date_start'=>$this->db->jdate($obj->date_start), 'date_end'=>$this->db->jdate($obj->date_end), 'halfday'=>$obj->halfday);
790
+	    			$arrayofrecord[$obj->rowid] = array('date_start'=>$this->db->jdate($obj->date_start), 'date_end'=>$this->db->jdate($obj->date_end), 'halfday'=>$obj->halfday);
791 791
 	    			$i++;
792 792
 	    		}
793 793
 
794 794
     			// We found a record, user is on holiday by default, so is not available is true.
795 795
 	    		$isavailablemorning = true;
796
-	    		foreach($arrayofrecord as $record)
796
+	    		foreach ($arrayofrecord as $record)
797 797
 	    		{
798 798
 					if ($timestamp == $record['date_start'] && $record['halfday'] == 2)  continue;
799 799
 					if ($timestamp == $record['date_start'] && $record['halfday'] == -1) continue;
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
 	    			break;
802 802
 	    		}
803 803
     			$isavailableafternoon = true;
804
-	    		foreach($arrayofrecord as $record)
804
+	    		foreach ($arrayofrecord as $record)
805 805
 	    		{
806 806
 					if ($timestamp == $record['date_end'] && $record['halfday'] == 2) continue;
807 807
 					if ($timestamp == $record['date_end'] && $record['halfday'] == 1) continue;
@@ -823,30 +823,30 @@  discard block
 block discarded – undo
823 823
      *  @param  int     	$save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
824 824
      *	@return	string									String with URL
825 825
      */
826
-    function getNomUrl($withpicto=0, $save_lastsearch_value=-1)
826
+    function getNomUrl($withpicto = 0, $save_lastsearch_value = -1)
827 827
     {
828 828
         global $langs;
829 829
 
830
-        $result='';
831
-        $picto='holiday';
832
-        $label=$langs->trans("Show").': '.$this->ref;
830
+        $result = '';
831
+        $picto = 'holiday';
832
+        $label = $langs->trans("Show").': '.$this->ref;
833 833
 
834 834
         $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id;
835 835
 
836 836
         //if ($option != 'nolink')
837 837
         //{
838 838
         	// Add param to save lastsearch_values or not
839
-        	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
840
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
841
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
839
+        	$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
840
+        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
841
+        	if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
842 842
         //}
843 843
 
844 844
         $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
845
-        $linkend='</a>';
845
+        $linkend = '</a>';
846 846
 
847
-        if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
848
-        if ($withpicto && $withpicto != 2) $result.=' ';
849
-        if ($withpicto != 2) $result.=$linkstart.$this->ref.$linkend;
847
+        if ($withpicto) $result .= ($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
848
+        if ($withpicto && $withpicto != 2) $result .= ' ';
849
+        if ($withpicto != 2) $result .= $linkstart.$this->ref.$linkend;
850 850
         return $result;
851 851
     }
852 852
 
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
      *	@param      int		$mode       0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
858 858
      *	@return     string      		Label
859 859
      */
860
-    function getLibStatut($mode=0)
860
+    function getLibStatut($mode = 0)
861 861
     {
862 862
     	return $this->LibStatut($this->statut, $mode, $this->date_debut);
863 863
     }
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
 	 *  @param		date	$startdate	Date holiday should start
871 871
 	 *	@return     string      		Label
872 872
 	 */
873
-	function LibStatut($statut, $mode=0, $startdate='')
873
+	function LibStatut($statut, $mode = 0, $startdate = '')
874 874
 	{
875 875
 		global $langs;
876 876
 
@@ -884,43 +884,43 @@  discard block
 block discarded – undo
884 884
 		}
885 885
 		if ($mode == 2)
886 886
 		{
887
-			$pictoapproved='statut6';
888
-			if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4';
889
-			if ($statut == 1) return img_picto($langs->trans('DraftCP'),'statut0').' '.$langs->trans('DraftCP');				// Draft
890
-			if ($statut == 2) return img_picto($langs->trans('ToReviewCP'),'statut1').' '.$langs->trans('ToReviewCP');		// Waiting approval
891
-			if ($statut == 3) return img_picto($langs->trans('ApprovedCP'),$pictoapproved).' '.$langs->trans('ApprovedCP');
892
-			if ($statut == 4) return img_picto($langs->trans('CancelCP'),'statut5').' '.$langs->trans('CancelCP');
893
-			if ($statut == 5) return img_picto($langs->trans('RefuseCP'),'statut5').' '.$langs->trans('RefuseCP');
887
+			$pictoapproved = 'statut6';
888
+			if (!empty($startdate) && $startdate > dol_now()) $pictoapproved = 'statut4';
889
+			if ($statut == 1) return img_picto($langs->trans('DraftCP'), 'statut0').' '.$langs->trans('DraftCP'); // Draft
890
+			if ($statut == 2) return img_picto($langs->trans('ToReviewCP'), 'statut1').' '.$langs->trans('ToReviewCP'); // Waiting approval
891
+			if ($statut == 3) return img_picto($langs->trans('ApprovedCP'), $pictoapproved).' '.$langs->trans('ApprovedCP');
892
+			if ($statut == 4) return img_picto($langs->trans('CancelCP'), 'statut5').' '.$langs->trans('CancelCP');
893
+			if ($statut == 5) return img_picto($langs->trans('RefuseCP'), 'statut5').' '.$langs->trans('RefuseCP');
894 894
 		}
895 895
 		if ($mode == 3)
896 896
 		{
897
-			$pictoapproved='statut6';
898
-			if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4';
899
-			if ($statut == 1) return img_picto($langs->trans('DraftCP'),'statut0');
900
-			if ($statut == 2) return img_picto($langs->trans('ToReviewCP'),'statut1');
901
-			if ($statut == 3) return img_picto($langs->trans('ApprovedCP'),$pictoapproved);
902
-			if ($statut == 4) return img_picto($langs->trans('CancelCP'),'statut5');
903
-			if ($statut == 5) return img_picto($langs->trans('RefuseCP'),'statut5');
897
+			$pictoapproved = 'statut6';
898
+			if (!empty($startdate) && $startdate > dol_now()) $pictoapproved = 'statut4';
899
+			if ($statut == 1) return img_picto($langs->trans('DraftCP'), 'statut0');
900
+			if ($statut == 2) return img_picto($langs->trans('ToReviewCP'), 'statut1');
901
+			if ($statut == 3) return img_picto($langs->trans('ApprovedCP'), $pictoapproved);
902
+			if ($statut == 4) return img_picto($langs->trans('CancelCP'), 'statut5');
903
+			if ($statut == 5) return img_picto($langs->trans('RefuseCP'), 'statut5');
904 904
 		}
905 905
 		if ($mode == 5)
906 906
 		{
907
-			$pictoapproved='statut6';
908
-			if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4';
909
-			if ($statut == 1) return $langs->trans('DraftCP').' '.img_picto($langs->trans('DraftCP'),'statut0');				// Draft
910
-			if ($statut == 2) return $langs->trans('ToReviewCP').' '.img_picto($langs->trans('ToReviewCP'),'statut1');		// Waiting approval
911
-			if ($statut == 3) return $langs->trans('ApprovedCP').' '.img_picto($langs->trans('ApprovedCP'),$pictoapproved);
912
-			if ($statut == 4) return $langs->trans('CancelCP').' '.img_picto($langs->trans('CancelCP'),'statut5');
913
-			if ($statut == 5) return $langs->trans('RefuseCP').' '.img_picto($langs->trans('RefuseCP'),'statut5');
907
+			$pictoapproved = 'statut6';
908
+			if (!empty($startdate) && $startdate > dol_now()) $pictoapproved = 'statut4';
909
+			if ($statut == 1) return $langs->trans('DraftCP').' '.img_picto($langs->trans('DraftCP'), 'statut0'); // Draft
910
+			if ($statut == 2) return $langs->trans('ToReviewCP').' '.img_picto($langs->trans('ToReviewCP'), 'statut1'); // Waiting approval
911
+			if ($statut == 3) return $langs->trans('ApprovedCP').' '.img_picto($langs->trans('ApprovedCP'), $pictoapproved);
912
+			if ($statut == 4) return $langs->trans('CancelCP').' '.img_picto($langs->trans('CancelCP'), 'statut5');
913
+			if ($statut == 5) return $langs->trans('RefuseCP').' '.img_picto($langs->trans('RefuseCP'), 'statut5');
914 914
 		}
915 915
 		if ($mode == 6)
916 916
 		{
917
-		    $pictoapproved='statut6';
918
-		    if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4';
919
-		    if ($statut == 1) return $langs->trans('DraftCP').' '.img_picto($langs->trans('DraftCP'),'statut0');				// Draft
920
-		    if ($statut == 2) return $langs->trans('ToReviewCP').' '.img_picto($langs->trans('ToReviewCP'),'statut1');		// Waiting approval
921
-		    if ($statut == 3) return $langs->trans('ApprovedCP').' '.img_picto($langs->trans('ApprovedCP'),$pictoapproved);
922
-		    if ($statut == 4) return $langs->trans('CancelCP').' '.img_picto($langs->trans('CancelCP'),'statut5');
923
-		    if ($statut == 5) return $langs->trans('RefuseCP').' '.img_picto($langs->trans('RefuseCP'),'statut5');
917
+		    $pictoapproved = 'statut6';
918
+		    if (!empty($startdate) && $startdate > dol_now()) $pictoapproved = 'statut4';
919
+		    if ($statut == 1) return $langs->trans('DraftCP').' '.img_picto($langs->trans('DraftCP'), 'statut0'); // Draft
920
+		    if ($statut == 2) return $langs->trans('ToReviewCP').' '.img_picto($langs->trans('ToReviewCP'), 'statut1'); // Waiting approval
921
+		    if ($statut == 3) return $langs->trans('ApprovedCP').' '.img_picto($langs->trans('ApprovedCP'), $pictoapproved);
922
+		    if ($statut == 4) return $langs->trans('CancelCP').' '.img_picto($langs->trans('CancelCP'), 'statut5');
923
+		    if ($statut == 5) return $langs->trans('RefuseCP').' '.img_picto($langs->trans('RefuseCP'), 'statut5');
924 924
 		}
925 925
 
926 926
 		return $statut;
@@ -933,29 +933,29 @@  discard block
 block discarded – undo
933 933
      *   @param 	int		$selected   int du statut séléctionné par défaut
934 934
      *   @return    string				affiche le select des statuts
935 935
      */
936
-    function selectStatutCP($selected='') {
936
+    function selectStatutCP($selected = '') {
937 937
 
938 938
         global $langs;
939 939
 
940 940
         // Liste des statuts
941
-        $name = array('DraftCP','ToReviewCP','ApprovedCP','CancelCP','RefuseCP');
942
-        $nb = count($name)+1;
941
+        $name = array('DraftCP', 'ToReviewCP', 'ApprovedCP', 'CancelCP', 'RefuseCP');
942
+        $nb = count($name) + 1;
943 943
 
944 944
         // Select HTML
945 945
         $statut = '<select name="select_statut" class="flat">'."\n";
946
-        $statut.= '<option value="-1">&nbsp;</option>'."\n";
946
+        $statut .= '<option value="-1">&nbsp;</option>'."\n";
947 947
 
948 948
         // Boucle des statuts
949
-        for($i=1; $i < $nb; $i++) {
950
-            if($i==$selected) {
951
-                $statut.= '<option value="'.$i.'" selected>'.$langs->trans($name[$i-1]).'</option>'."\n";
949
+        for ($i = 1; $i < $nb; $i++) {
950
+            if ($i == $selected) {
951
+                $statut .= '<option value="'.$i.'" selected>'.$langs->trans($name[$i - 1]).'</option>'."\n";
952 952
             }
953 953
             else {
954
-                $statut.= '<option value="'.$i.'">'.$langs->trans($name[$i-1]).'</option>'."\n";
954
+                $statut .= '<option value="'.$i.'">'.$langs->trans($name[$i - 1]).'</option>'."\n";
955 955
             }
956 956
         }
957 957
 
958
-        $statut.= '</select>'."\n";
958
+        $statut .= '</select>'."\n";
959 959
         print $statut;
960 960
 
961 961
     }
@@ -967,15 +967,15 @@  discard block
 block discarded – undo
967 967
      *  @param	string	$value      vrai si mise à jour OK sinon faux
968 968
      *  @return boolean				ok or ko
969 969
      */
970
-    function updateConfCP($name,$value) {
970
+    function updateConfCP($name, $value) {
971 971
 
972 972
         $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
973
-        $sql.= " value = '".$value."'";
974
-        $sql.= " WHERE name = '".$name."'";
973
+        $sql .= " value = '".$value."'";
974
+        $sql .= " WHERE name = '".$name."'";
975 975
 
976 976
         dol_syslog(get_class($this).'::updateConfCP name='.$name.'', LOG_DEBUG);
977 977
         $result = $this->db->query($sql);
978
-        if($result) {
978
+        if ($result) {
979 979
             return true;
980 980
         }
981 981
 
@@ -990,16 +990,16 @@  discard block
 block discarded – undo
990 990
      *  @param  string  $createifnotfound     'stringvalue'=Create entry with string value if not found. For example 'YYYYMMDDHHMMSS'.
991 991
      *  @return string      		          Value of parameter. Example: 'YYYYMMDDHHMMSS' or < 0 if error
992 992
      */
993
-    function getConfCP($name, $createifnotfound='')
993
+    function getConfCP($name, $createifnotfound = '')
994 994
     {
995 995
         $sql = "SELECT value";
996
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday_config";
997
-        $sql.= " WHERE name = '".$this->db->escape($name)."'";
996
+        $sql .= " FROM ".MAIN_DB_PREFIX."holiday_config";
997
+        $sql .= " WHERE name = '".$this->db->escape($name)."'";
998 998
 
999 999
         dol_syslog(get_class($this).'::getConfCP name='.$name.' createifnotfound='.$createifnotfound, LOG_DEBUG);
1000 1000
         $result = $this->db->query($sql);
1001 1001
 
1002
-        if($result) {
1002
+        if ($result) {
1003 1003
 
1004 1004
             $obj = $this->db->fetch_object($result);
1005 1005
             // Return value
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
                 if ($createifnotfound)
1009 1009
                 {
1010 1010
                     $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)";
1011
-                    $sql.= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')";
1011
+                    $sql .= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')";
1012 1012
                     $result = $this->db->query($sql);
1013 1013
                     if ($result)
1014 1014
                     {
@@ -1016,7 +1016,7 @@  discard block
 block discarded – undo
1016 1016
                     }
1017 1017
                     else
1018 1018
                     {
1019
-                        $this->error=$this->db->lasterror();
1019
+                        $this->error = $this->db->lasterror();
1020 1020
                         return -2;
1021 1021
                     }
1022 1022
                 }
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
         } else {
1033 1033
 
1034 1034
             // Erreur SQL
1035
-            $this->error=$this->db->lasterror();
1035
+            $this->error = $this->db->lasterror();
1036 1036
             return -1;
1037 1037
         }
1038 1038
     }
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
      *  @param		int		$fk_type	Type of vacation
1046 1046
      *  @return     int					0=Nothing done, 1=OK, -1=KO
1047 1047
      */
1048
-    function updateSoldeCP($userID='',$nbHoliday='', $fk_type='')
1048
+    function updateSoldeCP($userID = '', $nbHoliday = '', $fk_type = '')
1049 1049
     {
1050 1050
         global $user, $langs;
1051 1051
 
@@ -1056,9 +1056,9 @@  discard block
 block discarded – undo
1056 1056
             $langs->load("holiday");
1057 1057
 
1058 1058
             // Si mise à jour pour tout le monde en début de mois
1059
-			$now=dol_now();
1059
+			$now = dol_now();
1060 1060
 
1061
-            $month = date('m',$now);
1061
+            $month = date('m', $now);
1062 1062
             $newdateforlastupdate = dol_print_date($now, '%Y%m%d%H%M%S');
1063 1063
 
1064 1064
             // Get month of last update
@@ -1071,20 +1071,20 @@  discard block
 block discarded – undo
1071 1071
             {
1072 1072
             	$this->db->begin();
1073 1073
 
1074
-            	$users = $this->fetchUsers(false,false);
1074
+            	$users = $this->fetchUsers(false, false);
1075 1075
 	            $nbUser = count($users);
1076 1076
 
1077 1077
                 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1078
-                $sql.= " value = '".$this->db->escape($newdateforlastupdate)."'";
1079
-                $sql.= " WHERE name = 'lastUpdate'";
1078
+                $sql .= " value = '".$this->db->escape($newdateforlastupdate)."'";
1079
+                $sql .= " WHERE name = 'lastUpdate'";
1080 1080
                 $result = $this->db->query($sql);
1081 1081
 
1082
-				$typeleaves=$this->getTypes(1,1);
1083
-    			foreach($typeleaves as $key => $val)
1082
+				$typeleaves = $this->getTypes(1, 1);
1083
+    			foreach ($typeleaves as $key => $val)
1084 1084
     			{
1085 1085
 	                // On ajoute x jours à chaque utilisateurs
1086 1086
 	                $nb_holiday = $val['newByMonth'];
1087
-					if (empty($nb_holiday)) $nb_holiday=0;
1087
+					if (empty($nb_holiday)) $nb_holiday = 0;
1088 1088
 
1089 1089
 					if ($nb_holiday > 0)
1090 1090
 					{
@@ -1104,12 +1104,12 @@  discard block
 block discarded – undo
1104 1104
 
1105 1105
 		                // Now we update counter for all users at once
1106 1106
 		                $sql2 = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
1107
-		                $sql2.= " nb_holiday = nb_holiday + ".$nb_holiday;
1108
-						$sql2.= " WHERE fk_type = ".$val['rowid'];
1107
+		                $sql2 .= " nb_holiday = nb_holiday + ".$nb_holiday;
1108
+						$sql2 .= " WHERE fk_type = ".$val['rowid'];
1109 1109
 
1110
-		                $result= $this->db->query($sql2);
1110
+		                $result = $this->db->query($sql2);
1111 1111
 
1112
-		                if (! $result)
1112
+		                if (!$result)
1113 1113
 		                {
1114 1114
 		                	dol_print_error($this->db);
1115 1115
 		                	break;
@@ -1135,10 +1135,10 @@  discard block
 block discarded – undo
1135 1135
         else
1136 1136
 		{
1137 1137
             // Mise à jour pour un utilisateur
1138
-            $nbHoliday = price2num($nbHoliday,5);
1138
+            $nbHoliday = price2num($nbHoliday, 5);
1139 1139
 
1140 1140
             $sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users";
1141
-            $sql.= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type;
1141
+            $sql .= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type;
1142 1142
             $resql = $this->db->query($sql);
1143 1143
             if ($resql)
1144 1144
             {
@@ -1148,36 +1148,36 @@  discard block
 block discarded – undo
1148 1148
             	{
1149 1149
 		            // Update for user
1150 1150
 		            $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
1151
-		            $sql.= " nb_holiday = ".$nbHoliday;
1152
-		            $sql.= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type;
1151
+		            $sql .= " nb_holiday = ".$nbHoliday;
1152
+		            $sql .= " WHERE fk_user = '".$userID."' AND fk_type = ".$fk_type;
1153 1153
 		            $result = $this->db->query($sql);
1154
-		            if (! $result)
1154
+		            if (!$result)
1155 1155
 		            {
1156 1156
 		            	$error++;
1157
-		            	$this->errors[]=$this->db->lasterror();
1157
+		            	$this->errors[] = $this->db->lasterror();
1158 1158
 		            }
1159 1159
             	}
1160 1160
             	else
1161 1161
             	{
1162 1162
 		            // Insert for user
1163 1163
 		            $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1164
-		            $sql.= $nbHoliday;
1165
-		            $sql.= ", '".$userID."', ".$fk_type.")";
1164
+		            $sql .= $nbHoliday;
1165
+		            $sql .= ", '".$userID."', ".$fk_type.")";
1166 1166
 		            $result = $this->db->query($sql);
1167
-		            if (! $result)
1167
+		            if (!$result)
1168 1168
 		            {
1169 1169
 		            	$error++;
1170
-		            	$this->errors[]=$this->db->lasterror();
1170
+		            	$this->errors[] = $this->db->lasterror();
1171 1171
 		            }
1172 1172
             	}
1173 1173
             }
1174 1174
             else
1175 1175
 			{
1176
-		        $this->errors[]=$this->db->lasterror();
1176
+		        $this->errors[] = $this->db->lasterror();
1177 1177
             	$error++;
1178 1178
 			}
1179 1179
 
1180
-            if (! $error)
1180
+            if (!$error)
1181 1181
             {
1182 1182
             	return 1;
1183 1183
             }
@@ -1198,16 +1198,16 @@  discard block
 block discarded – undo
1198 1198
     function getCheckOption($name) {
1199 1199
 
1200 1200
         $sql = "SELECT value";
1201
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday_config";
1202
-        $sql.= " WHERE name = '".$name."'";
1201
+        $sql .= " FROM ".MAIN_DB_PREFIX."holiday_config";
1202
+        $sql .= " WHERE name = '".$name."'";
1203 1203
 
1204 1204
         $result = $this->db->query($sql);
1205 1205
 
1206
-        if($result) {
1206
+        if ($result) {
1207 1207
             $obj = $this->db->fetch_object($result);
1208 1208
 
1209 1209
             // Si la valeur est 1 on retourne checked
1210
-            if($obj->value) {
1210
+            if ($obj->value) {
1211 1211
                 return 'checked';
1212 1212
             }
1213 1213
         }
@@ -1221,32 +1221,32 @@  discard block
 block discarded – undo
1221 1221
      *  @param	int			$userid		Id user
1222 1222
      *  @return void
1223 1223
      */
1224
-    function createCPusers($single=false,$userid='')
1224
+    function createCPusers($single = false, $userid = '')
1225 1225
     {
1226 1226
         // Si c'est l'ensemble des utilisateurs à ajouter
1227
-        if (! $single)
1227
+        if (!$single)
1228 1228
         {
1229 1229
         	dol_syslog(get_class($this).'::createCPusers');
1230
-        	$arrayofusers = $this->fetchUsers(false,true);
1230
+        	$arrayofusers = $this->fetchUsers(false, true);
1231 1231
 
1232
-            foreach($arrayofusers as $users)
1232
+            foreach ($arrayofusers as $users)
1233 1233
             {
1234 1234
                 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1235
-                $sql.= " (fk_user, nb_holiday)";
1236
-                $sql.= " VALUES ('".$users['rowid']."','0')";
1235
+                $sql .= " (fk_user, nb_holiday)";
1236
+                $sql .= " VALUES ('".$users['rowid']."','0')";
1237 1237
 
1238
-                $resql=$this->db->query($sql);
1239
-                if (! $resql) dol_print_error($this->db);
1238
+                $resql = $this->db->query($sql);
1239
+                if (!$resql) dol_print_error($this->db);
1240 1240
             }
1241 1241
         }
1242 1242
         else
1243 1243
 		{
1244 1244
             $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1245
-            $sql.= " (fk_user, nb_holiday)";
1246
-            $sql.= " VALUES ('".$userid."','0')";
1245
+            $sql .= " (fk_user, nb_holiday)";
1246
+            $sql .= " VALUES ('".$userid."','0')";
1247 1247
 
1248
-            $resql=$this->db->query($sql);
1249
-            if (! $resql) dol_print_error($this->db);
1248
+            $resql = $this->db->query($sql);
1249
+            if (!$resql) dol_print_error($this->db);
1250 1250
         }
1251 1251
     }
1252 1252
 
@@ -1259,7 +1259,7 @@  discard block
 block discarded – undo
1259 1259
     function deleteCPuser($user_id) {
1260 1260
 
1261 1261
         $sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday_users";
1262
-        $sql.= " WHERE fk_user = '".$user_id."'";
1262
+        $sql .= " WHERE fk_user = '".$user_id."'";
1263 1263
 
1264 1264
         $this->db->query($sql);
1265 1265
 
@@ -1273,16 +1273,16 @@  discard block
 block discarded – undo
1273 1273
      *  @param	int		$fk_type	Filter on type
1274 1274
      *  @return float        		Retourne le solde de congés payés de l'utilisateur
1275 1275
      */
1276
-    function getCPforUser($user_id, $fk_type=0)
1276
+    function getCPforUser($user_id, $fk_type = 0)
1277 1277
     {
1278 1278
         $sql = "SELECT nb_holiday";
1279
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users";
1280
-        $sql.= " WHERE fk_user = '".$user_id."'";
1281
-        if ($fk_type > 0) $sql.=" AND fk_type = ".$fk_type;
1279
+        $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users";
1280
+        $sql .= " WHERE fk_user = '".$user_id."'";
1281
+        if ($fk_type > 0) $sql .= " AND fk_type = ".$fk_type;
1282 1282
 
1283 1283
         dol_syslog(get_class($this).'::getCPforUser', LOG_DEBUG);
1284 1284
         $result = $this->db->query($sql);
1285
-        if($result)
1285
+        if ($result)
1286 1286
         {
1287 1287
             $obj = $this->db->fetch_object($result);
1288 1288
             //return number_format($obj->nb_holiday,2);
@@ -1303,7 +1303,7 @@  discard block
 block discarded – undo
1303 1303
      *    @param      string            $filters        Filters
1304 1304
      *    @return     array|string|int      			Return an array
1305 1305
      */
1306
-    function fetchUsers($stringlist=true, $type=true, $filters='')
1306
+    function fetchUsers($stringlist = true, $type = true, $filters = '')
1307 1307
     {
1308 1308
     	global $conf;
1309 1309
 
@@ -1316,23 +1316,23 @@  discard block
 block discarded – undo
1316 1316
                 // Si utilisateur de Dolibarr
1317 1317
 
1318 1318
                 $sql = "SELECT u.rowid";
1319
-                $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
1319
+                $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
1320 1320
 
1321
-                if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1321
+                if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1322 1322
                 {
1323
-                	$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1324
-                	$sql.= " WHERE (ug.fk_user = u.rowid";
1325
-                	$sql.= " AND ug.entity = ".$conf->entity.")";
1326
-                	$sql.= " OR u.admin = 1";
1323
+                	$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1324
+                	$sql .= " WHERE (ug.fk_user = u.rowid";
1325
+                	$sql .= " AND ug.entity = ".$conf->entity.")";
1326
+                	$sql .= " OR u.admin = 1";
1327 1327
                 }
1328 1328
                 else
1329 1329
                 {
1330
-                	$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
1330
+                	$sql .= " WHERE u.entity IN (0,".$conf->entity.")";
1331 1331
                 }
1332
-                $sql.= " AND u.statut > 0";
1333
-                if ($filters) $sql.=$filters;
1332
+                $sql .= " AND u.statut > 0";
1333
+                if ($filters) $sql .= $filters;
1334 1334
 
1335
-                $resql=$this->db->query($sql);
1335
+                $resql = $this->db->query($sql);
1336 1336
 
1337 1337
                 // Si pas d'erreur SQL
1338 1338
                 if ($resql) {
@@ -1342,14 +1342,14 @@  discard block
 block discarded – undo
1342 1342
                     $stringlist = '';
1343 1343
 
1344 1344
                     // Boucles du listage des utilisateurs
1345
-                    while($i < $num)
1345
+                    while ($i < $num)
1346 1346
                     {
1347 1347
                         $obj = $this->db->fetch_object($resql);
1348 1348
 
1349 1349
                         if ($i == 0) {
1350
-                            $stringlist.= $obj->rowid;
1350
+                            $stringlist .= $obj->rowid;
1351 1351
                         } else {
1352
-                            $stringlist.= ', '.$obj->rowid;
1352
+                            $stringlist .= ', '.$obj->rowid;
1353 1353
                         }
1354 1354
 
1355 1355
                         $i++;
@@ -1360,7 +1360,7 @@  discard block
 block discarded – undo
1360 1360
                 else
1361 1361
                 {
1362 1362
                     // Erreur SQL
1363
-                    $this->error="Error ".$this->db->lasterror();
1363
+                    $this->error = "Error ".$this->db->lasterror();
1364 1364
                     return -1;
1365 1365
                 }
1366 1366
 
@@ -1369,11 +1369,11 @@  discard block
 block discarded – undo
1369 1369
             {
1370 1370
            		// We want only list of vacation balance for user ids
1371 1371
                 $sql = "SELECT DISTINCT cpu.fk_user";
1372
-                $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1373
-                $sql.= " WHERE cpu.fk_user = u.user";
1374
-                if ($filters) $sql.=$filters;
1372
+                $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1373
+                $sql .= " WHERE cpu.fk_user = u.user";
1374
+                if ($filters) $sql .= $filters;
1375 1375
 
1376
-                $resql=$this->db->query($sql);
1376
+                $resql = $this->db->query($sql);
1377 1377
 
1378 1378
                 // Si pas d'erreur SQL
1379 1379
                 if ($resql) {
@@ -1383,14 +1383,14 @@  discard block
 block discarded – undo
1383 1383
                     $stringlist = '';
1384 1384
 
1385 1385
                     // Boucles du listage des utilisateurs
1386
-                    while($i < $num)
1386
+                    while ($i < $num)
1387 1387
                     {
1388 1388
                         $obj = $this->db->fetch_object($resql);
1389 1389
 
1390
-                        if($i == 0) {
1391
-                            $stringlist.= $obj->fk_user;
1390
+                        if ($i == 0) {
1391
+                            $stringlist .= $obj->fk_user;
1392 1392
                         } else {
1393
-                            $stringlist.= ', '.$obj->fk_user;
1393
+                            $stringlist .= ', '.$obj->fk_user;
1394 1394
                         }
1395 1395
 
1396 1396
                         $i++;
@@ -1401,7 +1401,7 @@  discard block
 block discarded – undo
1401 1401
                 else
1402 1402
               {
1403 1403
                     // Erreur SQL
1404
-                    $this->error="Error ".$this->db->lasterror();
1404
+                    $this->error = "Error ".$this->db->lasterror();
1405 1405
                     return -1;
1406 1406
                 }
1407 1407
             }
@@ -1414,22 +1414,22 @@  discard block
 block discarded – undo
1414 1414
             if ($type)
1415 1415
             {
1416 1416
                 $sql = "SELECT u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1417
-                $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
1417
+                $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
1418 1418
 
1419
-                if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1419
+                if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1420 1420
                 {
1421
-                	$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1422
-                	$sql.= " WHERE (ug.fk_user = u.rowid";
1423
-                	$sql.= " AND ug.entity = ".$conf->entity.")";
1424
-                	$sql.= " OR u.admin = 1";
1421
+                	$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1422
+                	$sql .= " WHERE (ug.fk_user = u.rowid";
1423
+                	$sql .= " AND ug.entity = ".$conf->entity.")";
1424
+                	$sql .= " OR u.admin = 1";
1425 1425
                 }
1426 1426
                 else
1427
-                	$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
1427
+                	$sql .= " WHERE u.entity IN (0,".$conf->entity.")";
1428 1428
 
1429
-                $sql.= " AND u.statut > 0";
1430
-                if ($filters) $sql.=$filters;
1429
+                $sql .= " AND u.statut > 0";
1430
+                if ($filters) $sql .= $filters;
1431 1431
 
1432
-                $resql=$this->db->query($sql);
1432
+                $resql = $this->db->query($sql);
1433 1433
 
1434 1434
                 // Si pas d'erreur SQL
1435 1435
                 if ($resql)
@@ -1439,12 +1439,12 @@  discard block
 block discarded – undo
1439 1439
                     $num = $this->db->num_rows($resql);
1440 1440
 
1441 1441
                     // Boucles du listage des utilisateurs
1442
-                    while($i < $num) {
1442
+                    while ($i < $num) {
1443 1443
 
1444 1444
                         $obj = $this->db->fetch_object($resql);
1445 1445
 
1446 1446
                         $tab_result[$i]['rowid'] = $obj->rowid;
1447
-                        $tab_result[$i]['name'] = $obj->lastname;       // deprecated
1447
+                        $tab_result[$i]['name'] = $obj->lastname; // deprecated
1448 1448
                         $tab_result[$i]['lastname'] = $obj->lastname;
1449 1449
                         $tab_result[$i]['firstname'] = $obj->firstname;
1450 1450
                         $tab_result[$i]['gender'] = $obj->gender;
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
                 else
1464 1464
 				{
1465 1465
                     // Erreur SQL
1466
-                    $this->errors[]="Error ".$this->db->lasterror();
1466
+                    $this->errors[] = "Error ".$this->db->lasterror();
1467 1467
                     return -1;
1468 1468
                 }
1469 1469
             }
@@ -1471,11 +1471,11 @@  discard block
 block discarded – undo
1471 1471
             {
1472 1472
 				// List of vacation balance users
1473 1473
                 $sql = "SELECT cpu.fk_user, cpu.fk_type, cpu.nb_holiday, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1474
-                $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1475
-                $sql.= " WHERE cpu.fk_user = u.rowid";
1476
-                if ($filters) $sql.=$filters;
1474
+                $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1475
+                $sql .= " WHERE cpu.fk_user = u.rowid";
1476
+                if ($filters) $sql .= $filters;
1477 1477
 
1478
-                $resql=$this->db->query($sql);
1478
+                $resql = $this->db->query($sql);
1479 1479
 
1480 1480
                 // Si pas d'erreur SQL
1481 1481
                 if ($resql)
@@ -1485,12 +1485,12 @@  discard block
 block discarded – undo
1485 1485
                     $num = $this->db->num_rows($resql);
1486 1486
 
1487 1487
                     // Boucles du listage des utilisateurs
1488
-                    while($i < $num)
1488
+                    while ($i < $num)
1489 1489
                     {
1490 1490
                         $obj = $this->db->fetch_object($resql);
1491 1491
 
1492 1492
                         $tab_result[$i]['rowid'] = $obj->fk_user;
1493
-                        $tab_result[$i]['name'] = $obj->lastname;			// deprecated
1493
+                        $tab_result[$i]['name'] = $obj->lastname; // deprecated
1494 1494
                         $tab_result[$i]['lastname'] = $obj->lastname;
1495 1495
                         $tab_result[$i]['firstname'] = $obj->firstname;
1496 1496
                         $tab_result[$i]['gender'] = $obj->gender;
@@ -1510,7 +1510,7 @@  discard block
 block discarded – undo
1510 1510
                 else
1511 1511
 				{
1512 1512
                     // Erreur SQL
1513
-                    $this->error="Error ".$this->db->lasterror();
1513
+                    $this->error = "Error ".$this->db->lasterror();
1514 1514
                     return -1;
1515 1515
                 }
1516 1516
             }
@@ -1525,8 +1525,8 @@  discard block
 block discarded – undo
1525 1525
     function countActiveUsers()
1526 1526
     {
1527 1527
         $sql = "SELECT count(u.rowid) as compteur";
1528
-        $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
1529
-		$sql.= " WHERE u.statut > 0";
1528
+        $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
1529
+		$sql .= " WHERE u.statut > 0";
1530 1530
 
1531 1531
         $result = $this->db->query($sql);
1532 1532
         $objet = $this->db->fetch_object($result);
@@ -1541,8 +1541,8 @@  discard block
 block discarded – undo
1541 1541
     function countActiveUsersWithoutCP() {
1542 1542
 
1543 1543
         $sql = "SELECT count(u.rowid) as compteur";
1544
-        $sql.= " FROM ".MAIN_DB_PREFIX."user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX."holiday_users hu ON (hu.fk_user=u.rowid)";
1545
-		$sql.= " WHERE u.statut > 0 AND hu.fk_user IS NULL";
1544
+        $sql .= " FROM ".MAIN_DB_PREFIX."user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX."holiday_users hu ON (hu.fk_user=u.rowid)";
1545
+		$sql .= " WHERE u.statut > 0 AND hu.fk_user IS NULL";
1546 1546
 
1547 1547
         $result = $this->db->query($sql);
1548 1548
         $objet = $this->db->fetch_object($result);
@@ -1559,7 +1559,7 @@  discard block
 block discarded – undo
1559 1559
      */
1560 1560
     function verifNbUsers($userDolibarrWithoutCP, $userCP)
1561 1561
     {
1562
-    	if (empty($userCP)) $userCP=0;
1562
+    	if (empty($userCP)) $userCP = 0;
1563 1563
     	dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
1564 1564
         return 1;
1565 1565
     }
@@ -1579,7 +1579,7 @@  discard block
 block discarded – undo
1579 1579
     {
1580 1580
         global $conf, $langs;
1581 1581
 
1582
-        $error=0;
1582
+        $error = 0;
1583 1583
 
1584 1584
         $prev_solde = price2num($this->getCPforUser($fk_user_update, $fk_type), 5);
1585 1585
         $new_solde = price2num($new_solde, 5);
@@ -1591,30 +1591,30 @@  discard block
 block discarded – undo
1591 1591
 
1592 1592
 		// Insert request
1593 1593
         $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_logs (";
1594
-        $sql.= "date_action,";
1595
-        $sql.= "fk_user_action,";
1596
-        $sql.= "fk_user_update,";
1597
-        $sql.= "type_action,";
1598
-        $sql.= "prev_solde,";
1599
-        $sql.= "new_solde,";
1600
-		$sql.= "fk_type";
1601
-        $sql.= ") VALUES (";
1602
-        $sql.= " '".$this->db->idate(dol_now())."',";
1603
-        $sql.= " '".$fk_user_action."',";
1604
-        $sql.= " '".$fk_user_update."',";
1605
-        $sql.= " '".$this->db->escape($label)."',";
1606
-        $sql.= " '".$prev_solde."',";
1607
-        $sql.= " '".$new_solde."',";
1608
-        $sql.= " ".$fk_type;
1609
-        $sql.= ")";
1610
-
1611
-        $resql=$this->db->query($sql);
1612
-       	if (! $resql)
1594
+        $sql .= "date_action,";
1595
+        $sql .= "fk_user_action,";
1596
+        $sql .= "fk_user_update,";
1597
+        $sql .= "type_action,";
1598
+        $sql .= "prev_solde,";
1599
+        $sql .= "new_solde,";
1600
+		$sql .= "fk_type";
1601
+        $sql .= ") VALUES (";
1602
+        $sql .= " '".$this->db->idate(dol_now())."',";
1603
+        $sql .= " '".$fk_user_action."',";
1604
+        $sql .= " '".$fk_user_update."',";
1605
+        $sql .= " '".$this->db->escape($label)."',";
1606
+        $sql .= " '".$prev_solde."',";
1607
+        $sql .= " '".$new_solde."',";
1608
+        $sql .= " ".$fk_type;
1609
+        $sql .= ")";
1610
+
1611
+        $resql = $this->db->query($sql);
1612
+       	if (!$resql)
1613 1613
        	{
1614
-       	    $error++; $this->errors[]="Error ".$this->db->lasterror();
1614
+       	    $error++; $this->errors[] = "Error ".$this->db->lasterror();
1615 1615
        	}
1616 1616
 
1617
-       	if (! $error)
1617
+       	if (!$error)
1618 1618
        	{
1619 1619
        	    $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs");
1620 1620
        	}
@@ -1622,13 +1622,13 @@  discard block
 block discarded – undo
1622 1622
        	// Commit or rollback
1623 1623
        	if ($error)
1624 1624
        	{
1625
-       	    foreach($this->errors as $errmsg)
1625
+       	    foreach ($this->errors as $errmsg)
1626 1626
        	    {
1627 1627
    	            dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR);
1628
-   	            $this->error.=($this->error?', '.$errmsg:$errmsg);
1628
+   	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1629 1629
        	    }
1630 1630
        	    $this->db->rollback();
1631
-       	    return -1*$error;
1631
+       	    return -1 * $error;
1632 1632
        	}
1633 1633
        	else
1634 1634
        	{
@@ -1644,34 +1644,34 @@  discard block
 block discarded – undo
1644 1644
      *  @param  string	$filter     Filtre de séléction
1645 1645
      *  @return int         		-1 si erreur, 1 si OK et 2 si pas de résultat
1646 1646
      */
1647
-    function fetchLog($order,$filter)
1647
+    function fetchLog($order, $filter)
1648 1648
     {
1649 1649
         global $langs;
1650 1650
 
1651 1651
         $sql = "SELECT";
1652
-        $sql.= " cpl.rowid,";
1653
-        $sql.= " cpl.date_action,";
1654
-        $sql.= " cpl.fk_user_action,";
1655
-        $sql.= " cpl.fk_user_update,";
1656
-        $sql.= " cpl.type_action,";
1657
-        $sql.= " cpl.prev_solde,";
1658
-        $sql.= " cpl.new_solde,";
1659
-		$sql.= " cpl.fk_type";
1660
-        $sql.= " FROM ".MAIN_DB_PREFIX."holiday_logs as cpl";
1661
-        $sql.= " WHERE cpl.rowid > 0"; // To avoid error with other search and criteria
1652
+        $sql .= " cpl.rowid,";
1653
+        $sql .= " cpl.date_action,";
1654
+        $sql .= " cpl.fk_user_action,";
1655
+        $sql .= " cpl.fk_user_update,";
1656
+        $sql .= " cpl.type_action,";
1657
+        $sql .= " cpl.prev_solde,";
1658
+        $sql .= " cpl.new_solde,";
1659
+		$sql .= " cpl.fk_type";
1660
+        $sql .= " FROM ".MAIN_DB_PREFIX."holiday_logs as cpl";
1661
+        $sql .= " WHERE cpl.rowid > 0"; // To avoid error with other search and criteria
1662 1662
 
1663 1663
         // Filtrage de séléction
1664
-        if(!empty($filter)) {
1665
-            $sql.= " ".$filter;
1664
+        if (!empty($filter)) {
1665
+            $sql .= " ".$filter;
1666 1666
         }
1667 1667
 
1668 1668
         // Ordre d'affichage
1669
-        if(!empty($order)) {
1670
-            $sql.= " ".$order;
1669
+        if (!empty($order)) {
1670
+            $sql .= " ".$order;
1671 1671
         }
1672 1672
 
1673 1673
         dol_syslog(get_class($this)."::fetchLog", LOG_DEBUG);
1674
-        $resql=$this->db->query($sql);
1674
+        $resql = $this->db->query($sql);
1675 1675
 
1676 1676
         // Si pas d'erreur SQL
1677 1677
   		if ($resql) {
@@ -1681,12 +1681,12 @@  discard block
 block discarded – undo
1681 1681
   		    $num = $this->db->num_rows($resql);
1682 1682
 
1683 1683
   		    // Si pas d'enregistrement
1684
-  		    if(!$num) {
1684
+  		    if (!$num) {
1685 1685
                 return 2;
1686 1686
   		    }
1687 1687
 
1688 1688
   		    // On liste les résultats et on les ajoutent dans le tableau
1689
-  		    while($i < $num) {
1689
+  		    while ($i < $num) {
1690 1690
 
1691 1691
   		        $obj = $this->db->fetch_object($resql);
1692 1692
 
@@ -1708,7 +1708,7 @@  discard block
 block discarded – undo
1708 1708
   		else
1709 1709
   		{
1710 1710
   		    // Erreur SQL
1711
-  		    $this->error="Error ".$this->db->lasterror();
1711
+  		    $this->error = "Error ".$this->db->lasterror();
1712 1712
   		    return -1;
1713 1713
   		}
1714 1714
     }
@@ -1721,15 +1721,15 @@  discard block
 block discarded – undo
1721 1721
      *  @param		int		$affect		Filter on affect (a request will change sold or not). -1 = Both
1722 1722
      *  @return     array	    		Return array with list of types
1723 1723
      */
1724
-    function getTypes($active=-1, $affect=-1)
1724
+    function getTypes($active = -1, $affect = -1)
1725 1725
     {
1726 1726
     	global $mysoc;
1727 1727
 
1728 1728
     	$sql = "SELECT rowid, code, label, affect, delay, newByMonth";
1729
-    	$sql.= " FROM " . MAIN_DB_PREFIX . "c_holiday_types";
1730
-    	$sql.= " WHERE (fk_country IS NULL OR fk_country = ".$mysoc->country_id.')';
1731
-    	if ($active >= 0) $sql.=" AND active = ".((int) $active);
1732
-    	if ($affect >= 0) $sql.=" AND affect = ".((int) $affect);
1729
+    	$sql .= " FROM ".MAIN_DB_PREFIX."c_holiday_types";
1730
+    	$sql .= " WHERE (fk_country IS NULL OR fk_country = ".$mysoc->country_id.')';
1731
+    	if ($active >= 0) $sql .= " AND active = ".((int) $active);
1732
+    	if ($affect >= 0) $sql .= " AND affect = ".((int) $affect);
1733 1733
 
1734 1734
     	$result = $this->db->query($sql);
1735 1735
     	if ($result)
@@ -1760,19 +1760,19 @@  discard block
 block discarded – undo
1760 1760
      */
1761 1761
     function initAsSpecimen()
1762 1762
     {
1763
-    	global $user,$langs;
1763
+    	global $user, $langs;
1764 1764
 
1765 1765
     	// Initialise parameters
1766
-    	$this->id=0;
1767
-    	$this->specimen=1;
1768
-
1769
-    	$this->fk_user=1;
1770
-    	$this->description='SPECIMEN description';
1771
-    	$this->date_debut=dol_now();
1772
-    	$this->date_fin=dol_now()+(24*3600);
1773
-    	$this->fk_validator=1;
1774
-    	$this->halfday=0;
1775
-    	$this->fk_type=1;
1766
+    	$this->id = 0;
1767
+    	$this->specimen = 1;
1768
+
1769
+    	$this->fk_user = 1;
1770
+    	$this->description = 'SPECIMEN description';
1771
+    	$this->date_debut = dol_now();
1772
+    	$this->date_fin = dol_now() + (24 * 3600);
1773
+    	$this->fk_validator = 1;
1774
+    	$this->halfday = 0;
1775
+    	$this->fk_type = 1;
1776 1776
     }
1777 1777
 
1778 1778
 }
Please login to merge, or discard this patch.
Braces   +209 added lines, -123 removed lines patch added patch discarded remove patch
@@ -102,8 +102,7 @@  discard block
 block discarded – undo
102 102
 	    {
103 103
 	    	$this->db->commit();
104 104
 	    	return 1;
105
-	    }
106
-	    else
105
+	    } else
107 106
 		{
108 107
 	    	$this->db->rollback();
109 108
 	    	return -1;
@@ -187,8 +186,7 @@  discard block
 block discarded – undo
187 186
             }
188 187
             $this->db->rollback();
189 188
             return -1*$error;
190
-        }
191
-        else
189
+        } else
192 190
         {
193 191
             $this->db->commit();
194 192
             return $this->id;
@@ -268,8 +266,7 @@  discard block
 block discarded – undo
268 266
             $this->db->free($resql);
269 267
 
270 268
             return 1;
271
-        }
272
-        else
269
+        } else
273 270
         {
274 271
             $this->error="Error ".$this->db->lasterror();
275 272
             return -1;
@@ -394,8 +391,7 @@  discard block
 block discarded – undo
394 391
             // Retourne 1 avec le tableau rempli
395 392
             $this->holiday = $tab_result;
396 393
             return 1;
397
-        }
398
-        else
394
+        } else
399 395
         {
400 396
             // Erreur SQL
401 397
             $this->error="Error ".$this->db->lasterror();
@@ -518,8 +514,7 @@  discard block
 block discarded – undo
518 514
             // Retourne 1 et ajoute le tableau à la variable
519 515
             $this->holiday = $tab_result;
520 516
             return 1;
521
-        }
522
-        else
517
+        } else
523 518
         {
524 519
             // Erreur SQL
525 520
             $this->error="Error ".$this->db->lasterror();
@@ -632,8 +627,7 @@  discard block
 block discarded – undo
632 627
             }
633 628
             $this->db->rollback();
634 629
             return -1*$error;
635
-        }
636
-        else
630
+        } else
637 631
         {
638 632
             $this->db->commit();
639 633
             return 1;
@@ -685,8 +679,7 @@  discard block
 block discarded – undo
685 679
             }
686 680
             $this->db->rollback();
687 681
             return -1*$error;
688
-        }
689
-        else
682
+        } else
690 683
         {
691 684
             $this->db->commit();
692 685
             return 1;
@@ -712,8 +705,14 @@  discard block
 block discarded – undo
712 705
 
713 706
         foreach($this->holiday as $infos_CP)
714 707
         {
715
-        	if ($infos_CP['statut'] == 4) continue;		// ignore not validated holidays
716
-        	if ($infos_CP['statut'] == 5) continue;		// ignore not validated holidays
708
+        	if ($infos_CP['statut'] == 4) {
709
+        		continue;
710
+        	}
711
+        	// ignore not validated holidays
712
+        	if ($infos_CP['statut'] == 5) {
713
+        		continue;
714
+        	}
715
+        	// ignore not validated holidays
717 716
 
718 717
         	// TODO Also use halfday for the check
719 718
         	if ($halfday == 0)
@@ -722,29 +721,25 @@  discard block
 block discarded – undo
722 721
 	            {
723 722
 	                return false;
724 723
 	            }
725
-        	}
726
-            elseif ($halfday == -1)
724
+        	} elseif ($halfday == -1)
727 725
         	{
728 726
 	            if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut'])
729 727
 	            {
730 728
 	                return false;
731 729
 	            }
732
-        	}
733
-            elseif ($halfday == 1)
730
+        	} elseif ($halfday == 1)
734 731
         	{
735 732
 	            if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut'])
736 733
 	            {
737 734
 	                return false;
738 735
 	            }
739
-        	}
740
-            elseif ($halfday == 2)
736
+        	} elseif ($halfday == 2)
741 737
         	{
742 738
 	            if ($dateDebut >= $infos_CP['date_debut'] && $dateDebut <= $infos_CP['date_fin'] || $dateFin <= $infos_CP['date_fin'] && $dateFin >= $infos_CP['date_debut'])
743 739
 	            {
744 740
 	                return false;
745 741
 	            }
746
-        	}
747
-        	else
742
+        	} else
748 743
         	{
749 744
         		dol_print_error('', 'Bad value of parameter halfday when calling function verifDateHolidayCP');
750 745
         	}
@@ -795,22 +790,31 @@  discard block
 block discarded – undo
795 790
 	    		$isavailablemorning = true;
796 791
 	    		foreach($arrayofrecord as $record)
797 792
 	    		{
798
-					if ($timestamp == $record['date_start'] && $record['halfday'] == 2)  continue;
799
-					if ($timestamp == $record['date_start'] && $record['halfday'] == -1) continue;
793
+					if ($timestamp == $record['date_start'] && $record['halfday'] == 2) {
794
+						continue;
795
+					}
796
+					if ($timestamp == $record['date_start'] && $record['halfday'] == -1) {
797
+						continue;
798
+					}
800 799
 	    			$isavailablemorning = false;
801 800
 	    			break;
802 801
 	    		}
803 802
     			$isavailableafternoon = true;
804 803
 	    		foreach($arrayofrecord as $record)
805 804
 	    		{
806
-					if ($timestamp == $record['date_end'] && $record['halfday'] == 2) continue;
807
-					if ($timestamp == $record['date_end'] && $record['halfday'] == 1) continue;
805
+					if ($timestamp == $record['date_end'] && $record['halfday'] == 2) {
806
+						continue;
807
+					}
808
+					if ($timestamp == $record['date_end'] && $record['halfday'] == 1) {
809
+						continue;
810
+					}
808 811
 	    			$isavailableafternoon = false;
809 812
 	    			break;
810 813
 	    		}
811 814
     		}
815
+    	} else {
816
+    		dol_print_error($this->db);
812 817
     	}
813
-    	else dol_print_error($this->db);
814 818
 
815 819
    		return array('morning'=>$isavailablemorning, 'afternoon'=>$isavailableafternoon);
816 820
     }
@@ -837,16 +841,26 @@  discard block
 block discarded – undo
837 841
         //{
838 842
         	// Add param to save lastsearch_values or not
839 843
         	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
840
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
841
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
844
+        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) {
845
+        		$add_save_lastsearch_values=1;
846
+        	}
847
+        	if ($add_save_lastsearch_values) {
848
+        		$url.='&save_lastsearch_values=1';
849
+        	}
842 850
         //}
843 851
 
844 852
         $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
845 853
         $linkend='</a>';
846 854
 
847
-        if ($withpicto) $result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
848
-        if ($withpicto && $withpicto != 2) $result.=' ';
849
-        if ($withpicto != 2) $result.=$linkstart.$this->ref.$linkend;
855
+        if ($withpicto) {
856
+        	$result.=($linkstart.img_object($label, $picto, 'class="classfortooltip"').$linkend);
857
+        }
858
+        if ($withpicto && $withpicto != 2) {
859
+        	$result.=' ';
860
+        }
861
+        if ($withpicto != 2) {
862
+        	$result.=$linkstart.$this->ref.$linkend;
863
+        }
850 864
         return $result;
851 865
     }
852 866
 
@@ -876,51 +890,115 @@  discard block
 block discarded – undo
876 890
 
877 891
 		if ($mode == 0)
878 892
 		{
879
-            if ($statut == 1) return $langs->trans('DraftCP');
880
-            if ($statut == 2) return $langs->trans('ToReviewCP');
881
-            if ($statut == 3) return $langs->trans('ApprovedCP');
882
-            if ($statut == 4) return $langs->trans('CancelCP');
883
-            if ($statut == 5) return $langs->trans('RefuseCP');
893
+            if ($statut == 1) {
894
+            	return $langs->trans('DraftCP');
895
+            }
896
+            if ($statut == 2) {
897
+            	return $langs->trans('ToReviewCP');
898
+            }
899
+            if ($statut == 3) {
900
+            	return $langs->trans('ApprovedCP');
901
+            }
902
+            if ($statut == 4) {
903
+            	return $langs->trans('CancelCP');
904
+            }
905
+            if ($statut == 5) {
906
+            	return $langs->trans('RefuseCP');
907
+            }
884 908
 		}
885 909
 		if ($mode == 2)
886 910
 		{
887 911
 			$pictoapproved='statut6';
888
-			if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4';
889
-			if ($statut == 1) return img_picto($langs->trans('DraftCP'),'statut0').' '.$langs->trans('DraftCP');				// Draft
890
-			if ($statut == 2) return img_picto($langs->trans('ToReviewCP'),'statut1').' '.$langs->trans('ToReviewCP');		// Waiting approval
891
-			if ($statut == 3) return img_picto($langs->trans('ApprovedCP'),$pictoapproved).' '.$langs->trans('ApprovedCP');
892
-			if ($statut == 4) return img_picto($langs->trans('CancelCP'),'statut5').' '.$langs->trans('CancelCP');
893
-			if ($statut == 5) return img_picto($langs->trans('RefuseCP'),'statut5').' '.$langs->trans('RefuseCP');
912
+			if (! empty($startdate) && $startdate > dol_now()) {
913
+				$pictoapproved='statut4';
914
+			}
915
+			if ($statut == 1) {
916
+				return img_picto($langs->trans('DraftCP'),'statut0').' '.$langs->trans('DraftCP');
917
+			}
918
+			// Draft
919
+			if ($statut == 2) {
920
+				return img_picto($langs->trans('ToReviewCP'),'statut1').' '.$langs->trans('ToReviewCP');
921
+			}
922
+			// Waiting approval
923
+			if ($statut == 3) {
924
+				return img_picto($langs->trans('ApprovedCP'),$pictoapproved).' '.$langs->trans('ApprovedCP');
925
+			}
926
+			if ($statut == 4) {
927
+				return img_picto($langs->trans('CancelCP'),'statut5').' '.$langs->trans('CancelCP');
928
+			}
929
+			if ($statut == 5) {
930
+				return img_picto($langs->trans('RefuseCP'),'statut5').' '.$langs->trans('RefuseCP');
931
+			}
894 932
 		}
895 933
 		if ($mode == 3)
896 934
 		{
897 935
 			$pictoapproved='statut6';
898
-			if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4';
899
-			if ($statut == 1) return img_picto($langs->trans('DraftCP'),'statut0');
900
-			if ($statut == 2) return img_picto($langs->trans('ToReviewCP'),'statut1');
901
-			if ($statut == 3) return img_picto($langs->trans('ApprovedCP'),$pictoapproved);
902
-			if ($statut == 4) return img_picto($langs->trans('CancelCP'),'statut5');
903
-			if ($statut == 5) return img_picto($langs->trans('RefuseCP'),'statut5');
936
+			if (! empty($startdate) && $startdate > dol_now()) {
937
+				$pictoapproved='statut4';
938
+			}
939
+			if ($statut == 1) {
940
+				return img_picto($langs->trans('DraftCP'),'statut0');
941
+			}
942
+			if ($statut == 2) {
943
+				return img_picto($langs->trans('ToReviewCP'),'statut1');
944
+			}
945
+			if ($statut == 3) {
946
+				return img_picto($langs->trans('ApprovedCP'),$pictoapproved);
947
+			}
948
+			if ($statut == 4) {
949
+				return img_picto($langs->trans('CancelCP'),'statut5');
950
+			}
951
+			if ($statut == 5) {
952
+				return img_picto($langs->trans('RefuseCP'),'statut5');
953
+			}
904 954
 		}
905 955
 		if ($mode == 5)
906 956
 		{
907 957
 			$pictoapproved='statut6';
908
-			if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4';
909
-			if ($statut == 1) return $langs->trans('DraftCP').' '.img_picto($langs->trans('DraftCP'),'statut0');				// Draft
910
-			if ($statut == 2) return $langs->trans('ToReviewCP').' '.img_picto($langs->trans('ToReviewCP'),'statut1');		// Waiting approval
911
-			if ($statut == 3) return $langs->trans('ApprovedCP').' '.img_picto($langs->trans('ApprovedCP'),$pictoapproved);
912
-			if ($statut == 4) return $langs->trans('CancelCP').' '.img_picto($langs->trans('CancelCP'),'statut5');
913
-			if ($statut == 5) return $langs->trans('RefuseCP').' '.img_picto($langs->trans('RefuseCP'),'statut5');
958
+			if (! empty($startdate) && $startdate > dol_now()) {
959
+				$pictoapproved='statut4';
960
+			}
961
+			if ($statut == 1) {
962
+				return $langs->trans('DraftCP').' '.img_picto($langs->trans('DraftCP'),'statut0');
963
+			}
964
+			// Draft
965
+			if ($statut == 2) {
966
+				return $langs->trans('ToReviewCP').' '.img_picto($langs->trans('ToReviewCP'),'statut1');
967
+			}
968
+			// Waiting approval
969
+			if ($statut == 3) {
970
+				return $langs->trans('ApprovedCP').' '.img_picto($langs->trans('ApprovedCP'),$pictoapproved);
971
+			}
972
+			if ($statut == 4) {
973
+				return $langs->trans('CancelCP').' '.img_picto($langs->trans('CancelCP'),'statut5');
974
+			}
975
+			if ($statut == 5) {
976
+				return $langs->trans('RefuseCP').' '.img_picto($langs->trans('RefuseCP'),'statut5');
977
+			}
914 978
 		}
915 979
 		if ($mode == 6)
916 980
 		{
917 981
 		    $pictoapproved='statut6';
918
-		    if (! empty($startdate) && $startdate > dol_now()) $pictoapproved='statut4';
919
-		    if ($statut == 1) return $langs->trans('DraftCP').' '.img_picto($langs->trans('DraftCP'),'statut0');				// Draft
920
-		    if ($statut == 2) return $langs->trans('ToReviewCP').' '.img_picto($langs->trans('ToReviewCP'),'statut1');		// Waiting approval
921
-		    if ($statut == 3) return $langs->trans('ApprovedCP').' '.img_picto($langs->trans('ApprovedCP'),$pictoapproved);
922
-		    if ($statut == 4) return $langs->trans('CancelCP').' '.img_picto($langs->trans('CancelCP'),'statut5');
923
-		    if ($statut == 5) return $langs->trans('RefuseCP').' '.img_picto($langs->trans('RefuseCP'),'statut5');
982
+		    if (! empty($startdate) && $startdate > dol_now()) {
983
+		    	$pictoapproved='statut4';
984
+		    }
985
+		    if ($statut == 1) {
986
+		    	return $langs->trans('DraftCP').' '.img_picto($langs->trans('DraftCP'),'statut0');
987
+		    }
988
+		    // Draft
989
+		    if ($statut == 2) {
990
+		    	return $langs->trans('ToReviewCP').' '.img_picto($langs->trans('ToReviewCP'),'statut1');
991
+		    }
992
+		    // Waiting approval
993
+		    if ($statut == 3) {
994
+		    	return $langs->trans('ApprovedCP').' '.img_picto($langs->trans('ApprovedCP'),$pictoapproved);
995
+		    }
996
+		    if ($statut == 4) {
997
+		    	return $langs->trans('CancelCP').' '.img_picto($langs->trans('CancelCP'),'statut5');
998
+		    }
999
+		    if ($statut == 5) {
1000
+		    	return $langs->trans('RefuseCP').' '.img_picto($langs->trans('RefuseCP'),'statut5');
1001
+		    }
924 1002
 		}
925 1003
 
926 1004
 		return $statut;
@@ -949,8 +1027,7 @@  discard block
 block discarded – undo
949 1027
         for($i=1; $i < $nb; $i++) {
950 1028
             if($i==$selected) {
951 1029
                 $statut.= '<option value="'.$i.'" selected>'.$langs->trans($name[$i-1]).'</option>'."\n";
952
-            }
953
-            else {
1030
+            } else {
954 1031
                 $statut.= '<option value="'.$i.'">'.$langs->trans($name[$i-1]).'</option>'."\n";
955 1032
             }
956 1033
         }
@@ -1013,19 +1090,16 @@  discard block
 block discarded – undo
1013 1090
                     if ($result)
1014 1091
                     {
1015 1092
                         return $createifnotfound;
1016
-                    }
1017
-                    else
1093
+                    } else
1018 1094
                     {
1019 1095
                         $this->error=$this->db->lasterror();
1020 1096
                         return -2;
1021 1097
                     }
1022
-                }
1023
-                else
1098
+                } else
1024 1099
                 {
1025 1100
                     return '';
1026 1101
                 }
1027
-            }
1028
-            else
1102
+            } else
1029 1103
             {
1030 1104
                 return $obj->value;
1031 1105
             }
@@ -1084,7 +1158,9 @@  discard block
 block discarded – undo
1084 1158
     			{
1085 1159
 	                // On ajoute x jours à chaque utilisateurs
1086 1160
 	                $nb_holiday = $val['newByMonth'];
1087
-					if (empty($nb_holiday)) $nb_holiday=0;
1161
+					if (empty($nb_holiday)) {
1162
+						$nb_holiday=0;
1163
+					}
1088 1164
 
1089 1165
 					if ($nb_holiday > 0)
1090 1166
 					{
@@ -1114,16 +1190,16 @@  discard block
 block discarded – undo
1114 1190
 		                	dol_print_error($this->db);
1115 1191
 		                	break;
1116 1192
 		                }
1193
+					} else {
1194
+						dol_syslog("No change for leave of type ".$key, LOG_DEBUG);
1117 1195
 					}
1118
-					else dol_syslog("No change for leave of type ".$key, LOG_DEBUG);
1119 1196
     			}
1120 1197
 
1121 1198
 				if ($result)
1122 1199
 	           	{
1123 1200
 	            	$this->db->commit();
1124 1201
 	            	return 1;
1125
-	           	}
1126
-    	       	else
1202
+	           	} else
1127 1203
     	      	{
1128 1204
     	       		$this->db->rollback();
1129 1205
     	        	return -1;
@@ -1131,8 +1207,7 @@  discard block
 block discarded – undo
1131 1207
             }
1132 1208
 
1133 1209
             return 0;
1134
-        }
1135
-        else
1210
+        } else
1136 1211
 		{
1137 1212
             // Mise à jour pour un utilisateur
1138 1213
             $nbHoliday = price2num($nbHoliday,5);
@@ -1156,8 +1231,7 @@  discard block
 block discarded – undo
1156 1231
 		            	$error++;
1157 1232
 		            	$this->errors[]=$this->db->lasterror();
1158 1233
 		            }
1159
-            	}
1160
-            	else
1234
+            	} else
1161 1235
             	{
1162 1236
 		            // Insert for user
1163 1237
 		            $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
@@ -1170,8 +1244,7 @@  discard block
 block discarded – undo
1170 1244
 		            	$this->errors[]=$this->db->lasterror();
1171 1245
 		            }
1172 1246
             	}
1173
-            }
1174
-            else
1247
+            } else
1175 1248
 			{
1176 1249
 		        $this->errors[]=$this->db->lasterror();
1177 1250
             	$error++;
@@ -1180,8 +1253,7 @@  discard block
 block discarded – undo
1180 1253
             if (! $error)
1181 1254
             {
1182 1255
             	return 1;
1183
-            }
1184
-            else
1256
+            } else
1185 1257
            {
1186 1258
             	return -1;
1187 1259
             }
@@ -1236,17 +1308,20 @@  discard block
 block discarded – undo
1236 1308
                 $sql.= " VALUES ('".$users['rowid']."','0')";
1237 1309
 
1238 1310
                 $resql=$this->db->query($sql);
1239
-                if (! $resql) dol_print_error($this->db);
1311
+                if (! $resql) {
1312
+                	dol_print_error($this->db);
1313
+                }
1240 1314
             }
1241
-        }
1242
-        else
1315
+        } else
1243 1316
 		{
1244 1317
             $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1245 1318
             $sql.= " (fk_user, nb_holiday)";
1246 1319
             $sql.= " VALUES ('".$userid."','0')";
1247 1320
 
1248 1321
             $resql=$this->db->query($sql);
1249
-            if (! $resql) dol_print_error($this->db);
1322
+            if (! $resql) {
1323
+            	dol_print_error($this->db);
1324
+            }
1250 1325
         }
1251 1326
     }
1252 1327
 
@@ -1278,7 +1353,9 @@  discard block
 block discarded – undo
1278 1353
         $sql = "SELECT nb_holiday";
1279 1354
         $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users";
1280 1355
         $sql.= " WHERE fk_user = '".$user_id."'";
1281
-        if ($fk_type > 0) $sql.=" AND fk_type = ".$fk_type;
1356
+        if ($fk_type > 0) {
1357
+        	$sql.=" AND fk_type = ".$fk_type;
1358
+        }
1282 1359
 
1283 1360
         dol_syslog(get_class($this).'::getCPforUser', LOG_DEBUG);
1284 1361
         $result = $this->db->query($sql);
@@ -1286,10 +1363,12 @@  discard block
 block discarded – undo
1286 1363
         {
1287 1364
             $obj = $this->db->fetch_object($result);
1288 1365
             //return number_format($obj->nb_holiday,2);
1289
-            if ($obj) return $obj->nb_holiday;
1290
-            else return null;
1291
-        }
1292
-        else
1366
+            if ($obj) {
1367
+            	return $obj->nb_holiday;
1368
+            } else {
1369
+            	return null;
1370
+            }
1371
+        } else
1293 1372
 		{
1294 1373
             return null;
1295 1374
         }
@@ -1324,13 +1403,14 @@  discard block
 block discarded – undo
1324 1403
                 	$sql.= " WHERE (ug.fk_user = u.rowid";
1325 1404
                 	$sql.= " AND ug.entity = ".$conf->entity.")";
1326 1405
                 	$sql.= " OR u.admin = 1";
1327
-                }
1328
-                else
1406
+                } else
1329 1407
                 {
1330 1408
                 	$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
1331 1409
                 }
1332 1410
                 $sql.= " AND u.statut > 0";
1333
-                if ($filters) $sql.=$filters;
1411
+                if ($filters) {
1412
+                	$sql.=$filters;
1413
+                }
1334 1414
 
1335 1415
                 $resql=$this->db->query($sql);
1336 1416
 
@@ -1356,22 +1436,22 @@  discard block
 block discarded – undo
1356 1436
                     }
1357 1437
                     // Retoune le tableau des utilisateurs
1358 1438
                     return $stringlist;
1359
-                }
1360
-                else
1439
+                } else
1361 1440
                 {
1362 1441
                     // Erreur SQL
1363 1442
                     $this->error="Error ".$this->db->lasterror();
1364 1443
                     return -1;
1365 1444
                 }
1366 1445
 
1367
-            }
1368
-            else
1446
+            } else
1369 1447
             {
1370 1448
            		// We want only list of vacation balance for user ids
1371 1449
                 $sql = "SELECT DISTINCT cpu.fk_user";
1372 1450
                 $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1373 1451
                 $sql.= " WHERE cpu.fk_user = u.user";
1374
-                if ($filters) $sql.=$filters;
1452
+                if ($filters) {
1453
+                	$sql.=$filters;
1454
+                }
1375 1455
 
1376 1456
                 $resql=$this->db->query($sql);
1377 1457
 
@@ -1397,8 +1477,7 @@  discard block
 block discarded – undo
1397 1477
                     }
1398 1478
                     // Retoune le tableau des utilisateurs
1399 1479
                     return $stringlist;
1400
-                }
1401
-                else
1480
+                } else
1402 1481
               {
1403 1482
                     // Erreur SQL
1404 1483
                     $this->error="Error ".$this->db->lasterror();
@@ -1406,8 +1485,7 @@  discard block
 block discarded – undo
1406 1485
                 }
1407 1486
             }
1408 1487
 
1409
-        }
1410
-        else
1488
+        } else
1411 1489
         { // Si faux donc return array
1412 1490
 
1413 1491
             // List for Dolibarr users
@@ -1422,12 +1500,14 @@  discard block
 block discarded – undo
1422 1500
                 	$sql.= " WHERE (ug.fk_user = u.rowid";
1423 1501
                 	$sql.= " AND ug.entity = ".$conf->entity.")";
1424 1502
                 	$sql.= " OR u.admin = 1";
1503
+                } else {
1504
+                                	$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
1425 1505
                 }
1426
-                else
1427
-                	$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
1428 1506
 
1429 1507
                 $sql.= " AND u.statut > 0";
1430
-                if ($filters) $sql.=$filters;
1508
+                if ($filters) {
1509
+                	$sql.=$filters;
1510
+                }
1431 1511
 
1432 1512
                 $resql=$this->db->query($sql);
1433 1513
 
@@ -1459,21 +1539,21 @@  discard block
 block discarded – undo
1459 1539
                     }
1460 1540
                     // Retoune le tableau des utilisateurs
1461 1541
                     return $tab_result;
1462
-                }
1463
-                else
1542
+                } else
1464 1543
 				{
1465 1544
                     // Erreur SQL
1466 1545
                     $this->errors[]="Error ".$this->db->lasterror();
1467 1546
                     return -1;
1468 1547
                 }
1469
-            }
1470
-            else
1548
+            } else
1471 1549
             {
1472 1550
 				// List of vacation balance users
1473 1551
                 $sql = "SELECT cpu.fk_user, cpu.fk_type, cpu.nb_holiday, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user";
1474 1552
                 $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1475 1553
                 $sql.= " WHERE cpu.fk_user = u.rowid";
1476
-                if ($filters) $sql.=$filters;
1554
+                if ($filters) {
1555
+                	$sql.=$filters;
1556
+                }
1477 1557
 
1478 1558
                 $resql=$this->db->query($sql);
1479 1559
 
@@ -1506,8 +1586,7 @@  discard block
 block discarded – undo
1506 1586
                     }
1507 1587
                     // Retoune le tableau des utilisateurs
1508 1588
                     return $tab_result;
1509
-                }
1510
-                else
1589
+                } else
1511 1590
 				{
1512 1591
                     // Erreur SQL
1513 1592
                     $this->error="Error ".$this->db->lasterror();
@@ -1559,7 +1638,9 @@  discard block
 block discarded – undo
1559 1638
      */
1560 1639
     function verifNbUsers($userDolibarrWithoutCP, $userCP)
1561 1640
     {
1562
-    	if (empty($userCP)) $userCP=0;
1641
+    	if (empty($userCP)) {
1642
+    		$userCP=0;
1643
+    	}
1563 1644
     	dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
1564 1645
         return 1;
1565 1646
     }
@@ -1585,7 +1666,9 @@  discard block
 block discarded – undo
1585 1666
         $new_solde = price2num($new_solde, 5);
1586 1667
 		//print "$prev_solde == $new_solde";
1587 1668
 
1588
-        if ($prev_solde == $new_solde) return 0;
1669
+        if ($prev_solde == $new_solde) {
1670
+        	return 0;
1671
+        }
1589 1672
 
1590 1673
 		$this->db->begin();
1591 1674
 
@@ -1629,8 +1712,7 @@  discard block
 block discarded – undo
1629 1712
        	    }
1630 1713
        	    $this->db->rollback();
1631 1714
        	    return -1*$error;
1632
-       	}
1633
-       	else
1715
+       	} else
1634 1716
        	{
1635 1717
        	    $this->db->commit();
1636 1718
             return $this->optRowid;
@@ -1704,8 +1786,7 @@  discard block
 block discarded – undo
1704 1786
   		    // Retourne 1 et ajoute le tableau à la variable
1705 1787
   		    $this->logs = $tab_result;
1706 1788
   		    return 1;
1707
-  		}
1708
-  		else
1789
+  		} else
1709 1790
   		{
1710 1791
   		    // Erreur SQL
1711 1792
   		    $this->error="Error ".$this->db->lasterror();
@@ -1728,8 +1809,12 @@  discard block
 block discarded – undo
1728 1809
     	$sql = "SELECT rowid, code, label, affect, delay, newByMonth";
1729 1810
     	$sql.= " FROM " . MAIN_DB_PREFIX . "c_holiday_types";
1730 1811
     	$sql.= " WHERE (fk_country IS NULL OR fk_country = ".$mysoc->country_id.')';
1731
-    	if ($active >= 0) $sql.=" AND active = ".((int) $active);
1732
-    	if ($affect >= 0) $sql.=" AND affect = ".((int) $affect);
1812
+    	if ($active >= 0) {
1813
+    		$sql.=" AND active = ".((int) $active);
1814
+    	}
1815
+    	if ($affect >= 0) {
1816
+    		$sql.=" AND affect = ".((int) $affect);
1817
+    	}
1733 1818
 
1734 1819
     	$result = $this->db->query($sql);
1735 1820
     	if ($result)
@@ -1744,8 +1829,9 @@  discard block
 block discarded – undo
1744 1829
 
1745 1830
 	    		return $types;
1746 1831
 	    	}
1832
+    	} else {
1833
+    		dol_print_error($this->db);
1747 1834
     	}
1748
-    	else dol_print_error($this->db);
1749 1835
 
1750 1836
     	return array();
1751 1837
     }
Please login to merge, or discard this patch.
htdocs/categories/class/api_deprecated_category.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -297,7 +297,7 @@
 block discarded – undo
297 297
      * @param int		$cusid	Id of customer
298 298
      * @param int		$catid  Id of category
299 299
      * 
300
-     * @return mixed
300
+     * @return Client
301 301
      * 
302 302
      * @url GET /customer/{cusid}/addCategory/{catid}
303 303
      */
Please login to merge, or discard this patch.
Indentation   +389 added lines, -389 removed lines patch added patch discarded remove patch
@@ -31,462 +31,462 @@
 block discarded – undo
31 31
  */
32 32
 class CategoryApi extends DolibarrApi
33 33
 {
34
-    /**
35
-     * @var array   $FIELDS     Mandatory fields, checked when create and update object 
36
-     */
37
-    static $FIELDS = array(
38
-        'label',
39
-        'type'
40
-    );
34
+	/**
35
+	 * @var array   $FIELDS     Mandatory fields, checked when create and update object 
36
+	 */
37
+	static $FIELDS = array(
38
+		'label',
39
+		'type'
40
+	);
41 41
 
42
-    static $TYPES = array(
43
-        0 => 'product',
44
-        1 => 'supplier',
45
-        2 => 'customer',
46
-        3 => 'member',
47
-        4 => 'contact',
48
-        5 => 'account',
49
-    );
42
+	static $TYPES = array(
43
+		0 => 'product',
44
+		1 => 'supplier',
45
+		2 => 'customer',
46
+		3 => 'member',
47
+		4 => 'contact',
48
+		5 => 'account',
49
+	);
50 50
     
51
-    /**
52
-     * @var Categorie $category {@type Categorie}
53
-     */
54
-    public $category;
51
+	/**
52
+	 * @var Categorie $category {@type Categorie}
53
+	 */
54
+	public $category;
55 55
 
56
-    /**
57
-     * Constructor <b>Warning: Deprecated</b>
58
-     *
59
-     * @url     GET category/
60
-     * 
61
-     */
62
-    function __construct()
63
-    {
56
+	/**
57
+	 * Constructor <b>Warning: Deprecated</b>
58
+	 *
59
+	 * @url     GET category/
60
+	 * 
61
+	 */
62
+	function __construct()
63
+	{
64 64
 		global $db, $conf;
65 65
 		$this->db = $db;
66
-        $this->category = new Categorie($this->db);
66
+		$this->category = new Categorie($this->db);
67 67
         
68
-    }
68
+	}
69 69
 
70
-    /**
71
-     * Get properties of a category object <b>Warning: Deprecated</b>
72
-     *
73
-     * Return an array with category informations
74
-     *
75
-     * @param 	int 	$id ID of category
76
-     * @return 	array|mixed data without useless information
70
+	/**
71
+	 * Get properties of a category object <b>Warning: Deprecated</b>
72
+	 *
73
+	 * Return an array with category informations
74
+	 *
75
+	 * @param 	int 	$id ID of category
76
+	 * @return 	array|mixed data without useless information
77 77
 	 * 
78
-     * @url	GET category/{id}
79
-     * @throws 	RestException
80
-     */
81
-    function get($id)
82
-    {		
78
+	 * @url	GET category/{id}
79
+	 * @throws 	RestException
80
+	 */
81
+	function get($id)
82
+	{		
83 83
 		if(! DolibarrApiAccess::$user->rights->categorie->lire) {
84 84
 			throw new RestException(401);
85 85
 		}
86 86
 			
87
-        $result = $this->category->fetch($id);
88
-        if( ! $result ) {
89
-            throw new RestException(404, 'category not found');
90
-        }
87
+		$result = $this->category->fetch($id);
88
+		if( ! $result ) {
89
+			throw new RestException(404, 'category not found');
90
+		}
91 91
 		
92 92
 		if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
93 93
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
94 94
 		}
95 95
 
96 96
 		return $this->_cleanObjectDatas($this->category);
97
-    }
97
+	}
98 98
 
99
-    /**
100
-     * List categories <b>Warning: Deprecated</b>
101
-     * 
102
-     * Get a list of categories
103
-     *
104
-     * @param string	$type		Type of category ('member', 'customer', 'supplier', 'product', 'contact')
105
-     * @param string	$sortfield	Sort field
106
-     * @param string	$sortorder	Sort order
107
-     * @param int		$limit		Limit for list
108
-     * @param int		$page		Page number
109
-     * @return array Array of category objects
110
-     *
111
-     * @url	GET /category/list
112
-     */
113
-    function getList($type='product', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
114
-        global $db, $conf;
99
+	/**
100
+	 * List categories <b>Warning: Deprecated</b>
101
+	 * 
102
+	 * Get a list of categories
103
+	 *
104
+	 * @param string	$type		Type of category ('member', 'customer', 'supplier', 'product', 'contact')
105
+	 * @param string	$sortfield	Sort field
106
+	 * @param string	$sortorder	Sort order
107
+	 * @param int		$limit		Limit for list
108
+	 * @param int		$page		Page number
109
+	 * @return array Array of category objects
110
+	 *
111
+	 * @url	GET /category/list
112
+	 */
113
+	function getList($type='product', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
114
+		global $db, $conf;
115 115
         
116
-        $obj_ret = array();
116
+		$obj_ret = array();
117 117
         
118
-         if(! DolibarrApiAccess::$user->rights->categorie->lire) {
118
+		 if(! DolibarrApiAccess::$user->rights->categorie->lire) {
119 119
 			throw new RestException(401);
120 120
 		}
121 121
         
122
-        $sql = "SELECT s.rowid";
123
-        $sql.= " FROM ".MAIN_DB_PREFIX."categorie as s";
124
-        $sql.= ' WHERE s.entity IN ('.getEntity('category').')';
125
-        $sql.= ' AND s.type='.array_search($type,CategoryApi::$TYPES);
122
+		$sql = "SELECT s.rowid";
123
+		$sql.= " FROM ".MAIN_DB_PREFIX."categorie as s";
124
+		$sql.= ' WHERE s.entity IN ('.getEntity('category').')';
125
+		$sql.= ' AND s.type='.array_search($type,CategoryApi::$TYPES);
126 126
 
127
-        $nbtotalofrecords = '';
128
-        if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
129
-        {
130
-            $result = $db->query($sql);
131
-            $nbtotalofrecords = $db->num_rows($result);
132
-        }
127
+		$nbtotalofrecords = '';
128
+		if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
129
+		{
130
+			$result = $db->query($sql);
131
+			$nbtotalofrecords = $db->num_rows($result);
132
+		}
133 133
 
134
-        $sql.= $db->order($sortfield, $sortorder);
135
-        if ($limit)	{
136
-            if ($page < 0)
137
-            {
138
-                $page = 0;
139
-            }
140
-            $offset = $limit * $page;
134
+		$sql.= $db->order($sortfield, $sortorder);
135
+		if ($limit)	{
136
+			if ($page < 0)
137
+			{
138
+				$page = 0;
139
+			}
140
+			$offset = $limit * $page;
141 141
 
142
-            $sql.= $db->plimit($limit + 1, $offset);
143
-        }
142
+			$sql.= $db->plimit($limit + 1, $offset);
143
+		}
144 144
 
145
-        $result = $db->query($sql);
146
-        if ($result)
147
-        {
148
-        	$i=0;
149
-            $num = $db->num_rows($result);
150
-            $min = min($num, ($limit <= 0 ? $num : $limit));
151
-            while ($i < $min)
152
-            {
153
-                $obj = $db->fetch_object($result);
154
-                $category_static = new Categorie($db);
155
-                if($category_static->fetch($obj->rowid)) {
156
-                    $obj_ret[] = $this->_cleanObjectDatas($category_static);
157
-                }
158
-                $i++;
159
-            }
160
-        }
161
-        else {
162
-            throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
163
-        }
164
-        if( ! count($obj_ret)) {
165
-            throw new RestException(404, 'No category found');
166
-        }
145
+		$result = $db->query($sql);
146
+		if ($result)
147
+		{
148
+			$i=0;
149
+			$num = $db->num_rows($result);
150
+			$min = min($num, ($limit <= 0 ? $num : $limit));
151
+			while ($i < $min)
152
+			{
153
+				$obj = $db->fetch_object($result);
154
+				$category_static = new Categorie($db);
155
+				if($category_static->fetch($obj->rowid)) {
156
+					$obj_ret[] = $this->_cleanObjectDatas($category_static);
157
+				}
158
+				$i++;
159
+			}
160
+		}
161
+		else {
162
+			throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
163
+		}
164
+		if( ! count($obj_ret)) {
165
+			throw new RestException(404, 'No category found');
166
+		}
167 167
 		return $obj_ret;
168
-    }
169
-    /**
170
-     * List categories of an entity <b>Warning: Deprecated</b>
171
-     * 
172
-     * Get a list of categories
173
-     *
174
-     * @param string	$type		Type of category ('member', 'customer', 'supplier', 'product', 'contact')
175
-     * @param string	$sortfield	Sort field
176
-     * @param string	$sortorder	Sort order
177
-     * @param int		$limit		Limit for list
178
-     * @param int		$page		Page number
179
-     * @param int		$item		Id of the item to get categories for
180
-     * @return array Array of category objects
181
-     *
182
-     * @url	GET /product/{item}/categories
183
-     */
184
-    function getListForItem($type='product', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $item = 0) {
185
-        global $db, $conf;
168
+	}
169
+	/**
170
+	 * List categories of an entity <b>Warning: Deprecated</b>
171
+	 * 
172
+	 * Get a list of categories
173
+	 *
174
+	 * @param string	$type		Type of category ('member', 'customer', 'supplier', 'product', 'contact')
175
+	 * @param string	$sortfield	Sort field
176
+	 * @param string	$sortorder	Sort order
177
+	 * @param int		$limit		Limit for list
178
+	 * @param int		$page		Page number
179
+	 * @param int		$item		Id of the item to get categories for
180
+	 * @return array Array of category objects
181
+	 *
182
+	 * @url	GET /product/{item}/categories
183
+	 */
184
+	function getListForItem($type='product', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $item = 0) {
185
+		global $db, $conf;
186 186
         
187
-        $obj_ret = array();
187
+		$obj_ret = array();
188 188
         
189
-         if(! DolibarrApiAccess::$user->rights->categorie->lire) {
190
-			    throw new RestException(401);
191
-         }
192
-        //if ($type == "") {
193
-          //$type="product";
194
-        //}
195
-        $sub_type = $type;
196
-        $subcol_name = "fk_".$type;
197
-        if ($type=="customer" || $type=="supplier") {
198
-          $sub_type="societe";
199
-          $subcol_name="fk_soc";
200
-        }
201
-        $sql = "SELECT s.rowid";
202
-        $sql.= " FROM ".MAIN_DB_PREFIX."categorie as s";
203
-        $sql.= " , ".MAIN_DB_PREFIX."categorie_".$sub_type." as sub ";
204
-        $sql.= ' WHERE s.entity IN ('.getEntity('category').')';
205
-        $sql.= ' AND s.type='.array_search($type,CategoryApi::$TYPES);
206
-        $sql.= ' AND s.rowid = sub.fk_categorie';
207
-        $sql.= ' AND sub.'.$subcol_name.' = '.$item;
189
+		 if(! DolibarrApiAccess::$user->rights->categorie->lire) {
190
+				throw new RestException(401);
191
+		 }
192
+		//if ($type == "") {
193
+		  //$type="product";
194
+		//}
195
+		$sub_type = $type;
196
+		$subcol_name = "fk_".$type;
197
+		if ($type=="customer" || $type=="supplier") {
198
+		  $sub_type="societe";
199
+		  $subcol_name="fk_soc";
200
+		}
201
+		$sql = "SELECT s.rowid";
202
+		$sql.= " FROM ".MAIN_DB_PREFIX."categorie as s";
203
+		$sql.= " , ".MAIN_DB_PREFIX."categorie_".$sub_type." as sub ";
204
+		$sql.= ' WHERE s.entity IN ('.getEntity('category').')';
205
+		$sql.= ' AND s.type='.array_search($type,CategoryApi::$TYPES);
206
+		$sql.= ' AND s.rowid = sub.fk_categorie';
207
+		$sql.= ' AND sub.'.$subcol_name.' = '.$item;
208 208
 
209
-        $nbtotalofrecords = '';
210
-        if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
211
-        {
212
-            $result = $db->query($sql);
213
-            $nbtotalofrecords = $db->num_rows($result);
214
-        }
209
+		$nbtotalofrecords = '';
210
+		if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
211
+		{
212
+			$result = $db->query($sql);
213
+			$nbtotalofrecords = $db->num_rows($result);
214
+		}
215 215
 
216
-        $sql.= $db->order($sortfield, $sortorder);
217
-        if ($limit)	{
218
-            if ($page < 0)
219
-            {
220
-                $page = 0;
221
-            }
222
-            $offset = $limit * $page;
216
+		$sql.= $db->order($sortfield, $sortorder);
217
+		if ($limit)	{
218
+			if ($page < 0)
219
+			{
220
+				$page = 0;
221
+			}
222
+			$offset = $limit * $page;
223 223
 
224
-            $sql.= $db->plimit($limit + 1, $offset);
225
-        }
224
+			$sql.= $db->plimit($limit + 1, $offset);
225
+		}
226 226
 
227
-        $result = $db->query($sql);
228
-        if ($result)
229
-        {
230
-        	$i=0;
231
-            $num = $db->num_rows($result);
232
-            $min = min($num, ($limit <= 0 ? $num : $limit));
233
-            while ($i < $min)
234
-            {
235
-                $obj = $db->fetch_object($result);
236
-                $category_static = new Categorie($db);
237
-                if($category_static->fetch($obj->rowid)) {
238
-                    $obj_ret[] = $this->_cleanObjectDatas($category_static);
239
-                }
240
-                $i++;
241
-            }
242
-        }
243
-        else {
244
-            throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
245
-        }
246
-        if( ! count($obj_ret)) {
247
-            throw new RestException(404, 'No category found');
248
-        }
227
+		$result = $db->query($sql);
228
+		if ($result)
229
+		{
230
+			$i=0;
231
+			$num = $db->num_rows($result);
232
+			$min = min($num, ($limit <= 0 ? $num : $limit));
233
+			while ($i < $min)
234
+			{
235
+				$obj = $db->fetch_object($result);
236
+				$category_static = new Categorie($db);
237
+				if($category_static->fetch($obj->rowid)) {
238
+					$obj_ret[] = $this->_cleanObjectDatas($category_static);
239
+				}
240
+				$i++;
241
+			}
242
+		}
243
+		else {
244
+			throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
245
+		}
246
+		if( ! count($obj_ret)) {
247
+			throw new RestException(404, 'No category found');
248
+		}
249 249
 		return $obj_ret;
250
-    }
250
+	}
251 251
     
252
-    /**
253
-     * Get member categories list <b>Warning: Deprecated</b>
254
-     * 
255
-     * @param string	$sortfield	Sort field
256
-     * @param string	$sortorder	Sort order
257
-     * @param int		$limit		Limit for list
258
-     * @param int		$page		Page number
259
-     * @return mixed
260
-     * 
261
-     * @url GET /category/list/member
262
-     */
263
-    function getListCategoryMember($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
264
-        return $this->getList('member', $sortfield, $sortorder, $limit, $page);  
265
-    }
252
+	/**
253
+	 * Get member categories list <b>Warning: Deprecated</b>
254
+	 * 
255
+	 * @param string	$sortfield	Sort field
256
+	 * @param string	$sortorder	Sort order
257
+	 * @param int		$limit		Limit for list
258
+	 * @param int		$page		Page number
259
+	 * @return mixed
260
+	 * 
261
+	 * @url GET /category/list/member
262
+	 */
263
+	function getListCategoryMember($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
264
+		return $this->getList('member', $sortfield, $sortorder, $limit, $page);  
265
+	}
266 266
     
267
-    /**
268
-     * Get customer categories list <b>Warning: Deprecated</b>
269
-     * 
270
-     * @param string	$sortfield	Sort field
271
-     * @param string	$sortorder	Sort order
272
-     * @param int		$limit		Limit for list
273
-     * @param int		$page		Page number
274
-     * 
275
-     * @return mixed
276
-     * 
277
-     * @url GET /category/list/customer
278
-     */
279
-    function getListCategoryCustomer($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
280
-        return $this->getList('customer', $sortfield, $sortorder, $limit, $page);  
281
-    }
282
-    /**
283
-     * Get categories for a customer <b>Warning: Deprecated</b>
284
-     * 
285
-     * @param int		$cusid  Customer id filter
286
-     * @param string	$sortfield	Sort field
287
-     * @param string	$sortorder	Sort order
288
-     * @param int		$limit		Limit for list
289
-     * @param int		$page		Page number
290
-     * 
291
-     * @return mixed
292
-     * 
293
-     * @url GET /customer/{cusid}/categories
294
-     */
295
-    function getListCustomerCategories($cusid, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
296
-        return $this->getListForItem($sortfield, $sortorder, $limit, $page, 'customer', $cusid);  
297
-    }
267
+	/**
268
+	 * Get customer categories list <b>Warning: Deprecated</b>
269
+	 * 
270
+	 * @param string	$sortfield	Sort field
271
+	 * @param string	$sortorder	Sort order
272
+	 * @param int		$limit		Limit for list
273
+	 * @param int		$page		Page number
274
+	 * 
275
+	 * @return mixed
276
+	 * 
277
+	 * @url GET /category/list/customer
278
+	 */
279
+	function getListCategoryCustomer($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
280
+		return $this->getList('customer', $sortfield, $sortorder, $limit, $page);  
281
+	}
282
+	/**
283
+	 * Get categories for a customer <b>Warning: Deprecated</b>
284
+	 * 
285
+	 * @param int		$cusid  Customer id filter
286
+	 * @param string	$sortfield	Sort field
287
+	 * @param string	$sortorder	Sort order
288
+	 * @param int		$limit		Limit for list
289
+	 * @param int		$page		Page number
290
+	 * 
291
+	 * @return mixed
292
+	 * 
293
+	 * @url GET /customer/{cusid}/categories
294
+	 */
295
+	function getListCustomerCategories($cusid, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
296
+		return $this->getListForItem($sortfield, $sortorder, $limit, $page, 'customer', $cusid);  
297
+	}
298 298
 
299
-    /**
300
-     * Add category to customer <b>Warning: Deprecated</b>
301
-     * 
302
-     * @param int		$cusid	Id of customer
303
-     * @param int		$catid  Id of category
304
-     * 
305
-     * @return mixed
306
-     * 
307
-     * @url GET /customer/{cusid}/addCategory/{catid}
308
-     */
309
-    function addCustomerCategory($cusid,$catid) {
310
-      if(! DolibarrApiAccess::$user->rights->societe->creer) {
299
+	/**
300
+	 * Add category to customer <b>Warning: Deprecated</b>
301
+	 * 
302
+	 * @param int		$cusid	Id of customer
303
+	 * @param int		$catid  Id of category
304
+	 * 
305
+	 * @return mixed
306
+	 * 
307
+	 * @url GET /customer/{cusid}/addCategory/{catid}
308
+	 */
309
+	function addCustomerCategory($cusid,$catid) {
310
+	  if(! DolibarrApiAccess::$user->rights->societe->creer) {
311 311
 			  throw new RestException(401);
312
-      }
313
-      $customer = new Client($this->db);
314
-      $customer->fetch($cusid);
315
-      if( ! $customer ) {
316
-        throw new RestException(404, 'customer not found');
317
-      }
318
-      $result = $this->category->fetch($catid);
319
-      if( ! $result ) {
320
-        throw new RestException(404, 'category not found');
321
-      }
312
+	  }
313
+	  $customer = new Client($this->db);
314
+	  $customer->fetch($cusid);
315
+	  if( ! $customer ) {
316
+		throw new RestException(404, 'customer not found');
317
+	  }
318
+	  $result = $this->category->fetch($catid);
319
+	  if( ! $result ) {
320
+		throw new RestException(404, 'category not found');
321
+	  }
322 322
       
323
-      if( ! DolibarrApi::_checkAccessToResource('societe',$customer->id)) {
324
-        throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
325
-      }
326
-      if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
327
-        throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
328
-      }
329
-      $this->category->add_type($customer,'customer');
330
-      return $customer;
331
-    }
323
+	  if( ! DolibarrApi::_checkAccessToResource('societe',$customer->id)) {
324
+		throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
325
+	  }
326
+	  if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
327
+		throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
328
+	  }
329
+	  $this->category->add_type($customer,'customer');
330
+	  return $customer;
331
+	}
332 332
     
333
-    /**
334
-     * Get supplier categories list <b>Warning: Deprecated</b>
335
-     * 
336
-     * @param string	$sortfield	Sort field
337
-     * @param string	$sortorder	Sort order
338
-     * @param int		$limit		Limit for list
339
-     * @param int		$page		Page number
340
-     * 
341
-     * @return mixed
342
-     * 
343
-     * @url GET /category/list/supplier
344
-     */
345
-    function getListCategorySupplier($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
346
-        return $this->getList('supplier', $sortfield, $sortorder, $limit, $page);  
347
-    }
333
+	/**
334
+	 * Get supplier categories list <b>Warning: Deprecated</b>
335
+	 * 
336
+	 * @param string	$sortfield	Sort field
337
+	 * @param string	$sortorder	Sort order
338
+	 * @param int		$limit		Limit for list
339
+	 * @param int		$page		Page number
340
+	 * 
341
+	 * @return mixed
342
+	 * 
343
+	 * @url GET /category/list/supplier
344
+	 */
345
+	function getListCategorySupplier($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
346
+		return $this->getList('supplier', $sortfield, $sortorder, $limit, $page);  
347
+	}
348 348
     
349
-    /**
350
-     * Get product categories list <b>Warning: Deprecated</b>
351
-     * 
352
-     * @param string	$sortfield	Sort field
353
-     * @param string	$sortorder	Sort order
354
-     * @param int		$limit		Limit for list
355
-     * @param int		$page		Page number
356
-     * 
357
-     * @return mixed
358
-     * 
359
-     * @url GET /category/list/product
360
-     */
361
-    function getListCategoryProduct($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
362
-        return $this->getList('product', $sortfield, $sortorder, $limit, $page);  
363
-    }
349
+	/**
350
+	 * Get product categories list <b>Warning: Deprecated</b>
351
+	 * 
352
+	 * @param string	$sortfield	Sort field
353
+	 * @param string	$sortorder	Sort order
354
+	 * @param int		$limit		Limit for list
355
+	 * @param int		$page		Page number
356
+	 * 
357
+	 * @return mixed
358
+	 * 
359
+	 * @url GET /category/list/product
360
+	 */
361
+	function getListCategoryProduct($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
362
+		return $this->getList('product', $sortfield, $sortorder, $limit, $page);  
363
+	}
364 364
     
365
-    /**
366
-     * Get contact categories list <b>Warning: Deprecated</b>
367
-     * 
368
-     * @param string	$sortfield	Sort field
369
-     * @param string	$sortorder	Sort order
370
-     * @param int		$limit		Limit for list
371
-     * @param int		$page		Page number
372
-     * @return mixed
373
-     * 
374
-     * @url GET /category/list/contact
375
-     */
376
-    function getListCategoryContact($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
377
-        return $this->getList('contact', $sortfield, $sortorder, $limit, $page);  
378
-    }
365
+	/**
366
+	 * Get contact categories list <b>Warning: Deprecated</b>
367
+	 * 
368
+	 * @param string	$sortfield	Sort field
369
+	 * @param string	$sortorder	Sort order
370
+	 * @param int		$limit		Limit for list
371
+	 * @param int		$page		Page number
372
+	 * @return mixed
373
+	 * 
374
+	 * @url GET /category/list/contact
375
+	 */
376
+	function getListCategoryContact($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
377
+		return $this->getList('contact', $sortfield, $sortorder, $limit, $page);  
378
+	}
379 379
     
380
-    /**
381
-     * Create category object <b>Warning: Deprecated</b>
382
-     * 
383
-     * @param array $request_data   Request data
384
-     * @return int  ID of category
385
-     *
386
-     * @url	POST category/
387
-     */
388
-    function post($request_data = NULL)
389
-    {
390
-        if(! DolibarrApiAccess::$user->rights->categorie->creer) {
380
+	/**
381
+	 * Create category object <b>Warning: Deprecated</b>
382
+	 * 
383
+	 * @param array $request_data   Request data
384
+	 * @return int  ID of category
385
+	 *
386
+	 * @url	POST category/
387
+	 */
388
+	function post($request_data = NULL)
389
+	{
390
+		if(! DolibarrApiAccess::$user->rights->categorie->creer) {
391 391
 			throw new RestException(401);
392 392
 		}
393
-        // Check mandatory fields
394
-        $result = $this->_validate($request_data);
393
+		// Check mandatory fields
394
+		$result = $this->_validate($request_data);
395 395
         
396
-        foreach($request_data as $field => $value) {
397
-            $this->category->$field = $value;
398
-        }
399
-        if($this->category->create(DolibarrApiAccess::$user) < 0) {
400
-            throw new RestException(500, 'Error when create category : '.$this->category->error);
401
-        }
402
-        return $this->category->id;
403
-    }
396
+		foreach($request_data as $field => $value) {
397
+			$this->category->$field = $value;
398
+		}
399
+		if($this->category->create(DolibarrApiAccess::$user) < 0) {
400
+			throw new RestException(500, 'Error when create category : '.$this->category->error);
401
+		}
402
+		return $this->category->id;
403
+	}
404 404
 
405
-    /**
406
-     * Update category <b>Warning: Deprecated</b>
407
-     * 
408
-     * @param int   $id             Id of category to update
409
-     * @param array $request_data   Datas   
410
-     * @return int 
411
-     *
412
-     * @url	PUT category/{id}
413
-     */
414
-    function put($id, $request_data = NULL)
415
-    {
416
-        if(! DolibarrApiAccess::$user->rights->categorie->creer) {
405
+	/**
406
+	 * Update category <b>Warning: Deprecated</b>
407
+	 * 
408
+	 * @param int   $id             Id of category to update
409
+	 * @param array $request_data   Datas   
410
+	 * @return int 
411
+	 *
412
+	 * @url	PUT category/{id}
413
+	 */
414
+	function put($id, $request_data = NULL)
415
+	{
416
+		if(! DolibarrApiAccess::$user->rights->categorie->creer) {
417 417
 			throw new RestException(401);
418 418
 		}
419 419
         
420
-        $result = $this->category->fetch($id);
421
-        if( ! $result ) {
422
-            throw new RestException(404, 'category not found');
423
-        }
420
+		$result = $this->category->fetch($id);
421
+		if( ! $result ) {
422
+			throw new RestException(404, 'category not found');
423
+		}
424 424
 		
425 425
 		if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
426 426
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
427 427
 		}
428 428
 
429
-        foreach($request_data as $field => $value) {
430
-            if ($field == 'id') continue;
431
-            $this->category->$field = $value;
432
-        }
429
+		foreach($request_data as $field => $value) {
430
+			if ($field == 'id') continue;
431
+			$this->category->$field = $value;
432
+		}
433 433
         
434
-        if($this->category->update(DolibarrApiAccess::$user))
435
-            return $this->get ($id);
434
+		if($this->category->update(DolibarrApiAccess::$user))
435
+			return $this->get ($id);
436 436
         
437
-        return false;
438
-    }
437
+		return false;
438
+	}
439 439
     
440
-    /**
441
-     * Delete category <b>Warning: Deprecated</b>
442
-     *
443
-     * @param int $id   Category ID
444
-     * @return array
445
-     * 
446
-     * @url	DELETE category/{id}
447
-     */
448
-    function delete($id)
449
-    {
450
-        if(! DolibarrApiAccess::$user->rights->categorie->supprimer) {
440
+	/**
441
+	 * Delete category <b>Warning: Deprecated</b>
442
+	 *
443
+	 * @param int $id   Category ID
444
+	 * @return array
445
+	 * 
446
+	 * @url	DELETE category/{id}
447
+	 */
448
+	function delete($id)
449
+	{
450
+		if(! DolibarrApiAccess::$user->rights->categorie->supprimer) {
451 451
 			throw new RestException(401);
452 452
 		}
453
-        $result = $this->category->fetch($id);
454
-        if( ! $result ) {
455
-            throw new RestException(404, 'category not found');
456
-        }
453
+		$result = $this->category->fetch($id);
454
+		if( ! $result ) {
455
+			throw new RestException(404, 'category not found');
456
+		}
457 457
 		
458 458
 		if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
459 459
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
460 460
 		}
461 461
         
462
-        if (! $this->category->delete(DolibarrApiAccess::$user)) {
463
-            throw new RestException(401,'error when delete category');
464
-        }
462
+		if (! $this->category->delete(DolibarrApiAccess::$user)) {
463
+			throw new RestException(401,'error when delete category');
464
+		}
465 465
         
466
-        return array(
467
-            'success' => array(
468
-                'code' => 200,
469
-                'message' => 'Category deleted'
470
-            )
471
-        );
472
-    }
466
+		return array(
467
+			'success' => array(
468
+				'code' => 200,
469
+				'message' => 'Category deleted'
470
+			)
471
+		);
472
+	}
473 473
     
474
-    /**
475
-     * Validate fields before create or update object
476
-     * 
477
-     * @param array|null    $data   Data to validate
478
-     * @return array
479
-     * 
480
-     * @throws RestException
481
-     */
482
-    function _validate($data)
483
-    {
484
-        $category = array();
485
-        foreach (CategoryApi::$FIELDS as $field) {
486
-            if (!isset($data[$field]))
487
-                throw new RestException(400, "$field field missing");
488
-            $category[$field] = $data[$field];
489
-        }
490
-        return $category;
491
-    }
474
+	/**
475
+	 * Validate fields before create or update object
476
+	 * 
477
+	 * @param array|null    $data   Data to validate
478
+	 * @return array
479
+	 * 
480
+	 * @throws RestException
481
+	 */
482
+	function _validate($data)
483
+	{
484
+		$category = array();
485
+		foreach (CategoryApi::$FIELDS as $field) {
486
+			if (!isset($data[$field]))
487
+				throw new RestException(400, "$field field missing");
488
+			$category[$field] = $data[$field];
489
+		}
490
+		return $category;
491
+	}
492 492
 }
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -80,16 +80,16 @@  discard block
 block discarded – undo
80 80
      */
81 81
     function get($id)
82 82
     {		
83
-		if(! DolibarrApiAccess::$user->rights->categorie->lire) {
83
+		if (!DolibarrApiAccess::$user->rights->categorie->lire) {
84 84
 			throw new RestException(401);
85 85
 		}
86 86
 			
87 87
         $result = $this->category->fetch($id);
88
-        if( ! $result ) {
88
+        if (!$result) {
89 89
             throw new RestException(404, 'category not found');
90 90
         }
91 91
 		
92
-		if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
92
+		if (!DolibarrApi::_checkAccessToResource('category', $this->category->id)) {
93 93
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
94 94
 		}
95 95
 
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
      *
111 111
      * @url	GET /category/list
112 112
      */
113
-    function getList($type='product', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
113
+    function getList($type = 'product', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
114 114
         global $db, $conf;
115 115
         
116 116
         $obj_ret = array();
117 117
         
118
-         if(! DolibarrApiAccess::$user->rights->categorie->lire) {
118
+         if (!DolibarrApiAccess::$user->rights->categorie->lire) {
119 119
 			throw new RestException(401);
120 120
 		}
121 121
         
122 122
         $sql = "SELECT s.rowid";
123
-        $sql.= " FROM ".MAIN_DB_PREFIX."categorie as s";
124
-        $sql.= ' WHERE s.entity IN ('.getEntity('category').')';
125
-        $sql.= ' AND s.type='.array_search($type,CategoryApi::$TYPES);
123
+        $sql .= " FROM ".MAIN_DB_PREFIX."categorie as s";
124
+        $sql .= ' WHERE s.entity IN ('.getEntity('category').')';
125
+        $sql .= ' AND s.type='.array_search($type, CategoryApi::$TYPES);
126 126
 
127 127
         $nbtotalofrecords = '';
128 128
         if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
@@ -131,28 +131,28 @@  discard block
 block discarded – undo
131 131
             $nbtotalofrecords = $db->num_rows($result);
132 132
         }
133 133
 
134
-        $sql.= $db->order($sortfield, $sortorder);
135
-        if ($limit)	{
134
+        $sql .= $db->order($sortfield, $sortorder);
135
+        if ($limit) {
136 136
             if ($page < 0)
137 137
             {
138 138
                 $page = 0;
139 139
             }
140 140
             $offset = $limit * $page;
141 141
 
142
-            $sql.= $db->plimit($limit + 1, $offset);
142
+            $sql .= $db->plimit($limit + 1, $offset);
143 143
         }
144 144
 
145 145
         $result = $db->query($sql);
146 146
         if ($result)
147 147
         {
148
-        	$i=0;
148
+        	$i = 0;
149 149
             $num = $db->num_rows($result);
150 150
             $min = min($num, ($limit <= 0 ? $num : $limit));
151 151
             while ($i < $min)
152 152
             {
153 153
                 $obj = $db->fetch_object($result);
154 154
                 $category_static = new Categorie($db);
155
-                if($category_static->fetch($obj->rowid)) {
155
+                if ($category_static->fetch($obj->rowid)) {
156 156
                     $obj_ret[] = $this->_cleanObjectDatas($category_static);
157 157
                 }
158 158
                 $i++;
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
         else {
162 162
             throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
163 163
         }
164
-        if( ! count($obj_ret)) {
164
+        if (!count($obj_ret)) {
165 165
             throw new RestException(404, 'No category found');
166 166
         }
167 167
 		return $obj_ret;
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
      *
182 182
      * @url	GET /product/{item}/categories
183 183
      */
184
-    function getListForItem($type='product', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $item = 0) {
184
+    function getListForItem($type = 'product', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $item = 0) {
185 185
         global $db, $conf;
186 186
         
187 187
         $obj_ret = array();
188 188
         
189
-         if(! DolibarrApiAccess::$user->rights->categorie->lire) {
189
+         if (!DolibarrApiAccess::$user->rights->categorie->lire) {
190 190
 			    throw new RestException(401);
191 191
          }
192 192
         //if ($type == "") {
@@ -194,17 +194,17 @@  discard block
 block discarded – undo
194 194
         //}
195 195
         $sub_type = $type;
196 196
         $subcol_name = "fk_".$type;
197
-        if ($type=="customer" || $type=="supplier") {
198
-          $sub_type="societe";
199
-          $subcol_name="fk_soc";
197
+        if ($type == "customer" || $type == "supplier") {
198
+          $sub_type = "societe";
199
+          $subcol_name = "fk_soc";
200 200
         }
201 201
         $sql = "SELECT s.rowid";
202
-        $sql.= " FROM ".MAIN_DB_PREFIX."categorie as s";
203
-        $sql.= " , ".MAIN_DB_PREFIX."categorie_".$sub_type." as sub ";
204
-        $sql.= ' WHERE s.entity IN ('.getEntity('category').')';
205
-        $sql.= ' AND s.type='.array_search($type,CategoryApi::$TYPES);
206
-        $sql.= ' AND s.rowid = sub.fk_categorie';
207
-        $sql.= ' AND sub.'.$subcol_name.' = '.$item;
202
+        $sql .= " FROM ".MAIN_DB_PREFIX."categorie as s";
203
+        $sql .= " , ".MAIN_DB_PREFIX."categorie_".$sub_type." as sub ";
204
+        $sql .= ' WHERE s.entity IN ('.getEntity('category').')';
205
+        $sql .= ' AND s.type='.array_search($type, CategoryApi::$TYPES);
206
+        $sql .= ' AND s.rowid = sub.fk_categorie';
207
+        $sql .= ' AND sub.'.$subcol_name.' = '.$item;
208 208
 
209 209
         $nbtotalofrecords = '';
210 210
         if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
@@ -213,28 +213,28 @@  discard block
 block discarded – undo
213 213
             $nbtotalofrecords = $db->num_rows($result);
214 214
         }
215 215
 
216
-        $sql.= $db->order($sortfield, $sortorder);
217
-        if ($limit)	{
216
+        $sql .= $db->order($sortfield, $sortorder);
217
+        if ($limit) {
218 218
             if ($page < 0)
219 219
             {
220 220
                 $page = 0;
221 221
             }
222 222
             $offset = $limit * $page;
223 223
 
224
-            $sql.= $db->plimit($limit + 1, $offset);
224
+            $sql .= $db->plimit($limit + 1, $offset);
225 225
         }
226 226
 
227 227
         $result = $db->query($sql);
228 228
         if ($result)
229 229
         {
230
-        	$i=0;
230
+        	$i = 0;
231 231
             $num = $db->num_rows($result);
232 232
             $min = min($num, ($limit <= 0 ? $num : $limit));
233 233
             while ($i < $min)
234 234
             {
235 235
                 $obj = $db->fetch_object($result);
236 236
                 $category_static = new Categorie($db);
237
-                if($category_static->fetch($obj->rowid)) {
237
+                if ($category_static->fetch($obj->rowid)) {
238 238
                     $obj_ret[] = $this->_cleanObjectDatas($category_static);
239 239
                 }
240 240
                 $i++;
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
         else {
244 244
             throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
245 245
         }
246
-        if( ! count($obj_ret)) {
246
+        if (!count($obj_ret)) {
247 247
             throw new RestException(404, 'No category found');
248 248
         }
249 249
 		return $obj_ret;
@@ -306,27 +306,27 @@  discard block
 block discarded – undo
306 306
      * 
307 307
      * @url GET /customer/{cusid}/addCategory/{catid}
308 308
      */
309
-    function addCustomerCategory($cusid,$catid) {
310
-      if(! DolibarrApiAccess::$user->rights->societe->creer) {
309
+    function addCustomerCategory($cusid, $catid) {
310
+      if (!DolibarrApiAccess::$user->rights->societe->creer) {
311 311
 			  throw new RestException(401);
312 312
       }
313 313
       $customer = new Client($this->db);
314 314
       $customer->fetch($cusid);
315
-      if( ! $customer ) {
315
+      if (!$customer) {
316 316
         throw new RestException(404, 'customer not found');
317 317
       }
318 318
       $result = $this->category->fetch($catid);
319
-      if( ! $result ) {
319
+      if (!$result) {
320 320
         throw new RestException(404, 'category not found');
321 321
       }
322 322
       
323
-      if( ! DolibarrApi::_checkAccessToResource('societe',$customer->id)) {
323
+      if (!DolibarrApi::_checkAccessToResource('societe', $customer->id)) {
324 324
         throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
325 325
       }
326
-      if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
326
+      if (!DolibarrApi::_checkAccessToResource('category', $this->category->id)) {
327 327
         throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
328 328
       }
329
-      $this->category->add_type($customer,'customer');
329
+      $this->category->add_type($customer, 'customer');
330 330
       return $customer;
331 331
     }
332 332
     
@@ -387,16 +387,16 @@  discard block
 block discarded – undo
387 387
      */
388 388
     function post($request_data = NULL)
389 389
     {
390
-        if(! DolibarrApiAccess::$user->rights->categorie->creer) {
390
+        if (!DolibarrApiAccess::$user->rights->categorie->creer) {
391 391
 			throw new RestException(401);
392 392
 		}
393 393
         // Check mandatory fields
394 394
         $result = $this->_validate($request_data);
395 395
         
396
-        foreach($request_data as $field => $value) {
396
+        foreach ($request_data as $field => $value) {
397 397
             $this->category->$field = $value;
398 398
         }
399
-        if($this->category->create(DolibarrApiAccess::$user) < 0) {
399
+        if ($this->category->create(DolibarrApiAccess::$user) < 0) {
400 400
             throw new RestException(500, 'Error when create category : '.$this->category->error);
401 401
         }
402 402
         return $this->category->id;
@@ -413,26 +413,26 @@  discard block
 block discarded – undo
413 413
      */
414 414
     function put($id, $request_data = NULL)
415 415
     {
416
-        if(! DolibarrApiAccess::$user->rights->categorie->creer) {
416
+        if (!DolibarrApiAccess::$user->rights->categorie->creer) {
417 417
 			throw new RestException(401);
418 418
 		}
419 419
         
420 420
         $result = $this->category->fetch($id);
421
-        if( ! $result ) {
421
+        if (!$result) {
422 422
             throw new RestException(404, 'category not found');
423 423
         }
424 424
 		
425
-		if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
425
+		if (!DolibarrApi::_checkAccessToResource('category', $this->category->id)) {
426 426
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
427 427
 		}
428 428
 
429
-        foreach($request_data as $field => $value) {
429
+        foreach ($request_data as $field => $value) {
430 430
             if ($field == 'id') continue;
431 431
             $this->category->$field = $value;
432 432
         }
433 433
         
434
-        if($this->category->update(DolibarrApiAccess::$user))
435
-            return $this->get ($id);
434
+        if ($this->category->update(DolibarrApiAccess::$user))
435
+            return $this->get($id);
436 436
         
437 437
         return false;
438 438
     }
@@ -447,20 +447,20 @@  discard block
 block discarded – undo
447 447
      */
448 448
     function delete($id)
449 449
     {
450
-        if(! DolibarrApiAccess::$user->rights->categorie->supprimer) {
450
+        if (!DolibarrApiAccess::$user->rights->categorie->supprimer) {
451 451
 			throw new RestException(401);
452 452
 		}
453 453
         $result = $this->category->fetch($id);
454
-        if( ! $result ) {
454
+        if (!$result) {
455 455
             throw new RestException(404, 'category not found');
456 456
         }
457 457
 		
458
-		if( ! DolibarrApi::_checkAccessToResource('category',$this->category->id)) {
458
+		if (!DolibarrApi::_checkAccessToResource('category', $this->category->id)) {
459 459
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
460 460
 		}
461 461
         
462
-        if (! $this->category->delete(DolibarrApiAccess::$user)) {
463
-            throw new RestException(401,'error when delete category');
462
+        if (!$this->category->delete(DolibarrApiAccess::$user)) {
463
+            throw new RestException(401, 'error when delete category');
464 464
         }
465 465
         
466 466
         return array(
Please login to merge, or discard this patch.
Braces   +11 added lines, -9 removed lines patch added patch discarded remove patch
@@ -157,8 +157,7 @@  discard block
 block discarded – undo
157 157
                 }
158 158
                 $i++;
159 159
             }
160
-        }
161
-        else {
160
+        } else {
162 161
             throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
163 162
         }
164 163
         if( ! count($obj_ret)) {
@@ -239,8 +238,7 @@  discard block
 block discarded – undo
239 238
                 }
240 239
                 $i++;
241 240
             }
242
-        }
243
-        else {
241
+        } else {
244 242
             throw new RestException(503, 'Error when retrieve category list : '.$db->lasterror());
245 243
         }
246 244
         if( ! count($obj_ret)) {
@@ -427,12 +425,15 @@  discard block
 block discarded – undo
427 425
 		}
428 426
 
429 427
         foreach($request_data as $field => $value) {
430
-            if ($field == 'id') continue;
428
+            if ($field == 'id') {
429
+            	continue;
430
+            }
431 431
             $this->category->$field = $value;
432 432
         }
433 433
         
434
-        if($this->category->update(DolibarrApiAccess::$user))
435
-            return $this->get ($id);
434
+        if($this->category->update(DolibarrApiAccess::$user)) {
435
+                    return $this->get ($id);
436
+        }
436 437
         
437 438
         return false;
438 439
     }
@@ -483,8 +484,9 @@  discard block
 block discarded – undo
483 484
     {
484 485
         $category = array();
485 486
         foreach (CategoryApi::$FIELDS as $field) {
486
-            if (!isset($data[$field]))
487
-                throw new RestException(400, "$field field missing");
487
+            if (!isset($data[$field])) {
488
+                            throw new RestException(400, "$field field missing");
489
+            }
488 490
             $category[$field] = $data[$field];
489 491
         }
490 492
         return $category;
Please login to merge, or discard this patch.
htdocs/projet/ganttchart.inc.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@
 block discarded – undo
132 132
  * Add a gant chart line
133 133
  *
134 134
  * @param 	string	$tarr					tarr
135
- * @param	array	$task					Array with properties of one task
135
+ * @param	string	$task					Array with properties of one task
136 136
  * @param 	Project	$project_dependencies	Project object
137 137
  * @param 	int		$level					Level
138 138
  * @param 	int		$project_id				Id of project
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -140,43 +140,43 @@  discard block
 block discarded – undo
140 140
  */
141 141
 function constructGanttLine($tarr,$task,$project_dependencies,$level=0,$project_id=null)
142 142
 {
143
-    global $dateformatinput2;
144
-
145
-    $start_date = $task["task_start_date"];
146
-    $end_date = $task["task_end_date"];
147
-    if (!$end_date) $end_date = $start_date;
148
-    $start_date = dol_print_date($start_date, $dateformatinput2);
149
-    $end_date = dol_print_date($end_date, $dateformatinput2);
150
-    // Resources
151
-    $resources = $task["task_resources"];
152
-    // Define depend (ex: "", "4,13", ...)
153
-    $depend = '';
154
-    $count = 0;
155
-    foreach ($project_dependencies as $value) {
156
-        // Not yet used project_dependencies = array(array(0=>idtask,1=>idtasktofinishfisrt))
157
-        if ($value[0] == $task['task_id']) {
158
-            $depend.=($count>0?",":"").$value[1];
159
-            $count ++;
160
-        }
161
-    }
143
+	global $dateformatinput2;
144
+
145
+	$start_date = $task["task_start_date"];
146
+	$end_date = $task["task_end_date"];
147
+	if (!$end_date) $end_date = $start_date;
148
+	$start_date = dol_print_date($start_date, $dateformatinput2);
149
+	$end_date = dol_print_date($end_date, $dateformatinput2);
150
+	// Resources
151
+	$resources = $task["task_resources"];
152
+	// Define depend (ex: "", "4,13", ...)
153
+	$depend = '';
154
+	$count = 0;
155
+	foreach ($project_dependencies as $value) {
156
+		// Not yet used project_dependencies = array(array(0=>idtask,1=>idtasktofinishfisrt))
157
+		if ($value[0] == $task['task_id']) {
158
+			$depend.=($count>0?",":"").$value[1];
159
+			$count ++;
160
+		}
161
+	}
162 162
    // $depend .= "\"";
163
-    // Define parent
164
-    if ($project_id && $level < 0)
165
-    $parent = 'p'.$project_id;
166
-    else
167
-    $parent = $task["task_parent"];
168
-    // Define percent
169
-    $percent = $task['task_percent_complete']?$task['task_percent_complete']:0;
170
-    // Link (more information)
171
-    $link=DOL_URL_ROOT.'/projet/tasks/contact.php?withproject=1&id='.$task["task_id"];
172
-
173
-    // Name
174
-    $name=$task['task_name'];
175
-    /*for($i=0; $i < $level; $i++) {
163
+	// Define parent
164
+	if ($project_id && $level < 0)
165
+	$parent = 'p'.$project_id;
166
+	else
167
+	$parent = $task["task_parent"];
168
+	// Define percent
169
+	$percent = $task['task_percent_complete']?$task['task_percent_complete']:0;
170
+	// Link (more information)
171
+	$link=DOL_URL_ROOT.'/projet/tasks/contact.php?withproject=1&id='.$task["task_id"];
172
+
173
+	// Name
174
+	$name=$task['task_name'];
175
+	/*for($i=0; $i < $level; $i++) {
176 176
         $name=' - '.$name;
177 177
     }*/
178
-    // Add line to gantt
179
-    /*
178
+	// Add line to gantt
179
+	/*
180 180
 	g.AddTaskItem(new JSGantt.TaskItem(1, 'Define Chart API','',          '',          'ggroupblack','', 0, 'Brian', 0,  1,0,1,'','','Some Notes text',g));
181 181
 	g.AddTaskItem(new JSGantt.TaskItem(11,'Chart Object',    '2014-02-20','2014-02-20','gmilestone', '', 1, 'Shlomy',100,0,1,1,'','','',g));
182 182
 	</pre>
@@ -201,13 +201,13 @@  discard block
 block discarded – undo
201 201
 	<dt>pGantt</dt><dd>(required) javascript JSGantt.GanttChart object from which to take settings.  Defaults to &quot;g&quot; for backwards compatibility</dd>
202 202
     */
203 203
 
204
-    //$note="";
204
+	//$note="";
205 205
 
206
-    $s = "\n// Add taks id=".$task["task_id"]." level = ".$level."\n";
206
+	$s = "\n// Add taks id=".$task["task_id"]." level = ".$level."\n";
207 207
    // $s.= "g.AddTaskItem(new JSGantt.TaskItem(".$task['task_id'].",'".dol_escape_js($name)."','".$start_date."', '".$end_date."', '".$task['task_color']."', '".$link."', ".$task['task_milestone'].", '".$resources."', ".($percent >= 0 ? $percent : 0).", ".($task["task_is_group"]>0?1:0).", '".$parent."', 1, '".($depend?$depend:"")."', '".$note."'));";
208
-    // For JSGanttImproved
209
-    $s.= "g.AddTaskItem(new JSGantt.TaskItem(".$task['task_id'].",'".dol_escape_js(trim($name))."','".$start_date."', '".$end_date."', '".$task['task_css']."', '".$link."', ".$task['task_milestone'].", '".$resources."', ".($percent >= 0 ? $percent : 0).", ".($task["task_is_group"]).", '".$parent."', 1, '".($depend?$depend:$parent."SS")."', '".($percent >= 0 ? $percent.'%' : '0%')."','".dol_escape_js($task['note'])."'));";
210
-    echo $s;
208
+	// For JSGanttImproved
209
+	$s.= "g.AddTaskItem(new JSGantt.TaskItem(".$task['task_id'].",'".dol_escape_js(trim($name))."','".$start_date."', '".$end_date."', '".$task['task_css']."', '".$link."', ".$task['task_milestone'].", '".$resources."', ".($percent >= 0 ? $percent : 0).", ".($task["task_is_group"]).", '".$parent."', 1, '".($depend?$depend:$parent."SS")."', '".($percent >= 0 ? $percent.'%' : '0%')."','".dol_escape_js($task['note'])."'));";
210
+	echo $s;
211 211
 
212 212
 
213 213
 }
@@ -223,14 +223,14 @@  discard block
 block discarded – undo
223 223
  */
224 224
 function findChildGanttLine($tarr,$parent,$project_dependencies,$level)
225 225
 {
226
-    $n=count($tarr);
227
-    for ($x=0; $x < $n; $x++)
228
-    {
229
-        if($tarr[$x]["task_parent"] == $parent && $tarr[$x]["task_parent"] != $tarr[$x]["task_id"])
230
-        {
231
-            constructGanttLine($tarr,$tarr[$x],$project_dependencies,$level,null);
232
-            findChildGanttLine($tarr,$tarr[$x]["task_id"],$project_dependencies,$level+1);
233
-        }
234
-    }
226
+	$n=count($tarr);
227
+	for ($x=0; $x < $n; $x++)
228
+	{
229
+		if($tarr[$x]["task_parent"] == $parent && $tarr[$x]["task_parent"] != $tarr[$x]["task_id"])
230
+		{
231
+			constructGanttLine($tarr,$tarr[$x],$project_dependencies,$level,null);
232
+			findChildGanttLine($tarr,$tarr[$x]["task_id"],$project_dependencies,$level+1);
233
+		}
234
+	}
235 235
 }
236 236
 
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 	/* g.setShowTaskInfoLink(1) */
105 105
 
106 106
 	<?php
107
-	$level=0;
107
+	$level = 0;
108 108
 	$tnums = count($tasks);
109
-	for ($tcursor=0; $tcursor < $tnums; $tcursor++) {
109
+	for ($tcursor = 0; $tcursor < $tnums; $tcursor++) {
110 110
 		$t = $tasks[$tcursor];
111 111
 		if ($t["task_parent"] == 0) {
112
-			constructGanttLine($tasks,$t,$project_dependencies,$level,$project_id);
113
-			findChildGanttLine($tasks,$t["task_id"],$project_dependencies,$level+1);
112
+			constructGanttLine($tasks, $t, $project_dependencies, $level, $project_id);
113
+			findChildGanttLine($tasks, $t["task_id"], $project_dependencies, $level + 1);
114 114
 		}
115 115
 	}
116 116
 	?>
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
  * @param 	int		$project_id				Id of project
139 139
  * @return	void
140 140
  */
141
-function constructGanttLine($tarr,$task,$project_dependencies,$level=0,$project_id=null)
141
+function constructGanttLine($tarr, $task, $project_dependencies, $level = 0, $project_id = null)
142 142
 {
143 143
     global $dateformatinput2;
144 144
 
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
     foreach ($project_dependencies as $value) {
156 156
         // Not yet used project_dependencies = array(array(0=>idtask,1=>idtasktofinishfisrt))
157 157
         if ($value[0] == $task['task_id']) {
158
-            $depend.=($count>0?",":"").$value[1];
159
-            $count ++;
158
+            $depend .= ($count > 0 ? "," : "").$value[1];
159
+            $count++;
160 160
         }
161 161
     }
162 162
    // $depend .= "\"";
@@ -166,12 +166,12 @@  discard block
 block discarded – undo
166 166
     else
167 167
     $parent = $task["task_parent"];
168 168
     // Define percent
169
-    $percent = $task['task_percent_complete']?$task['task_percent_complete']:0;
169
+    $percent = $task['task_percent_complete'] ? $task['task_percent_complete'] : 0;
170 170
     // Link (more information)
171
-    $link=DOL_URL_ROOT.'/projet/tasks/contact.php?withproject=1&id='.$task["task_id"];
171
+    $link = DOL_URL_ROOT.'/projet/tasks/contact.php?withproject=1&id='.$task["task_id"];
172 172
 
173 173
     // Name
174
-    $name=$task['task_name'];
174
+    $name = $task['task_name'];
175 175
     /*for($i=0; $i < $level; $i++) {
176 176
         $name=' - '.$name;
177 177
     }*/
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
     $s = "\n// Add taks id=".$task["task_id"]." level = ".$level."\n";
207 207
    // $s.= "g.AddTaskItem(new JSGantt.TaskItem(".$task['task_id'].",'".dol_escape_js($name)."','".$start_date."', '".$end_date."', '".$task['task_color']."', '".$link."', ".$task['task_milestone'].", '".$resources."', ".($percent >= 0 ? $percent : 0).", ".($task["task_is_group"]>0?1:0).", '".$parent."', 1, '".($depend?$depend:"")."', '".$note."'));";
208 208
     // For JSGanttImproved
209
-    $s.= "g.AddTaskItem(new JSGantt.TaskItem(".$task['task_id'].",'".dol_escape_js(trim($name))."','".$start_date."', '".$end_date."', '".$task['task_css']."', '".$link."', ".$task['task_milestone'].", '".$resources."', ".($percent >= 0 ? $percent : 0).", ".($task["task_is_group"]).", '".$parent."', 1, '".($depend?$depend:$parent."SS")."', '".($percent >= 0 ? $percent.'%' : '0%')."','".dol_escape_js($task['note'])."'));";
209
+    $s .= "g.AddTaskItem(new JSGantt.TaskItem(".$task['task_id'].",'".dol_escape_js(trim($name))."','".$start_date."', '".$end_date."', '".$task['task_css']."', '".$link."', ".$task['task_milestone'].", '".$resources."', ".($percent >= 0 ? $percent : 0).", ".($task["task_is_group"]).", '".$parent."', 1, '".($depend ? $depend : $parent."SS")."', '".($percent >= 0 ? $percent.'%' : '0%')."','".dol_escape_js($task['note'])."'));";
210 210
     echo $s;
211 211
 
212 212
 
@@ -221,15 +221,15 @@  discard block
 block discarded – undo
221 221
  * @param 	int		$level					Level
222 222
  * @return	void
223 223
  */
224
-function findChildGanttLine($tarr,$parent,$project_dependencies,$level)
224
+function findChildGanttLine($tarr, $parent, $project_dependencies, $level)
225 225
 {
226
-    $n=count($tarr);
227
-    for ($x=0; $x < $n; $x++)
226
+    $n = count($tarr);
227
+    for ($x = 0; $x < $n; $x++)
228 228
     {
229
-        if($tarr[$x]["task_parent"] == $parent && $tarr[$x]["task_parent"] != $tarr[$x]["task_id"])
229
+        if ($tarr[$x]["task_parent"] == $parent && $tarr[$x]["task_parent"] != $tarr[$x]["task_id"])
230 230
         {
231
-            constructGanttLine($tarr,$tarr[$x],$project_dependencies,$level,null);
232
-            findChildGanttLine($tarr,$tarr[$x]["task_id"],$project_dependencies,$level+1);
231
+            constructGanttLine($tarr, $tarr[$x], $project_dependencies, $level, null);
232
+            findChildGanttLine($tarr, $tarr[$x]["task_id"], $project_dependencies, $level + 1);
233 233
         }
234 234
     }
235 235
 }
Please login to merge, or discard this patch.
Braces   +8 added lines, -5 removed lines patch added patch discarded remove patch
@@ -144,7 +144,9 @@  discard block
 block discarded – undo
144 144
 
145 145
     $start_date = $task["task_start_date"];
146 146
     $end_date = $task["task_end_date"];
147
-    if (!$end_date) $end_date = $start_date;
147
+    if (!$end_date) {
148
+    	$end_date = $start_date;
149
+    }
148 150
     $start_date = dol_print_date($start_date, $dateformatinput2);
149 151
     $end_date = dol_print_date($end_date, $dateformatinput2);
150 152
     // Resources
@@ -161,10 +163,11 @@  discard block
 block discarded – undo
161 163
     }
162 164
    // $depend .= "\"";
163 165
     // Define parent
164
-    if ($project_id && $level < 0)
165
-    $parent = 'p'.$project_id;
166
-    else
167
-    $parent = $task["task_parent"];
166
+    if ($project_id && $level < 0) {
167
+        $parent = 'p'.$project_id;
168
+    } else {
169
+        $parent = $task["task_parent"];
170
+    }
168 171
     // Define percent
169 172
     $percent = $task['task_percent_complete']?$task['task_percent_complete']:0;
170 173
     // Link (more information)
Please login to merge, or discard this patch.
htdocs/contact/class/contact.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -562,7 +562,7 @@
 block discarded – undo
562 562
 	 *  Load object contact
563 563
 	 *
564 564
 	 *  @param      int		$id          id du contact
565
-	 *  @param      User	$user        Utilisateur (abonnes aux alertes) qui veut les alertes de ce contact
565
+	 *  @param      integer	$user        Utilisateur (abonnes aux alertes) qui veut les alertes de ce contact
566 566
      *  @param      string  $ref_ext     External reference, not given by Dolibarr
567 567
 	 *  @return     int     		     -1 if KO, 0 if OK but not found, 1 if OK
568 568
 	 */
Please login to merge, or discard this patch.
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	public $state_code;		    // Code of department
67 67
 	public $state;			        // Label of department
68 68
 
69
-    	public $poste;                 // Position
69
+		public $poste;                 // Position
70 70
 
71 71
 	public $socid;					// fk_soc
72 72
 	public $statut;				// 0=inactif, 1=actif
@@ -75,17 +75,17 @@  discard block
 block discarded – undo
75 75
 	public $email;
76 76
 	public $skype;
77 77
 	public $photo;
78
-    	public $jabberid;
78
+		public $jabberid;
79 79
 	public $phone_pro;
80 80
 	public $phone_perso;
81 81
 	public $phone_mobile;
82
-    	public $fax;
82
+		public $fax;
83 83
 
84
-    	public $priv;
84
+		public $priv;
85 85
 
86 86
 	public $birthday;
87 87
 	public $default_lang;
88
-    	public $no_email;				// 1=Don't send e-mail to this contact, 0=do
88
+		public $no_email;				// 1=Don't send e-mail to this contact, 0=do
89 89
 
90 90
 	public $ref_facturation;       // Reference number of invoice for which it is contact
91 91
 	public $ref_contrat;           // Nb de reference contrat pour lequel il est contact
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
 		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
126 126
 		if (!$user->rights->societe->client->voir && !$user->societe_id)
127 127
 		{
128
-		    $sql.= ", ".MAIN_DB_PREFIX."societe as s";
129
-		    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
128
+			$sql.= ", ".MAIN_DB_PREFIX."societe as s";
129
+			$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
130 130
 			$sql.= " WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
131 131
 			$clause = "AND";
132 132
 		}
133 133
 		$sql.= ' '.$clause.' sp.entity IN ('.getEntity($this->element, 1).')';
134 134
 		$sql.= " AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat=".$user->id."))";
135
-        if ($user->societe_id > 0) $sql.=" AND sp.fk_soc = ".$user->societe_id;
135
+		if ($user->societe_id > 0) $sql.=" AND sp.fk_soc = ".$user->societe_id;
136 136
 
137 137
 		$resql=$this->db->query($sql);
138 138
 		if ($resql)
@@ -169,19 +169,19 @@  discard block
 block discarded – undo
169 169
 
170 170
 		// Clean parameters
171 171
 		$this->lastname=$this->lastname?trim($this->lastname):trim($this->name);
172
-        $this->firstname=trim($this->firstname);
173
-        if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords($this->lastname);
174
-        if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords($this->firstname);
175
-        if (empty($this->socid)) $this->socid = 0;
172
+		$this->firstname=trim($this->firstname);
173
+		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords($this->lastname);
174
+		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords($this->firstname);
175
+		if (empty($this->socid)) $this->socid = 0;
176 176
 		if (empty($this->priv)) $this->priv = 0;
177 177
 		if (empty($this->statut)) $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request
178 178
 
179 179
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (";
180 180
 		$sql.= " datec";
181 181
 		$sql.= ", fk_soc";
182
-        $sql.= ", lastname";
183
-        $sql.= ", firstname";
184
-        $sql.= ", fk_user_creat";
182
+		$sql.= ", lastname";
183
+		$sql.= ", firstname";
184
+		$sql.= ", fk_user_creat";
185 185
 		$sql.= ", priv";
186 186
 		$sql.= ", statut";
187 187
 		$sql.= ", canvas";
@@ -193,14 +193,14 @@  discard block
 block discarded – undo
193 193
 		if ($this->socid > 0) $sql.= " ".$this->socid.",";
194 194
 		else $sql.= "null,";
195 195
 		$sql.= "'".$this->db->escape($this->lastname)."',";
196
-        $sql.= "'".$this->db->escape($this->firstname)."',";
196
+		$sql.= "'".$this->db->escape($this->firstname)."',";
197 197
 		$sql.= " ".($user->id > 0 ? "'".$user->id."'":"null").",";
198 198
 		$sql.= " ".$this->priv.",";
199 199
 		$sql.= " ".$this->statut.",";
200
-        $sql.= " ".(! empty($this->canvas)?"'".$this->db->escape($this->canvas)."'":"null").",";
201
-        $sql.= " ".$conf->entity.",";
202
-        $sql.= "'".$this->db->escape($this->ref_ext)."',";
203
-        $sql.= " ".(! empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
200
+		$sql.= " ".(! empty($this->canvas)?"'".$this->db->escape($this->canvas)."'":"null").",";
201
+		$sql.= " ".$conf->entity.",";
202
+		$sql.= "'".$this->db->escape($this->ref_ext)."',";
203
+		$sql.= " ".(! empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
204 204
 		$sql.= ")";
205 205
 
206 206
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
@@ -211,43 +211,43 @@  discard block
 block discarded – undo
211 211
 
212 212
 			if (! $error)
213 213
 			{
214
-                $result=$this->update($this->id, $user, 1, 'add');
215
-                if ($result < 0)
216
-                {
217
-                    $error++;
218
-				    $this->error=$this->db->lasterror();
219
-                }
214
+				$result=$this->update($this->id, $user, 1, 'add');
215
+				if ($result < 0)
216
+				{
217
+					$error++;
218
+					$this->error=$this->db->lasterror();
219
+				}
220 220
 			}
221 221
 
222 222
 			if (! $error)
223
-            {
224
-                $result=$this->update_perso($this->id, $user, 1);   // TODO Remove function update_perso, should be same than update
225
-                if ($result < 0)
226
-                {
227
-                    $error++;
228
-                    $this->error=$this->db->lasterror();
229
-                }
230
-            }
223
+			{
224
+				$result=$this->update_perso($this->id, $user, 1);   // TODO Remove function update_perso, should be same than update
225
+				if ($result < 0)
226
+				{
227
+					$error++;
228
+					$this->error=$this->db->lasterror();
229
+				}
230
+			}
231
+
232
+			if (! $error)
233
+			{
234
+				// Call trigger
235
+				$result=$this->call_trigger('CONTACT_CREATE',$user);
236
+				if ($result < 0) { $error++; }
237
+				// End call triggers
238
+			}
231 239
 
232 240
 			if (! $error)
233
-            {
234
-                // Call trigger
235
-                $result=$this->call_trigger('CONTACT_CREATE',$user);
236
-                if ($result < 0) { $error++; }
237
-                // End call triggers
238
-            }
239
-
240
-            if (! $error)
241
-            {
242
-                $this->db->commit();
243
-                return $this->id;
244
-            }
245
-            else
246
-            {
247
-                $this->db->rollback();
248
-                dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
249
-                return -2;
250
-            }
241
+			{
242
+				$this->db->commit();
243
+				return $this->id;
244
+			}
245
+			else
246
+			{
247
+				$this->db->rollback();
248
+				dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
249
+				return -2;
250
+			}
251 251
 		}
252 252
 		else
253 253
 		{
@@ -328,36 +328,36 @@  discard block
 block discarded – undo
328 328
 		$result = $this->db->query($sql);
329 329
 		if ($result)
330 330
 		{
331
-		    unset($this->country_code);
332
-		    unset($this->country);
333
-		    unset($this->state_code);
334
-		    unset($this->state);
335
-
336
-		    $action='update';
337
-
338
-		    // Actions on extra fields (by external module or standard code)
339
-		    $hookmanager->initHooks(array('contactdao'));
340
-		    $parameters=array('socid'=>$this->id);
341
-		    $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
342
-		    if (empty($reshook))
343
-		    {
344
-		    	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
345
-		    	{
346
-		    		$result=$this->insertExtraFields();
347
-		    		if ($result < 0)
348
-		    		{
349
-		    			$error++;
350
-		    		}
351
-		    	}
352
-		    }
353
-		    else if ($reshook < 0) $error++;
331
+			unset($this->country_code);
332
+			unset($this->country);
333
+			unset($this->state_code);
334
+			unset($this->state);
335
+
336
+			$action='update';
337
+
338
+			// Actions on extra fields (by external module or standard code)
339
+			$hookmanager->initHooks(array('contactdao'));
340
+			$parameters=array('socid'=>$this->id);
341
+			$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
342
+			if (empty($reshook))
343
+			{
344
+				if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
345
+				{
346
+					$result=$this->insertExtraFields();
347
+					if ($result < 0)
348
+					{
349
+						$error++;
350
+					}
351
+				}
352
+			}
353
+			else if ($reshook < 0) $error++;
354 354
 
355 355
 			if (! $error && ! $notrigger)
356 356
 			{
357
-                // Call trigger
358
-                $result=$this->call_trigger('CONTACT_MODIFY',$user);
359
-                if ($result < 0) { $error++; }
360
-                // End call triggers
357
+				// Call trigger
358
+				$result=$this->call_trigger('CONTACT_MODIFY',$user);
359
+				if ($result < 0) { $error++; }
360
+				// End call triggers
361 361
 			}
362 362
 
363 363
 			if (! $error)
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 		else
376 376
 		{
377 377
 			$this->error=$this->db->lasterror().' sql='.$sql;
378
-            $this->db->rollback();
378
+			$this->db->rollback();
379 379
 			return -1;
380 380
 		}
381 381
 	}
@@ -410,9 +410,9 @@  discard block
 block discarded – undo
410 410
 	{
411 411
 		global $conf,$langs;
412 412
 
413
-        $info = array();
413
+		$info = array();
414 414
 
415
-        // Object classes
415
+		// Object classes
416 416
 		$info["objectclass"]=explode(',',$conf->global->LDAP_CONTACT_OBJECT_CLASS);
417 417
 
418 418
 		$this->fullname=$this->getFullName($langs);
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 		if ($this->phone_perso && ! empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
442 442
 		if ($this->phone_mobile && ! empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
443 443
 		if ($this->fax && ! empty($conf->global->LDAP_CONTACT_FIELD_FAX))	    $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
444
-        if ($this->skype && ! empty($conf->global->LDAP_CONTACT_FIELD_SKYPE))	    $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
444
+		if ($this->skype && ! empty($conf->global->LDAP_CONTACT_FIELD_SKYPE))	    $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
445 445
 		if ($this->note_private && ! empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = $this->note_private;
446 446
 		if ($this->email && ! empty($conf->global->LDAP_CONTACT_FIELD_MAIL))     $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
447 447
 
@@ -480,14 +480,14 @@  discard block
 block discarded – undo
480 480
 	 *  @param      int			$id         Id of contact
481 481
 	 *  @param      User		$user		User asking to change alert or birthday
482 482
 	 *  @param      int		    $notrigger	0=no, 1=yes
483
-     *  @return     int         			<0 if KO, >=0 if OK
483
+	 *  @return     int         			<0 if KO, >=0 if OK
484 484
 	 */
485 485
 	function update_perso($id, $user=null, $notrigger=0)
486 486
 	{
487
-	    $error=0;
488
-	    $result=false;
487
+		$error=0;
488
+		$result=false;
489 489
 
490
-	    $this->db->begin();
490
+		$this->db->begin();
491 491
 
492 492
 		// Mis a jour contact
493 493
 		$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
@@ -500,8 +500,8 @@  discard block
 block discarded – undo
500 500
 		$resql = $this->db->query($sql);
501 501
 		if (! $resql)
502 502
 		{
503
-            $error++;
504
-		    $this->error=$this->db->lasterror();
503
+			$error++;
504
+			$this->error=$this->db->lasterror();
505 505
 		}
506 506
 
507 507
 		// Mis a jour alerte birthday
@@ -518,8 +518,8 @@  discard block
 block discarded – undo
518 518
 				$result = $this->db->query($sql);
519 519
 				if (! $result)
520 520
 				{
521
-                    $error++;
522
-                    $this->error=$this->db->lasterror();
521
+					$error++;
522
+					$this->error=$this->db->lasterror();
523 523
 				}
524 524
 			}
525 525
 			else
@@ -534,29 +534,29 @@  discard block
 block discarded – undo
534 534
 			$result = $this->db->query($sql);
535 535
 			if (! $result)
536 536
 			{
537
-                $error++;
538
-                $this->error=$this->db->lasterror();
537
+				$error++;
538
+				$this->error=$this->db->lasterror();
539 539
 			}
540 540
 		}
541 541
 
542 542
 		if (! $error && ! $notrigger)
543 543
 		{
544
-		    // Call trigger
545
-		    $result=$this->call_trigger('CONTACT_MODIFY',$user);
546
-		    if ($result < 0) { $error++; }
547
-		    // End call triggers
544
+			// Call trigger
545
+			$result=$this->call_trigger('CONTACT_MODIFY',$user);
546
+			if ($result < 0) { $error++; }
547
+			// End call triggers
548 548
 		}
549 549
 
550 550
 		if (! $error)
551 551
 		{
552
-		    $this->db->commit();
553
-		    return 1;
552
+			$this->db->commit();
553
+			return 1;
554 554
 		}
555 555
 		else
556 556
 		{
557
-		    dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
558
-		    $this->db->rollback();
559
-		    return -$error;
557
+			dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
558
+			$this->db->rollback();
559
+			return -$error;
560 560
 		}
561 561
 	}
562 562
 
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
 	 *
567 567
 	 *  @param      int		$id          id du contact
568 568
 	 *  @param      User	$user        Utilisateur (abonnes aux alertes) qui veut les alertes de ce contact
569
-     *  @param      string  $ref_ext     External reference, not given by Dolibarr
569
+	 *  @param      string  $ref_ext     External reference, not given by Dolibarr
570 570
 	 *  @return     int     		     -1 if KO, 0 if OK but not found, 1 if OK
571 571
 	 */
572 572
 	function fetch($id, $user=0, $ref_ext='')
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 		$sql.= " c.fk_departement,";
590 590
 		$sql.= " c.birthday,";
591 591
 		$sql.= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid, c.skype,";
592
-        $sql.= " c.photo,";
592
+		$sql.= " c.photo,";
593 593
 		$sql.= " c.priv, c.note_private, c.note_public, c.default_lang, c.no_email, c.canvas,";
594 594
 		$sql.= " c.import_key,";
595 595
 		$sql.= " co.label as country, co.code as country_code,";
@@ -645,8 +645,8 @@  discard block
 block discarded – undo
645 645
 
646 646
 				$this->email			= $obj->email;
647 647
 				$this->jabberid			= $obj->jabberid;
648
-        		$this->skype			= $obj->skype;
649
-                $this->photo			= $obj->photo;
648
+				$this->skype			= $obj->skype;
649
+				$this->photo			= $obj->photo;
650 650
 				$this->priv				= $obj->priv;
651 651
 				$this->mail				= $obj->email;
652 652
 
@@ -713,11 +713,11 @@  discard block
 block discarded – undo
713 713
 				}
714 714
 
715 715
 				// Retreive all extrafield for contact
716
-                // fetch optionals attributes and labels
717
-                require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
718
-                $extrafields=new ExtraFields($this->db);
719
-                $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
720
-               	$this->fetch_optionals($this->id,$extralabels);
716
+				// fetch optionals attributes and labels
717
+				require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
718
+				$extrafields=new ExtraFields($this->db);
719
+				$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
720
+			   	$this->fetch_optionals($this->id,$extralabels);
721 721
 
722 722
 				return 1;
723 723
 			}
@@ -742,12 +742,12 @@  discard block
 block discarded – undo
742 742
 	 */
743 743
 	function setGenderFromCivility()
744 744
 	{
745
-	    unset($this->gender);
746
-    	if (in_array($this->civility_id, array('MR'))) {
747
-    	    $this->gender = 'man';
748
-    	} else if(in_array($this->civility_id, array('MME','MLE'))) {
749
-    	    $this->gender = 'woman';
750
-    	}
745
+		unset($this->gender);
746
+		if (in_array($this->civility_id, array('MR'))) {
747
+			$this->gender = 'man';
748
+		} else if(in_array($this->civility_id, array('MME','MLE'))) {
749
+			$this->gender = 'woman';
750
+		}
751 751
 	}
752 752
 
753 753
 	/**
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 	 *  ref_commande (for order and/or shipments)
758 758
 	 *  ref_propale
759 759
 	 *
760
-     *  @return     int             					<0 if KO, >=0 if OK
760
+	 *  @return     int             					<0 if KO, >=0 if OK
761 761
 	 */
762 762
 	function load_ref_elements()
763 763
 	{
@@ -885,10 +885,10 @@  discard block
 block discarded – undo
885 885
 
886 886
 		if (! $error && ! $notrigger)
887 887
 		{
888
-            // Call trigger
889
-            $result=$this->call_trigger('CONTACT_DELETE',$user);
890
-            if ($result < 0) { $error++; }
891
-            // End call triggers
888
+			// Call trigger
889
+			$result=$this->call_trigger('CONTACT_DELETE',$user);
890
+			if ($result < 0) { $error++; }
891
+			// End call triggers
892 892
 		}
893 893
 
894 894
 		if (! $error)
@@ -991,7 +991,7 @@  discard block
 block discarded – undo
991 991
 	 *	@param		string		$option						Where the link point to
992 992
 	 *	@param		int			$maxlen						Max length of
993 993
 	 *  @param		string		$moreparam					Add more param into URL
994
-     *  @param      int     	$save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
994
+	 *  @param      int     	$save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
995 995
 	 *	@return		string									String with URL
996 996
 	 */
997 997
 	function getNomUrl($withpicto=0, $option='', $maxlen=0, $moreparam='', $save_lastsearch_value=-1)
@@ -1000,39 +1000,39 @@  discard block
 block discarded – undo
1000 1000
 
1001 1001
 		$result='';
1002 1002
 
1003
-        $label = '<u>' . $langs->trans("ShowContact") . '</u>';
1004
-        $label.= '<br><b>' . $langs->trans("Name") . ':</b> '.$this->getFullName($langs);
1005
-        //if ($this->civility_id) $label.= '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id;		// TODO Translate cibilty_id code
1006
-        if (! empty($this->poste)) $label.= '<br><b>' . $langs->trans("Poste") . ':</b> '.$this->poste;
1007
-        $label.= '<br><b>' . $langs->trans("EMail") . ':</b> '.$this->email;
1008
-        $phonelist=array();
1009
-        if ($this->phone_pro) $phonelist[]=$this->phone_pro;
1010
-        if ($this->phone_mobile) $phonelist[]=$this->phone_mobile;
1011
-        if ($this->phone_perso) $phonelist[]=$this->phone_perso;
1012
-        $label.= '<br><b>' . $langs->trans("Phone") . ':</b> '.join(', ',$phonelist);
1013
-        $label.= '<br><b>' . $langs->trans("Address") . ':</b> '.dol_format_address($this, 1, ' ', $langs);
1014
-
1015
-        $url = DOL_URL_ROOT.'/contact/card.php?id='.$this->id;
1016
-
1017
-        if ($option !== 'nolink')
1018
-        {
1019
-        	// Add param to save lastsearch_values or not
1020
-        	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1021
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1022
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1023
-        }
1024
-
1025
-        $url .= $moreparam;
1026
-
1027
-        $linkstart = '<a href="'.$url.'"';
1028
-        $linkclose="";
1029
-    	if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1030
-        {
1031
-            $label=$langs->trans("ShowContact");
1032
-            $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1033
-        }
1034
-       	$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1035
-       	$linkclose.= ' class="classfortooltip">';
1003
+		$label = '<u>' . $langs->trans("ShowContact") . '</u>';
1004
+		$label.= '<br><b>' . $langs->trans("Name") . ':</b> '.$this->getFullName($langs);
1005
+		//if ($this->civility_id) $label.= '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id;		// TODO Translate cibilty_id code
1006
+		if (! empty($this->poste)) $label.= '<br><b>' . $langs->trans("Poste") . ':</b> '.$this->poste;
1007
+		$label.= '<br><b>' . $langs->trans("EMail") . ':</b> '.$this->email;
1008
+		$phonelist=array();
1009
+		if ($this->phone_pro) $phonelist[]=$this->phone_pro;
1010
+		if ($this->phone_mobile) $phonelist[]=$this->phone_mobile;
1011
+		if ($this->phone_perso) $phonelist[]=$this->phone_perso;
1012
+		$label.= '<br><b>' . $langs->trans("Phone") . ':</b> '.join(', ',$phonelist);
1013
+		$label.= '<br><b>' . $langs->trans("Address") . ':</b> '.dol_format_address($this, 1, ' ', $langs);
1014
+
1015
+		$url = DOL_URL_ROOT.'/contact/card.php?id='.$this->id;
1016
+
1017
+		if ($option !== 'nolink')
1018
+		{
1019
+			// Add param to save lastsearch_values or not
1020
+			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1021
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1022
+			if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1023
+		}
1024
+
1025
+		$url .= $moreparam;
1026
+
1027
+		$linkstart = '<a href="'.$url.'"';
1028
+		$linkclose="";
1029
+		if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1030
+		{
1031
+			$label=$langs->trans("ShowContact");
1032
+			$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1033
+		}
1034
+	   	$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1035
+	   	$linkclose.= ' class="classfortooltip">';
1036 1036
 
1037 1037
 		if (! is_object($hookmanager))
1038 1038
 		{
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
 			$linkend='</a>';
1054 1054
 		}
1055 1055
 
1056
-	        if ($withpicto) $result.=($linkstart.img_object($label, 'contact', 'class="classfortooltip"').$linkend.' ');
1056
+			if ($withpicto) $result.=($linkstart.img_object($label, 'contact', 'class="classfortooltip"').$linkend.' ');
1057 1057
 			$result.=$linkstart.($maxlen?dol_trunc($this->getFullName($langs),$maxlen):$this->getFullName($langs)).$linkend;
1058 1058
 		return $result;
1059 1059
 	}
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
 
1071 1071
 		$code=(! empty($this->civility_id)?$this->civility_id:(! empty($this->civilite_id)?$this->civilite_id:''));
1072 1072
 		if (empty($code)) return '';
1073
-        return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
1073
+		return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
1074 1074
 	}
1075 1075
 
1076 1076
 	/**
@@ -1144,11 +1144,11 @@  discard block
 block discarded – undo
1144 1144
 
1145 1145
 
1146 1146
 	/**
1147
-     *  Initialise an instance with random values.
1148
-     *  Used to build previews or test instances.
1149
-     *	id must be 0 if object instance is a specimen.
1150
-     *
1151
-     *  @return	void
1147
+	 *  Initialise an instance with random values.
1148
+	 *  Used to build previews or test instances.
1149
+	 *	id must be 0 if object instance is a specimen.
1150
+	 *
1151
+	 *  @return	void
1152 1152
 	 */
1153 1153
 	function initAsSpecimen()
1154 1154
 	{
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
 		$this->country_code = 'FR';
1175 1175
 		$this->country = 'France';
1176 1176
 		$this->email = '[email protected]';
1177
-    	$this->skype = 'tom.hanson';
1177
+		$this->skype = 'tom.hanson';
1178 1178
 
1179 1179
 		$this->phone_pro = '0909090901';
1180 1180
 		$this->phone_perso = '0909090902';
@@ -1215,10 +1215,10 @@  discard block
 block discarded – undo
1215 1215
 		dol_syslog(get_class($this)."::setstatus", LOG_DEBUG);
1216 1216
 		if ($result)
1217 1217
 		{
1218
-            // Call trigger
1219
-            $result=$this->call_trigger('CONTACT_ENABLEDISABLE',$user);
1220
-            if ($result < 0) { $error++; }
1221
-            // End call triggers
1218
+			// Call trigger
1219
+			$result=$this->call_trigger('CONTACT_ENABLEDISABLE',$user);
1220
+			if ($result < 0) { $error++; }
1221
+			// End call triggers
1222 1222
 		}
1223 1223
 
1224 1224
 		if ($error)
Please login to merge, or discard this patch.
Spacing   +322 added lines, -322 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
  *	\ingroup    societe
30 30
  *	\brief      File of contacts class
31 31
  */
32
-require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
32
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
33 33
 
34 34
 
35 35
 /**
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
  */
38 38
 class Contact extends CommonObject
39 39
 {
40
-	public $element='contact';
41
-	public $table_element='socpeople';
42
-	protected $ismultientitymanaged = 1;	// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
40
+	public $element = 'contact';
41
+	public $table_element = 'socpeople';
42
+	protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
43 43
 
44
-	public $civility_id;      // In fact we store civility_code
44
+	public $civility_id; // In fact we store civility_code
45 45
 	public $civility_code;
46 46
 	public $address;
47 47
 	public $zip;
@@ -62,14 +62,14 @@  discard block
 block discarded – undo
62 62
 	 * @see state
63 63
 	 */
64 64
 	public $departement;
65
-	public $state_id;	        	// Id of department
66
-	public $state_code;		    // Code of department
67
-	public $state;			        // Label of department
65
+	public $state_id; // Id of department
66
+	public $state_code; // Code of department
67
+	public $state; // Label of department
68 68
 
69
-    	public $poste;                 // Position
69
+    	public $poste; // Position
70 70
 
71
-	public $socid;					// fk_soc
72
-	public $statut;				// 0=inactif, 1=actif
71
+	public $socid; // fk_soc
72
+	public $statut; // 0=inactif, 1=actif
73 73
 
74 74
 	public $code;
75 75
 	public $email;
@@ -85,17 +85,17 @@  discard block
 block discarded – undo
85 85
 
86 86
 	public $birthday;
87 87
 	public $default_lang;
88
-    	public $no_email;				// 1=Don't send e-mail to this contact, 0=do
88
+    	public $no_email; // 1=Don't send e-mail to this contact, 0=do
89 89
 
90
-	public $ref_facturation;       // Reference number of invoice for which it is contact
91
-	public $ref_contrat;           // Nb de reference contrat pour lequel il est contact
92
-	public $ref_commande;          // Nb de reference commande pour lequel il est contact
93
-	public $ref_propal;            // Nb de reference propal pour lequel il est contact
90
+	public $ref_facturation; // Reference number of invoice for which it is contact
91
+	public $ref_contrat; // Nb de reference contrat pour lequel il est contact
92
+	public $ref_commande; // Nb de reference commande pour lequel il est contact
93
+	public $ref_propal; // Nb de reference propal pour lequel il est contact
94 94
 
95 95
 	public $user_id;
96 96
 	public $user_login;
97 97
 
98
-	public $oldcopy;				// To contains a clone of this when we need to save old properties of object
98
+	public $oldcopy; // To contains a clone of this when we need to save old properties of object
99 99
 
100 100
 
101 101
 	/**
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	function __construct($db)
107 107
 	{
108 108
 		$this->db = $db;
109
-		$this->statut = 1;	// By default, status is enabled
109
+		$this->statut = 1; // By default, status is enabled
110 110
 	}
111 111
 
112 112
 	/**
@@ -118,28 +118,28 @@  discard block
 block discarded – undo
118 118
 	{
119 119
 		global $user;
120 120
 
121
-		$this->nb=array();
121
+		$this->nb = array();
122 122
 		$clause = "WHERE";
123 123
 
124 124
 		$sql = "SELECT count(sp.rowid) as nb";
125
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
125
+		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
126 126
 		if (!$user->rights->societe->client->voir && !$user->societe_id)
127 127
 		{
128
-		    $sql.= ", ".MAIN_DB_PREFIX."societe as s";
129
-		    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
130
-			$sql.= " WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
128
+		    $sql .= ", ".MAIN_DB_PREFIX."societe as s";
129
+		    $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
130
+			$sql .= " WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
131 131
 			$clause = "AND";
132 132
 		}
133
-		$sql.= ' '.$clause.' sp.entity IN ('.getEntity($this->element, 1).')';
134
-		$sql.= " AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat=".$user->id."))";
135
-        if ($user->societe_id > 0) $sql.=" AND sp.fk_soc = ".$user->societe_id;
133
+		$sql .= ' '.$clause.' sp.entity IN ('.getEntity($this->element, 1).')';
134
+		$sql .= " AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat=".$user->id."))";
135
+        if ($user->societe_id > 0) $sql .= " AND sp.fk_soc = ".$user->societe_id;
136 136
 
137
-		$resql=$this->db->query($sql);
137
+		$resql = $this->db->query($sql);
138 138
 		if ($resql)
139 139
 		{
140
-			while ($obj=$this->db->fetch_object($resql))
140
+			while ($obj = $this->db->fetch_object($resql))
141 141
 			{
142
-				$this->nb["contacts"]=$obj->nb;
142
+				$this->nb["contacts"] = $obj->nb;
143 143
 			}
144 144
 			$this->db->free($resql);
145 145
 			return 1;
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 		else
148 148
 		{
149 149
 			dol_print_error($this->db);
150
-			$this->error=$this->db->lasterror();
150
+			$this->error = $this->db->lasterror();
151 151
 			return -1;
152 152
 		}
153 153
 	}
@@ -162,82 +162,82 @@  discard block
 block discarded – undo
162 162
 	{
163 163
 		global $conf, $langs;
164 164
 
165
-		$error=0;
166
-		$now=dol_now();
165
+		$error = 0;
166
+		$now = dol_now();
167 167
 
168 168
 		$this->db->begin();
169 169
 
170 170
 		// Clean parameters
171
-		$this->lastname=$this->lastname?trim($this->lastname):trim($this->name);
172
-        $this->firstname=trim($this->firstname);
173
-        if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords($this->lastname);
174
-        if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords($this->firstname);
171
+		$this->lastname = $this->lastname ?trim($this->lastname) : trim($this->name);
172
+        $this->firstname = trim($this->firstname);
173
+        if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname);
174
+        if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname);
175 175
         if (empty($this->socid)) $this->socid = 0;
176 176
 		if (empty($this->priv)) $this->priv = 0;
177 177
 		if (empty($this->statut)) $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request
178 178
 
179 179
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (";
180
-		$sql.= " datec";
181
-		$sql.= ", fk_soc";
182
-        $sql.= ", lastname";
183
-        $sql.= ", firstname";
184
-        $sql.= ", fk_user_creat";
185
-		$sql.= ", priv";
186
-		$sql.= ", statut";
187
-		$sql.= ", canvas";
188
-		$sql.= ", entity";
189
-		$sql.= ",ref_ext";
190
-		$sql.= ", import_key";
191
-		$sql.= ") VALUES (";
192
-		$sql.= "'".$this->db->idate($now)."',";
193
-		if ($this->socid > 0) $sql.= " ".$this->socid.",";
194
-		else $sql.= "null,";
195
-		$sql.= "'".$this->db->escape($this->lastname)."',";
196
-        $sql.= "'".$this->db->escape($this->firstname)."',";
197
-		$sql.= " ".($user->id > 0 ? "'".$user->id."'":"null").",";
198
-		$sql.= " ".$this->priv.",";
199
-		$sql.= " ".$this->statut.",";
200
-        $sql.= " ".(! empty($this->canvas)?"'".$this->db->escape($this->canvas)."'":"null").",";
201
-        $sql.= " ".$conf->entity.",";
202
-        $sql.= "'".$this->db->escape($this->ref_ext)."',";
203
-        $sql.= " ".(! empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
204
-		$sql.= ")";
180
+		$sql .= " datec";
181
+		$sql .= ", fk_soc";
182
+        $sql .= ", lastname";
183
+        $sql .= ", firstname";
184
+        $sql .= ", fk_user_creat";
185
+		$sql .= ", priv";
186
+		$sql .= ", statut";
187
+		$sql .= ", canvas";
188
+		$sql .= ", entity";
189
+		$sql .= ",ref_ext";
190
+		$sql .= ", import_key";
191
+		$sql .= ") VALUES (";
192
+		$sql .= "'".$this->db->idate($now)."',";
193
+		if ($this->socid > 0) $sql .= " ".$this->socid.",";
194
+		else $sql .= "null,";
195
+		$sql .= "'".$this->db->escape($this->lastname)."',";
196
+        $sql .= "'".$this->db->escape($this->firstname)."',";
197
+		$sql .= " ".($user->id > 0 ? "'".$user->id."'" : "null").",";
198
+		$sql .= " ".$this->priv.",";
199
+		$sql .= " ".$this->statut.",";
200
+        $sql .= " ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null").",";
201
+        $sql .= " ".$conf->entity.",";
202
+        $sql .= "'".$this->db->escape($this->ref_ext)."',";
203
+        $sql .= " ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
204
+		$sql .= ")";
205 205
 
206 206
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
207
-		$resql=$this->db->query($sql);
207
+		$resql = $this->db->query($sql);
208 208
 		if ($resql)
209 209
 		{
210 210
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople");
211 211
 
212
-			if (! $error)
212
+			if (!$error)
213 213
 			{
214
-                $result=$this->update($this->id, $user, 1, 'add');
214
+                $result = $this->update($this->id, $user, 1, 'add');
215 215
                 if ($result < 0)
216 216
                 {
217 217
                     $error++;
218
-				    $this->error=$this->db->lasterror();
218
+				    $this->error = $this->db->lasterror();
219 219
                 }
220 220
 			}
221 221
 
222
-			if (! $error)
222
+			if (!$error)
223 223
             {
224
-                $result=$this->update_perso($this->id, $user, 1);   // TODO Remove function update_perso, should be same than update
224
+                $result = $this->update_perso($this->id, $user, 1); // TODO Remove function update_perso, should be same than update
225 225
                 if ($result < 0)
226 226
                 {
227 227
                     $error++;
228
-                    $this->error=$this->db->lasterror();
228
+                    $this->error = $this->db->lasterror();
229 229
                 }
230 230
             }
231 231
 
232
-			if (! $error)
232
+			if (!$error)
233 233
             {
234 234
                 // Call trigger
235
-                $result=$this->call_trigger('CONTACT_CREATE',$user);
235
+                $result = $this->call_trigger('CONTACT_CREATE', $user);
236 236
                 if ($result < 0) { $error++; }
237 237
                 // End call triggers
238 238
             }
239 239
 
240
-            if (! $error)
240
+            if (!$error)
241 241
             {
242 242
                 $this->db->commit();
243 243
                 return $this->id;
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 		}
252 252
 		else
253 253
 		{
254
-			$this->error=$this->db->lasterror();
254
+			$this->error = $this->db->lasterror();
255 255
 
256 256
 			$this->db->rollback();
257 257
 			dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
@@ -268,29 +268,29 @@  discard block
 block discarded – undo
268 268
 	 *      @param		string	$action			Current action for hookmanager
269 269
 	 *      @return     int      			   	<0 if KO, >0 if OK
270 270
 	 */
271
-	function update($id, $user=null, $notrigger=0, $action='update')
271
+	function update($id, $user = null, $notrigger = 0, $action = 'update')
272 272
 	{
273 273
 		global $conf, $langs, $hookmanager;
274 274
 
275
-		$error=0;
275
+		$error = 0;
276 276
 
277 277
 		$this->id = $id;
278 278
 
279 279
 		// Clean parameters
280
-		$this->lastname=trim($this->lastname)?trim($this->lastname):trim($this->lastname);
281
-		$this->firstname=trim($this->firstname);
282
-		$this->email=trim($this->email);
283
-		$this->phone_pro=trim($this->phone_pro);
284
-		$this->phone_perso=trim($this->phone_perso);
285
-		$this->phone_mobile=trim($this->phone_mobile);
286
-		$this->jabberid=trim($this->jabberid);
287
-		$this->skype=trim($this->skype);
288
-		$this->photo=trim($this->photo);
289
-		$this->fax=trim($this->fax);
290
-		$this->zip=(empty($this->zip)?'':$this->zip);
291
-		$this->town=(empty($this->town)?'':$this->town);
292
-		$this->country_id=($this->country_id > 0?$this->country_id:$this->country_id);
293
-		$this->state_id=($this->state_id > 0?$this->state_id:$this->fk_departement);
280
+		$this->lastname = trim($this->lastname) ?trim($this->lastname) : trim($this->lastname);
281
+		$this->firstname = trim($this->firstname);
282
+		$this->email = trim($this->email);
283
+		$this->phone_pro = trim($this->phone_pro);
284
+		$this->phone_perso = trim($this->phone_perso);
285
+		$this->phone_mobile = trim($this->phone_mobile);
286
+		$this->jabberid = trim($this->jabberid);
287
+		$this->skype = trim($this->skype);
288
+		$this->photo = trim($this->photo);
289
+		$this->fax = trim($this->fax);
290
+		$this->zip = (empty($this->zip) ? '' : $this->zip);
291
+		$this->town = (empty($this->town) ? '' : $this->town);
292
+		$this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
293
+		$this->state_id = ($this->state_id > 0 ? $this->state_id : $this->fk_departement);
294 294
 		if (empty($this->statut)) $this->statut = 0;
295 295
 
296 296
 		$this->db->begin();
@@ -304,24 +304,24 @@  discard block
 block discarded – undo
304 304
 		$sql .= ", address='".$this->db->escape($this->address)."'";
305 305
 		$sql .= ", zip='".$this->db->escape($this->zip)."'";
306 306
 		$sql .= ", town='".$this->db->escape($this->town)."'";
307
-		$sql .= ", fk_pays=".($this->country_id>0?$this->country_id:'NULL');
308
-		$sql .= ", fk_departement=".($this->state_id>0?$this->state_id:'NULL');
307
+		$sql .= ", fk_pays=".($this->country_id > 0 ? $this->country_id : 'NULL');
308
+		$sql .= ", fk_departement=".($this->state_id > 0 ? $this->state_id : 'NULL');
309 309
 		$sql .= ", poste='".$this->db->escape($this->poste)."'";
310 310
 		$sql .= ", fax='".$this->db->escape($this->fax)."'";
311 311
 		$sql .= ", email='".$this->db->escape($this->email)."'";
312 312
 		$sql .= ", skype='".$this->db->escape($this->skype)."'";
313 313
 		$sql .= ", photo='".$this->db->escape($this->photo)."'";
314
-		$sql .= ", note_private = ".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
315
-		$sql .= ", note_public = ".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
316
-		$sql .= ", phone = ".(isset($this->phone_pro)?"'".$this->db->escape($this->phone_pro)."'":"null");
317
-		$sql .= ", phone_perso = ".(isset($this->phone_perso)?"'".$this->db->escape($this->phone_perso)."'":"null");
318
-		$sql .= ", phone_mobile = ".(isset($this->phone_mobile)?"'".$this->db->escape($this->phone_mobile)."'":"null");
319
-		$sql .= ", jabberid = ".(isset($this->jabberid)?"'".$this->db->escape($this->jabberid)."'":"null");
314
+		$sql .= ", note_private = ".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
315
+		$sql .= ", note_public = ".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
316
+		$sql .= ", phone = ".(isset($this->phone_pro) ? "'".$this->db->escape($this->phone_pro)."'" : "null");
317
+		$sql .= ", phone_perso = ".(isset($this->phone_perso) ? "'".$this->db->escape($this->phone_perso)."'" : "null");
318
+		$sql .= ", phone_mobile = ".(isset($this->phone_mobile) ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
319
+		$sql .= ", jabberid = ".(isset($this->jabberid) ? "'".$this->db->escape($this->jabberid)."'" : "null");
320 320
 		$sql .= ", priv = '".$this->db->escape($this->priv)."'";
321 321
 		$sql .= ", statut = ".$this->statut;
322
-		$sql .= ", fk_user_modif=".($user->id > 0 ? "'".$this->db->escape($user->id)."'":"NULL");
323
-		$sql .= ", default_lang=".($this->default_lang?"'".$this->db->escape($this->default_lang)."'":"NULL");
324
-		$sql .= ", no_email=".($this->no_email?"'".$this->db->escape($this->no_email)."'":"0");
322
+		$sql .= ", fk_user_modif=".($user->id > 0 ? "'".$this->db->escape($user->id)."'" : "NULL");
323
+		$sql .= ", default_lang=".($this->default_lang ? "'".$this->db->escape($this->default_lang)."'" : "NULL");
324
+		$sql .= ", no_email=".($this->no_email ? "'".$this->db->escape($this->no_email)."'" : "0");
325 325
 		$sql .= " WHERE rowid=".$this->db->escape($id);
326 326
 
327 327
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
@@ -333,17 +333,17 @@  discard block
 block discarded – undo
333 333
 		    unset($this->state_code);
334 334
 		    unset($this->state);
335 335
 
336
-		    $action='update';
336
+		    $action = 'update';
337 337
 
338 338
 		    // Actions on extra fields (by external module or standard code)
339 339
 		    $hookmanager->initHooks(array('contactdao'));
340
-		    $parameters=array('socid'=>$this->id);
341
-		    $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
340
+		    $parameters = array('socid'=>$this->id);
341
+		    $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
342 342
 		    if (empty($reshook))
343 343
 		    {
344 344
 		    	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
345 345
 		    	{
346
-		    		$result=$this->insertExtraFields();
346
+		    		$result = $this->insertExtraFields();
347 347
 		    		if ($result < 0)
348 348
 		    		{
349 349
 		    			$error++;
@@ -352,29 +352,29 @@  discard block
 block discarded – undo
352 352
 		    }
353 353
 		    else if ($reshook < 0) $error++;
354 354
 
355
-			if (! $error && ! $notrigger)
355
+			if (!$error && !$notrigger)
356 356
 			{
357 357
                 // Call trigger
358
-                $result=$this->call_trigger('CONTACT_MODIFY',$user);
358
+                $result = $this->call_trigger('CONTACT_MODIFY', $user);
359 359
                 if ($result < 0) { $error++; }
360 360
                 // End call triggers
361 361
 			}
362 362
 
363
-			if (! $error)
363
+			if (!$error)
364 364
 			{
365 365
 				$this->db->commit();
366 366
 				return 1;
367 367
 			}
368 368
 			else
369 369
 			{
370
-				dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
370
+				dol_syslog(get_class($this)."::update Error ".$this->error, LOG_ERR);
371 371
 				$this->db->rollback();
372 372
 				return -$error;
373 373
 			}
374 374
 		}
375 375
 		else
376 376
 		{
377
-			$this->error=$this->db->lasterror().' sql='.$sql;
377
+			$this->error = $this->db->lasterror().' sql='.$sql;
378 378
             $this->db->rollback();
379 379
 			return -1;
380 380
 		}
@@ -390,13 +390,13 @@  discard block
 block discarded – undo
390 390
 	 *									2=Return key only (uid=qqq)
391 391
 	 *	@return		string				DN
392 392
 	 */
393
-	function _load_ldap_dn($info,$mode=0)
393
+	function _load_ldap_dn($info, $mode = 0)
394 394
 	{
395 395
 		global $conf;
396
-		$dn='';
397
-		if ($mode==0) $dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN;
398
-		if ($mode==1) $dn=$conf->global->LDAP_CONTACT_DN;
399
-		if ($mode==2) $dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS];
396
+		$dn = '';
397
+		if ($mode == 0) $dn = $conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN;
398
+		if ($mode == 1) $dn = $conf->global->LDAP_CONTACT_DN;
399
+		if ($mode == 2) $dn = $conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS];
400 400
 		return $dn;
401 401
 	}
402 402
 
@@ -408,19 +408,19 @@  discard block
 block discarded – undo
408 408
 	 */
409 409
 	function _load_ldap_info()
410 410
 	{
411
-		global $conf,$langs;
411
+		global $conf, $langs;
412 412
 
413 413
         $info = array();
414 414
 
415 415
         // Object classes
416
-		$info["objectclass"]=explode(',',$conf->global->LDAP_CONTACT_OBJECT_CLASS);
416
+		$info["objectclass"] = explode(',', $conf->global->LDAP_CONTACT_OBJECT_CLASS);
417 417
 
418
-		$this->fullname=$this->getFullName($langs);
418
+		$this->fullname = $this->getFullName($langs);
419 419
 
420 420
 		// Fields
421
-		if ($this->fullname && ! empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
422
-		if ($this->lastname && ! empty($conf->global->LDAP_CONTACT_FIELD_NAME)) $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
423
-		if ($this->firstname && ! empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
421
+		if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
422
+		if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
423
+		if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
424 424
 
425 425
 		if ($this->poste) $info["title"] = $this->poste;
426 426
 		if ($this->socid > 0)
@@ -433,17 +433,17 @@  discard block
 block discarded – undo
433 433
 			if ($soc->client == 2)      $info["businessCategory"] = "Prospects";
434 434
 			if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers";
435 435
 		}
436
-		if ($this->address && ! empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
437
-		if ($this->zip && ! empty($conf->global->LDAP_CONTACT_FIELD_ZIP))          $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
438
-		if ($this->town && ! empty($conf->global->LDAP_CONTACT_FIELD_TOWN))      $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
439
-		if ($this->country_code && ! empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY))      $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
440
-		if ($this->phone_pro && ! empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
441
-		if ($this->phone_perso && ! empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
442
-		if ($this->phone_mobile && ! empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
443
-		if ($this->fax && ! empty($conf->global->LDAP_CONTACT_FIELD_FAX))	    $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
444
-        if ($this->skype && ! empty($conf->global->LDAP_CONTACT_FIELD_SKYPE))	    $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
445
-		if ($this->note_private && ! empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = $this->note_private;
446
-		if ($this->email && ! empty($conf->global->LDAP_CONTACT_FIELD_MAIL))     $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
436
+		if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
437
+		if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP))          $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
438
+		if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN))      $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
439
+		if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY))      $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
440
+		if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
441
+		if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
442
+		if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
443
+		if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX))	    $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
444
+        if ($this->skype && !empty($conf->global->LDAP_CONTACT_FIELD_SKYPE))	    $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
445
+		if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = $this->note_private;
446
+		if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL))     $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
447 447
 
448 448
 		if ($conf->global->LDAP_SERVER_TYPE == 'egroupware')
449 449
 		{
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 
452 452
 			$info['uidnumber'] = $this->id;
453 453
 
454
-			$info['phpgwTz']      = 0;
454
+			$info['phpgwTz'] = 0;
455 455
 			$info['phpgwMailType'] = 'INTERNET';
456 456
 			$info['phpgwMailHomeType'] = 'INTERNET';
457 457
 
@@ -482,26 +482,26 @@  discard block
 block discarded – undo
482 482
 	 *  @param      int		    $notrigger	0=no, 1=yes
483 483
      *  @return     int         			<0 if KO, >=0 if OK
484 484
 	 */
485
-	function update_perso($id, $user=null, $notrigger=0)
485
+	function update_perso($id, $user = null, $notrigger = 0)
486 486
 	{
487
-	    $error=0;
488
-	    $result=false;
487
+	    $error = 0;
488
+	    $result = false;
489 489
 
490 490
 	    $this->db->begin();
491 491
 
492 492
 		// Mis a jour contact
493 493
 		$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
494
-		$sql.= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
495
-		$sql.= ", photo = ".($this->photo? "'".$this->db->escape($this->photo)."'" : "null");
494
+		$sql .= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
495
+		$sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
496 496
 		if ($user) $sql .= ", fk_user_modif=".$user->id;
497
-		$sql.= " WHERE rowid=".$this->db->escape($id);
497
+		$sql .= " WHERE rowid=".$this->db->escape($id);
498 498
 
499 499
 		dol_syslog(get_class($this)."::update_perso this->birthday=".$this->birthday." -", LOG_DEBUG);
500 500
 		$resql = $this->db->query($sql);
501
-		if (! $resql)
501
+		if (!$resql)
502 502
 		{
503 503
             $error++;
504
-		    $this->error=$this->db->lasterror();
504
+		    $this->error = $this->db->lasterror();
505 505
 		}
506 506
 
507 507
 		// Mis a jour alerte birthday
@@ -510,16 +510,16 @@  discard block
 block discarded – undo
510 510
 			//check existing
511 511
 			$sql_check = "SELECT * FROM ".MAIN_DB_PREFIX."user_alert WHERE type=1 AND fk_contact=".$this->db->escape($id)." AND fk_user=".$user->id;
512 512
 			$result_check = $this->db->query($sql_check);
513
-			if (! $result_check || ($this->db->num_rows($result_check)<1))
513
+			if (!$result_check || ($this->db->num_rows($result_check) < 1))
514 514
 			{
515 515
 				//insert
516 516
 				$sql = "INSERT INTO ".MAIN_DB_PREFIX."user_alert(type,fk_contact,fk_user) ";
517
-				$sql.= "VALUES (1,".$this->db->escape($id).",".$user->id.")";
517
+				$sql .= "VALUES (1,".$this->db->escape($id).",".$user->id.")";
518 518
 				$result = $this->db->query($sql);
519
-				if (! $result)
519
+				if (!$result)
520 520
 				{
521 521
                     $error++;
522
-                    $this->error=$this->db->lasterror();
522
+                    $this->error = $this->db->lasterror();
523 523
 				}
524 524
 			}
525 525
 			else
@@ -530,31 +530,31 @@  discard block
 block discarded – undo
530 530
 		else
531 531
 		{
532 532
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_alert ";
533
-			$sql.= "WHERE type=1 AND fk_contact=".$this->db->escape($id)." AND fk_user=".$user->id;
533
+			$sql .= "WHERE type=1 AND fk_contact=".$this->db->escape($id)." AND fk_user=".$user->id;
534 534
 			$result = $this->db->query($sql);
535
-			if (! $result)
535
+			if (!$result)
536 536
 			{
537 537
                 $error++;
538
-                $this->error=$this->db->lasterror();
538
+                $this->error = $this->db->lasterror();
539 539
 			}
540 540
 		}
541 541
 
542
-		if (! $error && ! $notrigger)
542
+		if (!$error && !$notrigger)
543 543
 		{
544 544
 		    // Call trigger
545
-		    $result=$this->call_trigger('CONTACT_MODIFY',$user);
545
+		    $result = $this->call_trigger('CONTACT_MODIFY', $user);
546 546
 		    if ($result < 0) { $error++; }
547 547
 		    // End call triggers
548 548
 		}
549 549
 
550
-		if (! $error)
550
+		if (!$error)
551 551
 		{
552 552
 		    $this->db->commit();
553 553
 		    return 1;
554 554
 		}
555 555
 		else
556 556
 		{
557
-		    dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
557
+		    dol_syslog(get_class($this)."::update Error ".$this->error, LOG_ERR);
558 558
 		    $this->db->rollback();
559 559
 		    return -$error;
560 560
 		}
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
      *  @param      string  $ref_ext     External reference, not given by Dolibarr
570 570
 	 *  @return     int     		     -1 if KO, 0 if OK but not found, 1 if OK
571 571
 	 */
572
-	function fetch($id, $user=0, $ref_ext='')
572
+	function fetch($id, $user = 0, $ref_ext = '')
573 573
 	{
574 574
 		global $langs;
575 575
 
@@ -577,88 +577,88 @@  discard block
 block discarded – undo
577 577
 
578 578
 		if (empty($id) && empty($ref_ext))
579 579
 		{
580
-			$this->error='BadParameter';
580
+			$this->error = 'BadParameter';
581 581
 			return -1;
582 582
 		}
583 583
 
584 584
 		$langs->load("companies");
585 585
 
586 586
 		$sql = "SELECT c.rowid, c.fk_soc, c.ref_ext, c.civility as civility_id, c.lastname, c.firstname,";
587
-		$sql.= " c.address, c.statut, c.zip, c.town,";
588
-		$sql.= " c.fk_pays as country_id,";
589
-		$sql.= " c.fk_departement,";
590
-		$sql.= " c.birthday,";
591
-		$sql.= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid, c.skype,";
592
-        $sql.= " c.photo,";
593
-		$sql.= " c.priv, c.note_private, c.note_public, c.default_lang, c.no_email, c.canvas,";
594
-		$sql.= " c.import_key,";
595
-		$sql.= " co.label as country, co.code as country_code,";
596
-		$sql.= " d.nom as state, d.code_departement as state_code,";
597
-		$sql.= " u.rowid as user_id, u.login as user_login,";
598
-		$sql.= " s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
599
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
600
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON c.fk_pays = co.rowid";
601
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
602
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
603
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
604
-		if ($id) $sql.= " WHERE c.rowid = ". $id;
587
+		$sql .= " c.address, c.statut, c.zip, c.town,";
588
+		$sql .= " c.fk_pays as country_id,";
589
+		$sql .= " c.fk_departement,";
590
+		$sql .= " c.birthday,";
591
+		$sql .= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid, c.skype,";
592
+        $sql .= " c.photo,";
593
+		$sql .= " c.priv, c.note_private, c.note_public, c.default_lang, c.no_email, c.canvas,";
594
+		$sql .= " c.import_key,";
595
+		$sql .= " co.label as country, co.code as country_code,";
596
+		$sql .= " d.nom as state, d.code_departement as state_code,";
597
+		$sql .= " u.rowid as user_id, u.login as user_login,";
598
+		$sql .= " s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
599
+		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
600
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON c.fk_pays = co.rowid";
601
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
602
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
603
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
604
+		if ($id) $sql .= " WHERE c.rowid = ".$id;
605 605
 		elseif ($ref_ext) $sql .= " WHERE c.ref_ext = '".$this->db->escape($ref_ext)."'";
606 606
 
607
-		$resql=$this->db->query($sql);
607
+		$resql = $this->db->query($sql);
608 608
 		if ($resql)
609 609
 		{
610 610
 			if ($this->db->num_rows($resql))
611 611
 			{
612 612
 				$obj = $this->db->fetch_object($resql);
613 613
 
614
-				$this->id				= $obj->rowid;
615
-				$this->ref				= $obj->rowid;
616
-				$this->ref_ext			= $obj->ref_ext;
617
-				$this->civility_id		= $obj->civility_id;
618
-				$this->civility_code	= $obj->civility_id;
614
+				$this->id = $obj->rowid;
615
+				$this->ref = $obj->rowid;
616
+				$this->ref_ext = $obj->ref_ext;
617
+				$this->civility_id = $obj->civility_id;
618
+				$this->civility_code = $obj->civility_id;
619 619
 				$this->lastname			= $obj->lastname;
620 620
 				$this->firstname		= $obj->firstname;
621
-				$this->address			= $obj->address;
622
-				$this->zip				= $obj->zip;
623
-				$this->town				= $obj->town;
621
+				$this->address = $obj->address;
622
+				$this->zip = $obj->zip;
623
+				$this->town = $obj->town;
624 624
 
625
-				$this->fk_departement	= $obj->fk_departement;    // deprecated
626
-				$this->state_id			= $obj->fk_departement;
627
-				$this->departement_code = $obj->state_code;	       // deprecated
625
+				$this->fk_departement = $obj->fk_departement; // deprecated
626
+				$this->state_id = $obj->fk_departement;
627
+				$this->departement_code = $obj->state_code; // deprecated
628 628
 				$this->state_code       = $obj->state_code;
629
-				$this->departement		= $obj->state;	           // deprecated
630
-				$this->state			= $obj->state;
629
+				$this->departement		= $obj->state; // deprecated
630
+				$this->state = $obj->state;
631 631
 
632 632
 				$this->country_id 		= $obj->country_id;
633
-				$this->country_code		= $obj->country_id?$obj->country_code:'';
634
-				$this->country			= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
633
+				$this->country_code = $obj->country_id ? $obj->country_code : '';
634
+				$this->country			= $obj->country_id ? ($langs->trans('Country'.$obj->country_code) != 'Country'.$obj->country_code ? $langs->transnoentities('Country'.$obj->country_code) : $obj->country) : '';
635 635
 
636 636
 				$this->socid			= $obj->fk_soc;
637 637
 				$this->socname			= $obj->socname;
638 638
 				$this->poste			= $obj->poste;
639
-				$this->statut			= $obj->statut;
639
+				$this->statut = $obj->statut;
640 640
 
641
-				$this->phone_pro		= trim($obj->phone);
642
-				$this->fax				= trim($obj->fax);
643
-				$this->phone_perso		= trim($obj->phone_perso);
644
-				$this->phone_mobile		= trim($obj->phone_mobile);
641
+				$this->phone_pro = trim($obj->phone);
642
+				$this->fax = trim($obj->fax);
643
+				$this->phone_perso = trim($obj->phone_perso);
644
+				$this->phone_mobile = trim($obj->phone_mobile);
645 645
 
646
-				$this->email			= $obj->email;
647
-				$this->jabberid			= $obj->jabberid;
648
-        		$this->skype			= $obj->skype;
649
-                $this->photo			= $obj->photo;
646
+				$this->email = $obj->email;
647
+				$this->jabberid = $obj->jabberid;
648
+        		$this->skype = $obj->skype;
649
+                $this->photo = $obj->photo;
650 650
 				$this->priv				= $obj->priv;
651 651
 				$this->mail				= $obj->email;
652 652
 
653
-				$this->birthday			= $this->db->jdate($obj->birthday);
654
-				$this->note				= $obj->note_private;		// deprecated
653
+				$this->birthday = $this->db->jdate($obj->birthday);
654
+				$this->note				= $obj->note_private; // deprecated
655 655
 				$this->note_private		= $obj->note_private;
656
-				$this->note_public		= $obj->note_public;
656
+				$this->note_public = $obj->note_public;
657 657
 				$this->default_lang		= $obj->default_lang;
658
-				$this->no_email			= $obj->no_email;
659
-				$this->user_id			= $obj->user_id;
658
+				$this->no_email = $obj->no_email;
659
+				$this->user_id = $obj->user_id;
660 660
 				$this->user_login		= $obj->user_login;
661
-				$this->canvas			= $obj->canvas;
661
+				$this->canvas = $obj->canvas;
662 662
 
663 663
 				$this->import_key		= $obj->import_key;
664 664
 
@@ -668,9 +668,9 @@  discard block
 block discarded – undo
668 668
 				// Search Dolibarr user linked to this contact
669 669
 				$sql = "SELECT u.rowid ";
670 670
 				$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
671
-				$sql .= " WHERE u.fk_socpeople = ". $this->id;
671
+				$sql .= " WHERE u.fk_socpeople = ".$this->id;
672 672
 
673
-				$resql=$this->db->query($sql);
673
+				$resql = $this->db->query($sql);
674 674
 				if ($resql)
675 675
 				{
676 676
 					if ($this->db->num_rows($resql))
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
 				}
684 684
 				else
685 685
 				{
686
-					$this->error=$this->db->error();
686
+					$this->error = $this->db->error();
687 687
 					return -1;
688 688
 				}
689 689
 
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
 					$sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
695 695
 					$sql .= " WHERE fk_user = ".$user->id." AND fk_contact = ".$this->db->escape($id);
696 696
 
697
-					$resql=$this->db->query($sql);
697
+					$resql = $this->db->query($sql);
698 698
 					if ($resql)
699 699
 					{
700 700
 						if ($this->db->num_rows($resql))
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 					}
708 708
 					else
709 709
 					{
710
-						$this->error=$this->db->error();
710
+						$this->error = $this->db->error();
711 711
 						return -1;
712 712
 					}
713 713
 				}
@@ -715,21 +715,21 @@  discard block
 block discarded – undo
715 715
 				// Retreive all extrafield for contact
716 716
                 // fetch optionals attributes and labels
717 717
                 require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
718
-                $extrafields=new ExtraFields($this->db);
719
-                $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
720
-               	$this->fetch_optionals($this->id,$extralabels);
718
+                $extrafields = new ExtraFields($this->db);
719
+                $extralabels = $extrafields->fetch_name_optionals_label($this->table_element, true);
720
+               	$this->fetch_optionals($this->id, $extralabels);
721 721
 
722 722
 				return 1;
723 723
 			}
724 724
 			else
725 725
 			{
726
-				$this->error=$langs->trans("RecordNotFound");
726
+				$this->error = $langs->trans("RecordNotFound");
727 727
 				return 0;
728 728
 			}
729 729
 		}
730 730
 		else
731 731
 		{
732
-			$this->error=$this->db->error();
732
+			$this->error = $this->db->error();
733 733
 			return -1;
734 734
 		}
735 735
 	}
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
 	    unset($this->gender);
746 746
     	if (in_array($this->civility_id, array('MR'))) {
747 747
     	    $this->gender = 'man';
748
-    	} else if(in_array($this->civility_id, array('MME','MLE'))) {
748
+    	} else if (in_array($this->civility_id, array('MME', 'MLE'))) {
749 749
     	    $this->gender = 'woman';
750 750
     	}
751 751
 	}
@@ -762,25 +762,25 @@  discard block
 block discarded – undo
762 762
 	function load_ref_elements()
763 763
 	{
764 764
 		// Compte les elements pour lesquels il est contact
765
-		$sql ="SELECT tc.element, count(ec.rowid) as nb";
766
-		$sql.=" FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc";
767
-		$sql.=" WHERE ec.fk_c_type_contact = tc.rowid";
768
-		$sql.=" AND fk_socpeople = ". $this->id;
769
-		$sql.=" GROUP BY tc.element";
765
+		$sql = "SELECT tc.element, count(ec.rowid) as nb";
766
+		$sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc";
767
+		$sql .= " WHERE ec.fk_c_type_contact = tc.rowid";
768
+		$sql .= " AND fk_socpeople = ".$this->id;
769
+		$sql .= " GROUP BY tc.element";
770 770
 
771 771
 		dol_syslog(get_class($this)."::load_ref_elements", LOG_DEBUG);
772 772
 
773
-		$resql=$this->db->query($sql);
773
+		$resql = $this->db->query($sql);
774 774
 		if ($resql)
775 775
 		{
776
-			while($obj=$this->db->fetch_object($resql))
776
+			while ($obj = $this->db->fetch_object($resql))
777 777
 			{
778 778
 				if ($obj->nb)
779 779
 				{
780
-					if ($obj->element=='facture')  $this->ref_facturation = $obj->nb;
781
-					if ($obj->element=='contrat')  $this->ref_contrat = $obj->nb;
782
-					if ($obj->element=='commande') $this->ref_commande = $obj->nb;
783
-					if ($obj->element=='propal')   $this->ref_propal = $obj->nb;
780
+					if ($obj->element == 'facture')  $this->ref_facturation = $obj->nb;
781
+					if ($obj->element == 'contrat')  $this->ref_contrat = $obj->nb;
782
+					if ($obj->element == 'commande') $this->ref_commande = $obj->nb;
783
+					if ($obj->element == 'propal')   $this->ref_propal = $obj->nb;
784 784
 				}
785 785
 			}
786 786
 			$this->db->free($resql);
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 		}
789 789
 		else
790 790
 		{
791
-			$this->error=$this->db->lasterror();
791
+			$this->error = $this->db->lasterror();
792 792
 			return -1;
793 793
 		}
794 794
 	}
@@ -799,45 +799,45 @@  discard block
 block discarded – undo
799 799
 	 *   	@param		int		$notrigger		Disable all trigger
800 800
 	 *		@return		int						<0 if KO, >0 if OK
801 801
 	 */
802
-	function delete($notrigger=0)
802
+	function delete($notrigger = 0)
803 803
 	{
804 804
 		global $conf, $langs, $user;
805 805
 
806
-		$error=0;
806
+		$error = 0;
807 807
 
808 808
 		$this->old_lastname       = $obj->lastname;
809 809
 		$this->old_firstname      = $obj->firstname;
810 810
 
811 811
 		$this->db->begin();
812 812
 
813
-		if (! $error)
813
+		if (!$error)
814 814
 		{
815 815
 			// Get all rowid of element_contact linked to a type that is link to llx_socpeople
816 816
 			$sql = "SELECT ec.rowid";
817
-			$sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
818
-			$sql.= " ".MAIN_DB_PREFIX."c_type_contact tc";
819
-			$sql.= " WHERE ec.fk_socpeople=".$this->id;
820
-			$sql.= " AND ec.fk_c_type_contact=tc.rowid";
821
-			$sql.= " AND tc.source='external'";
817
+			$sql .= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
818
+			$sql .= " ".MAIN_DB_PREFIX."c_type_contact tc";
819
+			$sql .= " WHERE ec.fk_socpeople=".$this->id;
820
+			$sql .= " AND ec.fk_c_type_contact=tc.rowid";
821
+			$sql .= " AND tc.source='external'";
822 822
 			dol_syslog(get_class($this)."::delete", LOG_DEBUG);
823 823
 			$resql = $this->db->query($sql);
824 824
 			if ($resql)
825 825
 			{
826
-				$num=$this->db->num_rows($resql);
826
+				$num = $this->db->num_rows($resql);
827 827
 
828
-				$i=0;
829
-				while ($i < $num && ! $error)
828
+				$i = 0;
829
+				while ($i < $num && !$error)
830 830
 				{
831 831
 					$obj = $this->db->fetch_object($resql);
832 832
 
833 833
 					$sqldel = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
834
-					$sqldel.=" WHERE rowid = ".$obj->rowid;
834
+					$sqldel .= " WHERE rowid = ".$obj->rowid;
835 835
 					dol_syslog(get_class($this)."::delete", LOG_DEBUG);
836 836
 					$result = $this->db->query($sqldel);
837
-					if (! $result)
837
+					if (!$result)
838 838
 					{
839 839
 						$error++;
840
-						$this->error=$this->db->error().' sql='.$sqldel;
840
+						$this->error = $this->db->error().' sql='.$sqldel;
841 841
 					}
842 842
 
843 843
 					$i++;
@@ -846,52 +846,52 @@  discard block
 block discarded – undo
846 846
 			else
847 847
 			{
848 848
 				$error++;
849
-				$this->error=$this->db->error().' sql='.$sql;
849
+				$this->error = $this->db->error().' sql='.$sql;
850 850
 			}
851 851
 		}
852 852
 
853
-		if (! $error)
853
+		if (!$error)
854 854
 		{
855 855
 			// Remove category
856 856
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople = ".$this->id;
857 857
 			dol_syslog(get_class($this)."::delete", LOG_DEBUG);
858
-			$resql=$this->db->query($sql);
859
-			if (! $resql)
858
+			$resql = $this->db->query($sql);
859
+			if (!$resql)
860 860
 			{
861 861
 				$error++;
862 862
 				$this->error .= $this->db->lasterror();
863
-				$errorflag=-1;
863
+				$errorflag = -1;
864 864
 			}
865 865
 		}
866 866
 
867
-		if (! $error)
867
+		if (!$error)
868 868
 		{
869 869
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
870 870
 			$sql .= " WHERE rowid=".$this->id;
871 871
 			dol_syslog(get_class($this)."::delete", LOG_DEBUG);
872 872
 			$result = $this->db->query($sql);
873
-			if (! $result)
873
+			if (!$result)
874 874
 			{
875 875
 				$error++;
876
-				$this->error=$this->db->error().' sql='.$sql;
876
+				$this->error = $this->db->error().' sql='.$sql;
877 877
 			}
878 878
 		}
879 879
 
880 880
 		// Removed extrafields
881
-		 if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) { // For avoid conflicts if trigger used
882
-			$result=$this->deleteExtraFields($this);
881
+		 if ((!$error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) { // For avoid conflicts if trigger used
882
+			$result = $this->deleteExtraFields($this);
883 883
 			if ($result < 0) $error++;
884 884
 		}
885 885
 
886
-		if (! $error && ! $notrigger)
886
+		if (!$error && !$notrigger)
887 887
 		{
888 888
             // Call trigger
889
-            $result=$this->call_trigger('CONTACT_DELETE',$user);
889
+            $result = $this->call_trigger('CONTACT_DELETE', $user);
890 890
             if ($result < 0) { $error++; }
891 891
             // End call triggers
892 892
 		}
893 893
 
894
-		if (! $error)
894
+		if (!$error)
895 895
 		{
896 896
 
897 897
 			$this->db->commit();
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
 		else
901 901
 		{
902 902
 			$this->db->rollback();
903
-			dol_syslog("Error ".$this->error,LOG_ERR);
903
+			dol_syslog("Error ".$this->error, LOG_ERR);
904 904
 			return -1;
905 905
 		}
906 906
 	}
@@ -915,23 +915,23 @@  discard block
 block discarded – undo
915 915
 	function info($id)
916 916
 	{
917 917
 		$sql = "SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
918
-		$sql.= " c.tms as tms, c.fk_user_modif";
919
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
920
-		$sql.= " WHERE c.rowid = ".$this->db->escape($id);
918
+		$sql .= " c.tms as tms, c.fk_user_modif";
919
+		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
920
+		$sql .= " WHERE c.rowid = ".$this->db->escape($id);
921 921
 
922
-		$resql=$this->db->query($sql);
922
+		$resql = $this->db->query($sql);
923 923
 		if ($resql)
924 924
 		{
925 925
 			if ($this->db->num_rows($resql))
926 926
 			{
927 927
 				$obj = $this->db->fetch_object($resql);
928 928
 
929
-				$this->id                = $obj->rowid;
929
+				$this->id = $obj->rowid;
930 930
 
931 931
 				if ($obj->fk_user_creat) {
932 932
 					$cuser = new User($this->db);
933 933
 					$cuser->fetch($obj->fk_user_creat);
934
-					$this->user_creation     = $cuser;
934
+					$this->user_creation = $cuser;
935 935
 				}
936 936
 
937 937
 				if ($obj->fk_user_modif) {
@@ -960,25 +960,25 @@  discard block
 block discarded – undo
960 960
 	function getNbOfEMailings()
961 961
 	{
962 962
 		$sql = "SELECT count(mc.email) as nb";
963
-		$sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
964
-		$sql.= " WHERE mc.email = '".$this->db->escape($this->email)."'";
965
-		$sql.= " AND mc.statut NOT IN (-1,0)";      // -1 erreur, 0 non envoye, 1 envoye avec succes
963
+		$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
964
+		$sql .= " WHERE mc.email = '".$this->db->escape($this->email)."'";
965
+		$sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes
966 966
 
967 967
 		dol_syslog(get_class($this)."::getNbOfEMailings", LOG_DEBUG);
968 968
 
969
-		$resql=$this->db->query($sql);
969
+		$resql = $this->db->query($sql);
970 970
 
971 971
 		if ($resql)
972 972
 		{
973 973
 			$obj = $this->db->fetch_object($resql);
974
-			$nb=$obj->nb;
974
+			$nb = $obj->nb;
975 975
 
976 976
 			$this->db->free($resql);
977 977
 			return $nb;
978 978
 		}
979 979
 		else
980 980
 		{
981
-			$this->error=$this->db->error();
981
+			$this->error = $this->db->error();
982 982
 			return -1;
983 983
 		}
984 984
 	}
@@ -994,67 +994,67 @@  discard block
 block discarded – undo
994 994
      *  @param      int     	$save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
995 995
 	 *	@return		string									String with URL
996 996
 	 */
997
-	function getNomUrl($withpicto=0, $option='', $maxlen=0, $moreparam='', $save_lastsearch_value=-1)
997
+	function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $moreparam = '', $save_lastsearch_value = -1)
998 998
 	{
999 999
 		global $conf, $langs, $hookmanager;
1000 1000
 
1001
-		$result='';
1001
+		$result = '';
1002 1002
 
1003
-        $label = '<u>' . $langs->trans("ShowContact") . '</u>';
1004
-        $label.= '<br><b>' . $langs->trans("Name") . ':</b> '.$this->getFullName($langs);
1003
+        $label = '<u>'.$langs->trans("ShowContact").'</u>';
1004
+        $label .= '<br><b>'.$langs->trans("Name").':</b> '.$this->getFullName($langs);
1005 1005
         //if ($this->civility_id) $label.= '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id;		// TODO Translate cibilty_id code
1006
-        if (! empty($this->poste)) $label.= '<br><b>' . $langs->trans("Poste") . ':</b> '.$this->poste;
1007
-        $label.= '<br><b>' . $langs->trans("EMail") . ':</b> '.$this->email;
1008
-        $phonelist=array();
1009
-        if ($this->phone_pro) $phonelist[]=$this->phone_pro;
1010
-        if ($this->phone_mobile) $phonelist[]=$this->phone_mobile;
1011
-        if ($this->phone_perso) $phonelist[]=$this->phone_perso;
1012
-        $label.= '<br><b>' . $langs->trans("Phone") . ':</b> '.join(', ',$phonelist);
1013
-        $label.= '<br><b>' . $langs->trans("Address") . ':</b> '.dol_format_address($this, 1, ' ', $langs);
1006
+        if (!empty($this->poste)) $label .= '<br><b>'.$langs->trans("Poste").':</b> '.$this->poste;
1007
+        $label .= '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
1008
+        $phonelist = array();
1009
+        if ($this->phone_pro) $phonelist[] = $this->phone_pro;
1010
+        if ($this->phone_mobile) $phonelist[] = $this->phone_mobile;
1011
+        if ($this->phone_perso) $phonelist[] = $this->phone_perso;
1012
+        $label .= '<br><b>'.$langs->trans("Phone").':</b> '.join(', ', $phonelist);
1013
+        $label .= '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs);
1014 1014
 
1015 1015
         $url = DOL_URL_ROOT.'/contact/card.php?id='.$this->id;
1016 1016
 
1017 1017
         if ($option !== 'nolink')
1018 1018
         {
1019 1019
         	// Add param to save lastsearch_values or not
1020
-        	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1021
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1022
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1020
+        	$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1021
+        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
1022
+        	if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
1023 1023
         }
1024 1024
 
1025 1025
         $url .= $moreparam;
1026 1026
 
1027 1027
         $linkstart = '<a href="'.$url.'"';
1028
-        $linkclose="";
1029
-    	if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1028
+        $linkclose = "";
1029
+    	if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1030 1030
         {
1031
-            $label=$langs->trans("ShowContact");
1032
-            $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1031
+            $label = $langs->trans("ShowContact");
1032
+            $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1033 1033
         }
1034
-       	$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1035
-       	$linkclose.= ' class="classfortooltip">';
1034
+       	$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1035
+       	$linkclose .= ' class="classfortooltip">';
1036 1036
 
1037
-		if (! is_object($hookmanager))
1037
+		if (!is_object($hookmanager))
1038 1038
 		{
1039 1039
 			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
1040
-			$hookmanager=new HookManager($this->db);
1040
+			$hookmanager = new HookManager($this->db);
1041 1041
 		}
1042 1042
 		$hookmanager->initHooks(array('contactdao'));
1043
-		$parameters=array('id'=>$this->id);
1044
-		$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1043
+		$parameters = array('id'=>$this->id);
1044
+		$reshook = $hookmanager->executeHooks('getnomurltooltip', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1045 1045
 		if ($reshook > 0) $linkclose = $hookmanager->resPrint;
1046 1046
 
1047
-		$linkstart.=$linkclose;
1048
-		$linkend='</a>';
1047
+		$linkstart .= $linkclose;
1048
+		$linkend = '</a>';
1049 1049
 
1050 1050
 		if ($option == 'xxx')
1051 1051
 		{
1052 1052
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$this->id.$moreparam.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1053
-			$linkend='</a>';
1053
+			$linkend = '</a>';
1054 1054
 		}
1055 1055
 
1056
-	        if ($withpicto) $result.=($linkstart.img_object($label, 'contact', 'class="classfortooltip"').$linkend.' ');
1057
-			$result.=$linkstart.($maxlen?dol_trunc($this->getFullName($langs),$maxlen):$this->getFullName($langs)).$linkend;
1056
+	        if ($withpicto) $result .= ($linkstart.img_object($label, 'contact', 'class="classfortooltip"').$linkend.' ');
1057
+			$result .= $linkstart.($maxlen ?dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs)).$linkend;
1058 1058
 		return $result;
1059 1059
 	}
1060 1060
 
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
 		global $langs;
1069 1069
 		$langs->load("dict");
1070 1070
 
1071
-		$code=(! empty($this->civility_id)?$this->civility_id:(! empty($this->civilite_id)?$this->civilite_id:''));
1071
+		$code = (!empty($this->civility_id) ? $this->civility_id : (!empty($this->civilite_id) ? $this->civilite_id : ''));
1072 1072
 		if (empty($code)) return '';
1073 1073
         return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
1074 1074
 	}
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
 	 */
1082 1082
 	function getLibStatut($mode)
1083 1083
 	{
1084
-		return $this->LibStatut($this->statut,$mode);
1084
+		return $this->LibStatut($this->statut, $mode);
1085 1085
 	}
1086 1086
 
1087 1087
 	/**
@@ -1091,40 +1091,40 @@  discard block
 block discarded – undo
1091 1091
 	 *  @param      int			$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
1092 1092
 	 *  @return     string					Libelle
1093 1093
 	 */
1094
-	function LibStatut($statut,$mode)
1094
+	function LibStatut($statut, $mode)
1095 1095
 	{
1096 1096
 		global $langs;
1097 1097
 
1098 1098
 		if ($mode == 0)
1099 1099
 		{
1100
-			if ($statut==0 || $statut==5) return $langs->trans('Disabled');
1101
-			elseif ($statut==1 || $statut==4) return $langs->trans('Enabled');
1100
+			if ($statut == 0 || $statut == 5) return $langs->trans('Disabled');
1101
+			elseif ($statut == 1 || $statut == 4) return $langs->trans('Enabled');
1102 1102
 		}
1103 1103
 		elseif ($mode == 1)
1104 1104
 		{
1105
-			if ($statut==0 || $statut==5) return $langs->trans('Disabled');
1106
-			elseif ($statut==1 || $statut==4) return $langs->trans('Enabled');
1105
+			if ($statut == 0 || $statut == 5) return $langs->trans('Disabled');
1106
+			elseif ($statut == 1 || $statut == 4) return $langs->trans('Enabled');
1107 1107
 		}
1108 1108
 		elseif ($mode == 2)
1109 1109
 		{
1110
-			if ($statut==0 || $statut==5) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1111
-			elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1110
+			if ($statut == 0 || $statut == 5) return img_picto($langs->trans('Disabled'), 'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1111
+			elseif ($statut == 1 || $statut == 4) return img_picto($langs->trans('Enabled'), 'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1112 1112
 
1113 1113
 		}
1114 1114
 		elseif ($mode == 3)
1115 1115
 		{
1116
-			if ($statut==0 || $statut==5) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"');
1117
-			elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"');
1116
+			if ($statut == 0 || $statut == 5) return img_picto($langs->trans('Disabled'), 'statut5', 'class="pictostatus"');
1117
+			elseif ($statut == 1 || $statut == 4) return img_picto($langs->trans('Enabled'), 'statut4', 'class="pictostatus"');
1118 1118
 		}
1119 1119
 		elseif ($mode == 4)
1120 1120
 		{
1121
-			if ($statut==0) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1122
-			elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1121
+			if ($statut == 0) return img_picto($langs->trans('Disabled'), 'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1122
+			elseif ($statut == 1 || $statut == 4) return img_picto($langs->trans('Enabled'), 'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1123 1123
 		}
1124 1124
 		elseif ($mode == 5)
1125 1125
 		{
1126
-			if ($statut==0 || $statut==5) return '<span class="hideonsmartphone">'.$langs->trans('Disabled').' </span>'.img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"');
1127
-			elseif ($statut==1 || $statut==4) return '<span class="hideonsmartphone">'.$langs->trans('Enabled').' </span>'.img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"');
1126
+			if ($statut == 0 || $statut == 5) return '<span class="hideonsmartphone">'.$langs->trans('Disabled').' </span>'.img_picto($langs->trans('Disabled'), 'statut5', 'class="pictostatus"');
1127
+			elseif ($statut == 1 || $statut == 4) return '<span class="hideonsmartphone">'.$langs->trans('Enabled').' </span>'.img_picto($langs->trans('Enabled'), 'statut4', 'class="pictostatus"');
1128 1128
 		}
1129 1129
 	}
1130 1130
 
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
 	function LibPubPriv($statut)
1139 1139
 	{
1140 1140
 		global $langs;
1141
-		if ($statut=='1') return $langs->trans('ContactPrivate');
1141
+		if ($statut == '1') return $langs->trans('ContactPrivate');
1142 1142
 		else return $langs->trans('ContactPublic');
1143 1143
 	}
1144 1144
 
@@ -1159,12 +1159,12 @@  discard block
 block discarded – undo
1159 1159
 		if ($resql)
1160 1160
 		{
1161 1161
 			$obj = $this->db->fetch_object($resql);
1162
-			if ($obj) $socid=$obj->rowid;
1162
+			if ($obj) $socid = $obj->rowid;
1163 1163
 		}
1164 1164
 
1165 1165
 		// Initialise parameters
1166
-		$this->id=0;
1167
-		$this->specimen=1;
1166
+		$this->id = 0;
1167
+		$this->specimen = 1;
1168 1168
 		$this->lastname = 'DOLIBARR';
1169 1169
 		$this->firstname = 'SPECIMEN';
1170 1170
 		$this->address = '21 jump street';
@@ -1181,11 +1181,11 @@  discard block
 block discarded – undo
1181 1181
 		$this->phone_mobile = '0909090903';
1182 1182
 		$this->fax = '0909090909';
1183 1183
 
1184
-		$this->note_public='This is a comment (public)';
1185
-		$this->note_private='This is a comment (private)';
1184
+		$this->note_public = 'This is a comment (public)';
1185
+		$this->note_private = 'This is a comment (private)';
1186 1186
 
1187 1187
 		$this->socid = $socid;
1188
-		$this->statut=1;
1188
+		$this->statut = 1;
1189 1189
 	}
1190 1190
 
1191 1191
 	/**
@@ -1196,9 +1196,9 @@  discard block
 block discarded – undo
1196 1196
 	 */
1197 1197
 	function setstatus($statut)
1198 1198
 	{
1199
-		global $conf,$langs,$user;
1199
+		global $conf, $langs, $user;
1200 1200
 
1201
-		$error=0;
1201
+		$error = 0;
1202 1202
 
1203 1203
 		// Check parameters
1204 1204
 		if ($this->statut == $statut) return 0;
@@ -1208,15 +1208,15 @@  discard block
 block discarded – undo
1208 1208
 
1209 1209
 		// Desactive utilisateur
1210 1210
 		$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople";
1211
-		$sql.= " SET statut = ".$this->statut;
1212
-		$sql.= " WHERE rowid = ".$this->id;
1211
+		$sql .= " SET statut = ".$this->statut;
1212
+		$sql .= " WHERE rowid = ".$this->id;
1213 1213
 		$result = $this->db->query($sql);
1214 1214
 
1215 1215
 		dol_syslog(get_class($this)."::setstatus", LOG_DEBUG);
1216 1216
 		if ($result)
1217 1217
 		{
1218 1218
             // Call trigger
1219
-            $result=$this->call_trigger('CONTACT_ENABLEDISABLE',$user);
1219
+            $result = $this->call_trigger('CONTACT_ENABLEDISABLE', $user);
1220 1220
             if ($result < 0) { $error++; }
1221 1221
             // End call triggers
1222 1222
 		}
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
 		}
1251 1251
 
1252 1252
 		// Get current categories
1253
-		require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1253
+		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1254 1254
 		$c = new Categorie($this->db);
1255 1255
 		$existing = $c->containing($this->id, Categorie::TYPE_CONTACT, 'id');
1256 1256
 
Please login to merge, or discard this patch.
Braces   +222 added lines, -116 removed lines patch added patch discarded remove patch
@@ -132,7 +132,9 @@  discard block
 block discarded – undo
132 132
 		}
133 133
 		$sql.= ' '.$clause.' sp.entity IN ('.getEntity($this->element, 1).')';
134 134
 		$sql.= " AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat=".$user->id."))";
135
-        if ($user->societe_id > 0) $sql.=" AND sp.fk_soc = ".$user->societe_id;
135
+        if ($user->societe_id > 0) {
136
+        	$sql.=" AND sp.fk_soc = ".$user->societe_id;
137
+        }
136 138
 
137 139
 		$resql=$this->db->query($sql);
138 140
 		if ($resql)
@@ -143,8 +145,7 @@  discard block
 block discarded – undo
143 145
 			}
144 146
 			$this->db->free($resql);
145 147
 			return 1;
146
-		}
147
-		else
148
+		} else
148 149
 		{
149 150
 			dol_print_error($this->db);
150 151
 			$this->error=$this->db->lasterror();
@@ -170,11 +171,22 @@  discard block
 block discarded – undo
170 171
 		// Clean parameters
171 172
 		$this->lastname=$this->lastname?trim($this->lastname):trim($this->name);
172 173
         $this->firstname=trim($this->firstname);
173
-        if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords($this->lastname);
174
-        if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords($this->firstname);
175
-        if (empty($this->socid)) $this->socid = 0;
176
-		if (empty($this->priv)) $this->priv = 0;
177
-		if (empty($this->statut)) $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request
174
+        if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) {
175
+        	$this->lastname=ucwords($this->lastname);
176
+        }
177
+        if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) {
178
+        	$this->firstname=ucwords($this->firstname);
179
+        }
180
+        if (empty($this->socid)) {
181
+        	$this->socid = 0;
182
+        }
183
+		if (empty($this->priv)) {
184
+			$this->priv = 0;
185
+		}
186
+		if (empty($this->statut)) {
187
+			$this->statut = 0;
188
+		}
189
+		// This is to convert '' into '0' to avoid bad sql request
178 190
 
179 191
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (";
180 192
 		$sql.= " datec";
@@ -190,8 +202,11 @@  discard block
 block discarded – undo
190 202
 		$sql.= ", import_key";
191 203
 		$sql.= ") VALUES (";
192 204
 		$sql.= "'".$this->db->idate($now)."',";
193
-		if ($this->socid > 0) $sql.= " ".$this->socid.",";
194
-		else $sql.= "null,";
205
+		if ($this->socid > 0) {
206
+			$sql.= " ".$this->socid.",";
207
+		} else {
208
+			$sql.= "null,";
209
+		}
195 210
 		$sql.= "'".$this->db->escape($this->lastname)."',";
196 211
         $sql.= "'".$this->db->escape($this->firstname)."',";
197 212
 		$sql.= " ".($user->id > 0 ? "'".$user->id."'":"null").",";
@@ -241,15 +256,13 @@  discard block
 block discarded – undo
241 256
             {
242 257
                 $this->db->commit();
243 258
                 return $this->id;
244
-            }
245
-            else
259
+            } else
246 260
             {
247 261
                 $this->db->rollback();
248 262
                 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
249 263
                 return -2;
250 264
             }
251
-		}
252
-		else
265
+		} else
253 266
 		{
254 267
 			$this->error=$this->db->lasterror();
255 268
 
@@ -291,13 +304,18 @@  discard block
 block discarded – undo
291 304
 		$this->town=(empty($this->town)?'':$this->town);
292 305
 		$this->country_id=($this->country_id > 0?$this->country_id:$this->country_id);
293 306
 		$this->state_id=($this->state_id > 0?$this->state_id:$this->fk_departement);
294
-		if (empty($this->statut)) $this->statut = 0;
307
+		if (empty($this->statut)) {
308
+			$this->statut = 0;
309
+		}
295 310
 
296 311
 		$this->db->begin();
297 312
 
298 313
 		$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET ";
299
-		if ($this->socid > 0) $sql .= " fk_soc='".$this->db->escape($this->socid)."',";
300
-		else if ($this->socid == -1) $sql .= " fk_soc=null,";
314
+		if ($this->socid > 0) {
315
+			$sql .= " fk_soc='".$this->db->escape($this->socid)."',";
316
+		} else if ($this->socid == -1) {
317
+			$sql .= " fk_soc=null,";
318
+		}
301 319
 		$sql .= "  civility='".$this->db->escape($this->civility_id)."'";
302 320
 		$sql .= ", lastname='".$this->db->escape($this->lastname)."'";
303 321
 		$sql .= ", firstname='".$this->db->escape($this->firstname)."'";
@@ -341,16 +359,19 @@  discard block
 block discarded – undo
341 359
 		    $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
342 360
 		    if (empty($reshook))
343 361
 		    {
344
-		    	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
362
+		    	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
363
+		    		// For avoid conflicts if trigger used
345 364
 		    	{
346 365
 		    		$result=$this->insertExtraFields();
366
+		    	}
347 367
 		    		if ($result < 0)
348 368
 		    		{
349 369
 		    			$error++;
350 370
 		    		}
351 371
 		    	}
372
+		    } else if ($reshook < 0) {
373
+		    	$error++;
352 374
 		    }
353
-		    else if ($reshook < 0) $error++;
354 375
 
355 376
 			if (! $error && ! $notrigger)
356 377
 			{
@@ -364,15 +385,13 @@  discard block
 block discarded – undo
364 385
 			{
365 386
 				$this->db->commit();
366 387
 				return 1;
367
-			}
368
-			else
388
+			} else
369 389
 			{
370 390
 				dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
371 391
 				$this->db->rollback();
372 392
 				return -$error;
373 393
 			}
374
-		}
375
-		else
394
+		} else
376 395
 		{
377 396
 			$this->error=$this->db->lasterror().' sql='.$sql;
378 397
             $this->db->rollback();
@@ -394,9 +413,15 @@  discard block
 block discarded – undo
394 413
 	{
395 414
 		global $conf;
396 415
 		$dn='';
397
-		if ($mode==0) $dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN;
398
-		if ($mode==1) $dn=$conf->global->LDAP_CONTACT_DN;
399
-		if ($mode==2) $dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS];
416
+		if ($mode==0) {
417
+			$dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN;
418
+		}
419
+		if ($mode==1) {
420
+			$dn=$conf->global->LDAP_CONTACT_DN;
421
+		}
422
+		if ($mode==2) {
423
+			$dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS];
424
+		}
400 425
 		return $dn;
401 426
 	}
402 427
 
@@ -418,32 +443,68 @@  discard block
 block discarded – undo
418 443
 		$this->fullname=$this->getFullName($langs);
419 444
 
420 445
 		// Fields
421
-		if ($this->fullname && ! empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
422
-		if ($this->lastname && ! empty($conf->global->LDAP_CONTACT_FIELD_NAME)) $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
423
-		if ($this->firstname && ! empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
446
+		if ($this->fullname && ! empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) {
447
+			$info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
448
+		}
449
+		if ($this->lastname && ! empty($conf->global->LDAP_CONTACT_FIELD_NAME)) {
450
+			$info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
451
+		}
452
+		if ($this->firstname && ! empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) {
453
+			$info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
454
+		}
424 455
 
425
-		if ($this->poste) $info["title"] = $this->poste;
456
+		if ($this->poste) {
457
+			$info["title"] = $this->poste;
458
+		}
426 459
 		if ($this->socid > 0)
427 460
 		{
428 461
 			$soc = new Societe($this->db);
429 462
 			$soc->fetch($this->socid);
430 463
 
431 464
 			$info[$conf->global->LDAP_CONTACT_FIELD_COMPANY] = $soc->name;
432
-			if ($soc->client == 1)      $info["businessCategory"] = "Customers";
433
-			if ($soc->client == 2)      $info["businessCategory"] = "Prospects";
434
-			if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers";
465
+			if ($soc->client == 1) {
466
+				$info["businessCategory"] = "Customers";
467
+			}
468
+			if ($soc->client == 2) {
469
+				$info["businessCategory"] = "Prospects";
470
+			}
471
+			if ($soc->fournisseur == 1) {
472
+				$info["businessCategory"] = "Suppliers";
473
+			}
474
+		}
475
+		if ($this->address && ! empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) {
476
+			$info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
477
+		}
478
+		if ($this->zip && ! empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) {
479
+			$info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
480
+		}
481
+		if ($this->town && ! empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) {
482
+			$info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
483
+		}
484
+		if ($this->country_code && ! empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) {
485
+			$info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
486
+		}
487
+		if ($this->phone_pro && ! empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) {
488
+			$info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
489
+		}
490
+		if ($this->phone_perso && ! empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) {
491
+			$info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
492
+		}
493
+		if ($this->phone_mobile && ! empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) {
494
+			$info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
495
+		}
496
+		if ($this->fax && ! empty($conf->global->LDAP_CONTACT_FIELD_FAX)) {
497
+			$info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
498
+		}
499
+        if ($this->skype && ! empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) {
500
+        	$info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
501
+        }
502
+		if ($this->note_private && ! empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) {
503
+			$info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = $this->note_private;
504
+		}
505
+		if ($this->email && ! empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) {
506
+			$info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
435 507
 		}
436
-		if ($this->address && ! empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
437
-		if ($this->zip && ! empty($conf->global->LDAP_CONTACT_FIELD_ZIP))          $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
438
-		if ($this->town && ! empty($conf->global->LDAP_CONTACT_FIELD_TOWN))      $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
439
-		if ($this->country_code && ! empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY))      $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
440
-		if ($this->phone_pro && ! empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
441
-		if ($this->phone_perso && ! empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
442
-		if ($this->phone_mobile && ! empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
443
-		if ($this->fax && ! empty($conf->global->LDAP_CONTACT_FIELD_FAX))	    $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
444
-        if ($this->skype && ! empty($conf->global->LDAP_CONTACT_FIELD_SKYPE))	    $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
445
-		if ($this->note_private && ! empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = $this->note_private;
446
-		if ($this->email && ! empty($conf->global->LDAP_CONTACT_FIELD_MAIL))     $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
447 508
 
448 509
 		if ($conf->global->LDAP_SERVER_TYPE == 'egroupware')
449 510
 		{
@@ -466,8 +527,12 @@  discard block
 block discarded – undo
466 527
 
467 528
 			$info["phpgwContactOwner"] = $this->egroupware_id;
468 529
 
469
-			if ($this->email) $info["rfc822Mailbox"] = $this->email;
470
-			if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
530
+			if ($this->email) {
531
+				$info["rfc822Mailbox"] = $this->email;
532
+			}
533
+			if ($this->phone_mobile) {
534
+				$info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
535
+			}
471 536
 		}
472 537
 
473 538
 		return $info;
@@ -493,7 +558,9 @@  discard block
 block discarded – undo
493 558
 		$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
494 559
 		$sql.= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
495 560
 		$sql.= ", photo = ".($this->photo? "'".$this->db->escape($this->photo)."'" : "null");
496
-		if ($user) $sql .= ", fk_user_modif=".$user->id;
561
+		if ($user) {
562
+			$sql .= ", fk_user_modif=".$user->id;
563
+		}
497 564
 		$sql.= " WHERE rowid=".$this->db->escape($id);
498 565
 
499 566
 		dol_syslog(get_class($this)."::update_perso this->birthday=".$this->birthday." -", LOG_DEBUG);
@@ -521,13 +588,11 @@  discard block
 block discarded – undo
521 588
                     $error++;
522 589
                     $this->error=$this->db->lasterror();
523 590
 				}
524
-			}
525
-			else
591
+			} else
526 592
 			{
527 593
 				$result = true;
528 594
 			}
529
-		}
530
-		else
595
+		} else
531 596
 		{
532 597
 			$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_alert ";
533 598
 			$sql.= "WHERE type=1 AND fk_contact=".$this->db->escape($id)." AND fk_user=".$user->id;
@@ -551,8 +616,7 @@  discard block
 block discarded – undo
551 616
 		{
552 617
 		    $this->db->commit();
553 618
 		    return 1;
554
-		}
555
-		else
619
+		} else
556 620
 		{
557 621
 		    dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
558 622
 		    $this->db->rollback();
@@ -601,8 +665,11 @@  discard block
 block discarded – undo
601 665
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
602 666
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
603 667
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
604
-		if ($id) $sql.= " WHERE c.rowid = ". $id;
605
-		elseif ($ref_ext) $sql .= " WHERE c.ref_ext = '".$this->db->escape($ref_ext)."'";
668
+		if ($id) {
669
+			$sql.= " WHERE c.rowid = ". $id;
670
+		} elseif ($ref_ext) {
671
+			$sql .= " WHERE c.ref_ext = '".$this->db->escape($ref_ext)."'";
672
+		}
606 673
 
607 674
 		$resql=$this->db->query($sql);
608 675
 		if ($resql)
@@ -680,8 +747,7 @@  discard block
 block discarded – undo
680 747
 						$this->user_id = $uobj->rowid;
681 748
 					}
682 749
 					$this->db->free($resql);
683
-				}
684
-				else
750
+				} else
685 751
 				{
686 752
 					$this->error=$this->db->error();
687 753
 					return -1;
@@ -704,8 +770,7 @@  discard block
 block discarded – undo
704 770
 							$this->birthday_alert = 1;
705 771
 						}
706 772
 						$this->db->free($resql);
707
-					}
708
-					else
773
+					} else
709 774
 					{
710 775
 						$this->error=$this->db->error();
711 776
 						return -1;
@@ -720,14 +785,12 @@  discard block
 block discarded – undo
720 785
                	$this->fetch_optionals($this->id,$extralabels);
721 786
 
722 787
 				return 1;
723
-			}
724
-			else
788
+			} else
725 789
 			{
726 790
 				$this->error=$langs->trans("RecordNotFound");
727 791
 				return 0;
728 792
 			}
729
-		}
730
-		else
793
+		} else
731 794
 		{
732 795
 			$this->error=$this->db->error();
733 796
 			return -1;
@@ -777,16 +840,23 @@  discard block
 block discarded – undo
777 840
 			{
778 841
 				if ($obj->nb)
779 842
 				{
780
-					if ($obj->element=='facture')  $this->ref_facturation = $obj->nb;
781
-					if ($obj->element=='contrat')  $this->ref_contrat = $obj->nb;
782
-					if ($obj->element=='commande') $this->ref_commande = $obj->nb;
783
-					if ($obj->element=='propal')   $this->ref_propal = $obj->nb;
843
+					if ($obj->element=='facture') {
844
+						$this->ref_facturation = $obj->nb;
845
+					}
846
+					if ($obj->element=='contrat') {
847
+						$this->ref_contrat = $obj->nb;
848
+					}
849
+					if ($obj->element=='commande') {
850
+						$this->ref_commande = $obj->nb;
851
+					}
852
+					if ($obj->element=='propal') {
853
+						$this->ref_propal = $obj->nb;
854
+					}
784 855
 				}
785 856
 			}
786 857
 			$this->db->free($resql);
787 858
 			return 0;
788
-		}
789
-		else
859
+		} else
790 860
 		{
791 861
 			$this->error=$this->db->lasterror();
792 862
 			return -1;
@@ -842,8 +912,7 @@  discard block
 block discarded – undo
842 912
 
843 913
 					$i++;
844 914
 				}
845
-			}
846
-			else
915
+			} else
847 916
 			{
848 917
 				$error++;
849 918
 				$this->error=$this->db->error().' sql='.$sql;
@@ -880,7 +949,9 @@  discard block
 block discarded – undo
880 949
 		// Removed extrafields
881 950
 		 if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) { // For avoid conflicts if trigger used
882 951
 			$result=$this->deleteExtraFields($this);
883
-			if ($result < 0) $error++;
952
+			if ($result < 0) {
953
+				$error++;
954
+			}
884 955
 		}
885 956
 
886 957
 		if (! $error && ! $notrigger)
@@ -896,8 +967,7 @@  discard block
 block discarded – undo
896 967
 
897 968
 			$this->db->commit();
898 969
 			return 1;
899
-		}
900
-		else
970
+		} else
901 971
 		{
902 972
 			$this->db->rollback();
903 973
 			dol_syslog("Error ".$this->error,LOG_ERR);
@@ -945,8 +1015,7 @@  discard block
 block discarded – undo
945 1015
 			}
946 1016
 
947 1017
 			$this->db->free($resql);
948
-		}
949
-		else
1018
+		} else
950 1019
 		{
951 1020
 			print $this->db->error();
952 1021
 		}
@@ -975,8 +1044,7 @@  discard block
 block discarded – undo
975 1044
 
976 1045
 			$this->db->free($resql);
977 1046
 			return $nb;
978
-		}
979
-		else
1047
+		} else
980 1048
 		{
981 1049
 			$this->error=$this->db->error();
982 1050
 			return -1;
@@ -1003,12 +1071,20 @@  discard block
 block discarded – undo
1003 1071
         $label = '<u>' . $langs->trans("ShowContact") . '</u>';
1004 1072
         $label.= '<br><b>' . $langs->trans("Name") . ':</b> '.$this->getFullName($langs);
1005 1073
         //if ($this->civility_id) $label.= '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id;		// TODO Translate cibilty_id code
1006
-        if (! empty($this->poste)) $label.= '<br><b>' . $langs->trans("Poste") . ':</b> '.$this->poste;
1074
+        if (! empty($this->poste)) {
1075
+        	$label.= '<br><b>' . $langs->trans("Poste") . ':</b> '.$this->poste;
1076
+        }
1007 1077
         $label.= '<br><b>' . $langs->trans("EMail") . ':</b> '.$this->email;
1008 1078
         $phonelist=array();
1009
-        if ($this->phone_pro) $phonelist[]=$this->phone_pro;
1010
-        if ($this->phone_mobile) $phonelist[]=$this->phone_mobile;
1011
-        if ($this->phone_perso) $phonelist[]=$this->phone_perso;
1079
+        if ($this->phone_pro) {
1080
+        	$phonelist[]=$this->phone_pro;
1081
+        }
1082
+        if ($this->phone_mobile) {
1083
+        	$phonelist[]=$this->phone_mobile;
1084
+        }
1085
+        if ($this->phone_perso) {
1086
+        	$phonelist[]=$this->phone_perso;
1087
+        }
1012 1088
         $label.= '<br><b>' . $langs->trans("Phone") . ':</b> '.join(', ',$phonelist);
1013 1089
         $label.= '<br><b>' . $langs->trans("Address") . ':</b> '.dol_format_address($this, 1, ' ', $langs);
1014 1090
 
@@ -1018,8 +1094,12 @@  discard block
 block discarded – undo
1018 1094
         {
1019 1095
         	// Add param to save lastsearch_values or not
1020 1096
         	$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1021
-        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1022
-        	if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1097
+        	if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) {
1098
+        		$add_save_lastsearch_values=1;
1099
+        	}
1100
+        	if ($add_save_lastsearch_values) {
1101
+        		$url.='&save_lastsearch_values=1';
1102
+        	}
1023 1103
         }
1024 1104
 
1025 1105
         $url .= $moreparam;
@@ -1042,7 +1122,9 @@  discard block
 block discarded – undo
1042 1122
 		$hookmanager->initHooks(array('contactdao'));
1043 1123
 		$parameters=array('id'=>$this->id);
1044 1124
 		$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
1045
-		if ($reshook > 0) $linkclose = $hookmanager->resPrint;
1125
+		if ($reshook > 0) {
1126
+			$linkclose = $hookmanager->resPrint;
1127
+		}
1046 1128
 
1047 1129
 		$linkstart.=$linkclose;
1048 1130
 		$linkend='</a>';
@@ -1053,7 +1135,9 @@  discard block
 block discarded – undo
1053 1135
 			$linkend='</a>';
1054 1136
 		}
1055 1137
 
1056
-	        if ($withpicto) $result.=($linkstart.img_object($label, 'contact', 'class="classfortooltip"').$linkend.' ');
1138
+	        if ($withpicto) {
1139
+	        	$result.=($linkstart.img_object($label, 'contact', 'class="classfortooltip"').$linkend.' ');
1140
+	        }
1057 1141
 			$result.=$linkstart.($maxlen?dol_trunc($this->getFullName($langs),$maxlen):$this->getFullName($langs)).$linkend;
1058 1142
 		return $result;
1059 1143
 	}
@@ -1069,7 +1153,9 @@  discard block
 block discarded – undo
1069 1153
 		$langs->load("dict");
1070 1154
 
1071 1155
 		$code=(! empty($this->civility_id)?$this->civility_id:(! empty($this->civilite_id)?$this->civilite_id:''));
1072
-		if (empty($code)) return '';
1156
+		if (empty($code)) {
1157
+			return '';
1158
+		}
1073 1159
         return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
1074 1160
 	}
1075 1161
 
@@ -1097,34 +1183,47 @@  discard block
 block discarded – undo
1097 1183
 
1098 1184
 		if ($mode == 0)
1099 1185
 		{
1100
-			if ($statut==0 || $statut==5) return $langs->trans('Disabled');
1101
-			elseif ($statut==1 || $statut==4) return $langs->trans('Enabled');
1102
-		}
1103
-		elseif ($mode == 1)
1186
+			if ($statut==0 || $statut==5) {
1187
+				return $langs->trans('Disabled');
1188
+			} elseif ($statut==1 || $statut==4) {
1189
+				return $langs->trans('Enabled');
1190
+			}
1191
+		} elseif ($mode == 1)
1104 1192
 		{
1105
-			if ($statut==0 || $statut==5) return $langs->trans('Disabled');
1106
-			elseif ($statut==1 || $statut==4) return $langs->trans('Enabled');
1107
-		}
1108
-		elseif ($mode == 2)
1193
+			if ($statut==0 || $statut==5) {
1194
+				return $langs->trans('Disabled');
1195
+			} elseif ($statut==1 || $statut==4) {
1196
+				return $langs->trans('Enabled');
1197
+			}
1198
+		} elseif ($mode == 2)
1109 1199
 		{
1110
-			if ($statut==0 || $statut==5) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1111
-			elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1200
+			if ($statut==0 || $statut==5) {
1201
+				return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1202
+			} elseif ($statut==1 || $statut==4) {
1203
+				return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1204
+			}
1112 1205
 
1113
-		}
1114
-		elseif ($mode == 3)
1206
+		} elseif ($mode == 3)
1115 1207
 		{
1116
-			if ($statut==0 || $statut==5) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"');
1117
-			elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"');
1118
-		}
1119
-		elseif ($mode == 4)
1208
+			if ($statut==0 || $statut==5) {
1209
+				return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"');
1210
+			} elseif ($statut==1 || $statut==4) {
1211
+				return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"');
1212
+			}
1213
+		} elseif ($mode == 4)
1120 1214
 		{
1121
-			if ($statut==0) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1122
-			elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1123
-		}
1124
-		elseif ($mode == 5)
1215
+			if ($statut==0) {
1216
+				return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1217
+			} elseif ($statut==1 || $statut==4) {
1218
+				return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1219
+			}
1220
+		} elseif ($mode == 5)
1125 1221
 		{
1126
-			if ($statut==0 || $statut==5) return '<span class="hideonsmartphone">'.$langs->trans('Disabled').' </span>'.img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"');
1127
-			elseif ($statut==1 || $statut==4) return '<span class="hideonsmartphone">'.$langs->trans('Enabled').' </span>'.img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"');
1222
+			if ($statut==0 || $statut==5) {
1223
+				return '<span class="hideonsmartphone">'.$langs->trans('Disabled').' </span>'.img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"');
1224
+			} elseif ($statut==1 || $statut==4) {
1225
+				return '<span class="hideonsmartphone">'.$langs->trans('Enabled').' </span>'.img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"');
1226
+			}
1128 1227
 		}
1129 1228
 	}
1130 1229
 
@@ -1138,8 +1237,11 @@  discard block
 block discarded – undo
1138 1237
 	function LibPubPriv($statut)
1139 1238
 	{
1140 1239
 		global $langs;
1141
-		if ($statut=='1') return $langs->trans('ContactPrivate');
1142
-		else return $langs->trans('ContactPublic');
1240
+		if ($statut=='1') {
1241
+			return $langs->trans('ContactPrivate');
1242
+		} else {
1243
+			return $langs->trans('ContactPublic');
1244
+		}
1143 1245
 	}
1144 1246
 
1145 1247
 
@@ -1159,7 +1261,9 @@  discard block
 block discarded – undo
1159 1261
 		if ($resql)
1160 1262
 		{
1161 1263
 			$obj = $this->db->fetch_object($resql);
1162
-			if ($obj) $socid=$obj->rowid;
1264
+			if ($obj) {
1265
+				$socid=$obj->rowid;
1266
+			}
1163 1267
 		}
1164 1268
 
1165 1269
 		// Initialise parameters
@@ -1201,8 +1305,11 @@  discard block
 block discarded – undo
1201 1305
 		$error=0;
1202 1306
 
1203 1307
 		// Check parameters
1204
-		if ($this->statut == $statut) return 0;
1205
-		else $this->statut = $statut;
1308
+		if ($this->statut == $statut) {
1309
+			return 0;
1310
+		} else {
1311
+			$this->statut = $statut;
1312
+		}
1206 1313
 
1207 1314
 		$this->db->begin();
1208 1315
 
@@ -1225,8 +1332,7 @@  discard block
 block discarded – undo
1225 1332
 		{
1226 1333
 			$this->db->rollback();
1227 1334
 			return -$error;
1228
-		}
1229
-		else
1335
+		} else
1230 1336
 		{
1231 1337
 			$this->db->commit();
1232 1338
 			return 1;
Please login to merge, or discard this patch.
htdocs/commande/class/api_deprecated_commande.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@
 block discarded – undo
102 102
      * @param int		$limit		Limit for list
103 103
      * @param int		$page		Page number
104 104
      * @param int		$mode		Use this param to filter list
105
-     * @param string	$societe	Thirdparty filter field
105
+     * @param integer	$societe	Thirdparty filter field
106 106
      *
107 107
      * @url     GET     /order/list
108 108
      * @return  array   Array of order objects
Please login to merge, or discard this patch.
Indentation   +437 added lines, -437 removed lines patch added patch discarded remove patch
@@ -34,506 +34,506 @@
 block discarded – undo
34 34
 class CommandeApi extends DolibarrApi
35 35
 {
36 36
 
37
-    /**
38
-     * @var array   $FIELDS     Mandatory fields, checked when create and update object
39
-     */
40
-    static $FIELDS = array(
41
-        'socid'
42
-    );
43
-
44
-    /**
45
-     * @var Commande $commande {@type Commande}
46
-     */
47
-    public $commande;
48
-
49
-    /**
50
-     * Constructor <b>Warning: Deprecated</b>
51
-     *
52
-     * @url     GET order/
53
-     *
54
-     */
55
-    function __construct()
56
-    {
37
+	/**
38
+	 * @var array   $FIELDS     Mandatory fields, checked when create and update object
39
+	 */
40
+	static $FIELDS = array(
41
+		'socid'
42
+	);
43
+
44
+	/**
45
+	 * @var Commande $commande {@type Commande}
46
+	 */
47
+	public $commande;
48
+
49
+	/**
50
+	 * Constructor <b>Warning: Deprecated</b>
51
+	 *
52
+	 * @url     GET order/
53
+	 *
54
+	 */
55
+	function __construct()
56
+	{
57 57
 		global $db, $conf;
58 58
 		$this->db = $db;
59
-        $this->commande = new Commande($this->db);
60
-    }
61
-
62
-    /**
63
-     * Get properties of a commande object <b>Warning: Deprecated</b>
64
-     *
65
-     * Return an array with commande informations
66
-     *
67
-     * @param       int         $id         ID of order
68
-     * @param		string		$ref		Ref of object
69
-     * @param		string		$ref_ext		External reference of object
70
-     * @param		string		$ref_int		Internal reference of other object
71
-     * @return 	array|mixed data without useless information
72
-	 *
73
-     * @url	GET order/{id}
74
-     * @throws 	RestException
75
-     */
76
-    function get($id='',$ref='', $ref_ext='', $ref_int='')
77
-    {
59
+		$this->commande = new Commande($this->db);
60
+	}
61
+
62
+	/**
63
+	 * Get properties of a commande object <b>Warning: Deprecated</b>
64
+	 *
65
+	 * Return an array with commande informations
66
+	 *
67
+	 * @param       int         $id         ID of order
68
+	 * @param		string		$ref		Ref of object
69
+	 * @param		string		$ref_ext		External reference of object
70
+	 * @param		string		$ref_int		Internal reference of other object
71
+	 * @return 	array|mixed data without useless information
72
+	 *
73
+	 * @url	GET order/{id}
74
+	 * @throws 	RestException
75
+	 */
76
+	function get($id='',$ref='', $ref_ext='', $ref_int='')
77
+	{
78 78
 		if(! DolibarrApiAccess::$user->rights->commande->lire) {
79 79
 			throw new RestException(401);
80 80
 		}
81 81
 
82
-        $result = $this->commande->fetch($id);
83
-        if( ! $result ) {
84
-            throw new RestException(404, 'Order not found');
85
-        }
82
+		$result = $this->commande->fetch($id);
83
+		if( ! $result ) {
84
+			throw new RestException(404, 'Order not found');
85
+		}
86 86
 
87 87
 		if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
88 88
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
89 89
 		}
90 90
 
91
-        $this->commande->fetchObjectLinked();
91
+		$this->commande->fetchObjectLinked();
92 92
 		return $this->_cleanObjectDatas($this->commande);
93
-    }
94
-
95
-    /**
96
-     * List orders <b>Warning: Deprecated</b>
97
-     *
98
-     * Get a list of orders
99
-     *
100
-     * @param string	$sortfield	Sort field
101
-     * @param string	$sortorder	Sort order
102
-     * @param int		$limit		Limit for list
103
-     * @param int		$page		Page number
104
-     * @param int		$mode		Use this param to filter list
105
-     * @param string	$societe	Thirdparty filter field
106
-     *
107
-     * @url     GET     /order/list
108
-     * @return  array   Array of order objects
109
-     */
110
-    function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $societe = 0) {
111
-        global $db, $conf;
112
-
113
-        $obj_ret = array();
114
-        // case of external user, $societe param is ignored and replaced by user's socid
115
-        $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe;
116
-
117
-        // If the internal user must only see his customers, force searching by him
118
-        $search_sale = 0;
119
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
120
-
121
-        $sql = "SELECT s.rowid";
122
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
123
-        $sql.= " FROM ".MAIN_DB_PREFIX."commande as s";
124
-
125
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
93
+	}
94
+
95
+	/**
96
+	 * List orders <b>Warning: Deprecated</b>
97
+	 *
98
+	 * Get a list of orders
99
+	 *
100
+	 * @param string	$sortfield	Sort field
101
+	 * @param string	$sortorder	Sort order
102
+	 * @param int		$limit		Limit for list
103
+	 * @param int		$page		Page number
104
+	 * @param int		$mode		Use this param to filter list
105
+	 * @param string	$societe	Thirdparty filter field
106
+	 *
107
+	 * @url     GET     /order/list
108
+	 * @return  array   Array of order objects
109
+	 */
110
+	function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $societe = 0) {
111
+		global $db, $conf;
112
+
113
+		$obj_ret = array();
114
+		// case of external user, $societe param is ignored and replaced by user's socid
115
+		$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe;
116
+
117
+		// If the internal user must only see his customers, force searching by him
118
+		$search_sale = 0;
119
+		if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
120
+
121
+		$sql = "SELECT s.rowid";
122
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
123
+		$sql.= " FROM ".MAIN_DB_PREFIX."commande as s";
124
+
125
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
126 126
 
127 127
 		// Example of use $mode
128
-        //if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
129
-        //if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
130
-
131
-        $sql.= ' WHERE s.entity IN ('.getEntity('commande').')';
132
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc";
133
-        if ($socid) $sql.= " AND s.fk_soc = ".$socid;
134
-        if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
135
-
136
-        // Insert sale filter
137
-        if ($search_sale > 0)
138
-        {
139
-            $sql .= " AND sc.fk_user = ".$search_sale;
140
-        }
141
-
142
-        $nbtotalofrecords = '';
143
-        if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
144
-        {
145
-            $result = $db->query($sql);
146
-            $nbtotalofrecords = $db->num_rows($result);
147
-        }
148
-
149
-        $sql.= $db->order($sortfield, $sortorder);
150
-        if ($limit)	{
151
-            if ($page < 0)
152
-            {
153
-                $page = 0;
154
-            }
155
-            $offset = $limit * $page;
156
-
157
-            $sql.= $db->plimit($limit + 1, $offset);
158
-        }
159
-
160
-        $result = $db->query($sql);
161
-
162
-        if ($result)
163
-        {
164
-        	$i=0;
165
-            $num = $db->num_rows($result);
166
-            $min = min($num, ($limit <= 0 ? $num : $limit));
167
-            while ($i < $min)
168
-            {
169
-                $obj = $db->fetch_object($result);
170
-                $commande_static = new Commande($db);
171
-                if($commande_static->fetch($obj->rowid)) {
172
-                    $obj_ret[] = $this->_cleanObjectDatas($commande_static);
173
-                }
174
-                $i++;
175
-            }
176
-        }
177
-        else {
178
-            throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror());
179
-        }
180
-        if( ! count($obj_ret)) {
181
-            throw new RestException(404, 'No commande found');
182
-        }
128
+		//if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
129
+		//if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
130
+
131
+		$sql.= ' WHERE s.entity IN ('.getEntity('commande').')';
132
+		if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc";
133
+		if ($socid) $sql.= " AND s.fk_soc = ".$socid;
134
+		if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
135
+
136
+		// Insert sale filter
137
+		if ($search_sale > 0)
138
+		{
139
+			$sql .= " AND sc.fk_user = ".$search_sale;
140
+		}
141
+
142
+		$nbtotalofrecords = '';
143
+		if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
144
+		{
145
+			$result = $db->query($sql);
146
+			$nbtotalofrecords = $db->num_rows($result);
147
+		}
148
+
149
+		$sql.= $db->order($sortfield, $sortorder);
150
+		if ($limit)	{
151
+			if ($page < 0)
152
+			{
153
+				$page = 0;
154
+			}
155
+			$offset = $limit * $page;
156
+
157
+			$sql.= $db->plimit($limit + 1, $offset);
158
+		}
159
+
160
+		$result = $db->query($sql);
161
+
162
+		if ($result)
163
+		{
164
+			$i=0;
165
+			$num = $db->num_rows($result);
166
+			$min = min($num, ($limit <= 0 ? $num : $limit));
167
+			while ($i < $min)
168
+			{
169
+				$obj = $db->fetch_object($result);
170
+				$commande_static = new Commande($db);
171
+				if($commande_static->fetch($obj->rowid)) {
172
+					$obj_ret[] = $this->_cleanObjectDatas($commande_static);
173
+				}
174
+				$i++;
175
+			}
176
+		}
177
+		else {
178
+			throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror());
179
+		}
180
+		if( ! count($obj_ret)) {
181
+			throw new RestException(404, 'No commande found');
182
+		}
183 183
 		return $obj_ret;
184
-    }
185
-
186
-    /**
187
-     * List orders for specific thirdparty <b>Warning: Deprecated</b>
188
-     *
189
-     * Get a list of orders
190
-     *
191
-     * @param int	$socid Id of customer
192
-     *
193
-     * @url     GET     /customer/{socid}/order/list
194
-     * @url     GET     /thirdparty/{socid}/order/list
195
-     * @return  array   Array of order objects
196
-     */
197
-    function getListForSoc($socid = 0) {
198
-      return $this->getList(0,"s.rowid","ASC",0,0,$socid);
199
-    }
200
-
201
-
202
-    /**
203
-     * Create order object <b>Warning: Deprecated</b>
204
-     *
205
-     * @param   array   $request_data   Request datas
206
-     *
207
-     * @url     POST    order/
208
-     *
209
-     * @return  int     ID of commande
210
-     */
211
-    function post($request_data = NULL)
212
-    {
213
-      if(! DolibarrApiAccess::$user->rights->commande->creer) {
184
+	}
185
+
186
+	/**
187
+	 * List orders for specific thirdparty <b>Warning: Deprecated</b>
188
+	 *
189
+	 * Get a list of orders
190
+	 *
191
+	 * @param int	$socid Id of customer
192
+	 *
193
+	 * @url     GET     /customer/{socid}/order/list
194
+	 * @url     GET     /thirdparty/{socid}/order/list
195
+	 * @return  array   Array of order objects
196
+	 */
197
+	function getListForSoc($socid = 0) {
198
+	  return $this->getList(0,"s.rowid","ASC",0,0,$socid);
199
+	}
200
+
201
+
202
+	/**
203
+	 * Create order object <b>Warning: Deprecated</b>
204
+	 *
205
+	 * @param   array   $request_data   Request datas
206
+	 *
207
+	 * @url     POST    order/
208
+	 *
209
+	 * @return  int     ID of commande
210
+	 */
211
+	function post($request_data = NULL)
212
+	{
213
+	  if(! DolibarrApiAccess::$user->rights->commande->creer) {
214 214
 			  throw new RestException(401, "Insuffisant rights");
215 215
 		  }
216
-        // Check mandatory fields
217
-        $result = $this->_validate($request_data);
218
-
219
-        foreach($request_data as $field => $value) {
220
-            $this->commande->$field = $value;
221
-        }
222
-        if (isset($request_data["lines"])) {
223
-          $lines = array();
224
-          foreach ($request_data["lines"] as $line) {
225
-            array_push($lines, (object) $line);
226
-          }
227
-          $this->commande->lines = $lines;
228
-        }
229
-        if(! $this->commande->create(DolibarrApiAccess::$user) ) {
230
-            throw new RestException(500, "Error while creating order");
231
-        }
232
-
233
-        return $this->commande->id;
234
-    }
235
-    /**
236
-     * Get lines of an order <b>Warning: Deprecated</b>
237
-     *
238
-     *
239
-     * @param int   $id             Id of order
240
-     *
241
-     * @url	GET order/{id}/line/list
242
-     *
243
-     * @return int
244
-     */
245
-    function getLines($id) {
246
-      if(! DolibarrApiAccess::$user->rights->commande->lire) {
216
+		// Check mandatory fields
217
+		$result = $this->_validate($request_data);
218
+
219
+		foreach($request_data as $field => $value) {
220
+			$this->commande->$field = $value;
221
+		}
222
+		if (isset($request_data["lines"])) {
223
+		  $lines = array();
224
+		  foreach ($request_data["lines"] as $line) {
225
+			array_push($lines, (object) $line);
226
+		  }
227
+		  $this->commande->lines = $lines;
228
+		}
229
+		if(! $this->commande->create(DolibarrApiAccess::$user) ) {
230
+			throw new RestException(500, "Error while creating order");
231
+		}
232
+
233
+		return $this->commande->id;
234
+	}
235
+	/**
236
+	 * Get lines of an order <b>Warning: Deprecated</b>
237
+	 *
238
+	 *
239
+	 * @param int   $id             Id of order
240
+	 *
241
+	 * @url	GET order/{id}/line/list
242
+	 *
243
+	 * @return int
244
+	 */
245
+	function getLines($id) {
246
+	  if(! DolibarrApiAccess::$user->rights->commande->lire) {
247 247
 		  	throw new RestException(401);
248 248
 		  }
249 249
 
250
-      $result = $this->commande->fetch($id);
251
-      if( ! $result ) {
252
-         throw new RestException(404, 'Commande not found');
253
-      }
250
+	  $result = $this->commande->fetch($id);
251
+	  if( ! $result ) {
252
+		 throw new RestException(404, 'Commande not found');
253
+	  }
254 254
 
255 255
 		  if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
256 256
 			  throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
257
-      }
258
-      $this->commande->getLinesArray();
259
-      $result = array();
260
-      foreach ($this->commande->lines as $line) {
261
-        array_push($result,$this->_cleanObjectDatas($line));
262
-      }
263
-      return $result;
264
-    }
265
-    /**
266
-     * Add a line to given order <b>Warning: Deprecated</b>
267
-     *
268
-     *
269
-     * @param int   $id             Id of commande to update
270
-     * @param array $request_data   Orderline data
271
-     *
272
-     * @url	POST order/{id}/line
273
-     *
274
-     * @return int
275
-     */
276
-    function postLine($id, $request_data = NULL) {
277
-      if(! DolibarrApiAccess::$user->rights->commande->creer) {
257
+	  }
258
+	  $this->commande->getLinesArray();
259
+	  $result = array();
260
+	  foreach ($this->commande->lines as $line) {
261
+		array_push($result,$this->_cleanObjectDatas($line));
262
+	  }
263
+	  return $result;
264
+	}
265
+	/**
266
+	 * Add a line to given order <b>Warning: Deprecated</b>
267
+	 *
268
+	 *
269
+	 * @param int   $id             Id of commande to update
270
+	 * @param array $request_data   Orderline data
271
+	 *
272
+	 * @url	POST order/{id}/line
273
+	 *
274
+	 * @return int
275
+	 */
276
+	function postLine($id, $request_data = NULL) {
277
+	  if(! DolibarrApiAccess::$user->rights->commande->creer) {
278 278
 		  	throw new RestException(401);
279 279
 		  }
280 280
 
281
-      $result = $this->commande->fetch($id);
282
-      if( ! $result ) {
283
-         throw new RestException(404, 'Commande not found');
284
-      }
281
+	  $result = $this->commande->fetch($id);
282
+	  if( ! $result ) {
283
+		 throw new RestException(404, 'Commande not found');
284
+	  }
285 285
 
286 286
 		  if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
287 287
 			  throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
288
-      }
288
+	  }
289 289
 			$request_data = (object) $request_data;
290
-      $updateRes = $this->commande->addline(
291
-                        $request_data->desc,
292
-                        $request_data->subprice,
293
-                        $request_data->qty,
294
-                        $request_data->tva_tx,
295
-                        $request_data->localtax1_tx,
296
-                        $request_data->localtax2_tx,
297
-                        $request_data->fk_product,
298
-                        $request_data->remise_percent,
299
-                        $request_data->info_bits,
300
-                        $request_data->fk_remise_except,
301
-                        'HT',
302
-                        0,
303
-                        $request_data->date_start,
304
-                        $request_data->date_end,
305
-                        $request_data->product_type,
306
-                        $request_data->rang,
307
-                        $request_data->special_code,
308
-                        $fk_parent_line,
309
-                        $request_data->fk_fournprice,
310
-                        $request_data->pa_ht,
311
-                        $request_data->label,
312
-                        $request_data->array_options,
313
-                        $request_data->fk_unit,
314
-                        $this->element,
315
-                        $request_data->id
316
-      );
317
-
318
-      if ($updateRes > 0) {
319
-        return $this->get($id)->line->rowid;
320
-
321
-      }
322
-      return false;
323
-    }
324
-    /**
325
-     * Update a line to given order <b>Warning: Deprecated</b>
326
-     *
327
-     *
328
-     * @param int   $id             Id of commande to update
329
-     * @param int   $lineid         Id of line to update
330
-     * @param array $request_data   Orderline data
331
-     *
332
-     * @url	PUT order/{id}/line/{lineid}
333
-     *
334
-     * @return object
335
-     */
336
-    function putLine($id, $lineid, $request_data = NULL) {
337
-      if(! DolibarrApiAccess::$user->rights->commande->creer) {
290
+	  $updateRes = $this->commande->addline(
291
+						$request_data->desc,
292
+						$request_data->subprice,
293
+						$request_data->qty,
294
+						$request_data->tva_tx,
295
+						$request_data->localtax1_tx,
296
+						$request_data->localtax2_tx,
297
+						$request_data->fk_product,
298
+						$request_data->remise_percent,
299
+						$request_data->info_bits,
300
+						$request_data->fk_remise_except,
301
+						'HT',
302
+						0,
303
+						$request_data->date_start,
304
+						$request_data->date_end,
305
+						$request_data->product_type,
306
+						$request_data->rang,
307
+						$request_data->special_code,
308
+						$fk_parent_line,
309
+						$request_data->fk_fournprice,
310
+						$request_data->pa_ht,
311
+						$request_data->label,
312
+						$request_data->array_options,
313
+						$request_data->fk_unit,
314
+						$this->element,
315
+						$request_data->id
316
+	  );
317
+
318
+	  if ($updateRes > 0) {
319
+		return $this->get($id)->line->rowid;
320
+
321
+	  }
322
+	  return false;
323
+	}
324
+	/**
325
+	 * Update a line to given order <b>Warning: Deprecated</b>
326
+	 *
327
+	 *
328
+	 * @param int   $id             Id of commande to update
329
+	 * @param int   $lineid         Id of line to update
330
+	 * @param array $request_data   Orderline data
331
+	 *
332
+	 * @url	PUT order/{id}/line/{lineid}
333
+	 *
334
+	 * @return object
335
+	 */
336
+	function putLine($id, $lineid, $request_data = NULL) {
337
+	  if(! DolibarrApiAccess::$user->rights->commande->creer) {
338 338
 		  	throw new RestException(401);
339 339
 		  }
340 340
 
341
-      $result = $this->commande->fetch($id);
342
-      if( ! $result ) {
343
-         throw new RestException(404, 'Commande not found');
344
-      }
341
+	  $result = $this->commande->fetch($id);
342
+	  if( ! $result ) {
343
+		 throw new RestException(404, 'Commande not found');
344
+	  }
345 345
 
346 346
 		  if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
347 347
 			  throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
348
-      }
348
+	  }
349 349
 			$request_data = (object) $request_data;
350
-      $updateRes = $this->commande->updateline(
351
-                        $lineid,
352
-                        $request_data->desc,
353
-                        $request_data->subprice,
354
-                        $request_data->qty,
355
-                        $request_data->remise_percent,
356
-                        $request_data->tva_tx,
357
-                        $request_data->localtax1_tx,
358
-                        $request_data->localtax2_tx,
359
-                        'HT',
360
-                        $request_data->info_bits,
361
-                        $request_data->date_start,
362
-                        $request_data->date_end,
363
-                        $request_data->product_type,
364
-                        $request_data->fk_parent_line,
365
-                        0,
366
-                        $request_data->fk_fournprice,
367
-                        $request_data->pa_ht,
368
-                        $request_data->label,
369
-                        $request_data->special_code,
370
-                        $request_data->array_options,
371
-                        $request_data->fk_unit
372
-      );
373
-
374
-      if ($updateRes > 0) {
375
-        $result = $this->get($id);
376
-        unset($result->line);
377
-        return $this->_cleanObjectDatas($result);
378
-      }
379
-      return false;
380
-    }
381
-    /**
382
-     * Delete a line to given order <b>Warning: Deprecated</b>
383
-     *
384
-     *
385
-     * @param int   $id             Id of commande to update
386
-     * @param int   $lineid         Id of line to delete
387
-     *
388
-     * @url	DELETE order/{id}/line/{lineid}
389
-     *
390
-     * @return int
391
-     */
392
-    function delLine($id, $lineid) {
393
-      if(! DolibarrApiAccess::$user->rights->commande->creer) {
350
+	  $updateRes = $this->commande->updateline(
351
+						$lineid,
352
+						$request_data->desc,
353
+						$request_data->subprice,
354
+						$request_data->qty,
355
+						$request_data->remise_percent,
356
+						$request_data->tva_tx,
357
+						$request_data->localtax1_tx,
358
+						$request_data->localtax2_tx,
359
+						'HT',
360
+						$request_data->info_bits,
361
+						$request_data->date_start,
362
+						$request_data->date_end,
363
+						$request_data->product_type,
364
+						$request_data->fk_parent_line,
365
+						0,
366
+						$request_data->fk_fournprice,
367
+						$request_data->pa_ht,
368
+						$request_data->label,
369
+						$request_data->special_code,
370
+						$request_data->array_options,
371
+						$request_data->fk_unit
372
+	  );
373
+
374
+	  if ($updateRes > 0) {
375
+		$result = $this->get($id);
376
+		unset($result->line);
377
+		return $this->_cleanObjectDatas($result);
378
+	  }
379
+	  return false;
380
+	}
381
+	/**
382
+	 * Delete a line to given order <b>Warning: Deprecated</b>
383
+	 *
384
+	 *
385
+	 * @param int   $id             Id of commande to update
386
+	 * @param int   $lineid         Id of line to delete
387
+	 *
388
+	 * @url	DELETE order/{id}/line/{lineid}
389
+	 *
390
+	 * @return int
391
+	 */
392
+	function delLine($id, $lineid) {
393
+	  if(! DolibarrApiAccess::$user->rights->commande->creer) {
394 394
 		  	throw new RestException(401);
395 395
 		  }
396 396
 
397
-      $result = $this->commande->fetch($id);
398
-      if( ! $result ) {
399
-         throw new RestException(404, 'Commande not found');
400
-      }
397
+	  $result = $this->commande->fetch($id);
398
+	  if( ! $result ) {
399
+		 throw new RestException(404, 'Commande not found');
400
+	  }
401 401
 
402 402
 		  if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
403 403
 			  throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
404
-      }
404
+	  }
405 405
 			$request_data = (object) $request_data;
406
-      $updateRes = $this->commande->deleteline(DolibarrApiAccess::$user,$lineid);
407
-      if ($updateRes == 1) {
408
-        return $this->get($id);
409
-      }
410
-      return false;
411
-    }
412
-
413
-    /**
414
-     * Update order general fields (won't touch lines of order) <b>Warning: Deprecated</b>
415
-     *
416
-     * @param int   $id             Id of commande to update
417
-     * @param array $request_data   Datas
418
-     *
419
-     * @url	PUT order/{id}
420
-     *
421
-     * @return int
422
-     */
423
-    function put($id, $request_data = NULL) {
424
-      if(! DolibarrApiAccess::$user->rights->commande->creer) {
406
+	  $updateRes = $this->commande->deleteline(DolibarrApiAccess::$user,$lineid);
407
+	  if ($updateRes == 1) {
408
+		return $this->get($id);
409
+	  }
410
+	  return false;
411
+	}
412
+
413
+	/**
414
+	 * Update order general fields (won't touch lines of order) <b>Warning: Deprecated</b>
415
+	 *
416
+	 * @param int   $id             Id of commande to update
417
+	 * @param array $request_data   Datas
418
+	 *
419
+	 * @url	PUT order/{id}
420
+	 *
421
+	 * @return int
422
+	 */
423
+	function put($id, $request_data = NULL) {
424
+	  if(! DolibarrApiAccess::$user->rights->commande->creer) {
425 425
 		  	throw new RestException(401);
426 426
 		  }
427 427
 
428
-        $result = $this->commande->fetch($id);
429
-        if( ! $result ) {
430
-            throw new RestException(404, 'Commande not found');
431
-        }
428
+		$result = $this->commande->fetch($id);
429
+		if( ! $result ) {
430
+			throw new RestException(404, 'Commande not found');
431
+		}
432 432
 
433 433
 		if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
434 434
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
435 435
 		}
436
-        foreach($request_data as $field => $value) {
437
-            if ($field == 'id') continue;
438
-            $this->commande->$field = $value;
439
-        }
440
-
441
-        if($this->commande->update($id, DolibarrApiAccess::$user,1,'','','update'))
442
-            return $this->get($id);
443
-
444
-        return false;
445
-    }
446
-
447
-    /**
448
-     * Delete order <b>Warning: Deprecated</b>
449
-     *
450
-     * @param   int     $id         Order ID
451
-     *
452
-     * @url     DELETE  order/{id}
453
-     *
454
-     * @return  array
455
-     */
456
-    function delete($id)
457
-    {
458
-        if(! DolibarrApiAccess::$user->rights->commande->supprimer) {
436
+		foreach($request_data as $field => $value) {
437
+			if ($field == 'id') continue;
438
+			$this->commande->$field = $value;
439
+		}
440
+
441
+		if($this->commande->update($id, DolibarrApiAccess::$user,1,'','','update'))
442
+			return $this->get($id);
443
+
444
+		return false;
445
+	}
446
+
447
+	/**
448
+	 * Delete order <b>Warning: Deprecated</b>
449
+	 *
450
+	 * @param   int     $id         Order ID
451
+	 *
452
+	 * @url     DELETE  order/{id}
453
+	 *
454
+	 * @return  array
455
+	 */
456
+	function delete($id)
457
+	{
458
+		if(! DolibarrApiAccess::$user->rights->commande->supprimer) {
459 459
 			throw new RestException(401);
460 460
 		}
461
-        $result = $this->commande->fetch($id);
462
-        if( ! $result ) {
463
-            throw new RestException(404, 'Order not found');
464
-        }
461
+		$result = $this->commande->fetch($id);
462
+		if( ! $result ) {
463
+			throw new RestException(404, 'Order not found');
464
+		}
465 465
 
466 466
 		if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
467 467
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
468 468
 		}
469 469
 
470
-        if( ! $this->commande->delete(DolibarrApiAccess::$user)) {
471
-            throw new RestException(500, 'Error when delete order : '.$this->commande->error);
472
-        }
473
-
474
-        return array(
475
-            'success' => array(
476
-                'code' => 200,
477
-                'message' => 'Order deleted'
478
-            )
479
-        );
480
-
481
-    }
482
-
483
-    /**
484
-     * Validate an order <b>Warning: Deprecated</b>
485
-     *
486
-     * @param   int $id             Order ID
487
-     * @param   int $idwarehouse    Warehouse ID
488
-     *
489
-     * @url GET     order/{id}/validate
490
-     * @url POST    order/{id}/validate
491
-     *
492
-     * @return  array
493
-     *
494
-     */
495
-    function validOrder($id, $idwarehouse=0)
496
-    {
497
-        if(! DolibarrApiAccess::$user->rights->commande->creer) {
470
+		if( ! $this->commande->delete(DolibarrApiAccess::$user)) {
471
+			throw new RestException(500, 'Error when delete order : '.$this->commande->error);
472
+		}
473
+
474
+		return array(
475
+			'success' => array(
476
+				'code' => 200,
477
+				'message' => 'Order deleted'
478
+			)
479
+		);
480
+
481
+	}
482
+
483
+	/**
484
+	 * Validate an order <b>Warning: Deprecated</b>
485
+	 *
486
+	 * @param   int $id             Order ID
487
+	 * @param   int $idwarehouse    Warehouse ID
488
+	 *
489
+	 * @url GET     order/{id}/validate
490
+	 * @url POST    order/{id}/validate
491
+	 *
492
+	 * @return  array
493
+	 *
494
+	 */
495
+	function validOrder($id, $idwarehouse=0)
496
+	{
497
+		if(! DolibarrApiAccess::$user->rights->commande->creer) {
498 498
 			throw new RestException(401);
499 499
 		}
500
-        $result = $this->commande->fetch($id);
501
-        if( ! $result ) {
502
-            throw new RestException(404, 'Order not found');
503
-        }
500
+		$result = $this->commande->fetch($id);
501
+		if( ! $result ) {
502
+			throw new RestException(404, 'Order not found');
503
+		}
504 504
 
505 505
 		if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
506 506
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
507 507
 		}
508 508
 
509
-        if( ! $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse)) {
510
-            throw new RestException(500, 'Error when validate order');
511
-        }
512
-
513
-        return array(
514
-            'success' => array(
515
-                'code' => 200,
516
-                'message' => 'Order validated'
517
-            )
518
-        );
519
-    }
520
-
521
-    /**
522
-     * Validate fields before create or update object
523
-     *
524
-     * @param   array           $data   Array with data to verify
525
-     * @return  array
526
-     * @throws  RestException
527
-     */
528
-    function _validate($data)
529
-    {
530
-        $commande = array();
531
-        foreach (CommandeApi::$FIELDS as $field) {
532
-            if (!isset($data[$field]))
533
-                throw new RestException(400, "$field field missing");
534
-            $commande[$field] = $data[$field];
535
-
536
-        }
537
-        return $commande;
538
-    }
509
+		if( ! $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse)) {
510
+			throw new RestException(500, 'Error when validate order');
511
+		}
512
+
513
+		return array(
514
+			'success' => array(
515
+				'code' => 200,
516
+				'message' => 'Order validated'
517
+			)
518
+		);
519
+	}
520
+
521
+	/**
522
+	 * Validate fields before create or update object
523
+	 *
524
+	 * @param   array           $data   Array with data to verify
525
+	 * @return  array
526
+	 * @throws  RestException
527
+	 */
528
+	function _validate($data)
529
+	{
530
+		$commande = array();
531
+		foreach (CommandeApi::$FIELDS as $field) {
532
+			if (!isset($data[$field]))
533
+				throw new RestException(400, "$field field missing");
534
+			$commande[$field] = $data[$field];
535
+
536
+		}
537
+		return $commande;
538
+	}
539 539
 }
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -73,18 +73,18 @@  discard block
 block discarded – undo
73 73
      * @url	GET order/{id}
74 74
      * @throws 	RestException
75 75
      */
76
-    function get($id='',$ref='', $ref_ext='', $ref_int='')
76
+    function get($id = '', $ref = '', $ref_ext = '', $ref_int = '')
77 77
     {
78
-		if(! DolibarrApiAccess::$user->rights->commande->lire) {
78
+		if (!DolibarrApiAccess::$user->rights->commande->lire) {
79 79
 			throw new RestException(401);
80 80
 		}
81 81
 
82 82
         $result = $this->commande->fetch($id);
83
-        if( ! $result ) {
83
+        if (!$result) {
84 84
             throw new RestException(404, 'Order not found');
85 85
         }
86 86
 
87
-		if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
87
+		if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
88 88
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
89 89
 		}
90 90
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      * @url     GET     /order/list
108 108
      * @return  array   Array of order objects
109 109
      */
110
-    function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $societe = 0) {
110
+    function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode = 0, $societe = 0) {
111 111
         global $db, $conf;
112 112
 
113 113
         $obj_ret = array();
@@ -116,22 +116,22 @@  discard block
 block discarded – undo
116 116
 
117 117
         // If the internal user must only see his customers, force searching by him
118 118
         $search_sale = 0;
119
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
119
+        if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
120 120
 
121 121
         $sql = "SELECT s.rowid";
122 122
         if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
123
-        $sql.= " FROM ".MAIN_DB_PREFIX."commande as s";
123
+        $sql .= " FROM ".MAIN_DB_PREFIX."commande as s";
124 124
 
125
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
125
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
126 126
 
127 127
 		// Example of use $mode
128 128
         //if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
129 129
         //if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
130 130
 
131
-        $sql.= ' WHERE s.entity IN ('.getEntity('commande').')';
132
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc";
133
-        if ($socid) $sql.= " AND s.fk_soc = ".$socid;
134
-        if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
131
+        $sql .= ' WHERE s.entity IN ('.getEntity('commande').')';
132
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= " AND s.fk_soc = sc.fk_soc";
133
+        if ($socid) $sql .= " AND s.fk_soc = ".$socid;
134
+        if ($search_sale > 0) $sql .= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
135 135
 
136 136
         // Insert sale filter
137 137
         if ($search_sale > 0)
@@ -146,29 +146,29 @@  discard block
 block discarded – undo
146 146
             $nbtotalofrecords = $db->num_rows($result);
147 147
         }
148 148
 
149
-        $sql.= $db->order($sortfield, $sortorder);
150
-        if ($limit)	{
149
+        $sql .= $db->order($sortfield, $sortorder);
150
+        if ($limit) {
151 151
             if ($page < 0)
152 152
             {
153 153
                 $page = 0;
154 154
             }
155 155
             $offset = $limit * $page;
156 156
 
157
-            $sql.= $db->plimit($limit + 1, $offset);
157
+            $sql .= $db->plimit($limit + 1, $offset);
158 158
         }
159 159
 
160 160
         $result = $db->query($sql);
161 161
 
162 162
         if ($result)
163 163
         {
164
-        	$i=0;
164
+        	$i = 0;
165 165
             $num = $db->num_rows($result);
166 166
             $min = min($num, ($limit <= 0 ? $num : $limit));
167 167
             while ($i < $min)
168 168
             {
169 169
                 $obj = $db->fetch_object($result);
170 170
                 $commande_static = new Commande($db);
171
-                if($commande_static->fetch($obj->rowid)) {
171
+                if ($commande_static->fetch($obj->rowid)) {
172 172
                     $obj_ret[] = $this->_cleanObjectDatas($commande_static);
173 173
                 }
174 174
                 $i++;
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
         else {
178 178
             throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror());
179 179
         }
180
-        if( ! count($obj_ret)) {
180
+        if (!count($obj_ret)) {
181 181
             throw new RestException(404, 'No commande found');
182 182
         }
183 183
 		return $obj_ret;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      * @return  array   Array of order objects
196 196
      */
197 197
     function getListForSoc($socid = 0) {
198
-      return $this->getList(0,"s.rowid","ASC",0,0,$socid);
198
+      return $this->getList(0, "s.rowid", "ASC", 0, 0, $socid);
199 199
     }
200 200
 
201 201
 
@@ -210,13 +210,13 @@  discard block
 block discarded – undo
210 210
      */
211 211
     function post($request_data = NULL)
212 212
     {
213
-      if(! DolibarrApiAccess::$user->rights->commande->creer) {
213
+      if (!DolibarrApiAccess::$user->rights->commande->creer) {
214 214
 			  throw new RestException(401, "Insuffisant rights");
215 215
 		  }
216 216
         // Check mandatory fields
217 217
         $result = $this->_validate($request_data);
218 218
 
219
-        foreach($request_data as $field => $value) {
219
+        foreach ($request_data as $field => $value) {
220 220
             $this->commande->$field = $value;
221 221
         }
222 222
         if (isset($request_data["lines"])) {
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
           }
227 227
           $this->commande->lines = $lines;
228 228
         }
229
-        if(! $this->commande->create(DolibarrApiAccess::$user) ) {
229
+        if (!$this->commande->create(DolibarrApiAccess::$user)) {
230 230
             throw new RestException(500, "Error while creating order");
231 231
         }
232 232
 
@@ -243,22 +243,22 @@  discard block
 block discarded – undo
243 243
      * @return int
244 244
      */
245 245
     function getLines($id) {
246
-      if(! DolibarrApiAccess::$user->rights->commande->lire) {
246
+      if (!DolibarrApiAccess::$user->rights->commande->lire) {
247 247
 		  	throw new RestException(401);
248 248
 		  }
249 249
 
250 250
       $result = $this->commande->fetch($id);
251
-      if( ! $result ) {
251
+      if (!$result) {
252 252
          throw new RestException(404, 'Commande not found');
253 253
       }
254 254
 
255
-		  if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
255
+		  if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
256 256
 			  throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
257 257
       }
258 258
       $this->commande->getLinesArray();
259 259
       $result = array();
260 260
       foreach ($this->commande->lines as $line) {
261
-        array_push($result,$this->_cleanObjectDatas($line));
261
+        array_push($result, $this->_cleanObjectDatas($line));
262 262
       }
263 263
       return $result;
264 264
     }
@@ -274,16 +274,16 @@  discard block
 block discarded – undo
274 274
      * @return int
275 275
      */
276 276
     function postLine($id, $request_data = NULL) {
277
-      if(! DolibarrApiAccess::$user->rights->commande->creer) {
277
+      if (!DolibarrApiAccess::$user->rights->commande->creer) {
278 278
 		  	throw new RestException(401);
279 279
 		  }
280 280
 
281 281
       $result = $this->commande->fetch($id);
282
-      if( ! $result ) {
282
+      if (!$result) {
283 283
          throw new RestException(404, 'Commande not found');
284 284
       }
285 285
 
286
-		  if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
286
+		  if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
287 287
 			  throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
288 288
       }
289 289
 			$request_data = (object) $request_data;
@@ -334,16 +334,16 @@  discard block
 block discarded – undo
334 334
      * @return object
335 335
      */
336 336
     function putLine($id, $lineid, $request_data = NULL) {
337
-      if(! DolibarrApiAccess::$user->rights->commande->creer) {
337
+      if (!DolibarrApiAccess::$user->rights->commande->creer) {
338 338
 		  	throw new RestException(401);
339 339
 		  }
340 340
 
341 341
       $result = $this->commande->fetch($id);
342
-      if( ! $result ) {
342
+      if (!$result) {
343 343
          throw new RestException(404, 'Commande not found');
344 344
       }
345 345
 
346
-		  if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
346
+		  if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
347 347
 			  throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
348 348
       }
349 349
 			$request_data = (object) $request_data;
@@ -390,20 +390,20 @@  discard block
 block discarded – undo
390 390
      * @return int
391 391
      */
392 392
     function delLine($id, $lineid) {
393
-      if(! DolibarrApiAccess::$user->rights->commande->creer) {
393
+      if (!DolibarrApiAccess::$user->rights->commande->creer) {
394 394
 		  	throw new RestException(401);
395 395
 		  }
396 396
 
397 397
       $result = $this->commande->fetch($id);
398
-      if( ! $result ) {
398
+      if (!$result) {
399 399
          throw new RestException(404, 'Commande not found');
400 400
       }
401 401
 
402
-		  if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
402
+		  if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
403 403
 			  throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
404 404
       }
405 405
 			$request_data = (object) $request_data;
406
-      $updateRes = $this->commande->deleteline(DolibarrApiAccess::$user,$lineid);
406
+      $updateRes = $this->commande->deleteline(DolibarrApiAccess::$user, $lineid);
407 407
       if ($updateRes == 1) {
408 408
         return $this->get($id);
409 409
       }
@@ -421,24 +421,24 @@  discard block
 block discarded – undo
421 421
      * @return int
422 422
      */
423 423
     function put($id, $request_data = NULL) {
424
-      if(! DolibarrApiAccess::$user->rights->commande->creer) {
424
+      if (!DolibarrApiAccess::$user->rights->commande->creer) {
425 425
 		  	throw new RestException(401);
426 426
 		  }
427 427
 
428 428
         $result = $this->commande->fetch($id);
429
-        if( ! $result ) {
429
+        if (!$result) {
430 430
             throw new RestException(404, 'Commande not found');
431 431
         }
432 432
 
433
-		if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
433
+		if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
434 434
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
435 435
 		}
436
-        foreach($request_data as $field => $value) {
436
+        foreach ($request_data as $field => $value) {
437 437
             if ($field == 'id') continue;
438 438
             $this->commande->$field = $value;
439 439
         }
440 440
 
441
-        if($this->commande->update($id, DolibarrApiAccess::$user,1,'','','update'))
441
+        if ($this->commande->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
442 442
             return $this->get($id);
443 443
 
444 444
         return false;
@@ -455,19 +455,19 @@  discard block
 block discarded – undo
455 455
      */
456 456
     function delete($id)
457 457
     {
458
-        if(! DolibarrApiAccess::$user->rights->commande->supprimer) {
458
+        if (!DolibarrApiAccess::$user->rights->commande->supprimer) {
459 459
 			throw new RestException(401);
460 460
 		}
461 461
         $result = $this->commande->fetch($id);
462
-        if( ! $result ) {
462
+        if (!$result) {
463 463
             throw new RestException(404, 'Order not found');
464 464
         }
465 465
 
466
-		if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
466
+		if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
467 467
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
468 468
 		}
469 469
 
470
-        if( ! $this->commande->delete(DolibarrApiAccess::$user)) {
470
+        if (!$this->commande->delete(DolibarrApiAccess::$user)) {
471 471
             throw new RestException(500, 'Error when delete order : '.$this->commande->error);
472 472
         }
473 473
 
@@ -492,21 +492,21 @@  discard block
 block discarded – undo
492 492
      * @return  array
493 493
      *
494 494
      */
495
-    function validOrder($id, $idwarehouse=0)
495
+    function validOrder($id, $idwarehouse = 0)
496 496
     {
497
-        if(! DolibarrApiAccess::$user->rights->commande->creer) {
497
+        if (!DolibarrApiAccess::$user->rights->commande->creer) {
498 498
 			throw new RestException(401);
499 499
 		}
500 500
         $result = $this->commande->fetch($id);
501
-        if( ! $result ) {
501
+        if (!$result) {
502 502
             throw new RestException(404, 'Order not found');
503 503
         }
504 504
 
505
-		if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
505
+		if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
506 506
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
507 507
 		}
508 508
 
509
-        if( ! $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse)) {
509
+        if (!$this->commande->valid(DolibarrApiAccess::$user, $idwarehouse)) {
510 510
             throw new RestException(500, 'Error when validate order');
511 511
         }
512 512
 
Please login to merge, or discard this patch.
Braces   +31 added lines, -13 removed lines patch added patch discarded remove patch
@@ -116,22 +116,37 @@  discard block
 block discarded – undo
116 116
 
117 117
         // If the internal user must only see his customers, force searching by him
118 118
         $search_sale = 0;
119
-        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
119
+        if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
120
+        	$search_sale = DolibarrApiAccess::$user->id;
121
+        }
120 122
 
121 123
         $sql = "SELECT s.rowid";
122
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
124
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
125
+        	$sql .= ", sc.fk_soc, sc.fk_user";
126
+        }
127
+        // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
123 128
         $sql.= " FROM ".MAIN_DB_PREFIX."commande as s";
124 129
 
125
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
130
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
131
+        	$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
132
+        }
133
+        // We need this table joined to the select in order to filter by sale
126 134
 
127 135
 		// Example of use $mode
128 136
         //if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
129 137
         //if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
130 138
 
131 139
         $sql.= ' WHERE s.entity IN ('.getEntity('commande').')';
132
-        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc";
133
-        if ($socid) $sql.= " AND s.fk_soc = ".$socid;
134
-        if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc";		// Join for the needed table to filter by sale
140
+        if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
141
+        	$sql.= " AND s.fk_soc = sc.fk_soc";
142
+        }
143
+        if ($socid) {
144
+        	$sql.= " AND s.fk_soc = ".$socid;
145
+        }
146
+        if ($search_sale > 0) {
147
+        	$sql.= " AND s.rowid = sc.fk_soc";
148
+        }
149
+        // Join for the needed table to filter by sale
135 150
 
136 151
         // Insert sale filter
137 152
         if ($search_sale > 0)
@@ -173,8 +188,7 @@  discard block
 block discarded – undo
173 188
                 }
174 189
                 $i++;
175 190
             }
176
-        }
177
-        else {
191
+        } else {
178 192
             throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror());
179 193
         }
180 194
         if( ! count($obj_ret)) {
@@ -434,12 +448,15 @@  discard block
 block discarded – undo
434 448
 			throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
435 449
 		}
436 450
         foreach($request_data as $field => $value) {
437
-            if ($field == 'id') continue;
451
+            if ($field == 'id') {
452
+            	continue;
453
+            }
438 454
             $this->commande->$field = $value;
439 455
         }
440 456
 
441
-        if($this->commande->update($id, DolibarrApiAccess::$user,1,'','','update'))
442
-            return $this->get($id);
457
+        if($this->commande->update($id, DolibarrApiAccess::$user,1,'','','update')) {
458
+                    return $this->get($id);
459
+        }
443 460
 
444 461
         return false;
445 462
     }
@@ -529,8 +546,9 @@  discard block
 block discarded – undo
529 546
     {
530 547
         $commande = array();
531 548
         foreach (CommandeApi::$FIELDS as $field) {
532
-            if (!isset($data[$field]))
533
-                throw new RestException(400, "$field field missing");
549
+            if (!isset($data[$field])) {
550
+                            throw new RestException(400, "$field field missing");
551
+            }
534 552
             $commande[$field] = $data[$field];
535 553
 
536 554
         }
Please login to merge, or discard this patch.