File: request.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (116 lines) | stat: -rw-r--r-- 3,172 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php  // $Id: request.php,v 1.3.2.1 2006/05/17 16:37:14 tjhunt Exp $
 
    /// this allows a student to request a course be created for them.

    require_once('../config.php');
  
    require_login();

    if (isguest()) {
        error("No guests here!");
    }

    if (empty($CFG->enablecourserequests)) {
        error(get_string('courserequestdisabled'));
    }

    $strtitle = get_string('courserequest');

    print_header($strtitle,$strtitle,$strtitle);

    if (($form = data_submitted()) and confirm_sesskey()) {
        validate_form($form,$err) ;

        if (empty($err)) {
            $form->requester = $USER->id;

            if (insert_record('course_request',$form)) {
                notice(get_string('courserequestsuccess'));
            }
            else {
                notice(get_string('courserequestfailed'));
            }
            print_footer();
            exit;
        } else {
            $form = stripslashes_safe($form);
        }

        // !! no db access using data from $form beyond this point !!
    }

//    print_simple_box(get_string('courserequestintro'),'center');
    print_simple_box_start("center");
    print_string('courserequestintro'); 
    include("request.html");
    print_simple_box_end();

    print_footer($course);

    if ($usehtmleditor) {
        use_html_editor("summary");
        use_html_editor("reason");
    }

    exit;


function validate_form(&$form,&$err) {

    if (empty($form->shortname)) {
        $err['shortname'] = get_string('missingshortname');
    }
    
    if (empty($form->fullname)) {
        $err['fullname'] = get_string('missingfullname');
    }

    if (empty($form->summary)) {
        $err["summary"] = get_string("missingsummary");
    }

    if (empty($form->reason)) {
        $err["reason"] = get_string("missingreqreason");
    }
    
    $foundcourses = null;
    $foundreqcourses = null;

    if (!empty($form->shortname)) {
        $foundcourses = get_records("course", "shortname", $form->shortname);
        $foundreqcourses = get_records("course_request", "shortname", $form->shortname);
    }
    if (!empty($foundreqcourses)) {
        if (!empty($foundcourses)) {
            $foundcourses = array_merge($foundcourses,$foundreqcourses);
        } else {
            $foundcourses = $foundreqcourses;
        }
    }

    if (!empty($foundcourses)) {
        if (!empty($course->id)) {
            unset($foundcourses[$course->id]);
        }
        if (!empty($foundcourses)) {
            foreach ($foundcourses as $foundcourse) {
                if ($foundcourse->requester) {
                    $pending = 1;
                    $foundcoursenames[] = $foundcourse->fullname.' [*]';
                }
                else {
                    $foundcoursenames[] = $foundcourse->fullname;
                }
            }
            $foundcoursenamestring = addslashes(implode(',', $foundcoursenames));
            
            $err["shortname"] = get_string("shortnametaken", "", $foundcoursenamestring);
            if (!empty($pending)) {
                $err["shortname"] .= '<br />'.get_string('starpending');
            }
        }
    }
}


?>