(no commit message)
[wiki] / wishlist.mdwn
1 <?php
2 # Shoutbox 1.0
3 # by Andreas Beder
4 # codejungle.org
5 # mod for tinc wiki
6 # by wopot
7 # Licence GNU GPL 2
8
9 //config
10 $filename="wishlist.txt";
11
12 // be sure the file have write permissions
13 $url="http://tinc-vpn.org/wishlist/";
14
15 //function 
16
17 function get_content(){
18 global $filename;
19       $lines = file ($filename);
20       $start = count($lines)-12;
21       if ($start < 1) $start = 1;
22       for ($i = $start; $i < count ($lines); $i++){
23       $somecontent.=stripslashes($lines[$i]);
24       }
25 return $somecontent;
26 }
27
28 function add_content(){
29 global $filename;
30 if($_POST[submit] and $_POST[nick] and $_POST[content]){
31 //check content
32 //add content
33  $_SESSION["nick"]=$_POST[nick];
34  $somecontent=strip_tags($_POST[nick]).": ".strip_tags($_POST[content])."<br/>n";
35  $handle = fopen($filename, 'a+');
36  fwrite($handle, $somecontent);
37 }
38 }
39
40 function output_form(){
41
42 echo '
43 <form action="" method="post">
44 Name:';
45 if($_SESSION[nick]){
46         echo $_SESSION[nick].'<input type="hidden" name="nick" value="'.$_SESSION[nick].'"><br>';
47 }
48 else { 
49         echo '<br><input name="nick" type="text" value="'.$_SESSION[nick].'"><br>'; 
50 }
51 echo'
52 Your Wish/Idea for the tinc Project:<br>
53 <textarea rows="5" cols="100" name="content"></textarea><br>
54 <input type="submit" name="submit" value="save">
55 </form>
56 ';
57
58 }
59
60 if($_GET[content]=="true"){
61 echo get_content();
62 die();
63 }
64 ?>
65 <html>
66 <head>
67 <title>shoutbox demo</title>
68 <script type="text/javascript" language="javascript">
69
70     var http_request = false;
71
72     function macheRequest(url) {
73
74         http_request = false;
75
76         if (window.XMLHttpRequest) { // Mozilla, Safari,...
77             http_request = new XMLHttpRequest();
78             if (http_request.overrideMimeType) {
79                 http_request.overrideMimeType('text/xml');
80                 // zu dieser Zeile siehe weiter unten
81             }
82         } else if (window.ActiveXObject) { // IE
83             try {
84                 http_request = new ActiveXObject("Msxml2.XMLHTTP");
85             } catch (e) {
86                 try {
87                     http_request = new ActiveXObject("Microsoft.XMLHTTP");
88                 } catch (e) {}
89             }
90         }
91
92         if (!http_request) {
93             alert('Ende :( Kann keine XMLHTTP-Instanz erzeugen');
94             return false;
95         }
96         http_request.onreadystatechange = alertInhalt;
97         http_request.open('GET', url, true);
98         http_request.send(null);
99
100     }
101
102     function alertInhalt() {
103
104         if (http_request.readyState == 4) {
105             if (http_request.status == 200) {
106                 document.getElementById("shoutbox").innerHTML=http_request.responseText;
107                 var objDiv = document.getElementById("shoutbox");
108                 objDiv.scrollTop = objDiv.scrollHeight;
109                 setTimeout('macheRequest("<?php echo $url; ?>?content=true")',2000);
110
111             } else {
112                 alert('Bei dem Request ist ein Problem aufgetreten.');
113             }
114         }
115
116     }
117 </script>
118 </head>
119 <body onload="macheRequest('<?php echo $url; ?>?content=true');">
120 <h1>Wislist</h1>
121 <h2>Drop your Ideas into this Box</h2>
122 <h4>(The Idea will stay for a while and will check form the dev. Team)</h4>
123
124 <?php add_content(); ?>
125 <div style="border:1px solid #ccc; width:500px; height:300px; max-height:300px; overflow:auto;" name="shoutbox" id="shoutbox"></div>
126 <?php output_form(); ?>
127
128 </body>
129 </html>