public function execute() {

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

    	if ($userRole == "editor"){
    		$this->log("Entering certification mode for affiliates with ids: $affiliateIds"); 
    	} else if ($userRole == 'admin'){
	    	$this->log("Entering certification mode for affiliates with ids: $affiliateIds", true); 
    	}

    	$rawIds = $request->getParameter("affiliateIdsToCertify");

    	if (!is_array($rawIds)){
			header("location: Certification"); 
			die();
    	}

    	$affiliateIds = implode(",", array_keys($rawIds));

    	
		$db = new PearDBStorage();

		$userId = $this->getContext()->getUser()->getAttribute('Login')->id;

		$db->invoke("update asc_members_affiliates ama 
						 left join affiliates a  ON a.id = ama.affiliateFid 
						 set ama.certified = 0
						 where a.id in (".$affiliateIds.")"
				   );

		header("location: Certification"); 
		die();
    }
示例#2
0
    public function execute() {

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

		$db = new PearDBStorage();

		$userId = $this->getContext()->getUser()->getAttribute('Login')->id;

		if ($userRole == 'editor'){
	    	$this->log("Vieving list of affiliates available for certification.");

			$notCertifiedData = $db->invoke("select a.id, a.name as name, count(1) as not_certified 
											from affiliates a 
												left join asc_members_affiliates ama ON a.id = ama.affiliateFid 
												left join logins l on l.id = a.editor 
											where l.id = ".$userId." and ama.certified = 0 
											group by a.id");

			$affIds = $db->invoke("select a.id, a.name, 0 as not_certified 
											from affiliates a 
												left join asc_members_affiliates ama ON a.id = ama.affiliateFid 
												left join logins l on l.id = a.editor 
											where l.id = ".$userId." 
											group by a.id
											order by a.name");
	    } elseif ($userRole == 'admin') {

	    	$this->log("Vieving list of affiliates available for certification.", true);

			$notCertifiedData = $db->invoke("select a.id, a.name as name, count(1) as not_certified 
											from affiliates a 
												left join asc_members_affiliates ama ON a.id = ama.affiliateFid 
											where ama.certified = 0 
											group by a.id");

			$affIds = $db->invoke("select a.id, a.name, 0 as not_certified 
											from affiliates a 
												left join asc_members_affiliates ama ON a.id = ama.affiliateFid 
											group by a.id
											order by a.name");
	    }

	    $data = $this->combine($affIds, $notCertifiedData);

	    if (count($data) > 0){
	    	$request->setAttribute("data", $data);
    	} else{
    		$request->setAttribute("error", 1);
    	}
    	
		return 'List';
        
    }
示例#3
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;
		}
    }