@@ -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']) |
@@ -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 | } |
@@ -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 | } |
@@ -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 |
@@ -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 | } |
@@ -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 |
@@ -30,25 +30,25 @@ discard block |
||
30 | 30 | */ |
31 | 31 | function paypaladmin_prepare_head() |
32 | 32 | { |
33 | - global $langs, $conf; |
|
33 | + global $langs, $conf; |
|
34 | 34 | |
35 | - $h = 0; |
|
36 | - $head = array(); |
|
35 | + $h = 0; |
|
36 | + $head = array(); |
|
37 | 37 | |
38 | - $head[$h][0] = DOL_URL_ROOT."/paypal/admin/paypal.php"; |
|
39 | - $head[$h][1] = $langs->trans("PayPal"); |
|
40 | - $head[$h][2] = 'paypalaccount'; |
|
41 | - $h++; |
|
38 | + $head[$h][0] = DOL_URL_ROOT."/paypal/admin/paypal.php"; |
|
39 | + $head[$h][1] = $langs->trans("PayPal"); |
|
40 | + $head[$h][2] = 'paypalaccount'; |
|
41 | + $h++; |
|
42 | 42 | |
43 | - $object=new stdClass(); |
|
43 | + $object=new stdClass(); |
|
44 | 44 | |
45 | 45 | // Show more tabs from modules |
46 | 46 | // Entries must be declared in modules descriptor with line |
47 | 47 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
48 | 48 | // $this->tabs = array('entity:-tabname); to remove a tab |
49 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin'); |
|
49 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin'); |
|
50 | 50 | |
51 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin','remove'); |
|
51 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin','remove'); |
|
52 | 52 | |
53 | 53 | return $head; |
54 | 54 | } |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | */ |
65 | 65 | function showPaypalPaymentUrl($type,$ref) |
66 | 66 | { |
67 | - global $conf, $langs; |
|
67 | + global $conf, $langs; |
|
68 | 68 | |
69 | - $langs->load("paypal"); |
|
69 | + $langs->load("paypal"); |
|
70 | 70 | $langs->load("paybox"); |
71 | 71 | $servicename='PayPal'; |
72 | 72 | $out='<br><br>'; |
@@ -90,28 +90,28 @@ discard block |
||
90 | 90 | */ |
91 | 91 | function getPaypalPaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_free_tag') |
92 | 92 | { |
93 | - global $conf; |
|
93 | + global $conf; |
|
94 | 94 | |
95 | - $ref=str_replace(' ','',$ref); |
|
95 | + $ref=str_replace(' ','',$ref); |
|
96 | 96 | |
97 | 97 | if ($type == 'free') |
98 | 98 | { |
99 | - $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':''); |
|
100 | - if (! empty($conf->global->PAYPAL_SECURITY_TOKEN)) |
|
101 | - { |
|
102 | - if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN; |
|
103 | - else $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); |
|
104 | - } |
|
99 | + $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':''); |
|
100 | + if (! empty($conf->global->PAYPAL_SECURITY_TOKEN)) |
|
101 | + { |
|
102 | + if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN; |
|
103 | + else $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); |
|
104 | + } |
|
105 | 105 | } |
106 | 106 | if ($type == 'order') |
107 | 107 | { |
108 | 108 | $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':''); |
109 | 109 | if ($mode == 1) $out.='order_ref'; |
110 | 110 | if ($mode == 0) $out.=urlencode($ref); |
111 | - $out.=($mode?'</font>':''); |
|
111 | + $out.=($mode?'</font>':''); |
|
112 | 112 | if (! empty($conf->global->PAYPAL_SECURITY_TOKEN)) |
113 | 113 | { |
114 | - if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN; |
|
114 | + if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN; |
|
115 | 115 | else |
116 | 116 | { |
117 | 117 | $out.='&securekey='.($mode?'<font color="#666666">':''); |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':''); |
127 | 127 | if ($mode == 1) $out.='invoice_ref'; |
128 | 128 | if ($mode == 0) $out.=urlencode($ref); |
129 | - $out.=($mode?'</font>':''); |
|
129 | + $out.=($mode?'</font>':''); |
|
130 | 130 | if (! empty($conf->global->PAYPAL_SECURITY_TOKEN)) |
131 | 131 | { |
132 | - if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN; |
|
132 | + if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN; |
|
133 | 133 | else |
134 | 134 | { |
135 | 135 | $out.='&securekey='.($mode?'<font color="#666666">':''); |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':''); |
145 | 145 | if ($mode == 1) $out.='contractline_ref'; |
146 | 146 | if ($mode == 0) $out.=urlencode($ref); |
147 | - $out.=($mode?'</font>':''); |
|
147 | + $out.=($mode?'</font>':''); |
|
148 | 148 | if (! empty($conf->global->PAYPAL_SECURITY_TOKEN)) |
149 | 149 | { |
150 | - if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN; |
|
150 | + if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN; |
|
151 | 151 | else |
152 | 152 | { |
153 | 153 | $out.='&securekey='.($mode?'<font color="#666666">':''); |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':''); |
163 | 163 | if ($mode == 1) $out.='member_ref'; |
164 | 164 | if ($mode == 0) $out.=urlencode($ref); |
165 | - $out.=($mode?'</font>':''); |
|
165 | + $out.=($mode?'</font>':''); |
|
166 | 166 | if (! empty($conf->global->PAYPAL_SECURITY_TOKEN)) |
167 | 167 | { |
168 | - if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN; |
|
168 | + if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN; |
|
169 | 169 | else |
170 | 170 | { |
171 | 171 | $out.='&securekey='.($mode?'<font color="#666666">':''); |
@@ -274,15 +274,15 @@ discard block |
||
274 | 274 | |
275 | 275 | if ($ErrorCode == 10729) |
276 | 276 | { |
277 | - $mesg.= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n"; |
|
277 | + $mesg.= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n"; |
|
278 | 278 | } |
279 | 279 | else |
280 | 280 | { |
281 | - $mesg = $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n"; |
|
282 | - $mesg.= $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n"; |
|
283 | - $mesg.= $langs->trans('ShortErrorMessage') . ": " . $ErrorShortMsg."<br>\n"; |
|
284 | - $mesg.= $langs->trans('ErrorCode') . ": " . $ErrorCode."<br>\n"; |
|
285 | - $mesg.= $langs->trans('ErrorSeverityCode') . ": " . $ErrorSeverityCode."<br>\n"; |
|
281 | + $mesg = $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n"; |
|
282 | + $mesg.= $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n"; |
|
283 | + $mesg.= $langs->trans('ShortErrorMessage') . ": " . $ErrorShortMsg."<br>\n"; |
|
284 | + $mesg.= $langs->trans('ErrorCode') . ": " . $ErrorCode."<br>\n"; |
|
285 | + $mesg.= $langs->trans('ErrorSeverityCode') . ": " . $ErrorSeverityCode."<br>\n"; |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | return $mesg; |
@@ -346,28 +346,28 @@ discard block |
||
346 | 346 | $nvpstr = $nvpstr . "&CANCELURL=" . urlencode($cancelURL); |
347 | 347 | if (! empty($conf->global->PAYPAL_ALLOW_NOTES)) |
348 | 348 | { |
349 | - $nvpstr = $nvpstr . "&ALLOWNOTE=0"; |
|
349 | + $nvpstr = $nvpstr . "&ALLOWNOTE=0"; |
|
350 | 350 | } |
351 | 351 | if (empty($conf->global->PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS)) |
352 | 352 | { |
353 | - $nvpstr = $nvpstr . "&NOSHIPPING=1"; // An empty or not complete shipping address will be accepted |
|
353 | + $nvpstr = $nvpstr . "&NOSHIPPING=1"; // An empty or not complete shipping address will be accepted |
|
354 | 354 | } |
355 | 355 | else |
356 | 356 | { |
357 | - $nvpstr = $nvpstr . "&NOSHIPPING=0"; // A valid shipping address is required (full required fields mandatory) |
|
357 | + $nvpstr = $nvpstr . "&NOSHIPPING=0"; // A valid shipping address is required (full required fields mandatory) |
|
358 | 358 | } |
359 | 359 | $nvpstr = $nvpstr . "&SOLUTIONTYPE=" . urlencode($solutionType); |
360 | 360 | $nvpstr = $nvpstr . "&LANDINGPAGE=" . urlencode($landingPage); |
361 | 361 | if (! empty($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER)) |
362 | 362 | { |
363 | - $nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER); // Hotline phone number |
|
363 | + $nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER); // Hotline phone number |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | $paypalprefix = 'PAYMENTREQUEST_0_'; |
367 | 367 | //$paypalprefix = ''; |
368 | - if (! empty($paypalprefix) && $paymentType == 'Sole') $paymentType='Sale'; |
|
368 | + if (! empty($paypalprefix) && $paymentType == 'Sole') $paymentType='Sale'; |
|
369 | 369 | |
370 | - $nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount); // Total for all elements |
|
370 | + $nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount); // Total for all elements |
|
371 | 371 | |
372 | 372 | $nvpstr = $nvpstr . "&".$paypalprefix."INVNUM=" . urlencode($tag); |
373 | 373 | $nvpstr = $nvpstr . "&".$paypalprefix."AMT=". urlencode($paymentAmount); // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT |
@@ -393,26 +393,26 @@ discard block |
||
393 | 393 | |
394 | 394 | if (! empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo) |
395 | 395 | { |
396 | - global $dolibarr_main_url_root; |
|
396 | + global $dolibarr_main_url_root; |
|
397 | 397 | |
398 | - // Define $urlwithroot |
|
399 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
400 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
401 | - //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
398 | + // Define $urlwithroot |
|
399 | + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
400 | + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
401 | + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
402 | 402 | |
403 | - $urllogo=$urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo); |
|
404 | - $nvpstr = $nvpstr . "&LOGOIMG=" . urlencode($urllogo); |
|
403 | + $urllogo=$urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo); |
|
404 | + $nvpstr = $nvpstr . "&LOGOIMG=" . urlencode($urllogo); |
|
405 | 405 | } |
406 | 406 | if (! empty($conf->global->PAYPAL_BRANDNAME)) |
407 | 407 | { |
408 | - $nvpstr = $nvpstr . "&BRANDNAME=" . urlencode($conf->global->PAYPAL_BRANDNAME); // BRANDNAME |
|
408 | + $nvpstr = $nvpstr . "&BRANDNAME=" . urlencode($conf->global->PAYPAL_BRANDNAME); // BRANDNAME |
|
409 | 409 | } |
410 | 410 | if (! empty($conf->global->PAYPAL_NOTETOBUYER)) |
411 | 411 | { |
412 | - $nvpstr = $nvpstr . "&NOTETOBUYER=" . urlencode($conf->global->PAYPAL_NOTETOBUYER); // PAYPAL_NOTETOBUYER |
|
412 | + $nvpstr = $nvpstr . "&NOTETOBUYER=" . urlencode($conf->global->PAYPAL_NOTETOBUYER); // PAYPAL_NOTETOBUYER |
|
413 | 413 | } |
414 | 414 | |
415 | - $_SESSION["FinalPaymentAmt"] = $paymentAmount; |
|
415 | + $_SESSION["FinalPaymentAmt"] = $paymentAmount; |
|
416 | 416 | $_SESSION["currencyCodeType"] = $currencyCodeType; |
417 | 417 | $_SESSION["PaymentType"] = $paymentType; // 'Mark', 'Sole' |
418 | 418 | $_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR']; // Payer ip |
@@ -592,27 +592,27 @@ discard block |
||
592 | 592 | |
593 | 593 | // TODO problem with triggers |
594 | 594 | $API_version="98.0"; |
595 | - if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha')) // We can force sand box with param 'forcesandbox' |
|
596 | - { |
|
597 | - $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp"; |
|
598 | - $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token="; |
|
599 | - } |
|
600 | - else |
|
601 | - { |
|
602 | - $API_Endpoint = "https://api-3t.paypal.com/nvp"; |
|
603 | - $API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token="; |
|
604 | - } |
|
605 | - |
|
606 | - // Clean parameters |
|
607 | - $PAYPAL_API_USER=""; |
|
608 | - if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER; |
|
609 | - $PAYPAL_API_PASSWORD=""; |
|
610 | - if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD; |
|
611 | - $PAYPAL_API_SIGNATURE=""; |
|
612 | - if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE; |
|
613 | - $PAYPAL_API_SANDBOX=""; |
|
614 | - if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX; |
|
615 | - // TODO END problem with triggers |
|
595 | + if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha')) // We can force sand box with param 'forcesandbox' |
|
596 | + { |
|
597 | + $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp"; |
|
598 | + $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token="; |
|
599 | + } |
|
600 | + else |
|
601 | + { |
|
602 | + $API_Endpoint = "https://api-3t.paypal.com/nvp"; |
|
603 | + $API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token="; |
|
604 | + } |
|
605 | + |
|
606 | + // Clean parameters |
|
607 | + $PAYPAL_API_USER=""; |
|
608 | + if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER; |
|
609 | + $PAYPAL_API_PASSWORD=""; |
|
610 | + if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD; |
|
611 | + $PAYPAL_API_SIGNATURE=""; |
|
612 | + if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE; |
|
613 | + $PAYPAL_API_SANDBOX=""; |
|
614 | + if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX; |
|
615 | + // TODO END problem with triggers |
|
616 | 616 | |
617 | 617 | dol_syslog("Paypal API endpoint ".$API_Endpoint); |
618 | 618 | |
@@ -723,20 +723,20 @@ discard block |
||
723 | 723 | */ |
724 | 724 | function getApiError() |
725 | 725 | { |
726 | - $errors=array(); |
|
726 | + $errors=array(); |
|
727 | 727 | |
728 | - $resArray=$_SESSION['reshash']; |
|
728 | + $resArray=$_SESSION['reshash']; |
|
729 | 729 | |
730 | - if(isset($_SESSION['curl_error_no'])) |
|
731 | - { |
|
732 | - $errors[] = $_SESSION['curl_error_no'].'-'.$_SESSION['curl_error_msg']; |
|
733 | - } |
|
730 | + if(isset($_SESSION['curl_error_no'])) |
|
731 | + { |
|
732 | + $errors[] = $_SESSION['curl_error_no'].'-'.$_SESSION['curl_error_msg']; |
|
733 | + } |
|
734 | 734 | |
735 | - foreach($resArray as $key => $value) |
|
736 | - { |
|
737 | - $errors[] = $key.'-'.$value; |
|
738 | - } |
|
735 | + foreach($resArray as $key => $value) |
|
736 | + { |
|
737 | + $errors[] = $key.'-'.$value; |
|
738 | + } |
|
739 | 739 | |
740 | - return $errors; |
|
740 | + return $errors; |
|
741 | 741 | } |
742 | 742 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | if ($action == 'setvalue' && $user->admin) |
43 | 43 | { |
44 | - $db->begin(); |
|
44 | + $db->begin(); |
|
45 | 45 | |
46 | 46 | $result=dolibarr_set_const($db, "PAYPAL_API_USER",GETPOST('PAYPAL_API_USER','alpha'),'chaine',0,'',$conf->entity); |
47 | 47 | if (! $result > 0) $error++; |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK",GETPOST('ONLINE_PAYMENT_MESSAGE_OK'),'chaine',0,'',$conf->entity); |
67 | 67 | if (! $result > 0) $error++; |
68 | 68 | $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO",GETPOST('ONLINE_PAYMENT_MESSAGE_KO'),'chaine',0,'',$conf->entity); |
69 | - if (! $result > 0) $error++; |
|
70 | - $result=dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL",GETPOST('ONLINE_PAYMENT_SENDEMAIL'),'chaine',0,'',$conf->entity); |
|
71 | - if (! $result > 0) $error++; |
|
72 | - // Payment token for URL |
|
73 | - $result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN",GETPOST('PAYMENT_SECURITY_TOKEN','alpha'),'chaine',0,'',$conf->entity); |
|
74 | - if (! $result > 0) $error++; |
|
75 | - $result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE",GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE','alpha'),'chaine',0,'',$conf->entity); |
|
76 | - if (! $result > 0) $error++; |
|
77 | - |
|
78 | - if (! $error) |
|
79 | - { |
|
80 | - $db->commit(); |
|
81 | - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
|
82 | - } |
|
83 | - else |
|
84 | - { |
|
85 | - $db->rollback(); |
|
86 | - dol_print_error($db); |
|
69 | + if (! $result > 0) $error++; |
|
70 | + $result=dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL",GETPOST('ONLINE_PAYMENT_SENDEMAIL'),'chaine',0,'',$conf->entity); |
|
71 | + if (! $result > 0) $error++; |
|
72 | + // Payment token for URL |
|
73 | + $result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN",GETPOST('PAYMENT_SECURITY_TOKEN','alpha'),'chaine',0,'',$conf->entity); |
|
74 | + if (! $result > 0) $error++; |
|
75 | + $result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE",GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE','alpha'),'chaine',0,'',$conf->entity); |
|
76 | + if (! $result > 0) $error++; |
|
77 | + |
|
78 | + if (! $error) |
|
79 | + { |
|
80 | + $db->commit(); |
|
81 | + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
|
82 | + } |
|
83 | + else |
|
84 | + { |
|
85 | + $db->rollback(); |
|
86 | + dol_print_error($db); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | // Test if php curl exist |
130 | 130 | if (! function_exists('curl_version')) |
131 | 131 | { |
132 | - $langs->load("errors"); |
|
133 | - setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors'); |
|
132 | + $langs->load("errors"); |
|
133 | + setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors'); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | |
213 | 213 | if (! empty($conf->banque->enabled)) |
214 | 214 | { |
215 | - print '<tr class="oddeven"><td>'; |
|
216 | - print $langs->trans("BankAccount").'</td><td>'; |
|
217 | - print $form->select_comptes($conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS, 'PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1); |
|
218 | - print '</td></tr>'; |
|
215 | + print '<tr class="oddeven"><td>'; |
|
216 | + print $langs->trans("BankAccount").'</td><td>'; |
|
217 | + print $form->select_comptes($conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS, 'PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1); |
|
218 | + print '</td></tr>'; |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | print '<tr class="oddeven"><td>'; |
@@ -268,13 +268,13 @@ discard block |
||
268 | 268 | print $langs->trans("SecurityToken").'</td><td>'; |
269 | 269 | print '<input size="48" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">'; |
270 | 270 | if (! empty($conf->use_javascript_ajax)) |
271 | - print ' '.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"'); |
|
272 | - print '</td></tr>'; |
|
271 | + print ' '.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"'); |
|
272 | + print '</td></tr>'; |
|
273 | 273 | |
274 | - print '<tr class="oddeven"><td>'; |
|
275 | - print $langs->trans("SecurityTokenIsUnique").'</td><td>'; |
|
276 | - print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYMENT_SECURITY_TOKEN)?0:$conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE),1); |
|
277 | - print '</td></tr>'; |
|
274 | + print '<tr class="oddeven"><td>'; |
|
275 | + print $langs->trans("SecurityTokenIsUnique").'</td><td>'; |
|
276 | + print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYMENT_SECURITY_TOKEN)?0:$conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE),1); |
|
277 | + print '</td></tr>'; |
|
278 | 278 | |
279 | 279 | print '</table>'; |
280 | 280 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | // Help doc |
290 | 290 | print '<u>'.$langs->trans("InformationToFindParameters","Paypal").'</u>:<br>'; |
291 | 291 | if (! empty($conf->use_javascript_ajax)) |
292 | - print '<a href="#" class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>'; |
|
292 | + print '<a href="#" class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>'; |
|
293 | 293 | |
294 | 294 | $realpaypalurl='www.paypal.com'; |
295 | 295 | $sandboxpaypalurl='developer.paypal.com'; |
@@ -309,15 +309,15 @@ discard block |
||
309 | 309 | |
310 | 310 | if (! empty($conf->use_javascript_ajax)) |
311 | 311 | { |
312 | - print "\n".'<script type="text/javascript">'; |
|
313 | - print '$(document).ready(function () { |
|
312 | + print "\n".'<script type="text/javascript">'; |
|
313 | + print '$(document).ready(function () { |
|
314 | 314 | $("#apidoc").hide(); |
315 | 315 | $("#apidoca").click(function() { |
316 | 316 | $("#apidoc").show(); |
317 | 317 | $("#apidoca").hide(); |
318 | 318 | }) |
319 | 319 | });'; |
320 | - print '</script>'; |
|
320 | + print '</script>'; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | print '<br><br>'; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | { |
50 | 50 | $obj = $db->fetch_object($result); |
51 | 51 | preg_match('/([0-9]+)$/i',$obj->name,$reg); |
52 | - if ($reg[1]) $lastftpentry = $reg[1]; |
|
52 | + if ($reg[1]) $lastftpentry = $reg[1]; |
|
53 | 53 | } |
54 | 54 | else |
55 | 55 | { |
@@ -59,37 +59,37 @@ discard block |
||
59 | 59 | if ($action == 'add' || GETPOST('modify','alpha')) |
60 | 60 | { |
61 | 61 | $ftp_name = "FTP_NAME_" . $entry;// $_POST["numero_entry"]; |
62 | - $ftp_server = "FTP_SERVER_" . $entry; //$_POST["numero_entry"]; |
|
62 | + $ftp_server = "FTP_SERVER_" . $entry; //$_POST["numero_entry"]; |
|
63 | 63 | |
64 | - $error=0; |
|
64 | + $error=0; |
|
65 | 65 | |
66 | - if (! GETPOST("$ftp_name",'alpha')) |
|
67 | - { |
|
68 | - $error=1; |
|
69 | - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); |
|
70 | - } |
|
66 | + if (! GETPOST("$ftp_name",'alpha')) |
|
67 | + { |
|
68 | + $error=1; |
|
69 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); |
|
70 | + } |
|
71 | 71 | |
72 | - if (! GETPOST("$ftp_server",'alpha')) |
|
73 | - { |
|
74 | - $error=1; |
|
75 | - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server")), null, 'errors'); |
|
76 | - } |
|
72 | + if (! GETPOST("$ftp_server",'alpha')) |
|
73 | + { |
|
74 | + $error=1; |
|
75 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server")), null, 'errors'); |
|
76 | + } |
|
77 | 77 | |
78 | 78 | if (! $error) |
79 | 79 | { |
80 | - $ftp_port = "FTP_PORT_" . $entry; |
|
80 | + $ftp_port = "FTP_PORT_" . $entry; |
|
81 | 81 | $ftp_user = "FTP_USER_" . $entry; |
82 | 82 | $ftp_password = "FTP_PASSWORD_" . $entry; |
83 | 83 | $ftp_passive = "FTP_PASSIVE_" . $entry; |
84 | 84 | |
85 | 85 | $db->begin(); |
86 | 86 | |
87 | - $result1=dolibarr_set_const($db, "FTP_PORT_" . $entry,GETPOST($ftp_port,'alpha'),'chaine',0,'',$conf->entity); |
|
88 | - if ($result1) $result2=dolibarr_set_const($db, "FTP_SERVER_" . $entry, GETPOST($ftp_server,'alpha'),'chaine',0,'',$conf->entity); |
|
89 | - if ($result2) $result3=dolibarr_set_const($db, "FTP_USER_" . $entry,GETPOST($ftp_user,'alpha'),'chaine',0,'',$conf->entity); |
|
90 | - if ($result3) $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $entry,GETPOST($ftp_password,'alpha'),'chaine',0,'',$conf->entity); |
|
91 | - if ($result4) $result5=dolibarr_set_const($db, "FTP_NAME_" . $entry,GETPOST($ftp_name,'alpha'),'chaine',0,'',$conf->entity); |
|
92 | - if ($result5) $result6=dolibarr_set_const($db, "FTP_PASSIVE_" . $entry,GETPOST($ftp_passive,'alpha'),'chaine',0,'',$conf->entity); |
|
87 | + $result1=dolibarr_set_const($db, "FTP_PORT_" . $entry,GETPOST($ftp_port,'alpha'),'chaine',0,'',$conf->entity); |
|
88 | + if ($result1) $result2=dolibarr_set_const($db, "FTP_SERVER_" . $entry, GETPOST($ftp_server,'alpha'),'chaine',0,'',$conf->entity); |
|
89 | + if ($result2) $result3=dolibarr_set_const($db, "FTP_USER_" . $entry,GETPOST($ftp_user,'alpha'),'chaine',0,'',$conf->entity); |
|
90 | + if ($result3) $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $entry,GETPOST($ftp_password,'alpha'),'chaine',0,'',$conf->entity); |
|
91 | + if ($result4) $result5=dolibarr_set_const($db, "FTP_NAME_" . $entry,GETPOST($ftp_name,'alpha'),'chaine',0,'',$conf->entity); |
|
92 | + if ($result5) $result6=dolibarr_set_const($db, "FTP_PASSIVE_" . $entry,GETPOST($ftp_passive,'alpha'),'chaine',0,'',$conf->entity); |
|
93 | 93 | |
94 | 94 | if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) |
95 | 95 | { |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | { |
112 | 112 | $db->begin(); |
113 | 113 | |
114 | - $result1=dolibarr_del_const($db,"FTP_PORT_" . $entry,$conf->entity); |
|
115 | - if ($result1) $result2=dolibarr_del_const($db,"FTP_SERVER_" . $entry,$conf->entity); |
|
116 | - if ($result2) $result3=dolibarr_del_const($db,"FTP_USER_" . $entry,$conf->entity); |
|
117 | - if ($result3) $result4=dolibarr_del_const($db,"FTP_PASSWORD_" . $entry,$conf->entity); |
|
118 | - if ($result4) $result5=dolibarr_del_const($db,"FTP_NAME_" . $entry,$conf->entity); |
|
119 | - if ($result4) $result6=dolibarr_del_const($db,"FTP_PASSIVE_" . $entry,$conf->entity); |
|
114 | + $result1=dolibarr_del_const($db,"FTP_PORT_" . $entry,$conf->entity); |
|
115 | + if ($result1) $result2=dolibarr_del_const($db,"FTP_SERVER_" . $entry,$conf->entity); |
|
116 | + if ($result2) $result3=dolibarr_del_const($db,"FTP_USER_" . $entry,$conf->entity); |
|
117 | + if ($result3) $result4=dolibarr_del_const($db,"FTP_PASSWORD_" . $entry,$conf->entity); |
|
118 | + if ($result4) $result5=dolibarr_del_const($db,"FTP_NAME_" . $entry,$conf->entity); |
|
119 | + if ($result4) $result6=dolibarr_del_const($db,"FTP_PASSIVE_" . $entry,$conf->entity); |
|
120 | 120 | |
121 | 121 | if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6) |
122 | 122 | { |
@@ -147,165 +147,165 @@ discard block |
||
147 | 147 | |
148 | 148 | if (! function_exists('ftp_connect')) |
149 | 149 | { |
150 | - print $langs->trans("FTPFeatureNotSupportedByYourPHP"); |
|
150 | + print $langs->trans("FTPFeatureNotSupportedByYourPHP"); |
|
151 | 151 | } |
152 | 152 | else |
153 | 153 | { |
154 | 154 | |
155 | - // Formulaire ajout |
|
156 | - print '<form name="ftpconfig" action="ftpclient.php" method="post">'; |
|
157 | - print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
158 | - |
|
159 | - print '<table class="noborder" width="100%">'; |
|
160 | - print '<tr class="liste_titre">'; |
|
161 | - print '<td colspan="2">'.$langs->trans("NewFTPClient").'</td>'; |
|
162 | - print '<td>'.$langs->trans("Example").'</td>'; |
|
163 | - print '</tr>'; |
|
164 | - |
|
165 | - print '<tr class="pair">'; |
|
166 | - print '<td>'.$langs->trans("Label").'</td>'; |
|
167 | - print '<td><input type="text" name="FTP_NAME_'.($lastftpentry+1).'" value="'.GETPOST("FTP_NAME_" . ($lastftpentry+1)).'" size="64"></td>'; |
|
168 | - print '<td>My FTP access</td>'; |
|
169 | - print '</tr>'; |
|
170 | - |
|
171 | - print '<tr class="impair">'; |
|
172 | - print '<td>'.$langs->trans("Server").'</td>'; |
|
173 | - print '<td><input type="text" name="FTP_SERVER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_SERVER_" . ($lastftpentry+1)).'" size="64"></td>'; |
|
174 | - print '<td>localhost</td>'; |
|
175 | - print '</tr>'; |
|
176 | - |
|
177 | - print '<tr class="pair">'; |
|
178 | - print '<td width="100">'.$langs->trans("Port").'</td>'; |
|
179 | - print '<td><input type="text" name="FTP_PORT_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PORT_" . ($lastftpentry+1)).'" size="64"></td>'; |
|
180 | - print '<td>21 for pure non crypted FTP or if option FTP_CONNECT_WITH_SSL (See Home-Setup-Other) is on (FTPS)<br>22 if option FTP_CONNECT_WITH_SFTP (See Home-Setup-Other) is on (SFTP)</td>'; |
|
181 | - print '</tr>'; |
|
182 | - |
|
183 | - print '<tr class="impair">'; |
|
184 | - print '<td>'.$langs->trans("User").'</td>'; |
|
185 | - print '<td><input type="text" name="FTP_USER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_USER_" . ($lastftpentry+1)).'" size="24"></td>'; |
|
186 | - print '<td>myftplogin</td>'; |
|
187 | - print '</tr>'; |
|
188 | - |
|
189 | - print '<tr class="pair">'; |
|
190 | - print '<td>'.$langs->trans("Password").'</td>'; |
|
191 | - print '<td><input type="password" name="FTP_PASSWORD_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PASSWORD_" . ($lastftpentry+1)).'" size="24"></td>'; |
|
192 | - print '<td>myftppassword</td>'; |
|
193 | - print '</tr>'; |
|
194 | - |
|
195 | - print '<tr class="impair">'; |
|
196 | - print '<td>'.$langs->trans("FTPPassiveMode").'</td>'; |
|
197 | - $defaultpassive=GETPOST("FTP_PASSIVE_" . ($lastftpentry+1)); |
|
198 | - if (! isset($_POST["FTP_PASSIVE_" . ($lastftpentry+1)])) $defaultpassive=empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT)?0:1; |
|
199 | - print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry+1), $defaultpassive, 2).'</td>'; |
|
200 | - print '<td>'.$langs->trans("No").'</td>'; |
|
201 | - print '</tr>'; |
|
155 | + // Formulaire ajout |
|
156 | + print '<form name="ftpconfig" action="ftpclient.php" method="post">'; |
|
157 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
158 | + |
|
159 | + print '<table class="noborder" width="100%">'; |
|
160 | + print '<tr class="liste_titre">'; |
|
161 | + print '<td colspan="2">'.$langs->trans("NewFTPClient").'</td>'; |
|
162 | + print '<td>'.$langs->trans("Example").'</td>'; |
|
163 | + print '</tr>'; |
|
164 | + |
|
165 | + print '<tr class="pair">'; |
|
166 | + print '<td>'.$langs->trans("Label").'</td>'; |
|
167 | + print '<td><input type="text" name="FTP_NAME_'.($lastftpentry+1).'" value="'.GETPOST("FTP_NAME_" . ($lastftpentry+1)).'" size="64"></td>'; |
|
168 | + print '<td>My FTP access</td>'; |
|
169 | + print '</tr>'; |
|
170 | + |
|
171 | + print '<tr class="impair">'; |
|
172 | + print '<td>'.$langs->trans("Server").'</td>'; |
|
173 | + print '<td><input type="text" name="FTP_SERVER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_SERVER_" . ($lastftpentry+1)).'" size="64"></td>'; |
|
174 | + print '<td>localhost</td>'; |
|
175 | + print '</tr>'; |
|
176 | + |
|
177 | + print '<tr class="pair">'; |
|
178 | + print '<td width="100">'.$langs->trans("Port").'</td>'; |
|
179 | + print '<td><input type="text" name="FTP_PORT_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PORT_" . ($lastftpentry+1)).'" size="64"></td>'; |
|
180 | + print '<td>21 for pure non crypted FTP or if option FTP_CONNECT_WITH_SSL (See Home-Setup-Other) is on (FTPS)<br>22 if option FTP_CONNECT_WITH_SFTP (See Home-Setup-Other) is on (SFTP)</td>'; |
|
181 | + print '</tr>'; |
|
182 | + |
|
183 | + print '<tr class="impair">'; |
|
184 | + print '<td>'.$langs->trans("User").'</td>'; |
|
185 | + print '<td><input type="text" name="FTP_USER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_USER_" . ($lastftpentry+1)).'" size="24"></td>'; |
|
186 | + print '<td>myftplogin</td>'; |
|
187 | + print '</tr>'; |
|
188 | + |
|
189 | + print '<tr class="pair">'; |
|
190 | + print '<td>'.$langs->trans("Password").'</td>'; |
|
191 | + print '<td><input type="password" name="FTP_PASSWORD_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PASSWORD_" . ($lastftpentry+1)).'" size="24"></td>'; |
|
192 | + print '<td>myftppassword</td>'; |
|
193 | + print '</tr>'; |
|
194 | + |
|
195 | + print '<tr class="impair">'; |
|
196 | + print '<td>'.$langs->trans("FTPPassiveMode").'</td>'; |
|
197 | + $defaultpassive=GETPOST("FTP_PASSIVE_" . ($lastftpentry+1)); |
|
198 | + if (! isset($_POST["FTP_PASSIVE_" . ($lastftpentry+1)])) $defaultpassive=empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT)?0:1; |
|
199 | + print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry+1), $defaultpassive, 2).'</td>'; |
|
200 | + print '<td>'.$langs->trans("No").'</td>'; |
|
201 | + print '</tr>'; |
|
202 | 202 | |
203 | - print '</table>'; |
|
203 | + print '</table>'; |
|
204 | 204 | |
205 | - ?> |
|
205 | + ?> |
|
206 | 206 | <br><div class="center"><input type="submit" class="button" value="<?php echo $langs->trans("Add") ?>"></div> |
207 | 207 | <input type="hidden" name="action" value="add"> |
208 | 208 | <input type="hidden" name="numero_entry" value="<?php echo ($lastftpentry+1) ?>"> |
209 | 209 | <?php |
210 | - print '</form>'; |
|
211 | - ?> |
|
210 | + print '</form>'; |
|
211 | + ?> |
|
212 | 212 | |
213 | 213 | <br> |
214 | 214 | |
215 | 215 | <?php |
216 | 216 | |
217 | - $sql ="select name, value, note from ".MAIN_DB_PREFIX."const"; |
|
218 | - $sql.=" WHERE name like 'FTP_SERVER_%'"; |
|
219 | - $sql.=" ORDER BY name"; |
|
217 | + $sql ="select name, value, note from ".MAIN_DB_PREFIX."const"; |
|
218 | + $sql.=" WHERE name like 'FTP_SERVER_%'"; |
|
219 | + $sql.=" ORDER BY name"; |
|
220 | 220 | |
221 | - dol_syslog("ftpclient select ftp setup", LOG_DEBUG); |
|
222 | - $resql=$db->query($sql); |
|
223 | - if ($resql) |
|
224 | - { |
|
225 | - $num =$db->num_rows($resql); |
|
226 | - $i=0; |
|
221 | + dol_syslog("ftpclient select ftp setup", LOG_DEBUG); |
|
222 | + $resql=$db->query($sql); |
|
223 | + if ($resql) |
|
224 | + { |
|
225 | + $num =$db->num_rows($resql); |
|
226 | + $i=0; |
|
227 | 227 | |
228 | - while ($i < $num) |
|
229 | - { |
|
230 | - $obj = $db->fetch_object($resql); |
|
228 | + while ($i < $num) |
|
229 | + { |
|
230 | + $obj = $db->fetch_object($resql); |
|
231 | 231 | |
232 | - preg_match('/([0-9]+)$/i',$obj->name,$reg); |
|
233 | - $idrss = $reg[0]; |
|
234 | - //print "x".join(',',$reg)."=".$obj->name."=".$idrss; |
|
232 | + preg_match('/([0-9]+)$/i',$obj->name,$reg); |
|
233 | + $idrss = $reg[0]; |
|
234 | + //print "x".join(',',$reg)."=".$obj->name."=".$idrss; |
|
235 | 235 | |
236 | - print "<form name=\"externalrssconfig\" action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">"; |
|
237 | - print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
238 | - print '<input type="hidden" name="numero_entry" value="'.$idrss.'">'; |
|
236 | + print "<form name=\"externalrssconfig\" action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">"; |
|
237 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
238 | + print '<input type="hidden" name="numero_entry" value="'.$idrss.'">'; |
|
239 | 239 | |
240 | - print '<table class="noborder" width="100%">'."\n"; |
|
241 | - |
|
242 | - print '<tr class="liste_titre">'; |
|
243 | - print '<td class="fieldtitle">'.$langs->trans("FTP")." ".($idrss)."</td>"; |
|
244 | - print '<td></td>'; |
|
245 | - print "</tr>"; |
|
246 | - |
|
247 | - $keyforname="FTP_NAME_" . $idrss; |
|
248 | - $keyforserver="FTP_SERVER_" . $idrss; |
|
249 | - $keyforport="FTP_PORT_" . $idrss; |
|
250 | - $keyforuser="FTP_USER_" . $idrss; |
|
251 | - $keyforpassword="FTP_PASSWORD_" . $idrss; |
|
252 | - $keyforpassive="FTP_PASSIVE_" . $idrss; |
|
240 | + print '<table class="noborder" width="100%">'."\n"; |
|
241 | + |
|
242 | + print '<tr class="liste_titre">'; |
|
243 | + print '<td class="fieldtitle">'.$langs->trans("FTP")." ".($idrss)."</td>"; |
|
244 | + print '<td></td>'; |
|
245 | + print "</tr>"; |
|
246 | + |
|
247 | + $keyforname="FTP_NAME_" . $idrss; |
|
248 | + $keyforserver="FTP_SERVER_" . $idrss; |
|
249 | + $keyforport="FTP_PORT_" . $idrss; |
|
250 | + $keyforuser="FTP_USER_" . $idrss; |
|
251 | + $keyforpassword="FTP_PASSWORD_" . $idrss; |
|
252 | + $keyforpassive="FTP_PASSIVE_" . $idrss; |
|
253 | 253 | |
254 | - print '<tr class="oddeven">'; |
|
255 | - print "<td>".$langs->trans("Name")."</td>"; |
|
256 | - print "<td><input type=\"text\" class=\"flat\" name=\"FTP_NAME_" . $idrss . "\" value=\"" . $conf->global->$keyforname . "\" size=\"64\"></td>"; |
|
257 | - print "</tr>"; |
|
254 | + print '<tr class="oddeven">'; |
|
255 | + print "<td>".$langs->trans("Name")."</td>"; |
|
256 | + print "<td><input type=\"text\" class=\"flat\" name=\"FTP_NAME_" . $idrss . "\" value=\"" . $conf->global->$keyforname . "\" size=\"64\"></td>"; |
|
257 | + print "</tr>"; |
|
258 | 258 | |
259 | 259 | |
260 | - print '<tr class="oddeven">'; |
|
261 | - print "<td>".$langs->trans("Server")."</td>"; |
|
262 | - print "<td><input type=\"text\" class=\"flat\" name=\"FTP_SERVER_" . $idrss . "\" value=\"" . $conf->global->$keyforserver . "\" size=\"64\"></td>"; |
|
263 | - print "</tr>"; |
|
260 | + print '<tr class="oddeven">'; |
|
261 | + print "<td>".$langs->trans("Server")."</td>"; |
|
262 | + print "<td><input type=\"text\" class=\"flat\" name=\"FTP_SERVER_" . $idrss . "\" value=\"" . $conf->global->$keyforserver . "\" size=\"64\"></td>"; |
|
263 | + print "</tr>"; |
|
264 | 264 | |
265 | 265 | |
266 | - print '<tr class="oddeven">'; |
|
267 | - print "<td width=\"100\">".$langs->trans("Port")."</td>"; |
|
268 | - print "<td><input type=\"text\" class=\"flat\" name=\"FTP_PORT_" . $idrss . "\" value=\"" . $conf->global->$keyforport . "\" size=\"64\"></td>"; |
|
269 | - print "</tr>"; |
|
266 | + print '<tr class="oddeven">'; |
|
267 | + print "<td width=\"100\">".$langs->trans("Port")."</td>"; |
|
268 | + print "<td><input type=\"text\" class=\"flat\" name=\"FTP_PORT_" . $idrss . "\" value=\"" . $conf->global->$keyforport . "\" size=\"64\"></td>"; |
|
269 | + print "</tr>"; |
|
270 | 270 | |
271 | 271 | |
272 | - print '<tr class="oddeven">'; |
|
273 | - print "<td width=\"100\">".$langs->trans("User")."</td>"; |
|
274 | - print "<td><input type=\"text\" class=\"flat\" name=\"FTP_USER_" . $idrss . "\" value=\"" . $conf->global->$keyforuser . "\" size=\"24\"></td>"; |
|
275 | - print "</tr>"; |
|
272 | + print '<tr class="oddeven">'; |
|
273 | + print "<td width=\"100\">".$langs->trans("User")."</td>"; |
|
274 | + print "<td><input type=\"text\" class=\"flat\" name=\"FTP_USER_" . $idrss . "\" value=\"" . $conf->global->$keyforuser . "\" size=\"24\"></td>"; |
|
275 | + print "</tr>"; |
|
276 | 276 | |
277 | 277 | |
278 | - print '<tr class="oddeven">'; |
|
279 | - print "<td width=\"100\">".$langs->trans("Password")."</td>"; |
|
280 | - print "<td><input type=\"password\" class=\"flat\" name=\"FTP_PASSWORD_" . $idrss . "\" value=\"" . $conf->global->$keyforpassword . "\" size=\"24\"></td>"; |
|
281 | - print "</tr>"; |
|
278 | + print '<tr class="oddeven">'; |
|
279 | + print "<td width=\"100\">".$langs->trans("Password")."</td>"; |
|
280 | + print "<td><input type=\"password\" class=\"flat\" name=\"FTP_PASSWORD_" . $idrss . "\" value=\"" . $conf->global->$keyforpassword . "\" size=\"24\"></td>"; |
|
281 | + print "</tr>"; |
|
282 | 282 | |
283 | 283 | |
284 | - print '<tr class="oddeven">'; |
|
285 | - print "<td width=\"100\">".$langs->trans("FTPPassiveMode")."</td>"; |
|
286 | - print '<td>'.$form->selectyesno('FTP_PASSIVE_'.$idrss, $conf->global->$keyforpassive, 1).'</td>'; |
|
287 | - print "</tr>"; |
|
288 | - |
|
289 | - print "<tr>"; |
|
290 | - print "<td colspan=\"2\" align=\"center\">"; |
|
291 | - print "<input type=\"submit\" class=\"button\" name=\"modify\" value=\"".$langs->trans("Modify")."\">"; |
|
292 | - print " "; |
|
293 | - print "<input type=\"submit\" class=\"button\" name=\"delete\" value=\"".$langs->trans("Delete")."\">"; |
|
294 | - print "</td>"; |
|
295 | - print "</tr>"; |
|
296 | - |
|
297 | - print '</table>'; |
|
284 | + print '<tr class="oddeven">'; |
|
285 | + print "<td width=\"100\">".$langs->trans("FTPPassiveMode")."</td>"; |
|
286 | + print '<td>'.$form->selectyesno('FTP_PASSIVE_'.$idrss, $conf->global->$keyforpassive, 1).'</td>'; |
|
287 | + print "</tr>"; |
|
288 | + |
|
289 | + print "<tr>"; |
|
290 | + print "<td colspan=\"2\" align=\"center\">"; |
|
291 | + print "<input type=\"submit\" class=\"button\" name=\"modify\" value=\"".$langs->trans("Modify")."\">"; |
|
292 | + print " "; |
|
293 | + print "<input type=\"submit\" class=\"button\" name=\"delete\" value=\"".$langs->trans("Delete")."\">"; |
|
294 | + print "</td>"; |
|
295 | + print "</tr>"; |
|
296 | + |
|
297 | + print '</table>'; |
|
298 | 298 | |
299 | - print "</form>"; |
|
300 | - print '<br>'; |
|
299 | + print "</form>"; |
|
300 | + print '<br>'; |
|
301 | 301 | |
302 | - $i++; |
|
303 | - } |
|
304 | - } |
|
305 | - else |
|
306 | - { |
|
307 | - dol_print_error($db); |
|
308 | - } |
|
302 | + $i++; |
|
303 | + } |
|
304 | + } |
|
305 | + else |
|
306 | + { |
|
307 | + dol_print_error($db); |
|
308 | + } |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | // End of page |