3 * Project labels plugin
5 * Roland Mas <lolando@debian.org>
8 require_once '../../../www/env.inc.php';
9 require_once $gfcommon.'include/pre.php';
10 require_once $gfwww.'admin/admin_utils.php';
12 site_admin_header(array('title'=>_('Project labels')));
14 $func = getStringFromRequest ('func') ;
16 if ($func == 'addlabel') {
17 $label_name = addslashes (getStringFromRequest ('label_name')) ;
18 $label_text = addslashes (getStringFromRequest ('label_text')) ;
19 $res = db_query_params ('INSERT INTO plugin_projectlabels_labels (label_name, label_text)
24 if (!$res || db_affected_rows($res) < 1) {
25 printf (_('Cannot insert new label: %s'),
28 echo _('Project label added.');
32 if ($func == 'delete') {
34 $label_id = getIntFromRequest ('label_id', 0) ;
35 $res = db_query_params ('DELETE FROM plugin_projectlabels_group_labels WHERE label_id=$1',
39 printf (_('Cannot delete label: %s'),
43 $res = db_query_params ('DELETE FROM plugin_projectlabels_labels WHERE label_id=$1',
47 printf (_('Cannot delete label: %s'),
51 echo _('Project label deleted.');
57 if ($func == 'addlabeltoproject') {
58 $label_id = getIntFromRequest ('label_id', 0) ;
59 $group_uname = addslashes (getStringFromRequest ('group_uname')) ;
60 $g = group_get_object_by_name ($group_uname) ;
62 if ($g && !$g->isError()) {
64 $res = db_query_params ('INSERT INTO plugin_projectlabels_group_labels (label_id, group_id) VALUES ($1, $2)',
68 if (!$res || db_affected_rows($res) < 1) {
69 printf (_('Cannot add label onto project: %s'),
72 echo _('The label has been added to the project.');
75 echo _('No such project.') ;
79 if ($func == 'removelabelfromproject') {
80 $label_id = getIntFromRequest ('label_id', 0) ;
81 $res = db_query_params ('DELETE FROM plugin_projectlabels_group_labels WHERE label_id = $1 AND group_id = $2',
86 printf (_('Cannot remove label: %s'),
89 echo _('The label has been removed from the project.') ;
93 if ($func == 'editlabel') {
94 $label_id = getIntFromRequest ('label_id', 0) ;
95 $label_name = addslashes (getStringFromRequest ('label_name')) ;
96 $label_text = addslashes (getStringFromRequest ('label_text')) ;
97 $res = db_query_params ('UPDATE plugin_projectlabels_labels SET label_name = $1, label_text = $2
102 if (!$res || db_affected_rows($res) < 1) {
103 printf (_('Cannot modify label: %s'),
106 echo _('Label has been saved.') ;
109 if ($func == 'edit') {
110 $label_id = getIntFromRequest ('label_id', 0) ;
111 $res = db_query_params ('SELECT label_id, label_name, label_text FROM plugin_projectlabels_labels
114 $row = db_fetch_array($res) ;
116 <form name="edit_label" action="<?php echo util_make_url ('/plugins/projectlabels/') ; ?>" method="post">
117 <input type="hidden" name="func" value="editlabel" />
118 <input type="hidden" name="label_id" value="<?php echo $label_id ?>" />
119 <?php echo utils_requiredField(); ?>
120 <?php echo _('Label name:') ; ?><br/>
121 <input type="text" size="15" maxlength="32" name="label_name" value="<?php echo stripslashes ($row['label_name']) ; ?>"/> <br/>
122 <?php echo _('Displayed text (or HTML) for the label:') ; ?><br/>
123 <textarea tabindex='1' accesskey="," name="label_text" rows='5'
124 cols='80'><?php echo stripslashes($row['label_text']) ; ?></textarea><br/>
125 <?php echo _('This label currently looks like this:') ." " . stripslashes($row['label_text']) ; ?>
126 <input type="submit" value="<?php echo _('Save this label') ?>" />
135 $res = db_query_params ('SELECT label_id, label_name, label_text FROM plugin_projectlabels_labels
136 ORDER BY label_name ASC',
139 if (db_numrows($res) >= 1) {
140 echo "<h2>"._('Manage labels')."</h2>" ;
141 echo _('You can edit the labels that you have already created.') . "<br />" ;
143 while ($row = db_fetch_array($res)) {
144 echo "<h3>".stripslashes ($row['label_name'])."</h3>" ;
145 echo "<br />" . _('This label currently looks like this:') ." ";
146 echo stripslashes ($row['label_text']) . "<br />" ;
148 $res2 = db_query_params ('SELECT groups.unix_group_name, groups.group_name, groups.group_id FROM groups, plugin_projectlabels_group_labels
149 WHERE plugin_projectlabels_group_labels.group_id = groups.group_id
150 AND plugin_projectlabels_group_labels.label_id=$1
151 ORDER BY groups.unix_group_name ASC',
152 array ($row['label_id']));
153 if (db_numrows($res2) >= 1) {
154 echo ngettext ('This label is used on the following group:',
155 'This label is used on the following groups:',
156 db_numrows ($res2)) ;
159 while ($row2 = db_fetch_array($res2)) {
160 printf ('%1$s (%2$s)',
162 util_make_link ('/projects/'.$row2['unix_group_name'],
163 $row2['unix_group_name'])) ;
164 echo util_make_link ('/plugins/projectlabels/?func=removelabelfromproject&label_id='.$row['label_id']."&group_id=".$row2['group_id'],
165 _('[Remove this label]')) . "<br />" ;
168 echo _('This label is not used on any group.')."<br />" ;
171 <form name="addlabeltoproject" method="post" action="<?php echo util_make_url ('/plugins/projectlabels/') ; ?>">
172 <?php echo _('Unix name of the project:') . " " ; ?>
173 <input type=text name=group_uname>
174 <input type="hidden" name="func" value="addlabeltoproject">
175 <input type="submit" value="<?php echo _('Add label to project') ?>">
176 <input type="hidden" value="<?php echo $row['label_id'] ;?>" name=label_id>
179 echo util_make_link ('/plugins/projectlabels/?func=edit&label_id='.$row['label_id'],
180 _('[Edit this label]')) ;
181 echo util_make_link ('/plugins/projectlabels/?func=delete&label_id='.$row['label_id'],
182 _('[Delete this label]')) ;
190 echo "<h2>"._('Add new labels')."</h2>" ;
191 echo _('You can create new labels with the form below.') ?></p>
194 <form name="new_label" action="<?php echo util_make_url ('/plugins/projectlabels/') ; ?>" method="post">
195 <input type="hidden" name="func" value="addlabel" />
196 <?php echo utils_requiredField(); ?>
197 <?php echo _('Name of the label:') ; ?><br/>
198 <input type="text" size="15" maxlength="32" name="label_name" value="<?php echo _('potm') ; ?>"/> <br/>
199 <?php echo _('Displayed text (or HTML) for the label:') ; ?><br/>
200 <textarea tabindex='1' accesskey="," name="label_text" rows='5'
201 cols='80'><?php echo _('<p><b>Project of the month!</b></p>') ; ?>
203 <input type="submit" value="<?php echo _('Add label') ?>" />
208 site_admin_footer(array());
212 // c-file-style: "bsd"