Fixing my moodle bug in forum track posts display
[moodle.git] / blog / tags.php
CommitLineData
4a173181 1<?php
2require_once('../config.php');
3
4//form process
5
6$mode = optional_param('mode','',PARAM_ALPHA);
7
8switch ($mode) {
9 case 'addofficial':
10 if (($otag = optional_param('otag')) && (!get_record('tags','text',$otag))) {
11 $tag->userid = $USER->id;
12 $tag->text = $otag;
13 $tag->type = 'official';
14 $tagid = insert_record('tags', $tag);
15 echo '<script language="JavaScript" type="text/javascript">
16 var o = opener.document.createElement("option");
17 o.innerHTML = "<option>'.$tag->text.'</option>";
18 o.value = '.$tagid.';
19 opener.document.entry[\'otags[]\'].insertBefore(o, null);
20 </script>';
21 } else {
22 error ('there is already a tag with this name!');
23 }
24
25 break;
26
27 case 'addpersonal':
28 if (($ptag = optional_param('ptag')) && (!get_record('tags','text',$ptag))) {
29 $tag->userid = $USER->id;
30 $tag->text = $ptag;
31 $tag->type = 'personal';
32 $tagid = insert_record('tags', $tag);
33 echo '<script language="JavaScript" type="text/javascript">
34 var o = opener.document.createElement("option");
35 o.innerHTML = "<option>'.$tag->text.'</option>";
36 o.value = '.$tagid.';
37 opener.document.entry[\'ptags[]\'].insertBefore(o, null);
38 </script>';
39 } else {
40 error ('there is already a tag with this name!');
41 }
42 //write back to window.opener
43 break;
44
45 case 'delete':
46 $tags = optional_param('tags');
47 print_object($tags);
48 foreach ($tags as $tag) {
49
50 $blogtag = get_record('tags','id',$tag);
51
52 if (!isadmin() and $USER->id != $blogtag->userid) {
53 notify('no right to delete');
54 continue;
55 }
56
57 if (!isadmin() && get_records('blog_tag_instance','tagid', $tag)) {
58 notify('tag is used by other users, can not delete!');
59 continue;
60 }
61
62 delete_records('tags','id',$tag);
63 delete_records('blog_tag_instance', 'tagid', $tag);
64
65 //remove parent window option
66 echo '<script>
67 var i=0;
68 while (i < window.opener.document.entry[\'otags[]\'].length) {
69 if (window.opener.document.entry[\'otags[]\'].options[i].value == '.$tag.') {
70 window.opener.document.entry[\'otags[]\'].removeChild(opener.document.entry[\'otags[]\'].options[i]);
71 }
72 i++;
73 }
74
75 var i=0;
76 while (i < window.opener.document.entry[\'ptags[]\'].length) {
77 if (window.opener.document.entry[\'ptags[]\'].options[i].value == '.$tag.') {
78 window.opener.document.entry[\'ptags[]\'].removeChild(opener.document.entry[\'ptags[]\'].options[i]);
79 }
80 i++;
81 }
82
83 </script>';
84 }
85 //write back to window.opener
86 break;
87
88 default:
89 break;
90}
91
92//print the table
93
94print_header();
95
96include_once('tags.html');
97
98print_footer();
99
100
101?>