Mercurial > hg > index.fcgi > www > www-1
changeset 33:37ebfd93c8c2
add laterlinks
author | paulo |
---|---|
date | Fri, 08 Jun 2012 03:54:11 -0700 |
parents | 4d71846e56ee |
children | fbf56963efcc |
files | laterlinks/index.php |
diffstat | 1 files changed, 130 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/laterlinks/index.php Fri Jun 08 03:54:11 2012 -0700 1.3 @@ -0,0 +1,130 @@ 1.4 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 1.5 +<HTML> 1.6 +<HEAD> 1.7 +<META NAME="generator" CONTENT="http://txt2tags.sf.net"> 1.8 +<LINK REL="stylesheet" TYPE="text/css" HREF="index.css"> 1.9 +<TITLE>later links...</TITLE> 1.10 +</HEAD> 1.11 +<BODY> 1.12 + 1.13 +<DIV CLASS="header" ID="header"> 1.14 +<H1>later links...</H1> 1.15 +</DIV> 1.16 + 1.17 +<DIV CLASS="body" ID="body"> 1.18 + 1.19 +<?php 1.20 + 1.21 + include('../../login.php'); 1.22 + $database = 'pauloang_laterlinks'; 1.23 + 1.24 + $link = mysql_connect('localhost', $username, $password); 1.25 + if (!$link) 1.26 + die('Could not connect to MySQL server: ' . mysql_error()); 1.27 + 1.28 + $db_selected = mysql_select_db($database, $link); 1.29 + if (!$db_selected) 1.30 + die('Could not select database: ' . mysql_error()); 1.31 + 1.32 +?> 1.33 + 1.34 +<?php 1.35 + 1.36 + $_MY_PIN = 'qwop'; 1.37 + $pin = ''; 1.38 + 1.39 + if (count($_POST) > 0) { 1.40 + echo '<PRE>' . "\n"; 1.41 + 1.42 + foreach ($_POST as $postKey => $postValue) { 1.43 + if ($postKey != "pin") 1.44 + echo $postKey . " => " . $postValue . "\n"; 1.45 + else if ($postKey == "pin") { 1.46 + echo 'pin => '; 1.47 + for ($i = 0, $n = strlen($postValue); $i < $n; $i++) echo 'x'; 1.48 + echo "\n"; 1.49 + $pin = $postValue; 1.50 + } 1.51 + } 1.52 + 1.53 + if ($pin == $_MY_PIN) { 1.54 + echo "PIN OK \n"; 1.55 + 1.56 + $query = NULL; 1.57 + 1.58 + if ($_POST["submit"] == "Delete") { 1.59 + $delete_ids = array(); 1.60 + $delete_id_prefix = "delete_id_"; 1.61 + $delete_id_prefix_len = strlen($delete_id_prefix); 1.62 + foreach ($_POST as $postKey => $postValue) { 1.63 + if (strncmp($postKey, $delete_id_prefix, $delete_id_prefix_len) == 0) 1.64 + array_push($delete_ids, intval($postValue)); 1.65 + } 1.66 + if (count($delete_ids) > 0) { 1.67 + $query = sprintf("DELETE FROM LaterLinks WHERE id in (%s)", join(',', $delete_ids)); 1.68 + echo $query; 1.69 + } 1.70 + } else if ($_POST["submit"] == "Add") { 1.71 + $title = mysql_real_escape_string(trim($_POST["title"])); 1.72 + $url = mysql_real_escape_string(trim($_POST["url"])); 1.73 + if (strlen($title) && strlen($url)) { 1.74 + $query = sprintf("INSERT INTO LaterLinks SET title='%s', url='%s'", $title, $url); 1.75 + echo $query; 1.76 + } 1.77 + } 1.78 + 1.79 + if (!is_null($query)) 1.80 + mysql_query($query); 1.81 + } else 1.82 + echo "PIN FAIL \n"; 1.83 + 1.84 + echo '</PRE>' . "\n"; 1.85 + } 1.86 + 1.87 +?> 1.88 + 1.89 +<FORM ACTION="index.php" METHOD=post> 1.90 + 1.91 +<TABLE> 1.92 +<TR> 1.93 + <TH>Link</TH> 1.94 + <TH>Created</TH> 1.95 + <TH><INPUT TYPE=submit NAME="submit" VALUE="Delete"></TH> 1.96 +</TR> 1.97 + 1.98 +<?php 1.99 + 1.100 + $query = 'SELECT * FROM LaterLinks'; 1.101 + $results = mysql_query($query); 1.102 + 1.103 + while ($row = mysql_fetch_assoc($results)) { 1.104 + echo '<TR>'; 1.105 + echo ' <TD><A HREF="'.$row['url'].'">'.$row['title'].'</A></TD>'; 1.106 + echo ' <TD>'.$row['created_at'].'</TD>'; 1.107 + echo ' <TD><INPUT TYPE=checkbox NAME="delete_id_'.$row['id'].'" VALUE="'.$row['id'].'"></TD>'; 1.108 + echo '</TR>'; 1.109 + } 1.110 + 1.111 + mysql_free_result($results); 1.112 + mysql_close($link); 1.113 +?> 1.114 + 1.115 +</TABLE> 1.116 + 1.117 +<P> 1.118 +<LABEL>Title<INPUT TYPE=text NAME="title"></LABEL><BR> 1.119 +<LABEL>URL<INPUT TYPE=text NAME="url"></LABEL><BR> 1.120 +<INPUT TYPE=submit NAME="submit" VALUE="Add"> 1.121 +<P> 1.122 + 1.123 +<P> 1.124 +<INPUT TYPE=password NAME="pin" VALUE="<?php echo $pin ?>"> 1.125 +</P> 1.126 + 1.127 +</FORM> 1.128 + 1.129 +</DIV> 1.130 + 1.131 +<!-- html code generated by txt2tags 2.4 (http://txt2tags.sf.net) --> 1.132 +<!-- cmdline: txt2tags index.t2t --> 1.133 +</BODY></HTML>