示例#1
0
 public function init()
 {
     $this->module_name = "cache";
     $this->module_position = 1;
     $this->version = 2.229;
     // 2.229 - 2014-07-28 - menu generation speed improvement
     // 2.228 - 2014-05-12 - cache bug fixing
     // 2.227 - 2013-10-02 - cache bug fixing
     // 2.226 - 2013-09-12 - hopefully a BIG new speed improvement - change advanced cache_enabled to 1
     // 2.225 - 2013-09-12 - debug_cache advanced option added
     // 2.224 - 2013-09-10 - dashboard speed fix
     // 2.223 - 2013-09-08 - cache size fix
     // 2.222 - 2013-09-06 - cache_objects configuration variable (not cache_object)
     // 2.221 - 2013-09-03 - cache improvements and bug fixing
     // 2.22 - 2013-08-31 - cache and speed improvements
     // 2.21 - 2013-08-30 - better memcache support
     // 2.2 - 2013-08-30 - starting work on memcache support
     // version bug fix? maybe?
     // use memcache if it exists
     if (class_exists('Memcache', false) && module_config::c('cache_enabled', 1) && module_config::c('memcache_active', 0)) {
         self::$_memcache_instance = new Memcache();
         if (self::$_memcache_instance->connect(module_config::c('memcache_address', '127.0.0.1'), module_config::c('memcache_port', '11211'))) {
             //module_config::c('memcache_address','localhost'), )){
             self::$_memcache_prefix = md5(session_id() . _UCM_SECRET . _DB_PREFIX . _DB_NAME . _DB_USER . _DB_PASS);
             // what version of information are we requesting (inremented each time something is deleted, inserted or updated)
             // bad, but cannot think of any other easy quick way to invalidate caches upon updates
             self::$_memcache_version = self::$_memcache_instance->get(self::$_memcache_prefix . 'version');
             if (!self::$_memcache_version) {
                 self::$_memcache_version = 1;
             }
             self::$_use_memcache = true;
         }
     } else {
         if (module_config::c('cache_enabled', 1) && $this->db_table_exists('cache_store')) {
             $sql = "SELECT * FROM `" . _DB_PREFIX . "cache_store` WHERE expire_time > " . time();
             foreach (qa($sql) as $res) {
                 if (!isset(self::$_db_cache[$res['cache_group']])) {
                     self::$_db_cache[$res['cache_group']] = array();
                 }
                 self::$_db_cache[$res['cache_group']][$res['cache_key']] = $res['cache_data'];
             }
             register_shutdown_function('module_cache::shutdown_write_cached_data');
         }
     }
     // change to low number by default
     if (module_config::c('cache_objects', 120) == 3600) {
         module_config::save_config('cache_objects', 120);
     }
     if (module_config::c('cache_enabled', 1) && $this->db_table_exists('cache')) {
         $sql = "SELECT * FROM `" . _DB_PREFIX . "cache`";
         foreach (qa($sql) as $r) {
             self::$_cache_expiry[$r['cache_group']] = $r['expire_time'];
         }
     }
 }
示例#2
0
 public function run_cron($debug = false)
 {
     // check for payments.
     $sql = "SELECT * FROM `" . _DB_PREFIX . "invoice_payment` ip WHERE 1 ";
     $sql .= " AND  `method` = 'paynl' ";
     $sql .= " AND  `date_paid` = '0000-00-00' ";
     $sql .= " AND  `other_id` != '' ";
     foreach (qa($sql) as $payment) {
         // check api status:
         $strUrl = 'https://*****:*****@rest-api.pay.nl/v5/Transaction/info/json?';
         $arrArguments = array();
         $arrArguments['transactionId'] = $payment['other_id'];
         # Prepare and call API URL
         $strUrl .= http_build_query($arrArguments);
         if ($debug) {
             echo "Checking URL {$strUrl} <br>\n";
             $jsonResult = file_get_contents($strUrl);
         } else {
             $jsonResult = @file_get_contents($strUrl);
         }
         $json = @json_decode($jsonResult, true);
         if ($debug) {
             echo "Got result: <br>\n";
             print_r($json);
         }
         if ($json && isset($json['paymentDetails']) && isset($json['paymentDetails']['stateName']) && isset($json['paymentDetails']['amount'])) {
             module_paymethod_paynl::add_payment_data($payment['invoice_payment_id'], 'log', "PayNL Status " . $json['paymentDetails']['stateName'] . ": \n " . var_export($json, true));
             switch ($json['paymentDetails']['stateName']) {
                 case 'PENDING':
                     // defauly, still waiting for payment.
                     break;
                 case 'PAID':
                     update_insert("invoice_payment_id", $payment['invoice_payment_id'], "invoice_payment", array('date_paid' => date('Y-m-d'), 'amount' => $json['paymentDetails']['amount'] / 100, 'other_id' => ''));
                     module_invoice::save_invoice($payment['invoice_id'], array());
                     break;
                 case 'CANCEL':
                     update_insert("invoice_payment_id", $payment['invoice_payment_id'], "invoice_payment", array('other_id' => ''));
                     module_invoice::save_invoice($payment['invoice_id'], array());
                     send_error('PayNL payment cancelled for invoice: ' . module_invoice::link_open($payment['invoice_id'], true));
                     break;
             }
         } else {
             module_paymethod_paynl::add_payment_data($payment['invoice_payment_id'], 'log', "PayNL Status ERROR: \n " . $jsonResult);
         }
     }
 }
示例#3
0
 public static function display_notes($options)
 {
     $owner_table = isset($options['owner_table']) && $options['owner_table'] ? $options['owner_table'] : false;
     global $plugins;
     // permission checking.
     $can_create = $can_edit = $can_view = $can_delete = true;
     if ($options && isset($options['bypass_security'])) {
         // do nothing?
     } else {
         if (isset($options) && isset($options['owner_table']) && $options['owner_table'] && isset($options['title']) && $options['title']) {
             $can_view = $plugins[$options['owner_table']]->can_i('view', $options['title']);
             $can_edit = $plugins[$options['owner_table']]->can_i('edit', $options['title']);
             $can_create = $plugins[$options['owner_table']]->can_i('create', $options['title']);
             $can_delete = $plugins[$options['owner_table']]->can_i('delete', $options['title']);
         }
     }
     /*if(!module_security::is_page_editable()){
           $can_edit=$can_create=$can_delete=false;
       }*/
     if (!$can_view) {
         return '';
     }
     // display links in a popup?
     $popup_links = get_display_mode() != 'mobile';
     // disable popups in mobile version.
     $owner_id = isset($options['owner_id']) && $options['owner_id'] ? (int) $options['owner_id'] : false;
     if ($owner_id && $owner_table) {
         // we have all that we need to display some notes!! yey!!
         // do we display a summary or not?
         $note_items = self::get_notes(array('owner_table' => $owner_table, 'owner_id' => $owner_id));
         $display_summary = isset($options['display_summary']) && $options['display_summary'];
         if (isset($options['summary_owners']) && is_array($options['summary_owners'])) {
             // generate a list of other notes we have to display int eh list.
             foreach ($options['summary_owners'] as $summary_owner_table => $summary_owner_ids) {
                 if (is_array($summary_owner_ids) && count($summary_owner_ids) > 0) {
                     //$sql = "SELECT *, note_id AS id FROM `"._DB_PREFIX."note` n WHERE owner_table = '".mysql_real_escape_string($summary_owner_table)."' AND ( ";
                     $sql = "SELECT *, note_id AS id FROM `" . _DB_PREFIX . "note` n WHERE n.`owner_table` = '" . mysql_real_escape_string($summary_owner_table) . "' AND n.`owner_id` IN ( ";
                     /*foreach($summary_owner_ids as $summary_owner_id){
                     			//$note_items = array_merge($note_items,self::get_notes(array('owner_table'=>$summary_owner_table,'owner_id'=>$summary_owner_id)));
                                             $sql .= " `owner_id` = '".(int)$summary_owner_id."' OR ";
                     		}
                                         $sql = rtrim($sql,'OR ');*/
                     foreach ($summary_owner_ids as $k => $summary_owner_id) {
                         $summary_owner_ids[$k] = (int) $summary_owner_id;
                     }
                     $sql .= implode(',', $summary_owner_ids);
                     $sql .= " )";
                     $note_items = array_merge($note_items, qa($sql));
                 }
             }
         }
         // moved to 'note_list.php'
         /*foreach($note_items as $key=>$note_item){
         			$note_items[$key]['html'] = self::print_note($note_item['note_id'],$note_item,$display_summary,$can_edit,$can_delete,$options);
         		}*/
         uasort($note_items, 'sort_notes');
         if (isset($options['view_link'])) {
             $blah = parse_url($options['view_link']);
             if ($blah && isset($blah['path']) && isset($blah['query'])) {
                 $options['view_link'] = $blah['path'] . '?' . $blah['query'];
             }
             $rel_data = $options['view_link'];
         }
         $note_list_safe = true;
         include "pages/note_list.php";
     }
 }
示例#4
0
 public static function get_reports($search = array())
 {
     // limit based on customer id
     /*if(!isset($_REQUEST['customer_id']) || !(int)$_REQUEST['customer_id']){
     			return array();
     		}*/
     // build up a custom search sql query based on the provided search fields
     $sql = "SELECT u.*,u.report_id AS id ";
     $sql .= ", u.report_title AS name ";
     // add in our extra fields for the csv export
     //if(isset($_REQUEST['import_export_go']) && $_REQUEST['import_export_go'] == 'yes'){
     if (class_exists('module_extra', false)) {
         $sql .= " , (SELECT GROUP_CONCAT(ex.`extra_key` ORDER BY ex.`extra_id` ASC SEPARATOR '" . _EXTRA_FIELD_DELIM . "') FROM `" . _DB_PREFIX . "extra` ex WHERE owner_id = u.report_id AND owner_table = 'report') AS extra_keys";
         $sql .= " , (SELECT GROUP_CONCAT(ex.`extra` ORDER BY ex.`extra_id` ASC SEPARATOR '" . _EXTRA_FIELD_DELIM . "') FROM `" . _DB_PREFIX . "extra` ex WHERE owner_id = u.report_id AND owner_table = 'report') AS extra_vals";
     }
     $from = " FROM `" . _DB_PREFIX . "report` u ";
     $where = " WHERE 1 ";
     if (isset($search['generic']) && $search['generic']) {
         $str = mysql_real_escape_string($search['generic']);
         $where .= " AND ( ";
         $where .= " u.report_title LIKE '%{$str}%' ";
         $where .= ' ) ';
     }
     $group_order = ' GROUP BY u.report_id ORDER BY u.report_title';
     // stop when multiple company sites have same region
     $sql = $sql . $from . $where . $group_order;
     $result = qa($sql);
     //module_security::filter_data_set("report",$result);
     return $result;
     //		return get_multiple("report",$search,"report_id","fuzzy","name");
 }
示例#5
0
 public static function get_statuses()
 {
     $sql = "SELECT `status` FROM `" . _DB_PREFIX . "file` GROUP BY `status` ORDER BY `status`";
     $statuses = array();
     foreach (qa($sql) as $r) {
         $statuses[$r['status']] = $r['status'];
     }
     return $statuses;
 }
示例#6
0
 public function run_cron($debug = false)
 {
     // we only want to perform these cron actions if we're after a certain time of day
     // because we dont want to be generating these renewals and sending them at midnight, can get confusing
     $after_time = module_config::c('invoice_automatic_after_time', 7);
     $time_of_day = date('G');
     if ($time_of_day < $after_time) {
         if ($debug) {
             echo "Not performing automatic invoice operations until after {$after_time}:00 - it is currently {$time_of_day}:" . date('i') . "<br>\n";
         }
         return;
     }
     // find automaitic invoice overdues
     $sql = "SELECT * FROM `" . _DB_PREFIX . "invoice`  ";
     $sql .= " WHERE date_due != '0000-00-00' AND date_due <= '" . date('Y-m-d') . "' AND date_paid = '0000-00-00' AND date_cancel = '0000-00-00'";
     $invoice_items = qa($sql);
     if ($debug) {
         echo "Processing " . count($invoice_items) . " overdue invoices:  <br>\n";
     }
     foreach ($invoice_items as $invoice_item) {
         module_cache::clear('invoice');
         $invoice = module_invoice::get_invoice($invoice_item['invoice_id']);
         if ($invoice['overdue'] && $invoice['overdue_email_auto']) {
             if ($debug) {
                 echo "Processing overdue for invoice: " . module_invoice::link_open($invoice['invoice_id'], true) . " <br>\n";
             }
             if ($debug) {
                 echo " - last sent: " . $invoice['date_sent'] . " <br>\n";
             }
             if ($debug) {
                 echo " - due date: " . $invoice['date_due'] . " <br>\n";
             }
             if ($debug) {
                 echo " - now: " . date('Y-m-d') . " ( " . time() . " ) <br>\n";
             }
             // if you change this calculation make sure it is changed in the dashboard alerts above to
             $send_email_on = false;
             if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00' && strtotime($invoice['date_sent']) > strtotime($invoice['date_due'])) {
                 // we have sent a reminder already (todo: this isn't correct logic, fix it up so it can tell for sure if we have sent a reminder already or not (eg: look through email history table)
                 $last_invoice_sent = strtotime($invoice['date_sent']);
                 if (module_config::c('overdue_email_auto_days_repeat', 7) <= 0) {
                     continue;
                     // skip sendin repeat reminders.
                 }
                 $send_email_on = strtotime('+' . module_config::c('overdue_email_auto_days_repeat', 7) . ' days', $last_invoice_sent);
             } else {
                 if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') {
                     $invoice_is_due = strtotime($invoice['date_due']);
                     $send_email_on = strtotime('+' . module_config::c('overdue_email_auto_days', 3) . ' days', $invoice_is_due);
                     if ($debug) {
                         echo module_config::c('overdue_email_auto_days', 3) . " days from " . $invoice['date_due'] . " is " . date('Y-m-d', $send_email_on) . "<br>\n";
                     }
                 } else {
                     // this invoice has not been sent yet, so we don't send an automated overdue notice.
                     // the user has to pick a "sent datE" before the system will send overdue notices.
                     if ($debug) {
                         echo " - NOT Sending Overdue Invoice Notice for " . module_invoice::link_open($invoice['invoice_id'], true) . " because it has no SENT DATE.<br>\n";
                     }
                     $send_email_on = false;
                 }
             }
             if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00' && date('Y-m-d', $send_email_on) == $invoice['date_sent']) {
                 if ($debug) {
                     echo " - NOT Sending Overdue Invoice Notice for " . module_invoice::link_open($invoice['invoice_id'], true) . " because it was last sent today already.<br>\n";
                 }
                 $send_email_on = false;
             }
             if ($send_email_on !== false && $debug) {
                 echo " - will send next invoice at: " . date('Y-m-d', $send_email_on) . " ( {$send_email_on} ) <br>\n";
             }
             if ($send_email_on !== false && $send_email_on <= strtotime(date('Y-m-d'))) {
                 if ($debug) {
                     echo " - Automatically Sending Overdue Invoice Notice for " . module_invoice::link_open($invoice['invoice_id'], true) . "<br>\n";
                 }
                 if ($debug) {
                     echo " - Emailing invoice to customer...";
                 }
                 if (module_invoice::email_invoice_to_customer($invoice['invoice_id'], $debug)) {
                     if ($debug) {
                         echo "sent successfully<br>\n";
                     }
                 } else {
                     echo "sending overdue invoice email failed for " . module_invoice::link_open($invoice['invoice_id'], true) . "<br>\n";
                 }
                 if ($debug) {
                     echo "<br>\n";
                 }
             }
         }
     }
     // find automatic invoice renewals
     $sql = "SELECT i.* FROM `" . _DB_PREFIX . "invoice` i ";
     $sql .= " WHERE i.date_renew != '0000-00-00'";
     $sql .= " AND i.date_create != '0000-00-00'";
     $sql .= " AND i.date_cancel = '0000-00-00'";
     $sql .= " AND i.date_renew <= '" . date('Y-m-d') . "'";
     $sql .= " AND (i.renew_invoice_id IS NULL OR i.renew_invoice_id = 0)";
     $sql .= " AND (i.renew_auto = 1)";
     $renew_invoices = qa($sql);
     foreach ($renew_invoices as $renew_invoice) {
         // time to automatically renew this invoice! woo!
         if ($debug) {
             echo "Automatically Renewing invoice " . module_invoice::link_open($renew_invoice['invoice_id'], true) . "<br>\n";
         }
         $invoice_data = module_invoice::get_invoice($renew_invoice['invoice_id']);
         if (module_config::c('invoice_auto_renew_only_paid_invoices', 1) && $invoice_data['total_amount_due'] > 0) {
             // invoice hasnt been paid, dont continue with renewl
             if ($debug) {
                 echo "NOT RENEWING INVOICE because it hasn't been paid yet !!! <br>\n";
             }
         } else {
             $new_invoice_id = $this->renew_invoice($renew_invoice['invoice_id']);
             if ($new_invoice_id) {
                 //module_cache::clear_cache();
                 if ($debug) {
                     echo "invoice Automatically Renewed: " . module_invoice::link_open($new_invoice_id, true) . "<br>\n";
                 }
                 if ($renew_invoice['renew_email']) {
                     if ($debug) {
                         echo "Emailing invoice to customer...";
                     }
                     if (module_invoice::email_invoice_to_customer($new_invoice_id, $debug)) {
                         if ($debug) {
                             echo "send successfully";
                         }
                     } else {
                         echo "sending renewed invoice email failed for " . module_invoice::link_open($new_invoice_id, true) . "<br>\n";
                     }
                     if ($debug) {
                         echo "<br>\n";
                     }
                 }
             }
         }
     }
 }
示例#7
0
 public function get_newsletter_content($db = false, $newsletter_content_id)
 {
     if (!$db) {
         $db = db_connect();
     }
     $sql = "SELECT * FROM " . _DB_PREFIX . "newsletter_content WHERE newsletter_content_id = '" . (int) $newsletter_content_id . "'";
     $res = array_shift(qa($sql, $db));
     $folder = _IMAGES_DIR . 'newsletter-' . $res['newsletter_id'] . '/';
     if (is_file($folder . $newsletter_content_id . '-thumb.jpg')) {
         $res['image_thumb'] = $folder . $newsletter_content_id . '-thumb.jpg';
     }
     if (is_file($folder . $newsletter_content_id . '.jpg')) {
         $res['image_main'] = $folder . $newsletter_content_id . '.jpg';
     }
     return $res;
 }
示例#8
0
 public static function run_pagination_hook(&$rows)
 {
     if (isset($_REQUEST['import_export_go']) && $_REQUEST['import_export_go'] == 'yes') {
         // we are posting back tot his script with a go!
         if (is_resource($rows)) {
             $new_rows = array();
             while ($row = mysql_fetch_assoc($rows)) {
                 $new_rows[] = $row;
             }
             $rows = $new_rows;
         } else {
             // rows stays the same.
         }
         // add these items to the import_export.
         if (is_array($rows) && count($rows)) {
             $fields = self::$pagination_options['fields'];
             // export as CSV file:
             ob_end_clean();
             ob_start();
             foreach ($fields as $key => $val) {
                 echo '"' . str_replace('"', '""', $key) . '",';
             }
             // check for extra fields.
             if (class_exists('module_extra', false) && isset(self::$pagination_options['extra']) && count(self::$pagination_options['extra'])) {
                 if (isset(self::$pagination_options['extra']['owner_table'])) {
                     self::$pagination_options['extra'] = array(self::$pagination_options['extra']);
                 }
                 foreach (self::$pagination_options['extra'] as $extra_field_id => $extra_field_settings) {
                     $sql = "SELECT `extra_key` FROM `" . _DB_PREFIX . "extra` WHERE owner_table = '" . mysql_real_escape_string($extra_field_settings['owner_table']) . "' AND `extra_key` != '' GROUP BY `extra_key` ORDER BY `extra_key`";
                     self::$pagination_options['extra'][$extra_field_id]['extra_fields'] = qa($sql);
                     foreach (self::$pagination_options['extra'][$extra_field_id]['extra_fields'] as $extra_field) {
                         echo '"' . str_replace('"', '""', $extra_field['extra_key']) . '",';
                     }
                 }
             }
             // check for group fields.
             if (class_exists('module_group', false) && isset(self::$pagination_options['group']) && self::$pagination_options['group']) {
                 // find groups for this entry
                 foreach (self::$pagination_options['group'] as $group_search) {
                     echo '"' . str_replace('"', '""', $group_search['title']) . '",';
                 }
             }
             echo "\n";
             foreach ($rows as $row) {
                 foreach ($fields as $key => $val) {
                     echo '"' . str_replace('"', '""', isset($row[$val]) ? $row[$val] : '') . '",';
                 }
                 // check for extra fields.
                 if (class_exists('module_extra', false) && isset(self::$pagination_options['extra']) && count(self::$pagination_options['extra'])) {
                     foreach (self::$pagination_options['extra'] as $extra_field_id => $extra_field_settings) {
                         $extra_vals = array();
                         if (isset($row[$extra_field_settings['owner_id']]) && $row[$extra_field_settings['owner_id']] > 0) {
                             $sql = "SELECT `extra_key` AS `id`, `extra` FROM `" . _DB_PREFIX . "extra` WHERE owner_table = '" . mysql_real_escape_string($extra_field_settings['owner_table']) . "' AND `owner_id` = '" . (int) $row[$extra_field_settings['owner_id']] . "' ORDER BY `extra_key`";
                             $extra_vals = qa($sql);
                         }
                         foreach ($extra_field_settings['extra_fields'] as $extra_field) {
                             echo '"';
                             echo isset($extra_vals[$extra_field['extra_key']]) ? str_replace('"', '""', $extra_vals[$extra_field['extra_key']]['extra']) : '';
                             echo '",';
                         }
                     }
                 }
                 // check for group fields.
                 if (class_exists('module_group', false) && isset(self::$pagination_options['group']) && self::$pagination_options['group']) {
                     // find groups for this entry
                     foreach (self::$pagination_options['group'] as $group_search) {
                         $g = array();
                         $groups = module_group::get_groups_search(array('owner_table' => $group_search['owner_table'], 'owner_id' => isset($row[$group_search['owner_id']]) ? $row[$group_search['owner_id']] : 0));
                         foreach ($groups as $group) {
                             $g[] = $group['name'];
                         }
                         echo '"' . str_replace('"', '""', implode(', ', $g)) . '",';
                     }
                 }
                 echo "\n";
             }
             // is there a summary to add at the end of the export?
             if (isset(self::$pagination_options['summary']) && is_array(self::$pagination_options['summary'])) {
                 foreach (self::$pagination_options['summary'] as $summary_row) {
                     foreach ($fields as $key => $val) {
                         echo '"';
                         if (isset($summary_row[$val])) {
                             echo $summary_row[$val];
                         }
                         echo '",';
                     }
                     echo "\n";
                 }
             }
             $csv = ob_get_clean();
             if (module_config::c('export_csv_debug', 0)) {
                 echo '<pre>' . $csv . '</pre>';
                 exit;
             }
             header("Pragma: public");
             header("Expires: 0");
             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
             header("Cache-Control: private", false);
             header("Content-Type: text/csv");
             //todo: correct file name
             header("Content-Disposition: attachment; filename=\"" . (isset(self::$pagination_options['name']) ? self::$pagination_options['name'] . '.csv' : 'Export.csv') . "\";");
             header("Content-Transfer-Encoding: binary");
             // todo: calculate file size with ob buffering
             header("Content-Length: " . strlen($csv));
             echo $csv;
             exit;
         }
     }
 }
示例#9
0
 public function get_upgrade_sql()
 {
     $sql = '';
     /*$installed_version = (string)$installed_version;
             $new_version = (string)$new_version;
             $options = array(
                 '2' => array(
                     '2.1' =>   'ALTER TABLE  `'._DB_PREFIX.'task` CHANGE  `project_id`  `job_id` INT( 11 ) NOT NULL;' .
                         'ALTER TABLE  `'._DB_PREFIX.'task_log` CHANGE  `project_id`  `job_id` INT( 11 ) NOT NULL;',
                     '2.2' =>   'ALTER TABLE  `'._DB_PREFIX.'task` CHANGE  `project_id`  `job_id` INT( 11 ) NOT NULL;' .
                         'ALTER TABLE  `'._DB_PREFIX.'task_log` CHANGE  `project_id`  `job_id` INT( 11 ) NOT NULL;' .
                         'ALTER TABLE  `'._DB_PREFIX.'invoice` CHANGE  `project_id`  `job_id` INT( 11 ) NOT NULL;',
                 ),
                 '2.1' => array(
                     '2.2' =>   'ALTER TABLE  `'._DB_PREFIX.'invoice` CHANGE  `project_id`  `job_id` INT( 11 ) NOT NULL;',
                 ),
     
             );
             if(isset($options[$installed_version]) && isset($options[$installed_version][$new_version])){
                 $sql = $options[$installed_version][$new_version];
             }*/
     $fields = get_fields('job');
     if (!isset($fields['auto_task_numbers'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `auto_task_numbers` TINYINT( 1 ) NOT NULL DEFAULT  \'0\' AFTER  `user_id`;';
     }
     if (!isset($fields['job_discussion'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `job_discussion` TINYINT( 1 ) NOT NULL DEFAULT  \'0\' AFTER `auto_task_numbers`;';
     }
     if (!isset($fields['currency_id'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `currency_id` int(11) NOT NULL DEFAULT  \'1\' AFTER  `user_id`;';
     }
     if (!isset($fields['quote_id'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `quote_id` int(11) NOT NULL DEFAULT  \'0\' AFTER  `website_id`;';
     }
     if (!isset($fields['default_task_type'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `default_task_type` int(3) NOT NULL DEFAULT  \'0\' AFTER  `user_id`;';
     }
     if (!isset($fields['date_quote'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `date_quote` date NOT NULL AFTER `total_tax_rate`;';
         $sql .= 'UPDATE `' . _DB_PREFIX . 'job` SET `date_quote` = `date_created`;';
     }
     if (!isset($fields['renew_auto'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `renew_auto` TINYINT(1) NOT NULL DEFAULT \'0\' AFTER `currency_id`;';
     }
     if (!isset($fields['renew_invoice'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `renew_invoice` TINYINT(1) NOT NULL DEFAULT \'0\' AFTER `renew_auto`;';
     }
     if (!isset($fields['total_percent_complete'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `total_percent_complete` DECIMAL(6,4) NOT NULL DEFAULT \'0\' AFTER `renew_invoice`;';
     }
     if (!isset($fields['total_percent_complete_manual'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `total_percent_complete_manual` tinyint(1) NOT NULL DEFAULT \'0\' AFTER `total_percent_complete`;';
     }
     if (!isset($fields['c_total_amount_invoicable'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `c_total_amount_invoicable` DECIMAL( 10,2 ) NOT NULL DEFAULT  \'-1\' AFTER `total_percent_complete`;';
     }
     if (!isset($fields['c_staff_total_amount'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `c_staff_total_amount` DECIMAL( 10,2 ) NOT NULL DEFAULT  \'-1\' AFTER `c_total_amount_invoicable`;';
     }
     if (!isset($fields['c_total_net_amount'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `c_total_net_amount` DECIMAL( 10,2 ) NOT NULL DEFAULT  \'-1\' AFTER `c_staff_total_amount`;';
     }
     if (!isset($fields['c_staff_total_grouped'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `c_staff_total_grouped` TEXT NOT NULL DEFAULT  \'\' AFTER `c_total_net_amount`;';
     }
     if (!isset($fields['description'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD  `description` TEXT NOT NULL DEFAULT  \'\' AFTER `c_total_net_amount`;';
     }
     if (!isset($fields['discount_amount'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD `discount_amount` DECIMAL(10,2) NOT NULL DEFAULT \'0\' AFTER `description`;';
     }
     if (!isset($fields['discount_description'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD `discount_description` varchar(255) NOT NULL DEFAULT \'\' AFTER `discount_amount`;';
     }
     if (!isset($fields['discount_type'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD `discount_type` INT NOT NULL DEFAULT \'0\' AFTER `discount_description`;';
     }
     if (!isset($fields['time_start'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD `time_start` varchar(10) NOT NULL DEFAULT \'\' AFTER `date_start`;';
     }
     if (!isset($fields['time_end'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'job` ADD `time_end` varchar(10) NOT NULL DEFAULT \'\' AFTER `time_start`;';
     }
     $fields = get_fields('task');
     if (!isset($fields['long_description'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD `long_description` LONGTEXT NULL;';
     }
     if (!isset($fields['task_order'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `task_order` int(11) NOT NULL DEFAULT  \'0\' AFTER `approval_required`;';
     }
     if (!isset($fields['date_done'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `date_done` date NOT NULL AFTER `date_due`;';
     }
     if (!isset($fields['taxable'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `taxable` tinyint(1) NOT NULL DEFAULT \'1\' AFTER `amount`;';
     }
     if (!isset($fields['manual_percent'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `manual_percent` int(4) NOT NULL DEFAULT \'-1\' AFTER `taxable`;';
     }
     if (!isset($fields['manual_task_type'])) {
         // if -1 then we use job default_task_type
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `manual_task_type` tinyint(2) NOT NULL DEFAULT \'-1\' AFTER `manual_percent`;';
     }
     if (!isset($fields['hours_mins'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `hours_mins`  DECIMAL(10,2) NOT NULL DEFAULT  \'0\' AFTER  `hours`;';
     }
     /*
     `billable` tinyint(2) NOT NULL DEFAULT '1',
     `staff_hours` decimal(10,2) NOT NULL DEFAULT '0',
     `staff_hours_mins` decimal(10,2) NOT NULL DEFAULT '0',
     `staff_amount` decimal(10,2) NOT NULL DEFAULT '0',
     `staff_taxable` tinyint(1) NOT NULL DEFAULT '1',
     `staff_billable` tinyint(2) NOT NULL DEFAULT '1',
     */
     if (!isset($fields['staff_split'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `staff_split` tinyint(1) NOT NULL DEFAULT  \'0\' AFTER  `billable`;';
     }
     if (!isset($fields['staff_hours'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `staff_hours`  DECIMAL(10,2) NOT NULL DEFAULT  \'0\' AFTER  `staff_split`;';
     }
     if (!isset($fields['staff_hours_mins'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `staff_hours_mins`  DECIMAL(10,2) NOT NULL DEFAULT  \'0\' AFTER  `staff_hours`;';
     }
     if (!isset($fields['staff_amount'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `staff_amount`  DECIMAL(10,2) NOT NULL DEFAULT  \'0\' AFTER  `staff_hours_mins`;';
     }
     if (!isset($fields['staff_taxable'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `staff_taxable`  tinyint(1)  NOT NULL DEFAULT  \'1\' AFTER  `staff_amount`;';
     }
     if (!isset($fields['staff_billable'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'task` ADD  `staff_billable`  tinyint(2)  NOT NULL DEFAULT  \'1\' AFTER  `staff_taxable`;';
     }
     /*if(!isset($fields['task_type'])){
           $sql .= 'ALTER TABLE  `'._DB_PREFIX.'task` ADD  `task_type` tinyint(2) NOT NULL DEFAULT \'0\' AFTER `task_order`;';
       }*/
     if (!self::db_table_exists('job_tax')) {
         $sql .= "CREATE TABLE `" . _DB_PREFIX . "job_tax` (\r\r\n    `job_tax_id` int(11) NOT NULL AUTO_INCREMENT,\r\r\n    `job_id` int(11) NOT NULL,\r\r\n    `percent` decimal(10,2) NOT NULL DEFAULT  '0',\r\r\n    `amount` decimal(10,2) NOT NULL DEFAULT  '0',\r\r\n    `name` varchar(50) NOT NULL DEFAULT  '',\r\r\n    `order` INT( 4 ) NOT NULL DEFAULT  '0',\r\r\n    `increment` TINYINT( 1 ) NOT NULL DEFAULT  '0',\r\r\n    `create_user_id` int(11) NOT NULL,\r\r\n    `update_user_id` int(11) NULL,\r\r\n    `date_created` date NOT NULL,\r\r\n    `date_updated` date NULL,\r\r\n    PRIMARY KEY (`job_tax_id`),\r\r\n    KEY (`job_id`)\r\r\n    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
     }
     self::add_table_index('job', 'customer_id');
     self::add_table_index('job', 'user_id');
     self::add_table_index('job', 'website_id');
     self::add_table_index('job', 'quote_id');
     self::add_table_index('task', 'job_id');
     self::add_table_index('task', 'user_id');
     self::add_table_index('task', 'invoice_id');
     self::add_table_index('task_log', 'task_id');
     self::add_table_index('task_log', 'job_Id');
     $bug_check = "SELECT * FROM `" . _DB_PREFIX . "job` WHERE (customer_id IS NULL OR customer_id = 0) AND (website_id IS NULL OR website_id = 0)  AND `name` = '' AND `type` = '' AND `date_start` = '0000-00-00' AND c_total_net_amount = 0 AND `user_id` = 0 AND (`discount_description` = '' OR `discount_description` IS NULL)";
     $count = qa($bug_check);
     if (count($count)) {
         $sql .= "DELETE FROM `" . _DB_PREFIX . "job` WHERE (customer_id IS NULL OR customer_id = 0) AND (website_id IS NULL OR website_id = 0)  AND `name` = '' AND `type` = '' AND `date_start` = '0000-00-00' AND c_total_net_amount = 0 AND `user_id` = 0 AND (`discount_description` = '' OR `discount_description` IS NULL);";
     }
     return $sql;
 }
示例#10
0
 public static function get_types()
 {
     $sql = "SELECT `type` FROM `" . _DB_PREFIX . "quote` GROUP BY `type` ORDER BY `type`";
     $statuses = module_job::get_types();
     foreach (qa($sql) as $r) {
         $statuses[$r['type']] = $r['type'];
     }
     return $statuses;
 }
示例#11
0
 public static function get_remaining_changes($website_id)
 {
     $change_request_website = get_single('change_request_website', 'website_id', $website_id);
     $changes = array(0, isset($change_request_website['limit_number']) ? $change_request_website['limit_number'] : 5);
     if (isset($change_request_website['limit_per'])) {
         switch ($change_request_website['limit_per']) {
             case 1:
                 // week
                 $period = 'week';
                 $start_time = date('Y-m-d H:i:s', strtotime('-7 days'));
                 break;
             case 2:
                 // month
                 $period = 'month';
                 $start_time = date('Y-m-d H:i:s', strtotime('-1 month'));
                 break;
             case 3:
                 // year
                 $period = 'year';
                 $start_time = date('Y-m-d H:i:s', strtotime('-1 year'));
                 break;
             default:
                 // all time.
                 $period = 'all time';
                 $start_time = 0;
         }
         $changes[2] = $period;
         $sql = " SELECT * FROM `" . _DB_PREFIX . "change_request` ";
         $sql .= " WHERE website_id = " . (int) $website_id;
         $sql .= " AND (`status` = 1 OR `status` = 2) ";
         if ($start_time) {
             $sql .= " AND `date_created` >= '" . mysql_real_escape_string($start_time) . "'";
         }
         $all = qa($sql);
         $changes[0] = count($all);
     }
     /*$all = $wpdb->get_results("SELECT * FROM $table_name
       WHERE (published = 1 OR published = 2) AND `user_id` = '$user_id' AND `time` > '$start_time'"); //completed or published.
       $changes[0] = count($all);*/
     return $changes;
 }
示例#12
0
    echo count($staff_messages);
    ?>
 in <?php 
    echo count($staff_tickets);
    ?>
 tickets
	            </td>
	            <td>
		            <?php 
    echo count($staff_private_messages);
    ?>
	            </td>
	            <td>
		            <?php 
    $sql = "SELECT * FROM `" . _DB_PREFIX . "ticket` WHERE last_message_timestamp >= " . (int) strtotime(input_date($search['date_from'])) . " AND last_message_timestamp <= " . (int) strtotime(input_date($search['date_to'])) . " AND assigned_user_id = " . (int) $staff_member['user_id'];
    $tickets = qa($sql);
    echo count($tickets);
    ?>
	            </td>
	            <td>
		            <?php 
    $r = 0;
    foreach ($tickets as $ticket) {
        if ($ticket['status_id'] == _TICKET_STATUS_RESOLVED_ID) {
            $r++;
        }
    }
    echo $r;
    ?>
	            </td>
            </tr>
示例#13
0
 public static function handle_import($data, $group = false, $extra_options)
 {
     $imported = 0;
     if (!_DEMO_MODE && isset($extra_options['language_id']) && $extra_options['language_id'] > 0 && count($data) > 1) {
         foreach ($data as $row) {
             if (isset($row['word']) && strlen($row['word']) && isset($row['translation']) && strlen($row['translation'])) {
                 // ready to import this word!
                 $sql = "SELECT  lw.language_word_id, lw.`word` ";
                 $sql .= " FROM ";
                 $sql .= " `" . _DB_PREFIX . "language_word` lw ";
                 $sql .= " WHERE lw.`word` = '" . mysql_real_escape_string($row['word']) . "'";
                 $res = qa($sql);
                 $language_word_id = false;
                 if (is_array($res)) {
                     foreach ($res as $r) {
                         if ($r['word'] == $row['word']) {
                             $language_word_id = $r['language_word_id'];
                         }
                     }
                 }
                 /*if($row['word'] == 'Dashboard'){
                 			echo 'dash';
                 			echo $sql;
                 			print_r($res);
                 			exit;
                 		}*/
                 if (!$language_word_id) {
                     // create a new one, unless our ignore option is setup
                     if (isset($extra_options['new_words']) && $extra_options['new_words'] == 'ignore') {
                         continue;
                         // skip this word
                     }
                     $language_word_id = update_insert('language_word_id', false, 'language_word', array('word' => $row['word']));
                 }
                 $sql = "REPLACE INTO `" . _DB_PREFIX . "language_translation` SET `language_id` = " . (int) $extra_options['language_id'] . ", ";
                 $sql .= "`language_word_id` = " . (int) $language_word_id . ", `translation` = '" . mysql_real_escape_string($row['translation']) . "'";
                 query($sql);
                 // add this translation to the file.
                 $imported++;
             }
         }
     } else {
         if (_DEMO_MODE) {
             set_error('Import disabled in demo mode');
         }
     }
     return $imported;
 }
示例#14
0
 public static function get_member_groups($owner_table, $owner_id)
 {
     $sql = "SELECT * FROM `" . _DB_PREFIX . "group_member` WHERE ";
     $sql .= " `owner_id` = '" . (int) $owner_id . "' AND ";
     $sql .= " `owner_table` = '" . mysql_real_escape_string($owner_table) . "'";
     return qa($sql);
 }
示例#15
0
 public static function get_faqs($search = array())
 {
     //return get_multiple('faq',array(),'faq_id','exact','question');
     $sql = "SELECT f.*, f.faq_id AS `id` ";
     $sql .= " FROM `" . _DB_PREFIX . "faq` f ";
     $sql .= " LEFT JOIN `" . _DB_PREFIX . "faq_product_rel` r ON f.faq_id = r.faq_id ";
     $sql .= " WHERE 1 ";
     if (isset($search['question']) && $search['question']) {
         $sql .= " AND f.question LIKE '%" . mysql_real_escape_string($search['question']) . "%'";
     }
     if (isset($search['faq_product_id']) && $search['faq_product_id']) {
         $sql .= " AND r.faq_product_id = " . (int) $search['faq_product_id'];
     }
     $sql .= " GROUP BY f.faq_id";
     return qa($sql);
 }
示例#16
0
 public static function get_data_items($data_record_id, $data_record_revision_id = false)
 {
     // first find all the data_field_id's that are to be used in this data_record
     $sql = "SELECT DISTINCT data_field_id AS data_field_id FROM `" . _DB_PREFIX . "data_store` WHERE data_record_id = '" . (int) $data_record_id . "'";
     $fields = qa($sql);
     $items = array();
     foreach ($fields as $field) {
         $data_field_id = (int) $field['data_field_id'];
         if ($data_field_id) {
             $sql = "SELECT * FROM `" . _DB_PREFIX . "data_store` WHERE data_record_id = '" . (int) $data_record_id . "'";
             $sql .= " AND data_field_id = '" . (int) $data_field_id . "'";
             if ($data_record_revision_id) {
                 $sql .= " AND data_record_revision_id <= '" . (int) $data_record_revision_id . "'";
             }
             $sql .= " ORDER BY data_record_revision_id DESC LIMIT 1";
             $items[$data_field_id] = qa1($sql);
         }
     }
     //$search = array("data_record_id"=>$data_record_id); //,'data_record_revision_id'=>$data_record_revision_id);
     //$items = get_multiple("data_store",$search,false,'exact','date_created DESC');
     return $items;
 }
示例#17
0
 * IP Address: 67.79.165.254
 */
$import_options = module_config::c('import_export_base64', 1) ? json_decode(base64_decode($_REQUEST['import_options']), true) : json_decode($_REQUEST['import_options'], true);
if (!$import_options || !is_array($import_options)) {
    echo 'Sorry import failed. Please try again';
    exit;
}
$extra_fields = array();
if (class_exists('module_extra', false) && isset($import_options['extra']) && $import_options['extra'] && is_array($import_options['extra'])) {
    // support for multiple extra fields.
    if (isset($import_options['extra']['owner_table'])) {
        $import_options['extra'] = array($import_options['extra']);
    }
    foreach ($import_options['extra'] as $extra_option) {
        $sql = "SELECT `extra_key` FROM `" . _DB_PREFIX . "extra` WHERE owner_table = '" . mysql_real_escape_string($extra_option['owner_table']) . "' AND `extra_key` != '' GROUP BY `extra_key` ORDER BY `extra_key`";
        $extra_fields[] = qa($sql);
    }
}
define('_CSV_JS_DELIM', '|||-|||');
if (isset($_REQUEST['download'])) {
    ob_end_clean();
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private", false);
    header("Content-Type: text/csv");
    //todo: correct file name
    header("Content-Disposition: attachment; filename=\"SampleImportFile.csv\";");
    header("Content-Transfer-Encoding: binary");
    foreach ($import_options['fields'] as $key => $val) {
        echo '"' . str_replace('"', '""', $key) . '",';
示例#18
0
    public function get_upgrade_sql()
    {
        $sql = '';
        $fields = get_fields('subscription_history');
        /*if(!isset($fields['member_id'])){
              $sql .= 'ALTER TABLE `'._DB_PREFIX.'subscription_history` ADD `member_id` INT(11) NOT NULL DEFAULT \'0\' AFTER `subscription_id`;';
          }
          if(!isset($fields['customer_id'])){
              $sql .= 'ALTER TABLE `'._DB_PREFIX.'subscription_history` ADD `customer_id` INT(11) NOT NULL DEFAULT \'0\' AFTER `member_id`;';
          }*/
        if (!isset($fields['subscription_owner_id'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'subscription_history` ADD `subscription_owner_id` INT(11) NOT NULL DEFAULT \'0\' AFTER `subscription_id`;';
        } else {
            self::add_table_index('subscription_history', 'subscription_owner_id');
        }
        if (!isset($fields['from_next_due_date'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'subscription_history` ADD `from_next_due_date` DATE NOT NULL COMMENT \'what date was this invoice generated from\' AFTER `paid_date`;';
        }
        if (!self::db_table_exists('subscription_owner')) {
            $sql .= 'CREATE TABLE `' . _DB_PREFIX . 'subscription_owner` (
 `subscription_owner_id` int(11) NOT NULL auto_increment,
 `subscription_id` int(11) NOT NULL ,
  `owner_table` varchar(30) NOT NULL ,
  `owner_id` int(11) NOT NULL,
  `deleted` INT NOT NULL DEFAULT  \'0\',
`start_date` date NOT NULL,
`next_due_date` date NOT NULL COMMENT \'calculated in php when saving\',
`manual_next_due_date` tinyint(1) NOT NULL DEFAULT \'0\',
`use_as_credit_bucket` TINYINT NOT NULL DEFAULT  \'0\',
`recur_limit` INT(11) NOT NULL DEFAULT  \'0\',
  `date_created` date NOT NULL,
  `date_updated` date NULL,
  PRIMARY KEY  (`subscription_owner_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ;';
        } else {
            // make sure subscription_owner_id is auto incrementing, issue in old sql that stopped this
            $hack_sql = "SHOW FIELDS FROM `" . _DB_PREFIX . "subscription_owner`";
            $res = qa($hack_sql);
            $has_ai = false;
            foreach ($res as $r) {
                if ($r['Field'] == 'subscription_owner_id') {
                    if (isset($r['Extra']) && $r['Extra'] == 'auto_increment') {
                        $has_ai = true;
                    }
                }
            }
            if (!$has_ai) {
                $sql .= "UPDATE `" . _DB_PREFIX . "subscription_owner` SET  `subscription_owner_id` = 1 WHERE `subscription_owner_id` = 0; ";
                $sql .= "ALTER TABLE  `" . _DB_PREFIX . "subscription_owner` CHANGE  `subscription_owner_id`  `subscription_owner_id` INT( 11 ) NOT NULL AUTO_INCREMENT; ";
                //query($hack_sql);
            }
            $fields = get_fields('subscription_owner');
            if (!isset($fields['use_as_credit_bucket'])) {
                $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'subscription_owner` ADD `use_as_credit_bucket` TINYINT NOT NULL DEFAULT  \'0\' AFTER `manual_next_due_date`;';
            }
            if (!isset($fields['recur_limit'])) {
                $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'subscription_owner` ADD `recur_limit` INT(11) NOT NULL DEFAULT  \'0\' AFTER `use_as_credit_bucket`;';
            }
        }
        /*$fields = get_fields('subscription_customer');
          if(!isset($fields['manual_next_due_date'])){
              $sql .= 'ALTER TABLE `'._DB_PREFIX.'subscription_customer` ADD `manual_next_due_date` tinyint(1) NOT NULL DEFAULT \'0\' AFTER `next_due_date`;';
          }
          $fields = get_fields('subscription_member');
          if(!isset($fields['manual_next_due_date'])){
              $sql .= 'ALTER TABLE `'._DB_PREFIX.'subscription_member` ADD `manual_next_due_date` tinyint(1) NOT NULL DEFAULT \'0\' AFTER `next_due_date`;';
          }*/
        $fields = get_fields('subscription');
        if (!isset($fields['automatic_renew'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'subscription` ADD `automatic_renew` tinyint(1) NOT NULL DEFAULT \'0\' AFTER `currency_id`;';
        }
        if (!isset($fields['automatic_email'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'subscription` ADD `automatic_email` tinyint(1) NOT NULL DEFAULT \'0\' AFTER `automatic_renew`;';
        }
        if (!isset($fields['settings'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'subscription` ADD `settings` TEXT NOT NULL DEFAULT \'\' AFTER `automatic_email`;';
        }
        if (!isset($fields['invoice_prior_days'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'subscription` ADD `invoice_prior_days` INT(11) NOT NULL DEFAULT \'0\' AFTER `settings`;';
        }
        self::add_table_index('subscription', 'owner_id');
        self::add_table_index('subscription', 'owner_table');
        self::add_table_index('subscription_history', 'subscription_id');
        self::add_table_index('subscription_history', 'subscription_owner_id');
        self::add_table_index('subscription_history', 'invoice_id');
        return $sql;
    }
示例#19
0
文件: db.php 项目: sgh1986915/php-crm
 public static function get_fields($table, $ignore = array(), $hidden = array(), $from_cache = false)
 {
     if (is_array($table) || !trim($table)) {
         return array();
     }
     if (isset(self::$fieldscache[$table])) {
         return self::$fieldscache[$table];
     }
     $res = $db_cache = array();
     if ($from_cache) {
         $db_cache = module_cache::get('db', 'db_fields_' . $table);
         if (!is_array($db_cache)) {
             $db_cache = array();
         }
         if (isset($db_cache[$table])) {
             $res = $db_cache[$table];
         }
     }
     if (!count($res)) {
         $sql = "SHOW FIELDS FROM `" . _DB_PREFIX . "{$table}`";
         $res = qa($sql);
         if (!is_array($db_cache)) {
             $db_cache = array();
         }
         $db_cache[$table] = $res;
         module_cache::put('db', 'db_fields_' . $table, $db_cache, 172800);
     }
     $fields = array();
     foreach ($res as $r) {
         $format = "";
         $type = 'text';
         if (count($ignore) && in_array($r['Field'], $ignore)) {
             continue;
         }
         if (count($hidden) && in_array($r['Field'], $hidden)) {
             $type = "hidden";
             // new field for file.
         } else {
             if (preg_match("/^file_/", $r['Field']) && preg_match("/varchar\\((\\d+)\\)/", $r['Type'], $matches)) {
                 $type = "file";
                 $size = 50;
                 $maxlength = 255;
             } else {
                 if (preg_match("/varchar\\((\\d+)\\)/", $r['Type'], $matches)) {
                     $type = "text";
                     $size = max("10", min("30", $matches[1]));
                     $maxlength = $matches[1];
                 } else {
                     if (preg_match("/int/i", $r['Type']) || preg_match("/float/i", $r['Type'])) {
                         $format = array("/^\\d+\$/", "Integer");
                         $type = "number";
                         $maxlength = $size = 20;
                     } else {
                         if ($r['Type'] == "text") {
                             $type = "textarea";
                             $size = 0;
                         } else {
                             if ($r['Type'] == "date" || $r['Type'] == "datetime") {
                                 $format = array("/^\\d\\d\\d\\d-\\d\\d-\\d\\d\$/", "YYYY-MM-DD");
                                 $type = "date";
                                 $maxlength = $size = 20;
                             } else {
                                 if (preg_match("/decimal/", $r['Type']) || preg_match("/double/", $r['Type'])) {
                                     $format = array("/^\\d+\\.?[\\d+]?\$/", "Decimal");
                                     $type = "decimal";
                                     $maxlength = $size = 20;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $required = false;
         if ($r['Null'] == "NO") {
             $required = true;
         }
         $fields[$r['Field']] = array("name" => $r['Field'], "type" => $type, "dbtype" => $r['Type'], "size" => $size, "maxlength" => $maxlength, "required" => $required, "format" => $format);
     }
     self::$fieldscache[$table] = $fields;
     return $fields;
 }
示例#20
0
 private static function _build_perms_cache()
 {
     $sql = "SELECT `name`, `category`, `module`, available_perms, security_permission_id, `description` ";
     $sql .= "FROM `" . _DB_PREFIX . "security_permission` sp";
     self::$perms_cache = qa($sql, false);
 }
示例#21
0
 public static function get_defaults($owner_table = false)
 {
     $defaults = array();
     $nextorder = array();
     if ($owner_table && strlen($owner_table)) {
         $where = " WHERE e.owner_table = '" . mysql_real_escape_string($owner_table) . "' ";
         $defaults[$owner_table] = array();
         $nextorder[$owner_table] = 0;
     } else {
         $where = '';
     }
     $sql = "SELECT `extra_default_id`,`extra_key`, `order`, `display_type`, `owner_table`, `searchable`, `field_type`, `options` FROM `" . _DB_PREFIX . "extra_default` e {$where} ORDER BY e.`order` ASC";
     foreach (qa($sql) as $r) {
         if (!isset($defaults[$r['owner_table']])) {
             $defaults[$r['owner_table']] = array();
         }
         if (!isset($nextorder[$r['owner_table']])) {
             $nextorder[$r['owner_table']] = 0;
         }
         $defaults[$r['owner_table']][$r['extra_key']] = array('key' => $r['extra_key'], 'order' => $r['order'], 'extra_default_id' => $r['extra_default_id'], 'display_type' => $r['display_type'], 'searchable' => $r['searchable'], 'field_type' => $r['field_type'], 'options' => isset($r['options']) ? @json_decode($r['options'], true) : array());
         $nextorder[$r['owner_table']] = max($r['order'], $nextorder[$r['owner_table']]);
     }
     // search database for keys.
     $sql = "SELECT `extra_key`,`owner_table` FROM `" . _DB_PREFIX . "extra` e {$where} GROUP BY e.extra_key";
     foreach (qa($sql) as $r) {
         if (!isset($nextorder[$r['owner_table']])) {
             $nextorder[$r['owner_table']] = 0;
         }
         if (!isset($defaults[$r['owner_table']]) || !isset($defaults[$r['owner_table']][$r['extra_key']])) {
             $nextorder[$r['owner_table']]++;
             $extra_default_id = update_insert('extra_default_id', false, 'extra_default', array('owner_table' => $r['owner_table'], 'extra_key' => $r['extra_key'], 'order' => $nextorder[$r['owner_table']], 'display_type' => 0));
             $defaults[$r['owner_table']][$r['extra_key']] = array();
             $defaults[$r['owner_table']][$r['extra_key']]['key'] = $r['extra_key'];
             $defaults[$r['owner_table']][$r['extra_key']]['order'] = $nextorder[$r['owner_table']];
             $defaults[$r['owner_table']][$r['extra_key']]['extra_default_id'] = $extra_default_id;
             $defaults[$r['owner_table']][$r['extra_key']]['display_type'] = 0;
             $defaults[$r['owner_table']][$r['extra_key']]['field_type'] = '';
             $defaults[$r['owner_table']][$r['extra_key']]['options'] = array();
             module_cache::clear_cache(false);
         }
         if (!isset($defaults[$r['owner_table']][$r['extra_key']]['order'])) {
             $defaults[$r['owner_table']][$r['extra_key']]['order'] = 0;
         }
         /*$defaults[$r['owner_table']][$r['extra_key']] = array(
               'key' => $r['extra_key'],
               'order'=> isset($defaults[$r['extra_key']]) ? $defaults[$r['extra_key']]['order'] : 0,
           );*/
     }
     if ($owner_table) {
         uasort($defaults[$owner_table], 'sort_extra_defaults');
         return $defaults[$owner_table];
     } else {
         return $defaults;
         //return all for settings area
     }
     /*        switch($owner_table){
                 case 'website':
                     $defaults = array(
                         array('key' => 'FTP Username',),
                         array('key' => 'FTP Password',),
                         array('key' => 'FTP Provider',),
                         array('key' => 'Host Username',),
                         array('key' => 'Host Password',),
                         array('key' => 'Host Provider',),
                         array('key' => 'WordPress User',),
                         array('key' => 'WordPress Pass',),
                         array('key' => 'Analytics Account',),
                         array('key' => 'Webmaster Account',),
                     );
                     break;
             }*/
 }
示例#22
0
 public static function get_companys_by_user($user_id)
 {
     $sql = "SELECT c.*, c.company_id AS id ";
     $sql .= " FROM `" . _DB_PREFIX . "company_user_rel` cc ";
     $sql .= " LEFT JOIN `" . _DB_PREFIX . "company` c USING (company_id) ";
     $sql .= " WHERE cc.user_id = '" . (int) $user_id . "'";
     $sql .= " GROUP BY c.company_id ";
     return qa($sql);
 }
示例#23
0
 private static function _init_vars($only_load_key = false)
 {
     if (self::$config_vars) {
         return false;
     }
     self::$config_vars = array();
     $sql = "SELECT `key`,`val` FROM `" . _DB_PREFIX . "config` ";
     foreach (qa($sql) as $c) {
         self::$config_vars[$c['key']] = $c['val'];
     }
     if (_DEMO_MODE && isset($_SESSION['_demo_config'])) {
         foreach ($_SESSION['_demo_config'] as $key => $val) {
             self::$config_vars[$key] = $val;
         }
     }
     if (function_exists('hook_handle_callback')) {
         // hook into the company module (or any other modules in the future) to modify this if needed
         $new_configs = hook_handle_callback('config_init_vars', self::$config_vars);
         // returns a list of new configs from other modules
         if (is_array($new_configs)) {
             foreach ($new_configs as $new_config) {
                 if (is_array($new_config)) {
                     self::$config_vars = array_merge(self::$config_vars, $new_config);
                 }
             }
         }
     }
 }
示例#24
0
 public static function get_statistics_jobs($search)
 {
     $results = array();
     // any jobs that were created within this time period
     $sql = "SELECT * FROM `" . _DB_PREFIX . "job` j WHERE 1";
     if (isset($search['type']) && $search['type']) {
         $sql .= " AND j.`type` = '" . mysql_real_escape_string($search['type']) . "'";
     }
     if (isset($search['date_from']) && $search['date_from']) {
         $sql .= " AND j.date_start >= '" . input_date($search['date_from']) . "'";
     }
     if (isset($search['date_to']) && $search['date_to']) {
         $sql .= " AND j.date_start <= '" . input_date($search['date_to']) . "'";
     }
     $results = qa($sql);
     // find any jobs that are due to be renewed within this time period
     $sql = "SELECT * FROM `" . _DB_PREFIX . "job` j WHERE 1";
     $sql .= " AND j.date_renew != '0000-00-00' ";
     if (isset($search['type']) && $search['type']) {
         $sql .= " AND j.`type` = '" . mysql_real_escape_string($search['type']) . "'";
     }
     if (isset($search['date_from']) && $search['date_from']) {
         $sql .= " AND j.date_renew >= '" . input_date($search['date_from']) . "'";
     }
     if (isset($search['date_to']) && $search['date_to']) {
         $sql .= " AND j.date_renew <= '" . input_date($search['date_to']) . "'";
     }
     $sql .= " AND (renew_job_id IS NULL OR renew_job_id = 0)";
     foreach (qa($sql) as $renewed_job) {
         $renewed_job['renew_from_job_id'] = $renewed_job['job_id'];
         $time_diff = strtotime($renewed_job['date_renew']) - strtotime($renewed_job['date_start']);
         $date_renew = $renewed_job['date_renew'];
         $renewed_job['date_renew'] = date('Y-m-d', strtotime($renewed_job['date_renew']) + $time_diff);
         $renewed_job['date_start'] = $date_renew;
         $results[] = $renewed_job;
     }
     // any jobs due for renewal before this time period, that haven't been renewed.
     // calculate their next renewal date(s) and see if one of them lands in time period.
     if (isset($search['date_from']) && $search['date_from'] && isset($search['date_to']) && $search['date_to']) {
         $from_timestamp = strtotime(input_date($search['date_from']));
         $to_timestamp = strtotime(input_date($search['date_to']));
         $sql = "SELECT * FROM `" . _DB_PREFIX . "job` j WHERE 1";
         if (isset($search['type']) && $search['type']) {
             $sql .= " AND j.`type` = '" . mysql_real_escape_string($search['type']) . "'";
         }
         $sql .= " AND j.date_start != '0000-00-00' ";
         $sql .= " AND j.date_renew != '0000-00-00' ";
         //$sql .= " AND j.date_start < '".input_date($search['date_from'])."'";
         $sql .= " AND j.date_renew < '" . input_date($search['date_to']) . "'";
         $sql .= " AND (j.renew_job_id IS NULL OR j.renew_job_id = 0)";
         foreach (qa($sql) as $possible_renewed_job) {
             $time_diff = strtotime($possible_renewed_job['date_renew']) - strtotime($possible_renewed_job['date_start']);
             $new_renewal_date = strtotime($possible_renewed_job['date_renew']);
             for ($x = 0; $x < 5; $x++) {
                 $new_renewal_date = $new_renewal_date + $time_diff;
                 if ($new_renewal_date >= $from_timestamp) {
                     // this job will be renewed in our period! yay!
                     if ($to_timestamp == 0 || $to_timestamp > 0 && $new_renewal_date <= $to_timestamp) {
                         // this is within our bounds! yay!
                         $possible_renewed_job['renew_from_job_id'] = $possible_renewed_job['job_id'];
                         $possible_renewed_job['date_start'] = date('Y-m-d', $new_renewal_date);
                         $possible_renewed_job['date_renew'] = date('Y-m-d', $new_renewal_date + $time_diff);
                         $results[] = $possible_renewed_job;
                     } else {
                         break;
                         // gone too far
                     }
                 }
             }
         }
     }
     usort($results, array('module_statistic', "get_statistics_jobs_sort"));
     return $results;
 }
示例#25
0
 public static function get_finance_summary($week_start, $week_end, $multiplyer = 1, $row_limit = 7)
 {
     $cache_key = 'finance_sum_' . md5(module_security::get_loggedin_id() . '_' . serialize(func_get_args()));
     $cache_timeout = module_config::c('cache_objects', 60);
     if ($cached_item = module_cache::get('finance', $cache_key)) {
         return $cached_item;
     }
     $base_href = module_finance::link_generate(false, array('full' => false, 'page' => 'dashboard_popup', 'arguments' => array('display_mode' => 'ajax')), array('foo'));
     $base_href .= '&';
     /*$base_href .= (strpos($base_href,'?')!==false) ? '&' : '?';
       $base_href .= 'display_mode=ajax&';
       $base_href .= 'home_page_stats=true&';*/
     // init structure:
     if ($multiplyer > 1) {
         $row_limit++;
     }
     for ($x = 0; $x < $row_limit; $x++) {
         //$time = strtotime("+$x days",strtotime($week_start));
         $time = strtotime("+" . $x * $multiplyer . " days", strtotime($week_start));
         $data[date("Ymd", $time)] = array("day" => $time, "hours" => 0, "amount" => 0, "amount_invoiced" => 0, "amount_paid" => 0, "amount_spent" => 0);
         if (class_exists('module_envato', false)) {
             $data[date("Ymd", $time)]['envato_earnings'] = 0;
         }
     }
     $data['total'] = array('day' => _l('Totals:'), 'week' => _l('Totals:'), 'hours' => 0, 'amount' => 0, 'amount_invoiced' => 0, 'amount_paid' => 0, 'amount_spent' => 0);
     if (class_exists('module_envato', false)) {
         $data['total']['envato_earnings'] = 0;
     }
     if (class_exists('module_job', false)) {
         module_debug::log(array('title' => 'Finance Dashboard Job', 'data' => ''));
         // find all task LOGS completed within these dayes
         $sql = "SELECT t.task_id, tl.date_created, t.hours AS task_hours, t.amount, tl.hours AS hours_logged, p.job_id, p.hourly_rate, t.date_done ";
         //            $sql .= " FROM `"._DB_PREFIX."task_log` tl ";
         //            $sql .= " LEFT JOIN `"._DB_PREFIX."task` t ON tl.task_id = t.task_id ";
         $sql .= " FROM `" . _DB_PREFIX . "task` t";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "task_log` tl ON t.task_id = tl.task_id ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` p ON t.job_id = p.job_id";
         $sql .= " WHERE ( (tl.date_created >= '{$week_start}' AND tl.date_created < '{$week_end}') OR (t.fully_completed = 1 AND t.date_done >= '{$week_start}' AND t.date_done < '{$week_end}') )";
         $sql .= " AND t.job_id IN ( ";
         $valid_job_ids = module_job::get_valid_job_ids();
         if (count($valid_job_ids)) {
             foreach ($valid_job_ids as $valid_job_id) {
                 $sql .= (int) $valid_job_id['job_id'] . ", ";
             }
             $sql = rtrim($sql, ', ');
         } else {
             $sql .= ' NULL ';
         }
         $sql .= " ) ";
         //            echo $sql;
         $tasks = query($sql);
         $logged_tasks = array();
         while ($r = mysql_fetch_assoc($tasks)) {
             if (!$r['date_created']) {
                 $r['date_created'] = $r['date_done'];
             }
             if ($multiplyer > 1) {
                 $week_day = date('w', strtotime($r['date_created'])) - 1;
                 $r['date_created'] = date('Y-m-d', strtotime('-' . $week_day . ' days', strtotime($r['date_created'])));
             }
             $key = date("Ymd", strtotime($r['date_created']));
             if (!isset($data[$key])) {
                 // for some reason we're getting results here that shouldn't be in the list
                 // for now we just skip these results until I figure out why (only had 1 guy report this error, maybe misconfig)
                 continue;
             }
             // copied from dashboard_popup_hours_logged.php
             // needed get_tasks call to do the _JOB_TASK_ACCESS_ASSIGNED_ONLY permission check
             $jobtasks = module_job::get_tasks($r['job_id']);
             $task = isset($jobtasks[$r['task_id']]) ? $jobtasks[$r['task_id']] : false;
             if (!$task) {
                 continue;
             }
             if (!isset($task['manual_task_type']) || $task['manual_task_type'] < 0) {
                 $task['manual_task_type'] = $task['default_task_type'];
             }
             if (isset($r['hours_logged']) && $r['hours_logged'] > 0) {
                 if ($r['hours_logged'] == $task['completed']) {
                     // this listing is the only logged hours for this task.
                     if ($task['fully_completed']) {
                         // task complete, we show the final amount and hours.
                         if ($task['amount'] > 0) {
                             if ($task['manual_task_type'] == _TASK_TYPE_QTY_AMOUNT) {
                                 $display_amount = $task['amount'] * $task['hours'];
                             } else {
                                 $display_amount = $task['amount'];
                             }
                         } else {
                             $display_amount = $r['task_hours'] * $r['hourly_rate'];
                         }
                     } else {
                         // task isn't fully completed yet, just use hourly rate for now.
                         $display_amount = $r['hours_logged'] * $r['hourly_rate'];
                     }
                 } else {
                     // this is part of a bigger log of hours for this single task.
                     $display_amount = $r['hours_logged'] * $r['hourly_rate'];
                 }
                 $hours_logged = $r['task_hours'] > 0 ? $r['hours_logged'] : 0;
             } else {
                 // there are no logged hours for this particular task, but it is set to completed.
                 // we just assume it is completed on this day.
                 if ($task['amount'] > 0) {
                     if ($task['manual_task_type'] == _TASK_TYPE_QTY_AMOUNT) {
                         $display_amount = $task['amount'] * $task['hours'];
                     } else {
                         $display_amount = $task['amount'];
                     }
                 } else {
                     $display_amount = $r['task_hours'] * $r['hourly_rate'];
                 }
                 $hours_logged = $task['hours'];
             }
             $data[$key]['amount'] += $display_amount;
             $data['total']['amount'] += $display_amount;
             $data[$key]['hours'] += $hours_logged;
             $data['total']['hours'] += $hours_logged;
             /*$hourly_rate = $r['hourly_rate'];
               if($hours_logged > 0 && $r['amount'] > 0 && $hourly_rate > 0){
                   // there is a custom amount assigned to thsi task.
                   // only calculate this amount if the full hours is complete.
                   $hourly_rate = $r['amount'] / $r['task_hours'];
               }
               if($hours_logged > 0 && $hourly_rate > 0){
                   $data[$key]['amount'] += ($hours_logged * $hourly_rate);
                   $data['total']['amount'] += ($hours_logged * $hourly_rate);
               }*/
         }
     }
     module_debug::log(array('title' => 'Finance Dashboard Invoices', 'data' => ''));
     // find invoices sent this week.
     $sql = "SELECT i.* ";
     $sql .= " FROM `" . _DB_PREFIX . "invoice` i ";
     $sql .= " LEFT JOIN `" . _DB_PREFIX . "invoice_item` ii ON i.invoice_id = ii.invoice_id ";
     if (class_exists('module_job', false)) {
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON ii.task_id = t.task_id ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` p ON t.job_id = p.job_id ";
     }
     $sql .= " WHERE (i.date_create >= '{$week_start}' AND i.date_create <= '{$week_end}')";
     $sql .= " GROUP BY i.invoice_id";
     // todo - sql in here to limit what they can see.
     $invoices = query($sql);
     // group invoices into days of the week.
     while ($invoice_data = mysql_fetch_assoc($invoices)) {
         //$invoice_data = module_invoice::get_invoice($i['invoice_id']);
         if ($invoice_data) {
             if ($multiplyer > 1) {
                 $week_day = date('w', strtotime($invoice_data['date_create'])) - 1;
                 $invoice_data['date_create'] = date('Y-m-d', strtotime('-' . $week_day . ' days', strtotime($invoice_data['date_create'])));
             }
             $key = date("Ymd", strtotime($invoice_data['date_create']));
             if (!isset($data[$key])) {
                 // for some reason we're getting results here that shouldn't be in the list
                 // for now we just skip these results until I figure out why (only had 1 guy report this error, maybe misconfig)
                 continue;
             }
             if (isset($data[$key])) {
                 $data[$key]['amount_invoiced'] += $invoice_data['c_total_amount'];
                 $data['total']['amount_invoiced'] += $invoice_data['c_total_amount'];
             }
         }
     }
     module_debug::log(array('title' => 'Finance Dashboard Finances', 'data' => ''));
     // find all payments made this week.
     // we also have to search for entries in the new "finance" table and make sure we dont double up here.
     $finance_records = module_finance::get_finances(array('date_from' => $week_start, 'date_to' => $week_end));
     foreach ($finance_records as $finance_record) {
         if (isset($finance_record['payment_type']) && ($finance_record['payment_type'] == _INVOICE_PAYMENT_TYPE_OVERPAYMENT_CREDIT || $finance_record['payment_type'] == _INVOICE_PAYMENT_TYPE_CREDIT)) {
             // CODE COPIED FROM FINANCE_LIST.PHP
             // dont add these ones to the totals on the dashboard
             continue;
         }
         if ($finance_record['credit'] > 0) {
             if ($multiplyer > 1) {
                 $week_day = date('w', strtotime($finance_record['transaction_date'])) - 1;
                 $finance_record['transaction_date'] = date('Y-m-d', strtotime('-' . $week_day . ' days', strtotime($finance_record['transaction_date'])));
             }
             $key = date("Ymd", strtotime($finance_record['transaction_date']));
             if (isset($data[$key])) {
                 $data[$key]['amount_paid'] += $finance_record['amount'];
                 $data['total']['amount_paid'] += $finance_record['amount'];
             }
         }
         if ($finance_record['debit'] > 0) {
             if ($multiplyer > 1) {
                 $week_day = date('w', strtotime($finance_record['transaction_date'])) - 1;
                 $finance_record['transaction_date'] = date('Y-m-d', strtotime('-' . $week_day . ' days', strtotime($finance_record['transaction_date'])));
             }
             $key = date("Ymd", strtotime($finance_record['transaction_date']));
             if (isset($data[$key])) {
                 $data[$key]['amount_spent'] += $finance_record['amount'];
                 $data['total']['amount_spent'] += $finance_record['amount'];
             }
         }
     }
     module_debug::log(array('title' => 'Finance Dashboard DONE!', 'data' => ''));
     /*$sql = "SELECT p.* ";
       $sql .= " FROM `"._DB_PREFIX."invoice_payment` p ";
       $sql .= " WHERE (p.date_paid >= '$week_start' AND p.date_paid <= '$week_end')";
       // todo - sql in here to limit what they can see.
       $payments = query($sql);
       // group invoices into days of the week.
       while($payment = mysql_fetch_assoc($payments)){
           //$invoice_data = module_invoice::get_invoice($i['invoice_id']);
           if($multiplyer > 1){
               $week_day = date('w',strtotime($payment['date_paid'])) - 1;
               $payment['date_paid'] = date('Y-m-d',strtotime('-'.$week_day.' days',strtotime($payment['date_paid'])));
           }
           $key = date("Ymd",strtotime($payment['date_paid']));
           if(isset($data[$key])){
               $data[$key]['amount_paid'] += $payment['amount'];
               $data['total']['amount_paid'] += $payment['amount'];
           }
       }*/
     if (class_exists('module_envato', false)) {
         $envato_currency = "USD";
         $envato = new envato_api();
         $local_currency = $envato->read_setting("local_currency", "AUD");
         $currency_convert_multiplier = $envato->currency_convert($envato_currency, $local_currency);
         // find summary of earnings between these dates in the envato statement.
         $week_start_time = strtotime($week_start);
         $week_end_time = strtotime($week_end);
         $sql = "SELECT * FROM `" . _DB_PREFIX . "envato_statement` s WHERE `time` >= '{$week_start_time}' AND `time` <= {$week_end_time}";
         $sql .= " AND ( `type` = 'sale' OR `type` = 'referral_cut' )";
         foreach (qa($sql) as $sale) {
             $sale_time = $sale['time'];
             if ($multiplyer > 1) {
                 $week_day = date('w', $sale_time) - 1;
                 $sale_time = strtotime('-' . $week_day . ' days', $sale_time);
             }
             $key = date("Ymd", $sale_time);
             if (!isset($data[$key])) {
                 continue;
             }
             $data[$key]['envato_earnings'] += round($currency_convert_multiplier * $sale['earnt'], 2);
             $data['total']['envato_earnings'] += round($currency_convert_multiplier * $sale['earnt'], 2);
             /*if($sale['type']=='sale'){
                   $sales_count++;
               }
               $sales_amount+= $sale['earnt'];*/
         }
     }
     if ($multiplyer > 1) {
         // dont want totals on previous weeks listing
         unset($data['total']);
     }
     foreach ($data as $data_id => $row) {
         //$row['amount'] = dollar($row['amount']);
         $row['chart_amount'] = $row['amount'];
         $row['amount'] = currency((int) $row['amount']);
         $row['chart_amount_invoiced'] = $row['amount_invoiced'];
         $row['amount_invoiced'] = currency((int) $row['amount_invoiced']);
         $row['chart_amount_paid'] = $row['amount_paid'];
         $row['amount_paid'] = currency((int) $row['amount_paid']);
         $row['chart_amount_spent'] = $row['amount_spent'];
         $row['amount_spent'] = currency((int) $row['amount_spent']);
         if (class_exists('module_envato', false)) {
             $row['chart_envato_earnings'] = $row['envato_earnings'];
             $row['envato_earnings'] = currency((int) $row['envato_earnings']);
         }
         // combine together
         $row['chart_hours'] = $row['hours'];
         $row['hours'] = sprintf('%s (%s)', $row['hours'], $row['amount']);
         if (is_numeric($row['day'])) {
             $time = $row['day'];
             $date = date('Y-m-d', $time);
             $row['date'] = $date;
             if ($multiplyer > 1) {
                 $date .= '|' . date('Y-m-d', strtotime('+' . $multiplyer . ' days', $time));
             }
             //$row['hours'] = '<a href="'.$base_href.'w=hours&date='.$date.'" class="summary_popup">'. _l('%s hours',$row['hours']) . '</a>';
             $row['hours_link'] = '<a href="' . $base_href . 'w=hours&date=' . $date . '" class="summary_popup">' . $row['hours'] . '</a>';
             $row['amount_link'] = '<a href="' . $base_href . 'w=hours&date=' . $date . '" class="summary_popup">' . $row['amount'] . '</a>';
             $row['amount_invoiced_link'] = '<a href="' . $base_href . 'w=amount_invoiced&date=' . $date . '" class="summary_popup">' . $row['amount_invoiced'] . '</a>';
             $row['amount_paid_link'] = '<a href="' . $base_href . 'w=amount_paid&date=' . $date . '" class="summary_popup">' . $row['amount_paid'] . '</a>';
             $row['amount_spent_link'] = '<a href="' . $base_href . 'w=amount_spent&date=' . $date . '" class="summary_popup">' . $row['amount_spent'] . '</a>';
             $row['day'] = _l(date('D', $time)) . ' ' . date('j', $time) . _l(date('S', $time));
             $row['week'] = _l(date('M', $time)) . ' ' . date('j', $time) . _l(date('S', $time));
             // if it's today.
             if ($time == strtotime(date("Y-m-d"))) {
                 $row['highlight'] = true;
             }
         } else {
         }
         $data[$data_id] = $row;
     }
     module_cache::put('finance', $cache_key, $data, $cache_timeout);
     return $data;
 }
示例#26
0
 public static function get_address($owner_id, $owner_table, $address_type, $only_address_fields = false)
 {
     if (!$owner_id) {
         return array();
     }
     $sql = "SELECT a.*, address_id AS id ";
     //$sql .= " ,s.`state`, r.`region`, c.`country` ";
     $sql .= " FROM `" . _DB_PREFIX . "address` a ";
     //        $sql .= " LEFT JOIN `"._DB_PREFIX."address_state` s ON a.state_id = s.state_id ";
     //        $sql .= " LEFT JOIN `"._DB_PREFIX."address_region` r ON a.region_id = r.region_id ";
     //        $sql .= " LEFT JOIN `"._DB_PREFIX."address_country` c ON a.country_id = c.country_id ";
     $sql .= "WHERE";
     $sql .= " a.`owner_id` = " . (int) $owner_id . "";
     $sql .= " AND a.`owner_table` = '" . mysql_real_escape_string($owner_table) . "'";
     $sql .= " AND a.`address_type` = '" . mysql_real_escape_string($address_type) . "'";
     $res = qa($sql);
     if ($res && is_array($res)) {
         $res = array_shift($res);
     } else {
         $res = false;
     }
     if ($only_address_fields) {
         $address = array();
         foreach (array('line_1', 'line_2', 'suburb', 'state', 'region', 'country', 'post_code') as $key) {
             $address[$key] = $res[$key];
         }
         return $address;
     }
     return $res;
     //		return array_shift(get_multiple("address",array('owner_id'=>$owner_id,'owner_table'=>$owner_table,'address_type'=>$address_type),"owner_id"));
 }
示例#27
0
foreach ($invoice_templates as $template_key => $tf) {
    module_template::link_open_popup($template_key);
}
$template_html = ob_get_clean();
$payment_methods_options = array();
$payment_methods = handle_hook('get_payment_methods', $module);
foreach ($payment_methods as $payment_method) {
    if ($payment_method->is_method('online') && $payment_method->is_enabled()) {
        $payment_methods_options[$payment_method->module_name] = $payment_method->get_payment_method_name();
    }
}
$settings = array(array('key' => 'overdue_email_auto', 'default' => '0', 'type' => 'checkbox', 'description' => 'Automatic Overdue Emails', 'help' => 'If this is ticked then by default newly created invoices will be sent automatic overdue notices. This can be disabled/enabled per invoice. See the "Auto Overdue Email" option near "Due Date".'), array('key' => 'invoice_automatic_receipt', 'default' => '1', 'type' => 'checkbox', 'description' => 'Automatic Send Invoice Receipt', 'help' => 'Automatically send the invoice receipt to the customer once the invoice is marked as paid. If this is disabled you will have to go into the invoice and manually send it after payment is received.'), array('key' => 'invoice_template_print_default', 'default' => 'invoice_print', 'type' => 'text', 'description' => 'Default PDF invoice template', 'help' => 'Used for invoice PDF. You can overwrite in the Advanced settings of each invoice.'), array('key' => 'overdue_email_auto_days', 'default' => '3', 'type' => 'text', 'description' => 'Automically send after', 'help' => 'How many days after the invoice is overdue is the automated email sent (set to 0 will send on the date the invoice is due)'), array('key' => 'overdue_email_auto_days_repeat', 'default' => '7', 'type' => 'text', 'description' => 'Automically re-send every', 'help' => 'How many days after the last automatic overdue reminder is the overdue reminder re-sent automatically (set to 0 to disable this option)'), array('key' => 'invoice_automatic_after_time', 'default' => '7', 'type' => 'text', 'description' => 'Hour of day to perform automatic operations', 'help' => 'Enter the hour of day (eg: 7 for 7am, 14 for 2pm) to perform automatic actions - such as renewing invoices, subscriptions, overdue notices, etc...'), array('key' => 'invoice_auto_renew_only_paid_invoices', 'default' => '1', 'type' => 'checkbox', 'description' => 'Only renew paid invoices', 'help' => 'If an invoice (or past subscription invoice) has not been paid then do not renew the next one until original payment has been received.'), array('key' => 'invoice_default_payment_method', 'default' => 'paymethod_paypal', 'type' => 'select', 'options' => $payment_methods_options, 'description' => 'Default Payment Method'), array('key' => 'invoice_due_days', 'default' => '30', 'type' => 'text', 'description' => 'Invoice Due Days', 'help' => 'The number of days used to calculate the "Due Date" on new invoices. Due Date can be overridden per invoice.'), array('key' => 'invoice_name_match_job', 'default' => '0', 'type' => 'checkbox', 'description' => 'Match Invoice with Job Name', 'help' => 'If an invoice is created from a Job, set the Invoice name the same as the job name'), array('key' => 'invoice_incrementing', 'default' => '0', 'type' => 'checkbox', 'description' => 'Incrementing Invoice Numbers', 'help' => 'If this is enabled the system will pick a new invoice number each time. Choose what number to start from below.'), array('key' => 'invoice_incrementing_next', 'default' => '1', 'type' => 'text', 'description' => 'Incrementing Invoice Number', 'help' => 'What will be the next invoice number'), array('key' => 'invoice_task_list_show_date', 'default' => '1', 'type' => 'checkbox', 'description' => 'Show Dates on Invoice Items'), array('key' => 'invoice_task_numbers', 'default' => '1', 'type' => 'checkbox', 'description' => 'Show Task Numbers on Invoice Items'), array('key' => 'invoice_allow_payment_amount_adjustment', 'default' => '1', 'type' => 'checkbox', 'description' => 'Allow User To Enter Payment Amount', 'help' => 'If this is enabled the user can change the payment amount on invoices. For example, they might want to pay $50 of a $100 invoice with PayPal, and $50 with cash.'), array('type' => 'html', 'description' => 'Templates', 'html' => $template_html));
module_config::print_settings_form(array('heading' => array('title' => 'Invoice Settings', 'type' => 'h2', 'main' => true), 'settings' => $settings));
// find any blank invoices.
$sql = "SELECT * FROM `" . _DB_PREFIX . "invoice` WHERE customer_id IS NULL AND `name` = '' AND `status` = '' AND `date_create` = '0000-00-00' AND `date_sent` = '0000-00-00' AND `date_paid` = '0000-00-00' AND `date_due` = '0000-00-00' AND c_total_amount = 0 ";
$invoices = qa($sql);
$blank_invoices = array();
foreach ($invoices as $invoice) {
    $items = module_invoice::get_invoice_items($invoice['invoice_id']);
    if (empty($items)) {
        $blank_invoices[] = $invoice;
    }
}
if (count($blank_invoices) && isset($_POST['remove_duplicates']) && $_POST['remove_duplicates'] == 'yes') {
    foreach ($blank_invoices as $id => $blank_invoice) {
        module_invoice::delete_invoice($blank_invoice['invoice_id']);
        unset($blank_invoices[$id]);
    }
}
if (count($blank_invoices)) {
    ?>
示例#28
0
 public static function get_products($search = array())
 {
     $sql = "SELECT * FROM `" . _DB_PREFIX . "product` p ";
     $sql .= " LEFT JOIN `" . _DB_PREFIX . "product_category` pc USING (product_category_id) ";
     $sql .= " WHERE 1 ";
     if (isset($search['general']) && strlen(trim($search['general']))) {
         $sql .= " AND ( p.name LIKE '%" . mysql_real_escape_string($search['general']) . "%'";
         $sql .= " OR p.description LIKE '%" . mysql_real_escape_string($search['general']) . "%'";
         $sql .= " OR pc.product_category_name LIKE '%" . mysql_real_escape_string($search['general']) . "%'";
         $sql .= " )";
     }
     if (isset($search['name']) && strlen(trim($search['name']))) {
         $sql .= " AND p.name LIKE '%" . mysql_real_escape_string($search['name']) . "%'";
     }
     if (isset($search['description']) && strlen(trim($search['description']))) {
         $sql .= " AND p.description LIKE '%" . mysql_real_escape_string($search['description']) . "%'";
     }
     if (isset($search['product_category_name']) && strlen(trim($search['product_category_name']))) {
         $sql .= " AND pc.product_category_name LIKE '%" . mysql_real_escape_string($search['product_category_name']) . "%'";
     }
     if (isset($search['product_id']) && (int) $search['product_id'] > 0) {
         $sql .= " AND p.product_id = " . (int) $search['product_id'];
     }
     if (isset($search['product_category_id']) && (int) $search['product_id'] > 0) {
         $sql .= " AND p.product_category_id = " . (int) $search['product_category_id'];
     }
     $sql .= " ORDER BY pc.product_category_name ASC, p.name ASC";
     return qa($sql);
     //return get_multiple("product",$search,"product_id","fuzzy","name");
 }
                     $newlink = preg_replace('#\\&hash=\\w+#', '&nm=', $newlink);
                     //echo "Found link: $newlink<br>\n";
                     // search for this link in the DB
                     $sql = "SELECT * FROM `" . _DB_PREFIX . "newsletter_link` WHERE send_id = " . (int) $send_id . " AND link_url = '" . mysql_real_escape_string($newlink) . "' AND (page_index = " . (int) $page_index . " OR page_index = 0)";
                     $new_count = 0;
                     foreach (qa($sql) as $db_link) {
                         $new_count += isset($links_to_process[$db_link['link_id']]) ? $links_to_process[$db_link['link_id']] : 0;
                     }
                     $old_count = isset($old_links_by_url[$newlink]) ? array_sum($old_links_by_url[$newlink]) : 0;
                     // hack to support non-ssl links when viewing from an ssl account
                     if (!$new_count && !$old_count && isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != '' && $_SERVER['HTTPS'] != 'off') {
                         $newlink_nonssl = preg_replace('#^https:#', 'http:', $newlink);
                         if ($newlink_nonssl != $newlink) {
                             $sql = "SELECT * FROM `" . _DB_PREFIX . "newsletter_link` WHERE send_id = " . (int) $send_id . " AND link_url = '" . mysql_real_escape_string($newlink_nonssl) . "' AND (page_index = " . (int) $page_index . " OR page_index = 0)";
                             $new_count = 0;
                             foreach (qa($sql) as $db_link) {
                                 $new_count += isset($links_to_process[$db_link['link_id']]) ? $links_to_process[$db_link['link_id']] : 0;
                             }
                         }
                     }
                     $content = preg_replace('/' . preg_quote($links[0][$link_match_id], '/') . '/', '<span class="newsletter-click-span">' . ($new_count ? $new_count : $old_count) . ' clicks</span>' . $links[0][$link_match_id], $content);
                     $parts[$part_id] = $content;
                     $page_index++;
                 }
             }
         }
     }
     $content = implode('', $parts);
 }
 if (preg_match_all('#<a href=["\'].*ext\\.php\\?t=lnk&id=(\\d+)&#', $content, $matches)) {
     $processed_links = array();
示例#30
0
</td>
				            <td><?php 
            echo $user['name'];
            ?>
 (<?php 
            echo $current_revision['create_ip_address'];
            ?>
)</td>
				            <td>
				            	<?php 
            if ($current_revision['number'] == 1) {
                echo 'Initial Version';
            } else {
                // find out changed fields.
                $sql = "SELECT * FROM `" . _DB_PREFIX . "data_store` WHERE data_record_revision_id = '" . $current_revision['data_record_revision_id'] . "' AND data_record_id = '" . $data_record_id . "'";
                $res = qa($sql);
                if (!count($res)) {
                    echo 'no changes';
                }
                foreach ($res as $field) {
                    //if($current_revision['data_record_revision_id'] == $view_revision_id){
                    $custom_highlight_fields[$field['data_field_id']] = true;
                    //}
                    $field_data = unserialize($field['data_field_settings']);
                    echo $field_data['title'] . ',';
                }
            }
            ?>
				            </td>
						</tr>
						</tbody>