Пример #1
0
 /**
  * Unsubscribe user from forum emails
  *
  * @return void
  */
 public function unsubscribe()
 {
     // get the token
     $token = Request::getCmd('t', '');
     //token is required
     if ($token == '') {
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=' . $this->_name), Lang::txt('PLG_GROUPS_FORUM_UNSUBSCRIBE_MISSING_TOKEN'), 'error');
     }
     // get the token lib
     $encryptor = new \Hubzero\Mail\Token();
     // get token details
     $tokenDetails = $encryptor->decryptEmailToken($token);
     // make sure token details are good
     if (empty($tokenDetails) || !isset($tokenDetails[1]) || $this->group->get('gidNumber') != $tokenDetails[1]) {
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=' . $this->_name), Lang::txt('PLG_GROUPS_FORUM_UNSUBSCRIBE_INVALID_TOKEN'), 'error');
     }
     // neede member option lib
     include_once PATH_CORE . DS . 'plugins' . DS . 'groups' . DS . 'memberoptions' . DS . 'memberoption.class.php';
     // Find the user's group settings, do they want to get email (0 or 1)?
     $groupMemberOption = new GroupsTableMemberoption($this->database);
     $groupMemberOption->loadRecord($this->group->get('gidNumber'), $tokenDetails[0], GROUPS_MEMBEROPTION_TYPE_DISCUSSION_NOTIFICIATION);
     // mark that they dont want to be received anymore.
     $groupMemberOption->optionvalue = 0;
     // attempt to update
     if (!$groupMemberOption->save($groupMemberOption)) {
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=' . $this->_name), Lang::txt('PLG_GROUPS_FORUM_UNSUBSCRIBE_UNABLE_TO_UNSUBSCRIBE'), 'error');
     }
     // success
     App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->get('cn') . '&active=' . $this->_name), Lang::txt('PLG_GROUPS_FORUM_UNSUBSCRIBE_SUCCESSFULLY_UNSUBSCRIBED'));
 }
Пример #2
0
 /**
  * Save settings
  *
  * @param      object  $group
  * @param      object  $user
  * @param      integer $recvEmailOptionID
  * @param      integer $recvEmailOptionValue
  * @return     void
  */
 protected function save($group, $user, $recvEmailOptionID, $recvEmailOptionValue)
 {
     $postSaveRedirect = Request::getVar('postsaveredirect', '');
     //instantaite database object
     $database = App::get('db');
     // Save the GROUPS_MEMBEROPTION_TYPE_DISCUSSION_NOTIFICIATION setting
     $row = new GroupsTableMemberoption($database);
     //bind the data
     $rowdata = array('id' => $recvEmailOptionID, 'userid' => $user->id, 'gidNumber' => $group->get('gidNumber'), 'optionname' => GROUPS_MEMBEROPTION_TYPE_DISCUSSION_NOTIFICIATION, 'optionvalue' => $recvEmailOptionValue);
     $row->bind($rowdata);
     // Check content
     if (!$row->check()) {
         $this->setError($row->getError());
         return;
     }
     // Store content
     if (!$row->store()) {
         $this->setError($row->getError());
         return $this->edit();
     }
     if (Request::getInt('no_html')) {
         echo json_encode(array('success' => true));
         exit;
     } else {
         if (!$postSaveRedirect) {
             App::redirect(Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=memberoptions&action=edit'), Lang::txt('You have successfully updated your email settings'));
         } else {
             App::redirect($postSaveRedirect, Lang::txt('You have successfully updated your email settings'));
         }
     }
 }