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