表结构 /phpcms/modules/content/workflow.php表的结构
批量审时的权限判断
`v9_workflow`--CREATE TABLE IF NOT EXISTS `v9_workflow` (`workflowid` smallint(5) unsigned NOT NULL, `siteid` smallint(5) unsigned NOT NULL DEFAULT '0', `steps` tinyint(1) unsigned NOT NULL DEFAULT '1', `workname` varchar(20) NOT NULL, `description` varchar(255) NOT NULL, `setting` text NOT NULL, `flag` tinyint(1) unsigned NOT NULL DEFAULT '0') ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
</pre><pre name="code" class="php">---- 转存表中的数据 `v9_workflow`--INSERT INTO `v9_workflow` (`workflowid`, `siteid`, `steps`, `workname`, `description`, `setting`, `flag`) VALUES(1, 1, 1, '一级审核', '审核一次', '', 0),(2, 1, 2, '我的某栏目二级审核', '审核两次33333', 'array ( 1 => '''', 2 => array ( 0 => ''phpcms2'', ), 3 => '''', 4 => '''', ''nocheck_users'' => array ( 0 => ''phpcms3'', ),)', 1),(3, 1, 3, '三级审核', '审核三次', '', 0),(4, 1, 4, '四级审核', '四级审核', '', 0);
public function add() {
if(isset($_POST['dosubmit'])) {
$_POST['info']['siteid'] = $this->siteid;
$_POST['info']['workname'] = safe_replace($_POST['info']['workname']);
$setting[1] = $_POST['checkadmin1'];
$setting[2] = $_POST['checkadmin2'];
$setting[3] = $_POST['checkadmin3'];
$setting[4] = $_POST['checkadmin4'];
$setting['nocheck_users'] = $_POST['nocheck_users'];
$setting = array2string($setting);
$_POST['info']['setting'] = $setting;
$this->db->insert($_POST['info']);
$this->cache();
showmessage(L('add_success'));
} else {
文章后台管理时的权限判断 /phpcms/modules/content/content.php
//查询当前的工作流
$setting = string2array($category['setting']);
$workflowid = $setting['workflowid'];
$workflows = getcache('workflow_'.$this->siteid,'commons');
$workflows = $workflows[$workflowid];
$workflows_setting = string2array($workflows['setting']);
//将有权限的级别放到新数组中
$admin_privs = array();
foreach($workflows_setting as $_k=>$_v) {
if(empty($_v)) continue;
foreach($_v as $_value) {
if($_value==$admin_username) $admin_privs[$_k] = $_k;
}
}
//工作流审核级别
$workflow_steps = $workflows['steps'];
$workflow_menu = '';
$steps = isset($_GET['steps']) ? intval($_GET['steps']) : 0;
//工作流权限判断
if($_SESSION['roleid']!=1 && $steps && !in_array($steps,$admin_privs)) showmessage(L('permission_to_operate'));
for($i=1;$i<=$workflow_steps;$i++) {
if($_SESSION['roleid']!=1 && !in_array($i,$admin_privs)) continue;
$current = $steps==$i ? 'class=on' : '';
$r = $this->db->get_one(array('catid'=>$catid,'status'=>$i));
$newimg = $r ? '<img src="'.IMG_PATH.'icon/new.png" style="padding-bottom:2px" οnclick="window.location.href=\'?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&steps='.$i.'&pc_hash='.$pc_hash.'\'">' : '';
$workflow_menu .= '<a href="?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&steps='.$i.'&pc_hash='.$pc_hash.'" '.$current.' ><em>'.L('workflow_'.$i).$newimg.'</em></a><span>|</span>';
}
if($workflow_menu) {
$current = isset($_GET['reject']) ? 'class=on' : '';
$workflow_menu .= '<a href="?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&pc_hash='.$pc_hash.'&reject=1" '.$current.' ><em>'.L('reject').'</em></a><span>|</span>';
}
/**
* 过审内容
*/
public function pass() {
$admin_username = param::get_cookie('admin_username');
$catid = intval($_GET['catid']);
if(!$catid) showmessage(L('missing_part_parameters'));
$category = $this->categorys[$catid];
$setting = string2array($category['setting']);
$workflowid = $setting['workflowid'];
//只有存在工作流才需要审核
if($workflowid) {
$steps = intval($_GET['steps']);
//检查当前用户有没有当前工作流的操作权限
$workflows = getcache('workflow_'.$this->siteid,'commons');
$workflows = $workflows[$workflowid];
$workflows_setting = string2array($workflows['setting']);
//将有权限的级别放到新数组中
$admin_privs = array();
foreach($workflows_setting as $_k=>$_v) {
if(empty($_v)) continue;
foreach($_v as $_value) {
if($_value==$admin_username) $admin_privs[$_k] = $_k;
}
}
if($_SESSION['roleid']!=1 && $steps && !in_array($steps,$admin_privs)) showmessage(L('permission_to_operate'));
//更改内容状态
if(isset($_GET['reject'])) {
//退稿
$status = 0;
} else {
//工作流审核级别
$workflow_steps = $workflows['steps'];
if($workflow_steps>$steps) {
$status = $steps+1;
} else {
$status = 99;
}
}
批量审时的权限判断
if($status!=0 && !$super_admin) {
//以栏目进行循环
foreach ($this->categorys as $catid => $cat) {
if($cat['type']!=0) continue;
//查看管理员是否有这个栏目的查看权限。
if (!$this->priv_db->get_one(array('catid'=>$catid, 'siteid'=>$this->siteid, 'roleid'=>$_SESSION['roleid'], 'is_admin'=>'1'))) {
continue;
}
//如果栏目有设置工作流,进行权限检查。
$workflow = array();
$cat['setting'] = string2array($cat['setting']);
if (isset($cat['setting']['workflowid']) && !empty($cat['setting']['workflowid'])) {
$workflow = $workflows[$cat['setting']['workflowid']];
$workflow['setting'] = string2array($workflow['setting']);
$usernames = $workflow['setting'][$status];
if (empty($usernames) || !in_array($admin_username, $usernames)) {//判断当前管理,在工作流中可以审核几审
continue;
}
}
$priv_catid[] = $catid;
}
前台投稿时判断
//判断会员组投稿是否需要审核
if($grouplist[$memberinfo['groupid']]['allowpostverify'] || !$setting['workflowid']) {
$info['status'] = 99;
} else {
$info['status'] = 1;
}
semoa中的流程审批设计:
1、栏目设置时的工作流字段:
审批人:1001,1002|2001,2002|, 同一级审批人为多人时用逗号分隔,插入flow_log时同时记多条记录。 另还可以按 部门-职位,保存时为DPT-01-02这种编号形式,稍显麻烦,不用。
2、单条文章添加时,在flow_log表中生成待审记录,用于通知待审和记录审批情况:
对应记录 审批人ID及姓名、当前步骤step、审批结果result(1通过、0不通过、-1退回)、审批意见comment、isread(抄送时用)
其中有一人已审时,更新审批状态。并删除同一步骤下的其他人的记录,以免他人重复操作。
这种审批流程的设计,适合OA中多样、多变的业务流程,无须预先设置审批权限,完全靠流程设置来确定。