/**
  * Returns the total rows of the presence_users table.
  * @return type Integer
  */
 protected function total()
 {
     //get the total count
     $sql = "SELECT COUNT(*) as total\n                FROM presence_users";
     $total = DB::getRecord($sql, array());
     return $total->total;
 }
Example #2
0
 function __construct($page_id, $action = false, $is_tab = false)
 {
     $this->id = $page_id;
     $this->action = $action;
     $this->is_tab = $is_tab;
     $this->page_info = DB::getRecord($this->is_tab ? 'admin_tabs' : 'admin_pages', $page_id, 0, 1);
 }
 /**
  * Returns the number of available pages for a table. 10 rows per page
  *
  * @return int $pages
  */
 public static function pages()
 {
     $sql = "SELECT COUNT(*) as count\n                FROM " . self::table();
     $total = DB::getRecord($sql, array());
     $total->count % 10 > 0 ? $rest = 1 : ($rest = 0);
     return (int) (($total->count - $total->count % 10) / 10) + $rest;
 }
 public static function get_range_total($params)
 {
     $sql = "SELECT SEC_TO_TIME(SUM(timediff)) as total\n\t\t\t\tFROM " . self::table() . "\n\t\t\t\tWHERE timestart BETWEEN ? AND ?\n                AND `userid` = ?";
     $result = DB::getRecord($sql, array(strtotime($params->dp_start), strtotime($params->dp_end), $params->user));
     $result->timestart = $params->dp_start;
     $result->timeend = $params->dp_end;
     return $result;
 }
Example #5
0
 public static function getRecord($currency_abbr = false, $currency_id = false)
 {
     if (!$currency_abbr && !$currency_id) {
         return false;
     }
     if ($currency_abbr) {
         return DB::getRecord('currencies', false, $currency_abbr, 0, 'currency');
     } elseif ($currency_id > 0) {
         return DB::getRecord('currencies', $currency_id, false, 1);
     }
 }
Example #6
0
    function display()
    {
        global $CFG;
        $tab_id = $CFG->pm_editor ? $CFG->id : Control::getPageId($CFG->url, 1);
        if (!$tab_id > 0) {
            return false;
        }
        $current_tab = DB::getRecord('admin_tabs', $tab_id, 0, 1);
        $pages = self::getPages($tab_id);
        if ($pages) {
            $HTML = '
			<div class="page_map">';
            foreach ($pages as $page) {
                if ($CFG->pm_editor) {
                    $edit = '<a href="#" title="' . $CFG->edit_hover_caption . '" class="edit" class="method_edit_button" onclick="pmPageEdit(' . $page['id'] . ',event);return false;"></a>';
                }
                $order = $page['order'];
                $icon = $page['icon'] ? '<div class="lnk">' . Link::url($page['url'], '<img src="' . $page['icon'] . '" title="' . $page['name'] . '" />', false, false, false, 'content') . '</div>' : '';
                $pages_array[$order][] = '
				<div class="page_map_page o">
					<input type="hidden" id="id" value="' . $page['id'] . '" />
					' . $icon . '
					<div class="lnk">' . Link::url($page['url'], $page['name'], false, false, false, 'content') . '</div>
					' . $edit . '
					<div class="clear"></div>
				</div>';
            }
            $total = max(array_keys($pages_array));
            $total = $total + count($this->areas_s);
            $total = $total + count($this->areas_e);
            for ($i = 0; $i <= $total; $i++) {
                if ($this->areas_s[$i]) {
                    foreach ($this->areas_s[$i] as $area) {
                        $HTML .= $area;
                    }
                }
                if ($pages_array[$i]) {
                    foreach ($pages_array[$i] as $p) {
                        $HTML .= $p;
                    }
                }
                if ($this->areas_e[$i]) {
                    foreach ($this->areas_e[$i] as $area) {
                        $HTML .= $area;
                    }
                }
            }
            $HTML .= '</div>';
        } else {
            $HTML .= '<div class="no_pages">' . $CFG->pagemap_nothing . '</div>';
        }
        echo $HTML;
    }
Example #7
0
 public static function delete($remove_id)
 {
     global $CFG;
     $remove_id = preg_replace("/[^0-9]/", "", $remove_id);
     if (!$CFG->session_active || $CFG->session_locked || !($remove_id > 0) || !$CFG->token_verified) {
         return false;
     }
     $existing = DB::getRecord('api_keys', $remove_id, 0, 1);
     if (!$existing || $existing['site_user'] != User::$info['id']) {
         continue;
     }
     return db_delete('api_keys', $remove_id);
 }
Example #8
0
 public static function getRecord($currency_abbr = false, $currency_id = false)
 {
     if (!$currency_abbr && !$currency_id) {
         return false;
     }
     $currency_id1 = preg_replace("/[^0-9]/", "", $currency_id);
     $currency_abbr1 = preg_replace("/[^a-zA-Z]/", "", $currency_abbr);
     if ($currency_abbr1) {
         return DB::getRecord('currencies', false, $currency_abbr1, 0, 'currency');
     } elseif ($currency_id1 > 0) {
         return DB::getRecord('currencies', $currency_id1, false, 1);
     }
 }
 /**
  * Validates the user, and sets the language
  *
  * @global Object $CONFIG
  * @param Array $params
  */
 private function login($params)
 {
     global $CONFIG;
     $sql = "SELECT *\n                FROM presence_users\n                WHERE `identifier` = ?\n                AND `password` = ?";
     $result = DB::getRecord($sql, array($params['identifier'], sha1($params['password'])));
     if ($result) {
         $_SESSION['user'] = $result->identifier;
         $_SESSION['role'] = $result->role;
         //set language
         $_SESSION['lang'] = $params['lang'];
         RoutingHelper::redirect($CONFIG->wwwroot . '/' . $result->role . '/activity/');
     } else {
         RoutingHelper::redirect($CONFIG->wwwroot);
     }
 }
Example #10
0
 public static function getRecord($braket_id = false, $user = false)
 {
     global $CFG;
     $braket_id = preg_replace("/[^0-9]/", "", $braket_id);
     if ($user && !$CFG->session_active) {
         return false;
     }
     if (!($braket_id > 0) && !$user) {
         return false;
     }
     if ($user) {
         $braket_id = User::$info['fee_schedule'];
     }
     return DB::getRecord('fee_schedule', $braket_id, 0, 1);
 }
Example #11
0
 function __construct($id, $table, $minimum_increase = false, $place_proxy_bids = false, $anti_sniping_window = false, $anti_sniping_increase = false, $initial_bid = false)
 {
     $this->id = $id;
     $this->table = $table;
     $this->proxy_bids = $place_proxy_bids;
     $this->anti_sniping = $anti_sniping_window;
     $this->anti_sniping_increase = $anti_sniping_increase;
     $this->minimum_increase = $minimum_increase ? $minimum_increase : 0.01;
     $this->initial_bid = $initial_bid;
     $this->item_info = DB::getRecord($this->table, $this->id, false, true);
     $this->time_remaining = Auction::getTimeRemaining();
     $this->is_expired = $this->time_remaining <= 0;
     $this->high_bid = $this->item_info['high_bid'];
     $this->high_bid_user_id = $this->item_info['high_bid_user_id'];
     $this->now = date('Y-m-d H:i:s', time());
 }
Example #12
0
 function __construct($table, $record_id)
 {
     global $CFG;
     $this->table = $table;
     $this->record_id = $CFG->include_id > 0 ? $CFG->include_id : $record_id;
     $this->row = DB::getRecord($this->table, $this->record_id, 0, 1);
     $this->db_fields = DB::getTableFields($this->table);
     $this->db_subtables = DB::getSubtables($this->table);
     $this->db_subtables = !$this->db_subtables ? array() : $this->db_subtables;
     $this->area_i = 0;
     $this->current_area = 0;
     $page_id = Control::getPageId($CFG->url, $CFG->is_tab);
     $corresponding_form = Control::getControls($page_id, 'form', $CFG->is_tab);
     if ($corresponding_form) {
         $k = key($corresponding_form);
         if ($corresponding_form[$k]['params'] = 'Form') {
             foreach ($corresponding_form[$k]['methods'] as $method) {
                 $args = Control::parseArguments($method['arguments'], 'Form', $method['method']);
                 $name = $args['name'] ? $args['name'] : $args['value'];
                 $this->form_method_args[$name] = $args;
             }
         }
     }
 }
Example #13
0
 public static function delete($id = false, $order_log_id = false)
 {
     global $CFG;
     $id = preg_replace("/[^0-9]/", "", $id);
     $order_log_id = preg_replace("/[^0-9]/", "", $order_log_id);
     if (!($id > 0)) {
         $id = $order_log_id;
     }
     if (!($id > 0)) {
         return false;
     }
     if (!$CFG->session_active) {
         return false;
     }
     if (!$order_log_id) {
         $del_order = DB::getRecord('orders', $id, 0, 1);
     } else {
         $del_order = self::getRecord(false, $order_log_id);
     }
     if (!$del_order) {
         return array('error' => array('message' => 'Order not found.', 'code' => 'ORDER_NOT_FOUND'));
     }
     if ($del_order['site_user'] != User::$info['id']) {
         return array('error' => array('message' => 'User mismatch.', 'code' => 'AUTH_NOT_AUTHORIZED'));
     }
     self::setStatus(false, 'CANCELLED_USER', $del_order['log_id'], $del_order['btc']);
     db_delete('orders', $del_order['id']);
     return self::getStatus($del_order['log_id']);
 }
Example #14
0
								<div class="tr1_shadow"></div>
								<div class="tr2_shadow"></div>
								<div class="bl1_shadow"></div>
								<div class="bl2_shadow"></div>
								<div class="br1_shadow"></div>
								<div class="br2_shadow"></div>
								<div class="clear"></div>
							</div>
						</div>';
                    }
                    echo '
					</div>';
                }
            }
        } else {
            $page_info = DB::getRecord($CFG->is_tab ? 'admin_tabs' : 'admin_pages', $CFG->id, 0, 1);
            if (!$page_info['is_ctrl_panel'] || $page_info['is_ctrl_panel'] == 'N') {
                echo '
				<div class="menu_item"><a class="' . (!$CFG->action ? 'high' : false) . '" href="#">' . $CFG->pm_list_tab . '</a></div>
				<div class="menu_item"><a class="' . ($CFG->action == 'form' ? 'high' : false) . '" href="#">' . $CFG->pm_form_tab . '</a></div>
				<div class="menu_item"><a class="' . ($CFG->action == 'record' ? 'high' : false) . '" href="#">' . $CFG->pm_record_tab . '</a></div>';
            } else {
                echo '
				<div class="menu_item"><a class="' . (!$CFG->action ? 'high' : false) . '" href="#">' . $CFG->pm_ctrl_tab . '</a></div>';
            }
            echo '
			<div class="pm_nav">';
            PageMaker::showTabsPages();
            echo '
				<div class="pm_exit"><div class="pm_exit_icon" onclick="pmExitEditor();"></div> <a href="index.php" onclick="pmExitEditor();return false;">' . $CFG->pm_exit . '</a></div>
			</div>';
Example #15
0
    private function show($comments)
    {
        global $CFG;
        if ($comments) {
            echo '<ul>';
            foreach ($comments as $comment) {
                $elapsed = time() + Settings::mysqlTimeDiff() * 3600 - strtotime($comment['date']);
                if ($elapsed < 60) {
                    $time_ago = $CFG->comments_less_than_minute;
                } elseif ($elapsed > 60 && $elapsed < 60 * 60) {
                    $minutes = floor($elapsed / 60);
                    $time_ago = str_ireplace('[field]', $minutes, $CFG->comments_minutes_ago);
                } elseif ($elapsed > 60 * 60 && $elapsed < 60 * 60 * 24) {
                    $hours = floor($elapsed / 60 / 60);
                    $time_ago = str_ireplace('[field]', $hours, $CFG->comments_hours_ago);
                } elseif ($elapsed > 60 * 60 * 24 && $elapsed < 60 * 60 * 24 * 30.4) {
                    $days = floor($elapsed / 60 / 60 / 24);
                    $time_ago = str_ireplace('[field]', $days, $CFG->comments_days_ago);
                } else {
                    $months = floor($elapsed / 60 / 60 / 24 / 30.4);
                    $time_ago = str_ireplace('[field]', $months, $CFG->comments_months_ago);
                }
                if ($comment['user_id'] > 0) {
                    $user = DB::getRecord($this->user_table, $comment['user_id'], false, true);
                    $name = !empty($comment['website']) ? Link::url($comment['website'], $user['user']) : $user['user'];
                } else {
                    $name = !empty($comment['website']) ? Link::url($comment['website'], $comment['name']) : $comment['name'];
                }
                $short = $this->short_version ? '_short' : '';
                $icon = $comment['type'] ? eval('return $CFG->comment_type_' . $comment['type'] . ';') : $CFG->comment_type_1;
                $action = $comment['type'] ? eval('return $CFG->comments_action_' . $comment['type'] . $short . ';') : $CFG->comments_wrote_label;
                $action = String::doFormulaReplacements($action, unserialize($comment['f_table_row']), 1, 1);
                echo '
				<li id="comment_' . $comment['id'] . '" class="level_' . $comment['type'] . '">
					<div class="c_head">';
                if ($this->fields) {
                    foreach ($this->fields as $f_name => $field) {
                        $CFG->o_method_id = $field['method_id'];
                        $CFG->o_method_name = 'field';
                        $record = new Record($field['table'], $comment['record_id']);
                        echo '<div class="added_field">' . $record->field($field['name'], $field['caption'], $field['subtable'], $field['subtable_fields'], $field['link_url'], $field['concat_char'], true, $field['f_id_field'], $field['order_by'], $field['order_asc'], $comment['record_id'], $field['link_is_tab'], $field['limit_is_curdate'], false, $field['link_id_field']) . '</div>';
                    }
                }
                echo '
						' . $icon . ' ' . $name . ' (' . $time_ago . ') ' . $action . '
					</div>';
                if (!$this->short_version) {
                    echo '
						<div class="c_comment">
							' . (strlen($comment['comments']) != strlen(strip_tags($comment['comments'])) ? $comment['comments'] : nl2br($comment['comments'])) . '
						</div>';
                }
                echo '
					' . ($comment['type'] <= 1 && !$this->short_version ? '<div class="c_reply"><a href="#" onclick="showReplyBox(' . $comment['id'] . ',' . $this->i . ');return false;">' . $CFG->comments_reply_label . '</a></div>' : '') . '
					<div class="c_form"></div>
				</li>';
                if (is_array($comment['children'])) {
                    Comments::show($comment['children']);
                }
            }
            echo '<div style="clear:both;height:0;"></div></ul>';
        }
    }
Example #16
0
             $image_sizes = DB::getImageSizes($args['name']);
             end($image_sizes);
             $suffixes[$args['name']] = key($image_sizes);
         }
     }
 }
 $filename = $CFG->dirroot . $CFG->temp_file_location . 'archivos_' . date('Y-m-d') . '.zip';
 $zip = new ZipArchive();
 $res = $zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
 if ($res) {
     foreach ($_REQUEST['download'] as $table => $ids) {
         $record_ids = explode('|', $ids);
         $table_fields = explode('|', $_REQUEST['table_fields']);
         if (is_array($record_ids)) {
             foreach ($record_ids as $id) {
                 $record = DB::getRecord($_REQUEST['current_url'], $id);
                 $files = DB::getFiles($_REQUEST['current_url'] . '_files', $id);
                 if ($files) {
                     $i = 1;
                     foreach ($files as $row) {
                         $i = $name_in_zip != $old_name ? 1 : $i;
                         $f_name = $row['field_name'];
                         $suffix = '_' . $suffixes[$f_name];
                         $row['name'] = $row['name'] ? $row['name'] : $row['f_id'] . '_' . $row['id'];
                         $url = File::fileExists($row['name'] . $suffix . '.' . $row['ext'], $CFG->default_upload_location, $_REQUEST['current_url']);
                         if (!$url) {
                             $url = File::fileExists($row['f_id'] . '_' . $row['id'] . '.' . $row['ext'], $CFG->default_upload_location, $_REQUEST['current_url']);
                         }
                         if ($url) {
                             $name_parts = array();
                             if ($table_fields) {
Example #17
0
 function delete($item_id, $item_table, $table = false)
 {
     global $CFG;
     $table = $table ? $table : 'cart';
     $item = DB::getRecord($item_table, $item_id, false, true);
     $item_name = $item['name'];
     if (User::isLoggedIn()) {
         $result = getItem($item_id, $item_table, $table);
         if ($result) {
             DB::delete($result['id']);
             $messages[$item_name] = $CFG->cart_delete_message;
             Messages::merge($messages);
         }
     } else {
         unset($_SESSION['cart'][$item_table . '_' . $item_id]);
         $messages[$item_name] = $CFG->cart_delete_message;
         Messages::merge($messages);
     }
 }
Example #18
0
 public static function emailValidate($authcode)
 {
     global $CFG;
     if (!$CFG->session_active) {
         return false;
     }
     $authcode = Encryption::decrypt(urldecode($authcode));
     if (!$authcode) {
         return false;
     }
     $authcode = preg_replace("/[^0-9a-zA-Z]/", "", $authcode);
     if (!$authcode) {
         return false;
     }
     $sql = 'SELECT * FROM requests WHERE email_token = "' . $authcode . '"';
     $result = db_query_array($sql);
     if (!$result) {
         return false;
     }
     $request = $result[0];
     if ($request['request_status'] != $CFG->request_awaiting_id) {
         return false;
     }
     if (User::$info['notify_withdraw_bank'] == 'Y') {
         $currency_info = DB::getRecord('currencies', $request['currency'], 0, 1);
         $info['amount'] = $request['amount'];
         $info['currency'] = $currency_info['currency'];
         $info['first_name'] = User::$info['first_name'];
         $info['last_name'] = User::$info['last_name'];
         $info['id'] = $request['id'];
         $email = SiteEmail::getRecord('new-withdrawal');
         Email::send($CFG->form_email, User::$info['email'], str_replace('[amount]', number_format($request['amount'], 2), str_replace('[currency]', $currency_info['currency'], $email['title'])), $CFG->form_email_from, false, $email['content'], $info);
     }
     return db_update('requests', $request['id'], array('request_status' => $CFG->request_pending_id));
 }
Example #19
0
 protected function get_userid($token)
 {
     $sql = "SELECT userid\n                FROM presence_auth pa\n                WHERE pa.token = ?";
     $user = DB::getRecord($sql, array($token));
     return $user->userid;
 }
Example #20
0
                $errors[] = $CFG->ajax_insert_error;
            }
        }
    }
} elseif ($_REQUEST['delete']) {
}
if ($_REQUEST['l_order'] && is_array($_REQUEST['l_order'])) {
    foreach ($_REQUEST['l_order'] as $table => $items) {
        $table_fields = DB::getTableFields($table, true);
        if (!in_array('order', $table_fields)) {
            continue;
        }
        $i = 0;
        foreach ($items as $order => $id) {
            if (in_array('page_map_reorders', $table_fields) && $table == 'admin_pages') {
                $rec = DB::getRecord('admin_pages', $id, 0, 1);
                if ($rec['page_map_reorders'] > 0) {
                    continue;
                }
            }
            DB::update($table, array('order' => $i), $id);
            $i++;
        }
    }
}
if (is_array($_REQUEST['page_map'])) {
    if (is_array($_REQUEST['page_map']['methods'])) {
        foreach ($_REQUEST['page_map']['methods'] as $order => $id) {
            DB::update('admin_controls_methods', array('order' => $order), $id);
        }
    }
Example #21
0
$result = db_query_array($sql);
if ($result) {
    foreach ($result as $row) {
        $ledger[$row['currency_abbr']] = $row;
    }
}
// get total currency conversion commision in usd
$sql = 'SELECT SUM(conversions.profit_to_factor * currencies.usd_ask) AS conversion_fees FROM conversions LEFT JOIN currencies ON (currencies.id = conversions.currency) WHERE conversions.is_active = "Y" AND factored != "Y"';
$result = db_query_array($sql);
$conversion_fees = $result[0]['conversion_fees'];
// close this month's currency ledger
$sql = 'UPDATE conversions SET factored = "Y" WHERE conversions.is_active = "Y" AND factored != "Y"';
db_query($sql);
// move factored profits to individual currency escrows (these tell you how much of each currency you can safely withdraw as profit)
// create new ledger entries for next month
$status = DB::getRecord('status', 1, 0, 1, false, false, false, 1);
if (!empty($ledger)) {
    foreach ($ledger as $currency_abbr => $row) {
        $escrows[] = strtolower($currency_abbr) . '_escrow = ' . ($row['profit_to_factor'] + $status[strtolower($currency_abbr) . '_escrow']) . ' ';
        db_insert('conversions', array('amount' => $row['amount'] - $row['profit_to_factor'], 'total_withdrawals' => '0', 'date' => date('Y-m-d H:i:s'), 'date1' => date('Y-m-d H:i:s'), 'currency' => $row['currency'], 'is_active' => 'N', 'factored' => 'N'));
    }
    $sql = 'UPDATE `status` SET ' . implode(',', $escrows) . ' WHERE id = 1';
    db_query($sql);
}
// get fees incurred from the Bitcoin network for internal movements
$sql = 'SELECT SUM(fees.fee * currencies.usd_ask) AS fees_incurred FROM fees LEFT JOIN currencies ON (currencies.id = 28) WHERE MONTH(fees.date) = MONTH(CURDATE() - INTERVAL 1 MONTH) AND YEAR(fees.date) = YEAR(CURDATE() - INTERVAL 1 MONTH)';
$result = db_query_array($sql);
$gross_profit = $total_fees - $result[0]['fees_incurred'];
db_insert('monthly_reports', array('date' => date('Y-m-d', strtotime('-1 day')), 'transactions_btc' => $transactions_btc, 'avg_transaction_size_btc' => $avg_transaction, 'transaction_volume_per_user' => $trans_per_user, 'total_fees_btc' => $total_fees, 'fees_per_user_btc' => $fees_per_user, 'gross_profit_btc' => $gross_profit));
db_update('status', 1, array('cron_monthly_stats' => date('Y-m-d H:i:s')));
echo 'done' . PHP_EOL;
Example #22
0
 public static function getHotWallet()
 {
     global $CFG;
     if (!$CFG->session_active) {
         return false;
     }
     $sql = "SELECT * FROM bitcoin_addresses WHERE system_address = 'Y' AND hot_wallet = 'Y' ORDER BY `date` ASC LIMIT 0,1";
     $result = db_query_array($sql);
     if ($result[0]) {
         return $result[0];
     } else {
         $new_id = self::getNew(1);
         return DB::getRecord('bitcoin_addresses', $new_id, 0, 1);
     }
 }
Example #23
0
     $currency_info = $currencies[strtoupper($data[3])];
 } else {
     continue;
 }
 $sql = 'SELECT site_users_balances.id AS balance_id, site_users.id AS site_user, site_users_balances.balance AS cur_balance, site_users.notify_deposit_bank AS notify_deposit_bank, site_users.first_name AS first_name, site_users.last_name AS last_name, site_users.email AS email, site_users.last_lang AS last_lang FROM site_users LEFT JOIN site_users_balances ON (site_users_balances.site_user = site_users.id AND site_users_balances.currency = ' . $currency_info['id'] . ') WHERE site_users.user = '******' FOR UPDATE';
 $result = db_query_array($sql);
 if ($result) {
     $balance_record = false;
     if ($result[0]['balance_id'] > 0) {
         $balance_record = DB::getRecord('site_users_balances', $result[0]['balance_id'], 0, 1);
     }
     if ($balance_record) {
         db_update('site_users_balances', $result[0]['balance_id'], array('balance' => number_format($result[0]['cur_balance'] + $data[2])));
     } else {
         $balance_id = db_insert('site_users_balances', array('balance' => number_format($data[2]), 'site_user' => $result[0]['site_user'], 'currency' => $currency_info['id']));
         $balance_record = DB::getRecord('site_users_balances', $balance_id, 0, 1);
         $result[0]['balance_id'] = $balance_record['id'];
         $result[0]['cur_balance'] = 0;
     }
     $insert_id = db_insert('requests', array('date' => date('Y-m-d H:i:s'), 'site_user' => $result[0]['site_user'], 'currency' => $currency_info['id'], 'amount' => number_format($data[2], 2, '.', ''), 'description' => $CFG->deposit_fiat_desc, 'request_type' => $CFG->request_deposit_id, 'request_status' => $CFG->request_completed_id, 'account' => $data[4], 'crypto_id' => $data[0]));
     db_insert('history', array('date' => date('Y-m-d H:i:s'), 'history_action' => 4, 'site_user' => $result[0]['site_user'], 'request_id' => $insert_id, 'balance_before' => $result[0]['cur_balance'], 'balance_after' => $result[0]['cur_balance'] + $data[2]));
     if ($result[0]['notify_deposit_bank'] == 'Y') {
         $result[0]['amount'] = number_format($data[2], 2, '.', '');
         $result[0]['id'] = $insert_id;
         $CFG->language = $result[0]['last_lang'] ? $result[0]['last_lang'] : 'en';
         $email = SiteEmail::getRecord('new-deposit');
         Email::send($CFG->form_email, $result[0]['email'], str_replace('[amount]', number_format($data[2], 2), str_replace('[currency]', $currency_info['currency'], $email['title'])), $CFG->form_email_from, false, $email['content'], $result[0]);
     }
     $transactions++;
 } else {
     $insert_id = db_insert('requests', array('date' => date('Y-m-d H:i:s'), 'site_user' => $result[0]['site_user'], 'currency' => $currency_info['id'], 'amount' => number_format($data[2], 2, '.', ''), 'description' => $CFG->deposit_fiat_desc, 'request_type' => $CFG->request_deposit_id, 'request_status' => $CFG->request_cancelled_id, 'account' => $data[4], 'crypto_id' => $data[0]));
Example #24
0
 function save()
 {
     global $CFG;
     if ($_REQUEST['bypass_save'] || $CFG->save_called || strstr($_REQUEST['form_name'], 'form_filters')) {
         return false;
     }
     $this->save_called = true;
     $CFG->save_called = true;
     if (!$this->get_called && $this->record_id > 0) {
         if (!is_array(self::$old_info_prev)) {
             $this->old_info = DB::getRecord($this->table, $this->record_id, 0, 1);
             self::$old_info_prev = $this->old_info;
         } else {
             $this->old_info = self::$old_info_prev;
         }
         $subtables = DB::getSubtables($this->name);
         if (is_array($subtables)) {
             foreach ($subtables as $subtable) {
                 if (!DB::tableExists($this->table . '_' . $subtable)) {
                     continue;
                 }
                 if (strstr($subtable, 'grid_')) {
                     $name_parts = explode('grid_', $subtable);
                     $name = $name_parts[1];
                     $this->old_info[$name] = DB::getGridValues($this->table . '_grid_' . $name, $subtable_fields, $this->record_id);
                 } elseif (strstr($subtable, 'files')) {
                     //$files = DB::getFiles($this->table.'_files',$this->record_id);
                 } else {
                     if ($this->info['cat_selects']) {
                         $cats = DB::getCats($this->table . '_' . $subtable, $this->record_id);
                         if ($cats) {
                             foreach ($cats as $cat) {
                                 $this->old_info['cat_selects'][$subtable][] = $cat['row']['c_id'];
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($_FILES[$this->name]['name']) {
         foreach ($_FILES[$this->name]['name'] as $input_name => $file_name) {
             if ($file_name) {
                 $temp_files[] = Upload::saveTemp($this->name, $input_name);
             }
         }
         if (is_array($temp_files)) {
             foreach ($temp_files as $file_info) {
                 $field_name = $file_info['input_name'];
                 if ($file_info['error']) {
                     $this->errors[$field_name] = $file_info['error'];
                 } else {
                     $this->temp_files[$field_name] = $file_info['filename'];
                     $CFG->temp_files[$field_name] = $file_info['filename'];
                     $this->temp_descs[$field_name] = $file_info['file_desc'];
                 }
             }
         }
     }
 }
Example #25
0
 function getCountry($country_id)
 {
     return DB::getRecord('iso_countries', $country_id, 0, 1);
 }
Example #26
0
    function display($page = 0)
    {
        global $CFG;
        $filters = self::getFilterResults();
        $page = $page > 0 ? $page : $_SESSION['page' . $this->i];
        $_SESSION['page' . $this->i] = $page;
        $page = !($page > 0) || $_REQUEST['submit'] || $this->order_asc_changed || $this->order_by_changed ? 1 : $page;
        $fields = DB::getTableFields($this->table);
        $total_rows = DB::get($this->table, $this->fields, $page, $this->rows_per_page, $this->order_by, $this->order_asc, 1, $filters, $this->inset_id, $this->inset_id_field, false, false, false, false, false, false, false, $this->sql_filter, $this->group_by, $this->no_group_by);
        $data = DB::get($this->table, $this->fields, $page, $this->rows_per_page, $this->order_by, $this->order_asc, 0, $filters, $this->inset_id, $this->inset_id_field, false, false, false, false, false, false, false, $this->sql_filter, $this->group_by, $this->no_group_by);
        $HTML = "";
        if ($CFG->backstage_mode && User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1 && $this->inset_id === false) {
            $HTML .= '
			<form id="grid_form_' . $this->table . $this->i . '" name="grid_form_' . $this->table . $this->i . '" action="' . $CFG->self . '" method="POST">
				<input type="hidden" name="current_url" value="' . $CFG->url . '" />
				<input type="hidden" name="action" value="" />
				<input type="hidden" name="return_to_self" value="1" />';
            if (is_array($this->fields)) {
                foreach ($this->fields as $properties) {
                    if ($properties['aggregate_function']) {
                        $i_name = $properties['name'];
                        switch ($properties['aggregate_function']) {
                            case 'grand_total':
                                $grand_total[$i_name] = 0;
                                break;
                            case 'page_total':
                                $page_total[$i_name] = 0;
                                break;
                            case 'grand_avg':
                                $grand_avg[$i_name] = array();
                                break;
                            case 'page_avg':
                                $page_avg[$i_name] = array();
                                break;
                            case 'both_total':
                                $page_total[$i_name] = 0;
                                $grand_total[$i_name] = 0;
                                break;
                            case 'both_avg':
                                $page_avg[$i_name] = array();
                                $grand_avg[$i_name] = array();
                                break;
                        }
                    }
                }
            }
            if (is_array($this->fields)) {
                foreach ($this->fields as $properties) {
                    if ($properties['cumulative_function']) {
                        $i_name = $properties['name'];
                        if ($properties['cumulative_function'] == 'sum') {
                            $page_total[$i_name] = 0;
                            if ($grand_total) {
                                $grand_total[$i_name] = 0;
                            }
                        } elseif ($properties['cumulative_function'] == 'avg') {
                            $page_avg[$i_name] = array();
                            if ($grand_avg) {
                                $grand_avg[$i_name] = array();
                            }
                        }
                    }
                }
            }
        }
        if ($this->mode == 'list') {
            $HTML .= "<ul class=\"grid_list\">";
            if (is_array($data)) {
                $j = 0;
                foreach ($data as $row) {
                    $HTML .= "<li><ul>";
                    if (is_array($this->fields)) {
                        foreach ($this->fields as $name => $properties) {
                            $key = $name;
                            if (strstr($name, 'lll')) {
                                $name_parts = explode('lll', $name);
                                $name = $name_parts[0];
                            }
                            if ($this->inset_id > 0 && $name == $this->inset_id_field) {
                                continue;
                            }
                            $value = $row[$key];
                            $link_id = $row[$name . '_id'] ? $row[$name . '_id'] : $value;
                            $class = $properties['class'] ? "class=\"{$properties['class']}\"" : '';
                            if ($CFG->pm_editor) {
                                $method_name = Form::peLabel($properties['method_id'], 'field');
                            }
                            $HTML .= "<li {$class}>" . $method_name . "";
                            if (!empty($properties['is_media'])) {
                                reset($CFG->image_sizes);
                                $m_values = explode('|||', $value);
                                $m_size = !empty($properties['media_size']) ? $properties['media_size'] : key($CFG->image_sizes);
                                $m_limit = !empty($properties['media_amount']) ? $properties['media_amount'] : 1;
                                $HTML .= Gallery::multiple($properties['subtable'], $row['id'], $properties['name'], $properties['media_size'], 0, false, $properties['media_amount'], false, false, true);
                                $HTML .= '<div class="clear"></div>';
                            } else {
                                if ($fields[$name]['Type'] == 'datetime' || @in_array($name, $foreign_dates)) {
                                    $value = date($CFG->default_date_format, strtotime($value));
                                } elseif ($fields[$name]['Type'] == "enum('Y','N')") {
                                    $value = $value == 'Y' ? '<div class="y_icon"></div>' : '<div class="n_icon"></div>';
                                }
                                if ($value['filter']) {
                                    $order_asc = $this->order_asc ? false : true;
                                    if ($this->order_by == $name) {
                                        $dir_img = $this->order_asc ? $CFG->up : $CFG->down;
                                    } else {
                                        $dir_img = false;
                                    }
                                    $HTML .= '<b>' . Link::url($this->link_url, $properties['header_caption'] . $dir_img, "filter{$this->i}={$name}&order_by{$this->i}={$this->order_by}&order_asc{$this->i}={$order_asc}&is_tab={$this->is_tab}", $this->filter_results, false, 'content') . ':</b> ';
                                } else {
                                    $HTML .= $this->show_list_captions ? '<b>' . $properties['header_caption'] . ':</b> ' : '';
                                }
                                if (empty($properties['link_url'])) {
                                    $HTML .= str_ireplace('|||', ' ', $value);
                                } else {
                                    $action = $CFG->backstage_mode ? '&action=record' : '';
                                    $value = str_replace('|||', ' ', $value);
                                    if (!empty($value)) {
                                        $HTML .= Link::url($properties['link_url'], $value, "id={$link_id}&is_tab={$properties['link_is_tab']}{$action}", false, false, $this->target_elem_id);
                                    }
                                }
                                if (is_array($page_total)) {
                                    if (array_key_exists($name, $page_total)) {
                                        $page_total[$name] += $value;
                                    }
                                }
                                if (is_array($page_avg)) {
                                    if (array_key_exists($name, $page_avg)) {
                                        $page_avg[$name][] = $value;
                                    }
                                }
                            }
                            $HTML .= "</li>";
                        }
                    }
                    if ($this->show_buttons) {
                        $HTML .= '<li><nobr>' . ($CFG->backstage_mode ? "<span><label for=\"{$row['id']}\">Select:</label><input id=\"{$row['id']}\" type=\"checkbox\" value=\"{$row['id']}\" class=\"grid_select checkbox_input\"/></span>" : '');
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 0) {
                            $HTML .= Link::url($this->link_url, false, 'id=' . $row['id'] . '&action=record&is_tab=' . $this->is_tab, false, false, $this->target_elem_id, 'view', false, false, false, false, $CFG->view_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1) {
                            $HTML .= Link::url($this->link_url, false, 'id=' . $row['id'] . '&action=form&is_tab=' . $this->is_tab, false, false, $this->target_elem_id, 'edit', false, false, false, false, $CFG->edit_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1) {
                            $HTML .= '<a href="#" class="delete" title="' . $CFG->delete_hover_caption . '" onclick="gridDelete(' . $row['id'] . ',\'' . $this->table . '\',this)"></a></li>';
                        }
                    }
                    $HTML .= '</nobr></li></ul>';
                    $j++;
                }
            } else {
                $HTML .= '<li>' . $CFG->grid_no_results . '</li>';
            }
            $HTML .= "</ul>";
        } elseif ($this->mode == 'graph' || $this->mode == 'graph_line' || $this->mode == 'graph_pie') {
            $name_column = $this->graph_name_column;
            $y_axis = $this->graph_value_column;
            $x_axis = $this->graph_x_axis;
            if (is_array($this->fields)) {
                foreach ($this->fields as $name => $properties) {
                    if (strstr($fields[$name]['Type'], 'varchar') || !$properties['is_op'] && !empty($properties['subtable'])) {
                        if (!$name_column) {
                            $name_column = $name;
                        }
                        $this->name_columns[$name] = $properties['header_caption'];
                    } elseif (strstr($fields[$name]['Type'], 'date')) {
                        if (!$x_axis) {
                            $x_axis = $name;
                        }
                        $this->x_columns[$name] = $properties['header_caption'];
                    } elseif (($properties['is_op'] || strstr($fields[$name]['Type'], 'int') || strstr($fields[$name]['Type'], 'double')) && $name != 'id' && empty($properties['subtable'])) {
                        if (!$y_axis) {
                            $y_axis = $name;
                        }
                        $this->value_columns[$name] = $properties['header_caption'];
                    }
                }
            }
            if ($data) {
                foreach ($data as $row) {
                    $x_values[] = strtotime($row[$x_axis]);
                    $y_values[] = $row[$y_axis];
                }
                $days = (max($x_values) - min($x_values)) / 86400;
                $max_x = max($x_values);
                $min_x = min($x_values);
                $timestamp = $min_x;
                if ($days <= 30) {
                    $time_unit = 'days';
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp += 86400;
                    }
                } elseif ($days > 30 && $days <= 183) {
                    $time_unit = 'weeks';
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp += 86400 * 7;
                    }
                } elseif ($days > 183 && $days <= 910) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 1 month')));
                    }
                } elseif ($days > 910 && $days <= 1820) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 2 months')));
                    }
                } elseif ($days > 1820 && $days <= 3640) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 4 months')));
                    }
                } elseif ($days > 3640 && $days <= 7280) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 6 months')));
                    }
                } elseif ($days > 7280 && $days <= 14560) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 8 months')));
                    }
                } elseif ($days > 14560 && $days <= 29120) {
                    $time_unit = 'months';
                    $timestamp = strtotime(date('n/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('n/1/Y', strtotime($p_name . ' + 10 months')));
                    }
                } elseif ($days > 29120 && $days <= 58240) {
                    $time_unit = 'years';
                    $timestamp = strtotime(date('1/1/Y', $min_x));
                    while ($timestamp <= $max_x) {
                        $time_units[] = $timestamp;
                        $timestamp = strtotime(date('1/1/Y', strtotime($p_name . ' + 1 year')));
                    }
                }
                $reps = 0;
                foreach ($data as $row) {
                    if (is_array($this->fields)) {
                        $name_value = $this->graph_combine != 'Y' ? $row[$name_column] : 'All';
                        $c_units = count($time_units);
                        $x_val = strtotime($row[$x_axis]);
                        for ($i = 0; $i < $c_units; $i++) {
                            if ($x_val >= $time_units[$i] && ($x_val < $time_units[$i + 1] || !$time_units[$i + 1])) {
                                $x_current = $time_units[$i];
                                break;
                            }
                        }
                        $key = $x_current;
                        if ($x_prev != $x_current) {
                            $y_current = false;
                            $reps = 0;
                        }
                        if ($this->fields[$y_axis]['is_op'] && !$this->fields[$y_axis]['run_in_sql']) {
                            $y_current = self::doOperation($y_axis, $this->fields[$y_axis], $row, $name_value);
                        } else {
                            $y_current = $y_current + $row[$y_axis];
                        }
                        $x_prev = $x_current;
                        if ($this->mode != 'graph_pie') {
                            if (!$graph_data[$name_value][$key]) {
                                $graph_data[$name_value][$key] = $y_current;
                            } else {
                                if ($this->fields[$y_axis]['cumulative_function'] == 'avg') {
                                    $graph_data[$name_value][$key] = ($graph_data[$name_value][$key] + $y_current) / $reps;
                                } else {
                                    $graph_data[$name_value][$key] += $y_current;
                                }
                            }
                        } else {
                            if (!$graph_data[1][$name_value]) {
                                $graph_data[1][$name_value] = $y_current;
                            } else {
                                if ($this->fields[$y_axis]['cumulative_function'] == 'avg') {
                                    $graph_data[1][$name_value] = ($graph_data[1][$name_value] + $y_current) / $reps;
                                } else {
                                    $graph_data[1][$name_value] += $y_current;
                                }
                            }
                        }
                        $titles[$name_value] = $name_value;
                        $reps++;
                    }
                }
                if ($this->mode != 'graph_pie') {
                    foreach ($graph_data as $name_value => $val) {
                        $last_value = 0;
                        foreach ($time_units as $unit) {
                            $key = $unit;
                            if (!array_key_exists($key, $graph_data[$name_value])) {
                                if (!empty($this->fields[$y_axis]['cumulative_function'])) {
                                    $graph_data[$name_value][$key] = $last_value;
                                } else {
                                    $graph_data[$name_value][$key] = 0;
                                }
                            } else {
                                $last_value = $graph_data[$name_value][$key];
                            }
                        }
                    }
                    foreach ($graph_data as $name_value => $val) {
                        ksort($graph_data[$name_value]);
                        $last_value = 0;
                        foreach ($graph_data[$name_value] as $key => $val) {
                            if ($time_unit == 'days' || $time_unit == 'weeks') {
                                $key1 = date('M j', $key);
                            } elseif ($time_unit == 'months') {
                                $key1 = date('M', $key);
                            } elseif ($time_unit == 'years') {
                                $key1 = date('Y', $key);
                            }
                            $graph_data1[$name_value][$key1] = $val;
                        }
                    }
                } else {
                    $graph_data1 = $graph_data;
                }
            }
            $HTML .= '<img class="graph" src="includes/graph.php?graph_data=' . urlencode(serialize($graph_data1)) . '&titles=' . urlencode(serialize($titles)) . '&mode=' . $this->mode . '">';
        } else {
            $HTML .= "<table><tr class=\"grid_header\">";
            if ($CFG->backstage_mode && !$this->links_out && $this->show_buttons && $CFG->is_ctrl_panel != 'Y') {
                $HTML .= "<th><label for=\"grid_select{$this->i}\"/><input id=\"grid_select{$this->i}\" type=\"checkbox\" class=\"grid_select checkbox_input\" onclick=\"gridSelectAll(this)\"/></th>";
            }
            if (is_array($this->fields)) {
                foreach ($this->fields as $name => $value) {
                    $key = $name;
                    if (strstr($name, 'lll')) {
                        $name_parts = explode('lll', $name);
                        $name = $name_parts[0];
                    }
                    if ($this->inset_id > 0) {
                        if ($value['name'] == $this->inset_id_field) {
                            continue;
                        }
                        if (strstr($this->inset_id_field, '.')) {
                            $inset_field_parts = explode('.', $this->inset_id_field);
                            if ($value['subtable'] == $inset_field_parts[0] && (in_array($inset_field_parts[1], $value['subtable_fields']) || $inset_field_parts[1] == 'id')) {
                                continue;
                            }
                        }
                    }
                    if ($value['is_op'] && !$value['run_in_sql']) {
                        if ($CFG->pm_editor) {
                            $method_name = Form::peLabel($value['method_id'], 'aggregate');
                        }
                        $HTML .= "<th>" . $value['header_caption'] . $method_name . '</th>';
                        continue;
                    } elseif ($value['is_form']) {
                        if ($CFG->pm_editor) {
                            $method_name = Form::peLabel($value['method_id'], 'inlineForm');
                        }
                        if ($value['header_caption']) {
                            $HTML .= "<th class=\"multiple_input\">" . $value['header_caption'] . $method_name . '</th>';
                        }
                        continue;
                    }
                    if ($CFG->pm_editor) {
                        $method_name = !$value['run_in_sql'] ? Form::peLabel($value['method_id'], 'field') : Form::peLabel($value['method_id'], 'aggregate');
                    }
                    if ($value['filter']) {
                        $order_asc = $this->order_asc ? false : true;
                        if ($this->order_by == $name) {
                            $dir_img = $this->order_asc ? $CFG->up : $CFG->down;
                        } else {
                            $dir_img = false;
                        }
                        $filter_results = $_REQUEST['form_filters' . $this->i];
                        $HTML .= "<th>" . Link::url($CFG->url, $value['header_caption'] . $dir_img, false, array('filter' . $this->i => $name, 'order_by' . $this->i => $this->order_by, 'order_asc' . $this->i => $order_asc, 'is_tab' => $this->is_tab, 'inset_id' => $this->inset_id, 'inset_id_field' => $this->inset_id_field, 'inset_i' => $this->inset_i, 'form_filters' . $this->i => $filter_results, 'search_fields' . $this->i => $_REQUEST['search_fields' . $this->i]), false, false, $this->inset_i > 0 ? 'inset_area_' . $this->inset_i : 'content') . $method_name . "</th>";
                    } else {
                        $HTML .= "<th>" . $value['header_caption'] . $method_name . '</th>';
                    }
                }
            }
            $HTML .= $this->show_buttons ? "<th>&nbsp;</th>" : '';
            $HTML .= '</tr>';
            if (is_array($data)) {
                $alt = false;
                foreach ($data as $row) {
                    $alt = $alt ? false : 'alt';
                    if ($this->alert_condition1) {
                        $condition = String::doFormulaReplacements($this->alert_condition1, $row, 1);
                        $alert_class1 = eval("if ({$condition}) { return 1;} else { return 0;}") ? 'alert1' : '';
                    }
                    if ($this->alert_condition2) {
                        $condition = String::doFormulaReplacements($this->alert_condition2, $row, 1);
                        $alert_class2 = eval("if ({$condition}) { return 1;} else { return 0;}") ? 'alert2' : '';
                    }
                    $HTML .= '<tr class="' . $alt . ' ' . $alert_class1 . ' ' . $alert_class2 . '">';
                    if (!is_array($this->fields)) {
                        continue;
                    }
                    if ($CFG->backstage_mode && !$this->links_out && $this->show_buttons && $CFG->is_ctrl_panel != 'Y') {
                        $HTML .= "<td><label for=\"checkbox{$row['id']}\"/><input id=\"checkbox{$row['id']}\" type=\"checkbox\" value=\"{$row['id']}\" class=\"grid_select checkbox_input\"/></td>";
                    }
                    foreach ($this->fields as $name => $properties) {
                        $key = $name;
                        if (strstr($name, 'lll')) {
                            $name_parts = explode('lll', $name);
                            $name = $name_parts[0];
                        }
                        if ($this->inset_id > 0) {
                            if ($properties['name'] == $this->inset_id_field) {
                                continue;
                            }
                            if (strstr($this->inset_id_field, '.')) {
                                $inset_field_parts = explode('.', $this->inset_id_field);
                                if ($properties['subtable'] == $inset_field_parts[0] && (in_array($inset_field_parts[1], $properties['subtable_fields']) || $inset_field_parts[1] == 'id')) {
                                    continue;
                                }
                            }
                        }
                        $value = $row[$key];
                        $link_id = $row[$name . '_id'] ? $row[$name . '_id'] : $value;
                        $class = $properties['class'] ? "class=\"{$properties['class']}\"" : '';
                        $HTML .= "<td {$class}>";
                        if (!empty($properties['is_media'])) {
                            reset($CFG->image_sizes);
                            $m_values = explode('|||', $value);
                            $m_size = !empty($properties['media_size']) ? $properties['media_size'] : key($CFG->image_sizes);
                            $m_limit = !empty($properties['media_amount']) ? $properties['media_amount'] : 1;
                            $HTML .= Gallery::multiple($properties['subtable'], $row['id'], $properties['name'], $properties['media_size'], 0, false, $properties['media_amount'], false, false, true);
                        } elseif ($properties['is_op'] && !$properties['run_in_sql']) {
                            $value1 = number_format(self::doOperation($key, $properties, $row), 2);
                            if (is_array($page_total)) {
                                if (array_key_exists($name, $page_total)) {
                                    $page_total[$key] += $value1;
                                }
                            }
                            if (is_array($page_avg)) {
                                if (array_key_exists($name, $page_avg)) {
                                    $page_avg[$key][] = $value1;
                                }
                            }
                            $HTML .= $value1;
                        } elseif ($properties['is_form']) {
                            if (!$properties['header_caption']) {
                                continue;
                            }
                            $HTML .= '<div>';
                            if (!$ref) {
                                $ref = new ReflectionClass('Form');
                                if (is_array($properties['inputs_array'])) {
                                    foreach ($properties['inputs_array'] as $method => $args) {
                                        $method_parts = explode('|', $method);
                                        $method1 = $method_parts[0];
                                        $params = $ref->getMethod($method1)->getParameters();
                                        if (is_array($params)) {
                                            $i = 0;
                                            foreach ($params as $param) {
                                                $param_name = $param->getName();
                                                if ($param_name == 'value') {
                                                    $i_methods[$method]['value'] = $i;
                                                } elseif ($param_name == 'static') {
                                                    $i_methods[$method]['static'] = $i;
                                                } elseif ($param_name == 'j') {
                                                    $i_methods[$method]['j'] = $i;
                                                } elseif ($param_name == 'checked') {
                                                    $i_methods[$method]['checked'] = $i;
                                                } elseif ($param_name == 'grid_input') {
                                                    $i_methods[$method]['grid_input'] = $i;
                                                } elseif ($param_name == 'is_current_timestamp') {
                                                    $i_methods[$method]['is_current_timestamp'] = $i;
                                                }
                                                $i++;
                                            }
                                        }
                                    }
                                }
                            }
                            if (!empty($properties['insert_new_record_when'])) {
                                $properties['insert_new_record_when'] = String::replaceConditionals('(' . $properties['insert_new_record_when'] . ')', $row, $properties['f_id_field']);
                                $result = eval("if ({$properties['insert_new_record_when']}) { return 0;} else { return 1;}");
                            }
                            $i_table = !empty($properties['table']) ? $properties['table'] : $this->table;
                            $i_f_id = $properties['f_id'] ? $row[str_replace('[', '', str_replace(']', '', $properties['f_id']))] : $row['id'];
                            if (!$result) {
                                $i_row = DB::getRecord($i_table, 0, $row['id'], 1, $properties['f_id_field'], $properties['order_by'], $properties['order_asc']);
                            } else {
                                $i_row = false;
                            }
                            $HTML .= '
							<input type="hidden" name="iform_table' . $this->i . '[' . $row['id'] . ']" value="' . $i_table . '" />
							<input type="hidden" name="iform_id' . $this->i . '[' . $row['id'] . ']" value="' . $i_row['id'] . '" />';
                            if ($i_row) {
                                $HTML .= '<input type="hidden" name="iform_action' . $this->i . '[' . $row['id'] . ']" value="edit" />';
                            } else {
                                $HTML .= '<input type="hidden" name="iform_action' . $this->i . '[' . $row['id'] . ']" value="new" />';
                            }
                            if (is_array($properties['inputs_array'])) {
                                foreach ($properties['inputs_array'] as $method => $args) {
                                    $method_parts = explode('|', $method);
                                    $method1 = $method_parts[0];
                                    $CFG->method_id = $args['pm_method_id'];
                                    unset($args['pm_method_id']);
                                    unset($args['show_total']);
                                    $args1 = $args;
                                    $args = array_values($args);
                                    $i_value = $i_methods[$method]['value'];
                                    $i_checked = $i_methods[$method]['checked'];
                                    $i_static = $i_methods[$method]['static'];
                                    $i_j = $i_methods[$method]['j'];
                                    $i_is_current_timestamp = $i_methods[$method]['is_current_timestamp'];
                                    $input_name = $args[0];
                                    $args[$i_static] = 1;
                                    $args[$i_j] = $input_name;
                                    $args[0] = $row['id'];
                                    if ($method1 == 'textInput') {
                                        $args[13] = '';
                                        ksort($args);
                                    }
                                    if ($method1 == 'hiddenInput') {
                                        $args[8] = '';
                                        $args[$i_is_current_timestamp] = $args1['is_current_timestamp'];
                                        ksort($args);
                                    }
                                    if ($args1['show_total']) {
                                        $totals[$input_name][] = $row[$input_name];
                                    }
                                    if ($method1 == 'checkBox') {
                                        $args[$i_checked] = $i_row[$input_name];
                                    } else {
                                        $args[$i_value] = $i_row[$input_name];
                                    }
                                    if (!$class_instance) {
                                        $CFG->form_output_started = true;
                                        $class_instance = $ref->newInstanceArgs(array('grid_form_' . $this->table . $this->i));
                                    }
                                    $method_instance = $ref->getMethod($method1);
                                    $HTML .= '<div class="col" id="' . $properties['method_id'] . '">' . $method_instance->invokeArgs($class_instance, $args) . '</div>';
                                }
                            }
                            if ($class_instance) {
                                $CFG->o_method_suppress = true;
                                $method_instance = $ref->getMethod('hiddenInput');
                                $HTML .= $method_instance->invokeArgs($class_instance, array($row['id'], 0, $i_f_id, false, false, false, 1, $properties['f_id_field']));
                                $CFG->o_method_suppress = false;
                            }
                            $HTML .= '<div class="clear"></div>';
                            $HTML .= '</div>';
                        } else {
                            $value = self::detectData($key, $value, $fields, $foreign_dates);
                            if (!empty($properties['link_url'])) {
                                $action = $CFG->backstage_mode ? '&action=record' : '';
                                $value = str_replace('|||', ' ', $value);
                                if (!empty($value)) {
                                    $HTML .= Link::url($properties['link_url'], $value, "id={$link_id}&is_tab={$properties['link_is_tab']}{$action}", false, false, 'content');
                                }
                            } else {
                                $HTML .= str_ireplace('|||', ' ', $value);
                            }
                            if (is_array($page_total)) {
                                if (array_key_exists($name, $page_total)) {
                                    $page_total[$key] += $value;
                                }
                            }
                            if (is_array($page_avg)) {
                                if (array_key_exists($name, $page_avg)) {
                                    $page_avg[$key][] = $value;
                                }
                            }
                        }
                        $HTML .= "</td>";
                    }
                    if ($this->show_buttons) {
                        $HTML .= '<td><nobr>';
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 0) {
                            $HTML .= Link::url($this->link_url, false, 'id=' . $row['id'] . '&action=record&is_tab=' . $this->is_tab, false, false, $this->target_elem_id, 'view', false, false, false, false, $CFG->view_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1) {
                            $HTML .= Link::url($this->link_url, false, 'id=' . $row['id'] . '&action=form&is_tab=' . $this->is_tab, false, false, $this->target_elem_id, 'edit', false, false, false, false, $CFG->edit_hover_caption) . ' ';
                        }
                        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1 && !$this->links_out) {
                            $HTML .= '<a href="#" title="' . $CFG->delete_hover_caption . '" onclick="gridDelete(' . $row['id'] . ',\'' . $this->table . '\',this)" class="delete"></a></nobr></td>';
                        }
                    }
                    $HTML .= '</tr>';
                }
            } else {
                $HTML .= '<tr><td colspan="' . (count($this->fields) + 2) . '">' . $CFG->grid_no_results . '</td></tr>';
            }
            if ($page_total || $page_avg) {
                $HTML .= '<tr>';
                if ($this->show_buttons) {
                    $HTML .= '<td></td>';
                }
                foreach ($this->fields as $name => $properties) {
                    if ($page_total[$name]) {
                        $subtotal = $page_total[$name];
                        $subtotal = stristr($fields[$name]['Type'], 'double') ? number_format($subtotal, 2) : $subtotal;
                        $subtotals[$name] = $subtotal;
                    } else {
                        $subtotal = false;
                    }
                    if ($page_avg[$name]) {
                        $subavg = array_sum($page_avg[$name]) / count($page_avg[$name]);
                        $subavg = stristr($fields[$name]['Type'], 'double') ? number_format($subavg, 2) : $subavg;
                        $subavgs[$name] = $subavg;
                    } else {
                        $subavg = false;
                    }
                }
                $subtotals = $subtotals ? $subtotals : array();
                $subavgs = $subavgs ? $subavgs : array();
                $subs = array_merge($subtotals, $subavgs);
                foreach ($this->fields as $name => $properties) {
                    $sub = $subs[$name] ? $subs[$name] : false;
                    $HTML .= '<td class="subtotal">' . (is_numeric($sub) ? number_format($sub, 2) : $sub) . '</td>';
                }
                if ($this->show_buttons) {
                    $HTML .= '<td class="subtotal"><em>' . ($page_total ? $CFG->subtotal_label : '') . ($page_total && $page_avg ? '/' : '') . ($page_avg ? $CFG->subavg_label : '') . '</em></td>';
                }
                $HTML .= '</tr>';
            }
            if ($grand_total || $grand_avg) {
                $HTML .= '<tr>';
                if ($this->show_buttons) {
                    $HTML .= '<td class="total"></td>';
                }
                foreach ($this->fields as $name => $properties) {
                    if ($properties['is_op'] && !$properties['run_in_sql']) {
                        continue;
                    }
                    if (is_array($grand_total)) {
                        if (array_key_exists($name, $grand_total)) {
                            $total = array_key_exists($name, $grand_total) ? number_format(DB::getTotal($properties, $this->table), 2) : false;
                            $totals[$name] = $total;
                        }
                    }
                    if (is_array($grand_avg)) {
                        if (array_key_exists($name, $grand_avg)) {
                            //$avg = (array_key_exists($name,$grand_avg)) ? number_format(DB::get($this->table,array($this->table.'.'.$name),$page,$this->rows_per_page,$this->order_by,$this->order_asc,0,$this->filter_results,$this->inset_id,$this->inset_id_field,0,1),2) : false;
                            $avg = array_key_exists($name, $grand_avg) ? number_format(DB::getAverage($properties, $this->table), 2) : false;
                            $totals[$name] = $avg;
                        }
                    }
                }
                foreach ($this->fields as $name => $properties) {
                    if ($properties['is_op'] && !$properties['run_in_sql']) {
                        /*
                        $formula = $properties['formula'];
                        foreach ($totals as $o_name => $o_value) {
                        	$formula = str_replace($o_name,str_replace(',','',$o_value),$formula);
                        }
                        $total = eval("return $formula ;");
                        */
                        $total = false;
                    } else {
                        if ($totals[$name]) {
                            $total = $totals[$name];
                        } else {
                            $total = false;
                        }
                    }
                    $HTML .= '<td class="total">' . (is_numeric($total) ? number_format($total, 2) : $total) . '</td>';
                }
                if ($this->show_buttons) {
                    $HTML .= '<td class="total"><em>' . ($grand_total ? $CFG->total_label : '') . ($grand_total && $grand_avg ? '/' : '') . ($grand_avg ? $CFG->avg_label : '') . '</em></td>';
                }
                $HTML .= '</tr>';
            }
            $HTML .= '</table>';
        }
        $pagination = Grid::pagination($page, $total_rows);
        if ($this->grid_label) {
            if ($CFG->pm_editor) {
                $method_name = Form::peLabel($this->grid_label['method_id'], 'gridLabel');
            }
            $grid_label = $this->grid_label['text'] . ' ' . $method_name;
        } else {
            $grid_label = Ops::getPageTitle();
        }
        Grid::show_filters();
        Grid::show_errors();
        $amount = $total_rows > 0 ? '(' . $total_rows . ')' : false;
        if (!($this->inset_id > 0 || $CFG->is_form_inset)) {
            echo '
			<div class="area full_box" id="grid_' . $this->i . '">
				<h2>' . $grid_label . ' ' . $amount . '</h2>
				<div class="box_bar"></div>
				<div class="box_tl"></div>
				<div class="box_tr"></div>
				<div class="box_bl"></div>
				<div class="box_br"></div>
				<div class="t_shadow"></div>
				<div class="r_shadow"></div>
				<div class="b_shadow"></div>
				<div class="l_shadow"></div>
				<div class="box_b"></div>
				<div class="grid_buttons">
				' . $pagination . '';
            if (is_array($this->modes)) {
                if (count($this->modes) > 1) {
                    echo '<div class="modes">';
                    foreach ($this->modes as $mode => $enabled) {
                        $class1 = $mode == $this->mode ? 'active_view' : false;
                        if ($mode == 'table') {
                            $class = 'switch_table';
                            $caption = $CFG->switch_to_table;
                        } elseif ($mode == 'list') {
                            $class = 'switch_list';
                            $label = $CFG->switch_to_list;
                        } elseif ($mode == 'graph') {
                            $class = 'switch_graph';
                            $label = $CFG->switch_to_graph;
                        } elseif ($mode == 'graph_line') {
                            $class = 'switch_graph_line';
                            $label = $CFG->switch_to_graph_line;
                        } elseif ($mode == 'graph_pie') {
                            $class = 'switch_graph_pie';
                            $label = $CFG->switch_to_graph_pie;
                        }
                        echo Link::url($CFG->url, false, false, array('page' . $this->i => $page, 'p_bypass' . $this->i => 1, 'mode' . $this->i => $mode), true, 'content', $class . ' ' . $class1, false, false, false, false, $label) . ' ';
                    }
                    echo '</div>';
                }
            }
            if (!$this->links_out && $this->show_buttons && $CFG->is_ctrl_panel != 'Y') {
                echo '<div class="button before"></div>';
                if (is_array($this->fields)) {
                    foreach ($this->fields as $properties) {
                        if ($properties['is_form']) {
                            $i_name = !$properties['button_submit_all'] ? $properties['name'] : 'all';
                            echo '<a href="#" onclick="gridSubmitForm(\'' . $this->table . $this->i . '\')" class="button"><div class="save"></div>' . $properties['save_button_caption'] . '</a>';
                            if ($properties['button_submit_all']) {
                                break;
                            }
                        }
                    }
                }
                if (array_key_exists('is_active', $fields)) {
                    echo '<a class="button" href="#" onclick="gridSetActive(\'' . $this->table . '\',1)">' . $CFG->grid_activate_button . '</a>';
                    echo '<a class="button" href="#" onclick="gridSetActive(\'' . $this->table . '\')">' . $CFG->grid_deactivate_button . '</a>';
                }
                echo Link::url($this->link_url, '<div class="add_new"></div>' . $CFG->add_new_caption, '&action=form&is_tab=' . $this->is_tab, false, false, $this->target_elem_id, 'button') . '<a class="button last" href="#" onclick="gridDeleteSelection(\'' . $this->table . '\')"><div class="delete"></div> ' . $CFG->delete_button_label . '</a>';
                echo '<div class="button after"></div>';
            }
            echo '
				</div>
				<div class="contain">';
        }
        $HTML .= '
		<script type="text/javascript">
			$(document).ready(function() {
				$("#grid_' . $this->i . '").find("th").mouseover(function() {
					gridHighlightTH(this);
				});
				$("#grid_' . $this->i . '").find("th").mouseout(function() {
					gridUnHighlightTH(this);
				});
				$("#grid_' . $this->i . '").find("td").mouseover(function() {
					gridHighlightTD(this);
				});
				$("#grid_' . $this->i . '").find("td").mouseout(function() {
					gridUnHighlightTD(this);
				});
			';
        if (User::permission(0, 0, $this->link_url, false, $this->is_tab) < 1) {
            $HTML .= '
				$("input").attr("disabled","disabled");
				$("select").attr("disabled","disabled");
			';
        }
        $HTML .= '
			});
		</script>';
        echo $HTML;
        if ($this->rows_per_page > 30) {
            echo $pagination;
        }
        if ($CFG->backstage_mode && User::permission(0, 0, $this->link_url, false, $this->is_tab) > 1 && $this->inset_id === false) {
            echo "</form>";
        }
        if (!($this->inset_id > 0 || $CFG->is_form_inset)) {
            echo '</div></div>';
        }
    }
Example #27
0
 public static function registerNew($info)
 {
     global $CFG;
     if (!is_array($info)) {
         return false;
     }
     $info['email'] = preg_replace("/[^0-9a-zA-Z@\\.\\!#\$%\\&\\*+_\\~\\?\\-]/", "", $info['email']);
     $exist_id = self::userExists($info['email']);
     if ($exist_id > 0) {
         $user_info = DB::getRecord('site_users', $exist_id, 0, 1);
         $email = SiteEmail::getRecord('register-existing');
         Email::send($CFG->form_email, $info['email'], $email['title'], $CFG->form_email_from, false, $email['content'], $user_info);
         return false;
     }
     $new_id = self::getNewId();
     if ($new_id > 0) {
         $sql = 'SELECT id FROM fee_schedule ORDER BY from_usd ASC LIMIT 0,1';
         $result = db_query_array($sql);
         $pass1 = self::randomPassword(12);
         //$info['first_name'] = preg_replace("/[^\pL a-zA-Z0-9@\s\._-]/u", "",$info['first_name']);
         //$info['last_name'] = preg_replace("/[^\pL a-zA-Z0-9@\s\._-]/u", "",$info['last_name']);
         //$info['country'] = preg_replace("/[^0-9]/", "",$info['country']);
         $info['user'] = $new_id;
         $info['pass'] = Encryption::hash($pass1);
         $info['date'] = date('Y-m-d H:i:s');
         $info['confirm_withdrawal_email_btc'] = 'Y';
         $info['confirm_withdrawal_email_bank'] = 'Y';
         $info['notify_deposit_btc'] = 'Y';
         $info['notify_deposit_bank'] = 'Y';
         $info['notify_withdraw_btc'] = 'Y';
         $info['notify_withdraw_bank'] = 'Y';
         $info['notify_login'] = '******';
         $info['no_logins'] = 'Y';
         $info['fee_schedule'] = $result[0]['id'];
         $info['default_currency'] = preg_replace("/[^0-9]/", "", $info['default_currency']);
         unset($info['terms']);
         $record_id = db_insert('site_users', $info);
         require_once '../lib/easybitcoin.php';
         $bitcoin = new Bitcoin($CFG->bitcoin_username, $CFG->bitcoin_passphrase, $CFG->bitcoin_host, $CFG->bitcoin_port, $CFG->bitcoin_protocol);
         $new_address = $bitcoin->getnewaddress($CFG->bitcoin_accountname);
         db_insert('bitcoin_addresses', array('address' => $new_address, 'site_user' => $record_id, 'date' => date('Y-m-d H:i:s')));
         $info['pass'] = $pass1;
         $email = SiteEmail::getRecord('register');
         Email::send($CFG->form_email, $info['email'], $email['title'], $CFG->form_email_from, false, $email['content'], $info);
         if ($CFG->email_notify_new_users) {
             $email = SiteEmail::getRecord('register-notify');
             $info['pass'] = false;
             Email::send($CFG->form_email, $CFG->support_email, $email['title'], $CFG->form_email_from, false, $email['content'], $info);
         }
         return true;
     }
 }
Example #28
0
 $db_tables = DB::getTables();
 $is_tab = $_REQUEST['is_tab'];
 $next_page_id = $_REQUEST['pm_page_id'];
 $next_page_action = $_REQUEST['pm_action'];
 $method = $method == 'selectInput' ? 'fauxSelect' : $method;
 if (!empty($_REQUEST['field_name'])) {
     $fn = $_REQUEST['field_name'];
     $fv = $_REQUEST['field_value'];
     $table_fields = DB::getTableFields($fv, false, true);
 }
 echo "<span id=\"edit_title\">{$class}::{$method}{$parent_method_text}</span>";
 $CFG->in_popup = 1;
 $form = new Form('form', false, false, false, $table);
 $form->record_id = $_REQUEST['id'];
 if ($_REQUEST['id']) {
     $info = DB::getRecord($table, $_REQUEST['id']);
     $args = unserialize($info['arguments']);
     if (is_array($args)) {
         foreach ($args as $name => $value) {
             $name = 'argument_' . $name;
             $args1[$name] = $value;
         }
     } else {
         $args1 = array();
     }
     $form->info = array_merge($args1, $form->info);
 }
 if ($c_id > 0) {
     $form->hiddenInput('control_id', false, false, false, 'int');
     $form->hiddenInput('method');
 } elseif ($parent_method_id > 0) {
Example #29
0
 function createRecord($table, $insert_array, $trigger_field = false, $trigger_value = false, $day = false, $month = false, $year = false, $send_condition = false, $any_modification = false, $register_changes = false, $on_new_record_only = false, $store_row = false, $if_not_exists = false, $run_in_cron = false)
 {
     global $CFG;
     if ($CFG->backstage_mode) {
         $HTML = '';
         if ($CFG->pm_editor) {
             if (!$this->edit_record) {
                 $this->HTML[] = "[create_record]" . self::peLabel($CFG->method_id, 'createRecord');
             } else {
                 $this->HTML[] = "[edit_record]" . self::peLabel($CFG->method_id, 'editRecord');
             }
         }
         /*
         			$HTML .= '
         			<input type="hidden" name="trigger_field1[]" value="'.$trigger_field.'" />
         			<input type="hidden" name="trigger_value1[]" value="'.$trigger_value.'" />
         			<input type="hidden" name="create_record_table[]" value="'.$table.'" />
         			';
         			$this->HTML[] = $HTML;
         */
     }
     if ($run_in_cron && !$CFG->in_cron) {
         return false;
     } elseif ($run_in_cron && $CFG->in_cron) {
         $modified = true;
     }
     //used to have this ($CFG->ignore_request == $table) return false. Don't remember why.
     if ((is_array($this->errors) || !($this->save_called || $CFG->save_called) || !$_REQUEST[$this->name] || $_REQUEST['bypass_create_record']) && !$CFG->in_cron) {
         return false;
     }
     if (!$on_new_record_only && $this->record_created && !$trigger_field || $on_new_record_only && !$this->record_created) {
         return false;
     }
     if ($send_condition) {
         $send_condition = String::doFormulaReplacements($send_condition, $this->info, 1);
         if (!eval("if ({$send_condition}) { return 1;} else { return 0;}")) {
             return false;
         }
     }
     if ($register_changes) {
         $changes = '<div class="show_details"><a onclick="showDetails(this);return false;" href="#">' . $CFG->comments_show_details . '</a><a onclick="hideDetails(this);return false;" style="display:none;" href="#">' . $CFG->comments_hide_details . '</a></div><div class="details" style="display:none;">';
     }
     if ($this->info && $register_changes) {
         foreach ($this->info as $name => $value) {
             $grid_input_modified = false;
             if (@in_array($name, $_REQUEST['grid_inputs'])) {
                 if (is_array($this->info[$name])) {
                     if (is_array($this->old_info[$name])) {
                         foreach ($this->old_info[$name] as $id => $row) {
                             foreach ($row as $k => $v) {
                                 $key = $row['id'];
                                 if (!empty($v) && $v != 'N' && $k != 'id' && $k != 'f_id') {
                                     $compare[$key][$k] = $v;
                                 }
                             }
                         }
                         if ($compare) {
                             ksort($compare);
                             $compare = array_values($compare);
                         }
                     }
                     $i = 0;
                     foreach ($this->info[$name] as $id => $row) {
                         foreach ($row as $k => $v) {
                             if (!empty($v)) {
                                 $filtered[$i] = $row;
                             }
                         }
                         $i++;
                     }
                     if ($filtered && $compare) {
                         $i = 0;
                         foreach ($filtered as $array) {
                             if (is_array($array)) {
                                 foreach ($array as $k => $v) {
                                     if ($v != $compare[$i][$k] && (!empty($v) && !empty($compare[$i][$k]))) {
                                         $grid_input_modified = true;
                                     }
                                 }
                             }
                             $i++;
                         }
                         if (!$grid_input_modified) {
                             if (count($filtered) != count($compare)) {
                                 $grid_input_modified = true;
                             }
                         }
                     } elseif ($compare && !$filtered || $filtered && !$compare) {
                         $grid_input_modified = true;
                     }
                 }
             }
             if ($name == 'cat_selects') {
                 if (is_array($this->info[$name])) {
                     @asort($this->info[$name]);
                     @asort($this->old_info[$name]);
                     $this->info[$name] = @array_values($this->info[$name]);
                     $this->old_info[$name] = @array_values($this->old_info[$name]);
                     foreach ($this->info[$name] as $key => $arr) {
                         @asort($arr);
                         $this->info[$name][$key] = @array_values($arr);
                     }
                     if (is_array($this->old_info[$name])) {
                         foreach ($this->old_info[$name] as $key => $arr) {
                             @asort($arr);
                             $this->old_info[$name][$key] = @array_values($arr);
                         }
                     }
                     if ($this->info[$name] != $this->old_info[$name]) {
                         $modified = true;
                         $changes .= '<b>' . $name . '</b> ' . $CFG->comments_set_to . ' ' . (is_array($value) ? print_r($value, true) : $value) . '<br/>';
                     }
                 }
             } elseif (strip_tags($this->info[$name]) != strip_tags($this->old_info[$name]) && !@in_array($name, $_REQUEST['grid_inputs']) || $grid_input_modified) {
                 $modified = true;
                 $changes .= '<b>' . $name . '</b> ' . $CFG->comments_set_to . ' ' . (is_array($value) ? print_r($value, true) : $value) . '<br/>';
             }
             $bypass = false;
             $compare = false;
             $filtered = false;
         }
     }
     if ($register_changes) {
         $changes .= '</div>';
     }
     if ($on_new_record_only && $this->record_created) {
         $modified = true;
     }
     if ($this->info[$trigger_field] != $this->old_info[$trigger_field] || $modified) {
         if ($this->info[$trigger_field] == $trigger_value || !$trigger_value && $trigger_field || $modified) {
             if (!is_array($insert_array) && stristr($insert_array, 'array:')) {
                 $insert_array = str_ireplace('array:', '', $insert_array);
                 $ia1 = explode(',', $insert_array);
                 if (is_array($ia1)) {
                     foreach ($ia1 as $v) {
                         if (strstr($v, '=>')) {
                             $ia2 = explode('=>', $v);
                             $ia3[$ia2[0]] = $ia2[1];
                             $last_key = $ia2[0];
                         } else {
                             $ia3[$last_key] .= ',' . $v;
                         }
                     }
                 }
                 unset($insert_array);
                 $insert_array = $ia3;
             }
             if (is_array($insert_array)) {
                 foreach ($insert_array as $new_field => $old_field) {
                     if ($old_field == 'curdate') {
                         $insert_values[$new_field] = date('Y-m-d 00:00:00');
                     } elseif ($old_field == 'curtime') {
                         $insert_values[$new_field] = date('Y-m-d H:i:s', time() + Settings::mysqlTimeDiff() * 3600);
                     } elseif ($old_field == 'user_id') {
                         $insert_values[$new_field] = User::$info['id'];
                     } elseif ($old_field == 'record_id') {
                         $insert_values[$new_field] = $this->record_id;
                     } elseif (strstr($old_field, '(') && strstr($old_field, ')')) {
                         if ($this->record_created) {
                             $this->old_info['id'] = $this->record_id;
                         }
                         $formula = String::doFormulaReplacements($old_field, $this->old_info, 1);
                         $insert_values[$new_field] = eval("return ({$formula});");
                     } elseif ($old_field == 'current_url') {
                         $insert_values[$new_field] = $CFG->url;
                     } elseif (!is_array($old_field)) {
                         if (array_key_exists($old_field, $this->info)) {
                             $insert_values[$new_field] = $this->info[$old_field];
                         } else {
                             $insert_values[$new_field] = $old_field;
                         }
                     } else {
                         $insert_values[$new_field] = DB::getForeignValue(implode(',', $old_field), $this->info['id']);
                     }
                 }
                 if ($register_changes) {
                     $insert_values['comments'] = $changes;
                 }
                 if ($store_row && $table == 'comments') {
                     if ($this->edit_record && $table != $this->table) {
                         $row = DB::getRecord($table, $this->edit_record_field_id, 0, 1);
                         $insert_values['f_table_row'] = serialize($row);
                     } else {
                         $insert_values['f_table_row'] = serialize($this->info);
                     }
                 }
                 $CFG->ignore_request = $table;
                 $CFG->bypass_unserialize = true;
                 $this->edit_record_id_field = $this->edit_record_id_field ? $this->edit_record_id_field : $this->record_id;
                 if (!$this->edit_record) {
                     if ($if_not_exists) {
                         $insert_values1 = $insert_values;
                         if ($k = array_search($this->record_id, $insert_values1)) {
                             unset($insert_values1[$k]);
                         }
                         if (DB::recordExists($table, $insert_values1)) {
                             return false;
                         }
                     }
                     $this->create_record[] = array('table' => $table, 'insert_values' => $insert_values);
                     //echo 'Insert:';
                     //print_ar($insert_values);
                 } else {
                     $this->create_record[] = array('edit' => 1, 'table' => $table, 'insert_values' => $insert_values, 'id' => $this->edit_record_field_id);
                     //echo 'Update:';
                     //print_ar($insert_values);
                 }
             }
         }
     }
 }
 /**
  * Returns the id of the user identified by the identifier passed as a parameter
  *
  * @param String $identifier
  * @return Int
  */
 public static function find_by_identifier($identifier)
 {
     $sql = "SELECT id, firstname, lastname, identifier\n                FROM " . self::table() . "\n                WHERE `identifier` = ?";
     return DB::getRecord($sql, array($identifier));
 }