<?
    session_start();
    $selelag = $HTTP_SESSION_VARS["SelLanguage"];
    if (empty($selelag)) header("location:../break.php");
    require("../config/".$selelag);
    require("../_ConnectString.php");
    require("../_function.php");
    require("../_image.php");

    $_Pass_Path="/opt/local/apache/htdocs/config_file/chk_attachment_count";
    $_Pass_PathTmp="/tmp/chk_attachment_count";

    function chk_file($value){
        global $_Pass_Path,$_Pass_PathTmp;
        $flag = 0;
        if (!file_exists($_Pass_Path)){
            $fp = fopen($_Pass_PathTmp,"w+");
            fputs($fp,"_ATTACHMENT\n_COUNT\n");
            fclose($fp);
            copy ($_Pass_PathTmp,$_Pass_Path);
        }else{
            $arr = file($_Pass_Path);
            for ($i=0;$i<count($arr);$i++){
                if (substr($arr[$i],0,11) == $value){
                    $flag = 1;
                    break;               
                }else if (substr($arr[$i],0,6) == $value){
                    $flag = 1;
                    break;
                }
            }
            return $flag;
        }
    }

    $_INFORMATION				 = $HTTP_POST_VARS['_INFORMATION'];
    $RunAs				         = $HTTP_POST_VARS['RunAs'];

    if ((isset($HTTP_SESSION_VARS["LoginID_Sess"])) && (isset($HTTP_SESSION_VARS["OperateRole_Sess"])) && (isset($HTTP_SESSION_VARS["GroupNo_Sess"]))){

        if ($RunAs == 'Checkbox'){
            $fp = fopen($_Pass_PathTmp,"w+");
            for($i=0; $i<count($_INFORMATION); $i++){
                fputs($fp,$_INFORMATION[$i]."\n");
            }
            fclose($fp);
            copy ($_Pass_PathTmp,$_Pass_Path);
        }


        if (chk_file(_ATTACHMENT)) $chk_attachment = "checked";
        else $chk_attachment = "";

        if (chk_file(_COUNT)) $chk_count = "checked";
        else $chk_count = "";

    }
    else {
		include("../no_privilege.php");
    }
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=unicode">
<title></title>
<link href="../Display/display.css" type="text/css" rel="stylesheet">
<script language="JavaScript">
	function fn_submit(){
        document.frm.RunAs.value = "Checkbox";
        document.frm.submit();
	}
</script>
</head>
<body>
<form name="frm" action="display.php" method="post">
<input type="hidden" name="RunAs" value="">
<table height="100%" width="100%" cellSpacing="0" cellPadding="0" border="0" align="center" class="style1" style="border-collapse: collapse">
<tr><td align="center" valign="middle">
<table><tr><td>
<input type="checkbox" name="_INFORMATION[]" value="_ATTACHMENT" <?echo $chk_attachment;?>><span class="ContH" title="<?echo $MSN_SHOW?>"><?echo $MSN_SHOW_SHOW?> </span><img src="../<?echo $DIR_IMAGE.$MSNP_ATTACH;?>"></td></tr><tr><td>
<input type="checkbox" name="_INFORMATION[]" value="_COUNT" <?echo $chk_count;?>><span class="ContH" title="<?echo $MSN_SHOWCOUNT?>"><?echo $MSN_SHOWCOUNT_SHOW?></td></tr></table><p>
<input name="Query" type="button" onClick="fn_submit();" value="Submit"></td>
</tr>
</table>
</td></tr></table>
</form>
</body>
</html>
<? if ($RunAs == 'Checkbox'){?>
	<script language="JavaScript">
		opener.navigate("msn.php");
        window.close();
	</script>
<?}?>