Contactus – Open Source PHP Address Book

 

 

TABLE OF CONTENTS

Download & License Requirements & Installation What Is “Contactus”?
How To Use For The Developers Common Problems

 

DOWNLOAD & LICENSE

Download Contactus | GitHub | SourceForge

Contactus is released under the MIT License. You are free to use it for your own personal and commercial projects, modify it as you see fit. On the condition that there the software is provided “as-is”. There are no warranties provided and “no strings attached”. Code Boxx and the authors are not liable for any claims, damages, or liabilities.

 

REQUIREMENTS & INSTALLATION

Contactus has not been extensively tested, but it is developed and works on a WAMP8 (Windows Apache MySQL PHP 8) server. Requirements:

  • Apache Mod Rewrite
  • PHP PDO Extension
  • Best to have at least PHP 7

As for the “installation”… There is no installer, but this should be simple enough:

  1. Create a database and import the core/address_book.sql file.
  2. In core/Core.php, change the database settings (A2), and host (A4) to your own.

That’s all. Take note that there is no login system, you might want to add your own login and protection mechanism.

 

 

WHAT IS “CONTACTUS”?

Contactus is a simple, free, and open-source PHP Address Book. It is definitely not the best in the world, but it is at least a complete basic system and should work “out-of-the-box”.

Contactus is also built using pure HTML, CSS, Javascript, and PHP. It has no dependency on any third-party client-side frameworks such as jQuery, Angular, Bootstrap, or Symfony. This should also help developers to quickly build on – No need to learn any additional frameworks, no added script bloating.

 

HOW TO USE

STRAIGHTFORWARD AS CAN BE

Yep – Contactus is “Captain Obvious straightforward”. Just manage your contacts with add/edit/delete. That’s all.

 

EXPORT TO CSV & QR VCARD

Contactus is also capable of exporting the address book in CSV format, as well as generating QR vcards.

 

 

FOR THE DEVELOPERS

As simple as it may be, going through the entire system is still going to take some time. So instead of “explaining line-by-line”, here is a condensed version of “how to quickly customize and upgrade Contactus”.

 

FOLDER STRUCTURE

  • core/ Holds the libraries and API files.
  • pages/ The HTML pages
  • public/ Javascript, CSS, images, whatever public assets.

Yes, there are only 3 folders in the entire system.

 

DATABASE TABLE

address_book – The address book. Doh.
Field Description
id Contact ID, primary key, auto-increment.
name_first First name.
name_last Last name.
email Email.
tel_work Work telephone number.
tel_home Home telephone number.
tel_mob Mobile telephone number.
address Address.

 

 

DEVELOPING CONTACTUS

Contactus is actually a variant of Core Boxx. If you want to modify or improve it, it’s a 4 steps process.

STEP 1) CREATE/MODIFY DATABASE TABLES

Add your new tables, modify the existing ones.

 

STEP 2) ADD/UPDATE SYSTEM MODULE

Create a core/LIB-Module.php, define class Module, add functions inside. For example, to add a new report module – Create core/LIB-Report.php.

core/LIB-Report.php
class Report {
  function getAll ($id) {
    return $this->core->fetchAll(
      "SELECT * FROM `address_book` ORDER BY `name_first` DESC",
      [$id]
    );
  }
}

That’s it. The new module can now be loaded via $_CORE->load("Report") and the new function can be accessed via $_CORE->Report->getAll().

 

STEP 3) ADD/UPDATE API ENDPOINT (OPTIONAL)

Create core/API-Module.php. For example, core/API-Report.php can be accessed at http://site.com/api/Report. How the API work is simple, we just send a $_POST['req'] followed by the required parameters.

core/API-Report.php
// (A) API REQUESTS
$_CORE->load("Report");
if (isset($_POST['req'])) { switch ($_POST['req']) {
  // (A0) INVALID
  default:
    $_CORE->respond(0, "Invalid request");
    break;
 
  // (A1) GET ALL
  case "getAll":
    $records = $_CORE->Report->getAll();
    $_CORE->respond(1, "OK", $records);
    break;
}}

That’s all. We can now send $_POST['reqT']="getAll" to http://site.com/api/Report to fetch the report in a JSON-encoded string.

 

STEP 4) ADD/UPDATE HTML CSS JAVASCRIPT

Add new pages with pages/PAGE-name.php. For example, pages/PAGE-report.php will be accessed from http://site.com/report. That’s about it. Just reverse engineer and copy from the existing libraries, API, and pages… You will see the development pattern here.

 

 

COMMON PROBLEMS & FIXING THEM

Contactus is “not working”? Here are a few of the common problems and how to “fix” them.

 

MIGRATED TO A NEW DOMAIN

  • Simply update URL_BASE in core/Core.php.
  • Delete .htaccess.

Done. The system will regenerate a new one. If you have some extra URL rewrite to add – Go ahead and modify __construct() in core/LIB-Core.php.

 

NOT WORKING. DON’T KNOW WHY.

Update public/common.js section E1 – opt.debug = true. Reload the page and see the error message.

How To Debug Javascript – A Very Simple Guide

How to Debug PHP Code – A Very Simple Guide

Leave a Comment

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