function downloadDocument($bid) { global $_DOCMAN; $database = JFactory::getDBO(); // load document $doc = new mosDMDocument($database); $doc->load($bid); // download file $file = new DOCMAN_File($doc->dmfilename, $_DOCMAN->getCfg('dmpath')); $file->download(); die; // Important! }
function showDocuments($rows, $lists, $search, $pageNav, $number_pending, $number_unpublished, $view_type = 1) { global $database, $my, $_DOCMAN; global $mosConfig_live_site, $mosConfig_absolute_path; ?> <form action="index2.php" method="post" name="adminForm"> <?php dmHTML::adminHeading(_DML_DOCS, 'documents'); ?> <div class="dm_filters"> <?php echo _DML_FILTER; ?> <input class="text_area" type="text" name="search" value="<?php echo $search; ?> " class="inputbox" onChange="document.adminForm.submit();" /> <?php echo $lists['catid']; ?> <span class="small"> <?php if ($number_pending > 0) { echo " [{$number_pending} " . _DML_DOCS_NOT_APPROVED . "] "; } if ($number_unpublished > 0) { echo " [{$number_unpublished} " . _DML_DOCS_NOT_PUBLISHED . "] "; } if ($number_unpublished < 1 && $number_pending < 1) { echo " [" . _DML_NO_PENDING_DOCS . "] "; } ?> </span> </div> <table class="adminlist"> <thead> <tr> <th width="2%" align="left" > <input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?> );" /> </th> <th width="15%" align="left"> <a href="index2.php?option=com_docman§ion=documents&sort=name"><?php echo _DML_NAME; ?> </a> </th> <th width="15%" align="left" > <a href="index2.php?option=com_docman§ion=documents&sort=filename"><?php echo _DML_FILE; ?> </a> </th> <th width="15%" align="left"> <a href="index2.php?option=com_docman§ion=documents&sort=catsubcat"><?php echo _DML_CATEGORY; ?> </a> </th> <th width="10%" align="center"> <a href="index2.php?option=com_docman§ion=documents&sort=date"><?php echo _DML_DATE; ?> </a> </th> <th width="10%"> <?php echo _DML_OWNER; ?> </th> <th width="5%"> <?php echo _DML_PUBLISHED; ?> </th> <th width="5%"> <?php echo _DML_APPROVED; ?> </th> <th width="5%"> <?php echo _DML_SIZE; ?> </th> <th width="5%"> <?php echo _DML_HITS; ?> </th> <th width="5%" nowrap="nowrap"> <?php echo _DML_CHECKED_OUT; ?> </th> </tr> </thead> <tfoot><tr><td colspan="11"><?php echo $pageNav->getListFooter(); ?> </td></tr></tfoot> <tbody> <?php $k = 0; for ($i = 0, $n = count($rows); $i < $n; $i++) { $row =& $rows[$i]; $task = $row->published ? 'unpublish' : 'publish'; $img = $row->published ? 'publish_g.png' : 'publish_x.png'; $alt = $row->published ? _DML_PUBLISHED : _DML_UNPUBLISH; $file = new DOCMAN_File($row->dmfilename, $_DOCMAN->getCfg('dmpath')); ?> <tr class="row<?php echo $k; ?> "> <td width="20"> <?php echo mosHTML::idBox($i, $row->id, $row->checked_out && $row->checked_out != $my->id); ?> </td> <td width="15%"> <?php if ($row->checked_out && $row->checked_out != $my->id) { ?> <?php echo $row->dmname; ?> [ <i><?php echo _DML_CHECKED_OUT; ?> </i> ] <?php } else { ?> <a href="#edit" onclick="return listItemTask('cb<?php echo $i; ?> ','edit')"> <?php echo $row->dmname; ?> </a> <?php } ?> </td> <td> <?php if ($file->exists()) { ?> <a href="index2.php?option=com_docman§ion=documents&task=download&bid=<?php echo $row->id; ?> " target="_blank"> <?php echo DOCMAN_Utils::urlSnippet($row->dmfilename); ?> </a> <?php } else { echo _DML_FILE_MISSING; } ?> </td> <td width="15%"><?php echo $row->treename; ?> </td> <td width="10%" align="center"><?php echo mosFormatDate($row->dmdate_published); ?> </td> <td align="center"><?php echo DOCMAN_Utils::getUserName($row->dmowner); ?> </td> <td width="10%" align="center"> <a href="javascript: void(0);" onclick="return listItemTask('cb<?php echo $i; ?> ','<?php echo $task; ?> ')"> <img src="images/<?php echo $img; ?> " border="0" alt="<?php echo $alt; ?> " /> </a> </td> <?php if (!$row->approved) { ?> <td width="5%" align="center"><a href="#approve" onClick="return listItemTask('cb<?php echo $i; ?> ','approve')"><img src="images/publish_x.png" border=0 alt="approve" /></a></td> <?php } else { ?> <td width="5%" align="center"><img src="images/tick.png" /></td> <?php } ?> <td width="5%" align="center"> <?php if ($file->exists()) { echo $file->getSize(); } ?> </td> <td width="5%" align="center"><?php echo $row->dmcounter; ?> </td> <?php if ($row->checked_out) { ?> <td width="5%" align="center"><?php echo $row->editor; ?> </td> <?php } else { ?> <td width="5%" align="center">---</td> <?php } ?> </tr><?php $k = 1 - $k; } ?> </tbody> </table> <input type="hidden" name="option" value="com_docman" /> <input type="hidden" name="section" value="documents" /> <input type="hidden" name="task" value="" /> <input type="hidden" name="boxchecked" value="0" /> <?php echo DOCMAN_token::render(); ?> </form> <?php include_once $mosConfig_absolute_path . "/components/com_docman/footer.php"; }
function download(&$doc, $inline = false) { global $database, $mosConfig_live_site, $mosConfig_absolute_path, $mosConfig_offset; global $_DOCMAN, $_DMUSER; // global $HTTP_USER_AGENT; require_once $_DOCMAN->getPath('classes', 'file'); $data =& $doc->getDataObject(); /* ------------------------------ * * CORE AUTHORIZATIONS * * ------------------------------ */ // if the user is not authorized to download this document, redirect if (!$_DMUSER->canDownload($doc->getDBObject())) { _returnTo('cat_view', _DML_NOLOG_DOWNLOAD, $data->catid); } // If the document is not approved, redirect if (!$data->approved and !$_DMUSER->canApprove()) { _returnTo('cat_view', _DML_NOAPPROVED_DOWNLOAD, $data->catid); } // If the document is not published, redirect if (!$data->published and !$_DMUSER->canPublish()) { _returnTo('cat_view', _DML_NOPUBLISHED_DOWNLOAD, $data->catid); } // if the document is checked out, redirect if ($data->checked_out && $_DMUSER->userid != $data->checked_out) { _returnTo('cat_view', _DML_NOTDOWN, $data->catid); } // If the remote host is not allowed, show anti-leech message and die. if (!DOCMAN_Utils::checkDomainAuthorization()) { $from_url = parse_url($_SERVER['HTTP_REFERER']); $from_host = trim($from_url['host']); _returnTo('cat_view', _DML_ANTILEECH_ACTIVE . " (" . $from_host . ")", $data->catid); exit; } /* ------------------------------ * * GET FILE * * ------------------------------ */ $file = new DOCMAN_File($data->dmfilename, $_DOCMAN->getCfg('dmpath')); // If the file doesn't exist, redirect if (!$file->exists()) { _returnTo('cat_view', _DML_FILE_UNAVAILABLE, $data->catid); } /* ------------------------------ * * MAMBOT - Setup All Mambots * * ------------------------------ */ $doc_dbo = $doc->getDBObject(); //Fix for PHP 5 $logbot = new DOCMAN_mambot('onLog'); $prebot = new DOCMAN_mambot('onBeforeDownload'); $postbot = new DOCMAN_mambot('onAfterDownload'); $logbot->setParm('document', $doc_dbo); $logbot->setParm('file', $file); $logbot->setParm('user', $_DMUSER); $logbot->copyParm('process', 'download'); $prebot->setParmArray($logbot->getParm()); // Copy the parms over $postbot->setParmArray($logbot->getParm()); /* ------------------------------ * * MAMBOT - PREDOWNLOAD * * ------------------------------ */ $prebot->trigger(); if ($prebot->getError()) { $logbot->copyParm('msg', $prebot->getErrorMsg()); $logbot->copyParm('status', 'LOG_ERROR'); $logbot->trigger(); _returnTo('cat_view', $prebot->getErrorMsg()); } // let's increment the counter $dbobject = $doc->getDBObject(); $dbobject->incrementCounter(); // place an entry in the log if ($_DOCMAN->getCfg('log')) { require_once $_DOCMAN->getPath('classes', 'jbrowser'); $browser =& JBrowser::getInstance($_SERVER['HTTP_USER_AGENT']); $now = date("Y-m-d H:i:s", time("Y-m-d g:i:s") + $mosConfig_offset * 60 * 60); $remote_ip = $_SERVER['REMOTE_ADDR']; $row_log = new mosDMLog($database); $row_log->log_docid = $data->id; $row_log->log_ip = $remote_ip; $row_log->log_datetime = $now; $row_log->log_user = $_DMUSER->userid; $row_log->log_browser = $browser->getBrowser(); $row_log->log_os = $browser->getPlatform(); if (!$row_log->store()) { exit; } } $logbot->copyParm(array('msg' => 'Download Complete', 'status' => 'LOG_OK')); $logbot->trigger(); $file->download($inline); /* ------------------------------ * * MAMBOT - PostDownload * * Currently - we die and no out * * ------------------------------ */ $postbot->trigger(); /* if( $postbot->getError() ){ * $logbot->copyParm( array( 'msg' => $postbot->getErrorMsg() , * 'status'=> 'LOG_ERROR' * ) * ); * $logbot->trigger(); * _returnTo('cat_view',$postbot->getErrorMsg() ); *} */ die; // REQUIRED }