Commit 44146dbd authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

new profile page

parent 41703701
......@@ -202,6 +202,7 @@ $string['friend'] = 'friend';
$string['friends'] = 'friends';
$string['user'] = 'user';
$string['users'] = 'users';
$string['Friends'] = 'Friends';
$string['friendlistfailure'] = 'Failed to modify your friends list';
$string['userdoesntwantfriends'] = 'This user doesn\'t want any new friends';
......@@ -220,6 +221,12 @@ $string['sendfriendshiprequest'] = 'Send %s a friendship request';
$string['cantdenyrequest'] = 'That is not a valid friendship request';
$string['cantrequestfrienship'] = 'You cannot request frienship from this user';
$string['cantmessageuser'] = 'You cannot send this user a message';
$string['requestedfriendship'] = 'requested friendship';
$string['notinanygroups'] = 'Not in any groups';
$string['numberoffriends'] = 'Friends (%s of %s)';
$string['addusertogroup'] = 'Add to ';
$string['inviteusertojoingroup'] = 'Invite to ';
$string['invitemembertogroup'] = 'Invite %s to join \'%s\'';
// Group interactions
$string['groupinteractions'] = 'Group Interactions';
......
......@@ -1144,6 +1144,19 @@ a.folderhover {
width: 40%;
}
/* View User styles */
.friends table {
width: 320px;
}
.friendcell {
vertical-align: top;
text-align: center;
width: 25%;
font-size: smaller;
}
/* Groups I'm in and Groups I own styles */
.maincontent .addgrouplink {
margin: 10px 0 10px 0;
......
......@@ -2,47 +2,107 @@
{include file="sidebar.tpl"}
{include file="columnleftstart.tpl"}
<div id="userview">
<h3>{$NAME|escape}</h3>
<div id="userview">
<h2>
{$NAME|escape}
{if $relationship && $relationship != 'none'}
- {str tag=$relationship section='group'}
{/if}
</h2>
<div>
<table id="userview_profile"><tbody>
{foreach from=$USERFIELDS name=userfields key=key item=item}
<tr>{if $smarty.foreach.userfields.first}
<td style="width: 100px;" rowspan="{$smarty.foreach.userfields.total+1}">
<img src="{$WWWROOT}thumb.php?type=profileicon&maxsize=100&id={$USERID}" alt="">
</td>{/if}
<th>{str section=artefact.internal tag=$key}</th><td>{$item}</td>
</tr>
{/foreach}
</tbody></table>
<div class="fr">
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=100&amp;id={$USERID}" alt="">
{if $canmessage}
<br>
<a href="{$WWWROOT}user/sendmessage.php?id={$USERID}">{str tag='sendmessage' section='group'}</a>
{/if}
{if $relationship == 'existingfriend'}
<br>
<a href="{$WWWROOT}user/removefriend.php?id={$USERID}">{str tag='removefromfriendslist' section='group'}</a>
{elseif $relationship == 'none' && $friendscontrol == 'auto'}
{$newfriendform}
{elseif $relationship == 'none' && $friendscontrol == 'auth'}
<br>
<a href="{$WWWROOT}user/requestfriendship.php?id={$USERID}">{str tag='requestfriendship' section='group'}</a>
{/if}
{if $inviteform}
{$inviteform}
{/if}
{if $addform}
{$addform}
{/if}
</div>
{$introduction}
{foreach from=$USERFIELDS name=userfields key=key item=item}
<p><strong>{str section=artefact.internal tag=$key}:</strong> {$item}</p>
{/foreach}
{if $relationship == 'pending'}
<div class="message">
{str tag='whymakemeyourfriend' section='group'} {$reason}
{$requestform}
</div>
{/if}
<h5>{str section=mahara tag=views}</h6>
{if $VIEWS}
<table>
{foreach from=$VIEWS item=item name=view}
<tr>
<td>
<h6><a href="{$WWWROOT}view/view.php?id={$item->id}">{$item->title|escape}</a></h6>
<span>
{if $item->description}
{$item->description}
{/if}
{if $item->description && $item->artefacts}<br>{/if}
{if $item->artefacts}
<strong>{str tag="artefacts" section="view"}:</strong>
{foreach from=$item->artefacts item=artefact name=artefacts}<a href="{$WWWROOT}view/artefact.php?artefact={$artefact.id}&amp;view={$item->id}">{$artefact.title|escape}</a>{if !$smarty.foreach.artefacts.last}, {/if}{/foreach}
{/if}
</span>
</td>
</tr>
{/foreach}
</table>
{else}
{str tag='noviewstosee' section='group'}
{/if}
</ul>
<h6>{str section=mahara tag=groups}</h6>
{if $USERGROUPS}
<table>
{foreach from=$USERGROUPS item=item}
<tr>
<td>
<h6><a href="{$WWWROOT}group/view.php?id={$item->id}">{$item->name|escape}</a> - {str tag=$item->type section=group}</h6>
{if $item->description}
{$item->description}
{/if}
</td>
</tr>
{/foreach}
</table>
{else}
{str tag='notinanygroups' section='group'}
{/if}
<h6>{$friendsmessage}</h6>
<div class="friends">
<table>
{foreach from=$friends item=row}
<tr>
{foreach from=$row item=friend}
<td class="friendcell">
<a href="{$WWWROOT}user/view.php?id={$friend}">
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=60&amp;id={$friend}" alt="">
<br>{$friend|display_name|escape}
</a>
</td>
{/foreach}
</tr>
{/foreach}
</table>
</div>
</div>
{if $VIEWS}
<table id="userview_views"><thead><tr><th>
{str section=mahara tag=views}
</td></tr></thead>
<tbody><tr><td><ul>
{foreach from=$VIEWS key=key item=item name=view}
<li><a href="{$WWWROOT}view/view.php?id={$key}">{$item|escape}</a></li>
{/foreach}
</ul></td></tr></tbody></table>
{/if}
{if $USERGROUPS}
<table id="userview_groups"><thead><tr><th colspan=2>
{str section=mahara tag=groups}
</td></tr></thead>
<tbody>
{foreach from=$USERGROUPS item=item}
<tr><td><a href="{$WWWROOT}group/view.php?id={$item->id}">{$item->name|escape}</a></td><td>{str tag=$item->type section=group}</td></tr>
{/foreach}
</tbody></table>
{/if}
<br>
{$INVITEFORM}
{$ADDFORM}
{$FRIENDFORM}
{$MESSAGEFORM}
</div>
</div>
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
......@@ -30,54 +30,6 @@ require_once('pieforms/pieform.php');
$userid = param_integer('id','');
$loggedinid = $USER->get('id');
$inlinejs = <<<EOF
function messageform_success(formname, data) {
swapDOM(formname, P(null, data.message));
return true;
}
function usercontrol_success(formname, data) {
if (formname != 'friend') {
var dd = $(formname).elements['group'];
if (dd.nodeName == 'INPUT') {
$(formname).style.display = 'none';
return true;
}
if (dd.nodeName == 'SELECT') {
if (dd.options.length == 1) {
$(formname).style.display = 'none';
return true;
}
else {
removeElement(dd.options[dd.selectedIndex]);
if (dd.length > 0) {
return true;
}
}
}
}
swapDOM(formname, P(null, data.message));
return true;
}
function friendship_accept_reject(formname, data) {
var oldcount = parseInt($('pendingfriendscount').innerHTML);
var newcount = oldcount - 1;
var messagenode = $('pendingfriendsmessage');
if (newcount == 1) { // jump through hoops to change between plural and singular
messagenode.innerHTML = get_string('pendingfriend');
}
else {
messagenode.innerHTML = get_string('pendingfriends');
}
$('pendingfriendscount').innerHTML = newcount;
usercontrol_success(formname, data);
}
EOF;
// Get the user's details
......@@ -136,12 +88,56 @@ if (isset($userfields['country'])) {
$userfields['country'] = get_string('country.' . $userfields['country']);
}
if (isset($userfields['firstname'])) {
unset($userfields['firstname']);
}
if (isset($userfields['lastname'])) {
unset($userfields['lastname']);
}
if (isset($userfields['introduction'])) {
$introduction = $userfields['introduction'];
unset($userfields['introduction']);
}
// Get viewable views
$views = array();
if ($allviews = get_records_array('view', 'owner', $userid)) {
foreach ($allviews as $view) {
if (can_view_view($view->id)) {
$views[$view->id] = $view->title;
$views[$view->id] = $view;
$view->artefacts = array();
$view->description = format_description($view->description);
}
}
}
if ($views) {
$viewidlist = implode(', ', array_map(create_function('$a', 'return $a->id;'), $views));
$artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin
FROM {view_artefact} va
INNER JOIN {artefact} a ON va.artefact = a.id
INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name
WHERE va.view IN (' . $viewidlist . ')
GROUP BY 1, 2, 3, 4, 5
ORDER BY a.title, va.artefact', '');
if ($artefacts) {
foreach ($artefacts as $artefactrec) {
safe_require('artefact', $artefactrec->plugin);
// Perhaps I shouldn't have to construct the entire
// artefact object to render the name properly.
$classname = generate_artefact_class_name($artefactrec->artefacttype);
$artefactobj = new $classname(0, array('title' => $artefactrec->title));
$artefactobj->set('dirty', false);
if (!$artefactobj->in_view_list()) {
continue;
}
$artname = $artefactobj->display_title(30);
if (strlen($artname)) {
$views[$artefactrec->view]->artefacts[] = array('id' => $artefactrec->artefact,
'title' => $artname);
}
}
}
}
......@@ -151,6 +147,35 @@ if (!$userassocgroups = get_associated_groups($userid)) {
$userassocgroups = array();
}
foreach ($userassocgroups as $group) {
$group->description = format_description($group->description);
}
if (is_postgres()) {
$random = 'RANDOM()';
}
else if (is_mysql()) {
$random = 'RAND()';
}
$records = get_records_select_array('usr_friend', 'usr1 = ? OR usr2 = ?', array($userid, $userid), $random, 'usr1, usr2', 0, 16);
$numberoffriends = count_records_select('usr_friend', 'usr1 = ? OR usr2 = ?', array($userid, $userid));
$friendsmessage = get_string('numberoffriends', 'group', $records ? count($records) : 0, $numberoffriends);
// get the friends into a 4x4 array
$friends = array();
for ($i = 0; $i < 4; $i++) {
$friends[$i] = array();
for($j = 4 * $i; $j < ($i + 1 ) * 4; $j++) {
if (isset($records[$j])) {
if ($records[$j]->usr1 == $userid) {
$friends[$i][] = $records[$j]->usr2;
}
else {
$friends[$i][] = $records[$j]->usr1;
}
}
}
}
$smarty = smarty();
if ($loggedinid != $userid) {
......@@ -168,12 +193,12 @@ if ($loggedinid != $userid) {
$default = $default[0];
$inviteform = pieform(array(
'name' => 'invite',
'jsform' => true,
'jssuccesscallback' => 'usercontrol_success',
'successcallback' => 'invite_submit',
'renderer' => 'div',
'elements' => array(
'group' => array(
'type' => 'select',
'title' => get_string('inviteusertojoingroup'),
'title' => get_string('inviteusertojoingroup', 'group'),
'collapseifoneoption' => false,
'options' => $invitelist,
'defaultvalue' => $default,
......@@ -184,11 +209,11 @@ if ($loggedinid != $userid) {
),
'submit' => array(
'type' => 'submit',
'value' => get_string('sendinvitation'),
'value' => get_string('sendinvitation', 'group'),
),
),
));
$smarty->assign('INVITEFORM',$inviteform);
$smarty->assign('inviteform',$inviteform);
}
}
......@@ -206,203 +231,114 @@ if ($loggedinid != $userid) {
$default = $default[0];
$addform = pieform(array(
'name' => 'addmember',
'jsform' => true,
'jssuccesscallback' => 'add_success',
'successcallback' => 'addmember_submit',
'renderer' => 'div',
'elements' => array(
'group' => array(
'type' => 'select',
'title' => get_string('addusertogroup'),
'title' => get_string('addusertogroup', 'group'),
'collapseifoneoption' => false,
'options' => $controlledlist,
'defaultvalue' => $default,
),
'id' => array(
'type' => 'hidden',
'value' => $userid,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('add'),
),
),
));
$inlinejs .= <<<EOF
function add_success(data) {
usercontrol_success('addmember');
}
EOF;
$smarty->assign('ADDFORM',$addform);
$smarty->assign('addform',$addform);
}
}
// adding this user to the currently logged in user's friends list
// or removing or approving or rejecting or whatever else we can do.
$friendform = array(
'name' => 'friend',
'jsform' => true,
'elements' => array(),
'jssuccesscallback' => 'usercontrol_success',
);
$friendsubmit = '';
$friendtype = '';
$friendformmessage = '';
// already a friend ... we can remove.
if ($is_friend) {
$friendtype = 'remove';
$friendsubmit = get_string('removefromfriendslist');
}
// if there's a friends request already
else if ($request = get_friend_request($userid, $loggedinid)) {
if ($request->owner == $userid) {
$friendformmessage = get_string('friendshipalreadyrequested', 'mahara', $name);
}
else {
$friendform['jssuccesscallback'] = 'friendship_accept_reject';
$friendform['elements']['requested'] = array(
'type' => 'html',
'value' => get_string('friendshipalreadyrequestedowner', 'mahara', $name)
);
$friendform['elements']['rejectreason'] = array(
'type' => 'textarea',
'title' => get_string('rejectfriendshipreason'),
'cols' => 50,
'rows' => 4,
);
$friendsubmit = get_string('accept');
$friendform['elements']['rejectsubmit'] = array(
'type' => 'submit',
'value' => get_string('reject'),
);
$friendtype = 'accept';
}
$relationship = 'existingfriend';
}
// check the preference
else {
$friendscontrol = get_account_preference($userid, 'friendscontrol');
if ($friendscontrol == 'nobody') {
$friendtype = '';
$friendformmessage = get_string('userdoesntwantfriends');
}
else if ($friendscontrol == 'auth') {
$friendform['elements']['reason'] = array(
'type' => 'textarea',
'title' => get_string('requestfriendship'),
'cols' => 50,
'rows' => 4,
);
$friendsubmit = get_string('request');
$friendtype = 'request';
} else {
$friendsubmit = get_string('addtofriendslist');
$friendtype = 'add';
}
else if (record_exists('usr_friend_request', 'requester', $loggedinid, 'owner', $userid)) {
$relationship = 'requestedfriendship';
}
$messagepref = get_account_preference($userid, 'messages');
if (($is_friend && $messagepref == 'friends') || $messagepref == 'allow' || $USER->get('admin')) {
$messageform = array(
'name' => 'messageform',
'jsform' => true,
'jssuccesscallback' => 'messageform_success',
else if ($record = get_record('usr_friend_request', 'requester', $userid, 'owner', $loggedinid)) {
$relationship = 'pending';
$requestform = pieform(array(
'name' =>'approve_deny_friendrequest',
'renderer' => 'oneline',
'autofocus' => false,
'elements' => array(
'body' => array(
'type' => 'textarea',
'title' => get_string('messagebody'),
'cols' => 50,
'rows' => 4,
'rules' => array(
'required' => true,
),
'approve' => array(
'type' => 'submit',
'value' => get_string('approverequest', 'group'),
),
'submit' => array(
'deny' => array(
'type' => 'submit',
'value' => get_string('sendmessage'),
),
),
);
}
}
// if we have a form to display, do it
if (!empty($friendtype)) {
$friendform['elements']['type'] = array(
'type' => 'hidden',
'value' => $friendtype,
);
$friendform['elements']['id'] = array(
'type' => 'hidden',
'value' => $userid,
);
$friendform['elements']['submit'] = array(
'type' => 'submit',
'value' => $friendsubmit,
);
// friend submit function lives in lib/user.php
$friendform = pieform($friendform);
}
else {
$friendform = '';
if (!empty($friendformmessage)) {
$friendform = $friendformmessage;
'value' => get_string('denyrequest', 'group')
)
)
));
$smarty->assign('reason', $record->reason);
$smarty->assign('requestform', $requestform);
}
}
else {
$relationship = 'none';
$friendscontrol = get_account_preference($userid, 'friendscontrol');
if ($friendscontrol == 'auto') {
$newfriendform = pieform(array(
'name' => 'addfriend',
'autofocus' => false,
'renderer' => 'div',
'elements' => array(
'add' => array(
'type' => 'submit',
'value' => get_string('addtomyfriends', 'group')
),
'id' => array(
'type' => 'hidden',
'value' => $userid
)
)
));
$smarty->assign('newfriendform', $newfriendform);
}
$smarty->assign('friendscontrol', $friendscontrol);
}
$smarty->assign('relationship', $relationship);
if (!empty($messageform)) {
$messageform = pieform($messageform);
}
else {
$messageform = '';
}
$smarty->assign('FRIENDFORM', $friendform);
$smarty->assign('MESSAGEFORM', $messageform);
$smarty->assign('INLINEJAVASCRIPT', $inlinejs);
if (isset($introduction)) {
$smarty->assign('introduction', $introduction);
}
$smarty->assign('canmessage', can_send_message($userid, $loggedinid));
$smarty->assign('NAME',$name);
$smarty->assign('USERID', $userid);
$smarty->assign('USERFIELDS',$userfields);
if ($USER->get('admin')) {
$smarty->assign('USERGROUPS',$userassocgroups);
}
$smarty->assign('USERGROUPS',$userassocgroups);
$smarty->assign('VIEWS',$views);
$smarty->assign('friends', $friends);
$smarty->assign('friendsmessage', $friendsmessage);
$smarty->display('user/view.tpl');
////////// Functions to process ajax callbacks //////////
function format_description($description) {
$description = strip_tags($description);
// Note: the lengths are different to prevent chopping off just one or two characters in order to add an ellipsis
if (strlen($description) < 110) {
return $description;
}
return substr($description, 0, 100) . '...';
}
// Send an invitation to the user to join a group
function invite_submit(Pieform $form, $values) {
global $USER;
$data = new StdClass;
$data->group = $values['group'];
$data->member= $values['id'];
$data->ctime = db_format_timestamp(time());
$data->tutor = 0;
$ctitle = get_field('group', 'name', 'id', $data->group);
$adduser = get_record('usr', 'id', $data->member);
try {
insert_record('group_member_invite', $data);
$lang = get_user_language($values['id']);
activity_occurred('maharamessage',