function cahorro_off_action($xcrud) { if ($xcrud->get('primary')) { $db = Xcrud_db::get_instance(); $query = 'UPDATE datos_familiares SET `cahorro` = b\'0\' WHERE id_familiar = ' . (int) $xcrud->get('primary'); $db->query($query); } }
function unpublish_action($xcrud) { if ($xcrud->get('primary')) { $db = Xcrud_db::get_instance(); $query = 'UPDATE base_fields SET `bool` = b\'0\' WHERE id = ' . (int) $xcrud->get('primary'); $db->query($query); } }
function movebottom($xcrud) { if ($xcrud->get('primary') !== false) { $primary = (int) $xcrud->get('primary'); $db = Xcrud_db::get_instance(); $query = 'SELECT `officeCode` FROM `offices` ORDER BY `ordering`,`officeCode`'; $db->query($query); $result = $db->result(); $count = count($result); $sort = array(); foreach ($result as $key => $item) { if ($item['officeCode'] == $primary && $key != $count - 1) { unset($result[$key]); array_splice($result, $key + 1, 0, array($item)); break; } } foreach ($result as $key => $item) { $query = 'UPDATE `offices` SET `ordering` = ' . $key . ' WHERE officeCode = ' . $item['officeCode']; $db->query($query); } } }
protected function _clone_row() { if (is_array($this->table_info) && count($this->table_info) && !$this->table_ro) { $db = Xcrud_db::get_instance($this->connection); $fields = array(); $row = array(); $this->find_details_text_variables(); if ($this->direct_select_tags) { foreach ($this->direct_select_tags as $key => $dsf) { $fields[$key] = "`{$dsf['table']}`.`{$dsf['field']}` AS `{$key}`"; } } if ($fields) { if (!$this->join) { $db->query('SELECT ' . implode(',', $fields) . " FROM `{$this->table}` WHERE `{$this->primary_key}` = " . $db->escape($this->primary_val) . " LIMIT 1"); $row = $db->row(); } else { $tables = array('`' . $this->table . '`'); $joins = array(); foreach ($this->join as $alias => $param) { $tables[] = '`' . $alias . '`'; $joins[] = "INNER JOIN `{$param['join_table']}` AS `{$alias}` \n ON `{$param['table']}`.`{$param['field']}` = `{$alias}`.`{$param['join_field']}`"; } $db->query('SELECT ' . implode(',', $fields) . " FROM `{$this->table}` AS `{$this->table}` " . implode(' ', $joins) . " WHERE `{$this->table}`.`{$this->primary_key}` = " . $db->escape($this->primary_val)); $row = $db->row(); } } if (!$this->is_duplicate($row)) { return self::error('Forbidden'); } $columns = array(); $this->primary_ai = false; foreach ($this->table_info as $table => $types) { foreach ($types as $row) { $field_index = "{$table}.{$row['Field']}"; if ($row['Key'] == 'PRI' && $row['Extra'] == 'auto_increment') { if ($table == $this->table) { $this->primary_ai = "`{$table}`.`{$row['Field']}`"; } } elseif ($row['Key'] == 'UNI' or $row['Key'] == 'PRI') { self::error('Duplication impossible. The table has a unique field.'); } else { $columns[$field_index] = array('table' => $table, 'field' => $row['Field']); } } } if (!$this->primary_ai) { self::error('Duplication impossible. Table does not have a primary autoincrement field.'); } $select = $this->_build_select_clone($columns); $where = $this->_build_where(); $table_join = $this->_build_table_join(); $where_ai = $where ? "AND {$this->primary_ai} = " . (int) $this->primary_val : "WHERE {$this->primary_ai} = " . (int) $this->primary_val; $db->query("SELECT {$select}\r\n FROM `{$this->table}`\r\n {$table_join}\r\n {$where}\r\n {$where_ai} LIMIT 1"); $postdata = $db->row(); if (isset($this->pass_var['create'])) { foreach ($this->pass_var['create'] as $field => $pv) { $postdata[$field] = $pv['value']; } } if (!$this->demo_mode) { $this->_insert($postdata, true, $columns); } } $this->task = 'list'; }
function validate_weight() { $db = Xcrud_db::get_instance(); $sell_purchase_id = $postdata->get('seid'); $sel = "SELECT * FROM stock_new WHERE purchase_id=" . $sell_purchase_id; $db->query($sel); $result = $db->result(); $result = $result[0]; $stock_weight = $result['weight']; $sell_weight = $postdata->get('weight'); $total_weight = $stock_weight - $sell_weight; if ($stock_weight < $sell_weight) { echo "Your Remaining weight is" . $total_weight; } else { echo "Sell weight not greater then stock weight"; } }
function update_price() { //mengupdate field lpb_detail yang belum memiliki price HANYA UNTUK PR (cukup dijalankan sekali) Xcrud_config::$dbname = 'bcspurchase_2015'; Xcrud_config::$dbuser = '******'; Xcrud_config::$dbpass = '******'; Xcrud_config::$dbhost = '10.2.2.32'; $db = Xcrud_db::get_instance(); $select = "select lpb_id from lpb_detail"; $db->query($select); $arr = $db->result(); $count = 0; //die("Arr :".$arr[0]['lpb_id']); foreach ($arr as $ar) { foreach ($ar as $a) { $count++; } } for ($x = 0; $x < $count; $x++) { $query = "select po_item_id from lpb_detail where lpb_id='" . $arr[$x]['lpb_id'] . "'"; $db->query($query); $po_item_id = $db->row()['po_item_id']; //die("po item id : ".$po_item_id); if ($po_item_id != '') { $query2 = "select price from po_item where po_item_id='{$po_item_id}'"; $db->query($query2); $price = $db->row()['price']; //die("material id : ".$material_id); $query3 = "update lpb_detail set price='{$price}' where lpb_id='" . $arr[$x]['lpb_id'] . "'"; $db->query($query3); } } die; }
function close_dns($xcrud) { if ($xcrud->get('primary')) { $db = Xcrud_db::get_instance(); $query = 'UPDATE trans_transaksi_invoices_detail_dn a SET a.status = "Proses Penagihan", a.total = (SELECT sum(b.total) FROM trans_transaksi_dn_detail_new b WHERE b.no_surat_jalan = a.no_surat_jalan) WHERE a.nid = ' . (int) $xcrud->get('primary'); $query2 = 'UPDATE trans_transaksi_dn_detail_new a SET a.status_surat_jalan = "Proses Penagihan" WHERE a.no_surat_jalan = (select b.no_surat_jalan from trans_transaksi_invoices_detail_dn b WHERE b.nid = ' . (int) $xcrud->get('primary') . ')'; $db->query($query); $db->query($query2); } }
function make_new_row_last($postdata, $primary) { $db = Xcrud_db::get_instance(); $q = 'SELECT COUNT(*) as num FROM your_table'; $db->query($q); $num = $db->row()['num']; $q = 'UPDATE your_table SET ordering = ' . $db->quote($num) . ' WHERE id = ' . $db->quote($primary); $db->query($q); }
error_reporting(E_ALL); ini_set("display_errors", 1); include '../inc/commons.php'; include BASE_URL . 'xcrud/xcrud.php'; if (!function_exists('xcrud_get_instance')) { function xcrud_get_instance($name = true) { return Xcrud::get_instance($name); } } Xcrud_config::$dbname = 'shop'; Xcrud_config::$dbuser = '******'; Xcrud_config::$dbpass = '******'; Xcrud_config::$dbhost = 'localhost'; $db = Xcrud_db::get_instance('shop'); $exec = $db->query("SELECT counter from counter"); $array = $db->result(); $counter = $array[0]['counter']; $exec = $db->query("SELECT count(*),country from visitors group by country order by count(*) desc"); $array = $db->result(); $country = $array[0]['country']; $exec = $db->query("SELECT count(*) as items from items"); $array = $db->result(); $items = $array[0]['items']; $exec = $db->query("SELECT count(*) as count_category from (select distinct category from items group by category) as tbl1"); $array = $db->result(); $category = $array[0]['count_category']; $exec = $db->query("SELECT count(*) as new from (select * from items where date_created+INTERVAL 1 WEEK > NOW()) as tbl1"); $array = $db->result(); $new = $array[0]['new'];
error_reporting(E_ALL); ini_set("display_errors", 1); include '../inc/commons.php'; include BASE_URL . 'xcrud/xcrud.php'; if (!function_exists('xcrud_get_instance')) { function xcrud_get_instance($name = true) { return Xcrud::get_instance($name); } } require_once "userCake/models/config.php"; if (!securePage($_SERVER['PHP_SELF'])) { die; } elseif (isUserLoggedIn()) { $db = Xcrud_db::get_instance('fashion'); $exec = $db->query("SELECT counter from counter"); $res = $db->result(); $counter = $res[0]['counter']; $exec = $db->query("SELECT count(*) as items from items"); $res = $db->result(); $items = $res[0]['items']; $exec = $db->query("SELECT count(*) as count_category from (select distinct category from items group by category) as tbl1"); $res = $db->result(); $category = $res[0]['count_category']; $exec = $db->query("SELECT count(*) as new from (select * from items where date_created+INTERVAL 1 WEEK > NOW()) as tbl1"); $res = $db->result(); $new = $res[0]['new']; } ?> <!DOCTYPE html>
function update_sku($xcrud) { $db = Xcrud_db::get_instance(); $id = $xcrud->get('primary'); die("id" . $id); $result = ''; for ($i = 0; $i < 12; $i++) { $result .= mt_rand(0, 9); } $query = "update items set sku='{$result}' where id='{$id}'"; $db->query($query); }