Ticket #781: EditPage.php

File EditPage.php, 8.5 KB (added by Martin Kou, 17 years ago)

The file that is loading file to FCKeditor from both DataBase and File is attached. Moved from SF. Original author: atif123

Line 
1<?php
2session_start();
3if (isset($_SESSION["login"])) {
4} else {
5header("Location: index.php?TimeOut=1");
6}
7?>
8<?php
9   include "../includes/connection.inc.php";
10   $var = ($_GET['resource_type']=="");
11   //echo "::$var::<br>";
12   $var = (!array_key_exists('resource_type',$_GET));
13   //echo "::$var::<br>";
14   if(array_key_exists("resource_type",$_GET) && !array_key_exists("resource_name",$_GET))
15   {
16        $rt = $_GET['resource_type'];
17        //echo "outer if rt<br>";
18          if($rt=="")
19          {
20                $resourcetypecombo="<select id=\"resource_type\" name=\"resource_type\" onChange=\"updatePage1()\">
21          <option>Select An Option</option>
22          <option value=\"1\">dyamic contents[pages]</option>
23          <option value=\"2\">Files on server</option>
24        </select>";
25          }     
26          else if($rt==1) // dynamic contents (pages) is selected
27          {
28                //echo "in rt=1<br>";
29                $resourcetypecombo="<select id=\"resource_type\" name=\"resource_type\" onChange=\"updatePage1()\">
30          <option>Select An Option</option>
31          <option value=\"1\" selected=\"selected\">dyamic contents[pages]</option>
32          <option value=\"2\">Files on server</option>
33        </select>";
34                $sql = "select * from pages order by page_name";
35                $Result = mysql_query($sql);
36                        $resoucenamecombo = "<option value=\"\">Select A Page</option>";
37                        while($row = mysql_fetch_array($Result, MYSQL_BOTH))
38                        {
39                                $id=$row[id];
40                                $page_name = $row[page_name];
41                                $resoucenamecombo .= "<option value=\"$id\">$page_name</option>";
42                        }
43          }
44          else if($rt==2)
45          {
46                        //echo "in rt=2<br>";
47                        $resourcetypecombo="<select id=\"resource_type\" name=\"resource_type\" onChange=\"updatePage1()\">
48          <option>Select An Option</option>
49          <option value=\"1\">dyamic contents[pages]</option>
50          <option value=\"2\"  selected=\"selected\">Files on server</option>
51        </select>";
52                $resoucenamecombo = "<option value=\"\">Select A File</option>";
53                $dh  = opendir("../htmlfiles");
54                        clearstatcache();
55                        while (false !== ($filename = readdir($dh))) {
56                        $files[] = $filename;
57                        }
58                        sort($files);
59                        $size=count($files);
60                        for($i=0; $i<$size; $i++)
61                                {
62                                        $ext = substr(strrchr($files[$i], "."), 1); /* get extension without dot */
63                                        if(is_file("../htmlfiles/$files[$i]") && ($ext=='htm' || $ext=='html'))
64                                        {
65                                                $resoucenamecombo.="<option value=\"{$files[$i]}\">{$files[$i]}</option>";
66                                        }
67                                }
68          }
69         
70   }
71   else if(array_key_exists('resource_type',$_GET) && array_key_exists('resource_name',$_GET)) // if resource_type and resource_name selected change HTML contents of WYSIWYG HTML editor
72   {
73                //echo "in second if";
74                $rt=$_GET['resource_type'];
75                if($rt=="")
76          {
77                $resourcetypecombo="<select id=\"resource_type\" name=\"resource_type\" onChange=\"updatePage1()\">
78          <option>Select An Option</option>
79          <option value=\"1\">dyamic contents[pages]</option>
80          <option value=\"2\">Files on server</option>
81        </select>";
82          }     
83          else if($rt==1) // dynamic contents (pages) is selected
84          {
85                $pageid = $_GET['resource_name'];
86                //echo "in rt=1<br>";
87                $resourcetypecombo="<select id=\"resource_type\" name=\"resource_type\" onChange=\"updatePage1()\">
88          <option>Select An Option</option>
89          <option value=\"1\" selected=\"selected\">dyamic contents[pages]</option>
90          <option value=\"2\">Files on server</option>
91        </select>";
92                $sql = "select * from pages order by page_name";
93                $Result = mysql_query($sql);
94                        $resoucenamecombo = "<option value=\"\">Select A Page</option>";
95                        while($row = mysql_fetch_array($Result, MYSQL_BOTH))
96                        {
97                                $id=$row[id];
98                                $page_name = $row[page_name];
99                                if($id==$pageid)
100                                        $resoucenamecombo .= "<option value=\"$id\" selected=\"selected\">$page_name</option>";
101                                else
102                                        $resoucenamecombo .= "<option value=\"$id\">$page_name</option>";
103                        }
104                        $sql  = "select * from pages where id=$pageid";
105                        $Result = mysql_query($sql);
106                        $row = mysql_fetch_array($Result, MYSQL_BOTH);
107                        $PageAuthorName = $row['author_name'];
108                        $PageTitle = $row['title'];
109                        $contents = $row['body'];
110          }
111          else if($rt==2)
112          {
113                        $ffilename = $_GET['resource_name'];
114                        //echo "in rt=2<br>";
115                        $resourcetypecombo="<select id=\"resource_type\" name=\"resource_type\" onChange=\"updatePage1()\">
116          <option>Select An Option</option>
117          <option value=\"1\">dyamic contents[pages]</option>
118          <option value=\"2\"  selected=\"selected\">Files on server</option>
119        </select>";
120                $resoucenamecombo = "<option value=\"\">Select A File</option>";
121                $dh  = opendir("../htmlfiles");
122                        clearstatcache();
123                        while (false !== ($filename = readdir($dh))) {
124                        $files[] = $filename;
125                        }
126                        sort($files);
127                        $size=count($files);
128                        for($i=0; $i<$size; $i++)
129                                {
130                                        $ext = substr(strrchr($files[$i], "."), 1); /* get extension without dot */
131                                        if(is_file("../htmlfiles/$files[$i]") && ($ext=='htm' || $ext=='html'))
132                                        {
133                                                //echo "$ffilename==$files[$i]<br>";
134                                                if($ffilename==$files[$i])
135                                                        $resoucenamecombo.="<option value=\"{$files[$i]}\" selected=\"selected\">{$files[$i]}</option>";
136                                                else
137                                                        $resoucenamecombo.="<option value=\"{$files[$i]}\">{$files[$i]}</option>";
138                                        }
139                                }
140                       
141                        $PageAuthorEnabled = "Disabled='Disabled'";  // Disable text field, no use in case of files
142                        $PageTitleEnabled = "Disabled='Disabled'"; // Disable text field, no use in case of files
143                        $PageAuthorName = "Disabled, no use...";
144                        $PageTitle = "Disabled, no use...";
145                        $contents=file_get_contents("../htmlfiles/$ffilename");
146          }
147         
148               
149               
150   }
151        else if(!array_key_exists('resource_type',$_GET))// first time page visited
152        {
153                //echo "in last if";
154                $resourcetypecombo="<select id=\"resource_type\" name=\"resource_type\" onChange=\"updatePage1()\">
155          <option>Select An Option</option>
156          <option value=\"1\">dyamic contents[pages]</option>
157          <option value=\"2\">Files on server</option>
158        </select>";
159        }
160   
161?>
162<html>
163<head>
164<link rel="stylesheet" href="main.css" type="text/css" />
165<script language="javascript">
166function updatePage1()
167{
168        control = document.getElementById('resource_type');
169        rt = control.value;
170        document.form1.action = 'EditPage.php?resource_type='+rt;
171        document.form1.submit();
172}
173function updatePage2()
174{
175        control_one = document.getElementById('resource_type');
176        control_two = document.getElementById('resource_name');
177        rt = control_one.value;
178        rn = control_two.value;
179        document.form1.action = 'EditPage.php?resource_type='+rt+'&resource_name='+rn;
180        document.form1.submit();
181}
182</script>
183</head>
184<?php
185include("FCKeditor/fckeditor.php") ;
186?>
187<body >
188<form  name="form1"action="EditPageAction.php" method="post">
189<table align="center" class="maintable">
190  <tr><td colspan="2"><?php include "header.php"; ?></td></tr>
191  <tr>
192    <td id='menuPanel' width="14%" ><?php include "includes/menu.inc.php"; ?>      &nbsp;</td>
193    <td width="86%"><div id='mainpanel'><table width="99%" border="0">
194      <tr>
195          <td><p>Select Type </td><td width="34%"><label>
196        <?=$resourcetypecombo?>
197        </label></td>
198        <td width="15%">Select A Name :          </td>
199        <td width="29%"><div id="uniqness">
200          <select id="resource_name"  name="resource_name" onChange="updatePage2()">
201                  <?=$resoucenamecombo?>
202          </select>
203          </div></td>
204      </tr>
205      <tr>
206        <td>Page Author Name: </td>
207        <td colspan="3"><label>
208          <input type="text" id="author" name="author" value="<?=$PageAuthorName?>" <?=$PageAuthorEnabled?> >
209        [optional]</label></td>
210      </tr>
211      <tr>
212        <td width="22%">Enter Page Title : </td>
213        <td colspan="3"><label>
214          <input type="text" id="title" name="title" value="<?=$PageTitle?>" <?=$PageTitleEnabled?>>
215        </label></td>
216      </tr>
217      <tr>
218        <td colspan="4"><?php
219                $oFCKeditor = new FCKeditor('pageBody') ;
220                $oFCKeditor->BasePath = 'FCKeditor/';
221                $oFCKeditor->Value = $contents;
222                $oFCKeditor->Height = '400' ;
223                $oFCKeditor->Create() ;
224        ?></td>
225        </tr>
226      <tr>
227        <td colspan="4"><label>
228          <div align="center">
229            <input type="submit" name="Submit" value="Submit">
230            </div>
231        </label></td>
232      </tr>
233    </table></div></td>
234  </tr><tr><td colspan="2"><?php include "footer.php"; ?></td></tr>
235</table>
236
237</form>
238
239</body>
240</html>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy