You are here

function template_preprocess_filedepot_filedetail in filedepot 6

Same name and namespace in other branches
  1. 7 lib-theme.php \template_preprocess_filedepot_filedetail()

File

./lib-theme.php, line 450
lib-theme.php Theme support functions for the module

Code

function template_preprocess_filedepot_filedetail(&$variables) {
  $filedepot = filedepot_filedepot();
  $nexcloud = filedepot_nexcloud();
  $fid = $variables['fid'];
  $variables['site_url'] = base_path();
  $variables['ajax_server_url'] = url('filedepot_ajax');
  $variables['LANG_tags'] = t('Tags');
  $variables['LANG_size'] = t('Size');
  $variables['LANG_author'] = t('Author');
  $variables['LANG_folder'] = t('Folder');
  $variables['LANG_description'] = t('Description');
  $variables['LANG_version_note'] = t('Version Note');
  $variables['LANG_download'] = t('Download File');
  $variables['LANG_link_message'] = t('Direct link to file');
  $variables['LANG_lastupated'] = t('Last Updated');
  if ($variables['reportmode'] == 'approvals') {
    $sql = "SELECT file.cid,file.title,file.fname,file.date,file.version,file.size, ";
    $sql .= "file.description,file.submitter,file.status,file.version_note as notes,tags ";
    $sql .= "FROM {filedepot_filesubmissions} file ";
    $sql .= "WHERE file.id=%d";
  }
  elseif ($variables['reportmode'] == 'incoming') {
    $sql = "SELECT 0,file.orig_filename as title,file.orig_filename as fname,file.timestamp,1,file.size, ";
    $sql .= "file.description,file.uid,9,file.version_note,'' ";
    $sql .= "FROM {filedepot_import_queue} file ";
    $sql .= "WHERE file.id=%d";
  }
  else {
    $sql = "SELECT file.cid, file.title, file.fname, file.date, file.version, file.size, ";
    $sql .= "file.description, file.submitter, file.status, v.notes, '' as tags ";
    $sql .= "FROM {filedepot_files} file ";
    $sql .= "LEFT JOIN {filedepot_fileversions} v ON v.fid=file.fid ";
    $sql .= "WHERE file.fid=%d ORDER BY v.version DESC LIMIT 1";
  }
  $filedetail = FALSE;
  $query = db_query($sql, $fid);
  $A = db_fetch_array($query);
  if ($A != NULL) {
    list($cid, $title, $fname, $date, $cur_version, $size, $description, $submitter, $status, $cur_notes, $tags) = array_values($A);
    $variables['cid'] = $cid;
    $variables['shortdate'] = strftime($filedepot->shortdate, $date);
    $variables['size'] = filedepot_formatFileSize($size);
    $icon = $filedepot
      ->getFileIcon($fname);
    $variables['fileicon'] = "{$variables['layout_url']}/css/images/{$icon}";
    $author = db_result(db_query("SELECT name FROM {users} WHERE uid=%d", $submitter));
    $catname = db_result(db_query("SELECT name FROM {filedepot_categories} WHERE cid=%d", $cid));
    $nid = db_result(db_query("SELECT nid FROM {filedepot_categories} WHERE cid=%d", $cid));
    $variables['fname'] = filter_xss($fname);
    $variables['current_version'] = "(V{$cur_version})";
    $variables['filetitle'] = filter_xss($title);
    $variables['author'] = $author;
    $variables['description'] = nl2br(filter_xss($description));
    $variables['foldername'] = filter_xss($catname);
    $variables['current_ver_note'] = nl2br(filter_xss($cur_notes));
    $variables['tags'] = $nexcloud
      ->get_itemtags($fid);
    if ($status == FILEDEPOT_UNAPPROVED_STATUS) {
      $variables['status_image'] = '<img src="' . $variables['layout_url'] . '/css/images/padlock.gif">';
      $variables['statusmessage'] = '* ' . t('File Submission to Approve');
    }
    elseif ($status == FILEDEPOT_INCOMING_STATUS) {
      $variables['status_image'] = '&nbsp;';
      $variables['statusmessage'] = '* ' . t('Incoming File - needs to be moved or deleted');
      $variables['disable_download'] = 'onClick="return false;"';
    }
    elseif ($status == FILEDEPOT_LOCKED_STATUS) {
      $stat_userid = db_result(db_query("SELECT status_changedby_uid FROM {filedepot_files} WHERE fid=%d", $fid));
      $stat_user = db_result(db_query("SELECT name FROM {users} WHERE uid=%d", $stat_userid));
      $variables['status_image'] = '<img src="' . $variables['layout_url'] . '/css/images/padlock.gif">';
      $variables['statusmessage'] = '* ' . t('Locked by %name', array(
        '%name' => $stat_user,
      ));
      $variables['LANG_DOWNLOAD_MESSAGE'] = t('File Locked by: %name', array(
        '%name' => $stat_user,
      ));
      $variables['disable_download'] = 'onClick="return FALSE;"';
    }
    else {
      $variables['show_statusmsg'] = 'none';
      $variables['status_image'] = '&nbsp;';
      $variables['statusmessage'] = '&nbsp;';
    }
    if (function_exists(spaces_get_space)) {
      $space = spaces_get_space();
      if ($space && $space->type === 'og') {
        $urlprefix = '';
        switch (variable_get('purl_method_spaces_og', 'path')) {
          case 'path':
            $urlprefix = "{$space->group->purl}";
            break;
          case 'pair':
            $urlprefix = "{$key}/{$space->id}";
            break;
        }
      }
    }
    if (isset($urlprefix) and !empty($urlprefix)) {
      $variables['download_url'] = base_path() . "index.php?q={$urlprefix}/filedepot&cid={$cid}&fid={$fid}";
    }
    else {
      $variables['download_url'] = base_path() . "index.php?q=filedepot&cid={$cid}&fid={$fid}";
    }

    // Retrieve file versions
    $sql = "SELECT fid,fname,version,notes,size,date,uid FROM {filedepot_fileversions} " . "WHERE fid=%d AND version < %d ORDER by version DESC";
    $query = db_query($sql, $fid, $cur_version);
    $version_records = '';
    if ($query) {
      while ($rec = db_fetch_array($query)) {
        $rec['nid'] = $nid;
        $version_records .= theme('filedepot_fileversion', $rec);
      }
    }
    $variables['version_records'] = $version_records;
  }
}