diff --git a/admin/user_list.php b/admin/user_list.php index b20267f..3e18f38 100644 --- a/admin/user_list.php +++ b/admin/user_list.php @@ -29,12 +29,17 @@ require_once('judges.inc.php'); +$user_what = array(); + $query = mysql_query("SELECT `type`, `name` FROM roles"); + while($row = mysql_fetch_assoc($query)){ + $user_what[$row['type']] = $row['name']; + } + $show_types = $_GET['show_types']; - if(user_valid_type($show_types) == false) $show_types = array('judge'); + if(user_valid_role($show_types) == false) $show_types = array('judge'); $show_complete = ($_GET['show_complete'] == 'yes') ? 'yes' : 'no'; - $show_year = ($_GET['show_year'] == 'current') ? 'current' : 'all'; - + $show_all = ($_GET['show_all'] == 'yes') ? 'yes' : 'no'; $uid = intval($_GET['uid']); if($_GET['action']=='remove') { @@ -124,12 +129,12 @@ function neweditor() echo ""; echo ""; - echo "".i18n('Year').":"; - echo ""; + $s = ($show_all == 'no') ? 'selected="selected"' : ''; + echo ""; + $s = ($show_all == 'yes') ? 'selected="selected"' : ''; + echo ""; echo ""; echo ""; echo "
"; @@ -165,56 +170,40 @@ function neweditor() echo "
"; /* Grab a list of users */ - $w = array(); - foreach($show_types as $t) { - $w [] = "u1.types LIKE '%$t%'"; + $clauses = array(); + $roles = array(); + foreach($show_types as $t){ + $roles[] = "type = '$t'"; } - $where_types = "AND (".join(" OR ", $w).")"; + if(count($roles) > 0) $clauses[] = 'ur.roles_id IN(SELECT id FROM roles WHERE ' . implode(' OR ', $roles) . ')'; + if($show_complete == 'yes') $clauses[] = 'ur.complete = "yes"'; + if($show_all == 'no') $clauses[] = "u1.conferences_id={$conference['id']}"; - $where_complete = ""; - if($show_complete == 'yes') { - foreach($show_types as $t) { - $where_complete .= "AND ({$t}_complete='yes' OR {$t}_complete IS NULL) "; - } + $querystr = + "SELECT u1.id as userid, u1.*, ur.*, conferences.name AS conference_name " . + "FROM users u1 " . + "LEFT JOIN user_roles ur ON ur.users_id = u1.id " . + "JOIN conferences ON u1.conferences_id = conferences.id "; + + if(count($clauses) > 0){ + $querystr .= "WHERE " . implode(' AND ', $clauses) . " "; } - if($show_year == 'current') - $having_year = "AND u1.year={$config['FAIRYEAR']}"; + $querystr .= + "GROUP BY u1.accounts_id " . + "HAVING u1.deleted = 'no' " . + "ORDER BY lastname ASC, firstname ASC, conferences_id DESC "; + $q = mysql_query($querystr); + $num = mysql_num_rows($q); + echo i18n("Listing %1 people total. See the bottom for breakdown by complete status",array($num)); + echo mysql_error(); echo ""; - - $querystr="SELECT - * - FROM - users u1 - LEFT JOIN `users_committee` ON `users_committee`.`users_id`=`u1`.`id` - LEFT JOIN `users_judge` ON `users_judge`.`users_id`=`u1`.`id` - LEFT JOIN `users_volunteer` ON `users_volunteer`.`users_id`=`u1`.`id` - LEFT JOIN `users_fair` ON `users_fair`.`users_id`=`u1`.`id` - LEFT JOIN `users_sponsor` ON `users_sponsor`.`users_id`=`u1`.`id` - WHERE u1.year=( SELECT MAX(`year`) FROM users u2 WHERE u1.uid=u2.uid ) - GROUP BY uid - HAVING - u1.deleted='no' - $having_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 " "; @@ -227,48 +216,49 @@ function neweditor() $tally['inactive'] = array(); $tally['active']['complete'] = 0; $tally['active']['incomplete'] = 0; + $tally['active']['na'] = 0; $tally['inactive']['complete'] = 0; $tally['inactive']['incomplete'] = 0; + $tally['inactive']['na'] = 0; while($r=mysql_fetch_assoc($q)) { - //JAMES - TEMP - due to the previous error with improperly setting judge status to NOT complete when special awards was turned off - //we now need to make sure we re-calculate all the judge statuses somehow, so might as well do it here. - //FIXME: remove this after all the fairs are done this year SUMMER 2010 - if(in_array('judge',$show_types)){ - $u=user_load_by_uid($r['uid']); - - //we also set teh $r array so it displays properly on first load - if(judge_status_update($u)=="complete") - $r['judge_complete']='yes'; + // get the role data for this user + $roleData = array(); + $roleQuery = mysql_query("SELECT * FROM roles JOIN user_roles ON user_roles.roles_id = roles.id WHERE user_roles.users_id = " . $r['userid']); + while($dat = mysql_fetch_assoc($roleQuery)){ + //print_r($roleData); + $roleData[] = $dat; + $roleTypes[] = $dat['type']; } - $types = split(',', $r['types']); - $span = count($types) > 1 ? "rowspan=\"".count($types)."\"" : ''; + + $span = count($roleData) > 1 ? "rowspan=\"".count($roleData)."\"" : ''; echo ""; echo ""; - echo ""; + echo ""; $first = true; $complete = false; $incomplete = false; - foreach($types as $t) { + foreach($roleData as $roleData) { if(!$first) echo ''; - echo ""; + echo ""; echo ""; echo "
".i18n("Name")."".i18n("Email Address")."".i18n("Year")."".i18n("Conference")."".i18n("Type(s)")."".i18n("Active")."".i18n("Complete")."
"; $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']}'"); + if(in_array('fair', $roleTypes)) { + $qq = mysql_query("SELECT * FROM fairs WHERE id = " . $r['fairs_id']); + echo $qq.";
"; $rr = mysql_fetch_assoc($qq); $name = "{$rr['name']}".((trim($name)=='') ? '' : "
($name)"); - } + } + if(strlen(trim($name)) == 0) $name = "<" . i18n("not specified") . ">"; + echo "$name"; echo "
{$r['email']}{$r['year']}{$r['conference_name']}
{$user_what[$t]}{$roleData['name']}"; - if($r["{$t}_active"] == 'yes') { + if($roleData["active"] == 'yes') { echo "
".i18n("yes")."
"; $userstate = 'active'; } else { @@ -278,9 +268,9 @@ function neweditor() echo "
"; - if(in_array($t, array('parent','committee','alumni','mentor','fair'))) { + if(in_array($roleData['type'], array('parent','committee','alumni','mentor','fair'))) { /* Do nothing, there's nothing to complete */ - } else if($r["{$t}_complete"] == 'yes') { + } else if($roleData["complete"] == 'yes') { echo "
".i18n("yes")."
"; $complete = true; } else { @@ -305,6 +295,8 @@ function neweditor() $tally[$userstate]['complete']++; }else if($incomplete){ $tally[$userstate]['incomplete']++; + }else{ + $tally[$userstate]['na']++; } } @@ -315,11 +307,12 @@ function neweditor() ?> - + + @@ -328,16 +321,19 @@ function neweditor() - + + - + + +
List Totals
List Totals
Complete IncompleteN/A Total
Active
Inactive
Total