Exemple #1
0
function removeLog($cid)
{
    DOCMAN_token::check() or die('Invalid Token');
    global $database, $_DMUSER;
    $log = new mosDMLog($database);
    $rows = $log->loadRows($cid);
    // For log mambots
    if ($log->remove($cid)) {
        if ($rows) {
            $logbot = new DOCMAN_mambot('onLogDelete');
            $logbot->setParm('user', $_DMUSER);
            $logbot->copyParm('process', 'delete log');
            $logbot->setParm('rows', $rows);
            $logbot->trigger();
            // Delete the logs
        }
        mosRedirect("index2.php?option=com_docman&section=logs");
    }
}
Exemple #2
0
function getSearchResult($gid, $itemid)
{
    global $search_mode, $ordering, $invert_search, $reverse_order, $search_where, $search_phrase, $search_catid;
    $search_mode = ($invert_search ? '-' : '') . $search_mode;
    $searchList = array(array('search_mode' => $search_mode, 'search_phrase' => $search_phrase));
    $ordering = ($reverse_order ? '-' : '') . $ordering;
    $rows = DOCMAN_Docs::search($searchList, $ordering, $search_catid, '', $search_where);
    // This acts as the search header - so they can perform search again
    if (count($rows) == 0) {
        $msg = _DML_NOKEYWORD;
    } else {
        $msg = sprintf(_DML_SEARCH . ' ' . _DML_SEARCH_MATCHES, count($rows));
    }
    $items = array();
    if (count($rows) > 0) {
        foreach ($rows as $row) {
            // onFetchDocument event, type = list
            $bot = new DOCMAN_mambot('onFetchDocument');
            $bot->setParm('id', $row->id);
            $bot->copyParm('type', 'list');
            $bot->trigger();
            if ($bot->getError()) {
                _returnTo('cat_view', $bot->getErrorMsg());
            }
            // load doc
            $doc =& DOCMAN_Document::getInstance($row->id);
            // process content mambots
            DOCMAN_Utils::processContentBots($doc, 'dmdescription');
            $item = new StdClass();
            $item->buttons =& $doc->getLinkObject();
            $item->paths =& $doc->getPathObject();
            $item->data =& $doc->getDataObject();
            $item->data->category = $row->section;
            $items[] = $item;
        }
    }
    return $items;
}
 function transferFileProcess($uid, $step, $url, &$file)
 {
     DOCMAN_token::check() or die('Invalid Token');
     global $_DMUSER, $_DOCMAN;
     if ($file == '') {
         return array('_error' => 1, '_errmsg' => _DML_FILENAME_REQUIRED);
     }
     /* ------------------------------ *
      *   MAMBOT - Setup All Mambots   *
      * ------------------------------ */
     $logbot = new DOCMAN_mambot('onLog');
     $prebot = new DOCMAN_mambot('onBeforeUpload');
     $postbot = new DOCMAN_mambot('onAfterUpload');
     $logbot->setParm('filename', $file);
     $logbot->setParm('user', $_DMUSER);
     $logbot->copyParm('process', 'upload');
     $prebot->setParmArray($logbot->getParm());
     // Copy the parms over
     $postbot->setParmArray($logbot->getParm());
     /* ------------------------------ *
      *   Pre-upload                    *
      * ------------------------------ */
     $prebot->trigger();
     if ($prebot->getError()) {
         $logbot->setParm('msg', $prebot->getErrorMsg());
         $logbot->copyParm('status', 'LOG_ERROR');
         $logbot->trigger();
         return array('_error' => 1, '_errmsg' => $prebot->getErrorMsg());
     }
     /* ------------------------------ *
      *   Upload                        *
      * ------------------------------ */
     $path = $_DOCMAN->getCfg('dmpath') . DS;
     //get file validation settings
     if ($_DMUSER->isSpecial) {
         $validate = _DM_VALIDATE_ADMIN;
     } else {
         if ($_DOCMAN->getCfg('user_all', false)) {
             $validate = _DM_VALIDATE_USER_ALL;
         } else {
             $validate = _DM_VALIDATE_USER;
         }
     }
     //upload the file
     $upload = new DOCMAN_FileUpload();
     $file = $upload->uploadURL($url, $path, $validate, $file);
     /* -------------------------------- *
      *    Post-upload                   *
      * -------------------------------- */
     if (!$file) {
         $msg = _DML_ERROR_UPLOADING . " - " . $upload->_err;
         $logbot->setParm('msg', $msg);
         $logbot->setParm('file', $url);
         $logbot->copyParm('status', 'LOG_ERROR');
         $logbot->trigger();
         return array('_error' => 1, '_errmsg' => $msg);
     }
     $msg = """ . $file->name . "" " . _DML_UPLOADED;
     $logbot->copyParm(array('msg' => $msg, 'status' => 'LOG_OK'));
     $logbot->trigger();
     $postbot->setParm('file', $file);
     $postbot->trigger();
     if ($postbot->getError()) {
         $logbot->setParm('msg', $postbot->getErrorMsg());
         $logbot->copyParm('status', 'LOG_ERROR');
         $logbot->trigger();
         return array('_error' => 1, '_errmsg' => $postbot->getErrorMsg());
     }
     return array('_error' => 0, '_errmsg' => $msg);
 }
 function _format(&$objDBDoc)
 {
     global $_DOCMAN;
     require_once $_DOCMAN->getPath('classes', 'file');
     require_once $_DOCMAN->getPath('classes', 'params');
     require_once $_DOCMAN->getPath('classes', 'mambots');
     $file = new DOCMAN_file($objDBDoc->dmfilename, $_DOCMAN->getCfg('dmpath'));
     $params = new dmParameters($objDBDoc->attribs, '', 'params');
     // format document data
     $this->objFormatData = DOCMAN_Utils::get_object_vars($objDBDoc);
     $this->objFormatData->owner = $this->_formatUserName($objDBDoc->dmowner);
     $this->objFormatData->submited_by = $this->_formatUserName($objDBDoc->dmsubmitedby);
     $this->objFormatData->maintainedby = $this->_formatUserName($objDBDoc->dmmantainedby);
     $this->objFormatData->lastupdatedby = $this->_formatUserName($objDBDoc->dmlastupdateby);
     $this->objFormatData->checkedoutby = $this->_formatUserName($objDBDoc->checked_out);
     $this->objFormatData->filename = $this->_formatFilename($objDBDoc);
     $this->objFormatData->filesize = $file->getSize();
     $this->objFormatData->filetype = $file->ext;
     $this->objFormatData->mime = $file->mime;
     $this->objFormatData->hot = $this->_formatHot($objDBDoc);
     $this->objFormatData->new = $this->_formatNew($objDBDoc);
     $this->objFormatData->state = $this->objFormatData->new . ' ' . $this->objFormatData->hot;
     //for backwards compat with 1.3
     $this->objFormatData->params = $params;
     $this->objFormatData->dmdescription = $objDBDoc->dmdescription;
     $this->objFormatData->permalink = JRoute::_($this->_formatLink('doc_details'));
     // onFetchButtons event
     // plugins should always return an array of Button objects
     $bot = new DOCMAN_mambot('onFetchButtons');
     $bot->setParm('doc', $this);
     $bot->setParm('file', $file);
     $bot->trigger();
     if ($bot->getError()) {
         _returnTo('cat_view', $bot->getErrorMsg());
     }
     $buttons = array();
     foreach ($bot->getReturn() as $return) {
         if (!is_array($return)) {
             $return = array($return);
         }
         $buttons = array_merge($buttons, $return);
     }
     $this->objFormatLink =& $buttons;
     // format document paths
     $this->objFormatPath->icon = DOCMAN_Utils::pathIcon($file->ext . ".png", 1);
     $this->objFormatPath->thumb = DOCMAN_Utils::pathThumb($objDBDoc->dmthumbnail, 1);
 }
Exemple #5
0
function saveDocument($uid)
{
    DOCMAN_token::check() or die('Invalid Token');
    global $database, $_DMUSER;
    //fetch params
    $params = mosGetParam($_REQUEST, 'params', '');
    if (is_array($params)) {
        $txt = array();
        foreach ($params as $k => $v) {
            $txt[] = "{$k}={$v}";
        }
        $_POST['attribs'] = implode("\n", $txt);
    }
    $doc = new mosDMDocument($database);
    $doc->load($uid);
    // Load from id
    $doc->bind($_POST);
    /* ------------------------------ *
     *   MAMBOT - Setup All Mambots   *
     * ------------------------------ */
    $logbot = new DOCMAN_mambot('onLog');
    $postbot = new DOCMAN_mambot('onAfterEditDocument');
    $logbot->setParm('document', $doc);
    $logbot->setParm('file', $_POST['dmfilename']);
    $logbot->setParm('user', $_DMUSER);
    if (!$uid) {
        $logbot->copyParm('process', 'new document');
    } else {
        $logbot->copyParm('process', 'edit document');
    }
    $logbot->copyParm('new', !$uid);
    $postbot->setParmArray($logbot->getParm());
    $postbot->trigger();
    if ($postbot->getError()) {
        $logbot->copyParm('msg', $postbot->getErrorMsg());
        $logbot->copyParm('status', 'LOG_ERROR');
        $logbot->trigger();
        _returnTo('cat_view', $postbot->getErrorMsg());
    }
    // let's indicate last update information to store
    if ($doc->save()) {
        $logbot->copyParm('msg', 'Document saved');
        $logbot->copyParm('status', 'LOG_OK');
        $logbot->trigger();
        // if submited for the first time lets do auto-approve/publish operations
        if (!$uid) {
            autoApprove($doc);
            autoPublish($doc);
        }
        /* removed $message: undefined
         * original code:
         * _returnTo('cat_view', _DML_THANKSDOCMAN . $message ? "<br />" . $message : '', $doc->catid);
         */
        _returnTo('cat_view', _DML_THANKSDOCMAN, $doc->catid);
    }
    // doc->save failed. Log error
    $logbot->copyParm('msg', $doc->getError());
    $logbot->copyParm('status', 'LOG_ERROR');
    $logbot->trigger();
    _returnTo('cat_view', _DML_PROBLEM_SAVING_DOCUMENT);
}
function saveDocument($uid)
{
    DOCMAN_token::check() or die('Invalid Token');
    global $_DOCMAN, $_DMUSER;
    jimport('joomla.filesystem.file');
    $database = JFactory::getDBO();
    //fetch params
    $params = JRequest::getVar('params', array(), 'request', 'array');
    if (is_array($params)) {
        $txt = array();
        foreach ($params as $k => $v) {
            $txt[] = "{$k}={$v}";
        }
        $_POST['attribs'] = implode("\n", $txt);
    }
    $doc = new mosDMDocument($database);
    $doc->load(JRequest::getInt('id'));
    // get the uploaded filename from the session
    $session = JFactory::getSession();
    if ($session->get('docman.dmfilename')) {
        $_POST['dmfilename'] = $session->get('docman.dmfilename');
        $_POST['document_url'] = $session->get('docman.document_url');
    } else {
        $_POST['dmfilename'] = $doc->dmfilename;
        unset($_POST['document_url']);
    }
    $doc->bind(DOCMAN_Utils::stripslashes($_POST));
    // plugins
    $logbot = new DOCMAN_mambot('onLog');
    $postbot = new DOCMAN_mambot('onAfterEditDocument');
    $logbot->setParm('document', $doc);
    $logbot->setParm('file', $_POST['dmfilename']);
    $logbot->setParm('user', $_DMUSER);
    if (!$uid) {
        $logbot->copyParm('process', 'new document');
    } else {
        $logbot->copyParm('process', 'edit document');
    }
    $logbot->copyParm('new', !$uid);
    $postbot->setParmArray($logbot->getParm());
    // let's indicate last update information to store
    if ($doc->save()) {
        $session->set('docman.dmfilename', null);
        $session->set('docman.document_url', null);
        $logbot->copyParm('msg', 'Document saved');
        $logbot->copyParm('status', 'LOG_OK');
        $logbot->trigger();
        // if submited for the first time lets do auto-approve/publish operations
        if (!$uid) {
            autoApprove($doc);
            autoPublish($doc);
        }
        // If document is saved, trigger the postbot.
        $postbot->trigger();
        if ($postbot->getError()) {
            $logbot->copyParm('msg', $postbot->getErrorMsg());
            $logbot->copyParm('status', 'LOG_ERROR');
            $logbot->trigger();
            _returnTo('cat_view', $postbot->getErrorMsg());
        }
        _returnTo('cat_view', _DML_THANKSDOCMAN, $doc->catid);
    }
    // doc->save failed. Log error
    $logbot->copyParm('msg', $doc->getError());
    $logbot->copyParm('status', 'LOG_ERROR');
    $logbot->trigger();
    _returnTo('cat_view', _DML_PROBLEM_SAVING_DOCUMENT);
}
Exemple #7
0
function saveDocument()
{
    DOCMAN_token::check() or die('Invalid Token');
    global $task, $_DMUSER;
    $database = JFactory::getDBO();
    $mainframe = JFactory::getApplication();
    //fetch current id
    $cid = JRequest::getInt('cid', 0, 'post');
    //fetch params
    $params = JRequest::getVar('params', array(), 'post', 'array');
    if (is_array($params)) {
        $txt = array();
        foreach ($params as $k => $v) {
            $txt[] = "{$k}={$v}";
        }
        $_POST['attribs'] = implode("\n", $txt);
    }
    $doc = new mosDMDocument($database);
    // Create record
    $doc->load($cid);
    // Load from id
    $doc->bind(DOCMAN_Utils::stripslashes($_POST));
    /* ------------------------------ *
     *   MAMBOT - Setup All Mambots   *
     * ------------------------------ */
    $logbot = new DOCMAN_mambot('onLog');
    $postbot = new DOCMAN_mambot('onAfterEditDocument');
    $logbot->setParm('document', $doc);
    $logbot->setParm('file', DOCMAN_Utils::stripslashes($_POST['dmfilename']));
    $logbot->setParm('user', $_DMUSER);
    if (!$cid) {
        $logbot->copyParm('process', 'new document');
    } else {
        $logbot->copyParm('process', 'edit document');
    }
    $logbot->copyParm('new', !$cid);
    $postbot->setParmArray($logbot->getParm());
    $postbot->trigger();
    if ($postbot->getError()) {
        $logbot->copyParm('msg', $postbot->getErrorMsg());
        $logbot->copyParm('status', 'LOG_ERROR');
        $logbot->trigger();
        $mainframe->redirect("index.php?option=com_docman&section=documents", $postbot->getErrorMsg());
    }
    if ($doc->save()) {
        // Update from browser
        $logbot->copyParm('msg', 'Document saved');
        $logbot->copyParm('status', 'LOG_OK');
        $logbot->trigger();
        if ($task == 'save') {
            $url = 'index.php?option=com_docman&section=documents';
        } else {
            // $task = 'apply'
            $url = 'index.php?option=com_docman&section=documents&task=edit&cid[0]=' . $doc->id;
        }
        $mainframe->redirect($url, _DML_SAVED_CHANGES);
    }
    $logbot->copyParm('msg', $doc->getError());
    $logbot->copyParm('status', 'LOG_ERROR');
    $logbot->trigger();
    $mainframe->redirect('index.php?option=com_docman&section=documents', $doc->getError());
}
Exemple #8
0
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
}