[ Index ]

Source Code Reference for V1.00

title

Body

[close]

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

   1  <?php /* $Id: addedit.php 156 2008-04-11 15:47:40Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/files/addedit.php $ */
   2  if (!defined('W2P_BASE_DIR')) {
   3      die('You should not access this file directly.');
   4  }
   5  
   6  $folder = intval(w2PgetParam($_GET, 'folder', 0));
   7  $file_id = intval(w2PgetParam($_GET, 'file_id', 0));
   8  $ci = w2PgetParam($_GET, 'ci', 0) == 1 ? true : false;
   9  $preserve = $w2Pconfig['files_ci_preserve_attr'];
  10  
  11  // check permissions for this record
  12  $perms = &$AppUI->acl();
  13  $canAuthor = $perms->checkModule('files', 'add');
  14  $canEdit = $perms->checkModuleItem('files', 'edit', $file_id);
  15  
  16  // check permissions
  17  if (!$canAuthor && !$file_id) {
  18      $AppUI->redirect('m=public&a=access_denied');
  19  }
  20  
  21  if (!$canEdit && $file_id) {
  22      $AppUI->redirect('m=public&a=access_denied');
  23  }
  24  
  25  if (file_exists(W2P_BASE_DIR . '/modules/helpdesk/config.php')) {
  26      include (W2P_BASE_DIR . '/modules/helpdesk/config.php');
  27  }
  28  $canAdmin = $perms->checkModule('system', 'edit');
  29  // add to allow for returning to other modules besides Files
  30  $referrerArray = parse_url($_SERVER['HTTP_REFERER']);
  31  $referrer = $referrerArray['query'] . $referrerArray['fragment'];
  32  
  33  // load the companies class to retrieved denied companies
  34  require_once ($AppUI->getModuleClass('companies'));
  35  require_once ($AppUI->getModuleClass('projects'));
  36  require_once $AppUI->getModuleClass('tasks');
  37  
  38  $file_task = intval(w2PgetParam($_GET, 'file_task', 0));
  39  $file_parent = intval(w2PgetParam($_GET, 'file_parent', 0));
  40  $file_project = intval(w2PgetParam($_GET, 'project_id', 0));
  41  $file_helpdesk_item = intval(w2PgetParam($_GET, 'file_helpdesk_item', 0));
  42  
  43  $q = &new DBQuery;
  44  
  45  // check if this record has dependencies to prevent deletion
  46  $msg = '';
  47  $obj = new CFile();
  48  $canDelete = $obj->canDelete($msg, $file_id);
  49  
  50  // load the record data
  51  // $obj = null;
  52  if ($file_id > 0 && !$obj->load($file_id)) {
  53      $AppUI->setMsg('File');
  54      $AppUI->setMsg('invalidID', UI_MSG_ERROR, true);
  55      $AppUI->redirect();
  56  }
  57  if ($file_id > 0) {
  58      // Check to see if the task or the project is also allowed.
  59      if ($obj->file_task) {
  60          if (!$perms->checkModuleItem('tasks', 'view', $obj->file_task)) {
  61              $AppUI->redirect('m=public&a=access_denied');
  62          }
  63      }
  64      if ($obj->file_project) {
  65          if (!$perms->checkModuleItem('projects', 'view', $obj->file_project)) {
  66              $AppUI->redirect('m=public&a=access_denied');
  67          }
  68      }
  69  }
  70  
  71  if ($obj->file_checkout != $AppUI->user_id) {
  72      $ci = false;
  73  }
  74  
  75  if (!$canAdmin)
  76      $canAdmin = $obj->canAdmin();
  77  
  78  if ($obj->file_checkout == 'final' && !$canAdmin) {
  79      $AppUI->redirect('m=public&a=access_denied');
  80  }
  81  // setup the title block
  82  $ttl = $file_id ? 'Edit File' : 'Add File';
  83  $ttl = $ci ? 'Checking in' : $ttl;
  84  $titleBlock = new CTitleBlock($ttl, 'folder5.png', $m, $m . '.' . $a);
  85  $titleBlock->addCrumb('?m=files', 'files list');
  86  if ($canDelete && $file_id > 0 && !$ci) {
  87      $titleBlock->addCrumbDelete('delete file', $canDelete, $msg);
  88  }
  89  $titleBlock->show();
  90  
  91  //Clear the file id if checking out so a new version is created.
  92  if ($ci) {
  93      $file_id = 0;
  94  }
  95  
  96  if ($obj->file_project) {
  97      $file_project = $obj->file_project;
  98  }
  99  if ($obj->file_task) {
 100      $file_task = $obj->file_task;
 101      $task_name = $obj->getTaskName();
 102  } else
 103      if ($file_task) {
 104          $q = new DBQuery;
 105          $q->addTable('tasks');
 106          $q->addQuery('task_name');
 107          $q->addWhere('task_id=' . $file_task);
 108          $task_name = $q->loadResult();
 109          $q->clear();
 110      } else {
 111          $task_name = '';
 112      }
 113      if ($obj->file_helpdesk_item) {
 114          $file_helpdesk_item = $obj->file_helpdesk_item;
 115      }
 116  
 117  $extra = array('where' => 'project_active = 1');
 118  $project = new CProject();
 119  $projects = $project->getAllowedRecords($AppUI->user_id, 'projects.project_id,project_name', 'project_name', null, $extra, 'projects');
 120  $projects = arrayMerge(array('0' => $AppUI->_('None', UI_OUTPUT_RAW)), $projects);
 121  
 122  $folders = getFolderSelectList();
 123  ?>
 124  <script language="javascript">
 125  function submitIt() {
 126      var f = document.uploadFrm;
 127      f.submit();
 128  }
 129  function delIt() {
 130      if (confirm( '<?php echo $AppUI->_('filesDelete', UI_OUTPUT_JS); ?>' )) {
 131          var f = document.uploadFrm;
 132          f.del.value='1';
 133          f.submit();
 134      }
 135  }
 136  function popTask() {
 137      var f = document.uploadFrm;
 138      if (f.file_project.selectedIndex == 0) {
 139          alert( '<?php echo $AppUI->_('Please select a project first!', UI_OUTPUT_JS); ?>' );
 140      } else {
 141          window.open('./index.php?m=public&a=selector&dialog=1&callback=setTask&table=tasks&task_project=' + f.file_project.options[f.file_project.selectedIndex].value, 'task','left=50,top=50,height=250,width=400,resizable')
 142      }
 143  }
 144  
 145  function finalCI() {
 146      var f = document.uploadFrm;
 147      if (f.final_ci.value == '1') {
 148          f.file_checkout.value = 'final';
 149          f.file_co_reason.value = 'Final Version';
 150      } else {
 151          f.file_checkout.value = '';
 152          f.file_co_reason.value = '';
 153      }
 154  }
 155  
 156  // Callback function for the generic selector
 157  function setTask( key, val ) {
 158      var f = document.uploadFrm;
 159      if (val != '') {
 160          f.file_task.value = key;
 161          f.task_name.value = val;
 162      } else {
 163          f.file_task.value = '0';
 164          f.task_name.value = '';
 165      }
 166  }
 167  </script>
 168  
 169  <form name="uploadFrm" action="?m=files" enctype="multipart/form-data" method="post">
 170      <input type="hidden" name="dosql" value="do_file_aed" />
 171      <input type="hidden" name="del" value="0" />
 172      <input type="hidden" name="file_id" value="<?php echo $file_id; ?>" />
 173      <input type="hidden" name="file_version_id" value="<?php echo $obj->file_version_id; ?>" />
 174      <input type="hidden" name="redirect" value="<?php echo $referrer; ?>" />
 175      <input type="hidden" name="file_helpdesk_item" value="<?php echo $file_helpdesk_item; ?>" />
 176  <table width="100%" border="0" cellpadding="3" cellspacing="3" class="std">
 177  <tr>
 178      <td width="100%" valign="top" align="center">
 179          <table cellspacing="1" cellpadding="2" width="60%">
 180          <tr>
 181              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Folder'); ?>:</td>
 182              <?php if ($file_id == 0 && !$ci) { ?>
 183                  <td align="left"><?php echo arraySelectTree($folders, 'file_folder', 'style="width:175px;" class="text"', ($file_helpdesk_item ? getHelpdeskFolder() : $folder)); ?></td>
 184              <?php } else { ?>
 185                  <td align="left"><?php echo arraySelectTree($folders, 'file_folder', 'style="width:175px;" class="text"', ($file_helpdesk_item ? getHelpdeskFolder() : $obj->file_folder)); ?></td>
 186              <?php } ?>
 187          </tr>        
 188      <?php if ($file_id) { ?>
 189          <tr>
 190              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('File Name'); ?>:</td>
 191              <td align="left" class="hilite"><?php echo strlen($obj->file_name) == 0 ? 'n/a' : $obj->file_name; ?></td>
 192              <td>
 193                  <a href="./fileviewer.php?file_id=<?php echo $obj->file_id; ?>"><?php echo $AppUI->_('download'); ?></a>
 194              </td>
 195          </tr>
 196          <tr valign="top">
 197              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Type'); ?>:</td>
 198              <td align="left" class="hilite"><?php echo $obj->file_type; ?></td>
 199          </tr>
 200          <tr>
 201              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Size'); ?>:</td>
 202              <td align="left" class="hilite"><?php echo $obj->file_size; ?></td>
 203          </tr>
 204          <tr>
 205              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Uploaded By'); ?>:</td>
 206              <td align="left" class="hilite"><?php echo $obj->getOwner(); ?></td>
 207          </tr>
 208      <?php }
 209  echo file_show_attr(); ?>
 210          <tr>
 211              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Description'); ?>:</td>
 212              <td align="left">
 213                  <textarea name="file_description" class="textarea" rows="4" style="width:270px"><?php echo $obj->file_description; ?></textarea>
 214              </td>
 215          </tr>
 216          <tr>
 217              <td colspan="2">
 218              <?php
 219  // TODO - Add custom fields to files, doesnt make sense without a detail view.
 220  /*
 221  require_once($AppUI->getSystemClass( 'CustomFields' ));
 222  $custom_fields = New CustomFields( $m, $a, $obj->file_id, "edit" );
 223  $custom_fields->printHTML();
 224  */
 225  ?>
 226              </td>
 227          <tr>
 228              <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Upload File'); ?>:</td>
 229              <td align="left"><input type="File" name="formfile" style="width:270px" /></td>
 230          </tr>
 231                  <?php if ($ci || ($canAdmin && $obj->file_checkout == 'final')) {
 232  ?>
 233          <tr>
 234              <td align="right" nowrap="nowrap">&nbsp;</td>
 235              <td align="left"><input type="checkbox" name="final_ci" id="final_ci" onclick="finalCI()" /><label for="final_ci"><?php echo $AppUI->_('Final Version'); ?></label></td>        
 236          </tr>
 237                  <?php } ?>
 238          <tr>
 239              <td align="right" nowrap="nowrap">&nbsp;</td>
 240              <td align="left"><input type="checkbox" name="notify" id="notify" checked="checked" /><label for="notify"><?php echo $AppUI->_('Notify Assignees of Task or Project Owner by Email'); ?></label></td>        
 241          </tr>
 242          
 243          </table>
 244      </td>
 245  </tr>
 246  <tr>
 247      <td>
 248          <input class="button" type="button" name="cancel" value="<?php echo $AppUI->_('cancel'); ?>" onclick="javascript:if(confirm('<?php echo $AppUI->_('Are you sure you want to cancel?', UI_OUTPUT_JS); ?>')){location.href = '?<?php echo $AppUI->getPlace(); ?>'; }" />
 249      </td>
 250      <td align="right">
 251          <input type="button" class="button" value="<?php echo $AppUI->_('submit'); ?>" onclick="submitIt()" />
 252      </td>
 253  </tr>
 254  </form>
 255  </table>
 256  
 257  <?php
 258  function file_show_attr() {
 259      global $AppUI, $obj, $ci, $canAdmin, $projects, $file_project, $file_task, $task_name, $preserve, $file_helpdesk_item;
 260  
 261      if ($ci) {
 262          $str_out = '<tr><td align="right" nowrap="nowrap">' . $AppUI->_('Minor Revision') . '</td><td><input type="Radio" name="revision_type" value="minor" checked />' . '</td><tr><td align="right" nowrap="nowrap">' . $AppUI->_('Major Revision') . '</td><td><input type="Radio" name="revision_type" value="major" /></td>';
 263      } else {
 264          $str_out = '<tr><td align="right" nowrap="nowrap">' . $AppUI->_('Version') . ':</td>';
 265      }
 266  
 267      $str_out .= '<td align="left">';
 268  
 269      if ($ci || ($canAdmin && $obj->file_checkout == 'final')) {
 270          $str_out .= '<input type="hidden" name="file_checkout" value="" /><input type="hidden" name="file_co_reason" value="" />';
 271      }
 272  
 273      if ($ci) {
 274          $the_value = (strlen($obj->file_version) > 0 ? $obj->file_version + 0.01 : '1');
 275          $str_out .= '<input type="hidden" name="file_version" value="' . $the_value . '" />';
 276      } else {
 277          $the_value = (strlen($obj->file_version) > 0 ? $obj->file_version : '1');
 278          $str_out .= '<input type="text" name="file_version" maxlength="10" size="5" value="' . $the_value . '" />';
 279      }
 280  
 281      $str_out .= '</td>';
 282  
 283      $select_disabled = ' ';
 284      $onclick_task = ' onclick="popTask()" ';
 285      if ($ci && $preserve) {
 286          $select_disabled = ' disabled="disabled" ';
 287          $onclick_task = ' ';
 288          // need because when a html is disabled, it's value it's not sent in submit
 289          $str_out .= '<input type="hidden" name="file_project" value="' . $file_project . '" />';
 290          $str_out .= '<input type="hidden" name="file_category" value="' . $obj->file_category . '" />';
 291      }
 292  
 293      // Category
 294      $str_out .= '<tr><td align="right" nowrap="nowrap">' . $AppUI->_('Category') . ':</td>';
 295      $str_out .= '<td align="left">' . arraySelect(w2PgetSysVal('FileType'), 'file_category', '' . $select_disabled, $obj->file_category, true) . '<td>';
 296  
 297      // ---------------------------------------------------------------------------------
 298  
 299      if ($file_helpdesk_item) {
 300          $hd_item = new CHelpDeskItem();
 301          $hd_item->load($file_helpdesk_item);
 302          //Helpdesk Item
 303          $str_out .= '<tr><td align="right" nowrap="nowrap">' . $AppUI->_('Helpdesk Item') . ':</td>';
 304          $str_out .= '<td align="left"><strong>' . $hd_item->item_id . ' - ' . $hd_item->item_title . '</strong></td></tr>';
 305          // Project
 306          $str_out .= '<input type="hidden" name="file_project" value="' . $file_project . '" />';
 307  
 308          // Task
 309          $str_out .= '<input type="hidden" name="file_task" value="0" />';
 310      } else {
 311          // Project
 312          $str_out .= '<tr><td align="right" nowrap="nowrap">' . $AppUI->_('Project') . ':</td>';
 313          $str_out .= '<td align="left">' . projectSelectWithOptGroup($AppUI->user_id, 'file_project', 'size="1" class="text" style="width:270px"' . $select_disabled, $file_project) . '</td></tr>';
 314  
 315          // ---------------------------------------------------------------------------------
 316  
 317          // Task
 318          $str_out .= '<tr><td align="right" nowrap="nowrap">' . $AppUI->_('Task') . ':</td><td align="left" colspan="2" valign="top"><input type="hidden" name="file_task" value="' . $file_task . '" /><input type="text" class="text" name="task_name" value="' . $task_name . '" size="40" disabled /><input type="button" class="button" value="' . $AppUI->_('select task') . '..."' . $onclick_task . '/></td></tr>';
 319      }
 320  
 321      return ($str_out);
 322  }
 323  
 324  function getHelpdeskFolder() {
 325      $q = new DBQuery();
 326      $q->addTable('file_folders', 'ff');
 327      $q->addQuery('file_folder_id');
 328      $q->addWhere('ff.file_folder_name = \'Helpdesk\'');
 329      $ffid = $q->loadResult();
 330      $q->clear();
 331      return intval($ffid);
 332  }
 333  
 334  ?>


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