summaryrefslogtreecommitdiff
blob: 251655e7f059f42e9d2a828f8e8a8fd5e2baa3ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
# Adopt a Developer
#
# Copyright (C) 2006 Thomas Cort
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

class project_action extends actor {
  function execute() {
    global $accesslevel, $username;
    trigger("html_headers");
    if (isset($_REQUEST['project'])) {
      trigger("project");
      trigger("display_project");
    } else if (isset($_REQUEST['project_add'])) {
      trigger("project_add");
      trigger("display_project");
    } else {
      trigger("display_project");
    }
    trigger("html_footers");
    return new return_result(true);
  }
}

class display_project_event extends actor {
  function execute() {

    trigger("begin_story");

    if ($username != "guest") {
      echo "<h2>Projects (ordered by name)</h2>";
      $result = db_query("select projectid, name, url from projects order by name");
      while ($result->has_next()) {
        $row = $result->get_row();
        echo "<form action=\"./\" method=\"post\"><table>";
        echo "<tr><th>Name: </td><td bgcolor=\"#eeeeee\" colspan=\"2\">";
        echo "<input type=\"text\" name=\"project_name\" value=\"$row[1]\"></td>";
        echo "<th>URL: </td><td bgcolor=\"#eeeeee\" colspan=\"2\">";
        echo "<input type=\"text\" name=\"project_url\" value=\"$row[2]\"></td><td bgcolor=\"#eeeeee\">";
        echo "<input type=\"hidden\" name=\"a\" value=\"project\">";
        echo "<input type=\"hidden\" name=\"project\" value=\"1\">";
        echo "<input type=\"hidden\" name=\"projectid\" value=\"$row[0]\">";
        echo "&nbsp;</td><td bgcolor=\"#eeeeee\"><input type=\"submit\" id=\"button\" value=\"change\">";
        echo "</td><td bgcolor=\"#eeeeee\"><input type=\"reset\" id=\"button\" value=\"clear\"></td></tr>";
        echo "</table></form><br>";
      }

      echo "<h2>Add a Project</h2>";
      echo "<form action=\"./\" method=\"post\"><table>";
      echo "<tr><th>Project Name: </td><td bgcolor=\"#eeeeee\" colspan=\"2\">";
      echo "<input type=\"text\" name=\"project_name\"></td></tr><tr><td>";
      echo "<tr><th>URL: </td><td bgcolor=\"#eeeeee\" colspan=\"2\">";
      echo "<input type=\"text\" name=\"project_url\"></td></tr><tr><td bgcolor=\"#eeeeee\">";
      echo "<input type=\"hidden\" name=\"a\" value=\"project\">";
      echo "<input type=\"hidden\" name=\"project_add\" value=\"1\">";
      echo "&nbsp;</td><td bgcolor=\"#eeeeee\"><input type=\"submit\" id=\"button\" value=\"add\">";
      echo "</td><td bgcolor=\"#eeeeee\"><input type=\"reset\" id=\"button\" value=\"clear\"></td></tr>";
      echo "</table></form>";

    } else {

      echo "<h2>You aren't Logged In!</h2>";
      echo "<h2>Thank You! Come again!</h2>";

    }

    trigger("end_story");
    return new return_result(true);
  }
}

class project_event extends actor {
  function execute() {

    $projectid    = isset($_REQUEST['projectid']) && is_numeric($_REQUEST['projectid']) ? $_REQUEST['projectid'] : "";
    $project_name = isset($_REQUEST['project_name']) ? $_REQUEST['project_name'] : "";
    $project_url  = isset($_REQUEST['project_url'])  ? $_REQUEST['project_url']   : "";

    if (is_numeric($projectid) && $project_url != "" && $project_name != "") {
      $result = db_query("SELECT * from projects where url = '".doslashes($project_url)."' and name = '".doslashes($project_name)."';");
      if (!$result->has_next()) {
        $result = db_query("SELECT * from projects where projectid = $projectid");
        if ($result->has_next()) {
          if (db_exec("update projects set url = '".doslashes($project_url)."', name = '".doslashes($project_name)."' where projectid = $projectid")) {
             trigger("begin_story");
             echo "<h2>Done!</h2>";
             trigger("end_story");
          } else {
             trigger("begin_story");
             echo "<h2>DB Error!</h2>";
             trigger("end_story");
          }
        } else {
          trigger("begin_story");
          echo "<h2>Project ID does not exist!</h2>";
          echo "<h2>Thank You! Come again!</h2>";
          trigger("end_story");
        }
      } else {
        trigger("begin_story");
        echo "<h2>Nothing Has Changed!</h2>";
        echo "<h2>Thank You! Come again!</h2>";
        trigger("end_story");
      }
    } else {
      trigger("begin_story");
      echo "<h2>Incomplete Form Data!</h2>";
      echo "<h2>Thank You! Come again!</h2>";
      trigger("end_story");
    }

    echo "<br>";
    return new return_result(true);
  }
}

class project_add_event extends actor {
  function execute() {

    $project_name = isset($_REQUEST['project_name']) ? $_REQUEST['project_name'] : "";
    $project_url  = isset($_REQUEST['project_url'])  ? $_REQUEST['project_url']  : "";

    if ($project_url != "" && $project_name != "") {
      if (db_exec("insert into projects (name,url) values ('".doslashes($project_name)."','".doslashes($project_url)."')")) {
        trigger("begin_story");
        echo "<h2>Done!</h2>";
        trigger("end_story");
      } else {
        trigger("begin_story");
        echo "<h2>DB Error</h2>";
        trigger("end_story");
      }
    } else {
      trigger("begin_story");
      echo "<h2>Incomplete Form Data!</h2>";
      echo "<h2>Thank You! Come again!</h2>";
      trigger("end_story");
    }

    echo "<br>";
    return new return_result(true);
  }
}

register_handler(new project_event("project",50));
register_handler(new project_add_event("project_add",50));
register_handler(new display_project_event("display_project",50));
register_action(new project_action("project",50));
?>