Commit 0cc5205e authored by Krzysztof Kutt's avatar Krzysztof Kutt
Browse files

integracja z Activiti (by Dariusz Tarczynski)

parent 93bac6ea
<?php
/*
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Jason Grout <jason-doku@creativetrax.com>>
*
* Modifications by Sergio (1 Apr 2007), an unidentified author,
* and Niko Paltzer (15 Jan 2010).
*
* brought up-to-date with current Dokuwiki Event changes
* and event handling by Myron Turner (April 7 2011);
* new security features (September 2 2011)
* turnermm02@shaw.ca
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
/* We have to distinguish between the plugin being loaded and the plugin
actually being used for authentication. */
$active = ( $conf['authtype'] == 'tasklist' );
class action_plugin_tasklist extends DokuWiki_Action_Plugin {
public function __construct() {
global $conf;
}
function skip_login_action(&$event, $param) {
if ($event->data == 'login') {
act_redirect($ID, 'show');
}
}
var $done = false;
var $allow = true;
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Jason Grout, Myron Turner',
'email' => 'jason-doku@creativetrax.com',
'date' => '2007-02-24',
'name' => 'newpagetemplate',
'desc' => 'Loads into the new page creation box a template specified in the $_REQUEST "newpagetemplate" parameter (i.e., can be passed in the URL or as a form value).',
'url' => '',
);
}
/**
* register the eventhandlers
* Modified by
* @author Myron Turner
* turnermm02@shaw.ca
*/
function register(&$contr){
$contr->register_hook('COMMON_PAGE_FROMTEMPLATE', 'BEFORE', $this, 'pagefromtemplate', array());
$contr->register_hook('COMMON_PAGETPL_LOAD', 'BEFORE', $this, 'pagefromtemplate', array());
$contr->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'check_acl', array());
$contr->register_hook('TPL_CONTENT_DISPLAY', 'BEFORE', $this, 'write_msg', array());
$contr->register_hook('HTML_PAGE_FROMTEMPLATE', 'BEFORE', $this, 'pagefromtemplate', array());
if ($active) {
$contr->register_hook('ACTION_ACT_PREPROCESS', 'AFTER', $this, 'skip_login_action', NULL);
}
}
/**
* pagefromtemplate
* Modified by
* @author Myron Turner
* turnermm02@shaw.ca
*/
function pagefromtemplate(&$event, $param) {
if($this->done) return;
$this->done=true;
if(strlen(trim($_REQUEST['newpagetemplate']))>0) {
if(!$this->allow) {
return ;
}
global $conf;
global $INFO;
global $ID;
$tpl = io_readFile(wikiFN($_REQUEST['newpagetemplate']));
if($this->getConf('userreplace')) {
$stringvars =
array_map(create_function('$v', 'return explode(",",$v,2);'),
explode(';',$_REQUEST['newpagevars']));
foreach($stringvars as $value) {
$tpl = str_replace(trim($value[0]),hsc(trim($value[1])),$tpl);
}
}
if($this->getConf('standardreplace')) {
// replace placeholders
$file = noNS($ID);
$page = cleanID($file) ;
if($this->getConf('prettytitles')) {
$title= str_replace('_',' ',$page);
}
else {
$title = $page;
}
$tpl = str_replace(array(
'@ID@',
'@NS@',
'@FILE@',
'@!FILE@',
'@!FILE!@',
'@PAGE@',
'@!PAGE@',
'@!!PAGE@',
'@!PAGE!@',
'@USER@',
'@NAME@',
'@MAIL@',
'@DATE@',
'@EVENT@'
),
array(
$ID,
getNS($ID),
$file,
utf8_ucfirst($file),
utf8_strtoupper($file),
$page,
utf8_ucfirst($title),
utf8_ucwords($title),
utf8_strtoupper($title),
$_SERVER['REMOTE_USER'],
$INFO['userinfo']['name'],
$INFO['userinfo']['mail'],
$conf['dformat'],
$event->name ,
), $tpl);
// we need the callback to work around strftime's char limit
$tpl = preg_replace_callback('/%./',create_function('$m','return strftime($m[0]);'),$tpl);
}
if($event->name == 'HTML_PAGE_FROMTEMPLATE') {
$event->result=$tpl;
}
else {
$event->data['tpl'] = $tpl;
}
$event->preventDefault();
}
}
function check_acl(&$event,$param) {
if(strlen(trim($_REQUEST['newpagetemplate']))>0) {
$pg = trim($_REQUEST['newpagetemplate'],':');
$auth =auth_quickaclcheck($pg);
if($auth < 4) $this->allow = false;
}
}
function write_msg (&$event,$param) {
if($this->allow) return;
global $ID;
echo"<h1> Permission Denied </h1>";
echo "You do not have access to the template " . $_REQUEST['newpagetemplate'] . '</br>';
unlock($ID);
$event->preventDefault();
}
}
<?php
if(!defined('DOKU_INC')) die();
class auth_plugin_tasklist extends DokuWiki_Auth_Plugin {
/**
* Constructor.
*/
public function __construct() {
global $conf;
parent::__construct();
}
public function checkPass($user, $pass) {
$userinfo = $this->getUserData($user);
if($userinfo === false) return false;
$_SESSION[DOKU_COOKIE]['task']["user"]=$user;
$_SESSION[DOKU_COOKIE]['task']["pass"]=$pass;
$myusername=$user;
$mypassword=$pass;
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$params = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".$myusername.":".$mypassword."@localhost:8080/activiti-rest/service/runtime/tasks");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
echo $response;
if (!empty($response))
{
$params = json_decode($response, true);
if (!isset($params["errorMessage"]))
{
session_start();
$_SESSION["myusername"]=$myusername;
$_SESSION["mypassword"]=$mypassword;
return true;
}else
return false;
}
}
public function getUserData($user) {
global $conf;
$info['name'] = $user;
$info['mail'] = $user."@".$this->emaildomain;
if ($info['name']=='kermit') $info['grps'] = array('admin','user'); else $info['grps'] = array('user');
return $info;
}
}
<?php
$conf['standardreplace']=1;
$conf['userreplace']=1;
$conf['prettytitles']=0;
<?php
$meta['userreplace'] = array('onoff');
$meta['standardreplace'] = array('onoff');
$meta['prettytitles'] = array('onoff');
base tasklist
author Dariusz Tarczyski
email dariusz.tarczynski@gmail.com
date 2005-07-28
name Activiti Tasklist Plugin
desc Show tasklist of activiti
\ No newline at end of file
<?php
/**
* Plugin tasklist: Inserts an activiti tasklist.
*
*/
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_tasklist extends DokuWiki_Syntax_Plugin {
public function getType() { return 'substition'; }
public function getSort() { return 32; }
public function connectTo($mode) {
$this->Lexer->addSpecialPattern('\[tasklist\]',$mode,'plugin_tasklist');
$this->Lexer->addSpecialPattern('\[task.*?\]',$mode,'plugin_tasklist');
}
public function handle($match, $state, $pos, Doku_Handler &$handler) {
return array($match, $state, $pos);
}
public function render($mode, Doku_Renderer &$renderer, $data) {
// $data is what the function handle return'ed.
// $renderer->doc .='<h1>1</h1>';
if($mode == 'xhtml'){
if ($data[0] == '[tasklist]')
{
/** @var Doku_Renderer_xhtml $renderer */
// $renderer->doc .= date('r');
$renderer->doc .= ' <h2>Twoje obecne zadania</h2>
<table class="table">
<thead>
<tr>
<th>id</th>
<th>nazwa</th>
<th>data utworzenia</th>
<th>deadline</th>
<th>priorytet</th>
</tr>
</thead>
<tbody>';
$params = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://kermit:kermit@localhost:8080/activiti-rest/service/runtime/tasks?size=9999");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if (!empty($response))
{
$params = json_decode($response, true);
//var_dump($params['data']);
for ($i=0; $i<count($params['data']); $i++)
{
$renderer->doc .= '<tr>';
$renderer->doc .= '<td>'.($params['data'][$i]["id"]).'</td>';
$renderer->doc .= '<td>'.($params['data'][$i]["name"]).'</td>';
$renderer->doc .= '<td>'.($params['data'][$i]["createTime"]).'</td>';
$renderer->doc .= '<td>'.($params['data'][$i]["dueDate"]).'</td>';
$renderer->doc .= '<td>'.($params['data'][$i]["priority"]).'</td>';
$renderer->doc .= '<td><a href="doku.php?id=:taskdetails'.$params['data'][$i]["id"].'&do=edit&rev=&newpagetemplate=:pageteplates:details&newpagevars=@ID@,'.$params['data'][$i]["id"].'"><button type="button" class="btn btn-xs btn-success">Szczegóły</button></a></td>';
$renderer->doc .= '</tr>';
}
}
$renderer->doc .= ' </tbody>
</table>';
return true;
}else
{
global $INPUT;
//$renderer->doc .='<h1>2</h1>'.var_dump($INPUT);
$id = substr($data[0],6);//'[tasklist]'
$id = substr($id,0,strlen($id)-1);
$TASKINFO=null;
$params = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://kermit:kermit@localhost:8080/activiti-rest/service/runtime/tasks/".$id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
$response = curl_exec($ch);
if (!empty($response))
{
$params = json_decode($response, true);
$TASKINFO = $params;
}
if (($INPUT->str('idd'))!=null)
{
//$renderer->doc .='<h1>3</h1>';
if ($TASKINFO["assignee"]=='kermit')// user is asigned so we are closing the task
{
$params = array();
$ch = curl_init();
$variables=array();
foreach ($_REQUEST as $key => $value)
{
if ($key!="idd")
{
$variables[$key]=$value;
}
}
$data = $variables;
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_URL, "http://kermit:kermit@localhost:8080/activiti-rest/service/task/".$_REQUEST["idd"]."/complete");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$response = curl_exec($ch);
if (!empty($response))
{
//$renderer->doc .='<h1>4</h1>';
$_SESSION[DOKU_COOKIE]['task']["info"]="closed";
$params = json_decode($response, true);
$renderer->doc .= $response;
}
//header("location:doku.php?id=taskdetails".$INPUT->str('idd'));
} else { //lets assign the user to this task
$params = array();
$ch = curl_init();
$username = 'kermit';
$data = array("action"=>"delegate", "assignee" => $username);
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_URL, "http://kermit:kermit@localhost:8080/activiti-rest/service/runtime/tasks/".$_REQUEST["idd"]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$response = curl_exec($ch);
if (!empty($response))
{
$params = json_decode($response, true);
if ($params['statusCode']=='404')
{
$_SESSION[DOKU_COOKIE]['task']["info"]="404";
}
else
{
$_SESSION[DOKU_COOKIE]['task']["info"]="ok";
}
}
}
}
echo 'USER: '.$_SESSION[DOKU_COOKIE]['task']["user"];
if ($_SESSION[DOKU_COOKIE]['task']["info"]=="ok") echo '<div class="alert alert-success">
<strong>OK!</strong> Operacja przebiegła pomyślnie.
</div>';
if ($_SESSION[DOKU_COOKIE]['task']["info"]=="closed"){ echo '<h1>Zadanie zamknięte</h1>'; return;}
if ($_SESSION[DOKU_COOKIE]['task']["info"]=="404"){ echo '<h1>Zadanie nie istnieje</h1>'; return;}
//$renderer->doc .='<h1>5</h1>';
$TASKINFO=null;
$params = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://kermit:kermit@localhost:8080/activiti-rest/service/runtime/tasks/".$id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
$response = curl_exec($ch);
if (!empty($response))
{
$params = json_decode($response, true);
$TASKINFO = $params;
}
$renderer->doc .= ' <h3>Tytuł:</h3><h2>'.$TASKINFO["name"].'</h2>
<h4>Stworzony: '.$TASKINFO["createTime"].' <br/>Deadline: '.$TASKINFO["dueDate"].'</h4>
<p>&nbsp;</p>
<h4>Obraz:</h4>
<img src="http://localhost:8080/activiti-rest/service/process-instance/'.$TASKINFO["processInstanceId"].'/diagram" >
<div class="table-responsive">
<h3>Zmienne przypisane do zadania:</h3>
<table class="table">
<thead>
<tr>
<th>nazwa</th>
<th>wartość</th>
</tr>
</thead>
<tbody>';
$params = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://kermit:kermit@localhost:8080/activiti-rest/service/runtime/tasks/".$id."/variables");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
$response = curl_exec($ch);
if (!empty($response))
{
$params = json_decode($response, true);
for ($i=0; $i<count($params); $i++)
{
$renderer->doc .= '<tr>';
$renderer->doc .= '<td>'.$params[$i]["name"].'</td>';
$renderer->doc .= '<td>'.$params[$i]["value"].'</td>';
$renderer->doc .= '</tr>';
}
}
//header("location:tasks.php");
$renderer->doc .= '</tbody>
</table>
</div>';
$renderer->doc .= '<form action="doku.php" method="GET">
<h3>Formularz:</h3>
<input type="hidden" name="id" value="taskdetails'.$id.'"/>
<input type="hidden" name="idd" value="'.$id.'"/>';
$params = array();
$ch = curl_init();
$data = array("action" => "complete");
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_URL, "http://kermit:kermit@localhost:8080/activiti-rest/service/form/form-data?taskId=".$id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
$response = curl_exec($ch);
if (!empty($response))
{
$params = json_decode($response, true);
for ($i=0; $i<count($params["formProperties"]); $i++)
{
$renderer->doc .= '<tr>';
$renderer->doc .= '<td>'.($params["formProperties"][$i]["name"]).'</td>';
$renderer->doc .= '<td>';
switch ($params["formProperties"][$i]["type"])
{
case "boolean":
$renderer->doc .= $params["formProperties"][$i]["value"];
$renderer->doc .= '<div class="btn-group" data-toggle="buttons">
<label>
<input type="radio" name="'.$params["formProperties"][$i]["id"].'" id="'.$params["formProperties"][$i]["id"].'" value="True" ';
if ($params["formProperties"][$i]["value"]=="True") $renderer->doc .= 'checked';
$renderer->doc .= '>True</label>
<label>
<input type="radio" name="'.$params["formProperties"][$i]["id"].'" id="'.$params["formProperties"][$i]["id"].'" value="False" ';
if ($params["formProperties"][$i]["value"]=="False") $renderer->doc .= 'checked';
$renderer->doc .= '>False</label>
</div>';
break;
default:
$renderer->doc .= $params["formProperties"][$i]["type"]=="True";
break;
}
$renderer->doc .= '</td>';
$renderer->doc .= '</tr>';
}
}
$renderer->doc .= '<h3>Akcje:</h3>'; //$id = $_REQUEST["id"];
if ($TASKINFO["assignee"]!='kermit') {
$renderer->doc .= '<button type="submit" class="btn btn-success">Weź to zadanie</button>';
} else {
$renderer->doc .= '<button type="submit" class="btn btn-success">Potwierdź wykonanie</button>';
}
$renderer->doc .= '</form>';
}
}
return false;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment