Settings of the ZnetDK for Mobile Starter Web App
INSTALL_DIR/applications/default/app/config.php
script.
INSTALL_DIR/applications/default/app/lang/locale.php
script.
INSTALL_DIR/.htaccess
script.
The PHP constants defined below can be modified to customize some labels and the navigation menu logo of your Web app.
LC_PAGE_TITLE
, LC_HEAD_TITLE
, LC_FOOTER_LEFT
, LC_FOOTER_CENTER
, LC_FOOTER_RIGHT
, LC_HEAD_IMG_LOGO
LC_PAGE_TITLE
define('LC_PAGE_TITLE', 'My page title');
LC_HEAD_TITLE
define('LC_HEAD_TITLE', 'My App title');
LC_HEAD_IMG_LOGO
define('LC_HEAD_IMG_LOGO', ZNETDK_APP_URI . 'images/mylogo.png');
The following parameters are required to connect your Web App to a MySQL database and so, query data through the \DAO
and \SimpleDAO
ZnetDK classes, both based on the PHP PDO
class.
See Getting Started | Connecting to a database for more information.
CFG_SQL_HOST
, CFG_SQL_PORT
, CFG_SQL_APPL_DB
, CFG_SQL_APPL_USR
, CFG_SQL_APPL_PWD
, CFG_SQL_TRACE_ENABLED
CFG_SQL_HOST
define('CFG_SQL_HOST', 'localhost');
CFG_SQL_PORT
define('CFG_SQL_PORT', '35105');
CFG_SQL_APPL_DB
define('CFG_SQL_APPL_DB', 'mydatabase');
CFG_SQL_APPL_USR
define('CFG_SQL_APPL_USR', 'myuser');
CFG_SQL_APPL_PWD
define('CFG_SQL_APPL_PWD', 'mypassword');
CFG_SQL_TRACE_ENABLED
define('CFG_SQL_TRACE_ENABLED', TRUE);
To limit access to your application to only authorized users, authentication must first be enabled (see CFG_AUTHENT_REQUIRED
PHP constant).
Next, authorized users can be declared via the User Management form.
In addition, user rights on menu items and data can be restricted by adding profiles through the Profile Management form (see Profile management and user rights).
CFG_AUTHENT_REQUIRED
,
CFG_SESSION_DEFAULT_MODE
,
CFG_SESSION_SELECT_MODE
,
CFG_SESSION_TIMEOUT
,
CFG_DEFAULT_PWD_VALIDITY_PERIOD
,
CFG_CHECK_PWD_VALIDITY
,
CFG_FORGOT_PASSWORD_ENABLED
,
CFG_FORGOT_PASSWORD_REQUEST_TRACE_ENABLED
CFG_APPLICATION_VERSION
Parameters to enable user authentication and configure the user session.
See Getting Started | Enabling user authentication for more information.
CFG_AUTHENT_REQUIRED
define('CFG_AUTHENT_REQUIRED', TRUE);
CFG_SESSION_DEFAULT_MODE
define('CFG_SESSION_DEFAULT_MODE', 'public');
CFG_SESSION_SELECT_MODE
define('CFG_SESSION_SELECT_MODE', FALSE);
CFG_SESSION_TIMEOUT
define('CFG_SESSION_TIMEOUT', 5);
CFG_DEFAULT_PWD_VALIDITY_PERIOD
define('CFG_DEFAULT_PWD_VALIDITY_PERIOD', 3);
CFG_CHECK_PWD_VALIDITY
define('CFG_CHECK_PWD_VALIDITY', '/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{12,}$/');
CFG_FORGOT_PASSWORD_ENABLED
config.php
, display of the Forgot your password?link
define('CFG_FORGOT_PASSWORD_ENABLED', TRUE);
forgotpassword.php
, emails sent via a custom app/controller/ForgotPassword
class
<?php
namespace app\controller;
/* PHP script named 'forgotpassword.php' installed into the following directory:
'INSTALL_DIR/applications/default/controller/'
*/
/* PHPMailer is directly installed into the application */
use PHPMailer\PHPMailer\PHPMailer;
require 'app/phpmailer/src/Exception.php';
require 'app/phpmailer/src/PHPMailer.php';
class ForgotPassword extends \AppController {
/* Send email for confirmation */
static public function sendConfirmation($emailAddress, $confirmationUrl) {
$subject = 'Confirm your request for a new password';
$body = "Hello<br>Confirm your request by clicking <a href=\"{$confirmationUrl}\">this link</a>.";
if (!self::sendMail($emailAddress, $subject, $htmlMessage)) {
throw new \Exception('Unable to send email for confirmation!');
}
return TRUE;
}
/* Send password by email after confirmation */
static public function sendNewEmail($emailAddress, $tempPassword) {
$subject = 'Your new temporary password';
$body = "Hello<br>Here is your temporary password: <b>{$tempPassword}</b>";
if (!self::sendMail($emailAddress, $subject, $htmlMessage)) {
throw new \Exception('Unable to send temporary password!');
}
return TRUE;
}
/* Example of private sendMail method based on PHPMailer. Email is sent via PHP mail */
static private function sendMail($emailAddress, $subject, $htmlMessage) {
$mail = new PHPMailer();
$mail->setFrom('admin@example.com');
$mail->addAddress($emailAddress);
$mail->Subject = $subject;
$mail->msgHTML($htmlMessage);
return $mail->send();
}
}
?>
CFG_FORGOT_PASSWORD_REQUEST_TRACE_ENABLED
define('CFG_FORGOT_PASSWORD_REQUEST_TRACE_ENABLED', TRUE);
CFG_APPLICATION_VERSION
define('CFG_APPLICATION_VERSION', 2);
ZnetDK includes in standard a dedicated view to manage the users authorized to access to the Web Application.
To manage users, the following requirements must be fulfilled:
menu.php
of the application to access to the z4musers.php
view (see procedure).To give access to users in the Web Application, follow the procedure Declaring the users.
Rights are generally granted to users though Profiles.
However, if no particular restriction applies to users, then no profile is required. Users must simply be declared with the Menu Access Full option checked.
ZnetDK includes in standard a dedicated view to manage user profiles that can be assigned to users in order to restrict their rights in the Web Application.
To manage profiles, the following requirements must be fulfilled:
menu.php
of the application to access to the z4mprofiles.php
view (see procedure).A profile is generally created to restrict access to menu items in the application. In that case, the Menu Access Full option must be unchecked when assigning the profile to users.
It can also be defined to limit the visibility of the data when it is for some confidential, for example according to the department in the company in which the user works.
A profile can also be used to add specific functionalities to certain users or, on the contrary, to remove particularly sensitive functionalities.
When editing a user, one or several profiles can be assigned to him according to the rights we want to grant him.
The PHP API provides useful methods like \controller\Users::hasProfile()
and \controller\Users::hasMenuItem()
to grant specific rights to users programmatically based on their profiles and the menu items they have access to.
The User panel is displayed when clicking the user icon on the App header.
Only authenticated users have access to the User panel (see CFG_AUTHENT_REQUIRED
parameter).
The following screens are displayed when you click the corresponding User panel button.
When a user logs into the application, if their password has expired (see Expire on
entry field in the Edit a profile form), they are asked to renew it.
To renew their password, users have to enter the following informations:
New passwordfield).
Users can also renew their password before it has expired from the User panel.
Colors, font and logos can be customized through the parameters described below.
See Getting Started | Customizing the Starter Application for more information.
CFG_MOBILE_W3CSS_THEME
, CFG_MOBILE_CSS_FONT
, CFG_MOBILE_CSS_FONT_FAMILY
, CFG_MOBILE_FAVICON_CODE_FILENAME
, CFG_MOBILE_FAVICON_DIR
CFG_MOBILE_W3CSS_THEME
define('CFG_MOBILE_W3CSS_THEME', 'https://www.w3schools.com/lib/w3-theme-blue-grey.css');
CFG_MOBILE_CSS_FONT
define('CFG_MOBILE_CSS_FONT', 'https://fonts.googleapis.com/css?family=Poppins&display=swap');
CFG_MOBILE_CSS_FONT_FAMILY
define('CFG_MOBILE_CSS_FONT_FAMILY', "'Poppins', sans-serif");
CFG_MOBILE_FAVICON_CODE_FILENAME
define('CFG_MOBILE_FAVICON_CODE_FILENAME', 'applications/' . ZNETDK_APP_NAME . '/app/layout/mobile_favicons.php');
CFG_MOBILE_FAVICON_DIR
define('CFG_MOBILE_FAVICON_DIR', 'applications/' . ZNETDK_APP_NAME .'/public/images/favicons');
Additional CSS stylesheets and JavaScript libraries can be loaded for extending the web application capabilities through the following parameters.
CFG_APPLICATION_CSS
define('CFG_APPLICATION_CSS', serialize(array('applications/' . ZNETDK_APP_NAME . '/public/css/myscript.css', 'https://extracsslibrary.net/lib.css')));
CFG_APP_JS
define('CFG_APP_JS', serialize(array('applications/' . ZNETDK_APP_NAME . '/public/js/myscript.js', 'https://extrajslibrary.net/lib.js')));
By default, the Starter App shipped with ZnetDK 4 Mobile is configured to be displayed in English (CFG_DEFAULT_LANGUAGE
parameter set to 'en'
in the config.php
of the application).
The core features of ZnetDK are translated in English, French and Spanish.
To display your Web APP in French, set CFG_DEFAULT_LANGUAGE
to 'fr'
. For a display in Spanish, set CFG_DEFAULT_LANGUAGE
to 'es'
.
To translate your App into a language not translated in standard, for example in Portuguese:
INSTALL_DIR/engine/core/lang/locale_en.php
english core translation script into the INSTALL_DIR/applications/default/app/lang/
folder,locale_en.php
script by changing the en
filename suffix to the ISO 639-1 country code corresponding to your country, in this case to locale_pt.php
.locale_pt.php
script and translate the PHP constant values in Portuguese.INSTALL_DIR/applications/default/app/config.php
PHP script and change the value of the CFG_DEFAULT_LANGUAGE
parameter from en
to 'pt'
.It is also possible to translate a view of the application directly into several languages.
For example, if a view is originally named myview.php
with text displayed in English, then it might be suffixed with its language code (eg myview_en.php
).
This view once translated into Spanish will be named myview_es.php
and the one translated into French will be named myview_fr.php
.
Thus, the view corresponding to the language to be displayed for the application will be chosen automatically by ZnetDK.
Finally, the display of the application can be set to a specific language by reloading it with the ?lang=<iso code>
parameter added to its URL.
For example, to display the application in Spanish: https://mydomain/myapp?lang=es
.
See on the Code Snippets page an example of Multilingual application.
CFG_DEFAULT_LANGUAGE
define('CFG_DEFAULT_LANGUAGE', 'es');
CFG_MULTI_LANG_ENABLED
define('CFG_MULTI_LANG_ENABLED', TRUE);
The locale is used by ZnetDK to display dates and amounts formatted according to the user's language.
The locale can be set globally through the single LC_LOCALE_ALL
PHP constant described below.
However, this implies that the desired locale is installed on the web server.
Alternatively, the locale can be directly customized using the following PHP constants, independently of the locales installed on the web server: LC_LOCALE_DECIMAL_SEPARATOR
, LC_LOCALE_THOUSANDS_SEPARATOR
, LC_LOCALE_NUMBER_OF_DECIMALS
, LC_LOCALE_CURRENCY_SYMBOL
, LC_LOCALE_CURRENCY_SYMBOL_PRECEDE
, LC_LOCALE_CURRENCY_SYMBOL_SEPARATE
, LC_LOCALE_DATE_FORMAT
, LC_LOCALE_CSV_SEPARATOR
LC_LOCALE_ALL
, LC_LOCALE_DECIMAL_SEPARATOR
, LC_LOCALE_THOUSANDS_SEPARATOR
, LC_LOCALE_NUMBER_OF_DECIMALS
, LC_LOCALE_CURRENCY_SYMBOL
, LC_LOCALE_CURRENCY_SYMBOL_PRECEDE
, LC_LOCALE_CURRENCY_SYMBOL_SEPARATE
, LC_LOCALE_DATE_FORMAT
, LC_LOCALE_CSV_SEPARATOR
LC_LOCALE_ALL
define('LC_LOCALE_ALL', serialize(array('fr_FR', 'french', 'fr_FR.utf8')));
LC_LOCALE_DECIMAL_SEPARATOR
define('LC_LOCALE_DECIMAL_SEPARATOR', ',');
LC_LOCALE_THOUSANDS_SEPARATOR
define('LC_LOCALE_THOUSANDS_SEPARATOR', ' ');
LC_LOCALE_NUMBER_OF_DECIMALS
define('LC_LOCALE_NUMBER_OF_DECIMALS', 2);
LC_LOCALE_CURRENCY_SYMBOL
define('LC_LOCALE_CURRENCY_SYMBOL', '€');
LC_LOCALE_CURRENCY_SYMBOL_PRECEDE
define('LC_LOCALE_CURRENCY_SYMBOL_PRECEDE', FALSE);
LC_LOCALE_CURRENCY_SYMBOL_SEPARATE
define('LC_LOCALE_CURRENCY_SYMBOL_SEPARATE', ' ');
LC_LOCALE_DATE_FORMAT
<?php
// ZnetDK version <= 2.7
define('LC_LOCALE_DATE_FORMAT', '%d-%m-%y');
// ZnetDK version >= 2.8
define('LC_LOCALE_DATE_FORMAT', 'd-m-y');
LC_LOCALE_CSV_SEPARATOR
define('LC_LOCALE_CSV_SEPARATOR', ';');
By default, a view is loaded only once on demand, is not removed from the DOM (Document Object Model) when it is hidden, and therefore is not reloaded when it is displayed again on subsequent times.
This behaviour can be changed via the following PHP constants.
CFG_VIEW_PRELOAD
define('CFG_VIEW_PRELOAD', TRUE);
CFG_VIEW_PAGE_RELOAD
define('CFG_VIEW_PAGE_RELOAD', TRUE);
Pictures, documents and other files uploaded by users or generated by the Starter App can be stored within the INSTALL_DIR/applications/default/documents/
private directory whose absolute file path is accessible via the CFG_DOCUMENTS_DIR
PHP constant described below.
CFG_DOCUMENTS_DIR
define('CFG_DOCUMENTS_DIR', '/home/documents');
Controller actions can be exposed as Web Services.
The POST method should be used to call a Web Service. The GET method is reserved for downloading files.
The web service is authenticated through Basic Authentication. A dedicated user is generally declared in the application to call a web service.
For example, to execute the MyController::action_dostuff()
controller action of the Application deployed at https://mydomain.com/mydir/, with the user account wsuser
to authenticate, submit via the POST method the following URL:
https://wsuser:password@mydomain.com/mydir/?control=mycontroller&action=dostuff&my_param=myvalue
See below for PHP constants to configure controller actions to expose as a web service.
CFG_HTTP_BASIC_AUTHENTICATION_ENABLED
define('CFG_HTTP_BASIC_AUTHENTICATION_ENABLED', TRUE);
CFG_ACTIONS_ALLOWED_FOR_WEBSERVICE_USERS
define('CFG_ACTIONS_ALLOWED_FOR_WEBSERVICE_USERS', serialize([
'wsuser|mycontroller:dostuff',
'wsuser|mycontroller:download'
]));
CFG_DOWNLOAD_AS_POST_REQUEST_ENABLED
define('CFG_DOWNLOAD_AS_POST_REQUEST_ENABLED', TRUE);
According to the directory where ZnetDK for mobile is installed, the HTTP Error 403 (access forbidden) and HTTP error 404 (page not found) must be handled properly by adjusting the Apache Web Server ErrorDocument
parameter.
Then, if users attempt to access a page that does not exist or to which access is denied, then they will be automatically redirected to the dedicated ZnetDK HTTP error page.
The view displayed in case of HTTP errors is INSTALL_DIR/engine/core/view/httperror.php
.
This view can be customized after having copied it into the INSTALL_DIR/applications/default/app/view/
folder.
http://mydomain/
For example, your web root directory is /var/www/html/
and so the file path of the .htaccess
file shipped with ZnetDK is /var/www/html/.htaccess
.
Here is below the path to specify for the ErrorDocument
statement in the ZnetDK's .htaccess
file.
.htaccess
(in web server root directory)
ErrorDocument 403 /index.php?control=httperror&action=403
ErrorDocument 404 /index.php?control=httperror&action=404
http://mydomain/mysubdirectory/
For example, your web root directory is /var/www/html/
, the subdirectory is named mysubdirectory/
and so the file path of the .htaccess
file shipped with ZnetDK is /var/www/html/mysubdirectory/.htaccess
.
Here is below the path to specify for the ErrorDocument
statement in the ZnetDK's .htaccess
file.
.htaccess
(in web server subdirectory)
ErrorDocument 403 /mysubdirectory/index.php?control=httperror&action=403
ErrorDocument 404 /mysubdirectory/index.php?control=httperror&action=404
The ZnetDK 4 Mobile Starter Web application is natively configured to be a Progressive Web App.
A default service worker is started when loading the application.
The Starter Web App can be installed on devices with a web browser that supports A2HS feature like Chrome and Safari.
CFG_MOBILE_SERVICE_WORKER_URL
define('CFG_MOBILE_SERVICE_WORKER_URL', 'my-sw.js');
CFG_MOBILE_INSTALL_MESSAGE_DISPLAY_AUTO
define('CFG_MOBILE_INSTALL_MESSAGE_DISPLAY_AUTO', FALSE);
Additionnal application settings are described in this section.
CFG_IS_IN_MAINTENANCE
define('CFG_IS_IN_MAINTENANCE', TRUE);