edit_uphotos.pl
250 lines of code
1
#!/usr/local/bin/perl
2
3
($<,$>) = (getpwnam('nobody'), getpwnam('nobody')) or die $!;
4
5
binmode(STDIN, ":utf8");
6
binmode(STDOUT, ":utf8");
7
8
# must have's!
9
use strict;
10
use warnings;
11
use CGI::Carp qw(fatalsToBrowser);
12
use DBI;
13
use URI::Escape;
14
15
use lib "/var/www/html/Pm";
16
17
use Html qw(
18
            pre_html_header
19
            header
20
            html_end
21
            img
22
           );
23
use Html2 qw(
24
             tag
25
             classyhr
26
             br
27
             hr
28
             embolden
29
             italicize
30
            );
31
use Bc_chef qw(cookie_get);
32
use Bc_misc qw(get_param referrer get_params_asHash pluralize);
33
use Bc_sql qw(
34
              get_constant
35
              sql_execute
36
              user_exists
37
              get_flag_data
38
              $QUERY_PAGE
39
              $QUERY_UID
40
              $LOGGEDIN
41
42
              $DB
43
             );
44
45
use Security qw(banned);
46
use Redir qw(error_redir notice_redir);
47
use User qw(get_user_pics isUserModerator);
48
49
my $DEBUG = 0;
50
51
my $output;
52
53
if (not user_exists($LOGGEDIN) or banned($LOGGEDIN) or not isUserModerator($LOGGEDIN)) {
54
  my $msg =  "Access Denied";
55
  if ($DEBUG) { $msg .= " (edit_uphotos.pl)"; }
56
  $output = error_redir("/", $msg);
57
} else {
58
  ############################################################
59
  ### YOUR CONTENT HERE
60
  $output = pre_html_header();
61
  $output .= header(
62
                    "User Photo Manager",
63
                    "?nobg_img=1&nogrid=1",
64
                    0,
65
                    "setTimeout(removeMsg, " . get_constant("REMOVE_MSG_TIMEOUT") . ");",
66
                    "",
67
                    "style='display: flex; height: min-content;'"
68
                   );
69
  my %params = get_params_asHash();
70
71
  { my %container;
72
    $container{tag} = "div";
73
    $container{style} = "margin: 0 0; width: 100%;";
74
    $container{innerHTML} = "";
75
76
    if ($params{$QUERY_UID}) {
77
      my @pics = get_user_pics($params{$QUERY_UID});
78
79
      if ($DEBUG) {
80
        { my %debugtitle;
81
          $debugtitle{tag} = "div";
82
          $debugtitle{class} = "subnavbar";
83
          $debugtitle{innerHTML} = "DEBUGGING USER PHOTO MANAGER";
84
          { my %button;
85
            $button{tag} = "button";
86
            $button{type} = "button";
87
            $button{class} = "yellow";
88
            $button{onclick} = "document.location.reload();";
89
            $button{innerHTML} = "Reload";
90
91
            $debugtitle{innerHTML} .= tag(\%button);
92
          }
93
94
          $container{innerHTML} .= tag(\%debugtitle);
95
        }
96
97
        { my %debug;
98
          $debug{tag} = "div";
99
          $debug{class} = "translucent";
100
          $debug{innerHTML} = "uid: " . embolden($params{$QUERY_UID}) . br .
101
                              "# pics: " . embolden((@pics)) . br;
102
103
          $container{innerHTML} .= tag(\%debug);
104
        }
105
      } else {
106
        { my %titlebar;
107
          $titlebar{tag} = "div";
108
          $titlebar{class} = "sticky subnavbar";
109
          $titlebar{style} = "width: 100%; text-align: left;";
110
          $titlebar{innerHTML} = "<table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=1>";
111
          { my %button;
112
            $button{tag} = "button";
113
            $button{type} = "button";
114
            $button{class} = "yellow";
115
            $button{onclick} = "document.location.reload();";
116
            $button{title} = "Reload";
117
            $button{innerHTML} = "";
118
119
            { my %img;
120
              $img{tag} = "img";
121
              $img{src} = "/img.pl?i=site/reload.png&s=u";
122
123
              $button{innerHTML} .= tag(\%img);
124
            }
125
126
            $titlebar{innerHTML} .= tag(\%button);
127
          }
128
          $titlebar{innerHTML} .= "</td><td class=spacerx></td><td class='nowrap subtitle text-align-left'>";
129
          $titlebar{innerHTML} .= "Photos Manager";
130
          $titlebar{innerHTML} .= "</td></tr></table>";
131
132
          $container{innerHTML} .= tag(\%titlebar);
133
        }
134
135
        { my %flagsdiv;
136
          $flagsdiv{tag} = "div";
137
          $flagsdiv{class} = "translucent";
138
          $flagsdiv{style} = "min-height: 320px;";
139
          $flagsdiv{innerHTML} = "<table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td align=center class=subtitle height=270>";
140
          { my %count;
141
            $count{tag} = "div";
142
            $count{class} = "yellow-panel";
143
            $count{innerHTML} = italicize((@pics) . " " . pluralize("Picture", @pics) . " Found!");
144
145
            $flagsdiv{innerHTML} .= tag(\%count);
146
          }
147
          $flagsdiv{innerHTML} .= "</td></tr><tr><td align=center>";
148
          if (@pics) {
149
            foreach my $pic (@pics) {
150
              { my %flagdiv;
151
                $flagdiv{tag} = "div";
152
                $flagdiv{class} = "translucent-fadein";
153
                $flagdiv{innerHTML} .= "<table border=0 cellpadding=0 cellspacing=0><tr><td align=center class=subtitle colspan=3>";
154
                { my %name;
155
                  $name{tag} = "div";
156
                  if ($pic->{name}) {
157
                    $name{class} .= "subnavbar";
158
                    $name{innerHTML} .= $pic->{name};
159
                  } else {
160
                    $name{class} .= "subnavbar_dark";
161
                    $name{innerHTML} .= "no name";
162
                  }
163
164
                  $flagdiv{innerHTML} .= tag(\%name);
165
                } # end name div
166
167
                $flagdiv{innerHTML} .= "</td></tr><tr><td class=spacery colspan=3>";
168
                $flagdiv{innerHTML} .= "</td></tr><tr><td>";
169
                { my %img;
170
                  $img{tag} = "img";
171
                  $img{src} = "/getimage.pl?&id=$pic->{ID}";
172
                  $img{class} = "sunken";
173
                  $img{width} = "250";
174
175
                  $flagdiv{innerHTML} .= tag(\%img);
176
                }
177
                $flagdiv{innerHTML} .= "</td><td class=spacerx></td><td align=right valign=top>";
178
                { my %button;
179
                  $button{tag} = "button";
180
                  $button{type} = "button";
181
                  $button{innerHTML} = "X";
182
                  $button{class} = "red";
183
                  $button{title} = "Delete Image";
184
185
                  $flagdiv{innerHTML} .= tag(\%button);
186
                }
187
188
                my $flagged = get_flag_data($params{get_constant("FLAG_ID")});
189
                { my %button;
190
                  $button{tag} = "button";
191
                  $button{type} = "button";
192
                  if ($flagged) {
193
                    $button{class} = "yellow";
194
                    $button{innerHTML} = "U";
195
                    $button{title} = "Unflag Image";
196
                  } else {
197
                    $button{class} = "red";
198
                    $button{innerHTML} = "F";
199
                    $button{title} = "Flag Image";
200
                  }
201
202
                  $flagdiv{innerHTML} .= tag(\%button);
203
                } # end flag/unflag button
204
205
                $flagdiv{innerHTML} .= "</td></tr><tr><td class=spacery colspan=3>";
206
                $flagdiv{innerHTML} .= "</td></tr><tr><td align=center colspan=3 valign=top>";
207
208
                { my %desc;
209
                  $desc{tag} = "div";
210
                  if ($pic->{description}) {
211
                    $desc{class} = "subnavbar";
212
                    $desc{style} = "width: 100%; text-align: left;";
213
                    $desc{innerHTML} .= "$pic->{description}";
214
                  } else {
215
                    $desc{class} .= "subnavbar_dark";
216
                    $desc{innerHTML} .= "no description";
217
                  }
218
219
                  $flagdiv{innerHTML} .= tag(\%desc);
220
                } # end desc div
221
                $flagdiv{innerHTML} .= "</td></tr></table>";
222
223
                $flagsdiv{innerHTML} .= tag(\%flagdiv);
224
              } # end flag div
225
            } # end foreach flag
226
          } # end if @pics
227
          $flagsdiv{innerHTML} .= "</td></tr></table>";
228
229
          $container{innerHTML} .= tag(\%flagsdiv);
230
        } # end flags div
231
      }
232
    } else {
233
      if ($DEBUG) {
234
        $container{innerHTML} .= "Please provide a UID...";
235
      } else {
236
        $container{innerHTML} .= "Please provide a UID...";
237
      }
238
    }
239
240
    $output .= tag(\%container);
241
  } # end container div
242
243
  ### END YOUR CONTENT
244
  $output .= html_end();
245
  ############################################################
246
}
247
248
print $output;
249
250
exit 1;