添加联系人替换功能
This commit is contained in:
parent
49d6c6e3c1
commit
d17c4798ea
|
@ -293,5 +293,79 @@ class Admin_WatermdController extends Zend_Controller_Action
|
|||
$this->view->form=$form;
|
||||
}
|
||||
|
||||
//联系人信息替换
|
||||
function contactAction()
|
||||
{
|
||||
if ($this->_request->isPost()) {
|
||||
$formdata=$this->_request->getPost();
|
||||
if (isset($formdata["test"]))
|
||||
{
|
||||
$this->view->test=$this->contactReplace($formdata["testxml"],$formdata);
|
||||
} 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=$this->contactReplace($row["data"],$formdata);
|
||||
//防止正则错误
|
||||
if (!empty($new_data))
|
||||
{
|
||||
$sql="update metadata set data=? where uuid=?";
|
||||
$this->wdb->query($sql,array($new_data,$uuid));
|
||||
$dom = new DOMDocument();
|
||||
$dom->loadXML($row['data']);
|
||||
$title=$dom->getElementsByTagName('resTitle')->item(0)->nodeValue;
|
||||
$deal['uuid']=$uuid;
|
||||
$deal['title']=$title;
|
||||
$this->view->deal[]=$deal;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->view->formdata=$formdata;
|
||||
}
|
||||
}
|
||||
|
||||
private function contactReplace($xml,$replace)
|
||||
{
|
||||
$dom = new DOMDocument();
|
||||
$dom->loadXML($xml);
|
||||
$xpath = new DOMXpath($dom);
|
||||
$contacts=$xpath->query('//rpIndName');
|
||||
foreach($contacts as $contact)
|
||||
{
|
||||
if ($contact->nodeValue==$replace['oldname'])
|
||||
{
|
||||
$newrpIndName=$dom->createElement('rpIndName',$replace['name']);
|
||||
$newrpOrgName=$dom->createElement('rpOrgName',$replace['unit']);
|
||||
$newrpCntInfo=$dom->createElement('rpCntInfo');
|
||||
$newcntPhone=$dom->createElement('cntPhone');
|
||||
$newrpCntInfo->appendChild($newcntPhone);
|
||||
$newvoiceNum=$dom->createElement('voiceNum',$replace['voicenum']);
|
||||
$newcntPhone->appendChild($newvoiceNum);
|
||||
$newcntAddress=$dom->createElement('cntAddress');
|
||||
$newrpCntInfo->appendChild($newcntAddress);
|
||||
$newdelPoint=$dom->createElement('delPoint',$replace['delpoint']);
|
||||
$newcntAddress->appendChild($newdelPoint);
|
||||
$newpostCode=$dom->createElement('postCode',$replace['postcode']);
|
||||
$newcntAddress->appendChild($newpostCode);
|
||||
$neweMailAdd=$dom->createElement('eMailAdd',$replace['email']);
|
||||
$newcntAddress->appendChild($neweMailAdd);
|
||||
|
||||
$rporg=$xpath->query('rpOrgName',$contact->parentNode);
|
||||
$contact->parentNode->removeChild($rporg->item(0));
|
||||
$rpcnt=$xpath->query('rpCntInfo',$contact->parentNode);
|
||||
$contact->parentNode->removeChild($rpcnt->item(0));
|
||||
|
||||
$contact->parentNode->insertBefore($newrpIndName,$contact);
|
||||
$contact->parentNode->insertBefore($newrpOrgName,$contact);
|
||||
$contact->parentNode->insertBefore($newrpCntInfo,$contact);
|
||||
|
||||
$contact->parentNode->removeChild($contact);
|
||||
}
|
||||
}
|
||||
return $dom->saveXML();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('后台管理');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headLink()->appendStylesheet('/css/admin.css');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/admin">后台首页</a>');
|
||||
$this->breadcrumb('<a href="/admin/watermd">WATER元数据工具</a>');
|
||||
$this->breadcrumb('联系人替换');
|
||||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<div id="leftPanel">
|
||||
<?= $this->partial('watermd/left.phtml'); ?>
|
||||
</div>
|
||||
<div id="rightPanel">
|
||||
<?php if ($this->msg or $this->messages) :?>
|
||||
<div id="message">
|
||||
<?php if ($this->msg) : ?>
|
||||
<p><?php echo $this->msg; ?></p>
|
||||
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
|
||||
<p><?php echo $msg; ?></p>
|
||||
<?php endforeach;endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($this->deal) : ?>
|
||||
<div id="mdlist">
|
||||
已处理数据:
|
||||
<?php foreach ($this->deal as $deal): ?>
|
||||
<ul>
|
||||
<li>UUID:<?php echo $deal['uuid']; ?></li>
|
||||
<li><a href="/heihe/<?= $deal['uuid']; ?>"><?= $deal['title']; ?></a></li>
|
||||
</ul>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<form enctype="application/x-www-form-urlencoded" action="" method="post">
|
||||
<label>被替换者姓名:</label>
|
||||
<input type="text" name="oldname" value="<?= $this->formdata['oldname'] ?>">
|
||||
<fieldset><legend>替换信息</legend>
|
||||
<li><label>姓名:</label><input type="text" name="name" value="<?= $this->formdata['name'] ?>"></li>
|
||||
<li><label>单位:</label><input type="text" name="unit" value="<?= $this->formdata['unit'] ?>"></li>
|
||||
<li><label>地址:</label><input type="text" name="delpoint" value="<?= $this->formdata['delpoint'] ?>"></li>
|
||||
<li><label>邮编:</label><input type="text" name="postcode" value="<?= $this->formdata['postcode'] ?>"></li>
|
||||
<li><label>电话:</label><input type="text" name="voicenum" value="<?= $this->formdata['voicenum'] ?>"></li>
|
||||
<li><label>邮箱:</label><input type="text" name="email" value="<?= $this->formdata['email'] ?>"></li>
|
||||
</fieldset>
|
||||
<label>测试XML数据</label>
|
||||
<textarea name="testxml" rows="10" cols="80"><?= $this->formdata['testxml'] ?></textarea>
|
||||
<li><input type="submit" name="test" id="test" value="测试"> <input type="submit" name="submit" value="全部运行(危险操作!请先测试)"></li>
|
||||
</form>
|
||||
<?php if ($this->test) : ?>
|
||||
<div>测试结果:<br />
|
||||
<?= $this->escape($this->test) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
|
@ -3,4 +3,5 @@
|
|||
<li><a href="/admin/watermd/citetitle">引用的标题替换</a></li>
|
||||
<li><a href="/admin/watermd/filesize">文件大小处理</a></li>
|
||||
<li><a href="/admin/watermd/uselimit">使用声明处理</a></li>
|
||||
<li><a href="/admin/watermd/contact">联系人替换</a></li>
|
||||
</ul>
|
Loading…
Reference in New Issue