Moved some strings!
[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':
9154b440 10
11 if (!isadmin() || !confirm_sesskey()) {
12 die('you can not add official tags');
13 }
14
4a173181 15 if (($otag = optional_param('otag')) && (!get_record('tags','text',$otag))) {
16 $tag->userid = $USER->id;
17 $tag->text = $otag;
18 $tag->type = 'official';
19 $tagid = insert_record('tags', $tag);
20 echo '<script language="JavaScript" type="text/javascript">
21 var o = opener.document.createElement("option");
22 o.innerHTML = "<option>'.$tag->text.'</option>";
23 o.value = '.$tagid.';
24 opener.document.entry[\'otags[]\'].insertBefore(o, null);
25 </script>';
26 } else {
27 error ('there is already a tag with this name!');
28 }
29
30 break;
31
9154b440 32 case 'addpersonal': /// everyone can add
33 if (!confirm_sesskey() || isguest() || !isset($USER->id)) {
34 error ('you can not add tags');
35 }
36
4a173181 37 if (($ptag = optional_param('ptag')) && (!get_record('tags','text',$ptag))) {
38 $tag->userid = $USER->id;
39 $tag->text = $ptag;
40 $tag->type = 'personal';
41 $tagid = insert_record('tags', $tag);
42 echo '<script language="JavaScript" type="text/javascript">
43 var o = opener.document.createElement("option");
44 o.innerHTML = "<option>'.$tag->text.'</option>";
45 o.value = '.$tagid.';
46 opener.document.entry[\'ptags[]\'].insertBefore(o, null);
47 </script>';
48 } else {
49 error ('there is already a tag with this name!');
50 }
51 //write back to window.opener
52 break;
53
54 case 'delete':
9154b440 55 if (!confirm_sesskey()) {
56 error('you can not delete tags');
57 }
58
4a173181 59 $tags = optional_param('tags');
60 print_object($tags);
61 foreach ($tags as $tag) {
62
63 $blogtag = get_record('tags','id',$tag);
64
65 if (!isadmin() and $USER->id != $blogtag->userid) {
66 notify('no right to delete');
67 continue;
68 }
69
9154b440 70 /// Only admin can delete tags that are referenced
4a173181 71 if (!isadmin() && get_records('blog_tag_instance','tagid', $tag)) {
72 notify('tag is used by other users, can not delete!');
73 continue;
74 }
75
76 delete_records('tags','id',$tag);
77 delete_records('blog_tag_instance', 'tagid', $tag);
78
9154b440 79 /// remove parent window option via javascript
4a173181 80 echo '<script>
81 var i=0;
82 while (i < window.opener.document.entry[\'otags[]\'].length) {
83 if (window.opener.document.entry[\'otags[]\'].options[i].value == '.$tag.') {
84 window.opener.document.entry[\'otags[]\'].removeChild(opener.document.entry[\'otags[]\'].options[i]);
85 }
86 i++;
87 }
88
89 var i=0;
90 while (i < window.opener.document.entry[\'ptags[]\'].length) {
91 if (window.opener.document.entry[\'ptags[]\'].options[i].value == '.$tag.') {
92 window.opener.document.entry[\'ptags[]\'].removeChild(opener.document.entry[\'ptags[]\'].options[i]);
93 }
94 i++;
95 }
96
97 </script>';
98 }
99 //write back to window.opener
100 break;
101
102 default:
103 break;
104}
105
106//print the table
107
108print_header();
109
110include_once('tags.html');
111
112print_footer();
113
114
115?>