add_course.lib.inc.php 86 KB

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