Commit a97ffa86 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Merge branch 'master' into S_master

Conflicts:

	htdocs/artefact/blog/theme/default/render/blogpost_renderfull.tpl
parents a9ca3846 68984729
......@@ -78,8 +78,10 @@ $form['elements']['save'] = array(
'value' => get_string('save'),
);
$form = pieform($form);
$smarty = smarty();
$smarty->assign('form', pieform($form));
$smarty->assign('form', $form);
$smarty->assign('plugintype', $plugintype);
$smarty->assign('pluginname', $pluginname);
$smarty->assign('type', $type);
......
......@@ -35,17 +35,15 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
define('TITLE', get_string('sitefiles', 'admin'));
$javascript = ArtefactTypeFileBase::get_my_files_js(param_integer('folder', null));
$javascript .= <<<JS
browser.source += '?institution=mahara';
browser.createfolderscript += '?institution=mahara';
uploader.uploadscript += '?institution=mahara';
JS;
$form = pieform(ArtefactTypeFileBase::files_form(get_config('wwwroot') . 'admin/site/files.php', null, 'mahara'));
$js = ArtefactTypeFileBase::files_js();
$smarty = smarty(array('tablerenderer', 'artefact/file/js/file.js'));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty = smarty();
$smarty->assign('descriptionstrargs', array('<a href="' . get_config('wwwroot') . 'admin/site/menu.php">', '</a>'));
$smarty->assign('heading', get_string('sitefiles', 'admin'));
$smarty->display('admin/site/files.tpl');
$smarty->assign('institution', 'mahara');
$smarty->assign('form', $form);
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->display('artefact:file:files.tpl');
?>
......@@ -166,6 +166,20 @@ $siteoptionform = array(
'defaultvalue' => get_config('registration_sendweeklyupdates'),
'help' => true,
),
'institutionexpirynotification' => array(
'type' => 'expiry',
'title' => get_string('institutionexpirynotification', 'admin'),
'description' => get_string('institutionexpirynotificationdescription', 'admin'),
'defaultvalue' => is_null(get_config('institutionexpirynotification')) ? '2592000' : get_config('institutionexpirynotification'),
'help' => true,
),
'institutionautosuspend' => array(
'type' => 'checkbox',
'title' => get_string('institutionautosuspend', 'admin'),
'description' => get_string('institutionautosuspenddescription', 'admin'),
'defaultvalue' => get_config('institutionautosuspend'),
'help' => true,
),
)
);
......@@ -187,7 +201,7 @@ function siteoptions_submit(Pieform $form, $values) {
$fields = array('sitename','lang','theme', 'pathtoclam',
'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
'allowpublicviews', 'allowpublicprofiles', 'createpublicgroups', 'searchplugin',
'registration_sendweeklyupdates');
'registration_sendweeklyupdates', 'institutionexpirynotification', 'institutionautosuspend');
$oldlanguage = get_config('lang');
$oldtheme = get_config('theme');
foreach ($fields as $field) {
......
......@@ -35,7 +35,11 @@ require(dirname(dirname(dirname(__FILE__))).'/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('editsitepages', 'admin'));
$sitepages = get_records_array('site_content');
$sitepages = array();
$sitepagenames = site_content_pages();
if ($sitepagenames) {
$sitepages = get_records_select_array('site_content', 'name IN (' . join(',', array_map('db_quote', $sitepagenames)) . ')');
}
$pageoptions = array();
foreach ($sitepages as $page) {
$pageoptions[$page->name] = get_string($page->name, 'admin');
......
......@@ -259,7 +259,6 @@ else {
// unique
$suspendform = pieform($suspendformdef);
$suspendformdef['name'] = 'edituser_suspend2';
$suspendformdef['validatecallback'] = 'edituser_unsuspend_validate';
$suspendformdef['successcallback'] = 'edituser_unsuspend_submit';
$suspendform2 = pieform($suspendformdef);
......@@ -341,7 +340,7 @@ foreach ($user->get('institutions') as $i) {
'description' => get_string('membershipexpirydescription', 'admin'),
'minyear' => $currentdate['year'],
'maxyear' => $currentdate['year'] + 20,
'defaultvalue' => $i->expiry
'defaultvalue' => $i->membership_expiry
),
$i->institution.'_studentid' => array(
'type' => 'text',
......
......@@ -123,7 +123,7 @@ if ($institution || $add) {
if (!$add) {
$data = get_record('institution', 'name', $institution);
$lockedprofilefields = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
// TODO: Find a better way to work around Smarty's minimal looping logic
if (!empty($authinstances)) {
foreach($authinstances as $key => $val) {
......@@ -146,6 +146,7 @@ if ($institution || $add) {
else {
$data = new StdClass;
$data->displayname = '';
$data->expiry = null;
if (!get_config('usersuniquebyusername')) {
$data->registerallowed = 1;
}
......@@ -159,7 +160,9 @@ if ($institution || $add) {
$themeoptions = get_themes();
$themeoptions['sitedefault'] = '- ' . get_string('sitedefault', 'admin') . ' (' . $themeoptions[get_config('theme')] . ') -';
uksort($themeoptions, 'theme_sort');
$sitename = get_config('sitename');
safe_require('artefact', 'internal');
$elements = array(
'name' => array(
......@@ -199,6 +202,15 @@ if ($institution || $add) {
),
'help' => true,
),
'expiry' => array(
'type' => 'date',
'title' => get_string('institutionexpiry', 'admin'),
'description' => get_string('institutionexpirydescription', 'admin', $sitename),
'defaultvalue' => is_null($data->expiry) ? null : strtotime($data->expiry),
'help' => true,
'minyear' => date('Y') - 2,
'maxyear' => date('Y') + 10,
),
);
if ($USER->get('admin')) {
......@@ -321,6 +333,7 @@ else {
ii.name,
ii.displayname,
ii.maxuseraccounts,
ii.suspended,
COALESCE(a.members, 0) AS members,
COALESCE(a.staff, 0) AS staff,
COALESCE(a.admins, 0) AS admins
......@@ -366,6 +379,7 @@ function institution_submit(Pieform $form, $values) {
}
$newinstitution->displayname = $values['displayname'];
$newinstitution->expiry = db_format_timestamp($values['expiry']);
$newinstitution->authplugin = empty($values['authplugin']) ? null : $values['authplugin'];
if (get_config('usersuniquebyusername')) {
// Registering absolutely not allowed when this setting is on, it's a
......@@ -475,6 +489,91 @@ function institution_cancel_submit() {
redirect('/admin/users/institutions.php');
}
if ($institution) {
function institution_suspend_submit(Pieform $form, $values) {
global $SESSION, $USER;
if (!$USER->get('admin')) {
$SESSION->add_error_msg(get_string('errorwhilesuspending', 'admin'));
}
else {
set_field('institution', 'suspended', 1, 'name', $values['i']);
$SESSION->add_ok_msg(get_string('institutionsuspended', 'admin'));
}
redirect('/admin/users/institutions.php?i=' . $values['i']);
}
function institution_unsuspend_submit(Pieform $form, $values) {
global $SESSION, $USER;
if (!$USER->get('admin')) {
$SESSION->add_error_msg(get_string('errorwhileunsuspending', 'admin'));
}
else {
set_field('institution', 'suspended', 0, 'name', $values['i']);
$SESSION->add_ok_msg(get_string('institutionunsuspended', 'admin'));
}
redirect('/admin/users/institutions.php?i=' . $values['i']);
}
$_institution = get_record('institution', 'name', $institution);
// Suspension controls
$suspended = $_institution->suspended;
if (empty($suspended)) {
$suspendformdef = array(
'name' => 'institution_suspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'i' => array(
'type' => 'hidden',
'value' => $institution,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('suspendinstitution','admin'),
'description' => get_string('suspendinstitutiondescription','admin'),
),
)
);
$suspendform = pieform($suspendformdef);
}
else {
$suspendformdef = array(
'name' => 'institution_unsuspend',
'plugintype' => 'core',
'pluginname' => 'admin',
'elements' => array(
'i' => array(
'type' => 'hidden',
'value' => $institution,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('unsuspendinstitution','admin'),
'description' => get_string('unsuspendinstitutiondescription','admin'),
),
)
);
$suspendform = pieform($suspendformdef);
// Create a second forms for unsuspension to go in the suspend message.
// This keeps the HTML IDs unique
$suspendformdef['name'] = 'institution_unsuspend_top';
$suspendformdef['renderer'] = 'oneline';
$suspendformdef['successcallback'] = 'institution_unsuspend_submit';
$suspendform_top = pieform($suspendformdef);
}
$smarty->assign('suspendform', $suspendform);
if (isset($suspendform_top)) {
$smarty->assign('suspendform_top', $suspendform_top);
}
if ($suspended) {
$smarty->assign('suspended', get_string('suspendedinstitutionmessage', 'admin'));
}
}
$smarty->assign('heading', get_string('admininstitutions', 'admin'));
$smarty->display('admin/users/institutions.tpl');
......
......@@ -32,6 +32,7 @@ define('TITLE', get_string('uploadcsv', 'admin'));
require_once('pieforms/pieform.php');
require_once('institution.php');
safe_require('artefact', 'internal');
raise_memory_limit("512M");
// Turn on autodetecting of line endings, so mac newlines (\r) will work
ini_set('auto_detect_line_endings', 1);
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 artefact-blog
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'blog');
$limit = param_integer('limit', null);
$offset = param_integer('offset', 0);
$id = param_integer('blogpost', 0);
if ($id) {
$blogpost = new ArtefactTypeBlogPost($id);
$blogpost->check_permission();
if (!$filelist = $blogpost->get_attached_files()) {
$filelist = array();
}
}
else {
$filelist = array();
}
$result = array(
'count' => count($filelist),
'limit' => $limit,
'offset' => $offset,
'data' => $filelist,
'error' => false,
'message' => false,
);
json_headers();
print json_encode($result);
?>
......@@ -19,41 +19,5 @@
<KEY NAME="blogpostfk" TYPE="foreign" FIELDS="blogpost" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
<!-- This table relates artefacts of type 'blogpost' to artefacts of type
'file'. This is a many-many relation. -->
<TABLE NAME="artefact_blog_blogpost_file">
<FIELDS>
<FIELD NAME="blogpost" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="file" TYPE="int" LENGTH="10" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="blogpost_filepk" TYPE="primary" FIELDS="blogpost,file" />
<KEY NAME="blogpostfk" TYPE="foreign" FIELDS="blogpost" REFTABLE="artefact" REFFIELDS="id" />
<KEY NAME="filefk" TYPE="foreign" FIELDS="file" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
<!-- This table keeps track of files that are to be associated with a blog
post, but for which the post has not yet been created, or the association
has not yet been confirmed. No file should ever be in both this table and
artefact_blog_blogpost_file.
This table only keeps track of files that are specifically uploaded for a
blog post, not ones that have been uploaded already some other way, that
the user wants to associate with a blog post. -->
<TABLE NAME="artefact_blog_blogpost_file_pending">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="oldextension" TYPE="text" NOTNULL="false" />
<FIELD NAME="filetype" TYPE="text" NOTNULL="false" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
......@@ -28,17 +28,15 @@ defined('INTERNAL') || die();
function xmldb_artefact_blog_upgrade($oldversion=0) {
$status = true;
// There was no database prior to this version.
if ($status && $oldversion < 2006120501) {
$status = $status && install_from_xmldb_file(
if ($oldversion < 2006120501) {
install_from_xmldb_file(
get_config('docroot') .
'artefact/blog/db/install.xml'
);
}
if ($status && $oldversion < 2006121501) {
if ($oldversion < 2006121501) {
$table = new XMLDBTable('artefact_blog_blogpost_file_pending');
$table->addFieldInfo('file', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
......@@ -47,7 +45,9 @@ function xmldb_artefact_blog_upgrade($oldversion=0) {
$table->addKeyInfo('blogpost_file_pending_pk', XMLDB_KEY_PRIMARY, array('file'));
$table->addKeyInfo('filefk', XMLDB_KEY_FOREIGN, array('file'), 'artefact', array('id'));
$status = $status && create_table($table);
if (!create_table($table)) {
throw new SQLException($table . " could not be created, check log for errors.");
}
}
if ($oldversion < 2008012200) {
......@@ -124,8 +124,31 @@ function xmldb_artefact_blog_upgrade($oldversion=0) {
create_table($table);
}
if ($oldversion < 2009033100) {
$bloguploadbase = get_config('dataroot') . 'artefact/blog/uploads/';
if (is_dir($bloguploadbase)) {
if ($basedir = opendir($bloguploadbase)) {
while (false !== ($sessionupload = readdir($basedir))) {
if ($sessionupload != "." && $sessionupload != "..") {
$sessionupload = $bloguploadbase . $sessionupload;
$subdir = opendir($sessionupload);
while (false !== ($uploadfile = readdir($subdir))) {
if ($uploadfile != "." && $uploadfile != "..") {
$uploadfile = $sessionupload . '/' . $uploadfile;
unlink($uploadfile);
}
}
closedir($subdir);
rmdir($sessionupload);
}
}
}
@rmdir($bloguploadbase);
}
}
return $status;
return true;
}
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 artefact-file
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('file.php');
$uploadnumber = param_integer('tempfile');
safe_require('artefact', 'blog');
$path = ArtefactTypeBlogPost::get_temp_file_path($uploadnumber);
serve_file($path, '', get_field('artefact_blog_blogpost_file_pending', 'filetype', 'id', $uploadnumber));
?>
......@@ -42,8 +42,6 @@ $string['blogdesc'] = 'Description';
$string['blogdescdesc'] = 'e.g., ‘A record of Jill\'s experiences and reflections’.';
$string['blogdoesnotexist'] = 'You are trying to access a blog that does not exist';
$string['blogpostdoesnotexist'] = 'You are trying to access a blog post that does not exist';
$string['blogfilesdirdescription'] = 'Files uploaded as blog post attachments';
$string['blogfilesdirname'] = 'blogfiles';
$string['blogpost'] = 'Blog Post';
$string['blogdeleted'] = 'Blog deleted';
$string['blogpostdeleted'] = 'Blog post deleted';
......@@ -53,7 +51,6 @@ $string['blogsettings'] = 'Blog Settings';
$string['blogtitle'] = 'Title';
$string['blogtitledesc'] = 'e.g., ‘Jill’s Nursing Practicum Journal’.';
$string['border'] = 'Border';
$string['browsemyfiles'] = 'Browse my files';
$string['cancel'] = 'Cancel';
$string['commentsallowed'] = 'Comments';
$string['commentsalloweddesc'] = ' ';
......@@ -74,7 +71,6 @@ $string['dimensions'] = 'Dimensions';
$string['draft'] = 'Draft';
$string['edit'] = 'Edit';
$string['editblogpost'] = 'Edit Blog Post';
$string['erroraccessingblogfilesfolder'] = 'Error accessing blogfiles folder';
$string['errorsavingattachments'] = 'An error occurred while saving blog post attachments';
$string['horizontalspace'] = 'Horizontal space';
$string['insert'] = 'Insert';
......
<h3>Browse My Files</h3>
<p>If you wish to attach a file currently stored within your files area to your Blog posting, you can Browse your repository for the required file(s)</p>
<p>Navigate through your file folder structures and Attach the required file(s). The &#8216;blogfiles&#8217; folder contains those files already attached to Blog postings.</p>
<h3>Attach Files</h3>
<p>If you wish to attach a file currently stored within your files area to your Blog posting, you can Browse your repository for the required file(s)</p>
<p>Navigate through your file folder structures and Select the required file(s).</p>
<p>You can also upload new files from your computer. They will be placed in your files area and attached to your post at the same time.</p>
......@@ -58,53 +58,9 @@ class PluginArtefactBlog extends PluginArtefact {
}
public static function get_cron() {
return array(
(object)array(
'callfunction' => 'clean_post_files',
'hour' => '4',
'minute' => '40'
)
);
return array();
}
/**
* This function cleans out any files that have been uploaded, but which
* are not associated with a blog, because of an aborted blog creation.
*/
public static function clean_post_files() {
$bloguploadbase = get_config('dataroot') . ArtefactTypeBlogPost::$blogattachmentroot;
if (!$basedir = opendir($bloguploadbase)) {
// If the directory doesn't exist, it's likely that it hasn't been
// created yet (i.e. nobody has uploaded any files)
return;
}
$currenttime = time();
// Read through all the upload session directories
while (false !== ($sessionupload = readdir($basedir))) {
if ($sessionupload != "." && $sessionupload != "..") {
$sessionupload = $bloguploadbase . $sessionupload;
$subdir = opendir($sessionupload);
// Remove all files older than the session timeout plus two hours.
while (false !== ($uploadfile = readdir($subdir))) {
if ($uploadfile != "." && $uploadfile != "..") {
$uploadfile = $sessionupload . '/' . $uploadfile;
if ($currenttime - filemtime($uploadfile) > get_config('session_timeout') + 7200) {
unlink($uploadfile);
}
}
}
closedir($subdir);
rmdir($sessionupload);
}
}
closedir($basedir);
}
public static function block_advanced_options_element($configdata, $artefacttype) {
$strartefacttype = get_string($artefacttype, 'artefact.blog');
......@@ -440,7 +396,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
return;
}
delete_records('artefact_blog_blogpost_file', 'blogpost', $this->id);
$this->detach(); // Detach all file attachments
delete_records('artefact_blog_blogpost', 'blogpost', $this->id);
parent::delete();
......@@ -484,7 +440,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
}
$smarty->assign('artefactdescription', $postcontent);
$smarty->assign('artefact', $this);
$attachments = $this->get_attached_files();
$attachments = $this->get_attachments();
if ($attachments) {
$this->add_to_render_path($options);
require_once(get_config('docroot') . 'artefact/lib.php');
......@@ -508,49 +464,8 @@ class ArtefactTypeBlogPost extends ArtefactType {
}
/**
* Returns an array of IDs of artefacts attached to this blogpost
*/
public function attachment_id_list() {
if (!$list = get_column('artefact_blog_blogpost_file', 'file', 'blogpost', $this->get('id'))) {
$list = array();
}
return $list;
}
public function attach_file($artefactid) {
$data = new StdClass;
$data->blogpost = $this->get('id');
$data->file = $artefactid;
insert_record('artefact_blog_blogpost_file', $data);
$data = new StdClass;
$data->artefact = $artefactid;
$data->parent = $this->get('id');
$data->dirty = true;
insert_record('artefact_parent_cache', $data);
// Ensure the attachment is recorded as being related to the blog as well
$data = new StdClass;
$data->artefact = $artefactid;
$data->parent = $this->get('parent');
$data->dirty = 0;