add_course.lib.inc.php 121 KB

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