Subversion Repositories VORC

Rev

Rev 208 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/perl

# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)
my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";
close STDERR;
open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";
#warn "Redirecting errors to ${error_log_path}vorc_error.log";

use strict;
use cPanelUserConfig;
use WebDB;
use HTML::Tiny;
use RollerCon;
use CGI qw/param header start_html url url_param/;
my $h = HTML::Tiny->new( mode => 'html' );
my $dbh = WebDB::connect;
my $homeURL = '/schedule/';
my $pageTitle = "View MVP Class Comments";

my $cookie_string = authenticate (RollerCon::USER) || die;
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
my @ERRORS;
my $DEBUG = 0;

my $classid = param ("classid"); $classid //= url_param ("classid");
error ("No ClassID.") unless $classid;

my $qid = param ("qid"); $qid //= url_param ("qid");
error ("No QuestionID.") unless $classid;

# Limit access to coach-of-the-class, admins, and MVP Leads+
my ($coachID) = $dbh->selectrow_array ("select coach from class where id = ?", undef, $classid);
error ("You don't have access to view these comments.") unless $coachID == $ORCUSER->{RCid} or $LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{MVP} >= RollerCon::LEAD;

my ($type, $private) = $dbh->selectrow_array ("select type, private from survey_question where qid = ?", undef, $qid);
error ("This is a numeric range question (it doesn't have comments as answers).") unless $type eq "text";
# Check to make sure just-a-coach isn't looking at private comments
error ("You don't have access to view these comments.") unless !$private or $LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{MVP} >= RollerCon::LEAD;

my ($started) = $dbh->selectrow_array ("select id from v_class_signup_new where id = ? and concat_ws(date, end_time) < date_sub(now(), interval 2 hour)", undef, $classid);
error ("Feedback isn't availabel until after the class has ended.") unless $started;


display_comments ($classid, $qid);




sub display_comments {
  my $CID = shift // error ("No ClassID");
  my $QID = shift // error ("No QuestionID");
  my $saved = shift // "";
  
  print header (-cookie=> [ $RCAUTH_cookie ] ),
        start_html (-title => $pageTitle, -style => [{'src' => "/style.css"},{'src' => "/survey.css"}] );
  
  print $h->div ({ class => "accent pageheader" }, [
    $h->h1 ($pageTitle),
    $h->div ({ class=>"sp0" }, [
      $h->div ({ class=>"spLeft" }, [
      ]),
      $h->div ({ class=>"spRight" }, [
        $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
      ]),
    ]),
  ]);
  
  my ($CREF) = $dbh->selectrow_hashref ("select * from v_class_new where id = ?", undef, $classid);
  $CREF->{time} = convertTime $CREF->{time};
  $CREF->{date} = $CREF->{date}." [".$CREF->{dayofweek}."]";
  print $h->ul ( { style=>"max-width:610px" }, [ map { $h->li ({ class=>"shaded", style=>"margin:4px;" },
    $h->div ({ class=>"lisp0" }, [
      $h->div ({ class=>"liNarrowLeft"  }, ucfirst $_),
      $h->div ({ class=>"liWideRight"   }, $CREF->{$_})
      ])
    ) } ("name", "coach", "date", "time", "location") ]);

  
  
#  print $h->div (["Class Details:",
#    $h->p ("Name: ".$CREF->{name},
#           "Coach: ".$CREF->{coach}
#           ),
#    ]), $h->hr;

  my ($thequestion) = $dbh->selectrow_array ("select question from survey_question where qid = ?", undef, $QID);

  print $h->div ({ style=>"max-width:610px" }, ["Submitted Comments:", $h->p ({style=>"font-style:italic;margin-left:10px"}, $thequestion),
    $h->ul ([
      map { $h->li ({ class=>"shaded" }, $$_[0] ) } @{$dbh->selectall_arrayref ("select response from v_survey_answer where classid = ? and qid = ? and trim(response) <> '' order by aid", undef, $CID, $QID)}
    ]) ]);
      
  print $h->input ({ type=>"button", name=>"back", value=>"Back", onClick=>"history.back(); return false;" });
  
  print $h->close ("html");
  exit;
}




sub error {
  my $msg = shift // "";
  
  print header (-cookie=> [ $RCAUTH_cookie ] ),
                        start_html (-title => $pageTitle, -style => {'src' => "/style.css"} ); 

  print $h->div ({ class => "accent pageheader" }, [
    $h->h1 ($pageTitle),
    $h->div ({ class=>"sp0" }, [
      $h->div ({ class=>"spLeft" }, [
      ]),
      $h->div ({ class=>"spRight" }, [
        $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
      ]),
    ]),
  ]),
  $h->div ({ class => "error" }, $msg),
  $h->close ("html");
  
  exit;
}