diff --git a/workflow/engine/classes/triggers/api/class.zimbraApi.php b/workflow/engine/classes/triggers/api/class.zimbraApi.php new file mode 100644 index 000000000..5dd7d9320 --- /dev/null +++ b/workflow/engine/classes/triggers/api/class.zimbraApi.php @@ -0,0 +1,1280 @@ + + * @GPL 2007, Plymouth State University, ITS + */ +class Zimbra { + + public $debug = false; + public $error; + protected $_connected = false; // boolean to determine if the connect function has been called + protected static $_num_soap_calls = 0; // the number of times a SOAP call has been made + protected $_preAuthKey; // key for doing pre-authentication + protected $_lcached_assets = array(); // an array to hold assets that have been cached + protected $_preauth_expiration = 0; // 0 indicates using the default preauth expiration as defined on the server + protected $_dev; // boolean indicating whether this is development or not + protected $_protocol; // which protocol to use when building the URL + protected $_server1 = 'ip-10-73-18-235.ec2.internal'; // hostname of zimbra server + protected $_server; // displayname of zimbra server + protected $_path = '/service/soap'; + protected $_timestamp; + protected $_account_info; + protected $_admin = false; // operating as an admin + protected $_curl; + protected $_auth_token; // used for repeat calls to zimbra through soap + protected $_session_id; // used for repeat calls to zimbra through soap + protected $_idm; // IDMObject + protected $_username; // the user we are operating as + + /** + * __construct + * + * constructor sets up connectivity to servers + * + * @since version 1.0 + * @acess public + * @param string $username username + * @param string $which defaults to prod + */ + + public function __construct($username, $serverUrl, $preAuthKey, $which = 'prod') { + if ($which == 'dev') { + $which = 'zimbra_dev'; + $this->_dev = true; + } else { + $which = 'zimbra'; + } + + $this->_preAuthKey = $preAuthKey; + $this->_protocol = "http://"; // could also be http:// + $this->_server = $serverUrl; //'zimbra.hostname.edu'; + $this->_username = $username; + $this->_timestamp = time() . '000'; + } + +// end __construct + + /** + * sso + * + * sso to Zimbra + * + * @since version 1.0 + * @access public + * @param string $options options for sso + * @return boolean + */ + public function sso($options='') { + if ($this->_username) { + setcookie('ZM_SKIN', 'plymouth', time() + 60 * 60 * 24 * 30, '/', '.plymouth.edu'); + + $pre_auth = $this->getPreAuth($this->_username); + $url = $this->_protocol . '/service/preauth?account=' . $this->_username . '@' . $this->_server . '&expires=' . $this->_preauth_expiration . '×tamp=' . $this->_timestamp . '&preauth=' . $pre_auth; //.'&'.$options; + header("Location: $url"); + exit; + } else { + return false; + } + } + +// end sso + + /** + * createAccount + * @param string $name account name + * @param string $password password + * @return string account id + */ + function createAccount($name, $password) { + $option_string = ''; + + try { + + + $soap = ' + ' . $name . '@' . $this->_server1 . ' + ' . $password . '' . $option_string . ' + + '; + + + $response = $this->soapRequest($soap); + } catch (SoapFault $exception) { + print_exception($exception); + } + + return $result['SOAP:ENVELOPE']['SOAP:BODY']['CREATEACCOUNTRESPONSE']['ACCOUNT']['ID']; + } + + /** + * getPreAuth + * + * get the preauth key needed for single-sign on + * + * @since version1.0 + * @access public + * @param string $username username + * @return string preauthentication key in hmacsha1 format + */ + private function getPreAuth($username) { + $account_identifier = $username . '@' . $this->_server1; + $by_value = 'name'; + $expires = $this->_preauth_expiration; + $timestamp = $this->_timestamp; + + $string = $account_identifier . '|' . $by_value . '|' . $expires . '|' . $timestamp; + + return $this->hmacsha1($this->_preAuthKey, $string); + } + +// end getPreAuth + + /** + * hmacsha1 + * + * generate an HMAC using SHA1, required for preauth + * + * @since version 1.0 + * @access public + * @param int $key encryption key + * @param string $data data to encrypt + * @return string converted to hmac sha1 format + */ + private function hmacsha1($key, $data) { + $blocksize = 64; + $hashfunc = 'sha1'; + if (strlen($key) > $blocksize) + $key = pack('H*', $hashfunc($key)); + $key = str_pad($key, $blocksize, chr(0x00)); + $ipad = str_repeat(chr(0x36), $blocksize); + $opad = str_repeat(chr(0x5c), $blocksize); + $hmac = pack( + 'H*', $hashfunc( + ($key ^ $opad) . pack( + 'H*', $hashfunc( + ($key ^ $ipad) . $data + ) + ) + ) + ); + return bin2hex($hmac); + } + +// end hmacsha1 + + /** + * connect + * + * connect to the Zimbra SOAP service + * + * @since version 1.0 + * @access public + * @return array associative array of account information + */ + public function connect() { + if ($this->_connected) { + return $this->_account_info; + } + $completeurl = $this->_protocol . $this->_server . $this->_path; + $this->_curl = curl_init(); + curl_setopt($this->_curl, CURLOPT_URL, $this->_protocol . $this->_server . $this->_path); + curl_setopt($this->_curl, CURLOPT_POST, true); + curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($this->_curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($this->_curl, CURLOPT_SSL_VERIFYHOST, false); + + $preauth = $this->getPreAuth($this->_username); + $header = ''; + + if ($this->_admin) { + $body = ' + ' . $this->_admin_username . ' + ' . $this->_admin_password . ' + '; + } else { + $body = ' + ' . $this->_username . '@' . $this->_server1 . ' + ' . $preauth . ' + '; + } + + $response = $this->soapRequest($body, $header, true); + if ($response) { + $tmp = $this->makeXMLTree($response); + $this->_account_info = $tmp['soap:Envelope'][0]['soap:Header'][0]['context'][0]['refresh'][0]['folder'][0]; + + $this->session_id = $this->extractSessionID($response); + $this->auth_token = $this->extractAuthToken($response); + + $this->_connected = true; + + //return $this->_account_info; + return $this->_connected; + } else { + $this->_connected = false; + return false; + } + } + +// end connect + + /** + * administerUser + * + * set the user you are administering (experimental) + * + * @since version 1.0 + * @access public + * @param string $username username to administer + * @return boolean + */ + public function administerUser($username) { + if (!$this->_admin) { + return false; + } + + $this->_username = $username; + + $body = ' + ' . $this->_username . '@' . $this->_server . ' + '; + $response = $this->soapRequest($body, $header); + if ($response) { + $tmp = $this->makeXMLTree($response); + $this->_account_info = $tmp['soap:Envelope'][0]['soap:Header'][0]['context'][0]['refresh'][0]['folder'][0]; + + $this->session_id = $this->extractSessionID($response); + $this->auth_token = $this->extractAuthToken($response); + + return true; + } else { + return false; + } + } + +// end administerUser + + /** + * getInfo + * + * generic function to get information on mailbox, preferences, attributes, properties, and more! + * + * @since version 1.0 + * @access public + * @param string $options options for info retrieval, defaults to null + * @return array information + */ + public function getInfo($options='') { + // valid sections: mbox,prefs,attrs,zimlets,props,idents,sigs,dsrcs,children + $option_string = $this->buildOptionString($options); + + $soap = ''; + $response = $this->soapRequest($soap); + if ($response) { + $array = $this->makeXMLTree($response); + return $array['soap:Envelope'][0]['soap:Body'][0]['GetInfoResponse'][0]; + } else { + return false; + } + } + +// end getInfo + + /** + * getMessages + * + * get the messages in folder, deafults to inbox + * + * @since version 1.0 + * @access public + * @param string $search folder to retrieve from, defaults to in:inbox + * @param array $options options to apply to retrieval + * @return array array of messages + */ + public function getMessages($search='in:inbox', $options=array('limit' => 5, 'fetch' => 'none')) { + $option_string = $this->buildOptionString($options); + + $soap = ' + ' . $search . ' + '; + $response = $this->soapRequest($soap); + if ($response) { + $array = $this->makeXMLTree($response); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + +// end getMessages + + /** + * getContacts + * + * get the Contacts in folder, deafults to inbox + * + * @since version 1.0 + * @access public + * @param string $search folder to retrieve from, defaults to in:inbox + * @param array $options options to apply to retrieval + * @return array array of messages + */ + public function getContacts($search='in:contacts', $options=array('limit' => 5, 'fetch' => 'none')) { + $option_string = $this->buildOptionString($options); + + $soap = ' + ' . $search . ' + '; + $response = $this->soapRequest($soap); + if ($response) { + $array = $this->makeXMLTree($response); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + +// end getContacts + + + /* getAppointments + * + * get the Appointments in folder + * + * @since version 1.0 + * @access public + * @param string $search folder to retrieve from + * @param array $options options to apply to retrieval + * @return array array of messages + */ + + public function getAppointments($search='in:calendar', $options=array('limit' => 50, 'fetch' => 'none')) { + $option_string = $this->buildOptionString($options); + + $soap = ' + ' . $search . ' + '; + $response = $this->soapRequest($soap); + if ($response) { + $array = $this->makeXMLTree($response); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + +// end getAppointments + + /* getTasks + * + * get the Tasks in folder + * + * @since version 1.0 + * @access public + * @param string $search folder to retrieve from + * @param array $options options to apply to retrieval + * @return array array of messages + */ + + public function getTasks($search='in:tasks', $options=array('limit' => 50, 'fetch' => 'none')) { + $option_string = $this->buildOptionString($options); + + $soap = ' + ' . $search . ' + '; + $response = $this->soapRequest($soap); + if ($response) { + $array = $this->makeXMLTree($response); + return $array['soap:Envelope'][0]['soap:Body'][0]['SearchResponse'][0]; + } else { + return false; + } + } + +// end getTasks + + /** + * getMessageContent + * + * get the content from a message + * + * @since version 1.0 + * @access public + * @param int $id id number of message to retrieve content of + * @return array associative array with message content, valid for tasks, calendar entries, and email messages. + */ + public function getMessageContent($id) { + $soap = ' + * + '; + $response = $this->soapRequest($soap); + + if ($response) { + $array = $this->makeXMLTree($response); + $temp = $array['soap:Envelope'][0]['soap:Body'][0]['GetMsgResponse'][0]['m'][0]; + + $message = $temp['inv'][0]['comp'][0]; + + // content with no attachment + $message['content'] = $temp['mp'][0]['mp'][1]['content'][0]; + + // content with attachment + $message['content'] .= $temp['mp'][0]['mp'][0]['mp'][1]['content'][0]; + + return $message; + } else { + return false; + } + } + + /** + * getSubscribedCalendars + * + * get the calendars the user is subscribed to + * + * @since version 1.0 + * @access public + * @return array $subscribed + */ + public function getSubscribedCalendars() { + $subscribed = array(); + if (is_array($this->_account_info['link_attribute_name'])) { + foreach ($this->_account_info['link_attribute_name'] as $i => $name) { + if ($this->_account_info['link_attribute_view'][$i] == 'appointment') + $subscribed[$this->_account_info['link_attribute_id'][$i]] = $name; + } + } + return $subscribed; + } + +// end getSubscribedCalendars + + /** + * getSubscribedTaskLists + * + * get the task lists the user is subscribed to + * + * @since version 1.0 + * @access public + * @return array $subscribed or false + */ + public function getSubscribedTaskLists() { + $subscribed = array(); + if (is_array($this->_account_info['link_attribute_name'])) { + foreach ($this->_account_info['link_attribute_name'] as $i => $name) { + if ($this->_account_info['link_attribute_view'][$i] == 'task') + $subscribed[$this->_account_info['link_attribute_id'][$i]] = $name; + } + } + return $subscribed; + } + +// end getSubscribedCalendars + + /** + * getFolder + * + * get a folder (experimental) + * + * @since version 1.0 + * @access public + * @param string $folder_options options for folder retrieval + * @return array $folder or false + */ + public function getFolder($folderName, $folder_options='') { + + //$folder_option_string = $this->buildOptionString($folder_options); + + $soap = ' + + '; + $response = $this->soapRequest($soap); + if ($response) { + $array = $this->makeXMLTree($response); + + $folder = (is_array($array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]['folder'][0])) ? $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]['folder'][0] : $array['soap:Envelope'][0]['soap:Body'][0]['GetFolderResponse'][0]; + + $folder['u'] = (!isset($folder['u'])) ? $folder['folder_attribute_u'][0] : $folder['u']; + $folder['n'] = (!isset($folder['n'])) ? $folder['folder_attribute_n'][0] : $folder['n']; + + return $folder; + } else { + return false; + } + } + +// end getFolder + + /** + * getPrefrences + * + * get preferences + * + * @since version 1.0 + * @access public + * @example example XML: [ ] + * @return array $prefs or false + */ + public function getPreferences() { + $soap = ''; + $response = $this->soapRequest($soap); + if ($response) { + $prefs = array(); + $array = $this->makeXMLTree($response); + foreach ($array['soap:Envelope'][0]['soap:Body'][0]['GetPrefsResponse'][0]['pref'] as $k => $value) { + $prefs[$array['soap:Envelope'][0]['soap:Body'][0]['GetPrefsResponse'][0]['pref_attribute_name'][$k]] = $value; + } + return $prefs; + } else { + return false; + } + } + +// end getPreferences + + /** + * setPrefrences + * + * modify preferences + * + * @since version 1.0 + * @access public + * @param string $options options to set the prefrences + * @example example XML: [{value}...]+ + * @return boolean + */ + public function setPreferences($options='') { + $option_string = ''; + foreach ($options as $name => $value) { + $option_string .= '' . $value . ''; + } + + $soap = ' + ' . $option_string . ' + '; + $response = $this->soapRequest($soap); + if ($response) { + return true; + } else { + return false; + } + } + +// end setPreferences + + /** + * emailChannel + * + * build the email channel + * + * @since version 1.0 + * @access public + */ + public function emailChannel() { + require_once 'xtemplate.php'; + $tpl = new XTemplate('/web/pscpages/webapp/portal/channel/email/templates/index.tpl'); + + $tpl->parse('main.transition'); + + $total_messages = 0; + $unread_messages = 0; + + $messages = $this->getMessages('in:inbox'); + if (is_array($messages)) { + $more = $messages['more']; + foreach ($messages['m'] as $message) { + $clean_message = array(); + + $clean_message['subject'] = (isset($message['su'][0]) && $message['su'][0] != '') ? htmlentities($message['su'][0]) : '[None]'; + $clean_message['subject'] = (strlen($clean_message['subject']) > 20) ? substr($clean_message['subject'], 0, 17) . '...' : $clean_message['subject']; + + $clean_message['body_fragment'] = $message['fr'][0]; + $clean_message['from_email'] = $message['e_attribute_a'][0]; + $clean_message['from'] = ($message['e_attribute_p'][0]) ? htmlspecialchars($message['e_attribute_p'][0]) : $clean_message['from_email']; + $clean_message['size'] = $this->makeBytesPretty($message['s'], 40 * 1024 * 1024); + $clean_message['date'] = date('n/j/y', ($message['d'] / 1000)); + $clean_message['id'] = $message['id']; + $clean_message['url'] = 'http://go.plymouth.edu/mymail/msg/' . $clean_message['id']; + + $clean_message['attachment'] = false; + $clean_message['status'] = 'read'; + $clean_message['deleted'] = false; + $clean_message['flagged'] = false; + if (isset($message['f'])) { + $clean_message['attachment'] = (strpos($message['f'], 'a') !== false) ? true : false; + $clean_message['status'] = (strpos($message['f'], 'u') !== false) ? 'unread' : 'read'; + ; + $clean_message['deleted'] = (strpos($message['f'], '2') !== false) ? true : false; + $clean_message['flagged'] = (strpos($message['f'], 'f') !== false) ? true : false; + } + + $tpl->assign('message', $clean_message); + $tpl->parse('main.message'); + } + $inbox = $this->getFolder(array('l' => 2)); + + $total_messages = (int) $inbox['n']; + $unread_messages = (int) $inbox['u']; + } + + $tpl->assign('total_messages', $total_messages); + $tpl->assign('unread_messages', $unread_messages); + + $info = $this->getInfo(array('sections' => 'mbox')); + if (is_array($info['attrs'][0]['attr_attribute_name'])) { + $quota = $info['attrs'][0]['attr'][array_search('zimbraMailQuota', $info['attrs'][0]['attr_attribute_name'])]; + $size_text = $this->makeBytesPretty($info['used'][0], ($quota * 0.75)) . ' out of ' . $this->makeBytesPretty($quota); + $tpl->assign('size', $size_text); + } + + /* include_once 'portal_functions.php'; + $roles = getRoles($this->_username); + + if(in_array('faculty', $roles) || in_array('employee', $roles)) + { + $tpl->parse('main.away_message'); + } */ + + $tpl->parse('main'); + $tpl->out('main'); + } + +// end emailChannel + + /** + * builOptionString + * + * make an option string that will be placed as attributes inside an XML tag + * + * @since version 1.0 + * @access public + * @param array $options array of options to be parsed into a string + * @return string $options_string + */ + protected function buildOptionString($options) { + $options_string = ''; + foreach ($options as $k => $v) { + $options_string .= ' ' . $k . '="' . $v . '"'; + } + return $options_string; + } + +// end buildOptionString + + /** + * extractAuthToken + * + * get the Auth Token out of the XML + * + * @since version 1.0 + * @access public + * @param string $xml xml to have the auth token pulled from + * @return string $auth_token + */ + private function extractAuthToken($xml) { + $auth_token = strstr($xml, ""); + $auth_token = substr($auth_token, 1, strpos($auth_token, "<") - 1); + return $auth_token; + } + + /** + * extractSessionID + * + * get the Session ID out of the XML + * + * @since version 1.0 + * @access public + * @param string $xml xml to have the session id pulled from + * @return int $session_id + */ + private function extractSessionID($xml) { + + //for testing purpose we are extracting lifetime instead of sessionid + //$session_id = strstr($xml, ""); + $session_id = substr($session_id, 1, strpos($session_id, "<") - 1); + return $session_id; + } + +// end extractSessionID + + /** + * extractErrorCode + * + * get the error code out of the XML + * + * @since version 1.0 + * @access public + * @param string $xml xml to have the error code pulled from + * @return int $session_id + */ + private function extractErrorCode($xml) { + $session_id = strstr($xml, ""); + $session_id = substr($session_id, 1, strpos($session_id, "<") - 1); + return $session_id; + } + +// end extractErrorCode + + /** + * makeBytesPretty + * + * turns byte numbers into a more readable format with KB or MB + * + * @since version 1.0 + * @access public + * @param int $bytes bytes to be worked with + * @param boolean $redlevel + * @return int $size + */ + private function makeBytesPretty($bytes, $redlevel=false) { + if ($bytes < 1024) + $size = $bytes . ' B'; + elseif ($bytes < 1024 * 1024) + $size = round($bytes / 1024, 1) . ' KB'; + else + $size = round(($bytes / 1024) / 1024, 1) . ' MB'; + + if ($redlevel && $bytes > $redlevel) { + $size = '' . $size . ''; + } + + return $size; + } + +// end makeBytesPretty + + /** + * message + * + * if debug is on, show a message + * + * @since version 1.0 + * @access public + * @param string $message message for debug + */ + protected function message($message) { + if ($this->debug) { + echo $message; + } + } + +// end message + + /** + * soapRequest + * + * make a SOAP request to Zimbra server, returns the XML + * + * @since version 1.0 + * @access public + * @param string $body body of page + * @param boolean $header + * @param boolean $footer + * @return string $response + */ + protected function soapRequest($body, $header=false, $connecting=false) { + if (!$connecting && !$this->_connected) { + throw new Exception('zimbra.class: soapRequest called without a connection to Zimbra server'); + } + + if ($header == false) { + $header = ' + ' . $this->auth_token . ' + ' . $this->session_id . ' + '; + } + + $soap_message = ' + ' . $header . ' + ' . $body . ' + '; + $this->message('SOAP message:'); + + curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $soap_message); + + if (!($response = curl_exec($this->_curl))) { + $this->error = 'ERROR: curl_exec - (' . curl_errno($this->_curl) . ') ' . curl_error($this->_curl); + return false; + } elseif (strpos($response, '') !== false) { + $error_code = $this->extractErrorCode($response); + $this->error = 'ERROR: ' . $error_code . ':'; + $this->message($this->error); + $aError = array('error' => $error_code); + return $aError; + //return false; + } + $this->message('SOAP response:

'); + + $this->_num_soap_calls++; + return $response; + } + +// end soapRequest + + /** + * getNumSOAPCalls + * + * get the number of SOAP calls that have been made. This is for debugging and performancing + * + * @since version 1.0 + * @access public + * @return int $this->_num_soap_calls + */ + public function getNumSOAPCalls() { + return $this->_num_soap_calls; + } + +// end getNumSOAPCalls + + /** + * makeXMLTree + * + * turns XML into an array + * + * @since version 1.0 + * @access public + * @param string $data data to be built into an array + * @return array $ret + */ + protected function makeXMLTree($data) { + // create parser + $parser = xml_parser_create(); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); + xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); + xml_parse_into_struct($parser, $data, $values, $tags); + xml_parser_free($parser); + + // we store our path here + $hash_stack = array(); + + // this is our target + $ret = array(); + foreach ($values as $key => $val) { + + switch ($val['type']) { + case 'open': + array_push($hash_stack, $val['tag']); + if (isset($val['attributes'])) + $ret = $this->composeArray($ret, $hash_stack, $val['attributes']); + else + $ret = $this->composeArray($ret, $hash_stack); + break; + + case 'close': + array_pop($hash_stack); + break; + + case 'complete': + array_push($hash_stack, $val['tag']); + $ret = $this->composeArray($ret, $hash_stack, $val['value']); + array_pop($hash_stack); + + // handle attributes + if (isset($val['attributes'])) { + foreach ($val['attributes'] as $a_k => $a_v) { + $hash_stack[] = $val['tag'] . '_attribute_' . $a_k; + $ret = $this->composeArray($ret, $hash_stack, $a_v); + array_pop($hash_stack); + } + } + + break; + } + } + + return $ret; + } + +// end makeXMLTree + + /** + * &composeArray + * + * function used exclusively by makeXMLTree to help turn XML into an array + * + * @since version 1.0 + * @access public + * @param array $array + * @param array $elements + * @param array $value + * @return array $array + */ + private function &composeArray($array, $elements, $value=array()) { + global $XML_LIST_ELEMENTS; + + // get current element + $element = array_shift($elements); + + // does the current element refer to a list + if (sizeof($elements) > 0) { + $array[$element][sizeof($array[$element]) - 1] = &$this->composeArray($array[$element][sizeof($array[$element]) - 1], $elements, $value); + } else { // if (is_array($value)) + $array[$element][sizeof($array[$element])] = $value; + } + + return $array; + } + +// end composeArray + + /** + * noop + * + * keeps users session alive + * + * @since version 1.0 + * @access public + * @return string xml response from the noop + */ + public function noop() { + return $this->soapRequest(''); + } + + /** + * addAppointments + * + * add appointments in a calendar + * + * @since version 1.0 + * @access public + * @param + * @return + */ + public function addAppointment($serializeOp1) { + $unserializeOp1 = unserialize($serializeOp1); + + $username = $unserializeOp1['username']; + $subject = $unserializeOp1['subject']; + $appointmentName = $unserializeOp1['appointmentName']; + $friendlyName = $unserializeOp1['friendlyName']; + $userEmail = $unserializeOp1['userEmail']; + $domainName = $unserializeOp1['domainName']; + $schedule = $unserializeOp1['schedule']; + $cutype = $unserializeOp1['cutype']; + $allDay = $unserializeOp1['allDay']; + $isOrg = $unserializeOp1['isOrg']; + $rsvp = $unserializeOp1['rsvp']; + $atFriendlyName = $unserializeOp1['atFriendlyName']; + $role = $unserializeOp1['role']; + $location = $unserializeOp1['location']; + $ptst = $unserializeOp1['ptst']; + $startDate = $unserializeOp1['startDate']; + $endDate = $unserializeOp1['endDate']; + $timeZone = $unserializeOp1['tz']; + + $explodeEmail = explode(';', $userEmail); + $explodeFriendlyName = explode(';', $atFriendlyName); + $countExplodeEmail = count($explodeEmail); + + $soap = ' + ' . $subject . ''; + for ($i = 0; $i < $countExplodeEmail; $i++) { + $soap.= ''; + } + $soap.=' + + + + '; + for ($i = 0; $i < $countExplodeEmail; $i++) { + $soap.=''; + } + $soap.= ' + + + + + this is a sample Contents + + + + + '; + + $response = $this->soapRequest($soap); + if ($response) { + $array = $this->makeXMLTree($response); + + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateAppointmentResponse']; + } else { + return false; + } + } + +// end addAppointments + + /** + * addTask + * + * add Task in a Task Tab + * + * @since version 1.0 + * @access public + * @param array $options array of options to apply to retrieval from calendar + * @return array associative array of appointments + */ + public function addTask($serializeOp1) { + $unserializeOp1 = unserialize($serializeOp1); + + $subject = $unserializeOp1['subject']; + $taskName = $unserializeOp1['taskName']; + $friendlyName = $unserializeOp1['friendlyName']; + $userEmail = $unserializeOp1['userEmail']; + $priority = $unserializeOp1['priority']; + $allDay = $unserializeOp1['allDay']; + $class = $unserializeOp1['class']; + $location = $unserializeOp1['location']; + $dueDate = $unserializeOp1['dueDate']; + $status = $unserializeOp1['status']; + $percent = $unserializeOp1['percent']; + + + $soap = ' + + ' . $subject . ' + + + + + + + + + + + + + '; + + $response = $this->soapRequest($soap); + if ($response) { + $array = $this->makeXMLTree($response); + + //return $array['soap:Envelope'][0]['soap:Body'][0]['BatchResponse'][0]['CreateTaskRequest'][0]['appt']; + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateTaskResponse']; + } else { + return false; + } + } + +// end addTask + + /** + * addContacts + * + * add contact in a AddressBook + * + * @since version 1.0 + * @access public + * @param + * @return + */ + public function addContacts($serializeOp1) { + $unserializeOp1 = unserialize($serializeOp1); + + $firstName = $unserializeOp1['firstName']; + $lastName = $unserializeOp1['lastName']; + $email = $unserializeOp1['email']; + $otherData = $unserializeOp1['otherData']; + $otherDataValue = $unserializeOp1['otherDataValue']; + + $soap = ' + + ' . $firstName . ' + ' . $lastName . ' + ' . $email . ' + ' . $otherDataValue . ' + + '; + + $response = $this->soapRequest($soap); + if ($response) { + $array = $this->makeXMLTree($response); + + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateContactResponse']; + } else { + return false; + } + } + +// end addContacts + /** + * addFolder + * + * add Folder in a BriefCase + * + * @since version 1.0 + * @access public + * @param + * @return + */ + + public function addFolder($serializeOp1) { + $unserializeOp1 = unserialize($serializeOp1); + + $folderName = $unserializeOp1['folderName']; + $folderColor = $unserializeOp1['color']; + + $soap = ' + + + '; + + $response = $this->soapRequest($soap); + if ($response) { + $array = $this->makeXMLTree($response); + + return $array['soap:Envelope'][0]['soap:Body'][0]['CreateFolderResponse']; + } else { + return false; + } + } + +// end addFolder + /** + * uploadDocument + * + * add Folder in a BriefCase + * + * @since version 1.0 + * @access public + * @param + * @return + */ + + public function upload($folderId, $UploadId, $fileVersion='', $docId='') { + if ($fileVersion == '' && $docId == '') { + $soap = ' + + + + '; + } else { + $soap = ' + + + + '; + } + + $response = $this->soapRequest($soap); + if (is_array($response)) { + if (isset($response['error'])) { + return $response; + } + } else { + $array = $this->makeXMLTree($response); + + return $array['soap:Envelope'][0]['soap:Body'][0]['SaveDocumentResponse']; + } + } + +// end uploadDocument + + /** + * getDocId + * + * Get ID of File in Zimbra. + * + * @since version 1.0 + * @access public + * @param + * @return + */ + public function getDocId($folderId, $fileName) { + $soap = ' + + '; + + $response = $this->soapRequest($soap); + if (is_array($response)) { + if ($response['error']) { + return false; + } + } else { + $array = $this->makeXMLTree($response); + + return $array['soap:Envelope'][0]['soap:Body'][0]['GetItemResponse'][0]; + } + } + +// end getDocId +} + +// end Zimbra class +// annoying sorting functions for getTasks... +// I don't know how to make usort calls to internal OO functions +// if someone knows how, please fix this :) + +/** + * zimbra_startSort + * + * sort of zimbra elements + * + * @since version 1.0 + * @access public + * @param array $task_a + * @param array $task_b + * @return int (($task_a['dueDate']-$task_a['dur']) < ($task_b['dueDate']-$task_b['dur'])) ? -1 : 1 + */ +function zimbra_startSort($task_a, $task_b) { + if (($task_a['dueDate'] - $task_a['dur']) == ($task_b['dueDate'] - $task_b['dur'])) { + return ($task_a['name'] < $task_b['name']) ? -1 : 1; + } + return (($task_a['dueDate'] - $task_a['dur']) < ($task_b['dueDate'] - $task_b['dur'])) ? -1 : 1; +} + +/** + * zimbra_dueSort + * + * sort by dueDate + * + * @since version 1.0 + * @access public + * @param array $task_a + * @param array $task_b + * @return int ($task_a['dueDate'] < $task_b['dueDate']) ? -1 : 1 + */ +function zimbra_dueSort($task_a, $task_b) { + if ($task_a['dueDate'] == $task_b['dueDate']) { + return ($task_a['name'] < $task_b['name']) ? -1 : 1; + } + return ($task_a['dueDate'] < $task_b['dueDate']) ? -1 : 1; +} + +/** + * zimbra_nameSort + * + * sort by name + * + * @since version 1.0 + * @access public + * @param array $task_a + * @param array $task_b + * @return int ($task_a['name'] < $task_b['name']) ? -1 : 1 + */ +function zimbra_nameSort($task_a, $task_b) { + if ($task_a['name'] == $task_b['name']) { + return 0; + } + return ($task_a['name'] < $task_b['name']) ? -1 : 1; +} + +?> \ No newline at end of file diff --git a/workflow/engine/classes/triggers/class.pmTrZimbra.php b/workflow/engine/classes/triggers/class.pmTrZimbra.php new file mode 100644 index 000000000..23ffc837a --- /dev/null +++ b/workflow/engine/classes/triggers/class.pmTrZimbra.php @@ -0,0 +1,418 @@ +connect(); + + if (!$connectionResult) { + return "Check userName or Server URL"; + } + + $aXmlArray = array(); + $aXmlArray = $zimbra->getFolder($folderName); + $sXmlArray = @json_decode(@json_encode($aXmlArray), 1); + + $serializeResult = serialize($sXmlArray); // serializing the Array for Returning. + return $serializeResult; +} + +/** + * @method + * + * Get Contact List + * + * @name getZimbraContactList + * @label Get Contact Lists from Zimbra Server + * + * @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap + * @param string | $username| Valid username to connect to Zimbra server + * @param string | $preAuthKey | Server Key for SSO authentication + * + * @return string | $result | Response + * + */ +function getZimbraContactList($ServerUrl, $username, $preAuthKey) { + + $zimbra = new Zimbra($username, $ServerUrl, $preAuthKey); + $connectionResult = $zimbra->connect(); + + if (!$connectionResult) { + return "Check userName or Server URL"; + } + + $sXmlArray = array(); + $sXmlArray = $zimbra->getContacts(); + $aXmlArray = @json_decode(@json_encode($sXmlArray), 1); + + $serializeResult = serialize($aXmlArray); // serializing the Array for Returning. + return $serializeResult; +} + +/** + * @method + * + * Get Task List + * + * @name getZimbraTaskList + * @label Get Task Lists from Zimbra Server + * + * @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap + * @param string | $username| Valid username to connect to Zimbra server + * @param string | $preAuthKey | Server Key for SSO authentication + * + * @return string | $result | Response + * + */ +function getZimbraTaskList($ServerUrl, $username, $preAuthKey) { + + $xXmlArray = array(); + $xXmlArray1 = array(); + + $zimbra = new Zimbra($username, $ServerUrl, $preAuthKey); + $connectionResult = $zimbra->connect(); + + if (!$connectionResult) { + return "Check userName or Server URL"; + } + + $sXmlArray = array(); + $sXmlArray = $zimbra->getTasks(); + $aXmlArray = @json_decode(@json_encode($sXmlArray), 1); + + $serializeResult = serialize($aXmlArray); // serializing the Array for Returning. + return $serializeResult; +} + +/** + * @method + * + * Get Appointment List + * + * @name getZimbraAppointmentList + * @label Get Appointment Lists from Zimbra Server + * + * @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap + * @param string | $username| Valid username to connect to Zimbra server + * @param string | $preAuthKey | Server Key for SSO authentication + * + * @return string | $result | Response + * + */ +function getZimbraAppointmentList($ServerUrl, $username, $preAuthKey) { + + $xXmlArray = array(); + $xXmlArray1 = array(); + + $zimbra = new Zimbra($username, $ServerUrl, $preAuthKey); + $connectionResult = $zimbra->connect(); + + if (!$connectionResult) { + return "Check userName or Server URL"; + } + + $sXmlArray = array(); + $sXmlArray = $zimbra->getAppointments(); + $aXmlArray = @json_decode(@json_encode($sXmlArray), 1); + + $serializeResult = serialize($aXmlArray); // serializing the Array for Returning. + return $serializeResult; +} + +/** + * @method + * + * Create Folder Name and Attribute + * + * @name createZimbraFolder + * @label Create Specified Folder with Attributes in Briefcase Tab + * + * @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap + * @param string | $username | Valid username to connect to Zimbra server + * @param string | $preAuthKey | Server Key for SSO authentication + * @param string | $folderName | Folder Name + * @param string | $color | Color of Folder + * + * @return string | $result | Response + * + */ +function createZimbraFolder($ServerUrl, $username, $preAuthKey, $folderName, $color) { + $serializeOp = array(); + $serializeOp = array('folderName' => $folderName, 'color' => $color); + $serializeOp1 = serialize($serializeOp); + + $zimbra = new Zimbra($username, $ServerUrl, $preAuthKey); + $connectionResult = $zimbra->connect(); + + if (!$connectionResult) { + return "Check userName or Server URL"; + } + $sXmlArray = $zimbra->addFolder($serializeOp1); + if ($sXmlArray) { + return "Folder Created succesfully"; + } else { + return "A folder with name " . $folderName . " already exists."; + } +} + +/** + * @method + * + * Create Contacts + * + * @name createZimbraContacts + * @label Create Contacts in Address Book + * + * @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap + * @param string | $username | Valid username to connect to Zimbra server + * @param string | $preAuthKey | Server Key for SSO authentication + * @param string | $firstName | First Name + * @param string | $lastName | Last Name + * @param string | $email | Email Address + * @param string | $otherData | BirthDay/Anniversary/Custom + * @param string | $otherDataValue | Corresponding Date or Value + * + * @return string | $result | Response + * + */ +function createZimbraContacts($ServerUrl, $username, $preAuthKey, $firstName, $lastName, $email, $otherData, $otherDataValue) { + + $serializeOp = array(); + $serializeOp = array('firstName' => $firstName, 'lastName' => $lastName, 'email' => $email, 'otherData' => $otherData, 'otherDataValue' => $otherDataValue); + $serializeOp1 = serialize($serializeOp); + + $zimbra = new Zimbra($username, $ServerUrl, $preAuthKey); + $connectionResult = $zimbra->connect(); + + if (!$connectionResult) { + return "Check userName or Server URL"; + } + + $sXmlArray = $zimbra->addContacts($serializeOp1); + if ($sXmlArray) { + return "Contacts Created succesfully"; + } else { + return "Some Error"; + } +} + +/** + * @method + * + * Create Tasks + * + * @name createZimbraTask + * @label Create Task + * + * @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap + * @param string | $username | Valid username to connect to Zimbra server + * @param string | $preAuthKey | Server Key for SSO authentication + * @param string | $subject | Mail Subject + * @param string | $taskName | Task Name + * @param string | $friendlyName | Friendly Name of the User + * @param string | $userEmail | Email Address of the User + * @param string | $priority | Priority of the Task + * @param string | $allDay | Is All Day Task + * @param string | $class | Access Scope of the Class + * @param string | $location | Location of the task + * @param string | $dueDate | Due Date of the task + * @param string | $status | Status of the task + * @param string | $percent | Percentage of Task Completed + * + * @return string | $result | Response + * + */ +function createZimbraTask($ServerUrl, $username, $preAuthKey, $subject, $taskName, $friendlyName, $userEmail, $priority, $allDay, $class, $location, $dueDate, $status, $percent) { + + $serializeOp = array(); + $serializeOp = array('subject' => $subject, 'taskName' => $taskName, 'friendlyName' => $friendlyName, 'userEmail' => $userEmail, 'priority' => $priority, 'allDay' => $allDay, 'class' => $class, 'location' => $location, 'dueDate' => $dueDate, 'status' => $status, 'percent' => $percent); + $serializeOp1 = serialize($serializeOp); + + $zimbra = new Zimbra($username, $ServerUrl, $preAuthKey); + $connectionResult = $zimbra->connect(); + + if (!$connectionResult) { + return "Check userName or Server URL"; + } + + $sXmlArray = $zimbra->addTask($serializeOp1); + if ($sXmlArray) { + return "Task Created succesfully"; + } else { + return "Error in Creating Task"; + } +} + +/** + * @method + * + * Create Appointment + * + * @name createZimbraAppointment + * @label Create Appointment + * + * @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap + * @param string | $username | Valid username to connect to Zimbra server + * @param string | $preAuthKey | Server Key for SSO authentication + * @param string | $subject | Mail Subject + * @param string | $appointmentName | Appointment Name + * @param string | $friendlyName | Organizer's Friendly Name + * @param string | $userEmail | Email Address of the Attendee(s) seperated by ';' + * @param string | $domainName | Domain Name + * @param string | $schedule | Schedule of the Appointment + * @param string | $cutype | Type of Calendar User + * @param string | $allDay | Is All Day Appointment + * @param string | $isOrg | Is Organizer + * @param string | $rsvp | RSVP + * @param string | $atFriendlyName | Friendly Name of Attendee(s) seperated by ';' + * @param string | $role | Attendee's Role + * @param string | $location | Location + * @param string | $ptst | Paticipation Status of the user + * @param string | $startDate | Start Date of the Appointment + * @param string | $endDate | End Date of the Appointment + * @param string | $tz | Time Zone + * + * @return string | $result | Response + * + */ +function createZimbraAppointment($ServerUrl, $username, $preAuthKey, $subject, $appointmentName, $friendlyName, $userEmail, $domainName, $schedule, $cutype, $allDay, $isOrg, $rsvp, $atFriendlyName, $role, $location, $ptst, $startDate, $endDate, $tz='') { + + $serializeOp = array(); + $serializeOp = array('username' => $username, 'subject' => $subject, 'appointmentName' => $appointmentName, 'friendlyName' => $friendlyName, 'userEmail' => $userEmail, 'domainName' => $domainName, 'schedule' => $schedule, 'cutype' => $cutype, 'allDay' => $allDay, 'isOrg' => $isOrg, 'rsvp' => $rsvp, 'atFriendlyName' => $atFriendlyName, 'role' => $role, 'location' => $location, 'ptst' => $ptst, 'startDate' => $startDate, 'endDate' => $endDate, 'tz' => $tz); + $serializeOp1 = serialize($serializeOp); + + $zimbra = new Zimbra($username, $ServerUrl, $preAuthKey); + $connectionResult = $zimbra->connect(); + + if (!$connectionResult) { + return "Check userName or Server URL"; + } + + $sXmlArray = $zimbra->addAppointment($serializeOp1); + if ($sXmlArray) { + return "Appointment Created succesfully"; + } else { + return "Error in Creating Appointment"; + } +} + +/** + * @method + * + * Upload File/Document to Zimbra Server + * + * @name uploadZimbraFile + * @label Upload File/Document to Zimbra Server + * + * @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap + * @param string | $username | Valid username to connect to Zimbra server + * @param string | $preAuthKey | Server Key for SSO authentication + * @param string | $folderName | Folder Name + * @param string | $fileLocation | Absolute path of the File to be uploaded. + * + * @return string | $result | Response + * + */ +function uploadZimbraFile($ServerUrl, $username, $preAuthKey, $folderName, $fileLocation) { + + $header_array = array("ENCTYPE" => "multipart/form-data"); + $credentials = "root:solutions"; + $options = array(headers => $header_array, + httpauth => $credentials, + httpauthtype => HTTP_AUTH_BASIC); //1. test without the credentials + + $file = $fileLocation; + + $oZimbraObj = new Zimbra($username, $ServerUrl, $preAuthKey); + $connectResult = $oZimbraObj->connect(); + $sAuthToken = $oZimbraObj->auth_token; + $cookie = array('ZM_AUTH_TOKEN' => $sAuthToken, 'ZM_TEST' => true); + + $url = "http://$ServerUrl/service/upload?fmt=raw"; + $request = new HttpRequest($url, HTTP_METH_POST); + $request->setCookies($cookie); + $request->addPostFile("uploadFile", $file); // 2. test without 1st parameter + $request->addPostFields(array($options)); + + $sendResult = $request->send(); + + // gettin Upload ID + + $aResponce = (array) $sendResult; + $counter = 0; + foreach ($aResponce as $values) { + $counter++; + if ($counter == 2) { + $sResponce = $values; + } + } + + $aString = array(); + $aExplode = explode(",", $sResponce); + $uploadID = substr($aExplode[2], 1, -2); + + // gettin FOlder ID + + $FolderResult = $oZimbraObj->getFolder($folderName); + if (isset($FolderResult['id'])) { + $sFolderID = $FolderResult['id']; + } else { + $sFolderID = $FolderResult['folder_attribute_id']['0']; + } + + $fileNamePath = $fileLocation; + $fileName = basename($fileNamePath); + + $docDetails = $oZimbraObj->getDocId($sFolderID, $fileName); + if ($docDetails) { + $docId = $docDetails['doc_attribute_id'][0]; + $docVersion = $docDetails['doc_attribute_ver'][0]; + } + $uploadResult = $oZimbraObj->upload($sFolderID, $uploadID, $docVersion, $docId); + if (isset($uploadResult['error'])) { + return $uploadResult['error']; + } else { + return "The file has been uploaded Successfully"; + } +} \ No newline at end of file diff --git a/workflow/public_html/images/triggers/zimbra.gif b/workflow/public_html/images/triggers/zimbra.gif new file mode 100644 index 000000000..e63cb8df6 Binary files /dev/null and b/workflow/public_html/images/triggers/zimbra.gif differ