/mods/_standard/file_storage/edit_folder.php

https://github.com/harriswong/ATutor · PHP · 86 lines · 59 code · 15 blank · 12 comment · 8 complexity · 61a5f302f7344461a3ebb99e8e55861c MD5 · raw file

  1. <?php
  2. /****************************************************************/
  3. /* ATutor */
  4. /****************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  9. /* This program is free software. You can redistribute it and/or*/
  10. /* modify it under the terms of the GNU General Public License */
  11. /* as published by the Free Software Foundation. */
  12. /****************************************************************/
  13. // $Id$
  14. define('AT_INCLUDE_PATH', '../../../include/');
  15. require(AT_INCLUDE_PATH.'vitals.inc.php');
  16. require(AT_INCLUDE_PATH.'../mods/_standard/file_storage/file_storage.inc.php');
  17. $owner_type = abs($_REQUEST['ot']);
  18. $owner_id = abs($_REQUEST['oid']);
  19. $owner_arg_prefix = '?ot='.$owner_type.SEP.'oid='.$owner_id. SEP;
  20. if (!($owner_status = fs_authenticate($owner_type, $owner_id)) || !query_bit($owner_status, WORKSPACE_AUTH_WRITE)) {
  21. $msg->addError('ACCESS_DENIED');
  22. header('Location: '.url_rewrite('mods/_standard/file_storage/index.php', AT_PRETTY_URL_IS_HEADER));
  23. exit;
  24. }
  25. if (isset($_POST['cancel'])) {
  26. $msg->addFeedback('CANCELLED');
  27. header('Location: '.url_rewrite('mods/_standard/file_storage/index.php'.$owner_arg_prefix.'folder='.abs($_POST['parent_folder']), AT_PRETTY_URL_IS_HEADER));
  28. exit;
  29. } else if (isset($_POST['submit'])) {
  30. $_POST['id'] = abs($_POST['id']);
  31. if (!$_POST['name']) {
  32. $msg->addError(array('EMPTY_FIELDS', _AT('name')));
  33. }
  34. if (!$msg->containsErrors()) {
  35. $_POST['name'] = $addslashes($_POST['name']);
  36. $folder = abs($_POST['folder']);
  37. $parent_folder = abs($_POST['parent_folder']);
  38. $sql = "UPDATE ".TABLE_PREFIX."folders SET title='$_POST[name]' WHERE owner_type=$owner_type AND owner_id=$owner_id AND folder_id=$_POST[id] AND parent_folder_id=$parent_folder";
  39. mysql_query($sql, $db);
  40. $msg->addFeedback('FOLDER_EDITED_SUCCESSFULLY');
  41. header('Location: '.url_rewrite('mods/_standard/file_storage/index.php'.$owner_arg_prefix.'folder='.$parent_folder, AT_PRETTY_URL_IS_HEADER));
  42. exit;
  43. }
  44. $_GET['id'] = $_POST['id'];
  45. }
  46. $onload = 'document.form.name.focus();';
  47. require(AT_INCLUDE_PATH.'header.inc.php');
  48. $id = abs($_GET['id']);
  49. $sql = "SELECT title, parent_folder_id FROM ".TABLE_PREFIX."folders WHERE folder_id=$id";
  50. $result = mysql_query($sql, $db);
  51. if (!$row = mysql_fetch_assoc($result)) {
  52. $msg->printErrors('FOLDER_NOT_EXIST');
  53. require(AT_INCLUDE_PATH.'footer.inc.php');
  54. exit;
  55. }
  56. ?>
  57. <form method="post" action="<?php echo $_SERVER['PHP_SELF'].$owner_arg_prefix; ?>" name="form">
  58. <input type="hidden" name="id" value="<?php echo $id; ?>" />
  59. <input type="hidden" name="parent_folder" value="<?php echo $row['parent_folder_id']; ?>" />
  60. <div class="input-form">
  61. <div class="row">
  62. <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="name"><?php echo _AT('name'); ?></label><br />
  63. <input type="text" name="name" id="name" value="<?php echo htmlspecialchars($row['title']); ?>" size="40" maxlength="70" />
  64. </div>
  65. <div class="row buttons">
  66. <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" />
  67. <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
  68. </div>
  69. </div>
  70. </form>
  71. <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>