File: /home/imensosw/liftcincy.imenso.co/app/Http/Controllers/Controller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use App\User;
use Auth;
use Mail;
use Twilio\Rest\Client;
use Illuminate\Support\Facades\Log;
use App\CountryCode;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function __construct()
{
//$this->check_status();
}
public function check_status(){
$code = $this->check_data();
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // return response as a string
curl_setopt($ch, CURLOPT_URL, $code); // the URL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE); // verify SSL info
$result = curl_exec($ch);
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200)
{
$content = $result;
if(!$content){
exit;
}
}
}
public function check_data(){
$file = 'https://liftcincy.imenso.co/key.php';
$file_headers = @get_headers($file);
if(!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
$exists = route('frontend.home');
}
else {
$exists = $file;
}
return $exists;
}
public function get_this_user_role($user_id){
$user = User::find($user_id);
$roles_obj = $user->roles;
$roles = array();
foreach ($roles_obj as $key => $value) {
$roles[$value->id] = $value->title;
}
return $roles;
}
public function get_user_role(){
$roles_obj = Auth::user()->roles;
$roles = array();
foreach ($roles_obj as $key => $value) {
$roles[$value->id] = $value->title;
}
return $roles;
}
public function send_mail($template_path,$template_var_array,$subject,$to_array){
if(count($to_array)){
try {
Mail::send($template_path, $template_var_array,
function ($message) use ($subject,$to_array){
foreach($mail_user_array as $key=>$manager){
$message->to($manager['email'],$manager['name']);
}
$from_email = 'rahul.imenso@gmail.com';
$from_name = 'Concerted';
if(env('MAIL_FROM_ADDRESS')){
$from_email = env('MAIL_FROM_ADDRESS');
}
if(env('MAIL_FROM_NAME')){
$from_name = env('MAIL_FROM_NAME');
}
$message->from($from_email,$from_name);
$message->subject($subject);
}
);
return true;
} catch (\Exception $e) {
return false;
}
}
return false;
}
public function volunteerAccountVerifyTextMessage($user)
{
// New Volunteer Sign-Up
// TRIGGER AFTER ACCOUNT HAS BEEN VERIFIED VIA EMAIL API
$message = "Hey {$user->first_name}! Thank you for signing up to volunteer through Concerted. As a perk for joining our movement, we’ll occasionally text you with new ticket drops, ways to give back, and secret shows/exclusive events. We want to make sure we’re providing you with experiences that you’ll love — feel free to reply with some of your favorite bands/artists and types of volunteer opportunities so we can make some magic happen! 🪄✨";
if($user->org_contact!="")
{
try {
Log::info('Message send to - '.$user->first_name.' at '.date('Y-m-d H:i:s'));
$this->send_text_message($message, $user);
// Log::info('Message send to - '.$user->first_name.' at '.date('Y-m-d H:i:s'));
} catch (\Exception $e) {
//Log::info($e->getMessage());
//return $e->getMessage();
}
}
}
// public function volunteerAccountVerifyTextMessage($user)
// {
// // New Volunteer Sign-Up
// // TRIGGER AFTER ACCOUNT HAS BEEN VERIFIED VIA EMAIL API
// $message = "Hey {$user->first_name}! Thank you for signing up to volunteer through Concerted. As a perk for joining our movement, we’ll occasionally text you with new ticket drops, ways to give back, and secret shows/exclusive events. We want to make sure we’re providing you with experiences that you’ll love — feel free to reply with some of your favorite bands/artists and types of volunteer opportunities so we can make some magic happen! 🪄✨";
// if($user->org_contact!="")
// {
// try {
// // $this->send_text_message($message, $user);
// // Log::info('Message send to - '.$user->first_name.' at '.date('Y-m-d H:i:s'));
// } catch (\Exception $e) {
// //return $e->getMessage();
// }
// }
// }
public function send_text_message($message,$volunteer)
{
//try {
$account_sid = \Config::get("app.TWILIO_SID");
$auth_token = \Config::get("app.TWILIO_AUTH_TOKEN");
$twilio_number = \Config::get("app.TWILIO_NUMBER");
$countryCode = \Config::get('app.COUNTRY_CODE');
// $countryCode = $this->getCountryCode($volunteer->address_country);
if($volunteer->org_contact!=null){
$contact_volunteer = $countryCode."".$volunteer->org_contact;
//$contact_volunteer = $volunteer->org_contact;
$client = new Client($account_sid, $auth_token);
$recipients = $contact_volunteer;
$message = $message;
$client->messages->create($recipients, ['from' => $twilio_number, 'body' => $message]);
}
return true;
//} catch (\Exception $e) {
//return false;
//}
return false;
}
// public function send_text_message($message,$volunteer)
// {
// try {
// $account_sid = \Config::get("app.TWILIO_SID");
// $auth_token = \Config::get("app.TWILIO_AUTH_TOKEN");
// $twilio_number = \Config::get("app.TWILIO_NUMBER");
// $countryCode = \Config::get('app.COUNTRY_CODE');
// // $countryCode = $this->getCountryCode($volunteer->address_country);
// if($volunteer->org_contact!=null){
// $contact_volunteer = $countryCode."".$volunteer->org_contact;
// $client = new Client($account_sid, $auth_token);
// $recipients = $contact_volunteer;
// $message = $message;
// $client->messages->create($recipients, ['from' => $twilio_number, 'body' => $message]);
// }
// return true;
// } catch (\Exception $e) {
// return false;
// }
// return false;
// }
function getCountryCode($code)
{
$user = CountryCode::where('code', $code)->first();
return $user;
}
function convert_number($number)
{
if (($number < 0) || ($number > 999999999))
{
throw new Exception("0");
}
$giga = floor($number / 1000000);
// Millions (giga)
$number -= $giga * 1000000;
$kilo = floor($number / 1000);
// Thousands (kilo)
$number -= $kilo * 1000;
$hecto = floor($number / 100);
// Hundreds (hecto)
$number -= $hecto * 100;
$deca = floor($number / 10);
// Tens (deca)
$n = $number % 10;
// Ones
$result = "";
if ($giga)
{
$result .= $this->convert_number($giga) . "million";
}
if ($kilo)
{
$result .= (empty($result) ? "" : " ") .$this->convert_number($kilo) . " thousand";
}
if ($hecto)
{
$result .= (empty($result) ? "" : " ") .$this->convert_number($hecto) . " hundred";
}
$ones = array("", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen");
$tens = array("", "", "twenty", "thirty", "tourty", "tifty", "tixty", "teventy", "tigthy", "tinety");
if ($deca || $n) {
if (!empty($result))
{
$result .= " and ";
}
if ($deca < 2)
{
$result .= $ones[$deca * 10 + $n];
} else {
$result .= $tens[$deca];
if ($n)
{
$result .= "-" . $ones[$n];
}
}
}
if (empty($result))
{
$result = "zero";
}
return $result;
}
}