diff --git a/include/ajax.staff.php b/include/ajax.staff.php index e3fec3a653dea884cce34c13ee19bf84881c5a3b..444f8ebb53d82bc9310b14b27deda0352a13771f 100644 --- a/include/ajax.staff.php +++ b/include/ajax.staff.php @@ -206,4 +206,23 @@ class StaffAjaxAPI extends AjaxController { include STAFFINC_DIR . 'templates/quick-add.tmpl.php'; } + + function setAvatar($id) { + global $thisstaff; + + if (!$thisstaff) + Http::response(403, 'Agent login required'); + if ($id != $thisstaff->getId() && !$thisstaff->isAdmin()) + Http::response(403, 'Access denied'); + if ($id == $thisstaff->getId()) + $staff = $thisstaff; + else + $staff = Staff::lookup((int) $id); + + if (!($avatar = $staff->getAvatar())) + Http::response(404, 'User does not have an avatar'); + + if ($avatar->toggle()) + return $avatar; + } } diff --git a/include/class.avatar.php b/include/class.avatar.php index 6fbfc6b6302a20d6580a527c1db263d4c51b5cf7..3896e7c693b7dc77cb0272d4b214ab8d067b15ff 100644 --- a/include/class.avatar.php +++ b/include/class.avatar.php @@ -31,6 +31,11 @@ abstract class Avatar { function __toString() { return $this->getImageTag(); } + + function isChangeable() { + return false; + } + function toggle() {} } abstract class AvatarSource { @@ -107,13 +112,28 @@ extends Avatar { if (false && ($file = $this->user->getAvatarFile())) return $file->getDownloadUrl(); - // Generate a random string of 0-6 chars for the avatar signature - $uid = md5(strtolower($this->user->getEmail())); + $code = false; + if (method_exists($this->user, 'getExtraAttr')) + $code = $this->user->getExtraAttr('avatar'); + + if ($code) + $uid = md5($code); + else + // Generate a random string of 0-6 chars for the avatar signature + $uid = md5(strtolower($this->user->getEmail())); + return ROOT_PATH . 'avatar.php?'.Http::build_query(array('uid'=>$uid, 'mode' => $this->mode)); } - static function serveRandomAvatar($uid, $mode) { + function toggle() { + $code = Misc::randCode(21); + $this->user->setExtraAttr('avatar', $code); + return $this->user->save(); + } + + function isChangeable() { + return true; } } diff --git a/include/staff/profile.inc.php b/include/staff/profile.inc.php index 1662cd901e8efd2414a1ec75d71be0161cf2e84d..b707371368b06a3e7038361a1ccab38291915bad 100644 --- a/include/staff/profile.inc.php +++ b/include/staff/profile.inc.php @@ -18,8 +18,26 @@ if(!defined('OSTSTAFFINC') || !$staff || !$thisstaff) die('Access Denied'); <table class="table two-column" width="940" border="0" cellspacing="0" cellpadding="2"> <tbody> <tr><td colspan="2"><div> - <div class="avatar pull-left" style="margin: 10px 15px; border-radius: 5px; width: 100px;"> - <?php echo $staff->getAvatar(); ?> + <div class="avatar pull-left" style="margin: 10px 15px; width: 100px;"> +<?php $avatar = $staff->getAvatar(); + echo $avatar; +if ($avatar->isChangeable()) { ?> + <div style="text-align: center"> + <a class="button no-pjax" + href="#ajax.php/staff/<?php echo $staff->getId(); ?>/avatar/change" + onclick="javascript: + event.preventDefault(); + var a = this; + $.ajax({ + url: $(this).attr('href').substr(1), + success: function(html) { + $(a).closest('.avatar').find('img').replaceWith($(html)); + } + }); + return false;"><i class="icon-retweet"></i></a> + </div> +<?php +} ?> </div> <table class="table two-column" border="0" cellspacing="2" cellpadding="2" style="width:760px"> <tr> diff --git a/include/staff/staff.inc.php b/include/staff/staff.inc.php index 767e00bfcc3ab11c3f4bab59b7dd5ede4347e5c8..020e281622c359deb25df76694bc9440ea3a1bfa 100644 --- a/include/staff/staff.inc.php +++ b/include/staff/staff.inc.php @@ -58,7 +58,7 @@ else { <table class="table two-column" width="940" border="0" cellspacing="0" cellpadding="2"> <tbody> <tr><td colspan="2"><div> - <div class="avatar pull-left" style="width: 100px; margin: 10px; border-radius: 5px"> + <div class="avatar pull-left" style="width: 100px; margin: 10px;"> <?php echo $staff->getAvatar(); ?> </div> <table class="table two-column" border="0" cellspacing="2" cellpadding="2" style="width: 760px"> diff --git a/include/staff/templates/user.tmpl.php b/include/staff/templates/user.tmpl.php index 9400e4f93de8ed5ea0f96d5ffca19ba6a170f0a4..b1debfd90653b08fb1669c8a410c09460af73630 100644 --- a/include/staff/templates/user.tmpl.php +++ b/include/staff/templates/user.tmpl.php @@ -16,7 +16,9 @@ if ($info['error']) { echo sprintf('<p id="msg_notice">%s</p>', $info['msg']); } ?> <div id="user-profile" style="display:<?php echo $forms ? 'none' : 'block'; ?>;margin:5px;"> - <i class="icon-user icon-4x pull-left icon-border"></i> + <div class="avatar pull-left" style="margin: 0 10px;"> + <?php echo $user->getAvatar(); ?> + </div> <?php if ($ticket) { ?> <a class="action-button pull-right change-user" style="overflow:inherit" diff --git a/include/staff/user-view.inc.php b/include/staff/user-view.inc.php index 7c894ca6dc2fc6ad74657bc3c99f3c5c4cb6ae9b..4d02b3d66d166a9be7965ace9e6cdeab3ff9a72c 100644 --- a/include/staff/user-view.inc.php +++ b/include/staff/user-view.inc.php @@ -77,7 +77,10 @@ $org = $user->getOrganization(); </td> </tr> </table> -<table class="ticket_info" cellspacing="0" cellpadding="0" width="940" border="0"> +<div class="avatar pull-left" style="margin: 10px; width: 80px;"> + <?php echo $user->getAvatar(); ?> +</div> +<table class="ticket_info" cellspacing="0" cellpadding="0" width="830" border="0"> <tr> <td width="50%"> <table border="0" cellspacing="" cellpadding="4" width="100%"> diff --git a/scp/ajax.php b/scp/ajax.php index 5df6b35b966831f028f5e6c2e59c6653e91a55b1..c20995c61baabea70fe934dd849ee0f96d0b40b5 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -245,7 +245,8 @@ $dispatcher = patterns('', url('^/(?P<id>\d+)/change-password$', 'changePassword'), url_get('^/(?P<id>\d+)/perms', 'getAgentPerms'), url('^/reset-permissions', 'resetPermissions'), - url('^/change-department', 'changeDepartment') + url('^/change-department', 'changeDepartment'), + url('^/(?P<id>\d+)/avatar/change', 'setAvatar') )) ); diff --git a/scp/css/scp.css b/scp/css/scp.css index 313041d7364c96d15a80ae1522519dbf50339b89..690ebe063ee4eac9b98c19e32dbc825e258cfe95 100644 --- a/scp/css/scp.css +++ b/scp/css/scp.css @@ -875,7 +875,9 @@ h2 .reload { display:inline-block; width:48px; height:auto; - border-radius: 5px; +} +.avatar { + border-radius: 12%; } .thread-entry.message > .avatar { margin-left: initial;