<?php
/*=======================================================================
 *
 * GA_services.php
 *
 =======================================================================*/


include_once ("GA_global.inc.php");


// Check HTTP-Parameters
getSecHttpVars("1",array("f_act","mode","csId","opener","orderByService","orderByServiceType","orderByServiceCustomer",
                         "statusMessage", "serviceMode", "f_service_id", "f_service_change", "f_service_new", 
                         "f_servicetype_id", "f_servicetype_change", "f_servicetype_new", "deactivateMenu"));


// Access for current market of user logged in only.
// There can be a global price matrix if $csId == "0", but presently not. Not wondering about "if ($csId == "")..." in following code!  ;-)
if ($csId != "0") :

   $hq_id = "0";  // Presently use standard headquarters ID
   
   getLanguage(__FILE__);
   
   $pageTitel = getLngt("PREISE");
   if ($mode == "discount") : $pageTitel = getLngt("RABATTE"); endif;
   
   getCurrentScript(__FILE__);
   
   
   // Get usr_id of the current employee (session)
   // $currentSessionUsrId = getFieldValueFromId("employee", "emp_id", $emp_id, "usr_id");   // !!!!!!!!! HIER ID des aktuellen Benutzers zuweisen !!!!!!!!!!! 
   $currentSessionUsrId = "0";
   
   // Service-mode
   if ($serviceMode == "") : $serviceMode = "1"; endif;
   
   // Price-mode or discount-mode
   if ($mode == "") : $mode = "price" ; endif;
   
   // General price/discount for all customers
   if ($csId == "") : $csId = "0" ; endif;
   
   
   // Company Name and name2 of the current market ($csId)
   $cmpComp = "";   // !!!!!!!!! HIER Firma des aktuellen Benutzers zuweisen !!!!!!!!!!! 
   $cmpComp2 = "";  // !!!!!!!!! HIER Zusatz des aktuellen Benutzers zuweisen !!!!!!!!!!! 

   
   // ORDER BY to be displayed
   if ($orderByService == "") : $orderByService = "srv_group, srv_sort" ; endif;
   if ($orderByServiceType == "") : $orderByServiceType = "srvt_group, srvt_name" ; endif;
   if ($orderByServiceCustomer == "") : $orderByServiceCustomer = "srvt.srvt_group, srvt.srvt_name" ; endif;
   
   
   // Check mandator state; if enabled (= 1) then differ between mandators, else set HQ_ID = 0 => same values for ALL mandators
   $currentHqId = $hq_id;
   if ($serviceMode >= "1") :
      $constHqId = getParameterValue("0", "MANDATOR_SERVICE2_ENABLED", $hq_id);
   else :
      $constHqId = getParameterValue("0", "MANDATOR_SERVICE_ENABLED", $hq_id);
   endif;   
   if ($constHqId == "" || $constHqId == "0") : $currentHqId = "0"; endif;
   
   
   
   // *** Storing-processes ***
   // *** BEGIN ***************
   
   // Change name of a service
   if ($f_act == "save_service_change") :
      if ($f_service_id != "") :
         TA(B);
         updateStmt("service", "srv_id", $f_service_id, array("srv_name", $f_service_change));
         writeToLogDB("57",$hq_id,"",$usr_id,"","","","DBOP=Update_service|SRV_MODE=".$serviceMode);
         TA(C);
         TA(E);
      else :
         $statusMessage = getLngt("Der gewünschte Name existiert leider schon!");
      endif;
   endif;
   
   // Insert new service
   if ($f_act == "save_service_new") :
      if ($f_service_new != "") :
         TA(B);
         $tmpFields = array("srv_mode",$serviceMode,"hq_id",$currentHqId,"cs_id",$csId,"srv_name",$f_service_new);
         insertStmt("service",$tmpFields);
         writeToLogDB("58",$hq_id,"",$usr_id,"","","","DBOP=Insert_service|SRV_MODE=".$serviceMode);
         TA(C);
         TA(E);
      else :
         $statusMessage = getLngt("Vergeben Sie bitte einen Namen!");
      endif;
   endif;
   
   // Change name of a servicetype
   if ($f_act == "save_servicetype_change") :
      if ($f_servicetype_id != "") :
         TA(B);
         updateStmt("servicetype", "srvt_id", $f_servicetype_id, array("srvt_name", $f_servicetype_change));
         writeToLogDB("59",$hq_id,"",$usr_id,"","","","DBOP=Update_servicetype|SRV_MODE=".$serviceMode);
         TA(C);
         TA(E);
      else :
         $statusMessage = getLngt("Der gewünschte Name existiert leider schon!");
      endif;
   endif;
   
   // Insert new servicetype
   if ($f_act == "save_servicetype_new") :
      if ($f_servicetype_new != "") :
         TA(B);
         $tmpFields = array("srvt_mode",$serviceMode,"hq_id",$currentHqId,"cs_id",$csId,"srvt_name",$f_servicetype_new);
         insertStmt("servicetype",$tmpFields);
         writeToLogDB("60",$hq_id,"",$usr_id,"","","","DBOP=Insert_servicetype|SRV_MODE=".$serviceMode);
         TA(C);
         TA(E);
      else :
         $statusMessage = getLngt("Vergeben Sie bitte einen Namen!");
      endif;
   endif;
   
   // Removal of a service
   if ($f_act == "remove_service_single") :
      if ($f_service_id != "") :
         TA(B);
         $tmpSrvName .= getFieldValueFromId("service", "srv_id", $f_service_id, "srv_name");
         deleteStmt("service","srv_id = " . $f_service_id);
         writeToLogDB("131",$hq_id,"",$usr_id,"","","","DBOP=Delete_service|SRV_MODE=".$serviceMode."|SRV_ID=".$f_service_id."|SRV_NAME=".$tmpSrvName);
         TA(C);
         TA(E);
      else :
         $statusMessage = getLngt("Eine Löschung konnte nicht erfolgen!");
      endif;
   endif;
   
   // Removal of a service type
   if ($f_act == "remove_service_type_single") :
      if ($f_servicetype_id != "") :
         TA(B);
         $tmpSrvtName .= getFieldValueFromId("servicetype", "srvt_id", $f_servicetype_id, "srvt_name");
         deleteStmt("servicetype","srvt_id = " . $f_servicetype_id);
         writeToLogDB("132",$hq_id,"",$usr_id,"","","","DBOP=Delete_servicetype|SRV_MODE=".$serviceMode."|SRVT_ID=".$f_servicetype_id."|SRVT_NAME=".$tmpSrvtName);
         TA(C);
         TA(E);
      else :
         $statusMessage = getLngt("Eine Löschung konnte nicht erfolgen!");
      endif;
   endif;
   
   // *** END ***************
   
   
   
   // *****************************
   // * Selection of all services *
   // *****************************
   if ($csId > "0" && $serviceMode >= "1") :
      $sqlquery = "SELECT srv.srv_id, srv.srv_name, srv.srv_sort, srv.srv_group, srv.cs_id"
                  . " FROM service AS srv, customerservice AS cssrv"
                  . " WHERE srv.hq_id = '" . $currentHqId . "' AND srv.cs_id = '0' AND srv.srv_mode = '" . $serviceMode . "' AND"
                  . "       srv.srv_id = cssrv.srv_id AND cssrv.cs_id = '" . $csId . "'";
      
      $sqlquery2 = "SELECT srv_id, srv_name, srv_sort, srv_group, cs_id"
                   . " FROM service"
                   . " WHERE hq_id = '" . $currentHqId . "' AND cs_id = '" . $csId . "' AND srv_mode = '" . $serviceMode . "'";
      
      $sqlquery = "(" . $sqlquery . ") UNION (" . $sqlquery2 . ") ORDER BY " . $orderByService;
   else :
      // Default
      $sqlquery = "SELECT srv_id, srv_name, srv_sort, srv_group, cs_id"
                  . " FROM service"
                  . " WHERE hq_id = '" . $currentHqId . "' AND cs_id = '0' AND srv_mode = '" . $serviceMode . "'"
                  . " ORDER BY " . $orderByService;
   endif;
   
   $result = $db->query($sqlquery);
   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
   
   $services = array();
   $count = 0;
   while ($row = $result->fetch_assoc()):
         $count++;
         $services["id"][$count] = $row[srv_id];
         $services["name"][$count] = $row[srv_name];
         $services["sort"][$count] = $row[srv_sort];
         $services["group"][$count] = $row[srv_group];
         $services["cs_id"][$count] = $row[cs_id];
   endwhile;
   $result->free();
   
   
   // *********************************
   // * Selection of all servicetypes *
   // *********************************
   if ($csId > "0" && $serviceMode >= "1") :
      $sqlquery = "SELECT srvt.srvt_id, srvt.srvt_name, srvt.srvt_group, srvt.cs_id"
                  . " FROM servicetype AS srvt, customerservicetype AS cssrvt"
                  . " WHERE srvt.hq_id = '" . $currentHqId . "' AND srvt.cs_id = '0' AND srvt.srvt_mode = '" . $serviceMode . "' AND"
                  . "       srvt.srvt_id = cssrvt.srvt_id AND cssrvt.cs_id = '" . $csId . "'";
                  
      $sqlquery2 = "SELECT srvt_id, srvt_name, srvt_group, cs_id"
                   . " FROM servicetype"
                   . " WHERE hq_id = '" . $currentHqId . "' AND cs_id = '" . $csId . "' AND srvt_mode = '" . $serviceMode . "'";
                   
      // $sqlquery = "(" . $sqlquery . ") UNION (" . $sqlquery2 . ")";
      $sqlquery = "(" . $sqlquery . ") UNION ALL (" . $sqlquery2 . ") ORDER BY " . $orderByServiceType;
   else :
      // Default
      $sqlquery = "SELECT srvt_id, srvt_name, srvt_group, cs_id"
                  . " FROM servicetype"
                  . " WHERE hq_id = '" . $currentHqId . "' AND cs_id = '0' AND srvt_mode = '" . $serviceMode . "'"
                  . " ORDER BY " . $orderByServiceType;
   endif;
   
   $result = $db->query($sqlquery);
   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
   
   $serviceTypes = array();
   $count = 0;
   while ($row = $result->fetch_assoc()):
         $count++;
         $serviceTypes["id"][$count] = $row[srvt_id];
         $serviceTypes["name"][$count] = $row[srvt_name];
         $serviceTypes["group"][$count] = $row[srvt_group];
         $serviceTypes["cs_id"][$count] = $row[cs_id];
   endwhile;
   $result->free();
   
   
   // ***************************************
   // * Selection of servicecustomer-values *
   // ***************************************
   $sqlquery = "SELECT srvc.srv_id, srvc.srvt_id, srvc.cs_id, srvc.srvc_price, srvc.srvc_discount"
               . " FROM service AS srv, servicetype AS srvt, servicecustomer AS srvc"
               . " WHERE srvc.srv_id = srv.srv_id"
               . "   AND srv.srv_mode = '" . $serviceMode . "'"
               . "   AND srvc.srvt_id = srvt.srvt_id"
               . "   AND srvt.srvt_mode = '" . $serviceMode . "'"
               . "   AND srvc.cs_id = " . $csId
               . "   AND srvc.hq_id = " . $currentHqId
               . " ORDER BY " . $orderByServiceCustomer;
   
   $result = $db->query($sqlquery);
   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
   
   $servicePrices = array();
   $serviceDiscounts = array();
   while ($row = $result->fetch_assoc()):
         $servicePrices[$row[srv_id]][$row[srvt_id]] = $row[srvc_price];
         $serviceDiscounts[$row[srv_id]][$row[srvt_id]] = $row[srvc_discount];      
   endwhile;
   $result->free();
   
   
   // Number of entries
   $lenServices = count($services["id"]);
   $lenServiceTypes = count($serviceTypes["id"]);
   
   
   // *************************************************
   // * Storing prices and discounts if requested     *
   // * Using the results of the statements before!!! *
   // *************************************************
   if ($f_act != "" && $f_act == "save") :
   
      // Set the current timestamp to store the data
      $currentTime = getDateTime("0");
   
      TA("B");
   
      for ($i = 1; $i <= $lenServiceTypes; $i++) :
   
          for ($j = 1; $j <= $lenServices; $j++) :    
   
              // Define current service-id and service-type-id
              $srvCur = $services["id"][$j];
              $srvtCur = $serviceTypes["id"][$i];
   
              // Get current input-type-text-field with price-/dicount-value
              list ($newValueToBeStored) = getHttpVars(array("service_". $srvCur ."_" . $srvtCur));
              if ($newValueToBeStored == "") : $newValueToBeStored = "0"; endif;
              
              // Allow float data with "." and ","
              $newValueToBeStored = str_replace (",", ".", $newValueToBeStored);
              
              if ($servicePrices[$srvCur][$srvtCur] == "") : $servicePrices[$srvCur][$srvtCur] = "0"; endif;
              if ($serviceDiscounts[$srvCur][$srvtCur] == "") : $serviceDiscounts[$srvCur][$srvtCur] = "0"; endif;
   
              if ($mode == "price") :
   
                 // Check for necessity to update or insert
                 if ($servicePrices[$srvCur][$srvtCur] != $newValueToBeStored) :
   
                    if (existsEntry("servicecustomer",array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId))) :
                       // Update the new price              
                       $sqlStmt = "UPDATE servicecustomer SET srvc_price = $newValueToBeStored"
                                  . " WHERE srv_id = $srvCur AND srvt_id = $srvtCur AND hq_id = $currentHqId AND cs_id = $csId";
                       $res = $db->query($sqlStmt);
                       if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;
                    else :                
                       if ($newValueToBeStored != "0") :
                          // Insert the new price
                          $tmpFields = array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId,"srvc_price",$newValueToBeStored,"srvc_discount",$serviceDiscounts[$srvCur][$srvtCur]);
                          insertStmt("servicecustomer",$tmpFields);
                       endif;
                    endif;
                    
                    // Insert current prices AND (!) discounts into the servicehistory
                    $tmpFields = array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId,"usr_id",$currentSessionUsrId,"srvh_validfrom",$currentTime,"srvh_price",$newValueToBeStored,"srvh_discount",$serviceDiscounts[$srvCur][$srvtCur]);
                    insertStmt("servicehistory",$tmpFields);
                    
                    $servicePrices[$srvCur][$srvtCur] = $newValueToBeStored;
                 endif;
                    
              else :
   
                 // Check for necessity to update or insert
                 if ($serviceDiscounts[$srvCur][$srvtCur] != $newValueToBeStored) :
              
                    if (existsEntry("servicecustomer",array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId))) :           
                       // Update the new discount              
                       $sqlStmt = "UPDATE servicecustomer SET srvc_discount = $newValueToBeStored"
                                  . " WHERE srv_id = $srvCur AND srvt_id = $srvtCur AND hq_id = $currentHqId AND cs_id = $csId";
                       $res = $db->query($sqlStmt);
                       if (DB::isError($res)) : die ("$PHP_SELF: " . $res->getMessage()); endif;
                    else :                
                       if ($newValueToBeStored != "0") :
                          // Insert the new discount
                          $tmpFields = array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId,"srvc_price",$servicePrices[$srvCur][$srvtCur],"srvc_discount",$newValueToBeStored);
                          insertStmt("servicecustomer",$tmpFields);
                       endif;
                    endif;
                    
                    // Insert current prices AND (!) discounts into the servicehistory
                    $tmpFields = array("srv_id",$srvCur,"srvt_id",$srvtCur,"hq_id",$currentHqId,"cs_id",$csId,"usr_id",$currentSessionUsrId,"srvh_validfrom",$currentTime,"srvh_price",$servicePrices[$srvCur][$srvtCur],"srvh_discount",$newValueToBeStored);
                    insertStmt("servicehistory",$tmpFields);
                    
                    $serviceDiscounts[$srvCur][$srvtCur] = $newValueToBeStored;
                 endif;           
              endif;
                         
          endfor;
      endfor;
      
      TA("C");
      TA("E");   
   endif;
   
   
   // *****************************************************
   // * Generation of the price-matrix or discount-matrix *
   // *****************************************************
   
   // Table-header
   $serviceOutput = "<tr>\n";
   $serviceOutput .= "<td>&nbsp;</td>\n";   // because of the following row-names
   for ($j = 1; $j <= $lenServices; $j++) :
       $serviceOutput .= "<td>" . $services["name"][$j] . "</td>\n";
   endfor;
   $serviceOutput .= "</tr>\n";
   
   // Table-data
   $remServiceTypeGroup = "";
   for ($i = 1; $i <= $lenServiceTypes; $i++) :
       if ($remServiceTypeGroup != $serviceTypes["group"][$i]) :
          $remServiceTypeGroup = $serviceTypes["group"][$i];
          $tmpGroupIdArray = spliti(",", substr($serviceTypes["group"][$i], 1, -1));
          $tmpGroupIdArrayLen = count($tmpGroupIdArray);
          $tmpGroupName = "";
          for ($k = 0; $k < $tmpGroupIdArrayLen; $k++) :
              if ($tmpGroupName != "") : $tmpGroupName .= "&nbsp;&nbsp;/&nbsp;&nbsp;"; endif;
              $tmpGroupName .= getFieldValueFromId("groups", "grp_id", $tmpGroupIdArray[$k], "grp_name");
          endfor;
          $serviceOutput .= "<tr><td colspan=\"" . $lenServices . "\"><b>" . $tmpGroupName . "</b></td></tr>\n";   // "$lenServices" because of number of cols
       endif;
       $serviceOutput .= "<tr>\n";
       $serviceOutput .= "<td>" . $serviceTypes["name"][$i] . "</td>\n";
       for ($j = 1; $j <= $lenServices; $j++) :    
       
           // Define current service-id and service-type-id
           $srvCur = $services["id"][$j];
           $srvtCur = $serviceTypes["id"][$i];    
   
           if ($mode == "price") :
              if ($servicePrices[$srvCur][$srvtCur] == "") : $servicePrices[$srvCur][$srvtCur] = "0"; endif;
              $serviceOutput .= "<td><input type=\"text\" name=\"service_" . $srvCur . "_" . $srvtCur . "\" value=\"" . $servicePrices[$srvCur][$srvtCur] . "\" size=\"7\" align=\"right\"></td>\n";
           else :
              if ($serviceDiscounts[$srvCur][$srvtCur] == "") : $serviceDiscounts[$srvCur][$srvtCur] = "0"; endif;
              $serviceOutput .= "<td><input type=\"text\" name=\"service_" . $srvCur . "_" . $srvtCur . "\" value=\"" . $serviceDiscounts[$srvCur][$srvtCur] . "\" size=\"7\" align=\"right\"></td>\n";
           endif;
       endfor;
       $serviceOutput .= "</tr>\n";
   endfor;
   
   
   // Output
   if ($mode == "price") : 
      $title = getLngt("Allgemeine Preise");
   else :    
      $title = getLngt("Allgemeine Rabatte [in %]");
   endif;   
   if ($csId != "0") :   
      if ($mode == "price") : 
         $title = getLngt("Preise speziell für den Kunden") . " " . $cmpComp . " " . $cmpComp2;
      else :    
         $title = getLngt("Rabatte speziell für den Kunden") . " " . $cmpComp . " " . $cmpComp2;
      endif;   
   endif;
endif;
?>


<html lang="de">
<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 src="../include/checkFormTags.js" type="text/javascript"></script>

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

function searchCustomerPopup() {
  var widthPopupWin = 800;
  var heightPopupWin = 600;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin=window.open("../admin/impressum.html", "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin);  	
};	

function finishPage(f_act) { 
 // for(i=0;i<document.forms[0].jb_costcenter_select.length;++i) {
 //   if (document.forms[0].jb_costcenter_select.options[i].selected == true) {   
 //      document.forms[0].jb_costcenter.value=document.forms[0].jb_costcenter_select.options[i].value;
 //   }
 // };
 if (f_act == 'save') {
    if (!confirm('<?php echo getLngt("Preisbereichsmatrix speichern?") ?>')) {
       return false;
    }
 }
 if (f_act == 'changeMode') {
    if (confirm('<?php echo getLngt("Möchten Sie den Modus wechseln?") ?>')) {
    	 if (document.forms[0].serviceMode.value == '1') {
    	 	  document.forms[0].serviceMode.value = '0'
    	 } else {
    	 	  document.forms[0].serviceMode.value = '1'
    	 }	    	        
    }
 }
 document.forms[0].f_act.value = f_act;
 document.forms[0].submit();
};

function finishPageServiceRemove(f_act) { 
 var service_removed = getSelectedValue('f_service_id');
 if (service_removed != '') {
    if (confirm('<?php echo getLngt("Den Preistyp wirklich entfernen?") ?>')) {
    	 if (confirm('<?php echo getLngt("Wirklich entfernen? Alle zugehörigen Preisinformationen werden entfernt!") ?>')) {
          finishPage(f_act);
       };
    };
 } else {
    alert('<?php echo getLngt("Es wurde kein Preistyp zum Entfernen ausgewählt!") ?>');
 }
};

function finishPageServiceTypeRemove(f_act) { 
 var service_type_removed = getSelectedValue('f_servicetype_id');
 if (service_type_removed != '') {
    if (confirm('<?php echo getLngt("Den Leistungstyp wirklich entfernen?") ?>')) {
    	 if (confirm('<?php echo getLngt("Wirklich entfernen? Alle zugehörigen Preisinformationen werden entfernt!") ?>')) {
          finishPage(f_act);
       };
    };
 } else {
    alert('<?php echo getLngt("Es wurde kein Leistungstyp zum Entfernen ausgewählt!") ?>');
 }
};

function finishPageServiceChange(f_act) { 
 var service_change = document.forms[0].f_service_change.value;
 if (service_change != '') {
    if (confirm('<?php echo getLngt("Den Preistyp wirklich umbenennen?") ?>')) {
       finishPage(f_act);
    };
 } else {
    alert('<?php echo getLngt("Bitte geben Sie einen Bezeichner ein!") ?>');
 }
};

function finishPageServiceNew(f_act) {
 var service_new = document.forms[0].f_service_new.value;
 if (service_new != '') {
    if (confirm('<?php echo getLngt("Neuen Preistyp anlegen?") ?>')) {
       finishPage(f_act);
    };
 } else {
    alert('<?php echo getLngt("Bitte geben Sie einen Bezeichner ein!") ?>');
 }
};

function finishPageServiceTypeChange(f_act) { 
 var servicetype_change = document.forms[0].f_servicetype_change.value;
 if (servicetype_change != '') {
    if (confirm('<?php echo getLngt("Den Leistungstyp wirklich umbenennen?") ?>')) {
       finishPage(f_act);
    };
 } else {
    alert('<?php echo getLngt("Bitte geben Sie einen Bezeichner ein!") ?>');
 }
};

function finishPageServiceTypeNew(f_act) {
 var servicetype_new = document.forms[0].f_servicetype_new.value;
 if (servicetype_new != '') {
    if (confirm('<?php echo getLngt("Neuen Leistungstyp anlegen?") ?>')) {
       finishPage(f_act);
    };
 } else {
    alert('<?php echo getLngt("Bitte geben Sie einen Bezeichner ein!") ?>');
 }
};

function openGroups(itemType) {
	var itemId = 0;
	var elem = '';
  if (itemType == 'srv') {elem = document.forms[0].f_service_id;};
  if (itemType == 'srvt') {elem = document.forms[0].f_servicetype_id;};
	var optLen = elem.length;
  for (i = 0; i < optLen; ++i) {
    if (elem.options[i].selected == true) {
    	 itemId = elem.options[i].value;
    };
  }
  if (itemType != '' && itemId > 0) {
     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=" + itemType + "&itemId=" + itemId,"","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
  }
};
-->
</script>
<noscript>
  <center>
  <b><br>JavaScript ist nicht verf&uuml;gbar. Bitte aktivieren Sie JavaScript<br><br>
        in Ihrem Browser, damit diese Seite ordnungsgem&auml;&szlig; funktioniert!</b><br><br>
  </center>
</noscript>
</head>

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

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

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

<form action="../admin/services.php" method="post">
  
  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="mode" value="<?php echo ec($mode) ?>">
  <input type="hidden" name="orderByService" value="<?php echo $orderByService ?>">
  <input type="hidden" name="orderByServiceType" value="<?php echo $orderByServiceType ?>">
  <input type="hidden" name="orderByServiceCustomer" value="<?php echo $orderByServiceCustomer ?>">
  <input type="hidden" name="csId" value="<?php echo ec($csId) ?>">
  <input type="hidden" name="opener" value="<?php echo $opener ?>">
  <input type="hidden" name="serviceMode" value="<?php echo $serviceMode ?>">
  <?php echo $phpCurrentNavigationInputHidden ?>
  <input type="hidden" name="deactivateMenu" value="<?php echo ec($deactivateMenu) ?>">

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

  <div class="f12bp1_blue">
    <?php echo $title ?>
  </div>
  <?php echo htmlDivLineSpacer("30px"); ?>

  <div>
    <?php echo defineButtonType10(getLngt("Modus&nbsp;wechseln"), "action_reset", "finishPage('changeMode');", "120", "left", "3"); ?>
  </div>
  <?php echo htmlDivLineSpacer("15px", "", "left"); ?>

  <div>
    <table>
      <?php echo $serviceOutput ?>
    </table>    
  </div>
  <?php echo htmlDivLineSpacer("20px", "", "left"); ?>

  <div>
    <?php echo defineButtonType10(getLngt("Speichern"), "action_save", "finishPage('save');", "100", "left", "3"); ?>
  </div>
  <?php echo htmlDivLineSpacer("40px", "", "left"); ?>

  <?php if ($csId != "0") : ?>
     <div class="f12bp1_blue">
       <?php echo getLngt("Kundenspezifische Preis-/Leistungstypen:") ?>
     </div>
    <?php echo htmlDivLineSpacer("20px", "", "left"); ?>
  <?php endif; ?>  

  <?php if ($serviceMode == "1") : ?>
    <div>
      <div <?php echo setStyleHtmlDiv("130px","left"); ?>><span class="f10bp1_blue"><?php echo getLngt("Preistypen") ?>:</span></div>
      <div>
        <div <?php echo setStyleHtmlDiv("210px","left"); ?>>
          <select name="f_service_id">
          	<option value="">---</option>
            <?php 
              for ($j = 1; $j <= $lenServices; $j++) :
                  if ($csId == "0" || ($csId != "0" && $services["cs_id"][$j])) :
                     $is_selected = "";
                     if ($f_service_id == $services["id"][$j]) : $is_selected = " selected"; endif;
                     echo "<option value=\"" . $services["id"][$j] . "\" " . $is_selected . ">" . $services["name"][$j] . "</option>\n";
                  endif;
              endfor;
            ?>
          </select>
          <?php
            // Check for authorisation to remove single service
            if ($serviceMode >= "1" && authCheckEmployeeRights($emp_id, "31")) :
               echo "&nbsp;<a href=\"javascript:finishPageServiceRemove('remove_service_single');\"><img src=\"../images/waste.png\" border=\"0\" height=\"15\" width=\"12\"></a>";
            endif;
          ?>
        </div>
        <?php 
          if ($csId == "0") :
             echo defineButtonType10(getLngt("Gruppen"), "action_srvgroup", "openGroups('srv');", "90", "left", "5"); 
          endif;
        ?>
        <div <?php echo setStyleHtmlDiv("150px","left"); ?>>
          <input type="text" name="f_service_change" value="" size="20" maxlength="50">&nbsp;&nbsp;
        </div>
        <?php echo defineButtonType10(getLngt("Preistyp&nbsp;umbenennen"), "action_rename", "finishPageServiceChange('save_service_change');", "180", "left", "5"); ?>
        <div <?php echo setStyleHtmlDiv("140px","left"); ?>>
          Neuer&nbsp;Preistyp:
        </div>
        <div <?php echo setStyleHtmlDiv("150px","left"); ?>>
          <input type="text" name="f_service_new" value="" size="20" maxlength="50">&nbsp;&nbsp;&nbsp;
        </div>
        <?php echo defineButtonType10(getLngt("Preistyp&nbsp;anlegen"), "action_new", "finishPageServiceNew('save_service_new');", "180", "left", "3"); ?>
      </div>
    </div>
    <?php echo htmlDivLineSpacer("15px", "", "left"); ?>

    <div>
      <div <?php echo setStyleHtmlDiv("130px","left"); ?>><span class="f10bp1_blue"><?php echo getLngt("Leistungstypen") ?>:</span></div>
      <div>
        <div <?php echo setStyleHtmlDiv("210px","left"); ?>>
          <select name="f_servicetype_id">
          	<option value="">---</option>
            <?php 
              for ($j = 1; $j <= $lenServiceTypes; $j++) :
                  if ($csId == "0" || ($csId != "0" && $serviceTypes["cs_id"][$j])) :
                     $is_selected = "";
                     if ($f_servicetype_id == $serviceTypes["id"][$j]) : $is_selected = " selected"; endif;
                     echo "<option value=\"" . $serviceTypes["id"][$j] . "\" " . $is_selected . ">" . $serviceTypes["name"][$j] . "</option>\n";
                  endif;
              endfor;
            ?>
          </select>
          <?php
            // Check for authorisation to remove single service
            if ($serviceMode >= "1" && authCheckEmployeeRights($emp_id, "31")) :
               echo "&nbsp;<a href=\"javascript:finishPageServiceTypeRemove('remove_service_type_single');\"><img src=\"../images/waste.png\" border=\"0\" height=\"15\" width=\"12\"></a>";
            endif;
          ?>
        </div>
        <?php 
          if ($csId == "0") :
             echo defineButtonType10(getLngt("Gruppen"), "action_srvtgroup", "openGroups('srvt');", "90", "left", "5"); 
          endif;
        ?>
        <div <?php echo setStyleHtmlDiv("150px","left"); ?>>          
          <input type="text" name="f_servicetype_change" value="" size="20" maxlength="50">&nbsp;&nbsp;
          </div>
        <?php echo defineButtonType10(getLngt("Leistungstyp&nbsp;umbenennen"), "action_rename", "finishPageServiceTypeChange('save_servicetype_change');", "180", "left", "5"); ?>
        <div <?php echo setStyleHtmlDiv("140px","left"); ?>>
          Neuer&nbsp;Leistungstyp:
        </div>
        <div <?php echo setStyleHtmlDiv("150px","left"); ?>>
          <input type="text" name="f_servicetype_new" value="" size="20" maxlength="50">&nbsp;&nbsp;&nbsp;
        </div>
        <?php echo defineButtonType10(getLngt("Leistungstyp&nbsp;anlegen"), "action_new", "finishPageServiceTypeNew('save_servicetype_new');", "180", "left", "3"); ?>
      </div>
    </div>
    <?php echo htmlDivLineSpacer("15px", "", "left"); ?>
  <?php endif; ?>

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


<?php
/*
Hi Torben!


"Verwaltung der Endkundenpreise"

Dieses Thema werden wir auf Seite der Auftragserfassung 
implementieren, um die Daten nicht extra ständig aus 
votian per request ziehen zu müssen. 
Derzeit werden per se nur die B2B-Preise (HT <=> Märkte)
gespeichert und die Struktur müsste analog implementiert 
werden.

Ich werde dir gut zuarbeiten, weil wir die analoge
Struktur aus dem votian übernehmen. Ich bereite das vor
und wir besprechen das in der kommenden Woche.


Bitte füge in die DB folgende Tabellen hinzu:


CREATE TABLE service (
  srv_id int(10) NOT NULL auto_increment,
  srv_mode tinyint(1) NOT NULL default '0',
  hq_id int(10) NOT NULL default '0',
  cs_id int(10) NOT NULL default '0',
  srv_name varchar(50) NOT NULL default '',
  srv_group varchar(255) NOT NULL default '',
  srv_sort smallint(3) default '0',
  srv_modify timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (srv_id),
  KEY hq_id (hq_id,srv_name)
) ENGINE=InnoDB;

CREATE TABLE servicetype (
  srvt_id int(10) NOT NULL auto_increment,
  srvt_mode tinyint(1) NOT NULL default '0',
  hq_id int(10) NOT NULL default '0',
  cs_id int(10) NOT NULL default '0',
  srvt_name varchar(50) default NULL,
  srvt_group varchar(255) NOT NULL default '',
  srvt_modify timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (srvt_id),
  KEY hq_id (hq_id,srvt_name)
) ENGINE=InnoDB;


Danke dir!
Bis später,
MC

*/
?>
