/**
  * Create the dummy course
  */
 function create_dummy_course($course_code)
 {
     $this->default_property['insert_user_id'] = '1';
     $this->default_property['insert_date'] = date('Y-m-d H:i:s');
     $this->default_property['lastedit_date'] = date('Y-m-d H:i:s');
     $this->default_property['lastedit_user_id'] = '1';
     $this->default_property['to_group_id'] = '0';
     $this->default_property['to_user_id'] = null;
     $this->default_property['visibility'] = '1';
     $this->default_property['start_visible'] = '0000-00-00 00:00:00';
     $this->default_property['end_visible'] = '0000-00-00 00:00:00';
     $course = Database::get_course_info($course_code);
     $this->course = new Course();
     $tmp_path = api_get_path(SYS_COURSE_PATH) . $course['directory'] . '/document/tmp_' . uniqid('');
     @mkdir($tmp_path, api_get_permissions_for_new_directories(), true);
     $this->course->backup_path = $tmp_path;
     $this->create_dummy_links();
     $this->create_dummy_events();
     $this->create_dummy_forums();
     $this->create_dummy_announcements();
     $this->create_dummy_documents();
     $this->create_dummy_learnpaths();
     $cr = new CourseRestorer($this->course);
     $cr->set_file_option(FILE_OVERWRITE);
     $cr->restore($course_code);
     rmdirr($tmp_path);
 }
 /**
  * 
  * Returns the URL of a document
  * This funcion is loaded when using a gradebook as a tab (gradebook = -1) see issue #2705
  */
 public function get_view_url($stud_id)
 {
     // find a file uploaded by the given student,
     // with the same title as the evaluation name
     $eval = $this->get_evaluation();
     $sql = 'SELECT filename FROM ' . $this->get_dropbox_table() . ' WHERE c_id = ' . $this->course_id . ' AND uploader_id = ' . intval($stud_id) . " AND title = '" . Database::escape_string($eval->get_name()) . "'";
     $result = Database::query($sql);
     if ($fileurl = Database::fetch_row($result)) {
         $course_info = Database::get_course_info($this->get_course_code());
         return null;
     } else {
         return null;
     }
 }
Example #3
0
 /**
  *    Get a combined list of all users of the real course $course_code
  *        and all users in virtual courses linked to this course $course_code
  *    Filter user list: remove duplicate users; plus
  *        remove users that
  *        - are already in the current group $group_id;
  *        - do not have student status in these courses;
  *        - are not appointed as tutor (group assistent) for this group;
  *        - have already reached their maximum # of groups in this course.
  *
  *    Originally to get the correct list of users a big SQL statement was used,
  *    but this has become more complicated now there is not just one real course but many virtual courses.
  *    Still, that could have worked as well.
  *
  *    @version 1.1.3
  *    @author Roan Embrechts
  */
 public static function get_complete_list_of_users_that_can_be_added_to_group($course_code, $group_id)
 {
     global $_course, $_user;
     $category = self::get_category_from_group($group_id, $course_code);
     $number_of_groups_limit = $category['groups_per_user'] == self::GROUP_PER_MEMBER_NO_LIMIT ? self::INFINITE : $category['groups_per_user'];
     $real_course_code = $_course['sysCode'];
     $real_course_info = Database::get_course_info($real_course_code);
     $real_course_user_list = CourseManager::get_user_list_from_course_code($real_course_code);
     //get list of all virtual courses
     $user_subscribed_course_list = CourseManager::get_list_of_virtual_courses_for_specific_user_and_real_course($_user['user_id'], $real_course_code);
     //add real course to the list
     $user_subscribed_course_list[] = $real_course_info;
     if (!is_array($user_subscribed_course_list)) {
         return;
     }
     //for all courses...
     foreach ($user_subscribed_course_list as $this_course) {
         $this_course_code = $this_course['code'];
         $course_user_list = CourseManager::get_user_list_from_course_code($this_course_code);
         //for all users in the course
         foreach ($course_user_list as $this_user) {
             $user_id = $this_user['user_id'];
             $loginname = $this_user['username'];
             $lastname = $this_user['lastname'];
             $firstname = $this_user['firstname'];
             $status = $this_user['status'];
             //$role =  $this_user['role'];
             $tutor_id = $this_user['tutor_id'];
             $full_name = api_get_person_name($firstname, $lastname);
             if ($lastname == "" || $firstname == '') {
                 $full_name = $loginname;
             }
             $complete_user['user_id'] = $user_id;
             $complete_user['full_name'] = $full_name;
             $complete_user['firstname'] = $firstname;
             $complete_user['lastname'] = $lastname;
             $complete_user['status'] = $status;
             $complete_user['tutor_id'] = $tutor_id;
             $student_number_of_groups = self::user_in_number_of_groups($user_id, $category['id']);
             //filter: only add users that have not exceeded their maximum amount of groups
             if ($student_number_of_groups < $number_of_groups_limit) {
                 $complete_user_list[] = $complete_user;
             }
         }
     }
     if (is_array($complete_user_list)) {
         //sort once, on array field "full_name"
         $complete_user_list = TableSort::sort_table($complete_user_list, "full_name");
         //filter out duplicates, based on field "user_id"
         $complete_user_list = self::filter_duplicates($complete_user_list, "user_id");
         $complete_user_list = self::filter_users_already_in_group($complete_user_list, $group_id);
     }
     return $complete_user_list;
 }
Example #4
0
 /**
  * Exports the current AICC object's files as a zip. Excerpts taken from learnpath_functions.inc.php::exportpath()
  * @param	integer	Learnpath ID (optional, taken from object context if not defined)
  */
 function export_zip($lp_id = null)
 {
     if ($this->debug > 0) {
         error_log('In aicc::export_zip method(' . $lp_id . ')', 0);
     }
     if (empty($lp_id)) {
         if (!is_object($this)) {
             return false;
         } else {
             $id = $this->get_id();
             if (empty($id)) {
                 return false;
             } else {
                 $lp_id = $this->get_id();
             }
         }
     }
     //error_log('New LP - in export_zip()',0);
     //zip everything that is in the corresponding scorm dir
     //write the zip file somewhere (might be too big to return)
     require_once api_get_path(LIBRARY_PATH) . "fileUpload.lib.php";
     require_once api_get_path(LIBRARY_PATH) . "fileManage.lib.php";
     require_once api_get_path(LIBRARY_PATH) . "document.lib.php";
     require_once api_get_path(LIBRARY_PATH) . "pclzip/pclzip.lib.php";
     require_once "learnpath_functions.inc.php";
     $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
     $_course = Database::get_course_info(api_get_course_id());
     $sql = "SELECT * FROM {$tbl_lp} WHERE id=" . $lp_id;
     $result = Database::query($sql, __FILE__, __LINE__);
     $row = Database::fetch_array($result);
     $LPname = $row['path'];
     $list = split('/', $LPname);
     $LPnamesafe = $list[0];
     //$zipfoldername = '/tmp';
     //$zipfoldername = '../../courses/'.$_course['directory']."/temp/".$LPnamesafe;
     $zipfoldername = api_get_path('SYS_COURSE_PATH') . $_course['directory'] . "/temp/" . $LPnamesafe;
     $scormfoldername = api_get_path('SYS_COURSE_PATH') . $_course['directory'] . "/scorm/" . $LPnamesafe;
     $zipfilename = $zipfoldername . "/" . $LPnamesafe . ".zip";
     //Get a temporary dir for creating the zip file
     //error_log('New LP - cleaning dir '.$zipfoldername,0);
     deldir($zipfoldername);
     //make sure the temp dir is cleared
     $res = mkdir($zipfoldername);
     //error_log('New LP - made dir '.$zipfoldername,0);
     //create zipfile of given directory
     $zip_folder = new PclZip($zipfilename);
     $zip_folder->create($scormfoldername . '/', PCLZIP_OPT_REMOVE_PATH, $scormfoldername . '/');
     //$zipfilename = '/var/www/dokeos-comp/courses/TEST2/scorm/example_document.html';
     //this file sending implies removing the default mime-type from php.ini
     //DocumentManager :: file_send_for_download($zipfilename, true, $LPnamesafe.".zip");
     DocumentManager::file_send_for_download($zipfilename, true);
     // Delete the temporary zip file and directory in fileManage.lib.php
     my_delete($zipfilename);
     my_delete($zipfoldername);
     return true;
 }
Example #5
0
    /**
     * Exports the current SCORM object's files as a zip. Excerpts taken from learnpath_functions.inc.php::exportpath()
     * @param	integer	Learnpath ID (optional, taken from object context if not defined)
     */
    public function export_zip($lp_id = null)
    {
        if ($this->debug > 0) { error_log('In scorm::export_zip method('.$lp_id.')', 0); }
        if (empty($lp_id)) {
            if (!is_object($this)) {
                return false;
            } else {
                $id = $this->get_id();
                if (empty($id)) {
                    return false;
                } else {
                    $lp_id = $this->get_id();
                }
            }
        }
        //error_log('New LP - in export_zip()',0);
        //zip everything that is in the corresponding scorm dir
        //write the zip file somewhere (might be too big to return)
        require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
        require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
        require_once api_get_path(LIBRARY_PATH).'document.lib.php';

        require_once 'learnpath_functions.inc.php';
        $course_id = api_get_course_int_id();
        $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
        $_course = Database::get_course_info(api_get_course_id());

        $sql = "SELECT * FROM $tbl_lp WHERE c_id = ".$course_id." AND id=".$lp_id;
        $result = Database::query($sql);
        $row = Database::fetch_array($result);
        $LPname = $row['path'];
        $list = explode('/', $LPname);
        $LPnamesafe = $list[0];
        //$zipfoldername = '/tmp';
        //$zipfoldername = '../../courses/'.$_course['directory'].'/temp/'.$LPnamesafe;
        $zipfoldername = api_get_path(SYS_COURSE_PATH).$_course['directory'].'/temp/'.$LPnamesafe;
        $scormfoldername = api_get_path(SYS_COURSE_PATH).$_course['directory'].'/scorm/'.$LPnamesafe;
        $zipfilename = $zipfoldername.'/'.$LPnamesafe.'.zip';

        // Get a temporary dir for creating the zip file.

        //error_log('New LP - cleaning dir '.$zipfoldername, 0);
        deldir($zipfoldername); // Make sure the temp dir is cleared.
        $res = mkdir($zipfoldername, api_get_permissions_for_new_directories());
        //error_log('New LP - made dir '.$zipfoldername, 0);

        // Create zipfile of given directory.
        $zip_folder = new PclZip($zipfilename);
        $zip_folder->create($scormfoldername.'/', PCLZIP_OPT_REMOVE_PATH, $scormfoldername.'/');

        //$zipfilename = '/var/www/chamilo/courses/TEST2/scorm/example_document.html';
        //This file sending implies removing the default mime-type from php.ini
        //DocumentManager :: file_send_for_download($zipfilename, true, $LPnamesafe.'.zip');
        DocumentManager :: file_send_for_download($zipfilename, true);

        // Delete the temporary zip file and directory in fileManage.lib.php
        my_delete($zipfilename);
        my_delete($zipfoldername);

        return true;
    }
function display_virtual_course_list()
{
    $course_list = CourseManager::get_virtual_course_list();
    if (!is_array($course_list)) {
        //there are no virtual courses
        echo "<i>" . get_lang('ThereAreNoVirtualCourses') . "</i>";
        return;
    }
    $column_header[] = array(get_lang('Title'), true);
    $column_header[] = array(get_lang('Code'), true);
    $column_header[] = array(get_lang('VisualCode'), true);
    $column_header[] = array(get_lang('LinkedCourseTitle'), true);
    $column_header[] = array(get_lang('LinkedCourseCode'), true);
    $table_data = array();
    for ($i = 0; $i < count($course_list); $i++) {
        $course_list[$i] = Database::generate_abstract_course_field_names($course_list[$i]);
        $target_course_code = $course_list[$i]["target_course_code"];
        $real_course_info = Database::get_course_info($target_course_code);
        $row = array();
        $row[] = $course_list[$i]["title"];
        $row[] = $course_list[$i]["system_code"];
        $row[] = $course_list[$i]["visual_code"];
        $row[] = $real_course_info["title"];
        $row[] = $real_course_info["system_code"];
        $table_data[] = $row;
    }
    Display::display_sortable_table($column_header, $table_data, array(), array(), array('action' => $_GET['action']));
}
Example #7
0
    /**
     * Helper functions definition
     */
    public static function get_logged_user_course_html($my_course, $count)
    {
        global $nosession, $nbDigestEntries, $orderKey, $digest, $thisCourseSysCode;
        if (!$nosession) {
            global $now, $date_start, $date_end;
        }
        //initialise
        $result = '';
        // Table definitions
        $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
        $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);

        $course_code = $my_course['code'];
        $course_visual_code = $my_course['course_info']['official_code'];
        $course_title = $my_course['course_info']['title'];

        $course_info = Database :: get_course_info($course_code);

        $course_id = $course_info['real_id'];

        $course_access_settings = CourseManager :: get_access_settings($course_code);

        $course_visibility = $course_access_settings['visibility'];

        $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_code);
        //function logic - act on the data
        $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($course_code);
        if ($is_virtual_course) {
            // If the current user is also subscribed in the real course to which this
            // virtual course is linked, we don't need to display the virtual course entry in
            // the course list - it is combined with the real course entry.
            $target_course_code = CourseManager :: get_target_of_linked_course($course_code);
            $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
            if ($is_subscribed_in_target_course) {
                return; //do not display this course entry
            }
        }

        $s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course'));

        //display course entry
        $result .= '<div id="div_'.$count.'">';
        //$result .= '<h3><img src="../img/nolines_plus.gif" id="btn_'.$count.'" onclick="toogle_course(this,\''.$course_id.'\' )">';
        $result .= $s_htlm_status_icon;

        //show a hyperlink to the course, unless the course is closed and user is not course admin
        if ($course_visibility != COURSE_VISIBILITY_HIDDEN && ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)) {
           //$result .= '<a href="javascript:void(0)" id="ln_'.$count.'"  onclick=toogle_course(this,\''.$course_id.'\');>&nbsp;'.$course_title.'</a>';
           $result .= $course_title;
        } else {
            $result .= $course_title." "." ".get_lang('CourseClosed')."";
        }
        $result .= '</h3>';
        //$current_course_settings = CourseManager :: get_access_settings($my_course['k']);
        // display the what's new icons
        /*if ($nbDigestEntries > 0) {
            reset($digest);
            $result .= '<ul>';
            while (list ($key2) = each($digest[$thisCourseSysCode])) {
                $result .= '<li>';
                if ($orderKey[1] == 'keyTools') {
                    $result .= "<a href=\"$toolsList[$key2] [\"path\"] $thisCourseSysCode \">";
                    $result .= "$toolsList[$key2][\"name\"]</a>";
                } else {
                    $result .= api_convert_and_format_date($key2, DATE_FORMAT_LONG, date_default_timezone_get());
                }
                $result .= '</li>';
                $result .= '<ul>';
                reset($digest[$thisCourseSysCode][$key2]);
                while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) {
                    $result .= '<li>';
                    if ($orderKey[2] == 'keyTools') {
                        $result .= "<a href=\"$toolsList[$key3] [\"path\"] $thisCourseSysCode \">";
                        $result .= "$toolsList[$key3][\"name\"]</a>";
                    } else {
                        $result .= api_convert_and_format_date($key3, DATE_FORMAT_LONG, date_default_timezone_get());
                    }
                    $result .= '<ul compact="compact">';
                    reset($digest[$thisCourseSysCode][$key2][$key3]);
                    while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) {
                        $result .= '<li>';
                        $result .= htmlspecialchars(substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
                        $result .= '</li>';
                    }
                    $result .= '</ul>';
                    $result .= '</li>';
                }
                $result .= '</ul>';
                $result .= '</li>';
            }
            $result .= '</ul>';
        }*/
        $result .= '</li>';
        $result .= '</div>';

        if (!$nosession) {
            $session = '';
            $active = false;
            if (!empty($my_course['session_name'])) {

                // Request for the name of the general coach
                $sql = 'SELECT lastname, firstname
                        FROM '.$tbl_session.' ts  LEFT JOIN '.$main_user_table.' tu
                        ON ts.id_coach = tu.user_id
                        WHERE ts.id='.(int) $my_course['id_session'].' LIMIT 1';
                $rs = Database::query($sql);
                $sessioncoach = Database::store_result($rs);
                $sessioncoach = $sessioncoach[0];

                $session = array();
                $session['title'] = $my_course['session_name'];
                if ($my_course['date_start'] == '0000-00-00') {
                    $session['dates'] = get_lang('WithoutTimeLimits');
                    if (api_get_setting('show_session_coach') === 'true') {
                        $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
                    }
                    $active = true;
                } else {
                    $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
                    if (api_get_setting('show_session_coach') === 'true') {
                        $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
                    }
                    $active = ($date_start <= $now && $date_end >= $now) ? true : false;
                }
            }
            $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0;
            $output = array($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active' => $active);
        } else {
            $output = array($my_course['user_course_cat'], $result);
        }
        //$my_course['creation_date'];
        return $output;
    }
 if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
     $FileZip = create_zip();
     $to_group_id = 0;
     $sql_session = "SELECT id, name FROM {$tbl_session} ";
     $query_session = Database::query($sql_session);
     $ListSession = array();
     while ($rows_session = Database::fetch_assoc($query_session)) {
         $ListSession[$rows_session['id']] = $rows_session['name'];
     }
     $zip_folder = new PclZip($FileZip['TEMP_FILE_ZIP']);
     if (!isset($_POST['resource']) || count($_POST['resource']) == 0) {
         Display::display_error_message(get_lang('ErrorMsgSpecialExport'));
     } else {
         $Resource = $_POST['resource'];
         foreach ($Resource as $Code_course => $Sessions) {
             $_course = Database::get_course_info($Code_course);
             $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
             $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
             $course_id = $_course['real_id'];
             //Add item to the zip file course
             $sql = "SELECT path FROM {$tbl_document} AS docs, {$tbl_property} AS props\n                        WHERE props.tool='" . TOOL_DOCUMENT . "'\n\t\t\t\t\t\tAND docs.id=props.ref\n\t\t\t\t\t\tAND docs.path LIKE '" . $querypath . "/%'\n\t\t\t\t\t\tAND docs.filetype='file'\n\t\t\t\t\t\tAND docs.session_id = '0'\n\t\t\t\t\t\tAND props.visibility<>'2'\n\t\t\t\t\t\tAND props.to_group_id= {$to_group_id} AND docs.c_id = {$course_id} AND props.c_id = {$course_id}";
             $query = Database::query($sql);
             while ($rows_course_file = Database::fetch_assoc($query)) {
                 $zip_folder->add($FileZip['PATH_COURSE'] . $_course['directory'] . "/document" . $rows_course_file['path'], PCLZIP_OPT_ADD_PATH, $_course['directory'], PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'] . $_course['directory'] . "/document" . $FileZip['PATH_REMOVE']);
             }
             foreach ($Sessions as $IdSession => $value) {
                 $session_id = Security::remove_XSS($IdSession);
                 //Add tem to the zip file session course
                 $sql_session_doc = "SELECT path FROM {$tbl_document} AS docs, {$tbl_property} AS props\n\t\t\t\t\t\tWHERE props.tool='" . TOOL_DOCUMENT . "'\n\t\t\t\t\t\t\tAND docs.id=props.ref\n\t\t\t\t\t\t\tAND docs.path LIKE '" . $querypath . "/%'\n\t\t\t\t\t\t\tAND docs.filetype='file'\n\t\t\t\t\t\t\tAND docs.session_id = '{$session_id}'\n\t\t\t\t\t\t\tAND props.visibility<>'2'\n\t\t\t\t\t\t\tAND props.to_group_id= {$to_group_id} AND docs.c_id = {$course_id} AND props.c_id = {$course_id}";
                 $query_session_doc = Database::query($sql_session_doc);
                 while ($rows_course_session_file = Database::fetch_assoc($query_session_doc)) {
Example #9
0
 /**
  * This function creates a virtual course.
  * It assumes all parameters have been checked and are not empty.
  * It checks wether a course with the $wanted_course_code already exists.
  *
  * Users of this library should consider this function private,
  * please call attempt_create_virtual_course instead of this one.
  *
  * note: The virtual course 'owner' id (the first course admin) is set to the CURRENT user id.
  * @param  string  Course code
  * @param  string  Course title
  * @param  string  Wanted course code
  * @param  string  Course language
  * @param  string  Course category
  * @return true if the course creation succeeded, false otherwise
  * @todo research: expiration date of a course
  * @deprecated virtual course feature is not supported
  */
 public static function create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category)
 {
     global $firstExpirationDelay;
     $user_id = api_get_user_id();
     $real_course_info = Database::get_course_info($real_course_code);
     $real_course_code = $real_course_info['system_code'];
     //check: virtual course creation fails if another course has the same
     //code, real or fake.
     if (self::course_code_exists($wanted_course_code)) {
         Display::display_error_message($wanted_course_code . ' - ' . get_lang('CourseCodeAlreadyExists'));
         return false;
     }
     //add data to course table, course_rel_user
     $course_sys_code = $wanted_course_code;
     $course_screen_code = $wanted_course_code;
     $course_repository = $real_course_info['directory'];
     $course_db_name = $real_course_info['db_name'];
     $responsible_teacher = $real_course_info['tutor_name'];
     $faculty_shortname = $course_category;
     // $course_title = $course_title;
     // $course_language = $course_language;
     $teacher_id = $user_id;
     //HACK ----------------------------------------------------------------
     $expiration_date = time() + $firstExpirationDelay;
     //END HACK ------------------------------------------------------------
     register_course($course_sys_code, $course_screen_code, $course_repository, $course_db_name, $responsible_teacher, $faculty_shortname, $course_title, $course_language, $teacher_id, $expiration_date);
     //above was the normal course creation table update call,
     //now one more thing: fill in the target_course_code field
     Database::query("UPDATE " . Database::get_main_table(TABLE_MAIN_COURSE) . " SET target_course_code = '{$real_course_code}'\n                WHERE code = '" . Database::escape_string($course_sys_code) . "' LIMIT 1 ");
     return true;
 }
 private function get_exercise_data()
 {
     $tbl_name = $this->get_studpub_table();
     $course_info = Database::get_course_info($this->get_course_code());
     if ($tbl_name == '') {
         return false;
     } elseif (!isset($this->exercise_data)) {
         $sql = 'SELECT * FROM ' . $this->get_studpub_table() . " WHERE c_id ='" . $course_info['real_id'] . "' AND id = '" . intval($this->get_ref_id()) . "' ";
         $query = Database::query($sql);
         $this->exercise_data = Database::fetch_array($query);
     }
     return $this->exercise_data;
 }
/**
 * Gets the name of a resource (generally used in learnpath when no name is provided)
 *
 * @author Yannick Warnier <*****@*****.**>, Dokeos - rebranding
 * @param string 	Course code
 * @param string 	The tool type (using constants declared in main_api.lib.php)
 * @param integer 	The resource ID
 */
function rl_get_resource_name($course_code, $learnpath_id, $id_in_path)
{
    $_course = Database::get_course_info($course_code);
    $course_id = $_course['real_id'];
    $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
    $learnpath_id = intval($learnpath_id);
    $id_in_path = intval($id_in_path);

    $sql_item = "SELECT item_type, title, ref FROM $tbl_lp_item
                 WHERE c_id = $course_id AND lp_id = $learnpath_id AND id = $id_in_path";
    $res_item = Database::query($sql_item);

    if (Database::num_rows($res_item) < 1) {
        return '';
    }
    $row_item = Database::fetch_array($res_item);
    $type = strtolower($row_item['item_type']);
    $id = $row_item['ref'];
    $output = '';

    switch ($type) {
        case TOOL_CALENDAR_EVENT:
            $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
            $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
            $myrow = Database::fetch_array($result);
            $output = $myrow['title'];
            break;
        case TOOL_ANNOUNCEMENT:
            $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
            $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
            $myrow = Database::fetch_array($result);
            $output = $myrow['title'];
            break;
        case TOOL_LINK:
            // Doesn't take $target into account.
            $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
            $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
            $myrow = Database::fetch_array($result);
            $output = $myrow['title'];
            break;
        case TOOL_QUIZ:
            $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
            $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id=$id");
            $myrow = Database::fetch_array($result);
            $output = $myrow['title'];
            break;
        case TOOL_FORUM:
            $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
            $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
            $myrow = Database::fetch_array($result);
            $output = $myrow['forum_name'];
            break;
        case TOOL_THREAD:  //=topics
            $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
            // Grabbing the title of the post.
            $sql_title = "SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=".$id;
            $result_title = Database::query($sql_title);
            $myrow_title = Database::fetch_array($result_title);
            $output = $myrow_title['post_title'];
            break;
        case TOOL_POST:
            $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
            //$tbl_post_text = Database::get_course_table(FORUM_POST_TEXT_TABLE);
            $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND p.post_id = $id";
            $result = Database::query($sql);
            $post = Database::fetch_array($result);
            $output = $post['post_title'];
            break;
        case 'dokeos_chapter':
            $title = $row_item['title'];
            if (!empty($title)) {
                $output = $title;
            } else {
                $output = '-';
            }
            break;
        case TOOL_DOCUMENT:
            $title = $row_item['title'];
            if (!empty($title)) {
                $output = $title;
            } else {
                $output = '-';
            }
            break;
        case 'hotpotatoes':
            $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
            $result = Database::query("SELECT * FROM $tbl_doc WHERE c_id = $course_id AND id=$id");
            $myrow = Database::fetch_array($result);
            $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
            $last = count($pathname) - 1;  // Making a correct name for the link.
            $filename = $pathname[$last];  // Making a correct name for the link.
            $image = choose_image($filename);
            $ext = explode('.', $filename);
            $ext = strtolower($ext[sizeof($ext) - 1]);
            $myrow['path'] = rawurlencode($myrow['path']);
            $in_frames = in_array($ext, array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png'));
            $output = $filename;
            break;
        /*
        case 'externallink':
            $output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
            break;
        */
    }
    return stripslashes($output);
}