if ($sms == true) { smd($msg); } } } } if ($Sweg == 'On' && $STweg < $driemin && $Smeldingen == 'On') { if ($Spirhall != 'Off') { $msg = 'Beweging gedecteerd in hall om ' . strftime("%H:%M:%S", $STpirhall); $sirene = true; if ($mc->get('telegrampirhall') < $time - 90) { $mc->set('alertpirhall', $time); telegram($msg); ios($msg); if ($sms == true) { smd($msg); } } } } /*if($STdeurbel>$vijfsec) { $msg='Deurbel'; if($mc->get('alertDeurbel')<$eenmin) { $mc->set('alertDeurbel',$time); ios($msg); } //Udevice($SIdeurbel,0,'Off','deurbel'); if($Shall_auto=='On') { Schakel($SIvoordeur, 'On','licht voordeur'); $mc->set('Bellichtvoordeur',2); }
function Evaluation($id, $value, $input, $exercise_id, $operatorData, $answer) { $m = new EvalMath(); $xml = simplexml_load_file($exercise_id) or die("Error: Cannot create object"); // $ops = array("==", "!=", "GE", "LE", "GT", "LT"); $count_options = $xml->input[$id]->count(); for ($i = 0; $i < $count_options; $i++) { $operator = $xml->input[$id]->option[$i]->operator; $equation = trim($xml->input[$id]->option[$i]->equation); $data = explode(" ", $equation); $operatorDT = ""; if ($operator == 'IF') { if (strstr($equation, "and")) { $content = explode("and", $equation); $data1 = explode(" ", $content[0]); $data2 = explode(" ", $content[1]); if (evalStatement($data1, $input, $answer) and evalStatement($data2, $input, $answer)) { return $xml->input[$id]->option[$i]->result; } } elseif (strstr($equation, "or")) { $content = explode("or", $equation); $data1 = explode(" ", $content[0]); $data2 = explode(" ", $content[1]); if (evalStatement($data1, $input, $answer) or evalStatement($data2, $input, $answer)) { return $xml->input[$id]->option[$i]->result; } } else { if (evalStatement($data, $input, $answer)) { return $xml->input[$id]->option[$i]->result; } } } else { $equation = ""; foreach ($data as $element) { if (is_numeric($element)) { $equation .= $element; } else { if ($element[0] == 'o') { $operatorDT = ltrim($element, "o"); } elseif ($element[0] == 'v') { $trimmed = intval(ltrim($element, "v")); $equation .= $input[$trimmed]; } elseif ($element[0] == 'a') { $trimmed = intval(ltrim($element, "a")); $equation .= $answer[$trimmed - 1]; } else { $equation .= $element; } } } if (strstr($equation, "mcm")) { $valor = explode(",", substr($equation, 3)); $equation_result = mcm(intval($valor[0]), intval($valor[1])); } elseif (strstr($equation, "smn")) { $valor = explode(",", substr($equation, 3)); $equation_result = smn(intval($valor[0]), intval($valor[1])); } elseif (strstr($equation, "smd")) { $valor = explode(",", substr($equation, 3)); $equation_result = smd(intval($valor[0]), intval($valor[1])); } elseif (strstr($equation, "cod")) { $valor = explode(",", substr($equation, 3)); $equation_result = cod(intval($valor[0]), intval($valor[1])); } elseif (strstr($equation, "red")) { $valor = explode(",", substr($equation, 3)); $equation_result = red(intval($valor[0]), intval($valor[1])); } elseif (strstr($equation, "txt")) { $valor = explode(",", substr($equation, 3)); $equation_result = txt($valor[0], $valor[1]); } else { $equation_result = $m->evaluate($equation); } if ($operatorDT == "") { $operatorData = ""; } // return strval($equation_result); switch ($operator) { case "==": if ($equation_result == $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; case "!=": if ($equation_result != $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; case "GT": if ($equation_result > $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; case "GE": if ($equation_result >= $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; case "LT": if ($equation_result < $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; case "LE": if ($equation_result <= $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; } // SWITCH } // else IF } // option's LOOP }
function Evaluation($id, $value, $input, $exercise_id, $operatorData, $answer) { $m = new EvalMath(); $xml = simplexml_load_file($exercise_id) or die("Error: Cannot create object"); $count_options = $xml->input[$id]->count(); for ($i = 0; $i < $count_options; $i++) { $operator = $xml->input[$id]->option[$i]->operator; $equation = trim($xml->input[$id]->option[$i]->equation); $data = explode(" ", $equation); $equation = ""; $operatorDT = ""; if ($operator == 'IF') { // retrieve elements from de conditional $cont = 0; foreach ($data as $element) { if ($element[0] == 'v') { $trimmed = intval(ltrim($element, "v")); $value[$cont] = strval($input[$trimmed]); } elseif ($element[0] == 'a') { $trimmed = intval(ltrim($element, "a")); $value[$cont] = strval($answer[$trimmed - 1]); } else { $value[$cont] = strval($element); } //if($value[$cont] == "==") // return "ccc"; $cont++; } // evaluate one or two conditional statements if ($cont <= 3) { if (condicional($value[0], $data[1], $value[2])) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } } else { if ($data[3] == "and") { if (condicional($value[0], $data[1], $value[2]) and condicional($value[4], $data[5], $value[6])) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } } else { if ($data[3] == "or") { if (condicional($value[0], $data[1], $value[2]) or condicional($value[4], $data[5], $value[6])) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } } } } /* switch($data[1]) { case "==": if($equation == $data[2]) {return $xml->input[$id]->option[$i]->result; $i=$count_options; } break; case "!=": if($equation != $data[2]) {return $xml->input[$id]->option[$i]->result; $i=$count_options; } break; case "GT": if($equation > $data[2]) {return $xml->input[$id]->option[$i]->result; $i=$count_options; } break; case "GE": if($equation >= $data[2]) {return $xml->input[$id]->option[$i]->result; $i=$count_options; } break; case "LT": if($equation < $data[2]) {return $xml->input[$id]->option[$i]->result; $i=$count_options; } break; case "LE": if($equation <= $data[2]) {return $xml->input[$id]->option[$i]->result; $i=$count_options; } break; } // SWITCH */ } else { foreach ($data as $element) { if (is_numeric($element)) { $equation .= $element; } else { if ($element[0] == 'o') { $operatorDT = ltrim($element, "o"); } elseif ($element[0] == 'v') { $trimmed = intval(ltrim($element, "v")); $equation .= $input[$trimmed]; } elseif ($element[0] == 'a') { $trimmed = intval(ltrim($element, "a")); $equation .= $answer[$trimmed - 1]; } else { $equation .= $element; } /* elseif (strpos($element,'v') === False) { $equation .= $element; } else { $trimmed = intval(ltrim($element, "v")); $equation .= $input[$trimmed]; } */ } } // return $equation[3]; // $equation = "mcm(2,4)"; if (strstr($equation, "mcm")) { $valor = explode(",", substr($equation, 3)); $equation_result = mcm(intval($valor[0]), intval($valor[1])); } elseif (strstr($equation, "smn")) { $valor = explode(",", substr($equation, 3)); $equation_result = smn(intval($valor[0]), intval($valor[1])); } elseif (strstr($equation, "smd")) { $valor = explode(",", substr($equation, 3)); $equation_result = smd(intval($valor[0]), intval($valor[1])); } elseif (strstr($equation, "cod")) { $valor = explode(",", substr($equation, 3)); $equation_result = cod(intval($valor[0]), intval($valor[1])); } elseif (strstr($equation, "red")) { $valor = explode(",", substr($equation, 3)); $equation_result = red(intval($valor[0]), intval($valor[1])); } elseif (strstr($equation, "txt")) { $valor = explode(",", substr($equation, 3)); $equation_result = txt($valor[0], $valor[1]); } else { $equation_result = $m->evaluate($equation); } if ($operatorDT == "") { $operatorData = ""; } // return strval($equation_result); switch ($operator) { case "==": if ($equation_result == $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; case "!=": if ($equation_result != $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; case "GT": if ($equation_result > $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; case "GE": if ($equation_result >= $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; case "LT": if ($equation_result < $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; case "LE": if ($equation_result <= $value && $operatorDT == $operatorData) { return $xml->input[$id]->option[$i]->result; $i = $count_options; } break; } // SWITCH } // else IF } // option's LOOP }