dokeos   dokeos

dokeos > community > forum
Dokeos Forum Forum Index Dokeos Forum

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fatal Error on course.lib.php when adding a user to a course

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Dokeos Forum Forum Index -> Bugs Dokeos 1.6.x
View previous topic :: View next topic  
Author Message
llbra



Joined: 23 Mar 2006
Posts: 3

PostPosted: Thu Mar 23, 2006 1:56 pm    Post subject: Fatal Error on course.lib.php when adding a user to a course Reply with quote

Edited: I'm using Dokeos 1.6.3.


Original Topic:
I'm getting some strange errors when subscribing users to a course.

The first error was this:

Fatal error: Undefined class name 'rolesrights' in /.../dokeos/claroline/inc/lib/course.lib.php on line 261


So, I went to that file to search what was wrong. I found that line:

$location_id = RolesRights::get_course_location_id($course_code);

But, if found that RolesRights class doesn't exists on dokeos. Anywhere.

So, I just commented the line because I wanted to see what table was the function adding this location_id, since I found no table with that.

But that table MAIN_USER_ROLE_TABLE also doesn't exists.

So, I went deeper, and I found commenting this line and the SQL command to that phantom table, that there is also a api_max_sort_value(), that doesn't exists also.


I was wondering at that time what could be so wrong, untill I found a function equal as this (subscribe_user), called add_user_to_course and that function should do everything right, since there is no user role table.

What I think is that I found a deprecated or beta function that is being used by dokeos, a big mistake that wasn't letting the teachers to add students to the course.



I found no errors like this on the internet and on Dokeos Bug track Forum.
Correct me if I'm mistaken.


Thanks in advance.
Back to top
View user's profile Send private message
TL



Joined: 23 Oct 2005
Posts: 139
Location: SG St-Pieter Beringen-Lummen

PostPosted: Thu Mar 23, 2006 2:04 pm    Post subject: Fatal error fixed? Reply with quote

I think is error is already reported and fixed in topic: http://www.dokeos.com/forum/viewtopic.php?t=6515
Back to top
View user's profile Send private message Send e-mail Visit poster's website
llbra



Joined: 23 Mar 2006
Posts: 3

PostPosted: Thu Mar 23, 2006 2:17 pm    Post subject: Re: Fatal error fixed? Reply with quote

TL wrote:
I think is error is already reported and fixed in topic: http://www.dokeos.com/forum/viewtopic.php?t=6515



I fixed the error just right now.

In the topic you send me there is still and error on this line, that uses a non-existing function:

$max_sort = api_max_sort_value('0', $user_id);


To make it work, replace it by:

$max_sort = max_sort_value('0', $user_id);





Here is how I did (it's working for me):


    function subscribe_user($user_id, $course_code, $status = STUDENT)
    {
        $user_table = Database :: get_main_table(MAIN_USER_TABLE);
        $course_table = Database :: get_main_table(MAIN_COURSE_TABLE);
        $course_user_table = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
//        $location_table = Database :: get_main_table(MAIN_LOCATION_TABLE);
//        $user_role_table = Database :: get_main_table(MAIN_USER_ROLE_TABLE);
 
        $status = ($status == STUDENT || $status == COURSEMANAGER) ? $status : STUDENT;
//        $role_id = ($status == COURSEMANAGER) ? COURSE_ADMIN : NORMAL_COURSE_MEMBER;
//        $location_id = RolesRights::get_course_location_id($course_code);
 
        if (empty ($user_id) || empty ($course_code))
        {
            return false;
        }
        else
        {
            // previously check if the user are already registered on the platform
 
            $handle = api_sql_query("SELECT status FROM ".$user_table."
                                                        WHERE `user_id` = '$user_id' ");
            if (mysql_num_rows($handle) == 0)
            {
                return false; // the user isn't registered to the platform
            }
            else
            {
                //check if user isn't already subscribed to the course
                $handle = api_sql_query("SELECT * FROM ".$course_user_table."
                                                                    WHERE `user_id` = '$user_id'
                                                                    AND `course_code` ='$course_code'");
                if (mysql_num_rows($handle) > 0)
                {
                    return false; // the user is already subscribed to the course
                }
                else
                {
                    $max_sort = max_sort_value('0', $user_id);
                    $add_course_user_entry_sql = "INSERT INTO ".$course_user_table."
                                        SET `course_code` = '$course_code',
                                        `user_id`    = '$user_id',
                                            `status`    = '".$status."',
                                            `sort`  =   '".($max_sort+1)."'";
                    $result = api_sql_query($add_course_user_entry_sql);
//                    $set_role_sql = "INSERT INTO $user_role_table SET user_id='$user_id', role_id='$role_id', location_id='$location_id'";
//                    $role_result = api_sql_query($set_role_sql, __FILE__, __LINE__);
                    if ($result /*&& $role_result*/)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
        }
    }


Back to top
View user's profile Send private message
TL



Joined: 23 Oct 2005
Posts: 139
Location: SG St-Pieter Beringen-Lummen

PostPosted: Thu Mar 23, 2006 2:28 pm    Post subject: Re: Fatal error fixed? Reply with quote

llbra wrote:
I fixed the error just right now.

In the topic you send me there is still and error on this line, that uses a non-existing function:

$max_sort = api_max_sort_value('0', $user_id);


To make it work, replace it by:

$max_sort = max_sort_value('0', $user_id);

This also was reported in that topic.

Back to top
View user's profile Send private message Send e-mail Visit poster's website
llbra



Joined: 23 Mar 2006
Posts: 3

PostPosted: Thu Mar 23, 2006 2:30 pm    Post subject: Re: Fatal error fixed? Reply with quote

TL wrote:

llbra wrote:
I fixed the error just right now.

In the topic you send me there is still and error on this line, that uses a non-existing function:

$max_sort = api_max_sort_value('0', $user_id);


To make it work, replace it by:

$max_sort = max_sort_value('0', $user_id);

This also was reported in that topic.





Sorry, I didn't see it.

But the complete code is here.

I think is nice to put the full correct code in the original topic or don't close this topic.  
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Dokeos Forum Forum Index -> Bugs Dokeos 1.6.x All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP