| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: project_edit_issues.inc,v 1.3 2009/08/21 21:58:23 dww Exp $ 3 4 /** 5 * @file 6 * Code for the "issues" subtab to the edit tab on project nodes. 7 */ 8 9 /** 10 * Page callback for the "issues" subtab to the edit tab on project nodes. 11 */ 12 function project_issue_project_edit_issues($node) { 13 project_project_set_breadcrumb($node); 14 drupal_set_title(check_plain($node->title)); 15 return drupal_get_form('project_issue_project_edit_form', $node); 16 } 17 18 /** 19 * Theme function to render the issue subtab form. 20 */ 21 function theme_project_issue_project_edit_form($form) { 22 drupal_add_tabledrag('project-issue-edit-project-components-table', 'order', 'self', 'project-issue-component-weight'); 23 24 $header = array( 25 array('data' => t('Name')), 26 array('data' => t('Weight')), 27 array('data' => t('Operations')) 28 ); 29 // List the existing components. 30 foreach (element_children($form['component']) as $key) { 31 $rows[] = array( 32 'class' => 'draggable', 33 'data' => array( 34 drupal_render($form['component'][$key]['name']), 35 drupal_render($form['component'][$key]['weight']), 36 drupal_render($form['component'][$key]['delete']), 37 ), 38 ); 39 } 40 // Add a row to add a new component. 41 $rows[] = array( 42 'class' => 'draggable', 43 'data' => array( 44 drupal_render($form['component_add']['name']), 45 drupal_render($form['component_add']['weight']), 46 NULL, 47 ), 48 ); 49 50 $output = drupal_render($form['issue']); 51 $output .= drupal_render($form['email']); 52 $output .= '<h3>' . t('Issue components') . '</h3>'; 53 $output .= '<div>' . theme('table', $header, $rows, array('id' => 'project-issue-edit-project-components-table')) . '</div>'; 54 $output .= drupal_render($form); 55 return $output; 56 } 57 58 /** 59 * Form builder for the issues subtab on the edit tab for project nodes. 60 */ 61 function project_issue_project_edit_form(&$form_state, $node) { 62 /* Issue properties */ 63 $form['issue'] = array( 64 '#type' => 'fieldset', 65 '#title' => t('Issue information'), 66 '#collapsible' => TRUE, 67 ); 68 $form['issue']['issue'] = array( 69 '#type' => 'item', 70 '#title' => t('Issue tracker'), 71 ); 72 $form['issue']['issues'] = array( 73 '#type' => 'checkbox', 74 '#title' => t('Enable issue tracker'), 75 '#return_value' => 1, 76 '#default_value' => isset($node->project_issue['issues']) ? $node->project_issue['issues'] : 1, 77 '#description' => t('Let users submit bug requests, patches, feature requests, support requests, etc.'), 78 ); 79 $form['issue']['help'] = array( 80 '#type' => 'textarea', 81 '#title' => t('Submission guidelines'), 82 '#default_value' => isset($node->project_issue['help']) ? $node->project_issue['help'] : NULL, 83 '#cols' => 20, 84 '#rows' => 5, 85 ); 86 87 $weight = 0; 88 $default_component_options[0] = t('<none> (user must select)'); 89 $form['component']['#tree'] = TRUE; 90 $number_components = count($node->project_issue['components']); 91 $delta = max(20, $number_components + 10); 92 foreach ($node->project_issue['components'] as $component) { 93 $default_component_options[$component] = $component; 94 $form['component'][$component]['name'] = array( 95 '#type' => 'textfield', 96 '#default_value' => $component, 97 '#size' => 20, 98 ); 99 $form['component'][$component]['weight'] = array( 100 '#type' => 'weight', 101 '#default_value' => $weight, 102 '#delta' => $delta, 103 '#attributes' => array('class' => 'project-issue-component-weight'), 104 ); 105 // For the delete links, we just need the offset of the component as 106 // currently stored in the DB or node. So, we can just use the $weight. 107 // Using an integer offset avoids problems with urlencoding for component 108 // names that have '/' in them. 109 $del_link = ($component != $node->project_issue['default_component']) ? l(t('Delete'), 'node/'. $node->nid .'/edit/component/delete/'. $weight) : ''; 110 $form['component'][$component]['delete'] = array( 111 '#type' => 'markup', 112 '#value' => $del_link, 113 ); 114 $weight++; 115 } 116 $form['component_add']['#tree'] = TRUE; 117 $form['component_add']['name'] = array( 118 '#type' => 'textfield', 119 '#size' => 20, 120 ); 121 $form['component_add']['weight'] = array( 122 '#type' => 'weight', 123 '#default_value' => $weight, 124 '#delta' => $delta, 125 '#attributes' => array('class' => 'project-issue-component-weight'), 126 ); 127 $form['default_component'] = array( 128 '#type' => 'select', 129 '#title' => t('Default component for new issues'), 130 '#options' => $default_component_options, 131 '#default_value' => !empty($node->project_issue['default_component']) ? $node->project_issue['default_component'] : 0, 132 ); 133 134 /* E-mail options */ 135 $form['email'] = array( 136 '#type' => 'fieldset', 137 '#title' => t('Issue e-mail options'), 138 '#collapsible' => TRUE, 139 '#collapsed' => TRUE, 140 ); 141 $form['email']['mail_digest'] = array( 142 '#type' => 'textfield', 143 '#title' => t('Weekly critical issues report'), 144 '#default_value' => isset($node->project_issue['mail_digest']) ? $node->project_issue['mail_digest'] : NULL, 145 '#size' => 20, 146 '#maxlength' => 255, 147 '#description' => t('To get a weekly digest of critical issues specify an e-mail address.'), 148 ); 149 $form['email']['mail_copy'] = array( 150 '#type' => 'textfield', 151 '#title' => t('Issues e-mail address'), 152 '#default_value' => isset($node->project_issue['mail_copy']) ? $node->project_issue['mail_copy'] : NULL, 153 '#size' => 20, 154 '#maxlength' => 255, 155 '#description' => t('If you wish to receive a copy of all the issues to a central location specify an address here. <em>Note: the copy will contain links to file attachments.</em>'), 156 ); 157 $options = project_issue_category(); 158 $form['email']['categories'] = array( 159 '#type' => 'item', 160 '#title' => t('Categories'), 161 '#description' => t('Which issue categories to e-mail. If none is checked all categories will be posted.'), 162 ); 163 $form['email']['mail_copy_filter']['#tree'] = TRUE; 164 165 foreach ($options as $key => $choice) { 166 $form['email']['mail_copy_filter'][$key] = array( 167 '#type' => 'checkbox', 168 '#title' => $choice, 169 '#return_value' => $key, 170 '#default_value' => isset($node->project_issue['mail_copy_filter'][$key]) ? $node->project_issue['mail_copy_filter'][$key] : NULL, 171 ); 172 } 173 $options = project_issue_state(); 174 $form['email']['states'] = array( 175 '#type' => 'item', 176 '#title' => t('States'), 177 '#description' => t('Which issue states to e-mail. If none is checked all states will be posted.'), 178 ); 179 $form['email']['mail_copy_filter_state']['#tree'] = TRUE; 180 foreach ($options as $key => $choice) { 181 $form['email']['mail_copy_filter_state'][$key] = array( 182 '#type' => 'checkbox', 183 '#title' => check_plain($choice), 184 '#return_value' => $key, 185 '#default_value' => isset($node->project_issue['mail_copy_filter_state'][$key]) ? $node->project_issue['mail_copy_filter_state'][$key] : NULL, 186 ); 187 } 188 189 if (user_access('administer projects')) { 190 $form['email']['reminder'] = array( 191 '#type' => 'item', 192 '#title' => t('Monthly reminder'), 193 ); 194 $form['email']['mail_reminder'] = array( 195 '#type' => 'checkbox', 196 '#title' => t('Send monthly reminders to users'), 197 '#return_value' => 1, 198 '#default_value' => isset($node->project_issue['mail_reminder']) ? $node->project_issue['mail_reminder'] : NULL, 199 '#description' => t('Enabling this will send a monthly reminder to users that have open issues registered.'), 200 ); 201 } 202 203 $form['nid'] = array('#type' => 'value', '#value' => $node->nid); 204 $form['submit'] = array( 205 '#type' => 'submit', 206 '#value' => t('Save'), 207 '#weight' => 45, 208 ); 209 210 return $form; 211 } 212 213 /** 214 * Validation handler when project admins use the issues subtab. 215 * @see project_issue_project_edit_issues 216 */ 217 function project_issue_project_edit_form_validate($form, &$form_state) { 218 if (!empty($form_state['values']['mail_digest']) && ($data = user_validate_mail($form_state['values']['mail_digest']))) { 219 form_set_error('mail_digest', $data); 220 } 221 if (!empty($form_state['values']['mail_copy']) && ($data = user_validate_mail($form_state['values']['mail_copy']))) { 222 form_set_error('mail_copy', $data); 223 } 224 } 225 226 /** 227 * Submit handler when project admins use the issues subtab. 228 * @see project_issue_project_edit_issues 229 */ 230 function project_issue_project_edit_form_submit($form, &$form_state) { 231 $components = array(); 232 if (!empty($form_state['values']['component_add']['name'])) { 233 $components[trim($form_state['values']['component_add']['name'])] = $form_state['values']['component_add']['weight']; 234 } 235 if (!empty($form_state['values']['component'])) { 236 foreach ($form_state['values']['component'] as $component) { 237 $components[trim($component['name'])] = $component['weight']; 238 } 239 } 240 asort($components); 241 $components = serialize(array_keys($components)); 242 $default_component = !empty($form_state['values']['default_component']) ? $form_state['values']['default_component'] : ''; 243 $mail_copy_filter = serialize($form_state['values']['mail_copy_filter']); 244 $mail_copy_filter_state = serialize($form_state['values']['mail_copy_filter_state']); 245 246 db_query("UPDATE {project_issue_projects} SET issues = %d, components = '%s',default_component = '%s', mail_digest = '%s', mail_reminder = %d, mail_copy = '%s', mail_copy_filter = '%s', mail_copy_filter_state = '%s', help = '%s' WHERE nid = %d", $form_state['values']['issues'], $components, $default_component, $form_state['values']['mail_digest'], $form_state['values']['mail_reminder'], $form_state['values']['mail_copy'], $mail_copy_filter, $mail_copy_filter_state, $form_state['values']['help'], $form_state['values']['nid']); 247 db_query("UPDATE {node} SET changed = %d WHERE nid = %d", time(), $form_state['values']['nid']); 248 drupal_set_message(t('Issue settings have been saved.')); 249 } 250 251 function project_issue_component_delete_form($form_state, $project, $component_offset) { 252 $component = $project->project_issue['components'][$component_offset]; 253 $form['component'] = array( 254 '#type' => 'value', 255 '#value' => $component, 256 ); 257 $form['project'] = array( 258 '#type' => 'value', 259 '#value' => $project, 260 ); 261 return confirm_form( 262 $form, 263 t('Are you sure you want to delete the component %component?', array('%component' => $component)), 264 'node/' . $project->nid . '/edit/issues', 265 t('This action cannot be undone.'), 266 t('Delete'), t('Cancel') 267 ); 268 } 269 270 function project_issue_component_delete_form_submit($form, &$form_state) { 271 $project = $form_state['values']['project']; 272 $component = $form_state['values']['component']; 273 project_issue_delete_component($project, $component); 274 drupal_set_message(t('Issue component %component deleted.', array('%component' => $component))); 275 $form_state['redirect'] = 'node/' . $project->nid . '/edit/issues'; 276 } 277 278 /** 279 * Remove a component from a given project. 280 * 281 * @param $project 282 * The project to remove the component from. 283 * @param $component 284 * The component to remove. 285 */ 286 function project_issue_delete_component($project, $component) { 287 $components = array_diff($project->project_issue['components'], array($component)); 288 db_query("UPDATE {project_issue_projects} SET components = '%s' WHERE nid = %d", serialize($components), $project->nid); 289 db_query("UPDATE {node} SET changed = %d WHERE nid = %d", time(), $project->nid); 290 } 291 292
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |