pages.php 3.26 KB
Newer Older
Richard Mansfield's avatar
Richard Mansfield committed
1 2 3 4 5
<?php
/**
 *
 * @package    mahara
 * @subpackage admin
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.
Richard Mansfield's avatar
Richard Mansfield committed
9 10 11
 *
 */

12
define('INTERNAL', 1);
13
define('ADMIN', 1);
14
define('MENUITEM', 'configsite/sitepages');
Penny Leach's avatar
Penny Leach committed
15 16 17 18
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'sitepages');

19
require(dirname(dirname(dirname(__FILE__))).'/init.php');
20
require_once('pieforms/pieform.php');
21
define('TITLE', get_string('staticpages', 'admin'));
22
define('DEFAULTPAGE', 'home');
Richard Mansfield's avatar
Richard Mansfield committed
23

24
$sitepages = array();
25 26 27 28 29 30
$corepagenames = site_content_pages();
$localpagenames = function_exists('local_site_content_pages') ? local_site_content_pages() : array();
if ($pagenames = array_merge($corepagenames, $localpagenames)) {
    $sitepages = get_records_select_array(
        'site_content', 'name IN (' . join(',', array_fill(0, count($pagenames), '?')) . ')', $pagenames
    );
31
}
32

Richard Mansfield's avatar
Richard Mansfield committed
33 34
$pageoptions = array();
foreach ($sitepages as $page) {
35 36
    $section = in_array($page->name, $localpagenames) ? 'local' : 'admin';
    $pageoptions[$page->name] = get_string($page->name, $section);
37
    $pagecontents[$page->name] = $page->content;
Richard Mansfield's avatar
Richard Mansfield committed
38 39 40
}
asort($pageoptions);

41
$getstring = array('discardpageedits' => json_encode(get_string('discardpageedits', 'admin')));
42

43 44 45 46 47
$form = pieform(array(
    'name'              => 'editsitepage',
    'jsform'            => true,
    'jssuccesscallback' => 'contentSaved',
    'elements'          => array(
48
        'pageinstitution' => array('type' => 'hidden', 'value' => 'mahara'),
49
        'pagename'    => array(
50
            'type'    => 'select',
51
            'title'   => get_string('pagename', 'admin'),
52
            'defaultvalue' => DEFAULTPAGE,
Richard Mansfield's avatar
Richard Mansfield committed
53 54 55
            'options' => $pageoptions
        ),
        'pagetext' => array(
56 57
            'name'        => 'pagetext',
            'type'        => 'wysiwyg',
58 59
            'rows'        => 25,
            'cols'        => 100,
60
            'title'       => get_string('pagetext', 'admin'),
61
            'defaultvalue' => $pagecontents[DEFAULTPAGE],
62
            'rules'       => array(
63
                'maxlength' => 65536,
Richard Mansfield's avatar
Richard Mansfield committed
64 65 66 67
                'required' => true
            )
        ),
        'submit' => array(
Naomi Guyer's avatar
Naomi Guyer committed
68
            'class' => 'btn btn-success',
Richard Mansfield's avatar
Richard Mansfield committed
69
            'type'  => 'submit',
70
            'value' => get_string('savechanges', 'admin')
71
        ),
Richard Mansfield's avatar
Richard Mansfield committed
72
    )
73
));
74 75


76
function editsitepage_submit(Pieform $form, $values) {
77 78 79 80 81
    global $USER;
    $data = new StdClass;
    $data->name    = $values['pagename'];
    $data->content = $values['pagetext'];
    $data->mtime   = db_format_timestamp(time());
82
    $data->mauthor = $USER->get('id');
83
    $data->institution = 'mahara';
84
    try {
85
        update_record('site_content', $data, array('name', 'institution'));
86 87
    }
    catch (SQLException $e) {
88
        $form->reply(PIEFORM_ERR, get_string('savefailed', 'admin'));
89
    }
90
    $form->reply(PIEFORM_OK, get_string('pagesaved', 'admin'));
91 92
}

93
$smarty = smarty(array('adminsitepages'), array(), array('admin' => array('discardpageedits')));
Richard Mansfield's avatar
Richard Mansfield committed
94
$smarty->assign('pageeditform', $form);
Naomi Guyer's avatar
Naomi Guyer committed
95
$smarty->assign('PAGEICON', 'fa fa-pencil');
96
$smarty->assign('PAGEHEADING', TITLE);
97
$smarty->display('admin/site/pages.tpl');