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:
104: if (isset($params['bo']))
105: $BOName = $params['bo'];
106: else
107: throw new IllegalArguementException('Could not load the tag objects as a bo was not supplied!');
108:
109:
110: if (isset($params['oid']))
111: $BOoid = $params['oid'];
112: else
113: throw new IllegalArguementException('Could not load the tag objects as an oid was not supplied!');
114:
115: try {
116: AlphaDAO::loadClassDef($BOName);
117: $this->BO = new $BOName;
118: $this->BO->load($BOoid);
119:
120: $tags = $this->BO->getPropObject('tags')->getRelatedObjects();
121:
122: AlphaDAO::disconnect();
123:
124: echo '<table cols="3" class="edit_view">';
125: echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST">';
126: echo '<tr><td colspan="3"><h3>The following tags were found:</h3></td></tr>';
127:
128: foreach($tags as $tag) {
129: echo '<tr><td>';
130: $labels = $tag->getDataLabels();
131: echo $labels['content'];
132: echo '</td><td>';
133:
134: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('content_'.$tag->getID())) : 'content_'.$tag->getID());
135: $temp = new StringBox($tag->getPropObject('content'), $labels['content'], $fieldname, '');
136: echo $temp->render(false);
137: echo '</td><td>';
138:
139: $js = "$('#dialogDiv').text('Are you sure you wish to delete this tag?');
140: $('#dialogDiv').dialog({
141: buttons: {
142: 'OK': function(event, ui) {
143: $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID')."\"]').attr('value', '".$this->BO->getOID()."');
144: $('#deleteForm').submit();
145: },
146: 'Cancel': function(event, ui) {
147: $(this).dialog('close');
148: }
149: }
150: })
151: $('#dialogDiv').dialog('open');
152: return false;";
153: $button = new Button($js, "Delete", "delete".$tag->getID()."But");
154: echo $button->render().'</td></tr>';
155: }
156:
157: echo '<tr><td colspan="3"><h3>Add a new tag:</h3></td></tr>';
158: echo '<tr><td>';
159: echo 'New tag';
160: echo '</td><td>';
161: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('new_value')) : 'new_value');
162: $temp = new StringBox(new String(), 'New tag', $fieldname, '');
163: echo $temp->render(false);
164: echo '</td><td></td></tr>';
165:
166: echo '<tr><td colspan="3">';
167:
168: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('saveBut')) : 'saveBut');
169: $temp = new Button('submit', 'Save', $fieldname);
170: echo $temp->render();
171: echo ' ';
172: $temp = new Button("document.location = '".FrontController::generateSecureURL('act=Edit&bo='.$params['bo'].'&oid='.$params['oid'])."'", 'Back to Object', 'cancelBut');
173: echo $temp->render();
174: echo '</td></tr>';
175:
176: echo AlphaView::renderSecurityFields();
177:
178: echo '</form></table>';
179:
180: echo AlphaView::renderDeleteForm();
181:
182: }catch(BONotFoundException $e) {
183: $msg = 'Unable to load the BO of id ['.$params['oid'].'], error was ['.$e->getMessage().']';
184: self::$logger->error($msg);
185: throw new FileNotFoundException($msg);
186: }
187:
188: echo AlphaView::displayPageFoot($this);
189:
190: self::$logger->debug('<<doGET');
191: }
192:
193: 194: 195: 196: 197: 198: 199: 200:
201: public function doPOST($params) {
202: self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
203:
204: try {
205:
206: if(!$this->checkSecurityFields())
207: throw new SecurityException('This page cannot accept post data from remote servers!');
208:
209:
210: if (isset($params['bo']))
211: $BOName = $params['bo'];
212: else
213: throw new IllegalArguementException('Could not load the tag objects as a bo was not supplied!');
214:
215:
216: if (isset($params['oid']))
217: $BOoid = $params['oid'];
218: else
219: throw new IllegalArguementException('Could not load the tag objects as a bo was not supplied!');
220:
221: if (isset($params['saveBut'])) {
222: try {
223: AlphaDAO::loadClassDef($BOName);
224: $this->BO = new $BOName;
225: $this->BO->load($BOoid);
226:
227: $tags = $this->BO->getPropObject('tags')->getRelatedObjects();
228:
229: AlphaDAO::begin();
230:
231: foreach ($tags as $tag) {
232: $tag->set('content', TagObject::cleanTagContent($params['content_'.$tag->getID()]));
233: $tag->save();
234: self::$logger->action('Saved tag '.$tag->get('content').' on '.$BOName.' instance with OID '.$BOoid);
235: }
236:
237:
238: if(isset($params['new_value']) && trim($params['new_value']) != '') {
239: $newTag = new TagObject();
240: $newTag->set('content', TagObject::cleanTagContent($params['new_value']));
241: $newTag->set('taggedOID', $BOoid);
242: $newTag->set('taggedClass', $BOName);
243: $newTag->save();
244: self::$logger->action('Created a new tag '.$newTag->get('content').' on '.$BOName.' instance with OID '.$BOoid);
245: }
246:
247: AlphaDAO::commit();
248:
249: $this->setStatusMessage(AlphaView::displayUpdateMessage('Tags on '.get_class($this->BO).' '.$this->BO->getID().' saved successfully.'));
250:
251: $this->doGET($params);
252: }catch (ValidationException $e) {
253: 254: 255: 256:
257: AlphaDAO::rollback();
258:
259: $this->setStatusMessage(AlphaView::displayErrorMessage('Tags on '.get_class($this->BO).' '.$this->BO->getID().' not saved due to duplicate tag values, please try again.'));
260:
261: $this->doGET($params);
262: }catch (FailedSaveException $e) {
263: self::$logger->error('Unable to save the tags of id ['.$params['oid'].'], error was ['.$e->getMessage().']');
264: AlphaDAO::rollback();
265:
266: $this->setStatusMessage(AlphaView::displayErrorMessage('Tags on '.get_class($this->BO).' '.$this->BO->getID().' not saved, please check the application logs.'));
267:
268: $this->doGET($params);
269: }
270:
271: AlphaDAO::disconnect();
272: }
273:
274: if (!empty($params['deleteOID'])) {
275: try {
276: AlphaDAO::loadClassDef($BOName);
277: $this->BO = new $BOName;
278: $this->BO->load($BOoid);
279:
280: $tag = new TagObject();
281: $tag->load($params['deleteOID']);
282: $content = $tag->get('content');
283:
284: AlphaDAO::begin();
285:
286: $tag->delete();
287:
288: self::$logger->action('Deleted tag '.$content.' on '.$BOName.' instance with OID '.$BOoid);
289:
290: AlphaDAO::commit();
291:
292: $this->setStatusMessage(AlphaView::displayUpdateMessage('Tag <em>'.$content.'</em> on '.get_class($this->BO).' '.$this->BO->getID().' deleted successfully.'));
293:
294: $this->doGET($params);
295: }catch(AlphaException $e) {
296: self::$logger->error('Unable to delete the tag of id ['.$params['deleteOID'].'], error was ['.$e->getMessage().']');
297: AlphaDAO::rollback();
298:
299: $this->setStatusMessage(AlphaView::displayErrorMessage('Tag <em>'.$content.'</em> on '.get_class($this->BO).' '.$this->BO->getID().' not deleted, please check the application logs.'));
300:
301: $this->doGET($params);
302: }
303:
304: AlphaDAO::disconnect();
305: }
306: }catch(SecurityException $e) {
307:
308: $this->setStatusMessage(AlphaView::displayErrorMessage($e->getMessage()));
309:
310: self::$logger->warn($e->getMessage());
311: }catch(IllegalArguementException $e) {
312: self::$logger->error($e->getMessage());
313: }catch(BONotFoundException $e) {
314: self::$logger->warn($e->getMessage());
315:
316: $this->setStatusMessage(AlphaView::displayErrorMessage('Failed to load the requested item from the database!'));
317: }
318:
319: self::$logger->debug('<<doPOST');
320: }
321:
322: 323: 324: 325: 326: 327:
328: public function during_displayPageHead_callback() {
329: $html = '';
330: $html .= '<script language="javascript">';
331: $html .= 'function clearNewField() {';
332: $html .= ' document.getElementById("new_value").value = "";';
333: $html .= '}';
334: $html .= 'addOnloadEvent(clearNewField);';
335: $html .= '</script>';
336: return $html;
337: }
338: }
339:
340:
341: if ('EditTags.php' == basename($_SERVER['PHP_SELF'])) {
342: $controller = new EditTags();
343:
344: if(!empty($_POST)) {
345: $controller->doPOST($_REQUEST);
346: }else{
347: $controller->doGET($_GET);
348: }
349: }
350:
351: ?>