PHP
Ukázka kódu
<!--?php function smarty_function_pc($params, &$smarty){ if(!empty($_POST)){ $id = ORM::for_table('users') --->where('SN', $_POST['pc'])
->find_one();
if(empty($id)){
// Insert new PC into database
$pc = ORM::for_table('users')->create();
} else {
// Update record
$pc = $id;
history($pc->id,$pc->NAME);
}
// Data to save
$pc->NAME = $_POST['name'];
$pc->SN = $_POST['pc'];
$pc->DISPLAYSN = $_POST['monitor'];
$pc->DATE = 'NOW()';
$pc->ORACLEDATE = 'NOW()';
$pc->BIRTHDATE = czech_date_to_mysql($_POST['birth']);
$pc->save();
// Redirect to result
$url = BASE_URL.'find?sn='.$pc->SN;
Slim::redirect($url);
exit();
}
$smarty->assign('pc',
ORM::for_table('users')
->order_by_desc('id')
->find_many()
);
$smarty->assign('pc_count',
ORM::for_table('users')
->count()
);
}
function czech_date_to_mysql($date){
$pattern = '/(\d+)\.(\d+)\.(\d+)/';
$replacement = '$3-$2-$1';
return preg_replace($pattern, $replacement, $date);
}
function history($id,$name){
// we will directly access PDO because our ORM does not have
// functionality needed
$q = ORM::$_db->prepare("
INSERT INTO `history` (`id` ,`users_id` ,`name` ,`date`)
VALUES (NULL , :userid, :name, NOW());");
$q->execute(
array(
'userid' => $id,
'name' => $name,
));
}
?>
Zobrazeno: 736x


