diff --git a/db/db.update.118.php b/db/db.update.118.php index 8c173af..ab019cd 100644 --- a/db/db.update.118.php +++ b/db/db.update.118.php @@ -2,6 +2,8 @@ function db_update_118_post() { global $config; + $available="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789"; + $availlen=strlen($available) - 1; $userfields=array("salutation","firstname","lastname","email","phonehome","phonework","phonecell","fax"); @@ -42,8 +44,24 @@ function db_update_118_post() } else { - $sql="INSERT INTO users (`types`,`username`,`".implode("`,`",$userfields)."`,`year`) VALUES ("; - $sql.="'sponsor','".mysql_real_escape_string($r->email)."'"; + //we need a username, if htere's no email, then we need to gerneate one to use. + if($r->email) { + $username=$r->email; + } + else { + $username=""; + for($x=0;$x<16;$x++) + $username.=$available{rand(0,$availlen)}; + } + + //and create them a password + $password=""; + for($x=0;$x<8;$x++) + $password.=$available{rand(0,$availlen)}; + + //set passwordset to 0000-00-00 to force it to expire on next login + $sql="INSERT INTO users (`types`,`username`,`created`,`password`,`passwordset`,`".implode("`,`",$userfields)."`,`year`) VALUES ("; + $sql.="'sponsor','".mysql_real_escape_string($username)."',NOW(),'$password','0000-00-00'"; foreach($userfields AS $f) { $sql.=",'".mysql_real_escape_string($r->$f)."'"; } @@ -69,7 +87,6 @@ function db_update_118_post() '".mysql_real_escape_string($r->notes)."')"); echo mysql_error(); } - } ?> diff --git a/db/db.update.119.sql b/db/db.update.119.sql new file mode 100644 index 0000000..f641eea --- /dev/null +++ b/db/db.update.119.sql @@ -0,0 +1 @@ +DROP TABLE award_contacts; diff --git a/sponsor_main.php b/sponsor_main.php new file mode 100644 index 0000000..ab1800a --- /dev/null +++ b/sponsor_main.php @@ -0,0 +1,47 @@ + + 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'])); + 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"; + + send_footer(); +?> diff --git a/user.inc.php b/user.inc.php index 5bc4686..13afe6e 100644 --- a/user.inc.php +++ b/user.inc.php @@ -24,10 +24,10 @@ ?> 'Participant', 'judge' => 'Judge', 'committee'=>'Committee Member','volunteer' => 'Volunteer', - 'fair'=>'Science Fair'); + 'fair'=>'Science Fair','sponsor' => 'Sponsor Contact'); /* Duplicate of common.inc.php:generatePassword, which will be deleted @@ -107,6 +107,21 @@ function user_load_volunteer(&$u) return true; } +function user_load_sponsor($u) +{ + /* Double check, make sure the user is of this type */ + if(!in_array('sponsor', $u['types'])) return false; + + $q = mysql_query("SELECT * FROM users_sponsor + WHERE users_id='{$u['id']}'"); + if(mysql_num_rows($q)!=1) return false; + + $r = mysql_fetch_object($q); + $ret = array(); + $ret['sponsors_id'] = $r->sponsors_id; + return $ret; +} + function user_load($user) { $id = intval($user); @@ -267,6 +282,10 @@ function user_save_fair($u) user_save_type_list($u, 'users_fair', $fields); } +function user_save_sponsor($u) +{ +} + function user_save($u) { $fields = array('firstname','lastname','username', @@ -329,10 +348,15 @@ function user_delete_judge($u) function user_delete_fair($u) { } + function user_delete_student($u) { } +function user_delete_sponsor($u) +{ +} + function user_delete($u, $type=false) { $finish_delete = false; @@ -495,7 +519,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]; @@ -540,6 +565,9 @@ function user_create($type, $u = NULL) case 'committee': mysql_query("INSERT INTO users_committee(`users_id`, `committee_active`) VALUES ('$uid', 'yes')"); break; + case 'sponsor': + mysql_query("INSERT INTO users_sponsor(`users_id`) VALUES ('$uid')"); + break; } return user_load($uid); } diff --git a/user_login.php b/user_login.php index fa9fe8a..0e2fcdf 100644 --- a/user_login.php +++ b/user_login.php @@ -48,8 +48,8 @@ $q = mysql_query("SELECT id,username,password,year,deleted FROM users WHERE username='$user' - ORDER BY year DESC"); - echo mysql_error(); + AND deleted='no' + ORDER BY year DESC LIMIT 1"); if(mysql_num_rows($q) < 1) return false; $r = mysql_fetch_object($q); @@ -115,6 +115,9 @@ case 'fair': $reg_open = 'notpermitted'; break; + case 'sponsor': + $reg_open = 'notpermitted'; + break; case 'student': default: exit; @@ -298,7 +301,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']);