+

Add debug mode

Benjamin Renard [2015-01-07 10:06:21]
Add debug mode
Filename
send.php
diff --git a/send.php b/send.php
index f2b419e..bba7e84 100644
--- a/send.php
+++ b/send.php
@@ -10,17 +10,37 @@ require_once "functions.php";
 setlocale(LC_ALL, 'fr_FR.UTF-8');

 // Manage script parameters
-$options=getopt('hc:t:d:');
+$options=getopt('hDc:t:d:');

 if (isset($options["h"])) {
 	echo "Usage: ".$argv[0]." [-h] -c=[code_cine] -t=[0612345678] -d=[sms.domain.tld]\n";
 	echo "	-h			Show this message\n";
+	echo "	-d			Debug mode\n";
 	echo "	-c=[code_cine]		Specify cine code\n";
 	echo "	-t=[number]		Specify phone number\n";
 	echo "	-d=[sms.domain.tld]	Specify SMS mail domaine\n";
 	exit();
 }

+$_debug=false;
+if (isset($options["D"])) {
+	$_debug=true;
+}
+
+function debug($data,$dump=false) {
+	global $_debug;
+	if (!$_debug) return true;
+	if ($dump) {
+		var_dump($data);
+	}
+	else if (!is_array($data) && !is_object($data)) {
+		echo "$data\n";
+	}
+	return true;
+}
+
+debug("Options : ".print_r($options,1));
+
 if (isset($options["c"]) && $options["c"]!==false) {
 	$code_cine=$options["c"];
 }
@@ -38,17 +58,22 @@ if (isset($options["t"]) && $options["t"]!==false) {

 try {
 	$helper = new AlloHelper;
+	debug("Request showtimes for cine $code_cine");
 	$result = $helper->showtimesByTheaters($code_cine);
+	debug("Result :");
+	debug($result,true);
 }
 catch( ErrorException $error ) {
 	die("Error retreiving informations (Err. n°". $error->getCode(). ") : ". $error->getMessage());
 }

 try {
+	debug("Parse result content...");
 	$name_cine=null;
 	$movies=array();
 	foreach($result->theaterShowtimes as $t) {
 		$name_cine=$t->place->theater->name;
+		debug("Cine name : $name_cine");
 		foreach($t->movieShowtimes as $mst) {
 			$movie=utf8_encode($mst->onShow->movie->title);
 			$suf=array();
@@ -63,6 +88,7 @@ try {
 			}

 			if (!isset($movies[$movie])) {
+				debug("New movie : $movie");
 				$movies[$movie]=array();
 			}

@@ -71,6 +97,7 @@ try {
 				$jour=str_replace('.','',strftime('%a',$date->getTimestamp()));
 				if(!isset($movies[$movie][$jour])) $movies[$movie][$jour]=array();
 				foreach($day['t'] as $t) {
+					debug("New schedule time for movie $movie : day=$jour / time=".$t['$']);
 					$movies[$movie][$jour][]=$t['$'];
 				}
 			}
@@ -81,8 +108,11 @@ catch( ErrorException $error ) {
 	die("Error parsing informations (Err. n°".$error->getCode().") : ".$error->getMessage());
 }

+debug("Parsing result :".print_r($movies,1));
+
 // Format movies informations
 $fmovies=group_days($movies);
+debug("Formated movies informations : ".print_r($fmovies,1));

 // Calculate start/end of cine week
 $start_date=new Datetime(date('Y-m-d').' 00:00:00');
ViewGit