Forum

The great place to discuss topics with other users

Sngine Do Not Sell/Share My Data Addon for you.

'
Join the Conversation Στέλνω απάντηση
Edy Lee
Admin
Joined: 2024-11-24 00:57:42
2025-09-27 00:18:43

Installation

  1. Upload the contents of the zip into your Sngine root directory.

    • includes/ajax/do_not_sell.php

    • content/themes/yourtheme/templates/_do_not_sell.tpl

    • install.sql

  2. Run install.sql on your MySQL database to add the new column:

     
    ALTER TABLE users ADD COLUMN do_not_sell TINYINT(1) NOT NULL DEFAULT 0;
     
    • In your theme footer template (_footer.tpl), include the modal:

       
      {include file="_do_not_sell.tpl"}
    • Clear cache and refresh your site.

    1. Database Update

    Extend install.sql:

     
    ALTER TABLE users ADD COLUMN allow_ads TINYINT(1) NOT NULL DEFAULT 1;

    (Defaults to 1 so personalized ads are allowed until user opts out.)


    2. Update Modal Template (_do_not_sell.tpl)

    Replace your modal content with this:

     
    <!-- Do Not Sell or Share My Personal Data --> <a href="#" id="dns-trigger" class="small text-muted">Privacy & Data Preferences</a> <div id="dns-overlay" class="dns-overlay" role="dialog" aria-modal="true" aria-labelledby="dns-title"> <div class="dns-modal" role="document"> <button class="dns-close" id="dns-close">&times;</button> <h2 id="dns-title">Privacy & Data Preferences</h2> <!-- Do Not Sell --> <h5>Do Not Sell or Share My Personal Data</h5> <p> By choosing this option, you are requesting that {$system['system_title']} does not sell or share your personal information. </p> <div class="dns-actions mb-3"> <button class="btn btn-primary w-100" id="dns-confirm">Do Not Sell or Share My Data</button> </div> <hr> <!-- Personalized Ads --> <h5>Personalized Advertising</h5> <p> To enable personalized advertising (like interest-based ads), we may share your data with our marketing and advertising partners using cookies and other technologies. Those partners may have their own information they've collected about you. </p> <p> Turning off this setting won't stop you from seeing ads, but it may make the ads you see less relevant or more repetitive. </p> <p class="text-muted small"> Personalized advertising may be considered a "sale" or "sharing" of information under California and other state privacy laws. Learn more in our <a href="{$system['system_url']}/privacy">Privacy Policy</a>. </p> <div class="form-check mb-3"> <input class="form-check-input" type="checkbox" id="allow-ads" {if $user->_data['allow_ads']}checked{/if}> <label class="form-check-label" for="allow-ads"> Allow personalized advertising </label> </div> <div class="dns-actions"> <button class="btn btn-light" id="dns-cancel">Cancel</button> <button class="btn btn-primary" id="ads-save">Save Preferences</button> </div> </div> </div>

    3. Update JavaScript (inside _do_not_sell.tpl)

    Extend the script:

     
    <script> $(function() { var overlay = $("#dns-overlay"); $("#dns-trigger").on("click", function(e) { e.preventDefault(); overlay.addClass("active"); }); $("#dns-close, #dns-cancel").on("click", function() { overlay.removeClass("active"); }); // Do Not Sell / Share $("#dns-confirm").on("click", function() { $.post(site_ajax + "/do_not_sell.php", {action: "optout"}, function(response) { if(response.success) { alert("Your preference has been saved."); } else { alert("Something went wrong. Please try again."); } overlay.removeClass("active"); }, "json"); }); // Personalized Ads $("#ads-save").on("click", function() { var allow_ads = $("#allow-ads").is(":checked") ? 1 : 0; $.post(site_ajax + "/do_not_sell.php", {action: "ads", allow_ads: allow_ads}, function(response) { if(response.success) { alert("Your ad preference has been updated."); } else { alert("Something went wrong. Please try again."); } overlay.removeClass("active"); }, "json"); }); }); </script>

    4. Update AJAX Handler (do_not_sell.php)

     
    <?php require('../../../bootstrap.php'); // check ajax request is_ajax(); // user must be logged in if(!$user->_logged_in) { return_json(array('success' => false, 'message' => "Login required")); } try { switch ($_POST['action']) { case "optout": $db->query(sprintf("UPDATE users SET do_not_sell = 1 WHERE user_id = %s", secure($user->_data['user_id'], 'int'))); return_json(array('success' => true)); break; case "ads": $allow_ads = ($_POST['allow_ads'] == 1) ? 1 : 0; $db->query(sprintf("UPDATE users SET allow_ads = %s WHERE user_id = %s", secure($allow_ads, 'int'), secure($user->_data['user_id'], 'int'))); return_json(array('success' => true)); break; default: return_json(array('success' => false)); } } catch (Exception $e) { return_json(array('success' => false, 'message' => $e->getMessage())); }
Edy Lee
Admin
Joined: 2024-11-24 00:57:42
2025-09-28 17:19:50

https://scriptstribe.com/downloads.php?id=926

 

or 

1. Admin Template (admin.privacy.tpl)

 
{include file='__header.tpl'} <div class="card"> <div class="card-header with-icon"> <i class="fa fa-user-shield mr10"></i>User Privacy Preferences </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-striped table-bordered table-hover"> <thead> <tr> <th>ID</th> <th>User</th> <th>Email</th> <th>Do Not Sell</th> <th>Allow Ads</th> <th>Actions</th> </tr> </thead> <tbody> {foreach $rows as $row} <tr> <td>{$row.user_id}</td> <td>{$row.user_firstname} {$row.user_lastname}</td> <td>{$row.user_email}</td> <td>{if $row.do_not_sell}Yes{else}No{/if}</td> <td>{if $row.allow_ads}Yes{else}No{/if}</td> <td> <a href="{$system['system_url']}/admin/privacy.php?edit={$row.user_id}" class="btn btn-sm btn-primary"> Edit </a> </td> </tr> {/foreach} </tbody> </table> </div> </div> </div> {include file='__footer.tpl'}
 
 

2. Admin Controller (admin/privacy.php)

 
<?php require('../../bootstrap.php'); require('../../includes/admin.php'); // check admin permission if(!$user->_is_admin) { _error(404); } try { if(isset($_GET['edit'])) { // fetch user $user_id = secure($_GET['edit'], 'int'); $get_user = $db->query("SELECT * FROM users WHERE user_id = '{$user_id}'") or _error("SQL_ERROR"); if($get_user->num_rows == 0) { _error(404); } $user_data = $get_user->fetch_assoc(); // update if($_POST) { $do_not_sell = isset($_POST['do_not_sell']) ? 1 : 0; $allow_ads = isset($_POST['allow_ads']) ? 1 : 0; $db->query("UPDATE users SET do_not_sell = '{$do_not_sell}', allow_ads = '{$allow_ads}' WHERE user_id = '{$user_id}'") or _error("SQL_ERROR"); return_json(array('success' => true, 'message' => 'User privacy settings updated')); } // show edit form $smarty->assign('user_data', $user_data); page_header("Edit Privacy - " . $user_data['user_firstname']); $smarty->display('admin.privacy_edit.tpl'); exit; } // list all $rows = $db->query("SELECT user_id, user_firstname, user_lastname, user_email, do_not_sell, allow_ads FROM users ORDER BY user_id DESC") or _error("SQL_ERROR"); $smarty->assign('rows', $rows->fetch_all(MYSQLI_ASSOC)); page_header("User Privacy Preferences"); $smarty->display('admin.privacy.tpl'); } catch (Exception $e) { _error(__("Error"), $e->getMessage()); }
 
 

3. Edit Form Template (admin.privacy_edit.tpl)

 
{include file='__header.tpl'} <div class="card"> <div class="card-header with-icon"> <i class="fa fa-edit mr10"></i>Edit Privacy Settings for {$user_data.user_firstname} </div> <div class="card-body"> <form method="post" id="edit-privacy-form"> <div class="form-group"> <label> <input type="checkbox" name="do_not_sell" {if $user_data.do_not_sell}checked{/if}> Do Not Sell / Share Personal Data </label> </div> <div class="form-group"> <label> <input type="checkbox" name="allow_ads" {if $user_data.allow_ads}checked{/if}> Allow Personalized Ads </label> </div> <button type="submit" class="btn btn-primary">Save Changes</button> </form> </div> </div> <script> $("#edit-privacy-form").submit(function(e){ e.preventDefault(); $.post(window.location.href, $(this).serialize(), function(response){ if(response.success) { alert(response.message); window.location = "{$system['system_url']}/admin/privacy.php"; } else { alert(response.message); } }, "json"); }); </script> {include file='__footer.tpl'}
 
 

4. Admin Menu Integration

Add to includes/admin.php under Users:

 
$menu['users'][] = array( 'url' => $system['system_url'].'/admin/privacy.php', 'title' => "Privacy Preferences", 'icon' => "fa fa-user-shield" );
 
 
This way, admins can view all users’ preferences and edit individual users’ “Do Not Sell” and “Allow Ads” settings.
Edy Lee
Admin
Joined: 2024-11-24 00:57:42
2025-09-28 17:24:34

https://scriptstribe.com/downloads.php?id=927 v4

 

optional code

Here’s the updated admin widget template code that includes a Chart.js pie chart for user privacy stats in your Sngine admin panel.


content/themes/default/templates/admin.privacy_stats.tpl

 
<div class="row"> <div class="col-sm-4"> <div class="stat-panel bg-warning"> <div class="stat-cell"> <i class="fa fa-user-slash bg-icon"></i> <span class="text-xlg">{$privacy.do_not_sell}</span><br> <span class="text-lg">Do Not Sell Enabled</span><br> <span class="text-bg">Users who opted out</span> </div> </div> </div> <div class="col-sm-4"> <div class="stat-panel bg-success"> <div class="stat-cell"> <i class="fa fa-bullseye bg-icon"></i> <span class="text-xlg">{$privacy.allow_ads}</span><br> <span class="text-lg">Ads Allowed</span><br> <span class="text-bg">Users allowing personalized ads</span> </div> </div> </div> <div class="col-sm-4"> <div class="stat-panel bg-danger"> <div class="stat-cell"> <i class="fa fa-ban bg-icon"></i> <span class="text-xlg">{$privacy.disallow_ads}</span><br> <span class="text-lg">Ads Disabled</span><br> <span class="text-bg">Users who opted out of ads</span> </div> </div> </div> </div> <hr> <div class="card"> <div class="card-header"> <i class="fa fa-chart-pie mr10"></i> Privacy Preferences Overview </div> <div class="card-body"> <canvas id="privacyChart" height="150"></canvas> </div> </div> <!-- Chart.js --> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> <script> document.addEventListener("DOMContentLoaded", function() { var ctx = document.getElementById('privacyChart').getContext('2d'); new Chart(ctx, { type: 'pie', data: { labels: ['Do Not Sell', 'Ads Allowed', 'Ads Disabled'], datasets: [{ data: [{$privacy.do_not_sell}, {$privacy.allow_ads}, {$privacy.disallow_ads}], backgroundColor: ['#f0ad4e', '#5cb85c', '#d9534f'] }] }, options: { responsive: true, plugins: { legend: { position: 'bottom' } } } }); }); </script>
 

Open admin/index.php and include the widget:

 
require(__DIR__ . '/widgets/privacy_stats.php');