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.
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.
Please click on the following image to watch the demo:

[hidepost]
-
Open your ewcfg.php file, and find this code:
// General
before that line, insert this following code:
// Begin of modification by Masino Sinaga, for Maintenance mode, August 30, 2011 define("EW_MAINTENANCE_MODE", FALSE, TRUE); // Set the second parameter to TRUE if you want to display your website in Maintenance Mode define("EW_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("EW_MAINTENANCE_TEXT", "", TRUE); // Just for displaying maintenance message to user with admin level, nothing else! define("EW_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 by Masino Sinaga, for Maintenance mode, August 30, 2011 -
Open your C:\Program Files\PHPMaker8\languages\english.xml file, and find this code:
</global>
before that line, insert this 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="Days" value="day(s)"/> <phrase id="Hours" value="hour(s)"/> <phrase id="Minutes" value="minute(s)"/> <phrase id="Seconds" value="second(s)"/> <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 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="Days" value="hari"/> <phrase id="Hours" value="jam"/> <phrase id="Minutes" value="menit"/> <phrase id="Seconds" value="detik"/> <phrase id="MaintenanceEndWarning" value="Akhir dari waktu Pemeliharaan haruslah lebih besar dari waktu saat ini."/>
-
Open your template.php file, and find this code:
<!--##=SYSTEMFUNCTIONS.CSSFile##-->
before that line, insert this following code:
<?php if (EW_MAINTENANCE_MODE) { ?> <?php if (EW_MAINTENANCE_TEXT!="") { ?> <span class="Maintenance"><?php echo EW_MAINTENANCE_TEXT; ?></span> <?php } ?> <?php } ?> -
Next, go to your PHPMaker application, and click on HTML tab, then click on Styles sub-tab, and then click on the Edit styles button, and there will be a CSS Editor window appears. Scroll down the textbox area to the bottom, and you will find this code:
/*END_USER_STYLES*/
before that line, insert this following code:
.Maintenance { background-color: #F3F8F7; color: #000000; padding: 0.5em; border-left: 1px solid #7EACB1; border-right: 1px solid #7EACB1; border-top: 1px solid #7EACB1; border-bottom: 1px solid #7EACB1; text-align: left; font-family: verdana; /* font name */ font-size: 9pt; /* font size */ display: block; }afterwards click on OK button to close that window.
-
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, there are two tabs appear. They are: Fields and Server Events/Client Scripts. Click on the Server Events/Client Scripts tab, and then click on Server Events -> Global -> All Pages -> Page Loading. Copy and paste this following code inside the Page_Loading function:
global $Security; global $Language; if (EW_MAINTENANCE_MODE==TRUE) { $date_now = date("Y-m-d H:i:s"); $date_end = EW_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 (EW_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> </head>'; echo $cssfile; echo '<div class="Maintenance">'.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> </head>'; echo $cssfile; echo '<div class="Maintenance">'.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> </head>'; echo $cssfile; echo '<div class="Maintenance">'.ew_JsEncode($Language->Phrase("MaintenanceUserMessageUnknown")).' <br><a href="logout.php">'.$Language->Phrase("GoBack").'</a></div>'; exit; } } } 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 (EW_AUTO_NORMAL_AFTER_MAINTENANCE==TRUE) { } else { // We are using this, in order to avoid the css conflict, so we use constant help just for admin! @define("EW_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("EW_MAINTENANCE_TEXT", ew_JsEncode($Language->Phrase("MaintenanceAdminMessage")).' '.Duration(date("Y-m-d H:i:s"), $date_end).'<br><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("EW_MAINTENANCE_TEXT", ew_JsEncode($Language->Phrase("MaintenanceAdminMessage")).' ', FALSE); } } } } -
Next step, still in your that section, click on the Global Code that belongs to the Server Events section, and copy paste this following code to the right pane:
function Duration($parambegindate, $paramenddate) { global $Language; $begindate = strtotime($parambegindate); $enddate = strtotime($paramenddate); $diff = intval($enddate) - intval($begindate); $diffday = intval(floor($diff/86400)); $modday = ($diff%86400); $diffhour = intval(floor($modday/3600)); $diffminute = intval(floor(($modday%3600)/60)); $diffsecond = ($modday%60); if ($diffday==0) { return round($diffhour)." ".$Language->Phrase('hours'). ", ".round($diffminute,0)." ".$Language->Phrase('minutes'). ", ".round($diffsecond,0)." ".$Language->Phrase('seconds').""; } else { return round($diffday)." ".$Language->Phrase('days'). ", ".round($diffhour)." ".$Language->Phrase('hours'). ", ".round($diffminute,0)." ".$Language->Phrase('minutes'). ", ".round($diffsecond,0)." ".$Language->Phrase('seconds').""; } } - Re-generate your script files!
[/hidepost]
Leave a Reply
You must be logged in to post a comment.