add_course.lib.inc.php 99 KB

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