Commit b66ce866 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files
parents f640d6cc 27086dbf
......@@ -39,7 +39,7 @@ $ijs .= <<< EOJS
function getitems() {
logDebug(get_string('loadingmenuitems'));
processingStart();
var d = loadJSONDoc('getmenuitems.json.php',{'public':selectedmenu == 'public'});
var d = loadJSONDoc('getmenuitems.json.php',{'public':selectedmenu == 'loggedoutmenu'});
d.addCallback(function(data) {
if (!data.error) {
logDebug(get_string('loadedmenuitems'));
......@@ -59,7 +59,7 @@ function displaymenuitems(itemlist) {
var table = $('menuitemlist');
var newrow = TR({'id':'additem','style':'background-color: #ddd;'},
TD({'colspan':4},addform()));
replaceChildNodes(table,TBODY(null,[thead,rows,newrow]));
replaceChildNodes(table,cols(),TBODY(null,[thead,rows,newrow]));
}
// Creates one table row
......@@ -72,7 +72,7 @@ function formatrow (item) {
var edit = INPUT({'type':'button','value':get_string('edit')});
edit.onclick = function () { edititem(item); };
var cells = map(partial(TD,null),[type,item.name,linkedto,[del,edit]]);
return TR({'id':'menuitem_'+item.id,'class':'menueditcell'},cells);
return TR({'id':'menuitem_'+item.id},cells);
}
// Returns the form which adds a new menu item
......@@ -142,8 +142,8 @@ function editform(item) {
setNodeAttribute(elink,'checked',true);
}
var radios = [DIV(null,elink,eval('externallink')),DIV(null,afile,eval('adminfile'))];
var row = TR(null,map(partial(TD,{'class':'menueditcell'}),[radios,name,linkedto,savecancel]));
return TABLE(null,TBODY(null,row));
var row = TR(null,map(partial(TD,null),[radios,name,linkedto,savecancel]));
return TABLE({'width':'100%'},cols(),TBODY(null,row));
}
// Close all open edit forms
......@@ -210,14 +210,24 @@ function delitem(itemid) {
// Send the menu item in the form to the database.
function saveitem(formid) {
var f = $(formid);
var name = f.name.value;
var linkedto = f.linkedto.value;
if (name == '') {
displayMessage(get_string('namedfieldempty',get_string('name')),'error');
return false;
}
if (linkedto == '') {
displayMessage(get_string('namedfieldempty',get_string('linkedto')),'error');
return false;
}
processingStart();
displayMessage(get_string('savingmenuitem'),'info');
var f = $(formid);
var data = {'type':f.type[0].checked ? 'externallink' : 'adminfile',
'name':f.name.value,
'linkedto':f.linkedto.value,
'name':name,
'linkedto':linkedto,
'itemid':f.itemid.value,
'public':selectedmenu == 'public'};
'public':selectedmenu == 'loggedoutmenu'};
var req = getXMLHttpRequest();
req.open('POST','updatemenu.json.php');
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
......@@ -228,13 +238,13 @@ function saveitem(formid) {
if (!data.error) {
errtype = 'info';
}
if (data.error == 'local') {
else if (data.error == 'local') {
errtype = 'error';
}
if (errtype == 'global') {
else {
global_error_handler(data);
}
else {
if (errtype != 'global') {
displayMessage(data.message,errtype);
getitems();
processingStop();
......@@ -247,36 +257,44 @@ function saveitem(formid) {
return false;
}
// In phase 1 there are no files in the system
function getadminfiles() {
return null;
}
function setmenu(menu) {
selectedmenu = menu;
var pub = get_string('loggedoutmenu');
var priv = get_string('loggedinmenu');
if (menu == 'public') {
priv = A({'href':''},priv);
priv.onclick = function () {return setmenu('private');};
}
else {
pub = A({'href':''},pub);
pub.onclick = function () {return setmenu('public');};
}
replaceChildNodes($('menuselect'), [pub, priv]);
function changemenu() {
selectedmenu = $('menuselect').value;
getitems();
return false;
}
var selectedmenu = 'public';
addLoadEvent(function () {setmenu(selectedmenu);});
// Set column widths
function cols () {
COL = partial(createDOM,'col');
return [COL({'width':"20%"}),COL({'width':"25%"}),COL({'width':"40%"}),COL({'width':"15%"})];
}
var selectedmenu = 'loggedoutmenu';
addLoadEvent(function () {
$('menuselect').value = selectedmenu;
$('menuselect').onchange = changemenu;
changemenu();
});
EOJS;
$style = '<style type="text/css">.invisible{display:none;} .menueditcell{width:200px;}</style>';
$strings = array('deletefailed','deletingmenuitem','menuitemdeleted','noadminfiles',
'edit','delete','update','cancel','add','loggedinmenu','loggedoutmenu');
$menulist = array('loggedinmenu', 'loggedoutmenu');
foreach ($menulist as &$menu) {
$menu = array('value' => $menu,
'name' => get_string($menu));
}
$style = '<style type="text/css">.invisible{display:none;}</style>';
$strings = array('deletefailed','deletingmenuitem','menuitemdeleted','savingmenuitem','noadminfiles',
'edit','delete','update','cancel','add','loggedinmenu','loggedoutmenu','name',
'linkedto');
$smarty = smarty(array(),array($style),$strings);
$smarty->assign('INLINEJAVASCRIPT',$ijs);
$smarty->assign('EDIT',get_string('edit') . ':');
$smarty->assign('MENUS',$menulist);
$smarty->display('admin/editmenu.tpl');
?>
......@@ -79,16 +79,11 @@ function editsitepage_submit($values) {
$data->mauthor = $USER->id;
try {
update_record('site_content', $data, 'name');
$result['error'] = false;
$result['message'] = get_string('savedsuccessfully');
}
catch (SQLException $e) {
$result['error'] = 'local';
$result['message'] = get_string('savefailed');
json_reply('local', get_string('savefailed'));
}
json_headers();
echo json_encode($result);
exit;
json_reply(false, get_string('savedsuccessfully'));
}
if (use_html_editor()) {
......
......@@ -37,24 +37,26 @@ try {
// @todo: Get all the filenames of the files referred to in the $menuitems records.
// (files table doesn't exist yet)
$rows = array();
foreach ($menuitems as $i) {
$r = array();
$r['id'] = $i->id;
$r['name'] = $i->title;
if (empty($i->url) && !empty($i->file)) {
$r['type'] = 'adminfile';
$r['linkedto'] = $i->file; // @todo: substitute the appropriate filename.
// $r['link'] = ''; // @todo: provide a link to the file
if ($menuitems) {
foreach ($menuitems as $i) {
$r = array();
$r['id'] = $i->id;
$r['name'] = $i->title;
if (empty($i->url) && !empty($i->file)) {
$r['type'] = 'adminfile';
$r['linkedto'] = $i->file; // @todo: substitute the appropriate filename.
// $r['link'] = ''; // @todo: provide a link to the file
}
else if (!empty($i->url) && empty($i->file)) {
$r['type'] = 'externallink';
$r['linkedto'] = $i->url;
// $r['link'] = $i->url;
}
else {
throw new Exception ('Exactly one of {file,url} should be set in site_menu table');
}
$rows[] = $r;
}
else if (!empty($i->url) && empty($i->file)) {
$r['type'] = 'externallink';
$r['linkedto'] = $i->url;
// $r['link'] = $i->url;
}
else {
throw new Exception ('Exactly one of {file,url} should be set in site_menu table');
}
$rows[] = $r;
}
$result['menuitems'] = array_values($rows);
$result['error'] = false;
......
......@@ -28,14 +28,6 @@ define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
function send_fail_message() {
$result = array();
$result['error'] = 'local';
$result['message'] = get_string('savefailed');
echo json_encode($result);
exit;
}
$type = param_alpha('type'); // external list or admin file
$name = param_variable('name');
$linkedto = param_variable('linkedto');
......@@ -51,7 +43,7 @@ else if ($type == 'externallink') {
$data->url = $linkedto;
}
else { // Bad menu item type
send_fail_message();
json_reply('local',get_string('badmenuitemtype'));
}
$data->title = $name;
......@@ -61,14 +53,16 @@ if ($itemid == 'new') {
try {
$displayorders = get_rows('site_menu', 'public', $data->public, '', 'displayorder');
$max = 0;
foreach ($displayorders as $r) {
$max = $r['displayorder'] >= $max ? $r['displayorder'] + 1 : $max;
if ($displayorders) {
foreach ($displayorders as $r) {
$max = $r['displayorder'] >= $max ? $r['displayorder'] + 1 : $max;
}
}
$data->displayorder = $max;
insert_record('site_menu', $data);
}
catch (Exception $e) {
send_fail_message();
json_reply('local',get_string('savefailed'));
}
}
else {
......@@ -77,13 +71,10 @@ else {
update_record('site_menu', $data, 'id');
}
catch (Exception $e) {
send_fail_message();
json_reply('local',get_string('savefailed'));
}
}
$result = array();
$result['error'] = false;
$result['message'] = get_string('savedsuccessfully');
echo json_encode($result);
json_reply(false,get_string('menuitemsaved'));
?>
......@@ -235,8 +235,11 @@ abstract class ArtefactType {
public function set($field, $value) {
if (property_exists($this, $field)) {
if ($this->{$field} != $value) {
// only set it to dirty if it's changed
$this->dirty = true;
}
$this->{$field} = $value;
$this->dirty = true;
if ($field == 'parent') {
$this->parentdirty = true;
}
......@@ -251,7 +254,6 @@ abstract class ArtefactType {
* artefact cache as dirty if necessary.
*/
public function __destruct() {
try {
if (!empty($this->dirty)) {
$this->commit();
}
......@@ -266,10 +268,6 @@ 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() {
......
......@@ -70,7 +70,7 @@ class Session {
'admin' => false,
'firstname' => '',
'lastname' => '',
'prefname' => '',
'preferredname' => '',
'email' => '',
'accountprefs' => array(),
'activityprefs' => array(),
......
......@@ -107,7 +107,7 @@ function contactus_submit($values) {
email_user($to,$from,$values['subject'],$values['message']);
}
catch (Exception $e) {
json_reply('local', get_string('emailnotsent'));
json_reply('local', get_string('emailnotsent', 'mahara', $e->getMessage()));
}
json_reply(false, get_string('contactinformationsent'));
......
......@@ -50,7 +50,6 @@ $offset = param_integer('offset', 0);
$data = search_user($query, $limit, $offset);
foreach ($data['results'] as &$result) {
// @todo should call magical display user function
$result['name'] = display_name($result);
unset($result['email']);
......@@ -58,7 +57,7 @@ foreach ($data['results'] as &$result) {
unset($result['username']);
unset($result['firstname']);
unset($result['lastname']);
unset($result['prefname']);
unset($result['preferredname']);
}
print json_encode($data);
......
......@@ -43,6 +43,14 @@ $string['upgradesuccess'] = 'Successfully upgraded to version ';
$string['upgradefailure'] = 'Failed to upgrade!';
$string['noupgrades'] = 'Nothing to upgrade! You are fully up to date!';
// Admin navigation menu
$string['usermanagement'] = 'Manage users';
$string['siteoptions'] = 'Site options';
$string['pageeditor'] = 'Site pages';
$string['menueditor'] = 'Site menu';
$string['files'] = 'Files';
$string['adminhome'] = 'Admin home';
// Upload CSV stuff
$string['csvfile'] = 'CSV File';
$string['csvfiledescription'] = 'The file containing users to add';
......
......@@ -151,6 +151,8 @@ $string['delete'] = 'Delete';
$string['edit'] = 'Edit';
$string['loggedinmenu'] = 'Logged in menu';
$string['loggedoutmenu'] = 'Logged out menu';
$string['menuitemsaved'] = 'Menu item saved';
$string['savingmenuitem'] = 'Saving menu item';
// Site content
$string['about'] = 'About';
......@@ -171,6 +173,10 @@ $string['email'] = 'Email';
$string['subject'] = 'Subject';
$string['message'] = 'Message';
$string['submitcontactinformation'] = 'Submit contact information';
$string['nositecontactaddress'] = 'Site contact email address not set';
$string['nosendernamefound'] = 'No sender name was submitted';
$string['emailnotsent'] = 'Failed to send contact email. Error message: "%s"';
$string['contactinformationsent'] = 'Your contact information has been sent';
// mahara.js
$string['namedfieldempty'] = 'The required field "%s" is empty';
......@@ -193,7 +199,6 @@ $string['mycommunities'] = 'My Communities';
$string['myownedcommunities'] = 'My Owned Communities';
$string['mygroups'] = 'My Groups';
// mycontacts
// mygroups
......
......@@ -47,7 +47,7 @@ function form_render_userlist($element, Form $form) {
}
if (is_array($value) && count($value)) {
$members = get_records_select('usr','id IN (' . join(',',$value) . ')', null, '', 'id,firstname,lastname,prefname');
$members = get_records_select('usr','id IN (' . join(',',$value) . ')', null, '', 'id,firstname,lastname,preferredname');
foreach($members as &$member) {
$member = display_name($member);
......
......@@ -1008,7 +1008,7 @@ function site_menu() {
/**
* Always use this function for all emails to users
*
* @param object $userto user object to send email to. must contain firstname,lastname,prefname,email
* @param object $userto user object to send email to. must contain firstname,lastname,preferredname,email
* @param object $userfrom user object to send email from. If null, email will come from mahara
* @param string $subject email subject
* @param string $messagetext text version of email
......@@ -1059,14 +1059,14 @@ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml='')
else {
$mail->Sender = $userfrom->email;
$mail->From = $mail->Sender;
$mail->FromName = display_name($userfrom);
$mail->FromName = display_name($userfrom, $userto);
}
$mail->AddReplyTo($mail->From, $mail->FromName);
$mail->Subject = substr(stripslashes($subject), 0, 78);
$usertoname = display_name($userto);
$usertoname = display_name($userto, $userto);
$mail->AddAddress($userto->email, $usertoname );
$mail->WordWrap = 79;
......@@ -1089,12 +1089,37 @@ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml='')
. "Error from phpmailer was: " . $mail->ErrorInfo );
}
function display_name($user) {
function display_name($user, $userto=null) {
global $USER;
if (empty($userto)) {
$userto = $USER;
}
if (is_array($user)) {
$user = (object)$user;
}
return $user->firstname . ' ' . $user->lastname;
// @todo
else if (is_numeric($user)) {
$user = get_record('usr', 'id', $user);
}
if (!is_object($user)) {
throw new InvalidArgumentException("Invalid user passed to display_name");
}
// if they don't have a preferred name set, just return here
if (empty($user->preferredname)) {
return $user->firstname . ' ' . $user->lastname;
}
$prefix = get_config('dbprefix');
$sql = 'SELECT c1.member
FROM ' . $prefix . 'community_member c1
JOIN ' .$prefix. 'community_member c2
ON c1.community = c2.community
WHERE c1.member = ? AND c2.member = ? AND c2.tutor = ?';
if (record_exists_sql($sql, array($user->id, $userto->id, 1))) {
return $user->preferredname . ' (' . $user->firstname . ' ' . $user->lastname . ')';
}
return $user->preferredname;
}
/**
......
......@@ -40,22 +40,22 @@ defined('INTERNAL') || die();
* offset => integer, // starting from which result
* results => array( // the result records
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* prefname => string,
* email => string,
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* prefname => string,
* email => string,
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(...),
* ),
......
......@@ -53,7 +53,7 @@ class PluginNotificationEmaildigest extends PluginNotification {
public static function send_digest() {
$users = array();
$sql = 'SELECT q.id, u.firstname,u.lastname,u.prefname,u.email,q.*,' . db_format_tsfield('ctime').'
$sql = 'SELECT q.id, u.firstname,u.lastname,u.preferredname,u.email,q.*,' . db_format_tsfield('ctime').'
FROM ' . get_config('dbprefix') . 'usr u
JOIN ' . get_config('dbprefix') . 'notification_emaildigest_queue q
ON q.usr = u.id
......@@ -65,11 +65,11 @@ class PluginNotificationEmaildigest extends PluginNotification {
$users[$queue->usr] = new StdClass;
$users[$queue->usr]->user = new StdClass;
$users[$queue->usr]->user->firstname = $queue->firstname;
$users[$queue->usr]->user->lastname = $queue->lastname;
$users[$queue->usr]->user->prefname = $queue->prefname;
$users[$queue->usr]->user->email = $queue->email;
$users[$queue->usr]->user->id = $queue->usr;
$users[$queue->usr]->user->firstname = $queue->firstname;
$users[$queue->usr]->user->lastname = $queue->lastname;
$users[$queue->usr]->user->preferredname = $queue->preferredname;
$users[$queue->usr]->user->email = $queue->email;
$users[$queue->usr]->user->id = $queue->usr;
$users[$queue->usr]->entries = array();
}
......
......@@ -45,22 +45,22 @@ class PluginSearchInternal extends PluginSearch {
* offset => integer, // starting from which result
* results => array( // the result records
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* prefname => string,
* email => string,
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* prefname => string,
* email => string,
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,
* email => string,
* ),
* array(...),
* ),
......@@ -70,13 +70,13 @@ class PluginSearchInternal extends PluginSearch {
if ( is_postgres() ) {
$data = get_rows_sql("
SELECT
id, username, institution, firstname, lastname, prefname, email
id, username, institution, firstname, lastname, preferredname, email
FROM
" . get_config('dbprefix') . "usr u
WHERE
firstname ILIKE '%' || ? || '%'
OR lastname ILIKE '%' || ? || '%'
OR prefname ILIKE '%' || ? || '%'
OR preferredname ILIKE '%' || ? || '%'
OR email ILIKE '%' || ? || '%'
",
array($query_string, $query_string, $query_string, $query_string),
......@@ -92,7 +92,7 @@ class PluginSearchInternal extends PluginSearch {
WHERE
firstname ILIKE '%' || ? || '%'
OR lastname ILIKE '%' || ? || '%'
OR prefname ILIKE '%' || ? || '%'
OR preferredname ILIKE '%' || ? || '%'
OR email ILIKE '%' || ? || '%'
",
array($query_string, $query_string, $query_string, $query_string),
......
......@@ -44,23 +44,24 @@ abstract class PluginSearch {
* limit => integer, // how many results are returned
* offset => integer, // starting from which result
* results => array( // the result records
* array(
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* prefname => string,
* email => string,
* id => integer,
* username => string,
* institution => string,
* firstname => string,
* lastname => string,
* preferredname => string,