'words_n','pron'=>'words_pron','adj'=>'words_adj','num'=>'words_num','v'=>'words_v','adv'=>'words_adv','art'=>'words_art', 'prep'=>'words_prep','conj'=>'words_conj','int'=>'words_int','vt'=>'words_vt','vi'=>'words_vi','other'=>'words_other',); if (empty($step)){ $info = array(); $wordsPreId = ''; $wordsNextId = ''; if (!empty($courseId)){ $info = M('Words')->where(array('words_id'=>$wordsId))->find(); $wordsPreInfo = M('Words')->where(array('course_id'=>$courseId,'words_id'=>array('LT',$wordsId)))->order('words_id desc')->field('words_id')->find(); if ($wordsPreInfo!=null){ $wordsPreId = $wordsPreInfo['words_id']; } $wordsNextInfo = M('Words')->where(array('course_id'=>$courseId,'words_id'=>array('GT',$wordsId)))->order('words_id asc')->field('words_id')->find(); if ($wordsNextInfo!=null){ $wordsNextId = $wordsNextInfo['words_id']; } if($info['words_img']){ $arr=explode(',',$info['words_img']); $info['words_img1']=$arr[0]; $info['words_img2']=$arr[1]; $info['words_img3']=$arr[2]; } $ttt=''; if($info['words_voice1']){ if($ttt){ $ttt.=",".$info['words_voice1']; }else{ $ttt=$info['words_voice1']; } } if($info['words_voice2']){ if($ttt){ $ttt.=",".$info['words_voice2']; }else{ $ttt=$info['words_voice2']; } } if($info['words_voice3']){ if($ttt){ $ttt.=",".$info['words_voice3']; }else{ $ttt=$info['words_voice3']; } } $info['words_voice']=$ttt; $ttt=''; if($info['words_read1']){ if($ttt){ $ttt.=",".$info['words_read1']; }else{ $ttt=$info['words_read1']; } } if($info['words_read2']){ if($ttt){ $ttt.=",".$info['words_read2']; }else{ $ttt=$info['words_read2']; } } if($info['words_read3']){ if($ttt){ $ttt.=",".$info['words_read3']; }else{ $ttt=$info['words_read3']; } } $info['words_read']=$ttt; } $this->assign('info',$info); $this->assign('courseId', $courseId); $this->assign('wordsKeys', $wordsKeys); $this->assign('wordsPreId', $wordsPreId); $this->assign('wordsNextId', $wordsNextId); $this->display(); }else if($step==2){ $data['course_id'] = $courseId; $data['words_name'] = trim(I('words_name','')); $wordsVoice = I('words_voice',''); $wordsRead = I('words_read',''); if (substr($wordsVoice,-1)==','){ $wordsVoice = substr($wordsVoice, 0, -1); } $wordsVoiceArr = explode(',', $wordsVoice); $wordsReadArr = explode(',', $wordsRead); for ($i=0;$ierror('单词不能为空'); } /* if (empty($data['words_voice1'])){ $this->error('读音不能为空'); } if (empty($data['words_read1'])){ $this->error('音标不能为空'); } */ if ($checkWords){ $this->error('中文释义不能为空'); } $data['jz_en1'] = I('jz_en1',''); $data['jz_cn1'] = I('jz_cn1',''); $data['jz_en2'] = I('jz_en2',''); $data['jz_cn2'] = I('jz_cn2',''); $data['jz_en3'] = I('jz_en3',''); $data['jz_cn3'] = I('jz_cn3',''); $data['words_similar'] = I('words_similar',''); $data['annotation_cn'] = I('annotation_cn',''); $data['similar_cn'] = I('similar_cn',''); $words_img1=I('words_img1',''); $words_img2=I('words_img2',''); $words_img3=I('words_img3',''); $ttt=''; if($words_img1){ if($ttt){ $ttt.=",".$words_img1; }else{ $ttt=$words_img1; } } if($words_img2){ if($ttt){ $ttt.=",".$words_img2; }else{ $ttt=$words_img2; } } if($words_img3){ if($ttt){ $ttt.=",".$words_img3; }else{ $ttt=$words_img3; } } $data['words_img']=$ttt; /* if (!empty($data['jz_en1']) && strpos(strtolower($data['jz_en1']), strtolower($data['words_name']))===FALSE){ $this->error('您添加的例句1不包含对应单词,请仔细核对后提交'); } if (!empty($data['jz_en2']) && strpos(strtolower($data['jz_en2']), strtolower($data['words_name']))===FALSE){ $this->error('您添加的例句2不包含对应单词,请仔细核对后提交'); } if (!empty($data['jz_en3']) && strpos(strtolower($data['jz_en3']), strtolower($data['words_name']))===FALSE){ $this->error('您添加的例句3不包含对应单词,请仔细核对后提交'); } */ if (!empty($data['jz_en1']) && empty($data['jz_cn1'])){ $this->error('您添加的例句1释义不能为空,请仔细核对后提交'); } if (!empty($data['jz_en2']) && empty($data['jz_cn2'])){ $this->error('您添加的例句1释义不能为空,请仔细核对后提交'); } if (!empty($data['jz_en3']) && empty($data['jz_cn3'])){ $this->error('您添加的例句1释义不能为空,请仔细核对后提交'); } if (!empty($data['words_similar']) && strlen($data['words_similar'])>50){ $this->error('近义词不能大于50个字节'); } if (!empty($data['similar_cn']) && strlen($data['similar_cn'])>500){ $this->error('英文释义不能大于500个字节'); } $data['operate_dt'] = time(); if ($wordsId){ $jumpType = 1; M('Words')->where(array('words_id'=>$wordsId))->save($data); }else{ $jumpType = 2; $wordsId = M('Words')->add($data); M('Course')->where(array('course_id'=>$courseId))->setInc('course_num'); } //$this->success('单词操作成功','/admin/course/detail?course_id='.$courseId); $jumpId = I('jumpId'); if ($jumpId==1){ if ($jumpType==1){ $this->success('单词操作成功','/admin/words/edit?course_id='.$courseId.'&words_id='.$wordsId); }else{ $this->success('单词操作成功','/admin/words/edit?course_id='.$courseId); } }else if($jumpId==2){ $wordsInfo = M('Words')->where(array('course_id'=>$courseId,'words_id'=>array('LT',$wordsId)))->order('words_id desc')->field('words_id')->find(); if ($wordsInfo==NULL){ $this->success('单词操作成功,暂无上一个单词','/admin/words/edit?course_id='.$courseId); } $this->success('单词操作成功,跳转至上一个单词','/admin/words/edit?course_id='.$courseId.'&words_id='.$wordsInfo['words_id']); }else if($jumpId==3){ $wordsInfo = M('Words')->where(array('course_id'=>$courseId,'words_id'=>array('GT',$wordsId)))->order('words_id asc')->field('words_id')->find(); if ($wordsInfo==NULL){ $this->success('单词操作成功,暂无下一个单词','/admin/words/edit?course_id='.$courseId); } $this->success('单词操作成功,跳转至下一个单词','/admin/words/edit?course_id='.$courseId.'&words_id='.$wordsInfo['words_id']); } } } //删除单词 public function del(){ $wordsId = I('words_id',''); $courseId = I('course_id',''); //M('Words')->where(array('words_id'=>$wordsId))->save(array('is_delete'=>2)); M('Words')->where(array('words_id'=>$wordsId))->delete(); M('Course')->where(array('course_id'=>$courseId))->setDec('course_num'); $this->success('单词删除成功','/admin/course/detail/index?course_id='.$courseId); } //获取单词信息接口 public function dict(){ $wordsFields = array('n','pron','adj','num','v','adv','art','prep','conj','int','vt','vi','other',); $wordsName = I('words_name',''); if (empty($wordsName)){ $data = array('code'=>1,'msg'=>'单词不能为空'); echo json_encode($data); } $httpCurl = new \Org\Net\HttpCurl(); $url = C('TRANS').'&w='.$wordsName; $res = $httpCurl->get($url,'xml'); $res = json_decode(json_encode(simplexml_load_string($res, 'SimpleXMLElement', LIBXML_NOCDATA)), true); /* $url = C('TRANS').'&type=json&w='.$wordsName; $res = $httpCurl->get($url); */ if (!isset($res['key'])){ $data = array('code'=>1,'msg'=>'单词翻译出错'); echo json_encode($data); } if (isset($res['ps'])){ if (!is_array($res['ps'])){ $data['data']['ps'][] = $res['ps']; }else{ $data['data']['ps'] = $res['ps']; } }else{ $data['data']['ps'] = array(); } if (isset($res['pron'])){ if (!is_array($res['pron'])){ $data['data']['pron'][] = $res['pron']; }else{ $data['data']['pron'] = $res['pron']; } /* $data['data']['pron'] = array( 'http://res.iciba.com/resource/amp3/0/0/c4/7d/c47d187067c6cf953245f128b5fde62a.mp3', 'http://res.iciba.com/resource/amp3/0/0/34/d1/34d1f91fb2e514b8576fab1a75a89a6b.mp3' ); */ }else{ $data['data']['pron'] = array(); } if (isset($res['pos']) && !empty($res['pos'])){ if (is_array($res['pos'])){ foreach ($res['pos'] as $k=>$v){ $key = str_replace('.', '', $v); if (!in_array($key, $wordsFields)){ $pos[] = array('other', trim($res['acceptation'][$k])); }else{ $pos[] = array($key, trim($res['acceptation'][$k])); } } }else{ $key = str_replace('.', '', $res['pos']); //$pos[] = array(str_replace('.', '', $res['pos']),trim($res['acceptation'])); if (!in_array($key, $wordsFields)){ $pos[] = array('other', trim($res['acceptation'])); }else{ $pos[] = array($key, trim($res['acceptation'])); } /* if (isset($wordsKeys[str_replace('.', '', $res['pos'])])){ $pos[] = array(str_replace('.', '', $res['pos']),trim($res['acceptation'])); }else{ $pos[] = array('words_other',trim($res['acceptation'])); } */ } $data['data']['pos'] = $pos; }else{ $pos[] = array('other', trim($res['acceptation'])); $data['data']['pos'] = $pos; } if (isset($res['sent'])){ if (empty($res['sent'][0])){ $sent[] = array(trim($res['sent']['orig']),trim($res['sent']['trans'])); }else{ foreach ($res['sent'] as $k=>$v){ if ($k>2){ continue; } $sent[] = array(trim($v['orig']),trim($v['trans'])); } } $data['data']['sent'] = $sent; } $data['code'] = 0; $this->ajaxReturn($data);exit; } }