license-edit.php 3.46 KB
Newer Older
1 2 3 4 5 6
<?php
/**
 *
 * @package    mahara
 * @subpackage admin
 * @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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 */

define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite/sitelicenses');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'sitepages');

require(dirname(dirname(dirname(__FILE__))).'/init.php');
require_once('license.php');
require_once('pieforms/pieform.php');
define('DEFAULTPAGE', 'home');

$extralicensessql = "
25
    SELECT DISTINCT license
26
    FROM {artefact}
27
    WHERE license IS NOT NULL AND license <> ''
28
        AND license NOT IN (SELECT name FROM {artefact_license})
29
    ORDER BY license
30 31 32
";

$edit = param_variable('edit', null);
33
$title = get_string('sitelicensesadd', 'admin');
34 35 36

if ($edit !== null) {
    $edit = get_record('artefact_license', 'name', $edit);
37
    $title = get_string('sitelicensesedit', 'admin');
38 39
}

40 41
define('TITLE', $title);

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
$elements = array(
    'displayname' => array(
        'type' => 'text',
        'title' => get_string('licensedisplaynamelabel', 'admin'),
        'rules' => array('required' => true, 'maxlength' => 255),
    ),
    'name' => array(
        'type' => 'text',
        'title' => get_string('licensenamelabel', 'admin'),
        'rules' => array('required' => true, 'maxlength' => 255),
    ),
    'name2' => array(
        'type' => 'html',
        'title' => get_string('licensenamelabel', 'admin'),
        'ignore' => true,
    ),
    'shortname' => array(
        'type' => 'text',
        'title' => get_string('licenseshortnamelabel', 'admin'),
    ),
    'icon' => array(
        'type' => 'text',
        'title' => get_string('licenseiconlabel', 'admin'),
        'help' => true,
    ),
    'submit' => array(
        'type' => 'submit',
69
        'class' => 'btn-success',
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
        'value' => get_string('licensesave', 'admin'),
    ),
);
if (empty($edit)) {
    $options = array();
    foreach (get_column_sql($extralicensessql) as $o) {
        $options[$o] = $o;
    }
    if (count($options)) {
        $elements['name']['type'] = 'select';
        $elements['name']['allowother'] = true;
        $elements['name']['options'] = $options;
    }
}
else {
    $elements['name']['value'] = $edit->name;
    $elements['name']['type'] = 'hidden';
    $elements['name2']['value'] = '<a href="' . hsc($edit->name) . '" target="_blank">' . hsc($edit->name) . '</a>';
    unset($elements['name2']['ignore']);
    foreach (array('displayname', 'shortname', 'icon') as $f) {
        $elements[$f]['defaultvalue'] = $edit->{$f};
    }
}

$form = pieform(array(
    'name' => 'license',
    'plugintype' => 'core',
    'pluginname' => 'core',
    'elements' => $elements,
));


function license_submit(Pieform $form, $values) {
    global $SESSION;
    $data = new StdClass;
    foreach (array('name', 'displayname', 'shortname', 'icon') as $f) {
        $data->{$f} = trim($values[$f]);
    }

    db_begin();
    delete_records('artefact_license', 'name', $data->name);
    insert_record('artefact_license', $data);
    db_commit();
    $SESSION->add_ok_msg(get_string('licensesaved', 'admin'));
    redirect('/admin/site/licenses.php');
}

$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
Naomi Guyer's avatar
Naomi Guyer committed
119

120 121 122
$smarty->assign('form', $form);
$smarty->assign('enabled', get_config('licensemetadata'));
$smarty->display('admin/site/license-edit.tpl');