diff --git a/TODO b/TODO index 13b7e0c..6e37451 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,10 @@ - Make auto-logout on email address change work properly on the FIRST submit, not on first action after the submit - same for judges changing email address +testing commit emails +test two +test three +test four +test five +test six +test seven diff --git a/admin/award_awardcreatedivisional.php b/admin/award_awardcreatedivisional.php index b49d39d..e442aff 100644 --- a/admin/award_awardcreatedivisional.php +++ b/admin/award_awardcreatedivisional.php @@ -32,8 +32,8 @@ 'Awards Main' => 'admin/awards.php') ); - if($_GET['award_sponsors_id']) $award_sponsors_id=$_GET['award_sponsors_id']; - else if($_POST['award_sponsors_id']) $award_sponsors_id=$_POST['award_sponsors_id']; + if($_GET['sponsors_id']) $sponsors_id=$_GET['sponsors_id']; + else if($_POST['sponsors_id']) $sponsors_id=$_POST['sponsors_id']; if($_GET['award_types_id']) $award_types_id=$_GET['award_types_id']; else if($_POST['award_types_id']) $award_types_id=$_POST['award_types_id']; @@ -77,7 +77,7 @@ } - if($_GET['action']=="create" && $_GET['award_sponsors_id']) + if($_GET['action']=="create" && $_GET['sponsors_id']) { $q=mysql_query("SELECT * FROM award_prizes WHERE year='-1' AND award_awards_id='0' ORDER BY `order`"); $prizes=array(); @@ -106,8 +106,8 @@ $c_category=$cat[$c_id]; echo i18n("Creating %1 - %2",array($c_category,$d_division))."
"; - mysql_query("INSERT INTO award_awards (award_sponsors_id,award_types_id,name,criteria,`order`,year) VALUES ( - '{$_GET['award_sponsors_id']}', + mysql_query("INSERT INTO award_awards (sponsors_id,award_types_id,name,criteria,`order`,year) VALUES ( + '{$_GET['sponsors_id']}', '1', '$c_category - $d_division', '".i18n("Best %1 projects in the %2 division",array($c_category,$d_division))."', @@ -157,13 +157,13 @@ echo ""; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; - echo " \n"; + echo " \n"; $numq=mysql_query("SELECT COUNT(id) AS num FROM award_prizes WHERE award_awards_id='$r->id'"); $numr=mysql_fetch_object($numq); diff --git a/admin/award_contacts.php b/admin/award_contacts.php deleted file mode 100644 index ec7646f..0000000 --- a/admin/award_contacts.php +++ /dev/null @@ -1,230 +0,0 @@ - - Copyright (C) 2005 James Grant - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -?> - 'committee_main.php', - 'Administration' => 'admin/index.php', - 'Awards Main' => 'admin/awards.php', - 'Awards Sponsors' => 'admin/award_sponsors.php')); - - if($_GET['award_sponsors_id']) - $award_sponsors_id=$_GET['award_sponsors_id']; - else if($_POST['award_sponsors_id']) - $award_sponsors_id=$_POST['award_sponsors_id']; -?> - -"; - echo ""; - echo ""; - - if($award_sponsors_id) - { - - - if($_POST['save']=="edit" || $_POST['save']=="add") - { - $p = ($_POST['primary']=='yes')?'yes':'no'; - - if($_POST['save']=="add") - { - $q=mysql_query("INSERT INTO award_contacts (award_sponsors_id,year) VALUES ('$award_sponsors_id','".$config['FAIRYEAR']."')"); - $id=mysql_insert_id(); - } - else - $id=intval($_POST['id']); - - if($p == 'no') { - /* Make sure this sponsor ($award_sponsors_id) has a primary */ - $q = mysql_query("SELECT id FROM award_contacts WHERE - award_sponsors_id='$award_sponsors_id' - AND year={$config['FAIRYEAR']} - AND `primary`='yes' - AND id!='$id'"); - if(mysql_num_rows($q) == 0) { - /* This must be the primary */ - $p = 'yes'; - } - } else { - /* Unset all other primaries */ - mysql_query("UPDATE award_contacts SET `primary`='no' - WHERE award_sponsors_id='$award_sponsors_id' - AND year={$config['FAIRYEAR']}"); - } - - $exec="UPDATE award_contacts SET ". - "salutation='".mysql_escape_string(stripslashes($_POST['salutation']))."', ". - "firstname='".mysql_escape_string(stripslashes($_POST['firstname']))."', ". - "lastname='".mysql_escape_string(stripslashes($_POST['lastname']))."', ". - "position='".mysql_escape_string(stripslashes($_POST['position']))."', ". - "phonework='".mysql_escape_string(stripslashes($_POST['phonework']))."', ". - "phonecell='".mysql_escape_string(stripslashes($_POST['phonecell']))."', ". - "phonehome='".mysql_escape_string(stripslashes($_POST['phonehome']))."', ". - "fax='".mysql_escape_string(stripslashes($_POST['fax']))."', ". - "email='".mysql_escape_string(stripslashes($_POST['email']))."', ". - "notes='".mysql_escape_string(stripslashes($_POST['notes']))."', ". - "`primary`='$p' ". - "WHERE id='$id'"; - mysql_query($exec); - - if($_POST['save']=="add") - echo happy("Contact successfully added"); - else - echo happy("Successfully saved changes to contact"); - } - - if($_GET['action']=="delete" && $_GET['delete']) - { - mysql_query("DELETE FROM award_contacts WHERE id='".$_GET['delete']."'"); - echo happy("Contact successfully deleted"); - } - - if($_GET['action']=="edit" || $_GET['action']=="add") - { - - echo "<< ".i18n("Back to %1 Contacts",array($award_sponsors_organization))."\n"; - if($_GET['action']=="edit") - { - echo "

".i18n("Edit %1 Contact",array($award_sponsors_organization))."

\n"; - $buttontext="Save Contact"; - $q=mysql_query("SELECT * FROM award_contacts WHERE id='".$_GET['edit']."'"); - $r=mysql_fetch_object($q); - } - else if($_GET['action']=="add") - { - echo "

".i18n("Add %1 Contact",array($award_sponsors_organization))."

\n"; - $buttontext="Add Contact"; - } - $buttontext=i18n($buttontext); - - echo "
\n"; - echo "\n"; - echo "\n"; - - if($_GET['action']=="edit") - echo "\n"; - - echo "
".i18n("Sponsor").":"; - $sq=mysql_query("SELECT id,organization FROM award_sponsors ORDER BY organization"); - echo ""; //only show the "choose a sponsor" option if we are adding,if we are editing, then they must have already chosen one. echo $firstsponsor; while($sr=mysql_fetch_object($sq)) { - if($sr->id == $award_sponsors_id) + if($sr->id == $sponsors_id) $sel="selected=\"selected\""; else $sel=""; diff --git a/admin/award_awards.php b/admin/award_awards.php index 5b24c37..ee6f262 100644 --- a/admin/award_awards.php +++ b/admin/award_awards.php @@ -22,10 +22,99 @@ */ ?> id; + $award_awards_name=$r->name; + $award_awards_order=$r->order; + $award_awards_criteria=$r->criteria; + $award_awards_description=$r->description; + $award_types_id=$r->award_types_id; + $award_type=$r->type; + $sponsors_id=$r->sponsors_id; + $award_sponsor=$r->organization; + $award_awards_presenter=$r->presenter; + $award_awards_excludefromac=$r->excludefromac; + $award_awards_cwsfaward=$r->cwsfaward; + $award_awards_self_nominate=$r->self_nominate; + $award_awards_schedule_judges=$r->schedule_judges;*/ + + exit; + case 'geteligibility': + $id = intval($_GET['id']); + //select the current categories that this award is linked to + $reg = array(); + $q=mysql_query("SELECT * FROM award_awards_projectcategories WHERE award_awards_id='$id'"); + while($r=mysql_fetch_assoc($q)) { + $ret['categories'][] = $r['projectcategories_id']; + } + + //select the current categories that this award is linked to + $q=mysql_query("SELECT * FROM award_awards_projectdivisions WHERE award_awards_id='$id'"); + while($r=mysql_fetch_assoc($q)) { + $ret['divisions'][] = $r['projectdivisions_id']; + } + echo json_encode($ret); + exit; + + case 'orderprizes': + foreach ($_GET['listItem'] as $position => $item) { + $sql[] = "UPDATE `table` SET `position` = $position WHERE `id` = $item"; + } + print_r($sql); + exit; +} + if($_GET['action']=="edit" || $_GET['action']=="add") { send_header(($_GET['action']=="edit") ? "Edit Award" : "Add Award", array('Committee Main' => 'committee_main.php', @@ -39,33 +128,249 @@ 'Awards Main' => 'admin/awards.php') ); } - if($_GET['award_sponsors_id'] && $_GET['award_sponsors_id']!="all") - $_SESSION['award_sponsors_id']=$_GET['award_sponsors_id']; + + if($_GET['sponsors_id'] && $_GET['sponsors_id']!="all") + $_SESSION['sponsors_id']=$_GET['sponsors_id']; + else if($_GET['sponsors_id']=="all") + unset($_SESSION['sponsors_id']); if($_GET['award_types_id'] && $_GET['award_types_id']!="all") $_SESSION['award_types_id']=$_GET['award_types_id']; + else if($_GET['award_types_id']=="all") + unset($_SESSION['award_types_id']); +/* if($_GET['award_sponsors_confirmed'] && $_GET['award_sponsors_confirmed']!="all") $_SESSION['award_sponsors_confirmed']=$_GET['award_sponsors_confirmed']; - if($_GET['award_sponsors_id']=="all") - unset($_SESSION['award_sponsors_id']); + if($_GET['sponsors_id']=="all") + unset($_SESSION['sponsors_id']); if($_GET['award_types_id']=="all") unset($_SESSION['award_types_id']); if($_GET['award_sponsors_confirmed']=="all") unset($_SESSION['award_sponsors_confirmed']); +*/ $award_types_id=$_SESSION['award_types_id']; - $award_sponsors_id=$_SESSION['award_sponsors_id']; - $award_sponsors_confirmed=$_SESSION['award_sponsors_confirmed']; + $sponsors_id=$_SESSION['sponsors_id']; + //$award_sponsors_confirmed=$_SESSION['award_sponsors_confirmed']; - if($_POST['save']=="edit" || $_POST['save']=="add") - { + + function popup_begin($name, $title, $width=0, $height=0) + { + $size= $width ? "style=\"width:$width%; height:$height%\"" : ''; + echo "
"; + echo "
+ x +

{$title}

+

"; + } + function popup_end() + { + echo "

"; + } + + + + require_once('../htabs.inc.php'); + + + + ?> + + array('label' =>'Award', + 'title' => 'Award Info', + 'callback' => 'update_awardinfo'), + 'eligibility' => array('label' =>'Eligibility', + 'title' => 'Eligibility', + 'callback' => 'update_eligibility'), + 'prizes'=> array('label' => 'Prizes', + 'title' => 'Prizes', + 'callback' => ''), + ),'awardinfo'); + +htabs_tab_begin('awardinfo'); + echo "
"; + echo "\n"; +// echo "\n"; + echo "\n"; + echo "\n"; + + echo ""; + echo "\n"; + + echo ""; + + echo "\n"; + echo "\n"; + echo "


".i18n("Name").":
".i18n("Order").":(".i18n("presentation order").")
".i18n("Sponsor").":"; + $sq=mysql_query("SELECT id,organization FROM sponsors ORDER BY organization"); + echo "
".i18n("Presenter").":
".i18n("Type").":"; + $tq=mysql_query("SELECT id,type FROM award_types WHERE year='{$config['FAIRYEAR']}' ORDER BY type"); + echo ""; + echo "
".i18n("Criteria").":
".i18n("Description").":
"; + echo "

Options

"; + echo ''; + echo ""; + echo ""; + echo ""; + echo ""; + + echo "
"; + echo "".i18n("Exclude this award from the award ceremony script")."
"; + echo "".i18n("This award identifies the students that will be attending the Canada-Wide Science Fair")."
"; + echo "".i18n("Students can self-nominate for this award (this is usually checked for special awards)")."
"; + echo "".i18n("Allow the Automatic Judge Scheduler to assign judges to this award (usually checked)")."
"; + echo "
"; + echo "\n"; + + +htabs_tab_end(); + +htabs_tab_begin('eligibility'); + echo ""; + echo ""; + + echo ""; + echo ""; +// if(count($currentcategories)==0 || count($currentdivisions)==0) +// echo ""; + echo "
".i18n("Age Categories").":"; +// if(count($currentcategories)==0) $class="class=\"error\""; else $class=""; + + //now select all the categories so we can list them all + $cq=mysql_query("SELECT * FROM projectcategories WHERE year='{$config['FAIRYEAR']}' ORDER BY mingrade"); + echo mysql_error(); + while($cr=mysql_fetch_object($cq)) { + echo "id}\" name=\"eligiblecategories\" value=\"$cr->id\" />".i18n($cr->category)."
"; + } + echo "
".i18n("Divisions").":"; + $dq=mysql_query("SELECT * FROM projectdivisions WHERE year='{$config['FAIRYEAR']}' ORDER BY division"); + echo mysql_error(); + while($dr=mysql_fetch_object($dq)) { + echo "id}\" name=\"eligibledivisions\" value=\"$dr->id\" />".i18n($dr->division)."
"; + } + + echo "
".i18n("At least one age category and one division must be selected")."
"; +htabs_tab_end(); + +htabs_tab_begin('prizes'); +?> +
 
+    
Waiting for update
+
+
    +
  • + move + Item 1 with a link to Google +
  • +
  • + move + Item 2 +
  • +
  • + move + Item 3 +
  • +
  • + move + Item 4 +
  • +
+description; $award_types_id=$r->award_types_id; $award_type=$r->type; - $award_sponsors_id=$r->award_sponsors_id; + $sponsors_id=$r->sponsors_id; $award_sponsor=$r->organization; $award_awards_presenter=$r->presenter; $award_awards_excludefromac=$r->excludefromac; @@ -236,7 +541,7 @@ echo mysql_error(); if($_POST['criteria']) $award_awards_criteria=$_POST['criteria']; if($_POST['description']) $award_awards_criteria=$_POST['description']; if($_POST['award_types_id']) $award_types_id=$_POST['award_types_id']; - if($_POST['award_sponsors_id']) $award_sponsors_id=$_POST['award_sponsors_id']; + if($_POST['sponsors_id']) $sponsors_id=$_POST['sponsors_id']; if($_POST['eligiblecategories']) $currentcategories=$_POST['eligiblecategories']; if($_POST['eligibledivisions']) $currentdivisions=$_POST['eligibledivisions']; if($_POST['presenter']) $award_awards_presenter=$_POST['presenter']; @@ -256,13 +561,13 @@ echo mysql_error(); echo "
".i18n("Name")."
".i18n("Order")."(".i18n("presentation order").")
".i18n("Sponsor").""; - $sq=mysql_query("SELECT id,organization FROM award_sponsors ORDER BY organization"); - echo ""; //only show the "choose a sponsor" option if we are adding,if we are editing, then they must have already chosen one. echo $firstsponsor; while($sr=mysql_fetch_object($sq)) { - if($sr->id == $award_sponsors_id) + if($sr->id == $sponsors_id) $sel="selected=\"selected\""; else $sel=""; @@ -362,15 +667,15 @@ echo mysql_error(); echo "
"; echo ""; echo "
"; - $q=mysql_query("SELECT id,organization FROM award_sponsors ORDER BY organization"); - echo ""; echo ""; while($r=mysql_fetch_object($q)) { - if($r->id == $award_sponsors_id) + if($r->id == $sponsors_id) { $sel="selected=\"selected\""; - $award_sponsors_organization=$r->organization; + $sponsors_organization=$r->organization; } else $sel=""; @@ -397,6 +702,9 @@ echo mysql_error(); echo ""; echo ""; +/* +//FIXME: 'confirmed' no longer exists, we need to lookup their sponsorship record and check the status there, either pending, confirmed or received, dunno if it makes sense to put that here or not.. + echo ""; + */ echo ""; echo "
"; @@ -412,12 +721,12 @@ echo mysql_error(); echo "
"; - echo "".i18n("Add New Award")."\n"; + echo "".i18n("Add New Award")."\n"; echo "
"; - if($award_sponsors_id) $where_asi="AND award_sponsors_id='$award_sponsors_id'"; + if($sponsors_id) $where_asi="AND sponsors_id='$sponsors_id'"; if($award_types_id) $where_ati="AND award_types_id='$award_types_id'"; - if($award_sponsors_confirmed) $where_asc="AND award_sponsors.confirmed='$award_sponsors_confirmed'"; +// if($award_sponsors_confirmed) $where_asc="AND award_sponsors.confirmed='$award_sponsors_confirmed'"; if(!$orderby) $orderby="order"; @@ -425,21 +734,20 @@ echo mysql_error(); award_awards.id, award_awards.name, award_awards.order, - award_awards.award_sources_id, + award_awards.award_source_fairs_id, award_types.type, - award_sponsors.organization, - award_sponsors.confirmed + sponsors.organization FROM award_awards, award_types, - award_sponsors + sponsors WHERE award_awards.year='".$config['FAIRYEAR']."' $where_asi $where_ati $where_asc - AND award_awards.award_sponsors_id=award_sponsors.id + AND award_awards.sponsors_id=sponsors.id AND award_awards.award_types_id=award_types.id AND award_types.year='".$config['FAIRYEAR']."' ORDER BY `$orderby`"); @@ -465,12 +773,12 @@ echo mysql_error(); $hasexternal=false; while($r=mysql_fetch_object($q)) { - if($r->award_sources_id){ $cl="class=\"externalaward\""; $hasexternal=true; } else $cl=""; + if($r->award_source_fairs_id){ $cl="class=\"externalaward\""; $hasexternal=true; } else $cl=""; echo "
id]\" value=\"$r->order\" size=\"3\" />$r->organization$r->type$r->nameid});\">$r->name
\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
".i18n("Salutation")."salutation)."\" size=\"4\" maxlength=\"8\" />
".i18n("First Name")."firstname)."\" size=\"32\" maxlength=\"32\" />
".i18n("Last Name")."lastname)."\" size=\"32\" maxlength=\"32\" />
".i18n("Position")."position)."\" size=\"60\" maxlength=\"64\" />
".i18n("Phone (Work)")."phonework)."\" size=\"16\" maxlength=\"32\" />
".i18n("Phone (Cell)")."phonecell)."\" size=\"16\" maxlength=\"32\" />
".i18n("Phone (Home)")."phonehome)."\" size=\"16\" maxlength=\"32\" />
".i18n("Fax")."fax)."\" size=\"16\" maxlength=\"32\" />
".i18n("Email")."email)."\" size=\"60\" maxlength=\"128\" />
".i18n("Notes")."
".i18n("Primary Contact")."
\n"; - echo "\n"; - } - else - { - - echo "
"; - echo "".i18n("Add New Contact to %1",array($award_sponsors_organization))."\n"; - echo "
"; - - $q=mysql_query("SELECT * FROM award_contacts WHERE year='".$config['FAIRYEAR']."' AND award_sponsors_id='$award_sponsors_id' ORDER BY lastname,firstname"); - - if(mysql_num_rows($q)) - { - echo ""; - echo ""; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo "\n"; - - - while($r=mysql_fetch_object($q)) - { - echo "\n"; - echo " \n"; - echo " "; - echo " \n"; - echo " \n"; - $p = i18n(($r->primary=='yes')?'Yes':''); - echo " \n"; - echo " \n"; - echo "\n"; - } - - echo "
".i18n("Name")."".i18n("Email")."".i18n("Phone (Work)")."".i18n("Phone (Cell)")."".i18n("Primary")."Actions
"; - if($r->salutation) echo $r->salutation." "; - echo "$r->firstname $r->lastname"; - if($r->email) - { - list($eb,$ea)=split("@",$r->email); - echo ""; - } - else - echo " "; - - echo "$r->phonework$r->phonecell$p"; - echo "id\">"; - echo " "; - echo "id\">"; - - - echo "
\n"; - } - - } - - - } - - send_footer(); - -?> diff --git a/admin/award_download.php b/admin/award_download.php index 374cc27..c0f0b6b 100644 --- a/admin/award_download.php +++ b/admin/award_download.php @@ -21,309 +21,220 @@ */ ?> 'committee_main.php', 'Administration' => 'admin/index.php', 'Awards Main' => 'admin/awards.php' )); - function array_remove($needle,&$haystack) { - if(in_array($needle,$haystack)) - unset($haystack[array_search($needle,$haystack)]); - } - - - if($_GET['action']=="check") + function check_source($source) { - if(count($_GET['check'])) { - require_once("xml.inc.php"); - foreach($_GET['check'] AS $checksource) { - $checksource=intval($checksource); - $q=mysql_query("SELECT * FROM award_sources WHERE id='$checksource' AND enabled='yes'"); - $r=mysql_fetch_object($q); - if(!($r->username && $r->password)) { - echo error(i18n("Username and Password are not set for source '%1'. Please set them in the SFIAB Configuration/External Award Sources editor first",array($r->name))); - continue; + global $config; + $q=mysql_query("SELECT * FROM fairs WHERE id='$source'"); + $fair=mysql_fetch_assoc($q); + if(!($fair['username'] && $fair['password'])) { + echo error(i18n("Username and Password are not set for source '%1'. Please set them in the SFIAB Configuration/External Award Sources editor first",array($r->name))); + return; + } - } - echo i18n("Checking %1 for awards...",array($r->name)); - echo "
"; + echo i18n("Checking %1 for awards...",array($fair['name'])); + echo "
"; - $req=array("awardrequest"=>array( - "username"=>$r->username, - "password"=>$r->password, - "year"=>$config['FAIRYEAR'], - ) - ); + if($fair['type'] == 'ysf') { + $req=array("awardrequest"=>array( + "username"=>$r->username, + "password"=>$r->password, + "year"=>$config['FAIRYEAR'], + ) + ); + } else { + $req['getawards'] = array('year'=>$config['FAIRYEAR']); + } - $output=""; - xmlCreateRecurse($req); - $xmldata=$output; + $data = curl_query($fair, $req); - $ch = curl_init(); /// initialize a cURL session - curl_setopt ($ch, CURLOPT_URL,"$r->url"); - curl_setopt ($ch, CURLOPT_HEADER, 0); /// Header control - curl_setopt ($ch, CURLOPT_POST, 1); /// tell it to make a POST, not a GET - curl_setopt ($ch, CURLOPT_POSTFIELDS, "xml=".$xmldata); /// put the query string here starting with "?" - curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); /// This allows the output to be set into a variable $datastream - curl_setopt ($ch, CURLOPT_POSTFIELDSIZE, 0); - curl_setopt ($ch, CURLOPT_TIMEOUT, 360); - curl_setopt ($ch, CURLOPT_SSLVERSION, 3); - curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); - $datastream = curl_exec ($ch); /// execute the curl session and return the output to a variable $datastream - $datastream = str_replace(" standalone=\"yes\"","",$datastream); - // echo "curl close
"; - curl_close ($ch); /// close the curl session + if($data['error'] != 0) { + echo error("Server said: {$data['message']}
"); + send_footer(); + exit; + } + echo notice(i18n('Server said: Success')); // echo "sending [".nl2br(htmlspecialchars($xmldata))."]"; - echo i18n("The Remote Server said:")."
"; - $response=xml_parsexml($datastream); - if(is_array($response)) { - $keys=array_keys($response); - if($keys[0]=="awardresponse") { + $keys=array_keys($data); + if(!array_key_exists('awards', $data)) { + echo error(i18n("Invalid XML response. Expecting '%1' in '%2'",array("awards",join(',',array_keys($data))))); +// echo "response=".print_r($datastream); + return; + } - //get a list of all the existing awards for this external source - $aq=mysql_query("SELECT * FROM award_awards WHERE award_sources_id='$checksource' AND year='".$config['FAIRYEAR']."'"); - $existingawards=array(); - while($ar=mysql_fetch_object($aq)) { - $existingawards[]=$ar->id; + //get a list of all the existing awards for this external source + $aq=mysql_query("SELECT * FROM award_awards WHERE award_source_fairs_id='$source' AND year='{$config['FAIRYEAR']}'"); + $existingawards=array(); + while($ar=mysql_fetch_object($aq)) { + $existingawards[$ar->id] = true; + } + + echo ""; + $ar=$response['awardresponse'][0]; + $awards = $data['awards']; + $postback = $data['postback']; + echo i18n("Postback URL: %1",array($postback))."
"; + + $numawards=is_array($awards) ? count($awards) : 0; + echo i18n("Number of Awards: %1",array($numawards))."
"; + + if($numawards == 0) { + echo i18n('No awards to process').'

'; + return; + } + + foreach($awards as $award) { + $identifier=$award['identifier']; + $year=$award['year']; + echo i18n("Award Identifier: %1",array($identifier))."   "; + echo i18n("Award Year: %1",array($year))."
"; + echo i18n("Award Name: %1",array($award['name_en']))."
"; + + if($year != $config['FAIRYEAR']) { + echo error(i18n("Award is not for the current fair year... skipping")); + echo '
'; + continue; + } + + $tq=mysql_query("SELECT * FROM award_awards WHERE + external_identifier='$identifier' AND + award_source_fairs_id='$source' AND + year='$year'"); + if(mysql_num_rows($tq) == 0) { + /* Award doesn't exist, create it, then update it with the common code below */ + mysql_query("INSERT INTO award_awards (award_types_id, + year, external_identifier, + award_source_fairs_id) + VALUES (2,'{$year}', + '".mysql_escape_string($identifier)."', + '$source')"); + $award_id=mysql_insert_id(); + } else { + echo i18n("Award already exists, updating info")."
"; + $awardrecord=mysql_fetch_object($tq); + $award_id = $awardrecord->id; + } + + //remove it from the existingawards list + unset($existingawards[$award_id]); + + //check if the sponsor exists, if not, add them + $sponsor_str = mysql_escape_string($award['sponsor']); + $sponsorq=mysql_query("SELECT * FROM sponsors WHERE organization='$sponsor_str'"); + if($sponsorr=mysql_fetch_object($sponsorq)) { + $sponsor_id=$sponsorr->id; + } else { + mysql_query("INSERT INTO sponsors (organization,year,notes,confirmed) + VALUES ('$sponsor_str','$year','".mysql_escape_string("Imported from external source: $r->name")."','yes')"); + $sponsor_id=mysql_insert_id(); + } + + mysql_query("UPDATE award_awards SET + sponsors_id='$sponsor_id', + name='".mysql_escape_string($award['name_en'])."', + criteria='".mysql_escape_string($award['criteria_en'])."', + external_postback='".mysql_escape_string($postback)."' + WHERE + id='$award_id' + AND external_identifier='".mysql_escape_string($identifier)."' + AND year='$year' + "); + echo mysql_error(); + + //update the prizes + $prizes = $award['prizes']; + if(is_array($prizes) && count($prizes) > 0) { + echo i18n("Number of prizes: %1",array(count($prizes)))."
"; + $pq=mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$award_id'"); + //get a list of all the existing prizes + $existingprizes=array(); + while($pr=mysql_fetch_object($pq)) { + $existingprizes[$pr->external_identifier]=$pr; + } + + foreach($prizes AS $prize) { + //if it doesn't exist, add it + if(!array_key_exists($prize['identifier'],$existingprizes)) { + /* Add a base entry, then update it below, yes it's two sql queries, + * but it's much shorter code, and means changing things in only + * one spot */ + echo " ".i18n("Adding prize %1",array($prize['identifier']))."
"; + mysql_query("INSERT INTO award_prizes (award_awards_id,year,externa_identifier) + VALUES ('$award_id','$year',".mysql_escape_string($prize['identifier'])."')"); + } else { + $ep=$existingprizes[$prize['identifier']]; + echo " ".i18n("Updating prize %1",array($ep->external_identifier))."
"; } - - echo ""; - $ar=$response['awardresponse'][0]; - $postback=$ar['postback'][0]; - echo i18n("Postback URL: %1",array($postback))."
"; - if($ar['awards'][0]['award']) - $numawards=count($ar['awards'][0]['award']); - else - $numawards=0; - echo i18n("Number of Awards: %1",array($numawards))."
"; - if($numawards>0) { + if(!array_key_exists($prize['identifier'],$existingprizes)) { + $ep=$existingprizes[$prize['identifier']]; - foreach($ar['awards'][0]['award'] AS $award) { - $identifier=$award['identifier'][0]; - $year=$award['year'][0]; - echo i18n("Award Identifier: %1",array($identifier))."   "; - echo i18n("Award Year: %1",array($year))."
"; - echo i18n("Award Name: %1",array($award['name_en'][0]))."
"; - - if($year==$config['FAIRYEAR']) { - $tq=mysql_query("SELECT * FROM award_awards WHERE external_identifier='$identifier' AND award_sources_id='$checksource' AND year='$year'"); - if($awardrecord=mysql_fetch_object($tq)) { - echo i18n("Award already exists, updating info")."
"; - - //remove it from the existingawards list - array_remove($awardrecord->id,$existingawards); - - - //check if the sponsor exists, if not, add them - $sponsorq=mysql_query("SELECT * FROM award_sponsors WHERE organization='".mysql_escape_string($award['sponsor'][0])."'"); - if($sponsorr=mysql_fetch_object($sponsorq)) { - $sponsor_id=$sponsorr->id; - } - else - { - mysql_query("INSERT INTO award_sponsors (organization,year,notes,confirmed) VALUES ('".mysql_escape_string($award['sponsor'][0])."','$year','".mysql_escape_string("Imported from external source: $r->name")."','yes')"); - $sponsor_id=mysql_insert_id(); - } - - mysql_query("UPDATE award_awards SET - award_sponsors_id='$sponsor_id', - name='".mysql_escape_string($award['name_en'][0])."', - criteria='".mysql_escape_string($award['criteria_en'][0])."', - external_postback='".mysql_escape_string($postback)."' - WHERE - id='$awardrecord->id' - AND external_identifier='".mysql_escape_string($identifier)."' - AND year='$year' - "); - -echo mysql_error(); - //update the prizes - if(is_array($award['prizes'][0]) && count($award['prizes'][0]['prize']>0)) - { - $prizes=$award['prizes'][0]['prize']; - $numprizes=count($prizes); - echo i18n("Number of prizes: %1",array($numprizes))."
"; - $pq=mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$awardrecord->id'"); - //get a list of all the existing prizes - $existingprizes=array(); - while($pr=mysql_fetch_object($pq)) { - $existingprizes[$pr->external_identifier]=$pr; - } - - foreach($prizes AS $prize) { - //if it exists -> update it - if(array_key_exists($prize['identifier'][0],$existingprizes)) { - $ep=$existingprizes[$prize['identifier'][0]]; - - echo " ".i18n("Updating prize %1",array($ep->external_identifier))."
"; - mysql_query("UPDATE award_prizes SET - cash='".intval($prize['cash'][0])."', - scholarship='".intval($prize['scholarship'][0])."', - value='".intval($prize['value'][0])."', - prize='".mysql_escape_string($prize['prize_en'][0])."', - number='".intval($prize['number'][0])."', - `order`='".intval($prize['ord'][0])."' - WHERE - id='$ep->id'"); - - //remove it from the list - unset($existingprizes[$ep->external_identifier]); - } - else { //if it doesnt exist -> add it - echo " ".i18n("Adding prize %1",array($prize['identifier'][0]))."
"; - - mysql_query("INSERT INTO award_prizes ( - award_awards_id, - cash, - scholarship, - value, - prize, - number, - `order`, - `year`, - external_identifier - ) VALUES ( - '$awardrecord->id', - '".intval($prize['cash'][0])."', - '".intval($prize['scholarship'][0])."', - '".intval($prize['value'][0])."', - '".mysql_escape_string($prize['prize_en'][0])."', - '".intval($prize['number'][0])."', - '".intval($prize['ord'][0])."', - '$year', - '".mysql_escape_string($prize['identifier'][0])."' - )"); - - } - } - //if an entry exists thats not in the xml -> delete it - foreach($existingprizes AS $ep) { - echo " ".i18n("Removing prize %1",array($ep->external_identifier))."
"; - mysql_query("DELETE FROM award_prizes WHERE id='$ep->id'"); - } - } - //FIXME: update the translations - } - else { - //check if the sponsor exists, if not, add them - $sponsorq=mysql_query("SELECT * FROM award_sponsors WHERE organization='".mysql_escape_string($award['sponsor'][0])."'"); - if($sponsorr=mysql_fetch_object($sponsorq)) { - $sponsor_id=$sponsorr->id; - } - else - { - mysql_query("INSERT INTO award_sponsors (organization,year,notes,confirmed) VALUES ('".mysql_escape_string($award['sponsor'][0])."','$year','".mysql_escape_string("Imported from external source: $r->name")."','yes')"); - $sponsor_id=mysql_insert_id(); - } - - echo i18n("Award does not exists, adding...")."
"; - mysql_query("INSERT INTO award_awards ( - award_types_id, - award_sponsors_id, - name, - criteria, - year, - external_identifier, - external_postback, - award_sources_id - ) - VALUES ( - 2, - $sponsor_id, - '".mysql_escape_string($award['name_en'][0])."', - '".mysql_escape_string($award['criteria_en'][0])."', - '".$year."', - '".mysql_escape_string($identifier)."', - '".mysql_escape_string($postback)."', - '$checksource' - )"); - $award_id=mysql_insert_id(); - - //import the prizes - if(is_array($award['prizes'][0]) && count($award['prizes'][0]['prize']>0)) - { - $prizes=$award['prizes'][0]['prize']; - $numprizes=count($prizes); - echo i18n("Number of prizes: %1",array($numprizes))."
"; - foreach($prizes AS $prize) { - mysql_query("INSERT INTO award_prizes ( - award_awards_id, - cash, - scholarship, - value, - prize, - number, - `order`, - `year`, - external_identifier - ) VALUES ( - '$award_id', - '".intval($prize['cash'][0])."', - '".intval($prize['scholarship'][0])."', - '".intval($prize['value'][0])."', - '".mysql_escape_string($prize['prize_en'][0])."', - '".intval($prize['number'][0])."', - '".intval($prize['ord'][0])."', - '$year', - '".mysql_escape_string($prize['identifier'][0])."' - )"); - } - } - else - echo error(i18n("No prizes associated with this award")); - - //FIXME: import the translations & prize translations - } - } - else - { - echo error(i18n("Award is not for the current fair year... skipping")); - } - echo "
"; + mysql_query("UPDATE award_prizes SET + cash='".intval($prize['cash'])."', + scholarship='".intval($prize['scholarship'])."', + value='".intval($prize['value'])."', + prize='".mysql_escape_string($prize['prize_en'])."', + number='".intval($prize['number'])."', + `order`='".intval($prize['ord'])."' + WHERE + id='$ep->id'"); + //remove it from the list + unset($existingprizes[$ep->external_identifier]); } - } - echo "
"; - //remove any awards that are left in the $existingawards array, they must have been removed from the source - foreach($existingawards AS $aid) { - echo i18n("Removing award id %1 that was removed from external source",array($aid))."
"; - mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$aid'"); - mysql_query("DELETE FROM award_awards WHERE id='$aid'"); + //if an entry exists thats not in the xml -> delete it + foreach($existingprizes AS $ep) { + echo " ".i18n("Removing prize %1",array($ep->external_identifier))."
"; + mysql_query("DELETE FROM award_prizes WHERE id='$ep->id'"); } } - else - echo error(i18n("Invalid XML response. Expecting '%1', received '%2'",array("awardresponse",$keys[0]))); - } - else - echo error(i18n("Invalid response. Could not parse XML into Array: %1",array($response))); -// echo "response=".print_r($datastream); - - echo "
"; + //FIXME: update the translations } } - else - echo error(i18n("No sources available to check")); - } - else - { + echo "
"; - if(!function_exists('curl_init')) - { + +//remove any awards that are left in the $existingawards array, they must have been removed from the source + foreach($existingawards AS $aid) { + echo i18n("Removing award id %1 that was removed from external source",array($aid))."
"; + mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$aid'"); + mysql_query("DELETE FROM award_awards WHERE id='$aid'"); + } + + echo ""; + } + + if($_GET['action']=="check") { + if(count($_GET['check'])) { + foreach($_GET['check'] AS $checksource) { + check_source(intval($checksource)); + echo "
"; + } + } else { + echo error(i18n("No sources available to check")); + } + } else { + + if(!function_exists('curl_init')) { echo error(i18n("CURL Support Missing")); echo notice(i18n("Your PHP installation does not support CURL. You will need to have CURL support added by your system administrator before being able to access external award sources")); $links=false; - } - else + } else { $links=true; + } - $q=mysql_query("SELECT * FROM award_sources WHERE enabled='yes' ORDER BY name"); + $q=mysql_query("SELECT * FROM fairs WHERE enable_awards='yes' ORDER BY name"); echo ""; echo ""; echo ""; @@ -331,16 +242,16 @@ echo mysql_error(); echo ""; while($r=mysql_fetch_object($q)) { echo ""; - echo "\n"; - echo ""; + echo "\n"; + echo ""; echo ""; echo ""; - $checkurl.="&check[]=$r->id"; + $checkurl.="&check[]={$r->id}"; } echo "
".i18n("Source Name")."".i18n("Source Location URL")."
$r->name$r->url{$r->name}{$r->url}"; if($links) - echo "id\">".i18n("check").""; + echo "id}\">".i18n("check").""; else echo "n/a"; echo "
\n"; echo "
"; diff --git a/admin/award_sponsors.php b/admin/award_sponsors.php deleted file mode 100644 index 99fd7af..0000000 --- a/admin/award_sponsors.php +++ /dev/null @@ -1,195 +0,0 @@ - - Copyright (C) 2005 James Grant - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -?> - 'committee_main.php', - 'Administration' => 'admin/index.php', - 'Awards Main' => 'admin/awards.php') - ); - - if($_POST['save']=="edit" || $_POST['save']=="add") - { - if($_POST['save']=="add") - { - $q=mysql_query("INSERT INTO award_sponsors (year) VALUES ('".$config['FAIRYEAR']."')"); - $id=mysql_insert_id(); - } - else - $id=$_POST['id']; - - - $exec="UPDATE award_sponsors SET ". - "organization='".mysql_escape_string(stripslashes($_POST['organization']))."', ". - "address='".mysql_escape_string(stripslashes($_POST['address']))."', ". - "city='".mysql_escape_string(stripslashes($_POST['city']))."', ". - "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']))."', ". - "email='".mysql_escape_string(stripslashes($_POST['email']))."', ". - "notes='".mysql_escape_string(stripslashes($_POST['notes']))."' ". - "WHERE id='$id'"; - mysql_query($exec); - - if($_POST['save']=="add") - echo happy("Sponsor successfully added"); - else - echo happy("Successfully saved changes to sponsor"); - } - - if($_GET['action']=="delete" && $_GET['delete']) - { - mysql_query("DELETE FROM award_sponsors WHERE id='".$_GET['delete']."'"); - echo happy("Sponsor successfully deleted"); - } - - if($_GET['action']=="confirm" && $_GET['confirm']) - { - mysql_query("UPDATE award_sponsors SET confirmed='yes' WHERE id='".$_GET['confirm']."'"); - echo happy("Sponsor successfully confirmed"); - - } - if($_GET['action']=="unconfirm" && $_GET['unconfirm']) - { - mysql_query("UPDATE award_sponsors SET confirmed='no' WHERE id='".$_GET['unconfirm']."'"); - echo happy("Sponsor successfully unconfirmed"); - } - - if($_GET['action']=="edit" || $_GET['action']=="add") - { - - echo "<< ".i18n("Back to Award Sponsors")."\n"; - if($_GET['action']=="edit") - { - echo "

".i18n("Edit Award Sponsor")."

\n"; - $buttontext="Save Sponsor"; - $q=mysql_query("SELECT * FROM award_sponsors WHERE id='".$_GET['edit']."'"); - $r=mysql_fetch_object($q); - } - else if($_GET['action']=="add") - { - echo "

".i18n("Add New Award Sponsor")."

\n"; - $buttontext="Add Sponsor"; - } - $buttontext=i18n($buttontext); - - echo "
\n"; - echo "\n"; - - if($_GET['action']=="edit") - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
".i18n("Organization Name")."organization)."\" size=\"60\" maxlength=\"128\" />
".i18n("Address")."address)."\" size=\"60\" maxlength=\"64\" />
".i18n("City")."city)."\" size=\"32\" maxlength=\"32\" />
".i18n($config['provincestate']).""; - emit_province_selector("province_code",$r->province_code); - echo "
".i18n($config['postalzip'])."postalcode\" size=\"8\" maxlength=\"7\" />
".i18n("Phone")."phone)."\" size=\"16\" maxlength=\"32\" />
".i18n("Fax")."fax)."\" size=\"16\" maxlength=\"32\" />
".i18n("Email")."email)."\" size=\"60\" maxlength=\"128\" />
".i18n("Notes")."
\n"; - echo "
\n"; - - - - } - else - { - - - echo "
"; - echo "Add New Sponsor\n"; - echo "
"; - echo ""; - echo ""; - echo " "; - echo " "; - echo " "; - echo " "; - echo " "; - echo "\n"; - - //$q=mysql_query("SELECT * FROM award_sponsors WHERE year='".$config['FAIRYEAR']."' ORDER BY organization"); - //we want to show all years, infact that year field probably shouldnt even be there. - $q=mysql_query("SELECT * FROM award_sponsors ORDER BY organization"); - while($r=mysql_fetch_object($q)) - { - echo "\n"; - echo "\n"; - echo " \n"; - - $numq=mysql_query("SELECT COUNT(id) AS num FROM award_awards WHERE year='".$config['FAIRYEAR']."' AND award_sponsors_id='$r->id'"); - $numr=mysql_fetch_object($numq); - $numawards=$numr->num; - - $numq=mysql_query("SELECT COUNT(id) AS num FROM award_contacts WHERE year='".$config['FAIRYEAR']."' AND award_sponsors_id='$r->id'"); - $numr=mysql_fetch_object($numq); - $numcontacts=$numr->num; - - - echo " "; - echo " "; - echo " \n"; - echo "\n"; - } - - echo "
Confirmed?Organization# of Awards# of ContactsAction
\n"; - if($r->confirmed=='yes') - { - echo "id\">\"ok_alt\"\n"; - } - else - { - echo "id\">confirm"; - } - echo "$r->organization"; - echo "$numawards  "; - echo "id\">\"view\""; - echo ""; - echo "$numcontacts  "; - echo "id\">\"view\""; - echo ""; - echo "id\">"; - echo " "; - echo "id\">"; - - - echo "
\n"; - - - } - - send_footer(); - -?> diff --git a/admin/awards.php b/admin/awards.php index 02c8ba4..7f86631 100644 --- a/admin/awards.php +++ b/admin/awards.php @@ -34,8 +34,8 @@ require_once("rerollprizes.php"); echo "
"; - echo "".i18n('Award Sponsors')."
"; - echo "".i18n('Award Sponsors Contacts')."
"; + echo "".i18n('Award Sponsors')."
"; + echo "".i18n('Award Sponsors Contacts')."
"; echo "".i18n('Awards Management')."
"; echo "
"; echo "".i18n('Edit prize template for the divisional awards').""; diff --git a/admin/committees.php b/admin/committees.php index 5d36dfa..c11156b 100644 --- a/admin/committees.php +++ b/admin/committees.php @@ -28,23 +28,9 @@ user_auth_required('committee', 'admin'); -if($_POST['users_id']) - $uid = intval($_POST['users_id']); +if($_POST['users_uid']) + $uid = intval($_POST['users_uid']); - /* Some actions we want to redirect to the personal editor, so deal with those first */ - if($_POST['add_member']) - { - $u = user_create('committee'); - list($u['firstname'], $u['lastname']) = split(' ', $_POST['add_member']); - user_save($u); - header("location: {$config['SFIABDIRECTORY']}/user_personal.php?edit={$u['id']}"); - exit; - } - - if($_POST['action'] == 'edit') { - header("location: {$config['SFIABDIRECTORY']}/user_personal.php?edit=$uid"); - exit; - } /* Now, start the output for this page */ send_header("Committee Management", @@ -52,6 +38,7 @@ if($_POST['users_id']) 'Administration' => 'admin/index.php' ), "committee_management"); + $_SESSION['last_page'] = 'committee_management'; ?> @@ -59,6 +46,21 @@ if($_POST['users_id']) "; echo ""; @@ -227,12 +227,12 @@ if($_POST['add_member_to_committees_id']) echo " "; echo "

".i18n("Add Committee Member")."

\n"; - echo "
\n"; + echo "\n"; echo "\n"; - echo "\n"; - echo " \n"; + echo " \n"; echo "
".i18n("Member Name").": "; + echo "
".i18n("Member Email").": "; echo "\n"; echo "
\n"; echo "
\n"; @@ -253,13 +253,14 @@ if($_POST['add_member_to_committees_id']) echo ""; echo ""; - $q=mysql_query("SELECT * FROM users WHERE types LIKE '%committee%' ORDER BY firstname"); - echo ""; echo "\n"; while($r=mysql_fetch_object($q)) { + if($r->deleted != 'no') continue; $displayname = $r->firstname.' '.$r->lastname; - echo "\n"; + echo "\n"; } echo ""; @@ -308,56 +309,43 @@ if($_POST['add_member_to_committees_id']) echo "ord\" />"; echo "  $r->name"; - $q2=mysql_query("SELECT - users.id, - users.firstname,users.lastname, - users.email, - users_committee.emailprivate, - committees_link.title, - committees_link.ord - FROM - users, users_committee, committees_link - WHERE - users_committee.users_id=users.id - AND committees_link.users_id=users.id - AND committees_link.committees_id='$r->id' - ORDER BY - ord,firstname"); - if(mysql_num_rows($q2)==0) - { + $q2=mysql_query("SELECT committees_link.title,committees_link.ord,users.uid,MAX(users.year),users.lastname + FROM committees_link LEFT JOIN users ON users.uid = committees_link.users_uid + WHERE committees_id='{$r->id}' + GROUP BY users.uid ORDER BY ord,users.lastname "); + + if(mysql_num_rows($q2)==0) { echo "   "; echo "id\">\"Remove"; } echo "\n"; echo mysql_error(); - while($r2=mysql_fetch_object($q2)) - { + while($r2=mysql_fetch_object($q2)) { + $u = user_load_by_uid($r2->uid); echo "    "; - echo "id}\">\"Edit\""; + echo "\"Edit\""; echo " "; - echo "id&unlinkcommittee={$r->id}\">\"Unlink\""; + echo "id}\">\"Unlink\""; echo ""; echo ""; - echo "{$r2->firstname} {$r2->lastname}"; + echo "{$u['name']}"; echo ""; - echo "title}\" name=\"title[{$r->id}][{$r2->id}]\" size=\"15\">"; + echo "title}\" name=\"title[{$r->id}][{$u['id']}]\" size=\"15\">"; echo ""; - echo "ord}\" name=\"order[{$r->id}][{$r2->id}]\" size=\"2\">"; + echo "ord}\" name=\"order[{$r->id}][{$u['id']}]\" size=\"2\">"; echo ""; - if($r2->email) - { - list($b,$a)=split("@",$r2->email); + if($u['email']) { + list($b,$a)=split("@",$u['email']); echo ""; } - if($r2->emailprivate) - { - if($r2->email) echo " / "; - list($b,$a)=split("@",$r2->emailprivate); + if($u['emailprivate']) { + if($u['email']) echo " / "; + list($b,$a)=split("@",$u['emailprivate']); echo ""; } diff --git a/admin/communication.inc.php b/admin/communication.inc.php index bdd7071..b6377bb 100644 --- a/admin/communication.inc.php +++ b/admin/communication.inc.php @@ -1,22 +1,22 @@ array("name"=>"Committee members (all)","query"=> - "SELECT firstname, lastname, organization, email FROM users WHERE types LIKE '%committee' AND deleted='no'"), + "SELECT firstname, lastname, organization, email FROM users WHERE types LIKE '%committee%' AND deleted='no' AND year='{$config['FAIRYEAR']}' "), - "judges_all"=>array("name"=>"Judges from all years","query"=> - "SELECT firstname, lastname, email FROM judges WHERE deleted='no' ORDER BY email"), + "judges_all"=>array("name"=>"(BROKEN, DO NOT USE) Judges from all years","query"=> + "SELECT firstname, lastname, email FROM users WHERE 0 ORDER BY email"), "judges_active_thisyear"=>array("name"=>"Judges active for this year", "query"=> - "SELECT DISTINCT(judges.id), firstname, lastname, email FROM judges,judges_years WHERE judges.deleted='no' AND judges_years.year='".$config['FAIRYEAR']."' AND judges.id=judges_years.judges_id ORDER BY email"), + "SELECT firstname, lastname, email FROM users LEFT JOIN users_judge ON users_judge.users_id=users.id WHERE types LIKE '%judge%' AND year='{$config['FAIRYEAR']}' AND deleted='no' AND users_judge.judge_active='yes' ORDER BY email"), - "judges_inactive"=>array("name"=>"Judges not active for this year", "query"=> + "judges_inactive"=>array("name"=>"(BROKEN, DO NOT USE) Judges not active for this year", "query"=> "SELECT judges.id, firstname, lastname, email FROM judges WHERE id NOT IN (SELECT judges_id FROM judges_years WHERE year='".$config['FAIRYEAR']."') AND judges.deleted='no' ORDER BY email"), "judges_active_complete_thisyear"=>array("name"=>"Judges active for this year and complete", "query"=> - "SELECT DISTINCT(judges.id), firstname, lastname, email FROM judges,judges_years WHERE judges.deleted='no' AND judges_years.year='".$config['FAIRYEAR']."' AND judges.id=judges_years.judges_id AND judges.complete='yes' ORDER BY email"), + "SELECT firstname, lastname, email FROM users LEFT JOIN users_judge ON users_judge.users_id=users.id WHERE types LIKE '%judge%' AND year='{$config['FAIRYEAR']}' AND users_judge.judge_complete='yes' AND deleted='no' AND users_judge.judge_active='yes' ORDER BY email"), "judges_active_incomplete_thisyear"=>array("name"=>"Judges active for this year but not complete", "query"=> - "SELECT DISTINCT(judges.id), firstname, lastname, email FROM judges,judges_years WHERE judges.deleted='no' AND judges_years.year='".$config['FAIRYEAR']."' AND judges.id=judges_years.judges_id AND judges.complete!='yes' ORDER BY email"), + "SELECT firstname, lastname, email FROM users LEFT JOIN users_judge ON users_judge.users_id=users.id WHERE types LIKE '%judge%' AND year='{$config['FAIRYEAR']}' AND users_judge.judge_complete='no' AND deleted='no' AND users_judge.judge_active='yes' ORDER BY email"), "participants_complete_thisyear"=>array("name"=>"Participants complete this year","query"=> "SELECT firstname, lastname, students.email FROM students,registrations WHERE students.registrations_id=registrations.id AND registrations.year='".$config['FAIRYEAR']."' AND ( registrations.status='complete' OR registrations.status='paymentpending') ORDER BY students.email"), @@ -51,5 +51,12 @@ "SELECT DISTINCT(teacheremail) AS email, teachername AS firstname FROM students WHERE year='".($config['FAIRYEAR']-1)."' AND teacheremail!=''"), "school_teachers_allyears"=>array("name"=>"Teachers (as entered by students) all years","query"=> "SELECT DISTINCT(teacheremail) AS email, teachername AS firstname FROM students WHERE teacheremail!=''"), +/* Volunteers */ + "volunteers_active_complete_thisyear"=>array("name"=>"Volunteers active for this year and complete", "query"=> + "SELECT id, firstname, lastname, email FROM users LEFT JOIN users_volunteer ON users_volunteer.users_id=users.id WHERE users.year='{$config['FAIRYEAR']}' AND users_volunteer.volunteer_complete='yes' AND users_volunteer.volunteer_active='yes' AND users.deleted='no' AND types LIKE '%volunteer%' ORDER BY email"), + + "volunteers_active_incomplete_thisyear"=>array("name"=>"Volunteers active for this year but not complete", "query"=> + "SELECT id, firstname, lastname, email FROM users LEFT JOIN users_volunteer ON users_volunteer.users_id=users.id WHERE users.year='{$config['FAIRYEAR']}' AND users_volunteer.volunteer_complete='no' AND users_volunteer.volunteer_active='yes' AND users.deleted='no' AND users.types LIKE '%volunteer%' ORDER BY email"), + ); ?> diff --git a/admin/curl.inc.php b/admin/curl.inc.php new file mode 100644 index 0000000..4ce2662 --- /dev/null +++ b/admin/curl.inc.php @@ -0,0 +1,86 @@ + + Copyright (C) 2009 David Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + $fair['username'], + 'password' => $fair['password']); + $str = json_encode(array_merge($d, $data)); + break; + case 'ysf': + if($ysf_url == '') + $url = $fair['url']; + else + $url = $ysf_url; + $var = 'xml'; + $output=""; + xmlCreateRecurse($data); + $str = $output; + break; + } + + echo "
Curl Send: $str
"; + + $ch = curl_init(); /// initialize a cURL session + curl_setopt ($ch, CURLOPT_URL, $url); + curl_setopt ($ch, CURLOPT_HEADER, 0); /// Header control + curl_setopt ($ch, CURLOPT_POST, 1); /// tell it to make a POST, not a GET + curl_setopt ($ch, CURLOPT_POSTFIELDS, "$var=".urlencode($str)); /// put the query string here starting with "?" + curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); /// This allows the output to be set into a variable $datastream + curl_setopt ($ch, CURLOPT_POSTFIELDSIZE, 0); + curl_setopt ($ch, CURLOPT_TIMEOUT, 360); + curl_setopt ($ch, CURLOPT_SSLVERSION, 3); + curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); + $datastream = curl_exec ($ch); /// execute the curl session and return the output to a variable $datastream + curl_close ($ch); /// close the curl session + +// echo "
Server Returned: ".urldecode($datastream)."
"; + + switch($fair['type']) { + case 'sfiab': + $ret=json_decode(urldecode($datastream), true); + break; + case 'ysf': + $datastream = str_replace(" standalone=\"yes\"","",$datastream); + /* Return is plaintext, make a return array */ + $ret['error'] = 0; + $ret['message'] = $datastream; + break; + } + echo "
Server Returned: ";print_r($ret);echo "

"; + return $ret; + } +?> diff --git a/admin/fair_stats.php b/admin/fair_stats.php new file mode 100644 index 0000000..6fa55e5 --- /dev/null +++ b/admin/fair_stats.php @@ -0,0 +1,513 @@ + + Copyright (C) 2009 David Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + 'committee_main.php', + 'Administration' => 'admin/index.php'), + "one-click_ysf_affiliation_stats" + ); + echo "
"; + + /* SFIAB config options server side */ + $server_config = array(); + $server_config['fair_stats_participation'] = 'no'; + $server_config['fair_stats_schools_ext'] = 'no'; + $server_config['fair_stats_minorities'] = 'no'; + $server_config['fair_stats_guests'] = 'no'; + $server_config['fair_stats_sffbc_misc'] = 'no'; + $server_config['fair_stats_info'] = 'no'; + $server_config['fair_stats_next_chair'] = 'no'; + $server_config['fair_stats_scholarships'] = 'no'; + $server_config['fair_stats_delegates'] = 'no'; + + if($_GET['year']) $year=intval($_GET['year']); + else $year=$config['FAIRYEAR']; + + if($_GET['id']) $fairs_id=intval($_GET['id']); + else if($_POST['id']) $fairs_id=intval($_POST['id']); + else $fairs_id = -1; + + if($fairs_id != -1) { + $q = mysql_query("SELECT * FROM fairs WHERE id='$fairs_id'"); + $fair = mysql_fetch_assoc($q); + } + + $action = $_POST['action']; + + if($action == 'sendstats') { + foreach(array_keys($stats_data) as $k) { + $stats[$k] = $_POST[$k]; + } + $stats['year'] = $year; + if($fair['type'] == 'ysf') { + $st = stats_to_ysf($fair, $stats); + $req = array('affiliation' => array( + "ysf_region_id"=>$fair['username'], + "ysf_region_password"=>$fair['password'], + "year"=>$year, + 'stats'=>$st) + ); + } else { + $req = array('stats'=>$stats); + } + + if(function_exists('curl_init')) { + $r = curl_query($fair, $req, + 'https://secure.ysf-fsj.ca/registration/xmlaffiliation.php'); + if($r['error'] == 0) + echo happy(i18n("The %1 Server said:", array($fair['name'])).' '.$r['message']); + else + echo error(i18n("The %1 Server said:", array($fair['name'])).' '.$r['message']); +// $fairs_id = -1; +// $year = $config['FAIRYEAR']; + } else { + echo error("CURL Support Missing"); + echo i18n("Your PHP installation does not support CURL. You will need to login to the YSF system as the regional coodinator and upload the XML data manually"); + send_footer(); + exit; + } + } + + + echo "
"; + $q=mysql_query("SELECT * FROM fairs WHERE `type`='sfiab' OR `type`='ysf'"); + echo ""; + echo "\n"; + while($r=mysql_fetch_object($q)) { + if($year==$r->year) $sel="selected=\"selected\""; else $sel=""; + echo "\n"; + } + echo "\n"; + echo ""; + echo "
"; + echo "
"; + echo "
"; + + if($fairs_id == -1) { + echo i18n('Statistics will be shown below this line before being sent. Please select a fair and year first.'); + /* Wait for them to select somethign before generating stats */ + send_footer(); + exit; + } + + if($fair['type'] == 'ysf') { + $data['statconfig'] = array('fair_stats_participation'); + } else { + echo notice(i18n('Getting stats request and downloading existing stats from server %1', array($fair['url']))); + /* Query the server to see what stats we need */ + $q=array('getstats' => array('year' => $year)); + + $data = curl_query($fair, $q); + + if($data['error'] != 0) { + echo error("Server said: {$data['message']}
"); + send_footer(); + exit; + } + echo notice(i18n('Server said: Success')); + } + echo '
'; + echo i18n('This server has requested the following stats for your %1 fair:', array($year)); + echo '

'; + + foreach($server_config as $k=>$v) { + $server_config[$k] = $data['statconfig'][$k]; + } + + /* Gather all stats, then we'll decide what to send */ + $stats = array(); + $stats['year'] = $year; + + /* Now, overwrite all the stats with what we pulled down from the server */ + if(is_array($data['stats'])) { + foreach($data['stats'] as $k=>$v) { + $stats[$k] = $v; + } + } +// print_r($data['stats'][0]); + + /* And now, overwrite all the stuff we pulled down with stats we can compute */ + + //number of schools + $q=mysql_query("SELECT COUNT(id) AS num FROM schools WHERE year='$year'"); + $r=mysql_fetch_object($q); + $stats['schools_total']=$r->num; + + //number of schools participating + $q=mysql_query("SELECT DISTINCT(students.schools_id) AS sid, schools.* + FROM students + LEFT JOIN registrations ON students.registrations_id=registrations.id + LEFT JOIN schools ON students.schools_id=schools.id + WHERE students.year='$year' + AND registrations.year='$year' + AND (registrations.status='complete' OR registrations.status='paymentpending')"); + $stats['schools_active']=mysql_num_rows($q); + $stats['schools_public'] = 0; + $stats['schools_private'] = 0; + $stats['schools_atrisk'] = 0; + $districts = array(); + while($si=mysql_fetch_assoc($q)) { + if($si['designate'] == 'public') + $stats['schools_public']++; + if($si['designate'] == 'independent') + $stats['schools_private']++; + if($si['atrisk'] == 'yes') + $stats['schools_atrisk']++; + $bd = $si['board'].'~'.$si['district']; + if(!in_array($bd, $districts)) $districts[] =$bd; + } + $stats['schools_districts'] = count($districts); + + //numbers of students: + $q=mysql_query("SELECT students.*,schools.* + FROM students + LEFT JOIN registrations ON students.registrations_id=registrations.id + LEFT JOIN schools on students.schools_id=schools.id + WHERE students.year='$year' + AND registrations.year='$year' + AND (registrations.status='complete' OR registrations.status='paymentpending')"); + echo mysql_error(); + $stats['students_total'] = mysql_num_rows($q); + $stats['students_public'] = 0; + $stats['students_private'] = 0; + $stats['students_atrisk'] = 0; + $grademap = array(1=>1, 2=>1, 3=>1, 4=>4, 5=>4, 6=>4, 7=>7, 8=>7, + 9=>9, 10=>9, 11=>11, 12=>11, 13=>11); + foreach($grademap as $k=>$g) { + $stats["male_$g"] = 0; + $stats["female_$g"] = 0; + $stats["projects_$g"] = 0; + } + $unknown = array(); + while($s=mysql_fetch_assoc($q)) { + if(!in_array($s['sex'], array('male','female'))) + $unknown[$grademap[$s['grade']]]++; + else + $stats["{$s['sex']}_{$grademap[$s['grade']]}"]++; + + if($s['designate'] == 'public') + $stats['students_public']++; + if($s['designate'] == 'independent') + $stats['students_private']++; + if($s['atrisk'] == 'yes') + $stats['students_atrisk']++; + } + + foreach($unknown as $g=>$a) { + $m = round($a/2); + $f = $a - $m; + $stats["male_$g"] += $m; + $stats["female_$g"] += $f; + } + + //projects + $q=mysql_query("SELECT MAX(students.grade) AS grade FROM students + LEFT JOIN registrations ON students.registrations_id=registrations.id + LEFT JOIN projects ON projects.registrations_id=registrations.id + WHERE students.year='$year' + AND registrations.year='$year' + AND projects.year='$year' + AND (registrations.status='complete' OR registrations.status='paymentpending') + GROUP BY projects.id"); + echo mysql_error(); + while($r=mysql_fetch_assoc($q)) { + $stats["projects_{$grademap[$r['grade']]}"]++; + } + + + $q=mysql_query("SELECT COUNT(id) AS num FROM users + LEFT JOIN users_committee ON users_committee.users_id=users.id + WHERE types LIKE '%committee%' + AND year='$year' + AND users_committee.committee_active='yes' + AND deleted='no'"); + $r = mysql_fetch_object($q); + $stats['committee_members'] = $r->num; + + $q=mysql_query("SELECT COUNT(id) AS num FROM users LEFT JOIN users_judge ON users_judge.users_id=users.id + WHERE users.year='$year' + AND users.types LIKE '%judge%' + AND users.deleted='no' + AND users_judge.judge_complete='yes' + AND users_judge.judge_active='yes'"); + $r=mysql_fetch_object($q); + $stats['judges'] = $r->num; + + +/* All stats have been gathered, print them */ + + + /* Print all blocks the server requests */ + echo "
"; + echo ""; + + if($server_config['fair_stats_info'] == 'yes') { + echo '

'.i18n('%1 Fair information', array($year)).'

'; + echo ''; + echo ''; + echo ""; + echo ''; + echo ""; + echo ''; + echo ''; + echo ''; + echo ""; + echo ''; + echo ''; + echo ''; + echo ""; + echo '
'.i18n('Fair Start Date').':(YYYY-MM-DD)
'.i18n('Fair End Date').':(YYYY-MM-DD)
'.i18n('Fair Location/Address').':
'.i18n('Fair Budget').':$
'.i18n('YSF Affiliation Complete').'?
'.i18n('Charity Number or Information').'?
'; + echo '
'; + echo '
'; + } + + + if($server_config['fair_stats_next_chair'] == 'yes') { + echo '

'.i18n('%1 - %2 Chairperson (if known)', array($year, $year+1)).'

'; + echo ''; + echo ''; + echo ""; + echo ''; + echo ""; + echo ''; + echo ""; + echo ''; + echo ""; + echo ''; + echo ""; + echo ''; + + echo '
'.i18n('Name').': '.i18n('Email').':
'.i18n('Tel. Bus').': '.i18n('Tel. Home').':
'.i18n('Fax').':
'; + echo '

'; + } + + if($server_config['fair_stats_delegates'] == 'yes') { + echo '

'.i18n('%1 CWSF Delegates and Alternatives', array($year)).'

'; + echo ''; + echo ''; + for($x=1;$x<=3;$x++) { + $sizes = array('small'=>'Small', 'medium'=>'Medium', 'large'=>'Large', 'xlarge'=>'X-Large'); + echo ""; + echo ""; + echo "'; + } + echo '
'.i18n('Delegate Name(s)').''.i18n('Email').''.i18n('Jacket Size').'
'; + echo i18n('Remember, the jackets fit smaller than normal sizes.'); + echo '

'; + } + + if($server_config['fair_stats_scholarships'] == 'yes') { + echo '

'.i18n('%1 Scholarships', array($year)).'

'; + echo 'How many university/college scholarships are available at your fair? (use a format like:
6 - University of British Columbia - Entrance Scholarships
'; + echo ''; + echo '

'; + } + + if($server_config['fair_stats_participation'] == 'yes') { + $rangemap = array(1=>'1-3', 4=>'4-6', 7=>'7-8', 9=>'9-10', 11=>'11-12'); + echo '

'.i18n('%1 Fair participation', array($year)).'

'; + echo '
'; + echo i18n("Number of students").": {$stats['students_total']}"; + echo ''; + echo ''; + foreach($rangemap as $k=>$v) echo ""; + echo ''; + echo ''; + foreach($rangemap as $k=>$v) echo ""; + echo ''; + echo ''; + foreach($rangemap as $k=>$v) echo ""; + echo ''; + echo ''; + foreach($rangemap as $k=>$v) echo ""; + echo ''; + echo '
'.i18n('Grade').'
$v
'.i18n('Male').'{$stats["male_$k"]}
'.i18n('Female').'{$stats["female_$k"]}
'.i18n('Projects').'{$stats["projects_$k"]}
'; + echo '
'; + echo i18n("Number of schools").": {$stats['schools_total']}"; + echo '
'; + echo i18n("Number of active schools").": {$stats['schools_active']}"; + echo '
'; + echo '
'; + echo i18n("Number of committee members: %1 (note: this is number of committee members who logged in to SFIAB for the year, anyone who was active but didn't log in to SFIAB will NOT be counted)",array($stats['committee_members'])); + echo '
'; + echo i18n("Number of judges").": {$stats['judges']}"; + echo '
'; + echo '
'; + echo '
'; + } + + if($server_config['fair_stats_schools_ext'] == 'yes') { + echo '

'.i18n('%1 Extended School/Participant data', array($year)).'

'; + echo '
'; + echo i18n('Public schools: %1 (%2 students).',array( + $stats['schools_public'], $stats['students_public'])); + echo '
'; + echo i18n('Private/Independent schools: %1 (%2 students).',array( + $stats['schools_private'], $stats['students_private'])); + echo '
'; + echo i18n('At-risk/inner city schools: %1 (%2 students).',array( + $stats['schools_atrisk'], $stats['students_atrisk'])); + echo '
'; + echo i18n('Number of school boards/distrcits: %1',array( + $stats['schools_districts'])); + echo '
'; + echo '
'; + echo '
'; + } + if($server_config['fair_stats_minorities'] != '') { + echo '

'.i18n('%1 Data on minority groups', array($year)).'

'; + echo '
'; + echo ''; + if(strstr('firstnations',$server_config['fair_stats_minorities']) != false) { + echo ''; + } + echo '
'.i18n('Number of First Nations students'); + echo ": "; + echo '
'; + echo '
'; + echo '
'; + } + if($server_config['fair_stats_guests'] == 'yes' ) { + echo '

'.i18n('%1 Guests visiting the fair', array($year)).'

'; + echo '
'; + echo ''; + echo ''; + echo ''; + echo '
'.i18n('Number of Students that visited the fair (tours, etc.)'); + echo ": "; + echo '
'.i18n('Number of Public Guests that visited the fair'); + echo ": "; + echo '
'; + echo '
'; + echo '
'; + } + + if($server_config['fair_stats_sffbc_misc'] == 'yes') { + echo '

'.i18n('%1 Misc. SFFBC Questions', array($year)).'

'; + echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'.i18n('Number of Teachers supporting student projects'); + echo ": "; + echo '
'.i18n('Number of Students indicating increased interest in science & technology'); + echo ": "; + echo '
'.i18n('Number of Students considering careers in science & technology'); + echo ": "; + echo '
'; + echo '
'; + echo '
'; + } + $keys = array_keys($stats_data); + foreach($keys as $k) { + if($stats_data[$k]['manual'] == true) continue; + echo ""; + } + + echo ""; + echo '
'; + echo "
"; + echo "
"; + + /* Format XML output, and print it, last chance for the user to edit it */ +/* + $xml = stats_to_xml($fair, $stats); + + echo '
'; + echo "

".i18n("The following data will be sent to")." {$fair['name']}

"; + echo "
"; + echo ""; + echo ""; + echo ""; + echo "
"; + echo "
"; + echo ""; + echo "
"; +*/ + + echo "
";
+ print_r($fair);
+ print_r($server_config);
+ print_r($stats);
+ echo "
"; + + send_footer(); +?> diff --git a/admin/fundraising.php b/admin/fundraising.php new file mode 100644 index 0000000..c0b9fcd --- /dev/null +++ b/admin/fundraising.php @@ -0,0 +1,138 @@ + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + 'committee_main.php', + 'Administration' => 'admin/index.php'), + "fundraising" + ); + +require_once("../dialog.inc.php"); + + //first, insert any defaults + $q=mysql_query("SELECT * FROM fundraising WHERE year='".$config['FAIRYEAR']."'"); + if(!mysql_num_rows($q)) { + $q=mysql_query("SELECT * FROM fundraising WHERE year='-1'"); + while($r=mysql_fetch_object($q)) { + mysql_query("INSERT INTO fundraising (`type`,`name`,`description`,`system`,`goal`,`year`) VALUES ('$r->type','".mysql_real_escape_string($r->name)."','".mysql_real_escape_string($r->description)."','$r->system','$r->goal','".$config['FAIRYEAR']."')"); + } + } + +//this table is eventually going to be massive, and probably not in a tableview format, it'll show goals as well as all ongoing fund pledges, probabilities, etc as well as over/under, etc, all prettily colour coded.. basically a good overview of the total fundraising status of the fair. + $q=mysql_query("SELECT * FROM fundraising WHERE year='{$config['FAIRYEAR']}' ORDER BY system DESC,type"); + echo ""; + + while($r=mysql_fetch_object($q)) { + echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + if($r->type=="general") + $orsql.="OR fundraising_type IS NULL"; + + $typetotal=0; + $sq=mysql_query("SELECT sponsorships.id, sponsors.organization, sponsorships.value, sponsorships.status, sponsorships.probability + FROM sponsorships + JOIN sponsors ON sponsorships.sponsors_id=sponsors.id + WHERE (sponsorships.fundraising_type='$r->type' $orsql) + AND sponsorships.year='{$config['FAIRYEAR']}' + ORDER BY status DESC, probability DESC, organization"); + while($sr=mysql_fetch_object($sq)) { + echo "id\" class=\"fundraising{$sr->status}\">"; + echo ""; + echo "\n"; + /* + echo "id\">"; + + //only user emails can be deleted, system ones are required and cannot be removed + if($r->type=="user") + { + echo " "; + echo "id\">"; + echo " "; + echo "id\">Send"; + } + + + */ + echo ""; + echo ""; + echo ""; + } + else + echo "\n"; + + $probval=$sr->probability/100*$sr->value; + echo ""; + echo "\n"; + echo "\n"; + $typetotal+=$probval; + } + echo ""; + echo ""; + echo "\n"; + echo "\n"; + $typediff=$typetotal-$r->goal; + echo "\n"; + echo "\n"; + + $totalgoal+=$r->goal; + $totaldiff+=$typediff; + echo "\n"; + } + echo ""; + echo ""; + echo "\n"; + echo "
id',400,250)\" href=\"#\">"; + if($r->system=="no") { + echo "id\">"; + } + + echo "".i18n($r->name)."".format_money($r->goal)."
id&fundraising_type=$r->type',400,250)\" href=\"#\">"; + echo "id\">"; + + echo "$sr->organization$sr->status"; + if($sr->status=="pending") + { + echo "$sr->probability%"; + echo "".format_money($sr->value)."".format_money($probval)."
type',400,250)\" href=\"#\">add".i18n("%1 Total",array($r->name),array("Fundraising type total, eg) Award Sponsorship Total"))."".format_money($typetotal)."".format_money($typediff)."
 
add fund type".i18n("Total Net Position")."".format_money($totaldiff)."
\n"; + echo "
\n"; + echo "
\n"; + echo "Manage Sponsorship Levels\n"; + echo "
\n"; + echo "Manage Sponsors\n"; + echo "
\n"; + + send_footer(); +?> diff --git a/admin/fundraising_sponsorship.php b/admin/fundraising_sponsorship.php new file mode 100644 index 0000000..1fbac79 --- /dev/null +++ b/admin/fundraising_sponsorship.php @@ -0,0 +1,105 @@ + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +Edit Sponsorship"; + $sponsorship=mysql_fetch_object($q); + $formaction="sponsorshipedit"; + } + else + { + echo "

Create New Sponsorship

"; + $formaction="sponsorshipadd"; + $fundraising_type=$_GET['fundraising_type']; + } + + echo ""; + echo ""; + echo ""; + echo ""; + echo "\n"; + + echo ""; + echo "\n"; + echo "\n"; + + echo ""; + echo "\n"; + + echo ""; + echo "\n"; + + echo "
".i18n("Sponsor").""; + + if($formaction=="sponsorshipadd") { + $q=mysql_query("SELECT * FROM sponsors ORDER BY organization"); + echo mysql_error(); + echo " ".i18n("Add")."\n"; + } + else { + echo $sponsorship->organization; + } + echo "
".i18n("Type").""; + $q=mysql_query("SELECT * FROM fundraising WHERE year='{$config['FAIRYEAR']}' ORDER BY name"); + echo mysql_error(); + echo "\n"; + echo "
".i18n("Amount")."value\">
".i18n("Status").""; + echo "\n"; + echo "
".i18n("Probability").""; + echo "\n"; + echo "
\n"; + +?> diff --git a/admin/fundraising_sponsorship_handler.inc.php b/admin/fundraising_sponsorship_handler.inc.php new file mode 100644 index 0000000..7a0a004 --- /dev/null +++ b/admin/fundraising_sponsorship_handler.inc.php @@ -0,0 +1,80 @@ +fundraising_type!=$fundraising_type) + $log[]="Changed sponsorship type from $current->fundraising_type to $fundraising_type"; + + if($current->value!=$value) + $log[]="Changed sponsorship value from $current->value to $value"; + + if($current->status!=$status) + $log[]="Changed sponsorship status from $current->status to $status"; + + if($current->probability!=$probability) + $log[]="Changed sponsorship probability from $current->probability to $probability"; + + if(count($log)) { + mysql_query("UPDATE sponsorships SET fundraising_type='$fundraising_type', value='$value', status='$status', probability='$probability' WHERE id='$sponsorships_id'"); + + foreach($log AS $l) { + mysql_query("INSERT INTO sponsors_logs (sponsors_id,dt,users_id,log) VALUES ( + '$current->sponsors_id', + NOW(), + '".$_SESSION['users_id']."', + '".mysql_real_escape_string($l)."')"); + + } + if(mysql_error()) + message_push(error(mysql_error())); + else + message_push(happy(i18n("Saved sponsorship changes"))); + } + else + message_push(happy(i18n("No changes were made"))); + } + else { + message_push(error(i18n("Required fields were missing, please try again"))); + } + +} +if($_POST['action']=="sponsorshipadd") { + if($sponsors_id && $fundraising_type && $value) { + mysql_query("INSERT INTO sponsorships (sponsors_id,fundraising_type,value,status,probability,year) VALUES ('$sponsors_id','$fundraising_type','$value','$status','$probability','{$config['FAIRYEAR']}')"); + mysql_query("INSERT INTO sponsors_logs (sponsors_id,dt,users_id,log) VALUES ( + '$sponsors_id', + NOW(), + '".$_SESSION['users_id']."', + '".mysql_real_escape_string("Created sponsorship: type=$fundraising_type, value=\$$value, status=$status, probability=$probability%")."')"); + message_push(happy(i18n("Added new sponsorship"))); + } + else + message_push(error(i18n("Required fields were missing, please try again"))); + if(mysql_error()) + message_push(error(mysql_error())); +} + +?> diff --git a/admin/fundraising_types.php b/admin/fundraising_types.php new file mode 100644 index 0000000..dccbb36 --- /dev/null +++ b/admin/fundraising_types.php @@ -0,0 +1,59 @@ + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +Edit Fund"; + $fund=mysql_fetch_object($q); + $formaction="fundedit"; + } + else { + echo "

Create New Fund

"; + $formaction="fundadd"; + } + + echo ""; + echo ""; + + echo ""; + if($fund->system=="yes") { + echo "\n"; + echo "\n"; + echo "\n"; + } + else { + echo "\n"; + echo "\n"; + echo "\n"; + } + echo "\n"; + echo "\n"; + echo "
".i18n("Type")."".i18n("System (non-editable)")."
".i18n("Name")."".htmlspecialchars($fund->name)."
".i18n("Key")."".htmlspecialchars($fund->type)."
".i18n("Type")."".i18n("Custom (editable)")."
".i18n("Name")."name)."\">
".i18n("Key")."type)."\">
".i18n("Description")."
".i18n("Goal")."goal\">
\n"; + +?> diff --git a/admin/fundraising_types_handler.inc.php b/admin/fundraising_types_handler.inc.php new file mode 100644 index 0000000..2082b46 --- /dev/null +++ b/admin/fundraising_types_handler.inc.php @@ -0,0 +1,62 @@ +system=="no") { + mysql_query("DELETE FROM sponsorships WHERE fundraising_type='".mysql_real_escape_string($f->type)."' AND year='".$config['FAIRYEAR']."'"); + mysql_query("DELETE FROM fundraising WHERE id='$id'"); + if(mysql_affected_rows()) + message_push(happy(i18n("Successfully removed fund %1",array($f->name)))); + } + else { + message_push(error(i18n("Cannot remove system fund"))); + } + } +} +if($_POST['action']=="fundedit" || $_POST['action']=="fundadd") { + $fundraising_id=intval($_POST['fundraising_id']); + if($fundraising_id) { + $q=mysql_query("SELECT * FROM fundraising WHERE id='$fundraising_id'"); + $f=mysql_fetch_object($q); + $system=$f->system; + } + $name=mysql_real_escape_string($_POST['name']); + $type=mysql_real_escape_string($_POST['type']); + $description=mysql_real_escape_string($_POST['description']); + $goal=intval($_POST['goal']); +} + +if($_POST['action']=="fundedit") { + if( ($system=="yes" && $goal) || ($system=="no" && $goal && $type && $name) ) { + if($system=="yes") { + mysql_query("UPDATE fundraising SET goal='$goal', description='$description' WHERE id='$fundraising_id'"); + } + else { + mysql_query("UPDATE fundraising SET goal='$goal', description='$description', type='$type', name='$name' WHERE id='$fundraising_id'"); + } + if(mysql_error()) + message_push(error(mysql_error())); + else + message_push(happy(i18n("Saved fund changes"))); + } + else { + message_push(error(i18n("Required fields were missing, please try again"))); + } + +} +if($_POST['action']=="fundadd") { + if( $goal && $type && $name) { + mysql_query("INSERT INTO fundraising (type,name,description,system,goal,year) VALUES ('$type','$name','$description','no','$goal','{$config['FAIRYEAR']}')"); + message_push(happy(i18n("Added new fund"))); + } + else + message_push(error(i18n("Required fields were missing, please try again"))); + if(mysql_error()) + message_push(error(mysql_error())); +} + +?> diff --git a/admin/index.php b/admin/index.php index 79c6c2a..7f3949d 100644 --- a/admin/index.php +++ b/admin/index.php @@ -42,8 +42,12 @@ echo "".theme_icon("volunteer_management")."
".i18n("Volunteer Management")."
"; else echo theme_icon("volunteer_management")."
".i18n("Volunteer Management")."
(".i18n("disabled").")"; - echo ""; - echo " "; + echo ''; + echo " ".theme_icon("sciencefair_management")."
".i18n("Science Fair Management")."
"; + echo ''; + echo ''; + echo ''; + echo "\n"; echo "
"; echo ""; @@ -93,6 +97,7 @@ echo " "; echo " "; echo " "; + echo " "; echo " "; echo " \n"; echo "
".theme_icon("communication")."
".i18n("Communication (Send Emails)")."
".theme_icon("internal_document_management")."
".i18n("Internal Document Management")."
".theme_icon("website_content_management")."
".i18n("Website Content Management")."
".theme_icon("fundraising")."
".i18n("Fundraising")."
\n"; diff --git a/admin/judges.inc.php b/admin/judges.inc.php index 22aac84..a8f6c30 100644 --- a/admin/judges.inc.php +++ b/admin/judges.inc.php @@ -28,16 +28,16 @@ function getJudgingTeams() //get the members for this team $mq=mysql_query("SELECT - judges.id AS judges_id, - judges.firstname, - judges.lastname, + users.id AS judges_id, + users.firstname, + users.lastname, judges_teams_link.captain FROM - judges, + users, judges_teams_link WHERE - judges_teams_link.judges_id=judges.id AND + judges_teams_link.users_id=users.id AND judges_teams_link.judges_teams_id='$r->id' ORDER BY captain DESC, @@ -49,16 +49,9 @@ function getJudgingTeams() $teamlangs=array(); while($mr=mysql_fetch_object($mq)) { - $lq=mysql_query("SELECT * FROM judges_languages WHERE judges_id='$mr->judges_id'"); - $judgelangs=""; - if(mysql_num_rows($lq)) { - while($lr=mysql_fetch_object($lq)) { - $judgelangs.="$lr->languages_lang/"; - if(!in_array($lr->languages_lang,$teamlangs)) - $teamlangs[]=$lr->languages_lang; - } - $judgelangs=substr($judgelangs,0,-1); - } + $u = user_load($mr->judges_id, false); + $judgelangs = join('/', $u['languages']); + $teams[$lastteamid]['members'][]=array( "id"=>$mr->judges_id, "firstname"=>$mr->firstname, @@ -130,16 +123,16 @@ function getJudgingTeam($teamid) //get the members for this team $mq=mysql_query("SELECT - judges.id AS judges_id, - judges.firstname, - judges.lastname, + users.id AS judges_id, + users.firstname, + users.lastname, judges_teams_link.captain FROM - judges, + users, judges_teams_link WHERE - judges_teams_link.judges_id=judges.id AND + judges_teams_link.users_id=users.id AND judges_teams_link.judges_teams_id='$r->id' ORDER BY captain DESC, @@ -208,4 +201,23 @@ function getJudgingEligibilityCode() { } } +function judges_load_all() +{ + global $config; + + $ret = array(); + + $query = "SELECT id FROM users WHERE types LIKE '%judge%' + AND year='{$config['FAIRYEAR']}' + AND deleted='no'"; + $r = mysql_query($query); + while($i = mysql_fetch_assoc($r)) { + $u = user_load($i['id']); + if($u['judge_complete'] == 'no') continue; + + $ret[$i['id']] = $u; + } + return $ret; +} + ?> diff --git a/admin/judges.php b/admin/judges.php index f1957d5..1aa7320 100644 --- a/admin/judges.php +++ b/admin/judges.php @@ -33,12 +33,8 @@ ); echo "
"; echo ''.i18n('Judges').''; echo ''.i18n('Create the Judging Schedule').'
    '; echo "
  • ".i18n("Create/Edit Judging Timeslots")."
  • "; diff --git a/admin/judges_info.php b/admin/judges_info.php index 1e28ccd..9a77bea 100644 --- a/admin/judges_info.php +++ b/admin/judges_info.php @@ -40,167 +40,175 @@ $preferencechoices=array( ); - if($_GET['id']) - { - //include "../register_judges.inc.php"; + $id = intval($_GET['id']); - $q=mysql_query("SELECT - judges.* - FROM - judges - WHERE - judges.id='".$_GET['id']."'"); - echo mysql_error(); - $judgeinfo=mysql_fetch_object($q); - - send_popup_header(i18n("Judge Information - %1 %2",array($judgeinfo->firstname,$judgeinfo->lastname))); - - echo "Complete for {$config['FAIRYEAR']}: ".(($judgeinfo->complete=="yes") ? "Yes" : "No"); - echo "
    "; - - echo "

    ".i18n("Personal Info")."

    "; - echo "\n"; - - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - - echo "\n"; - echo " \n"; - echo " \n"; - echo ""; - - echo "\n"; - echo " \n"; - echo " \n"; - echo ""; - - echo ""; - - echo "\n"; - echo " \n"; - echo "\n"; - - echo "\n"; - echo "\n"; - - echo "\n"; - echo " "; - echo " \n"; - echo "\n"; - - echo "\n"; - echo " "; - echo " \n"; - echo "\n"; - - echo "\n"; - echo " "; - echo " \n"; - echo "\n"; - - questions_print_answers('judgereg',$judgeinfo->id, $config['FAIRYEAR']); - - echo "
    ".i18n("First Name")."$judgeinfo->firstname".i18n("Last Name")."$judgeinfo->lastname
    ".i18n("Email Address")."$judgeinfo->email".i18n("City")."$judgeinfo->city
    ".i18n("Address 1")."$judgeinfo->address".i18n($config['provincestate'])."$judgeinfo->province"; - echo "
    ".i18n("Address 2")."$judgeinfo->address2".i18n("Phone (Home)")."$judgeinfo->phonehome
    ".i18n($config['postalzip'])."$judgeinfo->postalcode".i18n("Phone (Work)")."$judgeinfo->phonework ext $judgeinfo->phoneworkext
    ".i18n("Organization")."$judgeinfo->organization".i18n("Phone (Cell)")."$judgeinfo->phonecell

    ".i18n("Age category preference").""; - -$q=mysql_query("SELECT judges_catpref.*,projectcategories.category FROM judges_catpref,projectcategories WHERE judges_id='{$_GET['id']}' AND judges_catpref.year='".$config['FAIRYEAR']."' AND projectcategories.year='".$config['FAIRYEAR']."' AND judges_catpref.projectcategories_id=projectcategories.id"); -echo mysql_error(); -while($r=mysql_fetch_object($q)) - echo i18n($r->category).": ".$preferencechoices[$r->rank]."
    "; - - echo "
    ".i18n("Highest post-secondary degree")."$judgeinfo->highest_psd
    ".i18n("Other professional qualifications")."$judgeinfo->professional_quals
    ".i18n("Languages").""; - - $q=mysql_query("SELECT languages_lang FROM judges_languages WHERE judges_id='$judgeinfo->id'"); - while($r=mysql_fetch_object($q)) - { - echo $r->languages_lang; - echo "
    "; - } - - echo "
    "; - - - echo "
    "; - echo "
    "; - echo "

    Areas of Expertise

    "; - echo ""; - - //grab the list of divisions, because the last fields of the table will be the sub-divisions - $q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY id"); - $divs=array(); - while($r=mysql_fetch_object($q)) - { - $divs[]=$r->id; - $divnames[$r->id]=$r->division; - } - - $subdivq=mysql_query("SELECT judges_expertise.*, - projectsubdivisions.subdivision, - projectsubdivisions.projectdivisions_id AS parent_id - FROM judges_expertise - LEFT JOIN projectsubdivisions ON judges_expertise.projectsubdivisions_id=projectsubdivisions.id - WHERE judges_id='$judgeinfo->id' - AND judges_expertise.year='".$config['FAIRYEAR']."' - ORDER BY projectdivisions_id, projectsubdivisions_id"); - echo mysql_error(); - $judge_divs=array(); - $judge_subdivs=array(); - $divdata=array(); - - while($subdivr=mysql_fetch_object($subdivq)) - { - if($subdivr->projectdivisions_id) - { - $judge_divs[$subdivr->projectdivisions_id]=$subdivr->val; - } - else - $judge_subdivs[$subdivr->parent_id][]=$subdivr->subdivision; - } - - - foreach($divs as $div) - { - echo ""; - echo " "; - - echo ""; - echo ""; - } - - echo "
    ".i18n($divnames[$div])."".$judge_divs[$div]."/5"; - if(count($judge_subdivs[$div])) - { - $divdata=implode(", ",$judge_subdivs[$div]); - echo "$divdata"; - } - else - echo " "; - echo "
    "; - } - else - { - send_popup_header("Judge Information"); + send_popup_header("Judge Information"); + if($id < 1) { echo error(i18n("No Judge ID passed to Judges Info")); + send_popup_footer(); + exit; } + $judgeinfo = user_load($id); + + send_popup_header(i18n("Judge Information - %1 %2",array($judgeinfo['firstname'],$judgeinfo['lastname']))); + +echo "Complete for {$config['FAIRYEAR']}: ".(($judgeinfo['complete']=="yes") ? "Yes" : "No"); +echo "
    "; + +echo "

    ".i18n("Personal Info")."

    "; +echo "\n"; + +echo "\n"; +echo " \n"; +echo " \n"; +echo "\n"; +echo "\n"; +echo " \n"; +echo " \n"; +echo "\n"; +echo "\n"; +echo " \n"; +echo " \n"; +echo "\n"; +echo "\n"; +echo " \n"; +echo " \n"; +echo "\n"; + +echo "\n"; +echo " \n"; +echo " \n"; +echo ""; + +echo "\n"; +echo " \n"; +echo " \n"; +echo ""; + +echo ""; + +echo "
    ".i18n("First Name").": {$judgeinfo['firstname']}".i18n("Last Name").":{$judgeinfo['lastname']}
    ".i18n("Email Address").":{$judgeinfo['email']}".i18n("City").":{$judgeinfo['city']}
    ".i18n("Address 1").":{$judgeinfo['address']}".i18n($config['provincestate']).": {$judgeinfo['province']}
    ".i18n("Address 2").":{$judgeinfo['address2']}".i18n("Phone (Home)").":{$judgeinfo['phonehome']}
    ".i18n($config['postalzip']).":{$judgeinfo['postalcode']}".i18n("Phone (Work)").":{$judgeinfo['phonework']}
    ".i18n("Organization").":{$judgeinfo['organization']}".i18n("Phone (Cell)").":{$judgeinfo['phonecell']}

    "; +echo ""; + +echo "\n"; +echo " "; +echo ""; +echo " \n"; +echo "\n"; + +echo "\n"; +echo "\n"; + +echo "\n"; +echo " "; +echo " \n"; +echo "\n"; + +echo "\n"; +echo " "; +echo " \n"; +echo "\n"; + +//questions_print_answers('judgereg',$judgeinfo['id'], $config['FAIRYEAR']); + +echo "
    ".i18n("Time Availability").":"; +$q = mysql_query("SELECT * FROM judges_availability WHERE users_id=\"{$judgeinfo['id']}\" ORDER BY `start`"); +$sel = array(); +while($r=mysql_fetch_object($q)) { + $st = substr($r->start, 0, 5); + $end = substr($r->end, 0, 5); + echo "$st - $end
    "; +} +echo "
    ".i18n("Age category preference").":"; + +$q=mysql_query("SELECT * FROM projectcategories + WHERE year='{$config['FAIRYEAR']}'"); +echo mysql_error(); +while($r=mysql_fetch_object($q)) { + $p = intval($judgeinfo['cat_prefs'][$r->id]); + echo i18n($r->category).": {$preferencechoices[$p]}
    "; +} + +echo "
    ".i18n("Highest post-secondary degree").":{$judgeinfo['highest_psd']}
    ".i18n("Languages").":".join(', ', $judgeinfo['languages']). "
    "; +echo "
    "; + + +echo "
    "; +echo "
    "; +echo "

    Areas of Expertise

    "; +echo ""; + +//grab the list of divisions, because the last fields of the table will be the sub-divisions +$q=mysql_query("SELECT * FROM projectdivisions WHERE year='{$config['FAIRYEAR']}' ORDER BY id"); +$divs=array(); +while($r=mysql_fetch_object($q)) +{ + $divs[]=$r->id; + $divnames[$r->id]=$r->division; +} + +/* +$subdivq=mysql_query("SELECT judges_expertise.*, + projectsubdivisions.subdivision, + projectsubdivisions.projectdivisions_id AS parent_id + FROM judges_expertise + LEFT JOIN projectsubdivisions ON judges_expertise.projectsubdivisions_id=projectsubdivisions.id + WHERE judges_id='{$judgeinfo['id']}' + AND judges_expertise.year='".$config['FAIRYEAR']."' + ORDER BY projectdivisions_id, projectsubdivisions_id"); + echo mysql_error(); +$judge_divs=array(); +$judge_subdivs=array(); +$divdata=array(); +*/ +/* +while($subdivr=mysql_fetch_object($subdivq)) +{ + if($subdivr->projectdivisions_id) + { + $judge_divs[$subdivr->projectdivisions_id]=$subdivr->val; + } + else + $judge_subdivs[$subdivr->parent_id][]=$subdivr->subdivision; +} +*/ + +foreach($divs as $div) +{ + $p = $judgeinfo['div_prefs'][$div]; + echo ""; + echo " "; + + echo ""; + echo ""; +} +echo "\n"; +echo " "; +echo " \n"; +echo "\n"; + +echo "
    ".i18n($divnames[$div]).":$p/5"; + $subq=mysql_query("SELECT * FROM projectsubdivisions WHERE + projectdivisions_id='$div' AND year='{$config['FAIRYEAR']}' ORDER BY subdivision"); + $sd = array(); + while($subr=mysql_fetch_object($subq)) { + if($u['div_prefs_sub'][$subr->id] == 1) { + $sd[] = $subdivr->subdivision; + } + } + + /* Only show subdiv if main div >=3 */ + if($p >= 3) echo implode(", ",$sd); + else echo " "; + + echo "
    ".i18n("Other").":{$judgeinfo['expertise_other']}
    "; +echo "
    "; - send_popup_footer(); + +send_popup_footer(); ?> diff --git a/admin/judges_judges.php b/admin/judges_judges.php deleted file mode 100644 index 58e667e..0000000 --- a/admin/judges_judges.php +++ /dev/null @@ -1,132 +0,0 @@ - - Copyright (C) 2005 James Grant - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -?> - 'committee_main.php', - 'Administration' => 'admin/index.php', - 'Judges' => 'admin/judges.php') - ); -?> - - -".i18n("Active Judges list for %1",array($config['FAIRYEAR'])).""; - echo ""; - $querystr="SELECT - judges.id, - judges.firstname, - judges.lastname, - judges.email, - judges.complete, - judges_years.year - FROM - judges - JOIN judges_years ON judges.id=judges_years.judges_id - WHERE - judges_years.year='".$config['FAIRYEAR']."' - AND judges.deleted='no' - ORDER BY - lastname, - firstname"; - $q=mysql_query($querystr); - $num=mysql_num_rows($q); - echo i18n("Listing %1 judges total. See the bottom for breakdown of judges by complete status",array($num),array("the number of judges")); - - echo mysql_error(); - echo ""; - echo " "; - echo " "; - echo " "; - echo " "; - echo ""; - $completeyes=0; - $completeno=0; - while($r=mysql_fetch_object($q)) - { - echo ""; - echo ""; - - if($r->complete=="yes" && $r->year) - { - echo ""; - $completeyes++; - } - else - { - echo ""; - $cl="error"; - $completeno++; - } - echo ""; - echo ""; - } - - echo "
    ".i18n("Judge Name")."".i18n("Email Address")."".i18n("Complete")."".i18n("Actions")."
    "; - echo "id)\">$r->firstname $r->lastname"; - echo "$r->email".i18n("yes")."".i18n("no").""; - echo "id\">"; - echo "
    "; - echo i18n("Note: Deleting judges from this list only deactivates the judge for this year's fair. To completely delete a judge, use the 'Manage Judges' page"); - echo "
    "; - echo "
    "; - echo i18n("There are %1 total active judges.",array($num),array("the number of judges")); - echo "
    "; - echo i18n("There are %1 complete judges.",array($completeyes),array("the number of judges")); - echo "
    "; - echo i18n("There are %1 incomplete judges.",array($completeno),array("the number of judges")); - echo "
    "; - echo "
    "; - echo "
    "; - - send_footer(); -?> diff --git a/admin/judges_manager.php b/admin/judges_manager.php deleted file mode 100644 index 233fcd2..0000000 --- a/admin/judges_manager.php +++ /dev/null @@ -1,100 +0,0 @@ - - Copyright (C) 2005 James Grant - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -?> - 'committee_main.php', - 'Administration' => 'admin/index.php', - 'Judges' => 'admin/judges.php') ); - -?> - - -"); - if(isset($_GET['show_what'])) { - $_SESSION['judgesmanager_show_what']=$_GET['show_what']; - } - if($_SESSION['judgesmanager_show_what']) { - $show_what = $_SESSION['judgesmanager_show_what']; - } else { - $show_what = "cy_complete"; - } - print("
    "); - print(""); - print(""); - print("
    "); - -// echo i18n("Note: Deleting a judge from this screen only unlinks them from the current fairyear"); - - $editor = new TableEditor('judge'); - -// $editor->setDebug(true); - - switch($show_what) { - case "all": - $editor->setOption('judges_show_what', 'all'); - break; - case "cy_active": - $editor->setOption('judges_show_what', 'current_year_active'); - break; - case "cy_complete": - $editor->setOption('judges_show_what', 'current_year_complete'); - break; - } - - $editor->execute(); - - - send_footer(); -?> diff --git a/admin/judges_sa.php b/admin/judges_sa.php index 748d6e9..d6f148d 100644 --- a/admin/judges_sa.php +++ b/admin/judges_sa.php @@ -22,52 +22,18 @@ */ ?> "; -echo "
    "; -echo i18n("When complete, a green bar will appear at the BOTTOM of this page -saying that everything has completed successfully. When complete, you can use -the following links to manage the Judging Teams and the Judges assigned to them -(clicking on these links now will stop the scheduler)."); -echo "
    "; -echo "
    "; -echo "".i18n("Manage Judge Teams").""; -echo "
    "; -echo "".i18n("Manage Judge Members").""; -echo "
    "; -echo "
    "; -echo i18n("If you get an error like: \"Fatal error: Maximum execution time of -30 seconds exceeded...\" you will need to talk to your system admin and have -them adjust the \"max_execution_time\" variable in the \"php.ini\" file from -30(seconds) to something larger, like 900 (15 minutes). And then have them -restart the webserver for the change to take effect"); -echo "
    "; -echo "
    "; - -*/ - - //function TRACE() { } //function TRACE_R() { } function TRACE($str) { print($str); } @@ -131,10 +97,12 @@ function judges_cost_function($annealer, $bucket_id, $ids) // TRACE_R($ids); $cost = 0; - $have_chair = 0; + $have_chair = false; + $have_div2 = false; if($bucket_id == 0) { - /* This is the placeholder */ + /* This is the placeholder for all judges, there's a slight + * cost for not using a judge */ $cost = count($ids) * 5; // TRACE("Extra judge team cost=$cost\n"); return $cost; @@ -180,7 +148,7 @@ function judges_cost_function($annealer, $bucket_id, $ids) $cost += 2 * $dpref; /* See if the judge is willing to chair a team */ - if($j['willing_chair'] == 'yes') $have_chair = 1; + if($j['willing_chair'] == 'yes') $have_chair = true; /* For each lang the team needs that the judge doesn't have, * increase the cost */ @@ -188,10 +156,18 @@ function judges_cost_function($annealer, $bucket_id, $ids) $l = $t['langs'][$y]; if(!in_array($l, $j['languages'])) $cost += 25; } + + /* If divisional round2 is enabled, make sure there is a judge + * on the team for round2 */ + if($j['available_for_divisional2'] == true) $have_div2 = true; } /* Huge penalty for a team without a willing chair, but only if the min judges per team >1 */ if(!$have_chair && $config['min_judges_per_team']>1) $cost += 40; + + /* Huge penalty for not having a round2 person on the team */ + if($have_div2 == false) + $cost += 40; // TRACE("Team $bucket_id, cost is $cost\n"); @@ -238,6 +214,96 @@ function jdiv_compute_cost($annealer, $bucket_id, $ids) return $cost; } +/* Returns true if a judge time preference indicates they are available for the + * specified round. Always returns true if judge time availablility selection + * is off */ +function judge_available_for_round($j, $r) +{ + global $config; + if($config['judges_availability_enable'] == 'no') return true; + + foreach($j['availability'] as $a) { + if($a['start'] <= $r['starttime'] + && $a['end'] >= $r['endtime'] + && $a['date'] == $r['date'] ) { + return true; + } + } + return false; +} + +function judge_mark_for_round($j, $r) +{ + /* The judge has been assigned to round $r, modify their available to + * exclude any time that falls within this time + * TODO: modify the DB to store date/times in timestamps, so we don't + * have to deal with dates separately. */ + global $config; + global $judges; + if($config['judges_availability_enable'] == 'no') return true; + + /* Grab a pointer to the real judge, because we want to + * modify it, not a copy of it */ + $ju =& $judges[$j['id']]; + + foreach($ju['availability'] as $key=>&$a) { + if($r['starttime'] >= $a['start'] && $r['starttime'] <= $a['end']) { + /* Round starts in the middle of this availablity slot + * modify this availabilty so it doesn't overlap */ + /* This may cause $a['start'] == $a['end'], that's ok */ + $a['end'] = $r['starttime']; +// TRACE("adjust starttime\n"); + } + + if($r['endtime'] >= $a['start'] && $r['endtime'] <= $a['end']) { + /* Round ends in the middle of this availablity slot + * modify this availabilty so it doesn't overlap */ + /* This may cause $a['start'] == $a['end'], that's ok */ + $a['start'] = $r['endtime']; +// TRACE("adjust endtime\n"); + } + + if($a['start'] >= $a['end']) { + /* Delete the whole round */ + unset($ju['availability'][$key]); + } + } + +// print_r($ju['availability']); + +} + +/* UNUSED: should be moved to the timeslot manager to ensure rounds + * don't overlap. */ +function rounds_overlap($r1, $r2) { + $s1 = strtotime("{$r1['date']} {$r1['starttime']}"); + $e1 = strtotime("{$r1['date']} {$r1['endtime']}"); + $s2 = strtotime("{$r1['date']} {$r2['starttime']}"); + $e2 = strtotime("{$r1['date']} {$r2['endtime']}"); + + if($s1 <= $s2 && $e1 > $s1) return true; + if($s1 > $s2 && $s1 < $e2) return true; + return false; +} + +/* Print a judge */ +function pr_judge(&$jt, $jid) +{ + global $judges; + $j =& $judges[$jid]; + print(" - {$j['name']} (".join(' ', $j['languages']).')'); + print("("); + foreach($jt['cats'] as $c) + print("c{$c}={$j['cat_prefs'][$c]} "); + foreach($jt['divs'] as $d) + print("d{$d}={$j['div_prefs'][$d]} "); + + print(")"); + if($j['willing_chair'] == 'yes') print(" (chair) "); + + print("\n"); +} + set_status("Loading Data From Database..."); TRACE("\n\n"); @@ -267,6 +333,27 @@ while($r=mysql_fetch_object($q)) { TRACE(" {$r->lang} - {$r->langname}\n"); } +TRACE("Loading Judging Round time data...\n"); +$round_divisional1 = NULL; +$round_divisional2 = NULL; +$round_special_awards = array(); +$round = array(); +$q = mysql_query("SELECT * FROM judges_timeslots WHERE round_id='0' AND `year`='{$config['FAIRYEAR']}'"); +/* Loads judges_timeslots.id, .starttime, .endtime, .date, .name */ +while($r = mysql_fetch_assoc($q)) { + TRACE(" id:{$r['id']} type:{$r['type']} name:{$r['name']}\n"); + $round[] = $r; + + if($r['type'] == 'divisional1') $round_divisional1 = $r; + if($r['type'] == 'divisional2') $round_divisional2 = $r; + if($r['type'] == 'special') $round_special_awards[] = $r; +} + +if($round_divisional1 == NULL) { + echo "No divisional1 round defined! Aborting!\n"; + exit; +} + $jdiv = array(); TRACE("Loading Judging Division Configuration and Projects...\n"); $q=mysql_query("SELECT * FROM judges_jdiv"); @@ -280,8 +367,7 @@ while($r=mysql_fetch_object($q)) { } $keys = array_keys($jdiv); -for($k=0; $k $d['div'], 'cat' => $d['cat'], 'lang' => $d['lang']); + $jdiv[$jdiv_id]['award_ids'] = array(); $count++; } TRACE(" ($count projects)\n"); @@ -312,13 +399,188 @@ for($k=0; $kid; + print(" $id"); + /* Clean out the judges_teams_link */ + mysql_query("DELETE FROM judges_teams_link WHERE judges_teams_id='$id' AND year={$config['FAIRYEAR']}"); + print mysql_error(); + /* Awards */ + mysql_query("DELETE FROM judges_teams_awards_link WHERE judges_teams_id='$id' AND year={$config['FAIRYEAR']}"); + print mysql_error(); + /* Timeslots */ + mysql_query("DELETE FROM judges_teams_timeslots_link WHERE judges_teams_id='$id' AND year={$config['FAIRYEAR']}"); + print mysql_error(); + /* Timeslots projects */ + mysql_query("DELETE FROM judges_teams_timeslots_projects_link WHERE judges_teams_id='$id' AND year={$config['FAIRYEAR']}"); + print mysql_error(); +} +echo "\n"; + +/* Finally, delete all the autocreated judges teams */ +mysql_query("DELETE FROM judges_teams WHERE autocreate_type_id=1 AND year={$config['FAIRYEAR']}"); +print mysql_error(); + +/* Also delete any judges_teams_link that link to teams that dont exist, just + * in case */ +$q=mysql_query("SELECT judges_teams_link.id, judges_teams.id AS judges_teams_id + FROM judges_teams_link + LEFT JOIN judges_teams ON judges_teams_link.judges_teams_id=judges_teams.id + WHERE judges_teams_link.year={$config['FAIRYEAR']}"); +$n=0; +while($r=mysql_fetch_object($q)) { + if(!$r->judges_teams_id) { + mysql_query("DELETE FROM judges_teams_link WHERE id='$r->id'"); + $n++; + } +} +print("Deleted $n orphaned team linkings\n"); +TRACE(" Done.\n"); + + +set_status("Loading Judges"); + +$judges = judges_load_all(); + +foreach($judges as &$j) { + if($j['judge_active'] == 'no') { + TRACE(" {$j['name']} has their judge profile deactivated, skipping.\n"); + unset($judges[$j['id']]); + continue; + } + if($j['judge_complete'] == 'no') { + TRACE(" {$j['name']} hasn't completed their judge profile, skipping.\n"); + unset($judges[$j['id']]); + continue; + } + + $q = mysql_query("SELECT users_id FROM judges_teams_link WHERE + users_id='{$j['id']}' + AND year='{$config['FAIRYEAR']}'"); + if(mysql_num_rows($q) != 0) { + TRACE(" {$j['name']} is already on a judging team, skipping.\n"); + unset($judges[$j['id']]); + continue; + } + + /* Load the judge time availability */ + $q = mysql_query("SELECT * FROM judges_availability WHERE users_id='{$j['id']}' ORDER BY `start`"); + if(mysql_num_rows($q) == 0) { + TRACE(" {$j['name']} hasn't selected any time availability, POTENTIAL BUG (they shouldn't be marked as complete).\n"); + TRACE(" Ignoring this judge.\n"); + unset($judges[$j['id']]); + continue; + } + while($r = mysql_fetch_assoc($q)) { + $j['availability'][] = $r; + } + + /* Load special award preferences */ + $q = mysql_query("SELECT award_awards.id,award_awards.name FROM + judges_specialaward_sel,award_awards + WHERE + award_awards.id=judges_specialaward_sel.award_awards_id + AND judges_specialaward_sel.users_id='{$j['id']}' + AND award_awards.year='{$config['FAIRYEAR']}'"); + echo mysql_error(); + + if($j['special_award_only'] == 'yes') { + TRACE(" {$j['name']} is a special awards only.\n"); + /* Find their special award id */ + if(mysql_num_rows($q) == 0) { + TRACE(" NO special award selected! (removing special award only request)\n"); + $j['special_award_only'] = 'no'; +// } else if(mysql_num_rows($q) > 1) { +// TRACE(" More than ONE special award selected (removing special award only request):\n"); +// $j['special_award_only'] = 'no'; + } + } + + $j['special_awards'] = array(); + while($r = mysql_fetch_object($q)) { + if($j['special_award_only'] == 'yes') { + TRACE(" {$r->name}\n"); + } + /* Add them to the SA judge list (modify the actual list, not + * $j, which is a copy */ + $j['special_awards'][] = $r->id; + } + + /* optimization, so the div1 cost function can try to find one + * round2 judge per team */ + $j['available_for_divisional2'] == judge_available_for_round($j, $round_divisional2); +} + + +TRACE("Loaded ".count($judges)." judges\n"); +$jteam[0]['max_judges'] = count($judges); + + +/* Load the numbers for any user-defined judge teams that already exist, + * these numbers will be off-limits for auto-assigning numbers */ +$q = mysql_query("SELECT * FROM judges_teams WHERE year={$config['FAIRYEAR']}"); +$used_judges_teams_numbers = array(); +while($i = mysql_fetch_assoc($q)) { + $used_judges_teams_numbers[] = $i['num']; +} +echo "The following judge team numbers are already used: \n"; +print_r($used_judges_teams_numbers); + +$next_judges_teams_number_try = 1; +/* A function to get the next available number */ +function next_judges_teams_number() +{ + global $used_judges_teams_numbers; + global $next_judges_teams_number_try; + + while(1) { + if(!in_array($next_judges_teams_number_try, $used_judges_teams_numbers)) break; + + $next_judges_teams_number_try++; + } + $r = $next_judges_teams_number_try; + $next_judges_teams_number_try++; + return $r; +} + +function judge_team_create($num, $name) +{ + global $config; + $name = mysql_escape_string($name); + mysql_query("INSERT INTO judges_teams (num,name,autocreate_type_id,year) + VALUES ('$num','$name','1','{$config['FAIRYEAR']}')"); + $id = mysql_insert_id(); + return $id; +} + +function judge_team_add_judge($team_id, $users_id) +{ + global $config, $judges; + mysql_query("INSERT INTO judges_teams_link + (users_id,judges_teams_id,captain,year) + VALUES ('$users_id','$team_id','{$judges[$users_id]['willing_chair']}', + '{$config['FAIRYEAR']}')"); +} + +/**************************************************************************** + * Round 1 Divisional Scheduling + * - Compute required divisional judge teams + * - Delete existing ones + * - Anneal Projects to Teams + * - Anneal Judtes to Projects + * + ***************************************************************************/ + set_status("Computing required judging teams"); TRACE(" Each judging team may judge {$config['max_projects_per_team']} projects\n"); TRACE(" Each project must be judged {$config['times_judged']} times\n"); $keys = array_keys($jdiv); -for($k=0; $kbucket[$x]; $jteam[$jteam_id]['sub'] = $x; $jteam[$jteam_id]['jdiv_id'] = $jdiv_id; @@ -370,8 +633,7 @@ for($k=0; $kid; - print(" $id"); - /* Clean out the judges_teams_link */ - mysql_query("DELETE FROM judges_teams_link WHERE judges_teams_id='$id' AND year={$config['FAIRYEAR']}"); - print mysql_error(); - /* Awards */ - mysql_query("DELETE FROM judges_teams_awards_link WHERE judges_teams_id='$id' AND year={$config['FAIRYEAR']}"); - print mysql_error(); - /* Timeslots */ - mysql_query("DELETE FROM judges_teams_timeslots_link WHERE judges_teams_id='$id' AND year={$config['FAIRYEAR']}"); - print mysql_error(); - /* Timeslots projects */ - mysql_query("DELETE FROM judges_teams_timeslots_projects_link WHERE judges_teams_id='$id' AND year={$config['FAIRYEAR']}"); - print mysql_error(); + /* If we get here, the judge is ok for div1 */ + $div1_judge_ids[] = $j['id']; } -/* Finally, delete all the autocreated judges teams */ -mysql_query("DELETE FROM judges_teams WHERE autocreate_type_id=1 AND year={$config['FAIRYEAR']}"); -print mysql_error(); - -/* Also delete any judges_teams_link that link to teams that dont exist */ -$q=mysql_query("SELECT judges_teams_link.id, judges_teams.id AS judges_teams_id FROM judges_teams_link LEFT JOIN judges_teams ON judges_teams_link.judges_teams_id=judges_teams.id WHERE judges_teams_link.year={$config['FAIRYEAR']}"); -$n=0; -while($r=mysql_fetch_object($q)) { - if(!$r->judges_teams_id) { - mysql_query("DELETE FROM judges_teams_link WHERE id='$r->id'"); - $n++; - } -} -print("Deleted $n orphaned team linkings\n"); -TRACE(" Done.\n"); - -set_status("Loading Judges"); - -$q=mysql_query("SELECT judges.* FROM judges,judges_years WHERE ". - "complete='yes' AND deleted='no' ". - " AND judges_years.year='{$config['FAIRYEAR']}' ". - " AND judges_years.judges_id=judges.id" - ); - -$judges=array(); -$sa_judges = array(); - -while($r=mysql_fetch_object($q)) -{ - unset($divprefs); - unset($catprefs); - unset($langprefs); - - /* Try to fetch a team link ID for this judge, if we can, we don't want to use this judge - * in the divisional awards, they are already assigned to soemthing */ - $q2 = mysql_query("SELECT judges_id FROM judges_teams_link WHERE ". - "judges_id='$r->id' ". - " AND year='".$config['FAIRYEAR']."'"); - if(mysql_num_rows($q2) != 0) { - TRACE(" {$r->firstname} {$r->lastname} is already on a judging team, skipping.\n"); - continue; - } - - //get category preferences - $q2=mysql_query("SELECT * FROM judges_catpref WHERE judges_id='$r->id' AND year='".$config['FAIRYEAR']."' ORDER BY projectcategories_id"); - $catprefs=array(); - while($r2=mysql_fetch_object($q2)) - $catprefs[$r2->projectcategories_id]=$r2->rank; - - //get division preferences - $q2=mysql_query("SELECT * FROM judges_expertise WHERE judges_id='$r->id' AND year='".$config['FAIRYEAR']."' AND projectsubdivisions_id IS NULL ORDER BY projectdivisions_id"); - //the areas of expertise are ranked from 1 to 5, and we need them as -2,-1,0,1,2 so we simply subtract 3 - $divprefs=array(); - while($r2=mysql_fetch_object($q2)) - $divprefs[$r2->projectdivisions_id]=$r2->val-3; - - $langprefs = array(); - $q3=mysql_query("SELECT * from judges_languages WHERE judges_id='$r->id'"); - while($r3=mysql_fetch_object($q3)) - $langprefs[]=$r3->languages_lang; - - $q2 = mysql_query("SELECT answer FROM question_answers WHERE ". - " registrations_id='{$r->id}' AND ". - " questions_id='$willing_chair_question_id' AND ". - " year='{$config['FAIRYEAR']}' "); - mysql_error(); - $willing_chair = 'no'; - if(mysql_num_rows($q2) == 1) { - $r2 = mysql_fetch_object($q2); - if($r2->answer == 'yes') $willing_chair = 'yes'; - } - - $sa_only = 'no'; - if($r->typepref == 'speconly') $sa_only = 'yes'; - $sa_sel = array(); - - - if($sa_only == 'yes') { - TRACE("Judge [{$r->firstname} {$r->lastname}] is a special awards only.\n"); - /* Find their special award id */ - $qq = mysql_query("SELECT award_awards.id,award_awards.name FROM - judges_specialaward_sel,award_awards - WHERE - award_awards.id=judges_specialaward_sel.award_awards_id - AND judges_specialaward_sel.judges_id='{$r->id}' - AND judges_specialaward_sel.year='{$config['FAIRYEAR']}' - AND award_awards.year='{$config['FAIRYEAR']}'"); - echo mysql_error(); - if(mysql_num_rows($qq) == 0) { - TRACE(" - NO special award selected! (removing special award only request)\n"); - $sa_only = 'no'; - } else if(mysql_num_rows($qq) > 1) { - TRACE(" - More than ONE special award selected (removing special award only request):\n"); - $sa_only = 'no'; - } - while($rr = mysql_fetch_object($qq)) { - TRACE(" ".$rr->name."\n"); - $sa_sel[] = $rr->id; - } - } - - $j=array( - "judges_id"=>"$r->id", - "name"=>"$r->firstname $r->lastname", - "years_school"=>$r->years_school, - "years_regional"=>$r->years_regional, - "years_national"=>$r->years_national, - "willing_chair"=>$willing_chair, - "divprefs"=>$divprefs, - "catprefs"=>$catprefs, - "languages"=>$langprefs, - "sa_only"=>$sa_only, - "sa_sel"=>$sa_sel, - ); - - /* If it's a special award only judge, keep them - * out of the judges list for the divisional annealer */ - if($sa_only == 'yes') { - $sa_judges[$r->id] = $j; - } else { - $judges[$r->id] = $j; - } - - -} -TRACE("Loaded ".count($judges)." judges.\n"); -$jteam[0]['max_judges'] = count($judges); +TRACE(count($div1_judge_ids)." judges available for round1 divisional\n"); function judges_to_teams_update($progress, $total) { @@ -548,52 +671,16 @@ function judges_to_teams_update($progress, $total) } set_status("Assigning Judges to Teams"); -$judge_ids = array_keys($judges); $e = $config['effort']; -$a = new annealer(count($jteam), 25, $e, 0.98, judges_cost_function, $judge_ids); +$a = new annealer(count($jteam), 25, $e, 0.98, judges_cost_function, $div1_judge_ids); $a->set_update_callback(judges_to_teams_update); $a->anneal(); -function pr_judge(&$jt, $jid) -{ - global $judges; - $j =& $judges[$jid]; - print(" - {$j['name']} ("); - for($x=0; $xmax; - -TRACE("Max Judging Team Number is currently $max_jteam_num\n"); - for($x=1;$xbucket_cost[$x]} "); + print("Judging Team {$t['num']}: cost={$a->bucket_cost[$x]} "); $lang_array = $t['langs']; asort($lang_array); $langstr = implode(' ', $lang_array); @@ -605,47 +692,49 @@ for($x=1;$xbucket[$x]; for($y=0; $yid','$team_id','{$config['FAIRYEAR']}')"); + /* Add the award ID to the jdiv, if it's not already there */ + if(!in_array($r->id, $jdiv[$t['jdiv_id']]['award_ids'])) { + $jdiv[$t['jdiv_id']]['award_ids'][] = $r->id; + } } } @@ -680,16 +773,86 @@ print("Unused Judges:\n"); $ids = $a->bucket[0]; for($y=0; $y$jd) { + + $num = next_judges_teams_number(); + $team_id = judge_team_create($num, 'Round 2 Divisional '.$jdiv_id); + + TRACE("Created Round2 team id $team_id\n"); + + /* Find all the jteams in this jdiv */ + for($x=1;$xpick_move(); - - /* See if $b1,$i1 is movable */ - $id1 = $a->bucket[$b1][$i1]; - $j1 =& $sa_judges[$id1]; -// print("J1:"); -// print_r($j1); - if($j1['sa_only'] == 'yes') continue; - - if($i2 != -1) { - $id2 = $a->bucket[$b2][$i2]; - $j2 =& $sa_judges[$id2]; -// print("J2:"); -// print_r($j2); - if($j2['sa_only'] == 'yes') continue; - } - - return array($b1, $i1, $b2, $i2); - } -} - if($config['scheduler_enable_sa_scheduling'] == 'yes') { + TRACE("Finding judges for special award round(s)\n"); + foreach($round_special_awards as &$r) { + $r['available_judge_ids'] = array(); + } + + $total_judges = 0; + foreach($judges as &$j) { + foreach($round_special_awards as &$r) { + if(judge_available_for_round($j, $r) == true) { + if($j['special_award_only'] == 'yes') { + for($i=0;$iname}"; - /* Write this team to the DB */ - mysql_query("INSERT INTO judges_teams (num,name,autocreate_type_id,year) - VALUES ('$max_jteam_num','".mysql_escape_string($tn)."','1','{$config['FAIRYEAR']}')"); - $sa_jteam[$x]['id'] = mysql_insert_id(); - - /* Link the award to this team */ + $required_judges += $min; + + /* Link the award to this team */ mysql_query("INSERT INTO judges_teams_awards_link (award_awards_id,judges_teams_id,year) VALUES ('{$i->id}','{$sa_jteam[$x]['id']}','{$config['FAIRYEAR']}')"); - TRACE("Created Team: $tn {$sa_jteam[$x]['id']}\n"); - $jteam_id++; + TRACE("Created Team: {$i->name}, $min judges needed (db id:{$sa_jteam[$x]['id']}) \n"); $x++; } + TRACE("Total Judges: $total_judges, Required: $required_judges\n"); /* ====================================================================*/ - set_status("Assigning Judges to Special Award Teams\n"); + set_status("Assigning Special Award Teams to Special Award Round(s)\n"); + /* Compute how many judges each round needs based on the total number + * of needed judges, e.g. if SAround1 has 10 judges available and SAround2 + * has 20 judges available, and we total need 90 judges, then we + * want to assign jteams so that SAround1 has 30 slots, and SAround2 has + * 60 to balance the deficit */ + foreach($round_special_awards as &$r) { + $x = count($r['available_judge_ids']); + $target = ($x * $required_judges) / $total_judges; + $r['target_judges'] = $target; + TRACE("Round {$r['name']} should be assigned $target judge timeslots\n"); - $judge_ids = array_keys($sa_judges); - $e = $config['effort']; - $a = new annealer(count($sa_jteam), 25, $e, 0.98, judges_sa_cost_function, $judge_ids); - //$a->set_update_callback(judges_to_teams_update); - //$a->set_pick_move(judges_sa_pick_move); - $a->anneal(); + /* Setup for the next step, always add special award + * judge team 0 to ALL rounds */ + $r['jteam_ids'] = array(0); + $r['assigned_judges'] = 0; + } + unset($r); - $x=0; - unset($t); - unset($tid); - foreach($sa_jteam as $tid => $t) { - if($tid == 0) { + /* ====================================================================*/ + /* Scan the list of special awards, check each special award to see if + * it has special award only judges, we want those special awards pre-assigned + * to rounds where ALL SA-only judges are available, or, as best we can. */ + foreach($sa_jteam as $x=>&$jt) { + if($x == 0) continue; + + $sa_judges = array(); + foreach($round_special_awards as $i=>$r) { + $sa_round_count[$i] = 0; + } + + foreach($jt['award_ids'] as $aid) { + foreach($judges as $jid=>$j) { + if($j['special_award_only'] == 'no') continue; + if(in_array($aid, $j['special_awards'])) { + $sa_judges[] = $jid; + foreach($round_special_awards as $i=>$r) { +// TRACE("Checking {$j['name']} in round {$r['name']}\n"); + if(judge_available_for_round($j, $r)) { +// TRACE(" yes, round $i ++\n"); + $sa_round_count[$i]++; + + } + } + } + } + + } + + /* If there are no SA-only judges, skip the pre-assignment */ + if(count($sa_judges) == 0) continue; + + /* There are count($sa_judges), find the round + * with the highest count */ + $highest_count = 0; + $highest_offset = -1; + foreach($round_special_awards as $i=>$r) { + if($sa_round_count[$i] > $highest_count || $highest_offset == -1) { + $highest_count = $sa_round_count[$i]; + $highest_offset = $i; + } + } + /* Assign this jteam to that round */ + $round_special_awards[$highest_offset]['jteam_ids'][] = $x; + $round_special_awards[$highest_offset]['assigned_judges'] += $jt['min_judges']; + TRACE("Pre-assigning Team {$jt['name']} to Round {$round_special_awards[$highest_offset]['name']}\n"); + $jt['assigned'] = true; + } + unset($jt); + + /* Use a greedy algorithm to assign the remaining jteams. First sort + * the teams by the number of judges needed so those can be assigned + * first */ + function sa_cmp($a, $b) { + return $b['min_judges'] - $a['min_judges']; + } + uasort($sa_jteam, 'sa_cmp'); + + foreach($sa_jteam as $x=>$jt) { + if($x == 0) continue; + if($jt['assigned'] == true) continue; + + $highest = 0; + $highest_offset = -1; + /* Find the round with the highest missing judges, this works + * even if the $p computation is negative */ + foreach($round_special_awards as $o=>$r) { + $p = $r['target_judges'] - $r['assigned_judges']; +// TRACE(" Round {$r['name']} p=$p\n"); + if($highest_offset == -1 || $p > $highest) { + $highest = $p; + $highest_offset = $o; + } + } + /* Assign this jteam id to the special award round */ + $round_special_awards[$highest_offset]['jteam_ids'][] = $x; + $round_special_awards[$highest_offset]['assigned_judges'] += $jt['min_judges']; + } + + /* Now, anneal in each special award round */ + foreach($round_special_awards as $r) { + set_status("Assigning Judges in round {$r['name']}\n"); + + $current_jteam_ids = $r['jteam_ids']; + $judge_ids = $r['available_judge_ids']; + $e = $config['effort']; + $a = new annealer(count($r['jteam_ids']), 25, $e, 0.98, + judges_sa_cost_function, $judge_ids); + //$a->set_update_callback(judges_to_teams_update); + //$a->set_pick_move(judges_sa_pick_move); + $a->anneal(); + + $x=0; + + unset($t); + unset($tid); + foreach($r['jteam_ids'] as $tid) { + if($tid == 0) { + $x++; + continue; + } + + $t = &$sa_jteam[$tid]; + + print("Judging Team {$t['id']} \"{$t['name']}\": cost={$a->bucket_cost[$x]} #=({$t['min_judges']},{$t['max_judges']}) "); + + // print("langs=("); + /* $langstr=""; + for($y=0; $ybucket[$x]; + foreach($a->bucket[$x] as $jid) { + // pr_judge($t, $ids[$y]); + + $j = &$judges[$jid]; + print(" - {$j['name']}\n"); + + /* Link Judges to the judging team we just inserted */ + judge_team_add_judge($t['id'], $jid); + } $x++; - continue; } - - print("Judging Team {$t['id']}: cost={$a->bucket_cost[$x]} #=({$t['min_judges']},{$t['max_judges']}) "); - - // print("langs=("); - /* $langstr=""; - for($y=0; $ybucket[$x]; - for($y=0; $y$r->id, - "date"=>$r->date, - "starttime"=>substr($r->starttime,0,-3), - "endtime"=>substr($r->endtime,0,-3)); + "date"=>$r->date, + "starttime"=>substr($r->starttime,0,-3), + "endtime"=>substr($r->endtime,0,-3)); print(" ".$available_timeslots[$x]['starttime']." -> ". $available_timeslots[$x]['endtime']."\n"); $x++; @@ -1032,13 +1313,19 @@ for($k=0; $k<$keys_count; $k++) { $a->set_pick_move(timeslot_pick_move); $a->anneal(); + printf(" "); + for($y=0;$y<$n_timeslots; $y++) { + printf("%4d ", $y+1); + } + printf("\n"); + for($x=0; $xbucket[$y][$x]; - TRACE(($y+1).":$jteam_id "); + printf("%4d ", $jteam[$jteam_id]['id']); if($jteam_id == 0) continue; @@ -1056,7 +1343,7 @@ for($k=0; $k<$keys_count; $k++) { " '$pid', '{$config['FAIRYEAR']}')"); } - TRACE("\n"); + printf("\n"); } } diff --git a/admin/judges_schedulerconfig_check.inc.php b/admin/judges_schedulerconfig_check.inc.php index c0df833..fca7529 100644 --- a/admin/judges_schedulerconfig_check.inc.php +++ b/admin/judges_schedulerconfig_check.inc.php @@ -6,7 +6,7 @@ function judges_scheduler_check_timeslots() $q=mysql_query("SELECT * FROM judges_timeslots WHERE ". " year='".$config['FAIRYEAR']."'". - " AND allowdivisional='yes'" ); + " AND `type`='divisional1'" ); $rows = mysql_num_rows($q); return $rows; @@ -172,9 +172,12 @@ function judges_scheduler_check_judges() echo "
    "; echo "
    "; - $jq=mysql_query("SELECT COUNT(judges.id) AS num FROM judges,judges_years WHERE complete='yes' AND deleted='no' AND judges_years.year='{$config['FAIRYEAR']}' AND judges_years.judges_id=judges.id"); +/* $jq=mysql_query("SELECT COUNT(judges.id) AS num FROM judges,judges_years WHERE complete='yes' AND deleted='no' AND judges_years.year='{$config['FAIRYEAR']}' AND judges_years.judges_id=judges.id"); $jr=mysql_fetch_object($jq); - $currentjudges=$jr->num; + $currentjudges=$jr->num;*/ + /* FIXME: this his highly inefficient :), but won't be done very often */ + $judges = judges_load_all(); + $currentjudges = count($judges); echo "Current number of registered judges: $currentjudges"; echo ""; echo "
    "; diff --git a/admin/judges_teams.php b/admin/judges_teams.php index ab6ba27..a9bbac8 100644 --- a/admin/judges_teams.php +++ b/admin/judges_teams.php @@ -27,23 +27,6 @@ user_auth_required('committee', 'admin'); include "judges.inc.php"; - send_header("Manage Judging Teams", - array('Committee Main' => 'committee_main.php', - 'Administration' => 'admin/index.php', - 'Judges' => 'admin/judges.php') - ); -?> - - -num) { $addaward=false; - echo error(i18n("Sorry, only one Special Award can be assigned to a judging team")); + message_push(error(i18n("Sorry, only one Special Award can be assigned to a judging team"))); } else { @@ -166,7 +149,7 @@ function addclicked() { //link up the award mysql_query("INSERT INTO judges_teams_awards_link (award_awards_id,judges_teams_id,year) VALUES ('".$_POST['award']."','$edit','".$config['FAIRYEAR']."')"); - echo happy(i18n("Award assigned to team")); + message_push(happy(i18n("Award assigned to team"))); } } @@ -179,7 +162,7 @@ function addclicked() $action="edit"; else { - echo happy(i18n("Team successfully saved")); + message_push(happy(i18n("Team successfully saved"))); unset($action); unset($edit); } @@ -189,7 +172,7 @@ function addclicked() if($action=="unassign") { mysql_query("DELETE FROM judges_teams_awards_link WHERE judges_teams_id='$edit' AND award_awards_id='".$_GET['unassign']."' AND year='".$config['FAIRYEAR']."'"); - echo happy(i18n("Award unassigned from judge team")); + message_push(happy(i18n("Award unassigned from judge team"))); //keep editing the same team $action="edit"; } @@ -201,7 +184,7 @@ function addclicked() $r=mysql_fetch_object($q); if($r->c) { - echo error(i18n("Cannot 'Create All' teams when any divisional teams currently exist. Try deleting all existing non-divisional teams first.")); + message_push(error(i18n("Cannot 'Create All' teams when any divisional teams currently exist. Try deleting all existing non-divisional teams first."))); } else { @@ -232,7 +215,7 @@ function addclicked() $team_id=mysql_insert_id(); //now link the new team to the award mysql_query("INSERT INTO judges_teams_awards_link (award_awards_id,judges_teams_id,year) VALUES ('$r->id','$team_id','".$config['FAIRYEAR']."')"); - echo happy(i18n("Created team #%1: %2",array($num,$name))); + message_push(happy(i18n("Created team #%1: %2",array($num,$name)))); $num++; } } @@ -248,8 +231,24 @@ function addclicked() if($action=="edit" && $edit) { - echo "<< ".i18n("Back to Judging Teams")."\n"; - echo "
    "; + send_header("Edit Judging Team", + array('Committee Main' => 'committee_main.php', + 'Administration' => 'admin/index.php', + 'Judges' => 'admin/judges.php', + 'Manage Judging Teams' => 'admin/judges_teams.php')); +?> + + +"; $team=getJudgingTeam($edit); @@ -359,6 +358,10 @@ function addclicked() } else { + send_header("Manage Judging Teams", + array('Committee Main' => 'committee_main.php', + 'Administration' => 'admin/index.php', + 'Judges' => 'admin/judges.php')); echo "
    "; $teams=getJudgingTeams(); diff --git a/admin/judges_teams_members.php b/admin/judges_teams_members.php index 6025343..bfab15b 100644 --- a/admin/judges_teams_members.php +++ b/admin/judges_teams_members.php @@ -22,10 +22,10 @@ */ ?> 'committee_main.php', @@ -98,7 +98,7 @@ function switchjudgeinfo() { //before we insert them, we need to make sure they dont already belong to this team. We can not have the same judge assigned to the same team multiple times. - $q=mysql_query("SELECT * FROM judges_teams_link WHERE judges_id='$selectedjudge' AND judges_teams_id='$team_id'"); + $q=mysql_query("SELECT * FROM judges_teams_link WHERE users_id='$selectedjudge' AND judges_teams_id='$team_id'"); if(mysql_num_rows($q)) { echo notice(i18n("Judge (%1) already belongs to judging team: %2",array($selectedjudge,$team_name))); @@ -107,7 +107,7 @@ function switchjudgeinfo() else { //lets make the first one we add a captain, the rest, non-captains :) - mysql_query("INSERT INTO judges_teams_link (judges_id,judges_teams_id,captain,year) VALUES ('$selectedjudge','$team_id','$captain','".$config['FAIRYEAR']."')"); + mysql_query("INSERT INTO judges_teams_link (users_id,judges_teams_id,captain,year) VALUES ('$selectedjudge','$team_id','$captain','".$config['FAIRYEAR']."')"); $added++; } //if this is alreayd no, then who cares, but if its the first one that is going into the new team, then @@ -122,9 +122,9 @@ function switchjudgeinfo() echo happy(i18n("%1 %2 added to team #%3 (%4)",array($added,$j,$_POST['team_num'],$team_name))); } - if($_GET['action']=="del" && $_GET['team_num'] && $_GET['team_id'] && $_GET['judges_id']) + if($_GET['action']=="del" && $_GET['team_num'] && $_GET['team_id'] && $_GET['users_id']) { - mysql_query("DELETE FROM judges_teams_link WHERE judges_id='".$_GET['judges_id']."' AND judges_teams_id='".$_GET['team_id']."' AND year='".$config['FAIRYEAR']."'"); + mysql_query("DELETE FROM judges_teams_link WHERE users_id='".$_GET['users_id']."' AND judges_teams_id='".$_GET['team_id']."' AND year='".$config['FAIRYEAR']."'"); echo happy(i18n("Removed judge from team #%1 (%2)",array($_GET['team_num'],$_GET['team_name']))); //if there is still members left in the team, make sure we have a captain still @@ -139,7 +139,7 @@ function switchjudgeinfo() { if($first) { - $firstjudge=$r->judges_id; + $firstjudge=$r->users_id; $first=false; } @@ -152,7 +152,7 @@ function switchjudgeinfo() if(!$gotcaptain) { //make the first judge the captain - mysql_query("UPDATE judges_teams_link SET captain='yes' WHERE judges_teams_id='".$_GET['team_id']."' AND judges_id='$firstjudge' AND year='".$config['FAIRYEAR']."'"); + mysql_query("UPDATE judges_teams_link SET captain='yes' WHERE judges_teams_id='".$_GET['team_id']."' AND users_id='$firstjudge' AND year='".$config['FAIRYEAR']."'"); echo notice(i18n("Team captain was removed. A new team captain has been automatically assigned")); } } @@ -181,7 +181,7 @@ function switchjudgeinfo() { //teams can have as many captains as they want, so just add it. - mysql_query("UPDATE judges_teams_link SET captain='yes' WHERE judges_teams_id='".$_GET['team_id']."' AND judges_id='".$_GET['judge_id']."'"); + mysql_query("UPDATE judges_teams_link SET captain='yes' WHERE judges_teams_id='".$_GET['team_id']."' AND users_id='".$_GET['judge_id']."'"); echo happy(i18n("Team captain assigned")); } @@ -195,7 +195,7 @@ function switchjudgeinfo() } else { - mysql_query("UPDATE judges_teams_link SET captain='no' WHERE judges_teams_id='".$_GET['team_id']."' AND judges_id='".$_GET['judge_id']."'"); + mysql_query("UPDATE judges_teams_link SET captain='no' WHERE judges_teams_id='".$_GET['team_id']."' AND users_id='".$_GET['judge_id']."'"); echo happy(i18n("Team captain removed")); } } @@ -211,7 +211,7 @@ function switchjudgeinfo() echo ""; echo ""; echo ""; - echo ""; + echo ""; echo ""; echo ""; echo "
    ".i18n("Judges List"); @@ -236,81 +236,46 @@ function switchjudgeinfo() echo "
    "; -/* - //mysql 4.0 does not support subqueries - it is supported as of mysql 4.1 - //this means we cant use NOT IN (SELECT..) so, we will have to workaround this - //at least for now. + /* Load all the judges (judge_complete=yes, deleted=no, year=fairyear) */ + $judgelist = judges_load_all(); - $querystr="SELECT - judges.id, - judges.firstname, - judges.lastname - FROM - judges, - judges_years - WHERE - judges_years.year='".$config['FAIRYEAR']."' AND - judges.id=judges_years.judges_id AND - judges.id NOT IN (SELECT judges_id AS id FROM judges_teams_link WHERE judges_teams_link.year='".$config['FAIRYEAR']."') - ORDER BY - lastname, - firstname"; -*/ - $querystr="SELECT - judges.id, - judges.firstname, - judges.lastname - FROM - judges, - judges_years - WHERE - judges_years.year='".$config['FAIRYEAR']."' AND - judges.id=judges_years.judges_id AND - judges.complete='yes' - ORDER BY - lastname, - firstname"; - $q=mysql_query($querystr); - $judgelist=array(); - while($r=mysql_fetch_object($q)) { - $judgelist[$r->id]=$r; + /* Load all the teams */ + $teams = array(); + $q = mysql_query("SELECT * FROM judges_teams WHERE year='{$config['FAIRYEAR']}'"); + while($i = mysql_fetch_assoc($q)) { + $teams[$i['id']] = $i; } - if($_SESSION['viewstate']['judges_teams_list_show']=='unassigned') - { - $querystr="SELECT - judges.id, - judges.firstname, - judges.lastname - FROM - judges, - judges_teams_link, - judges_years - WHERE - judges_years.year='".$config['FAIRYEAR']."' - AND judges_teams_link.year='".$config['FAIRYEAR']."' - AND judges.id=judges_years.judges_id - AND judges.id=judges_teams_link.judges_id - AND judges.complete='yes' - ORDER BY - lastname, - firstname"; - $q=mysql_query($querystr); - while($r=mysql_fetch_object($q)) { - //remove anyone we find here from the list of all judges - unset($judgelist[$r->id]); + + /* And the links */ + $links = array(); + $q = mysql_query("SELECT * FROM judges_teams_link WHERE year='{$config['FAIRYEAR']}'"); + while($i = mysql_fetch_assoc($q)) { + $judgelist[$i['users_id']]['teams_links'][] = $i; + } + + $jlist = array(); + if($_SESSION['viewstate']['judges_teams_list_show']=='unassigned') { + /* Remove all judges that have a link */ + foreach($judgelist as $j) { + if(count($j['teams_links']) == 0) $jlist[] = $j['id']; } + } else { + $jlist = array_keys($judgelist); } + echo "
    "; - echo i18n("Listing %1 judges",array(count($judgelist))); + echo i18n("Listing %1 judges",array(count($jlist))); echo "
    "; echo "
    "; echo mysql_error(); echo ""; echo ""; @@ -318,8 +283,7 @@ function switchjudgeinfo() $teams=getJudgingTeams(); - foreach($teams AS $team) - { + foreach($teams AS $team) { echo "
    "; echo ""; @@ -336,8 +300,9 @@ function switchjudgeinfo() { foreach($team['members'] AS $member) { + $j = &$judgelist[$member['id']]; echo ""; } diff --git a/admin/judges_teams_timeslots.php b/admin/judges_teams_timeslots.php index 811c6b2..88ed582 100644 --- a/admin/judges_teams_timeslots.php +++ b/admin/judges_teams_timeslots.php @@ -22,22 +22,64 @@ */ ?> 'Judging Timeslot', + 'divisional1' => 'Divisional Round 1', + 'divisional2' => 'Divisional Round 2', + 'grand' => 'Grand Awards', + 'special' => 'Special Awards' ); + if(array_key_exists('action',$_GET)) + $action = $_GET['action']; + if(array_key_exists('action',$_POST)) + $action = $_POST['action']; + + + if($action == 'delete' && array_key_exists('delete', $_GET)) { + $id = intval($_GET['delete']); + mysql_query("DELETE FROM judges_teams_timeslots_link WHERE id='$id'"); + message_push(happy(i18n("Judging team timeslot successfully removed"))); + } + + if($action == 'empty' && array_key_exists('empty',$_GET)) { + $id = intval($_GET['empty']); + mysql_query("DELETE FROM judges_teams_timeslots_link WHERE judges_teams_id='$id'"); + message_push(happy(i18n("Judging team timeslots successfully removed"))); + } + + if($action == 'assign') { + //the db handles the uniqueness (to ensure the same timeslot isnt assigned to the same team more than once) + //so all we'll do here is just mass insert without regards for whats already there. + if(count($_POST['teams']) && count($_POST['timeslots'])) { + foreach($_POST['teams'] AS $tm) { + foreach($_POST['timeslots'] AS $ts) { + mysql_query("INSERT INTO judges_teams_timeslots_link (judges_teams_id,judges_timeslots_id,year) + VALUES ('$tm','$ts','{$config['FAIRYEAR']}')"); + + } + } + message_push(happy(i18n("%1 Timeslots assigned to %2 teams",array(count($_POST['timeslots']),count($_POST['teams']))))); + } else { + message_push(error(i18n("You must select both team(s) and timeslot(s) to assign"))); + } + } + + + + send_header("Judging Teams Timeslots", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php', 'Judges' => 'admin/judges.php') ); + ?> - - "; - if($_GET['action']=="delete" && $_GET['delete']) - { - mysql_query("DELETE FROM judges_teams_timeslots_link WHERE id='".$_GET['delete']."'"); - echo happy(i18n("Judging team timeslot successfully removed")); - } - - if($_GET['action']=="empty" && $_GET['empty']) - { - mysql_query("DELETE FROM judges_teams_timeslots_link WHERE judges_teams_id='".$_GET['empty']."'"); - echo happy(i18n("Judging team timeslots successfully removed")); - } - - if($_POST['action']=="assign") - { - //the db handles the uniqueness (to ensure the same timeslot isnt assigned to the same team more than once) - //so all we'll do here is just mass insert without regards for whats already there. - if(count($_POST['teams']) && count($_POST['timeslots'])) - { - foreach($_POST['teams'] AS $tm) - { - foreach($_POST['timeslots'] AS $ts) - { - mysql_query("INSERT INTO judges_teams_timeslots_link (judges_teams_id,judges_timeslots_id,year) VALUES ('$tm','$ts','".$config['FAIRYEAR']."')"); - - } - } - echo happy(i18n("%1 Timeslots assigned to %2 teams",array(count($_POST['timeslots']),count($_POST['teams'])))); - } - else - echo error(i18n("You must select both team(s) and timeslot(s) to assign")); - } - echo ""; echo ""; @@ -134,15 +140,23 @@ function checkinvert(what) echo ""; echo "\n"; - $q=mysql_query("SELECT * FROM judges_timeslots WHERE year='".$config['FAIRYEAR']."' ORDER BY date,starttime"); - while($r=mysql_fetch_object($q)) - { + $q=mysql_query("SELECT * FROM judges_timeslots + WHERE year='{$config['FAIRYEAR']}' + AND round_id='0' ORDER BY date,starttime"); + while($r=mysql_fetch_object($q)) { echo ""; - echo ""; - if($show_date) echo ""; - echo ""; - echo ""; - echo "\n"; + $span = $show_date ? 4 : 3; + echo ""; + $qq = mysql_query("SELECT * FROM judges_timeslots + WHERE round_id='{$r->id}' ORDER BY date,starttime"); + while($rr = mysql_fetch_object($qq)) { + echo ""; + echo ""; + if($show_date) echo ""; + echo ""; + echo ""; + echo "\n"; + } } echo "
    "; - echo ""; + echo ""; echo ""; if($member['captain']=="yes") { @@ -355,7 +320,10 @@ function switchjudgeinfo() } echo ""; echo $member['firstname']." ".$member['lastname']; - echo " (".$member['languages'].")"; + if(is_array($j['languages'])) + $l = is_array($j['languages']) ? join(' ',$j['languages']) : ''; + + echo " ($l)"; echo "
    ".i18n("End Time")."
    id\" />$r->date".substr($r->starttime,0,-3)."".substr($r->endtime,0,-3)."
    {$r->name} (".$round_str[$r->type].")
    id}\" />{$r->date}".substr($rr->starttime,0,-3)."".substr($rr->endtime,0,-3)."
    "; diff --git a/admin/judges_timeslots.php b/admin/judges_timeslots.php index eebb25c..cd9cabb 100644 --- a/admin/judges_timeslots.php +++ b/admin/judges_timeslots.php @@ -22,290 +22,378 @@ */ ?> 'committee_main.php', - 'Administration' => 'admin/index.php', - 'Judges' => 'admin/judges.php') - ); - echo "
    "; - if($_POST['action']=="add" || $_POST['action']=="edit") - { - $err=0; - if($_POST['date_year'] && $_POST['date_month'] && $_POST['date_day']) - { - $date=$_POST['date_year'] ."-". $_POST['date_month'] ."-". $_POST['date_day']; - } - else - { - $err=1; - echo error(i18n("Date is required")); + $round_str = array('timeslot' => 'Judging Timeslot', + 'divisional1' => 'Divisional Round 1', + 'divisional2' => 'Divisional Round 2', + 'grand' => 'Grand Awards', + 'special' => 'Special Awards' ); + + if(array_key_exists('action',$_POST)) $action = $_POST['action']; + else if(array_key_exists('action',$_GET)) $action = $_GET['action']; + else $action = ''; + + if(array_key_exists('round_id',$_POST)) $round_id = intval($_POST['round_id']); + else if(array_key_exists('round_id',$_GET)) $round_id = intval($_GET['round_id']); + else $round_id = 0; + + if(array_key_exists('timeslot_id',$_POST)) $timeslot_id = intval($_POST['timeslot_id']); + else if(array_key_exists('timeslot_id',$_GET)) $timeslot_id = intval($_GET['timeslot_id']); + else $timeslot_id = 0; + + if($action == 'saveround') { + $save = true; + /* Sanity check all the values */ + $y = intval($_POST['date_year']); + $m = intval($_POST['date_month']); + $d = intval($_POST['date_day']); + if($y && $m && $d) $date = "$y-$m-$d"; + else { + $save = false; + message_push(error(i18n("Date is required"))); } - if($_POST['starttime_hour'] && $_POST['starttime_minute']) - { - $starttime=$_POST['starttime_hour'] .":". $_POST['starttime_minute'].":00"; - } - else - { - $err=1; - echo error(i18n("Start Time is required")); + if(array_key_exists('starttime_hour', $_POST) && array_key_exists('starttime_minute', $_POST)) { + $starttime = sprintf("%02d:%02d:00", intval($_POST['starttime_hour']), intval($_POST['starttime_minute'])); + } else { + $save = false; + message_push( error(i18n("Start Time is required"))); } - if($_POST['endtime_hour'] && $_POST['endtime_minute']) - { - $endtime=$_POST['endtime_hour'] .":". $_POST['endtime_minute'].":00"; - } - else - { - $err=1; - echo error(i18n("End Time is required")); + if(array_key_exists('endtime_hour', $_POST) && array_key_exists('endtime_minute', $_POST)) { + $endtime = sprintf("%02d:%02d:00", intval($_POST['endtime_hour']), intval($_POST['endtime_minute'])); + } else { + $save = false; + message_push( error(i18n("End Time is required"))); } - $allowdivisional=$_POST['allowdivisional']; - if(!$allowdivisional) $allowdivisional="no"; + $type = $_POST['type']; + if(!array_key_exists($type, $round_str)) { + $save = false; + message_push(error(i18n('Invalid type specified'))); + } - if(!$err) - { - if($_POST['action']=="add") - { - mysql_query("INSERT INTO judges_timeslots (date,starttime,endtime,year) VALUES ('$date','$starttime','$endtime','".$config['FAIRYEAR']."')"); - echo happy(i18n("New timeslot successfully added")); + $name = mysql_escape_string(stripslashes($_POST['name'])); + + if($save == true) { + if($round_id == 0) { + /* New entry */ + mysql_query("INSERT INTO judges_timeslots (round_id,year) VALUES('0','{$config['FAIRYEAR']}')"); + $round_id = mysql_insert_id(); } - if($_POST['action']=="edit") - { - mysql_query("UPDATE judges_timeslots SET `date`='$date', starttime='$starttime', endtime='$endtime', allowdivisional='$allowdivisional' WHERE id='".$_POST['edit']."'"); - echo mysql_error(); - echo happy(i18n("Timeslot successfully saved")); + + mysql_query("UPDATE judges_timeslots SET `date`='$date', + starttime='$starttime', endtime='$endtime', + `name`='$name', + `type`='$type' WHERE id='$round_id'"); + + echo mysql_error(); + message_push(happy(i18n("Round successfully saved"))); + $action = ''; + } + + } + + if($action == 'deleteround') { + mysql_query("DELETE FROM judges_timeslots WHERE id='$round_id'"); + /* Also delete all timeslots */ + mysql_query("DELETE FROM judges_timeslots WHERE round_id='$round_id'"); + message_push(happy(i18n("Round successfully removed"))); + $action = ''; + } + if($action == 'deletetimeslot') { + mysql_query("DELETE FROM judges_timeslots WHERE id='$timeslot_id'"); + message_push(happy(i18n("Timeslot successfully removed"))); + $action = ''; + } + + if($action == 'savetimeslot') { + $save = true; + + $q = mysql_query("SELECT * FROM judges_timeslots WHERE id='$round_id'"); + $round_data = mysql_fetch_assoc($q); + + $date = $round_data['date']; + + if(array_key_exists('starttime_hour', $_POST) && array_key_exists('starttime_minute', $_POST)) { + $starttime = sprintf("%02d:%02d:00", intval($_POST['starttime_hour']), intval($_POST['starttime_minute'])); + } else { + $save = false; + message_push( error(i18n("Start Time is required"))); + } + + if(array_key_exists('endtime_hour', $_POST) && array_key_exists('endtime_minute', $_POST)) { + $endtime = sprintf("%02d:%02d:00", intval($_POST['endtime_hour']), intval($_POST['endtime_minute'])); + } else { + $save = false; + message_push( error(i18n("End Time is required"))); + } + + if($save == true) { + if($timeslot_id == 0) { + /* New entry */ + mysql_query("INSERT INTO judges_timeslots (round_id,date,type,year) VALUES('$round_id', + '$date','timeslot','{$config['FAIRYEAR']}')"); + $timeslot_id = mysql_insert_id(); } + + mysql_query("UPDATE judges_timeslots SET starttime='$starttime', endtime='$endtime' + WHERE id='$timeslot_id'"); + + echo mysql_error(); + message_push(happy(i18n("Timeslot successfully saved"))); + $action = ''; } } - else if($_POST['action']=="addmultiple") - { - if($_POST['addnum'] && $_POST['date_day'] && $_POST['date_month'] && $_POST['date_year'] && $_POST['starttime_hour'] && $_POST['starttime_minute'] && $_POST['duration'] && $_POST['break']) - { - $date=$_POST['date_year']."-".$_POST['date_month']."-".$_POST['date_day']; - $hr=$_POST['starttime_hour']; - $min=$_POST['starttime_minute']; - $dur=$_POST['duration']; - $brk=$_POST['break']; - $tt=$dur+$brk; + + if($action=='savemultiple') { + $save = true; + + $addnum = intval($_POST['addnum']); + $duration = intval($_POST['duration'] ); + $break = intval($_POST['break']); - if($_POST['allowdivisional']=="yes") $ad="yes"; else $ad="no"; + if(array_key_exists('starttime_hour', $_POST) && array_key_exists('starttime_minute',$_POST) && $addnum && $duration) { + + $q = mysql_query("SELECT * FROM judges_timeslots WHERE id='$round_id'"); + $round_data = mysql_fetch_assoc($q); - for($x=0;$x<$_POST['addnum'];$x++) - { - $q=mysql_query("SELECT DATE_ADD('$date $hr:$min:00', INTERVAL $dur MINUTE) AS endtime, - DATE_ADD('$date $hr:$min:00', INTERVAL $tt MINUTE) AS startnext - "); - echo mysql_error(); + $date = $round_data['date']; + + $hr=intval($_POST['starttime_hour']); + $min=intval($_POST['starttime_minute']); + + $tt=$duration+$break; + + for($x=0;$x<$addnum;$x++) { + $q=mysql_query("SELECT DATE_ADD('$date $hr:$min:00', INTERVAL $duration MINUTE) AS endtime, + DATE_ADD('$date $hr:$min:00', INTERVAL $tt MINUTE) AS startnext "); + echo mysql_error(); $r=mysql_fetch_object($q); list($ed,$et)=split(" ",$r->endtime); list($nd,$nt)=split(" ",$r->startnext); - mysql_query("INSERT INTO judges_timeslots (date,starttime,endtime,allowdivisional,year) VALUES ( - '$date', - '$hr:$min:00', - '$et', - '$ad', - '".$config['FAIRYEAR']."')"); - echo mysql_Error(); + $starttime = sprintf("%02d:%02d:00", $hr, $min); + + mysql_query("INSERT INTO judges_timeslots (date,type,round_id,starttime,endtime,year) VALUES ( + '$date','timeslot','{$round_data['id']}', + '$starttime', '$et', + '{$config['FAIRYEAR']}')"); + echo mysql_error(); $date=$nd; list($s_h,$s_m,$s_s)=split(":",$nt); list($e_h,$e_m,$e_s)=split(":",$et); - echo happy(i18n("Adding timeslot: %1",array($date." ".$hr.":".$min." - ".$e_h.":".$e_m))); + message_push(happy(i18n("Adding timeslot: %1",array("$date $hr:$min - $e_h:$e_m")))); $hr=$s_h; $min=$s_m; } + $action = ''; + } else { + message_push(error(i18n("All fields are required to add multiple timeslots"))); } - else - echo error(i18n("All fields are required to add multiple timeslots")); + } + + + + if($action == '') { + send_header("Judging Rounds and Timeslots", + array('Committee Main' => 'committee_main.php', + 'Administration' => 'admin/index.php', + 'Judges' => 'admin/judges.php')); + } else { + send_header("Judging Rounds and Timeslots", + array('Committee Main' => 'committee_main.php', + 'Administration' => 'admin/index.php', + 'Judges' => 'admin/judges.php', + 'Judging Rounds and Timeslots' => 'admin/judges_timeslots.php')); + } + echo "
    "; + + + if($action == 'addround' || $action == 'editround') { + echo ""; + echo "\n"; + echo "\n"; + + if($action == 'addround') { + echo "

    Add New Judging Round

    "; + $r = array(); + $r['date'] = $config['dates']['fairdate']; + } else { + echo "

    Edit Judging Round

    "; + $q=mysql_query("SELECT * FROM judges_timeslots WHERE id='$round_id'"); + if(mysql_num_rows($q) != 1) { + echo "UNKNOWN ROUND $round_id"; + exit; + } + $r = mysql_fetch_assoc($q); + } + + echo ""; + echo ""; + + echo ""; + echo ""; + echo ""; + echo "
    ".i18n('Round Type').":"; + echo ""; + + echo "
    ".i18n("Name").":"; + echo "
    ".i18n("Date").":"; + emit_date_selector("date",$r['date']); + + echo "
    ".i18n("Start Time").":"; + emit_time_selector("starttime",$r['starttime']); + + echo "
    ".i18n("End Time").":"; + emit_time_selector("endtime",$r['endtime']); + + echo "
    "; + + echo ""; + echo ""; } - //FIXME: only delete if the timeslot is not in use!!! - if($_GET['action']=="delete" && $_GET['delete']) - { - mysql_query("DELETE FROM judges_timeslots WHERE id='".$_GET['delete']."'"); - echo happy(i18n("Timeslot successfully removed")); + if($action == 'addtimeslot' || $action == 'edittimeslot') { + echo "
    "; + echo "\n"; + echo "\n"; + echo "\n"; + $q = mysql_query("SELECT * FROM judges_timeslots WHERE id='$round_id'"); + $round_data = mysql_fetch_assoc($q); + if($action == 'addtimeslot') { + echo "

    Add New Judging Timeslot

    "; + $r = array(); + $r['date'] = $round_data['date']; + } else { + echo "

    Edit Judging Timeslot

    "; + $q=mysql_query("SELECT * FROM judges_timeslots WHERE id='$timeslot_id'"); + if(mysql_num_rows($q) != 1) { + echo "UNKNOWN ROUND $round_id"; + exit; + } + $r = mysql_fetch_assoc($q); + } + + echo ""; + echo ""; + echo ""; + + echo ""; + echo ""; + echo "
    ".i18n('Round Type').":{$round_str[$round_data['type']]}
    ".i18n("Name").":{$round_data['name']}
    ".i18n("Start Time").":"; + emit_time_selector("starttime",$r['starttime']); + + echo "
    ".i18n("End Time").":"; + emit_time_selector("endtime",$r['endtime']); + + echo "
    "; + + echo ""; + echo "
    "; } - if($_GET['action']=="addmultiple") - { + if($action == 'addmultiple') { echo "

    Add Multiple New Judging Timeslots

    "; - echo "<< ".i18n("Back to Judging Timeslots")."\n"; - $q=mysql_query("SELECT * FROM judges_timeslots WHERE year='".$config['FAIRYEAR']."' ORDER BY date DESC LIMIT 1"); - if(mysql_num_rows($q)) - { - $r=mysql_fetch_object($q); - $date=$r->date; - } - else - { - $date=$config['dates']['fairdate']; - } - echo "
    "; - echo "\n"; - echo ""; - echo "
    "; - echo i18n("Add"); - echo ""; - echo ""; - echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + + $q = mysql_query("SELECT * FROM judges_timeslots WHERE id='$round_id'"); + $round_data = mysql_fetch_assoc($q); + + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; - echo ""; - echo ""; + echo ""; + echo ""; - echo ""; - - - - echo ""; echo "
    ".i18n('Round Type').":{$round_str[$round_data['type']]}
    ".i18n("Name").":{$round_data['name']}
    ".i18n("Add").""; + echo " "; echo i18n("new timeslots"); - echo "
    "; - echo i18n("On date"); - echo ""; - emit_date_selector("date",$date); - echo "
    "; - echo i18n("Starting timeslots at"); - echo ""; + echo "
    ".i18n("Starting timeslots at").""; emit_time_selector("starttime"); echo "
    "; - echo i18n("With a duration of"); - echo ""; - echo ""; - echo ""; - echo i18n("minutes"); - echo "
    "; - echo i18n("And a break of"); - echo ""; - echo ""; - echo ""; - echo i18n("minutes"); - echo "
    ".i18n("With a duration of").""; + echo " "; + echo i18n("minutes")."
    ".i18n("And a break of").""; + echo " "; + echo i18n("minutes")."
    "; - if($allowdivisional=="yes") $ch="checked=\"checked\""; else $ch=""; - echo ""; - echo ""; - echo i18n("Allow this timeslot to be used by the automatic judges scheduler for divisional awards"); - echo "
    "; + echo "
    "; echo ""; echo "
    "; echo ""; - $showlist=false; - } - else if($_GET['action']=="add" || $_GET['action']=="edit") - { - echo "
    "; - echo "\n"; - - if($_GET['action']=="add") - { - echo "

    Add New Judging Timeslot

    "; - $buttontext=i18n("Add Timeslot"); - //get a default date, either the date from a different timeslot, or the date of the fair, whichever. - $q=mysql_query("SELECT * FROM judges_timeslots WHERE year='".$config['FAIRYEAR']."' ORDER BY date DESC LIMIT 1"); - if(mysql_num_rows($q)) - { - $r=mysql_fetch_object($q); - $date=$r->date; - } - else - { - $date=$config['dates']['fairdate']; - } - $starttime=""; - $endtime=""; - $allowdivisional="yes"; - - } - else if($_GET['action']=="edit") - { - echo "\n"; - echo "

    Edit Judging Timeslot

    "; - $buttontext=i18n("Save Timeslot"); - $q=mysql_query("SELECT * FROM judges_timeslots WHERE year='".$config['FAIRYEAR']."' AND id='".$_GET['edit']."'"); - $r=mysql_fetch_object($q); - - $date=$r->date; - $starttime=$r->starttime; - $endtime=$r->endtime; - $allowdivisional=$r->allowdivisional; - } - - - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - - echo "
    ".i18n("Date").":"; - emit_date_selector("date",$date); - - echo "
    ".i18n("Start Time").":"; - emit_time_selector("starttime",$starttime); - - echo "
    ".i18n("End Time").":"; - emit_time_selector("endtime",$endtime); - - echo "
    "; - if($allowdivisional=="yes") $ch="checked=\"checked\""; else $ch=""; - echo ""; - echo ""; - echo i18n("Allow this timeslot to be used by the automatic judges scheduler for divisional awards"); - echo "
    "; - - echo ""; - echo "
    "; - - - } - else - { - - echo "".i18n("Add new judging timeslot")."
    "; - echo "".i18n("Add multiple new judging timeslots")."
    "; + if($action == '') { + echo "".i18n("Add new round")."
    "; + echo "
    "; echo ""; echo ""; echo ""; echo ""; echo ""; - echo ""; + echo ""; echo ""; echo ""; - $q=mysql_query("SELECT * FROM judges_timeslots WHERE year='".$config['FAIRYEAR']."' ORDER BY date,starttime"); - while($r=mysql_fetch_object($q)) - { + $q=mysql_query("SELECT * FROM judges_timeslots WHERE year='{$config['FAIRYEAR']}' AND `type`!='timeslot' ORDER BY date,starttime"); + while($r=mysql_fetch_object($q)) { echo ""; -// echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - + $qq = mysql_query("SELECT * FROM judges_timeslots WHERE round_id='{$r->id}' ORDER BY `date`,`starttime`"); + $c = mysql_num_rows($qq) +1; + echo ""; + echo ""; + echo ""; + echo ""; echo " \n"; - echo ""; + + while($rr = mysql_fetch_object($qq)) { + echo ""; +// echo ""; + echo ""; + echo ""; + echo ""; + + + echo " \n"; + echo ""; + } } - echo "
    ".i18n("Date")."".i18n("Start Time")."".i18n("End Time")."".i18n("Div OK?")."".i18n("Judging Round")."".i18n("Actions")."
    $r->id$r->date".substr($r->starttime,0,-3)."".substr($r->endtime,0,-3)."$r->allowdivisional$r->date".substr($r->starttime,0,-3)."
    "; + + echo "
    ".substr($r->endtime,0,-3)."{$r->name} (".i18n($round_str[$r->type]).")"; - echo "id\">"; + echo "id}\">"; echo " "; - echo "id\">"; + echo "id}\">"; + echo "id}\">(new) "; + echo "id}\">(multiple)
    "; echo "
    ".substr($rr->starttime,0,-3)."".substr($rr->endtime,0,-3)."".i18n($round_str[$rr->type]).""; + echo "id}×lot_id={$rr->id}\">"; + echo " "; + echo "id}\">"; + + echo "
    "; + echo "
    "; } send_footer(); diff --git a/admin/regfee_items_manager.php b/admin/regfee_items_manager.php index a3532a7..40fc984 100644 --- a/admin/regfee_items_manager.php +++ b/admin/regfee_items_manager.php @@ -48,6 +48,7 @@ array('key' => 'project', 'val' => "Project") ) ); $editor->setFieldInputType("per", 'select'); + $editor->filterList('year',$config['FAIRYEAR']); $editor->execute(); diff --git a/admin/reports.inc.php b/admin/reports.inc.php index 1fbb50d..33cfd54 100644 --- a/admin/reports.inc.php +++ b/admin/reports.inc.php @@ -667,6 +667,10 @@ foreach($report_stock as $n=>$v) { } $t = $filter_ops[$d['x']]; $filter[] = "{$fields[$f]['table']} $t '{$d['value']}'"; + if(is_array($fields[$f]['components'])) { + $components = array_merge($components, + $fields[$f]['components']); + } } $sel = implode(",", $sel); $order = implode(",", $order); diff --git a/admin/reports.php b/admin/reports.php index d6cad83..d203586 100644 --- a/admin/reports.php +++ b/admin/reports.php @@ -40,7 +40,7 @@ if($action == 'unlink') { $id = intval($_GET['id']); mysql_query("DELETE FROM reports_committee WHERE - users_id='{$_SESSION['users_id']}' AND id='$id'"); + users_id='{$_SESSION['users_uid']}' AND id='$id'"); $_SESSION['messages'][] = 'unlinked'; header("Location: reports.php?edit=1"); exit; @@ -87,7 +87,7 @@ mysql_query("INSERT INTO `reports_committee` (`id`, `users_id` , `reports_id` , `category` , `comment` , `format` , `stock`) VALUES ( - NULL , '{$_SESSION['users_id']}', + NULL , '{$_SESSION['users_uid']}', '$reports_id', '$category', '$comment', '$type', '$stock' );"); $_SESSION['messages'][] = 'added'; @@ -139,7 +139,7 @@ $q = mysql_query("SELECT reports_committee.*,reports.name FROM reports_committee LEFT JOIN reports ON reports.id=reports_committee.reports_id - WHERE users_id='{$_SESSION['users_id']}' + WHERE users_id='{$_SESSION['users_uid']}' ORDER BY category,id"); echo mysql_error(); if(mysql_num_rows($q) == 0) { @@ -354,7 +354,7 @@ echo "".i18n("Category").":"; $q = mysql_query("SELECT DISTINCT category FROM reports_committee - WHERE users_id='{$_SESSION['users_id']}' + WHERE users_id='{$_SESSION['users_uid']}' ORDER BY category"); echo i18n("Existing Category").": "; echo "\n"; + echo "".i18n("School Designation").""; + $des = array('' => 'Choose', 'public' => 'Public', + 'independent' => 'Independent/Private', + 'home' => 'Home School'); + echo "\n"; echo "".i18n("School Level")."schoollevel)."\" size=\"32\" maxlength=\"32\" />\n"; echo "".i18n("School Board")."board)."\" size=\"60\" maxlength=\"64\" />\n"; echo "".i18n("School District")."district)."\" size=\"60\" maxlength=\"64\" />\n"; @@ -181,6 +194,10 @@ } + echo "
    ".i18n("Demographic Information").""; + + $ch = ($r->atrisk) == 'yes' ? 'checked="checked"' : ''; + echo "".i18n("Inner City or At-Risk school")."\n"; echo " "; echo "\n"; diff --git a/admin/sciencefairs.php b/admin/sciencefairs.php new file mode 100644 index 0000000..328dd06 --- /dev/null +++ b/admin/sciencefairs.php @@ -0,0 +1,39 @@ + + Copyright (C) 2005 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + 'committee_main.php', + 'Administration' => 'admin/index.php'), + "sciencefair_management" + ); + echo "
    "; + echo "".i18n("Science Fair Manager")."
    "; + + send_footer(); + +?> diff --git a/admin/sponsor_contacts.php b/admin/sponsor_contacts.php new file mode 100644 index 0000000..3423305 --- /dev/null +++ b/admin/sponsor_contacts.php @@ -0,0 +1,230 @@ + + Copyright (C) 2005-2008 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + 'committee_main.php', + 'Administration' => 'admin/index.php', + 'Sponsors' => 'admin/sponsors.php')); + + if($_GET['sponsors_id']) + $sponsors_id=$_GET['sponsors_id']; + else if($_POST['sponsors_id']) + $sponsors_id=$_POST['sponsors_id']; +?> + +"; + echo ""; + echo ""; + + if($sponsors_id) + { + if($_POST['save']=="edit" || $_POST['save']=="add") + { + $p = ($_POST['primary']=='yes')?'yes':'no'; + + if($_POST['save']=="add") { + $u=user_create("sponsor", $_POST['email']); + $id=$u['id']; + } + else { + $u=user_load($_POST['id']); + $id=intval($_POST['id']); + } + + if($p == 'no') { + /* Make sure this sponsor ($sponsors_id) has a primary */ + $q = mysql_query("SELECT users_id + FROM users_sponsor, users + WHERE + users_sponsor.users_id=users.id + AND sponsors_id='$sponsors_id' + AND `primary`='yes' + AND year='".$config['FAIRYEAR']."' + AND users_id!='$id'"); + if(mysql_num_rows($q) == 0) { + /* This must be the primary */ + $p = 'yes'; + } + } else { + /* Unset all other primaries */ + mysql_query("UPDATE users_sponsor SET `primary`='no' + WHERE sponsors_id='$sponsors_id'"); + } + + $u['primary']=$p; + $u['salutation']=$_POST['salutation']; + $u['firstname']=$_POST['firstname']; + $u['lastname']=$_POST['lastname']; + $u['position']=$_POST['position']; + $u['phonework']=$_POST['phonework']; + $u['phonecell']=$_POST['phonecell']; + $u['phonehome']=$_POST['phonehome']; + $u['fax']=$_POST['fax']; + $u['email']=$_POST['email']; + $u['notes']=$_POST['notes']; + $u['sponsors_id']=$sponsors_id; + user_save($u); + + if($_POST['save']=="add") + echo happy(i18n("Contact successfully added")); + else + echo happy(i18n("Successfully saved changes to contact")); + } + + if($_GET['action']=="delete" && $_GET['delete']) { + user_delete(intval($_GET['delete'])); + echo happy("Contact successfully deleted"); + } + + if($_GET['action']=="edit" || $_GET['action']=="add") + { + + echo "<< ".i18n("Back to %1 Contacts",array($sponsors_organization))."\n"; + if($_GET['action']=="edit") + { + echo "

    ".i18n("Edit %1 Contact",array($sponsors_organization))."

    \n"; + $buttontext="Save Contact"; +// $q=mysql_query("SELECT * FROM sponsor_contacts WHERE id='".$_GET['edit']."'"); +// $r=mysql_fetch_object($q); + $u=user_load(intval($_GET['edit'])); + } + else if($_GET['action']=="add") + { + echo "

    ".i18n("Add %1 Contact",array($sponsors_organization))."

    \n"; + $buttontext="Add Contact"; + } + $buttontext=i18n($buttontext); + + echo "
    \n"; + echo "\n"; + echo "\n"; + + if($_GET['action']=="edit") + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
    ".i18n("Salutation")."
    ".i18n("First Name")."
    ".i18n("Last Name")."
    ".i18n("Position")."
    ".i18n("Phone (Work)")."
    ".i18n("Phone (Cell)")."
    ".i18n("Phone (Home)")."
    ".i18n("Fax")."
    ".i18n("Email")."
    ".i18n("Notes")."
    ".i18n("Primary Contact")."
    \n"; + echo "
    \n"; + } + else + { + + echo "
    "; + echo "".i18n("Add New Contact to %1",array($sponsors_organization))."\n"; + echo "
    "; + + $q=mysql_query("SELECT * FROM users LEFT JOIN users_sponsor ON users_sponsor.users_id=users.id + WHERE year='".$config['FAIRYEAR']."' + AND sponsors_id='$sponsors_id' + AND deleted='no' + ORDER BY lastname,firstname"); + echo mysql_Error(); + + if(mysql_num_rows($q)) + { + echo ""; + echo ""; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo "\n"; + + + while($r=mysql_fetch_object($q)) + { + echo "\n"; + echo " \n"; + echo " "; + echo " \n"; + echo " \n"; + $p = i18n(($r->primary=='yes')?'Yes':'No'); + echo " \n"; + echo " \n"; + echo "\n"; + } + + echo "
    ".i18n("Name")."".i18n("Email")."".i18n("Phone (Work)")."".i18n("Phone (Cell)")."".i18n("Primary")."Actions
    "; + if($r->salutation) echo $r->salutation." "; + echo "$r->firstname $r->lastname"; + if($r->email) { + list($eb,$ea)=split("@",$r->email); + echo ""; + } + else + echo " "; + + echo " $r->phonework$r->phonecell$p"; + //FIXME: should we just go to /user_personal.php here instead? + echo "id\">"; + echo " "; + echo "id\">"; + echo "
    \n"; + } + } + + } + + send_footer(); + +?> diff --git a/admin/sponsors.php b/admin/sponsors.php new file mode 100644 index 0000000..6b4ec3d --- /dev/null +++ b/admin/sponsors.php @@ -0,0 +1,210 @@ + + Copyright (C) 2008 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + 'committee_main.php', + 'Administration' => 'admin/index.php', + 'Fundraising Main' => 'admin/fundraising.php') + ); + + if($_POST['save']=="edit" || $_POST['save']=="add") + { + if($_POST['save']=="add") + { + $q=mysql_query("INSERT INTO sponsors (year) VALUES ('".$config['FAIRYEAR']."')"); + $id=mysql_insert_id(); + } + else + $id=$_POST['id']; + + + $exec="UPDATE sponsors SET ". + "organization='".mysql_escape_string(stripslashes($_POST['organization']))."', ". + "address='".mysql_escape_string(stripslashes($_POST['address']))."', ". + "city='".mysql_escape_string(stripslashes($_POST['city']))."', ". + "province_code='".mysql_escape_string(stripslashes($_POST['province_code']))."', ". + "postalcode='".mysql_escape_string(stripslashes($_POST['postalcode']))."', ". + "phone='".mysql_escape_string(stripslashes($_POST['phone']))."', ". + "tollfree='".mysql_escape_string(stripslashes($_POST['tollfree']))."', ". + "fax='".mysql_escape_string(stripslashes($_POST['fax']))."', ". + "email='".mysql_escape_string(stripslashes($_POST['email']))."', ". + "website='".mysql_escape_string(stripslashes($_POST['website']))."', ". + "notes='".mysql_escape_string(stripslashes($_POST['notes']))."', ". + "donationpolicyurl='".mysql_escape_string(stripslashes($_POST['donationpolicyurl']))."', ". + "fundingselectiondate='".mysql_escape_string(stripslashes($_POST['fundingselectiondate']))."', ". + "logo='".mysql_escape_string(stripslashes($_POST['logo']))."', ". + "waiveraccepted='".mysql_escape_string(stripslashes($_POST['waiveraccepted']))."', ". + "taxreceiptrequired='".mysql_escape_string(stripslashes($_POST['taxreceiptrequired']))."' ". + "WHERE id='$id'"; + mysql_query($exec); + + if($_POST['save']=="add") + echo happy("Sponsor successfully added"); + else + echo happy("Successfully saved changes to sponsor"); + } + + if($_GET['action']=="delete" && $_GET['delete']) + { + //dont allow any deleting until we figure out what we need to do, infact, i think we never should hard delete + //this should only soft-delete so things like awards from previous years are still all linked correctly. + // mysql_query("DELETE FROM sponsors WHERE id='".$_GET['delete']."'"); +// echo happy("Sponsors cannot be deleted"); + } + + if($_GET['action']=="edit" || $_GET['action']=="add") + { + + echo "<< ".i18n("Back to Award Sponsors")."\n"; + if($_GET['action']=="edit") + { + echo "

    ".i18n("Edit Award Sponsor")."

    \n"; + $buttontext="Save Sponsor"; + $q=mysql_query("SELECT * FROM sponsors WHERE id='".$_GET['edit']."'"); + $r=mysql_fetch_object($q); + } + else if($_GET['action']=="add") + { + echo "

    ".i18n("Add New Award Sponsor")."

    \n"; + $buttontext="Add Sponsor"; + } + $buttontext=i18n($buttontext); + + echo "
    \n"; + echo "\n"; + + if($_GET['action']=="edit") + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + + echo "
    ".i18n("Organization Name")."organization)."\" size=\"60\" maxlength=\"128\" />
    ".i18n("Address")."address)."\" size=\"60\" maxlength=\"64\" />
    ".i18n("City")."city)."\" size=\"32\" maxlength=\"32\" />
    ".i18n($config['provincestate']).""; + emit_province_selector("province_code",$r->province_code); + echo "
    ".i18n($config['postalzip'])."postalcode\" size=\"8\" maxlength=\"7\" />
    ".i18n("Phone")."phone)."\" size=\"16\" maxlength=\"32\" />
    ".i18n("Toll Free")."tollfree)."\" size=\"16\" maxlength=\"32\" />
    ".i18n("Fax")."fax)."\" size=\"16\" maxlength=\"32\" />
    ".i18n("Email")."email)."\" size=\"60\" maxlength=\"128\" />
    ".i18n("Website")."website)."\" size=\"60\" maxlength=\"128\" />
    ".i18n("Donation Policy URL")."donationpolicyurl)."\" size=\"60\" maxlength=\"128\" />
    ".i18n("Funding Selection Date").""; + emit_date_selector("fundingselectiondate",$r->fundingselectiondate); + echo "
    ".i18n("Logo")."
    ".i18n("Waiver Accepted").""; + if($r->waiveraccepted=="no") $ch="checked=\"checked\""; else $ch=""; + echo "".i18n("No")."   "; + if($r->waiveraccepted=="yes") $ch="checked=\"checked\""; else $ch=""; + echo "".i18n("Yes")."   "; + echo "
    ".i18n("Tax Receipt Required").""; + if($r->taxreceiptrequired=="no") $ch="checked=\"checked\""; else $ch=""; + echo "".i18n("No")."   "; + if($r->taxreceiptrequired=="yes") $ch="checked=\"checked\""; else $ch=""; + echo "".i18n("Yes")."   "; + echo "
    ".i18n("Notes")."
    \n"; + echo "
    \n"; + + + + } + else + { + echo "Add New Sponsor\n"; + echo "
    "; + echo ""; + echo ""; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo "\n"; + + //$q=mysql_query("SELECT * FROM award_sponsors WHERE year='".$config['FAIRYEAR']."' ORDER BY organization"); + //we want to show all years, infact that year field probably shouldnt even be there. + $q=mysql_query("SELECT * FROM sponsors ORDER BY organization"); + while($r=mysql_fetch_object($q)) + { + echo "\n"; + echo " \n"; + + $numq=mysql_query("SELECT COUNT(id) AS num FROM award_awards WHERE year='".$config['FAIRYEAR']."' AND sponsors_id='$r->id'"); + $numr=mysql_fetch_object($numq); + $numawards=$numr->num; + + $numq=mysql_query("SELECT COUNT(id) AS num FROM sponsorships WHERE year='".$config['FAIRYEAR']."' AND sponsors_id='$r->id'"); + $numr=mysql_fetch_object($numq); + $numsponsorships=$numr->num; + + $numq=mysql_query("SELECT COUNT(users_id) AS num FROM users_sponsor, users WHERE sponsors_id='$r->id' AND users_sponsor.users_id=users.id AND users.year='".$config['FAIRYEAR']."' and users.deleted='no'"); + $numr=mysql_fetch_object($numq); + $numcontacts=$numr->num; + + + echo " "; + + echo " "; + + echo " "; + echo " \n"; + echo "\n"; + } + + echo "
    Organization# of Sponsorships# of Awards# of ContactsAction
    $r->organization"; + echo "$numsponsorships  "; + echo "id\">\"view\""; + echo ""; + echo "$numawards  "; + echo "id\">\"view\""; + echo ""; + echo "$numcontacts  "; + echo "id\">\"view\""; + echo ""; + echo "id\">"; + /* cannot delete sponsors, we need to be able to link to them from other years, etc... this could be turned back on as a soft delete eventually + echo " "; + echo "id\">"; +*/ + + echo "
    \n"; + + + } + + send_footer(); + +?> diff --git a/admin/sponsorship_levels.php b/admin/sponsorship_levels.php new file mode 100644 index 0000000..dc1e4d3 --- /dev/null +++ b/admin/sponsorship_levels.php @@ -0,0 +1,71 @@ + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +level)."', + '".mysql_real_escape_string($r->min)."', + '".mysql_real_escape_string($r->max)."', + '".mysql_real_escape_string($r->description)."', + '".$config['FAIRYEAR']."')"); + } + } + + user_auth_required('committee', 'admin'); + send_header("Sponsorship Levels", + array('Committee Main' => 'committee_main.php', + 'Administration' => 'admin/index.php', + 'Fundraising' => 'admin/fundraising.php'), + "internal_document_management" + ); + + $editor=new TableEditor("sponsorships_levels", + array("level"=>"Level Name", + "min"=>"Minimum Amount", + "max"=>"Maximum Amount", + ) + , + array("level"=>"Level Name", + "min"=>"Minimum Amount", + "max"=>"Maximum Amount", + "description"=>"Description / Benefits", + ) + ,array("year"=>$config['FAIRYEAR']) + ); + + $editor->setPrimaryKey("id"); + $editor->setDefaultSortField("max"); + $editor->setRecordType("Level"); + $editor->filterList('year',$config['FAIRYEAR']); + $editor->execute(); + + send_footer(); +?> diff --git a/admin/stats.inc.php b/admin/stats.inc.php new file mode 100644 index 0000000..8c8514d --- /dev/null +++ b/admin/stats.inc.php @@ -0,0 +1,62 @@ + array('manual' => true), + 'end_date' => array('manual' => true), + 'address' => array('manual' => true), + 'budget' => array('manual' => true), + 'ysf_affiliation_complete' => array('manual' => true), + 'charity' => array('manual' => true), + 'male_1' => array(), + 'male_4' => array(), + 'male_7' => array(), + 'male_9' => array(), + 'male_11' => array(), + 'female_1' => array(), + 'female_4' => array(), + 'female_7' => array(), + 'female_9' => array(), + 'female_11' => array(), + 'projects_1' => array(), + 'projects_4' => array(), + 'projects_7' => array(), + 'projects_9' => array(), + 'projects_11' => array(), + 'students_total' => array(), + 'schools_total' => array(), + 'schools_active' => array(), + 'students_public' => array(), + 'schools_public' => array(), + 'students_private' => array(), + 'schools_private' => array(), + 'schools_districts' => array(), + 'studentsvisiting' => array('manual' => true), + 'publicvisiting' => array('manual' => true), + 'firstnations' => array('manual' => true), + 'students_atrisk' => array(), + 'schools_atrisk' => array(), + 'teacherssupporting' => array('manual' => true), + 'increasedinterest' => array('manual' => true), + 'consideringcareer' => array('manual' => true), + 'committee_members' => array(), + 'judges' => array(), + 'next_chair_name' => array('manual' => true), + 'next_chairemail' => array('manual' => true), + 'next_chair_hphone' => array('manual' => true), + 'next_chair_bphone' => array('manual' => true), + 'next_chair_fax' => array('manual' => true), + 'scholarships' => array('manual' => true), + 'delegate1' => array('manual' => true), + 'delegate2' => array('manual' => true), + 'delegate3' => array('manual' => true), + 'delegate4' => array('manual' => true), + 'delegate1_email' => array('manual' => true), + 'delegate2_email' => array('manual' => true), + 'delegate3_email' => array('manual' => true), + 'delegate4_email' => array('manual' => true), + 'delegate1_size' => array('manual' => true), + 'delegate2_size' => array('manual' => true), + 'delegate3_size' => array('manual' => true), + 'delegate4_size' => array('manual' => true), +); +?> diff --git a/admin/student_editor.php b/admin/student_editor.php index c64abe4..70a1a12 100644 --- a/admin/student_editor.php +++ b/admin/student_editor.php @@ -328,13 +328,13 @@ if($config['participant_student_personal']=="yes") echo " ".i18n("School").""; if( $config['participant_registration_type']=="open" || $config['participant_registration_type']=="singlepassword" || ($studentinfo && !$studentinfo->schools_id) ) { - $schoolq=mysql_query("SELECT id,school FROM schools WHERE year='".$config['FAIRYEAR']."' ORDER by school"); + $schoolq=mysql_query("SELECT id,school,city FROM schools WHERE year='".$config['FAIRYEAR']."' ORDER by city,school"); echo "".REQUIREDFIELD; diff --git a/admin/user_editor_window.php b/admin/user_editor_window.php new file mode 100644 index 0000000..fccd157 --- /dev/null +++ b/admin/user_editor_window.php @@ -0,0 +1,148 @@ + + Copyright (C) 2005 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + array( + 'label' => 'Fair Information', + 'types' => array('fair'), + 'file' => '../fair_info.php', + 'enabled' => true,), + 'personal' => array( + 'label' => 'Personal', + 'types' => array('student','judge','committee','volunteer','sponsor','fair'), + 'file' => '../user_personal.php', + 'enabled' => true), + 'roles' => array( + 'label' => 'Roles/Account', + 'types' => array('student','judge','committee','volunteer','sponsor','fair'), + 'file' => '../user_activate.php', + 'enabled' => true), + 'judgeother' => array( + 'label' => 'Judge Other', + 'types' => array('judge'), + 'file' => '../judge_other.php', + 'enabled' => true), + 'judgeexpertise' => array( + 'label' => 'Expertise', + 'types' => array('judge'), + 'file' => '../judge_expertise.php', + 'enabled' => true), + 'judgeavailability' => array( + 'label' => 'Time Avail.', + 'types' => array('judge'), + 'file' => '../judge_availability.php', + 'enabled' => $config['judges_availability_enable'] == 'yes' ? true : false), + 'judgesa' => array( + 'label' => 'Special Awards', + 'types' => array('judge'), + 'file' => '../judge_special_awards.php', + 'enabled' => true,), + 'volunteerpos' => array( + 'label' => 'Volunteer Positions', + 'types' => array('volunteer'), + 'file' => '../volunteer_position.php', + 'enabled' => true,), + + + ); + + +if(array_key_exists('username',$_GET)) { + $username = $_GET['username']; + $type = $_GET['type']; + $un = mysql_escape_string($username); + $q = mysql_query("SELECT id,MAX(year),deleted FROM users WHERE username='$un' GROUP BY uid"); +echo mysql_error(); + + if(mysql_num_rows($q)) { + $r = mysql_fetch_object($q); + if($r->deleted == 'no') { + echo "Username already exists."; + exit; + } + } + $u = user_create($type, $username); + $u['email'] = $username; + user_save($u); + $id = $u['id']; +} else { + $id = $_GET['id']; +} + +$u = user_load($id); + +$selected = $_GET['tab']; +if(!array_key_exists($selected, $tabs)) { + if(in_array('fair', $u['types']) ) + $selected = 'fairinfo'; + else + $selected = 'personal'; +} + + +send_popup_header(i18n("User Editor").": {$u['name']}"); + +//require_once('../htabs.inc.php'); + +echo '
      '; +foreach($tabs as $k=>$t) { + /* Make sure the tab is enabled */ + if($t['enabled'] == false) continue; + /* Make sure the user has the right type to see the tab */ + $i = array_intersect($t['types'], $u['types']); + if(count($i) == 0) continue; + /* Show the tab */ + $sel = ($selected == $k) ? 'htabs_sel' : ''; + $href = "{$_SERVER['PHP_SELF']}?id=$id&tab=$k"; + echo "
    • ".i18n($t['label'])."
    • "; +} +echo '
    '; +echo ''; + + +$t = $tabs[$selected]; + +/* Setup some things */ +$_SESSION['embed'] = true; +$_SESSION['embed_submit_url'] = "{$_SERVER['PHP_SELF']}?id=$id&tab=$selected"; +$_SESSION['embed_edit_id'] = $id; + +echo '
    '; +include("{$t['file']}"); +echo '
    '; + +unset($_SESSION['embed']); +unset($_SESSION['embed_edit_id']); +unset($_SESSION['embed_submit_url']); + +$icon_path = $config['SFIABDIRECTORY']."/images/16/"; +$icon_exitension = $config['icon_extension']; + + + send_popup_footer(); +?> diff --git a/admin/user_invite.php b/admin/user_invite.php deleted file mode 100644 index 4c27d8c..0000000 --- a/admin/user_invite.php +++ /dev/null @@ -1,136 +0,0 @@ - - Copyright (C) 2005 James Grant - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -?> - 'admin/volunteer.php'); - break; - case 'judge': - $header_data = array('Judges Management' => 'admin/judges.php'); - break; - } - - if($_POST['action']=='confirm' && $email != '') { - $header_data = array_merge($header_data, - array("{$user_what[$type]} Invitations" => "admin/user_invite.php?type=$type")); - send_header("{$user_what[$type]} Confirm", - array_merge(array('Committee Main' => 'committee_main.php', - 'Administration' => 'admin/index.php'), - $header_data) ); - } else { - send_header("{$user_what[$type]} Invitations", - array_merge(array('Committee Main' => 'committee_main.php', - 'Administration' => 'admin/index.php'), - $header_data) ); - } - - $id = intval($_POST['id']); - if($_POST['action']=='confirm' && $id > 0) { - /* Add $type to their types */ - $id = intval($_POST['id']); - $u = user_load($id); - $u = user_create($type, $u); - echo happy(i18n("%1 has been added as a {$user_what[$type]}", - array($email))); - email_send("{$type}_add_invite", $email, - array("FAIRNAME"=>$config['fairname']), - array("FAIRNAME"=>$config['fairname'], - "EMAIL"=>$email)); - } - - - if($_POST['action']=="invite" && $email != '') { - $e = mysql_escape_string($email); - $q = mysql_query("SELECT id,types FROM users WHERE email='$e' OR username='$e'"); - if(mysql_num_rows($q) > 0) { - /* Check the roles */ - $r = mysql_fetch_object($q); - $types = split(',', $r->types); - if(in_array($type, $types)) { - echo notice(i18n("%1 already exists and is already a {$user_what[$type]}", - array($email))); - } else { - echo i18n("%1 already exists with the following roles:", array($email)); - echo '
      '; - foreach($types as $t) { - echo '
    • '.i18n($user_what[$t]).'
    • '; - } - echo '
    '; - echo i18n("Instead of generating a new password and - creating a new account, the role of {$user_what[$type]} - will be added to this account."); - echo "
    "; - echo "\n"; - echo "id}\" />\n"; - echo "\n"; - echo "\n"; - echo "
    \n"; - send_footer(); - exit; - } - } else { - /* They don't exist, create a new account */ - $u = user_create($type); - $u['username'] = $email; - $u['password'] = generatePassword(12); - $u['email'] = $email; - user_save($u); - - email_send("{$type}_new_invite",$email, - array("FAIRNAME"=>$config['fairname']), - array("FAIRNAME"=>$config['fairname'], - "EMAIL"=>$email, - "PASSWORD"=>$u['password'])); - - echo happy(i18n("%1 has been invited to be a {$user_what[$type]}",array($email))); - } - } - - - echo i18n("Enter the {$user_what[$type]} email address to invite them to be a {$user_what[$type]}"); - echo "
    \n"; - echo "
    \n"; - echo "
    \n"; - echo "\n"; - echo i18n("Email").": "; - echo "\n"; - echo "\n"; - echo "
    \n"; - - send_footer(); -?> diff --git a/admin/user_list.php b/admin/user_list.php new file mode 100644 index 0000000..b001ea1 --- /dev/null +++ b/admin/user_list.php @@ -0,0 +1,291 @@ + + Copyright (C) 2005 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + 'committee_main.php', + 'Administration' => 'admin/index.php') + ); +?> + + +"; + echo "- ".i18n('Hide Display Options').""; + + echo "
    "; + + echo "
    "; + echo ""; + $x = 0; + foreach($user_what as $k=>$v ) { + $sel = (in_array($k, $show_types)) ? 'checked="checked"' : ''; + echo ""; + if($x) echo ""; + $x = ~$x; + } + echo ""; + + echo ""; + echo "
    ".i18n('Type').":".i18n($v)."
    ".i18n('Complete').":"; + echo ""; + + echo "
    ".i18n('Year').":"; + echo ""; + echo "
    "; + echo "
    "; + echo ""; + echo "
    "; + echo "
    "; + + echo ""; + + + echo "
    ".i18n('Add New User').""; + echo ''; + echo "
    "; + echo "
    "; + + /* Grab a list of users */ + $w = array(); + foreach($show_types as $t) { + $w [] = "users.types LIKE '%$t%'"; + } + $where_types = "AND (".join(" OR ", $w).")"; + + $where_complete = ""; + if($show_complete == 'yes') { + foreach($show_types as $t) { + $where_complete .= "AND ({$t}_complete='yes' OR {$t}_complete IS NULL) "; + } + } + + if($show_year == 'current') + $where_year = "AND year={$config['FAIRYEAR']}"; + + echo ""; + $querystr="SELECT + * + FROM + users + LEFT JOIN `users_committee` ON `users_committee`.`users_id`=`users`.`id` + LEFT JOIN `users_judge` ON `users_judge`.`users_id`=`users`.`id` + 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` + WHERE + users.deleted='no' + $where_year + $where_types + $where_complete + ORDER BY + lastname ASC, + firstname ASC, + year DESC"; + $q=mysql_query($querystr); + echo mysql_error(); +// echo $querystr; + $num=mysql_num_rows($q); + echo i18n("Listing %1 people total. See the bottom for breakdown of by complete status",array($num)); + + echo mysql_error(); + echo ""; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo " "; + echo ""; + $completeyes=0; + $completeno=0; + while($r=mysql_fetch_assoc($q)) + { + $types = split(',', $r['types']); + $span = count($types) > 1 ? "rowspan=\"".count($types)."\"" : ''; + echo ""; + + echo ""; + + echo ""; + + $first = true; + foreach($types as $t) { + if(!$first) echo ''; + echo ""; + + echo ""; + + echo ""; + + if($first) { + /* Finish off the the first line */ + echo ""; + } + + $first = false; + } + echo ''; + } + + echo "
    ".i18n("Name")."".i18n("Email Address")."".i18n("Year")."".i18n("Type(s)")."".i18n("Active")."".i18n("Complete")."".i18n("Actions")."
    "; + + $name = "{$r['firstname']} {$r['lastname']}"; + if(in_array('fair', $types)) { + $qq = mysql_query("SELECT * FROM users_fair + LEFT JOIN fairs ON fairs.id=users_fair.fairs_id + WHERE users_id='{$r['id']}'"); + $rr = mysql_fetch_assoc($qq); + $name = "{$rr['name']}".((trim($name)=='') ? '' : "
    ($name)"); + } + echo "$name"; + echo "
    {$r['email']}{$r['year']}
    {$user_what[$t]}"; + if($r["{$t}_active"] == 'yes') { + echo "
    ".i18n("yes")."
    "; + } else { + echo "
    ".i18n("no")."
    "; + } + echo "
    "; + if($r["{$t}_complete"] == 'yes') { + echo "
    ".i18n("yes")."
    "; + $completeyes++; + } else { + echo "
    ".i18n("no")."
    "; + $completeno++; + } + echo "
    "; + echo " "; + echo ""; + echo "
    "; + echo i18n("Note: Deleting users from this list is a permanent operation and cannot be undone. Consider editting the user and deactivating or deleting roles in their account instead."); + echo "
    "; + echo "
    "; + echo "$num ".i18n("people listed."); + echo "
    "; + echo "$completeyes ".i18n('complete'); + echo "
    "; + echo "$completeno ".i18n('incomplete'); + echo "
    "; + echo "
    "; + echo "
    "; + + send_footer(); +?> diff --git a/admin/volunteer_positions_manager.php b/admin/volunteer_positions_manager.php index 838b240..5c8f4ee 100644 --- a/admin/volunteer_positions_manager.php +++ b/admin/volunteer_positions_manager.php @@ -47,6 +47,7 @@ $editor->setPrimaryKey("id"); $editor->setDefaultSortField("start,name"); $editor->setRecordType("Volunteer Position"); + $editor->filterList('year',$config['FAIRYEAR']); $editor->execute(); send_footer(); diff --git a/admin/volunteers.php b/admin/volunteers.php index 83f2e9c..f44d9be 100644 --- a/admin/volunteers.php +++ b/admin/volunteers.php @@ -32,11 +32,9 @@ "volunteer_management" ); echo "
    "; - if($config['volunteer_registration_type']=="invite") - { - echo "".i18n("Invite Volunteers")."
    "; - } - echo "".i18n("Volunteer Position Management")."
    "; + echo "".i18n("Volunteer Manager")."
    "; + echo "".i18n("Volunteer Position Management")."
    "; + echo "".i18n("Invite Volunteers")."
    "; send_footer(); diff --git a/admin/winners.php b/admin/winners.php index 249dea6..cbce6c9 100644 --- a/admin/winners.php +++ b/admin/winners.php @@ -28,8 +28,8 @@ user_auth_required('committee', 'admin'); - if($_GET['award_sponsors_id']) $award_sponsors_id=$_GET['award_sponsors_id']; - else if($_POST['award_sponsors_id']) $award_sponsors_id=$_POST['award_sponsors_id']; + if($_GET['sponsors_id']) $sponsors_id=$_GET['sponsors_id']; + else if($_POST['sponsors_id']) $sponsors_id=$_POST['sponsors_id']; if($_GET['award_types_id']) $award_types_id=$_GET['award_types_id']; else if($_POST['award_types_id']) $award_types_id=$_POST['award_types_id']; @@ -274,16 +274,16 @@ else award_awards.name, award_awards.order AS awards_order, award_types.type, - award_sponsors.organization + sponsors.organization FROM award_awards, award_types, - award_sponsors + sponsors WHERE award_awards.year='".$config['FAIRYEAR']."' AND award_awards.award_types_id=award_types.id AND award_types.year='".$config['FAIRYEAR']."' - AND award_awards.award_sponsors_id=award_sponsors.id + AND award_awards.sponsors_id=sponsors.id ORDER BY awards_order"); echo mysql_error(); diff --git a/admin/ysfstats.php b/admin/ysfstats.php index 382b247..a99e6fe 100644 --- a/admin/ysfstats.php +++ b/admin/ysfstats.php @@ -46,7 +46,7 @@ curl_setopt ($ch, CURLOPT_POSTFIELDSIZE, 0); curl_setopt ($ch, CURLOPT_TIMEOUT, 360); curl_setopt ($ch, CURLOPT_SSLVERSION, 3); - curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); $datastream = curl_exec ($ch); /// execute the curl session and return the output to a variable $datastream $datastream = str_replace(" standalone=\"yes\"","",$datastream); // echo "curl close
    "; @@ -234,14 +234,22 @@ $stats["proj910"]=$projs["910"]?$projs["910"]:0; $stats["proj11up"]=$projs["11up"]?$projs["11up"]:0; - $q=mysql_query("SELECT COUNT(id) AS num FROM users WHERE types LIKE '%committee%' AND deleted='no'"); + $q=mysql_query("SELECT COUNT(id) AS num FROM users + WHERE types LIKE '%committee%' + AND year='$year' + AND deleted='no'"); $r=mysql_fetch_object($q); $numcommittee=$r->num; - echo i18n("Committee Members: %1 (note: this is CURRENT number of active committee members as of right now! There is no way to extract committee member numbers from previous years)",array($r->num)); + echo i18n("Committee Members: %1 (note: this is number of committee members who logged in to SFIAB for the year, anyone who was active but didn't log in to SFIAB will NOT be counted)",array($r->num)); echo "
    "; $stats["committee"]=$numcommittee; - $q=mysql_query("SELECT COUNT(id) AS num FROM judges,judges_years WHERE judges_years.judges_id=judges.id AND judges_years.year='$year' AND judges.complete='yes' AND judges.deleted='no'"); + $q=mysql_query("SELECT COUNT(id) AS num FROM users LEFT JOIN users_judge ON users_judge.users_id=users.id + WHERE users.year='$year' + AND users.types LIKE '%judge%' + AND users.deleted='no' + AND users_judge.judge_complete='yes' + AND users_judge.judge_active='yes'"); $r=mysql_fetch_object($q); $numjudges=$r->num; echo i18n("Judges: %1",array($r->num)); diff --git a/committee_main.php b/committee_main.php index 5ac06b9..a91bf8c 100644 --- a/committee_main.php +++ b/committee_main.php @@ -31,18 +31,6 @@ send_header("Committee Main", array()); - switch($_GET['notice']) { - case 'password_changed': - echo happy(i18n('Your password has been successfully updated')); - break; - case 'already_logged_in': - echo error(i18n('You are already logged in, please use the [Logout] link in the upper right to logout')); - break; - case 'no_auth': - echo error(i18n('You do not have permission to view that page')); - break; - } - //only display the named greeting if we have their name echo i18n("Hello %1",array($_SESSION['name'])); echo "
    "; @@ -61,6 +49,7 @@ echo " \n"; echo " ".theme_icon("edit_profile")."
    ".i18n("Edit My Profile")."
    "; echo " ".theme_icon("change_password")."
    ".i18n("Change My Password")."
    "; + echo " ".theme_icon("")."
    ".i18n("Manage My Roles")."
    "; echo " \n"; echo "\n"; diff --git a/committees.php b/committees.php index a21d17d..d3d473f 100644 --- a/committees.php +++ b/committees.php @@ -22,68 +22,56 @@ */ ?> "; $q=mysql_query("SELECT * FROM committees ORDER BY ord,name"); - while($r=mysql_fetch_object($q)) - { - $q2=mysql_query("SELECT - users.id, - users.firstname,users.lastname, - users.email, - users_committee.emailprivate, - users_committee.displayemail, - committees_link.title, - committees_link.ord - FROM - users, users_committee, committees_link - WHERE - users_committee.users_id=users.id - AND committees_link.users_id=users.id - AND committees_link.committees_id='$r->id' - ORDER BY - ord,firstname"); - + while($r=mysql_fetch_object($q)) { + /* Select all the users in the committee, using MAX(year) for the most recent year */ + $q2=mysql_query("SELECT committees_link.*,users.uid,MAX(users.year),users.lastname + FROM committees_link LEFT JOIN users ON users.uid = committees_link.users_uid + WHERE committees_id='{$r->id}' + GROUP BY users.uid ORDER BY ord,users.lastname "); + //if there's nobody in this committee, then just skip it and go on to the next one. if(mysql_num_rows($q2)==0) continue; echo ""; - echo "

    $r->name

    "; + echo "

    {$r->name}

    "; echo "\n"; echo mysql_error(); - while($r2=mysql_fetch_object($q2)) - { + while($r2=mysql_fetch_object($q2)) { + + $uid = $r2->users_uid; + $u = user_load_by_uid($uid); + $output=$config['committee_publiclayout']; $name=$r2->firstname.' '.$r2->lastname; - $output=str_replace("name",$name,$output); + $output=str_replace("name",$u['name'],$output); $output=str_replace("title",$r2->title,$output); //make sure we do emailprivate before email so we dont match the wrong thing - if($r2->emailprivate && $r2->displayemail=='yes') - { - list($b,$a)=split("@",$r2->emailprivate); + if($u['emailprivate'] && $u['displayemail']=='yes') { + list($b,$a)=split("@",$u['emailprivate']); $output=str_replace("emailprivate","",$output); - } - else - $output=str_replace("emailprivate","",$output); + } else + $output=str_replace("emailprivate","",$output); - if($r2->email && $r2->displayemail=='yes') - { - list($b,$a)=split("@",$r2->email); + if($u['email'] && $u['displayemail']=='yes') { + list($b,$a)=split("@",$u['email']); $output=str_replace("email","",$output); - } - else + } else $output=str_replace("email","",$output); - $output=str_replace("phonehome",$r2->phonehome,$output); - $output=str_replace("phonework",$r2->phonework,$output); - $output=str_replace("phonecell",$r2->phonecell,$output); - $output=str_replace("fax",$r2->fax,$output); + $output=str_replace("phonehome",$u['phonehome'],$output); + $output=str_replace("phonework",$u['->phonework'],$output); + $output=str_replace("phonecell",$u['->phonecell'],$output); + $output=str_replace("fax",$u['fax'],$output); echo $output; diff --git a/common.inc.php b/common.inc.php index 8594d5b..a375591 100644 --- a/common.inc.php +++ b/common.inc.php @@ -244,10 +244,6 @@ if($_GET['switchlanguage']) } } -if(!is_array($_SESSION['messages'])) { - $_SESSION['messages'] = array(); -} - function i18n($str,$args=array(),$argsdesc=array(),$forcelang="") { if(!$str) @@ -357,6 +353,15 @@ function happy($str,$type="normal") return "$str
    "; } +function display_messages() +{ + /* Dump any messages in the queue */ + if(is_array($_SESSION['messages'])) { + foreach($_SESSION['messages'] as $m) echo $m; + } + $_SESSION['messages'] = array(); +} + $HEADER_SENT=false; function send_header($title="", $nav=null, $icon=null, $titletranslated=false) { @@ -378,51 +383,9 @@ function send_header($title="", $nav=null, $icon=null, $titletranslated=false) - + + + [".i18n("Logout")."]"; - } else if(isset($_SESSION['registration_id'])) { + if(isset($_SESSION['registration_id'])) { echo i18n('Participant'); echo " {$_SESSION['email']}: "; echo "[".i18n("Logout")."]"; @@ -496,12 +455,14 @@ echo ""; ".i18n("Home Page").''; echo "
  • ".i18n("Important Dates").'
  • '; - echo "
  • ".i18n("Participant Registration").'
  • '; echo $registrationconfirmationlink; - echo "
  • ".i18n("Judges Registration").'
  • '; + /* + echo "
  • ".i18n("Participant Registration").'
  • '; + echo "
  • ".i18n("Judges Registration").'
  • '; if($config['volunteer_enable'] == 'yes') { echo "
  • ".i18n("Volunteer Registration").'
  • '; } + */ echo "
  • ".i18n("Committee").'
  • '; echo "
  • ".i18n("Winners").'
  • '; echo '
'; @@ -509,60 +470,46 @@ echo "";
-
- -
- -
- 1) -{ +if(count($config['languages'])>1) { echo "
"; echo "
"; echo ""); + foreach($config['languages'] as $k=>$lang) { + $sel = ($config['default_language'] == $k) ? 'selected=selected' : ''; + print(""); + } + print(""); + break; default: print("\n"); diff --git a/contact.php b/contact.php index fdb2579..e7732e2 100644 --- a/contact.php +++ b/contact.php @@ -81,32 +81,26 @@ function tochange() { echo ""; + $sel = ($val == 'yes') ? 'selected="selected"' : ''; + echo ""; + $sel = ($val == 'no') ? 'selected="selected"' : ''; + echo ""; + echo ""; + } + + + if($_SESSION['embed'] == true) { + $u = user_load($_SESSION['embed_edit_id']); + } else { + user_auth_required('fair'); + $u = user_load($_SESSION['users_id']); + } + + + if($_POST['action']=="save") + { + $id = $_POST['id']; + if(trim($id) == '') { + $q = mysql_query("INSERT INTO fairs(`id`,`name`) VALUES('','new entry')"); + $id = mysql_insert_id(); + } else { + $id = intval($id); + } + + $name = mysql_escape_string(stripslashes($_POST['name'])); + $abbrv = mysql_escape_string(stripslashes($_POST['abbrv'])); + $url = mysql_escape_string($_POST['url']); + $website = mysql_escape_string($_POST['website']); + $type = array_key_exists($_POST['type'], $fair_type) ? $_POST['type'] : ''; + $username = mysql_escape_string(stripslashes($_POST['username'])); + $password = mysql_escape_string(stripslashes($_POST['password'])); + $enable_stats = ($_POST['enable_stats'] == 'yes') ? 'yes' : 'no'; + $enable_awards = ($_POST['enable_awards'] == 'yes') ? 'yes' : 'no'; + $enable_winners = ($_POST['enable_winners'] == 'yes') ? 'yes' : 'no'; + + $q = mysql_query("UPDATE fairs SET `name`='$name', + `abbrv`='$abbrv', `url`='$url', + `website`='$website', + `type`='$type' , `username`='$username', + `password`='$password', + `enable_stats`='$enable_stats', + `enable_awards`='$enable_awards', + `enable_winners`='$enable_winners' + WHERE id=$id"); + + $u['fairs_id'] = $id; + user_save($u); + message_push(notice(i18n("Fair Informaiton successfully updated"))); + } + +/* update overall status */ +fair_status_update($u); + +if($_SESSION['embed'] != true) { + //output the current status + $newstatus=fair_status_info($u); + if($newstatus!='complete') + message_push(error(i18n("Fair Information Incomplete"))); + else + message_push(happy(i18n("Fair Information Complete"))); +} + +if($_SESSION['embed'] == true) { + echo "
"; + display_messages(); + echo "

".i18n('Fair Information')."

"; + echo "
"; +} else { + //send the header + send_header("Fair Information", + array("Science Fair Main" => "fair_main.php") + ); +} + /* Load the fair info */ + $q = mysql_query("SELECT * FROM fairs WHERE id={$u['fairs_id']}"); + if(mysql_num_rows($q)) { + $f = mysql_fetch_assoc($q); + } else { + $f = array(); + } + + $s = ($_SESSION['embed'] == true) ? $_SESSION['embed_submit_url'] : 'fair_info.php'; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo '"; + echo ''; + echo '
'.i18n('Fair Type').':'; + echo "
'.i18n('Fair Name').':'; + echo ""; + echo '
'.i18n('Fair Abbreviation').':'; + echo ""; + echo '
'.i18n('Fair Website').':'; + if($f['website'] == '') $f['website'] = 'http://'; + echo ""; + echo '
'; + + /* All upstream stuff */ + echo '
'; + echo "\n"; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + /* End upstream stuff */ + echo "
'.i18n('Upstream URL').':'; + if($f['url'] == '') $f['url'] = 'http://'; + echo ""; + echo '
'.i18n('Upstream Username').':'; + echo ""; + echo '
'.i18n('Upstream Password').':'; + echo ""; + echo '
'.i18n('Enable stats upload').':'; + yesno('enable_stats', $f['enable_stats']); + echo '
'.i18n('Enable awards download').':'; + yesno('enable_awards', $f['enable_awards']); + echo '
'.i18n('Enable winners upload').':'; + yesno('enable_winners', $f['enable_winners']); + echo '
"; + + echo i18n('* Use the \'Personal\' tab to specify contact information for someone at this fair.'); + echo '
'; + echo '
'; + echo i18n('* The feeder fair must login to this SFIAB to download award lists + and upload statistics and winners. Use the \'Personal\' tab to specify an + email and password for the feeder fair, use the email address of a contact at + the feeder fair. Then give the email/password to that person so they can configure + their own SFIAB to upload data to this SFIAB.'); echo '
'; + + echo "
"; +echo "\n"; +echo "
"; + + echo "
"; + + + + if($_SESSION['embed'] != true) send_footer(); + +?> + + diff --git a/fair_main.php b/fair_main.php new file mode 100644 index 0000000..8706c53 --- /dev/null +++ b/fair_main.php @@ -0,0 +1,87 @@ + + Copyright (C) 2005 James Grant + Copyright (C) 2007 David Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +Activate Role' button in the Volunteer section below",array($config['FAIRYEAR'],$config['fairname'])))); + header('Location: user_activate.php'); + exit; + } + */ + send_header("Science Fair Main", array()); + + //only display the named greeting if we have their name + echo i18n("Hello %1",array($_SESSION['name'])); + echo "
"; + echo "
"; + + echo i18n("Please use the checklist below to complete your data. Click on an item in the table to edit that information. When you have entered all information, the Status field will change to Complete"); + echo "
"; + echo "
"; + + user_page_summary_begin(); + user_page_summary_item("Contact Information", + "user_personal.php", "user_personal_info_status", array($u)); + user_page_summary_item("Volunteer Positions", + "fair_info", "fair_status_info", array($u)); + $overallstatus = user_page_summary_end(true); + + /* Update fair_status */ + fair_status_update($u); + + echo "
"; + echo "
"; + + /* + if($overallstatus!='complete') + { + echo error(i18n("You will not be marked as an active fair until your \"Overall Status\" is \"Complete\"")); + } + else + { + echo happy(i18n("Thank you for completing the fair registration process. We look forward to seeing you at the fair")); + } + */ + echo "
"; + echo i18n('Other Options and Things To Do').':
'; + echo ''; + + send_footer(); +?> diff --git a/htabs.inc.php b/htabs.inc.php new file mode 100644 index 0000000..e601ff5 --- /dev/null +++ b/htabs.inc.php @@ -0,0 +1,79 @@ + + +"; + foreach($tabs as $t=>$d) { + $sel = ($t == $selected) ? 'class=\"htabs_sel\"' : ''; + echo "
  • ".i18n($d['label']).'
  • '; + $tabs[$t]['selected'] = false; + } + echo ''; + /* Force the upcoming divs below this UL */ + echo ''; + $tabs[$selected]['selected'] = true; + $htabs_current = $name; + $htabs_tabs = $tabs; +} + +function htabs_tab_begin($tab) +{ + global $htabs_current, $htabs_tabs; + echo "
    "; + echo '

    '.i18n($htabs_tabs[$tab]['title']).'

    '; + echo "
    "; + +} +function htabs_tab_end() +{ + echo '
    '; +} + +function htabs_end() +{ + global $htabs_current, $htabs_tabs; + $default = ''; + $first = ''; + echo ''; + $htabs_current = ""; + $htabs_tabs = array(); +} +?> diff --git a/important_dates.php b/important_dates.php index 40dadd2..8715316 100644 --- a/important_dates.php +++ b/important_dates.php @@ -31,11 +31,10 @@ while($r=mysql_fetch_object($q)) { $trclass = ($trclass == 'odd') ? 'even' : 'odd'; - if($r->date == '0000-00-00 00:00:00') - $d = i18n("not specified"); - else + if($r->date != '0000-00-00 00:00:00') { $d = format_datetime($r->udate); - echo "".i18n($r->description)."$d"; + echo "".i18n($r->description)."$d"; + } } echo ""; diff --git a/install3.php b/install3.php index 6856283..179c918 100644 --- a/install3.php +++ b/install3.php @@ -141,7 +141,7 @@ if($_POST['action']=="save") echo "Done!
    "; echo "Creating superuser account..."; - $u = user_create('committee'); + $u = user_create('committee',$_POST['email']); if($_POST['firstname'] && $_POST['lastname']) { $u['firstname']=mysql_escape_string(stripslashes($_POST['firstname'])); $u['lastname']=mysql_escape_string(stripslashes($_POST['lastname'])); diff --git a/judge.class.php b/judge.class.php deleted file mode 100644 index 4b937fa..0000000 --- a/judge.class.php +++ /dev/null @@ -1,392 +0,0 @@ - 'First Name', - 'lastname' => 'Last Name', - 'email' => 'Email Address', - 'password' => 'Password', - 'passwordexpiry' => 'Password Expiry', - 'phonehome' => 'Phone (Home)', - 'phonecell' => 'Phone (Cell)', - 'phonework' => 'Phone (Work)', - 'phoneworkext' => 'Phone Ext. (Work)', - 'organization' => 'Organization', -// 'created' => 'Created', -// 'lastlogin' => 'Last Login', - 'address' =>"Address 1", - 'address2' =>"Address 2", - 'city' => 'City', - 'province' => $config['provincestate'], - 'postalcode' => $config['postalzip'], -// 'deleted' => 'Deleted', -// 'deleteddatetime' => 'Deleted Date/Time', - 'expertise_other' => 'Other Expertise/Notes', - 'typepref' => 'Type Request', - 'complete' => "Complete"); - - /* Setup the table editor with the fields we want to display - * when displaying a list of judges, and also the type of each - * field where required */ -$judges_table_fields = array( 'id' => 'ID', - 'firstname' => 'First Name', - 'lastname' => 'Last Name', - 'email' => 'Email Address', - 'complete' => 'Complete', -// 'year' => 'Year', - ); - - -class person { - var $id; - -function person($person_id=NULL) -{ - if($person_id == NULL) { -// print("Empty constructor called\n"); - $this->id = FALSE; - } else { -// print("ID $person_id construction called\n"); - $this->id = $person_id; - } -} -}; - - -class judge extends person /*implements TableEditorInterface*/ { - -/* Static members for the table editor */ -function tableEditorSetup($editor) -{ - global $judges_fields, $judges_table_fields; - global $config; - - $cat = array(); - $catf = array(); - $q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id"); - while($r=mysql_fetch_object($q)) { - $cat[$r->id]=$r->category; - $catf["catpref_{$r->id}"] = "Category Pref|{$r->category}:"; - } - - $div = array(); - $diff = array(); - $q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY id"); - while($r=mysql_fetch_object($q)) { -// $divshort[$r->id]=$r->division_shortform; - $div[$r->id]=$r->division; - /* yes, catf */ - $catf["divpref_{$r->id}"] = "Expertise|{$r->division}:"; - } - - $q = mysql_query("SELECT * FROM award_awards WHERE year='{$config['FAIRYEAR']}' - AND (award_types_id=2 OR award_types_id=5) ORDER BY id"); - while($r=mysql_fetch_object($q)) { -// $divshort[$r->id]=$r->division_shortform; - $sa[$r->id]=$r->name; - /* yes, catf */ - $catf["sa_{$r->id}"] = "Special Award|{$r->name}:"; - } - - - - - /* Most of these should be moved to the base class, as they - * will be the same for all person groups */ - $e = array_merge($judges_fields, - array( 'language' => 'Language(s)', - )); - $e = array_merge($e, $catf); - - $editor->setTable('judges'); - $editor->setRecordType('Judge'); - $editor->setListFields($judges_table_fields); - $editor->setEditFields($e); - - $editor->setFieldOptions('complete', array( - array('key' => 'yes', 'val' => 'Yes'), - array('key' => 'no', 'val' => 'No'))); - $editor->setFieldOptions('year', array( - array('key' => 'NULL', 'val' => 'Inactive'), - array('key' => $config['FAIRYEAR'], 'val' => $config['FAIRYEAR']))); - -// print_r($e); - print("
    \n"); - /* Build an array of langauges that we support */ - $langs = array(); - $q=mysql_query("SELECT * FROM languages WHERE active='Y'"); - while($r=mysql_fetch_object($q)) { - $langs[$r->lang] = $r->langname; - } - $editor->setFieldOptions('language', $langs); - $editor->setFieldInputType('language', 'multicheck'); - - - /* Pulled these out of register_judges.inc.php */ - $preferencechoices=array( - array('key' => -2, 'val' => "Very Low"), - array('key' => -1, 'val' => "Low"), - array('key' => 0, 'val' => "Indifferent"), - array('key' => 1, 'val' => "Medium"), - array('key' => 2, 'val' => "High") ); - - foreach($cat as $cid=>$category) { - $editor->setFieldOptions("catpref_$cid", $preferencechoices); - $editor->setFieldInputType("catpref_$cid", 'select'); - } - $expertisechoices=array( - array('key' => 1, 'val' => "(1) Low"), - array('key' => 2, 'val' => "(2) Med-Low"), - array('key' => 3, 'val' => "(3) Medium"), - array('key' => 4, 'val' => "(4) Med-High"), - array('key' => 5, 'val' => "(5) High") ); - - foreach($div as $did=>$division) { - $editor->setFieldOptions("divpref_$did", $expertisechoices); - $editor->setFieldInputType("divpref_$did", 'select'); - } - - if(count($sa)) { - foreach($sa as $said=>$special_award) { - $editor->setFieldOptions("sa_$said", array( - array('key' => 'yes', 'val' => 'Would like to judge'), - array('key' => '', 'val' => ''))); - $editor->setFieldInputType("sa_$said", 'select'); - } - } - - $editor->setFieldOptions('typepref', array( - array('key' => 'speconly', 'val' => 'Special Award Judge Only'), - array('key' => '', 'val' => 'Regular Judge'))); - $editor->SetFieldInputType('typepref', 'select'); - - - $editor->createOption('judges_show_what'); -} - -/* STATIC */ -function tableEditorGetList($editor) -{ - //return $editor->defaultGetList(); - global $config; - global $judges_table_fields; - - $show_what = $editor->getOption('judges_show_what'); - - $sel = array_keys($judges_table_fields); - $from = array('judges'); - $where = array(); - - switch($show_what) { - case "all": -// $editor->additionalListTableLeftJoin("judges_years", "judges_years.judges_id=judges.id"); -// $editor->filterList("(judges_years.year={$config['FAIRYEAR']} OR judges_years.year IS NULL)"); - break; - case "current_year_active": - $from[] = "LEFT JOIN `judges_years` ON judges_years.judges_id=judges.id"; - $where[] = "judges_years.year={$config['FAIRYEAR']}"; - break; - case "current_year_complete": - $from[] = "LEFT JOIN `judges_years` ON judges_years.judges_id=judges.id"; - $where[] = "judges_years.judges_id=judges.id"; - $where[] = "judges_years.year={$config['FAIRYEAR']}"; - $where[] = "judges.complete='yes'"; - break; - } - //only show non-deleted judges - $where[] = "judges.deleted='no'"; - - return array($sel, $from, $where); -} - - - -/* Functions for $this */ - - -function judge($judge_id=NULL) -{ - global $judges_fields; - person::person($judge_id); -} - -function tableEditorLoad() -{ - global $config; - - $id = $this->id; - -// print("Loading Judge ID $id\n"); - - $q=mysql_query("SELECT judges.* - FROM judges - WHERE judges.id='$id'"); - echo mysql_error(); - - - /* We assume that the field names in the array we want to return - * are the same as those in the database, so we'll turn the entire - * query into a single associative array */ - $j = mysql_fetch_assoc($q); - - /* Now turn on the ones this judge has selected */ - $q=mysql_query("SELECT languages_lang - FROM judges_languages - WHERE judges_id='$id'"); - $j['language'] = array(); - if(mysql_num_rows($q)) { - while($r=mysql_fetch_object($q)) { - $j['language'][$r->languages_lang] = 1; - } - } - - $q=mysql_query("SELECT * - FROM judges_catpref - WHERE judges_id='$id' - AND year='{$config['FAIRYEAR']}'"); - if(mysql_num_rows($q)) { - while($r=mysql_fetch_object($q)) { - $j["catpref_{$r->projectcategories_id}"] = $r->rank; - } - } - $q=mysql_query("SELECT * - FROM judges_expertise - WHERE judges_id='$id' - AND year='{$config['FAIRYEAR']}'"); - if(mysql_num_rows($q)) { - while($r=mysql_fetch_object($q)) { - $j["divpref_{$r->projectdivisions_id}"] = $r->val; - } - } - - $q=mysql_query("SELECT * - FROM judges_specialaward_sel - WHERE judges_id='$id' - AND year='{$config['FAIRYEAR']}'"); - if(mysql_num_rows($q)) { - while($r=mysql_fetch_object($q)) { - $j["sa_{$r->award_awards_id}"] = 'yes'; - } - } - -// print_r($j); - - return $j; -} - -function tableEditorSave($data) -{ - /* If $this->id == false, then we need to INSERT a new record. - * if it's a number, then we want an UPDATE statement */ - global $judges_fields; - global $config; - - $query = ""; - - /* Construct an insert query if we have to */ - if($this->id == false) { - $query = "INSERT INTO judges (id) VALUES ('')"; - mysql_query($query); - $this->id = mysql_insert_id(); - } - - /* Now just update the record */ - $query="UPDATE `judges` SET "; - - foreach($judges_fields AS $f=>$n) { - $n = $data[$f]; - $query .= "`$f`=$n,"; - } - //rip off the last comma - $query=substr($query,0,-1); - - $query .= " WHERE id='{$this->id}'"; - -// echo $query; - mysql_query($query); - - - /* judges_languages */ - /* First delete all the languages, then insert the ones the judge - * has selected */ - $query = "DELETE FROM judges_languages WHERE judges_id='{$this->id}'"; - mysql_query($query); - -// print_r($data['language']); - $keys = array_keys($data['language']); - foreach($keys as $k) { - $query = "INSERT INTO - judges_languages (judges_id,languages_lang) - VALUES ('{$this->id}','$k')"; -// print("$query"); - mysql_query($query); - } - - /* judges_catpref */ - $query = "DELETE FROM judges_catpref WHERE judges_id='{$this->id}'"; -// print($query); - mysql_query($query); - - /* Find all the catpref_[number] keys */ - $keys = array_keys($data); - foreach($keys as $k) { - if(ereg("^catpref_([0-9]*)$", $k, $regs)) { - if($data[$k] == "''") continue; - $query = "INSERT INTO judges_catpref - (judges_id,projectcategories_id,rank,year) - values ('{$this->id}','{$regs[1]}',{$data[$k]},'{$config['FAIRYEAR']}')"; -// print($query."
    \n"); - mysql_query($query); - - } - } - /* Find all the divpref_[number] keys */ - $query = "DELETE FROM judges_expertise WHERE judges_id='{$this->id}'"; -// print($query); - mysql_query($query); - $keys = array_keys($data); - foreach($keys as $k) { - if(ereg("^divpref_([0-9]*)$", $k, $regs)) { - if($data[$k] == "''") continue; - $query = "INSERT INTO judges_expertise - (judges_id,projectdivisions_id,val,year) - values ('{$this->id}','{$regs[1]}',{$data[$k]},'{$config['FAIRYEAR']}')"; -// print($query."
    \n"); - mysql_query($query); - - } - } - - $query = "DELETE FROM judges_specialaward_sel WHERE judges_id='{$this->id}'"; - mysql_query($query); - $keys = array_keys($data); - foreach($keys as $k) { - if(ereg("^sa_([0-9]*)$", $k, $regs)) { - if($data[$k] == "''") continue; - $query = "INSERT INTO judges_specialaward_sel - (judges_id,award_awards_id,year) - values ('{$this->id}','{$regs[1]}','{$config['FAIRYEAR']}')"; -// print($query."
    \n"); - mysql_query($query); - } - } -} - -function tableEditorDelete() -{ - global $config; - - $id = $this->id; - - mysql_query("DELETE FROM judges_teams_link WHERE judges_id='$id' AND year=".$config['FAIRYEAR']."'"); - mysql_query("DELETE FROM judges_years WHERE judges_id='$id' AND year='".$config['FAIRYEAR']."'"); - mysql_query("UPDATE judges SET deleted='yes', deleteddatetime=NOW() WHERE id='$id'"); - - echo happy(i18n("Successfully deleted the judge")); -} - - - - -}; - -?> diff --git a/judge.inc.php b/judge.inc.php new file mode 100644 index 0000000..47cdb3d --- /dev/null +++ b/judge.inc.php @@ -0,0 +1,135 @@ + + Copyright (C) 2005 James Grant + Copyright (C) 2009 David Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +"Very Low", + -1=>"Low", + 0=>"Indifferent", + 1=>"Medium", + 2=>"High" +); + +function judge_status_expertise(&$u) +{ + global $config; + + /* If the judging special awards are active, and the judge has + * selected "I am a special awards judge", then disable + * expertise checking */ + if($config['judges_specialaward_only_enable'] == 'yes') { + if($u['special_award_only'] == 'yes') + return 'complete'; + } + + /* Check to see if they have ranked all project age categories, and all divisions */ + $q=mysql_query("SELECT COUNT(id) AS num FROM projectcategories WHERE year='".$config['FAIRYEAR']."'"); + $r=mysql_fetch_object($q); + $numcats=$r->num; + if($numcats != count($u['cat_prefs'])) return 'incomplete'; + + $q=mysql_query("SELECT COUNT(id) AS num FROM projectdivisions WHERE year='".$config['FAIRYEAR']."'"); + $r=mysql_fetch_object($q); + $numdivisions=$r->num; + if($numdivisions != count($u['div_prefs'])) return 'incomplete'; + + return 'complete'; +} + +function judge_status_other(&$u) +{ + global $config; + + /* They must select a language to judge in */ + if(count($u['languages']) < 1) return 'incomplete'; + + return 'complete'; +} + + + +function judge_status_special_awards(&$u) +{ + global $config; + + /* Complete if: + * - judge has selected (none) "no special award preferences" + * - judge has selected between min and max preferences + */ + + $qq = mysql_query("SELECT COUNT(id) AS num FROM judges_specialaward_sel + WHERE users_id='{$u['id']}'"); + $rr = mysql_fetch_object($qq); + $awards_selected = $rr->num; +// echo "$awards_selected awards selected, ({$config['judges_specialaward_min']} - {$config['judges_specialaward_max']})"; + + if($u['special_award_only'] == 'yes') { + /* Judge for special award */ + /* They may judge more than one award, so don't limit them + * to one */ + if($awards_selected >= 1) return 'complete'; + return 'incomplete'; + } + + if( ($awards_selected >= $config['judges_specialaward_min']) + &&($awards_selected <= $config['judges_specialaward_max']) ){ + return 'complete'; + } + + return 'incomplete'; +} + +function judge_status_availability(&$u) +{ + global $config; + if($config['judges_availability_enable'] == 'no') return 'complete'; + + $q = mysql_query("SELECT id FROM judges_availability + WHERE users_id=\"{$u['id']}\""); + if(mysql_num_rows($q) > 0) return 'complete'; + + return 'incomplete'; +} + +function judge_status_update(&$u) +{ + global $config; + + if( user_personal_info_status($u) == 'complete' + && judge_status_expertise($u) == 'complete' + && judge_status_other($u) == 'complete' + && judge_status_availability($u) == 'complete' + && judge_status_special_awards($u) == 'complete') + $u['judge_complete'] = 'yes'; + else + $u['judge_complete'] = 'no'; + + user_save($u); + return ($u['judge_complete'] == 'yes') ? 'complete' : 'incomplete'; + +} + + +?> diff --git a/judge_availability.php b/judge_availability.php new file mode 100644 index 0000000..cd25455 --- /dev/null +++ b/judge_availability.php @@ -0,0 +1,140 @@ + + Copyright (C) 2005 James Grant + Copyright (C) 2009 David Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + $t) { + if($t['date'] == $r->date && $t['starttime'] == $r->starttime && $t['endtime'] == $r->endtime) { + $times[$xx]['name'] .= ", {$r->name}"; + $found = true; + break; + } + } + if(!$found) { + $times[$x] = array( 'date' => $r->date, + 'starttime' => $r->starttime, + 'endtime' => $r->endtime, + 'name' => $r->name); + $x++; + } +} + +if($_POST['action']=='save') { + mysql_query("DELETE FROM judges_availability WHERE users_id='{$u['id']}'"); + + if(is_array($_POST['time']) ) { + foreach($_POST['time'] as $x) { + if(trim($times[$x]['starttime']) == '') continue; + + mysql_query("INSERT INTO judges_availability (users_id, `date`,`start`,`end`) + VALUES ('{$u['id']}', + '{$times[$x]['date']}', + '{$times[$x]['starttime']}','{$times[$x]['endtime']}')"); + } + } + message_push(notice(i18n("Time Availability preferences successfully saved"))); +} + +if($_SESSION['embed'] == true) { + echo "
    "; + display_messages(); + echo "

    ".i18n('Time Availability')."

    "; + echo "
    "; +} else { + //send the header + send_header('Time Availability', + array('Judge Registration' => 'judge_main.php') + ); +} + +judge_status_update($u); + +if($_SESSION['embed'] != true) { + //output the current status + $newstatus=judge_status_availability($u); + if($newstatus!='complete') + echo error(i18n("Time Availability Preferences Incomplete")); + else + echo happy(i18n("Time Availability Preferences Complete")); +} + +$url = ($_SESSION['embed'] == true) ? $_SESSION['embed_submit_url'] : 'judge_availability.php'; +echo "
    \n"; + +echo "\n"; + +echo "
    "; + +/* Get all their available times */ +$q = mysql_query("SELECT * FROM judges_availability WHERE users_id=\"{$u['id']}\" ORDER BY `start`"); + +$sel = array(); +while($r=mysql_fetch_object($q)) { + foreach($times as $x=>$t) { + if($r->start == $t['starttime'] && $r->end == $t['endtime'] && $r->date == $t['date']) { + $sel[$x] = true; + } + } +} + +echo "\n"; +foreach($times as $x=>$t) { + $ch = $sel[$x] == true ? 'checked="checked"' : ''; + echo ""; + echo ""; + echo ""; +} + +echo "
    "; + echo ""; + $st = substr($t['starttime'], 0, 5); + $end = substr($t['endtime'], 0, 5); + echo "{$times[$x]['date']} $st - $end

    {$t['name']}

    "; +echo "
    "; +echo "
    "; + +echo "\n"; +echo "
    "; + +if($_SESSION['embed'] != true) send_footer(); + +?> diff --git a/register_judges_expertise.php b/judge_expertise.php similarity index 50% rename from register_judges_expertise.php rename to judge_expertise.php index d992421..e7e5616 100644 --- a/register_judges_expertise.php +++ b/judge_expertise.php @@ -22,88 +22,87 @@ */ ?> << ".i18n("Back to Judges Registration Summary")."
    "; - echo "
    "; - if($_POST['action']=="save") { - //first delete all their old associations for this year.. - mysql_query("DELETE FROM judges_expertise WHERE judges_id='".$_SESSION['judges_id']."' AND year='".$config['FAIRYEAR']."'"); - if(!is_array($_POST['division'])) $_POST['division']=array(); if(!is_array($_POST['subdivision'])) $_POST['subdivision']=array(); + $u['div_prefs'] = array(); foreach($_POST['division'] AS $key=>$val) - { - mysql_query("INSERT INTO judges_expertise (judges_id, projectdivisions_id, val, year) VALUES ('".$_SESSION['judges_id']."','$key','$val','".$config['FAIRYEAR']."')"); - } + $u['div_prefs'][$key] = $val; + $u['div_prefs_sub'] = array(); foreach($_POST['subdivision'] AS $key=>$val) - { - mysql_query("INSERT INTO judges_expertise (judges_id, projectsubdivisions_id, val, year) VALUES ('".$_SESSION['judges_id']."','$key','$val','".$config['FAIRYEAR']."')"); - } + $u['div_prefs_sub'][$key] = $val; if($_POST['expertise_other']) - { - mysql_query("UPDATE judges SET expertise_other='".mysql_escape_string(stripslashes($_POST['expertise_other']))."' WHERE id='".$_SESSION['judges_id']."'"); + $u['expertise_other'] = stripslashes($_POST['expertise_other']); + else + $u['expertise_other'] = NULL; - } - else - { - mysql_query("UPDATE judges SET expertise_other=NULL WHERE id='".$_SESSION['judges_id']."'"); - } + $u['cat_prefs'] = array(); + if(is_array($_POST['catpref'])) { + foreach($_POST['catpref'] AS $k=>$v) { + if($v == '') continue; - mysql_query("DELETE FROM judges_catpref WHERE judges_id='".$_SESSION['judges_id']."'"); - - if(is_array($_POST['catpref'])) - { - foreach($_POST['catpref'] AS $k=>$v) - { - if($v!="") - mysql_query("INSERT INTO judges_catpref (judges_id,projectcategories_id,rank,year) values ('".$_SESSION['judges_id']."','$k','$v','".$config['FAIRYEAR']."')"); + $u['cat_prefs'][$k] = $v; } } - - echo notice(i18n("Preferences successfully saved")); + user_save($u); + message_push(notice(i18n("Preferences successfully saved"))); + $u = user_load($u['id']); } - $q=mysql_query("SELECT * FROM judges WHERE email='".$_SESSION['email']."' AND id='".$_SESSION['judges_id']."'"); - $judgeinfo=mysql_fetch_object($q); - updateJudgeCompleteStatus($judgeinfo); -//output the current status -$newstatus=expertiseStatus(); -if($newstatus!="complete") -{ - echo error(i18n("Divisional Judging Information Incomplete")); -} -else -{ - echo happy(i18n("Divisional Judging Information Complete")); + if($_SESSION['embed'] == true) { + echo "
    "; + display_messages(); +// echo "

    ".i18n('Category and Division Preferences')."

    "; + echo "
    "; + } else { + //send the header + send_header('Category and Division Preferences', + array('Judge Registration' => 'judge_main.php') + ); + } + +judge_status_update($u); + +if($_SESSION['embed'] != true) { + //output the current status + $newstatus=judge_status_expertise($u); + if($newstatus!="complete") + echo error(i18n("Divisional Judging Information Incomplete")); + else + echo happy(i18n("Divisional Judging Information Complete")); } - if($judgeinfo->typepref == "speconly") { + if($u['special_award_only'] == 'yes') { echo i18n("You have specified that you are a judge for a specific special award. Divisional Judging preferences have been disabled because they do not apply to you."); echo "
    "; send_footer(); exit; } - echo "
    \n"; +if($_SESSION['embed'] == true) { + echo "\n"; +} else { + echo "\n"; +} echo "\n"; - $q=mysql_query("SELECT * FROM judges_catpref WHERE judges_id='".$_SESSION['judges_id']."' AND year='".$config['FAIRYEAR']."'"); - $catprefs=array(); - while($r=mysql_fetch_object($q)) - $catprefs[$r->projectcategories_id]=$r->rank; - $q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY mingrade"); echo "

    ".i18n("Age Category Preferences")."


    "; echo ""; @@ -117,7 +116,10 @@ else echo "\n"; foreach($preferencechoices AS $val=>$str) { - if($catprefs[$r->id]==$val && $catprefs[$r->id]!="") $sel="selected=\"selected\""; else $sel=""; + if($u['cat_prefs'][$r->id]==$val && $u['cat_prefs'][$r->id]!="") + $sel="selected=\"selected\""; + else + $sel=""; echo "\n"; } echo "".REQUIREDFIELD; @@ -140,49 +142,42 @@ else echo "
    "; echo "
    "; - $q=mysql_query("SELECT * FROM judges_expertise WHERE judges_id='".$_SESSION['judges_id']."' AND year='".$config['FAIRYEAR']."'"); - while($r=mysql_fetch_object($q)) - { - if($r->projectdivisions_id) - $expertise[$r->projectdivisions_id]=$r->val; - else if($r->projectsubdivisions_id) - $subexpertise[$r->projectsubdivisions_id]=$r->val; - } // echo "
    \n"; //query all of the categories $q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY division"); - while($r=mysql_fetch_object($q)) - { - echo ""; - echo ""; - for($x=1;$x<=5;$x++) - echo ""; - echo ""; - echo ""; + $first = true; + while($r=mysql_fetch_object($q)) { - echo ""; + $trclass = ($trclass == 'odd') ? 'even' : 'odd'; + if($first == true) { + echo ""; + echo ""; + for($x=1;$x<=5;$x++) + echo ""; + echo ""; + echo ""; + $first = false; + } - for($x=1;$x<=5;$x++) - { - if($expertise[$r->id]==$x) $sel="checked=\"checked\""; else $sel=""; + echo ""; + for($x=1;$x<=5;$x++) { + $sel = ($u['div_prefs'][$r->id]==$x) ? "checked=\"checked\"" : ''; echo ""; } echo ""; echo ""; //only show the sub-divisions if the 'main' division is scored >=3 - if($expertise[$r->id]>=3) - { + if($u['div_prefs'][$r->id]>=3) { $subq=mysql_query("SELECT * FROM projectsubdivisions WHERE projectdivisions_id='$r->id' AND year='".$config['FAIRYEAR']."' ORDER BY subdivision"); - while($subr=mysql_fetch_object($subq)) - { + while($subr=mysql_fetch_object($subq)) { echo ""; echo ""; - if($subexpertise[$subr->id]) $ch="checked=\"checked\""; else $ch=""; + $ch = ($u['div_prefs_sub'][$subr->id]) ? "checked=\"checked\"" : ''; echo ""; echo ""; } } - - echo ""; - } echo "
    ".i18n("Novice")."".i18n("Expert")."
    $x
    ".i18n($r->division)."
    ".i18n("Novice")."".i18n("Expert")."
    $x
    ".i18n($r->division)."id]\" value=\"$x\" />
     id]\" value=\"1\" />"; @@ -191,24 +186,18 @@ else echo "
     
    "; echo "
    "; echo "

    ".i18n("Other Areas of Expertise not listed above")."

    "; - $q=mysql_query("SELECT expertise_other FROM judges WHERE id='".$_SESSION['judges_id']."'"); - $judgeinfo=mysql_fetch_object($q); - echo ""; + echo ""; echo "
    "; echo "
    "; echo "\n"; echo "
    "; - echo "
    "; - echo "<< ".i18n("Back to Judges Registration Summary")."
    "; - send_footer(); + if($_SESSION['embed'] != true) send_footer(); + ?> diff --git a/judge_main.php b/judge_main.php new file mode 100644 index 0000000..8c075d4 --- /dev/null +++ b/judge_main.php @@ -0,0 +1,102 @@ + + Copyright (C) 2005 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +Activate Role' button in the Judge section below",array($config['FAIRYEAR'],$config['fairname'])))); + header('Location: user_activate.php'); + exit; + } + + send_header("Judge Registration", array()); + + + //only display the named greeting if we have their name + if($u['firstname']) { + echo i18n("Hello %1",array($u['firstname'])); + echo "
    "; + } + echo "
    "; + + //first, we need to see if they havec the current FAIRYEAR activated, if not, we'll keep their acocunt 'dormant' and it wont + //be used for anything, but will still be available for them to login in the following years. + + + echo i18n("Please use the checklist below to complete your data. Click on an item in the table to edit that information. When you have entered all information, the Status field will change to Complete"); + echo "
    "; + echo "
    "; + + $overallstatus="complete"; + + user_page_summary_begin(); + user_page_summary_item("Contact Information", + "user_personal.php", "user_personal_info_status", array($u)); + user_page_summary_item("Other Information", + "judge_other.php", "judge_status_other", array($u)); + user_page_summary_item("Areas of Expertise", + "judge_expertise.php", "judge_status_expertise", array($u)); + + if($config['judges_availability_enable'] == 'yes') { + user_page_summary_item("Time Availability", + "judge_availability.php", "judge_status_availability", array($u)); + } + + if($config['judges_specialaward_enable'] == 'yes' || $u['special_award_only'] == 'yes') { + user_page_summary_item("Special Award Preferences", + "judge_special_awards.php", "judge_status_special_awards", array($u)); + } +// user_page_summary_item("Areas of Expertise", + // "register_judges_expertise.php", "expertiseStatus", array($u)); + + $overallstatus = user_page_summary_end(true); + + judge_status_update($u); + echo '

    '; + + if($overallstatus!="complete") + echo error(i18n("You will not be marked as an active judge until your \"Overall Status\" is \"Complete\"")); + else + echo happy(i18n("Thank you for completing the judge registration process. We look forward to seeing you at the fair")); + + echo "
    "; + + echo i18n('Other Options and Things To Do').':
    '; + echo ''; + + send_footer(); +?> diff --git a/judge_other.php b/judge_other.php new file mode 100644 index 0000000..39dab79 --- /dev/null +++ b/judge_other.php @@ -0,0 +1,158 @@ + + Copyright (C) 2005 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +"; + display_messages(); + echo "

    ".i18n('Other Information')."

    "; + echo "
    "; + } else { + //send the header + send_header('Other Information', + array('Judge Registration' => 'judge_main.php') + ); + } + +judge_status_update($u); + + +if($_SESSION['embed'] != true) { + //output the current status + $newstatus=judge_status_other($u); + if($newstatus!="complete") + echo error(i18n("Other Information Incomplete")); + else + echo happy(i18n("Other Information Complete")); +} + + +if($_SESSION['embed'] == true) { + echo "
    \n"; +} else { + echo "\n"; +} + echo "\n"; + + echo "\n"; + +echo "\n"; +echo " "; +echo " \n"; +echo "\n"; + + +if($config['judges_specialaward_only_enable'] == 'yes') { + echo ""; + echo "\n"; + echo " "; + $ch = ($u['special_award_only'] == 'yes') ? 'checked="checked"' : ''; + echo " "; + echo "\n"; +} + +echo ""; + +echo "\n"; +echo " "; +echo " \n"; +echo "\n"; +echo "\n"; +echo " "; +echo " \n"; +echo "\n"; +echo "\n"; +echo " "; +echo " \n"; +echo "\n"; +echo "\n"; +echo " "; +$ch = ($u['willing_chair'] == 'yes') ? 'checked="checked"' : ''; +echo " \n"; + +echo "\n"; +echo " "; +echo " \n"; +echo "\n"; + +echo ""; + +questions_print_answer_editor('judgereg', $u, 'questions'); + + +echo "
    ".i18n("I can judge in the following languages")." ".REQUIREDFIELD.""; + +$q=mysql_query("SELECT * FROM languages WHERE active='Y' ORDER BY langname"); +echo mysql_error(); +while($r=mysql_fetch_object($q)) +{ + $ch = (in_array($r->lang,$u['languages'])) ? 'checked="checked"' : ''; + + echo "lang\" /> $r->langname
    "; +} + +echo "

    ".i18n("I am a judge for a specific special award")."
    (".i18n("Check this box if you are supposed to judge a specific special award, and please select that award on the Special Award Preferences page.").")
    "; + echo "

    ".i18n("Years of judging experience at a School level:")."
    ".i18n("Years of judging experience at a Regional level:")."
    ".i18n("Years of judging experience at a National level:")."
    ".i18n("I am willing to be the lead for my judging team").""; +echo "
    ".i18n("Highest post-secondary degree")."

    "; + echo "
    "; + echo "
    "; + + echo "\n"; + echo "
    "; + + + if($_SESSION['embed'] != true) send_footer(); +?> diff --git a/register_judges_specialawards.php b/judge_special_awards.php similarity index 56% rename from register_judges_specialawards.php rename to judge_special_awards.php index 39300eb..dab6f85 100644 --- a/register_judges_specialawards.php +++ b/judge_special_awards.php @@ -22,47 +22,60 @@ */ ?> << ".i18n("Back to Judges Registration Summary")."
    "; - echo "
    "; + if($_SESSION['embed'] == true) { + $u = user_load($_SESSION['embed_edit_id']); + } else { + $u = user_load($_SESSION['users_id']); + } - if($_POST['action']=="save") - { + + if($_POST['action']=="save") { //first delete all their old associations for this year.. - mysql_query("DELETE FROM judges_specialaward_sel WHERE judges_id='".$_SESSION['judges_id']."' AND year='".$config['FAIRYEAR']."'"); - + mysql_query("DELETE FROM judges_specialaward_sel WHERE users_id='{$u['id']}'"); + if(array_key_exists('spaward', $_POST)) { - foreach($_POST['spaward'] AS $aid) - { - mysql_query("INSERT INTO judges_specialaward_sel (judges_id, award_awards_id, year) - VALUES ('".$_SESSION['judges_id']."','$aid','{$config['FAIRYEAR']}')"); + foreach($_POST['spaward'] AS $aid) { + mysql_query("INSERT INTO judges_specialaward_sel (users_id, award_awards_id) + VALUES ('{$u['id']}','$aid')"); } } - echo notice(i18n("Special Award preferences successfully saved")); + message_push(notice(i18n("Special Award preferences successfully saved"))); } - $q=mysql_query("SELECT * FROM judges WHERE email='".$_SESSION['email']."' AND id='".$_SESSION['judges_id']."'"); - $judgeinfo=mysql_fetch_object($q); - updateJudgeCompleteStatus($judgeinfo); -//output the current status -$newstatus=specialawardStatus(); -if($newstatus!="complete") -{ - echo error(i18n("Special Award Preferences Incomplete")); -} -else -{ - echo happy(i18n("Special Award Preferences Complete")); + if($_SESSION['embed'] == true) { + echo "
    "; + display_messages(); + echo "

    ".i18n('Special Awards')."

    "; + echo "
    "; + } else { + //send the header + send_header('Special Awards', + array('Judge Registration' => 'judge_main.php') + ); + } + + judge_status_update($u); + +if($_SESSION['embed'] != true) { + //output the current status + $newstatus=judge_status_special_awards($u); + if($newstatus!='complete') + echo error(i18n("Special Award Preferences Incomplete")); + else + echo happy(i18n("Special Award Preferences Complete")); } - echo "
    \n"; +if($_SESSION['embed'] == true) { + echo "\n"; +} else { + echo "\n"; +} echo "\n"; - if($judgeinfo->typepref == 'speconly') { + if($u['special_award_only'] == 'yes') { echo i18n("Please select the special award you are supposed to judge."); } else { echo i18n("Please select any special awards you would prefer to judge."); @@ -72,12 +85,10 @@ else echo "
    "; echo "
    "; - $q=mysql_query("SELECT * FROM judges_specialaward_sel WHERE judges_id='".$_SESSION['judges_id']."' AND year='".$config['FAIRYEAR']."'"); + $q=mysql_query("SELECT * FROM judges_specialaward_sel WHERE users_id='{$u['id']}'"); $spawards = array(); - while($r=mysql_fetch_object($q)) - { - $spawards[] = $r->award_awards_id; - } + while($r=mysql_fetch_object($q)) $spawards[] = $r->award_awards_id; + echo "\n"; @@ -85,14 +96,14 @@ else $q=mysql_query("SELECT award_awards.id, award_awards.name, award_awards.criteria, - award_sponsors.organization + sponsors.organization FROM award_awards, award_types, - award_sponsors + sponsors WHERE award_types.id=award_awards.award_types_id - AND award_sponsors.id=award_awards.award_sponsors_id + AND sponsors.id=award_awards.sponsors_id AND (award_types.type='Special' OR award_types.type='Other') AND award_awards.year='{$config['FAIRYEAR']}' AND award_types.year='{$config['FAIRYEAR']}' @@ -103,9 +114,9 @@ else { echo ""; echo "
    "; $ch = (in_array($r->id,$spawards)) ? "checked=\"checked\"" : ""; - echo "id}\" />"; + echo "id}\" />"; echo ""; - echo "{$r->name} ($r->organization)"; + echo "{$r->name} ({$r->organization})"; echo "
    "; echo "{$r->criteria}"; @@ -117,9 +128,8 @@ else echo "\n"; echo ""; - echo "
    "; - echo "<< ".i18n("Back to Judges Registration Summary")."
    "; - send_footer(); + if($_SESSION['embed'] != true) send_footer(); + ?> diff --git a/login.php b/login.php new file mode 100644 index 0000000..da83d38 --- /dev/null +++ b/login.php @@ -0,0 +1,74 @@ + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +\n"; + echo "
    \n"; + echo "

    Participant

    \n"; + echo "\n"; + + echo "

    Judge

    \n"; + echo "\n"; + + echo "

    Sponsor

    \n"; + echo "\n"; + + echo "

    Teacher/School

    \n"; + echo "\n"; + + if($config['volunteer_enable'] == 'yes') { + echo "

    Volunteer

    \n"; + echo "\n"; + } + + echo "

    Committee

    \n"; + echo "\n"; + +if($config['fairs_enable'] == 'yes' && $config['fairs_allow_login'] == 'yes') { + echo "

    Other Fair

    \n"; + echo "\n"; +} + +send_footer(); +?> + diff --git a/questions.inc.php b/questions.inc.php index be0743f..8508976 100644 --- a/questions.inc.php +++ b/questions.inc.php @@ -24,13 +24,12 @@ \n"; @@ -158,7 +156,7 @@ function questions_parse_from_http_headers($array_name) return $ans; } -function questions_update_question($qs, $year) +function questions_update_question($qs) { mysql_query("UPDATE questions SET `question`='".mysql_escape_string($qs['question'])."', @@ -166,7 +164,7 @@ function questions_update_question($qs, $year) `db_heading`='".mysql_escape_string($qs['db_heading'])."', `required`='".mysql_escape_string($qs['required'])."', `ord`=".intval($qs['ord'])." - WHERE id='{$qs['id']}' AND year='$year'"); + WHERE id='{$qs['id']}' "); echo mysql_error(); } diff --git a/register_judges.inc.php b/register_judges.inc.php deleted file mode 100644 index 5b1dec4..0000000 --- a/register_judges.inc.php +++ /dev/null @@ -1,203 +0,0 @@ - - Copyright (C) 2005 James Grant - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -?> -"Very Low", - -1=>"Low", - 0=>"Indifferent", - 1=>"Medium", - 2=>"High" -); - - - -function personalStatus() -{ - global $config; - $required_fields=array("firstname","lastname","address","city","postalcode","phonehome","email"); - - $q=mysql_query("SELECT * FROM judges WHERE id='".$_SESSION['judges_id']."'"); - - while($r=mysql_fetch_object($q)) - { - foreach ($required_fields AS $req) - { - if(!$r->$req) - { - return "incomplete"; - } - } - } - - //and they also have to select at least one language to judge in - $q=mysql_query("SELECT COUNT(judges_id) AS num FROM judges_languages WHERE judges_id='".$_SESSION['judges_id']."'"); - $r=mysql_fetch_object($q); - if($r->num==0) - return "incomplete"; - - - //if it made it through without returning incomplete, then we must be complete - return "complete"; -} - -function expertiseStatus() -{ - global $config; - - /* If the judging special awards are active, and the judge has - * selected "I am a special awards judge", then disable this */ - if($config['judges_specialaward_only_enable'] == 'yes') { - $q = mysql_query("SELECT typepref FROM judges WHERE - id='{$_SESSION['judges_id']}'"); - if(mysql_num_rows($q) != 1) return "incomplete"; - $r = mysql_fetch_object($q); - if($r->typepref == 'speconly') - return 'complete'; - } - - //and they need to rank all of the age categories - $q=mysql_query("SELECT COUNT(id) AS num FROM projectcategories WHERE year='".$config['FAIRYEAR']."'"); - $r=mysql_fetch_object($q); - $numcats=$r->num; - - $q=mysql_query("SELECT COUNT(id) AS num FROM judges_catpref WHERE year='".$config['FAIRYEAR']."' AND judges_id='".$_SESSION['judges_id']."'"); - $r=mysql_fetch_object($q); - $numprefs=$r->num; - - if($numcats!=$numprefs) - return "incomplete"; - - //easiest check here is to check the number of divisions, then check the number of entries - //that they have in the judges_expertise table. If they are the same, then we're good to go - //if they are different, they forgot to fill one out (because it only gets inserted if a value) - //is choosen, and they are always ALL removed before each update - - $q=mysql_query("SELECT COUNT(id) AS num FROM projectdivisions WHERE year='".$config['FAIRYEAR']."'"); - $r=mysql_fetch_object($q); - $numdivisions=$r->num; - - $q=mysql_query("SELECT COUNT(id) AS num FROM judges_expertise WHERE projectdivisions_id IS NOT NULL AND judges_id='".$_SESSION['judges_id']."' AND year='".$config['FAIRYEAR']."'"); - $r=mysql_fetch_object($q); - $numjudgesexpertise=$r->num; - - if($numdivisions == $numjudgesexpertise) - return "complete"; - else - return "incomplete"; -} - -function specialawardStatus() -{ - global $config; - - /* Complete if: - * - judge has selected (none) "no special award preferences" - * - judge has selected (pref) "i would like to specify awards", and has - * selected between min and max preferences - * - judge has selected "i am a special awards judge, and has - * selected an award */ - - $q = mysql_query("SELECT typepref FROM judges WHERE - id='{$_SESSION['judges_id']}'"); - if(mysql_num_rows($q) != 1) return "incomplete"; - $r = mysql_fetch_object($q); - - $qq = mysql_query("SELECT COUNT(id) AS num FROM judges_specialaward_sel - WHERE judges_id='{$_SESSION['judges_id']}' - AND year={$config['FAIRYEAR']}"); - $rr = mysql_fetch_object($qq); - $awards_selected = $rr->num; - - switch($r->typepref) { - case "speconly": /* Judge for special award */ - /* They may judge more than one award, so don't limit them - * to one */ - if($awards_selected >= 1) return "complete"; - break; - - case "pref": /* Special award preferences specified */ - default: - if( ($awards_selected >= $config['judges_specialaward_min']) - &&($awards_selected <= $config['judges_specialaward_max']) ){ - return "complete"; - } - break; - } - - return "incomplete"; -} - - - //authenticate based on email address and registration number from the SESSION - if(! ($_SESSION['email'] && $_SESSION['judges_id']) ) - { - header("Location: register_judges.php"); - exit; - } - - $q=mysql_query("SELECT * FROM judges WHERE email='".$_SESSION['email']."' AND id='".$_SESSION['judges_id']."' AND deleted='no'"); - echo mysql_error(); - - if(mysql_num_rows($q)==0) - { - header("Location: register_judges.php?action=logout"); - exit; - } - $judgeinfo=mysql_fetch_object($q); - - -//only check for password expiry if we are NOT on the change password page, otherwise we create endless redirect loops -if(!strstr($_SERVER['PHP_SELF'],"register_judges_password.php")) -{ - //check for expired password - $q=mysql_query("SELECT id FROM judges WHERE email='".$_SESSION['email']."' AND id='".$_SESSION['judges_id']."' AND deleted='no' AND passwordexpiry<=NOW()"); - if(mysql_num_rows($q)) - { - $_SESSION['judges_password_expired']=true; - header("Location: register_judges_password.php"); - } -} - - -//ji = judgeinfo record from database (select * from judges where id='whatever') -function updateJudgeCompleteStatus($ji) -{ - if( personalStatus()=="complete" && - expertiseStatus()=="complete" - ) - $complete="yes"; - else - $complete="no"; - - if($complete!=$ji->complete) - { - mysql_query("UPDATE judges SET complete='$complete' WHERE id='".$ji->id."'"); - } -} - -//finally, if everything else is good, update their 'overall status' if it needs to be -updateJudgeCompleteStatus($judgeinfo); - -?> diff --git a/register_judges.php b/register_judges.php deleted file mode 100644 index ac3641c..0000000 --- a/register_judges.php +++ /dev/null @@ -1,287 +0,0 @@ - - Copyright (C) 2005 James Grant - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -?> -0) - $ex="DATE_ADD(CURDATE(),INTERVAL ".$config['judges_password_expiry_days']." DAY)"; - else - $ex="NULL"; - - mysql_query("INSERT INTO judges (email,password,created,lastlogin,passwordexpiry) VALUES ('".$_SESSION['email']."','".$_POST['pass1']."',NOW(),NOW(),$ex)"); - $id=mysql_insert_id(); - $_SESSION['judges_id']=$id; - - //obviously if they are signing up right now they would like to particapte in the current years fair, so setup the year for them - mysql_query("INSERT INTO judges_years (judges_id,year) VALUES ('$id','".$config['FAIRYEAR']."')"); - - //now redirect to jduges main - header("Location: register_judges_main.php"); - exit; - } - - - } - - else if($_POST['action']=="continue") - { - if($_POST['pass']) - { - $q=mysql_query("SELECT * FROM judges WHERE email='".$_SESSION['email']."' AND password='".$_POST['pass']."' AND deleted='no'"); - if(mysql_num_rows($q)==1) - { - $r=mysql_fetch_object($q); - $_SESSION['judges_id']=$r->id; - $_SESSION['judges_lastlogin']=$r->lastlogin; - mysql_query("UPDATE judges SET lastlogin=NOW() WHERE id='$r->id'"); - header("Location: register_judges_main.php"); - exit; - } - else - { - send_header("Judges Registration"); - echo error(i18n("Invalid Password")); - $_POST['action']="login"; - - } - - } - else - { - send_header("Judges Registration"); - echo error(i18n("Password missing")); - $_POST['action']="login"; - } - } - else if($_GET['action']=="resend" && $_SESSION['email']) - { - //first see if the email matches directly from the registrations table - $q=mysql_query("SELECT * FROM judges - WHERE - email='".$_SESSION['email']."' - "); - $r=mysql_fetch_object($q); - if($r) - { - email_send("register_judges_resend_password",$_SESSION['email'],array("FAIRNAME"=>i18n($config['fairname'])),array("PASSWORD"=>$r->password,"EMAIL"=>$r->email)); - send_header("Judges Registration"); - echo notice(i18n("Your judge registration password has been sent to your email address %1",array($_SESSION['email']),array("email address") )); - } - else - { - send_header("Judges Registration"); - echo error(i18n("Could not find a judge record with your email address")); - } - } - else if($_GET['action']=="logout") - { - unset($_SESSION['email']); - unset($_SESSION['judges_id']); - unset($_SESSION['judges_lastlogin']); - unset($_SESSION['judges_password_expired']); - send_header("Judges Registration"); - echo notice(i18n("You have been successfully logged out")); - } - - if($_SESSION['email'] && $_SESSION['judges_id']) - { - header("Location: register_judges_main.php"); - exit; - } - - send_header("Judges Registration"); - - $_POST['email']=trim($_POST['email']); - - if($_POST['action']=="login" && ( $_POST['email'] || $_SESSION['email']) ) - { - if($_POST['email']) - $_SESSION['email']=$_POST['email']; - - echo "
    "; - - $allownew=true; - //first, check if they have any registrations waiting to be opened - $q=mysql_query("SELECT * FROM judges WHERE email='".$_SESSION['email']."' AND deleted='no'"); - if(mysql_num_rows($q)>0) - { - echo i18n("Please enter your password to login"); - echo "
    "; - echo "
    "; - echo i18n("Password:")." "; - echo ""; - echo ""; - echo ""; - echo "
    "; - echo "
    "; - echo i18n("If you have lost or forgotten your password, please click here to resend it to your email address"); - } - else - { - $allownew=true; - - if($config['judge_registration_type']=="invite") - { - $allownew=false; - - echo i18n("Judge registration is by invite only. You can not create a new account. If you have been invited already, you need to use the same email address that you were invited with. If you need an invitation, please contact the science fair committee."); - echo "
    "; - echo "
    "; - echo "Back to Judges Registration"; - - } - else if($config['judge_registration_type']=="singlepassword") - { - $showsinglepasswordform=true; - if($_POST['singlepassword']) - { - if($_POST['singlepassword']==$config['judge_registration_singlepassword']) - { - $allownew=true; - $showsinglepasswordform=false; - } - else - { - echo error(i18n("Invalid registration password, please try again")); - $allownew=false; - } - } - - if($showsinglepasswordform) - { - echo i18n("Judge registration is protected by a password. You must know the judge registration password in order to create an account."); - echo "
    "; - echo "
    "; - echo ""; - echo i18n("Email Address:")." ".$_SESSION['email']."
    "; - echo i18n("Judge Registration Password:"); - echo ""; - echo "
    "; - echo "
    "; - echo ""; - echo "
    "; - $allownew=false; - } - } - else if($config['judge_registration_type']=="open") - { - //thats fine, continue on and create them the account. - - } - else - { - echo error(i18n("There is an error with the SFIAB configuration. judge_registration_type is not defined. Contact the fair organizers to get this fixed.")); - $allownew=false; - } - - if($allownew) - { - echo i18n("Please choose a password in order to create your judges account"); - echo "
    "; - echo "
    "; - echo i18n("This session may not be encrypted (look for https:// in the URL, or the lock icon in the lower right corner of your browser window). For your safety, we recommend that you DO NOT use an important password here. For example, DO NOT use your personal banking password here."); - echo "
    "; - echo "
    "; - echo ""; - echo ""; - echo ""; - echo ""; - echo "
    "; - echo i18n("Choose Password:"); - echo ""; - echo ""; - echo "
    "; - echo i18n("Confirm Password:"); - echo ""; - echo ""; - echo "
    "; - echo "
    "; - echo ""; - } - } - - echo ""; - } - else - { - //Lets check the date - if we are AFTER 'judgeregopen' and BEFORE 'judgeregclose' then we can login - //otherwise, registration is closed - no logins! - $now = date('Y-m-d H:i:s'); - if($now < $config['dates']['judgeregopen']) - { - echo i18n("Judges registration for the %1 %2 has not yet opened",array($config['FAIRYEAR'],$config['fairname']),array("Fair year","Fair name")); - } - else if($now > $config['dates']['judgeregclose']) - { - echo i18n("Judges registration for the %1 %2 is now closed",array($config['FAIRYEAR'],$config['fairname']),array("Fair year","Fair name")); - } - else - { - if($config['judge_registration_type']=="invite") - { - output_page_text("register_judges_invite"); - echo "
    "; - echo "
    "; - echo i18n("Please enter your email address to :"); - echo "
      "; - } - else - { - echo i18n("Please enter your email address to :"); - echo "
        "; - echo "
      • ".i18n("Begin a new registration")."
      • "; - } - - echo "
      • ".i18n("Login to your account")."
      • "; - echo "
      "; - - ?> -
      - - : - " /> -
      - diff --git a/register_judges_main.php b/register_judges_main.php deleted file mode 100644 index c9562df..0000000 --- a/register_judges_main.php +++ /dev/null @@ -1,189 +0,0 @@ - - Copyright (C) 2005 James Grant - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -?> -firstname) - { - echo i18n("Hello %1",array($judgeinfo->firstname)); - echo "
      "; - } - echo "
      "; - - //first, we need to see if they havec the current FAIRYEAR activated, if not, we'll keep their acocunt 'dormant' and it wont - //be used for anything, but will still be available for them to login in the following years. - - $q=mysql_query("SELECT * FROM judges_years WHERE judges_id='".$_SESSION['judges_id']."' AND year='".$config['FAIRYEAR']."'"); - if(!mysql_num_rows($q)) - { - echo i18n("If you would like to participate as a judge for the %1 %2 please click the 'Activate %3 Judge Profile' button below to activate your judges account for the fair",array($config['FAIRYEAR'],$config['fairname'],$config['FAIRYEAR'])); - echo "
      "; - echo "
      "; - echo i18n("If you can not judge this year, but would like to remain on our mailing list for future years, no action is necessary"); - echo "
      "; - echo "
      "; - echo i18n("If you would like to be completely removed from our judges mailing list, please click the 'Delete Judge Account' button below"); - echo "
      "; - echo "
      "; - echo "
      "; - echo "\n"; - echo ""; - echo "
      "; - - } - else - { - $overallstatus="complete"; - - echo i18n("Please use the checklist below to complete your registration. Click on an item in the table to edit that information. When you have entered all information, the Status field will change to Complete"); - echo "
      "; - echo "
      "; - - echo ""; - echo ""; - - //judges personal information - echo ""; - - /* - //organization information - echo ""; - */ - - //area of expertise - echo ""; - - // special awards - if($config['judges_specialaward_enable'] == 'yes' || $judgeinfo->typepref == 'speconly') { - echo ""; - } - - - echo ""; - echo ""; - - echo "
      ".i18n("Registration Item")."".i18n("Status")."
      "; - echo ""; - echo i18n("Personal Information"); - echo ""; - echo ""; - //check to see if its complete - $statuspersonal=personalStatus(); - echo outputStatus($statuspersonal); - if($statuspersonal!="complete") $overallstatus="incomplete"; - echo "
      "; - echo ""; - echo i18n("Organization Information"); - echo ""; - echo ""; - //check to see if its complete - $statusorganization=organizationStatus(); - echo outputStatus($statusorganization); - echo "
      "; - echo ""; - echo i18n("Areas of Expertise"); - echo ""; - echo ""; - //check to see if its complete - $statusexpertise=expertiseStatus(); - echo outputStatus($statusexpertise); - if($statusexpertise!="complete") $overallstatus="incomplete"; - echo "
      "; - echo ""; - echo i18n("Special Award Preferences"); - echo ""; - echo ""; - //check to see if its complete - $statusspecialawards=specialawardStatus(); - echo outputStatus($statusspecialawards); - if($statusspecialawards!="complete") $overallstatus="incomplete"; - echo "

      ".i18n("Overall Status").""; - echo outputStatus($overallstatus); - echo "
      "; - echo "
      "; - echo "
      "; - - if($overallstatus!="complete") - { - echo error(i18n("You will not be marked as an active judge until your \"Overall Status\" is \"Complete\"")); - } - else - { - echo happy(i18n("Thank you for completing the judge registration process. We look forward to seeing you at the fair")); - } - echo "
      "; - - - echo i18n("If you are unable to participate as a judge in the %1 %2 please click the deactivate button below to deactivate your judges account for the fair",array($config['FAIRYEAR'],$config['fairname'])); - echo "
      "; - echo "
      "; - echo "
      "; - echo "\n"; - echo ""; - echo "
      "; - -} - -echo "
      "; -echo "
      "; -echo "\n"; -echo ""; -echo "
      "; - - -echo "
      "; -echo "".i18n("Change Password").""; -echo "
      "; -echo "".i18n("Logout").""; - - - send_footer(); -?> diff --git a/register_judges_password.php b/register_judges_password.php deleted file mode 100644 index 8fef317..0000000 --- a/register_judges_password.php +++ /dev/null @@ -1,111 +0,0 @@ - - Copyright (C) 2005 James Grant - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -?> -<< ".i18n("Back to Judges Registration Summary")."
      "; - echo "
      "; - } - - if($_POST['action']=="save") - { - //first, lets see if they choosed the same password again (bad bad bad) - $q=mysql_query("SELECT password FROM judges WHERE id='".$_SESSION['judges_id']."' AND email='".$_SESSION['email']."' AND password='".$_POST['pass1']."'"); - if(mysql_num_rows($q)) - { - echo error(i18n("You cannot choose the same password again. Please choose a different password")); - } - //now make sure their password is good - else if(!$_POST['pass1']) - { - echo error(i18n("New Password is required")); - } - else if(!$_POST['pass2']) - { - echo error(i18n("Confirm New Password is required")); - } - else if($_POST['pass1'] != $_POST['pass2']) - { - echo error(i18n("Passwords do not match")); - } - else - { - if($config['judges_password_expiry_days']>0) - $ex="passwordexpiry=DATE_ADD(CURDATE(),INTERVAL ".$config['judges_password_expiry_days']." DAY)"; - else - $ex="passwordexpiry=NULL"; - - mysql_query("UPDATE judges SET password='".$_POST['pass1']."', $ex WHERE id='".$_SESSION['judges_id']."' AND email='".$_SESSION['email']."'"); - echo happy(i18n("Password successfully changed")); - if($_SESSION['judges_password_expired']) - { - unset($_SESSION['judges_password_expired']); - echo "<< ".i18n("Back to Judges Registration Summary")."
      "; - echo "
      "; - send_footer(); - exit; - } - } - } - else - { - if($_SESSION['judges_password_expired']) - echo error(i18n("Your password has expired. You must choose a new password now")); - - } - echo "
      \n"; - echo "\n"; - - echo "
      "; - echo ""; - echo ""; - echo ""; - echo "
      "; - echo i18n("Enter New Password:"); - echo ""; - echo ""; - echo "
      "; - echo i18n("Confirm New Password:"); - echo ""; - echo ""; - echo "
      "; - - -echo "\n"; -echo "
      "; - -if(!$_SESSION['judges_password_expired']) -{ - echo "
      "; - echo "<< ".i18n("Back to Judges Registration Summary")."
      "; -} - -send_footer(); -?> diff --git a/register_judges_personal.php b/register_judges_personal.php deleted file mode 100644 index e565ee6..0000000 --- a/register_judges_personal.php +++ /dev/null @@ -1,181 +0,0 @@ - - Copyright (C) 2005 James Grant - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation, version 2. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ -?> -<< ".i18n("Back to Judges Registration Summary")."
      "; - echo "
      "; - - if($_POST['action']=="save") - { - mysql_query("UPDATE judges SET ". - "firstname='".mysql_escape_string(stripslashes($_POST['firstname']))."', ". - "lastname='".mysql_escape_string(stripslashes($_POST['lastname']))."', ". - "email='".mysql_escape_string(stripslashes($_POST['email']))."', ". - "address='".mysql_escape_string(stripslashes($_POST['address']))."', ". - "address2='".mysql_escape_string(stripslashes($_POST['address2']))."', ". - "city='".mysql_escape_string(stripslashes($_POST['city']))."', ". - "province='".mysql_escape_string(stripslashes($_POST['province']))."', ". - "postalcode='".mysql_escape_string(stripslashes($_POST['postalcode']))."', ". - "phonehome='".mysql_escape_string(stripslashes($_POST['phonehome']))."', ". - "phonework='".mysql_escape_string(stripslashes($_POST['phonework']))."', ". - "phoneworkext='".mysql_escape_string(stripslashes($_POST['phoneworkext']))."', ". - "phonecell='".mysql_escape_string(stripslashes($_POST['phonecell']))."', ". - "organization='".mysql_escape_string(stripslashes($_POST['organization']))."', ". - "highest_psd='".mysql_escape_string(stripslashes($_POST['highest_psd']))."', ". - "professional_quals='".mysql_escape_string(stripslashes($_POST['professional_quals']))."', ". - "typepref='".mysql_escape_string(stripslashes($_POST['typepref']))."' ". - "WHERE id='".$_SESSION['judges_id']."'"); - echo mysql_error(); - - //first we clear out their old languages - mysql_query("DELETE FROM judges_languages WHERE judges_id='".$_SESSION['judges_id']."'"); - if(count($_POST['languages'])) - { - //and now we add back any selected languages - foreach($_POST['languages'] AS $l) - { - mysql_query("INSERT INTO judges_languages (judges_id,languages_lang) VALUES ('".$_SESSION['judges_id']."','$l')"); - } - - } - /* Parse the ansers to the questions, and save them */ - $ans = questions_parse_from_http_headers('questions'); - questions_save_answers('judgereg', $_SESSION['judges_id'], - $config['FAIRYEAR'], $ans); - - echo notice(i18n("%1 %2 successfully updated",array($_POST['firstname'],$_POST['lastname']))); - } - $q=mysql_query("SELECT * FROM judges WHERE email='".$_SESSION['email']."' AND id='".$_SESSION['judges_id']."'"); - $judgeinfo=mysql_fetch_object($q); - updateJudgeCompleteStatus($judgeinfo); - -//output the current status -$newstatus=personalStatus(); -if($newstatus!="complete") -{ - echo error(i18n("Personal Information Incomplete")); -} -else -{ - echo happy(i18n("Personal Information Complete")); -} - - echo "
      \n"; - echo "\n"; - echo "\n"; - -echo "\n"; -echo " \n"; -echo " \n"; -echo "\n"; -echo "\n"; -echo " \n"; -echo " \n"; -echo "\n"; -echo "\n"; -echo " \n"; -echo " \n"; -echo "\n"; -echo "\n"; -echo " \n"; -echo " \n"; -echo "\n"; - -echo "\n"; -echo " \n"; -echo " \n"; -echo ""; - -echo "\n"; -echo " \n"; -echo " \n"; -echo ""; - - -if($config['judges_specialaward_only_enable'] == 'yes') { - echo ""; - echo "\n"; - echo " "; - if($judgeinfo->typepref == "speconly") $ch = "checked=checked"; - else $ch=""; - echo " "; - echo "\n"; -} - -echo ""; - -echo "\n"; -echo " "; -echo " \n"; -echo "\n"; - -echo "\n"; -echo " "; -echo " \n"; -echo "\n"; - -echo "\n"; -echo " "; -echo " \n"; -echo "\n"; - -questions_print_answer_editor('judgereg', - $_SESSION['judges_id'], $config['FAIRYEAR'], 'questions'); - -echo "
      ".i18n("First Name")."firstname\" />".REQUIREDFIELD."".i18n("Last Name")."lastname\" />".REQUIREDFIELD."
      ".i18n("Email Address")."email\" />".REQUIREDFIELD."".i18n("City")."city\" />".REQUIREDFIELD."
      ".i18n("Address 1")."address\" />".REQUIREDFIELD."".i18n($config['provincestate']).""; -emit_province_selector("province",$judgeinfo->province,"onchange=\"fieldChanged()\""); -echo REQUIREDFIELD."
      ".i18n("Address 2")."address2\" />".i18n("Phone (Home)")."phonehome\" />".REQUIREDFIELD."
      ".i18n($config['postalzip'])."postalcode\" />".REQUIREDFIELD."".i18n("Phone (Work)")."phonework\" /> extphoneworkext\" />
      ".i18n("Organization")."organization\" />".i18n("Phone (Cell)")."phonecell\" />

      ".i18n("I am a judge for a specific special award")."
      (".i18n("Check this box if you are supposed to judge a specific special award, and please select that award on the Special Award Preferences page.").")
      "; - echo "

      ".i18n("Highest post-secondary degree")."highest_psd\" />
      ".i18n("Other professional qualifications")."professional_quals\" />
      ".i18n("I can judge in the following languages")." ".REQUIREDFIELD.""; - -//grab the current languages that are selected -$currentlanguages=array(); -$q=mysql_query("SELECT languages_lang FROM judges_languages WHERE judges_id='".$_SESSION['judges_id']."'"); -while($r=mysql_fetch_object($q)) -{ - $currentlanguages[]=$r->languages_lang; -} - -$q=mysql_query("SELECT * FROM languages WHERE active='Y' ORDER BY langname"); -while($r=mysql_fetch_object($q)) -{ - if(in_array($r->lang,$currentlanguages)) $ch="checked=\"checked\""; else $ch=""; - - echo "lang\" /> $r->langname
      "; -} - -echo "
      "; -echo "\n"; -echo "
      "; - - echo "
      "; - echo "<< ".i18n("Back to Judges Registration Summary")."
      "; - -send_footer(); -?> diff --git a/register_participants.inc.php b/register_participants.inc.php index 9b8cf05..7dee2f7 100644 --- a/register_participants.inc.php +++ b/register_participants.inc.php @@ -258,22 +258,24 @@ function tourStatus($reg_id="") $sid = $s->id; $qq=mysql_query("SELECT * FROM tours_choice WHERE students_id='$sid' and year='{$config['FAIRYEAR']}' ORDER BY rank"); - /* See if there's a rank 0 tour (rank 0 == their tour assignment) */ - $i = mysql_fetch_object($qq); - if($i->rank == 0) { - /* Yes, there is, no matter what, this student's tour - * selection is complete. */ - continue; + $n_tours = mysql_num_rows($qq); + if($n_tours > 0) { + /* See if there's a rank 0 tour (rank 0 == their tour assignment) */ + $i = mysql_fetch_object($qq); + if($i->rank == 0) { + /* Yes, there is, no matter what, this student's tour + * selection is complete. */ + continue; + } } /* Else, they haven't been assigned a tour, see if they've made * the appropraite selection(s) */ - $n_tours = mysql_num_rows($qq); - if( ($n_tours >= $config['tours_choices_min']) && ($n_tours <= $config['tours_choices_max']) ){ continue; } $ret = "incomplete"; + break; } return $ret; } diff --git a/sfiab.js b/sfiab.js new file mode 100644 index 0000000..6dea00f --- /dev/null +++ b/sfiab.js @@ -0,0 +1,105 @@ +//useful function that we'll be using throughout +function confirmClick(msg) +{ + var okay=confirm(msg); + if(okay) + return true; + else + return false; +} + +function el(str,domain,name) +{ + document.write('' + name + ''); +} + +function em(str,domain) +{ + document.write('' + str + '@' + domain + ''); +} + +var anyFieldHasBeenChanged=false; + +function fieldChanged() +{ + anyFieldHasBeenChanged=true; +} + +function confirmChanges() +{ + if(anyFieldHasBeenChanged) + { + var okay=confirm(''); + if(okay) + return true; + else + return false; + } + else + return true; +} + +/* Popups using jQuery */ +var popup_current = null; +function popup_open(name) +{ + if(popup_current == null) { + var w = document.documentElement.clientWidth; + var h = document.documentElement.clientHeight; + var ph = $("#popup_"+name).height(); + var pw = $("#popup_"+name).width(); + /* Center the popup */ + $("#popup_"+name).css({ + "position": "absolute", + "top": (h - ph)/2, + "left": (w - pw)/2 + }); + + /* IE6 hack */ + $("#popup_"+name+"_background").css({ + "height": h + }); + + /* Display the popup */ + $("#popup_"+name+"_background").css({ + "opacity": "0.7" + }); + $("#popup_"+name+"_background").fadeIn("fast"); + $("#popup_"+name).fadeIn("fast"); + popup_current = name; + } +} + +function popup_close() +{ + //disables popup only if it is enabled + if(popup_current != null){ + $("#popup_"+popup_current+"_background").fadeOut("fast"); + $("#popup_"+popup_current).fadeOut("fast"); + popup_current = null; + } +} + +/* Hook ESC to cancel a popup */ +$(document).keypress(function(e) +{ + if(e.keyCode==27 && popup_current != null) { + popup_close(); + } +}); + + +/* Stuff to do after the document loads */ +$(document).ready(function() +{ + /* Hook close buttons on all popups (which may not be defined + * until the HTML is finished parsing, so we have to do it + * in the document.ready function ) */ + $(".popup_close").click(function() + { + popup_close(); + }); + +}); + + diff --git a/sponsor_main.php b/sponsor_main.php new file mode 100644 index 0000000..c679734 --- /dev/null +++ b/sponsor_main.php @@ -0,0 +1,129 @@ + + Copyright (C) 2008 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +%1",array($_SESSION['name'])); + if($sponsor->organization) echo " ".i18n("from %1",array($sponsor->organization)); + echo "
      "; + echo "
      "; + + echo ""; + echo " \n"; + echo " "; + echo " "; +// echo " "; + echo " \n"; + echo "
      ".theme_icon("edit_profile")."
      ".i18n("Edit My Profile")."
      ".theme_icon("change_password")."
      ".i18n("Change My Password")."
      ".theme_icon("")."
      ".i18n("Manage My Roles")."
      \n"; + echo "

      Your Sponsorships

      \n"; + + $sq=mysql_query("SELECT sponsorships.id, + sponsors.organization, + sponsorships.value, + sponsorships.status, + sponsorships.probability, + fundraising.name + FROM sponsorships + JOIN sponsors ON sponsorships.sponsors_id=sponsors.id + JOIN fundraising ON sponsorships.fundraising_type=fundraising.type + AND sponsorships.year='{$config['FAIRYEAR']}' + AND fundraising.year='{$config['FAIRYEAR']}' + AND sponsors.id='".$u['sponsors_id']."' + ORDER BY status DESC, probability DESC, organization"); + echo mysql_error(); + + echo ""; + echo ""; + echo " \n"; + echo " \n"; + echo " \n"; + echo " "; + echo "\n"; + $total=0; + while($sr=mysql_fetch_object($sq)) { + echo "id\" class=\"fundraising{$sr->status}\">"; + echo "\n"; + echo ""; + echo ""; + echo "\n"; + echo "\n"; + $total+=$sr->value; + } + echo "
      ".i18n("Sponsorship Category")."".i18n("Status")."".i18n("Amount")."".i18n("Action")."
      $sr->name$sr->status".format_money($sr->value).""; + if($sr->status=="confirmed") { + echo "Pay Online\n"; + } + else if($sr->status=="pending") { + echo "id\">Confirm Funding\n"; + } + echo " "; + echo "
      \n"; + echo "
      \n"; + echo "
      \n"; + + echo "

      Sponsorship Levels

      \n"; + $q=mysql_query("SELECT * FROM sponsorships_levels WHERE year='".$config['FAIRYEAR']."' ORDER BY max DESC"); + echo ""; + echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + $first=true; + while($r=mysql_fetch_object($q)) { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + } + echo "
      ".i18n("Level")."".i18n("Description / Benefits")."".i18n("Range")."
      "; + if($total>=$r->min && $total<=$r->max) { + echo "".i18n("You are here"); + echo " >>"; + echo ""; + } + echo "$r->level$r->description"; + if($first) { + echo format_money($r->min)."+"; + $first=false; + } + else + echo format_money($r->min)."-".format_money($r->max); + + echo "
      \n"; + + send_footer(); +?> diff --git a/tableeditor.css b/tableeditor.css index f9290cb..2d9955a 100644 --- a/tableeditor.css +++ b/tableeditor.css @@ -25,7 +25,7 @@ input { margin-left: 20px; margin-right: 20px; border: 0px; - font-size: 12px; + font-size: 0.8em;; } .tableview td { @@ -53,27 +53,45 @@ input { } .tableedit { - border-spacing: 1px; color: black; margin-left: 20px; margin-right: 20px; - font-size: 12px; + font-size: 0.8em; border: 0px; + border-collapse: collapse; +/* width: 100%;*/ } .tableedit td { - border: 0px solid #5C6F90; padding: 2px; + vertical-align: middle; +} + +/* vertical align top, then use top padding to bring it down + * so that the text is in the middle of the first line compared + * to an input box */ +.tableedit td.left { + width: 25%; + vertical-align: top; + text-align: right; + padding-right: 5px; + padding-top: 5px; +} +.tableedit td.right { + width: 75%; + vertical-align: middle; + text-align: left; } .tableedit th { - border: 1px solid #5C6F90; font-weight: bold; text-align: left; color: #FFFFFF; background-color: #5C6F90; - padding: 2px; + padding: 1px; + vertical-align: top; } + diff --git a/theme/default/icons/Coins-32x32.png b/theme/default/icons/Coins-32x32.png new file mode 100644 index 0000000..dfe4018 Binary files /dev/null and b/theme/default/icons/Coins-32x32.png differ diff --git a/theme/default/sfiab.css b/theme/default/sfiab.css index bbd6648..60e78f5 100644 --- a/theme/default/sfiab.css +++ b/theme/default/sfiab.css @@ -5,6 +5,7 @@ body margin: 0; padding: 0; background: #E0E0FF; + height:100%; } input @@ -30,6 +31,7 @@ td { vertical-align: top; } + table tr.even { background: #EEEEFF; } @@ -63,26 +65,28 @@ table tr.odd { background: #EEEEFF; border: 2px solid Silver; padding: 5px; - font-size: 1em; + font-size: 1.0em; } #main { margin-right: 10px; background: #EEEEFF; - padding: 5px; + padding: 3px; border: 2px solid Silver; min-height: 600px; + width: 99%; } #mainwhere { - margin-right: 10px; - background: #EEEEFF; - padding: 2px; - border-top: 2px solid Silver; - border-left: 2px solid Silver; - border-right: 2px solid Silver; - font-size: 0.85em; + margin-right: 10px; + background: #EEEEFF; + padding: 3px; + border-top: 2px solid Silver; + border-left: 2px solid Silver; + border-right: 2px solid Silver; + font-size: 0.85em; + width: 99%; } @@ -306,3 +310,252 @@ tr.externalaward { width: 128px; color: #999999; } + +.fundraisingpending { + color: black; + border: 1px solid #FFAAAA; + background: #FFAAAA; +} + +.fundraisingconfirmed { + color: black; + border: 1px solid #FFFFAA; + background: #FFFFAA; +} + + +.fundraisingreceived { + color: black; + border: 1px solid #AAFFAA; + background: #AAFFAA; +} + +.fundraisingtable { + border-collapse: collapse; + border-spacing: 0px; + border: 0px; + margin: 0px; + padding: 0px; + margin-left: 30px; + margin-right: 30px; + font-size: 0.8em; + +} + +.fundraisingtable th { + border: 1px solid black; + background-color: #5C6F90; + padding: 2px; + margin: 0px; + font-size: 1.0em; + color: white; + font-weight: bold; + text-align: left; +} + +.fundraisingtable th a{ + color: white; + font-weight: normal; +} + +.fundraisingtable td { + border: 1px solid black; + margin: 0px; + padding: 1px; + +} + + +.SFIABDialog { + font-size: 0.8em; + background-color: #EEEEFF; + border: 3px solid #5C6F90; + z-index: 140; +} + +.SFIABDialogInner { + background-color: #EEEEFF; + margin: 4px; + padding: 4px; + z-index: 150; + +} + +#FadeScreenDiv { + -moz-opacity:.50; + opacity:.50; + position: fixed; + display: block; + visibility: hidden; + top: 0px; + left: 0px; + width: 100%; + height: 100%; + z-index: 100; + background-color: black; + _background: none; + margin: 0px 0px 0px 0px; + clear: none; +} + +.SFIABDialogTable { + border-spacing: 1px; + color: black; + margin-left: 20px; + margin-right: 20px; + font-size: 0.9em; + border: 0px; + border-collapse: collapse; +} + +.SFIABDialogTable td { + border: 0px solid #5C6F90; + padding: 1px; +} + +.SFIABDialogTable th { + border: 1px solid #5C6F90; + font-weight: bold; + text-align: left; + color: #FFFFFF; + background-color: #5C6F90; + padding: 2px; +} + +/* Horizontal Tabs */ +/* For the whole UL */ +ul.htabs { + list-style: none; + list-style-position: outside; + border-bottom-color: #A5B5C6; /* Line colour */ +} + +/* Unselected Tab */ +ul.htabs li { + display: block; + float: left; + position: relative; + margin-right: 5px; + margin-bottom: -1px; + border: 1px solid #A5B5C6; + border-width: 1px 1px 1px 1px; + padding: 3px 5px 3px 5px; + font-weight: bold; + font-size: 11px; + background: #D0D0FF; /* Background Colour */ + color: #000000; + cursor: pointer; +} + +ul.htabs li a { + color: #000000; /* Font colour */ + border-color: #A5B5C6; + text-decoration:none; +} + +/* Overrides for selected tab */ +ul.htabs li.htabs_sel { + background: #EEEEFF; + top: 1px; + border-bottom: 0; + color: #000000; /* Font colour */ +} + +/* Mouseover colour */ +ul.htabs li:hover { + background: #ffffff; +} +/* Don't change colour hovering over the selected tab */ +ul.htabs li.htabs_sel:hover { + background: #EEEEFF; +} + +/* Body of the tab */ +div.htabs { + margin: 0pt auto; + background: #EEEEFF; + border: 1px solid #A5B5C6; + text-align: left; + padding: 10px; + padding-bottom: 20px; + font-size: 11px; +} + +/* Header inside the body */ +div.htabs h1 { + line-height: 1em; + vertical-align: middle; + height: 24px; + font-size: 16px; + font-weight: bold; +} + + +table.usereditor { + width: 100%; +} + +table.usereditor td.left { + width: 25%; + vertical-align: middle; + text-align: right; + padding-right: 5px; +} + +table.usereditor td.right { + width: 75%; + vertical-align: middle; + text-align: left; +} + + + +/* Popups */ +div.popup_background { + display:none; + position:fixed; + _position:absolute; /* hack for internet explorer 6*/ + height:100%; + width:100%; + top:0; + left:0; + background:#000000; + border:1px solid #cecece; + z-index:1; +} +div.popup { + display:none; + position:fixed; + _position:absolute; /* hack for internet explorer 6*/ + height: 75%; + width: 75%; + background: #E0E0FF; + border:2px solid Silver; + z-index:2; + padding:12px; + font-size:13px; +} +/* Popup heading */ +div.popup h1 { + text-align: left; + color: #000000; + font-size: 16px; + font-weight: bold; + border-bottom: 1px; + padding-bottom: 2px; +/* margin-bottom: 20px;*/ +} + +a.popup_close{ + font-size:14px; + line-height:14px; + right:6px; + top:4px; + position:absolute; + color:#5C6F90; + font-weight: bold; + display:block; + cursor: pointer; + text-decoration: none; +} + diff --git a/theme/default/theme.php b/theme/default/theme.php index ad93988..4a7ecb1 100644 --- a/theme/default/theme.php +++ b/theme/default/theme.php @@ -49,6 +49,7 @@ $theme['icons']['one-click_ysf_affiliation_stats']="flag-green.png"; $theme['icons']['communication']="mail-mark-unread.png"; $theme['icons']['website_content_management']="toggle_log.png"; + $theme['icons']['fundraising']="Coins-32x32.png"; //CONFIG ICONS $theme['icons']['configuration']="package_utilities.png"; diff --git a/user.inc.php b/user.inc.php index 2821c57..963cff5 100644 --- a/user.inc.php +++ b/user.inc.php @@ -24,11 +24,23 @@ ?> 'Participant', 'judge' => 'Judge', 'committee'=>'Committee Member','volunteer' => 'Volunteer', - 'fair'=>'Science Fair'); + 'fair'=>'Science Fair','sponsor' => 'Sponsor Contact'); +function user_valid_type($type) +{ + global $user_types; + if(is_array($type)) { + foreach($type as $t) { + if(!in_array($t, $user_types)) return false; + } + } else { + if(!in_array($type, $user_types)) return false; + } + return true; +} /* Duplicate of common.inc.php:generatePassword, which will be deleted * eventually when ALL users are handled through this file */ @@ -46,137 +58,144 @@ function user_generate_password($pwlen=8) -function user_load_fair($u) +/* Separate user_load_type functions, these could make additional database + * calls if required */ +function user_load_fair(&$u) { - /* Double check, make sure the user is of this type */ - if(!in_array('fair', $u['types'])) return false; - - $q = mysql_query("SELECT * FROM users_fair - WHERE users_id='{$u['id']}' - "); - if(mysql_num_rows($q)!=1) return false; - - $r = mysql_fetch_object($q); - $ret = array(); - $ret['fairs_id'] = intval($r->fairs_id); - return $ret; + $u['fair_active'] = ($u['fair_active'] == 'yes') ? 'yes' : 'no'; + $u['fair_complete'] = ($u['fair_complete'] == 'yes') ? 'yes' : 'no'; +// $u['fair_name'] = $u['fair_name']; +// $u['fair_abbrv'] = $u['fair_abbrv']; + return true; } -function user_load_student($u) +function user_load_student(&$u) { - /* Double check, make sure the user is of this type */ - if(!in_array('student', $u['types'])) return false; - $ret = array(); - return $ret; +// $u['student_active'] = ($u['student_active'] == 'yes') ? 'yes' : 'no'; +// $u['student_complete'] = ($u['student_complete'] == 'yes') ? 'yes' : 'no'; + return false; } -function user_load_judge($u) +function user_load_judge(&$u) { - /* Double check, make sure the user is of this type */ - if(!in_array('judge', $u['types'])) return false; - $ret = array(); - return $ret; + $u['judge_active'] = ($u['judge_active'] == 'yes') ? 'yes' : 'no'; + $u['judge_complete'] = ($u['judge_complete'] == 'yes') ? 'yes' : 'no'; + $u['years_school'] = intval($u['years_school']); + $u['years_regional'] = intval($u['years_regional']); + $u['years_national'] = intval($u['years_national']); + $u['willing_chair'] = ($u['willing_chair'] == 'yes') ? 'yes' : 'no'; + $u['special_award_only'] = ($u['special_award_only'] == 'yes') ? 'yes' : 'no'; + $u['cat_prefs'] = unserialize($u['cat_prefs']); + $u['div_prefs'] = unserialize($u['div_prefs']); + $u['divsub_prefs'] = unserialize($u['divsub_prefs']); +// $u['expertise_other'] = $u['expertise_other']; + $u['languages'] = unserialize($u['languages']); +// $u['highest_psd'] = $u['highest_psd']; + + /* Sanity check the arrays, make sure they are arrays */ + $should_be_arrays = array('cat_prefs','div_prefs', + 'divsub_prefs','languages'); + foreach($should_be_arrays as $k) { + if(!is_array($u[$k])) $u[$k] = array(); + } + + return true; } -function user_load_committee($u) +function user_load_committee(&$u) { - /* Double check, make sure the user is of this type */ - if(!in_array('committee', $u['types'])) return false; - - $q = mysql_query("SELECT * FROM users_committee - WHERE users_id='{$u['id']}'"); - if(mysql_num_rows($q)!=1) return false; - - $r = mysql_fetch_object($q); - $ret = array(); - $ret['emailprivate'] = $r->emailprivate; - $ret['ord'] = intval($r->ord); - $ret['displayemail'] = ($r->displayemail == 'yes') ? 'yes' : 'no'; - $ret['access_admin'] = ($r->access_admin == 'yes') ? 'yes' : 'no'; - $ret['access_config'] = ($r->access_config == 'yes') ? 'yes' : 'no'; - $ret['access_super'] = ($r->access_super == 'yes') ? 'yes' : 'no'; - - return $ret; + $u['committee_active'] = $u['committee_active']; + $u['emailprivate'] = $u['emailprivate']; + $u['ord'] = intval($u['ord']); + $u['displayemail'] = ($u['displayemail'] == 'yes') ? 'yes' : 'no'; + $u['access_admin'] = ($u['access_admin'] == 'yes') ? 'yes' : 'no'; + $u['access_config'] = ($u['access_config'] == 'yes') ? 'yes' : 'no'; + $u['access_super'] = ($u['access_super'] == 'yes') ? 'yes' : 'no'; + return true; } -function user_load_volunteer($u) +function user_load_volunteer(&$u) { - /* Double check, make sure the user is of this type */ - if(!in_array('volunteer', $u['types'])) return false; - $ret = array(); - return $ret; + $u['volunteer_active'] = ($u['volunteer_active'] == 'yes') ? 'yes' : 'no'; + $u['volunteer_complete'] = ($u['volunteer_complete'] == 'yes') ? 'yes' : 'no'; + return true; } -function user_load($user, $load_full=false) +function user_load_sponsor($u) { - $id = 0; + $u['sponsors_id'] = intval($u['sponsors_id']); + $u['sponsor_complete'] = ($u['sponsor_complete'] == 'yes') ? 'yes' : 'no'; + $u['sponsor_active'] = ($u['sponsor_active'] == 'yes') ? 'yes' : 'no'; + return true; +} - /* Sort out the type first */ - if(is_array($user)){ - /* User already loaded, this is just an extended load */ - $id = $user['id']; - $where = "id='$id'"; - $load_base = false; +function user_load($user, $uid = false) +{ + /* So, it turns out that doing one big load is faster than loading just + * from the users table then loading only the specific types the user + * has.. go figure. */ + $query = "SELECT * FROM `users` + LEFT JOIN `users_committee` ON `users_committee`.`users_id`=`users`.`id` + LEFT JOIN `users_judge` ON `users_judge`.`users_id`=`users`.`id` + 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` + WHERE "; + if($uid != false) { + $uid = intval($uid); + $query .= "`users`.`uid`='$uid' ORDER BY `users`.`year` DESC LIMIT 1"; } else { - $id = intval($user); - if($id > 0) { - /* Load by ID FIXME: if we enable load-by-email below, - * then a user could use a number at the beginning of - * their email address to exploit here, must fix that. - * */ - $where = "id='$id'"; - } else { - return false; - /* Load by email */ -// $e = stripslashes($user); -// $where = "email='$e'"; - } - $load_base = true; + $query .= " `users`.`id`='$id'"; + } + $q=mysql_query($query); + + if(mysql_num_rows($q)!=1) { + echo "Query [$query] returned ".mysql_num_rows($q)." rows\n"; +// echo "
      ";
      +//		print_r(debug_backtrace());
      +		return false;
       	}
       
      -	if($load_base) {
      -		$q=mysql_query("SELECT * FROM users
      -					WHERE
      -						$where
      -						AND deleted='no'
      -				");
      +	$ret = mysql_fetch_assoc($q);
       
      -                if(mysql_num_rows($q)!=1) return false;
      -
      -		$ret = mysql_fetch_assoc($q);
      +	/* Make sure they're not deleted, we don't want to do this in the query, because loading by $uid would
      +	 * simply return the previous year (where deleted=no) */
      +	if($ret['deleted'] != 'no') {
      +		/* User is deleted */
      +		return false;
      +	}
       		
      -		/* Do we need to do number conversions? */
      -		$ret['id'] = intval($ret['id']);
      +	/* Do we need to do number conversions? */
      +	$ret['id'] = intval($ret['id']);
      +	$ret['uid'] = intval($ret['uid']);
      +	$ret['year'] = intval($ret['year']);
       
      -		/* Turn the type into an array, because there could be more than one */
      -		$ts = explode(',', $ret['types']);
      -		$ret['types'] = $ts; /* Now we can use in_array('judge', $ret['types']) ; */
      -	} else {
      -		$ret = $user;
      -	}
      +	/* Turn the type into an array, because there could be more than one */
      +	$ts = explode(',', $ret['types']);
      +	$ret['types'] = $ts; /* Now we can use in_array('judge', $ret['types']) ; */
       
      -	if($load_full) {
      -		$r = true;
      -		foreach($ret['types'] as $t) {
      -			if($ret['load_full'] == true) continue;
      -			/* These all pass $ret by reference, and can modify
      -			 * $ret */
      -			$r = call_user_func("user_load_$t", $ret);
      -			if(!is_array($r)) return false;
      +	/* Convenience */
      +	$ret['name'] = $ret['firstname'].' '.$ret['lastname'];
       
      -			/* It is important that each type database doesn't
      -			have conflicting column names */
      -			foreach($r as $k=>$v) {
      -				if(array_key_exists($k, $ret)) {
      -					echo "DATABASE DESIGN ERROR, duplicate user key $k";
      -					exit;
      -				}
      -			}
      -			$ret = array_merge($ret, $r);
      +	foreach($ret['types'] as $t) {
      +		/* These all pass $ret by reference, and can modify
      +		 * $ret */
      +		$r = call_user_func("user_load_$t", &$ret);
      +		if($r != true) {
      +			echo "user_load_$t returned false!\n";
      +			return false;
       		}
      -		$ret['load_full'] = true;
      -	} else {
      -		$ret['load_full'] = false;
      +
      +		/* It is important that each type database doesn't
      +		have conflicting column names */
      +/*		foreach($r as $k=>$v) {
      +			if(array_key_exists($k, $ret)) {
      +				echo "DATABASE DESIGN ERROR, duplicate user key $k";
      +				exit;
      +			}
      +		}
      +		$ret = array_merge($ret, $r);
      +*/
       	}
       
       	/* Do this assignment without recursion :) */
      @@ -184,13 +203,18 @@ function user_load($user, $load_full=false)
       	$orig = $ret;
       	$ret['orig'] = $orig;
       
      -//	echo "
      User load returning:\n";
      -//	print_r($ret);
      -//	echo "
      "; - +/* echo "
      User load returning: \n";
      +	print_r($ret);
      +	echo "
      "; +*/ return $ret; } +function user_load_by_uid($uid) +{ + return user_load(0, $uid); +} + function user_set_password($id, $password = NULL) { /* pass $u by reference so we can update it */ @@ -221,49 +245,84 @@ function user_set_password($id, $password = NULL) return $password; } - -function user_save_volunteer($u) +function user_save_type_list($u, $db, $fields) { -} - -function user_save_committee($u) -{ - $fields = array('emailprivate','ord','displayemail','access_admin', - 'access_config','access_super'); //echo "
      ";
       //	print_r($u);
       //	echo "
      "; $set = ''; foreach($fields as $f) { + /* == even works on arrays in PHP */ if($u[$f] == $u['orig'][$f]) continue; if($set != '') $set .=','; - $data = mysql_escape_string(stripslashes($u[$f])); - $set .= "$f='$data'"; + if($u[$f] == NULL) { + $set .= "$f=NULL"; + continue; + } + + if(is_array($u[$f])) + $data = mysql_escape_string(serialize($u[$f])); + else + $data = mysql_escape_string(stripslashes($u[$f])); + + $set .= "`$f`='$data'"; } if($set != "") { - $query = "UPDATE users_committee SET $set WHERE users_id='{$u['id']}'"; + $query = "UPDATE $db SET $set WHERE users_id='{$u['id']}'"; mysql_query($query); + if(mysql_error()) { + echo mysql_error(); + echo error("Full query: $query"); + } } } +function user_save_volunteer($u) +{ + $fields = array('volunteer_active','volunteer_complete'); + user_save_type_list($u, 'users_volunteer', $fields); +} + +function user_save_committee($u) +{ + $fields = array('committee_active','emailprivate','ord','displayemail','access_admin', + 'access_config','access_super'); + user_save_type_list($u, 'users_committee', $fields); +} + function user_save_judge($u) { + $fields = array('judge_active','judge_complete','years_school','years_regional','years_national', + 'willing_chair','special_award_only', + 'cat_prefs','div_prefs','divsub_prefs', + 'expertise_other','languages', 'highest_psd'); + user_save_type_list($u, 'users_judge', $fields); } function user_save_student($u) { +// $fields = array('student_active','student_complete'); +// user_save_type_list($u, 'users_student', $fields); } function user_save_fair($u) { + $fields = array('fair_active','fairs_id'); + user_save_type_list($u, 'users_fair', $fields); +} + +function user_save_sponsor($u) +{ + $fields = array('sponsors_id','sponsor_active','sponsor_complete','primary','position','notes'); + user_save_type_list($u, 'users_sponsor', $fields); } function user_save($u) { - $fields = array('firstname','lastname','username', + $fields = array('salutation','firstname','lastname','username', 'email', 'phonehome','phonework','phonecell','fax','organization', 'address','address2','city','province','postalcode','sex', @@ -287,7 +346,7 @@ function user_save($u) if($set != "") { $query = "UPDATE users SET $set WHERE id='{$u['id']}'"; mysql_query($query); - // echo "query=[$query]"; +// echo "query=[$query]"; echo mysql_error(); } @@ -295,19 +354,17 @@ function user_save($u) if($u['password'] != $u['orig']['password']) user_set_password($u['id'], $u['password']); - /* If this was a full load, do a full save */ - if($u['load_full'] == true) { - foreach($u['types'] as $t) { - call_user_func("user_save_$t", $u); - } + foreach($u['types'] as $t) { + call_user_func("user_save_$t", $u); } } +/* Delete functions. These mark a user as deleted, and delete references to other + * tables */ function user_delete_committee($u) { - mysql_query("DELETE FROM users_committee WHERE users_id='{$u['id']}'"); - mysql_query("DELETE FROM committees_link WHERE users_id='{$u['id']}'"); + mysql_query("DELETE FROM committees_link WHERE users_uid='{$u['uid']}'"); } function user_delete_volunteer($u) @@ -316,15 +373,24 @@ function user_delete_volunteer($u) function user_delete_judge($u) { + global $config; + $id = $u['id']; + mysql_query("DELETE FROM judges_teams_link WHERE users_id='$id'"); + mysql_query("DELETE FROM judges_specialawards_sel WHERE users_id='$id'"); } function user_delete_fair($u) { } + function user_delete_student($u) { } +function user_delete_sponsor($u) +{ +} + function user_delete($u, $type=false) { $finish_delete = false; @@ -354,14 +420,132 @@ function user_delete($u, $type=false) } else { /* Delete the whole user */ foreach($u['types'] as $t) call_user_func("user_delete_$t", $u); - $finish_delete = true; } if($finish_delete == true) { + mysql_query("UPDATE users SET deleted='yes', deleteddatetime=NOW() WHERE id='{$u['id']}'"); + } +} + + +/* Purge functions. These completely eliminate all traces of a user from the + * database. This action cannot be undone. We prefer the committee to use the + * "delete" functions, which simply mark the account as "deleted". */ + +function user_purge($u, $type=false) +{ + $finish_purge = false; + + if(!is_array($u)) { + $u = user_load($u); + } + if($type != false) { + if(!in_array($type, $u['types'])) { + /* Hum, type specified, but the user is not this type, + * so, i guess we're done. */ + return; + } + if(count($u['types']) > 1) { + /* Don't delete the whole user */ + $types=''; + foreach($u['types'] as $t) { + if($t == $type) continue; + if($types != '') $types .= ','; + $types .= $t; + } + mysql_query("UPDATE users SET types='$types' WHERE id='{$u['id']}'"); + } else { + $finish_purge = true; + } + /* Call the delete func to deal with table linking, then completely wipe + * out the entry */ + call_user_func("user_delete_$type", $u); +// call_user_func("user_purge_$type", $u); + mysql_query("DELETE FROM users_$type WHERE users_id='{$u['id']}'"); + } else { + /* Delete the whole user */ + foreach($u['types'] as $t) { + call_user_func("user_delete_$t", $u); +// call_user_func("user_purge_$t", $u); + mysql_query("DELETE FROM users_$t WHERE users_id='{$u['id']}'"); + } + $finish_purge = true; + } + if($finish_purge == true) { mysql_query("DELETE FROM users WHERE id='{$u['id']}'"); } } + +/* Duplicate a row in the users table, or any one of the users_* tables. */ +function user_dupe_row($db, $key, $val, $newval) +{ + global $config; + $nullfields = array('deleteddatetime'); /* Fields that can be null */ + $q = mysql_query("SELECT * FROM $db WHERE $key='$val'"); + if(mysql_num_rows($q) != 1) { + echo "ERROR duplicating row in $db: $key=$val NOT FOUND.\n"; + exit; + } + $i = mysql_fetch_assoc($q); + $i[$key] = $newval; + + foreach($i as $k=>$v) { + if($v == NULL && in_array($k, $nullfields)) + $i[$k] = 'NULL'; + else if($k == 'year') + $i[$k] = $config['FAIRYEAR']; + else + $i[$k] = '\''.mysql_escape_string($v).'\''; + } + + $keys = '`'.join('`,`', array_keys($i)).'`'; + $vals = join(',', array_values($i)); + + $q = "INSERT INTO $db ($keys) VALUES ($vals)"; +// echo "Dupe Query: [$q]"; + $r = mysql_query($q); + echo mysql_error(); + + $id = mysql_insert_id(); + return $id; +} +/* Used by the login scripts to copy one user from one year to another */ +function user_dupe($u, $new_year) +{ + /* Dupe a user if: + * - They don't exist in the current year + * (users->year != the target year (passed in so we can use it in the rollover script) ) + * - They have a previous year entry + * (users->year DESC LIMIT 1 == 1 row) + * - That previous entry has deleted=no */ + + /* Find the last entry */ + $q = mysql_query("SELECT id,uid,year,deleted FROM users WHERE uid='{$u['uid']}' + ORDER BY year DESC LIMIT 1"); + $r = mysql_fetch_object($q); + if($r->deleted == 'yes') { + echo "Cannot duplicate user ID {$u['id']}, they are deleted. Undelete them first.\n"; + exit; + } + if($r->year == $new_year) { + echo "Cannot duplicate user ID {$u['id']}, they already exist in year $new_year\n"; + exit; + } + + $id = user_dupe_row('users', 'id', $u['id'], NULL); + $q = mysql_query("UPDATE users SET year='$new_year' WHERE id='$id'"); + + /* Load the new user */ + $u2 = user_load($id); + + foreach($u2['types'] as $t) { + user_dupe_row("users_$t", 'users_id', $u['id'], $id); + } + /* Return the ID of the new user */ + return $id; +} + /* Returns true if loaded user ($u) is allowed to add role type $type to their * profile. THis is intended as a last-stop mechanism, preventing, for example * a student from co-existing with any other account type. */ @@ -374,7 +558,8 @@ function user_add_role_allowed($type, $u) 'volunteer' => array('judge', 'committee'), 'judge' => array('volunteer', 'committee'), 'student' => array(), - 'fair' => array() ); + 'fair' => array(), + 'sponsor' => array('volunteer','judge') ); foreach($u['types'] as $ut) { $allowed_array = $allowed[$ut]; @@ -383,12 +568,15 @@ function user_add_role_allowed($type, $u) return false; } -function user_create($type, $u = NULL) +function user_create($type, $username, $u = NULL) { + global $config; if(!is_array($u)) { - mysql_query("INSERT INTO users (`types`,`passwordset`,`created`) - VALUES ('$type', '0000-00-00', NOW())"); + mysql_query("INSERT INTO users (`types`,`username`,`passwordset`,`created`,`year`) + 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'"); user_set_password($uid, NULL); } else { /* The user has been specified and already exists, @@ -405,16 +593,25 @@ function user_create($type, $u = NULL) 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`) VALUES ('$uid')"); + mysql_query("INSERT INTO users_fair(`users_id`, `fair_active`) VALUES ('$uid', 'yes')"); break; case 'committee': - mysql_query("INSERT INTO users_committee(`users_id`) VALUES ('$uid')"); + 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, true); + return user_load($uid); } @@ -457,12 +654,14 @@ function user_auth_required($type, $access='') { global $config; if(!isset($_SESSION['users_type'])) { - header("location: {$config['SFIABDIRECTORY']}/user_login.php?type=$type¬ice=auth_required"); + message_push(error(i18n("You must login to view that page"))); + header("location: {$config['SFIABDIRECTORY']}/user_login.php?type=$type"); exit; } if($_SESSION['users_type'] != $type) { - header("location: {$config['SFIABDIRECTORY']}/user_login.php?type=$type¬ice=auth_required"); + message_push(error(i18n("You must login to view that page"))); + header("location: {$config['SFIABDIRECTORY']}/user_login.php?type=$type"); exit; } @@ -478,7 +677,8 @@ function user_auth_required($type, $access='') } if(committee_auth_has_access($access) == false) { - header("Location: {$config['SFIABDIRECTORY']}/committee_main.php?notice=no_auth"); + message_push(error(i18n('You do not have permission to view that page'))); + header("Location: {$config['SFIABDIRECTORY']}/committee_main.php"); exit; } } @@ -505,6 +705,7 @@ function user_judge_registration_status() } $user_personal_fields_map = array( + 'salutation' => array('salutation'), 'name' => array('firstname','lastname'), 'email' => array('email'), 'sex' => array('sex'), @@ -552,11 +753,8 @@ function user_personal_required_fields($type) return $ret; } -function user_personal_info_status($u = false) +function user_personal_info_status(&$u) { - if($u == false) { - $u = user_load($_SESSION['users_id']); - } $required = array(); foreach($u['types'] as $t) { $required = array_merge($required, @@ -571,23 +769,12 @@ function user_personal_info_status($u = false) return 'incomplete'; } } + /* FIXME: somehow call the $type _status_update() function to update + * the individual $type _complete entry? */ return 'complete'; } -function user_update_complete(&$u, $status) -{ - if($status == 'complete' && $u['complete'] != 'yes') { - mysql_query("UPDATE users SET complete='yes' WHERE id='{$_SESSION['users_id']}'"); - $u['complete'] = 'yes'; - return; - } - if($status != 'complete' && $u['complete'] == 'yes') { - mysql_query("UPDATE users SET complete='no' WHERE id='{$_SESSION['users_id']}'"); - $u['complete'] = 'no'; - return; - } -} - +/* user_{$type}_login() is called with a full $u loaded */ function user_committee_login($u) { /* Double check, make sure the user is of this type */ @@ -596,7 +783,6 @@ function user_committee_login($u) exit; } - $u = user_load($u, true); $_SESSION['access_admin'] = $u['access_admin'];// == 'yes') ? true : false; $_SESSION['access_config'] = $u['access_config'];// == 'yes') ? true : false; $_SESSION['access_super'] = $u['access_super'];// == 'yes') ? true : false; @@ -610,7 +796,6 @@ function user_fair_login($u) exit; } - $u = user_load($u, true); $_SESSION['fairs_id'] = $u['fairs_id'];// == 'yes') ? true : false; } diff --git a/user_activate.php b/user_activate.php new file mode 100644 index 0000000..ae7a2a2 --- /dev/null +++ b/user_activate.php @@ -0,0 +1,155 @@ + + Copyright (C) 2005 James Grant + Copyright (C) 2007 David Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +"; + display_messages(); + echo "

      ".i18n("Role and Account Management")."

      "; + echo "
      "; + } else { + $type = $_SESSION['users_type']; + $m = $user_what[$type]; + send_header("Role and Account Management", + array("$m Main" => "{$type}_main.php") + ); + } + + $action_url = ($_SESSION['embed'] == true) ? $_SESSION['embed_submit_url'] : $_SERVER['PHP_SELF']; + + foreach($u['types'] as $t) { + echo '

      '.i18n("Role: {$user_what[$t]}").'

      '; + if($u["{$t}_active"] == 'yes') { + echo happy(i18n('Active')); + $a = 'disabled="disabled"'; + $d = ''; + } else { + echo notice(i18n('Deactivated')); + $a = ''; + $d = 'disabled="disabled"'; + } + + echo '
      '; + echo "
      "; + echo "\n"; + echo "\n"; + echo ""; + echo "
      "; + + echo '
      '; + + echo "
      "; + echo "\n"; + echo "\n"; + echo ""; + echo "
      "; + + echo '
      '; + + echo "
      "; + echo "\n"; + echo "\n"; + echo ""; + echo "
      "; + + echo '
      '; + echo '
      '; + echo '
      '; + } + + echo '
        '; + echo '
      • '.i18n("An Active Role indicates you would like to participate in the %1 %2 as that role (Judge, Volunteer, etc.)",array($config['FAIRYEAR'],$config['fairname'])); + echo '
      • '.i18n("A Deactivated Role indicates you cannot participate in the deactivated roles this year, but would like remain on the mailing lists for future years. You can activate your deactivated role at any time."); + echo '
      • '.i18n("The Remove Role button completely deletes the role from your account. You will not receive future emails for the removed role. This action cannot be undone."); + echo '
      • '.i18n("The Delete Entire Account button below completely deletes your entire account. You will not receive any future email for any roles. It completely removes you from the system. This action cannot be undone."); + echo '
      '; + + echo "
      "; + echo "\n"; + echo ""; + echo "
      "; + + if($_SESSION['embed'] != true) send_footer(); +?> diff --git a/user_invite.php b/user_invite.php new file mode 100644 index 0000000..77eb04f --- /dev/null +++ b/user_invite.php @@ -0,0 +1,244 @@ + + Copyright (C) 2005 James Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> + 'committee_main.php', + 'Administration' => 'admin/index.php' + ) ); + + require_once('ajax.inc.php'); + +?> + +"; + + $allowed_types = array('judge', 'volunteer'); + $type = $_POST['type']; + if($type == '') $type = $_GET['type']; + if($type != '') { + if(!in_array($type, $allowed_types)) { + echo "Type $type not allowed for invite

      "; + exit; + } + } + + if($_POST['action']!="" && $_POST['email'] && $type != '') { + $allowed_actions = array('notexist','norole','noyear'); + $email = stripslashes($_POST['email']); + + $action = $_POST['action']; + if(!in_array($action, $allowed_actions)) + exit; + + $q = mysql_query("SELECT id FROM users WHERE email='$email' ORDER BY year DESC"); + if(mysql_num_rows($q) > 0) { + $u = mysql_fetch_assoc($q); + $u = user_load($u['id']); + } else { + $u = NULL; + } + + switch($action) { + case 'notexist': /* Create the user */ + $u = user_create($type, $email); + $u['email'] = $email; + user_save($u); + email_send("{$type}_new_invite",$u['email'], + array("FAIRNAME"=>$config['fairname']), + array("FAIRNAME"=>$config['fairname'], + "EMAIL"=>$u['email'], + "PASSWORD"=>$u['password'])); + echo happy(i18n('%1 has been invited to be a %2', array($u['email'], $user_what[$type]))); + echo happy(i18n('An email has been sent to %1', array($u['email']))); + break; + + case 'norole': /* Add role to the existing user */ + user_create($type, $u['username'], $u); + email_send("{$type}_add_invite",$u['email'], + array("FAIRNAME"=>$config['fairname']), + array("FAIRNAME"=>$config['fairname'])); + echo happy(i18n('%1 is now also a %2', array($u['email'], $user_what[$type]))); + echo happy(i18n('An email has been sent to %1', array($u['email']))); + break; + + case 'noyear': /* Send a reminder email */ + email_send("{$type}_activate_reminder",$u['email'], + array("FAIRNAME"=>$config['fairname']), + array("FAIRNAME"=>$config['fairname'], + "EMAIL"=>$u['email'])); + echo happy(i18n('An email has been sent to %1', array($u['email']))); + break; + } + } + + + echo "
      \n"; + echo "
      \n"; + echo "\n"; + echo "
      "; + echo i18n("Select a Role: "); + echo "
      "; + echo i18n("Enter an Email: "); + echo ""; + echo "
      "; + echo "
      \n"; + echo "
      ".i18n('Select a role and enter an email address')."
      "; + + echo "
      \n"; + echo "\n"; + + echo "
      \n"; + + + send_footer(); +?> diff --git a/user_login.php b/user_login.php index 46cba42..52930e5 100644 --- a/user_login.php +++ b/user_login.php @@ -30,7 +30,7 @@ { /* Ensure sanity of inputs, user should be an email address, but it's stored * in the username field */ - /* FIXME: this shoudl be user_valid_email, but can't be yet, because + /* FIXME: this should be user_valid_email, but can't be yet, because * we copy the usernames from the email field, and that field may * contain a name too */ if(!isEmailAddress($user)) { @@ -45,16 +45,19 @@ return false; $user = mysql_escape_string($user); - $q = mysql_query("SELECT id,username,password + $q = mysql_query("SELECT id,username,password,year,deleted FROM users WHERE username='$user' - AND deleted='no'"); - echo mysql_error(); - if(mysql_num_rows($q) != 1) return false; + AND deleted='no' + ORDER BY year DESC LIMIT 1"); + if(mysql_num_rows($q) < 1) return false; - /* Ok.. see if the passwd matches */ $r = mysql_fetch_object($q); + /* See if the user account has been deleted */ + if($r->deleted == 'yes') return false; + + /* See if the password matches */ if($r->password != $pass) return false; /* Login successful */ @@ -71,7 +74,8 @@ $type = $_SESSION['users_type']; /* If they're not trying to logout, don't let them see the login page */ if($_GET['action'] != 'logout') { - header("location: {$type}_main.php?notice=already_logged_in"); + message_push(error(i18n('You are already logged in, please use the [Logout] link in the upper right to logout before logging in as different user'))); + header("location: {$type}_main.php"); exit; } } else { @@ -106,12 +110,14 @@ $reg_open = 'notpermitted'; break; case 'judge': - exit; $reg_open = user_judge_registration_status(); break; case 'fair': $reg_open = 'notpermitted'; break; + case 'sponsor': + $reg_open = 'notpermitted'; + break; case 'student': default: exit; @@ -125,108 +131,121 @@ { $id = try_login($_POST['user'], $_POST['pass']); if($id == false) { - header("location: user_login.php?type=$type¬ice=login_failed$redirect_url"); + message_push(error(i18n("Invalid Email/Password"))); + header("location: user_login.php?type=$type$redirect_url"); exit; - } else { + } + + $u = user_load($id); + + /* Make sure the user we loaded is actually for the current year, if not, + * we need to duplicate the user */ + if($u['year'] != $config['FAIRYEAR']) { + $id = user_dupe($u, $config['FAIRYEAR']); $u = user_load($id); - /* Make sure $type is in their types */ - if(!in_array($type, $u['types'])) { - /* Huh, someone is fudging with the HTML, get - * out before touching the session */ - header("location: index.php"); - exit; - } + } - $_SESSION['name']="{$u['firstname']} {$u['lastname']}"; - $_SESSION['username']=$u['username']; - $_SESSION['email']=$u['email']; - $_SESSION['users_id']=$u['id']; - $_SESSION['users_type']=$type; - - /* Load the password expiry for each user type, and - * find the longest expiry, which is the one we'll use - * for this user to determine if the passwd has - * expired. */ - $longest_expiry = 0; - foreach($u['types'] as $t) { - $e = $config["{$t}_password_expiry_days"]; - if($e == 0) { - /* Catch a never expire case. */ - $longest_expiry = 0; - break; - } else if($e > $longest_expiry) { - $longest_expiry = $e; - } - } - if($u['passwordset'] == '0000-00-00') { - /* Force the password to expire */ - $_SESSION['password_expired'] = true; - } else if($longest_expiry == 0) { - /* Never expires */ - unset($_SESSION['password_expired']); - } else { - /* Check expiry */ - $expires = date('Y-m-d', strtotime("{$u['passwordset']} +$longest_expiry days")); - $now = date('Y-m-d'); - if($now > $expires) { - $_SESSION['password_expired'] = true; - } else { - unset($_SESSION['password_expired']); - } - } - /* If password_expired == true, the main page (or any - * other user page) will catch this and require - * them to set a password */ - - /* Call login functions for each type, so multirole - * users can easily switch */ - foreach($u['types'] as $t) { - if(is_callable("user_{$t}_login")) { - call_user_func_array("user_{$t}_login", array($u)); - } - } - - mysql_query("UPDATE users SET lastlogin=NOW() - WHERE id={$u['id']}"); - - /* Setup multirole so a multirole user can switch if they want to - * without logging in/out */ - if(count($u['types']) > 1) { - $_SESSION['multirole'] = true; - } else { - $_SESSION['multirole'] = false; - } - - /* See if there is a redirect, and do that instead of - * taking them to their main page */ - if($redirect != '') { - switch($redirect) { - case 'roleadd': - if(!in_array($multirole_data, $user_types)) - $multirole_data = ''; - - header("location: user_multirole.php?action=add&type=$multirole_data"); - exit; - case 'roleattached': - header("location: {$type}_main.php?notice=attached"); - exit; - - } - } - - /* Now finally, take them to whatever main page they logged in for */ - header("location: {$type}_main.php"); + /* Make sure $type is in their types */ + if(!in_array($type, $u['types'])) { + /* Huh, someone is fudging with the HTML, get + * out before touching the session */ + header("location: index.php"); exit; } + $_SESSION['name']="{$u['firstname']} {$u['lastname']}"; + $_SESSION['username']=$u['username']; + $_SESSION['email']=$u['email']; + $_SESSION['users_id']=$u['id']; + $_SESSION['users_uid']=$u['uid']; + $_SESSION['users_type']=$type; + + /* Load the password expiry for each user type, and + * find the longest expiry, which is the one we'll use + * for this user to determine if the passwd has + * expired. */ + $longest_expiry = 0; + foreach($u['types'] as $t) { + $e = $config["{$t}_password_expiry_days"]; + if($e == 0) { + /* Catch a never expire case. */ + $longest_expiry = 0; + break; + } else if($e > $longest_expiry) { + $longest_expiry = $e; + } + } + if($u['passwordset'] == '0000-00-00') { + /* Force the password to expire */ + $_SESSION['password_expired'] = true; + } else if($longest_expiry == 0) { + /* Never expires */ + unset($_SESSION['password_expired']); + } else { + /* Check expiry */ + $expires = date('Y-m-d', strtotime("{$u['passwordset']} +$longest_expiry days")); + $now = date('Y-m-d'); + if($now > $expires) { + $_SESSION['password_expired'] = true; + } else { + unset($_SESSION['password_expired']); + } + } + /* If password_expired == true, the main page (or any + * other user page) will catch this and require + * them to set a password */ + + /* Call login functions for each type, so multirole + * users can easily switch */ + foreach($u['types'] as $t) { + if(is_callable("user_{$t}_login")) { + call_user_func_array("user_{$t}_login", array($u)); + } + } + + mysql_query("UPDATE users SET lastlogin=NOW() + WHERE id={$u['id']}"); + + /* Setup multirole so a multirole user can switch if they want to + * without logging in/out */ + if(count($u['types']) > 1) { + $_SESSION['multirole'] = true; + } else { + $_SESSION['multirole'] = false; + } + + /* See if there is a redirect, and do that instead of + * taking them to their main page */ + if($redirect != '') { + switch($redirect) { + case 'roleadd': + if(!in_array($multirole_data, $user_types)) + $multirole_data = ''; + + header("location: user_multirole.php?action=add&type=$multirole_data"); + exit; + case 'roleattached': + message_push(happy(i18n('The %1 role has been attached to your account', array($user_what[$type])))); + message_push(notice(i18n('Use the [Switch Roles] link in the upper right to change roles while you are logged in'))); + header("location: {$type}_main.php"); + exit; + + } + } + + /* Now finally, take them to whatever main page they logged in for */ + header("location: {$type}_main.php"); + exit; } - header("location: user_login.php?type=$type¬ice=login_failed"); + + message_push(error(i18n("Invalid Email/Password"))); + header("location: user_login.php?type=$type"); exit; } else if($_GET['action']=="logout") { /* Session keys to skip on logout */ - $skip = array('debug', 'lang'); + $skip = array('debug', 'lang', 'messages'); /* Do these explicitly because i'm paranoid */ unset($_SESSION['name']); @@ -238,9 +257,9 @@ $keys = array_diff(array_keys($_SESSION), $skip); foreach($keys as $k) unset($_SESSION[$k]); - if($notice != 'login_multirole') $notice = 'logged_out'; + message_push(notice(i18n("You have been successfully logged out"))); if($type != '') - header("location: user_login.php?type=$type¬ice=$notice$redirect_url"); + header("location: user_login.php?type=$type$redirect_url"); exit; } else if($_GET['action']=="recover") @@ -283,7 +302,7 @@ if(user_valid_email($email)) { /* valid email address */ $e = mysql_escape_string($email); - $q=mysql_query("SELECT * FROM users WHERE email='$e'"); + $q=mysql_query("SELECT * FROM users WHERE (username='$e' OR email='$e') ORDER BY year DESC LIMIT 1"); $r=mysql_fetch_object($q); if($r) { $fn = trim($_POST['fn']); @@ -291,7 +310,8 @@ /* Check name match */ if(strcasecmp($r->firstname, $fn)!=0 || strcasecmp($r->lastname, $ln)!=0) { - header("Location: user_login.php?type=$type¬ice=recover_name_error"); + message_push(error(i18n("The name you entered does not match the one in your account"))); + header("Location: user_login.php?type=$type"); exit; } @@ -307,55 +327,23 @@ "EMAIL"=>$email) ); - header("Location: user_login.php?type=$type¬ice=recover_sent"); + message_push(notice(i18n("Your password has been sent to your email address"))); + header("Location: user_login.php?type=$type"); exit; } else { - header("Location: user_login.php?type=$type¬ice=recover_email_error"); + message_push(error(i18n("Could not find your email address for recovery"))); + header("Location: user_login.php?type=$type"); exit; } } - header("Location: user_login.php?type=$type¬ice=email_error"); + message_push(error(i18n("Email address error"))); + header("Location: user_login.php?type=$type"); exit; } else { - send_header("{$user_what[$type]} - Login", array()); - switch($notice) { - case 'created_sent': - echo happy(i18n("Your new password has been sent to your email address. Please check your email and use the password to login")); - break; - case 'recover_sent': - echo notice(i18n("Your password has been sent to your email address")); - break; - case 'recover_email_error': - echo error(i18n("Could not find your email address for recovery")); - break; - case 'recover_name_error': - echo error(i18n("The name you entered does not match the one in your account")); - break; - case 'email_error': - echo error(i18n("Email address error")); - break; - case 'login_failed': - echo error(i18n("Invalid Email/Password")); - break; - case 'auth_required': - echo error(i18n("You must login to view that page")); - break; - case 'logged_out': - echo notice(i18n("You have been successfully logged out")); - break; - case 'login_multirole': - echo notice(i18n("You have been successfully logged out")); - echo notice(i18n("Now login to finish adding the new role to your account")); - break; - case 'multirole': - echo notice(i18n("Your email address already exists. Please login to your existing account below and you will be redirected to the multi-role creation page to complete your registration request.")); - break; - } - $recover_link = "user_login.php?type=$type&action=recover"; $new_link = "user_new.php?type=$type"; diff --git a/user_multirole.php b/user_multirole.php index 67f65f6..3fcf2d6 100644 --- a/user_multirole.php +++ b/user_multirole.php @@ -40,7 +40,7 @@ { global $user_what; if(user_add_role_allowed($type, $u) && !in_array($type, $u['types'])) { - echo "
    • {$user_what['volunteer']}"; + echo "
    • {$user_what[$type]}"; //onClick=\"return confirm('Are you sure you want to also be a {$user_what[$type]}?')\" echo '
    • '; return 1; @@ -51,8 +51,6 @@ if($action == 'add') { send_header("Select Additional Roles"); - $u = user_load($_SESSION['users_id']); - //only display the named greeting if we have their name echo i18n("Hello %1",array($_SESSION['name'])); echo "
      "; @@ -77,6 +75,7 @@ echo '
        '; $x += show_role('volunteer', $u); + $x += show_role('judge', $u); if($x == 0) { echo '
      • '; echo i18n('There are no more roles that can be added to your account'); diff --git a/user_new.php b/user_new.php index 23cacb2..6a6c7d2 100644 --- a/user_new.php +++ b/user_new.php @@ -26,16 +26,6 @@ require_once("common.inc.php"); require_once("user.inc.php"); - $type = false; -/* - if(isset($_SESSION['users_type'])) { - send_header("Registration", array()); - echo i18n("Please logout before creating a new user\n"); - send_footer(); - exit; - } - */ - $type = $_GET['type']; if(!in_array($type, $user_types)) { send_header("Registration"); @@ -44,7 +34,6 @@ exit; } - $notice = $_GET['notice']; $action = $_GET['action']; if($action == '') $action = $_POST['action']; @@ -69,7 +58,7 @@ $reg_mode = $config['judge_registration_type']; $reg_single_password = $config['judge_registration_singlepassword']; $password_expiry_days = $config['judges_password_expiry_days']; - $welcome_email = "register_judges_welcome"; + $welcome_email = "judge_welcome"; break; case 'student': $reg_open = 'closed'; @@ -120,7 +109,7 @@ /* Check the registration singlepassword */ if($reg_mode == 'singlepassword') { if($reg_single_password != $_POST['registrationpassword']) { - $notice = 'singlepassword_wrong'; + message_push(error(i18n("The {$user_what[$type]} Registration password you have entered is incorrect."))); break; /* Don't want to create an account */ } } @@ -133,7 +122,9 @@ $r = mysql_fetch_object($q); $types = split(',', $r->types); if(in_array($type, $types)) { - $notice = 'role_exists'; + message_push(error(i18n("That email address has an existing {$user_what[$type]} registration"))); + message_push(notice(i18n("Use the 'recover password' option on the %1 {$user_what[$type]} login page %2 if you have forgotten your password", + array("", "")))); break; /* Don't want to create an account */ } else { /* If they're already logged in, we can go ahead and @@ -146,29 +137,32 @@ * ensuring a student doesn't try to also * register as a judge */ $u = user_load($_SESSION['users_id']); - $u = user_create($type, $u); + $u = user_create($type, $u['username'], $u); $_SESSION['users_type'] = $type; - header("location: user_login.php?action=logout¬ice=login_multirole&redirect=roleattached"); + message_push(notice(i18n("Login to finish adding the new role to your account"))); + + header("location: user_login.php?action=logout&redirect=roleattached"); exit; } /* forward the user to the login page for whatever role * they already have (it doesn't matter), and * setup a login role_add redirect */ - header("location: user_login.php?type={$types[0]}¬ice=multirole&redirect=roleadd&redirectdata=$type"); + message_push(notice(i18n("Your email address already exists. Please login to your existing account below and you will be redirected to the multi-role creation page to complete your registration request."))); + header("location: user_login.php?type={$types[0]}&redirect=roleadd&redirectdata=$type"); exit; } } /* Strict validate the email */ if(!user_valid_email($data_email)) { - $notice = 'email_invalid'; + message_push(error(i18n("The email address is invalid"))); $data_email = ''; break; /* Don't want to create an account */ } /* Check the names */ if($data_fn == '' or $data_ln == '') { - $notice = 'name_invalid'; + message_push(error(i18n("You must enter your first and last name"))); break; /* Don't want to create an account */ } @@ -177,10 +171,9 @@ /* Add the user, user_create sets a random/expired password, * so we'll just use that */ - $u = user_create($type); + $u = user_create($type, $data_email); $u['firstname'] = $data_fn; $u['lastname'] = $data_ln; - $u['username'] = $data_email; $u['email'] = $data_email; user_save($u); @@ -192,38 +185,14 @@ ); /* now redirect to the login page */ - header("Location: user_login.php?type=$type¬ice=created_sent"); + message_push(happy(i18n("Your new password has been sent to your email address. Please check your email and use the password to login"))); + header("Location: user_login.php?type=$type"); exit; } send_header("{$user_what[$type]} Registration", array("{$user_what[$type]} Login" => "user_login.php?type=$type") ); - switch($notice) { - case 'email_invalid': - echo '
        '; - echo error(i18n("The email address is invalid")); - echo '
        '; - break; - case 'name_invalid': - echo '
        '; - echo error(i18n("You must enter your first and last name")); - echo '
        '; - break; - case 'singlepassword_wrong': - echo '
        '; - echo error(i18n("The {$user_what[$type]} Registration Password you have entered is incorrect.")); - echo '
        '; - break; - case 'role_exists': - echo '
        '; - echo error(i18n("That email address has an existing {$user_what[$type]} registration")); - echo notice(i18n("Use the 'recover password' option on the %1 {$user_what[$type]} login page %2 if you have forgotten your password", - array("", ""))); - echo '
        '; - break; - } - ?>
        @@ -239,8 +208,9 @@
    "; - echo i18n("Remember, once you click the Register button below, you will be logged out. You can immediately log back in."); + echo i18n("Remember, once you click the Register button below, you will be logged out. Log back in to complete the registration."); echo "
    "; + echo "'; diff --git a/user_password.php b/user_password.php index 81243df..8a0dbe3 100644 --- a/user_password.php +++ b/user_password.php @@ -31,24 +31,25 @@ if(isset($_SESSION['users_type'])) { $type = $_SESSION['users_type']; } else { - header("location: {$config['SFIABDIRECTORY']}/index.php?notice=auth_required"); + message_push(error(i18n("You must login to view that page"))); + header("location: {$config['SFIABDIRECTORY']}/index.php"); exit; } /* Make sure the user is logged in, but don't check passwd expiry */ if(!isset($_SESSION['users_type'])) { - header("location: {$config['SFIABDIRECTORY']}/user_login.php?type=$type¬ice=auth_required"); + message_push(error(i18n("You must login to view that page"))); + header("location: {$config['SFIABDIRECTORY']}/user_login.php?type=$type"); exit; } if($_SESSION['users_type'] != $type) { - header("location: {$config['SFIABDIRECTORY']}/user_login.php?type=$type¬ice=auth_required"); + message_push(error(i18n("You must login to view that page"))); + header("location: {$config['SFIABDIRECTORY']}/user_login.php?type=$type"); exit; } - $notice=$_GET['notice']; - $back_link = "{$type}_main.php"; $password_expiry_days = $config["{$type}_password_expiry_days"]; @@ -61,15 +62,20 @@ id='{$_SESSION['users_id']}' AND password='$pass'"); - if(mysql_num_rows($q)) $notice = 'same'; - else if(!$_POST['pass1']) $notice = 'passwordrequired'; - else if($_POST['pass1'] != $_POST['pass2']) $notice = 'nomatch'; - else if(user_valid_password($_POST['pass1']) == false) $notice = 'invalidchars'; + if(mysql_num_rows($q)) + message_push(error(i18n("You cannot choose the same password again. Please choose a different password"))); + else if(!$_POST['pass1']) + message_push(error(i18n("New Password is required"))); + else if($_POST['pass1'] != $_POST['pass2']) + message_push(error(i18n("Passwords do not match"))); + else if(user_valid_password($_POST['pass1']) == false) + message_push(error(i18n("The password contains invalid characters or is not long enough"))); else { user_set_password($_SESSION['users_id'], $pass); unset($_SESSION['password_expired']); - header("location: $back_link?notice=password_changed"); + message_push(happy(i18n('Your password has been successfully updated'))); + header("location: $back_link"); exit; } } @@ -84,22 +90,6 @@ echo i18n('Your password has expired. You must choose a new password now.'); } - switch($notice) { - case 'same': - echo error(i18n("You cannot choose the same password again. Please choose a different password")); - break; - case 'passwordrequired': - echo error(i18n("New Password is required")); - break; - case 'nomatch': - echo error(i18n("Passwords do not match")); - break; - case 'invalidchars': - echo error(i18n("The password contains invalid characters or is not long enough")); - - default: - } - echo "\n"; echo "\n"; echo "\n"; diff --git a/user_personal.php b/user_personal.php index 06ff640..671345c 100644 --- a/user_personal.php +++ b/user_personal.php @@ -34,6 +34,7 @@ } $user_personal_fields = array( + 'salutation' => array('name' => 'Salutation'), 'firstname' => array('name' => 'First Name'), 'lastname' => array('name' => 'Last Name'), 'email' => array('name' => 'Email Address'), @@ -70,20 +71,26 @@ /* See if there is an edit request */ - $eid = intval($_GET['edit']); + if($_SESSION['embed_edit_id']) + $eid = $_SESSION['embed_edit_id']; + else + $eid = intval($_GET['edit']); - if($eid != 0) { - /* There is an edit request, the user must be: + /* Force them to edit themselves if no eid found */ + if($eid == 0) $eid = $_SESSION['users_id']; + + if($_SESSION['users_id'] != $eid) { + /* There is an edit request for someone other than the logged in user, + * the user must be: * - on the committee * - with admin access */ user_auth_required('committee', 'admin'); - $u = user_load($eid, true); - + $ext_editor = true; } else { - /* Else, force them to edit themselves */ - $eid = false; - $u = user_load($_SESSION['users_id'], true); + /* Else, they are just editing themselves */ + $ext_editor = false; } + $u = user_load($eid); /* Load the fields the user can edit, and theones that are required */ @@ -146,57 +153,40 @@ /* Check for an email collision */ $em = mysql_escape_string(stripslashes($_POST['email'])); - $q=mysql_query("SELECT id FROM users WHERE email='$em' AND id!='{$u['id']}'"); + $q=mysql_query("SELECT id FROM users WHERE email='$em' AND uid!='{$u['uid']}' AND deleted='no'"); if(mysql_num_rows($q) > 0) { - $notice = 'email_exists'; + message_push(error(i18n("That email address is in use by another user"))); $save = false; } if($save == true) { user_save($u); - if($_SESSION['last_page'] == 'committee_management') { - header("location: {$config['SFIABDIRECTORY']}/admin/committees.php"); - exit; - } - $notice = 'success'; + message_push(notice(i18n("%1 %2 successfully updated",array($_POST['firstname'],$_POST['lastname'])))); } } + $type = $_SESSION['users_type']; //send the header - if($eid == false) { - $type = $_SESSION['users_type']; - $m = ($type == 'committee') ? 'Committee' : $user_what[$type]; - send_header("Personal Information", + if($_SESSION['embed'] == true) { + echo "
    "; + display_messages(); + echo "

    ".i18n("Personal Information")."

    "; + echo "
    "; + } else if($ext_editor == true) { + $m = ($type == 'committee') ? 'Committee' : $user_what[$type]; + send_header("Personal Information", array("$m Main" => "{$type}_main.php") ,"edit_profile" ); } else { - if($_SESSION['last_page'] == 'committee_management') { - send_header("Personal Information for {$u['firstname']} {$u['lastname']}", - array('Committee Main' => 'committee_main.php', - 'Administration' => 'admin/index.php', - 'Committee Management' => 'admin/committees.php') + send_header("Personal Information for {$u['firstname']} {$u['lastname']}", + array($user_what[$type]." Registration" => "{$type}_main.php") ,"edit_profile" ); - } else { - send_header("Personal Information for {$u['firstname']} {$u['lastname']}", - array("Committee Main" => "committee_main.php") - ,"edit_profile" - ); - } } - switch($notice) { - case 'success': - echo notice(i18n("%1 %2 successfully updated",array($_POST['firstname'],$_POST['lastname']))); - break; - case 'email_exists': - echo error(i18n("That email address is in use by another user")); - break; - } - foreach($errorfields as $f) { echo error(i18n('\'%1\' must use the format: %2', array(i18n($user_personal_fields[$f]['name']), @@ -204,13 +194,14 @@ } if(count($errorfields)) { echo error(i18n('Information will not be saved until the above errors are corrected')); - } else if ($eid == false) { + } else { //output the current status $newstatus=user_personal_info_status($u); if($newstatus!='complete') echo error(i18n("Personal Information Incomplete")); else echo happy(i18n("Personal Information Complete")); + } if(count($u['types']) > 1) { @@ -256,11 +247,12 @@ function item($user, $fname, $subtext='') } - $eidstr = ''; - if($eid != false) { - $eidstr="?edit=$eid"; + if($_SESSION['embed'] != true) { + echo "\n"; + } else { + echo "\n"; } - echo "\n"; + echo "\n"; echo "
    \n"; @@ -270,7 +262,7 @@ item($u, 'lastname'); echo "\n"; echo "\n"; item($u, 'email'); -echo ''; +item($u, 'salutation'); echo "\n"; echo "\n"; item($u, 'username', '(if different from Email)'); @@ -369,5 +361,8 @@ echo ""; echo "
    "; -send_footer(); +if($_SESSION['embed'] != true) { + send_footer(); +} + ?> diff --git a/volunteer.inc.php b/volunteer.inc.php index 41cdecc..4da0022 100644 --- a/volunteer.inc.php +++ b/volunteer.inc.php @@ -25,11 +25,11 @@ = 1) { @@ -37,4 +37,20 @@ function volunteer_status_position($u = false) } return "incomplete"; } + +function volunteer_status_update(&$u) +{ + global $config; + + if( user_personal_info_status($u) == 'complete' + && volunteer_status_position($u) == 'complete' ) + $u['volunteer_complete'] = 'yes'; + else + $u['volunteer_complete'] = 'no'; + + user_save($u); + return ($u['volunteer_complete'] == 'yes') ? 'complete' : 'incomplete'; + +} + ?> diff --git a/volunteer_main.php b/volunteer_main.php index 76a5437..1a95fd2 100644 --- a/volunteer_main.php +++ b/volunteer_main.php @@ -30,20 +30,16 @@ user_auth_required('volunteer'); - send_header("Volunteer Registration", array()); + $u = user_load($_SESSION['users_id']); - switch($_GET['notice']) { - case 'password_changed': - echo happy(i18n('Your password has been successfully updated')); - break; - case 'already_logged_in': - echo error(i18n('You are already logged in, please use the [Logout] link in the upper right to logout before loggin in as different user')); - break; - case 'attached': - echo happy(i18n('The Volunteer role has been attached to your account. Use the [Switch Roles] link in the upper right to change roles while you are logged in')); - break; + if($u['volunteer_active'] == 'no') { + message_push(notice(i18n("Your volunteer role is not active. If you would like to participate as a volunteer for the %1 %2 please click the 'Activate Role' button in the Volunteer section below",array($config['FAIRYEAR'],$config['fairname'])))); + header('Location: user_activate.php'); + exit; } + send_header("Volunteer Main", array()); + //only display the named greeting if we have their name echo i18n("Hello %1",array($_SESSION['name'])); echo "
    "; @@ -53,8 +49,6 @@ echo "
    "; echo "
    "; - $u = user_load($_SESSION['users_id']); - user_page_summary_begin(); user_page_summary_item("Contact Information", "user_personal.php", "user_personal_info_status", array($u)); @@ -62,11 +56,8 @@ "volunteer_position.php", "volunteer_status_position", array($u)); $overallstatus = user_page_summary_end(true); - /* A bit of a FIXME here, if a user completes everythign but doesn't refresh - this page, they will never be marked as complete. Not sure how to handle - this, it's kinda hackey to call EVERY status() fucntion within EACH page to - get teh overall status. */ - user_update_complete($u, $overallstatus); + /* Update volunteer_status */ + volunteer_status_update($u); echo "
    "; echo "
    "; @@ -82,7 +73,11 @@ echo "
    "; echo i18n('Other Options and Things To Do').':
    '; echo ''; send_footer(); diff --git a/volunteer_position.php b/volunteer_position.php index 0ffe618..ad93349 100644 --- a/volunteer_position.php +++ b/volunteer_position.php @@ -27,18 +27,13 @@ require_once("user.inc.php"); require_once("volunteer.inc.php"); - user_auth_required('volunteer'); - $u = user_load($_SESSION['users_id']); - - - /* Load the user's volunteer position selections */ - - //send the header - $type = $_SESSION['users_type']; - send_header("{$user_what[$type]} - Volunteer Positions", - array("{$user_what[$type]} Registration" => "{$type}_main.php") - ); + if($_SESSION['embed'] == true) { + $u = user_load($_SESSION['embed_edit_id']); + } else { + user_auth_required('volunteer'); + $u = user_load($_SESSION['users_id']); + } if($_POST['action']=="save") @@ -59,14 +54,14 @@ if(!in_array($id, $posns)) continue; if($vals != '') $vals .=','; - $vals .= "('{$_SESSION['users_id']}','$id','{$config['FAIRYEAR']}')"; + $vals .= "('{$u['id']}','$id','{$config['FAIRYEAR']}')"; } } /* Delete existing selections */ mysql_query("DELETE FROM volunteer_positions_signup WHERE - users_id='{$_SESSION['users_id']}' + users_id='{$u['id']}' AND year='{$config['FAIRYEAR']}' "); echo mysql_error(); @@ -79,28 +74,41 @@ } - echo notice(i18n("Volunteer Positions successfully updated")); + message_push(notice(i18n("Volunteer Positions successfully updated"))); } -//output the current status -$newstatus=volunteer_status_position($u); -if($newstatus!='complete') -{ - echo error(i18n("Volunteer Position Selection Incomplete")); -} -else -{ - echo happy(i18n("Volunteer Position Selection Complete")); +/* update overall status */ +volunteer_status_update($u); + +if($_SESSION['embed'] != true) { + //output the current status + $newstatus=volunteer_status_position($u); + if($newstatus!='complete') + message_push(error(i18n("Volunteer Position Selection Incomplete"))); + else + message_push(happy(i18n("Volunteer Position Selection Complete"))); } +if($_SESSION['embed'] == true) { + echo "
    "; + display_messages(); + echo "

    ".i18n('Volutneer Positions')."

    "; + echo "
    "; +} else { + //send the header + send_header("Volunteer Positions", + array("Volunteer Registration" => "volunteer_main.php") + ); +} - echo "\n"; + $s = ($_SESSION['embed'] == true) ? $_SESSION['embed_submit_url'] : 'volunteer_position.php'; + echo "\n"; echo "\n"; echo "
    \n"; /* Read current selections */ $q = "SELECT * FROM volunteer_positions_signup WHERE - users_id = '{$_SESSION['users_id']}' + users_id = '{$u['id']}' AND year='{$config['FAIRYEAR']}'"; $r = mysql_query($q); $checked_positions = array(); @@ -154,5 +162,5 @@ echo ""; echo "
    "; -send_footer(); + if($_SESSION['embed'] != true) send_footer(); ?> diff --git a/xmltransport.php b/xmltransport.php new file mode 100644 index 0000000..2f1eafc --- /dev/null +++ b/xmltransport.php @@ -0,0 +1,175 @@ + + Copyright (C) 2005 James Grant + Copyright (C) 2009 David Grant + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +?> +$v) { + $stats[$k] = mysql_escape_string($stats[$k]); + } + +// $str = join(',',$stats); + $keys = '`fairs_id`,`'.join('`,`', array_keys($stats)).'`'; + $vals = "'{$u['fairs_id']}','".join("','", array_values($stats))."'"; + mysql_query("DELETE FROM fairs_stats WHERE fairs_id='{$u['fairs_id']}' + AND year='{$stats['year']}'"); + echo mysql_error(); + mysql_query("INSERT INTO fairs_stats (`id`,$keys) VALUES ('',$vals)"); + echo mysql_error(); + + $response['message'] = 'Stats saved'; + $response['error'] = 0; +} + +function handle_getawards(&$u, $fair, &$data, &$response) +{ + $awards = array(); + $year = $data['getawards']['year']; + + $ids = unserialize($fair['award_awards_ids']); + + $where = "id='".join("' OR id='", $ids)."'"; + + $q = mysql_query("SELECT * FROM award_awards WHERE $where"); + + while($a = mysql_fetch_assoc($q)) { + $award = array(); + $award['identifier'] = ""; + $award['year'] = $a['year']; + $award['name_en'] = $a['name']; + $award['criteria_en'] = $a['criteria']; + + if($a['sponsors_id']) { + $sq = mysql_query("SELECT * FROM sponsors WHERE id='{$a['sponsors_id']}'"); + if(mysql_num_rows($sq)) { + $s = mysql_fetch_assoc($sq); + $award['sponsor'] = $s['organization']; + } + } + + $award['prizes'] = array(); + $pq = mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='{$a['id']}'"); + while($p = mysql_fetch_assoc($pq)) { + $prize = array(); + $prize['identifier'] = ""; + $prize['cash'] = $p['cash'];; + $prize['scholarship'] = $p['scholarship']; + $prize['value'] = $p['value']; + $prize['prize_en'] = $p['prize']; + $prize['number'] = $p['number']; + $prize['ord'] = $p['order']; + $award['prizes'][] = $prize; + } + $awards[] = $award; + } + $response['awards'] = $awards; + $response['postback'] = 'http://localhost'; +} + + + /* magic quotes DEPRECATED as of PHP 5.3.0, REMOVE as of 6.0, on by default * + * for any PHP < 5.3.0. Pain in the ASS. php is running the urldecode for us, + * seeing that the string has quotes, then adding quotes before we can + * json_decode() + * It only does this in POST and GET */ + if(get_magic_quotes_gpc()) + $data = json_decode(stripslashes($_POST['json']), true); + else + $data = json_decode($_POST['json'], true); + +// echo "post:";print_r($_POST); +// echo "json post: ".htmlspecialchars($_POST['json'])."
    "; +// echo "stripslashes(json post): ".stripslashes($_POST['json'])."
    "; +// echo "data:";print_r($data); +// echo "
    "; +// exit; + + $username = $data['auth']['username']; + $password = $data['auth']['password']; + + $response['query'] = $data; + +// echo "Authenticating... "; + $username = mysql_escape_string($username); + $q=mysql_query("SELECT uid FROM users WHERE username='$username'"); + if(mysql_num_rows($q) != 1) { + $response['error'] = 1; + $response['message'] = "Authentication Failed"; + echo json_encode($response); + exit; + } + $i = mysql_fetch_assoc($q); + $u = user_load_by_uid($i['uid']); + $response['i'] = $i; + if(!is_array($u) || $u['password'] == '') { + $response['error'] = 1; + $response['message'] = "Authentication Failed2"; + echo json_encode($response); + exit; + } + + if($u['password'] != $password) { + $response['error'] = 1; + $response['message'] = "Authentication Failed3"; + echo json_encode($response); + exit; + } + + $q = mysql_query("SELECT * FROM fairs WHERE id='{$u['fairs_id']}'"); + $fair = mysql_fetch_assoc($q); + + $response = array(); + if(array_key_exists('getstats', $data)) handle_getstats($u,$fair, $data, $response); + if(array_key_exists('stats', $data)) handle_stats($u,$fair, $data, $response); + if(array_key_exists('getawards', $data)) handle_getawards($u,$fair,$data, $response); + + echo urlencode(json_encode($response)); +// echo "Success!
    "; + + +?>