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: class Detail extends AlphaController implements AlphaControllerInterface {
56: 57: 58: 59: 60: 61:
62: protected $BO;
63:
64: 65: 66: 67: 68: 69:
70: private $BOName;
71:
72: 73: 74: 75: 76: 77:
78: private $BOView;
79:
80: 81: 82: 83: 84: 85:
86: private static $logger = null;
87:
88: 89: 90: 91: 92: 93:
94: public function __construct($visibility='Standard') {
95: self::$logger = new Logger('Detail');
96: self::$logger->debug('>>__construct()');
97:
98: global $config;
99:
100:
101: parent::__construct($visibility);
102:
103: self::$logger->debug('<<__construct');
104: }
105:
106: 107: 108: 109: 110: 111: 112: 113:
114: public function doGET($params) {
115: self::$logger->debug('>>doGET(params=['.var_export($params, true).'])');
116:
117: try{
118:
119: if (isset($params['bo']) && isset($params['oid'])) {
120: if(!AlphaValidator::isInteger($params['oid']))
121: throw new IllegalArguementException('Invalid oid ['.$params['oid'].'] provided on the request!');
122:
123: $BOName = $params['bo'];
124: AlphaDAO::loadClassDef($BOName);
125:
126: 127: 128:
129: if($this->getCustomControllerName($BOName, 'view') != null)
130: $this->loadCustomController($BOName, 'view');
131:
132: $this->BO = new $BOName();
133: $this->BO->load($params['oid']);
134: AlphaDAO::disconnect();
135:
136: $this->BOName = $BOName;
137: $this->BOView = AlphaView::getInstance($this->BO);
138:
139: echo AlphaView::displayPageHead($this);
140: echo AlphaView::renderDeleteForm();
141: echo $this->BOView->detailedView();
142: }else{
143: throw new IllegalArguementException('No BO available to display!');
144: }
145: }catch(IllegalArguementException $e) {
146: self::$logger->warn($e->getMessage());
147: throw new ResourceNotFoundException('The file that you have requested cannot be found!');
148: }catch(BONotFoundException $e) {
149: self::$logger->warn($e->getMessage());
150: throw new ResourceNotFoundException('The item that you have requested cannot be found!');
151: }
152:
153: echo AlphaView::displayPageFoot($this);
154: self::$logger->debug('<<doGET');
155: }
156:
157: 158: 159: 160: 161: 162: 163: 164:
165: public function doPOST($params) {
166: self::$logger->debug('>>doPOST(params=['.var_export($params, true).'])');
167:
168: global $config;
169:
170: echo AlphaView::displayPageHead($this);
171:
172: try {
173:
174: if(!$this->checkSecurityFields())
175: throw new SecurityException('This page cannot accept post data from remote servers!');
176:
177:
178: if (isset($params['bo'])) {
179: $BOName = $params['bo'];
180: AlphaDAO::loadClassDef($BOName);
181:
182: $this->BO = new $BOName();
183: $this->BOname = $BOName;
184: $this->BOView = AlphaView::getInstance($this->BO);
185:
186: if (!empty($params['deleteOID'])) {
187: if(!AlphaValidator::isInteger($params['deleteOID']))
188: throw new IllegalArguementException('Invalid deleteOID ['.$params['deleteOID'].'] provided on the request!');
189:
190: $temp = new $BOName();
191: $temp->load($params['deleteOID']);
192:
193: try {
194: AlphaDAO::begin();
195: $temp->delete();
196: self::$logger->action('Deleted '.$BOName.' instance with OID '.$params['deleteOID']);
197: AlphaDAO::commit();
198:
199: echo AlphaView::displayUpdateMessage($BOName.' '.$params['deleteOID'].' deleted successfully.');
200:
201: echo '<center>';
202:
203: $temp = new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'",
204: 'Back to List','cancelBut');
205: echo $temp->render();
206:
207: echo '</center>';
208: }catch(AlphaException $e) {
209: self::$logger->error($e->getMessage());
210: echo AlphaView::displayErrorMessage('Error deleting the BO of OID ['.$params['deleteOID'].'], check the log!');
211: AlphaDAO::rollback();
212: }
213:
214: AlphaDAO::disconnect();
215: }
216: }else{
217: throw new IllegalArguementException('No BO available to display!');
218: }
219: }catch(SecurityException $e) {
220: self::$logger->warn($e->getMessage());
221: throw new ResourceNotAllowedException($e->getMessage());
222: }catch(IllegalArguementException $e) {
223: self::$logger->warn($e->getMessage());
224: throw new ResourceNotFoundException('The file that you have requested cannot be found!');
225: }catch(BONotFoundException $e) {
226: self::$logger->warn($e->getMessage());
227: throw new ResourceNotFoundException('The item that you have requested cannot be found!');
228: }
229:
230: echo AlphaView::displayPageFoot($this);
231: self::$logger->debug('<<doPOST');
232: }
233:
234: 235: 236: 237: 238:
239: public function before_displayPageHead_callback() {
240: if($this->title == '' && isset($this->BO))
241: $this->setTitle('Displaying '.$this->BOName.' number '.$this->BO->getID());
242: if($this->description == '' && isset($this->BO))
243: $this->setDescription('Page to display '.$this->BOName.' number '.$this->BO->getID());
244: if($this->keywords == '')
245: $this->setKeywords('display,details,'.$this->BOName);
246: }
247:
248: 249: 250: 251: 252: 253:
254: public function after_displayPageHead_callback() {
255: $menu = '';
256:
257: if (isset($_SESSION['currentUser']) && AlphaDAO::isInstalled() && $_SESSION['currentUser']->inGroup('Admin') && strpos($_SERVER['REQUEST_URI'], '/tk/') !== false) {
258: $menu .= AlphaView::loadTemplateFragment('html', 'adminmenu.phtml', array());
259: }
260:
261: return $menu;
262: }
263: }
264:
265:
266: if(basename($_SERVER['PHP_SELF']) == 'Detail.php') {
267: $controller = new Detail();
268:
269: if(!empty($_POST)) {
270: $controller->doPOST($_REQUEST);
271: }else{
272: $controller->doGET($_GET);
273: }
274: }
275:
276: ?>