123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- class CancelgroupAction extends Action
- {
- var $group = null;
-
- function prepare($args)
- {
- parent::prepare($args);
- if (!common_logged_in()) {
-
- $this->clientError(_('You must be logged in to leave a group.'));
- }
- $nickname_arg = $this->trimmed('nickname');
- $id = intval($this->arg('id'));
- if ($id) {
- $this->group = User_group::getKV('id', $id);
- } else if ($nickname_arg) {
- $nickname = common_canonical_nickname($nickname_arg);
-
- if ($nickname_arg != $nickname) {
- $args = array('nickname' => $nickname);
- common_redirect(common_local_url('leavegroup', $args), 301);
- }
- $local = Local_group::getKV('nickname', $nickname);
- if (!$local) {
-
- $this->clientError(_('No such group.'), 404);
- }
- $this->group = User_group::getKV('id', $local->group_id);
- } else {
-
- $this->clientError(_('No nickname or ID.'), 404);
- }
- if (!$this->group) {
-
- $this->clientError(_('No such group.'), 404);
- }
- $cur = common_current_user();
- if (empty($cur)) {
-
- $this->clientError(_('Must be logged in.'), 403);
- }
- if ($this->arg('profile_id')) {
- if ($cur->isAdmin($this->group)) {
- $this->profile = Profile::getKV('id', $this->arg('profile_id'));
- } else {
-
-
- $this->clientError(_('Only group admin can approve or cancel join requests.'), 403);
- }
- } else {
- $this->profile = $cur->getProfile();
- }
- $this->request = Group_join_queue::pkeyGet(array('profile_id' => $this->profile->id,
- 'group_id' => $this->group->id));
- if (empty($this->request)) {
-
-
- $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403);
- }
- return true;
- }
-
- function handle($args)
- {
- parent::handle($args);
- try {
- $this->request->abort();
- } catch (Exception $e) {
- common_log(LOG_ERR, "Exception canceling group sub: " . $e->getMessage());
-
-
- $this->serverError(sprintf(_('Could not cancel request for user %1$s to join group %2$s.'),
- $this->profile->nickname, $this->group->nickname));
- return;
- }
- if ($this->boolean('ajax')) {
- $this->startHTML('text/xml;charset=utf-8');
- $this->elementStart('head');
-
-
- $this->element('title', null, sprintf(_m('TITLE','%1$s left group %2$s'),
- $this->profile->nickname,
- $this->group->nickname));
- $this->elementEnd('head');
- $this->elementStart('body');
- $jf = new JoinForm($this, $this->group);
- $jf->show();
- $this->elementEnd('body');
- $this->endHTML();
- } else {
- common_redirect(common_local_url('groupmembers', array('nickname' => $this->group->nickname)), 303);
- }
- }
- }
|