add_course.lib.inc.php 126 KB

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