/** * Copy a view via a 'copy' url * Currently for copying a page via a 'copy' button on view/view.php * * @param integer $id View id * @param bool $istemplate (optional) If you want to mark as template * @param integer $groupid (optional) The group to copy the view to * @param integer $collectionid (optional) Provide the collection id to indicate we want * to copy collection the view belongs to */ function copyview($id, $istemplate = false, $groupid = null, $collectionid = null) { global $USER, $SESSION; // check that the user can copy view $view = new View($id); if (!$view->is_copyable()) { throw new AccessDeniedException(get_string('thisviewmaynotbecopied', 'view')); } // set up a packet of values to send to the create_from_template function $values = array('new' => 1, 'owner' => $USER->get('id'), 'template' => (int) $istemplate); if (!empty($groupid) && is_int($groupid)) { $values['group'] = $groupid; } if (!empty($collectionid)) { require_once get_config('libroot') . 'collection.php'; list($collection, $template, $copystatus) = Collection::create_from_template($values, $collectionid); if (isset($copystatus['quotaexceeded'])) { $SESSION->add_error_msg(get_string('collectioncopywouldexceedquota', 'collection')); redirect(get_config('wwwroot') . 'view/view.php?id=' . $id); } $SESSION->add_ok_msg(get_string('copiedpagesblocksandartefactsfromtemplate', 'collection', $copystatus['pages'], $copystatus['blocks'], $copystatus['artefacts'], $template->get('name'))); redirect(get_config('wwwroot') . 'collection/edit.php?copy=1&id=' . $collection->get('id')); } else { list($view, $template, $copystatus) = View::create_from_template($values, $id); if (isset($copystatus['quotaexceeded'])) { $SESSION->add_error_msg(get_string('viewcopywouldexceedquota', 'view')); redirect(get_config('wwwroot') . 'view/view.php?id=' . $id); } $SESSION->add_ok_msg(get_string('copiedblocksandartefactsfromtemplate', 'view', $copystatus['blocks'], $copystatus['artefacts'], $template->get('title'))); redirect(get_config('wwwroot') . 'view/edit.php?new=1&id=' . $view->get('id')); } }
<?php /** * * @package mahara * @subpackage core * @author Catalyst IT Ltd * @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. * */ define('INTERNAL', 1); define('SECTION_PLUGINTYPE', 'core'); define('SECTION_PLUGINNAME', 'view'); define('SECTION_PAGE', 'copy'); require dirname(dirname(__FILE__)) . '/init.php'; require_once get_config('libroot') . 'view.php'; require_once get_config('libroot') . 'group.php'; $viewid = param_integer('id'); $collection = param_integer('collection', null); $groupid = param_integer('group', null); $view = new View($viewid); if (!$view->is_copyable()) { throw new AccessDeniedException(get_string('thisviewmaynotbecopied', 'view')); } copyview($view->get('id'), 0, $groupid, $collection);