Commit e1c3c0d8 authored by Richard Mansfield's avatar Richard Mansfield
Browse files
parents 8d8230e7 2983ab81
<?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 admin
* @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('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'adminnotifications');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$smarty = smarty();
$smarty->display('admin/usermanagement/adminnotifications.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 admin
* @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('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'adminusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$smarty = smarty();
$smarty->display('admin/usermanagement/adminusers.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 admin
* @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('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'staffusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$smarty = smarty();
$smarty->display('admin/usermanagement/staffusers.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 admin
* @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('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'suspendedusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$smarty = smarty();
$smarty->display('admin/usermanagement/suspendedusers.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 admin
* @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('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'uploadcsv');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('form.php');
$institutions = get_records('institution');
foreach ($institutions as $name => $data) {
$options[$name] = $data->displayname;
}
$institutions = get_records_select('institution', "registerallowed = 1 AND authplugin = 'internal'");
if (count($institutions) > 1) {
$options = array();
foreach ($institutions as $institution) {
$options[$institution->name] = $institution->displayname;
}
$institutionelement = array(
'type' => 'select',
'title' => get_string('institution'),
'description' => get_string('institutiondescription'),
'options' => $options
);
}
else {
$institutionelement = array(
'type' => 'hidden',
'value' => 'mahara'
);
}
$form = array(
'name' => 'uploadcsv',
'method' => 'post',
'action' => '',
'elements' => array(
'institution' => $institutionelement,
'file' => array(
'type' => 'file',
'title' => get_string('csvfile', 'admin'),
'description' => get_string('csvfiledescription', 'admin'),
'rules' => array(
'required' => true
)
),
'submit' => array(
'type' => 'submit',
'value' => get_string('uploadcsvfile', 'admin')
)
)
);
/**
* The CSV file is parsed here so validation errors can be returned to the
* user. The data from a successful parsing is stored in the <var>$CVSDATA</var>
* array so it can be accessed by the submit function
*
* @param Form $form The form to validate
* @param array $values The values submitted
*/
function uploadcsv_validate(Form $form, $values) {
global $CSVDATA;
// Don't even start attempting to parse if there are previous errors
if ($form->has_errors()) {
return;
}
if ($values['file']['size'] == 0) {
$form->set_error('file', get_string('thisfieldisrequired', 'admin'));
return;
}
require_once('pear/File.php');
require_once('pear/File/CSV.php');
$institution = $values['institution'];
log_debug($values);
$conf = File_CSV::discoverFormat($values['file']['tmp_name']);
log_debug($conf);
$i = 0;
while ($line = @File_CSV::readQuoted($values['file']['tmp_name'], $conf)) {
log_debug($line);
$i++;
if (count($line) < 3) {
$form->set_error('file', get_string('uploadcsverrorincorrectfieldcount', 'admin', $i));
return;
}
$username = $line[0];
$email = $line[1];
$password = $line[2];
safe_require('auth', 'internal', 'lib.php', 'require_once');
if (!AuthInternal::is_username_valid($username)) {
$form->set_error('file', get_string('uploadcsverrorinvalidusername', 'admin', $i));
return;
}
if (record_exists('usr', 'username', $username)) {
$form->set_error('file', get_string('uploadcsverroruseralreadyexists', 'admin', $i));
return;
}
require_once('form/rules/email.php');
if (form_rule_email($email) !== null) {
$form->set_error('file', get_string('uploadcsverrorinvalidemail', 'admin', $i));
return;
}
// Note: only checks for valid form are done here, none of the checks
// like whether the password is too easy. The user is going to have to
// change their password on first login anyway.
if (!AuthInternal::is_password_valid($password)) {
$form->set_error('file', get_string('uploadcsverrorinvalidpassword', 'admin', $i));
return;
}
// All OK!
$CSVDATA[] = $line;
}
}
/**
* Add the users to the system. Make sure that they have to change their
* password on next login also.
*/
function uploadcsv_submit($values) {
global $SESSION, $CSVDATA;
log_info('Inserting users from the CSV file');
foreach ($CSVDATA as $record) {
log_debug('adding user ' . $record->username);
// @todo when penny has done the profile field setting stuff...
//$user = new StdClass;
//$user->username = $record[0];
//$user->password = $record[2];
//$user->institution = $values['institution'];
//$user->passwordchange = 1;
//$user->firstname = ???;
//$user->lastname = ???;
//$user->email = $record[1];
}
log_info('Inserted ' . count($CSVDATA) . ' records');
$SESSION->add_ok_msg('yo yo users added yo!');
// @todo support relative URLs here
redirect(get_config('wwwroot') . 'admin/usermanagement/uploadcsv.php');
}
$smarty = smarty();
$smarty->assign('uploadcsvform', form($form));
$smarty->display('admin/usermanagement/uploadcsv.tpl');
?>
......@@ -29,7 +29,15 @@ defined('INTERNAL') || die();
class PluginArtefactInternal extends PluginArtefact {
public static function get_artefact_types() {
return array('profile', 'file', 'folder', 'image');
return array('file', 'folder', 'image',
'firstname', 'lastname', 'studentid',
'preferredname', 'introduction',
'email', 'officialwebsite', 'personalwebsite',
'blog', 'address', 'town', 'city',
'country', 'homenumber', 'businessnumber',
'mobilenumber', 'faxnumber', 'icqnumber',
'msnnumber'
);
}
public static function get_plugin_name() {
......@@ -70,7 +78,99 @@ class PluginArtefactInternal extends PluginArtefact {
}
}
// @todo write ArtefactType$name classes for each of the
// types returned by get_artefact_types
class ArtefactTypeProfile extends ArtefactType {
/**
* overriding this because profile fields
* are unique in that except for email, you only get ONE
* so if we don't get an id, we still need to go look for it
*/
public function __construct($id=0, $data=null) {
$type = $this->get_artefact_type();
if (!empty($id) || $type == 'email') {
return parent::__construct($id, $data);
}
if (!empty($data['owner'])) {
if ($a = get_record('artefact', 'artefacttype', $type, 'owner', $data['owner'])) {
return parent::__construct($a->id, $a);
}
}
$this->ctime = time();
$this->atime = time();
$this->artefacttype = $type;
}
public function commit() {
$this->commit_basic();
}
public function delete() {
$this->delete_basic();
}
public function render($format, $options) {
}
public function get_icon() {
}
public static function get_render_list() {
}
public static function can_render_to($format) {
}
public static function get_mandatory_fields() {
return array('firstname' => 'text',
'lastname' => 'text',
'studentid' => 'text',
'email' => 'text');
}
}
class ArtefactTypeCachedProfile extends ArtefactTypeProfile {
public function commit() {
$this->commit_basic();
$field = $this->get_artefact_type();
set_field('usr', $field, $this->title, 'id', $this->owner);
}
public function delete() {
$this->delete_basic();
$field = $this->get_artefact_type();
set_field('usr', $field, null, 'id', $this->owner);
}
}
class ArtefactTypeFirstname extends ArtefactTypeCachedProfile {}
class ArtefactTypeLastname extends ArtefactTypeCachedProfile {}
class ArtefactTypePreferredname extends ArtefactTypeCachedProfile {}
class ArtefactTypeEmail extends ArtefactTypeCachedProfile {}
class ArtefactTypeStudentid extends ArtefactTypeProfile {}
class ArtefactTypeIntroduction extends ArtefactTypeProfile {}
class ArtefactTypeOfficialwebsite extends ArtefactTypeProfile {}
class ArtefactTypePersonalwebsite extends ArtefactTypeProfile {}
class ArtefactTypeBlog extends ArtefactTypeProfile {}
class ArtefactTypeAddress extends ArtefactTypeProfile {}
class ArtefactTypeTown extends ArtefactTypeProfile {}
class ArtefactTypeCity extends ArtefactTypeProfile {}
class ArtefactTypeCountry extends ArtefactTypeProfile {}
class ArtefactTypeHomenumber extends ArtefactTypeProfile {}
class ArtefactTypeBusinessnumber extends ArtefactTypeProfile {}
class ArtefactTypeMobilenumber extends ArtefactTypeProfile {}
class ArtefactTypeFaxnumber extends ArtefactTypeProfile {}
class ArtefactTypeIcqnumber extends ArtefactTypeProfile {}
class ArtefactTypeMsnnumber extends ArtefactTypeProfile {}
class ArtefactTypeFolder extends ArtefactTypeProfile {}
class ArtefactTypeFile extends ArtefactTypeProfile {}
class ArtefactTypeImage extends ArtefactTypeFile {}
?>
......@@ -98,12 +98,13 @@ abstract class ArtefactType {
protected $dirty;
protected $parentdirty;
protected $id;
protected $type;
protected $artefacttype;
protected $owner;
protected $container;
protected $parent;
protected $ctime;
protected $mtime;
protected $vtime;
protected $atime;
protected $locked;
protected $title;
protected $description;
......@@ -132,7 +133,7 @@ abstract class ArtefactType {
}
}
foreach ((array)$data as $field => $value) {
if (property_exists($field)) {
if (property_exists($this, $field)) {
$this->{$field} = $value;
}
}
......@@ -140,6 +141,8 @@ abstract class ArtefactType {
else {
$this->ctime = time();
}
$this->atime = time();
$this->artefacttype = $this->get_artefact_type();
}
public function get_views_instances() {
......@@ -165,7 +168,7 @@ abstract class ArtefactType {
if ($children = $this->get_children_metadata()) {
$this->childreninstances = array();
foreach ($children as $child) {
$classname = $child->artefacttype;
$classname = generate_artefact_class_name($child->artefacttype);
$instance = new $classname($child->id, $child);
$this->childreninstances[] = $instance;
}
......@@ -202,7 +205,8 @@ abstract class ArtefactType {
if (!isset($this->parentinstance)) {
$this->parentinstance = false;
if ($parent = $this->get_parent_metadata()) {
$classname = $parent->artefacttype;
$classname = generate_artefact_class_name($parent->artefacttype);
// @todo this won't work.
$this->parentinstance = new $classname($parent->id, $parent);
}
}
......@@ -223,19 +227,20 @@ abstract class ArtefactType {
}
public function get($field) {
if (!property_exists($field)) {
if (!property_exists($this, $field)) {
throw new InvalidArgumentException("Field $field wasn't found in class " . get_class($this));
}
return $this->{$field};
}
public function set($field, $value) {
if (property_exists($field)) {
if (property_exists($this, $field)) {
$this->{$field} = $value;
$this->dirty = true;
if ($field == 'parent') {
$this->parentdirty = true;
}
$this->mtime = time();
return true;
}
throw new InvalidArgumentException("Field $field wasn't found in class " . get_class($this));
......@@ -246,11 +251,12 @@ abstract class ArtefactType {
* artefact cache as dirty if necessary.
*/
public function __destruct() {
try {
if (!empty($this->dirty)) {
$this->commit();
}
if (!empty($this->parentdirty)) {
if (!empty($this->parent) && !record_exists('artefact_parent_cache', 'aretfact', $this->id)) {
if (!empty($this->parent) && !record_exists('artefact_parent_cache', 'artefact', $this->id)) {
$apc = new StdClass;
$apc->artefact = $this->id;
$apc->parent = $this->parent;
......@@ -260,22 +266,65 @@ abstract class ArtefactType {
set_field_select('artefact_parent_cache', 'dirty', 1,
'artefact = ? OR parent = ?', array($this->id, $this->id));
}
}
catch (Exception $e) {
log_warn($e->GetMessage());
}
}
public function is_container() {
return false;
}
/**
* As commit is abstract, subclasses
* can use this as a helper to update
* the contents of the artefact table
*/
protected function commit_basic() {
$fordb = new StdClass;
foreach (get_object_vars($this) as $k => $v) {
$fordb->{$k} = $v;
if (in_array($k, array('mtime', 'ctime', 'atime')) && !empty($v)) {
$fordb->{$k} = db_format_timestamp($v);
}
}
if (empty($this->id)) {
$this->id = insert_record('artefact', $fordb, 'id', true);
}
else {
update_record('artefact', $fordb, 'id');
}
$this->dirty = false;
}
/**
* Saves any changes to the database
* for basic commits, use {@link commit_basic}
* @abstract
*/
public abstract function commit();
/**
* As delete is abstract, subclasses
* can use this to clear out the artefact
* table and set the parentdirty flag
*/
protected function delete_basic() {
delete_records('artefact', 'id', $this->id);
$this->dirty = false;
$this->parentdirty = true;
}
/**
* Deletes current instance
* you MUST set $this->parentdirty to true
* when delete is called.
* for basic delete, use {@link delete_basic}
* @abstract
*/
public abstract function delete();
......@@ -311,16 +360,43 @@ abstract class ArtefactType {
* returns array of formats can render to (constants)
* @abstract
*/
public static abstract function get_render_list($format);
public static abstract function get_render_list();