1 Attachment(s)
July 2014 Canada Anti-Spam Legislation (CASL) Twitch CASL
Twitch CASL - This is the first step towards compliance for the new CASL anti spam law in Canada. (Takes effect July 1st, 2014)
Tested and working with Zen 1.39h and 1.51.
Add to Database:
Table - cust_casl
Columns - cust_casl_id, date_checked, casl_purpose, ip_address
Attachment 14126
When a customer creates a new account...
Add to includes/modules/YOUR_TEMPLATE/create_account.php
PHP Code:
// bof Twitch CASL only record if they checked the box
if ($newsletter == '1') {
$sql = "insert into " . TABLE_CUST_CASL . "
(cust_casl_id, date_checked, casl_purpose, ip_address)
values ('" . (int)$_SESSION['customer_id'] . "', now(), 'Yes, I would like to receive emails from YOUR_COMPANY_HERE regarding upcoming promotions', '". $_SERVER['REMOTE_ADDR'] . "')";
$db->Execute($sql);
}
// eof Twitch CASL
(replace YOUR_COMPANY_HERE with your company name)
When a customer changes their newsletter settings via account_edit...
Add to includes/modules/pages/account_newsletters/header_php.php
PHP Code:
// bof Twitch CASL only record if they checked the box
//
// load cust_id from casl if exists
$casl_query = "SELECT cust_casl_id
FROM " . TABLE_CUST_CASL . "
WHERE cust_casl_id = '" . (int)$_SESSION['customer_id'] . "' ";
$casl_check = $db->Execute($casl_query);
if ($casl_check == '') { // no record found for this customer
if ($newsletter_general == '1') { // add the casl record ONLY if they checked the box
$sql = "insert into " . TABLE_CUST_CASL . "
(cust_casl_id, date_checked, casl_purpose, ip_address)
values ('" . (int)$_SESSION['customer_id'] . "', now(), 'Yes, I would like to receive emails from YOUR_COMPANY_HERE regarding upcoming promotions', '". $_SERVER['REMOTE_ADDR'] . "')";
$db->Execute($sql);
} // end checked box - insert new
} else { // if casl customer record already exists, update the date_checked and ip_address ONLY if the box is checked
if ($newsletter_general == '1') { // add the casl record ONLY if they checked the box
$sql = "update " . TABLE_CUST_CASL . "
set date_checked = now(), ip_address = '". $_SERVER['REMOTE_ADDR'] . "'
where cust_casl_id = '" . (int)$_SESSION['customer_id'] . "' ";
$db->Execute($sql);
} // end checked box update
} // end CASL check
//
// eof Twitch CASL only record if they checked the box
(replace YOUR_COMPANY_HERE with your company name)
Re: NEW - Government of Canada Anti-Spam Legislation (CASL) Twitch CASL
Understanding how this code works:
New Customer - When a new customer signs up and does not click the newsletter checkbox, nothing happens. When they check the box the customer_id, date and time, static text displayed that they are agreeing to, ip address are recorded in the CUST_CASL table.
Existing Customer - When an existing customer logs into their account, goes to 'My Account' and selects 'Subscribe or unsubscribe from newsletter' they land on a page with a checkbox showing their previous newsletter setting.
Scenario A - The newsletter box was never checked
-> All of the required fields will be added to the CUST_CASL table if they check the box.
Scenario B - The newsletter box was previously checked - remains checked - and they click update
-> The current date and time, current ip address will be updated in the existing customer field.
Note: If they previously did check the newsletter box, then they uncheck the box, the CASL records will remain intact. This ensures that any customer complaints can be traced back to a date, time and ip address for legal means.
As always, backup your site before making changes, read and follow the regulations provided by the Government of Canada related to CASL compliance for your own business, donations are appreciated :)
Re: 2014 Government of Canada Anti-Spam Legislation (CASL) Twitch CASL
To display the database records for those that have checked the newsletter box located at:
Admin -> Customers -> Select Customer -> Click Edit
In 'Options - Send me Discounts and Deals through email.' below the newsletter dropdown in admin/customers.php
Look for:
PHP Code:
<td class="main"><?php echo ENTRY_NEWSLETTER; ?></td>
<td class="main">
<?php
if ($processed == true) {
if ($cInfo->customers_newsletter == '1') {
echo ENTRY_NEWSLETTER_YES;
} else {
echo ENTRY_NEWSLETTER_NO;
}
echo zen_draw_hidden_field('customers_newsletter');
} else {
echo zen_draw_pull_down_menu('customers_newsletter', $newsletter_array, (($cInfo->customers_newsletter == '1') ? '1' : '0'));
}
?></td>
Add this code after the trailing </td>:
PHP Code:
<?php // bof Twitch CASL ?>
<tr> <td> </td>
<td>
<?php
// Display db records in admin
$casl_query = "SELECT *
FROM " . TABLE_CUST_CASL . "
WHERE cust_casl_id = '" . (int)$customers_id . "' ";
$casl_check = $db->Execute($casl_query);
if ($casl_check->fields['cust_casl_id'] == (int)$customers_id ) {
// output the db record
echo '<strong>Customer ID: </strong>' . $casl_check->fields['cust_casl_id'] . ' ' ;
echo '<strong>Date Last Checked: </strong>' . $casl_check->fields['date_checked'] . ' ' ;
echo '<strong>Agreement: </strong>' . $casl_check->fields['casl_purpose'] . ' ' ;
echo '<strong>Location: </strong>' . $casl_check->fields['ip_address'] . ' ' ;
} else {
// No record found meaning the customer has not checked the newsletter box
echo 'No CASL record found. Customer has not checked newsletter subscribe box.';
}
?>
</td>
<td> </td>
</tr>
<?php // eof Twitch CASL ?>
Re: 2014 Government of Canada Anti-Spam Legislation (CASL) Twitch CASL
Hi, I tried to do all of these steps for 1.51 and it's not working. After I made the DB changes by adding a new table with the 4 columns, I added the code lines in those files. The result is that I've got an error message every time when I make (confirm) a new account and also when I try to update the mail newsletter settings for an existing account. Can you be more specific where in those two files (create_account.php and header_php.php) should I add the code lines? Please help, first of July is coming.
Re: 2014 Government of Canada Anti-Spam Legislation (CASL) Twitch CASL
Is there other place where I need to modify the code or there are some hidden settings to do before?
Re: 2014 Government of Canada Anti-Spam Legislation (CASL) Twitch CASL
Quote:
Originally Posted by
verzea
Hi, I tried to do all of these steps for 1.51 and it's not working. After I made the DB changes by adding a new table with the 4 columns, I added the code lines in those files. The result is that I've got an error message every time when I make (confirm) a new account and also when I try to update the mail newsletter settings for an existing account. Can you be more specific where in those two files (create_account.php and header_php.php) should I add the code lines? Please help, first of July is coming.
In includes/modules/YOUR_TEMPLATE/create_account.php after the following code:
PHP Code:
$sql = "insert into " . TABLE_CUSTOMERS_INFO . "
(customers_info_id, customers_info_number_of_logons,
customers_info_date_account_created, customers_info_date_of_last_logon)
values ('" . (int)$_SESSION['customer_id'] . "', '1', now(), now())";
$db->Execute($sql);
(around line 319) you can add the Twitch CASL code.
In includes/modules/pages/account_newsletters/header_php.php after the following code:
PHP Code:
$sql = "UPDATE " . TABLE_CUSTOMERS . "
SET customers_newsletter = :customersNewsletter
WHERE customers_id = :customersID";
$sql = $db->bindVars($sql, ':customersID',$_SESSION['customer_id'], 'integer');
$sql = $db->bindVars($sql, ':customersNewsletter',$newsletter_general, 'integer');
$db->Execute($sql);
}
(around line 43) you can add the Twitch CASL code.
Re: 2014 Government of Canada Anti-Spam Legislation (CASL) Twitch CASL
Quote:
Originally Posted by
verzea
Is there other place where I need to modify the code or there are some hidden settings to do before?
There are no hidden settings. The database tables must be set exactly as listed in the original post #1. Next the Twitch CASL code needs to be cut and paste into the various php files in the locations posted in post #3 and #6.
If you are still having errors, it's best to contact me directly via email, or to this thread - with a copy of the error message or the most recent error listed in your /logs folder.
Or if you'd like I can check it for you, make email contact with me first then we'll share usernames and passwords for admin/FTP.
Re: 2014 Government of Canada Anti-Spam Legislation (CASL) Twitch CASL
The message is: WARNING: An Error occurred, please refresh the page and try again.
-the DB table looks identical
-the code is placed on the right place
-when I create a new account as a Canadian, once I checked the Newsletter and hit created I received this error
-if I log in with a different account (Canadian as well) and check My Account / Newsletter Subscription (which is already "on") and hit Update button, again, the error message
Thanks in advance :)
(it looks that nothing is written on the DB for the table zen_cust_casl)
Re: 2014 Government of Canada Anti-Spam Legislation (CASL) Twitch CASL
Quote:
Originally Posted by
verzea
The message is: WARNING: An Error occurred, please refresh the page and try again.
-the DB table looks identical
-the code is placed on the right place
-when I create a new account as a Canadian, once I checked the Newsletter and hit created I received this error
-if I log in with a different account (Canadian as well) and check My Account / Newsletter Subscription (which is already "on") and hit Update button, again, the error message
Thanks in advance :)
(it looks that nothing is written on the DB for the table zen_cust_casl)
Check your PM, I need access to trace this problem.
Re: 2014 Government of Canada Anti-Spam Legislation (CASL) Twitch CASL
verzea,
Did you define the new table in database_tables.php?
If not, add the following line at the end of file:
define('TABLE_CUST_CASL', DB_PREFIX . 'cust_casl');