Commit c3eeca855b7ccf33cfea112c3706741499c54bdf
1 parent
8a07991b
Added triggers into the user creation (refactored into new class), set droppedDo…
…cuments folder to be created with the user. Committed by: Megan Watson Reviewed by: Jarrett Jordaan
Showing
6 changed files
with
417 additions
and
297 deletions
lib/users/userutil.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * $Id$ | |
| 4 | + * | |
| 5 | + * KnowledgeTree Community Edition | |
| 6 | + * Document Management Made Simple | |
| 7 | + * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc. | |
| 8 | + * | |
| 9 | + * | |
| 10 | + * This program is free software; you can redistribute it and/or modify it under | |
| 11 | + * the terms of the GNU General Public License version 3 as published by the | |
| 12 | + * Free Software Foundation. | |
| 13 | + * | |
| 14 | + * This program is distributed in the hope that it will be useful, but WITHOUT | |
| 15 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
| 16 | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
| 17 | + * details. | |
| 18 | + * | |
| 19 | + * You should have received a copy of the GNU General Public License | |
| 20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 21 | + * | |
| 22 | + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 23 | + * California 94120-7775, or email info@knowledgetree.com. | |
| 24 | + * | |
| 25 | + * The interactive user interfaces in modified source and object code versions | |
| 26 | + * of this program must display Appropriate Legal Notices, as required under | |
| 27 | + * Section 5 of the GNU General Public License version 3. | |
| 28 | + * | |
| 29 | + * In accordance with Section 7(b) of the GNU General Public License version 3, | |
| 30 | + * these Appropriate Legal Notices must retain the display of the "Powered by | |
| 31 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 32 | + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | |
| 33 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 34 | + * copyright notice. | |
| 35 | + * Contributor( s): ______________________________________ | |
| 36 | + * | |
| 37 | + */ | |
| 38 | + | |
| 39 | +require_once(KT_LIB_DIR . '/users/User.inc'); | |
| 40 | + | |
| 41 | +class KTUserUtil | |
| 42 | +{ | |
| 43 | + 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) | |
| 44 | + { | |
| 45 | + $dupUser =& User::getByUserName($username); | |
| 46 | + if(!PEAR::isError($dupUser)) { | |
| 47 | + return PEAR::raiseError(_kt("A user with that username already exists")); | |
| 48 | + } | |
| 49 | + | |
| 50 | + $oUser =& User::createFromArray(array( | |
| 51 | + "sUsername" => $username, | |
| 52 | + "sName" => $name, | |
| 53 | + "sPassword" => md5($password), | |
| 54 | + "iQuotaMax" => 0, | |
| 55 | + "iQuotaCurrent" => 0, | |
| 56 | + "sEmail" => $email_address, | |
| 57 | + "bEmailNotification" => $email_notifications, | |
| 58 | + "sMobile" => $mobile_number, | |
| 59 | + "bSmsNotification" => false, // FIXME do we auto-act if the user has a mobile? | |
| 60 | + "iMaxSessions" => $max_sessions, | |
| 61 | + "authenticationsourceid" => $source_id, | |
| 62 | + "authenticationdetails" => $details, | |
| 63 | + "authenticationdetails2" => $details2, | |
| 64 | + )); | |
| 65 | + | |
| 66 | + if (PEAR::isError($oUser) || ($oUser == false)) { | |
| 67 | + return PEAR::raiseError(_kt("failed to create user.")); | |
| 68 | + } | |
| 69 | + | |
| 70 | + // run triggers on user creation | |
| 71 | + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | |
| 72 | + $aTriggers = $oKTTriggerRegistry->getTriggers('user_create', 'postValidate'); | |
| 73 | + | |
| 74 | + foreach ($aTriggers as $aTrigger) { | |
| 75 | + $sTrigger = $aTrigger[0]; | |
| 76 | + $oTrigger = new $sTrigger; | |
| 77 | + $aInfo = array( | |
| 78 | + 'user' => $oUser, | |
| 79 | + ); | |
| 80 | + $oTrigger->setInfo($aInfo); | |
| 81 | + $ret = $oTrigger->postValidate(); | |
| 82 | + } | |
| 83 | + | |
| 84 | + return $oUser; | |
| 85 | + } | |
| 86 | +} | |
| 87 | + | |
| 88 | + | |
| 89 | +?> | |
| 0 | 90 | \ No newline at end of file | ... | ... |
plugins/MyDropDocumentsPlugin/MyDropDocumentsDashlet.php
| ... | ... | @@ -5,75 +5,102 @@ |
| 5 | 5 | * KnowledgeTree Community Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc. |
| 8 | - * | |
| 9 | - * | |
| 8 | + * | |
| 9 | + * | |
| 10 | 10 | * This program is free software; you can redistribute it and/or modify it under |
| 11 | 11 | * the terms of the GNU General Public License version 3 as published by the |
| 12 | 12 | * Free Software Foundation. |
| 13 | - * | |
| 13 | + * | |
| 14 | 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 17 | 17 | * details. |
| 18 | - * | |
| 18 | + * | |
| 19 | 19 | * You should have received a copy of the GNU General Public License |
| 20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | - * | |
| 22 | - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 21 | + * | |
| 22 | + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | |
| 23 | 23 | * California 94120-7775, or email info@knowledgetree.com. |
| 24 | - * | |
| 24 | + * | |
| 25 | 25 | * The interactive user interfaces in modified source and object code versions |
| 26 | 26 | * of this program must display Appropriate Legal Notices, as required under |
| 27 | 27 | * Section 5 of the GNU General Public License version 3. |
| 28 | - * | |
| 28 | + * | |
| 29 | 29 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 30 | 30 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 31 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 31 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 32 | 32 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 33 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 34 | 34 | * copyright notice. |
| 35 | 35 | * Contributor( s): ______________________________________ |
| 36 | 36 | * |
| 37 | 37 | */ |
| 38 | 38 | |
| 39 | +require_once('MyDropDocumentsPage.php'); | |
| 40 | + | |
| 39 | 41 | class MyDropDocumentsDashlet extends KTBaseDashlet { |
| 40 | 42 | var $oUser; |
| 41 | - //var $sClass = 'ktError'; | |
| 42 | - | |
| 43 | + | |
| 43 | 44 | function MyDropDocumentsDashlet(){ |
| 44 | 45 | $this->sTitle = _kt('My Dropped Documents'); |
| 45 | 46 | } |
| 46 | - | |
| 47 | + | |
| 47 | 48 | function is_active($oUser) { |
| 48 | 49 | $this->oUser = $oUser; |
| 49 | 50 | return true; |
| 50 | 51 | } |
| 51 | - | |
| 52 | - | |
| 53 | -/* | |
| 52 | + | |
| 53 | + | |
| 54 | +/* | |
| 54 | 55 | function is_active($oUser) { |
| 55 | 56 | $this->oUser = $oUser; |
| 56 | 57 | return Permission::userIsSystemAdministrator($oUser); |
| 57 | 58 | } |
| 58 | 59 | */ |
| 59 | - | |
| 60 | + | |
| 60 | 61 | function render() { |
| 61 | 62 | global $main; |
| 62 | 63 | $main->requireJSResource("plugins/MyDropDocumentsPlugin/js/update.js"); |
| 63 | - | |
| 64 | + | |
| 64 | 65 | $oPlugin =& $this->oPlugin; |
| 65 | - | |
| 66 | + | |
| 66 | 67 | $oTemplating =& KTTemplating::getSingleton(); |
| 67 | - $oTemplate = $oTemplating->loadTemplate('MyDropDocumentsPlugin/dashlet'); | |
| 68 | - | |
| 68 | + $oTemplate = $oTemplating->loadTemplate('MyDropDocumentsPlugin/dashlet'); | |
| 69 | + | |
| 69 | 70 | $aTemplateData = array( |
| 70 | 71 | 'context' => $this, |
| 71 | 72 | 'url' => $oPlugin->getPagePath('MyDropDocuments'), |
| 72 | - | |
| 73 | + | |
| 73 | 74 | ); |
| 74 | - | |
| 75 | - | |
| 75 | + | |
| 76 | + | |
| 76 | 77 | return $oTemplate->render($aTemplateData); |
| 77 | 78 | } |
| 78 | 79 | } |
| 80 | + | |
| 81 | + | |
| 82 | +class CreateUserFolderTrigger { | |
| 83 | + var $namespace = 'ktlive.mydropdocuments.triggers.user_create'; | |
| 84 | + var $aInfo = null; | |
| 85 | + | |
| 86 | + function setInfo($aInfo) { | |
| 87 | + $this->aInfo = $aInfo; | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * Create the dropped documents folder for the user on user creation | |
| 92 | + */ | |
| 93 | + function postValidate() { | |
| 94 | + $oUser = $this->aInfo['user']; | |
| 95 | + | |
| 96 | + if(!($oUser instanceof User) || !($oUser instanceof UserProxy)){ | |
| 97 | + return false; | |
| 98 | + } | |
| 99 | + | |
| 100 | + $drop = new DropFolderCreation($oUser); | |
| 101 | + $drop->checkFolders(); | |
| 102 | + } | |
| 103 | +} | |
| 104 | + | |
| 105 | + | |
| 79 | 106 | ?> | ... | ... |
plugins/MyDropDocumentsPlugin/MyDropDocumentsPage.php
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | * KnowledgeTree Community Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc. |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * |
| 10 | 10 | * This program is free software; you can redistribute it and/or modify it under |
| 11 | 11 | * the terms of the GNU General Public License version 3 as published by the |
| ... | ... | @@ -73,6 +73,239 @@ class MyDropDocumentsPage extends KTStandardDispatcher { |
| 73 | 73 | $oUser = $this->oUser; |
| 74 | 74 | $sUserName = (string)$this->oUser->getUserName(); |
| 75 | 75 | |
| 76 | + // Check for the DropDocuments folder in root | |
| 77 | + if(!Folder::FolderExistsName('DroppedDocuments', $iRootID)) | |
| 78 | + { | |
| 79 | + return _kt('The Dropped Documents folder does not exist. Please contact your System Administrator'); | |
| 80 | + } | |
| 81 | + | |
| 82 | + $iDropDocsFolderID = $this->getFolderID('DroppedDocuments'); | |
| 83 | + | |
| 84 | + // Check for users folder | |
| 85 | + if(!Folder::FolderExistsName($sUserName, $iDropDocsFolderID)) | |
| 86 | + { | |
| 87 | + return _kt('Your personal folder under the Dropped Documents folder does not exist. Please contact your System Administrator'); | |
| 88 | + } | |
| 89 | + | |
| 90 | + // Get documents | |
| 91 | + return $this->getUsersDocument($sUserName, $iDropDocsFolderID); | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Method to get any documents added by the user via the Drop Box. | |
| 96 | + * Returns the HTML displaying the document list. | |
| 97 | + * | |
| 98 | + * @param string $sUserName | |
| 99 | + * @param numeric $iDropDocsFolderID | |
| 100 | + * @return string HTML - the document list on success or an error message on failure | |
| 101 | + */ | |
| 102 | + function getUsersDocument($sUserName, $iDropDocsFolderID) | |
| 103 | + { | |
| 104 | + $oUser = $this->oUser; | |
| 105 | + $oDropDocsFolder = Folder::get($iDropDocsFolderID); | |
| 106 | + | |
| 107 | + $fullPath = $oDropDocsFolder->getFullPath() . '/' . $sUserName; | |
| 108 | + | |
| 109 | + $aExternalWhereClauses[] = '(DT.transaction_namespace IN (?,?,?) AND (D.full_path LIKE "'.$fullPath.'/%"))'; | |
| 110 | + $aExternalWhereParams[] = 'ktcore.transactions.create'; | |
| 111 | + $aExternalWhereParams[] = 'ktcore.transactions.check_in'; | |
| 112 | + $aExternalWhereParams[] = 'ktcore.transactions.event'; | |
| 113 | + | |
| 114 | + | |
| 115 | + $aDocumentTransactions = $this->getTransactionsMatchingQuery($oUser, '', $aExternalWhereClauses, $aExternalWhereParams); | |
| 116 | + if (empty($aDocumentTransactions) || PEAR::isError($aDocumentTransactions)) | |
| 117 | + { | |
| 118 | + if(PEAR::isError($aDocumentTransactions)){ | |
| 119 | + global $default; | |
| 120 | + $default->log->debug('Error retrieving dropped documents - '.$aDocumentTransactions->getMessage()); | |
| 121 | + } | |
| 122 | + | |
| 123 | + return _kt('<span class="descriptiveText"> You do not have any dropped documents </span><br><br><br>'); | |
| 124 | + } | |
| 125 | + | |
| 126 | + $maxcount = 5; | |
| 127 | + | |
| 128 | + $sReturnTable = '<span class="descriptiveText">'._kt('Recently Dropped Documents').'</span> | |
| 129 | + <table width="100%" class="kt_collection drop_box" cellspacing="0"> | |
| 130 | + | |
| 131 | + <thead> | |
| 132 | + <tr> | |
| 133 | + <th width="100%">'._kt('Document').'</th> | |
| 134 | + <th width="1%">'._kt('Date Dropped').'</th> | |
| 135 | + </tr> | |
| 136 | + </thead> | |
| 137 | + <tbody>'; | |
| 138 | + | |
| 139 | + $sOddorEven = ''; | |
| 140 | + $count = 1; | |
| 141 | + $rendered = array(); | |
| 142 | + foreach ($aDocumentTransactions as $aRow) | |
| 143 | + { | |
| 144 | + $documentId = $aRow['document_id']; | |
| 145 | + if (in_array($documentId, $rendered)) | |
| 146 | + { | |
| 147 | + continue; | |
| 148 | + } | |
| 149 | + | |
| 150 | + $rendered[] = $documentId; | |
| 151 | + $oDocument = Document::get($documentId); | |
| 152 | + | |
| 153 | + $sContentType = KTMime::getIconPath($oDocument->getMimeTypeID()); | |
| 154 | + $aAnchorData = $this->getDocInfo($documentId); | |
| 155 | + $sLink = $aAnchorData[0]; | |
| 156 | + $sShortDocName = $sDocName = $aAnchorData[1]; | |
| 157 | + | |
| 158 | + $iDocLength = strlen($sDocName); | |
| 159 | + $iMax = 40; | |
| 160 | + if ( $iDocLength > $iMax ) | |
| 161 | + { | |
| 162 | + $sShortDocName = substr($sDocName, 0, $iMax) . '...'; | |
| 163 | + } | |
| 164 | + | |
| 165 | + $sOddorEven = ($count%2 == 0)?'even':'odd'; | |
| 166 | + | |
| 167 | + $sReturnTable .= '<tr class="'.$sOddorEven.'">'. | |
| 168 | + '<td width="100%"><span class="contenttype '.$sContentType.'"><a title="'.$sDocName.'" href='.$sLink.'>'.$sShortDocName.'</a></span></td>'. | |
| 169 | + '<td width="1%">'.$aRow['datetime'].'</td>'. | |
| 170 | + '</tr>'; | |
| 171 | + if (++$count > 5) | |
| 172 | + { | |
| 173 | + break; | |
| 174 | + } | |
| 175 | + } | |
| 176 | + | |
| 177 | + $subFolders = Folder::getByParentId($iDropDocsFolderID); | |
| 178 | + if(PEAR::isError($subFolders) || empty($subFolders)){ | |
| 179 | + $iMyDocsFolderID = $iDropDocsFolderID; | |
| 180 | + }else{ | |
| 181 | + foreach ($subFolders as $sub){ | |
| 182 | + if($sub->getName() == $sUserName){ | |
| 183 | + $iMyDocsFolderID = $sub->getID(); | |
| 184 | + break; | |
| 185 | + } | |
| 186 | + } | |
| 187 | + } | |
| 188 | + | |
| 189 | + $location = 'browse.php?fFolderId='.$iMyDocsFolderID; | |
| 190 | + $sReturnTable .= '</tbody>'. | |
| 191 | + '</table>'. | |
| 192 | + '<br>'. | |
| 193 | + '<a href="'.$location.'">'._kt(' View All').' </a><br><br>'; | |
| 194 | + return $sReturnTable; | |
| 195 | + } | |
| 196 | + | |
| 197 | + //this function returns the document link and document name to be displayed on the dashlet | |
| 198 | + function getDocInfo($iDocId) { | |
| 199 | + $oDocument = Document::get($iDocId); | |
| 200 | + | |
| 201 | + if (PEAR::isError($oDocument)) { | |
| 202 | + return _kt('Document no longer exists.'); | |
| 203 | + } | |
| 204 | + | |
| 205 | + $sName = htmlentities($oDocument->getName(), ENT_NOQUOTES, 'UTF-8'); | |
| 206 | + $sLink = KTBrowseUtil::getUrlForDocument($oDocument); | |
| 207 | + | |
| 208 | + $aAnchorData = array(); | |
| 209 | + $aAnchorData[] = $sLink; | |
| 210 | + $aAnchorData[] = $sName; | |
| 211 | + return $aAnchorData; | |
| 212 | + } | |
| 213 | + | |
| 214 | + //FIXME: Direct Database access | |
| 215 | + function getFolderID($sFolderName) { | |
| 216 | + $sQuery = 'SELECT id FROM folders WHERE name = \''.$sFolderName.'\''; | |
| 217 | + | |
| 218 | + $id = DBUtil::getResultArray($sQuery); | |
| 219 | + return $id[0]['id']; | |
| 220 | + } | |
| 221 | + | |
| 222 | + function handleOutput($sOutput) { | |
| 223 | + print $sOutput; | |
| 224 | + } | |
| 225 | + | |
| 226 | + /* | |
| 227 | + attempt to abstract the transaction-matching query. | |
| 228 | + | |
| 229 | + tables that are already defined (other than sec ones): | |
| 230 | + | |
| 231 | + - Documents (D) | |
| 232 | + - Users (U) | |
| 233 | + - TransactionTypes (DTT) | |
| 234 | + - Document Transactions (DT) | |
| 235 | + | |
| 236 | + so where clausess can take advantage of those. | |
| 237 | + | |
| 238 | + */ | |
| 239 | + function getTransactionsMatchingQuery($oUser, $sJoinClause, $aExternalWhereClauses, $aExternalWhereParams, $aOptions = null) { | |
| 240 | + | |
| 241 | + $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'; | |
| 242 | + $sBaseJoin = "FROM " . KTUtil::getTableName("document_transactions") . " AS DT " . | |
| 243 | + "INNER JOIN " . KTUtil::getTableName("users") . " AS U ON DT.user_id = U.id " . | |
| 244 | + "INNER JOIN " . KTUtil::getTableName("transaction_types") . " AS DTT ON DTT.namespace = DT.transaction_namespace " . | |
| 245 | + "INNER JOIN " . KTUtil::getTableName("documents") . " AS D ON D.id = DT.document_id "; | |
| 246 | + | |
| 247 | + // now we're almost at partialquery like status. | |
| 248 | + $perm_res = KTSearchUtil::permissionToSQL($oUser, 'ktcore.permissions.read'); | |
| 249 | + if (PEAR::isError($perm_res)) { | |
| 250 | + return $perm_res; | |
| 251 | + } | |
| 252 | + list($sPermissionString, $aPermissionParams, $sPermissionJoin) = $perm_res; | |
| 253 | + | |
| 254 | + // compile the final list | |
| 255 | + $aFinalWhere = kt_array_merge(array($sPermissionString,'D.creator_id IS NOT NULL'), $aExternalWhereClauses, array('D.status_id = ?')); | |
| 256 | + $aFinalWhereParams = kt_array_merge($aPermissionParams, $aExternalWhereParams, array(LIVE)); | |
| 257 | + | |
| 258 | + if (!is_array($aOptions)) { | |
| 259 | + $aOptions = (array) $aOptions; | |
| 260 | + } | |
| 261 | + $sOrderBy = KTUtil::arrayGet($aOptions, 'orderby', 'DT.datetime DESC'); | |
| 262 | + | |
| 263 | + // compile these. | |
| 264 | + // NBM: do we need to wrap these in ()? | |
| 265 | + $sWhereClause = implode(' AND ', $aFinalWhere); | |
| 266 | + if (!empty($sWhereClause)) { | |
| 267 | + $sWhereClause = 'WHERE ' . $sWhereClause; | |
| 268 | + } | |
| 269 | + | |
| 270 | + $sQuery = sprintf("SELECT %s %s %s %s %s ORDER BY %s", | |
| 271 | + $sSelectItems, | |
| 272 | + $sBaseJoin, | |
| 273 | + $sPermissionJoin, | |
| 274 | + $sJoinClause, | |
| 275 | + $sWhereClause, | |
| 276 | + $sOrderBy | |
| 277 | + ); | |
| 278 | + | |
| 279 | + //var_dump(array($sQuery, $aFinalWhereParams)); | |
| 280 | + | |
| 281 | + $res = DBUtil::getResultArray(array($sQuery, $aFinalWhereParams)); | |
| 282 | + //var_dump($res); exit(0); | |
| 283 | + return $res; | |
| 284 | + } | |
| 285 | + | |
| 286 | +} | |
| 287 | + | |
| 288 | +class DropFolderCreation | |
| 289 | +{ | |
| 290 | + private $oUser; | |
| 291 | + private $ktapi; | |
| 292 | + private $session; | |
| 293 | + | |
| 294 | + function __construct($oUser) | |
| 295 | + { | |
| 296 | + $this->oUser = $oUser; | |
| 297 | + } | |
| 298 | + | |
| 299 | + function checkFolders() | |
| 300 | + { | |
| 301 | + // Check if users folder exists in DropDocuments folder | |
| 302 | + // - it does -> continue on to check for documents | |
| 303 | + // - it doesn't -> switch to root user and create it | |
| 304 | + | |
| 305 | + global $default; | |
| 306 | + $iRootID = (int)1; | |
| 307 | + $oUser = $this->oUser; | |
| 308 | + $sUserName = (string)$this->oUser->getUserName(); | |
| 76 | 309 | |
| 77 | 310 | // Check for the DropDocuments folder in root |
| 78 | 311 | if(!Folder::FolderExistsName('DroppedDocuments', $iRootID)) |
| ... | ... | @@ -111,9 +344,6 @@ class MyDropDocumentsPage extends KTStandardDispatcher { |
| 111 | 344 | return $res; |
| 112 | 345 | } |
| 113 | 346 | } |
| 114 | - | |
| 115 | - // Get documents | |
| 116 | - return $this->getUsersDocument($sUserName, $iDropDocsFolderID); | |
| 117 | 347 | } |
| 118 | 348 | |
| 119 | 349 | /** |
| ... | ... | @@ -122,6 +352,7 @@ class MyDropDocumentsPage extends KTStandardDispatcher { |
| 122 | 352 | */ |
| 123 | 353 | function createPersonalFolder($sUserName, $iDropDocsFolderID) |
| 124 | 354 | { |
| 355 | + global $default; | |
| 125 | 356 | // Add the users folder |
| 126 | 357 | // Add the user to the WorkSpaceAdmin role on the DroppedDocuments folder |
| 127 | 358 | // Define users folder permissions |
| ... | ... | @@ -200,6 +431,7 @@ class MyDropDocumentsPage extends KTStandardDispatcher { |
| 200 | 431 | */ |
| 201 | 432 | function createDropDocsFolder() |
| 202 | 433 | { |
| 434 | + global $default; | |
| 203 | 435 | $root = $this->ktapi->get_root_folder(); |
| 204 | 436 | |
| 205 | 437 | if(PEAR::isError($root)){ |
| ... | ... | @@ -211,7 +443,7 @@ class MyDropDocumentsPage extends KTStandardDispatcher { |
| 211 | 443 | $dropDocsFolder = $root->add_folder('DroppedDocuments'); |
| 212 | 444 | |
| 213 | 445 | if(PEAR::isError($dropDocsFolder)){ |
| 214 | - $default->log->debug('MyDropDocuments: could not create DroppedDocuments folder '.$dropDocsFolder->getMessage()); | |
| 446 | + $defaultf->log->debug('MyDropDocuments: could not create DroppedDocuments folder '.$dropDocsFolder->getMessage()); | |
| 215 | 447 | return _kt('Error - could not create the DropppedDocuments folder: ').$dropDocsFolder->getMessage(); |
| 216 | 448 | } |
| 217 | 449 | |
| ... | ... | @@ -254,115 +486,6 @@ class MyDropDocumentsPage extends KTStandardDispatcher { |
| 254 | 486 | return null; |
| 255 | 487 | } |
| 256 | 488 | |
| 257 | - /** | |
| 258 | - * Method to get any documents added by the user via the Drop Box. | |
| 259 | - * Returns the HTML displaying the document list. | |
| 260 | - * | |
| 261 | - * @param string $sUserName | |
| 262 | - * @param numeric $iDropDocsFolderID | |
| 263 | - * @return string HTML - the document list on success or an error message on failure | |
| 264 | - */ | |
| 265 | - function getUsersDocument($sUserName, $iDropDocsFolderID) | |
| 266 | - { | |
| 267 | - $oUser = $this->oUser; | |
| 268 | - $oDropDocsFolder = Folder::get($iDropDocsFolderID); | |
| 269 | - | |
| 270 | - $fullPath = $oDropDocsFolder->getFullPath() . '/' . $sUserName; | |
| 271 | - | |
| 272 | - $aExternalWhereClauses[] = '(DT.transaction_namespace IN (?,?,?) AND (D.full_path LIKE "'.$fullPath.'/%"))'; | |
| 273 | - $aExternalWhereParams[] = 'ktcore.transactions.create'; | |
| 274 | - $aExternalWhereParams[] = 'ktcore.transactions.check_in'; | |
| 275 | - $aExternalWhereParams[] = 'ktcore.transactions.event'; | |
| 276 | - | |
| 277 | - | |
| 278 | - $aDocumentTransactions = $this->getTransactionsMatchingQuery($oUser, '', $aExternalWhereClauses, $aExternalWhereParams); | |
| 279 | - if (empty($aDocumentTransactions) || PEAR::isError($aDocumentTransactions)) | |
| 280 | - { | |
| 281 | - if(PEAR::isError($aDocumentTransactions)){ | |
| 282 | - global $default; | |
| 283 | - $default->log->debug('Error retrieving dropped documents - '.$aDocumentTransactions->getMessage()); | |
| 284 | - } | |
| 285 | - | |
| 286 | - return _kt('<span class="descriptiveText"> You do not have any dropped documents </span><br><br><br>'); | |
| 287 | - } | |
| 288 | - | |
| 289 | - $maxcount = 5; | |
| 290 | - | |
| 291 | - $sReturnTable = '<span class="descriptiveText">'._kt('Recently Dropped Documents').'</span> | |
| 292 | - <table width="100%" class="kt_collection drop_box" cellspacing="0"> | |
| 293 | - | |
| 294 | - <thead> | |
| 295 | - <tr> | |
| 296 | - <th width="100%">'._kt('Document').'</th> | |
| 297 | - <th width="1%">'._kt('Date Dropped').'</th> | |
| 298 | - </tr> | |
| 299 | - </thead> | |
| 300 | - <tbody>'; | |
| 301 | - | |
| 302 | - $sOddorEven = ''; | |
| 303 | - $count = 1; | |
| 304 | - $rendered = array(); | |
| 305 | - foreach ($aDocumentTransactions as $aRow) | |
| 306 | - { | |
| 307 | - $documentId = $aRow['document_id']; | |
| 308 | - if (in_array($documentId, $rendered)) | |
| 309 | - { | |
| 310 | - continue; | |
| 311 | - } | |
| 312 | - | |
| 313 | - $rendered[] = $documentId; | |
| 314 | - $oDocument = Document::get($documentId); | |
| 315 | - | |
| 316 | - $sContentType = KTMime::getIconPath($oDocument->getMimeTypeID()); | |
| 317 | - $aAnchorData = $this->getDocInfo($documentId); | |
| 318 | - $sLink = $aAnchorData[0]; | |
| 319 | - $sShortDocName = $sDocName = $aAnchorData[1]; | |
| 320 | - | |
| 321 | - $iDocLength = strlen($sDocName); | |
| 322 | - $iMax = 40; | |
| 323 | - if ( $iDocLength > $iMax ) | |
| 324 | - { | |
| 325 | - $sShortDocName = substr($sDocName, 0, $iMax) . '...'; | |
| 326 | - } | |
| 327 | - | |
| 328 | - $sOddorEven = ($count%2 == 0)?'even':'odd'; | |
| 329 | - | |
| 330 | - $sReturnTable .= '<tr class="'.$sOddorEven.'">'. | |
| 331 | - '<td width="100%"><span class="contenttype '.$sContentType.'"><a title="'.$sDocName.'" href='.$sLink.'>'.$sShortDocName.'</a></span></td>'. | |
| 332 | - '<td width="1%">'.$aRow['datetime'].'</td>'. | |
| 333 | - '</tr>'; | |
| 334 | - if (++$count > 5) | |
| 335 | - { | |
| 336 | - break; | |
| 337 | - } | |
| 338 | - } | |
| 339 | - | |
| 340 | - $subFolders = Folder::getByParentId($iDropDocsFolderID); | |
| 341 | - if(PEAR::isError($subFolders) || empty($subFolders)){ | |
| 342 | - $iMyDocsFolderID = $iDropDocsFolderID; | |
| 343 | - }else{ | |
| 344 | - foreach ($subFolders as $sub){ | |
| 345 | - if($sub->getName() == $sUserName){ | |
| 346 | - $iMyDocsFolderID = $sub->getID(); | |
| 347 | - break; | |
| 348 | - } | |
| 349 | - } | |
| 350 | - } | |
| 351 | - | |
| 352 | - $location = 'browse.php?fFolderId='.$iMyDocsFolderID; | |
| 353 | - $sReturnTable .= '</tbody>'. | |
| 354 | - '</table>'. | |
| 355 | - '<br>'. | |
| 356 | - '<a href="'.$location.'">'._kt(' View All').' </a><br><br>'; | |
| 357 | - //$this->session->logout(); | |
| 358 | - | |
| 359 | - return $sReturnTable; | |
| 360 | - } | |
| 361 | - | |
| 362 | - function handleOutput($sOutput) { | |
| 363 | - print $sOutput; | |
| 364 | - } | |
| 365 | - | |
| 366 | 489 | //This function is used to set the permission on the dropdocuments folder |
| 367 | 490 | function setUserDocsPermissions($oUserPO) |
| 368 | 491 | { |
| ... | ... | @@ -545,43 +668,13 @@ class MyDropDocumentsPage extends KTStandardDispatcher { |
| 545 | 668 | $this->renegeratePermissionsForRole($oRoleAllocation->getRoleId(), $personalFolderID); |
| 546 | 669 | } |
| 547 | 670 | |
| 548 | - //FIXME: Direct Database access | |
| 549 | - function getFolderID($sFolderName) { | |
| 550 | - $sQuery = 'SELECT id FROM folders WHERE name = \''.$sFolderName.'\''; | |
| 551 | - | |
| 552 | - $id = DBUtil::getResultArray($sQuery); | |
| 553 | - return $id[0]['id']; | |
| 554 | - } | |
| 555 | - | |
| 556 | - //this function returns the document link and document name to be displayed on the dashlet | |
| 557 | - function getDocInfo($iDocId) { | |
| 558 | - $oDocument = Document::get($iDocId); | |
| 559 | - | |
| 560 | - if (PEAR::isError($oDocument)) { | |
| 561 | - return _kt('Document no longer exists.'); | |
| 562 | - } | |
| 563 | - | |
| 564 | - $sName = htmlentities($oDocument->getName(), ENT_NOQUOTES, 'UTF-8'); | |
| 565 | - $sLink = KTBrowseUtil::getUrlForDocument($oDocument); | |
| 566 | - | |
| 567 | - $aAnchorData = array(); | |
| 568 | - $aAnchorData[] = $sLink; | |
| 569 | - $aAnchorData[] = $sName; | |
| 570 | - return $aAnchorData; | |
| 571 | - } | |
| 572 | - | |
| 573 | 671 | //This function is used to create the role, role allocation is done separately |
| 574 | 672 | function createRole ($sName) |
| 575 | 673 | { |
| 576 | - $this->startTransaction(); | |
| 577 | 674 | $oRole = Role::createFromArray(array('name' => $sName)); |
| 578 | 675 | |
| 579 | 676 | if (PEAR::isError($oRole) || ($oRole == false)) |
| 580 | 677 | { |
| 581 | - if ($this->bTransactionStarted) | |
| 582 | - { | |
| 583 | - $this->rollbackTransaction(); | |
| 584 | - } | |
| 585 | 678 | //return null on failure |
| 586 | 679 | return null; |
| 587 | 680 | } |
| ... | ... | @@ -630,6 +723,14 @@ class MyDropDocumentsPage extends KTStandardDispatcher { |
| 630 | 723 | } |
| 631 | 724 | |
| 632 | 725 | //FIXME: Direct Database access |
| 726 | + function getFolderID($sFolderName) { | |
| 727 | + $sQuery = 'SELECT id FROM folders WHERE name = \''.$sFolderName.'\''; | |
| 728 | + | |
| 729 | + $id = DBUtil::getResultArray($sQuery); | |
| 730 | + return $id[0]['id']; | |
| 731 | + } | |
| 732 | + | |
| 733 | + //FIXME: Direct Database access | |
| 633 | 734 | function getGroupIdByName ($sName) |
| 634 | 735 | { |
| 635 | 736 | $sQuery = "SELECT id FROM groups_lookup WHERE name = ?"; |
| ... | ... | @@ -672,7 +773,6 @@ class MyDropDocumentsPage extends KTStandardDispatcher { |
| 672 | 773 | |
| 673 | 774 | $aNewFolders = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id'); |
| 674 | 775 | if (PEAR::isError($aNewFolders)) { |
| 675 | - //$this->errorRedirectToMain(_kt('Failure to generate folderlisting.')); | |
| 676 | 776 | echo _kt('Failure to generate folderlisting.'); |
| 677 | 777 | } |
| 678 | 778 | $folder_queue = kt_array_merge ($folder_queue, (array) $aNewFolders); // push. |
| ... | ... | @@ -681,14 +781,12 @@ class MyDropDocumentsPage extends KTStandardDispatcher { |
| 681 | 781 | // update the folder. |
| 682 | 782 | $oFolder =& Folder::get($active_folder); |
| 683 | 783 | if (PEAR::isError($oFolder) || ($oFolder == false)) { |
| 684 | - //$this->errorRedirectToMain(_kt('Unable to locate folder: ') . $active_folder); | |
| 685 | 784 | echo _kt('Unable to locate folder: ').$active_folder; |
| 686 | 785 | } |
| 687 | 786 | |
| 688 | 787 | KTPermissionUtil::updatePermissionLookup($oFolder); |
| 689 | 788 | $aDocList =& Document::getList(array('folder_id = ?', $active_folder)); |
| 690 | 789 | if (PEAR::isError($aDocList) || ($aDocList === false)) { |
| 691 | - //$this->errorRedirectToMain(sprintf(_kt('Unable to get documents in folder %s: %s'), $active_folder, $aDocList->getMessage())); | |
| 692 | 790 | echo _kt('Unable to get documents in folder ').$active_folder; |
| 693 | 791 | } |
| 694 | 792 | |
| ... | ... | @@ -699,65 +797,5 @@ class MyDropDocumentsPage extends KTStandardDispatcher { |
| 699 | 797 | } |
| 700 | 798 | } |
| 701 | 799 | } |
| 702 | - | |
| 703 | - /* | |
| 704 | - attempt to abstract the transaction-matching query. | |
| 705 | - | |
| 706 | - tables that are already defined (other than sec ones): | |
| 707 | - | |
| 708 | - - Documents (D) | |
| 709 | - - Users (U) | |
| 710 | - - TransactionTypes (DTT) | |
| 711 | - - Document Transactions (DT) | |
| 712 | - | |
| 713 | - so where clausess can take advantage of those. | |
| 714 | - | |
| 715 | - */ | |
| 716 | - function getTransactionsMatchingQuery($oUser, $sJoinClause, $aExternalWhereClauses, $aExternalWhereParams, $aOptions = null) { | |
| 717 | - | |
| 718 | - $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'; | |
| 719 | - $sBaseJoin = "FROM " . KTUtil::getTableName("document_transactions") . " AS DT " . | |
| 720 | - "INNER JOIN " . KTUtil::getTableName("users") . " AS U ON DT.user_id = U.id " . | |
| 721 | - "INNER JOIN " . KTUtil::getTableName("transaction_types") . " AS DTT ON DTT.namespace = DT.transaction_namespace " . | |
| 722 | - "INNER JOIN " . KTUtil::getTableName("documents") . " AS D ON D.id = DT.document_id "; | |
| 723 | - | |
| 724 | - // now we're almost at partialquery like status. | |
| 725 | - $perm_res = KTSearchUtil::permissionToSQL($oUser, 'ktcore.permissions.read'); | |
| 726 | - if (PEAR::isError($perm_res)) { | |
| 727 | - return $perm_res; | |
| 728 | - } | |
| 729 | - list($sPermissionString, $aPermissionParams, $sPermissionJoin) = $perm_res; | |
| 730 | - | |
| 731 | - // compile the final list | |
| 732 | - $aFinalWhere = kt_array_merge(array($sPermissionString,'D.creator_id IS NOT NULL'), $aExternalWhereClauses, array('D.status_id = ?')); | |
| 733 | - $aFinalWhereParams = kt_array_merge($aPermissionParams, $aExternalWhereParams, array(LIVE)); | |
| 734 | - | |
| 735 | - if (!is_array($aOptions)) { | |
| 736 | - $aOptions = (array) $aOptions; | |
| 737 | - } | |
| 738 | - $sOrderBy = KTUtil::arrayGet($aOptions, 'orderby', 'DT.datetime DESC'); | |
| 739 | - | |
| 740 | - // compile these. | |
| 741 | - // NBM: do we need to wrap these in ()? | |
| 742 | - $sWhereClause = implode(' AND ', $aFinalWhere); | |
| 743 | - if (!empty($sWhereClause)) { | |
| 744 | - $sWhereClause = 'WHERE ' . $sWhereClause; | |
| 745 | - } | |
| 746 | - | |
| 747 | - $sQuery = sprintf("SELECT %s %s %s %s %s ORDER BY %s", | |
| 748 | - $sSelectItems, | |
| 749 | - $sBaseJoin, | |
| 750 | - $sPermissionJoin, | |
| 751 | - $sJoinClause, | |
| 752 | - $sWhereClause, | |
| 753 | - $sOrderBy | |
| 754 | - ); | |
| 755 | - | |
| 756 | - //var_dump(array($sQuery, $aFinalWhereParams)); | |
| 757 | - | |
| 758 | - $res = DBUtil::getResultArray(array($sQuery, $aFinalWhereParams)); | |
| 759 | - //var_dump($res); exit(0); | |
| 760 | - return $res; | |
| 761 | - } | |
| 762 | 800 | } |
| 763 | 801 | ?> | ... | ... |
plugins/MyDropDocumentsPlugin/MyDropDocumentsPlugin.php
| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | * License Version 1.1.2 ("License"); You may not use this file except in |
| 5 | 5 | * compliance with the License. You may obtain a copy of the License at |
| 6 | 6 | * http://www.knowledgetree.com/KPL |
| 7 | - * | |
| 7 | + * | |
| 8 | 8 | * Software distributed under the License is distributed on an "AS IS" |
| 9 | 9 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
| 10 | 10 | * See the License for the specific language governing rights and |
| ... | ... | @@ -15,9 +15,9 @@ |
| 15 | 15 | * (ii) the KnowledgeTree copyright notice |
| 16 | 16 | * in the same form as they appear in the distribution. See the License for |
| 17 | 17 | * requirements. |
| 18 | - * | |
| 18 | + * | |
| 19 | 19 | * The Original Code is: KnowledgeTree Open Source |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * The Initial Developer of the Original Code is The Jam Warehouse Software |
| 22 | 22 | * (Pty) Ltd, trading as KnowledgeTree. |
| 23 | 23 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright |
| ... | ... | @@ -26,28 +26,30 @@ |
| 26 | 26 | * Contributor( s): ______________________________________ |
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | - | |
| 29 | + | |
| 30 | 30 | require_once(KT_LIB_DIR . "/plugins/plugin.inc.php"); |
| 31 | 31 | require_once(KT_LIB_DIR . "/plugins/pluginregistry.inc.php"); |
| 32 | 32 | |
| 33 | 33 | class MyDropDocumentsPlugin extends KTPlugin |
| 34 | 34 | { |
| 35 | 35 | var $sNamespace = 'ktlive.mydropdocuments.plugin'; |
| 36 | + var $iVersion = 1; | |
| 36 | 37 | var $autoRegister = true; |
| 37 | - | |
| 38 | + | |
| 38 | 39 | function MyDropDocumentsPlugin($sFilename = null) { |
| 39 | - | |
| 40 | + | |
| 40 | 41 | $res = parent::KTPlugin($sFilename); |
| 41 | 42 | $this->sFriendlyName = _kt('My Drop Documents'); |
| 42 | 43 | return $res; |
| 43 | - | |
| 44 | + | |
| 44 | 45 | } |
| 45 | - | |
| 46 | + | |
| 46 | 47 | function setup() { |
| 47 | - | |
| 48 | + | |
| 48 | 49 | $this->registerDashlet('MyDropDocumentsDashlet', 'klive.mydropdocuments.dashlet', 'MyDropDocumentsDashlet.php'); |
| 49 | 50 | $this->registerPage('MyDropDocuments', 'MyDropDocumentsPage', 'MyDropDocumentsPage.php'); |
| 50 | - | |
| 51 | + $this->registerTrigger('user_create', 'postValidate', 'CreateUserFolderTrigger','ktlive.mydropdocuments.triggers.user_create', 'MyDropDocumentsDashlet.php'); | |
| 52 | + | |
| 51 | 53 | require_once(KT_LIB_DIR . "/templating/templating.inc.php"); |
| 52 | 54 | $oTemplating =& KTTemplating::getSingleton(); |
| 53 | 55 | $oTemplating->addLocation('MyDropDocumentsDashlet', '/plugins/MyDropDocumentsPlugin/templates'); | ... | ... |
plugins/ktcore/admin/userManagement.php
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | * KnowledgeTree Community Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc. |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * |
| 10 | 10 | * This program is free software; you can redistribute it and/or modify it under |
| 11 | 11 | * the terms of the GNU General Public License version 3 as published by the |
| ... | ... | @@ -39,6 +39,7 @@ |
| 39 | 39 | require_once(KT_LIB_DIR . '/database/dbutil.inc'); |
| 40 | 40 | |
| 41 | 41 | require_once(KT_LIB_DIR . '/users/User.inc'); |
| 42 | +require_once(KT_LIB_DIR . '/users/userutil.inc.php'); | |
| 42 | 43 | require_once(KT_LIB_DIR . '/groups/GroupUtil.php'); |
| 43 | 44 | require_once(KT_LIB_DIR . '/groups/Group.inc'); |
| 44 | 45 | |
| ... | ... | @@ -539,32 +540,21 @@ class KTUserAdminDispatcher extends KTAdminDispatcher { |
| 539 | 540 | $this->errorRedirectTo('addUser', _kt("You have entered an invalid character in your name.")); |
| 540 | 541 | } |
| 541 | 542 | |
| 542 | - $dupUser =& User::getByUserName($username); | |
| 543 | - if(!PEAR::isError($dupUser)) { | |
| 544 | - $this->errorRedirectTo('addUser', _kt("A user with that username already exists")); | |
| 545 | - } | |
| 546 | - | |
| 547 | 543 | |
| 544 | + $oUser = KTUserUtil::createUser($username, $name, $password, $email_address, $email_notifications, $mobile_number, $max_sessions); | |
| 548 | 545 | |
| 549 | - $oUser =& User::createFromArray(array( | |
| 550 | - "sUsername" => $username, | |
| 551 | - "sName" => $name, | |
| 552 | - "sPassword" => md5($password), | |
| 553 | - "iQuotaMax" => 0, | |
| 554 | - "iQuotaCurrent" => 0, | |
| 555 | - "sEmail" => $email_address, | |
| 556 | - "bEmailNotification" => $email_notifications, | |
| 557 | - "sMobile" => $mobile_number, | |
| 558 | - "bSmsNotification" => false, // FIXME do we auto-act if the user has a mobile? | |
| 559 | - "iMaxSessions" => $max_sessions, | |
| 560 | - )); | |
| 546 | + if(PEAR::isError($oUser)){ | |
| 547 | + if($oUser->getMessage() == _kt("A user with that username already exists")){ | |
| 548 | + $this->errorRedirectTo('addUser', _kt("A user with that username already exists")); | |
| 549 | + exit(); | |
| 550 | + } | |
| 561 | 551 | |
| 562 | - if (PEAR::isError($oUser) || ($oUser == false)) { | |
| 563 | 552 | $this->errorRedirectToMain(_kt("failed to create user."), sprintf("old_search=%s&do_search=1", $old_search)); |
| 564 | - exit(0); | |
| 553 | + exit; | |
| 565 | 554 | } |
| 566 | 555 | |
| 567 | 556 | $this->successRedirectToMain(_kt('Created new user') . ': ' . $oUser->getUsername(), 'name=' . $oUser->getUsername(), sprintf("old_search=%s&do_search=1", $old_search)); |
| 557 | + return ; | |
| 568 | 558 | } |
| 569 | 559 | |
| 570 | 560 | function do_deleteUser() { | ... | ... |
plugins/ktstandard/ldap/ldapbaseauthenticationprovider.inc.php
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | * KnowledgeTree Community Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2008, 2009, 2010 KnowledgeTree Inc. |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * |
| 10 | 10 | * This program is free software; you can redistribute it and/or modify it under |
| 11 | 11 | * the terms of the GNU General Public License version 3 as published by the |
| ... | ... | @@ -322,11 +322,6 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider { |
| 322 | 322 | $username = KTUtil::arrayGet($_REQUEST, 'ldap_username'); |
| 323 | 323 | if (empty($username)) { $this->errorRedirectToMain(_kt('You must specify a new username.')); } |
| 324 | 324 | |
| 325 | - $dupUser =& User::getByUserName($username); | |
| 326 | - if(!PEAR::isError($dupUser)) { | |
| 327 | - $this->errorRedirectToMain(_kt("A user with that username already exists")); | |
| 328 | - } | |
| 329 | - | |
| 330 | 325 | $email_address = KTUtil::arrayGet($_REQUEST, 'email_address'); |
| 331 | 326 | $email_notifications = KTUtil::arrayGet($_REQUEST, 'email_notifications', false); |
| 332 | 327 | if ($email_notifications !== false) $email_notifications = true; |
| ... | ... | @@ -334,21 +329,10 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider { |
| 334 | 329 | $max_sessions = KTUtil::arrayGet($_REQUEST, 'max_sessions', '3'); |
| 335 | 330 | // FIXME check for numeric max_sessions... db-error else? |
| 336 | 331 | |
| 337 | - $oUser =& User::createFromArray(array( | |
| 338 | - "Username" => $username, | |
| 339 | - "Name" => $name, | |
| 340 | - "Email" => $email_address, | |
| 341 | - "EmailNotification" => $email_notifications, | |
| 342 | - "SmsNotification" => false, // FIXME do we auto-act if the user has a mobile? | |
| 343 | - "MaxSessions" => $max_sessions, | |
| 344 | - "authenticationsourceid" => $oSource->getId(), | |
| 345 | - "authenticationdetails" => $dn, | |
| 346 | - "authenticationdetails2" => $samaccountname, | |
| 347 | - "password" => "", | |
| 348 | - )); | |
| 332 | + $oUser = KTUserUtil::createUser($username, $name, '', $email_address, $email_notifications, '', $max_sessions, $oSource->getId(), $dn, $samaccountname); | |
| 349 | 333 | |
| 350 | 334 | if (PEAR::isError($oUser) || ($oUser == false)) { |
| 351 | - $this->errorRedirectToMain(_kt("failed to create user") . ": " . $oUser->message); | |
| 335 | + $this->errorRedirectToMain($oUser->getMessage()); | |
| 352 | 336 | exit(0); |
| 353 | 337 | } |
| 354 | 338 | |
| ... | ... | @@ -368,24 +352,24 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider { |
| 368 | 352 | $aResults = $oAuthenticator->getUser($sId); |
| 369 | 353 | $dn = $sId; |
| 370 | 354 | $sUserName = $aResults[$this->aAttributes[1]]; |
| 371 | - | |
| 355 | + | |
| 372 | 356 | if ($sUserName == '') { |
| 373 | 357 | $dnParts = ldap_explode_dn($dn, 0); |
| 374 | 358 | $sUserName = end(explode('=',$dnParts[0]));; |
| 375 | 359 | } |
| 376 | - | |
| 360 | + | |
| 377 | 361 | // With LDAP, if the 'uid' is null then try using the 'givenname' instead. |
| 378 | 362 | // See activedirectoryauthenticationprovider.inc.php and ldapauthenticationprovider.inc.php for details. |
| 379 | 363 | if($this->sAuthenticatorClass == "KTLDAPAuthenticator" && empty($sUserName)) { |
| 380 | 364 | $sUserName = strtolower($aResults[$this->aAttributes[2]]); |
| 381 | 365 | } |
| 382 | 366 | $sName = $aResults[$this->aAttributes[0]]; |
| 383 | - | |
| 367 | + | |
| 384 | 368 | if ($sName == '') { |
| 385 | 369 | $dnParts = ldap_explode_dn($dn, 0); |
| 386 | 370 | $sName = end(explode('=',$dnParts[0]));; |
| 387 | 371 | } |
| 388 | - | |
| 372 | + | |
| 389 | 373 | $sEmailAddress = $aResults[$this->aAttributes[4]]; |
| 390 | 374 | $sMobileNumber = $aResults[$this->aAttributes[5]]; |
| 391 | 375 | |
| ... | ... | @@ -397,19 +381,9 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider { |
| 397 | 381 | $appending = true; |
| 398 | 382 | } else $appending = false; |
| 399 | 383 | } |
| 400 | - | |
| 401 | - $oUser = User::createFromArray(array( | |
| 402 | - "Username" => $sUserName, | |
| 403 | - "Name" => $sName, | |
| 404 | - "Email" => $sEmailAddress, | |
| 405 | - "EmailNotification" => true, | |
| 406 | - "SmsNotification" => false, // FIXME do we auto-act if the user has a mobile? | |
| 407 | - "MaxSessions" => 3, | |
| 408 | - "authenticationsourceid" => $oSource->getId(), | |
| 409 | - "authenticationdetails" => $dn, | |
| 410 | - "authenticationdetails2" => $sUserName, | |
| 411 | - "password" => "", | |
| 412 | - )); | |
| 384 | + | |
| 385 | + $oUser = KTUserUtil::createUser($sUserName, $sName, '', $sEmailAddress, true, '', 3, $oSource->getId(), $dn, $sUserName); | |
| 386 | + | |
| 413 | 387 | $aNames[] = $sName; |
| 414 | 388 | } |
| 415 | 389 | $this->successRedirectToMain(_kt("Added users") . ": " . join(', ', $aNames)); | ... | ... |