<?php
session_start();
//if(!isset($_SESSION['userid'])){
// header("Location:index.php");
// exit();
//}
$userid = $_SESSION['userid'];
$Product_info_total = 0;
$Contract_ID = $_REQUEST['Contract_ID'];
$t = $_REQUEST["t"];
$save_filename = $_REQUEST['save_filename'];
$thbgcolor ="bgcolor='#C9D6A6'";
$tdbgcolor0="bgcolor='#DFE3E6'";
$tdbgcolor1="bgcolor='#EDF1F4'";
$tdbgcolor2="bgcolor='#66CCFF'";
$tdbgcolor3="bgcolor='#B0C4DE'";
$tdbgcolor4="bgcolor='#FFE4C4'";
$tdbgcolor5="bgcolor='#FF0000'";
define("MSSP_TABDEF", "border='1' cellpadding='1' cellspacing='1' width='100%'");
define("MSSP_TABDEF2", "border='1' cellpadding='1' cellspacing='1' width='50%'");
$uploadfile='';
$upload_file_name = '';
if($t == 1) //选择附件
{
$upload_file_name=$_FILES['input_execel_contract_button']['name'];
$uploadfile = "/var/www/html/htdocs/upload/" . $upload_file_name;
$tmp_filename = $_FILES['input_execel_contract_button']['tmp_name'];
$bOK = 0;
if (@move_uploaded_file($tmp_filename, $uploadfile))
{
$bOK = 1;
}
else
{
echo json_encode(array('success'=>false, 'message'=> $upload_file_name));
exit;
}
}
else
if($t == 2) //保存附件
{
$uploadfile = "/var/www/html/htdocs/upload/" . $save_filename;
}
else
{
echo json_encode(array('success'=>false, 'message'=> '参数错误'));
exit;
}
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('PRC');
if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser');
/** Include PHPExcel */
//require_once '/var/www/html/htdocs/phpexcel/Classes/PHPExcel.php';
require_once '/var/www/html/htdocs/phpexcel/Classes/PHPExcel/IOFactory.php';
require_once('/var/www/html/htdocs/database.php');
$objPHPExcel = PHPExcel_IOFactory::load($uploadfile);
if(!$objPHPExcel)
{
echo json_encode(array('success'=>false, 'message'=> '格式错误!'));
exit;
}
/**读取excel文件中的第一个工作表*/
$currentSheet = $objPHPExcel->getSheet(0);
/**取得最大的列号*/
$allColumn = $currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();
$thtml = display_contract_content_excel($currentSheet, $allRow, $MaxContractID, $t, $msspdb);
function display_contract_content_excel($currentSheet, $allRow, $MaxContractID, $t, $msspdb)
{
global $thbgcolor ;
global $tdbgcolor0;
global $tdbgcolor1;
global $tdbgcolor2;
$col = ord('B')-65;// B4
$Contract_Date = getCellDate($currentSheet, $col, 4);
$Employee_Name = $currentSheet->getCellByColumnAndRow($col, 5)->getValue();
$Department_Name = $currentSheet->getCellByColumnAndRow($col, 6)->getValue();
$col = ord('E')-65;// E4
$Contract_No = $currentSheet->getCellByColumnAndRow($col, 4)->getValue();
$Contract_Customer = $currentSheet->getCellByColumnAndRow($col, 5)->getValue();
$Contract_Verb_Date = getCellDate($currentSheet, $col, 6);
if($t == 2)
{
$sql = "update tbl_contract set ";
$sql.= " Date = '$Contract_Date', ";
$sql.= " No = '$Contract_No', ";
$sql.= " Customer = '$Contract_Customer', ";
$sql.= " Verb_Date = '$Contract_Verb_Date' ";
$sql.= " where ID=$MaxContractID";
mysql_query($sql,$msspdb);
$thtml = '<table '.MSSP_TABDEF2 . '>';
$html = sprintf("<tr> <td %s align='right'>日期:</td><td>%s</td>", $tdbgcolor0, $Contract_Date); //第一个%s是颜色,第二个%s是值
$thtml .= $html;
$html = sprintf(" <td %s align='right'>合同编号:</td><td>%s</td>", $tdbgcolor0, $Contract_No);
$thtml .= $html;
$thtml .= "</tr> ";
$html = sprintf("<tr> <td %s align='right'>销售负责人:</td><td>%s</td>", $tdbgcolor0, $Employee_Name);
$thtml .= $html;
$html = sprintf(" <td %s align='right'>客户名称:</td><td>%s</td>", $tdbgcolor0, $Contract_Customer);
$thtml .= $html;
$thtml .= "</tr> ";
$html = sprintf("<tr> <td %s align='right'>部门:</td><td>%s</td>", $tdbgcolor0, $Department_Name);
$thtml .= $html;
$html = sprintf(" <td %s align='right'>合同签订日期:</td><td>%s</td>", $thbgcolor, $Contract_Verb_Date);
$thtml .= $html;
$thtml .= "</tr> ";
$thtml .= "</table>";
$thtml .= '<table '.MSSP_TABDEF . '>';
$html = sprintf("<tr > <td %s align=\"center\" colspan=\"7\">合同产品信息表(销售人员填写)</td>", $tdbgcolor0);
$thtml .= $html;
$html = sprintf(" <td %s align=\"center\" colspan=\"7\" >考核成本信息表(产品经理填写)</td>", $tdbgcolor2);
$thtml .= $html;
$thtml .= "</tr>";
$thtml .= display_contract_product_and_assessment_info_excel($currentSheet, $allRow, $MaxContractID, $t, $msspdb);
$thtml .= display_contract_other_info_excel($currentSheet, $allRow, $MaxContractID, $t, $msspdb);
$thtml .= "</table>";
return $thtml;
}
session_start();
//if(!isset($_SESSION['userid'])){
// header("Location:index.php");
// exit();
//}
$userid = $_SESSION['userid'];
$Product_info_total = 0;
$Contract_ID = $_REQUEST['Contract_ID'];
$t = $_REQUEST["t"];
$save_filename = $_REQUEST['save_filename'];
$thbgcolor ="bgcolor='#C9D6A6'";
$tdbgcolor0="bgcolor='#DFE3E6'";
$tdbgcolor1="bgcolor='#EDF1F4'";
$tdbgcolor2="bgcolor='#66CCFF'";
$tdbgcolor3="bgcolor='#B0C4DE'";
$tdbgcolor4="bgcolor='#FFE4C4'";
$tdbgcolor5="bgcolor='#FF0000'";
define("MSSP_TABDEF", "border='1' cellpadding='1' cellspacing='1' width='100%'");
define("MSSP_TABDEF2", "border='1' cellpadding='1' cellspacing='1' width='50%'");
$uploadfile='';
$upload_file_name = '';
if($t == 1) //选择附件
{
$upload_file_name=$_FILES['input_execel_contract_button']['name'];
$uploadfile = "/var/www/html/htdocs/upload/" . $upload_file_name;
$tmp_filename = $_FILES['input_execel_contract_button']['tmp_name'];
$bOK = 0;
if (@move_uploaded_file($tmp_filename, $uploadfile))
{
$bOK = 1;
}
else
{
echo json_encode(array('success'=>false, 'message'=> $upload_file_name));
exit;
}
}
else
if($t == 2) //保存附件
{
$uploadfile = "/var/www/html/htdocs/upload/" . $save_filename;
}
else
{
echo json_encode(array('success'=>false, 'message'=> '参数错误'));
exit;
}
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('PRC');
if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser');
/** Include PHPExcel */
//require_once '/var/www/html/htdocs/phpexcel/Classes/PHPExcel.php';
require_once '/var/www/html/htdocs/phpexcel/Classes/PHPExcel/IOFactory.php';
require_once('/var/www/html/htdocs/database.php');
$objPHPExcel = PHPExcel_IOFactory::load($uploadfile);
if(!$objPHPExcel)
{
echo json_encode(array('success'=>false, 'message'=> '格式错误!'));
exit;
}
/**读取excel文件中的第一个工作表*/
$currentSheet = $objPHPExcel->getSheet(0);
/**取得最大的列号*/
$allColumn = $currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();
$thtml = display_contract_content_excel($currentSheet, $allRow, $MaxContractID, $t, $msspdb);
function display_contract_content_excel($currentSheet, $allRow, $MaxContractID, $t, $msspdb)
{
global $thbgcolor ;
global $tdbgcolor0;
global $tdbgcolor1;
global $tdbgcolor2;
$col = ord('B')-65;// B4
$Contract_Date = getCellDate($currentSheet, $col, 4);
$Employee_Name = $currentSheet->getCellByColumnAndRow($col, 5)->getValue();
$Department_Name = $currentSheet->getCellByColumnAndRow($col, 6)->getValue();
$col = ord('E')-65;// E4
$Contract_No = $currentSheet->getCellByColumnAndRow($col, 4)->getValue();
$Contract_Customer = $currentSheet->getCellByColumnAndRow($col, 5)->getValue();
$Contract_Verb_Date = getCellDate($currentSheet, $col, 6);
if($t == 2)
{
$sql = "update tbl_contract set ";
$sql.= " Date = '$Contract_Date', ";
$sql.= " No = '$Contract_No', ";
$sql.= " Customer = '$Contract_Customer', ";
$sql.= " Verb_Date = '$Contract_Verb_Date' ";
$sql.= " where ID=$MaxContractID";
mysql_query($sql,$msspdb);
$thtml = '<table '.MSSP_TABDEF2 . '>';
$html = sprintf("<tr> <td %s align='right'>日期:</td><td>%s</td>", $tdbgcolor0, $Contract_Date); //第一个%s是颜色,第二个%s是值
$thtml .= $html;
$html = sprintf(" <td %s align='right'>合同编号:</td><td>%s</td>", $tdbgcolor0, $Contract_No);
$thtml .= $html;
$thtml .= "</tr> ";
$html = sprintf("<tr> <td %s align='right'>销售负责人:</td><td>%s</td>", $tdbgcolor0, $Employee_Name);
$thtml .= $html;
$html = sprintf(" <td %s align='right'>客户名称:</td><td>%s</td>", $tdbgcolor0, $Contract_Customer);
$thtml .= $html;
$thtml .= "</tr> ";
$html = sprintf("<tr> <td %s align='right'>部门:</td><td>%s</td>", $tdbgcolor0, $Department_Name);
$thtml .= $html;
$html = sprintf(" <td %s align='right'>合同签订日期:</td><td>%s</td>", $thbgcolor, $Contract_Verb_Date);
$thtml .= $html;
$thtml .= "</tr> ";
$thtml .= "</table>";
$thtml .= '<table '.MSSP_TABDEF . '>';
$html = sprintf("<tr > <td %s align=\"center\" colspan=\"7\">合同产品信息表(销售人员填写)</td>", $tdbgcolor0);
$thtml .= $html;
$html = sprintf(" <td %s align=\"center\" colspan=\"7\" >考核成本信息表(产品经理填写)</td>", $tdbgcolor2);
$thtml .= $html;
$thtml .= "</tr>";
$thtml .= display_contract_product_and_assessment_info_excel($currentSheet, $allRow, $MaxContractID, $t, $msspdb);
$thtml .= display_contract_other_info_excel($currentSheet, $allRow, $MaxContractID, $t, $msspdb);
$thtml .= "</table>";
return $thtml;
}