summaryrefslogtreecommitdiff
path: root/backend.php
blob: 45d169bb39aa4cea5ccea7c3815b37a2689b17f5 (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
<?

include "theme.inc";
include "backend.class.php";

function adminAddChannel() {
  ?>
   <HR>
   <FORM ACTION="backend.php" METHOD="post">
   <P>
    <B>Site name:</B><BR>
    <INPUT TYPE="text" NAME="site" SIZE="50">
   </P>

   <P>
    <B>URL:</B><BR>
    <INPUT TYPE="text" NAME="url" SIZE="50">
   </P>

   <P>
    <B>Backend file:</B><BR>
    <INPUT TYPE="text" NAME="file" SIZE="50">
   </P>

   <P>
    <B>Contact information:</B><BR>
    <INPUT TYPE="text" NAME="contact" SIZE="50">
   </P>
   <INPUT TYPE="submit" NAME="op" VALUE="Add backend"> 
   </FORM>
  <?
}

function displayAll() {
  global $theme;

  ### Connect to database:
  dbconnect();

  ### Get channel info:
  $result = mysql_query("SELECT * FROM channel ORDER BY id");

  print "<HR>";
  print "<TABLE BORDER=\"0\">";
  while ($channel = mysql_fetch_object($result)) {
    if ($state % 3 == 0) print " <TR>";

    print " <TD ALIGN=\"center\" VALIGN=\"top\" WIDTH=\"33%\">";
    
    ### Load backend from database:
    $backend = new backend($channel->id);
    
    ### Read headlines from backend class:
    $content = "";
    for (reset($backend->headlines); $headline = current($backend->headlines); next($backend->headlines)) {
      $content .= "<LI>$headline</LI>";
    }

    ### Print backend box to screen:
    $theme->box($backend->site, "$content<P ALIGN=\"right\">[ <A HREF=\"$backend->url\">more</A> ]");
    print " </TD>";

    if ($state % 3 == 2) print " </TR>";

    $state += 1;
  }  
  print "</TABLE>";
}

function adminMain() {
  global $theme, $PHP_SELF;

  ### Connect to database:
  dbconnect();

  ### Get channel info:
  $result = mysql_query("SELECT * FROM channel ORDER BY id");

  print "<TABLE BORDER=\"0\" WIDTH=\"100%\" CELLSPACING=\"2\" CELLPADDING=\"4\">";
  print " 
  <TR BGCOLOR=\"$theme->bgcolor1\"><TD ALIGN=\"center\"><B><FONT COLOR=\"$theme->fgcolor1\">Site</FONT></B></TD><TD ALIGN=\"center\"><B><FONT COLOR=\"$theme->fgcolor1\">Contact</FONT></B></TD><TD ALIGN=\"center\"><B><FONT COLOR=\"$theme->fgcolor1\">Last updated</FONT></B></TD><TD ALIGN=\"center\" COLSPAN=\"2\"><B><FONT COLOR=\"$theme->fgcolor1\">Operations</FONT></B></TD></TR>";
  while ($channel = mysql_fetch_object($result)) {
    ### Load backend from database:
    $backend = new backend($channel->id);
    
    print "<TR BGCOLOR=\"$theme->bgcolor2\">";
    print " <TD><A HREF=\"$backend->url\">$backend->site</A></TD>";
    print " <TD><A HREF=\"mailto:$backend->contact\">$backend->contact</A></TD>";
    print " <TD ALIGN=\"center\">". round((time() - $backend->timestamp) / 60) ." min. ago</TD>";
    print " <TD ALIGN=\"center\"><A HREF=\"$PHP_SELF?op=refresh&id=$backend->id\">refresh</A></TD>";
    print " <TD ALIGN=\"center\"><A HREF=\"$PHP_SELF?op=delete&id=$backend->id\">delete</A></TD>";
    print "</TR>";
  }  
  print "</TABLE>";
  print "<BR><BR>";
}


$theme->header();

switch($op) {
  case "refresh":
    $backend = new backend($id);
    $backend->refresh();
    adminMain();
    displayAll();
    adminAddChannel();
    break;
  case "delete":
    print "ID = $id<BR>";
    $backend = new backend($id);
    $backend->dump();
    $backend->delete();
    adminMain();
    displayAll();
    adminAddChannel();
    break;
  case "Add backend":
    $backend = new backend($id, $site, $url, $file, $contact);
    $backend->add();
    // fall through:
  default:
    adminMain();
    displayAll();
    adminAddChannel();
}

$theme->footer();

?>