<?php
#=============================================================#
#                                                             #
#           Powered by Dvbbs.PHP 2.0.0                        #
#           function  DownLoad 效益                           #
#           author    IvanSky                                 #
#           date      2007-9-3                                #
#                                                             #
#=============================================================#
if( !defined('ISDVBBS') ){
	header('HTTP/1.0 404 Not Found');
	exit;
}

?>

<script language=javascript> 
var vBobjects = new Array();
function fetch_object(idname, forcefetch)
{
	if (typeof(vBobjects[idname]) == "undefined")
	{
		vBobjects[idname] = MM_findObj(idname);
	}
	return vBobjects[idname];
}
function getGroup(Did)
{
var SGroup = fetch_object(Did);
	if (SGroup){
		if (SGroup.style.display=='none'){
		SGroup.style.top = '120px'//(document.body.scrollTop+((document.body.clientHeight-1000)/2))+"px";
		SGroup.style.left = '340px'//(document.body.scrollLeft+((document.body.clientWidth-480)/2))+"px";
		SGroup.style.display = '';
		}
		else{
			var SelGroupid = fetch_object("SelGroupid");
			var groupid = fetch_object("groupid");
			var Val="";
			SGroup.style.display='none';
			if (SelGroupid){
				for (var i=0;i<SelGroupid.length;i++){
					if (SelGroupid.options[i].selected){
						Val += SelGroupid.options[i].value;
						Val += ",";
					}
				}
				groupid.value = Val.substr(0,Val.lastIndexOf(","));
			}
		}
	}
}
function ad_winOpen(strUrl,strWid,strHei)
{ 
	window.open(strUrl,"","height="+strHei+",width="+strWid+",status=no,location=no,toolbar=no,directories=no,menubar=no,scrollbars=yes");
	//var win = window.showModalDialog(strUrl,strUrl,"dialogWidth=500px;dialogHeight=300px;center=yes;status=no");


} 
function storeCaret (o) {
	if (o.createTextRange) 
	o.caretPos = document.selection.createRange().duplicate();    
}
function insertAtCaret (o,w,h,fileurl,fileurlHide) {
	if (o.createTextRange && o.caretPos) {
		var text ;
		var tagname ;
		if (fileurl != ''){
			var f=fileurl.substr(fileurl.lastIndexOf(".")+1,3);
			if(f=="gif"||f=="jpg"  ){ 
				tagname = 'img';
			}else if (f=="swf"){
				tagname = 'flash';
			}
			text = '['+tagname+'Tmp='+w+','+h+']'+fileurl+'[/'+tagname+'Tmp]';
		}else if (fileurlHide!=''){
			var f=fileurlHide.substr(fileurlHide.lastIndexOf(".")+1,3);
			if(f=="gif"||f=="jpg"  ){ 
				tagname = 'img';
			}else if (f=="swf"){
				tagname = 'flash';
			}
			text = '['+tagname+'='+w+','+h+']'+fileurlHide+'[/'+tagname+']';
		}else{
			text = '';
		}
		var caretPos = o.caretPos;
		caretPos.text =caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?text + ' ' : text;  

	}      
}
function ShowDBtype(N){
	document.getElementById('DB_HTML_DIS').style.display=N;
	document.getElementById('DB_img_DIS').style.display=N;
}
</script> 

<?
//Select_Group($SelGroupID);

if (empty($do_action) or !isset($do_action)) { ?> 
<table border="0" cellspacing="0" cellpadding="0"  align="center" class="indextableborder1">
<tr> 
<td class="tdtit" colspan="6"><?=$lang['str.info11']?></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="0"  align="center" class="tableborder">
<form name="f_name" method="post" action="" > 

<tr>
<td colspan="8">
	<table cellpadding="0" cellspacing="0" width="100%">
	<tr class="forumrow2">
		<td width="18%" align="center"><?=$lang['str.info8']?></td>
		<td width="20%" align="center"><?=$lang['str.info1']?></td>
		<td width="16%" align="center"><?=$lang['str.info2']?></td>
		<td width="16%" align="center"><?=$lang['str.info3']?></td>
		<td width="12%" align="center"><?=$lang['str.info4']?></td>
		<td width="8%" align="center"><?=$lang['str.info5']?></td>
		<td width="5%" align="center"><?=$lang['str.info6']?></td>
		<td width="5%" align="center"><b><?=$lang['ad.preview']?></b></td>
		</tr>
	</table>
</td>
</tr>

<?
	if(!empty($arrDownLoad_benefit))
	{
		if(is_array($arrDownLoad_benefit))
		{
			foreach($arrDownLoad_benefit as $k => $vv)
			{

?>
	<tr style="padding:1px;height:25px;">
	<td width="20%" class="forumrow"><?=$vv['DB_name']?></td>
	<td width="20%" class="forumrow">
	<select name="DB_boardid" style="border:1px;">
	<?
		print boardjumplist($vv['DB_boardid'],$lang['search']);
			if($getskinid==1){
				$check='checked';
			}
			else{
				$check='';
			}
	?>
     </select>
	</td>
	<td width="16%" class="forumrow"><?=gmdate('Y-m-d H:i', $vv['DB_starttime'])?></td>
	<td width="16%" class="forumrow"><?=gmdate('Y-m-d H:i', $vv['DB_endtime'])?></td>
	<td width="8%" class="forumrow"><?=$vv['DB_dot']?></td>
	<td width="10%" class="forumrow"><A HREF="?do_action=startclose&setDB_Close=<?=$vv['DB_close']?>&setDB_id=<?=$vv['DB_id']?>" title="<?$DB_close=($vv['DB_close']==1)?$lang['str.add.info17']:$lang['str.add.info16'];echo $DB_close; ?>"><?$DB_close=($vv['DB_close']==1)?$lang['str.add.info12']:$lang['str.add.info13'];echo $DB_close; ?></A></td>
	<td width="5%"  class="forumrow"> <input type="checkbox" name="selected_id[]" value="<?=$vv['DB_id']?>"></td>
	<td width="5%" class="forumrow"><input name="preview" type="button" id="preview" value=" <?=$lang['ad.preview']?> " class="button"   onclick="ad_winOpen('../DownLoad_benefit_preview.php?getDB_id=<?=$vv['DB_id']?>','<?=$vv['DB_width']?>','<?=$vv['DB_height']?>')" ></td>
	</tr>
<?

			}
		}
	}
?>
<tr><td colspan="8" height="1" bgcolor="#0000ff"></td></tr>
<tr><td colspan="8" align="left" style="height:30px;" class="forumrow1"><?=$lang['template.info1']?>
<input name="select_all" type="checkbox" id="select_all"  value="Y" onclick="allun(this)">&nbsp;
<input name="del_sel" class="button" onclick="f_del('?do_action=del')" type="button" id="del_sel" value=" <?=$lang['ad.del']?> ">&nbsp;&nbsp;&nbsp;
<input name="edit_sel" class="button" onclick="f_edit('?do_action=edit')" type="button" id="del_sel" value=" <?=$lang['ad.edit']?> ">
</td></tr>
</table>
</td>
</tr>
  </form>
 </table>



 <?}elseif ($do_action == "add"){
	$start_time = gmdate('Y-m-d H:i', time()+getUserTimeZoneOffset());
	$end_time = gmdate('Y-m-d H:i', time()+(24*3600*7)+getUserTimeZoneOffset());
	 
	 ?> 
<table border="0" cellspacing="0" cellpadding="0"  align="center" class="indextableborder1">
<tr> 
<td class="tdtit" colspan="6"><?=$lang['str.info10']?></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="0"  align="center" class="tableborder">
<form name="DB_form" method="post" action="?do_action=save" enctype="multipart/form-data"> 
<input type="hidden" name="do_action" value="save">
<input name="groupid" type="hidden" value="">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<tr >
  <td class="forumrow"><?=$lang['str.add.info177']?></td>
  <td class="forumrow"><?=$lang['str.add.info178']?><INPUT TYPE="radio" NAME="DB_type" value="1" checked="checked" onclick="ShowDBtype('none')"><?=$lang['str.add.info179']?> <INPUT TYPE="radio" NAME="DB_type" value="2" onclick="ShowDBtype('')"></td>
</tr>  
<tr >
  <td class="forumrow"><?=$lang['str.add.info180']?></td>
  <td class="forumrow"><input type="button" class="button" value="<?=$lang['str.add.info181']?>" onclick="getGroup('Select_Group');"></td>
</tr>  
<tr >
  <td class="forumrow"><?=$lang['str.add.info14']?></td>
  <td class="forumrow"><input type="text" size="38" name="DB_name" id="DB_name" style="border:1px;"   maxLength=100></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info15']?></td>
  <td class="forumrow"><input type="text" size="38" name="DB_linkurl" id="DB_linkurl" style="border:1px;"   maxLength=200>&nbsp;<?=$lang['str.add.info18']?></td>
  </tr>
  <tr >
  <td width="30%" class="forumrow"><?=$lang['str.add.info1']?></td>
  <td width="70%" class="forumrow">
    	<select name="DB_boardid" style="border:1px;">
	<?
		print boardjumplist($GLOBALS['DBboardid'],$lang['search']);
			if($getskinid==1){
				$check='checked';
			}
			else{
				$check='';
			}
	?>
     </select>
  </td>
 </tr>
  <tr id="DB_HTML_DIS" style="display:none;">
  <td class="forumrow"><?=$lang['str.add.info182']?></td>
  <td class="forumrow">
  <div class="eidtor_bj" >
	<div class="eidtor_top" >
	<input type="button" id="dvEditor_ImgUrl" value="<?=$lang['str.add.info183']?>">
	<input type="button" id="dvEditor_FlashUrl" value="<?=$lang['str.add.info184']?>">
	</div>
  <textarea name="DB_HTML" id="DB_HTML"  WRAP="soft" style="width:98%;height:100px;color:#00CC99" rows="20" cols="20" ONSELECT="storeCaret(this);" ONCLICK="storeCaret(this);" ONKEYUP="storeCaret(this);">

</textarea>
  </div>
  </td>
  </tr>
<!--   <tr >
  <td class="forumrow">上传图片数量</td>
  <td class="forumrow"><input type="text" size="10" name="DB_filenum" id="DB_filenum" style="border:1px;" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" maxLength="2" value="1"  maxLength=4 >&nbsp;个</td>
  </tr> -->
  <tr >
  <td class="forumrow"><?=$lang['str.add.info2']?></td>
  <td class="forumrow"><input type="file" size="38" name="DB_File" id="DB_File" class="button"><span  id="DB_img_DIS" style="display:none">&nbsp;&nbsp;
  <?=$lang['str.add.info185']?><input type="text" size="6" name="DB_img_width" id="DB_img_width" style="border:1px;" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" value="300"  maxLength=4>
  &nbsp;&nbsp;<?=$lang['str.add.info186']?><input type="text" size="6" name="DB_img_height" id="DB_img_height" style="border:1px;" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" value="200"  maxLength=4>
  <INPUT TYPE="button" VALUE="<?=$lang['str.add.info187']?>"  ONCLICK="insertAtCaret(DB_form.DB_HTML,DB_form.DB_img_width.value,DB_form.DB_img_height.value ,DB_form.DB_File.value,'');"></span></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info3']?></td>
  <td class="forumrow"><input type="text" size="10" name="DB_width" id="DB_width" style="border:1px;" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" value="600"  maxLength=4>&nbsp;<?=$lang['str.add.info10']?></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info4']?></td>
  <td class="forumrow"><input type="text" size="10" name="DB_height" id="DB_height" style="border:1px;" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" value="400"  maxLength=4>&nbsp;<?=$lang['str.add.info10']?></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info5']?></td>
  <td class="forumrow"><input type="text" size="10" name="DB_second" id="DB_second" style="border:1px;" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" value="10"  maxLength=3>&nbsp;<?=$lang['str.add.info11']?></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info6']?></td>
  <td class="forumrow"><input type="text" size="22" name="DB_starttime" id="DB_starttime" value="<?=$start_time?>" style="border:1px;">&nbsp;<?=$lang['str.add.info8']?></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info7']?></td>
  <td class="forumrow"><input type="text" size="22" name="DB_endtime" id="DB_endtime" value="<?=$end_time?>" style="border:1px;"></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info9']?></td>
  <td class="forumrow"><input type="radio" name="DB_close" value="1" checked="checked" class="radio"/> <?=$lang['str.add.info12']?>&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="DB_close" value="2" class="radio"/> <?=$lang['str.add.info13']?></td>
  </tr>
  <tr><td colspan="6" style="height:30px;text-align:center;" class="forumrow1">
  <input class="button" type="submit" name="submit" id="save" value=" <?=$lang['ad.save']?> " >
  </td>

   </tr>
   </form>
</table>
<?
 Select_Group(0,0);
 }elseif ($do_action == "edit"){

?> 
<table width="100%" border="0" cellspacing="1" cellpadding="1"  align="center" class="tableborder">
<form name="DB_form" method="post" action="?do_action=edit" enctype="multipart/form-data"> 
<input type="hidden" name="do_action" value="edit">
<input type="hidden" name="self_action" value="saveedit">
<input type="hidden" name="strDB_id" value="<?=$GetArrDB['DB_id']?>">
<input type="hidden" name="DB_dot" value="<?=$GetArrDB['DB_dot']?>">
<input type="hidden" name="selected_id" value="<?=$selected_id?>">
<input type="hidden" name="oldDB_File" value="<?=$GetArrDB['DB_File']?>">
<input type="hidden" name="groupid" value="<?=$GetArrDB['DB_groupid']?>">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">

  <tr>
  <td class="tit1" colspan="6">
    </td>
  </tr>
<tr >
  <td class="forumrow"><?=$lang['str.add.info177']?></td>
  <td class="forumrow"><?=$lang['str.add.info178']?><INPUT TYPE="radio" NAME="DB_type" value="1" <?if (intval($GetArrDB['DB_type'])===1)echo 'checked="checked"';?> onclick="ShowDBtype('none')"> <?=$lang['str.add.info179']?><INPUT TYPE="radio" NAME="DB_type" value="2" <?if (intval($GetArrDB['DB_type'])===2)echo 'checked="checked"';?> onclick="ShowDBtype('')"></td>
</tr>  
<tr >
  <td class="forumrow"><?=$lang['str.add.info180']?></td>
  <td class="forumrow"><input type="button" class="button" value="<?=$lang['str.add.info181']?>" onclick="getGroup('Select_Group');"></td>
</tr>  

  <tr >
  <td class="forumrow"><?=$lang['str.add.info14']?></td>
  <td class="forumrow"><input type="text" size="38" name="DB_name" id="DB_name" value="<?=$GetArrDB[DB_name]?>" style="border:1px;"   maxLength=100></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info15']?></td>
  <td class="forumrow"><input type="text" size="38" name="DB_linkurl" id="DB_linkurl" value="<?=$GetArrDB[DB_linkurl]?>" style="border:1px;"   maxLength=200>&nbsp;<?=$lang['str.add.info18']?></td>
  </tr>

  <tr >
  <td width="30%" class="forumrow"><?=$lang['str.add.info1']?></td>
  <td width="70%" class="forumrow">
    	<select name="DB_boardid" style="border:1px;">
	<?
		print boardjumplist($GetArrDB['DB_boardid'],$lang['search']);
			if($getskinid==1){
				$check='checked';
			}
			else{
				$check='';
			}
	?>
     </select>
  </td>
  </tr>
  <tr id="DB_HTML_DIS" style="display:none;">
  <td class="forumrow"><?=$lang['str.add.info182']?></td>
  <td class="forumrow">
  <div class="eidtor_bj" >
	<div class="eidtor_top" >
	<input type="button" id="dvEditor_ImgUrl" value="<?=$lang['str.add.info183']?>">
	<input type="button" id="dvEditor_FlashUrl" value="<?=$lang['str.add.info184']?>">
	</div>
  <textarea name="DB_HTML" id="DB_HTML"  WRAP="soft" style="width:98%;height:100px;color:#00CC99" rows="20" cols="20" ONSELECT="storeCaret(this);" ONCLICK="storeCaret(this);" ONKEYUP="storeCaret(this);"><?=str_replace(array('\\','\\\\'),array('',''),$GetArrDB[DB_HTML])?></textarea>
  </div>
  </td>
  </tr>
 <tr >
  <td class="forumrow"><?=$lang['str.add.info2']?></td>
  <td class="forumrow"><input type="file" size="38" name="DB_File" id="DB_File" class="button">
  <INPUT TYPE="hidden" NAME="DB_FileHide" id="DB_FileHide" value="<?=$GetArrDB[DB_File]?>"><span id="DB_img_DIS" style="display:none">&nbsp;&nbsp;
  <?=$lang['str.add.info185']?><input type="text" size="6" name="DB_img_width" id="DB_img_width" style="border:1px;" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" value="300"  maxLength=4>
  &nbsp;&nbsp;<?=$lang['str.add.info186']?><input type="text" size="6" name="DB_img_height" id="DB_img_height" style="border:1px;" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" value="200"  maxLength=4>
  <INPUT TYPE="button" VALUE="<?=$lang['str.add.info187']?>"  ONCLICK="insertAtCaret(DB_form.DB_HTML,DB_form.DB_img_width.value,DB_form.DB_img_height.value ,DB_form.DB_File.value,DB_form.DB_FileHide.value);"></span>
  </td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info3']?></td>
  <td class="forumrow"><input type="text" size="10" name="DB_width" value="<?=$GetArrDB[DB_width]?>" id="DB_width" style="border:1px;" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"  maxLength=4>&nbsp;<?=$lang['str.add.info10']?></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info4']?></td>
  <td class="forumrow"><input type="text" size="10" name="DB_height" value="<?=$GetArrDB[DB_height]?>"  id="DB_height" style="border:1px;" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"  maxLength=4>&nbsp;<?=$lang['str.add.info10']?></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info5']?></td>
  <td class="forumrow"><input type="text" size="10" name="DB_second" value="<?=$GetArrDB[DB_second]?>"  id="DB_second" style="border:1px;" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"  maxLength=3>&nbsp;<?=$lang['str.add.info11']?></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info6']?></td>
  <td class="forumrow"><input type="text" size="22" name="DB_starttime" value="<?=gmdate('Y-m-d H:i', $GetArrDB[DB_starttime])?>" id="DB_starttime"  style="border:1px;">&nbsp;<?=$lang['str.add.info8']?></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info7']?></td>
  <td class="forumrow"><input type="text" size="22" name="DB_endtime" value="<?=gmdate('Y-m-d H:i', $GetArrDB[DB_endtime])?>"  id="DB_endtime"  style="border:1px;"></td>
  </tr>
  <tr >
  <td class="forumrow"><?=$lang['str.add.info9']?></td>
  <td class="forumrow"><input type="radio" name="DB_close" value="1" <?if ($GetArrDB[DB_close]==1)echo 'checked="checked"';?> class="radio"/> <?=$lang['str.add.info12']?>&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="DB_close" <?if ($GetArrDB[DB_close]==2)echo 'checked="checked"';?> value="2" class="radio"/> <?=$lang['str.add.info13']?></td>
  </tr>
  <tr><td colspan="6" align="center" height="30" class="forumrowc">
  <input class="button" type="submit" name="submit" id="edit" value=" <?=$lang['ad.saveedit']?> " >
  </td>

   </tr>
   </form>
</table>
<SCRIPT LANGUAGE="JavaScript">
<!--
	ShowDBtype('<?if (intval($GetArrDB[DB_type])===2)echo "block";else echo "none";?>')
//-->
</SCRIPT>
 <?
 Select_Group(0,$GetArrDB[DB_groupid]);
 }?> 

<script src="../templates/lang/zh-cn/js/main.js" type="text/javascript" ></script>
<script src="../templates/lang/zh-cn/js/post/dveditor.js" type="text/javascript" ></script>
<SCRIPT LANGUAGE="JavaScript">
<!--
	var IframeID=document.getElementById('DB_HTML');
	initMenuText();
//-->
</SCRIPT>



<?

function Select_Group($SelGroupID,$sGroupId){
	global $dv,$db,$lang;
?>
<div id="Select_Group" style="POSITION:absolute;Z-INDEX: 99;display:none;">
<table border="0" style="width:400px;"><tr><td class="td1">
<select name="SelGroupid" id="SelGroupid" size="28" style="width:100%" multiple="multiple">
<?
	$query=$db->query("select title,usertitle,usergroupid,parentgid from {$dv}usergroups where parentgid > 0 and usergroupid<>{$SelGroupID} order by parentgid,usergroupid");
	while($group = $db->fetch_array($query)){
		$show_selected = '';
		if (false!==strpos($sGroupId,',')){
			$arrGroupid = explode(',',$sGroupId);
			foreach($arrGroupid as $v){
				if (intval($group['usergroupid']) === intval($v)) {$show_selected = 'selected';break;}
			}
		}elseif (intval($group['usergroupid'])=== intval($sGroupId)){
			$show_selected = 'selected';
		}
?>
<option value="<?=$group['usergroupid']?>" <?=$show_selected?>> <?=$lang['sys_group_'.$group['parentgid']]?> <?=$group['usertitle']?></option>
<?
	}
?>
</select>
</td></tr>
<tr><td class="tit1" style="text-align:center;">
<input type="button" class="button" value="<?=$lang['str_button']?>" onclick="getGroup('Select_Group')" /> <?=$lang['str_redame1']?>
</td></tr>
</table>
</div>
<?
}
?>

