diff --git a/lib/users/userutil.inc.php b/lib/users/userutil.inc.php
new file mode 100644
index 0000000..70500e5
--- /dev/null
+++ b/lib/users/userutil.inc.php
@@ -0,0 +1,89 @@
+.
+ *
+ * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
+ * California 94120-7775, or email info@knowledgetree.com.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "Powered by
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
+ * must display the words "Powered by KnowledgeTree" and retain the original
+ * copyright notice.
+ * Contributor( s): ______________________________________
+ *
+ */
+
+require_once(KT_LIB_DIR . '/users/User.inc');
+
+class KTUserUtil
+{
+ static function createUser($username, $name, $password = null, $email_address = null, $email_notifications = false, $mobile_number = null, $max_sessions = 3, $source_id = null, $details = null, $details2 = null)
+ {
+ $dupUser =& User::getByUserName($username);
+ if(!PEAR::isError($dupUser)) {
+ return PEAR::raiseError(_kt("A user with that username already exists"));
+ }
+
+ $oUser =& User::createFromArray(array(
+ "sUsername" => $username,
+ "sName" => $name,
+ "sPassword" => md5($password),
+ "iQuotaMax" => 0,
+ "iQuotaCurrent" => 0,
+ "sEmail" => $email_address,
+ "bEmailNotification" => $email_notifications,
+ "sMobile" => $mobile_number,
+ "bSmsNotification" => false, // FIXME do we auto-act if the user has a mobile?
+ "iMaxSessions" => $max_sessions,
+ "authenticationsourceid" => $source_id,
+ "authenticationdetails" => $details,
+ "authenticationdetails2" => $details2,
+ ));
+
+ if (PEAR::isError($oUser) || ($oUser == false)) {
+ return PEAR::raiseError(_kt("failed to create user."));
+ }
+
+ // run triggers on user creation
+ $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
+ $aTriggers = $oKTTriggerRegistry->getTriggers('user_create', 'postValidate');
+
+ foreach ($aTriggers as $aTrigger) {
+ $sTrigger = $aTrigger[0];
+ $oTrigger = new $sTrigger;
+ $aInfo = array(
+ 'user' => $oUser,
+ );
+ $oTrigger->setInfo($aInfo);
+ $ret = $oTrigger->postValidate();
+ }
+
+ return $oUser;
+ }
+}
+
+
+?>
\ No newline at end of file
diff --git a/plugins/MyDropDocumentsPlugin/MyDropDocumentsDashlet.php b/plugins/MyDropDocumentsPlugin/MyDropDocumentsDashlet.php
index 24fba1c..93471d4 100644
--- a/plugins/MyDropDocumentsPlugin/MyDropDocumentsDashlet.php
+++ b/plugins/MyDropDocumentsPlugin/MyDropDocumentsDashlet.php
@@ -5,75 +5,102 @@
* KnowledgeTree Community Edition
* Document Management Made Simple
* Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc.
- *
- *
+ *
+ *
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
- *
+ *
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
- *
- * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
+ *
+ * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
* California 94120-7775, or email info@knowledgetree.com.
- *
+ *
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
- *
+ *
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
- * KnowledgeTree" logo and retain the original copyright notice. If the display of the
+ * KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
- * must display the words "Powered by KnowledgeTree" and retain the original
+ * must display the words "Powered by KnowledgeTree" and retain the original
* copyright notice.
* Contributor( s): ______________________________________
*
*/
+require_once('MyDropDocumentsPage.php');
+
class MyDropDocumentsDashlet extends KTBaseDashlet {
var $oUser;
- //var $sClass = 'ktError';
-
+
function MyDropDocumentsDashlet(){
$this->sTitle = _kt('My Dropped Documents');
}
-
+
function is_active($oUser) {
$this->oUser = $oUser;
return true;
}
-
-
-/*
+
+
+/*
function is_active($oUser) {
$this->oUser = $oUser;
return Permission::userIsSystemAdministrator($oUser);
}
*/
-
+
function render() {
global $main;
$main->requireJSResource("plugins/MyDropDocumentsPlugin/js/update.js");
-
+
$oPlugin =& $this->oPlugin;
-
+
$oTemplating =& KTTemplating::getSingleton();
- $oTemplate = $oTemplating->loadTemplate('MyDropDocumentsPlugin/dashlet');
-
+ $oTemplate = $oTemplating->loadTemplate('MyDropDocumentsPlugin/dashlet');
+
$aTemplateData = array(
'context' => $this,
'url' => $oPlugin->getPagePath('MyDropDocuments'),
-
+
);
-
-
+
+
return $oTemplate->render($aTemplateData);
}
}
+
+
+class CreateUserFolderTrigger {
+ var $namespace = 'ktlive.mydropdocuments.triggers.user_create';
+ var $aInfo = null;
+
+ function setInfo($aInfo) {
+ $this->aInfo = $aInfo;
+ }
+
+ /**
+ * Create the dropped documents folder for the user on user creation
+ */
+ function postValidate() {
+ $oUser = $this->aInfo['user'];
+
+ if(!($oUser instanceof User) || !($oUser instanceof UserProxy)){
+ return false;
+ }
+
+ $drop = new DropFolderCreation($oUser);
+ $drop->checkFolders();
+ }
+}
+
+
?>
diff --git a/plugins/MyDropDocumentsPlugin/MyDropDocumentsPage.php b/plugins/MyDropDocumentsPlugin/MyDropDocumentsPage.php
index 3b3abe2..c7a8ff4 100644
--- a/plugins/MyDropDocumentsPlugin/MyDropDocumentsPage.php
+++ b/plugins/MyDropDocumentsPlugin/MyDropDocumentsPage.php
@@ -5,7 +5,7 @@
* KnowledgeTree Community Edition
* Document Management Made Simple
* Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc.
- *
+ *
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
@@ -73,6 +73,239 @@ class MyDropDocumentsPage extends KTStandardDispatcher {
$oUser = $this->oUser;
$sUserName = (string)$this->oUser->getUserName();
+ // Check for the DropDocuments folder in root
+ if(!Folder::FolderExistsName('DroppedDocuments', $iRootID))
+ {
+ return _kt('The Dropped Documents folder does not exist. Please contact your System Administrator');
+ }
+
+ $iDropDocsFolderID = $this->getFolderID('DroppedDocuments');
+
+ // Check for users folder
+ if(!Folder::FolderExistsName($sUserName, $iDropDocsFolderID))
+ {
+ return _kt('Your personal folder under the Dropped Documents folder does not exist. Please contact your System Administrator');
+ }
+
+ // Get documents
+ return $this->getUsersDocument($sUserName, $iDropDocsFolderID);
+ }
+
+ /**
+ * Method to get any documents added by the user via the Drop Box.
+ * Returns the HTML displaying the document list.
+ *
+ * @param string $sUserName
+ * @param numeric $iDropDocsFolderID
+ * @return string HTML - the document list on success or an error message on failure
+ */
+ function getUsersDocument($sUserName, $iDropDocsFolderID)
+ {
+ $oUser = $this->oUser;
+ $oDropDocsFolder = Folder::get($iDropDocsFolderID);
+
+ $fullPath = $oDropDocsFolder->getFullPath() . '/' . $sUserName;
+
+ $aExternalWhereClauses[] = '(DT.transaction_namespace IN (?,?,?) AND (D.full_path LIKE "'.$fullPath.'/%"))';
+ $aExternalWhereParams[] = 'ktcore.transactions.create';
+ $aExternalWhereParams[] = 'ktcore.transactions.check_in';
+ $aExternalWhereParams[] = 'ktcore.transactions.event';
+
+
+ $aDocumentTransactions = $this->getTransactionsMatchingQuery($oUser, '', $aExternalWhereClauses, $aExternalWhereParams);
+ if (empty($aDocumentTransactions) || PEAR::isError($aDocumentTransactions))
+ {
+ if(PEAR::isError($aDocumentTransactions)){
+ global $default;
+ $default->log->debug('Error retrieving dropped documents - '.$aDocumentTransactions->getMessage());
+ }
+
+ return _kt(' You do not have any dropped documents
');
+ }
+
+ $maxcount = 5;
+
+ $sReturnTable = ''._kt('Recently Dropped Documents').'
+
+
+
+
+ | '._kt('Document').' |
+ '._kt('Date Dropped').' |
+
+
+ ';
+
+ $sOddorEven = '';
+ $count = 1;
+ $rendered = array();
+ foreach ($aDocumentTransactions as $aRow)
+ {
+ $documentId = $aRow['document_id'];
+ if (in_array($documentId, $rendered))
+ {
+ continue;
+ }
+
+ $rendered[] = $documentId;
+ $oDocument = Document::get($documentId);
+
+ $sContentType = KTMime::getIconPath($oDocument->getMimeTypeID());
+ $aAnchorData = $this->getDocInfo($documentId);
+ $sLink = $aAnchorData[0];
+ $sShortDocName = $sDocName = $aAnchorData[1];
+
+ $iDocLength = strlen($sDocName);
+ $iMax = 40;
+ if ( $iDocLength > $iMax )
+ {
+ $sShortDocName = substr($sDocName, 0, $iMax) . '...';
+ }
+
+ $sOddorEven = ($count%2 == 0)?'even':'odd';
+
+ $sReturnTable .= ''.
+ '| '.$sShortDocName.' | '.
+ ''.$aRow['datetime'].' | '.
+ '
';
+ if (++$count > 5)
+ {
+ break;
+ }
+ }
+
+ $subFolders = Folder::getByParentId($iDropDocsFolderID);
+ if(PEAR::isError($subFolders) || empty($subFolders)){
+ $iMyDocsFolderID = $iDropDocsFolderID;
+ }else{
+ foreach ($subFolders as $sub){
+ if($sub->getName() == $sUserName){
+ $iMyDocsFolderID = $sub->getID();
+ break;
+ }
+ }
+ }
+
+ $location = 'browse.php?fFolderId='.$iMyDocsFolderID;
+ $sReturnTable .= ''.
+ '
'.
+ '
'.
+ ''._kt(' View All').'
';
+ return $sReturnTable;
+ }
+
+ //this function returns the document link and document name to be displayed on the dashlet
+ function getDocInfo($iDocId) {
+ $oDocument = Document::get($iDocId);
+
+ if (PEAR::isError($oDocument)) {
+ return _kt('Document no longer exists.');
+ }
+
+ $sName = htmlentities($oDocument->getName(), ENT_NOQUOTES, 'UTF-8');
+ $sLink = KTBrowseUtil::getUrlForDocument($oDocument);
+
+ $aAnchorData = array();
+ $aAnchorData[] = $sLink;
+ $aAnchorData[] = $sName;
+ return $aAnchorData;
+ }
+
+ //FIXME: Direct Database access
+ function getFolderID($sFolderName) {
+ $sQuery = 'SELECT id FROM folders WHERE name = \''.$sFolderName.'\'';
+
+ $id = DBUtil::getResultArray($sQuery);
+ return $id[0]['id'];
+ }
+
+ function handleOutput($sOutput) {
+ print $sOutput;
+ }
+
+ /*
+ attempt to abstract the transaction-matching query.
+
+ tables that are already defined (other than sec ones):
+
+ - Documents (D)
+ - Users (U)
+ - TransactionTypes (DTT)
+ - Document Transactions (DT)
+
+ so where clausess can take advantage of those.
+
+ */
+ function getTransactionsMatchingQuery($oUser, $sJoinClause, $aExternalWhereClauses, $aExternalWhereParams, $aOptions = null) {
+
+ $sSelectItems = 'DTT.name AS transaction_name, U.name AS user_name, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime, D.id as document_id, DT.transaction_namespace as namespace';
+ $sBaseJoin = "FROM " . KTUtil::getTableName("document_transactions") . " AS DT " .
+ "INNER JOIN " . KTUtil::getTableName("users") . " AS U ON DT.user_id = U.id " .
+ "INNER JOIN " . KTUtil::getTableName("transaction_types") . " AS DTT ON DTT.namespace = DT.transaction_namespace " .
+ "INNER JOIN " . KTUtil::getTableName("documents") . " AS D ON D.id = DT.document_id ";
+
+ // now we're almost at partialquery like status.
+ $perm_res = KTSearchUtil::permissionToSQL($oUser, 'ktcore.permissions.read');
+ if (PEAR::isError($perm_res)) {
+ return $perm_res;
+ }
+ list($sPermissionString, $aPermissionParams, $sPermissionJoin) = $perm_res;
+
+ // compile the final list
+ $aFinalWhere = kt_array_merge(array($sPermissionString,'D.creator_id IS NOT NULL'), $aExternalWhereClauses, array('D.status_id = ?'));
+ $aFinalWhereParams = kt_array_merge($aPermissionParams, $aExternalWhereParams, array(LIVE));
+
+ if (!is_array($aOptions)) {
+ $aOptions = (array) $aOptions;
+ }
+ $sOrderBy = KTUtil::arrayGet($aOptions, 'orderby', 'DT.datetime DESC');
+
+ // compile these.
+ // NBM: do we need to wrap these in ()?
+ $sWhereClause = implode(' AND ', $aFinalWhere);
+ if (!empty($sWhereClause)) {
+ $sWhereClause = 'WHERE ' . $sWhereClause;
+ }
+
+ $sQuery = sprintf("SELECT %s %s %s %s %s ORDER BY %s",
+ $sSelectItems,
+ $sBaseJoin,
+ $sPermissionJoin,
+ $sJoinClause,
+ $sWhereClause,
+ $sOrderBy
+ );
+
+ //var_dump(array($sQuery, $aFinalWhereParams));
+
+ $res = DBUtil::getResultArray(array($sQuery, $aFinalWhereParams));
+ //var_dump($res); exit(0);
+ return $res;
+ }
+
+}
+
+class DropFolderCreation
+{
+ private $oUser;
+ private $ktapi;
+ private $session;
+
+ function __construct($oUser)
+ {
+ $this->oUser = $oUser;
+ }
+
+ function checkFolders()
+ {
+ // Check if users folder exists in DropDocuments folder
+ // - it does -> continue on to check for documents
+ // - it doesn't -> switch to root user and create it
+
+ global $default;
+ $iRootID = (int)1;
+ $oUser = $this->oUser;
+ $sUserName = (string)$this->oUser->getUserName();
// Check for the DropDocuments folder in root
if(!Folder::FolderExistsName('DroppedDocuments', $iRootID))
@@ -111,9 +344,6 @@ class MyDropDocumentsPage extends KTStandardDispatcher {
return $res;
}
}
-
- // Get documents
- return $this->getUsersDocument($sUserName, $iDropDocsFolderID);
}
/**
@@ -122,6 +352,7 @@ class MyDropDocumentsPage extends KTStandardDispatcher {
*/
function createPersonalFolder($sUserName, $iDropDocsFolderID)
{
+ global $default;
// Add the users folder
// Add the user to the WorkSpaceAdmin role on the DroppedDocuments folder
// Define users folder permissions
@@ -200,6 +431,7 @@ class MyDropDocumentsPage extends KTStandardDispatcher {
*/
function createDropDocsFolder()
{
+ global $default;
$root = $this->ktapi->get_root_folder();
if(PEAR::isError($root)){
@@ -211,7 +443,7 @@ class MyDropDocumentsPage extends KTStandardDispatcher {
$dropDocsFolder = $root->add_folder('DroppedDocuments');
if(PEAR::isError($dropDocsFolder)){
- $default->log->debug('MyDropDocuments: could not create DroppedDocuments folder '.$dropDocsFolder->getMessage());
+ $defaultf->log->debug('MyDropDocuments: could not create DroppedDocuments folder '.$dropDocsFolder->getMessage());
return _kt('Error - could not create the DropppedDocuments folder: ').$dropDocsFolder->getMessage();
}
@@ -254,115 +486,6 @@ class MyDropDocumentsPage extends KTStandardDispatcher {
return null;
}
- /**
- * Method to get any documents added by the user via the Drop Box.
- * Returns the HTML displaying the document list.
- *
- * @param string $sUserName
- * @param numeric $iDropDocsFolderID
- * @return string HTML - the document list on success or an error message on failure
- */
- function getUsersDocument($sUserName, $iDropDocsFolderID)
- {
- $oUser = $this->oUser;
- $oDropDocsFolder = Folder::get($iDropDocsFolderID);
-
- $fullPath = $oDropDocsFolder->getFullPath() . '/' . $sUserName;
-
- $aExternalWhereClauses[] = '(DT.transaction_namespace IN (?,?,?) AND (D.full_path LIKE "'.$fullPath.'/%"))';
- $aExternalWhereParams[] = 'ktcore.transactions.create';
- $aExternalWhereParams[] = 'ktcore.transactions.check_in';
- $aExternalWhereParams[] = 'ktcore.transactions.event';
-
-
- $aDocumentTransactions = $this->getTransactionsMatchingQuery($oUser, '', $aExternalWhereClauses, $aExternalWhereParams);
- if (empty($aDocumentTransactions) || PEAR::isError($aDocumentTransactions))
- {
- if(PEAR::isError($aDocumentTransactions)){
- global $default;
- $default->log->debug('Error retrieving dropped documents - '.$aDocumentTransactions->getMessage());
- }
-
- return _kt(' You do not have any dropped documents
');
- }
-
- $maxcount = 5;
-
- $sReturnTable = ''._kt('Recently Dropped Documents').'
-
-
-
-
- | '._kt('Document').' |
- '._kt('Date Dropped').' |
-
-
- ';
-
- $sOddorEven = '';
- $count = 1;
- $rendered = array();
- foreach ($aDocumentTransactions as $aRow)
- {
- $documentId = $aRow['document_id'];
- if (in_array($documentId, $rendered))
- {
- continue;
- }
-
- $rendered[] = $documentId;
- $oDocument = Document::get($documentId);
-
- $sContentType = KTMime::getIconPath($oDocument->getMimeTypeID());
- $aAnchorData = $this->getDocInfo($documentId);
- $sLink = $aAnchorData[0];
- $sShortDocName = $sDocName = $aAnchorData[1];
-
- $iDocLength = strlen($sDocName);
- $iMax = 40;
- if ( $iDocLength > $iMax )
- {
- $sShortDocName = substr($sDocName, 0, $iMax) . '...';
- }
-
- $sOddorEven = ($count%2 == 0)?'even':'odd';
-
- $sReturnTable .= ''.
- '| '.$sShortDocName.' | '.
- ''.$aRow['datetime'].' | '.
- '
';
- if (++$count > 5)
- {
- break;
- }
- }
-
- $subFolders = Folder::getByParentId($iDropDocsFolderID);
- if(PEAR::isError($subFolders) || empty($subFolders)){
- $iMyDocsFolderID = $iDropDocsFolderID;
- }else{
- foreach ($subFolders as $sub){
- if($sub->getName() == $sUserName){
- $iMyDocsFolderID = $sub->getID();
- break;
- }
- }
- }
-
- $location = 'browse.php?fFolderId='.$iMyDocsFolderID;
- $sReturnTable .= ''.
- '
'.
- '
'.
- ''._kt(' View All').'
';
- //$this->session->logout();
-
- return $sReturnTable;
- }
-
- function handleOutput($sOutput) {
- print $sOutput;
- }
-
//This function is used to set the permission on the dropdocuments folder
function setUserDocsPermissions($oUserPO)
{
@@ -545,43 +668,13 @@ class MyDropDocumentsPage extends KTStandardDispatcher {
$this->renegeratePermissionsForRole($oRoleAllocation->getRoleId(), $personalFolderID);
}
- //FIXME: Direct Database access
- function getFolderID($sFolderName) {
- $sQuery = 'SELECT id FROM folders WHERE name = \''.$sFolderName.'\'';
-
- $id = DBUtil::getResultArray($sQuery);
- return $id[0]['id'];
- }
-
- //this function returns the document link and document name to be displayed on the dashlet
- function getDocInfo($iDocId) {
- $oDocument = Document::get($iDocId);
-
- if (PEAR::isError($oDocument)) {
- return _kt('Document no longer exists.');
- }
-
- $sName = htmlentities($oDocument->getName(), ENT_NOQUOTES, 'UTF-8');
- $sLink = KTBrowseUtil::getUrlForDocument($oDocument);
-
- $aAnchorData = array();
- $aAnchorData[] = $sLink;
- $aAnchorData[] = $sName;
- return $aAnchorData;
- }
-
//This function is used to create the role, role allocation is done separately
function createRole ($sName)
{
- $this->startTransaction();
$oRole = Role::createFromArray(array('name' => $sName));
if (PEAR::isError($oRole) || ($oRole == false))
{
- if ($this->bTransactionStarted)
- {
- $this->rollbackTransaction();
- }
//return null on failure
return null;
}
@@ -630,6 +723,14 @@ class MyDropDocumentsPage extends KTStandardDispatcher {
}
//FIXME: Direct Database access
+ function getFolderID($sFolderName) {
+ $sQuery = 'SELECT id FROM folders WHERE name = \''.$sFolderName.'\'';
+
+ $id = DBUtil::getResultArray($sQuery);
+ return $id[0]['id'];
+ }
+
+ //FIXME: Direct Database access
function getGroupIdByName ($sName)
{
$sQuery = "SELECT id FROM groups_lookup WHERE name = ?";
@@ -672,7 +773,6 @@ class MyDropDocumentsPage extends KTStandardDispatcher {
$aNewFolders = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id');
if (PEAR::isError($aNewFolders)) {
- //$this->errorRedirectToMain(_kt('Failure to generate folderlisting.'));
echo _kt('Failure to generate folderlisting.');
}
$folder_queue = kt_array_merge ($folder_queue, (array) $aNewFolders); // push.
@@ -681,14 +781,12 @@ class MyDropDocumentsPage extends KTStandardDispatcher {
// update the folder.
$oFolder =& Folder::get($active_folder);
if (PEAR::isError($oFolder) || ($oFolder == false)) {
- //$this->errorRedirectToMain(_kt('Unable to locate folder: ') . $active_folder);
echo _kt('Unable to locate folder: ').$active_folder;
}
KTPermissionUtil::updatePermissionLookup($oFolder);
$aDocList =& Document::getList(array('folder_id = ?', $active_folder));
if (PEAR::isError($aDocList) || ($aDocList === false)) {
- //$this->errorRedirectToMain(sprintf(_kt('Unable to get documents in folder %s: %s'), $active_folder, $aDocList->getMessage()));
echo _kt('Unable to get documents in folder ').$active_folder;
}
@@ -699,65 +797,5 @@ class MyDropDocumentsPage extends KTStandardDispatcher {
}
}
}
-
- /*
- attempt to abstract the transaction-matching query.
-
- tables that are already defined (other than sec ones):
-
- - Documents (D)
- - Users (U)
- - TransactionTypes (DTT)
- - Document Transactions (DT)
-
- so where clausess can take advantage of those.
-
- */
- function getTransactionsMatchingQuery($oUser, $sJoinClause, $aExternalWhereClauses, $aExternalWhereParams, $aOptions = null) {
-
- $sSelectItems = 'DTT.name AS transaction_name, U.name AS user_name, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime, D.id as document_id, DT.transaction_namespace as namespace';
- $sBaseJoin = "FROM " . KTUtil::getTableName("document_transactions") . " AS DT " .
- "INNER JOIN " . KTUtil::getTableName("users") . " AS U ON DT.user_id = U.id " .
- "INNER JOIN " . KTUtil::getTableName("transaction_types") . " AS DTT ON DTT.namespace = DT.transaction_namespace " .
- "INNER JOIN " . KTUtil::getTableName("documents") . " AS D ON D.id = DT.document_id ";
-
- // now we're almost at partialquery like status.
- $perm_res = KTSearchUtil::permissionToSQL($oUser, 'ktcore.permissions.read');
- if (PEAR::isError($perm_res)) {
- return $perm_res;
- }
- list($sPermissionString, $aPermissionParams, $sPermissionJoin) = $perm_res;
-
- // compile the final list
- $aFinalWhere = kt_array_merge(array($sPermissionString,'D.creator_id IS NOT NULL'), $aExternalWhereClauses, array('D.status_id = ?'));
- $aFinalWhereParams = kt_array_merge($aPermissionParams, $aExternalWhereParams, array(LIVE));
-
- if (!is_array($aOptions)) {
- $aOptions = (array) $aOptions;
- }
- $sOrderBy = KTUtil::arrayGet($aOptions, 'orderby', 'DT.datetime DESC');
-
- // compile these.
- // NBM: do we need to wrap these in ()?
- $sWhereClause = implode(' AND ', $aFinalWhere);
- if (!empty($sWhereClause)) {
- $sWhereClause = 'WHERE ' . $sWhereClause;
- }
-
- $sQuery = sprintf("SELECT %s %s %s %s %s ORDER BY %s",
- $sSelectItems,
- $sBaseJoin,
- $sPermissionJoin,
- $sJoinClause,
- $sWhereClause,
- $sOrderBy
- );
-
- //var_dump(array($sQuery, $aFinalWhereParams));
-
- $res = DBUtil::getResultArray(array($sQuery, $aFinalWhereParams));
- //var_dump($res); exit(0);
- return $res;
- }
}
?>
diff --git a/plugins/MyDropDocumentsPlugin/MyDropDocumentsPlugin.php b/plugins/MyDropDocumentsPlugin/MyDropDocumentsPlugin.php
index ef9dc8f..38674bf 100644
--- a/plugins/MyDropDocumentsPlugin/MyDropDocumentsPlugin.php
+++ b/plugins/MyDropDocumentsPlugin/MyDropDocumentsPlugin.php
@@ -4,7 +4,7 @@
* License Version 1.1.2 ("License"); You may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.knowledgetree.com/KPL
- *
+ *
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights and
@@ -15,9 +15,9 @@
* (ii) the KnowledgeTree copyright notice
* in the same form as they appear in the distribution. See the License for
* requirements.
- *
+ *
* The Original Code is: KnowledgeTree Open Source
- *
+ *
* The Initial Developer of the Original Code is The Jam Warehouse Software
* (Pty) Ltd, trading as KnowledgeTree.
* Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
@@ -26,28 +26,30 @@
* Contributor( s): ______________________________________
*
*/
-
+
require_once(KT_LIB_DIR . "/plugins/plugin.inc.php");
require_once(KT_LIB_DIR . "/plugins/pluginregistry.inc.php");
class MyDropDocumentsPlugin extends KTPlugin
{
var $sNamespace = 'ktlive.mydropdocuments.plugin';
+ var $iVersion = 1;
var $autoRegister = true;
-
+
function MyDropDocumentsPlugin($sFilename = null) {
-
+
$res = parent::KTPlugin($sFilename);
$this->sFriendlyName = _kt('My Drop Documents');
return $res;
-
+
}
-
+
function setup() {
-
+
$this->registerDashlet('MyDropDocumentsDashlet', 'klive.mydropdocuments.dashlet', 'MyDropDocumentsDashlet.php');
$this->registerPage('MyDropDocuments', 'MyDropDocumentsPage', 'MyDropDocumentsPage.php');
-
+ $this->registerTrigger('user_create', 'postValidate', 'CreateUserFolderTrigger','ktlive.mydropdocuments.triggers.user_create', 'MyDropDocumentsDashlet.php');
+
require_once(KT_LIB_DIR . "/templating/templating.inc.php");
$oTemplating =& KTTemplating::getSingleton();
$oTemplating->addLocation('MyDropDocumentsDashlet', '/plugins/MyDropDocumentsPlugin/templates');
diff --git a/plugins/ktcore/admin/userManagement.php b/plugins/ktcore/admin/userManagement.php
index 56b07ca..4a711c8 100644
--- a/plugins/ktcore/admin/userManagement.php
+++ b/plugins/ktcore/admin/userManagement.php
@@ -5,7 +5,7 @@
* KnowledgeTree Community Edition
* Document Management Made Simple
* Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc.
- *
+ *
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
@@ -39,6 +39,7 @@
require_once(KT_LIB_DIR . '/database/dbutil.inc');
require_once(KT_LIB_DIR . '/users/User.inc');
+require_once(KT_LIB_DIR . '/users/userutil.inc.php');
require_once(KT_LIB_DIR . '/groups/GroupUtil.php');
require_once(KT_LIB_DIR . '/groups/Group.inc');
@@ -539,32 +540,21 @@ class KTUserAdminDispatcher extends KTAdminDispatcher {
$this->errorRedirectTo('addUser', _kt("You have entered an invalid character in your name."));
}
- $dupUser =& User::getByUserName($username);
- if(!PEAR::isError($dupUser)) {
- $this->errorRedirectTo('addUser', _kt("A user with that username already exists"));
- }
-
+ $oUser = KTUserUtil::createUser($username, $name, $password, $email_address, $email_notifications, $mobile_number, $max_sessions);
- $oUser =& User::createFromArray(array(
- "sUsername" => $username,
- "sName" => $name,
- "sPassword" => md5($password),
- "iQuotaMax" => 0,
- "iQuotaCurrent" => 0,
- "sEmail" => $email_address,
- "bEmailNotification" => $email_notifications,
- "sMobile" => $mobile_number,
- "bSmsNotification" => false, // FIXME do we auto-act if the user has a mobile?
- "iMaxSessions" => $max_sessions,
- ));
+ if(PEAR::isError($oUser)){
+ if($oUser->getMessage() == _kt("A user with that username already exists")){
+ $this->errorRedirectTo('addUser', _kt("A user with that username already exists"));
+ exit();
+ }
- if (PEAR::isError($oUser) || ($oUser == false)) {
$this->errorRedirectToMain(_kt("failed to create user."), sprintf("old_search=%s&do_search=1", $old_search));
- exit(0);
+ exit;
}
$this->successRedirectToMain(_kt('Created new user') . ': ' . $oUser->getUsername(), 'name=' . $oUser->getUsername(), sprintf("old_search=%s&do_search=1", $old_search));
+ return ;
}
function do_deleteUser() {
diff --git a/plugins/ktstandard/ldap/ldapbaseauthenticationprovider.inc.php b/plugins/ktstandard/ldap/ldapbaseauthenticationprovider.inc.php
index f632b10..92e4462 100644
--- a/plugins/ktstandard/ldap/ldapbaseauthenticationprovider.inc.php
+++ b/plugins/ktstandard/ldap/ldapbaseauthenticationprovider.inc.php
@@ -5,7 +5,7 @@
* KnowledgeTree Community Edition
* Document Management Made Simple
* Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc.
- *
+ *
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
@@ -322,11 +322,6 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider {
$username = KTUtil::arrayGet($_REQUEST, 'ldap_username');
if (empty($username)) { $this->errorRedirectToMain(_kt('You must specify a new username.')); }
- $dupUser =& User::getByUserName($username);
- if(!PEAR::isError($dupUser)) {
- $this->errorRedirectToMain(_kt("A user with that username already exists"));
- }
-
$email_address = KTUtil::arrayGet($_REQUEST, 'email_address');
$email_notifications = KTUtil::arrayGet($_REQUEST, 'email_notifications', false);
if ($email_notifications !== false) $email_notifications = true;
@@ -334,21 +329,10 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider {
$max_sessions = KTUtil::arrayGet($_REQUEST, 'max_sessions', '3');
// FIXME check for numeric max_sessions... db-error else?
- $oUser =& User::createFromArray(array(
- "Username" => $username,
- "Name" => $name,
- "Email" => $email_address,
- "EmailNotification" => $email_notifications,
- "SmsNotification" => false, // FIXME do we auto-act if the user has a mobile?
- "MaxSessions" => $max_sessions,
- "authenticationsourceid" => $oSource->getId(),
- "authenticationdetails" => $dn,
- "authenticationdetails2" => $samaccountname,
- "password" => "",
- ));
+ $oUser = KTUserUtil::createUser($username, $name, '', $email_address, $email_notifications, '', $max_sessions, $oSource->getId(), $dn, $samaccountname);
if (PEAR::isError($oUser) || ($oUser == false)) {
- $this->errorRedirectToMain(_kt("failed to create user") . ": " . $oUser->message);
+ $this->errorRedirectToMain($oUser->getMessage());
exit(0);
}
@@ -368,24 +352,24 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider {
$aResults = $oAuthenticator->getUser($sId);
$dn = $sId;
$sUserName = $aResults[$this->aAttributes[1]];
-
+
if ($sUserName == '') {
$dnParts = ldap_explode_dn($dn, 0);
$sUserName = end(explode('=',$dnParts[0]));;
}
-
+
// With LDAP, if the 'uid' is null then try using the 'givenname' instead.
// See activedirectoryauthenticationprovider.inc.php and ldapauthenticationprovider.inc.php for details.
if($this->sAuthenticatorClass == "KTLDAPAuthenticator" && empty($sUserName)) {
$sUserName = strtolower($aResults[$this->aAttributes[2]]);
}
$sName = $aResults[$this->aAttributes[0]];
-
+
if ($sName == '') {
$dnParts = ldap_explode_dn($dn, 0);
$sName = end(explode('=',$dnParts[0]));;
}
-
+
$sEmailAddress = $aResults[$this->aAttributes[4]];
$sMobileNumber = $aResults[$this->aAttributes[5]];
@@ -397,19 +381,9 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider {
$appending = true;
} else $appending = false;
}
-
- $oUser = User::createFromArray(array(
- "Username" => $sUserName,
- "Name" => $sName,
- "Email" => $sEmailAddress,
- "EmailNotification" => true,
- "SmsNotification" => false, // FIXME do we auto-act if the user has a mobile?
- "MaxSessions" => 3,
- "authenticationsourceid" => $oSource->getId(),
- "authenticationdetails" => $dn,
- "authenticationdetails2" => $sUserName,
- "password" => "",
- ));
+
+ $oUser = KTUserUtil::createUser($sUserName, $sName, '', $sEmailAddress, true, '', 3, $oSource->getId(), $dn, $sUserName);
+
$aNames[] = $sName;
}
$this->successRedirectToMain(_kt("Added users") . ": " . join(', ', $aNames));