Removes Is Advertiser/Uses Store checkbox from manage account, simplifies Monetization Type drop down in server settings, fixes enable/disable controls for Group and Search analytics, changes CreateDb to make sqlite DBs in WAL mode, adds wiki help documentation, a=chris

Chris Pollett [2018-05-16 17:May:th]
Removes Is Advertiser/Uses Store checkbox from manage account, simplifies Monetization Type drop down in server settings, fixes enable/disable controls for Group and Search analytics, changes CreateDb to make sqlite DBs in WAL mode, adds wiki help documentation, a=chris
Filename
src/configs/Config.php
src/configs/Createdb.php
src/configs/PublicHelpPages.php
src/controllers/AdminController.php
src/controllers/SearchController.php
src/controllers/components/AccountaccessComponent.php
src/controllers/components/SocialComponent.php
src/controllers/components/SystemComponent.php
src/data/default.db
src/library/UpgradeFunctions.php
src/library/VersionFunctions.php
src/models/GroupModel.php
src/models/ImpressionModel.php
src/models/ProfileModel.php
src/models/UserModel.php
src/views/CrawlstatusView.php
src/views/elements/ActivityElement.php
src/views/elements/ManageaccountElement.php
src/views/elements/ManagegroupsElement.php
diff --git a/src/configs/Config.php b/src/configs/Config.php
index ebd90b3e1..e6f9c07f2 100755
--- a/src/configs/Config.php
+++ b/src/configs/Config.php
@@ -498,6 +498,7 @@ if (file_exists(WORK_DIRECTORY . PROFILE_FILE_NAME)) {
     nsdefine('FOREGROUND_COLOR', "#FFFFFF");
     nsdefine('SIDEBAR_COLOR', "#88AA44");
     nsdefine('TOPBAR_COLOR', "#EEEEFF");
+    nsdefine('MONETIZATION_TYPE', "no_monetization");
     nsdefine('AD_LOCATION','none');
 }
 /** ignore */
@@ -1021,9 +1022,9 @@ nsconddefine("ANALYTICS_UPDATE_INTERVAL", ONE_HOUR / 6);
 /** Value of epsilon in differential privacy formula */
 nsconddefine('PRIVACY_EPSILON', 0.01);
 /** Flag to turn on/off search impression recording */
-nsconddefine('SEARCH_ANALYTICS', true);
+nsconddefine('SEARCH_ANALYTICS_MODE', true);
 /** Flag to turn on/off group impression recording */
-nsconddefine('GROUP_ANALYTICS', true);
+nsconddefine('GROUP_ANALYTICS_MODE', true);
 /** Flag to turn on/off differential privacy */
 nsconddefine('DIFFERENTIAL_PRIVACY', false);
 /*
diff --git a/src/configs/Createdb.php b/src/configs/Createdb.php
index 35f6763f5..cc101fd59 100755
--- a/src/configs/Createdb.php
+++ b/src/configs/Createdb.php
@@ -100,13 +100,16 @@ if (!in_array(DBMS, ['sqlite', 'sqlite3'])) {
     }
 } else {
     $which_dbms = "sqlite";
-    @unlink(CRAWL_DIR."/data/" . DB_NAME . ".db");
+    @unlink(CRAWL_DIR . "/data/" . DB_NAME . ".db");
     $db = new $db_class();
     $db->connect();
-    @unlink(CRAWL_DIR."/data/" . PRIVATE_DB_NAME . ".db");
+    $db->execute("PRAGMA journal_mode=WAL");
+    @unlink(CRAWL_DIR . "/data/" . PRIVATE_DB_NAME . ".db");
     $private_db = new $private_db_class();
     $private_db->connect(PRIVATE_DB_HOST, PRIVATE_DB_USER,
         PRIVATE_DB_PASSWORD, PRIVATE_DB_NAME);
+    $private_db->execute("PRAGMA journal_mode=WAL");
+    echo "yo";
 }
 if (!$profile_model->createDatabaseTables($db, $dbinfo)) {
     echo "\n\nCouldn't create database tables!!!\n\n";
@@ -139,7 +142,7 @@ $sql ="INSERT INTO USERS VALUES (" . ROOT_ID . ", 'admin', 'admin','" .
         ROOT_USERNAME . "',
         'root@dev.null', '".L\crawlCrypt('')."', '".ACTIVE_STATUS.
         "', '".L\crawlCrypt(ROOT_USERNAME . AUTH_KEY . $creation_time).
-        "', 0,'$creation_time', 0, 0, '$zkp_password')";
+        "', 0,'$creation_time', 0, '$zkp_password')";
 $db->execute($sql);
 /* public account is an inactive account for used for public permissions
    default account is root without a password
@@ -147,7 +150,7 @@ $db->execute($sql);
 $sql ="INSERT INTO USERS VALUES (".PUBLIC_USER_ID.", 'all', 'all','public',
         'public@dev.null', '".L\crawlCrypt('')."', '".INACTIVE_STATUS.
         "', '".L\crawlCrypt('public' . AUTH_KEY . $creation_time)."', 0,
-        '$creation_time', 0, 0, '$zkp_password')";
+        '$creation_time', 0, '$zkp_password')";
 $db->execute($sql);
 //default public group with group id 1
 $creation_time = L\microTimestamp();
@@ -158,7 +161,6 @@ $db->execute($sql);
 $now = time();
 $db->execute("INSERT INTO ROLE VALUES (" . ADMIN_ROLE . ", 'Admin' )");
 $db->execute("INSERT INTO ROLE VALUES (" . USER_ROLE . ", 'User' )");
-$db->execute("INSERT INTO ROLE VALUES (" . BUSINESS_ROLE . ", 'Business User' )");
 $db->execute("INSERT INTO ROLE VALUES (".BOT_ROLE.", 'Bot User' )");
 $db->execute("INSERT INTO USER_ROLE VALUES (" . ROOT_ID . ", " . ADMIN_ROLE .
     ")");
@@ -405,10 +407,7 @@ foreach ($activities as $activity => $translation_info) {
     // set-up activity
     $db->execute("INSERT INTO ACTIVITY VALUES ($i, $i, '$activity')");
     //give admin role the ability to have that activity (except ads)
-    if (in_array($activity, ["manageCredits", "manageAdvertisements"] )) {
-        $db->execute("INSERT INTO ROLE_ACTIVITY VALUES (" .
-            BUSINESS_ROLE . ", $i)");
-    } else {
+    if (!in_array($activity, ["manageCredits", "manageAdvertisements"] )) {
         if ($activity == "botStory") {
             $db->execute("INSERT INTO ROLE_ACTIVITY VALUES (" .
                 BOT_ROLE . ", $i)");
diff --git a/src/configs/PublicHelpPages.php b/src/configs/PublicHelpPages.php
index c19807f3d..ca3f33c2a 100644
--- a/src/configs/PublicHelpPages.php
+++ b/src/configs/PublicHelpPages.php
@@ -1332,41 +1332,58 @@ page_footer=

 sort=aname

-END_HEAD_VARS''This form appears when the Group Name is available to create a new Group. ''
-----
-
-'''Name''' Field is used to specify the name of the new Group.
-<br />
-'''Register''' dropdown says how other users are allowed to join the group:
-* <u>No One</u> means no other user can join the group (you can still invite
-other users).
-* <u>By Request</u> means that other users can request the group owner to join
-the group.
-* <u>Anyone</u> means all users are allowed to join the group.
-
-
-'''Access''' dropdown controls how users who belong/subscribe to a group
-other than the owner can access that group.
-* <u>No Read</u> means that a non-owner member of the group cannot read or
-write the group news feed and cannot read the group wiki.
-* <u>Read</u> means that a non-owner member of the group can read the group
-news feed and the groups wiki page.
-* <u>Read</u> Comment means that a non-owner member of the group can read the
-group feed and wikis and can comment on any existing threads, but cannot start
-new ones.
-* <u>Read Write</u>, means that a non-owner member of the group can start new
-threads and comment on existing ones in the group feed and can edit and create
-wiki pages for the group's wiki.
-
+END_HEAD_VARS''This form appears when the Group Name is available to create a new Group. ''
+----
+
+'''Name'''
+* is used to specify the name of the new Group.
+
+'''Register'''
+* says how other users are allowed to join the group:
+* <u>No One</u> means no other user can join the group (you can still invite
+other users).
+* <u>By Request</u> means that other users can request the group owner to join
+the group.
+* <u>Anyone</u> means all users are allowed to join the group.
+
+
+'''Access'''
+* controls how users who belong/subscribe to a group
+other than the owner can access that group.
+* <u>No Read</u> means that a non-owner member of the group cannot read or
+write the group news feed and cannot read the group wiki.
+* <u>Read</u> means that a non-owner member of the group can read the group
+news feed and the groups wiki page.
+* <u>Read Comment</u> means that a non-owner member of the group can read the
+group feed and wikis and can comment on any existing threads, but cannot start
+new ones.
+* <u>Read Write</u> means that a non-owner member of the group can start new
+threads and comment on existing ones in the group feed.
+* <u>Read Write Wiki</u>  means that a non-owner member of the group can start new
+threads, can comment on existing ones in the group feed, and can edit and create
+wiki pages for the group's wiki.
+
+'''Voting'''
+* Specifies the kind of voting allowed in the new group.
+* + Voting allows users to vote up posts and users,
+* - Voting allows users to vote down posts and users.
+* +/- Voting allows users to vote up and down posts and users..
+
+'''Post Life time'''
+* Specifies How long the posts should be kept.
+
+'''Encryption'''
+* Whether the posts in this group should be encrypted on the server.
+It does not enable encryption of wiki pages or media uploaded to a group.
+Enabling encryption means that posts will no longer be searchable. Once
+you choose a group as encrypted, you are not able to change it to be unencrypted.
+Similarly, you can't change an unencrypted group into a encrypted one. Yioop
+maintains two databases a private and public one. Encrypted posts are stored
+in the public database, group keys needed to decrypt and display them are stored
+in a private database. Each post is encrypted using the group key and a unique per
+post random salt vector. The idea is if an intruder steals only one of the
+two databases it will be difficult for them to decrypt the posts.

-'''Voting'''
-* Specify the kind of voting allowed in the new group. + Voting allows users to
-vote up, -- Voting allows users to vote down. +/- allows Voting up and down.
-'''Post Life time''' - Specifies How long the posts should be kept.
-
-'''Encryption'''
-* Whether the posts in this group should be encrypted on the server. Drawback is
-in future group will not be as searchable as a non-encrypted group.
 EOD;
 $help_pages["en-US"]["Database_Setup"] = <<< EOD
 page_type=standard
@@ -2019,8 +2036,13 @@ page_footer=

 sort=aname

-END_HEAD_VARSThe &#039;&#039;&#039;Monetization&#039;&#039;&#039; field-set is used to control whether, where,
-and what external advertisements should be displayed by this Yioop instance.
+END_HEAD_VARSThe &#039;&#039;&#039;Monetization&#039;&#039;&#039; field-set controls what kind of monetization features are used by Yioop. The default is that no monetization features are enabled.
+
+* &#039;&#039;&#039;External Ad Server&#039;&#039;&#039; allows one to add a script for an external ad server to search result pages. Selecting this option lets you choose the placement of the external ad server&#039;s results and to cut and paste the necessary Javascript code.
+* &#039;&#039;&#039;Group Fees&#039;&#039;&#039; enables the Manage Credits activity for all users. This allows users to purchase credits. By default credits are free, however, if the payment script is bought from seekquarry.com and installed then credits can be purchased via a credit card for a dollar value. Besides enabling the Manage Credits activity, &#039;&#039;&#039;Group Fees&#039;&#039;&#039; also allows owner&#039;s of groups on your site to charge a fee in credits to join a group.
+* &#039;&#039;&#039;Keyword Advertising&#039;&#039;&#039; enables the Manage Credits activity mentioned above and also enables a Manage Advertisements activity. This latter activity allows user&#039;s to purchase keyword advertisements for search results.
+* &#039;&#039;&#039;Group Fees and Keyword Ads&#039;&#039;&#039; enables both charging credits for joining groups and allows user&#039;s to purchase keyword advertisements.
+
 EOD;
 $help_pages["en-US"]["Name_Server_Setup"] = <<< EOD
 page_type=standard
@@ -2207,11 +2229,11 @@ page_footer=

 sort=aname

-END_HEAD_VARSThe privacy fieldset controls a variety of options with respect to how analytics from individual users is collected by a Yioop instance.
-
-*&#039;&#039;&#039;Differential Privacy&#039;&#039;&#039; controls whether group and thread view statistics which are displayed under the Manage Groups and Feeds and Wikis activities are fuzzified to try to prevent individual users from being identified by change in counts.
-*&#039;&#039;&#039;Group Analytics&#039;&#039;&#039; controls whether information about group and thread views is collected and aggregated.
-*&#039;&#039;&#039;Search Analytics&#039;&#039;&#039; controls whether information about search queries is collected and aggregated.
+END_HEAD_VARSThe privacy fieldset controls a variety of options with respect to how analytics from individual users is collected by a Yioop instance.
+
+* &#039;&#039;&#039;Differential Privacy&#039;&#039;&#039; controls whether group and thread view statistics which are displayed under the Manage Groups and Feeds and Wikis activities are fuzzified to try to prevent individual users from being identifiable by change in counts.
+* &#039;&#039;&#039;Group Analytics&#039;&#039;&#039; controls whether information about group and thread views is collected and whether statistics about these views are visible to group owners. If this is disabled, it does not delete statistics that were previously collected, however, they will no longer be viewable and no future views will be recorded.
+* &#039;&#039;&#039;Search Analytics&#039;&#039;&#039; controls whether information about search queries is collected and aggregated. If this is disabled, it does not delete statistics that were previously collected, however, they will no longer be viewable and no future collection will occur. Also, if this is disabled, but keyword advertisements are enabled, then impressions with respect to advertised keywords will still be collected.
 EOD;
 $help_pages["en-US"]["Proxy_Server"] = <<< EOD
 page_type=standard
diff --git a/src/controllers/AdminController.php b/src/controllers/AdminController.php
index eddccf5e2..6c0af9461 100755
--- a/src/controllers/AdminController.php
+++ b/src/controllers/AdminController.php
@@ -353,7 +353,7 @@ class AdminController extends Controller implements CrawlConstants
                 $allowed = true;
             }
         }
-        // business role only allows managing advertisements;
+        // always allow managing account
         if (!$allowed && $activity == "manageAccount") {
             $activity = $allowed_activities[0]['METHOD_NAME'];
             $_REQUEST["a"] = $activity;
diff --git a/src/controllers/SearchController.php b/src/controllers/SearchController.php
index ba5c77f14..009b490fa 100755
--- a/src/controllers/SearchController.php
+++ b/src/controllers/SearchController.php
@@ -144,10 +144,8 @@ class SearchController extends Controller implements CrawlConstants
                 }
                 $this->cacheRequestAndOutput($arg, $ui_array, $query,
                     $index_timestamp);
-                if (C\SEARCH_ANALYTICS) {
-                    $this->model("impression")->addQueryImpression(
-                        "cache:$arg");
-                }
+                $this->model("impression")->addQueryImpression(
+                    "cache:$arg");
                 return;
             }
         }
@@ -861,8 +859,7 @@ class SearchController extends Controller implements CrawlConstants
             $phrase_results['TOTAL_ROWS'] : 0;
         $data['LIMIT'] = $limit;
         $data['RESULTS_PER_PAGE'] = $results_per_page;
-        if ($add_query_impression && !empty($data['QUERY']) &&
-            C\SEARCH_ANALYTICS) {
+        if ($add_query_impression && !empty($data['QUERY'])) {
             $this->model("impression")->addQueryImpression($data['QUERY']);
         }
     }
@@ -934,6 +931,11 @@ class SearchController extends Controller implements CrawlConstants
         $use_cache_if_possible = ($original_query == $query) ? true : false;
         $network_work_query = $query;
         $query = preg_replace('/no:network/', "", $query);
+        /* if $use_network is true, then if there are multiple machine
+           we can try to use them. It doesn't say that a network query
+           must happen. If it is false, however, a network query should not
+           happen.
+         */
         $use_network = ($network_work_query == $query) ? true : false;
         $guess_query = $query;
         $query = preg_replace('/no:guess/', "", $query);
diff --git a/src/controllers/components/AccountaccessComponent.php b/src/controllers/components/AccountaccessComponent.php
index 8266feaf5..5ef981448 100644
--- a/src/controllers/components/AccountaccessComponent.php
+++ b/src/controllers/components/AccountaccessComponent.php
@@ -81,15 +81,7 @@ class AccountaccessComponent extends Component
         $data["ELEMENT"] = "manageaccount";
         $data['SCRIPT'] = "";
         $data['MESSAGE'] = "";
-        $monetization_type = (empty($profile['MONETIZATION_TYPE'])) ?
-            "no_monetization": $profile['MONETIZATION_TYPE'];
         $data['yioop_bot_configuration'] = $profile['CONFIGURE_BOT'];
-        if (!in_array($monetization_type,
-            ['no_monetization','external_advertisements'])) {
-            $data['yioop_store'] = true;
-        } else {
-            $data['yioop_store'] = false;
-        }
         if ($profile['CONFIGURE_BOT'] == 'enable_bot_users') {
             $data['yioop_bot_configuration'] = true;
         } else {
@@ -178,17 +170,6 @@ class AccountaccessComponent extends Component
                     $user_model->setUserSession($user_id, $user_session);
                 }
             }
-            $business_id = $role_model->getRoleId('Business User');
-            if (!$business_id || $business_id < 0) {
-                $data['yioop_store'] = false;
-            } else {
-                $role_ids = $user_model->isAllowedUserActivity($user_id,
-                    "manageAdvertisements", true);
-                if (is_array($role_ids) && (count($role_ids) > 1 ||
-                    $role_ids[0] != $business_id) ) {
-                    $data['yioop_store'] = false;
-                }
-            }
         }
         $data['USERNAME'] = $username;
         $data['NUM_SHOWN'] = 5;
@@ -297,18 +278,6 @@ class AccountaccessComponent extends Component
                         $data['USER'][$field] =  $user[$field];
                     }
                 }
-                $uses_store = false;
-                $business_id = $role_model->getRoleId('Business User');
-                if (isset($_REQUEST['USES_STORE']) && $business_id ) {
-                    $user['USES_STORE'] = 1;
-                    $data['USER']['USES_STORE'] = $user['USES_STORE'];
-                    $uses_store = true;
-                    $role_model->addUserRole($user_id, $business_id);
-                } else if ($business_id) {
-                    $user['USES_STORE'] = 0;
-                    $data['USER']['USES_STORE'] = $user['USES_STORE'];
-                    $role_model->deleteUserRole($user_id, $business_id);
-                }
                 $is_bot_updated = false;
                 $bot_role_id = $role_model->getRoleId('Bot User');
                 if (isset($_REQUEST['IS_BOT_USER']) && $bot_role_id) {
diff --git a/src/controllers/components/SocialComponent.php b/src/controllers/components/SocialComponent.php
index bf9cc85cb..ad153e32c 100644
--- a/src/controllers/components/SocialComponent.php
+++ b/src/controllers/components/SocialComponent.php
@@ -1718,12 +1718,10 @@ class SocialComponent extends Component implements CrawlConstants
                 !in_array($_REQUEST['f'], ["rss", "json", "serial"]))) {
                 $pub_clause = ['pub_date', "=", "", "ASC"];
                 $sort = "ksort";
-                if (C\GROUP_ANALYTICS) {
-                    $parent->model("impression")->add($user_id, $just_thread,
-                        C\THREAD_IMPRESSION);
-                    $parent->model("impression")->add($user_id, $group_id,
-                        C\GROUP_IMPRESSION);
-                }
+                $parent->model("impression")->add($user_id, $just_thread,
+                    C\THREAD_IMPRESSION);
+                $parent->model("impression")->add($user_id, $group_id,
+                    C\GROUP_IMPRESSION);
             }
         }
         $search_array = [
@@ -1781,10 +1779,8 @@ class SocialComponent extends Component implements CrawlConstants
             $type= "group";
             $type_id = $just_group_id;
             $data['JUST_GROUP_ID'] = $just_group_id;
-            if (C\GROUP_ANALYTICS) {
-                $parent->model("impression")->add($user_id, $just_group_id,
-                    C\GROUP_IMPRESSION);
-            }
+            $parent->model("impression")->add($user_id, $just_group_id,
+                C\GROUP_IMPRESSION);
         }
         if ($just_user_id) {
             $page["USER_NAME"] = $user_model->getUsername($just_user_id);
@@ -3041,8 +3037,7 @@ EOD;
     {
         $parent = $this->parent;
         $group_model = $parent->model("group");
-        if (!empty($data['PAGE_ID']) && $data['MODE'] != 'api' &&
-            C\GROUP_ANALYTICS) {
+        if (!empty($data['PAGE_ID']) && $data['MODE'] != 'api') {
             $parent->model("impression")->add($user_id, $data['PAGE_ID'],
                 C\WIKI_IMPRESSION);
             $parent->model("impression")->add($user_id, $group_id,
diff --git a/src/controllers/components/SystemComponent.php b/src/controllers/components/SystemComponent.php
index 3fc5db0e2..90935d34a 100755
--- a/src/controllers/components/SystemComponent.php
+++ b/src/controllers/components/SystemComponent.php
@@ -574,7 +574,8 @@ class SystemComponent extends Component
                     $profile_model->getProfile(C\WORK_DIRECTORY);
                 if (strcmp($old_profile["MONETIZATION_TYPE"],
                         $data["MONETIZATION_TYPE"]) !== 0) {
-                    $business_id = $role_model->getRoleId('Business User');
+                    $user_role_id = $role_model->getRoleId('User');
+                    $admin_role_id = $role_model->getRoleId('Admin');
                     $ad_id = $activity_model->getActivityIdFromMethodName(
                         'manageAdvertisements');
                     $credit_id = $activity_model->getActivityIdFromMethodName(
@@ -582,26 +583,37 @@ class SystemComponent extends Component
                     if (isset($data['MONETIZATION_TYPE']) &&
                         in_array($data['MONETIZATION_TYPE'],
                         ['no_monetization', 'external_advertisements'])) {
-                        if ($business_id) {
-                            $role_model->deleteActivityRole($business_id,
+                        if ($user_role_id) {
+                            $role_model->deleteActivityRole($user_role_id,
                                 $ad_id);
-                            $role_model->deleteActivityRole($business_id,
+                            $role_model->deleteActivityRole($user_role_id,
                                 $credit_id);
                         }
+                        $role_model->deleteActivityRole($admin_role_id,
+                            $ad_id);
+                        $role_model->deleteActivityRole($admin_role_id,
+                            $credit_id);
                     } else if (isset($data['MONETIZATION_TYPE']) &&
                         in_array($data['MONETIZATION_TYPE'],['group_fees'])) {
-                        if ($business_id) {
-                            $role_model->deleteActivityRole($business_id,
+                        if ($user_role_id) {
+                            $role_model->deleteActivityRole($user_role_id,
                                 $ad_id);
-                            $role_model->addActivityRole($business_id,
+                            $role_model->addActivityRole($user_role_id,
                                 $credit_id);
                         }
+                        $role_model->deleteActivityRole($admin_role_id,
+                            $ad_id);
+                        $role_model->addActivityRole($admin_role_id,
+                            $credit_id);
                     } else {
-                        if ($business_id) {
-                            $role_model->addActivityRole($business_id, $ad_id);
-                            $role_model->addActivityRole($business_id,
+                        if ($user_role_id) {
+                            $role_model->addActivityRole($user_role_id, $ad_id);
+                            $role_model->addActivityRole($user_role_id,
                                 $credit_id);
                         }
+                        $role_model->addActivityRole($admin_role_id, $ad_id);
+                        $role_model->addActivityRole($admin_role_id,
+                            $credit_id);
                     }
                 }
                 $db_problem = false;
@@ -1085,8 +1097,8 @@ EOD;
                         $data['WORK_DIRECTORY'])) {
                         $profile['DBMS'] = 'sqlite3';
                         $data['DBMS'] = 'sqlite3';
-                        $profile['DB_NAME'] = 'default';
-                        $data['DB_NAME'] = 'default';
+                        $profile['DB_NAME'] = 'public_default';
+                        $data['DB_NAME'] = 'public_default';
                         $profile['PRIVATE_DBMS'] = 'sqlite3';
                         $data['PRIVATE_DBMS'] = 'sqlite3';
                         $profile['PRIVATE_DB_NAME'] = 'private_default';
@@ -1121,7 +1133,7 @@ EOD;
                                     new D\Sqlite3Manager();
                                 $machine_model->db->connect("", "", "",
                                     $data['WORK_DIRECTORY'] .
-                                    "/data/default.db");
+                                    "/data/public_default.db");
                                 $parent->model('machine')->addMachine(
                                     "Local", $data['NAME_SERVER'], true, 1);
                                 return $parent->redirectWithMessage(
diff --git a/src/data/default.db b/src/data/default.db
deleted file mode 100644
index b9ed3c37c..000000000
Binary files a/src/data/default.db and /dev/null differ
diff --git a/src/library/UpgradeFunctions.php b/src/library/UpgradeFunctions.php
index ea8c10f9a..8e1e3160b 100644
--- a/src/library/UpgradeFunctions.php
+++ b/src/library/UpgradeFunctions.php
@@ -197,7 +197,7 @@ function getWikiHelpPages()
 {
     $help_pages = [];
     $default_dbm = new D\Sqlite3Manager();
-    $default_dbm->connect("", "", "", C\BASE_DIR . "/data/default.db");
+    $default_dbm->connect("", "", "", C\BASE_DIR . "/data/public_default.db");
     if (!$default_dbm) {
         return false;
     }
diff --git a/src/library/VersionFunctions.php b/src/library/VersionFunctions.php
index e72fc0d56..4011938c8 100644
--- a/src/library/VersionFunctions.php
+++ b/src/library/VersionFunctions.php
@@ -1634,7 +1634,6 @@ function upgradeDatabaseVersion57(&$db)
             C\NAME_LEN .") UNIQUE, EMAIL VARCHAR(" . C\LONG_NAME_LEN . "),
             PASSWORD VARCHAR(" . C\LONG_NAME_LEN . "), STATUS INTEGER,
             HASH VARCHAR(" . C\LONG_NAME_LEN . "),
-            USES_STORE INTEGER DEFAULT 0,
             CREATION_TIME VARCHAR(" . C\MICROSECOND_TIMESTAMP_LEN .
             "), UPS INTEGER DEFAULT 0,
             DOWNS INTEGER DEFAULT 0, ZKP_PASSWORD CHAR(" .
@@ -1642,7 +1641,8 @@ function upgradeDatabaseVersion57(&$db)
         D\DatasourceManager::copyTable("USERS_OLD", $db, "USERS",
             $db);
     } else {
-        $db->execute("ALTER TABLE USERS RENAME COLUMN IS_ADVERTISER TO
-            USES_STORE");
+        // only one of these should do anything
+        $db->execute("ALTER TABLE USERS DROP COLUMN IS_ADVERTISER");
+        $db->execute("ALTER TABLE USERS DROP COLUMN USES_STORE");
     }
 }
diff --git a/src/models/GroupModel.php b/src/models/GroupModel.php
index c9844bb58..8e00dfdb1 100644
--- a/src/models/GroupModel.php
+++ b/src/models/GroupModel.php
@@ -839,7 +839,7 @@ class GroupModel extends Model implements MediaConstants
         $pos = strpos($data, str_repeat("0", 10));
         if ($pos !== false) {
             $data_parts = explode(str_repeat("0", 10), $data);
-            $out_data= openssl_decrypt($data_parts[1], $cipher_method,
+            $out_data = openssl_decrypt($data_parts[1], $cipher_method,
                 $key, 0, $data_parts[0]);
         }
         return $out_data;
diff --git a/src/models/ImpressionModel.php b/src/models/ImpressionModel.php
index 18aade637..9d4681de9 100644
--- a/src/models/ImpressionModel.php
+++ b/src/models/ImpressionModel.php
@@ -89,7 +89,7 @@ class ImpressionModel extends Model
      */
     public function addQueryImpression($query)
     {
-        if (!C\SEARCH_ANALYTICS) {
+        if (!C\SEARCH_ANALYTICS_MODE || C\SEARCH_ANALYTICS_MODE == "0") {
             return;
         }
         $db = $this->db;
@@ -156,9 +156,9 @@ class ImpressionModel extends Model
     {
         $db = $this->db;
         $timestamps = [C\ONE_HOUR => floor(time()/C\ONE_HOUR) * C\ONE_HOUR,
-            C\ONE_DAY => floor(time()/C\ONE_DAY)*C\ONE_DAY,
-            C\ONE_MONTH => floor(time()/C\ONE_MONTH)*C\ONE_MONTH,
-            C\ONE_YEAR => floor(time()/C\ONE_YEAR)*C\ONE_YEAR];
+            C\ONE_DAY => floor(time()/C\ONE_DAY) * C\ONE_DAY,
+            C\ONE_MONTH => floor(time()/C\ONE_MONTH) * C\ONE_MONTH,
+            C\ONE_YEAR => floor(time()/C\ONE_YEAR) * C\ONE_YEAR];
         $table = "ITEM_IMPRESSION";
         $condition = "VIEW_DATE >= ?";
         $sum = "COUNT(*)";
@@ -435,6 +435,9 @@ class ImpressionModel extends Model
      */
     public static function addWithDb($user_id, $item_id, $type_id, $db)
     {
+        if (!C\GROUP_ANALYTICS_MODE || C\GROUP_ANALYTICS_MODE == "0") {
+            return;
+        }
         $sql = "INSERT INTO ITEM_IMPRESSION VALUES (?, ?, ?, ?)";
         if ($user_id != C\PUBLIC_USER_ID) {
             $db->execute($sql, [$user_id, $item_id, $type_id, time()]);
diff --git a/src/models/ProfileModel.php b/src/models/ProfileModel.php
index 7218d3c96..883dd1514 100755
--- a/src/models/ProfileModel.php
+++ b/src/models/ProfileModel.php
@@ -343,11 +343,9 @@ class ProfileModel extends Model
                 C\NAME_LEN .") UNIQUE, EMAIL VARCHAR(" . C\LONG_NAME_LEN . "),
                 PASSWORD VARCHAR(" . C\LONG_NAME_LEN . "), STATUS INTEGER,
                 HASH VARCHAR(" . C\LONG_NAME_LEN . "),
-                USES_STORE INTEGER DEFAULT 0,
                 CREATION_TIME VARCHAR(" . C\MICROSECOND_TIMESTAMP_LEN .
-                "), UPS INTEGER DEFAULT 0,
-                DOWNS INTEGER DEFAULT 0, ZKP_PASSWORD CHAR(" .
-                C\ZKP_PASSWORD_LEN . "))",
+                "), UPS INTEGER DEFAULT 0, DOWNS INTEGER DEFAULT 0,
+                ZKP_PASSWORD CHAR(" . C\ZKP_PASSWORD_LEN . "))",
             "USRS_USER_NAME_INDEX" => "CREATE INDEX USRS_USER_NAME_INDEX ON
                 USERS(USER_NAME)",
             "USER_GROUP" => "CREATE TABLE USER_GROUP (USER_ID INTEGER,
@@ -564,7 +562,7 @@ EOT;
             //don't let the database systems be unspecified
             if (empty($profile["DBMS"])) {
                 $profile["DBMS"] = 'Sqlite3';
-                $profile['DB_NAME'] = "default";
+                $profile['DB_NAME'] = "public_default";
             }
             if (empty($profile["PRIVATE_DBMS"])) {
                 $profile["PRIVATE_DBMS"] = 'Sqlite3';
@@ -652,7 +650,7 @@ EOT;
             return false;
         }
         $default_dbm = new Sqlite3Manager();
-        $default_dbm->connect("", "", "", C\BASE_DIR."/data/default.db");
+        $default_dbm->connect("", "", "", C\BASE_DIR."/data/public_default.db");
         if (!$default_dbm) {
             return false;
         }
diff --git a/src/models/UserModel.php b/src/models/UserModel.php
index 996a1b633..b6f7d5150 100755
--- a/src/models/UserModel.php
+++ b/src/models/UserModel.php
@@ -54,7 +54,7 @@ class UserModel extends Model
      */
     public $search_table_column_map = ["first"=>"FIRST_NAME",
         "last" => "LAST_NAME", "user" => "USER_NAME", "email"=>"EMAIL",
-        "status"=>"STATUS", "accounttype" => "IS_ADVERTISER"];
+        "status"=>"STATUS"];
     /**
      * These fields if present in $search_array (used by @see getRows() ),
      * but with value "-1", will be skipped as part of the where clause
diff --git a/src/views/CrawlstatusView.php b/src/views/CrawlstatusView.php
index 8c92f5adf..15b0bfd44 100755
--- a/src/views/CrawlstatusView.php
+++ b/src/views/CrawlstatusView.php
@@ -58,7 +58,6 @@ class CrawlstatusView extends View
             "&amp;filter=" . $data['FILTER'];
         $query_stats_url = "{$base_url}queryStats$filter";
         $statistics_url = "{$base_url}statistics&amp;";
-        //htmlentities(B\controllerUrl('statistics', true));
         ?>
         <h2><?= tl('crawlstatus_view_currently_processing') ?></h2>
         <p><b><?= tl('crawlstatus_view_description') ?></b> <?php
@@ -198,10 +197,12 @@ class CrawlstatusView extends View
         } else {
             e("<p>".tl('crawlstatus_view_no_recent_urls')."</p>");
         }
-
-        $data['TABLE_TITLE'] = tl('crawlstatus_view_previous_crawls') .
-            " <span class='no-bold medium-large'>[<a href='$query_stats_url'>" .
+        $data['TABLE_TITLE'] = tl('crawlstatus_view_previous_crawls');
+        if (C\SEARCH_ANALYTICS_MODE && C\SEARCH_ANALYTICS_MODE != "0") {
+            $data['TABLE_TITLE'] .= " <span class='no-bold medium-large'>" .
+            "[<a href='$query_stats_url'>" .
             tl('crawlstatus_view_query_stats') . "</a>]</span>";
+        }
         $data['ACTIVITY'] = 'manageCrawls';
         $data['VIEW'] = $this;
         $data['NO_FLOAT_TABLE'] = true;
diff --git a/src/views/elements/ActivityElement.php b/src/views/elements/ActivityElement.php
index 86ec168b6..3c70786e7 100755
--- a/src/views/elements/ActivityElement.php
+++ b/src/views/elements/ActivityElement.php
@@ -169,9 +169,9 @@ class ActivityElement extends Element
                         <?php
                         for ($i = 0 ; $i < $count; $i++) {
                             if ($i < $count - 1) {
-                                $class="class='bottom-border'";
+                                $class = "class='bottom-border'";
                             } else {
-                                $class="";
+                                $class = "";
                             }
                             e("<li $class><a href='"
                                 . B\controllerUrl('admin', true)
diff --git a/src/views/elements/ManageaccountElement.php b/src/views/elements/ManageaccountElement.php
index 500364ed6..210eda8da 100755
--- a/src/views/elements/ManageaccountElement.php
+++ b/src/views/elements/ManageaccountElement.php
@@ -174,20 +174,6 @@ class ManageaccountElement extends Element
                     class="narrow-field"/></td></tr>
             <?php
             if (isset($data['EDIT_USER'])) {
-                if (!empty($data['yioop_store'])) {
-                    ?>
-                    <tr><th class="table-label"><label for="uses_store"><?php
-                    e(tl('manageaccount_element_enable_store'));
-                    ?></label></th>
-                    <td><input type="checkbox" id="uses_store"
-                        name="USES_STORE" value="true"
-                        <?php if (isset($data['USER']['USES_STORE'])) {
-                            if ($data['USER']['USES_STORE'] == 1) {
-                                e("checked='checked'");
-                            }
-                        }?>/>
-                    </td></tr><?php
-                }
                 if (!empty($data['yioop_bot_configuration'])) {
                     ?>
                     <tr>
diff --git a/src/views/elements/ManagegroupsElement.php b/src/views/elements/ManagegroupsElement.php
index d2449c545..8b392ee57 100755
--- a/src/views/elements/ManagegroupsElement.php
+++ b/src/views/elements/ManagegroupsElement.php
@@ -72,6 +72,9 @@ class ManagegroupsElement extends Element
                 $this->renderSearchForm($data);
                 break;
             case "statistics":
+                if (!C\GROUP_ANALYTICS_MODE || C\GROUP_ANALYTICS_MODE == "0") {
+                    return;
+                }
                 $this->renderGroupStatistics($data);
                 if ($_SERVER["MOBILE"]) { ?>
                     <div class="clear">&nbsp;</div><?php
@@ -79,6 +82,9 @@ class ManagegroupsElement extends Element
                 e("</div>"); // close current-activity div
                 return;
             case "graphstats":
+                if (!C\GROUP_ANALYTICS_MODE || C\GROUP_ANALYTICS_MODE == "0") {
+                    return;
+                }
                 $this->renderGraphStats($data);
                 if ($_SERVER["MOBILE"]) { ?>
                     <div class="clear">&nbsp;</div><?php
@@ -246,8 +252,10 @@ class ManagegroupsElement extends Element
                             tl('managegroups_element_num_users',
                             $group['NUM_MEMBERS'])."]");
                         }
-                        if ($is_root ||
-                            $group['OWNER_ID'] == $_SESSION['USER_ID']) {
+                        if (($is_root ||
+                            $group['OWNER_ID'] == $_SESSION['USER_ID']) &&
+                            C\GROUP_ANALYTICS_MODE &&
+                            C\GROUP_ANALYTICS_MODE != "0") {
                             ?><br />[<a href="<?=$statistics_url .
                                 'group_id='.
                                 $group['GROUP_ID'].'&amp;user_id=' .
@@ -904,22 +912,22 @@ class ManagegroupsElement extends Element
                             "</p>");
                     } else {
                         if ($time_period == C\ONE_HOUR ||
-                           $time_period == C\FOREVER || C\DIFFERENTIAL_PRIVACY) {
+                           $time_period == C\FOREVER ||
+                           C\DIFFERENTIAL_PRIVACY) {
                             e("<p><b>$period_heading</b>: ".
                                 $data['STATISTICS'][$field]
                                 [$time_period][0]['NUM_VIEWS'].
                                 "</p>");
-                        }
-                        else {
-                        e("<p><b>$period_heading</b>:
-                            <a href='" . $graph_stats_url .
-                            "&amp;impression=" . $field .
-                            "&amp;time=" . $time_period .
-                            "&amp;item=" . $data['STATISTICS'][$field]
-                            [$time_period][0]['ID']."'> ".
-                            $data['STATISTICS'][$field]
-                            [$time_period][0]['NUM_VIEWS'].
-                            "</a></p>");
+                        } else {
+                            e("<p><b>$period_heading</b>:
+                                <a href='" . $graph_stats_url .
+                                "&amp;impression=" . $field .
+                                "&amp;time=" . $time_period .
+                                "&amp;item=" . $data['STATISTICS'][$field]
+                                [$time_period][0]['ID']."'> ".
+                                $data['STATISTICS'][$field]
+                                [$time_period][0]['NUM_VIEWS'].
+                                "</a></p>");
                         }
                     }
                 } else {
@@ -929,7 +937,8 @@ class ManagegroupsElement extends Element
                         foreach ($data['STATISTICS'][$field][
                             $time_period] as $item_name => $item_data) {
                             if ($time_period == C\ONE_HOUR ||
-                                $time_period == C\FOREVER || C\DIFFERENTIAL_PRIVACY) {
+                                $time_period == C\FOREVER ||
+                                C\DIFFERENTIAL_PRIVACY) {
                                 e("<p>$item_name: ". $item_data[0]['NUM_VIEWS'].
                                 "</p>");
                             } else {
@@ -1064,6 +1073,6 @@ class ManagegroupsElement extends Element
             <td><?= $total_view ?></td>
         </tr>
         </table>
-    <?php
+        <?php
     }
 }
ViewGit