Beehive PHP Cross Reference Discussion Forums

Source: /edit_attachments.php - 358 lines - 15097 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*======================================================================
   4  Copyright Project Beehive Forum 2002
   5  
   6  This file is part of Beehive Forum.
   7  
   8  Beehive Forum is free software; you can redistribute it and/or modify
   9  it under the terms of the GNU General Public License as published by
  10  the Free Software Foundation; either version 3 of the License, or
  11  (at your option) any later version.
  12  
  13  Beehive Forum is distributed in the hope that it will be useful,
  14  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  GNU General Public License for more details.
  17  
  18  You should have received a copy of the GNU General Public License
  19  along with Beehive; if not, write to the Free Software
  20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  21  USA
  22  ======================================================================*/
  23  
  24  // Bootstrap
  25  require_once  'boot.php';
  26  
  27  // Required includes
  28  require_once  BH_INCLUDE_PATH . 'attachments.inc.php';
  29  require_once  BH_INCLUDE_PATH . 'constants.inc.php';
  30  require_once  BH_INCLUDE_PATH . 'form.inc.php';
  31  require_once  BH_INCLUDE_PATH . 'format.inc.php';
  32  require_once  BH_INCLUDE_PATH . 'header.inc.php';
  33  require_once  BH_INCLUDE_PATH . 'html.inc.php';
  34  require_once  BH_INCLUDE_PATH . 'session.inc.php';
  35  // End Required includes
  36  
  37  // Check we're logged in correctly
  38  if (!session::logged_in()) {
  39      html_guest_error();
  40  }
  41  
  42  // Array to hold error messages
  43  $error_msg_array = array();
  44  
  45  // Arrays to hold our attachments
  46  $attachments_array = array();
  47  $image_attachments_array = array();
  48  
  49  // If attachments are disabled then no need to go any further.
  50  if (!($attachment_dir = attachments_check_dir())) {
  51      html_draw_error(gettext("Attachments have been disabled by the forum owner."));
  52  }
  53  
  54  // Total attachment space used
  55  $total_attachment_size = attachments_get_user_used_space($_SESSION['UID']);
  56  
  57  // Free space
  58  $attachment_free_user_space = attachments_get_free_user_space($_SESSION['UID']);
  59  
  60  // Check for attachment deletion.
  61  if (isset($_POST['delete_confirm'])) {
  62  
  63      $valid = true;
  64  
  65      if (isset($_POST['attachments_delete_confirm']) && is_array($_POST['attachments_delete_confirm'])) {
  66  
  67          foreach ($_POST['attachments_delete_confirm'] as $hash => $del_attachment) {
  68  
  69              if ($del_attachment == "Y" && attachments_get_by_hash($hash)) {
  70  
  71                  if (!attachments_delete($hash)) {
  72  
  73                      $valid = false;
  74                      $error_msg_array[] = gettext("Failed to delete all of the selected attachments");
  75                  }
  76              }
  77          }
  78  
  79          if ($valid) {
  80  
  81              header_redirect("edit_attachments.php?webtag=$webtag");
  82              exit;
  83          }
  84      }
  85  
  86  } else if (isset($_POST['delete_thumbs_confirm'])) {
  87  
  88      $valid = true;
  89  
  90      if (isset($_POST['attachments_delete_confirm']) && is_array($_POST['attachments_delete_confirm'])) {
  91  
  92          foreach ($_POST['attachments_delete_confirm'] as $hash => $del_attachment) {
  93  
  94              if ($del_attachment == "Y" && attachments_get_by_hash($hash)) {
  95  
  96                  if (!attachments_delete_thumbnail($hash)) {
  97  
  98                      $valid = false;
  99                      $error_msg_array[] = gettext("Failed to delete all of the selected attachment thumbnails");
 100                  }
 101              }
 102          }
 103  
 104          if ($valid) {
 105  
 106              header_redirect("edit_attachments.php?webtag=$webtag");
 107              exit;
 108          }
 109      }
 110  
 111  } else if (isset($_POST['delete']) || isset($_POST['delete_thumbs'])) {
 112  
 113      $hash_array = array();
 114  
 115      if (isset($_POST['attachments_delete']) && is_array($_POST['attachments_delete'])) {
 116          $hash_array = array_keys($_POST['attachments_delete']);
 117      }
 118  
 119      if (is_array($hash_array) && sizeof($hash_array) > 0) {
 120  
 121          if (($attachments_array = attachments_get($_SESSION['UID'], $hash_array)) !== false) {
 122  
 123              if (isset($_POST['delete_thumbs'])) {
 124  
 125                  html_draw_top(sprintf('title=%s', gettext("Delete Thumbnails")), 'pm_popup_disabled', 'class=window_title');
 126                  echo "<h1>", gettext("Delete Thumbnails"), "</h1>\n";
 127  
 128              } else {
 129  
 130                  html_draw_top(sprintf('title=%s', gettext("Delete attachments")), 'pm_popup_disabled', 'class=window_title');
 131                  echo "<h1>", gettext("Delete attachments"), "</h1>\n";
 132              }
 133  
 134              echo "<br />\n";
 135              echo "<form accept-charset=\"utf-8\" id=\"attachments\" enctype=\"multipart/form-data\" method=\"post\" action=\"edit_attachments.php\">\n";
 136              echo "  ", form_input_hidden('webtag', htmlentities_array($webtag)), "\n";
 137              echo "  <table cellpadding=\"0\" cellspacing=\"0\" width=\"700\">\n";
 138              echo "    <tr>\n";
 139              echo "      <td align=\"left\">\n";
 140              echo "        <table class=\"box\" width=\"100%\">\n";
 141              echo "          <tr>\n";
 142              echo "            <td align=\"left\" class=\"posthead\">\n";
 143              echo "              <table class=\"posthead\" width=\"100%\">\n";
 144  
 145              if (isset($_POST['delete_thumbs'])) {
 146  
 147                  echo "                <tr>\n";
 148                  echo "                  <td align=\"left\" class=\"subhead\">", gettext("Delete Thumbnails"), "</td>\n";
 149                  echo "                </tr>\n";
 150                  echo "                <tr>\n";
 151                  echo "                  <td align=\"center\">\n";
 152                  echo "                    <table class=\"posthead\" width=\"90%\">\n";
 153                  echo "                      <tr>\n";
 154                  echo "                        <td align=\"left\">", gettext("Are you sure you want to delete the selected attachments thumbnails?"), "</td>\n";
 155                  echo "                      </tr>\n";
 156  
 157              } else {
 158  
 159                  echo "                <tr>\n";
 160                  echo "                  <td align=\"left\" class=\"subhead\">", gettext("Delete attachments"), "</td>\n";
 161                  echo "                </tr>\n";
 162                  echo "                <tr>\n";
 163                  echo "                  <td align=\"center\">\n";
 164                  echo "                    <table class=\"posthead\" width=\"90%\">\n";
 165                  echo "                      <tr>\n";
 166                  echo "                        <td align=\"left\">", gettext("Are you sure you want to delete the selected attachments?"), "</td>\n";
 167                  echo "                      </tr>\n";
 168              }
 169  
 170              echo "                      <tr>\n";
 171              echo "                        <td align=\"center\">\n";
 172              echo "                          <table class=\"posthead\" width=\"95%\">\n";
 173              echo "                            <tr>\n";
 174              echo "                              <td><br />\n";
 175  
 176              if (is_array($attachments_array) && sizeof($attachments_array) > 0) {
 177  
 178                  foreach ($attachments_array as $attachment) {
 179  
 180                      echo "                                ", attachments_make_link($attachment, false, false), "<br />\n";
 181                      echo "                                ", form_input_hidden("attachments_delete_confirm[{$attachment['hash']}]", "Y"), "\n";
 182                  }
 183              }
 184  
 185              echo "                              </td>\n";
 186              echo "                            </tr>\n";
 187              echo "                          </table>\n";
 188              echo "                        </td>\n";
 189              echo "                      </tr>\n";
 190              echo "                    </table>\n";
 191              echo "                  </td>\n";
 192              echo "                </tr>\n";
 193              echo "                <tr>\n";
 194              echo "                  <td align=\"left\">&nbsp;</td>\n";
 195              echo "                </tr>\n";
 196              echo "              </table>\n";
 197              echo "            </td>\n";
 198              echo "          </tr>\n";
 199              echo "        </table>\n";
 200              echo "      </td>\n";
 201              echo "    </tr>\n";
 202              echo "    <tr>\n";
 203              echo "      <td align=\"left\">&nbsp;</td>\n";
 204              echo "    </tr>\n";
 205  
 206              if (isset($_POST['delete_thumbs'])) {
 207  
 208                  echo "    <tr>\n";
 209                  echo "      <td align=\"center\">", form_submit("delete_thumbs_confirm", gettext("Confirm")), "&nbsp;", form_submit("cancel", gettext("Cancel")), "</td>\n";
 210                  echo "    </tr>\n";
 211  
 212              } else {
 213  
 214                  echo "    <tr>\n";
 215                  echo "      <td align=\"center\">", form_submit("delete_confirm", gettext("Confirm")), "&nbsp;", form_submit("cancel", gettext("Cancel")), "</td>\n";
 216                  echo "    </tr>\n";
 217              }
 218  
 219              echo "  </table>\n";
 220              echo "</form>\n";
 221  
 222              html_draw_bottom();
 223              exit;
 224          }
 225      }
 226  }
 227  
 228  html_draw_top(sprintf('title=%s', gettext("Attachments")), "js/attachments.js", 'pm_popup_disabled', 'class=window_title');
 229  
 230  echo "<h1>", gettext("Attachments"), "</h1>\n";
 231  
 232  if (isset($error_msg_array) && sizeof($error_msg_array) > 0) {
 233      html_display_error_array($error_msg_array, '700', 'center');
 234  }
 235  
 236  echo "<br />\n";
 237  echo "<form accept-charset=\"utf-8\" name=\"attachments\" method=\"post\" action=\"edit_attachments.php\">\n";
 238  echo "  ", form_input_hidden('webtag', htmlentities_array($webtag)), "\n";
 239  echo "  <table cellpadding=\"0\" cellspacing=\"0\" width=\"700\">\n";
 240  echo "    <tr>\n";
 241  echo "      <td align=\"left\">\n";
 242  echo "        <table class=\"box\" width=\"100%\">\n";
 243  echo "          <tr>\n";
 244  echo "            <td align=\"left\" class=\"posthead\">\n";
 245  echo "              <table class=\"posthead\" width=\"100%\">\n";
 246  
 247  if (($attachments_array = attachments_get_all($_SESSION['UID'])) !== false) {
 248  
 249      echo "                <tr>\n";
 250      echo "                  <td class=\"subhead_checkbox\" align=\"center\" width=\"1%\">", form_checkbox("toggle_main", "toggle_main"), "</td>\n";
 251      echo "                  <td align=\"left\" colspan=\"4\" class=\"subhead\">", gettext("Attachments"), "</td>\n";
 252      echo "                </tr>\n";
 253  
 254      foreach ($attachments_array as $key => $attachment) {
 255  
 256          if (($attachment_link = attachments_make_link($attachment, false, true)) !== false) {
 257  
 258              echo "                <tr>\n";
 259              echo "                  <td align=\"center\" width=\"1%\">", form_checkbox("attachments_delete[{$attachment['hash']}]", "Y"), "</td>\n";
 260              echo "                  <td align=\"left\" valign=\"middle\" style=\"white-space: nowrap\" class=\"postbody\">$attachment_link</td>\n";
 261              echo "                  <td align=\"left\" valign=\"middle\" style=\"white-space: nowrap\" class=\"postbody\">";
 262  
 263              if (($message_link = attachments_get_message_link($attachment['hash'])) !== false) {
 264  
 265                  echo "<a href=\"$message_link\" target=\"_blank\">", gettext("View Message"), "</a>";
 266  
 267              } else if (($message_link = attachments_get_pm_link($attachment['hash'])) !== false) {
 268  
 269                  echo "<a href=\"$message_link\" target=\"_blank\">", gettext("View Message"), "</a>";
 270  
 271              } else {
 272  
 273                  echo '&nbsp;';
 274              }
 275  
 276              echo "</td>\n";
 277  
 278              if (isset($attachment['filesize']) && ($attachment['filesize'] > 0)) {
 279                  echo "                  <td align=\"right\" valign=\"middle\" style=\"white-space: nowrap\" class=\"postbody\">", format_file_size($attachment['filesize']), "</td>\n";
 280              } else {
 281                  echo "                  <td align=\"right\" valign=\"middle\" class=\"postbody\">", gettext("Unknown size"), "</td>\n";
 282              }
 283  
 284              echo "                  <td align=\"left\" width=\"25\">&nbsp;</td>\n";
 285              echo "                </tr>\n";
 286          }
 287      }
 288  
 289  } else {
 290  
 291      echo "                <tr>\n";
 292      echo "                  <td class=\"subhead_checkbox\" align=\"center\" width=\"25\">&nbsp;</td>\n";
 293      echo "                  <td align=\"left\" colspan=\"4\" class=\"subhead\">", gettext("Attachments"), "</td>\n";
 294      echo "                </tr>\n";
 295      echo "                <tr>\n";
 296      echo "                  <td align=\"center\" width=\"25\">&nbsp;</td>\n";
 297      echo "                  <td align=\"left\" valign=\"top\" colspan=\"4\" class=\"postbody\">(", gettext("none"), ")</td>\n";
 298      echo "                </tr>\n";
 299  }
 300  
 301  echo "                <tr>\n";
 302  echo "                  <td align=\"left\" colspan=\"4\">&nbsp;</td>\n";
 303  echo "                </tr>\n";
 304  echo "              </table>\n";
 305  echo "            </td>\n";
 306  echo "          </tr>\n";
 307  echo "        </table>\n";
 308  echo "      </td>\n";
 309  echo "    </tr>\n";
 310  echo "  </table>\n";
 311  echo "  <br />\n";
 312  echo "  <table cellpadding=\"0\" cellspacing=\"0\" width=\"700\">\n";
 313  echo "    <tr>\n";
 314  echo "      <td align=\"left\">\n";
 315  echo "        <table class=\"box\" width=\"100%\">\n";
 316  echo "          <tr>\n";
 317  echo "            <td align=\"left\" class=\"posthead\">\n";
 318  echo "              <table class=\"posthead\" width=\"100%\">\n";
 319  echo "                <tr>\n";
 320  echo "                  <td align=\"left\" colspan=\"5\" class=\"subhead\">", gettext("Usage"), "</td>\n";
 321  echo "                </tr>\n";
 322  echo "              </table>\n";
 323  echo "              <table class=\"posthead\" width=\"100%\">\n";
 324  echo "                <tr>\n";
 325  echo "                  <td align=\"left\" width=\"25\">&nbsp;</td>\n";
 326  echo "                  <td align=\"left\" valign=\"top\" class=\"postbody\">", gettext("Total Size"), ":</td>\n";
 327  echo "                  <td align=\"left\" valign=\"top\" class=\"postbody\">&nbsp;</td>\n";
 328  echo "                  <td align=\"right\" valign=\"top\" class=\"postbody\">", format_file_size($total_attachment_size), "</td>\n";
 329  echo "                  <td align=\"left\" width=\"25\">&nbsp;</td>\n";
 330  echo "                </tr>\n";
 331  echo "                <tr>\n";
 332  echo "                  <td align=\"left\" width=\"25\">&nbsp;</td>\n";
 333  echo "                  <td align=\"left\" valign=\"top\" class=\"postbody\">", gettext("Free Space"), ":</td>\n";
 334  echo "                  <td align=\"left\" valign=\"top\" class=\"postbody\">&nbsp;</td>\n";
 335  echo "                  <td align=\"right\" valign=\"top\" class=\"postbody\">", ($attachment_free_user_space >= 0) ? format_file_size($attachment_free_user_space) : gettext('Unlimited'), "</td>\n";
 336  echo "                  <td align=\"left\" width=\"25\">&nbsp;</td>\n";
 337  echo "                </tr>\n";
 338  echo "                <tr>\n";
 339  echo "                  <td align=\"left\" colspan=\"5\">&nbsp;</td>\n";
 340  echo "                </tr>\n";
 341  echo "              </table>\n";
 342  echo "            </td>\n";
 343  echo "          </tr>\n";
 344  echo "        </table>\n";
 345  echo "      </td>\n";
 346  echo "    </tr>\n";
 347  echo "    <tr>\n";
 348  echo "      <td align=\"left\">&nbsp;</td>\n";
 349  echo "    </tr>\n";
 350  echo "    <tr>\n";
 351  echo "      <td align=\"center\">";
 352  echo "        ", form_submit('delete', gettext("Delete"));
 353  echo "      </td>\n";
 354  echo "    </tr>\n";
 355  echo "  </table>\n";
 356  echo "</form>\n";
 357  
 358  html_draw_bottom();

title

Description

title

Description

title

Description

title

title

Body