Is there a syntax error in this iCalendar event code? - syntax-error

I have a 'Subscribed Calendar' on my iPhone which fetches calendar events in the iCalendar format from a URL. The calendar works fine except it does not show the following event, is there a reason why? All other events show fine. I'm thinking there's maybe a problem with the way the event is formatted/syntax but I can't seem to find anything that may be causing it.
BEGIN:VEVENT SUMMARY:Meet with tenant DESCRIPTION:Notes: Meter readings\, SoC images\, post box key\, finalise Let Procedure.\nLocation: Apartment X X Woodland Road\, Bebington\, Wirral\, CHXX XXX\nEmployee: Michael Le Brocq\nStatus: Confirmed\nOriginally Arranged: 07/09/16 12:18:43 by Lucy Christian\nLast Updated: 12/09/16 15:57:05 by Michael Le Brocq\n UID:2432 STATUS:CONFIRMED DTSTART:20160914T160000 DTEND:20160914T151500 LAST-MODIFIED:20160912T155705 LOCATION:Apartment 5 20 Woodland Road\, Bebington\, Wirral\, CH42 4NT END:VEVENT
Code used to generate calendar events;
<?php
require_once('../inc/app_top_cron.php');
if (!empty($_GET)) {
// define and escape each GET as a variable
foreach ($_GET as $key => $value) {
if (!empty($value)) {
${$key} = mysqli_real_escape_string($con, PrepareInput($value));
}
}
}
// company details
$company_details_query = mysqli_query($con, "SELECT company_id, company_trading_name FROM company WHERE company_token = '" . $company . "' LIMIT 1") or die(mysql_error());
$company_details = mysqli_fetch_array( $company_details_query );
// the iCal date format. Note the Z on the end indicates a UTC timestamp.
define('DATE_ICAL', 'Ymd\THis');
// max line length is 75 chars. New line is \\r\n
$output = "BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//Property Software//Calendar//EN
CALSCALE:GREGORIAN
X-WR-CALNAME:" . $company_details['company_trading_name'] . " Calendar" . "
\r\n";
$sql = "SELECT ce.*, ces.calendar_event_status_name
FROM calendar_event ce
INNER JOIN calendar_event_status ces
on ce.calendar_event_status = ces.calendar_event_status_id
WHERE ce.calendar_event_company_id = '" . $company_details['company_id'] . "'";
$calendar_event_query = mysqli_query($con, $sql) or die(mysql_error());
while($row = mysqli_fetch_array( $calendar_event_query )) {
$calendar_event_subject = str_replace(",","\,", $row['calendar_event_subject']);
$calendar_event_description = str_replace(",","\,", $row['calendar_event_description']);
$calendar_event_description = str_replace("\r\n","\\n", $calendar_event_description);
$calendar_event_location = str_replace(",","\,", $row['calendar_event_location']);
// loop through events
$output .=
"BEGIN:VEVENT
SUMMARY:" . $calendar_event_subject . "
DESCRIPTION:" . $calendar_event_description . "
UID:" . $row["calendar_event_id"] . "
STATUS:" . $row["calendar_event_status_name"] . "
DTSTART:" . date(DATE_ICAL, strtotime($row["calendar_event_start"])) . "
DTEND:" . date(DATE_ICAL, strtotime($row["calendar_event_end"])) . "
LAST-MODIFIED:" . date(DATE_ICAL, strtotime($row["calendar_event_date_updated"])) . "
LOCATION:" . $calendar_event_location . "
END:VEVENT
";
}
// close calendar
$output .= "END:VCALENDAR";
echo $output;
mysqli_close($con);
?>

This:
$calendar_event_description = str_replace("\r\n","\\n", $calendar_event_description);
You're taking \r\n (carriage return + newline) and turning them into a literal \ character, followed by an n. That's not a new line (one byte/character), it's TWO bytes/characters, and has no special meaning to anything.
And as per my comments above, don't do multiline string building/concatenating. it makes for hard-to-read and hard-to-follow debugging. Use a heredoc instead:
$output = <<<EOL
BEGIN:VEVENT
SUMMARY: {$calendar_event_subject}
DESCRIPTION: {$calendar_event_description}
UID: {$row["calendar_event_id"]}
etc...
EOL;
Note the lack of any " or . - making for a much more compact and easy-to-follow code block. If you need to change the line breaks afterwards, because your system uses something different than what your code editor is embedding, you can do that with a simple str_replace() after finishing building the string.

The icalendar standard requires \r\n line breaks between lines. You can validate the icalendar output using the validator at http://icalendar.org/validator.html

Related

Moneris Recurring Payment Gateway on Laravel 5.4

I have gone through the Moneris documentation, they have given straightforward API. I am trying to do recurring payment but not able to understand how to get DataKeys of previously made transition of the particular customer. Here what I have written for the purchase in which DateKey is used as a static from the demo Moneris Payment documentation. But I am not able to get my client data_key, how can we get that dataKey please help me out! If this code is not good let me know the better solution.
/************************ Transaction Variables ******************************/
$data_key='FjhVlt4020HAVSaOmnaaPACpJ';
$orderid='ord-'.date("dmy-G:i:s");
$amount='1.00';
$custid='test';
$crypt_type='1';
$commcard_invoice='Invoice 123';
$commcard_tax_amount='1.00';
/************************** CVD Variables *****************************/
$cvd_indicator = '1';
$cvd_value = '198';
/********************** CVD Associative Array *************************/
$cvdTemplate = array(
'cvd_indicator' => $cvd_indicator,
'cvd_value' => $cvd_value
);
$mpgCvdInfo = new mpgCvdInfo ($cvdTemplate);
/************************** Recur Variables *****************************/
$recurUnit = 'day';
$startDate = '2018/04/09';
$numRecurs = '4';
$recurInterval = '10';
$recurAmount = '09.00';
$startNow = 'true';
/****************************** Recur Array **************************/
$recurArray = array('recur_unit'=>$recurUnit, // (day | week | month)
'start_date'=>$startDate, //yyyy/mm/dd
'num_recurs'=>$numRecurs,
'start_now'=>$startNow,
'period' => $recurInterval,
'recur_amount'=> $recurAmount
);
$mpgRecur = new mpgRecur($recurArray);
/************************ Transaction Array **********************************/
$txnArray=array('type'=>'res_purchase_cc',
'data_key'=>$data_key,
'order_id'=>$orderid,
'cust_id'=>$custid,
'amount'=>$amount,
'crypt_type'=>$crypt_type,
'commcard_invoice'=>$commcard_invoice,
'commcard_tax_amount'=>$commcard_tax_amount
);
/************************ Transaction Object *******************************/
$mpgTxn = new mpgTransaction($txnArray);
$mpgTxn->setCvdInfo($mpgCvdInfo);
$mpgTxn->setRecur($mpgRecur);
/************************ Request Object **********************************/
$mpgRequest = new mpgRequest($mpgTxn);
$mpgRequest->setProcCountryCode("US"); //"CA" for sending transaction to Canadian environment
$mpgRequest->setTestMode(true); //false or comment out this line for production transactions
/************************ mpgHttpsPost Object ******************************/
$mpgHttpPost =new mpgHttpsPost($store_id,$api_token,$mpgRequest);
/************************ Response Object **********************************/
$mpgResponse=$mpgHttpPost->getMpgResponse();
// print_r($mpgResponse);
print("\nDataKey = " . $mpgResponse->getDataKey());
print("\nReceiptId = " . $mpgResponse->getReceiptId());
print("\nReferenceNum = " . $mpgResponse->getReferenceNum());
print("\nResponseCode = " . $mpgResponse->getResponseCode());
print("\nAuthCode = " . $mpgResponse->getAuthCode());
print("\nMessage = " . $mpgResponse->getMessage());
print("\nTransDate = " . $mpgResponse->getTransDate());
print("\nTransTime = " . $mpgResponse->getTransTime());
print("\nTransType = " . $mpgResponse->getTransType());
print("\nComplete = " . $mpgResponse->getComplete());
print("\nTransAmount = " . $mpgResponse->getTransAmount());
print("\nCardType = " . $mpgResponse->getCardType());
print("\nTxnNumber = " . $mpgResponse->getTxnNumber());
print("\nTimedOut = " . $mpgResponse->getTimedOut());
print("\nAVSResponse = " . $mpgResponse->getAvsResultCode());
print("\nRecurSuccess = " . $mpgResponse->getRecurSuccess());
print("\nResSuccess = " . $mpgResponse->getResSuccess());
print("\nPaymentType = " . $mpgResponse->getPaymentType());
//----------------- ResolveData ------------------------------
print("\n\nCust ID = " . $mpgResponse->getResDataCustId());
print("\nPhone = " . $mpgResponse->getResDataPhone());
print("\nEmail = " . $mpgResponse->getResDataEmail());
print("\nNote = " . $mpgResponse->getResDataNote());
print("\nMasked Pan = " . $mpgResponse->getResDataMaskedPan());
print("\nExp Date = " . $mpgResponse->getResDataExpDate());
print("\nCrypt Type = " . $mpgResponse->getResDataCryptType());
print("\nAvs Street Number = " . $mpgResponse->getResDataAvsStreetNumber());
print("\nAvs Street Name = " . $mpgResponse->getResDataAvsStreetName());
print("\nAvs Zipcode = " . $mpgResponse->getResDataAvsZipcode());
I have mailed to MINDBODY API support, they responded with the message
"Due to current API limitations, there is not a current option to filter the GetClasses REQUEST by the time. It would currently be necessary to parse the RESPONSE for the desired times."
There is no filter option with time.
Thank you

Behat (+ Mink) Check for some text followed by some text (in sibling elements)

The I should see... function is an essential feature of Behat but I regularly find myself wanting to write something like this in my scenarios:
Then I should see "Session ID" followed by "3"
Which is my humanly-parsable way of describing 2 pieces of text next to each other in the content. That is to say the first string is the content of any element and the second is the content of it's next immediate sibling.
This would be useful for checking label - value type layouts:
Or if I want to check header - cell value type layouts in tabulated data:
Or even definition title - definition.
Obviously I could add 'id' attributes to every element I want to test but in a complicated page where many parts of the content need testing this starts to feel like I am bloating the markup with single-use attributes.
To be able to use...
Then I should see "Session ID" followed by "3"
Add the following methods to your FeatureContext.php file:
/**
* #Then I should see :textA followed by :textB
*/
public function iShouldSeeFollowedBy($textA, $textB)
{
$content = $this->getSession()->getPage()->getContent();
// Get rid of stuff between script tags
$content = $this->removeContentBetweenTags('script', $content);
// ...and stuff between style tags
$content = $this->removeContentBetweenTags('style', $content);
$content = preg_replace('/<[^>]+>/', ' ',$content);
// Replace line breaks and tabs with a single space character
$content = preg_replace('/[\n\r\t]+/', ' ',$content);
$content = preg_replace('/ {2,}/', ' ',$content);
if (strpos($content,$textA) === false) {
throw new Exception(sprintf('"%s" was not found in the page', $textA));
}
$seeking = $textA . ' ' . $textB;
if (strpos($content,$textA . ' ' . $textB) === false) {
// Be helpful by finding the 10 characters that did follow $textA
preg_match('/' . $textA . ' [^ ]+/',$content,$matches);
throw new Exception(sprintf('"%s" was not found, found "%s" instead', $seeking, $matches[0]));
}
}
/**
* #param string $tagName - The name of the tag, eg. 'script', 'style'
* #param string $content
*
* #return string
*/
private function removeContentBetweenTags($tagName,$content)
{
$parts = explode('<' . $tagName, $content);
$keepers = [];
// We always want to keep the first part
$keepers[] = $parts[0];
foreach ($parts as $part) {
$subparts = explode('</' . $tagName . '>', $part);
if (count($subparts) > 1) {
$keepers[] = $subparts[1];
}
}
return implode('', $keepers);
}

yii2 saveAs two files, saves only one

i dont know why, but i have form where i specify two uploads (preview, detail) and when im trying to save them, detail is saved but preview not. Db has results as i expect - saved $slug in column imageSrc and imageDetailSrc
const UPLOAD_FILE_URL = 'uploads/recipes/';
const UPLOAD_FILE_DETAILS_URL = self::UPLOAD_FILE_URL.'details/';
$filePath = self::UPLOAD_FILE_URL . $slug . '.' . $this->imageSrc->extension;
$filePathDetail = self::UPLOAD_FILE_DETAILS_URL . $slug . '.' . $this->imageDetailSrc->extension;
if ($this->imageSrc->saveAs($filePath) && $this->imageDetailSrc->saveAs($filePathDetail)) {
$this->imageSrc = $slug . '.' . $this->imageSrc->extension;
$this->imageDetailSrc = $slug . '.' . $this->imageDetailSrc->extension;
}
if ($this->save(false, ['imageSrc', 'imageDetailSrc'])) {
return true;
}
Yii2 official documentation states that saveAs function uses move_uploaded_file() function to move the temporary file. Hence the temporary file gets deleted when you call saveAs function for the first time. If you do not want saveAs to delete then you should do send false as the second parameter to your saveAs function.
const UPLOAD_FILE_URL = 'uploads/recipes/';
const UPLOAD_FILE_DETAILS_URL = self::UPLOAD_FILE_URL.'details/';
$filePath = self::UPLOAD_FILE_URL . $slug . '.' . $this->imageSrc-
>extension;
$filePathDetail = self::UPLOAD_FILE_DETAILS_URL . $slug . '.' . $this->imageDetailSrc->extension;
if ($this->imageSrc->saveAs($filePath, false) && $this->imageDetailSrc->saveAs($filePathDetail)) {
$this->imageSrc = $slug . '.' . $this->imageSrc->extension;
$this->imageDetailSrc = $slug . '.' . $this->imageDetailSrc->extension;
}
if ($this->save(false, ['imageSrc', 'imageDetailSrc'])) {
return true;
}

The sample of FQL query in FB is incorrect. Someone has a correct sample?

The sample posted in the documentation, at:
http://developers.facebook.com/docs/reference/fql/
is incorrect and does not work. (php)
$fql_query_url = 'https://graph.facebook.com/'
. '/fql?q=SELECT+uid2+FROM+friend+WHERE+uid1=me()'
. '&' . $access_token;
$fql_query_result = file_get_contents($fql_query_url);
=> there are two / : ...facebook.com//fql...
=> the word "&access_token" is missing.
However, even issuing the correct url, the function does not seem to return anything...
Here is the code I have been using:
(function is passed $id, like 12345678)
$Fb = new Facebook(array('appId'=>FB_API_ID,'secret'=>FB_API_SECRET));
$access_token = $Fb->getAccessToken();
$fql_query_url = "https://graph.facebook.com/fql?q=SELECT+uid2+FROM+friend+WHERE+uid1=".$id."&access_token=" . $access_token;
$resp = file_get_contents($fql_query_url);
$var = json_decode($resp, true);
$txt .= "<br /><b>FQL QUERY:</b><br />" . display_tree($var);
Someone made it???
This query seems to work for me when I run it in the browser. Are you sure you have a valid access token?
Can you try it from the Graph API Explorer? Here's the link.

Help creating selective IF statement

I have this code that sends a text message to your mobile phone...
$text = fopen("../data/textmembers/registry.txt","r") or die("couldent open file");
while (!feof($text)) {
$name = fgets($text);
$number = fgets($text);
$carrier = fgets($text);
$date = fgets($text);
$line = fgets($text);
$content = $_POST['message'];
$message .= $content;
$message .= "\n";
$number = trim($number);
mail($number . "#vtext.com", "SGA Event Alert", $message, "SGA");
Header("Location: mailconf.php");
everything works fine.. Here is my question, if you look at where I have "#vtext.com"
as you may or may not know, each carrier has its own extension, verizon is #vtext.com, at&t is #txt.att.net. I need to take the feed from "$carrier" decide what carrier it is, and then assign the extension to it...
I thought an ifelse would work, but I am not good with if statements...
the user's choices are
Verizon = 1234567890#vtext.com
AT&T = 1234567890#txt.att.net
T-mobile = #tmomail.net
Nextel = #messaging.nextel.com
thanks guys!!
$carriers = array(
"verizon" => "vtext.com",
"at&t" => "txt.att.net",
"t-mobile" => "tmomail.net",
"nextel" => "messaging.nextel.com"
);
Then, you get that value by looking up the key:
print $carriers[strtolower($carrier)];
If $carrier is "Nextel," "messaging.nextel.com" will be returned.
Probably better than using an if statement would be using a switch statement.
Have a look at the section of the PHP manual that deals with the switch statement.