Subversion Repositories VORC

Rev

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

Rev Author Line No. Line
105 bgadell 1
#!/usr/bin/perl
2
 
3
# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)
4
my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";
5
close STDERR;
6
open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";
7
#warn "Redirecting errors to ${error_log_path}vorc_error.log";
8
 
9
use strict;
10
use cPanelUserConfig;
11
use WebDB;
12
use HTML::Tiny;
13
use RollerCon;
226 - 14
use CGI qw/param header start_html url url_param/;
105 bgadell 15
my $h = HTML::Tiny->new( mode => 'html' );
16
my $dbh = WebDB::connect;
17
my $homeURL = '/schedule/';
18
my $pageTitle = "View MVP Class Comments";
19
 
20
my $cookie_string = authenticate (RollerCon::USER) || die;
21
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
22
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
23
my @ERRORS;
24
my $DEBUG = 0;
25
 
226 - 26
my $classid = param ("classid"); $classid //= url_param ("classid");
105 bgadell 27
error ("No ClassID.") unless $classid;
28
 
226 - 29
my $qid = param ("qid"); $qid //= url_param ("qid");
105 bgadell 30
error ("No QuestionID.") unless $classid;
31
 
32
# Limit access to coach-of-the-class, admins, and MVP Leads+
33
my ($coachID) = $dbh->selectrow_array ("select coach from class where id = ?", undef, $classid);
34
error ("You don't have access to view these comments.") unless $coachID == $ORCUSER->{RCid} or $LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{MVP} >= RollerCon::LEAD;
35
 
36
my ($type, $private) = $dbh->selectrow_array ("select type, private from survey_question where qid = ?", undef, $qid);
37
error ("This is a numeric range question (it doesn't have comments as answers).") unless $type eq "text";
38
# Check to make sure just-a-coach isn't looking at private comments
39
error ("You don't have access to view these comments.") unless !$private or $LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{MVP} >= RollerCon::LEAD;
40
 
208 - 41
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);
105 bgadell 42
error ("Feedback isn't availabel until after the class has ended.") unless $started;
43
 
44
 
45
display_comments ($classid, $qid);
46
 
47
 
48
 
49
 
50
sub display_comments {
51
  my $CID = shift // error ("No ClassID");
52
  my $QID = shift // error ("No QuestionID");
53
  my $saved = shift // "";
54
 
55
  print header (-cookie=> [ $RCAUTH_cookie ] ),
56
  	start_html (-title => $pageTitle, -style => [{'src' => "/style.css"},{'src' => "/survey.css"}] );
57
 
58
  print $h->div ({ class => "accent pageheader" }, [
59
    $h->h1 ($pageTitle),
60
    $h->div ({ class=>"sp0" }, [
61
      $h->div ({ class=>"spLeft" }, [
62
      ]),
63
      $h->div ({ class=>"spRight" }, [
64
        $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
65
      ]),
66
    ]),
67
  ]);
68
 
208 - 69
  my ($CREF) = $dbh->selectrow_hashref ("select * from v_class_new where id = ?", undef, $classid);
105 bgadell 70
  $CREF->{time} = convertTime $CREF->{time};
71
  $CREF->{date} = $CREF->{date}." [".$CREF->{dayofweek}."]";
72
  print $h->ul ( { style=>"max-width:610px" }, [ map { $h->li ({ class=>"shaded", style=>"margin:4px;" },
73
    $h->div ({ class=>"lisp0" }, [
74
      $h->div ({ class=>"liNarrowLeft"  }, ucfirst $_),
75
      $h->div ({ class=>"liWideRight"   }, $CREF->{$_})
76
      ])
77
    ) } ("name", "coach", "date", "time", "location") ]);
78
 
79
 
80
 
81
#  print $h->div (["Class Details:",
82
#    $h->p ("Name: ".$CREF->{name},
83
#           "Coach: ".$CREF->{coach}
84
#           ),
85
#    ]), $h->hr;
86
 
108 bgadell 87
  my ($thequestion) = $dbh->selectrow_array ("select question from survey_question where qid = ?", undef, $QID);
88
 
89
  print $h->div ({ style=>"max-width:610px" }, ["Submitted Comments:", $h->p ({style=>"font-style:italic;margin-left:10px"}, $thequestion),
90
    $h->ul ([
91
      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)}
92
    ]) ]);
105 bgadell 93
 
94
  print $h->input ({ type=>"button", name=>"back", value=>"Back", onClick=>"history.back(); return false;" });
95
 
96
  print $h->close ("html");
97
  exit;
98
}
99
 
100
 
101
 
102
 
103
sub error {
104
  my $msg = shift // "";
105
 
106
  print header (-cookie=> [ $RCAUTH_cookie ] ),
107
			start_html (-title => $pageTitle, -style => {'src' => "/style.css"} );
108
 
109
  print $h->div ({ class => "accent pageheader" }, [
110
    $h->h1 ($pageTitle),
111
    $h->div ({ class=>"sp0" }, [
112
      $h->div ({ class=>"spLeft" }, [
113
      ]),
114
      $h->div ({ class=>"spRight" }, [
115
        $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
116
      ]),
117
    ]),
118
  ]),
119
  $h->div ({ class => "error" }, $msg),
120
  $h->close ("html");
121
 
122
  exit;
123
}