Add debug mode
Benjamin Renard

Benjamin Renard commited on 2015-01-07 10:06:21
Showing 1 changed files, with 31 additions and 1 deletions.

... ...
@@ -10,17 +10,37 @@ require_once "functions.php";
10 10
 setlocale(LC_ALL, 'fr_FR.UTF-8');
11 11
 
12 12
 // Manage script parameters
13
-$options=getopt('hc:t:d:');
13
+$options=getopt('hDc:t:d:');
14 14
 
15 15
 if (isset($options["h"])) {
16 16
 	echo "Usage: ".$argv[0]." [-h] -c=[code_cine] -t=[0612345678] -d=[sms.domain.tld]\n";
17 17
 	echo "	-h			Show this message\n";
18
+	echo "	-d			Debug mode\n";
18 19
 	echo "	-c=[code_cine]		Specify cine code\n";
19 20
 	echo "	-t=[number]		Specify phone number\n";
20 21
 	echo "	-d=[sms.domain.tld]	Specify SMS mail domaine\n";
21 22
 	exit();
22 23
 }
23 24
 
25
+$_debug=false;
26
+if (isset($options["D"])) {
27
+	$_debug=true;
28
+}
29
+
30
+function debug($data,$dump=false) {
31
+	global $_debug;
32
+	if (!$_debug) return true;
33
+	if ($dump) {
34
+		var_dump($data);
35
+	}
36
+	else if (!is_array($data) && !is_object($data)) {
37
+		echo "$data\n";
38
+	}
39
+	return true;
40
+}
41
+
42
+debug("Options : ".print_r($options,1));
43
+
24 44
 if (isset($options["c"]) && $options["c"]!==false) {
25 45
 	$code_cine=$options["c"];
26 46
 }
... ...
@@ -38,17 +58,22 @@ if (isset($options["t"]) && $options["t"]!==false) {
38 58
 
39 59
 try {
40 60
 	$helper = new AlloHelper;
61
+	debug("Request showtimes for cine $code_cine");
41 62
 	$result = $helper->showtimesByTheaters($code_cine);
63
+	debug("Result :");
64
+	debug($result,true);
42 65
 }
43 66
 catch( ErrorException $error ) {
44 67
 	die("Error retreiving informations (Err. n°". $error->getCode(). ") : ". $error->getMessage());
45 68
 }
46 69
 
47 70
 try {
71
+	debug("Parse result content...");
48 72
 	$name_cine=null;
49 73
 	$movies=array();
50 74
 	foreach($result->theaterShowtimes as $t) {
51 75
 		$name_cine=$t->place->theater->name;
76
+		debug("Cine name : $name_cine");
52 77
 		foreach($t->movieShowtimes as $mst) {
53 78
 			$movie=utf8_encode($mst->onShow->movie->title);
54 79
 			$suf=array();
... ...
@@ -63,6 +88,7 @@ try {
63 88
 			}
64 89
 	
65 90
 			if (!isset($movies[$movie])) {
91
+				debug("New movie : $movie");
66 92
 				$movies[$movie]=array();
67 93
 			}
68 94
 	
... ...
@@ -71,6 +97,7 @@ try {
71 97
 				$jour=str_replace('.','',strftime('%a',$date->getTimestamp()));
72 98
 				if(!isset($movies[$movie][$jour])) $movies[$movie][$jour]=array();
73 99
 				foreach($day['t'] as $t) {
100
+					debug("New schedule time for movie $movie : day=$jour / time=".$t['$']);
74 101
 					$movies[$movie][$jour][]=$t['$'];
75 102
 				}
76 103
 			}
... ...
@@ -81,8 +108,11 @@ catch( ErrorException $error ) {
81 108
 	die("Error parsing informations (Err. n°".$error->getCode().") : ".$error->getMessage());
82 109
 }
83 110
 
111
+debug("Parsing result :".print_r($movies,1));
112
+
84 113
 // Format movies informations
85 114
 $fmovies=group_days($movies);
115
+debug("Formated movies informations : ".print_r($fmovies,1));
86 116
 
87 117
 // Calculate start/end of cine week
88 118
 $start_date=new Datetime(date('Y-m-d').' 00:00:00');
89 119