[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/modules/files/ -> do_file_aed.php (source)

   1  <?php /* $Id: do_file_aed.php 137 2008-04-04 16:12:02Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/files/do_file_aed.php $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  
   6  //addfile sql
   7  $file_id = intval(w2PgetParam($_POST, 'file_id', 0));
   8  $del = intval(w2PgetParam($_POST, 'del', 0));
   9  $duplicate = intval(w2PgetParam($_POST, 'duplicate', 0));
  10  $redirect = w2PgetParam($_POST, 'redirect', '');
  11  global $db;
  12  
  13  $not = w2PgetParam($_POST, 'notify', '0');
  14  $notcont = w2PgetParam($_POST, 'notify_contacts', '0');
  15  if ($not != '0') {
  16      $not = '1';
  17  }
  18  if ($notcont != '0') {
  19      $notcont = '1';
  20  }
  21  
  22  $isNotNew = $_POST['file_id'];
  23  $perms = &$AppUI->acl();
  24  if ($del) {
  25      if (!$perms->checkModuleItem('files', 'delete', $file_id)) {
  26          $AppUI->redirect('m=public&a=access_denied');
  27      }
  28  } elseif ($isNotNew) {
  29      if (!$perms->checkModuleItem('files', 'edit', $file_id)) {
  30          $AppUI->redirect('m=public&a=access_denied');
  31      }
  32  } else {
  33      if (!$perms->checkModule('files', 'add')) {
  34          $AppUI->redirect('m=public&a=access_denied');
  35      }
  36  }
  37  
  38  $obj = new CFile();
  39  if ($file_id) {
  40      $obj->_message = 'updated';
  41      $oldObj = new CFile();
  42      $oldObj->load($file_id);
  43  } else {
  44      $obj->_message = 'added';
  45  }
  46  $obj->file_category = intval(w2PgetParam($_POST, 'file_category', 0));
  47  
  48  $version = w2PgetParam($_POST, 'file_version', 0);
  49  $revision_type = w2PgetParam($_POST, 'revision_type', 0);
  50  
  51  if (strcasecmp('major', $revision_type) == 0) {
  52      $major_num = strtok($version, '.') + 1;
  53      $_POST['file_version'] = $major_num;
  54  }
  55  
  56  if (!$obj->bind($_POST)) {
  57      $AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
  58      $AppUI->redirect($redirect);
  59  }
  60  
  61  // prepare (and translate) the module name ready for the suffix
  62  $AppUI->setMsg('File');
  63  // duplicate a file
  64  if ($duplicate) {
  65      $obj->load($file_id);
  66      $new_file = new CFile();
  67      $new_file = $obj->duplicate();
  68      $new_file->file_project = 0;
  69      $new_file->file_folder = 0;
  70      if (!($dup_realname = $obj->duplicateFile($obj->file_project, $obj->file_real_filename))) {
  71          $AppUI->setMsg('Could not duplicate file, check file permissions', UI_MSG_ERROR);
  72          $AppUI->redirect();
  73      } else {
  74          $new_file->file_real_filename = $dup_realname;
  75          $new_file->file_date = str_replace("'", '', $db->DBTimeStamp(time()));
  76          if (($msg = $new_file->store())) {
  77              $AppUI->setMsg($msg, UI_MSG_ERROR);
  78              $AppUI->redirect($redirect);
  79          } else {
  80              $AppUI->setMsg('duplicated', UI_MSG_OK, true);
  81              $AppUI->redirect($redirect);
  82          }
  83      }
  84  }
  85  // delete the file
  86  if ($del) {
  87      $obj->load($file_id);
  88      if (($msg = $obj->delete())) {
  89          $AppUI->setMsg($msg, UI_MSG_ERROR);
  90          $AppUI->redirect();
  91      } else {
  92          if ($not == '1') {
  93              $obj->notify();
  94          }
  95          if ($notcont == '1') {
  96              $obj->notifyContacts();
  97          }
  98          $AppUI->setMsg('deleted', UI_MSG_OK, true);
  99          $AppUI->redirect($redirect);
 100      }
 101  }
 102  
 103  if (!ini_get('safe_mode')) {
 104      set_time_limit(600);
 105  }
 106  ignore_user_abort(1);
 107  
 108  //echo "<pre>";print_r($_POST);echo "</pre>";die;
 109  
 110  $upload = null;
 111  if (isset($_FILES['formfile'])) {
 112      $upload = $_FILES['formfile'];
 113  
 114      if ($upload['size'] < 1) {
 115          if (!$file_id) {
 116              $AppUI->setMsg('Upload file size is zero. Process aborted.', UI_MSG_ERROR);
 117              $AppUI->redirect($redirect);
 118          }
 119      } else {
 120  
 121          // store file with a unique name
 122          $obj->file_name = $upload['name'];
 123          $obj->file_type = $upload['type'];
 124          $obj->file_size = $upload['size'];
 125          $obj->file_date = str_replace("'", '', $db->DBTimeStamp(time()));
 126          $obj->file_real_filename = uniqid(rand());
 127  
 128          $res = $obj->moveTemp($upload);
 129          if (!$res) {
 130              $AppUI->setMsg('File could not be written', UI_MSG_ERROR);
 131              $AppUI->redirect($redirect);
 132          }
 133  
 134      }
 135  }
 136  
 137  // move the file on filesystem if the affiliated project was changed
 138  if ($file_id && ($obj->file_project != $oldObj->file_project)) {
 139      $res = $obj->moveFile($oldObj->file_project, $oldObj->file_real_filename);
 140      if (!$res) {
 141          $AppUI->setMsg('File could not be moved', UI_MSG_ERROR);
 142          $AppUI->redirect($redirect);
 143      }
 144  }
 145  
 146  if (!$file_id) {
 147      $obj->file_owner = $AppUI->user_id;
 148      if (!$obj->file_version_id) {
 149          $q = new DBQuery;
 150          $q->addTable('files');
 151          $q->addQuery('file_version_id');
 152          $q->addOrder('file_version_id DESC');
 153          $q->setLimit(1);
 154          $latest_file_version = $q->loadResult();
 155          $q->clear();
 156          $obj->file_version_id = $latest_file_version + 1;
 157      } else {
 158          $q = new DBQuery;
 159          $q->addTable('files');
 160          $q->addUpdate('file_checkout', '');
 161          $q->addWhere('file_version_id = ' . (int)$obj->file_version_id);
 162          $q->exec();
 163          $q->clear();
 164      }
 165  }
 166  //print_r($obj);die;
 167  if (($msg = $obj->store())) {
 168      $AppUI->setMsg($msg, UI_MSG_ERROR);
 169  } else {
 170  
 171      // Notification
 172      $obj->load($obj->file_id);
 173      if ($not == '1') {
 174          $obj->notify();
 175      }
 176      if ($notcont == '1') {
 177          $obj->notifyContacts();
 178      }
 179  
 180      // Delete the existing (old) file in case of file replacement (through addedit not through c/o-versions)
 181      if (($file_id) && ($upload['size'] > 0)) {
 182          if (($oldObj->deleteFile())) {
 183              $AppUI->setMsg('replaced', UI_MSG_OK, true);
 184          } else {
 185              $AppUI->setMsg($file_id ? 'updated' : 'added' . '; unable to delete existing file', UI_MSG_OK, true);
 186          }
 187      } else {
 188          $AppUI->setMsg($file_id ? 'updated' : 'added', UI_MSG_OK, true);
 189      }
 190  
 191      /* Workaround for indexing large files:
 192      ** Based on the value defined in config data,
 193      ** files with file_size greater than specified limit
 194      ** are not indexed for searching.
 195      ** Negative value :<=> no filesize limit
 196      */
 197      $index_max_file_size = w2PgetConfig('index_max_file_size', 0);
 198      if ($index_max_file_size < 0 || $obj->file_size <= $index_max_file_size * 1024) {
 199          $obj->indexStrings();
 200          $AppUI->setMsg('; ' . $indexed . ' words indexed', UI_MSG_OK, true);
 201      }
 202  }
 203  $AppUI->redirect($redirect);
 204  ?>


Generated: Wed Jan 7 03:00:01 2009 Cross-referenced by PHPXref 0.7