PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/ASTRA_Demo_Server/udrive/www/astra/interact/includes/editor/popups/insert_media.php

https://github.com/shafiqissani/ASTRA-College-Website
PHP | 395 lines | 389 code | 6 blank | 0 comment | 2 complexity | f22a71777adb7ddca9a4797aff6e187e MD5 | raw file
  1. <?php
  2. require_once('../../../local/config.inc.php');
  3. if(!$_SESSION['current_user_key']) {
  4. echo "<div align=\"center\">You don't appear to be logged in<br />";
  5. echo "<a href=\"javascript:close()\">Close this Window</a></div>";
  6. exit;
  7. }
  8. $sql = "SELECT file_path from {$CONFIG['DB_PREFIX']}users where user_key='{$_SESSION['current_user_key']}'";
  9. $rs = $CONN->Execute($sql);
  10. $action = $_GET['action'];
  11. if ($_SERVER['REQUEST_METHOD']=='GET') {
  12. $file = $_GET['file'];
  13. } else {
  14. $file_name = $_FILES['file']['name'];
  15. $file = $_FILES['file']['tmp_name'];
  16. }
  17. while (!$rs->EOF) {
  18. $filepath = $CONFIG['USERS_PATH']."/".$rs->fields[0];
  19. $url_path = $CONFIG['USERS_VIEW_PATH']."/".$rs->fields[0];
  20. $rs->MoveNext();
  21. }
  22. $rs->Close();
  23. if ($action=="del" && is_file($CONFIG['BASE_PATH'].$file)) {
  24. if (unlink($CONFIG['BASE_PATH'].$file)) {
  25. $message = "The image has been deleted";
  26. } else {
  27. $message = "The image could not be deleted";
  28. }
  29. } else if ($action=="upload" && $file!="none") {
  30. //get file extension to see if it is an image
  31. $allowed_image_types = array('mp3', 'swf');
  32. $ext = strtolower(ereg_replace("^.+\\.([^.]+)$", "\\1", $file_name));
  33. if (!in_array($ext,$allowed_image_types)) {
  34. $message = "You can only upload gif, jpg and png files";
  35. //check that the file is not bigger than 100KB
  36. } else if ($file_size>100000000000) {
  37. $message = "That file is too large to upload";
  38. } else {
  39. //if image is wider than 300 pixels resize it
  40. $image_array = GetImageSize($file); // Get image dimensions
  41. $image_width = $image_array[0]; // Image width
  42. $image_height = $image_array[1]; // Image height
  43. if ($image_width > 400) {
  44. $newwidth=400;
  45. $factor=400/$image_width;
  46. $newheight=$image_height*$factor;
  47. exec("mogrify -geometry $newwidth x $newheight $file");
  48. }
  49. $image_name = ereg_replace("[^a-z0-9A-Z._]","",$file_name);
  50. if (copy($file,$filepath."/".$image_name)) {
  51. $message = "The image was uploaded";
  52. } else {
  53. $message = "The image could not be uploaded for some reason";
  54. }
  55. }
  56. }
  57. ?>
  58. <html>
  59. <head>
  60. <title>Insert Audio/Video</title>
  61. <style>
  62. BODY
  63. {
  64. FONT-FAMILY: Verdana;FONT-SIZE: xx-small;
  65. }
  66. TABLE
  67. {
  68. FONT-SIZE: xx-small;
  69. }
  70. INPUT
  71. {
  72. font:8pt verdana,arial,sans-serif;
  73. }
  74. select
  75. {
  76. height: 22px;
  77. top:2;
  78. font:8pt verdana,arial,sans-serif
  79. }
  80. .bar
  81. {
  82. BORDER-TOP: #99ccff 1px solid; BACKGROUND: #003399; WIDTH: 100%; BORDER-BOTTOM: #000000 1px solid; HEIGHT: 20px
  83. }
  84. </style>
  85. <script type="text/javascript" src="popup.js"></script>
  86. <script type="text/javascript">
  87. window.resizeTo(450, 100);
  88. self.focus()
  89. function Init() {
  90. __dlg_init();
  91. var param = window.dialogArguments;
  92. if (param) {
  93. document.getElementById("f_url").value = param["f_url"];
  94. document.getElementById("f_alt").value = param["f_alt"];
  95. document.getElementById("f_border").value = param["f_border"];
  96. document.getElementById("f_align").value = param["f_align"];
  97. document.getElementById("f_vert").value = param["f_vert"];
  98. document.getElementById("f_horiz").value = param["f_horiz"];
  99. document.getElementById("f_width").value = param["f_width"];
  100. document.getElementById("f_height").value = param["f_height"];
  101. //window.ipreview.location.replace(param.f_url);
  102. showExistingImage(param["f_url"]);
  103. }
  104. document.getElementById("f_url").focus;
  105. };
  106. function onOK() {
  107. document.getElementById("f_url").value = '/includes/editor/images/ed_sound.gif';
  108. var required = {
  109. };
  110. for (var i in required) {
  111. var el = document.getElementById(i);
  112. if (!el.value) {
  113. alert(required[i]);
  114. el.focus();
  115. return false;
  116. }
  117. }
  118. // pass data back to the calling window
  119. var fields = ["f_url", "f_alt", "f_align", "f_border",
  120. "f_horiz", "f_vert", "f_width", "f_height"];
  121. var param = new Object();
  122. for (var i in fields) {
  123. var id = fields[i];
  124. var el = document.getElementById(id);
  125. param[id] = el.value;
  126. }
  127. __dlg_close(param);
  128. return false;
  129. };
  130. function onCancel() {
  131. __dlg_close(null);
  132. return false;
  133. };
  134. // Fired when the width or height input texts change
  135. function sizeChanged(axe)
  136. {
  137. // Verifies if the aspect ration has to be mantained
  138. txtWidth = document.getElementById("f_width");
  139. txtHeight = document.getElementById("f_height");
  140. if (imageOriginal && document.getElementById("chkLockRatio").checked)
  141. {
  142. if ((axe) == "Width")
  143. {
  144. if (txtWidth.value != "")
  145. {
  146. if (! isNaN(txtWidth.value))
  147. txtHeight.value = Math.round( imageOriginal.height * ( txtWidth.value / imageOriginal.width ) ) ;
  148. }
  149. else
  150. txtHeight.value = "" ;
  151. }
  152. else
  153. if (txtHeight.value != "")
  154. {
  155. if (! isNaN(txtHeight.value))
  156. txtWidth.value = Math.round( imageOriginal.width * ( txtHeight.value / imageOriginal.height ) ) ;
  157. }
  158. else
  159. txtWidth.value = "" ;
  160. }
  161. //updatePreview() ;
  162. }
  163. // Fired when the Reset Size button is clicked
  164. function resetSize()
  165. {
  166. if (! imageOriginal) return ;
  167. txtWidth.value = imageOriginal.width ;
  168. txtHeight.value = imageOriginal.height ;
  169. //updatePreview() ;
  170. }
  171. </script>
  172. <style type="text/css">
  173. html, body {
  174. background: ButtonFace;
  175. color: ButtonText;
  176. font: 11px Tahoma,Verdana,sans-serif;
  177. margin: 0px;
  178. padding: 0px;
  179. }
  180. body { padding: 5px; }
  181. table {
  182. font: 11px Tahoma,Verdana,sans-serif;
  183. }
  184. form p {
  185. margin-top: 5px;
  186. margin-bottom: 5px;
  187. }
  188. .fl { width: 9em; float: left; padding: 2px 5px; text-align: right; }
  189. .fr { width: 6em; float: left; padding: 2px 5px; text-align: right; }
  190. fieldset { padding: 0px 10px 5px 5px; }
  191. select, input, button { font: 11px Tahoma,Verdana,sans-serif; }
  192. button { width: 70px; }
  193. .space { padding: 2px; }
  194. .title { background: #ddf; color: #000; font-weight: bold; font-size: 120%; padding: 3px 10px; margin-bottom: 10px;
  195. border-bottom: 1px solid black; letter-spacing: 2px;
  196. }
  197. form { padding: 0px; margin: 0px; }
  198. </style>
  199. </head>
  200. <body onLoad="Init()">
  201. <div class="title">Insert Audio</div>
  202. <?php
  203. echo "<div align=\"center\">$message</div>";
  204. ?>
  205. <table border="0" cellpadding="0" cellspacing="0">
  206. <tr>
  207. <td valign=top>
  208. <!-- Content -->
  209. <table border=0 cellpadding=3 cellspacing=3 align=center>
  210. <tr>
  211. <td valign=top>
  212. <table border=0 cellpadding=0 cellspacing=0 width=220>
  213. <tr>
  214. <td>
  215. <div class="title" style="padding-left: 5px;">
  216. <font size="2" ><b>File name</b></font>
  217. </div></td>
  218. </tr>
  219. </table>
  220. <div style="overflow:auto;height:120;width:220;BORDER-LEFT: #316AC5 1px solid;BORDER-RIGHT: LightSteelblue 1px solid;BORDER-BOTTOM: LightSteelblue 1px solid;">
  221. <table border=0 cellpadding=3 cellspacing=0 width=220>
  222. <?php
  223. $dir = dir($filepath);
  224. while($entry=$dir->read()) {
  225. if($entry == "." || $entry == "..") {
  226. continue;
  227. }
  228. $fp = @fopen("$filepath/$entry","r");
  229. if(!$fp) {
  230. print "Bad entry: $entry<br />";
  231. continue;
  232. }
  233. $name = fgets($fp,4096);
  234. fclose($fp);
  235. if (is_file("$filepath/$entry")) {
  236. $ext = strtolower(ereg_replace("^.+\\.([^.]+)$", "\\1", $entry));
  237. if ($ext=='mp3') {
  238. ?>
  239. <tr bgcolor=Gainsboro>
  240. <td valign=top><?php echo $entry?></td>
  241. <td valign=top></td>
  242. <td valign=top></td>
  243. <td valign=top style="cursor:hand;" onClick="selectImage('<?php echo "$url_path/$entry" ?>', '<?php echo "%MP3%$url_path/$entry%MP3%" ?>', '<?php echo "$url_path/$entry" ?>')"><u><font color=blue>select</font></u></td>
  244. <td valign=top style="cursor:hand;" onClick="deleteImage('<?php echo "$url_path/$entry" ?>')"> <u><font color=blue>del</font></u></td>
  245. </tr>
  246. <?php
  247. }
  248. }
  249. }
  250. ?>
  251. </table>
  252. </div>
  253. <FORM METHOD="Post" ENCTYPE="multipart/form-data" ACTION="insert_media.php?action=upload" ID="form1" name="form1">
  254. Upload Audio: <br />
  255. <INPUT type="file" id="file" name="file" size=22 style="font:8pt verdana,arial,sans-serif">
  256. <br />
  257. <input name="sub_dir" ID="sub_dir" type=hidden value="<?php echo $sub_dir?>">
  258. <INPUT TYPE="submit" value="Upload" >
  259. </FORM></td>
  260. <td align=center style="BORDER-TOP: #336699 1px solid;BORDER-LEFT: #336699 1px solid;BORDER-RIGHT: #336699 1px solid;BORDER-BOTTOM: #336699 1px solid;" bgcolor=White>
  261. <iframe name="ipreview" id="ipreview" frameborder="0" style="border : 1px solid gray;" height="130" width="150" src=""></iframe>
  262. </td>
  263. </tr>
  264. <tr>
  265. <td align=center colspan=2>&nbsp;
  266. </td>
  267. </tr>
  268. </table>
  269. <!-- /Content -->
  270. </td>
  271. </tr>
  272. </table>
  273. <script language="JavaScript">
  274. function deleteImage(sURL)
  275. {
  276. if (confirm("Delete this image?") == true)
  277. {
  278. window.navigate("insert_image.php?action=del&file="+sURL);
  279. }
  280. }
  281. function selectImage(surl, filename, filename2)
  282. {
  283. window.ipreview.location.replace('/includes/players/previewaudio.php?mp3_file='+filename2);
  284. imageOriginal = new Image() ;
  285. imageOriginal.src = surl ;
  286. image_1 = new Image();
  287. image_1.src = surl;
  288. document.getElementById("f_url").value = surl;
  289. document.getElementById("f_alt").value = filename;
  290. document.getElementById("f_width").value = '18';
  291. document.getElementById("f_height").value = '18';
  292. }
  293. function showExistingImage(surl)
  294. {
  295. imageOriginal = new Image() ;
  296. imageOriginal.src = surl ;
  297. window.ipreview.location.replace(surl);
  298. document.getElementById("f_url").value = surl;
  299. }
  300. function test() {
  301. alert('hello jo');
  302. }
  303. </script>
  304. <!--- new stuff --->
  305. <form action="" method="get">
  306. <input name="url" type="hidden" id="f_url" title="Enter the image URL here" size="30" />
  307. <input name="alt" type="hidden" id="f_alt" title="For browsers that don't support images" size="30" />
  308. <input type="hidden" name="align" id="f_align" title="Positioning of this image" />
  309. <input type="hidden" name="border" id="f_border" title="Leave empty for no border" />
  310. <input type="hidden" name="horiz" id="f_horiz" title="Horizontal padding" />
  311. <input type="hidden" name="vert" id="f_vert" title="Vertical padding" />
  312. <input type="hidden" id="f_width" >
  313. <input type="hidden" id="f_height" >
  314. <input type="hidden" class="CheckBox" checked id="chkLockRatio" >
  315. <div align="center">
  316. <input type="submit" name="ok" value="OK" onClick="return onOK();">
  317. <input type="submit" name="cancel" value="Cancel" onClick="return onCancel();">
  318. </div>
  319. </form>
  320. </body>
  321. </html>