<?php
/*
  欢迎使用DM企业建站系统，本系统由www.demososo.com开发。
 */
if (!defined('IN_DEMOSOSO')) {
    exit('this is wrong page,please back to homepage');
}


function gototrans($nodearr,$topidname,$tolang)
{
      

         $arrgo = [
            'name',
            'desp',
           // 'despprocan',
            'seo1',
            'seo2',
            'seo3',
         ];

        foreach($arrgo as $v){
            //if convery null,baidu will error
           // [error_code] => 54000
            // [error_msg] => PARAM_FROM_TO_OR_Q_EMPTY
             if($nodearr[$v]<>'')    $arr_trans[$v] =  dmbaidutrans($nodearr[$v], ADMMAINLANG, $tolang);
             else $arr_trans[$v] = '';
        }

         

         //pre($arr_trans);

         $name = zbdesp_onlyinsert($arr_trans['name']);
         $desp = zbdesp_onlyinsert($arr_trans['desp']);
        // $despprocan = zbdesp_onlyinsert($arr_trans['despprocan']);
         $seo1 = zbdesp_onlyinsert($arr_trans['seo1']);
         $seo2 = zbdesp_onlyinsert($arr_trans['seo2']);
         $seo3 = zbdesp_onlyinsert($arr_trans['seo3']);

         $andlangbh=" and lang = '$tolang' and  pbh='".USERBH."' ";

         $name = $name==''?'无标题':$name;

          $ss = "update ".TABLE_CATE." set name='$name',desp='<p>$desp</p>',seo1='$seo1',seo2='$seo2',seo3='$seo3'  where pidname='$topidname' $andlangbh limit 1";
            //  echo $ss; 
              iquery($ss);



}

if($act=='update'){

      $nodearr = get_fieldarr(TABLE_CATE,$pidname,'pidname');
        if($nodearr == 'no'){
            echo 'source: '.$pidname.' is not found';
            exit;
        }


    $topidname =  @htmlentitdm($_POST['topidname']);
    if($topidname =='') {
        echo 'topidname is null';
        exit;
    }
    else if($topidname =='allothers'){

            $andlangbh=" and  pbh='".USERBH."' ";
              $sql = "SELECT id,lang,pidname,name from  ".TABLE_CATE." where  langrelid='$pidname' $andlangbh order by id";
               //echo $sql;
               if(getnum($sql)>0){
                 $res = getall($sql);
                  foreach($res as $v){
                        $topidname = $v['pidname'];
                        $tolang = $v['lang'];
                        gototrans($nodearr,$topidname,$tolang);
                  }
             }else{
                echo '无关联内容';
                exit;
             }


    }else{
          $topidnamearr = explode("|",$topidname);
          $topidname = $topidnamearr[0];
          $tolang = $topidnamearr[1];
          gototrans($nodearr,$topidname,$tolang);
    } 
    //echo $topidname; 

    echo '<p>翻译完成。</p>';

    
       



}else{

        $name = get_field(TABLE_CATE,'name',$pidname,'pidname');
       // $jumpvinsert=$jumpv_.'&file=node';

        echo '<h3 style="margin-bottom:20px">来源：'.$name.'</h3>'; 



         
         $andlangbh=" and  pbh='".USERBH."' ";
              $sql = "SELECT id,lang,pidname,name from  ".TABLE_CATE." where  langrelid='$pidname' $andlangbh order by id";
               //echo $sql;
              $num = getnum($sql);
               if($num>0){
                 $res = getall($sql);
                // pre($res);
                ?>
                  
        <form   onsubmit="javascript:return checkhere(this)"  action="<?php echo $jumpv_file?>&act=update" method="post" enctype="multipart/form-data">

                        选择要翻译的内容：
                        <select name="topidname">
                          <option    value="">请选择</option>
                        
                     <?php
                          foreach($res as $v){ 
                         
                           //  if($v['lang']== ADMMAINLANG) continue;
                        ?>
                           <option   value="<?php echo $v['pidname']?>|<?php echo $v['lang']?>"><?php echo $v['lang']?> - <?php echo $v['name']?></option>
                           <?php 
                               }

                             if($num>1)   echo ' <option    value="allothers">翻译上面所有的语言内容</option>';

                         ?>
                      

                      </select>
                      <p>
                        <br />
                       <input  class="mysubmit mysubmitbig" type="submit" name="Submit" value="提交" />

                       <p class="loading translateing" >正在翻译中......</p>

                     </p>
                    </form>
                <?php 
               }
               else {
                        echo '暂无关联内容。';
                    }

        ?>
        <script>
            function  checkhere(thisForm){
                    if (thisForm.topidname.value==""){
                        alert("请选择翻译内容");
                        thisForm.topidname.focus();
                        return (false); 
                    
                     }else{
                        $('.translateing').show();

                     }

            }
             </script>
             


        <?php

      }




