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

Dokeos 1.6.x is no longer the latest version. Please use Dokeos 1.8

Moderator: jprudhomme

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

Postby llbra » Thu Mar 23, 2006 1:56 pm

<em>Edited:</em> I'm using Dokeos 1.6.3.


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

The first error was this:

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


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

<em>$location_id = RolesRights::get_course_location_id($course_code);

</em>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 <em>MAIN_USER_ROLE_TABLE</em> 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.


<strong>I was wondering at that time what could be so wrong, untill I found a function equal as this (subscribe_user), called <em>add_user_to_course </em>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.</strong>


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


Thanks in advance.
llbra
 
Posts: 3
Joined: Thu Mar 23, 2006 1:43 pm

Re: Fatal error fixed?

Postby llbra » Thu Mar 23, 2006 2:17 pm

TL wrote:I think is error is already reported and fixed in topic: 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:

<em><span class="postbody"><font face="Courier New">$max_sort = api_max_sort_value('0', $user_id);</font></span></em>


To make it work, replace it by:

<em>$max_sort = max_sort_value('0', $user_id);</em>





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


<font face="Verdana">    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;
                    }
                }
            }
        }
    }

</font><span class="postbody"></span><font face="Courier New">
</font>
llbra
 
Posts: 3
Joined: Thu Mar 23, 2006 1:43 pm

Re: Fatal error fixed?

Postby llbra » Thu Mar 23, 2006 2:30 pm

TL wrote:<p>
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:

<em><span class="postbody"><font face="Courier New">$max_sort = api_max_sort_value('0', $user_id);</font></span></em>


To make it work, replace it by:

<em>$max_sort = max_sort_value('0', $user_id);</em>

</p><p>This also was reported in that topic. </p>




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.  
llbra
 
Posts: 3
Joined: Thu Mar 23, 2006 1:43 pm


Return to Bugs Dokeos 1.6.x

Who is online

Users browsing this forum: No registered users and 0 guests