/** * Emails a document as an attachment or hyperlink to a list of users, groups or external email addresses. * In the case of external addresses, if a hyperlink is used then a timed download link (via webservices) is sent allowing the recipient a window period in which to download the document. * The period is set through the webservices config option webservice/downloadExpiry. Defaults to 30 minutes. * * @author KnowledgeTree Team * @access public * @param string $document_id The id of the document * @param array $members The email recipients (users, groups, external) in the format: array('users' => array(1,2), 'groups' => array(3,1), 'external' => array('*****@*****.**')) * @param string $comment Content to be appended to the email * @param bool $attach TRUE if document is an attachment | FALSE if using a hyperlink to the document * @return array Response */ public function email_document($document_id, $members, $content = '', $attach = true) { $response['status_code'] = 1; if (!isset($members['users']) && !isset($members['groups']) && !isset($members['external'])) { $response['message'] = _kt("No recipients were provided. The list of recipients should be in the format: array('users' => array(1,2), 'groups' => array(3,1), 'external' => array('*****@*****.**'))."); return $response; } $document = $this->get_document_by_id($document_id); if (PEAR::isError($document)) { $response['message'] = $document->getMessage(); return $response; } $recipients = array(); // Get member objects and add them to the role // Users if (isset($members['users'])) { foreach ($members['users'] as $user_id) { // Get the user object $member = KTAPI_User::getById($user_id); if (PEAR::isError($member)) { $response['message'] = $member->getMessage(); return $response; } // Add to recipients list $recipients[] = $member; } } // Groups if (isset($members['groups'])) { foreach ($members['groups'] as $group_id) { // Get the group object $member = KTAPI_Group::getById($group_id); if (PEAR::isError($member)) { $response['message'] = $member->getMessage(); return $response; } // Add to recipients list $recipients[] = $member; } } // External recipients if (isset($members['external'])) { foreach ($members['external'] as $email_address) { // Add to recipients list $recipients[] = $member; } } $result = $document->email($recipients, $content, $attach); if (PEAR::isError($result)) { $response['message'] = $result->getMessage(); return $response; } $response['status_code'] = 0; return $response; }
/** * 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'); }
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; }