dokeos-library
[ class tree: dokeos-library ] [ index: dokeos-library ] [ all elements ]

Source for file add_course.lib.inc.php

Documentation is available at add_course.lib.inc.php

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

Documentation generated on Thu, 12 Jun 2008 12:54:03 -0500 by phpDocumentor 1.4.1