
  <?php 
  //------------
if($pid== "") {
  echo 'must have pid';
  exit;
}
else {

  if(!ifhaspidname2(TABLE_NODE,$pid)){
       echo '出错，标识不存在!'.TABLE_NODE;
       exit;
  }
  //need judge by lang

 }

//---------


 $right_nodelangrel = '';
 
 if(LANG==$mainlang)  $right_nodelangrel = 'y';
 
  

if($right_nodelangrel == 'y'){  //only mainlang ,can operate rel 


     
   $sql = "SELECT * from ".TABLE_NODELANGREL." where nodeid='$pid' and lang='$mainlang' and pbh='".USERBH."' order by  id";
   if(getnum($sql)==0) {
      //insert
     $nrlang_pidname='nrlang'.$bshou;
        $sqlinsert = "insert into ".TABLE_NODELANGREL." (pbh,lang,pidname,nodeid) values ('$user2510','".LANG."','$nrlang_pidname','$pid')";
        // echo $ss;exit;
        iquery($sqlinsert);
      }
      else{
           if(getnum($sql)==1) {
              $row = getrow($sql);
              $nrlang_pidname= $row['pidname'];
           }
           else {
             echo '<p>发现有多个记录，请删除多余的。</p>';
                $rowall = getall($sql); 
                foreach ($rowall as $k => $v) {
                     $nrpidname222 = $v['pidname'];

                     $jumpv22 = $jumpv.'&file=del_mainlang&pidname2='.$nrpidname222;
                   $del_text= " <a  class='but2' href=javascript:delid('del---','$tid','$jumpv22','$jsname') ><span><i class='fa fa-trash-o'></i> 删除</span></a>";

                   echo '<p>'.$v['pidname'].$del_text.'</p>';

                          $sql333 = "SELECT * from ".TABLE_NODELANGREL." where pidname='$nrpidname222'   and pbh='".USERBH."' order by  id";
                                 if(getnum($sql333)>0) {
                                    $res33 = getall($sql333);
                                    foreach ($res33 as $v3) {
                                        echo '<p style="padding:2px 0 0 15px">'.$v3['pidname'].' &nbsp;&nbsp; 语言：'.$v3['lang'].'</p>';
                                    }

                                 }
                             echo '<hr />'; 



                }
           }
        

      }


 

//------------
}
else{
  //不是主语言，则是被关联
   $sql = "SELECT * from ".TABLE_NODELANGREL." where nodeid='$pid' and lang='".LANG."' and pbh='".USERBH."' order by  id";
   if(getnum($sql)>0) {
       if(getnum($sql)==1) {
         $row = getrow($sql);
         $nrlang_pidname= $row['pidname'];
       }else{
          echo '<p>发现有多个记录，请删除其他。</p>';
                $rowall = getall($sql); 
                foreach ($rowall as $k => $v) {

                  $nrpidname222 = $v['pidname'];

                     $jumpv22 = $jumpv.'&file=del_otherlang&pidname2='.$nrpidname222;
                   $del_text= " <a  class='but2' href=javascript:delid('del---','$tid','$jumpv22','$jsname') ><span><i class='fa fa-trash-o'></i> 删除</span></a>";


                   echo '<p>'.$v['pidname'].$del_text.'</p>';


                   $sql333 = "SELECT * from ".TABLE_NODELANGREL." where pidname='$nrpidname222'   and pbh='".USERBH."' order by  id";
                                 if(getnum($sql333)>0) {
                                    $res33 = getall($sql333);
                                    foreach ($res33 as $v3) {
                                        echo '<p style="padding:2px 0 0 15px;color:#999">'.$v3['pidname'].' &nbsp;&nbsp; 语言：'.$v3['lang'].'</p>';
                                    }

                                 }
                             echo '<hr />'; 








                }
             
 
                echo '<hr />';
       }

   }
   else{
       echo '本产品还没有被关联。 请在主语言里进行关联操作';
       exit;
   }

     

}


 //--------------

   $sql = "SELECT * from ".TABLE_LANG." where pbh='".USERBH."' order by pos desc,id $limit";
$rowlist = getall($sql);
if($rowlist=='no') echo '暂无内容';
else{


?>
<section class="content-header">
        <h1>语言关联</h1>
</section>
 
<?php
 if($nrlang_pidname<>'') echo '<p style="padding:10px 0">关联id：  '.$nrlang_pidname.'</p>';
?>

 
  <table class="formtab formtabhovertr">
  <tr style="font-weight:bold;background:#eeefff">
   
   <td  width="20%"  align="center">名称</td>
   <td  width="100" align="center">语言标识</td>
   <td   width="100" align="center">主语言</td>
   <td   width="130" align="center">产品分类</td>
   
    <td  align="center"   >关联产品</td> 
 <td  align="center"   >关联

 <br />只有当前语言是 主语言 时，才会显示关联链接
 </td> 
  </tr>
  <?php
 

      foreach($rowlist as $v){

$tid=$v['id'];
$curlang=$v['lang'];
$langpath=$v['langpath'];
$domain=$v['domain'];
 
$sta_visi_v=$v['sta_visible'];
$procatpid=$v['procatpid'];
 
$sitename=$v['sitename'];

?>
<tr>
   
   <td   align="center"><?php echo $sitename?>
    <?php 
    if($curlang==LANG){
      echo ' <span style="color:red">(当前语言)</span>';
      
    } 



  ?>
    
       </td>
   <td   align="center">
   <?php echo $curlang?>
    
  </td>

   <td   align="center">
    <?php 
    if($curlang==$mainlang) echo '主语言';
  ?>
    
  </td>

   <td   align="center">
     <?php 
         
            if($procatpid<>'') {
              echo $procatpid.'<br />';
              echo get_fieldnolang(TABLE_CATE,'name',$procatpid,'pidname');
            }
        ?>
  </td>
   
 
   
    <td  align="center" >
     <?php 
     $sql2 = "SELECT * from ".TABLE_NODELANGREL." where lang='$curlang' and pidname='$nrlang_pidname' and pbh='".USERBH."' order by  id";
     //echo $sql2;
   if(getnum($sql2)>0) {
       $row2 = getrow($sql2);
       $nodeid = $row2['nodeid'];
        if($nodeid<>''){

            echo  $nodeid;
           $tid = get_field_lang($curlang,TABLE_NODE,'id',$nodeid,'pidname');
            
           if($tid<>'noid') {
              $edit = '<a target="_blank" href="../mod_node/mod_node_edit.php?lang='.$curlang.'&act=editdesp&tid='.$tid.'&file=editdesp"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> 修改</a>';
              echo ' <br />'.$edit.'<span style="color:blue"> '.get_field_lang($curlang,TABLE_NODE,'title',$nodeid,'pidname').'</span>';

           }
           else echo  '<br />标识错误';
         }


   }
   else {
    echo '暂无';
   }
 
  ?>
 <td   align="center">
    <?php 
    if($right_nodelangrel == 'y'){ 
           if($curlang<>$mainlang){
            $linkrel = 'mod_nodelangrel.php?catpid='.$procatpid.'&lang='.$curlang.'&file=glian&pid='.$pid.'&pidname='.$nrlang_pidname;
            echo '<a href="'.$linkrel.'">关联</a>';

            //catpid use for add new pro id,  pid use for back list,

           }  
           else echo '主语言';
   }

  ?>
    
  </td>
 

<?php

}

 

}

?>