2013-07-17 09:53:44 +00:00
|
|
|
<?php
|
2013-08-28 01:49:27 +00:00
|
|
|
namespace Order;
|
2013-07-17 09:53:44 +00:00
|
|
|
|
2013-08-26 02:33:44 +00:00
|
|
|
use Helpers\View as view;
|
2013-07-17 09:53:44 +00:00
|
|
|
|
|
|
|
class Order
|
|
|
|
{
|
|
|
|
private $db;
|
|
|
|
private $config;
|
|
|
|
protected $events = NULL;
|
|
|
|
|
2013-07-19 10:19:59 +00:00
|
|
|
public $projectType = array(
|
|
|
|
"国家973计划项目课题" => "国家973计划项目课题",
|
|
|
|
"国家863计划课题"=>"国家863计划课题",
|
|
|
|
"国家级科技支撑课题" => "国家级科技支撑课题",
|
|
|
|
"国家级科技重大专项" => "国家级科技重大专项",
|
|
|
|
"国家级国家重大工程" => "国家级国家重大工程",
|
|
|
|
"国家级国家自然科学基金" => "国家级国家自然科学基金",
|
|
|
|
"国际合作项目"=>"国际合作项目",
|
|
|
|
"省部级项目" => "省部级项目",
|
|
|
|
"其他项目工程" => "其他项目工程",
|
2013-07-24 10:11:14 +00:00
|
|
|
);//申请中的项目类型
|
|
|
|
|
|
|
|
public $pdfData;
|
2013-07-19 10:19:59 +00:00
|
|
|
|
2013-07-17 09:53:44 +00:00
|
|
|
function __construct($db = NULL)
|
|
|
|
{
|
|
|
|
if(empty($db))
|
|
|
|
{
|
|
|
|
$this->db = \Zend_Registry::get('db');
|
|
|
|
}else{
|
|
|
|
$this->db = $db;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->config = \Zend_Registry::get('config');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function events(\Zend_EventManager_EventCollection $events = NULL)
|
|
|
|
{
|
|
|
|
if ($events !== NULL) {
|
|
|
|
$this->events = $events;
|
|
|
|
} elseif ($this->events === NULL) {
|
|
|
|
$this->events = new \Zend_EventManager_EventManager(__CLASS__);
|
|
|
|
}
|
|
|
|
return $this->events;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************
|
|
|
|
|
|
|
|
status:
|
|
|
|
|
|
|
|
1 开始进入离线申请申请程序中
|
|
|
|
2 填写并提交离线申请表
|
|
|
|
3 邮寄离线申请表
|
|
|
|
4 收到离线申请表
|
|
|
|
5 处理离线申请表
|
|
|
|
10:离线申请完成?
|
|
|
|
-1: 取消了在线下载进程
|
|
|
|
|
|
|
|
**************/
|
|
|
|
|
|
|
|
//添加到数据篮
|
2013-07-24 10:11:14 +00:00
|
|
|
public function addOrder($uuid,$selection = NULL,$uid = 0){
|
2013-07-17 09:53:44 +00:00
|
|
|
|
|
|
|
if(empty($uid))
|
|
|
|
{
|
2013-08-26 02:33:44 +00:00
|
|
|
$uid = view::User('id');
|
2013-07-17 09:53:44 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 10:19:59 +00:00
|
|
|
if(!is_numeric($uid))
|
|
|
|
{
|
2013-08-26 02:33:44 +00:00
|
|
|
$uid = view::User('id');
|
2013-07-19 10:19:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 09:53:44 +00:00
|
|
|
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
|
|
|
|
{
|
|
|
|
return "参数错误";
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = $this->events()->trigger('submit', $this, compact('uuid','uid'));
|
|
|
|
$data = $results->bottom();
|
|
|
|
|
|
|
|
if($data !== true)
|
|
|
|
{
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
if(empty($selection))
|
2013-07-17 09:53:44 +00:00
|
|
|
{
|
2013-07-24 10:11:14 +00:00
|
|
|
$results = $this->events()->trigger('checksource', $this, compact('uuid'));
|
|
|
|
$data = $results->bottom();
|
|
|
|
if(!empty($data))
|
|
|
|
{
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($this->pushToDataorder($uuid,$uid) === true)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return "操作中出现错误,请重试";
|
|
|
|
}
|
2013-07-17 09:53:44 +00:00
|
|
|
}else{
|
2013-08-26 02:33:44 +00:00
|
|
|
if($this->pushToDataorder($uuid,$uid,$selection) === true)
|
2013-07-24 10:11:14 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return "操作中出现错误,请重试";
|
|
|
|
}
|
2013-07-17 09:53:44 +00:00
|
|
|
}
|
2013-07-19 10:19:59 +00:00
|
|
|
}//addOrder
|
2013-07-17 09:53:44 +00:00
|
|
|
|
|
|
|
//放到数据篮中
|
2013-07-24 10:11:14 +00:00
|
|
|
public function pushToDataorder($uuid,$uid = 0,$selection = NULL)
|
2013-07-17 09:53:44 +00:00
|
|
|
{
|
|
|
|
if(empty($uid))
|
|
|
|
{
|
2013-08-26 02:33:44 +00:00
|
|
|
$uid = view::User('id');
|
2013-07-17 09:53:44 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
if(empty($selection))
|
|
|
|
{
|
|
|
|
$sql="insert into dataorder (uuid,ts_created,userid,status) values(?,now(),?,?)";
|
|
|
|
$rs = $this->db->query($sql,array($uuid,$uid,1));
|
|
|
|
}else{
|
|
|
|
$sql="insert into dataorder (uuid,ts_created,userid,status,selection) values(?,now(),?,?,?)";
|
|
|
|
$rs = $this->db->query($sql,array($uuid,$uid,1,$selection));
|
|
|
|
}
|
|
|
|
|
2013-07-17 09:53:44 +00:00
|
|
|
if($rs)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-19 10:19:59 +00:00
|
|
|
}//pushToDataorder
|
|
|
|
|
|
|
|
//提交
|
|
|
|
public function apply($id,$uid = 0)
|
|
|
|
{
|
|
|
|
if(!is_numeric($id) || !is_numeric($uid))
|
|
|
|
{
|
|
|
|
return "参数错误";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(empty($uid))
|
|
|
|
{
|
2013-08-26 02:33:44 +00:00
|
|
|
$uid = view::User('id');
|
2013-07-19 10:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if($id == -1)
|
|
|
|
{
|
|
|
|
$sql = $this->db->quoteInto("update dataorder set status=2 where status=1 and userid=?",$uid);
|
|
|
|
if($this->db->exec($sql))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return "处理中遇到问题,请重试";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($id > 0)
|
|
|
|
{
|
|
|
|
$sql = $this->db->quoteInto("update dataorder set status=2 where status=1 and userid=$uid and id=?",$id);
|
|
|
|
if($this->db->exec($sql))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return "处理中遇到问题,请重试";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "参数错误";
|
|
|
|
}//apply()
|
2013-07-17 09:53:44 +00:00
|
|
|
|
2013-07-19 10:19:59 +00:00
|
|
|
//删除
|
|
|
|
public function del($id,$uid = 0)
|
|
|
|
{
|
|
|
|
if(!is_numeric($id) || !is_numeric($uid))
|
|
|
|
{
|
|
|
|
return "参数错误";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(empty($uid))
|
|
|
|
{
|
2013-08-26 02:33:44 +00:00
|
|
|
$uid = view::User('id');
|
2013-07-19 10:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if($id > 0)
|
|
|
|
{
|
|
|
|
$sql = $this->db->quoteInto("delete from dataorder where userid=$uid and status in (1,2) and id=?",$id);
|
|
|
|
if($this->db->exec($sql))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return "处理中遇到错误,请重试";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "参数错误";
|
|
|
|
}
|
2013-07-17 09:53:44 +00:00
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
|
|
|
|
//设置PDF上显示的内容 getOrderItemForPdf() 的返回结果
|
|
|
|
public function setPdfData($data)
|
|
|
|
{
|
|
|
|
$this->pdfData = $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
//保存预览
|
|
|
|
public function SaveOrder($formData,$uid = 0)
|
|
|
|
{
|
|
|
|
if(empty($uid) || !is_numeric($uid))
|
|
|
|
{
|
2013-08-26 02:33:44 +00:00
|
|
|
$uid = view::User('id');
|
2013-07-24 10:11:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$results = $this->events()->trigger('order.formcheck', $this, compact('formData'));
|
|
|
|
$data = $results->bottom();
|
|
|
|
|
|
|
|
if($data !== true)
|
|
|
|
{
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = $this->events()->trigger('order.onUpdate', $this, compact('formData','uid'));
|
|
|
|
$data = $results->bottom();
|
|
|
|
|
|
|
|
if($data !== true)
|
|
|
|
{
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->pdfPrint($formData,$uid);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}//SaveOrder
|
|
|
|
|
2013-07-22 09:16:18 +00:00
|
|
|
//发送邮件
|
2013-07-24 10:11:14 +00:00
|
|
|
public function SendOrderEmail(){
|
2013-07-22 09:16:18 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-19 10:19:59 +00:00
|
|
|
//生成pdf
|
2013-07-24 10:11:14 +00:00
|
|
|
public function pdfPrint($formData,$userid = 0)
|
2013-07-19 10:19:59 +00:00
|
|
|
{
|
2013-07-24 10:11:14 +00:00
|
|
|
$sql="SELECT m.title||'('||m.filesize::text||'MB)' as title FROM dataorder d
|
|
|
|
RIGHT JOIN heihemetadata m ON d.uuid=m.uuid
|
|
|
|
WHERE d.status=2 AND d.userid=?";
|
|
|
|
|
|
|
|
$list = $this->db->fetchAll($sql,array($userid));
|
|
|
|
|
|
|
|
foreach($list as $i=>$row){
|
|
|
|
@$formData['heihelist'].=($i+1).". ".$row['title'].";";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql="SELECT m.title||'('||m.filesize::text||'MB)' as title FROM dataorder d
|
|
|
|
RIGHT JOIN normalmetadata m ON d.uuid=m.uuid WHERE d.uuid not in (select uuid from heihemetadata) AND d.status=2 AND d.userid=?";
|
|
|
|
$list = $this->db->fetchAll($sql,array($userid));
|
|
|
|
|
|
|
|
foreach($list as $i=>$row){
|
|
|
|
@$formData['westdclist'].=($i+1).". ".$row['title'].";";
|
|
|
|
}
|
|
|
|
|
|
|
|
$pdf = new \ApplicantPDF();
|
|
|
|
|
|
|
|
$pdf->template = $this->config->offline->template;
|
|
|
|
|
|
|
|
$pdf->heihetemplate = $this->config->offline->heihetemplate;
|
2013-08-28 01:41:49 +00:00
|
|
|
$formData['project'].='['.$formData['project_title'].' | '.$formData['project_type'].' | '.$formData['project_id'].' | ' . $formData['leader'] . ' | ' .$formData['leadertitle']. ']';
|
2013-07-24 10:11:14 +00:00
|
|
|
$pdf->data = $formData;
|
|
|
|
|
|
|
|
if (isset($formData['westdclist'])) $pdf->drawWestdc();
|
|
|
|
if (isset($formData['heihelist'])) $pdf->drawHeihe();
|
|
|
|
|
|
|
|
$pdf->addRef($this->pdfData);
|
|
|
|
|
|
|
|
$pdf->addSecurity($this->config->offline->security);
|
2013-07-19 10:19:59 +00:00
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
header("Content-Disposition: inline; filename=westdc-data-apply.pdf");
|
|
|
|
header("Content-Type:application/pdf");
|
2013-07-19 10:19:59 +00:00
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
//header("Content-Length: " . strlen($pdfstring));
|
|
|
|
echo $pdf->Output('westdc-data-apply.pdf','S');
|
2013-07-19 10:19:59 +00:00
|
|
|
}
|
2013-07-17 09:53:44 +00:00
|
|
|
|
2013-07-19 10:19:59 +00:00
|
|
|
//获得要生成pdf的信息
|
|
|
|
public function getOrderItemForPdf($uid = 0)
|
|
|
|
{
|
|
|
|
if(empty($uid))
|
|
|
|
{
|
2013-08-26 02:33:44 +00:00
|
|
|
$uid = view::User('id');
|
2013-07-19 10:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "select m.title||'('||m.filesize::text||'MB)' as title,m.ts_published,date_part('year',doi.ts_published) as publish_year,m.citation,m.suppinfo,
|
|
|
|
array_to_string(ARRAY(
|
|
|
|
select r.reference from mdref mr left join reference r on mr.refid=r.id
|
|
|
|
where mr.reftype=3 and mr.uuid=d.uuid order by mr.place),'\n'::text) as reference,
|
|
|
|
array_to_string(array(
|
|
|
|
select fund.fund_type||':'||fund.title||'(编号:'||fund.fund_id||')'
|
2013-07-22 05:23:41 +00:00
|
|
|
from fund left join mdfund on fund.id=mdfund.fid where mdfund.uuid=d.uuid order by mdfund.place),'\n'::text) as fund,
|
2013-07-19 10:19:59 +00:00
|
|
|
doi.doi as datadoi,doi.authors,doi.publisher,doi.title as doititle,doi.author_en,doi.publisher_en,doi.title_en
|
|
|
|
from dataorder d left join metadata m on d.uuid=m.uuid left join datadoi doi on doi.uuid=d.uuid
|
|
|
|
where d.status=2 and d.userid=? order by d.ts_created desc
|
|
|
|
";
|
|
|
|
$rows = $this->db->fetchAll($sql,array($uid));
|
|
|
|
|
|
|
|
return $rows;
|
|
|
|
}
|
2013-07-22 09:16:18 +00:00
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
//service_type 选择
|
|
|
|
public function serviceTypeTest($type)
|
2013-07-22 09:16:18 +00:00
|
|
|
{
|
2013-07-24 10:11:14 +00:00
|
|
|
if(empty($type) || !is_numeric($type))
|
2013-07-22 09:16:18 +00:00
|
|
|
{
|
2013-07-24 10:11:14 +00:00
|
|
|
return false;
|
2013-07-22 09:16:18 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
switch($type)
|
2013-07-22 09:16:18 +00:00
|
|
|
{
|
2013-07-24 10:11:14 +00:00
|
|
|
case 0:
|
|
|
|
return "此数据为在线查看数据";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return "此数据有可以选择的子集";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
return "此数据有多个子集供选择";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
return "";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
return "";
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
return "";
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
return "";
|
|
|
|
break;
|
2013-07-22 09:16:18 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
return false;
|
|
|
|
}//serviceTypeTest
|
2013-07-17 09:53:44 +00:00
|
|
|
}
|