dolibarr 21.0.0-beta
check.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2013-2014 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
8 * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
33include_once 'inc.php';
44$err = 0;
45$allowinstall = 0;
46$allowupgrade = false;
47$checksok = 1;
48
49$setuplang = GETPOST("selectlang", 'aZ09', 3) ? GETPOST("selectlang", 'aZ09', 3) : $langs->getDefaultLang();
50$langs->setDefaultLang($setuplang);
51
52$langs->load("install");
53
54// Now we load forced/pre-set values from install.forced.php file.
55$useforcedwizard = false;
56$forcedfile = "./install.forced.php";
57if ($conffile == "/etc/dolibarr/conf.php") {
58 $forcedfile = "/etc/dolibarr/install.forced.php";
59}
60if (@file_exists($forcedfile)) {
61 $useforcedwizard = true;
62 include_once $forcedfile;
63}
64
65dolibarr_install_syslog("- check: Dolibarr install/upgrade process started");
66
67
68/*
69 * View
70 */
71
72pHeader('', ''); // No next step for navigation buttons. Next step is defined by click on links.
73
74
75//print "<br>\n";
76//print $langs->trans("InstallEasy")."<br><br>\n";
77
78print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/gear.svg" width="20" alt="Database"> ';
79print '<span class="inline-block">'.$langs->trans("MiscellaneousChecks")."</span></h3>\n";
80
81// Check browser
82$useragent = $_SERVER['HTTP_USER_AGENT'];
83if (!empty($useragent)) {
84 $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
85 $browserversion = $tmp['browserversion'];
86 $browsername = $tmp['browsername'];
87 if ($browsername == 'ie' && $browserversion < 7) {
88 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("WarningBrowserTooOld")."<br>\n";
89 }
90}
91
92
93// Check PHP version min
94$arrayphpminversionerror = array(7, 0, 0);
95$arrayphpminversionwarning = array(7, 1, 0);
96if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) { // Minimum to use (error if lower)
97 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionerror));
98 $checksok = 0; // 0=error, 1=warning
99} elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) { // Minimum supported (warning if lower)
100 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionwarning));
101 $checksok = 1; // 0=error, 1=warning
102} else {
103 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPVersion")." ".versiontostring(versionphparray());
104}
105if (empty($force_install_nophpinfo)) {
106 print ' (<a href="phpinfo.php" target="_blank" rel="noopener noreferrer">'.$langs->trans("MoreInformation").'</a>)';
107}
108print "<br>\n";
109
110// Check PHP version max
111$arrayphpmaxversionwarning = array(8, 3, 0);
112if (versioncompare(versionphparray(), $arrayphpmaxversionwarning) > 0 && versioncompare(versionphparray(), $arrayphpmaxversionwarning) < 3) { // Maximum to use (warning if higher)
113 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooHigh", versiontostring($arrayphpmaxversionwarning));
114 $checksok = 1; // 0=error, 1=warning
115 print "<br>\n";
116}
117
118
119// Check PHP support for $_GET and $_POST
120if (!isset($_GET["testget"]) && !isset($_POST["testpost"])) { // We must keep $_GET and $_POST here
121 print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> '.$langs->trans("PHPSupportPOSTGETKo");
122 print ' (<a href="'.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?testget=ok">'.$langs->trans("Recheck").'</a>)';
123 print "<br>\n";
124 $checksok = 0;
125} else {
126 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupportPOSTGETOk")."<br>\n";
127}
128
129
130// Check if session_id is enabled
131if (!function_exists("session_id")) {
132 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupportSessions")."<br>\n";
133 $checksok = 0;
134} else {
135 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupportSessions")."<br>\n";
136}
137
138
139// Check for mbstring extension
140if (!extension_loaded("mbstring")) {
141 $langs->load("errors");
142 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "MBString")."<br>\n";
143 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
144} else {
145 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "MBString")."<br>\n";
146}
147
148// Check for json extension
149if (!extension_loaded("json")) {
150 $langs->load("errors");
151 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "JSON")."<br>\n";
152 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
153} else {
154 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "JSON")."<br>\n";
155}
156
157// Check if GD is supported (we need GD for image conversion)
158if (!function_exists("imagecreate")) {
159 $langs->load("errors");
160 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "GD")."<br>\n";
161 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
162} else {
163 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "GD")."<br>\n";
164}
165
166// Check if Curl is supported
167if (!function_exists("curl_init")) {
168 $langs->load("errors");
169 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Curl")."<br>\n";
170 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
171} else {
172 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Curl")."<br>\n";
173}
174
175// Check if PHP calendar extension is available
176if (!function_exists("easter_date")) {
177 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Calendar")."<br>\n";
178} else {
179 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Calendar")."<br>\n";
180}
181
182// Check if Xml is supported
183if (!function_exists("simplexml_load_string")) {
184 $langs->load("errors");
185 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Xml")."<br>\n";
186 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
187} else {
188 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Xml")."<br>\n";
189}
190
191// Check if UTF8 is supported
192if (!function_exists("utf8_encode")) {
193 $langs->load("errors");
194 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "UTF8")."<br>\n";
195 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
196} else {
197 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "UTF8")."<br>\n";
198}
199
200// Check if intl methods are supported if install is not from DoliWamp. TODO Why ?
201if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') {
202 if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region")) {
203 $langs->load("errors");
204 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Intl")."<br>\n";
205 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
206 } else {
207 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Intl")."<br>\n";
208 }
209}
210
211// Check if Imap is supported
212if (PHP_VERSION_ID <= 80300) {
213 if (!function_exists("imap_open")) {
214 $langs->load("errors");
215 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "IMAP")."<br>\n";
216 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
217 } else {
218 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "IMAP")."<br>\n";
219 }
220}
221
222// Check if Zip is supported
223if (!class_exists('ZipArchive')) {
224 $langs->load("errors");
225 print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "ZIP")."<br>\n";
226 // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
227} else {
228 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "ZIP")."<br>\n";
229}
230
231// Check memory
232$memrequiredorig = '64M';
233$memrequired = 64 * 1024 * 1024;
234$memmaxorig = @ini_get("memory_limit");
235$memmax = @ini_get("memory_limit");
236if ($memmaxorig != '') {
237 preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg);
238 if ($reg[2]) {
239 if (strtoupper($reg[2]) == 'G') {
240 $memmax = (int) $reg[1] * 1024 * 1024 * 1024;
241 }
242 if (strtoupper($reg[2]) == 'M') {
243 $memmax = (int) $reg[1] * 1024 * 1024;
244 }
245 if (strtoupper($reg[2]) == 'K') {
246 $memmax = (int) $reg[1] * 1024;
247 }
248 }
249 if ($memmax >= $memrequired || $memmax == -1) {
250 print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPMemoryOK", $memmaxorig, $memrequiredorig)."<br>\n";
251 } else {
252 print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> '.$langs->trans("PHPMemoryTooLow", $memmaxorig, $memrequiredorig)."<br>\n";
253 }
254}
255
256
257// If that config file is present and filled
258clearstatcache();
259if (is_readable($conffile) && filesize($conffile) > 8) {
260 dolibarr_install_syslog("check: conf file '".$conffile."' already defined");
261 $confexists = 1;
262 include_once $conffile;
263
264 $databaseok = 1;
265 if ($databaseok) {
266 // Already installed for all parts (config and database). We can propose upgrade.
267 $allowupgrade = true;
268 } else {
269 $allowupgrade = false;
270 }
271} else {
272 // If not, we create it
273 dolibarr_install_syslog("check: we try to create conf file '".$conffile."'");
274 $confexists = 0;
275
276 // First we try by copying example
277 if (@copy($conffile.".example", $conffile)) {
278 // Success
279 dolibarr_install_syslog("check: successfully copied file ".$conffile.".example into ".$conffile);
280 } else {
281 // If failed, we try to create an empty file
282 dolibarr_install_syslog("check: failed to copy file ".$conffile.".example into ".$conffile.". We try to create it.", LOG_WARNING);
283
284 $fp = @fopen($conffile, "w");
285 if ($fp) {
286 @fwrite($fp, '<?php');
287 @fwrite($fp, "\n");
288 fclose($fp);
289 } else {
290 dolibarr_install_syslog("check: failed to create a new file ".$conffile." into current dir ".getcwd().". Please check permissions.", LOG_ERR);
291 }
292 }
293
294 // First install: no upgrade necessary/required
295 $allowupgrade = false;
296}
297
298
299
300// File is missing and cannot be created
301if (!file_exists($conffile)) {
302 print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow);
303 print '<br><br><div class="error">';
304 print $langs->trans("YouMustCreateWithPermission", $conffiletoshow);
305 print '</div><br><br>'."\n";
306
307 print '<span class="opacitymedium">'.$langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok').'</span>';
308 $err++;
309} else {
310 if (dol_is_dir($conffile)) {
311 print '<img src="../theme/eldy/img/error.png" alt="Warning"> '.$langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow);
312
313 $allowinstall = 0;
314 } elseif (!is_writable($conffile)) {
315 // File exists but cannot be modified
316 if ($confexists) {
317 print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileExists", $conffiletoshow);
318 } else {
319 print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
320 }
321 print "<br>";
322 print '<img src="../theme/eldy/img/tick.png" alt="Warning"> '.$langs->trans("ConfFileIsNotWritable", $conffiletoshow);
323 print "<br>\n";
324
325 $allowinstall = 0;
326 } else {
327 // File exists and can be modified
328 if ($confexists) {
329 print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileExists", $conffiletoshow);
330 } else {
331 print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
332 }
333 print "<br>";
334 print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileIsWritable", $conffiletoshow);
335 print "<br>\n";
336
337 $allowinstall = 1;
338 }
339 print "<br>\n";
340
341 // Requirements met/all ok: display the next step button
342 if ($checksok) {
343 $ok = 0;
344
345 // Try to create db connection
346 if (file_exists($conffile)) {
347 include_once $conffile;
348 if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root)) {
349 if (!file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php")) {
350 print '<span class="error">A '.$conffiletoshow.' file exists with a dolibarr_main_document_root to '.$dolibarr_main_document_root.' that seems wrong. Try to fix or remove the '.$conffiletoshow.' file.</span><br>'."\n";
351 dol_syslog("A '".$conffiletoshow."' file exists with a dolibarr_main_document_root to ".$dolibarr_main_document_root." that seems wrong. Try to fix or remove the '".$conffiletoshow."' file.", LOG_WARNING);
352 } else {
353 require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
354
355 // If password is encoded, we decode it
356 if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
357 require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
358 if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
359 $dolibarr_main_db_encrypted_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass); // We need to set this as it is used to know the password was initially encrypted
360 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
361 } else {
362 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
363 }
364 }
365
366 // $conf already created in inc.php
367 $conf->db->type = $dolibarr_main_db_type;
368 $conf->db->host = $dolibarr_main_db_host;
369 $conf->db->port = $dolibarr_main_db_port;
370 $conf->db->name = $dolibarr_main_db_name;
371 $conf->db->user = $dolibarr_main_db_user;
372 $conf->db->pass = $dolibarr_main_db_pass;
373 $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
374 if ($db->connected && $db->database_selected) {
375 $ok = true;
376 }
377 }
378 }
379 }
380
381 // If database access is available, we set more variables
382 if ($ok) {
383 if (empty($dolibarr_main_db_encryption)) {
384 $dolibarr_main_db_encryption = 0;
385 }
386 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
387 if (empty($dolibarr_main_db_cryptkey)) {
388 $dolibarr_main_db_cryptkey = '';
389 }
390 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
391
392 $conf->setValues($db);
393 // Reset forced setup after the setValues
394 if (defined('SYSLOG_FILE')) {
395 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
396 }
397 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
398
399 // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
400 // Version to install is DOL_VERSION
401 $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL) ? $conf->global->MAIN_VERSION_LAST_INSTALL : ''));
402 $dolibarrversiontoinstallarray = versiondolibarrarray();
403 }
404
405 // Show title
406 if (getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') || getDolGlobalString('MAIN_VERSION_LAST_INSTALL')) {
407 print $langs->trans("VersionLastUpgrade").': <b><span class="ok">'.(!getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') ? $conf->global->MAIN_VERSION_LAST_INSTALL : $conf->global->MAIN_VERSION_LAST_UPGRADE).'</span></b> - ';
408 print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b>';
409 //print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired"));
410 print '<br>';
411 print '<br>';
412 } else {
413 print "<br>\n";
414 }
415
416 //print $langs->trans("InstallEasy")." ";
417 print '<h3><span class="soustitre">'.$langs->trans("ChooseYourSetupMode").'</span></h3>';
418
419 $foundrecommandedchoice = 0;
420
421 $available_choices = array();
422 $notavailable_choices = array();
423
424 if (empty($dolibarr_main_db_host)) { // This means install process was not run
425 $foundrecommandedchoice = 1; // To show only once
426 }
427
428 // Show line of first install choice
429 $choice = '<tr class="trlineforchoice'.($foundrecommandedchoice ? ' choiceselected' : '').'">'."\n";
430 $choice .= '<td class="nowrap center"><b>'.$langs->trans("FreshInstall").'</b>';
431 $choice .= '</td>';
432 $choice .= '<td class="listofchoicesdesc">';
433 $choice .= $langs->trans("FreshInstallDesc");
434 if (empty($dolibarr_main_db_host)) { // This means install process was not run
435 $choice .= '<br>';
436 //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
437 $choice .= '<div class="center"><div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div></div>';
438 // <img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ';
439 }
440
441 $choice .= '</td>';
442 $choice .= '<td class="center">';
443 if ($allowinstall) {
444 $choice .= '<a class="button" href="fileconf.php?selectlang='.$setuplang.'">'.$langs->trans("Start").'</a>';
445 } else {
446 $choice .= ($foundrecommandedchoice ? '<span class="warning">' : '').$langs->trans("InstallNotAllowed").($foundrecommandedchoice ? '</span>' : '');
447 }
448 $choice .= '</td>'."\n";
449 $choice .= '</tr>'."\n";
450
451 $positionkey = ($foundrecommandedchoice ? 999 : 0);
452 if ($allowinstall) {
453 $available_choices[$positionkey] = $choice;
454 } else {
455 $notavailable_choices[$positionkey] = $choice;
456 }
457
458 // Show upgrade lines
459 $allowupgrade = true;
460 if (empty($dolibarr_main_db_host)) { // This means install process was not run
461 $allowupgrade = false;
462 }
463 if (getDolGlobalInt("MAIN_NOT_INSTALLED")) {
464 $allowupgrade = false;
465 }
466 if (GETPOST('allowupgrade')) {
467 $allowupgrade = true;
468 }
469
470 $dir = DOL_DOCUMENT_ROOT."/install/mysql/migration/"; // We use mysql migration scripts whatever is database driver
471 dolibarr_install_syslog("Scan sql files for migration files in ".$dir);
472
473 // Get files list of migration file x.y.z-a.b.c.sql into /install/mysql/migration
474 $migrationscript = array();
475 $handle = opendir($dir);
476 if (is_resource($handle)) {
477 $versiontousetoqualifyscript = preg_replace('/-.*/', '', DOL_VERSION);
478 while (($file = readdir($handle)) !== false) {
479 $reg = array();
480 if (preg_match('/^(\d+\.\d+\.\d+)-(\d+\.\d+\.\d+)\.sql$/i', $file, $reg)) {
481 //var_dump(DOL_VERSION." ".$reg[2]." ".$versiontousetoqualifyscript." ".version_compare($versiontousetoqualifyscript, $reg[2]));
482 if (!empty($reg[2]) && version_compare($versiontousetoqualifyscript, $reg[2]) >= 0) {
483 $migrationscript[] = array('from' => $reg[1], 'to' => $reg[2]);
484 }
485 }
486 }
487 $migrationscript = dol_sort_array($migrationscript, 'from', 'asc', 1);
488 } else {
489 print '<div class="error">'.$langs->trans("ErrorCanNotReadDir", $dir).'</div>';
490 }
491
492 $count = 0;
493 foreach ($migrationscript as $migarray) {
494 $choice = '';
495
496 $count++;
497 $recommended_choice = false;
498 $version = DOL_VERSION;
499 $versionfrom = $migarray['from'];
500 $versionto = $migarray['to'];
501 $versionarray = preg_split('/[\.-]/', $version);
502 $dolibarrversionfromarray = preg_split('/[\.-]/', $versionfrom);
503 $dolibarrversiontoarray = preg_split('/[\.-]/', $versionto);
504 // Define string newversionxxx that are used for text to show
505 $newversionfrom = preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom);
506 $newversionto = preg_replace('/(\.[0-9]+)$/i', '.*', $versionto);
507 $newversionfrombis = '';
508 if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) { // From x.y.z -> x.y.z+1
509 $newversionfrombis = ' '.$langs->trans("or").' '.$versionto;
510 }
511
512 if ($ok) {
513 if (count($dolibarrlastupgradeversionarray) >= 2) { // If database access is available and last upgrade version is known
514 // Now we check if this is the first qualified choice
515 if ($allowupgrade && empty($foundrecommandedchoice) &&
516 (versioncompare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray, $versionarray) < -2)
517 ) {
518 $foundrecommandedchoice = 1; // To show only once
519 $recommended_choice = true;
520 }
521 } else {
522 // We cannot recommend a choice.
523 // A version of install may be known, but we need last upgrade.
524 }
525 }
526
527 $choice .= "\n".'<!-- choice '.$count.' -->'."\n";
528 $choice .= '<tr'.($recommended_choice ? ' class="choiceselected"' : '').'>';
529 $choice .= '<td class="nowrap center"><b>'.$langs->trans("Upgrade").'<br>'.$newversionfrom.$newversionfrombis.' -> '.$newversionto.'</b></td>';
530 $choice .= '<td class="listofchoicesdesc">';
531 $choice .= $langs->trans("UpgradeDesc");
532
533 if ($recommended_choice) {
534 $choice .= '<br>';
535 //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
536 $choice .= '<div class="center">';
537 $choice .= '<div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div>';
538 if ($count < count($migarray)) { // There are other choices after
539 print $langs->trans("MigrateIsDoneStepByStep", DOL_VERSION);
540 }
541 $choice .= '</div>';
542 }
543
544 $choice .= '</td>';
545 $choice .= '<td class="center">';
546 if ($allowupgrade) {
547 $disabled = false;
548 if ($foundrecommandedchoice == 2) {
549 $disabled = true;
550 }
551 if ($foundrecommandedchoice == 1) {
552 $foundrecommandedchoice = 2;
553 }
554 if ($disabled) {
555 $choice .= '<span class="opacitymedium">'.$langs->trans("NotYetAvailable").'</span>';
556 } else {
557 $choice .= '<a class="button runupgrade" href="upgrade.php?action=upgrade'.($count < count($migrationscript) ? '_'.$versionto : '').'&amp;selectlang='.$setuplang.'&amp;versionfrom='.$versionfrom.'&amp;versionto='.$versionto.'">'.$langs->trans("Start").'</a>';
558 }
559 } else {
560 $choice .= $langs->trans("NotAvailable");
561 }
562 $choice .= '</td>';
563 $choice .= '</tr>'."\n";
564
565 if ($allowupgrade) {
566 $available_choices[$count] = $choice;
567 } else {
568 $notavailable_choices[$count] = $choice;
569 }
570 }
571
572 // If there is no choice at all, we show all of them.
573 if (empty($available_choices)) {
574 $available_choices = $notavailable_choices;
575 $notavailable_choices = array();
576 }
577
578 // Array of install choices
579 krsort($available_choices, SORT_NATURAL);
580 print"\n";
581 print '<table width="100%" class="listofchoices">';
582 foreach ($available_choices as $choice) {
583 print $choice;
584 }
585
586 print '</table>'."\n";
587
588 if (count($notavailable_choices)) {
589 print '<br><div id="AShowChoices" style="opacity: 0.5">';
590 print '> '.$langs->trans('ShowNotAvailableOptions').'...';
591 print '</div>';
592
593 print '<div id="navail_choices" style="display:none">';
594 print "<br>\n";
595 print '<table width="100%" class="listofchoices">';
596 foreach ($notavailable_choices as $choice) {
597 print $choice;
598 }
599
600 print '</table>'."\n";
601 print '</div>';
602 }
603 }
604}
605
606print '<script type="text/javascript">
607
608$("div#AShowChoices").click(function() {
609
610 $("div#navail_choices").toggle();
611
612 if ($("div#navail_choices").css("display") == "none") {
613 $(this).text("> '.$langs->trans('ShowNotAvailableOptions').'...");
614 } else {
615 $(this).text("'.$langs->trans('HideNotAvailableOptions').'...");
616 }
617
618});
619
620/*
621$(".runupgrade").click(function() {
622 return confirm("'.dol_escape_js($langs->transnoentitiesnoconv("WarningUpgrade"), 0, 1).'");
623});
624*/
625
626</script>';
627
628dolibarr_install_syslog("- check: end");
629pFooter(1); // Never display next button
versiontostring($versionarray)
Renvoi une version en chaine depuis une version en tableau.
Definition admin.lib.php:39
versiondolibarrarray()
Return version Dolibarr.
versionphparray()
Return version PHP.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Definition admin.lib.php:69
dol_is_dir($folder)
Test if filename is a directory.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
getBrowserInfo($user_agent)
Return information about user browser.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition inc.php:535
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition inc.php:628
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:692
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.