function linkFileProcess($uid, $step, $url) { DOCMAN_token::check() or die('Invalid Token'); global $_DMUSER, $_DOCMAN; if ($url == '') { return array('_error' => 1, '_errmsg' => _DML_FILENAME_REQUIRED); } $path = $_DOCMAN->getCfg('dmpath'); //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->uploadLINK($url, $validate); if (!$file) { $msg = _DML_ERROR_LINKING . " - " . $upload->_err; return array('_error' => 1, '_errmsg' => $msg); } $msg = _DML_LINKED; return array('_error' => 0, '_errmsg' => $msg); }
function clearData($cid = array()) { DOCMAN_token::check() or die('Invalid Token'); $msgs = array(); $cleardata = new DOCMAN_Cleardata($cid); $cleardata->clear(); $rows =& $cleardata->getList(); foreach ($rows as $row) { $msgs[] = $row->msg; } mosRedirect('index2.php?option=com_docman§ion=cleardata', implode(' | ', $msgs)); }
function clearData($cid = array()) { DOCMAN_token::check('request') or die('Invalid Token'); $mainframe = JFactory::getApplication(); $msgs = array(); $cleardata = new DOCMAN_Cleardata($cid); $cleardata->clear(); $rows =& $cleardata->getList(); foreach ($rows as $row) { $msgs[] = $row->msg; } $mainframe->redirect('index.php?option=com_docman§ion=cleardata', implode(' | ', $msgs)); }
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§ion=logs"); } }
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 saveConfig() { DOCMAN_token::check() or die('Invalid Token'); global $_DOCMAN, $task; $mainframe = JFactory::getApplication(); $_POST = DOCMAN_Utils::stripslashes($_POST); $docmanMax = DOCMAN_Utils::text2number($_POST['maxAllowed']); $_POST['maxAllowed'] = $docmanMax; $sysUploadMax = DOCMAN_Utils::text2number(ini_get('upload_max_filesize')); $sysPostMax = DOCMAN_Utils::text2number(ini_get('post_max_size')); $max = min($sysUploadMax, $sysPostMax); if ($docmanMax < 0) { $mainframe->redirect("index.php?option=com_docman§ion=config", _DML_CONFIG_ERROR_UPLOAD); } $override_edit = _DM_ASSIGN_NONE; $author = JRequest::getBool('assign_edit_author', 0, 'post'); $editor = JRequest::getBool('assign_edit_editor', 0, 'post'); if ($author) { $override_edit = _DM_ASSIGN_BY_AUTHOR; } if ($editor) { $override_edit = _DM_ASSIGN_BY_EDITOR; } if ($author && $editor) { $override_edit = _DM_ASSIGN_BY_AUTHOR_EDITOR; } $_POST['editor_assign'] = $override_edit; unset($_POST['assign_edit_author']); unset($_POST['assign_edit_editor']); $override_down = _DM_ASSIGN_NONE; $author = JRequest::getBool('assign_download_author', 0, 'post'); $editor = JRequest::getBool('assign_download_editor', 0, 'post'); if ($author) { $override_down = _DM_ASSIGN_BY_AUTHOR; } if ($editor) { $override_down = _DM_ASSIGN_BY_EDITOR; } if ($author && $editor) { $override_down = _DM_ASSIGN_BY_AUTHOR_EDITOR; } $_POST['reader_assign'] = $override_down; unset($_POST['assign_download_author']); unset($_POST['assign_download_editor']); foreach ($_POST as $key => $value) { $_DOCMAN->setCfg($key, $value); } if ($_DOCMAN->saveConfig()) { if ($max < $docmanMax) { $mainframe->redirect("index.php?option=com_docman§ion=config", _DML_CONFIG_WARNING . DOCMAN_UTILS::number2text($max)); } else { $section = $task == 'apply' ? '§ion=config' : ''; $mainframe->redirect('index.php?option=com_docman' . $section, _DML_CONFIG_UPDATED); } } else { $mainframe->redirect("index.php?option=com_docman§ion=config", _DML_CONFIG_ERROR); } }
function deleteDocument($uid) { DOCMAN_token::check() or die('Invalid Token'); global $database, $_DMUSER; $doc = new mosDMDocument($database); $doc->load($uid); //check user permissions $err = $_DMUSER->canPreformTask($doc, 'Delete'); if ($err) { _returnTo('cat_view', $err, $doc->catid); } //delete the docmument $doc->remove(array($uid)); _returnTo('cat_view', _DML_DOCDELETED, $doc->catid); }
/** * changes the access level of a record * * @param integer $ The increment to reorder by */ function accessCategory($uid, $access) { DOCMAN_token::check() or die('Invalid Token'); $database = JFactory::getDBO(); $mainframe = JFactory::getApplication(); $row = new mosDMCategory($database); $row->load($uid); $row->access = $access; if (!$row->check()) { return $row->getError(); } if (!$row->store()) { return $row->getError(); } $mainframe->redirect('index.php?option=com_docman§ion=categories'); }
function saveThemeCSS() { DOCMAN_token::check() or die('Invalid Token'); global $_DOCMAN, $task; $mainframe = JFactory::getApplication(); $theme = trim(JRequest::getCmd('theme', '', 'post')); $filecontent = JRequest::getString('filecontent', '', 'post', JREQUEST_ALLOWHTML); if (!file_exists($_DOCMAN->getPath('themes') . DS . $theme)) { echo "<script> alert('Theme not found'); window.history.go(-1);</script>\n"; exit; } if (!$theme) { $mainframe->redirect('index.php?option=com_docman§ion=themes', _DML_OPFAILED_NO_TEMPLATE); } if (!$filecontent) { $mainframe->redirect('index.php?option=com_docman§ion=themes', _DML_OPFAILED_CONTENT_EMPTY); } $file = $_DOCMAN->getPath('themes', $theme) . "/css/theme.css"; if (is_writable($file) == false) { $mainframe->redirect('index.php?option=com_docman§ion=themes', _DML_OPFAILED_UNWRITABLE); } if ($fp = fopen($file, 'w')) { fputs($fp, stripslashes($filecontent)); fclose($fp); if ($task == 'save_css') { $url = 'index.php?option=com_docman§ion=themes'; } else { // $task = 'apply_css' $url = 'index.php?option=com_docman§ion=themes&task=edit_css&cid[0]=' . $theme; } $mainframe->redirect($url, _DML_SAVED_CHANGES); } else { $mainframe->redirect('index.php?option=com_docman§ion=themes', _DML_OPFAILED_CANT_OPEN_FILE); } }
function copyDocumentProcess($cid) { DOCMAN_token::check() or die('Invalid Token'); $mainframe = JFactory::getApplication(); $database = JFactory::getDBO(); $my = JFactory::getUser(); // get the id of the category to copy the document to $categoryCopy = JRequest::getInt('catid', '', 'post'); // preform move $doc = new mosDMDocument($database); $doc->copy($cid, $categoryCopy); // output status message $cids = implode(',', $cid); $total = count($cid); $cat = new mosDMCategory($database); $cat->load($categoryCopy); $msg = $total . ' ' . _DML_DOCUMENTS_COPIED_TO . ' ' . $cat->name; $mainframe->redirect('index.php?option=com_docman§ion=documents', $msg); }
function uploadWizard($step = 1, $method = 'http', $old_filename) { global $_DOCMAN; $mainframe = JFactory::getApplication(); $database = JFactory::getDBO(); switch ($step) { case 1: $lists['methods'] = dmHTML::uploadSelectList($method); HTML_DMFiles::uploadWizard($lists); break; case 2: switch ($method) { case 'http': HTML_DMFiles::uploadWizard_http($old_filename); break; case 'ftp': HTML_DMFiles::uploadWizard_ftp(); break; case 'link': $mainframe->redirect("index.php?option=com_docman§ion=documents&task=new&makelink=1", _DML_CREATEALINK); // HTML_DMFiles::uploadWizard_link(); break; case 'transfer': HTML_DMFiles::uploadWizard_transfer(); break; default: $mainframe->redirect("index.php?option=com_docman§ion=files", _DML_SELECTMETHODFIRST); } break; case 3: DOCMAN_token::check() or die('Invalid Token'); switch ($method) { case 'http': $path = $_DOCMAN->getCfg('dmpath'); $upload = new DOCMAN_FileUpload(); $file_upload = JRequest::getVar('upload', '', 'files', 'array'); $result =& $upload->uploadHTTP($file_upload, $path, _DM_VALIDATE_ADMIN); if (!$result) { $mainframe->redirect("index.php?option=com_docman§ion=files", _DML_ERROR_UPLOADING . " - " . $upload->_err); } else { $batch = JRequest::getCmd('batch', null); if ($batch && $old_filename != null) { require_once JPATH_ADMINISTRATOR . DS . 'includes' . DS . 'pcl' . DS . 'pclzip.lib.php'; if (!extension_loaded('zlib')) { $mainframe->redirect("index.php?option=com_docman§ion=files", _DML_ZLIB_ERROR); } $target_directory = $_DOCMAN->getCfg('dmpath'); $zip = new PclZip($target_directory . DS . $result->name); $file_to_unzip = preg_replace('/(.+)\\..*$/', '$1', $target_directory . DS . $result->name); if (!$zip->extract($target_directory)) { $mainframe->redirect("index.php?option=com_docman§ion=files", _DML_UNZIP_ERROR); } @unlink($target_directory . DS . $result->name); } if ($old_filename && $old_filename != $file_upload['name']) { $file = $_DOCMAN->getCfg('dmpath') . DS . $old_filename; @unlink($file); $database->setQuery("UPDATE #__docman SET dmfilename='" . $database->getEscaped($result->name) . "' WHERE dmfilename='" . $database->getEscaped($old_filename) . "'"); if (!$database->query()) { echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1);</script>\n"; exit; } } //HTML_DMFiles::uploadWizard_sucess($result, $batch, $old_filename); $mainframe->redirect("index.php?option=com_docman§ion=files&task=upload&step=4" . "&result=" . urlencode($result->name) . "&batch=" . (0 + $batch) . "&old_filename=" . $old_filename, _DML_SUCCESS . ' "' . $result->name . '" - ' . _DML_FILEUPLOADED); } break; case 'ftp': break; case 'link': break; case 'transfer': $url = stripslashes(JRequest::getString('url', null, 'post')); $name = stripslashes(JRequest::getString('localfile', null, 'post')); $path = $_DOCMAN->getCfg('dmpath') . DS; $upload = new DOCMAN_FileUpload(); $result = $upload->uploadURL($url, $path, _DM_VALIDATE_ADMIN, $name); if ($result) { // HTML_DMFiles::uploadWizard_sucess($result, 0, 1); $mainframe->redirect("index.php?option=com_docman§ion=files&task=upload&step=4" . "&result=" . urlencode($result->name) . "&batch=0&old_filename=1", _DML_SUCCESS . ' "' . $result->name . '" - ' . _DML_FILEUPLOADED); } else { $mainframe->redirect("index.php?option=com_docman§ion=files", $upload->_err); } break; } break; case '4': /* New step that gives us a header completion message rather than "in body" completion. For uniformity */ $file = new StdClass(); $file->name = urlencode(stripslashes(JRequest::getString('result', 'INTERNAL ERROR'))); $batch = JRequest::getInt('batch', 0); $old_filename = JRequest::getString('old_filename', null); HTML_DMFiles::uploadWizard_sucess($file, $batch, $old_filename, 0); break; } //End switch($step) }
function copyDocumentProcess($cid) { DOCMAN_token::check() or die('Invalid Token'); global $database, $my; // get the id of the category to copy the document to $categoryCopy = mosGetParam($_POST, 'catid', ''); // preform move $doc = new mosDMDocument($database); $doc->copy($cid, $categoryCopy); // output status message $cids = implode(',', $cid); $total = count($cid); $cat = new mosDMCategory($database); $cat->load($categoryCopy); $msg = $total . ' ' . _DML_DOCUMENTS_COPIED_TO . ' ' . $cat->name; mosRedirect('index2.php?option=com_docman§ion=documents', $msg); }
function sendEmail($gid) { DOCMAN_token::check() or die('Invalid Token'); // this is a generic mass mail sender to groups members. // From frontend you will find a email to group function specific for a document. $database = JFactory::getDBO(); $my = JFactory::getUser(); $mainframe = JFactory::getApplication(); $this_index = 'index.php?option=com_docman§ion=groups'; $message = JRequest::getString("mm_message", '', 'post'); $subject = JRequest::getString("mm_subject", '', 'post'); $leadin = JRequest::getString("mm_leadin", '', 'post'); if (!$message || !$subject) { $mainframe->redirect($this_index . '&task=emailgroup&gid=' . $gid, _DML_FILL_FORM); } $usertmp = trim(strtolower($my->usertype)); if ($usertmp != "super administrator" && $usertmp != "superadministrator" && $usertmp != "manager") { $mainframe->redirect("index.php", _DML_ONLY_ADMIN_EMAIL); } // Get the 'TO' list of addresses $database->setQuery("SELECT * " . "\n FROM #__docman_groups " . "\n WHERE groups_id=" . (int) $gid); $email_group = $database->loadObjectList(); $database->setQuery("SELECT id,name,username,email " . "\n FROM #__users" . "\n WHERE id in ( " . $email_group[0]->groups_members . ")" . "\n AND email !=''"); $listofusers = $database->loadObjectList(); if (!count($listofusers)) { $mainframe->redirect($this_index, _DML_NO_TARGET_EMAIL . " " . $email_groups[0]->name); } // Get 'FROM' sending email address (Use default) if (!$mainframe->getCfg('mailfrom')) { $database->setQuery("SELECT email " . "\n FROM #__users " . "\n WHERE id=" . $my->id); $my->email = $database->loadResult(); echo $database->getErrorMsg(); $mainframe->setCfg('mailfrom', $my->email); } // Build e-mail message format $message = ($leadin ? stripslashes($leadin) . "\r\n\r\n" : '') . stripslashes($message); $subject = stripslashes($subject); // ------- Obsolete: ...kept for historical purposes.... // $headers = "MIME-Version: 1.0\r\n" // . "From: " .$mosConfig_sitename." <".$my->email.">\r\n" // . "Reply-To: ".$mosConfig_sitename." <".$my->email.">\r\n" // . "X-Priority: 3\r\n" // . "X-MSMail-Priority: Low\r\n" // . "X-Mailer: DOCman\r\n" // ; // mail($emailtosend->email, $subject, $message, $headers); // TO: SUBJECT: (message) Headers // ------------ Send email using standard mosMail function foreach ($listofusers as $emailtosend) { JUTility::sendMail($mainframe->getCfg('mailfrom'), $mainframe->getCfg('fromname'), $emailtosend->email, $subject, $message); } $mainframe->redirect($this_index, _DML_EMAIL_SENT_TO . " " . count($listofusers) . " " . _DML_USERS); }
/** * changes the access level of a record * * @param integer $ The increment to reorder by */ function accessCategory($uid, $access) { DOCMAN_token::check() or die('Invalid Token'); global $database; $row = new mosDMCategory($database); $row->load($uid); $row->access = $access; if (!$row->check()) { return $row->getError(); } if (!$row->store()) { return $row->getError(); } mosRedirect('index2.php?option=com_docman§ion=categories'); }
function removeLicense($cid, $option) { DOCMAN_token::check() or die('Invalid Token'); $mainframe = JFactory::getApplication(); $database = JFactory::getDBO(); if (!is_array($cid) || count($cid) < 1) { echo "<script> alert(" . _DML_SELECT_ITEM_DEL . "); window.history.go(-1);</script>\n"; exit; } if (count($cid)) { $cids = implode(',', $cid); // lets see if some document is using this license for ($g = 0; $g < count($cid); $g++) { $ttt = $cid[$g]; $ttt = $ttt - 2 * $ttt - 10; $query = "SELECT id FROM #__docman WHERE dmlicense_id=" . (int) $ttt; $database->setQuery($query); if (!($result = $database->query())) { echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n"; } if ($database->getNumRows($result) != 0) { $mainframe->redirect("index.php?option=com_docman&task=viewgroups", _DML_CANNOT_DEL_LICENSE); } } $database->setQuery("DELETE FROM #__docman_licenses WHERE id IN ({$cids})"); if (!$database->query()) { echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n"; } } $mainframe->redirect("index.php?option=com_docman§ion=licenses"); }
function sendEmail($gid) { DOCMAN_token::check() or die('Invalid Token'); $database = JFactory::getDBO(); $my = JFactory::getUser(); $mainframe = JFactory::getApplication(); $link = 'index.php?option=com_docman§ion=groups'; $message = JRequest::getString("mm_message", '', 'post'); $subject = JRequest::getString("mm_subject", '', 'post'); $leadin = JRequest::getString("mm_leadin", '', 'post'); if (!$message || !$subject) { $mainframe->redirect($link . '&task=emailgroup&gid=' . $gid, _DML_FILL_FORM); } // Get the 'TO' list of addresses $group = DOCMAN_groups::get((int) $gid); $database->setQuery("SELECT * FROM #__users WHERE id in (" . $group->groups_members . ") AND email !=''"); $users = $database->loadObjectList(); if (!count($users)) { $mainframe->redirect($link, _DML_NO_TARGET_EMAIL . " " . $group->groups_name); } // Build e-mail message format $message = ($leadin ? stripslashes($leadin) . "\r\n\r\n" : '') . stripslashes($message); $subject = stripslashes($subject); foreach ($users as $user) { JUtility::sendMail($mainframe->getCfg('mailfrom'), $mainframe->getCfg('fromname'), $user->email, $subject, $message); } $mainframe->redirect($link, _DML_EMAIL_SENT_TO . ' ' . count($users) . ' ' . _DML_USERS); }