Commit 36d6fca3 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files
parents 2f07a1a8 f4879556
<?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 artefact-file
* @author Richard Mansfield <richard.mansfield@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);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
try {
$fileid = param_integer('id');
}
catch (ParameterException $e) {
json_reply('missingparameter',get_string('missingparameter'));
}
$prefix = get_config('dbprefix');
$filerecord = get_record_sql('SELECT a.artefacttype, a.owner, f.name
FROM ' . $prefix . 'artefact a
JOIN ' . $prefix . 'artefact_file_files f ON a.id = f.artefact
WHERE a.id = ' . $fileid);
if ($filerecord->owner != $USER->get('id')) {
json_reply('local',get_string('notowner'));
}
if (count_records('artefact', 'parent', $fileid) > 0) {
json_reply('local', get_string('artefacthaschildren'));
}
if (!delete_records('artefact_file_files', 'artefact', $fileid)) {
json_reply('local', get_string('deletefailed'));
}
if (!delete_records('artefact', 'id', $fileid)) {
json_reply('local', get_string('deletefailed'));
}
// @todo: Delete the file from the filesystem here
json_reply(false, get_string('filedeleted'));
?>
......@@ -43,7 +43,8 @@ MochiKit.MochiKit.SUBMODULES = [
"Color",
"Signal",
"Position",
"Visual"
"Visual",
"DragAndDrop"
];
if (typeof(JSAN) != 'undefined' || typeof(dojo) != 'undefined') {
......
......@@ -36,14 +36,27 @@ if (typeof(MochiKit.Selector) == 'undefined') {
}
MochiKit.Selector.NAME = "MochiKit.Selector";
MochiKit.Selector.VERSION = "1.4";
MochiKit.Selector.__repr__ = function () {
return "[" + this.NAME + " " + this.VERSION + "]";
};
MochiKit.Selector.toString = function () {
return this.__repr__();
};
MochiKit.Selector.EXPORT = [
"Selector",
"findChildElements",
"findDocElements",
"$$"
];
MochiKit.Selector.EXPORT_OK = [
];
MochiKit.Selector.Selector = function (expression) {
this.params = {classNames: [], pseudoClassNames: []};
this.expression = expression.toString().replace(/(^\s+|\s+$)/g, '');
......@@ -69,6 +82,7 @@ MochiKit.Selector.Selector.prototype = {
abort('empty expression');
}
var repr = MochiKit.Base.repr;
var params = this.params;
var expr = this.expression;
var match, modifier, clause, rest;
......@@ -113,6 +127,7 @@ MochiKit.Selector.Selector.prototype = {
/** @id MochiKit.Selector.Selector.prototype.buildMatchExpression */
buildMatchExpression: function () {
var repr = MochiKit.Base.repr;
var params = this.params;
var conditions = [];
var clause, i;
......@@ -390,11 +405,27 @@ MochiKit.Base.update(MochiKit.Selector, {
}
}, expression.replace(/(^\s+|\s+$)/g, '').split(/\s+/), [null]);
}, expressions));
}
},
findDocElements: function () {
return MochiKit.Selector.findChildElements(MochiKit.DOM.currentDocument(), arguments);
},
__new__: function () {
var m = MochiKit.Base;
this.$$ = this.findDocElements;
this.EXPORT_TAGS = {
":common": this.EXPORT,
":all": m.concat(this.EXPORT, this.EXPORT_OK)
};
m.nameFunctions(this);
}
});
function $$() {
return MochiKit.Selector.findChildElements(MochiKit.DOM.currentDocument(), arguments);
}
MochiKit.Selector.__new__();
MochiKit.Base._exportSymbols(this, MochiKit.Selector);
......@@ -175,7 +175,7 @@ MochiKit.Base.update(MochiKit.Style, {
var self = MochiKit.Style;
if (o == 1) {
var toSet = /Gecko/.test(navigator.userAgent) && !(/Konqueror|Safari|KHTML/.test(navigator.userAgent));
elem.style[name] = toSet ? 0.999999 : 1.0;
elem.style["opacity"] = toSet ? 0.999999 : 1.0;
if (/MSIE/.test(navigator.userAgent)) {
elem.style['filter'] =
self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '');
......@@ -184,7 +184,7 @@ MochiKit.Base.update(MochiKit.Style, {
if (o < 0.00001) {
o = 0;
}
elem.style[name] = o;
elem.style["opacity"] = o;
if (/MSIE/.test(navigator.userAgent)) {
elem.style['filter'] =
self.getStyle(elem, 'filter').replace(/alpha\([^\)]*\)/gi, '') + 'alpha(opacity=' + o * 100 + ')';
......
......@@ -254,3 +254,15 @@ function toggleChecked(c) {
return false;
}
function expandDownToViewport(element, width) {
var viewport = getViewportDimensions();
var position = getElementPosition(element);
var newheight = new Dimensions(width, viewport.h - position.y - 2);
if ($('footer')) {
newheight.h -= getElementDimensions('footer').h + 8;
}
setElementDimensions(element, newheight);
}
......@@ -32,14 +32,18 @@ $id = param_integer('id');
$artefact = artefact_instance_from_id($id);
$renderedartefact = $artefact->render(FORMAT_ARTEFACT_LISTSELF, null);
log_debug($renderedartefact);
if (!$renderedartefact) {
json_reply('local', 'artefactnotrendered');
}
$result = array(
'data' => $renderedartefact,
'error' => false,
'message' => '',
'message' => 'artefactrendered',
);
log_debug($result);
json_headers();
print json_encode($result);
......
......@@ -73,6 +73,15 @@ function handle_activity($activitytype, $data) {
if (empty($data->message)) {
throw new InvalidArgumentException("message was empty for $activitytype!");
}
if (is_string($activitytype)) {
$activitytype = get_record('activity_type', 'name', $activitytype);
}
if (!is_object($activitytype)) {
throw new InvalidArgumentException("Invalid activitytype $activitytype");
}
$users = array();
$prefix = get_config('dbprefix');
......@@ -87,55 +96,78 @@ function handle_activity($activitytype, $data) {
break;
case 'usermessage':
$users = activity_get_users($activitytype->name, array($data->userto));
if (empty($data->url)) {
// @todo when user messaging is implemented, this might change...
$data->url = get_config('wwwroot') . 'user/view.php?id=' . $data->userfrom;
}
break;
case 'feedback':
if ($data->view) {
if (empty($data->view)) {
throw new IllegalArgumentException("Feedback missing view id");
}
if (empty($data->artefact)) {
$userid = get_field('view', 'owner', 'id', $data->view);
if (empty($data->url)) {
// @todo this might change later
$data->url = get_config('wwwroot') . 'view/view.php?id=' . $data->view;
}
}
else if ($data->artefact) {
$userid = get_field('artefact', 'owner', 'id', $data->artefact);
if (empty($data->url)) {
// @todo this might change later
$data->url = get_config('wwwroot') . 'view/artefact.php?id='
. $data->artefact . '&view=' . $data->view;
}
}
$users = activity_get_users($activitytype->name, array($userid));
break;
// and now the harder ones
case 'watchlist':
if ($data->view) {
$sql = 'SELECT u.*, p.method
if (!empty($data->view)) {
$sql = 'SELECT u.*, p.method, CAST(? AS TEXT) AS url
FROM ' . $prefix . 'usr_watchlist_view wv
JOIN ' . $prefix . 'usr u
ON wa.user = u.id
JOIN ' . $prefix . 'usr_preference p
ON wv.usr = u.id
JOIN ' . $prefix . 'usr_activity_preference p
ON p.usr = u.id
WHERE pc.activity = ?
WHERE p.activity = ?
AND wv.view = ?
';
$users = get_records_sql_array($sql, array('watchlist', $data->view));
$users = get_records_sql_array($sql,
array(get_config('wwwroot') . 'view/view.php?id='
. $data->view, 'watchlist', $data->view));
}
else if ($data->artefact) {
$sql = 'SELECT DISTINCT u.*, p.method
else if (!empty($data->artefact)) {
$sql = 'SELECT DISTINCT u.*, p.method, ?||wa.view as url
FROM ' . $prefix . 'usr_watchlist_artefact wa
JOIN ' . $prefix . 'artefact_parent_cache pc
LEFT JOIN ' . $prefix . 'artefact_parent_cache pc
ON (pc.parent = wa.artefact OR pc.artefact = wa.artefact)
JOIN ' . $prefix . 'usr u
ON wa.user = u.id
JOIN ' . $prefix . 'usr_preference p
ON wa.usr = u.id
JOIN ' . $prefix . 'usr_activity_preference p
ON p.usr = u.id
WHERE pc.activity = ?
WHERE p.activity = ?
AND (pc.parent = ? OR wa.artefact = ?)
';
$users = get_records_sql_array($sql, array('watchlist', $data->artefact));
$users = get_records_sql_array($sql,
array(get_config('wwwroot') . 'view/artefact.php?id='
. $data->artefact . '&view=', 'watchlist',
$data->artefact, $data->artefact));
}
else if ($data->community) {
$sql = 'SELECT DISTINCT u.*, p.method
else if (!empty($data->community)) {
$sql = 'SELECT DISTINCT u.*, p.method, CAST(? AS TEXT) AS url
FROM ' . $prefix . 'usr_watchlist_community c
JOIN ' . $prefix . 'usr u
ON c.usr = u.id
JOIN ' . $prefix . 'usr_preference p
JOIN ' . $prefix . 'usr_activity_preference p
ON p.usr = u.id
WHERE pc.activity = ?
WHERE p.activity = ?
AND c.community = ?
';
$users = get_records_sql_array($sql, array('watchlist', $data->community));
$users = get_records_sql_array($sql,
array(get_config('wwwroot') . 'community/view.php?id='
. $data->community, 'watchlist', $data->community));
}
else {
throw new InvalidArgumentException("Invalid watchlist type");
......@@ -150,7 +182,7 @@ function handle_activity($activitytype, $data) {
WHERE (usr1 = ? OR usr2 = ?)
UNION SELECT member AS userid
FROM ' . $prefix . 'usr_group_member m
JOIN ' . $prefix . 'view_access_group g ON m.group = g.group
JOIN ' . $prefix . 'view_access_group g ON m.grp = g.grp
WHERE g.view = ?
UNION SELECT usr AS userid
FROM ' . $prefix . 'view_access_usr u
......@@ -161,11 +193,18 @@ function handle_activity($activitytype, $data) {
$users = get_records_sql_array($sql, array($data->owner, $data->owner, $data->owner,
$data->view, $data->view));
break;
// @todo more here (admin messages!)
}
}
if (empty($users)) {
return;
}
safe_require('notification', 'internal', 'lib.php', 'require_once');
$data->type = $activitytype;
$data->type = $activitytype->name;
foreach ($users as $user) {
if (!empty($user->url) && empty($data->url)) {
$data->url = $user->url;
}
if ($user->method != 'internal') {
safe_require('notification', $method, 'lib.php', 'require_once');
call_static_method(generate_class_name('notification', $method), 'notify_user', $user, $data);
......
......@@ -621,6 +621,40 @@
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_feedback">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="author" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="message" TYPE="text" NOTNULL="true" />
<FIELD NAME="attachment" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="public" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
<KEY NAME="authorfk" TYPE="foreign" FIELDS="author" REFTABLE="usr" REFFIELDS="id" />
<KEY NAME="attachmentfk" TYPE="foreign" FIELDS="attachment" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="artefact_feedback">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="artefact" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="author" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="message" TYPE="text" NOTNULL="false" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="public" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="artefactfk" TYPE="foreign" FIELDS="artefact" REFTABLE="artefact" REFFIELDS="id" />
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
<KEY NAME="authorfk" TYPE="foreign" FIELDS="author" REFTABLE="usr" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_access">
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
......@@ -714,12 +748,14 @@
<FIELDS>
<FIELD NAME="usr" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="artefact" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="usr,artefact" />
<KEY NAME="primary" TYPE="primary" FIELDS="usr,artefact,view" />
<KEY NAME="usrfk" TYPE="foreign" FIELDS="usr" REFTABLE="usr" REFFIELDS="id" />
<KEY NAME="artefactfk" TYPE="foreign" FIELDS="artefact" REFTABLE="artefact" REFFIELDS="id" />
<KEY NAME="viewfk" TYPE="foreign" FIELDS="view" REFTABLE="view" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="usr_watchlist_view">
......
......@@ -182,18 +182,89 @@ function template_locate($templatename, $fetchdb=true) {
*
* @param array $template a parsed template see {@link template_parse}
* @param mode either TEMPLATE_RENDER_READONLY or TEMPLATE_RENDER_EDITMODE
* @param array
*
* @returns string the html of the rendered template
*/
function template_render($template, $mode) {
$td = $template['parseddata'];
function template_render($template, $mode, $data=array()) {
if (isset($template['parseddata'])) {
$td = $template['parseddata'];
}
else {
$td = $template['cacheddata'];
}
$droplist = array();
$html = '';
foreach ($td as $t) {
if ($t['type'] == 'html') {
echo $t['content'];
$html .= $t['content'];
}
else {
// @todo call something depending on mode
if ($mode == TEMPLATE_RENDER_READONLY) {
$html .= 'READONLY';
}
else {
$t = $t['data'];
if ( isset($t['format']) && $t['format'] == 'label' ) {
$html .= '<input type="hidden" id=>';
}
else {
log_debug($t);
$classes = array('block');
#if ( $t['format'] == '
$droplist[$t['id']] = array('render_full');
// build opening div tag
if (isset($t['width']) && isset($t['height'])) {
$html .= '<div style="width: ' . $t['width'] . 'px;height: ' . $t['height'] . 'px;"';
}
else {
$html .= '<div';
}
$html .= ' id="' . $t['id'] . '"';
$html .= ' class="' . join(' ',$classes) . '"';
$html .= '>';
$html .= '<i>' . get_string('empty_block', 'view') . '</i>';
$html .= '</div>';
}
}
}
}
$droplist = json_encode($droplist);
$spinner_url = json_encode(theme_get_image_path('loading.gif'));
$wwwroot = get_config('wwwroot');
$javascript = <<<EOF
<script type="text/javascript">
var droplist = $droplist;
function blockdrop(element, target) {
replaceChildNodes(target, IMG({ src: {$spinner_url} }));
var d = loadJSONDoc({$wwwroot});
}
addLoadEvent(function () {
for ( id in droplist ) {
new Droppable(id, {
accept: droplist[id],
ondrop: blockdrop,
hoverclass: 'block_targetted',
activeclass: 'block_potential'
});
}
});
</script>
EOF;
return $javascript . $html;
}
?>
/*
* MARTYNS CREATEVIEW WIZARD STYLES
* these can be replaced with something similar that looks less suck
*/
div#tree, div#template {
margin-top: 20px;
}
div#tree {
overflow: auto;
float: left;
width: 400px;
border: thin dashed red;
border-right: thin solid #000;
}
div#template {
overflow: auto;
border: thin dashed red;
float: left;
width: 30%;
}
.render_metadata, .render_full, .render_listitem, .render_children {
cursor: move;
}
div.block {
border: 2px solid transparent;
}
div.block_potential {
border: 2px solid #008800;
}
div.block_targetted {
border: 2px solid #00ff00;
}
/*
* END MARTYNS STYLES FOR CREATEVIEW WIZARD
*/
This diff is collapsed.
div#tree, div#template {
border: thin dotted red;
}
div#tree {
overflow: auto;
float: left;
width: 400px;
}
div#template {
overflow: auto;
float: left;
width: 50%;
}
.render_metadata, .render_full, .render_listitem, .render_children {
cursor: move;
}
......@@ -15,6 +15,7 @@
{foreach from=$HEADERS item=header}{$header}{/foreach}
{/strip}
<link rel="stylesheet" type="text/css" href="{$THEMEURL}style/style.css">
<link rel="stylesheet" type="text/css" href="{$THEMEURL}style/dev.css">
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
</head>
<body>
......@@ -67,4 +68,4 @@
{/if}
{insert name="messages"}
\ No newline at end of file
......@@ -7,39 +7,67 @@ class="cnr-bl"><span class="cnr-br">
<h2>{str tag=createviewstep3}</h2>
<table border="1">
<tr>
<td><div id="tree">Artefact Tree</div></td>
<td>Template
<form action="" method="post">
<input type="submit" name="cancel" value="{str tag=cancel}">
<input type="submit" name="back" value="{str tag=back}">
<input type="submit" name="submit" value="{str tag=next}">
</form>
</td>
</tr>