Esempio n. 1
0
 public function test_main()
 {
     $this->assertEquals('0', todecimal(''));
     $this->assertEquals('1', todecimal(1));
     $this->assertEquals('-1', todecimal(-1));
     $this->assertEquals('1', todecimal('1'));
     $this->assertEquals('-1', todecimal('-1'));
     $this->assertEquals('1.1', todecimal('1.1'));
     $this->assertEquals('-1.1', todecimal('-1.1'));
     $this->assertEquals('1.1', todecimal('1,1'));
     $this->assertEquals('-1.1', todecimal('-1,1'));
     $this->assertEquals('0', todecimal(''));
     $this->assertEquals('0', todecimal('-'));
     $this->assertEquals('1999.37', todecimal('1.999,369€'));
     $this->assertEquals('-1999.37', todecimal('-1.999,369€'));
     $this->assertEquals('126564789.33', todecimal('126,564,789.33 m²'));
     $this->assertEquals('-126564789.33', todecimal('-126,564,789.33 m²'));
     $this->assertEquals('126564789.33', todecimal(126564789.33));
     $this->assertEquals('-126564789.33', todecimal(-126564789.33));
     $this->assertEquals('122.34', todecimal('122.34343The'));
     $this->assertEquals('-122.34', todecimal('-122.34343The'));
     $this->assertEquals('122.34', todecimal(' 122.34343 The '));
     $this->assertEquals('-122.34', todecimal(' -122.34343 The '));
     $this->assertEquals('122.34', todecimal('The122.34343'));
     $this->assertEquals('-122.34', todecimal('The-122.34343'));
     $this->assertEquals('0', todecimal('some string not containing numbers'));
     $this->assertEquals('1234', todecimal('01234'));
     $this->assertEquals('-1234', todecimal('-01234'));
     $this->assertEquals(['12.34', '56.78'], todecimal([12.341, '56,7811111']));
     $this->assertEquals(['12.34', '-56.78'], todecimal([12.341, '-56,7811111']));
     $this->assertEquals(['-12.34', '-56.78'], todecimal([-12.341, '-56,7811111']));
     $this->assertEquals(['k1' => '12.34', 'k2' => '56.78'], todecimal(['k1' => 12.341, 'k2' => '56,7811111']));
     $this->assertEquals(['k1' => '-12.34', 'k2' => '-56.78'], todecimal(['k1' => -12.341, 'k2' => '-56,7811111']));
     $this->assertEquals(['k1' => '12.34', 'k2' => [['56.78']]], todecimal(['k1' => 12.341, 'k2' => [['56,7811111']]]));
     $this->assertEquals(['k1' => '12.34', 'k2' => [['-56.78']]], todecimal(['k1' => 12.341, 'k2' => [['-56,7811111']]]));
     $this->assertEquals('56.7811', todecimal('56,7811111', $digits = 4));
     #		$this->assertEquals(array('12.341', '56.7811'), todecimal(array(12.341, '56,7811111'), $digits = 4) );
 }
Esempio n. 2
0
}
$country_ids = [];
foreach (db_geonames()->select('code', 'geoname_id')->from('geo_country')->get_2d() as $code => $id) {
    $id && ($country_ids[$code] = $id);
}
$region_ids = [];
foreach (db_geonames()->select('code', 'geoname_id')->from('geo_admin1')->get_2d() as $code => $id) {
    $id && ($region_ids[$code] = $id);
}
if ($lang) {
    $sql = '
		SELECT g.id, a.name, g.name AS name_eng, g.country, g.latitude, g.longitude, g.admin1, g.population
		FROM geo_geoname AS g
		LEFT JOIN geo_alternate_name AS a ON a.geoname_id = g.id
		WHERE 
			g.feature_class = "p"
			AND g.population > 10000
			AND a.language_code = "' . _es($lang) . '"
		GROUP BY g.id
		ORDER BY g.country, a.name COLLATE utf8_unicode_ci
	';
}
$to_update = [];
foreach (db_geonames()->get_all($sql) as $a) {
    $to_update[$a['id']] = ['id' => $a['id'], 'country' => $a['country'], 'name' => $a['name'], 'name_eng' => $a['name_eng'], 'population' => $a['population'], 'lat' => todecimal($a['latitude'], 6), 'lon' => todecimal($a['longitude'], 6), 'region_id' => $region_ids[$a['country'] . '.' . $a['admin1']]];
}
db()->replace_safe($table, $to_update);
db()->query('DELETE FROM ' . $table . ' WHERE country != "ua"') or print_r(db()->error());
db()->update($table, ['active' => 1], 'country = "ua"');
echo 'Trying to get 2 first records: ' . PHP_EOL;
print_r(db()->get_all('SELECT * FROM ' . $table . ' LIMIT 2'));
Esempio n. 3
0
 function _item_update_price_unit($options)
 {
     $_ = $options;
     $price = $_['price'];
     $order_id = $_['order_id'];
     $product_id = $_['product_id'];
     $param_id = $_['param_id'];
     $result = false;
     if (is_null($price) || is_null($order_id) || is_null($product_id) || is_null($param_id)) {
         return $result;
     }
     $result = db()->UPDATE(db('shop_order_items'), ['price' => todecimal($price)], sprintf('order_id=%u AND product_id=%u AND param_id=%u', $order_id, $product_id, $param_id));
     return $result;
 }
 function product_set_edit()
 {
     $product_set_id = (int) $_GET['id'];
     $a = db()->from('shop_product_sets')->whereid($product_set_id)->get();
     if (input()->is_post()) {
         // save image
         if ($_FILES) {
             $result = true;
             if (main()->is_ajax()) {
                 // prepare file options
                 $path = 'uploads/shop/product_sets/';
                 $file_path = PROJECT_PATH . $path;
                 $uri_path = WEB_PATH . $path;
                 $file_original = $file_path . $product_set_id . '.jpg';
                 $file_big = $file_path . $product_set_id . '_big.jpg';
                 $file_thumb = $file_path . $product_set_id . '_thumb.jpg';
                 $url_thumb = $uri_path . $product_set_id . '_thumb.jpg';
                 $file_watermark = PROJECT_PATH . SITE_WATERMARK_FILE;
                 $max_width = module('manage_shop')->BIG_X;
                 $max_height = module('manage_shop')->BIG_Y;
                 // processing upload
                 $upload_handler = _class('upload_handler');
                 $upload_handler->options('param_name', 'image');
                 $result = $upload_handler->post_handler(['image_versions' => ['image' => ['original' => ['file' => $file_original], 'big' => ['max_width' => $max_width, 'max_height' => $max_height, 'file' => $file_big, 'watermark' => $file_watermark], 'thumbnail' => ['max_width' => 324, 'max_height' => 216, 'file' => $file_thumb]]]]);
                 if (empty($result['versions'])) {
                     $status = false;
                     $url_thumb = false;
                 } else {
                     $status = true;
                 }
                 echo json_encode(['status' => $status, 'image' => $url_thumb]);
                 exit;
             }
         }
         $up = [];
         // Add products to current set
         if ($_POST['products_ids']) {
             $ids = [];
             foreach (explode(',', $_POST['products_ids']) as $id) {
                 $id = intval($id);
                 $id && ($ids[$id] = $id);
             }
             if ($ids) {
                 $ids = db()->select('id')->from('shop_products')->whereid($ids)->get_2d();
                 $ids && ($ids = array_combine($ids, $ids));
             }
             $insert_items = [];
             if ($ids) {
                 $current_ids = array_keys((array) db()->get_all(str_replace('%sid', $product_set_id, $this->_sql_set_list_products)));
                 $current_ids && ($current_ids = array_combine($current_ids, $current_ids));
                 foreach ((array) $ids as $id) {
                     if (isset($current_ids[$id])) {
                         continue;
                     }
                     $insert_items[$id] = ['product_set_id' => $product_set_id, 'product_id' => $id, 'quantity' => 1];
                 }
             }
             if ($insert_items) {
                 db()->replace_safe('shop_product_sets_items', $insert_items);
             }
         }
         // Editable quantity for each product in list
         if (!empty($_POST['quantity']) && is_array($_POST['quantity'])) {
             $current_items = (array) db()->get_all(str_replace('%sid', $product_set_id, $this->_sql_set_list_products));
             $current_ids = array_keys($current_items);
             $current_ids && ($current_ids = array_combine($current_ids, $current_ids));
             foreach ((array) $_POST['quantity'] as $id => $quantity) {
                 if (!isset($current_ids[$id])) {
                     continue;
                 }
                 $item = $current_items[$id];
                 if ($item['quantity'] == $quantity) {
                     continue;
                 }
                 $qup = ['product_id' => (int) $id, 'quantity' => (int) $quantity];
                 db()->update_safe('shop_product_sets_items', $qup, 'product_id=' . (int) $id . ' AND product_set_id=' . (int) $product_set_id);
             }
         }
         // Process common form fields
         foreach ((array) $this->_table['fields'] as $f) {
             // TODO: form validation, name=required
             if ($a[$f] != $_POST[$f] && isset($_POST[$f])) {
                 $up[$f] = $_POST[$f];
             }
         }
         // Count price from real product prices
         if (empty($_POST['price'])) {
             $product_prices = db()->get_2d($this->_sql_sets_prices_total);
             $total_price = $product_prices[$product_set_id];
             if ($total_price) {
                 $up['price'] = todecimal($total_price);
             }
         }
         if ($up) {
             db()->update_safe('shop_product_sets', $up, $product_set_id);
         }
         return js_redirect('');
     }
     $product_prices = db()->get_2d($this->_sql_sets_prices_total);
     $a = (array) $_POST + (array) $a;
     $a['form_action'] = './?object=' . main()->_get('object') . '&action=product_set_edit&id=' . $product_set_id;
     $a['back_link'] = './?object=' . main()->_get('object') . '&action=product_sets';
     $a['products_price'] = $product_prices[$product_set_id];
     $image = _class('_shop_products', 'modules/shop/')->_product_set_image($product_set_id, $a['cat_id'], 'thumb');
     return form($a)->upload('image', 'Изображение', ['preview' => $image]) . form($a)->text('name')->textarea('description')->text('price', ['class' => 'input-mini'])->info('products_price')->container(table(str_replace('%sid', $product_set_id, $this->_sql_set_list_products), ['pager_records_on_page' => 1000])->image('id', ['width' => '50px', 'no_link' => 1, 'img_path_callback' => function ($_p1, $_p2, $row) {
         $image = common()->shop_get_images($row['id']);
         return $image[0]['thumb'];
     }])->text('product_id', ['link' => './?object=manage_shop&action=product_edit&id=%d'])->text('name')->text('price')->input('quantity', ['class' => 'input-mini', 'type' => 'number'])->btn_delete('', './?object=' . main()->_get('object') . '&action=product_set_delete&product_id=%d&id=' . $product_set_id)->btn_active('active', [], ['disabled' => 1]))->container(_class('manage_shop_filter', 'admin_modules/manage_shop/')->_product_search_widget('products_ids', $replace['products_ids'], true), 'Добавить продукты')->chosen_box('cat_id', module('manage_shop')->_cats_for_select)->active_box()->save_and_back();
 }