Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class donorList{
- public $name = "Donor List";
- public $givingGroups = array(
- array('name' => 'Galaxy Group', 'range' => 'Over $100,000', 'min' => 100000, 'max' => 999999999999999),
- array('name' => 'North Star', 'range' => '$10,000 - $99,999', 'min' => 10000, 'max' => 99999),
- array('name' => 'Rising Star', 'range' => '$1,000 - $9,999', 'min' => 1000, 'max' => 9999),
- array('name' => 'Shining Star', 'range' => '$100 - $999', 'min' => 100, 'max' => 999),
- array('name' => 'Other', 'range' => '$1 - $99', 'min' => 1, 'max' => 99)
- );
- public $queryString = array();
- public function __construct(){
- include_once('db.php'); // just being picky
- $this->db = array('host' => $host, 'user' => $user, 'pass' => $pass,'db' => $db);
- }
- private function mySQLResultsToArray($result){
- $table_result=array();
- $r=0;
- while($row = mysql_fetch_assoc($result)){
- $arr_row=array();
- $c=0;
- while ($c < mysql_num_fields($result)) {
- $col = mysql_fetch_field($result, $c);
- $arr_row[$col -> name] = $row[$col -> name];
- $c++;
- }
- $table_result[$r] = $arr_row;
- $r++;
- }
- return $table_result;
- }
- public function getDonors($nameFilter = NULL, $ggID = array(0,1,2,3,4), $firstLetter = NULL){
- // just in case the value supplied was an empty string... lets be really forgiving here...
- if(empty($ggID) || in_array('all', $ggID) || is_null($ggID[0]) || $ggID[0] == '') $ggID = array(0,1,2,3,4);
- if($nameFilter == "Search by Last Name") $nameFilter ="";
- $connection = mysql_connect($this->db['host'], $this->db['user'], $this->db['pass'], $this->db['db']) or die ("Unable to connect!");
- mysql_select_db($this->db['db']);
- // protect again SQL Injection
- $nameFilter = mysql_real_escape_string($nameFilter);
- $firstLetter = mysql_real_escape_string($firstLetter);
- foreach($ggID as $i => $ggKey){
- // building the query for each group
- $this->queryString[$ggKey] = "SELECT * FROM donors_2010 ";
- $this->queryString[$ggKey] .= "WHERE donation < ".$this->givingGroups[$ggKey]['max']." AND donation > ".$this->givingGroups[$ggKey]['min']." ";
- if(!(empty($nameFilter)) || !(empty($firstLetter))){
- if(!(empty($nameFilter))) $this->queryString[$ggKey] .= "AND (name LIKE '%$nameFilter%' OR prettyName LIKE '%$nameFilter%') ";
- if(!(empty($firstLetter))) $this->queryString[$ggKey] .= "AND name LIKE '$firstLetter%' ";
- }
- $this->queryString[$ggKey] .= "ORDER BY name";
- $result = mysql_query($this->queryString[$ggKey]) or die ("Error in query: $query. ".mysql_error());
- $resultArray[$ggKey] = $this->mySQLResultsToArray($result);
- }
- return $resultArray;
- }
- public function getDonorList($donorArray = array()){
- $m = ''; //markup
- foreach($donorArray as $key => $donorGroup){
- if(empty($donorGroup)) continue; //nothing to see here, no reason to print a label
- $m .= "<br><br> \r\n";
- $m .= "<h3>".$this->givingGroups[$key]['name']." :: ".$this->givingGroups[$key]['range']."</h3>\r\n";
- //$m .= "<hr />\r\n";
- $m .= "<ul class='donorList'> \r\n";
- foreach($donorGroup as $donor){
- $m .= '<li>'.$donor['prettyName']."</li>\r\n";
- }
- $m .= "</ul> \r\n";
- }
- if($m == '') $m = "<h4>No Results Found</h4>";
- return $m;
- }
- public function getABCLinks(){
- $links = '<div class="alphabet-links">';
- foreach(range('A', 'Z') as $letter) {
- $links .= '<a href="'.$_SERVER["PHP_SELF"].$this->getQueryString(array('n','g')).'&a='.strtolower($letter).'" title="Results with last names starting with the letter '.$letter.'">'.$letter.'</a> ';
- }
- $links .= '</div>';
- return $links;
- }
- public function getDonorOptions(){
- $dl = "<option value='all'>All</option>\r\n";
- foreach($this->givingGroups as $key => $group){
- $dl .= "<option value='".$key."'>".$group['name']. ' :: '.$group['range']."</option>\r\n";
- }
- return $dl;
- }
- public function getQueryString($getVars = array()){
- $qs = '?'; //query string
- $i = 0;
- foreach($getVars as $getVar){
- if (isset($_GET[$getVar]))
- {
- if($i > 0 ) $qs .= "&";
- $qs .= $getVar."=".$_GET[$getVar];
- }
- $i++;
- }
- return $qs;
- }
- public function validateEmail($email){
- if(filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
- return false;
- }else {
- return true;
- }
- }
- public function saveEmail($email){
- $connection = mysql_connect($this->db['host'], $this->db['user'], $this->db['pass'], $this->db['db']) or die ("Unable to connect!");
- mysql_select_db($this->db['db']);
- $query = "INSERT INTO emails (email) VALUES ('$email')";
- $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
- }
- }
Add Comment
Please, Sign In to add comment