2019-11-04 15:22:11 +00:00
< ? php
2020-08-20 16:30:16 +00:00
2019-11-04 15:22:11 +00:00
/**
* Project :
* Contenido Content Management System
*
* Description :
* Workflow management class
*
* Requirements :
* @ con_php_req 5.0
*
*
* @ package Contenido Backend classes
* @ version 1.3
* @ author Timo Hummel
* @ copyright four for business AG < www . 4 fb . de >
* @ license http :// www . contenido . org / license / LIZENZ . txt
* @ link http :// www . 4 fb . de
* @ link http :// www . contenido . org
*
* { @ internal
* created 2003 - 07 - 18
*
* $Id : class . workflowusersequence . php 128 2019 - 07 - 03 11 : 58 : 28 Z oldperl $
* }}
*
*/
2020-08-20 16:30:16 +00:00
if ( ! defined ( 'CON_FRAMEWORK' )) {
die ( 'Illegal call' );
2019-11-04 15:22:11 +00:00
}
/**
* Class WorkflowUserSequences
* Class for workflow user sequence management
* @ author Timo A . Hummel < Timo . Hummel @ 4 fb . de >
* @ version 0.2
* @ copyright four for business 2003
*/
class WorkflowUserSequences extends ItemCollection {
2020-08-20 16:30:16 +00:00
/**
2019-11-04 15:22:11 +00:00
* Constructor Function
* @ param string $table The table to use as information source
*/
2020-08-20 16:30:16 +00:00
function __construct () {
global $cfg ;
parent :: __construct ( $cfg [ " tab " ][ " workflow_user_sequences " ], " idusersequence " );
2019-11-04 15:22:11 +00:00
$this -> _setItemClass ( " WorkflowUserSequence " );
2020-08-20 16:30:16 +00:00
}
2019-11-04 15:22:11 +00:00
/** @deprecated [2011-03-15] Old constructor function for downwards compatibility */
2020-08-20 16:30:16 +00:00
function WorkflowUserSequences () {
2019-11-04 15:22:11 +00:00
cWarning ( __FILE__ , __LINE__ , " Deprecated method call, use __construct() " );
$this -> __construct ();
}
2020-08-20 16:30:16 +00:00
function delete ( $id ) {
2019-11-04 15:22:11 +00:00
global $cfg , $idworkflow ;
2020-08-20 16:30:16 +00:00
$item = new WorkflowUserSequence ;
$item -> loadByPrimaryKey ( $id );
$pos = $item -> get ( " position " );
$idworkflowitem = $item -> get ( " idworkflowitem " );
$this -> select ( " position > $pos AND idworkflowitem = ' " . Contenido_Security :: escapeDB ( $idworkflowitem , NULL ) . " ' " );
while ( $obj = $this -> next ()) {
$pos = $obj -> get ( " position " ) - 1 ;
$obj -> setPosition ( $pos );
$obj -> store ();
}
2019-11-04 15:22:11 +00:00
parent :: delete ( $id );
2020-08-20 16:30:16 +00:00
2019-11-04 15:22:11 +00:00
$this -> updateArtAllocation ( $id );
2020-08-20 16:30:16 +00:00
}
function updateArtAllocation ( $idusersequence ) {
2019-11-04 15:22:11 +00:00
global $idworkflow , $cfg ;
$oDb = new DB_ConLite ();
2020-08-20 16:30:16 +00:00
2019-11-04 15:22:11 +00:00
$aIdArtLang = array ();
2020-08-20 16:30:16 +00:00
$sSql = 'SELECT idartlang FROM ' . $cfg [ " tab " ][ " workflow_art_allocation " ] . ' WHERE idusersequence = ' . Contenido_Security :: escapeDB ( $idusersequence , $oDb ) . ';' ;
2019-11-04 15:22:11 +00:00
$oDb -> query ( $sSql );
while ( $oDb -> next_record ()) {
array_push ( $aIdArtLang , $oDb -> f ( 'idartlang' ));
}
2020-08-20 16:30:16 +00:00
$sSql = 'DELETE FROM ' . $cfg [ " tab " ][ " workflow_art_allocation " ] . ' WHERE idusersequence = ' . Contenido_Security :: escapeDB ( $idusersequence , $oDb ) . ';' ;
2019-11-04 15:22:11 +00:00
$oDb -> query ( $sSql );
2020-08-20 16:30:16 +00:00
2019-11-04 15:22:11 +00:00
foreach ( $aIdArtLang as $iIdArtLang ) {
setUserSequence ( $iIdArtLang , $idworkflow );
2020-08-20 16:30:16 +00:00
}
}
function create ( $idworkflowitem ) {
global $auth , $client , $idworkflow ;
$newitem = parent :: createNewItem ();
$workflowitems = new WorkflowItems ;
if ( ! $workflowitems -> exists ( $idworkflowitem )) {
$this -> delete ( $newitem -> getField ( " idusersequence " ));
$this -> lasterror = i18n ( " Workflow item doesn't exist. Can't create entry. " , " workflow " );
return false ;
}
$this -> select ( " idworkflowitem = ' " . Contenido_Security :: escapeDB ( $idworkflowitem , NULL ) . " ' " , " " , " position DESC " , " 1 " );
$item = $this -> next ();
if ( $item === false ) {
$lastPos = 1 ;
} else {
$lastPos = $item -> getField ( " position " ) + 1 ;
}
$newitem -> setWorkflowItem ( $idworkflowitem );
$newitem -> setPosition ( $lastPos );
$newitem -> store ();
return ( $newitem );
2019-11-04 15:22:11 +00:00
}
2020-08-20 16:30:16 +00:00
function swap ( $idworkflowitem , $pos1 , $pos2 ) {
$this -> select ( " idworkflowitem = ' $idworkflowitem ' AND position = ' " . Contenido_Security :: escapeDB ( $pos1 , NULL ) . " ' " );
if (( $item = $this -> next ()) === false ) {
$this -> lasterror = i18n ( " Swapping items failed: Item doesn't exist " , " workflow " );
return false ;
}
$pos1ID = $item -> getField ( " idusersequence " );
$this -> select ( " idworkflowitem = ' $idworkflowitem ' AND position = ' " . Contenido_Security :: escapeDB ( $pos2 , NULL ) . " ' " );
if (( $item = $this -> next ()) === false ) {
$this -> lasterror ( i18n ( " Swapping items failed: Item doesn't exist " , " workflow " ));
return false ;
}
$pos2ID = $item -> getField ( " idusersequence " );
$item = new WorkflowUserSequence ();
$item -> loadByPrimaryKey ( $pos1ID );
$item -> setPosition ( $pos2 );
$item -> store ();
$item -> loadByPrimaryKey ( $pos2ID );
$item -> setPosition ( $pos1 );
$item -> store ();
2019-11-04 15:22:11 +00:00
$this -> updateArtAllocation ( $pos2ID );
$this -> updateArtAllocation ( $pos1ID );
2020-08-20 16:30:16 +00:00
return ( true );
}
2019-11-04 15:22:11 +00:00
}
/**
* Class WorkflowUserSequence
* Class for a single workflow item
* @ author Timo A . Hummel < Timo . Hummel @ 4 fb . de >
* @ version 0.1
* @ copyright four for business 2003
*/
class WorkflowUserSequence extends Item {
2020-08-20 16:30:16 +00:00
/**
2019-11-04 15:22:11 +00:00
* Constructor Function
* @ param string $table The table to use as information source
*/
2020-08-20 16:30:16 +00:00
function __construct () {
global $cfg ;
parent :: __construct ( $cfg [ " tab " ][ " workflow_user_sequences " ], " idusersequence " );
}
2019-11-04 15:22:11 +00:00
/** @deprecated [2011-03-15] Old constructor function for downwards compatibility */
2020-08-20 16:30:16 +00:00
function WorkflowUserSequence () {
2019-11-04 15:22:11 +00:00
cWarning ( __FILE__ , __LINE__ , " Deprecated method call, use __construct() " );
$this -> __construct ();
}
2020-08-20 16:30:16 +00:00
/**
2019-11-04 15:22:11 +00:00
* Override setField Function to prevent that somebody modifies
2020-08-20 16:30:16 +00:00
* idsequence .
2019-11-04 15:22:11 +00:00
* @ param string $field Field to set
* @ param string $valie Value to set
*/
2020-08-20 16:30:16 +00:00
function setField ( $field , $value , $bSafe = true ) {
global $cfg ;
switch ( $field ) {
case " idworkflowitem " :
die ( " Please use create to modify idsequence. Direct modifications are not allowed " );
case " idusersequence " :
die ( " Please use create to modify idsequence. Direct modifications are not allowed " );
case " position " :
die ( " Please use create and swap to set the position. Direct modifications are not allowed " );
case " iduser " :
if ( $value != 0 ) {
$db = new DB_ConLite ;
$sql = " SELECT user_id FROM " . $cfg [ " tab " ][ " phplib_auth_user_md5 " ] .
" WHERE user_id = ' " . Contenido_Security :: escapeDB ( $value , $db ) . " ' " ;
$db -> query ( $sql );
if ( ! $db -> next_record ()) {
$sql = " SELECT group_id FROM " . $cfg [ " tab " ][ " groups " ] .
" WHERE group_id = ' " . Contenido_Security :: escapeDB ( $value , $db ) . " ' " ;
$db -> query ( $sql );
if ( ! $db -> next_record ()) {
$this -> lasterror = i18n ( " Can't set user_id: User or group doesn't exist " , " workflow " );
return false ;
}
}
2019-11-04 15:22:11 +00:00
$idusersquence = parent :: getField ( 'idusersequence' );
2020-08-20 16:30:16 +00:00
}
}
2019-11-04 15:22:11 +00:00
2020-08-20 16:30:16 +00:00
parent :: setField ( $field , $value , $bSafe );
2019-11-04 15:22:11 +00:00
if ( $idusersquence ) {
WorkflowUserSequences :: updateArtAllocation ( 0 );
}
2020-08-20 16:30:16 +00:00
}
2019-11-04 15:22:11 +00:00
2020-08-20 16:30:16 +00:00
/**
2019-11-04 15:22:11 +00:00
* Returns the associated workflowItem for this user sequence
* @ param none
*/
2020-08-20 16:30:16 +00:00
function getWorkflowItem () {
if ( ! $this -> virgin ) {
$workflowItem = new WorkflowItem ;
$workflowItem -> loadByPrimaryKey ( $this -> values [ " idworkflowitem " ]);
return ( $workflowItem );
} else {
return false ;
}
}
/**
2019-11-04 15:22:11 +00:00
* Interface to set idworkflowitem . Should only be called by " create " .
* @ param string $value The value to set
*/
2020-08-20 16:30:16 +00:00
function setWorkflowItem ( $value ) {
parent :: setField ( " idworkflowitem " , $value );
}
2019-11-04 15:22:11 +00:00
2020-08-20 16:30:16 +00:00
/**
2019-11-04 15:22:11 +00:00
* Interface to set idworkflowitem . Should only be called by " create " .
* @ param string $value The value to set
*/
2020-08-20 16:30:16 +00:00
function setPosition ( $value ) {
parent :: setField ( " position " , $value );
}
2019-11-04 15:22:11 +00:00
}
2020-08-20 16:30:16 +00:00
2019-11-04 15:22:11 +00:00
?>