source: trunk/jpdd/class.jpdd.proposal.php @ 1428

Last change on this file since 1428 was 1428, checked in by Daniel Kahn Gillmor, 5 years ago

more cleanup of the private notes presentation

File size: 10.2 KB
Line 
1<?php  /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 2; -*-
2
3Title of workshop you would like to lead (be specific about the
4subject area):
5
6Brief, enticing description (consider workshop’s relationship to
7performance assessment):
8
9Maximum number of participants:
10
11
12We would greatly appreciate your supplying any needed equipment .  If
13that is not at all possible, let us know what equipment you would like
14to have, and we will see if we can help out:
15       */
16
17require_once('class.dkg.row.php');
18
19if (!class_exists('JPDD_Proposal')) {
20
21  class JPDD_Proposal extends DKG_Row {
22    function JPDD_Proposal($args = array()) {
23      $this->_min_attendees = 5;
24      $this->DKG_Row($args);
25    }
26   
27        var $_short_title_length = 35;
28
29        function getCreatePrivilege() {
30          return NULL;
31        }
32        function getEditPrivilege() {
33          return array('Update Proposals');
34        }
35        function getListPrivilege() {
36          return array('List Proposals');
37        }
38
39    function getShortTitle() {
40      if (is_null($this->_title)) 
41        return NULL;
42      if (strlen($this->_title) > $this->_short_title_length) {
43        if (!is_null($this->_short_title)) {
44          $ret = $this->_short_title;
45        } else {
46          $ret = array_shift(str_split($this->_title, $this->_short_title_length));
47        }
48      } else
49        $ret = $this->_title;
50
51      return htmlentities($ret);
52    }
53   
54        function getFormInnards() {
55          global $jpdd;
56     
57      $jpdd->addTinyMCE();
58      $jpdd->addSourcedScript('scripts/dkg.base.js');
59      $jpdd->addScriptChunk('DKG.onLoadScripts.push(\'DKG.hideOnLength("'.$this->getTitle(true).'", '.(int)$this->_short_title_length.', "short_title_label");\');');
60          return '<div>
61<label>Title<br/><input type="text" size="72" name="title" onchange="DKG.hideOnLength(this.value, '.(int)$this->_short_title_length.',\'short_title_label\');" value="'.$this->getTitle(true).'"/></label><br/>
62<label id="short_title_label">Short Title <span class="notes">(needed for printing when title is too long)</span><br/><input type="text" maxlength="'.(int)$this->_short_title_length.'" name="short_title" value="'.htmlentities($this->_short_title).'"/></label><br/>
63<label>Brief, enticing description (to be shown to participants)<br/><textarea name="description" rows="20" cols="70">'.$this->getDescription(true, true).'</textarea></label>
64
65<h3>Equipment, Presenters, and other notes</h3>
66<p>We would greatly appreciate your supplying any needed equipment .
67If that is not at all possible, let us know (in the private notes
68below) what equipment you would like to have, and we will see if we
69can help out.</p>
70
71<p>If you ('.$jpdd->_authenticated_user->getTitle().') are not the one who will present the workshop, or if you hope to
72have co-presenters, please indicate who that will be in the private
73notes below as well.</p>
74
75<label>Private Notes (for conference organizers, will not be shown to participants)<br/><textarea name="private_notes" rows="3" cols="70">'.$jpdd->FilterBlock($this->_private_notes, true).'</textarea></label>
76'.$this->getM2MEditView('category', 'proposal_category', 'Categories', 'Add Category').'
77<fieldset><legend>Attendance</legend>
78<label><input type="text" size="2" maxlength="2" name="min_attendees" value="'.($jpdd->isEmpty($this->_min_attendees) ? '' : (int)$this->_min_attendees).'"/> Minimum number of attendees needed to make the workshop</label><br/>
79<label><input type="text" size="2" maxlength="2" name="max_attendees" value="'.($jpdd->isEmpty($this->_max_attendees) ? '' : (int)$this->_max_attendees).'"/> Maximum number of attendees</label>
80</fieldset>
81';
82        }
83
84        function applyPostForm() {
85          $this->_title = $_POST['title'];
86          $this->_short_title = (array_key_exists('short_title', $_POST) ? $_POST['short_title'] : NULL);
87          $this->_description = $_POST['description'];
88          $this->_private_notes = $_POST['private_notes'];
89          $this->_min_attendees = $_POST['min_attendees'];
90          $this->_max_attendees = $_POST['max_attendees'];
91        }
92
93        function handleEdit() {
94          global $jpdd;
95          $this->applyPostForm();
96          $res = $jpdd->executeSQL('UPDATE '.$this->getSingletonTable().' SET '.
97                                                           'title = '.$jpdd->stringOrDefault($this->_title).', '.
98                                                           'short_title = '.$jpdd->stringOrDefault($this->_short_title).', '.
99                                                           'description = '.$jpdd->stringOrDefault($this->_description).', '.
100                                                           'private_notes = '.$jpdd->stringOrDefault($this->_private_notes).', '.
101                                                           'min_attendees = '.$jpdd->intOrDefault($this->_min_attendees).', '.
102                                                           'max_attendees = '.$jpdd->intOrDefault($this->_max_attendees).' WHERE '.
103                                                           'id = '.$this->getID(), false);
104          if (false === $res) {
105        $logid = $jpdd->log('edit proposal '.(int)$this->_id.' db update failed with pg error: '.pg_last_error($jpdd->_db));
106                return 'editing this proposal failed during insertion into the database for some reason (error: '.(int)$logid.')';
107          } else {
108                $this->JPDD_Proposal(array('id' => $this->getID()));
109        $this->addM2MPeers('category', 'proposal_category', $jpdd->getPostedIDs('add_proposal_category'));
110        $this->dropM2MPeers('category', 'proposal_category', $jpdd->getPostedIDs('remove_proposal_category'));
111                return NULL;
112          }
113        }
114
115        function handleCreation() {
116          // just insert a new row, grab the created ID, and re-initialize
117          // ourselves, returning true if successful.
118          global $jpdd;
119          $this->applyPostForm();
120          $res = $jpdd->executeSQL('INSERT INTO '.$this->getSingletonTable().' (title, short_title, description, private_notes, min_attendees, max_attendees, event_id, proposer_id) VALUES ('.
121                                                           $jpdd->stringOrDefault($this->_title).', '.
122                                                           $jpdd->stringOrDefault($this->_short_title).', '.
123                                                           $jpdd->stringOrDefault($this->_description).', '.
124                                                           $jpdd->stringOrDefault($this->_private_notes).', '.
125                                                           $jpdd->intOrDefault($this->_min_attendees).', '.
126                                                           $jpdd->intOrDefault($this->_max_attendees).', '.
127                               $jpdd->getActiveEventID().', '.
128                               $jpdd->getAuthenticatedUserID().')', false);
129          if (false === $res) {
130        $logid = $jpdd->log('create proposal failed with pg error: '.pg_last_error($jpdd->_db));
131                return 'database insertion failed for some reason (error: '.(int)$logid.').';
132          } else {
133                $this->JPDD_Proposal(array('data' => $jpdd->getSingletonFromSQL('SELECT * from proposal WHERE id = currval(\'proposal_id_seq\')')));
134        $this->addM2MPeers('category', 'proposal_category', $jpdd->getPostedIDs('add_proposal_category'));
135                return NULL;
136          }
137        }
138
139        function getDetailInnards() {
140          global $jpdd;
141      $editor = $jpdd->isAuthenticated() && $jpdd->_authenticated_user->canEdit($this);
142      $canaccept = $jpdd->isAuthenticated() && $jpdd->_authenticated_user->hasAllOfThesePrivileges('Update Workshops');
143
144      $ret = '';
145
146      if ($editor || $canaccept) {
147        $ret .= '<div>Proposed by: '.$this->getProposer()->getLinkedTitle().'</div>';
148        if (!is_null($this->_private_notes))
149          $ret .= '<div class="private-notes"><div class="title">Private Notes</div><div class="body">'.$jpdd->filterBlock($this->_private_notes).'</div></div>';
150      }
151
152      $ret .= '<div>Min. Attendees: '.(int)($this->_min_attendees).'<br/>'.
153        'Max. Attendees: '.(int)($this->_max_attendees).'<br/>'.
154        '</div>';
155      $cats = $this->getM2MPeers('category', 'proposal_category');
156      if (count($cats) > 0) {
157        $ret .=  'Categories: <ul>'."\n";
158        reset($cats);
159        while(list(,$cat) = each($cats)) {
160          $ret .= '<li>'.$cat->getLinkedTitle().'</li>';
161        }
162        $ret .= "</ul>\n";
163      }
164
165      if ($canaccept or $editor) {
166        // indicate whether any other workshops are already generated from this proposal:
167        $workshops = $this->getAssociatedWorkshops();
168        if (count($workshops)) {
169          $ret .= "<div>Workshop".(count($workshops) > 1 ? 's' : '')." based on this proposal:<ul>";
170          while(list(,$workshop) = each($workshops)) {
171            $ret .= '<li>'.$workshop->getLinkedTitle().'</li>';
172          }
173          $ret .= '</ul></div>';
174        } else {
175          if ($canaccept) {
176            $ret .= $this->getAcceptanceForm();
177          }
178        }
179      }
180          return $ret;
181        }
182
183    function getAcceptanceForm() {
184      global $jpdd;
185      $categories = '';
186      $cats = $this->getM2MPeers('category', 'proposal_category');
187      reset($cats);
188      while(list(,$cat) = each($cats))
189        $categories .= '<input type="hidden" name="add_workshop_category[]" value="'.$cat->getID().'"/>';
190     
191      return '<form action="'.$jpdd->Path('accept', 'proposal', $this->getID()).'" method="post">
192'.$jpdd->getFormTokenHiddenInput().
193        '<input type="hidden" name="title" value="'.htmlentities($this->_title).'"/>'.
194        '<input type="hidden" name="short_title" value="'.htmlentities($this->_short_title).'"/>'.
195        '<input type="hidden" name="description" value="'.htmlentities($this->_description).'"/>'.
196        '<input type="hidden" name="private_notes" value="'.htmlentities($this->_private_notes).'"/>'.
197        '<input type="hidden" name="min_attendees" value="'.htmlentities($this->_min_attendees).'"/>'.
198        '<input type="hidden" name="max_attendees" value="'.htmlentities($this->_max_attendees).'"/>'.
199        '<input type="hidden" name="add_presenter[]" value="'.(int)$this->_proposer_id.'"/>'.
200        $categories.
201'<input class="submit" type="submit" name="xx" value="Create a workshop from this proposal"/>
202</form>';
203    }
204
205    function createWorkshop() {
206      global $jpdd;
207      // create the workshop based on this proposal
208      $map = $jpdd->prepClass('workshop');
209      $workshop = new $map['classname'](array('data' => array('proposal_id' => $this->getID())));
210      $workshop->handleCreation();
211
212      return $workshop;
213    }
214
215    function getAssociatedWorkshops() {
216      // return a list of all associated workshops.
217      global $jpdd;
218      $jpdd->prepClass('workshop');
219      $sql = 'SELECT * from workshop WHERE proposal_id = '.(int)$this->getID();
220      return $jpdd->getSeriesFromSQL($sql, 'JPDD_Workshop');
221    }
222
223    function getProposer() {
224      global $jpdd;
225      $map = $jpdd->prepClass('person');
226      return new $map['classname'](array('id' => (int)$this->_proposer_id));
227    }
228
229    function canBeEditedBy($person) {
230      return ($person->getID() == $this->_proposer_id);
231    }
232
233  }
234}
Note: See TracBrowser for help on using the repository browser.