add_course.lib.inc.php 135 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is the course creation library for Chamilo.
  5. * Include/require it in your code for using its functionality.
  6. *
  7. * @package chamilo.library
  8. * @todo Clean up horrible structure, script is unwieldy, for example easier way to deal with
  9. * different tool visibility settings: ALL_TOOLS_INVISIBLE, ALL_TOOLS_VISIBLE, CORE_TOOLS_VISIBLE...
  10. */
  11. /**
  12. * Code
  13. */
  14. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  15. /* FUNCTIONS */
  16. /**
  17. * Generates a course code from a course title
  18. * @todo Such a function might be useful in other places too. It might be moved in the CourseManager class.
  19. * @todo the function might be upgraded for avoiding code duplications (currently, it might suggest a code that is already in use)
  20. * @param string A course title
  21. * @param string The course title encoding (defaults to type defined globally)
  22. * @return string A proposed course code
  23. * @assert (null,null) === false
  24. * @assert ('ABC_DEF', null) === 'ABCDEF'
  25. * @assert ('ABC09*^[%A', null) === 'ABC09A'
  26. */
  27. function generate_course_code($course_title, $encoding = null) {
  28. if (empty($encoding)) {
  29. $encoding = api_get_system_encoding();
  30. }
  31. return substr(preg_replace('/[^A-Z0-9]/', '', strtoupper(api_transliterate($course_title, 'X', $encoding))), 0, CourseManager::MAX_COURSE_LENGTH_CODE);
  32. }
  33. /**
  34. * Defines the four needed keys to create a course based on several parameters.
  35. * @param string The code you want for this course
  36. * @param string Prefix added for ALL keys
  37. * @param string Prefix added for databases only
  38. * @param string Prefix added for paths only
  39. * @param bool Add unique prefix
  40. * @param bool Use code-independent keys
  41. * @return array An array with the needed keys ['currentCourseCode'], ['currentCourseId'], ['currentCourseDbName'], ['currentCourseRepository']
  42. * @todo Eliminate the global variables.
  43. * @assert (null) === false
  44. */
  45. function define_course_keys($wanted_code, $prefix_for_all = '', $prefix_for_base_name = '', $prefix_for_path = '', $add_unique_prefix = false, $use_code_indepedent_keys = true) {
  46. global $prefixAntiNumber, $_configuration;
  47. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  48. $wanted_code = generate_course_code($wanted_code);
  49. $keys_course_code = $wanted_code;
  50. if (!$use_code_indepedent_keys) {
  51. $wanted_code = '';
  52. }
  53. if ($add_unique_prefix) {
  54. $unique_prefix = substr(md5(uniqid(rand())), 0, 10);
  55. } else {
  56. $unique_prefix = '';
  57. }
  58. $keys = array();
  59. $final_suffix = array('CourseId' => '', 'CourseDb' => '', 'CourseDir' => '');
  60. $limit_numb_try = 100;
  61. $keys_are_unique = false;
  62. $try_new_fsc_id = $try_new_fsc_db = $try_new_fsc_dir = 0;
  63. while (!$keys_are_unique) {
  64. $keys_course_id = $prefix_for_all . $unique_prefix . $wanted_code . $final_suffix['CourseId'];
  65. //$keys_course_db_name = $prefix_for_base_name . $unique_prefix . strtoupper($keys_course_id) . $final_suffix['CourseDb'];
  66. $keys_course_repository = $prefix_for_path . $unique_prefix . $wanted_code . $final_suffix['CourseDir'];
  67. $keys_are_unique = true;
  68. // Check whether they are unique.
  69. $query = "SELECT 1 FROM ".$course_table." WHERE code='".$keys_course_id."' LIMIT 0,1";
  70. $result = Database::query($query);
  71. if (Database::num_rows($result)) {
  72. $keys_are_unique = false;
  73. $try_new_fsc_id ++;
  74. $final_suffix['CourseId'] = substr(md5(uniqid(rand())), 0, 4);
  75. }
  76. if (file_exists(api_get_path(SYS_COURSE_PATH).$keys_course_repository)) {
  77. $keys_are_unique = false;
  78. $try_new_fsc_dir ++;
  79. $final_suffix['CourseDir'] = substr(md5(uniqid(rand())), 0, 4);
  80. }
  81. if (($try_new_fsc_id + $try_new_fsc_db + $try_new_fsc_dir) > $limit_numb_try) {
  82. return $keys;
  83. }
  84. }
  85. $keys['currentCourseCode'] = $keys_course_code;
  86. $keys['currentCourseId'] = $keys_course_id;
  87. $keys['currentCourseRepository'] = $keys_course_repository;
  88. return $keys;
  89. }
  90. /**
  91. * Initializes a file repository for a newly created course.
  92. * @param string Course repository
  93. * @param string Course code
  94. * @return int 0
  95. * @assert (null,null) === false
  96. */
  97. function prepare_course_repository($course_repository, $course_code) {
  98. $perm = api_get_permissions_for_new_directories();
  99. $perm_file = api_get_permissions_for_new_files();
  100. $htmlpage = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <title>Not authorized</title>\n </head>\n <body>\n </body>\n</html>";
  101. $cp = api_get_path(SYS_COURSE_PATH).$course_repository;
  102. //Creating document folder
  103. mkdir($cp, $perm);
  104. mkdir($cp . '/document', $perm);
  105. $cpt = $cp.'/document/index.html';
  106. $fd = fopen($cpt, 'w');
  107. fwrite($fd, $htmlpage);
  108. fclose($fd);
  109. /*
  110. @chmod($cpt, $perm_file);
  111. @copy($cpt, $cp . '/document/index.html');
  112. mkdir($cp . '/document/images', $perm);
  113. @copy($cpt, $cp . '/document/images/index.html');
  114. mkdir($cp . '/document/images/gallery/', $perm);
  115. @copy($cpt, $cp . '/document/images/gallery/index.html');
  116. mkdir($cp . '/document/shared_folder/', $perm);
  117. @copy($cpt, $cp . '/document/shared_folder/index.html');
  118. mkdir($cp . '/document/audio', $perm);
  119. @copy($cpt, $cp . '/document/audio/index.html');
  120. mkdir($cp . '/document/flash', $perm);
  121. @copy($cpt, $cp . '/document/flash/index.html');
  122. mkdir($cp . '/document/video', $perm);
  123. @copy($cpt, $cp . '/document/video/index.html'); */
  124. //Creatind dropbox folder
  125. mkdir($cp . '/dropbox', $perm);
  126. $cpt = $cp.'/dropbox/index.html';
  127. $fd = fopen($cpt, 'w');
  128. fwrite($fd, $htmlpage);
  129. fclose($fd);
  130. @chmod($cpt, $perm_file);
  131. mkdir($cp . '/group', $perm);
  132. @copy($cpt, $cp . '/group/index.html');
  133. mkdir($cp . '/page', $perm);
  134. @copy($cpt, $cp . '/page/index.html');
  135. mkdir($cp . '/scorm', $perm);
  136. @copy($cpt, $cp . '/scorm/index.html');
  137. mkdir($cp . '/upload', $perm);
  138. @copy($cpt, $cp . '/upload/index.html');
  139. mkdir($cp . '/upload/forum', $perm);
  140. @copy($cpt, $cp . '/upload/forum/index.html');
  141. mkdir($cp . '/upload/forum/images', $perm);
  142. @copy($cpt, $cp . '/upload/forum/images/index.html');
  143. mkdir($cp . '/upload/test', $perm);
  144. @copy($cpt, $cp . '/upload/test/index.html');
  145. mkdir($cp . '/upload/blog', $perm);
  146. @copy($cpt, $cp . '/upload/blog/index.html');
  147. mkdir($cp . '/upload/learning_path', $perm);
  148. @copy($cpt, $cp . '/upload/learning_path/index.html');
  149. mkdir($cp . '/upload/learning_path/images', $perm);
  150. @copy($cpt, $cp . '/upload/learning_path/images/index.html');
  151. mkdir($cp . '/upload/calendar', $perm);
  152. @copy($cpt, $cp . '/upload/calendar/index.html');
  153. mkdir($cp . '/upload/calendar/images', $perm);
  154. @copy($cpt, $cp . '/upload/calendar/images/index.html');
  155. mkdir($cp . '/work', $perm);
  156. @copy($cpt, $cp . '/work/index.html');
  157. mkdir($cp . '/upload/announcements', $perm);
  158. @copy($cpt, $cp . '/upload/announcements/index.html');
  159. mkdir($cp . '/upload/announcements/images', $perm);
  160. @copy($cpt, $cp . '/upload/announcements/images/index.html');
  161. //Oral expression question type
  162. mkdir($cp . '/exercises', $perm);
  163. @copy($cpt, $cp . '/exercises/index.html');
  164. // Create .htaccess in the dropbox directory.
  165. $fp = fopen($cp . '/dropbox/.htaccess', 'w');
  166. fwrite($fp, "AuthName AllowLocalAccess
  167. AuthType Basic
  168. order deny,allow
  169. deny from all
  170. php_flag zlib.output_compression off");
  171. fclose($fp);
  172. // Build index.php of the course.
  173. $fd = fopen($cp . '/index.php', 'w');
  174. // str_replace() removes \r that cause squares to appear at the end of each line
  175. //@todo fix the harcoded include
  176. $string = str_replace("\r", "", "<?" . "php
  177. \$cidReq = \"$course_code\";
  178. \$dbname = \"$course_code\";
  179. include(\"".api_get_path(SYS_CODE_PATH)."course_home/course_home.php\");
  180. ?>");
  181. fwrite($fd, $string);
  182. @chmod($cp . '/index.php',$perm_file);
  183. return 0;
  184. };
  185. /**
  186. * Gets an array with all the course tables (deprecated?)
  187. * @return array
  188. * @assert (null) !== null
  189. */
  190. function get_course_tables() {
  191. $tables = array();
  192. $tables[]= 'tool';
  193. $tables[]= 'tool_intro';
  194. $tables[]= 'group_info';
  195. $tables[]= 'group_category';
  196. $tables[]= 'group_rel_user';
  197. $tables[]= 'group_rel_tutor';
  198. $tables[]= 'item_property';
  199. $tables[]= 'userinfo_content';
  200. $tables[]= 'userinfo_def';
  201. $tables[]= 'course_description';
  202. $tables[]= 'calendar_event';
  203. $tables[]= 'calendar_event_repeat';
  204. $tables[]= 'calendar_event_repeat_not';
  205. $tables[]= 'calendar_event_attachment';
  206. $tables[]= 'announcement';
  207. $tables[]= 'announcement_attachment';
  208. $tables[]= 'resource';
  209. $tables[]= 'student_publication';
  210. $tables[]= 'student_publication_assignment';
  211. $tables[]= 'document';
  212. $tables[]= 'forum_category';
  213. $tables[]= 'forum_forum';
  214. $tables[]= 'forum_thread';
  215. $tables[]= 'forum_post';
  216. $tables[]= 'forum_mailcue';
  217. $tables[]= 'forum_attachment';
  218. $tables[]= 'forum_notification';
  219. $tables[]= 'forum_thread_qualify';
  220. $tables[]= 'forum_thread_qualify_log';
  221. $tables[]= 'link';
  222. $tables[]= 'link_category';
  223. $tables[]= 'online_connected';
  224. $tables[]= 'online_link';
  225. $tables[]= 'chat_connected';
  226. $tables[]= 'quiz';
  227. $tables[]= 'quiz_rel_question';
  228. $tables[]= 'quiz_question';
  229. $tables[]= 'quiz_answer';
  230. $tables[]= 'quiz_question_option';
  231. $tables[]= 'quiz_question_category';
  232. $tables[]= 'quiz_question_rel_category';
  233. $tables[]= 'dropbox_post';
  234. $tables[]= 'dropbox_file';
  235. $tables[]= 'dropbox_person';
  236. $tables[]= 'dropbox_category';
  237. $tables[]= 'dropbox_feedback';
  238. $tables[]= 'lp';
  239. $tables[]= 'lp_item';
  240. $tables[]= 'lp_view';
  241. $tables[]= 'lp_item_view';
  242. $tables[]= 'lp_iv_interaction';
  243. $tables[]= 'lp_iv_objective';
  244. $tables[]= 'blog';
  245. $tables[]= 'blog_comment';
  246. $tables[]= 'blog_post';
  247. $tables[]= 'blog_rating';
  248. $tables[]= 'blog_rel_user';
  249. $tables[]= 'blog_task';
  250. $tables[]= 'blog_task_rel_user';
  251. $tables[]= 'blog_attachment';
  252. $tables[]= 'permission_group';
  253. $tables[]= 'permission_user';
  254. $tables[]= 'permission_task';
  255. $tables[]= 'role';
  256. $tables[]= 'role_group';
  257. $tables[]= 'role_permissions';
  258. $tables[]= 'role_user';
  259. $tables[]= 'survey';
  260. $tables[]= 'survey_question';
  261. $tables[]= 'survey_question_option';
  262. $tables[]= 'survey_invitation';
  263. $tables[]= 'survey_answer';
  264. $tables[]= 'survey_group';
  265. $tables[]= 'wiki';
  266. $tables[]= 'wiki_conf';
  267. $tables[]= 'wiki_discuss';
  268. $tables[]= 'wiki_mailcue';
  269. $tables[]= 'course_setting';
  270. $tables[]= 'glossary';
  271. $tables[]= 'notebook';
  272. $tables[]= 'attendance';
  273. $tables[]= 'attendance_sheet';
  274. $tables[]= 'attendance_calendar';
  275. $tables[]= 'attendance_result';
  276. $tables[]= 'attendance_sheet_log';
  277. $tables[]= 'thematic';
  278. $tables[]= 'thematic_plan';
  279. $tables[]= 'thematic_advance';
  280. $tables[]= 'metadata';
  281. return $tables;
  282. }
  283. /**
  284. * Executed only before create_course_tables()
  285. * @return void
  286. * @assert (null) === null
  287. */
  288. function drop_course_tables() {
  289. $list = get_course_tables();
  290. foreach ($list as $table) {
  291. $sql = "DROP TABLE IF EXISTS ".DB_COURSE_PREFIX.$table;
  292. Database::query($sql);
  293. }
  294. }
  295. /**
  296. * Creates all the necessary tables for a new course (deprecated since 1.9.0 as
  297. * we only use a single database, configured at install time)
  298. * @param string Course DB name
  299. * @return int 0
  300. * @assert (null) === false
  301. */
  302. function create_course_tables($course_db_name = null) {
  303. global $_configuration;
  304. $charset_clause = ' DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci';
  305. $use_one_db = true;
  306. if ($use_one_db) {
  307. $course_db_name = DB_COURSE_PREFIX;
  308. } else {
  309. if (!$_configuration['single_database']) {
  310. Database::query("CREATE DATABASE IF NOT EXISTS " . $course_db_name . "" . $charset_clause);
  311. }
  312. $course_db_name = $_configuration['table_prefix'].$course_db_name.$_configuration['db_glue'];
  313. }
  314. //@todo define the backticks inside those table names directly (instead of adding them afterwards)
  315. $tbl_course_homepage = $course_db_name . 'tool';
  316. $TABLEINTROS = $course_db_name . 'tool_intro';
  317. $TABLEGROUPS = $course_db_name . 'group_info';
  318. $TABLEGROUPCATEGORIES = $course_db_name . 'group_category';
  319. $TABLEGROUPUSER = $course_db_name . 'group_rel_user';
  320. $TABLEGROUPTUTOR = $course_db_name . 'group_rel_tutor';
  321. $TABLEITEMPROPERTY = $course_db_name . 'item_property';
  322. $TABLETOOLUSERINFOCONTENT = $course_db_name . 'userinfo_content';
  323. $TABLETOOLUSERINFODEF = $course_db_name . 'userinfo_def';
  324. $TABLETOOLCOURSEDESC = $course_db_name . 'course_description';
  325. $TABLETOOLAGENDA = $course_db_name . 'calendar_event';
  326. $TABLETOOLAGENDAREPEAT = $course_db_name . 'calendar_event_repeat';
  327. $TABLETOOLAGENDAREPEATNOT = $course_db_name . 'calendar_event_repeat_not';
  328. $TABLETOOLAGENDAATTACHMENT = $course_db_name . 'calendar_event_attachment';
  329. // Announcements
  330. $TABLETOOLANNOUNCEMENTS = $course_db_name . 'announcement';
  331. $TABLETOOLANNOUNCEMENTSATTACHMENT = $course_db_name . 'announcement_attachment';
  332. // Resourcelinker
  333. $TABLEADDEDRESOURCES = $course_db_name . 'resource';
  334. // Student Publication
  335. $TABLETOOLWORKS = $course_db_name . 'student_publication';
  336. $TABLETOOLWORKSASS = $course_db_name . 'student_publication_assignment';
  337. // Document
  338. $TABLETOOLDOCUMENT = $course_db_name . 'document';
  339. // Forum
  340. $TABLETOOLFORUMCATEGORY = $course_db_name . 'forum_category';
  341. $TABLETOOLFORUM = $course_db_name . 'forum_forum';
  342. $TABLETOOLFORUMTHREAD = $course_db_name . 'forum_thread';
  343. $TABLETOOLFORUMPOST = $course_db_name . 'forum_post';
  344. $TABLETOOLFORUMMAILCUE = $course_db_name . 'forum_mailcue';
  345. $TABLETOOLFORUMATTACHMENT = $course_db_name . 'forum_attachment';
  346. $TABLETOOLFORUMNOTIFICATION = $course_db_name . 'forum_notification';
  347. $TABLETOOLFORUMQUALIFY = $course_db_name . 'forum_thread_qualify';
  348. $TABLETOOLFORUMQUALIFYLOG = $course_db_name . 'forum_thread_qualify_log';
  349. // Link
  350. $TABLETOOLLINK = $course_db_name . 'link';
  351. $TABLETOOLLINKCATEGORIES = $course_db_name . 'link_category';
  352. $TABLETOOLONLINECONNECTED = $course_db_name . 'online_connected';
  353. $TABLETOOLONLINELINK = $course_db_name . 'online_link';
  354. // Chat
  355. $TABLETOOLCHATCONNECTED = $course_db_name . 'chat_connected';
  356. // Quiz (a.k.a. exercises)
  357. $TABLEQUIZ = $course_db_name . 'quiz';
  358. $TABLEQUIZQUESTION = $course_db_name . 'quiz_rel_question';
  359. $TABLEQUIZQUESTIONLIST = $course_db_name . 'quiz_question';
  360. $TABLEQUIZANSWERSLIST = $course_db_name . 'quiz_answer';
  361. $TABLEQUIZQUESTIONOPTION = $course_db_name . 'quiz_question_option';
  362. $table_quiz_question_category = $course_db_name . 'quiz_question_category';
  363. $table_quiz_question_rel_category = $course_db_name . 'quiz_question_rel_category';
  364. // Dropbox
  365. $TABLETOOLDROPBOXPOST = $course_db_name . 'dropbox_post';
  366. $TABLETOOLDROPBOXFILE = $course_db_name . 'dropbox_file';
  367. $TABLETOOLDROPBOXPERSON = $course_db_name . 'dropbox_person';
  368. $TABLETOOLDROPBOXCATEGORY = $course_db_name . 'dropbox_category';
  369. $TABLETOOLDROPBOXFEEDBACK = $course_db_name . 'dropbox_feedback';
  370. // New Learning path
  371. $TABLELP = $course_db_name . 'lp';
  372. $TABLELPITEM = $course_db_name . 'lp_item';
  373. $TABLELPVIEW = $course_db_name . 'lp_view';
  374. $TABLELPITEMVIEW = $course_db_name . 'lp_item_view';
  375. $TABLELPIVINTERACTION = $course_db_name . 'lp_iv_interaction';
  376. $TABLELPIVOBJECTIVE = $course_db_name . 'lp_iv_objective';
  377. // Blogs
  378. $tbl_blogs = $course_db_name . 'blog';
  379. $tbl_blogs_comments = $course_db_name . 'blog_comment';
  380. $tbl_blogs_posts = $course_db_name . 'blog_post';
  381. $tbl_blogs_rating = $course_db_name . 'blog_rating';
  382. $tbl_blogs_rel_user = $course_db_name . 'blog_rel_user';
  383. $tbl_blogs_tasks = $course_db_name . 'blog_task';
  384. $tbl_blogs_tasks_rel_user = $course_db_name . 'blog_task_rel_user';
  385. $tbl_blogs_attachment = $course_db_name . 'blog_attachment';
  386. //Blogs permissions
  387. $tbl_permission_group = $course_db_name . 'permission_group';
  388. $tbl_permission_user = $course_db_name . 'permission_user';
  389. $tbl_permission_task = $course_db_name . 'permission_task';
  390. //Blog roles
  391. $tbl_role = $course_db_name . 'role';
  392. $tbl_role_group = $course_db_name . 'role_group';
  393. $tbl_role_permissions = $course_db_name . 'role_permissions';
  394. $tbl_role_user = $course_db_name . 'role_user';
  395. //Survey variables for course homepage;
  396. $TABLESURVEY = $course_db_name . 'survey';
  397. $TABLESURVEYQUESTION = $course_db_name . 'survey_question';
  398. $TABLESURVEYQUESTIONOPTION = $course_db_name . 'survey_question_option';
  399. $TABLESURVEYINVITATION = $course_db_name . 'survey_invitation';
  400. $TABLESURVEYANSWER = $course_db_name . 'survey_answer';
  401. $TABLESURVEYGROUP = $course_db_name . 'survey_group';
  402. // Wiki
  403. $TABLETOOLWIKI = $course_db_name . 'wiki';
  404. $TABLEWIKICONF = $course_db_name . 'wiki_conf';
  405. $TABLEWIKIDISCUSS = $course_db_name . 'wiki_discuss';
  406. $TABLEWIKIMAILCUE = $course_db_name . 'wiki_mailcue';
  407. // Course settings
  408. $TABLESETTING = $course_db_name . 'course_setting';
  409. // Glossary
  410. $TBL_GLOSSARY = $course_db_name . 'glossary';
  411. // Notebook
  412. $TBL_NOTEBOOK = $course_db_name . 'notebook';
  413. // Attendance
  414. $TBL_ATTENDANCE = $course_db_name . 'attendance';
  415. $TBL_ATTENDANCE_SHEET = $course_db_name . 'attendance_sheet';
  416. $TBL_ATTENDANCE_CALENDAR = $course_db_name . 'attendance_calendar';
  417. $TBL_ATTENDANCE_RESULT = $course_db_name . 'attendance_result';
  418. $TBL_ATTENDANCE_SHEET_LOG = $course_db_name . 'attendance_sheet_log';
  419. // Thematic
  420. $TBL_THEMATIC = $course_db_name . 'thematic';
  421. $TBL_THEMATIC_PLAN = $course_db_name . 'thematic_plan';
  422. $TBL_THEMATIC_ADVANCE = $course_db_name . 'thematic_advance';
  423. $TBL_METADATA = $course_db_name . 'metadata';
  424. $add_to_all_tables = ' c_id INT NOT NULL, ';
  425. /* Announcement tool */
  426. $sql = "
  427. CREATE TABLE `".$TABLETOOLANNOUNCEMENTS . "` (
  428. $add_to_all_tables
  429. id int unsigned NOT NULL auto_increment,
  430. title text,
  431. content mediumtext,
  432. end_date date default NULL,
  433. display_order mediumint NOT NULL default 0,
  434. email_sent tinyint default 0,
  435. session_id int default 0,
  436. PRIMARY KEY (c_id, id)
  437. )" . $charset_clause;
  438. Database::query($sql);
  439. $sql = "ALTER TABLE `".$TABLETOOLANNOUNCEMENTS . "` ADD INDEX ( session_id ) ";
  440. Database::query($sql);
  441. // Announcement Attachment
  442. $sql = "CREATE TABLE `".$TABLETOOLANNOUNCEMENTSATTACHMENT."` (
  443. $add_to_all_tables
  444. id int NOT NULL auto_increment,
  445. path varchar(255) NOT NULL,
  446. comment text,
  447. size int NOT NULL default 0,
  448. announcement_id int NOT NULL,
  449. filename varchar(255) NOT NULL,
  450. PRIMARY KEY (c_id, id)
  451. )" . $charset_clause;
  452. Database::query($sql);
  453. /*
  454. Resources
  455. */
  456. $sql = "
  457. CREATE TABLE `".$TABLEADDEDRESOURCES . "` (
  458. $add_to_all_tables
  459. id int unsigned NOT NULL auto_increment,
  460. source_type varchar(50) default NULL,
  461. source_id int unsigned default NULL,
  462. resource_type varchar(50) default NULL,
  463. resource_id int unsigned default NULL,
  464. PRIMARY KEY (c_id, id)
  465. )" . $charset_clause;
  466. Database::query($sql);
  467. $sql = "
  468. CREATE TABLE `".$TABLETOOLUSERINFOCONTENT . "` (
  469. $add_to_all_tables
  470. id int unsigned NOT NULL auto_increment,
  471. user_id int unsigned NOT NULL,
  472. definition_id int unsigned NOT NULL,
  473. editor_ip varchar(39) default NULL,
  474. edition_time datetime default NULL,
  475. content text NOT NULL,
  476. PRIMARY KEY (c_id, id),
  477. KEY user_id (user_id)
  478. )" . $charset_clause;
  479. Database::query($sql);
  480. // Unused table. Temporarily ignored for tests.
  481. // Reused because of user/userInfo and user/userInfoLib scripts
  482. $sql = "
  483. CREATE TABLE `".$TABLETOOLUSERINFODEF . "` (
  484. $add_to_all_tables
  485. id int unsigned NOT NULL auto_increment,
  486. title varchar(80) NOT NULL default '',
  487. comment text,
  488. line_count tinyint unsigned NOT NULL default 5,
  489. rank tinyint unsigned NOT NULL default 0,
  490. PRIMARY KEY (c_id, id)
  491. )" . $charset_clause;
  492. Database::query($sql);
  493. /* Forum tool */
  494. // Forum Category
  495. $sql = "
  496. CREATE TABLE `".$TABLETOOLFORUMCATEGORY . "` (
  497. $add_to_all_tables
  498. cat_id int NOT NULL auto_increment,
  499. cat_title varchar(255) NOT NULL default '',
  500. cat_comment text,
  501. cat_order int NOT NULL default 0,
  502. locked int NOT NULL default 0,
  503. session_id int unsigned NOT NULL default 0,
  504. PRIMARY KEY (c_id, cat_id)
  505. )" . $charset_clause;
  506. Database::query($sql);
  507. $sql = "ALTER TABLE `".$TABLETOOLFORUMCATEGORY . "` ADD INDEX ( session_id ) ";
  508. Database::query($sql);
  509. // Forum
  510. $sql = "
  511. CREATE TABLE `".$TABLETOOLFORUM . "` (
  512. $add_to_all_tables
  513. forum_id int NOT NULL auto_increment,
  514. forum_title varchar(255) NOT NULL default '',
  515. forum_comment text,
  516. forum_threads int default 0,
  517. forum_posts int default 0,
  518. forum_last_post int default 0,
  519. forum_category int default NULL,
  520. allow_anonymous int default NULL,
  521. allow_edit int default NULL,
  522. approval_direct_post varchar(20) default NULL,
  523. allow_attachments int default NULL,
  524. allow_new_threads int default NULL,
  525. default_view varchar(20) default NULL,
  526. forum_of_group varchar(20) default NULL,
  527. forum_group_public_private varchar(20) default 'public',
  528. forum_order int default NULL,
  529. locked int NOT NULL default 0,
  530. session_id int NOT NULL default 0,
  531. forum_image varchar(255) NOT NULL default '',
  532. start_time datetime NOT NULL default '0000-00-00 00:00:00',
  533. end_time datetime NOT NULL default '0000-00-00 00:00:00',
  534. PRIMARY KEY (c_id, forum_id)
  535. )" . $charset_clause;
  536. Database::query($sql);
  537. // Forum Threads
  538. $sql = "
  539. CREATE TABLE `".$TABLETOOLFORUMTHREAD . "` (
  540. $add_to_all_tables
  541. thread_id int NOT NULL auto_increment,
  542. thread_title varchar(255) default NULL,
  543. forum_id int default NULL,
  544. thread_replies int default 0,
  545. thread_poster_id int default NULL,
  546. thread_poster_name varchar(100) default '',
  547. thread_views int default 0,
  548. thread_last_post int default NULL,
  549. thread_date datetime default '0000-00-00 00:00:00',
  550. thread_sticky tinyint unsigned default 0,
  551. locked int NOT NULL default 0,
  552. session_id int unsigned default NULL,
  553. thread_title_qualify varchar(255) default '',
  554. thread_qualify_max float(6,2) UNSIGNED NOT NULL default 0,
  555. thread_close_date datetime default '0000-00-00 00:00:00',
  556. thread_weight float(6,2) UNSIGNED NOT NULL default 0,
  557. PRIMARY KEY (c_id, thread_id)
  558. )" . $charset_clause;
  559. Database::query($sql);
  560. $sql = "ALTER TABLE `".$TABLETOOLFORUMTHREAD . "` ADD INDEX idx_forum_thread_forum_id (forum_id)";
  561. Database::query($sql);
  562. // Forum Posts
  563. $sql = "
  564. CREATE TABLE `".$TABLETOOLFORUMPOST . "` (
  565. $add_to_all_tables
  566. post_id int NOT NULL auto_increment,
  567. post_title varchar(250) default NULL,
  568. post_text text,
  569. thread_id int default 0,
  570. forum_id int default 0,
  571. poster_id int default 0,
  572. poster_name varchar(100) default '',
  573. post_date datetime default '0000-00-00 00:00:00',
  574. post_notification tinyint default 0,
  575. post_parent_id int default 0,
  576. visible tinyint default 1,
  577. PRIMARY KEY (c_id, post_id),
  578. KEY poster_id (poster_id),
  579. KEY forum_id (forum_id)
  580. )" . $charset_clause;
  581. Database::query($sql);
  582. $sql = "ALTER TABLE `".$TABLETOOLFORUMPOST . "` ADD INDEX idx_forum_post_thread_id (thread_id)";
  583. Database::query($sql);
  584. $sql = "ALTER TABLE `".$TABLETOOLFORUMPOST . "` ADD INDEX idx_forum_post_visible (visible)";
  585. Database::query($sql);
  586. // Forum Mailcue
  587. $sql = "
  588. CREATE TABLE `".$TABLETOOLFORUMMAILCUE."` (
  589. $add_to_all_tables
  590. id int NOT NULL auto_increment,
  591. user_id int default NULL,
  592. thread_id int default NULL,
  593. post_id int default NULL,
  594. PRIMARY KEY (id, c_id, thread_id, user_id, post_id )
  595. )" . $charset_clause;
  596. Database::query($sql);
  597. // Forum Attachment
  598. $sql = "CREATE TABLE `".$TABLETOOLFORUMATTACHMENT."` (
  599. $add_to_all_tables
  600. id int NOT NULL auto_increment,
  601. path varchar(255) NOT NULL,
  602. comment text,
  603. size int NOT NULL default 0,
  604. post_id int NOT NULL,
  605. filename varchar(255) NOT NULL,
  606. PRIMARY KEY (c_id, id)
  607. )" . $charset_clause;
  608. Database::query($sql);
  609. // Forum notification
  610. $sql = "CREATE TABLE `".$TABLETOOLFORUMNOTIFICATION."` (
  611. $add_to_all_tables
  612. id int NOT NULL auto_increment,
  613. user_id int,
  614. forum_id int,
  615. thread_id int,
  616. post_id int,
  617. KEY user_id (user_id),
  618. KEY forum_id (forum_id),
  619. PRIMARY KEY (id, c_id, user_id, forum_id, thread_id, post_id )
  620. )" . $charset_clause;
  621. Database::query($sql);
  622. // Forum thread qualify :Add table forum_thread_qualify
  623. $sql = "CREATE TABLE `".$TABLETOOLFORUMQUALIFY."` (
  624. $add_to_all_tables
  625. id int unsigned AUTO_INCREMENT,
  626. user_id int unsigned NOT NULL,
  627. thread_id int NOT NULL,
  628. qualify float(6,2) NOT NULL default 0,
  629. qualify_user_id int default NULL,
  630. qualify_time datetime default '0000-00-00 00:00:00',
  631. session_id int default NULL,
  632. PRIMARY KEY (c_id, id)
  633. )" . $charset_clause;
  634. Database::query($sql);
  635. $sql = "ALTER TABLE `".$TABLETOOLFORUMQUALIFY . "` ADD INDEX (user_id, thread_id)";
  636. Database::query($sql);
  637. //Forum thread qualify: Add table forum_thread_qualify_historical
  638. $sql = "CREATE TABLE `".$TABLETOOLFORUMQUALIFYLOG."` (
  639. $add_to_all_tables
  640. id int unsigned AUTO_INCREMENT,
  641. user_id int unsigned NOT NULL,
  642. thread_id int NOT NULL,
  643. qualify float(6,2) NOT NULL default 0,
  644. qualify_user_id int default NULL,
  645. qualify_time datetime default '0000-00-00 00:00:00',
  646. session_id int default NULL,
  647. PRIMARY KEY (c_id, id)
  648. )" . $charset_clause;
  649. Database::query($sql);
  650. $sql = "ALTER TABLE `".$TABLETOOLFORUMQUALIFYLOG. "` ADD INDEX (user_id, thread_id)";
  651. Database::query($sql);
  652. /*
  653. * Exercise tool
  654. */
  655. // Exercise tool - Tests/exercises
  656. $sql = "CREATE TABLE `".$TABLEQUIZ . "` (
  657. $add_to_all_tables
  658. id int unsigned NOT NULL auto_increment,
  659. title varchar(255) NOT NULL,
  660. description text default NULL,
  661. sound varchar(255) default NULL,
  662. type tinyint unsigned NOT NULL default 1,
  663. random int NOT NULL default 0,
  664. random_answers tinyint unsigned NOT NULL default 0,
  665. active tinyint NOT NULL default 0,
  666. results_disabled INT UNSIGNED NOT NULL DEFAULT 0,
  667. access_condition TEXT DEFAULT NULL,
  668. max_attempt int NOT NULL default 0,
  669. start_time datetime NOT NULL default '0000-00-00 00:00:00',
  670. end_time datetime NOT NULL default '0000-00-00 00:00:00',
  671. feedback_type int NOT NULL default 0,
  672. expired_time int NOT NULL default '0',
  673. session_id int default 0,
  674. propagate_neg INT NOT NULL DEFAULT 0,
  675. review_answers INT NOT NULL DEFAULT 0,
  676. random_by_category INT NOT NULL DEFAULT 0,
  677. text_when_finished TEXT default NULL,
  678. display_category_name INT NOT NULL DEFAULT 1,
  679. pass_percentage INT DEFAULT NULL,
  680. PRIMARY KEY (c_id, id)
  681. )" . $charset_clause;
  682. Database::query($sql);
  683. $sql = "ALTER TABLE `".$TABLEQUIZ . "` ADD INDEX ( session_id ) ";
  684. Database::query($sql);
  685. // Exercise tool - questions
  686. $sql = "
  687. CREATE TABLE `".$TABLEQUIZQUESTIONLIST . "` (
  688. $add_to_all_tables
  689. id int unsigned NOT NULL auto_increment,
  690. question TEXT NOT NULL,
  691. description text default NULL,
  692. ponderation float(6,2) NOT NULL default 0,
  693. position mediumint unsigned NOT NULL default 1,
  694. type tinyint unsigned NOT NULL default 2,
  695. picture varchar(50) default NULL,
  696. level int unsigned NOT NULL default 0,
  697. extra varchar(255) default NULL,
  698. question_code char(10) default '',
  699. PRIMARY KEY (c_id, id)
  700. )" . $charset_clause;
  701. Database::query($sql);
  702. $sql = "ALTER TABLE `".$TABLEQUIZQUESTIONLIST . "` ADD INDEX (position)";
  703. Database::query($sql);
  704. // Exercise tool - answers
  705. $sql = "
  706. CREATE TABLE `".$TABLEQUIZANSWERSLIST . "` (
  707. $add_to_all_tables
  708. id int unsigned NOT NULL,
  709. id_auto int NOT NULL AUTO_INCREMENT,
  710. question_id int unsigned NOT NULL,
  711. answer text NOT NULL,
  712. correct mediumint unsigned default NULL,
  713. comment text default NULL,
  714. ponderation float(6,2) NOT NULL default 0,
  715. position mediumint unsigned NOT NULL default 1,
  716. hotspot_coordinates text,
  717. hotspot_type enum('square','circle','poly','delineation','oar') default NULL,
  718. destination text NOT NULL,
  719. answer_code char(10) default '',
  720. PRIMARY KEY (c_id, id_auto)
  721. )" . $charset_clause;
  722. Database::query($sql);
  723. // Exercise tool - answer options
  724. $sql = "
  725. CREATE TABLE `".$TABLEQUIZQUESTIONOPTION . "` (
  726. $add_to_all_tables
  727. id int NOT NULL auto_increment,
  728. question_id int NOT NULL,
  729. name varchar(255),
  730. position int unsigned NOT NULL,
  731. PRIMARY KEY (c_id, id)
  732. )" . $charset_clause;
  733. Database::query($sql);
  734. // Exercise tool - Test/question relations
  735. $sql = "
  736. CREATE TABLE `".$TABLEQUIZQUESTION . "` (
  737. $add_to_all_tables
  738. question_id int unsigned NOT NULL,
  739. exercice_id int unsigned NOT NULL,
  740. question_order int unsigned NOT NULL default 1,
  741. PRIMARY KEY (c_id, question_id,exercice_id)
  742. )" . $charset_clause;
  743. Database::query($sql);
  744. $sql = "CREATE TABLE `".$table_quiz_question_category . "` (
  745. $add_to_all_tables
  746. id int NOT NULL AUTO_INCREMENT,
  747. title varchar(255) NOT NULL,
  748. description text NOT NULL,
  749. PRIMARY KEY (c_id,id)
  750. )" . $charset_clause;
  751. Database::query($sql);
  752. $sql = "CREATE TABLE `".$table_quiz_question_rel_category . "` (
  753. $add_to_all_tables
  754. question_id int NOT NULL,
  755. category_id int NOT NULL,
  756. PRIMARY KEY (c_id,question_id)
  757. )" . $charset_clause;
  758. Database::query($sql);
  759. /* Course description */
  760. $sql = "
  761. CREATE TABLE `".$TABLETOOLCOURSEDESC . "` (
  762. $add_to_all_tables
  763. id int UNSIGNED NOT NULL auto_increment,
  764. title VARCHAR(255),
  765. content TEXT,
  766. session_id int default 0,
  767. description_type tinyint unsigned NOT NULL default 0,
  768. progress INT NOT NULL default 0,
  769. PRIMARY KEY (c_id, id)
  770. )" . $charset_clause;
  771. Database::query($sql);
  772. $sql = "ALTER TABLE `".$TABLETOOLCOURSEDESC . "` ADD INDEX ( session_id ) ";
  773. Database::query($sql);
  774. /* Course homepage tool list */
  775. $sql = "
  776. CREATE TABLE `" . $tbl_course_homepage . "` (
  777. $add_to_all_tables
  778. id int unsigned NOT NULL auto_increment,
  779. name varchar(255) NOT NULL,
  780. link varchar(255) NOT NULL,
  781. image varchar(255) default NULL,
  782. visibility tinyint unsigned default 0,
  783. admin varchar(255) default NULL,
  784. address varchar(255) default NULL,
  785. added_tool tinyint unsigned default 1,
  786. target enum('_self','_blank') NOT NULL default '_self',
  787. category varchar(20) not null default 'authoring',
  788. session_id int default 0,
  789. PRIMARY KEY (c_id, id)
  790. )" . $charset_clause;
  791. Database::query($sql);
  792. $sql = "ALTER TABLE `".$tbl_course_homepage . "` ADD INDEX ( session_id ) ";
  793. Database::query($sql);
  794. /* Agenda tool */
  795. $sql = "
  796. CREATE TABLE `".$TABLETOOLAGENDA . "` (
  797. $add_to_all_tables
  798. id int unsigned NOT NULL auto_increment,
  799. title varchar(255) NOT NULL,
  800. content text,
  801. start_date datetime NOT NULL default '0000-00-00 00:00:00',
  802. end_date datetime NOT NULL default '0000-00-00 00:00:00',
  803. parent_event_id INT NULL,
  804. session_id int unsigned NOT NULL default 0,
  805. all_day INT NOT NULL DEFAULT 0,
  806. PRIMARY KEY (c_id, id)
  807. )" . $charset_clause;
  808. Database::query($sql);
  809. $sql = "ALTER TABLE `".$TABLETOOLAGENDA . "` ADD INDEX ( session_id ) ;";
  810. Database::query($sql);
  811. $sql = "
  812. CREATE TABLE `".$TABLETOOLAGENDAREPEAT. "` (
  813. $add_to_all_tables
  814. cal_id INT DEFAULT 0 NOT NULL,
  815. cal_type VARCHAR(20),
  816. cal_end INT,
  817. cal_frequency INT DEFAULT 1,
  818. cal_days CHAR(7),
  819. PRIMARY KEY (c_id, cal_id)
  820. )" . $charset_clause;
  821. Database::query($sql);
  822. $sql = "
  823. CREATE TABLE `".$TABLETOOLAGENDAREPEATNOT."` (
  824. $add_to_all_tables
  825. cal_id INT NOT NULL,
  826. cal_date INT NOT NULL,
  827. PRIMARY KEY (c_id, cal_id, cal_date )
  828. )" . $charset_clause;
  829. Database::query($sql);
  830. // Agenda Attachment
  831. $sql = "CREATE TABLE `".$TABLETOOLAGENDAATTACHMENT."` (
  832. $add_to_all_tables
  833. id int NOT NULL auto_increment,
  834. path varchar(255) NOT NULL,
  835. comment text,
  836. size int NOT NULL default 0,
  837. agenda_id int NOT NULL,
  838. filename varchar(255) NOT NULL,
  839. PRIMARY KEY (c_id, id)
  840. )" . $charset_clause;
  841. Database::query($sql);
  842. /*
  843. Document tool
  844. */
  845. $sql = "
  846. CREATE TABLE `".$TABLETOOLDOCUMENT . "` (
  847. $add_to_all_tables
  848. id int unsigned NOT NULL auto_increment,
  849. path varchar(255) NOT NULL default '',
  850. comment text,
  851. title varchar(255) default NULL,
  852. filetype set('file','folder') NOT NULL default 'file',
  853. size int NOT NULL default 0,
  854. readonly TINYINT UNSIGNED NOT NULL,
  855. session_id int UNSIGNED NOT NULL default 0,
  856. PRIMARY KEY (c_id, id)
  857. )" . $charset_clause;
  858. Database::query($sql);
  859. /*
  860. Student publications
  861. */
  862. $sql = "
  863. CREATE TABLE `".$TABLETOOLWORKS . "` (
  864. $add_to_all_tables
  865. id int unsigned NOT NULL auto_increment,
  866. url varchar(255) default NULL,
  867. title varchar(255) default NULL,
  868. description text default NULL,
  869. author varchar(255) default NULL,
  870. active tinyint default NULL,
  871. accepted tinyint default 0,
  872. post_group_id int DEFAULT 0 NOT NULL,
  873. sent_date datetime NOT NULL default '0000-00-00 00:00:00',
  874. filetype set('file','folder') NOT NULL default 'file',
  875. has_properties int UNSIGNED NOT NULL DEFAULT 0,
  876. view_properties tinyint NULL,
  877. qualification float(6,2) UNSIGNED NOT NULL DEFAULT 0,
  878. date_of_qualification datetime NOT NULL default '0000-00-00 00:00:00',
  879. parent_id INT UNSIGNED NOT NULL DEFAULT 0,
  880. qualificator_id INT UNSIGNED NOT NULL DEFAULT 0,
  881. weight float(6,2) UNSIGNED NOT NULL default 0,
  882. session_id INT UNSIGNED NOT NULL default 0,
  883. user_id INTEGER NOT NULL,
  884. allow_text_assignment INTEGER NOT NULL DEFAULT 0,
  885. contains_file INTEGER NOT NULL DEFAULT 0,
  886. PRIMARY KEY (c_id, id)
  887. )" . $charset_clause;
  888. Database::query($sql);
  889. $sql = "
  890. CREATE TABLE `".$TABLETOOLWORKSASS."` (
  891. $add_to_all_tables
  892. id int NOT NULL auto_increment,
  893. expires_on datetime NOT NULL default '0000-00-00 00:00:00',
  894. ends_on datetime NOT NULL default '0000-00-00 00:00:00',
  895. add_to_calendar tinyint NOT NULL,
  896. enable_qualification tinyint NOT NULL,
  897. publication_id int NOT NULL,
  898. PRIMARY KEY (c_id, id)
  899. )" . $charset_clause;
  900. Database::query($sql);
  901. $sql = "ALTER TABLE `".$TABLETOOLWORKS . "` ADD INDEX ( session_id )" ;
  902. Database::query($sql);
  903. /*
  904. Links tool
  905. */
  906. $sql = "
  907. CREATE TABLE `".$TABLETOOLLINK . "` (
  908. $add_to_all_tables
  909. id int unsigned NOT NULL auto_increment,
  910. url TEXT NOT NULL,
  911. title varchar(150) default NULL,
  912. description text,
  913. category_id int unsigned default NULL,
  914. display_order int unsigned NOT NULL default 0,
  915. on_homepage enum('0','1') NOT NULL default '0',
  916. target char(10) default '_self',
  917. session_id int default 0,
  918. PRIMARY KEY (c_id, id)
  919. )" . $charset_clause;
  920. Database::query($sql);
  921. $sql = "ALTER TABLE `".$TABLETOOLLINK . "` ADD INDEX ( session_id ) ";
  922. Database::query($sql);
  923. $sql = "
  924. CREATE TABLE `".$TABLETOOLLINKCATEGORIES . "` (
  925. $add_to_all_tables
  926. id int unsigned NOT NULL auto_increment,
  927. category_title varchar(255) NOT NULL,
  928. description text,
  929. display_order mediumint unsigned NOT NULL default 0,
  930. session_id int default 0,
  931. PRIMARY KEY (c_id, id)
  932. )" . $charset_clause;
  933. Database::query($sql);
  934. $sql = "ALTER TABLE `".$TABLETOOLLINKCATEGORIES . "` ADD INDEX ( session_id ) ";
  935. Database::query($sql);
  936. /* Wiki */
  937. $sql = "CREATE TABLE `".$TABLETOOLWIKI . "` (
  938. $add_to_all_tables
  939. id int NOT NULL auto_increment,
  940. page_id int NOT NULL default 0,
  941. reflink varchar(255) NOT NULL default 'index',
  942. title varchar(255) NOT NULL,
  943. content mediumtext NOT NULL,
  944. user_id int NOT NULL default 0,
  945. group_id int DEFAULT NULL,
  946. dtime datetime NOT NULL default '0000-00-00 00:00:00',
  947. addlock int NOT NULL default 1,
  948. editlock int NOT NULL default 0,
  949. visibility int NOT NULL default 1,
  950. addlock_disc int NOT NULL default 1,
  951. visibility_disc int NOT NULL default 1,
  952. ratinglock_disc int NOT NULL default 1,
  953. assignment int NOT NULL default 0,
  954. comment text NOT NULL,
  955. progress text NOT NULL,
  956. score int NULL default 0,
  957. version int default NULL,
  958. is_editing int NOT NULL default 0,
  959. time_edit datetime NOT NULL default '0000-00-00 00:00:00',
  960. hits int default 0,
  961. linksto text NOT NULL,
  962. tag text NOT NULL,
  963. user_ip varchar(39) NOT NULL,
  964. session_id int default 0,
  965. PRIMARY KEY (c_id, id),
  966. KEY reflink (reflink),
  967. KEY group_id (group_id),
  968. KEY page_id (page_id),
  969. KEY session_id (session_id)
  970. )" . $charset_clause;
  971. Database::query($sql);
  972. $sql = "CREATE TABLE `".$TABLEWIKICONF . "` (
  973. $add_to_all_tables
  974. page_id int NOT NULL default 0,
  975. task text NOT NULL,
  976. feedback1 text NOT NULL,
  977. feedback2 text NOT NULL,
  978. feedback3 text NOT NULL,
  979. fprogress1 varchar(3) NOT NULL,
  980. fprogress2 varchar(3) NOT NULL,
  981. fprogress3 varchar(3) NOT NULL,
  982. max_size int default NULL,
  983. max_text int default NULL,
  984. max_version int default NULL,
  985. startdate_assig datetime NOT NULL default '0000-00-00 00:00:00',
  986. enddate_assig datetime NOT NULL default '0000-00-00 00:00:00',
  987. delayedsubmit int NOT NULL default 0,
  988. KEY page_id (page_id),
  989. PRIMARY KEY ( c_id, page_id )
  990. )" . $charset_clause;
  991. Database::query($sql);
  992. $sql = "CREATE TABLE `".$TABLEWIKIDISCUSS . "` (
  993. $add_to_all_tables
  994. id int NOT NULL auto_increment,
  995. publication_id int NOT NULL default 0,
  996. userc_id int NOT NULL default 0,
  997. comment text NOT NULL,
  998. p_score varchar(255) default NULL,
  999. dtime datetime NOT NULL default '0000-00-00 00:00:00',
  1000. PRIMARY KEY (c_id, id)
  1001. )" . $charset_clause;
  1002. Database::query($sql);
  1003. $sql = "CREATE TABLE `".$TABLEWIKIMAILCUE . "` (
  1004. $add_to_all_tables
  1005. id int NOT NULL,
  1006. user_id int NOT NULL,
  1007. type text NOT NULL,
  1008. group_id int DEFAULT NULL,
  1009. session_id int default 0,
  1010. KEY (c_id, id),
  1011. PRIMARY KEY ( c_id, id, user_id )
  1012. )" . $charset_clause;
  1013. Database::query($sql);
  1014. /*
  1015. Online
  1016. */
  1017. $sql = "
  1018. CREATE TABLE `".$TABLETOOLONLINECONNECTED . "` (
  1019. $add_to_all_tables
  1020. user_id int unsigned NOT NULL,
  1021. last_connection datetime NOT NULL default '0000-00-00 00:00:00',
  1022. PRIMARY KEY (c_id, user_id)
  1023. )" . $charset_clause;
  1024. Database::query($sql);
  1025. $sql = "
  1026. CREATE TABLE `".$TABLETOOLONLINELINK . "` (
  1027. $add_to_all_tables
  1028. id int unsigned NOT NULL auto_increment,
  1029. name char(50) NOT NULL default '',
  1030. url char(100) NOT NULL,
  1031. PRIMARY KEY (c_id, id)
  1032. )" . $charset_clause;
  1033. Database::query($sql);
  1034. $sql = "
  1035. CREATE TABLE `".$TABLETOOLCHATCONNECTED . "` (
  1036. $add_to_all_tables
  1037. id int unsigned NOT NULL auto_increment,
  1038. user_id int unsigned NOT NULL default '0',
  1039. last_connection datetime NOT NULL default '0000-00-00 00:00:00',
  1040. session_id INT NOT NULL default 0,
  1041. to_group_id INT NOT NULL default 0,
  1042. PRIMARY KEY (c_id, id, user_id, last_connection)
  1043. )" . $charset_clause;
  1044. Database::query($sql);
  1045. $sql = "ALTER TABLE `".$TABLETOOLCHATCONNECTED . "` ADD INDEX char_connected_index(user_id, session_id, to_group_id) ";
  1046. Database::query($sql);
  1047. /*
  1048. Groups tool
  1049. */
  1050. Database::query("CREATE TABLE `".$TABLEGROUPS . "` (
  1051. $add_to_all_tables
  1052. id int unsigned NOT NULL auto_increment,
  1053. name varchar(100) default NULL,
  1054. category_id int unsigned NOT NULL default 0,
  1055. description text,
  1056. max_student int unsigned NOT NULL default 8,
  1057. doc_state tinyint unsigned NOT NULL default 1,
  1058. calendar_state tinyint unsigned NOT NULL default 0,
  1059. work_state tinyint unsigned NOT NULL default 0,
  1060. announcements_state tinyint unsigned NOT NULL default 0,
  1061. forum_state tinyint unsigned NOT NULL default 0,
  1062. wiki_state tinyint unsigned NOT NULL default 1,
  1063. chat_state tinyint unsigned NOT NULL default 1,
  1064. secret_directory varchar(255) default NULL,
  1065. self_registration_allowed tinyint unsigned NOT NULL default '0',
  1066. self_unregistration_allowed tinyint unsigned NOT NULL default '0',
  1067. session_id int unsigned NOT NULL default 0,
  1068. PRIMARY KEY (c_id, id)
  1069. )" . $charset_clause);
  1070. Database::query("ALTER TABLE `".$TABLEGROUPS . "` ADD INDEX ( session_id )");
  1071. Database::query("CREATE TABLE `".$TABLEGROUPCATEGORIES . "` (
  1072. $add_to_all_tables
  1073. id int unsigned NOT NULL auto_increment,
  1074. title varchar(255) NOT NULL default '',
  1075. description text NOT NULL,
  1076. doc_state tinyint unsigned NOT NULL default 1,
  1077. calendar_state tinyint unsigned NOT NULL default 1,
  1078. work_state tinyint unsigned NOT NULL default 1,
  1079. announcements_state tinyint unsigned NOT NULL default 1,
  1080. forum_state tinyint unsigned NOT NULL default 1,
  1081. wiki_state tinyint unsigned NOT NULL default 1,
  1082. chat_state tinyint unsigned NOT NULL default 1,
  1083. max_student int unsigned NOT NULL default 8,
  1084. self_reg_allowed tinyint unsigned NOT NULL default 0,
  1085. self_unreg_allowed tinyint unsigned NOT NULL default 0,
  1086. groups_per_user int unsigned NOT NULL default 0,
  1087. display_order int unsigned NOT NULL default 0,
  1088. PRIMARY KEY (c_id, id)
  1089. )" . $charset_clause);
  1090. Database::query("CREATE TABLE `".$TABLEGROUPUSER . "` (
  1091. $add_to_all_tables
  1092. id int unsigned NOT NULL auto_increment,
  1093. user_id int unsigned NOT NULL,
  1094. group_id int unsigned NOT NULL default 0,
  1095. status int NOT NULL default 0,
  1096. role char(50) NOT NULL,
  1097. PRIMARY KEY (c_id, id)
  1098. )" . $charset_clause);
  1099. Database::query("CREATE TABLE `".$TABLEGROUPTUTOR . "` (
  1100. $add_to_all_tables
  1101. id int NOT NULL auto_increment,
  1102. user_id int NOT NULL,
  1103. group_id int NOT NULL default 0,
  1104. PRIMARY KEY (c_id, id)
  1105. )" . $charset_clause);
  1106. Database::query("CREATE TABLE `".$TABLEITEMPROPERTY . "` (
  1107. $add_to_all_tables
  1108. id int NOT NULL auto_increment,
  1109. tool varchar(100) NOT NULL default '',
  1110. insert_user_id int unsigned NOT NULL default '0',
  1111. insert_date datetime NOT NULL default '0000-00-00 00:00:00',
  1112. lastedit_date datetime NOT NULL default '0000-00-00 00:00:00',
  1113. ref int NOT NULL default '0',
  1114. lastedit_type varchar(100) NOT NULL default '',
  1115. lastedit_user_id int unsigned NOT NULL default '0',
  1116. to_group_id int unsigned default NULL,
  1117. to_user_id int unsigned default NULL,
  1118. visibility tinyint NOT NULL default '1',
  1119. start_visible datetime NOT NULL default '0000-00-00 00:00:00',
  1120. end_visible datetime NOT NULL default '0000-00-00 00:00:00',
  1121. id_session INT NOT NULL DEFAULT 0,
  1122. PRIMARY KEY (c_id, id)
  1123. )" . $charset_clause);
  1124. Database::query("ALTER TABLE `$TABLEITEMPROPERTY` ADD INDEX idx_item_property_toolref (tool,ref)");
  1125. /* Tool introductions */
  1126. Database::query("
  1127. CREATE TABLE `".$TABLEINTROS . "` (
  1128. $add_to_all_tables
  1129. id varchar(50) NOT NULL,
  1130. intro_text MEDIUMTEXT NOT NULL,
  1131. session_id INT NOT NULL DEFAULT 0,
  1132. PRIMARY KEY (c_id, id, session_id)
  1133. )" . $charset_clause);
  1134. /* Dropbox tool */
  1135. Database::query("
  1136. CREATE TABLE `".$TABLETOOLDROPBOXFILE . "` (
  1137. $add_to_all_tables
  1138. id int unsigned NOT NULL auto_increment,
  1139. uploader_id int unsigned NOT NULL default 0,
  1140. filename varchar(250) NOT NULL default '',
  1141. filesize int unsigned NOT NULL,
  1142. title varchar(250) default '',
  1143. description varchar(250) default '',
  1144. author varchar(250) default '',
  1145. upload_date datetime NOT NULL default '0000-00-00 00:00:00',
  1146. last_upload_date datetime NOT NULL default '0000-00-00 00:00:00',
  1147. cat_id int NOT NULL default 0,
  1148. session_id int UNSIGNED NOT NULL,
  1149. PRIMARY KEY (c_id, id),
  1150. UNIQUE KEY UN_filename (filename)
  1151. )" . $charset_clause);
  1152. Database::query("ALTER TABLE `$TABLETOOLDROPBOXFILE` ADD INDEX ( session_id )");
  1153. Database::query("
  1154. CREATE TABLE `".$TABLETOOLDROPBOXPOST . "` (
  1155. $add_to_all_tables
  1156. file_id int unsigned NOT NULL,
  1157. dest_user_id int unsigned NOT NULL default 0,
  1158. feedback_date datetime NOT NULL default '0000-00-00 00:00:00',
  1159. feedback text default '',
  1160. cat_id int NOT NULL default 0,
  1161. session_id int UNSIGNED NOT NULL,
  1162. PRIMARY KEY (c_id, file_id, dest_user_id)
  1163. )" . $charset_clause);
  1164. Database::query("ALTER TABLE `$TABLETOOLDROPBOXPOST` ADD INDEX ( session_id )");
  1165. Database::query("
  1166. CREATE TABLE `".$TABLETOOLDROPBOXPERSON . "` (
  1167. $add_to_all_tables
  1168. file_id int unsigned NOT NULL,
  1169. user_id int unsigned NOT NULL default 0,
  1170. PRIMARY KEY (c_id, file_id, user_id)
  1171. )" . $charset_clause);
  1172. $sql = "CREATE TABLE `".$TABLETOOLDROPBOXCATEGORY."` (
  1173. $add_to_all_tables
  1174. cat_id int NOT NULL auto_increment,
  1175. cat_name text NOT NULL,
  1176. received tinyint unsigned NOT NULL default 0,
  1177. sent tinyint unsigned NOT NULL default 0,
  1178. user_id int NOT NULL default 0,
  1179. session_id int NOT NULL default 0,
  1180. PRIMARY KEY (c_id, cat_id)
  1181. )" . $charset_clause;
  1182. Database::query($sql);
  1183. $sql = "ALTER TABLE `".$TABLETOOLDROPBOXCATEGORY . "` ADD INDEX ( session_id ) ";
  1184. Database::query($sql);
  1185. $sql = "CREATE TABLE `".$TABLETOOLDROPBOXFEEDBACK."` (
  1186. $add_to_all_tables
  1187. feedback_id int NOT NULL auto_increment,
  1188. file_id int NOT NULL default 0,
  1189. author_user_id int NOT NULL default 0,
  1190. feedback text NOT NULL,
  1191. feedback_date datetime NOT NULL default '0000-00-00 00:00:00',
  1192. PRIMARY KEY (c_id, feedback_id),
  1193. KEY file_id (file_id),
  1194. KEY author_user_id (author_user_id)
  1195. )" . $charset_clause;
  1196. Database::query($sql);
  1197. /*
  1198. New learning path tool
  1199. */
  1200. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELP` (
  1201. $add_to_all_tables
  1202. " .
  1203. "id int unsigned auto_increment," . // unique ID, generated by MySQL
  1204. "lp_type int unsigned not null," . // lp_types can be found in the main database's lp_type table
  1205. "name varchar(255) not null," . // name is the text name of the learning path (e.g. Word 2000)
  1206. "ref tinytext null," . // ref for SCORM elements is the SCORM ID in imsmanifest. For other learnpath types, just ignore
  1207. "description text null,". // textual description
  1208. "path text not null," . // path, starting at the platforms root (so all paths should start with 'courses/...' for now)
  1209. "force_commit tinyint unsigned not null default 0, " . // stores the default behaviour regarding SCORM information
  1210. "default_view_mod char(32) not null default 'embedded'," . // stores the default view mode (embedded or fullscreen)
  1211. "default_encoding char(32) not null default 'UTF-8', " . // stores the encoding detected at learning path reading
  1212. "display_order int unsigned not null default 0," . // order of learnpaths display in the learnpaths list - not really important
  1213. "content_maker tinytext not null default ''," . // the content make for this course (ENI, Articulate, ...)
  1214. "content_local varchar(32) not null default 'local'," . // content localisation ('local' or 'distant')
  1215. "content_license text not null default ''," . // content license
  1216. "prevent_reinit tinyint unsigned not null default 1," . // stores the default behaviour regarding items re-initialisation when viewed a second time after success
  1217. "js_lib tinytext not null default ''," . // the JavaScript library to load for this lp
  1218. "debug tinyint unsigned not null default 0," . // stores the default behaviour regarding items re-initialisation when viewed a second time after success
  1219. "theme varchar(255) not null default '', " . // stores the theme of the LP
  1220. "preview_image varchar(255) not null default '', " . // stores the theme of the LP
  1221. "author varchar(255) not null default '', " . // stores the theme of the LP
  1222. "session_id int unsigned not null default 0, " . // the session_id
  1223. "prerequisite int unsigned not null default 0," . // pre requisite for next lp
  1224. "hide_toc_frame tinyint NOT NULL DEFAULT 0, ".
  1225. "seriousgame_mode tinyint NOT NULL DEFAULT 0, ".
  1226. "use_max_score int unsigned not null default 1, " .
  1227. "autolunch int unsigned not null default 0, " . // auto lunch LP
  1228. "created_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
  1229. "modified_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
  1230. "publicated_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
  1231. "expired_on DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  1232. PRIMARY KEY (c_id, id)
  1233. )" . $charset_clause;
  1234. Database::query($sql);
  1235. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELPVIEW` (
  1236. $add_to_all_tables" .
  1237. "id int unsigned auto_increment," . // unique ID from MySQL
  1238. "lp_id int unsigned not null," . // learnpath ID from 'lp'
  1239. "user_id int unsigned not null," . // user ID from main.user
  1240. "view_count int unsigned not null default 0," . // integer counting the amount of times this learning path has been attempted
  1241. "last_item int unsigned not null default 0," . // last item seen in this view
  1242. "progress int unsigned default 0," .
  1243. "session_id int not null default 0,
  1244. PRIMARY KEY (c_id, id)
  1245. )" . $charset_clause; // lp's progress for this user
  1246. Database::query($sql);
  1247. $sql = "ALTER TABLE `$TABLELPVIEW` ADD INDEX (lp_id) ";
  1248. Database::query($sql);
  1249. $sql = "ALTER TABLE `$TABLELPVIEW` ADD INDEX (user_id) ";
  1250. Database::query($sql);
  1251. $sql = "ALTER TABLE `$TABLELPVIEW` ADD INDEX (session_id) ";
  1252. Database::query($sql);
  1253. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELPITEM` (
  1254. $add_to_all_tables
  1255. " .
  1256. "id int unsigned auto_increment," . // unique ID from MySQL
  1257. "lp_id int unsigned not null," . // lp_id from 'lp'
  1258. "item_type char(32) not null default 'dokeos_document'," . // can be dokeos_document, dokeos_chapter or scorm_asset, scorm_sco, scorm_chapter
  1259. "ref tinytext not null default ''," . // the ID given to this item in the imsmanifest file
  1260. "title varchar(511) not null," . // the title/name of this item (to display in the T.O.C.)
  1261. "description varchar(511) not null default ''," . // the description of this item - deprecated
  1262. "path text not null," . // the path to that item, starting at 'courses/...' level
  1263. "min_score float unsigned not null default 0," . // min score allowed
  1264. "max_score float unsigned default 100," . // max score allowed
  1265. "mastery_score float unsigned null," . // minimum score to pass the test
  1266. "parent_item_id int unsigned not null default 0," . // the item one level higher
  1267. "previous_item_id int unsigned not null default 0," . // the item before this one in the sequential learning order (MySQL id)
  1268. "next_item_id int unsigned not null default 0," . // the item after this one in the sequential learning order (MySQL id)
  1269. "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)
  1270. "prerequisite text null default null," . // prerequisites in AICC scripting language as defined in the SCORM norm (allow logical operators)
  1271. "parameters text null," . // prerequisites in AICC scripting language as defined in the SCORM norm (allow logical operators)
  1272. "launch_data text not null default ''," . // data from imsmanifest <item>
  1273. "max_time_allowed char(13) NULL default ''," . // data from imsmanifest <adlcp:maxtimeallowed>
  1274. "terms TEXT NULL," . // contains the indexing tags (search engine)
  1275. "search_did INT NULL,". // contains the internal search-engine id of this element
  1276. "audio VARCHAR(250),
  1277. PRIMARY KEY (c_id, id)
  1278. )" . $charset_clause; // contains the audio file that goes with the learning path step
  1279. Database::query($sql);
  1280. $sql = "ALTER TABLE `$TABLELPITEM` ADD INDEX (lp_id)";
  1281. Database::query($sql);
  1282. $sql = "ALTER TABLE $TABLELPITEM ADD INDEX idx_c_lp_item_cid_lp_id (c_id, lp_id)";
  1283. Database::query($sql);
  1284. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELPITEMVIEW` (
  1285. $add_to_all_tables
  1286. " .
  1287. "id bigint unsigned auto_increment," . // unique ID
  1288. "lp_item_id int unsigned not null," . // item ID (MySQL id)
  1289. "lp_view_id int unsigned not null," . // learning path view id (attempt)
  1290. "view_count int unsigned not null default 0," . // how many times this item has been viewed in the current attempt (generally 0 or 1)
  1291. "start_time int unsigned not null," . // when did the user open it?
  1292. "total_time int unsigned not null default 0," . // after how many seconds did he close it?
  1293. "score float unsigned not null default 0," . // score returned by SCORM or other techs
  1294. "status char(32) not null default 'not attempted'," . // status for this item (SCORM)
  1295. "suspend_data longtext null default ''," .
  1296. "lesson_location text null default ''," .
  1297. "core_exit varchar(32) not null default 'none'," .
  1298. "max_score varchar(8) default '',
  1299. PRIMARY KEY (c_id, id)
  1300. )" . $charset_clause;
  1301. Database::query($sql);
  1302. $sql = "ALTER TABLE `$TABLELPITEMVIEW` ADD INDEX (lp_item_id) ";
  1303. Database::query($sql);
  1304. $sql = "ALTER TABLE `$TABLELPITEMVIEW` ADD INDEX (lp_view_id) ";
  1305. Database::query($sql);
  1306. $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) ";
  1307. Database::query($sql);
  1308. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELPIVINTERACTION`(
  1309. $add_to_all_tables" .
  1310. "id bigint unsigned auto_increment," .
  1311. "order_id int unsigned not null default 0,". // internal order (0->...) given by Dokeos
  1312. "lp_iv_id bigint unsigned not null," . // identifier of the related sco_view
  1313. "interaction_id varchar(255) not null default ''," . // sco-specific, given by the sco
  1314. "interaction_type varchar(255) not null default ''," . // literal values, SCORM-specific (see p.63 of SCORM 1.2 RTE)
  1315. "weighting double not null default 0," .
  1316. "completion_time varchar(16) not null default ''," . // completion time for the interaction (timestamp in a day's time) - expected output format is scorm time
  1317. "correct_responses text not null default ''," . // actually a serialised array. See p.65 os SCORM 1.2 RTE)
  1318. "student_response text not null default ''," . // student response (format depends on type)
  1319. "result varchar(255) not null default ''," . // textual result
  1320. "latency varchar(16) not null default ''," . // time necessary for completion of the interaction
  1321. "PRIMARY KEY (c_id, id)".
  1322. ")" . $charset_clause;
  1323. Database::query($sql);
  1324. $sql = "ALTER TABLE `$TABLELPIVINTERACTION` ADD INDEX (lp_iv_id) ";
  1325. Database::query($sql);
  1326. $sql = "CREATE TABLE IF NOT EXISTS `$TABLELPIVOBJECTIVE`(
  1327. $add_to_all_tables" .
  1328. "id bigint unsigned auto_increment," .
  1329. "lp_iv_id bigint unsigned not null," . // identifier of the related sco_view
  1330. "order_id int unsigned not null default 0,". // internal order (0->...) given by Dokeos
  1331. "objective_id varchar(255) not null default ''," . // sco-specific, given by the sco
  1332. "score_raw float unsigned not null default 0," . // score
  1333. "score_max float unsigned not null default 0," . // max score
  1334. "score_min float unsigned not null default 0," . // min score
  1335. "status char(32) not null default 'not attempted', " . //status, just as sco status
  1336. "PRIMARY KEY (c_id, id) ".
  1337. ")" . $charset_clause;
  1338. Database::query($sql);
  1339. $sql = "ALTER TABLE `$TABLELPIVOBJECTIVE` ADD INDEX (lp_iv_id) ";
  1340. Database::query($sql);
  1341. /* Blogs */
  1342. $sql = "
  1343. CREATE TABLE `" . $tbl_blogs . "` (
  1344. $add_to_all_tables
  1345. blog_id int NOT NULL AUTO_INCREMENT ,
  1346. blog_name varchar( 250 ) NOT NULL default '',
  1347. blog_subtitle varchar( 250 ) default NULL ,
  1348. date_creation datetime NOT NULL default '0000-00-00 00:00:00',
  1349. visibility tinyint unsigned NOT NULL default 0,
  1350. session_id int default 0,
  1351. PRIMARY KEY (c_id, blog_id )
  1352. )" . $charset_clause . " COMMENT = 'Table with blogs in this course';";
  1353. Database::query($sql);
  1354. $sql = "ALTER TABLE `".$tbl_blogs . "` ADD INDEX ( session_id ) ";
  1355. Database::query($sql);
  1356. $sql = "
  1357. CREATE TABLE `" . $tbl_blogs_comments . "` (
  1358. $add_to_all_tables
  1359. comment_id int NOT NULL AUTO_INCREMENT ,
  1360. title varchar( 250 ) NOT NULL default '',
  1361. comment longtext NOT NULL ,
  1362. author_id int NOT NULL default 0,
  1363. date_creation datetime NOT NULL default '0000-00-00 00:00:00',
  1364. blog_id int NOT NULL default 0,
  1365. post_id int NOT NULL default 0,
  1366. task_id int default NULL ,
  1367. parent_comment_id int NOT NULL default 0,
  1368. PRIMARY KEY (c_id, comment_id )
  1369. )" . $charset_clause . " COMMENT = 'Table with comments on posts in a blog';";
  1370. Database::query($sql);
  1371. $sql = "
  1372. CREATE TABLE `" . $tbl_blogs_posts . "` (
  1373. $add_to_all_tables
  1374. post_id int NOT NULL AUTO_INCREMENT ,
  1375. title varchar( 250 ) NOT NULL default '',
  1376. full_text longtext NOT NULL ,
  1377. date_creation datetime NOT NULL default '0000-00-00 00:00:00',
  1378. blog_id int NOT NULL default 0,
  1379. author_id int NOT NULL default 0,
  1380. PRIMARY KEY (c_id, post_id )
  1381. )" . $charset_clause . " COMMENT = 'Table with posts / blog.';";
  1382. Database::query($sql);
  1383. $sql = "
  1384. CREATE TABLE `" . $tbl_blogs_rating . "` (
  1385. $add_to_all_tables
  1386. rating_id int NOT NULL AUTO_INCREMENT ,
  1387. blog_id int NOT NULL default 0,
  1388. rating_type enum( 'post', 'comment' ) NOT NULL default 'post',
  1389. item_id int NOT NULL default 0,
  1390. user_id int NOT NULL default 0,
  1391. rating int NOT NULL default 0,
  1392. PRIMARY KEY (c_id, rating_id )
  1393. )" . $charset_clause . " COMMENT = 'Table with ratings for post/comments in a certain blog';";
  1394. Database::query($sql);
  1395. $sql = "
  1396. CREATE TABLE `" . $tbl_blogs_rel_user . "` (
  1397. $add_to_all_tables
  1398. blog_id int NOT NULL default 0,
  1399. user_id int NOT NULL default 0,
  1400. PRIMARY KEY ( c_id, blog_id , user_id )
  1401. )" . $charset_clause . " COMMENT = 'Table representing users subscribed to a blog';";
  1402. Database::query($sql);
  1403. $sql = "
  1404. CREATE TABLE `" . $tbl_blogs_tasks . "` (
  1405. $add_to_all_tables
  1406. task_id int NOT NULL AUTO_INCREMENT ,
  1407. blog_id int NOT NULL default 0,
  1408. title varchar( 250 ) NOT NULL default '',
  1409. description text NOT NULL ,
  1410. color varchar( 10 ) NOT NULL default '',
  1411. system_task tinyint unsigned NOT NULL default 0,
  1412. PRIMARY KEY (c_id, task_id )
  1413. )" . $charset_clause . " COMMENT = 'Table with tasks for a blog';";
  1414. Database::query($sql);
  1415. $sql = "
  1416. CREATE TABLE `" . $tbl_blogs_tasks_rel_user . "` (
  1417. $add_to_all_tables
  1418. blog_id int NOT NULL default 0,
  1419. user_id int NOT NULL default 0,
  1420. task_id int NOT NULL default 0,
  1421. target_date date NOT NULL default '0000-00-00',
  1422. PRIMARY KEY (c_id, blog_id , user_id , task_id )
  1423. )" . $charset_clause . " COMMENT = 'Table with tasks assigned to a user in a blog';";
  1424. Database::query($sql);
  1425. $sql ="CREATE TABLE `" .$tbl_blogs_attachment."` (
  1426. $add_to_all_tables
  1427. id int unsigned NOT NULL auto_increment,
  1428. path varchar(255) NOT NULL COMMENT 'the real filename',
  1429. comment text,
  1430. size int NOT NULL default '0',
  1431. post_id int NOT NULL,
  1432. filename varchar(255) NOT NULL COMMENT 'the user s file name',
  1433. blog_id int NOT NULL,
  1434. comment_id int NOT NULL default '0',
  1435. PRIMARY KEY (c_id, id)
  1436. )" . $charset_clause;
  1437. Database::query($sql);
  1438. $sql = "
  1439. CREATE TABLE `" . $tbl_permission_group . "` (
  1440. $add_to_all_tables
  1441. id int NOT NULL AUTO_INCREMENT ,
  1442. group_id int NOT NULL default 0,
  1443. tool varchar( 250 ) NOT NULL default '',
  1444. action varchar( 250 ) NOT NULL default '',
  1445. PRIMARY KEY (c_id, id)
  1446. )" . $charset_clause;
  1447. Database::query($sql);
  1448. $sql = "
  1449. CREATE TABLE `" . $tbl_permission_user . "` (
  1450. $add_to_all_tables
  1451. id int NOT NULL AUTO_INCREMENT ,
  1452. user_id int NOT NULL default 0,
  1453. tool varchar( 250 ) NOT NULL default '',
  1454. action varchar( 250 ) NOT NULL default '',
  1455. PRIMARY KEY (c_id, id )
  1456. )" . $charset_clause;
  1457. Database::query($sql);
  1458. $sql = "
  1459. CREATE TABLE `" . $tbl_permission_task . "` (
  1460. $add_to_all_tables
  1461. id int NOT NULL AUTO_INCREMENT,
  1462. task_id int NOT NULL default 0,
  1463. tool varchar( 250 ) NOT NULL default '',
  1464. action varchar( 250 ) NOT NULL default '',
  1465. PRIMARY KEY (c_id, id )
  1466. )" . $charset_clause;
  1467. Database::query($sql);
  1468. $sql = "
  1469. CREATE TABLE `" . $tbl_role . "` (
  1470. $add_to_all_tables
  1471. role_id int NOT NULL AUTO_INCREMENT,
  1472. role_name varchar( 250 ) NOT NULL default '',
  1473. role_comment text,
  1474. default_role tinyint default 0,
  1475. PRIMARY KEY (c_id, role_id)
  1476. )" . $charset_clause;
  1477. Database::query($sql);
  1478. $sql = "
  1479. CREATE TABLE `" . $tbl_role_group . "` (
  1480. $add_to_all_tables
  1481. id int NOT NULL AUTO_INCREMENT,
  1482. role_id int NOT NULL default 0,
  1483. scope varchar( 20 ) NOT NULL default 'course',
  1484. group_id int NOT NULL default 0,
  1485. PRIMARY KEY (id, c_id, group_id )
  1486. )" . $charset_clause;
  1487. Database::query($sql);
  1488. $sql = "
  1489. CREATE TABLE `" . $tbl_role_permissions . "` (
  1490. $add_to_all_tables
  1491. id int NOT NULL AUTO_INCREMENT,
  1492. role_id int NOT NULL default 0,
  1493. tool varchar( 250 ) NOT NULL default '',
  1494. action varchar( 50 ) NOT NULL default '',
  1495. default_perm tinyint NOT NULL default 0,
  1496. PRIMARY KEY (id, c_id, role_id, tool, action )
  1497. )" . $charset_clause;
  1498. Database::query($sql);
  1499. $sql = "
  1500. CREATE TABLE `" . $tbl_role_user . "` (
  1501. $add_to_all_tables
  1502. role_id int NOT NULL default 0,
  1503. scope varchar( 20 ) NOT NULL default 'course',
  1504. user_id int NOT NULL default 0,
  1505. PRIMARY KEY ( c_id, role_id, user_id )
  1506. )" . $charset_clause;
  1507. Database::query($sql);
  1508. /*
  1509. * Course Config Settings
  1510. *
  1511. */
  1512. Database::query("
  1513. CREATE TABLE `".$TABLESETTING . "` (
  1514. $add_to_all_tables
  1515. id int unsigned NOT NULL auto_increment,
  1516. variable varchar(255) NOT NULL default '',
  1517. subkey varchar(255) default NULL,
  1518. type varchar(255) default NULL,
  1519. category varchar(255) default NULL,
  1520. value varchar(255) NOT NULL default '',
  1521. title varchar(255) NOT NULL default '',
  1522. comment varchar(255) default NULL,
  1523. subkeytext varchar(255) default NULL,
  1524. PRIMARY KEY (c_id, id)
  1525. )" . $charset_clause);
  1526. /*
  1527. Survey
  1528. */
  1529. $sql = "CREATE TABLE `".$TABLESURVEY."` (
  1530. $add_to_all_tables
  1531. survey_id int unsigned NOT NULL auto_increment,
  1532. code varchar(20) default NULL,
  1533. title text default NULL,
  1534. subtitle text default NULL,
  1535. author varchar(20) default NULL,
  1536. lang varchar(20) default NULL,
  1537. avail_from date default NULL,
  1538. avail_till date default NULL,
  1539. is_shared char(1) default '1',
  1540. template varchar(20) default NULL,
  1541. intro text,
  1542. surveythanks text,
  1543. creation_date datetime NOT NULL default '0000-00-00 00:00:00',
  1544. invited int NOT NULL,
  1545. answered int NOT NULL,
  1546. invite_mail text NOT NULL,
  1547. reminder_mail text NOT NULL,
  1548. mail_subject VARCHAR( 255 ) NOT NULL,
  1549. anonymous enum('0','1') NOT NULL default '0',
  1550. access_condition TEXT DEFAULT NULL,
  1551. shuffle bool NOT NULL default '0',
  1552. one_question_per_page bool NOT NULL default '0',
  1553. survey_version varchar(255) NOT NULL default '',
  1554. parent_id int unsigned NOT NULL,
  1555. survey_type int NOT NULL default 0,
  1556. show_form_profile int NOT NULL default 0,
  1557. form_fields TEXT NOT NULL,
  1558. session_id int unsigned NOT NULL default 0,
  1559. PRIMARY KEY (c_id, survey_id)
  1560. )" . $charset_clause;
  1561. $result = Database::query($sql);
  1562. $sql = "ALTER TABLE `".$TABLESURVEY."` ADD INDEX ( session_id )";
  1563. Database::query($sql);
  1564. $sql = "CREATE TABLE `".$TABLESURVEYINVITATION."` (
  1565. $add_to_all_tables
  1566. survey_invitation_id int unsigned NOT NULL auto_increment,
  1567. survey_code varchar(20) NOT NULL,
  1568. user varchar(250) NOT NULL,
  1569. invitation_code varchar(250) NOT NULL,
  1570. invitation_date datetime NOT NULL,
  1571. reminder_date datetime NOT NULL,
  1572. answered int NOT NULL default 0,
  1573. session_id int UNSIGNED NOT NULL default 0,
  1574. PRIMARY KEY (c_id, survey_invitation_id)
  1575. )" . $charset_clause;
  1576. $result = Database::query($sql);
  1577. $sql = "CREATE TABLE `".$TABLESURVEYQUESTION."` (
  1578. $add_to_all_tables
  1579. question_id int unsigned NOT NULL auto_increment,
  1580. survey_id int unsigned NOT NULL,
  1581. survey_question text NOT NULL,
  1582. survey_question_comment text NOT NULL,
  1583. type varchar(250) NOT NULL,
  1584. display varchar(10) NOT NULL,
  1585. sort int NOT NULL,
  1586. shared_question_id int,
  1587. max_value int,
  1588. survey_group_pri int unsigned NOT NULL default '0',
  1589. survey_group_sec1 int unsigned NOT NULL default '0',
  1590. survey_group_sec2 int unsigned NOT NULL default '0',
  1591. PRIMARY KEY (c_id, question_id)
  1592. )" . $charset_clause;
  1593. $result = Database::query($sql);
  1594. $sql ="CREATE TABLE `".$TABLESURVEYQUESTIONOPTION."` (
  1595. $add_to_all_tables
  1596. question_option_id int unsigned NOT NULL auto_increment,
  1597. question_id int unsigned NOT NULL,
  1598. survey_id int unsigned NOT NULL,
  1599. option_text text NOT NULL,
  1600. sort int NOT NULL,
  1601. value int NOT NULL default '0',
  1602. PRIMARY KEY (c_id, question_option_id)
  1603. )" . $charset_clause;
  1604. $result = Database::query($sql);
  1605. $sql = "CREATE TABLE `".$TABLESURVEYANSWER."` (
  1606. $add_to_all_tables
  1607. answer_id int unsigned NOT NULL auto_increment,
  1608. survey_id int unsigned NOT NULL,
  1609. question_id int unsigned NOT NULL,
  1610. option_id TEXT NOT NULL,
  1611. value int unsigned NOT NULL,
  1612. user varchar(250) NOT NULL,
  1613. PRIMARY KEY (c_id, answer_id)
  1614. )" . $charset_clause;
  1615. $result = Database::query($sql);
  1616. $sql = "CREATE TABLE `".$TABLESURVEYGROUP."` (
  1617. $add_to_all_tables
  1618. id int unsigned NOT NULL auto_increment,
  1619. name varchar(20) NOT NULL,
  1620. description varchar(255) NOT NULL,
  1621. survey_id int unsigned NOT NULL,
  1622. PRIMARY KEY (c_id, id)
  1623. )" . $charset_clause;
  1624. $result = Database::query($sql);
  1625. // Table glosary
  1626. $sql = "CREATE TABLE `".$TBL_GLOSSARY."` (
  1627. $add_to_all_tables
  1628. glossary_id int unsigned NOT NULL auto_increment,
  1629. name varchar(255) NOT NULL,
  1630. description text not null,
  1631. display_order int,
  1632. session_id int default 0,
  1633. PRIMARY KEY (c_id, glossary_id)
  1634. )" . $charset_clause;
  1635. $result = Database::query($sql);
  1636. $sql = "ALTER TABLE `".$TBL_GLOSSARY . "` ADD INDEX ( session_id ) ";
  1637. Database::query($sql);
  1638. // Table notebook
  1639. $sql = "CREATE TABLE `".$TBL_NOTEBOOK."` (
  1640. $add_to_all_tables
  1641. notebook_id int unsigned NOT NULL auto_increment,
  1642. user_id int unsigned NOT NULL,
  1643. course varchar(40) not null,
  1644. session_id int NOT NULL default 0,
  1645. title varchar(255) NOT NULL,
  1646. description text NOT NULL,
  1647. creation_date datetime NOT NULL default '0000-00-00 00:00:00',
  1648. update_date datetime NOT NULL default '0000-00-00 00:00:00',
  1649. status int,
  1650. PRIMARY KEY (c_id, notebook_id)
  1651. )" . $charset_clause;
  1652. $result = Database::query($sql);
  1653. /* Attendance tool */
  1654. // Attendance table
  1655. $sql = "
  1656. CREATE TABLE `".$TBL_ATTENDANCE."` (
  1657. $add_to_all_tables
  1658. id int NOT NULL auto_increment,
  1659. name text NOT NULL,
  1660. description TEXT NULL,
  1661. active tinyint NOT NULL default 1,
  1662. attendance_qualify_title varchar(255) NULL,
  1663. attendance_qualify_max int NOT NULL default 0,
  1664. attendance_weight float(6,2) NOT NULL default '0.0',
  1665. session_id int NOT NULL default 0,
  1666. locked int NOT NULL default 0,
  1667. PRIMARY KEY (c_id, id)
  1668. )" . $charset_clause;
  1669. $result = Database::query($sql);
  1670. $sql = "ALTER TABLE `".$TBL_ATTENDANCE . "` ADD INDEX (session_id)";
  1671. Database::query($sql);
  1672. $sql = "ALTER TABLE `".$TBL_ATTENDANCE . "` ADD INDEX (active)";
  1673. Database::query($sql);
  1674. // Attendance sheet table
  1675. $sql = "
  1676. CREATE TABLE `".$TBL_ATTENDANCE_SHEET."` (
  1677. $add_to_all_tables
  1678. user_id int NOT NULL,
  1679. attendance_calendar_id int NOT NULL,
  1680. presence tinyint NOT NULL DEFAULT 0,
  1681. PRIMARY KEY(c_id, user_id, attendance_calendar_id)
  1682. )" . $charset_clause;
  1683. $result = Database::query($sql);
  1684. $sql = "ALTER TABLE `".$TBL_ATTENDANCE_SHEET . "` ADD INDEX (presence) ";
  1685. Database::query($sql);
  1686. // Attendance calendar table
  1687. $sql = "
  1688. CREATE TABLE `".$TBL_ATTENDANCE_CALENDAR."` (
  1689. $add_to_all_tables
  1690. id int NOT NULL auto_increment,
  1691. attendance_id int NOT NULL ,
  1692. date_time datetime NOT NULL default '0000-00-00 00:00:00',
  1693. done_attendance tinyint NOT NULL default 0,
  1694. PRIMARY KEY(c_id, id)
  1695. )" . $charset_clause;
  1696. $result = Database::query($sql);
  1697. $sql = "ALTER TABLE `".$TBL_ATTENDANCE_CALENDAR."` ADD INDEX (attendance_id)";
  1698. Database::query($sql);
  1699. $sql = "ALTER TABLE `".$TBL_ATTENDANCE_CALENDAR."` ADD INDEX (done_attendance)";
  1700. Database::query($sql);
  1701. // Attendance result table
  1702. $sql = "
  1703. CREATE TABLE `".$TBL_ATTENDANCE_RESULT."` (
  1704. $add_to_all_tables
  1705. id int NOT NULL auto_increment,
  1706. user_id int NOT NULL,
  1707. attendance_id int NOT NULL,
  1708. score int NOT NULL DEFAULT 0,
  1709. PRIMARY KEY (c_id, id)
  1710. )" . $charset_clause;
  1711. $result = Database::query($sql);
  1712. $sql = "ALTER TABLE `".$TBL_ATTENDANCE_RESULT."` ADD INDEX (attendance_id)";
  1713. Database::query($sql);
  1714. $sql = "ALTER TABLE `".$TBL_ATTENDANCE_RESULT."` ADD INDEX (user_id)";
  1715. Database::query($sql);
  1716. // attendance sheet log table
  1717. $sql = "CREATE TABLE `".$TBL_ATTENDANCE_SHEET_LOG."` (
  1718. $add_to_all_tables
  1719. id int NOT NULL auto_increment,
  1720. attendance_id int NOT NULL DEFAULT 0,
  1721. lastedit_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  1722. lastedit_type varchar(200) NOT NULL,
  1723. lastedit_user_id int NOT NULL DEFAULT 0,
  1724. calendar_date_value datetime NULL,
  1725. PRIMARY KEY (c_id, id)
  1726. )" . $charset_clause;
  1727. $result = Database::query($sql) or die(Database::error());
  1728. // Thematic table
  1729. $sql = "CREATE TABLE `".$TBL_THEMATIC."` (
  1730. $add_to_all_tables
  1731. id int NOT NULL auto_increment,
  1732. title varchar(255) NOT NULL,
  1733. content text NULL,
  1734. display_order int unsigned NOT NULL DEFAULT 0,
  1735. active tinyint NOT NULL DEFAULT 0,
  1736. session_id int NOT NULL DEFAULT 0,
  1737. PRIMARY KEY (c_id, id)
  1738. )" . $charset_clause;
  1739. $result = Database::query($sql);
  1740. $sql = "ALTER TABLE `".$TBL_THEMATIC."` ADD INDEX (active, session_id)";
  1741. Database::query($sql);
  1742. // thematic plan table
  1743. $sql = "CREATE TABLE `".$TBL_THEMATIC_PLAN."` (
  1744. $add_to_all_tables
  1745. id int NOT NULL auto_increment,
  1746. thematic_id int NOT NULL,
  1747. title varchar(255) NOT NULL,
  1748. description text NULL,
  1749. description_type int NOT NULL,
  1750. PRIMARY KEY (c_id, id)
  1751. )" . $charset_clause;
  1752. $result = Database::query($sql);
  1753. $sql = "ALTER TABLE `".$TBL_THEMATIC_PLAN."` ADD INDEX (thematic_id, description_type)";
  1754. Database::query($sql);
  1755. // thematic advance table
  1756. $sql = "
  1757. CREATE TABLE `".$TBL_THEMATIC_ADVANCE."` (
  1758. $add_to_all_tables
  1759. id int NOT NULL auto_increment,
  1760. thematic_id int NOT NULL,
  1761. attendance_id int NOT NULL DEFAULT 0,
  1762. content text NULL,
  1763. start_date datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  1764. duration int NOT NULL DEFAULT 0,
  1765. done_advance tinyint NOT NULL DEFAULT 0,
  1766. PRIMARY KEY (c_id, id)
  1767. )" . $charset_clause;
  1768. $result = Database::query($sql);
  1769. $sql = "ALTER TABLE `".$TBL_THEMATIC_ADVANCE."` ADD INDEX (thematic_id)";
  1770. Database::query($sql);
  1771. $sql = "CREATE TABLE IF NOT EXISTS " . $TBL_METADATA . " ( " .
  1772. $add_to_all_tables.
  1773. "eid VARCHAR(250) NOT NULL," . // entry-id, e.g. doc.1
  1774. "mdxmltext TEXT default ''," . // MD-text, XML-formatted
  1775. "md5 CHAR(32) default ''," . // hash-validator
  1776. "htmlcache1 TEXT default ''," . // cached HTML, part 1
  1777. "htmlcache2 TEXT default ''," . // cached HTML, part 2
  1778. "indexabletext TEXT default ''," . // indexable for search
  1779. "PRIMARY KEY (c_id, eid) )".$charset_clause;
  1780. Database::query($sql);
  1781. return 0;
  1782. }
  1783. /**
  1784. * Returns a list of all files in the given course directory. The requested
  1785. * directory will be checked against a "checker" directory to avoid access to
  1786. * protected/unauthorized files
  1787. * @param string Complete path to directory we want to list
  1788. * @param array A list of files to which we want to add the files found
  1789. * @param string Type of base directory from which we want to recover the files
  1790. * @return array
  1791. * @assert (null,null,null) === false
  1792. * @assert ('abc',array(),'') === array()
  1793. */
  1794. function browse_folders($path, $files, $media) {
  1795. if ($media == 'images') {
  1796. $code_path = api_get_path(SYS_CODE_PATH).'default_course_document/images/';
  1797. }
  1798. if ($media == 'audio') {
  1799. $code_path = api_get_path(SYS_CODE_PATH).'default_course_document/audio/';
  1800. }
  1801. if ($media == 'flash') {
  1802. $code_path = api_get_path(SYS_CODE_PATH).'default_course_document/flash/';
  1803. }
  1804. if ($media == 'video') {
  1805. $code_path = api_get_path(SYS_CODE_PATH).'default_course_document/video/';
  1806. }
  1807. if ($media == 'certificates') {
  1808. $code_path = api_get_path(SYS_CODE_PATH).'default_course_document/certificates/';
  1809. }
  1810. if (is_dir($path)) {
  1811. $handle = opendir($path);
  1812. while (false !== ($file = readdir($handle))) {
  1813. if (is_dir($path.$file) && strpos($file, '.') !== 0) {
  1814. $files[]['dir'] = str_replace($code_path, '', $path.$file.'/');
  1815. $files = browse_folders($path.$file.'/', $files, $media);
  1816. } elseif (is_file($path.$file) && strpos($file, '.') !== 0) {
  1817. $files[]['file'] = str_replace($code_path, '', $path.$file);
  1818. }
  1819. }
  1820. }
  1821. return $files;
  1822. }
  1823. /**
  1824. * Sorts pictures by type (used?)
  1825. * @param array List of files (sthg like array(0=>array('png'=>1)))
  1826. * @param string File type
  1827. * @return array The received array without files not matching type
  1828. * @assert (array(),null) === array()
  1829. */
  1830. function sort_pictures($files, $type) {
  1831. $pictures = array();
  1832. foreach ($files as $key => $value){
  1833. if ($value[$type] != '') {
  1834. $pictures[][$type] = $value[$type];
  1835. }
  1836. }
  1837. return $pictures;
  1838. }
  1839. /**
  1840. * Fills the course repository with some example content.
  1841. * @param string Course directory name (without prefix/suffix). eg "ABC"
  1842. * @param bool Whether we want to fill it with example content or not
  1843. * @return array The (structured) list of files created
  1844. * @version 1.2
  1845. * @deprecated this function has been merged into the fill_db_course
  1846. * @assert (null, null) === false
  1847. */
  1848. function fill_course_repository($course_repository, $fill_with_exemplary_content = null) {
  1849. if (is_null($fill_with_exemplary_content)) {
  1850. $fill_with_exemplary_content = api_get_setting('example_material_course_creation') != 'false';
  1851. }
  1852. $default_document_array = array();
  1853. if ($fill_with_exemplary_content) {
  1854. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  1855. $perm = api_get_permissions_for_new_directories();
  1856. $perm_file = api_get_permissions_for_new_files();
  1857. $img_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/images/';
  1858. $audio_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/audio/';
  1859. $flash_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/flash/';
  1860. $video_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/video/';
  1861. $cert_code_path = api_get_path(SYS_CODE_PATH).'default_course_document/certificates/';
  1862. $course_documents_folder_images = $sys_course_path.$course_repository.'/document/images/gallery/';
  1863. $course_documents_folder_audio = $sys_course_path.$course_repository.'/document/audio/';
  1864. $course_documents_folder_flash = $sys_course_path.$course_repository.'/document/flash/';
  1865. $course_documents_folder_video = $sys_course_path.$course_repository.'/document/video/';
  1866. $course_documents_folder_cert = $sys_course_path.$course_repository.'/document/certificates/';
  1867. /* Images */
  1868. $files = array();
  1869. $files = browse_folders($img_code_path, $files, 'images');
  1870. $pictures_array = sort_pictures($files, 'dir');
  1871. $pictures_array = array_merge($pictures_array, sort_pictures($files, 'file'));
  1872. if (!is_dir($course_documents_folder_images)) {
  1873. mkdir($course_documents_folder_images,$perm);
  1874. }
  1875. $handle = opendir($img_code_path);
  1876. foreach ($pictures_array as $key => $value) {
  1877. if ($value['dir'] != '') {
  1878. mkdir($course_documents_folder_images.$value['dir'], $perm);
  1879. }
  1880. if ($value['file'] != '') {
  1881. copy($img_code_path.$value['file'], $course_documents_folder_images.$value['file']);
  1882. chmod($course_documents_folder_images.$value['file'], $perm_file);
  1883. }
  1884. }
  1885. // Trainer thumbnails fix.
  1886. $path_thumb = mkdir($course_documents_folder_images.'trainer/.thumbs', $perm);
  1887. $handle = opendir($img_code_path.'trainer/.thumbs/');
  1888. while (false !== ($file = readdir($handle))) {
  1889. if (is_file($img_code_path.'trainer/.thumbs/'.$file)) {
  1890. copy($img_code_path.'trainer/.thumbs/'.$file, $course_documents_folder_images.'trainer/.thumbs/'.$file);
  1891. chmod($course_documents_folder_images.'trainer/.thumbs/'.$file, $perm_file);
  1892. }
  1893. }
  1894. $default_document_array['images'] = $pictures_array;
  1895. /* Audio */
  1896. $files = array();
  1897. $files = browse_folders($audio_code_path, $files, 'audio');
  1898. $audio_array = sort_pictures($files, 'dir');
  1899. $audio_array = array_merge($audio_array,sort_pictures($files, 'file'));
  1900. if (!is_dir($course_documents_folder_audio)) {
  1901. mkdir($course_documents_folder_audio, $perm);
  1902. }
  1903. $handle = opendir($audio_code_path);
  1904. foreach ($audio_array as $key => $value){
  1905. if ($value['dir'] != '') {
  1906. mkdir($course_documents_folder_audio.$value['dir'], $perm);
  1907. }
  1908. if ($value['file'] != '') {
  1909. copy($audio_code_path.$value['file'], $course_documents_folder_audio.$value['file']);
  1910. chmod($course_documents_folder_audio.$value['file'], $perm_file);
  1911. }
  1912. }
  1913. $default_document_array['audio'] = $audio_array;
  1914. /*
  1915. * Flash
  1916. */
  1917. $files = array();
  1918. $files = browse_folders($flash_code_path, $files, 'flash');
  1919. $flash_array = sort_pictures($files, 'dir');
  1920. $flash_array = array_merge($flash_array, sort_pictures($files, 'file'));
  1921. if (!is_dir($course_documents_folder_flash)) {
  1922. mkdir($course_documents_folder_flash, $perm);
  1923. }
  1924. $handle = opendir($flash_code_path);
  1925. foreach ($flash_array as $key => $value) {
  1926. if ($value['dir'] != '') {
  1927. mkdir($course_documents_folder_flash.$value['dir'], $perm);
  1928. }
  1929. if ($value['file'] != '') {
  1930. copy($flash_code_path.$value['file'], $course_documents_folder_flash.$value['file']);
  1931. chmod($course_documents_folder_flash.$value['file'], $perm_file);
  1932. }
  1933. }
  1934. $default_document_array['flash'] = $flash_array;
  1935. /* Video */
  1936. $files = browse_folders($video_code_path, $files, 'video');
  1937. $video_array = sort_pictures($files, 'dir');
  1938. $video_array = array_merge($video_array, sort_pictures($files, 'file'));
  1939. if (!is_dir($course_documents_folder_video)) {
  1940. mkdir($course_documents_folder_video, $perm);
  1941. }
  1942. $handle = opendir($video_code_path);
  1943. foreach ($video_array as $key => $value) {
  1944. if ($value['dir'] != '') {
  1945. @mkdir($course_documents_folder_video.$value['dir'], $perm);
  1946. }
  1947. if ($value['file'] != '') {
  1948. copy($video_code_path.$value['file'], $course_documents_folder_video.$value['file']);
  1949. chmod($course_documents_folder_video.$value['file'], $perm_file);
  1950. }
  1951. }
  1952. $default_document_array['video'] = $video_array;
  1953. /* Certificates */
  1954. $files = browse_folders($cert_code_path, $files, 'certificates');
  1955. $cert_array = sort_pictures($files, 'dir'); //only one file so far
  1956. $cert_array = array_merge($cert_array, sort_pictures($files, 'file'));
  1957. if (!is_dir($course_documents_folder_cert)) {
  1958. mkdir($course_documents_folder_cert, $perm);
  1959. }
  1960. $handle = opendir($cert_code_path);
  1961. foreach ($cert_array as $key => $value) {
  1962. if ($value['dir'] != '') {
  1963. @mkdir($course_documents_folder_cert.$value['dir'], $perm);
  1964. }
  1965. if ($value['file'] != '') {
  1966. copy($cert_code_path.$value['file'], $course_documents_folder_cert.$value['file']);
  1967. chmod($course_documents_folder_cert.$value['file'], $perm_file);
  1968. }
  1969. }
  1970. $default_document_array['cert'] = $cert_array;
  1971. }
  1972. return $default_document_array;
  1973. }
  1974. /**
  1975. * Function to convert a string from the language files to a string ready
  1976. * to insert into the database (escapes single quotes)
  1977. * @author Bart Mollet (bart.mollet@hogent.be)
  1978. * @param string $string The string to convert
  1979. * @return string The string converted to insert into the database
  1980. * @assert ('a\'b') === 'ab'
  1981. */
  1982. function lang2db($string) {
  1983. $string = str_replace("\\'", "'", $string);
  1984. $string = Database::escape_string($string);
  1985. return $string;
  1986. }
  1987. /**
  1988. * Fills the course database with some required content and example content.
  1989. * @param int Course (int) ID
  1990. * @param string Course directory name (e.g. 'ABC')
  1991. * @param string Language used for content (e.g. 'spanish')
  1992. * @param bool Whether to fill the course with example content
  1993. * @return bool False on error, true otherwise
  1994. * @version 1.2
  1995. * @assert (null, '', '', null) === false
  1996. * @assert (1, 'ABC', null, null) === false
  1997. * @assert (1, 'TEST', 'spanish', true) === true
  1998. */
  1999. function fill_db_course($course_id, $course_repository, $language, $fill_with_exemplary_content = null) {
  2000. if (is_null($fill_with_exemplary_content)) {
  2001. $fill_with_exemplary_content = api_get_setting('example_material_course_creation') != 'false';
  2002. }
  2003. global $_configuration;
  2004. $course_id = intval($course_id);
  2005. if (empty($course_id)) {
  2006. return false;
  2007. }
  2008. $now = api_get_utc_datetime(time());
  2009. $tbl_course_homepage = Database::get_course_table(TABLE_TOOL_LIST);
  2010. $TABLEINTROS = Database::get_course_table(TABLE_TOOL_INTRO);
  2011. $TABLEGROUPCATEGORIES = Database::get_course_table(TABLE_GROUP_CATEGORY);
  2012. $TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  2013. $TABLETOOLAGENDA = Database::get_course_table(TABLE_AGENDA);
  2014. $TABLETOOLANNOUNCEMENTS = Database::get_course_table(TABLE_ANNOUNCEMENT);
  2015. $TABLETOOLDOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  2016. $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
  2017. $TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
  2018. $TABLEQUIZQUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  2019. $TABLEQUIZQUESTIONLIST = Database::get_course_table(TABLE_QUIZ_QUESTION);
  2020. $TABLEQUIZANSWERSLIST = Database::get_course_table(TABLE_QUIZ_ANSWER);
  2021. $TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING);
  2022. $TABLEFORUMCATEGORIES = Database::get_course_table(TABLE_FORUM_CATEGORY);
  2023. $TABLEFORUMS = Database::get_course_table(TABLE_FORUM);
  2024. $TABLEFORUMTHREADS = Database::get_course_table(TABLE_FORUM_THREAD);
  2025. $TABLEFORUMPOSTS = Database::get_course_table(TABLE_FORUM_POST);
  2026. $TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
  2027. $TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
  2028. $TABLEGRADEBOOKCERT = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
  2029. include api_get_path(SYS_CODE_PATH).'lang/english/create_course.inc.php';
  2030. $file_to_include = api_get_path(SYS_CODE_PATH).'lang/'.$language.'/create_course.inc.php';
  2031. if (file_exists($file_to_include)) {
  2032. include $file_to_include;
  2033. }
  2034. $visible_for_all = 1;
  2035. $visible_for_course_admin = 0;
  2036. $visible_for_platform_admin = 2;
  2037. /* Course tools */
  2038. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_COURSE_DESCRIPTION . "','course_description/','info.gif','".string2binary(api_get_setting('course_create_active_tools', 'course_description')) . "','0','squaregrey.gif','NO','_self','authoring','0')");
  2039. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_CALENDAR_EVENT . "','calendar/agenda.php','agenda.gif','".string2binary(api_get_setting('course_create_active_tools', 'agenda')) . "','0','squaregrey.gif','NO','_self','interaction','0')");
  2040. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_DOCUMENT . "','document/document.php','folder_document.gif','".string2binary(api_get_setting('course_create_active_tools', 'documents')) . "','0','squaregrey.gif','NO','_self','authoring','0')");
  2041. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_LEARNPATH . "','newscorm/lp_controller.php','scorms.gif','".string2binary(api_get_setting('course_create_active_tools', 'learning_path')) . "','0','squaregrey.gif','NO','_self','authoring','0')");
  2042. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_LINK . "','link/link.php','links.gif','".string2binary(api_get_setting('course_create_active_tools', 'links')) . "','0','squaregrey.gif','NO','_self','authoring','0')");
  2043. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_QUIZ . "','exercice/exercice.php','quiz.gif','".string2binary(api_get_setting('course_create_active_tools', 'quiz')) . "','0','squaregrey.gif','NO','_self','authoring','0')");
  2044. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_ANNOUNCEMENT . "','announcements/announcements.php','valves.gif','".string2binary(api_get_setting('course_create_active_tools', 'announcements')) . "','0','squaregrey.gif','NO','_self','authoring','0')");
  2045. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_FORUM . "','forum/index.php','forum.gif','".string2binary(api_get_setting('course_create_active_tools', 'forums')) . "','0','squaregrey.gif','NO','_self','interaction','0')");
  2046. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_DROPBOX . "','dropbox/index.php','dropbox.gif','".string2binary(api_get_setting('course_create_active_tools', 'dropbox')) . "','0','squaregrey.gif','NO','_self','interaction','0')");
  2047. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_USER . "','user/user.php','members.gif','".string2binary(api_get_setting('course_create_active_tools', 'users')) . "','0','squaregrey.gif','NO','_self','interaction','0')");
  2048. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_GROUP . "','group/group.php','group.gif','".string2binary(api_get_setting('course_create_active_tools', 'groups')) . "','0','squaregrey.gif','NO','_self','interaction','0')");
  2049. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_CHAT . "','chat/chat.php','chat.gif','".string2binary(api_get_setting('course_create_active_tools', 'chat')) . "','0','squaregrey.gif','NO','_self','interaction','0')");
  2050. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_STUDENTPUBLICATION . "','work/work.php','works.gif','".string2binary(api_get_setting('course_create_active_tools', 'student_publications')) . "','0','squaregrey.gif','NO','_self','interaction','0')");
  2051. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_SURVEY."','survey/survey_list.php','survey.gif','".string2binary(api_get_setting('course_create_active_tools', 'survey')) . "','0','squaregrey.gif','NO','_self','interaction','0')");
  2052. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_WIKI ."','wiki/index.php','wiki.gif','".string2binary(api_get_setting('course_create_active_tools', 'wiki')) . "','0','squaregrey.gif','NO','_self','interaction','0')");
  2053. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_GRADEBOOK."','gradebook/index.php','gradebook.gif','".string2binary(api_get_setting('course_create_active_tools', 'gradebook')). "','0','squaregrey.gif','NO','_self','authoring','0')");
  2054. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_GLOSSARY."','glossary/index.php','glossary.gif','".string2binary(api_get_setting('course_create_active_tools', 'glossary')). "','0','squaregrey.gif','NO','_self','authoring','0')");
  2055. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_NOTEBOOK."','notebook/index.php','notebook.gif','".string2binary(api_get_setting('course_create_active_tools', 'notebook'))."','0','squaregrey.gif','NO','_self','interaction','0')");
  2056. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_ATTENDANCE."','attendance/index.php','attendance.gif','".string2binary(api_get_setting('course_create_active_tools', 'attendances'))."','0','squaregrey.gif','NO','_self','authoring','0')");
  2057. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_COURSE_PROGRESS."','course_progress/index.php','course_progress.gif','".string2binary(api_get_setting('course_create_active_tools', 'course_progress'))."','0','squaregrey.gif','NO','_self','authoring','0')");
  2058. if (api_get_setting('service_visio', 'active') == 'true') {
  2059. $mycheck = api_get_setting('service_visio', 'visio_host');
  2060. if (!empty($mycheck)) {
  2061. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_VISIO_CONFERENCE . "','conference/index.php?type=conference','visio_meeting.gif','1','0','squaregrey.gif','NO','_self','interaction','0')");
  2062. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_VISIO_CLASSROOM . "','conference/index.php?type=classroom','visio.gif','1','0','squaregrey.gif','NO','_self','authoring','0')");
  2063. }
  2064. }
  2065. if (api_get_setting('search_enabled') == 'true') {
  2066. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '" . TOOL_SEARCH. "','search/','info.gif','".string2binary(api_get_setting('course_create_active_tools', 'enable_search')) . "','0','search.gif','NO','_self','authoring','0')");
  2067. }
  2068. // Smartblogs (Kevin Van Den Haute :: kevin@develop-it.be)
  2069. $sql = "INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL,'" . TOOL_BLOGS . "','blog/blog_admin.php','blog_admin.gif','" . string2binary(api_get_setting('course_create_active_tools', 'blogs')) . "','1','squaregrey.gif','NO','_self','admin','0')";
  2070. Database::query($sql);
  2071. // end of Smartblogs
  2072. /* Course homepage tools for course admin only */
  2073. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '".TOOL_TRACKING . "','tracking/courseLog.php','statistics.gif','$visible_for_course_admin','1','', 'NO','_self','admin','0')");
  2074. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '".TOOL_COURSE_SETTING . "','course_info/infocours.php','reference.gif','$visible_for_course_admin','1','', 'NO','_self','admin','0')");
  2075. Database::query("INSERT INTO $tbl_course_homepage VALUES ($course_id, NULL, '".TOOL_COURSE_MAINTENANCE."','course_info/maintenance.php','backup.gif','$visible_for_course_admin','1','','NO','_self', 'admin','0')");
  2076. $defaultEmailExerciseAlert = 1;
  2077. if (isset($_configuration['email_alert_manager_on_new_quiz'])) {
  2078. $defaultEmailExerciseAlert = intval($_configuration['email_alert_manager_on_new_quiz']);
  2079. }
  2080. /* course_setting table (courseinfo tool) */
  2081. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_manager_on_new_doc',0,'work')");
  2082. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_on_new_doc_dropbox',0,'dropbox')");
  2083. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_user_edit_agenda',0,'agenda')");
  2084. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_user_edit_announcement',0,'announcement')");
  2085. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_manager_on_new_quiz', $defaultEmailExerciseAlert,'quiz')");
  2086. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_user_image_forum',1,'forum')");
  2087. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'course_theme','','theme')");
  2088. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_learning_path_theme','1','theme')");
  2089. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_open_chat_window',1,'chat')");
  2090. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_to_teacher_on_new_user_in_course',0,'registration')");
  2091. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_user_view_user_list',1,'user')");
  2092. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'display_info_advance_inside_homecourse',1,'thematic_advance')");
  2093. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_students_on_new_homework',0,'work')");
  2094. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'enable_lp_auto_launch',0,'learning_path')");
  2095. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'pdf_export_watermark_text','','learning_path')");
  2096. Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_public_certificates','','certificates')");
  2097. Database::query("INSERT INTO $TABLESETTING (c_id, variable, value) VALUES ($course_id, 'documents_default_visibility', 'visible')");
  2098. /* Course homepage tools for platform admin only */
  2099. /* Group tool */
  2100. Database::query("INSERT INTO $TABLEGROUPCATEGORIES (c_id, id , title , description , max_student , self_reg_allowed , self_unreg_allowed , groups_per_user , display_order )
  2101. VALUES ($course_id, '2', '".lang2db(get_lang('DefaultGroupCategory')) . "', '', '8', '0', '0', '0', '0');");
  2102. /* Example Material */
  2103. global $language_interface;
  2104. $language_interface = !empty($language_interface) ? $language_interface : api_get_setting('platformLanguage');
  2105. // Example material should be in the same language as the course is.
  2106. $language_interface_original = $language_interface;
  2107. $language_interface = $language;
  2108. //Share folder
  2109. Database::query("INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) VALUES ($course_id,'/shared_folder','".get_lang('UserFolders')."','folder','0')");
  2110. $example_doc_id = Database :: insert_id();
  2111. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id,'document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)");
  2112. //Chat folder
  2113. Database::query("INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) VALUES ($course_id,'/chat_files','".get_lang('ChatFiles')."','folder','0')");
  2114. $example_doc_id = Database :: insert_id();
  2115. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id,'document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)");
  2116. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  2117. $perm = api_get_permissions_for_new_directories();
  2118. $perm_file = api_get_permissions_for_new_files();
  2119. $chat_path = $sys_course_path.$course_repository.'/document/chat_files';
  2120. if (!is_dir($chat_path)) {
  2121. @mkdir($chat_path, api_get_permissions_for_new_directories());
  2122. }
  2123. /* Documents */
  2124. if ($fill_with_exemplary_content) {
  2125. Database::query("INSERT INTO $TABLETOOLDOCUMENT (c_id,path,title,filetype,size) VALUES ($course_id,'/images','".get_lang('Images')."','folder','0')");
  2126. $example_doc_id = Database :: insert_id();
  2127. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id,'document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)");
  2128. Database::query("INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) VALUES ($course_id,'/images/gallery','".get_lang('DefaultCourseImages')."','folder','0')");
  2129. $example_doc_id = Database :: insert_id();
  2130. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id,'document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)");
  2131. Database::query("INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) VALUES ($course_id,'/audio','".get_lang('Audio')."','folder','0')");
  2132. $example_doc_id = Database :: insert_id();
  2133. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id,'document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)");
  2134. Database::query("INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) VALUES ($course_id,'/flash','".get_lang('Flash')."','folder','0')");
  2135. $example_doc_id = Database :: insert_id();
  2136. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id,'document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)");
  2137. Database::query("INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) VALUES ($course_id,'/video','".get_lang('Video')."','folder','0')");
  2138. $example_doc_id = Database :: insert_id();
  2139. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id,'document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)");
  2140. Database::query("INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) VALUES ($course_id,'/certificates','".get_lang('Certificates')."','folder','0')");
  2141. $example_doc_id = Database :: insert_id();
  2142. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id,'document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)");
  2143. // FILL THE COURSE DOCUMENT WITH DEFAULT COURSE PICTURES
  2144. $folders_to_copy_from_default_course = array(
  2145. 'images',
  2146. 'audio',
  2147. 'flash',
  2148. 'video',
  2149. 'certificates',
  2150. );
  2151. $default_course_path = api_get_path(SYS_CODE_PATH).'default_course_document/';
  2152. $default_document_array = array();
  2153. foreach ($folders_to_copy_from_default_course as $folder) {
  2154. $default_course_folder_path = $default_course_path.$folder.'/';
  2155. $files = browse_folders($default_course_folder_path, array(), $folder);
  2156. $sorted_array = sort_pictures($files, 'dir');
  2157. $sorted_array = array_merge($sorted_array, sort_pictures($files, 'file'));
  2158. $default_document_array[$folder] = $sorted_array;
  2159. }
  2160. //echo '<pre>'; print_r($default_document_array);exit;
  2161. //Light protection (adding index.html in every document folder)
  2162. $htmlpage = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <title>Not authorized</title>\n </head>\n <body>\n </body>\n</html>";
  2163. $example_cert_id = 0;
  2164. if (is_array($default_document_array) && count($default_document_array) > 0) {
  2165. foreach ($default_document_array as $media_type => $array_media) {
  2166. $path_documents = "/$media_type/";
  2167. //hack until feature #5242 is implemented
  2168. if ($media_type == 'images') {
  2169. $media_type = 'images/gallery';
  2170. $images_folder = $sys_course_path.$course_repository."/document/images/";
  2171. if (!is_dir($images_folder)) {
  2172. //Creating index.html
  2173. mkdir($images_folder, $perm);
  2174. $fd = fopen($images_folder.'index.html', 'w');
  2175. fwrite($fd, $htmlpage);
  2176. @chmod($images_folder.'index.html', $perm_file);
  2177. }
  2178. }
  2179. $course_documents_folder = $sys_course_path.$course_repository."/document/$media_type/";
  2180. $default_course_path = api_get_path(SYS_CODE_PATH).'default_course_document'.$path_documents;
  2181. //echo 'try '.$course_documents_folder; echo '<br />';
  2182. if (!is_dir($course_documents_folder)) {
  2183. //Creating index.html
  2184. mkdir($course_documents_folder, $perm);
  2185. $fd = fopen($course_documents_folder.'index.html', 'w');
  2186. fwrite($fd, $htmlpage);
  2187. @chmod($course_documents_folder.'index.html', $perm_file);
  2188. }
  2189. if (is_array($array_media) && count($array_media)>0) {
  2190. foreach ($array_media as $key => $value) {
  2191. if (isset($value['dir']) && !empty($value['dir'])) {
  2192. if (!is_dir($course_documents_folder.$value['dir'])) {
  2193. //Creating folder
  2194. mkdir($course_documents_folder.$value['dir'], $perm);
  2195. //Creating index.html (for light protection)
  2196. $index_html = $course_documents_folder.$value['dir'].'/index.html';
  2197. $fd = fopen($index_html, 'w');
  2198. fwrite($fd, $htmlpage);
  2199. @chmod($index_html, $perm_file);
  2200. //Inserting folder in the DB
  2201. $folder_path = substr($value['dir'], 0, strlen($value['dir']) - 1);
  2202. $temp = explode('/', $folder_path);
  2203. $title = $temp[count($temp)-1];
  2204. //hack until feature #5242 is implemented
  2205. if ($title == 'gallery') {
  2206. $title = get_lang('DefaultCourseImages');
  2207. }
  2208. if ($media_type == 'images/gallery') {
  2209. $folder_path = 'gallery/'.$folder_path;
  2210. }
  2211. Database::query("INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) VALUES ($course_id,'$path_documents".$folder_path."','".$title."','folder','0')");
  2212. $image_id = Database :: insert_id();
  2213. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id,'document',1,NOW(),NOW(),$image_id,'DocumentAdded',1,0,NULL,0)");
  2214. }
  2215. }
  2216. if (isset($value['file']) && !empty($value['file'])) {
  2217. if (!file_exists($course_documents_folder.$value['file'])) {
  2218. //Copying file
  2219. copy($default_course_path.$value['file'], $course_documents_folder.$value['file']);
  2220. chmod($course_documents_folder.$value['file'], $perm_file);
  2221. //echo $default_course_path.$value['file']; echo ' - '; echo $course_documents_folder.$value['file']; echo '<br />';
  2222. $temp = explode('/', $value['file']);
  2223. $file_size = filesize($course_documents_folder.$value['file']);
  2224. //hack until feature #5242 is implemented
  2225. if ($media_type == 'images/gallery') {
  2226. $value["file"] = 'gallery/'.$value["file"];
  2227. }
  2228. //Inserting file in the DB
  2229. Database::query("INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) VALUES ($course_id,'$path_documents".$value["file"]."','".$temp[count($temp)-1]."','file','$file_size')");
  2230. $image_id = Database :: insert_id();
  2231. if ($path_documents.$value['file'] == '/certificates/default.html') {
  2232. $example_cert_id = $image_id;
  2233. }
  2234. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id,'document',1,NOW(),NOW(),$image_id,'DocumentAdded',1,0,NULL,1)");
  2235. }
  2236. }
  2237. }
  2238. }
  2239. }
  2240. }
  2241. /* Agenda tool */
  2242. Database::query("INSERT INTO $TABLETOOLAGENDA VALUES ($course_id, NULL, '".lang2db(get_lang('AgendaCreationTitle')) . "', '".lang2db(get_lang('AgendaCreationContenu')) . "', now(), now(), NULL, 0, 0)");
  2243. // We need to add the item properties too!
  2244. $insert_id = Database :: insert_id();
  2245. $sql = "INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ($course_id, '" . TOOL_CALENDAR_EVENT . "',1,NOW(),NOW(),$insert_id,'AgendaAdded',1,0,NULL,1)";
  2246. Database::query($sql);
  2247. /* Links tool */
  2248. $add_google_link_sql = "INSERT INTO $TABLETOOLLINK (c_id, url, title, description, category_id, display_order, on_homepage, target)
  2249. VALUES ($course_id, 'http://www.google.com','Google','".lang2db(get_lang('Google')) . "','0','0','0','_self')";
  2250. Database::query($add_google_link_sql);
  2251. // We need to add the item properties too!
  2252. $insert_id = Database :: insert_id();
  2253. $sql = "INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)
  2254. VALUES ($course_id, '" . TOOL_LINK . "',1,NOW(),NOW(),$insert_id,'LinkAdded',1,0,NULL,1)";
  2255. Database::query($sql);
  2256. $add_wikipedia_link_sql = "INSERT INTO $TABLETOOLLINK (c_id, url, title, description, category_id, display_order, on_homepage, target)
  2257. VALUES ($course_id, 'http://www.wikipedia.org','Wikipedia','".lang2db(get_lang('Wikipedia')) . "','0','1','0','_self')";
  2258. Database::query($add_wikipedia_link_sql);
  2259. // We need to add the item properties too!
  2260. $insert_id = Database :: insert_id();
  2261. $sql = "INSERT INTO $TABLEITEMPROPERTY (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('" . TOOL_LINK . "',1,NOW(),NOW(),$insert_id,'LinkAdded',1,0,NULL,1)";
  2262. Database::query($sql);
  2263. /* Annoucement tool */
  2264. $sql = "INSERT INTO $TABLETOOLANNOUNCEMENTS (c_id, title,content,end_date,display_order,email_sent)
  2265. VALUES ($course_id, '".lang2db(get_lang('AnnouncementExampleTitle')) . "', '".lang2db(get_lang('AnnouncementEx')) . "', NOW(), '1','0')";
  2266. Database::query($sql);
  2267. // We need to add the item properties too!
  2268. $insert_id = Database :: insert_id();
  2269. $sql = "INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)
  2270. VALUES ($course_id, '" . TOOL_ANNOUNCEMENT . "',1,NOW(),NOW(),$insert_id,'AnnouncementAdded',1,0,NULL,1)";
  2271. Database::query($sql);
  2272. /* Introduction text */
  2273. $intro_text='<p style="text-align: center;">
  2274. <img src="'.api_get_path(REL_CODE_PATH).'img/mascot.png" alt="Mr. Chamilo" title="Mr. Chamilo" />
  2275. <h2>'.lang2db(get_lang('IntroductionText')).'</h2>
  2276. </p>';
  2277. Database::query("INSERT INTO $TABLEINTROS VALUES ($course_id, '" . TOOL_COURSE_HOMEPAGE . "','".$intro_text."', 0)");
  2278. Database::query("INSERT INTO $TABLEINTROS VALUES ($course_id, '" . TOOL_STUDENTPUBLICATION . "','".lang2db(get_lang('IntroductionTwo')) . "', 0)");
  2279. // Wiki intro
  2280. $intro_wiki='<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="110" valign="top" align="left"></td><td valign="top" align="left">'.lang2db(get_lang('IntroductionWiki')).'</td></tr></table>';
  2281. Database::query("INSERT INTO $TABLEINTROS VALUES ($course_id, '" . TOOL_WIKI . "','".$intro_wiki. "', 0)");
  2282. /* Exercise tool */
  2283. Database::query("INSERT INTO $TABLEQUIZANSWERSLIST (c_id, id, question_id, answer, correct, comment, ponderation, position) VALUES ($course_id, '1', '1', '".lang2db(get_lang('Ridiculise')) . "', '0', '".lang2db(get_lang('NoPsychology')) . "', '-5', '1')");
  2284. Database::query("INSERT INTO $TABLEQUIZANSWERSLIST (c_id, id, question_id, answer, correct, comment, ponderation, position) VALUES ($course_id, '2', '1', '".lang2db(get_lang('AdmitError')) . "', '0', '".lang2db(get_lang('NoSeduction')) . "', '-5', '2')");
  2285. Database::query("INSERT INTO $TABLEQUIZANSWERSLIST (c_id, id, question_id, answer, correct, comment, ponderation, position) VALUES ($course_id, '3', '1', '".lang2db(get_lang('Force')) . "', '1', '".lang2db(get_lang('Indeed')) . "', '5', '3')");
  2286. Database::query("INSERT INTO $TABLEQUIZANSWERSLIST (c_id, id, question_id, answer, correct, comment, ponderation, position) VALUES ($course_id, '4', '1', '".lang2db(get_lang('Contradiction')) . "', '1', '".lang2db(get_lang('NotFalse')) . "', '5', '4')");
  2287. $html=Database::escape_string('<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="110" valign="top" align="left"><img src="'.api_get_path(WEB_CODE_PATH).'default_course_document/images/mr_dokeos/thinking.jpg"></td><td valign="top" align="left">'.get_lang('Antique').'</td></tr></table>');
  2288. Database::query('INSERT INTO '.$TABLEQUIZ .
  2289. ' (c_id, title, description, type, random, random_answers, active, results_disabled ) ' .
  2290. ' VALUES ('.$course_id.', "'.lang2db(get_lang('ExerciceEx')) . '",' .
  2291. ' "'.$html.'", "1", "0", "0", "1", "0")');
  2292. $exercise_id = Database :: insert_id();
  2293. Database::query("INSERT INTO $TABLEQUIZQUESTIONLIST (c_id, id, question, description, ponderation, position, type, picture, level)
  2294. VALUES ( '.$course_id.', '1', '".lang2db(get_lang('SocraticIrony')) . "', '".lang2db(get_lang('ManyAnswers')) . "', '10', '1', '2','',1)");
  2295. Database::query("INSERT INTO $TABLEQUIZQUESTION (c_id, question_id, exercice_id, question_order) VALUES ('.$course_id.', 1,1,1)");
  2296. /* Forum tool */
  2297. Database::query("INSERT INTO $TABLEFORUMCATEGORIES VALUES ($course_id, 1,'".lang2db(get_lang('ExampleForumCategory'))."', '', 1, 0, 0)");
  2298. $insert_id = Database :: insert_id();
  2299. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)
  2300. VALUES ($course_id, 'forum_category',1,NOW(),NOW(),$insert_id,'ForumCategoryAdded',1,0,NULL,1)");
  2301. Database::query("INSERT INTO $TABLEFORUMS (c_id, forum_title, forum_comment, forum_threads,forum_posts,forum_last_post,forum_category, allow_anonymous, allow_edit,allow_attachments, allow_new_threads,default_view,forum_of_group,forum_group_public_private, forum_order,locked,session_id )
  2302. VALUES ($course_id, '".lang2db(get_lang('ExampleForum'))."', '', 0, 0, 0, 1, 0, 1, '0', 1, 'flat','0', 'public', 1, 0,0)");
  2303. $insert_id = Database :: insert_id();
  2304. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)
  2305. VALUES ($course_id, '".TOOL_FORUM."', 1,NOW(),NOW(),$insert_id,'ForumAdded',1,0,NULL,1)");
  2306. Database::query("INSERT INTO $TABLEFORUMTHREADS (c_id, thread_id, thread_title, forum_id, thread_replies, thread_poster_id, thread_poster_name, thread_views, thread_last_post, thread_date, locked, thread_qualify_max, session_id)
  2307. VALUES ($course_id, 1, '".lang2db(get_lang('ExampleThread'))."', 1, 0, 1, '', 0, 1, NOW(), 0, 10, 0)");
  2308. $insert_id = Database :: insert_id();
  2309. Database::query("INSERT INTO $TABLEITEMPROPERTY (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)
  2310. VALUES ($course_id, 'forum_thread',1,NOW(),NOW(),$insert_id,'ForumThreadAdded',1,0,NULL,1)");
  2311. Database::query("INSERT INTO $TABLEFORUMPOSTS VALUES ($course_id, 1, '".lang2db(get_lang('ExampleThread'))."', '".lang2db(get_lang('ExampleThreadContent'))."', 1, 1, 1, '', NOW(), 0, 0, 1)");
  2312. /* Gradebook tool */
  2313. $course = api_get_course_info_by_id($course_id);
  2314. $course_code = $course['code'];
  2315. // father gradebook
  2316. Database::query("INSERT INTO $TABLEGRADEBOOK (name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id, document_id) VALUES ('$course_code','',1,'$course_code',0,100,0,75,NULL,$example_cert_id)");
  2317. $gbid = Database :: insert_id();
  2318. Database::query("INSERT INTO $TABLEGRADEBOOK (name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id, document_id) VALUES ('$course_code','',1,'$course_code',$gbid,100,1,75,NULL,$example_cert_id)");
  2319. $gbid = Database :: insert_id();
  2320. Database::query("INSERT INTO $TABLEGRADEBOOKLINK (type, ref_id, user_id, course_code, category_id, created_at, weight, visible, locked) VALUES (1,$exercise_id,1,'$course_code',$gbid,'$now',100,1,0)");
  2321. }
  2322. //Installing plugins in course
  2323. $app_plugin = new AppPlugin();
  2324. $app_plugin->install_course_plugins($course_id);
  2325. $language_interface = $language_interface_original;
  2326. return true;
  2327. }
  2328. /**
  2329. * function string2binary converts the string "true" or "false" to the boolean true false (0 or 1)
  2330. * This is used for the Chamilo Config Settings as these store true or false as string
  2331. * and the api_get_setting('course_create_active_tools') should be 0 or 1 (used for
  2332. * the visibility of the tool)
  2333. * @param string $variable
  2334. * @author Patrick Cool, patrick.cool@ugent.be
  2335. * @assert ('true') === true
  2336. * @assert ('false') === false
  2337. */
  2338. function string2binary($variable) {
  2339. if ($variable == 'true') {
  2340. return true;
  2341. }
  2342. if ($variable == 'false') {
  2343. return false;
  2344. }
  2345. }
  2346. /**
  2347. * Function register_course to create a record in the course table of the main database
  2348. * @param array Course details (see code for details)
  2349. * @return int Created course ID
  2350. * @todo use an array called $params instead of lots of params
  2351. * @assert (null) === false
  2352. */
  2353. function register_course($params)
  2354. {
  2355. global $error_msg, $firstExpirationDelay;
  2356. $title = $params['title'];
  2357. $code = $params['code'];
  2358. $visual_code = $params['visual_code'];
  2359. $directory = $params['directory'];
  2360. $tutor_name = isset($params['tutor_name']) ? $params['tutor_name'] : null;
  2361. //$description = $params['description'];
  2362. $category_code = $params['course_category'];
  2363. $course_language = isset($params['course_language']) && !empty($params['course_language']) ? $params['course_language'] : api_get_setting('platformLanguage');
  2364. $user_id = empty($params['user_id']) ? api_get_user_id() : intval($params['user_id']);
  2365. $department_name = isset($params['department_name']) ?
  2366. $params['department_name'] : null;
  2367. $department_url = isset($params['department_url']) ?
  2368. $params['department_url'] : null;
  2369. $disk_quota = isset($params['disk_quota']) ?
  2370. $params['disk_quota'] : null;
  2371. if (!isset($params['visibility'])) {
  2372. $default_course_visibility = api_get_setting('courses_default_creation_visibility');
  2373. if (isset($default_course_visibility)) {
  2374. $visibility = $default_course_visibility;
  2375. } else {
  2376. $visibility = COURSE_VISIBILITY_OPEN_PLATFORM;
  2377. }
  2378. } else {
  2379. $visibility = $params['visibility'];
  2380. }
  2381. $subscribe = isset($params['subscribe']) ? intval($params['subscribe']) : ($visibility == COURSE_VISIBILITY_OPEN_PLATFORM ? 1 : 0);
  2382. $unsubscribe = isset($params['unsubscribe']) ? intval($params['unsubscribe']) : 0;
  2383. $expiration_date = isset($params['expiration_date']) ? $params['expiration_date'] : null;
  2384. $teachers = isset($params['teachers']) ? $params['teachers'] : null;
  2385. $status = isset($params['status']) ? $params['status'] : null;
  2386. $TABLECOURSE = Database :: get_main_table(TABLE_MAIN_COURSE);
  2387. $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  2388. $ok_to_register_course = true;
  2389. // Check whether all the needed parameters are present.
  2390. if (empty($code)) {
  2391. $error_msg[] = 'courseSysCode is missing';
  2392. $ok_to_register_course = false;
  2393. }
  2394. if (empty($visual_code)) {
  2395. $error_msg[] = 'courseScreenCode is missing';
  2396. $ok_to_register_course = false;
  2397. }
  2398. if (empty($directory)) {
  2399. $error_msg[] = 'courseRepository is missing';
  2400. $ok_to_register_course = false;
  2401. }
  2402. if (empty($title)) {
  2403. $error_msg[] = 'title is missing';
  2404. $ok_to_register_course = false;
  2405. }
  2406. if (empty($expiration_date)) {
  2407. $expiration_date = api_get_utc_datetime(time() + $firstExpirationDelay);
  2408. } else {
  2409. $expiration_date = api_get_utc_datetime($expiration_date);
  2410. }
  2411. if ($visibility < 0 || $visibility > 4) {
  2412. $error_msg[] = 'visibility is invalid';
  2413. $ok_to_register_course = false;
  2414. }
  2415. if (empty($disk_quota)) {
  2416. $disk_quota = api_get_setting('default_document_quotum');
  2417. }
  2418. $time = api_get_utc_datetime();
  2419. if (stripos($department_url, 'http://') === false && stripos($department_url, 'https://') === false) {
  2420. $department_url = 'http://'.$department_url;
  2421. }
  2422. //just in case
  2423. if ($department_url == 'http://') {
  2424. $department_url = '';
  2425. }
  2426. $course_id = 0;
  2427. if ($ok_to_register_course) {
  2428. // Here we must add 2 fields.
  2429. $sql = "INSERT INTO ".$TABLECOURSE . " SET
  2430. code = '".Database :: escape_string($code) . "',
  2431. directory = '".Database :: escape_string($directory) . "',
  2432. course_language = '".Database :: escape_string($course_language) . "',
  2433. title = '".Database :: escape_string($title) . "',
  2434. description = '".lang2db(get_lang('CourseDescription')) . "',
  2435. category_code = '".Database :: escape_string($category_code) . "',
  2436. visibility = '".$visibility . "',
  2437. show_score = '1',
  2438. disk_quota = '".intval($disk_quota) . "',
  2439. creation_date = '$time',
  2440. expiration_date = '".$expiration_date . "',
  2441. last_edit = '$time',
  2442. last_visit = NULL,
  2443. tutor_name = '".Database :: escape_string($tutor_name) . "',
  2444. department_name = '".Database :: escape_string($department_name) . "',
  2445. department_url = '".Database :: escape_string($department_url) . "',
  2446. subscribe = '".intval($subscribe) . "',
  2447. unsubscribe = '".intval($unsubscribe) . "',
  2448. visual_code = '".Database :: escape_string($visual_code) . "'";
  2449. Database::query($sql);
  2450. $course_id = Database::insert_id();
  2451. if ($course_id) {
  2452. $sort = api_max_sort_value('0', api_get_user_id());
  2453. // Default true
  2454. $addTeacher = isset($params['add_user_as_teacher']) ? $params['add_user_as_teacher'] : true;
  2455. if ($addTeacher) {
  2456. $i_course_sort = CourseManager:: userCourseSort(
  2457. $user_id,
  2458. $code
  2459. );
  2460. if (!empty($user_id)) {
  2461. $sql = "INSERT INTO " . $TABLECOURSUSER . " SET
  2462. course_code = '" . Database:: escape_string($code) . "',
  2463. user_id = '" . intval($user_id) . "',
  2464. status = '1',
  2465. role = '" . lang2db(get_lang('Professor')) . "',
  2466. tutor_id = '0',
  2467. sort = '" . ($i_course_sort) . "',
  2468. user_course_cat = '0'";
  2469. Database::query($sql);
  2470. }
  2471. }
  2472. if (!empty($teachers)) {
  2473. if (!is_array($teachers)) {
  2474. $teachers = array($teachers);
  2475. }
  2476. foreach ($teachers as $key) {
  2477. //just in case
  2478. if ($key == $user_id) {
  2479. continue;
  2480. }
  2481. if (empty($key)) {
  2482. continue;
  2483. }
  2484. $sql = "INSERT INTO ".$TABLECOURSUSER . " SET
  2485. course_code = '".Database::escape_string($code) . "',
  2486. user_id = '".Database::escape_string($key) . "',
  2487. status = '1',
  2488. role = '',
  2489. tutor_id = '0',
  2490. sort = '". ($sort +1) . "',
  2491. user_course_cat = '0'";
  2492. Database::query($sql);
  2493. }
  2494. }
  2495. // Adding the course to an URL.
  2496. if (api_get_multiple_access_url()) {
  2497. $url_id = 1;
  2498. if (api_get_current_access_url_id() != -1) {
  2499. $url_id = api_get_current_access_url_id();
  2500. }
  2501. UrlManager::add_course_to_url($code, $url_id);
  2502. } else {
  2503. UrlManager::add_course_to_url($code, 1);
  2504. }
  2505. // Add event to the system log.
  2506. $user_id = api_get_user_id();
  2507. event_system(LOG_COURSE_CREATE, LOG_COURSE_CODE, $code, api_get_utc_datetime(), $user_id, $code);
  2508. $send_mail_to_admin = api_get_setting('send_email_to_admin_when_create_course');
  2509. // @todo Improve code to send to all current portal administrators.
  2510. if ($send_mail_to_admin == 'true') {
  2511. $siteName = api_get_setting('siteName');
  2512. $recipient_email = api_get_setting('emailAdministrator');
  2513. $recipient_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'));
  2514. $iname = api_get_setting('Institution');
  2515. $subject = get_lang('NewCourseCreatedIn').' '.$siteName.' - '.$iname;
  2516. $message = get_lang('Dear').' '.$recipient_name.",\n\n".get_lang('MessageOfNewCourseToAdmin').' '.$siteName.' - '.$iname."\n";
  2517. $message .= get_lang('CourseName').' '.$title."\n";
  2518. $message .= get_lang('Category').' '.$category_code."\n";
  2519. $message .= get_lang('Tutor').' '.$tutor_name."\n";
  2520. $message .= get_lang('Language').' '.$course_language;
  2521. $userInfo = api_get_user_info($user_id);
  2522. $plugin = new AppPlugin();
  2523. $additionalParameters = array(
  2524. 'smsType' => constant($plugin->getSMSPluginName().'::NEW_COURSE_BEEN_CREATED'),
  2525. 'userId' => $user_id,
  2526. 'courseName' => $title,
  2527. 'creatorUsername' => $userInfo['username']
  2528. );
  2529. api_mail_html(
  2530. $recipient_name,
  2531. $recipient_email,
  2532. $subject,
  2533. $message,
  2534. $siteName,
  2535. $recipient_email,
  2536. null,
  2537. null,
  2538. null,
  2539. $additionalParameters
  2540. );
  2541. }
  2542. }
  2543. }
  2544. return $course_id;
  2545. }
  2546. /**
  2547. * Extract properties of the files from a ZIP package, write them to disk and
  2548. * return them as an array.
  2549. * @todo this function seems not to be used
  2550. * @param string Absolute path to the ZIP file
  2551. * @param bool Whether the ZIP file is compressed (not implemented). Defaults to TRUE.
  2552. * @return array List of files properties from the ZIP package
  2553. * @assert (null) === false
  2554. */
  2555. function readPropertiesInArchive($archive, $is_compressed = true) {
  2556. include api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
  2557. debug::printVar(dirname($archive), 'Zip : ');
  2558. $uid = api_get_user_id();
  2559. /*
  2560. string tempnam (string dir, string prefix)
  2561. tempnam() creates a unique temporary file in the dir directory. If the
  2562. directory doesn't existm tempnam() will generate a filename in the system's
  2563. temporary directory.
  2564. Before PHP 4.0.6, the behaviour of tempnam() depended of the underlying OS.
  2565. Under Windows, the "TMP" environment variable replaces the dir parameter;
  2566. under Linux, the "TMPDIR" environment variable has priority, while for the
  2567. OSes based on system V R4, the dir parameter will always be used if the
  2568. directory which it represents exists. Consult your documentation for more
  2569. details.
  2570. tempnam() returns the temporary filename, or the string NULL upon failure.
  2571. */
  2572. $zip_file = new PclZip($archive);
  2573. $tmp_dir_name = dirname($archive) . '/tmp'.$uid.uniqid($uid);
  2574. if (mkdir($tmp_dir_name, api_get_permissions_for_new_directories(), true)) {
  2575. $unzipping_state = $zip_file->extract($tmp_dir_name);
  2576. } else {
  2577. die ('mkdir failed');
  2578. }
  2579. $path_to_archive_ini = dirname($tmp_dir_name) . '/archive.ini';
  2580. //echo $path_to_archive_ini;
  2581. $course_properties = parse_ini_file($path_to_archive_ini);
  2582. rmdir($tmp_dir_name);
  2583. return $course_properties;
  2584. }