forked from science-ation/science-ation
All of tonights wackload of changes
This commit is contained in:
parent
9a62fbc26d
commit
663420b078
@ -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',
|
||||
|
@ -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']}'");
|
||||
?>
|
||||
<h4>Choose Prospects</h4>
|
||||
<form id="prospectform">
|
||||
<h4><?=i18n("Choose Prospects")?></h4>
|
||||
<form id="prospectform" onsubmit="return prospect_generatelist()">
|
||||
<input type="hidden" name="fundraising_campaigns_id" value="<?=$campaign_id?>" />
|
||||
<table>
|
||||
<tr><td style="width: 130px;"><?=i18n("Type")?>:</td><td>
|
||||
<label><input type="radio" name="donortype" value="organization" onchange="donortypechange()" ><?=i18n("Organization")?></label><br />
|
||||
@ -235,8 +236,9 @@ switch($_GET['action']){
|
||||
<?
|
||||
$q=mysql_query("SELECT * FROM fundraising_donor_levels WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY min");
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
echo "<label><input onchange=\"return prospect_search()\" type=\"checkbox\" name=\"donationlevel[]\" value=\"$r->level\" >".i18n($r->level)." (".format_money($r->min,false)." - ".format_money($r->max,false).")</label><br />\n";
|
||||
echo "<label><input onchange=\"return prospect_search()\" disabled=\"disabled\" type=\"checkbox\" name=\"donationlevel[]\" value=\"$r->level\" >".i18n($r->level)." (".format_money($r->min,false)." - ".format_money($r->max,false).")</label><br />\n";
|
||||
}
|
||||
echo "(disabled until the logic requirements can be established)";
|
||||
?>
|
||||
</td></tr>
|
||||
<tr><td><?=i18n("Email Address")?>:</td><td>
|
||||
@ -254,10 +256,10 @@ switch($_GET['action']){
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="sciencehead"><?=i18n("School Science Head")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="principal"><?=i18n("School Principal")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="parent"><?=i18n("Parent/Guardian")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="mentor"><?=i18n("Mentor")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="committee"><?=i18n("Committee")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="volunteer"><?=i18n("Volunteer")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="alumni"><?=i18n("Alumni")?></label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="alumni"><?=i18n("Alumni")?>(not implemented)</label><br />
|
||||
<label><input onchange="return prospect_search()" type="checkbox" name="individual_type[]" value="mentor"><?=i18n("Mentor")?>(not implemented)</label><br />
|
||||
</td></tr></table>
|
||||
</div>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?
|
||||
|
@ -49,7 +49,16 @@ if($_POST['donortype']=="organization") {
|
||||
$primary="no";
|
||||
break;
|
||||
}
|
||||
$cq=mysql_query("SELECT * FROM users_sponsor WHERE `primary`='$primary' AND sponsors_id='$r->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 <br />";
|
||||
echo "$othernum other results <br />";
|
||||
//print_r($userslist);
|
||||
//print_r($otherlist);
|
||||
|
||||
echo "<br /><br />";
|
||||
//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 <br />";
|
||||
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 <br />";
|
||||
unset($pastlist[$uid]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// echo "removing $uid because they have NOT donated in the past <br />";
|
||||
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 <br />";
|
||||
unset($lastyearlist[$uid]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// echo "removing $uid because they have NOT donated last year <br />";
|
||||
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 <br />";
|
||||
unset($thisyearlist[$uid]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// echo "removing $uid because they have NOT donated this year <br />";
|
||||
unset($thisyearlist[$uid]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
echo "neverlist:".count($neverlist)."<br />";
|
||||
echo "pastlist:".count($pastlist)."<br />";
|
||||
echo "lastyearlist:".count($lastyearlist)."<br />";
|
||||
echo "thisyearlist:".count($thisyearlist)."<br />";
|
||||
*/
|
||||
|
||||
$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))." <br />";
|
||||
echo "<input type=\"submit\" value=\"".i18n("Generate List")."\">\n";
|
||||
//print_r($userslist);
|
||||
//print_r($otherlist);
|
||||
}
|
||||
|
||||
|
||||
echo "<br /><br />";
|
||||
echo nl2br(print_r($_POST,true));
|
||||
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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 "<tr><td>".i18n($config['postalzip'])."</td><td><input type=\"text\" name=\"postalcode\" value=\"$r->postalcode\" size=\"8\" maxlength=\"7\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Phone")."</td><td><input type=\"text\" name=\"phone\" value=\"".htmlspecialchars($r->phone)."\" size=\"16\" maxlength=\"16\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Fax")."</td><td><input type=\"text\" name=\"fax\" value=\"".htmlspecialchars($r->fax)."\" size=\"16\" maxlength=\"16\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Principal")."</td><td><input type=\"text\" name=\"principal\" value=\"".htmlspecialchars($r->principal)."\" size=\"60\" maxlength=\"64\" /></td></tr>\n";
|
||||
|
||||
if($r->principal_uid > 0)
|
||||
$pl = user_load_by_uid($r->principal_uid);
|
||||
else
|
||||
$pl = array();
|
||||
echo "<tr><td>".i18n("Principal")."</td><td><input type=\"text\" name=\"principal\" value=\"".htmlspecialchars($pl['name'])."\" size=\"60\" maxlength=\"64\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("School Email")."</td><td><input type=\"text\" name=\"schoolemail\" value=\"".htmlspecialchars($r->schoolemail)."\" size=\"60\" maxlength=\"128\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Access Code")."</td><td><input type=\"text\" name=\"accesscode\" value=\"".htmlspecialchars($r->accesscode)."\" size=\"32\" maxlength=\"32\" /></td></tr>\n";
|
||||
echo "<tr><td colspan=2><br /><b>".i18n("Science head/teacher or science fair contact at school")."</b></td></tr>";
|
||||
echo "<tr><td>".i18n("Name")."</td><td><input type=\"text\" name=\"sciencehead\" value=\"".htmlspecialchars($r->sciencehead)."\" size=\"60\" maxlength=\"64\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Phone")."</td><td><input type=\"text\" name=\"scienceheadphone\" value=\"".htmlspecialchars($r->scienceheadphone)."\" size=\"16\" maxlength=\"16\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Email")."</td><td><input type=\"text\" name=\"scienceheademail\" value=\"".htmlspecialchars($r->scienceheademail)."\" size=\"60\" maxlength=\"128\" /></td></tr>\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 "<tr><td>".i18n("Email")."</td><td><input type=\"text\" name=\"scienceheademail\" value=\"".htmlspecialchars($e)."\" size=\"60\" maxlength=\"128\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Name")."</td><td><input type=\"text\" name=\"sciencehead\" value=\"".htmlspecialchars($sh['name'])."\" size=\"60\" maxlength=\"64\" /></td></tr>\n";
|
||||
echo "<tr><td>".i18n("Phone")."</td><td><input type=\"text\" name=\"scienceheadphone\" value=\"".htmlspecialchars($sh['phonework'])."\" size=\"16\" maxlength=\"16\" /></td></tr>\n";
|
||||
|
||||
if($config['participant_registration_type']=="schoolpassword")
|
||||
{
|
||||
|
@ -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)."',
|
||||
|
@ -1 +1 @@
|
||||
145
|
||||
146
|
||||
|
57
db/db.update.146.sql
Normal file
57
db/db.update.146.sql
Normal file
@ -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 ;
|
||||
|
@ -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);
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?
|
||||
include "common.inc.php";
|
||||
require_once('common.inc.php');
|
||||
require_once('user.inc.php');
|
||||
|
||||
if($_POST['schoolid'] && $_POST['accesscode'])
|
||||
{
|
||||
$q=mysql_query("SELECT * FROM schools WHERE id='".$_POST['schoolid']."' AND accesscode='".$_POST['accesscode']."' AND year='".$config['FAIRYEAR']."'");
|
||||
@ -29,10 +31,40 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode'])
|
||||
$q=mysql_query("SELECT * FROM schools WHERE id='".$_SESSION['schoolid']."' AND accesscode='".$_SESSION['schoolaccesscode']."' AND year='".$config['FAIRYEAR']."'");
|
||||
echo mysql_error();
|
||||
$school=mysql_fetch_object($q);
|
||||
if($school)
|
||||
{
|
||||
if($_POST['action']=="save")
|
||||
{
|
||||
if($school) {
|
||||
if($_POST['action']=="save") {
|
||||
|
||||
/* Get info about science head */
|
||||
$sciencehead_update = '';
|
||||
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($school->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 "<tr><td>".i18n($config['postalzip'])."</td><td><input value=\"$school->postalcode\" type=text name=postalcode size=10></td></tr>";
|
||||
echo "<tr><td>".i18n("Phone Number")."</td><td><input value=\"$school->phone\" type=text name=phone size=30></td></tr>";
|
||||
echo "<tr><td>".i18n("Fax Number")."</td><td><input value=\"$school->fax\" type=text name=fax size=30></td></tr>";
|
||||
echo "<tr><td>".i18n("Science Teacher")."</td><td><input value=\"$school->sciencehead\" type=text name=sciencehead size=40></td></tr>";
|
||||
echo "<tr><td>".i18n("Science Teacher Email")."</td><td><input value=\"$school->scienceheademail\" type=text name=scienceheademail size=40></td></tr>";
|
||||
echo "<tr><td>".i18n("Science Teacher Phone")."<br><font size=1>(".i18n("If different than above").")</font></td><td><input value=\"$school->scienceheadphone\" type=text name=scienceheadphone size=30></td></tr>";
|
||||
|
||||
echo "<tr><td>".i18n("Science Teacher")."</td><td><input value=\"{$sh['name']}\" type=text name=sciencehead size=40></td></tr>";
|
||||
echo "<tr><td>".i18n("Science Teacher Email")."</td><td><input value=\"$sh_email\" type=text name=scienceheademail size=40></td></tr>";
|
||||
echo "<tr><td>".i18n("Science Teacher Phone")."<br><font size=1>(".i18n("If different than above").")</font></td><td><input value=\"{$sh['phonework']}\" type=text name=scienceheadphone size=30></td></tr>";
|
||||
echo "</table>";
|
||||
echo "<input type=submit value=\"".i18n("Save Changes")."\">";
|
||||
echo "</form>";
|
||||
@ -143,7 +181,7 @@ if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode'])
|
||||
echo "<h4>".i18n("School Feedback / Questions")."</h4>";
|
||||
|
||||
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 "<form method=POST action=\"schoolaccess.php\">";
|
||||
echo "<input type=hidden name=action value=\"feedback\">";
|
||||
echo "<br><textarea name=feedbacktext rows=8 cols=60></textarea><br>";
|
||||
|
207
user.inc.php
207
user.inc.php
@ -24,10 +24,15 @@
|
||||
?>
|
||||
<?
|
||||
|
||||
$user_types = array('student','judge','committee','volunteer','fair','sponsor');
|
||||
$user_what = array('student'=>'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 "<pre>";
|
||||
// print_r($u);
|
||||
// echo "</pre>";
|
||||
/* echo "<pre> save type list $db";
|
||||
print_r($u);
|
||||
echo "</pre>";*/
|
||||
$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 "<pre>";
|
||||
//print_r($u);
|
||||
//echo "</pre>";
|
||||
// echo "<pre>";
|
||||
// print_r($u);
|
||||
// echo "</pre>";
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user