add_course.lib.inc.php 122 KB

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