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

title

Body

[close]

/ -> PersonCustomFieldsEditor.php (source)

   1  <?php
   2  /*******************************************************************************
   3   *
   4   *  filename    : PersonCustomFieldsEditor.php
   5   *  last change : 2003-03-28
   6   *
   7   *  function    : Editor for custom person fields
   8   *
   9   *
  10   *  http://osc.sourceforge.net
  11   *
  12   *  This product is based upon work previously done by Infocentral (infocentral.org)
  13   *  on their PHP version Church Management Software that they discontinued
  14   *  and we have taken over.  We continue to improve and build upon this product
  15   *  in the direction of excellence.
  16   * 
  17   *  OpenSourceChurch (OSC) is free software; you can redistribute it and/or modify
  18   *  it under the terms of the GNU General Public License as published by
  19   *  the Free Software Foundation; either version 2 of the License, or
  20   *  (at your option) any later version.
  21   * 
  22   *  Any changes to the software must be submitted back to the OpenSourceChurch project
  23   *  for review and possible inclusion.
  24   *
  25   *  Copyright 2003 Chris Gebhardt 
  26  ******************************************************************************/
  27  
  28  require  "Include/Config.php";
  29  require  "Include/Functions.php";
  30  
  31  // Security: user must be administrator to use this page
  32  if (!$_SESSION['bAdmin'])
  33  {
  34      Redirect("Menu.php");
  35      exit;
  36  }
  37  
  38  $sPageTitle = gettext("Custom Person Fields Editor");
  39  
  40  require  "Include/Header.php";
  41  
  42  // Does the user want to save changes to text fields?
  43  if (isset($_POST["SaveChanges"]))
  44  {
  45      // Fill in the other needed custom field data arrays not gathered from the form submit
  46      $sSQL = "SELECT * FROM person_custom_master WHERE chu_Church_ID=" .$_SESSION['iChurchID'] . " ORDER BY custom_Order";
  47      $rsCustomFields = RunQuery($sSQL);
  48      $numRows = mysql_num_rows($rsCustomFields);
  49  
  50      for ($row = 1; $row <= $numRows; $row++)
  51      {
  52          $aRow = mysql_fetch_array($rsCustomFields, MYSQL_BOTH);
  53          extract($aRow);
  54  
  55          $aFieldFields[$row] = $custom_Field;
  56          $aTypeFields[$row] = $type_ID;
  57          if (isset($custom_Special))
  58              $aSpecialFields[$row] = $custom_Special;
  59          else
  60              $aSpecialFields[$row] = "NULL";
  61      }
  62  
  63      for ($iFieldID = 1; $iFieldID <= $numRows; $iFieldID++ )
  64      {
  65          $aNameFields[$iFieldID] = FilterInput($_POST[$iFieldID . "name"]);
  66  
  67          if ( strlen($aNameFields[$iFieldID]) == 0 )
  68          {
  69              $aNameErrors[$iFieldID] = true;
  70              $bErrorFlag = true;
  71          }
  72          else
  73          {
  74              $aNameErrors[$iFieldID] = false;
  75          }
  76  
  77          $aSideFields[$iFieldID] = $_POST[$iFieldID . "side"];
  78  
  79          if (isset($_POST[$iFieldID . "special"]))
  80          {
  81              $aSpecialFields[$iFieldID] = FilterInput($_POST[$iFieldID . "special"],'int');
  82  
  83              if ( $aSpecialFields[$iFieldID] == 0 )
  84              {
  85                  $aSpecialErrors[$iFieldID] = true;
  86                  $bErrorFlag = true;
  87              }
  88              else
  89              {
  90                  $aSpecialErrors[$iFieldID] = false;
  91              }
  92          }
  93      }
  94  
  95      // If no errors, then update.
  96      if (!$bErrorFlag)
  97      {
  98          for( $iFieldID=1; $iFieldID <= $numRows; $iFieldID++ )
  99          {
 100              if ($aSideFields[$iFieldID] == 0)
 101                  $temp = 'left';
 102              else
 103                  $temp = 'right';
 104  
 105              $sSQL = "UPDATE person_custom_master
 106                      SET `custom_Name` = '" . $aNameFields[$iFieldID] . "',
 107                          `custom_Special` = " . $aSpecialFields[$iFieldID] . ",
 108                          `custom_Side` = '" . $temp . "'
 109                      WHERE `custom_Field` = '" . $aFieldFields[$iFieldID] . "'" 
 110                      . " AND `chu_Church_ID`=" . $_SESSION['iChurchID'] . ";";
 111  
 112              RunQuery($sSQL);
 113          }
 114      }
 115  }
 116  
 117  else
 118  {
 119      // Check if we're adding a field
 120      if (isset($_POST["AddField"]))
 121      {
 122          $newFieldType = FilterInput($_POST["newFieldType"],'int');
 123          $newFieldName = FilterInput($_POST["newFieldName"]);
 124          $newFieldSide = $_POST["newFieldSide"];
 125  
 126          if (strlen($newFieldName) == 0)
 127          {
 128              $bNewNameError = true;
 129          }
 130          elseif (strlen($newFieldType) == 0 || $newFieldType < 1)
 131          {
 132              // This should never happen, but check anyhow.
 133              // $bNewTypeError = true;
 134          }
 135          else
 136          {
 137              $sSQL = "SELECT custom_Name FROM person_custom_master" . " WHERE chu_Church_ID=" . $_SESSION['iChurchID'];
 138              $rsCustomNames = RunQuery($sSQL);
 139              while($aRow = mysql_fetch_array($rsCustomNames))
 140              {
 141                  if ($aRow[0] == $newFieldName) {
 142                      $bDuplicateNameError = true;
 143                      break;
 144                  }
 145              }
 146  
 147              if (!$bDuplicateNameError)
 148              {
 149                  // Find the highest existing field number in the table to determine the next free one.
 150                  // This is essentially an auto-incrementing system where deleted numbers are not re-used.
 151                  $fields = mysql_list_fields($sDATABASE, "person_custom", $cnInfoCentral);
 152                  $last = mysql_num_fields($fields) - 1;
 153  
 154                  // Set the new field number based on the highest existing.  Chop off the "c" at the beginning of the old one's name.
 155                  // The "c#" naming scheme is necessary because MySQL 3.23 doesn't allow numeric-only field (table column) names.
 156                  $newFieldNum = substr(mysql_field_name($fields, $last), 1) + 1;
 157  
 158                  if ($newFieldSide == 0)
 159                      $newFieldSide = 'left';
 160                  else
 161                      $newFieldSide = 'right';
 162  
 163                  // If we're inserting a new custom-list type field, create a new list and get its ID
 164                  if ($newFieldType == 12)
 165                  {
 166                      // Get the first available lst_ID for insertion.  lst_ID 0-9 are reserved for permanent lists.
 167                      $sSQL = "SELECT MAX(lst_ID) FROM list_lst where chu_Church_ID=" . $_SESSION['iChurchID'];
 168                      $aTemp = mysql_fetch_array(RunQuery($sSQL));
 169                      if ($aTemp[0] > 9)
 170                          $newListID = $aTemp[0] + 1;
 171                      else
 172                          $newListID = 10;
 173  
 174                      // Insert into the lists table with an example option.
 175                      $sSQL = "INSERT INTO list_lst VALUES ($newListID," . $_SESSION['iChurchID'] . ",1, 1,'". gettext("Default Option") . "')";
 176                      RunQuery($sSQL);
 177  
 178                      $newSpecial = "'$newListID'";
 179                  }
 180                  else
 181                      $newSpecial = "NULL";
 182  
 183                  // Insert into the master table
 184                  $newOrderID = $last + 1;
 185                  $sSQL = "INSERT INTO `person_custom_master`
 186                          (`custom_Order` , `custom_Field` , `custom_Name` ,  `custom_Special` , `custom_Side` , `type_ID`, `chu_Church_ID`)
 187                          VALUES ('" . $newOrderID . "', 'c" . $newFieldNum . "', '" . $newFieldName . "', " . $newSpecial . ", '" . $newFieldSide . "', '" . $newFieldType . "'," . $_SESSION['iChurchID'] .");";
 188                  RunQuery($sSQL);
 189  
 190                  // Insert into the custom fields table
 191                  $sSQL = "ALTER TABLE `person_custom` ADD `c" . $newFieldNum . "` ";
 192  
 193                  switch($newFieldType)
 194                  {
 195                  case 1:
 196                      $sSQL .= "ENUM('false', 'true')";
 197                      break;
 198                  case 2:
 199                      $sSQL .= "DATE";
 200                      break;
 201                  case 3:
 202                      $sSQL .= "VARCHAR(50)";
 203                      break;
 204                  case 4:
 205                      $sSQL .= "VARCHAR(100)";
 206                      break;
 207                  case 5:
 208                      $sSQL .= "TEXT";
 209                      break;
 210                  case 6:
 211                      $sSQL .= "YEAR";
 212                      break;
 213                  case 7:
 214                      $sSQL .= "ENUM('winter', 'spring', 'summer', 'fall')";
 215                      break;
 216                  case 8:
 217                      $sSQL .= "INT";
 218                      break;
 219                  case 9:
 220                      $sSQL .= "MEDIUMINT(9)";
 221                      break;
 222                  case 10:
 223                      $sSQL .= "DECIMAL(10,2)";
 224                      break;
 225                  case 11:
 226                      $sSQL .= "VARCHAR(30)";
 227                      break;
 228                  case 12:
 229                      $sSQL .= "TINYINT(4)";
 230                  }
 231  
 232                  $sSQL .= " DEFAULT NULL ;";
 233                  RunQuery($sSQL);
 234  
 235                  $bNewNameError = false;
 236              }
 237          }
 238      }
 239  
 240      // Get data for the form as it now exists..
 241      $sSQL = "SELECT * FROM person_custom_master WHERE chu_Church_ID=" .$_SESSION['iChurchID'] . " ORDER BY custom_Order"; 
 242  
 243      $rsCustomFields = RunQuery($sSQL);
 244      $numRows = mysql_num_rows($rsCustomFields);
 245  
 246      // Create arrays of the fields.
 247      for ($row = 1; $row <= $numRows; $row++)
 248      {
 249          $aRow = mysql_fetch_array($rsCustomFields, MYSQL_BOTH);
 250          extract($aRow);
 251  
 252          $aNameFields[$row] = $custom_Name;
 253          $aSpecialFields[$row] = $custom_Special;
 254          $aFieldFields[$row] = $custom_Field;
 255          $aTypeFields[$row] = $type_ID;
 256          $aSideFields[$row] = ($custom_Side == 'right');
 257      }
 258  }
 259  
 260  // Construct the form
 261  ?>
 262  
 263  <script language="javascript">
 264  
 265  function confirmDeleteField( Field, Row ) {
 266  var answer = confirm (<?php echo "'" . gettext("Warning:  By deleting this field, you will irrevokably lose all person data assigned for this field!") . "'"; ?>)
 267  if ( answer )
 268      window.location="PersonCustomFieldsRowOps.php?Field=" + Field + "&OrderID=" + Row + "&Action=delete"
 269  }
 270  </script>
 271  
 272  <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" name="PersonCustomFieldsEditor">
 273  
 274  <table cellpadding="3" width="75%" align="center">
 275  
 276  <?php
 277  if ($numRows == 0)
 278  {
 279  ?>
 280      <center><h2><?php echo gettext("No custom person fields have been added yet"); ?></h2>
 281      <input type="button" class="icButton" value="<?php echo gettext("Exit"); ?>" Name="Exit" onclick="javascript:document.location='Menu.php';">
 282      </center>
 283  <?php
 284  }
 285  else
 286  {
 287  ?>
 288      <tr><td colspan="6">
 289      <center><b><?php echo gettext("Warning: Field changes will be lost if you do not 'Save Changes' before using an up, down, delete or 'add new' button!"); ?></b></center>
 290      </td></tr>
 291  
 292      <tr><td colspan="6">
 293      <?php
 294      if ( $bErrorFlag ) echo "<span class=\"LargeText\" style=\"color: red;\"><BR>" . gettext("Invalid fields or selections. Changes not saved! Please correct and try again!") . "</span>";
 295      ?>
 296      </td></tr>
 297  
 298          <tr>
 299              <td colspan="6" align="center">
 300              <input type="submit" class="icButton" value="<?php echo gettext("Save Changes"); ?>" Name="SaveChanges">
 301              &nbsp;
 302              <input type="button" class="icButton" value="<?php echo gettext("Exit"); ?>" Name="Exit" onclick="javascript:document.location='Menu.php';">
 303              </td>
 304          </tr>
 305  
 306          <tr>
 307              <th></th>
 308              <th></th>
 309              <th><?php echo gettext("Type"); ?></th>
 310              <th><?php echo gettext("Name"); ?></th>
 311              <th><?php echo gettext("Special option"); ?></th>
 312              <th><?php echo gettext("Person-View Side"); ?></th>
 313          </tr>
 314  
 315      <?php
 316  
 317      for ($row=1; $row <= $numRows; $row++)
 318      {
 319          ?>
 320          <tr>
 321              <td class="LabelColumn"><h2><b><?php echo $row ?></b></h2></td>
 322  
 323              <td class="TextColumn" width="5%" nowrap>
 324                  <?php
 325                  if ($row != 1)
 326                      echo "<a href=\"PersonCustomFieldsRowOps.php?OrderID=$row&Field=" . $aFieldFields[$row] . "&Action=up\"><img src=\"Images/uparrow.gif\" border=\"0\"></a>";
 327                  if ($row < $numRows)
 328                      echo "<a href=\"PersonCustomFieldsRowOps.php?OrderID=$row&Field=" . $aFieldFields[$row] . "&Action=down\"><img src=\"Images/downarrow.gif\" border=\"0\"></a>";
 329                  ?>
 330                  <input type="image" value="delete" Name="delete" onclick="confirmDeleteField(<?php echo "'" . $aFieldFields[$row] . "', '" . $row . "'"; ?>);" src="Images/x.gif">
 331              </td>
 332  
 333              <td class="TextColumn" style="font-size:80%;">
 334              <?php echo $aPropTypes[$aTypeFields[$row]];    ?>
 335              </td>
 336  
 337              <td class="TextColumn" align="center"><input type="text" name="<?php echo $row . "name"; ?>" value="<?php echo htmlentities(stripslashes($aNameFields[$row])); ?>" size="35" maxlength="40">
 338                  <?php
 339                  if ( $aNameErrors[$row] )
 340                      echo "<span style=\"color: red;\"><BR>" . gettext("You must enter a name.") . " </span>";
 341                  ?>
 342              </td>
 343  
 344              <td class="TextColumn" align="center">
 345  
 346              <?php
 347              if ($aTypeFields[$row] == 9)
 348              {
 349                  echo "<select name=\"" . $row . "special\">";
 350                      echo "<option value=\"0\" selected>Select a group</option>";
 351  
 352                  $sSQL = "SELECT grp_ID,grp_Name FROM group_grp ORDER BY grp_Name";
 353                  $rsGroupList = RunQuery($sSQL);
 354  
 355                  while ($aRow = mysql_fetch_array($rsGroupList))
 356                  {
 357                      extract($aRow);
 358  
 359                      echo "<option value=\"" . $grp_ID . "\"";
 360                      if ($aSpecialFields[$row] == $grp_ID) { echo " selected"; }
 361                      echo ">" . $grp_Name;
 362                  }
 363  
 364                  echo "</select>";
 365                  if ( $aSpecialErrors[$row] ) echo "<span style=\"color: red;\"><BR>" . gettext("You must select a group.") . "</span>";
 366              }
 367              elseif ($aTypeFields[$row] == 12)
 368                  echo "<a href=\"javascript:void(0)\" onClick=\"Newwin=window.open('OptionManager.php?mode=custom&ListID=$aSpecialFields[$row]','Newwin','toolbar=no,status=no,width=400,height=500')\">" . gettext("Edit List Options") . "</a>";
 369              else
 370                  echo "&nbsp;";
 371              ?>
 372  
 373              </td>
 374              <td class="TextColumn" align="center" nowrap>
 375                  <input type="radio" Name="<?php echo $row . "side" ?>" value="0" <?php if (!$aSideFields[$row]) echo " checked" ?>><?php echo gettext("Left"); ?>
 376                  <input type="radio" Name="<?php echo $row . "side" ?>" value="1" <?php if ($aSideFields[$row]) echo " checked" ?>><?php echo gettext("Right"); ?>
 377              </td>
 378          </tr>
 379      <?php } ?>
 380  
 381          <tr>
 382              <td colspan="6">
 383              <table width="100%">
 384                  <tr>
 385                      <td width="30%"></td>
 386                      <td width="40%" align="center" valign="bottom">
 387                          <input type="submit" class="icButton" <?php echo 'value="' . gettext("Save Changes") . '"'; ?> Name="SaveChanges">
 388                          &nbsp;
 389                          <input type="button" class="icButton" <?php echo 'value="' . gettext("Exit") . '"'; ?>" Name="Exit" onclick="javascript:document.location='Menu.php';">
 390                      </td>
 391                      <td width="30%"></td>
 392                  </tr>
 393              </table>
 394              </td>
 395              <td>
 396          </tr>
 397  <?php } ?>
 398          <tr><td colspan="6"><hr></td></tr>
 399          <tr>
 400              <td colspan="6">
 401              <table width="100%">
 402                  <tr>
 403                      <td width="15%"></td>
 404                      <td valign="top">
 405                      <div><?php echo gettext("Type:"); ?></div>
 406                      <?php
 407                          echo "<select name=\"newFieldType\">";
 408  
 409                          for ($iOptionID = 1; $iOptionID <= count($aPropTypes); $iOptionID++)
 410                          {
 411                              echo "<option value=\"" . $iOptionID . "\"";
 412                              echo ">" . $aPropTypes[$iOptionID];
 413                          }
 414                          echo "</select>";
 415                      ?><BR>
 416                      <a href="Help.php?page=Types"><?php echo gettext("Help on types.."); ?></a>
 417                      </td>
 418                      <td valign="top">
 419                          <div><?php echo gettext("Name:"); ?></div>
 420                          <input type="text" name="newFieldName" size="30" maxlength="40">
 421                          <?php
 422                              if ( $bNewNameError ) echo "<div><span style=\"color: red;\"><BR>" . gettext("You must enter a name") . "</span></div>";
 423                              if ( $bDuplicateNameError ) echo "<div><span style=\"color: red;\"><BR>" . gettext("That field name already exists.") . "</span></div>";
 424                          ?>
 425                          &nbsp;
 426                      </td>
 427                      <td valign="top" nowrap>
 428                          <div><?php echo gettext("Side:"); ?></div>
 429                          <input type="radio" name="newFieldSide" value="0" checked><?php echo gettext("Left"); ?>
 430                          <input type="radio" name="newFieldSide" value="1"><?php echo gettext("Right"); ?>
 431                          &nbsp;
 432                      </td>
 433                      <td>
 434                          <input type="submit" class="icButton" <?php echo 'value="' . gettext("Add New Field") . '"'; ?> Name="AddField">
 435                      </td>
 436                      <td width="15%"></td>
 437                  </tr>
 438              </table>
 439              </td>
 440          </tr>
 441  
 442      </table>
 443      </form>
 444  
 445  <?php require  "Include/Footer.php"; ?>


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