// after constructing an eTag and getting a name for it... $fh = fopen('/tmp/PUT.txt', 'w'); foreach ($raw_headers as $k => $v) { fwrite($fh, sprintf("{$k}: %s\n", $v)); } fwrite($fh, "\n"); fwrite($fh, $request->raw_post); fclose($fh); $etag_none_match = str_replace('"', '', $_SERVER["HTTP_IF_NONE_MATCH"]); $etag_match = str_replace('"', '', $_SERVER["HTTP_IF_MATCH"]); $put_path = $_SERVER['PATH_INFO']; list($junk, $user, $ts_id) = preg_split('#/#', $put_path); $ts_id = intval($ts_id); dbg_error_log('PUT', "User: %s, TS_ID: %s", $user, $ts_id); include_once "vEvent.php"; $ev = new vEvent(array('vevent' => $request->raw_post)); /** * Attempt to discover a WR that this is related to */ if (preg_match("/^(wr)?[^1-9]?([1-9][0-9]*)[ \\/-]*(.*)\$/im", $ev->Get("summary"), $matches)) { $request_id = intval($matches[2]); $ev->Put("summary", $matches[3]); } else { $request_id = intval(preg_replace("/^WR#/", "", $ev->Get("location"))); } $delete_dav_event = false; /** * If they didn't send an etag_match header, we need to check if the PUT object already exists * and we are hence updating it. And we just set our etag_match to that. */ $qry = new PgQuery("SELECT * FROM caldav_data WHERE user_no=? AND dav_name=?", $session->user_no, $put_path);
/** * add a SugarEvent to the vCalendar Object * @param SugarEvent $event */ function addEvent($event) { $ev = new vEvent(); $ev->setEvent($event); $this->stack[] = $ev; }
if (isset($report[$i]['end'])) { $where .= "AND work_on <= " . qpg($report[$i]['end']) . "::timestamp with time zone "; } $sql .= $where; $sql .= " ORDER BY work_on ASC"; $responses = array(); $qry = new PgQuery($sql, $report_user_no); // echo $qry->querystring; if ($qry->Exec() && $qry->rows > 0) { while ($ts = $qry->Fetch()) { if ($ts->invoiced != "") { $ts->description .= "\n" . $ts->invoiced; } $response = new XMLElement("response"); $prop = new XMLElement("prop"); $ev = new vEvent(array('uid' => $ts->timesheet_id . "@" . $_SERVER['SERVER_NAME'], 'dtstart' => $ts->dtstart, 'duration' => $ts->duration, 'summary' => $ts->summary, 'location' => $ts->location, 'description' => $ts->description)); if (isset($report[$i]['include_href']) && $report[$i]['include_href'] > 0) { $url = sprintf("http://%s:%d%s/%s/%d.ics", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['SCRIPT_NAME'], $report_user_name, $ts->timesheet_id); $response->NewElement("href", $url); } if (isset($report[$i]['include_data']) && $report[$i]['include_data'] > 0) { $caldata = $ev->Render(); $prop->NewElement("calendar-data", $caldata, array("xmlns" => "urn:ietf:params:xml:ns:caldav")); } if (isset($report[$i]['properties']['GETETAG'])) { $prop->NewElement("getetag", '"' . $ts->dav_etag . '"'); } $status = new XMLElement("status", "HTTP/1.1 200 OK"); $response->NewElement("propstat", array($prop, $status)); $responses[] = $response; dbg_error_log("REPORT", "TS Response: ETag >>%s<< >>%s<<", $ts->dav_etag, $url);
WHERE work_by_id = ? AND timesheet_id = ? EOSQL; $qry = new PgQuery($sql, $get_user_no, $ts_id); if ($qry->Exec("GET") && $qry->rows == 1) { $ts = $qry->Fetch(); header("HTTP/1.1 200 OK"); header("ETag: {$ts->dav_etag}"); if (isset($debug)) { header("Content-Type: text/plain"); } else { header("Content-Type: text/calendar"); } if ($ts->invoiced != "") { $ts->description .= "\n" . $ts->invoiced; } $vevent = new vEvent(array('uid' => $ts_id . "@" . $_SERVER['SERVER_NAME'], 'dtstart' => $ts->dtstart, 'duration' => $ts->duration, 'summary' => $ts->summary, 'location' => $ts->location, 'description' => $ts->description)); print $vevent->Render(); dbg_error_log("GET", "User: %d, ETag: %s, Path: /%s/%d.ics", $get_user_no, $ts->dav_etag, $get_user_name, $ts_id); } else { $qry = new PgQuery("SELECT * FROM caldav_data WHERE user_no = ? AND dav_name = ? ;", $get_user_no, $get_path); dbg_error_log("get", "%s", $qry->querystring); if ($qry->Exec("GET") && $qry->rows == 1) { $event = $qry->Fetch(); header("HTTP/1.1 200 OK"); header("ETag: {$event->dav_etag}"); if (isset($debug)) { header("Content-Type: text/plain"); } else { header("Content-Type: text/calendar"); } print $event->caldav_data;