• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

cms/widgets/count_down/widget.class.php

Go to the documentation of this file.
00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 { 
00004         header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005         echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006         echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007         exit(1);
00008 }
00019 global $sourceFolder;
00020 require_once("$sourceFolder/widgetFramework.class.php");
00021 
00022 class count_down extends widgetFramework
00023 {
00024         public $configs;
00025         public $timeformat;
00026         public $globaldisable;
00027         public $date;
00028         public $event;
00029         public $format;
00030         
00031         public function __construct($widgetId,$widgetInstanceId,$pageId)
00032         {
00033                 $this->configs = array (
00034                         array (
00035                         'name' => 'date',
00036                         'type' => 'datetime',
00037                         'displaytext' => 'Enter the date to countdown to',
00038                         'default' => '',
00039                         'global' => 0
00040                         ),
00041                         array (
00042                         'name' => 'format',
00043                         'type' => 'select',
00044                         'options' => 'days|hours|minutes|seconds',
00045                         'displaytext' => 'Enter the format of countdown',
00046                         'default' => 'days',
00047                         'global' => 0
00048                         ),
00049                         array (
00050                         'name' => 'event',
00051                         'type' => 'text',
00052                         'displaytext' => 'Enter the Event',
00053                         'default' => 'event',
00054                         'global' => 0
00055                         ),
00056                         array (
00057                         'name' => 'global_disable',
00058                         'type' => 'bool',
00059                         'displaytext' => 'Disable all countdowns in the website',
00060                         'default' => '0',
00061                         'global' => 1
00062                         )
00063                 );
00064                 parent::__construct($widgetId,$widgetInstanceId,$pageId,$this->configs);
00065                 
00066         }
00067         
00068         
00069         public function initWidget()
00070         {
00071                 $this->date = $this->settings['date'];
00072                 $this->globaldisable = $this->settings['global_disable'];
00073                 $this->event = $this->settings['event'];
00074                 $this->format = $this->settings['format'];
00075         }
00076         
00077         public function getCommonHTML()
00078         {
00079         
00080                         $count =<<<COUNT
00081 <script type="text/javascript">
00082 function cdtime(container, targetdate){
00083 if (!document.getElementById || !document.getElementById(container)) return;
00084 this.container=document.getElementById(container);
00085 this.currentTime=new Date();
00086 this.targetdate=new Date(targetdate);
00087 this.timesup=false;
00088 this.updateTime();
00089 }
00090 cdtime.prototype.updateTime=function(){
00091 var thisobj=this;
00092 this.currentTime.setSeconds(this.currentTime.getSeconds()+1);
00093 setTimeout(function(){thisobj.updateTime()}, 1000); //update time every second
00094 }
00095 cdtime.prototype.displaycountdown=function(baseunit, functionref){
00096 this.baseunit=baseunit;
00097 this.formatresults=functionref;
00098 this.showresults();
00099 }
00100 cdtime.prototype.showresults=function(){
00101 var thisobj=this;
00102 var timediff=(this.targetdate-this.currentTime)/1000; //difference btw target date and current date, in seconds
00103 if (timediff<0){ //if time is up
00104 this.timesup=true;
00105 var timediff=(this.currentTime-this.targetdate)/1000;
00106 }
00107 var oneMinute=60; //minute unit in seconds
00108 var oneHour=60*60; //hour unit in seconds
00109 var oneDay=60*60*24; //day unit in seconds
00110 var dayfield=Math.floor(timediff/oneDay);
00111 var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour);
00112 var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute);
00113 var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute));
00114 if (this.baseunit=="days"){
00115 dayfield=dayfield+" <sub>days</sub> "
00116 hourfield=hourfield+" <sub>hours</sub> ";
00117 minutefield=minutefield+" <sub>minutes</sub> ";
00118 secondfield=secondfield+" <sub>seconds</sub>";
00119 }
00120 else if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
00121 hourfield=dayfield*24+hourfield+" <sub>hours</sub> ";
00122 minutefield=minutefield+" <sub>minutes</sub> ";
00123 secondfield=secondfield+" <sub>seconds</sub>";
00124 dayfield="";
00125 }
00126 else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
00127 minutefield=dayfield*24*60+hourfield*60+minutefield+" <sub>minutes</sub> ";
00128 secondfield=secondfield+" <sub>seconds</sub>";
00129 dayfield=hourfield="";
00130 }
00131 else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
00132 var secondfield=parseInt(timediff)+" <sub>seconds</sub>";;
00133 dayfield=hourfield=minutefield="";
00134 }
00135 this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield);
00136 setTimeout(function(){thisobj.showresults()}, 1000); //update results every second
00137 }
00138 </script>
00139 COUNT;
00140         return $count;
00141 
00142         }
00143         public function getHTML()
00144         {
00145                 if($this->globaldisable=='1' || $this->globaldisable=='Yes') return "";
00146                 $date =$this->date;
00147                 if($this->event!="")
00148                         $event=$this->event;
00149                 else
00150                         $event="Event";
00151                 
00152                 
00154                 $date=preg_replace('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})[\s]+([0-9]{1,2}):([0-9]{1,2})/i','$2 $3 $1 $4:$5',$date);
00155                 
00156                 $format = $this->format;
00157                 $ran = $this->widgetInstanceId;
00158                 $count ="<div id=\"countdowncontainer_$ran\"></div>";
00159                 $count .=<<<COUNT
00160 <script type="text/javascript">
00161 function result(){
00162 var eventstring = "$event";
00163 if (this.timesup==false){ //if target date/time not yet met
00164 var displaystring=arguments[0]+arguments[1]+arguments[2]+arguments[3]+"left until "+eventstring;
00165 }
00166 else{ //else if target date/time met
00167 if(arguments[0]=="0 <sub>days</sub> ")
00168         var displaystring=eventstring + "is here!!!";
00169 else
00170         var displaystring= arguments[0]+arguments[1]+arguments[2]+arguments[3]+" since "+eventstring;
00171 }
00172 return displaystring;
00173 }
00174 var count_down_date=new cdtime("countdowncontainer_$ran","$date");
00175 count_down_date.displaycountdown("$format", result);
00176 </script>
00177 COUNT;
00178                 return $count;
00179         }       
00180 }
00181 
00182 ?>

Generated on Sun Jan 2 2011 04:55:32 for Pragyan CMS by  doxygen 1.7.1