Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]Creating an event in Google Calendar stopped working
#1

[eluser]Cgull[/eluser]
Hello,

I am developing a site with ci 2.1.4

I used this tutorial to create an event in google calendar:
Tutorial

When I change a date on the view, it calls the controller function with ajax, used to work fine, now the page just hangs and I can't figure out what is going on.

My controller function (Calling create_event from the zend_helper):
Code:
public function set_paid()
{
  $this->load->helper('zend');
  $this->load->helper('date');
  $this->load->helper('send_email');
  $this->load->model('auth/user_m');
  $this->load->model('auth/user_addr_m');
  $this->load->model('order_dets_m');
  $this->load->model('delivery_types_m');
  
  $orderId = $this->input->post('id');
  $order = $this->order_m->get($orderId);
  $postageTypeId = $order->postage_type;
  $postageType = $this->delivery_types_m->get($postageTypeId);
  $postageType = $postageType->title;
  $userId = $order->user_id;
  $user = $this->user_m->get($userId);
  $addr = $this->user_addr_m->get_postal_addr($userId);
    
  $firstName = $user->first_name;
  $lastName = $user->last_name;
  
  $dets = $this->order_dets_m->get_open_order($orderId);
  
  $title = $firstName . ' ' . $lastName . ' - order has been paid.';
  $where = 'Clarens';
  
  $content = "Order Details:\n";
  foreach($dets as $item)
  {
   $qty = $item['qty'];
   $coffee = $item['coffee'];
   $weight = $item['weight'];
   $content .= "Qty: $qty\nCoffee: $coffee\nWeight: $weight\n\n";
  }
  
  $content .= "Postage type: $postageType\n\n";
  $content .= "\nPostal Address:\n";
  
  foreach($addr as $item)
  {
   $addrLine1 = $item->addr_line_1;
   $addrLine2 = $item->addr_line_2;
   $suburb = $item->suburb;
   $city = $item->city;
   $postCode = $item->post_code;
   $province = $item->province;
  
   $content .= "$addrLine1\n";
   if($addrLine2)
    $content .= "$addrLine2\n";
   $content .= "$suburb\n$city $postCode\n$province";
  }

  create_event($title, $where, $content);

  $save['paid'] = 1;
  $paidDate = $this->input->post('paid_date');
  $paidDate = mdate('%Y-%m-%d', strtotime($paidDate));
  $save['paid_date'] = $paidDate;
  $this->order_m->save($save, $orderId);

  $subject = 'Your payment for you order with Highland Coffee Roastery has been recieved.';
      
  $body = 'email/payment';
    
  $emailToName = $user->first_name . ' ' . $user->last_name;

  $data['user'] = $user;

  $emailSent = sendEmail($this->config->item('site_email'), 'Highland Coffee Roastery', '[email protected]', 'NoReply', $data['user']->email, $emailToName, $subject, $body, $data, '', $this->config->item('site_email'));
  
  echo 'The order has been updated and scheduled on google. An email has been sent to the user.';
}

My zend helper:
Code:
<?php
//Changed this today, copied the Zend folder to application/libraries
/*if(ENVIRONMENT != 'production')
{
ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.str_replace("/", "\\", BASEPATH)."contrib\\");
require_once ('Zend/Loader.php');
}
else
{
ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.BASEPATH."/contrib/");
require_once 'Zend/Loader.php';
}*/
require_once (APPPATH . 'libraries/Zend/Loader.php');

function create_event($title, $where, $content)
{
Zend_Loader::loadClass('Zend_Gdata_Calendar');
  Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
  // Parameters for ClientAuth authentication

$user = "user";
$pass = "pass";
  
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$service = new Zend_Gdata_Calendar($client);

// Create a new entry using the calendar service's magic factory method
$event= $service->newEventEntry();
  
// Populate the event with the desired information
// Note that each attribute is crated as an instance of a matching class
$event->title = $service->newTitle($title);
$event->where = array($service->newWhere($where));
$event->content = $service->newContent($content);
  
// Set the date using RFC 3339 format.
$date = new DateTime('NOW');
$duration = new DateInterval('PT15M');

$calendar_date = $date->format('Y-m-d');
$date->add($duration);
$startTime = $date->format('H:i');

$endDate = $date;
$endDate->add($duration);
$endTime = $endDate->format('H:i');

$tzOffset = "+02";

$when = $service->newWhen();

$when->startTime = "{$calendar_date}T{$startTime}:00.000{$tzOffset}:00";
$when->endTime = "{$calendar_date}T{$endTime}:00.000{$tzOffset}:00";
$reminder = $service->newReminder();
$reminder->method = "sms";
$reminder->minutes = "5";
  
// Apply the reminder to an existing event's when property
$when->reminders = array($reminder);
$event->when = array($when);
  
// Upload the event to the calendar server
// A copy of the event as it is recorded on the server is returned
$newEvent = $service->insertEvent($event);
}

I have the zend installed in two places now:
application/libraries/zend
system/contrib/zend

Do I have to use Zend to connect to google? I searched google but can't find a solution.

I also found this spark: Spark but it uses ZF2 and I have no clue what to do with it. Also installing sparks and getting the loader to work with HMVC broke the whole site.

Can someone please help me? I don't get any errors in firebug, I can't understand what is going on.
#2

[eluser]Cgull[/eluser]
Ok, found the problem, it was the csrf.

I added my function in the config file:
`$config['csrf_exclude_uris'] = array('cart/admin/orders/set_paid');`

And everything is back to normal.




Theme © iAndrew 2016 - Forum software by © MyBB