* Add entry and webhook module.

This commit is contained in:
liugang
2017-10-19 10:41:29 +08:00
parent fe16db7484
commit 29cd0d4b4e
26 changed files with 1113 additions and 5 deletions

View File

@@ -101,6 +101,9 @@ define('TABLE_DOCCONTENT', '`' . $config->db->prefix . 'doccontent`');
define('TABLE_TESTSUITE', '`' . $config->db->prefix . 'testsuite`');
define('TABLE_SUITECASE', '`' . $config->db->prefix . 'suitecase`');
define('TABLE_TESTREPORT', '`' . $config->db->prefix . 'testreport`');
define('TABLE_ENTRY', '`' . $config->db->prefix . 'entry`');
define('TABLE_WEBHOOK', '`' . $config->db->prefix . 'webhook`');
if(!defined('TABLE_LANG')) define('TABLE_LANG', '`' . $config->db->prefix . 'lang`');
$config->objectTables['product'] = TABLE_PRODUCT;

View File

@@ -341,6 +341,7 @@ $lang->admin->menu->safe = array('link' => 'Security|admin|safe', 'alias' =
$lang->admin->menu->cron = array('link' => 'Cron|cron|index', 'subModule' => 'cron');
$lang->admin->menu->trashes = array('link' => 'Recycle|action|trash', 'subModule' => 'action');
$lang->admin->menu->dev = array('link' => 'Develop|dev|api', 'alias' => 'db', 'subModule' => 'dev,editor');
$lang->admin->menu->entry = array('link' => 'API|entry|browse', 'alias' => 'create,edit', 'subModule' => 'entry,webhook');
$lang->admin->menu->sso = 'RangerTeam|admin|sso';
$lang->convert = new stdclass();
@@ -353,6 +354,8 @@ $lang->editor = new stdclass();
$lang->mail = new stdclass();
$lang->cron = new stdclass();
$lang->dev = new stdclass();
$lang->entry = new stdclass();
$lang->webhook = new stdclass();
$lang->search = new stdclass();
$lang->convert->menu = $lang->admin->menu;
@@ -365,6 +368,7 @@ $lang->custom->menu = $lang->admin->menu;
$lang->editor->menu = $lang->admin->menu;
$lang->mail->menu = $lang->admin->menu;
$lang->dev->menu = $lang->admin->menu;
$lang->webhook->menu = $lang->admin->menu;
/* 菜单分组。*/
$lang->menugroup = new stdclass();
@@ -395,6 +399,8 @@ $lang->menugroup->custom = 'admin';
$lang->menugroup->editor = 'admin';
$lang->menugroup->mail = 'admin';
$lang->menugroup->dev = 'admin';
$lang->menugroup->entry = 'admin';
$lang->menugroup->webhook = 'admin';
/* 错误提示信息。*/
$lang->error = new stdclass();

View File

@@ -118,6 +118,8 @@ $lang->admin->menuOrder[35] = 'cron';
$lang->admin->menuOrder[40] = 'backup';
$lang->admin->menuOrder[45] = 'dev';
$lang->admin->menuOrder[50] = 'safe';
$lang->admin->menuOrder[53] = 'entry';
$lang->admin->menuOrder[54] = 'webhook';
$lang->admin->menuOrder[55] = 'sso';
$lang->admin->menuOrder[60] = 'trashes';
$lang->convert->menuOrder = $lang->admin->menuOrder;
@@ -130,3 +132,5 @@ $lang->custom->menuOrder = $lang->admin->menuOrder;
$lang->editor->menuOrder = $lang->admin->menuOrder;
$lang->mail->menuOrder = $lang->admin->menuOrder;
$lang->dev->menuOrder = $lang->admin->menuOrder;
$lang->entry->menuOrder = $lang->admin->menuOrder;
$lang->webhook->menuOrder = $lang->admin->menuOrder;

View File

@@ -341,6 +341,7 @@ $lang->admin->menu->safe = array('link' => '安全|admin|safe', 'alias' =>
$lang->admin->menu->cron = array('link' => '计划任务|cron|index', 'subModule' => 'cron');
$lang->admin->menu->trashes = array('link' => '回收站|action|trash', 'subModule' => 'action');
$lang->admin->menu->dev = array('link' => '二次开发|dev|api', 'alias' => 'db', 'subModule' => 'dev,editor');
$lang->admin->menu->entry = array('link' => '接口|entry|browse', 'alias' => 'create,edit', 'subModule' => 'entry,webhook');
$lang->admin->menu->sso = '然之集成|admin|sso';
$lang->convert = new stdclass();
@@ -353,6 +354,8 @@ $lang->editor = new stdclass();
$lang->mail = new stdclass();
$lang->cron = new stdclass();
$lang->dev = new stdclass();
$lang->entry = new stdclass();
$lang->webhook = new stdclass();
$lang->search = new stdclass();
$lang->convert->menu = $lang->admin->menu;
@@ -365,6 +368,8 @@ $lang->custom->menu = $lang->admin->menu;
$lang->editor->menu = $lang->admin->menu;
$lang->mail->menu = $lang->admin->menu;
$lang->dev->menu = $lang->admin->menu;
$lang->entry->menu = $lang->admin->menu;
$lang->webhook->menu = $lang->admin->menu;
/* 菜单分组。*/
$lang->menugroup = new stdclass();
@@ -395,6 +400,8 @@ $lang->menugroup->custom = 'admin';
$lang->menugroup->editor = 'admin';
$lang->menugroup->mail = 'admin';
$lang->menugroup->dev = 'admin';
$lang->menugroup->entry = 'admin';
$lang->menugroup->webhook = 'admin';
/* 错误提示信息。*/
$lang->error = new stdclass();

6
module/entry/config.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
$config->entry->create = new stdclass();
$config->entry->create->requiredFields = 'name, code, key';
$config->entry->edit = new stdclass();
$config->entry->edit->requiredFields = 'name, code, key';

114
module/entry/control.php Normal file
View File

@@ -0,0 +1,114 @@
<?php
/**
* The control file of entry module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package entry
* @version $Id$
* @link http://www.zentao.net
*/
class entry extends control
{
/**
* Browse entries.
*
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 10, $pageID = 1)
{
$pager = $this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$this->view->title = $this->lang->entry->api . $this->lang->colon . $this->lang->entry->list;
$this->view->entries = $this->entry->getList($orderBy, $pager);
$this->view->orderBy = $orderBy;
$this->view->pager = $pager;
$this->display();
}
/**
* Create an entry.
*
* @access public
* @return void
*/
public function create()
{
if($_POST)
{
$entryID = $this->entry->create();
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->loadModel('action')->create('entry', $entryID, 'created');
$this->send(array('result' => 'success', 'message' => $this->lang->entry->saveSuccess, 'locate' => inlink('browse')));
}
$this->view->title = $this->lang->entry->api . $this->lang->colon . $this->lang->entry->create;
$this->display();
}
/**
* Edit an entry.
*
* @param int $entryID
* @access public
* @return void
*/
public function edit($entryID)
{
if($_POST)
{
$changes = $this->entry->update($entryID);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
if($changes)
{
$actionID = $this->loadModel('action')->create('entry', $entryID, 'edited');
$this->action->logHistory($actionID, $changes);
}
$this->send(array('result' => 'success', 'message' => $this->lang->entry->saveSuccess, 'locate' => inlink('browse')));
}
$entry = $this->entry->getById($entryID);
$this->view->title = $this->lang->entry->edit . $this->lang->colon . $entry->name;
$this->view->entry = $entry;
$this->display();
}
/**
* Delete an entry.
*
* @param int $entryID
* @access public
* @return void
*/
public function delete($entryID)
{
$this->entry->delete($entryID);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->send(array('result' => 'success'));
}
/**
* Show access logs of entry.
*
* @param int $entryID
* @access public
* @return void
*/
public function log($entryID)
{
$entry = $this->entry->getById($entryID);
$this->view->title = $this->lang->entry->log . $this->lang->colon . $entry->name;
$this->view->actions = $this->loadModel('action')->getList('entry', $entryID);
$this->display();
}
}

31
module/entry/js/create.js Normal file
View File

@@ -0,0 +1,31 @@
/**
* create key for an entry.
*
* @access public
* @return void
*/
function createKey()
{
var chars = '0123456789abcdefghiklmnopqrstuvwxyz'.split('');
var key = '';
for(var i = 0; i < 32; i ++)
{
key += chars[Math.floor(Math.random() * chars.length)];
}
$('#key').val(key);
return false;
}
$('#allIP').change(function()
{
if($(this).prop('checked'))
{
$('#ip').attr('disabled', 'disabled');
}
else
{
$('#ip').removeAttr('disabled');
}
})
$('#name').focus();

31
module/entry/js/edit.js Normal file
View File

@@ -0,0 +1,31 @@
/**
* create key for an entry.
*
* @access public
* @return void
*/
function createKey()
{
var chars = '0123456789abcdefghiklmnopqrstuvwxyz'.split('');
var key = '';
for(var i = 0; i < 32; i ++)
{
key += chars[Math.floor(Math.random() * chars.length)];
}
$('#key').val(key);
return false;
}
$('#allIP').change(function()
{
if($(this).prop('checked'))
{
$('#ip').attr('disabled', 'disabled');
}
else
{
$('#ip').removeAttr('disabled');
}
})
$('#name').focus();

View File

@@ -0,0 +1,32 @@
<?php
$lang->entry->common = '应用';
$lang->entry->list = '应用列表';
$lang->entry->api = '接口';
$lang->entry->webhook = 'webhook';
$lang->entry->log = '日志';
$lang->entry->browse = '浏览应用';
$lang->entry->create = '添加应用';
$lang->entry->edit = '编辑应用';
$lang->entry->delete = '删除应用';
$lang->entry->createKey = '重新生成密钥';
$lang->entry->id = 'ID';
$lang->entry->name = '名称';
$lang->entry->code = '代号';
$lang->entry->key = '密钥';
$lang->entry->ip = 'IP';
$lang->entry->desc = '描述';
$lang->entry->createdBy = '由谁创建';
$lang->entry->createdDate = '创建时间';
$lang->entry->editedby = '最后编辑';
$lang->entry->editedDate = '编辑时间';
$lang->entry->saveSuccess = '保存成功';
$lang->entry->confirmDelete = '您确认要删除该应用吗?';
$lang->entry->note = new stdClass();
$lang->entry->note->name = '授权应用名称';
$lang->entry->note->code = '授权应用代号,必须为英文、数字或下划线的组合';
$lang->entry->note->ip = "允许访问应用的ip多个ip用逗号隔开。支持IP段如192.168.1.*";
$lang->entry->note->allIP = '无限制';

108
module/entry/model.php Normal file
View File

@@ -0,0 +1,108 @@
<?php
/**
* The model file of entry module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package entry
* @version $Id$
* @link http://www.zentao.net
*/
class entryModel extends model
{
/**
* Get an entry by id.
*
* @param int $entryID
* @access public
* @return array
*/
public function getById($entryID)
{
return $this->dao->select('*')->from(TABLE_ENTRY)->where('id')->eq($entryID)->fetch();
}
/**
* Get entry list.
*
* @param string $orderBy
* @param obejct $pager
* @access public
* @return array
*/
public function getList($orderBy = 'id_desc', $pager = null)
{
return $this->dao->select('*')->from(TABLE_ENTRY)->orderBy($orderBy)->page($pager)->fetchAll('id');
}
/**
* Create an entry.
*
* @access public
* @return bool | int
*/
public function create()
{
$entry = fixer::input('post')
->setDefault('ip', '*')
->setIF($this->post->allIP, 'ip', '*')
->add('createdBy', $this->app->user->account)
->add('createdDate', helper::now())
->remove('allIP')
->get();
$this->dao->insert(TABLE_ENTRY)->data($entry)
->batchCheck($this->config->entry->create->requiredFields, 'notempty')
->check('code', 'unique')
->autoCheck()
->exec();
if(dao::isError()) return false;
return $this->dao->lastInsertId();
}
/**
* Update an entry.
*
* @param int $entryID
* @access public
* @return bool | array
*/
public function update($entryID)
{
$oldEntry = $this->getById($entryID);
$entry = fixer::input('post')
->setDefault('ip', '*')
->setIF($this->post->allIP, 'ip', '*')
->add('editedBy', $this->app->user->account)
->add('editedDate', helper::now())
->remove('allIP')
->get();
$this->dao->update(TABLE_ENTRY)->data($entry)
->batchCheck($this->config->entry->edit->requiredFields, 'notempty')
->check('code', 'unique', "id!=$entryID")
->autoCheck()
->where('id')->eq($entryID)
->exec();
if(dao::isError()) return false;
return common::createChanges($oldEntry, $entry);
}
/**
* Delete an entry.
*
* @param int $entryID
* @param int $null
* @access public
* @return bool
*/
public function delete($entryID, $null = null)
{
$this->dao->delete()->from(TABLE_ENTRY)->where('id')->eq($entryID)->exec();
return !dao::isError();
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* The browse view file of entry module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package entry
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include 'header.html.php';?>
<?php js::set('confirmDelete', $lang->entry->confirmDelete);?>
<form id='ajaxForm' method='post'>
<table id='entryList' class='table table-condensed table-hover table-striped tablesorter'>
<thead>
<tr>
<?php $vars = "orderBy=%s&recTotal=$pager->recTotal&recPerPage=$pager->recPerPage&pageID=$pager->pageID";?>
<th class='w-50px'><?php common::printOrderLink('id', $orderBy, $vars, $lang->entry->id);?></th>
<th class='w-200px'><?php common::printOrderLink('name', $orderBy, $vars, $lang->entry->name);?></th>
<th class='w-100px'><?php common::printOrderLink('code', $orderBy, $vars, $lang->entry->code);?></th>
<th class='w-200px'><?php common::printOrderLink('key', $orderBy, $vars, $lang->entry->key);?></th>
<th class='w-200px'><?php common::printOrderLink('ip', $orderBy, $vars, $lang->entry->ip);?></th>
<th><?php echo common::printOrderLink('desc', $orderBy, $vars, $lang->entry->desc);?></th>
<th class='w-80px'><?php echo html::a('###', $lang->actions);?></th>
</tr>
</thead>
<tbody>
<?php foreach($entries as $entry):?>
<tr>
<td class='text-center'><?php echo $entry->id;?></td>
<td title='<?php echo $entry->name;?>'><?php echo $entry->name;?></td>
<td><?php echo $entry->code;?></td>
<td title='<?php echo $entry->key;?>'><?php echo $entry->key;?></td>
<td title='<?php echo $entry->ip;?>'><?php echo $entry->ip;?></td>
<td title='<?php echo $entry->desc;?>'><?php echo $entry->desc;?></td>
<td class='text-right'>
<?php
common::printIcon('entry', 'log', "entryID=$entry->id", '', 'list', 'file-text-o');
common::printIcon('entry', 'edit', "entryID=$entry->id", '', 'list');
if(common::hasPriv('entry', 'delete'))
{
$deleteURL = $this->createLink('entry', 'delete', "entryID=$entry->id&confirm=yes");
echo html::a("javascript:ajaxDelete(\"$deleteURL\",\"entryList\",confirmDelete)", '<i class="icon-remove"></i>', '', "title='{$lang->entry->delete}' class='btn-icon'");
}
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan='7'><?php $pager->show();?></td>
</tr>
</tfoot>
</table>
</form>
<?php include '../../common/view/footer.html.php';?>

View File

@@ -0,0 +1,64 @@
<?php
/**
* The create view file of entry module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package entry
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/form.html.php';?>
<div class='container mw-800px'>
<div id="titlebar">
<div class="heading">
<strong><?php echo $lang->entry->api;?></strong>
<small class="text-muted"> <?php echo $lang->entry->create;?> <i class="icon-pencil"></i></small>
</div>
</div>
<form id='entryForm' method='post' class='ajaxForm'>
<table class='table table-form'>
<tr>
<th class='w-80px'><?php echo $lang->entry->name;?></th>
<td><?php echo html::input('name', '', "class='form-control' title='{$lang->entry->note->name}' placeholder='{$lang->entry->note->name}'");?></td>
<td class='w-120px'></td>
</tr>
<tr>
<th><?php echo $lang->entry->code;?></th>
<td><?php echo html::input('code', '', "class='form-control' title='{$lang->entry->note->code}' placeholder='{$lang->entry->note->code}'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->entry->key;?></th>
<td><?php echo html::input('key', md5(rand()), "class='form-control' readonly='readonly'");?></td>
<td><span class="help-inline"><?php echo html::a('javascript:void(0)', $lang->entry->createKey, '', 'onclick="createKey()" tabIndex="-1"')?></span></td>
</tr>
<tr>
<th><?php echo $lang->entry->ip;?></th>
<td>
<div class='input-group'>
<?php echo html::input('ip', '', "class='form-control' title='{$lang->entry->note->ip}' placeholder='{$lang->entry->note->ip}'");?>
<div class='input-group-addon'>
<label class="checkbox-inline"><input type="checkbox" id="allIP" name="allIP" value="1"><?php echo $lang->entry->note->allIP;?></label>
</div>
</div>
</td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->entry->desc;?></th>
<td><?php echo html::textarea('desc', '', "rows='3' class='form-control'");?></td>
<td></td>
</tr>
<tr>
<th></th>
<td><?php echo html::submitButton();?></td>
<td></td>
</tr>
</table>
</form>
</div>
<?php include '../../common/view/footer.lite.html.php';?>

View File

@@ -0,0 +1,64 @@
<?php
/**
* The edit view file of entry module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package entry
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/form.html.php';?>
<div class='container mw-800px'>
<div id="titlebar">
<div class="heading">
<strong><?php echo $lang->entry->api;?></strong>
<small class="text-muted"> <?php echo $lang->entry->edit;?> <i class="icon-pencil"></i></small>
</div>
</div>
<form id='entryForm' method='post' class='ajaxForm'>
<table class='table table-form'>
<tr>
<th class='w-80px'><?php echo $lang->entry->name;?></th>
<td><?php echo html::input('name', $entry->name, "class='form-control' title='{$lang->entry->note->name}' placeholder='{$lang->entry->note->name}'");?></td>
<td class='w-120px'></td>
</tr>
<tr>
<th><?php echo $lang->entry->code;?></th>
<td><?php echo html::input('code', $entry->code, "class='form-control' title='{$lang->entry->note->code}' placeholder='{$lang->entry->note->code}'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->entry->key;?></th>
<td><?php echo html::input('key', $entry->key, "class='form-control' readonly='readonly'");?></td>
<td><span class="help-inline"><?php echo html::a('javascript:void(0)', $lang->entry->createKey, '', 'onclick="createKey()" tabIndex="-1"')?></span></td>
</tr>
<tr>
<th><?php echo $lang->entry->ip;?></th>
<td>
<div class='input-group'>
<?php echo html::input('ip', $entry->ip, "class='form-control' title='{$lang->entry->note->ip}' placeholder='{$lang->entry->note->ip}'");?>
<div class='input-group-addon'>
<label class="checkbox-inline"><input type="checkbox" id="allIP" name="allIP" value="1"><?php echo $lang->entry->note->allIP;?></label>
</div>
</div>
</td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->entry->desc;?></th>
<td><?php echo html::textarea('desc', $entry->desc, "rows='3' class='form-control'");?></td>
<td></td>
</tr>
<tr>
<th></th>
<td><?php echo html::submitButton();?></td>
<td></td>
</tr>
</table>
</form>
</div>
<?php include '../../common/view/footer.lite.html.php';?>

View File

@@ -0,0 +1,29 @@
<?php
/**
* The header view file of entry module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package entry
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<div id='featurebar'>
<ul class='nav'>
<?php
echo '<li id="entry">'; common::printLink('entry', 'browse', "", $lang->entry->common); echo '</li>';
echo '<li id="webhook">'; common::printLink('webhook', 'browse', "", $lang->entry->webhook); echo '</li>';
?>
</ul>
<div class='actions'>
<div class='btn-group'>
<div class='btn-group' id='createActionMenu'>
<?php common::printIcon('entry', 'create', '', '', 'button', '', '', 'btn-primary');?>
</div>
</div>
</div>
</div>
<script>$('#<?php echo $this->moduleName;?>').addClass('active')</script>

View File

@@ -0,0 +1,22 @@
<?php
/**
* The log view file of entry module of RanZhi.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package entry
* @version $Id$
* @link http://www.ranzhico.com
*/
?>
<?php include 'header.html.php';?>
<table class='table table-condensed table-hover table-striped'>
<thead>
<tr>
<th class='w-120px'><?php echo $lang->action->date;?></th>
<th></th>
</tr>
</thead>
</table>
<?php include '../../common/view/footer.html.php';?>

View File

@@ -0,0 +1,9 @@
<?php
$config->webhook->create = new stdclass();
$config->webhook->create->requiredFields = 'name, url';
$config->webhook->edit = new stdclass();
$config->webhook->edit->requiredFields = 'name, url';
$config->webhook->requestType['post'] = 'post';
$config->webhook->requestType['get'] = 'get';

127
module/webhook/control.php Normal file
View File

@@ -0,0 +1,127 @@
<?php
/**
* The control file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
class webhook extends control
{
/**
* Browse entries.
*
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
public function browse($orderBy = 'id_desc', $recTotal = 0, $recPerPage = 10, $pageID = 1)
{
$pager = $this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$this->view->title = $this->lang->webhook->api . $this->lang->colon . $this->lang->webhook->list;
$this->view->entries = $this->webhook->getList($orderBy, $pager);
$this->view->orderBy = $orderBy;
$this->view->pager = $pager;
$this->display();
}
/**
* Create an webhook.
*
* @access public
* @return void
*/
public function create()
{
if($_POST)
{
$webhookID = $this->webhook->create();
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->loadModel('action')->create('webhook', $webhookID, 'created');
$this->send(array('result' => 'success', 'message' => $this->lang->webhook->saveSuccess, 'locate' => inlink('browse')));
}
$this->view->title = $this->lang->webhook->api . $this->lang->colon . $this->lang->webhook->create;
$this->display();
}
/**
* Edit an webhook.
*
* @param int $webhookID
* @access public
* @return void
*/
public function edit($webhookID)
{
if($_POST)
{
$changes = $this->webhook->update($webhookID);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
if($changes)
{
$actionID = $this->loadModel('action')->create('webhook', $webhookID, 'edited');
$this->action->logHistory($actionID, $changes);
}
$this->send(array('result' => 'success', 'message' => $this->lang->webhook->saveSuccess, 'locate' => inlink('browse')));
}
$webhook = $this->webhook->getById($webhookID);
$this->view->title = $this->lang->webhook->edit . $this->lang->colon . $webhook->name;
$this->view->webhook = $webhook;
$this->display();
}
/**
* Delete an webhook.
*
* @param int $webhookID
* @access public
* @return void
*/
public function delete($webhookID)
{
$this->webhook->delete($webhookID);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->send(array('result' => 'success'));
}
public function log($webhookID)
{
$webhook = $this->webhook->getById($webhookID);
$this->view->title = $this->lang->webhook->log . $this->lang->colon . $webhook->name;
$this->view->actions = $this->loadModel('action')->getList('webhook', $webhookID);
$this->display();
}
public function actions($webhookID)
{
if($_POST)
{
$this->webhook->saveActions($webhookID);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$this->send(array('result' => 'success', 'message' => $this->lang->webhook->saveSuccess, 'locate' => inlink('browse')));
}
$webhook = $this->webhook->getById($webhookID);
$this->view->title = $this->lang->webhook->actions . $this->lang->colon . $webhook->name;
$this->view->actions = $this->webhook->getActions($webhookID);
$this->display();
}
public function ajaxGetActions($module)
{
}
}

View File

@@ -0,0 +1,31 @@
/**
* create key for an entry.
*
* @access public
* @return void
*/
function createKey()
{
var chars = '0123456789abcdefghiklmnopqrstuvwxyz'.split('');
var key = '';
for(var i = 0; i < 32; i ++)
{
key += chars[Math.floor(Math.random() * chars.length)];
}
$('#key').val(key);
return false;
}
$('#allIP').change(function()
{
if($(this).prop('checked'))
{
$('#ip').attr('disabled', 'disabled');
}
else
{
$('#ip').removeAttr('disabled');
}
})
$('#name').focus();

31
module/webhook/js/edit.js Normal file
View File

@@ -0,0 +1,31 @@
/**
* create key for an entry.
*
* @access public
* @return void
*/
function createKey()
{
var chars = '0123456789abcdefghiklmnopqrstuvwxyz'.split('');
var key = '';
for(var i = 0; i < 32; i ++)
{
key += chars[Math.floor(Math.random() * chars.length)];
}
$('#key').val(key);
return false;
}
$('#allIP').change(function()
{
if($(this).prop('checked'))
{
$('#ip').attr('disabled', 'disabled');
}
else
{
$('#ip').removeAttr('disabled');
}
})
$('#name').focus();

View File

@@ -0,0 +1,31 @@
<?php
$lang->webhook->common = 'webhook';
$lang->webhook->list = 'webhook列表';
$lang->webhook->api = '接口';
$lang->webhook->entry = '应用';
$lang->webhook->log = '日志';
$lang->webhook->action = '触发操作';
$lang->webhook->browse = '浏览webhook';
$lang->webhook->create = '添加webhook';
$lang->webhook->edit = '编辑webhook';
$lang->webhook->delete = '删除webhook';
$lang->webhook->id = 'ID';
$lang->webhook->name = '名称';
$lang->webhook->url = '请求地址';
$lang->webhook->requestType = '请求类型';
$lang->webhook->params = '参数';
$lang->webhook->desc = '描述';
$lang->webhook->createdBy = '由谁创建';
$lang->webhook->createdDate = '创建时间';
$lang->webhook->editedby = '最后编辑';
$lang->webhook->editedDate = '编辑时间';
$lang->webhook->saveSuccess = '保存成功';
$lang->webhook->confirmDelete = '您确认要删除该webhook吗';
$lang->webhook->note = new stdClass();
$lang->webhook->note->name = '授权webhook名称';
$lang->webhook->note->url = '授权webhook地址';
$lang->webhook->note->params = '参数列表,以 & 隔开';

100
module/webhook/model.php Normal file
View File

@@ -0,0 +1,100 @@
<?php
/**
* The model file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
class webhookModel extends model
{
/**
* Get an webhook by id.
*
* @param int $webhookID
* @access public
* @return array
*/
public function getById($webhookID)
{
return $this->dao->select('*')->from(TABLE_WEBHOOK)->where('id')->eq($webhookID)->fetch();
}
/**
* Get webhook list.
*
* @param string $orderBy
* @param obejct $pager
* @access public
* @return array
*/
public function getList($orderBy = 'id_desc', $pager = null)
{
return $this->dao->select('*')->from(TABLE_WEBHOOK)->orderBy($orderBy)->page($pager)->fetchAll('id');
}
/**
* Create an webhook.
*
* @access public
* @return bool | int
*/
public function create()
{
$webhook = fixer::input('post')
->add('createdBy', $this->app->user->account)
->add('createdDate', helper::now())
->get();
$this->dao->insert(TABLE_WEBHOOK)->data($webhook)
->batchCheck($this->config->webhook->create->requiredFields, 'notempty')
->autoCheck()
->exec();
if(dao::isError()) return false;
return $this->dao->lastInsertId();
}
/**
* Update an webhook.
*
* @param int $webhookID
* @access public
* @return bool | array
*/
public function update($webhookID)
{
$oldEntry = $this->getById($webhookID);
$webhook = fixer::input('post')
->add('editedBy', $this->app->user->account)
->add('editedDate', helper::now())
->get();
$this->dao->update(TABLE_WEBHOOK)->data($webhook)
->batchCheck($this->config->webhook->edit->requiredFields, 'notempty')
->autoCheck()
->where('id')->eq($webhookID)
->exec();
if(dao::isError()) return false;
return common::createChanges($oldEntry, $webhook);
}
/**
* Delete an webhook.
*
* @param int $webhookID
* @param int $null
* @access public
* @return bool
*/
public function delete($webhookID, $null = null)
{
$this->dao->delete()->from(TABLE_WEBHOOK)->where('id')->eq($webhookID)->exec();
return !dao::isError();
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* The browse view file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include 'header.html.php';?>
<?php js::set('confirmDelete', $lang->webhook->confirmDelete);?>
<form id='ajaxForm' method='post'>
<table id='webhookList' class='table table-condensed table-hover table-striped tablesorter'>
<thead>
<tr>
<?php $vars = "orderBy=%s&recTotal=$pager->recTotal&recPerPage=$pager->recPerPage&pageID=$pager->pageID";?>
<th class='w-80px'><?php common::printOrderLink('id', $orderBy, $vars, $lang->webhook->id);?></th>
<th class='w-200px'><?php common::printOrderLink('name', $orderBy, $vars, $lang->webhook->name);?></th>
<th class='w-200px'><?php common::printOrderLink('url', $orderBy, $vars, $lang->webhook->url);?></th>
<th class='w-100px'><?php common::printOrderLink('requestType', $orderBy, $vars, $lang->webhook->requestType);?></th>
<th class='w-200px'><?php common::printOrderLink('params', $orderBy, $vars, $lang->webhook->params);?></th>
<th><?php echo common::printOrderLink('desc', $orderBy, $vars, $lang->webhook->desc);?></th>
<th class='w-100px'><?php echo html::a('###', $lang->actions);?></th>
</tr>
</thead>
<tbody>
<?php foreach($entries as $webhook):?>
<tr>
<td class='text-center'><?php echo $webhook->id;?></td>
<td title='<?php echo $webhook->name;?>'><?php echo $webhook->name;?></td>
<td><?php echo $webhook->url;?></td>
<td title='<?php echo $webhook->requestType;?>'><?php echo $webhook->requestType;?></td>
<td title='<?php echo $webhook->params;?>'><?php echo $webhook->params;?></td>
<td title='<?php echo $webhook->desc;?>'><?php echo $webhook->desc;?></td>
<td class='text-right'>
<?php
common::printIcon('webhook', 'log', "webhookID=$webhook->id", '', 'list', 'file-text-o');
common::printIcon('webhook', 'action', "webhookID=$webhook->id", '', 'list', 'cog');
common::printIcon('webhook', 'edit', "webhookID=$webhook->id", '', 'list');
if(common::hasPriv('webhook', 'delete'))
{
$deleteURL = $this->createLink('webhook', 'delete', "webhookID=$webhook->id&confirm=yes");
echo html::a("javascript:ajaxDelete(\"$deleteURL\",\"webhookList\",confirmDelete)", '<i class="icon-remove"></i>', '', "title='{$lang->webhook->delete}' class='btn-icon'");
}
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan='7'><?php $pager->show();?></td>
</tr>
</tfoot>
</table>
</form>
<?php include '../../common/view/footer.html.php';?>

View File

@@ -0,0 +1,55 @@
<?php
/**
* The create view file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/form.html.php';?>
<div class='container mw-800px'>
<div id="titlebar">
<div class="heading">
<strong><?php echo $lang->webhook->api;?></strong>
<small class="text-muted"> <?php echo $lang->webhook->create;?> <i class="icon-pencil"></i></small>
</div>
</div>
<form id='webhookForm' method='post' class='ajaxForm'>
<table class='table table-form'>
<tr>
<th class='w-80px'><?php echo $lang->webhook->name;?></th>
<td><?php echo html::input('name', '', "class='form-control' placeholder='{$lang->webhook->note->name}'");?></td>
<td class='w-120px'></td>
</tr>
<tr>
<th><?php echo $lang->webhook->url;?></th>
<td><?php echo html::input('url', '', "class='form-control' placeholder='{$lang->webhook->note->url}'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->webhook->requestType;?></th>
<td><?php echo html::select('requestType', $config->webhook->requestType, '', "class='form-control'");?></td>
</tr>
<tr>
<th><?php echo $lang->webhook->params;?></th>
<td><?php echo html::input('params', '', "class='form-control' title='{$lang->webhook->note->params}' placeholder='{$lang->webhook->note->params}'");?></td>
</tr>
<tr>
<th><?php echo $lang->webhook->desc;?></th>
<td><?php echo html::textarea('desc', '', "rows='3' class='form-control'");?></td>
<td></td>
</tr>
<tr>
<th></th>
<td><?php echo html::submitButton();?></td>
<td></td>
</tr>
</table>
</form>
</div>
<?php include '../../common/view/footer.lite.html.php';?>

View File

@@ -0,0 +1,55 @@
<?php
/**
* The edit view file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/form.html.php';?>
<div class='container mw-800px'>
<div id="titlebar">
<div class="heading">
<strong><?php echo $lang->webhook->api;?></strong>
<small class="text-muted"> <?php echo $lang->webhook->edit;?> <i class="icon-pencil"></i></small>
</div>
</div>
<form id='webhookForm' method='post' class='ajaxForm'>
<table class='table table-form'>
<tr>
<th class='w-80px'><?php echo $lang->webhook->name;?></th>
<td><?php echo html::input('name', $webhook->name, "class='form-control' placeholder='{$lang->webhook->note->name}'");?></td>
<td class='w-120px'></td>
</tr>
<tr>
<th><?php echo $lang->webhook->url;?></th>
<td><?php echo html::input('url', $webhook->url, "class='form-control' placeholder='{$lang->webhook->note->url}'");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->webhook->requestType;?></th>
<td><?php echo html::select('requestType', $config->webhook->requestType, $webhook->requestType, "class='form-control'");?></td>
</tr>
<tr>
<th><?php echo $lang->webhook->params;?></th>
<td><?php echo html::input('params', $webhook->params, "class='form-control' title='{$lang->webhook->note->params}' placeholder='{$lang->webhook->note->params}'");?></td>
</tr>
<tr>
<th><?php echo $lang->webhook->desc;?></th>
<td><?php echo html::textarea('desc', $webhook->desc, "rows='3' class='form-control'");?></td>
<td></td>
</tr>
<tr>
<th></th>
<td><?php echo html::submitButton();?></td>
<td></td>
</tr>
</table>
</form>
</div>
<?php include '../../common/view/footer.lite.html.php';?>

View File

@@ -0,0 +1,29 @@
<?php
/**
* The header view file of webhook module of ZenTaoPMS.
*
* @copyright Copyright 2009-2017 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
* @license ZPL (http://zpl.pub/page/zplv12.html)
* @author Gang Liu <liugang@cnezsoft.com>
* @package webhook
* @version $Id$
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<div id='featurebar'>
<ul class='nav'>
<?php
echo '<li id="entry">'; common::printLink('entry', 'browse', "", $lang->webhook->entry); echo '</li>';
echo '<li id="webhook">'; common::printLink('webhook', 'browse', "", $lang->webhook->common); echo '</li>';
?>
</ul>
<div class='actions'>
<div class='btn-group'>
<div class='btn-group' id='createActionMenu'>
<?php common::printIcon('webhook', 'create', '', '', 'button', '', '', 'btn-primary');?>
</div>
</div>
</div>
</div>
<script>$('#<?php echo $this->moduleName;?>').addClass('active')</script>