Exemplo n.º 1
0
 /**
  * Method to return a list of users matching the filter criteria
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $filter
  * @param string $options
  * @return array $response The formatted response array
  */
 public function get_user_list($filter = NULL, $options = NULL)
 {
     $users = KTAPI_User::getList($filter, $options);
     if (PEAR::isError($users)) {
         $response['status_code'] = 1;
         $response['message'] = $users->getMessage();
         return $response;
     }
     foreach ($users as $user) {
         $results[] = $this->_get_user_details($user);
     }
     $response['message'] = '';
     $response['status_code'] = 0;
     $response['results'] = $results;
     return $response;
 }
Exemplo n.º 2
0
 /**
  * Test KTAPI_PermissionAllocation getAllocation(), add(), remove(), save()
  *
  */
 function testPermissionAllocation()
 {
     $root = $this->ktapi->get_root_folder();
     $folder = $this->ktapi->get_folder_by_name('test123');
     if (!$folder instanceof KTAPI_Folder) {
         $folder = $root->add_folder('test123');
     }
     $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $folder);
     $group = KTAPI_Group::getByName('System Administrators');
     $user = KTAPI_User::getByUsername('anonymous');
     $role = KTAPI_Role::getByName('Publisher');
     $read = KTAPI_Permission::getByNamespace('ktcore.permissions.read');
     $write = KTAPI_Permission::getByNamespace('ktcore.permissions.write');
     $addFolder = KTAPI_Permission::getByNamespace('ktcore.permissions.addFolder');
     $security = KTAPI_Permission::getByNamespace('ktcore.permissions.security');
     $allocation->add($user, $read);
     $allocation->add($user, $write);
     $allocation->add($user, $addFolder);
     $allocation->add($user, $security);
     $allocation->add($role, $read);
     $allocation->add($role, $write);
     $allocation->remove($group, $write);
     $allocation->save();
     // refresh object and check permission allocations
     $folder2 = $this->ktapi->get_folder_by_name('test123');
     $allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $folder2);
     $this->assertTrue($allocation->isMemberPermissionSet($user, $read));
     $this->assertTrue($allocation->isMemberPermissionSet($user, $write));
     $this->assertTrue($allocation->isMemberPermissionSet($role, $write));
     $this->assertFalse($allocation->isMemberPermissionSet($group, $write));
     $folder->delete('Testing permission allocation');
 }
Exemplo n.º 3
0
 function send_email($params)
 {
     $kt =& $this->KT;
     $message = $params['message'];
     $list = $params['users'];
     $list = explode(',', $list);
     $recipientsList = array();
     foreach ($list as $recipient) {
         if (trim($recipient) != '') {
             // check that value is present
             // if @ sign is present, signifies email address
             if (strpos($recipient, '@') === false) {
                 $recipient = trim($recipient);
                 switch (substr($recipient, 0, 2)) {
                     case 'u_':
                         $id = substr($recipient, 2);
                         $user = KTAPI_User::getById($id);
                         if ($user != null) {
                             $recipientsList[] = $user;
                         }
                         break;
                     case 'g_':
                         $id = substr($recipient, 2);
                         $group = KTAPI_Group::getById($id);
                         if ($group != null) {
                             $recipientsList[] = $group;
                         }
                         break;
                 }
             } else {
                 // Email - just add to list
                 $recipientsList[] = trim($recipient);
             }
         }
     }
     $document = $kt->get_document_by_id($params['document']);
     if (count($recipientsList) == 0) {
         $this->setResponse(array('status' => 'norecipients'));
         return false;
     } else {
         $result = $document->email($recipientsList, $message, TRUE);
         // true to attach document
         if (PEAR::isError($result)) {
             $this->setResponse(array('status' => $result->getMessage()));
             return false;
         }
         $this->setResponse(array('status' => 'documentemailed'));
     }
     return true;
 }