daily pastebin goal
12%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class donorList{
  4.     public $name = "Donor List";
  5.    
  6.     public $givingGroups = array(
  7.         array('name' => 'Galaxy Group', 'range' => 'Over $100,000', 'min' => 100000, 'max' => 999999999999999),
  8.         array('name' => 'North Star', 'range' => '$10,000 - $99,999', 'min' => 10000, 'max' => 99999),
  9.         array('name' => 'Rising Star', 'range' => '$1,000 - $9,999', 'min' => 1000, 'max' => 9999),
  10.         array('name' => 'Shining Star', 'range' => '$100 - $999', 'min' => 100, 'max' => 999),
  11.         array('name' => 'Other', 'range' => '$1 - $99', 'min' => 1, 'max' => 99)
  12.     );
  13.     public $queryString = array();
  14.    
  15.     public function __construct(){
  16.         include_once('db.php'); // just being picky
  17.         $this->db = array('host' => $host, 'user' => $user, 'pass' => $pass,'db' => $db);
  18.     }
  19.    
  20.     private function mySQLResultsToArray($result){
  21.         $table_result=array();
  22.         $r=0;
  23.         while($row = mysql_fetch_assoc($result)){
  24.             $arr_row=array();
  25.             $c=0;
  26.             while ($c < mysql_num_fields($result)) {
  27.                 $col = mysql_fetch_field($result, $c);
  28.                 $arr_row[$col -> name] = $row[$col -> name];
  29.                 $c++;
  30.             }
  31.             $table_result[$r] = $arr_row;
  32.             $r++;
  33.         }
  34.         return $table_result;
  35.     }
  36.    
  37.     public function getDonors($nameFilter = NULL, $ggID = array(0,1,2,3,4), $firstLetter = NULL){
  38.         // just in case the value supplied was an empty string... lets be really forgiving here...
  39.         if(empty($ggID) || in_array('all', $ggID) || is_null($ggID[0]) || $ggID[0] == '') $ggID = array(0,1,2,3,4);
  40.         if($nameFilter == "Search by Last Name") $nameFilter ="";
  41.         $connection = mysql_connect($this->db['host'], $this->db['user'], $this->db['pass'], $this->db['db']) or die ("Unable to connect!");
  42.         mysql_select_db($this->db['db']);
  43.         // protect again SQL Injection
  44.         $nameFilter = mysql_real_escape_string($nameFilter);
  45.         $firstLetter = mysql_real_escape_string($firstLetter);
  46.         foreach($ggID as $i => $ggKey){
  47.             // building the query for each group
  48.             $this->queryString[$ggKey] = "SELECT * FROM donors_2010 ";
  49.             $this->queryString[$ggKey] .= "WHERE donation < ".$this->givingGroups[$ggKey]['max']." AND donation > ".$this->givingGroups[$ggKey]['min']." ";
  50.             if(!(empty($nameFilter)) || !(empty($firstLetter))){
  51.                 if(!(empty($nameFilter))) $this->queryString[$ggKey] .= "AND (name LIKE '%$nameFilter%' OR prettyName LIKE '%$nameFilter%') ";
  52.                 if(!(empty($firstLetter))) $this->queryString[$ggKey] .= "AND name LIKE '$firstLetter%' ";
  53.             }
  54.             $this->queryString[$ggKey] .= "ORDER BY name";
  55.             $result = mysql_query($this->queryString[$ggKey]) or die ("Error in query: $query. ".mysql_error());
  56.             $resultArray[$ggKey] = $this->mySQLResultsToArray($result);
  57.         }
  58.         return $resultArray;
  59.     }
  60.    
  61.     public function getDonorList($donorArray = array()){
  62.         $m = ''; //markup
  63.         foreach($donorArray as $key => $donorGroup){
  64.             if(empty($donorGroup)) continue; //nothing to see here, no reason to print a label
  65.             $m .= "<br><br> \r\n";
  66.             $m .= "<h3>".$this->givingGroups[$key]['name']." :: ".$this->givingGroups[$key]['range']."</h3>\r\n";
  67.             //$m .= "<hr />\r\n";
  68.             $m .= "<ul class='donorList'> \r\n";
  69.             foreach($donorGroup as $donor){
  70.                 $m .= '<li>'.$donor['prettyName']."</li>\r\n";
  71.             }
  72.             $m .= "</ul> \r\n";
  73.         }
  74.         if($m == '') $m = "<h4>No Results Found</h4>";
  75.         return $m;
  76.     }
  77.    
  78.     public function getABCLinks(){
  79.         $links = '<div class="alphabet-links">';
  80.         foreach(range('A', 'Z') as $letter) {
  81.             $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> ';
  82.         }
  83.         $links .= '</div>';
  84.         return $links;
  85.     }
  86.    
  87.     public function getDonorOptions(){
  88.         $dl = "<option value='all'>All</option>\r\n";
  89.         foreach($this->givingGroups as $key => $group){
  90.             $dl .= "<option value='".$key."'>".$group['name']. ' :: '.$group['range']."</option>\r\n";
  91.         }
  92.         return $dl;
  93.     }
  94.    
  95.     public function getQueryString($getVars = array()){
  96.         $qs = '?'; //query string
  97.         $i = 0;
  98.         foreach($getVars as $getVar){
  99.             if (isset($_GET[$getVar]))
  100.             {
  101.                 if($i > 0 ) $qs .= "&";
  102.                 $qs .= $getVar."=".$_GET[$getVar];
  103.             }
  104.             $i++;
  105.         }
  106.         return $qs;
  107.     }
  108.    
  109.     public function validateEmail($email){
  110.         if(filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
  111.             return false;
  112.         }else {
  113.         return true;
  114.         }
  115.     }
  116.    
  117.     public function saveEmail($email){
  118.         $connection = mysql_connect($this->db['host'], $this->db['user'], $this->db['pass'], $this->db['db']) or die ("Unable to connect!");
  119.         mysql_select_db($this->db['db']);
  120.         $query = "INSERT INTO emails (email) VALUES ('$email')";
  121.         $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
  122.     }
  123. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top