From 62941df8801527113838b7c08f8a55da0141b50c Mon Sep 17 00:00:00 2001 From: dave Date: Tue, 8 Sep 2009 17:34:52 +0000 Subject: [PATCH] - new htabs - beginnings of a jquery award editor - sfiab->sfiab award downloading - move most javascript into a sfiab.js file, so it can be cached and only pulled from the server once (instead of inline with the code each time) --- admin/award_awards.php | 277 ++++++++++++++++++++++++++++++++++- admin/user_editor_window.php | 32 ++-- common.inc.php | 47 +----- htabs.css | 64 -------- htabs.inc.php | 79 ++++++++++ sfiab.js | 105 +++++++++++++ tableeditor.css | 19 +++ theme/default/sfiab.css | 132 +++++++++++++---- xmltransport.php | 134 ++++++++++++----- 9 files changed, 692 insertions(+), 197 deletions(-) delete mode 100644 htabs.css create mode 100644 htabs.inc.php create mode 100644 sfiab.js diff --git a/admin/award_awards.php b/admin/award_awards.php index 3a0fa2c..da6efcc 100644 --- a/admin/award_awards.php +++ b/admin/award_awards.php @@ -22,10 +22,97 @@ */ ?> 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; +} + if($_GET['action']=="edit" || $_GET['action']=="add") { send_header(($_GET['action']=="edit") ? "Edit Award" : "Add Award", array('Committee Main' => 'committee_main.php', @@ -39,6 +126,7 @@ 'Awards Main' => 'admin/awards.php') ); } + if($_GET['sponsors_id'] && $_GET['sponsors_id']!="all") $_SESSION['sponsors_id']=$_GET['sponsors_id']; else if($_GET['sponsors_id']=="all") @@ -65,8 +153,183 @@ $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'); +echo 'Prize info!
'; +htabs_tab_end(); + +htabs_end(); + + +popup_end(); + + +if($_POST['save']=="edit" || $_POST['save']=="add") +{ if(!$_POST['award_types_id']) { echo error(i18n("Award Type is required")); $_GET['action']=$_POST['save']; @@ -435,7 +698,7 @@ 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, sponsors.organization @@ -474,12 +737,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 "\n"; echo " id]\" value=\"$r->order\" size=\"3\" />\n"; echo " $r->organization\n"; echo " $r->type\n"; - echo " $r->name\n"; + echo " id});\">$r->name\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/user_editor_window.php b/admin/user_editor_window.php index 8d352bf..fccd157 100644 --- a/admin/user_editor_window.php +++ b/admin/user_editor_window.php @@ -28,42 +28,42 @@ $tabs = array( 'fairinfo' => array( - 'name' => 'Fair Information', + 'label' => 'Fair Information', 'types' => array('fair'), 'file' => '../fair_info.php', 'enabled' => true,), 'personal' => array( - 'name' => 'Personal', + 'label' => 'Personal', 'types' => array('student','judge','committee','volunteer','sponsor','fair'), 'file' => '../user_personal.php', 'enabled' => true), 'roles' => array( - 'name' => 'Roles/Account', + 'label' => 'Roles/Account', 'types' => array('student','judge','committee','volunteer','sponsor','fair'), 'file' => '../user_activate.php', 'enabled' => true), 'judgeother' => array( - 'name' => 'Judge Other', + 'label' => 'Judge Other', 'types' => array('judge'), 'file' => '../judge_other.php', 'enabled' => true), 'judgeexpertise' => array( - 'name' => 'Expertise', + 'label' => 'Expertise', 'types' => array('judge'), 'file' => '../judge_expertise.php', 'enabled' => true), 'judgeavailability' => array( - 'name' => 'Time Avail.', + 'label' => 'Time Avail.', 'types' => array('judge'), 'file' => '../judge_availability.php', 'enabled' => $config['judges_availability_enable'] == 'yes' ? true : false), 'judgesa' => array( - 'name' => 'Special Awards', + 'label' => 'Special Awards', 'types' => array('judge'), 'file' => '../judge_special_awards.php', 'enabled' => true,), 'volunteerpos' => array( - 'name' => 'Volunteer Positions', + 'label' => 'Volunteer Positions', 'types' => array('volunteer'), 'file' => '../volunteer_position.php', 'enabled' => true,), @@ -107,11 +107,9 @@ if(!array_key_exists($selected, $tabs)) { send_popup_header(i18n("User Editor").": {$u['name']}"); -?> - -'; +echo ''; +echo ''; + $t = $tabs[$selected]; @@ -132,7 +132,7 @@ $_SESSION['embed'] = true; $_SESSION['embed_submit_url'] = "{$_SERVER['PHP_SELF']}?id=$id&tab=$selected"; $_SESSION['embed_edit_id'] = $id; -echo '
'; +echo '
'; include("{$t['file']}"); echo '
'; diff --git a/common.inc.php b/common.inc.php index 04d793b..a03bbb4 100644 --- a/common.inc.php +++ b/common.inc.php @@ -383,51 +383,8 @@ function send_header($title="", $nav=null, $icon=null, $titletranslated=false) - + + +var htabs_current = new Array(); + +function htabs_open(tab) +{ + var cur = htabs_current[tab]; + $("#htabs_"+tab+"_"+cur).click(); +} + + + +"; + 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/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/tableeditor.css b/tableeditor.css index 295a6cb..2d9955a 100644 --- a/tableeditor.css +++ b/tableeditor.css @@ -59,10 +59,28 @@ input { font-size: 0.8em; border: 0px; border-collapse: collapse; +/* width: 100%;*/ } .tableedit td { 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 { @@ -76,3 +94,4 @@ input { + diff --git a/theme/default/sfiab.css b/theme/default/sfiab.css index 9912d85..60e78f5 100644 --- a/theme/default/sfiab.css +++ b/theme/default/sfiab.css @@ -382,7 +382,6 @@ tr.externalaward { } #FadeScreenDiv { - filter:alpha(opacity=50); -moz-opacity:.50; opacity:.50; position: fixed; @@ -423,43 +422,73 @@ tr.externalaward { padding: 2px; } -/* Tab colours, boy this will be nice when CSS variables exist */ - -/* Tab Line Colour */ -ul#htabs { +/* Horizontal Tabs */ +/* For the whole UL */ +ul.htabs { + list-style: none; + list-style-position: outside; border-bottom-color: #A5B5C6; /* Line colour */ } -/* Non-selected tab */ -ul#htabs li a { - background-color: #D0D0FF; /* Background 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; } -/* Selected tab */ -ul#htabs li.htabsel { - background-color: #EEEEFF; /* Backgroudn Colour */ - border-bottom-color: #EEEEFF; /* Bottom border colour, should match the bkgrnd */ -} - -/* Selected tab link */ -ul#htabs li.htabsel a { - background-color: #EEEEFF; /* Background Colour */ +/* Overrides for selected tab */ +ul.htabs li.htabs_sel { + background: #EEEEFF; + top: 1px; + border-bottom: 0; color: #000000; /* Font colour */ -} +} -/* Hover over colour */ -ul#htabs a:hover { +/* Mouseover colour */ +ul.htabs li:hover { background: #ffffff; } - -#htabmain { - background: #EEEEFF; /* Should match selected tab background */ - border-color: #A5B5C6;/* Should match UL border */ +/* 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 { @@ -467,15 +496,66 @@ table.usereditor { } table.usereditor td.left { - width: 30%; + width: 25%; vertical-align: middle; text-align: right; padding-right: 5px; } table.usereditor td.right { - width: 70%; + 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/xmltransport.php b/xmltransport.php index f15f8bc..2f1eafc 100644 --- a/xmltransport.php +++ b/xmltransport.php @@ -23,8 +23,94 @@ */ ?> $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, @@ -42,7 +128,7 @@ // echo "data:";print_r($data); // echo "
    "; // exit; - + $username = $data['auth']['username']; $password = $data['auth']['password']; @@ -74,43 +160,13 @@ 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)) { - $year = $data['getstats']['year']; - $vars = array('fair_stats_participation', 'fair_stats_schools_ext', - 'fair_stats_minorities', 'fair_stats_guests', - 'fair_stats_sffbc_misc', 'fair_stats_info', - 'fair_stats_next_chair', 'fair_stats_scholarships', - 'fair_stats_delegates', - ); - foreach($vars as $v) { - $response['statconfig'][$v] = $config[$v]; - } - $q = mysql_query("SELECT * FROM fairs_stats WHERE fairs_id='{$u['fairs_id']}' - AND year='$year'"); - $response['stats'] = mysql_fetch_assoc($q); - unset($response['stats']['id']); - $response['error'] = 0; - } - - if(array_key_exists('stats', $data)) { - $stats = $data['stats']; - foreach($stats as $k=>$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['error'] = 0; - $response['message'] = 'Stats saved'; - } + 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!
    ";