Core Boxx – Mail Pagination Settings

TABLE OF CONTENTS

 

FILES CONFIG NOTES

Files and config list for this module, and some notes (if any).

 

FILES LIST

  • lib/LIB-Mail.php Email module.
  • lib/LIB-Page.php Pagination module.
  • lib/LIB-Settings.php Settings Module.

 

 

EMAIL MODULE

This email library uses the default PHP mail(). Feel free to rebuild the entire library if you want to use other libraries such as PHPMailer.

 

A FEW NOTES

  • Change EMAIL_FROM in the settings database table if you want to change the “email from”.
  • Beginners, if your “email is not working” – Check out this tutorial.

 

BASIC SEND MAIL

// (A) BASIC SEND
$_CORE->load("Mail");
echo $_CORE->Mail->send([
  "from" => "sys@site.com", // optional
  "to" => "job@doe.com",
  "cc" => "joe@doe.com", // optional
  "bcc" => "jon@doe.com", // optional
  "subject" => "Test Email",
  "body" => "This is a <strong>TEST</strong> email",
  "attach" => "PATH/IMAGE.JPG" // optional
]) ? "OK" : $_CORE->error ;

// (B) TO, CC, BCC CAN ALSO BE AN ARRAY OF EMAIL
// "to" => ["jac@doe.com", "jan@doe.com", "jay@doe.com"]
 
// (C) ATTACH CAN ALSO BE AN ARRAY OF FILES
// "attach" => ["FILE-1", "FILE-2"]

Yep, send() is all you need. The bare minimum is to specify the to, subject, and body.

 

 

EMAIL WITH HTML TEMPLATE

HTML Template
<html><body>
  <h1>Welcome!</h1>
  <p>Thank you for joining <?=$name?>. Here is your discount code <?=$code?></p>
</body></html>
Use HTML Template
$_CORE->Mail->send([
  "from" => "sys@site.com",
  "to" => "Jon@doe.com",
  "subject" => "Welcome",
  "template" => "template.php",
  "vars" => ["name"=>"Jon", "code"=>"123ABC"]
]);

Take note, if body and template exist at the same time, template will take precedence.

 

PAGINATION MODULE

Pagination is a 2 steps process. First, you will have to feed the total number of entries and the current page into $_CORE->paginator(TOTAL, NOW). Then, use $_CORE->page to build your pagination.

 

PAGINATION EXAMPLE

DUMMY LIBRARY
class Dummy extends Core {
  function get ($page=1) {
    // (A) FEED TOTAL NUMBER OF ENTRIES & CURRENT PAGE INTO PAGINATOR
    $this->Core->paginator(
      $this->DB->fetchCol("SELECT COUNT(*) FROM `TABLE`"), $page
    );

    // (B) USE CALCULATED LIMITS TO RESTRICT ENTRIES
    return $this->DB->fetchAll(
      "SELECT * FROM `TABLE`" . $this->Core->page["lim"]
    );
  }
}
PHP AJAX HANDLER
<?php
// (A) GET ENTRIES
$_CORE->autoCall("Dummy", "get");
 
// (B) DRAW HTML LIST
foreach ($entries as $e) { ... }
 
// (C) DRAW PAGINATION
// THIS WILL DRAW <A ONCLICK="GO(N)">N</A>
$_CORE->load("Page");
$_CORE->Page->draw("go");
HTML PAGE
<!-- (A) EMPTY DIV CONTAINER -->
<div id="demo"></div>
 
<!-- (B) AJAX LOAD ENTRIES -->
<script> 
function go (pg) {
  cb.load({
    page : "AJAX-HANDLER-ABOVE",
    target : "demo",
    data : { page : pg }
  });
}
window.onload = () => go(1);
</script>

 

 

BUILD YOUR OWN PAGINATION

  • No hard rules that you must use the “default” lib/LIB-Page.php.
  • Go ahead and modify $_CORE->Page->draw() if you don’t like it.
  • Or build your own pagination library, use $_CORE->page to help you.
    • $_CORE->page["total"] Total number of pages.
    • $_CORE->page["now"] Current page.

 

SETTINGS MODULE

Not to be confused. Keep critical config in CORE-Config.php, use this module to allow administrators to change the not-so-critical aspects of the system.

 

SETTINGS TABLE

Field Description
setting_name Primary key. More like setting key, that is, define(SETTING_NAME, SETTING_VALUE).
setting_description Short description of this setting.
setting_value The setting value.
setting_group Setting group.

This table should be pretty self-explanatory in most parts, except for the group. Use the group to help you organize the settings, and load the group only when required.

  • Group 0 – Use this to keep track of your app version.
  • Group 1 – System-wide settings. This group is loaded by default during $_CORE->load("Settings").
  • The rest is up to you. For example, use group 2 to keep settings pertaining to API calls. Group 3 for settings for a certain module. Load the group settings only during API calls, or when the module is loaded.

 

 

SETTINGS LIBRARY FUNCTIONS

function __construct ()
Loads and sets all settings from the database with setting_group=1.
function defineG ($group)

Get all group settings from the database and run PHP define(NAME, VALUE).

  • $group – Integer, group ID.
$_CORE->Settings->defineG(1);
function defineN ($name)

Get specified settings from the database and run PHP define(NAME, VALUE).

  • $name – String, setting name. Or an array of setting names.
$_CORE->Settings->defineN("PAGE_PER");
$_CORE->Settings->defineN(["SETTINGA", "SETTINGB"]);
function getAll ($group=1)

Get all settings in the specified group.

  • $group – Integer, group ID.
$settings = $_CORE->settings->get();
function save ($setting)

Save the given settings.

  • $settings – Array, in the format of [NAME => VALUE, NAME => VALUE].
$CORE->settings->save([
  "EMAIL_FROM" => "jon@doe.com",
  "PAGE_PER" => 30
]);

Leave a Comment

Your email address will not be published. Required fields are marked *