/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $webinars = Webinar::all();
     $faker = Faker\Factory::create();
     foreach ($webinars as $webinar) {
         for ($i = 0; $i < 5; $i++) {
             QA::create(['webinar_id' => $webinar->id, 'subscriber_id' => rand(1, 9), 'panelist_id' => rand(1, 3), 'question' => $faker->realText($faker->numberBetween(60, 80)), 'answer' => $faker->realText($faker->numberBetween(90, 120)), 'public' => 1]);
         }
     }
 }
function decodeWebinar($webinarHash)
{
    $hashids = new Hashids\Hashids(config('gtw.hashid.salts.webinars'), 20, config('gtw.hashid.hash_chars'));
    $ids = null;
    try {
        $ids = $hashids->decode($webinarHash);
    } catch (\Exception $e) {
    }
    if (count($ids) == 0) {
        return null;
    }
    return Webinar::findOrFail($ids[0]);
}
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $webinars = [];
     $users = [1, 2, 3];
     foreach ($users as $uid) {
         for ($i = 0; $i < 5; $i++) {
             $faker = Faker\Factory::create();
             $webinar = ['user_id' => $uid, 'title' => $faker->realText($faker->numberBetween(60, 80)), 'hosts' => $faker->realText($faker->numberBetween(60, 80)), 'share' => $faker->realText($faker->numberBetween(30, 50)), 'description' => $faker->realText($faker->numberBetween(120, 180)), 'starts_on' => $faker->dateTime($min = 'now'), 'duration' => rand(1, 4) . 'h', 'timezone' => 'EDT'];
             $webinar = Webinar::create($webinar);
             $hashedId = hashWebinar($webinar->id);
             $webinar->uuid = $hashedId;
             $webinar->save();
             $webinar->subscribers_lists()->attach(rand(1, 3));
             $webinar_subscriber_list = SubscribersList::whereWebinarId($webinar->id)->first();
             $webinar->signup_subscribers_lists()->attach($webinar_subscriber_list->id);
         }
     }
 }
 function addLead(Request $request)
 {
     if ($request->ajax()) {
         $input = $request->all();
         $webinar_id = $input['webinar_id'];
         $first_name = $input['first_name'];
         $last_name = $input['last_name'];
         $email = $input['email'];
         $response = array();
         $rules = ['webinar_id' => 'required', 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email'];
         $validator = Validator::make($input, $rules);
         if ($validator->passes()) {
             $webinar = Webinar::find($webinar_id);
             if ($webinar) {
                 $subscriber = Subscriber::whereEmail($email)->first();
                 if (!$subscriber) {
                     $insert = ["first_name" => $first_name, "last_name" => $last_name, "email" => $email, "status" => "Active"];
                     $subscriber = Subscriber::create($insert);
                 }
                 $webinar_signup_subscribers_lists = $webinar->signup_subscribers_lists()->get();
                 foreach ($webinar_signup_subscribers_lists as $webinar_list) {
                     // Attach New Subscriber with Webinar
                     $webinar_list->subscribers()->detach($subscriber->id);
                     $webinar_list->subscribers()->attach($subscriber->id);
                 }
                 $response = array('success' => true);
             } else {
                 $errors = array("Webinar Not Found");
                 $response = array('success' => false, 'errors' => $errors);
             }
         } else {
             $errors = $validator->getMessageBag()->toArray();
             $response = array('success' => false, 'errors' => $errors);
         }
         echo json_encode($response);
     }
 }
 public function single_data_generate($max_no_of_dataset_per_data, $webinar_id, $data_no)
 {
     $data_to_return = [];
     if ($max_no_of_dataset_per_data < 5) {
         $max_no_of_dataset_per_data = 5;
     }
     ///////////////////////////////////////////////////////////////////////////////////
     $webinar = Webinar::find($webinar_id);
     $start_time = $webinar['starts_on'];
     $time = DB::select(DB::raw('SELECT NOW() AS end_time'));
     $end_time = $time[0]->end_time;
     //time();
     $start = strtotime($start_time);
     $end = strtotime($end_time);
     $interval = ($end - $start) / $max_no_of_dataset_per_data;
     //return date('Y-m-d H:i:s', $interval);
     for ($x = $start; $x <= $end; $x += $interval) {
         $data_to_return[] = $this->one_entry($x, $webinar_id, $data_no);
     }
     ////////////////////////////////////////////////////////////////////////////////////
     /*for ($x = 1; $x <= $max_no_of_dataset_per_data; $x++)
       {
           $data_to_return[] = $this->one_entry($x,$webinar_id,$data_no);
       }*/
     return $data_to_return;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, $webinarId)
 {
     ini_set("max_execution_time", 0);
     try {
         $webinar = Webinar::find($webinarId);
         $webinar_uuid = hashWebinar($webinarId);
         $user_id = Auth::user()->id;
         $subscribers_lists = $webinar->subscribers_lists()->get();
         $webinar_signup_subscribers_lists = $webinar->signup_subscribers_lists()->get();
         $input = $request->all();
         if (count($subscribers_lists) > 0) {
             $subject = $input['subject'];
             $body = $input['content'];
             $smtp_method = $input['smtp_method'][0];
             $setting = Setting::whereName('custom_domain')->where('customer_id', '=', $user_id)->first();
             if (!$setting) {
                 return redirect()->back()->with("error", "Custom Domain is not Set.");
             }
             $smtp = Smtp::find($smtp_method);
             if (!$smtp) {
                 return redirect()->back()->with("error", "No SMTP Method Found");
             }
             $custom_domain = $setting->value;
             config(["mail.driver" => "smtp", "mail.host" => $smtp->host, "mail.port" => $smtp->port, "mail.from.address" => $smtp->from_email, "mail.from.name" => $smtp->from_name, "mail.encryption" => $smtp->protocol, "mail.username" => $smtp->username, "mail.password" => $smtp->password]);
             // General Subscribers List
             if ($subscribers_lists) {
                 foreach ($subscribers_lists as $subscriber_list) {
                     $subscribers = $subscriber_list->activeSubscribers()->get();
                     if (count($subscribers) > 0) {
                         foreach ($subscribers as $subscriber) {
                             $subscriber_hash = $subscriber->uuid;
                             $subscriber_name = $subscriber->first_name . ' ' . $subscriber->last_name;
                             $to_email = $subscriber->email;
                             $webinar_url = "http://" . $custom_domain . "/webinar/" . $webinar_uuid . "/" . $subscriber_hash;
                             $emailData = ['body' => $body, 'subscriber_name' => $subscriber_name, 'webinar_url' => $webinar_url];
                             Mail::send('emails.webinar_invite_email', $emailData, function ($message) use($subject, $to_email, $subscriber_name) {
                                 $message->subject($subject);
                                 $message->from('*****@*****.**', 'Webinar Admin');
                                 $message->to($to_email, $subscriber_name);
                             });
                         }
                     }
                 }
             }
             // Send Email to Webinar Specific Subscribers
             if ($webinar_signup_subscribers_lists) {
                 foreach ($webinar_signup_subscribers_lists as $subscriber_list) {
                     $subscribers = $subscriber_list->activeSubscribers()->get();
                     if (count($subscribers) > 0) {
                         foreach ($subscribers as $subscriber) {
                             echo $subscriber->id . "<br/>";
                             $subscriber_hash = $subscriber->uuid;
                             $subscriber_name = $subscriber->first_name . ' ' . $subscriber->last_name;
                             $to_email = $subscriber->email;
                             $webinar_url = "http://" . $custom_domain . "/webinar/" . $webinar_uuid . "/" . $subscriber_hash;
                             $emailData = ['body' => $body, 'subscriber_name' => $subscriber_name, 'webinar_url' => $webinar_url];
                             Mail::send('emails.webinar_invite_email', $emailData, function ($message) use($subject, $to_email, $subscriber_name) {
                                 $message->subject($subject);
                                 $message->to($to_email, $subscriber_name);
                             });
                         }
                     }
                 }
             }
         }
         return redirect()->back()->with("status", "Mail Sent Succesfully");
     } catch (\Exception $e) {
     }
     return redirect()->back();
 }
 public function postEmailNotification(Request $request, $userId, $webinarUUId)
 {
     ini_set("max_execution_time", 0);
     $input = $request->all();
     $webinar = Webinar::whereId($webinarUUId)->first();
     $webinar_uuid = $webinar->uuid;
     $subscribers_lists = $webinar->subscribers_lists()->get();
     $webinar_signup_subscribers_lists = $webinar->signup_subscribers_lists()->get();
     $setting = Setting::whereName('custom_domain')->where('customer_id', '=', $userId)->first();
     if (!$setting) {
         return redirect()->back()->with("error", "Custom Domain is not Set.");
     }
     $custom_domain = $setting->value;
     $rules = ["subject" => "required", "content" => "required", "smtp_method" => "required", "send_type" => "required"];
     $validator = Validator::make($input, $rules);
     if ($validator->passes()) {
         $send_type = $input["send_type"];
         $input['customer_id'] = $userId;
         $input['smtp_setting_id'] = $input['smtp_method'];
         $smtp = Smtp::find($input['smtp_method']);
         if (!$smtp) {
             return redirect()->back()->with("error", "No SMTP Method Found");
         }
         unset($input['smtp_method']);
         if ($send_type == "now") {
             $input['send_date'] = Carbon::now();
             $input['minutes_before_webinar'] = NULL;
         } else {
             if ($send_type == "minutes_before") {
                 $minutes_before_webinar = $input['minutes_before_webinar'];
                 $input['send_date'] = Carbon::parse($webinar->starts_on)->subMinutes($minutes_before_webinar);
                 $input['minutes_before_webinar'] = $minutes_before_webinar;
             }
         }
         $count_subscribers = 0;
         $input['webinar_id'] = $webinar->id;
         $email_notification = EmailNotification::create($input);
         $email_notification->uuid = hashCampaignEmail($email_notification->id);
         $email_notification->save();
         $subject = $input['subject'];
         $body = $input['content'];
         if ($send_type == "now") {
             // Send Instant Email
             config(["mail.driver" => "smtp", "mail.host" => $smtp->host, "mail.port" => $smtp->port, "mail.from.address" => $smtp->from_email, "mail.from.name" => $smtp->from_name, "mail.encryption" => $smtp->protocol, "mail.username" => $smtp->username, "mail.password" => $smtp->password]);
             try {
                 // General Subscribers List
                 if ($subscribers_lists) {
                     foreach ($subscribers_lists as $subscriber_list) {
                         $subscribers = $subscriber_list->activeSubscribers()->get();
                         if (count($subscribers) > 0) {
                             $count_subscribers += count($subscribers);
                             foreach ($subscribers as $subscriber) {
                                 $subscriber_hash = $subscriber->uuid;
                                 $subscriber_name = $subscriber->first_name . ' ' . $subscriber->last_name;
                                 $to_email = $subscriber->email;
                                 $webinar_url = "http://" . $custom_domain . "/webinar/" . $webinar_uuid . "/" . $subscriber_hash;
                                 $emailData = ['body' => $body, 'subscriber_name' => $subscriber_name, 'webinar_url' => $webinar_url];
                                 //pr($emailData); die;
                                 Mail::send('emails.webinar_invite_email', $emailData, function ($message) use($subject, $to_email, $subscriber_name) {
                                     $message->subject($subject);
                                     $message->from('*****@*****.**', 'Webinar Admin');
                                     $message->to($to_email, $subscriber_name);
                                 });
                             }
                         }
                     }
                 }
                 // Send Email to Webinar Specific Subscribers
                 if ($webinar_signup_subscribers_lists) {
                     foreach ($webinar_signup_subscribers_lists as $subscriber_list) {
                         $subscribers = $subscriber_list->activeSubscribers()->get();
                         if (count($subscribers) > 0) {
                             $count_subscribers += count($subscribers);
                             foreach ($subscribers as $subscriber) {
                                 $subscriber_hash = $subscriber->uuid;
                                 $subscriber_name = $subscriber->first_name . ' ' . $subscriber->last_name;
                                 $to_email = $subscriber->email;
                                 $webinar_url = "http://" . $custom_domain . "/webinar/" . $webinar_uuid . "/" . $subscriber_hash;
                                 $emailData = ['body' => $body, 'subscriber_name' => $subscriber_name, 'webinar_url' => $webinar_url];
                                 Mail::send('emails.webinar_invite_email', $emailData, function ($message) use($subject, $to_email, $subscriber_name) {
                                     $message->subject($subject);
                                     $message->to($to_email, $subscriber_name);
                                 });
                             }
                         }
                     }
                 }
                 // Mail Sent Successfully
                 $email_notification->count_subscribers = $count_subscribers;
                 $email_notification->status = 1;
                 $email_notification->save();
             } catch (\Exception $e) {
                 // Error in Sending Mail
                 $email_notification->status = -1;
                 $email_notification->save();
             }
         }
         return redirect()->back()->with('status', "Email Notification updated successfully");
     } else {
         return redirect()->back()->withErrors($validator)->withInput();
     }
 }
 public function getWebinar($webinar_uuid)
 {
     $webinar = Webinar::where('uuid', '=', $webinar_uuid)->first();
     $streamingServer = $webinar->streaming_server;
     return $this->view('layouts.member.webinar', compact('webinar', 'streamingServer'));
 }
 public function postBestellen($slug, Order $order, User $u, Request $request, Bedrijfsgegevens $bedrijfsgegevens, Product $p, Webinar $webinar)
 {
     // $webinardatum = Carbon::create(2015, 10, 24, '12', '00', '00', 'Europe/Amsterdam');
     // if(Carbon::now() > $webinardatum) {
     $product = $p->where('slug', $slug)->first();
     $user = $u->where('email', '=', $request->get('email'))->first();
     // $dag = Carbon::now('Europe/Amsterdam')->format('jnyGis');
     // $order_id = $dag.'-'.$user->id;
     // dd(route('webinar.aanbod.bedankt', array('order_id='.$order_id,'pakket_id='.$request->get('pakket_id'))));
     // dd($product);
     if ($user == null) {
         $user = new $u(['voornaam' => $request->get('voornaam'), 'achternaam' => $request->get('achternaam'), 'email' => $request->get('email')]);
         $user->save();
     }
     if ($user) {
         // Log de nieuwe gebruiker in
         Auth::loginUsingId($user->id);
         // maak order_id
         $dag = Carbon::now('Europe/Amsterdam')->format('jnyGis');
         $order_id = $dag . '-' . $user->id;
         // Maak betaling aan Mollie klaar
         $gateway = Omnipay::gateway('Mollie');
         $gateway->setApiKey('test_N3BbdyKoizxGlYlbPqjUGE3eMpIZJC');
         $response = $gateway->purchase(['amount' => $request->get('bedrag') * 1.21, 'issuer' => $request->get('issuer'), 'description' => $request->get('omschrijving'), 'returnUrl' => route('test.bestel.bedankt', array('order_id=' . $order_id)), 'notifyUrl' => route('test.webhook'), 'paymentMethod' => $request->get('paymentmethod'), 'metadata' => array('order_id' => $order_id, 'product_id' => $product->id, 'cursus_id' => $product->cursus_id, 'plan_id' => $product->plan_id)])->send();
         // dd($response);
         if ($response->isSuccessful()) {
             // payment successful - update database
             return response()->json(['success' => false, 'errors' => $response]);
         } elseif ($response->isRedirect()) {
             // redirect to offsite payment gateway
             // Maak order die aan user zit
             $ref = $response->getTransactionReference();
             $order = new $order(['transaction_id' => $ref, 'order_id' => $order_id, 'user_id' => $user->id, 'cursus_id' => $product->cursus_id, 'bedrag' => $request->get('bedrag') * 1.21, 'betaalmethode' => $request->get('paymentmethod')]);
             $order->save();
             $user->update(['voornaam' => $request->get('voornaam'), 'achternaam' => $request->get('achternaam')]);
             $input = array('CompanyName' => $request->get('bedrijfsnaam'), 'Sex' => $request->get('aanhef'), 'Initials' => $request->get('voornaam'), 'SurName' => $request->get('achternaam'), 'Address' => $request->get('adres'), 'ZipCode' => $request->get('postcode'), 'City' => $request->get('woonplaats'), 'Country' => $request->get('land'), 'EmailAddress' => $request->get('email'), 'Mailings' => 'yes', 'PhoneNumber' => $request->get('telefoonnummer'), 'MobileNumber' => $request->get('mobielnummer'), 'InvoiceSex' => '', 'InvoiceMethod' => '0');
             $this->createDebitor($input, $request->get('email'));
             $bedrijfsgegevens = new $bedrijfsgegevens(['bedrijfsnaam' => $request->get('bedrijfsnaam'), 'aanhef' => $request->get('aanhef'), 'adres' => $request->get('adres'), 'postcode' => $request->get('postcode'), 'mobiel' => $request->get('mobielnummer'), 'telefoonnummer' => $request->get('telefoonnummer'), 'woonplaats' => $request->get('woonplaats'), 'land' => $request->get('land'), 'user_id' => $user->id]);
             $bedrijfsgegevens->save();
             return redirect($response->getRedirectUrl());
         } else {
             // display error message
             return response()->json(['success' => false, 'errors' => $response->getMessage()]);
         }
     } else {
         $webinars = $webinar->all();
         return view('testomgeving.webinar.index', compact('webinars'))->with(['message' => 'Er is iets fout gegaan, neem a.u.b. contact op met jeroen@digitusmarketing.nl']);
     }
 }