index.php 3.78 KB
Newer Older
Alastair Pharo's avatar
Alastair Pharo committed
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
<?php
/**
 * This program is part of Mahara
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 *
 * @package    mahara
 * @subpackage artefact-blog
 * @author     Alastair Pharo <alastair@catalyst.net.nz>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

define('INTERNAL', 1);
define('MENUITEM', 'myblogs');

require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('pieforms/pieform.php');
safe_require('artefact', 'blog');

$id = param_integer('id');

$form = pieform(array(
    'name' => 'newpost',
    'method' => 'post',
    'action' => '',
    'elements' => array(
        'id' => array(
            'type' => 'hidden',
            'value' => $id,
            'rules' => array(
                'required' => true
            )
        ),
        'title' => array(
            'type' => 'text',
            'title' => get_string('posttitle', 'artefact.blog'),
            'description' => get_string('posttitledesc', 'artefact.blog'),
            'rules' => array(
                'required' => true
            )
        ),
        'description' => array(
Alastair Pharo's avatar
Alastair Pharo committed
57
            'type' => 'wysiwyg',
Alastair Pharo's avatar
Alastair Pharo committed
58
            'rows' => 10,
59
            'cols' => 70,
Alastair Pharo's avatar
Alastair Pharo committed
60
61
62
63
64
65
            'title' => get_string('postbody', 'artefact.blog'),
            'description' => get_string('postbodydesc', 'artefact.blog'),
            'rules' => array(
                'required' => true
            )
        ),
Alastair Pharo's avatar
Alastair Pharo committed
66
        'saveandpublish' => array(
Alastair Pharo's avatar
Alastair Pharo committed
67
            'type' => 'submit',
Alastair Pharo's avatar
Alastair Pharo committed
68
69
70
71
72
73
74
75
76
77
78
            'description' => get_string('createandpublishdesc', 'artefact.blog'),
            'value' => get_string('saveandpublish', 'artefact.blog')
        ),
        'saveasdraft' => array(
            'type' => 'submit',
            'description' => get_string('createasdraftdesc', 'artefact.blog'),
            'value' => get_string('saveasdraft', 'artefact.blog')
        ),
        'cancel' => array(
            'type' => 'cancel',
            'value' => get_string('cancel', 'artefact.blog')
Alastair Pharo's avatar
Alastair Pharo committed
79
80
81
82
        )
    )
));

Alastair Pharo's avatar
Alastair Pharo committed
83
$smarty = smarty();
Alastair Pharo's avatar
Alastair Pharo committed
84
85
86
87
88
$smarty->assign_by_ref('newpostform', $form);
$smarty->display('artefact:blog:newpost.tpl');
exit;

/**
Alastair Pharo's avatar
Alastair Pharo committed
89
90
 * This function gets called to create a new blog post, and publish it
 * simultaneously.
Alastair Pharo's avatar
Alastair Pharo committed
91
92
93
 *
 * @param array
 */
94
function newpost_submit_saveandpublish(Pieform $form, array $values) {
Alastair Pharo's avatar
Alastair Pharo committed
95
96
    global $USER;

Alastair Pharo's avatar
Alastair Pharo committed
97
98
99
100
101
102
103
104
105
106
    $values['published'] = true;
    $id = ArtefactTypeBlogPost::new_post($USER, $values);
    redirect(get_config('wwwroot') . 'artefact/blog/view/?id=' . $values['id']);
}

/**
 * This function gets called to create a new blog post and mark it as a draft.
 *
 * @param array
 */
107
function newpost_submit_saveasdraft(Pieform $form, array $values) {
Alastair Pharo's avatar
Alastair Pharo committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    global $USER;

    $values['published'] = false;
    $id = ArtefactTypeBlogPost::new_post($USER, $values);
    redirect(get_config('wwwroot') . 'artefact/blog/view/?id=' . $values['id']);
}


/** 
 * This function get called to cancel the form submission. It returns to the
 * blog list.
 */
function newpost_cancel_cancel() {
    $id = param_integer('id');
    redirect(get_config('wwwroot') . 'artefact/blog/view/?id=' . $id);
Alastair Pharo's avatar
Alastair Pharo committed
123
124
125
}

?>