4images PHP Cross Reference Image Galleries

Source: /update_RC-1_to_RC-2.php - 273 lines - 9852 bytes - Summary - Text - Print

   1  <?php
   2  /**************************************************************************
   3   *                                                                        *
   4   *    4images - A Web Based Image Gallery Management System               *
   5   *    ----------------------------------------------------------------    *
   6   *                                                                        *
   7   *             File: update_RC-1_to_RC-2.php                              *
   8   *        Copyright: (C) 2002-2012 Jan Sorgalla                           *
   9   *            Email: jan@4homepages.de                                    * 
  10   *              Web: http://www.4homepages.de                             * 
  11   *    Scriptversion: 1.7.11                                               *
  12   *                                                                        *
  13   *    Never released without support from: Nicky (http://www.nicky.net)   *
  14   *                                                                        *
  15   **************************************************************************
  16   *                                                                        *
  17   *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
  18   *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
  19   *    ---------------------------------------------------------------     *
  20   *    This script is NOT freeware! Please read the Copyright Notice       *
  21   *    (Licence.txt) for further information.                              *
  22   *                                                                        *
  23   *************************************************************************/
  24  
  25  error_reporting(E_ERROR | E_WARNING | E_PARSE);
  26  set_magic_quotes_runtime(0);
  27  define('ROOT_PATH', './');
  28  
  29  if (isset($HTTP_GET_VARS['action']) || isset($HTTP_POST_VARS['action'])) {
  30    $action = (isset($HTTP_GET_VARS['action'])) ? trim($HTTP_GET_VARS['action']) : trim($HTTP_POST_VARS['action']);
  31  }
  32  else {
  33    $action = "intro";
  34  }
  35  
  36  if (@file_exists(ROOT_PATH."config.php")) {
  37    @include(ROOT_PATH.'config.php');
  38  }
  39  if (!defined("4IMAGES_ACTIVE")) {
  40    header("Location: install.php");
  41    exit;
  42  }
  43  if ($action == "finish") {
  44    header("Location: index.php");
  45    exit;
  46  }
  47  include (ROOT_PATH.'includes/constants.php');
  48  define('MEDIA_PATH', ROOT_PATH.MEDIA_DIR);
  49  define('THUMB_PATH', ROOT_PATH.THUMB_DIR);
  50  
  51  include (ROOT_PATH.'includes/search_utils.php');
  52  include(ROOT_PATH.'includes/db_'.$db_servertype.'.php');
  53  $site_db = new Db($db_host, $db_user, $db_password, $db_name);
  54  
  55  $sql_add = array();
  56  $sql_edit = array();
  57  //$sql[] = "DROP TABLE IF EXISTS ".$table_prefix."wordlist";
  58  $sql_add[$table_prefix.'wordlist'] = "CREATE TABLE ".$table_prefix."wordlist (
  59                                        word_text varchar(50) binary NOT NULL default '',
  60                                        word_id mediumint(8) unsigned NOT NULL auto_increment,
  61                                        word_common tinyint(1) unsigned NOT NULL default '0',
  62                                        PRIMARY KEY  (word_text),
  63                                        KEY word_id (word_id)
  64                                        ) TYPE=MyISAM";
  65  //$sql[] = "DROP TABLE IF EXISTS ".$table_prefix."wordmatch";
  66  $sql_add[$table_prefix.'wordmatch'] = "CREATE TABLE ".$table_prefix."wordmatch (
  67                                         image_id mediumint(8) unsigned NOT NULL default '0',
  68                                         word_id mediumint(8) unsigned NOT NULL default '0',
  69                                         name_match tinyint(1) NOT NULL default '0',
  70                                         desc_match tinyint(1) NOT NULL default '0',
  71                                         keys_match tinyint(1) NOT NULL default '0',
  72                                         KEY word_id (word_id)
  73                                         ) TYPE=MyISAM";
  74  $sql_edit[] = "ALTER TABLE ".SESSION_VARS_TABLE."
  75                 TYPE=MyISAM";
  76  $sql_edit[] = "ALTER TABLE ".SESSION_VARS_TABLE."
  77                 MODIFY sessionvars_value text";
  78  
  79  function next_step($action, $msg) {
  80    global $PHP_SELF;
  81  ?>
  82  <br />
  83  <table width="400" border="0" cellspacing="0" cellpadding="1" align="center">
  84    <tr>
  85      <td class="tableseparator">
  86        <table width="100%" border="0" cellspacing="0" cellpadding="3">
  87          <tr>
  88            <td class="tablerow2" align="center">
  89              <?php echo "Next step: <a href=\"".$PHP_SELF."?action=".$action."\"><b>".$msg."</b></a>\n"; ?>
  90            </td>
  91          </tr>
  92        </table>
  93      </td>
  94    </tr>
  95  </table>
  96  <br />
  97  <?php
  98  }
  99  
 100  ?>
 101  <html>
 102    <head>
 103    <meta content="text/html; charset=windows-1252" http-equiv="Content-Type">
 104    <link rel="stylesheet" href="admin/cpstyle.css">
 105    <title>4images Update RC-1 to RC-2</title>
 106  </head>
 107  <body leftmargin="20" topmargin="20" marginwidth="20" marginheight="20" bgcolor="#FFFFFF">
 108  <table width="400" border="0" cellspacing="0" cellpadding="1" align="center">
 109    <tr>
 110      <td>
 111  <p align="center"><span class="headline">4images Update RC-1 to RC-2</span></p><br /><br />
 112  <?php
 113  
 114  if ($action == "intro") {
 115    next_step("createcategories", "Create category folders");
 116  }
 117  
 118  if ($action == "createcategories") {
 119    $result = $site_db->query("SELECT cat_id, cat_name
 120                               FROM ".CATEGORIES_TABLE."
 121                               ORDER BY cat_name ASC");
 122    if (!is_writable(MEDIA_PATH)) {
 123      umask(0111);
 124      @chmod(MEDIA_PATH, 0777);
 125    }
 126    if (!is_writable(THUMB_PATH)) {
 127      umask(0111);
 128      @chmod(THUMB_PATH, 0777);
 129    }
 130    while ($row = $site_db->fetch_array($result)){
 131      echo "Create folder for ".$row['cat_name'].": .......... \n";
 132      flush();
 133      $oldumask = umask(0);
 134      echo (@mkdir(MEDIA_PATH."/".$row['cat_id'], 0777) && @mkdir(THUMB_PATH."/".$row['cat_id'], 0777)) ? "<b>OK</b><br />\n" : "<b><span class=\"marktext\">Failed</span></b><br />\n";
 135      umask($oldumask);
 136    }
 137  
 138    next_step("copyimages", "Copy Images");
 139  }
 140  
 141  if ($action == "copyimages") {
 142    $sql = "SELECT MAX(image_id) as max
 143            FROM ".IMAGES_TABLE;
 144    $result = $site_db->query_firstrow($sql);
 145  
 146    $max = $result['max'];
 147    $batchsize = 25; // Process this many posts per loop
 148    $batchcount = 0;
 149    $counter = 0;
 150  
 151    while ($counter < $max) {
 152      $batchstart = $counter + 1;
 153      $batchend = $counter + $batchsize;
 154      if ($batchend > $max) {
 155        $batchend = $max;
 156      }
 157      $batchcount++;
 158  
 159      echo "Copy images to category folders ($batchstart to $batchend): ";
 160      flush();
 161  
 162      $sql = "SELECT cat_id, image_media_file, image_thumb_file
 163              FROM ".IMAGES_TABLE."
 164              WHERE image_id
 165              BETWEEN $batchstart AND $batchend";
 166      $result = $site_db->query($sql);
 167      $ok = 0;
 168      if ($row = $site_db->fetch_array($result)) {
 169        do {
 170          if (!empty($row['image_media_file'])) {
 171            $ok = (copy(MEDIA_PATH."/".$row['image_media_file'], MEDIA_PATH."/".$row['cat_id']."/".$row['image_media_file'])) ? 1 : 0;
 172            if ($ok) {
 173              unlink(MEDIA_PATH."/".$row['image_media_file']);
 174              chmod(MEDIA_PATH."/".$row['cat_id']."/".$row['image_media_file'], 0777);
 175            }
 176          }
 177  
 178          if (!empty($row['image_thumb_file'])) {
 179            $ok = (copy(THUMB_PATH."/".$row['image_thumb_file'], THUMB_PATH."/".$row['cat_id']."/".$row['image_thumb_file'])) ? 1 : 0;
 180            if ($ok) {
 181              unlink(THUMB_PATH."/".$row['image_thumb_file']);
 182              chmod(THUMB_PATH."/".$row['cat_id']."/".$row['image_thumb_file'], 0777);
 183            }
 184          }
 185  
 186          echo ".";
 187          flush();
 188        }
 189        while ($row = $site_db->fetch_array($result) );
 190      }
 191      $site_db->free_result($result);
 192      $counter += $batchsize;
 193      echo ($ok) ? " <b>OK</b><br />\n" : "<b><span class=\"marktext\">Failed</span></b><br />\n";
 194    }
 195    next_step("addtables", "Add new Tables to database");
 196  }
 197  
 198  if ($action == "addtables") {
 199    foreach ($sql_add as $key => $val) {
 200      if ($site_db->query($val)) {
 201        echo "Table <b>$key</b> created!<br />\n";
 202      }
 203      else {
 204        echo "<span class=\"marktext\">An error occured while creating table <b>$key</b></span><br />\n";
 205      }
 206    }
 207    $ok = 1;
 208    foreach ($sql_edit as $val) {
 209      if (!$site_db->query($val)) {
 210        $ok = 0;
 211      }
 212    }
 213    echo ($ok) ? "Tables changed successfully!<br />\n" : "<span class=\"marktext\">An error occured while editing tables<br />\n";
 214    next_step("addsearchindex", "Add search Index");
 215  }
 216  
 217  if ($action == "addsearchindex") {
 218    $sql = "SELECT MAX(image_id) as max
 219            FROM ".IMAGES_TABLE;
 220    $result = $site_db->query_firstrow($sql);
 221  
 222    $max = $result['max'];
 223    $batchsize = 50; // Process this many posts per loop
 224    $batchcount = 0;
 225    $counter = 0;
 226  
 227    while ($counter < $max) {
 228      $batchstart = $counter + 1;
 229      $batchend = $counter + $batchsize;
 230      if ($batchend > $max) {
 231        $batchend = $max;
 232      }
 233      $batchcount++;
 234  
 235      echo "Fulltext Indexing ($batchstart to $batchend): ";
 236      flush();
 237  
 238      $sql = "SELECT *
 239              FROM ".IMAGES_TABLE."
 240              WHERE image_id
 241              BETWEEN $batchstart AND $batchend";
 242      $result = $site_db->query($sql);
 243  
 244      if ($row = $site_db->fetch_array($result)) {
 245        do {
 246          $search_words = array();
 247          foreach ($search_match_fields as $image_column => $match_column) {
 248            if (isset($row[$image_column])) {
 249              $search_words[$image_column] = $row[$image_column];
 250            }
 251          }
 252          add_searchwords($row['image_id'], $search_words);
 253          echo ".";
 254          flush();
 255        }
 256        while ($row = $site_db->fetch_array($result));
 257      }
 258      $site_db->free_result($result);
 259      $counter += $batchsize;
 260      print " <b>OK</b><br />\n";
 261    }
 262    next_step("finish", "Update complete");
 263  }
 264  ?>
 265  <br />
 266      </td>
 267    </tr>
 268  </table>
 269  <p align="center">Powered by <b>4images</b> <?php echo SCRIPT_VERSION ?><br />
 270    Copyright &copy; 2002 <a href="http://www.4homepages.de" target="_blank">4homepages.de</a>
 271  </p>
 272  </body>
 273  </html>

title

Description

title

Description

title

Description

title

title

Body