/src/plugins/projectlabels/www/index.php

https://github.com/olberger/fusionforge · PHP · 215 lines · 179 code · 27 blank · 9 comment · 35 complexity · 30f7aa67eebdaa33d793c16bd5414024 MD5 · raw file

  1. <?php
  2. /*
  3. * Project labels plugin
  4. *
  5. * Roland Mas <lolando@debian.org>
  6. */
  7. require_once '../../../www/env.inc.php';
  8. require_once $gfcommon.'include/pre.php';
  9. require_once $gfwww.'admin/admin_utils.php';
  10. site_admin_header(array('title'=>_('Project labels')));
  11. $func = getStringFromRequest ('func') ;
  12. if ($func == 'addlabel') {
  13. $label_name = addslashes (getStringFromRequest ('label_name')) ;
  14. $label_text = addslashes (getStringFromRequest ('label_text')) ;
  15. $res = db_query_params ('INSERT INTO plugin_projectlabels_labels (label_name, label_text)
  16. VALUES($1,$2)',
  17. array($label_name,
  18. $label_text));
  19. if (!$res || db_affected_rows($res) < 1) {
  20. printf (_('Cannot insert new label: %s'),
  21. db_error()) ;
  22. } else {
  23. echo _('Project label added.');
  24. }
  25. }
  26. if ($func == 'delete') {
  27. db_begin () ;
  28. $label_id = getIntFromRequest ('label_id', 0) ;
  29. $res = db_query_params ('DELETE FROM plugin_projectlabels_group_labels WHERE label_id=$1',
  30. array($label_id));
  31. if (!$res) {
  32. printf (_('Cannot delete label: %s'),
  33. db_error()) ;
  34. db_rollback () ;
  35. } else {
  36. $res = db_query_params ('DELETE FROM plugin_projectlabels_labels WHERE label_id=$1',
  37. array($label_id));
  38. if (!$res) {
  39. printf (_('Cannot delete label: %s'),
  40. db_error()) ;
  41. db_rollback () ;
  42. } else {
  43. echo _('Project label deleted.');
  44. db_commit () ;
  45. }
  46. }
  47. }
  48. if ($func == 'addlabeltoproject') {
  49. $label_id = getIntFromRequest ('label_id', 0) ;
  50. $group_uname = addslashes (getStringFromRequest ('group_uname')) ;
  51. $g = group_get_object_by_name ($group_uname) ;
  52. if ($g && !$g->isError()) {
  53. $res = db_query_params ('INSERT INTO plugin_projectlabels_group_labels (label_id, group_id) VALUES ($1, $2)',
  54. array ($label_id,
  55. $g->getID()));
  56. if (!$res || db_affected_rows($res) < 1) {
  57. printf (_('Cannot add label onto project: %s'),
  58. db_error()) ;
  59. } else {
  60. echo _('The label has been added to the project.');
  61. }
  62. } else {
  63. echo _('No such project.') ;
  64. }
  65. }
  66. if ($func == 'removelabelfromproject') {
  67. $label_id = getIntFromRequest ('label_id', 0) ;
  68. $res = db_query_params ('DELETE FROM plugin_projectlabels_group_labels WHERE label_id = $1 AND group_id = $2',
  69. array($label_id,
  70. $group_id));
  71. if (!$res) {
  72. printf (_('Cannot remove label: %s'),
  73. db_error()) ;
  74. } else {
  75. echo _('The label has been removed from the project.') ;
  76. }
  77. }
  78. if ($func == 'editlabel') {
  79. $label_id = getIntFromRequest ('label_id', 0) ;
  80. $label_name = addslashes (getStringFromRequest ('label_name')) ;
  81. $label_text = addslashes (getStringFromRequest ('label_text')) ;
  82. $res = db_query_params ('UPDATE plugin_projectlabels_labels SET label_name = $1, label_text = $2
  83. WHERE label_id=$3',
  84. array($label_name,
  85. $label_text,
  86. $label_id));
  87. if (!$res || db_affected_rows($res) < 1) {
  88. printf (_('Cannot modify label: %s'),
  89. db_error()) ;
  90. } else {
  91. echo _('Label has been saved.') ;
  92. }
  93. }
  94. if ($func == 'edit') {
  95. $label_id = getIntFromRequest ('label_id', 0) ;
  96. $res = db_query_params ('SELECT label_id, label_name, label_text FROM plugin_projectlabels_labels
  97. WHERE label_id=$1',
  98. array($label_id));
  99. $row = db_fetch_array($res) ;
  100. ?>
  101. <form name="edit_label" action="<?php echo util_make_url ('/plugins/projectlabels/') ; ?>" method="post">
  102. <input type="hidden" name="func" value="editlabel" />
  103. <input type="hidden" name="label_id" value="<?php echo $label_id ?>" />
  104. <?php echo utils_requiredField(); ?>
  105. <?php echo _('Label name:') ; ?><br/>
  106. <input type="text" size="15" maxlength="32" name="label_name" value="<?php echo stripslashes ($row['label_name']) ; ?>"/> <br/>
  107. <?php echo _('Displayed text (or HTML) for the label:') ; ?><br/>
  108. <textarea tabindex='1' accesskey="," name="label_text" rows='5'
  109. cols='80'><?php echo stripslashes($row['label_text']) ; ?></textarea><br/>
  110. <?php echo _('This label currently looks like this:') ." " . stripslashes($row['label_text']) ; ?>
  111. <input type="submit" value="<?php echo _('Save this label') ?>" />
  112. </form>
  113. <?php
  114. }
  115. ?>
  116. <p>
  117. <?php
  118. $res = db_query_params ('SELECT label_id, label_name, label_text FROM plugin_projectlabels_labels
  119. ORDER BY label_name ASC',
  120. array());
  121. if (db_numrows($res) >= 1) {
  122. echo "<h2>"._('Manage labels')."</h2>" ;
  123. echo _('You can edit the labels that you have already created.') . "<br />" ;
  124. while ($row = db_fetch_array($res)) {
  125. echo "<h3>".stripslashes ($row['label_name'])."</h3>" ;
  126. echo "<br />" . _('This label currently looks like this:') ." ";
  127. echo stripslashes ($row['label_text']) . "<br />" ;
  128. $res2 = db_query_params ('SELECT groups.unix_group_name, groups.group_name, groups.group_id FROM groups, plugin_projectlabels_group_labels
  129. WHERE plugin_projectlabels_group_labels.group_id = groups.group_id
  130. AND plugin_projectlabels_group_labels.label_id=$1
  131. ORDER BY groups.unix_group_name ASC',
  132. array ($row['label_id']));
  133. if (db_numrows($res2) >= 1) {
  134. echo ngettext ('This label is used on the following group:',
  135. 'This label is used on the following groups:',
  136. db_numrows ($res2)) ;
  137. echo "<br />";
  138. while ($row2 = db_fetch_array($res2)) {
  139. printf ('%1$s (%2$s)',
  140. $row2['group_name'],
  141. util_make_link ('/projects/'.$row2['unix_group_name'],
  142. $row2['unix_group_name'])) ;
  143. echo util_make_link ('/plugins/projectlabels/?func=removelabelfromproject&label_id='.$row['label_id']."&group_id=".$row2['group_id'],
  144. _('[Remove this label]')) . "<br />" ;
  145. }
  146. } else {
  147. echo _('This label is not used on any group.')."<br />" ;
  148. }
  149. ?>
  150. <form name="addlabeltoproject" method="post" action="<?php echo util_make_url ('/plugins/projectlabels/') ; ?>">
  151. <?php echo _('Unix name of the project:') . " " ; ?>
  152. <input type=text name=group_uname>
  153. <input type="hidden" name="func" value="addlabeltoproject">
  154. <input type="submit" value="<?php echo _('Add label to project') ?>">
  155. <input type="hidden" value="<?php echo $row['label_id'] ;?>" name=label_id>
  156. </form>
  157. <?php
  158. echo util_make_link ('/plugins/projectlabels/?func=edit&label_id='.$row['label_id'],
  159. _('[Edit this label]')) ;
  160. echo util_make_link ('/plugins/projectlabels/?func=delete&label_id='.$row['label_id'],
  161. _('[Delete this label]')) ;
  162. }
  163. }
  164. ?>
  165. </p>
  166. <p><?php
  167. echo "<h2>"._('Add new labels')."</h2>" ;
  168. echo _('You can create new labels with the form below.') ?></p>
  169. <p>
  170. <form name="new_label" action="<?php echo util_make_url ('/plugins/projectlabels/') ; ?>" method="post">
  171. <input type="hidden" name="func" value="addlabel" />
  172. <?php echo utils_requiredField(); ?>
  173. <?php echo _('Name of the label:') ; ?><br/>
  174. <input type="text" size="15" maxlength="32" name="label_name" value="<?php echo _('potm') ; ?>"/> <br/>
  175. <?php echo _('Displayed text (or HTML) for the label:') ; ?><br/>
  176. <textarea tabindex='1' accesskey="," name="label_text" rows='5'
  177. cols='80'><?php echo _('<p><b>Project of the month!</b></p>') ; ?>
  178. </textarea><br/>
  179. <input type="submit" value="<?php echo _('Add label') ?>" />
  180. </form>
  181. </p>
  182. <?php
  183. site_admin_footer(array());
  184. // Local Variables:
  185. // mode: php
  186. // c-file-style: "bsd"
  187. // End:
  188. ?>