Copy Code code as follows:
<?php
Class Reportformaction extends commonaction{
Public Function index () {
if ($_post) {
@param $data array needs to export the data
@param $field string to export the column name of a CSV file
@param $filename string needs to export the name of the CSV file
$where = ' 1 ';
$order = ' creative_id desc ';
if ($_post[' crea_wh '] = = 1) $order. = "";
if ($_post[' crea_wh '] = = 2) $order. = "Creative_time desc";
$star = Strtotime ($_post[' Control_star '));
$end = Strtotime ($_post[' control_end '));
if ($star && $end) $where. = "and (Create_time between $star and $end)";
if ($_post[' creative_type '] = = 1) $where. = "and Creative_type = 1";
if ($_post[' creative_type '] = = 2) $where. = "and Creative_type = 2";
if ($_post[' creative_type '] = = 3) $where. = "and Creative_type = 3";
if ($_post[' sort_name '] = = 1) $where. = "and Sort_name = ' Technical class '";
if ($_post[' sort_name '] = = 2) $where. = "and Sort_name = ' packing class '";
if ($_post[' sort_name '] = = 3) $where. = "and Sort_name = ' Product class '";
if ($_post[' sort_name '] = = 4) $where. = "and Sort_name = ' marketing class '";
if ($_post[' sort_name '] = = 5) $where. = "and Sort_name = ' other class '";
if ($_post[' Two_status ']==0) {$where. = "and two_status=0"; $fenlei 1 = "one word originality";}
if ($_post[' Two_status ']==1) {$where. = "and Two_status=1"; $fenlei 2 = "Standard originality";}
$csv = ';
$lists = M (' creative ')->where ($where)->order ($order)->select ();
if (Is_array ($lists) && count ($lists) >0) {
if (empty ($filename)) {
$filename = Date (' y-m-d ', Time ()). CSV ';
}
Header (' Content-type:application/vnd.ms-excel ');
Header (' content-disposition:attachment;filename= '. $filename);
Header (' Pragma:no-cache ');
Header (' expires:0 ');
if ($_post[' Two_status ']==0) {
$csv = ' category, creative ID, creative type, creative label, creative title, creative description, comments, favorites, votes, author, author '. ' \ n ";
}elseif ($_post[' two_status ']==1) {
$csv = ' classification, creative ID, creative type, creative label, creative title, creative description, comments, favorites, votes, author, author, partner, core Innovation Point description, marketing plan, there are similar commercial cases, related patent status, implementation mode discussion, publication time '. ' \ n ";
}else{
$csv = ' classification, creative ID, creative type, creative label, creative title, creative description, comments, favorites, votes, author, author, partner, core Innovation Point description, marketing plan, there are similar commercial cases, related patent status, implementation mode discussion, publication time '. ' \ n ";
}
foreach ($lists as $list => $v) {
if ($v [' creative_type '] = = 1) {
$type = ' problem ';
}elseif ($v [' creative_type '] = = 2) {
$type = ' solution ';
}elseif ($v [' creative_type '] = = 3) {
$type = ' New Idea ';
}
if ($v [' Two_status ']==0) $fenlei = "A word of originality";
if ($v [' Two_status ']==1) $fenlei = "Standard originality";
if ($_post[' Two_status ']==0) {//a Word
$csv. = $fenlei 1. ', '. $v [' creative_id ']. ",". $v [' Sort_name ']. ', ' $type. ', '. $v [' Creative_name ']. ', '. $v [' Creative_ Description ']. '. $v [' Comment_num ']. ', '. $v [' Collect_num ']. $v [' Vote_num ']. $v [' Submitter ']. $v [' Author ']. " \ n ";
}elseif ($_post[' two_status ']==1) {//Standard
$csv. = $fenlei 2. ', '. $v [' creative_id ']. ",". $v [' Sort_name ']. ', ' $type. ', '. $v [' Creative_name ']. ', '. $v [' Creative_ Description ']. '. $v [' Comment_num ']. ', '. $v [' Collect_num ']. $v [' Vote_num ']. $v [' Submitter ']. $v [' Author ']. '. $v [' collaborator ']. $v [' innovation_description ']. $v [' Marketing_plan ']. $v [' Business_ Case ']. ' $v [' patent_situation ']. ', '. $v [' discuss_ways ']. ', '. Strtotime ($v [' create_time ']). " \ n ";
}else{//All
$csv. = $fenlei. ', '. $v [' creative_id ']. ",". $v [' Sort_name ']. ', ' $type. ', '. $v [' Creative_name ']. ', '. $v [' Creative_ Description ']. '. $v [' Comment_num ']. ', '. $v [' Collect_num ']. $v [' Vote_num ']. $v [' Submitter ']. $v [' Author ']. '. $v [' collaborator ']. $v [' innovation_description ']. $v [' Marketing_plan ']. $v [' Business_ Case ']. ' $v [' patent_situation ']. ', '. $v [' discuss_ways ']. ', '. Strtotime ($v [' create_time ']). " \ n ";
}
}
Echo mb_convert_encoding ($csv, "CP936", "UTF-8");
}else{
$this->assign ("msg", $msg);
}
Exit
}
$this->display ();
}
Public Function Votecount () {
if ($_post) {
@param $data array needs to export the data
@param $field string to export the column name of a CSV file
@param $filename string needs to export the name of the CSV file
$where = ' 1 ';
if ($_post[' crea_order '] = = 1) $order = "C.vote_num desc";
$star = Strtotime ($_post[' Control_star '));
$end = Strtotime ($_post[' control_end '));
if ($star && $end) $where. = "and (C.vote_start_time between $star and $end) and c.vote_end_time between $star D $end) ";
$sql = "Select C.sort_name,c.creative_id,c.creative_type,c.creative_name,c.creative_description,c.vote_num, C.comment_num,c.collect_num,c.create_time, u.username from cofco_creative as C-left join Cofco_userinfo as u on c.uid = U. The UID where $where order by $order ";
$lists = M ()->query ($sql);
$csv = ';
if (Is_array ($lists) && count ($lists) >0) {
if (empty ($filename)) {
$filename = Date (' y-m-d ', Time ()). CSV ';
}
Header (' Content-type:application/vnd.ms-excel ');
Header (' content-disposition:attachment;filename= '. $filename);
Header (' Pragma:no-cache ');
Header (' expires:0 ');
$csv = ' Creative label, submitter, creative category, creative title, Creative brief, number of votes, comments, favorites, upload time '. \ n ";
foreach ($lists as $list => $v) {
if ($v [' creative_type '] = = 1) {
$type = ' problem ';
}elseif ($v [' creative_type '] = = 2) {
$type = ' solution ';
}elseif ($v [' creative_type '] = = 3) {
$type = ' New Idea ';
}
$time = Date ("y-m-d h:i:s", $v [' create_time ']);
$csv. = $v [' Sort_name ']. $v [' username ']. ', ' $type. ', '. $v [' Creative_name ']. ', '. $v [' creative_description ']. $v [' Vote_num ']. $v [' Comment_num ']. $v [' Collect_num ']. $time. " \ n ";
}
Echo mb_convert_encoding ($csv, "CP936", "UTF-8");
}else{
$this->assign ("msg", $msg);
}
Exit
}
$this->display ();
}
}
?>