Location: PHPKode > scripts > PHP calendar with AJAX driven agenda > MyWeb20Agenda/MyWeb20Agenda/includes/agenda_form.php
<?php	
		
		$m = $_REQUEST['m'];	
		$y = $_REQUEST['y'];
		$days = $_REQUEST['days'];
		$updid = $_REQUEST['updateid'];	
		
		if($updid > '0')
		{
			$noquery = "Error query the table!";
			require 'calendar_conn.php';
			$query = "SELECT * 
					FROM agenda
					WHERE date_id =  ".$updid." ";
			$data = mysql_query($query);
			if(!$data) die ($noquery);
			while ($zeile = mysql_fetch_array($data, MYSQL_BOTH))
    			{
    				$date_id = utf8_encode($zeile['date_id']);
    				$task = utf8_encode($zeile['task']);
    				$lokation = utf8_encode($zeile['lokation']);
    				$importance = utf8_encode($zeile['importance']);
    				$status = utf8_encode($zeile['status']);
    				$dates = utf8_encode($zeile['dates']);
    				$starttime = utf8_encode($zeile['starttime']);
    				$endtime = utf8_encode($zeile['endtime']);
    				$todo = utf8_encode($zeile['todo']);
    				$okay = '1';
    			}
		}
				
		$formurl = "#"	;							// URL to send data with
		$formethod = 'POST'; 						// Method to send data
		$formname = 'FormAgenda'; 					// Name of the form
		$resetName = 'SubmitResetForm'; 			// Name of the button to resett data
		$resetText = 'Reset Form'; 					// Button to reset data
		$resetSubmitType = 'reset'; 					// choose reset or submit
		$NameSubmitButton = "sendDataForm"; 		// Name of the button to submit data
		if($okay != '1')
		{ $TextSubmitButton = "Send Data"; } 			// Button to submit data
		else	{ $TextSubmitButton = "Update Data"; } 	// Button to update data	
		$formclass = "forminput"; 					// CSS input
		$titleclass = 'title'; 							// CSS form title
		$buttonclass = 'formbutton'; 					// CSS submit button
		$closecass = 'showbutton';					// CSS close window
		$tabletitle = "tabtitle";						// CSS form title
		$tdf	= "tdf";								// CSS form general formatting
		$tde = "tde";								// CSS form elements formatting
		$tableTitle = 'My Agenda - insert and edit form'; 	// Title of table
		$tableWidth = "40%"; 						// width of the table
		$tableHeight = "20%";						// height of the table
		$FirstcolWidth = "30%"; 					// width of the columns with the names
		$TitleCellHeight = "30";						// minimum height of the title cell
		if($okay != '1')
		{ $formevent = "return insertForm($m,$y)";	}		// set or remove javascript event handler
		else { $formevent = "return updateForm($updid)"; } // set or remove javascript event handler
		
		// define the form fields you want to see
		$inputfield = 		'1';						// 1 = show / 0 = hide
		$passwfield = 		'0';						// 1 = show / 0 = hide
		$hiddenfield = 	'1';						// 1 = show / 0 = hide
		$textareafield = 	'1';						// 1 = show / 0 = hide
		$menufield = 		'1';						// 1 = show / 0 = hide
		$listfield = 		'1';						// 1 = show / 0 = hide
		$radiofield = 		'1';						// 1 = show / 0 = hide
		$checkfield = 		'1';						// 1 = show / 0 = hide
		$submitfield = 	'1';						// 1 = show / 0 = hide
		$resetfield = 		'1';						// 1 = show / 0 = hide
		
		// input fields
		if($okay != '1') { $task	= "";					// usually a $_REQUEST['var'] or empty
		$lokation	= "";								// usually a $_REQUEST['var'] or empty
		$disabled = "";							// disabled or empty if not used
		$readonly = ""; }							// readonly or empty if not used		
		// rowtext-name-value-size-disabled-readonly		
		$inputparts = array(	array("Task:", "task", $task,  '38', $disabled, $readonly),
							array("Location:", "lokation", $lokation, '24'));
		reset($inputparts);
		
		// password fields
		$passw1	= "";								// usually a $_REQUEST['var'] or empty
		$passw2	= "";								// usually a $_REQUEST['var'] or empty
		$disabled = "";							// disabled or empty if not used
		$readonly = "";							// readonly or empty if not used
		// rowtext-name-value-size-disabled-readonly
		$passwparts = array(	array("Password:", "passw1", $passw1,  '38', $disabled, $readonly),
							array("Confirm Password:", "passw2", $passw2, '38'));
		reset($passwparts);
		
		// hidden fields
		// name-value
		$hiddenparts = array(	array("day", $day),
							array("m", $m),
							array("y", $y),
							array("updid", $updid));
		reset($hiddenparts);
	
		// textarea fields
		if($okay != '1') { $todo = "";					// usually a $_REQUEST['var'] or empty
		$disabled = "";							// disabled or empty if not used
		$readonly = ""; }							// readonly or empty if not used
		// row text-name-rows-cols-value-size-disabled-readonly
		$textareapart = array(array("To do:", "todo", '6',  '40', $todo, $disabled, $readonly));
		reset($textareapart);
		
		// dropdown menu fields
		// row text for the menu		
		$menutitle = "Date:";
		// the size of the menu						
		$menusize = '1';
		if($okay != '1') {
		// first menu row selected?
		$menusel = "selected";
		// how many menus do we want to see (3)
		$yearfill = range('2007','2027');
		$dayfill = range('1', $days-1);
		$monthfill = range('1','12');		
		foreach($yearfill as $val) { $showyears .= "<option value='$val'>$val</option>";}
		foreach($monthfill as $val) { $showmonth .= "<option value='$val'>$val</option>";}
		foreach($dayfill as $val) { $showdays .= "<option value='$val'>$val</option>";}
		// menuname-selectedvalue-selectedshow-fillvalueshow
		$menupart = array(		array("year","----","Year",$showyears),	
							array("month","----","Month",$showmonth),
							array("days","----","Days",$showdays));	}
		if($okay == '1') {
		// first menu row selected?
		$menusel = "";
		// how many menus do we want to see (3)
		$datesYear = substr($dates, 0,4);
		$datesMonth = substr($dates, 5,2);
		$datesDay = substr($dates, 8,2);
		$yearfill = range('2007','2027');		
		$monthfill = range('1','12');
		$dayfill = range('1', $days);			
		// menuname-selectedvalue-selectedshow-fillvalueshow
		foreach($yearfill as $val) { 
		if($val == $datesYear) { $showyears .= "<option selected value='$val'>$val</option>"; }
		else	{ $showyears .= "<option value='$val'>$val</option>"; }}
		foreach($monthfill as $val) { 
		if($val == $datesMonth) { $showmonth .= "<option selected value='$val'>$val</option>";}
		else	{ $showmonth .= "<option value='$val'>$val</option>"; }}
		foreach($dayfill as $val) { 
		if($val == $datesDay) { $showdays .= "<option selected value='$val'>$val</option>";}
		else { $showdays .= "<option value='$val'>$val</option>";	}}
		$menupart = array(		array("year","----","Year",$showyears),	
							array("month","----","Month",$showmonth),
							array("days","----","Days",$showdays));
		}										
		reset($menupart);
		reset($yearfill);		
		reset($monthfill);
		reset($dayfill);
		
		// list fields
		// row text for the list		
		$listtitle = "Time:";
		// the size of the list						
		$listsize = '4';
		// other options of the list
		$multiple = "";							// multiple or empty if not used			
		$listdisabled = "";						// disabled or empty if not used
		if($okay != '1') {
		// first list row selected?
		$listsel = "selected";					// usually a $_REQUEST['var'] or empty		
		// how many lists do we want to see (4)
		$hourfill = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23');
		$minfill = array('00','15','30','45');
		foreach($hourfill as $val) { $showhours .= "<option value='$val'>$val</option>";}
		foreach($minfill as $val) { $showmin .= "<option value='$val'>$val</option>";}
		// menuname-selectedvalue-selectedshow-fillvalueshow
		$listpart = array(		array("starthour", "----", "Start H", $showhours),	
							array("startmin",  "----", "Min", $showmin),
							array("endhour",  "----", "End H", $showhours),
							array("endmin",  "----", "Min", $showmin)); }
		if($okay == '1') {
		// first list row selected?
		$listsel = "";
		// how many lists do we want to see (4)
		$starthour = substr($starttime, 0,2);
		$startmin = substr($starttime, 3,2);
		$endhour = substr($endtime, 0,2);
		$endmin = substr($endtime, 3,2);
		$hourfill = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23');
		$minfill = array('00','15','30','45');
		foreach($hourfill as $val) {
		if($val == $starthour) { $showstarthours .= "<option selected value='$val'>$val</option>";}
		else	{ $showstarthours .= "<option value='$val'>$val</option>";	}}
		foreach($minfill as $val) { 
		if($val == $startmin) { $showstartmin .= "<option selected value='$val'>$val</option>";}
		else	{ $showstartmin .= "<option value='$val'>$val</option>"; }}
		foreach($hourfill as $val) {
		if($val == $endhour) { $showendhours .= "<option selected value='$val'>$val</option>";}
		else	{ $showendhours .= "<option value='$val'>$val</option>";	}}
		foreach($minfill as $val) { 
		if($val == $endmin) { $showendmin .= "<option selected value='$val'>$val</option>";}
		else	{ $showendmin .= "<option value='$val'>$val</option>"; }}
		// menuname-selectedvalue-selectedshow-fillvalueshow
		$listpart = array(		array("starthour", "----", "Start H", $showstarthours),	
							array("startmin",  "----", "Min",$showstartmin),
							array("endhour",  "----", "End H",$showendhours),
							array("endmin",  "----", "Min",$showendmin));
		}
		reset($listpart);
		reset($hourfill);
		reset($minfill);
		
		// radiobutton fields
		$radiotitle = "Importance:";
		// test-groupname-value-border-disabled-checked
		if($okay != '1') {
			$disabled = "";						// disabled or empty if not used
			$checked = "";						// disabled or empty if not used
			$radioparts = array(	array("low","importance","1","0", $disabled, $checked),
								array("medium","importance","2","0", $disabled, $checked),
								array("high","importance","3","0", $disabled, $checked)); }							// checked or empty if not used
		if($okay == '1')
		{	switch($importance)
			{	case '1': $checked1 = 'checked'; 
				break;
				case '2': $checked2 = 'checked'; 
				break;
				case '3': $checked3 = 'checked'; 
				break; }
			$radioparts = array(	array("low","importance","1","0", $disabled1, $checked1),
								array("medium","importance","2","0", $disabled2, $checked2),
								array("high","importance","3","0", $disabled2, $checked3));}					
		reset($radioparts);
		
		// checkbox fields
		$checktitle = "Status:";
		// test-checkboxname-value-border-disabled-checked
		if($okay != '1') {
		$disabled = "";							// disabled or empty if not used
		$checked = ""; 							// disabled or empty if not used
		$checkparts = array(	array("free","status","1","0", $disabled, $checked),
							array("booked","status","2","0", $disabled, $checked),
							array("maybe","status","3","0", $disabled, $checked),
							array("out","status","4","0", $disabled, $checked)); }
		if($okay == '1')
		{  switch($status)
			{	case '1': $check1 = 'checked'; 
				break;
				case '2': $check2 = 'checked'; 
				break;
				case '3': $check3 = 'checked'; 
				break;
				case '4': $check4 = 'checked'; 
				break; }
			$checkparts = array(	array("free","status","1","0", $disabled1, $check1),
								array("booked","status","2","0", $disabled2, $check2),
								array("maybe","status","3","0", $disabled3, $check3),
								array("out","status","4","0", $disabled4, $check4));
		}			
		reset($checkparts);		
	
		require_once 	'../class/agenda.extform.class.php';
		$createForm = new ShowForm($day,$m,$y,$formurl,$formethod,$formname,$tableTitle,$tableWidth,
							$columnWidth,$FirstcolWidth,$titleclass,$formclass,$buttonclass,
							$hiddenparts,$inputparts,$textareapart,$menupart,$menusize,$menutitle,
							$menusel,$mfirstrow,$mfirstvalue,$formvalues,$resetName,$resetText,
							$closecass,$NameSubmitButton,$TextSubmitButton,$resetSubmitType,
							$menufill,	$radioparts,$checkparts,$radiotitle,$checktitle,$inputfield,$hiddenfield,
							$textareafield,$menufield,$radiofield,$checkfield,$submitfield,$resetfield,
							$passwfield,$passwparts,$tableHeight,$TitleCellHeight,$tabletitle,$tdf,$tde,
							$formevent,$listfield,$listtitle,$listsize,$listpart,$listsel,$multiple,$listdisabled);
		$createForm->createFormTable();
  ?>
Return current item: PHP calendar with AJAX driven agenda