|
|
|
|
|
|
| |
- Use It to manage your open/close status for your website .
- You can fix your start time for your website /open .
- You can fix your close time for your website /close .
- You can show the time which your website will be avaliable .
- it's easy for using .
download EasyCron :)
readme.txt
| /************************************************************************
=========================================================
| @ Script Name : EasyCron
| @ Version : 1.0
| @ Description : Open and Close your website in fixed times .
| @ All rights reserved to : NaiF PHP
| @ Created In : 8-9-2006
| @ Support Site : http://www.naifphp.net
=========================================================
**************************************************************************/
# ABOUT THIS CLASS :
- Use It to manage your open/close status for your website .
- You can fix your start time for your website /open .
- You can fix your close time for your website /close .
- You can adding more hours for your website to open and close.
- You can show the time which your website will be avaliable .
- it's easy for using .
# ABOUT USING :
- go to make.php to make new cron
- include the EasyCron.php in your website header
- May you need to statement this folder 'easycron' (Chmod) the 777 .
# Notes :
- if you want to use EasyCron in another folder, just use
$obj->cron_path = "path/to/EasyCron";
then add :
include("path/to/easycron/example.php");
in the included page .
for example :
easycorn : "path/to/easycron/example.php"
add this line in example.php :
$obj->cron_path = "path/to/easycron";
you have another folder : "path/to/new_folder/index.php"
add this code in index.php for included cron page :
include("path/to/easycron/example.php");
thanks for you . | |
easycron.class.php
| <?php
/****************************************************************************************
=========================================================================================
| @ Script Name : EasyCron
| @ Version : 1.0
| @ Description : Open and Close your website in fixed times .
| @ All rights reserved to : NaiF PHP
| @ Created In : 8-9-2006
| @ Support Site : http://www.naifphp.net
=========================================================================================
*****************************************************************************************/
class MyEasyCron
{
# Public #
// path to EasyCron.cron
var $cron_path = "./";
// Difference to Greenwich time (GMT) in hours
var $greenwich = "+3"; // 3 for ksa
// time now
var $TimeNow;
// Name's The Day's Weeks , week start with sunday
var $days_of_names = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
// print my copyright with message close , default ( 1 : yes )
var $print_copyright = 1;
# Private #
// day name
var $day_name;
// hour start
var $start_time = 1;
// day number , default error number for day
var $day_number = -1;
//table setup
var $TableHtml;
// for view a 12 culomn
var $Tid = 0;
// table width
var $w_table = 90;
// rows
var $rows = 12;
// <td> width
var $w_td;
function MyEasyCron()
{
$this->cron_path = getcwd();
$this->NowTime = gmdate("G",mktime(date("G") + $this->greenwich,date("i"),date("s"),date("m"),date("d"),date("Y")));
$this->day_name = date("l");
$this->w_td = ceil($this->w_table / $this->rows - 1);
}
# To Show All Times , Convert Time and Author :)
function CronTable()
{
// header
$this->TableHtml = "<html dir=\"ltr\">\r\n\r\n<title> EasyCron 1.0 beta - naifphp </title>\n\r\n";
$this->TableHtml .= "<head>\r\n<script language=\"javascript\" src=\"./EasyCron.js\" type=\"text/javascript\"></script>\r\n</head>\r\n";
$this->TableHtml .= "\r\n<center>\r\n<h2> Please Select time Started Close and Started open site , Of Table :<BR></h2>\r\n</center>\r\n";
$this->TableHtml .= "<table align='center' border='1' width='".$this->w_table."%'>\n<tr><td width='10%'> <b>AM :</b></td>";
for ($i = 1; $i < 25; $i++ )
{
$color = ($i % 2) ? 'EaEaEa' : 'dfdfam';
if ($this->Tid == $this->rows):
$this->TableHtml .= "</tr><tr>\n<td></td>\n</tr><tr>\n<td> <b> PM :</b></td>\n";
$this->Tid = 0;
endif;
$st = $this->start_time++;
$ts_show = (($ts_show >= 12) ? "1" : ($ts_show+1));
$n_m = ($st >= 13) ? 'PM' : 'AM';
$st = ($st > 23) ? "0" : $st;
$ts_view = ($st == $this->NowTime) ? "<font color=\"red\">". $ts_show ."</font>" : $ts_show;
$this->TableHtml .= "\r\n<td title='hour : ".$ts_show." ".$n_m."' onclick='InsertTime(\"".$st."\")' style='cursor:hand' bgcolor='#".$color."' width='".$this->w_td."%'>\r\n<center>";
$this->TableHtml .= "<b>".$ts_view."</b> </center></td>\r\n";
$this->Tid++;
}
$this->TableHtml .= ("</table></center>");
# The Form
$this->TableHtml .= $this->OutPutForm();
# My Copy Rights :)
$this->TableHtml .= $this->ShowMyCopyRight();
return $this->TableHtml;
}
# KSA Time
function convertTime($gmtime)
{
if ($gmtime > 12)
{
$ar = 1;
for ($gm = 13; $gm <= 24; $gm++)
{
if ($gm == $gmtime)
{
$resultTime = $ar;
$resultTime .= ($ar == 12) ? " AM" : " PM";
break;
}
$ar++;
}
}
else
{
$resultTime = $gmtime;
$resultTime .= ($gmtime == 12) ? " PM" : " AM";
}
return $resultTime;
}
# Cron handling
function CheckCron($startClose,$startRun)
{
if( $startClose >= 13 && $startRun <= 12)
{
if($this->NowTime < $startClose )
{
if ( ($startClose >= $this->NowTime) && ($startRun > $this->NowTime) )
{
return true;
}
}
else
{
if ( ($this->NowTime >= $startClose) && ($this->NowTime > $startRun) )
{
return true;
}
}
}
elseif( $startClose <= 12 && $startRun >= 13)
{
if ( ($this->NowTime >= $startClose) && ($this->NowTime < $startRun) )
{
return true;
}
}
elseif( ($startClose <= 12 && $startRun <= 12) or ( $startClose >= 13 && $startRun >= 13) )
{
if ( ($this->NowTime >= $startClose) && ($startRun > $this->NowTime) )
{
return true;
}
}
else
{
return false;
}
}
# day name from the day number
function GetDays($day_number="-1")
{
$this->day_number = $day_number;
switch($this->day_number)
{
case 0;
$day_name = $this->days_of_names[0];
break;
case 1;
$day_name = $this->days_of_names[1];
break;
case 2;
$day_name = $this->days_of_names[2];
break;
case 3;
$day_name = $this->days_of_names[3];
break;
case 4;
$day_name = $this->days_of_names[4];
break;
case 5;
$day_name = $this->days_of_names[5];
break;
case 6;
$day_name = $this->days_of_names[6];
break;
default:
$day_name = "Please Enter Number Of The Day";
break;
}
return $day_name;
}
# Interface
function OutPutForm()
{
$output = "<br><center><form name='fm' method='GET' OnSubmit=\"return checker(this)\">\n";
$output .= "<input type='radio' id='whereadd1' name='whereadd'>";
$output .= "Started Close :\n";
$output .= "<input type='text' id='s' name='start' disabled='true'>\n";
$output .= "<input type='button' id='r1' value='reset' onclick='resrt(1)'>";
$output .= " ";
$output .= "<input type='radio' id='whereadd2' name='whereadd'>";
$output .= "Started Open : \n";
$output .= "<input type='text' id='e' name='end' disabled='true'>\n";
$output .= "<input type='button' id='r2' value='reset' onclick='resrt(2)'>";
$output .= "<br><br> Iteration Of In : <select name='loop'>\n";
$output .= "<option>Every Days</option>\n";
for($d=0; $d < 7; $d++)
{
$output .= "<option>". $this->GetDays($d) ."</option>\n";
}
$output .= "</select>";
$output .= "<br>\n<input type='checkbox' id='check' name='ViewStartRun' value='yes' checked='true'>\n";
$output .= "<label for='check'> Write return time the site to open : </label>\n";
$output .= "<br><br><label for='msg'>The Closing Message : </label><br>\n";
$output .= "<textarea rows='10' id='msg' cols='75' name='MsgClose'></textarea>\n";
$output .= "<br>( if you don't write message the closing then we putting default message )(don't use HTML tag)<br>\n";
$output .= "<input type='hidden' id='Cstart' name='StartClose'>\n";
$output .= "<input type='hidden' id='Rstart' name='StartRun'>\n";
$output .= "<input type='hidden' name='EasyCron' value='CreateCode'>\n";
$output .= "<input type='hidden' name='ss' value='".md5(time())."'>\n";
$output .= "<br><input type='submit' value='Create : EasyCron File'>\n";
$output .= "</form>\n";
return ($output);
}
# read Cron
function ReadCron()
{
if(!file_exists($this->cron_path ."/EasyCron.cron"))
{
die(" error <b>". $this->cron_path ."/EasyCron.cron </b> don't exists ");
}
else
{
$CronFile = @file($this->cron_path ."/EasyCron.cron");
$CronGet = explode ("#", $CronFile[0]);
$sc = $this->GetValue("C",trim($CronGet[0]));
$so = $this->GetValue("O",trim($CronGet[1]));
$lr = $this->GetValue("L",trim($CronGet[2]));
$ms = $this->GetValue("M",trim($CronGet[3]));
$bt = $this->GetValue("V",trim($CronGet[4]));
if(is_array($sc))
{
foreach($sc as $k=>$v)
{
while( $this->CheckCron($sc[$k],$so[$k]) == true )
{
$backTime = $this->convertTime($so[$k]);
$this->E_Cron($lr,$ms,$bt,$backTime);
}
}
}
else
{
if( $this->CheckCron($sc,$so) == true )
{
$backTime = $this->convertTime($so);
$this->E_Cron($lr,$ms,$bt,$backTime);
}
}
}
}
# open/close
function E_Cron($Iteration,$message,$show_back_time,$backtime)
{
if (($Iteration == "Every Days") or ($Iteration == $this->day_name))
{
$message = str_replace('[br]',"<br />\n",$message);
$CronMsg = "<html>\n\n <head>\n<title> Closed ! </title> \n</head>\n ";
$CronMsg .= "<body>\n\n <center>\n<h1>". $message ."</h1>\n\n\n";
if ($show_back_time == "Yes")
{
$CronMsg .= "<br>\n<h3> it's back to the state opening in : ". $backtime ."</h2>\n</center>";
}
if($this->print_copyright == 1)
{
$CronMsg .= "<br><br>\n\n\n ". $this->ShowMyCopyRight();
}
$CronMsg .= "\n\n </body>\n\n</html>";
die($CronMsg);
}
}
# print the value
function GetValue($element,$InCron)
{
$pattern = "/". $element ."\s*{(.+)}\s*/i";
$Value = preg_replace($pattern, "\${1}", $InCron);
if (stristr($Value, "~") == true)
{
$ExtractValue = explode("~", $Value);
return $ExtractValue;
}
else
{
return $Value;
}
}
# to save copy of file created
function SaveCron($startClose,$startRun,$run_in="Every Days",$msgclose,$ViewStartRun,$yes=0)
{
$ShowStartRun = ($ViewStartRun) ? "Yes" : "No";
$msgclose = (empty($msgclose)) ? "sorry , but this site it's closed now ! " : $msgclose;
$msgclose = strip_tags($msgclose);
$msgclose = str_replace("\n",'[br]',$msgclose);
$msgclose = str_replace("\'","'",$msgclose);
$cron = "C {".$startClose."} # O {".$startRun."} # L {".$run_in."} # M {".$msgclose."} # V {".$ShowStartRun."}";
$open_new_cron = @fopen($this->cron_path ."/EasyCron.cron",'w+');
$write_cron = @fwrite($open_new_cron,$cron);
@fclose($open_new_cron);
if($yes != 0)
{
Header("Pragma: public");
Header("Expires: 0");
Header('Content-Description: File Transfer');
Header('Content-Type: application/force-download');
Header("Content-Disposition: attachment; filename=EasyCron.cron");
Header("Content-Type: application/x-ms-download ");
ECHO $cron;
exit;
}
if($write_cron)
{
ECHO " The <b> EasyCron.cron </b> has created successfuly .";
return true;
}
else
{
ECHO "Sorry , But The File don't Create , please try again later . ";
return false;
}
}
# copy right
function ShowMyCopyRight()
{
$CopyRight .= "<hr><center><b><font face='Tahoma' size='2'>";
$CopyRight .= " EasyCron version: 1.0 beta , All rights reserved for : ";
$CopyRight .= " <a href='http://www.naifphp.net'>naifphp</a>";
$CopyRight .= "</font></b></center>\r\n\r\n</html>";
return ($CopyRight);
}
}
?> | |
admin.php
| <?php
/****************************************************************************************
=========================================================================================
| @ Script Name : EasyCron
| @ Version : 1.0
| @ Description : Open and Close your website in fixed times .
| @ All rights reserved to : NaiF PHP
| @ Created In : 8-9-2006
| @ Support Site : http://www.naifphp.net
=========================================================================================
*****************************************************************************************/
include "easycron.class.php";
$EC = new MyEasyCron;
if(isset($_GET["EasyCron"]))
{
$start_close = $_GET["StartClose"];
$start_open = $_GET["StartRun"];
$iteration = $_GET["loop"];
$msg_close = $_GET["MsgClose"];
$show_back_time = $_GET["ViewStartRun"];
$EC->SaveCron($start_close, $start_open, $iteration, $msg_close, $show_back_time);
}
else
{
echo $EC->CronTable();
}
?> | |
EasyCron.cron
| | C {5} # O {7} # L {Every Days} # M {sorry , but this site it's closed now ! } # V {Yes} | |
example.php
| <?php
/****************************************************************************************
=========================================================================================
| @ Script Name : EasyCron
| @ Version : 1.0
| @ Description : Open and Close your website in fixed times .
| @ All rights reserved to : NaiF PHP
| @ Created In : 8-9-2006
| @ Support Site : http://www.naifphp.net
| @ file created in : 8-9-2006 4:44 AM
=========================================================================================
*****************************************************************************************/
/*
# Description This Example
Checks if return true => status = 'closed'
Else
return => 'value'
*/
include "easycron.class.php";
$EC = new MyEasyCron;
// you have to spicfy the EasyCron path
//$EC->cron_path = "c:/appserv/www/easycron";
$EC->ReadCron();
// if this easy corn didn't return true ,you will see this message
$Value = "<html>\n <head> <title> EasyCron Version 1.0 </title>\n\n </head>\n <body>";
$Value .= " <center> <h1> Example For Easy Cron Version 1.0 </h1> </center> ";
$Value . "</body>\n</html>";
echo $Value;
?> | |
EasyCron.js
| /****************************************************************************************
=========================================================================================
| @ Script Name : EasyCorn
| @ Version : 1.0
| @ Description : Open and Close your website in fixed times .
| @ All rights reserved to : NaiF PHP
| @ Created In : 8-9-2006
| @ Support Site : http://www.naifphp.net
=========================================================================================
*****************************************************************************************/
function checker(fm)
{
if(fm.Cstart.value == "")
{
alert(" Please selected the time it started close !");
return false;
}
if(fm.Rstart.value == "")
{
alert(" Please selected the time it started open !");
return false;
}
}
function InsertTime(numbric) {
var STime = document.getElementById('s');
var ETime = document.getElementById('e');
var ETime2 = document.getElementById('Rstart');
var STime2 = document.getElementById('Cstart');
var resrt1 = document.getElementById('r1');
var resrt2 = document.getElementById('r2');
var WA1 = document.getElementById('whereadd1');
var WA2 = document.getElementById('whereadd2');
if (numbric)
{
if (!(WA1.checked) && !(WA2.checked))
{
alert(" please select where you want to add this time !! ");
}
else if(WA1.checked)
{
if(STime.value!="")
{
STime.value = STime.value +"~"+ numbric;
STime2.value = STime2.value +"~"+ numbric;
resrt1.disabled = false;
}
else
{
STime.value = numbric;
STime2.value = numbric;
resrt1.disabled = false;
}
}
else if(WA2.checked)
{
if(ETime.value!="")
{
ETime.value = ETime.value +"~"+ numbric;
ETime2.value = ETime2.value +"~"+ numbric;
resrt2.disabled = false;
}
else
{
ETime.value = numbric;
ETime2.value = numbric;
resrt2.disabled = false;
}
}
}
}
window.onload = function()
{
var resrt1 = document.getElementById('r1');
var resrt2 = document.getElementById('r2');
resrt1.disabled = true;
resrt2.disabled = true;
//resrt2.style.visibility='hidden';
}
function resrt(x)
{
var STime = document.getElementById('s');
var ETime = document.getElementById('e');
var resrt1 = document.getElementById('r1');
var resrt2 = document.getElementById('r2');
var ETime2 = document.getElementById('Rstart');
var STime2 = document.getElementById('Cstart');
if(x==1)
{
STime.value = "";
STime2.value = "";
resrt1.disabled = true;
}
if(x==2)
{
ETime.value = "";
ETime2.value = "";
resrt2.disabled = true;
}
} | | |
|
| A Timing Class Categories : PHP, PHP Classes, Date Time | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example. Categories : PHP, Date Time, PHP Classes, Calendar | | | A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function. Categories : PHP, PHP Classes, Calendar, Date Time | | | Validator - A PHP class that can can be used for validating Email IDs and Dates Categories : PHP, PHP Classes, Data Validation, Email, Date Time | | | A time measuring and performance benchmarking class Categories : PHP, PHP Classes, Testing, Debugging, Date Time | | | Bs_StopWatch is a class to measure time intervals in microseconds.
Categories : PHP, Date Time, PHP Classes | | | Customizable Calendar Class Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar | | | a class that uses microtime() to provide easy calculation of elapsed times
Categories : Date Time, PHP, PHP Classes | | | very simple ftp class Categories : PHP, PHP Classes, FTP | | | PHP Paypal IPN Integration Class v1.0.0 Categories : PHP, PHP Classes, Payment Gateways | | | crop and resize image class using gd library function Categories : PHP, PHP Classes, GD image library, Graphics | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | Create HTML forms dynamicly using Javascript & PHP Categories : PHP, PHP Classes, Java Script | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | |
|
|
|