addText('from', "From (name)") ->setRequired("Any mail should have a sender") ->addRule($form::PATTERN, "Name must not be an address", '^[^@]+$'); $form->addCheckbox('noreply', "I do not wish to receive replies"); $form->addText('from_email', "From (email)") ->addconditionOn($form['noreply'], Nette\Application\UI\Form::EQUAL, FALSE) ->setRequired("Any mail should have a sender"); $form->addText('subject', "Subject") ->setRequired("You really want your message to have a subject"); $uid = $this->user->id; $user = $this->database->get_user($uid); $groups = []; // TODO: $groups[] = current group first, if not defined, personal group first $usergroups = $user->groups; $mygroups = []; $defaultvalue = false; foreach($usergroups as $usergroup) { $mygroups[$usergroup->primary] = $usergroup->name; # addresslist->getOwnergroup if ($usergroup->primary == $user->primarygroup->primary) { $defaultvalue = $usergroup->primary; } } $form->addSelect('access', "Access", $mygroups); if ($defaultvalue) $form['access']->setDefaultValue($defaultvalue); $form->addSubmit('save', "Save"); $form->addSubmit('cancel', "Cancel")->setValidationScope(false); $form->addProtection("protection token expired"); $form->onSuccess[] = [$this, 'metadataSubmit']; return $form; } public function MetadataSubmit(Nette\Application\UI\Form $form, $values = '') { $luser = $this->luser; $values = $form->values; $uid = $this->user->id; $user = $this->database->get_user($uid); $me = $user->primary; $mailing = $user->get_mailing($this->id); if(is_null($mailing)) throw new \Exception("mailing with id '$this->id' not found"); if($form['save']->submittedBy) { if($values->noreply) $values->from_email = $this->cfg->noreplyaddress; // Check if the email address specified is our own address, if not get verification $allowed = [ strtolower($user->emailaddress), strtolower(preg_replace('/@uvt\.nl\z/i', '@tilburguniversity.edu', $user->emailaddress)), 'noreply@uvt.nl', 'noreply@tilburguniversity.edu', $this->cfg->noreplyaddress, ]; $old_from_email = $mailing->fromemail; if($old_from_email && $mailing->addressapproved) $allowed[] = strtolower($old_from_email); if($values->from) $mailing->fromname = $values->from; if($values->subject) $mailing->subject = $values->subject; $new_from_email = $values->from_email; if($new_from_email && $new_from_email != $old_from_email) { $mailing->fromemail = $new_from_email; $frompreapproved = in_array(strtolower($new_from_email), $allowed); $mailing->addressapproved = $frompreapproved; if(!$frompreapproved) { $mailing->requestAddresschange($luser, $mailing->mtime); $this->flashMessage("The email address you specified needs to be verified before it will be used. At the given address you will receive a confirmation message within a few minutes."); } } } $this->MetadataRedirect($form, $values); } public function MetadataRedirect(Nette\Application\UI\Form $form, $values = '') { $this->redirect('Mailing:default'); } public function renderDefault() { $uid = $this->user->id; $user = $this->database->get_user($uid); if(is_null($id = $this->id)) $this->template->mailing = $user->default_mailing; else $this->template->mailing = $user->get_mailing($id); } }