04/05/2010, 08:10
|
| | Fecha de Ingreso: enero-2010
Mensajes: 373
Antigüedad: 14 años, 10 meses Puntos: 5 | |
Respuesta: funcion switch Vale aqui te lo dejo Cita: <?php
include('databaseConnection.php');
include('settings.php');
$action = $_POST['action'];
switch($action) {
case 'startCalendar':
$month = $_POST['month'];
$year = $_POST['year'];
if(($month == 0) || ($year == 0)) {
$thisDate = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
} else {
$thisDate = mktime(0, 0, 0, $month, 1, $year);
}
echo '<div style="margin-bottom: 3px;">
<form name="changeCalendarDate">
<select id="ccMonth" onChange="startCalendar($F(\'ccMonth\'), $F(\'ccYear\'))">';
for($i=0; $i<=11; $i++)
{
$monthNumber = ($i+1);
$monthMaker = mktime(0, 0, 0, $monthNumber, 1, 2006);
if($month > 0) {
if($month == $monthNumber) {
$sel = 'selected';
} else {
$sel = '';
}
} else {
if(date("m", $thisDate) == $monthNumber) {
$sel = 'selected';
} else {
$sel = '';
}
}
/*
************************************************** ************************************************** ****
Change the names in here to your language - DO NOT CHANGE ANYTHING ELSE UNLESS YOU UNDERSTAND IT
************************************************** ************************************************** ****
*/
$monthName = array('January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December');
echo '<option value="'. $monthNumber .'" '. $sel .'>'. $monthName[$i] .'</option>';
}
echo '</select>
<select id="ccYear" onChange="startCalendar($F(\'ccMonth\'), $F(\'ccYear\'))">';
$yStart = 2006;
$yEnd = ($yStart + 4);
for($i=$yStart; $i<$yEnd; $i++)
{
if($year > 0) {
if($year == $i) {
$sel = 'selected';
} else {
$sel = '';
}
} else {
if(date("Y", $thisDate) == $i) {
$sel = 'selected';
} else {
$sel = '';
}
}
echo '<option value="'. $i .'" '. $sel .'>'. $i .'</option>';
}
echo '</select>';
// Check if they are loggedin.
if($_COOKIE['nodstrumCalendarV2']) {
echo ' <a href="#" onClick="showCP();">Control Panel</a>';
} else {
echo ' <a href="#" onClick="showLoginBox();">Login</a>';
}
echo '</form>
</div>';
// Display the week days.
echo '<div class="calendarFloat" style="text-align: center; background-color: #'. $dayColor .';"><span style="position: relative; top: 4px;">L</span></div>
<div class="calendarFloat" style="text-align: center; background-color: #'. $dayColor .';"><span style="position: relative; top: 4px;">Tue</span></div>
<div class="calendarFloat" style="text-align: center; background-color: #'. $dayColor .';"><span style="position: relative; top: 4px;">Wed</span></div>
<div class="calendarFloat" style="text-align: center; background-color: #'. $dayColor .';"><span style="position: relative; top: 4px;">Thur</span></div>
<div class="calendarFloat" style="text-align: center; background-color: #'. $dayColor .';"><span style="position: relative; top: 4px;">Fri</span></div>
<div class="calendarFloat" style="text-align: center; background-color: #'. $weekendColor .';"><span style="position: relative; top: 4px;">Sat</span></div>
<div class="calendarFloat" style="text-align: center; background-color: #'. $weekendColor .';"><span style="position: relative; top: 4px;">Sun</span></div>';
// Show the calendar.
for($i=0; $i<date("t", $thisDate); $i++)
{
$thisDay = ($i + 1);
if(($month == 0) || ($year == 0)) {
$finalDate = mktime(0, 0, 0, date("m"), $thisDay, date("Y"));
$today = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
$fdf = mktime(0, 0, 0, date("m"), 1, date("Y"));
$month = date("m");
$year = date("Y");
} else {
$finalDate = mktime(0, 0, 0, $month, $thisDay, $year);
$fdf = mktime(0, 0, 0, $month, 1, $year);
}
// Skip some cells to take into account for the weekdays.
if($i == 0) {
$firstDay = date("w", $fdf);
$skip = ($firstDay - 1);
if($skip < 0) { $skip = 6; }
for($s=0; $s<$skip; $s++)
{
echo '<div class="calendarFloat" style="border: 1px solid #FFF;"> </div>';
}
}
// Make the weekends a darker colour.
if((date("w", $finalDate) == 0) || (date("w", $finalDate) == 6)) {
$bgColor = '#'. $weekendColor .'';
} else {
$bgColor = '#'. $dayColor .'';
}
// Determine what they should see if they are logged in or not.
if($_COOKIE['nodstrumCalendarV2']) {
$onClick = 'showEventForm('. $thisDay .')';
} else {
// displayEvents(day, $F('ccMonth'), $F('ccYear'));
$onClick = 'displayEvents('. $thisDay .', '. $month .', '. $year .')';
}
// Check the database for any events on this day.
include 'consulta.php';
}
break;
case 'listEvents':
$day = $_POST['d'];
$month = $_POST['m'];
$year = $_POST['y'];
$timeStamp = mktime(0,0,0, $month, $day, $year);
$eventQuery = mysql_query("SELECT * FROM event WHERE timestamp='$timeStamp' ORDER BY id DESC", $conn);
if($eventQuery) {
if(mysql_num_rows($eventQuery) >0) {
echo '<br><b>Events on: '. date("d", $timeStamp) .'/'. date("m", $timeStamp) .'/'. date("Y", $timeStamp) .'</b>';
for($i=0; $i<mysql_num_rows($eventQuery); $i++) {
if($i % 2) { $bgColor = '#'. $iteratorColor1 .''; } else { $bgColor='#'. $iteratorColor2 .''; }
extract(mysql_fetch_array($eventQuery), EXTR_PREFIX_ALL, 'e');
if($_COOKIE['nodstrumCalendarV2']) {
echo '<div style="background-color: '. $bgColor .'; margin-bottom: 4px; padding: 1px;" id="event_'.$e_id.'">
<div>
'. nl2br($e_body) .'
</div>
<div style="font-size: 9px;">
<span style="color: blue; text-decoration: underline; cursor: pointer;" onClick="deleteEvent('.$e_id.')">
Delete this event
</span>
</div>
</div>';
} else {
echo '<div style="background-color: '. $bgColor .'; margin-bottom: 4px; padding: 1px;">
'. nl2br($e_body) .'
</div>';
}
} // for.
} else {
echo 'There are no events here yet';
}
} else {
echo 'Error getting the results.';
}
break;
case 'addEvent':
$day = $_POST['d'];
$month = $_POST['m'];
$year = $_POST['y'];
$body = $_POST['body'];
$timeStamp = mktime(0,0,0, $month, $day, $year);
$bodyF = addslashes(trim($body));
$addEvent = mysql_query("INSERT INTO event (body, timestamp) VALUES ('$body', '$timeStamp')", $conn);
break;
case 'deleteEvent':
if($_COOKIE['nodstrumCalendarV2']) {
$eid = $_POST['eid'];
if(is_numeric($eid)) {
$deleteIt = mysql_query("DELETE FROM event WHERE id='$eid' LIMIT 1", $conn);
} else {
// Dont do anything.
}
} else {
// Dont delete it.
}
default:
break;
}
?> las opciones del switch las recibe de un javascript |