Ignore:
Timestamp:
Apr 12, 2011, 10:44:12 PM (13 years ago)
Author:
Eric
Message:

r10342 merged from trunk to branch 2.20

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/UserAdvManager/branches/2.20/include/functions.inc.php

    r10145 r10343  
    24032403
    24042404/**
     2405 * UAM specific database dump (only for MySql !)
     2406 * Creates an SQL dump of UAM specific tables and configuration settings
     2407 *
     2408 * @returns  : Boolean to manage appropriate message display
     2409 *
     2410 */
     2411function uam_dump($download)
     2412{
     2413  global $conf;
     2414 
     2415  // Initial backup folder creation and file initialisation
     2416  if (!is_dir(UAM_PATH.'/include/backup'))
     2417    mkdir(UAM_PATH.'/include/backup');
     2418
     2419  $Backup_File = UAM_PATH.'/include/backup/UAM_dbbackup.sql';
     2420
     2421  $fp = fopen($Backup_File, 'w');
     2422
     2423
     2424  // Saving UAM specific tables
     2425  $ListTables = array(USER_CONFIRM_MAIL_TABLE, USER_LASTVISIT_TABLE);
     2426  $j=0;
     2427 
     2428  while($j < count($ListTables))
     2429  {
     2430    $sql = 'SHOW CREATE TABLE '.$ListTables[$j];
     2431    $res = pwg_query($sql);
     2432
     2433    if ($res)
     2434    {
     2435      $insertions = "-- -------------------------------------------------------\n";
     2436      $insertions .= "-- Create ".$ListTables[$j]." table\n";
     2437      $insertions .= "-- ------------------------------------------------------\n\n";
     2438
     2439      $insertions .= "DROP TABLE IF EXISTS ".$ListTables[$j].";\n\n";
     2440
     2441      $array = mysql_fetch_array($res);
     2442      $array[1] .= ";\n\n";
     2443      $insertions .= $array[1];
     2444
     2445      $req_table = pwg_query('SELECT * FROM '.$ListTables[$j]) or die(mysql_error());
     2446      $nb_fields = mysql_num_fields($req_table);
     2447      while ($line = mysql_fetch_array($req_table))
     2448      {
     2449        $insertions .= 'INSERT INTO '.$ListTables[$j].' VALUES (';
     2450        for ($i=0; $i<$nb_fields; $i++)
     2451        {
     2452          $insertions .= '\'' . mysql_real_escape_string($line[$i]) . '\', ';
     2453        }
     2454        $insertions = substr($insertions, 0, -2);
     2455        $insertions .= ");\n";
     2456      }
     2457      $insertions .= "\n\n";
     2458    }
     2459
     2460    fwrite($fp, $insertions);   
     2461    $j++;
     2462  }
     2463 
     2464  // Saving UAM configuration
     2465  $insertions = "-- -------------------------------------------------------\n";
     2466  $insertions .= "-- Insert UAM configuration in ".CONFIG_TABLE."\n";
     2467  $insertions .= "-- ------------------------------------------------------\n\n";
     2468
     2469  fwrite($fp, $insertions);
     2470
     2471  $pattern = "UserAdvManager%";
     2472  $req_table = pwg_query('SELECT * FROM '.CONFIG_TABLE.' WHERE param LIKE "'.$pattern.'";') or die(mysql_error());
     2473  $nb_fields = mysql_num_fields($req_table);
     2474
     2475  while ($line = mysql_fetch_array($req_table))
     2476  {
     2477    $insertions = 'INSERT INTO '.CONFIG_TABLE.' VALUES (';
     2478    for ($i=0; $i<$nb_fields; $i++)
     2479    {
     2480      $insertions .= '\'' . mysql_real_escape_string($line[$i]) . '\', ';
     2481    }
     2482    $insertions = substr($insertions, 0, -2);
     2483    $insertions .= ");\n";
     2484
     2485    fwrite($fp, $insertions);
     2486  }
     2487
     2488  fclose($fp);
     2489
     2490  // Download generated dump file
     2491  if ($download == 'true')
     2492  {
     2493    if (@filesize($Backup_File))
     2494    {
     2495      $http_headers = array(
     2496        'Content-Length: '.@filesize($Backup_File),
     2497        'Content-Type: text/x-sql',
     2498        'Content-Disposition: attachment; filename="UAM_dbbackup.sql";',
     2499        'Content-Transfer-Encoding: binary',
     2500        );
     2501
     2502      foreach ($http_headers as $header)
     2503      {
     2504        header($header);
     2505      }
     2506
     2507      @readfile($Backup_File);
     2508      exit();
     2509    }
     2510  }
     2511
     2512  return true;
     2513}
     2514
     2515
     2516/**
    24052517 * Useful for debugging - 4 vars can be set
    24062518 * Output result to log.txt file
Note: See TracChangeset for help on using the changeset viewer.