Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * Test KTAPI_Group getList(), getById(), getByName
  *
  */
 function testGroups()
 {
     // getList()
     $list = KTAPI_Group::getList();
     $this->assertTrue(count($list) > 0);
     // getById()
     $group = KTAPI_Group::getById(1);
     $this->assertTrue($group->Name == 'System Administrators');
     // getByName()
     $group = KTAPI_Group::getByName('System Administrators');
     $this->assertTrue($group->Id == 1);
     $this->assertTrue($group->IsSystemAdministrator);
 }
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;
 }