Exemplo n.º 1
0
Arquivo: act.php Projeto: hunglmtb/eb
<?php

include_once '../lib/db.php';
include_once '../lib/utils.php';
$act = $_REQUEST['act'];
if ($act == "opentask") {
    $taskcode = $_REQUEST['taskcode'];
    $url = getOneValue("select PATH from eb_functions where CODE='{$taskcode}'");
    $ROOT = "/eb";
    if ($url) {
        header("location:{$ROOT}/{$url}");
    }
} else {
    if ($act == "get_help") {
        $func_code = $_REQUEST['func_code'];
        echo getOneValue("select HELP from eb_functions where CODE='{$func_code}'");
    } else {
        if ($act == "get_tasklog") {
            $task_id = $_REQUEST['task_id'];
            echo getOneValue("select `log` from tm_workflow_task where id={$task_id}");
        } else {
            if ($act == "save_help") {
                $func_code = $_REQUEST['func_code'];
                $help = mysql_real_escape_string($_REQUEST['help']);
                $sSQL = "update eb_functions set HELP='{$help}' where CODE='{$func_code}'";
                mysql_query($sSQL) or die(mysql_error());
            }
        }
    }
}
Exemplo n.º 2
0
    $re = mysql_query($s) or die("Error: " . mysql_error());
    $ro = mysql_fetch_row($re);
    return $ro[0];
}
function getField($table)
{
    $s = "SELECT COLUMN_NAME, DATA_METHOD FROM cfg_field_props WHERE TABLE_NAME='" . $table . "' AND USE_FDC='1' ORDER BY FIELD_ORDER";
    $ref = mysql_query($s) or die("fail: " . $s . "-> error:" . mysql_error());
    while ($row = mysql_fetch_array($ref)) {
        $fields .= $fields ? "," . $row[COLUMN_NAME] : $row[COLUMN_NAME];
    }
    return $fields;
}
$facility_id = $_REQUEST[facility_id];
$object_type = $_REQUEST[object_type];
$xtable = getOneValue("select CODE from INT_OBJECT_TYPE where id={$object_type}");
$c_system = loadCodes('INT_SYSTEM');
$c_freq = loadCodes('CODE_READING_FREQUENCY');
$c_override = loadCodes('CODE_BOOLEAN');
$c_table = loadComboFromSQL("select TABLE_NAME ID,TABLE_NAME `NAME` from INT_MAP_TABLE where OBJECT_TYPE={$object_type}");
$c_object = loadComboFromSQL("select ID,`NAME` from {$xtable} where FACILITY_ID={$facility_id} order by `NAME`");
$c_eventtype = loadCodes('CODE_EVENT_TYPE');
$c_flowphase = loadCodes('CODE_FLOW_PHASE');
$x_system = $c_system;
$x_freq = $c_freq;
$x_override = $c_override;
$x_table = $c_table;
$x_object = $c_object;
$x_eventtype = $c_eventtype;
$x_flowphase = $c_flowphase;
$fields = getField("INT_TAG_MAPPING");
Exemplo n.º 3
0
<?php

include_once '../lib/db.php';
include_once '../lib/utils.php';
$key = $_REQUEST["key"];
if (!isset($key)) {
    $key = "WF_TASK_ID";
}
$v = getOneValue("select `NUMBER_VALUE`+1 from `params` where `KEY`='{$key}'");
$s = "update params set NUMBER_VALUE=NUMBER_VALUE+1 where `KEY`='{$key}'";
mysql_query($s) or die("fail: " . $s . "-> error:" . mysql_error());
echo $v;
Exemplo n.º 4
0
    $s = "SELECT COLUMN_NAME, DATA_METHOD FROM cfg_field_props WHERE TABLE_NAME='" . $table . "' AND USE_FDC='1' ORDER BY FIELD_ORDER";
    $ref = mysql_query($s) or die("fail: " . $s . "-> error:" . mysql_error());
    while ($row = mysql_fetch_array($ref)) {
        $fields .= $fields ? "," . $row[COLUMN_NAME] : $row[COLUMN_NAME];
    }
    return $fields;
}
$facility_id = $_REQUEST[facility_id];
$object_type = $_REQUEST[object_type];
$object_id = $_REQUEST[object_id];
$xtable = getOneValue("select CODE from INT_OBJECT_TYPE where id={$object_type}");
$c_system = loadCodes('INT_SYSTEM');
$c_freq = loadCodes('CODE_READING_FREQUENCY');
$c_override = loadCodes('CODE_BOOLEAN');
$c_table = loadComboFromSQL("select TABLE_NAME ID,TABLE_NAME `NAME` from INT_MAP_TABLE where OBJECT_TYPE={$object_type}");
$first_table = getOneValue("select TABLE_NAME from INT_MAP_TABLE where OBJECT_TYPE={$object_type} limit 1");
if ($first_table) {
    $x_column = getTableFields($first_table, "decimal", "", false);
}
$c_object = loadComboFromSQL("select ID,`NAME` from {$xtable} where FACILITY_ID={$facility_id} order by `NAME`");
$c_eventtype = loadCodes('CODE_EVENT_TYPE');
$c_flowphase = loadCodes('CODE_FLOW_PHASE');
$x_system = $c_system;
$x_freq = $c_freq;
$x_override = $c_override;
$x_table = $c_table;
$x_object = $c_object;
$x_eventtype = $c_eventtype;
$x_flowphase = $c_flowphase;
$fields = getField("INT_TAG_MAPPING");
$sSQL = "select a.*\n\tfrom INT_TAG_MAPPING a,{$xtable} b \n\twhere a.OBJECT_ID=b.ID and b.FACILITY_ID={$facility_id} and a.OBJECT_TYPE={$object_type}" . ($object_id > 0 ? " and a.OBJECT_ID={$object_id}" : "");
Exemplo n.º 5
0
 public static function evalFormula($formulaRow, $occur_date = null, $show_echo = false)
 {
     $logs = false;
     if (!$formulaRow) {
         $logs = $show_echo ? ["error" => true, "reason" => "Formula is out of date range"] : false;
         return $logs;
     }
     $fid = $formulaRow->ID;
     $flow_phase = $formulaRow->FLOW_PHASE;
     $object_id = $formulaRow->OBJECT_ID;
     $formula = $formulaRow->FORMULA;
     if (!$formula) {
         $logs = $show_echo ? ["error" => true, "reason" => "formula {$formulaRow->NAME} was empty. Please set it in formula table"] : false;
         if ($show_echo) {
             return $logs;
         } else {
             throw new Exception("formula {$formulaRow->NAME} was empty. Please set it in formula table");
         }
     }
     $foVars = $formulaRow->FoVar()->get();
     $CURRENT_DATE = date("Y-m-d");
     $s = "";
     $i = 0;
     $vars = array();
     $vvv = array();
     $logs = ["error" => false, "variables" => []];
     foreach ($foVars as $row) {
         if ($show_echo) {
             $logs["variables"][] = ["content" => "Processing {$row->NAME}={$row->STATIC_VALUE} ...", "type" => "source"];
             $sqlLog = null;
             $valueLog = null;
         }
         array_push($vvv, $row->NAME);
         $row->STATIC_VALUE = str_replace("@OCCUR_DATE", "'{$occur_date}'", $row->STATIC_VALUE);
         $row->STATIC_VALUE = str_replace("@OBJECT_ID", $object_id, $row->STATIC_VALUE);
         $row->STATIC_VALUE = str_replace("@FLOW_PHASE", $flow_phase, $row->STATIC_VALUE);
         $row->STATIC_VALUE = str_replace("@VAR_OBJECT_ID", $row->OBJECT_ID, $row->STATIC_VALUE);
         $row->STATIC_VALUE = str_replace("#OIL#", "1", $row->STATIC_VALUE);
         $row->STATIC_VALUE = str_replace("#GAS#", "2", $row->STATIC_VALUE);
         $row->STATIC_VALUE = str_replace("#WATER#", "3", $row->STATIC_VALUE);
         if (strpos($row->STATIC_VALUE, "#CODE_") !== false) {
             $row->STATIC_VALUE = processFormulaCodeConstant($row->STATIC_VALUE);
         }
         if ($row->IS_DATE > 0) {
             $s = '$' . $row->NAME . "='{$row->STATIC_VALUE}';\$vs=\${$row->NAME};";
             eval($s);
             $vars[$row->NAME] = $vs;
             if ($show_echo) {
                 $valueLog = ["content" => "{$row->NAME} = {$vs}", "type" => "value"];
             }
         } else {
             if (is_numeric($row->STATIC_VALUE)) {
                 $s = '$' . $row->NAME . "={$row->STATIC_VALUE};\$vs=\${$row->NAME};";
                 eval($s);
                 $vars[$row->NAME] = $vs;
                 if ($show_echo) {
                     $valueLog = ["content" => "{$row->NAME} = {$vs}", "type" => "value"];
                 }
             } else {
                 if (strpos($row->STATIC_VALUE, "[") > 0) {
                     $i = strpos($row->STATIC_VALUE, "[");
                     $j = strpos($row->STATIC_VALUE, "]", $i);
                     if ($j > $i) {
                         $ms = substr($row->STATIC_VALUE, 0, $i);
                         $key = substr($row->STATIC_VALUE, $i + 1, $j - $i - 1);
                         $vs = explode("\r", $vars[$ms]);
                         $vl = "";
                         foreach ($vs as $v) {
                             $vx = explode("=", $v);
                             if (trim($vx[0]) == $key) {
                                 $vl = $vx[1];
                                 break;
                             }
                         }
                         if ($vl) {
                             $s = '$' . $row->NAME . "={$vl};\$vs=\${$row->NAME};";
                             eval($s);
                             $vars[$row->NAME] = $vs;
                             if ($show_echo) {
                                 $valueLog = ["content" => "{$row->NAME} = {$vs}", "type" => "value"];
                             }
                         }
                     }
                 } else {
                     if (substr($row->STATIC_VALUE, 0, 6) == "matlab") {
                         $i = strpos($row->STATIC_VALUE, "(");
                         $j = strpos($row->STATIC_VALUE, ")", $i);
                         if ($j > $i) {
                             $ms = explode(",", substr($row->STATIC_VALUE, $i + 1, $j - $i - 1));
                             $args = "";
                             $matlab_code = $ms[0];
                             for ($i = 1; $i < sizeof($ms); $i++) {
                                 $args .= ($args == "" ? "" : "%20") . $vars[$ms[$i]];
                             }
                             $s = "\$vs = file_get_contents('http://energybuilder.co/eb/matlab/{$matlab_code}/{$matlab_code}.php?act=get&a=" . $args . "', true);";
                             // echo "xxxxx".$s;
                             eval($s);
                             $vars[$row->NAME] = $vs;
                             if ($show_echo) {
                                 $valueLog = ["content" => "{$row->NAME} = {$vs}", "type" => "value"];
                             }
                         }
                         // $s="$m = file_get_contents('http://energybuilder.co/eb/matlab/test.php?act=get&a=1%204%202', true);
                     } else {
                         if (substr($row->STATIC_VALUE, 0, 7) == "getData") {
                             if ($row->TABLE_NAME && $row->VALUE_COLUMN) {
                                 $j = strpos($row->STATIC_VALUE, "(");
                                 $k = self::findClosedSign(")", $row->STATIC_VALUE, $j);
                                 if ($k > $j && $j > 0) {
                                     $table = $row->TABLE_NAME;
                                     $field = $row->VALUE_COLUMN;
                                     $sql = "select {$field} from `{$table}` where 1";
                                     //echo "field: $field<br>";
                                     $params = explode(",", substr($row->STATIC_VALUE, $j + 1, $k - $j - 1));
                                     $where = [];
                                     $whereDate = [];
                                     $whereMonth = [];
                                     $whereYear = [];
                                     $swhere = false;
                                     foreach ($params as $param) {
                                         $deli = "";
                                         if (strpos($param, '>=') !== false) {
                                             $deli = ">=";
                                         } else {
                                             if (strpos($param, '<=') !== false) {
                                                 $deli = "<=";
                                             } else {
                                                 if (strpos($param, '>') !== false) {
                                                     $deli = ">";
                                                 } else {
                                                     if (strpos($param, '<') !== false) {
                                                         $deli = "<";
                                                     } else {
                                                         if (strpos($param, '=') !== false) {
                                                             $deli = "=";
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         if ($deli !== "") {
                                             $ps = explode($deli, $param);
                                             if ($ps[1] == "@DATE") {
                                                 $pp = "{$ps['0']} {$deli} {$CURRENT_DATE}";
                                                 $whereItem = [$ps[0], $deli, $CURRENT_DATE];
                                             } else {
                                                 if (isset($vars[$ps[1]]) && is_numeric($vars[$ps[1]])) {
                                                     $pp = "{$ps['0']} {$deli} " . $vars[$ps[1]] . "";
                                                     $whereItem = [$ps[0], $deli, $vars[$ps[1]]];
                                                 } else {
                                                     if (isset($vars[$ps[1]])) {
                                                         $pp = "{$ps['0']} {$deli} '" . $vars[$ps[1]] . "'";
                                                         $whereItem = [$ps[0], $deli, $vars[$ps[1]]];
                                                     } else {
                                                         $pp = "{$ps['0']} {$deli} {$ps['1']}";
                                                         $whereItem = [$ps[0], $deli, $ps[1]];
                                                     }
                                                 }
                                             }
                                             $sql .= " and {$pp}";
                                             //     								$swhere.=" and $pp";
                                             if ($whereItem[0] == "OCCUR_DATE" || $whereItem[0] == "EFFECTIVE_DATE") {
                                                 $whereItem[2] = $occur_date;
                                                 $whereDate[] = $whereItem;
                                             } else {
                                                 if (strpos($whereItem[0], 'month') !== false || strpos($whereItem[0], 'year') !== false) {
                                                     $swhere = $swhere ? "{$swhere} and {$pp}" : $pp;
                                                     /* if (strpos($whereItem[0], 'month') !== false) {
                                                     				$whereItem[2] 	= $occur_date->month;
                                                     				$whereMonth[] 	= $whereItem;
                                                     			}
                                                     			else {
                                                     				if (strpos($whereItem[0], 'year') !== false) $whereItem[2] = $occur_date->year;
                                                     				$whereYear[] 	= $whereItem;
                                                     			} */
                                                 } else {
                                                     $where[] = $whereItem;
                                                 }
                                             }
                                             //echo "param: $pp<br>";
                                         }
                                     }
                                     $sql .= " limit 100";
                                     if ($show_echo) {
                                         $sqlLog = ["content" => $sql, "type" => "sql"];
                                     }
                                     //      						\DB::enableQueryLog();
                                     //      						$getDataResult = DB::table($table)->where( \DB::raw($swhere))->select($field)->skip(0)->take(100)->get();
                                     $queryField = DB::table($table)->where($where);
                                     if ($swhere) {
                                         $queryField->where(\DB::raw($swhere));
                                     }
                                     foreach ($whereDate as $dkey => $dvalue) {
                                         $queryField->whereDate($dvalue[0], $dvalue[1], $dvalue[2]);
                                     }
                                     foreach ($whereMonth as $mkey => $mvalue) {
                                         $queryField->whereMonth($mvalue[0], $mvalue[1], $mvalue[2]);
                                     }
                                     foreach ($whereYear as $ykey => $yvalue) {
                                         $queryField->whereYear($yvalue[0], $yvalue[1], $yvalue[2]);
                                     }
                                     $getDataResult = $queryField->select($field)->skip(0)->take(100)->get();
                                     //      						\Log::info(\DB::getQueryLog());
                                     unset($table);
                                     unset($where);
                                     unset($params);
                                     $num_rows = count($getDataResult);
                                     //     						$rrr=mysql_query($sql) or die("fail: ".$sql."-> error:".mysql_error());
                                     //     						$num_rows = mysql_num_rows($rrr);
                                     //$sqlvalue=getOneRow($sql);
                                     if ($num_rows == 0) {
                                         $s = '$' . $row->NAME . "='null';\$vs=\${$row->NAME};";
                                         eval($s);
                                         if ($show_echo) {
                                             $valueLog = ["content" => "{$row->NAME} = {$vs}", "type" => "value"];
                                         }
                                     } else {
                                         if ($num_rows == 1) {
                                             //     							$sqlvalue=mysql_fetch_array($rrr);
                                             $sqlvalue = $getDataResult[0];
                                             if (count($sqlvalue) <= 2) {
                                                 $stdvl = $sqlvalue->{$field};
                                                 $s = '$' . $row->NAME . "='{$stdvl}';\$vs=\${$row->NAME};";
                                                 eval($s);
                                                 if ($show_echo) {
                                                     $valueLog = ["content" => "{$row->NAME} = {$vs}", "type" => "value"];
                                                 }
                                             } else {
                                                 $sqlarray = array();
                                                 foreach ($sqlvalue as $key => $value) {
                                                     if (is_numeric($key)) {
                                                         $sqlarray[$key] = $value;
                                                     }
                                                 }
                                                 //for($i=0;$i<count($sqlvalue)/2;$i++)
                                                 //{
                                                 //	$sqlarray[]=$sqlvalue[$i];
                                                 //}
                                                 $s = '$' . $row->NAME . '=$sqlarray;' . "\$vs=\${$row->NAME};";
                                                 eval($s);
                                                 if ($show_echo) {
                                                     $valueLog = ["content" => "{$row->NAME} = {$vs}", "type" => "value"];
                                                 }
                                             }
                                         } else {
                                             /* $sqlvalue=array();
                                             			while($rox=mysql_fetch_array($rrr))
                                             			{
                                             				$sqlvalue[]=$rox;
                                             			} */
                                             $sqlvalue = is_array($getDataResult) ? $getDataResult : $getDataResult->toArray();
                                             //     							$sqlvalue= $getDataResult;
                                             $sqlarray = array();
                                             for ($k = 0; $k < $num_rows; $k++) {
                                                 foreach ($sqlvalue[$k] as $key => $value) {
                                                     //     									if(is_numeric($key))
                                                     $sqlarray[$k][$key] = $value;
                                                 }
                                                 //for($i=0;$i<count($sqlvalue[$k])/2;$i++)
                                                 //{
                                                 //	$sqlarray[$k][]=$sqlvalue[$k][$i];
                                                 //}
                                             }
                                             $s = '$' . $row->NAME . '=$sqlarray;' . "\$vs=\${$row->NAME};";
                                             eval($s);
                                             if ($show_echo) {
                                                 $valueLog = ["content" => "{$row->NAME} is an array with {$num_rows} rows", "type" => "value"];
                                             }
                                         }
                                     }
                                     $vars[$row->NAME] = $vs;
                                     unset($field);
                                     unset($getDataResult);
                                     unset($s);
                                 }
                             }
                         } else {
                             $v = $row->STATIC_VALUE;
                             $i = strpos($v, ".");
                             if ($i > 0) {
                                 $table = substr($v, 0, $i);
                                 //echo "table: $table<br>";
                                 $j = strpos($v, "(", $i);
                                 $k = strpos($v, ")", $i);
                                 if ($j > $i && $k > $j) {
                                     $field = substr($v, $i + 1, $j - $i - 1);
                                     $sql = "select `{$field}` from `{$table}` where 1";
                                     //echo "field: $field<br>";
                                     $params = explode(",", substr($v, $j + 1, $k - $j - 1));
                                     foreach ($params as $param) {
                                         $ps = explode("=", $param);
                                         if ($vars[$ps[1]]) {
                                             $pp = "{$ps['0']} = '" . $vars[$ps[1]] . "'";
                                         } else {
                                             $pp = "{$ps['0']} = '{$ps['1']}'";
                                         }
                                         $sql .= " and {$pp}";
                                         //echo "param: $pp<br>";
                                     }
                                     $sqlvalue = getOneValue($sql);
                                     $s = '$' . $row->NAME . "='{$sqlvalue}';\$vs=\${$row->NAME};";
                                     eval($s);
                                     $vars[$row->NAME] = $vs;
                                     if ($show_echo) {
                                         $sqlLog = ["content" => $sql, "type" => "sql"];
                                         $valueLog = ["content" => "{$row->NAME} = {$vs}", "type" => "value"];
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($show_echo) {
             if ($sqlLog) {
                 $logs["variables"][] = $sqlLog;
             }
             if ($valueLog) {
                 $logs["variables"][] = $valueLog;
             }
         }
     }
     if ($show_echo) {
         $logs["variables"][] = ["content" => "Processing final expression ...", "type" => "source"];
     }
     $f = $formula;
     $varsKey = [];
     foreach ($vvv as $key => $v) {
         //$f=str_replace($v,$vars[$v],$f);
         if (!isset($vars[$v]) || !$vars[$v]) {
             $f = str_replace($v, "0", $f);
         } else {
             if (is_array($vars[$v])) {
                 $varsKey[$v] = $vars[$v];
                 $f = str_replace($v, "\$varsKey['{$v}']", $f);
             } else {
                 $f = str_replace($v, $vars[$v], $f);
             }
         }
         //if() echo "$f<br>";
     }
     $f = str_replace("@DATE", $CURRENT_DATE, $f);
     $s = '$vf = ' . $f . ";";
     if ($show_echo) {
         $logs["variables"][] = ["content" => $f, "type" => "sql"];
     }
     if (!self::php_syntax_error($s)) {
         set_error_handler("evalErrorHandler");
         try {
             eval($s);
             if ($show_echo) {
                 $logs["variables"][] = ["content" => "Final result: {$vf}", "type" => "value"];
             }
         } catch (Exception $e) {
             \Log::info("Exception with eval {$s} " . $e->getMessage());
             $vf = null;
             if ($show_echo) {
                 $logs["variables"][] = ["content" => "Syntax error in final expression: {$s}", "type" => "error"];
             }
         }
         restore_error_handler();
     } else {
         $vf = null;
         if ($show_echo) {
             $logs["variables"][] = ["content" => "Syntax error in final expression: {$s}", "type" => "error"];
         }
     }
     if ($show_echo) {
         return $logs;
     }
     return $vf;
 }