2 require_once('../config.php');
6 error ('Guests can not modify tags!');
9 $mode = optional_param('mode','',PARAM_ALPHA
);
12 case 'addofficial': /// adding official tags
14 if (!isadmin() ||
!confirm_sesskey()) {
15 die('you can not add official tags');
18 if (($otag = optional_param('otag', '', PARAM_NOTAGS
)) && (!get_record('tags','text',$otag))) {
19 $tag->userid
= $USER->id
;
21 $tag->type
= 'official';
22 $tagid = insert_record('tags', $tag);
24 /// write newly added tags back into window opener
25 echo '<script language="JavaScript" type="text/javascript">
26 var o = opener.document.createElement("option");
27 o.innerHTML = "<option>'.$tag->text
.'</option>";
29 opener.document.entry[\'otags[]\'].insertBefore(o, null);
31 } else { // tag already exist
32 notify(get_string('tagalready'));
37 case 'addpersonal': /// everyone can add personal tags
38 if (!confirm_sesskey() ||
isguest() ||
!isset($USER->id
)) {
39 error ('you can not add tags');
42 if (($ptag = optional_param('ptag', '', PARAM_NOTAGS
)) && (!get_record('tags','text',$ptag))) {
43 $tag->userid
= $USER->id
;
45 $tag->type
= 'personal';
46 $tagid = insert_record('tags', $tag);
48 /// write newly added tags back into window opener
49 echo '<script language="JavaScript" type="text/javascript">
50 var o = opener.document.createElement("option");
51 o.innerHTML = "<option>'.$tag->text
.'</option>";
53 opener.document.entry[\'ptags[]\'].insertBefore(o, null);
55 } else { //tag already exist
56 notify(get_string('tagalready'));
61 case 'delete': /// delete a tag
62 if (!confirm_sesskey()) {
63 error('you can not delete tags');
66 if ($tags = optional_param('tags', 0, PARAM_INT
)) {
68 foreach ($tags as $tag) {
70 $blogtag = get_record('tags','id',$tag);
72 // you can only delete your own tags, or you have to be an admin
73 if (!isadmin() and $USER->id
!= $blogtag->userid
) {
74 notify(get_string('norighttodeletetag','blog', $blogtag->text
));
78 /// Only admin can delete tags that are referenced
79 if (!isadmin() && get_records('blog_tag_instance','tagid', $tag)) {
80 notify('tag is used by other users, can not delete!');
84 delete_records('tags','id',$tag);
85 delete_records('blog_tag_instance', 'tagid', $tag);
87 /// remove parent window option via javascript
90 while (i < window.opener.document.entry[\'otags[]\'].length) {
91 if (window.opener.document.entry[\'otags[]\'].options[i].value == '.$tag.') {
92 window.opener.document.entry[\'otags[]\'].removeChild(opener.document.entry[\'otags[]\'].options[i]);
98 while (i < window.opener.document.entry[\'ptags[]\'].length) {
99 if (window.opener.document.entry[\'ptags[]\'].options[i].value == '.$tag.') {
100 window.opener.document.entry[\'ptags[]\'].removeChild(opener.document.entry[\'ptags[]\'].options[i]);
110 default: // just displaying tags form
118 include_once('tags.html');