<?

$thisprog="shareforum.php";
$shareforumfile="datafile/shareforum.php";

require("adminglobal.php");

print "    <tr><td bgcolor=#80809b colspan=3><font color=#FFFFFF>
    <b>欢迎来到讨论区管理程式 / 联盟论坛管理</b>
    </td></tr>
";

if (file_exists($shareforumfile)) {
	$shareforumdata=file($shareforumfile);
	$count=count($shareforumdata);
}

if (empty($action)) {
	$shareforumselect="";
	for($i=0; $i<$count; $i++) {
	  $detail=explode("|",$shareforumdata[$i]);
	  $shareforumselect.="<option value=\"$detail[0]\">$detail[0]</option>";
	}
	$shareforumselect.="</select>";
	print <<<EOT
    <tr><td bgcolor=#FFFFFF colspan=3>
    <b>1.新建一个联盟论坛项目：</b>
    <form action="$thisprog" method=POST><input type=hidden name="action" value="create">
    $tab_top
    没什么要解释的吧<br>
    LOGO地址：<input type=text name="name" size=30>&nbsp;URL：<input type=text name="url" size=30><br>
    描述：<input type=text name="des" size=70> <input type=submit value="提 交">
    $tab_bottom</form>
    <b>2.修改/删除联盟论坛：</b>
    <form action="$thisprog" method=POST><input type=hidden name="action" value="modify">
    $tab_top
    我看还是没什么要解释的。<br>
    动作对象：<select name="target">$shareforumselect <input type=radio checked name="job" value="modify">修改 <input type=radio name="job" value="delete">删除 (下面资料不填则不做修改)<br>
    LOGO地址：<input type=text name="name" size=30>&nbsp;URL：<input type=text name="url" size=30><br>
    描述：<input type=text name="des" size=70> <input type=submit value="提 交">
    $tab_bottom</form>
    </td></tr></td></tr></table></body></html>
EOT;
exit;
}elseif ($action=="create") {
//-------新建项目-----------
	$newstring="";
	print "<tr><td bgcolor=#EEEEEE valign=middle align=center colspan=2><b>新建联盟论坛</b></td></tr>
	<tr><td bgcolor=FFFFFF colspan=2>";

	$name=str_replace("|","",$name);
	$url=str_replace("|","",$url);
	$des=str_replace("|","",$des);
	
	$newstring="$name|$url|$des\n";
	if (!empty($name) && !empty($url) && !empty($des)) {
	  $fp=fopen($shareforumfile,"a");
	  if (fwrite($fp,$newstring)) echo "<br><br>成功更新联盟论坛列表资料<b></b><br>";
	    else echo "<br><br>联盟论坛列表更新失败，请检查datafile目录属性<b></b><br>";
	  fclose($fp);
	} else echo "<br><br>联盟论坛列表更新失败，请检查所提交数据是否完整<b></b><br>";
}elseif ($action=="modify") {
	print "<tr><td bgcolor=#EEEEEE valign=middle align=center colspan=2><b>修改/删除联盟论坛</b></td></tr>
	<tr><td bgcolor=FFFFFF colspan=2>";
	$name=str_replace("|","",$name);
	$url=str_replace("|","",$url);
	$des=str_replace("|","",$des);
	$new="";
	for ($i=0; $i<$count; $i++) {
		$detail=explode("|",$shareforumdata[$i]);
		if ($target==$detail[0]) {
		  if ($job=="modify") {
			if (!empty($name)) $detail[0]=$name;
			if (!empty($url)) $detail[1]=$url;
			if (!empty($des)) $detail[2]=$des."\n";
			$new.=implode("|",$detail);
		  }
		} else $new.=$shareforumdata[$i];
	}
	writetofile($shareforumfile,$new);
}
print "<br><b>&nbsp;操作完成</b><br><br>&nbsp;&gt;&gt; <a href=$thisprog>返回执行其他动作</a></td></tr></table></body></html>";
exit;