2011-11-29 16:39:39 -04:00
|
|
|
<?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
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
|
2011-11-29 16:39:39 -04:00
|
|
|
* @param string | $username | Valid username to connect to Zimbra server
|
|
|
|
|
* @param string | $preAuthKey | Server Key for SSO authentication
|
|
|
|
|
* @param string | $folderName | Folder Name
|
2012-12-11 11:00:02 -04:00
|
|
|
* @param string | $protocol | protpcol server http https
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
2013-04-03 13:40:57 -04:00
|
|
|
* @return string | $result | Response |
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2012-12-11 11:00:02 -04:00
|
|
|
function getZimbraFolder($ServerUrl, $username, $preAuthKey, $folderName, $protocol = 'http')
|
|
|
|
|
{
|
|
|
|
|
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey , '', $protocol);
|
2011-11-29 16:39:39 -04:00
|
|
|
$connectionResult = $zimbra->connect();
|
|
|
|
|
|
|
|
|
|
if (!$connectionResult) {
|
|
|
|
|
return "Check userName or Server URL";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$aXmlArray = array();
|
|
|
|
|
$aXmlArray = $zimbra->getFolder($folderName);
|
2012-04-23 12:34:16 -04:00
|
|
|
$sXmlArray = @G::json_decode(@G::json_encode($aXmlArray), 1);
|
2011-11-29 16:39:39 -04:00
|
|
|
|
|
|
|
|
$serializeResult = serialize($sXmlArray); // serializing the Array for Returning.
|
|
|
|
|
return $serializeResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method
|
|
|
|
|
*
|
|
|
|
|
* Get Contact List
|
|
|
|
|
*
|
|
|
|
|
* @name getZimbraContactList
|
|
|
|
|
* @label Get Contact Lists from Zimbra Server
|
|
|
|
|
*
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
|
2011-11-29 16:39:39 -04:00
|
|
|
* @param string | $username| Valid username to connect to Zimbra server
|
|
|
|
|
* @param string | $preAuthKey | Server Key for SSO authentication
|
2012-12-11 11:00:02 -04:00
|
|
|
* @param string | $protocol | protpcol server http https
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
2013-04-03 13:40:57 -04:00
|
|
|
* @return string | $result | Response |
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2012-12-11 11:00:02 -04:00
|
|
|
function getZimbraContactList($ServerUrl, $username, $preAuthKey, $protocol = 'http')
|
|
|
|
|
{
|
2011-11-29 16:39:39 -04:00
|
|
|
|
2012-12-11 11:00:02 -04:00
|
|
|
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
|
2011-11-29 16:39:39 -04:00
|
|
|
$connectionResult = $zimbra->connect();
|
|
|
|
|
|
|
|
|
|
if (!$connectionResult) {
|
|
|
|
|
return "Check userName or Server URL";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sXmlArray = array();
|
|
|
|
|
$sXmlArray = $zimbra->getContacts();
|
2012-04-23 12:34:16 -04:00
|
|
|
$aXmlArray = @G::json_decode(@G::json_encode($sXmlArray), 1);
|
2011-11-29 16:39:39 -04:00
|
|
|
|
|
|
|
|
$serializeResult = serialize($aXmlArray); // serializing the Array for Returning.
|
|
|
|
|
return $serializeResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method
|
|
|
|
|
*
|
|
|
|
|
* Get Task List
|
|
|
|
|
*
|
|
|
|
|
* @name getZimbraTaskList
|
|
|
|
|
* @label Get Task Lists from Zimbra Server
|
|
|
|
|
*
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
|
2011-11-29 16:39:39 -04:00
|
|
|
* @param string | $username| Valid username to connect to Zimbra server
|
|
|
|
|
* @param string | $preAuthKey | Server Key for SSO authentication
|
2012-12-11 11:00:02 -04:00
|
|
|
* @param string | $protocol | protpcol server http https
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
2013-04-03 13:40:57 -04:00
|
|
|
* @return string | $result | Response |
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2012-12-11 11:00:02 -04:00
|
|
|
function getZimbraTaskList($ServerUrl, $username, $preAuthKey, $protocol = 'http')
|
|
|
|
|
{
|
2011-11-29 16:39:39 -04:00
|
|
|
|
|
|
|
|
$xXmlArray = array();
|
|
|
|
|
$xXmlArray1 = array();
|
|
|
|
|
|
2012-12-11 11:00:02 -04:00
|
|
|
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol = 'http');
|
2011-11-29 16:39:39 -04:00
|
|
|
$connectionResult = $zimbra->connect();
|
|
|
|
|
|
|
|
|
|
if (!$connectionResult) {
|
|
|
|
|
return "Check userName or Server URL";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sXmlArray = array();
|
|
|
|
|
$sXmlArray = $zimbra->getTasks();
|
2012-04-23 12:34:16 -04:00
|
|
|
$aXmlArray = @G::json_decode(@G::json_encode($sXmlArray), 1);
|
2011-11-29 16:39:39 -04:00
|
|
|
|
|
|
|
|
$serializeResult = serialize($aXmlArray); // serializing the Array for Returning.
|
|
|
|
|
return $serializeResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method
|
|
|
|
|
*
|
2012-04-27 16:39:51 -04:00
|
|
|
* Get Appointment List
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
|
|
|
|
* @name getZimbraAppointmentList
|
|
|
|
|
* @label Get Appointment Lists from Zimbra Server
|
|
|
|
|
*
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
|
2011-11-29 16:39:39 -04:00
|
|
|
* @param string | $username| Valid username to connect to Zimbra server
|
|
|
|
|
* @param string | $preAuthKey | Server Key for SSO authentication
|
2012-12-11 11:00:02 -04:00
|
|
|
* @param string | $protocol | protpcol server http https
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
2013-04-03 13:40:57 -04:00
|
|
|
* @return string | $result | Response |
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2012-12-11 11:00:02 -04:00
|
|
|
function getZimbraAppointmentList($ServerUrl, $username, $preAuthKey, $protocol = 'http')
|
|
|
|
|
{
|
2011-11-29 16:39:39 -04:00
|
|
|
|
|
|
|
|
$xXmlArray = array();
|
|
|
|
|
$xXmlArray1 = array();
|
|
|
|
|
|
2012-12-11 11:00:02 -04:00
|
|
|
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
|
2011-11-29 16:39:39 -04:00
|
|
|
$connectionResult = $zimbra->connect();
|
|
|
|
|
|
|
|
|
|
if (!$connectionResult) {
|
|
|
|
|
return "Check userName or Server URL";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sXmlArray = array();
|
|
|
|
|
$sXmlArray = $zimbra->getAppointments();
|
2012-04-23 12:34:16 -04:00
|
|
|
$aXmlArray = @G::json_decode(@G::json_encode($sXmlArray), 1);
|
2011-11-29 16:39:39 -04:00
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
*
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
|
2011-11-29 16:39:39 -04:00
|
|
|
* @param string | $username | Valid username to connect to Zimbra server
|
|
|
|
|
* @param string | $preAuthKey | Server Key for SSO authentication
|
|
|
|
|
* @param string | $folderName | Folder Name
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $color | Color of Folder
|
2012-12-11 11:00:02 -04:00
|
|
|
* @param string | $protocol | protpcol server http https
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
2013-04-03 13:40:57 -04:00
|
|
|
* @return string | $result | Response |
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2012-12-11 11:00:02 -04:00
|
|
|
function createZimbraFolder($ServerUrl, $username, $preAuthKey, $folderName, $color, $protocol = 'http')
|
|
|
|
|
{
|
2011-11-29 16:39:39 -04:00
|
|
|
$serializeOp = array();
|
|
|
|
|
$serializeOp = array('folderName' => $folderName, 'color' => $color);
|
|
|
|
|
$serializeOp1 = serialize($serializeOp);
|
|
|
|
|
|
2012-12-11 11:00:02 -04:00
|
|
|
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
|
2011-11-29 16:39:39 -04:00
|
|
|
$connectionResult = $zimbra->connect();
|
|
|
|
|
|
|
|
|
|
if (!$connectionResult) {
|
|
|
|
|
return "Check userName or Server URL";
|
|
|
|
|
}
|
|
|
|
|
$sXmlArray = $zimbra->addFolder($serializeOp1);
|
|
|
|
|
if ($sXmlArray) {
|
|
|
|
|
return "Folder Created succesfully";
|
|
|
|
|
} else {
|
2012-07-25 16:51:09 -04:00
|
|
|
return "A folder with name " . $folderName . " already exist.";
|
2011-11-29 16:39:39 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method
|
|
|
|
|
*
|
2012-04-27 16:39:51 -04:00
|
|
|
* Create Contacts
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
|
|
|
|
* @name createZimbraContacts
|
|
|
|
|
* @label Create Contacts in Address Book
|
|
|
|
|
*
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
|
2011-11-29 16:39:39 -04:00
|
|
|
* @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
|
2012-12-11 11:00:02 -04:00
|
|
|
* @param string | $protocol | protpcol server http https
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
2013-04-03 13:40:57 -04:00
|
|
|
* @return string | $result | Response |
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2012-12-11 11:00:02 -04:00
|
|
|
function createZimbraContacts($ServerUrl, $username, $preAuthKey, $firstName, $lastName, $email, $otherData, $otherDataValue, $protocol = 'http')
|
|
|
|
|
{
|
2011-11-29 16:39:39 -04:00
|
|
|
|
|
|
|
|
$serializeOp = array();
|
|
|
|
|
$serializeOp = array('firstName' => $firstName, 'lastName' => $lastName, 'email' => $email, 'otherData' => $otherData, 'otherDataValue' => $otherDataValue);
|
|
|
|
|
$serializeOp1 = serialize($serializeOp);
|
|
|
|
|
|
2012-12-11 11:00:02 -04:00
|
|
|
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
|
2011-11-29 16:39:39 -04:00
|
|
|
$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
|
|
|
|
|
*
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
|
2011-11-29 16:39:39 -04:00
|
|
|
* @param string | $username | Valid username to connect to Zimbra server
|
|
|
|
|
* @param string | $preAuthKey | Server Key for SSO authentication
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $subject | Mail Subject
|
2011-11-29 16:39:39 -04:00
|
|
|
* @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
|
2012-12-11 11:00:02 -04:00
|
|
|
* @param string | $protocol | protpcol server http https
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
2013-04-03 13:40:57 -04:00
|
|
|
* @return string | $result | Response |
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2012-12-11 11:00:02 -04:00
|
|
|
function createZimbraTask($ServerUrl, $username, $preAuthKey, $subject, $taskName, $friendlyName, $userEmail, $priority, $allDay, $class, $location, $dueDate, $status, $percent, $protocol = 'http')
|
|
|
|
|
{
|
2011-11-29 16:39:39 -04:00
|
|
|
$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);
|
|
|
|
|
|
2012-12-11 11:00:02 -04:00
|
|
|
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
|
2011-11-29 16:39:39 -04:00
|
|
|
|
2012-04-27 16:39:51 -04:00
|
|
|
$connectionResult = $zimbra->connect();
|
2011-11-29 16:39:39 -04:00
|
|
|
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
|
|
|
|
|
*
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
|
2011-11-29 16:39:39 -04:00
|
|
|
* @param string | $username | Valid username to connect to Zimbra server
|
|
|
|
|
* @param string | $preAuthKey | Server Key for SSO authentication
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $subject | Mail Subject
|
2011-11-29 16:39:39 -04:00
|
|
|
* @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
|
2012-12-11 11:00:02 -04:00
|
|
|
* @param string | $protocol | protpcol server http https
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
2013-04-03 13:40:57 -04:00
|
|
|
* @return string | $result | Response |
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2012-12-11 11:00:02 -04:00
|
|
|
function createZimbraAppointment($ServerUrl, $username, $preAuthKey, $subject, $appointmentName, $friendlyName, $userEmail, $domainName, $schedule, $cutype, $allDay, $isOrg, $rsvp, $atFriendlyName, $role, $location, $ptst, $startDate, $endDate, $tz = '', $protocol = 'http')
|
|
|
|
|
{
|
2011-11-29 16:39:39 -04:00
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
|
2012-12-11 11:00:02 -04:00
|
|
|
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
|
2011-11-29 16:39:39 -04:00
|
|
|
$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
|
|
|
|
|
*
|
2012-04-27 16:39:51 -04:00
|
|
|
* @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
|
2011-11-29 16:39:39 -04:00
|
|
|
* @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.
|
2012-12-11 11:00:02 -04:00
|
|
|
* @param string | $protocol | protpcol server http https
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
2013-04-03 13:40:57 -04:00
|
|
|
* @return string | $result | Response |
|
2011-11-29 16:39:39 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2012-12-11 11:00:02 -04:00
|
|
|
function uploadZimbraFile($ServerUrl, $username, $preAuthKey, $folderName, $fileLocation, $protocol = 'http')
|
|
|
|
|
{
|
2011-11-29 16:39:39 -04:00
|
|
|
|
|
|
|
|
$header_array = array("ENCTYPE" => "multipart/form-data");
|
|
|
|
|
$file = $fileLocation;
|
|
|
|
|
|
2012-12-11 11:00:02 -04:00
|
|
|
$oZimbraObj = new Zimbra($username, $ServerUrl, $preAuthKey, '', $protocol);
|
2011-11-29 16:39:39 -04:00
|
|
|
$connectResult = $oZimbraObj->connect();
|
|
|
|
|
$sAuthToken = $oZimbraObj->auth_token;
|
|
|
|
|
$cookie = array('ZM_AUTH_TOKEN' => $sAuthToken, 'ZM_TEST' => true);
|
2012-04-27 16:39:51 -04:00
|
|
|
$cookie = 'ZM_AUTH_TOKEN=' . $sAuthToken. '; ZM_TEST='. true;
|
2011-11-29 16:39:39 -04:00
|
|
|
$url = "http://$ServerUrl/service/upload?fmt=raw";
|
2012-04-27 16:39:51 -04:00
|
|
|
$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);
|
2012-09-19 14:48:38 -04:00
|
|
|
|
|
|
|
|
//Apply proxy settings
|
2017-08-04 11:49:43 -04:00
|
|
|
$sysConf = PmSystem::getSystemConfiguration();
|
2012-09-19 14:48:38 -04:00
|
|
|
if ($sysConf['proxy_host'] != '') {
|
2012-12-11 11:00:02 -04:00
|
|
|
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:'));
|
2012-09-19 14:48:38 -04:00
|
|
|
}
|
|
|
|
|
|
2012-12-11 11:00:02 -04:00
|
|
|
if ( ! $response = curl_exec($ch)) {
|
|
|
|
|
return "Upload error. Connection Error";
|
2011-11-29 16:39:39 -04:00
|
|
|
}
|
2012-09-19 14:48:38 -04:00
|
|
|
|
2012-04-27 16:39:51 -04:00
|
|
|
//G::pr($response);
|
2012-09-19 14:48:38 -04:00
|
|
|
|
2012-04-27 16:39:51 -04:00
|
|
|
$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);
|
2012-09-19 14:48:38 -04:00
|
|
|
|
2011-11-29 16:39:39 -04:00
|
|
|
$aString = array();
|
2012-04-27 16:39:51 -04:00
|
|
|
$aExplode = explode(",", $result['body']);
|
2011-11-29 16:39:39 -04:00
|
|
|
$uploadID = substr($aExplode[2], 1, -2);
|
2012-09-19 14:48:38 -04:00
|
|
|
|
2012-04-27 16:39:51 -04:00
|
|
|
curl_close($ch);
|
2012-09-19 14:48:38 -04:00
|
|
|
|
2012-04-27 16:39:51 -04:00
|
|
|
// gettin FOlder ID
|
2011-11-29 16:39:39 -04:00
|
|
|
|
|
|
|
|
$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";
|
|
|
|
|
}
|
2012-12-11 11:00:02 -04:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|