diff --git a/application/module/Files/Files.php b/application/module/Files/Files.php index 44b19014..7be0fd5c 100644 --- a/application/module/Files/Files.php +++ b/application/module/Files/Files.php @@ -47,6 +47,11 @@ class Files{ return array("error"=>"文件上传失败,请重新上传"); } + if($file['size'] > 20 * 1024 * 1024) + { + return array('error'=>"文件大小超出限制"); + } + $ext = $this->getFileTextExt($file['name']); $filename = $orderid.".".$ext; diff --git a/application/module/Helpers/View.php b/application/module/Helpers/View.php index 4643f6c9..703b189b 100644 --- a/application/module/Helpers/View.php +++ b/application/module/Helpers/View.php @@ -130,4 +130,10 @@ class View extends \Zend_Controller_Plugin_Abstract } return $protocol."://".$_SERVER['SERVER_NAME']; } + + static function isXmlHttpRequest() + { + $zfhttp = new \Zend_Controller_Request_Http(); + return $zfhttp->isXmlHttpRequest(); + } } \ No newline at end of file diff --git a/application/module/Helpers/dbh.php b/application/module/Helpers/dbh.php index 0a434f16..83791cd1 100644 --- a/application/module/Helpers/dbh.php +++ b/application/module/Helpers/dbh.php @@ -57,7 +57,7 @@ class dbh $sth = $this->db->prepare($sql); if($sth->execute()) { - $temp = $sth->fetch(PDO::FETCH_ASSOC); + $temp = $sth->fetch(\PDO::FETCH_ASSOC); return $temp['id']; }else{ return false; diff --git a/application/module/Mail/Mail.php b/application/module/Mail/Mail.php index c8e3656e..8736bffb 100644 --- a/application/module/Mail/Mail.php +++ b/application/module/Mail/Mail.php @@ -82,6 +82,12 @@ class Mail $this->mail->setFrom($this->conf->username,$this->conf->name); } + //设置默认收件人 + public function setDefaultTo() + { + $this->mail->addTo($this->conf->username,$this->conf->name); + } + //加载模板 public function loadTemplate($id,$data){ if(is_numeric($id)) diff --git a/application/module/Open/app.php b/application/module/Open/app.php new file mode 100644 index 00000000..23d3b377 --- /dev/null +++ b/application/module/Open/app.php @@ -0,0 +1,45 @@ +load(); + } + + //获得用户创建的app + public function getUserApp($uid = 0) + { + if(empty($uid)) + { + $uid = $this->user->id; + } + + $sql = "SELECT * FROM ".$this->tbl_oauth_clients." WHERE user_id=".$this->user->id; + $rs = $this->db->query($sql); + $rows = $rs->fetchAll(); + + return $rows; + } + + //获得某个App的信息 + public function getAppInfo($id) + { + if(empty($id)) + { + return false; + } + $sql = "SELECT * FROM ".$this->tbl_oauth_clients." WHERE id=".$id; + $rs = $this->db->query($sql); + $rows = $rs->fetch(); + + return $rows; + } + + +} \ No newline at end of file diff --git a/application/module/Open/open.php b/application/module/Open/open.php new file mode 100644 index 00000000..8a6445df --- /dev/null +++ b/application/module/Open/open.php @@ -0,0 +1,66 @@ +config = \Zend_Registry::get('config'); + if(empty($db)) + { + $this->db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + if(empty($auth)) + { + $this->auth = \Zend_Auth::getInstance(); + if($this->auth->hasIdentity()) + { + $this->user = $this->auth->getIdentity(); + } + }else{ + $this->auth = false; + } + } + + //检查用户资料完整性 + public function checkinfo() + { + if($this->auth === false) + { + return "未登陆"; + } + + include_once("Users.php"); + $user = new \Users($this->db); + $info = $user->getUserInfo($this->user->id); + + foreach($this->checkFiled as $v) + { + if(empty($info[$v])) + { + return "请完善个人信息"; + } + } + + return true; + } + +} \ No newline at end of file diff --git a/application/module/Open/server.php b/application/module/Open/server.php new file mode 100644 index 00000000..ee0b7408 --- /dev/null +++ b/application/module/Open/server.php @@ -0,0 +1,50 @@ +config = \Zend_Registry::get('config'); + if(empty($db)) + { + $this->db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + if(empty($auth)) + { + $this->auth = \Zend_Auth::getInstance(); + if($this->auth->hasIdentity()) + { + $this->user = $this->auth->getIdentity(); + } + }else{ + $this->auth = false; + } + } + + public function bootstrap() + { + $dsn = "pgsql:dbname={$this->config->db->params->dbname};host={$this->config->db->params->host}"; + + $storage = new \OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $this->config->db->params->username, 'password' => $this->config->db->params->password)); + + $server = new \OAuth2\Server($storage); + + $server->addGrantType(new \OAuth2\GrantType\ClientCredentials($storage)); + + $server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($storage)); + + //应用授权 + //$server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send(); + + return $server; + } + +} \ No newline at end of file diff --git a/application/module/Order/Manager/Offlineapp.php b/application/module/Order/Manager/Offlineapp.php index 3b01191d..dedf7f27 100644 --- a/application/module/Order/Manager/Offlineapp.php +++ b/application/module/Order/Manager/Offlineapp.php @@ -3,6 +3,7 @@ namespace Order\Manager; use Helpers\View as view; use Helpers\dbh; +use Order\listener\ManagerListener; class Offlineapp { @@ -16,6 +17,9 @@ class Offlineapp { $this->db = \Zend_Registry::get('db'); $this->config = \Zend_Registry::get('config'); + + $Listener = new ManagerListener(); + @$this->events()->attachAggregate($Listener); } public function events(\Zend_EventManager_EventCollection $events = NULL) @@ -50,25 +54,73 @@ class Offlineapp return "参数错误"; } - $data = array( - - ); - $sql="update dataorder set status=4,ts_received=now() where id=?"; - $rs = $this->db->query($sql,array($id)); - $row = $rs->fetch(); + $sql="update dataorder set status=4,ts_received=now() where offlineappid=$id"; + if($this->db->exec($sql) > 0) + { + @$this->db->exec("UPDATE offlineapp SET status=4,ts_received=now() WHERE id=$id"); + @$this->events()->trigger('offlineapp.received', $this, compact('id')); + return true; + }else{ + return "接收失败,请重试"; + } + } + + //获取一个申请的详细信息 + public function getOneAppInfo($id) + { + $sql = "SELECT off.*,o.status,o.applicationform FROM offlineapp off + LEFT JOIN dataorder o ON off.id=o.offlineappid + WHERE off.id = $id + "; + $rs = $this->db->query($sql); + return $rs->fetchAll(); + }// + + //重置申请表 + public function resetAppForm($id) + { + $sql = "SELECT * FROM dataorder WHERE offlineappid=$id"; + $rs = $this->db->query($sql); + $rows = $rs->fetchAll(); + $ids = array(); + + foreach($rows as $v) + { + $ids[] = $v['id']; + } + + if(file_exists($rows[0]['applicationform'])) + { + @unlink($rows[0]['applicationform']); + } + + if($this->db->exec("UPDATE dataorder SET applicationform=NULL WHERE offlineappid=$id")>0) + { + @$this->events()->trigger('offlineapp.AppFormReseted', $this, compact('id')); + return true; + }else{ + return "重置遇到问题,请重试"; + } + } + + //提交给作者的时候需要处理的内容 + public function sendToAuthor() + { } + /////////////////////////////////////////// public function offLineAppMakeQuery($opt) { $def = array( - 'field' => ' o.id as orderid,o.status,o.applicationform,off.*,u.realname,u.username ', + 'field' => ' off.*,o.id as orderid,o.status,o.applicationform,u.realname,u.username,md.title ', 'table' => ' dataorder o ', 'join' => ' LEFT JOIN offlineapp off ON off.id=o.offlineappid - LEFT JOIN users u ON u.id = off.userid', - 'order' => ' o.id ASC ' + LEFT JOIN users u ON u.id = off.userid + LEFT JOIN metadata md ON md.uuid=o.uuid', + 'order' => ' o.id DESC ' ); return array_merge($def,$opt); } @@ -76,9 +128,29 @@ class Offlineapp public function fetchNotReceived() { $opt = $this->offLineAppMakeQuery(array( - 'where' => ' o.offlineappid != -1 AND o.status=1' + 'where' => ' o.offlineappid != -1 AND o.status=3' + )); + $dbh = new dbh(); + //echo $dbh->select($opt,true);exit(); + return $dbh->select($opt); + }//未接受的 + + public function fetchNoPdf() + { + $opt = $this->offLineAppMakeQuery(array( + 'where' => ' o.offlineappid != -1 AND o.status=4 AND (o.applicationform IS NULL OR o.applicationform=\'\') ' + )); + $dbh = new dbh(); + //echo $dbh->select($opt,true);exit(); + return $dbh->select($opt); + }//没有pdf的 + + public function fetchNotApprove() + { + $opt = $this->offLineAppMakeQuery(array( + 'where' => ' o.offlineappid != -1 AND o.status=4 AND (o.applicationform IS NOT NULL || o.applicationform!=\'\') ' )); $dbh = new dbh(); return $dbh->select($opt); - } + }//待审核 } \ No newline at end of file diff --git a/application/module/Order/Order.php b/application/module/Order/Order.php index 40f358cd..ef7cc4de 100644 --- a/application/module/Order/Order.php +++ b/application/module/Order/Order.php @@ -2,6 +2,8 @@ namespace Order; use Helpers\View as view; +use Mail\Mail; +use Order\listener\OrderListener; class Order { @@ -33,6 +35,9 @@ class Order } $this->config = \Zend_Registry::get('config'); + + $Listener = new OrderListener(); + @$this->events()->attachAggregate($Listener); } public function events(\Zend_EventManager_EventCollection $events = NULL) @@ -319,10 +324,11 @@ class Order //header("Content-Length: " . strlen($pdfstring)); echo $pdf->Output('westdc-data-apply.pdf','S'); }else{ - $fn = $formData['realname'].date('YmdHis').".pdf"; - //$fn = date('YmdHis').".pdf"; + //$fn = $formData['realname'].date('YmdHis').".pdf"; + $fn = date('YmdHis').".pdf"; $path = realpath($this->config->offline->savepath); - $pdf->Output($path.DIRECTORY_SEPARATOR.$fn, 'F'); + $pdf->pdflink = $fn; + @$pdf->Output($path.DIRECTORY_SEPARATOR.$fn, 'F'); } if($returnpdf === true) @@ -332,7 +338,7 @@ class Order } //获得要生成pdf的信息 - public function getOrderItemForPdf($uid = 0) + public function getOrderItemForPdf($uid = 0 , $statu = 2) { if(empty($uid)) { @@ -348,13 +354,34 @@ class Order from fund left join mdfund on fund.id=mdfund.fid where mdfund.uuid=d.uuid order by mdfund.place),'\n'::text) as fund, 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 + where d.status=$statu and d.userid=? order by d.ts_created desc "; $rows = $this->db->fetchAll($sql,array($uid)); return $rows; } + //确认申请 + public function commitApplicationForm($offlineappid) + { + $user = view::User(); + + if($user === false) + { + return false; + } + + $data = array( + "user" => empty($user->realname) ? $user->username : $user->realname, + "link"=> view::getHostLink() . '/admin/down/offlineapps/ac/view/offlineappid/'.$offlineappid + ); + + $mail = new Mail(); + $mail->loadTemplate("offline-pdf-commited",$data); + $mail->setDefaultTo(); + $mail->send(); + }//确认申请 + //service_type 选择 public function serviceTypeTest($type) { diff --git a/application/module/Order/listener/ManagerEvents.php b/application/module/Order/listener/ManagerEvents.php new file mode 100644 index 00000000..2fedd65f --- /dev/null +++ b/application/module/Order/listener/ManagerEvents.php @@ -0,0 +1,10 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + $this->config = \Zend_Registry::get('config'); + } + + public function attach(\Zend_EventManager_EventCollection $events) + { + $this->attachOnOfflineapp($events); + } + + public function detach(\Zend_EventManager_EventCollection $events) + { + + } + + public function attachOnOfflineapp(\Zend_EventManager_EventCollection $events) + { + $mountedClass = new ManagerOperate(); + $events->attach('offlineapp.received', array($mountedClass, 'received'), 100); + $events->attach('offlineapp.AppFormReseted',array($mountedClass, 'appFormReseted'), 100); + } + + +} \ No newline at end of file diff --git a/application/module/Order/mount/ManagerOperate.php b/application/module/Order/mount/ManagerOperate.php new file mode 100644 index 00000000..8929337b --- /dev/null +++ b/application/module/Order/mount/ManagerOperate.php @@ -0,0 +1,92 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + } + + //申请成功提交之后 + public function received(\Zend_EventManager_Event $e) + { + $id = $e->getParam('id'); + + try{ + + $OM = new Offlineapp(); + + $data = $OM->getOneAppInfo($id); + + $emailkeys = array( + "user"=>$data[0]['username'], + "datalist"=>str_replace(";","\n",$data[0]['datalist']), + ); + + $mail = new Mail(); + $mail->loadTemplate("offline-start",$emailkeys); + $mail->addTo($data[0]['email'],$data[0]['username']); + $mail->send(); + + }catch(Exception $e) + { + return $e->getMessage(); + } + + return true; + } + + //申请表重置 + public function appFormReseted(\Zend_EventManager_Event $e) + { + $id = $e->getParam('id'); + + try{ + + $OM = new Offlineapp(); + + $data = $OM->getOneAppInfo($id); + + $emailkeys = array( + "user"=>$data[0]['username'], + "link"=> view::getHostLink() . '/data/order/ac/offline3' + ); + + $mail = new Mail(); + $mail->loadTemplate("offline-appformreseted",$emailkeys); + $mail->addTo($data[0]['email'],$data[0]['username']); + $mail->send(); + + }catch(Exception $e) + { + return $e->getMessage(); + } + + return true; + + } + + //专题数据集 + public function checkDataSource() + { + + } + +} \ No newline at end of file diff --git a/application/module/Order/mount/PdfOperate.php b/application/module/Order/mount/PdfOperate.php index d091cb2c..7639142d 100644 --- a/application/module/Order/mount/PdfOperate.php +++ b/application/module/Order/mount/PdfOperate.php @@ -101,6 +101,12 @@ class PdfOperate implements \Order\listener\PdfEvents return "数据篮状态更新失败,请重试"; } + $sql = "UPDATE offlineapp SET pdflink='".$pdf->pdflink."' WHERE id=$oid "; + if($this->db->exec($sql) < 0) + { + return "数据篮状态更新有误,请联系管理员"; + } + $this->sendEmail($formData,$pdf); }catch(Exception $e) @@ -116,7 +122,8 @@ class PdfOperate implements \Order\listener\PdfEvents { $data = array( "user"=>$formData['realname'], - "datalist"=>str_replace(";","\n",$formData['datalist']) + "datalist"=>str_replace(";","\n",$formData['datalist']), + "orderlink"=> view::getHostLink() . '/data/order/ac/offline3' ); $mail = new Mail();