function clearHistory($id, $user) { Model::loadProxy("network"); if (network::validate($id)) { db::init()->query("epoch.clear", array("id" => $_GET['n'])); } }
function create($name, $pass, $network) { $id = self::find($name); if ($id === false) { db::init()->query("users.add", array("name" => $name, "pass" => $pass)); $id = db::init()->lastInsertId(); } Model::loadProxy("usernetwork")->link($id, $network); }
/** * Loads a validation set and records errors to an array * @param name Name of the validation set * @param data Form data to process */ public function load($name = "default", $data = array()) { $set = $this->set[$name] or die("<b>Error:</b> validation set " . $name . " not found"); foreach ($set as $index => $rule) { if ($index == "@attributes") { continue; } if (!isset($data[$index])) { if (isset($rule['required']) && $rule['required'] == "false") { continue; } //skip if not required $this->addError($rule, $index . " does not exist"); continue; //skip if failed this level } if ($rule['type'] == "file") { //if type is file, perform extended validation $result = $this->fileValidate($data[$index], $rule); if (!is_null($result)) { $this->addError($rule, $result); } } if (!$this->validate($data[$index], $rule['type'])) { //test by type $this->addError($rule, $index . " is not of type " . $rule['type']); continue; //skip if failed this level } if (isset($rule['range']) && $rule['type'] == "int") { //test against range $range = explode(",", $rule['range']); //create array from range attribute where 0=min and 1=max if (intval($data[$index]) < intval($range[0]) || intval($data[$index]) > intval($range[1])) { //if value is out of bounds $this->addError($rule, $index . " is not between " . $range[0] . " and " . $range[1]); continue; //skip if failed this level } } if (isset($rule['maxlen']) && strlen($data[$index]) > $rule['maxlen']) { //test against max length $this->addError($rule, $index . " is too long. Must be less than " . $rule['maxlen']); continue; //skip if failed this level } if (isset($rule['minlen']) && strlen($data[$index]) < $rule['minlen']) { //test against min length $this->addError($rule, $index . " is too short. Must be greater than " . $rule['minlen']); continue; //skip if failed this level } if (isset($rule['check'])) { //check by static function $class = substr($rule['check'], 0, strpos($rule['check'], ".")); //store the specified class $function = substr($rule['check'], strpos($rule['check'], ".") + 1, strlen($rule['check'])); //store the function $result = Model::loadProxy($class)->{$function}($data[$index]); //try run the assertion if (!$result) { $this->addError($rule, $index . " is not valid"); continue; //skip if failed this level } } } }
<?php require "lib/controller.class.php"; $app = new Controller(); switch ($_GET['action']) { case "remove": Model::loadProxy("train")->validate($_GET['s']); db::init()->query("pattern.remove", array("id" => $_GET['s'])); break; case "add": $app->model->val->run("trainingset", $_POST); db::init()->query("pattern.add", array("pattern" => $_POST['input'], "id" => $_POST['id'], "output" => $_POST['output'])); break; case "rename": $app->model->val->run("setrename", $_POST); db::init()->query("train.update", array("label" => $_POST['label'], "id" => $_POST['id'])); break; case "delete": Model::loadProxy("train")->validate($_GET['s']); db::init()->query("train.remove", array("id" => $_GET['s'])); break; case "new": $app->model->val->run("newset", $_POST); db::init()->query("train.add", array("id" => $_POST['n'], "label" => $_POST['label'])); break; } Model::direct($_SERVER['HTTP_REFERER']);
/** * Non-static wrapper for loadProxy method * @param $name name of object * @return Proxy object */ public function get($name) { return Model::loadProxy($name); }