Commit 7988e54f authored by Stacey Walker's avatar Stacey Walker Committed by Richard Mansfield

new collection creation start form

parent 11ef570b
......@@ -42,18 +42,18 @@ if (!get_config('allowcollections')) {
die();
}
$collectionid = param_integer('id');
define('COLLECTION', $collectionid);
$id = param_integer('id');
define('COLLECTION', $id);
$data = get_record_select('collection', 'id = ?', array(COLLECTION), '*, ' . db_format_tsfield('ctime'));
$collection = new Collection(COLLECTION, (array)$data);
$data = get_record_select('collection', 'id = ?', array($id), '*, ' . db_format_tsfield('ctime'));
$collection = new Collection($id, (array)$data);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('/collection/');
}
$data->ctime = strftime(get_string('strftimedate'), $data->ctime);
$data->views = count_records('collection_view','collection',COLLECTION);
$data->views = count_records('collection_view','collection',$id);
$data->access = $collection->master();
$smarty = smarty();
......
......@@ -36,7 +36,6 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('collection.php');
require_once('view.php');
define('TITLE', get_string('collectionaccess','collection'));
// check that My Collections is enabled in the config
// if not as the user is trying to access this illegally
......@@ -44,14 +43,24 @@ if (!get_config('allowcollections')) {
die();
}
$collectionid = param_integer('id');
define('COLLECTION', $collectionid);
$new = param_integer('new', 0);
$id = param_integer('id');
$collection = Collection::current_collection();
$data = get_record_select('collection', 'id = ?', array($id), '*');
$collection = new Collection($id, (array)$data);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('/collection/');
}
if (!$new) {
define('COLLECTION', $id);
define('TITLE', $collection->get('name').': '.get_string('editaccess','collection'));
}
else {
define('TITLE', get_string('editaccess','collection'));
}
$master = $collection->master();
$form = null;
......@@ -70,55 +79,99 @@ if ($collection->has_views()) {
'rules' => array('required' => true),
'defaultvalue' => $master ? $master->view : 0,
);
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('save'),
'goto' => get_config('wwwroot') . 'collection/views.php?id='.COLLECTION,
);
if ($new) {
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('save'),
'goto' => get_config('wwwroot') . 'collection/views.php?id='.$id.'&new='.$new,
);
}
else {
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('save'),
'goto' => get_config('wwwroot') . 'collection/views.php?id='.$id,
);
}
$form = pieform(array(
'name' => 'access',
'plugintype' => 'core',
'pluginname' => 'collection',
'autofocus' => false,
'successcallback' => 'submit',
'renderer' => 'div',
'elements' => $elements,
'plugintype' => 'core',
'pluginname' => 'collection',
'autofocus' => false,
'method' => 'post',
'renderer' => 'div',
'elements' => $elements,
));
}
$smarty = smarty();
$smarty->assign('master',$master);
$smarty->assign('form', $form);
$smarty->assign('accessdesc',get_string('accessdesc','collection'));
if ($new) {
$newform = pieform(array(
'name' => 'new',
'plugintype' => 'core',
'pluginname' => 'collection',
'autofocus' => false,
'method' => 'post',
'elements' => array(
'submit' => array(
'type' => 'cancelbackcreate',
'value' => array(get_string('cancel'), get_string('back','collection'), get_string('save')),
'confirm' => array(get_string('confirmcancelcreatingcollection', 'collection'), null, null),
),
),
));
$smarty->assign('newform', $newform);
}
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('master', $master);
$smarty->assign_by_ref('form', $form);
$smarty->display('collection/access.tpl');
function submit(Pieform $form, $values) {
global $SESSION, $collection;
function access_submit(Pieform $form, $values) {
global $SESSION, $collection, $new;
$new = $new ? '&new=1' : '';
$success = $collection->set_master($values['view']);
if (!$success) {
$SESSION->add_ok_msg(get_string('nooverridesaved', 'collection'));
redirect('/collection/access.php?id=' . $collection->get('id'));
redirect('/collection/access.php?id=' . $collection->get('id') . $new);
}
if ($success['secreturl'] == false) {
$SESSION->add_ok_msg(get_string('accesssaved', 'collection'));
redirect('/collection/access.php?id=' . $collection->get('id'));
redirect('/collection/access.php?id=' . $collection->get('id') . $new);
}
else {
if (!empty($success['valid'])) {
$SESSION->add_ok_msg(get_string('accesssaved', 'collection'));
$SESSION->add_info_msg(get_string('accessignored', 'collection'));
redirect('/collection/access.php?id=' . $collection->get('id'));
redirect('/collection/access.php?id=' . $collection->get('id') . $new);
}
else {
$SESSION->add_error_msg(get_string('accesscantbeused', 'collection'));
redirect('/collection/access.php?id=' . $collection->get('id'));
redirect('/collection/access.php?id=' . $collection->get('id') . $new);
}
}
}
function new_cancel_submit() {
global $collection;
$collection->delete();
redirect('/collection/');
}
function new_submit(Pieform $form, $values) {
global $collection;
if (param_boolean('back')) {
redirect('/collection/views.php?id='.$collection->get('id').'&new=1');
}
else {
redirect('/collection/about.php?id='.$collection->get('id'));
}
}
?>
<?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);
define('MENUITEM', 'myportfolio/collection');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'collection');
define('SECTION_PAGE', 'create');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('collection.php');
require_once('collection2.php');
define('TITLE', get_string('newcollection', 'collection'));
// check that My Collections is enabled in the config
// if not as the user is trying to access this illegally
if (!get_config('allowcollections')) {
die();
}
$elements = Collection::get_collectionform_elements();
$elements['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('savecollection','collection'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'collection/',
);
$form = pieform(array(
'name' => 'createcollection',
'plugintype' => 'core',
'pluginname' => 'collection',
'successcallback' => 'submit',
'elements' => $elements,
));
$smarty = smarty();
$smarty->assign_by_ref('newcollectionform', $form);
$smarty->assign_by_ref('PAGEHEADING', hsc(TITLE));
$smarty->display('collection/new.tpl');
function submit(Pieform $form, $values) {
global $SESSION;
Collection::save($values);
$SESSION->add_ok_msg(get_string('collectionsaved', 'collection'));
redirect('/collection/');
}
?>
......@@ -36,7 +36,8 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('collection.php');
define('TITLE', get_string('deletecollection', 'collection'));
$collectionid = param_integer('id');
$id = param_integer('id');
// check that My Collections is enabled in the config
// if not as the user is trying to access this illegally
......@@ -44,8 +45,8 @@ if (!get_config('allowcollections')) {
die();
}
$data = get_record_select('collection', 'id = ?', array($collectionid));
$collection = new Collection($collectionid, (array)$data);
$data = get_record_select('collection', 'id = ?', array($id));
$collection = new Collection($id, (array)$data);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('/collection/');
......
......@@ -43,16 +43,30 @@ if (!get_config('allowcollections')) {
die();
}
$viewid = param_integer('view');
$collectionid = param_integer('id');
define('COLLECTION', $collectionid);
$vid = param_integer('view');
$new = param_integer('new',0);
$id = param_integer('id');
$collection = Collection::current_collection();
if (!$new) {
define('COLLECTION', $id);
}
$data = (array)get_record_select('collection', 'id = ?', array($id), '*');
$collection = new Collection($id, $data);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('/collection/');
}
$newtxt = $new ? 'new=1' : '';
$elements = array(
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'collection/views.php?id='.$id.$newtxt,
),
);
$form = pieform(array(
'name' => 'removeview',
'renderer' => 'div',
......@@ -60,13 +74,7 @@ $form = pieform(array(
'pluginname' => 'collection',
'autofocus' => false,
'successcallback' => 'submit',
'elements' => array(
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'collection/views.php?id='.COLLECTION,
),
),
'elements' => $elements,
));
$smarty = smarty();
......@@ -76,10 +84,10 @@ $smarty->assign('form', $form);
$smarty->display('collection/delete.tpl');
function submit(Pieform $form, $values) {
global $SESSION, $viewid, $collection;
$collection->remove_view($viewid);
global $SESSION, $vid, $collection, $newtxt;
$collection->remove_view($vid);
$SESSION->add_ok_msg(get_string('viewremovedsuccessfully','collection'));
redirect('/collection/views.php?id='.$collection->get('id'));
redirect('/collection/views.php?id='.$collection->get('id').$newtxt);
}
?>
......@@ -35,7 +35,6 @@ define('SECTION_PAGE', 'edit');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('collection.php');
define('TITLE', get_string('editcollection', 'collection'));
// check that My Collections is enabled in the config
// if not as the user is trying to access this illegally
......@@ -43,24 +42,47 @@ if (!get_config('allowcollections')) {
die();
}
$collectionid = param_integer('id');
define('COLLECTION', $collectionid);
$new = param_boolean('new', 0);
$id = param_integer('id', 0);
$data = get_record_select('collection', 'id = ?', array(COLLECTION));
$collection = new Collection(COLLECTION, (array)$data);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('/collection/');
$data = null;
if ($data = get_record_select('collection', 'id = ?', array($id))) {
$collection = new Collection($id, (array)$data);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('/collection/');
}
}
// if not a new collection
if (!$new) {
define('COLLECTION', $id);
define('TITLE', $collection->get('name').': '.get_string('edittitleanddesc', 'collection'));
}
else {
define('TITLE', get_string('edittitleanddesc', 'collection'));
}
$elements = Collection::get_collectionform_elements($data);
$elements['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('savecollection','collection'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'collection/about.php?id='.COLLECTION,
);
if ($new) {
$elements['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('next') . ': ' . get_string('editviews', 'collection'), get_string('cancel')),
);
}
else {
$elements['id'] = array(
'type' => 'hidden',
'value' => $id,
);
$elements['submit'] = array(
'type' => 'submitcancel',
'value' => array(get_string('savecollection','collection'), get_string('cancel')),
);
}
$form = pieform(array(
'name' => 'editcollection',
'name' => 'edit',
'plugintype' => 'core',
'pluginname' => 'collection',
'successcallback' => 'submit',
......@@ -68,14 +90,28 @@ $form = pieform(array(
));
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign_by_ref('form', $form);
$smarty->display('collection/edit.tpl');
function edit_cancel_submit() {
global $new;
if ($new) {
redirect('/collection/');
}
else {
global $id;
redirect('/collection/about.php?id='.$id);
}
}
function submit(Pieform $form, $values) {
global $SESSION, $collectionid;
Collection::save($values);
$SESSION->add_ok_msg(get_string('collectionsaved', 'collection'));
redirect('/collection/about.php?id='.$collectionid);
global $SESSION, $new;
$collection = Collection::save($values);
if (!$new) {
$SESSION->add_ok_msg(get_string('collectionsaved', 'collection'));
}
$collection->post_edit_redirect($new);
}
?>
......@@ -71,7 +71,7 @@ $smarty = smarty(array('paginator'));
$smarty->assign('collections', $data->data);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('strnocollectionsaddone',
get_string('nocollectionsaddone','collection','<a href="' . get_config('wwwroot') . 'collection/create.php">', '</a>'));
get_string('nocollectionsaddone','collection','<a href="' . get_config('wwwroot') . 'collection/edit.php?new=1">', '</a>'));
$smarty->assign('PAGEHEADING', hsc(get_string('mycollections', 'collection')));
$smarty->display('collection/index.tpl');
......
......@@ -35,7 +35,6 @@ define('SECTION_PAGE', 'views');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('collection.php');
define('TITLE', get_string('editviews', 'collection'));
// check that My Collections is enabled in the config
// if not as the user is trying to access this illegally
......@@ -43,26 +42,38 @@ if (!get_config('allowcollections')) {
die();
}
$new = param_integer('new',0);
$id = param_integer('id');
$newtxt = $new ? '&new=1' : '';
// view addition/displayorder values
$view = param_integer('view',0);
$direction = param_variable('direction','');
$collectionid = param_integer('id');
define('COLLECTION', $collectionid);
$data = get_record_select('collection', 'id = ?', array(COLLECTION), '*, ' . db_format_tsfield('ctime'));
$collection = new Collection(COLLECTION, (array)$data);
$data = get_record_select('collection', 'id = ?', array($id), '*');
$collection = new Collection($id, (array)$data);
if (!$USER->can_edit_collection($collection)) {
$SESSION->add_error_msg(get_string('canteditdontown'));
redirect('/collection/');
}
if (!$new) {
define('COLLECTION', $id);
define('TITLE', $collection->get('name') . ': ' . get_string('editviews', 'collection'));
}
else {
define('TITLE', get_string('editviews', 'collection'));
}
if ($view AND !empty($direction)) {
$collection->set_viewdisplayorder($view,$direction);
redirect('/collection/views.php?id='.COLLECTION);
redirect('/collection/views.php?id='.$id.$newtxt);
}
$views = $collection->views();
$elements = array();
$viewsform = null;
if ($available = Collection::available_views()) {
foreach ($available as $a) {
$elements['view_'.$a->id] = array(
......@@ -73,30 +84,47 @@ if ($available = Collection::available_views()) {
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('add','collection'),
'goto' => get_config('wwwroot') . 'collection/views.php?id='.COLLECTION,
'goto' => get_config('wwwroot') . 'collection/views.php?id='.$id,
);
$form = pieform(array(
$viewsform = pieform(array(
'name' => 'addviews',
'plugintype' => 'core',
'pluginname' => 'collection',
'autofocus' => false,
'successcallback' => 'submit',
'method' => 'post',
'elements' => $elements,
));
}
else {
$form = get_string('noviewstochoose','collection');
}
$smarty = smarty();
if ($new) {
$newform = pieform(array(
'name' => 'new',
'plugintype' => 'core',
'pluginname' => 'collection',
'autofocus' => false,
'method' => 'post',
'elements' => array(
'submit' => array(
'type' => 'cancelbackcreate',
'value' => array(get_string('cancel'), get_string('back','collection'), get_string('next') . ': ' . get_string('editaccess', 'collection')),
'confirm' => array(get_string('confirmcancelcreatingcollection', 'collection'), null, null),
),
),
));
$smarty->assign_by_ref('newform', $newform);
}
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->assign('displayurl',get_config('wwwroot').'collection/views.php?id='.$id.$newtxt);
$smarty->assign('removeurl',get_config('wwwroot').'collection/deleteview.php?id='.$id.$newtxt);
$smarty->assign_by_ref('views', $views);
$smarty->assign('form', $form);
$smarty->assign('addviews', get_string('addviews', 'collection'));
$smarty->assign_by_ref('viewsform', $viewsform);
$smarty->display('collection/views.tpl');
function submit(Pieform $form, $values) {
global $SESSION, $collection;
function addviews_submit(Pieform $form, $values) {
global $SESSION, $collection, $newurl;
$count = $collection->add_views($values);
if ($count > 1) {
$SESSION->add_ok_msg(get_string('viewsaddedtocollection', 'collection'));
......@@ -104,9 +132,24 @@ function submit(Pieform $form, $values) {
else {
$SESSION->add_ok_msg(get_string('viewaddedtocollection', 'collection'));
}
redirect('/collection/views.php?id='.$collection->get('id').$newurl);
}
redirect('/collection/views.php?id=' . $collection->get('id'));
function newcol_cancel_submit() {
global $collection;
$collection->delete();
redirect('/collection/');
}
function newcol_submit(Pieform $form, $values) {
global $collection;
if (param_boolean('back')) {
redirect('/collection/edit.php?id='.$collection->get('id').'&new=1');
}
else {
redirect('/collection/access.php?id='.$collection->get('id').'&new=1');
}
}
?>
......@@ -40,25 +40,29 @@ $string['accessignored'] = 'Some secret URL access types were ignored.';
$string['add'] = 'Add';
$string['addview'] = 'Add view';
$string['addviews'] = 'Add views to collection';
$string['back'] = 'Back';
$string['collection'] = 'Collection';
$string['collectionaccess'] = 'Collection access';
$string['collectionconfirmdelete'] = 'Are you sure you wish to delete this collection?';
$string['collections'] = 'Collections';
$string['collectiondeleted'] = 'Collection deleted successfully.';
$string['collectionsaved'] = 'Collection saved successfully.';
$string['confirmcancelcreatingcollection'] = 'This Collection has not been completed. Do you really want to cancel?';
$string['created'] = 'Created';
$string['currentmaster'] = 'Current master';
$string['deletecollection'] = 'Delete collection';