From d29b5efb521a85b5cbdb7bb5e32195ce39746b7c Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Mon, 7 Jul 2014 15:37:34 +0000 Subject: [PATCH] Notifications: Retains postback values if input was invalid. --- app/notifications/notification_edit.php | 92 +++++++++++++------------ resources/functions.php | 14 ++++ 2 files changed, 62 insertions(+), 44 deletions(-) diff --git a/app/notifications/notification_edit.php b/app/notifications/notification_edit.php index 75d4c15786..7a126a9cf8 100644 --- a/app/notifications/notification_edit.php +++ b/app/notifications/notification_edit.php @@ -114,6 +114,7 @@ else { ($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; @@ -217,40 +218,50 @@ else { } -// check 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) { - $project_notifications = $row["project_notifications"]; - break; // limit to 1 row - } - } - unset($sql, $prep_statement); +// check post back session + if (!isset($_SESSION["form"])) { - // if participation enabled - if ($project_notifications == 'true') { - - // get current project notification preferences - $url = "https://".$software_url."/app/notifications/notifications_manage.php?id=".$software_uuid; - 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); + // check 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) { + $setting["project_notifications"] = $row["project_notifications"]; + break; // limit to 1 row + } } + unset($sql, $prep_statement); - // parse response - $setting = json_decode($response, true); + // if participation enabled + if ($setting["project_notifications"] == 'true') { + + // get current project notification preferences + $url = "https://".$software_url."/app/notifications/notifications_manage.php?id=".$software_uuid; + 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 + $setting = json_decode($response, true); + $setting["project_notifications"] = 'true'; + } } + else { + $setting = fix_postback($_SESSION["form"]); + unset($_SESSION["form"]); + + } require_once "resources/header.php"; $page["title"] = $text['title-notifications']; @@ -286,10 +297,9 @@ $page["title"] = $text['title-notifications']; echo " \n"; echo " \n"; echo " \n"; - echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; echo $text['description-project_notifications']."\n"; echo " \n"; echo " \n"; @@ -302,8 +312,7 @@ $page["title"] = $text['title-notifications']; echo " \n"; - echo "
\n"; + echo "
\n"; echo $text['description-project_security']."\n"; echo " \n"; echo " \n"; @@ -316,8 +325,7 @@ $page["title"] = $text['title-notifications']; echo " \n"; - echo "
\n"; + echo "
\n"; echo $text['description-project_releases']."\n"; echo " \n"; echo " \n"; @@ -330,8 +338,7 @@ $page["title"] = $text['title-notifications']; echo " \n"; - echo "
\n"; + echo "
\n"; echo $text['description-project_events']."\n"; echo " \n"; echo " \n"; @@ -344,8 +351,7 @@ $page["title"] = $text['title-notifications']; echo " \n"; - echo "
\n"; + echo "
\n"; echo $text['description-project_news']."\n"; echo " \n"; echo " \n"; @@ -360,8 +366,7 @@ $page["title"] = $text['title-notifications']; //echo " \n"; echo " \n"; //echo " \n"; - echo " \n"; - echo "
\n"; + echo "
\n"; echo $text['description-project_notification_method']."\n"; echo " \n"; echo " \n"; @@ -372,8 +377,7 @@ $page["title"] = $text['title-notifications']; echo $text['label-project_notification_recipient']."\n"; echo " \n"; echo " \n"; - echo " \n"; - echo "
\n"; + echo "
\n"; echo $text['description-project_notification_recipient']."\n"; echo " \n"; echo " \n"; diff --git a/resources/functions.php b/resources/functions.php index ba460c1a31..2f740e7c61 100644 --- a/resources/functions.php +++ b/resources/functions.php @@ -66,6 +66,20 @@ } } + if (!function_exists('fix_postback')) { + function fix_postback($post_array) { + foreach ($post_array as $index => $value) { + if (is_array($value)) { fix_postback($value); } + else { + $value = str_replace('"', """, $value); + $value = str_replace("'", "'", $value); + $post_array[$index] = $value; + } + } + return $post_array; + } + } + if (!function_exists('uuid')) { function uuid() { //uuid version 4