[go: up one dir, main page]

Menu

[r3]: / doc / app / workflow.inc.php  Maximize  Restore  History

Download this file

109 lines (73 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
<?
//issue our alerts for a specific stage of a route
function beginWorkflowDist($conn,$routeId,$stage) {
//get our list of routes assigned to this object
$sql = "SELECT * FROM dm_workflow_route WHERE workflow_id='$routeId';";
$list = total_result($conn,$sql);
//stop here if there are no tasks assigned yet
if ($list["count"]=="0" || !$list) return false;
//get the list of accounts for this stage
$keys = array_keys($list["sort_order"],$stage);
//if there are no accounts at this stage, the job is complete. update our status and exit
if (count($keys)=="0") {
//see if we are supposed to notify the user this is complete
sendWorkflowNotify($conn,$routeId);
$sql = "UPDATE dm_workflow SET status='complete',date_complete='".date("Y-m-d H:i:s")."' WHERE id='$routeId';";
if (db_query($conn,$sql)) {
//log that it's completed
$sql = "SELECT object_id FROM dm_workflow WHERE id='$routeId'";
$info = single_result($conn,$sql);
logEvent($conn,"OBJ_WORKFLOW_END",$info["object_id"],null,USER_ID);
return true;
}
else return false;
}
//pull all accounts at this stage and their job types
$accounts = arrayCombine($keys,$list["account_id"]);
$ids = arrayCombine($keys,$list["id"]);
$dates = arrayCombine($keys,$list["date_due"]);
$types = arrayCombine($keys,$list["task_type"]);
//get our object id
$sql = "SELECT object_id FROM dm_workflow WHERE id='$routeId';";
$info = single_result($conn,$sql);
$objectId = $info["object_id"];
//make sure our primary status is still set to pending since we are not done
$sql = "Update dm_workflow SET status='pending' WHERE id='$routeId';";
for ($i=0;$i<count($accounts);$i++) {
if ($types[$i]=="view") $alertType = "OBJ_VIEW_ALERT";
elseif ($types[$i]=="edit") $alertType = "OBJ_EDIT_ALERT";
elseif ($types[$i]=="approve") $alertType = "OBJ_APPROVAL_ALERT";
elseif ($types[$i]=="comment") $alertType = "OBJ_COMMENT_ALERT";
$sql .= "INSERT INTO dm_task (account_id,task_id,alert_type,date_due)
VALUES
('".$accounts[$i]."','".$ids[$i]."','".$alertType."','".$dates[$i]."');";
$sql .= "UPDATE dm_workflow_route SET status='pending' WHERE id='".$ids[$i]."';";
}
//run the query
if (db_query($conn,$sql)) {
//send email alerts if configured
if (defined("EMAIL_SUPPORT")) {
//send a task notify alert
for ($i=0;$i<count($accounts);$i++) sendTaskNotify($conn,$objectId,$accounts[$i]);
}
return true;
}
else return false;
}
function sendWorkflowNotify($conn,$routeId) {
//see if we are supposed to notify the user this is complete
$sql = "SELECT object_id,account_id,email_notify FROM dm_workflow WHERE id='$routeId'";
$info = single_result($conn,$sql);
if ($info["email_notify"]=="t") {
//get the user's email and send them a notification
$ainfo = returnAccountInfo($conn,$info["account_id"],null);
if ($ainfo["email"]) {
//get the object's name
$sql = "SELECT name FROM dm_object WHERE id='".$info["object_id"]."'";
$objInfo = single_result($conn,$sql);
$sub = _WORKFLOW_COMPLETE;
$msg = $objInfo["name"].": "._WORKFLOW_COMPLETE_MSG;
send_email($ainfo["email"],ADMIN_EMAIL,$sub,$msg,null);
}
}
}