register.php 3.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
/**
 * @file Register a mahara site
 */
/**
 * @defgroup Registration Registration
 * Send site information to mahara.org
 * 
 */
 
defined('INTERNAL') || die();
require_once('pieforms/pieform.php');

/**
 * @return string that is the registation form
 * @ingroup Registration 
 */
function register_site()  {
Nigel McNie's avatar
Nigel McNie committed
19
20
    $strfield = get_string('Field', 'admin');
    $strvalue = get_string('Value', 'admin');
21
22
23
    $info = <<<EOF
<table>
    <tr>
Nigel McNie's avatar
Nigel McNie committed
24
25
        <th>$strfield</th>
        <th>$strvalue</th>
26
27
28
29
30
31
32
    </tr>
EOF;
    $data = registration_data();
    foreach($data as $key => $val) {
        $info .= '<tr><td>'. hsc($key) . '</td><td>' . hsc($val) . "</td></tr>\n";
    }
    $info .= '</table>';
33

34
35
36
37
38
39
    $form = array(
        'name' => 'register',
        'autofocus' => false,
        'elements' => array(
            'whatsent' => array(
                'type' => 'fieldset',
Nigel McNie's avatar
Nigel McNie committed
40
                'legend' => get_string('datathatwillbesent', 'admin'),
41
42
43
44
45
                'collapsible' => true,
                'collapsed' => true,
                'elements' => array(
                    'info' => array(
                        'type' => 'markup',
Nigel McNie's avatar
Nigel McNie committed
46
                        'value'=> $info,
47
48
49
50
51
                    ),
                )
            ),
            'sendweeklyupdates' => array(
                'type' => 'checkbox',
Nigel McNie's avatar
Nigel McNie committed
52
53
                'title' => get_string('sendweeklyupdates', 'admin'),
                'defaultvalue' => true,
54
55
56
            ),
            'register' => array(
                'type' => 'submit',
Nigel McNie's avatar
Nigel McNie committed
57
                'value' => get_string('Register', 'admin'),
58
59
60
            ),
        )
     );
61
62
63
64
65
66
     
     return pieform($form);
}
/**
 * Runs when registration form is submitted
 */
67
68
69
70
71
72
73
74
75
76
77
function register_submit(Pieform $form, $values) {
    global $SESSION;
    $registrationurl = 'http://mahara.org/mahara-registration.php';

    $data = registration_data();
    $request = array(
        CURLOPT_URL        => $registrationurl,
        CURLOPT_POST       => 1,
        CURLOPT_POSTFIELDS => $data,
    );
    $result = http_request($request);
78

79
    if ($result->data != '1') {
Nigel McNie's avatar
Nigel McNie committed
80
81
        log_info($result);
        $SESSION->add_error_msg(get_string('registrationfailedtrylater', 'admin', $result->info['http_code']));
82
83
84
    }
    else {
        set_config('registration_lastsent', strtotime('now'));
85
        set_config('registration_sendweeklyupdates', $values['sendweeklyupdates']);
Nigel McNie's avatar
Nigel McNie committed
86
        $SESSION->add_ok_msg(get_string('registrationsuccessfulthanksforregistering'));
87
88
    }
    redirect('/admin/');
89
90
91
}


92
93
94
/**
 * Builds the data that will be sent by the "register your site" feature
 */
95
function registration_data() {
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    foreach (array(
        'wwwroot',
        'installation_key',
        'sitename',
        'dbtype',
        'lang',
        'theme',
        'enablenetworking',
        'allowpublicviews',
        'allowpublicprofiles',
        'version',
        'release') as $key) {
        $data_to_send[$key] = get_config($key);
    }

    foreach (array(
        'usr',
        'usr_friend',
        'usr_institution',
        'group',
        'group_member',
        'block_instance',
        'institution',
        'blocktype_wall_post',
        'host',
        'institution') as $key) {
        $data_to_send['count_' . $key] = count_records($key);
    }
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
    // Don't include the root user
    $data_to_send['count_usr']--;

    // Slightly more drilled down information
    if ($data = get_records_sql_array('SELECT artefacttype, COUNT(*) AS count
        FROM {artefact}
        GROUP BY artefacttype', array())) {
        foreach ($data as $artefacttypeinfo) {
            $data_to_send['artefact_type_' . $artefacttypeinfo->artefacttype] = $artefacttypeinfo->count;
        }
    }

    if ($data = get_records_sql_array('SELECT type, COUNT(*) AS count
        FROM {view}
        GROUP BY type', array())) {
        foreach ($data as $viewtypeinfo) {
            $data_to_send['view_type_' . $viewtypeinfo->type] = $viewtypeinfo->count;
        }
    }
144

145
    return $data_to_send;
146
}