Commit f683507f authored by Richard Mansfield's avatar Richard Mansfield

Put edit layout stuff on a single page

Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent b805aaf3
......@@ -247,7 +247,9 @@ $string['in'] = 'in';
$string['noblocks'] = 'Sorry, no blocks in this category :(';
$string['timeofsubmission'] = 'Time of submission';
$string['50,50'] = $string['33,33,33'] = $string['25,25,25,25'] = 'Equal widths';
$string['column'] = 'column';
$string['columns'] = 'columns';
$string['100'] = $string['50,50'] = $string['33,33,33'] = $string['25,25,25,25'] = $string['20,20,20,20,20'] = 'Equal widths';
$string['67,33'] = 'Larger left column';
$string['33,67'] = 'Larger right column';
$string['25,50,25'] = 'Larger centre column';
......
{if $microheaders}
{include file="viewmicroheader.tpl"}
{else}
{include file="header.tpl"}
<h1>{$viewtitle}</h1>
{/if}
{include file="view/editviewtabs.tpl" selected='layout'}
<div class="subpage rel">
<p>{str tag='viewcolumnspagedescription' section='view'}</p>
{$form|safe}
</div>
{if $microheaders}{include file="microfooter.tpl"}{else}{include file="footer.tpl"}{/if}
\ No newline at end of file
......@@ -2,5 +2,5 @@
<ul class="in-page-tabs edit-view-tabs">
<li><a{if $selected == 'content'} class="current-tab"{/if} href="{$WWWROOT}view/blocks.php?id={$viewid}">{str tag=editcontent section=view}</a></li>
{if $edittitle}<li><a{if $selected == 'title'} class="current-tab"{/if} href="{$WWWROOT}view/edit.php?id={$viewid}">{str tag=edittitleanddescription section=view}</a></li>{/if}
<li><a{if $selected == 'layout'} class="current-tab"{/if} href="{$WWWROOT}view/columns.php?id={$viewid}">{str tag=editlayout section=view}</a></li>
<li><a{if $selected == 'layout'} class="current-tab"{/if} href="{$WWWROOT}view/layout.php?id={$viewid}">{str tag=editlayout section=view}</a></li>
</ul>
......@@ -12,7 +12,13 @@
{$form_start_tag|safe}
{assign var=columns value=0}
{foreach from=$options key=id item=description}
{if $columns != $layouts[$id]->columns}
{assign var=columns value=$layouts[$id]->columns}
<div class="cb"></div>
<div class="fl">{$layouts[$id]->columns} {if $columns > 1}{str tag=columns section=view}{else}{str tag=column section=view}{/if}</div>
{/if}
<div class="fl">
<div><img src="{$WWWROOT}thumb.php?type=viewlayout&amp;vl={$id}" alt=""></div>
{if $id == $currentlayout}
......@@ -25,10 +31,7 @@
{/foreach}
<div class="cb">
<input type="hidden" name="pieform_viewlayout" value="">
{if $back}
<input type="submit" class="cancel" name="cancel_submit" value="{str tag='back'}">
{/if}
<input type="submit" class="submit" name="submit" value="{str tag='changeviewlayout' section='view'}">
<input type="submit" class="submit" name="submit" value="{str tag='save'}">
</div>
</form>
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 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 core
* @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);
require_once(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('view.php');
require_once(get_config('libroot') . 'group.php');
define('TITLE', get_string('changemyviewlayout', 'view'));
$id = param_integer('id');
$new = param_boolean('new');
$category = param_alpha('c', '');
$view = new View($id);
$numcolumns = $view->get('numcolumns');
$group = $view->get('group');
$institution = $view->get('institution');
$view->set_edit_nav();
$params = 'id=' . $id;
if ($category) {
$params .= '&c=' . $category;
}
if ($new) {
$params .= '&new=1';
}
if (!$USER->can_edit_view($view)) {
throw new AccessDeniedException();
}
if ($USER->get_account_preference('addremovecolumns')) {
redirect('/view/layout.php?' . $params);
}
$columnsform = pieform(array(
'name' => 'viewcolumns',
'elements' => array(
'numcolumns' => array(
'type' => 'select',
'title' => get_string('numberofcolumns', 'view'),
'options' => array( 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5'),
'defaultvalue' => $numcolumns,
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('next'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'view/blocks.php?' . $params
)
)
));
$smarty = smarty(array(), array(), array(), array('sidebars' => false));
$smarty->assign('form', $columnsform);
$smarty->assign('viewid', $view->get('id'));
$smarty->assign('viewtitle', $view->get('title'));
$smarty->assign('edittitle', $view->can_edit_title());
if (get_config('viewmicroheaders')) {
$smarty->assign('microheaders', true);
$smarty->assign('microheadertitle', $view->display_title(true, false));
}
$smarty->display('view/columns.tpl');
function viewcolumns_submit(Pieform $form, $values) {
global $view, $SESSION, $category, $new, $params;
$oldcolumns = $view->get('numcolumns');
$newcolumns = $values['numcolumns'];
db_begin();
if ($oldcolumns > $newcolumns) {
for ($i = $oldcolumns; $i > $newcolumns; $i--) {
$view->removecolumn(array('column' => $i));
}
}
else if ($oldcolumns < $newcolumns) {
for ($i = $oldcolumns; $i < $newcolumns; $i++) {
$view->addcolumn(array('before' => $i + 1, 'returndata' => false));
}
}
$dbcolumns = get_field('view', 'numcolumns', 'id', $view->get('id'));
if ($dbcolumns != $newcolumns) {
db_rollback();
$SESSION->add_error_msg(get_string('changecolumnlayoutfailed', 'view'));
redirect(get_config('wwwroot') . 'view/columns.php?' . $params);
}
db_commit();
if ($newcolumns > 1 && $newcolumns < 5) {
redirect(get_config('wwwroot') . 'view/layout.php?' . $params);
}
else {
$SESSION->add_ok_msg(get_string('viewlayoutchanged', 'view'));
redirect(get_config('wwwroot') . 'view/blocks.php?' . $params);
}
}
?>
......@@ -36,7 +36,6 @@ define('TITLE', get_string('changemyviewlayout', 'view'));
$id = param_integer('id');
$new = param_boolean('new');
$category = param_alpha('c', '');
$view = new View($id);
$numcolumns = $view->get('numcolumns');
$currentlayout = $view->get('layout');
......@@ -45,9 +44,6 @@ $group = $view->get('group');
$institution = $view->get('institution');
$view->set_edit_nav();
$goto = get_config('wwwroot') . 'view/blocks.php?id=' . $view->get('id');
if ($category) {
$goto .= '&c=' . $category;
}
if ($new) {
$goto .= '&new=1';
}
......@@ -61,34 +57,28 @@ if (!$currentlayout) {
$currentlayout = $view->get_layout()->id;
}
if ($numcolumns > 1 && $numcolumns < 5) {
$layouts = get_records_array('view_layout', 'columns', $numcolumns);
$options = array();
foreach ($layouts as $layout) {
$options[$layout->id] = get_string($layout->widths, 'view');
}
$layoutform = new Pieform(array(
'name' => 'viewlayout',
'elements' => array(
'layout' => array(
'type' => 'radio',
'options' => $options,
'defaultvalue' => $currentlayout,
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('submit'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'view/columns.php?id=' . $view->get('id') . '&c=' . $category . '&new=' . $new
),
),
));
}
else {
$SESSION->add_error_msg(get_string('noviewlayouts', 'view', $numcolumns));
redirect($goto);
$layouts = get_records_assoc('view_layout', '', '', 'columns,id');
$options = array();
foreach ($layouts as $layout) {
$options[$layout->id] = get_string($layout->widths, 'view');
}
$layoutform = new Pieform(array(
'name' => 'viewlayout',
'elements' => array(
'layout' => array(
'type' => 'radio',
'options' => $options,
'defaultvalue' => $currentlayout,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('save'),
),
),
));
$smarty = smarty(array(), array(), array(), array('sidebars' => false));
$smarty->assign('layouts', $layouts);
$smarty->assign('currentlayout', $currentlayout);
$smarty->assign('form', $layoutform);
$smarty->assign('form_start_tag', $layoutform->get_form_tag());
......@@ -103,12 +93,44 @@ if (get_config('viewmicroheaders')) {
}
$smarty->display('view/layout.tpl');
function viewlayout_validate(Pieform $form, $values) {
global $layouts;
if (!isset($layouts[$values['layout']])) {
$form->set_error('invalidlayout');
}
}
function viewlayout_submit(Pieform $form, $values) {
global $view, $SESSION, $goto;
global $view, $SESSION, $goto, $layouts;
$oldcolumns = $view->get('numcolumns');
$newcolumns = $layouts[$values['layout']]->columns;
db_begin();
if ($oldcolumns > $newcolumns) {
for ($i = $oldcolumns; $i > $newcolumns; $i--) {
$view->removecolumn(array('column' => $i));
}
}
else if ($oldcolumns < $newcolumns) {
for ($i = $oldcolumns; $i < $newcolumns; $i++) {
$view->addcolumn(array('before' => $i + 1, 'returndata' => false));
}
}
$dbcolumns = get_field('view', 'numcolumns', 'id', $view->get('id'));
if ($dbcolumns != $newcolumns) {
db_rollback();
$SESSION->add_error_msg(get_string('changecolumnlayoutfailed', 'view'));
redirect(get_config('wwwroot') . 'view/layout.php?' . $params);
}
db_commit();
$view->set('layout', $values['layout']);
$view->commit();
$SESSION->add_ok_msg(get_string('viewlayoutchanged', 'view'));
redirect($goto);
}
?>
}
\ No newline at end of file
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