_binary From 288d576413e693ac8923ee6392acc6937e0aaf9d Mon Sep 17 00:00:00 2001
From: Pragya Rana <pragya.rana9@gmail.com>
Date: Mon, 27 Feb 2017 16:21:32 -0800
Subject: [PATCH] Initial commit for adding fields to Security feature

Add following fields to allow user to update via Security:
* Differential Privacy
* Group Analytics
* Search Analytics
---
 src/configs/Config.php                         | 12 ++++++
 src/configs/PublicHelpPages.php                | 14 +++----
 src/controllers/components/SystemComponent.php | 33 ++++++++++++++++
 src/locale/en_US/configure.ini                 | 10 +++++
 src/models/ProfileModel.php                    |  7 ++--
 src/views/elements/SecurityElement.php         | 52 +++++++++++++++++++++++++-
 6 files changed, 117 insertions(+), 11 deletions(-)

diff --git a/src/configs/Config.php b/src/configs/Config.php
index 1f3c481..2045b35 100755
--- a/src/configs/Config.php
+++ b/src/configs/Config.php
@@ -277,6 +277,18 @@ nsdefine('IMAGE_CAPTCHA', 3);
 nsdefine('NORMAL_AUTHENTICATION', 1);
 /** Authentication Mode Possibility*/
 nsdefine('ZKP_AUTHENTICATION', 2);
+/** Privacy Mode Possibility*/
+nsdefine('TRUE_PRIVACY', true);
+/** Privacy Mode Possibility*/
+nsdefine('FALSE_PRIVACY', false);
+/** Group Analytics Mode Possibility*/
+nsdefine('TRUE_GROUP_ANALYTICS', true);
+/** Group Analytics Mode Possibility*/
+nsdefine('FALSE_GROUP_ANALYTICS', false);
+/** Search Analytics Mode Possibility*/
+nsdefine('TRUE_SEARCH_ANALYTICS', true);
+/** Search Analytics Mode Possibility*/
+nsdefine('FALSE_SEARCH_ANALYTICS', false);
 /** */
 nsdefine('NO_RECOVERY', 0);
 /** */
diff --git a/src/configs/PublicHelpPages.php b/src/configs/PublicHelpPages.php
index d0009e5..228fc47 100644
--- a/src/configs/PublicHelpPages.php
+++ b/src/configs/PublicHelpPages.php
@@ -712,7 +712,7 @@ page_footer=
 
 sort=aname
 
-END_HEAD_VARSThe Ad Server field-set is used to control whether, where,
+END_HEAD_VARSThe Ad Server field-set is used to control whether, where,
 and what external advertisements should be displayed by this Yioop instance.
 EOD;
 $help_pages["en-US"]["Add_Locale"] = <<< EOD
@@ -899,12 +899,12 @@ page_footer=
 
 sort=aname
 
-END_HEAD_VARSThe Bot Configuration field-set is used to control whether user&#039;s of this Yioop instance can be chat bots.
-&lt;br/&gt;
-
-If enabled under &#039;&#039;&#039;Manage Accounts&#039;&#039;&#039; a Yioop user can declare themselves a chat bot and give a callback url.
-&lt;br/&gt;
- 
+END_HEAD_VARSThe Bot Configuration field-set is used to control whether user&#039;s of this Yioop instance can be chat bots.
+&lt;br/&gt;
+
+If enabled under &#039;&#039;&#039;Manage Accounts&#039;&#039;&#039; a Yioop user can declare themselves a chat bot and give a callback url.
+&lt;br/&gt;
+ 
 Suppose a chat bot user has a name user name, &#039;&#039;user1&#039;&#039;. If that chat bot user belongs to a group, and in an already existing thread, someone posts a follow up comment containing &#039;&#039;user1&#039;&#039;, then that message will be sent in a post field together with a bot_token field to the callback url. The response from the url will then be used in a response to the comment (if any).  
 EOD;
 $help_pages["en-US"]["Bot_User"] = <<< EOD
diff --git a/src/controllers/components/SystemComponent.php b/src/controllers/components/SystemComponent.php
index c5e5562..d4a982e 100755
--- a/src/controllers/components/SystemComponent.php
+++ b/src/controllers/components/SystemComponent.php
@@ -778,6 +778,24 @@ EOD;
                 ];
             $data['ZKP_UNAVAILABLE'] = true;
         }
+        $data['PRIVACY_MODES'] = [
+           C\TRUE_PRIVACY =>
+               tl('system_component_privacy_enable'),
+           C\FALSE_PRIVACY =>
+               tl('system_component_privacy_disable'),
+            ];
+        $data['GROUP_ANALYTICS_MODES'] = [
+           C\TRUE_GROUP_ANALYTICS =>
+               tl('system_component_group_analytics_enable'),
+           C\FALSE_GROUP_ANALYTICS =>
+               tl('system_component_group_analytics_disable'),
+            ];
+        $data['SEARCH_ANALYTICS_MODES'] = [
+           C\TRUE_SEARCH_ANALYTICS =>
+               tl('system_component_search_analytics_enable'),
+           C\FALSE_SEARCH_ANALYTICS =>
+               tl('system_component_search_analytics_disable'),
+            ];
         if (isset($_REQUEST['arg']) &&
             in_array($_REQUEST['arg'], $possible_arguments)) {
             switch ($_REQUEST['arg']) {
@@ -800,6 +818,21 @@ EOD;
                             $_REQUEST['RECOVERY_MODE'];
                         $change = true;
                     }
+                    if (in_array($_REQUEST['DIFFERENTIAL_PRIVACY'],
+                        array_keys($data['PRIVACY_MODES']))) {
+                        $profile["DIFFERENTIAL_PRIVACY"] = $_REQUEST['DIFFERENTIAL_PRIVACY'];
+                        $change = true;
+                    }
+                    if (in_array($_REQUEST['GROUP_ANALYTICS_MODE'],
+                        array_keys($data['GROUP_ANALYTICS_MODES']))) {
+                        $profile["GROUP_ANALYTICS_MODE"] = $_REQUEST['GROUP_ANALYTICS_MODE'];
+                        $change = true;
+                    }
+                    if (in_array($_REQUEST['SEARCH_ANALYTICS_MODE'],
+                        array_keys($data['SEARCH_ANALYTICS_MODES']))) {
+                        $profile["SEARCH_ANALYTICS_MODE"] = $_REQUEST['SEARCH_ANALYTICS_MODE'];
+                        $change = true;
+                    }
                     if ($change) {
                         $profile_model->updateProfile(C\WORK_DIRECTORY,
                             [], $profile);
diff --git a/src/locale/en_US/configure.ini b/src/locale/en_US/configure.ini
index 838a78a..181006c 100644
--- a/src/locale/en_US/configure.ini
+++ b/src/locale/en_US/configure.ini
@@ -489,6 +489,12 @@ system_component_missing_required = "The following required items were missing:"
 system_component_missing_optional = "The following optional items were missing:"
 system_component_check_passed = "Check Passed."
 system_component_using_local_config = "Using configs/LocalConfig.php so changing work directory above may not work."
+system_component_privacy_enable = "Enable"
+system_component_privacy_disable = "Disable"
+system_component_group_analytics_enable = "True"
+system_component_group_analytics_disable = "False"
+system_component_search_analytics_enable = "True"
+system_component_search_analytics_disable = "False"
 ;
 ; Controller.php
 search_controller_logout_successful = "Logout Successful!!"
@@ -1240,6 +1246,10 @@ security_element_save = "Save"
 security_element_captcha_recovery_questions = "Captcha and Recovery Questions"
 security_element_edit_recovery = "Edit Account Recovery Questions"
 security_element_edit_captcha = "Edit Text Captcha Questions"
+security_element_privacy_type = "Privacy Type"
+security_element_differential_privacy = "Differential Privacy"
+security_element_group_analytics = "Group Analytics"
+security_element_search_analytics = "Search Analytics"
 ;
 ; ServersettingsElement.php
 serversettings_element_server_settings = "Servers and Registration"
diff --git a/src/models/ProfileModel.php b/src/models/ProfileModel.php
index 5341918..2002917 100755
--- a/src/models/ProfileModel.php
+++ b/src/models/ProfileModel.php
@@ -53,14 +53,15 @@ class ProfileModel extends Model
         'BACKGROUND_COLOR', 'BACKGROUND_IMAGE', 'CACHE_LINK', 'CAPTCHA_MODE',
         'CONFIGURE_BOT','CSRF_TOKEN', 'DEBUG_LEVEL', 'DESCRIPTION_WEIGHT',
         'DB_HOST', 'DBMS', 'DB_NAME', 'DB_PASSWORD', 'DB_USER',
-        'DEFAULT_LOCALE', 'FAVICON', 'FIAT_SHAMIR_MODULUS', 'FOREGROUND_COLOR',
-        'GLOBAL_ADSCRIPT', 'GROUP_ITEM', 'IN_LINK','IP_LINK', 'LANDING_PAGE',
+        'DEFAULT_LOCALE', 'DIFFERENTIAL_PRIVACY',
+        'FAVICON', 'FIAT_SHAMIR_MODULUS', 'FOREGROUND_COLOR',
+        'GLOBAL_ADSCRIPT', 'GROUP_ITEM', 'GROUP_ANALYTICS_MODE', 'IN_LINK','IP_LINK', 'LANDING_PAGE',
         'LINK_WEIGHT', 'LOGO', 'M_LOGO', 'MAIL_PASSWORD',  'MAIL_SECURITY',
         'MAIL_SENDER', 'MAIL_SERVER', 'MAIL_SERVERPORT', 'MAIL_USERNAME',
         'MEMCACHE_SERVERS', 'MIN_RESULTS_TO_GROUP', 'NAME_SERVER',
         'MEDIA_MODE',
         'PROXY_SERVERS', 'RECOVERY_MODE', 'REGISTRATION_TYPE', 'RESULT_SCORE',
-        'ROBOT_INSTANCE','RSS_ACCESS', 'SEARCHBAR_PATH',
+        'ROBOT_INSTANCE','RSS_ACCESS', 'SEARCH_ANALYTICS_MODE', 'SEARCHBAR_PATH',
         'SEND_MAIL_MEDIA_UPDATER', 'SERVER_ALPHA', 'SESSION_NAME',
         'SIDE_ADSCRIPT', 'SIDEBAR_COLOR', 'SIGNIN_LINK', 'SIMILAR_LINK',
         'SUBSEARCH_LINK', 'TIMEZONE', 'TITLE_WEIGHT', 'TOPBAR_COLOR',
diff --git a/src/views/elements/SecurityElement.php b/src/views/elements/SecurityElement.php
index fa08d5a..0b6ad65 100755
--- a/src/views/elements/SecurityElement.php
+++ b/src/views/elements/SecurityElement.php
@@ -103,7 +103,7 @@ class SecurityElement extends Element
             <div class="top-margin">
             <fieldset>
                 <legend><label
-                for="captcha-mode"><b><?php
+                for="recovery-mode"><b><?php
                 e(tl('security_element_recovery_type'));
                 e("&nbsp;" . $this->view->helper("helpbutton")->render(
                     "Recovery Type", $data[C\CSRF_TOKEN]))
@@ -116,6 +116,56 @@ class SecurityElement extends Element
                 ?>
             </fieldset>
             </div>
+            <div class="top-margin">
+            <fieldset>
+                <legend><label
+                for="privacy-mode"><b><?php
+                e(tl('security_element_privacy_type'));
+                e("&nbsp;" . $this->view->helper("helpbutton")->render(
+                    "Privacy Type", $data[C\CSRF_TOKEN]))
+                ?></b>
+                </label></legend>
+                <label><b><?=
+                    tl('security_element_differential_privacy')?></b></label>
+                <?php
+                    $this->view->helper("options")->render("privacy-mode",
+                        "DIFFERENTIAL_PRIVACY", $data['PRIVACY_MODES'],
+                        $data['DIFFERENTIAL_PRIVACY']);
+                ?>
+            </fieldset>
+            </div>
+            <div class="top-margin">
+            <fieldset>
+                <legend><label
+                for="group-analytics-mode"><b><?php
+                e(tl('security_element_group_analytics'));
+                e("&nbsp;" . $this->view->helper("helpbutton")->render(
+                    "Group Analytics", $data[C\CSRF_TOKEN]))
+                ?></b>
+                </label></legend>
+                <?php
+                    $this->view->helper("options")->render("group-analytics-mode",
+                        "GROUP_ANALYTICS_MODE", $data['GROUP_ANALYTICS_MODES'],
+                        $data['GROUP_ANALYTICS_MODE']);
+                ?>
+            </fieldset>
+            </div>
+            <div class="top-margin">
+            <fieldset>
+                <legend><label
+                for="search-analytics"><b><?php
+                e(tl('security_element_search_analytics'));
+                e("&nbsp;" . $this->view->helper("helpbutton")->render(
+                    "Search Analytics", $data[C\CSRF_TOKEN]))
+                ?></b>
+                </label></legend>
+                <?php
+                    $this->view->helper("options")->render("search-analytics-mode",
+                        "SEARCH_ANAYTICS_MODE", $data['SEARCH_ANALYTICS_MODES'],
+                        $data['SEARCH_ANALYTICS_MODE']);
+                ?>
+            </fieldset>
+            </div>
             <div class="top-margin center"><button
                 class="button-box" type="submit"><?=tl('security_element_save')
                 ?></button>
-- 
2.8.4 (Apple Git-73)

