Spaces:
Sleeping
Sleeping
File size: 16,046 Bytes
07c3cdd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | <?php
/**
* class.pmTrZimbra.pmFunctions.php
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2008 Colosa Inc.
* *
*/
////////////////////////////////////////////////////
// pmTrZimbra PM Functions
//
// Copyright (C) 2007 COLOSA
//
// License: LGPL, see LICENSE
////////////////////////////////////////////////////
use ProcessMaker\Core\System;
/**
* Triggers that allow ProcessMaker to integrate with Zimbra
* @class pmZimbra
* @name Zimbra Triggers v. 0.1
* @icon /images/triggers/zimbra.gif
* @className class.pmZimbra.pmFunctions.php
*/
/**
* @method
*
* Get Folder Name and Attributes
*
* @name getZimbraFolder
* @label Get Attributes for specified FolderName
*
* @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
* @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 | $protocol | protpcol server http https
*
* @return string | $result | Response |
*
*/
function getZimbraFolder($ServerUrl, $username, $preAuthKey, $folderName, $protocol = 'http')
{
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey , '', $protocol);
$connectionResult = $zimbra->connect();
if (!$connectionResult) {
return "Check userName or Server URL";
}
$aXmlArray = array();
$aXmlArray = $zimbra->getFolder($folderName);
$sXmlArray = @G::json_decode(@G::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 | zimbra.server:port
* @param string | $username| Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication
* @param string | $protocol | protpcol server http https
*
* @return string | $result | Response |
*
*/
function getZimbraContactList($ServerUrl, $username, $preAuthKey, $protocol = 'http')
{
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
$connectionResult = $zimbra->connect();
if (!$connectionResult) {
return "Check userName or Server URL";
}
$sXmlArray = array();
$sXmlArray = $zimbra->getContacts();
$aXmlArray = @G::json_decode(@G::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 | zimbra.server:port
* @param string | $username| Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication
* @param string | $protocol | protpcol server http https
*
* @return string | $result | Response |
*
*/
function getZimbraTaskList($ServerUrl, $username, $preAuthKey, $protocol = 'http')
{
$xXmlArray = array();
$xXmlArray1 = array();
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol = 'http');
$connectionResult = $zimbra->connect();
if (!$connectionResult) {
return "Check userName or Server URL";
}
$sXmlArray = array();
$sXmlArray = $zimbra->getTasks();
$aXmlArray = @G::json_decode(@G::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 | zimbra.server:port
* @param string | $username| Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication
* @param string | $protocol | protpcol server http https
*
* @return string | $result | Response |
*
*/
function getZimbraAppointmentList($ServerUrl, $username, $preAuthKey, $protocol = 'http')
{
$xXmlArray = array();
$xXmlArray1 = array();
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
$connectionResult = $zimbra->connect();
if (!$connectionResult) {
return "Check userName or Server URL";
}
$sXmlArray = array();
$sXmlArray = $zimbra->getAppointments();
$aXmlArray = @G::json_decode(@G::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 | zimbra.server:port
* @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
* @param string | $protocol | protpcol server http https
*
* @return string | $result | Response |
*
*/
function createZimbraFolder($ServerUrl, $username, $preAuthKey, $folderName, $color, $protocol = 'http')
{
$serializeOp = array();
$serializeOp = array('folderName' => $folderName, 'color' => $color);
$serializeOp1 = serialize($serializeOp);
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
$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 exist.";
}
}
/**
* @method
*
* Create Contacts
*
* @name createZimbraContacts
* @label Create Contacts in Address Book
*
* @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
* @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
* @param string | $protocol | protpcol server http https
*
* @return string | $result | Response |
*
*/
function createZimbraContacts($ServerUrl, $username, $preAuthKey, $firstName, $lastName, $email, $otherData, $otherDataValue, $protocol = 'http')
{
$serializeOp = array();
$serializeOp = array('firstName' => $firstName, 'lastName' => $lastName, 'email' => $email, 'otherData' => $otherData, 'otherDataValue' => $otherDataValue);
$serializeOp1 = serialize($serializeOp);
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
$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 | zimbra.server:port
* @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
* @param string | $protocol | protpcol server http https
*
* @return string | $result | Response |
*
*/
function createZimbraTask($ServerUrl, $username, $preAuthKey, $subject, $taskName, $friendlyName, $userEmail, $priority, $allDay, $class, $location, $dueDate, $status, $percent, $protocol = 'http')
{
$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, '', $protocol);
$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 | zimbra.server:port
* @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
* @param string | $protocol | protpcol server http https
*
* @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 = '', $protocol = 'http')
{
$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, '', $protocol);
$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 | zimbra.server:port
* @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.
* @param string | $protocol | protpcol server http https
*
* @return string | $result | Response |
*
*/
function uploadZimbraFile($ServerUrl, $username, $preAuthKey, $folderName, $fileLocation, $protocol = 'http')
{
$header_array = array("ENCTYPE" => "multipart/form-data");
$file = $fileLocation;
$oZimbraObj = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
$connectResult = $oZimbraObj->connect();
$sAuthToken = $oZimbraObj->auth_token;
$cookie = array('ZM_AUTH_TOKEN' => $sAuthToken, 'ZM_TEST' => true);
$cookie = 'ZM_AUTH_TOKEN=' . $sAuthToken. '; ZM_TEST='. true;
$url = "http://$ServerUrl/service/upload?fmt=raw";
$params = array (
'uploadFile' => "@$file"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt ($ch, CURLOPT_COOKIESESSION, true);
curl_setopt ($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt ($ch, CURLOPT_HEADER, true);
curl_setopt ($ch, CURLOPT_NOPROGRESS, false);
curl_setopt ($ch, CURLOPT_VERBOSE, true);
curl_setopt ($ch, CURLOPT_HTTPHEADER,$header_array);
//Apply proxy settings
$sysConf = System::getSystemConfiguration();
if ($sysConf['proxy_host'] != '') {
curl_setopt($ch, CURLOPT_PROXY, $sysConf['proxy_host'] . ($sysConf['proxy_port'] != '' ? ':' . $sysConf['proxy_port'] : ''));
if ($sysConf['proxy_port'] != '') {
curl_setopt($ch, CURLOPT_PROXYPORT, $sysConf['proxy_port']);
}
if ($sysConf['proxy_user'] != '') {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $sysConf['proxy_user'] . ($sysConf['proxy_pass'] != '' ? ':' . $sysConf['proxy_pass'] : ''));
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
}
if ( ! $response = curl_exec($ch)) {
return "Upload error. Connection Error";
}
//G::pr($response);
$header_size = curl_getinfo($ch,CURLINFO_HEADER_SIZE);
$result['header'] = substr($response, 0, $header_size);
$result['body'] = substr( $response, $header_size );
$result['http_code'] = curl_getinfo($ch,CURLINFO_HTTP_CODE);
$result['last_url'] = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);
$aString = array();
$aExplode = explode(",", $result['body']);
$uploadID = substr($aExplode[2], 1, -2);
curl_close($ch);
// 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";
}
}
|