-
Notifications
You must be signed in to change notification settings - Fork 35
/
index.php
79 lines (72 loc) · 2.13 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
header('Content-type: text/html; charset=utf-8');
if (isset($_GET['about'])){
include 'views/about.inc';
return;
}
// $_GET['ajax'] should be set by the javascript in an ajax call.
$ajax = isset($ajax)? true : (isset($_GET['ajax'])? true : false);
$format = (isset($_GET['rss'])? 'rss' :
(isset($_GET['json'])? 'json' : 'html'));
$q = "";
$data = null;
if (isset($_GET['q'])){
include 'prayertimes.inc';
$q = $_GET['q'];
if (strlen($q) > 0){
$method = 4;
if (isset($_GET['method'])){
$meth = $_GET['method'];
if ((is_numeric($meth)) && ($meth > 0) && ($meth < 8))
$method = $meth;
}
$data = PrayerTimes::getPrayerTimes($q, $method);
if ($data['type']=='error'){
print $data['msg'];
$data = null;
}
}
}
if (!is_null($data)){
if ($data['type']=='search_results'){
if ($format == 'html') {
$search_results = $data['data'];
if ($ajax) include 'views/locsearch.inc';
else include 'views/main.inc';
} else {
header("Content-Type: application/json");
print '{}';
return;
}
}
else showSalatTimes($data['location'], $data['data'],
$format, $method, $ajax);
return;
}
else if ($ajax) return;
else include 'views/main.inc';
function showSalatTimes($location, $pt, $format, $method, $ajax = true){
global $q; // don't like this, but...
$data = array();
$times = array(0 => "Fajr", 1 => "Shurooq", 2 => "Dhuhr",
3 => "'Asr", 4 => "Maghrib", 5 => "'Isha");
foreach ($times as $key => $val){
$min = $pt[$key]['minute'];
$hour = $pt[$key]['hour'];
$time_of_day = 'am';
if ($hour >= 12) {
$time_of_day = 'pm';
if ($hour > 12) $hour -= 12;
}
if ($min < 10) $min = "0$min";
$time = $hour . ":" . $min . " $time_of_day";
$data[$val] = $time;
}
if ($format == 'rss')
include 'views/salatrss.inc';
else if ($format == 'json')
include 'views/salatjson.inc';
else if (!$ajax) include 'views/main.inc';
else include 'views/salatimes.inc';
}
?>