//备课打包下载
public function download(){

$row_key=session("row_key");
$teacher_info=M('teacher_info');
$newlesson_info=M('newlesson_info');
$chapter_info=M('chapter_info');
$newlesson_scort=M('newlesson_scort');
$res_info=M("res_info");
$newlesson_type=M('newlesson_type');
$subject_info=M("subject_info");

$te=$teacher_info->where(array('user_key'=>$row_key))->find();
$path='dabao/'.$row_key;
       mkdir(iconv('UTF-8','GBK',$path),0777,true);
sleep(1);
$chapter_key = I('get.chapter_key');
$year_key = I('get.year_key');
$tao_key = I('get.tao_key');
$use = I('get.use');

if (is_dir($path)) {  
        $handle = opendir($path);  
        if ($handle) {  
            while (false !== ( $item = readdir($handle) )) {  
                if ($item != "." && $item != "..")  
                    is_dir("$path/$item") ? delDirAndFile("$path/$item", $delDir) : @unlink("$path/$item");  
            }  
            closedir($handle);  
            if ($delDir)  
                return rmdir($path);  
        }  
    } else {  
        if (file_exists($path)) {  
            return @unlink($path);  
        } else {  
            return FALSE;  
        }  
    }  
    clearstatcache();

$chap=$chapter_info->where(array('row_key'=>$chapter_key))->find();
$sname=$subject_info->where(array('row_key'=>$chap['subject_key']))->find();
// p($chap);die;
$res=$res_info->where(array('subject_key'=>$chap['subject_key'],'material_key'=>$chap['material_key'],'chapter_list'=>$chap['row_key'],'creator'=>$row_key))->select();
foreach($res as $key=>$value){
// $rul=copy($value['res_file'],$path);
//echo $value['res_file'];die; iconv("GB2312","UTF-8",$value['res_file']);

/* if(!file_exists( $_SERVER['DOCUMENT_ROOT'].iconv("UTF-8","GB2312",$value['res_file']))){  
         return false;  
     }  */
     //$filename = basename($sourcefile);  
$rf=explode(".",$value['res_file']);
$num=count($rf);
$hz=$rf[$num-1];
      copy($_SERVER['DOCUMENT_ROOT'].iconv("UTF-8","GB2312",$value['res_file']), $_SERVER['DOCUMENT_ROOT']."/".$path .'/'.iconv("UTF-8","GB2312",$chap['name'].'课件资源.'.$hz));  
}
$camp=session("camp");
$cou=$newlesson_scort->where(array('user_key'=>$row_key,'chapter_key'=>$chapter_key,'tao_key'=>$tao_key))->count();
 $nscort=$newlesson_scort->where(array('user_key'=>$row_key,'chapter_key'=>$chapter_key,'tao_key'=>$tao_key))->find();
 $scort=explode(',',$nscort['tscort']);
 $tid=$newlesson_type->where(array('camp'=>$camp,'gc'=>1))->getfield("id");
$less=$newlesson_info->where(array('teacher_key'=>$te['row_key'],'chapter_key'=>$chapter_key,'year_key'=>$year_key,'state'=>1,'use'=>$use,'tao_key'=>$tao_key))->order('tid,scort asc')->select();
$le=$newlesson_info->where(array('teacher_key'=>$te['row_key'],'chapter_key'=>$chapter_key,'year_key'=>$year_key,'state'=>1,'use'=>$use,'tid'=>$tid,'tao_key'=>$tao_key))->order('tid,scort asc')->find();
$cc=$newlesson_info->where(array('teacher_key'=>$te['row_key'],'chapter_key'=>$chapter_key,'year_key'=>$year_key,'state'=>1,'use'=>$use,'tid'=>$tid,'tao_key'=>$tao_key))->count();
if($cou!=0){
 foreach($scort as $kk=>$vv){
  foreach($less as $ke=>$va){
  if($vv==$va['tid']){
  $arr[$ke]=$va;
  }
 }
 }
  $less=$arr;
 }

$fansi=$newlesson_info->where(array('teacher_key'=>$te['row_key'],'chapter_key'=>$chapter_key,'tid'=>0,'use'=>1,'tao_key'=>$tao_key))->order('id desc')->select();
$erci=$newlesson_info->where(array('teacher_key'=>$te['row_key'],'chapter_key'=>$chapter_key,'state'=>2,'use'=>1,'tao_key'=>$tao_key))->limit(1)->order('id desc')->select();
foreach($less as $key=>$value){
foreach($fansi as $ke=>$val){
if($value['id']==$val['id']){
unset($value);
}}
if($value['id']==$le['id']){
$value['st']=1;
}
$less[$key]=$value;

}
$less=array_values(array_filter($less));

//p($less);die;
import("Org.Util.PHPWord");
   $this->getExcel1($chap['name'],$less,$row_key,$fansi,$erci,$cc,$chap['grade'],$sname['name']);

$PHPZip = new \myclass\PHPZip();

$zip_dir = 'dabao/'.$row_key;
$PHPZip->ZipDir($zip_dir, $chap['name'].".zip", 1); //文件夹打包 第三个参数1为直接下载,2为保存到服务器

}

//tp导出word(通过PHPword插件)
private function getExcel1($fileNames,$data,$row,$fansi,$erci,$cc,$gname,$sname){
$keyword=urlencode($fileNames);//将关键字编码
$keyword=preg_replace("/(%7E|%60|%21|%40|%23|%24|%25|%5E|%26|%27|%2A|%28|%29|%2B|%7C|%5C|%3D|\-|_|%5B|%5D|%7D|%7B|%3B|%22|%3A|%3F|%3E|%3C|%2C|\.|%2F|%A3%BF|%A1%B7|%A1%B6|%A1%A2|%A1%A3|%A3%AC|%7D|%A1%B0|%A3%BA|%A3%BB|%A1%AE|%A1%AF|%A1%B1|%A3%FC|%A3%BD|%A1%AA|%A3%A9|%A3%A8|%A1%AD|%A3%A4|%A1%A4|%A3%A1|%E3%80%82|%EF%BC%81|%EF%BC%8C|%EF%BC%9B|%EF%BC%9F|%EF%BC%9A|%E3%80%81|%E2%80%A6%E2%80%A6|%E2%80%9D|%E2%80%9C|%E2%80%98|%E2%80%99)+/",'',$keyword);
$fileName=urldecode($keyword);//将过滤后的关键字解码
//创建PHPExcel对象,注意,不能少了
   $PHPWord = new \PHPWord();
$subject_info=M('subject_info');
            $lesson_info=M('lesson_info');
$school_year=M('school_year');
$material_info=M('material_info');
$chapter_info=M('chapter_info');
            $newlesson_type=M('newlesson_type');
$row_key=session("row_key");
$teacher_info=M('teacher_info');
$te=$teacher_info->where(array('user_key'=>$row_key))->find();
//p($cgrade);die;
//对数据进行检验
   if(empty($data) || !is_array($data)){
$this->error("该教案不存在");
      // die("该教案不存在!!");
   }
   //检查文件名
   if(empty($fileName)){
       exit;
   }

$date = date("Y_m_d",time());
   $fileName .= ".docx";
       
$sectionStyle=array('orientation'=>null,'marginLeft'=>'1000','marginRight'=>'1000','marginTop'=>'1000','marginBottom'=>'1000');
           //设置默认字体
           $PHPWord->setDefaultFontName('楷体');
             $section = $PHPWord->createSection($sectionStyle);

/**************table start*******************/
//$tableStyle = array('cellMarginTop'=>80,      'cellMarginLeft'=>80,      'cellMarginRight'=>80,      'cellMarginBottom'=>80);
$styleTable = array('borderSize'=>6, 'borderColor'=>'000000','cellMargin'=>80);
$styleCell = array('valign'=>'center', 'align'=>'center','bold'=>true);
$fontStyle = array('size'=>'14');
$cfont = array('size'=>'12');//内容字体大小
$tStyle = array('size'=>'14' ,'bold'=>true);
$fStyle = array('size'=>'24' ,'bold'=>true);
$PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $fontStyle);
$section->addTextBreak();
$table = $section->addTable('myOwnTableStyle');
$table->addRow(800);
$table->addCell(1600, array('cellMerge' => 'restart', 'valign' => "center"))->addText(iconv('utf-8','GB2312',$fileNames), $fStyle, $styleCell);    
        $table->addCell(1600, array('cellMerge' => 'continue'));  
$table->addCell(1600, array('cellMerge' => 'continue'));  
$table->addCell(1600, array('cellMerge' => 'continue'));    
$table->addCell(1600, array('cellMerge' => 'continue'));  
$table->addCell(1600, array('cellMerge' => 'continue'));    
$table->addRow(500);
  $table->addCell(1300,$styleCell)->addText(iconv('utf-8','GB2312','科目'),$tStyle, $styleCell); 
  $table->addCell(1500,array('valign'=>'center', 'align'=>'center'))->addText(iconv('utf-8','GB2312',$sname), $fontStyle);
   $table->addCell(1500,$styleCell)->addText(iconv('utf-8','GB2312','年级'),$tStyle, $styleCell); 
  $table->addCell(1500,array('valign'=>'center', 'align'=>'center'))->addText(iconv('utf-8','GB2312',$gname), $fontStyle);
  $table->addCell(1500, $styleCell)->addText(iconv('utf-8','GB2312','课时'),$tStyle, $styleCell); 
  $table->addCell(1800,array('valign'=>'center', 'align'=>'center'))->addText(iconv('utf-8','GB2312',"{$cc}课时"),$fontStyle); 
$table->addRow(500);
  $table->addCell(1300,$styleCell)->addText(iconv('utf-8','GB2312','授课人'),$tStyle, $styleCell); 
  $table->addCell(1500,array('valign'=>'center', 'align'=>'center'))->addText(iconv('utf-8','GB2312',$te['name']), $fontStyle);
   $table->addCell(1500,$styleCell)->addText(iconv('utf-8','GB2312','授课班级'),$tStyle, $styleCell); 
  $table->addCell(1500,array('valign'=>'center', 'align'=>'center'))->addText(iconv('utf-8','GB2312',""), $fontStyle);
  $table->addCell(1500, $styleCell)->addText(iconv('utf-8','GB2312','授课时间'),$tStyle, $styleCell); 
  $table->addCell(1800,array('valign'=>'center', 'align'=>'center'))->addText(iconv('utf-8','GB2312',""),$tStyle);

// $table->addCell(30000, array('cellMerge' => 'restart'))->addText(iconv('utf-8','GB2312',$fileNames), $fStyle, $styleCell);
//$table->addCell(30000, array('cellMerge' => 'continue'));
//$table->addCell(30000, array('cellMerge' => 'continue'));
//p($data);die;
$camp=session("camp");
 $tid=$newlesson_type->where(array('camp'=>$camp,'gc'=>1))->getfield("id");
foreach($data as $key=>$value){

if($value['tid']!=$tid){
$table->addRow(500); 
$table->addCell(1600, array('cellMerge' => 'restart', 'valign' => "center"))->addText(iconv('utf-8','GB2312',str_replace(" "," ",strip_tags(trim($value['title'])))), $tStyle, $styleCell);
 $table->addCell(1600, array('cellMerge' => 'continue'));  
$table->addCell(1600, array('cellMerge' => 'continue'));  
$table->addCell(1600, array('cellMerge' => 'continue'));    
$table->addCell(1600, array('cellMerge' => 'continue'));  
$table->addCell(1600)->addText(iconv('utf-8','GB2312',"修改"), $tStyle, $styleCell);    
$table->addRow(600); 
  $content1=explode('</span>',trim(str_replace("——", "--",str_replace("&nbsp;","",$value['content']))));
  $content2=explode('</p>',trim(str_replace("——", "--",str_replace("&nbsp;","",$value['content']))));
  $content3=explode('<br/>',trim(str_replace("——", "--",str_replace("&nbsp;","",$value['content']))));
  $a=count($content1);
  $b=count($content2);
  $c=count($content3);
  $e=($c>=($a>=$b? $a:$b )? $c:($a>=$b? $a:$b ));
  if($e==$a){
 $content=$content1;
  }
   if($e==$b){
 $content=$content2;
  }
   if($e==$c){
 $content=$content3;
  }
$c2=$table->addCell(5000, array('cellMerge' => 'restart'));
//$content=trim($content);
$content=array_filter($content);
foreach($content as $k=>$v){

// p(strip_tags($v));
$c2->addText(iconv('utf-8','GB2312',str_replace("ɑ","a",preg_replace('/\s{2,}| /', '',strip_tags($v)))), $cfont);
}
//p($con);
//die;
/* if(is_numeric($value['title'])){
$cell=$table->addCell(30000, array('cellMerge' => 'restart'));
$cell->addText(iconv('utf-8','GB2312',"第".strip_tags($value['title'])."课时"), $tStyle,$styleCell);
}else{*/

//$cell=$table->addCell(30000, array('cellMerge' => 'restart'));
//$cell->addText(iconv('utf-8','GB2312',str_replace("&nbsp;"," ",strip_tags($value['title']))), $tStyle);
//$section->addTextBreak();

/*if($value['content'] == strip_tags($value['content'],'</p>')){
$content=explode('</span>',str_replace("——", "--",str_replace("&nbsp;","",$value['content'])));
}
else{
$content=explode('</p>',str_replace("——", "--",str_replace("&nbsp;","",$value['content'])));
}*/

// }
//elseif(){

$table->addCell(1000, array('cellMerge' => 'continue'));  
$table->addCell(2000, array('cellMerge' => 'continue'));
$table->addCell(1000, array('cellMerge' => 'continue'));  
$table->addCell(2000, array('cellMerge' => 'continue'));
$table->addCell(1600)->addText(iconv('utf-8','GB2312',""));

}else{
if($value['st']==1){
$table->addRow();
$cell=$table->addCell(5000, array('cellMerge' => 'restart'), $styleCell);
$cell->addText(iconv('utf-8','GB2312','教学过程'), $tStyle);
 
 $table->addCell(1000, array('cellMerge' => 'continue'));  
 $table->addCell(2000, array('cellMerge' => 'continue'));
 $table->addCell(1000, array('cellMerge' => 'continue'));  
 $table->addCell(1000, array('cellMerge' => 'continue'));
 $table->addCell(2500, array('rowMerge' => 'restart'))->addText(iconv('utf-8','GB2312','二次备课'), $tStyle, $styleCell);

}
 
if($value['tid']==$tid){

//标题
$table->addRow(600); 
$cell=$table->addCell(5000, array('cellMerge' => 'restart'));
$cell->addText(trim(iconv('utf-8','GB2312',$value['title'])), $tStyle, $styleCell);
$table->addCell(1000, array('cellMerge' => 'continue'));
$table->addCell(2000, array('cellMerge' => 'continue'));
$table->addCell(1000, array('cellMerge' => 'continue'));  
       $table->addCell(2000, array('cellMerge' => 'continue'));
//$table->addCell(1500)->addText(iconv('utf-8','GB2312','二次教案'), $tStyle, $styleCell); 
if($value['st']==1){
$cell3=$table->addCell(2000, array('rowMerge' => 'restart')); 
foreach($erci as $kk=>$vv){
$cell3->addText(iconv('utf-8','GB2312',strip_tags($vv['content'])), $cfont);
}

}else{
$table->addCell(2000, array('rowMerge' => 'continue'));
}

//教学内容
$table->addRow(600); 
$cell4=$table->addCell(5000, array('cellMerge' => 'restart'));
$content1=explode('</span>',str_replace("——", "--",str_replace("&nbsp;","",$value['content'])));
  $content2=explode('</p>',str_replace("——", "--",str_replace("&nbsp;","",$value['content'])));
  $content3=explode('<br/>',str_replace("——", "--",str_replace("&nbsp;","",$value['content'])));
  $a=count($content1);
  $b=count($content2);
  $c=count($content3);
  $e=($c>=($a>=$b? $a:$b )? $c:($a>=$b? $a:$b ));
  if($e==$a){
 $content=$content1;
  }
   if($e==$b){
 $content=$content2;
  }
   if($e==$c){
 $content=$content3;
  }
  $content=array_filter($content);
foreach($content as $v){
$cell4->addText(iconv('utf-8','GB2312',str_replace("ɑ","a",preg_replace('/\s{2,}| /', '',strip_tags($v)))), $cfont);
//$section->addTextBreak();
}

$table->addCell(1000, array('cellMerge' => 'continue'));
$table->addCell(2000, array('cellMerge' => 'continue'));
$table->addCell(1000, array('cellMerge' => 'continue'));  
       $table->addCell(1000, array('cellMerge' => 'continue'));

}

$table->addCell(2500, array('rowMerge' => 'continue'));

//$table->addCell(2000, array('rowMerge' => 'continue'));
//$table->addCell(2000, array('rowMerge' => 'restart'));
//$table->addCell(2000, array('rowMerge' => 'continue'));
//$table->addCell(2000, array('rowMerge' => 'continue'));

}

/* if($key>2){
//$table->addCell(9000, array('rowMerge' => 'restart'))->addText(iconv('utf-8','GB2312','二次教案'), $tStyle, $styleCell);
$cell=$table->addCell(2000, array('rowMerge' => 'restart'));
$cell->addText(iconv('utf-8','GB2312','二次教案'), $tStyle, $styleCell);
foreach($erci as $kk=>$vv){
$cell->addText(iconv('utf-8','GB2312',$vv['content']), $fontStyle);
$section->addTextBreak();
}
}else{
$table->addCell(2000, array('rowMerge' => 'continue'));
}
*/

}

//$table->addCell(2000, array('rowMerge' => 'continue'));

$table->addRow(600);
$table->addCell(1300, $styleCell)->addText(iconv('utf-8','GB2312',"教学反思"), $tStyle);
$cell5=$table->addCell(5000, array('cellMerge' => 'restart'));
foreach($fansi as $kk=>$vv){
$cell5->addText(iconv('utf-8','GB2312',$vv['content']), $cfont);
// $section->addTextBreak();
}

//$table->addCell(4000, array('cellMerge' => 'restart'))->addText("", $fontStyle);
   $table->addCell(1000, array('cellMerge' => 'continue'));
$table->addCell(2000, array('cellMerge' => 'continue'));
$table->addCell(1000, array('cellMerge' => 'continue'));  
   $table->addCell(2000, array('cellMerge' => 'continue'));

/**************table start*******************/

$fileName = iconv("utf-8", "gb2312", $fileName);
   
$hstyle = array('align'=>'right','');
$footstyle = array('align'=>'center');
$hfontStyle = array('size'=>'9');
//添加页眉
$header = $section->createHeader();
$footer = $section->createFooter();
$table = $header->addTable();
$time=date('Y/m/d');
$header->addText(iconv('utf-8','GB2312',$sname.$gname.$fileNames."教学设计"),$hfontStyle,$hstyle);
$footer->addText(iconv('utf-8','GB2312','网络备课自动生成教案-'.$time),$hfontStyle,$footstyle);

ob_end_clean();
   header("Content-type: application/vnd.ms-word"); 
header("Content-Disposition:attachment;filename=\"$fileName\"");
//header("Content-Type: application/vnd.ms-excel; charset=UTF-8"); 
header('Cache-Control: max-age=0');

$objWriter = \PHPWord_IOFactory::createWriter($PHPWord,'Word2007');
   $objWriter->save('dabao/'.$row_key."/".$fileName); //文件通过浏览器下载

}

thinkPHP打包下载相关推荐

  1. php文件管理 打包,Thinkphp6如何利用ZipArchive打包下载文件

    下面给大家介绍Thinkphp6利用ZipArchive打包下载文件的方法,希望对需要的朋友有所帮助!基础环境 系统环境:Windows10 x64 PHP集成环境:phpstudy PHP依赖管理工 ...

  2. 1357篇ECCV 2020论文打包下载!奖项公布:李飞飞高徒获最佳论文奖

    ↑ 点击蓝字 关注极市平台 部分内容来源丨机器之心 编辑|极市平台 极市导读 昨日,ECCV 2020五项大奖出炉,分别是最佳论文奖.最佳论文提名奖.Koenderink奖.Mark Everingh ...

  3. 多媒体领域顶会--ACM MM 2020 会议论文打包下载

    点击上方,选择星标或置顶,不定期资源大放送! 阅读大概需要15分钟 Follow小博主,每天更新前沿干货 ACM International Conference on Multimedia (ACM ...

  4. CVPR2020检测类论文最全汇总:136篇论文方向细分(附代码和论文打包下载)

    为了方便大家进一步的学习,我们对这CVPR中的1467篇论文进行了整理,本次分享的是所有检测类论文,并将它们细分为3D目标检测.人脸检测.动作检测.视频目标检测.文本检测.行人检测等方向,同时附上了相 ...

  5. 刘道成mysql视频教程_燕十八刘道成Mysql 系列视频教程 Mysql视频教程打包下载

    课程名称 燕十八刘道成Mysql 系列视频教程 Mysql视频教程打包下载 课程介绍 本教程完全从初学者的角度出发,循序渐进,逐步深入,确保每一位初学者能够理解和掌握,进而达到精通的程度,本套教程非常 ...

  6. python学习手册视频教程-Python学习精品教程,视频书籍打包下载

    这是Python书籍打包下载的地址,在下载之前,我首先要感谢分享资源的一位朋友(QQ的网名叫:破斧盛粥,非常感谢)链接:https://pan.baidu.com/s/1jMLa3mDcMfX9KaV ...

  7. 开源 免费使用 打包下载自行部署 :升讯威 周报系统

    最新版地址: 最新版本请访问:http://e2.shengxunwei.com/ 使用说明书:http://blog.shengxunwei.com/Home/Post/0a5950ef-22bd- ...

  8. 最强六大开源轻量级人脸检测项目分析 | 附打包下载

    随着深度学习的兴起,工业界和学术界越来越多的使用基于深度学习的方法,而不是传统的基于模板匹配,纹理提取或者像素积分图等方法.因为人脸检测本身并不属于特别复杂的任务,因此轻量级的深度学习模型即可满足该任 ...

  9. 一文看尽 CVPR2022 最新 22 篇论文(附打包下载)

    CVPR 2022 已经放榜,本次一共有2067篇论文被接收,接收论文数量相比去年增长了24%.由于每年的 CVPR 全部论文以及相关细节都需要等到六月会议召开才会正式公布,在这之前,为了让大家更快地 ...

最新文章

  1. 接力黄琨儿同志的《给玩命工作却对现状不满的IT人》
  2. Dot Net设计模式—外观模式
  3. PHP类继承、接口继承关系概述
  4. QT的QUrl类的使用
  5. shownews.php,newsshow.php
  6. 消息中间件kafka与activeMQ、rabbitMQ、zeroMQ、rocketMQ的比较
  7. iOS开发中对NSArray或者NSMutableArray中的内容排序
  8. Freeswitch与外域IP对接之incoming call
  9. Atitit 如何利用先有索引项进行查询性能优化
  10. RS232和RS485的协议原理及应用
  11. python数据分析有哪些模型-python数据挖掘的基本流程有哪些?
  12. 搜索进阶-迭代加深搜索
  13. 5G核心网-Identifiers身份标识
  14. 深度学习经历过程(caffe学习过程)
  15. C#用于登录数据库的方法
  16. srs之ingest
  17. 荣耀路由2 虚拟服务器,华为荣耀路由器2怎么设置? | 192路由网
  18. JAVA学习心得--自勉(转)
  19. 不靠谱的Access 轻松破解密码
  20. Unity3D 集成 高德地图SDK 地图

热门文章

  1. 2021年山东省安全员C证考试题及山东省安全员C证考试资料
  2. ai作文批改_我就要这样一款AI英语作文批改应用:免费,覆盖雅思考研四六级,打分评语纠错都得有 | 测评...
  3. 程序员的数学课14 程序的循环:如何利用数学归纳法进行程序开发?
  4. 《遥远的救世主》--编剧豆豆
  5. 2022-2028全球与中国酒店物业管理软件市场现状及未来发展趋势
  6. 移动电源最好的品牌推荐,移动电源牌子排行榜
  7. 由于找不到mfc140u.dll,无法继续执行代码?
  8. 数据降维之主成分分析法PCA
  9. 让Sublime Text在系统浅色模式下依然保持深色模式
  10. delphi真的穷途末路了! 不变程序员的苦难和热爱的精神。