work in progress - email subscription

This commit is contained in:
systopia 2015-03-19 09:29:54 +01:00
parent be1a118ec7
commit c86213dcc9
3 changed files with 154 additions and 12 deletions

View File

@ -7,8 +7,7 @@
| http://www.systopia.de/ | | http://www.systopia.de/ |
+---------------------------------------------------------*/ +---------------------------------------------------------*/
require_once "config.php"; require "proxy.php";
require_once "proxy.php";
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
@ -116,7 +115,7 @@ require_once "proxy.php";
<body> <body>
<div id="container"> <div id="container">
<div id="info" class="center-small"> <div id="info" class="center-small">
<a href="https://www.systopia.de/"><img src="static/images/proxy-logo.png" alt="SYSTOPIA Organisationsberatung"></img></a> <a href="https://www.systopia.de/"><?php echo $civiproxy_logo;?></a>
<p id="version">CiviProxy Version <?php echo $civiproxy_version;?></p> <p id="version">CiviProxy Version <?php echo $civiproxy_version;?></p>
</div> </div>
<div id="error-container" class="center"> <div id="error-container" class="center">

View File

@ -7,15 +7,120 @@
| http://www.systopia.de/ | | http://www.systopia.de/ |
+---------------------------------------------------------*/ +---------------------------------------------------------*/
require_once "../config.php"; require "../proxy.php";
require_once "../proxy.php";
// see if mail open tracking is enabled // see if mailing subscribe feature is enabled
if (!$target_mail_base) civiproxy_http_error("Feature disabled", 405); if (empty($mail_subscription_user_key)) civiproxy_http_error("Feature disabled", 405);
// basic check // get the groups you could subscribe to
civiproxy_security_check('mail-subscribe'); $group_query = civicrm_api3('Group', 'get', array( 'visibility' => 'Public Pages',
'is_hidden' => 0,
'is_active' => 1,
'api_key' => $mail_subscription_user_key,
));
// just forward, no parameters if (!empty($group_query['is_error'])) {
civiproxy_redirect($target_mail_base . '/subscribe', array()); civiproxy_http_error($group_query['error_message'], 500);
} else {
$groups = $group_query['values'];
}
error_log(print_r($groups,1));
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CiviProxy Version <?php echo $civiproxy_version;?></title>
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
<style type="text/css">
body {
margin: 0;
padding: 0;
}
.container {
position: relative;
width: 100%;
}
.center {
margin-left: auto;
margin-right: auto;
width: 970px;
}
p {
font-family: "Open Sans", sans-serif;
font-size: 160%;
}
#info {
padding-top: 20px;
vertical-align: top;
text-align: center;
width: 462px;
}
</style>
</head>
<body>
<div id="container">
<div id="info" class="center">
<a href="https://www.systopia.de/"><?php echo $civiproxy_logo;?></a>
<p id="version">Subscribe to Newsletters</p>
</div>
<div id="content" class="center">
<?php
/*********************************************
** main processing routine **
********************************************/
$parameter_errors = array();
if (!empty($_REQUEST['email'])) {
// get parameters
$email = $_REQUEST['email'];
$group_ids = array();
foreach ($_REQUEST as $key => $value) {
error_log(substr($key, 0, 6));
if (substr($key, 0, 6) == 'group_') {
$group_ids[] = $value;
}
}
// TODO: verify email is valid, otherwise set $parameter_errors['email']
// TODO: verify at least one group is selected, otherwise set $parameter_errors['group_id']
}
if (empty($_REQUEST['email']) || !empty($parameter_errors)) {
// TODO: if
print "
<form id='subscribe' method='POST'>
<label for='email'>Your email Address:</label>
<input type='text' name='email'></input>
<h3>Select the newsletter you would like to subscribe to:</h3>
<ul>
";
foreach ($groups as $group_id => $group) {
print "
<li>
<input type='checkbox' name='group_{$group_id}' value='{$group_id}'>{$group['name']}</input>
<p>{$group['description']}</p>
</li>";
}
print "
</ul>
</form>";
} else {
print_r($_REQUEST);
}
?>
</div>
</div>
</body>
</html>

View File

@ -7,8 +7,9 @@
| http://www.systopia.de/ | | http://www.systopia.de/ |
+---------------------------------------------------------*/ +---------------------------------------------------------*/
require "config.php";
$civiproxy_version = '0.3'; $civiproxy_version = '0.3';
require_once "config.php"; $civiproxy_logo = "<img src='{$proxy_base}/static/images/proxy-logo.png' alt='SYSTOPIA Organisationsberatung'></img>";
/** /**
* this will redirect the request to another URL, * this will redirect the request to another URL,
@ -204,3 +205,40 @@ function civiproxy_http_error($message, $code = 404) {
exit(); exit();
} }
/**
* call the CiviCRM REST API via CURL
*/
function civicrm_api3($entity, $action, $data) {
global $target_rest, $sys_key_map;
// extract site key
$site_keys = array_values($sys_key_map);
if (empty($site_keys)) civiproxy_http_error('No site key set.');
$query = $data; // array copy(!)
$query['key'] = $site_keys[0];
$query['json'] = 1;
$query['version'] = 3;
$query['entity'] = $entity;
$query['action'] = $action;
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $query);
curl_setopt($curl, CURLOPT_URL, $target_rest);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
$response = curl_exec($curl);
if (curl_error($curl)){
civiproxy_http_error(curl_error($curl));
} else {
return json_decode($response, true);
}
}