<?php session_start(); if (!isset($_SESSION['authuser']) || !isset($_GET['target_id']) || !isset($_GET['product_id'])) { exit; } require_once "./include/config.inc"; require_once "./horse_inc.php"; $target_id = $_GET['target_id']; $product_id = $_GET['product_id']; $rt = array('query_status' => 0, 'query_msg' => ''); $rt = check_horse($product_id); if ($rt['query_status'] == 1) { echo json_encode($rt); exit; } $rt = sync_horse($target_id, $product_id); $horse = get_horse($target_id, $product_id); if (isset($_GET['action']) && $_GET['action'] == 'start_horse') { $sql = sprintf("UPDATE horse, workflow_object \n\t\t\t\t\t\tSET horse.start_time = now(), workflow_object.status = %d, workflow_object.start_time = now() \n\t\t\t\t\t\tWHERE workflow_object.id = %d AND horse.workflow_object_id = workflow_object.id", STARTED, $horse['workflow_object_id']); $st = mysql_query($sql); $rt['query_status'] = $st ? 0 : 1; $rt['start_sql'] = $sql; $rt['query_msg'] = $st ? 'Horse started' : 'Error starting horse:' . mysql_error(); if ($rt['query_status'] == 0) { $rt['horse'] = '<img src="./images/play-disabled.png" /> <img src="./images/stop.png" onClick="stop_horse($(this).parent());" /> <img src="./images/eject.png" onClick="cancel_horse($(this).parent());" /> '; } echo json_encode($rt); exit;
if (!isset($_GET['workflow_id'])) { exit; } require_once "include/config.inc"; require_once "horse_inc.php"; $workflow_id = $_GET['workflow_id']; function get_out($status, $msg, $sql, $error) { $rt = array('status' => $status, 'query_msg' => $msg, 'sql' => $sql, 'error' => $error); echo json_encode($rt); exit; } // get all products that are using this workflow $sql = "SELECT * FROM product WHERE workflow_id = " . $workflow_id; $st = mysql_query($sql); while ($product = mysql_fetch_assoc($st)) { $check_rt = check_horse($product['id']); if ($check_rt['query_status'] == 1) { echo json_encode($check_rt); exit; } $p_sql = sprintf("SELECT * FROM horse WHERE product_id = %d", $product['id']); $p_st = mysql_query($p_sql); while ($pt = mysql_fetch_assoc($p_st)) { $sync = sync_horse($pt['target_id'], $pt['product_id']); if ($sync['query_status'] == 1) { get_out(1, "Error sync workflow for product [" . $product['name'] . "] ", '', $sync['query_msg']); } } } get_out(0, "All products using this workflow have been synced", '', '');