Commit 0bf5cee1 authored by Jiri Baum's avatar Jiri Baum
Browse files

License metadata - license list admin. (Bug #1095499)



Add a page where the site admin can edit the list of licenses available.

Change-Id: Id124a51fd37c7e4b99ff80be7764fd2175f247e7
Signed-off-by: default avatarJiri Baum <jiri@catalyst-au.net>
parent 5a3a8039
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2012 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
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('TITLE', get_string('sitelicenses', 'admin'));
define('DEFAULTPAGE', 'home');
$extralicensessql = "
SELECT license FROM artefact WHERE license IS NOT NULL and license <> ''
EXCEPT
SELECT name FROM artefact_license
";
$edit = param_variable('edit', null);
if ($edit !== null) {
$edit = get_record('artefact_license', 'name', $edit);
}
$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',
'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);
$smarty->assign('form', $form);
$smarty->assign('enabled', get_config('licensemetadata'));
$smarty->display('admin/site/license-edit.tpl');
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2012 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
define('MENUITEM', 'configsite/sitelicenses');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'licenses');
require(dirname(dirname(dirname(__FILE__))).'/init.php');
require_once('license.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('sitelicenses', 'admin'));
define('DEFAULTPAGE', 'home');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['license_delete'])) {
$del = array_shift(array_keys($_POST['license_delete']));
delete_records('artefact_license', 'name', $del);
$SESSION->add_ok_msg(get_string('licensedeleted', 'admin'));
}
}
if (!isset($licenses)) {
$licenses = get_records_assoc('artefact_license', null, null, 'displayname');
}
$extralicenses = get_column_sql("
SELECT license FROM artefact WHERE license IS NOT NULL and license <> ''
EXCEPT
SELECT name FROM artefact_license
");
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('licenses', $licenses);
$smarty->assign('extralicenses', $extralicenses);
$smarty->assign('enabled', get_config('licensemetadata'));
$smarty->display('admin/site/licenses.tpl');
......@@ -92,6 +92,9 @@ $string['editsitepagesdescription'] = 'Edit the content of various pages around
$string['menus'] = 'Menus';
$string['menusdescription'] = 'Manage the links and files within the "Links and resources" and footer menus';
$string['sitefiles'] = 'Site files';
$string['sitelicenses'] = 'Licenses';
$string['sitelicensesdescription'] = 'Configure the list of licenses that users can use for content.';
$string['sitelicensesdisablednote'] = '<b>Note</b>: License metadata is currently disabled. You will need to enable it in the "General settings" section of "<a href="%sadmin/site/options.php">Configure site</a>" before users will be able to specify licenses.';
$string['sitefilesdescription'] = 'Upload and administer files that can be put in the "Links and resources" menu and in site pages';
$string['siteviews'] = 'Site pages';
$string['siteviewsdescription'] = 'Create and administer pages and page templates for the entire site';
......@@ -452,6 +455,19 @@ $string['footercustomlink'] = 'You can override the default page, <em>%s</em>, b
// Admin Files
$string['adminfilespagedescription'] = 'Here you can upload files that can be included in the %s"Links and resources"%s menu. Files in the home directory will be able to be added to the logged-in menu, while files in the public directory will be able to be added to the public menu.';
// License settings
$string['extralicensesdescription'] = 'Note: The following licenses are used by some content but have not been configured.';
$string['licensenamelabel'] = 'URL';
$string['licensedisplaynamelabel'] = 'Display name';
$string['licenseshortnamelabel'] = 'Acronym';
$string['licenseiconlabel'] = 'Icon';
$string['addsitelicense'] = 'Add a license';
$string['licensedeleted'] = 'License deleted.';
$string['licensesave'] = 'Save';
$string['licensesaved'] = 'License saved.';
$string['licenseurldup'] = 'The URLs must be unique; %s is repeated here.';
$string['licenseurlnone'] = 'Please specify a URL for %s.';
// Networking options
$string['networkingextensionsmissing'] = 'Sorry, you cannot configure Mahara networking because your PHP installation is missing one or more required extensions:';
$string['publickey'] = 'Public key';
......
<h3>License icon</h3>
<p>This can be a http://... or https://... URL to an image elsewhere on your site or externally.</p>
<p>It can also be a license:... URL to specify license icons from the Mahara theme. For example, the
URL <pre>license:gfdl.png</pre> would refer to the file
<pre>static/images/license/gfdl.png</pre> in the theme.</p>
<h3>Licenses</h3>
<p>The licenses configured here serve three functions:
<ul>
<li>The display name, acronym and icon are shown for the content license rather than the URL.</li>
<li>If the "License metadata" setting is checked in the "General settings" section of "Site options", the licenses are displayed to users when they create content.</li>
<li>Users are restricted to the licenses configured here unless the "Allow custom licenses" setting is checked in the "General settings" section of "Site options".</li>
</ul></p>
......@@ -1846,6 +1846,12 @@ function admin_nav() {
'title' => get_string('networking', 'admin'),
'weight' => 40,
),
'configsite/sitelicenses' => array(
'path' => 'configsite/sitelicenses',
'url' => 'admin/site/licenses.php',
'title' => get_string('sitelicenses', 'admin'),
'weight' => 45,
),
'configsite/siteviews' => array(
'path' => 'configsite/siteviews',
'url' => 'admin/site/views.php',
......
......@@ -78,6 +78,7 @@
<li><strong><a href="{$WWWROOT}admin/site/networking.php">{str tag=networking section=admin}</a></strong> - {str tag=networkingdescription section=admin}</li>
<li><strong><a href="{$WWWROOT}admin/site/views.php">{str tag=siteviews section=admin}</a></strong> - {str tag=siteviewsdescription section=admin}</li>
<li><strong><a href="{$WWWROOT}artefact/file/sitefiles.php">{str tag=sitefiles section=admin}</a></strong> - {str tag=sitefilesdescription section=admin}</li>
<li><strong><a href="{$WWWROOT}admin/site/licenses.php">{str tag=sitelicenses section=admin}</a></strong> - {str tag=sitelicensesdescription section=admin}</li>
</ul>
<h3>{str tag=configusers section=admin}</h3>
......
{include file="header.tpl"}
<p>{str tag=sitelicensesdescription section=admin}</p>
{if !$enabled}
<p>{str tag=sitelicensesdisablednote section=admin args=$WWWROOT}</p>
{/if}
{$form|safe}
{include file="footer.tpl"}
{include file="header.tpl"}
<p>{str tag=sitelicensesdescription section=admin}</p>
{if !$enabled}
<p>{str tag=sitelicensesdisablednote section=admin args=$WWWROOT}</p>
{/if}
<form id="sitelicenses" action="" method="post" name="sitelicenses">
{if $errors}
{foreach from=$errors item=e}
<div class="errmsg">{$e}</div>
{/foreach}
{/if}
<table>
<tr class="{cycle values='r0,r1'}">
<th>{str tag=licenseiconlabel section=admin}</td>
<th>{str tag=licensedisplaynamelabel section=admin}</td>
<th>{str tag=licenseshortnamelabel section=admin}</td>
<th>{str tag=licensenamelabel section=admin}</td>
<th>&nbsp;</td>
</tr>
{foreach from=$licenses key=i item=l}
<tr class="{cycle values='r0,r1'}">
<td>{if $l->icon}<img src="{license_icon_url($l->icon)}">{/if}</td>
<td><a href="{$l->name}">{$l->displayname}</a></td>
<td>{$l->shortname}</td>
<td><a href="{$l->name}">{$l->name}</a></td>
<td>
<a href="license-edit.php?edit={$l->name|escape:url}"><img src="{$THEME->get_url('images/edit.gif')}"></a>
<input type="image" title="Delete" value="" name="license_delete[{$l->name}]" src="{$THEME->get_url('images/icon_close.gif')}"></td>
</tr>
{/foreach}
</table>
<a href="license-edit.php?add=add" class="btn">{str tag=addsitelicense section=admin}</a>
{if $extralicenses}
<p>{str tag=extralicensesdescription section=admin}</p>
<ul>
{foreach from=$extralicenses item=l}
<li>{$l}</li>
{/foreach}
</ul>
{/if}
</form>
{include file="footer.tpl"}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment