output->set_content_type('application/json');
$current->output->set_output(json_encode($result));
$current->output->_display();
exit();
}
function generate_random_keys($length)
{
$random= "";
srand((double)microtime()*1000000);
$data = "AbcDE123IJKLMN67QRSTUVWXYZ";
$data .= "aBCdefghijklmn123opq45rs67tuv89wxyz";
$data .= "0FGH45OP89";
for($i = 0; $i < $length; $i++)
{
$random .= substr($data, (rand()%(strlen($data))), 1);
}
return $random;
}
function read_default_styles($filename)
{
$filestring = file_get_contents($filename);
$filearray = explode("\n", $filestring);
return $filearray;
}
function cleanQuery($string)
{
if(get_magic_quotes_gpc()) // prevents duplicate backslashes
{
$string = stripslashes($string);
}
if (phpversion() >= '4.3.0')
{
$string = mysql_real_escape_string($string);
}
else
{
$string = mysql_escape_string($string);
}
return $string;
}
function translate_date_in_french($date) {
$eng = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', '/');
$fr = array('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre', ' ');
$month = str_replace($eng, $fr, $date);
echo strtolower($month);
}
function translate_day_in_french($date) {
$eng = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', '/');
$fr = array('lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche');
$day = str_replace($eng, $fr, $date);
echo $day;
}
function start_date ($reservation_start_date){
$splits = explode(" ", $reservation_start_date);
$date = $splits[0];
$hours = explode(":", $splits[1]);
$newHours = $hours[0]."h".$hours[1];
$week_name = array("dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi");
$month_name= array("","janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre");
$split = preg_split('/-/', $date);
$year = $split[0];
$month = round($split[1]);
$day = round($split[2]);
$week_day = date("w", mktime(12, 0, 0, $month, $day, $year));
return $date_fr = "
Ouverture des réservations :
".$week_name[$week_day] .' '. $day .' '. strtolower($month_name[$month]) .' '. $year.', à '.$newHours."";
}
function date_in_french($reservation_end_date){
if($reservation_end_date==''){
return "";
}else{
$splits = explode(" ", $reservation_end_date);
$date = $splits[0];
$hours = explode(":", $splits[1]);
$newHours = $hours[0]."h".$hours[1];
$week_name = array("dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi");
$month_name= array("","janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre");
$split = preg_split('/-/', $date);
$year = $split[0];
$month = round($split[1]);
$day = round($split[2]);
if($day>=10){
$add ='';
}else{
$add ='0';
}
$week_day = date("w", mktime(12, 0, 0, $month, $day, $year));
return $date_fr = " ".$week_name[$week_day] .' '.$add. $day .' '. $month_name[$month] ." ". $year.', à '.$newHours." ";
}
}
function xss_protection(){
if($_POST) {
foreach($_POST as $key=>$value){
$_POST[$key] = strip_tags($_POST[$key]);
}
} else {
foreach($_GET as $key=>$value){
$_GET[$key] = strip_tags($_GET[$key]);
}
}
//will still review tickets for formatting
}
function secondsToTime($inputSeconds) {
$secondsInAMinute = 60;
$secondsInAnHour = 60 * $secondsInAMinute;
$secondsInADay = 24 * $secondsInAnHour;
// Extract days
$days = floor($inputSeconds / $secondsInADay);
// Extract hours
$hourSeconds = $inputSeconds % $secondsInADay;
$hours = floor($hourSeconds / $secondsInAnHour);
// Extract minutes
$minuteSeconds = $hourSeconds % $secondsInAnHour;
$minutes = floor($minuteSeconds / $secondsInAMinute);
// Extract the remaining seconds
$remainingSeconds = $minuteSeconds % $secondsInAMinute;
$seconds = ceil($remainingSeconds);
// Format and return
$timeParts = [];
$sections = [
'jour' => (int)$days,
'heure' => (int)$hours,
'minute' => (int)$minutes,
// 'second' => (int)$seconds,
];
foreach ($sections as $name => $value){
if ($value > 0){
$name = $name.($value == 1 ? '' : 's');
if($name=="heures") {
// $name.=" et ";
}
$timeParts[] = $value. ' '.$name;
}
}
return implode(', ', $timeParts);
}
function validatePostalCode($countryCode, $postalCode)
{
$CI =& get_instance();
$CI->load->library("postalcodechecker");
return $CI->postalcodechecker->isValid($countryCode, $postalCode);
}
function validatePhoneNumber($countryCode, $phone)
{
if (in_array($countryCode, ["FR", "FX"])) {
//check if country code in phone number is correct
$phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$phoneObj = ($phoneNumberUtil->getExampleNumberForType($countryCode, \libphonenumber\PhoneNumberType::MOBILE));
$country_Code = "";
if ($phoneObj !== null) {
$country_Code = $phoneObj->getCountryCode();
}
$val = explode("]", $phone);
$finalval = str_replace("[", "", $val[0]);
//option one
if($finalval=='333') {
return true;
}
if($finalval!=$country_Code) {
return false;
}
if(strpos($phone, 'X') != false){
return "empty";
}
$phone = preg_replace('/\+?\[\d+\] /', '', $phone);
$string = $phone;
$length = 0;
$i = 0;
while(isset($string[$i]))
{
if($string[$i] != ' ') $length++;
$i++;
}
if ($length < 9) {
return "invalide";
}
$numberProto = $phoneNumberUtil->parse($phone, $countryCode);
return $phoneNumberUtil->isValidNumber($numberProto);
}
else {
//check if country code in phone number is correct
$phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$phoneObj = ($phoneNumberUtil->getExampleNumberForType($countryCode, \libphonenumber\PhoneNumberType::MOBILE));
$country_Code = "";
if(strpos($phone, 'X') != false){
return "empty";
}
$phone_len = preg_replace('/\+?\[\d+\] /', '', $phone);
$string = $phone_len;
$length = 0;
$i = 0;
while(isset($string[$i]))
{
if($string[$i] != ' ') $length++;
$i++;
}
if ($length < 9) {
return "invalide";
}
if ($phoneObj !== null) {
$country_Code = $phoneObj->getCountryCode();
}
$val = explode("]", $phone);
$finalval = str_replace("[", "", $val[0]);
if($finalval!=$country_Code) {
return false;
}
// check if inputs are all DIGITS
$phone = str_replace(array("[", "]", " ", "+"), "", $phone);
if (!ctype_digit($phone)) {
return false;
}
return true;
}
}
function validatePhoneNumberEmpty($countryCode, $phone)
{
if(strpos($phone, 'X') !== false){
return false;
}
}
function customEmailFormat($emailTemplate, $emailValues) {
$emailTpl = urldecode($emailTemplate);
if (isset($emailValues->event_start_hour) && !$emailValues->event_start_hour) {
$emailTpl = str_replace(', à [[var:event_start_hour]]', '', $emailTpl);
}
if (isset($emailValues->event_postal_code) && !$emailValues->event_postal_code) {
$emailTpl = str_replace(', [[var:event_postal_code]]', ',', $emailTpl);
}
return $emailTpl;
}