madspof Posted June 9, 2009 Share Posted June 9, 2009 I am trying to edit a class so that depending on what is in the cookie data it will show edit or nothing. So i thought that i would use $data = isset($_COOKIE['cookie_info']) ? $_COOKIE['cookie_info'] : null; in the class but it is not extracting the cookie data, is it not doing this because i need to extract the cookie info in the actual php file that calls the class and then forward the variable with the cookie info to the class php file? if so how do i forward the variable? thanks before hand madspof Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/ Share on other sites More sharing options...
madspof Posted June 9, 2009 Author Share Posted June 9, 2009 how you pass a variable from the php file calling the php class to the actualy php class being used ? Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852685 Share on other sites More sharing options...
KevinM1 Posted June 9, 2009 Share Posted June 9, 2009 You need to provide more information. What does your class look like? Is it instantiated? What about the main code, where you're trying to use the cookie? Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852690 Share on other sites More sharing options...
madspof Posted June 9, 2009 Author Share Posted June 9, 2009 here is the class <?php /** EasyPhpEventCalendar Class version 1.0.0 Copyright (c) 2009 JF Nutbroek <jfnutbroek@gmail.com> For more information visit http://wwww.mywebmymail.com Permission to use, copy, modify, and/or distribute this software for any purpose without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ class easyphpeventcalendar { /** * URL to gfx directory with calendar backgrounds * * @var string */ public $Gfxurl; /** * Days; array with 7 string values representing the days * [0]: Sunday * [1]: Monday * [2]: Tuesday * [3]: Wednesday * [4]: Thursday * [5]: Friday * [6]: Saturday * * @var array */ public $Days; /** * Months; array with 12 string values representing the months * [0]: January * [1]: February * [2]: March * [3]: April * [4]: May * [5]: June * [6]: July * [7]: August * [8]: September * [9]: October * [10]: November * [11]: December * * @var array */ public $Months; /** * Events; array with arrays representing the events * [0]: array ('YYYYMMDD','Event 1 as text with html markup') * [1]: array ('YYYYMMDD','Event 2 as text with html markup') * [2]: etc. * * @var array */ public $Events; /** * Class constructor * */ public function __construct() { $this->Gfxurl = 'gfx'; $this->Days = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); $this->Months = array('January','February','March','April','May','June','July','August','September','October','November','December'); $this->Events = array(); } /** * Creates Event Calendar * * @param string/array $filename * @param string $output */ public function CreateEventCalendar() { $this->Gfxurl=rtrim($this->Gfxurl,'/'); echo "<div id=\"eventcalendar\">\n"; echo "<style type=\"text/css\">\n"; echo ".eventtable {\n"; echo " text-align : center;\n"; echo " font-family : Verdana, Helvetica, Arial, sans-serif;\n"; echo " font-size : 11px;\n"; echo " color : #000000;\n"; echo " border-collapse : separate;\n"; echo " border-spacing : 2px;\n"; echo " width : 410px;\n"; echo "}\n"; echo ".eventweekmonth {\n"; echo " background-image : url('$this->Gfxurl/weekmonth.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 25px;\n"; echo " width : 40px;\n"; echo "}\n"; echo ".eventweekmonthactive {\n"; echo " background-image : url('$this->Gfxurl/weekmonth_event.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 25px;\n"; echo " width : 40px;\n"; echo " font-weight : bold;\n"; echo "}\n"; echo ".eventweekend {\n"; echo " background-image : url('$this->Gfxurl/weekend.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 19px;\n"; echo " width : 40px;\n"; echo "}\n"; echo ".eventweekendactive {\n"; echo " background-image : url('$this->Gfxurl/weekend_event.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 19px;\n"; echo " width : 40px;\n"; echo " font-weight : bold;\n"; echo "}\n"; echo ".eventday {\n"; echo " background-image : url('$this->Gfxurl/day.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 19px;\n"; echo " width : 40px;\n"; echo "}\n"; echo ".eventdayactive {\n"; echo " background-image : url('$this->Gfxurl/day_event.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 19px;\n"; echo " width : 40px;\n"; echo " font-weight : bold;\n"; echo "}\n"; echo ".eventdaydisabled {\n"; echo " background-image : url('$this->Gfxurl/day.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 19px;\n"; echo " width : 40px;\n"; echo " color : #969696;\n"; echo "}\n"; echo ".eventdetails {\n"; echo " background-image : url('$this->Gfxurl/eventdetails.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " text-align : left;\n"; echo " vertical-align : top;\n"; echo " height : 160px;\n"; echo " width : 304px;\n"; echo " padding : 5px;\n"; echo "}\n"; echo ".eventcalendartitle {\n"; echo " background-image : url('$this->Gfxurl/title.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 25px;\n"; echo " width : 304px;\n"; echo " font-weight : bold;\n"; echo "}\n"; echo "</style>\n"; // Get current date $date=time();$month=date('m',$date);$year=date('Y',$date); // Left column with months echo "<table class=\"eventtable\"><tr><td style=\"vertical-align : top;width : 44px;\">\n"; echo "<table style=\"vertical-align : top;border-collapse : separate;border-spacing : 2px;width : 44px;\">\n"; echo "<tr><td style=\"height : 25px;\"> </td></tr>\n"; if ($this->eventcheck(1)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('1')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[0],0,3) . "</td></tr>\n"; if ($this->eventcheck(2)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('2')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[1],0,3) . "</td></tr>\n"; if ($this->eventcheck(3)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('3')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[2],0,3) . "</td></tr>\n"; if ($this->eventcheck(4)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('4')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[3],0,3) . "</td></tr>\n"; if ($this->eventcheck(5)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('5')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[4],0,3) . "</td></tr>\n"; if ($this->eventcheck(6)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('6')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[5],0,3) . "</td></tr>\n"; echo "</table>\n"; echo "</td><td style=\"vertical-align : top;width : 308px;\">\n"; // Add Events foreach ($this->Events as $key => $event) { $eventmonth=intval(substr($event[0],4,2));$eventyear=intval(substr($event[0],0,4));$eventday=intval(substr($event[0],6,2)); if (checkdate($eventmonth,$eventday,$eventyear)) { $day_no=date('N',mktime(0,0,0,$eventmonth,$eventday,$eventyear));$month_no=date('n',mktime(0,0,0,$eventmonth,$eventday,$eventyear))-1; if ($day_no==7) {$day_no=0;} $date=$this->Days[$day_no] . ' ' . $eventday . ' ' . $this->Months[$month_no] . ' ' . $eventyear; echo "<div id=\"" . ($key + 13) ."\" style=\"display: none\">\n"; echo "<table style=\"width : 308px;vertical-align : top;border-collapse : separate;border-spacing : 2px;\"><tr><td class=\"eventcalendartitle\">$date</td></tr><tr><td class=\"eventdetails\" onClick=\"expandCollapse($eventmonth)\" onMouseOver=\"this.style.cursor='pointer';\">" . $event[1] . "</td></tr></table>\n"; echo "</div>\n"; } } // Add Months for ($m=1;$m<13;$m++) { if ($m==$month) { echo "<div id=\"$m\">\n"; $this->eventcalendar(mktime(0,0,0,$m,1,$year)); echo "</div>\n"; } else { if ($m<$month) {$i=1;} else {$i=0;} echo "<div id=\"$m\" style=\"display: none\">\n"; $this->eventcalendar(mktime(0,0,0,$m,1,$year+$i)); echo "</div>\n"; } } // Right column with months echo "</td><td style=\"vertical-align : top;width : 44px;\">\n"; echo "<table style=\"width : 44px;vertical-align : top;border-collapse : separate;border-spacing : 2px;\">\n"; echo "<tr><td style=\"height : 25px;\"> </td></tr>\n"; if ($this->eventcheck(7)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('7')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[6],0,3) . "</td></tr>\n"; if ($this->eventcheck() {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('8')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[7],0,3) . "</td></tr>\n"; if ($this->eventcheck(9)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('9')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[8],0,3) . "</td></tr>\n"; if ($this->eventcheck(10)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('10')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[9],0,3) . "</td></tr>\n"; if ($this->eventcheck(11)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('11')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[10],0,3) . "</td></tr>\n"; if ($this->eventcheck(12)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('12')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[11],0,3) . "</td></tr>\n"; echo "</table>\n"; echo "</td></tr></table>\n"; // Javascript to show and hide content echo "<script language=\"JavaScript\">\n"; echo "<!-- EasyPhpEventCalendar Copyright (c) 2009 JF Nutbroek -->\n"; echo "<!-- More information on http://www.mywebmymail.com -->\n"; echo "function expandCollapse(divsection) {\n"; echo " for(i=1;i<" . (13+count($this->Events)) . ";i++) {Collapse(i);}\n"; echo " var element = document.getElementById(divsection);\n"; echo " element.style.display = \"block\";\n"; echo "}\n"; echo "function Collapse(divsection) {\n"; echo " var element = document.getElementById(divsection);\n"; echo " element.style.display = \"none\";\n"; echo "}\n"; echo "</script>\n"; echo "</div>\n"; } /** * Check if month has an event * */ private function eventcheck($month) { foreach ($this->Events as $key => $event) { if (intval(substr($event[0],4,2))==$month) return true; } return false; } /** * Print the month * */ private function eventcalendar($date) { $day=date('d',$date);$month=date('m',$date);$year=date('Y',$date);$first_day=mktime(0,0,0,$month,1,$year);$title=$this->Months[date('n',mktime(0,0,0,$month,$day,$year))-1]; $days_in_month=cal_days_in_month(0,$month,$year);$day_of_week=date('N',$first_day); if ($day_of_week==7) {$blank=0;} else {$blank=$day_of_week;} echo "<table style=\"vertical-align : top;border-collapse : separate;border-spacing : 2px;width : 308px;\">";echo "<tr><td colspan=\"7\" class=\"eventcalendartitle\">$title $year</td></tr>"; echo "<tr><td class=\"eventweekmonth\">". substr($this->Days[0],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[1],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[2],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[3],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[4],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[5],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[6],0,3) . "</td></tr>"; if (($month-1)==0) {$prevmonth=1;$prevyear=($year-1);} else {$prevmonth=($month-1);$prevyear=$year;} $day_prevmonth=cal_days_in_month(0,$prevmonth,$prevyear)-($blank-1);echo "<tr>"; $day_num=1;$day_count=1;$datenow=time();$monthnow=date('n',$datenow);$yearnow=date('Y',$datenow);$daynow=date('j',$datenow); while ($blank>0) {echo "<td class=\"eventdaydisabled\">$day_prevmonth</td>";$blank=$blank-1;$day_count++;$day_prevmonth++;} while ($day_num<=$days_in_month) { $class="class=\"eventday\"";$id=0; if ($day_count==1 || $day_count==7) {$class="class=\"eventweekend\"";} foreach ($this->Events as $key => $event) { $eventyear=intval(substr($event[0],0,4));$eventmonth=intval(substr($event[0],4,2));$eventday=intval(substr($event[0],6,2)); if ($eventyear==$year && $eventmonth==$month && $eventday==$day_num) { $class="class=\"eventdayactive\""; if ($day_count==1 || $day_count==7) {$class="class=\"eventweekendactive\"";} $id=($key +13);break; } } if ($yearnow==$year && $monthnow==$month && $daynow==$day_num) {$textstyle='style="color : #FF0000;font-weight : bold;"';} else {$textstyle='';} if ($id>0) { echo "<td $class $textstyle onClick=\"expandCollapse($id)\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\"> $day_num </td>"; } else { echo "<td $class $textstyle> $day_num </td>"; } $day_num++;$day_count++; if ($day_count>7) {echo "</tr><tr>";$day_count=1;} } $day_nextmonth=1; if ($day_count==1) { echo "<td colspan=\"7\"> </td>"; } else { while ($day_count>1 && $day_count<=7 ) {echo "<td class=\"eventdaydisabled\">$day_nextmonth</td>";$day_count++;$day_nextmonth++;} } echo "</tr></table>\n"; } } ?> and here is the php file that calls the function <?php // Include the Class - Paths are relative to the file that included the class include_once('./easyphpeventcalendar.php'); // Initialize the Class $calendar = new easyphpeventcalendar; // Configure the Calendar // Provide the path to the class background images // Paths are relative to the file that included the class $calendar -> Gfxurl = '../gfx'; $calendar -> rank = isset($_COOKIE['cookie_info']) ? $_COOKIE['cookie_info'] : null; // Optional: Override the English language by providing the days and months in another language // $calendar -> Days = array('Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag'); // $calendar -> Months = array('Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'); // Method 1: Add events manually // Format: $calendar -> Events[] = array('YYYYMMDD','Event as text with optional html markup') $calendar -> Events[] = array('20091225','<b>Christmasday</b><br /><br />Merry X-mas!!'); $calendar -> Events[] = array(date('Y'). '0801','<div style="text-align: center;padding: 50px 10px;"><b>1st of August!!</b></div>'); // Method 2: Add events from textfiles // Provide the path/location to your directory with events stored in textfiles with filenames 'YYYYMMDD.txt' $eventslocation='events'; if ($dir=@opendir($eventslocation)) { while ($file=@readdir($dir)) { if (@strtolower(substr($file,-3))=='txt') { if ($fp=@fopen("$eventslocation/".$file,'r+')) { $text=fread($fp,filesize("$eventslocation/".$file)); @fclose($fp); $calendar -> Events[] = array(substr($file,0,,$text); } } } } // Method 3: Add events from a database // Place your custom code here ... // Print the Event Calendar // You could position it anywhere on a page using a <div> $calendar -> CreateEventCalendar(); ?> how do i pass a variable from the php file to the class file ? Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852701 Share on other sites More sharing options...
KevinM1 Posted June 9, 2009 Share Posted June 9, 2009 What exactly are you trying to do with the cookie info? Are you trying to pass it to the calender object? If so, what are you hoping to accomplish? Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852706 Share on other sites More sharing options...
KevinM1 Posted June 9, 2009 Share Posted June 9, 2009 Okay, I see it...it was buried under mounds of over-commented code. Here's the thing - you can't pass a value to an object and automatically expect it to work. The class that the object is an instance of needs to be written in such a way that it can handle your cookie data. Right now nothing is happening because, from what I can see, the calender knows nothing about 'rank' or anything else of that nature. Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852711 Share on other sites More sharing options...
.josh Posted June 9, 2009 Share Posted June 9, 2009 Assuming that in your code $calendar->rank is what you were showing $data to be... So you are trying to assign your cookie to $calendar->rank but in your class, you do not have a property called rank (nor does it look like you're actually doing anything in your class with a property called rank... In your class you need to add $rank to your list of properties. Assuming that you want to be able to assign something to it directly, you would have public $rank; Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852714 Share on other sites More sharing options...
KevinM1 Posted June 9, 2009 Share Posted June 9, 2009 Assuming that in your code $calendar->rank is what you were showing $data to be... So you are trying to assign your cookie to $calendar->rank but in your class, you do not have a property called rank (nor does it look like you're actually doing anything in your class with a property called rank... In your class you need to add $rank to your list of properties. Assuming that you want to be able to assign something to it directly, you would have public $rank; He'd also need to write a new method, or edit an existing one, to actually do something useful with his new $rank property. Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852716 Share on other sites More sharing options...
.josh Posted June 9, 2009 Share Posted June 9, 2009 yeah was going to also mention that but you posted just before me and mentioned pretty much everything I said. Was gonna just say fuck it and not post at all since you beat me to it but I did post a little bit more details so I went ahead and posted it but left out mentioning it since you already did Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852724 Share on other sites More sharing options...
KevinM1 Posted June 9, 2009 Share Posted June 9, 2009 yeah was going to also mention that but you posted just before me and mentioned pretty much everything I said. Was gonna just say fuck it and not post at all since you beat me to it but I did post a little bit more details so I went ahead and posted it but left out mentioning it since you already did Hehe EDIT: I admit, though, that the wording to that initial "it ain't gonna work" response was a bit awkward...even I went "what the hell was I trying to say?" when I re-read it. Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852725 Share on other sites More sharing options...
madspof Posted June 9, 2009 Author Share Posted June 9, 2009 ok here is my new code for the class and php file but it does not work <?php /** EasyPhpEventCalendar Class version 1.0.0 Copyright (c) 2009 JF Nutbroek <jfnutbroek@gmail.com> For more information visit http://wwww.mywebmymail.com Permission to use, copy, modify, and/or distribute this software for any purpose without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ class easyphpeventcalendar { /** * URL to gfx directory with calendar backgrounds * * @var string */ public $Gfxurl; public $rank; /** * Days; array with 7 string values representing the days * [0]: Sunday * [1]: Monday * [2]: Tuesday * [3]: Wednesday * [4]: Thursday * [5]: Friday * [6]: Saturday * * @var array */ public $Days; /** * Months; array with 12 string values representing the months * [0]: January * [1]: February * [2]: March * [3]: April * [4]: May * [5]: June * [6]: July * [7]: August * [8]: September * [9]: October * [10]: November * [11]: December * * @var array */ public $Months; /** * Events; array with arrays representing the events * [0]: array ('YYYYMMDD','Event 1 as text with html markup') * [1]: array ('YYYYMMDD','Event 2 as text with html markup') * [2]: etc. * * @var array */ public $Events; /** * Class constructor * */ public function __construct() { $this->Gfxurl = 'gfx'; $this->Days = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); $this->Months = array('January','February','March','April','May','June','July','August','September','October','November','December'); $this->Events = array(); } /** * Creates Event Calendar * * @param string/array $filename * @param string $output */ public function CreateEventCalendar() { $this->Gfxurl=rtrim($this->Gfxurl,'/'); echo "<div id=\"eventcalendar\">\n"; echo "<style type=\"text/css\">\n"; echo ".eventtable {\n"; echo " text-align : center;\n"; echo " font-family : Verdana, Helvetica, Arial, sans-serif;\n"; echo " font-size : 13px;\n"; echo " color : #000000;\n"; echo " border-collapse : separate;\n"; echo " border-spacing : 2px;\n"; echo " width : 410px;\n"; echo "}\n"; echo ".eventweekmonth {\n"; echo " background-image : url('$this->Gfxurl/weekmonth.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 25px;\n"; echo " width : 40px;\n"; //echo " font-weight : bold;\n"; echo "}\n"; echo ".eventweekmonthactive {\n"; echo " background-image : url('$this->Gfxurl/weekmonth_event.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 25px;\n"; echo " width : 40px;\n"; echo " font-weight : bold;\n"; echo "}\n"; echo ".eventweekend {\n"; echo " background-image : url('$this->Gfxurl/weekend.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 19px;\n"; echo " width : 40px;\n"; echo "}\n"; echo ".eventweekendactive {\n"; echo " background-image : url('$this->Gfxurl/weekend_event.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 19px;\n"; echo " width : 40px;\n"; echo " font-weight : bold;\n"; echo "}\n"; echo ".eventday {\n"; echo " background-image : url('$this->Gfxurl/day.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 19px;\n"; echo " width : 40px;\n"; echo "}\n"; echo ".eventdayactive {\n"; echo " background-image : url('$this->Gfxurl/day_event.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 19px;\n"; echo " width : 40px;\n"; echo " font-weight : bold;\n"; echo "}\n"; echo ".eventdaydisabled {\n"; echo " background-image : url('$this->Gfxurl/day.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 19px;\n"; echo " width : 40px;\n"; echo " color : #969696;\n"; echo "}\n"; echo ".eventdetails {\n"; echo " background-image : url('$this->Gfxurl/eventdetails.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " text-align : left;\n"; echo " vertical-align : top;\n"; echo " height : 160px;\n"; echo " width : 304px;\n"; echo " padding : 5px;\n"; echo "}\n"; echo ".eventcalendartitle {\n"; echo " background-image : url('$this->Gfxurl/title.gif');\n"; echo " background-repeat : no-repeat;\n"; echo " height : 25px;\n"; echo " width : 304px;\n"; echo " font-weight : bold;\n"; echo "}\n"; echo "</style>\n"; // Get current date $date=time();$month=date('m',$date);$year=date('Y',$date); // Left column with months echo "<table class=\"eventtable\"><tr><td style=\"vertical-align : top;width : 44px;\">\n"; echo "<table style=\"vertical-align : top;border-collapse : separate;border-spacing : 2px;width : 44px;\">\n"; echo "<tr><td style=\"height : 25px;\"> </td></tr>\n"; if ($this->eventcheck(1)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('1')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[0],0,3) . "</td></tr>\n"; if ($this->eventcheck(2)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('2')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[1],0,3) . "</td></tr>\n"; if ($this->eventcheck(3)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('3')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[2],0,3) . "</td></tr>\n"; if ($this->eventcheck(4)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('4')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[3],0,3) . "</td></tr>\n"; if ($this->eventcheck(5)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('5')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[4],0,3) . "</td></tr>\n"; if ($this->eventcheck(6)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('6')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[5],0,3) . "</td></tr>\n"; echo "</table>\n"; echo "</td><td style=\"vertical-align : top;width : 308px;\">\n"; // Add Events $data = $this->rank; //$data = $_COOKIE['cookie_info']; $check = strpos($data,'-'); $gh = strlen($data); $fg = strpos($data,'@'); $jk = ($fg-1)-$check; $rank = substr($data,$fg+1,$gh); $a = "lol"; if($rank == "STAFF"){ $a = "dfdfdff"; }elseif($rank == "NCO"){ $a = "dfdfdff"; } foreach ($this->Events as $key => $event) { $eventmonth=intval(substr($event[0],4,2));$eventyear=intval(substr($event[0],0,4));$eventday=intval(substr($event[0],6,2)); if (checkdate($eventmonth,$eventday,$eventyear)) { $day_no=date('N',mktime(0,0,0,$eventmonth,$eventday,$eventyear));$month_no=date('n',mktime(0,0,0,$eventmonth,$eventday,$eventyear))-1; if ($day_no==7) {$day_no=0;} $date=$this->Days[$day_no] . ' ' . $eventday . ' ' . $this->Months[$month_no] . ' ' . $eventyear; echo "<div id=\"" . ($key + 13) ."\" style=\"display: none\">\n"; echo "<table style=\"width : 308px;vertical-align : top;border-collapse : separate;border-spacing : 2px;\"><tr><td class=\"eventcalendartitle\">$date</td></tr><tr><td class=\"eventdetails\" onClick=\"expandCollapse($eventmonth)\" onMouseOver=\"this.style.cursor='pointer';\">" . $data . $rank . $event[1] . "</td></tr></table>\n"; echo "</div>\n"; } } // Add Months for ($m=1;$m<13;$m++) { if ($m==$month) { echo "<div id=\"$m\">\n"; $this->eventcalendar(mktime(0,0,0,$m,1,$year)); echo "</div>\n"; } else { if ($m<$month) {$i=1;} else {$i=0;} echo "<div id=\"$m\" style=\"display: none\">\n"; $this->eventcalendar(mktime(0,0,0,$m,1,$year+$i)); echo "</div>\n"; } } // Right column with months echo "</td><td style=\"vertical-align : top;width : 44px;\">\n"; echo "<table style=\"width : 44px;vertical-align : top;border-collapse : separate;border-spacing : 2px;\">\n"; echo "<tr><td style=\"height : 25px;\"> </td></tr>\n"; if ($this->eventcheck(7)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('7')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[6],0,3) . "</td></tr>\n"; if ($this->eventcheck() {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('8')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[7],0,3) . "</td></tr>\n"; if ($this->eventcheck(9)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('9')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[8],0,3) . "</td></tr>\n"; if ($this->eventcheck(10)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('10')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[9],0,3) . "</td></tr>\n"; if ($this->eventcheck(11)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('11')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[10],0,3) . "</td></tr>\n"; if ($this->eventcheck(12)) {$class='eventweekmonthactive';} else {$class='eventweekmonth';} echo "<tr><td class=\"$class\" onClick=\"expandCollapse('12')\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\">". substr($this->Months[11],0,3) . "</td></tr>\n"; echo "</table>\n"; echo "</td></tr></table>\n"; // Javascript to show and hide content echo "<script language=\"JavaScript\">\n"; echo "<!-- EasyPhpEventCalendar Copyright (c) 2009 JF Nutbroek -->\n"; echo "<!-- More information on http://www.mywebmymail.com -->\n"; echo "function expandCollapse(divsection) {\n"; echo " for(i=1;i<" . (13+count($this->Events)) . ";i++) {Collapse(i);}\n"; echo " var element = document.getElementById(divsection);\n"; echo " element.style.display = \"block\";\n"; echo "}\n"; echo "function Collapse(divsection) {\n"; echo " var element = document.getElementById(divsection);\n"; echo " element.style.display = \"none\";\n"; echo "}\n"; echo "</script>\n"; echo "</div>\n"; } /** * Check if month has an event * */ private function eventcheck($month) { foreach ($this->Events as $key => $event) { if (intval(substr($event[0],4,2))==$month) return true; } return false; } /** * Print the month * */ private function eventcalendar($date) { $day=date('d',$date);$month=date('m',$date);$year=date('Y',$date);$first_day=mktime(0,0,0,$month,1,$year);$title=$this->Months[date('n',mktime(0,0,0,$month,$day,$year))-1]; $days_in_month=cal_days_in_month(0,$month,$year);$day_of_week=date('N',$first_day); if ($day_of_week==7) {$blank=0;} else {$blank=$day_of_week;} echo "<table style=\"vertical-align : top;border-collapse : separate;border-spacing : 2px;width : 308px;\">";echo "<tr><td colspan=\"7\" class=\"eventcalendartitle\">$title $year</td></tr>"; echo "<tr><td class=\"eventweekmonth\">". substr($this->Days[0],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[1],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[2],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[3],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[4],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[5],0,3) . "</td><td class=\"eventweekmonth\">". substr($this->Days[6],0,3) . "</td></tr>"; if (($month-1)==0) {$prevmonth=1;$prevyear=($year-1);} else {$prevmonth=($month-1);$prevyear=$year;} $day_prevmonth=cal_days_in_month(0,$prevmonth,$prevyear)-($blank-1);echo "<tr>"; $day_num=1;$day_count=1;$datenow=time();$monthnow=date('n',$datenow);$yearnow=date('Y',$datenow);$daynow=date('j',$datenow); while ($blank>0) {echo "<td class=\"eventdaydisabled\">$day_prevmonth</td>";$blank=$blank-1;$day_count++;$day_prevmonth++;} while ($day_num<=$days_in_month) { $class="class=\"eventday\"";$id=0; if ($day_count==1 || $day_count==7) {$class="class=\"eventweekend\"";} foreach ($this->Events as $key => $event) { $eventyear=intval(substr($event[0],0,4));$eventmonth=intval(substr($event[0],4,2));$eventday=intval(substr($event[0],6,2)); if ($eventyear==$year && $eventmonth==$month && $eventday==$day_num) { $class="class=\"eventdayactive\""; if ($day_count==1 || $day_count==7) {$class="class=\"eventweekendactive\"";} $id=($key +13);break; } } if ($yearnow==$year && $monthnow==$month && $daynow==$day_num) {$textstyle='style="color : #FF0000;font-weight : bold;"';} else {$textstyle='';} if ($id>0) { echo "<td $class $textstyle onClick=\"expandCollapse($id)\" onMouseOver=\"this.style.cursor='pointer';this.style.textDecoration='underline';\" onMouseOut=\"this.style.textDecoration='none';\"> $day_num </td>"; } else { echo "<td $class $textstyle> $day_num </td>"; } $day_num++;$day_count++; if ($day_count>7) {echo "</tr><tr>";$day_count=1;} } $day_nextmonth=1; if ($day_count==1) { echo "<td colspan=\"7\"> </td>"; } else { while ($day_count>1 && $day_count<=7 ) {echo "<td class=\"eventdaydisabled\">$day_nextmonth</td>";$day_count++;$day_nextmonth++;} } echo "</tr></table>\n"; } } ?> <?php // Include the Class - Paths are relative to the file that included the class include_once('./easyphpeventcalendar.php'); // Initialize the Class $calendar = new easyphpeventcalendar; // Configure the Calendar // Provide the path to the class background images // Paths are relative to the file that included the class $calendar -> Gfxurl = '../gfx'; $calendar -> rank = isset($_COOKIE['cookie_info']) ? $_COOKIE['cookie_info'] : null; // Optional: Override the English language by providing the days and months in another language // $calendar -> Days = array('Zondag','Maandag','Dinsdag','Woensdag','Donderdag','Vrijdag','Zaterdag'); // $calendar -> Months = array('Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'); // Method 1: Add events manually // Format: $calendar -> Events[] = array('YYYYMMDD','Event as text with optional html markup') $calendar -> Events[] = array('20091225','<b>Christmasday</b><br /><br />Merry X-mas!!'); $calendar -> Events[] = array(date('Y'). '0801','<div style="text-align: center;padding: 50px 10px;"><b>1st of August!!</b></div>'); // Method 2: Add events from textfiles // Provide the path/location to your directory with events stored in textfiles with filenames 'YYYYMMDD.txt' $eventslocation='events'; if ($dir=@opendir($eventslocation)) { while ($file=@readdir($dir)) { if (@strtolower(substr($file,-3))=='txt') { if ($fp=@fopen("$eventslocation/".$file,'r+')) { $text=fread($fp,filesize("$eventslocation/".$file)); @fclose($fp); $calendar -> Events[] = array(substr($file,0,,$text); } } } } // Method 3: Add events from a database // Place your custom code here ... // Print the Event Calendar // You could position it anywhere on a page using a <div> $calendar -> CreateEventCalendar(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852729 Share on other sites More sharing options...
.josh Posted June 9, 2009 Share Posted June 9, 2009 have you tried echoing out your cookie on the global level to see if it contains what you are expecting? Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852746 Share on other sites More sharing options...
madspof Posted June 9, 2009 Author Share Posted June 9, 2009 i have also added this $this->rank; in the public function __construct() section Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852748 Share on other sites More sharing options...
madspof Posted June 9, 2009 Author Share Posted June 9, 2009 ok the cookie data is definatly there and i can retrive it using the same bit of code on a php page that does not include the calendar system so it must be some thing to do with the calendar system as i cannot echo the cookia data when the it is on the same page as the calendar system code :s any ideas frazzled Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852757 Share on other sites More sharing options...
madspof Posted June 10, 2009 Author Share Posted June 10, 2009 So can anyone see why i cannot retrive the cookie info whilst running this class ? Quote Link to comment https://forums.phpfreaks.com/topic/161588-extracting-cookie-data-whilst-using-a-class/#findComment-852935 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.