1: <?php
2:
3:
4: if(!isset($config)) {
5: require_once '../util/AlphaConfig.inc';
6: $config = AlphaConfig::getInstance();
7:
8: require_once $config->get('app.root').'alpha/util/AlphaAutoLoader.inc';
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: class ListBusinessObjects extends AlphaController implements AlphaControllerInterface {
57: 58: 59: 60: 61: 62:
63: private static $logger = null;
64:
65: 66: 67: 68: 69:
70: public function __construct() {
71: self::$logger = new Logger('ListBusinessObjects');
72: self::$logger->debug('>>__construct()');
73:
74: global $config;
75:
76:
77: parent::__construct('Admin');
78:
79:
80: $this->setTitle('Listing all business objects in the system');
81: $this->setDescription('Page to list all business objects.');
82: $this->setKeywords('list,all,business,objects');
83:
84: self::$logger->debug('<<__construct');
85: }
86:
87: 88: 89: 90: 91: 92:
93: public function doGET($params) {
94: self::$logger->debug('>>doGET($params=['.var_export($params, true).'])');
95:
96: echo AlphaView::displayPageHead($this);
97:
98: $this->displayBodyContent();
99:
100: echo AlphaView::displayPageFoot($this);
101:
102: self::$logger->debug('<<doGET');
103: }
104:
105: 106: 107: 108: 109: 110:
111: public function doPOST($params) {
112: self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
113:
114: global $config;
115:
116: echo AlphaView::displayPageHead($this);
117:
118: try {
119:
120: if(!$this->checkSecurityFields())
121: throw new SecurityException('This page cannot accept post data from remote servers!');
122:
123: if(isset($params['createTableBut'])) {
124: try {
125: $classname = $params['createTableClass'];
126: AlphaDAO::loadClassDef($classname);
127:
128: $BO = new $classname();
129: $BO->makeTable();
130:
131: self::$logger->action('Created the table for class '.$classname);
132:
133: echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully created.');
134: }catch(AlphaException $e) {
135: self::$logger->error($e->getMessage());
136: echo AlphaView::displayErrorMessage('Error creating the table for the class '.$classname.', check the log!');
137: }
138: }
139:
140: if(isset($params['createHistoryTableBut'])) {
141: try {
142: $classname = $params['createTableClass'];
143: AlphaDAO::loadClassDef($classname);
144:
145: $BO = new $classname();
146: $BO->makeHistoryTable();
147:
148: self::$logger->action('Created the history table for class '.$classname);
149:
150: echo AlphaView::displayUpdateMessage('The history table for the class '.$classname.' has been successfully created.');
151: }catch(AlphaException $e) {
152: self::$logger->error($e->getMessage());
153: echo AlphaView::displayErrorMessage('Error creating the history table for the class '.$classname.', check the log!');
154: }
155: }
156:
157: if(isset($params['recreateTableClass']) && $params['admin_'.$params['recreateTableClass'].'_button_pressed'] == 'recreateTableBut') {
158: try {
159: $classname = $params['recreateTableClass'];
160: AlphaDAO::loadClassDef($classname);
161: $BO = new $classname();
162: $BO->rebuildTable();
163:
164: self::$logger->action('Recreated the table for class '.$classname);
165:
166: echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully recreated.');
167: }catch(AlphaException $e) {
168: self::$logger->error($e->getMessage());
169: echo AlphaView::displayErrorMessage('Error recreating the table for the class '.$classname.', check the log!');
170: }
171: }
172:
173: if(isset($params['updateTableClass']) && $params['admin_'.$params['updateTableClass'].'_button_pressed'] == 'updateTableBut') {
174: try {
175: $classname = $params['updateTableClass'];
176: AlphaDAO::loadClassDef($classname);
177:
178: $BO = new $classname();
179: $missingFields = $BO->findMissingFields();
180:
181: $count = count($missingFields);
182:
183: for($i = 0; $i < $count; $i++)
184: $BO->addProperty($missingFields[$i]);
185:
186: self::$logger->action('Updated the table for class '.$classname);
187:
188: echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully updated.');
189: }catch(AlphaException $e) {
190: self::$logger->error($e->getMessage());
191: echo AlphaView::displayErrorMessage('Error updating the table for the class '.$classname.', check the log!');
192: }
193: }
194: }catch(SecurityException $e) {
195: echo AlphaView::displayErrorMessage($e->getMessage());
196: self::$logger->warn($e->getMessage());
197: }
198:
199: $this->displayBodyContent();
200:
201: echo AlphaView::displayPageFoot($this);
202:
203: self::$logger->debug('<<doPOST');
204: }
205:
206: 207: 208: 209: 210:
211: private function displayBodyContent() {
212:
213: $classNames = AlphaDAO::getBOClassNames();
214: $loadedClasses = array();
215:
216: foreach($classNames as $classname) {
217: AlphaDAO::loadClassDef($classname);
218: array_push($loadedClasses, $classname);
219: }
220:
221: foreach($loadedClasses as $classname) {
222: try {
223: $BO = new $classname();
224: $BO_View = AlphaView::getInstance($BO);
225: $BO_View->adminView();
226: }catch (AlphaException $e) {
227: self::$logger->error("[$classname]:".$e->getMessage());
228:
229: if($BO->checkTableExists() && $BO->checkTableNeedsUpdate()) {
230: $missingFields = $BO->findMissingFields();
231:
232: $count = count($missingFields);
233:
234: for($i = 0; $i < $count; $i++)
235: $BO->addProperty($missingFields[$i]);
236:
237:
238: $BO = new $classname();
239: $BO_View = AlphaView::getInstance($BO);
240: $BO_View->adminView();
241: }
242: }catch (Exception $e) {
243: self::$logger->error($e->getMessage());
244: echo AlphaView::displayErrorMessage('Error accessing the class ['.$classname.'], check the log!');
245: }
246: }
247: }
248:
249: 250: 251: 252: 253:
254: public function after_displayPageHead_callback() {
255: $menu = AlphaView::loadTemplateFragment('html', 'adminmenu.phtml', array());
256:
257: return $menu;
258: }
259: }
260:
261:
262: if(basename($_SERVER['PHP_SELF']) == 'ListBusinessObjects.php') {
263: $controller = new ListBusinessObjects();
264:
265: if(!empty($_POST)) {
266: $controller->doPOST($_REQUEST);
267: }else{
268: $controller->doGET($_GET);
269: }
270: }
271:
272: ?>