Many websites created nowadays do not include the maintenance mode feature in order to prevent users login and access the database. This maintenance mode, actually, is very useful whenever you maintain your database periodically and in the same time you do not want your user accessing your website and the database. Imagine if your user login and access to your database while you are maintaining or altering your database structure, what would be happened? The worst possibility is your database will be unstable or your database integrity will not be guaranteed anymore.
Unfortunately, the websites that created with PHPMaker are still not support for the maintenance mode. So this customization will solve the problem. I have successfully added the maintenance mode to the websites created with PHPMaker. Users with Administrator level now can change to the maintenance mode by simply changing the related constant value in your configuration file. In addition, they can also define until the certain date and time in the future this maintenance mode will be displayed in your website. Not until that, they even will be able to define whether this maintenance mode will be automatically switched to the normal mode when the end of maintainance date and time has been reached. This is very useful if you want your web application will automatically switch to the normal mode after the end date/time of maintenance has come.
Users which have level access other than Administrator will not be able to access your web application except for the Login page, whereas users which have level access Administrator will still be able to access the web application but they will see the maintenance mode message at the top of all pages. This condition is very important if Administrator want to ensure that everything is gonna be okay (assuming the database maintenance process has been already finished), and Administrator will be keep reminded that the maintenance mode is still on.
All we have to do is customizing PHPMaker template files and also adding some code into the Server Events of PHPMaker application. In other words, we will not modify the generated script files at all.
Updated on May 30, 2012: This customization has been implemented in PHPMaker version 9.0.2, it matches to each other, and as a result, it works properly.
Updated on July 22, 2012: This customization has been implemented in PHPMaker version 9.0.3, it matches to each other, and as a result, it works properly.
Updated on September 4, 2012: This customization has been implemented in PHPMaker version 9.0.4, it matches to each other, and as a result, it works properly.
Updated on November 28, 2012: This customization has been implemented in PHPMaker version 9.1.0, it matches to each other, and as a result, it works properly.
Updated on February 9, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.
Updated on June 17, 2013: This customization below has been handled by using MasinoFixedWidthSite extension. You don’t need to implement the customization below if you use my extensions together with the original PHPMaker Template and Extension files.
[hidepost]
-
Open your C:\Program Files\PHPMaker 9\languages\english.xml file, and find this code:
</global>
before that line, please insert the following code:
<phrase id="MaintenanceTitle" value="Maintenance"/> <phrase id="MaintenanceUserMessage" value="Sorry, we are doing the database maintenance periodically. <br />The system is unavailable at the moment. <br /> Please come back in "/> <phrase id="MaintenanceUserMessageUnknown" value="Sorry, we are doing the database maintenance periodically. <br />The system is not available at the moment until an undetermined time limit."/> <phrase id="MaintenanceAdminMessage" value="You are in maintenance mode."/> <phrase id="MaintenanceEndWarning" value="End of Maintenance must be greater than the current time."/>Do the same way with your another .xml language file. For example, I am also using Indonesian language, so I add those phrases to my C:\Program Files\PHPMaker 9\languages\indonesian.xml file:
<phrase id="MaintenanceTitle" value="Pemeliharaan"/> <phrase id="MaintenanceUserMessage" value="Maaf, kami sedang melakukan pemeliharaan basis data secara berkala. <br />Sistem tidak dapat digunakan untuk saat ini. <br /> Silahkan kembali lagi dalam "/> <phrase id="MaintenanceUserMessageUnknown" value="Maaf, kami sedang melakukan pemeliharaan basis data secara berkala. <br />Sistem tidak dapat digunakan untuk saat ini sampai batas waktu yang belum diketahui."/> <phrase id="MaintenanceAdminMessage" value="Anda sedang dalam mode pemeliharaan."/> <phrase id="MaintenanceEndWarning" value="Akhir dari waktu Pemeliharaan haruslah lebih besar dari waktu saat ini."/> -
Open your \Script\ewcfg.php file, and find this code:
// General
before that line, please insert the following code:
// Begin of modification Maintenance Mode, by Masino Sinaga, May 12, 2012 define("MS_MAINTENANCE_MODE", FALSE, TRUE); // Set the second parameter to TRUE if you want to display your website in Maintenance Mode define("MS_MAINTENANCE_END_DATETIME", "", TRUE); // Set the second parameter to the future date/time value in "yyyy-MM-dd hh:mm:ss" format, if you want the system calculate how much long the system takes duration time to get the end of maintenance date/time. For example: 2011-08-30 17:28:00 define("MS_MAINTENANCE_TEXT", "", TRUE); // Just for displaying maintenance message to user with admin level, nothing else! define("MS_AUTO_NORMAL_AFTER_MAINTENANCE", TRUE, TRUE); // Set the second parameter to TRUE if you want the system to be automatically switch from the Maintenance Mode to Normal Mode whenever the end of maintenance date/time has been reached. // End of modification Maintenance Mode, by Masino Sinaga, May 12, 2012 -
Open your C:\Program Files\PHPMaker 9\themes\ew.css file, and find this code:
/*END_SYSTEM_STYLES*/
before that line, please insert the following code:
/* maintenance */ .msMaintenance { font-family: Tahoma; /* font name */ font-size: 8pt; /* font size */ background-color: #FFCCCC; background: #FFCCCC url(../phpimages/info.gif) 5px 5px no-repeat; padding: 0.5em; padding-left: 25px; border-left: 1px solid #FFCCCC; border-right: 1px solid #FFCCCC; border-top: 1px solid #FFCCCC; border-bottom: 1px solid #FFCCCC; display: block; } /* maintenance */ -
Open your \Script\template.php file, and find this code:
<!--##=SYSTEMFUNCTIONS.CSSFile()##-->
before that line, please insert the following code:
<?php // Begin of modification Maintenance Mode, by Masino Sinaga, May 12, 2012 ?> <?php $date_now = date("Y-m-d H:i:s"); ?> <?php if ( (MS_MAINTENANCE_MODE==TRUE) && (strtotime(MS_MAINTENANCE_END_DATETIME) < strtotime($date_now)) && (MS_AUTO_NORMAL_AFTER_MAINTENANCE==FALSE) || (MS_MAINTENANCE_MODE==TRUE) && (strtotime(MS_MAINTENANCE_END_DATETIME) > strtotime($date_now)) && (MS_AUTO_NORMAL_AFTER_MAINTENANCE==TRUE) || (MS_MAINTENANCE_MODE==TRUE) && (MS_MAINTENANCE_END_DATETIME=="") ) { ?> <?php if (MS_MAINTENANCE_TEXT!="") { ?> <span class="msMaintenance"><?php echo MS_MAINTENANCE_TEXT; ?></span> <?php } ?> <?php } ?> <?php // End of modification Maintenance Mode, by Masino Sinaga, May 12, 2012 ?> -
Next step, still on your PHPMaker application, click on one of your tables from the left panel, and see in the right panel of your PHPMaker application click on the Code (Server Events, Client Scripts and Custom Templates) tab, and then click on Server Events -> Global -> All Pages -> Page_Loading, and find this code:
global $Security; global $Language;if you have already had that code inside the Page_Loading function, then insert the following code after the last line of that code:
// Begin of modification Maintenance Mode, by Masino Sinaga, May 12, 2012 if (MS_MAINTENANCE_MODE==TRUE) { $date_now = date("Y-m-d H:i:s"); $date_end = MS_MAINTENANCE_END_DATETIME; $cssfile = '<link rel="stylesheet" type="text/css" href="'.EW_PROJECT_STYLESHEET_FILENAME.'">'; if (!$Security->CanAdmin()) { if ((ew_CurrentPage()!="index.php") && (ew_CurrentPage()!="logout.php") && (ew_CurrentPage()!="login.php")) { if ($date_end != "") { // Assuming end of maintenance date/time is valid if ($date_end<=$date_now) { if (MS_AUTO_NORMAL_AFTER_MAINTENANCE==TRUE) { // Normal mode here, just give your user an access! } else { // Still in maintenance mode, and end of date/time not reached yet, even Auto Normal is False echo '<head><title>'.$Language->Phrase("MaintenanceTitle").'</title><meta name="generator" content="PHPMaker v9.0.1"></head>'; echo $cssfile; echo '<div class="msMaintenance">'.ew_JsEncode($Language->Phrase("MaintenanceUserMessageUnknown")).' <br><a href="logout.php">'.$Language->Phrase("GoBack").'</a></div>'; exit; } } else { // Still in maintenance mode, even end of date/time has been reached echo '<head><title>'.$Language->Phrase("MaintenanceTitle").'</title><meta name="generator" content="PHPMaker v9.0.1"></head>'; echo $cssfile; echo '<div class="msMaintenance">'.ew_JsEncode($Language->Phrase("MaintenanceUserMessage")).' '.Duration(date("Y-m-d H:i:s"), $date_end).'<br><a href="logout.php">'.$Language->Phrase("GoBack").'</a></div>'; exit; } } else { // Still in maintenance mode, the date/time value is blank! echo '<head><title>'.$Language->Phrase("MaintenanceTitle").'</title><meta name="generator" content="PHPMaker v9.0.1"></head>'; echo $cssfile; echo '<div class="msMaintenance">'.ew_JsEncode($Language->Phrase("MaintenanceUserMessageUnknown")).' <br><a href="logout.php">'.$Language->Phrase("GoBack").'</a></div>'; exit; } } else { // DO NOTHING HERE !!! if ($date_end != "") { // Assuming end of maintenance date/time is valid if ($date_end<=$date_now) { if (MS_AUTO_NORMAL_AFTER_MAINTENANCE==TRUE) { @define("MS_MAINTENANCE_TEXT", ew_JsEncode($Language->Phrase("MaintenanceUserMessageUnknown")).' <a href="logout.php">'.$Language->Phrase("GoBack").'</a>', FALSE); // Normal mode here, just give your user an access! } else { // Still in maintenance mode, and end of date/time not reached yet, even Auto Normal is False @define("MS_MAINTENANCE_TEXT", ew_JsEncode($Language->Phrase("MaintenanceUserMessageUnknown")).' <a href="logout.php">'.$Language->Phrase("GoBack").'</a>', FALSE); } } else { // Still in maintenance mode, even end of date/time has been reached @define("MS_MAINTENANCE_TEXT", ew_JsEncode($Language->Phrase("MaintenanceUserMessage")).' '.Duration(date("Y-m-d H:i:s"), $date_end).' <a href="logout.php">'.$Language->Phrase("GoBack").'</a>', FALSE); } } else { // Still in maintenance mode, the date/time value is blank! @define("MS_MAINTENANCE_TEXT", ew_JsEncode($Language->Phrase("MaintenanceUserMessageUnknown")).' <a href="logout.php">'.$Language->Phrase("GoBack").'</a>', FALSE); } } } else { // Start from here, Maintenance Mode for Admin! if ((ew_CurrentPage()!="index.php") && (ew_CurrentPage()!="logout.php") && (ew_CurrentPage()!="login.php")) { if ($date_end != "") { // Assuming end of maintenance date/time is valid if ($date_end<=$date_now) { if (MS_AUTO_NORMAL_AFTER_MAINTENANCE==TRUE) { @define("MS_MAINTENANCE_TEXT", ew_JsEncode($Language->Phrase("MaintenanceUserMessageUnknown")).' <a href="logout.php">'.$Language->Phrase("GoBack").'</a>', FALSE); } else { // We are using this, in order to avoid the css conflict, so we use constant help just for admin! @define("MS_MAINTENANCE_TEXT", ew_JsEncode($Language->Phrase("MaintenanceAdminMessage")).' ', FALSE); } } else { // We are using this, in order to avoid the css conflict, so we use constant help just for admin! // Show the remaining time to admin! @define("MS_MAINTENANCE_TEXT", ew_JsEncode($Language->Phrase("MaintenanceAdminMessage")).' '.Duration(date("Y-m-d H:i:s"), $date_end).' <a href="logout.php">'.$Language->Phrase("GoBack").'</a>', FALSE); } } else { // We are using this, in order to avoid the css conflict, so we use constant help just for admin! @define("MS_MAINTENANCE_TEXT", ew_JsEncode($Language->Phrase("MaintenanceAdminMessage")).' ', FALSE); } } } } // End of modification Maintenance Mode, by Masino Sinaga, May 12, 2012 - Finally, re-generate your script files using PHPMaker as always.
[/hidepost]
Leave a Reply
You must be logged in to post a comment.