check.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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. /**
  24. * \file htdocs/install/check.php
  25. * \ingroup install
  26. * \brief Test if file conf can be modified and if does not exists, test if install process can create it
  27. */
  28. include_once 'inc.php';
  29. global $langs;
  30. $err = 0;
  31. $allowinstall = 0;
  32. $allowupgrade = false;
  33. $checksok = 1;
  34. $setuplang = GETPOST("selectlang", 'aZ09', 3) ?GETPOST("selectlang", 'aZ09', 3) : $langs->getDefaultLang();
  35. $langs->setDefaultLang($setuplang);
  36. $langs->load("install");
  37. // Now we load forced/pre-set values from install.forced.php file.
  38. $useforcedwizard = false;
  39. $forcedfile = "./install.forced.php";
  40. if ($conffile == "/etc/dolibarr/conf.php") {
  41. $forcedfile = "/etc/dolibarr/install.forced.php";
  42. }
  43. if (@file_exists($forcedfile)) {
  44. $useforcedwizard = true;
  45. include_once $forcedfile;
  46. }
  47. dolibarr_install_syslog("- check: Dolibarr install/upgrade process started");
  48. /*
  49. * View
  50. */
  51. pHeader('', ''); // No next step for navigation buttons. Next step is defined by click on links.
  52. //print "<br>\n";
  53. //print $langs->trans("InstallEasy")."<br><br>\n";
  54. print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/gear.svg" width="20" alt="Database"> ';
  55. print '<span class="inline-block">'.$langs->trans("MiscellaneousChecks")."</span></h3>\n";
  56. // Check browser
  57. $useragent = $_SERVER['HTTP_USER_AGENT'];
  58. if (!empty($useragent)) {
  59. $tmp = getBrowserInfo($_SERVER["HTTP_USER_AGENT"]);
  60. $browserversion = $tmp['browserversion'];
  61. $browsername = $tmp['browsername'];
  62. if ($browsername == 'ie' && $browserversion < 7) {
  63. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("WarningBrowserTooOld")."<br>\n";
  64. }
  65. }
  66. // Check PHP version min
  67. $arrayphpminversionerror = array(5, 6, 0);
  68. $arrayphpminversionwarning = array(5, 6, 0);
  69. if (versioncompare(versionphparray(), $arrayphpminversionerror) < 0) { // Minimum to use (error if lower)
  70. print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionerror));
  71. $checksok = 0; // 0=error, 1=warning
  72. } elseif (versioncompare(versionphparray(), $arrayphpminversionwarning) < 0) { // Minimum supported (warning if lower)
  73. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooLow", versiontostring($arrayphpminversionwarning));
  74. $checksok = 0; // 0=error, 1=warning
  75. } else {
  76. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPVersion")." ".versiontostring(versionphparray());
  77. }
  78. if (empty($force_install_nophpinfo)) {
  79. print ' (<a href="phpinfo.php" target="_blank" rel="noopener noreferrer">'.$langs->trans("MoreInformation").'</a>)';
  80. }
  81. print "<br>\n";
  82. // Check PHP version max
  83. $arrayphpmaxversionwarning = array(8, 1, 0);
  84. if (versioncompare(versionphparray(), $arrayphpmaxversionwarning) > 0 && versioncompare(versionphparray(), $arrayphpmaxversionwarning) < 3) { // Maximum to use (warning if higher)
  85. print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPVersionTooHigh", versiontostring($arrayphpmaxversionwarning));
  86. $checksok = 1; // 0=error, 1=warning
  87. print "<br>\n";
  88. }
  89. // Check PHP support for $_GET and $_POST
  90. if (!isset($_GET["testget"]) && !isset($_POST["testpost"])) { // We must keep $_GET and $_POST here
  91. print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> '.$langs->trans("PHPSupportPOSTGETKo");
  92. print ' (<a href="'.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?testget=ok">'.$langs->trans("Recheck").'</a>)';
  93. print "<br>\n";
  94. $checksok = 0;
  95. } else {
  96. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupportPOSTGETOk")."<br>\n";
  97. }
  98. // Check if session_id is enabled
  99. if (!function_exists("session_id")) {
  100. print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupportSessions")."<br>\n";
  101. $checksok = 0;
  102. } else {
  103. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupportSessions")."<br>\n";
  104. }
  105. // Check for mbstring extension
  106. if (!extension_loaded("mbstring")) {
  107. $langs->load("errors");
  108. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "MBString")."<br>\n";
  109. // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
  110. } else {
  111. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "MBString")."<br>\n";
  112. }
  113. // Check for json extension
  114. if (!extension_loaded("json")) {
  115. $langs->load("errors");
  116. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "JSON")."<br>\n";
  117. // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
  118. } else {
  119. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "JSON")."<br>\n";
  120. }
  121. // Check if GD is supported (we need GD for image conversion)
  122. if (!function_exists("imagecreate")) {
  123. $langs->load("errors");
  124. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "GD")."<br>\n";
  125. // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
  126. } else {
  127. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "GD")."<br>\n";
  128. }
  129. // Check if Curl is supported
  130. if (!function_exists("curl_init")) {
  131. $langs->load("errors");
  132. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Curl")."<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", "Curl")."<br>\n";
  136. }
  137. // Check if PHP calendar extension is available
  138. if (!function_exists("easter_date")) {
  139. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Calendar")."<br>\n";
  140. } else {
  141. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Calendar")."<br>\n";
  142. }
  143. // Check if Curl is supported
  144. if (!function_exists("simplexml_load_string")) {
  145. $langs->load("errors");
  146. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Xml")."<br>\n";
  147. // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
  148. } else {
  149. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Xml")."<br>\n";
  150. }
  151. // Check if UTF8 is supported
  152. if (!function_exists("utf8_encode")) {
  153. $langs->load("errors");
  154. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "UTF8")."<br>\n";
  155. // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
  156. } else {
  157. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "UTF8")."<br>\n";
  158. }
  159. // Check if intl methods are supported
  160. if (empty($_SERVER["SERVER_ADMIN"]) || $_SERVER["SERVER_ADMIN"] != 'doliwamp@localhost') {
  161. if (!function_exists("locale_get_primary_language") || !function_exists("locale_get_region")) {
  162. $langs->load("errors");
  163. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "Intl")."<br>\n";
  164. // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
  165. } else {
  166. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "Intl")."<br>\n";
  167. }
  168. }
  169. // Check if Curl is supported
  170. if (!function_exists("imap_open")) {
  171. $langs->load("errors");
  172. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "IMAP")."<br>\n";
  173. // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
  174. } else {
  175. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "IMAP")."<br>\n";
  176. }
  177. if (!class_exists('ZipArchive')) {
  178. $langs->load("errors");
  179. print '<img src="../theme/eldy/img/warning.png" alt="Error" class="valignmiddle"> '.$langs->trans("ErrorPHPDoesNotSupport", "ZIP")."<br>\n";
  180. // $checksok = 0; // If ko, just warning. So check must still be 1 (otherwise no way to install)
  181. } else {
  182. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPSupport", "ZIP")."<br>\n";
  183. }
  184. // Check memory
  185. $memrequiredorig = '64M';
  186. $memrequired = 64 * 1024 * 1024;
  187. $memmaxorig = @ini_get("memory_limit");
  188. $memmax = @ini_get("memory_limit");
  189. if ($memmaxorig != '') {
  190. preg_match('/([0-9]+)([a-zA-Z]*)/i', $memmax, $reg);
  191. if ($reg[2]) {
  192. if (strtoupper($reg[2]) == 'G') {
  193. $memmax = $reg[1] * 1024 * 1024 * 1024;
  194. }
  195. if (strtoupper($reg[2]) == 'M') {
  196. $memmax = $reg[1] * 1024 * 1024;
  197. }
  198. if (strtoupper($reg[2]) == 'K') {
  199. $memmax = $reg[1] * 1024;
  200. }
  201. }
  202. if ($memmax >= $memrequired || $memmax == -1) {
  203. print '<img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> '.$langs->trans("PHPMemoryOK", $memmaxorig, $memrequiredorig)."<br>\n";
  204. } else {
  205. print '<img src="../theme/eldy/img/warning.png" alt="Warning" class="valignmiddle"> '.$langs->trans("PHPMemoryTooLow", $memmaxorig, $memrequiredorig)."<br>\n";
  206. }
  207. }
  208. // If that config file is present and filled
  209. clearstatcache();
  210. if (is_readable($conffile) && filesize($conffile) > 8) {
  211. dolibarr_install_syslog("check: conf file '".$conffile."' already defined");
  212. $confexists = 1;
  213. include_once $conffile;
  214. $databaseok = 1;
  215. if ($databaseok) {
  216. // Already installed for all parts (config and database). We can propose upgrade.
  217. $allowupgrade = true;
  218. } else {
  219. $allowupgrade = false;
  220. }
  221. } else {
  222. // If not, we create it
  223. dolibarr_install_syslog("check: we try to create conf file '".$conffile."'");
  224. $confexists = 0;
  225. // First we try by copying example
  226. if (@copy($conffile.".example", $conffile)) {
  227. // Success
  228. dolibarr_install_syslog("check: successfully copied file ".$conffile.".example into ".$conffile);
  229. } else {
  230. // If failed, we try to create an empty file
  231. dolibarr_install_syslog("check: failed to copy file ".$conffile.".example into ".$conffile.". We try to create it.", LOG_WARNING);
  232. $fp = @fopen($conffile, "w");
  233. if ($fp) {
  234. @fwrite($fp, '<?php');
  235. @fputs($fp, "\n");
  236. fclose($fp);
  237. } else {
  238. dolibarr_install_syslog("check: failed to create a new file ".$conffile." into current dir ".getcwd().". Please check permissions.", LOG_ERR);
  239. }
  240. }
  241. // First install: no upgrade necessary/required
  242. $allowupgrade = false;
  243. }
  244. // File is missing and cannot be created
  245. if (!file_exists($conffile)) {
  246. print '<img src="../theme/eldy/img/error.png" alt="Error" class="valignmiddle"> '.$langs->trans("ConfFileDoesNotExistsAndCouldNotBeCreated", $conffiletoshow);
  247. print '<br><br><div class="error">';
  248. print $langs->trans("YouMustCreateWithPermission", $conffiletoshow);
  249. print '</div><br><br>'."\n";
  250. print '<span class="opacitymedium">'.$langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'].'?testget=ok').'</span>';
  251. $err++;
  252. } else {
  253. if (dol_is_dir($conffile)) {
  254. print '<img src="../theme/eldy/img/error.png" alt="Warning"> '.$langs->trans("ConfFileMustBeAFileNotADir", $conffiletoshow);
  255. $allowinstall = 0;
  256. } elseif (!is_writable($conffile)) {
  257. // File exists but cannot be modified
  258. if ($confexists) {
  259. print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileExists", $conffiletoshow);
  260. } else {
  261. print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
  262. }
  263. print "<br>";
  264. print '<img src="../theme/eldy/img/tick.png" alt="Warning"> '.$langs->trans("ConfFileIsNotWritable", $conffiletoshow);
  265. print "<br>\n";
  266. $allowinstall = 0;
  267. } else {
  268. // File exists and can be modified
  269. if ($confexists) {
  270. print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileExists", $conffiletoshow);
  271. } else {
  272. print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileCouldBeCreated", $conffiletoshow);
  273. }
  274. print "<br>";
  275. print '<img src="../theme/eldy/img/tick.png" alt="Ok"> '.$langs->trans("ConfFileIsWritable", $conffiletoshow);
  276. print "<br>\n";
  277. $allowinstall = 1;
  278. }
  279. print "<br>\n";
  280. // Requirements met/all ok: display the next step button
  281. if ($checksok) {
  282. $ok = 0;
  283. // Try to create db connection
  284. if (file_exists($conffile)) {
  285. include_once $conffile;
  286. if (!empty($dolibarr_main_db_type) && !empty($dolibarr_main_document_root)) {
  287. if (!file_exists($dolibarr_main_document_root."/core/lib/admin.lib.php")) {
  288. 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";
  289. 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);
  290. } else {
  291. require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
  292. // If password is encoded, we decode it
  293. if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
  294. require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
  295. if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
  296. $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
  297. $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
  298. } else {
  299. $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
  300. }
  301. }
  302. // $conf already created in inc.php
  303. $conf->db->type = $dolibarr_main_db_type;
  304. $conf->db->host = $dolibarr_main_db_host;
  305. $conf->db->port = $dolibarr_main_db_port;
  306. $conf->db->name = $dolibarr_main_db_name;
  307. $conf->db->user = $dolibarr_main_db_user;
  308. $conf->db->pass = $dolibarr_main_db_pass;
  309. $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
  310. if ($db->connected && $db->database_selected) {
  311. $ok = true;
  312. }
  313. }
  314. }
  315. }
  316. // If database access is available, we set more variables
  317. if ($ok) {
  318. if (empty($dolibarr_main_db_encryption)) {
  319. $dolibarr_main_db_encryption = 0;
  320. }
  321. $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
  322. if (empty($dolibarr_main_db_cryptkey)) {
  323. $dolibarr_main_db_cryptkey = '';
  324. }
  325. $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
  326. $conf->setValues($db);
  327. // Reset forced setup after the setValues
  328. if (defined('SYSLOG_FILE')) {
  329. $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
  330. }
  331. $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
  332. // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
  333. // Version to install is DOL_VERSION
  334. $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 : ''));
  335. $dolibarrversiontoinstallarray = versiondolibarrarray();
  336. }
  337. // Show title
  338. if (!empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || !empty($conf->global->MAIN_VERSION_LAST_INSTALL)) {
  339. 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> - ';
  340. print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b>';
  341. //print ' '.img_warning($langs->trans("RunningUpdateProcessMayBeRequired"));
  342. print '<br>';
  343. print '<br>';
  344. } else {
  345. print "<br>\n";
  346. }
  347. //print $langs->trans("InstallEasy")." ";
  348. print '<h3><span class="soustitre">'.$langs->trans("ChooseYourSetupMode").'</span></h3>';
  349. $foundrecommandedchoice = 0;
  350. $available_choices = array();
  351. $notavailable_choices = array();
  352. if (empty($dolibarr_main_db_host)) { // This means install process was not run
  353. $foundrecommandedchoice = 1; // To show only once
  354. }
  355. // Show line of first install choice
  356. $choice = '<tr class="trlineforchoice'.($foundrecommandedchoice ? ' choiceselected' : '').'">'."\n";
  357. $choice .= '<td class="nowrap center"><b>'.$langs->trans("FreshInstall").'</b>';
  358. $choice .= '</td>';
  359. $choice .= '<td class="listofchoicesdesc">';
  360. $choice .= $langs->trans("FreshInstallDesc");
  361. if (empty($dolibarr_main_db_host)) { // This means install process was not run
  362. $choice .= '<br>';
  363. //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
  364. $choice .= '<div class="center"><div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div></div>';
  365. // <img src="../theme/eldy/img/tick.png" alt="Ok" class="valignmiddle"> ';
  366. }
  367. $choice .= '</td>';
  368. $choice .= '<td class="center">';
  369. if ($allowinstall) {
  370. $choice .= '<a class="button" href="fileconf.php?selectlang='.$setuplang.'">'.$langs->trans("Start").'</a>';
  371. } else {
  372. $choice .= ($foundrecommandedchoice ? '<span class="warning">' : '').$langs->trans("InstallNotAllowed").($foundrecommandedchoice ? '</span>' : '');
  373. }
  374. $choice .= '</td>'."\n";
  375. $choice .= '</tr>'."\n";
  376. $positionkey = ($foundrecommandedchoice ? 999 : 0);
  377. if ($allowinstall) {
  378. $available_choices[$positionkey] = $choice;
  379. } else {
  380. $notavailable_choices[$positionkey] = $choice;
  381. }
  382. // Show upgrade lines
  383. $allowupgrade = true;
  384. if (empty($dolibarr_main_db_host)) { // This means install process was not run
  385. $allowupgrade = false;
  386. }
  387. if (getDolGlobalInt("MAIN_NOT_INSTALLED")) {
  388. $allowupgrade = false;
  389. }
  390. if (GETPOST('allowupgrade')) {
  391. $allowupgrade = true;
  392. }
  393. $dir = DOL_DOCUMENT_ROOT."/install/mysql/migration/"; // We use mysql migration scripts whatever is database driver
  394. dolibarr_install_syslog("Scan sql files for migration files in ".$dir);
  395. // Get files list of migration file x.y.z-a.b.c.sql into /install/mysql/migration
  396. $migrationscript = array();
  397. $handle = opendir($dir);
  398. if (is_resource($handle)) {
  399. $versiontousetoqualifyscript = preg_replace('/-.*/', '', DOL_VERSION);
  400. while (($file = readdir($handle)) !== false) {
  401. $reg = array();
  402. if (preg_match('/^(\d+\.\d+\.\d+)-(\d+\.\d+\.\d+)\.sql$/i', $file, $reg)) {
  403. //var_dump(DOL_VERSION." ".$reg[2]." ".$versiontousetoqualifyscript." ".version_compare($versiontousetoqualifyscript, $reg[2]));
  404. if (!empty($reg[2]) && version_compare($versiontousetoqualifyscript, $reg[2]) >= 0) {
  405. $migrationscript[] = array('from' => $reg[1], 'to' => $reg[2]);
  406. }
  407. }
  408. }
  409. $migrationscript = dol_sort_array($migrationscript, 'from', 'asc', 1);
  410. } else {
  411. print '<div class="error">'.$langs->trans("ErrorCanNotReadDir", $dir).'</div>';
  412. }
  413. $count = 0;
  414. foreach ($migrationscript as $migarray) {
  415. $choice = '';
  416. $count++;
  417. $recommended_choice = false;
  418. $version = DOL_VERSION;
  419. $versionfrom = $migarray['from'];
  420. $versionto = $migarray['to'];
  421. $versionarray = preg_split('/[\.-]/', $version);
  422. $dolibarrversionfromarray = preg_split('/[\.-]/', $versionfrom);
  423. $dolibarrversiontoarray = preg_split('/[\.-]/', $versionto);
  424. // Define string newversionxxx that are used for text to show
  425. $newversionfrom = preg_replace('/(\.[0-9]+)$/i', '.*', $versionfrom);
  426. $newversionto = preg_replace('/(\.[0-9]+)$/i', '.*', $versionto);
  427. $newversionfrombis = '';
  428. if (versioncompare($dolibarrversiontoarray, $versionarray) < -2) { // From x.y.z -> x.y.z+1
  429. $newversionfrombis = ' '.$langs->trans("or").' '.$versionto;
  430. }
  431. if ($ok) {
  432. if (count($dolibarrlastupgradeversionarray) >= 2) { // If database access is available and last upgrade version is known
  433. // Now we check if this is the first qualified choice
  434. if ($allowupgrade && empty($foundrecommandedchoice) &&
  435. (versioncompare($dolibarrversiontoarray, $dolibarrlastupgradeversionarray) > 0 || versioncompare($dolibarrversiontoarray, $versionarray) < -2)
  436. ) {
  437. $foundrecommandedchoice = 1; // To show only once
  438. $recommended_choice = true;
  439. }
  440. } else {
  441. // We cannot recommend a choice.
  442. // A version of install may be known, but we need last upgrade.
  443. }
  444. }
  445. $choice .= "\n".'<!-- choice '.$count.' -->'."\n";
  446. $choice .= '<tr'.($recommended_choice ? ' class="choiceselected"' : '').'>';
  447. $choice .= '<td class="nowrap center"><b>'.$langs->trans("Upgrade").'<br>'.$newversionfrom.$newversionfrombis.' -> '.$newversionto.'</b></td>';
  448. $choice .= '<td class="listofchoicesdesc">';
  449. $choice .= $langs->trans("UpgradeDesc");
  450. if ($recommended_choice) {
  451. $choice .= '<br>';
  452. //print $langs->trans("InstallChoiceRecommanded",DOL_VERSION,$conf->global->MAIN_VERSION_LAST_UPGRADE);
  453. $choice .= '<div class="center">';
  454. $choice .= '<div class="ok suggestedchoice">'.$langs->trans("InstallChoiceSuggested").'</div>';
  455. if ($count < count($migarray)) { // There are other choices after
  456. print $langs->trans("MigrateIsDoneStepByStep", DOL_VERSION);
  457. }
  458. $choice .= '</div>';
  459. }
  460. $choice .= '</td>';
  461. $choice .= '<td class="center">';
  462. if ($allowupgrade) {
  463. $disabled = false;
  464. if ($foundrecommandedchoice == 2) {
  465. $disabled = true;
  466. }
  467. if ($foundrecommandedchoice == 1) {
  468. $foundrecommandedchoice = 2;
  469. }
  470. if ($disabled) {
  471. $choice .= '<span class="opacitymedium">'.$langs->trans("NotYetAvailable").'</span>';
  472. } else {
  473. $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>';
  474. }
  475. } else {
  476. $choice .= $langs->trans("NotAvailable");
  477. }
  478. $choice .= '</td>';
  479. $choice .= '</tr>'."\n";
  480. if ($allowupgrade) {
  481. $available_choices[$count] = $choice;
  482. } else {
  483. $notavailable_choices[$count] = $choice;
  484. }
  485. }
  486. // If there is no choice at all, we show all of them.
  487. if (empty($available_choices)) {
  488. $available_choices = $notavailable_choices;
  489. $notavailable_choices = array();
  490. }
  491. // Array of install choices
  492. krsort($available_choices, SORT_NATURAL);
  493. print"\n";
  494. print '<table width="100%" class="listofchoices">';
  495. foreach ($available_choices as $choice) {
  496. print $choice;
  497. }
  498. print '</table>'."\n";
  499. if (count($notavailable_choices)) {
  500. print '<br><div id="AShowChoices" style="opacity: 0.5">';
  501. print '> '.$langs->trans('ShowNotAvailableOptions').'...';
  502. print '</div>';
  503. print '<div id="navail_choices" style="display:none">';
  504. print "<br>\n";
  505. print '<table width="100%" class="listofchoices">';
  506. foreach ($notavailable_choices as $choice) {
  507. print $choice;
  508. }
  509. print '</table>'."\n";
  510. print '</div>';
  511. }
  512. }
  513. }
  514. print '<script type="text/javascript">
  515. $("div#AShowChoices").click(function() {
  516. $("div#navail_choices").toggle();
  517. if ($("div#navail_choices").css("display") == "none") {
  518. $(this).text("> '.$langs->trans('ShowNotAvailableOptions').'...");
  519. } else {
  520. $(this).text("'.$langs->trans('HideNotAvailableOptions').'...");
  521. }
  522. });
  523. /*
  524. $(".runupgrade").click(function() {
  525. return confirm("'.dol_escape_js($langs->transnoentitiesnoconv("WarningUpgrade"), 0, 1).'");
  526. });
  527. */
  528. </script>';
  529. dolibarr_install_syslog("- check: end");
  530. pFooter(1); // Never display next button