if (strlen($currency_code) == 3) { if ($value) { $rate = $value; } else { $rate = $currency['value']; } } else { $rate = 1; } $number2currency = $currency['symbol_left'] . number_format($number * $rate, $currency['decimal_places'], $currency['decimal_point'], $currency['thousands_point']) . $currency['symbol_right']; } else { $number2currency = $currency['symbol_left'] . number_format($number, $currency['decimal_places'], $currency['decimal_point'], $currency['thousands_point']) . $currency['symbol_right']; } return $number2currency; } osc_set_time_limit(0); $languages = osc_get_languages(); // send data to the browser, so the flushing works with IE for ($i = 0; $i < 300; $i++) { print ' '; } print "\n"; ?> <p><span id="addressBook"><span id="addressBookMarker">-</span> Address Book</span><br> <span id="banners"><span id="bannersMarker">-</span> Banners</span><br> <span id="categories"><span id="categoriesMarker">-</span> Categories</span><br> <span id="configuration"><span id="configurationMarker">-</span> Configuration</span><br> <span id="currencies"><span id="currenciesMarker">-</span> Currencies</span><br> <span id="customers"><span id="customersMarker">-</span> Customers</span><br> <span id="images"><span id="imagesMarker">-</span> Images</span><br>
public static function restore($filename = false) { global $osC_Database; osc_set_time_limit(0); if ($filename !== false) { if (file_exists(DIR_FS_BACKUP . $filename)) { $restore_file = DIR_FS_BACKUP . $filename; $extension = substr($filename, -3); if ($extension == 'sql' || $extension == '.gz' || $extension == 'zip') { switch ($extension) { case 'sql': $restore_from = $restore_file; $remove_raw = false; break; case '.gz': $restore_from = substr($restore_file, 0, -3); exec(CFG_APP_GUNZIP . ' ' . $restore_file . ' -c > ' . $restore_from); $remove_raw = true; break; case 'zip': $restore_from = substr($restore_file, 0, -4); exec(CFG_APP_UNZIP . ' ' . $restore_file . ' -d ' . DIR_FS_BACKUP); $remove_raw = true; break; } if (isset($restore_from) && file_exists($restore_from)) { $fd = fopen($restore_from, 'rb'); $restore_query = fread($fd, filesize($restore_from)); fclose($fd); } } } } else { $sql_file = new upload('sql_file'); if ($sql_file->parse()) { $restore_query = fread(fopen($sql_file->tmp_filename, 'r'), filesize($sql_file->tmp_filename)); $filename = $sql_file->filename; } } if (isset($restore_query) && !empty($restore_query)) { $sql_array = array(); $sql_length = strlen($restore_query); $pos = strpos($restore_query, ';'); for ($i = $pos; $i < $sql_length; $i++) { if ($restore_query[0] == '#') { $restore_query = ltrim(substr($restore_query, strpos($restore_query, "\n"))); $sql_length = strlen($restore_query); $i = strpos($restore_query, ';') - 1; continue; } if ($restore_query[$i + 1] == "\n") { for ($j = $i + 2; $j < $sql_length; $j++) { if (trim($restore_query[$j]) != '') { $next = substr($restore_query, $j, 6); if ($next[0] == '#') { // find out where the break position is so we can remove this line (#comment line) for ($k = $j; $k < $sql_length; $k++) { if ($restore_query[$k] == "\n") { break; } } $query = substr($restore_query, 0, $i + 1); $restore_query = substr($restore_query, $k); // join the query before the comment appeared, with the rest of the dump $restore_query = $query . $restore_query; $sql_length = strlen($restore_query); $i = strpos($restore_query, ';') - 1; continue 2; } break; } } if ($next == '') { // get the last insert query $next = 'insert'; } if (preg_match('/create/i', $next) || preg_match('/insert/i', $next) || preg_match('/drop t/i', $next)) { $next = ''; $sql_array[] = substr($restore_query, 0, $i); $restore_query = ltrim(substr($restore_query, $i + 1)); $sql_length = strlen($restore_query); $i = strpos($restore_query, ';') - 1; } } } // drop all tables defined in oscommerce/includes/database_tables.php $tables_array = array(); foreach (get_defined_constants() as $key => $value) { if (substr($key, 0, 6) == 'TABLE_') { $tables_array[] = $value; } } if (!empty($tables_array)) { $Qdrop = $osC_Database->query('drop table if exists :tables'); $Qdrop->bindRaw(':tables', implode(', ', $tables_array)); $Qdrop->execute(); } for ($i = 0, $n = sizeof($sql_array); $i < $n; $i++) { $osC_Database->simpleQuery($sql_array[$i]); } OSCOM_Registry::get('Session')->close(); // empty the sessions table $Qsessions = $osC_Database->query('delete from :table_sessions'); $Qsessions->bindTable(':table_sessions', TABLE_SESSIONS); $Qsessions->execute(); // empty the who's online table $Qwho = $osC_Database->query('delete from :table_whos_online'); $Qwho->bindTable(':table_whos_online', TABLE_WHOS_ONLINE); $Qwho->execute(); $Qcfg = $osC_Database->query('delete from :table_configuration where configuration_key = :configuration_key'); $Qcfg->bindTable(':table_configuration', TABLE_CONFIGURATION); $Qcfg->bindValue(':configuration_key', 'DB_LAST_RESTORE'); $Qcfg->execute(); $Qcfg = $osC_Database->query('insert into :table_configuration values ("", "Last Database Restore", "DB_LAST_RESTORE", :filename, "Last database restore file", "6", "", "", now(), "", "")'); $Qcfg->bindTable(':table_configuration', TABLE_CONFIGURATION); $Qcfg->bindValue(':filename', $filename); $Qcfg->execute(); osC_Cache::clear('configuration'); if (isset($remove_raw) && $remove_raw === true) { unlink($restore_from); } return true; } return false; }
function delete($id) { global $osC_Database, $osC_CategoryTree; $error = false; if (is_numeric($id)) { $osC_CategoryTree->setBreadcrumbUsage(false); $categories = array_merge(array(array('id' => $id, 'text' => '')), $osC_CategoryTree->getTree($id)); $products = array(); $products_delete = array(); foreach ($categories as $c_entry) { $Qproducts = $osC_Database->query('select products_id from :table_products_to_categories where categories_id = :categories_id'); $Qproducts->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES); $Qproducts->bindInt(':categories_id', $c_entry['id']); $Qproducts->execute(); while ($Qproducts->next()) { $products[$Qproducts->valueInt('products_id')]['categories'][] = $c_entry['id']; } } foreach ($products as $key => $value) { $Qcheck = $osC_Database->query('select count(*) as total from :table_products_to_categories where products_id = :products_id and categories_id not in :categories_id'); $Qcheck->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES); $Qcheck->bindInt(':products_id', $key); $Qcheck->bindRaw(':categories_id', '("' . implode('", "', $value['categories']) . '")'); $Qcheck->execute(); if ($Qcheck->valueInt('total') < 1) { $products_delete[$key] = $key; } } osc_set_time_limit(0); foreach ($categories as $c_entry) { $osC_Database->startTransaction(); $Qimage = $osC_Database->query('select categories_image from :table_categories where categories_id = :categories_id'); $Qimage->bindTable(':table_categories', TABLE_CATEGORIES); $Qimage->bindInt(':categories_id', $c_entry['id']); $Qimage->execute(); $image = $Qimage->value('categories_image'); if (!empty($image)) { $Qcheck = $osC_Database->query('select count(*) as image_count from :table_categories where categories_image = :categories_image'); $Qcheck->bindTable(':table_categories', TABLE_CATEGORIES); $Qcheck->bindValue(':categories_image', $image); $Qcheck->execute(); if ($Qcheck->valueInt('image_count') == 1) { $path = realpath('../' . DIR_WS_IMAGES . 'categories') . '\\' . $image; if (file_exists($path)) { unlink($path); } } } $Qc = $osC_Database->query('delete from :table_categories where categories_id = :categories_id'); $Qc->bindTable(':table_categories', TABLE_CATEGORIES); $Qc->bindInt(':categories_id', $c_entry['id']); $Qc->setLogging($_SESSION['module'], $id); $Qc->execute(); if ($osC_Database->isError()) { $error = true; } if ($error === false) { $Qratings = $osC_Database->query('delete from :table_categories_ratings where categories_id = :categories_id'); $Qratings->bindTable(':table_categories_ratings', TABLE_CATEGORIES_RATINGS); $Qratings->bindInt(':categories_id', $id); $Qratings->setLogging($_SESSION['module'], $id); $Qratings->execute(); if ($osC_Database->isError()) { $error = true; } } if ($error === false) { $Qcd = $osC_Database->query('delete from :table_categories_description where categories_id = :categories_id'); $Qcd->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION); $Qcd->bindInt(':categories_id', $c_entry['id']); $Qcd->setLogging($_SESSION['module'], $id); $Qcd->execute(); if (!$osC_Database->isError()) { $Qp2c = $osC_Database->query('delete from :table_products_to_categories where categories_id = :categories_id'); $Qp2c->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES); $Qp2c->bindInt(':categories_id', $c_entry['id']); $Qp2c->setLogging($_SESSION['module'], $id); $Qp2c->execute(); if (!$osC_Database->isError()) { $osC_Database->commitTransaction(); osC_Cache::clear('categories'); osC_Cache::clear('category_tree'); osC_Cache::clear('also_purchased'); osC_Cache::clear('sefu-products'); osC_Cache::clear('new_products'); if (!osc_empty($Qimage->value('categories_image'))) { $Qcheck = $osC_Database->query('select count(*) as total from :table_categories where categories_image = :categories_image'); $Qcheck->bindTable(':table_categories', TABLE_CATEGORIES); $Qcheck->bindValue(':categories_image', $Qimage->value('categories_image')); $Qcheck->execute(); if ($Qcheck->numberOfRows() === 0) { if (file_exists(realpath('../' . DIR_WS_IMAGES . 'categories/' . $Qimage->value('categories_image')))) { @unlink(realpath('../' . DIR_WS_IMAGES . 'categories/' . $Qimage->value('categories_image'))); } } } } else { $osC_Database->rollbackTransaction(); } } else { $osC_Database->rollbackTransaction(); } } else { $osC_Database->rollbackTransaction(); } } foreach ($products_delete as $id) { osC_Products_Admin::delete($id); } osC_Cache::clear('categories'); osC_Cache::clear('category_tree'); osC_Cache::clear('also_purchased'); osC_Cache::clear('sefu-products'); osC_Cache::clear('new_products'); return true; } return false; }
$db_selected = @osc_db_select_db(trim($_POST['mysql_db'])); if (!$db_selected) { $error = $error . '<BR>Can\'t use the database specified. Error: ' . mysql_error(); } //mysql_close($link); } $baseURL = trim($_POST['base_url']); $mysqlHost = trim($_POST['mysql_host']); $mysqlUname = trim($_POST['mysql_uname']); $mysqlPass = trim($_POST['mysql_password']); $mysqlDB = trim($_POST['mysql_db']); if ($error == '') { $basePath = dirname(__FILE__); $db_error = false; $sql_file = $basePath . '/install.sql'; osc_set_time_limit(); osc_db_install($mysqlDB, $sql_file); /* Create the config file */ $file1 = file_get_contents($basePath . '/temp/config1.cfg'); $file2 = trim($_POST['base_url']); $file3 = file_get_contents($basePath . '/temp/config2.cfg'); $file4 = '$config[\'hostname\'] = "' . trim($_POST['mysql_host']) . '"; $config[\'db_username\'] = "' . trim($_POST['mysql_uname']) . '"; $config[\'db_password\'] = "' . trim($_POST['mysql_password']) . '"; $config[\'db\'] = "' . trim($_POST['mysql_db']) . '";'; $file5 = file_get_contents($basePath . '/temp/config3.cfg'); $file9 = $folder; $file8 = file_get_contents($basePath . '/temp/config7.cfg'); $file6 = trim($_POST['folder']); $file7 = file_get_contents($basePath . '/temp/config4.cfg'); $configFile = $file1 . $file2 . $file3 . $file4 . $file5 . $file9 . $file8 . $file6 . $file7;