add_course.lib.inc.php 102 KB

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