Så fik jeg endelig lavet min php kode om til JavaScript, og flyttet det til uddannelse.php
Så nu virker min reserver funktion :-)
Jeg har indtil videre beholdt al js i samme fil.
har forsøgt at gemme det i kal.js og kaldt filen via denne kode:
- <SCRIPT TYPE="text/javascript" SRC="JavaScripts/kal.js"></SCRIPT>
men filen bliver ikke indlæst..
kal.php er blevet modificeret så den nu udskriver følgende for Januar måned:
["17","19","22","23","24","25","26","27","28","28","31"]
hvilket er de dage som er "optaget"
http://prosalg.nu/kal_4.php?month=01&year=2018- <?php
- session_start();
- require_once(".....");
- require_once('....class_kalender.php');
- $kal = new kalender();
- $year = $_GET['year'];
- $month_number = $_GET['month'];
- $number_of_days = cal_days_in_month(CAL_GREGORIAN, $month_number, $year);
- $start = mktime(0, 0, 0, $month_number, 01, $year);
- $dato_start = $year."-".$month_number."-01";
- $dato_slut = $year."-".$month_number."-".$number_of_days;
- $kal->optaget($dato_start, $dato_slut);
- $optag = array(2,6,9);//
- $optaget = $kal->getOptaget();
- echo json_encode($optaget);
- ?>
uddannelse.php:
https://prosalg.nu/uddannelse_4.php?uddannelse=2- <?php
- session_start();
- require_once(".......");
- require_once(".....class_uddannelse.php");
- require_once(".....class_book.php");
- require_once('.....class_kalender.php');
- $kal = new kalender();
- $title = "uddannelse";
- $get = $_GET['uddannelse'];
- $uddan = new uddannelse();
- $SetUdd = $uddan->setUddannelse($get);
- $GetUdd = $uddan->getUddannelse();
- $results = $GetUdd->fetchAll(PDO::FETCH_ASSOC)[0];
- $title = $results['udd'];
- $description = substr($results['beskrivelse'], 0, 160);
- print_header($title, $description, $kontakt);
- /*
- <SCRIPT TYPE="text/javascript" SRC="JavaScripts/reserver.js"></SCRIPT>
- <SCRIPT TYPE="text/javascript" SRC="JavaScripts/kal.js"></SCRIPT>
- */
- ?>
- <script>
- var d = new Date();
- var month = d.getMonth();
- var year = d.getFullYear();
- var number_of_days = daysInMonth(month,year);
- var dags_nummer = getDay();
-
- function mName(number)
- {
- var mn;
- switch (number)
- {
- case 1:
- mn = "Januar";
- break;
- case 2:
- mn = "Februar";
- break;
- case 3:
- mn = "Marts";
- break;
- case 4:
- mn = "April";
- break;
- case 5:
- mn = "Maj";
- break;
- case 6:
- mn = "Juni";
- break;
- case 7:
- mn = "Juli";
- break;
- case 8:
- mn = "August";
- break;
- case 9:
- mn = "September";
- break;
- case 10:
- mn = "Oktober";
- break;
- case 11:
- mn = "November";
- break;
- case 12:
- mn = "December";
- }
- return mn;
- }
- function load()
- {
- month = month + 1;
- var m = mName(month);
- document.getElementById("showMonth").innerHTML = m;
- document.getElementById("showYear").innerHTML = year;
- datoer(year, month);
- }
-
- function next()
- {
- month += 1;
- if (month > 12) { year += 1; month = 1; }
- var m = mName(month);
- document.getElementById("showMonth").innerHTML = m;
- document.getElementById("showYear").innerHTML = year;
- datoer(year, month);
- }
- function prev()
- {
- month -= 1;
- if (month < 1) { year -= 1; month = 12; }
- var m = mName(month);
- document.getElementById("showMonth").innerHTML = m;
- document.getElementById("showYear").innerHTML = year;
- datoer(year, month);
- }
- function get(m, y)
- {
- if (window.XMLHttpRequest)
- {
- // code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp = new XMLHttpRequest();
- }
- else
- {
- // code for IE6, IE5
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange = function()
- {
- if (this.readyState == 4 && this.status == 200)
- {
- document.getElementById("days").innerHTML = this.responseText;
- }
- }
- xmlhttp.open("GET","kal_4.php?month="+ m + "&year=" + y,true);
- xmlhttp.send();
- }
-
- function reserver(dato)
- {
- var dato = dato;
- document.getElementById("test").value = dato;
-
- }
-
- function ugedage()
- {
- var days;
- days = ["Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag", "Søndag"];
-
- document.getElementById("weekdays").innerHTML = days;
- }
-
- // Sikrer at datoerne bliver vist korrekt, dagens nummer i ugen
- function blank(dato)
- {
-
-
- }
- function datoer(param_year, param_month)
- {
- //blanks
- var dat = param_year +'-' + param_month + '-' + '-01';
- var dsplit = dat.split("-");
- var newdate =new Date(dsplit[0],dsplit[1]-1,dsplit[2]);
- var count = 1;
- var blank = newdate.getDay();
- var blanks = "";
- while (count <= blank)
- {
- blanks += '<li class="blank"></li>';
- count++;
- }
- //datoer
- var ledig = "";
- var dato_start = 1;
- var dato_slut = new Date(param_year, param_month, 0).getDate();
- var optaget = get(month, year);
- while(dato_start <= dato_slut)
- {
- if(dato_start<10)
- {
- dato_start='0'+dato_start;
- }
- if(month<10)
- {
- mm ='0'+month;
- }
- var valg = dato_start + '-' + mm + '-' + year;
- ledig += '<li class="ledig"><button value ="' + valg + '" onclick="reserver(this.value)">' + dato_start + '</button></li>';
- dato_start++;
- }
- document.getElementById("blank").innerHTML = blanks + ledig;
- document.getElementById("ledig").value = valg;
- }
-
- function reserver(dato)
- {
- var dato = dato;
- document.getElementById("dato").value = dato;
- }
- </script>
- <body onload="load();">
-
-
- <?php include_once("elements/top-menu.php"); ?>
-
- <section id="pageheader" class="section pageheader">
- <div class="container">
- <div class="col-md-8 col-md-offset-2 text-center">
- <h1><?php echo $title; ?></h1>
- </div>
- </div>
- </section>
-
-
- <section id="download" class="section feature" style="margin-bottom:0;">
- <div class="container">
- <div class="col-md-6">
-
- <h2><?php echo $title; ?></h2>
- <p><?php echo $results['beskrivelse']; ?></p>
-
- <p><strong>Varighed: <?php echo $results['varighed']; ?> Minutter</strong></p>
-
- <p><?php echo $results['kompetance_beskrivelse']; ?></p>
-
- <p><strong>Max. deltager antal: <?php echo $results['max_antal_deltagere']; ?></strong></p>
-
- <p><strong>Pris: <?php echo $results['pris_virksomhed']; ?> kr. Eksl. moms</strong></p>
-
-
- </div>
-
-
- <div class="col-md-6">
- <p>
- <img src="images/uddannelser/<?php echo $results['billede']; ?>" class="img-responsive" />
- </p>
-
-
- <fieldset>
- <legend>Tilmelding</legend>
- <div class="month">
- <ul>
- <li class="prev"><button class="btn btn-warning" id="prev_month" onclick="prev()">❮</button></li>
- <li class="next"><button class="btn btn-warning" id="next_month" onclick="next()">❯</button></li>
- <li id="showMonth"></li><li id="showYear"></li>
- </ul>
- </div>
-
- <ul class="weekdays">
- <?php foreach ($kal->ugedage() as $day)
- {
- echo "<li class='weekdays'>".$day."</li>";
- }
- ?>
- </ul>
- <ul class="days" id ="blank">
- <li class ="optaget"></li>
- <li class ="ledig"></li>
- </ul>
-
- <form class="well form-horizontal" action="book.php" method="post" name="book">
- <!-- Tidspunkt -->
- <div class="form-group">
- <label class="col-md-4 control-label">Ønsket dato for afholdelse?</label>
- <div class="col-md-8 inputGroupContainer">
- <div class="input-group">
- <span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span>
- <input id="dato" name="dato" value ="" class="form-control" type="text">
- </div>
- </div>
- </div>
-
- <div class="form-group">
- <label class="col-md-4 control-label">Ønsket starttidspunkt for afholdelse?</label>
- <div class="col-md-8 inputGroupContainer">
- <div class="input-group">
- <span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span>
- <input name="tid" value="08:00" class="form-control" type="time">
- </div>
- </div>
- </div>
-
- <input type ="hidden" name ="udd" value="<?php echo $get;?>">
- <input type="hidden" name="navn" value="<?php echo $results['udd']; ?>">
- <input type="hidden" name="pris" value="<?php echo $results['pris_virksomhed']; ?> ">
-
- <!-- Button -->
- <div class="form-group">
- <label class="col-md-4 control-label"></label>
- <div class="col-md-8">
- <button type="submit" class="btn btn-warning" >Book <span class="glyphicon glyphicon-ok"></span></button>
- </div>
- </div>
-
- </fieldset>
- </form>
- </div>
-
- </div>
- </section>
-
- <?php include_once("elements/footer.php"); ?>
- <?php include_once("elements/footer-scripts.php"); ?>
-
- </body>
- </html>
Så langt så godt, nu er det "kun" følgende funktion som volder mig problemer:
- function get(m, y)
- {
- if (window.XMLHttpRequest)
- {
- // code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp = new XMLHttpRequest();
- }
- else
- {
- // code for IE6, IE5
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange = function()
- {
- if (this.readyState == 4 && this.status == 200)
- {
- document.getElementById("days").innerHTML = this.responseText;
- }
- }
- xmlhttp.open("GET","kal_4.php?month="+ m + "&year=" + y,true);
- xmlhttp.send();
- }
i stedet for at skrive kal_4.php til days, kan der så oprettes et js array som jeg kan arbejde med?
eks.: var optaget = this.responseText; return optaget;
så kunne jeg måske lave denne form for sammenligning som jeg gjorde i php:
- if (in_array($date, $optaget))
- { ?> <li class ="optaget"><span class="optaget"><?php echo $date;?></span></li><?php }
Indlæg senest redigeret d. 31.01.2018 07:58 af Bruger #16819