<?php
/*=======================================================================
 *
 * metafield_editor.php
 *
 * Autor: Marc Vollmann
 *
 =======================================================================*/

include_once ("../include/mcglobal.inc.php");
include_once ("../include/auth.inc.php");


// Check HTTP-Parameters
getSecHttpVars("1",array("f_act", "generic", "deactivateMenu", 
                         "f_mtfc_id", "f_mtfc_mnemonic", "f_mtfc_description", "f_mtft_id", "f_mtft_name", 
                         "f_mtfk_id", "f_mtfk_type", "f_mtfk_name", "f_mtfk_new_id", "f_filter_mtfk_name"));

getLanguage(__FILE__);

$pageTitel = getLngt("FORMULARE");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");

// Check for authentication access and granted rights
$usrAccessArray["hq"] = "1";
authCheckForAccess($hq_id, $usr_id, $emp_id, "1", $customerId, $cscIdRoot, $cscIdActual);
authCheckEmployeeRights($emp_id, "15", "1");

if ($hqId == "") : $hqId = $hq_id; endif;
$category = $f_mtfc_id;   // Has to be set because of the following include
include_once ("../include/inc_metafield.inc.php");

getCurrentScript(__FILE__);

// Check for setting according to global usage
if ($gHqId) : $hqId = "0"; endif;

// Initialize value    
if ($generic == "") : $generic = "1111"; endif;
mcTrim($f_mtfc_mnemonic);
mcTrim($f_mtfc_description);
mcTrim($f_mtft_name);
mcTrim($f_mtfk_type);
mcTrim($f_mtfk_name);
mcTrim($f_filter_mtfk_name);  // Filter to reduce displayed number of global fields
mcIsSet($listOfEntries);

// Special treatment according to combined fields:
// E.g. "Str.-Hausnr.:123:124" is a combination of the fields 123 (here e.g. street) and 124 (here e.g. houseno.) with the description (name) "Str.-Hausnr."
// Now the whole fieldname "Str.-Hausnr.:123:124" will be automatically changed in "Str.-Hausnr." and the selected default type "ref:desc:xxx:yyy:..." will be changed in "ref:123:124".
if ($f_mtfk_type == "ref:desc:xxx:yyy:..." && $f_mtfk_name != "" && ($f_act == "saveFieldNew" || $f_act == "saveFieldModified")) :
   $f_act = "saveFieldNew";   // The selection of the reference field does result in a new reference field
   $tmpArray = spliti(":",$f_mtfk_name);
   $tmpArrayLen = count($tmpArray);
   $f_mtfk_type = "ref";
   for ($i = 1; $i < $tmpArrayLen; $i++) :
      $f_mtfk_type .= ":" . $tmpArray[$i];
   endfor;
   $f_mtfk_name = $tmpArray[0];   // E.g. "Str.-Hausnr."
endif;

// *** ACTION ***
// * Forms (categories) *
if ($f_act == "saveCategoryNew") :
   if ($f_mtfc_mnemonic != "" && $f_mtfc_description != "") :
      if (!existsEntry("metafieldcategory",array("mtfc_mnemonic",$f_mtfc_mnemonic))) :
         if (!existsEntry("metafieldcategory",array("mtfc_description",$f_mtfc_description))) :

            insertStmt("metafieldcategory", array("mtfc_mnemonic", $f_mtfc_mnemonic, "mtfc_description", $f_mtfc_description, "mtfc_group", ""));

            $f_mtfc_mnemonic = "";
            $f_mtfc_description = "";
         else :
            $statusMessage = getLngt("Der eingegebene Name existiert schon!");
         endif;
      else :
         $statusMessage = getLngt("Das eingegebene Kürzel existiert schon!");
      endif;
   else :
      $statusMessage = getLngt("Bitte vollständig eingeben!");
   endif;
endif;
if ($f_act == "saveCategoryModified") :
   if ($f_mtfc_id != "" && $f_mtfc_mnemonic != "" && $f_mtfc_description != "") :
      if (existsEntry("metafieldcategory",array("mtfc_id",$f_mtfc_id))) :
                  
         if (!existsEntry("metafieldcategory",array("mtfc_description",$f_mtfc_description))) :

            updateStmt("metafieldcategory","mtfc_id",$f_mtfc_id,array("mtfc_description", $f_mtfc_description));

            $f_mtfc_description = "";
         else :
            $statusMessage = getLngt("Der eingegebene Name existiert schon!");
         endif;
         
         if (!existsEntry("metafieldcategory",array("mtfc_mnemonic",$f_mtfc_mnemonic))) :

            updateStmt("metafieldcategory","mtfc_id",$f_mtfc_id,array("mtfc_mnemonic", $f_mtfc_mnemonic));

            $f_mtfc_mnemonic = "";
         else :
            $statusMessage = getLngt("Das eingegebene Kürzel existiert schon!");
         endif;
      else :
         $statusMessage = getLngt("Das eingegebene Formular existiert nicht!");
      endif;
   else :
      $statusMessage = getLngt("Bitte vollständig eingeben!");
   endif;
endif;

// * Global field vector *
if ($f_act == "saveFieldNew") :
   if ($f_mtfk_type != "" && $f_mtfk_name != "") :
      // if (existsEntry("metafieldkey",array("mtfk_type",$f_mtfk_type))) :   // Only existing type !!!
         if (!existsEntry("metafieldkey",array("mtfk_name",$f_mtfk_name))) :

            insertStmt("metafieldkey", array("mtfk_type", $f_mtfk_type, "mtfk_name", $f_mtfk_name));

            $f_mtfk_type = "";
            $f_mtfk_name = "";
         else :
            $statusMessage = getLngt("Der eingegebene Name existiert schon!");
         endif;
      // else :
      //    $statusMessage = getLngt("Der Typ ist ungültig!");
      // endif;
   else :
      $statusMessage = getLngt("Bitte vollständig eingeben!");
   endif;
endif;
if ($f_act == "saveFieldModified") :
   if ($f_mtfk_id != "" && $f_mtfk_type != "" && $f_mtfk_name != "") :
      if (existsEntry("metafieldkey",array("mtfk_id",$f_mtfk_id))) :
                  
         if (!existsEntry("metafieldkey",array("mtfk_name",$f_mtfk_name))) :

            updateStmt("metafieldkey","mtfk_id",$f_mtfk_id,array("mtfk_name", $f_mtfk_name));

            $f_mtfk_name = "";
         else :
            $statusMessage = getLngt("Der eingegebene Name existiert schon!");
         endif;
         
         if (existsEntry("metafieldkey",array("mtfk_type",$f_mtfk_type))) :

            updateStmt("metafieldkey","mtfk_id",$f_mtfk_id,array("mtfk_type", $f_mtfk_type));

            $f_mtfk_type = "";
         endif;
      else :
         $statusMessage = getLngt("Das eingegebene Formular existiert nicht!");
      endif;
   else :
      $statusMessage = getLngt("Bitte vollständig eingeben!");
   endif;
endif;

// * Template *
if ($f_act == "saveTemplateNew") :
   if ($f_mtft_name != "") :

      if (!existsEntry("metafieldtemplate",array("mtft_name",$f_mtft_name))) :

         insertStmt("metafieldtemplate", array("mtft_name", $f_mtft_name, "mtft_group", "", "mtft_content", ""));

         $f_mtft_name = "";
      else :
         $statusMessage = getLngt("Der eingegebene Name existiert schon!");
      endif;
   else :
      $statusMessage = getLngt("Bitte vollständig eingeben!");
   endif;
endif;
if ($f_act == "saveTemplateModified") :
   if ($f_mtft_id != "" && $f_mtft_name != "") :
      if (existsEntry("metafieldtemplate",array("mtft_id",$f_mtft_id))) :
                  
         if (!existsEntry("metafieldtemplate",array("mtft_name",$f_mtft_name))) :

            updateStmt("metafieldtemplate","mtft_id",$f_mtft_id,array("mtft_name", $f_mtft_name));

            $f_mtft_name = "";
         else :
            $statusMessage = getLngt("Der eingegebene Name existiert schon!");
         endif;
      else :
         $statusMessage = getLngt("Das eingegebene Template existiert nicht!");
      endif;
   else :
      $statusMessage = getLngt("Bitte vollständig eingeben!");
   endif;
endif;

// * Category fields *
if ($f_act == "saveCategoryFieldNew") :
   if ($f_mtfk_new_id != "") :
      if (!existsEntry("metafieldcategorykey",array("mtfc_id",$f_mtfc_id,"mtfk_id",$f_mtfk_new_id,"hq_id",$hqId))) :

         insertStmt("metafieldcategorykey", array("mtfc_id", $f_mtfc_id, "mtfk_id", $f_mtfk_new_id, "hq_id", $hqId, "mtfck_sort", ($mtfck_mtfckIdsLen + 1)));
      else :
         $statusMessage = getLngt("Dieses Feld existiert schon im Formular!");
      endif;
   else :
      $statusMessage = getLngt("Bitte eines der globalen Felder auswählen!");
   endif;
endif;
if ($f_act == "saveCategoryFieldSort") :
   if ($f_mtfc_id != "") :
      for ($i = 0; $i < $mtfck_mtfckIdsLen; $i++) :
          list ($newSortValueToBeStored) = getSecHttpVars("1",array("f_" . $mtfck_mtfkIds[$i]));
          
          updateStmt("metafieldcategorykey","mtfc_id",$f_mtfc_id,array("mtfck_sort", $newSortValueToBeStored),"hq_id = '" . $hqId . "' AND mtfk_id = '" . $mtfck_mtfkIds[$i] . "'");
      endfor;
   else :
      $statusMessage = getLngt("Es ist kein Formular gewählt!");
   endif;
endif;

// Load the meta field structure in memory
initMetaFieldStructure();


// * Output of the forms (categories) *
// Statement for metafieldcategory
$sqlquery = "SELECT mtfc.mtfc_id, mtfc.mtfc_mnemonic, mtfc.mtfc_description"
          . " FROM metafieldcategory AS mtfc"
          . " ORDER BY mtfc.mtfc_description";

$result = $db->query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

 // Table with header
$numOfRows = 1;
$lineToggler = 0;
$tableOfRowsForm = "<tr><td align=\"left\">" . getLngt("Beschreibung") . "&nbsp;&nbsp;&nbsp;</td><td align=\"center\">&nbsp;" . getLngt("Bearbeiten") . "&nbsp;</td><td align=\"center\">&nbsp;" . getLngt("Gruppen") . "&nbsp;</td><td align=\"center\">&nbsp;" . getLngt("Inhalt") . "&nbsp;</td></tr>";
while ($row = $result->fetch_assoc()):
      $numOfRows++;

   	  if ($lineToggler == 0) : $lineToggler = 1; else : $lineToggler = 0; endif;
      $cellColor = getListColor($numOfRows, $lineToggler);
	   
      $tableOfRowsForm .= "<tr>";      
      $tableOfRowsForm .= "<td align=\"left\" bgcolor=\"" . $cellColor ."\">&nbsp;" . $row["mtfc_description"] . "&nbsp;&nbsp;&nbsp;</td>";
      $tableOfRowsForm .= "<td align=\"center\" bgcolor=\"" . $cellColor ."\">&nbsp;<a href=\"javascript:editCategory('" . $row["mtfc_id"] . "','" . $row["mtfc_mnemonic"] . "','" . $row["mtfc_description"] . "');\"><img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\"></a></td>";
      $tableOfRowsForm .= "<td align=\"center\" bgcolor=\"" . $cellColor ."\">&nbsp;<a href=\"javascript:openGroups('mtfc','" . $row["mtfc_id"] . "');\"><img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\"></a></td>";
      $tableOfRowsForm .= "<td align=\"center\" bgcolor=\"" . $cellColor ."\">&nbsp;<a href=\"javascript:categoryFields('" . $row["mtfc_id"] . "');\"><img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\"></a></td>";
      $tableOfRowsForm .= "</tr>";
endwhile;
$result->free();


// * Output of the global fields *
// Statement for metafieldcategory
$whereClause = "";
$orderByClause = "mtfk.mtfk_name";
if ($f_filter_mtfk_name != "") :
   $whereClause = " WHERE mtfk.mtfk_name LIKE '" . $f_filter_mtfk_name . "%'";
endif;
$sqlquery = "SELECT mtfk.mtfk_id, mtfk.mtfk_type, mtfk.mtfk_name"
          . " FROM metafieldkey AS mtfk"
          . $whereClause
          . " ORDER BY " . $orderByClause;

$result = $db->query($sqlquery);
if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

 // Table with header
$numOfRows = 1;
$lineToggler = 0;
$tableOfRowsField = "<tr><td align=\"left\">" . getLngt("Nr.") . "&nbsp;&nbsp;&nbsp;</td><td align=\"left\">" . getLngt("Name") . "&nbsp;&nbsp;&nbsp;</td><td align=\"center\">&nbsp;" . getLngt("Bearbeiten") . "&nbsp;</td></tr>";
while ($row = $result->fetch_assoc()):
      $numOfRows++;

   	  if ($lineToggler == 0) : $lineToggler = 1; else : $lineToggler = 0; endif;
      $cellColor = getListColor($numOfRows, $lineToggler);
	   
      $tableOfRowsField .= "<tr>";
      $tableOfRowsField .= "<td align=\"left\" bgcolor=\"" . $cellColor ."\">&nbsp;" . $row["mtfk_id"] . "&nbsp;&nbsp;&nbsp;</td>";
      $tableOfRowsField .= "<td align=\"left\" bgcolor=\"" . $cellColor ."\">&nbsp;" . $row["mtfk_name"] . "&nbsp;&nbsp;&nbsp;</td>";
      // $tableOfRowsField .= "<td align=\"left\" bgcolor=\"" . $cellColor ."\">&nbsp;" . $row["mtfk_type"] . "&nbsp;&nbsp;&nbsp;</td>";
      $tableOfRowsField .= "<td align=\"center\" bgcolor=\"" . $cellColor ."\">&nbsp;<a href=\"javascript:editField('" . $row["mtfk_id"] . "','" . $row["mtfk_type"] . "','" . $row["mtfk_name"] . "');\"><img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\"></a></td>";
      // $tableOfRowsField .= "<td align=\"center\" bgcolor=\"" . $cellColor ."\">&nbsp;<a href=\"javascript:FieldMembers('" . $row["mtfk_id"] . "');\"><img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\"></a></td>";
      // $tableOfRowsField .= "<td align=\"center\" bgcolor=\"" . $cellColor ."\">&nbsp;<a href=\"javascript:finishPage('" . $row["mtfk_id"] . "','" . $row["mtfk_type"] . "','" . $row["mtfk_name"] . "');\">" . $row["mtfk_name"] . "</a></td>";
      $tableOfRowsField .= "</tr>";
endwhile;
$result->free();


// * Output of the templates *
$mtfcTemplateMode = getParameterValue("0", "MTFC_TPL_MODE", "0");
if ($mtfcTemplateMode == "1") :
   // Statement for metafieldtemplate
   $sqlquery = "SELECT mtft.mtft_id, mtft.mtft_name"
             . " FROM metafieldtemplate AS mtft"
             . " ORDER BY mtft.mtft_name";

   $result = $db->query($sqlquery);
   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());

    // Table with header
   $numOfRows = 1;
   $lineToggler = 0;
   $tableOfRowsTemplate = "<tr><td align=\"left\">" . getLngt("Beschreibung") . "&nbsp;&nbsp;&nbsp;</td><td align=\"center\">&nbsp;" . getLngt("Bearbeiten") . "&nbsp;</td><td align=\"center\">&nbsp;" . getLngt("Gruppen") . "&nbsp;</td><td align=\"center\">&nbsp;" . getLngt("Inhalt") . "&nbsp;</td></tr>";
   while ($row = $result->fetch_assoc()):
         $numOfRows++;

      	  if ($lineToggler == 0) : $lineToggler = 1; else : $lineToggler = 0; endif;
         $cellColor = getListColor($numOfRows, $lineToggler);

         $tableOfRowsTemplate .= "<tr>";      
         $tableOfRowsTemplate .= "<td align=\"left\" bgcolor=\"" . $cellColor ."\">&nbsp;" . $row["mtft_name"] . "&nbsp;&nbsp;&nbsp;</td>";
         $tableOfRowsTemplate .= "<td align=\"center\" bgcolor=\"" . $cellColor ."\">&nbsp;<a href=\"javascript:editTemplate('" . $row["mtft_id"] . "','" . $row["mtft_name"] . "');\"><img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\"></a></td>";
         $tableOfRowsTemplate .= "<td align=\"center\" bgcolor=\"" . $cellColor ."\">&nbsp;<a href=\"javascript:openGroups('mtft','" . $row["mtft_id"] . "');\"><img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\"></a></td>";
         $tableOfRowsTemplate .= "<td align=\"center\" bgcolor=\"" . $cellColor ."\">&nbsp;<a href=\"javascript:openContent('" . $row["mtft_id"] . "');\"><img src=\"../images/arrow_right.png\" border=\"0\" height=\"10\" width=\"25\"></a></td>";
         $tableOfRowsTemplate .= "</tr>";
   endwhile;
   $result->free();
endif;


// * Output of the fields of a specified category (form) *
if ($f_mtfc_id != "") :

   $numOfRows = 1;
   $lineToggler = 0;
   $tableOfcategoryField = "<tr><td align=\"left\">" . getLngt("Name") . "&nbsp;&nbsp;&nbsp;</td><td align=\"center\">&nbsp;" . getLngt("Sortierung") . "&nbsp;</td></tr>";
   for ($i = 0; $i < $mtfck_mtfckIdsLen; $i++) :
      $numOfRows++;

   	  if ($lineToggler == 0) : $lineToggler = 1; else : $lineToggler = 0; endif;
      $cellColor = getListColor($numOfRows, $lineToggler);
      
      $tableOfcategoryField .= "<tr>";

      $tableOfcategoryField .= "<td align=\"left\" bgcolor=\"" . $cellColor ."\">&nbsp;" . $mtfk_allFieldNames[$mtfck_mtfkIds[$i]] . "&nbsp;&nbsp;&nbsp;</td>";
      $tableOfcategoryField .= "<td align=\"left\" bgcolor=\"" . $cellColor ."\">&nbsp;<select class=\"f8np1\" name=\"f_" . $mtfck_mtfkIds[$i] . "\">" . addOptionsFromRange(1, $mtfck_mtfckIdsLen, $mtfck_mtfkSortedIds[$mtfck_mtfkIds[$i]], "", "", "") . "</select>&nbsp;&nbsp;&nbsp;</td>";
      
      $tableOfcategoryField .= "</tr>";
   endfor;
endif;
?>

<html>

<head>
<title><?php echo $pageTitel ?></title>

<link rel="stylesheet" type="text/css" href="../css/phoenix.css">
<style type="text/css">
  <?php include_once ("../css/navigation.css.php"); ?>
</style>

<?php include_once ("../include/js_framework.inc.php"); ?>

<script type="text/javascript">
<!--
// NAVIGATION
<?php echo $jsMenuOut; ?>

// GENERIC function
function finishPage(grp_id,grp_name) {

  <?php if (substr($generic, 0,1) == "1") : ?> opener.document.forms[0].g_grp_id.value = grp_id;     <?php endif; ?>
  <?php if (substr($generic, 2,1) == "1") : ?> opener.document.forms[0].g_grp_name.value = grp_name; <?php endif; ?>
  self.close();
};

function finishPage2(f_act) {
  document.forms[0].f_act.value = f_act;
  document.forms[0].submit();
};

function editCategory(mtfc_id,mtfc_mnemonic,mtfc_description) {
	document.forms[0].f_mtfc_id.value = mtfc_id;
	document.forms[0].f_mtfc_mnemonic.value = mtfc_mnemonic;
  document.forms[0].f_mtfc_description.value = mtfc_description;
};

function editField(mtfk_id,mtfk_type,mtfk_name) {
	document.forms[0].f_mtfk_id.value = mtfk_id;
	document.forms[0].f_mtfk_type.value = mtfk_type;
  document.forms[0].f_mtfk_name.value = mtfk_name;
};

function editTemplate(mtft_id,mtft_name) {
	document.forms[0].f_mtft_id.value = mtft_id;
  document.forms[0].f_mtft_name.value = mtft_name;
};

function categoryFields(mtfc_id) {
	document.forms[0].f_mtfc_id.value = mtfc_id;
	  document.forms[0].submit();
};

function openContent(mtft_id) {
  var widthPopupWin = 1500;
  var heightPopupWin = 900;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/metafield_template.php?mtft_id=" + mtft_id + "&deactivateMenu=1","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openGroups(mtf_type, mtf_id) {
  var widthPopupWin = 800;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/groupmembers.php?itemType=" + mtf_type + "&itemId=" + mtf_id,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};
-->
</script>
</head>

<body onLoad="<?php echo $phpCurrentNavigationOnLoad ?>displayStatusMessage();">

<?php echo $phpMenuOut ?>
<?php echo $phpReducedMenuOut ?>
<?php echo $phpPageTitelOut ?>

<div class="maincontent2" name="maincontent" id="maincontent">

  <form action="../admin/metafield_editor.php" method="post">
  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="generic" value="<?php echo $generic ?>">
  <input type="hidden" name="f_mtfc_id" value="<?php echo $f_mtfc_id ?>">
  <input type="hidden" name="f_mtfk_id" value="<?php echo $f_mtfk_id ?>">
  <input type="hidden" name="f_mtft_id" value="<?php echo $f_mtft_id ?>">
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">  

  <?php echo htmlDivLineSpacer("20px"); ?>

  <!-- FORMS (CATEGORIES) -->
  <div style="float:left;">
    <div>
      <div class="f12bp1_blue"><?php echo getLngt("Formulare") ?></div>
    </div>
    <?php echo htmlDivLineSpacer("10px"); ?>
    <div>
      <table class="f10np1" border="0" cellpadding="0">
        <?php echo $tableOfRowsForm ?>
      </table>
    </div>
    <?php echo htmlDivLineSpacer("20px"); ?>
    
    <div>
      <?php echo getLngt("(Neues) Formular:") ?>
    </div>
    <?php echo htmlDivLineSpacer("10px"); ?>
    
    <div>
      <div <?php echo setStyleHtmlDiv("150px","left"); ?>><?php echo getLngt("Kürzel:") ?></div>
      <div>
        <input type="text" name="f_mtfc_mnemonic" value="<?php echo $f_mtfc_mnemonic ?>" maxlength="30" size="30">
      </div>
    </div>
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
    <div>
      <div <?php echo setStyleHtmlDiv("150px","left"); ?>><?php echo getLngt("Bezeichnung:") ?></div>
      <div>
        <input type="text" name="f_mtfc_description" value="<?php echo $f_mtfc_description ?>" maxlength="100" size="30">
      </div>
    </div>
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
    
    <div>
      <?php echo defineButtonType10(getLngt("Hinzufügen"), "action_new", "finishPage2('saveCategoryNew');", "120", "left", "3"); ?>
      <?php echo defineButtonType10(getLngt("Umbenennen"), "action_rename", "finishPage2('saveCategoryModified');", "120", "left", "3"); ?>
    </div>  
    <?php echo htmlDivLineSpacer("30px", "", "left"); ?>
    
    <div>
      <?php echo $listOfEntries ?>
    </div>
  </div>
  

  <!-- SPACER -->
  <div <?php echo setStyleHtmlDiv("80px","left"); ?>>&nbsp;</div>


  <!-- FIELDS -->
  <div style="float:left;">
    <div>
      <div class="f12bp1_blue"><?php echo getLngt("Globale Felder") ?></div>
    </div>
    <?php echo htmlDivLineSpacer("10px"); ?>
    <div>
     	<div <?php echo setStyleHtmlDiv("250","left"); ?>>
     	  <?php echo getLngt("Anzeigefilter") ?>&nbsp;:&nbsp;&nbsp;<input type="text" name="f_filter_mtfk_name" value="<?php echo $f_filter_mtfk_name ?>" maxlength="15" size="15">
    	</div>
      <?php echo defineButtonType10(getLngt("Anzeigen"), "action_field_show", "document.forms[0].submit();", "120", "", ""); ?>
    </div>
    <?php echo htmlDivLineSpacer("10px"); ?>
    <div>
      <table class="f10np1" border="0" cellpadding="0">
        <?php echo $tableOfRowsField ?>
      </table>
    </div>
    <?php echo htmlDivLineSpacer("20px"); ?>
    
    <div>
      <?php echo getLngt("(Neues) Feld:") ?>
    </div>
    <?php echo htmlDivLineSpacer("10px"); ?>
    
    <div>
      <div <?php echo setStyleHtmlDiv("150px","left"); ?>><?php echo getLngt("Typ:") ?></div>
      <div>
        <select name="f_mtfk_type">
          <?php 
            echo addOptionsFromArray(getColVectorFromDB2ArrayByClause("metafieldkey", "mtfk_type", "", "", "mtfk_type", "DISTINCT"),$f_mtfk_type,"1");
            echo addOptionsFromAssociativeArray($metaTypeMappingArray, "", "", "2", "db:");
            echo addOptionsFromAssociativeArray($metaTypeSystemArray, "", "", "2", "sys:");
          ?>
        </select>
      </div>
    </div>
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
    <div>
      <div <?php echo setStyleHtmlDiv("150px","left"); ?>><?php echo getLngt("Name:") ?></div>
      <div>
        <input type="text" name="f_mtfk_name" value="<?php echo $f_mtfk_name ?>" maxlength="100" size="30">
      </div>
    </div>
    <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
    
    <div>
      <?php echo defineButtonType10(getLngt("Hinzufügen"), "action_field_new", "finishPage2('saveFieldNew');", "120", "left", "3"); ?>
      <?php echo defineButtonType10(getLngt("Umbenennen"), "action_field_rename", "finishPage2('saveFieldModified');", "120", "left", "3"); ?>
    </div>  
    <?php echo htmlDivLineSpacer("30px", "", "left"); ?>
  </div>


  <?php if ($mtfcTemplateMode == "1") : ?>

    <!-- SPACER -->  
    <div <?php echo setStyleHtmlDiv("80px","left"); ?>>&nbsp;</div>

    <!-- TEMPLATES -->
    <div style="float:left;">
      <div>
        <div class="f12bp1_blue"><?php echo getLngt("Vorlagen") ?></div>
      </div>
      <?php echo htmlDivLineSpacer("10px"); ?>
      <div>
        <table class="f10np1" border="0" cellpadding="0">
          <?php echo $tableOfRowsTemplate ?>
        </table>
      </div>
      <?php echo htmlDivLineSpacer("20px"); ?>
      
      <div>
        <?php echo getLngt("(Neue) Vorlage:") ?>
      </div>
      <?php echo htmlDivLineSpacer("10px"); ?>

      <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
      <div>
        <div <?php echo setStyleHtmlDiv("150px","left"); ?>><?php echo getLngt("Name:") ?></div>
        <div>
          <input type="text" name="f_mtft_name" value="<?php echo $f_mtft_name ?>" maxlength="100" size="30">
        </div>
      </div>
      <?php echo htmlDivLineSpacer("10px", "", "left"); ?>
      
      <div>
        <?php echo defineButtonType10(getLngt("Hinzufügen"), "action_new", "finishPage2('saveTemplateNew');", "120", "left", "3"); ?>
        <?php echo defineButtonType10(getLngt("Umbenennen"), "action_rename", "finishPage2('saveTemplateModified');", "120", "left", "3"); ?>
      </div>  
      <?php echo htmlDivLineSpacer("30px", "", "left"); ?>
      
      <div>
        <?php echo $listOfEntries ?>
      </div>
    </div>

  <?php endif; ?>


  <?php if ($f_mtfc_id != "") : ?>
  
    <!-- SPACER -->
    <div <?php echo setStyleHtmlDiv("80px","left"); ?>>&nbsp;</div>


    <!-- FIELDS OF A SPECIFIED FORM -->
    <div style="float:left;">
      <div>
        <div class="f12bp1_blue"><?php echo getLngt("Felder des Formulars") ?>:&nbsp;<?php echo getFieldValueFromId("metafieldcategory","mtfc_id",$f_mtfc_id,"mtfc_description"); ?></div>
      </div>
      <?php echo htmlDivLineSpacer("10px"); ?>
      <div>
        <table class="f10np1" border="0" cellpadding="0">
          <?php echo $tableOfcategoryField ?>
        </table>
      </div>
      <?php echo htmlDivLineSpacer("10px"); ?>

      <div>
        <?php echo defineButtonType10(getLngt("Sortierung speichern"), "action_categoryfield_sort", "finishPage2('saveCategoryFieldSort');", "200", "left", "3"); ?>
      </div>
      <?php echo htmlDivLineSpacer("30px", "", "left"); ?>
      
      <div>
        <?php echo getLngt("(Neues) Formularfeld:") ?>
      </div>
      <?php echo htmlDivLineSpacer("10px"); ?>
    
      <div>
        <div>
          <select class="f8np1" name="f_mtfk_new_id">
            <?php echo addOptionsAndTextsFromArrays(mtfk_getAllIDs("mtfk_id"), getColVectorFromDB2ArrayByClause("metafieldkey", "mtfk_name", "", "", "mtfk_id"), "", "1"); ?>
          </select>
        </div>
      </div>
      <?php echo htmlDivLineSpacer("10px", "", "left"); ?>

      <div>
        <?php echo defineButtonType10(getLngt("Hinzufügen"), "action_categoryfield_new", "finishPage2('saveCategoryFieldNew');", "120", "left", "3"); ?>
      </div>
      <?php echo htmlDivLineSpacer("30px", "", "left"); ?>
    </div>
    
  <?php endif; ?>

  <?php echo htmlDivLineSpacer("20px"); ?>

</form>
</div>
</body>

</html>