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