I'm attempting to plug a php based calendar management system into exchange 2007 calendars.
I have the below code setup at present.
$subject = 'Appointment with ..';
$request = new EWSType_CreateItemType();
$request->Items = new EWSType_NonEmptyArrayOfAllItemsType();
$request->Items->CalendarItem = new EWSType_CalendarItemType();
$request->Items->CalendarItem->Subject = $subject;
$date1 = new DateTime('2015-05-10T15:00:00+03:00');
$DateStart = $date1->format('Y-m-d H:i:00');
$date = new DateTime($DateStart);
$request->Items->CalendarItem->Start = $date->format('c');
$date1 = new DateTime('2015-05-10T17:00:00+03:00');
$DateEnd = $date1->format('Y-m-d H:i:00');
$date = new DateTime($DateEnd);
$request->Items->CalendarItem->End = $date->format('c');
$request->Items->CalendarItem->ReminderIsSet = false;
$request->Items->CalendarItem->ReminderMinutesBeforeStart = 15;
$request->Items->CalendarItem->Body = new EWSType_BodyType();
$request->Items->CalendarItem->Body->BodyType = EWSType_BodyTypeType::HTML;
$request->Items->CalendarItem->Body->_ = <<<EOD
<p><strong>Staff Attending</strong>:bob</p>
EOD;
$request->Items->CalendarItem->ItemClass = new EWSType_ItemClassType();
$request->Items->CalendarItem->ItemClass->_ = EWSType_ItemClassType::APPOINTMENT;
$request->Items->CalendarItem->Sensitivity = new EWSType_SensitivityChoicesType();
$request->Items->CalendarItem->Sensitivity->_ = EWSType_SensitivityChoicesType::NORMAL;
$request->Items->CalendarItem->Categories = new EWSType_ArrayOfStringsType();
$request->Items->CalendarItem->Categories->String = array(
'Client Meeting (Scheduled)'
);
$request->Items->CalendarItem->Location = "Showroom";
$request->SendMeetingInvitations = EWSType_CalendarItemCreateOrDeleteOperationType::SEND_ONLY_TO_ALL;
$request->Items->CalendarItem->RequiredAttendees->Attendee[0]->Mailbox->EmailAddress = "user#domain.com";
$request->Items->CalendarItem->RequiredAttendees->Attendee[0]->Mailbox->RoutingType = 'SMTP';
$n = 1;
$response = $ews->CreateItem($request);
This will setup an event in the users personal calendar just fine, but what I need to do is to get it to post to a public folder calendar which I have the folderID for.
If anyone could assist it would be greatly appreciated!
Try adding the line:
$request->SavedItemFolderId->FolderId->Id=$folder_id;
after the
$request = new EWSType_CreateItemType();
where $folder_id is your stupidly long microsoft folder id!!!!
I'm doing the same right now.
You have to replace the SEND_ONLY_TO_ALL with SEND_TO_NONE.
This means that we cannot send meeting invitations for appointments stored in a public folder (I've been trying to find a workaround for this problem for a couple weeks now).
I'm not sure if there are other problems in your request but this is surely an issue.
Related
I have this code that updates my Google MySQL instance authorized IPs, connection is ok, the code prints me the current IP's but it cannot add a new IP to the settings I tried many ways but it still do not works it doesn't make any change to the Instance configuration.
$client = new Google_Client();
$client->setAuthConfig('../config/service-account.json');
$client->setApplicationName(env("APP_NAME"));
$projectName = env("GOOGLE_PROJECT_NAME");
$instanceName = env("SQL_INSTANCE_NAME");
$scopes = [
"https://www.googleapis.com/auth/sqlservice.admin",
"https://www.googleapis.com/auth/compute",
];
$client->addScope($scopes);
$sql = new Google_Service_SQLAdmin($client);
$sqlAdmin = new Google_Service_SQLAdmin_Settings($client);
$instanceSettings = $sql->instances->get($projectName, $instanceName)->getSettings();
$authNetworks = $instanceSettings->getIpConfiguration();
$newAuthNetwork = new Google_Service_SQLAdmin_AclEntry($client);
$newAuthNetwork->setName("tmp_ip_connection");
$newAuthNetwork->setKind("sql#aclEntry");
$authNetworks->setAuthorizedNetworks($newAuthNetwork);
$ipv4 = file_get_contents('https://api.ipify.org');
$newAuthNetwork->setValue($ipv4);
$ipConfiguration = new Google_Service_SQLAdmin_IpConfiguration($client);
$ipConfiguration->setIpv4Enabled(true);
$ipConfiguration->setAuthorizedNetworks([$newAuthNetwork]);
$instanceSettings->setIpConfiguration($ipConfiguration);
$sql->instances->get($projectName, $instanceName)->setSettings($instanceSettings);
//TODO why it is not working??
print_r($sql->instances->get($projectName, $instanceName)->getSettings()->getIpConfiguration()->getAuthorizedNetworks());
The main thing missing from yours is you never updated the instance after you made the change.
Working example:
$client = new Google_Client();
$client->setAuthConfig('../config/service-account.json');
$client->setApplicationName(env("APP_NAME"));
$projectName = env("GOOGLE_PROJECT_NAME");
$instanceName = env("SQL_INSTANCE_NAME");
$scopes = [
"https://www.googleapis.com/auth/sqlservice.admin",
"https://www.googleapis.com/auth/compute",
];
$client->addScope($scopes);
$sql = new Google_Service_SQLAdmin($client);
$instances = $sql->instances;
$instance = $instances->get('projectId', 'instanceId');
$networks = $instance->getSettings()->getIpConfiguration()->getAuthorizedNetworks();
$values = [];
foreach ($networks as $network) {
$values[$network->getName()] = $network;
}
$values['1.production'] = array_get($values, '1.production', clone head($values));
$external_ip = #file_get_contents('http://ipecho.net/plain');
$values['1.production']->setValue("$external_ip/32");
$values['1.production']->setName('1.production');
$instance->getSettings()->getIpConfiguration()->setAuthorizedNetworks(array_values($values));
$instances->update('projectId', 'instanceId', $instance);
I have looked at some answers on here and tried putting them into action in my script; but it's not working, and I'm not sure why.
I am trying to update a custom field on an already-existing inventory item. Here is what I have so far
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$item = new InventoryItem();
$item->internalId = 72309;
$customFieldList = new CustomFieldList();
$customField = new StringCustomFieldRef();
$customField->value = utf8_encode("12345");
$customField->internalId = 'custitem_testinput';
$customFieldList->customField[] = $customField;
$item->customFieldList = $customFieldList;
$request = new UpdateRequest();
$request->record = $item;
$response = $service->update($request);
?>
I'm trying to pull the item record up by its internalID, and then update just 1 of its many custom fields.
This code doesn't error out, but it doesn't seem to do anything either. Looking at the var_dump of the objects, I can see an item object with just the parameters I've set populated, and everything else null.
What am I doing wrong?
This is a basic example showing how to update custom field in an existing record using PHP toolkit.
<?php
require_once 'PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$ItemId = '72309';
$ItemRecord= new InventoryItem();
//StringCustomFieldRef
$itemField= new StringCustomFieldRef();
$itemField->scriptId = 'custitem_part_lookup';
$itemField->value = 'test';
$customFieldList = new customFieldList();
$customFieldList->customField = array($itemField);
$ItemRecord->internalId = $ItemId ;
$ItemRecord->customFieldList = $customFieldList;
$updateRequest = new UpdateRequest();
$updateRequest->record = $ItemRecord;
$updateResponse = $service->update($updateRequest);
?>
For additional information you can visit Net Suite User Group
i am trying to send a bunch of events via an Batch Request to Google Calendar.
But i cant figur out how to do. https://developers.google.com/google-apps/calendar/batch doesnt help me.
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_CalendarService.php';
$client = new Google_Client();
$client->setUseBatch(true);
$batch = new Google_BatchRequest();
$uri = 'http://www.google.com/calendar/feeds/default/private/full/batch';
$batchContent = file_get_contents('xxxxx/google-api-php-client/batch.xml');
$batch->add($batchContent);
batch.xml contains 2 -items.
Thats all so far. But nothing happened.
I also have tried
$batch->execute()
But thats throws error without message.
My question: How to send a Batch via PHP to Google Calendar ?
I'm using the latest version of Google APIs Client Library for PHP (Google Calendar v.3). I use batch operations for pushing instructor lessons to Google Calendar. Here is my example of code for you (multipleInsert function). Good luck!
<?php
require_once(APPPATH . 'libraries/Google/Client.php');
require_once(APPPATH . 'libraries/Google/Http/Batch.php');
require_once(APPPATH . 'libraries/Google/Service/Calendar.php');
class My_google_calendar
{
...
/** Add single Event for Student */
function addEvent($lesson, $instructor, $return_request = false, $enable_attendees = false)
{
$calendar = $this->getGoogleCalendar(); // get calendar service variable
$lesson_from = date(DATE_RFC3339, $lesson->from);
$lesson_to = date(DATE_RFC3339, $lesson->from + $lesson->duration);
$event = new Google_Service_Calendar_Event();
$event->setSummary('Lesson with student: '$lesson->student_full_name);
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime($lesson_from);
$start->setTimeZone($this->getGoogleCalendarTimeZone());
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime($lesson_to);
$end->setTimeZone($this->getGoogleCalendarTimeZone());
$event->setEnd($end);
$event->setColorId(4);
$description = "...";
$event->setDescription($description);
if (isset($student->email) && $enable_attendees) {
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setResponseStatus('needsAction');
$attendee1->setEmail($student->email);
$attendees = array($attendee1);
$event->setAttendees($attendees);
}
$createdEvent = $this->calendar->events->insert($this->calendar_id, $event, array('fields' => 'id'));
return $return_request ? $createdEvent : $createdEvent->getId();
}
/** Push group of events to the Calendar */
function multipleInsert ($lessons, $instructor)
{
$this->use_batch = true;
$this->client->setUseBatch($this->use_batch);
$batch = new Google_Http_Batch($this->client);
$optParams = array('fields' => 'status,updates');
foreach($lessons as $time => $lesson) {
$lesson = array_shift($group['lessons']);
$req = $this->addEvent($lesson, $instructor, true);
$batch->add($req, $time);
}
}
$results = $batch->execute();
return $results;
}
}
in the newer versions, you should use
$batch = $service->createBatch();
instead of
$batch = new Google_Http_Batch($this->client);
reference
I am using https://github.com/jamesiarmes/php-ews for connecting php to exchange server so far no problem using the code below . i can connect to specific user mail box and can retrieve all his calender events . right now its pulling all the events what i want is to pull only those calendar events which has lets say 'Student Appt.' in Subject line.Is it possible . ?
require_once('bug/dBug.php');
require_once('EWSType.php');
require_once('ExchangeWebServices.php');
require_once('NTLMSoapClient.php');
require_once('NTLMSoapClient/Exchange.php');
require_once('EWS_Exception.php');
require_once('EWSType/FindItemType.php');
require_once('EWSType/ItemQueryTraversalType.php');
require_once('EWSType/ItemResponseShapeType.php');
require_once('EWSType/DefaultShapeNamesType.php');
require_once('EWSType/CalendarViewType.php');
require_once('EWSType/NonEmptyArrayOfBaseFolderIdsType.php');
require_once('EWSType/DistinguishedFolderIdType.php');
require_once('EWSType/DistinguishedFolderIdNameType.php');
require_once('EWSType/EmailAddressType.php');
require_once('EWSType/UserIdType.php');
require_once('EWSType/CalendarEventDetails.php');
$host = 'xxx';
$username = 'xxx';
$password = 'xxx';
$version = 'Exchange2010';
$start = " 2013-04-17T15:18:34+03:00";
$end = " 2013-04-30T15:18:34+03:00";
$ews = new ExchangeWebServices($host, $username, $password, $version);
//new dBug ($ews);
// Set init class
$request = new EWSType_FindItemType();
// Use this to search only the items in the parent directory in question or use ::SOFT_DELETED
// to identify "soft deleted" items, i.e. not visible and not in the trash can.
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
// This identifies the set of properties to return in an item or folder response
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;
// Define the timeframe to load calendar items
$request->CalendarView = new EWSType_CalendarViewType();
$request->CalendarView->StartDate = $start ;// an ISO8601 date e.g. 2012-06-12T15:18:34+03:00
$request->CalendarView->EndDate = $end ; // an ISO8601 date later than the above
// Only look in the "calendars folder"
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
// if you want to get to someones folder
while($info = mysql_fetch_array( $call_pri_result )){
$EmailAddy = 'abc#exchangeserver.com';
$mailBox = new EWSType_EmailAddressType();
$mailBox->EmailAddress = $EmailAddy;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox = $mailBox;
echo 'Now Looping for Consular ID '.$EmailAddy.'<br>' ;
// Send request
$response = $ews->FindItem($request);
// Loop through each item if event(s) were found in the timeframe specified
if ($response->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView > 0){
$events = $response->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
foreach ($events as $event){
$id = $event->ItemId->Id;
$change_key = $event->ItemId->ChangeKey;
$start = $event->Start;
$end = $event->End;
$subject = $event->Subject;
//$location = $event->Location;
}
}
else {
// No items returned
}
}
From my digging you cannot add restrictions or sort order to a CalendarView. I added the code found here to my code to get calendar items and I got the following MessageText:
Restrictions and sort order may not be specified for a CalendarView.
It looks like the full list of FieldURI variables is listed at this MSDN page.
What I would do in your case is put a regular expression, strpos() or similar in your foreach() loop of events. Then if that case matches perform your function. Yes you will have extra events that you will do nothing with but you will at least be able to filter out your desired events.
I am trying to search for a customer by email. The Netsuite api documentation does not help much. Appreciate any help i can get. Thank You.
global $myNSclient;
$email = "myemail";
$item = new nsComplexObject('SearchStringField');
$item->setFields(array( 'searchValue' => $email, 'operator' => 'is'));
$search = new nsComplexObject('ContactSearchBasic');
$search->setFields($item);
$myNSclient->setSearchPreferences(false, 10);
$searchResponse = $myNSclient->search($search);
I got quite a few gray hairs trying to figure this out myself.
Below is the code to get a contact (different than a customer in Netsuite, both are native data types though) from their email. It will be very similar for a Customer.
$service = new NetSuiteService();
$service->setSearchPreferences(false, 20);
$recordRef = new RecordRef();
$recordRef->internalId = '-6'; //Internal ID for a customer is -2, contact is -6
$contactSearch = new ContactSearch(); //use CustomerSearch() for a customer
$contactSearchBasic = new ContactSearchBasic();//SearchRecordBasic
$contactSearchBasic->email = new SearchStringField();
$contactSearchBasic->email->searchValue = 'someone#somewhere.com';
$contactSearchBasic->email->operator = SearchStringFieldOperator::is;
$contactSearch->basic = $contactSearchBasic;
$searchRequest = new searchRequest(); //% contains a searchRecord
$searchRequest->searchRecord = $contactSearch;
$searchResponse = $service->search($searchRequest);