/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info('Working');
     $date1 = date('Y-m-d h:i:s');
     $this->info($date1);
     $date = date_create($date1);
     $msgtime = $date->add(new DateInterval('P0Y0M0DT0H30M0S'))->format('Y-m-d H:i:s');
     $requests = Requests::where('later', 1)->where('is_started', 0)->where('request_start_time', '<=', $msgtime)->get();
     if ($requests->count() > 0) {
         $this->info('hola');
         foreach ($requests as $request) {
             $provider = Walker::where('id', $request->confirmed_walker)->first();
             $owner = Owner::where('id', $request->owner_id)->first();
             $message = "You have a ride scheduled in 30 mins from now. Client name is {$owner->first_name} {$owner->last_name} and phone no. is {$owner->phone}";
             $this->info($request->id);
             $this->info($message);
             send_notifications($provider->id, 'provider', 'Ride in 30 min', $message);
             $request->later = 0;
             $request->save();
         }
     }
 }
 public function schedule_request()
 {
     $time = date("Y-m-d H:i:s");
     $query = "SELECT id,owner_id,current_walker,TIMESTAMPDIFF(SECOND,request_start_time, '{$time}') as diff from request where status = 0 and is_cancelled = 0";
     $results = DB::select(DB::raw($query));
     foreach ($results as $result) {
         $settings = Settings::where('key', 'provider_timeout')->first();
         $timeout = $settings->value;
         if ($result->diff >= $timeout) {
             // Archiving Old Walker
             RequestMeta::where('request_id', '=', $result->id)->where('walker_id', '=', $result->current_walker)->update(array('status' => 2));
             $request_meta = RequestMeta::where('request_id', '=', $result->id)->where('status', '=', 0)->orderBy('created_at')->first();
             // update request
             if (isset($request_meta->walker_id)) {
                 // assign new walker
                 Requests::where('id', '=', $result->id)->update(array('current_walker' => $request_meta->walker_id, 'request_start_time' => date("Y-m-d H:i:s")));
                 // Send Notification
                 $walker = Walker::find($request_meta->walker_id);
                 $owner_data = Owner::find($result->owner_id);
                 $msg_array = array();
                 $msg_array['request_id'] = $result->id;
                 $msg_array['id'] = $request_meta->walker_id;
                 if ($walker) {
                     $msg_array['token'] = $walker->token;
                 }
                 $msg_array['client_profile'] = array();
                 $msg_array['client_profile']['name'] = $owner_data->first_name . " " . $owner_data->last_name;
                 $msg_array['client_profile']['picture'] = $owner_data->picture;
                 $msg_array['client_profile']['bio'] = $owner_data->bio;
                 $msg_array['client_profile']['address'] = $owner_data->address;
                 $msg_array['client_profile']['phone'] = $owner_data->phone;
                 $title = "New Request";
                 $message = $msg_array;
                 send_notifications($request_meta->walker_id, "walker", $title, $message);
             } else {
                 // request ended
                 Requests::where('id', '=', $result->id)->update(array('current_walker' => 0, 'status' => 1));
                 $settings = Settings::where('key', 'sms_request_unanswered')->first();
                 $pattern = $settings->value;
                 $pattern = str_replace('%id%', $result->id, $pattern);
                 sms_notification(1, 'admin', $pattern);
                 // send email
                 $settings = Settings::where('key', 'email_request_unanswered')->first();
                 $pattern = $settings->value;
                 $pattern = str_replace('%id%', $result->id, $pattern);
                 $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $result->id, $pattern);
                 $subject = "New Request Unansweres";
                 email_notification(1, 'admin', $pattern, $subject);
             }
         }
     }
 }
 public function decline_walker()
 {
     $id = Request::segment(4);
     $success = Input::get('success');
     $walker = Walker::find($id);
     $walker->is_approved = 0;
     $txt_approve = "Decline";
     if ($walker->is_approved) {
         $txt_approve = "Approved";
     }
     $response_array = array('unique_id' => 5, 'success' => true, 'id' => $walker->id, 'first_name' => $walker->first_name, 'last_name' => $walker->last_name, 'phone' => $walker->phone, 'email' => $walker->email, 'picture' => $walker->picture, 'bio' => $walker->bio, 'address' => $walker->address, 'state' => $walker->state, 'country' => $walker->country, 'zipcode' => $walker->zipcode, 'login_by' => $walker->login_by, 'social_unique_id' => $walker->social_unique_id, 'device_token' => $walker->device_token, 'device_type' => $walker->device_type, 'token' => $walker->token, 'type' => $walker->type, 'is_approved' => $walker->is_approved, 'is_approved_txt' => $txt_approve);
     $title = "You are Decline";
     $message = $response_array;
     send_notifications($id, "walker", $title, $message, "imp");
     /* SMS */
     $settings = Settings::where('key', 'sms_walker_decline')->first();
     $pattern = $settings->value;
     $pattern = str_replace('%name%', $walker->first_name . " " . $walker->last_name, $pattern);
     sms_notification($id, 'walker', $pattern);
     /* SMS END */
     /* EMAIL */
     /* $settings = Settings::where('key', 'email_walker_decline')->first();
        $pattern = $settings->value;
        $pattern = str_replace('%name%', $walker->first_name . " " . $walker->last_name, $pattern); */
     $settings = Settings::where('key', 'admin_email_address')->first();
     $admin_email = $settings->value;
     $pattern = array('walker_name' => $walker->first_name . " " . $walker->last_name, 'admin_eamil' => $admin_email);
     $subject = "Welcome " . $walker->first_name . " " . $walker->last_name . " To " . Config::get('app.website_title') . "";
     email_notification($id, 'walker', $pattern, $subject, 'walker_decline');
     /* EMAIL END */
     $walker->save();
     /* $pattern = "Hi " . $walker->first_name . ", Your account is deactivated, Please contact admin to Continue";
        $subject = "Your Account Deactivated";
        email_notification($walker->id, 'walker', $pattern, $subject); */
     return Redirect::to("/admin/providers");
 }
 public function testpush()
 {
     $title = "PBN";
     $message = "post added";
     $post_id = 1;
     $url = "single.html";
     Log::info($message);
     send_notifications($title, $message, $post_id, $url);
 }
 public function payment_type()
 {
     $token = Input::get('token');
     $owner_id = Input::get('id');
     $request_id = Input::get('request_id');
     $cash_or_card = Input::get('cash_or_card');
     $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id, 'cash_or_card' => $cash_or_card, 'request_id' => $request_id), array('token' => 'required', 'owner_id' => 'required|integer', 'cash_or_card' => 'required', 'request_id' => 'required'));
     if ($validator->fails()) {
         $error_messages = $validator->messages()->all();
         $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
         $response_code = 200;
     } else {
         $payments = array();
         /* $payments['none'] = ""; */
         $def_card = 0;
         $is_admin = $this->isAdmin($token);
         if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) {
             // check for token validity
             if (is_token_active($owner_data->token_expiry) || $is_admin) {
                 if ($cash_or_card != 1) {
                     $card_count = Payment::where('owner_id', '=', $owner_id)->count();
                     if ($card_count <= 0) {
                         $response_array = array('success' => false, 'error' => "Please add card first for payment.", 'error_code' => 417);
                         $response_code = 200;
                         $response = Response::json($response_array, $response_code);
                         return $response;
                     }
                 }
                 // Do necessary operations
                 $owner = Owner::find($owner_id);
                 $payment_data = Payment::where('owner_id', $owner_id)->orderBy('is_default', 'DESC')->get();
                 foreach ($payment_data as $data1) {
                     $default = $data1->is_default;
                     if ($default == 1) {
                         $def_card = $data1->id;
                         $data['is_default_text'] = "default";
                     } else {
                         $data['is_default_text'] = "not_default";
                     }
                     $data['id'] = $data1->id;
                     $data['owner_id'] = $data1->owner_id;
                     $data['customer_id'] = $data1->customer_id;
                     $data['last_four'] = $data1->last_four;
                     $data['card_token'] = $data1->card_token;
                     $data['card_type'] = $data1->card_type;
                     $data['card_id'] = $data1->card_token;
                     $data['is_default'] = $default;
                     array_push($payments, $data);
                 }
                 if ($request = Requests::find($request_id)) {
                     $request->payment_mode = $cash_or_card;
                     $request->save();
                     $walker = Walker::where('id', $request->confirmed_walker)->first();
                     if ($walker) {
                         $msg_array = array();
                         $msg_array['unique_id'] = 3;
                         $response_array = array('success' => true, 'id' => $owner->id, 'first_name' => $owner->first_name, 'last_name' => $owner->last_name, 'phone' => $owner->phone, 'email' => $owner->email, 'picture' => $owner->picture, 'bio' => $owner->bio, 'address' => $owner->address, 'state' => $owner->state, 'country' => $owner->country, 'zipcode' => $owner->zipcode, 'login_by' => $owner->login_by, 'social_unique_id' => $owner->social_unique_id, 'device_token' => $owner->device_token, 'device_type' => $owner->device_type, 'token' => $owner->token, 'default_card_id' => $def_card, 'payment_type' => $request->payment_mode, 'is_referee' => $owner->is_referee, 'promo_count' => $owner->promo_count, 'payments' => $payments);
                         $response_array['unique_id'] = 3;
                         $response_code = 200;
                         $msg_array['owner_data'] = $response_array;
                         $title = "Payment Type Change";
                         $message = $msg_array;
                         if ($request->confirmed_walker == $request->current_walker) {
                             send_notifications($request->confirmed_walker, "walker", $title, $message);
                         }
                     } else {
                         $response_array = array('success' => false, 'error' => 'Driver Not Found', 'error_code' => 408);
                         $response_code = 200;
                     }
                 } else {
                     $response_array = array('success' => false, 'error' => 'Request ID Not Found', 'error_code' => 408);
                     $response_code = 200;
                 }
             } else {
                 $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                 $response_code = 200;
             }
         } else {
             if ($is_admin) {
                 $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410);
             } else {
                 $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
             }
             $response_code = 200;
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
Example #6
0
        // Get amounts
        if ($_POST['currency'] == 'fiat') {
            $amount = $_POST['amount'];
            $amount_btc = $amount / $config['exchange_rate'];
        } else {
            $amount_btc = $_POST['amount'];
            $amount = $amount_btc * $config['exchange_rate'];
        }
        // Generate payment address
        $address = $bip32->generate_address($_POST['wallet_id'], $user_row['id']);
        DB::query("UPDATE coin_addresses SET is_used = 1 WHERE address = %s", $address);
        // Add new invoice
        DB::insert('invoices', array('wallet_id' => $_POST['wallet_id'], 'userid' => $user_row['id'], 'currency' => $_POST['currency'], 'amount' => $amount, 'amount_btc' => $amount_btc, 'payment_address' => $address, 'note' => $_POST['note'], 'process_note' => ''));
        $invoice_id = DB::insertId();
        // Send notifications
        send_notifications('invoice_created', $invoice_id);
        // User message
        $template->add_message("Successfully generated a new pending invoice for user, {$_POST['username']}");
    }
    // Process invoices
} elseif (isset($_POST['submit']) && $_POST['submit'] == 'Process Checked Invoices') {
    // Process
    $ids = get_chk('invoice_id');
    foreach ($ids as $id) {
        if (!$id > 0) {
            continue;
        }
        DB::update('invoices', array('status' => $_POST['status'], 'date_paid' => DB::sqleval('now()'), 'process_note' => $_POST['note']), "id = %d", $id);
    }
    // User message
    $template->add_message("Successfully processed all checked invoices, and marked them as <b>{$_POST['status']}</b>.");
Example #7
0
    function approve($id, $unlock_safe = false)
    {
        /* fetch info about the message, poll (if one exists), thread & forum */
        $mtf = db_sab('SELECT
					m.id, m.poster_id, m.apr, m.subject, m.foff, m.length, m.file_id, m.thread_id, m.poll_id, m.attach_cnt,
					m.post_stamp, m.reply_to, m.mlist_msg_id,
					t.forum_id, t.last_post_id, t.root_msg_id, t.last_post_date,
					m2.post_stamp AS frm_last_post_date,
					f.name AS frm_name,
					u.alias, u.email, u.sig,
					n.id AS nntp_id, ml.id AS mlist_id
				FROM phpgw_fud_msg m
				INNER JOIN phpgw_fud_thread t ON m.thread_id=t.id
				INNER JOIN phpgw_fud_forum f ON t.forum_id=f.id
				LEFT JOIN phpgw_fud_msg m2 ON f.last_post_id=m2.id
				LEFT JOIN phpgw_fud_users u ON m.poster_id=u.id
				LEFT JOIN phpgw_fud_mlist ml ON ml.forum_id=f.id
				LEFT JOIN phpgw_fud_nntp n ON n.forum_id=f.id
				WHERE m.id=' . $id . ' AND m.apr=0');
        /* nothing to do or bad message id */
        if (!$mtf) {
            return;
        }
        if ($mtf->alias) {
            reverse_fmt($mtf->alias);
        } else {
            $mtf->alias = $GLOBALS['ANON_NICK'];
        }
        if (!db_locked()) {
            db_lock('phpgw_fud_thread_view WRITE, phpgw_fud_level WRITE, phpgw_fud_users WRITE, phpgw_fud_forum WRITE, phpgw_fud_thread WRITE, phpgw_fud_msg WRITE');
            $ll = 1;
        }
        q("UPDATE phpgw_fud_msg SET apr=1 WHERE id=" . $mtf->id);
        if ($mtf->poster_id) {
            user_set_post_count($mtf->poster_id);
        }
        $last_post_id = $mtf->post_stamp > $mtf->frm_last_post_date ? $mtf->id : 0;
        if ($mtf->root_msg_id == $mtf->id) {
            /* new thread */
            rebuild_forum_view($mtf->forum_id);
            $threads = 1;
        } else {
            /* reply to thread */
            if ($mtf->post_stamp > $mtf->last_post_date) {
                th_inc_post_count($mtf->thread_id, 1, $mtf->id, $mtf->post_stamp);
            } else {
                th_inc_post_count($mtf->thread_id, 1);
            }
            rebuild_forum_view($mtf->forum_id, q_singleval('SELECT page FROM phpgw_fud_thread_view WHERE forum_id=' . $mtf->forum_id . ' AND thread_id=' . $mtf->thread_id));
            $threads = 0;
        }
        /* update forum thread & post count as well as last_post_id field */
        frm_updt_counts($mtf->forum_id, 1, $threads, $last_post_id);
        if ($unlock_safe || isset($ll)) {
            db_unlock();
        }
        if ($mtf->poll_id) {
            poll_activate($mtf->poll_id, $mtf->forum_id);
        }
        $mtf->body = read_msg_body($mtf->foff, $mtf->length, $mtf->file_id);
        if ($GLOBALS['FUD_OPT_1'] & 16777216) {
            index_text(preg_match('!Re: !i', $mtf->subject) ? '' : $mtf->subject, $mtf->body, $mtf->id);
        }
        /* handle notifications */
        if ($mtf->root_msg_id == $mtf->id) {
            if (empty($mtf->frm_last_post_date)) {
                $mtf->frm_last_post_date = 0;
            }
            /* send new thread notifications to forum subscribers */
            $c = uq('SELECT u.email, u.icq, u.users_opt
					FROM phpgw_fud_forum_notify fn
					INNER JOIN phpgw_fud_users u ON fn.user_id=u.id
					LEFT JOIN phpgw_fud_forum_read r ON r.forum_id=fn.forum_id AND r.user_id=fn.user_id
					INNER JOIN phpgw_fud_group_cache g1 ON g1.user_id=2147483647 AND g1.resource_id=' . $mtf->forum_id . '
					LEFT JOIN phpgw_fud_group_cache g2 ON g2.user_id=fn.user_id AND g2.resource_id=' . $mtf->forum_id . '
				WHERE
					fn.forum_id=' . $mtf->forum_id . ' AND fn.user_id!=' . (int) $mtf->poster_id . '
					AND (CASE WHEN (r.last_view IS NULL AND (u.last_read=0 OR u.last_read >= ' . $mtf->frm_last_post_date . ')) OR r.last_view > ' . $mtf->frm_last_post_date . ' THEN 1 ELSE 0 END)=1
					AND ((CASE WHEN g2.id IS NOT NULL THEN g2.group_cache_opt ELSE g1.group_cache_opt END) & 2) > 0');
            $notify_type = 'frm';
        } else {
            /* send new reply notifications to thread subscribers */
            $c = uq('SELECT u.email, u.icq, u.users_opt, r.msg_id, u.id
					FROM phpgw_fud_thread_notify tn
					INNER JOIN phpgw_fud_users u ON tn.user_id=u.id
					LEFT JOIN phpgw_fud_read r ON r.thread_id=tn.thread_id AND r.user_id=tn.user_id
					INNER JOIN phpgw_fud_group_cache g1 ON g1.user_id=2147483647 AND g1.resource_id=' . $mtf->forum_id . '
					LEFT JOIN phpgw_fud_group_cache g2 ON g2.user_id=tn.user_id AND g2.resource_id=' . $mtf->forum_id . '
				WHERE
					tn.thread_id=' . $mtf->thread_id . ' AND tn.user_id!=' . (int) $mtf->poster_id . '
					AND (r.msg_id=' . $mtf->last_post_id . ' OR (r.msg_id IS NULL AND ' . $mtf->post_stamp . ' > u.last_read))
					AND ((CASE WHEN g2.id IS NOT NULL THEN g2.group_cache_opt ELSE g1.group_cache_opt END) & 2) > 0');
            $notify_type = 'thr';
        }
        while ($r = db_rowarr($c)) {
            if ($r[2] & 16) {
                $to['EMAIL'] = $r[0];
            } else {
                $to['ICQ'] = $r[1] . '@pager.icq.com';
            }
            if (isset($r[4]) && is_null($r[3])) {
                $tl[] = $r[4];
            }
        }
        unset($c);
        if (isset($tl)) {
            /* this allows us to mark the message we are sending notification about as read, so that we do not re-notify the user
             * until this message is read.
             */
            q('INSERT INTO phpgw_fud_read (thread_id, msg_id, last_view, user_id) SELECT ' . $mtf->thread_id . ', 0, 0, id FROM phpgw_fud_users WHERE id IN(' . implode(',', $tl) . ')');
        }
        if (isset($to)) {
            send_notifications($to, $mtf->id, $mtf->subject, $mtf->alias, $notify_type, $notify_type == 'thr' ? $mtf->thread_id : $mtf->forum_id, $mtf->frm_name, $mtf->forum_id);
        }
        // Handle Mailing List and/or Newsgroup syncronization.
        if (($mtf->nntp_id || $mtf->mlist_id) && !$mtf->mlist_msg_id) {
            fud_use('email_msg_format.inc', true);
            reverse_fmt($mtf->alias);
            $from = $mtf->poster_id ? $mtf->alias . ' <' . $mtf->email . '>' : $GLOBALS['ANON_NICK'] . ' <' . $GLOBALS['NOTIFY_FROM'] . '>';
            $body = $mtf->body . ($mtf->msg_opt & 1 && $mtf->sig ? "\n--\n" . $mtf->sig : '');
            plain_text($body);
            plain_text($subject);
            if ($mtf->reply_to) {
                $replyto_id = q_singleval('SELECT mlist_msg_id FROM phpgw_fud_msg WHERE id=' . $mtf->reply_to);
            } else {
                $replyto_id = 0;
            }
            if ($mtf->attach_cnt) {
                $r = uq("SELECT a.id, a.original_name,\n\t\t\t\t\t\tCASE WHEN m.mime_hdr IS NULL THEN 'application/octet-stream' ELSE m.mime_hdr END\n\t\t\t\t\t\tFROM phpgw_fud_attach a\n\t\t\t\t\t\tLEFT JOIN phpgw_fud_mime m ON a.mime_type=m.id\n\t\t\t\t\t\tWHERE a.message_id=" . $mtf->id . " AND a.attach_opt=0");
                while ($ent = db_rowarr($r)) {
                    $attach[$ent[1]] = file_get_contents($GLOBALS['FILE_STORE'] . $ent[0] . '.atch');
                    if ($mtf->mlist_id) {
                        $attach_mime[$ent[1]] = $ent[2];
                    }
                }
            } else {
                $attach_mime = $attach = null;
            }
            if ($mtf->nntp_id) {
                fud_use('nntp.inc', true);
                $nntp_adm = db_sab('SELECT * FROM phpgw_fud_nntp WHERE id=' . $mtf->nntp_id);
                $nntp = new fud_nntp();
                $nntp->server = $nntp_adm->server;
                $nntp->newsgroup = $nntp_adm->newsgroup;
                $nntp->port = $nntp_adm->port;
                $nntp->timeout = $nntp_adm->timeout;
                $nntp->nntp_opt = $nntp_adm->nntp_opt;
                $nntp->login = $nntp_adm->login;
                $nntp->pass = $nntp_adm->pass;
                define('sql_p', 'phpgw_fud_');
                $lock = $nntp->get_lock();
                $nntp->post_message($mtf->subject, $body, $from, $mtf->id, $replyto_id, $attach);
                $nntp->close_connection();
                $nntp->release_lock($lock);
            } else {
                fud_use('mlist_post.inc', true);
                $GLOBALS['CHARSET'] = 'ISO-8859-15';
                $r = db_saq('SELECT name, additional_headers FROM phpgw_fud_mlist WHERE id=' . $mtf->mlist_id);
                mail_list_post($r[0], $from, $mtf->subject, $body, $mtf->id, $replyto_id, $attach, $attach_mime, $r[1]);
            }
        }
    }
/**
 * Handle the submission of a FAQ
 *
 * @since    3.0.0
 */
function handle_submission()
{
    //this $post variable is for the PRODUCT
    global $post;
    //create errors and result arrays
    $errors = array();
    $result = array();
    //put post data into an array
    if (isset($_POST['faq_author_name'])) {
        $input['faq_author_name'] = sanitize_text_field($_POST['faq_author_name']);
    }
    if (isset($_POST['faq_author_email'])) {
        $input['faq_author_email'] = sanitize_email($_POST['faq_author_email']);
    }
    if (isset($_POST['faq_content'])) {
        $input['faq_content'] = esc_textarea(stripslashes($_POST['faq_content']));
    }
    //very simple validation for content, name, and email
    //TODO - make this validation more stringent
    if (empty($input['faq_content'])) {
        $errors['faq_content'] = __('Please enter a question!', 'woocommerce-faqs');
    }
    if (empty($input['faq_author_name'])) {
        $errors['faq_author_name'] = __('Please enter your name!', 'woocommerce-faqs');
    }
    if (empty($input['faq_author_email']) || !empty($input['faq_author_email']) && !is_email($input['faq_author_email'])) {
        $errors['faq_author_email'] = __('Please enter a valid email!', 'woocommerce-faqs');
    }
    $result = handle_antispam();
    //if antispam returned a error type result, asker failed antispam check
    if ($result['type'] == 'error') {
        $errors[] = $result['message'];
    }
    //passed all checks
    if (empty($errors)) {
        $post_info = array('post_title' => __('Question for ', 'woocommerce-faqs') . $post->post_title, 'post_content' => wp_strip_all_tags($input['faq_content']), 'post_type' => WOOFAQS_POST_TYPE, 'post_status' => 'pending', 'comment_status' => 'open');
        //create the post
        $post_id = wp_insert_post($post_info);
        //add post meta
        update_post_meta($post_id, '_' . WOOFAQS_POST_TYPE . '_product', $post->ID);
        update_post_meta($post_id, '_' . WOOFAQS_POST_TYPE . '_author_name', $input['faq_author_name']);
        update_post_meta($post_id, '_' . WOOFAQS_POST_TYPE . '_author_email', $input['faq_author_email']);
        //data for elsewhere (like the notifications)
        $input['product_title'] = $post->post_title;
        $input['question_title'] = $post_info['post_title'];
        $input['question_content'] = $post_info['post_content'];
        $input['post_id'] = absint($post_id);
        $input['product_id'] = absint($post->ID);
        $input['product_author_id'] = absint($post->post_author);
        //result for the form (success)
        $result['type'] = 'success';
        $result['message'] = __('FAQ Successfully Posted. Your question will be reviewed and answered soon!', 'woocommerce-faqs');
        //send the notification to the answerer
        send_notifications('answerer', $input);
    } else {
        //result for the form (error)
        $result['type'] = 'error';
        $result['errors'] = $errors;
    }
    return $result;
}
 public function pre_payment()
 {
     if (Request::isMethod('post')) {
         $request_id = Input::get('request_id');
         $token = Input::get('token');
         $walker_id = Input::get('id');
         $time = Input::get('time');
         $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'walker_id' => $walker_id, 'time' => $time), array('request_id' => 'required|integer', 'token' => 'required', 'walker_id' => 'required|integer', 'time' => 'required'));
         if ($validator->fails()) {
             $error_messages = $validator->messages()->all();
             $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
             $response_code = 200;
         } else {
             $is_admin = $this->isAdmin($token);
             if ($walker_data = $this->getWalkerData($walker_id, $token, $is_admin)) {
                 // check for token validity
                 if (is_token_active($walker_data->token_expiry) || $is_admin) {
                     // Do necessary operations
                     if ($request = Requests::find($request_id)) {
                         if ($request->confirmed_walker == $walker_id) {
                             $request_service = RequestServices::find($request_id);
                             $request_typ = ProviderType::where('id', '=', $request_service->type)->first();
                             if (!$walker_data->type) {
                                 /* $settings = Settings::where('key', 'price_per_unit_distance')->first();
                                    $price_per_unit_distance = $settings->value;
                                    $settings = Settings::where('key', 'price_per_unit_time')->first();
                                    $price_per_unit_time = $settings->value;
                                    $settings = Settings::where('key', 'base_price')->first();
                                    $base_price = $settings->value; */
                                 $price_per_unit_distance = $request_typ->price_per_unit_distance;
                                 $price_per_unit_time = $request_typ->price_per_unit_time;
                                 $base_price = $request_typ->base_price;
                             } else {
                                 $provider_type = ProviderServices::find($walker_data->type);
                                 $base_price = $provider_type->base_price;
                                 $price_per_unit_distance = $provider_type->price_per_unit_distance;
                                 $price_per_unit_time = $provider_type->price_per_unit_time;
                             }
                             $settings = Settings::where('key', 'default_charging_method_for_users')->first();
                             $pricing_type = $settings->value;
                             $settings = Settings::where('key', 'default_distance_unit')->first();
                             $unit = $settings->value;
                             if ($pricing_type == 1) {
                                 $distance_cost = $price_per_unit_distance;
                                 $time_cost = $price_per_unit_time;
                                 $total = $base_price + $distance_cost + $time_cost;
                             } else {
                                 $distance_cost = 0;
                                 $time_cost = 0;
                                 $total = $base_price;
                             }
                             Log::info('req');
                             $request_service = RequestServices::find($request_id);
                             $request_service->base_price = $base_price;
                             $request_service->distance_cost = $distance_cost;
                             $request_service->time_cost = $time_cost;
                             $request_service->total = $total;
                             $request_service->save();
                             $request->distance = $distance_cost;
                             $request->time = $time_cost;
                             $request->total = $total;
                             Log::info('in ');
                             // charge client
                             $ledger = Ledger::where('owner_id', $request->owner_id)->first();
                             if ($ledger) {
                                 $balance = $ledger->amount_earned - $ledger->amount_spent;
                                 if ($balance > 0) {
                                     if ($total > $balance) {
                                         $ledger_temp = Ledger::find($ledger->id);
                                         $ledger_temp->amount_spent = $ledger_temp->amount_spent + $balance;
                                         $ledger_temp->save();
                                         $total = $total - $balance;
                                     } else {
                                         $ledger_temp = Ledger::find($ledger->id);
                                         $ledger_temp->amount_spent = $ledger_temp->amount_spent + $total;
                                         $ledger_temp->save();
                                         $total = 0;
                                     }
                                 }
                             }
                             Log::info('out');
                             if ($total == 0) {
                                 $request->is_paid = 1;
                             } else {
                                 $payment_data = Payment::where('owner_id', $request->owner_id)->where('is_default', 1)->first();
                                 if (!$payment_data) {
                                     $payment_data = Payment::where('owner_id', $request->owner_id)->first();
                                 }
                                 if ($payment_data) {
                                     $customer_id = $payment_data->customer_id;
                                     try {
                                         if (Config::get('app.default_payment') == 'stripe') {
                                             Stripe::setApiKey(Config::get('app.stripe_secret_key'));
                                             try {
                                                 Stripe_Charge::create(array("amount" => floor($total) * 100, "currency" => "usd", "customer" => $customer_id));
                                             } catch (Stripe_InvalidRequestError $e) {
                                                 // Invalid parameters were supplied to Stripe's API
                                                 $ownr = Owner::find($request->owner_id);
                                                 $ownr->debt = $total;
                                                 $ownr->save();
                                                 $response_array = array('error' => $e->getMessage());
                                                 $response_code = 200;
                                                 $response = Response::json($response_array, $response_code);
                                                 return $response;
                                             }
                                             $request->is_paid = 1;
                                             $setting = Settings::where('key', 'paypal')->first();
                                             $settng1 = Settings::where('key', 'service_fee')->first();
                                             if ($setting->value == 2 && $walker_data->merchant_id != NULL) {
                                                 // dd($amount$request->transfer_amount);
                                                 $transfer = Stripe_Transfer::create(array("amount" => ($total - $settng1->value) * 100, "currency" => "usd", "recipient" => $walker_data->merchant_id));
                                             }
                                         } else {
                                             $amount = $total;
                                             Braintree_Configuration::environment(Config::get('app.braintree_environment'));
                                             Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id'));
                                             Braintree_Configuration::publicKey(Config::get('app.braintree_public_key'));
                                             Braintree_Configuration::privateKey(Config::get('app.braintree_private_key'));
                                             $card_id = $payment_data->card_token;
                                             $setting = Settings::where('key', 'paypal')->first();
                                             $settng1 = Settings::where('key', 'service_fee')->first();
                                             if ($setting->value == 2 && $walker_data->merchant_id != NULL) {
                                                 // escrow
                                                 $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id));
                                             } else {
                                                 $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id));
                                             }
                                             Log::info('result = ' . print_r($result, true));
                                             if ($result->success) {
                                                 $request->is_paid = 1;
                                             } else {
                                                 $request->is_paid = 0;
                                             }
                                         }
                                     } catch (Exception $e) {
                                         $response_array = array('success' => false, 'error' => $e, 'error_code' => 405);
                                         $response_code = 200;
                                         $response = Response::json($response_array, $response_code);
                                         return $response;
                                     }
                                 }
                             }
                             $request->card_payment = $total;
                             $request->ledger_payment = $request->total - $total;
                             $request->save();
                             Log::info('Request = ' . print_r($request, true));
                             if ($request->is_paid == 1) {
                                 $owner = Owner::find($request->owner_id);
                                 $settings = Settings::where('key', 'sms_request_unanswered')->first();
                                 $pattern = $settings->value;
                                 $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern);
                                 $pattern = str_replace('%id%', $request->id, $pattern);
                                 $pattern = str_replace('%user_mobile%', $owner->phone, $pattern);
                                 sms_notification(1, 'admin', $pattern);
                             }
                             $walker = Walker::find($walker_id);
                             $walker->is_available = 1;
                             $walker->save();
                             // Send Notification
                             $walker = Walker::find($request->confirmed_walker);
                             $walker_data = array();
                             $walker_data['first_name'] = $walker->first_name;
                             $walker_data['last_name'] = $walker->last_name;
                             $walker_data['phone'] = $walker->phone;
                             $walker_data['bio'] = $walker->bio;
                             $walker_data['picture'] = $walker->picture;
                             $walker_data['type'] = $walker->type;
                             $walker_data['rating'] = $walker->rate;
                             $walker_data['num_rating'] = $walker->rate_count;
                             $walker_data['car_model'] = $walker->car_model;
                             $walker_data['car_number'] = $walker->car_number;
                             /* $walker_data['rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->avg('rating') ? : 0;
                                $walker_data['num_rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->count(); */
                             $settings = Settings::where('key', 'default_distance_unit')->first();
                             $unit = $settings->value;
                             if ($unit == 0) {
                                 $unit_set = 'kms';
                             } elseif ($unit == 1) {
                                 $unit_set = 'miles';
                             }
                             $bill = array();
                             if ($request->is_paid == 1) {
                                 $bill['distance'] = (string) convert($request->distance, $unit);
                                 $bill['unit'] = $unit_set;
                                 $bill['time'] = $request->time;
                                 $bill['base_price'] = currency_converted($base_price);
                                 $bill['distance_cost'] = currency_converted($distance_cost);
                                 $bill['time_cost'] = currency_converted($time_cost);
                                 $bill['total'] = currency_converted($request->total);
                                 $bill['is_paid'] = $request->is_paid;
                             }
                             $response_array = array('success' => true, 'request_id' => $request_id, 'status' => $request->status, 'confirmed_walker' => $request->confirmed_walker, 'walker' => $walker_data, 'bill' => $bill);
                             $title = "Payment Has Made";
                             $message = $response_array;
                             send_notifications($walker->id, "walker", $title, $message);
                             $settings = Settings::where('key', 'email_notification')->first();
                             $condition = $settings->value;
                             if ($condition == 1) {
                                 /* $settings = Settings::where('key', 'payment_made_client')->first();
                                                                       $pattern = $settings->value;
                                 
                                                                       $pattern = str_replace('%id%', $request->id, $pattern);
                                                                       $pattern = str_replace('%amount%', $request->total, $pattern);
                                 
                                                                       $subject = "Payment Charged";
                                                                       email_notification($walker->id, 'walker', $pattern, $subject); */
                                 $settings = Settings::where('key', 'admin_email_address')->first();
                                 $admin_email = $settings->value;
                                 $pattern = array('admin_eamil' => $admin_email, 'name' => ucwords($walker->first_name . " " . $walker->last_name), 'amount' => $total, 'req_id' => $request_id, 'web_url' => web_url());
                                 $subject = "Payment Done With " . $request_id . "";
                                 email_notification($walker->id, 'walker', $pattern, $subject, 'pre_payment', null);
                             }
                             // Send SMS
                             $owner = Owner::find($request->owner_id);
                             $settings = Settings::where('key', 'sms_when_provider_completes_job')->first();
                             $pattern = $settings->value;
                             $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern);
                             $pattern = str_replace('%driver%', $walker->first_name . " " . $walker->last_name, $pattern);
                             $pattern = str_replace('%driver_mobile%', $walker->phone, $pattern);
                             $pattern = str_replace('%amount%', $request->total, $pattern);
                             sms_notification($request->owner_id, 'owner', $pattern);
                             $email_data = array();
                             $email_data['name'] = $owner->first_name;
                             $email_data['emailType'] = 'user';
                             $email_data['base_price'] = $bill['base_price'];
                             $email_data['distance'] = $bill['distance'];
                             $email_data['time'] = $bill['time'];
                             $email_data['unit'] = $bill['unit'];
                             $email_data['total'] = $bill['total'];
                             if ($bill['payment_mode']) {
                                 $email_data['payment_mode'] = $bill['payment_mode'];
                             } else {
                                 $email_data['payment_mode'] = '---';
                             }
                             /* $subject = "Invoice Generated";
                                                               send_email($request->owner_id, 'owner', $email_data, $subject, 'invoice');
                             
                                                               $subject = "Invoice Generated";
                                                               $email_data['emailType'] = 'walker';
                                                               send_email($request->confirmed_walker, 'walker', $email_data, $subject, 'invoice');
                                                              */
                             if ($request->is_paid == 1) {
                                 // send email
                                 /* $settings = Settings::where('key', 'email_payment_charged')->first();
                                                                       $pattern = $settings->value;
                                 
                                                                       $pattern = str_replace('%id%', $request->id, $pattern);
                                                                       $pattern = str_replace('%url%', web_url() . "/admin/request/" . $request->id, $pattern);
                                 
                                                                       $subject = "Payment Charged";
                                                                       email_notification(1, 'admin', $pattern, $subject); */
                                 $settings = Settings::where('key', 'admin_email_address')->first();
                                 $admin_email = $settings->value;
                                 $pattern = array('admin_eamil' => $admin_email, 'name' => 'Administrator', 'amount' => $total, 'req_id' => $request_id, 'web_url' => web_url());
                                 $subject = "Payment Done With " . $request_id . "";
                                 email_notification(1, 'admin', $pattern, $subject, 'pay_charged', null);
                             }
                             $response_array = array('success' => true, 'base_fare' => currency_converted($base_price), 'distance_cost' => currency_converted($distance_cost), 'time_cost' => currency_converted($time_cost), 'total' => currency_converted($total), 'is_paid' => $request->is_paid);
                             $response_code = 200;
                         } else {
                             /* $var = Keywords::where('id', 1)->first();
                                $response_array = array('success' => false, 'error' => 'Service ID doesnot matches with ' . $var->keyword . ' ID', 'error_code' => 407); */
                             $response_array = array('success' => false, 'error' => 'Service ID doesnot matches with ' . Config::get('app.generic_keywords.Provider') . ' ID', 'error_code' => 407);
                             $response_code = 200;
                         }
                     } else {
                         $response_array = array('success' => false, 'error' => 'Service ID Not Found', 'error_code' => 408);
                         $response_code = 200;
                     }
                 } else {
                     $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                     $response_code = 200;
                 }
             } else {
                 if ($is_admin) {
                     /* $var = Keywords::where('id', 1)->first();
                        $response_array = array('success' => false, 'error' => '' . $var->keyword . ' ID not Found', 'error_code' => 410); */
                     $response_array = array('success' => false, 'error' => '' . Config::get('app.generic_keywords.Provider') . ' ID not Found', 'error_code' => 410);
                 } else {
                     $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
                 }
                 $response_code = 200;
             }
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
 public function user_set_destination()
 {
     $request_id = Input::get('request_id');
     $token = Input::get('token');
     $owner_id = Input::get('id');
     $dest_lat = Input::get('dest_lat');
     $dest_long = Input::get('dest_long');
     $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'owner_id' => $owner_id, 'dest_lat' => $dest_lat, 'dest_long' => $dest_long), array('request_id' => 'required|integer', 'token' => 'required', 'owner_id' => 'required|integer', 'dest_lat' => 'required', 'dest_long' => 'required'));
     if ($validator->fails()) {
         $error_messages = $validator->messages()->all();
         $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
         $response_code = 200;
     } else {
         $is_admin = $this->isAdmin($token);
         if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) {
             // check for token validity
             if (is_token_active($owner_data->token_expiry) || $is_admin) {
                 // Do necessary operations
                 if ($request = Requests::find($request_id)) {
                     if ($request->owner_id == $owner_data->id) {
                         Requests::where('id', $request_id)->update(array('D_latitude' => $dest_lat, 'D_longitude' => $dest_long));
                         if ($request->current_walker) {
                             $msg_array = array();
                             $msg_array['request_id'] = $request_id;
                             $msg_array['unique_id'] = 4;
                             $last_destination = Requests::find($request_id);
                             $owner = Owner::find($owner_id);
                             $request_data = array();
                             $request_data['owner'] = array();
                             $request_data['owner']['name'] = $owner->first_name . " " . $owner->last_name;
                             $request_data['owner']['picture'] = $owner->picture;
                             $request_data['owner']['phone'] = $owner->phone;
                             $request_data['owner']['address'] = $owner->address;
                             $request_data['owner']['latitude'] = $owner->latitude;
                             $request_data['owner']['longitude'] = $owner->longitude;
                             $request_data['owner']['dest_latitude'] = $last_destination->D_latitude;
                             $request_data['owner']['dest_longitude'] = $last_destination->D_longitude;
                             $request_data['owner']['rating'] = $owner->rate;
                             $request_data['owner']['num_rating'] = $owner->rate_count;
                             $request_data['dog'] = array();
                             if ($dog = Dog::find($owner->dog_id)) {
                                 $request_data['dog']['name'] = $dog->name;
                                 $request_data['dog']['age'] = $dog->age;
                                 $request_data['dog']['breed'] = $dog->breed;
                                 $request_data['dog']['likes'] = $dog->likes;
                                 $request_data['dog']['picture'] = $dog->image_url;
                             }
                             $msg_array['request_data'] = $request_data;
                             $title = "Set Destination";
                             $message = $msg_array;
                             if ($request->confirmed_walker == $request->current_walker) {
                                 send_notifications($request->confirmed_walker, "walker", $title, $message);
                             }
                         }
                         $response_array = array('success' => true, 'error' => "Destination Set Successfully");
                         $response_code = 200;
                     } else {
                         $response_array = array('success' => false, 'error' => 'Request ID doesnot matches with Owner ID', 'error_code' => 407);
                         $response_code = 200;
                     }
                 } else {
                     $response_array = array('success' => false, 'error' => 'Request ID Not Found', 'error_code' => 408);
                     $response_code = 200;
                 }
             } else {
                 $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                 $response_code = 200;
             }
         } else {
             if ($is_admin) {
                 $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410);
             } else {
                 $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
             }
             $response_code = 200;
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
Example #11
0
 public function add_input($address, $amount, $txid, $vout, $scriptsig = '', $confirmations = 0, $blocknum = 0)
 {
     // Initialize
     global $config;
     // Check mempool
     if ($row = DB::queryFirstRow("SELECT * FROM coin_mempool WHERE txid = %s AND vout = %d", $txid, $vout)) {
         return false;
     }
     DB::insert('coin_mempool', array('txid' => $txid, 'vout' => $vout));
     // Get address
     if (!($addr_row = DB::queryFirstRow("SELECT * FROM coin_addresses WHERE address = %s", $address))) {
         return false;
     }
     $is_confirmed = $confirmations >= $config['btc_minconf'] || $addr_row['is_change_address'] == 1 ? 1 : 0;
     // Check for invoice
     $product_id = 0;
     $invoice_id = 0;
     $order_id = 0;
     $order_complete = false;
     $overpayment = 0;
     if ($irow = DB::queryFirstRow("SELECT * FROM invoices WHERE payment_address = %s", $address)) {
         $invoice_id = $irow['id'];
         // Check for order
     } elseif ($prow = DB::queryFirstRow("SELECT * FROM coin_pending_payment WHERE payment_address = %s", $address)) {
         $prow['amount_received'] += $amount;
         if ($prow['amount_received'] >= $prow['amount_btc']) {
             DB::query("UPDATE coin_pending_payment SET status = 'approved', amount_received = amount_received + %d WHERE id = %d", $amount, $prow['id']);
             if ($prow['item_id'] > 0) {
                 $order_complete = true;
             }
         } else {
             DB::query("UPDATE coin_pending_payment SET amount_received = amount_received + %d WHERE id = %d", $amount, $prow['id']);
         }
         $product_id = $prow['item_id'];
         if ($prow['amount_received'] > $prow['amount_btc']) {
             $overpayment = $prow['amount_received'] - $prow['amount_btc'];
         }
     }
     // Check if exists
     if ($row = DB::queryFirstRow("SELECT * FROM coin_inputs WHERE txid = %s AND vout = %d", $txid, $vout)) {
         return false;
     }
     // Update invoice, if needed
     if ($invoice_id > 0) {
         $irow['amount_paid'] += $amount;
         $updates = array('amount_paid' => $irow['amount_paid']);
         if ($irow['amount_paid'] >= $irow['amount_btc']) {
             $updates['status'] = 'paid';
             $updates['date_paid'] = DB::sqleval('now()');
             DB::update('invoices', $updates, "id = %d", $invoice_id);
             if ($irow['amount_paid'] > $irow['amount_btc']) {
                 $overpayment = $irow['amount_paid'] - $irow['amount_btc'];
             }
         }
         // Add order, if needed
     } elseif ($order_complete === true) {
         DB::insert('orders', array('userid' => $addr_row['userid'], 'product_id' => $product_id, 'amount' => $prow['amount'], 'amount_btc' => $prow['amount_btc']));
         $order_id = DB::insertId();
     }
     // Add to DB
     $hash = $txid . ':' . $vout;
     DB::insert('coin_inputs', array('userid' => $addr_row['userid'], 'wallet_id' => $addr_row['wallet_id'], 'product_id' => $product_id, 'order_id' => $order_id, 'invoice_id' => $invoice_id, 'is_confirmed' => $is_confirmed, 'is_change' => $addr_row['is_change_address'], 'confirmations' => $confirmations, 'blocknum' => $blocknum, 'address' => $address, 'txid' => $txid, 'vout' => $vout, 'amount' => $amount, 'hash' => $hash));
     $input_id = DB::insertId();
     // Mark address as used
     DB::query("UPDATE coin_addresses SET is_used = 1, total_input = total_input + %d WHERE address = %s", $amount, $address);
     // Add overpayment, if needed
     if ($overpayment != 0) {
         DB::insert('coin_overpayments', array('userid' => $addr_row['userid'], 'input_id' => $input_id, 'amount_btc' => $overpayment));
     }
     // Add alerts
     if ($product_id > 0) {
         add_alert('product_purchase', $input_id, $amount);
     } elseif ($invoice_id > 0) {
         add_alert('invoice_paid', $input_id, $amount);
     } elseif ($addr_row['is_change_address'] != 1) {
         add_alert('new_deposit', $input_id, $amount);
     }
     // Process notifications
     if ($addr_row['is_change_address'] != 1) {
         send_notifications('new_deposit', $input_id);
     }
     if ($product_id > 0) {
         send_notifications('product_purchase', $input_id);
     }
     if ($invoice_id > 0) {
         send_notifications('invoice_paid', $input_id);
     }
     // Execute hooks, as needed
     if ($addr_row['is_change_address'] != 1) {
         execute_hooks('new_deposit', $input_id);
     }
     if ($is_confirmed == 1) {
         execute_hooks('confirmed_deposit', $input_id);
     }
     if ($product_id > 0) {
         execute_hooks('product_purchased', $input_id, $product_id);
     }
     if ($invoice_id > 0) {
         execute_hooks('invoice_paid', $input_id);
     }
     // Return
     return $input_id;
 }
 public function saveUserRequestTrip()
 {
     Session::forget('skipReview');
     $latitude = Input::get('latitude');
     $longitude = Input::get('longitude');
     $d_latitude = Input::get('d_latitude');
     $d_longitude = Input::get('d_longitude');
     $type = Input::get('type');
     $owner_id = Session::get('user_id');
     $payment_type = Input::get('payment_type');
     if ($type == "") {
         $message = "Please Select the Service Type";
         $type = "warning";
         return Redirect::route('userrequestTrip')->with('message', $message)->with('type', $type);
     } else {
         if (Input::has('promo_code')) {
             $promo_code = Input::get('promo_code');
             $code_check = PromoCodes::where('coupon_code', $promo_code)->first();
             if ($code_check == NULL) {
                 $message = "Invalid Promo Code";
                 $type = "error";
                 return Redirect::route('userrequestTrip')->with('message', $message)->with('type', $type);
             } else {
                 if ($code_check->state == 1 && date('Y-m-d H:i:s', strtotime($code_check->expiry)) > date('Y-m-d H:i:s')) {
                     $code_id = $code_check->id;
                 } else {
                     $message = "Invalid Promo Code";
                     $type = "error";
                     return Redirect::route('userrequestTrip')->with('message', $message)->with('type', $type);
                 }
             }
         } else {
             $code_id = NULL;
         }
         $owner_data = Owner::find($owner_id);
         $settings = Settings::where('key', 'default_search_radius')->first();
         $distance = $settings->value;
         if (Input::has('type')) {
             $type = Input::get('type');
             if (!$type) {
                 // choose default type
                 $provider_type = ProviderType::where('is_default', 1)->first();
                 if (!$provider_type) {
                     $type = 1;
                 } else {
                     $type = $provider_type->id;
                 }
             }
         }
         $typequery = "SELECT distinct provider_id from walker_services where type IN({$type})";
         $typewalkers = DB::select(DB::raw($typequery));
         /* $var = Keywords::where('id', 1)->first(); */
         if (empty($typewalkers)) {
             /* $message = "No " . $var->keyword . " found matching the service type."; */
             $message = "No " . Config::get('app.generic_keywords.Provider') . " found matching the service type.";
         } else {
             Log::info('typewalkers = ' . print_r($typewalkers, true));
             foreach ($typewalkers as $key) {
                 $types[] = $key->provider_id;
             }
             $typestring = implode(",", $types);
             Log::info('typestring = ' . print_r($typestring, true));
             if ($typestring == '') {
                 /* $message = "No " . $var->keyword . " found matching the service type."; */
                 $message = "No " . Config::get('app.generic_keywords.Provider') . " found matching the service type.";
             }
             $settings = Settings::where('key', 'default_search_radius')->first();
             $distance = $settings->value;
             $settings = Settings::where('key', 'default_distance_unit')->first();
             $unit = $settings->value;
             if ($unit == 0) {
                 $multiply = 1.609344;
             } elseif ($unit == 1) {
                 $multiply = 1;
             }
             $query = "SELECT walker.*, ROUND(" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ,8) as distance from walker where is_available = 1 and is_active = 1 and is_approved = 1 and ROUND((" . $multiply . " * 3956 * acos( cos( radians('{$latitude}') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('{$longitude}') ) + sin( radians('{$latitude}') ) * sin( radians(latitude) ) ) ) ,8) <= {$distance} and walker.deleted_at IS NULL and walker.id IN({$typestring}) order by distance";
             $walkers = DB::select(DB::raw($query));
             $walker_list = array();
             $owner = Owner::find($owner_id);
             $owner->latitude = $latitude;
             $owner->longitude = $longitude;
             $owner->save();
             $user_timezone = $owner->timezone;
             $default_timezone = Config::get('app.timezone');
             $offset = $this->get_timezone_offset($default_timezone, $user_timezone);
             $request = new Requests();
             $request->owner_id = $owner_id;
             if ($d_longitude != '' && $d_latitude != '') {
                 $request->D_latitude = $d_latitude;
                 $request->D_longitude = $d_longitude;
             }
             $request->request_start_time = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s")) + $offset);
             $request->save();
             $request_service = new RequestServices();
             $request_service->type = $type;
             $request_service->request_id = $request->id;
             $request_service->save();
             $i = 0;
             $first_walker_id = 0;
             foreach ($walkers as $walker) {
                 $request_meta = new RequestMeta();
                 $request_meta->request_id = $request->id;
                 $request_meta->walker_id = $walker->id;
                 if ($i == 0) {
                     $first_walker_id = $walker->id;
                     $i++;
                 }
                 $request_meta->save();
             }
             $req = Requests::find($request->id);
             $req->current_walker = $first_walker_id;
             $req->confirmed_walker = 0;
             $req->payment_mode = $payment_type;
             $req->promo_code = $code_id;
             $req->save();
             $settings = Settings::where('key', 'provider_timeout')->first();
             $time_left = $settings->value;
             /* $var = Keywords::where('id', 1)->first();
             
                               $message = "Your Request is successful. Please wait while we are finding a nearest " . $var->keyword . " for you."; */
             $message = "Your Request is successful. Please wait while we are finding a nearest " . Config::get('app.generic_keywords.Provider') . " for you.";
             $type = "success";
         }
         return Redirect::to('/user/request-trip')->with('message', $message)->with('type', $type);
         // Send Notification
         $walker = Walker::find($first_walker_id);
         if ($walker) {
             $msg_array = array();
             $msg_array['unique_id'] = 1;
             $msg_array['request_id'] = $request->id;
             $msg_array['time_left_to_respond'] = $time_left;
             $owner = Owner::find($owner_id);
             $request_data = array();
             $request_data['owner'] = array();
             $request_data['owner']['name'] = $owner->first_name . " " . $owner->last_name;
             $request_data['owner']['picture'] = $owner->picture;
             $request_data['owner']['phone'] = $owner->phone;
             $request_data['owner']['address'] = $owner->address;
             $request_data['owner']['latitude'] = $owner->latitude;
             $request_data['owner']['longitude'] = $owner->longitude;
             /* $request_data['owner']['rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->avg('rating') ? : 0; */
             $request_data['owner']['rating'] = $owner->rate;
             /* $request_data['owner']['num_rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->count(); */
             $request_data['owner']['num_rating'] = $owner->rate_count;
             $request_data['dog'] = array();
             if ($dog = Dog::find($owner->dog_id)) {
                 $request_data['dog']['name'] = $dog->name;
                 $request_data['dog']['age'] = $dog->age;
                 $request_data['dog']['breed'] = $dog->breed;
                 $request_data['dog']['likes'] = $dog->likes;
                 $request_data['dog']['picture'] = $dog->image_url;
             }
             $msg_array['request_data'] = $request_data;
             $title = "New Request";
             $message = json_encode($msg_array);
             send_notifications($first_walker_id, "walker", $title, $message);
         }
         // Send SMS
         $settings = Settings::where('key', 'sms_request_created')->first();
         $pattern = $settings->value;
         $pattern = str_replace('%user%', $owner_data->first_name . " " . $owner_data->last_name, $pattern);
         $pattern = str_replace('%id%', $request->id, $pattern);
         $pattern = str_replace('%user_mobile%', $owner_data->phone, $pattern);
         sms_notification(1, 'admin', $pattern);
         // send email
         /* $settings = Settings::where('key', 'email_new_request')->first();
            $pattern = $settings->value;
            $pattern = str_replace('%id%', $request->id, $pattern);
            $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $request->id, $pattern);
            $subject = "New Request Created";
            email_notification(1, 'admin', $pattern, $subject); */
         $settings = Settings::where('key', 'admin_email_address')->first();
         $admin_email = $settings->value;
         $follow_url = web_url() . "/user/signin";
         $pattern = array('admin_eamil' => $admin_email, 'trip_id' => $request->id, 'follow_url' => $follow_url);
         $subject = "Ride Booking Request";
         email_notification(1, 'admin', $pattern, $subject, 'new_request', null);
         return Redirect::to('/user/request-trip')->with('message', $message)->with('type', $type);
     }
 }
Example #13
0
        continue;
    }
    // Process transaction, if ok
    if ($template->has_errors != 1) {
        // Update db
        DB::update('coin_sends', array('status' => 'sent', 'txid' => $txid), "id = %d", $_POST['send_id']);
        // Mark inputs as spent
        $input_ids = explode(",", $_POST['input_ids']);
        foreach ($input_ids as $input_id) {
            if (!$input_id > 0) {
                continue;
            }
            DB::query("UPDATE coin_inputs SET is_spent = 1, is_locked = 0 WHERE id = %d", $input_id);
        }
        // Send notifications
        send_notifications('funds_sent', $_POST['send_id']);
        // Execute hooks
        execute_hooks('funds_sent', $_POST['send_id']);
        // User message
        $template->add_message("Successfully broadcast transaction, TxID {$txid}");
    }
}
// Initialize
$bip32 = new bip32();
// Get wallets
$first = true;
$bip32_key_fields = '';
$required_sigs = 0;
$wallet_id = 0;
$wallet_javascript = '';
$wallet_options = '';
 public function sendPush($id)
 {
     $post = Post::find($id);
     if ($post) {
         $response_array = $post->title;
         $title = "PBN";
         $message = $post->title;
         $post_id = $post->id;
         $url = "single.html";
         Log::info($message);
         send_notifications($title, $message, $post_id, $url);
         Log::info("push started");
         return Redirect::back()->with('flash_success', tr('push_notification_success'));
     } else {
         return Redirect::back()->with('flash_error', tr('push_notification_error'));
     }
 }
 public function decline_request()
 {
     $request_id = Request::segment(4);
     $walker_id = Session::get('walker_id');
     $request = Requests::find($request_id);
     if ($request->current_walker == $walker_id) {
         // Archiving Old Walker
         RequestMeta::where('request_id', '=', $request_id)->where('walker_id', '=', $walker_id)->update(array('status' => 3));
         $request_meta = RequestMeta::where('request_id', '=', $request_id)->where('status', '=', 0)->orderBy('created_at')->first();
         // update request
         if (isset($request_meta->walker_id)) {
             // assign new walker
             Requests::where('id', '=', $request_id)->update(array('current_walker' => $request_meta->walker_id, 'request_start_time' => date("Y-m-d H:i:s")));
             // Send Notification
             $walker = Walker::find($request_meta->walker_id);
             $owner_data = Owner::find($request->owner_id);
             $msg_array = array();
             $msg_array['request_id'] = $request->id;
             $msg_array['id'] = $request_meta->walker_id;
             if ($walker) {
                 $msg_array['token'] = $walker->token;
             }
             $msg_array['client_profile'] = array();
             $msg_array['client_profile']['name'] = $owner_data->first_name . " " . $owner_data->last_name;
             $msg_array['client_profile']['picture'] = $owner_data->picture;
             $msg_array['client_profile']['bio'] = $owner_data->bio;
             $msg_array['client_profile']['address'] = $owner_data->address;
             $msg_array['client_profile']['phone'] = $owner_data->phone;
             $title = "New Request";
             $message = $msg_array;
             send_notifications($request_meta->walker_id, "walker", $title, $message);
         } else {
             // request ended
             Requests::where('id', '=', $request_id)->update(array('current_walker' => 0, 'status' => 1));
         }
     }
     return Redirect::to('/provider/trips');
 }
function sysalerts_smtp_client_scan($uuid)
{
    $unix = new unix();
    $sock = new sockets();
    $q = new mysql();
    if (!$q->test_mysql_connection()) {
        return;
    }
    $meta = new mysql_meta();
    $hostname = $meta->uuid_to_host($uuid);
    $tag = $meta->uuid_to_tag($uuid);
    if ($tag != null) {
        $hostname = "{$hostname}/{$tag}";
    }
    $severityT[0] = "Alert";
    $severityT[1] = "Warning";
    $ArticaMetaStorage = $sock->GET_INFO("ArticaMetaStorage");
    if ($ArticaMetaStorage == null) {
        $ArticaMetaStorage = "/home/artica-meta";
    }
    $destdir = "{$ArticaMetaStorage}/{$uuid}/SMTP_NOTIF";
    $files = $unix->DirFiles($destdir);
    while (list($filename, $ARRAY) = each($files)) {
        $sourcefile = "{$destdir}/{$filename}";
        $filetime = $unix->file_time_min($sourcefile);
        if ($filetime > 240) {
            @unlink($sourcefile);
            continue;
        }
        $array = unserialize(@file_get_contents($sourcefile));
        if (!is_array($array)) {
            meta_events("{$sourcefile} no such array");
            @unlink($sourcefile);
            continue;
        }
        $zdate = $array["zdate"];
        $subject = $array["subject"];
        $text = $array["text"];
        $severity = $array["severity"];
        $function = $array["function"];
        $file = $array["file"];
        $line = $array["line"];
        $md5 = md5("{$uuid}{$subject}");
        if (isset($GLOBALS["NOTIFS"][$md5])) {
            @unlink($sourcefile);
            continue;
        }
        $GLOBALS["NOTIFS"][$md5] = true;
        $subject = "[{$hostname}]:{$severityT[$severity]} {$subject}";
        $content = "Operation created by {$hostname} on {$zdate} by {$file} ({$function} in line:{$line})\nuuid:{$uuid}\n{$text}\n";
        if (!send_notifications($subject, $content)) {
            continue;
        }
        @unlink($sourcefile);
    }
}
/**
 * This function sends the notification mails to everybody who stated that they wanted to be informed when a new post
 * was added to a given thread.
 *
 * @param array reply information
 * @return void
 *
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @version february 2006, dokeos 1.8
 */
function send_notification_mails($thread_id, $reply_info)
{
    $table = Database::get_course_table(TABLE_FORUM_MAIL_QUEUE);
    // First we need to check if
    // 1. the forum category is visible
    // 2. the forum is visible
    // 3. the thread is visible
    // 4. the reply is visible (=when there is)
    $current_thread = get_thread_information($thread_id);
    $current_forum = get_forum_information($current_thread['forum_id']);
    $current_forum_category = null;
    if (isset($current_forum['forum_category'])) {
        $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
    }
    if ($current_thread['visibility'] == '1' && $current_forum['visibility'] == '1' && ($current_forum_category && $current_forum_category['visibility'] == '1') && $current_forum['approval_direct_post'] != '1') {
        $send_mails = true;
    } else {
        $send_mails = false;
    }
    // The forum category, the forum, the thread and the reply are visible to the user
    if ($send_mails) {
        if (isset($current_thread['forum_id'])) {
            send_notifications($current_thread['forum_id'], $thread_id);
        }
    } else {
        $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION);
        if (isset($current_forum['forum_id'])) {
            $sql = "SELECT * FROM {$table_notification}\n                    WHERE\n                        c_id = " . api_get_course_int_id() . " AND\n                        (\n                            forum_id = '" . intval($current_forum['forum_id']) . "' OR\n                            thread_id = '" . intval($thread_id) . "'\n                        ) ";
            $result = Database::query($sql);
            $user_id = api_get_user_id();
            while ($row = Database::fetch_array($result)) {
                $sql = "INSERT INTO {$table} (c_id, thread_id, post_id, user_id)\n                        VALUES (" . api_get_course_int_id() . ", '" . intval($thread_id) . "', '" . intval($reply_info['new_post_id']) . "', '{$user_id}' )";
                Database::query($sql);
            }
        }
    }
}
 public function request_walk_completed()
 {
     if (Request::isMethod('post')) {
         $request_id = Input::get('request_id');
         $token = Input::get('token');
         $walker_id = Input::get('id');
         $latitude = Input::get('latitude');
         $longitude = Input::get('longitude');
         $distance = Input::get('distance');
         $time = Input::get('time');
         $walker = Walker::find($walker_id);
         $validator = Validator::make(array('request_id' => $request_id, 'token' => $token, 'walker_id' => $walker_id, 'latitude' => $latitude, 'longitude' => $longitude, 'distance' => $distance, 'time' => $time), array('request_id' => 'required|integer', 'token' => 'required', 'walker_id' => 'required|integer', 'latitude' => 'required', 'longitude' => 'required', 'distance' => 'required', 'time' => 'required'));
         if ($validator->fails()) {
             $error_messages = $validator->messages()->all();
             $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
             $response_code = 200;
         } else {
             $is_admin = $this->isAdmin($token);
             if ($walker_data = $this->getWalkerData($walker_id, $token, $is_admin)) {
                 // check for token validity
                 if (is_token_active($walker_data->token_expiry) || $is_admin) {
                     // Do necessary operations
                     if ($request = Requests::find($request_id)) {
                         if ($request->confirmed_walker == $walker_id) {
                             if ($request->is_started == 1) {
                                 $settings = Settings::where('key', 'default_charging_method_for_users')->first();
                                 $pricing_type = $settings->value;
                                 $settings = Settings::where('key', 'default_distance_unit')->first();
                                 $unit = $settings->value;
                                 $distance = convert($distance, $unit);
                                 $pt = ProviderServices::where('provider_id', $walker_id)->get();
                                 foreach ($pt as $key) {
                                     $reqserv = RequestServices::where('request_id', $request_id)->where('type', $key->type)->first();
                                     $base_price = $key->base_price;
                                     $price_per_unit_distance = $key->price_per_unit_distance * $distance;
                                     $price_per_unit_time = $key->price_per_unit_time * $time;
                                     $reqserv->base_price = $base_price;
                                     $reqserv->distance_cost = $price_per_unit_distance;
                                     $reqserv->time_cost = $price_per_unit_time;
                                     $reqserv->total = $base_price + $price_per_unit_distance + $price_per_unit_time;
                                     $reqserv->save();
                                 }
                                 $rs = RequestServices::where('request_id', $request_id)->get();
                                 $total = 0;
                                 foreach ($rs as $key) {
                                     Log::info('total = ' . print_r($key->total, true));
                                     $total = $total + $key->total;
                                 }
                                 $request->is_completed = 1;
                                 $request->distance = $distance;
                                 $request->time = $time;
                                 $request->total = $total;
                                 // charge client
                                 $ledger = Ledger::where('owner_id', $request->owner_id)->first();
                                 if ($ledger) {
                                     $balance = $ledger->amount_earned - $ledger->amount_spent;
                                     if ($balance > 0) {
                                         if ($total > $balance) {
                                             $ledger_temp = Ledger::find($ledger->id);
                                             $ledger_temp->amount_spent = $ledger_temp->amount_spent + $balance;
                                             $ledger_temp->save();
                                             $total = $total - $balance;
                                         } else {
                                             $ledger_temp = Ledger::find($ledger->id);
                                             $ledger_temp->amount_spent = $ledger_temp->amount_spent + $total;
                                             $ledger_temp->save();
                                             $total = 0;
                                         }
                                     }
                                 }
                                 if ($total == 0) {
                                     $request->is_paid = 1;
                                 } else {
                                     $payment_data = Payment::where('owner_id', $request->owner_id)->first();
                                     if ($payment_data) {
                                         $customer_id = $payment_data->customer_id;
                                         try {
                                             if (Config::get('app.default_payment') == 'stripe') {
                                                 $am = round($total) * 100;
                                                 $sett = Settings::where('key', 'service_fee')->first();
                                                 $serviceFee = $sett->value * 100;
                                                 $amount = $am - $serviceFee;
                                                 Stripe::setApiKey(Config::get('app.stripe_secret_key'));
                                                 Stripe_Charge::create(array("amount" => $am, "currency" => "usd", "customer" => $customer_id));
                                                 if ($walker->merchant_id != NULL) {
                                                     $transfer = Stripe_Transfer::create(array("amount" => $amount, "currency" => "usd", "recipient" => $walker->merchant_id, "statement_descriptor" => "UberFoxX"));
                                                     Log::info('transfer = ' . print_r($transfer, true));
                                                 }
                                                 $request->is_paid = 1;
                                             } else {
                                                 $am = round($total, 2);
                                                 $sett = Settings::where('key', 'service_fee')->first();
                                                 $serviceFee = $sett->value;
                                                 $amount = $am - $serviceFee;
                                                 Braintree_Configuration::environment(Config::get('app.braintree_environment'));
                                                 Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id'));
                                                 Braintree_Configuration::publicKey(Config::get('app.braintree_public_key'));
                                                 Braintree_Configuration::privateKey(Config::get('app.braintree_private_key'));
                                                 $card_id = $payment_data->card_token;
                                                 if ($walker->merchant_id == NULL) {
                                                     $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id));
                                                 } else {
                                                     $result = Braintree_Transaction::sale(array('amount' => $amount, 'paymentMethodToken' => $card_id, 'merchantAccountId' => $walker->merchant_id, 'serviceFeeAmount' => $serviceFee));
                                                 }
                                                 Log::info('result = ' . print_r($result, true));
                                                 if ($result->success) {
                                                     $request->is_paid = 1;
                                                 } else {
                                                     $request->is_paid = 0;
                                                 }
                                             }
                                         } catch (Exception $e) {
                                             $response_array = array('success' => false, 'error' => $e, 'error_code' => 405);
                                             $response_code = 200;
                                             $response = Response::json($response_array, $response_code);
                                             return $response;
                                         }
                                     }
                                 }
                                 $request->card_payment = $total;
                                 $request->ledger_payment = $request->total - $total;
                                 $request->save();
                                 if ($request->is_paid == 1) {
                                     $owner = Owner::find($request->owner_id);
                                     $settings = Settings::where('key', 'sms_request_unanswered')->first();
                                     $pattern = $settings->value;
                                     $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern);
                                     $pattern = str_replace('%id%', $request->id, $pattern);
                                     $pattern = str_replace('%user_mobile%', $owner->phone, $pattern);
                                     sms_notification(1, 'admin', $pattern);
                                 }
                                 $walker = Walker::find($walker_id);
                                 $walker->is_available = 1;
                                 $walker->save();
                                 $walk_location = new WalkLocation();
                                 $walk_location->latitude = $latitude;
                                 $walk_location->longitude = $longitude;
                                 $walk_location->request_id = $request_id;
                                 $walk_location->save();
                                 // Send Notification
                                 $walker = Walker::find($request->confirmed_walker);
                                 $walker_data = array();
                                 $walker_data['first_name'] = $walker->first_name;
                                 $walker_data['last_name'] = $walker->last_name;
                                 $walker_data['phone'] = $walker->phone;
                                 $walker_data['bio'] = $walker->bio;
                                 $walker_data['picture'] = $walker->picture;
                                 $walker_data['latitude'] = $walker->latitude;
                                 $walker_data['longitude'] = $walker->longitude;
                                 $walker_data['type'] = $walker->type;
                                 $walker_data['rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->avg('rating') ?: 0;
                                 $walker_data['num_rating'] = DB::table('review_walker')->where('walker_id', '=', $walker->id)->count();
                                 $settings = Settings::where('key', 'default_distance_unit')->first();
                                 $unit = $settings->value;
                                 $bill = array();
                                 if ($request->is_completed == 1) {
                                     $bill['distance'] = convert($request->distance, $unit);
                                     $bill['time'] = $request->time;
                                     $bill['base_price'] = $request->base_price;
                                     $bill['distance_cost'] = $request->distance_cost;
                                     $bill['time_cost'] = $request->time_cost;
                                     $bill['total'] = $request->total;
                                     $bill['is_paid'] = $request->is_paid;
                                 }
                                 $response_array = array('success' => true, 'request_id' => $request_id, 'status' => $request->status, 'confirmed_walker' => $request->confirmed_walker, 'is_walker_started' => $request->is_walker_started, 'is_walker_arrived' => $request->is_walker_arrived, 'is_walk_started' => $request->is_started, 'is_completed' => $request->is_completed, 'is_walker_rated' => $request->is_walker_rated, 'walker' => $walker_data, 'bill' => $bill);
                                 $title = "Trip Completed";
                                 $message = $response_array;
                                 send_notifications($request->owner_id, "owner", $title, $message);
                                 // Send SMS
                                 $owner = Owner::find($request->owner_id);
                                 $settings = Settings::where('key', 'sms_when_provider_completes_job')->first();
                                 $pattern = $settings->value;
                                 $pattern = str_replace('%user%', $owner->first_name . " " . $owner->last_name, $pattern);
                                 $pattern = str_replace('%driver%', $walker->first_name . " " . $walker->last_name, $pattern);
                                 $pattern = str_replace('%driver_mobile%', $walker->phone, $pattern);
                                 $pattern = str_replace('%damount%', $request->total, $pattern);
                                 sms_notification($request->owner_id, 'owner', $pattern);
                                 // send email
                                 $settings = Settings::where('key', 'email_request_finished')->first();
                                 $pattern = $settings->value;
                                 $pattern = str_replace('%id%', $request->id, $pattern);
                                 $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $request->id, $pattern);
                                 $subject = "Request Completed";
                                 email_notification(1, 'admin', $pattern, $subject);
                                 $settings = Settings::where('key', 'email_invoice_generated_user')->first();
                                 $pattern = $settings->value;
                                 $pattern = str_replace('%id%', $request->id, $pattern);
                                 $pattern = str_replace('%amount%', $request->total, $pattern);
                                 $subject = "Invoice Generated";
                                 email_notification($request->owner_id, 'owner', $pattern, $subject);
                                 $settings = Settings::where('key', 'email_invoice_generated_provider')->first();
                                 $pattern = $settings->value;
                                 $pattern = str_replace('%id%', $request->id, $pattern);
                                 $pattern = str_replace('%amount%', $request->total, $pattern);
                                 $subject = "Invoice Generated";
                                 email_notification($request->confirmed_walker, 'walker', $pattern, $subject);
                                 if ($request->is_paid == 1) {
                                     // send email
                                     $settings = Settings::where('key', 'email_payment_charged')->first();
                                     $pattern = $settings->value;
                                     $pattern = str_replace('%id%', $request->id, $pattern);
                                     $pattern = str_replace('%url%', web_url() . "/admin/request/map/" . $request->id, $pattern);
                                     $subject = "Payment Charged";
                                     email_notification(1, 'admin', $pattern, $subject);
                                 }
                                 $response_array = array('success' => true, 'total' => $total, 'is_paid' => $request->is_paid);
                                 $response_code = 200;
                             } else {
                                 $response_array = array('success' => false, 'error' => 'Walk not yet started', 'error_code' => 413);
                                 $response_code = 200;
                             }
                         } else {
                             $response_array = array('success' => false, 'error' => 'Walk ID doesnot matches with Walker ID', 'error_code' => 407);
                             $response_code = 200;
                         }
                     } else {
                         $response_array = array('success' => false, 'error' => 'Walk ID Not Found', 'error_code' => 408);
                         $response_code = 200;
                     }
                 } else {
                     $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                     $response_code = 200;
                 }
             } else {
                 if ($is_admin) {
                     $response_array = array('success' => false, 'error' => 'Walker ID not Found', 'error_code' => 410);
                 } else {
                     $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
                 }
                 $response_code = 200;
             }
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
 public function userTripCancel()
 {
     $request_id = Request::segment(4);
     $owner_id = Session::get('user_id');
     $request = Requests::find($request_id);
     if ($request->owner_id == $owner_id) {
         Requests::where('id', $request_id)->update(array('is_cancelled' => 1));
         RequestMeta::where('request_id', $request_id)->update(array('is_cancelled' => 1));
         if ($request->confirmed_walker) {
             $walker = Walker::find($request->confirmed_walker);
             $walker->is_available = 1;
             $walker->save();
         }
         if ($request->current_walker) {
             $msg_array = array();
             $msg_array['request_id'] = $request_id;
             $msg_array['unique_id'] = 2;
             $owner = Owner::find($owner_id);
             $request_data = array();
             $request_data['owner'] = array();
             $request_data['owner']['name'] = $owner->first_name . " " . $owner->last_name;
             $request_data['owner']['picture'] = $owner->picture;
             $request_data['owner']['phone'] = $owner->phone;
             $request_data['owner']['address'] = $owner->address;
             $request_data['owner']['latitude'] = $owner->latitude;
             $request_data['owner']['longitude'] = $owner->longitude;
             $request_data['owner']['rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->avg('rating') ?: 0;
             $request_data['owner']['num_rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->count();
             $request_data['dog'] = array();
             if ($dog = Dog::find($owner->dog_id)) {
                 $request_data['dog']['name'] = $dog->name;
                 $request_data['dog']['age'] = $dog->age;
                 $request_data['dog']['breed'] = $dog->breed;
                 $request_data['dog']['likes'] = $dog->likes;
                 $request_data['dog']['picture'] = $dog->image_url;
             }
             $msg_array['request_data'] = $request_data;
             $title = "Request Cancelled";
             $message = $msg_array;
             send_notifications($request->current_walker, "walker", $title, $message);
         }
     }
     // Redirect
     $message = "Your Request is Cancelled.";
     $type = "success";
     return Redirect::to('/user/trips')->with('message', $message)->with('type', $type);
 }
Example #20
0
        print_footer();
        die;
    }
    $comment = array();
    $comment["cid"] = 0;
    $comment["sid"] = $sid;
    $comment["qid"] = $qid;
    $comment["pid"] = $pid;
    $comment["parent"] = $cid;
    $comment["zid"] = $zid;
    $comment["time"] = $time;
    $comment["subject"] = $subject;
    $comment["comment"] = $new_body;
    db_set_rec("comment", $comment);
    $comment = db_get_rec("comment", array("zid" => $zid, "time" => $time));
    send_notifications($cid, $comment);
    if ($sid != 0) {
        header("Location: /story/{$day}/" . $story["ctitle"]);
    } elseif ($pid != 0) {
        header("Location: /pipe/{$pid}");
    } elseif ($qid != 0) {
        header("Location: /poll/{$qid}");
    }
    die;
}
$sid = http_get_int("sid", array("required" => false));
$cid = http_get_int("cid", array("required" => false));
$pid = http_get_int("pid", array("required" => false));
$qid = http_get_int("qid", array("required" => false));
print_header("Post Comment");
writeln('<table class="fill">');