add_course.lib.inc.php 126 KB

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