Changeset 73


Ignore:
Timestamp:
Jan 7, 2007 4:13:31 AM (6 years ago)
Author:
dkg
Message:

JPDD: made it so an admin can add/remove presenters from a workshop.

Location:
trunk/jpdd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/jpdd/class.jpdd.workshop.php

    r72 r73  
    1414          return array('Update Workshops'); 
    1515        } 
    16          
    1716        function getEditPrivilege() { 
    1817          return array('Update Workshops'); 
     18        } 
     19 
     20        function getNonAttendees($flavor) { 
     21          global $jpdd; 
     22          $jpdd->prepClass('person'); 
     23          return $jpdd->getSeriesFromSQL('SELECT person.* FROM person LEFT JOIN (SELECT * FROM attendance WHERE workshop_id = '.$this->getID().' AND flavor = '.$jpdd->escStr($flavor).') AS attendance ON (person.id = attendance.person_id) WHERE workshop_id IS NULL', 'JPDD_Person'); 
    1924        } 
    2025 
     
    2530        } 
    2631 
     32        function addAttendees($ids, $flavor) { 
     33          global $jpdd; 
     34          if (!is_array($ids)) { 
     35                if ($jpdd->isEmpty($ids)) 
     36                  return; 
     37                $ids = array($ids); 
     38          } 
     39          reset($ids); 
     40          while(list(,$id) = each($ids)) { 
     41                if (!$jpdd->isEmpty($id)) { 
     42                  $jpdd->executeSQL('INSERT INTO attendance (person_id, workshop_id, flavor) VALUES ('.(int)$id.', '.$this->getID().', '.$jpdd->escStr($flavor).')'); 
     43                } 
     44          } 
     45        } 
     46        function dropAttendees($ids, $flavor) { 
     47          global $jpdd; 
     48          if (!is_array($ids)) { 
     49                if ($jpdd->isEmpty($ids)) 
     50                  return; 
     51                $ids = array($ids); 
     52          } 
     53          $jpdd->executeSQL('DELETE FROM attendance WHERE workshop_id = '.$this->getID().' AND flavor = '.$jpdd->escStr($flavor).' AND person_id IN ('.join(',', array_map('intval', $ids)).')'); 
     54        } 
     55 
     56 
    2757        function getFormInnards() { 
    2858          global $jpdd; 
     59          $nonpresenters = $this->getNonAttendees('presenter'); 
     60          $presenters = $this->getAttendees('presenter'); 
     61 
    2962          return '<div> 
    3063<label>Title<br/><input type="text" size="72" name="title" value="'.$this->getTitle(true).'"/></label><br/> 
     
    3467<label>Min. Attendees: <input type="text" size="2" maxlength="2" name="min_attendees" value="'.($jpdd->isEmpty($this->_min_attendees) ? '' : (int)$this->_min_attendees).'"/></label><br/> 
    3568<label>Max. Attendees: <input type="text" size="2" maxlength="2" name="max_attendees" value="'.($jpdd->isEmpty($this->_max_attendees) ? '' : (int)$this->_max_attendees).'"/></label> 
     69</div> 
     70<div> 
     71'.(0 == count($presenters)?'':'Presented by:<br/><ul>'. 
     72   join("\n", array_map(create_function('$h', 'return "<li>".$h->getLinkedTitle()." <label>[<input type=\"checkbox\" name=\"remove_presenters[]\" value=\"".$h->getID()."\"/>remove]</label>";'), $presenters)).'</ul>').' 
     73<label>Add Presenter:<br/><select name="new_presenters[]"> 
     74<option value=""></option> 
     75'.join("\n", array_map(create_function('$h', "return '<option value=\"'.\$h->getID().'\">'.\$h->getTitle().'</option>';"), $nonpresenters)).' 
     76</select></label> 
    3677</div> 
    3778</div>'; 
     
    60101          } else { 
    61102                $this->JPDD_Workshop(array('id' => $this->getID())); 
     103                $this->addAttendees($_POST['new_presenters'], 'presenter'); 
     104                $this->dropAttendees($_POST['remove_presenters'], 'presenter'); 
    62105                return true; 
    63106          } 
     
    79122          } else { 
    80123                $this->JPDD_Workshop(array('data' => $jpdd->getSingletonFromSQL('SELECT * from workshop WHERE id = currval(\'workshop_id_seq\')'))); 
     124                $this->addAttendees($_POST['new_presenters'], 'presenter'); 
    81125                return true; 
    82126          } 
     
    91135          } 
    92136 
    93           $ret .= '<div class="workshop-blurb">'.$this->getDescription().'</div>'; 
     137          // silly debugging: 
     138          //      $nonpresenters = $this->getNonAttendees('presenter'); 
     139          //      $ret .= 'Non-presenters: <ul>'.join("\n", array_map(create_function('$xx', 'return "<li>".$xx->getLinkedTitle();'), $nonpresenters)).'</ul>'; 
    94140 
    95141          $ret .= '<div class="attendance">Min. Attendees: '.(int)($this->_min_attendees).'<br/>'. 
  • trunk/jpdd/sql/db.sql

    r72 r73  
    302302REVOKE ALL ON TABLE attendance FROM dkg; 
    303303GRANT ALL ON TABLE attendance TO dkg; 
    304 GRANT SELECT ON TABLE attendance TO "www-data"; 
     304GRANT INSERT,SELECT,DELETE ON TABLE attendance TO "www-data"; 
     305 
     306 
     307-- 
     308-- Name: attendance_id_seq; Type: ACL; Schema: public; Owner: dkg 
     309-- 
     310 
     311REVOKE ALL ON TABLE attendance_id_seq FROM PUBLIC; 
     312REVOKE ALL ON TABLE attendance_id_seq FROM dkg; 
     313GRANT ALL ON TABLE attendance_id_seq TO dkg; 
     314GRANT SELECT,UPDATE ON TABLE attendance_id_seq TO "www-data"; 
    305315 
    306316 
Note: See TracChangeset for help on using the changeset viewer.