Skip to content

Commit

Permalink
committee attendees submitted with points, improvements to committee …
Browse files Browse the repository at this point in the history
…headquarters
  • Loading branch information
benthemonkey committed May 3, 2014
1 parent ad9083e commit c5114b3
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 70 deletions.
46 changes: 31 additions & 15 deletions ajax/PointsCenter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
require_once __DIR__ . "/datastoreVars.php";
include_once __DIR__ . "/swift/swift_required.php";

class PointsCenter
{
Expand Down Expand Up @@ -42,7 +43,7 @@ public function getQuarters ()
$statement = self::$dbConn->prepare(
"SELECT qtr,quarter
FROM quarters
WHERE 1301<qtr
WHERE 1301 < qtr
ORDER BY qtr DESC");
$statement->bindValue(":qtr", self::$qtr);
$statement->execute();
Expand Down Expand Up @@ -974,7 +975,21 @@ public function updateSuite ($slivkans, $suite)

public function submitCommitteePoint ($nu_email, $event_name, $points)
{
if($event_name == 'bonus'){
if($points == '0' || $points == '0.0'){
try {
$statement = self::$dbConn->prepare(
"DELETE FROM committeepoints
WHERE nu_email=:nu_email AND event_name=:event_name AND qtr=:qtr");
$statement->bindValue(':nu_email', $nu_email);
$statement->bindValue(':event_name', $event_name);
$statement->bindValue(':qtr', self::$qtr);

$statement->execute();
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
die();
}
}else if($event_name == 'bonus'){
try {
$statement = self::$dbConn->prepare(
"INSERT INTO committees (nu_email,bonus,qtr) VALUES (?,?,?)
Expand Down Expand Up @@ -1020,16 +1035,17 @@ public function submitPointsForm ($get)
{
$real_event_name = $get['event_name'] . " " . $get['date'];

if($get['committee_members'] === NULL){ $get['committee_members'] = array(""); }
if($get['fellows'] === NULL){ $get['fellows'] = array(""); }

# Begin PDO Transaction
self::$dbConn->beginTransaction();

try {
$statement = self::$dbConn->prepare(
"INSERT INTO `pointsform` SET
date=:date, type=:type, committee=:committee, event_name=:event_name, description=:description,
filled_by=:filled_by, comments=:comments, attendees=:attendees, fellows=:fellows");
"INSERT INTO pointsform SET date=:date, type=:type, committee=:committee, event_name=:event_name,
description=:description, filled_by=:filled_by, comments=:comments, attendees=:attendees,
committee_members=:committee_members, fellows=:fellows");
$statement->bindValue(":date", $get['date']);
$statement->bindValue(":type", $get['type']);
$statement->bindValue(":committee", $get['committee']);
Expand All @@ -1038,6 +1054,7 @@ public function submitPointsForm ($get)
$statement->bindValue(":filled_by", $get['filled_by']);
$statement->bindValue(":comments", $get['comments']);
$statement->bindValue(":attendees", implode(", ",$get['attendees']));
$statement->bindValue(":committee_members", implode(", ",$get['committee_members']));
$statement->bindValue(":fellows", implode(", ",$get['fellows']));

$statement->execute();
Expand Down Expand Up @@ -1095,23 +1112,23 @@ public function submitPointsForm ($get)
self::$dbConn->rollBack();
die();
}
}
}*/

if ($get['committee_members'][0] != ""){
try {
$statement = self::$dbConn->prepare(
"INSERT INTO committeepoints (nu_email, event_name, qtr)
VALUES (?,?,?)");
"INSERT INTO committeepoints (nu_email, event_name, points, qtr)
VALUES (?,?,?,?)");

foreach($get['committee_members'] as $c){
$statement->execute(array($c,$real_event_name,self::$qtr));
$statement->execute(array($c,$real_event_name,$get['filled_by'] == $c ? 1.0 : 0.5,self::$qtr));
}
} catch (PDOException $e) {
echo json_encode(array("error" => $e->getMessage(), "step" => "5"));
self::$dbConn->rollBack();
die();
}
}*/
}

if ($get['fellows'][0] != ""){
try {
Expand All @@ -1134,20 +1151,20 @@ public function submitPointsForm ($get)
$html = "<table border=\"1\">";

foreach($get as $key => $value){
$html .= "<tr><td style=\"text-align:right;\">";
$html .= "<tr><td style=\"text-align:right;\">" . $key . "</td><td>";

if(is_array($value)){
$html .= $key . "</td><td>" . implode(", ", $value);
$html .= implode(", ", $value);
}else{
$html .= $key . "</td><td>" . $value;
$html .= $value;
}

$html .= "</td></tr>\n";
}

$html .= "</table>";

self::sendEmail(null, "Points Submitted for " . $real_event_name, $html);
self::sendEmail(false, "Points Submitted for " . $real_event_name, $html);
}

return self::$dbConn->commit();
Expand Down Expand Up @@ -1304,7 +1321,6 @@ public function pointsCorrectionReply($get)

private function sendEmail($to_email,$subject,$body)
{
include_once __DIR__ . "/swift/swift_required.php";
$from = array($GLOBALS['MAILBOT_EMAIL'] => "Slivka Points Center");

if($to_email){
Expand Down
69 changes: 45 additions & 24 deletions committeeHeadquarters.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ function getFullName($slivkans, $nu_email){

return '';
}


?>

<!DOCTYPE HTML>
<html lang="en">
<head>
Expand Down Expand Up @@ -84,29 +83,25 @@ function getFullName($slivkans, $nu_email){
<thead>
<tr>
<th class="nameHeader"><div><div></div></div><span>Name</span></th>
<?php
$indent = "\t\t\t\t\t\t\t";

for($i=0; $i<count($points_table['events']); $i++){
echo $indent . "<th class=\"eventHeader\">\n" .
$indent . "\t<div class=\"slantedHeader\">\n" .
$indent . "\t\t<span>" . substr($points_table['events'][$i], 0, -10) . substr($points_table['events'][$i], -5) . "</span>\n" .
$indent . "\t</div>\n" .
$indent . "\t<div class=\"sort-icon\"></div>\n" .
$indent . "</th>\n";
}
<?php for($i=0; $i<count($points_table['events']); $i++){ ?>
<th class="eventHeader">
<div class="slantedHeader">
<span><?= substr($points_table['events'][$i], 0, -10) . substr($points_table['events'][$i], -5)?></span>
</div>
<div class="sort-icon"></div>
</th>
<?php }

$totalsColumns = array("Bonus", "Total");//, "Total (adjusted)");
$totalsColumns = array("Bonus", "Total");//, "Total (adjusted)");

for($i=0; $i<count($totalsColumns); $i++){
echo $indent . "<th class=\"totalsHeader\">\n" .
$indent . "\t<div class=\"slantedHeader\">\n" .
$indent . "\t\t<span>" . $totalsColumns[$i] . "</span>\n" .
$indent . "\t</div>\n" .
$indent . "\t<div class=\"sort-icon\"></div>\n" .
$indent . "</th>\n";
}
?>
for($i=0; $i<count($totalsColumns); $i++){ ?>
<th class="totalsHeader">
<div class="slantedHeader">
<span><?= $totalsColumns[$i] ?></span>
</div>
<div class="sort-icon"></div>
</th>
<?php } ?>
<th class="endHeader">
<div class="slantedHeader"></div>
<div class="sort-icon"></div>
Expand Down Expand Up @@ -166,11 +161,37 @@ function getFullName($slivkans, $nu_email){
</div>
<?php } else { ?>
<div class="alert alert-info text-center"><h4>Select a Committee</h4></div>

<?php } ?>
<?php include('credits.html'); ?>
</div><!--content-->
</div>
<div id="pts-input-template" style="display: none;">
<button type="button" class="close" aria-hidden="true">&times;</button>
<div class="form-group has-success">
<label class="control-label" for="pts-input">Edit Points:</label>
<div class="input-group">
<input type="number" id="pts-input" min="0.0" max="3.0" step="0.1" class="form-control pts-input">
<span class="input-group-btn">
<button class="btn btn-primary submit-committee-point">
<span class="glyphicon glyphicon-ok"></span>
</button>
</span>
</div>
</div>
<div class="form-group">
<label class="control-label" for="contributions">Contributions (not saved yet):</label>
<div class="clearfix"></div>
<select id="contributions" class="multiselect" multiple="multiple" style="height: 34px;">
<option data-pts="0.5" disabled>Attended (0.5)</option>
<option data-pts="0.5" disabled>Took Points (0.5)</option>
<option data-pts="2">Ran event (2)</option>
<option data-pts="1">Poster (1)</option>
<option data-pts="0.5">Set up (0.5)</option>
<option data-pts="0.5">Clean up (0.5)</option>
<option data-pts="0">Other</option>
</select>
</div>
</div>
<div id="helper-point-modal" class="modal fade" role="dialog" >
<div class="modal-dialog">
<div class="modal-content">
Expand Down
82 changes: 51 additions & 31 deletions js/pointsCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan) {
}
},
submitPointsForm: function() {
var name, nu_email, val,
var name, nu_email, val, ind,
data = {
date: $('#date').val(),
type: type.toLowerCase().replace(' ', '_'),
Expand All @@ -1108,15 +1108,20 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan) {
filled_by: slivkans[slivkans.indexOfKey('full_name', $('#filled-by').val())].nu_email,
comments: $('#comments').val(),
attendees: [],
committee_members: [],
fellows: []
};

$('#slivkan-entry-tab').find('.slivkan-entry').each(function() {
name = $(this).val();
if(name.length > 0){
nu_email = slivkans[slivkans.indexOfKey('full_name', name)].nu_email;
ind = slivkans.indexOfKey('full_name', name);
nu_email = slivkans[ind].nu_email;

data.attendees.push(nu_email);
if (slivkans[ind].committee == data.committee && data.committee != 'Exec' && type != 'p2p' && type != 'im') {
data.committee_members.push(nu_email);
}
}
});

Expand All @@ -1133,7 +1138,7 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan) {

for(var obj in data){
if(data.hasOwnProperty(obj)){
if(obj == 'attendees' || obj == 'fellows'){
if(obj == 'attendees' || obj == 'committee_members' || obj == 'fellows'){
val = data[obj].join(', ');
}else{
val = data[obj];
Expand Down Expand Up @@ -1163,7 +1168,7 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan) {
real_submit.button('reset');
$('#results-status').parent().removeClass('has-warning');
if(data_in.error){
$('#results-status').text('Error in Step '+data_in.step).parent().addClass('has-error');
$('#results-status').text('Error in Step '+data_in.step).parent().removeClass('warning').addClass('error');
}else{
$('#unconfirmed').fadeOut({complete: function() {$('#confirmed').fadeIn();}});

Expand All @@ -1173,7 +1178,7 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan) {
$('#unconfirmed').show();
});

$('#results-status').text('Success!').parent().addClass('has-success');
$('#results-status').text('Success!').parent().removeClass('warning').addClass('success');

submission.resetForm('force');
}
Expand Down Expand Up @@ -1212,7 +1217,8 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan) {
events = events.sort(function(a, b) { return a[2] - b[2]; });

for(var i=0; i<events.length; i++){
$('<li />').html(events[i][0] + ' ' + events[i][1]).appendTo('#events'); // + ' ' + moment(events[i][2]+'', 'X').format('ddd MMM DD, YYYY h:mma')
$('<li />').html(events[i][0] + ' ' + events[i][1]).appendTo('#events');
// + ' ' + moment(events[i][2]+'', 'X').format('ddd MMM DD, YYYY h:mma')
}
}
});
Expand Down Expand Up @@ -1514,21 +1520,11 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan) {
container: 'body',
trigger: 'manual',
content: function(){
return ['',
'<div class="form-group has-success" style="width:100px;">',
'<label class="control-label" for="pts-input">Edit Points:</label>',
'<div class="input-group">',
'<input type="number" id="pts-input" min="0.0" max="3.0" step="0.1" ',
'data-original-value="', this.innerText, '" ',
'value="', this.innerText, '" class="form-control pts-input" >',
'<span class="input-group-btn">',
'<button class="btn btn-primary submit-committee-point">',
'<span class="glyphicon glyphicon-ok"></span>',
'</button>',
'</span>',
'</div>',
'</div>'
].join('');
var template = $('#pts-input-template');

template.find('input').data('original-value', this.innerText).attr('value', this.innerText);

return template.html();
}
}).on('click', function(e){
var target = $(e.target);
Expand All @@ -1546,7 +1542,35 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan) {
openPopover = target.popover('show');
});

$('body').on('click', function(e){
$('body').on('shown.bs.popover', function(e){
var target = $(e.target),
popover = $('.popover');

if(target.hasClass('green')){
popover.find('option:disabled').eq(0).attr('selected', 'selected');
}else if(target.hasClass('blue')){
popover.find('option:disabled').attr('selected', 'selected');
}

popover.find('.multiselect').multiselect({
buttonClass: 'btn btn-default',
buttonWidth: 244,
onChange: function(e, checked){
var pts_input = $('.pts-input').last(),
newVal = parseFloat(pts_input.val()) + (checked ? 1 : -1) * parseFloat(e.data('pts'));

if(newVal < 0){
pts_input.val(0);
}else if(newVal > 3){
pts_input.val(3);
}else{
pts_input.val(newVal);
}

committeeHeadquarters.validatePoints(pts_input);
}
});
}).on('click', function(e){
var target = $(e.target);

if(openPopover && target.closest('.pts').length === 0 && target.closest('.popover').length === 0){
Expand All @@ -1573,7 +1597,9 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan) {
openPopover = null;
}
});
}).on('input', '.pts-input', committeeHeadquarters.validatePoints);
}).on('input', '.pts-input', function(e){
committeeHeadquarters.validatePoints($(e.target));
});

$('#helper-point-form').on('submit', function(){
var nu_email = $('#helper-slivkan').val(),
Expand All @@ -1596,11 +1622,6 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan) {
});
}
});

// $('body').on('shown.bs.popover', function(e){
// console.log(e);
// });
//$('#helper-slivkan') .on('change', );
},
updateTotal: function(row){
var total = row.find('td.pts').map(function(i, el){
Expand All @@ -1611,9 +1632,8 @@ define(['jquery', 'moment', 'hogan'], function($, moment, Hogan) {

row.find('.totals').text(total.toFixed(1));
},
validatePoints: function(e){
var target = $(e.target),
control = target.closest('.form-group'),
validatePoints: function(target){
var control = target.closest('.form-group'),
button = control.find('button'),
valid = true;

Expand Down

0 comments on commit c5114b3

Please sign in to comment.