Commit 6839a281 authored by Alan McNatty's avatar Alan McNatty Committed by Richard Mansfield

Page and configuration for file uploads from mobile application

parent 0183678b
......@@ -36,7 +36,7 @@ define('TITLE', get_string('account'));
require_once('pieforms/pieform.php');
// load up user preferences
$prefs = (object)($USER->accountprefs);
$prefs = (object) load_account_preferences($USER->id);
$authobj = AuthFactory::create($USER->authinstance);
......@@ -192,6 +192,14 @@ if (get_config('homepageinfo')) {
'help' => 'true'
);
}
if (get_config('allowmobileuploads')) {
$elements['mobileuploadtoken'] = array(
'type' => 'text',
'title' => get_string('mobileuploadtoken', 'account'),
'description' => get_string('mobileuploadtokendescription', 'account'),
'defaultvalue' => isset($prefs->mobileuploadtoken) ? $prefs->mobileuploadtoken : get_config('mobileuploadtoken')
);
}
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('save')
......
......@@ -437,6 +437,13 @@ $siteoptionform = array(
'defaultvalue' => get_config('registerterms'),
'disabled' => in_array('registerterms', $OVERRIDDEN),
),
'allowmobileuploads' => array(
'type' => 'checkbox',
'title' => get_string('allowmobileuploads', 'admin'),
'description' => get_string('allowmobileuploadsdescription', 'admin'),
'defaultvalue' => get_config('allowmobileuploads'),
'disabled' => in_array('allowmobileuploads', $OVERRIDDEN),
),
),
),
)
......@@ -466,7 +473,7 @@ function siteoptions_submit(Pieform $form, $values) {
'tagssideblockmaxtags', 'country', 'viewmicroheaders', 'userscanchooseviewthemes',
'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments',
'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials',
'homepageinfo', 'showonlineuserssideblock', 'registerterms',
'homepageinfo', 'showonlineuserssideblock', 'registerterms', 'allowmobileuploads',
'creategroups', 'createpublicgroups', 'allowgroupcategories',
);
$oldlanguage = get_config('lang');
......
<?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 artefact-file
* @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('PUBLIC', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
$protocol = strtoupper($_SERVER['SERVER_PROTOCOL']);
if ($protocol != 'HTTP/1.1') {
$protocol = 'HTTP/1.0';
}
if (!get_config('allowmobileuploads')) {
header($protocol.' 500 Mobile uploads disabled');
exit;
}
$token = '';
try {
$token = param_variable('token');
$token = trim($token);
}
catch (ParameterException $e) {
$token = '';
}
if ($token == '') {
header($protocol.' 500 Auth token cannot be blank');
exit;
}
$data = new StdClass;
$USER = new User();
try {
$USER->find_by_mobileuploadtoken($token);
}
catch (AuthUnknownUserException $e) {
header($protocol.' 500 Invalid user token');
exit;
}
$data->owner = $USER->get('id'); // id of owner
$folder = '';
try {
$folder = param_variable('foldername');
$folder = trim($folder);
if ($folder) {
// TODO: create if doesn't exist - note assumes it is a base folder (hence null parent)
$artefact = ArtefactTypeFolder::get_folder_by_name($folder, null, $data->owner); // id of folder you're putting the file into
if ($artefact) {
$data->parent = $artefact->id;
if ($data->parent == 0) {
$data->parent = null;
}
}
else {
$fd = (object) array(
'owner' => $data->owner,
'title' => $folder,
'parent' => null,
);
$f = new ArtefactTypeFolder(0, $fd);
$f->commit();
$data->parent = $f->get('id');
}
}
else {
$data->parent = null;
}
}
catch (ParameterException $e) {
$data->parent = null;
}
$originalname = $_FILES['userfile']['name'];
$originalname = $originalname ? basename($originalname) : get_string('file', 'artefact.file');
$data->title = ArtefactTypeFileBase::get_new_file_title($originalname, $data->parent, $data->owner);
try {
$newid = ArtefactTypeFile::save_uploaded_file('userfile', $data);
}
catch (QuotaExceededException $e) {
header($protocol.' 500 Quota exceeded');
exit;
}
catch (UploadException $e) {
header($protocol.' 500 Failed to save file');
exit;
}
// Here we need to create a new hash - update our own store of it and return it too the handset
echo $USER->refresh_mobileuploadtoken();
......@@ -258,6 +258,53 @@ class User {
return $this;
}
/**
* Populates this object with the user record identified by a mobile 'token'
*
* @throws AuthUnknownUserException If the user cannot be found.
*/
public function find_by_mobileuploadtoken($token) {
if (!is_string($token)) {
throw new InvalidArgumentException('Input parameters must be strings to create a User object from token');
}
$sql = 'SELECT
u.*,
' . db_format_tsfield('u.expiry', 'expiry') . ',
' . db_format_tsfield('u.lastlogin', 'lastlogin') . ',
' . db_format_tsfield('u.lastlastlogin', 'lastlastlogin') . ',
' . db_format_tsfield('u.lastaccess', 'lastaccess') . ',
' . db_format_tsfield('u.suspendedctime', 'suspendedctime') . ',
' . db_format_tsfield('u.ctime', 'ctime') . '
FROM
{usr} u
LEFT JOIN {usr_account_preference} p ON u.id = p.usr
WHERE p.field=\'mobileuploadtoken\' and p.value = ?
';
$user = get_record_sql($sql, array($token));
if (false == $user) {
throw new AuthUnknownUserException("User with mobile upload token \"$token\" is not known");
}
$this->populate($user);
return $this;
}
/**
* Refreshes a users mobile 'token' and returns it
*
*/
public function refresh_mobileuploadtoken() {
$new_token = md5( uniqid() );
$this->set_account_preference('mobileuploadtoken', $new_token);
$this->set('lastaccess', time());
$this->commit();
return $new_token;
}
/**
* Set stuff that needs to be initialised once before a user record is created.
*/
......
......@@ -69,6 +69,9 @@ $string['hiderealnamedescription'] = 'Check this box if you have set a display n
$string['showhomeinfo'] = 'Show information about Mahara on the home page';
$string['mobileuploadtoken'] = 'Mobile upload token';
$string['mobileuploadtokendescription'] = 'Enter a token here and on your phone to enable uploads (note: it will change automatically after each upload. <br/>If you have any problems - simply reset it here and on your phone.';
$string['prefssaved'] = 'Preferences saved';
$string['prefsnotsaved'] = 'Failed to save your Preferences!';
......
......@@ -237,6 +237,8 @@ $string['pathtoclam'] = 'Path to clam';
$string['pathtoclamdescription'] = 'The filesystem path to clamscan or clamdscan';
$string['registerterms'] = 'Registration agreement';
$string['registertermsdescription'] = "Force users to agree to the Terms and Conditions before registration. You should edit your site's Terms and Conditions page before enabling this option.";
$string['allowmobileuploads'] = 'Allow Mobile Uploads';
$string['allowmobileuploadsdescription'] = 'If enabled users will have the option of setting an authentication token - content uploaded with this token will be saved as artefacts.';
$string['remoteavatars'] = 'Display remote avatars';
$string['remoteavatarsdescription'] = 'If checked, the <a href="http://www.gravatar.com">Gravatar</a> service will be used for users\' default profile icons.';
$string['searchplugin'] = 'Search plugin';
......
......@@ -206,6 +206,7 @@ function expected_account_preferences() {
'hiderealname' => 0,
'multipleblogs' => 0,
'showhomeinfo' => 1,
'mobileuploadtoken' => '',
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment