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 Detail extends AlphaController implements AlphaControllerInterface {
57: 58: 59: 60: 61: 62:
63: protected $BO;
64:
65: 66: 67: 68: 69: 70:
71: private $BOName;
72:
73: 74: 75: 76: 77: 78:
79: private $BOView;
80:
81: 82: 83: 84: 85: 86:
87: private static $logger = null;
88:
89: 90: 91: 92: 93: 94:
95: public function __construct($visibility='Standard') {
96: self::$logger = new Logger('Detail');
97: self::$logger->debug('>>__construct()');
98:
99: global $config;
100:
101:
102: parent::__construct($visibility);
103:
104: self::$logger->debug('<<__construct');
105: }
106:
107: 108: 109: 110: 111: 112: 113: 114:
115: public function doGET($params) {
116: self::$logger->debug('>>doGET(params=['.var_export($params, true).'])');
117:
118: try{
119:
120: if (isset($params['bo']) && isset($params['oid'])) {
121: if(!AlphaValidator::isInteger($params['oid']))
122: throw new IllegalArguementException('Invalid oid ['.$params['oid'].'] provided on the request!');
123:
124: $BOName = $params['bo'];
125: AlphaDAO::loadClassDef($BOName);
126:
127: 128: 129:
130: if($this->getCustomControllerName($BOName, 'view') != null)
131: $this->loadCustomController($BOName, 'view');
132:
133: $this->BO = new $BOName();
134: $this->BO->load($params['oid']);
135: AlphaDAO::disconnect();
136:
137: $this->BOName = $BOName;
138: $this->BOView = AlphaView::getInstance($this->BO);
139:
140: echo AlphaView::displayPageHead($this);
141: echo AlphaView::renderDeleteForm();
142: echo $this->BOView->detailedView();
143: }else{
144: throw new IllegalArguementException('No BO available to display!');
145: }
146: }catch(IllegalArguementException $e) {
147: self::$logger->warn($e->getMessage());
148: throw new ResourceNotFoundException('The file that you have requested cannot be found!');
149: }catch(BONotFoundException $e) {
150: self::$logger->warn($e->getMessage());
151: throw new ResourceNotFoundException('The item that you have requested cannot be found!');
152: }
153:
154: echo AlphaView::displayPageFoot($this);
155: self::$logger->debug('<<doGET');
156: }
157:
158: 159: 160: 161: 162: 163: 164: 165:
166: public function doPOST($params) {
167: self::$logger->debug('>>doPOST(params=['.var_export($params, true).'])');
168:
169: global $config;
170:
171: echo AlphaView::displayPageHead($this);
172:
173: try {
174:
175: if(!$this->checkSecurityFields())
176: throw new SecurityException('This page cannot accept post data from remote servers!');
177:
178:
179: if (isset($params['bo'])) {
180: $BOName = $params['bo'];
181: AlphaDAO::loadClassDef($BOName);
182:
183: $this->BO = new $BOName();
184: $this->BOname = $BOName;
185: $this->BOView = AlphaView::getInstance($this->BO);
186:
187: if (!empty($params['deleteOID'])) {
188: if(!AlphaValidator::isInteger($params['deleteOID']))
189: throw new IllegalArguementException('Invalid deleteOID ['.$params['deleteOID'].'] provided on the request!');
190:
191: $temp = new $BOName();
192: $temp->load($params['deleteOID']);
193:
194: try {
195: AlphaDAO::begin();
196: $temp->delete();
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: ?>