Permalink
Browse files

Merge branch 'master' of github.com:styfle/The-Harvest-Club

  • Loading branch information...
2 parents b1badad + 7d58633 commit 7fdda9504fea75c79315757632642e88498b505b @SgtRaccoon SgtRaccoon committed Mar 12, 2012
Showing with 161 additions and 61 deletions.
  1. +34 −3 ajax.php
  2. +9 −7 createTables.sql
  3. +2 −2 include/forms.php
  4. +115 −4 index.php
  5. +1 −45 js/event.js
View
@@ -559,9 +559,29 @@ function dateToStr($dateStr) {
}
$data['title'] = 'Volunteer-Events';
$volunteer_id = $_REQUEST['volunteer_id'];
- $sql = "SELECT ve.*
- FROM volunteer_events ve
- WHERE ve.volunteer_id = $volunteer_id;";
+
+ $q = mysql_query("SELECT SUM(ve2.hour) AS event_hours FROM volunteer_events ve2 WHERE ve2.volunteer_id=$volunteer_id;");
+ while($result=mysql_fetch_array($q)){
+ $event_hours = $result['event_hours'];
+ }
+ $q = mysql_query("SELECT v1.surplus_hours FROM volunteers v1 WHERE v1.id=$volunteer_id");
+ while($result=mysql_fetch_array($q)){
+ $surplus_hours = $result['surplus_hours'];
+ }
+ $total = $surplus_hours + $event_hours;
+
+ $sql = "SELECT ve.event_id, ve.volunteer_id, CONCAT(g.first_name,' ', g.last_name) AS Grower, e.date AS Date, ve.hour AS Hours, '0' AS surplus_tag
+ FROM volunteer_events ve, events e, growers g
+ WHERE ve.volunteer_id = $volunteer_id AND ve.event_id=e.id AND e.grower_id=g.id
+ UNION
+ SELECT '-1' AS event_id,
+ '0' AS volunteer_id,
+ 'TOTAL' AS Grower,
+ CONCAT('Plus ',
+ $surplus_hours,
+ ' surplus hours') AS Date,
+ '$total' AS Hours,
+ '$surplus_hours' AS surplus_tag;";
getTableNoCheckbox($sql);
break;
case 'get_growers':
@@ -946,6 +966,17 @@ function dateToStr($dateStr) {
$sql = "SELECT month_id FROM month_harvests mh Where mh.tree_id=".$id;
getTree_Months($sql);
break;
+ case 'update_surplus_hours':
+ if (!$PRIV['edit_volunteer']) {
+ forbidden();
+ break;
+ }
+ $surplus_hours = $_REQUEST['surplus_hours'];
+ $volunteer_id = $_REQUEST['volunteer_id'];
+ $data['title'] = 'Surplus Hours';
+ $sql = "Update volunteers Set surplus_hours = $surplus_hours where id=$volunteer_id";
+ $r = $db->q($sql);
+ break;
case 'update_volunteer':
if (!$PRIV['edit_volunteer']) {
forbidden();
View
@@ -305,18 +305,20 @@ CREATE TABLE volunteers (
signed_up DATE,
notes TEXT,
source_id INT DEFAULT 1,
+ surplus_hours INT DEFAULT 0,
CONSTRAINT fk_privilege_id FOREIGN KEY (privilege_id) REFERENCES privileges(id),
CONSTRAINT fk_source_id_volunteers FOREIGN KEY (source_id) REFERENCES sources(id)
) ENGINE=innodb;
-- start temp insert
-INSERT INTO volunteers (first_name, middle_name, last_name, phone, email, password, active_id, street, city, state, zip, privilege_id, signed_up, notes) VALUES
-('Peter','', 'Anteater', '(123) 456-7890', 'admin@uci.edu', SHA1('password'), 1, '456 Fake St', 'Irvine', 'CA', '91234', 5,'2010-05-01', 'Fearless mascot'),
-('Joanne','', 'Lolcatz', '(949) 555-3418', 'joanne@uci.edu', SHA1('password'), 1, '1 Harvest Cir', 'Irvine', 'CA', '91234', 5,'2012-03-01', 'Executive Power'),
-('Gillian','', 'Pwn', '(555) 555-1090', 'gillian@uci.edu', SHA1('password'), 1, '2 Harvest Cir', 'Irvine', 'CA', '91234', 4,'2012-03-01', 'Administrative skillz'),
-('Captain','Jack', 'Sparrow', '(949) 555-1337', 'captain@uci.edu', SHA1('password'), 1, '4 Black Pearl Rd', 'Pacific Ocean', 'CA', '99999', 3,'2012-03-01', 'Cursed'),
-('Victor','', 'Van', '(949) 555-9168', 'victor@uci.edu', SHA1('password'), 1, '2121 Ball Rd', 'Anaheim', 'CA', '92806', 2,'2012-03-01', 'Donut owner'),
-('Peter','', 'Pending', '(949) 555-0001', 'peter@uci.edu', SHA1('password'), 1, '6 Blue Nowhere', 'San Clemente', 'CA', '96539', 1,'2012-03-01', 'I am waiting...');
+INSERT INTO volunteers (first_name, middle_name, last_name, phone, email, password, active_id, street, city, state, zip, privilege_id, signed_up, notes, surplus_hours) VALUES
+('Peter','', 'Anteater', '(123) 456-7890', 'admin@uci.edu', SHA1('password'), 1, '456 Fake St', 'Irvine', 'CA', '91234', 5,'2010-05-01', 'Fearless mascot','1'),
+('Joanne','', 'Lolcatz', '(949) 555-3418', 'joanne@uci.edu', SHA1('password'), 1, '1 Harvest Cir', 'Irvine', 'CA', '91234', 5,'2012-03-01', 'Executive Power','2'),
+('Gillian','', 'Pwn', '(555) 555-1090', 'gillian@uci.edu', SHA1('password'), 1, '2 Harvest Cir', 'Irvine', 'CA', '91234', 4,'2012-03-01', 'Administrative skillz','3'),
+('Captain','Jack', 'Sparrow', '(949) 555-1337', 'captain@uci.edu', SHA1('password'), 1, '4 Black Pearl Rd', 'Pacific Ocean', 'CA', '99999', 3,'2012-03-01', 'Cursed','4'),
+('Victor','', 'Van', '(949) 555-9168', 'victor@uci.edu', SHA1('password'), 1, '2121 Ball Rd', 'Anaheim', 'CA', '92806', 2,'2012-03-01', 'Donut owner','5'),
+('Peter','', 'Pending', '(949) 555-0001', 'peter@uci.edu', SHA1('password'), 1, '6 Blue Nowhere', 'San Clemente', 'CA', '96539', 1,'2012-03-01', 'I am waiting...','6');
+
-- end temp insert
-- A volunteer can have many rolls
View
@@ -211,8 +211,8 @@ function options($id, $name, $data, $disabled=false) {
<div id="statsTable">
<table id="volunteerStats" cellpadding="0" cellspacing="0" border="0" class="display">
<!-- table is filled dynamically -->
- <thead><tr><th></th></tr></thead>
- <tbody><tr><td></td></tr></tbody>
+ <thead><tr><th>Loading...</th></tr></thead>
+ <tbody><tr><td>Please wait</td></tr></tbody>
</table>
</div>
View
119 index.php
@@ -1080,7 +1080,7 @@ function showAddDelEmailExport(add, del, eml, exp) {
});
$(document).ready(function() {
-
+
dt = $('#dt').dataTable({
'bJQueryUI': true, // style using jQuery UI
'sPaginationType': 'full_numbers', // full pagination
@@ -1351,8 +1351,14 @@ function showAddDelEmailExport(add, del, eml, exp) {
$(document).on('click', '#volunteerStats tbody tr',function(e) {
var eventRow = (dt2.fnGetData(this));
- eventID = eventRow[0];
- viewEvent();
+ eventID = eventRow[0];
+ if(eventID>0)
+ viewEvent();
+ else{
+ var current_hours = eventRow[5];
+ var volunteer_id = eventRow[1];
+ //var surplus_hours = getSurplusHours(current_hours, volunteer_id);
+ }
});//on.click dt2
@@ -1395,6 +1401,55 @@ function showAddDelEmailExport(add, del, eml, exp) {
document.getElementById('get_notifications').click();
}); // document.ready()
+ function getSurplusHours(current_surplus, volunteer_id) {
+
+ // Build dialog markup
+ var win = $('<div><p>Enter surplus hours</p></div>');
+ var userInput = $('<input type="text" style="width:100%" value="' +current_surplus+ '"></input>');
+ userInput.appendTo(win);
+
+ var surplus_hours = '';
+
+ // Display dialog
+ $(win).dialog({
+ 'modal': true,
+ 'buttons': {
+ 'Save': function() {
+ surplus_hours = $(userInput).val();
+ if(surplus_hours<0)
+ alert("Hours cannot be negative!");
+ else{
+ alert(surplus_hours);
+ $.ajax({
+ 'type': 'GET',
+ 'url': 'ajax.php?cmd=update_surplus_hours&volunteer_id='+volunteer_id+'&surplus_hours='+surplus_hours,
+ 'success': function (data) {
+ if (!validResponse(data))
+ return false;
+ setInfo('Information Updated');
+ // for(var i = 1; i < row.length; i++) {
+ // if($('#volunteer'+i).val() == undefined)
+ // row[i]='';
+ // else;
+ // row[i]=$('#volunteer'+i).val();
+ // }
+
+ // dt.fnUpdate(row, aPos, 0); //Update Table -- Independent from updating db!
+ },
+ 'error': ajaxError
+ });
+
+ $(this).dialog('close');
+ }
+ },
+ 'Cancel': function() {
+ $(this).dialog('close');
+ }
+ }
+ });
+ return surplus_hours;
+}
+
function viewTrees(){
viewTreeClicked = 1;
growerID = $('#grower1').val(); //get ID of grower whose trees are to be shown
@@ -1491,7 +1546,63 @@ function changeTemplate(t) {
t.value = '';
event_field.val(event_id);
}
-
+
+ function viewStats(){
+ //var dt2;
+ $('#statsTable').show();
+ var volunteer_id = $('#volunteer1').val();
+ //alert(volunteer_id);
+ $.ajax({
+ 'dataType': 'json',
+ 'type': 'GET',
+ 'url': 'ajax.php?cmd=get_volunteer_stats&volunteer_id='+volunteer_id,
+ 'success': function (data) {
+ if (!validResponse(data))
+ return false;
+ if (!data.datatable || !data.datatable.aoColumns || !data.datatable.aaData)
+ return alert('There is no column and row data!');
+ $('#volunteerStats thead').html('');
+ $('#volunteerStats tbody').html('');
+
+ if (typeof dt2 == 'undefined') {
+ alert("1");
+ dt2 = $('#volunteerStats').dataTable({
+ 'bJQueryUI': true, // style using jQuery UI
+ 'sPaginationType': 'full_numbers', // full pagination
+ 'bProcessing': true, // show loading bar text
+ 'bAutoWidth': false, // auto column size
+ 'aaSorting': [], // disable initial sort
+ "sScrollX": "100%",
+ 'aoColumns': data.datatable.aoColumns,
+ 'aaData': data.datatable.aaData
+ });
+ }
+ else
+ {
+ alert("re");
+ //dt2.fnReloadAjax();
+ alert("2");
+ dt2.fnDestroy();
+ $('#volunteerStats thead').html('');
+ $('#volunteerStats tbody').html('');
+ dt2 = $('#volunteerStats').dataTable({
+ 'bJQueryUI': true, // style using jQuery UI
+ 'sPaginationType': 'full_numbers', // full pagination
+ 'bProcessing': true, // show loading bar text
+ 'bAutoWidth': false, // auto column size
+ 'aaSorting': [], // disable initial sort
+
+ 'aoColumns': data.datatable.aoColumns,
+ 'aaData': data.datatable.aaData
+ });
+ }
+ //dt2.fnDraw(false);
+ },
+ 'error': ajaxError
+ });
+
+ }
+
</script>
<!-- Prompt IE 6 users to install Chrome Frame. -->
View
@@ -97,51 +97,7 @@ function deleteTreeRow(tableID) {
}
}
-function viewStats(){
- var volunteer_id = $('#volunteer1').val();
- $.ajax({
- 'dataType': 'json',
- 'type': 'GET',
- 'url': 'ajax.php?cmd=get_volunteer_stats&volunteer_id='+volunteer_id,
- 'success': function (data) {
- if (!validResponse(data))
- return false;
- if (!data.datatable || !data.datatable.aoColumns || !data.datatable.aaData)
- return alert('There is no column and row data!');
-
- if (typeof dt2 == 'undefined') {
-
- dt2 = $('#volunteerStats').dataTable({
- 'bJQueryUI': true, // style using jQuery UI
- 'sPaginationType': 'full_numbers', // full pagination
- 'bProcessing': true, // show loading bar text
- 'bAutoWidth': false, // auto column size
- 'aaSorting': [], // disable initial sort
- "sScrollX": "100%",
- 'aoColumns': data.datatable.aoColumns,
- 'aaData': data.datatable.aaData,
- });
- }
- else
- {
- dt2.fnDestroy();
- dt2 = $('#volunteerStats').dataTable({
- 'bJQueryUI': true, // style using jQuery UI
- 'sPaginationType': 'full_numbers', // full pagination
- 'bProcessing': true, // show loading bar text
- 'bAutoWidth': false, // auto column size
- 'aaSorting': [], // disable initial sort
- "aLengthMenu": [[10, 25, 50, 100, -1], // sort length
- [10, 25, 50, 100, "All"]], // sort name
- 'iDisplayLength': dt_length,
- 'aoColumns': data.datatable.aoColumns,
- 'aaData': data.datatable.aaData,
- });
- }
- }
- });
- $('#statsTable').show();
-}
+
function addVolunteerRow(tableID) {
var table = document.getElementById(tableID);

0 comments on commit 7fdda95

Please sign in to comment.