Ejemplo n.º 1
0
<?php

error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
include_once 'GoogleCustomSearch.class.php';
$apikey = '';
$seid = '';
$keyword = urlencode('');
$api = new GoogleCustomSearch();
$req = $api->customSearch($apikey, $seid, $keyword);
$i = 1;
foreach ($req as $val) {
    echo $i . ' | ' . $val['link'] . '<br/>';
    $i++;
}
 function purchaseContact($_index = null, $_cache = null)
 {
     $_JSON = array();
     $_JSON['error'] = '';
     $_JSON['code'] = '';
     $_JSON['credits'] = 0;
     $_JSON['contacts'] = 0;
     if (Auth::check()) {
         $credits = Auth::user()->credits;
         $subscriptions = Auth::user()->subscription()->first();
         if ($subscriptions != null) {
             $transactions = $subscriptions->transaction()->get();
             if (count($transactions) > 0) {
                 foreach ($transactions as $transaction) {
                     $credits = $credits + $transaction->credits;
                 }
             }
         }
         $_JSON['error'] = '';
         $user = User::find(Auth::user()->id);
         $customername = $user->firstname . " " . $user->lastname;
         if ($credits == 0) {
             $_JSON['card'] = '';
             $_JSON['last4'] = '';
             $payment_profile = PaymentProfile::whereUser_id($user->id)->first();
             if (!empty($payment_profile)) {
                 $responseData = unserialize($payment_profile->response);
                 $responseData = $responseData->__toArray();
                 $cards = $responseData['cards']->__toArray();
                 if ($cards['total_count'] > 0) {
                     $card = $cards['data'][0]->__toArray();
                     $_JSON['card'] = $card['brand'];
                     $_JSON['last4'] = $card['last4'];
                 }
             }
             $_JSON['error'] = 'You don&#39;t have sufficient funds to purchase contacts';
         } else {
             $login_user_id = Auth::id();
             $index = Input::get('index', 0);
             if ($_cache == null) {
                 $CONTACTS = unserialize($user->cache);
             } else {
                 $CONTACTS = $_cache;
             }
             $_JSON['info1'] = $CONTACTS[$index]["linkedin"];
             $agents = User::where("status", "=", User::STATUS_AGENT)->get();
             $min = 1000000;
             $min_id = NULL;
             foreach ($agents as $agent) {
                 $linkedin_list = LinkedinContact::where("agent_id", "=", $agent->id)->where("status", "=", LinkedinContact::INCOMPLETE)->get();
                 $count = 0;
                 foreach ($linkedin_list as $linkedin_item) {
                     $count++;
                 }
                 if ($count < $min) {
                     $min = $count;
                     $min_id = $agent->id;
                 }
             }
             $linkedin_contact = LinkedinContact::where("url", "=", base64_decode($CONTACTS[$index]["linkedin"]))->first();
             if (!empty($min_id)) {
                 $linkedin_contact->agent_id = $min_id;
                 $linkedin_contact->started = 1;
                 $linkedin_contact->save();
             }
             // Automation Start
             $company_name = $CONTACTS[$index]['company_name'];
             $company_domain = '';
             if ($company_name != '') {
                 $obj = new GoogleCustomSearch();
                 $company_domain = $obj->makeCall($company_name);
                 //google Search Domain
             }
             if ($company_domain != '') {
                 $this->addNewLead($company_domain, $linkedin_contact->id);
             }
             // Automation End
             $_JSON['info2'] = $linkedin_contact;
             if ($linkedin_contact != null) {
                 $_JSON['info3'] = "saveToList";
                 $this->saveToList(Auth::user()->id, serialize($CONTACTS[$index]), $linkedin_contact->id);
                 $_JSON['credits'] = $credits - 1;
                 //send email to all addresses that are added from admin
                 $contact_data = array("firstname" => $linkedin_contact->firstname, "lastname" => $linkedin_contact->lastname, "title" => $linkedin_contact->title, "company" => $linkedin_contact->company, "location" => $linkedin_contact->location, "url" => $linkedin_contact->url);
                 $agent_alerts = Settings::all();
                 foreach ($agent_alerts as $alert) {
                     $contact_data['customername'] = $customername;
                     $contact_data['agentname'] = $alert['name'];
                     $contact_data['agentemail'] = $alert['value'];
                     Session::put('agentemail', $alert['value']);
                     Mail::queue('emails/agent/agent-added-contact', $contact_data, function ($message) {
                         $message->to(Session::get('agentemail'), 'abc')->subject('A new lead has been added by a user.');
                     });
                 }
                 // send to admin
                 $contact_data['customername'] = $customername;
                 $contact_data['agentname'] = 'Admin';
                 $contact_data['agentemail'] = '*****@*****.**';
                 Mail::queue('emails/agent/admin-added-contact', $contact_data, function ($message) {
                     $message->to('*****@*****.**', 'abc')->subject('A new lead has been added by a user.');
                 });
             }
         }
         $_JSON['contacts'] = count($user->lists()->first()->linkedinContact()->get());
     } else {
         $_JSON['error'] = '';
         $_JSON['code'] = '0001';
     }
     if ($_index == 5) {
         Log::notice("error");
     } else {
         Log::notice("json.response");
     }
     if ($_index == 5) {
         return $_JSON["error"];
     } else {
         return Response::json($_JSON);
     }
 }