require_once ROOT_DIR . '/include/module_init.inc.php'; require_once ROOT_DIR . '/browsing/include/browsing_functions.inc.php'; // MODULE's OWN IMPORTS require_once MODULES_SERVICECOMPLETE_PATH . '/config/config.inc.php'; require_once MODULES_SERVICECOMPLETE_PATH . '/include/init.inc.php'; $self = whoami(); $GLOBALS['dh'] = AMACompleteDataHandler::instance(MultiPort::getDSN($_SESSION['sess_selected_tester'])); $data = ''; $containerDIV = CDOMElement::create('div', 'id:moduleContent'); try { if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST)) { // there are post datas, save them $conditionPOST = $_POST['condition']; $conditionParamsPOST = $_POST['param']; $savedOK = false; fixPOSTArray($conditionPOST, $conditionParamsPOST); if (!empty($conditionPOST)) { $conditionSetId = isset($_POST['conditionSetId']) && intval($_POST['conditionSetId']) > 0 ? intval($_POST['conditionSetId']) : null; $description = isset($_POST['description']) && trim($_POST['description']) !== '' ? trim($_POST['description']) : ''; if ($description !== '') { $saveCondition = new CompleteConditionSet($conditionSetId, $description); $saveCondition->setOperation(Operation::buildOperationTreeFromPOST($conditionPOST)); $savedOK = $GLOBALS['dh']->saveCompleteConditionSet($saveCondition); if ($savedOK) { $msg = translateFN('set di condizioni salvato'); } else { $msg = translateFN('problemi con il salvataggio'); } } else { $msg = translateFN('la descrizione non può essere vuota'); }
/** * given an array of conditions an params coming * from the form POST, will build an array ready to be passed * the operation builder. e.g. * [condition] => Array ( [0] => Array ( [0] => completeConditionTime [1] => null [2] => null ) [1] => Array ( [0] => completeConditionTest1 [1] => null [2] => null ) [2] => Array ( [0] => completeConditionTest2 [1] => null [2] => null ) ) [param] => Array ( [0] => Array ( [0] => 12 [1] => [2] => ) [1] => Array ( [0] => [1] => [2] => ) [2] => Array ( [0] => [1] => [2] => ) ) after running the function, $conditions will be: Array ( [0] => Array ( [0] => completeConditionTime::buildAndCheck(12); ) [1] => Array ( [0] => completeConditionTest1::buildAndCheck(); ) [2] => Array ( [0] => completeConditionTest2::buildAndCheck(); ) ) * * * @param array $conditions * @param array $params */ function fixPOSTArray(&$conditions, $params) { foreach ($conditions as $key => &$val) { if (is_array($val)) { fixPOSTArray($val, $params[$key]); if (empty($val)) { unset($conditions[$key]); } } else { if ($val === 'null') { unset($conditions[$key]); } else { $val .= sprintf('::buildAndCheck(%s)', $params[$key]); } } } }