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:
57: class EditTags extends Edit implements AlphaControllerInterface {
58: 59: 60: 61: 62: 63:
64: private static $logger = null;
65:
66: 67: 68: 69: 70:
71: public function __construct() {
72: self::$logger = new Logger('EditTags');
73: self::$logger->debug('>>__construct()');
74:
75:
76: parent::__construct('Admin');
77:
78:
79: $this->setTitle('Editing Tags');
80: $this->setDescription('Page to edit tags.');
81: $this->setKeywords('edit,tags');
82:
83: $this->BO = new TagObject();
84:
85: self::$logger->debug('<<__construct');
86: }
87:
88: 89: 90: 91: 92: 93: 94: 95:
96: public function doGET($params) {
97: self::$logger->debug('>>doGET($params=['.var_export($params, true).'])');
98:
99: global $config;
100:
101: echo AlphaView::displayPageHead($this);
102:
103: $message = $this->getStatusMessage();
104: if(!empty($message))
105: echo $message;
106:
107:
108: if (isset($params['bo']))
109: $BOName = $params['bo'];
110: else
111: throw new IllegalArguementException('Could not load the tag objects as a bo was not supplied!');
112:
113:
114: if (isset($params['oid']))
115: $BOoid = $params['oid'];
116: else
117: throw new IllegalArguementException('Could not load the tag objects as an oid was not supplied!');
118:
119: try {
120: AlphaDAO::loadClassDef($BOName);
121: $this->BO = new $BOName;
122: $this->BO->load($BOoid);
123:
124: $tags = $this->BO->getPropObject('tags')->getRelatedObjects();
125:
126: AlphaDAO::disconnect();
127:
128: echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST" accept-charset="UTF-8">';
129: echo '<h3>The following tags were found:</h3>';
130:
131: foreach($tags as $tag) {
132: $labels = $tag->getDataLabels();
133:
134: $temp = new StringBox($tag->getPropObject('content'), $labels['content'], 'content_'.$tag->getID(), '');
135: echo $temp->render(false);
136:
137: $js = "if(window.jQuery) {
138: BootstrapDialog.show({
139: title: 'Confirmation',
140: message: 'Are you sure you wish to delete this tag?',
141: buttons: [
142: {
143: icon: 'glyphicon glyphicon-remove',
144: label: 'Cancel',
145: cssClass: 'btn btn-default btn-xs',
146: action: function(dialogItself){
147: dialogItself.close();
148: }
149: },
150: {
151: icon: 'glyphicon glyphicon-ok',
152: label: 'Okay',
153: cssClass: 'btn btn-default btn-xs',
154: action: function(dialogItself) {
155: $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID')."\"]').attr('value', '".$tag->getID()."');
156: $('#deleteForm').submit();
157: dialogItself.close();
158: }
159: }
160: ]
161: });
162: }";
163: $button = new Button($js, "Delete", "delete".$tag->getID()."But");
164: echo $button->render();
165: }
166:
167: echo '<h3>Add a new tag:</h3>';
168:
169: $temp = new StringBox(new String(), 'New tag', 'new_value', '');
170: echo $temp->render(false);
171:
172:
173: $temp = new Button('submit', 'Save', 'saveBut');
174: echo $temp->render();
175: echo ' ';
176: $temp = new Button("document.location = '".FrontController::generateSecureURL('act=Edit&bo='.$params['bo'].'&oid='.$params['oid'])."'", 'Back to Object', 'cancelBut');
177: echo $temp->render();
178:
179: echo AlphaView::renderSecurityFields();
180:
181: echo '</form>';
182:
183: echo AlphaView::renderDeleteForm();
184:
185: }catch(BONotFoundException $e) {
186: $msg = 'Unable to load the BO of id ['.$params['oid'].'], error was ['.$e->getMessage().']';
187: self::$logger->error($msg);
188: throw new FileNotFoundException($msg);
189: }
190:
191: echo AlphaView::displayPageFoot($this);
192:
193: self::$logger->debug('<<doGET');
194: }
195:
196: 197: 198: 199: 200: 201: 202: 203:
204: public function doPOST($params) {
205: self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
206:
207: try {
208:
209: if(!$this->checkSecurityFields())
210: throw new SecurityException('This page cannot accept post data from remote servers!');
211:
212:
213: if (isset($params['bo']))
214: $BOName = $params['bo'];
215: else
216: throw new IllegalArguementException('Could not load the tag objects as a bo was not supplied!');
217:
218:
219: if (isset($params['oid']))
220: $BOoid = $params['oid'];
221: else
222: throw new IllegalArguementException('Could not load the tag objects as a bo was not supplied!');
223:
224: if (isset($params['saveBut'])) {
225: try {
226: AlphaDAO::loadClassDef($BOName);
227: $this->BO = new $BOName;
228: $this->BO->load($BOoid);
229:
230: $tags = $this->BO->getPropObject('tags')->getRelatedObjects();
231:
232: AlphaDAO::begin();
233:
234: foreach ($tags as $tag) {
235: $tag->set('content', TagObject::cleanTagContent($params['content_'.$tag->getID()]));
236: $tag->save();
237: self::$logger->action('Saved tag '.$tag->get('content').' on '.$BOName.' instance with OID '.$BOoid);
238: }
239:
240:
241: if(isset($params['new_value']) && trim($params['new_value']) != '') {
242: $newTag = new TagObject();
243: $newTag->set('content', TagObject::cleanTagContent($params['new_value']));
244: $newTag->set('taggedOID', $BOoid);
245: $newTag->set('taggedClass', $BOName);
246: $newTag->save();
247: self::$logger->action('Created a new tag '.$newTag->get('content').' on '.$BOName.' instance with OID '.$BOoid);
248: }
249:
250: AlphaDAO::commit();
251:
252: $this->setStatusMessage(AlphaView::displayUpdateMessage('Tags on '.get_class($this->BO).' '.$this->BO->getID().' saved successfully.'));
253:
254: $this->doGET($params);
255: }catch (ValidationException $e) {
256: 257: 258: 259:
260: AlphaDAO::rollback();
261:
262: $this->setStatusMessage(AlphaView::displayErrorMessage('Tags on '.get_class($this->BO).' '.$this->BO->getID().' not saved due to duplicate tag values, please try again.'));
263:
264: $this->doGET($params);
265: }catch (FailedSaveException $e) {
266: self::$logger->error('Unable to save the tags of id ['.$params['oid'].'], error was ['.$e->getMessage().']');
267: AlphaDAO::rollback();
268:
269: $this->setStatusMessage(AlphaView::displayErrorMessage('Tags on '.get_class($this->BO).' '.$this->BO->getID().' not saved, please check the application logs.'));
270:
271: $this->doGET($params);
272: }
273:
274: AlphaDAO::disconnect();
275: }
276:
277: if (!empty($params['deleteOID'])) {
278: try {
279: AlphaDAO::loadClassDef($BOName);
280: $this->BO = new $BOName;
281: $this->BO->load($BOoid);
282:
283: $tag = new TagObject();
284: $tag->load($params['deleteOID']);
285: $content = $tag->get('content');
286:
287: AlphaDAO::begin();
288:
289: $tag->delete();
290:
291: self::$logger->action('Deleted tag '.$content.' on '.$BOName.' instance with OID '.$BOoid);
292:
293: AlphaDAO::commit();
294:
295: $this->setStatusMessage(AlphaView::displayUpdateMessage('Tag <em>'.$content.'</em> on '.get_class($this->BO).' '.$this->BO->getID().' deleted successfully.'));
296:
297: $this->doGET($params);
298: }catch(AlphaException $e) {
299: self::$logger->error('Unable to delete the tag of id ['.$params['deleteOID'].'], error was ['.$e->getMessage().']');
300: AlphaDAO::rollback();
301:
302: $this->setStatusMessage(AlphaView::displayErrorMessage('Tag <em>'.$content.'</em> on '.get_class($this->BO).' '.$this->BO->getID().' not deleted, please check the application logs.'));
303:
304: $this->doGET($params);
305: }
306:
307: AlphaDAO::disconnect();
308: }
309: }catch(SecurityException $e) {
310:
311: $this->setStatusMessage(AlphaView::displayErrorMessage($e->getMessage()));
312:
313: self::$logger->warn($e->getMessage());
314: }catch(IllegalArguementException $e) {
315: self::$logger->error($e->getMessage());
316: }catch(BONotFoundException $e) {
317: self::$logger->warn($e->getMessage());
318:
319: $this->setStatusMessage(AlphaView::displayErrorMessage('Failed to load the requested item from the database!'));
320: }
321:
322: self::$logger->debug('<<doPOST');
323: }
324: }
325:
326:
327: if ('EditTags.php' == basename($_SERVER['PHP_SELF'])) {
328: $controller = new EditTags();
329:
330: if(!empty($_POST)) {
331: $controller->doPOST($_REQUEST);
332: }else{
333: $controller->doGET($_GET);
334: }
335: }
336:
337: ?>