='<'?>?php
class =$class_name?> extends DBTable {
/**
* Constructor
* Arguments : None
*/
function __construct() {
parent::__construct("= $table ?>");
}
/**
* This will create a new = $name_single ?> and returns the id of the newly created row.
*/
function create() {
$validation_rules = $this->getValidationRules();
$this->checkDuplicate('=$f['field']?>', $=$f['field']?>);
$validation_errors = check($validation_rules,2);
if($validation_errors) {
$GLOBALS['QUERY']['error'] = "Please correct the errors before continuing...
" . $validation_errors;
return false;
}
$this->newRow();
'$fn', 'is'=>'empty', 'error'=>'Please provide a password');\n";
if($f['password_encryption_algorithm']) $value = $f['password_encryption_algorithm'] . "(\$$fn . '$f[password_salt]')";
else $value = "\$$fn";
} else $value = '$' . $f['field'];
if($f['auto_handler']) { //Auto handled values
if($f['auto_handler'] === 'time_of_insert' || $f['auto_handler'] === 'current_time') $value = "'NOW()'";
elseif($f['auto_handler'] === 'current_user') $value = '$_SESSION["user_id"]';
elseif($f['auto_handler'] !== 'none' and $f['auto_handler']) continue; //Some unknown or invalid auto_handler - don't bother with that.
}
if(!in_array('must',$f['validation']) and $f['auto_handler'] === false) { ?>if($=$fn?> !== false) $this->field['=$fn?>'] = =$value?>;
return $this->save();
}
/**
* You can edit an existing = $title ?> using this function. The first argument
* must be the id of the row to be edited
*/
function edit($id, ) {
if(!$id) return -1;
$this->checkDuplicate('=$fn?>', $=$fn?>);
$validation_errors = check($this->getValidationRules(),2);
if($validation_errors) {
$GLOBALS['QUERY']['error'] = "Please correct the errors before continuing...
" . $validation_errors;
return false;
}
$this->newRow($id);
if($=$fn?> !== false) $this->field['=$fn?>'] = =$value?>;
return $this->save();
}
/**
* Delete the = $title ?> whose id is given
* Argument : $id - The Id of the row to be deleted.
*/
function remove($id) {
if(!$id) return -1;
where("' . $user_field. 'id=$id");';
} else {
print '$this->newRow($id);';
}
?>
$this->delete();
}
/**
* Checks to make sure that there is no other row with the same value in the specified name.
* Example: =$class_name?>.checkDuplicate("username", "binnyva", 4);
* =$class_name?>.checkDuplicate("email", "binnyva@email.com");
*/
function checkDuplicate($field, $value, $not_id=0) {
//See if an item with that name is already there.
$others = $this->find(array(
"select" => 'id',
'where' => array("$field='$value'", "id!=$not_id")));
if($others) {
showMessage("= $name_single ?> '$new_name' already exists!","index.php",'error');
}
return false;
}
function getValidationRules() {
'$fn', 'is'=>'empty', 'error'=>'The $f[title] cannot be empty'),\n";
if(in_array('email', $f['validation'])) $validation_rules .= "\t\t\tarray('name'=>'$fn', 'is'=>'not_email', 'error'=>'Please provide a valid $f[title]'),\n";
if(in_array('number', $f['validation'])) $validation_rules .= "\t\t\tarray('name'=>'$fn', 'is'=>'nan', 'error'=>'$f[title] must be a number'),\n";
if(in_array('password', $f['validation'])) $validation_rules .= "\t\t\tarray('name'=>'$fn', 'is'=>'not', 'value_field'=>'confirm_password', 'error'=>'Password and confirmation dont match'),\n";
}
}
$validation_rules .= "\t\t)";
?> return =$validation_rules?>;
}
}
$GLOBALS['=str_replace('$','',$object_name)?>'] = new =$class_name?>;
/*
Controllor Constructor Code(JSON):
*/