Ejemplo n.º 1
0
 function save_records($backup_file, $tables_array, $where_array)
 {
     extract(tep_load('database', 'message_stack'));
     tep_set_time_limit(0);
     if (!is_array($tables_array) || !is_array($where_array) || count($tables_array) != count($where_array)) {
         return false;
     }
     $fp = fopen($backup_file, 'a');
     if (!$fp) {
         return false;
     }
     for ($p = 0, $q = count($tables_array); $p < $q; $p++) {
         $table = $tables_array[$p];
         $table_list = array();
         $fields_array = $db->query_to_array("show fields from " . $table);
         for ($i = 0, $j = count($fields_array); $i < $j; $i++) {
             $table_list[] = $fields_array[$i]['Field'];
         }
         // dump the data
         $where = $where_array[$p];
         if (!empty($where)) {
             $where = " where " . $where;
         }
         $data_query = $db->query("select " . implode(',', $table_list) . " from " . $table . $where);
         if ($db->num_rows($data_query)) {
             $schema = 'insert into ' . $table . ' (' . implode(', ', $table_list) . ') values ' . "\n";
             $write_flag = false;
             while ($data_array = $db->fetch_array($data_query)) {
                 $tmp_schema = '(';
                 $write_flag = true;
                 reset($table_list);
                 while (list(, $i) = each($table_list)) {
                     if (!isset($data_array[$i])) {
                         $tmp_schema .= 'NULL, ';
                     } elseif (tep_not_null($data_array[$i])) {
                         $row = addslashes($data_array[$i]);
                         $row = preg_replace("/\n#/", "\n" . '\\#', $row);
                         $tmp_schema .= '\'' . $row . '\', ';
                     } else {
                         $tmp_schema .= '\'\', ';
                     }
                 }
                 $tmp_schema = preg_replace('/, $/', '', $tmp_schema) . '),' . "\n";
                 if (strlen($schema) + strlen($tmp_schema) > $this->max_packet) {
                     $write_flag = false;
                     $schema = substr($schema, 0, -2);
                     $schema .= ';' . "\n\n";
                     fputs($fp, $schema);
                     $schema = 'insert into ' . $table . ' (' . implode(', ', $table_list) . ') values ' . "\n";
                 }
                 $schema .= $tmp_schema;
             }
             if ($write_flag) {
                 $schema = substr($schema, 0, -2);
                 $schema .= ';' . "\n\n";
                 fputs($fp, $schema);
             }
         }
     }
     fclose($fp);
     return true;
 }
Ejemplo n.º 2
0
      <tr>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main" valign="middle"><?php 
    echo tep_image(DIR_WS_ICONS . 'ani_send_email.gif', IMAGE_ANI_SEND_EMAIL);
    ?>
</td>
            <td class="main" valign="middle"><b><?php 
    echo TEXT_PLEASE_WAIT;
    ?>
</b></td>
          </tr>
        </table></td>
      </tr>
<?php 
    tep_set_time_limit(0);
    flush();
    $module->send($nInfo->affiliate_newsletters_id);
    ?>
      <tr>
        <td><?php 
    echo tep_draw_separator('pixel_trans.gif', '1', '10');
    ?>
</td>
      </tr>
      <tr>
        <td class="main"><font color="#ff0000"><b><?php 
    echo TEXT_FINISHED_SENDING_EMAILS;
    ?>
</b></font></td>
      </tr>
Ejemplo n.º 3
0
 $total = 0;
 $all_products = array();
 $i = 0;
 $cells = array();
 $fp = fopen($_FILES['products_file']['tmp_name'], 'r');
 while (($cell = fgetcsv($fp, 10000, ";")) !== FALSE) {
     $cell[0] = str_replace('–', '-', trim($cell[0]));
     if ($i > 0) {
         $cells[] = array_merge(array(''), $cell);
     }
     $i++;
 }
 fclose($fp);
 //		  echo '<pre>' . print_r($cells, true) . '</pre>';
 //		  die();
 tep_set_time_limit(9600);
 $cells_count = 0;
 reset($cells);
 while (list($i, $cell) = each($cells)) {
     if (tep_not_null($cell[1])) {
         $products_model = tep_db_prepare_input($cell[1]);
         $products_model_1 = preg_replace('/[^\\d]/', '', $products_model);
         $products_name = preg_replace('/\\s+/', ' ', tep_db_input($cell[2]));
         $products_name = htmlspecialchars(stripslashes($products_name));
         $authors_name = tep_db_prepare_input($cell[3]);
         $manufacturers_name = tep_db_prepare_input($cell[4]);
         $products_year = tep_db_prepare_input($cell[5]);
         $products_url = tep_db_prepare_input($cell[6]);
         $image_big = tep_db_prepare_input($cell[7]);
         $products_price = str_replace(',', '.', trim($cell[8]));
         $products_currency = tep_db_prepare_input($cell[9]);
Ejemplo n.º 4
0
	  if (strpos($content, '<div class="legend">')) {
		list(, $descr) = explode('<div class="legend">', $content);
		list($descr) = explode('</div></td></tr></table><div style="margin-top:40px">', $descr);
		$descr = preg_replace('/<a [^>]+>/i', '', $descr);
		$descr = str_ireplace(array('<b>', '</b>', '</a>', '<br>'), array('<strong>', '</strong>', '', '<br />'), $descr);
	  }
	  if (preg_match('/<p class="item_price"[^>]*>Цена: ([\s\.\d]+) р.[^<]*<\/p>/', $content, $regs)) $price = str_replace(',', '.', (float)preg_replace('/\s+/', '', $regs[1]));
	  $j ++;
//	  if ($j > 10) die();
	}
	fputcsv($fp, array($i, $name, $descr, $regs1[1], $price, $regs1[2], $regs1[3], $regs1[4], $regs1[5], $regs1[6], $regs1[7], $compl), ';');
  }
  fclose($fp);
  die();
*/
tep_set_time_limit(6000);
$listed_products = array();
$fp = fopen(UPLOAD_DIR . 'csv/forum.csv', 'r');
while (list($products_id) = fgetcsv($fp, 16, ';')) {
    $listed_products[] = $products_id;
}
fclose($fp);
$fp = fopen(UPLOAD_DIR . 'csv/forum.csv', 'a+');
//  $fp = fopen('electronics/forum.csv', 'a+');
//  fputcsv($fp, array('артикул', 'наименование', 'описание', 'картинка', 'вес', 'производитель', 'Раздел'), ';');
for ($i = 55493; $i < 81500; $i++) {
    if (!in_array($i, $listed_products)) {
        //	  echo $content = tep_request_html('http://forum3.ru/descr.aspx?code=' . $i);
        $content = implode('', file('http://forum3.ru/descr.aspx?code=' . $i));
        if (!strpos($content, '<title>404')) {
            preg_match("/<td class=catalogue>\\s+([^\n]+)\\s+<br>/i", $content, $regs);
Ejemplo n.º 5
0
<?php

$updated = 0;
$added = 0;
$not_added = 0;
$total = 0;
$begin_time = time();
$fp = fopen($filename, 'r');
tep_set_time_limit(3600);
$cells_count = 0;
while (($cell = fgetcsv($fp, 1000, ";")) !== FALSE) {
    $authors_code = (int) tep_db_prepare_input($cell[0]);
    if ($authors_code > 0 && strlen($cell[1]) > 2) {
        $authors_code = 'bat' . sprintf('%010d', (int) $authors_code);
        $authors_name = trim(html_entity_decode(preg_replace('/\\s{2,}/', ' ', tep_db_prepare_input($cell[1])), ENT_QUOTES));
        if (tep_not_null($authors_name)) {
            $i = 0;
            do {
                $letter = strtoupper(substr($authors_name, $i, 1));
                $i++;
                if ($i >= strlen($authors_name)) {
                    break;
                }
            } while (!preg_match('/^[абвгдеёжзийклмнопрстуфхцчшщъыьэюяa-z0-9].*/i', $letter));
        }
        $authors_name = trim(str_replace('&quot;', '', str_replace('"', '', $authors_name)));
        $authors_name = htmlspecialchars(stripslashes($authors_name), ENT_QUOTES);
        $authors_check_query = tep_db_query("select authors_id from " . TABLE_AUTHORS . " where authors_code = '" . tep_db_input($authors_code) . "'");
        if (tep_db_num_rows($authors_check_query) < 1) {
            $authors_check_query = tep_db_query("select authors_id, authors_code from " . TABLE_AUTHORS . " where authors_name = '" . tep_db_input($authors_name) . "' and language_id = '" . (int) $languages_id . "'");
        }
Ejemplo n.º 6
0
define('TIME_LIMIT', 600);
// Ограничение размера данных доставаемых за одно обращения к БД (в мегабайтах)
// Нужно для ограничения количества памяти пожираемой сервером при дампе очень объемных таблиц
define('LIMIT', 1);
// Кодировка соединения с MySQL
// auto - автоматический выбор (устанавливается кодировка таблицы), cp1251 - windows-1251, и т.п.
define('DB_CHARSET', 'auto');
// Кодировка соединения с MySQL при восстановлении
// На случай переноса со старых версий MySQL (до 4.1), у которых не указана кодировка таблиц в дампе
// При добавлении 'forced->', к примеру 'forced->cp1251', кодировка таблиц при восстановлении будет принудительно заменена на cp1251
// Можно также указывать сравнение нужное к примеру 'cp1251_ukrainian_ci' или 'forced->cp1251_ukrainian_ci'
define('RESTORE_CHARSET', 'cp1251');
// Типы таблиц у которых сохраняется только структура, разделенные запятой
define('ONLY_CREATE', 'MRG_MyISAM,MERGE,HEAP,MEMORY');
// Дальше ничего редактировать не нужно
tep_set_time_limit(TIME_LIMIT);
if (function_exists("ob_implicit_flush")) {
    ob_implicit_flush();
}
if (!function_exists('tep_db_fetch_row')) {
    function tep_db_fetch_row($db_query)
    {
        return mysql_fetch_row($db_query);
    }
}
$dump = new dumper();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
switch ($action) {
    case 'backup':
        $dump->backup();
        break;
Ejemplo n.º 7
0
 function data_exec($data, $display = false)
 {
     tep_set_time_limit(0);
     $sql_line = $query = '';
     $background = '#FFC';
     $sql_count = 0;
     $data_array = preg_split("/((\r(?!\n))|((?<!\r)\n)|(\r\n))/", $data);
     foreach ($data_array as $sql_line) {
         $background = $sql_count % 2 ? 'EFE' : 'EFF';
         $line = trim($sql_line);
         if (!empty($line) && substr($line, 0, 2) != "--" && substr($line, 0, 1) != "#") {
             $query .= $sql_line;
             if (preg_match("/;\\s*\$/", $sql_line)) {
                 if ($display) {
                     $tmp_array = explode("\r\n", htmlspecialchars($query));
                     $display_string = implode('<br />', $tmp_array);
                     echo '<div style="background: #' . $background . '"><b style="color: #CC0000; font-weight: bold">' . ($sql_count + 1) . '. DB-Executive: </b><br />' . $display_string . '</div>' . "\n";
                 }
                 $this->query($query);
                 $query = '';
                 $sql_count++;
             }
         }
     }
 }