add_course.lib.inc.php 129 KB

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