summaryrefslogtreecommitdiff
path: root/backend/php/src/setup/rpc.php
Unidiff
Diffstat (limited to 'backend/php/src/setup/rpc.php') (more/less context) (ignore whitespace changes)
-rw-r--r--backend/php/src/setup/rpc.php227
1 files changed, 227 insertions, 0 deletions
diff --git a/backend/php/src/setup/rpc.php b/backend/php/src/setup/rpc.php
new file mode 100644
index 0000000..2e2d0c1
--- a/dev/null
+++ b/backend/php/src/setup/rpc.php
@@ -0,0 +1,227 @@
1<?php
2include "./setup_library/xPandMenu.php";
3include "./setup_library/setup_misc.php";
4if(file_exists("../configuration.php"))
5{
6 include_once("../configuration.php");
7}
8
9if(file_exists("../objects/class.database.php"))
10{
11 include_once("../objects/class.database.php");
12}
13include_once('../objects/class.pog_base.php');
14
15$objectName = isset($_REQUEST['objectname']) ? $_REQUEST['objectname'] : '';
16$anchor = isset($_REQUEST['anchor']) ? $_REQUEST['anchor'] : '';
17$offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : '';
18$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : '';
19
20
21//include all classes (possible relations)
22$dir = opendir('../objects/');
23$objects = array();
24while(($file = readdir($dir)) !== false)
25{
26 if(strlen($file) > 4 && substr(strtolower($file), strlen($file) - 4) === '.php' && !is_dir($file) && $file != "class.database.php" && $file != "configuration.php" && $file != "setup.php" && $file != "class.pog_base.php")
27 {
28 $objects[] = $file;
29 }
30}
31closedir($dir);
32foreach ($objects as $object)
33{
34 include_once("../objects/{$object}");
35}
36
37eval ('$instance = new '.$objectName.'();');
38$attributeList = array_keys(get_object_vars($instance));
39$noOfExternalAttributes = sizeof($attributeList) - 3;
40
41// get object id to perform action. required for Delete() and Update()
42$objectId = isset($_REQUEST['objectid']) ? $_REQUEST['objectid'] : '';
43
44// get the ids of all open nodes before action is performed
45$openNodes = isset($_REQUEST['opennodes']) ? explode('-', $_REQUEST['opennodes']) : '';
46
47// get action to perform
48$action = $_GET['action'];
49
50$currentNode = -1;
51if (isset($_GET['currentnode']))
52{
53 // get the node id on which the action is performed. required for Delete() and Update()
54 $currentNode = $_GET['currentnode'];
55 $currentNodeParts = explode('Xnode', $currentNode);
56 if (isset($currentNodeParts[1]))
57 {
58 $currentNode = $currentNodeParts[1];
59 }
60}
61$root = new XMenu();
62
63if ($openNodes != '')
64{
65 foreach ($openNodes as $openNode)
66 {
67 $openNodeParts = explode('Xtree', $openNode);
68 $noParts = sizeof($openNodeParts);
69
70 // all open nodes when action is initiated
71 if ($noParts > 0 && is_numeric($openNodeParts[$noParts - 1]))
72 {
73 // initialize all open nodes
74 $root->visibleNodes[] = $openNodeParts[$noParts - 1];
75 }
76 }
77}
78// perform requested action
79switch($action)
80{
81 case 'Add':
82 eval ('$instance = new '.$objectName.'();');
83 $attributeList = array_keys(get_object_vars($instance));
84 foreach($attributeList as $attribute)
85 {
86 if ($attribute != "pog_attribute_type" && $attribute!= "pog_query")
87 {
88 if (isset($instance->pog_attribute_type[$attribute]))
89 {
90 if (isset($_GET[$attribute]))
91 {
92 $instance->{$attribute} = $_GET[$attribute];
93 }
94 }
95 }
96 }
97 if ($instance->Save())
98 {
99 for ($i = 0; $i < sizeof($root->visibleNodes); $i++)
100 {
101 if ($root->visibleNodes[$i] > ($noOfExternalAttributes + 2))
102 {
103 $root->visibleNodes[$i] += ($noOfExternalAttributes + 1);
104 }
105 }
106 }
107 RefreshTree($anchor, $root);
108 break;
109 case 'Refresh':
110 RefreshTree($objectName, $root, $offset, $limit);
111 break;
112 case 'GetList':
113 RefreshTree($anchor, $root, $offset, $limit);
114 break;
115 case 'DeleteDeep':
116 case 'Delete':
117 eval ('$instance = new '.$objectName.'();');
118 $instance->Get($objectId);
119 $instance->Delete(($action == 'DeleteDeep'));
120 for ($i = 0; $i < sizeof($root->visibleNodes); $i++)
121 {
122 if ($root->visibleNodes[$i] > ($noOfExternalAttributes + 2))
123 {
124 if (intval($root->visibleNodes[$i]) == intval($openNodeParts[$noParts - 1]))
125 {
126 $root->visibleNodes[$i] = null;
127 }
128 else if ($root->visibleNodes[$i] > $currentNode)
129 {
130 $root->visibleNodes[$i] -= ($noOfExternalAttributes + 1);
131 }
132 }
133 }
134 RefreshTree($anchor, $root);
135 break;
136 case 'Update':
137 eval ('$instance = new '.$objectName.'();');
138 $instance->Get($objectId);
139 $attributeList = array_keys(get_object_vars($instance));
140 foreach($attributeList as $attribute)
141 {
142 if ($attribute != "pog_attribute_type" && $attribute!= "pog_query")
143 {
144 if (isset($instance->pog_attribute_type[$attribute]))
145 {
146 if (isset($_GET[$attribute]))
147 {
148 $instance->{$attribute} = $_GET[$attribute];
149 }
150 }
151 }
152 }
153 $instance->Save();
154 RefreshTree($anchor, $root);
155 break;
156 }
157
158 /**
159 * Refreshes the tree after an operation while preserving node statuses
160 *
161 * @param unknown_type $objectName
162 * @param unknown_type $root
163 */
164 function RefreshTree($objectName, $root, $offset = '', $limit = '')
165 {
166 if ($limit == '')
167 {
168 $offset = 0;
169 $limit = 50;
170 }
171 $sqlLimit = "$offset, $limit";
172
173 $js = "new Array(";
174 eval ('$instance = new '.$objectName.'();');
175 $recCount = GetNumberOfRecords(strtolower($objectName));
176 $attributeList = array_keys(get_object_vars($instance));
177 $instanceList = $instance->GetList(array(array(strtolower($objectName)."Id",">",0)), strtolower($objectName)."Id", false, $sqlLimit);
178 $x = 0;
179 $masterNode = &$root->addItem(new XNode("<span style='color:#998D05'>".$objectName."</span>&nbsp;<span style='font-weight:normal'>{Dimensions:[".sizeof($instanceList)."]}</span>", false, "setup_images/folderclose.gif","setup_images/folderopen.gif"));
180 $node = &$masterNode->addItem(new XNode("<span style='color:#998D05'>ADD RECORD</span>", false,"setup_images/folderclose.gif","setup_images/folderopen.gif"));
181 foreach($attributeList as $attribute)
182 {
183 if ($attribute != "pog_attribute_type" && $attribute!= "pog_query")
184 {
185 if ($x != 0 && isset($instance->pog_attribute_type[$attribute]))
186 {
187 $js .= '"'.$attribute.'",';
188 $thisValue = ConvertAttributeToHtml($attribute, $instance->pog_attribute_type[$attribute]['db_attributes'], $instance->{$attribute}, $instance->{$attributeList[0]});
189 $subnode = &$node->addItem(new XNode("<br/><span style='color:#998D05'>".$attribute."</span>&nbsp;<span style='font-weight:normal;color:#ADA8B2;'>{".$instance->pog_attribute_type[$attribute]['db_attributes'][1]."}</span><br/>".$thisValue."<br/>", false,'',"setup_images/folderopen.gif"));
190 }
191 }
192 $x++;
193 }
194 $js = trim($js, ",");
195 $js .= ")";
196 $subnode = &$node->addItem(new XNode("<br/><a href='#' onclick='javascript:sndReq(\"Add\", getOpenNodes(), \"$objectName\", \"".$instance->{strtolower($objectName).'Id'}."\", this.parentNode.parentNode.parentNode.parentNode.id, $js, \"$objectName\");return false;'><img src='./setup_images/button_add.gif' border='0'/></a>", false,'',"folderopen.gif"));
197
198 if ($instanceList != null)
199 {
200 foreach($instanceList as $instance)
201 {
202 ConvertObjectToNode($instance, $masterNode, $js, $objectName);
203 }
204 }
205
206 $menu_html_code = $root->generateTree();
207 $menu_html_code .= "<div class='nav'>";
208 $pre = "<div class='nav'>";
209 if ($offset != '' && $offset != 0)
210 {
211 $pre .= "&#8249;&#8249;<a href='#' onclick='javascript:refTree(".($offset-$limit).", $limit, \"$objectName\");return false;'>Newer</a> | ";
212 $menu_html_code.= "&#8249;&#8249;<a href='#' onclick='javascript:refTree(".($offset-$limit).", $limit, \"$objectName\");return false;'>Newer</a> | ";
213 }
214 $pre .= "<b>".($recCount-$offset-$limit < 0 ? 0 : $recCount-$offset-$limit)." - ".($recCount-$offset)." of $recCount </b>";
215 $menu_html_code .= "<b>".($recCount-$offset-$limit < 0 ? 0 : $recCount-$offset-$limit)." - ".($recCount-$offset)." of $recCount </b>";
216
217 if ($offset <= $recCount - $limit)
218 {
219 $pre .= "| <a href='#' onclick='javascript:refTree(".($offset+$limit).", $limit, \"$objectName\");return false;'>Older</a>&#8250;&#8250;";
220 $menu_html_code.= "| <a href='#' onclick='javascript:refTree(".($offset+$limit).", $limit, \"$objectName\");return false;'>Older</a>&#8250;&#8250;";
221 }
222 $menu_html_code .= "</div>";
223 $pre .= "</div>";
224 $table = "<div id='container'><br/><br/>".$pre.$menu_html_code."</div>";
225 echo $table;
226 }
227?>