install.lib.php 166 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873
  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', '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. require_once api_get_path(LIBRARY_PATH).'database.constants.inc.php';
  17. /* COMMON PURPOSE FUNCTIONS */
  18. /**
  19. * This function detects whether the system has been already installed.
  20. * It should be used for prevention from second running the installation
  21. * script and as a result - destroying a production system.
  22. * @return bool The detected result;
  23. * @author Ivan Tcholakov, 2010;
  24. */
  25. function is_already_installed_system() {
  26. global $new_version, $_configuration;
  27. if (empty($new_version)) {
  28. return true; // Must be initialized.
  29. }
  30. $current_config_file = api_get_path(CONFIGURATION_PATH).'configuration.php';
  31. if (!file_exists($current_config_file)) {
  32. return false; // Configuration file does not exist, install the system.
  33. }
  34. require $current_config_file;
  35. $current_version = null;
  36. if (isset($_configuration['dokeos_version'])) {
  37. $current_version = trim($_configuration['dokeos_version']);
  38. }
  39. if (empty($current_version)) {
  40. $current_version = trim($_configuration['system_version']);
  41. }
  42. // If the current version is old, upgrading is assumed, the installer goes ahead.
  43. return empty($current_version) ? false : version_compare($current_version, $new_version, '>=');
  44. }
  45. /**
  46. * This function checks if a php extension exists or not and returns an HTML status string.
  47. *
  48. * @param string Name of the PHP extension to be checked
  49. * @param string Text to show when extension is available (defaults to 'Yes')
  50. * @param string Text to show when extension is available (defaults to 'No')
  51. * @param boolean Whether this extension is optional (in this case show unavailable text in orange rather than red)
  52. * @return string HTML string reporting the status of this extension. Language-aware.
  53. * @author Christophe Gesch??
  54. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  55. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  56. * @version Dokeos 1.8.1, May 2007
  57. */
  58. function check_extension($extension_name, $return_success = 'Yes', $return_failure = 'No', $optional = false) {
  59. if (extension_loaded($extension_name)) {
  60. return Display::label($return_success, 'success');
  61. } else {
  62. if ($optional) {
  63. return Display::label($return_failure, 'warning');
  64. //return '<strong><font color="#ff9900">'.$return_failure.'</font></strong>';
  65. } else {
  66. return Display::label($return_failure, 'important');
  67. //return '<strong><font color="red">'.$return_failure.'</font></strong>';
  68. }
  69. }
  70. }
  71. /**
  72. * This function checks whether a php setting matches the recommended value
  73. *
  74. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  75. * @version Dokeos 1.8, august 2006
  76. */
  77. function check_php_setting($php_setting, $recommended_value, $return_success = false, $return_failure = false) {
  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. return ini_get($val) == '1' ? 'ON' : 'OFF';
  94. }
  95. /**
  96. * This function returns a string "true" or "false" according to the passed parameter.
  97. *
  98. * @param integer $var The variable to present as text
  99. * @return string the string "true" or "false"
  100. * @author Christophe Gesch??
  101. */
  102. function true_false($var) {
  103. return $var ? 'true' : 'false';
  104. }
  105. /**
  106. * Removes memory and time limits as much as possible.
  107. */
  108. function remove_memory_and_time_limits() {
  109. if (function_exists('ini_set')) {
  110. ini_set('memory_limit', -1);
  111. ini_set('max_execution_time', 0);
  112. } else {
  113. error_log('Update-db script: could not change memory and time limits', 0);
  114. }
  115. }
  116. /**
  117. * Detects browser's language.
  118. * @return string Returns a language identificator, i.e. 'english', 'spanish', ...
  119. * @author Ivan Tcholakov, 2010
  120. */
  121. function detect_browser_language() {
  122. static $language_index = array(
  123. 'ar' => 'arabic',
  124. 'ast' => 'asturian',
  125. 'bg' => 'bulgarian',
  126. 'bs' => 'bosnian',
  127. 'ca' => 'catalan',
  128. 'zh' => 'simpl_chinese',
  129. 'zh-tw' => 'trad_chinese',
  130. 'cs' => 'czech',
  131. 'da' => 'danish',
  132. 'prs' => 'dari',
  133. 'de' => 'german',
  134. 'el' => 'greek',
  135. 'en' => 'english',
  136. 'es' => 'spanish',
  137. 'eo' => 'esperanto',
  138. 'eu' => 'basque',
  139. 'fa' => 'persian',
  140. 'fr' => 'french',
  141. 'fur' => 'friulian',
  142. 'gl' => 'galician',
  143. 'ka' => 'georgian',
  144. 'hr' => 'croatian',
  145. 'he' => 'hebrew',
  146. 'hi' => 'hindi',
  147. 'id' => 'indonesian',
  148. 'it' => 'italian',
  149. 'ko' => 'korean',
  150. 'lv' => 'latvian',
  151. 'lt' => 'lithuanian',
  152. 'mk' => 'macedonian',
  153. 'hu' => 'hungarian',
  154. 'ms' => 'malay',
  155. 'nl' => 'dutch',
  156. 'ja' => 'japanese',
  157. 'no' => 'norwegian',
  158. 'oc' => 'occitan',
  159. 'ps' => 'pashto',
  160. 'pl' => 'polish',
  161. 'pt' => 'portuguese',
  162. 'pt-br' => 'brazilian',
  163. 'ro' => 'romanian',
  164. 'qu' => 'quechua_cusco',
  165. 'ru' => 'russian',
  166. 'sk' => 'slovak',
  167. 'sl' => 'slovenian',
  168. 'sr' => 'serbian',
  169. 'fi' => 'finnish',
  170. 'sv' => 'swedish',
  171. 'th' => 'thai',
  172. 'tr' => 'turkish',
  173. 'uk' => 'ukrainian',
  174. 'vi' => 'vietnamese',
  175. 'sw' => 'swahili',
  176. 'yo' => 'yoruba'
  177. );
  178. $system_available_languages = & get_language_folder_list();
  179. $accept_languages = strtolower(str_replace('_', '-', $_SERVER['HTTP_ACCEPT_LANGUAGE']));
  180. foreach ($language_index as $code => $language) {
  181. if (strpos($accept_languages, $code) === 0) {
  182. if (!empty($system_available_languages[$language])) {
  183. return $language;
  184. }
  185. }
  186. }
  187. $user_agent = strtolower(str_replace('_', '-', $_SERVER['HTTP_USER_AGENT']));
  188. foreach ($language_index as $code => $language) {
  189. if (@preg_match("/[\[\( ]{$code}[;,_\-\)]/", $user_agent)) {
  190. if (!empty($system_available_languages[$language])) {
  191. return $language;
  192. }
  193. }
  194. }
  195. return 'english';
  196. }
  197. /* FILESYSTEM RELATED FUNCTIONS */
  198. /**
  199. * This function checks if the given folder is writable
  200. */
  201. function check_writable($folder, $suggestion = false) {
  202. if (is_writable(api_get_path(SYS_CODE_PATH).$folder)) {
  203. return Display::label(get_lang('Writable'), 'success');
  204. } else {
  205. if ($suggestion) {
  206. return Display::label(get_lang('NotWritable'), 'info');
  207. } else {
  208. return Display::label(get_lang('NotWritable'), 'important');
  209. }
  210. }
  211. }
  212. /**
  213. * This function is similar to the core file() function, except that it
  214. * works with line endings in Windows (which is not the case of file())
  215. * @param string File path
  216. * @return array The lines of the file returned as an array
  217. */
  218. function file_to_array($filename) {
  219. if(!is_readable($filename) || is_dir($filename)){
  220. return array();
  221. }
  222. $fp = fopen($filename, 'rb');
  223. $buffer = fread($fp, filesize($filename));
  224. fclose($fp);
  225. return explode('<br />', nl2br($buffer));
  226. }
  227. /**
  228. * We assume this function is called from install scripts that reside inside the install folder.
  229. */
  230. function set_file_folder_permissions() {
  231. @chmod('.', 0755); //set permissions on install dir
  232. @chmod('..', 0755); //set permissions on parent dir of install dir
  233. @chmod('country_data.csv.csv', 0755);
  234. }
  235. /**
  236. * Add's a .htaccess file to the courses directory
  237. * @param string $url_append The path from your webroot to your chamilo root
  238. */
  239. function write_courses_htaccess_file($url_append) {
  240. $content = file_get_contents(dirname(__FILE__).'/'.COURSES_HTACCESS_FILENAME);
  241. $content = str_replace('{CHAMILO_URL_APPEND_PATH}', $url_append, $content);
  242. $fp = @ fopen(api_get_path(SYS_PATH).'courses/.htaccess', 'w');
  243. if ($fp) {
  244. fwrite($fp, $content);
  245. return fclose($fp);
  246. }
  247. return false;
  248. }
  249. /**
  250. * Write the main system config file
  251. * @param string $path Path to the config file
  252. */
  253. function write_system_config_file($path) {
  254. global $dbHostForm;
  255. global $dbUsernameForm;
  256. global $dbPassForm;
  257. global $enableTrackingForm;
  258. global $singleDbForm;
  259. global $dbPrefixForm;
  260. global $dbNameForm;
  261. global $dbStatsForm;
  262. global $dbScormForm;
  263. global $dbUserForm;
  264. global $urlForm;
  265. global $pathForm;
  266. global $urlAppendPath;
  267. global $languageForm;
  268. global $encryptPassForm;
  269. global $installType;
  270. global $updatePath;
  271. global $session_lifetime;
  272. global $new_version;
  273. global $new_version_stable;
  274. $root_sys = api_add_trailing_slash(str_replace('\\', '/', realpath($pathForm)));
  275. $content = file_get_contents(dirname(__FILE__).'/'.SYSTEM_CONFIG_FILENAME);
  276. $config['{DATE_GENERATED}'] = date('r');
  277. $config['{DATABASE_HOST}'] = $dbHostForm;
  278. $config['{DATABASE_USER}'] = $dbUsernameForm;
  279. $config['{DATABASE_PASSWORD}'] = $dbPassForm;
  280. $config['TRACKING_ENABLED'] = true_false($enableTrackingForm);
  281. $config['SINGLE_DATABASE'] = true_false($singleDbForm);
  282. $config['{COURSE_TABLE_PREFIX}'] = ($singleDbForm ? 'crs_' : '');
  283. $config['{DATABASE_GLUE}'] = ($singleDbForm ? '_' : '`.`');
  284. $config['{DATABASE_PREFIX}'] = '';
  285. $config['{DATABASE_MAIN}'] = $dbNameForm;
  286. $config['{DATABASE_STATS}'] = $dbNameForm;
  287. $config['{DATABASE_SCORM}'] = $dbNameForm;
  288. $config['{DATABASE_PERSONAL}'] = $dbNameForm;
  289. $config['{ROOT_WEB}'] = $urlForm;
  290. $config['{ROOT_SYS}'] = $root_sys;
  291. $config['{URL_APPEND_PATH}'] = $urlAppendPath;
  292. $config['{PLATFORM_LANGUAGE}'] = $languageForm;
  293. $config['{SECURITY_KEY}'] = md5(uniqid(rand().time()));
  294. $config['{ENCRYPT_PASSWORD}'] = $encryptPassForm;
  295. $config['SESSION_LIFETIME'] = $session_lifetime;
  296. $config['{NEW_VERSION}'] = $new_version;
  297. $config['NEW_VERSION_STABLE'] = true_false($new_version_stable);
  298. foreach ($config as $key => $value) {
  299. $content = str_replace($key, $value, $content);
  300. }
  301. $fp = @ fopen($path, 'w');
  302. if (!$fp) {
  303. echo '<strong><font color="red">Your script doesn\'t have write access to the config directory</font></strong><br />
  304. <em>('.str_replace('\\', '/', realpath($path)).')</em><br /><br />
  305. You probably do not have write access on Chamilo root directory,
  306. i.e. you should <em>CHMOD 777</em> or <em>755</em> or <em>775</em>.<br /><br />
  307. Your problems can be related on two possible causes:<br />
  308. <ul>
  309. <li>Permission problems.<br />Try initially with <em>chmod -R 777</em> and increase restrictions gradually.</li>
  310. <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>
  311. </ul>
  312. <a href="http://forum.chamilo.org/" target="_blank">Read about this problem in Support Forum</a><br /><br />
  313. Please go back to step 5.
  314. <p><input type="submit" name="step5" value="&lt; Back" /></p>
  315. </td></tr></table></form></body></html>';
  316. exit;
  317. }
  318. fwrite($fp, $content);
  319. fclose($fp);
  320. }
  321. /**
  322. * Returns a list of language directories.
  323. */
  324. function & get_language_folder_list() {
  325. static $result;
  326. if (!is_array($result)) {
  327. $result = array();
  328. $exceptions = array('.', '..', 'CVS', '.svn');
  329. $search = array('_latin', '_unicode', '_corporate', '_org' , '_KM', '_');
  330. $replace_with = array(' (Latin)', ' (unicode)', ' (corporate)', ' (org)', ' (KM)', ' ');
  331. $dirname = api_get_path(SYS_LANG_PATH);
  332. $handle = opendir($dirname);
  333. while ($entries = readdir($handle)) {
  334. if (in_array($entries, $exceptions)) {
  335. continue;
  336. }
  337. if (is_dir($dirname.$entries)) {
  338. $result[$entries] = ucwords(str_replace($search, $replace_with, $entries));
  339. }
  340. }
  341. closedir($handle);
  342. asort($result);
  343. }
  344. return $result;
  345. }
  346. /**
  347. * TODO: my_directory_to_array() - maybe within the main API there is already a suitable function?
  348. */
  349. function my_directory_to_array($directory) {
  350. $array_items = array();
  351. if ($handle = opendir($directory)) {
  352. while (false !== ($file = readdir($handle))) {
  353. if ($file != "." && $file != "..") {
  354. if (is_dir($directory. "/" . $file)) {
  355. $array_items = array_merge($array_items, my_directory_to_array($directory. '/' . $file));
  356. $file = $directory . "/" . $file;
  357. $array_items[] = preg_replace("/\/\//si", '/', $file);
  358. }
  359. }
  360. }
  361. closedir($handle);
  362. }
  363. return $array_items;
  364. }
  365. /**
  366. * This function returns the value of a parameter from the configuration file
  367. *
  368. * WARNING - this function relies heavily on global variables $updateFromConfigFile
  369. * and $configFile, and also changes these globals. This can be rewritten.
  370. *
  371. * @param string $param the parameter of which the value is returned
  372. * @param string If we want to give the path rather than take it from POST
  373. * @return string the value of the parameter
  374. * @author Olivier Brouckaert
  375. * @author Reworked by Ivan Tcholakov, 2010
  376. */
  377. function get_config_param($param, $updatePath = '') {
  378. global $configFile, $updateFromConfigFile;
  379. // Look if we already have the queried parameter.
  380. if (is_array($configFile) && isset($configFile[$param])) {
  381. return $configFile[$param];
  382. }
  383. if (empty($updatePath) && !empty($_POST['updatePath'])) {
  384. $updatePath = $_POST['updatePath'];
  385. }
  386. if (empty($updatePath)) {
  387. $updatePath = api_get_path(SYS_PATH);
  388. }
  389. $updatePath = api_add_trailing_slash(str_replace('\\', '/', realpath($updatePath)));
  390. $updateFromInstalledVersionFile = '';
  391. if (empty($updateFromConfigFile)) {
  392. // If update from previous install was requested,
  393. // try to recover old config file from dokeos 1.8.x.
  394. if (file_exists($updatePath.'main/inc/conf/configuration.php')) {
  395. $updateFromConfigFile = 'main/inc/conf/configuration.php';
  396. } elseif (file_exists($updatePath.'claroline/inc/conf/claro_main.conf.php')) {
  397. $updateFromConfigFile = 'claroline/inc/conf/claro_main.conf.php';
  398. } else {
  399. // Give up recovering.
  400. //error_log('Chamilo Notice: Could not find previous config file at '.$updatePath.'main/inc/conf/configuration.php nor at '.$updatePath.'claroline/inc/conf/claro_main.conf.php in get_config_param(). Will start new config (in '.__FILE__.', line '.__LINE__.')', 0);
  401. return null;
  402. }
  403. }
  404. if (file_exists($updatePath.$updateFromConfigFile) && !is_dir($updatePath.$updateFromConfigFile)) {
  405. // The parameter was not found among the global variables, so look into the old configuration file.
  406. // Make sure the installedVersion file is read first so it is overwritten
  407. // by the config file if the config file contains the version (from 1.8.4).
  408. $config_data_2 = array();
  409. if (file_exists($updatePath.$updateFromInstalledVersionFile)) {
  410. $config_data_2 = file_to_array($updatePath.$updateFromInstalledVersionFile);
  411. }
  412. $configFile = array();
  413. $config_data = file_to_array($updatePath.$updateFromConfigFile);
  414. $config_data = array_merge($config_data, $config_data_2);
  415. $val = '';
  416. // Parse the configuration file, statement by statement (line by line, actually).
  417. foreach ($config_data as $php_statement) {
  418. if (strpos($php_statement, '=') !== false) {
  419. // Variable assignment statement have been detected (probably).
  420. // It is expected to be as follows:
  421. // $variable = 'some_value'; // A comment that is not mandatory.
  422. // Split the statement into its left and right sides.
  423. $php_statement = explode('=', $php_statement);
  424. $variable = trim($php_statement[0]);
  425. $value = $php_statement[1];
  426. if (substr($variable, 0, 1) == '$') {
  427. // We have for sure a php variable assignment detected.
  428. // On the left side: Retrieve the pure variable's name
  429. $variable = trim(str_replace('$', '', $variable));
  430. // On the right side: Remove the comment, if it exists.
  431. list($value) = explode(' //', $value);
  432. // Remove extra whitespace, if any. Remove the trailing semicolon (;).
  433. $value = substr(trim($value), 0, -1);
  434. // Remove surroundig quotes, restore escaped quotes.
  435. $value = str_replace('\"', '"', preg_replace('/^"|"$/', '', $value));
  436. $value = str_replace('\'', '"', preg_replace('/^\'|\'$/', '', $value));
  437. if (strtolower($value) == 'true') {
  438. // A boolean true value have been recognized.
  439. $value = 1;
  440. } elseif (strtolower($value) == 'false') {
  441. // A boolean false value have been recognized.
  442. $value = 0;
  443. } else {
  444. // Probably we have a string value, but also we have to check
  445. // possible string concatenations that may include string values
  446. // and other configuration variables. I this case we have to
  447. // get the calculated result of the concatenation.
  448. $implode_string = ' ';
  449. if (!strstr($value, '." ".') && strstr($value, '.$')) {
  450. // Yes, there is concatenation, insert a special separator string.
  451. $value = str_replace('.$', '." ".$', $value);
  452. $implode_string = '';
  453. }
  454. // Split the concatenated values, if they are more than one.
  455. $sub_strings = explode('." ".', $value);
  456. // Seek for variables and retrieve their values.
  457. foreach ($sub_strings as $key => & $sub_string) {
  458. if (preg_match('/^\$[a-zA-Z_][a-zA-Z0-9_]*$/', $sub_string)) {
  459. // A variable has been detected, read it by recursive call.
  460. $sub_string = get_config_param(str_replace('$', '', $sub_string));
  461. }
  462. }
  463. // Concatenate everything into the final, the calculated string value.
  464. $value = implode($implode_string, $sub_strings);
  465. }
  466. // Cache the result value.
  467. $configFile[$variable] = $value;
  468. $a = explode("'", $variable);
  469. $key_tmp = isset($a[1]) ? $a[1] : null;
  470. if ($key_tmp == $param) {
  471. $val = $value;
  472. }
  473. }
  474. }
  475. }
  476. }
  477. if($param == 'dbGlu' && empty($val)){
  478. return '`.`';
  479. }
  480. //Special treatment for dokeos_version parameter due to Dokeos 1.8.3 have the dokeos_version in the main/inc/installedVersion.inc.php file
  481. if ($param == 'dokeos_version') {
  482. //dokeos_version from configuration.php if empty
  483. $dokeos_version = $val;
  484. if (empty($dokeos_version)) {
  485. //checking the dokeos_version value exists in main/inc/installedVersion.inc.php
  486. if (file_exists($updatePath.'main/inc/installedVersion.inc.php')) {
  487. $updateFromInstalledVersionFile = $updatePath.'main/inc/installedVersion.inc.php';
  488. require ($updateFromInstalledVersionFile); //there are only 2 variables here: $stable & $dokeos_version
  489. $stable = false;
  490. }
  491. }
  492. return $dokeos_version;
  493. } else {
  494. if (file_exists($updatePath.$updateFromConfigFile)) {
  495. return $val;
  496. } else {
  497. error_log('Config array could not be found in get_config_param()', 0);
  498. return null;
  499. }
  500. }
  501. }
  502. /* DATABASE RELATED FUNCTIONS */
  503. /**
  504. * Gets a configuration parameter from the database. Returns returns null on failure.
  505. * @param string DB Host
  506. * @param string DB login
  507. * @param string DB pass
  508. * @param string DB name
  509. * @param string Name of param we want
  510. * @return mixed The parameter value or null if not found
  511. */
  512. function get_config_param_from_db($host, $login, $pass, $db_name, $param = '') {
  513. Database::connect(array('server' => $host, 'username' => $login, 'password' => $pass));
  514. Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
  515. Database::select_db($db_name);
  516. if (($res = Database::query("SELECT * FROM settings_current WHERE variable = '$param'")) !== false) {
  517. if (Database::num_rows($res) > 0) {
  518. $row = Database::fetch_array($res);
  519. return $row['selected_value'];
  520. }
  521. }
  522. return null;
  523. }
  524. /**
  525. * Connects to the database server.
  526. */
  527. function database_server_connect() {
  528. global $dbHostForm, $dbUsernameForm, $dbPassForm;
  529. if (($res = @Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm))) === false) {
  530. $no = Database::errno();
  531. $msg = Database::error();
  532. echo '<hr />#'.$no.': '.$msg.'<hr />';
  533. echo get_lang('DBServerDoesntWorkOrLoginPassIsWrong').'.<br /><br />'.
  534. get_lang('PleaseCheckTheseValues').' :<br /><br />'.
  535. '<strong>'.get_lang('DBHost').'</strong> : '.$dbHostForm.'<br />'.
  536. '<strong>'.get_lang('DBLogin').'</strong> : '.$dbUsernameForm.'<br />'.
  537. '<strong>'.get_lang('DBPassword').'</strong> : '.$dbPassForm.'<br /><br />'.
  538. get_lang('PleaseGoBackToStep').' '. (defined('SYSTEM_INSTALLATION') ? '3' : '1').'.'.
  539. '<p><button type="submit" class="back" name="step'. (defined('SYSTEM_INSTALLATION') ? '3' : '1').'" value="&lt; '.get_lang('Back').'">'.get_lang('Back').'</button></p>'.
  540. '</td></tr></table></form></body></html>';
  541. exit ();
  542. }
  543. @Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
  544. }
  545. /**
  546. * Database exists for the MYSQL user
  547. * @param type $database_name
  548. * @return boolean
  549. */
  550. function database_exists($database_name) {
  551. if (empty($database_name)) {
  552. return false;
  553. }
  554. $select_database = @Database::select_db($database_name);
  555. $show_database = false;
  556. $sql = "SHOW DATABASES LIKE '".addslashes($database_name)."'";
  557. $result = @Database::query($sql);
  558. if (Database::num_rows($result)) {
  559. $show_database = true;
  560. }
  561. return $select_database || $show_database;
  562. }
  563. /**
  564. * In step 3. Tests establishing connection to the database server.
  565. * If it's a single database environment the function checks if the database exist.
  566. * If the database doesn't exist we check the creation permissions.
  567. *
  568. * @return int 1 when there is no problem;
  569. * 0 when a new database is impossible to be created, then the single/multiple database configuration is impossible too
  570. * -1 when there is no connection established.
  571. */
  572. function test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm, $dbNameForm) {
  573. $dbConnect = -1;
  574. //Checking user credentials
  575. if (@Database::connect(array('server' => $dbHostForm, 'username' => $dbUsernameForm, 'password' => $dbPassForm)) !== false) {
  576. $dbConnect = 1;
  577. } else {
  578. $dbConnect = -1;
  579. }
  580. 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.
  581. }
  582. /**
  583. * Fills the countries table with a list of countries.
  584. */
  585. function fill_track_countries_table($track_countries_table) {
  586. $file_path = dirname(__FILE__).'/'.COUNTRY_DATA_FILENAME;
  587. $countries = file($file_path);
  588. $add_country_sql = "INSERT INTO $track_countries_table (id, code, country, counter) VALUES ";
  589. foreach ($countries as $line) {
  590. $elems = explode(',',$line);
  591. $add_country_sql .= '('.intval($elems[0]).',\''.Database::escape_string($elems[1]).'\',\''.Database::escape_string($elems[2]).'\','.intval($elems[3]).'),';
  592. }
  593. $add_country_sql = substr($add_country_sql,0,-1);
  594. //$add_country_sql = "LOAD DATA INFILE '".Database::escape_string($file_path)."' INTO TABLE $track_countries_table FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\'';";
  595. @ Database::query($add_country_sql);
  596. }
  597. /**
  598. * Creates the structure of the main database and fills it
  599. * with data. Placeholder symbols in the main database file
  600. * have to be replaced by the settings entered by the user during installation.
  601. *
  602. * @param array $installation_settings list of settings entered by the user
  603. * @param string optional path about the script for database
  604. * @return void
  605. */
  606. function load_main_database($installation_settings, $db_script = '') {
  607. if (!empty($db_script)) {
  608. if (file_exists($db_script)) {
  609. $sql_text = file_get_contents($db_script);
  610. }
  611. } else {
  612. $db_script = api_get_path(SYS_CODE_PATH).'install/'.SYSTEM_MAIN_DATABASE_FILE;
  613. if (file_exists($db_script)) {
  614. $sql_text = file_get_contents($db_script);
  615. }
  616. }
  617. //replace symbolic parameters with user-specified values
  618. foreach ($installation_settings as $key => $value) {
  619. $sql_text = str_replace($key, Database::escape_string($value), $sql_text);
  620. }
  621. parse_sql_queries($sql_text);
  622. }
  623. /**
  624. * Creates the structure of the stats database
  625. * @param string Name of the file containing the SQL script inside the install directory
  626. */
  627. function load_database_script($db_script) {
  628. $db_script = api_get_path(SYS_CODE_PATH).'install/'.$db_script;
  629. if (file_exists($db_script)) {
  630. $sql_text = file_get_contents($db_script);
  631. }
  632. parse_sql_queries($sql_text);
  633. }
  634. function parse_sql_queries($sql_text) {
  635. //split in array of sql strings
  636. $sql_instructions = array();
  637. split_sql_file($sql_instructions, $sql_text);
  638. //execute the sql instructions
  639. $count = count($sql_instructions);
  640. for ($i = 0; $i < $count; $i++) {
  641. $this_sql_query = $sql_instructions[$i]['query'];
  642. Database::query($this_sql_query);
  643. //UTF8 fix see #5678
  644. if (strpos(strtolower($this_sql_query), 'create table') === false) {
  645. Database::query($this_sql_query);
  646. } else {
  647. //$this_sql_query .= substr($this_sql_query, strlen($this_sql_query), strlen($this_sql_query)-1);
  648. $this_sql_query .= ' DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci ';
  649. Database::query($this_sql_query);
  650. }
  651. }
  652. }
  653. /**
  654. * Function copied and adapted from phpMyAdmin 2.6.0 PMA_splitSqlFile (also GNU GPL)
  655. * Removes comment lines and splits up large sql files into individual queries
  656. * Last revision: September 23, 2001 - gandon
  657. * @param array the splitted sql commands
  658. * @param string the sql commands
  659. * @param integer the MySQL release number (because certains php3 versions
  660. * can't get the value of a constant from within a function)
  661. * @return boolean always true
  662. */
  663. function split_sql_file(&$ret, $sql) {
  664. // do not trim, see bug #1030644
  665. //$sql = trim($sql);
  666. $sql = rtrim($sql, "\n\r");
  667. $sql_len = strlen($sql);
  668. $char = '';
  669. $string_start = '';
  670. $in_string = false;
  671. $nothing = true;
  672. $time0 = time();
  673. for ($i = 0; $i < $sql_len; ++$i) {
  674. $char = $sql[$i];
  675. // We are in a string, check for not escaped end of strings except for
  676. // backquotes that can't be escaped
  677. if ($in_string) {
  678. for (;;) {
  679. $i = strpos($sql, $string_start, $i);
  680. // No end of string found -> add the current substring to the
  681. // returned array
  682. if (!$i) {
  683. $ret[] = $sql;
  684. return true;
  685. }
  686. // Backquotes or no backslashes before quotes: it's indeed the
  687. // end of the string -> exit the loop
  688. elseif ($string_start == '`' || $sql[$i - 1] != '\\') {
  689. $string_start = '';
  690. $in_string = false;
  691. break;
  692. }
  693. // one or more Backslashes before the presumed end of string...
  694. else {
  695. // ... first checks for escaped backslashes
  696. $j = 2;
  697. $escaped_backslash = false;
  698. while ($i - $j > 0 && $sql[$i - $j] == '\\') {
  699. $escaped_backslash = !$escaped_backslash;
  700. $j++;
  701. }
  702. // ... if escaped backslashes: it's really the end of the
  703. // string -> exit the loop
  704. if ($escaped_backslash) {
  705. $string_start = '';
  706. $in_string = false;
  707. break;
  708. }
  709. // ... else loop
  710. else {
  711. $i++;
  712. }
  713. } // end if...elseif...else
  714. } // end for
  715. } // end if (in string)
  716. // lets skip comments (/*, -- and #)
  717. elseif (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) {
  718. $i = strpos($sql, $char == '/' ? '*/' : "\n", $i);
  719. // didn't we hit end of string?
  720. if ($i === false) {
  721. break;
  722. }
  723. if ($char == '/') $i++;
  724. }
  725. // We are not in a string, first check for delimiter...
  726. elseif ($char == ';') {
  727. // if delimiter found, add the parsed part to the returned array
  728. $ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing);
  729. $nothing = true;
  730. $sql = ltrim(substr($sql, min($i + 1, $sql_len)));
  731. $sql_len = strlen($sql);
  732. if ($sql_len) {
  733. $i = -1;
  734. } else {
  735. // The submited statement(s) end(s) here
  736. return true;
  737. }
  738. } // end elseif (is delimiter)
  739. // ... then check for start of a string,...
  740. elseif (($char == '"') || ($char == '\'') || ($char == '`')) {
  741. $in_string = true;
  742. $nothing = false;
  743. $string_start = $char;
  744. } // end elseif (is start of string)
  745. elseif ($nothing) {
  746. $nothing = false;
  747. }
  748. // loic1: send a fake header each 30 sec. to bypass browser timeout
  749. $time1 = time();
  750. if ($time1 >= $time0 + 30) {
  751. $time0 = $time1;
  752. header('X-pmaPing: Pong');
  753. } // end if
  754. } // end for
  755. // add any rest to the returned array
  756. if (!empty($sql) && preg_match('@[^[:space:]]+@', $sql)) {
  757. $ret[] = array('query' => $sql, 'empty' => $nothing);
  758. }
  759. return true;
  760. } // end of the 'split_sql_file()' function
  761. /**
  762. * Get an SQL file's contents
  763. *
  764. * This function bases its parsing on the pre-set format of the specific SQL files in
  765. * the install/upgrade procedure:
  766. * Lines starting with "--" are comments (but need to be taken into account as they also hold sections names)
  767. * Other lines are considered to be one-line-per-query lines (this is checked quickly by this function)
  768. * @param string File to parse (in the current directory)
  769. * @param string Section to return
  770. * @param boolean Print (true) or hide (false) error texts when they occur
  771. */
  772. function get_sql_file_contents($file, $section, $print_errors = true) {
  773. //check given parameters
  774. if (empty($file)) {
  775. $error = "Missing name of file to parse in get_sql_file_contents()";
  776. if ($print_errors) echo $error;
  777. return false;
  778. }
  779. if (!in_array($section, array('main', 'user', 'stats', 'scorm', 'course'))) {
  780. $error = "Section '$section' is not authorized in get_sql_file_contents()";
  781. if ($print_errors) echo $error;
  782. return false;
  783. }
  784. $filepath = getcwd().'/'.$file;
  785. if (!is_file($filepath) or !is_readable($filepath)) {
  786. $error = "File $filepath not found or not readable in get_sql_file_contents()";
  787. if ($print_errors) echo $error;
  788. return false;
  789. }
  790. //read the file in an array
  791. // Empty lines should not be executed as SQL statements, because errors occur, see Task #2167.
  792. $file_contents = file($filepath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  793. if (!is_array($file_contents) or count($file_contents) < 1) {
  794. $error = "File $filepath looks empty in get_sql_file_contents()";
  795. if ($print_errors) echo $error;
  796. return false;
  797. }
  798. //prepare the resulting array
  799. $section_contents = array();
  800. $record = false;
  801. foreach ($file_contents as $index => $line) {
  802. if (substr($line, 0, 2) == '--') {
  803. //This is a comment. Check if section name, otherwise ignore
  804. $result = array();
  805. if (preg_match('/^-- xx([A-Z]*)xx/', $line, $result)) { //we got a section name here
  806. if ($result[1] == strtoupper($section)) {
  807. //we have the section we are looking for, start recording
  808. $record = true;
  809. } else {
  810. //we have another section's header. If we were recording, stop now and exit loop
  811. if ($record) {
  812. break;
  813. }
  814. $record = false;
  815. }
  816. }
  817. } else {
  818. if ($record) {
  819. if (!empty($line)) {
  820. $section_contents[] = $line;
  821. }
  822. }
  823. }
  824. }
  825. //now we have our section's SQL statements group ready, return
  826. return $section_contents;
  827. }
  828. /**
  829. * Adds a new document to the database - specific to version 1.8.0
  830. *
  831. * @param array $_course
  832. * @param string $path
  833. * @param string $filetype
  834. * @param int $filesize
  835. * @param string $title
  836. * @return id if inserted document
  837. */
  838. function add_document_180($_course, $path, $filetype, $filesize, $title, $comment = null) {
  839. $table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']);
  840. $sql = "INSERT INTO $table_document
  841. (`path`,`filetype`,`size`,`title`, `comment`)
  842. VALUES ('$path','$filetype','$filesize','".
  843. Database::escape_string($title)."', '$comment')";
  844. if (Database::query($sql)) {
  845. //display_message("Added to database (id ".Database::insert_id().")!");
  846. return Database::insert_id();
  847. } else {
  848. //display_error("The uploaded file could not be added to the database (".Database::error().")!");
  849. return false;
  850. }
  851. }
  852. /* DISPLAY FUNCTIONS */
  853. /**
  854. * This function prints class=active_step $current_step=$param
  855. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  856. */
  857. function step_active($param) {
  858. global $current_step;
  859. if ($param == $current_step) {
  860. echo 'class="current_step" ';
  861. }
  862. }
  863. /**
  864. * This function displays the Step X of Y -
  865. * @return string String that says 'Step X of Y' with the right values
  866. */
  867. function display_step_sequence() {
  868. global $current_step;
  869. return get_lang('Step'.$current_step).' &ndash; ';
  870. }
  871. /**
  872. * Displays a drop down box for selection the preferred language.
  873. */
  874. function display_language_selection_box($name = 'language_list', $default_language = 'english') {
  875. // Reading language list.
  876. $language_list = get_language_folder_list();
  877. /*
  878. // Reduction of the number of languages shown. Enable this fragment of code for customization purposes.
  879. // Modify the language list according to your preference. Don't exclude the 'english' item.
  880. $language_to_display = array('asturian', 'bulgarian', 'english', 'italian', 'french', 'slovenian', 'slovenian_unicode', 'spanish');
  881. foreach ($language_list as $key => & $value) {
  882. if (!in_array($key, $language_to_display)) {
  883. unset($language_list[$key]);
  884. }
  885. }
  886. */
  887. // Sanity checks due to the possibility for customizations.
  888. if (!is_array($language_list) || empty($language_list)) {
  889. $language_list = array('english' => 'English');
  890. }
  891. // Sorting again, if it is necessary.
  892. //asort($language_list);
  893. // More sanity checks.
  894. if (!array_key_exists($default_language, $language_list)) {
  895. if (array_key_exists('english', $language_list)) {
  896. $default_language = 'english';
  897. } else {
  898. $language_keys = array_keys($language_list);
  899. $default_language = $language_keys[0];
  900. }
  901. }
  902. // Displaying the box.
  903. echo "\t\t<select name=\"$name\">\n";
  904. foreach ($language_list as $key => $value) {
  905. if ($key == $default_language) {
  906. $option_end = ' selected="selected">';
  907. } else {
  908. $option_end = '>';
  909. }
  910. echo "\t\t\t<option value=\"$key\"$option_end";
  911. echo $value;
  912. echo "</option>\n";
  913. }
  914. echo "\t\t</select>\n";
  915. }
  916. /**
  917. * This function displays a language dropdown box so that the installatioin
  918. * can be done in the language of the user
  919. */
  920. function display_language_selection() { ?>
  921. <h2><?php get_lang('WelcomeToTheDokeosInstaller'); ?></h2>
  922. <div class="RequirementHeading">
  923. <h2><?php echo display_step_sequence(); ?><?php echo get_lang('InstallationLanguage'); ?></h2>
  924. <p><?php echo get_lang('PleaseSelectInstallationProcessLanguage'); ?>:</p>
  925. <form id="lang_form" method="post" action="<?php echo api_get_self(); ?>">
  926. <?php display_language_selection_box('language_list', api_get_interface_language()); ?>
  927. <button type="submit" name="step1" class="btn next" autofocus="autofocus" value="<?php echo get_lang('Next'); ?>"><?php echo get_lang('Next'); ?></button>
  928. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  929. </form>
  930. </div>
  931. <?php
  932. }
  933. /**
  934. * This function displays the requirements for installing Chamilo.
  935. *
  936. * @param string $installType
  937. * @param boolean $badUpdatePath
  938. * @param string The updatePath given (if given)
  939. * @param array $update_from_version_8 The different subversions from version 1.8
  940. * @param array $update_from_version_6 The different subversions from version 1.6
  941. *
  942. * @author unknow
  943. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  944. */
  945. function display_requirements($installType, $badUpdatePath, $updatePath = '', $update_from_version_8 = array(), $update_from_version_6 = array()) {
  946. global $_setting;
  947. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('Requirements')."</h2></div>";
  948. echo '<div class="RequirementText">';
  949. echo '<strong>'.get_lang('ReadThoroughly').'</strong><br />';
  950. echo get_lang('MoreDetails').' <a href="../../documentation/installation_guide.html" target="_blank">'.get_lang('ReadTheInstallGuide').'</a>.<br />'."\n";
  951. if ($installType == 'update') {
  952. echo get_lang('IfYouPlanToUpgradeFromOlderVersionYouMightWantToHaveAlookAtTheChangelog').'<br />';
  953. }
  954. echo '</div>';
  955. // SERVER REQUIREMENTS
  956. echo '<div class="RequirementHeading"><h2>'.get_lang('ServerRequirements').'</h2>';
  957. echo '<div class="RequirementText">'.get_lang('ServerRequirementsInfo').'</div>';
  958. echo '<div class="RequirementContent">';
  959. echo '<table class="table">
  960. <tr>
  961. <td class="requirements-item">'.get_lang('PHPVersion').' >= '.REQUIRED_PHP_VERSION.'</td>
  962. <td class="requirements-value">';
  963. if (phpversion() < REQUIRED_PHP_VERSION) {
  964. echo '<strong><font color="red">'.get_lang('PHPVersionError').'</font></strong>';
  965. } else {
  966. echo '<strong><font color="green">'.get_lang('PHPVersionOK'). ' '.phpversion().'</font></strong>';
  967. }
  968. echo '</td>
  969. </tr>
  970. <tr>
  971. <td class="requirements-item"><a href="http://php.net/manual/en/book.session.php" target="_blank">Session</a> '.get_lang('support').'</td>
  972. <td class="requirements-value">'.check_extension('session', get_lang('Yes'), get_lang('ExtensionSessionsNotAvailable')).'</td>
  973. </tr>
  974. <tr>
  975. <td class="requirements-item"><a href="http://php.net/manual/en/book.mysql.php" target="_blank">MySQL</a> '.get_lang('support').'</td>
  976. <td class="requirements-value">'.check_extension('mysql', get_lang('Yes'), get_lang('ExtensionMySQLNotAvailable')).'</td>
  977. </tr>
  978. <tr>
  979. <td class="requirements-item"><a href="http://php.net/manual/en/book.zlib.php" target="_blank">Zlib</a> '.get_lang('support').'</td>
  980. <td class="requirements-value">'.check_extension('zlib', get_lang('Yes'), get_lang('ExtensionZlibNotAvailable')).'</td>
  981. </tr>
  982. <tr>
  983. <td class="requirements-item"><a href="http://php.net/manual/en/book.pcre.php" target="_blank">Perl-compatible regular expressions</a> '.get_lang('support').'</td>
  984. <td class="requirements-value">'.check_extension('pcre', get_lang('Yes'), get_lang('ExtensionPCRENotAvailable')).'</td>
  985. </tr>
  986. <tr>
  987. <td class="requirements-item"><a href="http://php.net/manual/en/book.xml.php" target="_blank">XML</a> '.get_lang('support').'</td>
  988. <td class="requirements-value">'.check_extension('xml', get_lang('Yes'), get_lang('No')).'</td>
  989. </tr>
  990. <tr>
  991. <td class="requirements-item"><a href="http://php.net/manual/en/book.mbstring.php" target="_blank">Multibyte string</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  992. <td class="requirements-value">'.check_extension('mbstring', get_lang('Yes'), get_lang('ExtensionMBStringNotAvailable'), true).'</td>
  993. </tr>
  994. <tr>
  995. <td class="requirements-item"><a href="http://php.net/manual/en/book.iconv.php" target="_blank">Iconv</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  996. <td class="requirements-value">'.check_extension('iconv', get_lang('Yes'), get_lang('No'), true).'</td>
  997. </tr>
  998. <tr>
  999. <td class="requirements-item"><a href="http://php.net/manual/en/book.intl.php" target="_blank">Internationalization</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  1000. <td class="requirements-value">'.check_extension('intl', get_lang('Yes'), get_lang('No'), true).'</td>
  1001. </tr>
  1002. <tr>
  1003. <td class="requirements-item"><a href="http://php.net/manual/en/book.image.php" target="_blank">GD</a> '.get_lang('support').'</td>
  1004. <td class="requirements-value">'.check_extension('gd', get_lang('Yes'), get_lang('ExtensionGDNotAvailable')).'</td>
  1005. </tr>
  1006. <tr>
  1007. <td class="requirements-item"><a href="http://php.net/manual/en/book.json.php" target="_blank">JSON</a> '.get_lang('support').'</td>
  1008. <td class="requirements-value">'.check_extension('json', get_lang('Yes'), get_lang('No')).'</td>
  1009. </tr>
  1010. <tr>
  1011. <td class="requirements-item"><a href="http://php.net/manual/en/book.ldap.php" target="_blank">LDAP</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  1012. <td class="requirements-value">'.check_extension('ldap', get_lang('Yes'), get_lang('ExtensionLDAPNotAvailable'), true).'</td>
  1013. </tr>
  1014. <tr>
  1015. <td class="requirements-item"><a href="http://xapian.org/" target="_blank">Xapian</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  1016. <td class="requirements-value">'.check_extension('xapian', get_lang('Yes'), get_lang('No'), true).'</td>
  1017. </tr>
  1018. <tr>
  1019. <td class="requirements-item"><a href="http://php.net/manual/en/book.curl.php" target="_blank">cURL</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
  1020. <td class="requirements-value">'.check_extension('curl', get_lang('Yes'), get_lang('No'), true).'</td>
  1021. </tr>
  1022. </table>';
  1023. echo ' </div>';
  1024. echo '</div>';
  1025. // RECOMMENDED SETTINGS
  1026. // Note: these are the settings for Joomla, does this also apply for Chamilo?
  1027. // Note: also add upload_max_filesize here so that large uploads are possible
  1028. echo '<div class="RequirementHeading"><h2>'.get_lang('RecommendedSettings').'</h2>';
  1029. echo '<div class="RequirementText">'.get_lang('RecommendedSettingsInfo').'</div>';
  1030. echo '<div class="RequirementContent">';
  1031. echo '<table class="table">
  1032. <tr>
  1033. <th>'.get_lang('Setting').'</th>
  1034. <th>'.get_lang('Recommended').'</th>
  1035. <th>'.get_lang('Actual').'</th>
  1036. </tr>
  1037. <tr>
  1038. <td class="requirements-item"><a href="http://php.net/manual/features.safe-mode.php">Safe Mode</a></td>
  1039. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1040. <td class="requirements-value">'.check_php_setting('safe_mode','OFF').'</td>
  1041. </tr>
  1042. <tr>
  1043. <td class="requirements-item"><a href="http://php.net/manual/ref.errorfunc.php#ini.display-errors">Display Errors</a></td>
  1044. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1045. <td class="requirements-value">'.check_php_setting('display_errors','OFF').'</td>
  1046. </tr>
  1047. <tr>
  1048. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.file-uploads">File Uploads</a></td>
  1049. <td class="requirements-recommended">'.Display::label('ON', 'success').'</td>
  1050. <td class="requirements-value">'.check_php_setting('file_uploads','ON').'</td>
  1051. </tr>
  1052. <tr>
  1053. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-gpc">Magic Quotes GPC</a></td>
  1054. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1055. <td class="requirements-value">'.check_php_setting('magic_quotes_gpc','OFF').'</td>
  1056. </tr>
  1057. <tr>
  1058. <td class="requirements-item"><a href="http://php.net/manual/ref.info.php#ini.magic-quotes-runtime">Magic Quotes Runtime</a></td>
  1059. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1060. <td class="requirements-value">'.check_php_setting('magic_quotes_runtime','OFF').'</td>
  1061. </tr>
  1062. <tr>
  1063. <td class="requirements-item"><a href="http://php.net/manual/security.globals.php">Register Globals</a></td>
  1064. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1065. <td class="requirements-value">'.check_php_setting('register_globals','OFF').'</td>
  1066. </tr>
  1067. <tr>
  1068. <td class="requirements-item"><a href="http://php.net/manual/ref.session.php#ini.session.auto-start">Session auto start</a></td>
  1069. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1070. <td class="requirements-value">'.check_php_setting('session.auto_start','OFF').'</td>
  1071. </tr>
  1072. <tr>
  1073. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.short-open-tag">Short Open Tag</a></td>
  1074. <td class="requirements-recommended">'.Display::label('OFF', 'success').'</td>
  1075. <td class="requirements-value">'.check_php_setting('short_open_tag','OFF').'</td>
  1076. </tr>
  1077. <tr>
  1078. <td class="requirements-item"><a href="http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-httponly">Cookie HTTP Only</a></td>
  1079. <td class="requirements-recommended">'.Display::label('ON', 'success').'</td>
  1080. <td class="requirements-value">'.check_php_setting('session.cookie_httponly','ON').'</td>
  1081. </tr>
  1082. <tr>
  1083. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.upload-max-filesize">Maximum upload file size</a></td>
  1084. <td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_UPLOAD_MAX_FILESIZE.'M', 'success').'</td>
  1085. <td class="requirements-value">'.compare_setting_values(ini_get('upload_max_filesize'), REQUIRED_MIN_UPLOAD_MAX_FILESIZE).'</td>
  1086. </tr>
  1087. <tr>
  1088. <td class="requirements-item"><a href="http://php.net/manual/ini.core.php#ini.post-max-size">Maximum post size</a></td>
  1089. <td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_POST_MAX_SIZE.'M', 'success').'</td>
  1090. <td class="requirements-value">'.compare_setting_values(ini_get('post_max_size'), REQUIRED_MIN_POST_MAX_SIZE).'</td>
  1091. </tr>
  1092. <tr>
  1093. <td class="requirements-item"><a href="http://www.php.net/manual/en/ini.core.php#ini.memory-limit">Memory Limit</a></td>
  1094. <td class="requirements-recommended">'.Display::label('>= '.REQUIRED_MIN_MEMORY_LIMIT.'M', 'success').'</td>
  1095. <td class="requirements-value">'.compare_setting_values(ini_get('memory_limit'), REQUIRED_MIN_MEMORY_LIMIT).'</td>
  1096. </tr>
  1097. </table>';
  1098. echo ' </div>';
  1099. echo '</div>';
  1100. // DIRECTORY AND FILE PERMISSIONS
  1101. echo '<div class="RequirementHeading"><h2>'.get_lang('DirectoryAndFilePermissions').'</h2>';
  1102. echo '<div class="RequirementText">'.get_lang('DirectoryAndFilePermissionsInfo').'</div>';
  1103. echo '<div class="RequirementContent">';
  1104. $course_attempt_name = '__XxTestxX__';
  1105. $course_dir = api_get_path(SYS_COURSE_PATH).$course_attempt_name;
  1106. //Just in case
  1107. @unlink($course_dir.'/test.txt');
  1108. @rmdir($course_dir);
  1109. $perms_dir = array(0777, 0755, 0775, 0770, 0750, 0700);
  1110. $perms_fil = array(0666, 0644, 0664, 0660, 0640, 0600);
  1111. $course_test_was_created = false;
  1112. $dir_perm_verified = 0777;
  1113. foreach ($perms_dir as $perm) {
  1114. $r = @mkdir($course_dir, $perm);
  1115. if ($r === true) {
  1116. $dir_perm_verified = $perm;
  1117. $course_test_was_created = true;
  1118. break;
  1119. }
  1120. }
  1121. $fil_perm_verified = 0666;
  1122. if (is_dir($course_dir)) {
  1123. foreach ($perms_fil as $perm) {
  1124. $r = @touch($course_dir.'/test.txt',$perm);
  1125. if ($r === true) {
  1126. $fil_perm_verified = $perm;
  1127. break;
  1128. }
  1129. }
  1130. }
  1131. @unlink($course_dir.'/test.txt');
  1132. @rmdir($course_dir);
  1133. $_SESSION['permissions_for_new_directories'] = $_setting['permissions_for_new_directories'] = $dir_perm_verified;
  1134. $_SESSION['permissions_for_new_files'] = $_setting['permissions_for_new_files'] = $fil_perm_verified;
  1135. $dir_perm = Display::label('0'.decoct($dir_perm_verified), 'info');
  1136. $file_perm = Display::label('0'.decoct($fil_perm_verified), 'info');
  1137. $course_test_was_created = $course_test_was_created == true ? Display::label(get_lang('Yes'), 'success') : Display::label(get_lang('No'), 'warning');
  1138. echo '<table class="table">
  1139. <tr>
  1140. <td class="requirements-item">chamilo/main/inc/conf/</td>
  1141. <td class="requirements-value">'.check_writable('inc/conf/').'</td>
  1142. </tr>
  1143. <tr>
  1144. <td class="requirements-item">chamilo/main/upload/users/</td>
  1145. <td class="requirements-value">'.check_writable('upload/users/').'</td>
  1146. </tr>
  1147. <tr>
  1148. <td class="requirements-item">chamilo/main/default_course_document/images/</td>
  1149. <td class="requirements-value">'.check_writable('default_course_document/images/').'</td>
  1150. </tr>
  1151. <tr>
  1152. <td class="requirements-item">chamilo/archive/</td>
  1153. <td class="requirements-value">'.check_writable('../archive/').'</td>
  1154. </tr>
  1155. <tr>
  1156. <td class="requirements-item">chamilo/courses/</td>
  1157. <td class="requirements-value">'.check_writable('../courses/').' </td>
  1158. </tr>
  1159. <tr>
  1160. <td class="requirements-item">'.get_lang('CourseTestWasCreated').'</td>
  1161. <td class="requirements-value">'.$course_test_was_created.' </td>
  1162. </tr>
  1163. <tr>
  1164. <td class="requirements-item">'.get_lang('PermissionsForNewDirs').'</td>
  1165. <td class="requirements-value">'.$dir_perm.' </td>
  1166. </tr>
  1167. <tr>
  1168. <td class="requirements-item">'.get_lang('PermissionsForNewFiles').'</td>
  1169. <td class="requirements-value">'.$file_perm.' </td>
  1170. </tr>
  1171. <tr>
  1172. <td class="requirements-item">chamilo/home/</td>
  1173. <td class="requirements-value">'.check_writable('../home/').'</td>
  1174. </tr>
  1175. <tr>
  1176. <td class="requirements-item">chamilo/main/css/</td>
  1177. <td class="requirements-value">'.check_writable('css/', true).' ('.get_lang('SuggestionOnlyToEnableCSSUploadFeature').')</td>
  1178. </tr>
  1179. <tr>
  1180. <td class="requirements-item">chamilo/main/lang/</td>
  1181. <td class="requirements-value">'.check_writable('lang/', true).' ('.get_lang('SuggestionOnlyToEnableSubLanguageFeature').')</td>
  1182. </tr>'.
  1183. //'<tr>
  1184. // <td class="requirements-item">chamilo/searchdb/</td>
  1185. // <td class="requirements-value">'.check_writable('../searchdb/').'</td>
  1186. //</tr>'.
  1187. //'<tr>
  1188. // <td class="requirements-item">'.session_save_path().'</td>
  1189. // <td class="requirements-value">'.(is_writable(session_save_path())
  1190. // ? '<strong><font color="green">'.get_lang('Writable').'</font></strong>'
  1191. // : '<strong><font color="red">'.get_lang('NotWritable').'</font></strong>').'</td>
  1192. //</tr>'.
  1193. '';
  1194. echo ' </table>';
  1195. echo ' </div>';
  1196. echo '</div>';
  1197. if ($installType == 'update' && (empty($updatePath) || $badUpdatePath)) {
  1198. if ($badUpdatePath) { ?>
  1199. <div class="error-message">
  1200. <?php echo get_lang('Error'); ?>!<br />
  1201. Chamilo <?php echo (isset($_POST['step2_update_6']) ? implode('|', $update_from_version_6) : implode('|', $update_from_version_8)).' '.get_lang('HasNotBeenFoundInThatDir'); ?>.
  1202. </div>
  1203. <?php }
  1204. else {
  1205. echo '<br />';
  1206. }
  1207. ?>
  1208. <table border="0" cellpadding="5" align="center">
  1209. <tr>
  1210. <td><?php echo get_lang('OldVersionRootPath'); ?>:</td>
  1211. <td><input type="text" name="updatePath" size="50" value="<?php echo ($badUpdatePath && !empty($updatePath)) ? htmlentities($updatePath) : api_get_path(SYS_SERVER_ROOT_PATH).'old_version/'; ?>" /></td>
  1212. </tr>
  1213. <tr>
  1214. <td colspan="2" align="center">
  1215. <button type="submit" class="back" name="step1" value="&lt; <?php echo get_lang('Back'); ?>" ><?php echo get_lang('Back'); ?></button>
  1216. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1217. <button type="submit" class="btn next" name="<?php echo (isset($_POST['step2_update_6']) ? 'step2_update_6' : 'step2_update_8'); ?>" value="<?php echo get_lang('Next'); ?> &gt;" ><?php echo get_lang('Next'); ?></button>
  1218. </td>
  1219. </tr>
  1220. </table>
  1221. <?php
  1222. } else {
  1223. $error = false;
  1224. // First, attempt to set writing permissions if we don't have them yet
  1225. $perm = api_get_permissions_for_new_directories();
  1226. $perm_file = api_get_permissions_for_new_files();
  1227. $notwritable = array();
  1228. $curdir = getcwd();
  1229. $checked_writable = api_get_path(CONFIGURATION_PATH);
  1230. if (!is_writable($checked_writable)) {
  1231. $notwritable[] = $checked_writable;
  1232. @chmod($checked_writable, $perm);
  1233. }
  1234. $checked_writable = api_get_path(SYS_CODE_PATH).'upload/users/';
  1235. if (!is_writable($checked_writable)) {
  1236. $notwritable[] = $checked_writable;
  1237. @chmod($checked_writable, $perm);
  1238. }
  1239. $checked_writable = api_get_path(SYS_CODE_PATH).'default_course_document/images/';
  1240. if (!is_writable($checked_writable)) {
  1241. $notwritable[] = $checked_writable;
  1242. @chmod($checked_writable, $perm);
  1243. }
  1244. $checked_writable = api_get_path(SYS_ARCHIVE_PATH);
  1245. if (!is_writable($checked_writable)) {
  1246. $notwritable[] = $checked_writable;
  1247. @chmod($checked_writable, $perm);
  1248. }
  1249. $checked_writable = api_get_path(SYS_COURSE_PATH);
  1250. if (!is_writable($checked_writable)) {
  1251. $notwritable[] = $checked_writable;
  1252. @chmod($checked_writable, $perm);
  1253. }
  1254. if ($course_test_was_created == false) {
  1255. $error = true;
  1256. }
  1257. $checked_writable = api_get_path(SYS_PATH).'home/';
  1258. if (!is_writable($checked_writable)) {
  1259. $notwritable[] = realpath($checked_writable);
  1260. @chmod($checked_writable, $perm);
  1261. }
  1262. $checked_writable = api_get_path(CONFIGURATION_PATH).'configuration.php';
  1263. if (file_exists($checked_writable) && !is_writable($checked_writable)) {
  1264. $notwritable[] = $checked_writable;
  1265. @chmod($checked_writable, $perm_file);
  1266. }
  1267. // Second, if this fails, report an error
  1268. //--> The user would have to adjust the permissions manually
  1269. if (count($notwritable) > 0) {
  1270. $error = true;
  1271. echo '<div class="error-message">';
  1272. echo '<center><h3>'.get_lang('Warning').'</h3></center>';
  1273. printf(get_lang('NoWritePermissionPleaseReadInstallGuide'), '</font>
  1274. <a href="../../documentation/installation_guide.html" target="blank">', '</a> <font color="red">');
  1275. echo '</div>';
  1276. echo '<ul>';
  1277. foreach ($notwritable as $value) {
  1278. echo '<li>'.$value.'</li>';
  1279. }
  1280. echo '</ul>';
  1281. }
  1282. // Check wether a Chamilo configuration file already exists.
  1283. elseif (file_exists(api_get_path(CONFIGURATION_PATH).'configuration.php')) {
  1284. echo '<div class="warning-message"><h4><center>';
  1285. echo get_lang('WarningExistingDokeosInstallationDetected');
  1286. echo '</center></h4></div>';
  1287. }
  1288. // And now display the choice buttons (go back or install)
  1289. ?>
  1290. <p align="center" style="padding-top:15px">
  1291. <button type="submit" name="step1" class="back" onclick="javascript: window.location='index.php'; return false;" value="&lt; <?php echo get_lang('Previous'); ?>" ><?php echo get_lang('Previous'); ?></button>
  1292. <button type="submit" name="step2_install" class="add" value="<?php echo get_lang("NewInstallation"); ?>" <?php if ($error) { echo 'disabled="disabled"'; } ?> ><?php echo get_lang('NewInstallation'); ?></button>
  1293. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1294. <?php
  1295. // Real code
  1296. echo '<button type="submit" class="save" name="step2_update_8" value="Upgrade from Dokeos 1.8.x"';
  1297. if ($error) echo ' disabled="disabled"';
  1298. // Temporary code for alpha version, disabling upgrade
  1299. //echo '<input type="submit" name="step2_update" value="Upgrading is not possible in this beta version"';
  1300. //echo ' disabled="disabled"';
  1301. //end temp code
  1302. echo ' >'.get_lang('UpgradeFromDokeos18x').'</button>';
  1303. echo ' <button type="submit" class="save" name="step2_update_6" value="Upgrade from Dokeos 1.6.x"';
  1304. if ($error) echo ' disabled="disabled"';
  1305. echo ' >'.get_lang('UpgradeFromDokeos16x').'</button>';
  1306. echo '</p>';
  1307. }
  1308. }
  1309. /**
  1310. * Displays the license (GNU GPL) as step 2, with
  1311. * - an "I accept" button named step3 to proceed to step 3;
  1312. * - a "Back" button named step1 to go back to the first step.
  1313. */
  1314. function display_license_agreement() {
  1315. echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('Licence').'</h2>';
  1316. echo '<p>'.get_lang('DokeosLicenseInfo').'</p>';
  1317. echo '<p><a href="../../documentation/license.html" target="_blank">'.get_lang('PrintVers').'</a></p>';
  1318. echo '</div>';
  1319. ?>
  1320. <table>
  1321. <tr><td>
  1322. <p style="font-size:90%">
  1323. <textarea cols="90" rows="7" class="span6">
  1324. <?php echo api_htmlentities(@file_get_contents(api_get_path(SYS_PATH).'documentation/license.txt')); ?>
  1325. </textarea></p>
  1326. </td>
  1327. </tr>
  1328. <tr><td>
  1329. <label class="checkbox">
  1330. <input type="checkbox" name="accept" id="accept_licence" value="1" autofocus="autofocus" />
  1331. <?php echo get_lang('IAccept'); ?>
  1332. </label>
  1333. </td>
  1334. </tr>
  1335. <tr><td><p style="color:#666"><br /><?php echo get_lang('DokeosArtLicense'); ?></p></td></tr>
  1336. <tr>
  1337. <td>
  1338. <table width="100%">
  1339. <tr>
  1340. <td></td>
  1341. <td align="center">
  1342. <button type="submit" class="btn back" name="step1" value="&lt; <?php echo get_lang('Previous'); ?>" ><?php echo get_lang('Previous'); ?></button>
  1343. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1344. <button type="submit" class="btn next" name="step3" onclick="javascript: if(!document.getElementById('accept_licence').checked) { alert('<?php echo get_lang('YouMustAcceptLicence')?>');return false;}" value="<?php echo get_lang('Next'); ?> &gt;" ><?php echo get_lang('Next'); ?></button>
  1345. </td>
  1346. </tr>
  1347. </table>
  1348. </td>
  1349. </tr>
  1350. </table>
  1351. <!-- Contact information form -->
  1352. <div>
  1353. <a href="javascript://" class = "advanced_parameters" >
  1354. <span id="img_plus_and_minus">&nbsp;<img src="<?php echo api_get_path(WEB_IMG_PATH) ?>div_hide.gif" alt="<?php echo get_lang('Hide') ?>" title="<?php echo get_lang('Hide')?>" style ="vertical-align:middle" />&nbsp;<?php echo get_lang('ContactInformation') ?></span>
  1355. </a>
  1356. </div>
  1357. <div id="id_contact_form" style="display:block">
  1358. <div class="normal-message"><?php echo get_lang('ContactInformationDescription') ?></div>
  1359. <div id="contact_registration">
  1360. <p><?php echo get_contact_registration_form() ?></p><br />
  1361. </div>
  1362. </div>
  1363. <?php
  1364. }
  1365. /**
  1366. * Get contact registration form
  1367. */
  1368. function get_contact_registration_form() {
  1369. $html ='
  1370. <form class="form-horizontal">
  1371. <fieldset style="width:95%;padding:15px;border:1pt solid #eee">
  1372. <div id="div_sent_information"></div>
  1373. <div class="control-group">
  1374. <label class="control-label"><span class="form_required">*</span>'.get_lang('Name').'</label>
  1375. <div class="controls"><input id="person_name" type="text" name="person_name" size="30" /></div>
  1376. </div>
  1377. <div class="control-group">
  1378. <label class="control-label"><span class="form_required">*</span>'.get_lang('Email').'</label>
  1379. <div class="controls"><input id="person_email" type="text" name="person_email" size="30" /></div>
  1380. </div>
  1381. <div class="control-group">
  1382. <label class="control-label"><span class="form_required">*</span>'.get_lang('CompanyName').'</label>
  1383. <div class="controls"><input id="company_name" type="text" name="company_name" size="30" /></div>
  1384. </div>
  1385. <div class="control-group">
  1386. <div class="control-label"><span class="form_required">*</span>'.get_lang('CompanyActivity').'</div>
  1387. <div class="controls">
  1388. <select name="company_activity" id="company_activity" >
  1389. <option value="">--- '.get_lang('SelectOne').' ---</option>
  1390. <Option value="Advertising/Marketing/PR">Advertising/Marketing/PR</Option><Option value="Agriculture/Forestry">Agriculture/Forestry</Option>
  1391. <Option value="Architecture">Architecture</Option><Option value="Banking/Finance">Banking/Finance</Option>
  1392. <Option value="Biotech/Pharmaceuticals">Biotech/Pharmaceuticals</Option><Option value="Business Equipment">Business Equipment</Option>
  1393. <Option value="Business Services">Business Services</Option><Option value="Construction">Construction</Option>
  1394. <Option value="Consulting/Research">Consulting/Research</Option><Option value="Education">Education</Option>
  1395. <Option value="Engineering">Engineering</Option><Option value="Environmental">Environmental</Option>
  1396. <Option value="Government">Government</Option><Option value="Healthcare">Health Care</Option>
  1397. <Option value="Hospitality/Lodging/Travel">Hospitality/Lodging/Travel</Option><Option value="Insurance">Insurance</Option>
  1398. <Option value="Legal">Legal</Option><Option value="Manufacturing">Manufacturing</Option>
  1399. <Option value="Media/Entertainment">Media/Entertainment</Option><Option value="Mortgage">Mortgage</Option>
  1400. <Option value="Non-Profit">Non-Profit</Option><Option value="Real Estate">Real Estate</Option>
  1401. <Option value="Restaurant">Restaurant</Option><Option value="Retail">Retail</Option>
  1402. <Option value="Shipping/Transportation">Shipping/Transportation</Option>
  1403. <Option value="Technology">Technology</Option><Option value="Telecommunications">Telecommunications</Option>
  1404. <Option value="Other">Other</Option>
  1405. </select>
  1406. </div>
  1407. </div>
  1408. <div class="control-group">
  1409. <div class="control-label"><span class="form_required">*</span>'.get_lang('PersonRole').'</div>
  1410. <div class="controls">
  1411. <select name="person_role" id="person_role" >
  1412. <option value="">--- '.get_lang('SelectOne').' ---</option>
  1413. <Option value="Administration">Administration</Option><Option value="CEO/President/ Owner">CEO/President/ Owner</Option>
  1414. <Option value="CFO">CFO</Option><Option value="CIO/CTO">CIO/CTO</Option>
  1415. <Option value="Consultant">Consultant</Option><Option value="Customer Service">Customer Service</Option>
  1416. <Option value="Engineer/Programmer">Engineer/Programmer</Option><Option value="Facilities/Operations">Facilities/Operations</Option>
  1417. <Option value="Finance/ Accounting Manager">Finance/ Accounting Manager</Option><Option value="Finance/ Accounting Staff">Finance/ Accounting Staff</Option>
  1418. <Option value="General Manager">General Manager</Option><Option value="Human Resources">Human Resources</Option>
  1419. <Option value="IS/IT Management">IS/IT Management</Option><Option value="IS/ IT Staff">IS/ IT Staff</Option>
  1420. <Option value="Marketing Manager">Marketing Manager</Option><Option value="Marketing Staff">Marketing Staff</Option>
  1421. <Option value="Partner/Principal">Partner/Principal</Option><Option value="Purchasing Manager">Purchasing Manager</Option>
  1422. <Option value="Sales/ Business Dev. Manager">Sales/ Business Dev. Manager</Option><Option value="Sales/ Business Dev.">Sales/ Business Dev.</Option>
  1423. <Option value="Vice President/Senior Manager">Vice President/Senior Manager</Option><Option value="Other">Other</Option>
  1424. </select>
  1425. </div>
  1426. </div>
  1427. <div class="control-group">
  1428. <div class="control-label"><span class="form_required">*</span>'.get_lang('CompanyCountry').'</div>
  1429. <div class="controls">'.get_countries_list_from_array(true).'</div>
  1430. </div>
  1431. <div class="control-group">
  1432. <div class="control-label">'.get_lang('CompanyCity').'</div>
  1433. <div class="controls">
  1434. <input type="text" id="company_city" name="company_city" size="30" />
  1435. </div>
  1436. </div>
  1437. <div class="control-group">
  1438. <div class="control-label">'.get_lang('WhichLanguageWouldYouLikeToUseWhenContactingYou').'</div>
  1439. <div class="controls">
  1440. <select id="language" name="language">
  1441. <option value="bulgarian">Bulgarian</option>
  1442. <option value="indonesian">Bahasa Indonesia</option>
  1443. <option value="bosnian">Bosanski</option>
  1444. <option value="german">Deutsch</option>
  1445. <option selected="selected" value="english">English</option>
  1446. <option value="spanish">Spanish</option>
  1447. <option value="french">Français</option>
  1448. <option value="italian">Italian</option>
  1449. <option value="hungarian">Magyar</option>
  1450. <option value="dutch">Nederlands</option>
  1451. <option value="brazilian">Português do Brasil</option>
  1452. <option value="portuguese">Português europeu</option>
  1453. <option value="slovenian">Slovenčina</option>
  1454. </select>
  1455. </div>
  1456. </div>
  1457. <div class="control-group">
  1458. <div class="control-label">'.get_lang('HaveYouThePowerToTakeFinancialDecisions').'</div>
  1459. <div class="controls">
  1460. <input type="radio" name="financial_decision" id="financial_decision1" value="1" checked />'.get_lang('Yes').'
  1461. <input type="radio" name="financial_decision" id="financial_decision2" value="0" />'.get_lang('No').'
  1462. </div>
  1463. </div>
  1464. <div class="clear"></div>
  1465. <div class="control-group">
  1466. <div class="control-label">&nbsp;</div>
  1467. <div class="controls"><button type="button" class="save" onclick="javascript:send_contact_information();" value="'.get_lang('SendInformation').'" >'.get_lang('SendInformation').'</button></div>
  1468. </div>
  1469. <div class="control-group">
  1470. <div class="control-label">&nbsp;</div>
  1471. <div class="controls"><span class="form_required">*</span><small>'.get_lang('FieldRequired').'</small></div>
  1472. </div>
  1473. </fieldset></form>';
  1474. return $html;
  1475. }
  1476. /**
  1477. * Displays a parameter in a table row.
  1478. * Used by the display_database_settings_form function.
  1479. * @param string Type of install
  1480. * @param string Name of parameter
  1481. * @param string Field name (in the HTML form)
  1482. * @param string Field value
  1483. * @param string Extra notice (to show on the right side)
  1484. * @param boolean Whether to display in update mode
  1485. * @param string Additional attribute for the <tr> element
  1486. * @return void Direct output
  1487. */
  1488. function display_database_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $extra_notice, $display_when_update = true, $tr_attribute = '') {
  1489. echo "<tr ".$tr_attribute.">";
  1490. echo "<td>$parameter_name&nbsp;&nbsp;</td>";
  1491. if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update) {
  1492. echo '<td><input type="hidden" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities($parameter_value).'" />'.$parameter_value."</td>";
  1493. } else {
  1494. $inputtype = $form_field_name == 'dbPassForm' ? 'password' : 'text';
  1495. //Slightly limit the length of the database prefix to avoid having to cut down the databases names later on
  1496. $maxlength = $form_field_name == 'dbPrefixForm' ? '15' : MAX_FORM_FIELD_LENGTH;
  1497. if ($install_type == INSTALL_TYPE_UPDATE) {
  1498. echo '<input type="hidden" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities($parameter_value).'" />';
  1499. echo '<td>'.api_htmlentities($parameter_value)."</td>";
  1500. } else {
  1501. echo '<td><input type="'.$inputtype.'" size="'.DATABASE_FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.$maxlength.'" name="'.$form_field_name.'" id="'.$form_field_name.'" value="'.api_htmlentities($parameter_value).'" />'."</td>";
  1502. echo "<td>$extra_notice</td>";
  1503. }
  1504. }
  1505. echo "</tr>";
  1506. }
  1507. /**
  1508. * Displays step 3 - a form where the user can enter the installation settings
  1509. * regarding the databases - login and password, names, prefixes, single
  1510. * or multiple databases, tracking or not...
  1511. */
  1512. function display_database_settings_form($installType, $dbHostForm, $dbUsernameForm, $dbPassForm, $dbPrefixForm, $enableTrackingForm, $singleDbForm, $dbNameForm, $dbStatsForm, $dbScormForm, $dbUserForm) {
  1513. if ($installType == 'update') {
  1514. global $_configuration, $update_from_version_6;
  1515. if (in_array($_POST['old_version'], $update_from_version_6)) {
  1516. $dbHostForm = get_config_param('dbHost');
  1517. $dbUsernameForm = get_config_param('dbLogin');
  1518. $dbPassForm = get_config_param('dbPass');
  1519. $dbPrefixForm = get_config_param('dbNamePrefix');
  1520. $enableTrackingForm = get_config_param('is_trackingEnabled');
  1521. $singleDbForm = get_config_param('singleDbEnabled');
  1522. $dbHostForm = get_config_param('mainDbName');
  1523. $dbStatsForm = get_config_param('statsDbName');
  1524. $dbScormForm = get_config_param('scormDbName');
  1525. $dbUserForm = get_config_param('user_personal_database');
  1526. $dbScormExists = true;
  1527. } else {
  1528. $dbHostForm = $_configuration['db_host'];
  1529. $dbUsernameForm = $_configuration['db_user'];
  1530. $dbPassForm = $_configuration['db_password'];
  1531. $dbPrefixForm = $_configuration['db_prefix'];
  1532. $enableTrackingForm = $_configuration['tracking_enabled'];
  1533. $singleDbForm = $_configuration['single_database'];
  1534. $dbNameForm = $_configuration['main_database'];
  1535. $dbStatsForm = $_configuration['statistics_database'];
  1536. $dbScormForm = $_configuration['scorm_database'];
  1537. $dbUserForm = $_configuration['user_personal_database'];
  1538. $dbScormExists = true;
  1539. }
  1540. if (empty($dbScormForm)) {
  1541. if ($singleDbForm) {
  1542. $dbScormForm = $dbNameForm;
  1543. } else {
  1544. $dbScormForm = $dbPrefixForm.'scorm';
  1545. $dbScormExists = false;
  1546. }
  1547. }
  1548. if (empty($dbUserForm)) {
  1549. $dbUserForm = $singleDbForm ? $dbNameForm : $dbPrefixForm.'chamilo_user';
  1550. }
  1551. echo '<div class="RequirementHeading"><h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2></div>';
  1552. echo '<div class="RequirementContent">';
  1553. echo get_lang('DBSettingUpgradeIntro');
  1554. echo '</div>';
  1555. } else {
  1556. if (empty($dbPrefixForm)) { //make sure there is a default value for db prefix
  1557. $dbPrefixForm = '';
  1558. }
  1559. echo '<div class="RequirementHeading"><h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2></div>';
  1560. echo '<div class="RequirementContent">';
  1561. echo get_lang('DBSettingIntro');
  1562. echo '</div>';
  1563. }
  1564. $dbConnect = test_db_connect($dbHostForm, $dbUsernameForm, $dbPassForm, $singleDbForm, $dbPrefixForm, $dbNameForm);
  1565. ?>
  1566. </td>
  1567. </tr>
  1568. <tr>
  1569. <td>
  1570. <table class="data_table_no_border">
  1571. <tr>
  1572. <td width="40%"><?php echo get_lang('DBHost'); ?> </td>
  1573. <?php if ($installType == 'update'): ?>
  1574. <td width="30%"><input type="hidden" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /><?php echo $dbHostForm; ?></td>
  1575. <td width="30%">&nbsp;</td>
  1576. <?php else: ?>
  1577. <td width="30%"><input type="text" size="25" maxlength="50" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" <?php if ($dbConnect == -1) { echo 'autofocus="autofocus"'; } ?> /></td>
  1578. <td width="30%"><?php echo get_lang('EG').' localhost'; ?></td>
  1579. <?php endif; ?>
  1580. </tr>
  1581. <tr>
  1582. <?php
  1583. //database user username
  1584. $example_login = get_lang('EG').' root';
  1585. display_database_parameter($installType, get_lang('DBLogin'), 'dbUsernameForm', $dbUsernameForm, $example_login);
  1586. //database user password
  1587. $example_password = get_lang('EG').' '.api_generate_password();
  1588. display_database_parameter($installType, get_lang('DBPassword'), 'dbPassForm', $dbPassForm, $example_password);
  1589. echo '<input type="hidden" name="enableTrackingForm" value="1" />';
  1590. $style = '';
  1591. if ($installType == INSTALL_TYPE_UPDATE) {
  1592. $style = '';
  1593. }
  1594. //Database Name fix replace weird chars
  1595. if ($installType != INSTALL_TYPE_UPDATE) {
  1596. $dbNameForm = str_replace(array('-','*', '$', ' ', '.'), '', $dbNameForm);
  1597. $dbNameForm = replace_dangerous_char($dbNameForm);
  1598. }
  1599. display_database_parameter($installType, get_lang('MainDB'), 'dbNameForm', $dbNameForm, '&nbsp;', null, 'id="optional_param1" '.$style);
  1600. //Only for updates we show this options
  1601. if ($installType == INSTALL_TYPE_UPDATE) {
  1602. display_database_parameter($installType, get_lang('StatDB'), 'dbStatsForm', $dbStatsForm, '&nbsp;', null, 'id="optional_param2" '.$style);
  1603. if ($installType == INSTALL_TYPE_UPDATE && in_array($_POST['old_version'], $update_from_version_6)) {
  1604. display_database_parameter($installType, get_lang('ScormDB'), 'dbScormForm', $dbScormForm, '&nbsp;', null, 'id="optional_param3" '.$style);
  1605. }
  1606. display_database_parameter($installType, get_lang('UserDB'), 'dbUserForm', $dbUserForm, '&nbsp;', null, 'id="optional_param4" '.$style);
  1607. }
  1608. ?>
  1609. <tr>
  1610. <td></td>
  1611. <td>
  1612. <button type="submit" class="btn" name="step3" value="<?php echo get_lang('CheckDatabaseConnection'); ?>" >
  1613. <?php echo get_lang('CheckDatabaseConnection'); ?></button>
  1614. </td>
  1615. </tr>
  1616. <tr>
  1617. <td>
  1618. <?php
  1619. $database_exists_text = '';
  1620. if (database_exists($dbNameForm)) {
  1621. $database_exists_text = '<div class="warning-message">'.get_lang('ADatabaseWithTheSameNameAlreadyExists').'</div>';
  1622. } else {
  1623. if ($dbConnect == -1) {
  1624. $database_exists_text = '<div class="warning-message">'.sprintf(get_lang('UserXCantHaveAccessInTheDatabaseX'), $dbUsernameForm, $dbNameForm).'</div>';
  1625. } else {
  1626. //Try to create the database
  1627. $user_can_create_databases = false;
  1628. $multipleDbCheck = @Database::query("CREATE DATABASE ".mysql_real_escape_string($dbNameForm));
  1629. if ($multipleDbCheck !== false) {
  1630. $multipleDbCheck = @Database::query("DROP DATABASE IF EXISTS ".mysql_real_escape_string($dbNameForm));
  1631. $user_can_create_databases = true;
  1632. }
  1633. if ($user_can_create_databases) {
  1634. $database_exists_text = '<div class="normal-message">'.sprintf(get_lang('DatabaseXWillBeCreated'), $dbNameForm, $dbUsernameForm).'</div>';
  1635. } else {
  1636. $dbConnect = 0;
  1637. $database_exists_text = '<div class="warning-message">'.sprintf(get_lang('DatabaseXCantBeCreatedUserXDoestHaveEnoughPermissions'), $dbNameForm, $dbUsernameForm).'</div>';
  1638. }
  1639. }
  1640. }
  1641. if ($dbConnect == 1): ?>
  1642. <td colspan="2">
  1643. <?php echo $database_exists_text ?>
  1644. <div id="db_status" class="confirmation-message">
  1645. Database host: <strong><?php echo Database::get_host_info(); ?></strong><br />
  1646. Database server version: <strong><?php echo Database::get_server_info(); ?></strong><br />
  1647. Database client version: <strong><?php echo Database::get_client_info(); ?></strong><br />
  1648. Database protocol version: <strong><?php echo Database::get_proto_info(); ?></strong>
  1649. <div style="clear:both;"></div>
  1650. </div>
  1651. </td>
  1652. <?php else: ?>
  1653. <td colspan="2">
  1654. <?php echo $database_exists_text ?>
  1655. <div id="db_status" style="float:left;" class="error-message">
  1656. <div style="float:left;">
  1657. <strong><?php echo get_lang('FailedConectionDatabase'); ?></strong><br />
  1658. <strong>Database error: <?php echo Database::errno(); ?></strong><br />
  1659. <?php echo Database::error().'<br />'; ?>
  1660. </div>
  1661. </div>
  1662. </td>
  1663. <?php endif; ?>
  1664. </tr>
  1665. <tr>
  1666. <td>
  1667. <button type="submit" name="step2" class="back" value="&lt; <?php echo get_lang('Previous'); ?>" ><?php echo get_lang('Previous'); ?></button>
  1668. </td>
  1669. <td>&nbsp;</td>
  1670. <td align="right">
  1671. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1672. <?php if ($dbConnect == 1) { ?>
  1673. <button type="submit" class="btn next" name="step4" value="<?php echo get_lang('Next'); ?> &gt;" <?php if ($dbConnect == 1) { echo 'autofocus="autofocus"'; } ?> /><?php echo get_lang('Next'); ?></button>
  1674. <?php } else { ?>
  1675. <button disabled="disabled" type="submit" class="btn next disabled" name="step4" value="<?php echo get_lang('Next'); ?> &gt;" /><?php echo get_lang('Next'); ?></button>
  1676. <?php } ?>
  1677. </td>
  1678. </tr>
  1679. </table>
  1680. <?php
  1681. }
  1682. /**
  1683. * Displays a parameter in a table row.
  1684. * Used by the display_configuration_settings_form function.
  1685. */
  1686. function display_configuration_parameter($install_type, $parameter_name, $form_field_name, $parameter_value, $display_when_update = 'true') {
  1687. echo "<tr>";
  1688. echo "<td>$parameter_name</td>";
  1689. if ($install_type == INSTALL_TYPE_UPDATE && $display_when_update) {
  1690. echo '<td><input type="hidden" name="'.$form_field_name.'" value="'.api_htmlentities($parameter_value, ENT_QUOTES).'" />'.$parameter_value."</td>\n";
  1691. } else {
  1692. echo '<td><input type="text" size="'.FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.MAX_FORM_FIELD_LENGTH.'" name="'.$form_field_name.'" value="'.api_htmlentities($parameter_value, ENT_QUOTES).'" '.($form_field_name=='loginForm'?'autofocus="autofocus"':'').' />'."</td>\n";
  1693. }
  1694. echo "</tr>";
  1695. }
  1696. /**
  1697. * Displays step 4 of the installation - configuration settings about Chamilo itself.
  1698. */
  1699. function display_configuration_settings_form($installType, $urlForm, $languageForm, $emailForm, $adminFirstName, $adminLastName, $adminPhoneForm, $campusForm, $institutionForm, $institutionUrlForm, $encryptPassForm, $allowSelfReg, $allowSelfRegProf, $loginForm, $passForm) {
  1700. if ($installType != 'update' && empty($languageForm)) {
  1701. $languageForm = $_SESSION['install_language'];
  1702. }
  1703. echo '<div class="RequirementHeading">';
  1704. echo "<h2>" . display_step_sequence() . get_lang("CfgSetting") . "</h2>";
  1705. echo '</div>';
  1706. echo '<div class="RequirementContent">';
  1707. echo '<p>'.get_lang('ConfigSettingsInfo').' <strong>main/inc/conf/configuration.php</strong></p>';
  1708. echo '</div>';
  1709. echo '<fieldset>';
  1710. echo '<legend>'.get_lang('Administrator').'</legend>';
  1711. echo '<table class="data_table_no_border">';
  1712. //Parameter 1: administrator's login
  1713. display_configuration_parameter($installType, get_lang('AdminLogin'), 'loginForm', $loginForm, $installType == 'update');
  1714. //Parameter 2: administrator's password
  1715. if ($installType != 'update') {
  1716. display_configuration_parameter($installType, get_lang('AdminPass'), 'passForm', $passForm, false);
  1717. }
  1718. //Parameters 3 and 4: administrator's names
  1719. if (api_is_western_name_order()) {
  1720. display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
  1721. display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
  1722. } else {
  1723. display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
  1724. display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
  1725. }
  1726. //Parameter 3: administrator's email
  1727. display_configuration_parameter($installType, get_lang('AdminEmail'), 'emailForm', $emailForm);
  1728. //Parameter 6: administrator's telephone
  1729. display_configuration_parameter($installType, get_lang('AdminPhone'), 'adminPhoneForm', $adminPhoneForm);
  1730. echo '</table>';
  1731. echo '</fieldset>';
  1732. echo '<fieldset>';
  1733. echo '<legend>'.get_lang('Platform').'</legend>';
  1734. echo '<table class="data_table_no_border">';
  1735. //First parameter: language
  1736. echo "<tr>";
  1737. echo '<td>'.get_lang('MainLang')."&nbsp;&nbsp;</td>";
  1738. if ($installType == 'update') {
  1739. echo '<td><input type="hidden" name="languageForm" value="'.api_htmlentities($languageForm, ENT_QUOTES).'" />'.$languageForm."</td>";
  1740. } else { // new installation
  1741. echo '<td>';
  1742. display_language_selection_box('languageForm', $languageForm);
  1743. echo "</td>\n";
  1744. }
  1745. echo "</tr>\n";
  1746. //Second parameter: Chamilo URL
  1747. echo "<tr>";
  1748. echo '<td>'.get_lang('ChamiloURL').' (<font color="red">'.get_lang('ThisFieldIsRequired')."</font>)&nbsp;&nbsp;</td>";
  1749. if ($installType == 'update') {
  1750. echo '<td>'.api_htmlentities($urlForm, ENT_QUOTES)."</td>\n";
  1751. } else {
  1752. echo '<td><input type="text" size="40" maxlength="100" name="urlForm" value="'.api_htmlentities($urlForm, ENT_QUOTES).'" />'."</td>";
  1753. }
  1754. echo "</tr>";
  1755. //Parameter 9: campus name
  1756. display_configuration_parameter($installType, get_lang('CampusName'), 'campusForm', $campusForm);
  1757. //Parameter 10: institute (short) name
  1758. display_configuration_parameter($installType, get_lang('InstituteShortName'), 'institutionForm', $institutionForm);
  1759. //Parameter 11: institute (short) name
  1760. display_configuration_parameter($installType, get_lang('InstituteURL'), 'institutionUrlForm', $institutionUrlForm);
  1761. ?>
  1762. <tr>
  1763. <td><?php echo get_lang("EncryptMethodUserPass"); ?> :</td>
  1764. <?php if ($installType == 'update') { ?>
  1765. <td><input type="hidden" name="encryptPassForm" value="<?php echo $encryptPassForm; ?>" /><?php echo $encryptPassForm; ?></td>
  1766. <?php } else { ?>
  1767. <td>
  1768. <div class="control-group">
  1769. <label class="checkbox inline">
  1770. <input class="checkbox" type="radio" name="encryptPassForm" value="sha1" id="encryptPass1" <?php echo ($encryptPassForm == 'sha1') ? 'checked="checked" ': ''; ?>/><?php echo 'sha1'; ?>
  1771. </label>
  1772. <label class="checkbox inline">
  1773. <input class="checkbox" type="radio" name="encryptPassForm" value="md5" id="encryptPass0" <?php echo $encryptPassForm == 1 ? 'checked="checked" ' : ''; ?>/><?php echo 'md5'; ?>
  1774. </label>
  1775. <label class="checkbox inline">
  1776. <input class="checkbox" type="radio" name="encryptPassForm" value="none" id="encryptPass2" <?php echo $encryptPassForm === '0' or $encryptPassForm === 0 ? 'checked="checked" ':''; ?>/><?php echo get_lang('None'); ?>
  1777. </label>
  1778. </div>
  1779. </td>
  1780. <?php } ?>
  1781. </tr>
  1782. <tr>
  1783. <td><?php echo get_lang('AllowSelfReg'); ?> :</td>
  1784. <?php if ($installType == 'update'): ?>
  1785. <td><input type="hidden" name="allowSelfReg" value="<?php echo $allowSelfReg; ?>" /><?php echo $allowSelfReg ? get_lang('Yes') : get_lang('No'); ?></td>
  1786. <?php else: ?>
  1787. <td>
  1788. <div class="control-group">
  1789. <label class="checkbox inline">
  1790. <input class="checkbox" type="radio" name="allowSelfReg" value="1" id="allowSelfReg1" <?php echo $allowSelfReg ? 'checked="checked" ' : ''; ?>/> <?php echo get_lang('Yes'); ?>
  1791. </label>
  1792. <label class="checkbox inline">
  1793. <input class="checkbox" type="radio" name="allowSelfReg" value="0" id="allowSelfReg0" <?php echo $allowSelfReg ? '' : 'checked="checked" '; ?>/><?php echo get_lang('No'); ?>
  1794. </label>
  1795. </div>
  1796. </td>
  1797. <?php endif; ?>
  1798. </tr>
  1799. <tr>
  1800. <td><?php echo get_lang('AllowSelfRegProf'); ?> :</td>
  1801. <?php if ($installType == 'update'): ?>
  1802. <td><input type="hidden" name="allowSelfRegProf" value="<?php echo $allowSelfRegProf; ?>" /><?php echo $allowSelfRegProf? get_lang('Yes') : get_lang('No'); ?></td>
  1803. <?php else: ?>
  1804. <td>
  1805. <div class="control-group">
  1806. <label class="checkbox inline">
  1807. <input class="checkbox" type="radio" name="allowSelfRegProf" value="1" id="allowSelfRegProf1" <?php echo $allowSelfRegProf ? 'checked="checked" ' : ''; ?>/>
  1808. <?php echo get_lang('Yes'); ?>
  1809. </label>
  1810. <label class="checkbox inline">
  1811. <input class="checkbox" type="radio" name="allowSelfRegProf" value="0" id="allowSelfRegProf0" <?php echo $allowSelfRegProf ? '' : 'checked="checked" '; ?>/>
  1812. <?php echo get_lang('No'); ?>
  1813. </label>
  1814. </div>
  1815. </td>
  1816. <?php endif; ?>
  1817. </tr>
  1818. <tr>
  1819. <td>
  1820. <button type="submit" class="btn back" name="step3" value="&lt; <?php echo get_lang('Previous'); ?>" /><?php echo get_lang('Previous'); ?></button>
  1821. </td>
  1822. <td align="right">
  1823. <input type="hidden" name="is_executable" id="is_executable" value="-" />
  1824. <button class="btn next" type="submit" name="step5" value="<?php echo get_lang('Next'); ?> &gt;" /><?php echo get_lang('Next'); ?></button></td>
  1825. </tr>
  1826. </fieldset>
  1827. </table>
  1828. <?php
  1829. }
  1830. /**
  1831. * After installation is completed (step 6), this message is displayed.
  1832. */
  1833. function display_after_install_message($installType) {
  1834. echo '<div class="RequirementContent">'.get_lang('FirstUseTip').'</div>';
  1835. echo '<div class="warning-message">';
  1836. echo '<strong>'.get_lang('SecurityAdvice').'</strong>';
  1837. echo ': ';
  1838. printf(get_lang('ToProtectYourSiteMakeXReadOnlyAndDeleteY'), 'main/inc/conf/', 'main/install/');
  1839. echo '</div>';
  1840. ?></form>
  1841. <br />
  1842. <a class="btn btn-success btn-large btn-install" href="../../index.php" autofocus="autofocus"><?php echo get_lang('GoToYourNewlyCreatedPortal'); ?></a>
  1843. <?php
  1844. }
  1845. /**
  1846. * This function return countries list from array (hardcoded)
  1847. * @param bool (Optional) True for returning countries list with select html
  1848. * @return array|string countries list
  1849. */
  1850. function get_countries_list_from_array($combo = false) {
  1851. $a_countries = array(
  1852. "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan",
  1853. "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burundi",
  1854. "Cambodia", "Cameroon", "Canada", "Cape Verde", "Central African Republic", "Chad", "Chile", "China", "Colombi", "Comoros", "Congo (Brazzaville)", "Congo", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic",
  1855. "Denmark", "Djibouti", "Dominica", "Dominican Republic",
  1856. "East Timor (Timor Timur)", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia",
  1857. "Fiji", "Finland", "France",
  1858. "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana", "Greece", "Grenada", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana",
  1859. "Haiti", "Honduras", "Hungary",
  1860. "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy",
  1861. "Jamaica", "Japan", "Jordan",
  1862. "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait", "Kyrgyzstan",
  1863. "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
  1864. "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Morocco", "Mozambique", "Myanmar",
  1865. "Namibia", "Nauru", "Nepa", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway",
  1866. "Oman",
  1867. "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland","Portugal",
  1868. "Qatar",
  1869. "Romania", "Russia", "Rwanda",
  1870. "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia and Montenegro", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria",
  1871. "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu",
  1872. "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan",
  1873. "Vanuatu", "Vatican City", "Venezuela", "Vietnam",
  1874. "Yemen",
  1875. "Zambia", "Zimbabwe"
  1876. );
  1877. $country_select = '';
  1878. if ($combo) {
  1879. $country_select = '<select id="country" name="country">';
  1880. $country_select .= '<option value="">--- '.get_lang('SelectOne').' ---</option>';
  1881. foreach ($a_countries as $country) {
  1882. $country_select .= '<option value="'.$country.'">'.$country.'</option>';
  1883. }
  1884. $country_select .= '</select>';
  1885. return $country_select;
  1886. }
  1887. return $a_countries;
  1888. }
  1889. /**
  1890. * Lockis settings that can't be changed in other portals
  1891. */
  1892. function locking_settings() {
  1893. $access_url_locked_settings = api_get_locked_settings();
  1894. $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1895. foreach ($access_url_locked_settings as $setting) {
  1896. $sql = "UPDATE $table SET access_url_locked = 1 WHERE variable = '$setting'";
  1897. Database::query($sql);
  1898. }
  1899. }
  1900. function update_dir_and_files_permissions() {
  1901. $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
  1902. $permissions_for_new_directories = isset($_SESSION['permissions_for_new_directories']) ? $_SESSION['permissions_for_new_directories'] : 0770;
  1903. $permissions_for_new_files = isset($_SESSION['permissions_for_new_files']) ? $_SESSION['permissions_for_new_files'] : 0660;
  1904. // use decoct() to store as string
  1905. $sql = "UPDATE $table SET selected_value = '0".decoct($permissions_for_new_directories)."' WHERE variable = 'permissions_for_new_directories'";
  1906. Database::query($sql);
  1907. $sql = "UPDATE $table SET selected_value = '0".decoct($permissions_for_new_files)."' WHERE variable = 'permissions_for_new_files'";
  1908. Database::query($sql);
  1909. unset($_SESSION['permissions_for_new_directories']);
  1910. unset($_SESSION['permissions_for_new_files']);
  1911. }
  1912. function compare_setting_values($current_value, $wanted_value) {
  1913. $current_value_string = $current_value;
  1914. $current_value = (float)$current_value;
  1915. $wanted_value = (float)$wanted_value;
  1916. if ($current_value >= $wanted_value) {
  1917. return Display::label($current_value_string, 'success');
  1918. } else {
  1919. return Display::label($current_value_string, 'important');
  1920. }
  1921. }
  1922. /* Executed only before create_course_tables() */
  1923. function drop_course_tables() {
  1924. $list = CourseManager::get_course_tables();
  1925. foreach ($list as $table) {
  1926. $sql = "DROP TABLE IF EXISTS ".DB_COURSE_PREFIX.$table;
  1927. Database::query($sql);
  1928. }
  1929. }
  1930. /**
  1931. * Creates all the necessary tables for a new course
  1932. */
  1933. function create_course_tables($course_db_name = null) {
  1934. global $_configuration;
  1935. $charset_clause = ' DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci';
  1936. $use_one_db = true;
  1937. if ($use_one_db) {
  1938. $course_db_name = DB_COURSE_PREFIX;
  1939. } else {
  1940. if (!$_configuration['single_database']) {
  1941. Database::query("CREATE DATABASE IF NOT EXISTS " . $course_db_name . "" . $charset_clause);
  1942. }
  1943. $course_db_name = $_configuration['table_prefix'].$course_db_name.$_configuration['db_glue'];
  1944. }
  1945. //@todo define the backticks inside those table names directly (instead of adding them afterwards)
  1946. $tbl_course_homepage = $course_db_name . 'tool';
  1947. $TABLEINTROS = $course_db_name . 'tool_intro';
  1948. $TABLEGROUPS = $course_db_name . 'group_info';
  1949. $TABLEGROUPCATEGORIES = $course_db_name . 'group_category';
  1950. $TABLEGROUPUSER = $course_db_name . 'group_rel_user';
  1951. $TABLEGROUPTUTOR = $course_db_name . 'group_rel_tutor';
  1952. $TABLEITEMPROPERTY = $course_db_name . 'item_property';
  1953. $TABLETOOLUSERINFOCONTENT = $course_db_name . 'userinfo_content';
  1954. $TABLETOOLUSERINFODEF = $course_db_name . 'userinfo_def';
  1955. $TABLETOOLCOURSEDESC = $course_db_name . 'course_description';
  1956. $TABLETOOLAGENDA = $course_db_name . 'calendar_event';
  1957. $TABLETOOLAGENDAREPEAT = $course_db_name . 'calendar_event_repeat';
  1958. $TABLETOOLAGENDAREPEATNOT = $course_db_name . 'calendar_event_repeat_not';
  1959. $TABLETOOLAGENDAATTACHMENT = $course_db_name . 'calendar_event_attachment';
  1960. // Announcements
  1961. $TABLETOOLANNOUNCEMENTS = $course_db_name . 'announcement';
  1962. $TABLETOOLANNOUNCEMENTSATTACHMENT = $course_db_name . 'announcement_attachment';
  1963. // Resourcelinker
  1964. $TABLEADDEDRESOURCES = $course_db_name . 'resource';
  1965. // Student Publication
  1966. $TABLETOOLWORKS = $course_db_name . 'student_publication';
  1967. $TABLETOOLWORKSASS = $course_db_name . 'student_publication_assignment';
  1968. // Document
  1969. $TABLETOOLDOCUMENT = $course_db_name . 'document';
  1970. // Forum
  1971. $TABLETOOLFORUMCATEGORY = $course_db_name . 'forum_category';
  1972. $TABLETOOLFORUM = $course_db_name . 'forum_forum';
  1973. $TABLETOOLFORUMTHREAD = $course_db_name . 'forum_thread';
  1974. $TABLETOOLFORUMPOST = $course_db_name . 'forum_post';
  1975. $TABLETOOLFORUMMAILCUE = $course_db_name . 'forum_mailcue';
  1976. $TABLETOOLFORUMATTACHMENT = $course_db_name . 'forum_attachment';
  1977. $TABLETOOLFORUMNOTIFICATION = $course_db_name . 'forum_notification';
  1978. $TABLETOOLFORUMQUALIFY = $course_db_name . 'forum_thread_qualify';
  1979. $TABLETOOLFORUMQUALIFYLOG = $course_db_name . 'forum_thread_qualify_log';
  1980. // Link
  1981. $TABLETOOLLINK = $course_db_name . 'link';
  1982. $TABLETOOLLINKCATEGORIES = $course_db_name . 'link_category';
  1983. $TABLETOOLONLINECONNECTED = $course_db_name . 'online_connected';
  1984. $TABLETOOLONLINELINK = $course_db_name . 'online_link';
  1985. // Chat
  1986. $TABLETOOLCHATCONNECTED = $course_db_name . 'chat_connected';
  1987. // Quiz (a.k.a. exercises)
  1988. $TABLEQUIZ = $course_db_name . 'quiz';
  1989. $TABLEQUIZQUESTION = $course_db_name . 'quiz_rel_question';
  1990. $TABLEQUIZQUESTIONLIST = $course_db_name . 'quiz_question';
  1991. $TABLEQUIZANSWERSLIST = $course_db_name . 'quiz_answer';
  1992. $TABLEQUIZQUESTIONOPTION = $course_db_name . 'quiz_question_option';
  1993. $table_quiz_question_category = $course_db_name . 'quiz_question_category';
  1994. $table_quiz_question_rel_category = $course_db_name . 'quiz_question_rel_category';
  1995. // Dropbox
  1996. $TABLETOOLDROPBOXPOST = $course_db_name . 'dropbox_post';
  1997. $TABLETOOLDROPBOXFILE = $course_db_name . 'dropbox_file';
  1998. $TABLETOOLDROPBOXPERSON = $course_db_name . 'dropbox_person';
  1999. $TABLETOOLDROPBOXCATEGORY = $course_db_name . 'dropbox_category';
  2000. $TABLETOOLDROPBOXFEEDBACK = $course_db_name . 'dropbox_feedback';
  2001. // New Learning path
  2002. $TABLELP = $course_db_name . 'lp';
  2003. $TABLELPITEM = $course_db_name . 'lp_item';
  2004. $TABLELPVIEW = $course_db_name . 'lp_view';
  2005. $TABLELPITEMVIEW = $course_db_name . 'lp_item_view';
  2006. $TABLELPIVINTERACTION = $course_db_name . 'lp_iv_interaction';
  2007. $TABLELPIVOBJECTIVE = $course_db_name . 'lp_iv_objective';
  2008. // Blogs
  2009. $tbl_blogs = $course_db_name . 'blog';
  2010. $tbl_blogs_comments = $course_db_name . 'blog_comment';
  2011. $tbl_blogs_posts = $course_db_name . 'blog_post';
  2012. $tbl_blogs_rating = $course_db_name . 'blog_rating';
  2013. $tbl_blogs_rel_user = $course_db_name . 'blog_rel_user';
  2014. $tbl_blogs_tasks = $course_db_name . 'blog_task';
  2015. $tbl_blogs_tasks_rel_user = $course_db_name . 'blog_task_rel_user';
  2016. $tbl_blogs_attachment = $course_db_name . 'blog_attachment';
  2017. //Blogs permissions
  2018. $tbl_permission_group = $course_db_name . 'permission_group';
  2019. $tbl_permission_user = $course_db_name . 'permission_user';
  2020. $tbl_permission_task = $course_db_name . 'permission_task';
  2021. //Blog roles
  2022. $tbl_role = $course_db_name . 'role';
  2023. $tbl_role_group = $course_db_name . 'role_group';
  2024. $tbl_role_permissions = $course_db_name . 'role_permissions';
  2025. $tbl_role_user = $course_db_name . 'role_user';
  2026. //Survey variables for course homepage;
  2027. $TABLESURVEY = $course_db_name . 'survey';
  2028. $TABLESURVEYQUESTION = $course_db_name . 'survey_question';
  2029. $TABLESURVEYQUESTIONOPTION = $course_db_name . 'survey_question_option';
  2030. $TABLESURVEYINVITATION = $course_db_name . 'survey_invitation';
  2031. $TABLESURVEYANSWER = $course_db_name . 'survey_answer';
  2032. $TABLESURVEYGROUP = $course_db_name . 'survey_group';
  2033. // Wiki
  2034. $TABLETOOLWIKI = $course_db_name . 'wiki';
  2035. $TABLEWIKICONF = $course_db_name . 'wiki_conf';
  2036. $TABLEWIKIDISCUSS = $course_db_name . 'wiki_discuss';
  2037. $TABLEWIKIMAILCUE = $course_db_name . 'wiki_mailcue';
  2038. // Course settings
  2039. $TABLESETTING = $course_db_name . 'course_setting';
  2040. // Glossary
  2041. $TBL_GLOSSARY = $course_db_name . 'glossary';
  2042. // Notebook
  2043. $TBL_NOTEBOOK = $course_db_name . 'notebook';
  2044. // Attendance
  2045. $TBL_ATTENDANCE = $course_db_name . 'attendance';
  2046. $TBL_ATTENDANCE_SHEET = $course_db_name . 'attendance_sheet';
  2047. $TBL_ATTENDANCE_CALENDAR = $course_db_name . 'attendance_calendar';
  2048. $TBL_ATTENDANCE_RESULT = $course_db_name . 'attendance_result';
  2049. $TBL_ATTENDANCE_SHEET_LOG = $course_db_name . 'attendance_sheet_log';
  2050. // Thematic
  2051. $TBL_THEMATIC = $course_db_name . 'thematic';
  2052. $TBL_THEMATIC_PLAN = $course_db_name . 'thematic_plan';
  2053. $TBL_THEMATIC_ADVANCE = $course_db_name . 'thematic_advance';
  2054. $TBL_METADATA = $course_db_name . 'metadata';
  2055. $add_to_all_tables = ' c_id INT NOT NULL, ';
  2056. /* Announcement tool */
  2057. $sql = "
  2058. CREATE TABLE `".$TABLETOOLANNOUNCEMENTS . "` (
  2059. $add_to_all_tables
  2060. id int unsigned NOT NULL auto_increment,
  2061. title text,
  2062. content mediumtext,
  2063. end_date date default NULL,
  2064. display_order mediumint NOT NULL default 0,
  2065. email_sent tinyint default 0,
  2066. session_id int default 0,
  2067. PRIMARY KEY (c_id, id)
  2068. )" . $charset_clause;
  2069. Database::query($sql);
  2070. $sql = "ALTER TABLE `".$TABLETOOLANNOUNCEMENTS . "` ADD INDEX ( session_id ) ";
  2071. Database::query($sql);
  2072. // Announcement Attachment
  2073. $sql = "CREATE TABLE `".$TABLETOOLANNOUNCEMENTSATTACHMENT."` (
  2074. $add_to_all_tables
  2075. id int NOT NULL auto_increment,
  2076. path varchar(255) NOT NULL,
  2077. comment text,
  2078. size int NOT NULL default 0,
  2079. announcement_id int NOT NULL,
  2080. filename varchar(255) NOT NULL,
  2081. PRIMARY KEY (c_id, id)
  2082. )" . $charset_clause;
  2083. Database::query($sql);
  2084. /*
  2085. Resources
  2086. */
  2087. $sql = "
  2088. CREATE TABLE `".$TABLEADDEDRESOURCES . "` (
  2089. $add_to_all_tables
  2090. id int unsigned NOT NULL auto_increment,
  2091. source_type varchar(50) default NULL,
  2092. source_id int unsigned default NULL,
  2093. resource_type varchar(50) default NULL,
  2094. resource_id int unsigned default NULL,
  2095. PRIMARY KEY (c_id, id)
  2096. )" . $charset_clause;
  2097. Database::query($sql);
  2098. $sql = "
  2099. CREATE TABLE `".$TABLETOOLUSERINFOCONTENT . "` (
  2100. $add_to_all_tables
  2101. id int unsigned NOT NULL auto_increment,
  2102. user_id int unsigned NOT NULL,
  2103. definition_id int unsigned NOT NULL,
  2104. editor_ip varchar(39) default NULL,
  2105. edition_time datetime default NULL,
  2106. content text NOT NULL,
  2107. PRIMARY KEY (c_id, id),
  2108. KEY user_id (user_id)
  2109. )" . $charset_clause;
  2110. Database::query($sql);
  2111. // Unused table. Temporarily ignored for tests.
  2112. // Reused because of user/userInfo and user/userInfoLib scripts
  2113. $sql = "
  2114. CREATE TABLE `".$TABLETOOLUSERINFODEF . "` (
  2115. $add_to_all_tables
  2116. id int unsigned NOT NULL auto_increment,
  2117. title varchar(80) NOT NULL default '',
  2118. comment text,
  2119. line_count tinyint unsigned NOT NULL default 5,
  2120. rank tinyint unsigned NOT NULL default 0,
  2121. PRIMARY KEY (c_id, id)
  2122. )" . $charset_clause;
  2123. Database::query($sql);
  2124. /* Forum tool */
  2125. // Forum Category
  2126. $sql = "
  2127. CREATE TABLE `".$TABLETOOLFORUMCATEGORY . "` (
  2128. $add_to_all_tables
  2129. cat_id int NOT NULL auto_increment,
  2130. cat_title varchar(255) NOT NULL default '',
  2131. cat_comment text,
  2132. cat_order int NOT NULL default 0,
  2133. locked int NOT NULL default 0,
  2134. session_id int unsigned NOT NULL default 0,
  2135. PRIMARY KEY (c_id, cat_id)
  2136. )" . $charset_clause;
  2137. Database::query($sql);
  2138. $sql = "ALTER TABLE `".$TABLETOOLFORUMCATEGORY . "` ADD INDEX ( session_id ) ";
  2139. Database::query($sql);
  2140. // Forum
  2141. $sql = "
  2142. CREATE TABLE `".$TABLETOOLFORUM . "` (
  2143. $add_to_all_tables
  2144. forum_id int NOT NULL auto_increment,
  2145. forum_title varchar(255) NOT NULL default '',
  2146. forum_comment text,
  2147. forum_threads int default 0,
  2148. forum_posts int default 0,
  2149. forum_last_post int default 0,
  2150. forum_category int default NULL,
  2151. allow_anonymous int default NULL,
  2152. allow_edit int default NULL,
  2153. approval_direct_post varchar(20) default NULL,
  2154. allow_attachments int default NULL,
  2155. allow_new_threads int default NULL,
  2156. default_view varchar(20) default NULL,
  2157. forum_of_group varchar(20) default NULL,
  2158. forum_group_public_private varchar(20) default 'public',
  2159. forum_order int default NULL,
  2160. locked int NOT NULL default 0,
  2161. session_id int NOT NULL default 0,
  2162. forum_image varchar(255) NOT NULL default '',
  2163. start_time datetime NOT NULL default '0000-00-00 00:00:00',
  2164. end_time datetime NOT NULL default '0000-00-00 00:00:00',
  2165. PRIMARY KEY (c_id, forum_id)
  2166. )" . $charset_clause;
  2167. Database::query($sql);
  2168. // Forum Threads
  2169. $sql = "
  2170. CREATE TABLE `".$TABLETOOLFORUMTHREAD . "` (
  2171. $add_to_all_tables
  2172. thread_id int NOT NULL auto_increment,
  2173. thread_title varchar(255) default NULL,
  2174. forum_id int default NULL,
  2175. thread_replies int default 0,
  2176. thread_poster_id int default NULL,
  2177. thread_poster_name varchar(100) default '',
  2178. thread_views int default 0,
  2179. thread_last_post int default NULL,
  2180. thread_date datetime default '0000-00-00 00:00:00',
  2181. thread_sticky tinyint unsigned default 0,
  2182. locked int NOT NULL default 0,
  2183. session_id int unsigned default NULL,
  2184. thread_title_qualify varchar(255) default '',
  2185. thread_qualify_max float(6,2) UNSIGNED NOT NULL default 0,
  2186. thread_close_date datetime default '0000-00-00 00:00:00',
  2187. thread_weight float(6,2) UNSIGNED NOT NULL default 0,
  2188. PRIMARY KEY (c_id, thread_id)
  2189. )" . $charset_clause;
  2190. Database::query($sql);
  2191. $sql = "ALTER TABLE `".$TABLETOOLFORUMTHREAD . "` ADD INDEX idx_forum_thread_forum_id (forum_id)";
  2192. Database::query($sql);
  2193. // Forum Posts
  2194. $sql = "
  2195. CREATE TABLE `".$TABLETOOLFORUMPOST . "` (
  2196. $add_to_all_tables
  2197. post_id int NOT NULL auto_increment,
  2198. post_title varchar(250) default NULL,
  2199. post_text text,
  2200. thread_id int default 0,
  2201. forum_id int default 0,
  2202. poster_id int default 0,
  2203. poster_name varchar(100) default '',
  2204. post_date datetime default '0000-00-00 00:00:00',
  2205. post_notification tinyint default 0,
  2206. post_parent_id int default 0,
  2207. visible tinyint default 1,
  2208. PRIMARY KEY (c_id, post_id),
  2209. KEY poster_id (poster_id),
  2210. KEY forum_id (forum_id)
  2211. )" . $charset_clause;
  2212. Database::query($sql);
  2213. $sql = "ALTER TABLE `".$TABLETOOLFORUMPOST . "` ADD INDEX idx_forum_post_thread_id (thread_id)";
  2214. Database::query($sql);
  2215. $sql = "ALTER TABLE `".$TABLETOOLFORUMPOST . "` ADD INDEX idx_forum_post_visible (visible)";
  2216. Database::query($sql);
  2217. // Forum Mailcue
  2218. $sql = "
  2219. CREATE TABLE `".$TABLETOOLFORUMMAILCUE."` (
  2220. $add_to_all_tables
  2221. id int NOT NULL auto_increment,
  2222. user_id int default NULL,
  2223. thread_id int default NULL,
  2224. post_id int default NULL,
  2225. PRIMARY KEY (id, c_id, thread_id, user_id, post_id )
  2226. )" . $charset_clause;
  2227. Database::query($sql);
  2228. // Forum Attachment
  2229. $sql = "CREATE TABLE `".$TABLETOOLFORUMATTACHMENT."` (
  2230. $add_to_all_tables
  2231. id int NOT NULL auto_increment,
  2232. path varchar(255) NOT NULL,
  2233. comment text,
  2234. size int NOT NULL default 0,
  2235. post_id int NOT NULL,
  2236. filename varchar(255) NOT NULL,
  2237. PRIMARY KEY (c_id, id)
  2238. )" . $charset_clause;
  2239. Database::query($sql);
  2240. // Forum notification
  2241. $sql = "CREATE TABLE `".$TABLETOOLFORUMNOTIFICATION."` (
  2242. $add_to_all_tables
  2243. id int NOT NULL auto_increment,
  2244. user_id int,
  2245. forum_id int,
  2246. thread_id int,
  2247. post_id int,
  2248. KEY user_id (user_id),
  2249. KEY forum_id (forum_id),
  2250. PRIMARY KEY (id, c_id, user_id, forum_id, thread_id, post_id )
  2251. )" . $charset_clause;
  2252. Database::query($sql);
  2253. // Forum thread qualify :Add table forum_thread_qualify
  2254. $sql = "CREATE TABLE `".$TABLETOOLFORUMQUALIFY."` (
  2255. $add_to_all_tables
  2256. id int unsigned AUTO_INCREMENT,
  2257. user_id int unsigned NOT NULL,
  2258. thread_id int NOT NULL,
  2259. qualify float(6,2) NOT NULL default 0,
  2260. qualify_user_id int default NULL,
  2261. qualify_time datetime default '0000-00-00 00:00:00',
  2262. session_id int default NULL,
  2263. PRIMARY KEY (c_id, id)
  2264. )" . $charset_clause;
  2265. Database::query($sql);
  2266. $sql = "ALTER TABLE `".$TABLETOOLFORUMQUALIFY . "` ADD INDEX (user_id, thread_id)";
  2267. Database::query($sql);
  2268. //Forum thread qualify: Add table forum_thread_qualify_historical
  2269. $sql = "CREATE TABLE `".$TABLETOOLFORUMQUALIFYLOG."` (
  2270. $add_to_all_tables
  2271. id int unsigned AUTO_INCREMENT,
  2272. user_id int unsigned NOT NULL,
  2273. thread_id int NOT NULL,
  2274. qualify float(6,2) NOT NULL default 0,
  2275. qualify_user_id int default NULL,
  2276. qualify_time datetime default '0000-00-00 00:00:00',
  2277. session_id int default NULL,
  2278. PRIMARY KEY (c_id, id)
  2279. )" . $charset_clause;
  2280. Database::query($sql);
  2281. $sql = "ALTER TABLE `".$TABLETOOLFORUMQUALIFYLOG. "` ADD INDEX (user_id, thread_id)";
  2282. Database::query($sql);
  2283. /*
  2284. * Exercise tool
  2285. */
  2286. // Exercise tool - Tests/exercises
  2287. $sql = "CREATE TABLE `".$TABLEQUIZ . "` (
  2288. $add_to_all_tables
  2289. id int unsigned NOT NULL auto_increment,
  2290. title varchar(255) NOT NULL,
  2291. description text default NULL,
  2292. sound varchar(255) default NULL,
  2293. type tinyint unsigned NOT NULL default 1,
  2294. random int NOT NULL default 0,
  2295. random_answers tinyint unsigned NOT NULL default 0,
  2296. active tinyint NOT NULL default 0,
  2297. results_disabled INT UNSIGNED NOT NULL DEFAULT 0,
  2298. access_condition TEXT DEFAULT NULL,
  2299. max_attempt int NOT NULL default 0,
  2300. start_time datetime NOT NULL default '0000-00-00 00:00:00',
  2301. end_time datetime NOT NULL default '0000-00-00 00:00:00',
  2302. feedback_type int NOT NULL default 0,
  2303. expired_time int NOT NULL default '0',
  2304. session_id int default 0,
  2305. propagate_neg INT NOT NULL DEFAULT 0,
  2306. review_answers INT NOT NULL DEFAULT 0,
  2307. random_by_category INT NOT NULL DEFAULT 0,
  2308. text_when_finished TEXT default NULL,
  2309. display_category_name INT NOT NULL DEFAULT 1,
  2310. pass_percentage INT DEFAULT NULL,
  2311. PRIMARY KEY (c_id, id)
  2312. )" . $charset_clause;
  2313. Database::query($sql);
  2314. $sql = "ALTER TABLE `".$TABLEQUIZ . "` ADD INDEX ( session_id ) ";
  2315. Database::query($sql);
  2316. // Exercise tool - questions
  2317. $sql = "
  2318. CREATE TABLE `".$TABLEQUIZQUESTIONLIST . "` (
  2319. $add_to_all_tables
  2320. id int unsigned NOT NULL auto_increment,
  2321. parent_id int unsigned NOT NULL default 0,
  2322. question TEXT NOT NULL,
  2323. description text default NULL,
  2324. ponderation float(6,2) NOT NULL default 0,
  2325. position mediumint unsigned NOT NULL default 1,
  2326. type tinyint unsigned NOT NULL default 2,
  2327. picture varchar(50) default NULL,
  2328. level int unsigned NOT NULL default 0,
  2329. extra varchar(255) default NULL,
  2330. question_code char(10) default '',
  2331. PRIMARY KEY (c_id, id)
  2332. )" . $charset_clause;
  2333. Database::query($sql);
  2334. $sql = "ALTER TABLE `".$TABLEQUIZQUESTIONLIST . "` ADD INDEX (position)";
  2335. Database::query($sql);
  2336. // Exercise tool - answers
  2337. $sql = "
  2338. CREATE TABLE `".$TABLEQUIZANSWERSLIST . "` (
  2339. $add_to_all_tables
  2340. id int unsigned NOT NULL,
  2341. id_auto int NOT NULL AUTO_INCREMENT,
  2342. question_id int unsigned NOT NULL,
  2343. answer text NOT NULL,
  2344. correct mediumint unsigned default NULL,
  2345. comment text default NULL,
  2346. ponderation float(6,2) NOT NULL default 0,
  2347. position mediumint unsigned NOT NULL default 1,
  2348. hotspot_coordinates text,
  2349. hotspot_type enum('square','circle','poly','delineation','oar') default NULL,
  2350. destination text NOT NULL,
  2351. answer_code char(10) default '',
  2352. PRIMARY KEY (c_id, id_auto)
  2353. )" . $charset_clause;
  2354. Database::query($sql);
  2355. $sql = "ALTER TABLE `".$TABLEQUIZANSWERSLIST . "` ADD INDEX idx_quiz_answer_c_q (c_id, question_id)";
  2356. Database::query($sql);
  2357. // Exercise tool - answer options
  2358. $sql = "
  2359. CREATE TABLE `".$TABLEQUIZQUESTIONOPTION . "` (
  2360. $add_to_all_tables
  2361. id int NOT NULL auto_increment,
  2362. question_id int NOT NULL,
  2363. name varchar(255),
  2364. position int unsigned NOT NULL,
  2365. PRIMARY KEY (c_id, id)
  2366. )" . $charset_clause;
  2367. Database::query($sql);
  2368. // Exercise tool - Test/question relations
  2369. $sql = "
  2370. CREATE TABLE `".$TABLEQUIZQUESTION . "` (
  2371. $add_to_all_tables
  2372. question_id int unsigned NOT NULL,
  2373. exercice_id int unsigned NOT NULL,
  2374. question_order int unsigned NOT NULL default 1,
  2375. PRIMARY KEY (c_id, question_id, exercice_id)
  2376. )" . $charset_clause;
  2377. Database::query($sql);
  2378. $sql = "CREATE TABLE `".$table_quiz_question_category . "` (
  2379. $add_to_all_tables
  2380. id int unsigned NOT NULL AUTO_INCREMENT,
  2381. title varchar(255) NOT NULL,
  2382. description text NOT NULL,
  2383. PRIMARY KEY (c_id, id)
  2384. )" . $charset_clause;
  2385. Database::query($sql);
  2386. $sql = "CREATE TABLE `".$table_quiz_question_rel_category . "` (
  2387. $add_to_all_tables
  2388. id int unsigned NOT NULL AUTO_INCREMENT,
  2389. question_id int NOT NULL,
  2390. category_id int NOT NULL,
  2391. PRIMARY KEY (id, c_id, question_id)
  2392. )" . $charset_clause;
  2393. Database::query($sql);
  2394. //Course description
  2395. $sql = "
  2396. CREATE TABLE `".$TABLETOOLCOURSEDESC . "` (
  2397. $add_to_all_tables
  2398. id int UNSIGNED NOT NULL auto_increment,
  2399. title VARCHAR(255),
  2400. content TEXT,
  2401. session_id int default 0,
  2402. description_type tinyint unsigned NOT NULL default 0,
  2403. progress INT NOT NULL default 0,
  2404. PRIMARY KEY (c_id, id)
  2405. )" . $charset_clause;
  2406. Database::query($sql);
  2407. $sql = "ALTER TABLE `".$TABLETOOLCOURSEDESC . "` ADD INDEX ( session_id ) ";
  2408. Database::query($sql);
  2409. /* Course homepage tool list */
  2410. $sql = "
  2411. CREATE TABLE `" . $tbl_course_homepage . "` (
  2412. $add_to_all_tables
  2413. id int unsigned NOT NULL auto_increment,
  2414. name varchar(255) NOT NULL,
  2415. link varchar(255) NOT NULL,
  2416. image varchar(255) default NULL,
  2417. visibility tinyint unsigned default 0,
  2418. admin varchar(255) default NULL,
  2419. address varchar(255) default NULL,
  2420. added_tool tinyint unsigned default 1,
  2421. target enum('_self','_blank') NOT NULL default '_self',
  2422. category varchar(20) not null default 'authoring',
  2423. session_id int default 0,
  2424. PRIMARY KEY (c_id, id)
  2425. )" . $charset_clause;
  2426. Database::query($sql);
  2427. $sql = "ALTER TABLE `".$tbl_course_homepage . "` ADD INDEX ( session_id ) ";
  2428. Database::query($sql);
  2429. /* Agenda tool */
  2430. $sql = "
  2431. CREATE TABLE `".$TABLETOOLAGENDA . "` (
  2432. $add_to_all_tables
  2433. id int unsigned NOT NULL auto_increment,
  2434. title varchar(255) NOT NULL,
  2435. content text,
  2436. start_date datetime NOT NULL default '0000-00-00 00:00:00',
  2437. end_date datetime NOT NULL default '0000-00-00 00:00:00',
  2438. parent_event_id INT NULL,
  2439. session_id int unsigned NOT NULL default 0,
  2440. all_day INT NOT NULL DEFAULT 0,
  2441. PRIMARY KEY (c_id, id)
  2442. )" . $charset_clause;
  2443. Database::query($sql);
  2444. $sql = "ALTER TABLE `".$TABLETOOLAGENDA . "` ADD INDEX ( session_id ) ;";
  2445. Database::query($sql);
  2446. $sql = "
  2447. CREATE TABLE `".$TABLETOOLAGENDAREPEAT. "` (
  2448. $add_to_all_tables
  2449. cal_id INT DEFAULT 0 NOT NULL,
  2450. cal_type VARCHAR(20),
  2451. cal_end INT,
  2452. cal_frequency INT DEFAULT 1,
  2453. cal_days CHAR(7),
  2454. PRIMARY KEY (c_id, cal_id)
  2455. )" . $charset_clause;
  2456. Database::query($sql);
  2457. $sql = "
  2458. CREATE TABLE `".$TABLETOOLAGENDAREPEATNOT."` (
  2459. $add_to_all_tables
  2460. cal_id INT NOT NULL,
  2461. cal_date INT NOT NULL,
  2462. PRIMARY KEY (c_id, cal_id, cal_date )
  2463. )" . $charset_clause;
  2464. Database::query($sql);
  2465. // Agenda Attachment
  2466. $sql = "CREATE TABLE `".$TABLETOOLAGENDAATTACHMENT."` (
  2467. $add_to_all_tables
  2468. id int NOT NULL auto_increment,
  2469. path varchar(255) NOT NULL,
  2470. comment text,
  2471. size int NOT NULL default 0,
  2472. agenda_id int NOT NULL,
  2473. filename varchar(255) NOT NULL,
  2474. PRIMARY KEY (c_id, id)
  2475. )" . $charset_clause;
  2476. Database::query($sql);
  2477. /*
  2478. Document tool
  2479. */
  2480. $sql = "
  2481. CREATE TABLE `".$TABLETOOLDOCUMENT . "` (
  2482. $add_to_all_tables
  2483. id int unsigned NOT NULL auto_increment,
  2484. path varchar(255) NOT NULL default '',
  2485. comment text,
  2486. title varchar(255) default NULL,
  2487. filetype set('file','folder') NOT NULL default 'file',
  2488. size int NOT NULL default 0,
  2489. readonly TINYINT UNSIGNED NOT NULL,
  2490. session_id int UNSIGNED NOT NULL default 0,
  2491. PRIMARY KEY (c_id, id)
  2492. )" . $charset_clause;
  2493. Database::query($sql);
  2494. /*
  2495. Student publications
  2496. */
  2497. $sql = "
  2498. CREATE TABLE `".$TABLETOOLWORKS . "` (
  2499. $add_to_all_tables
  2500. id int unsigned NOT NULL auto_increment,
  2501. url varchar(255) default NULL,
  2502. title varchar(255) default NULL,
  2503. description text default NULL,
  2504. author varchar(255) default NULL,
  2505. active tinyint default NULL,
  2506. accepted tinyint default 0,
  2507. post_group_id int DEFAULT 0 NOT NULL,
  2508. sent_date datetime NOT NULL default '0000-00-00 00:00:00',
  2509. filetype set('file','folder') NOT NULL default 'file',
  2510. has_properties int UNSIGNED NOT NULL DEFAULT 0,
  2511. view_properties tinyint NULL,
  2512. qualification float(6,2) UNSIGNED NOT NULL DEFAULT 0,
  2513. date_of_qualification datetime NOT NULL default '0000-00-00 00:00:00',
  2514. parent_id INT UNSIGNED NOT NULL DEFAULT 0,
  2515. qualificator_id INT UNSIGNED NOT NULL DEFAULT 0,
  2516. weight float(6,2) UNSIGNED NOT NULL default 0,
  2517. session_id INT UNSIGNED NOT NULL default 0,
  2518. user_id INTEGER NOT NULL,
  2519. allow_text_assignment INTEGER NOT NULL DEFAULT 0,
  2520. contains_file INTEGER NOT NULL DEFAULT 0,
  2521. PRIMARY KEY (c_id, id)
  2522. )" . $charset_clause;
  2523. Database::query($sql);
  2524. $sql = "
  2525. CREATE TABLE `".$TABLETOOLWORKSASS."` (
  2526. $add_to_all_tables
  2527. id int NOT NULL auto_increment,
  2528. expires_on datetime NOT NULL default '0000-00-00 00:00:00',
  2529. ends_on datetime NOT NULL default '0000-00-00 00:00:00',
  2530. add_to_calendar tinyint NOT NULL,
  2531. enable_qualification tinyint NOT NULL,
  2532. publication_id int NOT NULL,
  2533. PRIMARY KEY (c_id, id)
  2534. )" . $charset_clause;
  2535. Database::query($sql);
  2536. $sql = "ALTER TABLE `".$TABLETOOLWORKS . "` ADD INDEX ( session_id )" ;
  2537. Database::query($sql);
  2538. /*
  2539. Links tool
  2540. */
  2541. $sql = "
  2542. CREATE TABLE `".$TABLETOOLLINK . "` (
  2543. $add_to_all_tables
  2544. id int unsigned NOT NULL auto_increment,
  2545. url TEXT NOT NULL,
  2546. title varchar(150) default NULL,
  2547. description text,
  2548. category_id int unsigned default NULL,
  2549. display_order int unsigned NOT NULL default 0,
  2550. on_homepage enum('0','1') NOT NULL default '0',
  2551. target char(10) default '_self',
  2552. session_id int default 0,
  2553. PRIMARY KEY (c_id, id)
  2554. )" . $charset_clause;
  2555. Database::query($sql);
  2556. $sql = "ALTER TABLE `".$TABLETOOLLINK . "` ADD INDEX ( session_id ) ";
  2557. Database::query($sql);
  2558. $sql = "
  2559. CREATE TABLE `".$TABLETOOLLINKCATEGORIES . "` (
  2560. $add_to_all_tables
  2561. id int unsigned NOT NULL auto_increment,
  2562. category_title varchar(255) NOT NULL,
  2563. description text,
  2564. display_order mediumint unsigned NOT NULL default 0,
  2565. session_id int default 0,
  2566. PRIMARY KEY (c_id, id)
  2567. )" . $charset_clause;
  2568. Database::query($sql);
  2569. $sql = "ALTER TABLE `".$TABLETOOLLINKCATEGORIES . "` ADD INDEX ( session_id ) ";
  2570. Database::query($sql);
  2571. /* Wiki */
  2572. $sql = "CREATE TABLE `".$TABLETOOLWIKI . "` (
  2573. $add_to_all_tables
  2574. id int NOT NULL auto_increment,
  2575. page_id int NOT NULL default 0,
  2576. reflink varchar(255) NOT NULL default 'index',
  2577. title varchar(255) NOT NULL,
  2578. content mediumtext NOT NULL,
  2579. user_id int NOT NULL default 0,
  2580. group_id int DEFAULT NULL,
  2581. dtime datetime NOT NULL default '0000-00-00 00:00:00',
  2582. addlock int NOT NULL default 1,
  2583. editlock int NOT NULL default 0,
  2584. visibility int NOT NULL default 1,
  2585. addlock_disc int NOT NULL default 1,
  2586. visibility_disc int NOT NULL default 1,
  2587. ratinglock_disc int NOT NULL default 1,
  2588. assignment int NOT NULL default 0,
  2589. comment text NOT NULL,
  2590. progress text NOT NULL,
  2591. score int NULL default 0,
  2592. version int default NULL,
  2593. is_editing int NOT NULL default 0,
  2594. time_edit datetime NOT NULL default '0000-00-00 00:00:00',
  2595. hits int default 0,
  2596. linksto text NOT NULL,
  2597. tag text NOT NULL,
  2598. user_ip varchar(39) NOT NULL,
  2599. session_id int default 0,
  2600. PRIMARY KEY (c_id, id),
  2601. KEY reflink (reflink),
  2602. KEY group_id (group_id),
  2603. KEY page_id (page_id),
  2604. KEY session_id (session_id)
  2605. )" . $charset_clause;
  2606. Database::query($sql);
  2607. $sql = "CREATE TABLE `".$TABLEWIKICONF . "` (
  2608. $add_to_all_tables
  2609. page_id int NOT NULL default 0,
  2610. task text NOT NULL,
  2611. feedback1 text NOT NULL,
  2612. feedback2 text NOT NULL,
  2613. feedback3 text NOT NULL,
  2614. fprogress1 varchar(3) NOT NULL,
  2615. fprogress2 varchar(3) NOT NULL,
  2616. fprogress3 varchar(3) NOT NULL,
  2617. max_size int default NULL,
  2618. max_text int default NULL,
  2619. max_version int default NULL,
  2620. startdate_assig datetime NOT NULL default '0000-00-00 00:00:00',
  2621. enddate_assig datetime NOT NULL default '0000-00-00 00:00:00',
  2622. delayedsubmit int NOT NULL default 0,
  2623. KEY page_id (page_id),
  2624. PRIMARY KEY ( c_id, page_id )
  2625. )" . $charset_clause;
  2626. Database::query($sql);
  2627. $sql = "CREATE TABLE `".$TABLEWIKIDISCUSS . "` (
  2628. $add_to_all_tables
  2629. id int NOT NULL auto_increment,
  2630. publication_id int NOT NULL default 0,
  2631. userc_id int NOT NULL default 0,
  2632. comment text NOT NULL,
  2633. p_score varchar(255) default NULL,
  2634. dtime datetime NOT NULL default '0000-00-00 00:00:00',
  2635. PRIMARY KEY (c_id, id)
  2636. )" . $charset_clause;
  2637. Database::query($sql);
  2638. $sql = "CREATE TABLE `".$TABLEWIKIMAILCUE . "` (
  2639. $add_to_all_tables
  2640. id int NOT NULL,
  2641. user_id int NOT NULL,
  2642. type text NOT NULL,
  2643. group_id int DEFAULT NULL,
  2644. session_id int default 0,
  2645. KEY (c_id, id),
  2646. PRIMARY KEY ( c_id, id, user_id )
  2647. )" . $charset_clause;
  2648. Database::query($sql);
  2649. /*
  2650. Online
  2651. */
  2652. $sql = "
  2653. CREATE TABLE `".$TABLETOOLONLINECONNECTED . "` (
  2654. $add_to_all_tables
  2655. user_id int unsigned NOT NULL,
  2656. last_connection datetime NOT NULL default '0000-00-00 00:00:00',
  2657. PRIMARY KEY (c_id, user_id)
  2658. )" . $charset_clause;
  2659. Database::query($sql);
  2660. $sql = "
  2661. CREATE TABLE `".$TABLETOOLONLINELINK . "` (
  2662. $add_to_all_tables
  2663. id int unsigned NOT NULL auto_increment,
  2664. name char(50) NOT NULL default '',
  2665. url char(100) NOT NULL,
  2666. PRIMARY KEY (c_id, id)
  2667. )" . $charset_clause;
  2668. Database::query($sql);
  2669. $sql = "
  2670. CREATE TABLE `".$TABLETOOLCHATCONNECTED . "` (
  2671. $add_to_all_tables
  2672. id int unsigned NOT NULL auto_increment,
  2673. user_id int unsigned NOT NULL default '0',
  2674. last_connection datetime NOT NULL default '0000-00-00 00:00:00',
  2675. session_id INT NOT NULL default 0,
  2676. to_group_id INT NOT NULL default 0,
  2677. PRIMARY KEY (c_id, id, user_id, last_connection)
  2678. )" . $charset_clause;
  2679. Database::query($sql);
  2680. $sql = "ALTER TABLE `".$TABLETOOLCHATCONNECTED . "` ADD INDEX char_connected_index(user_id, session_id, to_group_id) ";
  2681. Database::query($sql);
  2682. /*
  2683. Groups tool
  2684. */
  2685. Database::query("CREATE TABLE `".$TABLEGROUPS . "` (
  2686. $add_to_all_tables
  2687. id int unsigned NOT NULL auto_increment,
  2688. name varchar(100) default NULL,
  2689. category_id int unsigned NOT NULL default 0,
  2690. description text,
  2691. max_student int unsigned NOT NULL default 8,
  2692. doc_state tinyint unsigned NOT NULL default 1,
  2693. calendar_state tinyint unsigned NOT NULL default 0,
  2694. work_state tinyint unsigned NOT NULL default 0,
  2695. announcements_state tinyint unsigned NOT NULL default 0,
  2696. forum_state tinyint unsigned NOT NULL default 0,
  2697. wiki_state tinyint unsigned NOT NULL default 1,
  2698. chat_state tinyint unsigned NOT NULL default 1,
  2699. secret_directory varchar(255) default NULL,
  2700. self_registration_allowed tinyint unsigned NOT NULL default '0',
  2701. self_unregistration_allowed tinyint unsigned NOT NULL default '0',
  2702. session_id int unsigned NOT NULL default 0,
  2703. PRIMARY KEY (c_id, id)
  2704. )" . $charset_clause);
  2705. Database::query("ALTER TABLE `".$TABLEGROUPS . "` ADD INDEX ( session_id )");
  2706. Database::query("CREATE TABLE `".$TABLEGROUPCATEGORIES . "` (
  2707. $add_to_all_tables
  2708. id int unsigned NOT NULL auto_increment,
  2709. title varchar(255) NOT NULL default '',
  2710. description text NOT NULL,
  2711. doc_state tinyint unsigned NOT NULL default 1,
  2712. calendar_state tinyint unsigned NOT NULL default 1,
  2713. work_state tinyint unsigned NOT NULL default 1,
  2714. announcements_state tinyint unsigned NOT NULL default 1,
  2715. forum_state tinyint unsigned NOT NULL default 1,
  2716. wiki_state tinyint unsigned NOT NULL default 1,
  2717. chat_state tinyint unsigned NOT NULL default 1,
  2718. max_student int unsigned NOT NULL default 8,
  2719. self_reg_allowed tinyint unsigned NOT NULL default 0,
  2720. self_unreg_allowed tinyint unsigned NOT NULL default 0,
  2721. groups_per_user int unsigned NOT NULL default 0,
  2722. display_order int unsigned NOT NULL default 0,
  2723. PRIMARY KEY (c_id, id)
  2724. )" . $charset_clause);
  2725. Database::query("CREATE TABLE `".$TABLEGROUPUSER . "` (
  2726. $add_to_all_tables
  2727. id int unsigned NOT NULL auto_increment,
  2728. user_id int unsigned NOT NULL,
  2729. group_id int unsigned NOT NULL default 0,
  2730. status int NOT NULL default 0,
  2731. role char(50) NOT NULL,
  2732. PRIMARY KEY (c_id, id)
  2733. )" . $charset_clause);
  2734. Database::query("CREATE TABLE `".$TABLEGROUPTUTOR . "` (
  2735. $add_to_all_tables
  2736. id int NOT NULL auto_increment,
  2737. user_id int NOT NULL,
  2738. group_id int NOT NULL default 0,
  2739. PRIMARY KEY (c_id, id)
  2740. )" . $charset_clause);
  2741. Database::query("CREATE TABLE `".$TABLEITEMPROPERTY . "` (
  2742. $add_to_all_tables
  2743. id int NOT NULL auto_increment,
  2744. tool varchar(100) NOT NULL default '',
  2745. insert_user_id int unsigned NOT NULL default '0',
  2746. insert_date datetime NOT NULL default '0000-00-00 00:00:00',
  2747. lastedit_date datetime NOT NULL default '0000-00-00 00:00:00',
  2748. ref int NOT NULL default '0',
  2749. lastedit_type varchar(100) NOT NULL default '',
  2750. lastedit_user_id int unsigned NOT NULL default '0',
  2751. to_group_id int unsigned default NULL,
  2752. to_user_id int unsigned default NULL,
  2753. visibility tinyint NOT NULL default '1',
  2754. start_visible datetime NOT NULL default '0000-00-00 00:00:00',
  2755. end_visible datetime NOT NULL default '0000-00-00 00:00:00',
  2756. id_session INT NOT NULL DEFAULT 0,
  2757. PRIMARY KEY (c_id, id)
  2758. )" . $charset_clause);
  2759. Database::query("ALTER TABLE `$TABLEITEMPROPERTY` ADD INDEX idx_item_property_toolref (tool, ref)");
  2760. Database::query("ALTER TABLE `$TABLEITEMPROPERTY` ADD INDEX idx_itemprop_id_tool (c_id, tool(8))");
  2761. /* Tool introductions */
  2762. Database::query("
  2763. CREATE TABLE `".$TABLEINTROS . "` (
  2764. $add_to_all_tables
  2765. id varchar(50) NOT NULL,
  2766. intro_text MEDIUMTEXT NOT NULL,
  2767. session_id INT NOT NULL DEFAULT 0,
  2768. PRIMARY KEY (c_id, id, session_id)
  2769. )" . $charset_clause);
  2770. /* Dropbox tool */
  2771. Database::query("
  2772. CREATE TABLE `".$TABLETOOLDROPBOXFILE . "` (
  2773. $add_to_all_tables
  2774. id int unsigned NOT NULL auto_increment,
  2775. uploader_id int unsigned NOT NULL default 0,
  2776. filename varchar(250) NOT NULL default '',
  2777. filesize int unsigned NOT NULL,
  2778. title varchar(250) default '',
  2779. description varchar(250) default '',
  2780. author varchar(250) default '',
  2781. upload_date datetime NOT NULL default '0000-00-00 00:00:00',
  2782. last_upload_date datetime NOT NULL default '0000-00-00 00:00:00',
  2783. cat_id int NOT NULL default 0,
  2784. session_id int UNSIGNED NOT NULL,
  2785. PRIMARY KEY (c_id, id),
  2786. UNIQUE KEY UN_filename (filename)
  2787. )" . $charset_clause);
  2788. Database::query("ALTER TABLE `$TABLETOOLDROPBOXFILE` ADD INDEX ( session_id )");
  2789. Database::query("
  2790. CREATE TABLE `".$TABLETOOLDROPBOXPOST . "` (
  2791. $add_to_all_tables
  2792. file_id int unsigned NOT NULL,
  2793. dest_user_id int unsigned NOT NULL default 0,
  2794. feedback_date datetime NOT NULL default '0000-00-00 00:00:00',
  2795. feedback text default '',
  2796. cat_id int NOT NULL default 0,
  2797. session_id int UNSIGNED NOT NULL,
  2798. PRIMARY KEY (c_id, file_id, dest_user_id)
  2799. )" . $charset_clause);
  2800. Database::query("ALTER TABLE `$TABLETOOLDROPBOXPOST` ADD INDEX ( session_id )");
  2801. Database::query("
  2802. CREATE TABLE `".$TABLETOOLDROPBOXPERSON . "` (
  2803. $add_to_all_tables
  2804. file_id int unsigned NOT NULL,
  2805. user_id int unsigned NOT NULL default 0,
  2806. PRIMARY KEY (c_id, file_id, user_id)
  2807. )" . $charset_clause);
  2808. $sql = "CREATE TABLE `".$TABLETOOLDROPBOXCATEGORY."` (
  2809. $add_to_all_tables
  2810. cat_id int NOT NULL auto_increment,
  2811. cat_name text NOT NULL,
  2812. received tinyint unsigned NOT NULL default 0,
  2813. sent tinyint unsigned NOT NULL default 0,
  2814. user_id int NOT NULL default 0,
  2815. session_id int NOT NULL default 0,
  2816. PRIMARY KEY (c_id, cat_id)
  2817. )" . $charset_clause;
  2818. Database::query($sql);
  2819. $sql = "ALTER TABLE `".$TABLETOOLDROPBOXCATEGORY . "` ADD INDEX ( session_id ) ";
  2820. Database::query($sql);
  2821. $sql = "CREATE TABLE `".$TABLETOOLDROPBOXFEEDBACK."` (
  2822. $add_to_all_tables
  2823. feedback_id int NOT NULL auto_increment,
  2824. file_id int NOT NULL default 0,
  2825. author_user_id int NOT NULL default 0,
  2826. feedback text NOT NULL,
  2827. feedback_date datetime NOT NULL default '0000-00-00 00:00:00',
  2828. PRIMARY KEY (c_id, feedback_id),
  2829. KEY file_id (file_id),
  2830. KEY author_user_id (author_user_id)
  2831. )" . $charset_clause;
  2832. Database::query($sql);
  2833. /*
  2834. New learning path tool
  2835. */
  2836. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELP` (
  2837. $add_to_all_tables
  2838. " .
  2839. "id int unsigned auto_increment," . // unique ID, generated by MySQL
  2840. "lp_type int unsigned not null," . // lp_types can be found in the main database's lp_type table
  2841. "name varchar(255) not null," . // name is the text name of the learning path (e.g. Word 2000)
  2842. "ref tinytext null," . // ref for SCORM elements is the SCORM ID in imsmanifest. For other learnpath types, just ignore
  2843. "description text null,". // textual description
  2844. "path text not null," . // path, starting at the platforms root (so all paths should start with 'courses/...' for now)
  2845. "force_commit tinyint unsigned not null default 0, " . // stores the default behaviour regarding SCORM information
  2846. "default_view_mod char(32) not null default 'embedded'," . // stores the default view mode (embedded or fullscreen)
  2847. "default_encoding char(32) not null default 'UTF-8', " . // stores the encoding detected at learning path reading
  2848. "display_order int unsigned not null default 0," . // order of learnpaths display in the learnpaths list - not really important
  2849. "content_maker tinytext not null default ''," . // the content make for this course (ENI, Articulate, ...)
  2850. "content_local varchar(32) not null default 'local'," . // content localisation ('local' or 'distant')
  2851. "content_license text not null default ''," . // content license
  2852. "prevent_reinit tinyint unsigned not null default 1," . // stores the default behaviour regarding items re-initialisation when viewed a second time after success
  2853. "js_lib tinytext not null default ''," . // the JavaScript library to load for this lp
  2854. "debug tinyint unsigned not null default 0," . // stores the default behaviour regarding items re-initialisation when viewed a second time after success
  2855. "theme varchar(255) not null default '', " . // stores the theme of the LP
  2856. "preview_image varchar(255) not null default '', " . // stores the theme of the LP
  2857. "author varchar(255) not null default '', " . // stores the theme of the LP
  2858. "session_id int unsigned not null default 0, " . // the session_id
  2859. "prerequisite int unsigned not null default 0," . // pre requisite for next lp
  2860. "hide_toc_frame tinyint NOT NULL DEFAULT 0, ".
  2861. "seriousgame_mode tinyint NOT NULL DEFAULT 0, ".
  2862. "use_max_score int unsigned not null default 1, " .
  2863. "autolunch int unsigned not null default 0, " . // auto lunch LP
  2864. "created_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
  2865. "modified_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
  2866. "publicated_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
  2867. "expired_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  2868. PRIMARY KEY (c_id, id)
  2869. )" . $charset_clause;
  2870. Database::query($sql);
  2871. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELPVIEW` (
  2872. $add_to_all_tables" .
  2873. "id int unsigned auto_increment," . // unique ID from MySQL
  2874. "lp_id int unsigned not null," . // learnpath ID from 'lp'
  2875. "user_id int unsigned not null," . // user ID from main.user
  2876. "view_count int unsigned not null default 0," . // integer counting the amount of times this learning path has been attempted
  2877. "last_item int unsigned not null default 0," . // last item seen in this view
  2878. "progress int unsigned default 0," .
  2879. "session_id int not null default 0,
  2880. PRIMARY KEY (c_id, id)
  2881. )" . $charset_clause; // lp's progress for this user
  2882. Database::query($sql);
  2883. $sql = "ALTER TABLE `$TABLELPVIEW` ADD INDEX (lp_id) ";
  2884. Database::query($sql);
  2885. $sql = "ALTER TABLE `$TABLELPVIEW` ADD INDEX (user_id) ";
  2886. Database::query($sql);
  2887. $sql = "ALTER TABLE `$TABLELPVIEW` ADD INDEX (session_id) ";
  2888. Database::query($sql);
  2889. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELPITEM` (
  2890. $add_to_all_tables
  2891. " .
  2892. "id int unsigned auto_increment," . // unique ID from MySQL
  2893. "lp_id int unsigned not null," . // lp_id from 'lp'
  2894. "item_type char(32) not null default 'dokeos_document'," . // can be dokeos_document, dokeos_chapter or scorm_asset, scorm_sco, scorm_chapter
  2895. "ref tinytext not null default ''," . // the ID given to this item in the imsmanifest file
  2896. "title varchar(511) not null," . // the title/name of this item (to display in the T.O.C.)
  2897. "description varchar(511) not null default ''," . // the description of this item - deprecated
  2898. "path text not null," . // the path to that item, starting at 'courses/...' level
  2899. "min_score float unsigned not null default 0," . // min score allowed
  2900. "max_score float unsigned default 100," . // max score allowed
  2901. "mastery_score float unsigned null," . // minimum score to pass the test
  2902. "parent_item_id int unsigned not null default 0," . // the item one level higher
  2903. "previous_item_id int unsigned not null default 0," . // the item before this one in the sequential learning order (MySQL id)
  2904. "next_item_id int unsigned not null default 0," . // the item after this one in the sequential learning order (MySQL id)
  2905. "display_order int unsigned not null default 0," . // this is needed for ordering items under the same parent (previous_item_id doesn't give correct order after reordering)
  2906. "prerequisite text null default null," . // prerequisites in AICC scripting language as defined in the SCORM norm (allow logical operators)
  2907. "parameters text null," . // prerequisites in AICC scripting language as defined in the SCORM norm (allow logical operators)
  2908. "launch_data text not null default ''," . // data from imsmanifest <item>
  2909. "max_time_allowed char(13) NULL default ''," . // data from imsmanifest <adlcp:maxtimeallowed>
  2910. "terms TEXT NULL," . // contains the indexing tags (search engine)
  2911. "search_did INT NULL,". // contains the internal search-engine id of this element
  2912. "audio VARCHAR(250),
  2913. PRIMARY KEY (c_id, id)
  2914. )" . $charset_clause; // contains the audio file that goes with the learning path step
  2915. Database::query($sql);
  2916. $sql = "ALTER TABLE `$TABLELPITEM` ADD INDEX (lp_id)";
  2917. Database::query($sql);
  2918. $sql = "ALTER TABLE $TABLELPITEM ADD INDEX idx_c_lp_item_cid_lp_id (c_id, lp_id)";
  2919. Database::query($sql);
  2920. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELPITEMVIEW` (
  2921. $add_to_all_tables
  2922. " .
  2923. "id bigint unsigned auto_increment," . // unique ID
  2924. "lp_item_id int unsigned not null," . // item ID (MySQL id)
  2925. "lp_view_id int unsigned not null," . // learning path view id (attempt)
  2926. "view_count int unsigned not null default 0," . // how many times this item has been viewed in the current attempt (generally 0 or 1)
  2927. "start_time int unsigned not null," . // when did the user open it?
  2928. "total_time int unsigned not null default 0," . // after how many seconds did he close it?
  2929. "score float unsigned not null default 0," . // score returned by SCORM or other techs
  2930. "status char(32) not null default 'not attempted'," . // status for this item (SCORM)
  2931. "suspend_data longtext null default ''," .
  2932. "lesson_location text null default ''," .
  2933. "core_exit varchar(32) not null default 'none'," .
  2934. "max_score varchar(8) default '',
  2935. PRIMARY KEY (c_id, id)
  2936. )" . $charset_clause;
  2937. Database::query($sql);
  2938. $sql = "ALTER TABLE `$TABLELPITEMVIEW` ADD INDEX (lp_item_id) ";
  2939. Database::query($sql);
  2940. $sql = "ALTER TABLE `$TABLELPITEMVIEW` ADD INDEX (lp_view_id) ";
  2941. Database::query($sql);
  2942. $sql = "ALTER TABLE $TABLELPITEMVIEW ADD INDEX idx_c_lp_item_view_cid_lp_view_id_lp_item_id (c_id, lp_view_id, lp_item_id) ";
  2943. Database::query($sql);
  2944. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELPIVINTERACTION`(
  2945. $add_to_all_tables" .
  2946. "id bigint unsigned auto_increment," .
  2947. "order_id int unsigned not null default 0,". // internal order (0->...) given by Dokeos
  2948. "lp_iv_id bigint unsigned not null," . // identifier of the related sco_view
  2949. "interaction_id varchar(255) not null default ''," . // sco-specific, given by the sco
  2950. "interaction_type varchar(255) not null default ''," . // literal values, SCORM-specific (see p.63 of SCORM 1.2 RTE)
  2951. "weighting double not null default 0," .
  2952. "completion_time varchar(16) not null default ''," . // completion time for the interaction (timestamp in a day's time) - expected output format is scorm time
  2953. "correct_responses text not null default ''," . // actually a serialised array. See p.65 os SCORM 1.2 RTE)
  2954. "student_response text not null default ''," . // student response (format depends on type)
  2955. "result varchar(255) not null default ''," . // textual result
  2956. "latency varchar(16) not null default ''," . // time necessary for completion of the interaction
  2957. "PRIMARY KEY (c_id, id)".
  2958. ")" . $charset_clause;
  2959. Database::query($sql);
  2960. $sql = "ALTER TABLE `$TABLELPIVINTERACTION` ADD INDEX (lp_iv_id) ";
  2961. Database::query($sql);
  2962. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELPIVOBJECTIVE`(
  2963. $add_to_all_tables" .
  2964. "id bigint unsigned auto_increment," .
  2965. "lp_iv_id bigint unsigned not null," . // identifier of the related sco_view
  2966. "order_id int unsigned not null default 0,". // internal order (0->...) given by Dokeos
  2967. "objective_id varchar(255) not null default ''," . // sco-specific, given by the sco
  2968. "score_raw float unsigned not null default 0," . // score
  2969. "score_max float unsigned not null default 0," . // max score
  2970. "score_min float unsigned not null default 0," . // min score
  2971. "status char(32) not null default 'not attempted', " . //status, just as sco status
  2972. "PRIMARY KEY (c_id, id) ".
  2973. ")" . $charset_clause;
  2974. Database::query($sql);
  2975. $sql = "ALTER TABLE `$TABLELPIVOBJECTIVE` ADD INDEX (lp_iv_id) ";
  2976. Database::query($sql);
  2977. /* Blogs */
  2978. $sql = "
  2979. CREATE TABLE `" . $tbl_blogs . "` (
  2980. $add_to_all_tables
  2981. blog_id int NOT NULL AUTO_INCREMENT ,
  2982. blog_name varchar( 250 ) NOT NULL default '',
  2983. blog_subtitle varchar( 250 ) default NULL ,
  2984. date_creation datetime NOT NULL default '0000-00-00 00:00:00',
  2985. visibility tinyint unsigned NOT NULL default 0,
  2986. session_id int default 0,
  2987. PRIMARY KEY (c_id, blog_id )
  2988. )" . $charset_clause . " COMMENT = 'Table with blogs in this course';";
  2989. Database::query($sql);
  2990. $sql = "ALTER TABLE `".$tbl_blogs . "` ADD INDEX ( session_id ) ";
  2991. Database::query($sql);
  2992. $sql = "
  2993. CREATE TABLE `" . $tbl_blogs_comments . "` (
  2994. $add_to_all_tables
  2995. comment_id int NOT NULL AUTO_INCREMENT ,
  2996. title varchar( 250 ) NOT NULL default '',
  2997. comment longtext NOT NULL ,
  2998. author_id int NOT NULL default 0,
  2999. date_creation datetime NOT NULL default '0000-00-00 00:00:00',
  3000. blog_id int NOT NULL default 0,
  3001. post_id int NOT NULL default 0,
  3002. task_id int default NULL ,
  3003. parent_comment_id int NOT NULL default 0,
  3004. PRIMARY KEY (c_id, comment_id )
  3005. )" . $charset_clause . " COMMENT = 'Table with comments on posts in a blog';";
  3006. Database::query($sql);
  3007. $sql = "
  3008. CREATE TABLE `" . $tbl_blogs_posts . "` (
  3009. $add_to_all_tables
  3010. post_id int NOT NULL AUTO_INCREMENT ,
  3011. title varchar( 250 ) NOT NULL default '',
  3012. full_text longtext NOT NULL ,
  3013. date_creation datetime NOT NULL default '0000-00-00 00:00:00',
  3014. blog_id int NOT NULL default 0,
  3015. author_id int NOT NULL default 0,
  3016. PRIMARY KEY (c_id, post_id )
  3017. )" . $charset_clause . " COMMENT = 'Table with posts / blog.';";
  3018. Database::query($sql);
  3019. $sql = "
  3020. CREATE TABLE `" . $tbl_blogs_rating . "` (
  3021. $add_to_all_tables
  3022. rating_id int NOT NULL AUTO_INCREMENT ,
  3023. blog_id int NOT NULL default 0,
  3024. rating_type enum( 'post', 'comment' ) NOT NULL default 'post',
  3025. item_id int NOT NULL default 0,
  3026. user_id int NOT NULL default 0,
  3027. rating int NOT NULL default 0,
  3028. PRIMARY KEY (c_id, rating_id )
  3029. )" . $charset_clause . " COMMENT = 'Table with ratings for post/comments in a certain blog';";
  3030. Database::query($sql);
  3031. $sql = "
  3032. CREATE TABLE `" . $tbl_blogs_rel_user . "` (
  3033. $add_to_all_tables
  3034. blog_id int NOT NULL default 0,
  3035. user_id int NOT NULL default 0,
  3036. PRIMARY KEY ( c_id, blog_id , user_id )
  3037. )" . $charset_clause . " COMMENT = 'Table representing users subscribed to a blog';";
  3038. Database::query($sql);
  3039. $sql = "
  3040. CREATE TABLE `" . $tbl_blogs_tasks . "` (
  3041. $add_to_all_tables
  3042. task_id int NOT NULL AUTO_INCREMENT ,
  3043. blog_id int NOT NULL default 0,
  3044. title varchar( 250 ) NOT NULL default '',
  3045. description text NOT NULL ,
  3046. color varchar( 10 ) NOT NULL default '',
  3047. system_task tinyint unsigned NOT NULL default 0,
  3048. PRIMARY KEY (c_id, task_id )
  3049. )" . $charset_clause . " COMMENT = 'Table with tasks for a blog';";
  3050. Database::query($sql);
  3051. $sql = "
  3052. CREATE TABLE `" . $tbl_blogs_tasks_rel_user . "` (
  3053. $add_to_all_tables
  3054. blog_id int NOT NULL default 0,
  3055. user_id int NOT NULL default 0,
  3056. task_id int NOT NULL default 0,
  3057. target_date date NOT NULL default '0000-00-00',
  3058. PRIMARY KEY (c_id, blog_id , user_id , task_id )
  3059. )" . $charset_clause . " COMMENT = 'Table with tasks assigned to a user in a blog';";
  3060. Database::query($sql);
  3061. $sql ="CREATE TABLE `" .$tbl_blogs_attachment."` (
  3062. $add_to_all_tables
  3063. id int unsigned NOT NULL auto_increment,
  3064. path varchar(255) NOT NULL COMMENT 'the real filename',
  3065. comment text,
  3066. size int NOT NULL default '0',
  3067. post_id int NOT NULL,
  3068. filename varchar(255) NOT NULL COMMENT 'the user s file name',
  3069. blog_id int NOT NULL,
  3070. comment_id int NOT NULL default '0',
  3071. PRIMARY KEY (c_id, id)
  3072. )" . $charset_clause;
  3073. Database::query($sql);
  3074. $sql = "
  3075. CREATE TABLE `" . $tbl_permission_group . "` (
  3076. $add_to_all_tables
  3077. id int NOT NULL AUTO_INCREMENT ,
  3078. group_id int NOT NULL default 0,
  3079. tool varchar( 250 ) NOT NULL default '',
  3080. action varchar( 250 ) NOT NULL default '',
  3081. PRIMARY KEY (c_id, id)
  3082. )" . $charset_clause;
  3083. Database::query($sql);
  3084. $sql = "
  3085. CREATE TABLE `" . $tbl_permission_user . "` (
  3086. $add_to_all_tables
  3087. id int NOT NULL AUTO_INCREMENT ,
  3088. user_id int NOT NULL default 0,
  3089. tool varchar( 250 ) NOT NULL default '',
  3090. action varchar( 250 ) NOT NULL default '',
  3091. PRIMARY KEY (c_id, id )
  3092. )" . $charset_clause;
  3093. Database::query($sql);
  3094. $sql = "
  3095. CREATE TABLE `" . $tbl_permission_task . "` (
  3096. $add_to_all_tables
  3097. id int NOT NULL AUTO_INCREMENT,
  3098. task_id int NOT NULL default 0,
  3099. tool varchar( 250 ) NOT NULL default '',
  3100. action varchar( 250 ) NOT NULL default '',
  3101. PRIMARY KEY (c_id, id )
  3102. )" . $charset_clause;
  3103. Database::query($sql);
  3104. $sql = "
  3105. CREATE TABLE `" . $tbl_role . "` (
  3106. $add_to_all_tables
  3107. role_id int NOT NULL AUTO_INCREMENT,
  3108. role_name varchar( 250 ) NOT NULL default '',
  3109. role_comment text,
  3110. default_role tinyint default 0,
  3111. PRIMARY KEY (c_id, role_id)
  3112. )" . $charset_clause;
  3113. Database::query($sql);
  3114. $sql = "
  3115. CREATE TABLE `" . $tbl_role_group . "` (
  3116. $add_to_all_tables
  3117. id int NOT NULL AUTO_INCREMENT,
  3118. role_id int NOT NULL default 0,
  3119. scope varchar( 20 ) NOT NULL default 'course',
  3120. group_id int NOT NULL default 0,
  3121. PRIMARY KEY (id, c_id, group_id )
  3122. )" . $charset_clause;
  3123. Database::query($sql);
  3124. $sql = "
  3125. CREATE TABLE `" . $tbl_role_permissions . "` (
  3126. $add_to_all_tables
  3127. id int NOT NULL AUTO_INCREMENT,
  3128. role_id int NOT NULL default 0,
  3129. tool varchar( 250 ) NOT NULL default '',
  3130. action varchar( 50 ) NOT NULL default '',
  3131. default_perm tinyint NOT NULL default 0,
  3132. PRIMARY KEY (id, c_id, role_id, tool, action )
  3133. )" . $charset_clause;
  3134. Database::query($sql);
  3135. $sql = "
  3136. CREATE TABLE `" . $tbl_role_user . "` (
  3137. $add_to_all_tables
  3138. role_id int NOT NULL default 0,
  3139. scope varchar( 20 ) NOT NULL default 'course',
  3140. user_id int NOT NULL default 0,
  3141. PRIMARY KEY ( c_id, role_id, user_id )
  3142. )" . $charset_clause;
  3143. Database::query($sql);
  3144. /*
  3145. * Course Config Settings
  3146. *
  3147. */
  3148. Database::query("
  3149. CREATE TABLE `".$TABLESETTING . "` (
  3150. $add_to_all_tables
  3151. id int unsigned NOT NULL auto_increment,
  3152. variable varchar(255) NOT NULL default '',
  3153. subkey varchar(255) default NULL,
  3154. type varchar(255) default NULL,
  3155. category varchar(255) default NULL,
  3156. value varchar(255) NOT NULL default '',
  3157. title varchar(255) NOT NULL default '',
  3158. comment varchar(255) default NULL,
  3159. subkeytext varchar(255) default NULL,
  3160. PRIMARY KEY (c_id, id)
  3161. )" . $charset_clause);
  3162. /*
  3163. Survey
  3164. */
  3165. $sql = "CREATE TABLE `".$TABLESURVEY."` (
  3166. $add_to_all_tables
  3167. survey_id int unsigned NOT NULL auto_increment,
  3168. code varchar(20) default NULL,
  3169. title text default NULL,
  3170. subtitle text default NULL,
  3171. author varchar(20) default NULL,
  3172. lang varchar(20) default NULL,
  3173. avail_from date default NULL,
  3174. avail_till date default NULL,
  3175. is_shared char(1) default '1',
  3176. template varchar(20) default NULL,
  3177. intro text,
  3178. surveythanks text,
  3179. creation_date datetime NOT NULL default '0000-00-00 00:00:00',
  3180. invited int NOT NULL,
  3181. answered int NOT NULL,
  3182. invite_mail text NOT NULL,
  3183. reminder_mail text NOT NULL,
  3184. mail_subject VARCHAR( 255 ) NOT NULL,
  3185. anonymous enum('0','1') NOT NULL default '0',
  3186. access_condition TEXT DEFAULT NULL,
  3187. shuffle bool NOT NULL default '0',
  3188. one_question_per_page bool NOT NULL default '0',
  3189. survey_version varchar(255) NOT NULL default '',
  3190. parent_id int unsigned NOT NULL,
  3191. survey_type int NOT NULL default 0,
  3192. show_form_profile int NOT NULL default 0,
  3193. form_fields TEXT NOT NULL,
  3194. session_id int unsigned NOT NULL default 0,
  3195. PRIMARY KEY (c_id, survey_id)
  3196. )" . $charset_clause;
  3197. $result = Database::query($sql);
  3198. $sql = "ALTER TABLE `".$TABLESURVEY."` ADD INDEX ( session_id )";
  3199. Database::query($sql);
  3200. $sql = "CREATE TABLE `".$TABLESURVEYINVITATION."` (
  3201. $add_to_all_tables
  3202. survey_invitation_id int unsigned NOT NULL auto_increment,
  3203. survey_code varchar(20) NOT NULL,
  3204. user varchar(250) NOT NULL,
  3205. invitation_code varchar(250) NOT NULL,
  3206. invitation_date datetime NOT NULL,
  3207. reminder_date datetime NOT NULL,
  3208. answered int NOT NULL default 0,
  3209. session_id int UNSIGNED NOT NULL default 0,
  3210. PRIMARY KEY (c_id, survey_invitation_id)
  3211. )" . $charset_clause;
  3212. $result = Database::query($sql);
  3213. $sql = "CREATE TABLE `".$TABLESURVEYQUESTION."` (
  3214. $add_to_all_tables
  3215. question_id int unsigned NOT NULL auto_increment,
  3216. survey_id int unsigned NOT NULL,
  3217. survey_question text NOT NULL,
  3218. survey_question_comment text NOT NULL,
  3219. type varchar(250) NOT NULL,
  3220. display varchar(10) NOT NULL,
  3221. sort int NOT NULL,
  3222. shared_question_id int,
  3223. max_value int,
  3224. survey_group_pri int unsigned NOT NULL default '0',
  3225. survey_group_sec1 int unsigned NOT NULL default '0',
  3226. survey_group_sec2 int unsigned NOT NULL default '0',
  3227. PRIMARY KEY (c_id, question_id)
  3228. )" . $charset_clause;
  3229. $result = Database::query($sql);
  3230. $sql ="CREATE TABLE `".$TABLESURVEYQUESTIONOPTION."` (
  3231. $add_to_all_tables
  3232. question_option_id int unsigned NOT NULL auto_increment,
  3233. question_id int unsigned NOT NULL,
  3234. survey_id int unsigned NOT NULL,
  3235. option_text text NOT NULL,
  3236. sort int NOT NULL,
  3237. value int NOT NULL default '0',
  3238. PRIMARY KEY (c_id, question_option_id)
  3239. )" . $charset_clause;
  3240. $result = Database::query($sql);
  3241. $sql = "CREATE TABLE `".$TABLESURVEYANSWER."` (
  3242. $add_to_all_tables
  3243. answer_id int unsigned NOT NULL auto_increment,
  3244. survey_id int unsigned NOT NULL,
  3245. question_id int unsigned NOT NULL,
  3246. option_id TEXT NOT NULL,
  3247. value int unsigned NOT NULL,
  3248. user varchar(250) NOT NULL,
  3249. PRIMARY KEY (c_id, answer_id)
  3250. )" . $charset_clause;
  3251. $result = Database::query($sql);
  3252. $sql = "CREATE TABLE `".$TABLESURVEYGROUP."` (
  3253. $add_to_all_tables
  3254. id int unsigned NOT NULL auto_increment,
  3255. name varchar(20) NOT NULL,
  3256. description varchar(255) NOT NULL,
  3257. survey_id int unsigned NOT NULL,
  3258. PRIMARY KEY (c_id, id)
  3259. )" . $charset_clause;
  3260. $result = Database::query($sql);
  3261. // Table glosary
  3262. $sql = "CREATE TABLE `".$TBL_GLOSSARY."` (
  3263. $add_to_all_tables
  3264. glossary_id int unsigned NOT NULL auto_increment,
  3265. name varchar(255) NOT NULL,
  3266. description text not null,
  3267. display_order int,
  3268. session_id int default 0,
  3269. PRIMARY KEY (c_id, glossary_id)
  3270. )" . $charset_clause;
  3271. $result = Database::query($sql);
  3272. $sql = "ALTER TABLE `".$TBL_GLOSSARY . "` ADD INDEX ( session_id ) ";
  3273. Database::query($sql);
  3274. // Table notebook
  3275. $sql = "CREATE TABLE `".$TBL_NOTEBOOK."` (
  3276. $add_to_all_tables
  3277. notebook_id int unsigned NOT NULL auto_increment,
  3278. user_id int unsigned NOT NULL,
  3279. course varchar(40) not null,
  3280. session_id int NOT NULL default 0,
  3281. title varchar(255) NOT NULL,
  3282. description text NOT NULL,
  3283. creation_date datetime NOT NULL default '0000-00-00 00:00:00',
  3284. update_date datetime NOT NULL default '0000-00-00 00:00:00',
  3285. status int,
  3286. PRIMARY KEY (c_id, notebook_id)
  3287. )" . $charset_clause;
  3288. $result = Database::query($sql);
  3289. /* Attendance tool */
  3290. // Attendance table
  3291. $sql = "
  3292. CREATE TABLE `".$TBL_ATTENDANCE."` (
  3293. $add_to_all_tables
  3294. id int NOT NULL auto_increment,
  3295. name text NOT NULL,
  3296. description TEXT NULL,
  3297. active tinyint NOT NULL default 1,
  3298. attendance_qualify_title varchar(255) NULL,
  3299. attendance_qualify_max int NOT NULL default 0,
  3300. attendance_weight float(6,2) NOT NULL default '0.0',
  3301. session_id int NOT NULL default 0,
  3302. locked int NOT NULL default 0,
  3303. PRIMARY KEY (c_id, id)
  3304. )" . $charset_clause;
  3305. $result = Database::query($sql);
  3306. $sql = "ALTER TABLE `".$TBL_ATTENDANCE . "` ADD INDEX (session_id)";
  3307. Database::query($sql);
  3308. $sql = "ALTER TABLE `".$TBL_ATTENDANCE . "` ADD INDEX (active)";
  3309. Database::query($sql);
  3310. // Attendance sheet table
  3311. $sql = "
  3312. CREATE TABLE `".$TBL_ATTENDANCE_SHEET."` (
  3313. $add_to_all_tables
  3314. user_id int NOT NULL,
  3315. attendance_calendar_id int NOT NULL,
  3316. presence tinyint NOT NULL DEFAULT 0,
  3317. PRIMARY KEY(c_id, user_id, attendance_calendar_id)
  3318. )" . $charset_clause;
  3319. $result = Database::query($sql);
  3320. $sql = "ALTER TABLE `".$TBL_ATTENDANCE_SHEET . "` ADD INDEX (presence) ";
  3321. Database::query($sql);
  3322. // Attendance calendar table
  3323. $sql = "
  3324. CREATE TABLE `".$TBL_ATTENDANCE_CALENDAR."` (
  3325. $add_to_all_tables
  3326. id int NOT NULL auto_increment,
  3327. attendance_id int NOT NULL ,
  3328. date_time datetime NOT NULL default '0000-00-00 00:00:00',
  3329. done_attendance tinyint NOT NULL default 0,
  3330. PRIMARY KEY(c_id, id)
  3331. )" . $charset_clause;
  3332. $result = Database::query($sql);
  3333. $sql = "ALTER TABLE `".$TBL_ATTENDANCE_CALENDAR."` ADD INDEX (attendance_id)";
  3334. Database::query($sql);
  3335. $sql = "ALTER TABLE `".$TBL_ATTENDANCE_CALENDAR."` ADD INDEX (done_attendance)";
  3336. Database::query($sql);
  3337. // Attendance result table
  3338. $sql = "
  3339. CREATE TABLE `".$TBL_ATTENDANCE_RESULT."` (
  3340. $add_to_all_tables
  3341. id int NOT NULL auto_increment,
  3342. user_id int NOT NULL,
  3343. attendance_id int NOT NULL,
  3344. score int NOT NULL DEFAULT 0,
  3345. PRIMARY KEY (c_id, id)
  3346. )" . $charset_clause;
  3347. $result = Database::query($sql);
  3348. $sql = "ALTER TABLE `".$TBL_ATTENDANCE_RESULT."` ADD INDEX (attendance_id)";
  3349. Database::query($sql);
  3350. $sql = "ALTER TABLE `".$TBL_ATTENDANCE_RESULT."` ADD INDEX (user_id)";
  3351. Database::query($sql);
  3352. // attendance sheet log table
  3353. $sql = "CREATE TABLE `".$TBL_ATTENDANCE_SHEET_LOG."` (
  3354. $add_to_all_tables
  3355. id int NOT NULL auto_increment,
  3356. attendance_id int NOT NULL DEFAULT 0,
  3357. lastedit_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  3358. lastedit_type varchar(200) NOT NULL,
  3359. lastedit_user_id int NOT NULL DEFAULT 0,
  3360. calendar_date_value datetime NULL,
  3361. PRIMARY KEY (c_id, id)
  3362. )" . $charset_clause;
  3363. $result = Database::query($sql) or die(Database::error());
  3364. // Thematic table
  3365. $sql = "CREATE TABLE `".$TBL_THEMATIC."` (
  3366. $add_to_all_tables
  3367. id int NOT NULL auto_increment,
  3368. title varchar(255) NOT NULL,
  3369. content text NULL,
  3370. display_order int unsigned NOT NULL DEFAULT 0,
  3371. active tinyint NOT NULL DEFAULT 0,
  3372. session_id int NOT NULL DEFAULT 0,
  3373. PRIMARY KEY (c_id, id)
  3374. )" . $charset_clause;
  3375. $result = Database::query($sql);
  3376. $sql = "ALTER TABLE `".$TBL_THEMATIC."` ADD INDEX (active, session_id)";
  3377. Database::query($sql);
  3378. // thematic plan table
  3379. $sql = "CREATE TABLE `".$TBL_THEMATIC_PLAN."` (
  3380. $add_to_all_tables
  3381. id int NOT NULL auto_increment,
  3382. thematic_id int NOT NULL,
  3383. title varchar(255) NOT NULL,
  3384. description text NULL,
  3385. description_type int NOT NULL,
  3386. PRIMARY KEY (c_id, id)
  3387. )" . $charset_clause;
  3388. $result = Database::query($sql);
  3389. $sql = "ALTER TABLE `".$TBL_THEMATIC_PLAN."` ADD INDEX (thematic_id, description_type)";
  3390. Database::query($sql);
  3391. // thematic advance table
  3392. $sql = "
  3393. CREATE TABLE `".$TBL_THEMATIC_ADVANCE."` (
  3394. $add_to_all_tables
  3395. id int NOT NULL auto_increment,
  3396. thematic_id int NOT NULL,
  3397. attendance_id int NOT NULL DEFAULT 0,
  3398. content text NULL,
  3399. start_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  3400. duration int NOT NULL DEFAULT 0,
  3401. done_advance tinyint NOT NULL DEFAULT 0,
  3402. PRIMARY KEY (c_id, id)
  3403. )" . $charset_clause;
  3404. $result = Database::query($sql);
  3405. $sql = "ALTER TABLE `".$TBL_THEMATIC_ADVANCE."` ADD INDEX (thematic_id)";
  3406. Database::query($sql);
  3407. $sql = "CREATE TABLE IF NOT EXISTS " . $TBL_METADATA . " ( " .
  3408. $add_to_all_tables.
  3409. "eid VARCHAR(250) NOT NULL," . // entry-id, e.g. doc.1
  3410. "mdxmltext TEXT default ''," . // MD-text, XML-formatted
  3411. "md5 CHAR(32) default ''," . // hash-validator
  3412. "htmlcache1 TEXT default ''," . // cached HTML, part 1
  3413. "htmlcache2 TEXT default ''," . // cached HTML, part 2
  3414. "indexabletext TEXT default ''," . // indexable for search
  3415. "PRIMARY KEY (c_id, eid) )".$charset_clause;
  3416. Database::query($sql);
  3417. $sql = "CREATE TABLE IF NOT EXISTS " . $TBL_METADATA . " ( " .
  3418. $add_to_all_tables.
  3419. "eid VARCHAR(250) NOT NULL," . // entry-id, e.g. doc.1
  3420. "mdxmltext TEXT default ''," . // MD-text, XML-formatted
  3421. "md5 CHAR(32) default ''," . // hash-validator
  3422. "htmlcache1 TEXT default ''," . // cached HTML, part 1
  3423. "htmlcache2 TEXT default ''," . // cached HTML, part 2
  3424. "indexabletext TEXT default ''," . // indexable for search
  3425. "PRIMARY KEY (c_id, eid) )".$charset_clause;
  3426. Database::query($sql);
  3427. $table_quiz_order = $course_db_name . 'quiz_order';
  3428. $sql = " CREATE TABLE $table_quiz_order(
  3429. id int unsigned NOT NULL auto_increment,
  3430. c_id int unsigned NOT NULL,
  3431. session_id int unsigned NOT NULL,
  3432. exercise_id int NOT NULL,
  3433. exercise_order INT NOT NULL,
  3434. PRIMARY KEY (id)
  3435. ) ".$charset_clause;
  3436. Database::query($sql);
  3437. return 0;
  3438. }