add_course.lib.inc.php 126 KB

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