Upload version 0.5
[LocalLink.git] / www / protected / edit.html
blob14c6620e396eb187cdf4783dc06a69e9f4fc9ad4
1 <?php
2 $title = "Template(s) & file editing";
3 /* <Template> */
5 function add_magic_quotes($array) {
6 foreach ($array as $k => $v) {
7 if (is_array($v)) {
8 $array[$k] = add_magic_quotes($v);
9 } else {
10 $array[$k] = addslashes($v);
13 return $array;
16 if (!get_magic_quotes_gpc()) {
17 $HTTP_GET_VARS = add_magic_quotes($HTTP_GET_VARS);
18 $HTTP_POST_VARS = add_magic_quotes($HTTP_POST_VARS);
19 $HTTP_COOKIE_VARS = add_magic_quotes($HTTP_COOKIE_VARS);
22 $b2varstoreset = array('action','standalone','redirect','profile','error','warning','a','file');
23 for ($i=0; $i<count($b2varstoreset); $i += 1) {
24 $b2var = $b2varstoreset[$i];
25 if (!isset($$b2var)) {
26 if (empty($HTTP_POST_VARS["$b2var"])) {
27 if (empty($HTTP_GET_VARS["$b2var"])) {
28 $$b2var = '';
29 } else {
30 $$b2var = $HTTP_GET_VARS["$b2var"];
32 } else {
33 $$b2var = $HTTP_POST_VARS["$b2var"];
38 switch($action) {
40 case "update":
42 $standalone=1;
44 $newcontent = stripslashes($HTTP_POST_VARS["newcontent"]);
45 $file = $HTTP_POST_VARS["file"];
46 $f = fopen($file,"w+");
47 fwrite($f,$newcontent);
48 fclose($f);
50 // header("Location: index.php?file=$file&a=te");
51 // exit();
53 // break;
55 default:
57 $file = $HTTP_POST_VARS["file"];
59 if ( ereg('/', $file ) && !ereg('^/', $file ) )
60 $file = str_replace('/', '.', $file);
62 if ( !ereg('.comment[2]?$', $file) )
63 $file .= '.comment2';
65 if ($file==".comment2") {
66 // prepend with '<directory name>.' if comments under <directory name>
67 $file = "notes.html.comment2";
68 // change from notes to whichever page it is your comments are on
71 if ( !ereg('^/usr', $file ) )
72 $file = ANNOTATE_DIR . $project . '/' . $file;
74 if (!is_file($file))
75 $error = 1;
77 $file = stripslashes($file);
79 if (!$error) {
80 $f = fopen($file,"r");
81 $content = fread($f,filesize($file));
82 $content = htmlspecialchars($content);
85 echo $blankline;
87 <table width="100%" cellpadding="5" cellspacing="0">
88 <tr>
89 <td>
90 <?php
91 echo "Listing <b>$file</b>".$warning;
92 if ($a == "te")
93 echo "<i> [ file edited ! ]</i>";
95 if (!$error) {
97 <form name="template" action="edit.html" method="post">
98 <textarea cols="80" rows="20" style="width:100%" name="newcontent" tabindex="1"><?php echo $content ?></textarea>
99 <input type="hidden" name="action" value="update" />
100 <input type="hidden" name="file" value="<?php echo $file ?>" />
101 <br />
102 <?php
103 if (is_writeable($file)) {
104 echo "<input type=\"submit\" name=\"submit\" class=\"search\" value=\"update template !\" tabindex=\"2\" />";
105 } else {
106 echo "<input type=\"button\" name=\"oops\" class=\"search\" value=\"(you cannot update that file/template: must make it writable, e.g. CHMOD 766)\" tabindex=\"2\" />";
109 </form>
110 <?php
111 } else {
112 echo "<p>oops, no such file !</p>";
114 echo $tablebottom;
116 </td>
117 </table>
118 <br />
119 <br /><?php break;
122 /* </Template> */