<?php

include_once "inc/auth.inc.php";
include_once "inc/utility_all.php";
include_once "inc/utility_file.php";
include_once "inc/editor.php";

if ($IS_MAIN == 1) {
	$QUERY_MASTER = true;
}
else {
	$QUERY_MASTER = "";
}

$HTML_PAGE_TITLE = _("单位管理");
include_once "inc/header.inc.php";
echo "<script type=\"text/javascript\" src=\"/inc/js_lang.php\"></script>\r\n<script src=\"";
echo MYOA_JS_SERVER;
echo "/static/js/jquery-1.10.2/jquery.min.js\"></script>\r\n<script src=\"";
echo MYOA_JS_SERVER;
echo "/static/js/module.js?v=";
echo MYOA_SYS_VERSION;
echo "\"></script>\r\n<script type=\"text/javascript\" src=\"";
echo MYOA_JS_SERVER;
echo "/static/js/utility.js\"></script>\r\n<script type=\"text/javascript\" src=\"";
echo MYOA_JS_SERVER;
echo "/static/js/attach.js\"></script>\r\n<script Language=\"JavaScript\">\r\nvar upload_limit=";
echo MYOA_UPLOAD_LIMIT;
echo ",limit_type=\"";
echo strtolower(MYOA_UPLOAD_LIMIT_TYPE);
echo "\";\r\n\r\nfunction InsertImage(src)\r\n{\r\n    AddImage2Editor('CONTENT', src);\r\n}\r\n\r\nfunction delete_attach(ATTACHMENT_ID,ATTACHMENT_NAME)\r\n{\r\n    var msg = sprintf(\"";
echo _("确定要删除文件 '%s' 吗？");
echo "\", ATTACHMENT_NAME);\r\n    if(window.confirm(msg))\r\n    {\r\n        URL=\"delete_attach.php?ATTACHMENT_ID=\"+ATTACHMENT_ID+\"&ATTACHMENT_NAME=\"+URLSpecialChars(ATTACHMENT_NAME);\r\n        window.location=URL;\r\n    }\r\n}\r\n\r\nfunction IsNumber(str)\r\n{\r\n    return str.match(/^[0-9]*$/)!=null;\r\n}\r\n\r\nfunction IsValidEmail(str)\r\n{\r\n    var re = /@/;\r\n    return str.match(re)!=null;\r\n}\r\n\r\nfunction CheckForm()\r\n{  \r\n    if (document.form1.UNIT_NAME.value==\"\")\r\n    {\r\n        alert(\"";
echo _("单位名称不能为空！");
echo "\");\r\n        return (false);\r\n    }\r\n\r\n    if (document.form1.POST_NO.value!=\"\"&&!IsNumber(document.form1.POST_NO.value))\r\n    {\r\n        alert(\"";
echo _("邮编只能是数字！");
echo "\");\r\n        return (false);\r\n    }\r\n\r\n    if (document.form1.EMAIL.value!=\"\"&&!IsValidEmail(document.form1.EMAIL.value))\r\n    {\r\n        alert(\"";
echo _("请输入有效的电子信箱！");
echo "\");\r\n        return (false);\r\n    }\r\n}\r\n</script>\r\n\r\n";
$query = "SELECT * from UNIT";
$cursor = exequery(TD::conn(), $query, $QUERY_MASTER);

if ($ROW = mysql_fetch_array($cursor)) {
	$UNIT_NAME = $ROW["UNIT_NAME"];
	$UNIT_SHOW_NAME = $ROW["UNIT_SHOW_NAME"];
	$TEL_NO = $ROW["TEL_NO"];
	$FAX_NO = $ROW["FAX_NO"];
	$POST_NO = $ROW["POST_NO"];
	$ADDRESS = $ROW["ADDRESS"];
	$UNIT_URL = $ROW["URL"];
	$EMAIL = $ROW["EMAIL"];
	$BANK_NAME = $ROW["BANK_NAME"];
	$BANK_NO = $ROW["BANK_NO"];
	$ATTACHMENT_ID = $ROW["ATTACHMENT_ID"];
	$ATTACHMENT_NAME = $ROW["ATTACHMENT_NAME"];
	$CONTENT = $ROW["CONTENT"];
	$UNIT_SHOW_NAME = ($UNIT_SHOW_NAME ? $UNIT_SHOW_NAME : $UNIT_NAME);
}

echo "\r\n<body class=\"bodycolor\" onLoad=\"document.form1.UNIT_SHOW_NAME.focus();\">\r\n<form enctype=\"multipart/form-data\" action=\"update.php\"  method=\"post\" name=\"form1\" id=\"form1\" onSubmit=\"return CheckForm();\">\r\n<table class=\"table table-bordered table-hover\" style=\"width:800px\" align=\"center\">\r\n    <tr>\r\n        <td class=\"center\" colspan=\"4\">\r\n            ";
echo _("单位信息");
echo "        </td>\r\n    </tr>\r\n\t<tr>\r\n        <td nowrap class=\"\">";
echo _("授权名称：");
echo "</td>\r\n        <td nowrap class=\"\">";
echo td_htmlspecialchars($UNIT_SHOW_NAME);
echo "        </td>\r\n        <td nowrap class=\"\">";
echo _("单位名称：");
echo "</td>\r\n        <td nowrap class=\"\">\r\n            <input type=\"text\" name=\"UNIT_SHOW_NAME\" class=\"\" size=\"40\" value=\"";
echo td_htmlspecialchars($UNIT_SHOW_NAME);
echo "\">\r\n        </td>\r\n    </tr>\r\n    <tr>\r\n        <td nowrap class=\"\">";
echo _("电话：");
echo "</td>\r\n        <td nowrap class=\"\">\r\n            <input type=\"text\" name=\"TEL_NO\" class=\"\"  size=\"40\" value=\"";
echo td_htmlspecialchars($TEL_NO);
echo "\">&nbsp;\r\n        </td>\r\n        <td nowrap class=\"\">";
echo _("传真：");
echo "</td>\r\n        <td nowrap class=\"\">\r\n            <input type=\"text\" name=\"FAX_NO\" class=\"\" size=\"40\" value=\"";
echo td_htmlspecialchars($FAX_NO);
echo "\">&nbsp;\r\n        </td>\r\n    </tr>\r\n    <tr>\r\n        <td nowrap class=\"\">";
echo _("邮编：");
echo "</td>\r\n        <td nowrap class=\"\">\r\n            <input type=\"text\" name=\"POST_NO\" class=\"\" size=\"40\" value=\"";
echo td_htmlspecialchars($POST_NO);
echo "\">&nbsp;\r\n        </td>\r\n        <td nowrap class=\"\">";
echo _("地址：");
echo "</td>\r\n        <td nowrap class=\"\">\r\n            <input type=\"text\" name=\"ADDRESS\" class=\"\" size=\"40\" data-prompt-position=\"centerRight:0,-4\" value=\"";
echo td_htmlspecialchars($ADDRESS);
echo "\">&nbsp;\r\n        </td>\r\n    </tr>\r\n    <tr>\r\n        <td nowrap class=\"\">";
echo _("网站：");
echo "</td>\r\n        <td nowrap class=\"\">\r\n            <input type=\"text\" name=\"URL\" class=\"\" size=\"40\" value=\"";
echo td_htmlspecialchars($UNIT_URL);
echo "\">&nbsp;\r\n        </td>\r\n        <td nowrap class=\"\">";
echo _("电子信箱：");
echo "</td>\r\n        <td nowrap class=\"\">\r\n            <input type=\"text\" name=\"EMAIL\" class=\"\" size=\"40\" data-prompt-position=\"centerRight:0,-4\" value=\"";
echo td_htmlspecialchars($EMAIL);
echo "\">&nbsp;\r\n        </td>\r\n    </tr>\r\n    <tr>\r\n        <td nowrap class=\"\">";
echo _("开户行：");
echo "</td>\r\n        <td nowrap class=\"\">\r\n            <input type=\"text\" name=\"BANK_NAME\" class=\"\" size=\"40\" value=\"";
echo td_htmlspecialchars($BANK_NAME);
echo "\">&nbsp;\r\n        </td>\r\n        <td nowrap class=\"\">";
echo _("账号：");
echo "</td>\r\n        <td nowrap class=\"\">\r\n            <input type=\"text\" name=\"BANK_NO\" class=\"\" size=\"40\" value=\"";
echo td_htmlspecialchars($BANK_NO);
echo "\">&nbsp;\r\n        </td>\r\n    </tr>\r\n    <tr>\r\n        <td nowrap class=\"\" colspan=\"4\" >";
echo _("单位简介");
echo "</td>\r\n    </tr>\r\n";

if ($ATTACHMENT_ID != "") {
	echo "    <tr class=\"\" id=\"attachment2\">\r\n        <td colspan=\"1\" nowrap>";
	echo _("附件文档：");
	echo "</td>\r\n        <td colspan=\"3\" nowrap>";
	echo attach_link($ATTACHMENT_ID, $ATTACHMENT_NAME, 1, 1, 1, 1, 1, 1, 1, 1);
	echo "</td>\r\n    </tr>\r\n";
}

echo "\r\n    <tr height=\"25\" id=\"attachment1\">\r\n        <td nowrap class=\"\"><span id=\"ATTACH_LABEL\">";
echo _("附件上传：");
echo "</span></td>\r\n        <td class=\"\" colspan=\"3\">\r\n            <script>ShowAddFile();ShowAddImage();</script>\r\n            <input type=\"hidden\" name=\"ATTACHMENT_ID_OLD\" value=\"";
echo $ATTACHMENT_ID;
echo "\">\r\n            <input type=\"hidden\" name=\"ATTACHMENT_NAME_OLD\" value=\"";
echo $ATTACHMENT_NAME;
echo "\">\r\n        </td>\r\n    </tr>\r\n     \r\n    <tr id=\"EDITOR\">\r\n        <td class=\"\" colspan=\"4\">\r\n";
$editor = new Editor("CONTENT");
$editor->Height = "350";
$editor->Value = $CONTENT;
$editor->Create();
echo "        </td>\r\n    </tr>\r\n    <tr>\r\n        <td nowrap  class=\"\" colspan=\"4\" align=\"center\" style=\"text-align:center\">\r\n            <input type=\"submit\" value=\"";
echo _("保存单位设置");
echo "\" class=\"btn btn-primary\">\r\n           </td>\r\n    </tr>\r\n</table>\r\n</form>\r\n</body>\r\n</html>";

?>
