ProcessMaker: Automated Cron Task


<?php
echo 'Automated cron task to evaluate form information and pass it on';
$dbuser="root";
$dbpass="";
$dbname="wf_workflow"; //the name of the database
$chandle = mysql_connect("127.0.0.1", $dbuser, $dbpass)
 or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found." . $dbuser);
$qty=5;

//These keys need to be retrived from teh content table of the created task.

//automated user id who the waiting task is assigned to
$AUTO_USER_ID = '9859924314d367fe0450f37051224667';
$PRO_UID = '2045593264d367e54325200075086262';
$TAS_WAITING_UID = '2568359374d367e62073f48030834145';
//next task
$TASK_FINSHED_UID = '8718566894d367e65ab0561057703743';
$TASK_FINSHED_NEXT_USER = '00000000000000000000000000000001';

//query out the current task in waiting.

$query = "SELECT app.*, del.* FROM APPLICATION as app inner join APP_DELEGATION as del on (app.APP_UID = del.APP_UID) WHERE app.PRO_UID='".$PRO_UID."' and USR_UID='".$AUTO_USER_ID."' and app.APP_STATUS='TO_DO' and del.TAS_UID='".$TAS_WAITING_UID."' and del.DEL_THREAD_STATUS='OPEN'";

//echo '<br>'.$query.'<br><br>';
 $result = mysql_query($query,$chandle);
 while(($APP = mysql_fetch_array($result)))
 {
 //echo $APP['APP_UID'].'<br>';
 //echo print_r($APP);

$AppData[] = unserialize($APP['APP_DATA']);
 echo print_r($AppData);
 //echo '<br><br><br>';

//update the fact that the script has run
 $query = "update IGNORE APP_DELEGATION SET DEL_INIT_DATE=NOW() where APP_UID='".$APP['APP_UID']."' and TAS_UID ='".$APP['TAS_UID']."' and USR_UID='".$AUTO_USER_ID."' and DEL_THREAD_STATUS='OPEN'";
 //echo $query;
 $result = mysql_query($query,$chandle);
 //echo '<br><br><br>';

if($_GET['complete']=='on')
 {
 //atempt to close the ticket by updating the delegation table
 $query = "update IGNORE APP_DELEGATION SET DEL_THREAD_STATUS='CLOSED',DEL_FINISH_DATE=NOW() where APP_UID='".$APP['APP_UID']."' and TAS_UID ='".$APP['TAS_UID']."' and USR_UID='".$AUTO_USER_ID."' and DEL_THREAD_STATUS='OPEN'";
 //echo $query;
 $result = mysql_query($query,$chandle);

//now insert the new ticket for the next user
 $query="Insert INTO APP_DELEGATION SET APP_UID ='".$APP['APP_UID']."' ,DEL_INDEX ='".($APP['DEL_INDEX']+1)."' ,DEL_PREVIOUS ='".$APP['DEL_INDEX']."' ,PRO_UID ='".$APP['PRO_UID']."' ,TAS_UID='".$TASK_FINSHED_UID."' ,USR_UID='".$TASK_FINSHED_NEXT_USER."' ,DEL_TYPE ='".$APP['DEL_TYPE']."' ,DEL_THREAD='".$APP['DEL_THREAD']."' ,DEL_THREAD_STATUS ='OPEN' ,DEL_PRIORITY ='".$APP['DEL_PRIORITY']."' ,DEL_DELEGATE_DATE ='".$APP['DEL_DELEGATE_DATE']."' ,DEL_INIT_DATE='NULL' ,DEL_TASK_DUE_DATE=DATE_ADD(NOW(),INTERVAL 1 HOUR) ,DEL_FINISH_DATE=NULL, DEL_DURATION ='".$APP['DEL_DURATION']."' ,DEL_QUEUE_DURATION ='".$APP['DEL_QUEUE_DURATION']."' ,DEL_DELAY_DURATION='".$APP['DEL_DELAY_DURATION']."' ,DEL_STARTED='".$APP['DEL_STARTED']."' ,DEL_FINISHED ='".$APP['DEL_FINISHED']."' ,DEL_DELAYED='".$APP['DEL_DELAYED']."' ,DEL_DATA='".$APP['DEL_DATA']."' ,APP_OVERDUE_PERCENTAGE='".$APP['APP_OVERDUE_PERCENTAGE']."'";
 //echo '<br><br><br>'.$query;
 $result = mysql_query($query,$chandle);

//now update the relavent reflection to the right task.
 $query="update APP_THREAD set DEL_INDEX='".($APP['DEL_INDEX']+1)."' WHERE APP_UID='".$APP['APP_UID']."'";
 //echo '<br><br><br>'.$query;
 $result = mysql_query($query,$chandle);
 }
 }

mysql_close($chandle);

?>

Advertisements