add_course.lib.inc.php 104 KB

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