|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
Copyright (C) 2018-2020 KANOUN Salim |
|
4
|
|
|
This program is free software; you can redistribute it and/or modify |
|
5
|
|
|
it under the terms of the Affero GNU General Public v.3 License as published by |
|
6
|
|
|
the Free Software Foundation; |
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10
|
|
|
Affero GNU General Public Public for more details. |
|
11
|
|
|
You should have received a copy of the Affero GNU General Public Public along |
|
12
|
|
|
with this program; if not, write to the Free Software Foundation, Inc., |
|
13
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Static methods for global data |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
use Ifsnop\Mysqldump as IMysqldump; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
Class Global_Data { |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Get CountryName by Code |
|
26
|
|
|
* Source country list from : https://github.com/umpirsky/country-list |
|
27
|
|
|
* @param PDO $linkpdo |
|
28
|
|
|
* @param $countryCode |
|
29
|
|
|
* @return string |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function getCountryName(PDO $linkpdo, string $countryCode) { |
|
32
|
|
|
|
|
33
|
|
|
$countryQuery=$linkpdo->prepare("SELECT country_us FROM country WHERE country_code = :countryCode"); |
|
34
|
|
|
$countryQuery->execute(array('countryCode' => $countryCode)); |
|
35
|
|
|
$countryName=$countryQuery->fetch(PDO::FETCH_COLUMN); |
|
36
|
|
|
|
|
37
|
|
|
return $countryName; |
|
38
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Return a country code depending of countryName (take account language prefrences) |
|
43
|
|
|
* @param PDO $linkpdo |
|
44
|
|
|
* @param string $countryName |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function getCountryCode(PDO $linkpdo, string $countryName) { |
|
48
|
|
|
if (GAELO_COUNTRY_LANGUAGE == "FR") { |
|
49
|
|
|
$request="SELECT country_code FROM country WHERE country_fr = :countryName"; |
|
50
|
|
|
}else if (GAELO_COUNTRY_LANGUAGE == "US") { |
|
51
|
|
|
$request="SELECT country_code FROM country WHERE country_us = :countryName"; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$countryQuery=$linkpdo->prepare($request); |
|
|
|
|
|
|
55
|
|
|
$countryQuery->execute(array('countryName' => $countryName)); |
|
56
|
|
|
$countryName=$countryQuery->fetch(PDO::FETCH_COLUMN); |
|
57
|
|
|
|
|
58
|
|
|
return $countryName; |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Return all studies name in the platefome (activated true to get only active study) |
|
64
|
|
|
* @param PDO $linkpdo |
|
65
|
|
|
* @param bool $onlyActivated |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function getAllStudies(PDO $linkpdo, bool $onlyActivated=false) { |
|
69
|
|
|
|
|
70
|
|
|
if ($onlyActivated) { |
|
71
|
|
|
$connecter=$linkpdo->prepare('SELECT name FROM studies WHERE active=1 ORDER BY name'); |
|
72
|
|
|
}else { |
|
73
|
|
|
$connecter=$linkpdo->prepare('SELECT name FROM studies ORDER BY name'); |
|
74
|
|
|
} |
|
75
|
|
|
$connecter->execute(); |
|
76
|
|
|
|
|
77
|
|
|
$AvailableStudies=$connecter->fetchall(PDO::FETCH_COLUMN); |
|
78
|
|
|
|
|
79
|
|
|
return $AvailableStudies; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get All centers objects declared in the plateform |
|
84
|
|
|
* @param PDO $linkpdo |
|
85
|
|
|
* @return Center[] |
|
86
|
|
|
*/ |
|
87
|
|
|
public static function getAllCentersObjects(PDO $linkpdo) { |
|
88
|
|
|
$centerQuery=$linkpdo->prepare('SELECT code FROM centers ORDER BY code'); |
|
89
|
|
|
$centerQuery->execute(); |
|
90
|
|
|
$centers=$centerQuery->fetchAll(PDO::FETCH_COLUMN); |
|
91
|
|
|
|
|
92
|
|
|
$centerObject=[]; |
|
93
|
|
|
foreach ($centers as $center) { |
|
94
|
|
|
$centerObject[]=new Center($linkpdo, $center); |
|
95
|
|
|
} |
|
96
|
|
|
return $centerObject; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public static function getAllCentersAsJson(PDO $linkpdo) : String { |
|
100
|
|
|
$centersObjectArray=Global_Data::getAllCentersObjects($linkpdo); |
|
101
|
|
|
$centerResponseArray=[]; |
|
102
|
|
|
|
|
103
|
|
|
foreach ($centersObjectArray as $centerObject) { |
|
104
|
|
|
$centerResponseArray[$centerObject->code]['centerName']=$centerObject->name; |
|
105
|
|
|
$centerResponseArray[$centerObject->code]['countryCode']=$centerObject->countryCode; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$temporaryFile=Global_Data::writeTextAsTempFile(json_encode($centerResponseArray, JSON_FORCE_OBJECT)); |
|
109
|
|
|
|
|
110
|
|
|
return $temporaryFile; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Get All possible countries |
|
115
|
|
|
* @param PDO $linkpdo |
|
116
|
|
|
* @return array |
|
117
|
|
|
*/ |
|
118
|
|
|
public static function getAllcountries(PDO $linkpdo) { |
|
119
|
|
|
$countryQuery=$linkpdo->prepare("SELECT * FROM country ORDER BY country_us"); |
|
120
|
|
|
$countryQuery->execute(); |
|
121
|
|
|
$countryCode=$countryQuery->fetchAll(PDO::FETCH_ASSOC); |
|
122
|
|
|
|
|
123
|
|
|
return $countryCode; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Get all possible jobs existing in the plateform |
|
128
|
|
|
* @param PDO $linkpdo |
|
129
|
|
|
* @return array |
|
130
|
|
|
*/ |
|
131
|
|
|
public static function getAllJobs(PDO $linkpdo) { |
|
132
|
|
|
$jobQuery=$linkpdo->prepare('SELECT name FROM job ORDER BY name'); |
|
133
|
|
|
$jobQuery->execute(); |
|
134
|
|
|
$jobs=$jobQuery->fetchAll(PDO::FETCH_COLUMN); |
|
135
|
|
|
return $jobs; |
|
136
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Return userObject array for all users in the system |
|
141
|
|
|
* @return User[] |
|
142
|
|
|
*/ |
|
143
|
|
|
public static function getAllUsers(PDO $linkpdo) { |
|
144
|
|
|
$req=$linkpdo->prepare('SELECT username FROM users'); |
|
145
|
|
|
$req->execute(); |
|
146
|
|
|
$answers=$req->fetchAll(PDO::FETCH_COLUMN); |
|
147
|
|
|
|
|
148
|
|
|
$usersObjects=[]; |
|
149
|
|
|
foreach ($answers as $username) { |
|
150
|
|
|
$usersObjects[]=new User($username, $linkpdo); |
|
151
|
|
|
} |
|
152
|
|
|
return $usersObjects; |
|
153
|
|
|
|
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Return full list of series IDs in the database, just to export reference for administrator |
|
158
|
|
|
* @param PDO $linkpdo |
|
159
|
|
|
* @return mixed |
|
160
|
|
|
*/ |
|
161
|
|
|
public static function getAllSeriesOrthancID(PDO $linkpdo) { |
|
162
|
|
|
$seriesQuery=$linkpdo->prepare('SELECT Series_Orthanc_ID FROM orthanc_series'); |
|
163
|
|
|
$seriesQuery->execute(); |
|
164
|
|
|
$seriesOrthancIds=$seriesQuery->fetchAll(PDO::FETCH_COLUMN); |
|
165
|
|
|
return $seriesOrthancIds; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Update plateform preferences |
|
170
|
|
|
* @param array $post |
|
171
|
|
|
* @param PDO $linkpdo |
|
172
|
|
|
*/ |
|
173
|
|
|
public static function updatePlateformPreferences(array $post, PDO $linkpdo) { |
|
174
|
|
|
|
|
175
|
|
|
$prefUpdater=$linkpdo->prepare('UPDATE preferences SET patient_code_length=:codeLenght, |
|
176
|
|
|
name=:name, |
|
177
|
|
|
admin_email=:email, |
|
178
|
|
|
email_reply_to=:reply_to, |
|
179
|
|
|
corporation=:corporation, |
|
180
|
|
|
address=:address, |
|
181
|
|
|
parse_date_import=:parse_date_import, |
|
182
|
|
|
parse_country_name=:parseCountryName, |
|
183
|
|
|
orthanc_exposed_internal_address=:Orthanc_Exposed_Internal_Address, |
|
184
|
|
|
orthanc_exposed_internal_port=:Orthanc_Exposed_Internal_Port, |
|
185
|
|
|
orthanc_exposed_internal_login=:Orthanc_Exposed_Internal_Login, |
|
186
|
|
|
orthanc_exposed_internal_password=:Orthanc_Exposed_Internal_Password, |
|
187
|
|
|
orthanc_exposed_external_address=:Orthanc_Exposed_External_Address, |
|
188
|
|
|
orthanc_exposed_external_port=:Orthanc_Exposed_External_Port, |
|
189
|
|
|
orthanc_exposed_external_login=:Orthanc_Exposed_External_Login, |
|
190
|
|
|
orthanc_exposed_external_password=:Orthanc_Exposed_External_Password, |
|
191
|
|
|
orthanc_pacs_address=:Orthanc_Pacs_Address, |
|
192
|
|
|
orthanc_pacs_port=:Orthanc_Pacs_Port, |
|
193
|
|
|
orthanc_pacs_login=:Orthanc_Pacs_Login, |
|
194
|
|
|
orthanc_pacs_password=:Orthanc_Pacs_Password, |
|
195
|
|
|
use_smtp=:use_smtp, |
|
196
|
|
|
smtp_host=:smtp_host, |
|
197
|
|
|
smtp_port=:smtp_port, |
|
198
|
|
|
smtp_user=:smtp_user, |
|
199
|
|
|
smtp_password=:smtp_password, |
|
200
|
|
|
smtp_secure=:smtp_secure |
|
201
|
|
|
WHERE 1'); |
|
202
|
|
|
|
|
203
|
|
|
$prefUpdater->execute(array('codeLenght'=>$post['patientCodeLenght'], |
|
204
|
|
|
'corporation'=>$post['coporation'], |
|
205
|
|
|
'address'=>$post['webAddress'], |
|
206
|
|
|
'email'=>$post['adminEmail'], |
|
207
|
|
|
'reply_to'=>$post['replyTo'], |
|
208
|
|
|
'name'=>$post['plateformName'], |
|
209
|
|
|
'parse_date_import'=>$post['parseDateImport'], |
|
210
|
|
|
'parseCountryName'=>$post['parseCountryName'], |
|
211
|
|
|
'Orthanc_Exposed_Internal_Address'=>$post['orthancExposedInternalAddress'], |
|
212
|
|
|
'Orthanc_Exposed_Internal_Port'=>$post['orthancExposedInternalPort'], |
|
213
|
|
|
'Orthanc_Exposed_Internal_Login'=>$post['orthancExposedInternalLogin'], |
|
214
|
|
|
'Orthanc_Exposed_Internal_Password'=>$post['orthancExposedInternalPassword'], |
|
215
|
|
|
'Orthanc_Pacs_Address'=>$post['orthancPacsAddress'], |
|
216
|
|
|
'Orthanc_Pacs_Port'=>$post['orthancPacsPort'], |
|
217
|
|
|
'Orthanc_Pacs_Login'=>$post['orthancPacsLogin'], |
|
218
|
|
|
'Orthanc_Pacs_Password'=>$post['orthancPacsPassword'], |
|
219
|
|
|
'use_smtp'=>isset($post['useSmtp']) ? 1 : 0, |
|
220
|
|
|
'smtp_host'=>$post['smtpHost'], |
|
221
|
|
|
'smtp_port'=>$post['smtpPort'], |
|
222
|
|
|
'smtp_user'=>$post['smtpUser'], |
|
223
|
|
|
'smtp_password'=>$post['smtpPassword'], |
|
224
|
|
|
'smtp_secure'=>$post['smtpSecure'], |
|
225
|
|
|
'Orthanc_Exposed_External_Address'=>$post['orthancExposedExternalAddress'], |
|
226
|
|
|
'Orthanc_Exposed_External_Port'=>$post['orthancExposedExternalPort'], |
|
227
|
|
|
'Orthanc_Exposed_External_Login'=>$post['orthancExposedExternalLogin'], |
|
228
|
|
|
'Orthanc_Exposed_External_Password'=>$post['orthancExposedExternalPassword'] |
|
229
|
|
|
)); |
|
230
|
|
|
|
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Generate a raw dump of the database for backum purpose |
|
235
|
|
|
*/ |
|
236
|
|
|
public static function dumpDatabase() : String { |
|
237
|
|
|
|
|
238
|
|
|
$fileSql=tempnam(ini_get('upload_tmp_dir'), 'TMPDB_'); |
|
239
|
|
|
|
|
240
|
|
|
try { |
|
241
|
|
|
if (DATABASE_SSL) { |
|
|
|
|
|
|
242
|
|
|
$dump=new IMysqldump\Mysqldump('mysql:host='.DATABASE_HOST.';dbname='.DATABASE_NAME.'', ''.DATABASE_USERNAME.'', ''.DATABASE_PASSWORD.'', array(), Session::getSSLPDOArrayOptions()); |
|
|
|
|
|
|
243
|
|
|
}else { |
|
244
|
|
|
$dump=new IMysqldump\Mysqldump('mysql:host='.DATABASE_HOST.';dbname='.DATABASE_NAME.'', ''.DATABASE_USERNAME.'', ''.DATABASE_PASSWORD.''); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
$dump->start($fileSql); |
|
248
|
|
|
}catch (Exception $e) { |
|
249
|
|
|
echo 'mysqldump-php error: '.$e->getMessage(); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
return $fileSql; |
|
253
|
|
|
|
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
public static function writeTextAsTempFile($strData) : String { |
|
257
|
|
|
$seriesJsonFile=tempnam(ini_get('upload_tmp_dir'), 'TMPGaelOFile_'); |
|
258
|
|
|
$seriesJsonHandler=fopen($seriesJsonFile, 'w'); |
|
259
|
|
|
fwrite($seriesJsonHandler, $strData); |
|
260
|
|
|
fclose($seriesJsonHandler); |
|
261
|
|
|
|
|
262
|
|
|
return $seriesJsonFile; |
|
263
|
|
|
|
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* Generate a JSON File with all Series stored in Orthanc (either marked deleted or not) |
|
268
|
|
|
* For backup purposes |
|
269
|
|
|
*/ |
|
270
|
|
|
public static function dumpOrthancSeriesJSON(PDO $linkpdo) : String { |
|
271
|
|
|
|
|
272
|
|
|
$seriesFullJson=json_encode(Global_Data::getAllSeriesOrthancID($linkpdo), JSON_PRETTY_PRINT); |
|
273
|
|
|
$seriesJsonFile=Global_Data::writeTextAsTempFile($seriesFullJson); |
|
274
|
|
|
|
|
275
|
|
|
return $seriesJsonFile; |
|
276
|
|
|
|
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* Return file of a folder on the server |
|
281
|
|
|
* Use of Generator |
|
282
|
|
|
* For backup purpose |
|
283
|
|
|
*/ |
|
284
|
|
|
public static function getFileInPath(String $path) { |
|
285
|
|
|
|
|
286
|
|
|
if (is_dir($path)) { |
|
287
|
|
|
// Create recursive directory iterator |
|
288
|
|
|
$files=new RecursiveIteratorIterator( |
|
289
|
|
|
new RecursiveDirectoryIterator($path), |
|
290
|
|
|
RecursiveIteratorIterator::LEAVES_ONLY |
|
291
|
|
|
); |
|
292
|
|
|
|
|
293
|
|
|
foreach ($files as $name => $file) { |
|
294
|
|
|
// Skip directories (they would be added automatically) |
|
295
|
|
|
if (!$file->isDir()) { |
|
296
|
|
|
// Get real and relative path for current file |
|
297
|
|
|
yield $file; |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
|
|
304
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths