<?php
require_once '../include/adminfunction.php';
checkadmin();

function updatesettext($text){
	if($text=="")
		return "";
    $text=str_replace("'",'"',$text);
    $text=str_replace("\r","",$text);
    $text=str_replace("\n","",$text);
    return $text;
}

$pageid=var_request("pageid","");
$typeid = var_request("typeid","");
$action=var_request("action","");
$tp=var_request("tp","");
$arri=var_request("i","");

$arrays = application("page".$pageid,"../data/singerpagedate.php");
$pageinfo = application("singerpagelist","../data/singerpagedate.php");

if(!is_array($arrays)){
	$arrays = array();
}



$errmsg = "";
$pagetext="";
if($action=="update" || $action=="add"){
	
	$ctypename = updatesettext(var_request("typename",""));
	$ctypeurl = updatesettext(var_request("typeurl",""));
	$cappno = var_request("appno","0");
	$cbutton = var_request("button","0");
	
	$arrayNow = array();
	$arrayNow['typename'] = $ctypename;
	$arrayNow['typeurl'] = $ctypeurl;
		
	if($action=="add"){
		$arrayNow['keywordlist'] = array();
		array_push($arrays,$arrayNow);
	}
	if($action=="update" && $cbutton=="修改"){
		$arrays[$cappno]['typename'] = $arrayNow['typename'];
		$arrays[$cappno]['typeurl'] = $arrayNow['typeurl'];
	}
	if($action=="update" && $cbutton=="删除"){
		array_splice($arrays,$cappno,1);
	}
	setapplication("page".$pageid,$arrays,"../data/singerpagedate.php");
	
	redirect_to("ManageSingerPageEdit.php?pageid=".$pageid);
	exit;
	
}

if($action=="updatelink" || $action=="addlink"){
	
	$ctitle = updatesettext(var_request("title",""));
	$cpic = updatesettext(var_request("pic",""));
	$cshoplevel = updatesettext(var_request("shoplevel",""));
	$clink = updatesettext(var_request("link",""));
	$cappno = var_request("appno","0");
	$cbutton = var_request("button","0");
	
	$arrayNow = array();
	$arrayNow['title'] = $ctitle;
	$arrayNow['pic'] = $cpic;
	$arrayNow['shoplevel'] = $cshoplevel;
	$arrayNow['link'] = $clink;
	
	
	if($action=="addlink"){
		array_push($arrays[$typeid]['keywordlist'],$arrayNow);
	}
	if($action=="updatelink" && $cbutton=="修改"){
		$arrays[$typeid]['keywordlist'][$cappno] = $arrayNow;
	}
	if($action=="updatelink" && $cbutton=="删除"){
		array_splice($arrays[$typeid]['keywordlist'],$cappno,1);
	}
	//dump($arrays);
	setapplication("page".$pageid,$arrays,"../data/singerpagedate.php");
	
	redirect_to("ManageSingerPageEdit.php?pageid=".$pageid);
	exit;
	
}

?>

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>315爱购网</title>
	<link rel='stylesheet' href='images/order.css'>
    <style type="text/css">
<!--
.STYLE2 {color: #FF0000}
-->
    </style>
</head>

<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
<center>
  <table width="96%" border="0" cellpadding="3" cellspacing="1" bgcolor="#cccccc">
    <tr>
    <td height="30" colspan="2" align="center" bgcolor="#FFFFFF"><strong>页面名称： <?php echo $pageinfo[$pageid]['pagetitle']?></strong></td>
  </tr>
</table>
    <table width="96%" border="0" cellpadding="3" cellspacing="1" bgcolor="#cccccc">
    <tr bgcolor="#c8ddf4">
      <td align="left" bgcolor="#FFFFFF" class="paragraph" title="20039669">




    <table border="0" cellpadding="3" cellspacing="1" bgcolor="#cccccc">
<?php 
if(is_array($arrays) && Count($arrays)>0){
	for($i=0;$i<Count($arrays);$i++){
?>    
    <form name="form1" method="post" action="ManageSingerPageEdit.php?action=update&pageid=<?php echo $pageid ?>" style=" margin:0px; padding:0px;">
    <tr bgcolor="#efefef">
        <td align="right" bgcolor="#efefef" class="paragraph" title="20039669">类别名：</td>
        <td bgcolor="#efefef"><input name="typename" type="text" id="typename" value="<?php echo $arrays[$i]['typename'] ?>" size="10">
       
                </td>
        <td bgcolor="#efefef">


        类别链接：
          <input name="typeurl" type="text" value="<?php echo $arrays[$i]['typeurl'] ?>" size="40"></td>
        <td bgcolor="#efefef"><label>
      	  <input type="submit" name="button" id="button" value="修改">
          <input type="submit" name="button" id="button2" value="删除">
          <input type="hidden" name="appno" value="<?php echo $i ?>">
        </label></td>
    </tr>
  </form>
	<?php 
  if(is_array($arrays[$i]['keywordlist']) && Count($arrays[$i]['keywordlist'])>0){
    for($j=0;$j<Count($arrays[$i]['keywordlist']);$j++){
  ?>    
    <form name="form1" method="post" action="ManageSingerPageEdit.php?action=updatelink&pageid=<?php echo $pageid ?>&typeid=<?php echo $i ?>" style=" margin:0px; padding:0px;">
    <tr bgcolor="#efefef">
        <td align="right" bgcolor="#FFFFFF" class="paragraph" title="20039669">链名：</td>
        <td bgcolor="#ffffff"><input name="title" type="text" id="txtrootroad" value="<?php echo $arrays[$i]['keywordlist'][$j]['title'] ?>" size="10">
                </td>
        <td bgcolor="#ffffff">
        搜索词：
          <input name="pic" type="text" value="<?php echo $arrays[$i]['keywordlist'][$j]['pic'] ?>" size="10">
          附加属性：
          
                    <select name="shoplevel" id="select">
        <option value="0" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==0){ ?> selected<?php }?> >无</option>
        <option value="20" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==20){ ?> selected<?php }?> >5金冠</option>
        <option value="19" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==19){ ?> selected<?php }?> >4金冠</option>
        <option value="18" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==18){ ?> selected<?php }?> >3金冠</option>
        <option value="17" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==17){ ?> selected<?php }?> >2金冠</option>
        <option value="16" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==16){ ?> selected<?php }?> >1金冠</option>
        <option value="15" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==15){ ?> selected<?php }?> >5冠</option>
        <option value="14" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==14){ ?> selected<?php }?> >4冠</option>
        <option value="13" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==13){ ?> selected<?php }?> >3冠</option>
        <option value="12" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==12){ ?> selected<?php }?> >2冠</option>
        <option value="11" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==11){ ?> selected<?php }?> >1冠</option>
        <option value="10" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==10){ ?> selected<?php }?> >5钻</option>
        <option value="9" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==9){ ?> selected<?php }?> >4钻</option>
        <option value="8" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==8){ ?> selected<?php }?> >3钻</option>
        <option value="7" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==7){ ?> selected<?php }?> >2钻</option>
        <option value="6" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==6){ ?> selected<?php }?> >1钻</option>
        <option value="5" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==5){ ?> selected<?php }?> >5星</option>
        <option value="4" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==4){ ?> selected<?php }?> >4星</option>
        <option value="3" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==3){ ?> selected<?php }?> >3星</option>
        <option value="2" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==2){ ?> selected<?php }?> >2星</option>
        <option value="1" <?php if($arrays[$i]['keywordlist'][$j]['shoplevel']==1){ ?> selected<?php }?> >1星</option>
      </select>
          
        链接网址：
<input name="link" type="text" value="<?php echo $arrays[$i]['keywordlist'][$j]['link'] ?>" size="40"></td>
        <td bgcolor="#ffffff"><label>
          <input type="submit" name="button" id="button" value="修改">
          <input type="submit" name="button" id="button2" value="删除">
          <input type="hidden" name="appno" value="<?php echo $j ?>">
        </label></td>
    </tr>
  </form>
	<?php 
    }
  }	
  ?>
<form name="form1" method="post" action="ManageSingerPageEdit.php?action=addlink&pageid=<?php echo $pageid ?>&typeid=<?php echo $i ?>" style="margin:0px; padding:0px;">
<tr bgcolor="#efefef">
        <td align="right" bgcolor="#FFFFFF" class="paragraph" title="20039669">新链名：</td>
        <td bgcolor="#ffffff"><input name="title" type="text" id="txtrootroad" value="" size="10"></td>
        <td bgcolor="#ffffff">
       搜索词：
         <input name="pic" type="text" value="" size="10">     

       附加属性：
                 <select name="shoplevel" id="select">
        <option value="0">无</option>
        <option value="20">5金冠</option>
        <option value="19">4金冠</option>
        <option value="18">3金冠</option>
        <option value="17">2金冠</option>
        <option value="16">1金冠</option>
        <option value="15">5冠</option>
        <option value="14">4冠</option>
        <option value="13">3冠</option>
        <option value="12">2冠</option>
        <option value="11">1冠</option>
        <option value="10">5钻</option>
        <option value="9">4钻</option>
        <option value="8">3钻</option>
        <option value="7">2钻</option>
        <option value="6">1钻</option>
        <option value="5">5星</option>
        <option value="4">4星</option>
        <option value="3">3星</option>
        <option value="2">2星</option>
        <option value="1">1星</option>
      </select>
       链接网址：
<input name="link" type="text" id="txtrootroad2" value="" size="40"></td>
        <td bgcolor="#ffffff"><label>
      <input type="submit" name="button" id="button" value="添加">
    </label></td>
</tr>
</form>

  
<?php 
	}
}	
?>
</table>
    <br></td>
     </tr>
  </table>

  
    <table width="96%" border="0" cellpadding="3" cellspacing="1" bgcolor="#cccccc">
    <tr bgcolor="#c8ddf4">
        <td align="left" bgcolor="#FFFFFF" class="paragraph" title="20039669">
<form name="form1" method="post" action="ManageSingerPageEdit.php?action=add&pageid=<?php echo $pageid ?>">
<table border="0" cellpadding="3" cellspacing="1" bgcolor="#cccccc"><tr bgcolor="#c8ddf4">
        <td align="right" bgcolor="#FFFFFF" class="paragraph" title="20039669">新类别名：</td>
        <td bgcolor="#ffffff"><input name="typename" type="text" id="txtrootroad" size="10"></td>
        <td bgcolor="#ffffff">类别链接：
          <input name="typeurl" type="text" id="typeurl" value="" size="40"></td>
        <td bgcolor="#ffffff"><label>
      <input type="submit" name="button" id="button" value="添加类别">
    </label></td>
</tr>
</table>
</form>
        </td>
     </tr>
  </table>



<table width="96%" height="91" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td height="1" bgcolor="#b2b2b2"></td>
  </tr>
  <tr>
    <td height="90" align=center>
<br> 
<p><span style="color:#FF0000">提示：链接类别ID是阿里妈妈固定的分类ID，如果不熟悉请不要修改。否则将无法正确获取类别商品数据!<br><br>
  如果设置了关键词会优先关键词链接,如果设置了链接网址,会优先链接网址!查找类别ID的方法请<a href="http://www.cnmysoft.com/taoapi/" target="_blank">点击这里查找类别</a></span></p>

      </td>
  </tr>
</table>
</center>
</body>
</html>
