function getDefaults() { $therecord = parent::getDefaults(); $therecord["crontab"] = "*::*::*::*::*"; $therecord["min"] = "*"; $therecord["hrs"] = "*"; $therecord["date"] = "*"; $therecord["mo"] = "*"; $therecord["day"] = "*"; $therecord["startdate"] = dateToString(mktime(), "SQL"); $therecord["starttime"] = sqlTimeFromString(timeToString(time())); $therecord["enddate"] = ""; $therecord["endtime"] = ""; $therecord["scripttype"] = "job"; return $therecord; }
/** * function prepareFieldForSQL * * Given a value, and field type, prepare the * value for SQL insertion (replacing nul with the SQL string NULL, * and typeing variables) * * @param string/int $value to be prepared. * @param string $type mysql field type * @param string $flags A list of flags seperated by spaces (" "). */ function prepareFieldForSQL($value, $type, $flags) { switch ($type) { case "blob": case "string": if ($value === "" or $value === NULL) { if (strpos($flags, "not_null") === false) { $value = NULL; } else { $value = "''"; } } else { $value = "'" . $value . "'"; } break; case "real": if ($value === "" or $value === NULL) { if (strpos($flags, "not_null") === false) { $value = NULL; } else { $value = 0; } } else { $value = (double) $value; } break; case "int": if ($value === "" or $value === NULL) { if (strpos($flags, "not_null") === false) { $value = NULL; } else { $value = 0; } } else { $value = (int) $value; } break; case "date": if ($value === "" or $value === NULL) { if (strpos($flags, "not_null") === false) { $value = NULL; } else { $value = "'" . dateToString(mktime(), "SQL") . "'"; } } else { $value = "'" . sqlDateFromString($value, $this->dateFormat) . "'"; } break; case "time": if ($value === "" or $value === NULL) { if (strpos($flags, "not_null") === false) { $value = NULL; } else { $value = "'" . timeToString(mktime(), "SQL") . "'"; } } else { $value = "'" . sqlTimeFromString($value, $this->timeFormat) . "'"; } break; case "year": if ($value === "" or $value === NULL) { if (strpos($flags, "not_null") === false) { $value = NULL; } else { $value = @strftime("%Y"); } } break; case "datetime": case "timestamp": if ($value === "" or $value === NULL) { if (strpos($flags, "not_null") === false) { $value = NULL; } else { $value = "'" . dateToString(mktime(), "SQL") . " " . timeToString(mktime(), "24 Hour") . "'"; } } else { $datetimearray = explode(" ", $value); $date = null; $time = null; //If the value can be split by spaces we assume we // are looking at a "date time" if (count($datetimearray) > 1) { $date = sqlDateFromString($datetimearray[0], $this->dateFormat); //times can have spaces... so we need //to resemble in some cases. if (count($datetimearray) > 2) { $datetimearray[1] = $datetimearray[1] . " " . $datetimearray[2]; } $time = sqlTimeFromString($datetimearray[1], $this->timeFormat); } //endif //If we don't have a date, perhaps only a date was passed if (!$date) { $date = sqlDateFromString($value, $this->dateFormat); //still no date?, then assume only a time was passed, // so we need to set the time to the deafult // date. if (!$date) { $date = "0000-00-00"; } } //endif //if we don't have a time, let's try the getting the //time from the full value. if (!$time) { $time = sqlTimeFromString($value, $this->timeFormat); } $value = "'" . trim($date . " " . $time) . "'"; } //end if break; case "password": $value = "ENCODE('" . $value . "','" . ENCRYPTION_SEED . "')"; break; } //end switch if ($value === NULL) { $value = "NULL"; } return $value; }