Author: Dieter Vanden Eynde (dieter.vandeneynde@netlash.com)
Author: Jeroen Desloovere (jeroen@siesqo.be)
Exemple #1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // get fields
         $ddmGroup = $this->frm->getField('group');
         $fileFile = $this->frm->getField('file');
         $csv = array();
         // validate input
         $ddmGroup->isFilled(BL::getError('FieldIsRequired'));
         if ($fileFile->isFilled(BL::err('FieldIsRequired'))) {
             if ($fileFile->isAllowedExtension(array('csv'), sprintf(BL::getError('ExtensionNotAllowed'), 'csv'))) {
                 $csv = Csv::fileToArray($fileFile->getTempFileName());
                 if ($csv === false) {
                     $fileFile->addError(BL::getError('InvalidCSV'));
                 }
             }
         }
         if ($this->frm->isCorrect()) {
             // import the profiles
             $overwrite = $this->frm->getField('overwrite_existing')->isChecked();
             $statistics = BackendProfilesModel::importCsv($csv, $ddmGroup->getValue(), $overwrite);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_import', array('statistics' => $statistics));
             // build redirect url with the right message
             $redirectUrl = BackendModel::createURLForAction('index') . '&report=';
             $redirectUrl .= $overwrite ? 'profiles-imported-and-updated' : 'profiles-imported';
             $redirectUrl .= '&var[]=' . $statistics['count']['inserted'];
             $redirectUrl .= '&var[]=' . $statistics['count']['exists'];
             // everything is saved, so redirect to the overview
             $this->redirect($redirectUrl);
         }
     }
 }
Exemple #2
0
 /**
  * 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');
     }
 }
Exemple #3
0
 /**
  * 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
         /** @var $txtName \SpoonFormText */
         $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=' . rawurlencode($values['name']) . '&highlight=row-' . $id);
         }
     }
 }
Exemple #4
0
 /**
  * Execute the action.
  */
 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()), '');
     // no ids provided
     if (empty($ids)) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=no-profiles-selected');
     }
     // delete the given profiles
     if ($action === 'delete') {
         BackendProfilesModel::delete($ids);
         $report = 'deleted';
     } elseif ($action === 'addToGroup') {
         // add the profiles to the given group
         // no group id provided
         if ($newGroupId == '') {
             $this->redirect(BackendModel::createURLForAction('Index') . '&error=no-group-selected');
         }
         // 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 {
         // unknown action
         $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);
 }
 /**
  * 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');
     }
 }
Exemple #6
0
 /**
  * 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=' . rawurlencode($group['name']));
     } else {
         $this->redirect(BackendModel::createURLForAction('Groups') . '&error=non-existing');
     }
 }
Exemple #7
0
 /**
  * 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');
         }
     }
 }
Exemple #8
0
 /**
  * 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
         $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())) {
                     // 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())) {
                 // set error
                 $txtDisplayName->addError(BL::getError('DisplayNameExists'));
             }
         }
         // profile must not be notified, password must not be empty
         if (!$this->notifyProfile) {
             $txtPassword->isFilled(BL::err('FieldIsRequired'));
         }
         // one of the birthday 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()) {
             $salt = BackendProfilesModel::getRandomString();
             $password = $txtPassword->isFilled() ? $txtPassword->getValue() : BackendModel::generatePassword(8);
             // build item
             $values = array('email' => $txtEmail->getValue(), 'registered_on' => BackendModel::getUTCDate(), 'display_name' => $txtDisplayName->getValue(), 'url' => BackendProfilesModel::getUrl($txtDisplayName->getValue()), 'last_login' => BackendModel::getUTCDate(null, 0), 'password' => BackendProfilesModel::getEncryptedString($password, $salt));
             $this->id = BackendProfilesModel::insert($values);
             // update salt
             BackendProfilesModel::setSetting($this->id, 'salt', $salt);
             // 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 {
                 // not filled in
                 $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());
             // notify values
             $notifyValues = array_merge($values, array('id' => $this->id, 'first_name' => $txtFirstName->getValue(), 'last_name' => $txtLastName->getValue(), 'unencrypted_password' => $password));
             $redirectUrl = BackendModel::createURLForAction('Edit') . '&id=' . $this->id . '&var=' . rawurlencode($values['display_name']) . '&report=';
             // notify new profile user
             if ($this->notifyProfile) {
                 BackendProfilesModel::notifyProfile($notifyValues);
                 $redirectUrl .= 'saved-and-notified';
             } else {
                 $redirectUrl .= 'saved';
             }
             // notify admin
             if ($this->notifyAdmin) {
                 BackendProfilesModel::notifyAdmin($notifyValues);
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $values));
             // everything is saved, so redirect to the overview
             $this->redirect($redirectUrl);
         }
     }
 }
Exemple #9
0
 /**
  * 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
         $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);
             // birthday 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);
         }
     }
 }
Exemple #10
0
 /**
  * Load the form.
  */
 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);
 }
Exemple #11
0
 /**
  * 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
         $chkNewEmail = $this->frm->getField('new_email');
         $txtEmail = $this->frm->getField('email');
         $txtDisplayName = $this->frm->getField('display_name');
         $chkNewPassword = $this->frm->getField('new_password');
         $txtPassword = $this->frm->getField('password');
         $txtPasswordRepeat = $this->frm->getField('password_repeat');
         $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 ($chkNewEmail->isChecked() && $txtEmail->isFilled(BL::getError('EmailIsRequired'))) {
             // email must not be the same as previous one
             if ($txtEmail->getValue() == $this->profile['email']) {
                 $txtEmail->addError(BL::getError('EmailMatchesPrevious'));
             }
             // 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'));
             }
         }
         // new_password is checked, so verify new password (only if profile should not be notified)
         // because then if the password field is empty, it will generate a new password
         if ($chkNewPassword->isChecked() && !$this->notifyProfile) {
             $txtPassword->isFilled(BL::err('FieldIsRequired'));
             $txtPasswordRepeat->isFilled(BL::err('FieldIsRequired'));
             // both password fields are filled in and should match
             if ($txtPassword->isFilled() && $txtPasswordRepeat->isFilled() && $txtPassword->getValue() != $txtPasswordRepeat->getValue()) {
                 $txtPasswordRepeat->addError(BL::err('PasswordRepeatIsRequired'));
             }
         }
         // 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'] = $chkNewEmail->isChecked() ? $txtEmail->getValue() : $this->profile['email'];
             // 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 ($chkNewPassword->isChecked()) {
                 // get new salt
                 $salt = BackendProfilesModel::getRandomString();
                 // update salt
                 BackendProfilesModel::setSetting($this->id, 'salt', $salt);
                 // new password filled in? otherwise generate a password
                 $password = $txtPassword->isFilled() ? $txtPassword->getValue() : BackendModel::generatePassword(8);
                 // build password
                 $values['password'] = BackendProfilesModel::getEncryptedString($password, $salt);
             }
             // update values
             BackendProfilesModel::update($this->id, $values);
             // birthday 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());
             $displayName = isset($values['display_name']) ? $values['display_name'] : $this->profile['display_name'];
             $redirectUrl = BackendModel::createURLForAction('Index') . '&var=' . rawurlencode($values['email']) . '&highlight=row-' . $this->id . '&var=' . rawurlencode($displayName) . '&report=';
             if ($this->notifyProfile && ($chkNewEmail->isChecked() || $chkNewPassword->isChecked())) {
                 // no new password
                 if (!$chkNewPassword->isChecked()) {
                     $password = BL::lbl('YourExistingPassword');
                 }
                 // notify values
                 $notifyValues = array_merge($values, array('id' => $this->id, 'first_name' => $txtFirstName->getValue(), 'last_name' => $txtLastName->getValue(), 'unencrypted_password' => $password));
                 if (!isset($notifyValues['display_name'])) {
                     $notifyValues['display_name'] = $this->profile['display_name'];
                 }
                 BackendProfilesModel::notifyProfile($notifyValues, true);
                 $redirectUrl .= 'saved-and-notified';
             } else {
                 $redirectUrl .= 'saved';
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $values));
             // everything is saved, so redirect to the overview
             $this->redirect($redirectUrl);
         }
     }
 }
Exemple #12
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // get default template id
     $defaultTemplateId = $this->get('fork.settings')->get('Pages', 'default_template', 1);
     // create form
     $this->frm = new BackendForm('edit');
     // assign in template
     $this->tpl->assign('defaultTemplateId', $defaultTemplateId);
     // create elements
     $this->frm->addText('title', $this->record['title'], null, 'form-control title', 'form-control danger title');
     $this->frm->addEditor('html');
     $this->frm->addHidden('template_id', $this->record['template_id']);
     $this->frm->addRadiobutton('hidden', array(array('label' => BL::lbl('Hidden'), 'value' => 'Y'), array('label' => BL::lbl('Published'), 'value' => 'N')), $this->record['hidden']);
     // image related fields
     $this->frm->addImage('image');
     $this->frm->addCheckbox('remove_image');
     // page auth related fields
     // check if profiles module is installed
     if (BackendModel::isModuleInstalled('Profiles')) {
         // add checkbox for auth_required
         $this->frm->addCheckbox('auth_required', isset($this->record['data']['auth_required']) && $this->record['data']['auth_required']);
         // get all groups and parse them in key value pair
         $groupItems = BackendProfilesModel::getGroups();
         if (!empty($groupItems)) {
             $groups = array();
             foreach ($groupItems as $key => $item) {
                 $groups[] = array('label' => $item, 'value' => $key);
             }
             // set checked values
             $checkedGroups = array();
             if (is_array($this->record['data']['auth_groups'])) {
                 foreach ($this->record['data']['auth_groups'] as $group) {
                     $checkedGroups[] = $group;
                 }
             }
             // add multi checkbox
             $this->frm->addMultiCheckbox('auth_groups', $groups, $checkedGroups);
         }
     }
     // a god user should be able to adjust the detailed settings for a page easily
     if ($this->isGod) {
         // init some vars
         $items = array('move', 'children', 'edit', 'delete');
         $checked = array();
         $values = array();
         foreach ($items as $value) {
             $values[] = array('label' => BL::msg(\SpoonFilter::toCamelCase('allow_' . $value)), 'value' => $value);
             if (isset($this->record['allow_' . $value]) && $this->record['allow_' . $value] == 'Y') {
                 $checked[] = $value;
             }
         }
         $this->frm->addMultiCheckbox('allow', $values, $checked);
     }
     // build prototype block
     $block['index'] = 0;
     $block['formElements']['chkVisible'] = $this->frm->addCheckbox('block_visible_' . $block['index'], true);
     $block['formElements']['hidExtraId'] = $this->frm->addHidden('block_extra_id_' . $block['index'], 0);
     $block['formElements']['hidPosition'] = $this->frm->addHidden('block_position_' . $block['index'], 'fallback');
     $block['formElements']['txtHTML'] = $this->frm->addTextarea('block_html_' . $block['index'], '');
     // this is no editor; we'll add the editor in JS
     // add default block to "fallback" position, the only one which we can rest assured to exist
     $this->positions['fallback']['blocks'][] = $block;
     // content has been submitted: re-create submitted content rather than the db-fetched content
     if (isset($_POST['block_html_0'])) {
         // init vars
         $this->blocksContent = array();
         $hasBlock = false;
         $i = 1;
         // loop submitted blocks
         while (isset($_POST['block_position_' . $i])) {
             // init var
             $block = array();
             // save block position
             $block['position'] = $_POST['block_position_' . $i];
             $positions[$block['position']][] = $block;
             // set linked extra
             $block['extra_id'] = $_POST['block_extra_id_' . $i];
             // reset some stuff
             if ($block['extra_id'] <= 0) {
                 $block['extra_id'] = null;
             }
             // init html
             $block['html'] = null;
             // extra-type is HTML
             if ($block['extra_id'] === null) {
                 // reset vars
                 $block['extra_id'] = null;
                 $block['html'] = $_POST['block_html_' . $i];
             } else {
                 // type of block
                 if (isset($this->extras[$block['extra_id']]['type']) && $this->extras[$block['extra_id']]['type'] == 'block') {
                     // set error
                     if ($hasBlock) {
                         $this->frm->addError(BL::err('CantAdd2Blocks'));
                     }
                     // home can't have blocks
                     if ($this->record['id'] == 1) {
                         $this->frm->addError(BL::err('HomeCantHaveBlocks'));
                     }
                     // reset var
                     $hasBlock = true;
                 }
             }
             // set data
             $block['created_on'] = BackendModel::getUTCDate();
             $block['edited_on'] = $block['created_on'];
             $block['visible'] = isset($_POST['block_visible_' . $i]) && $_POST['block_visible_' . $i] == 'Y' ? 'Y' : 'N';
             $block['sequence'] = count($positions[$block['position']]) - 1;
             // add to blocks
             $this->blocksContent[] = $block;
             // increment counter; go fetch next block
             ++$i;
         }
     }
     // build blocks array
     foreach ($this->blocksContent as $i => $block) {
         $block['index'] = $i + 1;
         $block['formElements']['chkVisible'] = $this->frm->addCheckbox('block_visible_' . $block['index'], $block['visible'] == 'Y');
         $block['formElements']['hidExtraId'] = $this->frm->addHidden('block_extra_id_' . $block['index'], (int) $block['extra_id']);
         $block['formElements']['hidPosition'] = $this->frm->addHidden('block_position_' . $block['index'], $block['position']);
         $block['formElements']['txtHTML'] = $this->frm->addTextarea('block_html_' . $block['index'], $block['html']);
         // this is no editor; we'll add the editor in JS
         $this->positions[$block['position']]['blocks'][] = $block;
     }
     // redirect
     $redirectValue = 'none';
     if (isset($this->record['data']['internal_redirect']['page_id'])) {
         $redirectValue = 'internal';
     }
     if (isset($this->record['data']['external_redirect']['url'])) {
         $redirectValue = 'external';
     }
     $redirectValues = array(array('value' => 'none', 'label' => \SpoonFilter::ucfirst(BL::lbl('None'))), array('value' => 'internal', 'label' => \SpoonFilter::ucfirst(BL::lbl('InternalLink')), 'variables' => array('isInternal' => true)), array('value' => 'external', 'label' => \SpoonFilter::ucfirst(BL::lbl('ExternalLink')), 'variables' => array('isExternal' => true)));
     $this->frm->addRadiobutton('redirect', $redirectValues, $redirectValue);
     $this->frm->addDropdown('internal_redirect', BackendPagesModel::getPagesForDropdown(), $redirectValue == 'internal' ? $this->record['data']['internal_redirect']['page_id'] : null);
     $this->frm->addText('external_redirect', $redirectValue == 'external' ? urldecode($this->record['data']['external_redirect']['url']) : null, null, null, null, true);
     // page info
     $this->frm->addCheckbox('navigation_title_overwrite', $this->record['navigation_title_overwrite'] == 'Y');
     $this->frm->addText('navigation_title', $this->record['navigation_title']);
     if ($this->showTags()) {
         // tags
         $this->frm->addText('tags', BackendTagsModel::getTags($this->URL->getModule(), $this->id), null, 'form-control js-tags-input', 'error js-tags-input');
     }
     // a specific action
     $isAction = isset($this->record['data']['is_action']) && $this->record['data']['is_action'] == true ? true : false;
     $this->frm->addCheckbox('is_action', $isAction);
     // extra
     $blockTypes = BackendPagesModel::getTypes();
     $this->frm->addDropdown('extra_type', $blockTypes, key($blockTypes));
     // meta
     $this->meta = new BackendMeta($this->frm, $this->record['meta_id'], 'title', true);
     // set callback for generating an unique URL
     $this->meta->setURLCallback('Backend\\Modules\\Pages\\Engine\\Model', 'getURL', array($this->record['id'], $this->record['parent_id'], $isAction));
 }