TimeFrame Statistic Issue - php

I'm having a problem regarding a time frame statistic as you see here: http://www.ivao.ch/rfe_gva/stats . I don't know why but from 1200 to 1300z I've all the flight and this is not correct..I wanna see only the flight for that time..
<?php
for ($i=8;$i<18;$i++) {
if ($i % 2 == 0) {
echo "<div class=\"row margintop20\">";
}
if ($i >= 24) {
$time = ($i-24)*100;
} else {
$time = $i*100;
}
$time100 = $time+100;
?>
How can i solve this problem?

Related

Ajax request from overridden component of joomla template

I'm new guy in joomla and i was searching for the answer a lot of time, but didn't get the result. I have my template in joomla 3.4.5 and i have overridden component com_content and category inside it. I made my file blog.php where i output my calendar. The problem is to send ajax changing month by clickng proper button. There is an error, when i'm trying to send ajax. Seems like joomla bans direct request. I read many articles, like how to use ajax in modules and components, but there is no advice how to use it in overriden component. Please give me detailed answer for my problem.
JHtml::_('jquery.framework');
$document = JFactory::getDocument();
$document->addScript('/space/media/media/js/mainscript.js');
i used that code to include my scriptfile in blog.php
function getAjaxData()
{
echo 'login: ' .$_REQUEST['month'] . '; password: ' . $_REQUEST['year'];
exit;
}
created method to handle my ajax request in blog.php
var j = jQuery.noConflict()
j(document).ready(function(){
j('#next').click(function(){
var month = j(this).data('month');
var year = j(this).data('year');
if(month == 12){
year +=1;
month = 1;
}
else{
month++;
}
j.post("/space/templates/forte/")
j.ajax({
url: "index.php?option=com_content&view=category&task=getAjaxData&format=raw",
type: "POST",
data: {
month: month,
year: year
},
success: function(data){
j('#calendar_wrap').html(data);
}
});
console.log('month: '+month+' year: '+year);
})
j('#prev').click(function(){
var month = j(this).data('month');
var year = j(this).data('year');
if(month == 1){
year -=1;
month = 12;
}
else{
month--;
}
j.ajax({
url: "index.php?option=com_content&view=category&task=getAjaxData&format=raw",
type: "POST",
data: {
month: month,
year: year
},
success: function(data){
j('#calendar_wrap').html(data);
}
});
console.log('month: '+month+' year: '+year);
})
});
mainscript.js, included in blog.php
Synchronous XMLHttpRequest on the main thread is deprecated because of
its detrimental effects to the end user's experience. For more help,
check http://xhr.spec.whatwg.org/
here is the error outputted to browser console
I solve problem with that error by putting that method:
public function getAjaxData()
{
}
In file: /site/components/com_content/controller.php
but, i have one more problem now.
In that method my calendar outputs again, but now we have new values, send by ajax. The code below:
public function getAjaxData()
{
JHtml::_('jquery.framework');
$document = JFactory::getDocument();
$document->addScript('/space/media/media/js/mainscript.js');
function days_in_month($month, $year)
{
// calculate number of days in a month
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
}
// get number of days in needed month
$currentYear = date('Y');
$currentMonth = date('n');
if(isset($_REQUEST['year']))
$currentYear = $_REQUEST['year'];
if(isset($_REQUEST['month']))
$currentMonth = $_REQUEST['month'];
$rusmonth = array('Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь');
$dayofmonth = days_in_month($currentMonth, $currentYear);
// count for days in month
$day_count = 1;
// 1. first week
$num = 0;
for($i = 0; $i < 7; $i++)
{
// get day of week
$dayofweek = date('w',
mktime(0, 0, 0, $currentMonth, $day_count, $currentYear));
// format our values to 1-monday, 6-saturday
$dayofweek = $dayofweek - 1;
if($dayofweek == -1) $dayofweek = 6;
if($dayofweek == $i)
{
// if numbers of week are equal,
// put values into array $week
$week[$num][$i] = $day_count;
$day_count++;
}
else
{
$week[$num][$i] = "";
}
}
// 2. other weeks of month
while(true)
{
$num++;
for($i = 0; $i < 7; $i++)
{
$week[$num][$i] = $day_count;
$day_count++;
// if we got the end of the month exit from loop
if($day_count > $dayofmonth) break;
}
if($day_count > $dayofmonth) break;
}
// 3. output array $week
echo '<div> <span id="prev" data-month="'.$currentMonth.'" data-year="'.$currentYear.'"><</span> '.$rusmonth[$currentMonth-1].' <span id="next" data-month="'.$currentMonth.'" data-year="'.$currentYear.'">></span> </div>';
echo '<div id="calendar_wrap">';
echo '<table border=1>';
echo '<tr>
<th>ПН</th>
<th>ВТ</th>
<th>СР</th>
<th>ЧТ</th>
<th>ПТ</th>
<th>СБ</th>
<th>ВС</th>
</tr>';
for($i = 0; $i < count($week); $i++)
{
echo "<tr>";
for($j = 0; $j < 7; $j++)
{
if(!empty($week[$i][$j]))
{
if($j == 5 || $j == 6)
echo "<td><font color=red>".$week[$i][$j]."</font></td>";
else echo "<td>".$week[$i][$j]."</td>";
}
else echo "<td> </td>";
}
echo "</tr>";
}
echo "</table>";
echo '</div>';
exit;
}
in that method i can't add my script again to get new month.
So there are two ways for me as I see:
1. make my method that way, so he become something like a bridge between blog.php and ajax. There will be no outputs.
Find a way, how could i add script to controller and make double code.
The problem is, that i have no idea, how realize both of it in Joomla...
Of course i prefer 1st variant.

Count how many times strpos accured inside a foreach loop

How can i show how many times a sence was shown while looping?
$i = 0;
foreach ($parts as $new[$i]) {
$abouttoexpire = strpos($new[$i], 'Your Airbnb question is about to expire');
$anairbnbexpert = strpos($new[$i], 'An Airbnb expert is waiting on feedback from you regarding');
$requesttoalter = strpos($new[$i], 'Your request to alter reservation');
//when the message was made
preg_match('/<div class="timestamp"[\s\S]*?>(.*)*?\+0000<\/div>/', $new[$i], $dateofmsg);
//between 9am and 6pm
$hour = date('H', strtotime(#$dateofmsg[1]));
if ($hour >= 9 && $hour <= 18) {
//if we found this sentence
if ($abouttoexpire !== FALSE) {
//how i show here how many times we catch the sentence #abouttoexpire??
}
}
}
$i++;
Inside the condition: if ($abouttoexpire !== FALSE)
How do i print the times this sence (#abouttoexpire) was accured during the loop?
Try this...
$i = 0;
$j = 0;
$k = 0;
foreach ($parts as $new[$i]) {
if ($hour >= 9 && $hour <= 18) {
$j++;
if ($abouttoexpire !== FALSE) {
$k++;
}
}
$i++;
}
echo "foreach loop=".$i;
echo "if loop =".$j;
echo "within if loop =".$k;
$i = 0;$j=0;
foreach ($parts as $new[$i]) {
$abouttoexpire = strpos($new[$i], 'Your Airbnb question is about to expire');
$anairbnbexpert = strpos($new[$i], 'An Airbnb expert is waiting on feedback from you regarding');
$requesttoalter = strpos($new[$i], 'Your request to alter reservation');
//when the message was made
preg_match('/<div class="timestamp"[\s\S]*?>(.*)*?\+0000<\/div>/', $new[$i], $dateofmsg);
//between 9am and 6pm
$hour = date('H', strtotime(#$dateofmsg[1]));
if ($hour >= 9 && $hour <= 18) {
//if we found this sentence
if ($abouttoexpire !== FALSE) {
$j++;
}
}
}
$i++;
echo 'no_of_times:'.$j;

I have an issue with my loops to show the result

$array_of_time = array ();
$start_time = strtotime ("$app_date 07:00");
$end_time = strtotime ("$app_date 22:00");
$mins = 04 * 60;
while ($start_time <= $end_time)
{
$array_of_time[] = date ('h:i a', $start_time);
$start_time += $mins;
}
echo "<div style='width:700px' class='time_slot_div'>";
echo "<p class='time_slot_p'> Time Slot :</p>";
foreach($array_of_time as $key=>$value)
{
for($i = 0; $i < count($app_data); $i++)
{
$book_time=$app_data[$i]["appointment_time"];
if($value==$book_time)
{
echo "<a class='time_slot_a_book'>$value</a> ";
} else {
echo "<a href='#' onclick='get_time_value(\"$value\");' class='time_slot_a'>$value</a> ";
}
}
}
echo "</div>";
Here foreach loop can run as many time as it can as well as for loop also, but i want to show the links that are not matched with the foreach value and for loop value.
The foreach loop values like 7:20 am not from database but the for loop value like 7:20 am is from database so if 7:20 am==7:20 am then the if statement it run it is working fine, but the issue is that it is running 2 time if i get 2 value in for loop. It should run my div only once.
Use a array to store the item that has shown.
<?php
foreach($array_of_time as $key=>$value)
{
$tag_list = array();
for($i = 0; $i < count($app_data); $i++)
{
$book_time=$app_data[$i]["appointment_time"];
// shown, skip
if (isset($tag_list[$book_time]))
{
continue;
}
// mark as show
$tag_list[$book_time] = 1;
if ($value == $book_time)
{
echo "<a class='time_slot_a_book'>$value</a> ";
}
else
{
echo "<a href='#' onclick='get_time_value(\"$value\");' class='time_slot_a'>$value</a> ";
}
}
}

Limiting what content is displayed from MySQL/ PHP

I'm building an interactive timeline that loads in films and calculates the difference between their release dates, thus displaying "days" where there isn't any film release to create a timeline effect. However I have some films that are released on the same date. I don't want to repeat the date for these films over and over again, rather just display the date for the first film in like a group effect.
I have manipulated an if statement that loops through the table and checks whether the date is the same as the previous row's date.
http://ignitethatdesign.com/CheckFilm/test_search.php
However how would I use PHP to only display the date for the first film in a group of films with the same date?
I'm using a complex loop system, here is the full code
<?php
$last_value = null;
echo "<div class=\"timeline\">";
$pNumber = 0;
while ($row = mysql_fetch_assoc($sql)) {
if (!is_null($last_value)) {
$pNumber++;
$a = new DateTime($row['FilmRelease']);
$film_date = $row['FilmRelease'];
$film_name = urldecode($row['FilmName']);
$film_desc = urldecode($row['Synopsis']);
echo "<div id=\"t".$pNumber."\"><p class=\"everyday\">".$film_name."</div>";
if (empty($film_desc)) {
echo "<div id=\"b".$pNumber."\" style=\"font-size:12px;\">No film information for ".$film_name."</div>";
}
else
{
echo "<div id=\"b".$pNumber."\" style=\"font-size:12px;\">".$film_desc."</div>";
}
?> <script type="text/javascript">
$("#b<?php echo $pNumber ?>").hide();
$("#t<?php echo $pNumber ?>").click(function() {
$("#b<?php echo $pNumber ?>").fadeToggle("slow");
});
</script>
<?php
$interval = $a->diff(new DateTime($last_value));
//echo $interval->format('%d days');
$b = new DateTime($last_value);
$i = 0;
}
if ($b == $a)
{
echo "same date as above";
} else
{
echo "This date is different";
}
$howManydays = $interval->days;
for ( $i; $i < $howManydays; $i++) {
echo "<p class=\"day\"></p>";
}
$last_value = $row['FilmRelease'];
}
echo "<div id=\"end\"></end>";
echo "</div>";
?>
Any help would be greatly appreciated :)
Simple example:
$lastDate = null;
while (...) {
$currentDate = date('Y-m-d', strtotime($film['date']));
if ($currentDate != $lastDate) {
echo "<h1>$currentDate</h1>";
}
$lastDate = $currentDate;
// output film details
}
This will give you something like:
2012-04-01
Film A
Film B
2012-04-02
Film C
2012-04-05
Film D
Film E

Sometimes the contents load and sometimes they don't

I have the script below and on the website http://cacrochester.com, sometimes the contents of the right sidebar load and sometimes they don't. I think it's if it's your first few times on a page, it will say no events scheduled.
I'm completely stumped on why this is happening. The data in the database is not changing.
Let me know if you need me to post anymore code.
Thanks for helping!
<?php
$dummy = 0;
$headingLength = 0;
$descriptionLength = 0;
$shortHeading = 0;
$shortDescription = 0;
$todayYear = date('Y');
$todayMonth = date('m');
$todayDay = date('d');
$events = new dates();
$noEvents = 0;
//get the number of upcoming events
$numEvents = $events->getNumberEvents();
//get the actual events
$results = $events->getRows();
//used if there are not at least 5 events to fill up the event scroller
switch($numEvents) {
case 1: $dummy = 4; break;
case 2: $dummy = 3; break;
case 3: $dummy = 2; break;
case 4: $dummy = 1; break;
}
//loops through all of the events in the table and adds them to the list
foreach($results as $result)
{
$strippedHeading = stripslashes($result['heading']);
$strippedDescription = stripslashes($result['description']);
$headingLength = strlen($strippedHeading);
$descriptionLength = strlen($strippedDescription);
$shortHeading = $strippedHeading;
$shortDescription = $strippedDescription;
$time = strftime("%l:%M %P", $result['time']);
$location = $result['location'];
$startDate = getdate($result['start_date']);
$today = getdate();
//if the events are NOT in the past...
if($startDate >= $today)
{
//if we are at the end of the array, add the class 'last' to the li
if(current($result) == end($result))
{
echo "<li class=\"last\"><h4>".$shortHeading."</h4><h6>$time</h6><h6>$location</h6></li>".PHP_EOL;
}
else
{
echo "<li><h4>".$shortHeading."</h4><h6>$time</h6><h6>$location</h6></li>".PHP_EOL;
}
$noEvents = 1;
}
//if there is not at least 5 events, it repeats the events in the list until there are 5 total
elseif($dummy > 0 && $numEvents > 0)
{
//if the events are NOT in the past...
if($startDate >= $today)
{
//if we are at the end of the array, add the class 'last' to the li
if($dummy == 0)
{
echo "<li class=\"last\"><h4>".$shortHeading."</h4> ".$shortDescription."</li>".PHP_EOL;
$dummy--;
}
else
{
echo "<li><h4>".$shortHeading."</h4> ".$shortDescription."</li>".PHP_EOL;
$dummy--;
}
//if we have 5 events, do not add anymore
if($dummy < 0)
{
break;
}
}
$noEvents = 1;
}
}
//if there are no events, display the no events message
if($noEvents == 0)
{
echo "<li class=\"last\"><h4>No Events Scheduled</h4></li>".PHP_EOL;
}
?>
When you do $startDate >= $today you are trying to compare two arrays, which isn't too good an idea. Just use plain timestamps and it should work fine:
$startDate = $result['start_date'];
$today = strtotime('today');
Also, I'm not sure if this is a typo: current($result) == end($result), but shouldn't it be $results, which is the array name?

Categories