1 | <?php |
---|
2 | # ***** BEGIN LICENSE BLOCK ***** |
---|
3 | # Copyright (c) 2009 Olivier Azeau and contributors. All rights reserved. |
---|
4 | # |
---|
5 | # This is free software; you can redistribute it and/or modify |
---|
6 | # it under the terms of the GNU General Public License as published by |
---|
7 | # the Free Software Foundation; either version 2 of the License, or |
---|
8 | # (at your option) any later version. |
---|
9 | # |
---|
10 | # This is distributed in the hope that it will be useful, |
---|
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | # GNU General Public License for more details. |
---|
14 | # |
---|
15 | # You should have received a copy of the GNU General Public License |
---|
16 | # along with DotClear; if not, write to the Free Software |
---|
17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
18 | # |
---|
19 | # ***** END LICENSE BLOCK ***** |
---|
20 | |
---|
21 | require_once("Record.php"); |
---|
22 | |
---|
23 | $core->tpl->addBlock('myformsInsertRecord',array('MyFormsTplDatabase','InsertRecord')); |
---|
24 | $core->tpl->addBlock('myformsInsertOrUpdateRecord',array('MyFormsTplDatabase','InsertOrUpdateRecord')); |
---|
25 | $core->tpl->addBlock('myformsRecordField',array('MyFormsTplDatabase','RecordField')); |
---|
26 | |
---|
27 | $core->tpl->addBlock('myformsDbSelect',array('MyFormsTplDatabase','DbSelect')); |
---|
28 | $core->tpl->addBlock('myformsDbRecord',array('MyFormsTplDatabase','DbRecord')); |
---|
29 | $core->tpl->addValue('myformsDbField',array('MyFormsTplDatabase','DbField')); |
---|
30 | |
---|
31 | class MyFormsTplDatabase |
---|
32 | { |
---|
33 | public static function InsertRecord($attr,$content) |
---|
34 | { |
---|
35 | return '<?php $record=new MyFormsRecord("'.$attr['table'].'"); ?>'.$content.'<?php MyForms::execute( $record->insert() ); ?>'; |
---|
36 | } |
---|
37 | |
---|
38 | public static function InsertOrUpdateRecord($attr,$content) |
---|
39 | { |
---|
40 | return '<?php $record=new MyFormsRecord("'.$attr['table'].'"); ?>'.$content.'<?php MyForms::execute( $record->insertOrUpdate() ); ?>'; |
---|
41 | } |
---|
42 | |
---|
43 | public static function RecordField($attr,$content) |
---|
44 | { |
---|
45 | return '<?php ob_start(); ?>'.$content.'<?php $record->set("'.$attr['name'].'",ob_get_clean(),'.(isset($attr['key'])?'true':'false').'); ?>'; |
---|
46 | } |
---|
47 | |
---|
48 | public static function DbSelect($attr,$content) |
---|
49 | { |
---|
50 | $where = ""; |
---|
51 | if(isset($attr['where'])) |
---|
52 | $where = ' WHERE '.$attr['where']; |
---|
53 | return '<?php $record = $core->con->select("SELECT * FROM ".$core->prefix."'.$attr['table'].$where.'"); ?>'.$content; |
---|
54 | } |
---|
55 | |
---|
56 | public static function DbRecord($attr,$content) |
---|
57 | { |
---|
58 | return '<?php while ($record->fetch()) { ?>'. |
---|
59 | $content. |
---|
60 | '<?php } ?>'; |
---|
61 | } |
---|
62 | |
---|
63 | public static function DbField($attr) |
---|
64 | { |
---|
65 | return '<?php print $record->field("'.$attr['name'].'"); ?>'; |
---|
66 | } |
---|
67 | |
---|
68 | } |
---|
69 | ?> |
---|