install.lib.php 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Chamilo LMS
  5. * This file contains functions used by the install and upgrade scripts.
  6. *
  7. * Ideas for future additions:
  8. * - a function get_old_version_settings to retrieve the config file settings
  9. * of older versions before upgrading.
  10. */
  11. /* CONSTANTS */
  12. define('SYSTEM_MAIN_DATABASE_FILE', $new_version.'/db_main.sql');
  13. define('COUNTRY_DATA_FILENAME', 'country_data.csv');
  14. define('COURSES_HTACCESS_FILENAME', 'htaccess.dist');
  15. define('SYSTEM_CONFIG_FILENAME', 'configuration.dist.php');
  16. /* COMMON PURPOSE FUNCTIONS */
  17. /**
  18. * This function detects whether the system has been already installed.
  19. * It should be used for prevention from second running the installation
  20. * script and as a result - destroying a production system.
  21. * @return bool The detected result;
  22. * @author Ivan Tcholakov, 2010;
  23. */
  24. function is_already_installed_system()
  25. {
  26. global $new_version, $_configuration;
  27. if (empty($new_version)) {
  28. return true; // Must be initialized.
  29. }
  30. if (empty($_configuration)) {
  31. return false;
  32. }
  33. $current_version = null;
  34. if (isset($_configuration['dokeos_version'])) {
  35. $current_version = trim($_configuration['dokeos_version']);
  36. }
  37. if (empty($current_version)) {
  38. $current_version = trim($_configuration['system_version']);
  39. }
  40. // If the current version is old, upgrading is assumed, the installer goes ahead.
  41. return empty($current_version) ? false : version_compare($current_version, $new_version, '>=');
  42. }
  43. /**
  44. * This function checks if a php extension exists or not and returns an HTML status string.
  45. *
  46. * @param string Name of the PHP extension to be checked
  47. * @param string Text to show when extension is available (defaults to 'Yes')
  48. * @param string Text to show when extension is available (defaults to 'No')
  49. * @param boolean Whether this extension is optional (in this case show unavailable text in orange rather than red)
  50. * @return string HTML string reporting the status of this extension. Language-aware.
  51. * @author Christophe Gesch??
  52. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  53. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  54. * @version Dokeos 1.8.1, May 2007
  55. */
  56. function check_extension($extension_name, $return_success = 'Yes', $return_failure = 'No', $optional = false)
  57. {
  58. if (extension_loaded($extension_name)) {
  59. return Display::label($return_success, 'success');
  60. } else {
  61. if ($optional) {
  62. return Display::label($return_failure, 'warning');
  63. //return '<strong><font color="#ff9900">'.$return_failure.'</font></strong>';
  64. } else {
  65. return Display::label($return_failure, 'important');
  66. //return '<strong><font color="red">'.$return_failure.'</font></strong>';
  67. }
  68. }
  69. }
  70. /**
  71. * This function checks whether a php setting matches the recommended value
  72. *
  73. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  74. * @version Dokeos 1.8, august 2006
  75. */
  76. function check_php_setting($php_setting, $recommended_value, $return_success = false, $return_failure = false)
  77. {
  78. $current_php_value = get_php_setting($php_setting);
  79. if ($current_php_value == $recommended_value) {
  80. return Display::label($current_php_value.' '.$return_success, 'success');
  81. } else {
  82. return Display::label($current_php_value.' '.$return_success, 'important');
  83. }
  84. }
  85. /**
  86. * Returns a textual value ('ON' or 'OFF') based on a requester 2-state ini- configuration setting.
  87. *
  88. * @param string $val a php ini value
  89. * @return boolean: ON or OFF
  90. * @author Joomla <http://www.joomla.org>
  91. */
  92. function get_php_setting($val)
  93. {
  94. return ini_get($val) == '1' ? 'ON' : 'OFF';
  95. }
  96. /**
  97. * This function returns a string "true" or "false" according to the passed parameter.
  98. *
  99. * @param integer $var The variable to present as text
  100. * @return string the string "true" or "false"
  101. * @author Christophe Gesch??
  102. */
  103. function true_false($var)
  104. {
  105. return $var ? 'true' : 'false';
  106. }
  107. /**
  108. * Removes memory and time limits as much as possible.
  109. */
  110. function remove_memory_and_time_limits()
  111. {
  112. if (function_exists('ini_set')) {
  113. ini_set('memory_limit', -1);
  114. ini_set('max_execution_time', 0);
  115. } else {
  116. error_log('Update-db script: could not change memory and time limits', 0);
  117. }
  118. }
  119. /**
  120. * Detects browser's language.
  121. * @return string Returns a language identificator, i.e. 'english', 'spanish', ...
  122. * @author Ivan Tcholakov, 2010
  123. */
  124. function detect_browser_language()
  125. {
  126. static $language_index = array(
  127. 'ar' => 'arabic',
  128. 'ast' => 'asturian',
  129. 'bg' => 'bulgarian',
  130. 'bs' => 'bosnian',
  131. 'ca' => 'catalan',
  132. 'zh' => 'simpl_chinese',
  133. 'zh-tw' => 'trad_chinese',
  134. 'cs' => 'czech',
  135. 'da' => 'danish',
  136. 'prs' => 'dari',
  137. 'de' => 'german',
  138. 'el' => 'greek',
  139. 'en' => 'english',
  140. 'es' => 'spanish',
  141. 'eo' => 'esperanto',
  142. 'eu' => 'basque',
  143. 'fa' => 'persian',
  144. 'fr' => 'french',
  145. 'fur' => 'friulian',
  146. 'gl' => 'galician',
  147. 'ka' => 'georgian',
  148. 'hr' => 'croatian',
  149. 'he' => 'hebrew',
  150. 'hi' => 'hindi',
  151. 'id' => 'indonesian',
  152. 'it' => 'italian',
  153. 'ko' => 'korean',
  154. 'lv' => 'latvian',
  155. 'lt' => 'lithuanian',
  156. 'mk' => 'macedonian',
  157. 'hu' => 'hungarian',
  158. 'ms' => 'malay',
  159. 'nl' => 'dutch',
  160. 'ja' => 'japanese',
  161. 'no' => 'norwegian',
  162. 'oc' => 'occitan',
  163. 'ps' => 'pashto',
  164. 'pl' => 'polish',
  165. 'pt' => 'portuguese',
  166. 'pt-br' => 'brazilian',
  167. 'ro' => 'romanian',
  168. 'qu' => 'quechua_cusco',
  169. 'ru' => 'russian',
  170. 'sk' => 'slovak',
  171. 'sl' => 'slovenian',
  172. 'sr' => 'serbian',
  173. 'fi' => 'finnish',
  174. 'sv' => 'swedish',
  175. 'th' => 'thai',
  176. 'tr' => 'turkish',
  177. 'uk' => 'ukrainian',
  178. 'vi' => 'vietnamese',
  179. 'sw' => 'swahili',
  180. 'yo' => 'yoruba'
  181. );
  182. $system_available_languages = & get_language_folder_list();
  183. $accept_languages = strtolower(str_replace('_', '-', $_SERVER['HTTP_ACCEPT_LANGUAGE']));
  184. foreach ($language_index as $code => $language) {
  185. if (strpos($accept_languages, $code) === 0) {
  186. if (!empty($system_available_languages[$language])) {
  187. return $language;
  188. }
  189. }
  190. }
  191. $user_agent = strtolower(str_replace('_', '-', $_SERVER['HTTP_USER_AGENT']));
  192. foreach ($language_index as $code => $language) {
  193. if (@preg_match("/[\[\( ]{$code}[;,_\-\)]/", $user_agent)) {
  194. if (!empty($system_available_languages[$language])) {
  195. return $language;
  196. }
  197. }
  198. }
  199. return 'english';
  200. }
  201. /* FILESYSTEM RELATED FUNCTIONS */
  202. /**
  203. * This function checks if the given folder is writable
  204. */
  205. function check_writable($folder, $suggestion = false)
  206. {
  207. if (is_writable(api_get_path(SYS_CODE_PATH).$folder)) {
  208. return Display::label(get_lang('Writable'), 'success');
  209. } else {
  210. if ($suggestion) {
  211. return Display::label(get_lang('NotWritable'), 'info');
  212. } else {
  213. return Display::label(get_lang('NotWritable'), 'important');
  214. }
  215. }
  216. }
  217. /**
  218. * This function checks if the given folder is writable
  219. */
  220. function check_writable_root_path($folder, $suggestion = false)
  221. {
  222. if (is_writable(api_get_path(SYS_PATH).$folder)) {
  223. return Display::label(get_lang('Writable'), 'success');
  224. } else {
  225. if ($suggestion) {
  226. return Display::label(get_lang('NotWritable'), 'info');
  227. } else {
  228. return Display::label(get_lang('NotWritable'), 'important');
  229. }
  230. }
  231. }
  232. /**
  233. * This function is similar to the core file() function, except that it
  234. * works with line endings in Windows (which is not the case of file())
  235. * @param string File path
  236. * @return array The lines of the file returned as an array
  237. */
  238. function file_to_array($filename)
  239. {
  240. if (!is_readable($filename) || is_dir($filename)) {
  241. return array();
  242. }
  243. $fp = fopen($filename, 'rb');
  244. $buffer = fread($fp, filesize($filename));
  245. fclose($fp);
  246. return explode('<br />', nl2br($buffer));
  247. }
  248. /**
  249. * We assume this function is called from install scripts that reside inside the install folder.
  250. */
  251. function set_file_folder_permissions()
  252. {
  253. @chmod('.', 0755); //set permissions on install dir
  254. @chmod('..', 0755); //set permissions on parent dir of install dir
  255. @chmod('country_data.csv.csv', 0755);
  256. }
  257. /**
  258. * Add's a .htaccess file to the courses directory
  259. * @param string $url_append The path from your webroot to your chamilo root
  260. */
  261. function write_courses_htaccess_file($url_append)
  262. {
  263. $content = file_get_contents(dirname(__FILE__).'/'.COURSES_HTACCESS_FILENAME);
  264. $content = str_replace('{CHAMILO_URL_APPEND_PATH}', $url_append, $content);
  265. $fp = @ fopen(api_get_path(SYS_PATH).'courses/.htaccess', 'w');
  266. if ($fp) {
  267. fwrite($fp, $content);
  268. return fclose($fp);
  269. }
  270. return false;
  271. }
  272. /**
  273. * Write the main system config file
  274. * @param string $path Path to the config file
  275. */
  276. function write_system_config_file($path)
  277. {
  278. global $dbHostForm;
  279. global $dbUsernameForm;
  280. global $dbPassForm;
  281. global $enableTrackingForm;
  282. global $singleDbForm;
  283. global $dbPrefixForm;
  284. global $dbNameForm;
  285. global $dbStatsForm;
  286. global $dbScormForm;
  287. global $dbUserForm;
  288. global $urlForm;
  289. global $pathForm;
  290. global $urlAppendPath;
  291. global $languageForm;
  292. global $encryptPassForm;
  293. global $installType;
  294. global $updatePath;
  295. global $session_lifetime;
  296. global $new_version;
  297. global $new_version_stable;
  298. $root_sys = api_add_trailing_slash(str_replace('\\', '/', realpath($pathForm)));
  299. $content = file_get_contents(dirname(__FILE__).'/'.SYSTEM_CONFIG_FILENAME);
  300. $config['{DATE_GENERATED}'] = date('r');
  301. $config['{DATABASE_HOST}'] = $dbHostForm;
  302. $config['{DATABASE_USER}'] = $dbUsernameForm;
  303. $config['{DATABASE_PASSWORD}'] = $dbPassForm;
  304. $config['TRACKING_ENABLED'] = true_false($enableTrackingForm);
  305. $config['SINGLE_DATABASE'] = true_false($singleDbForm);
  306. $config['{COURSE_TABLE_PREFIX}'] = ($singleDbForm ? 'crs_' : '');
  307. $config['{DATABASE_GLUE}'] = ($singleDbForm ? '_' : '`.`');
  308. $config['{DATABASE_PREFIX}'] = '';
  309. $config['{DATABASE_MAIN}'] = $dbNameForm;
  310. $config['{DATABASE_STATS}'] = $dbNameForm;
  311. $config['{DATABASE_SCORM}'] = $dbNameForm;
  312. $config['{DATABASE_PERSONAL}'] = $dbNameForm;
  313. $config['{ROOT_WEB}'] = $urlForm;
  314. $config['{ROOT_SYS}'] = $root_sys;
  315. $config['{URL_APPEND_PATH}'] = $urlAppendPath;
  316. $config['{PLATFORM_LANGUAGE}'] = $languageForm;
  317. $config['{SECURITY_KEY}'] = md5(uniqid(rand().time()));
  318. $config['{ENCRYPT_PASSWORD}'] = $encryptPassForm;
  319. $config['SESSION_LIFETIME'] = $session_lifetime;
  320. $config['{NEW_VERSION}'] = $new_version;
  321. $config['NEW_VERSION_STABLE'] = true_false($new_version_stable);
  322. foreach ($config as $key => $value) {
  323. $content = str_replace($key, $value, $content);
  324. }
  325. $fp = @ fopen($path, 'w');
  326. if (!$fp) {
  327. echo '<strong>
  328. <font color="red">Your script doesn\'t have write access to the config directory</font></strong>
  329. <br />
  330. <em>('.str_replace('\\', '/', realpath($path)).')</em><br /><br />
  331. You probably do not have write access on Chamilo root directory,
  332. i.e. you should <em>CHMOD 777</em> or <em>755</em> or <em>775</em>.<br /><br />
  333. Your problems can be related on two possible causes:<br />
  334. <ul>
  335. <li>Permission problems.<br />Try initially with <em>chmod -R 777</em> and increase restrictions gradually.</li>
  336. <li>PHP is running in <a href="http://www.php.net/manual/en/features.safe-mode.php" target="_blank">Safe-Mode</a>. If possible, try to switch it off.</li>
  337. </ul>
  338. <a href="http://forum.chamilo.org/" target="_blank">Read about this problem in Support Forum</a><br /><br />
  339. Please go back to step 5.
  340. <p><input type="submit" name="step5" value="&lt; Back" /></p>
  341. </td></tr></table></form></body></html>';
  342. exit;
  343. }
  344. fwrite($fp, $content);
  345. fclose($fp);
  346. }
  347. /**
  348. * Returns a list of language directories.
  349. */
  350. function & get_language_folder_list()
  351. {
  352. static $result;
  353. if (!is_array($result)) {
  354. $result = array();
  355. $exceptions = array('.', '..', 'CVS', '.svn');
  356. $search = array('_latin', '_unicode', '_corporate', '_org', '_KM', '_');
  357. $replace_with = array(' (Latin)', ' (unicode)', ' (corporate)', ' (org)', ' (KM)', ' ');
  358. $dirname = api_get_path(SYS_LANG_PATH);
  359. $handle = opendir($dirname);
  360. while ($entries = readdir($handle)) {
  361. if (in_array($entries, $exceptions)) {
  362. continue;
  363. }
  364. if (is_dir($dirname.$entries)) {
  365. $result[$entries] = ucwords(str_replace($search, $replace_with, $entries));
  366. }
  367. }
  368. closedir($handle);
  369. asort($result);
  370. }
  371. return $result;
  372. }
  373. /**
  374. * TODO: my_directory_to_array() - maybe within the main API there is already a suitable function?
  375. */
  376. function my_directory_to_array($directory)
  377. {
  378. $array_items = array();
  379. if ($handle = opendir($directory)) {
  380. while (false !== ($file = readdir($handle))) {
  381. if ($file != "." && $file != "..") {
  382. if (is_dir($directory."/".$file)) {
  383. $array_items = array_merge($array_items, my_directory_to_array($directory.'/'.$file));
  384. $file = $directory."/".$file;
  385. $array_items[] = preg_replace("/\/\//si", '/', $file);
  386. }
  387. }
  388. }
  389. closedir($handle);
  390. }
  391. return $array_items;
  392. }
  393. /**
  394. * This function returns the value of a parameter from the configuration file
  395. *
  396. * WARNING - this function relies heavily on global variables $updateFromConfigFile
  397. * and $configFile, and also changes these globals. This can be rewritten.
  398. *
  399. * @param string $param the parameter of which the value is returned
  400. * @param string If we want to give the path rather than take it from POST
  401. * @return string the value of the parameter
  402. * @author Olivier Brouckaert
  403. * @author Reworked by Ivan Tcholakov, 2010
  404. */
  405. function get_config_param($param, $updatePath = '')
  406. {
  407. global $configFile, $updateFromConfigFile, $_configuration;
  408. if (isset($_configuration[$param])) {
  409. return $_configuration[$param];
  410. } else {
  411. return null;
  412. }
  413. }
  414. /* DATABASE RELATED FUNCTIONS */
  415. /**
  416. * Gets a configuration parameter from the database. Returns returns null on failure.
  417. * @param string DB Host
  418. * @param string DB login
  419. * @param string DB pass
  420. * @param string DB name
  421. * @param string Name of param we want
  422. * @return mixed The parameter value or null if not found
  423. */
  424. function get_config_param_from_db($host, $login, $pass, $db_name, $param = '')
  425. {
  426. Database::connect(array('server' => $host, 'username' => $login, 'password' => $pass));
  427. Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
  428. Database::select_db($db_name);
  429. if (($res = Database::query("SELECT * FROM settings_current WHERE variable = '$param'")) !== false) {
  430. if (Database::num_rows($res) > 0) {
  431. $row = Database::fetch_array($res);
  432. return $row['selected_value'];
  433. }
  434. }
  435. return null;
  436. }
  437. /**
  438. * Connects to the database server.
  439. */
  440. function database_server_connect()
  441. {
  442. global $dbHostForm, $dbUsernameForm, $dbPassForm;
  443. if (($res = @Database::connect(
  444. array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm)
  445. )) === false
  446. ) {
  447. $no = Database::errno();
  448. $msg = Database::error();
  449. echo '<hr />#'.$no.': '.$msg.'<hr />';
  450. echo get_lang('DBServerDoesntWorkOrLoginPassIsWrong').'.<br /><br />'.
  451. get_lang('PleaseCheckTheseValues').' :<br /><br />'.
  452. '<strong>'.get_lang('DBHost').'</strong> : '.$dbHostForm.'<br />'.
  453. '<strong>'.get_lang('DBLogin').'</strong> : '.$dbUsernameForm.'<br />'.
  454. '<strong>'.get_lang('DBPassword').'</strong> : '.$dbPassForm.'<br /><br />'.
  455. get_lang('PleaseGoBackToStep').' '.(defined('SYSTEM_INSTALLATION') ? '3' : '1').'.'.
  456. '<p><button type="submit" class="back" name="step'.(defined(
  457. 'SYSTEM_INSTALLATION'
  458. ) ? '3' : '1').'" value="&lt; '.get_lang('Back').'">'.get_lang('Back').'</button></p>'.
  459. '</td></tr></table></form></body></html>';
  460. exit ();
  461. }
  462. @Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
  463. }
  464. /**
  465. * Database exists for the MYSQL user
  466. * @param type $database_name
  467. * @return boolean
  468. */
  469. function database_exists($database_name)
  470. {
  471. if (empty($database_name)) {
  472. return false;
  473. }
  474. $select_database = @Database::select_db($database_name);
  475. $show_database = false;
  476. $sql = "SHOW DATABASES LIKE '".addslashes($database_name)."'";
  477. $result = @Database::query($sql);
  478. if (Database::num_rows($result)) {
  479. $show_database = true;
  480. }
  481. return $select_database || $show_database;
  482. }
  483. /**
  484. * In step 3. Tests establishing connection to the database server.
  485. * If it's a single database environment the function checks if the database exist.
  486. * If the database doesn't exist we check the creation permissions.
  487. *
  488. * @return int 1 when there is no problem;
  489. * 0 when a new database is impossible to be created, then the single/multiple database configuration is impossible too
  490. * -1 when there is no connection established.
  491. */
  492. function test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm, $dbNameForm)
  493. {
  494. $dbConnect = -1;
  495. //Checking user credentials
  496. if (@Database::connect(
  497. array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm)
  498. ) !== false
  499. ) {
  500. $dbConnect = 1;
  501. } else {
  502. $dbConnect = -1;
  503. }
  504. return $dbConnect; //return 1, if no problems, "0" if, in case we can't create a new DB and "-1" if there is no connection.
  505. }
  506. /**
  507. * Fills the countries table with a list of countries.
  508. */
  509. function fill_track_countries_table($track_countries_table)
  510. {
  511. $file_path = dirname(__FILE__).'/'.COUNTRY_DATA_FILENAME;
  512. $countries = file($file_path);
  513. $add_country_sql = "INSERT INTO $track_countries_table (id, code, country, counter) VALUES ";
  514. foreach ($countries as $line) {
  515. $elems = explode(',', $line);
  516. $add_country_sql .= '('.intval($elems[0]).',\''.Database::escape_string(
  517. $elems[1]
  518. ).'\',\''.Database::escape_string($elems[2]).'\','.intval($elems[3]).'),';
  519. }
  520. $add_country_sql = substr($add_country_sql, 0, -1);
  521. //$add_country_sql = "LOAD DATA INFILE '".Database::escape_string($file_path)."' INTO TABLE $track_countries_table FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\'';";
  522. @ Database::query($add_country_sql);
  523. }
  524. /**
  525. * Creates the structure of the main database and fills it
  526. * with data. Placeholder symbols in the main database file
  527. * have to be replaced by the settings entered by the user during installation.
  528. *
  529. * @param array $installation_settings list of settings entered by the user
  530. * @param string optional path about the script for database
  531. * @return void
  532. */
  533. function load_main_database($installation_settings, $db_script = '')
  534. {
  535. $sql_text = null;
  536. if (!empty($db_script)) {
  537. if (file_exists($db_script)) {
  538. $sql_text = file_get_contents($db_script);
  539. }
  540. } else {
  541. $db_script = api_get_path(SYS_CODE_PATH).'install/'.SYSTEM_MAIN_DATABASE_FILE;
  542. if (file_exists($db_script)) {
  543. $sql_text = file_get_contents($db_script);
  544. }
  545. }
  546. //replace symbolic parameters with user-specified values
  547. foreach ($installation_settings as $key => $value) {
  548. $sql_text = str_replace($key, Database::escape_string($value), $sql_text);
  549. }
  550. parse_sql_queries($sql_text);
  551. }
  552. /**
  553. * Creates the structure of the stats database
  554. * @param string Name of the file containing the SQL script inside the install directory
  555. */
  556. function load_database_script($db_script)
  557. {
  558. $db_script = api_get_path(SYS_CODE_PATH).'install/'.$db_script;
  559. if (file_exists($db_script)) {
  560. $sql_text = file_get_contents($db_script);
  561. }
  562. parse_sql_queries($sql_text);
  563. }
  564. function parse_sql_queries($sql_text)
  565. {
  566. //split in array of sql strings
  567. $sql_instructions = array();
  568. split_sql_file($sql_instructions, $sql_text);
  569. //execute the sql instructions
  570. $count = count($sql_instructions);
  571. for ($i = 0; $i < $count; $i++) {
  572. $this_sql_query = $sql_instructions[$i]['query'];
  573. //UTF8 fix see #5678
  574. if (strpos(strtolower($this_sql_query), 'create table') === false) {
  575. iDatabase::query($this_sql_query);
  576. } else {
  577. //$this_sql_query .= substr($this_sql_query, strlen($this_sql_query), strlen($this_sql_query)-1);
  578. $this_sql_query .= ' DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci ';
  579. iDatabase::query($this_sql_query);
  580. }
  581. }
  582. }
  583. /**
  584. * Function copied and adapted from phpMyAdmin 2.6.0 PMA_splitSqlFile (also GNU GPL)
  585. * Removes comment lines and splits up large sql files into individual queries
  586. * Last revision: September 23, 2001 - gandon
  587. * @param array the splitted sql commands
  588. * @param string the sql commands
  589. * @param integer the MySQL release number (because certains php3 versions
  590. * can't get the value of a constant from within a function)
  591. * @return boolean always true
  592. */
  593. function split_sql_file(&$ret, $sql)
  594. {
  595. // do not trim, see bug #1030644
  596. //$sql = trim($sql);
  597. $sql = rtrim($sql, "\n\r");
  598. $sql_len = strlen($sql);
  599. $char = '';
  600. $string_start = '';
  601. $in_string = false;
  602. $nothing = true;
  603. $time0 = time();
  604. for ($i = 0; $i < $sql_len; ++$i) {
  605. $char = $sql[$i];
  606. // We are in a string, check for not escaped end of strings except for
  607. // backquotes that can't be escaped
  608. if ($in_string) {
  609. for (; ;) {
  610. $i = strpos($sql, $string_start, $i);
  611. // No end of string found -> add the current substring to the
  612. // returned array
  613. if (!$i) {
  614. $ret[] = $sql;
  615. return true;
  616. } // Backquotes or no backslashes before quotes: it's indeed the
  617. // end of the string -> exit the loop
  618. elseif ($string_start == '`' || $sql[$i - 1] != '\\') {
  619. $string_start = '';
  620. $in_string = false;
  621. break;
  622. } // one or more Backslashes before the presumed end of string...
  623. else {
  624. // ... first checks for escaped backslashes
  625. $j = 2;
  626. $escaped_backslash = false;
  627. while ($i - $j > 0 && $sql[$i - $j] == '\\') {
  628. $escaped_backslash = !$escaped_backslash;
  629. $j++;
  630. }
  631. // ... if escaped backslashes: it's really the end of the
  632. // string -> exit the loop
  633. if ($escaped_backslash) {
  634. $string_start = '';
  635. $in_string = false;
  636. break;
  637. } // ... else loop
  638. else {
  639. $i++;
  640. }
  641. } // end if...elseif...else
  642. } // end for
  643. } // end if (in string)
  644. // lets skip comments (/*, -- and #)
  645. elseif (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) {
  646. $i = strpos($sql, $char == '/' ? '*/' : "\n", $i);
  647. // didn't we hit end of string?
  648. if ($i === false) {
  649. break;
  650. }
  651. if ($char == '/') {
  652. $i++;
  653. }
  654. } // We are not in a string, first check for delimiter...
  655. elseif ($char == ';') {
  656. // if delimiter found, add the parsed part to the returned array
  657. $ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing);
  658. $nothing = true;
  659. $sql = ltrim(substr($sql, min($i + 1, $sql_len)));
  660. $sql_len = strlen($sql);
  661. if ($sql_len) {
  662. $i = -1;
  663. } else {
  664. // The submited statement(s) end(s) here
  665. return true;
  666. }
  667. } // end elseif (is delimiter)
  668. // ... then check for start of a string,...
  669. elseif (($char == '"') || ($char == '\'') || ($char == '`')) {
  670. $in_string = true;
  671. $nothing = false;
  672. $string_start = $char;
  673. } // end elseif (is start of string)
  674. elseif ($nothing) {
  675. $nothing = false;
  676. }
  677. // loic1: send a fake header each 30 sec. to bypass browser timeout
  678. $time1 = time();
  679. if ($time1 >= $time0 + 30) {
  680. $time0 = $time1;
  681. header('X-pmaPing: Pong');
  682. } // end if
  683. } // end for
  684. // add any rest to the returned array
  685. if (!empty($sql) && preg_match('@[^[:space:]]+@', $sql)) {
  686. $ret[] = array('query' => $sql, 'empty' => $nothing);
  687. }
  688. return true;
  689. } // end of the 'split_sql_file()' function
  690. /**
  691. * Get an SQL file's contents
  692. *
  693. * This function bases its parsing on the pre-set format of the specific SQL files in
  694. * the install/upgrade procedure:
  695. * Lines starting with "--" are comments (but need to be taken into account as they also hold sections names)
  696. * Other lines are considered to be one-line-per-query lines (this is checked quickly by this function)
  697. * @param string File to parse (in the current directory)
  698. * @param string Section to return
  699. * @param boolean Print (true) or hide (false) error texts when they occur
  700. */
  701. function get_sql_file_contents($file, $section, $print_errors = true)
  702. {
  703. //check given parameters
  704. if (empty($file)) {
  705. $error = "Missing name of file to parse in get_sql_file_contents()";
  706. if ($print_errors) {
  707. echo $error;
  708. }
  709. return false;
  710. }
  711. if (!in_array($section, array('main', 'user', 'stats', 'scorm', 'course'))) {
  712. $error = "Section '$section' is not authorized in get_sql_file_contents()";
  713. if ($print_errors) {
  714. echo $error;
  715. }
  716. return false;
  717. }
  718. $filepath = getcwd().'/'.$file;
  719. if (!is_file($filepath) or !is_readable($filepath)) {
  720. $error = "File $filepath not found or not readable in get_sql_file_contents()";
  721. if ($print_errors) {
  722. echo $error;
  723. }
  724. return false;
  725. }
  726. //read the file in an array
  727. // Empty lines should not be executed as SQL statements, because errors occur, see Task #2167.
  728. $file_contents = file($filepath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  729. if (!is_array($file_contents) or count($file_contents) < 1) {
  730. $error = "File $filepath looks empty in get_sql_file_contents()";
  731. if ($print_errors) {
  732. echo $error;
  733. }
  734. return false;
  735. }
  736. //prepare the resulting array
  737. $section_contents = array();
  738. $record = false;
  739. foreach ($file_contents as $index => $line) {
  740. if (substr($line, 0, 2) == '--') {
  741. //This is a comment. Check if section name, otherwise ignore
  742. $result = array();
  743. if (preg_match('/^-- xx([A-Z]*)xx/', $line, $result)) { //we got a section name here
  744. if ($result[1] == strtoupper($section)) {
  745. //we have the section we are looking for, start recording
  746. $record = true;
  747. } else {
  748. //we have another section's header. If we were recording, stop now and exit loop
  749. if ($record) {
  750. break;
  751. }
  752. $record = false;
  753. }
  754. }
  755. } else {
  756. if ($record) {
  757. if (!empty($line)) {
  758. $section_contents[] = $line;
  759. }
  760. }
  761. }
  762. }
  763. //now we have our section's SQL statements group ready, return
  764. return $section_contents;
  765. }
  766. /**
  767. * Adds a new document to the database - specific to version 1.8.0
  768. *
  769. * @param array $_course
  770. * @param string $path
  771. * @param string $filetype
  772. * @param int $filesize
  773. * @param string $title
  774. * @return id if inserted document
  775. */
  776. function add_document_180($_course, $path, $filetype, $filesize, $title, $comment = null)
  777. {
  778. $table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']);
  779. $sql = "INSERT INTO $table_document
  780. (`path`,`filetype`,`size`,`title`, `comment`)
  781. VALUES ('$path','$filetype','$filesize','".
  782. Database::escape_string($title)."', '$comment')";
  783. if (Database::query($sql)) {
  784. //display_message("Added to database (id ".Database::insert_id().")!");
  785. return Database::insert_id();
  786. } else {
  787. //display_error("The uploaded file could not be added to the database (".Database::error().")!");
  788. return false;
  789. }
  790. }
  791. /* DISPLAY FUNCTIONS */
  792. /**
  793. * This function prints class=active_step $current_step=$param
  794. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  795. */
  796. function step_active($param)
  797. {
  798. global $current_step;
  799. if ($param == $current_step) {
  800. echo 'class="current_step" ';
  801. }
  802. }
  803. /**
  804. * This function displays the Step X of Y -
  805. * @return string String that says 'Step X of Y' with the right values
  806. */
  807. function display_step_sequence()
  808. {
  809. global $current_step;
  810. return get_lang('Step'.$current_step).' &ndash; ';
  811. }
  812. /**
  813. * Displays a drop down box for selection the preferred language.
  814. */
  815. function display_language_selection_box($name = 'language_list', $default_language = 'english')
  816. {
  817. // Reading language list.
  818. $language_list = get_language_folder_list();
  819. // Sanity checks due to the possibility for customizations.
  820. if (!is_array($language_list) || empty($language_list)) {
  821. $language_list = array('english' => 'English');
  822. }
  823. // Sorting again, if it is necessary.
  824. //asort($language_list);
  825. // More sanity checks.
  826. if (!array_key_exists($default_language, $language_list)) {
  827. if (array_key_exists('english', $language_list)) {
  828. $default_language = 'english';
  829. } else {
  830. $language_keys = array_keys($language_list);
  831. $default_language = $language_keys[0];
  832. }
  833. }
  834. // Displaying the box.
  835. echo "\t\t<select name=\"$name\">\n";
  836. foreach ($language_list as $key => $value) {
  837. if ($key == $default_language) {
  838. $option_end = ' selected="selected">';
  839. } else {
  840. $option_end = '>';
  841. }
  842. echo "\t\t\t<option value=\"$key\"$option_end";
  843. echo $value;
  844. echo "</option>\n";
  845. }
  846. echo "\t\t</select>\n";
  847. }
  848. /**
  849. * This function displays a language dropdown box so that the installatioin
  850. * can be done in the language of the user
  851. */
  852. function display_language_selection()
  853. {
  854. ?>
  855. <h2><?php get_lang('WelcomeToTheDokeosInstaller'); ?></h2>
  856. <div class="RequirementHeading">
  857. <h2><?php echo display_step_sequence(); ?><?php echo get_lang('InstallationLanguage'); ?></h2>
  858. <p><?php echo get_lang('PleaseSelectInstallationProcessLanguage'); ?>:</p>
  859. <form id="lang_form" method="post" action="<?php echo api_get_self(); ?>">
  860. <?php display_language_selection_box('language_list', api_get_interface_language()); ?>
  861. <button type="submit" name="step1" class="btn next" autofocus="autofocus"
  862. value="<?php echo get_lang('Next'); ?>"><?php echo get_lang('Next'); ?></button>
  863. <input type="hidden" name="is_executable" id="is_executable" value="-"/>
  864. </form>
  865. </div>
  866. <?php
  867. }
  868. /**
  869. * This function displays the requirements for installing Chamilo.
  870. *
  871. * @param string $installType
  872. * @param boolean $badUpdatePath
  873. * @param string The updatePath given (if given)
  874. * @param array $update_from_version_8 The different subversions from version 1.8
  875. * @param array $update_from_version_6 The different subversions from version 1.6
  876. *
  877. * @author unknow
  878. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  879. */
  880. function display_requirements(
  881. $installType,
  882. $badUpdatePath,
  883. $updatePath = '',
  884. $update_from_version_8 = array(),
  885. $update_from_version_6 = array()
  886. ) {
  887. global $_setting;
  888. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('Requirements')."</h2></div>";
  889. echo '<div class="RequirementText">';
  890. echo '<strong>'.get_lang('ReadThoroughly').'</strong><br />';
  891. echo get_lang('MoreDetails').' <a href="../../documentation/installation_guide.html" target="_blank">'.get_lang(
  892. 'ReadTheInstallGuide'
  893. ).'</a>.<br />'."\n";
  894. if ($installType == 'update') {
  895. echo get_lang('IfYouPlanToUpgradeFromOlderVersionYouMightWantToHaveAlookAtTheChangelog').'<br />';
  896. }
  897. echo '</div>';
  898. // SERVER REQUIREMENTS
  899. echo '<div class="RequirementHeading"><h2>'.get_lang('ServerRequirements').'</h2>';
  900. echo '<div class="RequirementText">'.get_lang('ServerRequirementsInfo').'</div>';
  901. echo '<div class="RequirementContent">';
  902. echo '<table class="table">
  903. <tr>
  904. <td class="requirements-item">'.get_lang('PHPVersion').' >= '.REQUIRED_PHP_VERSION.'</td>
  905. <td class="requirements-value">';
  906. if (phpversion() < REQUIRED_PHP_VERSION) {
  907. echo '<strong><font color="red">'.get_lang('PHPVersionError').'</font></strong>';
  908. } else {
  909. echo '<strong><font color="green">'.get_lang('PHPVersionOK').' '.phpversion().'</font></strong>';
  910. }
  911. echo '</td>
  912. </tr>
  913. <tr>
  914. <td class="requirements-item"><a href="http://php.net/manual/en/book.session.php" target="_blank">Session</a> '.get_lang(
  915. 'support'
  916. ).'</td>
  917. <td class="requirements-value">'.check_extension(
  918. 'session',
  919. get_lang('Yes'),
  920. get_lang('ExtensionSessionsNotAvailable')
  921. ).'</td>
  922. </tr>
  923. <tr>
  924. <td class="requirements-item"><a href="http://php.net/manual/en/book.mysql.php" target="_blank">MySQL</a> '.get_lang(
  925. 'support'
  926. ).'</td>
  927. <td class="requirements-value">'.check_extension(
  928. 'mysql',
  929. get_lang('Yes'),
  930. get_lang('ExtensionMySQLNotAvailable')
  931. ).'</td>
  932. </tr>
  933. <tr>
  934. <td class="requirements-item"><a href="http://php.net/manual/en/book.zlib.php" target="_blank">Zlib</a> '.get_lang(
  935. 'support'
  936. ).'</td>
  937. <td class="requirements-value">'.check_extension(
  938. 'zlib',
  939. get_lang('Yes'),
  940. get_lang('ExtensionZlibNotAvailable')
  941. ).'</td>
  942. </tr>
  943. <tr>
  944. <td class="requirements-item"><a href="http://php.net/manual/en/book.pcre.php" target="_blank">Perl-compatible regular expressions</a> '.get_lang(
  945. 'support'
  946. ).'</td>
  947. <td class="requirements-value">'.check_extension(
  948. 'pcre',
  949. get_lang('Yes'),
  950. get_lang('ExtensionPCRENotAvailable')
  951. ).'</td>
  952. </tr>
  953. <tr>
  954. <td class="requirements-item"><a href="http://php.net/manual/en/book.xml.php" target="_blank">XML</a> '.get_lang(
  955. 'support'
  956. ).'</td>
  957. <td class="requirements-value">'.check_extension('xml', get_lang('Yes'), get_lang('No')).'</td>
  958. </tr>
  959. <tr>
  960. <td class="requirements-item"><a href="http://php.net/manual/en/book.mbstring.php" target="_blank">Multibyte string</a> '.get_lang(
  961. 'support'
  962. ).' ('.get_lang('Optional').')</td>
  963. <td class="requirements-value">'.check_extension(
  964. 'mbstring',
  965. get_lang('Yes'),
  966. get_lang('ExtensionMBStringNotAvailable'),
  967. true
  968. ).'</td>
  969. </tr>
  970. <tr>
  971. <td class="requirements-item"><a href="http://php.net/manual/en/book.iconv.php" target="_blank">Iconv</a> '.get_lang(
  972. 'support'
  973. ).' ('.get_lang('Optional').')</td>
  974. <td class="requirements-value">'.check_extension('iconv', get_lang('Yes'), get_lang('No'), true).'</td>
  975. </tr>
  976. <tr>
  977. <td class="requirements-item"><a href="http://php.net/manual/en/book.intl.php" target="_blank">Internationalization</a> '.get_lang(
  978. 'support'
  979. ).' ('.get_lang('Optional').')</td>
  980. <td class="requirements-value">'.check_extension('intl', get_lang('Yes'), get_lang('No'), true).'</td>
  981. </tr>
  982. <tr>
  983. <td class="requirements-item"><a href="http://php.net/manual/en/book.image.php" target="_blank">GD</a> '.get_lang(
  984. 'support'
  985. ).'</td>
  986. <td class="requirements-value">'.check_extension(
  987. 'gd',
  988. get_lang('Yes'),
  989. get_lang('ExtensionGDNotAvailable')
  990. ).'</td>
  991. </tr>
  992. <tr>
  993. <td class="requirements-item"><a href="http://php.net/manual/en/book.json.php" target="_blank">JSON</a> '.get_lang(
  994. 'support'
  995. ).'</td>
  996. <td class="requirements-value">'.check_extension('json', get_lang('Yes'), get_lang('No')).'</td>
  997. </tr>
  998. <tr>
  999. <td class="requirements-item"><a href="http://php.net/manual/en/book.ldap.php" target="_blank">LDAP</a> '.get_lang(
  1000. 'support'
  1001. ).' ('.get_lang('Optional').')</td>
  1002. <td class="requirements-value">'.check_extension(
  1003. 'ldap',
  1004. get_lang('Yes'),
  1005. get_lang('ExtensionLDAPNotAvailable'),
  1006. true
  1007. ).'</td>
  1008. </tr>
  1009. <tr>
  1010. <td class="requirements-item"><a href="http://xapian.org/" target="_blank">Xapian</a> '.get_lang(
  1011. 'support'
  1012. ).' ('.get_lang('Optional').')</td>
  1013. <td class="requirements-value">'.check_extension('xapian', get_lang('Yes'), get_lang('No'), true).'</td>
  1014. </tr>
  1015. <tr>
  1016. <td class="requirements-item"><a href="http://php.net/manual/en/book.curl.php" target="_blank">cURL</a> '.get_lang(
  1017. 'support'
  1018. ).' ('.get_lang('Optional').')</td>
  1019. <td class="requirements-value">'.check_extension('curl', get_lang('Yes'), get_lang('No'), true).'</td>
  1020. </tr>
  1021. </table>';
  1022. echo ' </div>';
  1023. echo '</div>';
  1024. // RECOMMENDED SETTINGS
  1025. // Note: these are the settings for Joomla, does this also apply for Chamilo?
  1026. // Note: also add upload_max_filesize here so that large uploads are possible
  1027. echo '<div class="RequirementHeading"><h2>'.get_lang('RecommendedSettings').'</h2>';
  1028. echo '<div class="RequirementText">'.get_lang('RecommendedSettingsInfo').'</div>';
  1029. echo '<div class="RequirementContent">';
  1030. echo '<table class="table">
  1031. <tr>
  1032. <th>'.get_lang('Setting').'</th>
  1033. <th>'.get_lang('Recommended').'</th>
  1034. <th>'.get_lang('Actual').'</th>
  1035. </tr>
  1036. <tr>
  1037. <td class="requirements-item"><a href="http://php.net/manual/features.safe-mode.php">Safe Mode</a></td>
  1038. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1039. <td class="requirements-value">'.check_php_setting('safe_mode', 'OFF').'</td>
  1040. </tr>
  1041. <tr>
  1042. <td class="requirements-item"><a href="http://php.net/manual/ref.errorfunc.php#ini.display-errors">Display Errors</a></td>
  1043. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1044. <td class="requirements-value">'.check_php_setting('display_errors', 'OFF').'</td>
  1045. </tr>
  1046. <tr>
  1047. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.file-uploads">File Uploads</a></td>
  1048. <td class="requirements-recommended">'.Display::label('ON', 'success').'</td>
  1049. <td class="requirements-value">'.check_php_setting('file_uploads', 'ON').'</td>
  1050. </tr>
  1051. <tr>
  1052. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-gpc">Magic Quotes GPC</a></td>
  1053. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1054. <td class="requirements-value">'.check_php_setting('magic_quotes_gpc', 'OFF').'</td>
  1055. </tr>
  1056. <tr>
  1057. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-runtime">Magic Quotes Runtime</a></td>
  1058. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1059. <td class="requirements-value">'.check_php_setting('magic_quotes_runtime', 'OFF').'</td>
  1060. </tr>
  1061. <tr>
  1062. <td class="requirements-item"><a href="http://php.net/manual/security.globals.php">Register Globals</a></td>
  1063. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1064. <td class="requirements-value">'.check_php_setting('register_globals', 'OFF').'</td>
  1065. </tr>
  1066. <tr>
  1067. <td class="requirements-item"><a href="http://php.net/manual/ref.session.php#ini.session.auto-start">Session auto start</a></td>
  1068. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1069. <td class="requirements-value">'.check_php_setting('session.auto_start', 'OFF').'</td>
  1070. </tr>
  1071. <tr>
  1072. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.short-open-tag">Short Open Tag</a></td>
  1073. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1074. <td class="requirements-value">'.check_php_setting('short_open_tag', 'OFF').'</td>
  1075. </tr>
  1076. <tr>
  1077. <td class="requirements-item"><a href="http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-httponly">Cookie HTTP Only</a></td>
  1078. <td class="requirements-recommended">'.Display::label('ON', 'success').'</td>
  1079. <td class="requirements-value">'.check_php_setting('session.cookie_httponly', 'ON').'</td>
  1080. </tr>
  1081. <tr>
  1082. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.upload-max-filesize">Maximum upload file size</a></td>
  1083. <td class="requirements-recommended">'.Display::label(
  1084. '>= '.REQUIRED_MIN_UPLOAD_MAX_FILESIZE.'M',
  1085. 'success'
  1086. ).'</td>
  1087. <td class="requirements-value">'.compare_setting_values(
  1088. ini_get('upload_max_filesize'),
  1089. REQUIRED_MIN_UPLOAD_MAX_FILESIZE
  1090. ).'</td>
  1091. </tr>
  1092. <tr>
  1093. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.post-max-size">Maximum post size</a></td>
  1094. <td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_POST_MAX_SIZE.'M', 'success').'</td>
  1095. <td class="requirements-value">'.compare_setting_values(
  1096. ini_get('post_max_size'),
  1097. REQUIRED_MIN_POST_MAX_SIZE
  1098. ).'</td>
  1099. </tr>
  1100. <tr>
  1101. <td class="requirements-item"><a href="http://www.php.net/manual/en/ini.core.php#ini.memory-limit">Memory Limit</a></td>
  1102. <td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_MEMORY_LIMIT.'M', 'success').'</td>
  1103. <td class="requirements-value">'.compare_setting_values(
  1104. ini_get('memory_limit'),
  1105. REQUIRED_MIN_MEMORY_LIMIT
  1106. ).'</td>
  1107. </tr>
  1108. </table>';
  1109. echo ' </div>';
  1110. echo '</div>';
  1111. // DIRECTORY AND FILE PERMISSIONS
  1112. echo '<div class="RequirementHeading"><h2>'.get_lang('DirectoryAndFilePermissions').'</h2>';
  1113. echo '<div class="RequirementText">'.get_lang('DirectoryAndFilePermissionsInfo').'</div>';
  1114. echo '<div class="RequirementContent">';
  1115. $course_attempt_name = '__XxTestxX__';
  1116. $course_dir = api_get_path(SYS_COURSE_PATH).$course_attempt_name;
  1117. //Just in case
  1118. @unlink($course_dir.'/test.txt');
  1119. @rmdir($course_dir);
  1120. $perms_dir = array(0777, 0755, 0775, 0770, 0750, 0700);
  1121. $perms_fil = array(0666, 0644, 0664, 0660, 0640, 0600);
  1122. $course_test_was_created = false;
  1123. $dir_perm_verified = 0777;
  1124. foreach ($perms_dir as $perm) {
  1125. $r = @mkdir($course_dir, $perm);
  1126. if ($r === true) {
  1127. $dir_perm_verified = $perm;
  1128. $course_test_was_created = true;
  1129. break;
  1130. }
  1131. }
  1132. $fil_perm_verified = 0666;
  1133. $file_course_test_was_created = false;
  1134. if (is_dir($course_dir)) {
  1135. foreach ($perms_fil as $perm) {
  1136. if ($file_course_test_was_created == true) {
  1137. break;
  1138. }
  1139. $r = @touch($course_dir.'/test.php',$perm);
  1140. if ($r === true) {
  1141. $fil_perm_verified = $perm;
  1142. if (check_course_script_interpretation($course_dir, $course_attempt_name, 'test.php')) {
  1143. $file_course_test_was_created = true;
  1144. }
  1145. }
  1146. }
  1147. }
  1148. @unlink($course_dir.'/test.php');
  1149. @rmdir($course_dir);
  1150. $_SESSION['permissions_for_new_directories'] = $_setting['permissions_for_new_directories'] = $dir_perm_verified;
  1151. $_SESSION['permissions_for_new_files'] = $_setting['permissions_for_new_files'] = $fil_perm_verified;
  1152. $dir_perm = Display::label('0'.decoct($dir_perm_verified), 'info');
  1153. $file_perm = Display::label('0'.decoct($fil_perm_verified), 'info');
  1154. $course_test_was_created = ($course_test_was_created == true && $file_course_test_was_created == true) ? Display::label(get_lang('Yes'), 'success') : Display::label(get_lang('No'), 'warning');
  1155. echo '<table class="table">
  1156. <tr>
  1157. <td class="requirements-item">chamilo/app/config</td>
  1158. <td class="requirements-value">'.check_writable_root_path('app/config/').'</td>
  1159. </tr>
  1160. <tr>
  1161. <td class="requirements-item">chamilo/app/data</td>
  1162. <td class="requirements-value">'.check_writable_root_path('app/data').'</td>
  1163. </tr>
  1164. <tr>
  1165. <td class="requirements-item">chamilo/app/logs</td>
  1166. <td class="requirements-value">'.check_writable_root_path('app/logs').'</td>
  1167. </tr>
  1168. <tr>
  1169. <td class="requirements-item">chamilo/app/cache</td>
  1170. <td class="requirements-value">'.check_writable_root_path('app/cache').'</td>
  1171. </tr>
  1172. <tr>
  1173. <td class="requirements-item">chamilo/main/default_course_document/images/</td>
  1174. <td class="requirements-value">'.check_writable('default_course_document/images/').'</td>
  1175. </tr>
  1176. <tr>
  1177. <td class="requirements-item">chamilo/courses/</td>
  1178. <td class="requirements-value">'.check_writable('../courses/').' </td>
  1179. </tr>
  1180. <tr>
  1181. <td class="requirements-item">'.get_lang('CourseTestWasCreated').'</td>
  1182. <td class="requirements-value">'.$course_test_was_created.' </td>
  1183. </tr>
  1184. <tr>
  1185. <td class="requirements-item">'.get_lang('PermissionsForNewDirs').'</td>
  1186. <td class="requirements-value">'.$dir_perm.' </td>
  1187. </tr>
  1188. <tr>
  1189. <td class="requirements-item">'.get_lang('PermissionsForNewFiles').'</td>
  1190. <td class="requirements-value">'.$file_perm.' </td>
  1191. </tr>
  1192. <tr>
  1193. <td class="requirements-item">chamilo/main/css/</td>
  1194. <td class="requirements-value">'.check_writable('css/', true).' ('.get_lang(
  1195. 'SuggestionOnlyToEnableCSSUploadFeature'
  1196. ).')</td>
  1197. </tr>
  1198. <tr>
  1199. <td class="requirements-item">chamilo/main/lang/</td>
  1200. <td class="requirements-value">'.check_writable('lang/', true).' ('.get_lang(
  1201. 'SuggestionOnlyToEnableSubLanguageFeature'
  1202. ).')</td>
  1203. </tr>';
  1204. echo ' </table>';
  1205. echo ' </div>';
  1206. echo '</div>';
  1207. if ($installType == 'update' && (empty($updatePath) || $badUpdatePath)) {
  1208. if ($badUpdatePath) {
  1209. ?>
  1210. <div class="error-message">
  1211. <?php echo get_lang('Error'); ?>!<br/>
  1212. Chamilo <?php echo (isset($_POST['step2_update_6']) ? implode('|', $update_from_version_6) : implode(
  1213. '|',
  1214. $update_from_version_8
  1215. )).' '.get_lang('HasNotBeenFoundInThatDir'); ?>.
  1216. </div>
  1217. <?php
  1218. } else {
  1219. echo '<br />';
  1220. }
  1221. ?>
  1222. <table border="0" cellpadding="5" align="center">
  1223. <tr>
  1224. <td><?php echo get_lang('OldVersionRootPath'); ?>:</td>
  1225. <td><input type="text" name="updatePath" size="50"
  1226. value="<?php echo ($badUpdatePath && !empty($updatePath)) ? htmlentities(
  1227. $updatePath
  1228. ) : api_get_path(SYS_SERVER_ROOT_PATH).'old_version/'; ?>"/></td>
  1229. </tr>
  1230. <tr>
  1231. <td colspan="2" align="center">
  1232. <button type="submit" class="back" name="step1"
  1233. value="&lt; <?php echo get_lang('Back'); ?>"><?php echo get_lang('Back'); ?></button>
  1234. <input type="hidden" name="is_executable" id="is_executable" value="-"/>
  1235. <button type="submit" class="btn next"
  1236. name="<?php echo (isset($_POST['step2_update_6']) ? 'step2_update_6' : 'step2_update_8'); ?>"
  1237. value="<?php echo get_lang('Next'); ?> &gt;"><?php echo get_lang('Next'); ?></button>
  1238. </td>
  1239. </tr>
  1240. </table>
  1241. <?php
  1242. } else {
  1243. $error = false;
  1244. // First, attempt to set writing permissions if we don't have them yet
  1245. $perm = api_get_permissions_for_new_directories();
  1246. $perm_file = api_get_permissions_for_new_files();
  1247. $notwritable = array();
  1248. $curdir = getcwd();
  1249. $checked_writable = api_get_path(CONFIGURATION_PATH);
  1250. if (!is_writable($checked_writable)) {
  1251. $notwritable[] = $checked_writable;
  1252. @chmod($checked_writable, $perm);
  1253. }
  1254. $checked_writable = api_get_path(SYS_CODE_PATH).'upload/users/';
  1255. if (!is_writable($checked_writable)) {
  1256. $notwritable[] = $checked_writable;
  1257. @chmod($checked_writable, $perm);
  1258. }
  1259. $checked_writable = api_get_path(SYS_CODE_PATH).'default_course_document/images/';
  1260. if (!is_writable($checked_writable)) {
  1261. $notwritable[] = $checked_writable;
  1262. @chmod($checked_writable, $perm);
  1263. }
  1264. $checked_writable = api_get_path(SYS_ARCHIVE_PATH);
  1265. if (!is_writable($checked_writable)) {
  1266. $notwritable[] = $checked_writable;
  1267. @chmod($checked_writable, $perm);
  1268. }
  1269. $checked_writable = api_get_path(SYS_COURSE_PATH);
  1270. if (!is_writable($checked_writable)) {
  1271. $notwritable[] = $checked_writable;
  1272. @chmod($checked_writable, $perm);
  1273. }
  1274. if ($course_test_was_created == false || $file_course_test_was_created == false) {
  1275. $error = true;
  1276. }
  1277. $checked_writable = api_get_path(SYS_PATH).'home/';
  1278. if (!is_writable($checked_writable)) {
  1279. $notwritable[] = realpath($checked_writable);
  1280. @chmod($checked_writable, $perm);
  1281. }
  1282. $checked_writable = api_get_path(CONFIGURATION_PATH).'configuration.php';
  1283. if (file_exists($checked_writable) && !is_writable($checked_writable)) {
  1284. $notwritable[] = $checked_writable;
  1285. @chmod($checked_writable, $perm_file);
  1286. }
  1287. // Second, if this fails, report an error
  1288. //--> The user would have to adjust the permissions manually
  1289. if (count($notwritable) > 0) {
  1290. $error = true;
  1291. echo '<div class="error-message">';
  1292. echo '<center><h3>'.get_lang('Warning').'</h3></center>';
  1293. printf(
  1294. get_lang('NoWritePermissionPleaseReadInstallGuide'),
  1295. '</font>
  1296. <a href="../../documentation/installation_guide.html" target="blank">',
  1297. '</a> <font color="red">'
  1298. );
  1299. echo '</div>';
  1300. echo '<ul>';
  1301. foreach ($notwritable as $value) {
  1302. echo '<li>'.$value.'</li>';
  1303. }
  1304. echo '</ul>';
  1305. } // Check wether a Chamilo configuration file already exists.
  1306. elseif (file_exists(api_get_path(CONFIGURATION_PATH).'configuration.php')) {
  1307. echo '<div class="warning-message"><h4><center>';
  1308. echo get_lang('WarningExistingDokeosInstallationDetected');
  1309. echo '</center></h4></div>';
  1310. }
  1311. // And now display the choice buttons (go back or install)
  1312. ?>
  1313. <p align="center" style="padding-top:15px">
  1314. <button type="submit" name="step1" class="back" onclick="javascript: window.location='index.php'; return false;"
  1315. value="&lt; <?php echo get_lang('Previous'); ?>"><?php echo get_lang('Previous'); ?></button>
  1316. <button type="submit" name="step2_install" class="add"
  1317. value="<?php echo get_lang("NewInstallation"); ?>" <?php if ($error) {
  1318. echo 'disabled="disabled"';
  1319. } ?> ><?php echo get_lang('NewInstallation'); ?></button>
  1320. <input type="hidden" name="is_executable" id="is_executable" value="-"/>
  1321. <?php
  1322. // Real code
  1323. echo '<button type="submit" class="save" name="step2_update_8" value="Upgrade from Dokeos 1.8.x"';
  1324. if ($error) {
  1325. echo ' disabled="disabled"';
  1326. }
  1327. // Temporary code for alpha version, disabling upgrade
  1328. //echo '<input type="submit" name="step2_update" value="Upgrading is not possible in this beta version"';
  1329. //echo ' disabled="disabled"';
  1330. //end temp code
  1331. echo ' >'.get_lang('UpgradeFromDokeos18x').'</button>';
  1332. echo ' <button type="submit" class="save" name="step2_update_6" value="Upgrade from Dokeos 1.6.x"';
  1333. if ($error) {
  1334. echo ' disabled="disabled"';
  1335. }
  1336. echo ' >'.get_lang('UpgradeFromDokeos16x').'</button>';
  1337. echo '</p>';
  1338. }
  1339. }
  1340. /**
  1341. * Displays the license (GNU GPL) as step 2, with
  1342. * - an "I accept" button named step3 to proceed to step 3;
  1343. * - a "Back" button named step1 to go back to the first step.
  1344. */
  1345. function display_license_agreement()
  1346. {
  1347. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('Licence').'</h2>';
  1348. echo '<p>'.get_lang('DokeosLicenseInfo').'</p>';
  1349. echo '<p><a href="../../documentation/license.html" target="_blank">'.get_lang('PrintVers').'</a></p>';
  1350. echo '</div>';
  1351. ?>
  1352. <table>
  1353. <tr>
  1354. <td>
  1355. <p style="font-size:90%">
  1356. <textarea cols="90" rows="7" class="span6">
  1357. <?php echo api_htmlentities(
  1358. @file_get_contents(api_get_path(SYS_PATH).'documentation/license.txt')
  1359. ); ?>
  1360. </textarea></p>
  1361. </td>
  1362. </tr>
  1363. <tr>
  1364. <td>
  1365. <label class="checkbox">
  1366. <input type="checkbox" name="accept" id="accept_licence" value="1" autofocus="autofocus"/>
  1367. <?php echo get_lang('IAccept'); ?>
  1368. </label>
  1369. </td>
  1370. </tr>
  1371. <tr>
  1372. <td><p style="color:#666"><br/><?php echo get_lang('DokeosArtLicense'); ?></p></td>
  1373. </tr>
  1374. <tr>
  1375. <td>
  1376. <table width="100%">
  1377. <tr>
  1378. <td></td>
  1379. <td align="center">
  1380. <button type="submit" class="btn back" name="step1"
  1381. value="&lt; <?php echo get_lang('Previous'); ?>"><?php echo get_lang(
  1382. 'Previous'
  1383. ); ?></button>
  1384. <input type="hidden" name="is_executable" id="is_executable" value="-"/>
  1385. <button type="submit" class="btn next" name="step3"
  1386. onclick="javascript: if(!document.getElementById('accept_licence').checked) { alert('<?php echo get_lang(
  1387. 'YouMustAcceptLicence'
  1388. )?>');return false;}" value="<?php echo get_lang('Next'); ?> &gt;"><?php echo get_lang(
  1389. 'Next'
  1390. ); ?></button>
  1391. </td>
  1392. </tr>
  1393. </table>
  1394. </td>
  1395. </tr>
  1396. </table>
  1397. <!-- Contact information form -->
  1398. <div>
  1399. <a href="javascript://" class="advanced_parameters">
  1400. <span id="img_plus_and_minus">&nbsp;<img src="<?php echo api_get_path(WEB_IMG_PATH) ?>div_hide.gif"
  1401. alt="<?php echo get_lang('Hide') ?>"
  1402. title="<?php echo get_lang('Hide')?>" style="vertical-align:middle"/>&nbsp;<?php echo get_lang(
  1403. 'ContactInformation'
  1404. ) ?></span>
  1405. </a>
  1406. </div>
  1407. <div id="id_contact_form" style="display:block">
  1408. <div class="normal-message"><?php echo get_lang('ContactInformationDescription') ?></div>
  1409. <div id="contact_registration">
  1410. <p><?php echo get_contact_registration_form() ?></p><br/>
  1411. </div>
  1412. </div>
  1413. <?php
  1414. }
  1415. /**
  1416. * Get contact registration form
  1417. */
  1418. function get_contact_registration_form()
  1419. {
  1420. $html = '
  1421. <form class="form-horizontal">
  1422. <fieldset style="width:95%;padding:15px;border:1pt solid #eee">
  1423. <div id="div_sent_information"></div>
  1424. <div class="control-group">
  1425. <label class="control-label"><span class="form_required">*</span>'.get_lang('Name').'</label>
  1426. <div class="controls"><input id="person_name" type="text" name="person_name" size="30" /></div>
  1427. </div>
  1428. <div class="control-group">
  1429. <label class="control-label"><span class="form_required">*</span>'.get_lang('Email').'</label>
  1430. <div class="controls"><input id="person_email" type="text" name="person_email" size="30" /></div>
  1431. </div>
  1432. <div class="control-group">
  1433. <label class="control-label"><span class="form_required">*</span>'.get_lang('CompanyName').'</label>
  1434. <div class="controls"><input id="company_name" type="text" name="company_name" size="30" /></div>
  1435. </div>
  1436. <div class="control-group">
  1437. <div class="control-label"><span class="form_required">*</span>'.get_lang('CompanyActivity').'</div>
  1438. <div class="controls">
  1439. <select name="company_activity" id="company_activity" >
  1440. <option value="">--- '.get_lang('SelectOne').' ---</option>
  1441. <Option value="Advertising/Marketing/PR">Advertising/Marketing/PR</Option><Option value="Agriculture/Forestry">Agriculture/Forestry</Option>
  1442. <Option value="Architecture">Architecture</Option><Option value="Banking/Finance">Banking/Finance</Option>
  1443. <Option value="Biotech/Pharmaceuticals">Biotech/Pharmaceuticals</Option><Option value="Business Equipment">Business Equipment</Option>
  1444. <Option value="Business Services">Business Services</Option><Option value="Construction">Construction</Option>
  1445. <Option value="Consulting/Research">Consulting/Research</Option><Option value="Education">Education</Option>
  1446. <Option value="Engineering">Engineering</Option><Option value="Environmental">Environmental</Option>
  1447. <Option value="Government">Government</Option><Option value="Healthcare">Health Care</Option>
  1448. <Option value="Hospitality/Lodging/Travel">Hospitality/Lodging/Travel</Option><Option value="Insurance">Insurance</Option>
  1449. <Option value="Legal">Legal</Option><Option value="Manufacturing">Manufacturing</Option>
  1450. <Option value="Media/Entertainment">Media/Entertainment</Option><Option value="Mortgage">Mortgage</Option>
  1451. <Option value="Non-Profit">Non-Profit</Option><Option value="Real Estate">Real Estate</Option>
  1452. <Option value="Restaurant">Restaurant</Option><Option value="Retail">Retail</Option>
  1453. <Option value="Shipping/Transportation">Shipping/Transportation</Option>
  1454. <Option value="Technology">Technology</Option><Option value="Telecommunications">Telecommunications</Option>
  1455. <Option value="Other">Other</Option>
  1456. </select>
  1457. </div>
  1458. </div>
  1459. <div class="control-group">
  1460. <div class="control-label"><span class="form_required">*</span>'.get_lang('PersonRole').'</div>
  1461. <div class="controls">
  1462. <select name="person_role" id="person_role" >
  1463. <option value="">--- '.get_lang('SelectOne').' ---</option>
  1464. <Option value="Administration">Administration</Option><Option value="CEO/President/ Owner">CEO/President/ Owner</Option>
  1465. <Option value="CFO">CFO</Option><Option value="CIO/CTO">CIO/CTO</Option>
  1466. <Option value="Consultant">Consultant</Option><Option value="Customer Service">Customer Service</Option>
  1467. <Option value="Engineer/Programmer">Engineer/Programmer</Option><Option value="Facilities/Operations">Facilities/Operations</Option>
  1468. <Option value="Finance/ Accounting Manager">Finance/ Accounting Manager</Option><Option value="Finance/ Accounting Staff">Finance/ Accounting Staff</Option>
  1469. <Option value="General Manager">General Manager</Option><Option value="Human Resources">Human Resources</Option>
  1470. <Option value="IS/IT Management">IS/IT Management</Option><Option value="IS/ IT Staff">IS/ IT Staff</Option>
  1471. <Option value="Marketing Manager">Marketing Manager</Option><Option value="Marketing Staff">Marketing Staff</Option>
  1472. <Option value="Partner/Principal">Partner/Principal</Option><Option value="Purchasing Manager">Purchasing Manager</Option>
  1473. <Option value="Sales/ Business Dev. Manager">Sales/ Business Dev. Manager</Option><Option value="Sales/ Business Dev.">Sales/ Business Dev.</Option>
  1474. <Option value="Vice President/Senior Manager">Vice President/Senior Manager</Option><Option value="Other">Other</Option>
  1475. </select>
  1476. </div>
  1477. </div>
  1478. <div class="control-group">
  1479. <div class="control-label"><span class="form_required">*</span>'.get_lang('CompanyCountry').'</div>
  1480. <div class="controls">'.get_countries_list_from_array(true).'</div>
  1481. </div>
  1482. <div class="control-group">
  1483. <div class="control-label">'.get_lang('CompanyCity').'</div>
  1484. <div class="controls">
  1485. <input type="text" id="company_city" name="company_city" size="30" />
  1486. </div>
  1487. </div>
  1488. <div class="control-group">
  1489. <div class="control-label">'.get_lang('WhichLanguageWouldYouLikeToUseWhenContactingYou').'</div>
  1490. <div class="controls">
  1491. <select id="language" name="language">
  1492. <option value="bulgarian">Bulgarian</option>
  1493. <option value="indonesian">Bahasa Indonesia</option>
  1494. <option value="bosnian">Bosanski</option>
  1495. <option value="german">Deutsch</option>
  1496. <option selected="selected" value="english">English</option>
  1497. <option value="spanish">Spanish</option>
  1498. <option value="french">Français</option>
  1499. <option value="italian">Italian</option>
  1500. <option value="hungarian">Magyar</option>
  1501. <option value="dutch">Nederlands</option>
  1502. <option value="brazilian">Português do Brasil</option>
  1503. <option value="portuguese">Português europeu</option>
  1504. <option value="slovenian">Slovenčina</option>
  1505. </select>
  1506. </div>
  1507. </div>
  1508. <div class="control-group">
  1509. <div class="control-label">'.get_lang('HaveYouThePowerToTakeFinancialDecisions').'</div>
  1510. <div class="controls">
  1511. <input type="radio" name="financial_decision" id="financial_decision1" value="1" checked />'.get_lang(
  1512. 'Yes'
  1513. ).'
  1514. <input type="radio" name="financial_decision" id="financial_decision2" value="0" />'.get_lang('No').'
  1515. </div>
  1516. </div>
  1517. <div class="clear"></div>
  1518. <div class="control-group">
  1519. <div class="control-label">&nbsp;</div>
  1520. <div class="controls"><button type="button" class="save" onclick="javascript:send_contact_information();" value="'.get_lang(
  1521. 'SendInformation'
  1522. ).'" >'.get_lang('SendInformation').'</button></div>
  1523. </div>
  1524. <div class="control-group">
  1525. <div class="control-label">&nbsp;</div>
  1526. <div class="controls"><span class="form_required">*</span><small>'.get_lang('FieldRequired').'</small></div>
  1527. </div>
  1528. </fieldset></form>';
  1529. return $html;
  1530. }
  1531. /**
  1532. * Displays a parameter in a table row.
  1533. * Used by the display_database_settings_form function.
  1534. * @param string Type of install
  1535. * @param string Name of parameter
  1536. * @param string Field name (in the HTML form)
  1537. * @param string Field value
  1538. * @param string Extra notice (to show on the right side)
  1539. * @param boolean Whether to display in update mode
  1540. * @param string Additional attribute for the <tr> element
  1541. * @return void Direct output
  1542. */
  1543. function display_database_parameter(
  1544. $install_type,
  1545. $parameter_name,
  1546. $form_field_name,
  1547. $parameter_value,
  1548. $extra_notice,
  1549. $display_when_update = true,
  1550. $tr_attribute = ''
  1551. ) {
  1552. echo "<tr ".$tr_attribute.">";
  1553. echo "<td>$parameter_name&nbsp;&nbsp;</td>";
  1554. if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update) {
  1555. echo '<td><input type="hidden" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities(
  1556. $parameter_value
  1557. ).'" />'.$parameter_value."</td>";
  1558. } else {
  1559. $inputtype = $form_field_name == 'dbPassForm' ? 'password' : 'text';
  1560. //Slightly limit the length of the database prefix to avoid having to cut down the databases names later on
  1561. $maxlength = $form_field_name == 'dbPrefixForm' ? '15' : MAX_FORM_FIELD_LENGTH;
  1562. if ($install_type == INSTALL_TYPE_UPDATE) {
  1563. echo '<input type="hidden" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities(
  1564. $parameter_value
  1565. ).'" />';
  1566. echo '<td>'.api_htmlentities($parameter_value)."</td>";
  1567. } else {
  1568. echo '<td><input type="'.$inputtype.'" size="'.DATABASE_FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.$maxlength.'" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities(
  1569. $parameter_value
  1570. ).'" />'."</td>";
  1571. echo "<td>$extra_notice</td>";
  1572. }
  1573. }
  1574. echo "</tr>";
  1575. }
  1576. /**
  1577. * Displays step 3 - a form where the user can enter the installation settings
  1578. * regarding the databases - login and password, names, prefixes, single
  1579. * or multiple databases, tracking or not...
  1580. */
  1581. function display_database_settings_form(
  1582. $installType,
  1583. $dbHostForm,
  1584. $dbUsernameForm,
  1585. $dbPassForm,
  1586. $dbPrefixForm,
  1587. $enableTrackingForm,
  1588. $singleDbForm,
  1589. $dbNameForm,
  1590. $dbStatsForm,
  1591. $dbScormForm,
  1592. $dbUserForm
  1593. ) {
  1594. if ($installType == 'update') {
  1595. global $_configuration, $update_from_version_6;
  1596. if (in_array($_POST['old_version'], $update_from_version_6)) {
  1597. $dbHostForm = get_config_param('dbHost');
  1598. $dbUsernameForm = get_config_param('dbLogin');
  1599. $dbPassForm = get_config_param('dbPass');
  1600. $dbPrefixForm = get_config_param('dbNamePrefix');
  1601. $enableTrackingForm = get_config_param('is_trackingEnabled');
  1602. $singleDbForm = get_config_param('singleDbEnabled');
  1603. $dbHostForm = get_config_param('mainDbName');
  1604. $dbStatsForm = get_config_param('statsDbName');
  1605. $dbScormForm = get_config_param('scormDbName');
  1606. $dbUserForm = get_config_param('user_personal_database');
  1607. $dbScormExists = true;
  1608. } else {
  1609. $dbHostForm = $_configuration['db_host'];
  1610. $dbUsernameForm = $_configuration['db_user'];
  1611. $dbPassForm = $_configuration['db_password'];
  1612. $dbPrefixForm = $_configuration['db_prefix'];
  1613. $enableTrackingForm = isset($_configuration['tracking_enabled']) ? $_configuration['tracking_enabled'] : null;
  1614. $singleDbForm = isset($_configuration['single_database']) ? $_configuration['single_database'] : null;
  1615. $dbNameForm = $_configuration['main_database'];
  1616. $dbStatsForm = isset($_configuration['statistics_database']) ? $_configuration['statistics_database'] : null;
  1617. $dbScormForm = isset($_configuration['scorm_database']) ? $_configuration['scorm_database'] : null;
  1618. $dbUserForm = isset($_configuration['user_personal_database']) ? $_configuration['user_personal_database'] : null;
  1619. $dbScormExists = true;
  1620. }
  1621. if (empty($dbScormForm)) {
  1622. if ($singleDbForm) {
  1623. $dbScormForm = $dbNameForm;
  1624. } else {
  1625. $dbScormForm = $dbPrefixForm.'scorm';
  1626. $dbScormExists = false;
  1627. }
  1628. }
  1629. if (empty($dbUserForm)) {
  1630. $dbUserForm = $singleDbForm ? $dbNameForm : $dbPrefixForm.'chamilo_user';
  1631. }
  1632. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('DBSetting').'</h2></div>';
  1633. echo '<div class="RequirementContent">';
  1634. echo get_lang('DBSettingUpgradeIntro');
  1635. echo '</div>';
  1636. } else {
  1637. if (empty($dbPrefixForm)) { //make sure there is a default value for db prefix
  1638. $dbPrefixForm = '';
  1639. }
  1640. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('DBSetting').'</h2></div>';
  1641. echo '<div class="RequirementContent">';
  1642. echo get_lang('DBSettingIntro');
  1643. echo '</div>';
  1644. }
  1645. $dbConnect = test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm, $dbNameForm);
  1646. ?>
  1647. </td>
  1648. </tr>
  1649. <tr>
  1650. <td>
  1651. <table class="data_table_no_border">
  1652. <tr>
  1653. <td width="40%"><?php echo get_lang('DBHost'); ?> </td>
  1654. <?php if ($installType == 'update'): ?>
  1655. <td width="30%"><input type="hidden" name="dbHostForm"
  1656. value="<?php echo htmlentities($dbHostForm); ?>"/><?php echo $dbHostForm; ?></td>
  1657. <td width="30%">&nbsp;</td>
  1658. <?php else: ?>
  1659. <td width="30%"><input type="text" size="25" maxlength="50" name="dbHostForm"
  1660. value="<?php echo htmlentities($dbHostForm); ?>" <?php if ($dbConnect == -1) {
  1661. echo 'autofocus="autofocus"';
  1662. } ?> /></td>
  1663. <td width="30%"><?php echo get_lang('EG').' localhost'; ?></td>
  1664. <?php endif; ?>
  1665. </tr>
  1666. <tr>
  1667. <?php
  1668. //database user username
  1669. $example_login = get_lang('EG').' root';
  1670. display_database_parameter(
  1671. $installType,
  1672. get_lang('DBLogin'),
  1673. 'dbUsernameForm',
  1674. $dbUsernameForm,
  1675. $example_login
  1676. );
  1677. //database user password
  1678. $example_password = get_lang('EG').' '.api_generate_password();
  1679. display_database_parameter(
  1680. $installType,
  1681. get_lang('DBPassword'),
  1682. 'dbPassForm',
  1683. $dbPassForm,
  1684. $example_password
  1685. );
  1686. echo '<input type="hidden" name="enableTrackingForm" value="1" />';
  1687. $style = '';
  1688. if ($installType == INSTALL_TYPE_UPDATE) {
  1689. $style = '';
  1690. }
  1691. //Database Name fix replace weird chars
  1692. if ($installType != INSTALL_TYPE_UPDATE) {
  1693. $dbNameForm = str_replace(array('-', '*', '$', ' ', '.'), '', $dbNameForm);
  1694. $dbNameForm = replace_dangerous_char($dbNameForm);
  1695. }
  1696. display_database_parameter(
  1697. $installType,
  1698. get_lang('MainDB'),
  1699. 'dbNameForm',
  1700. $dbNameForm,
  1701. '&nbsp;',
  1702. null,
  1703. 'id="optional_param1" '.$style
  1704. );
  1705. //Only for updates we show this options
  1706. if ($installType == INSTALL_TYPE_UPDATE) {
  1707. /*display_database_parameter(
  1708. $installType,
  1709. get_lang('StatDB'),
  1710. 'dbStatsForm',
  1711. $dbStatsForm,
  1712. '&nbsp;',
  1713. null,
  1714. 'id="optional_param2" '.$style
  1715. );
  1716. if ($installType == INSTALL_TYPE_UPDATE && in_array($_POST['old_version'], $update_from_version_6)) {
  1717. display_database_parameter(
  1718. $installType,
  1719. get_lang('ScormDB'),
  1720. 'dbScormForm',
  1721. $dbScormForm,
  1722. '&nbsp;',
  1723. null,
  1724. 'id="optional_param3" '.$style
  1725. );
  1726. }
  1727. display_database_parameter(
  1728. $installType,
  1729. get_lang('UserDB'),
  1730. 'dbUserForm',
  1731. $dbUserForm,
  1732. '&nbsp;',
  1733. null,
  1734. 'id="optional_param4" '.$style
  1735. );*/
  1736. }
  1737. ?>
  1738. <tr>
  1739. <td></td>
  1740. <td>
  1741. <button type="submit" class="btn" name="step3"
  1742. value="<?php echo get_lang('CheckDatabaseConnection'); ?>">
  1743. <?php echo get_lang('CheckDatabaseConnection'); ?></button>
  1744. </td>
  1745. </tr>
  1746. <tr>
  1747. <td>
  1748. <?php
  1749. $database_exists_text = '';
  1750. if (database_exists($dbNameForm)) {
  1751. $database_exists_text = '<div class="warning-message">'.get_lang(
  1752. 'ADatabaseWithTheSameNameAlreadyExists'
  1753. ).'</div>';
  1754. } else {
  1755. if ($dbConnect == -1) {
  1756. $database_exists_text = '<div class="warning-message">'.sprintf(
  1757. get_lang('UserXCantHaveAccessInTheDatabaseX'),
  1758. $dbUsernameForm,
  1759. $dbNameForm
  1760. ).'</div>';
  1761. } else {
  1762. //Try to create the database
  1763. $user_can_create_databases = false;
  1764. $multipleDbCheck = @Database::query("CREATE DATABASE ".mysql_real_escape_string($dbNameForm));
  1765. if ($multipleDbCheck !== false) {
  1766. $multipleDbCheck = @Database::query(
  1767. "DROP DATABASE IF EXISTS ".mysql_real_escape_string($dbNameForm)
  1768. );
  1769. $user_can_create_databases = true;
  1770. }
  1771. if ($user_can_create_databases) {
  1772. $database_exists_text = '<div class="normal-message">'.sprintf(
  1773. get_lang('DatabaseXWillBeCreated'),
  1774. $dbNameForm,
  1775. $dbUsernameForm
  1776. ).'</div>';
  1777. } else {
  1778. $dbConnect = 0;
  1779. $database_exists_text = '<div class="warning-message">'.sprintf(
  1780. get_lang('DatabaseXCantBeCreatedUserXDoestHaveEnoughPermissions'),
  1781. $dbNameForm,
  1782. $dbUsernameForm
  1783. ).'</div>';
  1784. }
  1785. }
  1786. }
  1787. if ($dbConnect == 1): ?>
  1788. <td colspan="2">
  1789. <?php echo $database_exists_text ?>
  1790. <div id="db_status" class="confirmation-message">
  1791. Database host: <strong><?php echo Database::get_host_info(); ?></strong><br/>
  1792. Database server version: <strong><?php echo Database::get_server_info(); ?></strong><br/>
  1793. Database client version: <strong><?php echo Database::get_client_info(); ?></strong><br/>
  1794. Database protocol version: <strong><?php echo Database::get_proto_info(); ?></strong>
  1795. <div style="clear:both;"></div>
  1796. </div>
  1797. </td>
  1798. <?php else: ?>
  1799. <td colspan="2">
  1800. <?php echo $database_exists_text ?>
  1801. <div id="db_status" style="float:left;" class="error-message">
  1802. <div style="float:left;">
  1803. <strong><?php echo get_lang('FailedConectionDatabase'); ?></strong><br/>
  1804. <strong>Database error: <?php echo Database::errno(); ?></strong><br/>
  1805. <?php echo Database::error().'<br />'; ?>
  1806. </div>
  1807. </div>
  1808. </td>
  1809. <?php endif; ?>
  1810. </tr>
  1811. <tr>
  1812. <td>
  1813. <button type="submit" name="step2" class="back"
  1814. value="&lt; <?php echo get_lang('Previous'); ?>"><?php echo get_lang('Previous'); ?></button>
  1815. </td>
  1816. <td>&nbsp;</td>
  1817. <td align="right">
  1818. <input type="hidden" name="is_executable" id="is_executable" value="-"/>
  1819. <?php if ($dbConnect == 1) { ?>
  1820. <button type="submit" class="btn next" name="step4"
  1821. value="<?php echo get_lang('Next'); ?> &gt;" <?php if ($dbConnect == 1) {
  1822. echo 'autofocus="autofocus"';
  1823. } ?> /><?php echo get_lang('Next'); ?></button>
  1824. <?php } else { ?>
  1825. <button disabled="disabled" type="submit" class="btn next disabled" name="step4"
  1826. value="<?php echo get_lang('Next'); ?> &gt;"/><?php echo get_lang('Next'); ?></button>
  1827. <?php } ?>
  1828. </td>
  1829. </tr>
  1830. </table>
  1831. <?php
  1832. }
  1833. /**
  1834. * Displays a parameter in a table row.
  1835. * Used by the display_configuration_settings_form function.
  1836. */
  1837. function display_configuration_parameter(
  1838. $install_type,
  1839. $parameter_name,
  1840. $form_field_name,
  1841. $parameter_value,
  1842. $display_when_update = 'true'
  1843. ) {
  1844. echo "<tr>";
  1845. echo "<td>$parameter_name</td>";
  1846. if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update) {
  1847. echo '<td><input type="hidden" name="'.$form_field_name.'" value="'.api_htmlentities(
  1848. $parameter_value,
  1849. ENT_QUOTES
  1850. ).'" />'.$parameter_value."</td>\n";
  1851. } else {
  1852. echo '<td><input type="text" size="'.FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.MAX_FORM_FIELD_LENGTH.'" name="'.$form_field_name.'" value="'.api_htmlentities(
  1853. $parameter_value,
  1854. ENT_QUOTES
  1855. ).'" '.($form_field_name == 'loginForm' ? 'autofocus="autofocus"' : '').' />'."</td>\n";
  1856. }
  1857. echo "</tr>";
  1858. }
  1859. /**
  1860. * Displays step 4 of the installation - configuration settings about Chamilo itself.
  1861. */
  1862. function display_configuration_settings_form(
  1863. $installType,
  1864. $urlForm,
  1865. $languageForm,
  1866. $emailForm,
  1867. $adminFirstName,
  1868. $adminLastName,
  1869. $adminPhoneForm,
  1870. $campusForm,
  1871. $institutionForm,
  1872. $institutionUrlForm,
  1873. $encryptPassForm,
  1874. $allowSelfReg,
  1875. $allowSelfRegProf,
  1876. $loginForm,
  1877. $passForm
  1878. ) {
  1879. if ($installType != 'update' && empty($languageForm)) {
  1880. $languageForm = $_SESSION['install_language'];
  1881. }
  1882. echo '<div class="RequirementHeading">';
  1883. echo "<h2>".display_step_sequence().get_lang("CfgSetting")."</h2>";
  1884. echo '</div>';
  1885. echo '<div class="RequirementContent">';
  1886. echo '<p>'.get_lang('ConfigSettingsInfo').' <strong>main/inc/conf/configuration.php</strong></p>';
  1887. echo '</div>';
  1888. echo '<fieldset>';
  1889. echo '<legend>'.get_lang('Administrator').'</legend>';
  1890. echo '<table class="data_table_no_border">';
  1891. //Parameter 1: administrator's login
  1892. display_configuration_parameter(
  1893. $installType,
  1894. get_lang('AdminLogin'),
  1895. 'loginForm',
  1896. $loginForm,
  1897. $installType == 'update'
  1898. );
  1899. //Parameter 2: administrator's password
  1900. if ($installType != 'update') {
  1901. display_configuration_parameter($installType, get_lang('AdminPass'), 'passForm', $passForm, false);
  1902. }
  1903. //Parameters 3 and 4: administrator's names
  1904. if (api_is_western_name_order()) {
  1905. display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
  1906. display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
  1907. } else {
  1908. display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
  1909. display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
  1910. }
  1911. //Parameter 3: administrator's email
  1912. display_configuration_parameter($installType, get_lang('AdminEmail'), 'emailForm', $emailForm);
  1913. //Parameter 6: administrator's telephone
  1914. display_configuration_parameter($installType, get_lang('AdminPhone'), 'adminPhoneForm', $adminPhoneForm);
  1915. echo '</table>';
  1916. echo '</fieldset>';
  1917. echo '<fieldset>';
  1918. echo '<legend>'.get_lang('Platform').'</legend>';
  1919. echo '<table class="data_table_no_border">';
  1920. //First parameter: language
  1921. echo "<tr>";
  1922. echo '<td>'.get_lang('MainLang')."&nbsp;&nbsp;</td>";
  1923. if ($installType == 'update') {
  1924. echo '<td><input type="hidden" name="languageForm" value="'.api_htmlentities(
  1925. $languageForm,
  1926. ENT_QUOTES
  1927. ).'" />'.$languageForm."</td>";
  1928. } else { // new installation
  1929. echo '<td>';
  1930. display_language_selection_box('languageForm', $languageForm);
  1931. echo "</td>\n";
  1932. }
  1933. echo "</tr>\n";
  1934. //Second parameter: Chamilo URL
  1935. echo "<tr>";
  1936. echo '<td>'.get_lang('ChamiloURL').' (<font color="red">'.get_lang(
  1937. 'ThisFieldIsRequired'
  1938. )."</font>)&nbsp;&nbsp;</td>";
  1939. if ($installType == 'update') {
  1940. echo '<td>'.api_htmlentities($urlForm, ENT_QUOTES)."</td>\n";
  1941. } else {
  1942. echo '<td><input type="text" size="40" maxlength="100" name="urlForm" value="'.api_htmlentities(
  1943. $urlForm,
  1944. ENT_QUOTES
  1945. ).'" />'."</td>";
  1946. }
  1947. echo "</tr>";
  1948. //Parameter 9: campus name
  1949. display_configuration_parameter($installType, get_lang('CampusName'), 'campusForm', $campusForm);
  1950. //Parameter 10: institute (short) name
  1951. display_configuration_parameter($installType, get_lang('InstituteShortName'), 'institutionForm', $institutionForm);
  1952. //Parameter 11: institute (short) name
  1953. display_configuration_parameter($installType, get_lang('InstituteURL'), 'institutionUrlForm', $institutionUrlForm);
  1954. ?>
  1955. <tr>
  1956. <td><?php echo get_lang("EncryptMethodUserPass"); ?> :</td>
  1957. <?php if ($installType == 'update') { ?>
  1958. <td><input type="hidden" name="encryptPassForm"
  1959. value="<?php echo $encryptPassForm; ?>"/><?php echo $encryptPassForm; ?></td>
  1960. <?php } else { ?>
  1961. <td>
  1962. <div class="control-group">
  1963. <label class="checkbox inline">
  1964. <input class="checkbox" type="radio" name="encryptPassForm" value="sha1"
  1965. id="encryptPass1" <?php echo ($encryptPassForm == 'sha1') ? 'checked="checked" ' : ''; ?>/><?php echo 'sha1'; ?>
  1966. </label>
  1967. <label class="checkbox inline">
  1968. <input class="checkbox" type="radio" name="encryptPassForm" value="md5"
  1969. id="encryptPass0" <?php echo $encryptPassForm == 1 ? 'checked="checked" ' : ''; ?>/><?php echo 'md5'; ?>
  1970. </label>
  1971. <label class="checkbox inline">
  1972. <input class="checkbox" type="radio" name="encryptPassForm" value="none"
  1973. id="encryptPass2" <?php echo $encryptPassForm === '0' or $encryptPassForm === 0 ? 'checked="checked" ' : ''; ?>/><?php echo get_lang(
  1974. 'None'
  1975. ); ?>
  1976. </label>
  1977. </div>
  1978. </td>
  1979. <?php } ?>
  1980. </tr>
  1981. <tr>
  1982. <td><?php echo get_lang('AllowSelfReg'); ?> :</td>
  1983. <?php if ($installType == 'update'): ?>
  1984. <td><input type="hidden" name="allowSelfReg"
  1985. value="<?php echo $allowSelfReg; ?>"/><?php echo $allowSelfReg ? get_lang('Yes') : get_lang('No'); ?>
  1986. </td>
  1987. <?php else: ?>
  1988. <td>
  1989. <div class="control-group">
  1990. <label class="checkbox inline">
  1991. <input class="checkbox" type="radio" name="allowSelfReg" value="1"
  1992. id="allowSelfReg1" <?php echo $allowSelfReg ? 'checked="checked" ' : ''; ?>/> <?php echo get_lang(
  1993. 'Yes'
  1994. ); ?>
  1995. </label>
  1996. <label class="checkbox inline">
  1997. <input class="checkbox" type="radio" name="allowSelfReg" value="0"
  1998. id="allowSelfReg0" <?php echo $allowSelfReg ? '' : 'checked="checked" '; ?>/><?php echo get_lang(
  1999. 'No'
  2000. ); ?>
  2001. </label>
  2002. </div>
  2003. </td>
  2004. <?php endif; ?>
  2005. </tr>
  2006. <tr>
  2007. <td><?php echo get_lang('AllowSelfRegProf'); ?> :</td>
  2008. <?php if ($installType == 'update'): ?>
  2009. <td><input type="hidden" name="allowSelfRegProf"
  2010. value="<?php echo $allowSelfRegProf; ?>"/><?php echo $allowSelfRegProf ? get_lang('Yes') : get_lang(
  2011. 'No'
  2012. ); ?></td>
  2013. <?php else: ?>
  2014. <td>
  2015. <div class="control-group">
  2016. <label class="checkbox inline">
  2017. <input class="checkbox" type="radio" name="allowSelfRegProf" value="1"
  2018. id="allowSelfRegProf1" <?php echo $allowSelfRegProf ? 'checked="checked" ' : ''; ?>/>
  2019. <?php echo get_lang('Yes'); ?>
  2020. </label>
  2021. <label class="checkbox inline">
  2022. <input class="checkbox" type="radio" name="allowSelfRegProf" value="0"
  2023. id="allowSelfRegProf0" <?php echo $allowSelfRegProf ? '' : 'checked="checked" '; ?>/>
  2024. <?php echo get_lang('No'); ?>
  2025. </label>
  2026. </div>
  2027. </td>
  2028. <?php endif; ?>
  2029. </tr>
  2030. <tr>
  2031. <td>
  2032. <button type="submit" class="btn back" name="step3" value="&lt; <?php echo get_lang('Previous'); ?>"/>
  2033. <?php echo get_lang('Previous'); ?></button>
  2034. </td>
  2035. <td align="right">
  2036. <input type="hidden" name="is_executable" id="is_executable" value="-"/>
  2037. <button class="btn next" type="submit" name="step5" value="<?php echo get_lang('Next'); ?> &gt;"/>
  2038. <?php echo get_lang('Next'); ?></button></td>
  2039. </tr>
  2040. </fieldset>
  2041. </table>
  2042. <?php
  2043. }
  2044. /**
  2045. * After installation is completed (step 6), this message is displayed.
  2046. */
  2047. function display_after_install_message($installType)
  2048. {
  2049. echo '<div class="RequirementContent">'.get_lang('FirstUseTip').'</div>';
  2050. echo '<div class="warning-message">';
  2051. echo '<strong>'.get_lang('SecurityAdvice').'</strong>';
  2052. echo ': ';
  2053. printf(get_lang('ToProtectYourSiteMakeXReadOnlyAndDeleteY'), 'main/inc/conf/', 'main/install/');
  2054. echo '</div>';
  2055. ?></form>
  2056. <br/>
  2057. <a class="btn btn-success btn-large btn-install" href="../../index.php" autofocus="autofocus"><?php echo get_lang(
  2058. 'GoToYourNewlyCreatedPortal'
  2059. ); ?></a>
  2060. <?php
  2061. }
  2062. /**
  2063. * This function return countries list from array (hardcoded)
  2064. * @param bool (Optional) True for returning countries list with select html
  2065. * @return array|string countries list
  2066. */
  2067. function get_countries_list_from_array($combo = false)
  2068. {
  2069. $a_countries = array(
  2070. "Afghanistan",
  2071. "Albania",
  2072. "Algeria",
  2073. "Andorra",
  2074. "Angola",
  2075. "Antigua and Barbuda",
  2076. "Argentina",
  2077. "Armenia",
  2078. "Australia",
  2079. "Austria",
  2080. "Azerbaijan",
  2081. "Bahamas",
  2082. "Bahrain",
  2083. "Bangladesh",
  2084. "Barbados",
  2085. "Belarus",
  2086. "Belgium",
  2087. "Belize",
  2088. "Benin",
  2089. "Bhutan",
  2090. "Bolivia",
  2091. "Bosnia and Herzegovina",
  2092. "Botswana",
  2093. "Brazil",
  2094. "Brunei",
  2095. "Bulgaria",
  2096. "Burkina Faso",
  2097. "Burundi",
  2098. "Cambodia",
  2099. "Cameroon",
  2100. "Canada",
  2101. "Cape Verde",
  2102. "Central African Republic",
  2103. "Chad",
  2104. "Chile",
  2105. "China",
  2106. "Colombi",
  2107. "Comoros",
  2108. "Congo (Brazzaville)",
  2109. "Congo",
  2110. "Costa Rica",
  2111. "Cote d'Ivoire",
  2112. "Croatia",
  2113. "Cuba",
  2114. "Cyprus",
  2115. "Czech Republic",
  2116. "Denmark",
  2117. "Djibouti",
  2118. "Dominica",
  2119. "Dominican Republic",
  2120. "East Timor (Timor Timur)",
  2121. "Ecuador",
  2122. "Egypt",
  2123. "El Salvador",
  2124. "Equatorial Guinea",
  2125. "Eritrea",
  2126. "Estonia",
  2127. "Ethiopia",
  2128. "Fiji",
  2129. "Finland",
  2130. "France",
  2131. "Gabon",
  2132. "Gambia, The",
  2133. "Georgia",
  2134. "Germany",
  2135. "Ghana",
  2136. "Greece",
  2137. "Grenada",
  2138. "Guatemala",
  2139. "Guinea",
  2140. "Guinea-Bissau",
  2141. "Guyana",
  2142. "Haiti",
  2143. "Honduras",
  2144. "Hungary",
  2145. "Iceland",
  2146. "India",
  2147. "Indonesia",
  2148. "Iran",
  2149. "Iraq",
  2150. "Ireland",
  2151. "Israel",
  2152. "Italy",
  2153. "Jamaica",
  2154. "Japan",
  2155. "Jordan",
  2156. "Kazakhstan",
  2157. "Kenya",
  2158. "Kiribati",
  2159. "Korea, North",
  2160. "Korea, South",
  2161. "Kuwait",
  2162. "Kyrgyzstan",
  2163. "Laos",
  2164. "Latvia",
  2165. "Lebanon",
  2166. "Lesotho",
  2167. "Liberia",
  2168. "Libya",
  2169. "Liechtenstein",
  2170. "Lithuania",
  2171. "Luxembourg",
  2172. "Macedonia",
  2173. "Madagascar",
  2174. "Malawi",
  2175. "Malaysia",
  2176. "Maldives",
  2177. "Mali",
  2178. "Malta",
  2179. "Marshall Islands",
  2180. "Mauritania",
  2181. "Mauritius",
  2182. "Mexico",
  2183. "Micronesia",
  2184. "Moldova",
  2185. "Monaco",
  2186. "Mongolia",
  2187. "Morocco",
  2188. "Mozambique",
  2189. "Myanmar",
  2190. "Namibia",
  2191. "Nauru",
  2192. "Nepa",
  2193. "Netherlands",
  2194. "New Zealand",
  2195. "Nicaragua",
  2196. "Niger",
  2197. "Nigeria",
  2198. "Norway",
  2199. "Oman",
  2200. "Pakistan",
  2201. "Palau",
  2202. "Panama",
  2203. "Papua New Guinea",
  2204. "Paraguay",
  2205. "Peru",
  2206. "Philippines",
  2207. "Poland",
  2208. "Portugal",
  2209. "Qatar",
  2210. "Romania",
  2211. "Russia",
  2212. "Rwanda",
  2213. "Saint Kitts and Nevis",
  2214. "Saint Lucia",
  2215. "Saint Vincent",
  2216. "Samoa",
  2217. "San Marino",
  2218. "Sao Tome and Principe",
  2219. "Saudi Arabia",
  2220. "Senegal",
  2221. "Serbia and Montenegro",
  2222. "Seychelles",
  2223. "Sierra Leone",
  2224. "Singapore",
  2225. "Slovakia",
  2226. "Slovenia",
  2227. "Solomon Islands",
  2228. "Somalia",
  2229. "South Africa",
  2230. "Spain",
  2231. "Sri Lanka",
  2232. "Sudan",
  2233. "Suriname",
  2234. "Swaziland",
  2235. "Sweden",
  2236. "Switzerland",
  2237. "Syria",
  2238. "Taiwan",
  2239. "Tajikistan",
  2240. "Tanzania",
  2241. "Thailand",
  2242. "Togo",
  2243. "Tonga",
  2244. "Trinidad and Tobago",
  2245. "Tunisia",
  2246. "Turkey",
  2247. "Turkmenistan",
  2248. "Tuvalu",
  2249. "Uganda",
  2250. "Ukraine",
  2251. "United Arab Emirates",
  2252. "United Kingdom",
  2253. "United States",
  2254. "Uruguay",
  2255. "Uzbekistan",
  2256. "Vanuatu",
  2257. "Vatican City",
  2258. "Venezuela",
  2259. "Vietnam",
  2260. "Yemen",
  2261. "Zambia",
  2262. "Zimbabwe"
  2263. );
  2264. $country_select = '';
  2265. if ($combo) {
  2266. $country_select = '<select id="country" name="country">';
  2267. $country_select .= '<option value="">--- '.get_lang('SelectOne').' ---</option>';
  2268. foreach ($a_countries as $country) {
  2269. $country_select .= '<option value="'.$country.'">'.$country.'</option>';
  2270. }
  2271. $country_select .= '</select>';
  2272. return $country_select;
  2273. }
  2274. return $a_countries;
  2275. }
  2276. /**
  2277. * Lockis settings that can't be changed in other portals
  2278. */
  2279. function locking_settings()
  2280. {
  2281. $access_url_locked_settings = api_get_locked_settings();
  2282. $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  2283. foreach ($access_url_locked_settings as $setting) {
  2284. $sql = "UPDATE $table SET access_url_locked = 1 WHERE variable = '$setting'";
  2285. Database::query($sql);
  2286. }
  2287. }
  2288. function update_dir_and_files_permissions()
  2289. {
  2290. $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  2291. $permissions_for_new_directories = isset($_SESSION['permissions_for_new_directories']) ? $_SESSION['permissions_for_new_directories'] : 0770;
  2292. $permissions_for_new_files = isset($_SESSION['permissions_for_new_files']) ? $_SESSION['permissions_for_new_files'] : 0660;
  2293. // use decoct() to store as string
  2294. $sql = "UPDATE $table SET selected_value = '0".decoct(
  2295. $permissions_for_new_directories
  2296. )."' WHERE variable = 'permissions_for_new_directories'";
  2297. Database::query($sql);
  2298. $sql = "UPDATE $table SET selected_value = '0".decoct(
  2299. $permissions_for_new_files
  2300. )."' WHERE variable = 'permissions_for_new_files'";
  2301. Database::query($sql);
  2302. unset($_SESSION['permissions_for_new_directories']);
  2303. unset($_SESSION['permissions_for_new_files']);
  2304. }
  2305. function compare_setting_values($current_value, $wanted_value)
  2306. {
  2307. $current_value_string = $current_value;
  2308. $current_value = (float)$current_value;
  2309. $wanted_value = (float)$wanted_value;
  2310. if ($current_value >= $wanted_value) {
  2311. return Display::label($current_value_string, 'success');
  2312. } else {
  2313. return Display::label($current_value_string, 'important');
  2314. }
  2315. }
  2316. function check_course_script_interpretation($course_dir, $course_attempt_name, $file = 'test.php'){
  2317. $output = false;
  2318. //Write in file
  2319. $file_name = $course_dir.'/'.$file;
  2320. $content = '<?php echo "123"; exit;';
  2321. if (is_writable($file_name)) {
  2322. if ($handler = @fopen($file_name, "w")) {
  2323. //write content
  2324. if (fwrite($handler , $content)) {
  2325. $sock_errno = ''; $sock_errmsg = '';
  2326. $url = api_get_path(WEB_COURSE_PATH).'/'.$course_attempt_name.'/'.$file;
  2327. $parsed_url = parse_url($url);
  2328. //$scheme = isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] : ''; //http
  2329. $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
  2330. $path = isset($parsed_url['path']) ? $parsed_url['path'] : '/';
  2331. $port = isset($parsed_url['port']) ? $parsed_url['port'] : '80';
  2332. //Check fsockopen
  2333. if ($fp = @fsockopen(str_replace('http://', '', $url), -1, $sock_errno, $sock_errmsg, 60)) {
  2334. $out = "GET $path HTTP/1.1\r\n";
  2335. $out .= "Host: $host\r\n";
  2336. $out .= "Connection: Close\r\n\r\n";
  2337. fwrite($fp, $out);
  2338. while (!feof($fp)) {
  2339. $result = str_replace("\r\n", '',fgets($fp, 128));
  2340. if (!empty($result) && $result == '123') {
  2341. $output = true;
  2342. }
  2343. }
  2344. fclose($fp);
  2345. //Check allow_url_fopen
  2346. } elseif (ini_get('allow_url_fopen')) {
  2347. if ($fp = @fopen($url, 'r')) {
  2348. while ($result = fgets($fp, 1024)) {
  2349. if (!empty($result) && $result == '123') {
  2350. $output = true;
  2351. }
  2352. }
  2353. fclose($fp);
  2354. }
  2355. // Check if has support for cURL
  2356. } elseif (function_exists('curl_init')) {
  2357. $ch = curl_init();
  2358. curl_setopt($ch, CURLOPT_HEADER, 0);
  2359. curl_setopt($ch, CURLOPT_URL, $url);
  2360. //curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  2361. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2362. $result = curl_exec ($ch);
  2363. if (!empty($result) && $result == '123') {
  2364. $output = true;
  2365. }
  2366. curl_close($ch);
  2367. }
  2368. }
  2369. @fclose($handler);
  2370. }
  2371. }
  2372. return $output;
  2373. }
  2374. /* Executed only before create_course_tables() */
  2375. function drop_course_tables()
  2376. {
  2377. $list = CourseManager::get_course_tables();
  2378. foreach ($list as $table) {
  2379. $sql = "DROP TABLE IF EXISTS ".DB_COURSE_PREFIX.$table;
  2380. Database::query($sql);
  2381. }
  2382. }
  2383. function movingFilesInAppFolder()
  2384. {
  2385. $sysPath = api_get_path(SYS_PATH);
  2386. $moveDirs = array(
  2387. $sysPath.'searchdb' => api_get_path(SYS_PATH_APP).'data/searchdb/',
  2388. $sysPath.'home' => api_get_path(SYS_PATH_APP).'data/home/',
  2389. );
  2390. foreach ($moveDirs as $from => $to) {
  2391. if (is_dir($from)) {
  2392. $copy = "cp -r $from/* $to";
  2393. system($copy);
  2394. }
  2395. }
  2396. }