Commit 81d40d0e authored by Nigel McNie's avatar Nigel McNie
Browse files

Merge branch 'viewartefactsplit'

Conflicts:

	htdocs/view/view.php
parents 76f75b88 a47577b2
......@@ -19,7 +19,7 @@
{foreach from=$children item=child}
<tr class="{cycle values=r1,r0}">
<td><img src="{$child->iconsrc}" border="0" alt="{$child->artefacttype|escape}"></td>
<td><a href="{$WWWROOT}view/view.php?id={$viewid|escape}&amp;artefact={$child->id|escape}">{$child->title}</a></td>
<td><a href="{$WWWROOT}view/artefact.php?artefact={$child->id|escape}&amp;view={$viewid|escape}">{$child->title}</a></td>
<td>{$child->description}</td>
<td>{$child->date}</td>
</tr>
......
......@@ -370,8 +370,8 @@ class BlockInstance {
// block to be a link to view more information about that artefact
$configdata = $this->get('configdata');
if (!empty($configdata['artefactid'])) {
$smarty->assign('viewartefacturl', get_config('wwwroot') . 'view/view.php?id='
. $this->get('view') . '&artefact=' . $configdata['artefactid']);
$smarty->assign('viewartefacturl', get_config('wwwroot') . 'view/artefact.php?artefact='
. $configdata['artefactid'] . '&view=' . $this->get('view'));
}
$smarty->assign('content', $content);
......
......@@ -27,9 +27,9 @@
defined('INTERNAL') || die();
$string['createview'] = 'Create View';
$string['editview'] = 'Edit View';
$string['editaccess'] = 'Edit View Access';
$string['editblocks'] = 'Edit blocks';
$string['editview'] = 'Edit Details for View "%s"';
$string['editaccessforview'] = 'Edit View Access for View "%s"';
$string['editblocksforview'] = 'Edit Blocks for View "%s"';
$string['next'] = 'Next';
$string['back'] = 'Back';
$string['createview'] = 'Create View';
......@@ -39,8 +39,11 @@ $string['startdate'] = 'Access Start Date/Time';
$string['stopdate'] = 'Access End Date/Time';
$string['startdatemustbebeforestopdate'] = 'The start date must be before the stop date';
$string['ownerformat'] = 'Name display format';
$string['ownerformatdescription'] = 'This field controls what appears in the author field for the template you select in step 2';
$string['ownerformatdescription'] = 'How do you want people who look at your view to see your name?';
$string['editaccesspagedescription'] = '<p>You can control who can see your view, and when they can do so. By default, only you can see your views.</p>
<p>You can grant access to your view to your friends, all logged in users, or only to the certain users and groups you choose.</p>
<p>All dates are optional. If you wish, you can use them to restrict the time in which people can see your view.</p>';
$string['emptylabel'] = 'Click here to enter text for this label';
$string['empty_block'] = 'Select an artefact from the tree on the left to place here';
......@@ -100,7 +103,8 @@ $string['viewlayoutdescription'] = 'You can change the widths of the columns in
$string['changeviewlayout'] = 'Change view layout';
$string['backtoyourview'] = 'Back to your view';
$string['titleformatted'] = '%s by %s';
$string['by'] = 'by';
$string['in'] = 'in';
$string['noblocks'] = 'Sorry, no blocks in this category :(';
$string['50,50'] = $string['33,33,33'] = $string['25,25,25,25'] = 'Equal widths';
......
......@@ -45,7 +45,6 @@ class View {
private $friendsonly;
private $artefact_instances;
private $artefact_metadata;
private $artefact_hierarchy;
private $ownerobj;
private $numcolumns;
private $layout;
......@@ -194,46 +193,6 @@ class View {
return $this->artefact_metadata;
}
public function get_artefact_hierarchy() {
if (isset($this->artefact_hierarchy)) {
return $this->artefact_hierarchy;
}
if (!$artefacts = $this->get_artefact_metadata()) {
return array();
}
$this->artefact_hierarchy = array('data' => array(),
'refs' => array());
$sql = 'SELECT a.*,a.parent,pc.parent,a.artefacttype
FROM {artefact} a
JOIN (
SELECT apc1.*
FROM {artefact_parent_cache} apc1
JOIN {artefact_parent_cache} apc2 ON apc1.artefact = apc2.artefact
WHERE apc2.parent IN (
SELECT artefact FROM {view_artefact} where view = ?
)
) pc ON pc.artefact = a.id
UNION SELECT a2.*,a2.parent,null,a2.artefacttype
FROM {artefact} a2
JOIN {view_artefact} va ON va.artefact = a2.id
WHERE va.id = ?';
$allchildren = get_records_sql_array($sql, array($this->id, $this->id));
foreach ($artefacts as $toplevel) {
$a = array();
$a['artefact'] = $toplevel;
$a['children'] = $this->find_artefact_children($toplevel,
$allchildren, $this->artefact_hierarchy['refs']);
$this->artefact_hierarchy['data'][$toplevel->id] = $a;
$this->artefact_hierarchy['refs'][$toplevel->id] = $toplevel;
}
return $this->artefact_hierarchy;
}
public function find_artefact_children($artefact, $allchildren, &$refs) {
$children = array();
......
......@@ -238,7 +238,6 @@ addLoadEvent(function () {
var accesslist = {{$accesslist}};
if (accesslist) {
forEach(accesslist, function(item) {
log(item);
renderAccessListItem(item);
});
}
......
{include file="header.tpl"}
{include file="columnfullstart.tpl"}
<h2>{str tag=editaccess section=view}</h2>
<h2>{$pagetitle}</h2>
{str tag=editaccesspagedescription section=view}
{$form}
{include file="columnfullend.tpl"}
......
{include file="header.tpl"}
{include file="columnfullstart.tpl"}
<h3><a href="{$WWWROOT}view/view.php?id={$viewid|escape}">{$viewtitle|escape}</a> {str tag=by section=view} <a href="{$WWWROOT}user/view.php?id={$viewowner}">{$formattedowner|escape}</a>: {foreach name=path from=$artefactpath item=path}{if $path.url}<a href="{$path.url|escape}">{/if}{$path.title|escape}{if $path.url}</a>{/if}{if !$smarty.foreach.path.last}: {/if}{/foreach}</h3>
<div id="view">
<div id="bottom-pane">
<div id="column-container">
{$artefact}
</div>
</div>
</div>
<div id="publicfeedback">
<table id="feedbacktable">
<thead>
<tr><th colspan=5>{str tag=feedback}</th></tr>
</thead>
</table>
</div>
<div id="viewmenu"></div>
{include file="columnfullend.tpl"}
{include file="footer.tpl"}
......@@ -9,28 +9,17 @@
</div>
{/if}
<div id="view">
<h3>
{foreach name=viewnav from=$VIEWNAV item=item}
{$item}
{if !$smarty.foreach.viewnav.last}
:
{/if}
{/foreach}
</h3>
<h3>{$viewtitle|escape} {str tag=by section=view} <a href="{$WWWROOT}user/view.php?id={$viewowner}">{$formattedowner|escape}</a></h3>
{if $DESCRIPTION}
<p class="view-description">{$DESCRIPTION}</p>
{/if}
<p class="view-description">{$viewdescription}</p>
<div id="bottom-pane">
<div id="column-container">
{if $VIEWCONTENT}
{$VIEWCONTENT}
{/if}
<div class="cb">
</div>
<div id="bottom-pane">
<div id="column-container">
{$viewcontent}
<div class="cb">
</div>
</div>
</div>
<div id="publicfeedback">
<table id="feedbacktable">
<thead>
......
......@@ -31,15 +31,16 @@ define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'editaccess');
require(dirname(dirname(__FILE__)) . '/init.php');
define('TITLE', get_string('editaccess', 'view'));
require_once('pieforms/pieform.php');
require_once('pieforms/pieform/elements/calendar.php');
require_once(get_config('docroot') . 'lib/view.php');
$smarty = smarty(array('tablerenderer'), pieform_element_calendar_get_headdata(pieform_element_calendar_configure(array())), array('mahara' => array('From', 'To')));
$view = new View(param_integer('id'));
define('TITLE', get_string('editaccessforview', 'view', $view->get('title')));
$new = param_boolean('new');
$smarty = smarty(array('tablerenderer'), pieform_element_calendar_get_headdata(pieform_element_calendar_configure(array())), array('mahara' => array('From', 'To')));
$artefacts = $view->get_artefact_metadata();
if (empty($artefacts)) {
$confirmmessage = get_string('reallyaddaccesstoemptyview');
......@@ -104,6 +105,7 @@ function editaccess_submit(Pieform $form, $values) {
}
$smarty->assign('pagetitle', TITLE);
$smarty->assign('form', pieform($form));
$smarty->display('view/access.tpl');
......
<?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('PUBLIC', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require(get_config('libroot') . 'view.php');
$artefactid = param_integer('artefact');
$viewid = param_integer('view');
$path = param_variable('path', null);
$view = new View($viewid);
if (!can_view_view($viewid)) {
throw new AccessDeniedException();
}
if (!artefact_in_view($artefactid, $viewid)) {
throw new AccessDeniedException("Artefact $artefactid not in View $viewid");
}
require_once(get_config('docroot') . 'artefact/lib.php');
$artefact = artefact_instance_from_id($artefactid);
define('TITLE', $artefact->get('title') . ' ' . get_string('in', 'view') . ' ' . $view->get('title'));
// Render the artefact
$options = array('viewid' => $viewid,
'path' => $path);
$rendered = $artefact->render_self($options);
$content = '';
if (!empty($rendered['javascript'])) {
$content = '<script type="text/javascript">' . $rendered['javascript'] . '</script>';
}
$content .= $rendered['html'];
// Build the path to the artefact, through its parents
$artefactpath = array();
$parent = $artefact->get('parent');
while ($parent !== null) {
// This loop could get expensive when there are a lot of parents. But at least
// it works, unlike the old attempt
$artefactdata = get_record('artefact', 'id', $parent);
if (artefact_in_view($parent, $viewid)) {
array_unshift($artefactpath, array(
'url' => get_config('wwwroot') . 'view/artefact.php?artefact=' . $parent . '&view=' . $viewid,
'title' => $artefactdata->title,
));
}
$parent = $artefactdata->parent;
}
$artefactpath[] = array(
'url' => '',
'title' => $artefact->get('title'),
);
$tutorfilefeedbackformrow = '';
$submittedgroup = $view->get('submittedto');
if ($submittedgroup
&& record_exists('group_member',
'group', $submittedgroup,
'member', $USER->get('id'),
'tutor', 1)) {
// The user is a tutor of the group that this view has
// been submitted to, and is entitled to upload an additional
// file when submitting feedback.
$tutorfilefeedbackformrow = "TR(null, TH(null, LABEL(null, '" . get_string('attachfile') . "'))),"
. "TR(null, TD(null, INPUT({'type':'file', 'name':'attachment'}))),";
}
$getstring = quotestrings(array('mahara' => array(
'message', 'makepublic', 'placefeedback', 'cancel', 'complaint',
'feedbackonthisartefactwillbeprivate', 'notifysiteadministrator',
'nopublicfeedback', 'reportobjectionablematerial', 'print',
)));
$getstring['feedbackattachmessage'] = "'(" . get_string('feedbackattachmessage', 'mahara', get_string('feedbackattachdirname')) . ")'";
// Safari doesn't seem to like these inputs to be called 'public', so call them 'ispublic' instead.
$feedbackisprivate = !$artefact->public_feedback_allowed();
if (!empty($feedbackisprivate)) {
$makepublic = "TR(null, INPUT({'type':'hidden','name':'ispublic','value':'false'}), TD({'colspan':2}, "
. $getstring['feedbackonthisartefactwillbeprivate'] . ")),";
}
else {
$makepublic = "TR(null, TH(null, LABEL(null, " . $getstring['makepublic'] . " ), "
. "INPUT({'type':'checkbox', 'class':'checkbox', 'name':'ispublic'}))),";
}
$javascript = <<<EOF
var view = {$viewid};
var artefact = {$artefactid};
function feedbackform() {
if ($('menuform')) {
removeElement('menuform');
}
var form = FORM({'id':'menuform','method':'post'});
submitfeedback = function () {
if (form.attachment && form.attachment.value) {
updateNodeAttributes(form, {'enctype':'multipart/form-data',
'encoding':'multipart/form-data',
'action':'feedbackattachment.php', 'target':''});
appendChildNodes(form, INPUT({'type':'hidden', 'name':'view', 'value':view}));
appendChildNodes(form, INPUT({'type':'hidden', 'name':'filename',
'value':basename(form.attachment.value)}));
form.submit();
}
else {
var data = {'view':view,
'public':form.ispublic.checked,
'message':form.message.value};
if (artefact) {
data.artefact = artefact;
}
sendjsonrequest('addfeedback.json.php', data, 'POST', function () {
removeElement('menuform');
feedbacklist.doupdate();
});
return false;
}
}
appendChildNodes(form,
TABLE({'border':0, 'cellspacing':0, 'id':'feedback'},
TBODY(null,
TR(null, TH(null, LABEL(null, {$getstring['message']}))),
TR(null, TD(null, TEXTAREA({'rows':5, 'cols':80, 'name':'message'}))),
{$makepublic}
{$tutorfilefeedbackformrow}
TR(null, TD(null,
INPUT({'type':'button', 'class':'button',
'value':{$getstring['placefeedback']},
'onclick':'submitfeedback();'}),
INPUT({'type':'button', 'class':'button', 'value':{$getstring['cancel']},
'onclick':"removeElement('menuform');"}))))));
appendChildNodes('viewmenu', DIV(null, form));
form.message.focus();
return false;
}
function objectionform() {
if ($('menuform')) {
removeElement('menuform');
}
var form = FORM({'id':'menuform','method':'post'});
submitobjection = function () {
var data = {'view':view, 'message':form.message.value};
if (artefact) {
data.artefact = artefact;
}
sendjsonrequest('objectionable.json.php', data, 'POST', function () { removeElement('menuform'); });
return false;
}
appendChildNodes(form,
TABLE({'border':0, 'cellspacing':0, 'id':'objection'},
TBODY(null,
TR(null, TH(null, LABEL(null, {$getstring['complaint']}))),
TR(null, TD(null, TEXTAREA({'rows':5, 'cols':80, 'name':'message'}))),
TR(null, TD(null,
INPUT({'type':'button', 'class':'button',
'value':{$getstring['notifysiteadministrator']},
'onclick':'submitobjection();'}),
INPUT({'type':'button', 'class':'button', 'value':{$getstring['cancel']},
'onclick':"removeElement('menuform');"}))))));
appendChildNodes('viewmenu', DIV(null, form));
form.message.focus();
return false;
}
function view_menu() {
if (config.loggedin) {
appendChildNodes('viewmenu',
A({'href':'', 'onclick':"return feedbackform();"},
{$getstring['placefeedback']}), ' | ',
A({'href':'', 'onclick':'return objectionform();'},
{$getstring['reportobjectionablematerial']}), ' | '
);
}
appendChildNodes('viewmenu',
A({'href':'', 'onclick':'window.print();return false;'},
{$getstring['print']})
);
}
addLoadEvent(view_menu);
// The list of existing feedback.
var feedbacklist = new TableRenderer(
'feedbacktable',
'getfeedback.json.php',
[
function (r) {
var td = TD(null);
td.innerHTML = r.message;
if (r.attachid && r.ownedbythisuser) {
appendChildNodes(td, DIV(null, {$getstring['feedbackattachmessage']}));
return td;
}
return td;
},
'name',
'date',
function (r) {
if (r.ispublic == 1) {
var makePrivate = null;
if (r.ownedbythisuser) {
makePrivate = A({'href': ''}, get_string('makeprivate'));
connect(makePrivate, 'onclick', function (e) {
sendjsonrequest(
'changefeedback.json.php',
r,
'POST',
function (data) {
if (!data.error) {
replaceChildNodes(makePrivate.parentNode, '(' + get_string('private') + ')');
}
}
);
e.stop();
});
}
return TD(null, '(' + get_string('public') + ') ', makePrivate);
}
return TD(null, '(' + get_string('private') + ')');
},
function (r) {
if (r.attachid) {
return TD(null, A({'href':config.wwwroot + 'artefact/file/download.php?file=' + r.attachid},
r.attachtitle));
}
return TD(null);
}
]
);
feedbacklist.limit = 10;
feedbacklist.view = view;
feedbacklist.artefact = artefact;
feedbacklist.statevars.push('view','artefact');
feedbacklist.emptycontent = {$getstring['nopublicfeedback']};
feedbacklist.updateOnLoad();
EOF;
$smarty = smarty(
array('tablerenderer'),
array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'),
array(
'mahara' => array(
'public',
'private',
'makeprivate',
),
),
array(
'stylesheets' => array('style/views.css')
)
);
$smarty->assign('artefact', $content);
$smarty->assign('artefactpath', $artefactpath);
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('viewid', $viewid);
$smarty->assign('viewowner', $view->get('owner'));
$smarty->assign('viewtitle', $view->get('title'));
$smarty->assign('formattedowner', $view->formatted_owner());
$smarty->display('view/artefact.tpl');
?>
......@@ -28,9 +28,9 @@ define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/views');
require(dirname(dirname(__FILE__)) . '/init.php');
require('view.php');
define('TITLE', get_string('editblocks', 'view'));
$view = new View(param_integer('id'));
define('TITLE', get_string('editblocksforview', 'view', $view->get('title')));
$new = param_boolean('new');
$category = param_alpha('c', '');
......
......@@ -42,11 +42,11 @@ if (empty($id)) {
$new = true;
}
else {
define('TITLE', get_string('editview', 'view'));
$view = new View($id);
if ($view->get('owner') != $USER->get('id')) {
throw new AccessDeniedException(get_string('canteditdontown', 'view'));
}
define('TITLE', get_string('editview', 'view', $view->get('title')));
}
$heading = TITLE; // for the smarty template
......
......@@ -106,7 +106,7 @@ function assessselect(viewid, grouplist) {
}
function renderartefact(viewid,a) {
var link = A({'href':'{$wwwroot}view/view.php?id='+viewid+'&artefact='+a.id});
var link = A({'href':'{$wwwroot}view/artefact.php?artefact='+a.id+'&view='+viewid});
link.innerHTML = a.title;
return LI(null,link);
}
......
......@@ -29,106 +29,28 @@ define('PUBLIC', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require(get_config('libroot') . 'view.php');
// TODO for 1.0 - remove 'view' as an allowed value for this
$viewid = param_integer('id', 0);
if (!$viewid) {
$viewid = param_integer('view');
log_info('view/view.php accessed with view parameter instead of ID. If this was because of a link internal to mahara, please change it!');
}
$artefactid = param_integer('artefact', null);
$path = param_variable('path', null);
$viewid = param_integer('id');
$view = new View($viewid);
if (!can_view_view($viewid)) {
throw new AccessDeniedException();
}
$viewbeingwatched = 0;
$title = get_string('titleformatted', 'view', $view->get('title'), $view->formatted_owner());
define('TITLE', $title);
$description = '';
if ($artefactid) {
if (!artefact_in_view($artefactid, $viewid)) {
throw new AccessDeniedException("Artefact $artefactid not in View $viewid");
}
require_once(get_config('docroot') . 'artefact/lib.php');
$artefact = artefact_instance_from_id($artefactid);
$feedbackisprivate = !$artefact->public_feedback_allowed();
$options = array('viewid' => $viewid,
'path' => $path);
$rendered = $artefact->render_self($options);
$content = '';
if (!empty($rendered['javascript'])) {
$content = '<script type="text/javascript">' . $rendered['javascript'] . '</script>';
}
$content .= $rendered['html'];
$viewhref = 'view.php?id=' . $viewid;
$navlist = array('<a href="' . $viewhref . '">' . $title . '</a>');
if (!empty($path)) {
$titles = get_records_sql_assoc('
SELECT id,title FROM {artefact}
WHERE id IN (' . $path . ')','');
$artefactids = split(',', $path);