Zionetrix::Git
Repositories
Help
Report an Issue
cinememe
Code
Commits
Branches
Tags
Search
Tree:
a1235f3
Branches
Tags
master
cinememe
send.php
Leave possibility to run script without sending SMS (just display)
Benjamin Renard
commited
a1235f3
at 2015-01-07 09:39:48
send.php
Blame
History
Raw
<?php error_reporting(E_ERROR); @require_once "lib/api-allocine-helper/api-allocine-helper.php"; require_once "functions.php"; // Retreive local from environnement setlocale(LC_ALL, ''); // Manage script parameters $options=getopt('hc: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 " -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(); } if (isset($options["c"]) && $options["c"]!==false) { $code_cine=$options["c"]; } else die("You must provide cine code with -c=XXX parameter.\n"); $send_to=false; $mail_domain=false; if (isset($options["t"]) && $options["t"]!==false) { $send_to=$options["t"]; if (isset($options["d"]) && $options["d"]!==false) { $mail_domain=$options["d"]; } else die("You must provide SMS mail domain with -d=domain.tld parameter.\n"); } try { $helper = new AlloHelper; $result = $helper->showtimesByTheaters($code_cine); } catch( ErrorException $error ) { die("Error retreiving informations (Err. n°". $error->getCode(). ") : ". $error->getMessage()); } try { $name_cine=null; $movies=array(); foreach($result->theaterShowtimes as $t) { $name_cine=$t->place->theater->name; foreach($t->movieShowtimes as $mst) { $movie=utf8_encode($mst->onShow->movie->title); $suf=array(); if ($mst->screenFormat['$']=='3D') { $suf[]='3D'; } if ($mst->version->code!=6001) { $suf[]='VO'; } if(count($suf)>0) { $movie.=' ('.implode('/',$suf).')'; } if (!isset($movies[$movie])) { $movies[$movie]=array(); } foreach($mst->scr as $day) { $date=DateTime::createFromFormat('Y-m-d',$day['d']); $jour=str_replace('.','',strftime('%a',$date->getTimestamp())); if(!isset($movies[$movie][$jour])) $movies[$movie][$jour]=array(); foreach($day['t'] as $t) { $movies[$movie][$jour][]=$t['$']; } } } } } catch( ErrorException $error ) { die("Error parsing informations (Err. n°".$error->getCode().") : ".$error->getMessage()); } // Format movies informations $fmovies=group_days($movies); // Calculate start/end of cine week $start_date=new Datetime(date('Y-m-d').' 00:00:00'); $start=$start_date->format('d/m'); $start_time=$start_date->getTimestamp(); $start_wd=(int)date('N',$start_time); $end_time=$start_time+(24*3600*((9-$start_wd)%7)); $end=date('d/m',$end_time); // Format Message $msg="Cinema $name_cine\nProgramme du $start au $end\n"; foreach($fmovies as $m => $ps){ $msg.="$m : "; $hss=array(); foreach($ps as $p => $hs) { $hss[]="$p ".implode(' & ',$hs); } $msg.=implode(' / ',$hss)."\n"; } // Remove accents $msg=$msg=withoutAccents($msg); if ($send_to && $mail_domain) { // Format mail $mail="$send_to@$mail_domain"; // Display message echo "Send to $mail :\n\n$msg"; // Send message mail($mail,'',$msg); } else { echo "$msg"; }