PageRenderTime 56ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Ecodrama/editor/rotator.php

http://oregon-caspages.googlecode.com/
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
  1. <?php
  2. /*
  3. <!--
  4. * File Name:
  5. * rotator.php
  6. * Save pictures in ../rotator folder
  7. * the picture list is saved in datas/rotate as an array
  8. * File Authors:
  9. * Team: caspages
  10. * Aujin Jang (ajang@uoregon.edu)
  11. -->
  12. */
  13. include 'editor_conf.php';
  14. chdir($sourcepath);
  15. include 'check_cookie.php';
  16. chdir($curpath);
  17. echo file_get_contents('editor_t.html');
  18. if ($error != 1 && is_admin){
  19. require_once('array_storage.php');
  20. $array_storage = new array_storage();
  21. $compress = 0;
  22. /* Get rotate picture list */
  23. $myFile = "datas/rotate";
  24. $fh = fopen($myFile, 'r');
  25. if(filesize($myFile) != 0){
  26. $array = fread($fh, filesize($myFile));
  27. }
  28. $image_list = $array_storage->Txt2Array($array,$compress);
  29. fclose($fh);
  30. $dirpath = '../../rotator/';
  31. $dh = opendir($dirpath);
  32. /* upload file fuction*/
  33. if($HTTP_POST_VARS['upload']){
  34. $pname = str_replace('-' , '_' , basename( $_FILES['uploadedfile']['name']));
  35. $pname = str_replace('_' , '' , $pname);
  36. $target_path = $dirpath . $pname;
  37. if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
  38. chmod( $target_path , 0644);
  39. $pname = str_replace('.' , '_', $pname);
  40. $s_descrp = $_POST['description'];
  41. $s_descrp = str_replace("'" , "[small]" , $s_descrp);
  42. $s_descrp = str_replace('"' , '[big]' , $s_descrp);
  43. $s_descrp = str_replace('\\' , '' , $s_descrp);
  44. $image_list[$pname] = 'Show|' . $s_descrp;
  45. $fh = fopen($myFile, 'w+');
  46. $array_text = $array_storage->Array2Txt($image_list,$compress);
  47. fwrite($fh, $array_text);
  48. fclose($fh);
  49. } else{
  50. echo "There was an error uploading the file, please try again!";
  51. }
  52. }
  53. /* print list on the page */
  54. echo '
  55. <p> Modify existing files </p>
  56. <form name="form1" method="post" action="rotator.php">';
  57. echo '
  58. <table width="700" border="0">
  59. <tr>
  60. <td width="40">Picture</td>
  61. <td width="40">Delete</td>
  62. <td width="180">Visiblity</td>
  63. <td width="440">Description</td>
  64. </tr>';
  65. /* update files that user has selected */
  66. while (false !== ($file = readdir($dh))) {
  67. //Don't list subdirectories
  68. if (!is_dir("$dirpath/$file")) {
  69. if (strcmp($file, 'content.html') != 0){
  70. if (strcmp($file, 'index.php') != 0){
  71. //Truncate the file extension and capitalize the first letter
  72. $pname = str_replace('.' , '_' , $file);
  73. $delete = $_POST[$pname];
  74. $select = $_POST['select_' . $pname];
  75. $s_select = strtok($image_list[$pname], '|');
  76. $s_descrp = strtok('|');
  77. if ($HTTP_POST_VARS['update'] and $delete == 'checked'){
  78. //delete file
  79. unlink($dirpath . '/' . $file);
  80. unset($image_list[$pname]);
  81. $fh = fopen($myFile, 'w+');
  82. $array_text = $array_storage->Array2Txt($image_list,$compress);
  83. fwrite($fh, $array_text);
  84. fclose($fh);
  85. }
  86. else{
  87. if($HTTP_POST_VARS['update']){
  88. // update the list
  89. $s_select = $select;
  90. $s_descrp = $_POST['text_' . $pname];
  91. $s_descrp = str_replace("\\'" , "[small]" , $s_descrp);
  92. $s_descrp = str_replace('\\"' , '[big]' , $s_descrp);
  93. $s_descrp = str_replace("\\" , "" , $s_descrp);
  94. $s_descrp = str_replace("'" , "[small]" , $s_descrp);
  95. $s_descrp = str_replace('"' , '[big]' , $s_descrp);
  96. $s_descrp = str_replace("\\" , "" , $s_descrp);
  97. $image_list[$pname] = $select . '|' . $s_descrp;
  98. $fh = fopen($myFile, 'w+');
  99. $array_text = $array_storage->Array2Txt($image_list,$compress);
  100. fwrite($fh, $array_text);
  101. fclose($fh);
  102. }
  103. $s_descrp = str_replace("[small]" , "'" , $s_descrp);
  104. $s_descrp = str_replace("\\" , "" , $s_descrp);
  105. $s_descrp = str_replace('[big]' , '"' , $s_descrp);
  106. echo '<tr><td><img src="' . $dirpath . '/' . $file . '" width = "40" height="40"></td>';
  107. echo '<td><input type="checkbox" name="' . $pname . '" value="checked"></td>';
  108. if($s_select == 'Show'){ $t = '<option selected>Show</option><option>Hide</option>';}
  109. else { $t = '<option>Show</option><option selected>Hide</option>';}
  110. echo '<td><select name="select_' . $pname . '">' . $t . '</select></td>';
  111. echo '<td><textarea rows="2" name="text_' . $pname . '">' . $s_descrp . '</textarea></td></tr>';
  112. }
  113. }}
  114. }
  115. }
  116. echo '
  117. </tr>
  118. <tr>
  119. <td colspan="5"> <div align="right">
  120. <input name="update" type="submit" value="submit changes">
  121. <input name="reset" type="reset" value="discard changes">
  122. </div>
  123. </td>
  124. </tr>
  125. </table></form>
  126. <br>
  127. <p>Or upload a new File
  128. <form enctype="multipart/form-data" method="POST" action="rotator.php">
  129. <table width="700" border="0">
  130. <tr>
  131. <td width="260">Description:</td>
  132. <td width="440"><textarea rows="2" name="description"></textarea></td>
  133. </tr>
  134. <tr>
  135. <td width="260">Choose a file to upload:</td>
  136. <td align="right"><input name="uploadedfile" type="file" />
  137. <input type="submit" name="upload" value="Upload File" /></td>
  138. </tr>
  139. </table>
  140. </form>
  141. ';
  142. closedir($dh);
  143. }
  144. ?>