2. Files & Coding

2.1 Structure of files

2.1.1 PHP Files

Main files of the script phpRegister:

php strucuture files of the phpRegister script

When starting a new page or a new aJax php file, you must define first the constant _PATHROOT.

This constant define how many subdirectories before the root directory, for example define(_PATHROOT, '../');for the file index.php in the directory contact/.

Example of the constant _PATHROOT needed in a functon of global.inc.php:



    
    

2.1.2 CSS Files

CSS files for your page must be in the folder incude/css/ with a name with the version number separated by a "-". Example:

mypage-1.10.css

To insert css files in your webpage, initialize the variable $cssFiles with the function get__cssFiles, example:


    

In this example, it will insert automatically all css files from the folder incude/css/ with the names starting with navbar, main and mypage through the function show__header() from the required file display_global.inc.php.
When you edit these css files, to prevent css caching by browsers, modify the version number and the newest version will be selected by the function get__cssFiles.
You can have in your folder include/css different versions, for example mypage-1.10.css, mypage-1.11.css and mypage-1.12.css, the function will recover the version 1.12.

2.1.3 Javascript through PHP variables

Sometimes, php scripts can generate some JavaScript, therefor the choice of not using javascript files has been selected. Instead of files, the phpRegister script uses php global variables in which the javascript is inserted.
Then the content of these variables is displayed in the DOM at the end of the page through the function show__end().

These variables are:

  • $jsWindowLoaded
  • $jsScripts
  • $jsWindowResize

Also, this solution allows us to be faster in coding page. You just have to refresh the page to debug the Javascript.


Using $jsWindowLoaded

All the content of the PHP global variable $jsWindowLoaded will be inserted at the end of the DOM in the Javascript event $(window).load(function() {...}, example:



    

Using $jsScripts

All the content of the PHP global variable $jsScripts will be inserted at the end of the DOM in the tags <script> ... </script>, example:



    

Using $jsWindowResize

The content of the PHP global variable will be called on Window resize $(window).resize(function(){ ... } . This is usefull for example for resizing a Bootstrap Modal through a function:


    
    

2.1.3 Javascript in .js files

phpRegister script can manage as well JS files in the same way of CSS files with versioning to get most recent JS file.

JS files for your page must be in the folder incude/js/ with a name with the version number separated by a "-". Example:

mypage-1.10.js

To insert js files in your webpage, initialize the variable $jsFiles with the function get__jsFiles, example with the sample page coming with a JS file:


    

To insert in the DOM several JS files:


    

Result in the DOM with this example:



    
    

2.2 Coding

2.2.1 Inserting JS/CSS plugins

Plugins may be inserted in the DOM with the global variables $cssPlugins and $jsPlugins which are an array.

The files of the plugins may be on your own server in the directory include/plugins/css and include/plugins/js or may be included from CDN using //.
You can create new folders in the directories css or js to organize your plugins.

Example:


    

Result in the DOM with this example:



    
    

2.2.2 Admin rights

Admin rights are specified in the config file config.inc.php. To add, modify or delete rights, this config file must be edited.

Default available Admin rights:


    

List of admin rights can be checked from the Admin section:
User Accounts > Preferences > Admin rights description

List of admin rights

The global function check__adminRights() allows to check if the current user has the needed privileges for an action.

Examples:

  • Checking if current user has any privileges in home part of the Admin section in the file index.php:
    
                
  • Checking if privileges allow to display link to access to the User Accounts part from the file admin_display.inc.php:
    
                
  • Checking if privileges allow to delete an account from the file ajax_accounts_delete.php in the Admin section (security check):
    
                If the user does not have enough privilege, the script exits. No user is deleted.
                

2.2.3 Sending email

The phpRegister script comes with a set functions for easy of sending well formatted emails.
To use the phpRegister functions to send an emai, the file email_global_send.php must be first required:


    

The global variable $configEmail will be used to set the email options (To, From, ReplyTo, BCC, Subject, Body).

By default, if the option From is not set, it will use the value of $config['EmailContact'] from the config file config.inc.php

Examples:

  • Minimum send options:
    
                
  • All send options:
    
                

By default, there are 3 display templates for emails. The main and default template is function email__templateBase(), example:

List of admin rights

This templateBase contains boxes which may be text boxes or button boxes.

Example with creating a file test-email.php in directory sample/:


    

An example that let you test an email layout with theses boxes may be found in include/php/emails/displaytest/index.php.

2.2.4 Adding new languages

The phpRegister script comes with a set functions to manage languages. Languages are specified in the config file config.inc.php.
Default phpRegister languages:


    

To add a new language, for example espanol, add it in the config file:


    

Then in langs folders, duplicate the file en.inc.php as es.inc.php and translate it.


    

If the file es.inc.php does not exist, the default language file will be taken.