예제 #1
0
function fetchEditDocumentForm($uid, $filename = null, $catid = 0)
{
    global $_DOCMAN, $_DMUSER;
    $database = JFactory::getDBO();
    $doc = new mosDMDocument($database);
    if ($uid) {
        $doc->load($uid);
        //Load the document
        //check user permissions
        $err = $_DMUSER->canPreformTask($doc, 'Edit');
        if ($err) {
            _returnTo('cat_view', $err, $doc->catid);
        }
    } else {
        $doc->init_record();
        //Initialise a document
        //check user permissions
        $err = $_DMUSER->canPreformTask($doc, 'Upload');
        if ($err) {
            _returnTo('cat_view', $err, $doc->catid);
        }
    }
    //checkout the document
    $doc->checkout($_DMUSER->userid);
    // Set document filename
    if (!is_null($filename)) {
        $filename = DOCMAN_Utils::safeDecodeURL($filename);
        $doc->dmfilename = $filename;
    }
    // Set document url
    $prefix = substr($doc->dmfilename, 0, _DM_DOCUMENT_LINK_LNG);
    if (strcasecmp($prefix, _DM_DOCUMENT_LINK) == 0) {
        $doc->dmlink = substr($doc->dmfilename, _DM_DOCUMENT_LINK_LNG);
        $doc->dmfilename = _DM_DOCUMENT_LINK;
    }
    $lists = array();
    // Set filename
    $lists['dmfilename'] = filesSelectList($doc, 'class="inputbox" size="1" disabled="disabled"');
    // Built category select list
    $options = array(JHTML::_('select.option', '0', _DML_SELECT_CAT));
    if ($uid) {
        $lists['catid'] = dmHTML::categoryList($doc->catid, "", $options);
    } else {
        $lists['catid'] = dmHTML::categoryList($catid, "", $options);
    }
    // Build select lists
    $lists['approved'] = JHTML::_('select.booleanlist', 'approved', 'class="inputbox"', $doc->approved, _DML_YES, _DML_NO);
    $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $doc->published, _DML_YES, _DML_NO);
    $lists['viewer'] = dmHTML::viewerList($doc, 'dmowner');
    $lists['maintainer'] = dmHTML::maintainerList($doc, 'dmmantainedby');
    $lists['licenses'] = licenseSelectList($doc);
    $lists['licenses_display'] = licenseDisplayList($doc);
    // Built image list
    $lists['dmthumbnail'] = dmHTML::imageList('dmthumbnail', $doc->dmthumbnail);
    $lists['dmthumbnail_preview'] = $doc->dmthumbnail;
    // Find lastupdate user
    $last = array();
    if ($doc->dmlastupdateby > _DM_PERMIT_USER) {
        $last[0] = DOCMAN_users::get($doc->dmlastupdateby);
        // the array is for BC 1.5.2, could be refactored in 1.6
    } else {
        $last[0]->name = "Super Administrator";
    }
    // Find createdby user
    $created = array();
    if ($doc->dmsubmitedby > _DM_PERMIT_USER) {
        $created[0] = DOCMAN_users::get($doc->dmsubmitedby);
        // the array is for BC 1.5.2, could be refactored in 1.6
    } else {
        $created[0]->name = "Super Administrator";
    }
    // update 'dmlastupdateon'
    $doc->dmlastupdateon = date("Y-m-d H:i:s");
    // Params definitions
    $params = null;
    $params_path = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_docman' . DS . 'docman.params.xml';
    if (file_exists($params_path)) {
        $params = new dmParameters($doc->attribs, $params_path, 'params');
    }
    /* ------------------------------ *
     *   MAMBOT - Setup All Mambots   *
     * ------------------------------ */
    $prebot = new DOCMAN_mambot('onBeforeEditDocument');
    $prebot->setParm('document', $doc);
    $prebot->setParm('filename', $filename);
    $prebot->setParm('user', $_DMUSER);
    if (!$uid) {
        $prebot->copyParm('process', 'new document');
    } else {
        $prebot->copyParm('process', 'edit document');
    }
    $prebot->trigger();
    if ($prebot->getError()) {
        _returnTo('cat_view', $prebot->getErrorMsg());
    }
    return HTML_DMDocuments::editDocumentForm($doc, $lists, $last, $created, $params);
}
예제 #2
0
function fetchEditDocumentForm($uid, $filename = null, $catid = 0)
{
    global $database, $mosConfig_absolute_path;
    global $_DOCMAN, $_DMUSER;
    $doc = new mosDMDocument($database);
    if ($uid) {
        $doc->load($uid);
        //Load the document
        //check user permissions
        $err = $_DMUSER->canPreformTask($doc, 'Edit');
        if ($err) {
            _returnTo('cat_view', $err, $doc->catid);
        }
    } else {
        $doc->init_record();
        //Initialise a document
        //check user permissions
        $err = $_DMUSER->canPreformTask($doc, 'Upload');
        if ($err) {
            _returnTo('cat_view', $err, $doc->catid);
        }
    }
    //checkout the document
    $doc->checkout($_DMUSER->userid);
    // Set document filename
    if (!is_null($filename)) {
        $filename = DOCMAN_Utils::safeDecodeURL($filename);
        $doc->dmfilename = $filename;
    }
    // Set document url
    $prefix = substr($doc->dmfilename, 0, _DM_DOCUMENT_LINK_LNG);
    if (strcasecmp($prefix, _DM_DOCUMENT_LINK) == 0) {
        $doc->dmlink = substr($doc->dmfilename, _DM_DOCUMENT_LINK_LNG);
        $doc->dmfilename = _DM_DOCUMENT_LINK;
    }
    $lists = array();
    // Set filename
    $lists['dmfilename'] = filesSelectList($doc);
    // Built category select list
    $options = array(mosHTML::makeOption('0', _DML_SELECT_CAT));
    if ($uid) {
        $lists['catid'] = dmHTML::categoryList($doc->catid, "", $options);
    } else {
        $lists['catid'] = dmHTML::categoryList($catid, "", $options);
    }
    // Build select lists
    $lists['approved'] = mosHTML::yesnoRadioList('approved', 'class="inputbox"', $doc->approved);
    $lists['published'] = mosHTML::yesnoRadioList('published', 'class="inputbox"', $doc->published);
    $lists['viewer'] = dmHTML::viewerList($doc, 'dmowner');
    $lists['maintainer'] = dmHTML::maintainerList($doc, 'dmmantainedby');
    $lists['licenses'] = licenseSelectList($doc);
    $lists['licenses_display'] = licenseDisplayList($doc);
    // Built image list
    $lists['dmthumbnail'] = dmHTML::imageList('dmthumbnail', $doc->dmthumbnail);
    $lists['dmthumbnail_preview'] = $doc->dmthumbnail;
    // Find lastupdate user
    $last = array();
    if ($doc->dmlastupdateby > _DM_PERMIT_USER) {
        $database->setQuery("SELECT id, name " . "\n FROM #__users " . "\n WHERE id=" . (int) $doc->dmlastupdateby);
        $last = $database->loadObjectList();
    } else {
        $last[0]->name = "Super Administrator";
    }
    // Find createdby user
    $created = array();
    if ($doc->dmsubmitedby > _DM_PERMIT_USER) {
        $database->setQuery("SELECT id, name " . "\n FROM #__users " . "\n WHERE id=" . (int) $doc->dmsubmitedby);
        $created = $database->loadObjectList();
    } else {
        $created[0]->name = "Super Administrator";
    }
    // update 'dmlastupdateon'
    $doc->dmlastupdateon = date("Y-m-d H:i:s");
    // Params definitions
    $params = null;
    $params_path = $mosConfig_absolute_path . '/administrator/components/com_docman/docman.params.xml';
    if (file_exists($params_path)) {
        $params =& new dmParameters($doc->attribs, $params_path, 'params');
    }
    /* ------------------------------ *
     *   MAMBOT - Setup All Mambots   *
     * ------------------------------ */
    $prebot = new DOCMAN_mambot('onBeforeEditDocument');
    $prebot->setParm('document', $doc);
    $prebot->setParm('filename', $filename);
    $prebot->setParm('user', $_DMUSER);
    if (!$uid) {
        $prebot->copyParm('process', 'new document');
    } else {
        $prebot->copyParm('process', 'edit document');
    }
    $prebot->trigger();
    if ($prebot->getError()) {
        _returnTo('cat_view', $prebot->getErrorMsg());
    }
    return HTML_DMDocuments::editDocumentForm($doc, $lists, $last, $created, $params);
}
예제 #3
0
function editDocument($uid)
{
    require_once JPATH_ADMINISTRATOR . "/components/com_docman/classes/DOCMAN_utils.class.php";
    require_once JPATH_ADMINISTRATOR . "/components/com_docman/classes/DOCMAN_params.class.php";
    global $_DOCMAN, $_DMUSER;
    $database = JFactory::getDBO();
    $my = JFactory::getUser();
    $mainframe = JFactory::getApplication();
    // disable the main menu to force user to use buttons
    $_REQUEST['hidemainmenu'] = 1;
    //@TODO :: Needs to be tested
    //$uploaded_file = mosGetParam(DOCMAN_Utils::stripslashes($_REQUEST), "uploaded_file", "");
    $uploaded_file = JRequest::getString('uploaded_file', '');
    $doc = new mosDMDocument($database);
    if ($uid) {
        $doc->load($uid);
        if ($doc->checked_out) {
            if ($doc->checked_out != $my->id) {
                $mainframe->redirect("index.php?option={$option}", _DML_THE_MODULE . " {$row->title} " . _DML_IS_BEING);
            }
        } else {
            // check out document...
            $doc->checkout($my->id);
        }
    } else {
        $doc->init_record();
    }
    // Begin building interface information...
    $lists = array();
    $lists['document_url'] = '';
    //make sure
    $lists['original_dmfilename'] = $doc->dmfilename;
    if (strcasecmp(substr($doc->dmfilename, 0, _DM_DOCUMENT_LINK_LNG), _DM_DOCUMENT_LINK) == 0) {
        $lists['document_url'] = substr($doc->dmfilename, _DM_DOCUMENT_LINK_LNG);
        $doc->dmfilename = _DM_DOCUMENT_LINK;
    }
    // category select list
    $options = array(JHTML::_('select.option', '0', _DML_SELECT_CAT));
    $lists['catid'] = dmHTML::categoryList($doc->catid, "", $options);
    // check if we have at least one category defined
    $database->setQuery("SELECT id " . "\n FROM #__categories " . "\n WHERE section='com_docman'", 0, 1);
    if (!($checkcats = $database->loadObjectList())) {
        $mainframe->redirect("index.php?option=com_docman&section=categories", _DML_PLEASE_SEL_CAT);
    }
    // select lists
    $lists['approved'] = JHTML::_('select.booleanlist', 'approved', 'class="inputbox"', $doc->approved);
    $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $doc->published);
    // licenses list
    $database->setQuery("SELECT id, name " . "\n FROM #__docman_licenses " . "\n ORDER BY name ASC");
    $licensesTemp = $database->loadObjectList();
    $licenses[] = JHTML::_('select.option', '0', _DML_NO_LICENSE);
    foreach ($licensesTemp as $licensesTemp) {
        $licenses[] = JHTML::_('select.option', $licensesTemp->id, $licensesTemp->name);
    }
    $lists['licenses'] = JHTML::_('select.genericlist', $licenses, 'dmlicense_id', 'class="inputbox" size="1"', 'value', 'text', $doc->dmlicense_id);
    // licenses display list
    $licenses_display[] = JHTML::_('select.option', '0', _DML_NO);
    $licenses_display[] = JHTML::_('select.option', '1', _DML_YES);
    $lists['licenses_display'] = JHTML::_('select.genericlist', $licenses_display, 'dmlicense_display', 'class="inputbox" size="1"', 'value', 'text', $doc->dmlicense_display);
    if ($uploaded_file == '') {
        // Create docs List
        $dm_path = $_DOCMAN->getCfg('dmpath');
        $fname_reject = $_DOCMAN->getCfg('fname_reject');
        $docFiles = DOCMAN_Compat::mosReadDirectory($dm_path);
        $docs = array(JHTML::_('select.option', '', _DML_SELECT_FILE));
        $docs[] = JHTML::_('select.option', _DM_DOCUMENT_LINK, _DML_LINKED);
        if (count($docFiles) > 0) {
            foreach ($docFiles as $file) {
                if (substr($file, 0, 1) == '.') {
                    continue;
                }
                //ignore files starting with .
                if (@is_dir($dm_path . '/' . $file)) {
                    continue;
                }
                //ignore directories
                if ($fname_reject && preg_match("/^(" . $fname_reject . ")\$/i", $file)) {
                    continue;
                }
                //ignore certain filenames
                if (preg_match("/^(" . _DM_FNAME_REJECT . ")\$/i", $file)) {
                    continue;
                }
                //ignore certain filenames
                //$query = "SELECT * FROM #__docman WHERE dmfilename='" . $database->getEscaped($file) . "'";
                //$database->setQuery($query);
                //if (!($result = $database->query())) {
                //	echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
                //}
                //if ($database->getNumRows($result) == 0 || $doc->dmfilename == $file) {
                $docs[] = JHTML::_('select.option', $file);
                //}
            }
            //end foreach $docsFiles
        }
        if (count($docs) < 1) {
            $mainframe->redirect("index.php?option={$option}&task=upload", _DML_YOU_MUST_UPLOAD);
        }
        $lists['dmfilename'] = JHTML::_('select.genericlist', $docs, 'dmfilename', 'class="inputbox" size="1"', 'value', 'text', $doc->dmfilename);
    } else {
        // uploaded_file isn't blank
        $filename = split("\\.", $uploaded_file);
        $row->dmname = $filename[0];
        $docs = array(JHTML::_('select.option', $uploaded_file));
        $lists['dmfilename'] = JHTML::_('select.genericlist', $docs, 'dmfilename', 'class="inputbox" size="1"', 'value', 'text', $doc->dmfilename);
    }
    // endif uploaded_file
    // permissions lists
    $lists['viewer'] = dmHTML::viewerList($doc, 'dmowner');
    $lists['maintainer'] = dmHTML::maintainerList($doc, 'dmmantainedby');
    // updater user information
    $last = array();
    if ($doc->dmlastupdateby > '0' && $doc->dmlastupdateby != $my->id) {
        $database->setQuery("SELECT id, name FROM #__users WHERE id=" . (int) $doc->dmlastupdateby);
        $last = $database->loadObjectList();
    } else {
        $last[0]->name = $my->name ? $my->name : $my->username;
    }
    // "Super Administrator"
    // creator user information
    $created = array();
    if ($doc->dmsubmitedby > '0' && $doc->dmsubmitedby != $my->id) {
        $database->setQuery("SELECT id, name FROM #__users WHERE id=" . (int) $doc->dmsubmitedby);
        $created = $database->loadObjectList();
    } else {
        $created[0]->name = $my->name ? $my->name : $my->username;
    }
    // "Super Administrator"
    // Imagelist
    $lists['image'] = dmHTML::imageList('dmthumbnail', $doc->dmthumbnail);
    // Params definitions
    $params_path = JPATH_ADMINISTRATOR . '/components/com_docman/docman.params.xml';
    if (file_exists($params_path)) {
        $params =& new dmParameters($doc->attribs, $params_path, 'params');
    }
    /* ------------------------------ *
     *   MAMBOT - Setup All Mambots   *
     * ------------------------------ */
    $prebot = new DOCMAN_mambot('onBeforeEditDocument');
    $prebot->setParm('document', $doc);
    $prebot->setParm('filename', $filename);
    $prebot->setParm('user', $_DMUSER);
    if (!$uid) {
        $prebot->copyParm('process', 'new document');
    } else {
        $prebot->copyParm('process', 'edit document');
    }
    $prebot->trigger();
    if ($prebot->getError()) {
        $mainframe->redirect("index.php?option=com_docman&section=documents", $prebot->getErrorMsg());
    }
    HTML_DMDocuments::editDocument($doc, $lists, $last, $created, $params);
}