diff --git a/admin/award_contacts.php b/admin/award_contacts.php index ec7646f..cc05c38 100644 --- a/admin/award_contacts.php +++ b/admin/award_contacts.php @@ -4,7 +4,7 @@ SFIAB Website: http://www.sfiab.ca Copyright (C) 2005 Sci-Tech Ontario Inc - Copyright (C) 2005 James Grant + 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 @@ -26,29 +26,28 @@ require_once("../user.inc.php"); user_auth_required('committee', 'admin'); - send_header("Award Contacts", + send_header("Sponsor Contacts", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php', - 'Awards Main' => 'admin/awards.php', - 'Awards Sponsors' => 'admin/award_sponsors.php')); + 'Sponsors' => 'admin/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']; + if($_GET['sponsors_id']) + $sponsors_id=$_GET['sponsors_id']; + else if($_POST['sponsors_id']) + $sponsors_id=$_POST['sponsors_id']; ?> "; - 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=""; @@ -57,107 +56,107 @@ echo ""; echo ""; - if($award_sponsors_id) + if($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(); + if($_POST['save']=="add") { + $u=user_create("sponsor"); + $id=$u['id']; } - else + else { + $u=user_load($_POST['id']); $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']} + /* 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 id!='$id'"); + 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 award_contacts SET `primary`='no' - WHERE award_sponsors_id='$award_sponsors_id' - AND year={$config['FAIRYEAR']}"); + mysql_query("UPDATE users_sponsor SET `primary`='no' + WHERE sponsors_id='$sponsors_id'"); } - $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); + $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("Contact successfully added"); + echo happy(i18n("Contact successfully added")); else - echo happy("Successfully saved changes to contact"); + echo happy(i18n("Successfully saved changes to contact")); } - if($_GET['action']=="delete" && $_GET['delete']) - { - mysql_query("DELETE FROM award_contacts WHERE id='".$_GET['delete']."'"); + 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($award_sponsors_organization))."\n"; + echo "<< ".i18n("Back to %1 Contacts",array($sponsors_organization))."\n"; if($_GET['action']=="edit") { - echo "

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

\n"; + echo "

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

\n"; $buttontext="Save Contact"; - $q=mysql_query("SELECT * FROM award_contacts WHERE id='".$_GET['edit']."'"); - $r=mysql_fetch_object($q); +// $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($award_sponsors_organization))."

\n"; + echo "

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

\n"; $buttontext="Add Contact"; } $buttontext=i18n($buttontext); - echo "
\n"; - echo "\n"; + 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 "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; echo "\n"; @@ -169,14 +168,16 @@ { echo "
"; - echo "".i18n("Add New Contact to %1",array($award_sponsors_organization))."\n"; + echo "".i18n("Add New Contact to %1",array($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"); + $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' ORDER BY lastname,firstname"); + echo mysql_Error(); if(mysql_num_rows($q)) { - 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("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")."
"; + echo "
"; echo ""; echo " "; echo " "; @@ -194,35 +195,31 @@ if($r->salutation) echo $r->salutation." "; echo "$r->firstname $r->lastname\n"; echo " "; + echo " "; echo " \n"; echo " \n"; - $p = i18n(($r->primary=='yes')?'Yes':''); + $p = i18n(($r->primary=='yes')?'Yes':'No'); echo " \n"; echo " \n"; echo "\n"; } echo "
".i18n("Name")."".i18n("Email").""; - if($r->email) - { + if($r->email) { list($eb,$ea)=split("@",$r->email); echo ""; } else echo " "; - echo "$r->phonework$r->phonecell$p"; - echo "id\">"; + //FIXME: should we just go to /user_personal.php here instead? + echo "id\">"; echo " "; - echo "id\">"; - - + echo "id\">"; echo "
\n"; } - } - } send_footer(); diff --git a/admin/sponsors.php b/admin/sponsors.php index aeb947a..a999862 100644 --- a/admin/sponsors.php +++ b/admin/sponsors.php @@ -148,6 +148,7 @@ echo ""; echo ""; echo " "; + echo " "; echo " "; echo " "; echo " "; @@ -159,36 +160,34 @@ 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 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 WHERE sponsors_id='$r->id'"); $numr=mysql_fetch_object($numq); $numcontacts=$numr->num; + echo " "; + echo " "; + echo " "; echo "
Organization# of Sponsorships# of Awards# of ContactsAction
\n"; - if($r->confirmed=='yes') - { - echo "id\">\"ok_alt\"\n"; - } - else - { - echo "id\">confirm"; - } - echo "$r->organization"; + echo "$numsponsorships  "; + echo "id\">\"view\""; + echo ""; echo "$numawards  "; echo "id\">\"view\""; echo ""; echo "$numcontacts  "; - echo "id\">\"view\""; + echo "id\">\"view\""; echo ""; echo "id\">"; diff --git a/user.inc.php b/user.inc.php index cbb075d..1db3714 100644 --- a/user.inc.php +++ b/user.inc.php @@ -102,14 +102,16 @@ function user_load_committee(&$u) function user_load_volunteer(&$u) { - $u['volunteer_active'] = ($u['>volunteer_active'] == 'yes') ? 'yes' : 'no'; - $u['volunteer_complete'] = ($u['>volunteer_complete'] == 'yes') ? 'yes' : 'no'; + $u['volunteer_active'] = ($u['volunteer_active'] == 'yes') ? 'yes' : 'no'; + $u['volunteer_complete'] = ($u['volunteer_complete'] == 'yes') ? 'yes' : 'no'; return true; } function user_load_sponsor($u) { $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; } @@ -234,12 +236,15 @@ function user_save_type_list($u, $db, $fields) else $data = mysql_escape_string(stripslashes($u[$f])); - $set .= "$f='$data'"; + $set .= "`$f`='$data'"; } if($set != "") { $query = "UPDATE $db SET $set WHERE users_id='{$u['id']}'"; mysql_query($query); - echo mysql_error(); + if(mysql_error()) { + echo mysql_error(); + echo error("Full query: $query"); + } } } @@ -279,11 +284,13 @@ function user_save_fair($u) 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', @@ -526,10 +533,12 @@ function user_add_role_allowed($type, $u) function user_create($type, $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`,`passwordset`,`created`,`year`) + VALUES ('$type', '0000-00-00', NOW(), '{$config['FAIRYEAR']}')"); $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,