/** * Execute the action. */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendProfilesModel::exists($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get item $profile = BackendProfilesModel::get($this->id); // already blocked? Prolly want to unblock then if ($profile['status'] === 'blocked') { // set profile status to active BackendProfilesModel::update($this->id, array('status' => 'active')); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_unblock', array('id' => $this->id)); // redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=profile-unblocked&var=' . urlencode($profile['email']) . '&highlight=row-' . $this->id); } else { // delete profile session that may be active BackendProfilesModel::deleteSession($this->id); // set profile status to blocked BackendProfilesModel::update($this->id, array('status' => 'blocked')); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_block', array('id' => $this->id)); // redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=profile-blocked&var=' . urlencode($profile['email']) . '&highlight=row-' . $this->id); } } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * Validate the form. */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // get field $txtName = $this->frm->getField('name'); // name filled in? if ($txtName->isFilled(BL::getError('NameIsRequired'))) { // name exists? if (BackendProfilesModel::existsGroupName($txtName->getValue())) { // set error $txtName->addError(BL::getError('GroupNameExists')); } } // no errors? if ($this->frm->isCorrect()) { // build item $values['name'] = $txtName->getValue(); // insert values $id = BackendProfilesModel::insertGroup($values); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_group', array('item' => $values)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('groups') . '&report=group-added&var=' . urlencode($values['name']) . '&highlight=row-' . $id); } } }
/** * Execute the action. * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // action to execute $action = SpoonFilter::getGetValue('action', array('addToGroup', 'delete'), ''); $ids = isset($_GET['id']) ? (array) $_GET['id'] : array(); $newGroupId = SpoonFilter::getGetValue('newGroup', array_keys(BackendProfilesModel::getGroups()), ''); // at least one id if (!empty($ids)) { // delete the given profiles if ($action === 'delete') { BackendProfilesModel::delete($ids); $report = 'deleted'; } elseif ($action === 'addToGroup') { // for which we need a group of course if ($newGroupId != '') { // set new status foreach ($ids as $id) { // profile must exist if (BackendProfilesModel::exists($id)) { // make sure the user is not already part of this group without an expiration date foreach (BackendProfilesModel::getProfileGroups($id) as $existingGroup) { // if he is, skip to the next user if ($existingGroup['group_id'] === $newGroupId) { continue 2; } } // OK, it's safe to add the user to this group BackendProfilesModel::insertProfileGroup(array('profile_id' => $id, 'group_id' => $newGroupId, 'starts_on' => BackendModel::getUTCDate())); } } // report $report = 'added-to-group'; } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=no-group-selected'); } } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=unknown-action'); } // report $report = (count($ids) > 1 ? 'profiles-' : 'profile-') . $report; // redirect $this->redirect(BackendModel::createURLForAction('index', null, null, array('offset' => SpoonFilter::getGetValue('offset', null, ''), 'order' => SpoonFilter::getGetValue('order', null, ''), 'sort' => SpoonFilter::getGetValue('sort', null, ''), 'email' => SpoonFilter::getGetValue('email', null, ''), 'status' => SpoonFilter::getGetValue('status', null, ''), 'group' => SpoonFilter::getGetValue('group', null, ''))) . '&report=' . $report); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=no-profiles-selected'); } }
/** * Execute the action. */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendProfilesModel::existsGroup($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get group $group = BackendProfilesModel::getGroup($this->id); // delete group BackendProfilesModel::deleteGroup($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_group', array('id' => $this->id)); // group was deleted, so redirect $this->redirect(BackendModel::createURLForAction('groups') . '&report=deleted&var=' . urlencode($group['name'])); } else { $this->redirect(BackendModel::createURLForAction('groups') . '&error=non-existing'); } }
/** * Execute the action. */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendProfilesModel::existsProfileGroup($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get profile group $profileGroup = BackendProfilesModel::getProfileGroup($this->id); // delete profile group BackendProfilesModel::deleteProfileGroup($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_profile_delete_from_group', array('id' => $this->id)); // profile group was deleted, so redirect $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $profileGroup['profile_id'] . '&report=membership-deleted#tabGroups'); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * Validate the form. */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // get fields $ddmGroup = $this->frm->getField('group'); $txtExpirationDate = $this->frm->getField('expiration_date'); $txtExpirationTime = $this->frm->getField('expiration_time'); // fields filled? $ddmGroup->isFilled(BL::getError('FieldIsRequired')); if ($txtExpirationDate->isFilled()) { $txtExpirationDate->isValid(BL::getError('DateIsInvalid')); } if ($txtExpirationTime->isFilled()) { $txtExpirationTime->isValid(BL::getError('TimeIsInvalid')); } // no errors? if ($this->frm->isCorrect()) { // build item $values['profile_id'] = $this->id; $values['group_id'] = $ddmGroup->getSelected(); $values['starts_on'] = BackendModel::getUTCDate(); // only format date if not empty if ($txtExpirationDate->isFilled() && $txtExpirationTime->isFilled()) { // format date $values['expires_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($txtExpirationDate, $txtExpirationTime)); } // insert values $id = BackendProfilesModel::insertProfileGroup($values); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_profile_add_to_group', array('item' => $values)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $values['profile_id'] . '&report=membership-added&highlight=row-' . $id . '#tabGroups'); } } }
/** * Load the form. * * @return void */ private function loadForm() { // create form $this->frm = new BackendForm('filter', BackendModel::createURLForAction(), 'get'); // values for dropdowns $status = BackendProfilesModel::getStatusForDropDown(); $groups = BackendProfilesModel::getGroups(); // add fields $this->frm->addText('email', $this->filter['email']); $this->frm->addDropdown('status', $status, $this->filter['status']); $this->frm->getField('status')->setDefaultElement(''); // add a group filter if wa have groups if (!empty($groups)) { $this->frm->addDropdown('group', $groups, $this->filter['group']); $this->frm->getField('group')->setDefaultElement(''); } // manually parse fields $this->frm->parse($this->tpl); }
/** * Validate the form * * @return void */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // get fields $txtEmail = $this->frm->getField('email'); $txtDisplayName = $this->frm->getField('display_name'); $txtPassword = $this->frm->getField('password'); $txtFirstName = $this->frm->getField('first_name'); $txtLastName = $this->frm->getField('last_name'); $txtCity = $this->frm->getField('city'); $ddmGender = $this->frm->getField('gender'); $ddmDay = $this->frm->getField('day'); $ddmMonth = $this->frm->getField('month'); $ddmYear = $this->frm->getField('year'); $ddmCountry = $this->frm->getField('country'); // email filled in? if ($txtEmail->isFilled(BL::getError('EmailIsRequired'))) { // valid email? if ($txtEmail->isEmail(BL::getError('EmailIsInvalid'))) { // email already exists? if (BackendProfilesModel::existsByEmail($txtEmail->getValue(), $this->id)) { // set error $txtEmail->addError(BL::getError('EmailExists')); } } } // display name filled in? if ($txtDisplayName->isFilled(BL::getError('DisplayNameIsRequired'))) { // display name already exists? if (BackendProfilesModel::existsDisplayName($txtDisplayName->getValue(), $this->id)) { // set error $txtDisplayName->addError(BL::getError('DisplayNameExists')); } } // one of the bday fields are filled in if ($ddmDay->isFilled() || $ddmMonth->isFilled() || $ddmYear->isFilled()) { // valid date? if (!checkdate($ddmMonth->getValue(), $ddmDay->getValue(), $ddmYear->getValue())) { // set error $ddmYear->addError(BL::getError('DateIsInvalid')); } } // no errors? if ($this->frm->isCorrect()) { // build item $values['email'] = $txtEmail->getValue(); // only update if display name changed if ($txtDisplayName->getValue() != $this->profile['display_name']) { $values['display_name'] = $txtDisplayName->getValue(); $values['url'] = BackendProfilesModel::getUrl($txtDisplayName->getValue(), $this->id); } // new password filled in? if ($txtPassword->isFilled()) { // get new salt $salt = BackendProfilesModel::getRandomString(); // update salt BackendProfilesModel::setSetting($this->id, 'salt', $salt); // build password $values['password'] = BackendProfilesModel::getEncryptedString($txtPassword->getValue(), $salt); } // update values BackendProfilesModel::update($this->id, $values); // bday is filled in if ($ddmYear->isFilled()) { // mysql format $birthDate = $ddmYear->getValue() . '-'; $birthDate .= str_pad($ddmMonth->getValue(), 2, '0', STR_PAD_LEFT) . '-'; $birthDate .= str_pad($ddmDay->getValue(), 2, '0', STR_PAD_LEFT); } else { $birthDate = null; } // update settings BackendProfilesModel::setSetting($this->id, 'first_name', $txtFirstName->getValue()); BackendProfilesModel::setSetting($this->id, 'last_name', $txtLastName->getValue()); BackendProfilesModel::setSetting($this->id, 'gender', $ddmGender->getValue()); BackendProfilesModel::setSetting($this->id, 'birth_date', $birthDate); BackendProfilesModel::setSetting($this->id, 'city', $txtCity->getValue()); BackendProfilesModel::setSetting($this->id, 'country', $ddmCountry->getValue()); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $values)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=saved&var=' . urlencode($values['email']) . '&highlight=row-' . $this->id); } } }