add_course.lib.inc.php 77 KB

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