@@ -31,110 +31,110 @@ |
||
31 | 31 | */ |
32 | 32 | function __construct() |
33 | 33 | { |
34 | - global $db; |
|
35 | - $this->db = $db; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Login |
|
40 | - * |
|
41 | - * Request the API token for a couple username / password. |
|
42 | - * Using method POST is recommanded for security reasons (method GET is often logged by default by web servers with parameters so with login and pass into server log file). |
|
43 | - * Both methods are provided for developer conveniance. Best is to not use at all the login API method and enter directly the "DOLAPIKEY" into field at the top right of page. Note: The API key (DOLAPIKEY) can be found/set on the user page. |
|
44 | - * |
|
45 | - * @param string $login User login |
|
46 | - * @param string $password User password |
|
47 | - * @param string $entity Entity (when multicompany module is used). '' means 1=first company. |
|
48 | - * @param int $reset Reset token (0=get current token, 1=ask a new token and canceled old token. This means access using current existing API token of user will fails: new token will be required for new access) |
|
34 | + global $db; |
|
35 | + $this->db = $db; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Login |
|
40 | + * |
|
41 | + * Request the API token for a couple username / password. |
|
42 | + * Using method POST is recommanded for security reasons (method GET is often logged by default by web servers with parameters so with login and pass into server log file). |
|
43 | + * Both methods are provided for developer conveniance. Best is to not use at all the login API method and enter directly the "DOLAPIKEY" into field at the top right of page. Note: The API key (DOLAPIKEY) can be found/set on the user page. |
|
44 | + * |
|
45 | + * @param string $login User login |
|
46 | + * @param string $password User password |
|
47 | + * @param string $entity Entity (when multicompany module is used). '' means 1=first company. |
|
48 | + * @param int $reset Reset token (0=get current token, 1=ask a new token and canceled old token. This means access using current existing API token of user will fails: new token will be required for new access) |
|
49 | 49 | * @return array Response status and user token |
50 | 50 | * |
51 | - * @throws 200 |
|
52 | - * @throws 403 |
|
53 | - * @throws 500 |
|
54 | - * |
|
55 | - * @url GET / |
|
56 | - * @url POST / |
|
57 | - */ |
|
51 | + * @throws 200 |
|
52 | + * @throws 403 |
|
53 | + * @throws 500 |
|
54 | + * |
|
55 | + * @url GET / |
|
56 | + * @url POST / |
|
57 | + */ |
|
58 | 58 | public function index($login, $password, $entity='', $reset=0) |
59 | 59 | { |
60 | 60 | |
61 | - global $conf, $dolibarr_main_authentication, $dolibarr_auto_user; |
|
62 | - |
|
63 | - // Authentication mode |
|
64 | - if (empty($dolibarr_main_authentication)) |
|
65 | - $dolibarr_main_authentication = 'http,dolibarr'; |
|
66 | - // Authentication mode: forceuser |
|
67 | - if ($dolibarr_main_authentication == 'forceuser') |
|
68 | - { |
|
69 | - if (empty($dolibarr_auto_user)) $dolibarr_auto_user='auto'; |
|
70 | - if ($dolibarr_auto_user != $login) |
|
71 | - { |
|
72 | - dol_syslog("Warning: your instance is set to use the automatic forced login '".$dolibarr_auto_user."' that is not the requested login. API usage is forbidden in this mode."); |
|
73 | - throw new RestException(403, "Your instance is set to use the automatic login '".$dolibarr_auto_user."' that is not the requested login. API usage is forbidden in this mode."); |
|
74 | - } |
|
75 | - } |
|
76 | - // Set authmode |
|
77 | - $authmode = explode(',', $dolibarr_main_authentication); |
|
78 | - |
|
79 | - if ($entity != '' && ! is_numeric($entity)) |
|
80 | - { |
|
81 | - throw new RestException(403, "Bad value for entity, must be the numeric ID of company."); |
|
82 | - } |
|
83 | - if ($entity == '') $entity=1; |
|
84 | - |
|
85 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php'; |
|
86 | - $login = checkLoginPassEntity($login, $password, $entity, $authmode); |
|
87 | - if (empty($login)) |
|
88 | - { |
|
89 | - throw new RestException(403, 'Access denied'); |
|
90 | - } |
|
91 | - |
|
92 | - $token = 'failedtogenerateorgettoken'; |
|
93 | - |
|
94 | - $tmpuser=new User($this->db); |
|
95 | - $tmpuser->fetch(0, $login, 0, 0, $entity); |
|
96 | - if (empty($tmpuser->id)) |
|
97 | - { |
|
98 | - throw new RestException(500, 'Failed to load user'); |
|
99 | - } |
|
100 | - |
|
101 | - // Renew the hash |
|
102 | - if (empty($tmpuser->api_key) || $reset) |
|
103 | - { |
|
104 | - $tmpuser->getrights(); |
|
105 | - if (empty($tmpuser->rights->user->self->creer)) |
|
106 | - { |
|
107 | - throw new RestException(403, 'User need write permission on itself to reset its API token'); |
|
108 | - } |
|
109 | - |
|
110 | - // Generate token for user |
|
111 | - $token = dol_hash($login.uniqid().$conf->global->MAIN_API_KEY,1); |
|
112 | - |
|
113 | - // We store API token into database |
|
114 | - $sql = "UPDATE ".MAIN_DB_PREFIX."user"; |
|
115 | - $sql.= " SET api_key = '".$this->db->escape($token)."'"; |
|
116 | - $sql.= " WHERE login = '".$this->db->escape($login)."'"; |
|
117 | - |
|
118 | - dol_syslog(get_class($this)."::login", LOG_DEBUG); // No log |
|
119 | - $result = $this->db->query($sql); |
|
120 | - if (!$result) |
|
121 | - { |
|
122 | - throw new RestException(500, 'Error when updating api_key for user :'.$this->db->lasterror()); |
|
123 | - } |
|
124 | - } |
|
125 | - else |
|
126 | - { |
|
61 | + global $conf, $dolibarr_main_authentication, $dolibarr_auto_user; |
|
62 | + |
|
63 | + // Authentication mode |
|
64 | + if (empty($dolibarr_main_authentication)) |
|
65 | + $dolibarr_main_authentication = 'http,dolibarr'; |
|
66 | + // Authentication mode: forceuser |
|
67 | + if ($dolibarr_main_authentication == 'forceuser') |
|
68 | + { |
|
69 | + if (empty($dolibarr_auto_user)) $dolibarr_auto_user='auto'; |
|
70 | + if ($dolibarr_auto_user != $login) |
|
71 | + { |
|
72 | + dol_syslog("Warning: your instance is set to use the automatic forced login '".$dolibarr_auto_user."' that is not the requested login. API usage is forbidden in this mode."); |
|
73 | + throw new RestException(403, "Your instance is set to use the automatic login '".$dolibarr_auto_user."' that is not the requested login. API usage is forbidden in this mode."); |
|
74 | + } |
|
75 | + } |
|
76 | + // Set authmode |
|
77 | + $authmode = explode(',', $dolibarr_main_authentication); |
|
78 | + |
|
79 | + if ($entity != '' && ! is_numeric($entity)) |
|
80 | + { |
|
81 | + throw new RestException(403, "Bad value for entity, must be the numeric ID of company."); |
|
82 | + } |
|
83 | + if ($entity == '') $entity=1; |
|
84 | + |
|
85 | + include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php'; |
|
86 | + $login = checkLoginPassEntity($login, $password, $entity, $authmode); |
|
87 | + if (empty($login)) |
|
88 | + { |
|
89 | + throw new RestException(403, 'Access denied'); |
|
90 | + } |
|
91 | + |
|
92 | + $token = 'failedtogenerateorgettoken'; |
|
93 | + |
|
94 | + $tmpuser=new User($this->db); |
|
95 | + $tmpuser->fetch(0, $login, 0, 0, $entity); |
|
96 | + if (empty($tmpuser->id)) |
|
97 | + { |
|
98 | + throw new RestException(500, 'Failed to load user'); |
|
99 | + } |
|
100 | + |
|
101 | + // Renew the hash |
|
102 | + if (empty($tmpuser->api_key) || $reset) |
|
103 | + { |
|
104 | + $tmpuser->getrights(); |
|
105 | + if (empty($tmpuser->rights->user->self->creer)) |
|
106 | + { |
|
107 | + throw new RestException(403, 'User need write permission on itself to reset its API token'); |
|
108 | + } |
|
109 | + |
|
110 | + // Generate token for user |
|
111 | + $token = dol_hash($login.uniqid().$conf->global->MAIN_API_KEY,1); |
|
112 | + |
|
113 | + // We store API token into database |
|
114 | + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; |
|
115 | + $sql.= " SET api_key = '".$this->db->escape($token)."'"; |
|
116 | + $sql.= " WHERE login = '".$this->db->escape($login)."'"; |
|
117 | + |
|
118 | + dol_syslog(get_class($this)."::login", LOG_DEBUG); // No log |
|
119 | + $result = $this->db->query($sql); |
|
120 | + if (!$result) |
|
121 | + { |
|
122 | + throw new RestException(500, 'Error when updating api_key for user :'.$this->db->lasterror()); |
|
123 | + } |
|
124 | + } |
|
125 | + else |
|
126 | + { |
|
127 | 127 | $token = $tmpuser->api_key; |
128 | - } |
|
129 | - |
|
130 | - //return token |
|
131 | - return array( |
|
132 | - 'success' => array( |
|
133 | - 'code' => 200, |
|
134 | - 'token' => $token, |
|
135 | - 'entity' => $tmpuser->entity, |
|
136 | - 'message' => 'Welcome ' . $login.($reset?' - Token is new':' - This is your token (generated by a previous call). You can use it to make any REST API call, or enter it into the DOLAPIKEY field to use the Dolibarr API explorer.') |
|
137 | - ) |
|
138 | - ); |
|
139 | - } |
|
128 | + } |
|
129 | + |
|
130 | + //return token |
|
131 | + return array( |
|
132 | + 'success' => array( |
|
133 | + 'code' => 200, |
|
134 | + 'token' => $token, |
|
135 | + 'entity' => $tmpuser->entity, |
|
136 | + 'message' => 'Welcome ' . $login.($reset?' - Token is new':' - This is your token (generated by a previous call). You can use it to make any REST API call, or enter it into the DOLAPIKEY field to use the Dolibarr API explorer.') |
|
137 | + ) |
|
138 | + ); |
|
139 | + } |
|
140 | 140 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @url GET / |
56 | 56 | * @url POST / |
57 | 57 | */ |
58 | - public function index($login, $password, $entity='', $reset=0) |
|
58 | + public function index($login, $password, $entity = '', $reset = 0) |
|
59 | 59 | { |
60 | 60 | |
61 | 61 | global $conf, $dolibarr_main_authentication, $dolibarr_auto_user; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | // Authentication mode: forceuser |
67 | 67 | if ($dolibarr_main_authentication == 'forceuser') |
68 | 68 | { |
69 | - if (empty($dolibarr_auto_user)) $dolibarr_auto_user='auto'; |
|
69 | + if (empty($dolibarr_auto_user)) $dolibarr_auto_user = 'auto'; |
|
70 | 70 | if ($dolibarr_auto_user != $login) |
71 | 71 | { |
72 | 72 | dol_syslog("Warning: your instance is set to use the automatic forced login '".$dolibarr_auto_user."' that is not the requested login. API usage is forbidden in this mode."); |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | // Set authmode |
77 | 77 | $authmode = explode(',', $dolibarr_main_authentication); |
78 | 78 | |
79 | - if ($entity != '' && ! is_numeric($entity)) |
|
79 | + if ($entity != '' && !is_numeric($entity)) |
|
80 | 80 | { |
81 | 81 | throw new RestException(403, "Bad value for entity, must be the numeric ID of company."); |
82 | 82 | } |
83 | - if ($entity == '') $entity=1; |
|
83 | + if ($entity == '') $entity = 1; |
|
84 | 84 | |
85 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php'; |
|
85 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
86 | 86 | $login = checkLoginPassEntity($login, $password, $entity, $authmode); |
87 | 87 | if (empty($login)) |
88 | 88 | { |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | $token = 'failedtogenerateorgettoken'; |
93 | 93 | |
94 | - $tmpuser=new User($this->db); |
|
94 | + $tmpuser = new User($this->db); |
|
95 | 95 | $tmpuser->fetch(0, $login, 0, 0, $entity); |
96 | 96 | if (empty($tmpuser->id)) |
97 | 97 | { |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | // Generate token for user |
111 | - $token = dol_hash($login.uniqid().$conf->global->MAIN_API_KEY,1); |
|
111 | + $token = dol_hash($login.uniqid().$conf->global->MAIN_API_KEY, 1); |
|
112 | 112 | |
113 | 113 | // We store API token into database |
114 | 114 | $sql = "UPDATE ".MAIN_DB_PREFIX."user"; |
115 | - $sql.= " SET api_key = '".$this->db->escape($token)."'"; |
|
116 | - $sql.= " WHERE login = '".$this->db->escape($login)."'"; |
|
115 | + $sql .= " SET api_key = '".$this->db->escape($token)."'"; |
|
116 | + $sql .= " WHERE login = '".$this->db->escape($login)."'"; |
|
117 | 117 | |
118 | - dol_syslog(get_class($this)."::login", LOG_DEBUG); // No log |
|
118 | + dol_syslog(get_class($this)."::login", LOG_DEBUG); // No log |
|
119 | 119 | $result = $this->db->query($sql); |
120 | 120 | if (!$result) |
121 | 121 | { |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | 'code' => 200, |
134 | 134 | 'token' => $token, |
135 | 135 | 'entity' => $tmpuser->entity, |
136 | - 'message' => 'Welcome ' . $login.($reset?' - Token is new':' - This is your token (generated by a previous call). You can use it to make any REST API call, or enter it into the DOLAPIKEY field to use the Dolibarr API explorer.') |
|
136 | + 'message' => 'Welcome '.$login.($reset ? ' - Token is new' : ' - This is your token (generated by a previous call). You can use it to make any REST API call, or enter it into the DOLAPIKEY field to use the Dolibarr API explorer.') |
|
137 | 137 | ) |
138 | 138 | ); |
139 | 139 | } |
@@ -61,12 +61,15 @@ discard block |
||
61 | 61 | global $conf, $dolibarr_main_authentication, $dolibarr_auto_user; |
62 | 62 | |
63 | 63 | // Authentication mode |
64 | - if (empty($dolibarr_main_authentication)) |
|
65 | - $dolibarr_main_authentication = 'http,dolibarr'; |
|
64 | + if (empty($dolibarr_main_authentication)) { |
|
65 | + $dolibarr_main_authentication = 'http,dolibarr'; |
|
66 | + } |
|
66 | 67 | // Authentication mode: forceuser |
67 | 68 | if ($dolibarr_main_authentication == 'forceuser') |
68 | 69 | { |
69 | - if (empty($dolibarr_auto_user)) $dolibarr_auto_user='auto'; |
|
70 | + if (empty($dolibarr_auto_user)) { |
|
71 | + $dolibarr_auto_user='auto'; |
|
72 | + } |
|
70 | 73 | if ($dolibarr_auto_user != $login) |
71 | 74 | { |
72 | 75 | dol_syslog("Warning: your instance is set to use the automatic forced login '".$dolibarr_auto_user."' that is not the requested login. API usage is forbidden in this mode."); |
@@ -80,7 +83,9 @@ discard block |
||
80 | 83 | { |
81 | 84 | throw new RestException(403, "Bad value for entity, must be the numeric ID of company."); |
82 | 85 | } |
83 | - if ($entity == '') $entity=1; |
|
86 | + if ($entity == '') { |
|
87 | + $entity=1; |
|
88 | + } |
|
84 | 89 | |
85 | 90 | include_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php'; |
86 | 91 | $login = checkLoginPassEntity($login, $password, $entity, $authmode); |
@@ -121,8 +126,7 @@ discard block |
||
121 | 126 | { |
122 | 127 | throw new RestException(500, 'Error when updating api_key for user :'.$this->db->lasterror()); |
123 | 128 | } |
124 | - } |
|
125 | - else |
|
129 | + } else |
|
126 | 130 | { |
127 | 131 | $token = $tmpuser->api_key; |
128 | 132 | } |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | // Remove $db object property for object |
101 | 101 | unset($object->db); |
102 | 102 | unset($object->isextrafieldmanaged); |
103 | - unset($object->ismultientitymanaged); |
|
104 | - unset($object->restrictiononfksoc); |
|
103 | + unset($object->ismultientitymanaged); |
|
104 | + unset($object->restrictiononfksoc); |
|
105 | 105 | |
106 | 106 | // Remove linkedObjects. We should already have linkedObjectIds that avoid huge responses |
107 | 107 | unset($object->linkedObjects); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | unset($object->picto); |
146 | 146 | |
147 | 147 | unset($object->fieldsforcombobox); |
148 | - unset($object->comments); |
|
148 | + unset($object->comments); |
|
149 | 149 | |
150 | 150 | unset($object->skip_update_total); |
151 | 151 | unset($object->context); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | // If object has lines, remove $db property |
165 | 165 | if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) { |
166 | 166 | $nboflines = count($object->lines); |
167 | - for ($i=0; $i < $nboflines; $i++) |
|
167 | + for ($i=0; $i < $nboflines; $i++) |
|
168 | 168 | { |
169 | 169 | $this->_cleanObjectDatas($object->lines[$i]); |
170 | 170 | |
@@ -202,101 +202,101 @@ discard block |
||
202 | 202 | |
203 | 203 | if (! empty($object->thirdparty) && is_object($object->thirdparty)) |
204 | 204 | { |
205 | - $this->_cleanObjectDatas($object->thirdparty); |
|
205 | + $this->_cleanObjectDatas($object->thirdparty); |
|
206 | 206 | } |
207 | 207 | |
208 | - return $object; |
|
208 | + return $object; |
|
209 | 209 | } |
210 | 210 | |
211 | - /** |
|
212 | - * Check user access to a resource |
|
213 | - * |
|
214 | - * Check access by user to a given resource |
|
215 | - * |
|
216 | - * @param string $resource element to check |
|
217 | - * @param int $resource_id Object ID if we want to check a particular record (optional) is linked to a owned thirdparty (optional). |
|
218 | - * @param type $dbtablename 'TableName&SharedElement' with Tablename is table where object is stored. SharedElement is an optional key to define where to check entity. Not used if objectid is null (optional) |
|
219 | - * @param string $feature2 Feature to check, second level of permission (optional). Can be or check with 'level1|level2'. |
|
220 | - * @param string $dbt_keyfield Field name for socid foreign key if not fk_soc. Not used if objectid is null (optional) |
|
221 | - * @param string $dbt_select Field name for select if not rowid. Not used if objectid is null (optional) |
|
211 | + /** |
|
212 | + * Check user access to a resource |
|
213 | + * |
|
214 | + * Check access by user to a given resource |
|
215 | + * |
|
216 | + * @param string $resource element to check |
|
217 | + * @param int $resource_id Object ID if we want to check a particular record (optional) is linked to a owned thirdparty (optional). |
|
218 | + * @param type $dbtablename 'TableName&SharedElement' with Tablename is table where object is stored. SharedElement is an optional key to define where to check entity. Not used if objectid is null (optional) |
|
219 | + * @param string $feature2 Feature to check, second level of permission (optional). Can be or check with 'level1|level2'. |
|
220 | + * @param string $dbt_keyfield Field name for socid foreign key if not fk_soc. Not used if objectid is null (optional) |
|
221 | + * @param string $dbt_select Field name for select if not rowid. Not used if objectid is null (optional) |
|
222 | 222 | * @return bool |
223 | - * @throws RestException |
|
224 | - */ |
|
223 | + * @throws RestException |
|
224 | + */ |
|
225 | 225 | static function _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid') |
226 | 226 | { |
227 | 227 | |
228 | - // Features/modules to check |
|
229 | - $featuresarray = array($resource); |
|
230 | - if (preg_match('/&/', $resource)) { |
|
231 | - $featuresarray = explode("&", $resource); |
|
232 | - } |
|
233 | - else if (preg_match('/\|/', $resource)) { |
|
234 | - $featuresarray = explode("|", $resource); |
|
235 | - } |
|
236 | - |
|
237 | - // More subfeatures to check |
|
238 | - if (! empty($feature2)) { |
|
239 | - $feature2 = explode("|", $feature2); |
|
240 | - } |
|
241 | - |
|
242 | - return checkUserAccessToObject(DolibarrApiAccess::$user, $featuresarray, $resource_id, $dbtablename, $feature2, $dbt_keyfield, $dbt_select); |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Return if a $sqlfilters parameter is valid |
|
247 | - * |
|
248 | - * @param string $sqlfilters sqlfilter string |
|
249 | - * @return boolean True if valid, False if not valid |
|
250 | - */ |
|
251 | - function _checkFilters($sqlfilters) |
|
252 | - { |
|
253 | - //$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
254 | - //$tmp=preg_replace_all('/'.$regexstring.'/', '', $sqlfilters); |
|
255 | - $tmp=$sqlfilters; |
|
256 | - $ok=0; |
|
257 | - $i=0; $nb=strlen($tmp); |
|
258 | - $counter=0; |
|
259 | - while ($i < $nb) |
|
260 | - { |
|
261 | - if ($tmp[$i]=='(') $counter++; |
|
262 | - if ($tmp[$i]==')') $counter--; |
|
228 | + // Features/modules to check |
|
229 | + $featuresarray = array($resource); |
|
230 | + if (preg_match('/&/', $resource)) { |
|
231 | + $featuresarray = explode("&", $resource); |
|
232 | + } |
|
233 | + else if (preg_match('/\|/', $resource)) { |
|
234 | + $featuresarray = explode("|", $resource); |
|
235 | + } |
|
236 | + |
|
237 | + // More subfeatures to check |
|
238 | + if (! empty($feature2)) { |
|
239 | + $feature2 = explode("|", $feature2); |
|
240 | + } |
|
241 | + |
|
242 | + return checkUserAccessToObject(DolibarrApiAccess::$user, $featuresarray, $resource_id, $dbtablename, $feature2, $dbt_keyfield, $dbt_select); |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Return if a $sqlfilters parameter is valid |
|
247 | + * |
|
248 | + * @param string $sqlfilters sqlfilter string |
|
249 | + * @return boolean True if valid, False if not valid |
|
250 | + */ |
|
251 | + function _checkFilters($sqlfilters) |
|
252 | + { |
|
253 | + //$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
254 | + //$tmp=preg_replace_all('/'.$regexstring.'/', '', $sqlfilters); |
|
255 | + $tmp=$sqlfilters; |
|
256 | + $ok=0; |
|
257 | + $i=0; $nb=strlen($tmp); |
|
258 | + $counter=0; |
|
259 | + while ($i < $nb) |
|
260 | + { |
|
261 | + if ($tmp[$i]=='(') $counter++; |
|
262 | + if ($tmp[$i]==')') $counter--; |
|
263 | 263 | if ($counter < 0) |
264 | 264 | { |
265 | - $error="Bad sqlfilters=".$sqlfilters; |
|
266 | - dol_syslog($error, LOG_WARNING); |
|
267 | - return false; |
|
265 | + $error="Bad sqlfilters=".$sqlfilters; |
|
266 | + dol_syslog($error, LOG_WARNING); |
|
267 | + return false; |
|
268 | 268 | } |
269 | 269 | $i++; |
270 | - } |
|
271 | - return true; |
|
272 | - } |
|
270 | + } |
|
271 | + return true; |
|
272 | + } |
|
273 | 273 | |
274 | 274 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
275 | - /** |
|
276 | - * Function to forge a SQL criteria |
|
277 | - * |
|
278 | - * @param array $matches Array of found string by regex search |
|
279 | - * @return string Forged criteria. Example: "t.field like 'abc%'" |
|
280 | - */ |
|
281 | - static function _forge_criteria_callback($matches) |
|
282 | - { |
|
275 | + /** |
|
276 | + * Function to forge a SQL criteria |
|
277 | + * |
|
278 | + * @param array $matches Array of found string by regex search |
|
279 | + * @return string Forged criteria. Example: "t.field like 'abc%'" |
|
280 | + */ |
|
281 | + static function _forge_criteria_callback($matches) |
|
282 | + { |
|
283 | 283 | // phpcs:enable |
284 | - global $db; |
|
284 | + global $db; |
|
285 | 285 | |
286 | - //dol_syslog("Convert matches ".$matches[1]); |
|
287 | - if (empty($matches[1])) return ''; |
|
288 | - $tmp=explode(':',$matches[1]); |
|
286 | + //dol_syslog("Convert matches ".$matches[1]); |
|
287 | + if (empty($matches[1])) return ''; |
|
288 | + $tmp=explode(':',$matches[1]); |
|
289 | 289 | if (count($tmp) < 3) return ''; |
290 | 290 | |
291 | - $tmpescaped=$tmp[2]; |
|
292 | - if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis)) |
|
293 | - { |
|
294 | - $tmpescaped = "'".$db->escape($regbis[1])."'"; |
|
295 | - } |
|
296 | - else |
|
297 | - { |
|
298 | - $tmpescaped = $db->escape($tmpescaped); |
|
299 | - } |
|
300 | - return $db->escape($tmp[0]).' '.strtoupper($db->escape($tmp[1]))." ".$tmpescaped; |
|
301 | - } |
|
291 | + $tmpescaped=$tmp[2]; |
|
292 | + if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis)) |
|
293 | + { |
|
294 | + $tmpescaped = "'".$db->escape($regbis[1])."'"; |
|
295 | + } |
|
296 | + else |
|
297 | + { |
|
298 | + $tmpescaped = $db->escape($tmpescaped); |
|
299 | + } |
|
300 | + return $db->escape($tmp[0]).' '.strtoupper($db->escape($tmp[1]))." ".$tmpescaped; |
|
301 | + } |
|
302 | 302 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param string $cachedir Cache dir |
47 | 47 | * @param boolean $refreshCache Update cache |
48 | 48 | */ |
49 | - function __construct($db, $cachedir='', $refreshCache=false) |
|
49 | + function __construct($db, $cachedir = '', $refreshCache = false) |
|
50 | 50 | { |
51 | 51 | global $conf, $dolibarr_main_url_root; |
52 | 52 | |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | Defaults::$cacheDirectory = $cachedir; |
55 | 55 | |
56 | 56 | $this->db = $db; |
57 | - $production_mode = ( empty($conf->global->API_PRODUCTION_MODE) ? false : true ); |
|
57 | + $production_mode = (empty($conf->global->API_PRODUCTION_MODE) ? false : true); |
|
58 | 58 | $this->r = new Restler($production_mode, $refreshCache); |
59 | 59 | |
60 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
61 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
60 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
61 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
62 | 62 | |
63 | - $urlwithouturlrootautodetect=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim(DOL_MAIN_URL_ROOT)); |
|
64 | - $urlwithrootautodetect=$urlwithouturlroot.DOL_URL_ROOT; // This is to use local domain autodetected by dolibarr from url |
|
63 | + $urlwithouturlrootautodetect = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim(DOL_MAIN_URL_ROOT)); |
|
64 | + $urlwithrootautodetect = $urlwithouturlroot.DOL_URL_ROOT; // This is to use local domain autodetected by dolibarr from url |
|
65 | 65 | |
66 | 66 | $this->r->setBaseUrls($urlwithouturlroot, $urlwithouturlrootautodetect); |
67 | 67 | $this->r->setAPIVersion(1); |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | unset($object->ref_next); |
119 | 119 | unset($object->ref_int); |
120 | 120 | |
121 | - unset($object->projet); // Should be fk_project |
|
122 | - unset($object->project); // Should be fk_project |
|
123 | - unset($object->author); // Should be fk_user_author |
|
121 | + unset($object->projet); // Should be fk_project |
|
122 | + unset($object->project); // Should be fk_project |
|
123 | + unset($object->author); // Should be fk_user_author |
|
124 | 124 | unset($object->timespent_old_duration); |
125 | 125 | unset($object->timespent_id); |
126 | 126 | unset($object->timespent_duration); |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | unset($object->oldcopy); |
163 | 163 | |
164 | 164 | // If object has lines, remove $db property |
165 | - if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) { |
|
165 | + if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) { |
|
166 | 166 | $nboflines = count($object->lines); |
167 | - for ($i=0; $i < $nboflines; $i++) |
|
167 | + for ($i = 0; $i < $nboflines; $i++) |
|
168 | 168 | { |
169 | 169 | $this->_cleanObjectDatas($object->lines[$i]); |
170 | 170 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
203 | - if (! empty($object->thirdparty) && is_object($object->thirdparty)) |
|
203 | + if (!empty($object->thirdparty) && is_object($object->thirdparty)) |
|
204 | 204 | { |
205 | 205 | $this->_cleanObjectDatas($object->thirdparty); |
206 | 206 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * @return bool |
223 | 223 | * @throws RestException |
224 | 224 | */ |
225 | - static function _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid') |
|
225 | + static function _checkAccessToResource($resource, $resource_id = 0, $dbtablename = '', $feature2 = '', $dbt_keyfield = 'fk_soc', $dbt_select = 'rowid') |
|
226 | 226 | { |
227 | 227 | |
228 | 228 | // Features/modules to check |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | // More subfeatures to check |
238 | - if (! empty($feature2)) { |
|
238 | + if (!empty($feature2)) { |
|
239 | 239 | $feature2 = explode("|", $feature2); |
240 | 240 | } |
241 | 241 | |
@@ -252,17 +252,17 @@ discard block |
||
252 | 252 | { |
253 | 253 | //$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
254 | 254 | //$tmp=preg_replace_all('/'.$regexstring.'/', '', $sqlfilters); |
255 | - $tmp=$sqlfilters; |
|
256 | - $ok=0; |
|
257 | - $i=0; $nb=strlen($tmp); |
|
258 | - $counter=0; |
|
255 | + $tmp = $sqlfilters; |
|
256 | + $ok = 0; |
|
257 | + $i = 0; $nb = strlen($tmp); |
|
258 | + $counter = 0; |
|
259 | 259 | while ($i < $nb) |
260 | 260 | { |
261 | - if ($tmp[$i]=='(') $counter++; |
|
262 | - if ($tmp[$i]==')') $counter--; |
|
261 | + if ($tmp[$i] == '(') $counter++; |
|
262 | + if ($tmp[$i] == ')') $counter--; |
|
263 | 263 | if ($counter < 0) |
264 | 264 | { |
265 | - $error="Bad sqlfilters=".$sqlfilters; |
|
265 | + $error = "Bad sqlfilters=".$sqlfilters; |
|
266 | 266 | dol_syslog($error, LOG_WARNING); |
267 | 267 | return false; |
268 | 268 | } |
@@ -285,10 +285,10 @@ discard block |
||
285 | 285 | |
286 | 286 | //dol_syslog("Convert matches ".$matches[1]); |
287 | 287 | if (empty($matches[1])) return ''; |
288 | - $tmp=explode(':',$matches[1]); |
|
288 | + $tmp = explode(':', $matches[1]); |
|
289 | 289 | if (count($tmp) < 3) return ''; |
290 | 290 | |
291 | - $tmpescaped=$tmp[2]; |
|
291 | + $tmpescaped = $tmp[2]; |
|
292 | 292 | if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis)) |
293 | 293 | { |
294 | 294 | $tmpescaped = "'".$db->escape($regbis[1])."'"; |
@@ -50,7 +50,9 @@ discard block |
||
50 | 50 | { |
51 | 51 | global $conf, $dolibarr_main_url_root; |
52 | 52 | |
53 | - if (empty($cachedir)) $cachedir = $conf->api->dir_temp; |
|
53 | + if (empty($cachedir)) { |
|
54 | + $cachedir = $conf->api->dir_temp; |
|
55 | + } |
|
54 | 56 | Defaults::$cacheDirectory = $cachedir; |
55 | 57 | |
56 | 58 | $this->db = $db; |
@@ -229,8 +231,7 @@ discard block |
||
229 | 231 | $featuresarray = array($resource); |
230 | 232 | if (preg_match('/&/', $resource)) { |
231 | 233 | $featuresarray = explode("&", $resource); |
232 | - } |
|
233 | - else if (preg_match('/\|/', $resource)) { |
|
234 | + } else if (preg_match('/\|/', $resource)) { |
|
234 | 235 | $featuresarray = explode("|", $resource); |
235 | 236 | } |
236 | 237 | |
@@ -258,8 +259,12 @@ discard block |
||
258 | 259 | $counter=0; |
259 | 260 | while ($i < $nb) |
260 | 261 | { |
261 | - if ($tmp[$i]=='(') $counter++; |
|
262 | - if ($tmp[$i]==')') $counter--; |
|
262 | + if ($tmp[$i]=='(') { |
|
263 | + $counter++; |
|
264 | + } |
|
265 | + if ($tmp[$i]==')') { |
|
266 | + $counter--; |
|
267 | + } |
|
263 | 268 | if ($counter < 0) |
264 | 269 | { |
265 | 270 | $error="Bad sqlfilters=".$sqlfilters; |
@@ -284,16 +289,19 @@ discard block |
||
284 | 289 | global $db; |
285 | 290 | |
286 | 291 | //dol_syslog("Convert matches ".$matches[1]); |
287 | - if (empty($matches[1])) return ''; |
|
292 | + if (empty($matches[1])) { |
|
293 | + return ''; |
|
294 | + } |
|
288 | 295 | $tmp=explode(':',$matches[1]); |
289 | - if (count($tmp) < 3) return ''; |
|
296 | + if (count($tmp) < 3) { |
|
297 | + return ''; |
|
298 | + } |
|
290 | 299 | |
291 | 300 | $tmpescaped=$tmp[2]; |
292 | 301 | if (preg_match('/^\'(.*)\'$/', $tmpescaped, $regbis)) |
293 | 302 | { |
294 | 303 | $tmpescaped = "'".$db->escape($regbis[1])."'"; |
295 | - } |
|
296 | - else |
|
304 | + } else |
|
297 | 305 | { |
298 | 306 | $tmpescaped = $db->escape($tmpescaped); |
299 | 307 | } |
@@ -42,151 +42,151 @@ |
||
42 | 42 | */ |
43 | 43 | class DolibarrApiAccess implements iAuthenticate |
44 | 44 | { |
45 | - const REALM = 'Restricted Dolibarr API'; |
|
45 | + const REALM = 'Restricted Dolibarr API'; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @var array $requires role required by API method user / external / admin |
|
49 | - */ |
|
50 | - public static $requires = array('user','external','admin'); |
|
47 | + /** |
|
48 | + * @var array $requires role required by API method user / external / admin |
|
49 | + */ |
|
50 | + public static $requires = array('user','external','admin'); |
|
51 | 51 | |
52 | - /** |
|
53 | - * @var string $role user role |
|
54 | - */ |
|
52 | + /** |
|
53 | + * @var string $role user role |
|
54 | + */ |
|
55 | 55 | public static $role = 'user'; |
56 | 56 | |
57 | - /** |
|
58 | - * @var User $user Loggued user |
|
59 | - */ |
|
60 | - public static $user = ''; |
|
57 | + /** |
|
58 | + * @var User $user Loggued user |
|
59 | + */ |
|
60 | + public static $user = ''; |
|
61 | 61 | |
62 | 62 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName |
63 | - /** |
|
64 | - * Check access |
|
65 | - * |
|
66 | - * @return bool |
|
67 | - * @throws RestException |
|
68 | - */ |
|
69 | - public function __isAllowed() |
|
70 | - { |
|
63 | + /** |
|
64 | + * Check access |
|
65 | + * |
|
66 | + * @return bool |
|
67 | + * @throws RestException |
|
68 | + */ |
|
69 | + public function __isAllowed() |
|
70 | + { |
|
71 | 71 | // phpcs:enable |
72 | - global $conf, $db; |
|
72 | + global $conf, $db; |
|
73 | 73 | |
74 | - $login = ''; |
|
75 | - $stored_key = ''; |
|
74 | + $login = ''; |
|
75 | + $stored_key = ''; |
|
76 | 76 | |
77 | - $userClass = Defaults::$userIdentifierClass; |
|
77 | + $userClass = Defaults::$userIdentifierClass; |
|
78 | 78 | |
79 | - /*foreach ($_SERVER as $key => $val) |
|
79 | + /*foreach ($_SERVER as $key => $val) |
|
80 | 80 | { |
81 | 81 | dol_syslog($key.' - '.$val); |
82 | 82 | }*/ |
83 | 83 | |
84 | - // api key can be provided in url with parameter api_key=xxx or ni header with header DOLAPIKEY:xxx |
|
85 | - $api_key = ''; |
|
86 | - if (isset($_GET['api_key'])) // For backward compatibility |
|
87 | - { |
|
88 | - // TODO Add option to disable use of api key on url. Return errors if used. |
|
89 | - $api_key = $_GET['api_key']; |
|
90 | - } |
|
91 | - if (isset($_GET['DOLAPIKEY'])) |
|
92 | - { |
|
93 | - // TODO Add option to disable use of api key on url. Return errors if used. |
|
94 | - $api_key = $_GET['DOLAPIKEY']; // With GET method |
|
95 | - } |
|
96 | - if (isset($_SERVER['HTTP_DOLAPIKEY'])) // Param DOLAPIKEY in header can be read with HTTP_DOLAPIKEY |
|
97 | - { |
|
98 | - $api_key = $_SERVER['HTTP_DOLAPIKEY']; // With header method (recommanded) |
|
99 | - } |
|
84 | + // api key can be provided in url with parameter api_key=xxx or ni header with header DOLAPIKEY:xxx |
|
85 | + $api_key = ''; |
|
86 | + if (isset($_GET['api_key'])) // For backward compatibility |
|
87 | + { |
|
88 | + // TODO Add option to disable use of api key on url. Return errors if used. |
|
89 | + $api_key = $_GET['api_key']; |
|
90 | + } |
|
91 | + if (isset($_GET['DOLAPIKEY'])) |
|
92 | + { |
|
93 | + // TODO Add option to disable use of api key on url. Return errors if used. |
|
94 | + $api_key = $_GET['DOLAPIKEY']; // With GET method |
|
95 | + } |
|
96 | + if (isset($_SERVER['HTTP_DOLAPIKEY'])) // Param DOLAPIKEY in header can be read with HTTP_DOLAPIKEY |
|
97 | + { |
|
98 | + $api_key = $_SERVER['HTTP_DOLAPIKEY']; // With header method (recommanded) |
|
99 | + } |
|
100 | 100 | |
101 | - if ($api_key) |
|
102 | - { |
|
103 | - $userentity = 0; |
|
104 | - |
|
105 | - $sql = "SELECT u.login, u.datec, u.api_key, "; |
|
106 | - $sql.= " u.tms as date_modification, u.entity"; |
|
107 | - $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; |
|
108 | - $sql.= " WHERE u.api_key = '".$db->escape($api_key)."'"; |
|
109 | - // TODO Check if 2 users has same API key. |
|
110 | - |
|
111 | - $result = $db->query($sql); |
|
112 | - if ($result) |
|
113 | - { |
|
114 | - if ($db->num_rows($result)) |
|
115 | - { |
|
116 | - $obj = $db->fetch_object($result); |
|
117 | - $login = $obj->login; |
|
118 | - $stored_key = $obj->api_key; |
|
119 | - $userentity = $obj->entity; |
|
120 | - |
|
121 | - if (! defined("DOLENTITY") && $conf->entity != ($obj->entity?$obj->entity:1)) // If API was not forced with HTTP_DOLENTITY, and user is on another entity, so we reset entity to entity of user |
|
122 | - { |
|
123 | - $conf->entity = ($obj->entity?$obj->entity:1); |
|
124 | - // We must also reload global conf to get params from the entity |
|
125 | - dol_syslog("Entity was not set on http header with HTTP_DOLAPIENTITY (recommanded for performance purpose), so we switch now on entity of user (".$conf->entity .") and we have to reload configuration.", LOG_WARNING); |
|
126 | - $conf->setValues($db); |
|
127 | - } |
|
128 | - } |
|
129 | - } |
|
130 | - else { |
|
131 | - throw new RestException(503, 'Error when fetching user api_key :'.$db->error_msg); |
|
132 | - } |
|
133 | - |
|
134 | - if ($stored_key != $api_key) { // This should not happen since we did a search on api_key |
|
135 | - $userClass::setCacheIdentifier($api_key); |
|
136 | - return false; |
|
137 | - } |
|
138 | - |
|
139 | - if (! $login) |
|
140 | - { |
|
141 | - throw new RestException(503, 'Error when searching login user from api key'); |
|
142 | - } |
|
143 | - $fuser = new User($db); |
|
144 | - $result = $fuser->fetch('', $login, '', 0, (empty($userentity) ? -1 : $conf->entity)); // If user is not entity 0, we search in working entity $conf->entity (that may have been forced to a different value than user entity) |
|
145 | - if ($result <= 0) { |
|
146 | - throw new RestException(503, 'Error when fetching user :'.$fuser->error.' (conf->entity='.$conf->entity.')'); |
|
147 | - } |
|
148 | - $fuser->getrights(); |
|
149 | - static::$user = $fuser; |
|
150 | - |
|
151 | - if($fuser->societe_id) |
|
152 | - static::$role = 'external'; |
|
153 | - |
|
154 | - if($fuser->admin) |
|
155 | - static::$role = 'admin'; |
|
101 | + if ($api_key) |
|
102 | + { |
|
103 | + $userentity = 0; |
|
104 | + |
|
105 | + $sql = "SELECT u.login, u.datec, u.api_key, "; |
|
106 | + $sql.= " u.tms as date_modification, u.entity"; |
|
107 | + $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; |
|
108 | + $sql.= " WHERE u.api_key = '".$db->escape($api_key)."'"; |
|
109 | + // TODO Check if 2 users has same API key. |
|
110 | + |
|
111 | + $result = $db->query($sql); |
|
112 | + if ($result) |
|
113 | + { |
|
114 | + if ($db->num_rows($result)) |
|
115 | + { |
|
116 | + $obj = $db->fetch_object($result); |
|
117 | + $login = $obj->login; |
|
118 | + $stored_key = $obj->api_key; |
|
119 | + $userentity = $obj->entity; |
|
120 | + |
|
121 | + if (! defined("DOLENTITY") && $conf->entity != ($obj->entity?$obj->entity:1)) // If API was not forced with HTTP_DOLENTITY, and user is on another entity, so we reset entity to entity of user |
|
122 | + { |
|
123 | + $conf->entity = ($obj->entity?$obj->entity:1); |
|
124 | + // We must also reload global conf to get params from the entity |
|
125 | + dol_syslog("Entity was not set on http header with HTTP_DOLAPIENTITY (recommanded for performance purpose), so we switch now on entity of user (".$conf->entity .") and we have to reload configuration.", LOG_WARNING); |
|
126 | + $conf->setValues($db); |
|
127 | + } |
|
128 | + } |
|
129 | + } |
|
130 | + else { |
|
131 | + throw new RestException(503, 'Error when fetching user api_key :'.$db->error_msg); |
|
132 | + } |
|
133 | + |
|
134 | + if ($stored_key != $api_key) { // This should not happen since we did a search on api_key |
|
135 | + $userClass::setCacheIdentifier($api_key); |
|
136 | + return false; |
|
137 | + } |
|
138 | + |
|
139 | + if (! $login) |
|
140 | + { |
|
141 | + throw new RestException(503, 'Error when searching login user from api key'); |
|
142 | + } |
|
143 | + $fuser = new User($db); |
|
144 | + $result = $fuser->fetch('', $login, '', 0, (empty($userentity) ? -1 : $conf->entity)); // If user is not entity 0, we search in working entity $conf->entity (that may have been forced to a different value than user entity) |
|
145 | + if ($result <= 0) { |
|
146 | + throw new RestException(503, 'Error when fetching user :'.$fuser->error.' (conf->entity='.$conf->entity.')'); |
|
147 | + } |
|
148 | + $fuser->getrights(); |
|
149 | + static::$user = $fuser; |
|
150 | + |
|
151 | + if($fuser->societe_id) |
|
152 | + static::$role = 'external'; |
|
153 | + |
|
154 | + if($fuser->admin) |
|
155 | + static::$role = 'admin'; |
|
156 | + } |
|
157 | + else |
|
158 | + { |
|
159 | + throw new RestException(401, "Failed to login to API. No parameter 'HTTP_DOLAPIKEY' on HTTP header (and no parameter DOLAPIKEY in URL)."); |
|
156 | 160 | } |
157 | - else |
|
158 | - { |
|
159 | - throw new RestException(401, "Failed to login to API. No parameter 'HTTP_DOLAPIKEY' on HTTP header (and no parameter DOLAPIKEY in URL)."); |
|
160 | - } |
|
161 | 161 | |
162 | - $userClass::setCacheIdentifier(static::$role); |
|
163 | - Resources::$accessControlFunction = 'DolibarrApiAccess::verifyAccess'; |
|
164 | - $requirefortest = static::$requires; |
|
165 | - if (! is_array($requirefortest)) $requirefortest=explode(',',$requirefortest); |
|
166 | - return in_array(static::$role, (array) $requirefortest) || static::$role == 'admin'; |
|
167 | - } |
|
162 | + $userClass::setCacheIdentifier(static::$role); |
|
163 | + Resources::$accessControlFunction = 'DolibarrApiAccess::verifyAccess'; |
|
164 | + $requirefortest = static::$requires; |
|
165 | + if (! is_array($requirefortest)) $requirefortest=explode(',',$requirefortest); |
|
166 | + return in_array(static::$role, (array) $requirefortest) || static::$role == 'admin'; |
|
167 | + } |
|
168 | 168 | |
169 | 169 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName |
170 | - /** |
|
171 | - * @return string string to be used with WWW-Authenticate header |
|
172 | - * @example Basic |
|
173 | - * @example Digest |
|
174 | - * @example OAuth |
|
175 | - */ |
|
176 | - public function __getWWWAuthenticateString() |
|
170 | + /** |
|
171 | + * @return string string to be used with WWW-Authenticate header |
|
172 | + * @example Basic |
|
173 | + * @example Digest |
|
174 | + * @example OAuth |
|
175 | + */ |
|
176 | + public function __getWWWAuthenticateString() |
|
177 | 177 | { |
178 | 178 | // phpcs:enable |
179 | 179 | return ''; |
180 | 180 | } |
181 | 181 | |
182 | - /** |
|
183 | - * Verify access |
|
184 | - * |
|
185 | - * @param array $m Properties of method |
|
186 | - * |
|
187 | - * @access private |
|
188 | - * @return bool |
|
189 | - */ |
|
182 | + /** |
|
183 | + * Verify access |
|
184 | + * |
|
185 | + * @param array $m Properties of method |
|
186 | + * |
|
187 | + * @access private |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | 190 | public static function verifyAccess(array $m) |
191 | 191 | { |
192 | 192 | $requires = isset($m['class']['DolibarrApiAccess']['properties']['requires']) |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | |
19 | 19 | // Create the autoloader for Luracast |
20 | 20 | require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/AutoLoader.php'; |
21 | -call_user_func(function () { |
|
21 | +call_user_func(function() { |
|
22 | 22 | $loader = Luracast\Restler\AutoLoader::instance(); |
23 | 23 | spl_autoload_register($loader); |
24 | 24 | return $loader; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | /** |
48 | 48 | * @var array $requires role required by API method user / external / admin |
49 | 49 | */ |
50 | - public static $requires = array('user','external','admin'); |
|
50 | + public static $requires = array('user', 'external', 'admin'); |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @var string $role user role |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | if (isset($_GET['DOLAPIKEY'])) |
92 | 92 | { |
93 | 93 | // TODO Add option to disable use of api key on url. Return errors if used. |
94 | - $api_key = $_GET['DOLAPIKEY']; // With GET method |
|
94 | + $api_key = $_GET['DOLAPIKEY']; // With GET method |
|
95 | 95 | } |
96 | 96 | if (isset($_SERVER['HTTP_DOLAPIKEY'])) // Param DOLAPIKEY in header can be read with HTTP_DOLAPIKEY |
97 | 97 | { |
98 | - $api_key = $_SERVER['HTTP_DOLAPIKEY']; // With header method (recommanded) |
|
98 | + $api_key = $_SERVER['HTTP_DOLAPIKEY']; // With header method (recommanded) |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | if ($api_key) |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | $userentity = 0; |
104 | 104 | |
105 | 105 | $sql = "SELECT u.login, u.datec, u.api_key, "; |
106 | - $sql.= " u.tms as date_modification, u.entity"; |
|
107 | - $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; |
|
108 | - $sql.= " WHERE u.api_key = '".$db->escape($api_key)."'"; |
|
106 | + $sql .= " u.tms as date_modification, u.entity"; |
|
107 | + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; |
|
108 | + $sql .= " WHERE u.api_key = '".$db->escape($api_key)."'"; |
|
109 | 109 | // TODO Check if 2 users has same API key. |
110 | 110 | |
111 | 111 | $result = $db->query($sql); |
@@ -118,11 +118,11 @@ discard block |
||
118 | 118 | $stored_key = $obj->api_key; |
119 | 119 | $userentity = $obj->entity; |
120 | 120 | |
121 | - if (! defined("DOLENTITY") && $conf->entity != ($obj->entity?$obj->entity:1)) // If API was not forced with HTTP_DOLENTITY, and user is on another entity, so we reset entity to entity of user |
|
121 | + if (!defined("DOLENTITY") && $conf->entity != ($obj->entity ? $obj->entity : 1)) // If API was not forced with HTTP_DOLENTITY, and user is on another entity, so we reset entity to entity of user |
|
122 | 122 | { |
123 | - $conf->entity = ($obj->entity?$obj->entity:1); |
|
123 | + $conf->entity = ($obj->entity ? $obj->entity : 1); |
|
124 | 124 | // We must also reload global conf to get params from the entity |
125 | - dol_syslog("Entity was not set on http header with HTTP_DOLAPIENTITY (recommanded for performance purpose), so we switch now on entity of user (".$conf->entity .") and we have to reload configuration.", LOG_WARNING); |
|
125 | + dol_syslog("Entity was not set on http header with HTTP_DOLAPIENTITY (recommanded for performance purpose), so we switch now on entity of user (".$conf->entity.") and we have to reload configuration.", LOG_WARNING); |
|
126 | 126 | $conf->setValues($db); |
127 | 127 | } |
128 | 128 | } |
@@ -136,22 +136,22 @@ discard block |
||
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | |
139 | - if (! $login) |
|
139 | + if (!$login) |
|
140 | 140 | { |
141 | 141 | throw new RestException(503, 'Error when searching login user from api key'); |
142 | 142 | } |
143 | 143 | $fuser = new User($db); |
144 | - $result = $fuser->fetch('', $login, '', 0, (empty($userentity) ? -1 : $conf->entity)); // If user is not entity 0, we search in working entity $conf->entity (that may have been forced to a different value than user entity) |
|
144 | + $result = $fuser->fetch('', $login, '', 0, (empty($userentity) ? -1 : $conf->entity)); // If user is not entity 0, we search in working entity $conf->entity (that may have been forced to a different value than user entity) |
|
145 | 145 | if ($result <= 0) { |
146 | 146 | throw new RestException(503, 'Error when fetching user :'.$fuser->error.' (conf->entity='.$conf->entity.')'); |
147 | 147 | } |
148 | 148 | $fuser->getrights(); |
149 | 149 | static::$user = $fuser; |
150 | 150 | |
151 | - if($fuser->societe_id) |
|
151 | + if ($fuser->societe_id) |
|
152 | 152 | static::$role = 'external'; |
153 | 153 | |
154 | - if($fuser->admin) |
|
154 | + if ($fuser->admin) |
|
155 | 155 | static::$role = 'admin'; |
156 | 156 | } |
157 | 157 | else |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | $userClass::setCacheIdentifier(static::$role); |
163 | 163 | Resources::$accessControlFunction = 'DolibarrApiAccess::verifyAccess'; |
164 | 164 | $requirefortest = static::$requires; |
165 | - if (! is_array($requirefortest)) $requirefortest=explode(',',$requirefortest); |
|
165 | + if (!is_array($requirefortest)) $requirefortest = explode(',', $requirefortest); |
|
166 | 166 | return in_array(static::$role, (array) $requirefortest) || static::$role == 'admin'; |
167 | 167 | } |
168 | 168 |
@@ -83,19 +83,24 @@ discard block |
||
83 | 83 | |
84 | 84 | // api key can be provided in url with parameter api_key=xxx or ni header with header DOLAPIKEY:xxx |
85 | 85 | $api_key = ''; |
86 | - if (isset($_GET['api_key'])) // For backward compatibility |
|
86 | + if (isset($_GET['api_key'])) { |
|
87 | + // For backward compatibility |
|
87 | 88 | { |
88 | 89 | // TODO Add option to disable use of api key on url. Return errors if used. |
89 | 90 | $api_key = $_GET['api_key']; |
90 | 91 | } |
92 | + } |
|
91 | 93 | if (isset($_GET['DOLAPIKEY'])) |
92 | 94 | { |
93 | 95 | // TODO Add option to disable use of api key on url. Return errors if used. |
94 | 96 | $api_key = $_GET['DOLAPIKEY']; // With GET method |
95 | 97 | } |
96 | - if (isset($_SERVER['HTTP_DOLAPIKEY'])) // Param DOLAPIKEY in header can be read with HTTP_DOLAPIKEY |
|
98 | + if (isset($_SERVER['HTTP_DOLAPIKEY'])) { |
|
99 | + // Param DOLAPIKEY in header can be read with HTTP_DOLAPIKEY |
|
97 | 100 | { |
98 | - $api_key = $_SERVER['HTTP_DOLAPIKEY']; // With header method (recommanded) |
|
101 | + $api_key = $_SERVER['HTTP_DOLAPIKEY']; |
|
102 | + } |
|
103 | + // With header method (recommanded) |
|
99 | 104 | } |
100 | 105 | |
101 | 106 | if ($api_key) |
@@ -118,16 +123,17 @@ discard block |
||
118 | 123 | $stored_key = $obj->api_key; |
119 | 124 | $userentity = $obj->entity; |
120 | 125 | |
121 | - if (! defined("DOLENTITY") && $conf->entity != ($obj->entity?$obj->entity:1)) // If API was not forced with HTTP_DOLENTITY, and user is on another entity, so we reset entity to entity of user |
|
126 | + if (! defined("DOLENTITY") && $conf->entity != ($obj->entity?$obj->entity:1)) { |
|
127 | + // If API was not forced with HTTP_DOLENTITY, and user is on another entity, so we reset entity to entity of user |
|
122 | 128 | { |
123 | 129 | $conf->entity = ($obj->entity?$obj->entity:1); |
130 | + } |
|
124 | 131 | // We must also reload global conf to get params from the entity |
125 | 132 | dol_syslog("Entity was not set on http header with HTTP_DOLAPIENTITY (recommanded for performance purpose), so we switch now on entity of user (".$conf->entity .") and we have to reload configuration.", LOG_WARNING); |
126 | 133 | $conf->setValues($db); |
127 | 134 | } |
128 | 135 | } |
129 | - } |
|
130 | - else { |
|
136 | + } else { |
|
131 | 137 | throw new RestException(503, 'Error when fetching user api_key :'.$db->error_msg); |
132 | 138 | } |
133 | 139 | |
@@ -148,13 +154,14 @@ discard block |
||
148 | 154 | $fuser->getrights(); |
149 | 155 | static::$user = $fuser; |
150 | 156 | |
151 | - if($fuser->societe_id) |
|
152 | - static::$role = 'external'; |
|
157 | + if($fuser->societe_id) { |
|
158 | + static::$role = 'external'; |
|
159 | + } |
|
153 | 160 | |
154 | - if($fuser->admin) |
|
155 | - static::$role = 'admin'; |
|
156 | - } |
|
157 | - else |
|
161 | + if($fuser->admin) { |
|
162 | + static::$role = 'admin'; |
|
163 | + } |
|
164 | + } else |
|
158 | 165 | { |
159 | 166 | throw new RestException(401, "Failed to login to API. No parameter 'HTTP_DOLAPIKEY' on HTTP header (and no parameter DOLAPIKEY in URL)."); |
160 | 167 | } |
@@ -162,7 +169,9 @@ discard block |
||
162 | 169 | $userClass::setCacheIdentifier(static::$role); |
163 | 170 | Resources::$accessControlFunction = 'DolibarrApiAccess::verifyAccess'; |
164 | 171 | $requirefortest = static::$requires; |
165 | - if (! is_array($requirefortest)) $requirefortest=explode(',',$requirefortest); |
|
172 | + if (! is_array($requirefortest)) { |
|
173 | + $requirefortest=explode(',',$requirefortest); |
|
174 | + } |
|
166 | 175 | return in_array(static::$role, (array) $requirefortest) || static::$role == 'admin'; |
167 | 176 | } |
168 | 177 |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | { |
77 | 77 | throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters); |
78 | 78 | } |
79 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
79 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
80 | 80 | $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
81 | 81 | } |
82 | 82 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | { |
144 | 144 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
145 | 145 | } |
146 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
146 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
147 | 147 | $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
148 | 148 | } |
149 | 149 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | { |
243 | 243 | throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters); |
244 | 244 | } |
245 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
245 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
246 | 246 | $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
247 | 247 | } |
248 | 248 | |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | { |
350 | 350 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
351 | 351 | } |
352 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
352 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
353 | 353 | $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
354 | 354 | } |
355 | 355 | |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | { |
411 | 411 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
412 | 412 | } |
413 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
413 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
414 | 414 | $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
415 | 415 | } |
416 | 416 | |
@@ -468,12 +468,12 @@ discard block |
||
468 | 468 | // Add sql filters |
469 | 469 | if ($sqlfilters) |
470 | 470 | { |
471 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
472 | - { |
|
473 | - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
|
474 | - } |
|
475 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
476 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
471 | + if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
472 | + { |
|
473 | + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
|
474 | + } |
|
475 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
476 | + $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | $sql.= $this->db->order($sortfield, $sortorder); |
@@ -481,26 +481,26 @@ discard block |
||
481 | 481 | $resql=$this->db->query($sql); |
482 | 482 | if ($resql) |
483 | 483 | { |
484 | - if ($this->db->num_rows($resql)) |
|
485 | - { |
|
486 | - while ($tab = $this->db->fetch_object($resql)) |
|
487 | - { |
|
488 | - // New usage |
|
489 | - $list[$tab->elementtype][$tab->name]['type']=$tab->type; |
|
490 | - $list[$tab->elementtype][$tab->name]['label']=$tab->label; |
|
491 | - $list[$tab->elementtype][$tab->name]['size']=$tab->size; |
|
492 | - $list[$tab->elementtype][$tab->name]['elementtype']=$tab->elementtype; |
|
493 | - $list[$tab->elementtype][$tab->name]['default']=$tab->fielddefault; |
|
494 | - $list[$tab->elementtype][$tab->name]['computed']=$tab->fieldcomputed; |
|
495 | - $list[$tab->elementtype][$tab->name]['unique']=$tab->fieldunique; |
|
496 | - $list[$tab->elementtype][$tab->name]['required']=$tab->fieldrequired; |
|
497 | - $list[$tab->elementtype][$tab->name]['param']=($tab->param ? unserialize($tab->param) : ''); |
|
498 | - $list[$tab->elementtype][$tab->name]['pos']=$tab->pos; |
|
499 | - $list[$tab->elementtype][$tab->name]['alwayseditable']=$tab->alwayseditable; |
|
500 | - $list[$tab->elementtype][$tab->name]['perms']=$tab->perms; |
|
501 | - $list[$tab->elementtype][$tab->name]['list']=$tab->list; |
|
502 | - } |
|
503 | - } |
|
484 | + if ($this->db->num_rows($resql)) |
|
485 | + { |
|
486 | + while ($tab = $this->db->fetch_object($resql)) |
|
487 | + { |
|
488 | + // New usage |
|
489 | + $list[$tab->elementtype][$tab->name]['type']=$tab->type; |
|
490 | + $list[$tab->elementtype][$tab->name]['label']=$tab->label; |
|
491 | + $list[$tab->elementtype][$tab->name]['size']=$tab->size; |
|
492 | + $list[$tab->elementtype][$tab->name]['elementtype']=$tab->elementtype; |
|
493 | + $list[$tab->elementtype][$tab->name]['default']=$tab->fielddefault; |
|
494 | + $list[$tab->elementtype][$tab->name]['computed']=$tab->fieldcomputed; |
|
495 | + $list[$tab->elementtype][$tab->name]['unique']=$tab->fieldunique; |
|
496 | + $list[$tab->elementtype][$tab->name]['required']=$tab->fieldrequired; |
|
497 | + $list[$tab->elementtype][$tab->name]['param']=($tab->param ? unserialize($tab->param) : ''); |
|
498 | + $list[$tab->elementtype][$tab->name]['pos']=$tab->pos; |
|
499 | + $list[$tab->elementtype][$tab->name]['alwayseditable']=$tab->alwayseditable; |
|
500 | + $list[$tab->elementtype][$tab->name]['perms']=$tab->perms; |
|
501 | + $list[$tab->elementtype][$tab->name]['list']=$tab->list; |
|
502 | + } |
|
503 | + } |
|
504 | 504 | } |
505 | 505 | else |
506 | 506 | { |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | |
510 | 510 | if (! count($list)) |
511 | 511 | { |
512 | - throw new RestException(404, 'No extrafield found'); |
|
512 | + throw new RestException(404, 'No extrafield found'); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | return $list; |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | { |
549 | 549 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
550 | 550 | } |
551 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
551 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
552 | 552 | $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
553 | 553 | } |
554 | 554 | |
@@ -642,63 +642,63 @@ discard block |
||
642 | 642 | return $list; |
643 | 643 | } |
644 | 644 | |
645 | - /** |
|
646 | - * Get the list of tickets categories. |
|
647 | - * |
|
648 | - * @param string $sortfield Sort field |
|
649 | - * @param string $sortorder Sort order |
|
650 | - * @param int $limit Number of items per page |
|
651 | - * @param int $page Page number (starting from zero) |
|
652 | - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" |
|
653 | - * @return List of events types |
|
654 | - * |
|
655 | - * @url GET dictionary/ticket_categories |
|
656 | - * |
|
657 | - * @throws RestException |
|
658 | - */ |
|
645 | + /** |
|
646 | + * Get the list of tickets categories. |
|
647 | + * |
|
648 | + * @param string $sortfield Sort field |
|
649 | + * @param string $sortorder Sort order |
|
650 | + * @param int $limit Number of items per page |
|
651 | + * @param int $page Page number (starting from zero) |
|
652 | + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" |
|
653 | + * @return List of events types |
|
654 | + * |
|
655 | + * @url GET dictionary/ticket_categories |
|
656 | + * |
|
657 | + * @throws RestException |
|
658 | + */ |
|
659 | 659 | function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') |
660 | 660 | { |
661 | - $list = array(); |
|
662 | - |
|
663 | - $sql = "SELECT rowid, code, pos, label, use_default, description"; |
|
664 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t"; |
|
665 | - $sql.= " WHERE t.active = 1"; |
|
666 | - // Add sql filters |
|
667 | - if ($sqlfilters) |
|
668 | - { |
|
669 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
670 | - { |
|
671 | - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
|
672 | - } |
|
673 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
674 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
675 | - } |
|
676 | - |
|
677 | - |
|
678 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
679 | - |
|
680 | - if ($limit) { |
|
681 | - if ($page < 0) { |
|
682 | - $page = 0; |
|
683 | - } |
|
684 | - $offset = $limit * $page; |
|
685 | - |
|
686 | - $sql .= $this->db->plimit($limit, $offset); |
|
687 | - } |
|
688 | - |
|
689 | - $result = $this->db->query($sql); |
|
690 | - |
|
691 | - if ($result) { |
|
692 | - $num = $this->db->num_rows($result); |
|
693 | - $min = min($num, ($limit <= 0 ? $num : $limit)); |
|
694 | - for ($i = 0; $i < $min; $i++) { |
|
695 | - $list[] = $this->db->fetch_object($result); |
|
696 | - } |
|
697 | - } else { |
|
698 | - throw new RestException(503, 'Error when retrieving list of ticket categories : '.$this->db->lasterror()); |
|
699 | - } |
|
700 | - |
|
701 | - return $list; |
|
661 | + $list = array(); |
|
662 | + |
|
663 | + $sql = "SELECT rowid, code, pos, label, use_default, description"; |
|
664 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t"; |
|
665 | + $sql.= " WHERE t.active = 1"; |
|
666 | + // Add sql filters |
|
667 | + if ($sqlfilters) |
|
668 | + { |
|
669 | + if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
670 | + { |
|
671 | + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
|
672 | + } |
|
673 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
674 | + $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
675 | + } |
|
676 | + |
|
677 | + |
|
678 | + $sql.= $this->db->order($sortfield, $sortorder); |
|
679 | + |
|
680 | + if ($limit) { |
|
681 | + if ($page < 0) { |
|
682 | + $page = 0; |
|
683 | + } |
|
684 | + $offset = $limit * $page; |
|
685 | + |
|
686 | + $sql .= $this->db->plimit($limit, $offset); |
|
687 | + } |
|
688 | + |
|
689 | + $result = $this->db->query($sql); |
|
690 | + |
|
691 | + if ($result) { |
|
692 | + $num = $this->db->num_rows($result); |
|
693 | + $min = min($num, ($limit <= 0 ? $num : $limit)); |
|
694 | + for ($i = 0; $i < $min; $i++) { |
|
695 | + $list[] = $this->db->fetch_object($result); |
|
696 | + } |
|
697 | + } else { |
|
698 | + throw new RestException(503, 'Error when retrieving list of ticket categories : '.$this->db->lasterror()); |
|
699 | + } |
|
700 | + |
|
701 | + return $list; |
|
702 | 702 | } |
703 | 703 | |
704 | 704 | /** |
@@ -717,47 +717,47 @@ discard block |
||
717 | 717 | */ |
718 | 718 | function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') |
719 | 719 | { |
720 | - $list = array(); |
|
721 | - |
|
722 | - $sql = "SELECT rowid, code, pos, label, use_default, color, description"; |
|
723 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t"; |
|
724 | - $sql.= " WHERE t.active = 1"; |
|
725 | - // Add sql filters |
|
726 | - if ($sqlfilters) |
|
727 | - { |
|
728 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
729 | - { |
|
730 | - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
|
731 | - } |
|
732 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
733 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
738 | - |
|
739 | - if ($limit) { |
|
740 | - if ($page < 0) { |
|
741 | - $page = 0; |
|
742 | - } |
|
743 | - $offset = $limit * $page; |
|
744 | - |
|
745 | - $sql .= $this->db->plimit($limit, $offset); |
|
746 | - } |
|
747 | - |
|
748 | - $result = $this->db->query($sql); |
|
749 | - |
|
750 | - if ($result) { |
|
751 | - $num = $this->db->num_rows($result); |
|
752 | - $min = min($num, ($limit <= 0 ? $num : $limit)); |
|
753 | - for ($i = 0; $i < $min; $i++) { |
|
754 | - $list[] = $this->db->fetch_object($result); |
|
755 | - } |
|
756 | - } else { |
|
757 | - throw new RestException(503, 'Error when retrieving list of ticket severities : '.$this->db->lasterror()); |
|
758 | - } |
|
759 | - |
|
760 | - return $list; |
|
720 | + $list = array(); |
|
721 | + |
|
722 | + $sql = "SELECT rowid, code, pos, label, use_default, color, description"; |
|
723 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t"; |
|
724 | + $sql.= " WHERE t.active = 1"; |
|
725 | + // Add sql filters |
|
726 | + if ($sqlfilters) |
|
727 | + { |
|
728 | + if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
729 | + { |
|
730 | + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
|
731 | + } |
|
732 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
733 | + $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + $sql.= $this->db->order($sortfield, $sortorder); |
|
738 | + |
|
739 | + if ($limit) { |
|
740 | + if ($page < 0) { |
|
741 | + $page = 0; |
|
742 | + } |
|
743 | + $offset = $limit * $page; |
|
744 | + |
|
745 | + $sql .= $this->db->plimit($limit, $offset); |
|
746 | + } |
|
747 | + |
|
748 | + $result = $this->db->query($sql); |
|
749 | + |
|
750 | + if ($result) { |
|
751 | + $num = $this->db->num_rows($result); |
|
752 | + $min = min($num, ($limit <= 0 ? $num : $limit)); |
|
753 | + for ($i = 0; $i < $min; $i++) { |
|
754 | + $list[] = $this->db->fetch_object($result); |
|
755 | + } |
|
756 | + } else { |
|
757 | + throw new RestException(503, 'Error when retrieving list of ticket severities : '.$this->db->lasterror()); |
|
758 | + } |
|
759 | + |
|
760 | + return $list; |
|
761 | 761 | } |
762 | 762 | |
763 | 763 | /** |
@@ -776,49 +776,49 @@ discard block |
||
776 | 776 | */ |
777 | 777 | function getTicketsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') |
778 | 778 | { |
779 | - $list = array(); |
|
780 | - |
|
781 | - $sql = "SELECT rowid, code, pos, label, use_default, description"; |
|
782 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t"; |
|
783 | - $sql.= " WHERE t.active = 1"; |
|
784 | - if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'"; |
|
785 | - if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; |
|
786 | - // Add sql filters |
|
787 | - if ($sqlfilters) |
|
788 | - { |
|
789 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
790 | - { |
|
791 | - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
|
792 | - } |
|
793 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
794 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
795 | - } |
|
796 | - |
|
797 | - |
|
798 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
799 | - |
|
800 | - if ($limit) { |
|
801 | - if ($page < 0) { |
|
802 | - $page = 0; |
|
803 | - } |
|
804 | - $offset = $limit * $page; |
|
805 | - |
|
806 | - $sql .= $this->db->plimit($limit, $offset); |
|
807 | - } |
|
808 | - |
|
809 | - $result = $this->db->query($sql); |
|
810 | - |
|
811 | - if ($result) { |
|
812 | - $num = $this->db->num_rows($result); |
|
813 | - $min = min($num, ($limit <= 0 ? $num : $limit)); |
|
814 | - for ($i = 0; $i < $min; $i++) { |
|
815 | - $list[] = $this->db->fetch_object($result); |
|
816 | - } |
|
817 | - } else { |
|
818 | - throw new RestException(503, 'Error when retrieving list of ticket types : '.$this->db->lasterror()); |
|
819 | - } |
|
820 | - |
|
821 | - return $list; |
|
779 | + $list = array(); |
|
780 | + |
|
781 | + $sql = "SELECT rowid, code, pos, label, use_default, description"; |
|
782 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t"; |
|
783 | + $sql.= " WHERE t.active = 1"; |
|
784 | + if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'"; |
|
785 | + if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; |
|
786 | + // Add sql filters |
|
787 | + if ($sqlfilters) |
|
788 | + { |
|
789 | + if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
790 | + { |
|
791 | + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
|
792 | + } |
|
793 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
794 | + $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
795 | + } |
|
796 | + |
|
797 | + |
|
798 | + $sql.= $this->db->order($sortfield, $sortorder); |
|
799 | + |
|
800 | + if ($limit) { |
|
801 | + if ($page < 0) { |
|
802 | + $page = 0; |
|
803 | + } |
|
804 | + $offset = $limit * $page; |
|
805 | + |
|
806 | + $sql .= $this->db->plimit($limit, $offset); |
|
807 | + } |
|
808 | + |
|
809 | + $result = $this->db->query($sql); |
|
810 | + |
|
811 | + if ($result) { |
|
812 | + $num = $this->db->num_rows($result); |
|
813 | + $min = min($num, ($limit <= 0 ? $num : $limit)); |
|
814 | + for ($i = 0; $i < $min; $i++) { |
|
815 | + $list[] = $this->db->fetch_object($result); |
|
816 | + } |
|
817 | + } else { |
|
818 | + throw new RestException(503, 'Error when retrieving list of ticket types : '.$this->db->lasterror()); |
|
819 | + } |
|
820 | + |
|
821 | + return $list; |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | |
@@ -834,328 +834,328 @@ discard block |
||
834 | 834 | */ |
835 | 835 | function getCheckIntegrity($target) |
836 | 836 | { |
837 | - global $langs, $conf; |
|
838 | - |
|
839 | - if (! DolibarrApiAccess::$user->admin |
|
840 | - && (empty($conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK)) |
|
841 | - { |
|
842 | - throw new RestException(503, 'Error API open to admin users only or to login user defined with constant API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK'); |
|
843 | - } |
|
844 | - |
|
845 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
846 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; |
|
847 | - |
|
848 | - $langs->load("admin"); |
|
849 | - |
|
850 | - $outexpectedchecksum = ''; |
|
851 | - $outcurrentchecksum = ''; |
|
852 | - |
|
853 | - // Modified or missing files |
|
854 | - $file_list = array('missing' => array(), 'updated' => array()); |
|
855 | - |
|
856 | - // Local file to compare to |
|
857 | - $xmlshortfile = GETPOST('xmlshortfile')?GETPOST('xmlshortfile'):'/install/filelist-'.DOL_VERSION.'.xml'; |
|
858 | - $xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile; |
|
859 | - // Remote file to compare to |
|
860 | - $xmlremote = ($target == 'default' ? '' : $target); |
|
861 | - if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL; |
|
862 | - $param='MAIN_FILECHECK_URL_'.DOL_VERSION; |
|
863 | - if (empty($xmlremote) && ! empty($conf->global->$param)) $xmlremote = $conf->global->$param; |
|
864 | - if (empty($xmlremote)) $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml'; |
|
865 | - |
|
866 | - if ($target == 'local') |
|
867 | - { |
|
868 | - if (dol_is_file($xmlfile)) |
|
869 | - { |
|
870 | - $xml = simplexml_load_file($xmlfile); |
|
871 | - } |
|
872 | - else |
|
873 | - { |
|
874 | - throw new RestException(500, $langs->trans('XmlNotFound') . ': ' . $xmlfile); |
|
875 | - } |
|
876 | - } |
|
877 | - else |
|
878 | - { |
|
879 | - $xmlarray = getURLContent($xmlremote); |
|
880 | - |
|
881 | - // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...) |
|
882 | - if (! $xmlarray['curl_error_no'] && $xmlarray['http_code'] != '404') |
|
883 | - { |
|
884 | - $xmlfile = $xmlarray['content']; |
|
885 | - //print "xmlfilestart".$xmlfile."endxmlfile"; |
|
886 | - $xml = simplexml_load_string($xmlfile); |
|
887 | - } |
|
888 | - else |
|
889 | - { |
|
890 | - $errormsg=$langs->trans('XmlNotFound') . ': ' . $xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg']; |
|
891 | - throw new RestException(500, $errormsg); |
|
892 | - } |
|
893 | - } |
|
894 | - |
|
895 | - |
|
896 | - |
|
897 | - if ($xml) |
|
898 | - { |
|
899 | - $checksumconcat = array(); |
|
900 | - $file_list = array(); |
|
901 | - $out = ''; |
|
902 | - |
|
903 | - // Forced constants |
|
904 | - if (is_object($xml->dolibarr_constants[0])) |
|
905 | - { |
|
906 | - $out.=load_fiche_titre($langs->trans("ForcedConstants")); |
|
907 | - |
|
908 | - $out.='<div class="div-table-responsive-no-min">'; |
|
909 | - $out.='<table class="noborder">'; |
|
910 | - $out.='<tr class="liste_titre">'; |
|
911 | - $out.='<td>#</td>'; |
|
912 | - $out.='<td>' . $langs->trans("Constant") . '</td>'; |
|
913 | - $out.='<td align="center">' . $langs->trans("ExpectedValue") . '</td>'; |
|
914 | - $out.='<td align="center">' . $langs->trans("Value") . '</td>'; |
|
915 | - $out.='</tr>'."\n"; |
|
916 | - |
|
917 | - $i = 0; |
|
918 | - foreach ($xml->dolibarr_constants[0]->constant as $constant) // $constant is a simpleXMLElement |
|
919 | - { |
|
920 | - $constname=$constant['name']; |
|
921 | - $constvalue=(string) $constant; |
|
922 | - $constvalue = (empty($constvalue)?'0':$constvalue); |
|
923 | - // Value found |
|
924 | - $value=''; |
|
925 | - if ($constname && $conf->global->$constname != '') $value=$conf->global->$constname; |
|
926 | - $valueforchecksum=(empty($value)?'0':$value); |
|
927 | - |
|
928 | - $checksumconcat[]=$valueforchecksum; |
|
929 | - |
|
930 | - $i++; |
|
931 | - $out.='<tr class="oddeven">'; |
|
932 | - $out.='<td>'.$i.'</td>' . "\n"; |
|
933 | - $out.='<td>'.$constname.'</td>' . "\n"; |
|
934 | - $out.='<td align="center">'.$constvalue.'</td>' . "\n"; |
|
935 | - $out.='<td align="center">'.$valueforchecksum.'</td>' . "\n"; |
|
936 | - $out.="</tr>\n"; |
|
937 | - } |
|
938 | - |
|
939 | - if ($i==0) |
|
940 | - { |
|
941 | - $out.='<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
942 | - } |
|
943 | - $out.='</table>'; |
|
944 | - $out.='</div>'; |
|
945 | - |
|
946 | - $out.='<br>'; |
|
947 | - } |
|
948 | - |
|
949 | - // Scan htdocs |
|
950 | - if (is_object($xml->dolibarr_htdocs_dir[0])) |
|
951 | - { |
|
952 | - //var_dump($xml->dolibarr_htdocs_dir[0]['includecustom']);exit; |
|
953 | - $includecustom=(empty($xml->dolibarr_htdocs_dir[0]['includecustom'])?0:$xml->dolibarr_htdocs_dir[0]['includecustom']); |
|
954 | - |
|
955 | - // Defined qualified files (must be same than into generate_filelist_xml.php) |
|
956 | - $regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$'; |
|
957 | - $regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs |
|
958 | - $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude); |
|
959 | - |
|
960 | - // Fill file_list with files in signature, new files, modified files |
|
961 | - $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat, $scanfiles); // Fill array $file_list |
|
962 | - // Complete with list of new files |
|
963 | - foreach ($scanfiles as $keyfile => $valfile) |
|
964 | - { |
|
965 | - $tmprelativefilename=preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT,'/').'/','', $valfile['fullname']); |
|
966 | - if (! in_array($tmprelativefilename, $file_list['insignature'])) |
|
967 | - { |
|
968 | - $md5newfile=@md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file |
|
969 | - $file_list['added'][]=array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile); |
|
970 | - } |
|
971 | - } |
|
972 | - |
|
973 | - // Files missings |
|
974 | - $out.=load_fiche_titre($langs->trans("FilesMissing")); |
|
975 | - |
|
976 | - $out.='<div class="div-table-responsive-no-min">'; |
|
977 | - $out.='<table class="noborder">'; |
|
978 | - $out.='<tr class="liste_titre">'; |
|
979 | - $out.='<td>#</td>'; |
|
980 | - $out.='<td>' . $langs->trans("Filename") . '</td>'; |
|
981 | - $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>'; |
|
982 | - $out.='</tr>'."\n"; |
|
983 | - $tmpfilelist = dol_sort_array($file_list['missing'], 'filename'); |
|
984 | - if (is_array($tmpfilelist) && count($tmpfilelist)) |
|
985 | - { |
|
986 | - $i = 0; |
|
987 | - foreach ($tmpfilelist as $file) |
|
988 | - { |
|
989 | - $i++; |
|
990 | - $out.='<tr class="oddeven">'; |
|
991 | - $out.='<td>'.$i.'</td>' . "\n"; |
|
992 | - $out.='<td>'.$file['filename'].'</td>' . "\n"; |
|
993 | - $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n"; |
|
994 | - $out.="</tr>\n"; |
|
995 | - } |
|
996 | - } |
|
997 | - else |
|
998 | - { |
|
999 | - $out.='<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
1000 | - } |
|
1001 | - $out.='</table>'; |
|
1002 | - $out.='</div>'; |
|
1003 | - |
|
1004 | - $out.='<br>'; |
|
1005 | - |
|
1006 | - // Files modified |
|
1007 | - $out.=load_fiche_titre($langs->trans("FilesModified")); |
|
1008 | - |
|
1009 | - $totalsize=0; |
|
1010 | - $out.='<div class="div-table-responsive-no-min">'; |
|
1011 | - $out.='<table class="noborder">'; |
|
1012 | - $out.='<tr class="liste_titre">'; |
|
1013 | - $out.='<td>#</td>'; |
|
1014 | - $out.='<td>' . $langs->trans("Filename") . '</td>'; |
|
1015 | - $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>'; |
|
1016 | - $out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>'; |
|
1017 | - $out.='<td align="right">' . $langs->trans("Size") . '</td>'; |
|
1018 | - $out.='<td align="right">' . $langs->trans("DateModification") . '</td>'; |
|
1019 | - $out.='</tr>'."\n"; |
|
1020 | - $tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename'); |
|
1021 | - if (is_array($tmpfilelist2) && count($tmpfilelist2)) |
|
1022 | - { |
|
1023 | - $i = 0; |
|
1024 | - foreach ($tmpfilelist2 as $file) |
|
1025 | - { |
|
1026 | - $i++; |
|
1027 | - $out.='<tr class="oddeven">'; |
|
1028 | - $out.='<td>'.$i.'</td>' . "\n"; |
|
1029 | - $out.='<td>'.$file['filename'].'</td>' . "\n"; |
|
1030 | - $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n"; |
|
1031 | - $out.='<td align="center">'.$file['md5'].'</td>' . "\n"; |
|
1032 | - $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']); |
|
1033 | - $totalsize += $size; |
|
1034 | - $out.='<td align="right">'.dol_print_size($size).'</td>' . "\n"; |
|
1035 | - $out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n"; |
|
1036 | - $out.="</tr>\n"; |
|
1037 | - } |
|
1038 | - $out.='<tr class="liste_total">'; |
|
1039 | - $out.='<td></td>' . "\n"; |
|
1040 | - $out.='<td>'.$langs->trans("Total").'</td>' . "\n"; |
|
1041 | - $out.='<td align="center"></td>' . "\n"; |
|
1042 | - $out.='<td align="center"></td>' . "\n"; |
|
1043 | - $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n"; |
|
1044 | - $out.='<td align="right"></td>' . "\n"; |
|
1045 | - $out.="</tr>\n"; |
|
1046 | - } |
|
1047 | - else |
|
1048 | - { |
|
1049 | - $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
1050 | - } |
|
1051 | - $out.='</table>'; |
|
1052 | - $out.='</div>'; |
|
1053 | - |
|
1054 | - $out.='<br>'; |
|
1055 | - |
|
1056 | - // Files added |
|
1057 | - $out.=load_fiche_titre($langs->trans("FilesAdded")); |
|
1058 | - |
|
1059 | - $totalsize = 0; |
|
1060 | - $out.='<div class="div-table-responsive-no-min">'; |
|
1061 | - $out.='<table class="noborder">'; |
|
1062 | - $out.='<tr class="liste_titre">'; |
|
1063 | - $out.='<td>#</td>'; |
|
1064 | - $out.='<td>' . $langs->trans("Filename") . '</td>'; |
|
1065 | - $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>'; |
|
1066 | - $out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>'; |
|
1067 | - $out.='<td align="right">' . $langs->trans("Size") . '</td>'; |
|
1068 | - $out.='<td align="right">' . $langs->trans("DateModification") . '</td>'; |
|
1069 | - $out.='</tr>'."\n"; |
|
1070 | - $tmpfilelist3 = dol_sort_array($file_list['added'], 'filename'); |
|
1071 | - if (is_array($tmpfilelist3) && count($tmpfilelist3)) |
|
1072 | - { |
|
1073 | - $i = 0; |
|
1074 | - foreach ($tmpfilelist3 as $file) |
|
1075 | - { |
|
1076 | - $i++; |
|
1077 | - $out.='<tr class="oddeven">'; |
|
1078 | - $out.='<td>'.$i.'</td>' . "\n"; |
|
1079 | - $out.='<td>'.$file['filename'].'</td>' . "\n"; |
|
1080 | - $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n"; |
|
1081 | - $out.='<td align="center">'.$file['md5'].'</td>' . "\n"; |
|
1082 | - $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']); |
|
1083 | - $totalsize += $size; |
|
1084 | - $out.='<td align="right">'.dol_print_size($size).'</td>' . "\n"; |
|
1085 | - $out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n"; |
|
1086 | - $out.="</tr>\n"; |
|
1087 | - } |
|
1088 | - $out.='<tr class="liste_total">'; |
|
1089 | - $out.='<td></td>' . "\n"; |
|
1090 | - $out.='<td>'.$langs->trans("Total").'</td>' . "\n"; |
|
1091 | - $out.='<td align="center"></td>' . "\n"; |
|
1092 | - $out.='<td align="center"></td>' . "\n"; |
|
1093 | - $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n"; |
|
1094 | - $out.='<td align="right"></td>' . "\n"; |
|
1095 | - $out.="</tr>\n"; |
|
1096 | - } |
|
1097 | - else |
|
1098 | - { |
|
1099 | - $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
1100 | - } |
|
1101 | - $out.='</table>'; |
|
1102 | - $out.='</div>'; |
|
1103 | - |
|
1104 | - |
|
1105 | - // Show warning |
|
1106 | - if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) |
|
1107 | - { |
|
1108 | - //setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs'); |
|
1109 | - } |
|
1110 | - else |
|
1111 | - { |
|
1112 | - //setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings'); |
|
1113 | - } |
|
1114 | - } |
|
1115 | - else |
|
1116 | - { |
|
1117 | - throw new RestException(500, 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile); |
|
1118 | - } |
|
1119 | - |
|
1120 | - |
|
1121 | - // Scan scripts |
|
1122 | - |
|
1123 | - |
|
1124 | - asort($checksumconcat); // Sort list of checksum |
|
1125 | - //var_dump($checksumconcat); |
|
1126 | - $checksumget = md5(join(',',$checksumconcat)); |
|
1127 | - $checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum); |
|
1128 | - |
|
1129 | - $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown")); |
|
1130 | - if ($checksumget == $checksumtoget) |
|
1131 | - { |
|
1132 | - if (count($file_list['added'])) |
|
1133 | - { |
|
1134 | - $resultcode = 'warning'; |
|
1135 | - $resultcomment='FileIntegrityIsOkButFilesWereAdded'; |
|
1136 | - //$outcurrentchecksum = $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>'; |
|
1137 | - $outcurrentchecksum = $checksumget; |
|
1138 | - } |
|
1139 | - else |
|
1140 | - { |
|
1141 | - $resultcode = 'ok'; |
|
1142 | - $resultcomment='Success'; |
|
1143 | - //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>'; |
|
1144 | - $outcurrentchecksum = $checksumget; |
|
1145 | - } |
|
1146 | - } |
|
1147 | - else |
|
1148 | - { |
|
1149 | - $resultcode = 'error'; |
|
1150 | - $resultcomment='Error'; |
|
1151 | - //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>'; |
|
1152 | - $outcurrentchecksum = $checksumget; |
|
1153 | - } |
|
1154 | - } |
|
1155 | - else { |
|
1156 | - throw new RestException(404, 'No signature file known'); |
|
1157 | - } |
|
1158 | - |
|
1159 | - return array('resultcode'=>$resultcode, 'resultcomment'=>$resultcomment, 'expectedchecksum'=> $outexpectedchecksum, 'currentchecksum'=> $outcurrentchecksum, 'out'=>$out); |
|
837 | + global $langs, $conf; |
|
838 | + |
|
839 | + if (! DolibarrApiAccess::$user->admin |
|
840 | + && (empty($conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK)) |
|
841 | + { |
|
842 | + throw new RestException(503, 'Error API open to admin users only or to login user defined with constant API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK'); |
|
843 | + } |
|
844 | + |
|
845 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
846 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; |
|
847 | + |
|
848 | + $langs->load("admin"); |
|
849 | + |
|
850 | + $outexpectedchecksum = ''; |
|
851 | + $outcurrentchecksum = ''; |
|
852 | + |
|
853 | + // Modified or missing files |
|
854 | + $file_list = array('missing' => array(), 'updated' => array()); |
|
855 | + |
|
856 | + // Local file to compare to |
|
857 | + $xmlshortfile = GETPOST('xmlshortfile')?GETPOST('xmlshortfile'):'/install/filelist-'.DOL_VERSION.'.xml'; |
|
858 | + $xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile; |
|
859 | + // Remote file to compare to |
|
860 | + $xmlremote = ($target == 'default' ? '' : $target); |
|
861 | + if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL; |
|
862 | + $param='MAIN_FILECHECK_URL_'.DOL_VERSION; |
|
863 | + if (empty($xmlremote) && ! empty($conf->global->$param)) $xmlremote = $conf->global->$param; |
|
864 | + if (empty($xmlremote)) $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml'; |
|
865 | + |
|
866 | + if ($target == 'local') |
|
867 | + { |
|
868 | + if (dol_is_file($xmlfile)) |
|
869 | + { |
|
870 | + $xml = simplexml_load_file($xmlfile); |
|
871 | + } |
|
872 | + else |
|
873 | + { |
|
874 | + throw new RestException(500, $langs->trans('XmlNotFound') . ': ' . $xmlfile); |
|
875 | + } |
|
876 | + } |
|
877 | + else |
|
878 | + { |
|
879 | + $xmlarray = getURLContent($xmlremote); |
|
880 | + |
|
881 | + // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...) |
|
882 | + if (! $xmlarray['curl_error_no'] && $xmlarray['http_code'] != '404') |
|
883 | + { |
|
884 | + $xmlfile = $xmlarray['content']; |
|
885 | + //print "xmlfilestart".$xmlfile."endxmlfile"; |
|
886 | + $xml = simplexml_load_string($xmlfile); |
|
887 | + } |
|
888 | + else |
|
889 | + { |
|
890 | + $errormsg=$langs->trans('XmlNotFound') . ': ' . $xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg']; |
|
891 | + throw new RestException(500, $errormsg); |
|
892 | + } |
|
893 | + } |
|
894 | + |
|
895 | + |
|
896 | + |
|
897 | + if ($xml) |
|
898 | + { |
|
899 | + $checksumconcat = array(); |
|
900 | + $file_list = array(); |
|
901 | + $out = ''; |
|
902 | + |
|
903 | + // Forced constants |
|
904 | + if (is_object($xml->dolibarr_constants[0])) |
|
905 | + { |
|
906 | + $out.=load_fiche_titre($langs->trans("ForcedConstants")); |
|
907 | + |
|
908 | + $out.='<div class="div-table-responsive-no-min">'; |
|
909 | + $out.='<table class="noborder">'; |
|
910 | + $out.='<tr class="liste_titre">'; |
|
911 | + $out.='<td>#</td>'; |
|
912 | + $out.='<td>' . $langs->trans("Constant") . '</td>'; |
|
913 | + $out.='<td align="center">' . $langs->trans("ExpectedValue") . '</td>'; |
|
914 | + $out.='<td align="center">' . $langs->trans("Value") . '</td>'; |
|
915 | + $out.='</tr>'."\n"; |
|
916 | + |
|
917 | + $i = 0; |
|
918 | + foreach ($xml->dolibarr_constants[0]->constant as $constant) // $constant is a simpleXMLElement |
|
919 | + { |
|
920 | + $constname=$constant['name']; |
|
921 | + $constvalue=(string) $constant; |
|
922 | + $constvalue = (empty($constvalue)?'0':$constvalue); |
|
923 | + // Value found |
|
924 | + $value=''; |
|
925 | + if ($constname && $conf->global->$constname != '') $value=$conf->global->$constname; |
|
926 | + $valueforchecksum=(empty($value)?'0':$value); |
|
927 | + |
|
928 | + $checksumconcat[]=$valueforchecksum; |
|
929 | + |
|
930 | + $i++; |
|
931 | + $out.='<tr class="oddeven">'; |
|
932 | + $out.='<td>'.$i.'</td>' . "\n"; |
|
933 | + $out.='<td>'.$constname.'</td>' . "\n"; |
|
934 | + $out.='<td align="center">'.$constvalue.'</td>' . "\n"; |
|
935 | + $out.='<td align="center">'.$valueforchecksum.'</td>' . "\n"; |
|
936 | + $out.="</tr>\n"; |
|
937 | + } |
|
938 | + |
|
939 | + if ($i==0) |
|
940 | + { |
|
941 | + $out.='<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
942 | + } |
|
943 | + $out.='</table>'; |
|
944 | + $out.='</div>'; |
|
945 | + |
|
946 | + $out.='<br>'; |
|
947 | + } |
|
948 | + |
|
949 | + // Scan htdocs |
|
950 | + if (is_object($xml->dolibarr_htdocs_dir[0])) |
|
951 | + { |
|
952 | + //var_dump($xml->dolibarr_htdocs_dir[0]['includecustom']);exit; |
|
953 | + $includecustom=(empty($xml->dolibarr_htdocs_dir[0]['includecustom'])?0:$xml->dolibarr_htdocs_dir[0]['includecustom']); |
|
954 | + |
|
955 | + // Defined qualified files (must be same than into generate_filelist_xml.php) |
|
956 | + $regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$'; |
|
957 | + $regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs |
|
958 | + $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude); |
|
959 | + |
|
960 | + // Fill file_list with files in signature, new files, modified files |
|
961 | + $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat, $scanfiles); // Fill array $file_list |
|
962 | + // Complete with list of new files |
|
963 | + foreach ($scanfiles as $keyfile => $valfile) |
|
964 | + { |
|
965 | + $tmprelativefilename=preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT,'/').'/','', $valfile['fullname']); |
|
966 | + if (! in_array($tmprelativefilename, $file_list['insignature'])) |
|
967 | + { |
|
968 | + $md5newfile=@md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file |
|
969 | + $file_list['added'][]=array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile); |
|
970 | + } |
|
971 | + } |
|
972 | + |
|
973 | + // Files missings |
|
974 | + $out.=load_fiche_titre($langs->trans("FilesMissing")); |
|
975 | + |
|
976 | + $out.='<div class="div-table-responsive-no-min">'; |
|
977 | + $out.='<table class="noborder">'; |
|
978 | + $out.='<tr class="liste_titre">'; |
|
979 | + $out.='<td>#</td>'; |
|
980 | + $out.='<td>' . $langs->trans("Filename") . '</td>'; |
|
981 | + $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>'; |
|
982 | + $out.='</tr>'."\n"; |
|
983 | + $tmpfilelist = dol_sort_array($file_list['missing'], 'filename'); |
|
984 | + if (is_array($tmpfilelist) && count($tmpfilelist)) |
|
985 | + { |
|
986 | + $i = 0; |
|
987 | + foreach ($tmpfilelist as $file) |
|
988 | + { |
|
989 | + $i++; |
|
990 | + $out.='<tr class="oddeven">'; |
|
991 | + $out.='<td>'.$i.'</td>' . "\n"; |
|
992 | + $out.='<td>'.$file['filename'].'</td>' . "\n"; |
|
993 | + $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n"; |
|
994 | + $out.="</tr>\n"; |
|
995 | + } |
|
996 | + } |
|
997 | + else |
|
998 | + { |
|
999 | + $out.='<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
1000 | + } |
|
1001 | + $out.='</table>'; |
|
1002 | + $out.='</div>'; |
|
1003 | + |
|
1004 | + $out.='<br>'; |
|
1005 | + |
|
1006 | + // Files modified |
|
1007 | + $out.=load_fiche_titre($langs->trans("FilesModified")); |
|
1008 | + |
|
1009 | + $totalsize=0; |
|
1010 | + $out.='<div class="div-table-responsive-no-min">'; |
|
1011 | + $out.='<table class="noborder">'; |
|
1012 | + $out.='<tr class="liste_titre">'; |
|
1013 | + $out.='<td>#</td>'; |
|
1014 | + $out.='<td>' . $langs->trans("Filename") . '</td>'; |
|
1015 | + $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>'; |
|
1016 | + $out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>'; |
|
1017 | + $out.='<td align="right">' . $langs->trans("Size") . '</td>'; |
|
1018 | + $out.='<td align="right">' . $langs->trans("DateModification") . '</td>'; |
|
1019 | + $out.='</tr>'."\n"; |
|
1020 | + $tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename'); |
|
1021 | + if (is_array($tmpfilelist2) && count($tmpfilelist2)) |
|
1022 | + { |
|
1023 | + $i = 0; |
|
1024 | + foreach ($tmpfilelist2 as $file) |
|
1025 | + { |
|
1026 | + $i++; |
|
1027 | + $out.='<tr class="oddeven">'; |
|
1028 | + $out.='<td>'.$i.'</td>' . "\n"; |
|
1029 | + $out.='<td>'.$file['filename'].'</td>' . "\n"; |
|
1030 | + $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n"; |
|
1031 | + $out.='<td align="center">'.$file['md5'].'</td>' . "\n"; |
|
1032 | + $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']); |
|
1033 | + $totalsize += $size; |
|
1034 | + $out.='<td align="right">'.dol_print_size($size).'</td>' . "\n"; |
|
1035 | + $out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n"; |
|
1036 | + $out.="</tr>\n"; |
|
1037 | + } |
|
1038 | + $out.='<tr class="liste_total">'; |
|
1039 | + $out.='<td></td>' . "\n"; |
|
1040 | + $out.='<td>'.$langs->trans("Total").'</td>' . "\n"; |
|
1041 | + $out.='<td align="center"></td>' . "\n"; |
|
1042 | + $out.='<td align="center"></td>' . "\n"; |
|
1043 | + $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n"; |
|
1044 | + $out.='<td align="right"></td>' . "\n"; |
|
1045 | + $out.="</tr>\n"; |
|
1046 | + } |
|
1047 | + else |
|
1048 | + { |
|
1049 | + $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
1050 | + } |
|
1051 | + $out.='</table>'; |
|
1052 | + $out.='</div>'; |
|
1053 | + |
|
1054 | + $out.='<br>'; |
|
1055 | + |
|
1056 | + // Files added |
|
1057 | + $out.=load_fiche_titre($langs->trans("FilesAdded")); |
|
1058 | + |
|
1059 | + $totalsize = 0; |
|
1060 | + $out.='<div class="div-table-responsive-no-min">'; |
|
1061 | + $out.='<table class="noborder">'; |
|
1062 | + $out.='<tr class="liste_titre">'; |
|
1063 | + $out.='<td>#</td>'; |
|
1064 | + $out.='<td>' . $langs->trans("Filename") . '</td>'; |
|
1065 | + $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>'; |
|
1066 | + $out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>'; |
|
1067 | + $out.='<td align="right">' . $langs->trans("Size") . '</td>'; |
|
1068 | + $out.='<td align="right">' . $langs->trans("DateModification") . '</td>'; |
|
1069 | + $out.='</tr>'."\n"; |
|
1070 | + $tmpfilelist3 = dol_sort_array($file_list['added'], 'filename'); |
|
1071 | + if (is_array($tmpfilelist3) && count($tmpfilelist3)) |
|
1072 | + { |
|
1073 | + $i = 0; |
|
1074 | + foreach ($tmpfilelist3 as $file) |
|
1075 | + { |
|
1076 | + $i++; |
|
1077 | + $out.='<tr class="oddeven">'; |
|
1078 | + $out.='<td>'.$i.'</td>' . "\n"; |
|
1079 | + $out.='<td>'.$file['filename'].'</td>' . "\n"; |
|
1080 | + $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n"; |
|
1081 | + $out.='<td align="center">'.$file['md5'].'</td>' . "\n"; |
|
1082 | + $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']); |
|
1083 | + $totalsize += $size; |
|
1084 | + $out.='<td align="right">'.dol_print_size($size).'</td>' . "\n"; |
|
1085 | + $out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n"; |
|
1086 | + $out.="</tr>\n"; |
|
1087 | + } |
|
1088 | + $out.='<tr class="liste_total">'; |
|
1089 | + $out.='<td></td>' . "\n"; |
|
1090 | + $out.='<td>'.$langs->trans("Total").'</td>' . "\n"; |
|
1091 | + $out.='<td align="center"></td>' . "\n"; |
|
1092 | + $out.='<td align="center"></td>' . "\n"; |
|
1093 | + $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n"; |
|
1094 | + $out.='<td align="right"></td>' . "\n"; |
|
1095 | + $out.="</tr>\n"; |
|
1096 | + } |
|
1097 | + else |
|
1098 | + { |
|
1099 | + $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
1100 | + } |
|
1101 | + $out.='</table>'; |
|
1102 | + $out.='</div>'; |
|
1103 | + |
|
1104 | + |
|
1105 | + // Show warning |
|
1106 | + if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) |
|
1107 | + { |
|
1108 | + //setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs'); |
|
1109 | + } |
|
1110 | + else |
|
1111 | + { |
|
1112 | + //setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings'); |
|
1113 | + } |
|
1114 | + } |
|
1115 | + else |
|
1116 | + { |
|
1117 | + throw new RestException(500, 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile); |
|
1118 | + } |
|
1119 | + |
|
1120 | + |
|
1121 | + // Scan scripts |
|
1122 | + |
|
1123 | + |
|
1124 | + asort($checksumconcat); // Sort list of checksum |
|
1125 | + //var_dump($checksumconcat); |
|
1126 | + $checksumget = md5(join(',',$checksumconcat)); |
|
1127 | + $checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum); |
|
1128 | + |
|
1129 | + $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown")); |
|
1130 | + if ($checksumget == $checksumtoget) |
|
1131 | + { |
|
1132 | + if (count($file_list['added'])) |
|
1133 | + { |
|
1134 | + $resultcode = 'warning'; |
|
1135 | + $resultcomment='FileIntegrityIsOkButFilesWereAdded'; |
|
1136 | + //$outcurrentchecksum = $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>'; |
|
1137 | + $outcurrentchecksum = $checksumget; |
|
1138 | + } |
|
1139 | + else |
|
1140 | + { |
|
1141 | + $resultcode = 'ok'; |
|
1142 | + $resultcomment='Success'; |
|
1143 | + //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>'; |
|
1144 | + $outcurrentchecksum = $checksumget; |
|
1145 | + } |
|
1146 | + } |
|
1147 | + else |
|
1148 | + { |
|
1149 | + $resultcode = 'error'; |
|
1150 | + $resultcomment='Error'; |
|
1151 | + //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>'; |
|
1152 | + $outcurrentchecksum = $checksumget; |
|
1153 | + } |
|
1154 | + } |
|
1155 | + else { |
|
1156 | + throw new RestException(404, 'No signature file known'); |
|
1157 | + } |
|
1158 | + |
|
1159 | + return array('resultcode'=>$resultcode, 'resultcomment'=>$resultcomment, 'expectedchecksum'=> $outexpectedchecksum, 'currentchecksum'=> $outcurrentchecksum, 'out'=>$out); |
|
1160 | 1160 | } |
1161 | 1161 | } |
@@ -66,22 +66,22 @@ discard block |
||
66 | 66 | $list = array(); |
67 | 67 | |
68 | 68 | $sql = "SELECT id, code, type, libelle as label, module"; |
69 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement as t"; |
|
70 | - $sql.= " WHERE t.entity IN (".getEntity('c_paiement').")"; |
|
71 | - $sql.= " AND t.active = ".$active; |
|
69 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_paiement as t"; |
|
70 | + $sql .= " WHERE t.entity IN (".getEntity('c_paiement').")"; |
|
71 | + $sql .= " AND t.active = ".$active; |
|
72 | 72 | // Add sql filters |
73 | 73 | if ($sqlfilters) |
74 | 74 | { |
75 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
75 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
76 | 76 | { |
77 | 77 | throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters); |
78 | 78 | } |
79 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
80 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
79 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
80 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
84 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
84 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
85 | 85 | |
86 | 86 | if ($limit) { |
87 | 87 | if ($page < 0) { |
@@ -135,19 +135,19 @@ discard block |
||
135 | 135 | // Note: The filter is not applied in the SQL request because it must |
136 | 136 | // be applied to the translated names, not to the names in database. |
137 | 137 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country as t"; |
138 | - $sql.=" WHERE 1 = 1"; |
|
138 | + $sql .= " WHERE 1 = 1"; |
|
139 | 139 | // Add sql filters |
140 | 140 | if ($sqlfilters) |
141 | 141 | { |
142 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
142 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
143 | 143 | { |
144 | 144 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
145 | 145 | } |
146 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
147 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
146 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
147 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
148 | 148 | } |
149 | 149 | |
150 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
150 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
151 | 151 | |
152 | 152 | if ($limit) { |
153 | 153 | if ($page < 0) { |
@@ -233,21 +233,21 @@ discard block |
||
233 | 233 | $list = array(); |
234 | 234 | |
235 | 235 | $sql = "SELECT rowid, code, label"; |
236 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_availability as t"; |
|
237 | - $sql.= " WHERE t.active = ".$active; |
|
236 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_availability as t"; |
|
237 | + $sql .= " WHERE t.active = ".$active; |
|
238 | 238 | // Add sql filters |
239 | 239 | if ($sqlfilters) |
240 | 240 | { |
241 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
241 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
242 | 242 | { |
243 | 243 | throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters); |
244 | 244 | } |
245 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
246 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
245 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
246 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | |
250 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
250 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
251 | 251 | |
252 | 252 | if ($limit) { |
253 | 253 | if ($page < 0) { |
@@ -338,23 +338,23 @@ discard block |
||
338 | 338 | $list = array(); |
339 | 339 | |
340 | 340 | $sql = "SELECT id, code, type, libelle as label, module"; |
341 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t"; |
|
342 | - $sql.= " WHERE t.active = 1"; |
|
343 | - if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'"; |
|
344 | - if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; |
|
341 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t"; |
|
342 | + $sql .= " WHERE t.active = 1"; |
|
343 | + if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'"; |
|
344 | + if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'"; |
|
345 | 345 | // Add sql filters |
346 | 346 | if ($sqlfilters) |
347 | 347 | { |
348 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
348 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
349 | 349 | { |
350 | 350 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
351 | 351 | } |
352 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
353 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
352 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
353 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | |
357 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
357 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
358 | 358 | |
359 | 359 | if ($limit) { |
360 | 360 | if ($page < 0) { |
@@ -400,22 +400,22 @@ discard block |
||
400 | 400 | $list = array(); |
401 | 401 | |
402 | 402 | $sql = "SELECT rowid, code, label, module"; |
403 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_civility as t"; |
|
404 | - $sql.= " WHERE t.active = 1"; |
|
405 | - if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; |
|
403 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_civility as t"; |
|
404 | + $sql .= " WHERE t.active = 1"; |
|
405 | + if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'"; |
|
406 | 406 | // Add sql filters |
407 | 407 | if ($sqlfilters) |
408 | 408 | { |
409 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
409 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
410 | 410 | { |
411 | 411 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
412 | 412 | } |
413 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
414 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
413 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
414 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | |
418 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
418 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
419 | 419 | |
420 | 420 | if ($limit) { |
421 | 421 | if ($page < 0) { |
@@ -458,27 +458,27 @@ discard block |
||
458 | 458 | { |
459 | 459 | $list = array(); |
460 | 460 | |
461 | - if ($type == 'thirdparty') $type='societe'; |
|
462 | - if ($type == 'contact') $type='socpeople'; |
|
461 | + if ($type == 'thirdparty') $type = 'societe'; |
|
462 | + if ($type == 'contact') $type = 'socpeople'; |
|
463 | 463 | |
464 | 464 | $sql = "SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.fielddefault, t.fieldcomputed"; |
465 | - $sql.= " FROM ".MAIN_DB_PREFIX."extrafields as t"; |
|
466 | - $sql.= " WHERE t.entity IN (".getEntity('extrafields').")"; |
|
467 | - if (! empty($type)) $sql.= " AND t.elementtype = '".$this->db->escape($type)."'"; |
|
465 | + $sql .= " FROM ".MAIN_DB_PREFIX."extrafields as t"; |
|
466 | + $sql .= " WHERE t.entity IN (".getEntity('extrafields').")"; |
|
467 | + if (!empty($type)) $sql .= " AND t.elementtype = '".$this->db->escape($type)."'"; |
|
468 | 468 | // Add sql filters |
469 | 469 | if ($sqlfilters) |
470 | 470 | { |
471 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
471 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
472 | 472 | { |
473 | 473 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
474 | 474 | } |
475 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
476 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
475 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
476 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
477 | 477 | } |
478 | 478 | |
479 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
479 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
480 | 480 | |
481 | - $resql=$this->db->query($sql); |
|
481 | + $resql = $this->db->query($sql); |
|
482 | 482 | if ($resql) |
483 | 483 | { |
484 | 484 | if ($this->db->num_rows($resql)) |
@@ -486,19 +486,19 @@ discard block |
||
486 | 486 | while ($tab = $this->db->fetch_object($resql)) |
487 | 487 | { |
488 | 488 | // New usage |
489 | - $list[$tab->elementtype][$tab->name]['type']=$tab->type; |
|
490 | - $list[$tab->elementtype][$tab->name]['label']=$tab->label; |
|
491 | - $list[$tab->elementtype][$tab->name]['size']=$tab->size; |
|
492 | - $list[$tab->elementtype][$tab->name]['elementtype']=$tab->elementtype; |
|
493 | - $list[$tab->elementtype][$tab->name]['default']=$tab->fielddefault; |
|
494 | - $list[$tab->elementtype][$tab->name]['computed']=$tab->fieldcomputed; |
|
495 | - $list[$tab->elementtype][$tab->name]['unique']=$tab->fieldunique; |
|
496 | - $list[$tab->elementtype][$tab->name]['required']=$tab->fieldrequired; |
|
497 | - $list[$tab->elementtype][$tab->name]['param']=($tab->param ? unserialize($tab->param) : ''); |
|
498 | - $list[$tab->elementtype][$tab->name]['pos']=$tab->pos; |
|
499 | - $list[$tab->elementtype][$tab->name]['alwayseditable']=$tab->alwayseditable; |
|
500 | - $list[$tab->elementtype][$tab->name]['perms']=$tab->perms; |
|
501 | - $list[$tab->elementtype][$tab->name]['list']=$tab->list; |
|
489 | + $list[$tab->elementtype][$tab->name]['type'] = $tab->type; |
|
490 | + $list[$tab->elementtype][$tab->name]['label'] = $tab->label; |
|
491 | + $list[$tab->elementtype][$tab->name]['size'] = $tab->size; |
|
492 | + $list[$tab->elementtype][$tab->name]['elementtype'] = $tab->elementtype; |
|
493 | + $list[$tab->elementtype][$tab->name]['default'] = $tab->fielddefault; |
|
494 | + $list[$tab->elementtype][$tab->name]['computed'] = $tab->fieldcomputed; |
|
495 | + $list[$tab->elementtype][$tab->name]['unique'] = $tab->fieldunique; |
|
496 | + $list[$tab->elementtype][$tab->name]['required'] = $tab->fieldrequired; |
|
497 | + $list[$tab->elementtype][$tab->name]['param'] = ($tab->param ? unserialize($tab->param) : ''); |
|
498 | + $list[$tab->elementtype][$tab->name]['pos'] = $tab->pos; |
|
499 | + $list[$tab->elementtype][$tab->name]['alwayseditable'] = $tab->alwayseditable; |
|
500 | + $list[$tab->elementtype][$tab->name]['perms'] = $tab->perms; |
|
501 | + $list[$tab->elementtype][$tab->name]['list'] = $tab->list; |
|
502 | 502 | } |
503 | 503 | } |
504 | 504 | } |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror()); |
508 | 508 | } |
509 | 509 | |
510 | - if (! count($list)) |
|
510 | + if (!count($list)) |
|
511 | 511 | { |
512 | 512 | throw new RestException(404, 'No extrafield found'); |
513 | 513 | } |
@@ -537,23 +537,23 @@ discard block |
||
537 | 537 | $list = array(); |
538 | 538 | |
539 | 539 | $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country"; |
540 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as t"; |
|
541 | - $sql.= " WHERE t.active = 1"; |
|
542 | - if ($zipcode) $sql.=" AND t.zip LIKE '%" . $this->db->escape($zipcode) . "%'"; |
|
543 | - if ($town) $sql.=" AND t.town LIKE '%" . $this->db->escape($town) . "%'"; |
|
540 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_ziptown as t"; |
|
541 | + $sql .= " WHERE t.active = 1"; |
|
542 | + if ($zipcode) $sql .= " AND t.zip LIKE '%".$this->db->escape($zipcode)."%'"; |
|
543 | + if ($town) $sql .= " AND t.town LIKE '%".$this->db->escape($town)."%'"; |
|
544 | 544 | // Add sql filters |
545 | 545 | if ($sqlfilters) |
546 | 546 | { |
547 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
547 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
548 | 548 | { |
549 | 549 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
550 | 550 | } |
551 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
552 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
551 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
552 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | |
556 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
556 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
557 | 557 | |
558 | 558 | if ($limit) { |
559 | 559 | if ($page < 0) { |
@@ -601,22 +601,22 @@ discard block |
||
601 | 601 | $list = array(); |
602 | 602 | |
603 | 603 | $sql = "SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module"; |
604 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_payment_term as t"; |
|
605 | - $sql.= " WHERE t.entity IN (".getEntity('c_payment_term').")"; |
|
606 | - $sql.= " AND t.active = ".$active; |
|
604 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_payment_term as t"; |
|
605 | + $sql .= " WHERE t.entity IN (".getEntity('c_payment_term').")"; |
|
606 | + $sql .= " AND t.active = ".$active; |
|
607 | 607 | // Add sql filters |
608 | 608 | if ($sqlfilters) |
609 | 609 | { |
610 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
610 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
611 | 611 | { |
612 | 612 | throw new RestException(400, 'Error when validating parameter sqlfilters '.$sqlfilters); |
613 | 613 | } |
614 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
615 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
614 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
615 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | |
619 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
619 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
620 | 620 | |
621 | 621 | if ($limit) { |
622 | 622 | if ($page < 0) { |
@@ -661,21 +661,21 @@ discard block |
||
661 | 661 | $list = array(); |
662 | 662 | |
663 | 663 | $sql = "SELECT rowid, code, pos, label, use_default, description"; |
664 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t"; |
|
665 | - $sql.= " WHERE t.active = 1"; |
|
664 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t"; |
|
665 | + $sql .= " WHERE t.active = 1"; |
|
666 | 666 | // Add sql filters |
667 | 667 | if ($sqlfilters) |
668 | 668 | { |
669 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
669 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
670 | 670 | { |
671 | 671 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
672 | 672 | } |
673 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
674 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
673 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
674 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | |
678 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
678 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
679 | 679 | |
680 | 680 | if ($limit) { |
681 | 681 | if ($page < 0) { |
@@ -720,21 +720,21 @@ discard block |
||
720 | 720 | $list = array(); |
721 | 721 | |
722 | 722 | $sql = "SELECT rowid, code, pos, label, use_default, color, description"; |
723 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t"; |
|
724 | - $sql.= " WHERE t.active = 1"; |
|
723 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t"; |
|
724 | + $sql .= " WHERE t.active = 1"; |
|
725 | 725 | // Add sql filters |
726 | 726 | if ($sqlfilters) |
727 | 727 | { |
728 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
728 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
729 | 729 | { |
730 | 730 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
731 | 731 | } |
732 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
733 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
732 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
733 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | |
737 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
737 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
738 | 738 | |
739 | 739 | if ($limit) { |
740 | 740 | if ($page < 0) { |
@@ -779,23 +779,23 @@ discard block |
||
779 | 779 | $list = array(); |
780 | 780 | |
781 | 781 | $sql = "SELECT rowid, code, pos, label, use_default, description"; |
782 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t"; |
|
783 | - $sql.= " WHERE t.active = 1"; |
|
784 | - if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'"; |
|
785 | - if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; |
|
782 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t"; |
|
783 | + $sql .= " WHERE t.active = 1"; |
|
784 | + if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'"; |
|
785 | + if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'"; |
|
786 | 786 | // Add sql filters |
787 | 787 | if ($sqlfilters) |
788 | 788 | { |
789 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
789 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
790 | 790 | { |
791 | 791 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
792 | 792 | } |
793 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
794 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
793 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
794 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | |
798 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
798 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
799 | 799 | |
800 | 800 | if ($limit) { |
801 | 801 | if ($page < 0) { |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | { |
837 | 837 | global $langs, $conf; |
838 | 838 | |
839 | - if (! DolibarrApiAccess::$user->admin |
|
839 | + if (!DolibarrApiAccess::$user->admin |
|
840 | 840 | && (empty($conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK)) |
841 | 841 | { |
842 | 842 | throw new RestException(503, 'Error API open to admin users only or to login user defined with constant API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK'); |
@@ -854,13 +854,13 @@ discard block |
||
854 | 854 | $file_list = array('missing' => array(), 'updated' => array()); |
855 | 855 | |
856 | 856 | // Local file to compare to |
857 | - $xmlshortfile = GETPOST('xmlshortfile')?GETPOST('xmlshortfile'):'/install/filelist-'.DOL_VERSION.'.xml'; |
|
857 | + $xmlshortfile = GETPOST('xmlshortfile') ?GETPOST('xmlshortfile') : '/install/filelist-'.DOL_VERSION.'.xml'; |
|
858 | 858 | $xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile; |
859 | 859 | // Remote file to compare to |
860 | 860 | $xmlremote = ($target == 'default' ? '' : $target); |
861 | - if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL; |
|
862 | - $param='MAIN_FILECHECK_URL_'.DOL_VERSION; |
|
863 | - if (empty($xmlremote) && ! empty($conf->global->$param)) $xmlremote = $conf->global->$param; |
|
861 | + if (empty($xmlremote) && !empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL; |
|
862 | + $param = 'MAIN_FILECHECK_URL_'.DOL_VERSION; |
|
863 | + if (empty($xmlremote) && !empty($conf->global->$param)) $xmlremote = $conf->global->$param; |
|
864 | 864 | if (empty($xmlremote)) $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml'; |
865 | 865 | |
866 | 866 | if ($target == 'local') |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | } |
872 | 872 | else |
873 | 873 | { |
874 | - throw new RestException(500, $langs->trans('XmlNotFound') . ': ' . $xmlfile); |
|
874 | + throw new RestException(500, $langs->trans('XmlNotFound').': '.$xmlfile); |
|
875 | 875 | } |
876 | 876 | } |
877 | 877 | else |
@@ -879,7 +879,7 @@ discard block |
||
879 | 879 | $xmlarray = getURLContent($xmlremote); |
880 | 880 | |
881 | 881 | // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...) |
882 | - if (! $xmlarray['curl_error_no'] && $xmlarray['http_code'] != '404') |
|
882 | + if (!$xmlarray['curl_error_no'] && $xmlarray['http_code'] != '404') |
|
883 | 883 | { |
884 | 884 | $xmlfile = $xmlarray['content']; |
885 | 885 | //print "xmlfilestart".$xmlfile."endxmlfile"; |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | } |
888 | 888 | else |
889 | 889 | { |
890 | - $errormsg=$langs->trans('XmlNotFound') . ': ' . $xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg']; |
|
890 | + $errormsg = $langs->trans('XmlNotFound').': '.$xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg']; |
|
891 | 891 | throw new RestException(500, $errormsg); |
892 | 892 | } |
893 | 893 | } |
@@ -903,83 +903,83 @@ discard block |
||
903 | 903 | // Forced constants |
904 | 904 | if (is_object($xml->dolibarr_constants[0])) |
905 | 905 | { |
906 | - $out.=load_fiche_titre($langs->trans("ForcedConstants")); |
|
906 | + $out .= load_fiche_titre($langs->trans("ForcedConstants")); |
|
907 | 907 | |
908 | - $out.='<div class="div-table-responsive-no-min">'; |
|
909 | - $out.='<table class="noborder">'; |
|
910 | - $out.='<tr class="liste_titre">'; |
|
911 | - $out.='<td>#</td>'; |
|
912 | - $out.='<td>' . $langs->trans("Constant") . '</td>'; |
|
913 | - $out.='<td align="center">' . $langs->trans("ExpectedValue") . '</td>'; |
|
914 | - $out.='<td align="center">' . $langs->trans("Value") . '</td>'; |
|
915 | - $out.='</tr>'."\n"; |
|
908 | + $out .= '<div class="div-table-responsive-no-min">'; |
|
909 | + $out .= '<table class="noborder">'; |
|
910 | + $out .= '<tr class="liste_titre">'; |
|
911 | + $out .= '<td>#</td>'; |
|
912 | + $out .= '<td>'.$langs->trans("Constant").'</td>'; |
|
913 | + $out .= '<td align="center">'.$langs->trans("ExpectedValue").'</td>'; |
|
914 | + $out .= '<td align="center">'.$langs->trans("Value").'</td>'; |
|
915 | + $out .= '</tr>'."\n"; |
|
916 | 916 | |
917 | 917 | $i = 0; |
918 | 918 | foreach ($xml->dolibarr_constants[0]->constant as $constant) // $constant is a simpleXMLElement |
919 | 919 | { |
920 | - $constname=$constant['name']; |
|
921 | - $constvalue=(string) $constant; |
|
922 | - $constvalue = (empty($constvalue)?'0':$constvalue); |
|
920 | + $constname = $constant['name']; |
|
921 | + $constvalue = (string) $constant; |
|
922 | + $constvalue = (empty($constvalue) ? '0' : $constvalue); |
|
923 | 923 | // Value found |
924 | - $value=''; |
|
925 | - if ($constname && $conf->global->$constname != '') $value=$conf->global->$constname; |
|
926 | - $valueforchecksum=(empty($value)?'0':$value); |
|
924 | + $value = ''; |
|
925 | + if ($constname && $conf->global->$constname != '') $value = $conf->global->$constname; |
|
926 | + $valueforchecksum = (empty($value) ? '0' : $value); |
|
927 | 927 | |
928 | - $checksumconcat[]=$valueforchecksum; |
|
928 | + $checksumconcat[] = $valueforchecksum; |
|
929 | 929 | |
930 | 930 | $i++; |
931 | - $out.='<tr class="oddeven">'; |
|
932 | - $out.='<td>'.$i.'</td>' . "\n"; |
|
933 | - $out.='<td>'.$constname.'</td>' . "\n"; |
|
934 | - $out.='<td align="center">'.$constvalue.'</td>' . "\n"; |
|
935 | - $out.='<td align="center">'.$valueforchecksum.'</td>' . "\n"; |
|
936 | - $out.="</tr>\n"; |
|
931 | + $out .= '<tr class="oddeven">'; |
|
932 | + $out .= '<td>'.$i.'</td>'."\n"; |
|
933 | + $out .= '<td>'.$constname.'</td>'."\n"; |
|
934 | + $out .= '<td align="center">'.$constvalue.'</td>'."\n"; |
|
935 | + $out .= '<td align="center">'.$valueforchecksum.'</td>'."\n"; |
|
936 | + $out .= "</tr>\n"; |
|
937 | 937 | } |
938 | 938 | |
939 | - if ($i==0) |
|
939 | + if ($i == 0) |
|
940 | 940 | { |
941 | - $out.='<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
941 | + $out .= '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
942 | 942 | } |
943 | - $out.='</table>'; |
|
944 | - $out.='</div>'; |
|
943 | + $out .= '</table>'; |
|
944 | + $out .= '</div>'; |
|
945 | 945 | |
946 | - $out.='<br>'; |
|
946 | + $out .= '<br>'; |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | // Scan htdocs |
950 | 950 | if (is_object($xml->dolibarr_htdocs_dir[0])) |
951 | 951 | { |
952 | 952 | //var_dump($xml->dolibarr_htdocs_dir[0]['includecustom']);exit; |
953 | - $includecustom=(empty($xml->dolibarr_htdocs_dir[0]['includecustom'])?0:$xml->dolibarr_htdocs_dir[0]['includecustom']); |
|
953 | + $includecustom = (empty($xml->dolibarr_htdocs_dir[0]['includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0]['includecustom']); |
|
954 | 954 | |
955 | 955 | // Defined qualified files (must be same than into generate_filelist_xml.php) |
956 | - $regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$'; |
|
957 | - $regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs |
|
956 | + $regextoinclude = '\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$'; |
|
957 | + $regextoexclude = '('.($includecustom ? '' : 'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs |
|
958 | 958 | $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude); |
959 | 959 | |
960 | 960 | // Fill file_list with files in signature, new files, modified files |
961 | - $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat, $scanfiles); // Fill array $file_list |
|
961 | + $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat, $scanfiles); // Fill array $file_list |
|
962 | 962 | // Complete with list of new files |
963 | 963 | foreach ($scanfiles as $keyfile => $valfile) |
964 | 964 | { |
965 | - $tmprelativefilename=preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT,'/').'/','', $valfile['fullname']); |
|
966 | - if (! in_array($tmprelativefilename, $file_list['insignature'])) |
|
965 | + $tmprelativefilename = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', $valfile['fullname']); |
|
966 | + if (!in_array($tmprelativefilename, $file_list['insignature'])) |
|
967 | 967 | { |
968 | - $md5newfile=@md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file |
|
969 | - $file_list['added'][]=array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile); |
|
968 | + $md5newfile = @md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file |
|
969 | + $file_list['added'][] = array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile); |
|
970 | 970 | } |
971 | 971 | } |
972 | 972 | |
973 | 973 | // Files missings |
974 | - $out.=load_fiche_titre($langs->trans("FilesMissing")); |
|
975 | - |
|
976 | - $out.='<div class="div-table-responsive-no-min">'; |
|
977 | - $out.='<table class="noborder">'; |
|
978 | - $out.='<tr class="liste_titre">'; |
|
979 | - $out.='<td>#</td>'; |
|
980 | - $out.='<td>' . $langs->trans("Filename") . '</td>'; |
|
981 | - $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>'; |
|
982 | - $out.='</tr>'."\n"; |
|
974 | + $out .= load_fiche_titre($langs->trans("FilesMissing")); |
|
975 | + |
|
976 | + $out .= '<div class="div-table-responsive-no-min">'; |
|
977 | + $out .= '<table class="noborder">'; |
|
978 | + $out .= '<tr class="liste_titre">'; |
|
979 | + $out .= '<td>#</td>'; |
|
980 | + $out .= '<td>'.$langs->trans("Filename").'</td>'; |
|
981 | + $out .= '<td align="center">'.$langs->trans("ExpectedChecksum").'</td>'; |
|
982 | + $out .= '</tr>'."\n"; |
|
983 | 983 | $tmpfilelist = dol_sort_array($file_list['missing'], 'filename'); |
984 | 984 | if (is_array($tmpfilelist) && count($tmpfilelist)) |
985 | 985 | { |
@@ -987,36 +987,36 @@ discard block |
||
987 | 987 | foreach ($tmpfilelist as $file) |
988 | 988 | { |
989 | 989 | $i++; |
990 | - $out.='<tr class="oddeven">'; |
|
991 | - $out.='<td>'.$i.'</td>' . "\n"; |
|
992 | - $out.='<td>'.$file['filename'].'</td>' . "\n"; |
|
993 | - $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n"; |
|
994 | - $out.="</tr>\n"; |
|
990 | + $out .= '<tr class="oddeven">'; |
|
991 | + $out .= '<td>'.$i.'</td>'."\n"; |
|
992 | + $out .= '<td>'.$file['filename'].'</td>'."\n"; |
|
993 | + $out .= '<td align="center">'.$file['expectedmd5'].'</td>'."\n"; |
|
994 | + $out .= "</tr>\n"; |
|
995 | 995 | } |
996 | 996 | } |
997 | 997 | else |
998 | 998 | { |
999 | - $out.='<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
999 | + $out .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
1000 | 1000 | } |
1001 | - $out.='</table>'; |
|
1002 | - $out.='</div>'; |
|
1001 | + $out .= '</table>'; |
|
1002 | + $out .= '</div>'; |
|
1003 | 1003 | |
1004 | - $out.='<br>'; |
|
1004 | + $out .= '<br>'; |
|
1005 | 1005 | |
1006 | 1006 | // Files modified |
1007 | - $out.=load_fiche_titre($langs->trans("FilesModified")); |
|
1008 | - |
|
1009 | - $totalsize=0; |
|
1010 | - $out.='<div class="div-table-responsive-no-min">'; |
|
1011 | - $out.='<table class="noborder">'; |
|
1012 | - $out.='<tr class="liste_titre">'; |
|
1013 | - $out.='<td>#</td>'; |
|
1014 | - $out.='<td>' . $langs->trans("Filename") . '</td>'; |
|
1015 | - $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>'; |
|
1016 | - $out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>'; |
|
1017 | - $out.='<td align="right">' . $langs->trans("Size") . '</td>'; |
|
1018 | - $out.='<td align="right">' . $langs->trans("DateModification") . '</td>'; |
|
1019 | - $out.='</tr>'."\n"; |
|
1007 | + $out .= load_fiche_titre($langs->trans("FilesModified")); |
|
1008 | + |
|
1009 | + $totalsize = 0; |
|
1010 | + $out .= '<div class="div-table-responsive-no-min">'; |
|
1011 | + $out .= '<table class="noborder">'; |
|
1012 | + $out .= '<tr class="liste_titre">'; |
|
1013 | + $out .= '<td>#</td>'; |
|
1014 | + $out .= '<td>'.$langs->trans("Filename").'</td>'; |
|
1015 | + $out .= '<td align="center">'.$langs->trans("ExpectedChecksum").'</td>'; |
|
1016 | + $out .= '<td align="center">'.$langs->trans("CurrentChecksum").'</td>'; |
|
1017 | + $out .= '<td align="right">'.$langs->trans("Size").'</td>'; |
|
1018 | + $out .= '<td align="right">'.$langs->trans("DateModification").'</td>'; |
|
1019 | + $out .= '</tr>'."\n"; |
|
1020 | 1020 | $tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename'); |
1021 | 1021 | if (is_array($tmpfilelist2) && count($tmpfilelist2)) |
1022 | 1022 | { |
@@ -1024,49 +1024,49 @@ discard block |
||
1024 | 1024 | foreach ($tmpfilelist2 as $file) |
1025 | 1025 | { |
1026 | 1026 | $i++; |
1027 | - $out.='<tr class="oddeven">'; |
|
1028 | - $out.='<td>'.$i.'</td>' . "\n"; |
|
1029 | - $out.='<td>'.$file['filename'].'</td>' . "\n"; |
|
1030 | - $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n"; |
|
1031 | - $out.='<td align="center">'.$file['md5'].'</td>' . "\n"; |
|
1027 | + $out .= '<tr class="oddeven">'; |
|
1028 | + $out .= '<td>'.$i.'</td>'."\n"; |
|
1029 | + $out .= '<td>'.$file['filename'].'</td>'."\n"; |
|
1030 | + $out .= '<td align="center">'.$file['expectedmd5'].'</td>'."\n"; |
|
1031 | + $out .= '<td align="center">'.$file['md5'].'</td>'."\n"; |
|
1032 | 1032 | $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']); |
1033 | 1033 | $totalsize += $size; |
1034 | - $out.='<td align="right">'.dol_print_size($size).'</td>' . "\n"; |
|
1035 | - $out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n"; |
|
1036 | - $out.="</tr>\n"; |
|
1034 | + $out .= '<td align="right">'.dol_print_size($size).'</td>'."\n"; |
|
1035 | + $out .= '<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n"; |
|
1036 | + $out .= "</tr>\n"; |
|
1037 | 1037 | } |
1038 | - $out.='<tr class="liste_total">'; |
|
1039 | - $out.='<td></td>' . "\n"; |
|
1040 | - $out.='<td>'.$langs->trans("Total").'</td>' . "\n"; |
|
1041 | - $out.='<td align="center"></td>' . "\n"; |
|
1042 | - $out.='<td align="center"></td>' . "\n"; |
|
1043 | - $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n"; |
|
1044 | - $out.='<td align="right"></td>' . "\n"; |
|
1045 | - $out.="</tr>\n"; |
|
1038 | + $out .= '<tr class="liste_total">'; |
|
1039 | + $out .= '<td></td>'."\n"; |
|
1040 | + $out .= '<td>'.$langs->trans("Total").'</td>'."\n"; |
|
1041 | + $out .= '<td align="center"></td>'."\n"; |
|
1042 | + $out .= '<td align="center"></td>'."\n"; |
|
1043 | + $out .= '<td align="right">'.dol_print_size($totalsize).'</td>'."\n"; |
|
1044 | + $out .= '<td align="right"></td>'."\n"; |
|
1045 | + $out .= "</tr>\n"; |
|
1046 | 1046 | } |
1047 | 1047 | else |
1048 | 1048 | { |
1049 | - $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
1049 | + $out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
1050 | 1050 | } |
1051 | - $out.='</table>'; |
|
1052 | - $out.='</div>'; |
|
1051 | + $out .= '</table>'; |
|
1052 | + $out .= '</div>'; |
|
1053 | 1053 | |
1054 | - $out.='<br>'; |
|
1054 | + $out .= '<br>'; |
|
1055 | 1055 | |
1056 | 1056 | // Files added |
1057 | - $out.=load_fiche_titre($langs->trans("FilesAdded")); |
|
1057 | + $out .= load_fiche_titre($langs->trans("FilesAdded")); |
|
1058 | 1058 | |
1059 | 1059 | $totalsize = 0; |
1060 | - $out.='<div class="div-table-responsive-no-min">'; |
|
1061 | - $out.='<table class="noborder">'; |
|
1062 | - $out.='<tr class="liste_titre">'; |
|
1063 | - $out.='<td>#</td>'; |
|
1064 | - $out.='<td>' . $langs->trans("Filename") . '</td>'; |
|
1065 | - $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>'; |
|
1066 | - $out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>'; |
|
1067 | - $out.='<td align="right">' . $langs->trans("Size") . '</td>'; |
|
1068 | - $out.='<td align="right">' . $langs->trans("DateModification") . '</td>'; |
|
1069 | - $out.='</tr>'."\n"; |
|
1060 | + $out .= '<div class="div-table-responsive-no-min">'; |
|
1061 | + $out .= '<table class="noborder">'; |
|
1062 | + $out .= '<tr class="liste_titre">'; |
|
1063 | + $out .= '<td>#</td>'; |
|
1064 | + $out .= '<td>'.$langs->trans("Filename").'</td>'; |
|
1065 | + $out .= '<td align="center">'.$langs->trans("ExpectedChecksum").'</td>'; |
|
1066 | + $out .= '<td align="center">'.$langs->trans("CurrentChecksum").'</td>'; |
|
1067 | + $out .= '<td align="right">'.$langs->trans("Size").'</td>'; |
|
1068 | + $out .= '<td align="right">'.$langs->trans("DateModification").'</td>'; |
|
1069 | + $out .= '</tr>'."\n"; |
|
1070 | 1070 | $tmpfilelist3 = dol_sort_array($file_list['added'], 'filename'); |
1071 | 1071 | if (is_array($tmpfilelist3) && count($tmpfilelist3)) |
1072 | 1072 | { |
@@ -1074,32 +1074,32 @@ discard block |
||
1074 | 1074 | foreach ($tmpfilelist3 as $file) |
1075 | 1075 | { |
1076 | 1076 | $i++; |
1077 | - $out.='<tr class="oddeven">'; |
|
1078 | - $out.='<td>'.$i.'</td>' . "\n"; |
|
1079 | - $out.='<td>'.$file['filename'].'</td>' . "\n"; |
|
1080 | - $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n"; |
|
1081 | - $out.='<td align="center">'.$file['md5'].'</td>' . "\n"; |
|
1077 | + $out .= '<tr class="oddeven">'; |
|
1078 | + $out .= '<td>'.$i.'</td>'."\n"; |
|
1079 | + $out .= '<td>'.$file['filename'].'</td>'."\n"; |
|
1080 | + $out .= '<td align="center">'.$file['expectedmd5'].'</td>'."\n"; |
|
1081 | + $out .= '<td align="center">'.$file['md5'].'</td>'."\n"; |
|
1082 | 1082 | $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']); |
1083 | 1083 | $totalsize += $size; |
1084 | - $out.='<td align="right">'.dol_print_size($size).'</td>' . "\n"; |
|
1085 | - $out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n"; |
|
1086 | - $out.="</tr>\n"; |
|
1084 | + $out .= '<td align="right">'.dol_print_size($size).'</td>'."\n"; |
|
1085 | + $out .= '<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n"; |
|
1086 | + $out .= "</tr>\n"; |
|
1087 | 1087 | } |
1088 | - $out.='<tr class="liste_total">'; |
|
1089 | - $out.='<td></td>' . "\n"; |
|
1090 | - $out.='<td>'.$langs->trans("Total").'</td>' . "\n"; |
|
1091 | - $out.='<td align="center"></td>' . "\n"; |
|
1092 | - $out.='<td align="center"></td>' . "\n"; |
|
1093 | - $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n"; |
|
1094 | - $out.='<td align="right"></td>' . "\n"; |
|
1095 | - $out.="</tr>\n"; |
|
1088 | + $out .= '<tr class="liste_total">'; |
|
1089 | + $out .= '<td></td>'."\n"; |
|
1090 | + $out .= '<td>'.$langs->trans("Total").'</td>'."\n"; |
|
1091 | + $out .= '<td align="center"></td>'."\n"; |
|
1092 | + $out .= '<td align="center"></td>'."\n"; |
|
1093 | + $out .= '<td align="right">'.dol_print_size($totalsize).'</td>'."\n"; |
|
1094 | + $out .= '<td align="right"></td>'."\n"; |
|
1095 | + $out .= "</tr>\n"; |
|
1096 | 1096 | } |
1097 | 1097 | else |
1098 | 1098 | { |
1099 | - $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
1099 | + $out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
|
1100 | 1100 | } |
1101 | - $out.='</table>'; |
|
1102 | - $out.='</div>'; |
|
1101 | + $out .= '</table>'; |
|
1102 | + $out .= '</div>'; |
|
1103 | 1103 | |
1104 | 1104 | |
1105 | 1105 | // Show warning |
@@ -1123,7 +1123,7 @@ discard block |
||
1123 | 1123 | |
1124 | 1124 | asort($checksumconcat); // Sort list of checksum |
1125 | 1125 | //var_dump($checksumconcat); |
1126 | - $checksumget = md5(join(',',$checksumconcat)); |
|
1126 | + $checksumget = md5(join(',', $checksumconcat)); |
|
1127 | 1127 | $checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum); |
1128 | 1128 | |
1129 | 1129 | $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown")); |
@@ -1132,24 +1132,24 @@ discard block |
||
1132 | 1132 | if (count($file_list['added'])) |
1133 | 1133 | { |
1134 | 1134 | $resultcode = 'warning'; |
1135 | - $resultcomment='FileIntegrityIsOkButFilesWereAdded'; |
|
1135 | + $resultcomment = 'FileIntegrityIsOkButFilesWereAdded'; |
|
1136 | 1136 | //$outcurrentchecksum = $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>'; |
1137 | - $outcurrentchecksum = $checksumget; |
|
1137 | + $outcurrentchecksum = $checksumget; |
|
1138 | 1138 | } |
1139 | 1139 | else |
1140 | 1140 | { |
1141 | 1141 | $resultcode = 'ok'; |
1142 | - $resultcomment='Success'; |
|
1142 | + $resultcomment = 'Success'; |
|
1143 | 1143 | //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>'; |
1144 | - $outcurrentchecksum = $checksumget; |
|
1144 | + $outcurrentchecksum = $checksumget; |
|
1145 | 1145 | } |
1146 | 1146 | } |
1147 | 1147 | else |
1148 | 1148 | { |
1149 | 1149 | $resultcode = 'error'; |
1150 | - $resultcomment='Error'; |
|
1150 | + $resultcomment = 'Error'; |
|
1151 | 1151 | //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>'; |
1152 | - $outcurrentchecksum = $checksumget; |
|
1152 | + $outcurrentchecksum = $checksumget; |
|
1153 | 1153 | } |
1154 | 1154 | } |
1155 | 1155 | else { |
@@ -201,8 +201,7 @@ discard block |
||
201 | 201 | |
202 | 202 | if ($country->fetch($id) < 0) { |
203 | 203 | throw new RestException(503, 'Error when retrieving country : '.$country->error); |
204 | - } |
|
205 | - else if ($country->fetch($id) == 0) { |
|
204 | + } else if ($country->fetch($id) == 0) { |
|
206 | 205 | throw new RestException(404, 'country not found'); |
207 | 206 | } |
208 | 207 | |
@@ -340,8 +339,12 @@ discard block |
||
340 | 339 | $sql = "SELECT id, code, type, libelle as label, module"; |
341 | 340 | $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t"; |
342 | 341 | $sql.= " WHERE t.active = 1"; |
343 | - if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'"; |
|
344 | - if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; |
|
342 | + if ($type) { |
|
343 | + $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'"; |
|
344 | + } |
|
345 | + if ($module) { |
|
346 | + $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; |
|
347 | + } |
|
345 | 348 | // Add sql filters |
346 | 349 | if ($sqlfilters) |
347 | 350 | { |
@@ -402,7 +405,9 @@ discard block |
||
402 | 405 | $sql = "SELECT rowid, code, label, module"; |
403 | 406 | $sql.= " FROM ".MAIN_DB_PREFIX."c_civility as t"; |
404 | 407 | $sql.= " WHERE t.active = 1"; |
405 | - if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; |
|
408 | + if ($module) { |
|
409 | + $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; |
|
410 | + } |
|
406 | 411 | // Add sql filters |
407 | 412 | if ($sqlfilters) |
408 | 413 | { |
@@ -458,13 +463,19 @@ discard block |
||
458 | 463 | { |
459 | 464 | $list = array(); |
460 | 465 | |
461 | - if ($type == 'thirdparty') $type='societe'; |
|
462 | - if ($type == 'contact') $type='socpeople'; |
|
466 | + if ($type == 'thirdparty') { |
|
467 | + $type='societe'; |
|
468 | + } |
|
469 | + if ($type == 'contact') { |
|
470 | + $type='socpeople'; |
|
471 | + } |
|
463 | 472 | |
464 | 473 | $sql = "SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.fielddefault, t.fieldcomputed"; |
465 | 474 | $sql.= " FROM ".MAIN_DB_PREFIX."extrafields as t"; |
466 | 475 | $sql.= " WHERE t.entity IN (".getEntity('extrafields').")"; |
467 | - if (! empty($type)) $sql.= " AND t.elementtype = '".$this->db->escape($type)."'"; |
|
476 | + if (! empty($type)) { |
|
477 | + $sql.= " AND t.elementtype = '".$this->db->escape($type)."'"; |
|
478 | + } |
|
468 | 479 | // Add sql filters |
469 | 480 | if ($sqlfilters) |
470 | 481 | { |
@@ -501,8 +512,7 @@ discard block |
||
501 | 512 | $list[$tab->elementtype][$tab->name]['list']=$tab->list; |
502 | 513 | } |
503 | 514 | } |
504 | - } |
|
505 | - else |
|
515 | + } else |
|
506 | 516 | { |
507 | 517 | throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror()); |
508 | 518 | } |
@@ -539,8 +549,12 @@ discard block |
||
539 | 549 | $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country"; |
540 | 550 | $sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as t"; |
541 | 551 | $sql.= " WHERE t.active = 1"; |
542 | - if ($zipcode) $sql.=" AND t.zip LIKE '%" . $this->db->escape($zipcode) . "%'"; |
|
543 | - if ($town) $sql.=" AND t.town LIKE '%" . $this->db->escape($town) . "%'"; |
|
552 | + if ($zipcode) { |
|
553 | + $sql.=" AND t.zip LIKE '%" . $this->db->escape($zipcode) . "%'"; |
|
554 | + } |
|
555 | + if ($town) { |
|
556 | + $sql.=" AND t.town LIKE '%" . $this->db->escape($town) . "%'"; |
|
557 | + } |
|
544 | 558 | // Add sql filters |
545 | 559 | if ($sqlfilters) |
546 | 560 | { |
@@ -781,8 +795,12 @@ discard block |
||
781 | 795 | $sql = "SELECT rowid, code, pos, label, use_default, description"; |
782 | 796 | $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t"; |
783 | 797 | $sql.= " WHERE t.active = 1"; |
784 | - if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'"; |
|
785 | - if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; |
|
798 | + if ($type) { |
|
799 | + $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'"; |
|
800 | + } |
|
801 | + if ($module) { |
|
802 | + $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; |
|
803 | + } |
|
786 | 804 | // Add sql filters |
787 | 805 | if ($sqlfilters) |
788 | 806 | { |
@@ -858,23 +876,27 @@ discard block |
||
858 | 876 | $xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile; |
859 | 877 | // Remote file to compare to |
860 | 878 | $xmlremote = ($target == 'default' ? '' : $target); |
861 | - if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL; |
|
879 | + if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) { |
|
880 | + $xmlremote = $conf->global->MAIN_FILECHECK_URL; |
|
881 | + } |
|
862 | 882 | $param='MAIN_FILECHECK_URL_'.DOL_VERSION; |
863 | - if (empty($xmlremote) && ! empty($conf->global->$param)) $xmlremote = $conf->global->$param; |
|
864 | - if (empty($xmlremote)) $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml'; |
|
883 | + if (empty($xmlremote) && ! empty($conf->global->$param)) { |
|
884 | + $xmlremote = $conf->global->$param; |
|
885 | + } |
|
886 | + if (empty($xmlremote)) { |
|
887 | + $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml'; |
|
888 | + } |
|
865 | 889 | |
866 | 890 | if ($target == 'local') |
867 | 891 | { |
868 | 892 | if (dol_is_file($xmlfile)) |
869 | 893 | { |
870 | 894 | $xml = simplexml_load_file($xmlfile); |
871 | - } |
|
872 | - else |
|
895 | + } else |
|
873 | 896 | { |
874 | 897 | throw new RestException(500, $langs->trans('XmlNotFound') . ': ' . $xmlfile); |
875 | 898 | } |
876 | - } |
|
877 | - else |
|
899 | + } else |
|
878 | 900 | { |
879 | 901 | $xmlarray = getURLContent($xmlremote); |
880 | 902 | |
@@ -884,8 +906,7 @@ discard block |
||
884 | 906 | $xmlfile = $xmlarray['content']; |
885 | 907 | //print "xmlfilestart".$xmlfile."endxmlfile"; |
886 | 908 | $xml = simplexml_load_string($xmlfile); |
887 | - } |
|
888 | - else |
|
909 | + } else |
|
889 | 910 | { |
890 | 911 | $errormsg=$langs->trans('XmlNotFound') . ': ' . $xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg']; |
891 | 912 | throw new RestException(500, $errormsg); |
@@ -915,14 +936,18 @@ discard block |
||
915 | 936 | $out.='</tr>'."\n"; |
916 | 937 | |
917 | 938 | $i = 0; |
918 | - foreach ($xml->dolibarr_constants[0]->constant as $constant) // $constant is a simpleXMLElement |
|
939 | + foreach ($xml->dolibarr_constants[0]->constant as $constant) { |
|
940 | + // $constant is a simpleXMLElement |
|
919 | 941 | { |
920 | 942 | $constname=$constant['name']; |
943 | + } |
|
921 | 944 | $constvalue=(string) $constant; |
922 | 945 | $constvalue = (empty($constvalue)?'0':$constvalue); |
923 | 946 | // Value found |
924 | 947 | $value=''; |
925 | - if ($constname && $conf->global->$constname != '') $value=$conf->global->$constname; |
|
948 | + if ($constname && $conf->global->$constname != '') { |
|
949 | + $value=$conf->global->$constname; |
|
950 | + } |
|
926 | 951 | $valueforchecksum=(empty($value)?'0':$value); |
927 | 952 | |
928 | 953 | $checksumconcat[]=$valueforchecksum; |
@@ -993,8 +1018,7 @@ discard block |
||
993 | 1018 | $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n"; |
994 | 1019 | $out.="</tr>\n"; |
995 | 1020 | } |
996 | - } |
|
997 | - else |
|
1021 | + } else |
|
998 | 1022 | { |
999 | 1023 | $out.='<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
1000 | 1024 | } |
@@ -1043,8 +1067,7 @@ discard block |
||
1043 | 1067 | $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n"; |
1044 | 1068 | $out.='<td align="right"></td>' . "\n"; |
1045 | 1069 | $out.="</tr>\n"; |
1046 | - } |
|
1047 | - else |
|
1070 | + } else |
|
1048 | 1071 | { |
1049 | 1072 | $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
1050 | 1073 | } |
@@ -1093,8 +1116,7 @@ discard block |
||
1093 | 1116 | $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n"; |
1094 | 1117 | $out.='<td align="right"></td>' . "\n"; |
1095 | 1118 | $out.="</tr>\n"; |
1096 | - } |
|
1097 | - else |
|
1119 | + } else |
|
1098 | 1120 | { |
1099 | 1121 | $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; |
1100 | 1122 | } |
@@ -1106,13 +1128,11 @@ discard block |
||
1106 | 1128 | if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) |
1107 | 1129 | { |
1108 | 1130 | //setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs'); |
1109 | - } |
|
1110 | - else |
|
1131 | + } else |
|
1111 | 1132 | { |
1112 | 1133 | //setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings'); |
1113 | 1134 | } |
1114 | - } |
|
1115 | - else |
|
1135 | + } else |
|
1116 | 1136 | { |
1117 | 1137 | throw new RestException(500, 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile); |
1118 | 1138 | } |
@@ -1135,24 +1155,21 @@ discard block |
||
1135 | 1155 | $resultcomment='FileIntegrityIsOkButFilesWereAdded'; |
1136 | 1156 | //$outcurrentchecksum = $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>'; |
1137 | 1157 | $outcurrentchecksum = $checksumget; |
1138 | - } |
|
1139 | - else |
|
1158 | + } else |
|
1140 | 1159 | { |
1141 | 1160 | $resultcode = 'ok'; |
1142 | 1161 | $resultcomment='Success'; |
1143 | 1162 | //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>'; |
1144 | 1163 | $outcurrentchecksum = $checksumget; |
1145 | 1164 | } |
1146 | - } |
|
1147 | - else |
|
1165 | + } else |
|
1148 | 1166 | { |
1149 | 1167 | $resultcode = 'error'; |
1150 | 1168 | $resultcomment='Error'; |
1151 | 1169 | //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>'; |
1152 | 1170 | $outcurrentchecksum = $checksumget; |
1153 | 1171 | } |
1154 | - } |
|
1155 | - else { |
|
1172 | + } else { |
|
1156 | 1173 | throw new RestException(404, 'No signature file known'); |
1157 | 1174 | } |
1158 | 1175 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | */ |
17 | 17 | |
18 | -require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php'; |
|
18 | +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; |
|
19 | 19 | |
20 | 20 | |
21 | 21 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | 'success' => array( |
40 | 40 | 'code' => 200, |
41 | 41 | 'dolibarr_version' => DOL_VERSION, |
42 | - 'access_locked' => (empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)?'0':$conf->global->MAIN_ONLY_LOGIN_ALLOWED), |
|
42 | + 'access_locked' => (empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED) ? '0' : $conf->global->MAIN_ONLY_LOGIN_ALLOWED), |
|
43 | 43 | ), |
44 | 44 | ); |
45 | 45 | } |
@@ -33,563 +33,563 @@ |
||
33 | 33 | class Documents extends DolibarrApi |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * @var array $DOCUMENT_FIELDS Mandatory fields, checked when create and update object |
|
38 | - */ |
|
39 | - static $DOCUMENT_FIELDS = array( |
|
40 | - 'modulepart' |
|
41 | - ); |
|
42 | - |
|
43 | - /** |
|
44 | - * Constructor |
|
45 | - */ |
|
46 | - function __construct() |
|
47 | - { |
|
48 | - global $db; |
|
49 | - $this->db = $db; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Download a document. |
|
55 | - * |
|
56 | - * Note that, this API is similar to using the wrapper link "documents.php" to download a file (used for |
|
57 | - * internal HTML links of documents into application), but with no need to have a session cookie (the token is used instead). |
|
58 | - * |
|
59 | - * @param string $module_part Name of module or area concerned by file download ('facture', ...) |
|
60 | - * @param string $original_file Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf) |
|
61 | - * @return array List of documents |
|
62 | - * |
|
63 | - * @throws 400 |
|
64 | - * @throws 401 |
|
65 | - * @throws 404 |
|
66 | - * @throws 200 |
|
67 | - * |
|
68 | - * @url GET /download |
|
69 | - */ |
|
70 | - public function index($module_part, $original_file='') |
|
71 | - { |
|
72 | - global $conf, $langs; |
|
73 | - |
|
74 | - if (empty($module_part)) { |
|
75 | - throw new RestException(400, 'bad value for parameter modulepart'); |
|
76 | - } |
|
77 | - if (empty($original_file)) { |
|
78 | - throw new RestException(400, 'bad value for parameter original_file'); |
|
79 | - } |
|
80 | - |
|
81 | - //--- Finds and returns the document |
|
82 | - $entity=$conf->entity; |
|
83 | - |
|
84 | - $check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'read'); |
|
85 | - $accessallowed = $check_access['accessallowed']; |
|
86 | - $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; |
|
87 | - $original_file = $check_access['original_file']; |
|
88 | - |
|
89 | - if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) |
|
90 | - { |
|
91 | - throw new RestException(401); |
|
92 | - } |
|
93 | - if (!$accessallowed) { |
|
94 | - throw new RestException(401); |
|
95 | - } |
|
96 | - |
|
97 | - $filename = basename($original_file); |
|
98 | - $original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset |
|
99 | - |
|
100 | - if (! file_exists($original_file_osencoded)) |
|
101 | - { |
|
102 | - throw new RestException(404, 'File not found'); |
|
103 | - } |
|
104 | - |
|
105 | - $file_content=file_get_contents($original_file_osencoded); |
|
106 | - return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'encoding'=>'base64' ); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Build a document. |
|
112 | - * |
|
113 | - * Test sample 1: { "module_part": "invoice", "original_file": "FA1701-001/FA1701-001.pdf", "doctemplate": "crabe", "langcode": "fr_FR" }. |
|
114 | - * |
|
115 | - * @param string $module_part Name of module or area concerned by file download ('invoice', 'order', ...). |
|
116 | - * @param string $original_file Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf). |
|
117 | - * @param string $doctemplate Set here the doc template to use for document generation (If not set, use the default template). |
|
118 | - * @param string $langcode Language code like 'en_US', 'fr_FR', 'es_ES', ... (If not set, use the default language). |
|
119 | - * @return array List of documents |
|
120 | - * |
|
121 | - * @throws 500 |
|
122 | - * @throws 501 |
|
123 | - * @throws 400 |
|
124 | - * @throws 401 |
|
125 | - * @throws 404 |
|
126 | - * @throws 200 |
|
127 | - * |
|
128 | - * @url PUT /builddoc |
|
129 | - */ |
|
130 | - public function builddoc($module_part, $original_file='', $doctemplate='', $langcode='') |
|
131 | - { |
|
132 | - global $conf, $langs; |
|
133 | - |
|
134 | - if (empty($module_part)) { |
|
135 | - throw new RestException(400, 'bad value for parameter modulepart'); |
|
136 | - } |
|
137 | - if (empty($original_file)) { |
|
138 | - throw new RestException(400, 'bad value for parameter original_file'); |
|
139 | - } |
|
140 | - |
|
141 | - $outputlangs = $langs; |
|
142 | - if ($langcode && $langs->defaultlang != $langcode) |
|
143 | - { |
|
144 | - $outputlangs=new Translate('', $conf); |
|
145 | - $outputlangs->setDefaultLang($langcode); |
|
146 | - } |
|
147 | - |
|
148 | - //--- Finds and returns the document |
|
149 | - $entity=$conf->entity; |
|
150 | - |
|
151 | - $check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'write'); |
|
152 | - $accessallowed = $check_access['accessallowed']; |
|
153 | - $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; |
|
154 | - $original_file = $check_access['original_file']; |
|
155 | - |
|
156 | - if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) { |
|
157 | - throw new RestException(401); |
|
158 | - } |
|
159 | - if (!$accessallowed) { |
|
160 | - throw new RestException(401); |
|
161 | - } |
|
162 | - |
|
163 | - // --- Generates the document |
|
164 | - $hidedetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 0 : 1; |
|
165 | - $hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1; |
|
166 | - $hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1; |
|
167 | - |
|
168 | - $templateused=''; |
|
169 | - |
|
170 | - if ($module_part == 'facture' || $module_part == 'invoice') |
|
171 | - { |
|
172 | - require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
173 | - $this->invoice = new Facture($this->db); |
|
174 | - $result = $this->invoice->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); |
|
175 | - if( ! $result ) { |
|
176 | - throw new RestException(404, 'Invoice not found'); |
|
177 | - } |
|
178 | - |
|
179 | - $templateused = $doctemplate?$doctemplate:$this->invoice->modelpdf; |
|
180 | - $result = $this->invoice->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref); |
|
181 | - if( $result <= 0 ) { |
|
182 | - throw new RestException(500, 'Error generating document'); |
|
183 | - } |
|
184 | - } |
|
185 | - elseif ($module_part == 'commande' || $module_part == 'order') |
|
186 | - { |
|
187 | - require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
188 | - $this->order = new Commande($this->db); |
|
189 | - $result = $this->order->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); |
|
190 | - if( ! $result ) { |
|
191 | - throw new RestException(404, 'Order not found'); |
|
192 | - } |
|
193 | - $templateused = $doctemplate?$doctemplate:$this->order->modelpdf; |
|
194 | - $result = $this->order->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref); |
|
195 | - if( $result <= 0 ) { |
|
196 | - throw new RestException(500, 'Error generating document'); |
|
197 | - } |
|
198 | - } |
|
199 | - elseif ($module_part == 'propal' || $module_part == 'proposal') |
|
200 | - { |
|
201 | - require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
202 | - $this->propal = new Propal($this->db); |
|
203 | - $result = $this->propal->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); |
|
204 | - if( ! $result ) { |
|
205 | - throw new RestException(404, 'Proposal not found'); |
|
206 | - } |
|
207 | - $templateused = $doctemplate?$doctemplate:$this->propal->modelpdf; |
|
208 | - $result = $this->propal->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref); |
|
209 | - if( $result <= 0 ) { |
|
210 | - throw new RestException(500, 'Error generating document'); |
|
211 | - } |
|
212 | - } |
|
213 | - else |
|
214 | - { |
|
215 | - throw new RestException(403, 'Generation not available for this modulepart'); |
|
216 | - } |
|
217 | - |
|
218 | - $filename = basename($original_file); |
|
219 | - $original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset |
|
220 | - |
|
221 | - if (! file_exists($original_file_osencoded)) |
|
222 | - { |
|
223 | - throw new RestException(404, 'File not found'); |
|
224 | - } |
|
225 | - |
|
226 | - $file_content=file_get_contents($original_file_osencoded); |
|
227 | - return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'langcode'=>$outputlangs->defaultlang, 'template'=>$templateused, 'encoding'=>'base64' ); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Return the list of documents of a dedicated element (from its ID or Ref) |
|
232 | - * |
|
233 | - * @param string $modulepart Name of module or area concerned ('thirdparty', 'member', 'proposal', 'order', 'invoice', 'shipment', 'project', ...) |
|
234 | - * @param int $id ID of element |
|
235 | - * @param string $ref Ref of element |
|
236 | - * @param string $sortfield Sort criteria ('','fullname','relativename','name','date','size') |
|
237 | - * @param string $sortorder Sort order ('asc' or 'desc') |
|
238 | - * @return array Array of documents with path |
|
239 | - * |
|
240 | - * @throws 200 |
|
241 | - * @throws 400 |
|
242 | - * @throws 401 |
|
243 | - * @throws 404 |
|
244 | - * @throws 500 |
|
245 | - * |
|
246 | - * @url GET / |
|
247 | - */ |
|
248 | - function getDocumentsListByElement($modulepart, $id=0, $ref='', $sortfield='', $sortorder='') |
|
249 | - { |
|
250 | - global $conf; |
|
251 | - |
|
252 | - if (empty($modulepart)) { |
|
253 | - throw new RestException(400, 'bad value for parameter modulepart'); |
|
254 | - } |
|
255 | - |
|
256 | - if (empty($id) && empty($ref)) { |
|
257 | - throw new RestException(400, 'bad value for parameter id or ref'); |
|
258 | - } |
|
259 | - |
|
260 | - $id = (empty($id)?0:$id); |
|
261 | - |
|
262 | - if ($modulepart == 'societe' || $modulepart == 'thirdparty') |
|
263 | - { |
|
264 | - require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
265 | - |
|
266 | - if (!DolibarrApiAccess::$user->rights->societe->lire) { |
|
267 | - throw new RestException(401); |
|
268 | - } |
|
269 | - |
|
270 | - $object = new Societe($this->db); |
|
271 | - $result=$object->fetch($id, $ref); |
|
272 | - if ( ! $result ) { |
|
273 | - throw new RestException(404, 'Thirdparty not found'); |
|
274 | - } |
|
275 | - |
|
276 | - $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id; |
|
277 | - } |
|
278 | - else if ($modulepart == 'adherent' || $modulepart == 'member') |
|
279 | - { |
|
280 | - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; |
|
281 | - |
|
282 | - if (!DolibarrApiAccess::$user->rights->adherent->lire) { |
|
283 | - throw new RestException(401); |
|
284 | - } |
|
285 | - |
|
286 | - $object = new Adherent($this->db); |
|
287 | - $result=$object->fetch($id, $ref); |
|
288 | - if ( ! $result ) { |
|
289 | - throw new RestException(404, 'Member not found'); |
|
290 | - } |
|
291 | - |
|
292 | - $upload_dir = $conf->adherent->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'member'); |
|
293 | - } |
|
294 | - else if ($modulepart == 'propal' || $modulepart == 'proposal') |
|
295 | - { |
|
296 | - require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
297 | - |
|
298 | - if (!DolibarrApiAccess::$user->rights->propal->lire) { |
|
299 | - throw new RestException(401); |
|
300 | - } |
|
301 | - |
|
302 | - $object = new Propal($this->db); |
|
303 | - $result=$object->fetch($id, $ref); |
|
304 | - if ( ! $result ) { |
|
305 | - throw new RestException(404, 'Proposal not found'); |
|
306 | - } |
|
307 | - |
|
308 | - $upload_dir = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal'); |
|
309 | - } |
|
310 | - else if ($modulepart == 'commande' || $modulepart == 'order') |
|
311 | - { |
|
312 | - require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
313 | - |
|
314 | - if (!DolibarrApiAccess::$user->rights->commande->lire) { |
|
315 | - throw new RestException(401); |
|
316 | - } |
|
317 | - |
|
318 | - $object = new Commande($this->db); |
|
319 | - $result=$object->fetch($id, $ref); |
|
320 | - if ( ! $result ) { |
|
321 | - throw new RestException(404, 'Order not found'); |
|
322 | - } |
|
323 | - |
|
324 | - $upload_dir = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande'); |
|
325 | - } |
|
326 | - else if ($modulepart == 'shipment' || $modulepart == 'expedition') |
|
327 | - { |
|
328 | - require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; |
|
329 | - |
|
330 | - if (!DolibarrApiAccess::$user->rights->expedition->lire) { |
|
331 | - throw new RestException(401); |
|
332 | - } |
|
333 | - |
|
334 | - $object = new Expedition($this->db); |
|
335 | - $result=$object->fetch($id, $ref); |
|
336 | - if ( ! $result ) { |
|
337 | - throw new RestException(404, 'Shipment not found'); |
|
338 | - } |
|
339 | - |
|
340 | - $upload_dir = $conf->expedition->dir_output . "/sending/" . get_exdir(0, 0, 0, 1, $object, 'shipment'); |
|
341 | - } |
|
342 | - else if ($modulepart == 'facture' || $modulepart == 'invoice') |
|
343 | - { |
|
344 | - require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
345 | - |
|
346 | - if (!DolibarrApiAccess::$user->rights->facture->lire) { |
|
347 | - throw new RestException(401); |
|
348 | - } |
|
349 | - |
|
350 | - $object = new Facture($this->db); |
|
351 | - $result=$object->fetch($id, $ref); |
|
352 | - if ( ! $result ) { |
|
353 | - throw new RestException(404, 'Invoice not found'); |
|
354 | - } |
|
355 | - |
|
356 | - $upload_dir = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); |
|
357 | - } |
|
358 | - else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event') |
|
359 | - { |
|
360 | - require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; |
|
361 | - |
|
362 | - if (!DolibarrApiAccess::$user->rights->agenda->myactions->read && !DolibarrApiAccess::$user->rights->agenda->allactions->read) { |
|
363 | - throw new RestException(401); |
|
364 | - } |
|
365 | - |
|
366 | - $object = new ActionComm($this->db); |
|
367 | - $result=$object->fetch($id, $ref); |
|
368 | - if ( ! $result ) { |
|
369 | - throw new RestException(404, 'Event not found'); |
|
370 | - } |
|
371 | - |
|
372 | - $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref); |
|
373 | - } |
|
374 | - else |
|
375 | - { |
|
376 | - throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.'); |
|
377 | - } |
|
378 | - |
|
379 | - $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
380 | - if (empty($filearray)) { |
|
381 | - throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(! empty($object->Ref)?' or Ref '.$object->ref:'').' does not return any document.'); |
|
382 | - } |
|
383 | - |
|
384 | - return $filearray; |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * Return a document. |
|
390 | - * |
|
391 | - * @param int $id ID of document |
|
392 | - * @return array Array with data of file |
|
393 | - * |
|
394 | - * @throws RestException |
|
395 | - */ |
|
396 | - /* |
|
36 | + /** |
|
37 | + * @var array $DOCUMENT_FIELDS Mandatory fields, checked when create and update object |
|
38 | + */ |
|
39 | + static $DOCUMENT_FIELDS = array( |
|
40 | + 'modulepart' |
|
41 | + ); |
|
42 | + |
|
43 | + /** |
|
44 | + * Constructor |
|
45 | + */ |
|
46 | + function __construct() |
|
47 | + { |
|
48 | + global $db; |
|
49 | + $this->db = $db; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Download a document. |
|
55 | + * |
|
56 | + * Note that, this API is similar to using the wrapper link "documents.php" to download a file (used for |
|
57 | + * internal HTML links of documents into application), but with no need to have a session cookie (the token is used instead). |
|
58 | + * |
|
59 | + * @param string $module_part Name of module or area concerned by file download ('facture', ...) |
|
60 | + * @param string $original_file Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf) |
|
61 | + * @return array List of documents |
|
62 | + * |
|
63 | + * @throws 400 |
|
64 | + * @throws 401 |
|
65 | + * @throws 404 |
|
66 | + * @throws 200 |
|
67 | + * |
|
68 | + * @url GET /download |
|
69 | + */ |
|
70 | + public function index($module_part, $original_file='') |
|
71 | + { |
|
72 | + global $conf, $langs; |
|
73 | + |
|
74 | + if (empty($module_part)) { |
|
75 | + throw new RestException(400, 'bad value for parameter modulepart'); |
|
76 | + } |
|
77 | + if (empty($original_file)) { |
|
78 | + throw new RestException(400, 'bad value for parameter original_file'); |
|
79 | + } |
|
80 | + |
|
81 | + //--- Finds and returns the document |
|
82 | + $entity=$conf->entity; |
|
83 | + |
|
84 | + $check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'read'); |
|
85 | + $accessallowed = $check_access['accessallowed']; |
|
86 | + $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; |
|
87 | + $original_file = $check_access['original_file']; |
|
88 | + |
|
89 | + if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) |
|
90 | + { |
|
91 | + throw new RestException(401); |
|
92 | + } |
|
93 | + if (!$accessallowed) { |
|
94 | + throw new RestException(401); |
|
95 | + } |
|
96 | + |
|
97 | + $filename = basename($original_file); |
|
98 | + $original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset |
|
99 | + |
|
100 | + if (! file_exists($original_file_osencoded)) |
|
101 | + { |
|
102 | + throw new RestException(404, 'File not found'); |
|
103 | + } |
|
104 | + |
|
105 | + $file_content=file_get_contents($original_file_osencoded); |
|
106 | + return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'encoding'=>'base64' ); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Build a document. |
|
112 | + * |
|
113 | + * Test sample 1: { "module_part": "invoice", "original_file": "FA1701-001/FA1701-001.pdf", "doctemplate": "crabe", "langcode": "fr_FR" }. |
|
114 | + * |
|
115 | + * @param string $module_part Name of module or area concerned by file download ('invoice', 'order', ...). |
|
116 | + * @param string $original_file Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf). |
|
117 | + * @param string $doctemplate Set here the doc template to use for document generation (If not set, use the default template). |
|
118 | + * @param string $langcode Language code like 'en_US', 'fr_FR', 'es_ES', ... (If not set, use the default language). |
|
119 | + * @return array List of documents |
|
120 | + * |
|
121 | + * @throws 500 |
|
122 | + * @throws 501 |
|
123 | + * @throws 400 |
|
124 | + * @throws 401 |
|
125 | + * @throws 404 |
|
126 | + * @throws 200 |
|
127 | + * |
|
128 | + * @url PUT /builddoc |
|
129 | + */ |
|
130 | + public function builddoc($module_part, $original_file='', $doctemplate='', $langcode='') |
|
131 | + { |
|
132 | + global $conf, $langs; |
|
133 | + |
|
134 | + if (empty($module_part)) { |
|
135 | + throw new RestException(400, 'bad value for parameter modulepart'); |
|
136 | + } |
|
137 | + if (empty($original_file)) { |
|
138 | + throw new RestException(400, 'bad value for parameter original_file'); |
|
139 | + } |
|
140 | + |
|
141 | + $outputlangs = $langs; |
|
142 | + if ($langcode && $langs->defaultlang != $langcode) |
|
143 | + { |
|
144 | + $outputlangs=new Translate('', $conf); |
|
145 | + $outputlangs->setDefaultLang($langcode); |
|
146 | + } |
|
147 | + |
|
148 | + //--- Finds and returns the document |
|
149 | + $entity=$conf->entity; |
|
150 | + |
|
151 | + $check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'write'); |
|
152 | + $accessallowed = $check_access['accessallowed']; |
|
153 | + $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; |
|
154 | + $original_file = $check_access['original_file']; |
|
155 | + |
|
156 | + if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) { |
|
157 | + throw new RestException(401); |
|
158 | + } |
|
159 | + if (!$accessallowed) { |
|
160 | + throw new RestException(401); |
|
161 | + } |
|
162 | + |
|
163 | + // --- Generates the document |
|
164 | + $hidedetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 0 : 1; |
|
165 | + $hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1; |
|
166 | + $hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1; |
|
167 | + |
|
168 | + $templateused=''; |
|
169 | + |
|
170 | + if ($module_part == 'facture' || $module_part == 'invoice') |
|
171 | + { |
|
172 | + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
173 | + $this->invoice = new Facture($this->db); |
|
174 | + $result = $this->invoice->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); |
|
175 | + if( ! $result ) { |
|
176 | + throw new RestException(404, 'Invoice not found'); |
|
177 | + } |
|
178 | + |
|
179 | + $templateused = $doctemplate?$doctemplate:$this->invoice->modelpdf; |
|
180 | + $result = $this->invoice->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref); |
|
181 | + if( $result <= 0 ) { |
|
182 | + throw new RestException(500, 'Error generating document'); |
|
183 | + } |
|
184 | + } |
|
185 | + elseif ($module_part == 'commande' || $module_part == 'order') |
|
186 | + { |
|
187 | + require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
188 | + $this->order = new Commande($this->db); |
|
189 | + $result = $this->order->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); |
|
190 | + if( ! $result ) { |
|
191 | + throw new RestException(404, 'Order not found'); |
|
192 | + } |
|
193 | + $templateused = $doctemplate?$doctemplate:$this->order->modelpdf; |
|
194 | + $result = $this->order->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref); |
|
195 | + if( $result <= 0 ) { |
|
196 | + throw new RestException(500, 'Error generating document'); |
|
197 | + } |
|
198 | + } |
|
199 | + elseif ($module_part == 'propal' || $module_part == 'proposal') |
|
200 | + { |
|
201 | + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
202 | + $this->propal = new Propal($this->db); |
|
203 | + $result = $this->propal->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); |
|
204 | + if( ! $result ) { |
|
205 | + throw new RestException(404, 'Proposal not found'); |
|
206 | + } |
|
207 | + $templateused = $doctemplate?$doctemplate:$this->propal->modelpdf; |
|
208 | + $result = $this->propal->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref); |
|
209 | + if( $result <= 0 ) { |
|
210 | + throw new RestException(500, 'Error generating document'); |
|
211 | + } |
|
212 | + } |
|
213 | + else |
|
214 | + { |
|
215 | + throw new RestException(403, 'Generation not available for this modulepart'); |
|
216 | + } |
|
217 | + |
|
218 | + $filename = basename($original_file); |
|
219 | + $original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset |
|
220 | + |
|
221 | + if (! file_exists($original_file_osencoded)) |
|
222 | + { |
|
223 | + throw new RestException(404, 'File not found'); |
|
224 | + } |
|
225 | + |
|
226 | + $file_content=file_get_contents($original_file_osencoded); |
|
227 | + return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'langcode'=>$outputlangs->defaultlang, 'template'=>$templateused, 'encoding'=>'base64' ); |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Return the list of documents of a dedicated element (from its ID or Ref) |
|
232 | + * |
|
233 | + * @param string $modulepart Name of module or area concerned ('thirdparty', 'member', 'proposal', 'order', 'invoice', 'shipment', 'project', ...) |
|
234 | + * @param int $id ID of element |
|
235 | + * @param string $ref Ref of element |
|
236 | + * @param string $sortfield Sort criteria ('','fullname','relativename','name','date','size') |
|
237 | + * @param string $sortorder Sort order ('asc' or 'desc') |
|
238 | + * @return array Array of documents with path |
|
239 | + * |
|
240 | + * @throws 200 |
|
241 | + * @throws 400 |
|
242 | + * @throws 401 |
|
243 | + * @throws 404 |
|
244 | + * @throws 500 |
|
245 | + * |
|
246 | + * @url GET / |
|
247 | + */ |
|
248 | + function getDocumentsListByElement($modulepart, $id=0, $ref='', $sortfield='', $sortorder='') |
|
249 | + { |
|
250 | + global $conf; |
|
251 | + |
|
252 | + if (empty($modulepart)) { |
|
253 | + throw new RestException(400, 'bad value for parameter modulepart'); |
|
254 | + } |
|
255 | + |
|
256 | + if (empty($id) && empty($ref)) { |
|
257 | + throw new RestException(400, 'bad value for parameter id or ref'); |
|
258 | + } |
|
259 | + |
|
260 | + $id = (empty($id)?0:$id); |
|
261 | + |
|
262 | + if ($modulepart == 'societe' || $modulepart == 'thirdparty') |
|
263 | + { |
|
264 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
265 | + |
|
266 | + if (!DolibarrApiAccess::$user->rights->societe->lire) { |
|
267 | + throw new RestException(401); |
|
268 | + } |
|
269 | + |
|
270 | + $object = new Societe($this->db); |
|
271 | + $result=$object->fetch($id, $ref); |
|
272 | + if ( ! $result ) { |
|
273 | + throw new RestException(404, 'Thirdparty not found'); |
|
274 | + } |
|
275 | + |
|
276 | + $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id; |
|
277 | + } |
|
278 | + else if ($modulepart == 'adherent' || $modulepart == 'member') |
|
279 | + { |
|
280 | + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; |
|
281 | + |
|
282 | + if (!DolibarrApiAccess::$user->rights->adherent->lire) { |
|
283 | + throw new RestException(401); |
|
284 | + } |
|
285 | + |
|
286 | + $object = new Adherent($this->db); |
|
287 | + $result=$object->fetch($id, $ref); |
|
288 | + if ( ! $result ) { |
|
289 | + throw new RestException(404, 'Member not found'); |
|
290 | + } |
|
291 | + |
|
292 | + $upload_dir = $conf->adherent->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'member'); |
|
293 | + } |
|
294 | + else if ($modulepart == 'propal' || $modulepart == 'proposal') |
|
295 | + { |
|
296 | + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
297 | + |
|
298 | + if (!DolibarrApiAccess::$user->rights->propal->lire) { |
|
299 | + throw new RestException(401); |
|
300 | + } |
|
301 | + |
|
302 | + $object = new Propal($this->db); |
|
303 | + $result=$object->fetch($id, $ref); |
|
304 | + if ( ! $result ) { |
|
305 | + throw new RestException(404, 'Proposal not found'); |
|
306 | + } |
|
307 | + |
|
308 | + $upload_dir = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal'); |
|
309 | + } |
|
310 | + else if ($modulepart == 'commande' || $modulepart == 'order') |
|
311 | + { |
|
312 | + require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
313 | + |
|
314 | + if (!DolibarrApiAccess::$user->rights->commande->lire) { |
|
315 | + throw new RestException(401); |
|
316 | + } |
|
317 | + |
|
318 | + $object = new Commande($this->db); |
|
319 | + $result=$object->fetch($id, $ref); |
|
320 | + if ( ! $result ) { |
|
321 | + throw new RestException(404, 'Order not found'); |
|
322 | + } |
|
323 | + |
|
324 | + $upload_dir = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande'); |
|
325 | + } |
|
326 | + else if ($modulepart == 'shipment' || $modulepart == 'expedition') |
|
327 | + { |
|
328 | + require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; |
|
329 | + |
|
330 | + if (!DolibarrApiAccess::$user->rights->expedition->lire) { |
|
331 | + throw new RestException(401); |
|
332 | + } |
|
333 | + |
|
334 | + $object = new Expedition($this->db); |
|
335 | + $result=$object->fetch($id, $ref); |
|
336 | + if ( ! $result ) { |
|
337 | + throw new RestException(404, 'Shipment not found'); |
|
338 | + } |
|
339 | + |
|
340 | + $upload_dir = $conf->expedition->dir_output . "/sending/" . get_exdir(0, 0, 0, 1, $object, 'shipment'); |
|
341 | + } |
|
342 | + else if ($modulepart == 'facture' || $modulepart == 'invoice') |
|
343 | + { |
|
344 | + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
345 | + |
|
346 | + if (!DolibarrApiAccess::$user->rights->facture->lire) { |
|
347 | + throw new RestException(401); |
|
348 | + } |
|
349 | + |
|
350 | + $object = new Facture($this->db); |
|
351 | + $result=$object->fetch($id, $ref); |
|
352 | + if ( ! $result ) { |
|
353 | + throw new RestException(404, 'Invoice not found'); |
|
354 | + } |
|
355 | + |
|
356 | + $upload_dir = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); |
|
357 | + } |
|
358 | + else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event') |
|
359 | + { |
|
360 | + require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; |
|
361 | + |
|
362 | + if (!DolibarrApiAccess::$user->rights->agenda->myactions->read && !DolibarrApiAccess::$user->rights->agenda->allactions->read) { |
|
363 | + throw new RestException(401); |
|
364 | + } |
|
365 | + |
|
366 | + $object = new ActionComm($this->db); |
|
367 | + $result=$object->fetch($id, $ref); |
|
368 | + if ( ! $result ) { |
|
369 | + throw new RestException(404, 'Event not found'); |
|
370 | + } |
|
371 | + |
|
372 | + $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref); |
|
373 | + } |
|
374 | + else |
|
375 | + { |
|
376 | + throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.'); |
|
377 | + } |
|
378 | + |
|
379 | + $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
380 | + if (empty($filearray)) { |
|
381 | + throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(! empty($object->Ref)?' or Ref '.$object->ref:'').' does not return any document.'); |
|
382 | + } |
|
383 | + |
|
384 | + return $filearray; |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * Return a document. |
|
390 | + * |
|
391 | + * @param int $id ID of document |
|
392 | + * @return array Array with data of file |
|
393 | + * |
|
394 | + * @throws RestException |
|
395 | + */ |
|
396 | + /* |
|
397 | 397 | public function get($id) { |
398 | 398 | return array('note'=>'xxx'); |
399 | 399 | }*/ |
400 | 400 | |
401 | 401 | |
402 | - /** |
|
403 | - * Upload a file. |
|
404 | - * |
|
405 | - * Test sample 1: { "filename": "mynewfile.txt", "modulepart": "facture", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }. |
|
406 | - * Test sample 2: { "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "image/mywebsite", "filecontent": "Y29udGVudCB0ZXh0Cg==", "fileencoding": "base64", "overwriteifexists": "0" }. |
|
407 | - * |
|
408 | - * @param string $filename Name of file to create ('FA1705-0123.txt') |
|
409 | - * @param string $modulepart Name of module or area concerned by file upload ('facture', 'project', 'project_task', ...) |
|
410 | - * @param string $ref Reference of object (This will define subdir automatically and store submited file into it) |
|
411 | - * @param string $subdir Subdirectory (Only if ref not provided) |
|
412 | - * @param string $filecontent File content (string with file content. An empty file will be created if this parameter is not provided) |
|
413 | - * @param string $fileencoding File encoding (''=no encoding, 'base64'=Base 64) {@example '' or 'base64'} |
|
414 | - * @param int $overwriteifexists Overwrite file if exists (1 by default) |
|
415 | - * |
|
416 | - * @throws 200 |
|
417 | - * @throws 400 |
|
418 | - * @throws 401 |
|
419 | - * @throws 404 |
|
420 | - * @throws 500 |
|
421 | - * |
|
422 | - * @url POST /upload |
|
423 | - */ |
|
424 | - public function post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0) |
|
425 | - { |
|
426 | - global $db, $conf; |
|
427 | - |
|
428 | - /*var_dump($modulepart); |
|
402 | + /** |
|
403 | + * Upload a file. |
|
404 | + * |
|
405 | + * Test sample 1: { "filename": "mynewfile.txt", "modulepart": "facture", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }. |
|
406 | + * Test sample 2: { "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "image/mywebsite", "filecontent": "Y29udGVudCB0ZXh0Cg==", "fileencoding": "base64", "overwriteifexists": "0" }. |
|
407 | + * |
|
408 | + * @param string $filename Name of file to create ('FA1705-0123.txt') |
|
409 | + * @param string $modulepart Name of module or area concerned by file upload ('facture', 'project', 'project_task', ...) |
|
410 | + * @param string $ref Reference of object (This will define subdir automatically and store submited file into it) |
|
411 | + * @param string $subdir Subdirectory (Only if ref not provided) |
|
412 | + * @param string $filecontent File content (string with file content. An empty file will be created if this parameter is not provided) |
|
413 | + * @param string $fileencoding File encoding (''=no encoding, 'base64'=Base 64) {@example '' or 'base64'} |
|
414 | + * @param int $overwriteifexists Overwrite file if exists (1 by default) |
|
415 | + * |
|
416 | + * @throws 200 |
|
417 | + * @throws 400 |
|
418 | + * @throws 401 |
|
419 | + * @throws 404 |
|
420 | + * @throws 500 |
|
421 | + * |
|
422 | + * @url POST /upload |
|
423 | + */ |
|
424 | + public function post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0) |
|
425 | + { |
|
426 | + global $db, $conf; |
|
427 | + |
|
428 | + /*var_dump($modulepart); |
|
429 | 429 | var_dump($filename); |
430 | 430 | var_dump($filecontent); |
431 | 431 | exit;*/ |
432 | 432 | |
433 | - if(empty($modulepart)) |
|
434 | - { |
|
435 | - throw new RestException(400, 'Modulepart not provided.'); |
|
436 | - } |
|
437 | - |
|
438 | - if (!DolibarrApiAccess::$user->rights->ecm->upload) { |
|
439 | - throw new RestException(401); |
|
440 | - } |
|
441 | - |
|
442 | - $newfilecontent = ''; |
|
443 | - if (empty($fileencoding)) $newfilecontent = $filecontent; |
|
444 | - if ($fileencoding == 'base64') $newfilecontent = base64_decode($filecontent); |
|
445 | - |
|
446 | - $original_file = dol_sanitizeFileName($filename); |
|
447 | - |
|
448 | - // Define $uploadir |
|
449 | - $object = null; |
|
450 | - $entity = DolibarrApiAccess::$user->entity; |
|
451 | - if ($ref) |
|
452 | - { |
|
453 | - $tmpreldir=''; |
|
454 | - |
|
455 | - if ($modulepart == 'facture' || $modulepart == 'invoice') |
|
456 | - { |
|
457 | - $modulepart='facture'; |
|
458 | - |
|
459 | - require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
460 | - $object = new Facture($this->db); |
|
461 | - } |
|
462 | - elseif ($modulepart == 'project') |
|
463 | - { |
|
464 | - require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
465 | - $object = new Project($this->db); |
|
466 | - } |
|
467 | - elseif ($modulepart == 'task' || $modulepart == 'project_task') |
|
468 | - { |
|
469 | - $modulepart = 'project_task'; |
|
470 | - |
|
471 | - require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; |
|
472 | - $object = new Task($this->db); |
|
473 | - |
|
474 | - $task_result = $object->fetch('', $ref); |
|
475 | - |
|
476 | - // Fetching the tasks project is required because its out_dir might be a sub-directory of the project |
|
477 | - if($task_result > 0) |
|
478 | - { |
|
479 | - $project_result = $object->fetch_projet(); |
|
480 | - |
|
481 | - if($project_result >= 0) |
|
482 | - { |
|
483 | - $tmpreldir = dol_sanitizeFileName($object->project->ref).'/'; |
|
484 | - } |
|
485 | - } |
|
486 | - else |
|
487 | - { |
|
488 | - throw new RestException(500, 'Error while fetching Task '.$ref); |
|
489 | - } |
|
490 | - } |
|
491 | - // TODO Implement additional moduleparts |
|
492 | - else |
|
493 | - { |
|
494 | - throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.'); |
|
495 | - } |
|
496 | - |
|
497 | - if(is_object($object)) |
|
498 | - { |
|
499 | - $result = $object->fetch('', $ref); |
|
500 | - |
|
501 | - if($result == 0) |
|
502 | - { |
|
503 | - throw new RestException(404, "Object with ref '".$ref."' was not found."); |
|
504 | - } |
|
505 | - elseif ($result < 0) |
|
506 | - { |
|
507 | - throw new RestException(500, 'Error while fetching object.'); |
|
508 | - } |
|
509 | - } |
|
510 | - |
|
511 | - if (! ($object->id > 0)) |
|
512 | - { |
|
513 | - throw new RestException(404, 'The object '.$modulepart." with ref '".$ref."' was not found."); |
|
514 | - } |
|
515 | - |
|
516 | - $relativefile = $tmpreldir.dol_sanitizeFileName($object->ref); |
|
517 | - |
|
518 | - $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, $ref, 'write'); |
|
519 | - $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir |
|
520 | - |
|
521 | - if (empty($upload_dir) || $upload_dir == '/') |
|
522 | - { |
|
523 | - throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.'); |
|
524 | - } |
|
525 | - } |
|
526 | - else |
|
527 | - { |
|
528 | - if ($modulepart == 'invoice') $modulepart ='facture'; |
|
529 | - |
|
530 | - $relativefile = $subdir; |
|
531 | - |
|
532 | - $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write'); |
|
533 | - $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir |
|
534 | - |
|
535 | - if (empty($upload_dir) || $upload_dir == '/') |
|
536 | - { |
|
537 | - throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.'); |
|
538 | - } |
|
539 | - } |
|
540 | - // $original_file here is still value of filename without any dir. |
|
541 | - |
|
542 | - $upload_dir = dol_sanitizePathName($upload_dir); |
|
543 | - |
|
544 | - $destfile = $upload_dir . '/' . $original_file; |
|
545 | - $destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file; |
|
546 | - dol_delete_file($destfiletmp); |
|
547 | - //var_dump($original_file);exit; |
|
548 | - |
|
549 | - if (!dol_is_dir(dirname($destfile))) { |
|
550 | - throw new RestException(401, 'Directory not exists : '.dirname($destfile)); |
|
551 | - } |
|
552 | - |
|
553 | - if (! $overwriteifexists && dol_is_file($destfile)) |
|
554 | - { |
|
555 | - throw new RestException(500, "File with name '".$original_file."' already exists."); |
|
556 | - } |
|
557 | - |
|
558 | - $fhandle = @fopen($destfiletmp, 'w'); |
|
559 | - if ($fhandle) |
|
560 | - { |
|
561 | - $nbofbyteswrote = fwrite($fhandle, $newfilecontent); |
|
562 | - fclose($fhandle); |
|
563 | - @chmod($destfiletmp, octdec($conf->global->MAIN_UMASK)); |
|
564 | - } |
|
565 | - else |
|
566 | - { |
|
567 | - throw new RestException(500, "Failed to open file '".$destfiletmp."' for write"); |
|
568 | - } |
|
569 | - |
|
570 | - $result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1); |
|
571 | - if (! $result) |
|
572 | - { |
|
573 | - throw new RestException(500, "Failed to move file into '".$destfile."'"); |
|
574 | - } |
|
575 | - |
|
576 | - return dol_basename($destfile); |
|
577 | - } |
|
578 | - |
|
579 | - /** |
|
580 | - * Validate fields before create or update object |
|
581 | - * |
|
582 | - * @param array $data Array with data to verify |
|
583 | - * @return array |
|
584 | - * @throws RestException |
|
585 | - */ |
|
586 | - function _validate_file($data) { |
|
587 | - $result = array(); |
|
588 | - foreach (Documents::$DOCUMENT_FIELDS as $field) { |
|
589 | - if (!isset($data[$field])) |
|
590 | - throw new RestException(400, "$field field missing"); |
|
591 | - $result[$field] = $data[$field]; |
|
592 | - } |
|
593 | - return $result; |
|
594 | - } |
|
433 | + if(empty($modulepart)) |
|
434 | + { |
|
435 | + throw new RestException(400, 'Modulepart not provided.'); |
|
436 | + } |
|
437 | + |
|
438 | + if (!DolibarrApiAccess::$user->rights->ecm->upload) { |
|
439 | + throw new RestException(401); |
|
440 | + } |
|
441 | + |
|
442 | + $newfilecontent = ''; |
|
443 | + if (empty($fileencoding)) $newfilecontent = $filecontent; |
|
444 | + if ($fileencoding == 'base64') $newfilecontent = base64_decode($filecontent); |
|
445 | + |
|
446 | + $original_file = dol_sanitizeFileName($filename); |
|
447 | + |
|
448 | + // Define $uploadir |
|
449 | + $object = null; |
|
450 | + $entity = DolibarrApiAccess::$user->entity; |
|
451 | + if ($ref) |
|
452 | + { |
|
453 | + $tmpreldir=''; |
|
454 | + |
|
455 | + if ($modulepart == 'facture' || $modulepart == 'invoice') |
|
456 | + { |
|
457 | + $modulepart='facture'; |
|
458 | + |
|
459 | + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
460 | + $object = new Facture($this->db); |
|
461 | + } |
|
462 | + elseif ($modulepart == 'project') |
|
463 | + { |
|
464 | + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
465 | + $object = new Project($this->db); |
|
466 | + } |
|
467 | + elseif ($modulepart == 'task' || $modulepart == 'project_task') |
|
468 | + { |
|
469 | + $modulepart = 'project_task'; |
|
470 | + |
|
471 | + require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; |
|
472 | + $object = new Task($this->db); |
|
473 | + |
|
474 | + $task_result = $object->fetch('', $ref); |
|
475 | + |
|
476 | + // Fetching the tasks project is required because its out_dir might be a sub-directory of the project |
|
477 | + if($task_result > 0) |
|
478 | + { |
|
479 | + $project_result = $object->fetch_projet(); |
|
480 | + |
|
481 | + if($project_result >= 0) |
|
482 | + { |
|
483 | + $tmpreldir = dol_sanitizeFileName($object->project->ref).'/'; |
|
484 | + } |
|
485 | + } |
|
486 | + else |
|
487 | + { |
|
488 | + throw new RestException(500, 'Error while fetching Task '.$ref); |
|
489 | + } |
|
490 | + } |
|
491 | + // TODO Implement additional moduleparts |
|
492 | + else |
|
493 | + { |
|
494 | + throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.'); |
|
495 | + } |
|
496 | + |
|
497 | + if(is_object($object)) |
|
498 | + { |
|
499 | + $result = $object->fetch('', $ref); |
|
500 | + |
|
501 | + if($result == 0) |
|
502 | + { |
|
503 | + throw new RestException(404, "Object with ref '".$ref."' was not found."); |
|
504 | + } |
|
505 | + elseif ($result < 0) |
|
506 | + { |
|
507 | + throw new RestException(500, 'Error while fetching object.'); |
|
508 | + } |
|
509 | + } |
|
510 | + |
|
511 | + if (! ($object->id > 0)) |
|
512 | + { |
|
513 | + throw new RestException(404, 'The object '.$modulepart." with ref '".$ref."' was not found."); |
|
514 | + } |
|
515 | + |
|
516 | + $relativefile = $tmpreldir.dol_sanitizeFileName($object->ref); |
|
517 | + |
|
518 | + $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, $ref, 'write'); |
|
519 | + $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir |
|
520 | + |
|
521 | + if (empty($upload_dir) || $upload_dir == '/') |
|
522 | + { |
|
523 | + throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.'); |
|
524 | + } |
|
525 | + } |
|
526 | + else |
|
527 | + { |
|
528 | + if ($modulepart == 'invoice') $modulepart ='facture'; |
|
529 | + |
|
530 | + $relativefile = $subdir; |
|
531 | + |
|
532 | + $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write'); |
|
533 | + $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir |
|
534 | + |
|
535 | + if (empty($upload_dir) || $upload_dir == '/') |
|
536 | + { |
|
537 | + throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.'); |
|
538 | + } |
|
539 | + } |
|
540 | + // $original_file here is still value of filename without any dir. |
|
541 | + |
|
542 | + $upload_dir = dol_sanitizePathName($upload_dir); |
|
543 | + |
|
544 | + $destfile = $upload_dir . '/' . $original_file; |
|
545 | + $destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file; |
|
546 | + dol_delete_file($destfiletmp); |
|
547 | + //var_dump($original_file);exit; |
|
548 | + |
|
549 | + if (!dol_is_dir(dirname($destfile))) { |
|
550 | + throw new RestException(401, 'Directory not exists : '.dirname($destfile)); |
|
551 | + } |
|
552 | + |
|
553 | + if (! $overwriteifexists && dol_is_file($destfile)) |
|
554 | + { |
|
555 | + throw new RestException(500, "File with name '".$original_file."' already exists."); |
|
556 | + } |
|
557 | + |
|
558 | + $fhandle = @fopen($destfiletmp, 'w'); |
|
559 | + if ($fhandle) |
|
560 | + { |
|
561 | + $nbofbyteswrote = fwrite($fhandle, $newfilecontent); |
|
562 | + fclose($fhandle); |
|
563 | + @chmod($destfiletmp, octdec($conf->global->MAIN_UMASK)); |
|
564 | + } |
|
565 | + else |
|
566 | + { |
|
567 | + throw new RestException(500, "Failed to open file '".$destfiletmp."' for write"); |
|
568 | + } |
|
569 | + |
|
570 | + $result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1); |
|
571 | + if (! $result) |
|
572 | + { |
|
573 | + throw new RestException(500, "Failed to move file into '".$destfile."'"); |
|
574 | + } |
|
575 | + |
|
576 | + return dol_basename($destfile); |
|
577 | + } |
|
578 | + |
|
579 | + /** |
|
580 | + * Validate fields before create or update object |
|
581 | + * |
|
582 | + * @param array $data Array with data to verify |
|
583 | + * @return array |
|
584 | + * @throws RestException |
|
585 | + */ |
|
586 | + function _validate_file($data) { |
|
587 | + $result = array(); |
|
588 | + foreach (Documents::$DOCUMENT_FIELDS as $field) { |
|
589 | + if (!isset($data[$field])) |
|
590 | + throw new RestException(400, "$field field missing"); |
|
591 | + $result[$field] = $data[$field]; |
|
592 | + } |
|
593 | + return $result; |
|
594 | + } |
|
595 | 595 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @url GET /download |
69 | 69 | */ |
70 | - public function index($module_part, $original_file='') |
|
70 | + public function index($module_part, $original_file = '') |
|
71 | 71 | { |
72 | 72 | global $conf, $langs; |
73 | 73 | |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | } |
80 | 80 | |
81 | 81 | //--- Finds and returns the document |
82 | - $entity=$conf->entity; |
|
82 | + $entity = $conf->entity; |
|
83 | 83 | |
84 | 84 | $check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'read'); |
85 | 85 | $accessallowed = $check_access['accessallowed']; |
86 | 86 | $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; |
87 | 87 | $original_file = $check_access['original_file']; |
88 | 88 | |
89 | - if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) |
|
89 | + if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) |
|
90 | 90 | { |
91 | 91 | throw new RestException(401); |
92 | 92 | } |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | $filename = basename($original_file); |
98 | - $original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset |
|
98 | + $original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset |
|
99 | 99 | |
100 | - if (! file_exists($original_file_osencoded)) |
|
100 | + if (!file_exists($original_file_osencoded)) |
|
101 | 101 | { |
102 | 102 | throw new RestException(404, 'File not found'); |
103 | 103 | } |
104 | 104 | |
105 | - $file_content=file_get_contents($original_file_osencoded); |
|
106 | - return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'encoding'=>'base64' ); |
|
105 | + $file_content = file_get_contents($original_file_osencoded); |
|
106 | + return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'encoding'=>'base64'); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * |
128 | 128 | * @url PUT /builddoc |
129 | 129 | */ |
130 | - public function builddoc($module_part, $original_file='', $doctemplate='', $langcode='') |
|
130 | + public function builddoc($module_part, $original_file = '', $doctemplate = '', $langcode = '') |
|
131 | 131 | { |
132 | 132 | global $conf, $langs; |
133 | 133 | |
@@ -141,19 +141,19 @@ discard block |
||
141 | 141 | $outputlangs = $langs; |
142 | 142 | if ($langcode && $langs->defaultlang != $langcode) |
143 | 143 | { |
144 | - $outputlangs=new Translate('', $conf); |
|
144 | + $outputlangs = new Translate('', $conf); |
|
145 | 145 | $outputlangs->setDefaultLang($langcode); |
146 | 146 | } |
147 | 147 | |
148 | 148 | //--- Finds and returns the document |
149 | - $entity=$conf->entity; |
|
149 | + $entity = $conf->entity; |
|
150 | 150 | |
151 | 151 | $check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'write'); |
152 | 152 | $accessallowed = $check_access['accessallowed']; |
153 | 153 | $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; |
154 | 154 | $original_file = $check_access['original_file']; |
155 | 155 | |
156 | - if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) { |
|
156 | + if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) { |
|
157 | 157 | throw new RestException(401); |
158 | 158 | } |
159 | 159 | if (!$accessallowed) { |
@@ -165,20 +165,20 @@ discard block |
||
165 | 165 | $hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1; |
166 | 166 | $hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1; |
167 | 167 | |
168 | - $templateused=''; |
|
168 | + $templateused = ''; |
|
169 | 169 | |
170 | 170 | if ($module_part == 'facture' || $module_part == 'invoice') |
171 | 171 | { |
172 | 172 | require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
173 | 173 | $this->invoice = new Facture($this->db); |
174 | 174 | $result = $this->invoice->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); |
175 | - if( ! $result ) { |
|
175 | + if (!$result) { |
|
176 | 176 | throw new RestException(404, 'Invoice not found'); |
177 | 177 | } |
178 | 178 | |
179 | - $templateused = $doctemplate?$doctemplate:$this->invoice->modelpdf; |
|
179 | + $templateused = $doctemplate ? $doctemplate : $this->invoice->modelpdf; |
|
180 | 180 | $result = $this->invoice->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref); |
181 | - if( $result <= 0 ) { |
|
181 | + if ($result <= 0) { |
|
182 | 182 | throw new RestException(500, 'Error generating document'); |
183 | 183 | } |
184 | 184 | } |
@@ -187,12 +187,12 @@ discard block |
||
187 | 187 | require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
188 | 188 | $this->order = new Commande($this->db); |
189 | 189 | $result = $this->order->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); |
190 | - if( ! $result ) { |
|
190 | + if (!$result) { |
|
191 | 191 | throw new RestException(404, 'Order not found'); |
192 | 192 | } |
193 | - $templateused = $doctemplate?$doctemplate:$this->order->modelpdf; |
|
193 | + $templateused = $doctemplate ? $doctemplate : $this->order->modelpdf; |
|
194 | 194 | $result = $this->order->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref); |
195 | - if( $result <= 0 ) { |
|
195 | + if ($result <= 0) { |
|
196 | 196 | throw new RestException(500, 'Error generating document'); |
197 | 197 | } |
198 | 198 | } |
@@ -201,12 +201,12 @@ discard block |
||
201 | 201 | require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
202 | 202 | $this->propal = new Propal($this->db); |
203 | 203 | $result = $this->propal->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); |
204 | - if( ! $result ) { |
|
204 | + if (!$result) { |
|
205 | 205 | throw new RestException(404, 'Proposal not found'); |
206 | 206 | } |
207 | - $templateused = $doctemplate?$doctemplate:$this->propal->modelpdf; |
|
207 | + $templateused = $doctemplate ? $doctemplate : $this->propal->modelpdf; |
|
208 | 208 | $result = $this->propal->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref); |
209 | - if( $result <= 0 ) { |
|
209 | + if ($result <= 0) { |
|
210 | 210 | throw new RestException(500, 'Error generating document'); |
211 | 211 | } |
212 | 212 | } |
@@ -216,15 +216,15 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | $filename = basename($original_file); |
219 | - $original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset |
|
219 | + $original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset |
|
220 | 220 | |
221 | - if (! file_exists($original_file_osencoded)) |
|
221 | + if (!file_exists($original_file_osencoded)) |
|
222 | 222 | { |
223 | 223 | throw new RestException(404, 'File not found'); |
224 | 224 | } |
225 | 225 | |
226 | - $file_content=file_get_contents($original_file_osencoded); |
|
227 | - return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'langcode'=>$outputlangs->defaultlang, 'template'=>$templateused, 'encoding'=>'base64' ); |
|
226 | + $file_content = file_get_contents($original_file_osencoded); |
|
227 | + return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'langcode'=>$outputlangs->defaultlang, 'template'=>$templateused, 'encoding'=>'base64'); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * |
246 | 246 | * @url GET / |
247 | 247 | */ |
248 | - function getDocumentsListByElement($modulepart, $id=0, $ref='', $sortfield='', $sortorder='') |
|
248 | + function getDocumentsListByElement($modulepart, $id = 0, $ref = '', $sortfield = '', $sortorder = '') |
|
249 | 249 | { |
250 | 250 | global $conf; |
251 | 251 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | throw new RestException(400, 'bad value for parameter id or ref'); |
258 | 258 | } |
259 | 259 | |
260 | - $id = (empty($id)?0:$id); |
|
260 | + $id = (empty($id) ? 0 : $id); |
|
261 | 261 | |
262 | 262 | if ($modulepart == 'societe' || $modulepart == 'thirdparty') |
263 | 263 | { |
@@ -268,12 +268,12 @@ discard block |
||
268 | 268 | } |
269 | 269 | |
270 | 270 | $object = new Societe($this->db); |
271 | - $result=$object->fetch($id, $ref); |
|
272 | - if ( ! $result ) { |
|
271 | + $result = $object->fetch($id, $ref); |
|
272 | + if (!$result) { |
|
273 | 273 | throw new RestException(404, 'Thirdparty not found'); |
274 | 274 | } |
275 | 275 | |
276 | - $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id; |
|
276 | + $upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id; |
|
277 | 277 | } |
278 | 278 | else if ($modulepart == 'adherent' || $modulepart == 'member') |
279 | 279 | { |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | } |
285 | 285 | |
286 | 286 | $object = new Adherent($this->db); |
287 | - $result=$object->fetch($id, $ref); |
|
288 | - if ( ! $result ) { |
|
287 | + $result = $object->fetch($id, $ref); |
|
288 | + if (!$result) { |
|
289 | 289 | throw new RestException(404, 'Member not found'); |
290 | 290 | } |
291 | 291 | |
292 | - $upload_dir = $conf->adherent->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'member'); |
|
292 | + $upload_dir = $conf->adherent->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'member'); |
|
293 | 293 | } |
294 | 294 | else if ($modulepart == 'propal' || $modulepart == 'proposal') |
295 | 295 | { |
@@ -300,12 +300,12 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | $object = new Propal($this->db); |
303 | - $result=$object->fetch($id, $ref); |
|
304 | - if ( ! $result ) { |
|
303 | + $result = $object->fetch($id, $ref); |
|
304 | + if (!$result) { |
|
305 | 305 | throw new RestException(404, 'Proposal not found'); |
306 | 306 | } |
307 | 307 | |
308 | - $upload_dir = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal'); |
|
308 | + $upload_dir = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal'); |
|
309 | 309 | } |
310 | 310 | else if ($modulepart == 'commande' || $modulepart == 'order') |
311 | 311 | { |
@@ -316,12 +316,12 @@ discard block |
||
316 | 316 | } |
317 | 317 | |
318 | 318 | $object = new Commande($this->db); |
319 | - $result=$object->fetch($id, $ref); |
|
320 | - if ( ! $result ) { |
|
319 | + $result = $object->fetch($id, $ref); |
|
320 | + if (!$result) { |
|
321 | 321 | throw new RestException(404, 'Order not found'); |
322 | 322 | } |
323 | 323 | |
324 | - $upload_dir = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande'); |
|
324 | + $upload_dir = $conf->commande->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'commande'); |
|
325 | 325 | } |
326 | 326 | else if ($modulepart == 'shipment' || $modulepart == 'expedition') |
327 | 327 | { |
@@ -332,12 +332,12 @@ discard block |
||
332 | 332 | } |
333 | 333 | |
334 | 334 | $object = new Expedition($this->db); |
335 | - $result=$object->fetch($id, $ref); |
|
336 | - if ( ! $result ) { |
|
335 | + $result = $object->fetch($id, $ref); |
|
336 | + if (!$result) { |
|
337 | 337 | throw new RestException(404, 'Shipment not found'); |
338 | 338 | } |
339 | 339 | |
340 | - $upload_dir = $conf->expedition->dir_output . "/sending/" . get_exdir(0, 0, 0, 1, $object, 'shipment'); |
|
340 | + $upload_dir = $conf->expedition->dir_output."/sending/".get_exdir(0, 0, 0, 1, $object, 'shipment'); |
|
341 | 341 | } |
342 | 342 | else if ($modulepart == 'facture' || $modulepart == 'invoice') |
343 | 343 | { |
@@ -348,12 +348,12 @@ discard block |
||
348 | 348 | } |
349 | 349 | |
350 | 350 | $object = new Facture($this->db); |
351 | - $result=$object->fetch($id, $ref); |
|
352 | - if ( ! $result ) { |
|
351 | + $result = $object->fetch($id, $ref); |
|
352 | + if (!$result) { |
|
353 | 353 | throw new RestException(404, 'Invoice not found'); |
354 | 354 | } |
355 | 355 | |
356 | - $upload_dir = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); |
|
356 | + $upload_dir = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice'); |
|
357 | 357 | } |
358 | 358 | else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event') |
359 | 359 | { |
@@ -364,8 +364,8 @@ discard block |
||
364 | 364 | } |
365 | 365 | |
366 | 366 | $object = new ActionComm($this->db); |
367 | - $result=$object->fetch($id, $ref); |
|
368 | - if ( ! $result ) { |
|
367 | + $result = $object->fetch($id, $ref); |
|
368 | + if (!$result) { |
|
369 | 369 | throw new RestException(404, 'Event not found'); |
370 | 370 | } |
371 | 371 | |
@@ -376,9 +376,9 @@ discard block |
||
376 | 376 | throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.'); |
377 | 377 | } |
378 | 378 | |
379 | - $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
379 | + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); |
|
380 | 380 | if (empty($filearray)) { |
381 | - throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(! empty($object->Ref)?' or Ref '.$object->ref:'').' does not return any document.'); |
|
381 | + throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(!empty($object->Ref) ? ' or Ref '.$object->ref : '').' does not return any document.'); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | return $filearray; |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | * |
422 | 422 | * @url POST /upload |
423 | 423 | */ |
424 | - public function post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0) |
|
424 | + public function post($filename, $modulepart, $ref = '', $subdir = '', $filecontent = '', $fileencoding = '', $overwriteifexists = 0) |
|
425 | 425 | { |
426 | 426 | global $db, $conf; |
427 | 427 | |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | var_dump($filecontent); |
431 | 431 | exit;*/ |
432 | 432 | |
433 | - if(empty($modulepart)) |
|
433 | + if (empty($modulepart)) |
|
434 | 434 | { |
435 | 435 | throw new RestException(400, 'Modulepart not provided.'); |
436 | 436 | } |
@@ -450,11 +450,11 @@ discard block |
||
450 | 450 | $entity = DolibarrApiAccess::$user->entity; |
451 | 451 | if ($ref) |
452 | 452 | { |
453 | - $tmpreldir=''; |
|
453 | + $tmpreldir = ''; |
|
454 | 454 | |
455 | 455 | if ($modulepart == 'facture' || $modulepart == 'invoice') |
456 | 456 | { |
457 | - $modulepart='facture'; |
|
457 | + $modulepart = 'facture'; |
|
458 | 458 | |
459 | 459 | require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
460 | 460 | $object = new Facture($this->db); |
@@ -474,11 +474,11 @@ discard block |
||
474 | 474 | $task_result = $object->fetch('', $ref); |
475 | 475 | |
476 | 476 | // Fetching the tasks project is required because its out_dir might be a sub-directory of the project |
477 | - if($task_result > 0) |
|
477 | + if ($task_result > 0) |
|
478 | 478 | { |
479 | 479 | $project_result = $object->fetch_projet(); |
480 | 480 | |
481 | - if($project_result >= 0) |
|
481 | + if ($project_result >= 0) |
|
482 | 482 | { |
483 | 483 | $tmpreldir = dol_sanitizeFileName($object->project->ref).'/'; |
484 | 484 | } |
@@ -494,11 +494,11 @@ discard block |
||
494 | 494 | throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.'); |
495 | 495 | } |
496 | 496 | |
497 | - if(is_object($object)) |
|
497 | + if (is_object($object)) |
|
498 | 498 | { |
499 | 499 | $result = $object->fetch('', $ref); |
500 | 500 | |
501 | - if($result == 0) |
|
501 | + if ($result == 0) |
|
502 | 502 | { |
503 | 503 | throw new RestException(404, "Object with ref '".$ref."' was not found."); |
504 | 504 | } |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | } |
509 | 509 | } |
510 | 510 | |
511 | - if (! ($object->id > 0)) |
|
511 | + if (!($object->id > 0)) |
|
512 | 512 | { |
513 | 513 | throw new RestException(404, 'The object '.$modulepart." with ref '".$ref."' was not found."); |
514 | 514 | } |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | $relativefile = $tmpreldir.dol_sanitizeFileName($object->ref); |
517 | 517 | |
518 | 518 | $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, $ref, 'write'); |
519 | - $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir |
|
519 | + $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir |
|
520 | 520 | |
521 | 521 | if (empty($upload_dir) || $upload_dir == '/') |
522 | 522 | { |
@@ -525,12 +525,12 @@ discard block |
||
525 | 525 | } |
526 | 526 | else |
527 | 527 | { |
528 | - if ($modulepart == 'invoice') $modulepart ='facture'; |
|
528 | + if ($modulepart == 'invoice') $modulepart = 'facture'; |
|
529 | 529 | |
530 | 530 | $relativefile = $subdir; |
531 | 531 | |
532 | 532 | $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write'); |
533 | - $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir |
|
533 | + $upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir |
|
534 | 534 | |
535 | 535 | if (empty($upload_dir) || $upload_dir == '/') |
536 | 536 | { |
@@ -541,8 +541,8 @@ discard block |
||
541 | 541 | |
542 | 542 | $upload_dir = dol_sanitizePathName($upload_dir); |
543 | 543 | |
544 | - $destfile = $upload_dir . '/' . $original_file; |
|
545 | - $destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file; |
|
544 | + $destfile = $upload_dir.'/'.$original_file; |
|
545 | + $destfiletmp = DOL_DATA_ROOT.'/admin/temp/'.$original_file; |
|
546 | 546 | dol_delete_file($destfiletmp); |
547 | 547 | //var_dump($original_file);exit; |
548 | 548 | |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | throw new RestException(401, 'Directory not exists : '.dirname($destfile)); |
551 | 551 | } |
552 | 552 | |
553 | - if (! $overwriteifexists && dol_is_file($destfile)) |
|
553 | + if (!$overwriteifexists && dol_is_file($destfile)) |
|
554 | 554 | { |
555 | 555 | throw new RestException(500, "File with name '".$original_file."' already exists."); |
556 | 556 | } |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | } |
569 | 569 | |
570 | 570 | $result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1); |
571 | - if (! $result) |
|
571 | + if (!$result) |
|
572 | 572 | { |
573 | 573 | throw new RestException(500, "Failed to move file into '".$destfile."'"); |
574 | 574 | } |
@@ -181,8 +181,7 @@ discard block |
||
181 | 181 | if( $result <= 0 ) { |
182 | 182 | throw new RestException(500, 'Error generating document'); |
183 | 183 | } |
184 | - } |
|
185 | - elseif ($module_part == 'commande' || $module_part == 'order') |
|
184 | + } elseif ($module_part == 'commande' || $module_part == 'order') |
|
186 | 185 | { |
187 | 186 | require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
188 | 187 | $this->order = new Commande($this->db); |
@@ -195,8 +194,7 @@ discard block |
||
195 | 194 | if( $result <= 0 ) { |
196 | 195 | throw new RestException(500, 'Error generating document'); |
197 | 196 | } |
198 | - } |
|
199 | - elseif ($module_part == 'propal' || $module_part == 'proposal') |
|
197 | + } elseif ($module_part == 'propal' || $module_part == 'proposal') |
|
200 | 198 | { |
201 | 199 | require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
202 | 200 | $this->propal = new Propal($this->db); |
@@ -209,8 +207,7 @@ discard block |
||
209 | 207 | if( $result <= 0 ) { |
210 | 208 | throw new RestException(500, 'Error generating document'); |
211 | 209 | } |
212 | - } |
|
213 | - else |
|
210 | + } else |
|
214 | 211 | { |
215 | 212 | throw new RestException(403, 'Generation not available for this modulepart'); |
216 | 213 | } |
@@ -274,8 +271,7 @@ discard block |
||
274 | 271 | } |
275 | 272 | |
276 | 273 | $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id; |
277 | - } |
|
278 | - else if ($modulepart == 'adherent' || $modulepart == 'member') |
|
274 | + } else if ($modulepart == 'adherent' || $modulepart == 'member') |
|
279 | 275 | { |
280 | 276 | require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; |
281 | 277 | |
@@ -290,8 +286,7 @@ discard block |
||
290 | 286 | } |
291 | 287 | |
292 | 288 | $upload_dir = $conf->adherent->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'member'); |
293 | - } |
|
294 | - else if ($modulepart == 'propal' || $modulepart == 'proposal') |
|
289 | + } else if ($modulepart == 'propal' || $modulepart == 'proposal') |
|
295 | 290 | { |
296 | 291 | require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
297 | 292 | |
@@ -306,8 +301,7 @@ discard block |
||
306 | 301 | } |
307 | 302 | |
308 | 303 | $upload_dir = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal'); |
309 | - } |
|
310 | - else if ($modulepart == 'commande' || $modulepart == 'order') |
|
304 | + } else if ($modulepart == 'commande' || $modulepart == 'order') |
|
311 | 305 | { |
312 | 306 | require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
313 | 307 | |
@@ -322,8 +316,7 @@ discard block |
||
322 | 316 | } |
323 | 317 | |
324 | 318 | $upload_dir = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande'); |
325 | - } |
|
326 | - else if ($modulepart == 'shipment' || $modulepart == 'expedition') |
|
319 | + } else if ($modulepart == 'shipment' || $modulepart == 'expedition') |
|
327 | 320 | { |
328 | 321 | require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; |
329 | 322 | |
@@ -338,8 +331,7 @@ discard block |
||
338 | 331 | } |
339 | 332 | |
340 | 333 | $upload_dir = $conf->expedition->dir_output . "/sending/" . get_exdir(0, 0, 0, 1, $object, 'shipment'); |
341 | - } |
|
342 | - else if ($modulepart == 'facture' || $modulepart == 'invoice') |
|
334 | + } else if ($modulepart == 'facture' || $modulepart == 'invoice') |
|
343 | 335 | { |
344 | 336 | require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
345 | 337 | |
@@ -354,8 +346,7 @@ discard block |
||
354 | 346 | } |
355 | 347 | |
356 | 348 | $upload_dir = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); |
357 | - } |
|
358 | - else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event') |
|
349 | + } else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event') |
|
359 | 350 | { |
360 | 351 | require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; |
361 | 352 | |
@@ -370,8 +361,7 @@ discard block |
||
370 | 361 | } |
371 | 362 | |
372 | 363 | $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref); |
373 | - } |
|
374 | - else |
|
364 | + } else |
|
375 | 365 | { |
376 | 366 | throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.'); |
377 | 367 | } |
@@ -440,8 +430,12 @@ discard block |
||
440 | 430 | } |
441 | 431 | |
442 | 432 | $newfilecontent = ''; |
443 | - if (empty($fileencoding)) $newfilecontent = $filecontent; |
|
444 | - if ($fileencoding == 'base64') $newfilecontent = base64_decode($filecontent); |
|
433 | + if (empty($fileencoding)) { |
|
434 | + $newfilecontent = $filecontent; |
|
435 | + } |
|
436 | + if ($fileencoding == 'base64') { |
|
437 | + $newfilecontent = base64_decode($filecontent); |
|
438 | + } |
|
445 | 439 | |
446 | 440 | $original_file = dol_sanitizeFileName($filename); |
447 | 441 | |
@@ -458,13 +452,11 @@ discard block |
||
458 | 452 | |
459 | 453 | require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
460 | 454 | $object = new Facture($this->db); |
461 | - } |
|
462 | - elseif ($modulepart == 'project') |
|
455 | + } elseif ($modulepart == 'project') |
|
463 | 456 | { |
464 | 457 | require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
465 | 458 | $object = new Project($this->db); |
466 | - } |
|
467 | - elseif ($modulepart == 'task' || $modulepart == 'project_task') |
|
459 | + } elseif ($modulepart == 'task' || $modulepart == 'project_task') |
|
468 | 460 | { |
469 | 461 | $modulepart = 'project_task'; |
470 | 462 | |
@@ -482,8 +474,7 @@ discard block |
||
482 | 474 | { |
483 | 475 | $tmpreldir = dol_sanitizeFileName($object->project->ref).'/'; |
484 | 476 | } |
485 | - } |
|
486 | - else |
|
477 | + } else |
|
487 | 478 | { |
488 | 479 | throw new RestException(500, 'Error while fetching Task '.$ref); |
489 | 480 | } |
@@ -501,8 +492,7 @@ discard block |
||
501 | 492 | if($result == 0) |
502 | 493 | { |
503 | 494 | throw new RestException(404, "Object with ref '".$ref."' was not found."); |
504 | - } |
|
505 | - elseif ($result < 0) |
|
495 | + } elseif ($result < 0) |
|
506 | 496 | { |
507 | 497 | throw new RestException(500, 'Error while fetching object.'); |
508 | 498 | } |
@@ -522,10 +512,11 @@ discard block |
||
522 | 512 | { |
523 | 513 | throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.'); |
524 | 514 | } |
525 | - } |
|
526 | - else |
|
515 | + } else |
|
527 | 516 | { |
528 | - if ($modulepart == 'invoice') $modulepart ='facture'; |
|
517 | + if ($modulepart == 'invoice') { |
|
518 | + $modulepart ='facture'; |
|
519 | + } |
|
529 | 520 | |
530 | 521 | $relativefile = $subdir; |
531 | 522 | |
@@ -561,8 +552,7 @@ discard block |
||
561 | 552 | $nbofbyteswrote = fwrite($fhandle, $newfilecontent); |
562 | 553 | fclose($fhandle); |
563 | 554 | @chmod($destfiletmp, octdec($conf->global->MAIN_UMASK)); |
564 | - } |
|
565 | - else |
|
555 | + } else |
|
566 | 556 | { |
567 | 557 | throw new RestException(500, "Failed to open file '".$destfiletmp."' for write"); |
568 | 558 | } |
@@ -586,8 +576,9 @@ discard block |
||
586 | 576 | function _validate_file($data) { |
587 | 577 | $result = array(); |
588 | 578 | foreach (Documents::$DOCUMENT_FIELDS as $field) { |
589 | - if (!isset($data[$field])) |
|
590 | - throw new RestException(400, "$field field missing"); |
|
579 | + if (!isset($data[$field])) { |
|
580 | + throw new RestException(400, "$field field missing"); |
|
581 | + } |
|
591 | 582 | $result[$field] = $data[$field]; |
592 | 583 | } |
593 | 584 | return $result; |
@@ -33,49 +33,49 @@ |
||
33 | 33 | $langs->load("admin"); |
34 | 34 | |
35 | 35 | if (! $user->admin) |
36 | - accessforbidden(); |
|
36 | + accessforbidden(); |
|
37 | 37 | |
38 | 38 | $action=GETPOST('action','aZ09'); |
39 | 39 | |
40 | 40 | //Activate ProfId |
41 | 41 | if ($action == 'setproductionmode') |
42 | 42 | { |
43 | - $status = GETPOST('status','alpha'); |
|
44 | - |
|
45 | - if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0) |
|
46 | - { |
|
47 | - $error=0; |
|
48 | - |
|
49 | - if ($status == 1) |
|
50 | - { |
|
51 | - $result = dol_mkdir($conf->api->dir_temp); |
|
52 | - if ($result < 0) |
|
53 | - { |
|
54 | - setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors'); |
|
55 | - $error++; |
|
56 | - } |
|
57 | - } |
|
58 | - else |
|
59 | - { |
|
60 | - // Delete the cache file otherwise it does not update |
|
61 | - $result = dol_delete_file($conf->api->dir_temp.'/routes.php'); |
|
62 | - if ($result < 0) |
|
63 | - { |
|
64 | - setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors'); |
|
65 | - $error++; |
|
66 | - } |
|
67 | - } |
|
68 | - |
|
69 | - if (!$error) |
|
70 | - { |
|
71 | - header("Location: ".$_SERVER["PHP_SELF"]); |
|
72 | - exit; |
|
73 | - } |
|
74 | - } |
|
75 | - else |
|
76 | - { |
|
77 | - dol_print_error($db); |
|
78 | - } |
|
43 | + $status = GETPOST('status','alpha'); |
|
44 | + |
|
45 | + if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0) |
|
46 | + { |
|
47 | + $error=0; |
|
48 | + |
|
49 | + if ($status == 1) |
|
50 | + { |
|
51 | + $result = dol_mkdir($conf->api->dir_temp); |
|
52 | + if ($result < 0) |
|
53 | + { |
|
54 | + setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors'); |
|
55 | + $error++; |
|
56 | + } |
|
57 | + } |
|
58 | + else |
|
59 | + { |
|
60 | + // Delete the cache file otherwise it does not update |
|
61 | + $result = dol_delete_file($conf->api->dir_temp.'/routes.php'); |
|
62 | + if ($result < 0) |
|
63 | + { |
|
64 | + setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors'); |
|
65 | + $error++; |
|
66 | + } |
|
67 | + } |
|
68 | + |
|
69 | + if (!$error) |
|
70 | + { |
|
71 | + header("Location: ".$_SERVER["PHP_SELF"]); |
|
72 | + exit; |
|
73 | + } |
|
74 | + } |
|
75 | + else |
|
76 | + { |
|
77 | + dol_print_error($db); |
|
78 | + } |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | dol_mkdir(DOL_DATA_ROOT.'/api/temp'); // May have been deleted by a purge |
@@ -32,8 +32,9 @@ discard block |
||
32 | 32 | // Load translation files required by the page |
33 | 33 | $langs->load("admin"); |
34 | 34 | |
35 | -if (! $user->admin) |
|
35 | +if (! $user->admin) { |
|
36 | 36 | accessforbidden(); |
37 | +} |
|
37 | 38 | |
38 | 39 | $action=GETPOST('action','aZ09'); |
39 | 40 | |
@@ -54,8 +55,7 @@ discard block |
||
54 | 55 | setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors'); |
55 | 56 | $error++; |
56 | 57 | } |
57 | - } |
|
58 | - else |
|
58 | + } else |
|
59 | 59 | { |
60 | 60 | // Delete the cache file otherwise it does not update |
61 | 61 | $result = dol_delete_file($conf->api->dir_temp.'/routes.php'); |
@@ -71,8 +71,7 @@ discard block |
||
71 | 71 | header("Location: ".$_SERVER["PHP_SELF"]); |
72 | 72 | exit; |
73 | 73 | } |
74 | - } |
|
75 | - else |
|
74 | + } else |
|
76 | 75 | { |
77 | 76 | dol_print_error($db); |
78 | 77 | } |
@@ -111,8 +110,7 @@ discard block |
||
111 | 110 | print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=0">'; |
112 | 111 | print img_picto($langs->trans("Activated"),'switch_on'); |
113 | 112 | print '</a></td>'; |
114 | -} |
|
115 | -else |
|
113 | +} else |
|
116 | 114 | { |
117 | 115 | print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=1">'; |
118 | 116 | print img_picto($langs->trans("Disabled"),'switch_off'); |
@@ -144,8 +142,7 @@ discard block |
||
144 | 142 | { |
145 | 143 | $url=DOL_MAIN_URL_ROOT.'/api/index.php/explorer'; |
146 | 144 | print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n"; |
147 | -} |
|
148 | -else |
|
145 | +} else |
|
149 | 146 | { |
150 | 147 | print $langs->trans("NotAvailableWithThisDistribution"); |
151 | 148 | } |
@@ -28,26 +28,26 @@ discard block |
||
28 | 28 | |
29 | 29 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
30 | 30 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
31 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
31 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
32 | 32 | require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; |
33 | 33 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
34 | 34 | |
35 | 35 | // Load translation files required by the page |
36 | 36 | $langs->load("admin"); |
37 | 37 | |
38 | -if (! $user->admin) |
|
38 | +if (!$user->admin) |
|
39 | 39 | accessforbidden(); |
40 | 40 | |
41 | -$action=GETPOST('action','aZ09'); |
|
41 | +$action = GETPOST('action', 'aZ09'); |
|
42 | 42 | |
43 | 43 | //Activate ProfId |
44 | 44 | if ($action == 'setproductionmode') |
45 | 45 | { |
46 | - $status = GETPOST('status','alpha'); |
|
46 | + $status = GETPOST('status', 'alpha'); |
|
47 | 47 | |
48 | 48 | if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0) |
49 | 49 | { |
50 | - $error=0; |
|
50 | + $error = 0; |
|
51 | 51 | |
52 | 52 | if ($status == 1) |
53 | 53 | { |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | -dol_mkdir(DOL_DATA_ROOT.'/api/temp'); // May have been deleted by a purge |
|
84 | +dol_mkdir(DOL_DATA_ROOT.'/api/temp'); // May have been deleted by a purge |
|
85 | 85 | |
86 | 86 | |
87 | 87 | /* |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | |
91 | 91 | llxHeader(); |
92 | 92 | |
93 | -$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
|
94 | -print load_fiche_titre($langs->trans("ApiSetup"),$linkback,'title_setup'); |
|
93 | +$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
|
94 | +print load_fiche_titre($langs->trans("ApiSetup"), $linkback, 'title_setup'); |
|
95 | 95 | |
96 | 96 | print $langs->trans("ApiDesc")."<br>\n"; |
97 | 97 | print "<br>\n"; |
@@ -108,17 +108,17 @@ discard block |
||
108 | 108 | |
109 | 109 | print '<tr class="impair">'; |
110 | 110 | print '<td>'.$langs->trans("ApiProductionMode").'</td>'; |
111 | -$production_mode=(empty($conf->global->API_PRODUCTION_MODE)?false:true); |
|
111 | +$production_mode = (empty($conf->global->API_PRODUCTION_MODE) ?false:true); |
|
112 | 112 | if ($production_mode) |
113 | 113 | { |
114 | - print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=0">'; |
|
115 | - print img_picto($langs->trans("Activated"),'switch_on'); |
|
114 | + print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i + 1).'&status=0">'; |
|
115 | + print img_picto($langs->trans("Activated"), 'switch_on'); |
|
116 | 116 | print '</a></td>'; |
117 | 117 | } |
118 | 118 | else |
119 | 119 | { |
120 | - print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=1">'; |
|
121 | - print img_picto($langs->trans("Disabled"),'switch_off'); |
|
120 | + print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i + 1).'&status=1">'; |
|
121 | + print img_picto($langs->trans("Disabled"), 'switch_off'); |
|
122 | 122 | print '</a></td>'; |
123 | 123 | } |
124 | 124 | print '<td> </td>'; |
@@ -128,15 +128,15 @@ discard block |
||
128 | 128 | print '<br><br>'; |
129 | 129 | |
130 | 130 | // Define $urlwithroot |
131 | -$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
132 | -$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
131 | +$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
132 | +$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
133 | 133 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
134 | 134 | |
135 | 135 | // Show message |
136 | -$message=''; |
|
137 | -$url=$urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&password=<strong>thepassword</strong>[&reset=1]'; |
|
138 | -$message.=$langs->trans("UrlToGetKeyToUseAPIs").':<br>'; |
|
139 | -$message.=img_picto('','object_globe.png').' '.$url; |
|
136 | +$message = ''; |
|
137 | +$url = $urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&password=<strong>thepassword</strong>[&reset=1]'; |
|
138 | +$message .= $langs->trans("UrlToGetKeyToUseAPIs").':<br>'; |
|
139 | +$message .= img_picto('', 'object_globe.png').' '.$url; |
|
140 | 140 | print $message; |
141 | 141 | print '<br>'; |
142 | 142 | print '<br>'; |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | print '<u>'.$langs->trans("ApiExporerIs").':</u><br>'; |
146 | 146 | if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer')) |
147 | 147 | { |
148 | - $url=DOL_MAIN_URL_ROOT.'/api/index.php/explorer'; |
|
149 | - print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n"; |
|
148 | + $url = DOL_MAIN_URL_ROOT.'/api/index.php/explorer'; |
|
149 | + print img_picto('', 'object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n"; |
|
150 | 150 | } |
151 | 151 | else |
152 | 152 | { |
@@ -78,23 +78,23 @@ discard block |
||
78 | 78 | $module=$part=$obj=strtolower(preg_replace('/^mod/i','',$modulename)); |
79 | 79 | //if ($part == 'propale') $part='propal'; |
80 | 80 | if ($module == 'societe') { |
81 | - $obj = 'thirdparty'; |
|
82 | - } |
|
81 | + $obj = 'thirdparty'; |
|
82 | + } |
|
83 | 83 | if ($module == 'categorie') { |
84 | 84 | $part = 'categories'; |
85 | - $obj = 'category'; |
|
86 | - } |
|
85 | + $obj = 'category'; |
|
86 | + } |
|
87 | 87 | if ($module == 'facture') { |
88 | 88 | $part = 'compta/facture'; |
89 | - $obj = 'facture'; |
|
90 | - } |
|
89 | + $obj = 'facture'; |
|
90 | + } |
|
91 | 91 | if ($module == 'ficheinter') { |
92 | - $obj = 'fichinter'; |
|
93 | - $part = 'fichinter'; |
|
94 | - $module='fichinter'; |
|
95 | - } |
|
92 | + $obj = 'fichinter'; |
|
93 | + $part = 'fichinter'; |
|
94 | + $module='fichinter'; |
|
95 | + } |
|
96 | 96 | |
97 | - if (empty($conf->$module->enabled)) $enabled=false; |
|
97 | + if (empty($conf->$module->enabled)) $enabled=false; |
|
98 | 98 | |
99 | 99 | if ($enabled) |
100 | 100 | { |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | }*/ |
150 | 150 | |
151 | 151 | //$listofapis[]=array('classname'=>$classname, 'fullpath'=>$file_searched); |
152 | - /* } |
|
152 | + /* } |
|
153 | 153 | |
154 | 154 | }*/ |
155 | 155 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | if (empty($conf->global->MAIN_MODULE_API)) |
43 | 43 | { |
44 | 44 | dol_syslog("Call Dolibarr API interfaces with module REST disabled"); |
45 | - print $langs->trans("WarningModuleNotActive",'Api').'.<br><br>'; |
|
45 | + print $langs->trans("WarningModuleNotActive", 'Api').'.<br><br>'; |
|
46 | 46 | print $langs->trans("ToActivateModule"); |
47 | 47 | exit; |
48 | 48 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | $api->r->addAPIClass('Luracast\\Restler\\Resources'); //this creates resources.json at API Root |
54 | 54 | $api->r->setSupportedFormats('JsonFormat', 'XmlFormat'); |
55 | -$api->r->addAuthenticationClass('DolibarrApiAccess',''); |
|
55 | +$api->r->addAuthenticationClass('DolibarrApiAccess', ''); |
|
56 | 56 | |
57 | 57 | $listofapis = array(); |
58 | 58 | |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | */ |
65 | 65 | //dol_syslog("Scan directory ".$dir." for API modules"); |
66 | 66 | |
67 | - $handle=@opendir(dol_osencode($dir)); |
|
67 | + $handle = @opendir(dol_osencode($dir)); |
|
68 | 68 | if (is_resource($handle)) |
69 | 69 | { |
70 | - while (($file = readdir($handle))!==false) |
|
70 | + while (($file = readdir($handle)) !== false) |
|
71 | 71 | { |
72 | - if (is_readable($dir.$file) && preg_match("/^(mod.*)\.class\.php$/i",$file,$reg)) |
|
72 | + if (is_readable($dir.$file) && preg_match("/^(mod.*)\.class\.php$/i", $file, $reg)) |
|
73 | 73 | { |
74 | - $modulename=$reg[1]; |
|
74 | + $modulename = $reg[1]; |
|
75 | 75 | |
76 | 76 | // Defined if module is enabled |
77 | - $enabled=true; |
|
78 | - $module=$part=$obj=strtolower(preg_replace('/^mod/i','',$modulename)); |
|
77 | + $enabled = true; |
|
78 | + $module = $part = $obj = strtolower(preg_replace('/^mod/i', '', $modulename)); |
|
79 | 79 | //if ($part == 'propale') $part='propal'; |
80 | 80 | if ($module == 'societe') { |
81 | 81 | $obj = 'thirdparty'; |
@@ -91,10 +91,10 @@ discard block |
||
91 | 91 | if ($module == 'ficheinter') { |
92 | 92 | $obj = 'fichinter'; |
93 | 93 | $part = 'fichinter'; |
94 | - $module='fichinter'; |
|
94 | + $module = 'fichinter'; |
|
95 | 95 | } |
96 | 96 | |
97 | - if (empty($conf->$module->enabled)) $enabled=false; |
|
97 | + if (empty($conf->$module->enabled)) $enabled = false; |
|
98 | 98 | |
99 | 99 | if ($enabled) |
100 | 100 | { |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | */ |
109 | 109 | $dir_part = DOL_DOCUMENT_ROOT.'/'.$part.'/class/'; |
110 | 110 | |
111 | - $handle_part=@opendir(dol_osencode($dir_part)); |
|
111 | + $handle_part = @opendir(dol_osencode($dir_part)); |
|
112 | 112 | if (is_resource($handle_part)) |
113 | 113 | { |
114 | - while (($file_searched = readdir($handle_part))!==false) |
|
114 | + while (($file_searched = readdir($handle_part)) !== false) |
|
115 | 115 | { |
116 | - if (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i",$file_searched,$reg)) |
|
116 | + if (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i", $file_searched, $reg)) |
|
117 | 117 | { |
118 | 118 | $classname = ucwords($reg[1]); |
119 | 119 | require_once $dir_part.$file_searched; |
@@ -161,43 +161,43 @@ discard block |
||
161 | 161 | } |
162 | 162 | |
163 | 163 | //var_dump($listofapis); |
164 | -$listofapis=Routes::toArray(); // TODO api for "status" is lost here |
|
164 | +$listofapis = Routes::toArray(); // TODO api for "status" is lost here |
|
165 | 165 | //var_dump($listofapis); |
166 | 166 | |
167 | 167 | |
168 | 168 | llxHeader(); |
169 | 169 | |
170 | -$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
|
171 | -print load_fiche_titre($langs->trans("ApiSetup"),$linkback,'title_setup'); |
|
170 | +$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
|
171 | +print load_fiche_titre($langs->trans("ApiSetup"), $linkback, 'title_setup'); |
|
172 | 172 | |
173 | 173 | // Define $urlwithroot |
174 | -$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
175 | -$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
174 | +$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
175 | +$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
176 | 176 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
177 | 177 | |
178 | 178 | // Show message |
179 | 179 | print '<br>'; |
180 | -$message=''; |
|
181 | -$url='<a href="'.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword" target="_blank">'.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword[&reset=1]</a>'; |
|
182 | -$message.=$langs->trans("UrlToGetKeyToUseAPIs").':<br>'; |
|
183 | -$message.=img_picto('','object_globe.png').' '.$url; |
|
180 | +$message = ''; |
|
181 | +$url = '<a href="'.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword" target="_blank">'.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword[&reset=1]</a>'; |
|
182 | +$message .= $langs->trans("UrlToGetKeyToUseAPIs").':<br>'; |
|
183 | +$message .= img_picto('', 'object_globe.png').' '.$url; |
|
184 | 184 | print $message; |
185 | 185 | print '<br>'; |
186 | 186 | print '<br>'; |
187 | 187 | |
188 | -$oldclass=''; |
|
188 | +$oldclass = ''; |
|
189 | 189 | |
190 | 190 | print $langs->trans("ListOfAvailableAPIs").':<br>'; |
191 | -foreach($listofapis['v1'] as $key => $val) |
|
191 | +foreach ($listofapis['v1'] as $key => $val) |
|
192 | 192 | { |
193 | 193 | if ($key == 'login') continue; |
194 | 194 | if ($key == 'index') continue; |
195 | 195 | |
196 | 196 | if ($key) |
197 | 197 | { |
198 | - foreach($val as $method => $val2) |
|
198 | + foreach ($val as $method => $val2) |
|
199 | 199 | { |
200 | - $newclass=$val2['className']; |
|
200 | + $newclass = $val2['className']; |
|
201 | 201 | |
202 | 202 | if (preg_match('/restler/i', $newclass)) continue; |
203 | 203 | |
@@ -207,9 +207,9 @@ discard block |
||
207 | 207 | $oldclass = $newclass; |
208 | 208 | } |
209 | 209 | //print $key.' - '.$val['classname'].' - '.$val['fullpath']." - ".DOL_MAIN_URL_ROOT.'/api/index.php/'.strtolower(preg_replace('/Api$/','',$val['classname']))."/xxx<br>\n"; |
210 | - $url=$urlwithroot.'/api/index.php/'.$key; |
|
211 | - $url.='?api_key=token'; |
|
212 | - print img_picto('','object_globe.png').' '.$method.' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n"; |
|
210 | + $url = $urlwithroot.'/api/index.php/'.$key; |
|
211 | + $url .= '?api_key=token'; |
|
212 | + print img_picto('', 'object_globe.png').' '.$method.' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n"; |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | } |
@@ -94,7 +94,9 @@ discard block |
||
94 | 94 | $module='fichinter'; |
95 | 95 | } |
96 | 96 | |
97 | - if (empty($conf->$module->enabled)) $enabled=false; |
|
97 | + if (empty($conf->$module->enabled)) { |
|
98 | + $enabled=false; |
|
99 | + } |
|
98 | 100 | |
99 | 101 | if ($enabled) |
100 | 102 | { |
@@ -190,8 +192,12 @@ discard block |
||
190 | 192 | print $langs->trans("ListOfAvailableAPIs").':<br>'; |
191 | 193 | foreach($listofapis['v1'] as $key => $val) |
192 | 194 | { |
193 | - if ($key == 'login') continue; |
|
194 | - if ($key == 'index') continue; |
|
195 | + if ($key == 'login') { |
|
196 | + continue; |
|
197 | + } |
|
198 | + if ($key == 'index') { |
|
199 | + continue; |
|
200 | + } |
|
195 | 201 | |
196 | 202 | if ($key) |
197 | 203 | { |
@@ -199,7 +205,9 @@ discard block |
||
199 | 205 | { |
200 | 206 | $newclass=$val2['className']; |
201 | 207 | |
202 | - if (preg_match('/restler/i', $newclass)) continue; |
|
208 | + if (preg_match('/restler/i', $newclass)) { |
|
209 | + continue; |
|
210 | + } |
|
203 | 211 | |
204 | 212 | if ($oldclass != $newclass) |
205 | 213 | { |
@@ -215,38 +215,38 @@ |
||
215 | 215 | // Load a dedicated API file |
216 | 216 | dol_syslog("Load a dedicated API file module=".$module." moduledirforclass=".$moduledirforclass); |
217 | 217 | |
218 | - $tmpmodule = $module; |
|
219 | - if ($tmpmodule != 'api') |
|
220 | - $tmpmodule = preg_replace('/api$/i', '', $tmpmodule); |
|
221 | - $classfile = str_replace('_', '', $tmpmodule); |
|
222 | - if ($module == 'supplierproposals') |
|
223 | - $classfile = 'supplier_proposals'; |
|
224 | - if ($module == 'supplierorders') |
|
225 | - $classfile = 'supplier_orders'; |
|
226 | - if ($module == 'supplierinvoices') |
|
227 | - $classfile = 'supplier_invoices'; |
|
228 | - if ($module == 'ficheinter') |
|
229 | - $classfile = 'interventions'; |
|
230 | - if ($module == 'interventions') |
|
231 | - $classfile = 'interventions'; |
|
232 | - |
|
233 | - $dir_part_file = dol_buildpath('/' . $moduledirforclass . '/class/api_' . $classfile . '.class.php', 0, 2); |
|
234 | - |
|
235 | - $classname = ucwords($module); |
|
236 | - |
|
237 | - dol_syslog('Search /' . $moduledirforclass . '/class/api_' . $classfile . '.class.php => dir_part_file=' . $dir_part_file . ' classname=' . $classname); |
|
238 | - |
|
239 | - $res = false; |
|
240 | - if ($dir_part_file) |
|
241 | - $res = include_once $dir_part_file; |
|
242 | - if (! $res) { |
|
243 | - print 'API not found (failed to include API file)'; |
|
244 | - header('HTTP/1.1 501 API not found (failed to include API file)'); |
|
245 | - exit(0); |
|
246 | - } |
|
247 | - |
|
248 | - if (class_exists($classname)) |
|
249 | - $api->r->addAPIClass($classname); |
|
218 | + $tmpmodule = $module; |
|
219 | + if ($tmpmodule != 'api') |
|
220 | + $tmpmodule = preg_replace('/api$/i', '', $tmpmodule); |
|
221 | + $classfile = str_replace('_', '', $tmpmodule); |
|
222 | + if ($module == 'supplierproposals') |
|
223 | + $classfile = 'supplier_proposals'; |
|
224 | + if ($module == 'supplierorders') |
|
225 | + $classfile = 'supplier_orders'; |
|
226 | + if ($module == 'supplierinvoices') |
|
227 | + $classfile = 'supplier_invoices'; |
|
228 | + if ($module == 'ficheinter') |
|
229 | + $classfile = 'interventions'; |
|
230 | + if ($module == 'interventions') |
|
231 | + $classfile = 'interventions'; |
|
232 | + |
|
233 | + $dir_part_file = dol_buildpath('/' . $moduledirforclass . '/class/api_' . $classfile . '.class.php', 0, 2); |
|
234 | + |
|
235 | + $classname = ucwords($module); |
|
236 | + |
|
237 | + dol_syslog('Search /' . $moduledirforclass . '/class/api_' . $classfile . '.class.php => dir_part_file=' . $dir_part_file . ' classname=' . $classname); |
|
238 | + |
|
239 | + $res = false; |
|
240 | + if ($dir_part_file) |
|
241 | + $res = include_once $dir_part_file; |
|
242 | + if (! $res) { |
|
243 | + print 'API not found (failed to include API file)'; |
|
244 | + header('HTTP/1.1 501 API not found (failed to include API file)'); |
|
245 | + exit(0); |
|
246 | + } |
|
247 | + |
|
248 | + if (class_exists($classname)) |
|
249 | + $api->r->addAPIClass($classname); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | // TODO If not found, redirect to explorer |
@@ -24,25 +24,25 @@ discard block |
||
24 | 24 | * \file htdocs/api/index.php |
25 | 25 | */ |
26 | 26 | |
27 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check anti CSRF attack test |
|
28 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not check anti POST attack test |
|
29 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no need to load and show top and left menu |
|
30 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php |
|
31 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); // Do not load ajax.lib.php library |
|
32 | -if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) |
|
27 | +if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check anti CSRF attack test |
|
28 | +if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test |
|
29 | +if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu |
|
30 | +if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php |
|
31 | +if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library |
|
32 | +if (!defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) |
|
33 | 33 | |
34 | 34 | |
35 | 35 | // Force entity if a value is provided into HTTP header. Otherwise, will use the entity of user of token used. |
36 | -if (! empty($_SERVER['HTTP_DOLAPIENTITY'])) define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']); |
|
36 | +if (!empty($_SERVER['HTTP_DOLAPIENTITY'])) define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']); |
|
37 | 37 | |
38 | 38 | |
39 | -$res=0; |
|
40 | -if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php'; |
|
41 | -if (! $res) die("Include of main fails"); |
|
39 | +$res = 0; |
|
40 | +if (!$res && file_exists("../main.inc.php")) $res = include '../main.inc.php'; |
|
41 | +if (!$res) die("Include of main fails"); |
|
42 | 42 | |
43 | 43 | require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/AutoLoader.php'; |
44 | 44 | |
45 | -call_user_func(function () { |
|
45 | +call_user_func(function() { |
|
46 | 46 | $loader = Luracast\Restler\AutoLoader::instance(); |
47 | 47 | spl_autoload_register($loader); |
48 | 48 | return $loader; |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | { |
60 | 60 | $langs->load("admin"); |
61 | 61 | dol_syslog("Call Dolibarr API interfaces with module REST disabled"); |
62 | - print $langs->trans("WarningModuleNotActive",'Api').'.<br><br>'; |
|
62 | + print $langs->trans("WarningModuleNotActive", 'Api').'.<br><br>'; |
|
63 | 63 | print $langs->trans("ToActivateModule"); |
64 | 64 | exit; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // Test if explorer is not disabled |
68 | -if (preg_match('/api\/index\.php\/explorer/', $_SERVER["PHP_SELF"]) && ! empty($conf->global->API_EXPLORER_DISABLED)) |
|
68 | +if (preg_match('/api\/index\.php\/explorer/', $_SERVER["PHP_SELF"]) && !empty($conf->global->API_EXPLORER_DISABLED)) |
|
69 | 69 | { |
70 | 70 | $langs->load("admin"); |
71 | 71 | dol_syslog("Call Dolibarr API interfaces with module REST disabled"); |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | |
94 | 94 | |
95 | 95 | // Set the flag to say to refresh (when we reload the explorer, production must be for API call only) |
96 | -$refreshcache=false; |
|
97 | -if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root')) |
|
96 | +$refreshcache = false; |
|
97 | +if (!empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root')) |
|
98 | 98 | { |
99 | - $refreshcache=true; |
|
99 | + $refreshcache = true; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | // See https://github.com/Luracast/Restler-API-Explorer for more info. |
108 | 108 | $api->r->addAPIClass('Luracast\\Restler\\Explorer'); |
109 | 109 | |
110 | -$api->r->setSupportedFormats('JsonFormat', 'XmlFormat', 'UploadFormat'); // 'YamlFormat' |
|
111 | -$api->r->addAuthenticationClass('DolibarrApiAccess',''); |
|
110 | +$api->r->setSupportedFormats('JsonFormat', 'XmlFormat', 'UploadFormat'); // 'YamlFormat' |
|
111 | +$api->r->addAuthenticationClass('DolibarrApiAccess', ''); |
|
112 | 112 | |
113 | 113 | // Define accepted mime types |
114 | 114 | UploadFormat::$allowedMimeTypes = array('image/jpeg', 'image/png', 'text/plain', 'application/octet-stream'); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | |
118 | 118 | // Call Explorer file for all APIs definitions |
119 | -if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root')) |
|
119 | +if (!empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root')) |
|
120 | 120 | { |
121 | 121 | // Scan all API files to load them |
122 | 122 | |
@@ -128,25 +128,25 @@ discard block |
||
128 | 128 | // Search available module |
129 | 129 | dol_syslog("Scan directory ".$dir." for module descriptor files, then search for API files"); |
130 | 130 | |
131 | - $handle=@opendir(dol_osencode($dir)); |
|
131 | + $handle = @opendir(dol_osencode($dir)); |
|
132 | 132 | if (is_resource($handle)) |
133 | 133 | { |
134 | - while (($file = readdir($handle))!==false) |
|
134 | + while (($file = readdir($handle)) !== false) |
|
135 | 135 | { |
136 | - if (is_readable($dir.$file) && preg_match("/^mod(.*)\.class\.php$/i",$file,$regmod)) |
|
136 | + if (is_readable($dir.$file) && preg_match("/^mod(.*)\.class\.php$/i", $file, $regmod)) |
|
137 | 137 | { |
138 | 138 | $module = strtolower($regmod[1]); |
139 | 139 | $moduledirforclass = getModuleDirForApiClass($module); |
140 | 140 | $modulenameforenabled = $module; |
141 | - if ($module == 'propale') { $modulenameforenabled='propal'; } |
|
142 | - if ($module == 'supplierproposal') { $modulenameforenabled='supplier_proposal'; } |
|
143 | - if ($module == 'ficheinter') { $modulenameforenabled='ficheinter'; } |
|
141 | + if ($module == 'propale') { $modulenameforenabled = 'propal'; } |
|
142 | + if ($module == 'supplierproposal') { $modulenameforenabled = 'supplier_proposal'; } |
|
143 | + if ($module == 'ficheinter') { $modulenameforenabled = 'ficheinter'; } |
|
144 | 144 | |
145 | 145 | dol_syslog("Found module file ".$file." - module=".$module." - modulenameforenabled=".$modulenameforenabled." - moduledirforclass=".$moduledirforclass); |
146 | 146 | |
147 | 147 | // Defined if module is enabled |
148 | - $enabled=true; |
|
149 | - if (empty($conf->$modulenameforenabled->enabled)) $enabled=false; |
|
148 | + $enabled = true; |
|
149 | + if (empty($conf->$modulenameforenabled->enabled)) $enabled = false; |
|
150 | 150 | |
151 | 151 | if ($enabled) |
152 | 152 | { |
@@ -155,14 +155,14 @@ discard block |
||
155 | 155 | // @todo : use getElementProperties() function ? |
156 | 156 | $dir_part = dol_buildpath('/'.$moduledirforclass.'/class/'); |
157 | 157 | |
158 | - $handle_part=@opendir(dol_osencode($dir_part)); |
|
158 | + $handle_part = @opendir(dol_osencode($dir_part)); |
|
159 | 159 | if (is_resource($handle_part)) |
160 | 160 | { |
161 | - while (($file_searched = readdir($handle_part))!==false) |
|
161 | + while (($file_searched = readdir($handle_part)) !== false) |
|
162 | 162 | { |
163 | 163 | if ($file_searched == 'api_access.class.php') continue; |
164 | 164 | |
165 | - if (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i",$file_searched,$regapi)) |
|
165 | + if (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i", $file_searched, $regapi)) |
|
166 | 166 | { |
167 | 167 | $classname = ucwords($regapi[1]); |
168 | 168 | $classname = str_replace('_', '', $classname); |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | } |
202 | 202 | |
203 | 203 | // Call one APIs or one definition of an API |
204 | -if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && $reg[2] != '/resources.json' && preg_match('/^\/(swagger|resources)\.json\/(.+)$/', $reg[2], $regbis) && $regbis[2] != 'root'))) |
|
204 | +if (!empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && $reg[2] != '/resources.json' && preg_match('/^\/(swagger|resources)\.json\/(.+)$/', $reg[2], $regbis) && $regbis[2] != 'root'))) |
|
205 | 205 | { |
206 | 206 | $module = $reg[1]; |
207 | 207 | if ($module == 'explorer') // If we call page to explore details of a service |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | $module = $regbis[2]; |
210 | 210 | } |
211 | 211 | |
212 | - $module=strtolower($module); |
|
212 | + $module = strtolower($module); |
|
213 | 213 | $moduledirforclass = getModuleDirForApiClass($module); |
214 | 214 | |
215 | 215 | // Load a dedicated API file |
@@ -230,16 +230,16 @@ discard block |
||
230 | 230 | if ($module == 'interventions') |
231 | 231 | $classfile = 'interventions'; |
232 | 232 | |
233 | - $dir_part_file = dol_buildpath('/' . $moduledirforclass . '/class/api_' . $classfile . '.class.php', 0, 2); |
|
233 | + $dir_part_file = dol_buildpath('/'.$moduledirforclass.'/class/api_'.$classfile.'.class.php', 0, 2); |
|
234 | 234 | |
235 | 235 | $classname = ucwords($module); |
236 | 236 | |
237 | - dol_syslog('Search /' . $moduledirforclass . '/class/api_' . $classfile . '.class.php => dir_part_file=' . $dir_part_file . ' classname=' . $classname); |
|
237 | + dol_syslog('Search /'.$moduledirforclass.'/class/api_'.$classfile.'.class.php => dir_part_file='.$dir_part_file.' classname='.$classname); |
|
238 | 238 | |
239 | 239 | $res = false; |
240 | 240 | if ($dir_part_file) |
241 | 241 | $res = include_once $dir_part_file; |
242 | - if (! $res) { |
|
242 | + if (!$res) { |
|
243 | 243 | print 'API not found (failed to include API file)'; |
244 | 244 | header('HTTP/1.1 501 API not found (failed to include API file)'); |
245 | 245 | exit(0); |
@@ -24,21 +24,45 @@ discard block |
||
24 | 24 | * \file htdocs/api/index.php |
25 | 25 | */ |
26 | 26 | |
27 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check anti CSRF attack test |
|
28 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not check anti POST attack test |
|
29 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no need to load and show top and left menu |
|
30 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php |
|
31 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); // Do not load ajax.lib.php library |
|
32 | -if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) |
|
27 | +if (! defined('NOCSRFCHECK')) { |
|
28 | + define('NOCSRFCHECK','1'); |
|
29 | +} |
|
30 | +// Do not check anti CSRF attack test |
|
31 | +if (! defined('NOTOKENRENEWAL')) { |
|
32 | + define('NOTOKENRENEWAL','1'); |
|
33 | +} |
|
34 | +// Do not check anti POST attack test |
|
35 | +if (! defined('NOREQUIREMENU')) { |
|
36 | + define('NOREQUIREMENU','1'); |
|
37 | +} |
|
38 | +// If there is no need to load and show top and left menu |
|
39 | +if (! defined('NOREQUIREHTML')) { |
|
40 | + define('NOREQUIREHTML','1'); |
|
41 | +} |
|
42 | +// If we don't need to load the html.form.class.php |
|
43 | +if (! defined('NOREQUIREAJAX')) { |
|
44 | + define('NOREQUIREAJAX','1'); |
|
45 | +} |
|
46 | +// Do not load ajax.lib.php library |
|
47 | +if (! defined("NOLOGIN")) { |
|
48 | + define("NOLOGIN",'1'); |
|
49 | +} |
|
50 | +// If this page is public (can be called outside logged session) |
|
33 | 51 | |
34 | 52 | |
35 | 53 | // Force entity if a value is provided into HTTP header. Otherwise, will use the entity of user of token used. |
36 | -if (! empty($_SERVER['HTTP_DOLAPIENTITY'])) define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']); |
|
54 | +if (! empty($_SERVER['HTTP_DOLAPIENTITY'])) { |
|
55 | + define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']); |
|
56 | +} |
|
37 | 57 | |
38 | 58 | |
39 | 59 | $res=0; |
40 | -if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php'; |
|
41 | -if (! $res) die("Include of main fails"); |
|
60 | +if (! $res && file_exists("../main.inc.php")) { |
|
61 | + $res=include '../main.inc.php'; |
|
62 | +} |
|
63 | +if (! $res) { |
|
64 | + die("Include of main fails"); |
|
65 | +} |
|
42 | 66 | |
43 | 67 | require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/AutoLoader.php'; |
44 | 68 | |
@@ -146,7 +170,9 @@ discard block |
||
146 | 170 | |
147 | 171 | // Defined if module is enabled |
148 | 172 | $enabled=true; |
149 | - if (empty($conf->$modulenameforenabled->enabled)) $enabled=false; |
|
173 | + if (empty($conf->$modulenameforenabled->enabled)) { |
|
174 | + $enabled=false; |
|
175 | + } |
|
150 | 176 | |
151 | 177 | if ($enabled) |
152 | 178 | { |
@@ -160,7 +186,9 @@ discard block |
||
160 | 186 | { |
161 | 187 | while (($file_searched = readdir($handle_part))!==false) |
162 | 188 | { |
163 | - if ($file_searched == 'api_access.class.php') continue; |
|
189 | + if ($file_searched == 'api_access.class.php') { |
|
190 | + continue; |
|
191 | + } |
|
164 | 192 | |
165 | 193 | if (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i",$file_searched,$regapi)) |
166 | 194 | { |
@@ -171,13 +199,11 @@ discard block |
||
171 | 199 | { |
172 | 200 | //dol_syslog("Found API by index.php: classname=".$classname."Api for module ".$dir." into ".$dir_part.$file_searched); |
173 | 201 | $listofapis[strtolower($classname.'Api')] = $classname.'Api'; |
174 | - } |
|
175 | - elseif (class_exists($classname)) |
|
202 | + } elseif (class_exists($classname)) |
|
176 | 203 | { |
177 | 204 | //dol_syslog("Found API by index.php: classname=".$classname." for module ".$dir." into ".$dir_part.$file_searched); |
178 | 205 | $listofapis[strtolower($classname)] = $classname; |
179 | - } |
|
180 | - else |
|
206 | + } else |
|
181 | 207 | { |
182 | 208 | dol_syslog("We found an api_xxx file (".$file_searched.") but class ".$classname." does not exists after loading file", LOG_WARNING); |
183 | 209 | } |
@@ -204,10 +230,12 @@ discard block |
||
204 | 230 | if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && $reg[2] != '/resources.json' && preg_match('/^\/(swagger|resources)\.json\/(.+)$/', $reg[2], $regbis) && $regbis[2] != 'root'))) |
205 | 231 | { |
206 | 232 | $module = $reg[1]; |
207 | - if ($module == 'explorer') // If we call page to explore details of a service |
|
233 | + if ($module == 'explorer') { |
|
234 | + // If we call page to explore details of a service |
|
208 | 235 | { |
209 | 236 | $module = $regbis[2]; |
210 | 237 | } |
238 | + } |
|
211 | 239 | |
212 | 240 | $module=strtolower($module); |
213 | 241 | $moduledirforclass = getModuleDirForApiClass($module); |
@@ -216,19 +244,25 @@ discard block |
||
216 | 244 | dol_syslog("Load a dedicated API file module=".$module." moduledirforclass=".$moduledirforclass); |
217 | 245 | |
218 | 246 | $tmpmodule = $module; |
219 | - if ($tmpmodule != 'api') |
|
220 | - $tmpmodule = preg_replace('/api$/i', '', $tmpmodule); |
|
247 | + if ($tmpmodule != 'api') { |
|
248 | + $tmpmodule = preg_replace('/api$/i', '', $tmpmodule); |
|
249 | + } |
|
221 | 250 | $classfile = str_replace('_', '', $tmpmodule); |
222 | - if ($module == 'supplierproposals') |
|
223 | - $classfile = 'supplier_proposals'; |
|
224 | - if ($module == 'supplierorders') |
|
225 | - $classfile = 'supplier_orders'; |
|
226 | - if ($module == 'supplierinvoices') |
|
227 | - $classfile = 'supplier_invoices'; |
|
228 | - if ($module == 'ficheinter') |
|
229 | - $classfile = 'interventions'; |
|
230 | - if ($module == 'interventions') |
|
231 | - $classfile = 'interventions'; |
|
251 | + if ($module == 'supplierproposals') { |
|
252 | + $classfile = 'supplier_proposals'; |
|
253 | + } |
|
254 | + if ($module == 'supplierorders') { |
|
255 | + $classfile = 'supplier_orders'; |
|
256 | + } |
|
257 | + if ($module == 'supplierinvoices') { |
|
258 | + $classfile = 'supplier_invoices'; |
|
259 | + } |
|
260 | + if ($module == 'ficheinter') { |
|
261 | + $classfile = 'interventions'; |
|
262 | + } |
|
263 | + if ($module == 'interventions') { |
|
264 | + $classfile = 'interventions'; |
|
265 | + } |
|
232 | 266 | |
233 | 267 | $dir_part_file = dol_buildpath('/' . $moduledirforclass . '/class/api_' . $classfile . '.class.php', 0, 2); |
234 | 268 | |
@@ -237,17 +271,19 @@ discard block |
||
237 | 271 | dol_syslog('Search /' . $moduledirforclass . '/class/api_' . $classfile . '.class.php => dir_part_file=' . $dir_part_file . ' classname=' . $classname); |
238 | 272 | |
239 | 273 | $res = false; |
240 | - if ($dir_part_file) |
|
241 | - $res = include_once $dir_part_file; |
|
274 | + if ($dir_part_file) { |
|
275 | + $res = include_once $dir_part_file; |
|
276 | + } |
|
242 | 277 | if (! $res) { |
243 | 278 | print 'API not found (failed to include API file)'; |
244 | 279 | header('HTTP/1.1 501 API not found (failed to include API file)'); |
245 | 280 | exit(0); |
246 | 281 | } |
247 | 282 | |
248 | - if (class_exists($classname)) |
|
249 | - $api->r->addAPIClass($classname); |
|
250 | -} |
|
283 | + if (class_exists($classname)) { |
|
284 | + $api->r->addAPIClass($classname); |
|
285 | + } |
|
286 | + } |
|
251 | 287 | |
252 | 288 | // TODO If not found, redirect to explorer |
253 | 289 | //var_dump($api->r->apiVersionMap); |