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

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


$httpVarsArray = array("f_act", "courierId", "orderClause", "statusMessage", "f_msggrp", "deactivateMenu");

getSecHttpVars("1", $httpVarsArray);

getLanguage(__FILE__);

$deactivateMenuStatic = "1";
$pageTitel = getLngt("NACHRICHTENGRUPPEN");
include_once ("../admin/menu.php");
include_once ("../include/html.inc.php");
getCurrentScript(__FILE__);

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


// Only for output
$htmlClass01 = "class=\"smaller\"";                // input,select
$html_td_01  = "valign=\"top\" align=\"left\"";    // input
$html_td_02  = "valign=\"top\" align=\"right\"";   // input


// Implode courier message groups
$f_msggrp2 = getImplodedFilterstring($f_msggrp);


   // Set message group(s) of the courier
   if ($f_act == "setCourierMsgGrp" && $courierId != "") :

      TA("B");       

      // Update message groups
      updateStmt("courier","cr_id",$courierId,array("cr_msggrp", $f_msggrp2));

      // Write logdata into log database
      writeToLogDB("66",$hq_id,"",$usr_id,$courierId,"","","MESSAGEGROUPS=".$f_msggrp2);

      TA("C");
      TA("E");
   endif;
   
  
   
   // ***************************************
   // * Selection of the message group data *
   // ***************************************
   /*   
   $sqlquery = "SELECT msggrp.msggrp_id, msggrp.hq_id, msggrp.msggrp_name"
                   . " FROM messagegroup AS msggrp"
                   . " WHERE msggrp.hq_id = $hq_id"
                   . " ORDER BY msggrp.msggrp_id";
   $result = $db->query($sqlquery);
   if (DB::isError($result)) die ("$PHP_SELF: " . $result->getMessage());
   
   while ($row = $result->fetch_assoc()): 
         $f_msggrp_id_array[] = $row["msggrp_id"];
   endwhile;
   $result->free();
   */

   // Courier message groups
   $f_msggrp = getFieldValueFromId("courier", "cr_id", "$courierId", "cr_msggrp");
   $f_msggrp = substr($f_msggrp, 1, (strlen($f_msggrp) - 2) );
   $f_msggrp = spliti(",",$f_msggrp);
   $output = addCheckboxesFromTable ("f_msggrp", "messagegroup", "msggrp_id", "msggrp_name", "msggrp_id", "hq_id =" . $hq_id, $f_msggrp, "<br><br>");


   // Only for output
   $tmp_usr_id = getFieldValueFromId("courier", "cr_id", "$courierId", "usr_id");
   $tmpFields = getFieldsValueFromId("user","usr_id",$tmp_usr_id,array("usr_name","usr_firstname"));
   $tmp_usr_name = $tmpFields[0];
   $tmp_usr_firstname = $tmpFields[1];   
   $title = getLngt("Nachrichtengruppen für") . " " . $tmp_usr_firstname . " " . $tmp_usr_name;
?>

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

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

function finishPage(mode) {
  var ok = true;

  if (mode == 'save') {
     // if (!NaN(document.forms[0].f_crvh_prov.value, '<?php echo getLngt("Bitte tragen Sie eine Zahl bei Provision ein!") ?>')) {ok = false;};

     if (ok) {
     	  document.forms[0].f_act.value='setCourierMsgGrp';
     	  document.forms[0].submit();
     }; 
  }

  if (mode == 'reset') {
     document.location.href = "courier_msggrp.php?courierId=<?php echo ec($courierId) ?>";  
  }
};
-->
</script>

</head>

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

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

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

<form action="../admin/courier_msggrp.php" method="post">
  <input type="hidden" name="f_act" value="">
  <input type="hidden" name="courierId" value="<?php echo ec($courierId) ?>">
  <?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("10px"); ?>
  
  <!-- Message groups -->
  <div>
    <table>   
      <tr>
        <td>          
          <?php echo $output ?>
        </td>      
      </tr>
    </table>  
  </div>

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

  <div>
    <?php echo defineButtonType10(getLngt("Speichern"), "action_save", "finishPage('save');", "100", "left", "3"); ?>
    <?php echo defineButtonType10(getLngt("Zurücksetzen"), "action_close", "finishPage('reset');", "100", "left", "3"); ?>
    <?php echo defineButtonType10(getLngt("Schließen"), "action_close", "window.close();", "100", "left", "3"); ?>
  </div>
  
</form>
</div>
</body>

</html>
