Example #1
0
    public function execute() {

       	$request = $this->getContext()->getRequest();

    	$postLoginUser = $request->getParameter('user');
    	$postLoginId = $postLoginUser['id'];

    	$id = $request->getParameter('id');

		$login = $this->getContext()->getUser()->getAttribute('Login');
    	$loginRole = $this->getLoginRole();

    	if ($loginRole == 'editor'){
    		if ($id != $login->id && $postLoginId != $login->id){

				$this->log("Unauthorized attempt edit login record. Login id: $id, user name: ". $login->name);
    					
    			$this->getContext()->getController()->forward('Default', "Secure");	
    		}
    	}

//    	$this->checkAdminAuth();

		if($request->getParameter('cancel')) {

			if ($loginRole == 'admin'){
				$this->getContext()->getController()->forward('Default', "ListLogin");
			} else {
				header("Location:Search?searchFor=Member");
			}

			return View::NONE;
		}
        
    	$form = new HTML_QuickForm("loginForm", 'post');

    	$loginDao = new BaseDao("Login");

		$affDao = new BaseDao("Affiliate"); 

    	if ($id){
    		$user = $loginDao->get($id);	

			$this->log("Editing login: "******" ,name: ".$user->name);
			$this->log("Editing login: "******" ,name: ".$user->name, true);

    		$affiliate = $affDao->getPattern();
    		$affiliate->editor = $user->id;
			$currentAffs = $affDao->search($affiliate);
			$affIds = $this->getListOfCertainFieldValues($currentAffs, 'id');

    		$form->setDefaults(array('user' => (array) $user, 
    								 "password2" => $user->password,
    								 "affiliates" => $affIds));
    	} else{
			$this->log("Creating new login.", true);

	    	$user = $loginDao->getPattern();
    	}

		$request->setAttribute('user', $user);

		$roleDao = new BaseDao("Role"); 
		$roles = $this->prepareDropdown($roleDao->search(), 'id', 'name');

		$affs = $this->prepareDropdown($affDao->searchWhereWithOrder($affDao->getPattern(), "1=1", 'name'), 'id', 'name');

		$form->addElement("text", "user[name]", "Name:", array('size' => 50, "maxlength" => 255));
		$form->addElement("text", "user[login]", "Login:"******"maxlength" => 255));
		$form->addElement("password", "user[password]", "Password:"******"maxlength" => 255));
		$form->addElement("password", "password2", "Repeat Password:"******"maxlength" => 255));
		$form->addElement('text', "user[email]", 'Email:', array('size' => 50, "maxlength" => 255));
		$form->addElement('select', "user[roleFid]", "User Role:", $roles);
		$form->addElement('select', "affiliates", "Affiliate:", $affs, array('multiple' => 'multiple', 'id' => "affDropdown") );
		$form->addElement('checkbox', "user[nationalOfficer]", "National Officer:", "", array());

		$element =& $form->getElement("affiliates");
		$element->setSize(5);
		if ($loginRole != 'admin') $element->freeze();

		$form->addElement('hidden', 'user[id]');
		$form->addElement("submit", null, "Save Changes");
		$form->addElement("submit", 'cancel', "Cancel");

		$form->addRule("user[name]", "Please enter your name.", 'required', null);
		$form->addRule("user[login]", "Login can't be blank.", 'required', null);
		$form->addRule("user[password]", "You haven't entered password.", 'required', null);
		$form->addRule("user[email]", "Please enter your email.", 'required', null);
		$form->addRule("user[email]", "Please enter valid email.", 'email', null);

		$form->addFormRule(array(&$this, "validatePassword"));
		$form->addFormRule(array(&$this, "checkEmail"));
		$form->addFormRule(array(&$this, "max5admins"));



		if (!$form->validate()) {

			$request->setAttribute("editLoginForm", $form->toHtml());

			return 'Form';
		}
		else{	
			$reqUser = $request->getParameter('user');

			$user->id = $reqUser['id'];
			$user->login = $reqUser['login'];
			$user->password = $reqUser['password'];
			$user->email = $reqUser['email'];
			$user->roleFid = $reqUser['roleFid'];
			$user->name = $reqUser['name'];

			if ($reqUser["nationalOfficer"]){
				$this->log("Assigng new national Officer: ".$user->login." ,name: ".$user->name, true);

				$user->nationalOfficer = 1;		
				$db = new PearDBStorage();
				$db->invoke("update logins set nationalOfficer=0 where nationalOfficer=1");
			}

			$loginDao->save($user);

			$affiliates = $reqUser = $request->getParameter("affiliates");
			$affText = "";
			if ($affiliates){
				foreach($affiliates as $affId){
					$affiliate = $affDao->get($affId);
					$affiliate->editor = $user->id;
					$affDao->save($affiliate);

					$affText .= $affiliate->name." ";
				}
			}

			if (!$user->id){

				$emailMessage = "Dear ".$user->name.":\n\n
				You have been assigned the role of Editor in the American Council of the Blind membership database for ".$affText.".\n
				Your User ID is ".$user->login." and your default password is ".$user->password.".  Please change this password immediately when you log into the database.\n\n
				Thank you for your work both in your affiliate and with the ACB management of the most precious resource we have:  Our members.\n\n
				Sincerely,\n\n
				The Database Management Team";

				mail($user->email, "ACB mail", $emailMessage);
			}

			if ($loginRole == 'admin'){
				$this->log("Saving login: "******" ,name: ".$user->name, true);

				$this->getContext()->getController()->forward('Default', "ListLogin");
			} else {
				$this->log("Saving login: "******" ,name: ".$user->name);

				header("Location:Search?searchFor=Member");
			}

			return View::NONE;
		}
    }
Example #2
0
 private function _validate()
 {
     if ($this->action == TIP_FORM_ACTION_DELETE || $this->action == TIP_FORM_ACTION_CUSTOM) {
         // Special case: GET driven form
         $this->_form->freeze();
         return TIP::getGet('process', 'int') == 1;
     }
     // Add element and form rules
     isset($this->validator) && $this->_form->addFormRule($this->validator);
     foreach (array_keys($this->fields) as $id) {
         if ($this->_form->elementExists($id)) {
             $this->_addGuessedRules($id);
             $this->_addCustomRules($id);
         }
     }
     $stage_id = $this->id . '.stage';
     $last_stage = HTTP_Session2::get($stage_id);
     if (!$this->_form->isSubmitted() || isset($last_stage) && $last_stage < $this->_stage) {
         HTTP_Session2::set($stage_id, $this->_stage);
         $valid = false;
     } elseif (is_null($last_stage)) {
         // No last stage defined
         TIP::notifyError('double');
         $valid = null;
     } else {
         // Validation
         $this->_form->applyFilter('__ALL__', array('TIP', 'extendedTrim'));
         $valid = $this->_form->validate();
     }
     // Perform uploads (if needed)
     if (is_callable(array('HTML_QuickForm_attachment', 'doUploads'))) {
         HTML_QuickForm_attachment::doUploads($this->_form);
     }
     return $valid;
 }
Example #3
0
function buildWriteForm($options) {
    global $fyr_values, $fyr_postcode, $fyr_who, $fyr_type;
    global $fyr_representative, $fyr_voting_area, $fyr_date;
    global $fyr_postcode_editable, $fyr_group_msg, $fyr_valid_reps;
    global $rep_text, $cobrand, $cocode;

    $form_action = cobrand_url($cobrand, '/write', $cocode);
    $form = new HTML_QuickForm('writeForm', 'post', $form_action);
    
    if ($fyr_voting_area['name']=='United Kingdom')
        $fyr_voting_area['name'] = 'House of Lords';
 
    $write_header = '';
    if ($options['include_write_header']){
        $write_header = "<strong>Now Write Your Message:</strong> <small>(* means required)</small><br><br>";
    }

    if ($options['include_fao']){
        $write_header = '<strong>For the attention of:</strong>';
    }

    $stuff_on_left = <<<END
            <div class="letter-header">
            ${write_header}
            ${rep_text}
            <span>${fyr_voting_area['name']}</span>
            <span>$fyr_date</span>
            </div>
END;
    // special formatting for letter-like code, TODO: how do this properly with QuickHtml?
    if ($options['table_layout']){
        $form->addElement("html", "<tr><td valign=\"top\">$stuff_on_left</td><td align=\"right\">\n<table>"); // CSSify
    } else {
        $form->addElement("html", "<div class=\"highlight\">$stuff_on_left<ul class=\"data-input\">");
    }  

    $form->addElement('text', 'name', "Your name:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
    $form->addRule('name', 'Please enter your name', 'required', null, null);
    $form->applyFilter('name', 'trim');

    $form->addElement('text', 'writer_address1', "Address 1:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
    $form->addRule('writer_address1', 'Please enter your address', 'required', null, null);
    $form->applyFilter('writer_address1', 'trim');

    $form->addElement('text', 'writer_address2', "Address 2:", array('size' => 20, 'maxlength' => 255));
    $form->applyFilter('writer_address2', 'trim');

    $form->addElement('text', 'writer_town', "Town/City:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
    $form->addRule('writer_town', 'Please enter your town/city', 'required', null, null);
    $form->applyFilter('writer_town', 'trim');

    # Call it state so that Google Toolbar (and presumably others) can auto-fill.
    $form->addElement('text', 'state', 'County:', array('size' => 20, 'maxlength' => 255));
    $form->applyFilter('state', 'trim');

    if ($fyr_postcode_editable) {
        // House of Lords
        $form->addElement('text', 'pc', "UK postcode:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
        $form->addRule('pc', 'Please enter a UK postcode (<a href="/about-lords#ukpostcode" target="_blank">why?</a>)', 'required', null, null);
        $form->addRule('pc', 'Choose a valid UK postcode (<a href="/about-lords#ukpostcode" target="_blank">why?</a>)', new RulePostcode(), null, null);
        $form->applyFilter('pc', 'trim');
    } else {
        // All other representatives (postcode fixed as must be in constituency)
        $form->addElement('static', 'staticpc', 'UK postcode:', htmlentities($fyr_postcode));
    }

    $form->addElement('text', 'writer_email', "Your email:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
    $form->addRule('writer_email', 'Please enter your email address', 'required', null, null);
    $invalid_email_message = cobrand_invalid_email_message($cobrand);
    if (!$invalid_email_message) {
         $invalid_email_message = 'Choose a valid email address';
    }
    $form->addRule('writer_email', $invalid_email_message, 'email', null, null);
    $form->applyFilter('writer_email', 'trim');

    $form->addElement('text', 'writer_email2', "Confirm email:<sup>*</sup>", array('size' => 20, 'maxlength' => 255));
    $form->addRule('writer_email2', 'Please re-enter your email address', 'required', null, null);
    $form->applyFilter('writer_email2', 'trim');
    $form->addFormRule('compare_email_addrs');

    /* add additional text explaining why we ask for email address twice? */

    #    $form->addElement("html", "</td><td colspan=2><p style=\"margin-top: 0em; margin-bottom: -0.2em\"><em style=\"font-size: 75%\">Optional, to let your {$fyr_voting_area['rep_name']} contact you more easily:</em>"); // CSSify

    $form->addElement('text', 'writer_phone', "Phone:", array('size' => 20, 'maxlength' => 255));
    $form->applyFilter('writer_phone', 'trim');

    // special formatting for letter-like code, TODO: how do this properly with QuickHtml?
    if ($options['table_layout']){
        $form->addElement("html", "</table>\n</td></tr>");
    } else {
        $form->addElement("html", "</ul>");
    }

    $form->addElement('textarea', 'body', null, array('rows' => 15, 'cols' => 62));
    $form->addRule('body', 'Please enter your message', 'required', null, null);
    $form->addRule('body', 'Please enter your message', new RuleAlteredBodyText(), null, null);
    $form->addRule('body', 'Please sign at the bottom with your name, or alter the "Yours sincerely" signature', new RuleSigned(), null, null);
    $form->addRule('body', 'Your message is a bit too long for us to send', 'maxlength', OPTION_MAX_BODY_LENGTH);
    if (!$options['table_layout']){
        $form->addElement("html", "</div>");
    }

    add_all_variables_hidden($form, $fyr_values, $options);
    $preview_text = cobrand_preview_text($cobrand);
    if (!$preview_text) {
        $preview_text = 'Ready? Press the "Preview" button to continue:';
    }
    $preview_button_text = cobrand_preview_button_text($cobrand);
    if (!$preview_button_text) {   
        $preview_button_text = 'preview your Message';
    }
    $buttons[0] =& HTML_QuickForm::createElement('static', 'staticpreview', null,"<p class=\"action\" id=\"preview-submit\">$preview_text"); 
    $buttons[2] =& HTML_QuickForm::createElement('submit', 'submitPreview', $preview_button_text);
    $buttons[3] =& HTML_QuickForm::createElement('static', 'staticpreview', null, "</p>");     
    $form->addGroup($buttons, 'previewStuff', '', '', false);

    return $form;
}
Example #4
0
function buildWriteForm($options)
{
    global $fyr_values, $stash;
    global $fyr_voting_area;
    global $cobrand, $cocode;
    $form_action = cobrand_url($cobrand, '/write', $cocode);
    $form = new HTML_QuickForm('writeForm', 'post', $form_action);
    if ($fyr_voting_area['name'] == 'United Kingdom') {
        $fyr_voting_area['name'] = 'House of Lords';
    }
    $write_header = '';
    $form->addElement('textarea', 'body', null, array('class' => 'message'));
    $form->addRule('body', 'Please enter your message', 'required', null, null);
    $form->addRule('body', 'Please enter your message', new RuleAlteredBodyText(), null, null);
    $form->addRule('body', 'Please sign at the bottom with your name, or alter the "Yours sincerely" signature', new RuleSigned(), null, null);
    $form->addRule('body', 'Your message is a bit too long for us to send', 'maxlength', OPTION_MAX_BODY_LENGTH);
    $form->addElement('html', '<div class="row">');
    $form->addElement('html', '<fieldset class="large-6 columns">');
    $form->addElement('html', '<legend>About You</legend>');
    $form->addElement('text', 'name', "Your name", array('required' => 'required', 'maxlength' => 255));
    $form->addRule('name', 'Please enter your name', 'required', null, null);
    $form->applyFilter('name', 'trim');
    $form->addElement('text', 'writer_email', "Your email", array('required' => 'required', 'maxlength' => 255));
    $form->addRule('writer_email', 'Please enter your email address', 'required', null, null);
    $invalid_email_message = cobrand_invalid_email_message($cobrand);
    if (!$invalid_email_message) {
        $invalid_email_message = 'Choose a valid email address';
    }
    $form->addRule('writer_email', $invalid_email_message, 'email', null, null);
    $form->applyFilter('writer_email', 'trim');
    $form->addElement('text', 'writer_email2', "Confirm email", array('required' => 'required', 'maxlength' => 255));
    $form->addRule('writer_email2', 'Please re-enter your email address', 'required', null, null);
    $form->applyFilter('writer_email2', 'trim');
    $form->addFormRule('compare_email_addrs');
    $form->updateElementAttr(array('writer_email', 'writer_email2'), array('type' => 'email'));
    $form->addElement('text', 'writer_phone', 'Phone <span class="optional-text">optional</span>', array('maxlength' => 255));
    $form->applyFilter('writer_phone', 'trim');
    $form->addElement("html", "</fieldset>");
    $form->addElement("html", '<fieldset class="large-6 columns">');
    $form->addElement("html", '<legend>Your Address</legend>');
    $form->addElement('text', 'writer_address1', "Address Line 1", array('required' => 'required', 'maxlength' => 255));
    $form->addRule('writer_address1', 'Please enter your address', 'required', null, null);
    $form->applyFilter('writer_address1', 'trim');
    $form->addElement('text', 'writer_address2', 'Address Line 2 <span class="optional-text">optional</span>', array('maxlength' => 255));
    $form->applyFilter('writer_address2', 'trim');
    $form->addElement('text', 'writer_town', "Town/City", array('required' => 'required', 'maxlength' => 255));
    $form->addRule('writer_town', 'Please enter your town/city', 'required', null, null);
    $form->applyFilter('writer_town', 'trim');
    $form->addElement('html', '<div class="row">');
    $form->addElement('html', '<div class="small-8 columns">');
    # Call it state so that Google Toolbar (and presumably others) can auto-fill.
    $form->addElement('text', 'state', 'County <span class="optional-text">optional</span>', array('maxlength' => 255));
    $form->applyFilter('state', 'trim');
    $form->addElement('html', '</div>');
    $form->addElement('html', '<div class="small-4 columns">');
    if (is_postcode_editable($fyr_voting_area['type'])) {
        // House of Lords
        $form->addElement('text', 'pc', "UK postcode", array('required' => 'required', 'maxlength' => 8));
        $form->addRule('pc', 'Please enter a UK postcode (<a href="/about-lords#ukpostcode" target="_blank">why?</a>)', 'required', null, null);
        $form->addRule('pc', 'Please enter a valid UK postcode (<a href="/about-lords#ukpostcode" target="_blank">why?</a>)', new RulePostcode(), null, null);
        $form->applyFilter('pc', 'trim');
    } else {
        // All other representatives (postcode fixed as must be in constituency)
        $form->addElement('text', 'staticpc', "UK postcode", array('disabled' => 'disabled', 'value' => htmlentities($fyr_values['pc'])));
    }
    $form->addElement('html', '</div>');
    $form->addElement('html', '</div>');
    $form->addElement("html", "</fieldset>");
    $form->addElement('html', '</div>');
    # close div.row
    $form->addElement("html", '<fieldset class="last"><legend>Ready?</legend>');
    add_all_variables_hidden($form, $fyr_values, $options);
    $preview_text = cobrand_preview_text($cobrand);
    if (!$preview_text) {
        $preview_text = "When you’re ready to send your message click the button below. You’ll get a chance to read through it again to check for problems before we send it.";
    }
    $preview_button_text = cobrand_preview_button_text($cobrand);
    if (!$preview_button_text) {
        $preview_button_text = 'Preview and send';
    }
    $form->addElement('html', "<p class=\"action\" id=\"preview-submit\">{$preview_text}</p>");
    $form->addElement('submit', 'submitPreview', $preview_button_text, array('class' => 'button radius success'));
    $form->addElement("html", "</fieldset>");
    return $form;
}