From 663420b078dfd8cd0467fb5834abaccbb4d79f20 Mon Sep 17 00:00:00 2001 From: james Date: Sun, 11 Oct 2009 03:32:14 +0000 Subject: [PATCH] All of tonights wackload of changes --- admin/award_upload.php | 6 +- admin/fundraising_campaigns.php | 18 +- admin/fundraising_campaigns_prospecting.php | 226 +++++++++++++++----- admin/reports_schools.inc.php | 73 ++++--- admin/schools.php | 93 +++++++- config/rollover.php | 14 +- db/db.code.version.txt | 2 +- db/db.update.146.sql | 57 +++++ remote.php | 6 +- schoolaccess.php | 72 +++++-- user.inc.php | 207 ++++++++++++++---- 11 files changed, 597 insertions(+), 177 deletions(-) create mode 100644 db/db.update.146.sql diff --git a/admin/award_upload.php b/admin/award_upload.php index 4e65025..64d7e8d 100644 --- a/admin/award_upload.php +++ b/admin/award_upload.php @@ -43,11 +43,11 @@ function get_winners($awardid) 'city'=>'city', 'province_code'=>'province_code', 'postalcode'=>'postalcode', - 'principal'=>'principal', - 'schoolemail'=>'schoolemail', + 'schoolemail'=>'schoolemail'); +/* 'principal'=>'principal', 'sciencehead'=>'sciencehead', 'scienceheademail'=>'scienceheademail', - 'scienceheadphone'=>'scienceheadphone'); + 'scienceheadphone'=>'scienceheadphone');*/ $student_fields = array('firstname'=>'firstname', 'lastname'=>'lastname', diff --git a/admin/fundraising_campaigns.php b/admin/fundraising_campaigns.php index 5649709..649a208 100644 --- a/admin/fundraising_campaigns.php +++ b/admin/fundraising_campaigns.php @@ -214,8 +214,9 @@ switch($_GET['action']){ $campaign_id=intval($_GET['id']); $q=mysql_query("SELECT * FROM fundraising_campaigns WHERE id='$campaign_id' AND fiscalyear='{$config['FISCALYEAR']}'"); ?> -

Choose Prospects

-
+

+ +
:
@@ -235,8 +236,9 @@ switch($_GET['action']){ level\" >".i18n($r->level)." (".format_money($r->min,false)." - ".format_money($r->max,false).")
\n"; + echo "
\n"; } + echo "(disabled until the logic requirements can be established)"; ?>
: @@ -254,10 +256,10 @@ switch($_GET['action']){


-


-
+
+
@@ -435,11 +437,15 @@ function donortypechange() { } function prospect_search() { - $("#prospectsearchresults").load("fundraising_campaigns_prospecting.php",$("#prospectform").serializeArray()); return false; } +function prospect_generatelist() { + $("#prospectsearchresults").load("fundraising_campaigns_prospecting.php?generatelist=true",$("#prospectform").serializeArray()); + return false; +} + id'"); + $cq = mysql_query("SELECT *,MAX(year) FROM users LEFT JOIN users_sponsor ON users_sponsor.users_id=users.id + WHERE + sponsors_id='" . $r->id . "' + AND `primary`='$primary' + AND types LIKE '%sponsor%' + GROUP BY uid + HAVING deleted='no' + ORDER BY users_sponsor.primary DESC,lastname,firstname + "); + echo mysql_error(); while($cr=mysql_fetch_object($cq)) { if(!$userslist[$cr->users_id]) @@ -66,68 +75,167 @@ else if($_POST['donortype']=="individual") { $individual_type=$_POST['individual_type']; foreach($individual_type AS $t) { - switch($t) { - case "judge": - case "volunteer": - case "committee": - $query="SELECT *,MAX(year) FROM users WHERE types LIKE '%$t%' GROUP BY uid HAVING deleted='no' ORDER BY lastname,firstname"; - $q=mysql_query($query); - echo mysql_error(); - while($r=mysql_fetch_object($q)) { - if(!$userslist[$r->uid]) - $userslist[$r->uid]=user_load_by_uid($r->uid); - } - break; - - case "teacher": - $q=mysql_query("SELECT DISTINCT(teacheremail) AS email, teachername AS name FROM students ORDER BY teachername"); - while($r=mysql_fetch_assoc($q)) { - $otherlist[]=$r; - } - break; - case "sciencehead": - $q=mysql_query("SELECT DISTINCT(scienceheademail) AS email, sciencehead AS name, scienceheadphone AS phone FROM schools WHERE year='{$config['FAIRYEAR']}' ORDER BY name"); - while($r=mysql_fetch_assoc($q)) { - $otherlist[]=$r; - } - break; - case "principal": - $q=mysql_query("SELECT DISTINCT(schoolemail) AS email, principal AS name FROM schools WHERE year='{$config['FAIRYEAR']}' ORDER BY name"); - while($r=mysql_fetch_assoc($q)) { - $otherlist[]=$r; - } - break; - case "parent": - //unfortunately, this doesnt exist anywhere in sfiab - break; - case "mentor": - $q=mysql_query("SELECT DISTINCT(email) AS email, CONCAT(firstname, ' ', lastname) AS name, phone FROM mentors ORDER BY email"); - echo mysql_error(); - while($r=mysql_fetch_assoc($q)) { - $otherlist[]=$r; - } - - break; - case "students": - $q=mysql_query("SELECT DISTINCT(email) AS email, CONCAT(firstname, ' ', lastname) AS name, address, city, province, postalcode, phone FROM students ORDER BY email"); - echo mysql_error(); - while($r=mysql_fetch_assoc($q)) { - $otherlist[]=$r; - } - - break; + $query="SELECT *,MAX(year) FROM users WHERE types LIKE '%$t%' GROUP BY uid HAVING deleted='no' ORDER BY lastname,firstname"; + $q=mysql_query($query); + echo mysql_error(); + while($r=mysql_fetch_object($q)) { + if(!$userslist[$r->uid]) + $userslist[$r->uid]=user_load_by_uid($r->uid); } - } } -$usersnum=count($userslist); -$othernum=count($otherlist); -echo "$usersnum users results
"; -echo "$othernum other results
"; -//print_r($userslist); -//print_r($otherlist); -echo "

"; +//okie dokie, now we need to filter ou the list on the other criteria +if($_POST['emailaddress']) { + $emailaddress=$_POST['emailaddress']; +} +else { + $emailaddress=array("available","not available"); +} + +if(count($emailaddress)==1) { + $emailavailablelist=array(); + $emailnotavailablelist=array(); + + foreach($userslist AS $uid=>$u) { + if($u['email']) + $emailavailablelist[$uid]=$u; + else + $emailnotavailablelist[$uid]=$u; + } + + if($emailaddress[0]=="available") { + $userslist=$emailavailablelist; + } else { + $userslist=$emailnotavailablelist; + } +} + + +if($_POST['donationhistory']) { + $donationhistory=$_POST['donationhistory']; +} +else { + $donationhistory=array("never","past","lastyear","thisyear"); +} + +/* +FIXME: put this back in as it would eliminate a lot of processing + +if(in_array('never',$donationhistory) && in_array('past',$donationhistory)) { + //these cancel eachother out basically, so include everyone + unset($donationhistory[array_search("never",$donationhistory)]); + unset($donationhistory[array_search("past",$donationhistory)]); +} +*/ + +$neverlist=$userslist; +$pastlist=$userslist; +$lastyearlist=$userslist; +$thisyearlist=$userslist; + + //if they dont have a sponsors id, then they,ve never donated for sure, so keep them + //if they DO have a sponsors id, we need to check if tere is a donation record for them + //and if so, remove them if there is because tey have donated in the past + + foreach($neverlist AS $uid=>$u) { + if($u['sponsors_id']) { + $q=mysql_query("SELECT * FROM fundraising_donations WHERE status='received' AND sponsors_id='{$u['sponsors_id']}'"); + if(mysql_num_rows($q)) { + // echo "removing $uid because they have donated in the past
"; + unset($neverlist[$uid]); + } + } + } + +//if they dont have a sponsors id, then they,ve never donated for sure, get rid of them + //if they DO have a sponsors id, we need to check if tere is a donation record for them + //and if not remove them if there is because tey have not donated in the past + + foreach($pastlist AS $uid=>$u) { + if($u['sponsors_id']) { + $q=mysql_query("SELECT * FROM fundraising_donations WHERE status='received' AND sponsors_id='{$u['sponsors_id']}'"); + if(!mysql_num_rows($q)) { + // echo "removing $uid because they have NOT donated in the past
"; + unset($pastlist[$uid]); + } + } + else { + // echo "removing $uid because they have NOT donated in the past
"; + unset($pastlist[$uid]); + + } + } + + $lastyear=$config['FISCALYEAR']-1; + + foreach($lastyearlist AS $uid=>$u) { + if($u['sponsors_id']) { + $q=mysql_query("SELECT * FROM fundraising_donations WHERE status='received' AND sponsors_id='{$u['sponsors_id']}' AND fiscalyear='$lastyear'"); + if(!mysql_num_rows($q)) { + // echo "removing $uid because they have NOT donated last year
"; + unset($lastyearlist[$uid]); + } + } + else { + // echo "removing $uid because they have NOT donated last year
"; + unset($lastyearlist[$uid]); + + } + } + + foreach($thisyearlist AS $uid=>$u) { + if($u['sponsors_id']) { + $q=mysql_query("SELECT * FROM fundraising_donations WHERE status='received' AND sponsors_id='{$u['sponsors_id']}' AND fiscalyear='{$config['FISCALYEAR']}'"); + if(!mysql_num_rows($q)) { + // echo "removing $uid because they have NOT donated this year
"; + unset($thisyearlist[$uid]); + } + } + else { + // echo "removing $uid because they have NOT donated this year
"; + unset($thisyearlist[$uid]); + + } + } + +/* +echo "neverlist:".count($neverlist)."
"; +echo "pastlist:".count($pastlist)."
"; +echo "lastyearlist:".count($lastyearlist)."
"; +echo "thisyearlist:".count($thisyearlist)."
"; +*/ + +$userslist=array(); +foreach($donationhistory AS $dh) { + $arr=$dh."list"; + foreach($$arr AS $uid=>$u) { + $userslist[$uid]=$u; + } +} + +if($_GET['generatelist']) { + $campaignid=$_POST['fundraising_campaigns_id']; + $params=serialize($_POST); + echo "params=$params"; + mysql_query("UPDATE fundraising_campaigns SET filterparameters='{$params}' WHERE id='$campaignid'"); + $uids=array_keys($userslist); + foreach($uids AS $u) { + mysql_query("INSERT INTO fundraising_campaigns_users_link (fundraising_campaigns_id, users_uid) VALUES ('$campaignid','$u')"); + } + echo "List created"; +} +else { + //just show the results + $usersnum=count($userslist); + echo i18n("%1 users match the given criteria",array($usersnum))."
"; + echo "\n"; + //print_r($userslist); + //print_r($otherlist); +} + + + echo "

"; echo nl2br(print_r($_POST,true)); diff --git a/admin/reports_schools.inc.php b/admin/reports_schools.inc.php index 6eabc95..ffde0fc 100644 --- a/admin/reports_schools.inc.php +++ b/admin/reports_schools.inc.php @@ -21,6 +21,46 @@ Boston, MA 02111-1307, USA. */ + +function reports_schools_principal(&$report, $text) +{ + $year = $report['year']; + if($text > 0) { /* text is the uid */ + $u = user_load_by_uid_year($text, $year); + return $u['name']; + } + return ''; +} +function reports_schools_sciencehead(&$report, $text) +{ + $year = $report['year']; + if($text > 0) { /* text is the uid */ + $u = user_load_by_uid_year($text, $year); + return $u['name']; + } + return ''; +} + +function reports_schools_shphone(&$report, $text) +{ + $year = $report['year']; + if($text > 0) { /* text is the uid */ + $u = user_load_by_uid_year($text, $year); + return $u['phonework']; + } + return ''; +} + +function reports_schools_shemail(&$report, $text) +{ + $year = $report['year']; + if($text > 0) { /* text is the uid */ + $u = user_load_by_uid_year($text, $year); + return $u['email']; + } + return ''; +} + $report_schools_fields = array( 'school' => array( 'name' => 'School -- Name', @@ -110,46 +150,29 @@ $report_schools_fields = array( 'name' => 'School -- Principal', 'header' => 'Principal', 'width' => 1.25, - 'table' => 'schools.principal' ), + 'table' => 'schools.principal_uid', + 'exec_function' => 'reports_schools_principal'), 'school_sh' => array( 'name' => 'School -- Science Head', 'header' => 'Science Head', 'width' => 1.25, - 'table' => 'schools.sciencehead' ), + 'table' => 'schools.sciencehead_uid', + 'exec_function' => 'reports_schools_sciencehead'), 'school_shphone' => array( 'name' => 'School -- Science Head Phone', 'header' => 'Science Hd Phone', 'width' => 1, - 'table' => 'schools.scienceheadphone' ), + 'table' => 'schools.sciencehead_uid', + 'exec_function' => 'reports_schools_shphone'), 'school_shemail' => array( 'name' => 'School -- Science Head Email', 'header' => 'Science Head Email', 'width' => 1.5, - 'table' => 'schools.scienceheademail' ), - - 'school_contact' => array( - 'name' => 'School -- Contact (Principal if school PHONE exists, else Science Head)', - 'header' => 'Contact', - 'width' => 1.5, - 'table' => "IF(schools.phone='',schools.sciencehead,schools.principal)", - 'table_sort' => 'schools.principal' ), - - 'school_contactphone' => array( - 'name' => 'School -- Contact Phone (School Phone if exists, else Science Head Phone)', - 'header' => 'Cnct Phone', - 'width' => 1, - 'table' => "IF(schools.phone='',schools.scienceheadphone,schools.phone)", - 'table_sort' => 'schools.phone' ), - - 'school_contactemail' => array( - 'name' => 'School -- Contact Email (School Email if school PHONE exists, else Science Head Email)', - 'header' => 'Contact Email', - 'width' => 1.5, - 'table' => "IF(schools.phone='',schools.scienceheademail,schools.schoolemail)", - 'table_sort' => 'schools.schoolemail' ), + 'table' => 'schools.sciencehead_uid', + 'exec_function' => 'reports_schools_shemail'), 'school_accesscode' => array( 'name' => 'School -- Access Code', diff --git a/admin/schools.php b/admin/schools.php index 0fd109f..c4d7138 100644 --- a/admin/schools.php +++ b/admin/schools.php @@ -35,10 +35,77 @@ $id=mysql_insert_id(); } else - $id=$_POST['id']; + $id=intval($_POST['id']); $atrisk = $_POST['atrisk'] == 'yes' ? 'yes' : 'no'; +/* + "sciencehead='".mysql_escape_string(stripslashes($_POST['sciencehead']))."', ". + "scienceheadphone='".mysql_escape_string(stripslashes($_POST['scienceheadphone']))."', ". + "scienceheademail='".mysql_escape_string(stripslashes($_POST['scienceheademail']))."', ". + "principal='".mysql_escape_string(stripslashes($_POST['principal']))."', ". +*/ + + /* Get the uids for principal/science head */ + $q = mysql_query("SELECT principal_uid,sciencehead_uid FROM schools WHERE id='$id'"); + $i = mysql_fetch_assoc($q); + + $principal_update = ''; + $sciencehead_update = ''; + list($first, $last) = split(' ', $_POST['principal'], 2); + /* Load existing entry if it exists, else make an entry if + * there is data, else, do nothing */ + if($i['principal_uid'] > 0) + $pl = user_load_by_uid($i['principal_uid']); + else if($first != '' && $last != '') { + $pl = user_create('principal', "*$first$last".user_generate_password()); + $principal_update = "principal_uid='{$pl['uid']}',"; + } else + $pl = false; + + /* If we loaded or created an entry, either + * update and save, or purge it */ + if(is_array($pl)) { + if($first == '' && $last == '') { + user_purge($pl, 'principal'); + $principal_update = 'principal_uid=NULL,'; + } else { + $pl['firstname'] = $first; + $pl['lastname'] = $last; + user_save($pl); + } + } + + + /* Get info about science head */ + list($first, $last) = split(' ', $_POST['sciencehead'], 2); + $em = $_POST['scienceheademail']; + if($em == '' && ($first != '' || $last != '')) $em = "*$first$last".user_generate_password(); + /* Load existing record, or create new if there's something + * to insert */ + if($i['sciencehead_uid'] > 0) + $sh = user_load_by_uid($i['sciencehead_uid']); + else if($em != '') { + $sh = user_create('teacher', $em); + $sciencehead_update = "sciencehead_uid='{$sh['uid']}',"; + } else + $sh = false; + + /* If we have a record, either delete it or update it */ + if(is_array($sh)) { + if($em == '') { + user_purge($sh, 'teacher'); + $sciencehead_update = 'sciencehead_uid=NULL,'; + } else { + $sh['firstname'] = $first; + $sh['lastname'] = $last; + $sh['phonework'] = $_POST['scienceheadphone']; + $sh['email'] = $em; + $sh['username'] = $em; + user_save($sh); + } + } + $exec="UPDATE schools SET ". "school='".mysql_escape_string(stripslashes($_POST['school']))."', ". "schoollang='".mysql_escape_string(stripslashes($_POST['schoollang']))."', ". @@ -51,17 +118,14 @@ "city='".mysql_escape_string(stripslashes($_POST['city']))."', ". "province_code='".mysql_escape_string(stripslashes($_POST['province_code']))."', ". "postalcode='".mysql_escape_string(stripslashes($_POST['postalcode']))."', ". - "principal='".mysql_escape_string(stripslashes($_POST['principal']))."', ". "schoolemail='".mysql_escape_string(stripslashes($_POST['schoolemail']))."', ". "phone='".mysql_escape_string(stripslashes($_POST['phone']))."', ". "fax='".mysql_escape_string(stripslashes($_POST['fax']))."', ". - "sciencehead='".mysql_escape_string(stripslashes($_POST['sciencehead']))."', ". - "scienceheadphone='".mysql_escape_string(stripslashes($_POST['scienceheadphone']))."', ". - "scienceheademail='".mysql_escape_string(stripslashes($_POST['scienceheademail']))."', ". "registration_password='".mysql_escape_string(stripslashes($_POST['registration_password']))."', ". "projectlimit='".mysql_escape_string(stripslashes($_POST['projectlimit']))."', ". "projectlimitper='".mysql_escape_string(stripslashes($_POST['projectlimitper']))."', ". "accesscode='".mysql_escape_string(stripslashes($_POST['accesscode']))."', ". + $sciencehead_update.$principal_update. "atrisk='$atrisk' ". "WHERE id='$id'"; mysql_query($exec); @@ -158,13 +222,24 @@ echo "".i18n($config['postalzip'])."postalcode\" size=\"8\" maxlength=\"7\" />\n"; echo "".i18n("Phone")."phone)."\" size=\"16\" maxlength=\"16\" />\n"; echo "".i18n("Fax")."fax)."\" size=\"16\" maxlength=\"16\" />\n"; - echo "".i18n("Principal")."principal)."\" size=\"60\" maxlength=\"64\" />\n"; + + if($r->principal_uid > 0) + $pl = user_load_by_uid($r->principal_uid); + else + $pl = array(); + echo "".i18n("Principal")."\n"; echo "".i18n("School Email")."schoolemail)."\" size=\"60\" maxlength=\"128\" />\n"; echo "".i18n("Access Code")."accesscode)."\" size=\"32\" maxlength=\"32\" />\n"; echo "
".i18n("Science head/teacher or science fair contact at school").""; - echo "".i18n("Name")."sciencehead)."\" size=\"60\" maxlength=\"64\" />\n"; - echo "".i18n("Phone")."scienceheadphone)."\" size=\"16\" maxlength=\"16\" />\n"; - echo "".i18n("Email")."scienceheademail)."\" size=\"60\" maxlength=\"128\" />\n"; + if($r->sciencehead_uid > 0) + $sh = user_load_by_uid($r->sciencehead_uid); + else + $sh = array(); + /* Don't show autogenerated emails */ + $e = $sh['email'][0] == '*' ? '' : $sh['email']; + echo "".i18n("Email")."\n"; + echo "".i18n("Name")."\n"; + echo "".i18n("Phone")."\n"; if($config['participant_registration_type']=="schoolpassword") { diff --git a/config/rollover.php b/config/rollover.php index 7d1e56e..7deb604 100644 --- a/config/rollover.php +++ b/config/rollover.php @@ -268,7 +268,11 @@ $q=mysql_query("SELECT * FROM schools WHERE year='$currentfairyear'"); echo mysql_error(); while($r=mysql_fetch_object($q)) - mysql_query("INSERT INTO schools (school,schoollang,schoollevel,board,district,phone,fax,address,city,province_code,postalcode,principal,schoolemail,sciencehead,scienceheademail,scienceheadphone,accesscode,lastlogin,junior,intermediate,senior,registration_password,projectlimit,projectlimitper,year) VALUES ( + $puid = ($r->principal_uid == null) ? 'NULL' : ("'".intval($r->principal_uid)."'"); + $shuid = ($r->sciencehead_uid == null) ? 'NULL' : ("'".intval($r->sciencehead_uid)."'"); + + + mysql_query("INSERT INTO schools (school,schoollang,schoollevel,board,district,phone,fax,address,city,province_code,postalcode,principal_uid,schoolemail,sciencehead_uid,accesscode,lastlogin,junior,intermediate,senior,registration_password,projectlimit,projectlimitper,year) VALUES ( '".mysql_real_escape_string($r->school)."', '".mysql_real_escape_string($r->schoollang)."', '".mysql_real_escape_string($r->schoollevel)."', @@ -279,12 +283,8 @@ '".mysql_real_escape_string($r->address)."', '".mysql_real_escape_string($r->city)."', '".mysql_real_escape_string($r->province_code)."', - '".mysql_real_escape_string($r->postalcode)."', - '".mysql_real_escape_string($r->principal)."', - '".mysql_real_escape_string($r->schoolemail)."', - '".mysql_real_escape_string($r->sciencehead)."', - '".mysql_real_escape_string($r->scienceheademail)."', - '".mysql_real_escape_string($r->scienceheadphone)."', + '".mysql_real_escape_string($r->postalcode)."',$puid, + '".mysql_real_escape_string($r->schoolemail)."',$shuid, '".mysql_real_escape_string($r->accesscode)."', NULL, '".mysql_real_escape_string($r->junior)."', diff --git a/db/db.code.version.txt b/db/db.code.version.txt index 13c09a0..878d5a0 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -145 +146 diff --git a/db/db.update.146.sql b/db/db.update.146.sql new file mode 100644 index 0000000..efe199d --- /dev/null +++ b/db/db.update.146.sql @@ -0,0 +1,57 @@ +ALTER TABLE `users` CHANGE `types` `types` SET( 'student', 'judge', 'committee', 'volunteer', 'fair', 'sponsor', 'principal', 'teacher', 'parent', 'mentor', 'alumni' ) NOT NULL; + +CREATE TABLE `users_principal` ( + `users_id` INT NOT NULL , + `principal_active` ENUM( 'no', 'yes' ) NOT NULL , + `principal_complete` ENUM( 'no', 'yes' ) NOT NULL +) ENGINE = MYISAM ; + +CREATE TABLE `users_teacher` ( + `users_id` INT NOT NULL , + `teacher_active` ENUM( 'no', 'yes' ) NOT NULL , + `teacher_complete` ENUM( 'no', 'yes' ) NOT NULL +) ENGINE = MYISAM ; + +CREATE TABLE `users_parent` ( + `users_id` INT NOT NULL , + `parent_active` ENUM( 'no', 'yes' ) NOT NULL , + `parent_complete` ENUM( 'no', 'yes' ) NOT NULL +) ENGINE = MYISAM ; + +CREATE TABLE `users_mentor` ( + `users_id` INT NOT NULL , + `mentor_active` ENUM( 'no', 'yes' ) NOT NULL , + `mentor_complete` ENUM( 'no', 'yes' ) NOT NULL +) ENGINE = MYISAM ; + +CREATE TABLE `users_alumni` ( + `users_id` INT NOT NULL , + `alumni_active` ENUM( 'no', 'yes' ) NOT NULL , + `alumni_complete` ENUM( 'no', 'yes' ) NOT NULL +) ENGINE = MYISAM ; + +ALTER TABLE `sponsors` DROP `taxreceiptrequired`; +ALTER TABLE `sponsors` ADD `proposalsubmissiondate` DATE NOT NULL; + +ALTER TABLE `schools` ADD `principal_uid` INT NULL AFTER `principal` , + ADD `sciencehead_uid` INT NULL AFTER `principal_uid` ; + +UPDATE `schools` SET `principal_uid`=NULL WHERE 1; +UPDATE `schools` SET `sciencehead_uid`=NULL WHERE 1; + +DROP TABLE `fundraising_campaigns_segments`; + +CREATE TABLE `fundraising_campaigns_users_link` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , + `fundraising_campaigns_id` INT UNSIGNED NOT NULL , + `users_uid` INT UNSIGNED NOT NULL +) ENGINE = MYISAM ; + +ALTER TABLE `fundraising_campaigns` ADD `filterparameters` VARCHAR(255) NULL DEFAULT NULL AFTER `fundraising_goal`; + +UPDATE `reports_items` SET field = 'school_principal' WHERE field = 'school_contact'; +UPDATE `reports_items` SET field = 'school_phone' WHERE field = 'school_contactphone'; +UPDATE `reports_items` SET field = 'school_email' WHERE field = 'school_contactemail'; + +UPDATE `reports` SET `desc` = 'List of all schools in the database. Name, address, principal and phone.' WHERE `reports`.`system_report_id` =35 ; + diff --git a/remote.php b/remote.php index d49edee..8af20ea 100644 --- a/remote.php +++ b/remote.php @@ -133,11 +133,11 @@ function award_upload_update_school(&$mysql_query, &$school, $school_id = -1) 'city'=>'city', 'province_code'=>'province_code', 'postalcode'=>'postalcode', - 'principal'=>'principal', - 'schoolemail'=>'schoolemail', + 'schoolemail'=>'schoolemail'); +/* 'principal'=>'principal', 'sciencehead'=>'sciencehead', 'scienceheademail'=>'scienceheademail', - 'scienceheadphone'=>'scienceheadphone'); + 'scienceheadphone'=>'scienceheadphone');*/ if($school_id == -1) { $our_school = mysql_fetch_assoc($mysql_query); diff --git a/schoolaccess.php b/schoolaccess.php index e4ba37d..e23ba75 100644 --- a/schoolaccess.php +++ b/schoolaccess.php @@ -1,5 +1,7 @@ sciencehead_uid > 0) + $sh = user_load_by_uid($school->sciencehead_uid); + else if($em != '') { + $sh = user_create('teacher', $em); + $sciencehead_update = "sciencehead_uid='{$sh['uid']}',"; + } else + $sh = false; + + /* If we have a record, either delete it or update it */ + if(is_array($sh)) { + if($em == '') { + user_purge($sh, 'teacher'); + $sciencehead_update = 'sciencehead_uid=NULL,'; + } else { + $sh['firstname'] = $first; + $sh['lastname'] = $last; + $sh['phonework'] = $_POST['scienceheadphone']; + $sh['email'] = $em; + $sh['username'] = $em; + user_save($sh); + } + } + + mysql_query("UPDATE schools SET school='".mysql_escape_string(stripslashes($_POST['school']))."', address='".mysql_escape_string(stripslashes($_POST['address']))."', @@ -40,12 +72,11 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']) province_code='".mysql_escape_string(stripslashes($_POST['province_code']))."', postalcode='".mysql_escape_string(stripslashes($_POST['postalcode']))."', phone='".mysql_escape_string(stripslashes($_POST['phone']))."', - fax='".mysql_escape_string(stripslashes($_POST['fax']))."', - sciencehead='".mysql_escape_string(stripslashes($_POST['sciencehead']))."', - scienceheademail='".mysql_escape_string(stripslashes($_POST['scienceheademail']))."', - scienceheadphone='".mysql_escape_string(stripslashes($_POST['scienceheadphone']))."' + $sciencehead_update + fax='".mysql_escape_string(stripslashes($_POST['fax']))."' WHERE id='$school->id'"); + echo mysql_error(); if(mysql_error()) echo error(i18n("An Error occured trying to save the school information")); else @@ -74,6 +105,12 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']) } */ + if($school->sciencehead_uid > 0) + $sh = user_load_by_uid($school->sciencehead_uid); + else + $sh = array(); + $sh_email = ($sh['email'] != '' && $sh['email'][0] != '*') ? $sh['email'] : ''; + if($_POST['action']=="feedback") { $body=""; @@ -81,11 +118,11 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']) $body.=$_SERVER['REMOTE_ADDR']." (".$_SERVER['REMOTE_HOST'].")\n"; $body.="School ID: $school->id\n"; $body.="School Name: $school->school\n"; - if($school->sciencehead) $body.="Science Teacher: $school->sciencehead\n"; - if($school->scienceheadphone) $body.="Science Teacher Phone: $school->scienceheadphone\n"; - if($school->scienceheademail) $body.="Science Teacher Email: $school->scienceheademail\n"; + if($sh['name']) $body.="Science Teacher: {$sh['name']}\n"; + if($sh['phonework']) $body.="Science Teacher Phone: {$sh['phonework']}\n"; + if($sh_email) $body.="Science Teacher Email: $sh_email\n"; $body.="\nFeedback:\n".stripslashes($_POST['feedbacktext'])."\n"; - $returnEmailAddress = $school->scienceheademail; + $returnEmailAddress = $sh_email; mail($config['fairmanageremail'],"School Feedback",$body,"From: ". $returnEmailAddress."\nReply-To: ".$returnEmailAddress."\nReturn-Path: ".$returnEmailAddress); echo happy(i18n("Your feedback has been sent")); } @@ -106,9 +143,10 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']) echo "".i18n($config['postalzip'])."postalcode\" type=text name=postalcode size=10>"; echo "".i18n("Phone Number")."phone\" type=text name=phone size=30>"; echo "".i18n("Fax Number")."fax\" type=text name=fax size=30>"; - echo "".i18n("Science Teacher")."sciencehead\" type=text name=sciencehead size=40>"; - echo "".i18n("Science Teacher Email")."scienceheademail\" type=text name=scienceheademail size=40>"; - echo "".i18n("Science Teacher Phone")."
(".i18n("If different than above").")scienceheadphone\" type=text name=scienceheadphone size=30>"; + + echo "".i18n("Science Teacher").""; + echo "".i18n("Science Teacher Email").""; + echo "".i18n("Science Teacher Phone")."
(".i18n("If different than above").")"; echo ""; echo ""; echo "
"; @@ -143,7 +181,7 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode']) echo "

".i18n("School Feedback / Questions")."

"; echo i18n("We are always welcome to any feedback (both positive and constructive crisicism!), or any questions you may have. Please use the following form to communicate with the science fair committee!"); - if($school->scienceheademail) { + if($sh_email != '') { echo "
"; echo ""; echo "

"; diff --git a/user.inc.php b/user.inc.php index 2ac5c54..55fa268 100644 --- a/user.inc.php +++ b/user.inc.php @@ -24,10 +24,15 @@ ?> 'Participant', 'judge' => 'Judge', 'committee'=>'Committee Member','volunteer' => 'Volunteer', - 'fair'=>'Science Fair','sponsor' => 'Sponsor Contact'); + 'fair'=>'Science Fair','sponsor' => 'Sponsor Contact', + 'principal' => 'Principal', + 'teacher' => 'Teacher', + 'parent' => 'Parent', + 'alumni' => 'Alumni', + 'mentor' => 'Mentor'); +$user_types = array_keys($user_what); function user_valid_type($type) { @@ -128,6 +133,30 @@ function user_load_sponsor($u) return true; } +function user_load_principal(&$u) +{ + return true; +} + +function user_load_teacher(&$u) +{ + return true; +} + +function user_load_mentor(&$u) +{ + return true; +} +function user_load_parent(&$u) +{ + return true; +} + +function user_load_alumni(&$u) +{ + return true; +} + function user_load($user, $uid = false) { /* So, it turns out that doing one big load is faster than loading just @@ -139,6 +168,11 @@ function user_load($user, $uid = false) LEFT JOIN `users_volunteer` ON `users_volunteer`.`users_id`=`users`.`id` LEFT JOIN `users_fair` ON `users_fair`.`users_id`=`users`.`id` LEFT JOIN `users_sponsor` ON `users_sponsor`.`users_id`=`users`.`id` + LEFT JOIN `users_principal` ON `users_principal`.`users_id`=`users`.`id` + LEFT JOIN `users_teacher` ON `users_teacher`.`users_id`=`users`.`id` + LEFT JOIN `users_parent` ON `users_parent`.`users_id`=`users`.`id` + LEFT JOIN `users_mentor` ON `users_mentor`.`users_id`=`users`.`id` + LEFT JOIN `users_alumni` ON `users_alumni`.`users_id`=`users`.`id` WHERE "; if($uid != false) { $uid = intval($uid); @@ -215,6 +249,27 @@ function user_load_by_uid($uid) return user_load(0, $uid); } +function user_load_by_email($email) +{ + /* Find the most recent uid for the email, regardless of deleted status */ + $e = mysql_real_escape_string($email); + $q = mysql_query("SELECT uid FROM users WHERE email='$e' ORDER BY year DESC LIMIT 1"); + + if(mysql_num_rows($q) == 1) { + $i = mysql_fetch_assoc($q); + return user_load_by_uid($i['uid']); + } + return false; +} + +function user_load_by_uid_year($uid, $year) +{ + $q = mysql_query("SELECT id FROM users WHERE uid='$uid' AND year <= '$year'"); + if(!mysql_num_rows($q)) return false; + $i = mysql_fetch_assoc($q); + return user_load($i['id']); +} + function user_set_password($id, $password = NULL) { /* pass $u by reference so we can update it */ @@ -247,9 +302,9 @@ function user_set_password($id, $password = NULL) function user_save_type_list($u, $db, $fields) { - //echo "
";
-//	print_r($u);
-//	echo "
"; +/* echo "
 save type list $db";
+	print_r($u);
+	echo "
";*/ $set = ''; foreach($fields as $f) { @@ -320,13 +375,46 @@ function user_save_sponsor($u) user_save_type_list($u, 'users_sponsor', $fields); } -function user_save($u) +function user_save_teacher($u) { +} + +function user_save_principal($u) +{ +} + +function user_save_mentor($u) +{ +} + +function user_save_alumni($u) +{ +} + +function user_save_parent($u) +{ +} + +function user_save(&$u) +{ + /* Add any new types */ + $added = array_diff($u['types'], $u['orig']['types']); + foreach($added as $t) { + if(!user_add_role_allowed($t, $u)) { + echo "HALT: user can't add this type"; + exit; + } + //give em a record, the primary key on the table takes care of uniqueness + $q=mysql_query("INSERT INTO users_$t (users_id) VALUES ('{$u['id']}')"); + } + + + $fields = array('salutation','firstname','lastname','username', 'email', 'phonehome','phonework','phonecell','fax','organization', 'address','address2','city','province','postalcode','sex', - 'firstaid', 'cpr'); + 'firstaid', 'cpr', 'types'); $set = ""; foreach($fields as $f) { @@ -334,15 +422,16 @@ function user_save($u) if($set != "") $set .=','; -// if($f == 'types') -// $set .= "$f='".implode(',', $u[$f])."'"; - - $data = mysql_escape_string(stripslashes($u[$f])); - $set .= "$f='$data'"; + if($f == 'types') + $set .= "$f='".implode(',', $u[$f])."'"; + else { + $data = mysql_escape_string(stripslashes($u[$f])); + $set .= "$f='$data'"; + } } - //echo "
";
-	//print_r($u);
-	//echo "
"; +// echo "
";
+//	print_r($u);
+//	echo "
"; if($set != "") { $query = "UPDATE users SET $set WHERE id='{$u['id']}'"; mysql_query($query); @@ -354,11 +443,18 @@ function user_save($u) if($u['password'] != $u['orig']['password']) user_set_password($u['id'], $u['password']); + /* Save types */ foreach($u['types'] as $t) { - //give em a record, the primary key on the table takes care of uniqueness - $q=mysql_query("INSERT INTO users_$t (users_id) VALUES ('{$u['id']}')"); call_user_func("user_save_$t", $u); } + + /* Should we do this? */ + /* Record all the data in orig that we saved */ + unset($u['orig']); + $orig = $u; + $u['orig'] = $orig; + +// print_r($u); } /* Delete functions. These mark a user as deleted, and delete references to other @@ -393,6 +489,27 @@ function user_delete_sponsor($u) { } +function user_delete_principal($u) +{ +} + +function user_delete_teacher($u) +{ +} + +function user_delete_parent($u) +{ +} + +function user_delete_mentor($u) +{ +} + +function user_delete_alumni($u) +{ +} + + function user_delete($u, $type=false) { $finish_delete = false; @@ -558,12 +675,18 @@ function user_add_role_allowed($type, $u) /* For example, a committee member can add a volunteer or judge role to * their account. */ $allowed = array( - 'committee' => array('volunteer', 'judge'), - 'volunteer' => array('judge', 'committee'), - 'judge' => array('volunteer', 'committee'), + 'committee' => array('volunteer', 'judge', 'sponsor','principal','teacher','parent','mentor','alumni'), + 'volunteer' => array('judge', 'committee', 'sponsor','principal','teacher','parent','mentor','alumni'), + 'judge' => array('volunteer', 'committee', 'sponsor','principal','teacher','parent','mentor','alumni'), 'student' => array(), 'fair' => array(), - 'sponsor' => array('volunteer','judge') ); + 'sponsor' => array('volunteer','judge', 'sponsor','principal','teacher','parent','mentor','alumni'), + 'principal' => array('volunteer','judge', 'sponsor','committee','teacher','parent','mentor','alumni'), + 'teacher' => array('volunteer','judge', 'sponsor','principal','committee','parent','mentor','alumni'), + 'parent' => array('volunteer','judge', 'sponsor','principal','teacher','committee','mentor','alumni'), + 'mentor' => array('volunteer','judge', 'sponsor','principal','teacher','parent','committee','alumni'), + 'alumni' => array('volunteer','judge', 'sponsor','principal','teacher','parent','mentor','committee'), + ); foreach($u['types'] as $ut) { $allowed_array = $allowed[$ut]; @@ -577,45 +700,35 @@ function user_create($type, $username, $u = NULL) global $config; if(!is_array($u)) { mysql_query("INSERT INTO users (`types`,`username`,`passwordset`,`created`,`year`) - VALUES ('$type', '$username','0000-00-00', NOW(), '{$config['FAIRYEAR']}')"); + VALUES ('$type','$username','0000-00-00', NOW(), '{$config['FAIRYEAR']}')"); echo mysql_error(); $uid = mysql_insert_id(); mysql_query("UPDATE users SET uid='$uid' WHERE id='$uid'"); + echo mysql_error(); user_set_password($uid, NULL); + /* Since the user already has a type, user_save won't create this + * entry for us, so do it here */ + mysql_query("INSERT INTO users_$type (users_id) VALUES('$uid')"); + echo mysql_error(); + /* Load the complete user */ + $u = user_load($uid); } else { /* The user has been specified and already exists, * just add a role */ - $uid = $u['id']; + $uid = $u['uid']; if(!user_add_role_allowed($type, $u)) { /* If we get in here, someone is hand crafting URLs */ echo "HALT: invalid role add specified for operation."; exit; } - $new_types = implode(',', $u['types']).','.$type; - mysql_query("UPDATE users SET types='$new_types' WHERE id='$uid'"); + /* Ensure we have a full user, and add the type to the existing user */ + $u = user_load_by_uid($uid); + $u['types'][] = $type; } - - switch($type) { - case 'volunteer': - mysql_query("INSERT INTO users_volunteer(`users_id`, `volunteer_active`) VALUES ('$uid', 'yes')"); - break; - case 'student': -// mysql_query("INSERT INTO users_student(`users_id`, `student_active`) VALUES ('$uid', 'yes')"); - break; - case 'judge': - mysql_query("INSERT INTO users_judge(`users_id`, `judge_active`) VALUES ('$uid', 'yes')"); - break; - case 'fair': - mysql_query("INSERT INTO users_fair(`users_id`, `fair_active`) VALUES ('$uid', 'yes')"); - break; - case 'committee': - mysql_query("INSERT INTO users_committee(`users_id`, `committee_active`) VALUES ('$uid', 'yes')"); - break; - case 'sponsor': - mysql_query("INSERT INTO users_sponsor(`users_id`) VALUES ('$uid')"); - break; - } - return user_load($uid); + /* Activate the new type, and save, then return the user */ + $u["{$type}_active"] = 'yes'; + user_save($u); + return $u; }