view laterlinks/index.php @ 65:e3bbdec7e12a

refactor clock to use d3 style routines
author paulo
date Wed, 01 Oct 2014 00:30:36 -0700
parents
children
line source
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <HTML>
3 <HEAD>
4 <META NAME="generator" CONTENT="http://txt2tags.sf.net">
5 <LINK REL="stylesheet" TYPE="text/css" HREF="index.css">
6 <TITLE>later links...</TITLE>
7 </HEAD>
8 <BODY>
10 <DIV CLASS="header" ID="header">
11 <H1>later links...</H1>
12 </DIV>
14 <DIV CLASS="body" ID="body">
16 <?php
18 include('../../login.php');
19 $database = 'pauloang_laterlinks';
21 $link = mysql_connect('localhost', $username, $password);
22 if (!$link)
23 die('Could not connect to MySQL server: ' . mysql_error());
25 $db_selected = mysql_select_db($database, $link);
26 if (!$db_selected)
27 die('Could not select database: ' . mysql_error());
29 ?>
31 <?php
33 $_MY_PIN = 'qwop';
34 $pin = '';
36 if (count($_POST) > 0) {
37 echo '<PRE>' . "\n";
39 foreach ($_POST as $postKey => $postValue) {
40 if ($postKey != "pin")
41 echo $postKey . " => " . $postValue . "\n";
42 else if ($postKey == "pin") {
43 echo 'pin => ';
44 for ($i = 0, $n = strlen($postValue); $i < $n; $i++) echo 'x';
45 echo "\n";
46 $pin = $postValue;
47 }
48 }
50 if ($pin == $_MY_PIN) {
51 echo "PIN OK \n";
53 $query = NULL;
55 if ($_POST["submit"] == "Delete") {
56 $delete_ids = array();
57 $delete_id_prefix = "delete_id_";
58 $delete_id_prefix_len = strlen($delete_id_prefix);
59 foreach ($_POST as $postKey => $postValue) {
60 if (strncmp($postKey, $delete_id_prefix, $delete_id_prefix_len) == 0)
61 array_push($delete_ids, intval($postValue));
62 }
63 if (count($delete_ids) > 0) {
64 $query = sprintf("DELETE FROM LaterLinks WHERE id in (%s)", join(',', $delete_ids));
65 echo $query;
66 }
67 } else if ($_POST["submit"] == "Add") {
68 $title = mysql_real_escape_string(trim($_POST["title"]));
69 $url = mysql_real_escape_string(trim($_POST["url"]));
70 if (strlen($title) && strlen($url)) {
71 $query = sprintf("INSERT INTO LaterLinks SET title='%s', url='%s'", $title, $url);
72 echo $query;
73 }
74 }
76 if (!is_null($query))
77 mysql_query($query);
78 } else
79 echo "PIN FAIL \n";
81 echo '</PRE>' . "\n";
82 }
84 ?>
86 <FORM ACTION="index.php" METHOD=post>
88 <TABLE>
89 <TR>
90 <TH>Link</TH>
91 <TH>Created</TH>
92 <TH><INPUT TYPE=submit NAME="submit" VALUE="Delete"></TH>
93 </TR>
95 <?php
97 $query = 'SELECT * FROM LaterLinks';
98 $results = mysql_query($query);
100 while ($row = mysql_fetch_assoc($results)) {
101 echo '<TR>';
102 echo ' <TD><A HREF="'.$row['url'].'">'.$row['title'].'</A></TD>';
103 echo ' <TD>'.$row['created_at'].'</TD>';
104 echo ' <TD><INPUT TYPE=checkbox NAME="delete_id_'.$row['id'].'" VALUE="'.$row['id'].'"></TD>';
105 echo '</TR>';
106 }
108 mysql_free_result($results);
109 mysql_close($link);
110 ?>
112 </TABLE>
114 <P>
115 <LABEL>Title<INPUT TYPE=text NAME="title"></LABEL><BR>
116 <LABEL>URL<INPUT TYPE=text NAME="url"></LABEL><BR>
117 <INPUT TYPE=submit NAME="submit" VALUE="Add">
118 <P>
120 <P>
121 <INPUT TYPE=password NAME="pin" VALUE="<?php echo $pin ?>">
122 </P>
124 </FORM>
126 </DIV>
128 <!-- html code generated by txt2tags 2.4 (http://txt2tags.sf.net) -->
129 <!-- cmdline: txt2tags index.t2t -->
130 </BODY></HTML>