Jump to content

Integrate mysql to exisiting php calendar


yandoo

Recommended Posts

Hi there,

 

I was hoping for a little help please :P  I want to start a project in php mysql that is like a kind of rostering database allocating support workers to clients on a specific date.

 

To make it user friendly i will need the use of a visual calendar so that user can easily assign support workers to clients on specific dates.

 

I have found a calendar a php calendar from here...

 

http://www.erobosoftware.com/scripts/php/scripts_code.php?id=6&section=PHP&division=PHP+date+and+time

 

The calendar works independantly at the moment but essentially i need mysql integrated to allow the assignment of support workers, clients and other entities.

 

I just dont know where to start, if somebody could help me that would be ace!

 

Heres the calendar pages:

 

 

DEMO:

<?php 

  require("myEventsCalendar.php"); 
  
  $thisCal = new MyEventsCalendar("http://localhost/testsite/details.php");
  
  $thisCal->setOverlibPath("http://localhost/testsite/overlib.js");
  
  $todaysDate = date("m") . "-" . date("d") . "-" . date("Y");
  
  $thisCal->addEvent($todaysDate,
                     "PHP Programming Talk at Ontario, Cananda",
                     "10:45 AM",
                     "Porgramming talk on new features for PHP 5.0");
  
    $thisCal->addEvent($todaysDate,
                     "PHP programmers meeting at Atlanta, US",
                     "5:45 PM",
                     "PHP Programmers are gonna meet to discuss issues about programming");
   
  if($_GET["m"] && $_GET["y"]) { 
    $thisCal->setMonth(trim($_GET["m"])); 
    $thisCal->setDay(1);
    $thisCal->setYear(trim($_GET["y"]));
    $thisCal->generateHTML("demo.php?calendar=start"); 
         
  } 
  else { 

    $thisCal->setMonth(date("m")); 
    $thisCal->setDay(1);
    $thisCal->setYear(date("Y"));
    $thisCal->generateHTML("demo.php?calendar=start"); 

  } 
    
?> 

 

DETAILS

<?php 

//Erobo Software Events Calendar
//Detail Page

$event = urldecode($_POST["event"]);


echo "<b>--Event Details--</b>\n";
echo "<br>" . $event;
echo "<br><br>" . "<a href=\"demo.php\">Go back to Calendar</a>";

?> 

 

MyEventsCalendar

<?php 


class myEventsCalendar 
{ 
  var $month = 0; 
  var $day = 0; 
  var $year = 0; 
  var $Months = Array("January", "February",  
  "March", "April", "May", "June", "July",  
  "August", "September", "October", "November", "December");  
  var $overlibPath = "";
  var $eventsId = array();
  var $eventsData = array();
  var $eventsCount = 0;
  var $formDetailsAction = "";
   
  function myEventsCalendar($thisFormDetailsAction) 
  {    
  	 //set the destination to view event details
  	 $this->formDetailsAction = $thisFormDetailsAction;
  	 
      //set additional parameters if necessary
      //need to set month, day, and year
      //before generating HTML
      $this->eventsData = array();
      $this->eventsCount = count($this->eventsData);
  }  
  
   
    /**Append the parameter element to the vector*/
  function addEvent($thisDate,$thisEventTitle, $thisEventTime, $thisEventDescription)
  {
  	
        if(!empty($thisDate))
        {
        	  $dateArr = explode("-",$thisDate);
        	  
        	  $mIndex = intVal($dateArr[0]);
        	  $dIndex = intVal($dateArr[1]);
        	  $yIndex = intVal($dateArr[2]);
        	  
        	  $dateIndex = $mIndex . "-" . $dIndex . "-" . $yIndex;
        	  
        	  if(!$this->eventsId[$dateIndex]) {
        	    	$this->eventsId[$dateIndex] = 1;
        	  }
        	  else {
        	  	$numOfEvents = intVal($this->eventsId[$dateIndex]);
        	  	$numOfEvents = $numOfEvents + 1;
        	  	$this->eventsId[$dateIndex] = $numOfEvents;
        	  }
        	  
        	  $titleIdx = "title" . $this->eventsId[$dateIndex];
        	  $timeIdx = "time" . $this->eventsId[$dateIndex];
        	  $descrIdx = "description" . $this->eventsId[$dateIndex];
        	  
            $this->eventsData[$dateIndex][$titleIdx] = $thisEventTitle;
            $this->eventsData[$dateIndex][$timeIdx] = $thisEventTime;
            $this->eventsData[$dateIndex][$descrIdx] = $thisEventDescription;
            $this->eventsCount = count($this->eventsData);
            return true;
        }
        else
            return false;
           
  }
  
  function setMonth($thisMonth)
  {
    $this->month = $thisMonth; 
  } 
  
  function setYear($thisYear)
  {
    $this->year = $thisYear;
  }
  
  function setDay($thisDay)
  {
     $this->day = $thisDay;
  }
  
  function setOverlibPath($thisPath)
  {
  	$this->overlibPath = $thisPath;
  }
  
  function getDayOfMonth($month, $day, $year) 
  { 
    $myresult = date("l", mktime(0, 0, 0, $month, $day, $year)); 
     
    return $myresult; 
  }   
   
   
  function getMonthName($month, $day, $year) 
  { 
    $myresult = date("F", mktime(0, 0, 0, $month, $day, $year)); 
     
    return $myresult; 
  }   
   
  function getWeekDay($day) 
  { 
      $myresult = 0;    
    switch ($day) { 
    case "Monday": 
      $myresult = 1;  
      break; 
    case "Tuesday": 
      $myresult = 2;  
      break; 
    case "Wednesday": 
      $myresult = 3;  
      break; 
    case "Thursday": 
      $myresult = 4;  
      break; 
    case "Friday": 
       $myresult =  5;  
      break; 
    case "Saturday": 
      $myresult = 6;  
      break; 
    case "Sunday": 
      $myresult = 7;  
      break; 
    } 
    return $myresult; 
  } 
   
   
  function getNumDaysOfMonth($month, $year) 
  { 
     
    // non-leap year          
    $nonleap = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);   
     
    // leap year  
    $leap = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);   
     
    $isLeap = false ; 
     
    if (($year % 4) == 0) {  
     
      if (($year % 100) == 0 && ($year % 400) != 0) {  
        $isLeap = false; 
      }  
      else {  
        $isLeap = true; 
      }  
     
    }   
    else {  
     
      $isLeap = false; 
    }  
     
     
    if($isLeap == true) {  
      return $leap[$month - 1]; 
    }  
    else {  
      return $nonleap[$month - 1];  
    }  

  } 
   
  function isToday($month,$day,$year)  
  { 
     
     if( ($month == intval(date("m"))) && ( $day == intval(date("d"))) 
      && ($year == intval(date("Y")))){ 
       return true;   
     } else { 
      return false; 
     }   
     
  } 
  
  
  function getDetails($thisDate, $allDetails)
  {
  	
$counter = 1;

$titleIdx = "title" . $counter;
$timeIdx = "time" . $counter;
$descrIdx = "description" . $counter;
$result = "";
  
//prepare overlib data
while($this->eventsData[$thisDate][$titleIdx] != "") {

	if($counter > 1){ $result .= "<br><br>"; }

	$result .= "<b>Event:</b> " . $this->eventsData[$thisDate][$titleIdx];

	$result .= "<br><b>Time:</b> " . $this->eventsData[$thisDate][$timeIdx];

	if($allDetails) {

	$result .= "<br><b>Description:</b> " . $this->eventsData[$thisDate][$descrIdx];

	}

	$counter = $counter + 1;
	$titleIdx = "title" . $counter;
	$timeIdx = "time" . $counter;
	$descrIdx = "description" . $counter;

} 	
  	return $result;
  	
  }
  
  
  function outputDay($thisMonth,$thisDay,$thisYear)
  {
    $thisDate = $thisMonth . "-" . $thisDay . "-" . $thisYear;
    
        
        if($this->eventsId[$thisDate]) {
        	
        	$overlib = $this->getDetails($thisDate, false);
        	$details = $this->getDetails($thisDate, true);	   
    	   
    	   
    	   echo "<a href=\"javascript:goToDetails('" . urlencode($details) . "')";
    	   echo ";\" ";
    	   echo "onmouseover=\"return overlib('" . $overlib . "',";
    	   echo "CAPTION,";
    	   echo "'" . $thisDate . "');\" ";
    	   echo "onmouseout=\"return nd();\">". $thisDay ."</a>\n";

    	
        } else {
          
           echo $thisDay;
        
        }
  	
  	
  }
   
  function generateHTML($toUrl)  
  {    
        
      //configure top navigation 
        
      $nextMonth = $this->month + 1; 
      $nextYear  = $this->year; 
       
      if($nextMonth == 13) { 
        $nextMonth = 1;   
        $nextYear = $this->year + 1; 
      } 
       
      $prevMonth = $this->month - 1; 
      $prevYear = $this->year; 
       
    if($prevMonth == 0) { 
        $prevMonth = 12;   
        $prevYear = $this->year - 1; 
      }       
       
      //output overlib js path
      
      echo "<script type=\"text/javascript\" src=\"" . $this->overlibPath . "\"></script>";
      
      //output overlib div
      echo "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>";
      
      //output detail form
      
      echo "<form name=\"jump_to_details\" action=\"" . $this->formDetailsAction  . "\" ";
      echo "method=\"POST\">\n";
      
      echo "<input type=\"hidden\" name=\"event\" value=\"\">\n";
      
      echo "</form>";
      
      //output javascript submit form (handler) method
      
      echo "<script language=\"Javascript\">\n";
      echo "\n";
      echo "function goToDetails(thisEvent) {\n";
      echo "document.jump_to_details.event.value=thisEvent\n";
      echo "document.jump_to_details.submit()\n";
      echo "}\n";
      echo "</script>\n";
       
      //configure bottom navigation 

      $gobackwards = $toUrl . "&m=" . $prevMonth . "&y=" . $prevYear; 
      $goforward = $toUrl . "&m=" . $nextMonth . "&y=" . $nextYear; 
       
      echo "<small>"; 
      echo "<table border=\"1\" cellpadding=\"3\">\n"; 
      echo "<tr>\n"; 
      echo "   <td colspan=\"7\">"; 
      echo "      <table border=\"0\" cellpadding=\"0\" width=\"100%\">\n"; 
      echo "      <tr>\n"; 
      echo "           <td width=\"5%\"><a href=\"" . $gobackwards .  
                                                            "\"><<</a></td>\n"; 
      echo "          <td width=\"90%\" align=\"center\"><b>" .  
      $this->getMonthName($this->month , 1 , $this->year) .  
      " " . $this->year . "</b></td>\n"; 
      echo "         <td width=\"5%\"><a href=\"" . $goforward . 
                                                            "\">>></a></td>\n"; 
      echo "      </tr>\n"; 
      echo "      </table>\n"; 
      echo "   </td>"; 
      echo "</tr>\n";       
      echo "<tr>\n"; 
      echo "   <td><b>Sun</b></td>\n"; 
      echo "   <td><b>Mon</b></td>\n"; 
      echo "   <td><b>Tue</b></td>\n"; 
      echo "   <td><b>Wed</b></td>\n"; 
      echo "   <td><b>Thur</b></td>\n"; 
      echo "   <td><b>Fri</b></td>\n"; 
      echo "   <td><b>Sat</b></td>\n"; 
      echo "</tr>\n"; 
       
      $newrow = 1; 
      $monLoop = $this->getNumDaysOfMonth($this->month, $this->year); 
      $startDay = intval($this->getWeekDay($this->getDayOfMonth( 
                                               $this->month, 1, $this->year))); 
      $begin = false; 
       

       
      for($i=1; $i <= $monLoop; $i++) { 
         
         if($startDay == 7) { 
        $begin = true;   
       } 
        
         if($newrow == 8 || $newrow == 1) { 
           echo "<tr>"; 
           $newrow = 1;   
         } 
          
         if($begin == true) { 
           
          if( $this->isToday($this->month, $i, $this->year)) { 
            echo "   <td><font color=\"red\">";
            $this->outputDay(intVal($this->month), intVal($i), intVal($this->year));
            echo "</font></td>";  
          } else { 
            echo "   <td>";
            $this->outputDay(intVal($this->month), intVal($i), intVal($this->year));
            echo "</td>";    
         }  
         } 
          
         if($i <= $startDay && $begin == false ) { 
            
           echo "   <td> </td>"; 
            
           if($i == $startDay) { 
             $begin = true;   
             $i = 0; 
           } 
            
         }  
          
         $newrow++; 
          
     if($newrow ==  { 
           echo "</tr>"; 
         }           
         
      } 
       
      echo "</table>\n"; 
      echo "</small>"; 
     
  } 
   

} 

?> 

 

 

If anybody could help me or give some advice that would be ace.

 

Thanks for Listening  ;D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.