[ PHPXref.com ] [ Generated: Sun Jul 20 19:12:48 2008 ] [ OSC 2.0.5 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/SQL/ -> Upgrade-Helper.php (source)

   1  <?php
   2  /*******************************************************************************
   3   *
   4   *  filename    : Upgrade-Helper.php
   5   *  last change : 2003-03-29
   6   *  website     : http://www.infocentral.org
   7   *  copyright   : Copyright 2003 Chris Gebhardt (http://www.openserve.org)
   8   *
   9   *  function    : Does some maintenance on the database for certain upgrades.
  10   *
  11   *  InfoCentral is free software; you can redistribute it and/or modify
  12   *  it under the terms of the GNU General Public License as published by
  13   *  the Free Software Foundation; either version 2 of the License, or
  14   *  (at your option) any later version.
  15  ******************************************************************************/
  16  
  17  require  "../Include/Config.php";
  18  require  "../Include/Functions.php";
  19  
  20  // Security: user must be administrator to use this page
  21  if (!$_SESSION['bAdmin'])
  22  {
  23      Redirect("Menu.php");
  24      exit;
  25  }
  26  
  27  $iOperation = $_POST["Operation"];
  28  switch($iOperation)
  29  {
  30      case 1:
  31          $sSQL = "SELECT per_ID FROM person_per";
  32          $rsPeople = RunQuery($sSQL);
  33  
  34          // Create custom fields table entries for everyone currently in the database.
  35          while ($person = mysql_fetch_array($rsPeople))
  36          {
  37              $sSQL = "INSERT INTO `person_custom` (`per_ID`)    VALUES ('" . $person[0] . "');";
  38              RunQuery($sSQL,false); // this will silently fail if record already exists; not a problem
  39          }
  40      break;
  41  
  42      case 2:
  43          $sSQL = "SELECT * FROM classification_cls ORDER BY cls_ID";
  44          $result = RunQuery($sSQL);
  45          $count = 1;
  46          while($aRow = mysql_fetch_array($result))
  47          {
  48              extract($aRow);
  49              $sSQL = "INSERT INTO list_lst VALUES (1, $cls_ID, $count,'$cls_Description')";
  50              RunQuery($sSQL);
  51              $count++;
  52          }
  53          echo "Done with classifications. ";
  54  
  55          $sSQL = "SELECT * FROM familyrole_fmr ORDER BY fmr_Sequence";
  56          $result = RunQuery($sSQL);
  57          $count = 1;
  58          while($aRow = mysql_fetch_array($result))
  59          {
  60              extract($aRow);
  61              $sSQL = "INSERT INTO list_lst VALUES (2, $fmr_ID, $count,'$fmr_Description')";
  62              RunQuery($sSQL);
  63              $count++;
  64          }
  65          echo "Done with family roles. ";
  66  
  67           // Get the first available lst_ID for translating group-role lists.  lst_ID 0-9 are reserved for permanent lists.
  68          $sSQL = "SELECT MAX(lst_ID) FROM list_lst";
  69          $aTemp = mysql_fetch_array(RunQuery($sSQL));
  70          if ($aTemp[0] > 9)
  71              $newListID = $aTemp[0] + 1;
  72          else
  73              $newListID = 10;
  74  
  75          $sSQL = "SELECT grp_ID, grp_DefaultRole FROM group_grp";
  76          $rsGroups = RunQuery($sSQL);
  77  
  78          while($aGroup = mysql_fetch_array($rsGroups))
  79          {
  80              extract($aGroup);
  81  
  82              $sSQL = "SELECT * FROM role_rle WHERE rle_grp_ID = $grp_ID ORDER BY rle_Sequence";
  83              $result = RunQuery($sSQL);
  84              $count = 1;
  85              $newDefaultID = 1;
  86  
  87              while($aRole = mysql_fetch_array($result))
  88              {
  89                  extract($aRole);
  90                  $sSQL = "INSERT INTO list_lst VALUES ($newListID, $count, $count,'$rle_Name')";
  91                  RunQuery($sSQL);
  92  
  93                  // if we've just processed the old grp_defaultrole, store the new OptionID so we can fix the group table
  94                  if ($rle_ID == $grp_DefaultRole)
  95                      $newDefaultID = $count;
  96  
  97                  // Update any group members who were using the old rle_ID.. translate to the new one.
  98                  $sSQL = "UPDATE person2group2role_p2g2r SET p2g2r_rle_ID=$count WHERE p2g2r_rle_ID=$rle_ID";
  99                  RunQuery($sSQL);
 100  
 101                  $count++;
 102              }
 103  
 104              // reset default role and set the group's RoleList_ID
 105              $sSQL = "UPDATE group_grp SET grp_DefaultRole=$newDefaultID, grp_RoleListID=$newListID WHERE grp_ID = $grp_ID";
 106              RunQuery($sSQL);
 107  
 108              $newListID++;
 109          }
 110          echo "Done with group roles. Import complete!";
 111  
 112      break;
 113  
 114      case 3:
 115          $sSQL = "DROP TABLE `role_rle`";
 116          RunQuery($sSQL);
 117          $sSQL = "DROP TABLE `classification_cls`";
 118          RunQuery($sSQL);
 119          $sSQL = "DROP TABLE `familyrole_fmr`";
 120          RunQuery($sSQL);
 121      break;
 122  
 123      case 4:
 124          $dirsToProcess = array('../Images/Person', '../Images/Family');
 125          foreach($dirsToProcess as $dir)
 126          {
 127              if ($dh = opendir($dir))
 128              {
 129                  while (($file = readdir($dh)) != false)
 130                  {
 131                      if (substr($file,-3) == "jpg") {
 132                          $srcImage=imagecreatefromjpeg($dir . '/' . $file);
 133                          $src_w=imageSX($srcImage);
 134                          $src_h=imageSY($srcImage);
 135  
 136                          // Calculate thumbnail's height and width (a "maxpect" algorithm)
 137                          $dst_max_w = 200;
 138                          $dst_max_h = 350;
 139                          if ($src_w > $dst_max_w) {
 140                              $thumb_w=$dst_max_w;
 141                              $thumb_h=$src_h*($dst_max_w/$src_w);
 142                              if ($thumb_h > $dst_max_h) {
 143                                  $thumb_h = $dst_max_h;
 144                                  $thumb_w = $src_w*($dst_max_h/$src_h);
 145                              }
 146                          }
 147                          elseif ($src_h > $dst_max_h) {
 148                              $thumb_h=$dst_max_h;
 149                              $thumb_w=$src_w*($dst_max_h/$src_h);
 150                              if ($thumb_w > $dst_max_w) {
 151                                  $thumb_w = $dst_max_w;
 152                                  $thumb_h = $src_h*($dst_max_w/$src_w);
 153                              }
 154                          }
 155                          else {
 156                              if ($src_w > $src_h) {
 157                                  $thumb_w = $dst_max_w;
 158                                  $thumb_h = $src_h*($dst_max_w/$src_w);
 159                              } elseif ($src_w < $src_h) {
 160                                  $thumb_h = $dst_max_h;
 161                                  $thumb_w = $src_w*($dst_max_h/$src_h);
 162                              } else {
 163                                  if ($dst_max_w >= $dst_max_h) {
 164                                      $thumb_w=$dst_max_h;
 165                                      $thumb_h=$dst_max_h;
 166                                  } else {
 167                                      $thumb_w=$dst_max_w;
 168                                      $thumb_h=$dst_max_w;
 169                                  }
 170                              }
 171                          }
 172                          $dstImage=ImageCreateTrueColor($thumb_w,$thumb_h);
 173                          imagecopyresampled($dstImage,$srcImage,0,0,0,0,$thumb_w,$thumb_h,$src_w,$src_h);
 174                          imagejpeg($dstImage,$dir . "/thumbnails/" . $file);
 175                          imagedestroy($dstImage);
 176                          imagedestroy($srcImage);
 177                      }
 178                  }
 179                  closedir($dh);
 180              }
 181              else
 182                  echo "couldn't open $dir";
 183          }
 184      break;
 185  
 186      default:
 187      break;
 188  }
 189  
 190  
 191  // Determine what work needs done..
 192  
 193  // Check for old lists that need converted.
 194  $bOldLists = false;
 195  $result = mysql_list_tables($sDATABASE);
 196  if (!$result) {
 197      print "DB Error, could not list tables\n";
 198      print 'MySQL Error: ' . mysql_error();
 199      exit;
 200  }
 201  while ($row = mysql_fetch_row($result)) {
 202      if ($row[0] == 'role_rle') $bOldLists = true;
 203  }
 204  
 205  // Check for missing custom person field entries
 206  $sSQL = "SELECT '' FROM person_per";
 207  $rsPeople = RunQuery($sSQL);
 208  $sSQL = "SELECT '' FROM person_custom";
 209  $rsCustom = RunQuery($sSQL);
 210  if (mysql_num_rows($rsPeople) != mysql_num_rows($rsCustom))
 211      $bMissingCustomFields = true;
 212  
 213  // Check if there are images but no thumbnails. (from old image handling routine)
 214  $count = 0;
 215  if ($dh = opendir('../Images/Person')) {
 216      while (($file = readdir($dh)) != false) {
 217          if (substr($file,-3) == "jpg")
 218              $count++;
 219      }
 220  }
 221  if ($dh = opendir('../Images/Person/thumbnails')) {
 222      while (($file = readdir($dh)) != false) {
 223          if (substr($file,-3) == "jpg")
 224              $count--;
 225      }
 226  }
 227  if ($count > 0) $bMissingThumbnails = true;
 228  
 229  require  "../Include/Header-Short.php";
 230  ?>
 231  
 232  <br><br>
 233  <center><h2>Upgrade-Helper:  A database maintenance utility for InfoCentral upgraders</h2></center>
 234  <br><br>
 235  
 236  <?php if ($bOldLists || $bMissingCustomFields || $bMissingThumbnails) { ?>
 237  <table align="center" width="80%"><tr><td>
 238  
 239  <?php if ($bMissingCustomFields) { ?>
 240  <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" name="UpgradeHelper">
 241  <input type="hidden" name="Operation" value="1">
 242  <input type="submit" class="icButton" value="Perform">
 243  Create custom fields table entries for everyone currently in the database.
 244  </form>
 245  <?php } ?>
 246  
 247  <?php if ($bOldLists && $iOperation != 2) { ?>
 248  <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" name="UpgradeHelper">
 249  <input type="hidden" name="Operation" value="2">
 250  <input type="submit" class="icButton" value="Perform">
 251  Import your old Classifications, Family Roles, and Group Roles to the new Lists Master Table (list_lst).
 252  </form>
 253  <?php } ?>
 254  
 255  <?php if ($bOldLists && $iOperation == 2) { ?>
 256  <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" name="UpgradeHelper">
 257  <input type="hidden" name="Operation" value="3">
 258  &nbsp;&nbsp;&nbsp;<input type="submit" class="icButton" value="Perform">
 259  Delete your old Classifications, Family Roles, and Group Roles tables.
 260  </form>
 261  <?php } ?>
 262  
 263  <?php if ($bMissingThumbnails) { ?>
 264  <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" name="UpgradeHelper">
 265  <input type="hidden" name="Operation" value="4">
 266  &nbsp;&nbsp;&nbsp;<input type="submit" class="icButton" value="Perform">
 267  Create thumbnails of previously uploaded person and family pictures.
 268  </form>
 269  <?php } ?>
 270  
 271  </td></tr></table>
 272  <?php }
 273  else echo "<center><h3>No additional maintenance required.</h3></center>";
 274  
 275  require  "../Include/Footer-Short.php";
 276  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]