/Ecodrama/editor/rotator.php
PHP | 185 lines | 131 code | 35 blank | 19 comment | 19 complexity | fdef4cd4aef5a249401aa7bc8b5ab8f8 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-3.0
- <?php
- /*
- <!--
- * File Name:
- * rotator.php
- * Save pictures in ../rotator folder
- * the picture list is saved in datas/rotate as an array
- * File Authors:
- * Team: caspages
- * Aujin Jang (ajang@uoregon.edu)
- -->
- */
- include 'editor_conf.php';
- chdir($sourcepath);
- include 'check_cookie.php';
- chdir($curpath);
- echo file_get_contents('editor_t.html');
- if ($error != 1 && is_admin){
- require_once('array_storage.php');
- $array_storage = new array_storage();
- $compress = 0;
- /* Get rotate picture list */
- $myFile = "datas/rotate";
- $fh = fopen($myFile, 'r');
- if(filesize($myFile) != 0){
- $array = fread($fh, filesize($myFile));
- }
- $image_list = $array_storage->Txt2Array($array,$compress);
- fclose($fh);
- $dirpath = '../../rotator/';
- $dh = opendir($dirpath);
- /* upload file fuction*/
- if($HTTP_POST_VARS['upload']){
- $pname = str_replace('-' , '_' , basename( $_FILES['uploadedfile']['name']));
- $pname = str_replace('_' , '' , $pname);
- $target_path = $dirpath . $pname;
- if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
- chmod( $target_path , 0644);
- $pname = str_replace('.' , '_', $pname);
- $s_descrp = $_POST['description'];
- $s_descrp = str_replace("'" , "[small]" , $s_descrp);
- $s_descrp = str_replace('"' , '[big]' , $s_descrp);
- $s_descrp = str_replace('\\' , '' , $s_descrp);
- $image_list[$pname] = 'Show|' . $s_descrp;
- $fh = fopen($myFile, 'w+');
- $array_text = $array_storage->Array2Txt($image_list,$compress);
- fwrite($fh, $array_text);
- fclose($fh);
- } else{
- echo "There was an error uploading the file, please try again!";
- }
- }
- /* print list on the page */
- echo '
- <p> Modify existing files </p>
- <form name="form1" method="post" action="rotator.php">';
- echo '
- <table width="700" border="0">
- <tr>
- <td width="40">Picture</td>
- <td width="40">Delete</td>
- <td width="180">Visiblity</td>
- <td width="440">Description</td>
- </tr>';
- /* update files that user has selected */
- while (false !== ($file = readdir($dh))) {
- //Don't list subdirectories
- if (!is_dir("$dirpath/$file")) {
- if (strcmp($file, 'content.html') != 0){
- if (strcmp($file, 'index.php') != 0){
-
- //Truncate the file extension and capitalize the first letter
- $pname = str_replace('.' , '_' , $file);
- $delete = $_POST[$pname];
- $select = $_POST['select_' . $pname];
-
- $s_select = strtok($image_list[$pname], '|');
- $s_descrp = strtok('|');
-
- if ($HTTP_POST_VARS['update'] and $delete == 'checked'){
- //delete file
- unlink($dirpath . '/' . $file);
- unset($image_list[$pname]);
- $fh = fopen($myFile, 'w+');
- $array_text = $array_storage->Array2Txt($image_list,$compress);
- fwrite($fh, $array_text);
- fclose($fh);
- }
- else{
- if($HTTP_POST_VARS['update']){
-
- // update the list
-
- $s_select = $select;
- $s_descrp = $_POST['text_' . $pname];
- $s_descrp = str_replace("\\'" , "[small]" , $s_descrp);
- $s_descrp = str_replace('\\"' , '[big]' , $s_descrp);
- $s_descrp = str_replace("\\" , "" , $s_descrp);
- $s_descrp = str_replace("'" , "[small]" , $s_descrp);
- $s_descrp = str_replace('"' , '[big]' , $s_descrp);
- $s_descrp = str_replace("\\" , "" , $s_descrp);
- $image_list[$pname] = $select . '|' . $s_descrp;
- $fh = fopen($myFile, 'w+');
- $array_text = $array_storage->Array2Txt($image_list,$compress);
- fwrite($fh, $array_text);
- fclose($fh);
- }
- $s_descrp = str_replace("[small]" , "'" , $s_descrp);
- $s_descrp = str_replace("\\" , "" , $s_descrp);
- $s_descrp = str_replace('[big]' , '"' , $s_descrp);
- echo '<tr><td><img src="' . $dirpath . '/' . $file . '" width = "40" height="40"></td>';
- echo '<td><input type="checkbox" name="' . $pname . '" value="checked"></td>';
- if($s_select == 'Show'){ $t = '<option selected>Show</option><option>Hide</option>';}
- else { $t = '<option>Show</option><option selected>Hide</option>';}
- echo '<td><select name="select_' . $pname . '">' . $t . '</select></td>';
- echo '<td><textarea rows="2" name="text_' . $pname . '">' . $s_descrp . '</textarea></td></tr>';
- }
- }}
- }
- }
- echo '
- </tr>
- <tr>
- <td colspan="5"> <div align="right">
- <input name="update" type="submit" value="submit changes">
- <input name="reset" type="reset" value="discard changes">
- </div>
- </td>
- </tr>
- </table></form>
- <br>
- <p>Or upload a new File
- <form enctype="multipart/form-data" method="POST" action="rotator.php">
- <table width="700" border="0">
- <tr>
- <td width="260">Description:</td>
- <td width="440"><textarea rows="2" name="description"></textarea></td>
- </tr>
- <tr>
- <td width="260">Choose a file to upload:</td>
- <td align="right"><input name="uploadedfile" type="file" />
- <input type="submit" name="upload" value="Upload File" /></td>
- </tr>
- </table>
- </form>
- ';
- closedir($dh);
- }
- ?>