[ Index ]

PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12)

title

Body

[close]

/include/inc_tmpl/ -> files.private.upload.tmpl.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2012 Oliver Georgi <oliver@phpwcms.de> // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  // ----------------------------------------------------------------
  24  // obligate check for phpwcms constants
  25  if (!defined('PHPWCMS_ROOT')) {
  26     die("You Cannot Access This Script Directly, Have a Nice Day.");
  27  }
  28  // ----------------------------------------------------------------
  29  
  30  
  31  // initialize Mootools for autocomplete
  32  initMootoolsAutocompleter();
  33  
  34  // Upload new file
  35  $file_aktiv                = 1;
  36  $file_public            = 0;
  37  $file_shortinfo            = '';
  38  $file_longinfo            = '';
  39  $file_pid                = empty($_GET["upload"]) ? 0 : intval($_GET["upload"]);
  40  $file_copyright            = '';
  41  $file_tags                = '';
  42  $file_granted            = 0;
  43  $file_gallerydownload    = 0;
  44  $file_sort                = 0;
  45                  
  46  //Auswerten des Formulars
  47  if(isset($_POST["file_aktion"]) && intval($_POST["file_aktion"]) == 1) {
  48      if(!ini_get('safe_mode') && function_exists('set_time_limit')) set_time_limit(0);
  49      $file_pid                 = intval($_POST["file_pid"]);
  50      $file_aktiv                = empty($_POST["file_aktiv"]) ? 0 : 1;
  51      $file_public             = empty($_POST["file_public"]) ? 0 : 1;
  52      $file_shortinfo            = clean_slweg($_POST["file_shortinfo"]);
  53      $file_longinfo            = slweg(trim($_POST["file_longinfo"]));
  54      $file_copyright            = clean_slweg($_POST["file_copyright"]);
  55      $file_tags                = trim( clean_slweg($_POST["file_tags"]), ',' );
  56      $file_granted            = empty($_POST["file_granted"]) ? 0 : 1;
  57      $file_gallerydownload    = empty($_POST["file_gallerydownload"]) ? 0 : 1;
  58      $file_keys                = '';
  59      $file_sort                 = intval($_POST["file_sort"]);
  60      
  61      $file_keywords    = empty($_POST["file_keywords"]) ? array() : $_POST["file_keywords"];
  62      if(count($file_keywords)) {
  63          foreach($file_keywords as $key => $value) {
  64              unset($file_keywords[$key]);
  65              $key = intval($key);
  66              if($value != "0_1") {
  67                  $file_keys .= (($file_keys) ? ":" : "").$key."_".intval($value);
  68                  $file_keywords[$key] = intval($value);
  69              } else {
  70                  $file_error["keywords"][$key] = 1;
  71              }        
  72          }
  73      }
  74      
  75      //starts upload of file
  76      if(!is_uploaded_file($_FILES["file"]["tmp_name"])) {
  77          $file_error["file"] = $BL['be_fprivup_err1'];
  78      } else {
  79          if($_FILES["file"]["size"] > $phpwcms["file_maxsize"]) {
  80              $file_error["file"] = $BL['be_fprivup_err2']." ".number_format($phpwcms["file_maxsize"] / 1024, 2, ',', '.')." kB";
  81          }
  82      }
  83      
  84      //Create new file in database and give hashed
  85      if(!isset($file_error)) {
  86          $fileExt    = check_image_extension($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]);
  87          $fileExt    = $fileExt === false ? which_ext($_FILES["file"]["name"]) : $fileExt;
  88          $fileName    = clearfilename($_FILES["file"]["name"]);
  89          $fileHash    = md5( $fileName . microtime() );
  90          $fileType    = is_mimetype_format($_FILES["file"]["type"]) ? $_FILES["file"]["type"] : get_mimetype_by_extension($fileExt);
  91          
  92          $sql =  "INSERT INTO ".DB_PREPEND."phpwcms_file (".
  93                  "f_pid, f_uid, f_kid, f_aktiv, f_public, f_name, f_created, f_size, f_type, f_ext, ".
  94                  "f_shortinfo, f_longinfo, f_keywords, f_hash, f_copyright, f_tags, f_granted, f_gallerystatus, f_sort) VALUES (".
  95                  $file_pid.", ".intval($_SESSION["wcs_user_id"]).", 1, ".$file_aktiv.", ".$file_public.", '".
  96                  $fileName."', '".time()."', '".intval($_FILES["file"]["size"])."', '".
  97                  aporeplace($fileType)."', '".$fileExt."', '".aporeplace($file_shortinfo)."', '".
  98                  aporeplace($file_longinfo)."', '".aporeplace($file_keys)."', '".aporeplace($fileHash)."', '".
  99                  aporeplace($file_copyright)."', '".aporeplace($file_tags)."', ".$file_granted.", ".
 100                  $file_gallerydownload.", ".$file_sort.")";
 101          
 102          if($result = mysql_query($sql, $db) or die("error while insert file information")) {
 103              $new_fileId = mysql_insert_id($db); //Festlegen der aktuellen File-ID    
 104              $wcs_newfilename = ($fileExt) ? $fileHash.'.'.$fileExt : $fileHash;
 105  
 106              // changed for using hashed file names
 107              $useruploadpath = PHPWCMS_ROOT.$phpwcms["file_path"];
 108              $usernewfile    = $useruploadpath.$wcs_newfilename;
 109              
 110              if ($dir = @opendir($useruploadpath)) {
 111                  if(!@move_uploaded_file($_FILES["file"]["tmp_name"], $usernewfile)) {
 112                      
 113                      $file_error["upload"] = $BL['be_fprivup_err3'].' (1)';
 114                  }
 115              } else {
 116                  $oldumask = umask(0);
 117                  if(@mkdir($useruploadpath, 0777)) {;
 118                      if(!@move_uploaded_file($_FILES["file"]["tmp_name"], $usernewfile)) {
 119                          $file_error["upload"] = $BL['be_fprivup_err3'].' (2)';
 120                      }
 121                  } else {
 122                      $file_error["upload"] = $BL['be_fprivup_err4'];
 123                  }
 124                  umask($oldumask);
 125              }
 126              if(file_exists($usernewfile)) {
 127                  @chmod($usernewfile, 0666);
 128              }
 129              if(!isset($file_error["upload"])) {
 130              
 131                  // store tags
 132                  _dbSaveCategories($file_tags, 'file', $new_fileId, ',');
 133              
 134                  //after successful upload go back to clear post (form) var        
 135                  headerRedirect(PHPWCMS_URL."phpwcms.php?do=files&f=0&uploaded=1");
 136              } else {
 137                  echo $file_error["upload"]."<br />";
 138                  $file_error["upload"] = str_replace('{VAL}', $phpwcms["admin_email"], $BL['be_fprivup_err6']);
 139                  mysql_query("DELETE FROM ".DB_PREPEND."phpwcms_file WHERE f_id=".$new_fileId." AND f_uid=".$_SESSION["wcs_user_id"].";", $db);
 140              }        
 141          }
 142      }
 143      if(!ini_get('safe_mode') && function_exists('set_time_limit')) set_time_limit(30);
 144  }
 145  //Ende Auswerten Formular
 146                  
 147  
 148  ?>
 149  <form action="phpwcms.php?do=files&amp;f=0" method="post" enctype="multipart/form-data" name="uploadfile" id="uploadfile">
 150  <table border="0" cellpadding="0" cellspacing="0" bgcolor='#EBF2F4' summary="">
 151      <tr>
 152          <td rowspan="2" valign="top"><a href="phpwcms.php?do=files&amp;f=0"><img src="img/button/close_reiter.gif" alt="" width="45" height="12" border="0" /></a></td>
 153          <td><img src="img/leer.gif" alt="" width="1" height="6" /></td>
 154      </tr>
 155      <tr><td class="title"><?php echo $BL['be_fprivup_title'] ?></td></tr>
 156      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="5" /></td></tr>
 157      <tr>
 158          <td align="right" class="v09"><?php echo $BL['be_ftptakeover_directory'] ?>:&nbsp;</td>
 159          <td class="v10"><select name="file_pid" id="file_pid" class="width400">
 160  <option value="0"><?php echo $BL['be_ftptakeover_rootdir'] ?></option>
 161  <?php dir_menu(0, $file_pid, $db, "+", $_SESSION["wcs_user_id"], "+") ?>
 162      </select></td>
 163      </tr>
 164      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="6" /></td></tr>
 165      <tr><td colspan="2"><img src="img/lines/line-bluelight.gif" alt="" width="538" height="1" /></td></tr>
 166      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="6" /></td></tr>
 167      <?php if(isset($file_error["upload"])) { ?>
 168      <tr>
 169        <td><img src="img/leer.gif" alt="" width="1" height="1" /></td>
 170        <td class="v10"><strong style="color:#FF3300"><?php echo $file_error["upload"] ?></strong></td>
 171      </tr>
 172      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="2" /></td>
 173      </tr>
 174      <?php }
 175      
 176      if(isset($file_error["file"])) { ?>
 177      <tr>
 178        <td><img src="img/leer.gif" alt="" width="1" height="1" /></td>
 179        <td class="v10"><strong style="color:#FF3300"><?php echo $file_error["file"] ?></strong></td>
 180      </tr>
 181      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="2" /></td></tr>
 182      <?php } ?>
 183      <tr>
 184          <td align="right" class="v09"><?php echo $BL['be_fprivup_upload'] ?>:&nbsp;</td>
 185          <td><input name="file" type="file" id="file" size="40" /></td>
 186      </tr>
 187      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="6" /></td></tr>
 188      <tr><td colspan="2"><img src="img/lines/line-bluelight.gif" alt="" width="538" height="1" /></td></tr>
 189      <tr bgcolor="#F5F8F9"><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="6" /></td></tr>
 190      <?php 
 191      
 192      //Auswahlliste vordefinierte Keywörter
 193      $sql = "SELECT * FROM ".DB_PREPEND."phpwcms_filecat WHERE fcat_deleted=0 ORDER BY fcat_sort, fcat_name";
 194      if($result = mysql_query($sql, $db) or die("error while browsing file categories for selecting keywords")) {
 195          $k = "";
 196          while($row = mysql_fetch_array($result)) {
 197              if(get_filecat_childcount ($row["fcat_id"], $db)) {
 198              
 199                  $ke = empty($file_error["keywords"][$row["fcat_id"]])? '' : "<img src=\"img/symbole/error.gif\" width=\"8\" height=\"9\">&nbsp;";
 200                  $k .= "<tr>\n<td class=\"f10b\">".$ke.html_specialchars($row["fcat_name"]).":&nbsp;</td>\n";
 201                  $k .= "<td><select name=\"file_keywords[".$row["fcat_id"]."]\" class=\"width300\">\n";
 202                  $k .= "<option value=\"".(($row["fcat_needed"])?"0_".$row["fcat_needed"]."\">".$BL['be_ftptakeover_needed']:'0">'.$BL['be_ftptakeover_optional'])."</option>\n";
 203                  
 204                  $ksql = "SELECT * FROM ".DB_PREPEND."phpwcms_filekey WHERE fkey_deleted=0 AND fkey_cid=".$row["fcat_id"]." ORDER BY fkey_name";
 205                  if($kresult = mysql_query($ksql, $db) or die("error while listing file keywords")) {
 206                      while($krow = mysql_fetch_array($kresult)) {
 207                          $k .= "<option value=\"".$krow["fkey_id"]."\"";
 208                          $k .= isset($file_keywords[$row["fcat_id"]]) && $file_keywords[$row["fcat_id"]] == $krow["fkey_id"] ? " selected" : "";
 209                          $k .= ">".html_specialchars($krow["fkey_name"])."</option>\n";
 210                      }
 211                      mysql_free_result($kresult);
 212                  }
 213                  
 214                  $k .= "</select></td>\n</tr>\n";
 215                  $k .= "<tr>\n<td colspan=\"2\"><img src=\"img/leer.gif\" width=\"1\" height=\"2\"></td>\n</tr>\n";            
 216              
 217              }
 218          }
 219          mysql_free_result($result);
 220      }    
 221      //Ende vordefinierte Keywörter
 222      
 223      ?>
 224      <tr bgcolor="#F5F8F9">
 225          <td align="right" valign="top" class="v09"><img src="img/leer.gif" alt="" width="1" height="13" /><?php echo $BL['be_ftptakeover_keywords'] ?>:&nbsp;</td>
 226          <td><table border="0" cellpadding="0" cellspacing="0" summary="">
 227          <?php if($k) echo $k; ?>
 228          <tr>
 229              <td class="f10b"><?php echo $BL['be_ftptakeover_additional'] ?>:&nbsp;</td>
 230              <td><input name="file_shortinfo" type="text" class="width300" id="file_shortinfo" value="<?php echo html_specialchars($file_shortinfo) ?>" size="40" maxlength="250" /></td>
 231          </tr>        
 232          </table></td>
 233      </tr>
 234      <tr bgcolor="#F5F8F9"><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="6" /></td>
 235      </tr>
 236      <tr><td colspan="2"><img src="img/lines/line-bluelight.gif" alt="" width="538" height="1" /></td>
 237      </tr>
 238      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="6" /></td>
 239      </tr>
 240      <tr>
 241          <td align="right" valign="top" class="v09"><img src="img/leer.gif" alt="" width="1" height="13" /><?php echo $BL['be_ftptakeover_longinfo'] ?>:&nbsp;</td>
 242          <td valign="top"><textarea name="file_longinfo" cols="40" rows="10" class="v12 width400" id="file_longinfo"><?php echo html_specialchars($file_longinfo) ?></textarea></td>
 243      </tr>    
 244      
 245  
 246      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="3" /></td>
 247      </tr>
 248      
 249      <tr>
 250          <td align="right" class="v09"><?php echo $BL['be_copyright'] ?>:&nbsp;</td>
 251          <td><input name="file_copyright" type="text" id="file_copyright" size="40" class="width400" maxlength="255" value="<?php echo html_specialchars($file_copyright) ?>" /></td>
 252      </tr>    
 253      
 254      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="3" /></td></tr>
 255      
 256      <tr>
 257          <td align="right" class="v09">&nbsp;<?php echo $BL['be_tags'] ?>:&nbsp;</td>
 258          <td><input name="file_tags" type="text" id="file_tags" size="40" class="width400" maxlength="255" value="<?php echo html_specialchars($file_tags) ?>" /></td>
 259      </tr>
 260      
 261      
 262      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="8" /></td></tr>
 263  
 264      
 265      <tr>
 266          <td align="right" class="v09">&nbsp;<?php echo $BL['be_cnt_sorting'] ?>:&nbsp;</td>
 267          <td><input name="file_sort" type="text" id="file_sort" size="10" class="width50" maxlength="10" value="<?php echo intval($file_sort) ?>" /></td>
 268      </tr>    
 269  
 270      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="5" /></td></tr>
 271      
 272      
 273      <tr>
 274          <td align="right" class="v09 tdtop3"><?php echo $BL['be_ftptakeover_status'] ?>:&nbsp;</td>
 275          <td><table border="0" cellpadding="0" cellspacing="0" summary="">
 276          <tr>
 277              <td><input name="file_aktiv" type="checkbox" id="file_aktiv" value="1"<?php is_checked("1", $file_aktiv) ?> /></td>
 278              <td class="v10"><strong><label for="file_aktiv"><?php echo $BL['be_ftptakeover_active'] ?></label></strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 279              
 280              <td><input name="file_granted" type="checkbox" id="file_granted" value="1"<?php is_checked("1", $file_granted) ?>></td>
 281              <td class="v10"><label for="file_granted"><?php echo $BL['be_granted_download'] ?></label></td>
 282          </tr>
 283          <tr>
 284              <td><input name="file_public" type="checkbox" id="file_public" value="1"<?php is_checked("1", $file_public) ?> /></td>
 285              <td class="v10"><strong><label for="file_public"><?php echo $BL['be_ftptakeover_public'] ?></label></strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
 286              
 287              <td><input name="file_gallerydownload" type="checkbox" id="file_gallerydownload" value="1"<?php is_checked(1, $file_gallerydownload) ?>></td>
 288              <td class="v10"><label for="file_gallerydownload"><?php echo $BL['be_gallerydownload'] ?></label></td>
 289          </tr>
 290          </table></td>
 291      </tr>
 292      
 293      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="5" /></td></tr>
 294      
 295      <tr>
 296          <td valign="top"><input name="file_aktion" type="hidden" id="file_aktion" value="1" />
 297              <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $phpwcms["file_maxsize"] ?>" /></td>
 298          <td><input name="Submit" type="submit" class="button10" value="<?php echo $BL['be_fprivup_button'] ?>" /></td>
 299      </tr>
 300      <tr><td colspan="2"><img src="img/leer.gif" alt="" width="1" height="8" /></td></tr>
 301      <tr><td colspan="2" bgcolor="#9BBECA"><img src="img/leer.gif" alt="" width="1" height="4" /></td></tr>
 302  </table>
 303  </form>
 304  <script type="text/javascript">
 305  <!--
 306  
 307  window.addEvent('domready', function(){
 308                                       
 309      /* Autocompleter for keywords (=tags) */
 310      var searchKeyword = $('file_tags');
 311      var indicator = new Element('span', {'class': 'autocompleter-loading', 'styles': {'display': 'none'}}).setHTML('').injectAfter(searchKeyword);
 312      var completer = new Autocompleter.Ajax.Json(searchKeyword, 'include/inc_act/ajax_connector.php', {
 313          multi: true,
 314          maxChoices: 30,
 315          autotrim: true,
 316          minLength: 0,
 317          allowDupes: false,
 318          postData: {action: 'category', method: 'json'},
 319          onRequest: function(el) {
 320              indicator.setStyle('display', '');
 321          },
 322          onComplete: function(el) {
 323              indicator.setStyle('display', 'none');
 324          }
 325      });
 326      
 327  
 328  });
 329  
 330  
 331  //-->
 332  </script>


Generated: Sun Jan 29 16:31:14 2012 Cross-referenced by PHPXref 0.7.1