Exemplo n.º 1
0
 public function index($single_id = null)
 {
     $info = get_single($single_id);
     if (empty($info)) {
         $this->_empty();
     }
     $tpl = empty($info['index_tpl']) ? 'index' : $info['index_tpl'];
     $this->assign('single', $info);
     $this->display($tpl);
 }
Exemplo n.º 2
0
 public function process()
 {
     if (isset($_REQUEST['_process']) && $_REQUEST['_process'] == 'ajax_save_map_coords') {
         $address_id = (int) $_REQUEST['address_id'];
         if ($address_id && !empty($_REQUEST['address_hash']) && !empty($_REQUEST['lat']) && !empty($_REQUEST['lng'])) {
             // existing?
             $existing = get_single('map', 'address_id', $address_id);
             update_insert('map_id', $existing ? $existing['map_id'] : false, 'map', array('address_hash' => $_REQUEST['address_hash'], 'address_id' => $_REQUEST['address_id'], 'lat' => $_REQUEST['lat'], 'lng' => $_REQUEST['lng']));
         }
         echo 'Done';
         exit;
     }
 }
Exemplo n.º 3
0
    $address = module_address::get_address($customer['customer_id'], 'customer', 'physical');
    if (!empty($address)) {
        $address_count = 0;
        $customer['full_address'] = '';
        foreach (array('line_1', 'line_2', 'suburb', 'state', 'region', 'country', 'post_code') as $key) {
            if (!empty($address[$key])) {
                $address_count++;
                $customer['full_address'] .= $address[$key] . ', ';
            }
            $customer[$key] = $address[$key];
        }
        if ($address_count > 1) {
            $customer['address_id'] = $address['address_id'];
            $customer['full_address'] = rtrim($customer['full_address'], ', ');
            $customer['address_hash'] = md5(serialize($address));
            $geocode = get_single('map', 'address_id', $address['address_id']);
            if ($geocode) {
                // check hash matches - ie address hasn't changed.
                if ($geocode['address_hash'] == $customer['address_hash']) {
                    $customer = array_merge($customer, $geocode);
                }
            }
            $customer_addresses[] = $customer;
        }
    }
}
foreach ($customer_addresses as $customer_address) {
    ?>
customer_address.push(<?php 
    echo json_encode($customer_address);
    ?>
Exemplo n.º 4
0
            ?>

		                                    <a href="#"
		                                       onclick="editinvoice_payment('<?php 
            echo $invoice_payment_id;
            ?>
',0); return false;"><?php 
            _e('Edit');
            ?>
</a> |
	                                    <?php 
        }
        // more details to the finance section
        if (class_exists('module_finance', false) && module_finance::is_plugin_enabled() && module_finance::can_i('view', 'Finance') && module_finance::is_enabled()) {
            // check if this finance has been added to the finance section yet.
            $existing_finance = get_single('finance', 'invoice_payment_id', $invoice_payment_data['invoice_payment_id']);
            if ($existing_finance) {
                ?>
 <a href="<?php 
                echo module_finance::link_open($existing_finance['finance_id']);
                ?>
"><?php 
                _e('More');
                ?>
</a> | <?php 
            } else {
                ?>
 <a href="<?php 
                echo module_finance::link_open('new', false) . '&invoice_payment_id=' . $invoice_payment_data['invoice_payment_id'];
                ?>
"><?php 
Exemplo n.º 5
0
 public function get_data()
 {
     if (count($this->_get_data_cache)) {
         return $this->_get_data_cache;
     }
     $file = false;
     if ($this->file_id > 0) {
         $file = get_single("file", "file_id", $this->file_id);
     }
     // check user has permissions to view this file.
     // for now we just base this on the customer id check
     if ($file) {
         // staff listing
         $staff = get_multiple('file_user_rel', array('file_id' => $file['file_id']), 'user_id');
         $file['staff_ids'] = array_keys($staff);
         $file['type'] = isset($file['file_url']) && $file['file_url'] ? 'remote' : (isset($file['bucket']) && $file['bucket'] ? 'bucket' : 'upload');
         if ($this->do_permissions) {
             switch (module_file::get_file_data_access()) {
                 case _FILE_ACCESS_ALL:
                     // all files, no limits on SQL here
                     break;
                 case _FILE_ACCESS_JOBS:
                     $jobs = module_job::get_jobs(array(), array('columns' => 'u.job_id AS id'));
                     if (!$file['job_id'] || !isset($jobs[$file['job_id']])) {
                         $file = false;
                     }
                     break;
                 case _FILE_ACCESS_ME:
                     if ($file['create_user_id'] != module_security::get_loggedin_id()) {
                         $file = false;
                     }
                     break;
                 case _FILE_ACCESS_ASSIGNED:
                     if (!in_array(module_security::get_loggedin_id(), $file['staff_ids'])) {
                         $file = false;
                     }
                     break;
                 case _FILE_ACCESS_CUSTOMERS:
                 default:
                     if (class_exists('module_customer', false)) {
                         //added for compat in newsletter system that doesn't have customer module
                         $customer_permission_check = module_customer::get_customer($file['customer_id']);
                         if ($customer_permission_check['customer_id'] != $file['customer_id']) {
                             $file = false;
                         }
                     }
             }
             // file data access switch
         }
     }
     if (!$file) {
         $file = array('new' => true, 'type' => 'upload', 'file_id' => 0, 'customer_id' => isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : 0, 'job_id' => isset($_REQUEST['job_id']) ? $_REQUEST['job_id'] : 0, 'quote_id' => isset($_REQUEST['quote_id']) ? $_REQUEST['quote_id'] : 0, 'description' => '', 'status' => module_config::c('file_default_status', 'Uploaded'), 'file_name' => '', 'file_url' => '', 'staff_ids' => array(), 'bucket' => 0, 'bucket_parent_file_id' => 0, 'approved_time' => 0);
     }
     $this->_get_data_cache = $file;
     return $file;
 }
Exemplo n.º 6
0
 public static function is_automatic_paying_invoice($invoice_id)
 {
     $invoice_payments = module_invoice::get_invoice_payments($invoice_id);
     foreach ($invoice_payments as $payment) {
         if (isset($payment['invoice_payment_subscription_id']) && $payment['invoice_payment_subscription_id']) {
             return true;
         }
     }
     // check if this is part of a subscription, and if the previous subscription
     if (class_exists('module_subscription', false)) {
         // THIS CODE EXISTS
         // check if this invoice is part of a subscription.
         // if it is we hunt through the subscription history until we find a recent unpaid invoice
         $subscription_history_item = get_single('subscription_history', 'invoice_id', $invoice_id);
         if ($subscription_history_item && $subscription_history_item['subscription_owner_id']) {
             // we have an invoice that is on a subscription!
             $subscription_owner = module_subscription::get_subscription_owner($subscription_history_item['subscription_owner_id']);
             // check if there are unpaid invoices that were generated after this invoice.
             if ($subscription_owner['subscription_owner_id'] == $subscription_history_item['subscription_owner_id']) {
                 $subscription_history = get_multiple('subscription_history', array('subscription_owner_id' => $subscription_owner['subscription_owner_id']));
                 foreach ($subscription_history as $h) {
                     $invoice_payments = module_invoice::get_invoice_payments($h['invoice_id']);
                     foreach ($invoice_payments as $payment) {
                         if (isset($payment['invoice_payment_subscription_id']) && $payment['invoice_payment_subscription_id']) {
                             $payment_subscription = get_single('invoice_payment_subscription', 'invoice_payment_subscription_id', $payment['invoice_payment_subscription_id']);
                             if ($payment_subscription && $payment_subscription['status'] == _INVOICE_SUBSCRIPTION_ACTIVE) {
                                 //} || $payment_subscription['status'] == _INVOICE_SUBSCRIPTION_PENDING)){
                                 return true;
                             }
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
Exemplo n.º 7
0
 function get_data_field($data_field_id)
 {
     $data = get_single("data_field", "data_field_id", $data_field_id);
     if ($data) {
         // optional processing here later on.
     }
     return $data;
 }
Exemplo n.º 8
0
 public function external_hook($hook)
 {
     switch ($hook) {
         case 'event_ipn':
             $body = @file_get_contents('php://input');
             $event_json = json_decode($body);
             ob_start();
             echo "UCM coinbase DEBUG:<br><br>JSON: <br>\n";
             print_r($event_json);
             echo "<br><br>\n";
             $success = false;
             $bits = explode(':', isset($event_json->order->custom) ? $event_json->order->custom : '');
             if (count($bits) == 4) {
                 // we have our custom bits, invoice_id, invoice_payment_id and hash
                 // check they are right
                 $invoice_id = (int) $bits[0];
                 $invoice_payment_id = (int) $bits[1];
                 $invoice_payment_subscription_id = (int) $bits[2];
                 $hash = $bits[3];
                 $correct_hash = self::get_payment_key($invoice_id, $invoice_payment_id, $invoice_payment_subscription_id, true);
                 if ($invoice_id && $invoice_payment_id && $hash == $correct_hash) {
                     // This will send receipts on succesful invoices
                     // todo - coinbase doesnt sent this callback correctly just yet
                     if ($event_json && isset($event_json->recurring_payment) && $invoice_payment_subscription_id) {
                         // status changes on a recurring payment.
                         $invoice_payment_subscription = get_single('invoice_payment_subscription', 'invoice_payment_subscription_id', $invoice_payment_subscription_id);
                         if (!$invoice_payment_subscription['date_start'] || $invoice_payment_subscription['date_start'] == '0000-00-00') {
                             // no start date yet, set the start date now.
                             if ($event_json->recurring_payment->status == 'active') {
                                 update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_ACTIVE, 'date_start' => date('Y-m-d')));
                             }
                         }
                         if ($event_json->recurring_payment->status == 'paused' || $event_json->recurring_payment->status == 'canceled') {
                             update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_FAILED));
                         }
                     }
                     if ($event_json && isset($event_json->order->status) && $event_json->order->status == 'completed' && isset($event_json->order->total_native) && isset($event_json->order->custom)) {
                         // crab out the custom bits so we know what to deal with.
                         $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id);
                         $currency = module_config::get_currency($invoice_payment_data['currency_id']);
                         if ($invoice_payment_subscription_id) {
                             // this API result is for a subscription payment.
                             $invoice_payment_subscription = get_single('invoice_payment_subscription', 'invoice_payment_subscription_id', $invoice_payment_subscription_id);
                             if ($invoice_payment_subscription && $invoice_payment_subscription['invoice_payment_subscription_id'] == $invoice_payment_subscription_id && $currency['code'] == $event_json->order->total_native->currency_iso) {
                                 if (!$invoice_payment_subscription['date_start'] || $invoice_payment_subscription['date_start'] == '0000-00-00') {
                                     // no start date yet, set the start date now (this should really happen in the above callback, but coinbase isn't working right now)
                                     update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_ACTIVE, 'date_start' => date('Y-m-d')));
                                 }
                                 // we have a subscription payment. woo!
                                 // this gets a bit tricky, we have to work out if the invoice has been generated for this subscription yet.
                                 // if this invoice hasn't been generated yet then we have to generate it.
                                 // pass this back to the invoice class so we can reuse this feature in the future.
                                 $data = module_invoice::create_new_invoice_for_subscription_payment($invoice_id, $invoice_payment_id, $invoice_payment_subscription_id);
                                 if ($data && $data['invoice_id'] && $data['invoice_payment_id']) {
                                     $next_time = time();
                                     $next_time = strtotime('+' . abs((int) $invoice_payment_subscription['days']) . ' days', $next_time);
                                     $next_time = strtotime('+' . abs((int) $invoice_payment_subscription['months']) . ' months', $next_time);
                                     $next_time = strtotime('+' . abs((int) $invoice_payment_subscription['years']) . ' years', $next_time);
                                     update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('date_last_pay' => date('Y-m-d'), 'date_next' => date('Y-m-d', $next_time)));
                                     update_insert("invoice_payment_id", $data['invoice_payment_id'], "invoice_payment", array('date_paid' => date('Y-m-d'), 'amount' => $event_json->order->total_native->cents / 100, 'method' => self::get_payment_method_name() . ' (Subscription)', 'invoice_payment_subscription_id' => $invoice_payment_subscription_id));
                                     self::add_payment_data($data['invoice_payment_id'], 'log', "Invoice Payment Subscription Received!");
                                     self::add_payment_data($data['invoice_payment_id'], 'log', "API IP is " . $_SERVER['REMOTE_ADDR']);
                                     self::add_payment_data($data['invoice_payment_id'], 'log', "Received BTC: " . $event_json->order->total_btc->cents / 10000000);
                                     self::add_payment_data($data['invoice_payment_id'], 'log', "Received " . $event_json->order->total_native->currency_iso . ': ' . $event_json->order->total_native->cents / 100);
                                     self::add_payment_data($data['invoice_payment_id'], 'log', "Destination Address: " . $event_json->order->receive_address);
                                     self::add_payment_data($data['invoice_payment_id'], 'log', "Currency code matches, marking invoice as paid.");
                                     self::add_payment_data($data['invoice_payment_id'], 'log', "Raw Event Data: \n" . json_encode($event_json));
                                     module_invoice::save_invoice($data['invoice_id'], array());
                                     echo "Successful Subscription Payment!";
                                 } else {
                                     send_error("Coinbase Subscription Error (failed to generate new invoice!) " . var_export($data, true));
                                 }
                             } else {
                                 send_error('Currency code missmatch on coinbase subscription payment');
                             }
                         } else {
                             // this is a normal once off payment.
                             self::add_payment_data($invoice_payment_id, 'log', "API IP is " . $_SERVER['REMOTE_ADDR']);
                             self::add_payment_data($invoice_payment_id, 'log', "Received BTC: " . $event_json->order->total_btc->cents / 10000000);
                             self::add_payment_data($invoice_payment_id, 'log', "Received " . $event_json->order->total_native->currency_iso . ': ' . $event_json->order->total_native->cents / 100);
                             self::add_payment_data($invoice_payment_id, 'log', "Destination Address: " . $event_json->order->receive_address);
                             if ($currency['code'] == $event_json->order->total_native->currency_iso) {
                                 self::add_payment_data($invoice_payment_id, 'log', "Currency code matches, marking invoice as paid.");
                                 update_insert("invoice_payment_id", $invoice_payment_id, "invoice_payment", array('date_paid' => date('Y-m-d'), 'amount' => $event_json->order->total_native->cents / 100));
                                 module_invoice::save_invoice($invoice_id, array());
                                 echo "Successful Payment!";
                                 $success = true;
                             } else {
                                 self::add_payment_data($invoice_payment_id, 'log', "Currency code missmatch, please check settings!");
                             }
                             self::add_payment_data($invoice_payment_id, 'log', "Raw Event Data: \n" . json_encode($event_json));
                         }
                     }
                 }
             }
             $debug = ob_get_clean();
             if (module_config::c('coinbase_payment_debug', 0)) {
                 send_error("Coinbase Debug: {$debug}");
             }
             exit;
             break;
         case 'pay_subscription':
             $invoice_id = isset($_REQUEST['invoice_id']) ? $_REQUEST['invoice_id'] : false;
             $invoice_payment_id = isset($_REQUEST['invoice_payment_id']) ? $_REQUEST['invoice_payment_id'] : false;
             $invoice_payment_subscription_id = isset($_REQUEST['invoice_payment_subscription_id']) ? $_REQUEST['invoice_payment_subscription_id'] : false;
             $coinbase_plan_id = isset($_REQUEST['coinbase_plan_id']) ? $_REQUEST['coinbase_plan_id'] : false;
             $user_id = isset($_REQUEST['user_id']) ? $_REQUEST['user_id'] : false;
             if ($invoice_id && $invoice_payment_id && $coinbase_plan_id && $invoice_payment_subscription_id && $user_id && isset($_POST['coinbaseToken'])) {
                 $user_data = module_user::get_user($user_id);
                 $email = isset($_REQUEST['coinbaseEmail']) && strlen($_REQUEST['coinbaseEmail']) ? $_REQUEST['coinbaseEmail'] : $user_data['email'];
                 if (!$email || !strpos($email, '@')) {
                     die('Please ensure your user account has a valid email address before paying with coinbase');
                 }
                 $invoice_payment = get_single('invoice_payment', 'invoice_payment_id', $invoice_payment_id);
                 $invoice_payment_subscription = get_single('invoice_payment_subscription', 'invoice_payment_subscription_id', $invoice_payment_subscription_id);
                 if (!$invoice_payment || !$invoice_payment_subscription || $invoice_payment['invoice_id'] != $invoice_id || $invoice_payment['invoice_payment_subscription_id'] != $invoice_payment_subscription_id) {
                     die('Invalid invoice payment subscription id');
                 }
                 $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id);
                 $invoice_data = module_invoice::get_invoice($invoice_id);
                 if ($invoice_payment_data && $invoice_data && $invoice_id == $invoice_data['invoice_id'] && $invoice_payment_data['invoice_id'] == $invoice_data['invoice_id']) {
                     $currency = module_config::get_currency($invoice_payment_data['currency_id']);
                     $currency_code = $currency['code'];
                     $description = isset($_REQUEST['description']) ? $_REQUEST['description'] : 'N/A';
                     $template = new module_template();
                     ob_start();
                     require_once 'includes/plugin_paymethod_coinbase/coinbase-php/lib/coinbase.php';
                     $coinbase = array("secret_key" => module_config::c('payment_method_coinbase_api_key'), "publishable_key" => module_config::c('payment_method_coinbase_secret_key'));
                     coinbase::setApiKey($coinbase['secret_key']);
                     try {
                         // todo- search for existing customer based on email address???
                         // todo: check if adding new plan to existing customer work??
                         $coinbase_customer = coinbase_Customer::create(array("card" => $_POST['coinbaseToken'], "email" => $email, 'metadata' => array('user_id' => $user_id)));
                         if ($coinbase_customer && $coinbase_customer->id) {
                             //} && $coinbase_customer->subscriptions){
                             $coinbase_subscription = $coinbase_customer->subscriptions->create(array('plan' => $coinbase_plan_id));
                             if ($coinbase_subscription && $coinbase_subscription->id) {
                                 update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_ACTIVE, 'date_start' => date('Y-m-d'), 'coinbase_customer' => $coinbase_customer->id, 'coinbase_subscription' => $coinbase_subscription->id));
                                 module_paymethod_coinbase::add_payment_data($invoice_payment_id, 'log', "Started coinbase Subscription: " . var_export(array('customer.id' => $coinbase_customer->id, 'plan.id' => $coinbase_plan_id, 'subscription.id' => $coinbase_subscription->id), true));
                                 // success!
                                 // redirect to receipt page.
                                 redirect_browser(module_invoice::link_public_payment_complete($invoice_id));
                             } else {
                                 echo 'Failed to create subscription with coinbase';
                             }
                         }
                         $error = "Something went wrong during coinbase payment. Please confirm invoice payment went through: " . htmlspecialchars($description);
                         send_error($error);
                         echo $error;
                     } catch (coinbase_CardError $e) {
                         // The card has been declined
                         $body = $e->getJsonBody();
                         $err = $body['error'];
                         $error = "Sorry: Payment failed. <br><br>\n\n" . htmlspecialchars($description) . ". <br><br>\n\n";
                         $error .= $err['message'];
                         echo $error;
                         $error .= "\n\n\n" . var_export($err, true);
                         send_error($error);
                     } catch (Exception $e) {
                         $body = $e->getJsonBody();
                         $err = $body['error'];
                         $error = "Sorry: Payment failed. <br><br>\n\n" . htmlspecialchars($description) . ". <br><br>\n\n";
                         $error .= $err['message'];
                         echo $error;
                         $error .= "\n\n\n" . var_export($err, true);
                         send_error($error);
                     }
                     $template->content = ob_get_clean();
                     echo $template->render('pretty_html');
                     exit;
                 }
             }
             echo 'Error paying via coinbase';
             exit;
     }
 }
Exemplo n.º 9
0
    public function external_hook($hook)
    {
        switch ($hook) {
            case 'popup':
                // popup not used any more. cross domain issues.
                // load up the full script to be injected into our clients website.
                $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $change_request_id = $change_id = isset($_REQUEST['change_id']) ? (int) $_REQUEST['change_id'] : false;
                $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false;
                $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : false;
                if ($type == 'popupjs') {
                    @ob_end_clean();
                    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                    header("Cache-Control: no-cache");
                    header("Pragma: no-cache");
                    header("Content-type: text/javascript");
                }
                if ($website_id && $hash && module_change_request::link_popup($website_id, true) == $hash) {
                    $change_history = module_change_request::get_remaining_changes($website_id);
                    $step = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0;
                    // get the change details out
                    if ($change_request_id) {
                        $change_request = module_change_request::get_change_request_by_website($website_id, $change_request_id);
                    } else {
                        $change_request = array();
                    }
                    if (!$change_request) {
                        $change_request = array('change_request_id' => 0, 'name' => '', 'request' => '', 'attachments' => array());
                    }
                    switch ($type) {
                        case 'save':
                            // saving a change.
                            $data = $_POST;
                            $data['url'] = urldecode($data['url']);
                            $data['website_id'] = $website_id;
                            $data['change_request_id'] = $change_request['change_request_id'];
                            if (isset($_REQUEST['completed_test'])) {
                                if (!isset($_REQUEST['completed']) || !$_REQUEST['completed']) {
                                    $data['status'] = _CHANGE_REQUEST_STATUS_NEW;
                                    // not completed.
                                } else {
                                    $data['status'] = _CHANGE_REQUEST_STATUS_COMPLETE;
                                    // completed!
                                }
                            }
                            if (isset($_REQUEST['delete_request'])) {
                                $data['status'] = _CHANGE_REQUEST_STATUS_DELETE;
                                // deleted
                            }
                            $change_request_id = update_insert('change_request_id', $change_request['change_request_id'], 'change_request', $data);
                            // redirect to send email page if we're logged in
                            if (module_security::is_logged_in() && isset($_REQUEST['completed_send_email']) && $_REQUEST['completed_send_email'] && self::can_i('edit', 'Change Requests')) {
                                // don't do the template, do the redirect to the email page (todo!)
                                redirect_browser(self::link_open($change_request_id));
                            } else {
                                // send email to administrator (everyone with change request edit permissions?) about this change request.
                                $alert_users = module_user::get_users_by_permission(array('category' => 'Change Request', 'name' => 'Change Requests', 'module' => 'change_request', 'edit' => 1));
                                $email_data = get_single('change_request', 'change_request_id', $change_request_id);
                                $customer_data = $website_data = array();
                                if ($website_id) {
                                    $website_data = module_website::get_website($website_id);
                                    $email_data['website_name'] = $website_data['name'];
                                    $email_data['website_link'] = module_website::link_open($website_id, true);
                                    if ($website_data && $website_data['customer_id']) {
                                        $customer_data = module_customer::get_customer($website_data['customer_id'], true);
                                    }
                                }
                                if (isset($email_data['request'])) {
                                    $email_data['request'] = nl2br($email_data['request']);
                                    // for the plain text emails.
                                }
                                foreach ($alert_users as $alert_user) {
                                    // todo: make sure this staff member has access to this website?
                                    // nfi how to figure this out. maybe we just look for staff members who are assigned jobs/tasks against this website?
                                    $template = module_template::get_template_by_key('change_request_alert_email');
                                    $template->assign_values(array_merge($customer_data, $website_data, $email_data));
                                    $html = $template->render('html');
                                    // send an email to this user.
                                    $email = module_email::new_email();
                                    $email->replace_values = array_merge($customer_data, $website_data, $email_data);
                                    $email->set_to('user', $alert_user['user_id']);
                                    $email->set_from('user', module_security::get_loggedin_id() ? module_security::get_loggedin_id() : isset($customer_data['primary_user_id']) ? $customer_data['primary_user_id'] : 0);
                                    $email->set_subject($template->description);
                                    // do we send images inline?
                                    $email->set_html($html);
                                    if ($email->send()) {
                                        // it worked successfully!!
                                        // sweet.
                                    } else {
                                        /// log err?
                                        set_error(_l('Failed to send change notification email to User ID: %s Email: %s Status: %s Error: %s', $alert_user['user_id'], json_encode($email->to), $email->status, $email->error_text));
                                    }
                                }
                            }
                            // display thankyou template.
                            module_template::init_template('change_request_submitted', '<h2>Change Request</h2>
    <p>Thank you. Your change request has been submitted successfully.</p>
    <p>Please <a href="{URL}">click here</a> to continue.</p>
    ', 'Displayed after a change request is created/updated.', 'code');
                            // correct!
                            // load up the receipt template.
                            $template = module_template::get_template_by_key('change_request_submitted');
                            $template->page_title = _l("Change Request");
                            foreach ($data as $key => $val) {
                                if (!is_array($val)) {
                                    $data[$key] = htmlspecialchars($val);
                                }
                            }
                            $template->assign_values($data);
                            echo $template->render('pretty_html');
                            exit;
                            break;
                        case 'display_change':
                            ob_start();
                            ?>

                            <div class="title">
                                <?php 
                            _e('Change request');
                            ?>

                            </div>
                            <div class="content">
                                <p><?php 
                            echo nl2br(htmlspecialchars($change_request['request']));
                            ?>
</p>
                                <div class="wp3changerequest_actions">
                                    <p>
                                       <!-- <strong><?php 
                            _e('Attachments:');
                            ?>
</strong>
                                        <?php 
                            if (!$change_request['attachments']) {
                                ?>
 - none - <?php 
                            } else {
                                foreach ($change_request['attachments'] as $attachment) {
                                    ?>

                                            <a href="#"><?php 
                                    echo htmlspecialchars($attachment->name);
                                    ?>
</a>
                                            <?php 
                                }
                                ?>

                                        <?php 
                            }
                            ?>

                                        <br/>-->
                                        <strong><?php 
                            _e('Created by:');
                            ?>
</strong> <?php 
                            echo htmlspecialchars($change_request['name']);
                            ?>
 <br/>
                                        <strong><?php 
                            _e('Created on:');
                            ?>
</strong> <?php 
                            echo print_date($change_request['date_created'], true);
                            ?>

	                                    <?php 
                            if (isset($change_request['job_id']) && $change_request['job_id']) {
                                ?>
 <br/>
		                                    <strong><?php 
                                _e('Converted to job:');
                                ?>
</strong> <?php 
                                _e('This task has been converted to a Job');
                                ?>

	                                    <?php 
                            }
                            ?>

                                    </p>
                                    <?php 
                            if (!isset($change_request['job_id']) || !$change_request['job_id'] || self::can_i('edit', 'Change Requests')) {
                                ?>

                                    <p align="center">
                                        <input type="button" name="edit" value="<?php 
                                _e('Edit');
                                ?>
" class="wp3changerequest_button wp3changerequest_button_small"  onclick="dtbaker_changerequest.edit(<?php 
                                echo $change_request_id;
                                ?>
); return false;">
                                    </p>
	                                <?php 
                            }
                            ?>

                                </div>
                            </div>
                            <?php 
                            $change_request['html'] = preg_replace('/\\s+/', ' ', ob_get_clean());
                            //                                echo json_encode($change_request);
                            //                                exit;
                            @ob_end_clean();
                            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                            header("Cache-Control: no-cache");
                            header("Pragma: no-cache");
                            header("Content-type: text/javascript");
                            ?>


                            var t = dtbaker_changerequest;
                            var change_id = <?php 
                            echo $change_request_id;
                            ?>
;
                                var msg = <?php 
                            echo json_encode($change_request);
                            ?>
;

                            jQuery('body').prepend('<div class="wp3changerequest_change" id="dtbaker_change_'+change_id+'" style="'+((!t.show_postits) ? 'display:none;':'')+'"></div>');
                            var box = jQuery('#dtbaker_change_'+change_id);
                            box.html(msg.html);
                            if(msg.status == 0){
                                box.addClass('wp3changerequest_change_pending');
                            }else if(msg.status == 2){
                                box.addClass('wp3changerequest_change_complete');
                            }else if(msg.status == 3){
                                box.addClass('wp3changerequest_change_deleted');
                            }
                            box.css('top',msg.y+'px');
                            box.data('window_width',msg.window_width);
                            box.data('left',msg.x);
                            t.set_left(change_id);
                            with({i:change_id}){
                                jQuery(window).resize(function () {
                                    t.set_left(i);
                                });
                            }
                            box.data('original_height',box.height());
                            box.css('overflow','hidden');
                            jQuery('.title',box).slideUp();
                            box.stop(true, true).animate({
                                height: t.min_height,
                                width: t.min_width
                            },500);
                            box.hover(function(){
                                jQuery(this).addClass('wp3changerequest_change_active');
                                jQuery('.title',this).stop(true, true).slideDown();
                                jQuery(this).stop().animate({
                                    width: t.max_width,
                                    height: jQuery(this).data('original_height'),
                                    opacity: 1
                                },500);
                            },function(){
                                jQuery('.title',this).stop(true, true).slideUp();
                                jQuery(this).stop().animate({
                                    width: t.min_width,
                                    height: t.min_height,
                                    opacity: 0.7
                                },500,function(){
                                    jQuery(this).removeClass('wp3changerequest_change_active');
                                });
                            })


                                <?php 
                            break;
                        default:
                            @ob_end_clean();
                            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                            header("Cache-Control: no-cache");
                            header("Pragma: no-cache");
                            header("Content-type: text/javascript");
                            ob_start();
                            include 'pages/popup.php';
                            $html = ob_get_clean();
                            $html = addcslashes($html, "'");
                            $html = preg_replace('#\\r|\\n#', "' +\n'", $html);
                            // inject using javascript. fixes cross domain issues
                            ?>

                            if(!jQuery('#dtbaker_changerequest_inlinewizard').length){
                                // fix for jQuery 1.9+
                                jQuery('body').append('<div id="dtbaker_changerequest_inlinewizard" style="display:none;"></div>');
                            }
                            jQuery('#dtbaker_changerequest_inlinewizard').html('<?php 
                            echo $html;
                            ?>
');
                            <?php 
                    }
                }
                exit;
                break;
            case 'script':
                // load up the full script to be injected into our clients website.
                $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false;
                @ob_end_clean();
                header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
                header("Cache-Control: no-cache");
                header("Pragma: no-cache");
                header("Content-type: text/javascript");
                if ($website_id && $hash && module_change_request::link_script($website_id, true) == $hash) {
                    include "js/client.js";
                    $client_url = isset($_REQUEST['url']) ? $_REQUEST['url'] : false;
                    if ($client_url) {
                        $change_requests = self::get_change_requests(array('website_id' => $website_id, 'url' => $client_url));
                        // todo - option this out incase url causes issues. ie: old js check method
                        ?>

                        jQuery(function(){
                            <?php 
                        foreach ($change_requests as $change_request) {
                            $displayed = false;
                            if ($change_request['status'] == _CHANGE_REQUEST_STATUS_NEW) {
                                $displayed = true;
                                ?>

                                    dtbaker_changerequest.display_change(<?php 
                                echo $change_request['change_request_id'];
                                ?>
);
                            <?php 
                            }
                            if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight'] == $change_request['change_request_id']) {
                                ?>

                                    <?php 
                                if (!$displayed) {
                                    ?>

                                    dtbaker_changerequest.display_change(<?php 
                                    echo $change_request['change_request_id'];
                                    ?>
);
                                    <?php 
                                }
                                ?>

                                    dtbaker_changerequest.highlight(<?php 
                                echo (int) $_SESSION['_change_request_highlight'];
                                ?>
);
                                    <?php 
                                unset($_SESSION['_change_request_highlight']);
                            }
                        }
                        ?>

                        });
                        <?php 
                    } else {
                        // not posting the URL, some setups do not like this
                        // get list of active change requests
                        $change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_NEW));
                        // we also do completed ones because the change request highlight countbe in there
                        $completed_change_requests = self::get_change_requests(array('website_id' => $website_id, 'status' => _CHANGE_REQUEST_STATUS_COMPLETE));
                        ?>


                        jQuery(function(){
                            var current_url = window.location.href;
                            <?php 
                        foreach ($change_requests as $change_request) {
                            ?>

                            if(current_url == '<?php 
                            echo addcslashes(htmlspecialchars($change_request['url']), "'");
                            ?>
'){
                                // todo: do this better!
                                dtbaker_changerequest.display_change(<?php 
                            echo $change_request['change_request_id'];
                            ?>
);
                            }
                            <?php 
                        }
                        ?>

                            <?php 
                        // todo: do we display all previous change requests on the page or not?
                        if (isset($_SESSION['_change_request_highlight']) && $_SESSION['_change_request_highlight']) {
                            echo '// Checking for request: ' . (int) $_SESSION['_change_request_highlight'];
                            foreach ($completed_change_requests as $complete_change_request) {
                                if ($complete_change_request['change_request_id'] == $_SESSION['_change_request_highlight']) {
                                    // show this completed one as well.
                                    ?>

                                        dtbaker_changerequest.display_change(<?php 
                                    echo $complete_change_request['change_request_id'];
                                    ?>
);
                                        <?php 
                                }
                            }
                            ?>

                            dtbaker_changerequest.highlight(<?php 
                            echo (int) $_SESSION['_change_request_highlight'];
                            ?>
);
                            <?php 
                            // todo: move this unset over to the "display_change" callback so we only remove the session when we know it has been displayed.
                            unset($_SESSION['_change_request_highlight']);
                        }
                        ?>

                        });
                        <?php 
                    }
                }
                exit;
                break;
            case 'public':
                $website_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
                $hash = isset($_REQUEST['hash']) ? $_REQUEST['hash'] : false;
                if ($website_id && $hash && module_change_request::link_public($website_id, true) == $hash) {
                    // correct!
                    // redirect to website with our "change_request" url parameter, that is picked up by the included text.
                    $website = module_website::get_website($website_id);
                    $change_request_website = get_single('change_request_website', 'website_id', $website_id);
                    if ($change_request_website && $change_request_website['enabled']) {
                        $url = module_website::urlify($website['url']);
                        // todo - pass this to a (yet to be created) method in website that will deal with https:// or http:// based on user input. stop hardcoding http!
                        if (isset($_REQUEST['change_request_id'])) {
                            $selected_change_request = self::get_change_request_by_website($website_id, (int) $_REQUEST['change_request_id']);
                            if ($selected_change_request && $selected_change_request['url']) {
                                $url = $selected_change_request['url'];
                            }
                            //$url .= "&change_request_id=".(int)$_REQUEST['change_request_id'];
                            $_SESSION['_change_request_highlight'] = (int) $_REQUEST['change_request_id'];
                        }
                        $url = $url . (strpos($url, '?') === false ? '?' : '&') . 'change_request=' . self::link_script($website_id, true);
                        redirect_browser($url);
                    }
                }
                echo "Change request disabled.";
                break;
        }
    }
Exemplo n.º 10
0
 function handle_paypal_ipn()
 {
     ob_end_clean();
     if (!isset($_REQUEST['custom'])) {
         return;
     }
     $paypal_bits = explode("|", $_REQUEST['custom']);
     $user_id = (int) $paypal_bits[0];
     $payment_id = (int) $paypal_bits[1];
     $invoice_id = (int) $paypal_bits[2];
     $invoice_payment_subscription_id = false;
     if (count($paypal_bits) == 4) {
         // normal IPN, single payment.
     } else {
         if (count($paypal_bits) == 5) {
             // subscription IPN, with subscription id.
             $invoice_payment_subscription_id = (int) $paypal_bits[3];
             $invoice_payment_subscription = get_single('invoice_payment_subscription', 'invoice_payment_subscription_id', $invoice_payment_subscription_id);
         }
     }
     //send_error('bad?');
     if ($payment_id && $invoice_id) {
         $hash = $this->paypal_custom($user_id, $payment_id, $invoice_id, $invoice_payment_subscription_id);
         if ($hash != $_REQUEST['custom']) {
             send_error("PayPal IPN Error (incorrect hash) it should be " . $hash);
             exit;
         }
         /*$sql = "SELECT * FROM `"._DB_PREFIX."user` WHERE user_id = '$user_id' LIMIT 1";
                     $res = qa($sql);
                     if($res){
         
                         $user = array_shift($res);
                         if($user && $user['user_id'] == $user_id){*/
         // check for payment exists
         $payment = module_invoice::get_invoice_payment($payment_id);
         $invoice = module_invoice::get_invoice($invoice_id);
         if ($payment && $invoice) {
             /*if(isset($_REQUEST['fakepay'])){
                                         if($invoice_payment_subscription_id){
                                             // we have a subscription payment. woo!
                                             // this gets a bit tricky, we have to work out if the invoice has been generated for this subscription yet.
                                             // if this invoice hasn't been generated yet then we have to generate it.
                                             // pass this back to the invoice class so we can reuse this feature in the future.
                                             $data = module_invoice::create_new_invoice_for_subscription_payment($invoice_id, $payment_id, $invoice_payment_subscription_id);
                                             if($data && $data['invoice_id'] && $data['invoice_payment_id']){
             
                                                 $next_time = time();
                                                 $next_time = strtotime('+'.abs((int)$invoice_payment_subscription['days']).' days',$next_time);
                                                 $next_time = strtotime('+'.abs((int)$invoice_payment_subscription['months']).' months',$next_time);
                                                 $next_time = strtotime('+'.abs((int)$invoice_payment_subscription['years']).' years',$next_time);
                                                 update_insert('invoice_payment_subscription_id',$invoice_payment_subscription_id,'invoice_payment_subscription',array(
                                                     'date_last_pay' => date('Y-m-d'),
                                                     'date_next' => date('Y-m-d',$next_time),
                                                 ));
                                                 $new_payment_details = array(
                                                       'date_paid' => date('Y-m-d'),
                                                       'amount' => $_REQUEST['mc_gross'],
                                                       'method' => 'PayPal (Subscription)',
                                                       'invoice_payment_subscription_id' => $invoice_payment_subscription_id,
                                                  );
                                                 foreach(array('fee_percent','fee_amount','fee_description','fee_total') as $fee_field){
                                                     if(isset($payment[$fee_field])) {
                                                         $new_payment_details[ $fee_field ] = $payment[ $fee_field ];
                                                     }
                                                 }
                                                  update_insert("invoice_payment_id",$data['invoice_payment_id'],"invoice_payment",$new_payment_details);
             
                                                 module_invoice::save_invoice($data['invoice_id'],array());
             
                                                 echo "Successful Subscription Payment!";
             
                                             }else{
                                                 send_error("PayPal IPN Subscription Error (failed to generate new invoice!) ".var_export($result,true));
                                             }
             
                                         }else{
                                             // mark a normal payment as paid
             
                                             update_insert("invoice_payment_id",$payment_id,"invoice_payment",array(
                                                       'date_paid' => date('Y-m-d'),
                                                       'amount' => $_REQUEST['mc_gross'],
                                                       'method' => 'PayPal (IPN)',
                                              ));
             
                                             module_invoice::save_invoice($invoice_id,array());
             
                                             echo "Successful Payment!";
             
                                         }
                                         echo 'fakepay done';exit;
                                     }*/
             $invoice_currency = module_config::get_currency($invoice['currency_id']);
             $invoice_currency_code = $invoice_currency['code'];
             // check correct business
             if (!$_REQUEST['business'] && $_REQUEST['receiver_email']) {
                 $_REQUEST['business'] = $_REQUEST['receiver_email'];
             }
             if ($_REQUEST['business'] != module_config::c('payment_method_paypal_email', _ERROR_EMAIL)) {
                 send_error('PayPal error! Paid the wrong business name. ' . $_REQUEST['business'] . ' instead of ' . module_config::c('payment_method_paypal_email', _ERROR_EMAIL));
                 exit;
             }
             // check correct currency
             if ($invoice_currency_code && $_REQUEST['mc_currency'] != $invoice_currency_code) {
                 send_error('PayPal error! Paid the wrong currency code. ' . $_REQUEST['mc_currency'] . ' instead of ' . $invoice_currency_code);
                 exit;
             }
             switch ($_REQUEST['txn_type']) {
                 // handle subscriptions first.
                 // https://www.paypal.com/au/cgi-bin/webscr?cmd=p/acc/ipn-subscriptions-outside
                 case "subscr_signup":
                     // started! we update the start date of this one.
                     if ($invoice_payment_subscription_id) {
                         update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_ACTIVE, 'date_start' => date('Y-m-d')));
                     }
                     break;
                 case "subscr_cancel":
                 case "subscr_failed":
                 case "subscr_eot":
                     if ($invoice_payment_subscription_id) {
                         update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_FAILED));
                     }
                     break;
                     break;
                 case "subscr_payment":
                 case "web_accept":
                     if ($_REQUEST['payment_status'] == "Canceled_Reversal" || $_REQUEST['payment_status'] == "Refunded") {
                         // funky refund!! oh noes!!
                         // TODO: store this in the database as a negative payment... should be easy.
                         // populate $_REQUEST vars then do something like $payment_history_id = update_insert("payment_history_id","new","payment_history");
                         send_error("PayPal Error! The payment {$payment_id} has been refunded or reversed! BAD BAD! You have to follup up customer for money manually now.");
                     } else {
                         if ($_REQUEST['payment_status'] == "Completed") {
                             // payment is completed! yeye getting closer...
                             // running in paypal sandbox or not?
                             //$sandbox = (self::is_sandbox())?"sandbox.":'';
                             // quick check we're not getting a fake payment request.
                             $url = 'https://www.' . (self::is_sandbox() ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr';
                             $result = self::fsockPost($url, $_POST);
                             //send_error('paypal sock post: '.$url."\n\n".var_export($result,true));
                             if (eregi("VERIFIED", $result)) {
                                 // finally have everything.
                                 // mark the payment as completed.
                                 if ($invoice_payment_subscription_id) {
                                     // we have a subscription payment. woo!
                                     // this gets a bit tricky, we have to work out if the invoice has been generated for this subscription yet.
                                     // if this invoice hasn't been generated yet then we have to generate it.
                                     // pass this back to the invoice class so we can reuse this feature in the future.
                                     $data = module_invoice::create_new_invoice_for_subscription_payment($invoice_id, $payment_id, $invoice_payment_subscription_id);
                                     if ($data && $data['invoice_id'] && $data['invoice_payment_id']) {
                                         $next_time = time();
                                         $next_time = strtotime('+' . abs((int) $invoice_payment_subscription['days']) . ' days', $next_time);
                                         $next_time = strtotime('+' . abs((int) $invoice_payment_subscription['months']) . ' months', $next_time);
                                         $next_time = strtotime('+' . abs((int) $invoice_payment_subscription['years']) . ' years', $next_time);
                                         update_insert('invoice_payment_subscription_id', $invoice_payment_subscription_id, 'invoice_payment_subscription', array('date_last_pay' => date('Y-m-d'), 'date_next' => date('Y-m-d', $next_time)));
                                         $new_payment_details = array('date_paid' => date('Y-m-d'), 'amount' => $_REQUEST['mc_gross'], 'method' => 'PayPal (Subscription)', 'invoice_payment_subscription_id' => $invoice_payment_subscription_id);
                                         foreach (array('fee_percent', 'fee_amount', 'fee_description', 'fee_total') as $fee_field) {
                                             if (isset($payment[$fee_field])) {
                                                 $new_payment_details[$fee_field] = $payment[$fee_field];
                                             }
                                         }
                                         update_insert("invoice_payment_id", $data['invoice_payment_id'], "invoice_payment", $new_payment_details);
                                         module_invoice::save_invoice($data['invoice_id'], array());
                                         echo "Successful Subscription Payment!";
                                     } else {
                                         send_error("PayPal IPN Subscription Error (failed to generate new invoice!) " . var_export($result, true));
                                     }
                                 } else {
                                     // mark a normal payment as paid
                                     update_insert("invoice_payment_id", $payment_id, "invoice_payment", array('date_paid' => date('Y-m-d'), 'amount' => $_REQUEST['mc_gross'], 'method' => 'PayPal (IPN)'));
                                     module_invoice::save_invoice($invoice_id, array());
                                     echo "Successful Payment!";
                                 }
                                 /*// send customer an email thanking them for their payment.
                                                                         $sql = "SELECT * FROM "._DB_PREFIX."users WHERE user_id = '"._ADMIN_USER_ID."'";
                                                                         $res = qa($sql);
                                                                         $admin = array_shift($res);
                                                                         $from_email = $admin['email'];
                                                                         $from_name = $admin['real_name'];
                                                                         $mail_content = "Dear ".$user['real_name'].", \n\n";
                                                                         $mail_content .= "Your ".dollar($payment['outstanding'])." payment for '".$payment['description']."' has been processed. \n\n";
                                                                         $mail_content .= "We have successfully recorded your ".dollar($_REQUEST['mc_gross'])." payment in our system.\n\n";
                                                                         $mail_content .= "You will receive another email shortly from PayPal with details of the transaction.\n\n";
                                                                         $mail_content .= "Kind Regards,\n\n";
                                                                         $mail_content .= $from_name."\n".$from_email;
                                 
                                                                         send_error("PayPal SUCCESS!! User has paid you ".$_REQUEST['mc_gross']." we have recorded this against the payment and sent them an email");
                                                                         //$this->send_email( $payment_id, $user['email'], $mail_content, "Payment Successful", $from_email, $from_name );
                                                                         send_email($user['email'], "Payment Successful", $mail_content, array("FROM"=>$from_email,"FROM_NAME"=>$from_name));
                                                                         */
                                 // check if it's been paid in full..
                             } else {
                                 send_error("PayPal IPN Error (paypal rejected the payment!) " . var_export($result, true));
                             }
                         } else {
                             send_error("PayPal info: This payment is not yet completed, this usually means it's an e-cheque, follow it up in a few days if you dont hear anything. This also means you may have to login to paypal and 'Accept' the payment. So check there first.");
                         }
                     }
                     break;
                 default:
                     send_error("PayPal IPN Error (unknown transaction t ype!) ");
                     break;
             }
         } else {
             send_error("PayPal IPN Error (no payment found in database!)");
         }
         /*}else{
                   send_error("PayPal IPN Error (error with user that was found in database..)");
               }
           }else{
               send_error("PayPal IPN Error (no user found in database #1)");
           }*/
     } else {
         send_error("PayPal IPN Error (no payment or invoice id found)");
     }
     exit;
 }
Exemplo n.º 11
0
 public function load($social_twitter_message_id = false)
 {
     if (!$social_twitter_message_id) {
         $social_twitter_message_id = $this->social_twitter_message_id;
     }
     $this->reset();
     $this->social_twitter_message_id = $social_twitter_message_id;
     if ($this->social_twitter_message_id) {
         $this->details = get_single('social_twitter_message', 'social_twitter_message_id', $this->social_twitter_message_id);
         if (!is_array($this->details) || !isset($this->details['social_twitter_message_id']) || $this->details['social_twitter_message_id'] != $this->social_twitter_message_id) {
             $this->reset();
             return false;
         }
     }
     foreach ($this->details as $key => $val) {
         $this->{$key} = $val;
     }
     if (!$this->twitter_account && $this->get('social_twitter_id')) {
         $this->twitter_account = new ucm_twitter_account($this->get('social_twitter_id'));
     }
     return $this->social_twitter_message_id;
 }
Exemplo n.º 12
0
 public static function get_languages_attributes()
 {
     $all = array();
     $language_files = glob(_UCM_FOLDER . 'includes/plugin_language/custom/*.php');
     if (is_array($language_files)) {
         foreach ($language_files as $language) {
             $language = strtolower(str_replace('.php', '', basename($language)));
             if ($language[0] == '_') {
                 continue;
             }
             $all[$language] = array('language_name' => $language, 'language_code' => $language);
         }
     }
     $language_files = glob(_UCM_FOLDER . 'includes/plugin_language/labels/*.php');
     if (is_array($language_files)) {
         foreach ($language_files as $language) {
             $language = strtolower(str_replace('.php', '', basename($language)));
             if ($language[0] == '_') {
                 continue;
             }
             $all[$language] = array('language_name' => $language, 'language_code' => $language);
         }
     }
     if (self::is_language_db_enabled()) {
         foreach ($all as $language_code => $language) {
             // does this language code exist in the database?
             $language_db = get_single('language', 'language_code', $language_code);
             if (!$language_db || $language_db['language_code'] != $language_code) {
                 update_insert('language_id', false, 'language', array('language_code' => $language['language_code'], 'language_name' => $language['language_name']));
             }
         }
         // now we get any language attributes from the database and overwrite the old file based ones with those.
         foreach (get_multiple('language', false, 'language_id', 'exact', 'language_code') as $language) {
             if (isset($all[strtolower($language['language_code'])])) {
                 // this language exists in the old file based method.
                 $all[strtolower($language['language_code'])] = $language;
             } else {
                 // this is a language that only exists in the new database translation method.
                 $all[strtolower($language['language_code'])] = $language;
             }
             // todo - well, not sure about the above. maybe we do some update here and remove the old files ??? move everything to the database or something?? meh..
         }
     }
     return $all;
 }
Exemplo n.º 13
0
 public static function add_to_group($group_id, $owner_id, $owner_table = false)
 {
     if ($group_id > 0 && $owner_id > 0) {
         if (!$owner_table) {
             $group = get_single('group', 'group_id', $group_id);
             $owner_table = $group['owner_table'];
         }
         $sql = "REPLACE INTO `" . _DB_PREFIX . "group_member` SET ";
         $sql .= " `group_id` = '" . (int) $group_id . "', ";
         $sql .= " `owner_id` = '" . (int) $owner_id . "', ";
         $sql .= " `owner_table` = '" . mysql_real_escape_string($owner_table) . "'";
         query($sql);
     }
 }
Exemplo n.º 14
0
 public static function get_faq($faq_id)
 {
     $faq = get_single('faq', 'faq_id', $faq_id);
     // get linked ids
     $faq['faq_product_ids'] = array();
     foreach (get_multiple('faq_product_rel', array('faq_id' => $faq_id)) as $product) {
         $faq['faq_product_ids'][$product['faq_product_id']] = $product['faq_product_id'];
     }
     return $faq;
 }
Exemplo n.º 15
0
            function customer_admin_email_generate_invoice_list($invoices, $customer_id)
            {
                ob_start();
                $colspan = 9;
                $colspan2 = 0;
                $invoice_total = array();
                $invoice_total_due = array();
                foreach ($invoices as $invoice) {
                    if (!isset($invoice_total[$invoice['currency_id']])) {
                        $invoice_total[$invoice['currency_id']] = 0;
                    }
                    if ($invoice['c_total_amount'] == 0) {
                        $invoice = module_invoice::get_invoice($invoice['invoice_id']);
                    }
                    $invoice_total[$invoice['currency_id']] += $invoice['c_total_amount'];
                    if (!isset($invoice_total_due[$invoice['currency_id']])) {
                        $invoice_total_due[$invoice['currency_id']] = 0;
                    }
                    $invoice_total_due[$invoice['currency_id']] += $invoice['c_total_amount_due'];
                }
                $table_manager = module_theme::new_table_manager();
                $columns = array();
                $columns['invoice_number'] = array('title' => 'Invoice Number', 'callback' => function ($invoice) {
                    //echo module_invoice::link_open($invoice['invoice_id'],true,$invoice);
                    echo '<a href="' . module_invoice::link_public($invoice['invoice_id']) . '">' . htmlspecialchars($invoice['name']) . '</a>';
                }, 'cell_class' => 'row_action');
                $columns['invoice_status'] = array('title' => 'Status', 'callback' => function ($invoice) {
                    echo htmlspecialchars($invoice['status']);
                });
                $columns['invoice_create_date'] = array('title' => 'Create Date', 'callback' => function ($invoice) {
                    if (!$invoice['date_create'] || $invoice['date_create'] == '0000-00-00') {
                        //echo print_date($invoice['date_created']);
                    } else {
                        echo print_date($invoice['date_create']);
                    }
                });
                $columns['invoice_due_date'] = array('title' => 'Due Date', 'callback' => function ($invoice) {
                    if ((!$invoice['date_paid'] || $invoice['date_paid'] == '0000-00-00') && strtotime($invoice['date_due']) < time()) {
                        echo '<span class="error_text">';
                        echo print_date($invoice['date_due']);
                        echo '</span>';
                    } else {
                        echo print_date($invoice['date_due']);
                    }
                });
                $columns['invoice_sent_date'] = array('title' => 'Sent Date', 'callback' => function ($invoice) {
                    if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') {
                        ?>

				            <?php 
                        echo print_date($invoice['date_sent']);
                        ?>

				        <?php 
                    } else {
                        ?>

				            <span class="error_text"><?php 
                        _e('Not sent');
                        ?>
</span>
				        <?php 
                    }
                });
                $columns['invoice_paid_date'] = array('title' => 'Paid Date', 'callback' => function ($invoice) {
                    if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') {
                        ?>

				            <?php 
                        echo print_date($invoice['date_paid']);
                        ?>

				        <?php 
                    } else {
                        if ($invoice['date_cancel'] && $invoice['date_cancel'] != '0000-00-00') {
                            ?>

				            <span class="error_text"><?php 
                            _e('Cancelled');
                            ?>
</span>
				        <?php 
                        } else {
                            if ($invoice['overdue']) {
                                ?>

				            <span class="error_text" style="font-weight: bold; text-decoration: underline;"><?php 
                                _e('Overdue');
                                ?>
</span>
				        <?php 
                            } else {
                                ?>

				            <span class="error_text"><?php 
                                _e('Not paid');
                                ?>
</span>
				        <?php 
                            }
                        }
                    }
                });
                if (class_exists('module_website', false) && module_website::is_plugin_enabled() && module_website::can_i('view', module_config::c('project_name_plural', 'Websites'))) {
                    $colspan++;
                    $columns['invoice_website'] = array('title' => module_config::c('project_name_single', 'Website'), 'callback' => function ($invoice) {
                        if (isset($invoice['website_ids'])) {
                            foreach ($invoice['website_ids'] as $website_id) {
                                if ((int) $website_id > 0) {
                                    echo module_website::link_open($website_id, true);
                                    echo '<br/>';
                                }
                            }
                        }
                    });
                }
                $columns['invoice_job'] = array('title' => 'Job', 'callback' => function ($invoice) {
                    foreach ($invoice['job_ids'] as $job_id) {
                        if ((int) $job_id > 0) {
                            //echo module_job::link_open($job_id,true);
                            $job_data = module_job::get_job($job_id);
                            echo '<a href="' . module_job::link_public($job_id) . '">' . htmlspecialchars($job_data['name']) . '</a>';
                            if ($job_data['date_start'] && $job_data['date_start'] != '0000-00-00' && $job_data['date_renew'] && $job_data['date_renew'] != '0000-00-00') {
                                _e(' (%s to %s)', print_date($job_data['date_start']), print_date(strtotime("-1 day", strtotime($job_data['date_renew']))));
                            }
                            echo "<br/>\n";
                        }
                    }
                    hook_handle_callback('invoice_admin_list_job', $invoice['invoice_id']);
                });
                if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) {
                    $colspan++;
                    $columns['invoice_customer'] = array('title' => 'Customer', 'callback' => function ($invoice) {
                        echo module_customer::link_open($invoice['customer_id'], true);
                    });
                }
                $columns['c_invoice_total'] = array('title' => 'Invoice Total', 'callback' => function ($invoice) {
                    echo dollar($invoice['total_amount'], true, $invoice['currency_id']);
                });
                $columns['c_invoice_total_due'] = array('title' => 'Amount Due', 'callback' => function ($invoice) {
                    echo dollar($invoice['total_amount_due'], true, $invoice['currency_id']);
                    ?>

				        <?php 
                    if ($invoice['total_amount_credit'] > 0) {
                        ?>

				        <span class="success_text"><?php 
                        echo _l('Credit: %s', dollar($invoice['total_amount_credit'], true, $invoice['currency_id']));
                        ?>
</span>
				            <?php 
                    }
                });
                if (class_exists('module_extra', false)) {
                    ob_start();
                    $colspan2 += module_extra::print_table_header('invoice');
                    // used in the footer calc.
                    ob_end_clean();
                    $table_manager->display_extra('invoice', function ($invoice) {
                        module_extra::print_table_data('invoice', $invoice['invoice_id']);
                    });
                }
                $table_manager->set_columns($columns);
                $table_manager->row_callback = function ($row_data) {
                    // load the full vendor data before displaying each row so we have access to more details
                    if (isset($row_data['invoice_id']) && (int) $row_data['invoice_id'] > 0) {
                        return module_invoice::get_invoice($row_data['invoice_id']);
                    }
                    return array();
                };
                $table_manager->set_rows($invoices);
                if (module_config::c('invoice_list_show_totals', 1)) {
                    $footer_rows = array();
                    foreach ($invoice_total + $invoice_total_due as $currency_id => $foo) {
                        $currency = get_single('currency', 'currency_id', $currency_id);
                        $footer_rows[] = array('invoice_number' => array('data' => '<strong>' . _l('%s Totals:', $currency && isset($currency['code']) ? $currency['code'] : '') . '</strong>', 'cell_colspan' => $colspan - 2, 'cell_class' => 'text-right'), 'c_invoice_total' => array('data' => '<strong>' . dollar(isset($invoice_total[$currency_id]) ? $invoice_total[$currency_id] : 0, true, $currency_id) . '</strong>'), 'c_invoice_total_due' => array('data' => '<strong>' . dollar(isset($invoice_total_due[$currency_id]) ? $invoice_total_due[$currency_id] : 0, true, $currency_id) . '</strong>'), 'row_bulk_action' => array('data' => ' ', 'cell_colspan' => $colspan2));
                    }
                    $table_manager->set_footer_rows($footer_rows);
                }
                $table_manager->pagination = false;
                $table_manager->print_table();
                return ob_get_clean();
            }
Exemplo n.º 16
0
 public static function get_address_by_id($address_id)
 {
     return get_single("address", 'address_id', $address_id);
 }
Exemplo n.º 17
0
 public static function get_template($template_id)
 {
     if (self::db_table_exists('template')) {
         $data = get_single("template", "template_id", $template_id);
         if ($data && $data['template_id'] && $data['template_id'] == $template_id) {
             // hook in here to load any custom company templates.
             if (class_exists('module_company', false) && is_callable('module_company::template_get_company')) {
                 $custom_data = module_company::template_get_company($data['template_id'], $data);
                 if ($custom_data) {
                     $data = $custom_data;
                 }
             }
         }
         return $data;
     } else {
         return array();
     }
 }
Exemplo n.º 18
0
    }
    ?>

                    <input type="checkbox" name="finance_category_new_checked" value="new">
                    <input type="text" name="finance_category_new" value="">
                </div> &nbsp;
	<?php 
    $header_cats = ob_get_clean();
    $header_rows[] = array('sort_date' => array('data' => '<input type="text" name="transaction_date" class="date_field" value="' . print_date(time()) . '"> '), 'sort_name' => array('data' => '<input type="text" name="name" id="new_transaction_name">'), 'finance_description' => array('data' => '<input type="text" name="description">'), 'finance_customer' => array('data' => ''), 'sort_credit' => array('data' => currency('') . '<input type="text" name="credit" class="currency">', 'cell_class' => 'success_text'), 'sort_debit' => array('data' => currency('') . '<input type="text" name="debit" class="currency">', 'cell_class' => 'error_text'), 'sort_account' => array('data' => print_select_box(module_finance::get_accounts(), 'finance_account_id', '', '', true, 'name', true)), 'finance_categories' => array('data' => $header_cats), 'finance_tick' => array('data' => '<input type="submit" name="addnew" value="' . _l('Quick Add') . '" class="small_button">'));
    $table_manager->set_header_rows($header_rows);
}
$table_manager->set_rows($recent_transactions);
if (module_config::c('finance_list_show_totals', 1)) {
    $footer_rows = array();
    foreach ($finance_credit_total + $finance_debit_total as $currency_id => $foo) {
        $currency = get_single('currency', 'currency_id', $currency_id);
        $footer_rows[] = array('sort_date' => array('data' => ' ', 'cell_colspan' => 3), 'finance_customer' => array('data' => '<strong>' . _l('%s Totals:', $currency && isset($currency['code']) ? $currency['code'] : '') . '</strong>', 'cell_class' => 'text-right'), 'sort_credit' => array('data' => '<strong>' . dollar(isset($finance_credit_total[$currency_id]) ? $finance_credit_total[$currency_id] : 0, true, $currency_id) . '</strong>'), 'sort_debit' => array('data' => '<strong>' . dollar(isset($finance_debit_total[$currency_id]) ? $finance_debit_total[$currency_id] : 0, true, $currency_id) . '</strong>'), 'sort_account' => array('data' => ' ', 'cell_colspan' => 4));
    }
    $footer_rows[] = array('sort_date' => array('data' => ' ', 'cell_colspan' => 8), 'finance_tick' => array('data' => '<input type="button" name="link" value="' . _l('Link') . '" class="small_button" onclick="$(\'#link_go\').val(\'go\'); $(\'#quick_add_form\')[0].submit();">
						<input type="hidden" name="link_go" value="0" id="link_go">
                        ' . _hr('Combine transactions together. eg: an invoice payment history with corresponding bank statement transaction. Transactions need to be the same dollar amount to link successfully.'), 'cell_colspan' => 4));
    $table_manager->set_footer_rows($footer_rows);
}
$table_manager->pagination = true;
$table_manager->print_table();
?>

</form>
<?php 
if ($show_excluded_payment_info) {
    ?>
Exemplo n.º 19
0
 public static function handle_import($data, $add_to_group)
 {
     // woo! we're doing an import.
     // our first loop we go through and find matching products by their "product_name" (required field)
     // and then we assign that product_id to the import data.
     // our second loop through if there is a product_id we overwrite that existing product with the import data (ignoring blanks).
     // if there is no product id we create a new product record :) awesome.
     foreach ($data as $rowid => $row) {
         if (!isset($row['name']) || !trim($row['name'])) {
             unset($data[$rowid]);
             continue;
         }
         if (!isset($row['product_id']) || !$row['product_id']) {
             $data[$rowid]['product_id'] = 0;
         }
     }
     // now save the data.
     $count = 0;
     foreach ($data as $rowid => $row) {
         $row['product_id'] = update_insert('product_id', $row['product_id'], 'product', $row);
         if ($row['product_id']) {
             // is there a category?
             if (isset($row['category_name']) && strlen(trim($row['category_name']))) {
                 // find this category, if none exists then create it.
                 $product_category = get_single('product_category', 'product_category_name', trim($row['category_name']));
                 if (!$product_category) {
                     $product_category = array('product_category_name' => trim($row['category_name']));
                     $product_category['product_category_id'] = update_insert('product_category_id', false, 'product_category', $product_category);
                 }
                 if (isset($product_category['product_category_id']) && $product_category['product_category_id']) {
                     $row['product_id'] = update_insert('product_id', $row['product_id'], 'product', array('product_category_id' => $product_category['product_category_id']));
                 }
             }
             $count++;
         }
     }
     return $count;
 }
Exemplo n.º 20
0
 public static function handle_import_tasks($data, $add_to_group)
 {
     $import_options = json_decode(base64_decode($_REQUEST['import_options']), true);
     $job_id = (int) $import_options['job_id'];
     if (!$import_options || !is_array($import_options) || $job_id <= 0) {
         echo 'Sorry import failed. Please try again';
         exit;
     }
     $existing_tasks = self::get_tasks($job_id);
     $existing_staff = module_user::get_staff_members();
     // woo! we're doing an import.
     // make sure we have a job id
     foreach ($data as $rowid => $row) {
         $row['job_id'] = $job_id;
         // check for required fields
         if (!isset($row['description']) || !trim($row['description'])) {
             unset($data[$rowid]);
             continue;
         }
         if (!isset($row['task_id']) || !$row['task_id']) {
             $data[$rowid]['task_id'] = 0;
         }
         // make sure this task id exists in the system against this job.
         if ($data[$rowid]['task_id'] > 0) {
             if (!isset($existing_tasks[$data[$rowid]['task_id']])) {
                 $data[$rowid]['task_id'] = 0;
                 // create a new task.
                 // this stops them updating a task in another job.
             }
         }
         if (!$data[$rowid]['task_id'] && $row['description']) {
             // search for a task based on this name. dont want duplicates in the system.
             $existing_task = get_single('task', array('job_id', 'description'), array($job_id, $row['description']));
             if ($existing_task) {
                 $data[$rowid]['task_id'] = $existing_task['task_id'];
             }
         }
         // we have to save the user_name specially.
         /*if(isset($row['user_name']) && $row['user_name']){
               // see if this staff member exists.
               foreach($existing_staff as $staff_member){
                   if(strtolower($staff_member['name']) == strtolower($row['user_name'])){
                       $data[$rowid]['user_id'] = $staff_member['user_id'];
                   }
               }
           }*/
     }
     $c = 0;
     $task_data = array();
     foreach ($data as $rowid => $row) {
         // now save the data.
         // we specify a "log_hours" value if we are logging more hours on a specific task.
         if (isset($row['completed']) && $row['completed'] > 0 && isset($row['hours']) && $row['hours'] > 0) {
             if ($row['task_id'] == 0) {
                 // we are logging hours against a new task
                 $row['log_hours'] = $row['completed'];
             } else {
                 if ($row['task_id'] > 0) {
                     // we are adjusting hours on an existing task.
                     $existing_completed_hours = $existing_tasks[$row['task_id']]['completed'];
                     if ($row['completed'] > $existing_completed_hours) {
                         // we are logging additional hours against the job.
                         $row['log_hours'] = $row['completed'] - $existing_completed_hours;
                     } else {
                         if ($row['completed'] < $existing_completed_hours) {
                             // we are removing hours on this task!
                             // tricky!!
                             $sql = "DELETE FROM `" . _DB_PREFIX . "task_log` WHERE task_id = " . (int) $row['task_id'];
                             query($sql);
                             $row['log_hours'] = $row['completed'];
                         }
                     }
                 }
             }
         }
         if ($row['task_id'] > 0) {
             $task_id = $row['task_id'];
         } else {
             $task_id = 'new' . $c . 'new';
             $c++;
         }
         $task_data[$task_id] = $row;
         /*foreach($add_to_group as $group_id => $tf){
               module_group::add_to_group($group_id,$task_id,'task');
           }*/
     }
     self::save_job($job_id, array('job_id' => $job_id, 'job_task' => $task_data));
 }
Exemplo n.º 21
0
 public static function get_extra_default($extra_default_id)
 {
     $extra_default_id = (int) $extra_default_id;
     $extra_data_key = false;
     if ($extra_default_id > 0) {
         $extra_data_key = get_single('extra_default', 'extra_default_id', $extra_default_id);
         if ($extra_data_key && isset($extra_data_key['options'])) {
             $extra_data_key['options'] = @json_decode($extra_data_key['options'], true);
         }
     }
     if (!$extra_data_key) {
         $extra_data_key = array('extra_default_id' => '', 'owner_table' => '', 'extra_key' => '', 'display_type' => '', 'order' => '', 'field_type' => '', 'reminder' => '0', 'options' => array());
     }
     return $extra_data_key;
 }
Exemplo n.º 22
0
    public static function print_table_data($owner_table, $owner_id)
    {
        if (self::can_i('view', 'Subscriptions') && module_config::c('subscription_show_in_table', 1)) {
            $extra_data = get_multiple('subscription_owner', array('owner_table' => $owner_table, 'owner_id' => $owner_id, 'deleted' => 0), 'subscription_owner_id');
            ?>

            <td>
                <?php 
            if ($extra_data) {
                foreach ($extra_data as $e) {
                    $subscription = get_single('subscription', 'subscription_id', $e['subscription_id']);
                    if (isset($subscription['name'])) {
                        echo htmlspecialchars($subscription['name']) . '<br/>';
                    }
                }
            }
            ?>

            </td>
            <?php 
        }
    }
Exemplo n.º 23
0
 public static function get_currency($currency_id)
 {
     return get_single('currency', 'currency_id', $currency_id);
 }
Exemplo n.º 24
0
 public static function get_security_role($security_role_id)
 {
     $role = get_single('security_role', 'security_role_id', $security_role_id);
     $role['permissions'] = get_multiple('security_role_perm', array('security_role_id' => $security_role_id), 'security_permission_id');
     return $role;
 }
Exemplo n.º 25
0
 public static function get_finances($search = array())
 {
     // we have to search for recent transactions. this involves combining the "finance" table with the "invoice_payment" table
     // then sort the results by date
     $hide_invoice_payments = false;
     $sql = "SELECT f.* ";
     $sql .= " , fa.name AS account_name ";
     $sql .= " , GROUP_CONCAT(fc.`name` ORDER BY fc.`name` ASC SEPARATOR ', ') AS categories ";
     $sql .= " FROM `" . _DB_PREFIX . "finance` f ";
     $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_account` fa USING (finance_account_id) ";
     $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_category_rel` fcr ON f.finance_id = fcr.finance_id ";
     $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_category` fc ON fcr.finance_category_id = fc.finance_category_id ";
     $where = " WHERE 1 ";
     if (isset($search['finance_account_id']) && is_array($search['finance_account_id'])) {
         $fo = array();
         foreach ($search['finance_account_id'] as $val) {
             if ((int) $val > 0) {
                 $fo[(int) $val] = true;
             }
         }
         if (count($fo) > 0) {
             $where .= " AND ( ";
             foreach ($fo as $f => $ff) {
                 $where .= " f.finance_account_id = " . $f . ' OR';
             }
             $where = rtrim($where, 'OR');
             $where .= ' )';
             $hide_invoice_payments = true;
         }
     }
     if (isset($search['finance_recurring_id']) && $search['finance_recurring_id']) {
         $where .= " AND f.finance_recurring_id = '" . (int) $search['finance_recurring_id'] . "'";
         $hide_invoice_payments = true;
     }
     if (isset($search['finance_category_id']) && is_array($search['finance_category_id'])) {
         $fo = array();
         foreach ($search['finance_category_id'] as $val) {
             if ((int) $val > 0) {
                 $fo[(int) $val] = true;
             }
         }
         if (count($fo) > 0) {
             $where .= " AND EXISTS ( SELECT * FROM `" . _DB_PREFIX . "finance_category_rel` fcr2 WHERE fcr2.finance_id = f.finance_id AND ( ";
             foreach ($fo as $f => $ff) {
                 $where .= " fcr2.finance_category_id = " . $f . ' OR';
             }
             $where = rtrim($where, 'OR');
             $where .= ' )';
             $where .= ' )';
             $hide_invoice_payments = true;
         }
     }
     if (isset($search['invoice_payment_id']) && $search['invoice_payment_id']) {
         $where .= " AND f.invoice_payment_id = '" . (int) $search['invoice_payment_id'] . "'";
         $hide_invoice_payments = true;
     }
     // below 6 searches are repeated again below in invoice payments
     if (isset($search['job_id']) && (int) $search['job_id'] > 0) {
         $where .= " AND f.`job_id` = " . (int) $search['job_id'];
     }
     if (isset($search['invoice_id']) && (int) $search['invoice_id'] > 0) {
         $where .= " AND f.`invoice_id` = " . (int) $search['invoice_id'];
     }
     if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) {
         $where .= " AND f.`customer_id` = " . (int) $search['customer_id'];
     }
     if (isset($search['company_id']) && (int) $search['company_id'] > 0) {
         // check this user can view this company id or not
         if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) {
             $companys = module_company::get_companys();
             if (isset($companys[$search['company_id']])) {
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON f.customer_id = cc.customer_id ";
                 $where .= " AND ( cc.`company_id` = " . (int) $search['company_id'] . " OR  f.`company_id` = " . (int) $search['company_id'] . " )";
             }
         }
     }
     if (isset($search['generic']) && strlen(trim($search['generic']))) {
         $name = mysql_real_escape_string(trim($search['generic']));
         $where .= " AND (f.`name` LIKE '%{$name}%' OR f.description LIKE '%{$name}%' )";
     }
     if (isset($search['date_from']) && $search['date_from'] != '') {
         $where .= " AND f.transaction_date >= '" . input_date($search['date_from']) . "'";
     }
     if (isset($search['date_to']) && $search['date_to'] != '') {
         $where .= " AND f.transaction_date <= '" . input_date($search['date_to']) . "'";
     }
     if (isset($search['amount_from']) && $search['amount_from'] != '') {
         $where .= " AND f.amount >= '" . mysql_real_escape_string($search['amount_from']) . "'";
     }
     if (isset($search['amount_to']) && $search['amount_to'] != '') {
         $where .= " AND f.amount <= '" . mysql_real_escape_string($search['amount_to']) . "'";
     }
     if (isset($search['type']) && $search['type'] != '' && $search['type'] != 'ie') {
         $where .= " AND f.type = '" . mysql_real_escape_string($search['type']) . "'";
     }
     // permissions from job module.
     /*switch(module_job::get_job_access_permissions()){
                 case _JOB_ACCESS_ALL:
     
                     break;
                 case _JOB_ACCESS_ASSIGNED:
                     // only assigned jobs!
                     //$from .= " LEFT JOIN `"._DB_PREFIX."task` t ON u.job_id = t.job_id ";
                     //u.user_id = ".(int)module_security::get_loggedin_id()." OR
                     $where .= " AND (t.user_id = ".(int)module_security::get_loggedin_id().")";
                     break;
                 case _JOB_ACCESS_CUSTOMER:
                     break;
             }*/
     // permissions from customer module.
     // tie in with customer permissions to only get jobs from customers we can access.
     switch (module_customer::get_customer_data_access()) {
         case _CUSTOMER_ACCESS_ALL:
             // all customers! so this means all jobs!
             break;
         case _CUSTOMER_ACCESS_ALL_COMPANY:
         case _CUSTOMER_ACCESS_CONTACTS:
         case _CUSTOMER_ACCESS_TASKS:
         case _CUSTOMER_ACCESS_STAFF:
             $valid_customer_ids = module_security::get_customer_restrictions();
             if (count($valid_customer_ids)) {
                 $where .= " AND f.customer_id IN ( ";
                 foreach ($valid_customer_ids as $valid_customer_id) {
                     $where .= (int) $valid_customer_id . ", ";
                 }
                 $where = rtrim($where, ', ');
                 $where .= " )";
             }
     }
     $where .= " GROUP BY f.finance_id ";
     $where .= " ORDER BY f.transaction_date DESC ";
     $sql .= $where;
     $finances_from_finance_db_table = qa($sql);
     // invoice payments:
     $finance_from_invoice_payments = array();
     $finance_from_job_staff_expenses = array();
     if (!$hide_invoice_payments && (!isset($search['invoice_id']) || !(int) $search['invoice_id'] > 0)) {
         $sql = "SELECT j.*, f.finance_id AS existing_finance_id ";
         $sql .= " FROM `" . _DB_PREFIX . "job` j ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance` f ON j.job_id = f.job_id AND f.job_staff_expense > 0 ";
         $where = " WHERE 1 ";
         //j.date_completed != '0000-00-00' ";
         $where .= " AND j.`c_staff_total_amount` > 0 ";
         if (isset($search['job_id']) && (int) $search['job_id'] > 0) {
             $where .= " AND (j.`job_id` = " . (int) $search['job_id'] . " ) ";
         }
         if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) {
             $where .= " AND j.`customer_id` = " . (int) $search['customer_id'];
         }
         /*if(isset($search['generic']) && strlen(trim($search['generic']))){
               $name = mysql_real_escape_string(trim($search['generic']));
               $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )";
           }*/
         if (isset($search['company_id']) && (int) $search['company_id'] > 0) {
             // check this user can view this company id or not
             if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) {
                 $companys = module_company::get_companys();
                 if (isset($companys[$search['company_id']])) {
                     $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON j.customer_id = cc.customer_id ";
                     $where .= " AND cc.`company_id` = " . (int) $search['company_id'];
                 }
             }
         }
         if (isset($search['date_from']) && $search['date_from'] != '') {
             $where .= " AND j.date_completed >= '" . input_date($search['date_from']) . "'";
         }
         if (isset($search['date_to']) && $search['date_to'] != '') {
             $where .= " AND j.date_completed <= '" . input_date($search['date_to']) . "'";
         }
         if (isset($search['amount_from']) && $search['amount_from'] != '') {
             $where .= " AND j.c_staff_total_amount >= '" . mysql_real_escape_string($search['amount_from']) . "'";
         }
         if (isset($search['amount_to']) && $search['amount_to'] != '') {
             $where .= " AND j.c_staff_total_amount <= '" . mysql_real_escape_string($search['amount_to']) . "'";
         }
         switch (module_job::get_job_access_permissions()) {
             case _JOB_ACCESS_ALL:
                 break;
             case _JOB_ACCESS_ASSIGNED:
                 // only assigned jobs!
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON j.job_id = t.job_id ";
                 $where .= " AND (j.user_id = " . (int) module_security::get_loggedin_id() . " OR t.user_id = " . (int) module_security::get_loggedin_id() . ")";
                 break;
             case _JOB_ACCESS_CUSTOMER:
                 // tie in with customer permissions to only get jobs from customers we can access.
                 $valid_customer_ids = module_security::get_customer_restrictions();
                 if (count($valid_customer_ids)) {
                     $where .= " AND j.customer_id IN ( ";
                     foreach ($valid_customer_ids as $valid_customer_id) {
                         $where .= (int) $valid_customer_id . ", ";
                     }
                     $where = rtrim($where, ', ');
                     $where .= " )";
                 }
                 break;
         }
         switch (module_customer::get_customer_data_access()) {
             case _CUSTOMER_ACCESS_ALL:
                 // all customers! so this means all jobs!
                 break;
             case _CUSTOMER_ACCESS_ALL_COMPANY:
             case _CUSTOMER_ACCESS_CONTACTS:
             case _CUSTOMER_ACCESS_TASKS:
             case _CUSTOMER_ACCESS_STAFF:
                 $valid_customer_ids = module_security::get_customer_restrictions();
                 if (count($valid_customer_ids)) {
                     $where .= " AND j.customer_id IN ( ";
                     foreach ($valid_customer_ids as $valid_customer_id) {
                         $where .= (int) $valid_customer_id . ", ";
                     }
                     $where = rtrim($where, ', ');
                     $where .= " )";
                 }
         }
         $sql .= $where . " GROUP BY j.job_id ORDER BY j.date_completed DESC ";
         //echo $sql;
         $finance_from_job_staff_expenses = array();
         $res = qa($sql);
         foreach ($res as $finance) {
             // we have a job with staff expenses. split this up into gruops based on staff members.
             $staff_total_grouped = false;
             if (isset($finance['c_staff_total_grouped']) && strlen($finance['c_staff_total_grouped'])) {
                 $staff_total_grouped = @unserialize($finance['c_staff_total_grouped']);
             }
             if ($staff_total_grouped === false) {
                 //	                echo 'here: ';
                 //	                var_dump($finance);
                 //	                var_dump($staff_total_grouped);
                 $job_data = module_job::get_job($finance['job_id']);
                 $staff_total_grouped = $job_data['staff_total_grouped'];
             }
             if (is_array($staff_total_grouped)) {
                 foreach ($staff_total_grouped as $staff_id => $staff_total) {
                     $staff_member = module_user::get_user($staff_id);
                     if ($staff_member && $staff_member['user_id'] == $staff_id) {
                         // make sure this entry doesn't already exist in the database table for this job
                         // there MAY be an existing entry if 'existing_finance_id' is set
                         if ($finance['existing_finance_id'] > 0) {
                             // check if it exists for this staff member.
                             $existing = get_single('finance', array('job_id', 'job_staff_expense', 'amount'), array($finance['job_id'], $staff_id, $staff_total));
                             if ($existing) {
                                 // match exists already, skip adding this one to the list.
                                 continue;
                             }
                         }
                         //$finance = self::_format_invoice_payment($finance, $finance);
                         //$finance['url'] = module_job::link_open($finance['job_id'],false,$finance);
                         $finance['url'] = module_finance::link_open('new', false) . '&job_staff_expense=' . $staff_id . '&from_job_id=' . $finance['job_id'];
                         $finance['transaction_date'] = $finance['date_completed'];
                         $finance['description'] = _l('Job Expense For Staff Member: %s', $staff_member['name'] . ' ' . $staff_member['last_name']);
                         //"Exiting: ".$finance['existing_finance_id'].": ".
                         $finance['amount'] = $staff_total;
                         $finance['debit'] = $staff_total;
                         $finance['sub_amount'] = $staff_total;
                         $finance['taxable_amount'] = $staff_total;
                         $finance['credit'] = 0;
                         $finance['type'] = 'e';
                         $finance_from_job_staff_expenses[] = $finance;
                     }
                 }
             }
         }
     }
     if (!$hide_invoice_payments) {
         $sql = "SELECT p.*, i.customer_id ";
         if (module_config::c('finance_date_type', 'payment') == 'invoice') {
             // show entries by invoice create date, not payment date.
             $sql .= " , i.date_create AS transaction_date ";
         } else {
             // default, show by paid date.
             $sql .= " , p.date_paid AS transaction_date ";
         }
         $sql .= " FROM `" . _DB_PREFIX . "invoice_payment` p ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice` i ON p.invoice_id = i.invoice_id ";
         $where = " WHERE p.date_paid != '0000-00-00' ";
         $where .= " AND p.`amount` != 0 ";
         $where .= " AND ( p.`payment_type` = " . _INVOICE_PAYMENT_TYPE_NORMAL . " OR p.`payment_type` = " . _INVOICE_PAYMENT_TYPE_REFUND . ' OR p.`payment_type` = ' . _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT . ' OR p.`payment_type` = ' . _INVOICE_PAYMENT_TYPE_CREDIT . ')';
         if (isset($search['job_id']) && (int) $search['job_id'] > 0) {
             $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice_item` ii ON i.invoice_id = ii.invoice_id";
             $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON ii.task_id = t.task_id";
             $where .= " AND (t.`job_id` = " . (int) $search['job_id'] . " OR i.`deposit_job_id` = " . (int) $search['job_id'] . " ) ";
         }
         if (isset($search['invoice_id']) && (int) $search['invoice_id'] > 0) {
             $where .= " AND p.`invoice_id` = " . (int) $search['invoice_id'];
         }
         if (isset($search['customer_id']) && (int) $search['customer_id'] > 0) {
             $where .= " AND i.`customer_id` = " . (int) $search['customer_id'];
         }
         /*if(isset($search['generic']) && strlen(trim($search['generic']))){
               $name = mysql_real_escape_string(trim($search['generic']));
               $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )";
           }*/
         if (isset($search['company_id']) && (int) $search['company_id'] > 0) {
             // check this user can view this company id or not
             if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled()) {
                 $companys = module_company::get_companys();
                 if (isset($companys[$search['company_id']])) {
                     $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON i.customer_id = cc.customer_id ";
                     $where .= " AND cc.`company_id` = " . (int) $search['company_id'];
                 }
             }
         }
         if (isset($search['date_from']) && $search['date_from'] != '') {
             if (module_config::c('finance_date_type', 'payment') == 'invoice') {
                 $where .= " AND i.date_create >= '" . input_date($search['date_from']) . "'";
             } else {
                 $where .= " AND p.date_paid >= '" . input_date($search['date_from']) . "'";
             }
         }
         if (isset($search['date_to']) && $search['date_to'] != '') {
             if (module_config::c('finance_date_type', 'payment') == 'invoice') {
                 $where .= " AND i.date_create <= '" . input_date($search['date_to']) . "'";
             } else {
                 $where .= " AND p.date_paid <= '" . input_date($search['date_to']) . "'";
             }
         }
         if (isset($search['amount_from']) && $search['amount_from'] != '') {
             $where .= " AND p.amount >= '" . mysql_real_escape_string($search['amount_from']) . "'";
         }
         if (isset($search['amount_to']) && $search['amount_to'] != '') {
             $where .= " AND p.amount <= '" . mysql_real_escape_string($search['amount_to']) . "'";
         }
         if (isset($search['type']) && $search['type'] != '' && $search['type'] != 'ie') {
             if ($search['type'] == 'i') {
                 $where .= " AND p.amount > 0";
             } else {
                 if ($search['type'] == 'e') {
                     $where .= " AND p.amount < 0";
                 }
             }
         }
         switch (module_customer::get_customer_data_access()) {
             case _CUSTOMER_ACCESS_ALL:
                 // all customers! so this means all jobs!
                 break;
             case _CUSTOMER_ACCESS_ALL_COMPANY:
             case _CUSTOMER_ACCESS_CONTACTS:
             case _CUSTOMER_ACCESS_TASKS:
             case _CUSTOMER_ACCESS_STAFF:
                 $valid_customer_ids = module_security::get_customer_restrictions();
                 if (count($valid_customer_ids)) {
                     $where .= " AND i.customer_id IN ( ";
                     foreach ($valid_customer_ids as $valid_customer_id) {
                         $where .= (int) $valid_customer_id . ", ";
                     }
                     $where = rtrim($where, ', ');
                     $where .= " )";
                 }
         }
         $sql .= $where . " ORDER BY p.date_paid DESC ";
         //echo $sql;
         $finance_from_invoice_payments = qa($sql);
         foreach ($finance_from_invoice_payments as $finance_id => $finance) {
             // doesn't have an finance / account reference just yet.
             // but they can create one and this will become a child entry to it.
             $finance = self::_format_invoice_payment($finance, $finance);
             /*if(!isset($finance['customer_id']) || !$finance['customer_id']){
                   $invoice_data = module_invoice::get_invoice($finance['invoice_id'],2);
                   $finance['customer_id'] = $invoice_data['customer_id'];
               }*/
             // grab a new name/descriptino/etc.. from other plugins (at the moment only subscription)
             /*$new_finance = hook_handle_callback('finance_invoice_listing',$finance['invoice_id'],$finance);
               if(is_array($new_finance) && count($new_finance)){
                   foreach($new_finance as $n){
                       $finance = array_merge($finance,$n);
                   }
               }*/
             $finance_from_invoice_payments[$finance_id] = $finance;
         }
         if (isset($search['generic']) && strlen(trim($search['generic']))) {
             $name = mysql_real_escape_string(trim($search['generic']));
             //                $where .= " AND (i.`name` LIKE '%$name%' OR p.method LIKE '%$name%' )";
             // we have to do a PHP search here because
             foreach ($finance_from_invoice_payments as $finance_id => $finance) {
                 if (stripos($finance['name'], $name) === false && stripos($finance['description'], $name) === false) {
                     unset($finance_from_invoice_payments[$finance_id]);
                 }
             }
         }
     }
     $finances = array_merge($finances_from_finance_db_table, $finance_from_invoice_payments, $finance_from_job_staff_expenses);
     unset($finances_from_finance_db_table);
     unset($finance_from_invoice_payments);
     unset($finance_from_job_staff_expenses);
     // sort this
     if (!function_exists('sort_finance')) {
         function sort_finance($a, $b)
         {
             $t1 = strtotime($a['transaction_date']);
             $t2 = strtotime($b['transaction_date']);
             if ($t1 == $t2) {
                 // sort by finance id, putting ones with a finance id first before others. then amount.
                 if (isset($a['finance_id']) && !isset($b['finance_id'])) {
                     // put $a before $b
                     return -1;
                 } else {
                     if (!isset($a['finance_id']) && isset($b['finance_id'])) {
                         // put $b before $a
                         return 1;
                     } else {
                         return $a['amount'] > $b['amount'];
                     }
                 }
             } else {
                 return $t1 < $t2;
             }
         }
     }
     uasort($finances, 'sort_finance');
     foreach ($finances as $finance_id => $finance) {
         // we load each of these transactions
         // transaction can be a "transaction" or an "invoice_payment"
         // find out if this transaction is a child transaction to another transaction.
         // if it is a child transaction and we haven't already dispayed it in this listing
         // then we find the parent transaction and display it along with all it's children in this place.
         // this wont be perfect all the time but will be awesome in 99% of cases.
         if (isset($finance['finance_id']) && $finance['finance_id']) {
             // displayed before already?
             if (isset($displayed_finance_ids[$finance['finance_id']])) {
                 $finances[$displayed_finance_ids[$finance['finance_id']]]['link_count']++;
                 unset($finances[$finance_id]);
                 continue;
             }
             $displayed_finance_ids[$finance['finance_id']] = $finance_id;
             if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id']) {
                 $displayed_invoice_payment_ids[$finance['invoice_payment_id']] = $finance_id;
                 // so we dont display again.
             }
         } else {
             if (isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] && isset($finance['invoice_id']) && $finance['invoice_id']) {
                 // this is an invoice payment (incoming payment)
                 // displayed before already?
                 if (isset($displayed_invoice_payment_ids[$finance['invoice_payment_id']])) {
                     $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]] = array_merge($finance, $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]]);
                     $finances[$displayed_invoice_payment_ids[$finance['invoice_payment_id']]]['link_count']++;
                     unset($finances[$finance_id]);
                     continue;
                 }
                 $displayed_invoice_payment_ids[$finance['invoice_payment_id']] = $finance_id;
                 // so we dont display again.
             } else {
                 if (isset($finance['c_staff_total_amount'])) {
                     // staff expense.
                 } else {
                     // nfi?
                     unset($finances[$finance_id]);
                     continue;
                 }
             }
         }
         if (isset($finance['parent_finance_id']) && $finance['parent_finance_id']) {
             // check if it's parent finance id has been displayed already somewhere.
             if (isset($displayed_finance_ids[$finance['parent_finance_id']])) {
                 $finances[$displayed_finance_ids[$finance['parent_finance_id']]]['link_count']++;
                 unset($finances[$finance_id]);
                 continue;
                 // already done it on this page.
             }
             $displayed_finance_ids[$finance['parent_finance_id']] = $finance_id;
             // we haven't displayed the parent one yet.
             // display the parent one in this listing.
             $finance = self::get_finance($finance['parent_finance_id']);
         }
         /*if(isset($finance['invoice_payment_id']) && $finance['invoice_payment_id'] && isset($finance['invoice_id']) && $finance['invoice_id']){
               // moved to above.
           }else*/
         if (isset($finance['finance_id']) && $finance['finance_id']) {
             $finance['url'] = self::link_open($finance['finance_id'], false);
             $finance['credit'] = $finance['type'] == 'i' ? $finance['amount'] : 0;
             $finance['debit'] = $finance['type'] == 'e' ? $finance['amount'] : 0;
             if (!isset($finance['categories'])) {
                 $finance['categories'] = '';
             }
             if (!isset($finance['account_name'])) {
                 $finance['account_name'] = '';
             }
         }
         if (isset($finance['taxes']) && !isset($finance['sub_amount'])) {
             $finance['sub_amount'] = $finance['amount'];
             foreach ($finance['taxes'] as $tax) {
                 if (isset($tax['amount'])) {
                     $finance['sub_amount'] -= $tax['amount'];
                 }
             }
         }
         $finance['link_count'] = 0;
         $finances[$finance_id] = $finance;
     }
     return $finances;
 }
Exemplo n.º 26
0
 public static function template_get_company($template_id, $existing_template_data, $override_company_id = false)
 {
     if (defined('COMPANY_UNIQUE_CONFIG') && COMPANY_UNIQUE_CONFIG) {
         $company_id = $override_company_id ? $override_company_id : self::get_current_logged_in_company_id();
         if ((int) $company_id > 0) {
             // check user has access to this company.
             $company = self::get_company($company_id);
             if ($company && $company['company_id'] == $company_id) {
                 $data = get_single("company_template", array('company_id', 'template_id'), array($company_id, $template_id));
                 if ($data && $data['company_id'] == (int) $company_id) {
                     return array_merge($existing_template_data, $data);
                 }
             }
         }
     }
     return false;
 }
Exemplo n.º 27
0
 public static function get_report($report_id)
 {
     $report = get_single("report", "report_id", $report_id);
     if (!$report) {
         $report = array('report_id' => 'new', 'report_title' => '', 'notes' => '');
     }
     return $report;
 }
Exemplo n.º 28
0
 public static function get($social_facebook_id)
 {
     return get_single('social_facebook', 'social_facebook_id', $social_facebook_id);
 }
Exemplo n.º 29
0
 public static function get_note($note_id)
 {
     $note = get_single("note", "note_id", $note_id);
     if ($note) {
         // optional processing here later on.
     }
     return $note;
 }
Exemplo n.º 30
0
 public static function save_encrypt_value($encrypt_key_id, $raw_value, $page_name, $field_name, $existing_encrypt_id = 0)
 {
     // find matching field, if none exists create it.
     $encrypt_field = get_single('encrypt_field', array('page_name', 'field_name'), array($page_name, $field_name));
     $encrypt_field_id = false;
     if ($encrypt_field && $encrypt_field['encrypt_field_id']) {
         $encrypt_field_id = $encrypt_field['encrypt_field_id'];
     }
     if (!$encrypt_field_id) {
         $encrypt_field_id = update_insert('encrypt_field_id', 0, 'encrypt_field', array('page_name' => $page_name, 'field_name' => $field_name, 'encrypt_key_id' => $encrypt_key_id));
     }
     $encrypted_value = self::encrypt_value($encrypt_key_id, $raw_value);
     $encrypt_id = update_insert('encrypt_id', $existing_encrypt_id, 'encrypt', array('encrypt_key_id' => $encrypt_key_id, 'data' => $encrypted_value, 'encrypt_field_id' => $encrypt_field_id));
     return 'encrypt:' . $encrypt_id;
 }