]> ruin.nu Git - ndwebbie.git/blob - ND/Web/Pages/AddIntel.pm
big restructure
[ndwebbie.git] / ND / Web / Pages / AddIntel.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
4 #   This program is free software; you can redistribute it and/or modify  *
5 #   it under the terms of the GNU General Public License as published by  *
6 #   the Free Software Foundation; either version 2 of the License, or     *
7 #   (at your option) any later version.                                   *
8 #                                                                         *
9 #   This program is distributed in the hope that it will be useful,       *
10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 #   GNU General Public License for more details.                          *
13 #                                                                         *
14 #   You should have received a copy of the GNU General Public License     *
15 #   along with this program; if not, write to the                         *
16 #   Free Software Foundation, Inc.,                                       *
17 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18 #**************************************************************************/
19
20 package ND::Web::Pages::AddIntel;
21 use strict;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
24 use ND::Web::Forum;
25 use ND::Web::Include;
26
27 $ND::PAGES{addintel} = {parse => \&parse, process => \&process, render=> \&render};
28
29 sub parse {
30 }
31
32 sub process {
33
34 }
35
36 sub render {
37         my ($DBH,$BODY) = @_;
38         $ND::TEMPLATE->param(TITLE => 'Add Intel and Scans');
39
40         my $error;
41
42         return $ND::NOACCESS unless isMember();
43
44         if (defined param('cmd')){
45                 if (param('cmd') eq 'submit' || param('cmd') eq 'submit_message'){
46                         my $findscan = $DBH->prepare("SELECT scan_id FROM scans WHERE scan_id = ? AND tick >= tick() - 48");
47                         my $addscan = $DBH->prepare('INSERT INTO scans (scan_id,tick,"type") VALUES (?,tick(),?)');
48                         my $addpoint = $DBH->prepare('UPDATE users SET scan_points = scan_points + 1 WHERE uid = ? ');
49                         my $intel = param('intel');
50                         my @scans;
51                         while ($intel =~ m/http:\/\/game.planetarion.com\/showscan.pl\?scan_id=(\d+)/g){
52                                 my %scan;
53                                 $scan{Scan} = $1;
54                                 $scan{Message} = "Scan $1: ";
55                                 $findscan->execute($1);
56                                 if ($findscan->rows == 0){
57                                         if ($addscan->execute($1,$ND::UID)){
58                                                 $addpoint->execute($ND::UID);
59                                                 $scan{Message} .= '<i>added</i>';
60                                         }else{
61                                                 $scan{Message} .= "<b>something went wrong:</b> <i>$DBH->errstr</i>";
62                                         }
63                                 }else{
64                                         $scan{Message} .= '<b>already exists</b>';
65                                 }
66                                 push @scans,\%scan;
67                         }
68                         $BODY->param(Scans => \@scans);
69                         my $tick = $ND::TICK;
70                         $tick = param('tick') if $tick =~ /^(\d+)$/;
71                         my $addintel = $DBH->prepare(qq{SELECT add_intel(?,?,?,?,?,?,?,?,?,?,?)});
72                         while ($intel =~ m/(\d+):(\d+):(\d+)\*?\s+(\d+):(\d+):(\d+)\*?\s+.+(?:Ter|Cat|Xan|Zik)?\s+(\d+)\s+(Attack|Defend)\s+(\d+)/g){
73                                 $addintel->execute($tick,$9, $1,$2,$3,$4,$5,$6,$7,$8,$ND::UID) or $error .= $DBH->errstr;
74                         }
75                 }
76                 if (param('cmd') eq 'submit_message'){
77                         my $board = {id => 12};
78                         my $subject = param('subject');
79                         unless ($subject){
80                                 if (param('intel') =~ /(.*\w.*)/){
81                                         $subject = $1;
82                                 }
83
84                         }
85                         if (my $thread = addForumThread $DBH,$board,$ND::UID,$subject){
86                                 $error .= p 'Intel message added' if addForumPost $DBH,$thread,$ND::UID,param('intel')
87                         }
88                 }
89         }
90         $BODY->param(Tick => $ND::TICK);
91         $BODY->param(Error => $error);
92         return $BODY;
93 }
94 1;