= 0 AND $colon_time[0] <=24 AND $colon_time[1] >= 0 AND $colon_time[1] <= 59 ){ return 1; } } return 0; } /* The date check part of the data validator */ function check_date($date){ GLOBAL $setup; $test_date = split("-",$date); if ($test_date[0] AND $test_date[1] AND $test_date[2]){ $day = $test_date[0]; $month = $test_date[1]; $year = $test_date[2]; if (!checkdate($month, $day, $year)){return 0;} return 1; } return 0; } /* The sensor check part of the data validator */ function check_sensor($sensor){ GLOBAL $setup; $sql = "select id from sensor where alarmnum = '".$sensor."'"; $result = mysql_query($sql); $data = mysql_fetch_row($result); if (!empty($data[0])){ return 1; } else { return 0; } } /* The data validator - works great! */ function validator(){ GLOBAL $setup; /* Make variables readable */ $date = $setup->get['date']; $time = $setup->get['time']; $anum = $setup->get['alarmnumber']; $init = $setup->get['init_id']; /* Perform the checks */ if (!check_date($date)){ return "error-date"; } if (!check_time($time)){ return "error-time"; } if (!check_sensor($anum)){ return "error-sensor"; } if (!$init){ return "error-no_init";} /* No checks has failed. Report all ok*/ return "ok"; } /* Generate the data input table */ function make_default_table($error){ GLOBAL $setup; /* print_r($setup->get); */ /* Check if date is set */ if (!$setup->get['date']){ $date = date("d-m-y",time()); } else { $date = $setup->get['date']; } /* Make variables readable */ $time = $setup->get['time']; $alarmnum = $setup->get['alarmnumber']; $textarea = $setup->get['teksten']; $init = $setup->get['init_id']; /* Check if any reason is given */ if (!$setup->get['reason']){ $reason = "SG1"; } else { $reason = $setup->get['reason']; } /* set action to Insert and display any error */ $action = "Insert"; if ($setup->get['error']){echo "\n

The following error was encountered: ".$setup->get['error'].".

";} /* Start the form and create the table */ form_start($_SERVER['SCRIPT_URI'], "get"); echo "\n|* Date (dd-mm-yy) *|* Time (tt:mm) *|* Alarm # *|* Reason *|* Init *|\n"; echo "| "; echo "| "; echo "| "; echo "| "; echo "| "; form_drop("init_id",$setup->get_init_sql,$init); echo " |\n"; echo "%TABLE{cellpadding='2' sort='on' dataalign='left'}%\n"; echo "|* Extra things to remark *|\n | |\n"; echo ""; } /* If erroneus data was given, retry by redirecting to twiki with retry vars */ function retry_insert($error){ GLOBAL $setup; // print_r($setup->get); $date = $setup->get['date']; $time = $setup->get['time']; $anum = $setup->get['alarmnumber']; $init = $setup->get['init_id']; $text = $setup->get['teksten']; $string = ref()."?date=".$date."&time=".$time."&alarmnumber=".$anum."&init_id=".$init."&teksten=".urlencode($text)."&error=".$error."&action=Retry"; header("location: $string"); } /* Basically redirects to the retry part of the script */ function retry($error){ generel($error); } /* This is where the validated data is inserted */ function insert_into_db(){ GLOBAL $setup; generel($error); } /* The main page part. Handles the talbes and vars and important stuff */ function generel($error){ GLOBAL $setup; /* Check if the script is called from Twiki */ // twikitest(); /* Connect to the database */ db_connection('open'); /* Output some generel Startup HTML */ html_start($setup->newalarm); make_default_table($error); /* Output some generel Ending HTML */ html_end($setup->footer); /* Close the database connection */ } /* The submitted page is checked and the best function is selected (or something - bad language) */ function insert(){ GLOBAL $setup; if ($setup->get['action'] == "Retry"){ retry($error); } $error = validator(); if ($error == "ok"){ insert_into_db(); } else { if ($setup->get['action'] == "Insert"){ retry_insert($error); } } } /* Connect to the database */ db_connection('open'); /* First of all: Figure out what to do. This is where everything begins. */ if ($setup->get['action'] == "Insert" OR $setup->get['action'] == "Retry" ){ insert ();} if (!$setup->get['action']){ echo "Cant figure it out"; generel(); } db_connection('close'); ?>