create4.php 4.06 KB
Newer Older
Nigel McNie's avatar
Nigel McNie 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
<?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 core
 * @author     Nigel McNie <nigel@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', 'view');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('pieforms/pieform/elements/calendar.php');
$smarty = smarty(array(), pieform_get_headdata_calendar(pieform_configure_calendar(array())));
33
$createid = param_integer('createid', null);
Nigel McNie's avatar
Nigel McNie committed
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

$form = array(
    'name' => 'createview4',
    'elements' => array(
        'acl' => array(
            'type' => 'viewacl',
            //'defaultvalue' => array(
            //    // make something up
            //    array(
            //        'type'  => 'public',
            //        'id'    => null,
            //        'start' => null,
            //        'end'   => null
            //    ),
            //    array(
            //        'type' => 'user',
            //        'id' => 1,
            //        'start' => null,
            //        'end' => null
            //    )
            //)
        ),
        'submit' => array(
            'type' => 'submitcancel',
            'value' => array(get_string('createview'), get_string('cancel'))
        )
    )
);


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
117
118
119
120
121
function createview4_submit($values) {
    global $SESSION, $USER, $createid;
    log_debug($values);
    $data = $SESSION->get('create_' . $createid);
    log_debug($data);


    db_begin();
    $time = db_format_timestamp(time());

    $view = new StdClass;
    $view->title = $data['title'];
    $view->description = $data['description'];
    $view->owner = $USER->get('id');
    $view->ownerformat = $data['ownerformat'];
    $view->template = $data['template'];
    $view->startdate = db_format_timestamp($data['startdate']);
    $view->stopdate = db_format_timestamp($data['stopdate']);
    $view->ctime = $view->mtime = $view->atime = $time;
    log_debug($view);
    $viewid = insert_record('view', $view, 'id', true);
    log_debug('inserted view as id ' . $viewid);

    foreach ($data['artefacts'] as $block => $blockdata) {
        if ($blockdata['type'] == 'label') {
            $viewcontent          = new StdClass;
            $viewcontent->view    = $viewid;
            $viewcontent->content = $blockdata['value'];
            $viewcontent->block   = $block;
            $viewcontent->ctime   = $time;
            insert_record('view_content', $viewcontent);
        }
        else if ($blockdata['type'] == 'artefact') {
            $viewartefact           = new StdClass;
            $viewartefact->view     = $viewid;
            $viewartefact->artefact = $blockdata['id'];
            $viewartefact->block    = $block;
            $viewartefact->ctime    = $time;
            $viewartefact->format   = $blockdata['format'];
            insert_record('view_artefact', $viewartefact);
        }
        else {
            throw new OMGWTFException();
        }
    }

    // @todo view access
    //

    db_commit();
    $SESSION->add_ok_msg(get_string('viewcreatedsuccessfully'));
    redirect(get_config('wwwroot') . 'view/');
}

function createview4_cancel() {
    redirect(get_config('wwwroot') . 'view/');
}

Nigel McNie's avatar
Nigel McNie committed
122
123
124
125
$smarty->assign('createview4form', pieform($form));
$smarty->display('view/create4.tpl');

?>