Subversion Repositories VORC

Rev

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