PatternCreate.inc
6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
* $Id$
*
* This pattern facilities the creation of new entries in the database using
* the objects associated with those entries.
*
* Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @version $Revision$
* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
* @package lib.visualpatterns
*/
class PatternCreate {
var $sObject;
var $sObjectPath;
var $aDisplayRowNames;
var $aParameterNumbers;
var $aDisplayColumnTypes;
var $aRequired;
var $aDropDownListTableNames;
var $aDropDownListValueColumns;
var $aDropDownListDisplayColumns;
var $sUniqueName;
var $aDefaultValues;
/**
* Default constructor
*
* @param String Name of object
* @param Array Name of each item that will be displayed
* @param Array Paramater number for each column e.g. is it constructor parameter 1 or 2 etc.
NB PARAMETER NUMBERS START AT ZERO
* @param Array Types of columns to be displayed (1 = text, 2 = boolean, 3 = drop down list)
* @param Array Names of lookup tables for display column type 3
* @param Array Names of column in lookup table to use as value in select (if not is specified, id is assumed)
* @param Array Names of column in lookup table to display (if not is specified, name is assumed)
*/
function PatternCreate($sNewObject, $sNewObjectPath, $aNewDisplayRowNames, $aNewParameterNumbers, $aNewDisplayColumnTypes, $aNewRequired, $aNewDropDownListTableNames = null, $aNewDropDownListValueColumns = null, $aNewDropDownListDisplayColumns = null) {
$this->sObject = $sNewObject;
$this->sObjectPath = $sNewObjectPath;
$this->sNewQuery = $sNewQuery;
$this->aDisplayRowNames = $aNewDisplayRowNames;
$this->aParameterNumbers = $aNewParameterNumbers;
$this->aDisplayColumnTypes = $aNewDisplayColumnTypes;
$this->aRequired = $aNewRequired;
$this->aDropDownListTableNames = $aNewDropDownListTableNames;
$this->aDropDownListValueColumns = $aNewDropDownListValueColumns;
$this->aDropDownListDisplayColumns = $aNewDropDownListDisplayColumns;
}
function setUniqueName($sNewValue) {
$this->sUniqueName = $sNewValue;
}
function setDefaultValues($aNewValue) {
$this->aDefaultValues = $aNewValue;
}
function render() {
global $default;
$this->sUniqueName .= KTUtil::randomString();
$_SESSION["pelfq_" . $this->sUniqueName . "_object"] = $this->sObject;
$_SESSION["pelfq_" . $this->sUniqueName . "_fn"] = $this->sObjectPath;
$_SESSION["pageAccess"][$default->rootUrl . '/presentation/lookAndFeel/knowledgeTree/create.php'] = true;
$sToRender = "<table border=\"0\">\n";
//unique_start marks the start of information to be parsed from the HTML page by create.php
$sToRender .= "<input type=\"hidden\" name=\"unique_start_" . $this->sUniqueName . "\" />\n";
//write the name of the object to be created
// $sToRender .= "<input type=\"hidden\" name=\"" . $this->sUniqueName . "_object\" value=\"" . $this->sObject . "\" />\n";
//name of folder in lib directory in which object .inc file is located
// $sToRender .= "<input type=\"hidden\" name=\"" . $this->sUniqueName . "_fn\" value=\"" . $this->sObjectPath . "\" />\n";
for ($i = 0; $i < count($this->aDisplayRowNames); $i++) {
$sToRender .= "<tr>\n";
//write the parameter number of this value in the object's constructor
$sToRender .= "<input type=\"hidden\" name=\"" . $this->sUniqueName . "_" . $i . "_parnum\" value=\"" . $this->aParameterNumbers[$i] . "\" />\n";
switch ($this->aDisplayColumnTypes[$i]) {
case 1:
//write the type (in this case text)
$sToRender .= "<input type=\"hidden\" name=\"" . $this->sUniqueName . "_" . $i . "_type\" value=\"1\" />\n";
//write the value
$sToRender .= "<td>" . $this->aDisplayRowNames[$i] . "</td><td><input size = \"30\" type=\"text\" name=\"" . $this->sUniqueName . "_" . $i . "_value\" value=\"" . (isset($this->aDefaultValues[$i]) ? $this->aDefaultValues[$i] : "") . "\" /></td>\n";
break;
case 2:
//write the type (in this case checkbox)
$sToRender .= "<input type=\"hidden\" name=\"" . $this->sUniqueName . "_" . $i . "_type\" value=\"2\" />\n";
//write the value
$sToRender .= "<td>" . $this->aDisplayRowNames[$i] . "</td><td><input type=\"checkbox\" name=\"" . $this->sUniqueName . "_" . $i . "_value\" value=\"1\" /></td>\n";
break;
case 3:
//write the type (in this case dropdown)
$sToRender .= "<input type=\"hidden\" name=\"" . $this->sUniqueName . "_" . $i . "_type\" value=\"3\" />\n";
$sDisplayColumn;
$sValueColumn;
//write the value
if (isset($this->aDropDownListValueColumns[$i])) {
$sValueColumn = $this->aDropDownListValueColumns[$i];
} else {
$sValueColumn = "id";
}
if (isset($this->aDropDownListDisplayColumns[$i])) {
$sDisplayColumn = $this->aDropDownListDisplayColumns[$i];
} else {
$sDisplayColumn = "name";
}
$oPatternListBox = & new PatternListBox($this->aDropDownListTableNames[$i], $sDisplayColumn, $sValueColumn, $this->sUniqueName . "_" . $i . "_value");
$sToRender .= "\t<td>" . $this->aDisplayRowNames[$i] . "</td><td>" . $oPatternListBox->render() . "</td>\t\n";
break;
default;
break;
}
$sToRender .= "</tr>\n";
}
//unique_end marks the end of information to be parsed from the HTML page by create.php
$sToRender .= "<input type=\"hidden\" name=\"unique_end_" . $this->sUniqueName . "\" />\n";
$sToRender .= "</table>\n";
$sToRender .= $this->generateRequiredFieldValidation();
return $sToRender;
}
function generateRequiredFieldValidation() {
$sToRender .= "\n\n<script language=\"javascript\">\n<!--\n";
$sToRender .= "function validateForm(theForm) {\n";
for ($i = 0; $i < count($this->aDisplayRowNames); $i++) {
if ($this->aRequired[$i]) {
$sToRender .= "\tif (!(validRequired(document.MainForm." . $this->sUniqueName . "_" . $i . "_value, '" . $this->aDisplayRowNames[$i] . "'))) {\n";
$sToRender .= "\t\treturn false;\n\t}\n";
}
}
$sToRender .= "return true;\n}\n";
$sToRender .= "//-->\n</script>\n\n";
return $sToRender;
}
}
?>