From d921d8efdf809b53fcf290a89040c67aec15c3ec Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Mon, 7 Jul 2014 17:55:07 +0000 Subject: [PATCH] Notifications: Allow subscribe even if no notification channels enabled (collects demographic data and email), some jQuery goodness. --- app/notifications/app_languages.php | 5 + app/notifications/notification_edit.php | 246 +++++++++++++----------- 2 files changed, 137 insertions(+), 114 deletions(-) diff --git a/app/notifications/app_languages.php b/app/notifications/app_languages.php index b703cf0ee8..bac090db5e 100644 --- a/app/notifications/app_languages.php +++ b/app/notifications/app_languages.php @@ -120,6 +120,11 @@ $text['message-failed']['pt-pt'] = "Falha na atualização - Contato com o suporte"; $text['message-failed']['fr-fr'] = "Mise à jour a échoué - Contacter le support technique"; + $text['message-no_channels']['en-us'] = "No Channels Enabled"; + $text['message-no_channels']['es-cl'] = "No hay canales habilitados"; + $text['message-no_channels']['pt-pt'] = "Não há canais habilitados"; + $text['message-no_channels']['fr-fr'] = "Pas de canaux activés"; + $text['message-invalid_recipient']['en-us'] = "Invalid Notification Recipient"; $text['message-invalid_recipient']['es-cl'] = "Inválido destinatario de la notificación"; $text['message-invalid_recipient']['pt-pt'] = "Inválido Notificação Destinatário"; diff --git a/app/notifications/notification_edit.php b/app/notifications/notification_edit.php index 7a126a9cf8..580748de21 100644 --- a/app/notifications/notification_edit.php +++ b/app/notifications/notification_edit.php @@ -56,7 +56,6 @@ else { } unset($sql, $prep_statement); -// process submitted values if (count($_POST) > 0) { // retrieve submitted values @@ -68,56 +67,63 @@ else { $project_notification_method = check_str($_POST["project_notification_method"]); $project_notification_recipient = check_str($_POST["project_notification_recipient"]); + // get local project notification participation flag + $sql = "select project_notifications from v_notifications"; + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($result as &$row) { + $current_project_notifications = $row["project_notifications"]; + break; // limit to 1 row + } + } + unset($sql, $prep_statement); + // check if remote record should be removed - if ( $project_notifications == 'false' || ( - $project_security == 'false' && - $project_releases == 'false' && - $project_events == 'false' && - $project_news == 'false' - ) - ) { + if ($project_notifications == 'false') { - // remove remote server record - $url = "https://".$software_url."/app/notifications/notifications_manage.php?id=".$software_uuid."&action=delete"; - if (function_exists('curl_version')) { - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - $response = curl_exec($curl); - curl_close($curl); + if ($current_project_notifications == 'true') { + // remove remote server record + $url = "https://".$software_url."/app/notifications/notifications_manage.php?id=".$software_uuid."&action=delete"; + if (function_exists('curl_version')) { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + $response = curl_exec($curl); + curl_close($curl); + } + else if (file_get_contents(__FILE__) && ini_get('allow_url_fopen')) { + $response = file_get_contents($url); + } + + // parse response + $response = json_decode($response, true); + + if ($response['result'] == 'deleted') { + // set local project notification participation flag to false + $sql = "update v_notifications set project_notifications = 'false'"; + $db->exec(check_sql($sql)); + unset($sql); + } } - else if (file_get_contents(__FILE__) && ini_get('allow_url_fopen')) { - $response = file_get_contents($url); - } - - // parse response - $response = json_decode($response, true); - - if ($response['result'] == 'deleted') { - // set local project notification participation flag to false - $sql = "update v_notifications set project_notifications = 'false'"; - $db->exec(check_sql($sql)); - unset($sql); - - // redirect - $_SESSION["message"] = $text['message-update']; - } - + // redirect + $_SESSION["message"] = $text['message-update']; header("Location: notification_edit.php"); - return; + exit; } - // check for invalid recipient - if ( - $project_notifications == 'true' && - (($project_notification_method == 'email' && !valid_email($project_notification_recipient)) || - ($project_notification_method == 'email' && $project_notification_recipient == '') || - ($project_notification_method == 'text' && $project_notification_recipient == '') - )) { - $_SESSION["form"] = $_POST; - $_SESSION["message"] = $text['message-invalid_recipient']; - header("Location: notification_edit.php"); - return; + // check for invalid values + if ($project_notifications == 'true') { + if ( + ($project_notification_method == 'email' && !valid_email($project_notification_recipient)) || + ($project_notification_method == 'email' && $project_notification_recipient == '') + ) { + $_SESSION["postback"] = $_POST; + $_SESSION["message"] = $text['message-invalid_recipient']; + header("Location: notification_edit.php"); + exit; + } } // collect demographic information ********************************************** @@ -187,8 +193,7 @@ else { $url .= "&os_platform=".urlencode($os_platform); $url .= "&os_info_1=".urlencode($os_info_1); $url .= "&os_info_2=".urlencode($os_info_2); -// echo $url."

"; -// exit; + if (function_exists('curl_version')) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); @@ -208,20 +213,27 @@ else { $sql = "update v_notifications set project_notifications = 'true'"; $db->exec(check_sql($sql)); unset($sql); - - // redirect + // set message $_SESSION["message"] = $text['message-update']; + if ( + $project_security == 'false' && + $project_releases == 'false' && + $project_events == 'false' && + $project_news == 'false' + ) { + $_SESSION["message"] = $_SESSION["message"]." - ".$text['message-no_channels']; + } + // redirect header("Location: notification_edit.php"); - return; + exit; } - } -// check post back session - if (!isset($_SESSION["form"])) { +// check postback session + if (!isset($_SESSION["postback"])) { - // check local project notification participation flag + // check local project notification participation flag $sql = "select project_notifications from v_notifications"; $prep_statement = $db->prepare($sql); if ($prep_statement) { @@ -258,8 +270,9 @@ else { } else { - $setting = fix_postback($_SESSION["form"]); - unset($_SESSION["form"]); + // load postback variables + $setting = fix_postback($_SESSION["postback"]); + unset($_SESSION["postback"]); } @@ -292,11 +305,11 @@ $page["title"] = $text['title-notifications']; echo " \n"; echo " \n"; - echo " \n"; + echo " \n"; echo $text['label-project_notifications']."\n"; echo " \n"; - echo " \n"; - echo " \n"; echo " \n"; echo " \n"; echo "
\n"; @@ -304,74 +317,79 @@ $page["title"] = $text['title-notifications']; echo " \n"; echo " \n"; - echo " \n"; - echo " \n"; - echo $text['label-project_security']."\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo $text['description-project_security']."\n"; - echo " \n"; - echo " \n"; + echo "\n"; - echo " \n"; - echo " \n"; - echo $text['label-project_releases']."\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo $text['description-project_releases']."\n"; - echo " \n"; - echo " \n"; + echo "
\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + echo "
\n"; + echo $text['label-project_security']."\n"; + echo " \n"; + echo "
\n"; + echo $text['description-project_security']."\n"; + echo "
\n"; + echo $text['label-project_releases']."\n"; + echo " \n"; + echo "
\n"; + echo $text['description-project_releases']."\n"; + echo "
\n"; + echo $text['label-project_events']."\n"; + echo " \n"; + echo "
\n"; + echo $text['description-project_events']."\n"; + echo "
\n"; + echo $text['label-project_news']."\n"; + echo " \n"; + echo "
\n"; + echo $text['description-project_news']."\n"; + echo "
\n"; + echo "
\n"; + + echo "\n"; echo " \n"; echo " \n"; - echo " \n"; - echo " \n"; - - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - - echo " \n"; - echo " \n"; - echo " \n"; echo " \n"; - //echo " \n"; echo " \n"; echo "
\n"; - echo $text['label-project_events']."\n"; - echo " \n"; - echo "
\n"; - echo $text['description-project_events']."\n"; - echo "
\n"; - echo $text['label-project_news']."\n"; - echo " \n"; - echo "
\n"; - echo $text['description-project_news']."\n"; - echo "
\n"; echo $text['label-project_notification_method']."\n"; echo " \n"; - //echo " \n"; echo "
\n"; echo $text['description-project_notification_method']."\n"; echo "
\n"; echo $text['label-project_notification_recipient']."\n";