~ubuntu-branches/ubuntu/breezy/moodle/breezy

« back to all changes in this revision

Viewing changes to enrol/enrol.class.php

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-10-13 02:00:59 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051013020059-y2qcyo41t7nqppcg
Tags: 1.5.2-1ubuntu1
* Resync with debian (security update)
* changed dependencys to php5
* changed apache dependency to apache2 
* References
  CAN-2005-2247

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php   /// $Id: enrol.class.php,v 1.8.2.3 2004/11/20 19:08:20 defacer Exp $
 
1
<?php   /// $Id: enrol.class.php,v 1.20 2005/05/13 05:10:17 martinlanghoff Exp $
2
2
///////////////////////////////////////////////////////////////////////////
3
3
//                                                                       //
4
4
// NOTICE OF COPYRIGHT                                                   //
129
129
        if (isguest()) {
130
130
            add_to_log($course->id, "course", "guest", "view.php?id=$course->id", "$USER->id");
131
131
 
132
 
        } else if (empty($_GET['confirm'])) {
 
132
        } else if (empty($_GET['confirm']) && empty($_GET['cancel'])) {
133
133
 
134
134
            print_header($strloginto, $course->fullname, "<a href=\".\">$strcourses</a> -> $strloginto");
135
135
            echo "<br />";
136
 
            notice_yesno(get_string("enrolmentconfirmation"), "enrol.php?id=$course->id&confirm=1", $CFG->wwwroot);
 
136
            notice_yesno(get_string("enrolmentconfirmation"), "enrol.php?id=$course->id&amp;confirm=1", "enrol.php?id=$course->id&amp;cancel=1");
137
137
            print_footer();
138
138
            exit;
139
139
 
140
 
        } else {
 
140
        } elseif (!empty($_GET['confirm'])) {
141
141
            if ($course->enrolperiod) {
142
142
                $timestart = time();
143
143
                $timeend = time() + $course->enrolperiod;
170
170
            }
171
171
 
172
172
            redirect($destination);
 
173
        } elseif (!empty($_GET['cancel'])) {
 
174
            unset($SESSION->wantsurl);
 
175
            redirect($CFG->wwwroot);
173
176
        }
174
177
    }
175
178
 
179
182
    }
180
183
 
181
184
 
182
 
    print_header($strloginto, $course->fullname, "<A HREF=\".\">$strcourses</A> -> $strloginto", "form.password");
 
185
    print_header($strloginto, $course->fullname, "<a href=\".\">$strcourses</a> -> $strloginto", "form.password");
183
186
 
184
 
    print_course($course);
 
187
    print_course($course, "80%");
185
188
 
186
189
    include("$CFG->dirroot/enrol/internal/enrol.html");
187
190
 
203
206
function check_entry($form, $course) {
204
207
    global $CFG, $USER, $SESSION, $THEME;
205
208
 
206
 
    if ($form->password == $course->password) {
 
209
    if (empty($form->password)) {
 
210
        $form->password = '';
 
211
    }
 
212
 
 
213
    $groupid = $this->check_group_entry($course->id, $form->password);
 
214
    if (($form->password == $course->password) or ($groupid !== false) ) {
207
215
 
208
216
        if (isguest()) {
209
217
        
221
229
            if (! enrol_student($USER->id, $course->id, $timestart, $timeend)) {
222
230
                error("An error occurred while trying to enrol you.");
223
231
            }
224
 
            
 
232
 
 
233
            if ($groupid !== false) {
 
234
                if (add_user_to_group($groupid, $USER->id)) {
 
235
                    $USER->groupmember[$course->id] = $groupid;
 
236
                } else {
 
237
                    error("An error occurred while trying to add you to a group");
 
238
                }
 
239
            }
 
240
 
225
241
            $subject = get_string("welcometocourse", "", $course->fullname);
226
242
            $a->coursename = $course->fullname;
227
 
            $a->profileurl = "$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id";
 
243
            $a->profileurl = "$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$course->id";
228
244
            $message = get_string("welcometocoursetext", "", $a);
229
245
            
230
246
            if (! $teacher = get_teacher($course->id)) {
254
270
 
255
271
 
256
272
/**
 
273
* Check if the given enrolment key matches a group enrolment key for the given course
 
274
*
 
275
* Check if the given enrolment key matches a group enrolment key for the given course
 
276
*
 
277
* @param    courseid  the current course id
 
278
* @param    password  the submitted enrolment key
 
279
*/
 
280
function check_group_entry ($courseid, $password) {
 
281
    $ingroup = false;
 
282
    if ( ($groups = get_groups($courseid)) !== false ) {
 
283
        foreach ($groups as $group) 
 
284
            if ( !empty($group->password) and ($password == $group->password) )
 
285
                $ingroup = $group->id;
 
286
    }
 
287
    return $ingroup;
 
288
}
 
289
 
 
290
 
 
291
/**
257
292
* Prints a form for configuring the current enrolment plugin
258
293
*
259
294
* This function is called from admin/enrol.php, and outputs a 
302
337
    
303
338
    if ($students = get_records_select('user_students', $select)) {
304
339
        foreach ($students as $student) {
 
340
            if ($course = get_record('course', 'id', $student->course)) {
 
341
                if (empty($course->enrolperiod)) {   // This overrides student timeend
 
342
                    continue;
 
343
                }
 
344
            }
305
345
            unenrol_student($student->userid, $student->course);
306
346
        }
307
347
    }
327
367
 
328
368
    if (!empty($course->guest)) {
329
369
        $strallowguests = get_string("allowguests");
330
 
        $str .= "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
331
 
        $str .= "<img vspace=4 alt=\"$strallowguests\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/guest.gif\"></a>&nbsp;&nbsp;";
 
370
        $str .= '<a title="'.$strallowguests.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">';
 
371
        $str .= '<img vspace="4" alt="'.$strallowguests.'" height="16" width="16" border="0" '.
 
372
                'src="'.$CFG->pixpath.'/i/guest.gif" /></a>&nbsp;&nbsp;';
332
373
    }
333
374
    if (!empty($course->password)) {
334
375
        $strrequireskey = get_string("requireskey");
335
 
        $str .= "<a title=\"$strrequireskey\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
336
 
        $str .= "<img vspace=4 alt=\"$strrequireskey\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/key.gif\"></a>";
 
376
        $str .= '<a title="'.$strrequireskey.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">';
 
377
        $str .= '<img vspace="4" alt="'.$strrequireskey.'" height="16" width="16" border="0" src="'.$CFG->pixpath.'/i/key.gif" /></a>';
337
378
    }
338
379
 
339
380
    return $str;