index.php 5.27 KB
Newer Older
Alastair Pharo's avatar
Alastair Pharo committed
1
2
3
4
5
<?php
/**
 *
 * @package    mahara
 * @subpackage artefact-internal
6
 * @author     Catalyst IT Ltd
7
8
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
Alastair Pharo's avatar
Alastair Pharo committed
9
10
11
12
 *
 */

define('INTERNAL', 1);
13
14
15
16
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'blog');
define('SECTION_PAGE', 'new');

Alastair Pharo's avatar
Alastair Pharo committed
17
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
18
require_once('license.php');
Alastair Pharo's avatar
Alastair Pharo committed
19
safe_require('artefact', 'blog');
20
21
22
23
24

if ($groupid = param_alphanum('group', null)) {
    define('SUBSECTIONHEADING', get_string('newblog','artefact.blog'));
}

25
$institutionname = $groupid = null;
26
27
28
29
if ($institutionname = param_alphanum('institution', null)) {
    require_once(get_config('libroot') . 'institution.php');
    $section = 'institution';
    if ($institutionname == 'mahara') {
30
31
32
        if (!$USER->get('admin')) {
            throw new AccessDeniedException(get_string('youarenotasiteadmin', 'artefact.blog'));
        }
33
34
        $section = 'site';
    }
35
36
37
38
39
40
    else {
        if (!$USER->get('admin') && !$USER->is_institutional_admin($institutionname)) {
            throw new AccessDeniedException(get_string('youarenotanadminof', 'artefact.blog', $institutionname));
        }
    }
    define('TITLE', get_string('newblog' . $section, 'artefact.blog', institution_display_name($institutionname)) . ': ' . get_string('blogsettings','artefact.blog'));
41
42
    PluginArtefactBlog::set_blog_nav(true, $institutionname);
}
43
44
else if ($groupid = param_alphanum('group', null)) {
    require_once('group.php');
45
    $group = get_group_by_id($groupid);
46
47
48
49
50
51
52
53
54
55
56
57
    $USER->reset_grouproles();
    if (!isset($USER->grouproles[$group->id])) {
        throw new AccessDeniedException(get_string('youarenotamemberof', 'artefact.blog', $group->name));
    }
    if (!group_role_can_edit_views($groupid, $USER->grouproles[$group->id])) {
        throw new AccessDeniedException(get_string('youarenotaneditingmemberof', 'artefact.blog', $group->name));
    }
    define('TITLE', $group->name);
    PluginArtefactBlog::set_blog_nav(false, null, $groupid);
}
else {
    define('TITLE', get_string('newblog', 'artefact.blog') . ': ' . get_string('blogsettings','artefact.blog'));
58
    PluginArtefactBlog::set_blog_nav();
59
}
Alastair Pharo's avatar
Alastair Pharo committed
60

61
$form = array(
Alastair Pharo's avatar
Alastair Pharo committed
62
63
64
    'name' => 'newblog',
    'method' => 'post',
    'action' => '',
65
66
    'plugintype' => 'artefact',
    'pluginname' => 'blog',
Alastair Pharo's avatar
Alastair Pharo committed
67
68
69
70
71
72
73
    'elements' => array(
        'title' => array(
            'type'        => 'text',
            'title'       => get_string('blogtitle', 'artefact.blog'),
            'description' => get_string('blogtitledesc', 'artefact.blog'),
            'rules' => array(
                'required'    => true
74
            ),
Alastair Pharo's avatar
Alastair Pharo committed
75
76
        ),
        'description' => array(
Alastair Pharo's avatar
Alastair Pharo committed
77
            'type'        => 'wysiwyg',
Alastair Pharo's avatar
Alastair Pharo committed
78
            'rows'        => 10,
79
            'cols'        => 70,
Alastair Pharo's avatar
Alastair Pharo committed
80
81
82
            'title'       => get_string('blogdesc', 'artefact.blog'),
            'description' => get_string('blogdescdesc', 'artefact.blog'),
            'rules' => array(
83
                'maxlength'   => 65536,
Alastair Pharo's avatar
Alastair Pharo committed
84
                'required'    => false
85
            ),
Alastair Pharo's avatar
Alastair Pharo committed
86
        ),
87
88
89
        'tags'        => array(
            'type'        => 'tags',
            'title'       => get_string('tags'),
90
            'description' => get_string('tagsdescprofile'),
91
            'help'        => true,
92
            'institution' => $institutionname,
93
        ),
94
95
        'license' => license_form_el_basic(null),
        'licensing_advanced' => license_form_el_advanced(null),
Alastair Pharo's avatar
Alastair Pharo committed
96
        'submit' => array(
Alastair Pharo's avatar
Alastair Pharo committed
97
            'type'  => 'submitcancel',
98
            'class' => 'btn-primary',
Alastair Pharo's avatar
Alastair Pharo committed
99
100
101
102
            'value' => array(
                get_string('createblog', 'artefact.blog'),
                get_string('cancel', 'artefact.blog')
            )
Alastair Pharo's avatar
Alastair Pharo committed
103
104
        )
    )
105
106
);
$form['elements']['institution'] = array('type' => 'hidden', 'value' => ($institutionname) ? $institutionname : 0);
107
$form['elements']['group'] = array('type' => 'hidden', 'value' => ($groupid) ? $groupid : 0);
108
109

$form = pieform($form);
Alastair Pharo's avatar
Alastair Pharo committed
110

111
$smarty = smarty();
112
$smarty->assign('form', $form);
113
$smarty->display('form.tpl');
Alastair Pharo's avatar
Alastair Pharo committed
114
115
116
117
118
119
120
exit;

/**
 * This function gets called to submit the new blog.
 *
 * @param array
 */
121
function newblog_submit(Pieform $form, $values) {
Alastair Pharo's avatar
Alastair Pharo committed
122
123
    global $USER;

124
    $data = $form->get_element('institution');
125
    $group = $form->get_element('group');
126
127
128
129
    if ($data['value'] != false) {
        ArtefactTypeBlog::new_blog(null, $values);
        redirect('/artefact/blog/index.php?institution=' . $data['value']);
    }
130
131
132
133
    else if ($group['value'] != false) {
        ArtefactTypeBlog::new_blog(null, $values);
        redirect('/artefact/blog/index.php?group=' . $group['value']);
    }
134
135
136
137
    else {
        ArtefactTypeBlog::new_blog($USER, $values);
        redirect('/artefact/blog/index.php');
    }
Alastair Pharo's avatar
Alastair Pharo committed
138
139
140
141
142
}

/**
 * This function gets called to cancel a submission.
 */
143
144
function newblog_cancel_submit(Pieform $form) {
    $data = $form->get_element('institution');
145
    $group = $form->get_element('group');
146
147
148
    if ($data['value'] != false) {
        redirect('/artefact/blog/index.php?institution=' . $data['value']);
    }
149
150
151
    if ($group['value'] != false) {
        redirect('/artefact/blog/index.php?group=' . $group['value']);
    }
152
153
154
    else {
        redirect('/artefact/blog/index.php');
    }
Alastair Pharo's avatar
Alastair Pharo committed
155
}