Commit a10e4430 authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Edit view screen

parent d99e8079
......@@ -26,20 +26,21 @@
defined('INTERNAL') || die();
$string['createviewstep1'] = 'Create View - Step 1 of 4';
$string['editmetadata'] = 'Edit View Information';
$string['createviewstep2'] = 'Create View - Step 2 of 4';
$string['createviewstep3'] = 'Create View - Step 3 of 4';
$string['createviewstep4'] = 'Create View - Step 4 of 4';
$string['next'] = 'Next';
$string['back'] = 'Back';
$string['createview'] = 'Create View';
$string['title'] = 'View Title';
$string['description'] = 'View Description';
$string['startdate'] = 'Access Start Date/Time';
$string['stopdate'] = 'Access End Date/Time';
$string['stopdate'] = 'Access End Date/Time';
$string['ownerformat'] = 'Owner Format';
$string['createviewstep1'] = 'Create View - Step 1 of 4';
$string['editmetadata'] = 'Edit View Information';
$string['createviewstep2'] = 'Create View - Step 2 of 4';
$string['createviewstep3'] = 'Create View - Step 3 of 4';
$string['editview'] = 'Edit View';
$string['createviewstep4'] = 'Create View - Step 4 of 4';
$string['next'] = 'Next';
$string['back'] = 'Back';
$string['createview'] = 'Create View';
$string['title'] = 'View Title';
$string['description'] = 'View Description';
$string['startdate'] = 'Access Start Date/Time';
$string['stopdate'] = 'Access End Date/Time';
$string['stopdate'] = 'Access End Date/Time';
$string['ownerformat'] = 'Owner Format';
$string['ownerformatdescription'] = 'This field controls what appears in the author field for the template you select in step 2';
$string['category.all'] = 'All Templates';
......
......@@ -35,6 +35,7 @@
{else}
<li id="globalnav-siteadmin"><a href="{$WWWROOT}admin/">Site Administration</a></li>
{/if}
<li><a href="" onclick="createLoggingPane(); return false;">Create Logging Pane</a></li>
{/if}
</ul>
</div>
......
......@@ -5,7 +5,11 @@
<div class="box-cnrs"><span class="cnr-tl"><span class="cnr-tr"><span class="cnr-bl"><span class="cnr-br">
<div class="maincontent">
<h2>{str tag=createviewstep3 section=view}</h2>
{if $EDITMODE}
<h2>{str tag=editview section=view}</h2>
{else}
<h2>{str tag=createviewstep3 section=view}</h2>
{/if}
{literal}
<style type="text/css">
......@@ -15,9 +19,16 @@
<div id="template">
<form action="" method="post">
{$template}
{if $EDITMODE}
<input type="hidden" name="viewid" value="{$viewid}">
{/if}
<input type="submit" name="cancel" value="{str tag=cancel}">
{if $EDITMODE}
<input type="submit" name="submit" value="{str tag=save}">
{else}
<input type="submit" name="back" value="{str tag=back section=view}">
<input type="submit" name="submit" value="{str tag=next section=view}">
{/if}
</form>
</div>
<script type="text/javascript">
......
<?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('template.php');
$view_id = param_integer('viewid');
$artefacts = param_variable('template', array());
$view_data = get_record( 'view', 'id', $view_id, 'owner', $USER->get('id'));
if(!$view_data) {
$SESSION->add_error_msg(get_string('canteditdontown', 'view'));
redirect(get_config('wwwroot') . 'view/');
}
$data = array(
'template' => $view_data->template,
'title' => $view_data->title,
'description' => $view_data->description,
'ownerformat' => $view_data->ownerformat,
'artefacts' => array(),
);
$view_content = get_records_array('view_content', 'view', $view_id);
if ($view_content) {
foreach ($view_content as &$label) {
$data['artefacts'][$label->block] = array(
'value' => $label->content,
);
}
}
$view_artefact = get_records_array('view_artefact', 'view', $view_id);
if ($view_artefact) {
foreach ($view_artefact as &$artefact) {
if (isset($data['artefacts'][$artefact->block])) {
if (!is_array($data['artefacts'][$artefact->block]['id'])) {
$data['artefacts'][$artefact->block]['id'] = array($data['artefacts'][$artefact->block]['id']);
}
$data['artefacts'][$artefact->block]['id'][] = $artefact->artefact;
}
else {
$data['artefacts'][$artefact->block] = array(
'id' => $artefact->artefact,
'format' => $artefact->format,
);
}
}
}
// @todo load artefacts
$parsed_template = template_locate($data['template']);
function validate_artefacts(&$artefacts) {
global $parsed_template;
if (isset($parsed_template['parseddata'])) {
$template_data = $parsed_template['parseddata'];
}
else {
$template_data = $parsed_template['cacheddata'];
}
$template_fields = array();
foreach ($template_data as $block) {
if ($block['type'] == 'block') {
$template_fields[$block['data']['id']] = $block['data'];
}
}
foreach ($artefacts as $block => &$data) {
if (!isset($template_fields[$block])) {
unset($artefacts[$block]);
next;
}
// @todo martyn more validation ;)
$data['type'] = $template_fields[$block]['type'];
}
}
if (param_boolean('submit')) {
validate_artefacts($artefacts);
$data['artefacts'] = $artefacts;
db_begin();
delete_records('view_content', 'view', $view_id);
delete_records('view_artefact', 'view', $view_id);
$time = db_format_timestamp(time());
foreach ($data['artefacts'] as $block => $blockdata) {
if ($blockdata['type'] == 'label') {
$viewcontent = new StdClass;
$viewcontent->view = $view_id;
$viewcontent->content = $blockdata['value'];
$viewcontent->block = $block;
$viewcontent->ctime = $time;
insert_record('view_content', $viewcontent);
}
else if ($blockdata['type'] == 'artefact') {
$blockdata['id'] = (array)$blockdata['id'];
foreach ($blockdata['id'] as $id) {
$viewartefact = new StdClass;
$viewartefact->view = $view_id;
$viewartefact->artefact = $id;
$viewartefact->block = $block;
$viewartefact->ctime = $time;
$viewartefact->format = $blockdata['format'];
insert_record('view_artefact', $viewartefact);
}
}
else {
throw new MaharaException('Unknown block data type, this simply should _not_ happen. Perhaps someone changed step3 and forgot to change this?');
}
}
db_commit();
$SESSION->add_ok_msg(get_string('viewinformationsaved', 'view'));
redirect(get_config('wwwroot') . 'view/');
}
if (param_boolean('cancel')) {
redirect(get_config('wwwroot') . 'view/');
}
// Get the list of root things for the tree
$rootinfo = "var data = [";
foreach (plugins_installed('artefact') as $artefacttype) {
safe_require('artefact', $artefacttype->name);
if ($artefacttype->active) {
foreach (call_static_method('PluginArtefact' . ucfirst($artefacttype->name), 'get_toplevel_artefact_types') as $type) {
$rootinfo .= json_encode(array(
'id' => $artefacttype->name,
'isartefact' => false,
'container' => true,
'text' => get_string($type, "artefact.{$artefacttype->name}"),
'pluginname' => $artefacttype->name
)) . ',';
}
}
}
$rootinfo = substr($rootinfo, 0, -1) . '];';
$template = template_render($parsed_template, TEMPLATE_RENDER_EDITMODE, array_merge($data, $data['artefacts']));
$headers = array();
if (isset($parsed_template['css'])) {
$headers[] = '<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'view/template.css.php?template=' . $data['template'] . '">';
}
$smarty = smarty(array('collapsabletree', 'move', 'tablerenderer'), $headers);
$smarty->assign('rootinfo', $rootinfo);
$smarty->assign('plusicon', theme_get_image_path('plus.png'));
$smarty->assign('minusicon', theme_get_image_path('minus.png'));
$smarty->assign('template', $template);
$smarty->assign('EDITMODE', true);
$smarty->assign('viewid', $view_id);
$smarty->display('view/create3.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