function do_main() { $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('User Management')); $this->oPage->setBreadcrumbDetails(_kt('select a user')); $this->oPage->setTitle(_kt("User Management")); $KTConfig =& KTConfig::getSingleton(); $alwaysAll = $KTConfig->get("alwaysShowAll"); $name = KTUtil::arrayGet($_REQUEST, 'search_name', KTUtil::arrayGet($_REQUEST, 'old_search')); $show_all = KTUtil::arrayGet($_REQUEST, 'show_all', $alwaysAll); $user_id = KTUtil::arrayGet($_REQUEST, 'user_id'); $no_search = true; if (KTUtil::arrayGet($_REQUEST, 'do_search', false) != false) { $no_search = false; } if ($name == '*') { $show_all = true; $name = ''; } $search_fields = array(); $search_fields[] = new KTStringWidget(_kt('Username'), _kt("Enter part of the person's username. e.g. <strong>ra</strong> will match <strong>brad</strong>."), 'search_name', $name, $this->oPage, true); // FIXME handle group search stuff. $search_results = null; if (!empty($name)) { $search_results =& User::getList('WHERE username LIKE \'%' . DBUtil::escapeSimple($name) . '%\' AND id > 0'); } else { if ($show_all !== false) { $search_results =& User::getList('id > 0'); $no_search = false; $name = '*'; } } $aAuthenticationSources =& KTAuthenticationSource::getList(); $bCanAdd = true; if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { $path = KTPluginUtil::getPluginPath('ktdms.wintools'); require_once $path . 'baobabkeyutil.inc.php'; $bCanAdd = BaobabKeyUtil::canAddUser(); if (PEAR::isError($bCanAdd)) { $bCanAdd = false; } } $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("ktcore/principals/useradmin"); $aTemplateData = array("context" => $this, "search_fields" => $search_fields, "search_results" => $search_results, "no_search" => $no_search, "authentication_sources" => $aAuthenticationSources, "old_search" => $name, "can_add" => $bCanAdd); return $oTemplate->render($aTemplateData); }
function json_notificationusers() { $sFilter = KTUtil::arrayGet($_REQUEST, 'filter', false); if ($sFilter == false) { $values = array('off' => _kt('-- Please filter --')); // default } $sFilter = trim($sFilter); $values = array('off' => _kt('-- Please filter --')); // default if (!empty($sFilter)) { $allowed = array(); // Modified Jarrett Jordaan Only notify enabled users $q = sprintf('name like "%%%s%%" AND disabled = 0', DBUtil::escapeSimple($sFilter)); $aUsers = User::getList($q); $q = sprintf('name like "%%%s%%"', DBUtil::escapeSimple($sFilter)); $aGroups = Group::getList($q); $aRoles = Role::getList($q); $empty = true; if (!PEAR::isError($aUsers)) { $allowed['user'] = $aUsers; if (!empty($aUsers)) { $empty = false; } } if (!PEAR::isError($aGroups)) { $allowed['group'] = $aGroups; if (!empty($aGroups)) { $empty = false; } } if (!PEAR::isError($aRole)) { $allowed['role'] = $aRoles; if (!empty($aRoles)) { $empty = false; } } if ($empty) { $values = array('off' => '-- No results --'); // default } else { $values = $this->descriptorToJSON($allowed); } } return $values; }
function _importfolder($oFolder, $sPath) { $oPermission = KTPermission::getByName('ktcore.permissions.addFolder'); $aDocPaths = $this->oStorage->listDocuments($sPath); if (PEAR::isError($aDocPaths)) { return $aDocPaths; } $oDocObjects = array(); foreach ($aDocPaths as $sDocumentPath) { $res = $this->_importdocument($oFolder, $sDocumentPath); if (PEAR::isError($res)) { return $res; } // Store document object $this->uploadedDocs[] = $res; } $aFolderPaths = $this->oStorage->listFolders($sPath); if (PEAR::isError($aFolderPaths)) { return $aFolderPaths; } $oFolderObjects = array(); foreach ($aFolderPaths as $sFolderPath) { $sFolderBasePath = basename($sFolderPath); $sFolderBasePath = $this->is_utf8($sFolderBasePath) ? $sFolderBasePath : utf8_encode($sFolderBasePath); if (Folder::folderExistsName($sFolderPath, KTUtil::getId($oFolder))) { $_SESSION['KTErrorMessage'][] = sprintf(_kt("The folder %s is already present in %s. Adding files into pre-existing folder."), $sFolderBasePath, $oFolder->getName()); $aOptions = Folder::getList("parent_id = " . KTUtil::getId($oFolder) . ' AND name = "' . DBUtil::escapeSimple($sFolderBasePath) . '"'); if (PEAR::isError($aOptions)) { return $aOptions; } if (count($aOptions) != 1) { return PEAR::raiseError(sprintf(_kt("Two folders named %s present in %s. Unable to decide which to use..."), $sFolderName, $oFolder->getName())); } else { $oThisFolder = $aOptions[0]; } } else { if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $oFolder)) { $oThisFolder = KTFolderUtil::add($oFolder, $sFolderBasePath, $this->oUser, true); } else { $oThisFolder = $oFolder; if (!in_array('Your documents have been added to this folder and not the folder structure within the upload file because you do not have permission to add any folders.', $_SESSION['KTErrorMessage'])) { $_SESSION['KTErrorMessage'][] = sprintf(_kt('Your documents have been added to this folder and not the folder structure within the upload file because you do not have permission to add any folders.')); } } } if (PEAR::isError($oThisFolder)) { return $oThisFolder; } $res = $this->_importfolder($oThisFolder, $sFolderPath); if (PEAR::isError($res)) { return $res; } // Store folder object $this->uploadedFolders[] = $res; } }
/** * Searches the user store for users matching the supplied search string. * * @param string the username to search for * @param array the attributes to return from the search * @return array containing the users found */ function searchUsers($sUserNameSearch, $aAttributes) { $sTable = KTUtil::getTableName('users'); $sQuery = 'SELECT '; /*ok*/ $sQuery .= implode(', ', $aAttributes); $sQuery .= " FROM {$sTable} where username like '%" . DBUtil::escapeSimple($sUserNameSearch) . "%'"; $res = DBUtil::getResultArray(array($sQuery, array())); if (PEAR::isError($res)) { return false; // return $res; } $aUserResults = array(); foreach ($res as $aRow) { $sUserName = $aRow['username']; foreach ($aAttributes as $sAttrName) { $aUserResults[$sUserName][$sAttrName] = $aRow[$sAttrName]; } } return $aUserResults; }
function do_main() { $this->oPage->setBreadcrumbDetails(_kt('select a group')); $this->oPage->setTitle(_kt("Group Management")); $KTConfig =& KTConfig::getSingleton(); $alwaysAll = $KTConfig->get("alwaysShowAll"); $name = KTUtil::arrayGet($_REQUEST, 'search_name', KTUtil::arrayGet($_REQUEST, 'old_search')); $show_all = KTUtil::arrayGet($_REQUEST, 'show_all', $alwaysAll); $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); $no_search = true; if (KTUtil::arrayGet($_REQUEST, 'do_search', false) != false) { $no_search = false; } if ($name == '*') { $show_all = true; $name = ''; } $search_fields = array(); $search_fields[] = new KTStringWidget(_kt('Group Name'), _kt("Enter part of the group's name. e.g. <strong>ad</strong> will match <strong>administrators</strong>."), 'search_name', $name, $this->oPage, true); if (!empty($name)) { $search_results =& Group::getList('WHERE name LIKE \'%' . DBUtil::escapeSimple($name) . '%\' AND id > 0'); } else { if ($show_all !== false) { $search_results =& Group::getList('id > 0'); $no_search = false; $name = '*'; } } $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("ktcore/principals/groupadmin"); $aTemplateData = array("context" => $this, "search_fields" => $search_fields, "search_results" => $search_results, 'no_search' => $no_search, 'old_search' => $name); return $oTemplate->render($aTemplateData); }