westdc-zf1/application/admin/controllers/WatermdController.php

298 lines
10 KiB
PHP

<?php
class Admin_WatermdController extends Zend_Controller_Action
{
function preDispatch()
{
$this->db=Zend_Registry::get('db');
$this->view->config = Zend_Registry::get('config');
$this->messenger=$this->_helper->getHelper('FlashMessenger');
$this->view->messages = $this->messenger->getMessages();
$this->wdb=Zend_Db::factory($this->view->config->waterdb);
}
function postDispatch()
{
$this->view->messages = $this->messenger->getMessages();
}
function indexAction()
{
//其他连接
}
function replaceAction()
{
//use preg_replace to replace the string
$form=new ReplaceForm();
if ($this->_request->isPost()) {
$formdata=$this->_request->getPost();
$pattern=$formdata["pattern"];
$form->populate($formdata);
if (substr($pattern,0,1)!='/')
{
$pattern='/'.$pattern.'/m';
}
$replace=$formdata["replace"];
if (isset($formdata["test"]))
{
$this->view->test=preg_replace($pattern,$replace,$formdata["source"]);
} elseif (isset($formdata["submit"]))
{
$sql="select uuid,data from metadata where istemplate = 'n'";
$rows=$this->wdb->fetchAll($sql);
foreach($rows as $k=>$row)
{
//do the replace
$new_data=preg_replace($pattern,$replace,$row['data']);
//防止正则错误
if (!empty($new_data))
{
$sql="update metadata set data=? where uuid=?";
$this->wdb->query($sql,array($new_data,$uuid));
$dom = new DOMDocument();
$dom->loadXML($formdata['source']);
$title=$dom->getElementsByTagName('resTitle')->item(0)->nodeValue;
$deal['uuid']=$uuid;
$deal['title']=$title;
$this->view->deal[]=$deal;
}
}
}
}
$this->view->form=$form;
}
//替换标题和英文标题到数据引用中,以标题为准
function citetitleAction()
{
$form=new ReplaceForm();
$form->setElements(array($form->source,$form->test,$form->submit));
if ($this->_request->isPost()) {
$formdata=$this->_request->getPost();
$form->populate($formdata);
if (isset($formdata["test"]))
{
$dom = new DOMDocument();
$dom->loadXML($formdata['source']);
$root = $dom->getElementsByTagName('Metadata');
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$title_en_path=$xpath->query("//Metadata/dataIdInfo/idCitation/resAltTitle");
$title_en=$title_en_path->item(0)->nodeValue;
$otherCitDet=$xpath->query("//Metadata/dataIdInfo/idCitation/otherCitDet");
$other=$otherCitDet->item(0)->nodeValue;
$other_cn=mb_strstr($other,'[',true);
$title_o=mb_strstr($other_cn,'.',false);
$title_ol=substr($title_o,1,-4);
$title_old=mb_strstr($title_ol,'.',true);
$other_eng=mb_strstr($other,'[',false);
$titlen_o=mb_strstr($other_eng,'.',false);
$titlen_ol=substr($titlen_o,1,-4);
$titlen_old=mb_strstr($titlen_ol,',',true);
$new_other=str_replace(array($title_old,$titlen_old),array($title,$title_en),$other);
$otherCitDet->item(0)->nodeValue=$new_other;
$this->view->test= $dom->saveXML($root->item(0));
} elseif (isset($formdata["submit"]))
{
$sql="select uuid,data from metadata where istemplate = 'n'";
$rows=$this->wdb->fetchAll($sql);
foreach($rows as $k=>$row)
{
//do the replace
$dom = new DOMDocument();
$dom->loadXML($row['data']);
$uuid = $row['uuid'];
$root = $dom->getElementsByTagName('Metadata');
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$title_en_path=$xpath->query("//Metadata/dataIdInfo/idCitation/resAltTitle");
$title_en=$title_en_path->item(0)->nodeValue;
$otherCitDet=$xpath->query("//Metadata/dataIdInfo/idCitation/otherCitDet");
$other=$otherCitDet->item(0)->nodeValue;
$other_cn=mb_strstr($other,'[',true);
$title_o=mb_strstr($other_cn,'.',false);
$title_ol=substr($title_o,1,-4);
$title_old=mb_strstr($title_ol,'.',true);
$other_eng=mb_strstr($other,'[',false);
$titlen_o=mb_strstr($other_eng,'.',false);
$titlen_ol=substr($titlen_o,1,-4);
$titlen_old=mb_strstr($titlen_ol,',',true);
$new_other=str_replace(array($title_old,$titlen_old),array($title,$title_en),$other);
$otherCitDet->item(0)->nodeValue=$new_other;
$new_data = $dom->saveXML($root->item(0));
//防止错误
if (!empty($new_data))
{
$sql="update metadata set data=? where uuid=?";
$this->wdb->query($sql,array($new_data,$uuid));
$deal['uuid']=$uuid;
$deal['title']=$title;
$this->view->deal[]=$deal;
}
}
}
}
$this->view->form=$form;
}
//文件大小处理
function filesizeAction()
{
$form=new ReplaceForm();
$form->pattern->setLabel('文件大小');
$form->setElements(array($form->pattern,$form->source,$form->test,$form->submit));
if ($this->_request->isPost()) {
$formdata=$this->_request->getPost();
$form->populate($formdata);
if (isset($formdata["test"]))
{
$dom = new DOMDocument();
$dom->loadXML($formdata['source']);
$root = $dom->getElementsByTagName('Metadata');
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$transize_path=$xpath->query("//Metadata/distInfo/distTranOps/transSize");
$transize_path->item(0)->nodeValue=$formdata['pattern'];
$this->view->test= $dom->saveXML($root->item(0));
} elseif (isset($formdata["submit"]))
{
$sql="select uuid,data from metadata where istemplate = 'n'";
$rows=$this->wdb->fetchAll($sql);
foreach($rows as $k=>$row)
{
//do the replace
$dom = new DOMDocument();
$dom->loadXML($row['data']);
$root = $dom->getElementsByTagName('Metadata');
$uuid = $row['uuid'];
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$transize_path=$xpath->query("//Metadata/distInfo/distTranOps/transSize");
$sql="select sum(file_size) as fsize from westdc_fileinfo where meta_uuid = ?";
$this->db->setFetchMode(Zend_Db::FETCH_OBJ);
$row=$this->db->fetchRow($sql,array($uuid));
//转换单位为MB
$msize=round($row->fsize/(1024*1024),2);
if($msize>10){
$msize=round($size/(1024*1024),1);
}
$transize_path->item(0)->nodeValue=msize;
$new_data = $dom->saveXML($root->item(0));
//防止错误
if (!empty($new_data))
{
$sql="update metadata set data=? where uuid=?";
$this->wdb->query($sql,array($new_data,$uuid));
$deal['uuid']=$uuid;
$deal['title']=$title;
$this->view->deal[]=$deal;
}
}
}
}
$this->view->form=$form;
}
//修改限制使用说明
//useLimit可以是多项的
function uselimitAction()
{
$form=new ReplaceForm();
$form->pattern->setLabel('使用声明');
$form->setElements(array($form->pattern,$form->source,$form->test,$form->submit));
if ($this->_request->isPost()) {
$formdata=$this->_request->getPost();
$form->populate($formdata);
$limit_text=$formdata['pattern'];
if (isset($formdata["test"]))
{
$dom = new DOMDocument();
$dom->loadXML($formdata['source']);
$root = $dom->getElementsByTagName('Metadata');
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$uselimits=$xpath->query("//Metadata/dataIdInfo/resConst/Consts/useLimit");
$do_uselimit=1;
foreach($uselimits as $limit)
{
//已经有声明,则不需要处理
if ($limit->nodeValue==$limit_text || (strlen($limit->nodeValue)>3))
$do_uselimit=0;
}
if ($do_uselimit==1)
{
$new_uselimit=$dom->createElement('useLimit',$limit_text);
$new_resconst=$dom->createElement('resConst');
$new_const=$dom->createElement('Consts');
$new_const->appendChild($new_uselimit);
$new_resconst->appendChild($new_const);
$desckey=$xpath->query("//Metadata/dataIdInfo/descKeys")->item(0);
$resconst=$xpath->query("//Metadata/dataIdInfo/resConst")->item(0);
if ($resconst)
$resconst->parentNode->insertBefore($new_resconst,$resconst);
else
$desckey->parentNode->insertBefore($new_resconst,$desckey);
$new_data=$dom->saveXML();
}
$this->view->test= $new_data;
} elseif (isset($formdata["submit"]))
{
$sql="select uuid,data from metadata where istemplate = 'n'";
$rows=$this->wdb->fetchAll($sql);
foreach($rows as $k=>$row)
{
//do the replace
$dom = new DOMDocument();
$dom->loadXML($row['data']);
$root = $dom->getElementsByTagName('Metadata');
$uuid = $row['uuid'];
$xpath = new DOMXpath($dom);
$title_key=$xpath->query("//Metadata/dataIdInfo/idCitation/resTitle");
$title=$title_key->item(0)->nodeValue;
$uselimits=$xpath->query("//Metadata/dataIdInfo/resConst/Consts/useLimit");
$do_uselimit=1;
foreach($uselimits as $limit)
{
//已经有声明,则不需要处理
if ($limit->nodeValue==$limit_text || (strlen($limit->nodeValue)>3))
$do_uselimit=0;
}
if ($do_uselimit==1)
{
$new_uselimit=$dom->createElement('useLimit',$limit_text);
$new_resconst=$dom->createElement('resConst');
$new_const=$dom->createElement('Consts');
$new_const->appendChild($new_uselimit);
$new_resconst->appendChild($new_const);
$desckey=$xpath->query("//Metadata/dataIdInfo/descKeys")->item(0);
$resconst=$xpath->query("//Metadata/dataIdInfo/resConst")->item(0);
if ($resconst)
$resconst->parentNode->insertBefore($new_resconst,$resconst);
else
$desckey->parentNode->insertBefore($new_resconst,$desckey);
$new_data=$dom->saveXML();
//防止错误
if (!empty($new_data))
{
$sql="update metadata set data=? where uuid=?";
$this->wdb->query($sql,array($new_data,$uuid));
$deal['uuid']=$uuid;
$deal['title']=$title;
$this->view->deal[]=$deal;
}
}
}
}
}
$this->view->form=$form;
}
}