Changeset 121 for roster


Ignore:
Timestamp:
22/11/07 05:59:55 (4 years ago)
Author:
nigel.sim
Message:
  • Fixed saving issue where notes would not be editable
File:
1 edited

Legend:

Unmodified
Added
Removed
  • roster/trunk/roster.module

    r120 r121  
    2121        'type' => MENU_LOCAL_TASK 
    2222      ); 
     23      $items[] = array( 
     24        'path' => 'node/'.arg(1).'/csv', 
     25        'title' => t('csv export'), 
     26        'callback' => 'roster_csv', 
     27        'access' => user_access('assign booths'), 
     28        'type' => MENU_LOCAL_TASK 
     29      ); 
    2330    } 
    2431  } 
     
    165172  $form['submit'] = array ( 
    166173     '#type' => 'submit', 
    167      '#value' => t('Go'), 
     174     '#value' => t('Save'), 
    168175     ); 
    169176 
     
    182189  $form['person'] = array( 
    183190    '#type' => 'select', 
    184     '#title' => t(''), 
     191    '#title' => t('Working'), 
    185192    '#options' => $users, 
    186193  ); 
    187194  $form['notes'] = array( 
    188195    '#type' => 'textfield', 
    189     '#title' => t('notes') 
     196    '#title' => t('Notes') 
    190197  ); 
    191198  $form['bid'] = array( 
     
    199206  $form['save'] = array( 
    200207    '#type' => 'submit', 
    201     '#value' => t('save') 
     208    '#value' => t('Save') 
    202209  ); 
    203210  $form['aid'] = array( 
     
    207214  if ($selected != NULL){ 
    208215    $form['aid']['#value'] = $selected->aid; 
    209     $form['notes']['#value'] = $selected->notes; 
     216    $form['notes']['#default_value'] = $selected->notes; 
    210217    $form['person']['#default_value'] = $selected->person; 
    211218  } 
     
    248255 
    249256  // Format roster table for display 
    250   $table = "<table><tr><th>Booth</th><th>Morning</th><th>Afternoon</th></tr>"; 
     257  $table = "<table border='1px'><tr><th>Booth</th><th>Morning</th><th>Afternoon</th></tr>"; 
    251258  foreach ($booths as $booth){ 
    252     $table .= "<tr><td>".l($booth->name,'node/'.arg(1).'/booth/'.$booth->bid)."</td>"; 
    253     $people = ($roster[$booth->bid] != NULL)?$roster[$booth->bid][0]:NULL; 
     259    $table .= "<tr><td>".l($booth->name,'node/'.arg(1).'/booth/'.$booth->bid). 
     260      "<br/>".$booth->last_votes.'/'.$booth->last_votes_total."</td>"; 
     261     
     262    $people = ($roster[$booth->bid] != NULL && $roster[$booth->bid][0] != NULL)?$roster[$booth->bid][0]:array(); 
    254263    $table .= "<td>"; 
    255264    foreach ($people as $person) 
    256       drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, $person, $booth->bid, 0); 
     265      $table .= drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, $person, $booth->bid, 0); 
    257266    // A new one too 
    258     drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, NULL, $booth->bid, 0); 
     267    $table .= drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, NULL, $booth->bid, 0); 
    259268    $table .= "</td>"; 
    260     $people = ($roster[$booth->bid] != NULL)?$roster[$booth->bid][1]:NULL; 
     269     
     270    $people = ($roster[$booth->bid] != NULL && $roster[$booth->bid][1] != NULL)?$roster[$booth->bid][1]:array(); 
    261271    $table .= "<td>"; 
    262272    foreach ($people as $person) 
    263       drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, $person, $booth->bid, 1) 
     273      $table .= drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, $person, $booth->bid, 1); 
    264274    // A new one too 
    265     drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, NULL, $booth->bid, 1) 
     275    $table .= drupal_get_form('roster_assignment_form'.$rosterFormId++, $users, NULL, $booth->bid, 1); 
    266276    $table .= "</td>"; 
    267277    $table .= "</tr>"; 
     
    276286  $node->content['body'] = NULL; 
    277287  return $node; 
     288} 
     289 
     290function roster_csv($node, $teaser = FALSE, $page = FALSE) { 
     291  if (!user_access('assign booths')) 
     292    return FALSE; 
     293  $node = node_load(arg(1)); 
     294  // Get roster data 
     295  $booths = roster_get_booths($node->nid); 
     296  $roster = roster_get_roster($node->nid); 
     297  $_users = roster_get_group_members($node->group_id); 
     298  $users = array(''=>'None'); 
     299  foreach ($_users[0] as $contact){ 
     300    $users[$contact['contact_id']] = $contact['sort_name']; 
     301  } 
     302  drupal_set_header('Content-Type: text/csv; charset=utf-8'); 
     303  drupal_set_header('Content-Disposition: attachment; filename="roster.csv";'); 
     304 
     305  print '"Booth","Morning shift","Afternoon shift"'."\n"; 
     306  foreach ($booths as $booth){ 
     307    $morn = $roster[$booth->bid][0]; 
     308    $after = $roster[$booth->bid][1]; 
     309    print '"'.$booth->name.' '.$booth->last_votes.'/'.$booth->last_votes_total.'","'; 
     310    $once = false; 
     311    foreach ($morn as $p){ 
     312        if ($once)print ' & '; 
     313        print $users[$p->person].'('.$p->notes.')'; 
     314        $once = true; 
     315    } 
     316    print '","'; 
     317    $once = false; 
     318    foreach ($after as $p){ 
     319        if ($once)print ' & '; 
     320        print $users[$p->person].'('.$p->notes.')'; 
     321        $once = true; 
     322    } 
     323    print "\"\n"; 
     324  } 
    278325} 
    279326 
     
    322369 $sort = array('sort_name' => 'ASC'); 
    323370 
    324  $contacts =& crm_contact_search( $params, $return_properties, $sort ); 
     371 $contacts =& crm_contact_search( $params, $return_properties, $sort , 0, 200); 
    325372 if (!$contacts) return false; 
    326373 return $contacts; 
Note: See TracChangeset for help on using the changeset viewer.