PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/filebrowser.php

https://github.com/adamfranco/segue-1.x
PHP | 1104 lines | 830 code | 143 blank | 131 comment | 172 complexity | b1e6778243e57486c4781d8ea0d7025b MD5 | raw file
  1. <? /* $Id$ */
  2. $content = '';
  3. $metadata = array ( "is_published" => "Is this from a published source?",
  4. "title_whole" => "Book/Joural Title",
  5. "title_part" => "Article/Chapter Title",
  6. "author" => "Author",
  7. "pagerange" => "Pages",
  8. "publisher" => "Publisher",
  9. "pubyear" => "Pub. Year",
  10. "isbn" => "ISBN/ISSN"
  11. );
  12. ob_start();
  13. session_start();
  14. // include all necessary files
  15. include("includes.inc.php");
  16. include("sniffer.inc.php");
  17. include("objects/objects.inc.php");
  18. //$siteObj = new site ($site);
  19. //if ($_SESSION['ltype'] != 'admin') exit;
  20. db_connect($dbhost, $dbuser, $dbpass, $dbdb);
  21. if ($_REQUEST['delete']) {
  22. deleteuserfile($_REQUEST['filetodelete']);
  23. printerr2();
  24. }
  25. $sitelist = array();
  26. $owner = $_REQUEST[owner];
  27. $editor = $_REQUEST[editor];
  28. $site = $_SESSION[settings][site];
  29. $order = $_REQUEST[order];
  30. $lowerlimit = $_REQUEST[lowerlimit];
  31. $user = $_REQUEST[user];
  32. $name = $_REQUEST[name];
  33. $upload = $_REQUEST[upload];
  34. /* if (isset($_SESSION[settings][sitename])) { */
  35. /* $site = $_SESSION[settings][sitename]; */
  36. /* } else if (isset($_SESSION[settings][site])) { */
  37. /* $site = $_SESSION[settings][site]; */
  38. /* } */
  39. //printpre($_SESSION[settings]);
  40. //printpre($_REQUEST);
  41. if ($_REQUEST[site]) {
  42. $site = $_REQUEST[site];
  43. } else if ($_SESSION[settings][sitename]) {
  44. $site = $_SESSION[settings][sitename];
  45. } else {
  46. $site = $_SESSION[settings][site];
  47. }
  48. //print $owner;
  49. //printpre($settings[site]);
  50. $w = array();
  51. if ($_SESSION['ltype'] == 'admin') {
  52. if ($_REQUEST[site])
  53. $w[]="slot_name='".addslashes($site)."'";
  54. else if ($all) $w[]="slot_name like '%'";
  55. else $w[]="slot_name='".addslashes($settings[site])."'";
  56. } else $w[]="slot_name='".(($site)?"".addslashes($site)."":"".addslashes($settings[site])."")."'";
  57. if (count($w)) $where = " WHERE ".implode(" and ",$w);
  58. $query = "
  59. SELECT
  60. media_id,
  61. media_tag,
  62. media_type,
  63. media_size,
  64. slot_name,
  65. slot_uploadlimit
  66. FROM
  67. media
  68. INNER JOIN
  69. slot
  70. ON media.FK_site = slot.FK_site
  71. $where AND media_location = 'local'
  72. ";
  73. $r = db_query($query);
  74. //printpre($query);
  75. $totalsize = 0;
  76. while ($a = db_fetch_assoc($r)) {
  77. $totalsize = $totalsize + $a[media_size];
  78. }
  79. /******************************************************************************
  80. * if source = discuss then show only files uploaded by currently authed user
  81. ******************************************************************************/
  82. if ($_REQUEST[source]) {
  83. $user_id = $_SESSION[aid];
  84. $username = $_SESSION[auser];
  85. if ($username == $owner) {
  86. $userfilter = "";
  87. } else if (!$user_id) {
  88. $userfilter = "AND user_id = 'anonymous'";
  89. } else {
  90. $userfilter = "AND user_id = '".addslashes($user_id)."'";
  91. }
  92. //print "useruname=".$username;
  93. } else {
  94. $userfilter = "";
  95. }
  96. if ($_REQUEST[comingFrom]) {
  97. //print $_REQUEST[comingFrom];
  98. }
  99. /******************************************************************************
  100. * Uploads files: check if media limit is reached..
  101. ******************************************************************************/
  102. if ($_REQUEST['upload']) {
  103. $query = "
  104. SELECT
  105. media_tag,
  106. media_id,
  107. media_size,
  108. media_type,
  109. slot_name,
  110. user_id,
  111. user_fname,
  112. user_uname,
  113. slot_uploadlimit
  114. FROM
  115. media
  116. INNER JOIN
  117. slot
  118. ON media.FK_site = slot.FK_site
  119. INNER JOIN
  120. user
  121. ON media.FK_createdby = user_id
  122. WHERE
  123. slot_name='".addslashes((($_REQUEST[site])?$_REQUEST[site]:$settings[site]))."'
  124. AND
  125. media_location = 'local'
  126. $userfilter
  127. ";
  128. // print "$query <br />";
  129. $r = db_query($query);
  130. $filename = ereg_replace("[\x27\x22]",'',trim($_FILES[file][name]));
  131. // printpre ($_REQUEST);
  132. // exit;
  133. if ($_FILES['file']['tmp_name'] == 'none') {
  134. $upload_results = "<li>No file selected";
  135. } else {
  136. /*********************************************************
  137. * Check for file validity before uploading.
  138. * There are two modes that this can run in:
  139. *
  140. * - Whitelist - Only file extensions specified are allowed.
  141. * All others are blocked.
  142. *
  143. * - Blacklist - Only file extensions specified are blocked.
  144. * All others are allowed.
  145. *
  146. *********************************************************/
  147. /*********************************************************
  148. * Blacklist mode
  149. *********************************************************/
  150. if ($cfg['useBlacklistMode']) {
  151. if (is_array($cfg['additionalBlacklist']))
  152. $expressionsToCheck = array_merge($cfg['defaultBlacklist'],
  153. $cfg['additionalBlacklist']);
  154. else
  155. $expressionsToCheck = $cfg['defaultBlacklist'];
  156. $isBlocked = nameMatches($filename, $expressionsToCheck);
  157. }
  158. /*********************************************************
  159. * Whitelist (default) mode.
  160. *********************************************************/
  161. else {
  162. if (is_array($cfg['additionalWhitelist']))
  163. $expressionsToCheck = array_merge($cfg['defaultWhitelist'],
  164. $cfg['additionalWhitelist']);
  165. else
  166. $expressionsToCheck = $cfg['defaultWhitelist'];
  167. $isBlocked = !(nameMatches($filename, $expressionsToCheck));
  168. }
  169. if ($isBlocked) {
  170. ereg("\.([^\.]+)$", $filename, $filenameParts);
  171. $extension = $filenameParts[1];
  172. $upload_results = "
  173. <li>For security reasons, file-upload types must be approved by the system administrator.
  174. <br />".strtoupper($extension)." files have not [yet] been approved.
  175. <br />Please contact the system administrator if you feel that this is in error.
  176. <br /><b>File, $filename, was NOT uploaded.</b>";
  177. } else {
  178. // Check to see if the name is used.
  179. $nameUsed = 0;
  180. while ($a = db_fetch_assoc($r)) {
  181. if ($a[media_tag] == $filename) {
  182. $nameUsed = 1;
  183. $usedId = $a[media_id];
  184. }
  185. }
  186. $q = "
  187. SELECT
  188. slot_uploadlimit
  189. FROM
  190. slot
  191. WHERE
  192. slot_name='".(($_REQUEST[site])?"".addslashes($_REQUEST[site])."":"".addslashes($settings[site])."")."'";
  193. $res = db_query($q);
  194. $b = db_fetch_assoc($res);
  195. if ($b[slot_uploadlimit]) {
  196. $dirlimit = $b[slot_uploadlimit];
  197. } else {
  198. $dirlimit = $userdirlimit;
  199. }
  200. if (($_FILES[file][size] + $totalsize) > $dirlimit) {
  201. $upload_results = "<li>There is not enough room in your directory for $filename.";
  202. } else if ($_REQUEST[overwrite] && $nameUsed) {
  203. $newID = copyuserfile($_FILES['file'],(($_REQUEST[site])?"$_REQUEST[site]":"$settings[site]"),1,$usedId,0);
  204. if ($newID && $newID != 'ERROR') {
  205. $upload_results = "<li>$filename successfully uploaded to ID $newID. <li>The origional file was overwritten. <li>If the your new version does not appear, please reload your page. If the new version still doesn't appear, clear your browser cache.";
  206. } else {
  207. $upload_results = "<li>An error occurred when trying to upload ".$filename.". <li>Please see above for any additional messages.";
  208. }
  209. } else if ($nameUsed) {
  210. $upload_results = "<li>Filename, $filename, is already in use. <li>Please change the filename before uploading or check \"overwrite\" to OVERWRITE";
  211. } else {
  212. $newID = copyuserfile($_FILES['file'],(($_REQUEST[site])?"$_REQUEST[site]":"$settings[site]"),0,0);
  213. printpre($newID);
  214. if ($newID && $newID != 'ERROR') {
  215. $upload_results = "<li>$filename successfully uploaded to ID $newID";
  216. } else {
  217. $upload_results = "<li>An error occurred when trying to upload ".$filename.". <li>Please see above for any additional messages.";
  218. }
  219. }
  220. }
  221. }
  222. }
  223. // If we've uploaded a file, then add any specified metadata
  224. if (($upload && $newID) || $_REQUEST['update_id']) {
  225. if ($_REQUEST['update_id']) {
  226. $newID = $_REQUEST['update_id'];
  227. // Clear out existing metadata
  228. $query = "UPDATE media SET ";
  229. $query .= implode("=NULL, ", array_keys($metadata));
  230. $query .= "=NULL WHERE media_id='".addslashes($newID)."'";
  231. // printpre($query);
  232. db_query($query);
  233. }
  234. // Add new metada
  235. $arguments = array();
  236. if ($_REQUEST['is_published'] == '1')
  237. $arguments[] = "is_published=1";
  238. else
  239. $arguments[] = "is_published=0";
  240. if ($_REQUEST['title_whole'])
  241. $arguments[] = "title_whole='".addslashes($_REQUEST['title_whole'])."'";
  242. if ($_REQUEST['title_part'])
  243. $arguments[] = "title_part='".addslashes($_REQUEST['title_part'])."'";
  244. if ($_REQUEST['author'])
  245. $arguments[] = "author='".addslashes($_REQUEST['author'])."'";
  246. if ($_REQUEST['pagerange'])
  247. $arguments[] = "pagerange='".addslashes($_REQUEST['pagerange'])."'";
  248. if ($_REQUEST['publisher'])
  249. $arguments[] = "publisher='".addslashes($_REQUEST['publisher'])."'";
  250. if (preg_match('/^[0-9]{4}$/', $_REQUEST['pubyear']))
  251. $arguments[] = "pubyear='".addslashes($_REQUEST['pubyear'])."'";
  252. if ($_REQUEST['isbn'])
  253. $arguments[] = "isbn='".addslashes($_REQUEST['isbn'])."'";
  254. // Set the values if any are in the request
  255. if (count($arguments)) {
  256. $query = "UPDATE media SET ";
  257. $query .= implode(", ", $arguments);
  258. $query .= " WHERE media_id='".addslashes($newID)."'";
  259. // printpre($query);
  260. db_query($query);
  261. }
  262. }
  263. /******************************************************************************
  264. * clears filename search UI??
  265. ******************************************************************************/
  266. if ($_REQUEST[clear]) {
  267. if ($_SESSION['ltype'] == 'admin') {
  268. $user = "";
  269. $site = "";
  270. $name = "";
  271. } else {
  272. $name = "";
  273. $user = $user;
  274. $site = $site;
  275. }
  276. }
  277. /******************************************************************************
  278. * get media file
  279. ******************************************************************************/
  280. $w = array();
  281. if ($_SESSION['ltype'] == 'admin') {
  282. if ($site) $w[]="slot_name='".addslashes($site)."'";
  283. else if ($all) $w[]="slot_name like '%'";
  284. else $w[]="slot_name='".addslashes($settings[site])."'";
  285. } else $w[]="slot_name='".(($site)?"".addslashes($site)."":"".addslashes($settings[site])."")."'";
  286. if (count($w)) $where = " where ".implode(" and ",$w);
  287. $query = "
  288. SELECT
  289. media_tag,
  290. media_id,
  291. media_size,
  292. media_type,
  293. slot_name,
  294. user_fname,
  295. user_uname
  296. FROM
  297. media
  298. INNER JOIN
  299. slot
  300. ON media.FK_site = slot.FK_site
  301. INNER JOIN
  302. user
  303. ON media.FK_createdby = user_id
  304. $where AND media_location = 'local'
  305. ";
  306. $r = db_query($query);
  307. $totalsize = 0;
  308. while ($a = db_fetch_assoc($r)) {
  309. $totalsize = $totalsize + $a[media_size];
  310. }
  311. if (!isset($order)) $order = "media_updated_tstamp desc";
  312. $order = addslashes($order);
  313. $orderby = " ORDER BY $order";
  314. $w = array();
  315. if ($_SESSION['ltype'] == 'admin') {
  316. if ($site) {
  317. $w[]="slot_name='".addslashes($site)."'";
  318. } else if ($all) {
  319. $w[]="slot_name like '%'";
  320. } else {
  321. $w[]="slot_name='".addslashes($settings[site])."'";
  322. }
  323. } else {
  324. $w[]="slot_name='".(($site)?"".addslashes($site)."":"".addslashes($settings[site])."")."'";
  325. }
  326. if ($user) $w[]="user_uname LIKE '%".addslashes($user)."%'";
  327. if ($name) $w[]="media_tag LIKE '%".addslashes($name)."%'";
  328. if (count($w)) $where = " WHERE ".implode(" AND ",$w);
  329. $query = "
  330. SELECT
  331. COUNT(media_id) AS media_count
  332. FROM
  333. media
  334. INNER JOIN
  335. slot
  336. ON media.FK_site = slot.FK_site
  337. INNER JOIN
  338. user
  339. ON media.FK_createdby = user_id
  340. $where AND media_location = 'local'
  341. ";
  342. $r=db_query($query);
  343. $a = db_fetch_assoc($r);
  344. $numrows = $a[media_count];
  345. $numperpage = 20;
  346. if (!isset($lowerlimit)) $lowerlimit = 0;
  347. if ($lowerlimit < 0) $lowerlimit = 0;
  348. $lowerlimit = addslashes($lowerlimit);
  349. $limit = " LIMIT $lowerlimit,$numperpage";
  350. $query = "
  351. SELECT
  352. media_tag,
  353. media_id,
  354. media_size,
  355. date_format(media_updated_tstamp, '%m/%d/%Y %k:%i') AS media_updated_tstamp_text,
  356. media_updated_tstamp,
  357. media_type,
  358. slot_name,
  359. user_fname,
  360. user_uname,
  361. slot_uploadlimit,
  362. is_published,
  363. title_whole,
  364. title_part,
  365. author,
  366. pagerange,
  367. publisher,
  368. pubyear,
  369. isbn
  370. FROM
  371. media
  372. INNER JOIN
  373. slot
  374. ON media.FK_site = slot.FK_site
  375. INNER JOIN
  376. user
  377. ON media.FK_createdby = user_id
  378. $where AND media_location = 'local'
  379. $userfilter
  380. $orderby
  381. $limit
  382. ";
  383. // printpre($query);
  384. $r = db_query($query);
  385. ?>
  386. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  387. <html>
  388. <head>
  389. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  390. <title>File Browser</title>
  391. <style type='text/css'>
  392. a {
  393. color: #a33;
  394. text-decoration: none;
  395. }
  396. a:hover {text-decoration: underline;}
  397. table {
  398. border: 1px solid #555;
  399. }
  400. th, td {
  401. border: 0px;
  402. background-color: #FFFFFF;
  403. text-align: center;
  404. }
  405. .td1 {
  406. background-color: #F0F0F0;
  407. padding-left: 4px;
  408. padding-right: 4px;
  409. }
  410. .td0 {
  411. border-right: 1px solid #F0F0F0;
  412. background-color: #FFFFFF;
  413. padding-left: 4px;
  414. padding-right: 4px;
  415. }
  416. th {
  417. background-color: #ccc;
  418. font-variant: small-caps;
  419. }
  420. .sizebox1 {
  421. text-align: left;
  422. padding-right: 5px;
  423. }
  424. .sizebox2 {
  425. text-align: right;
  426. }
  427. body {
  428. background-color: white;
  429. }
  430. body, table, td, th, input {
  431. font-size: 10px;
  432. font-family: "Verdana", "sans-serif";
  433. }
  434. /* td { font-size: 10px; } */
  435. input,select {
  436. border: 1px solid black;
  437. background-color: white;
  438. font-size: 10px;
  439. }
  440. </style>
  441. <script type="text/javascript">
  442. // <![CDATA[
  443. <?
  444. /******************************************************************************
  445. * Use button action:
  446. * if source is discuss then values pasted to discussion post form
  447. * if source is not discuss, then is one of following:
  448. * site header/footer image or text content block
  449. ******************************************************************************/
  450. //if ($source == 'discuss') {
  451. ?>
  452. function useFileDiscuss(fileID,fileName) {
  453. o = opener.document.postform;
  454. o.libraryfileid.value=fileID;
  455. o.libraryfilename.value=fileName;
  456. window.close();
  457. }
  458. <?
  459. //}
  460. ?>
  461. <?
  462. /******************************************************************************
  463. * if image content block then editor = none and useFile is used
  464. * if text content block then editor = html and getUrl is used
  465. ******************************************************************************/
  466. ?>
  467. function useFile(fileID,fileName) {
  468. o = opener.document.addform;
  469. o.libraryfileid.value=fileID;
  470. o.libraryfilename.value=fileName;
  471. o.submit();
  472. window.close();
  473. }
  474. function getUrl(url,img_url) {
  475. o = opener.document.addform;
  476. o.media_url.value=url;
  477. window.close();
  478. }
  479. function FCKSetUrl(url) {
  480. window.opener.SetUrl(url);
  481. window.close();
  482. }
  483. <?
  484. // this function may not be needed....
  485. ?>
  486. function useFile2(siteName,fileName,fileID) {
  487. opener = window.dialogArguments;
  488. var _editor_url = opener._editor_url;
  489. var objname = location.search.substring(1,location.search.length);
  490. var config = opener.document.all[objname].config;
  491. var editor_obj = opener.document.all["_" +objname+ "_editor"];
  492. var editdoc = editor_obj.contentWindow.document;
  493. var image = '<img src="<?echo $uploadurl ?>/' +siteName+ '/' +fileName+ '" imageID=\"' +fileID+ '\" />\n';
  494. opener.editor_insertHTML(objname, image);
  495. window.close();
  496. }
  497. <?
  498. ?>
  499. function deleteFile(fileID,fileName) {
  500. if (confirm("Are you sure that you want to delete "+fileName+"? If this file is in use anywhere in your site, it will no longer appear.")) {
  501. f = document.deleteform;
  502. f.filetodelete.value=fileID;
  503. f.submit();
  504. }
  505. }
  506. function changeOrder(order) {
  507. f = document.searchform;
  508. f.order.value=order;
  509. f.submit();
  510. }
  511. function changePage(lolim) {
  512. f = document.searchform;
  513. f.lowerlimit.value=lolim;
  514. f.submit();
  515. }
  516. // ]]>
  517. </script>
  518. </head>
  519. <body>
  520. <!--
  521. <table width='100%'>
  522. <tr><td style='text-align: left'>
  523. <? //print $content; ?>
  524. <? //print $numrows . " | " . $query;
  525. ?>
  526. </td></tr>
  527. </table> -->
  528. <table cellspacing='1' width='100%'>
  529. <tr>
  530. <td colspan='<? print (($_SESSION['ltype']=='admin')?"10":"9"); ?>'>
  531. <table width='100%' >
  532. <tr>
  533. <td style='text-align: left; border: 0px solid #FFF; margin-bottom: 10px;' valign='top'>
  534. <div class='desc'>
  535. Select the file or image you would like to upload by clicking the 'Browse...' button below.
  536. <br/><em>(Titles, author, etc are optional, but are encouraged for files originating from published sources.)</em>
  537. </div>
  538. </td>
  539. <td rowspan='3' valign='top' style='text-align: right; border: 0px solid #FFF'>
  540. <?
  541. $dirtotal = convertfilesize($totalsize);
  542. if ($all) {
  543. $res = db_query("SELECT COUNT(site_id) AS num_sites FROM site");
  544. $b = db_fetch_assoc($res);
  545. $dirlimit_B = $b['num_sites']*$userdirlimit;
  546. } else {
  547. // printpre($dirlimit);
  548. if ($site) {
  549. $q = "SELECT slot_uploadlimit FROM slot WHERE slot_name='".addslashes($site)."'";
  550. $res = db_query($q);
  551. $b = db_fetch_assoc($res);
  552. if ($b[slot_uploadlimit])
  553. $dirlimit_B = $b[slot_uploadlimit];
  554. else
  555. $dirlimit_B = $userdirlimit;
  556. }else
  557. $dirlimit_B = $userdirlimit;
  558. }
  559. $dirlimit = convertfilesize($dirlimit_B);
  560. $percentused = round($totalsize/$dirlimit_B,"4")*100;
  561. $percentfree = 100-$percentused;
  562. $space = $dirlimit_B - $totalsize;
  563. $space = convertfilesize($space);
  564. //print "<div style='text-align: right;'>";
  565. print helplink("filelibrary");
  566. print "<br \><br \>";
  567. print "<table cellspacing='0' cellpadding='1' align='right'>";
  568. print "<tr><td class='sizebox1'>Total media allowed: </td><td class='sizebox2'> $dirlimit</td></tr>";
  569. print "<tr><td class='sizebox1'>Total size of your media: </td><td class='sizebox2'> $dirtotal</td></tr>";
  570. print "<tr><td class='sizebox1'>Space available: </td><td class='sizebox2' style='border-top: 1px solid #000'> $space</td></tr>";
  571. print "<tr><td colspan='2'><table width='100%'><tr>";
  572. if ($percentused == 0)
  573. print "<td style='background-color: #00C; height: 5px;' width='100%'> </td>";
  574. else if ($percentused == 100)
  575. print "<td style='background-color: #F00; height: 5px;' width='100%'> </td>";
  576. else
  577. print "<td style='background-color: #F00; height: 5px;' width='$percentused%'> </td><td style='background-color: #00C;' width='$percentfree%'> </td>";
  578. print "</tr></table></td></tr>";
  579. print "</table><br />";
  580. ?>
  581. </td>
  582. </tr>
  583. <tr>
  584. <td style='text-align: left; padding-top: 5px; border: 0px solid #FFF' valign='top'>
  585. <form action="filebrowser.php" name='addform' method="post" enctype="multipart/form-data">
  586. <input type='hidden' name='comingfrom' value='<? echo $comingfrom ?>' />
  587. <input type='hidden' name='site' value='<? echo $site ?>' />
  588. <input type='hidden' name='upload' value='1' />
  589. <input type='hidden' name='order' value='<? echo $order ?>' />
  590. <input type='hidden' name='editor' value='<? echo $editor ?>' />
  591. <input type='hidden' name='source' value='<? echo $source ?>' />
  592. <input type='hidden' name='owner' value='<? echo $owner ?>' />
  593. <input type='file' name='file' class='textfield' style='color: #000' />
  594. <input type='submit' value='Upload' />
  595. <input type='checkbox' name='overwrite' value='1' style='border: 0px;' /> Overwrite existing version?
  596. <div style='margin-top: 10px'>
  597. Is this file from a published source?
  598. <input type='radio' name='is_published' value='1' style='border: 0px;' />yes
  599. <input type='radio' name='is_published' value='0' checked='checked' style='border: 0px;' />no
  600. </div>
  601. <table cellpadding='0', cellspacing='3' style='border: 0px;'>
  602. <tr>
  603. <td style='text-align: right;'>Book/Journal Title</td>
  604. <td style='text-align: left;'><input type='text' class='textfield small' name='title_whole' value='' /></td>
  605. <td style='text-align: right;'>Article/Chapter Title</td>
  606. <td style='text-align: left;'><input type='text' name='title_part' value='' /></td>
  607. </tr>
  608. <tr>
  609. <td style='text-align: right;'>Author</td>
  610. <td style='text-align: left;'><input type='text' name='author' value='' /></td>
  611. <td style='text-align: right;'>Publisher</td>
  612. <td style='text-align: left;'><input type='text' name='publisher' value='' /></td>
  613. </tr>
  614. <tr>
  615. <td style='text-align: right;'>Pages</td>
  616. <td style='text-align: left;'><input type='text' name='pagerange' value='' /></td>
  617. <td style='text-align: right;'>Pub.Year</td>
  618. <td style='text-align: left;'>
  619. <input type='text' name='pubyear' value=''
  620. onchange='if (!this.value.match(/^([0-9]{4})?$/)) {alert("Year must be four digits.\n\""+this.value+"\" is not a valid year."); this.value=""; this.focus();}' />
  621. </td>
  622. </tr>
  623. <tr>
  624. <td style='text-align: right;'>ISBN/ISSN</td><td><input type='text' name='isbn' value='' /></td>
  625. <td style='text-align: center; font-style: italic' colspan='2'>
  626. </td>
  627. </tr>
  628. </table>
  629. </form>
  630. </td>
  631. </tr>
  632. <tr>
  633. <td style='text-align: left; border: 0px solid #FFF; margin-top: 10px;' valign='top'>
  634. <?
  635. if ($upload) {
  636. print "Upload Results: <div style='margin-left: 25px'>";
  637. print $upload_results;
  638. print "</div>";
  639. } else {
  640. print " &nbsp; ";
  641. }
  642. ?>
  643. </td>
  644. </tr>
  645. </table>
  646. </td>
  647. </tr>
  648. <?
  649. if (1) {
  650. ?>
  651. <tr>
  652. <td colspan='<? print (($_SESSION['ltype']=='admin')?"10":"9"); ?>'>
  653. <table width='100%'>
  654. <tr><td style='text-align: left'>
  655. <form action='<?echo "$PHP_SELF?$sid"?>' method='post' name='searchform'>
  656. <?
  657. if ($_SESSION['ltype'] == 'admin') {
  658. ?>
  659. filename: <input type='text' name='name' size='15' value='<?echo $name?>' />
  660. site: <input type='text' name='site' size='10' value='<?echo $site?>' />
  661. user: <input type='text' name='user' size='10' value='<?echo $user?>' />
  662. <? } else { ?>
  663. filename: <input type='text' name='name' size='10' value='<?echo $name?>' />
  664. <input type='hidden' name='site' value='<?echo $site?>' />
  665. <? } ?>
  666. <input type='submit' value='search' />
  667. <input type='submit' name='clear' value='clear' />
  668. <? if ($_SESSION['ltype'] == 'admin') print "Search all sites: <input type='checkbox' name='all' value='all sites'".(($all)?" checked='checked'":"")." style='border: 0px;' />"; ?>
  669. <input type='hidden' name='order' value='<? echo $order ?>' />
  670. <input type='hidden' name='editor' value='<? echo $editor ?>' />
  671. <input type='hidden' name='source' value='<? echo $source ?>' />
  672. <input type='hidden' name='comingfrom' value='<? echo $comingfrom ?>' />
  673. <input type='hidden' name='lowerlimit' value='0' />
  674. </form>
  675. </td>
  676. <td align='right'>
  677. <?
  678. $tpages = ceil($numrows/$numperpage);
  679. $curr = ceil(($lowerlimit+$numperpage)/$numperpage);
  680. $prev = $lowerlimit-$numperpage;
  681. if ($prev < 0) $prev = 0;
  682. $next = $lowerlimit+$numperpage;
  683. if ($next >= $numrows) $next = $numrows-$numperpage;
  684. if ($next < 0) $next = 0;
  685. print "$curr of $tpages ";
  686. // print "$prev $lowerlimit $next ";
  687. if ($prev != $lowerlimit)
  688. print "<input type='button' value='&lt;&lt;' onclick=\"changePage('$prev')\" />\n";
  689. if ($next != $lowerlimit && $next > $lowerlimit)
  690. print "<input type='button' value='&gt;&gt;' onclick=\"changePage('$next')\" />\n";
  691. ?>
  692. </td>
  693. </tr>
  694. </table>
  695. </td>
  696. </tr>
  697. <? } else { ?>
  698. <form action='<?echo "$PHP_SELF?$sid"?>' method='post' name='searchform'>
  699. <input type='hidden' name='order' value='<? echo $order ?>' />
  700. <input type='hidden' name='editor' value='<? echo $editor ?>' />
  701. <input type='hidden' name='source' value='<? echo $source ?>' />
  702. <input type='hidden' name='comingfrom' value='<? echo $comingfrom ?>' />
  703. <input type='hidden' name='site' value='<? echo $site ?>' />
  704. </form>
  705. <? } ?>
  706. <tr>
  707. <th> </th>
  708. <th> </th>
  709. <?
  710. // print "<th><a href='#' onclick=\"changeOrder('";
  711. // if ($order =='media_id asc') print "media_id desc";
  712. // else print "media_id asc";
  713. // print "')\" style='color: #000'>ID";
  714. // if ($order =='media_id asc') print " &or;";
  715. // if ($order =='media_id desc') print " &and;";
  716. // print "</a></th>";
  717. print "<th><a href='#' onclick=\"changeOrder('";
  718. if ($order =='media_tag asc') print "media_tag desc";
  719. else print "media_tag asc";
  720. print "')\" style='color: #000'>File Name";
  721. if ($order =='media_tag asc') print " &and;";
  722. if ($order =='media_tag desc') print " &or;";
  723. print "</a></th>";
  724. print "<th><a href='#' onclick=\"changeOrder('";
  725. if ($order =='media_type asc') print "media_type desc";
  726. else print "media_type asc";
  727. print "')\" style='color: #000'>Type";
  728. if ($order =='media_type asc') print " &and;";
  729. if ($order =='media_type desc') print " &or;";
  730. print "</a></th>";
  731. print "<th><a href='#' onclick=\"changeOrder('";
  732. if ($order =='media_size asc') print "media_size desc";
  733. else print "media_size asc";
  734. print "')\" style='color: #000'>Size";
  735. if ($order =='media_size asc') print " &and;";
  736. if ($order =='media_size desc') print " &or;";
  737. print "</a></th>";
  738. if ($_SESSION['ltype'] == 'admin') {
  739. print "<th><a href='#' onclick=\"changeOrder('";
  740. if ($order =='slot_name asc') print "slot_name desc";
  741. else print "slot_name asc";
  742. print "')\" style='color: #000'>Site";
  743. if ($order =='slot_name asc') print " &and;";
  744. if ($order =='slot_name desc') print " &or;";
  745. print "</a></th>";
  746. }
  747. print "<th><a href='#' onclick=\"changeOrder('";
  748. if ($order =='media_updated_tstamp asc') print "media_updated_tstamp desc";
  749. else print "media_updated_tstamp asc";
  750. print "')\" style='color: #000'>Date Modified";
  751. if ($order =='media_updated_tstamp asc') print " &and;";
  752. if ($order =='media_updated_tstamp desc') print " &or;";
  753. print "</a></th>";
  754. print "<th><a href='#' onclick=\"changeOrder('";
  755. if ($order =='user_uname asc') print "user_uname desc";
  756. else print "user_uname asc";
  757. print "')\" style='color: #000'>Added by User:";
  758. if ($order =='user_uname asc') print " &and;";
  759. if ($order =='user_uname desc') print " &or;";
  760. print "</a></th>";
  761. ?>
  762. <th> </th>
  763. </tr>
  764. <?
  765. $color = 0;
  766. $today = date(Ymd);
  767. $yesterday = date(Ymd)-1;
  768. if (db_num_rows($r)) {
  769. while ($a=db_fetch_assoc($r)) {
  770. $a[media_tag] = urldecode($a[media_tag]);
  771. $a[media_size] = convertfilesize($a[media_size]);
  772. $url = $uploadurl."/".$a[slot_name]."/".rawurlencode($a[media_tag]);
  773. if ($a[media_type] == 'image') {
  774. $img_path = $uploaddir."/".$a[slot_name]."/".$a[media_tag];
  775. $img_url = $url;
  776. } else {
  777. $img_path = "images/file.gif";
  778. $img_url = $img_path;
  779. }
  780. if (file_exists($img_path)) {
  781. $thumb_size = get_sizes($img_path,'50');
  782. $img_size = get_size($img_path);
  783. } else {
  784. $img_url = "images/nofile.gif";
  785. $thumb_size = get_sizes($img_path);
  786. $img_size = get_size($img_path);
  787. }
  788. /* $img_size = get_size($url); */
  789. print "<tr>";
  790. /******************************************************************************
  791. * Media file USE button
  792. * Use button depends on context
  793. * viewsite: no USE button displayed
  794. * discussion UI: source = discuss
  795. * image content block: editor = none
  796. * text content block: editor = html
  797. ******************************************************************************/
  798. print "<td class='td$color'>\n";
  799. if ($comingfrom != "viewsite") {
  800. // for discussions, get media filename and id
  801. if ($source == 'discuss') {
  802. print "<input type='button' name='use' value='use' onclick=\"useFileDiscuss('".$a[media_id]."','".$a[media_tag]."')\" />\n";
  803. // for image content blocks
  804. } else if ($editor == 'none') {
  805. print "<input type='button' name='use' value='use' onclick=\"useFile('".$a[media_id]."','".$a[media_tag]."')\" />\n";
  806. // for text editors... (not needed?)
  807. } else if ($editor == 'text') {
  808. print "<input type='button' name='use' value='use' onclick=\"useFile('".$a[media_id]."','".$a[media_tag]."')\" />\n";
  809. // for HTML editors get media url, mediatype image url,
  810. } else if ($editor == 'html') {
  811. //printpre($editor);
  812. print "<input type='button' name='use' value='use' onclick=\"getUrl('".$url."','".$img_url."')\" />\n";
  813. // not sure where this function is called
  814. } else {
  815. //print "<input type='button' name='use' value='use' onclick=\"useFile2('".$a[slot_name]."','".$a[media_tag]."','".$a[media_id]."')\" />\n";
  816. print "<input type='button' name='use' value='use' onclick=\"FCKSetUrl('".$url."')\" />\n";
  817. }
  818. } else print " &nbsp; ";
  819. // print "<input type='button' name='use' value='use' onclick=\"useFile()\" />";
  820. print "</td>\n";
  821. print "<td class='td$color'>";
  822. if ($a[media_type]=='image') {
  823. $windowSize[x] = $img_size[x]+15;
  824. $windowSize[y] = $img_size[y]+15;
  825. // print "<a href='#' onclick=\"window.open('$url','imagewindow',config='width=$img_size[x],height=$img_size[y],resizeable=1,scrollbars=0')\">";
  826. print "<a href=\"JavaScript:window.open('$url','imagewindow',config='width=$windowSize[x],height=$windowSize[y],resizeable=1,scrollbars=0');void('');\">";
  827. } else
  828. print "<a href='$url'>";
  829. print "<img src='$img_url' height='$thumb_size[y]' width='$thumb_size[x]' border='0' alt='thumbnail image for file'/>";
  830. print "</a>";
  831. print "</td>\n";
  832. // print "<td class='td$color' style='vertical-align: top;'>";
  833. // print "$a[media_id]";
  834. // print "</td>\n";
  835. print "<td class='td$color' style='text-align: left;'>";
  836. print "<strong>$a[media_tag]</strong>";
  837. //-----------------------------------------------
  838. // Metdata
  839. //-----------------------------------------------
  840. print "\n<div>";
  841. printCitation($a);
  842. print "</div>";
  843. print<<<END
  844. <div
  845. style='cursor: pointer; text-align: right; font-size: 9px;'
  846. onclick="if (this.nextSibling.style.display!='block') {this.nextSibling.style.display='block'; this.innerHTML='cancel';} else {this.nextSibling.style.display='none'; this.innerHTML='edit'}"
  847. >
  848. END;
  849. print "edit</div>";
  850. print "<div style='display: none'>";
  851. print "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
  852. print "\n\t<input type='hidden' name='update_id' value='".$a['media_id']."'/>";
  853. print <<<END
  854. <input type='hidden' name='order' value='$order' />
  855. <input type='hidden' name='all' value='$all' />
  856. <input type='hidden' name='editor' value='$editor' />
  857. <input type='hidden' name='source' value='$source' />
  858. <input type='hidden' name='site' value='$site' />
  859. <input type='hidden' name='comingfrom' value='$comingfrom' />
  860. END;
  861. print "\n\t\t<dl>";
  862. foreach ($metadata as $field => $label) {
  863. print "\n\t\t\t<dt style='font-weight: bold'>".$label."</dt>";
  864. if ($field == "is_published") {
  865. print "\n\t\t\t<dd style='margin-left: 10px;'>
  866. <input type='radio' name='is_published' value='1' ".(($a['is_published'] == '1')?" checked='checked'":"")." style='border: 0px;' />yes
  867. <input type='radio' name='is_published' value='0' ".(($a['is_published'] == '0')?" checked='checked'":"")." style='border: 0px;' />no
  868. </dd>";
  869. } else if ($field == 'pubyear') {
  870. $val = $a[$field];
  871. print <<<END
  872. <dd style='margin-left: 10px;'>
  873. <input type='text' name='pubyear' value='$val'
  874. onchange='if (!this.value.match(/^([0-9]{4})?$/)) {alert("Year must be four digits.\\n\\""+this.value+"\\" is not a valid year."); this.value="$val"; this.focus();}' />
  875. </dd>
  876. END;
  877. } else {
  878. print "\n\t\t\t<dd style='margin-left: 10px;'><input type='text' name='".$field."' value=\"".$a[$field]."\" /></dd>";
  879. }
  880. }
  881. print "\n\t\t</dl>";
  882. print "\n\t\t<input type='submit' value='Update' />";
  883. print "\n\t\t</form>";
  884. print "\n\t</div>\n";
  885. // if ($hasMetadata)
  886. // ob_end_flush();
  887. // else
  888. // ob_end_clean();
  889. print "</td>\n";
  890. print "<td class='td$color'>";
  891. print "$a[media_type]";
  892. print "</td>\n";
  893. print "<td class='td$color'>";
  894. print "$a[media_size]";
  895. print "</td>\n";
  896. if ($_SESSION['ltype'] == 'admin') {
  897. print "<td class='td$color'>";
  898. print "$a[slot_name]";
  899. print "</td>\n";
  900. }
  901. print "<td class='td$color'><span style='white-space: nowrap;'>";
  902. if (strncmp($today, $a[media_updated_tstamp], 8) == 0 || strncmp($yesterday, $a[media_updated_tstamp], 8) == 0) print "<b>";
  903. print $a[media_updated_tstamp_text];
  904. if (strncmp($today, $a[media_updated_tstamp], 8) == 0 || strncmp($yesterday, $a[media_updated_tstamp], 8) == 0) print "</b>";
  905. print "</span></td>\n";
  906. print "<td class='td$color'>";
  907. print "$a[user_fname] ($a[user_uname])";
  908. print "</td>\n";
  909. print "<td class='td$color'>";
  910. print "<input type='button' value='delete' onclick=\"deleteFile('".$a[media_id]."','".$a[media_tag]."')\" />";
  911. // print "<input type='button' name='delete' value='delete' />";
  912. print "</td>\n";
  913. print "</tr>";
  914. $color = 1-$color;
  915. }
  916. } else {
  917. print "<tr><td colspan=".(($_SESSION['ltype']=='admin')?"10":"9")." style='text-align: left'>No media.</td></tr>";
  918. }
  919. ?>
  920. </table><br />
  921. <form action='filebrowser.php' name='deleteform' method='post'>
  922. <input type='hidden' name='filetodelete' />
  923. <input type='hidden' name='delete' value='1' />
  924. <input type='hidden' name='order' value='<? echo $order ?>' />
  925. <input type='hidden' name='all' value='<? echo $all ?>' />
  926. <input type='hidden' name='editor' value='<? echo $editor ?>' />
  927. <input type='hidden' name='source' value='<? echo $source ?>' />
  928. <input type='hidden' name='site' value='<? echo $site ?>' />
  929. <input type='hidden' name='comingfrom' value='<? echo $comingfrom ?>' />
  930. </form>
  931. <div align='right'><input type='button' value='Close Window' onclick='window.close()' /></div>
  932. <?
  933. // debug output -- handy :)
  934. /* print "<pre>"; */
  935. /* print "request:\n"; */
  936. /* print_r($_REQUEST); */
  937. /* print "\n\n"; */
  938. /* print "session:\n"; */
  939. /* print_r($_SESSION); */
  940. /* print "\n\n"; */
  941. /* if (is_object($thisPage)) { */
  942. /* print "\n\n"; */
  943. /* print "thisPage:\n"; */
  944. /* print_r($thisPage); */
  945. /* } else if (is_object($thisSection)) { */
  946. /* print "\n\n"; */
  947. /* print "thisSection:\n"; */
  948. /* print_r($thisSection); */
  949. /* } else if (is_object($thisSite)) { */
  950. /* print "\n\n"; */
  951. /* print "thisSite:\n"; */
  952. /* print_r($thisSite); */
  953. /* } */
  954. // print "</pre>";
  955. ?>
  956. </body>
  957. </html>