add_course.lib.inc.php 98 KB

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