Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
poll_question_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 
33 {
34 
35 
41  {
42  $this->Asset_Edit_Fns();
43  $this->static_screens['details']['force_unlock'] = FALSE;
44 
45  }//end constructor
46 
47 
58  function paintPollOptions(&$asset, &$o, $prefix)
59  {
60 
61  $am =& $GLOBALS['SQ_SYSTEM']->am;
62  $admin_access = $asset->writeAccess('attributes');
63  $prefix = $asset->getPrefix();
64 
65  // include script for re-ordering questions
66  ?>
67  <script language="JavaScript">
68  function sortOrderMoveDown(currentOrder) {
69  if (!document.getElementById) {
70  alert(js_translate('brower_does_not_support_getelementbyid'));
71  return;
72  }
73 
74  var form = document.getElementById('main_form');
75 
76  if (!document.getElementById('<?php echo $prefix ?>_option_text' + (currentOrder + 1))) return;
77 
78  // switch the text-box values
79  var currentText = document.getElementById('<?php echo $prefix ?>_option_text' + currentOrder);
80  var nextText = document.getElementById('<?php echo $prefix ?>_option_text' + (currentOrder + 1));
81  temp = currentText.value;
82  currentText.value = nextText.value;
83  nextText.value = temp;
84 
85  // switch the votes values around
86  var currentVotes = document.getElementById('<?php echo $prefix ?>_option_votes' + currentOrder);
87  var prevVotes = document.getElementById('<?php echo $prefix ?>_option_votes' + (currentOrder + 1));
88  temp = currentVotes.innerHTML;
89  currentVotes.innerHTML = prevVotes.innerHTML;
90  prevVotes.innerHTML = temp;
91 
92  // switch the delete checkboxes
93  temp = form.elements['<?php echo $prefix ?>_order[delete][' + (currentOrder+1) + ']'].checked;
94  form.elements['<?php echo $prefix ?>_order[delete][' + (currentOrder+1) + ']'].checked = form.elements['<?php echo $prefix ?>_order[delete][' + currentOrder + ']'].checked;
95  form.elements['<?php echo $prefix ?>_order[delete][' + currentOrder + ']'].checked = temp;
96 
97  // switch the reorder values
98  temp = form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder+1) + ']'].value;
99  form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder+1) + ']'].value = form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value;
100  form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value = temp;
101  }
102 
103  function sortOrderMoveUp(currentOrder) {
104  if (!document.getElementById) {
105  alert(js_translate('brower_does_not_support_getelementbyid'));
106  return;
107  }
108 
109  var form = document.getElementById('main_form');
110 
111  if (currentOrder == 0) return;
112 
113  // switch the text-box values
114  var currentText = document.getElementById('<?php echo $prefix ?>_option_text' + currentOrder);
115  var prevText = document.getElementById('<?php echo $prefix ?>_option_text' + (currentOrder - 1));
116  temp = currentText.value;
117  currentText.value = prevText.value;
118  prevText.value = temp;
119 
120  // switch the votes values around
121  var currentVotes = document.getElementById('<?php echo $prefix ?>_option_votes' + currentOrder);
122  var prevVotes = document.getElementById('<?php echo $prefix ?>_option_votes' + (currentOrder - 1));
123  temp = currentVotes.innerHTML;
124  currentVotes.innerHTML = prevVotes.innerHTML;
125  prevVotes.innerHTML = temp;
126 
127  // switch the delete checkboxes
128  temp = form.elements['<?php echo $prefix ?>_order[delete][' + (currentOrder-1) + ']'].checked;
129  form.elements['<?php echo $prefix ?>_order[delete][' + (currentOrder-1) + ']'].checked = form.elements['<?php echo $prefix ?>_order[delete][' + currentOrder + ']'].checked;
130  form.elements['<?php echo $prefix ?>_order[delete][' + currentOrder + ']'].checked = temp;
131 
132  // switch the reorder values
133  temp = form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder-1) + ']'].value;
134  form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder-1) + ']'].value = form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value;
135  form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value = temp;
136  }
137  </script>
138 
139  <table class="sq-backend-table">
140  <tr>
141  <td class="sq-backend-table-header">
142  Poll Option
143  </td>
144  <td align="center" width="100" class="sq-backend-table-header" style="font-weight: bold;">
145  Votes
146  </td>
147  <?php
148 
149  if ($admin_access) {
150 
151  ?>
152  <td align="center" width="100" class="sq-backend-table-header" style="font-weight: bold;">Delete ?</td>
153  <td align="center" width="100" class="sq-backend-table-header" style="font-weight: bold;">Move</td>
154  <?php
155 
156  }
157 
158  ?>
159  </tr>
160  <?php
161 
162  // Grab array of options
163  $poll_options = $asset->attr('options');
164 
165  if (is_null($poll_options)) return FALSE;
166 
167  $ii = 0;
168  foreach ($poll_options as $sort_id => $sort_data) {
169  ?>
170  <tr>
171  <!-- Option Text -->
172  <td class="sq-backend-table-cell">
173  <?php
174  if ($admin_access) {
175  text_box($prefix.'_option_text'.$sort_id,$sort_data['option_text'], 30);
176  } else {
177  echo $sort_data['option_text'];
178  }
179  ?>
180  <?php
181  hidden_field($prefix.'_order[reorder]['.$sort_id.']', $sort_id);
182  ?>
183  </td>
184  <!-- No. of Votes -->
185  <td align="center" width="100" class="sq-backend-table-cell">
186  <span id="<?php echo $prefix.'_option_votes'.$sort_id; ?>">
187  <?php
188  echo $sort_data['votes'];
189  ?>
190  </span>
191  </td>
192  <?php
193  if ($admin_access) {
194  ?>
195  <td align="center" width="100" class="sq-backend-table-cell">
196  <?php
197  check_box($prefix.'_order[delete]['.$sort_id.']');
198  ?>
199  </td>
200  <td align="center" width="100" class="sq-backend-table-cell">
201  <?php
202  if ($ii != 0) {
203  ?><a href="#" onclick="sortOrderMoveUp(<?php echo $sort_id ?>); return false;"><script language="JavaScript" type="text/javascript">sq_print_icon("<?php echo sq_web_path('lib').'/web/images/icons/up_arrow.png' ?>", "16", "16", "Move Up");</script></a><?php
204  }
205 
206  if ($ii != count($poll_options) -1) {
207  ?><a href="#" onclick="sortOrderMoveDown(<?php echo $sort_id ?>); return false;"><img src="<?php echo sq_web_path('lib').'/web/images/icons/down_arrow.png' ?>" width="16" height="16" border="0"alt="Move Down" /></a><?php
208  }
209  ?>
210  </td>
211  <?php
212  }//end if admin access
213  ?>
214  </tr>
215  <?php
216  $ii++;
217  }//end foreach data
218  ?>
219  </table>
220  <?php
221  return TRUE;
222 
223  }//end paintPollOptions()
224 
225 
236  function processPollOptions(&$asset, &$o, $prefix)
237  {
238 
239  $prefix = $asset->getPrefix();
240  $options = $asset->attr('options');
241  $option_updated = FALSE;
242 
243  // Re-order and re-name the list
244  if (isset($_POST[$prefix.'_order']['reorder'])) {
245  $reorder_array = $_POST[$prefix.'_order']['reorder'];
246  $newArray = Array();
247  foreach ($reorder_array as $reorder_index => $reorder_data) {
248  $options[$reorder_data]['option_text'] = $_POST[$prefix.'_option_text'.$reorder_index];
249  array_push($newArray, $options[$reorder_data]);
250  $option_updated = TRUE;
251  }
252  $options = $newArray;
253  }
254 
255  // Delete any items flagged for deletion
256  if (isset($_POST[$prefix.'_order']['delete'])) {
257  foreach (array_keys($options) as $option_index ) {
258  if (isset($_POST[$prefix.'_order']['delete'][$option_index])) {
259  if ($_POST[$prefix.'_order']['delete'][$option_index] == '1') {
260  $options[$option_index] = NULL;
261  unset($options[$option_index]);
262  $options = array_values($options);
263  }
264  }
265  $option_updated = TRUE;
266  }
267  }
268 
269  if ($option_updated) $asset->updateOptions($options);
270  return TRUE;
271 
272 
273  }//end processPollOptions()
274 
275 
286  function paintAddPollOptions(&$asset, &$o, $prefix)
287  {
288  $am =& $GLOBALS['SQ_SYSTEM']->am;
289  $admin_access = $asset->writeAccess('attributes');
290  $prefix = $asset->getPrefix();
291  if ($admin_access) {
292  combo_box($prefix.'_no_options', Array( '','1','2','3','4','5','6','7','8','9','10' ), FALSE, '');
293  }
294 
295  }//end paintAddPollOptions()
296 
297 
308  function processAddPollOptions(&$asset, &$o, $prefix)
309  {
310  $prefix = $asset->getPrefix();
311  $options = $asset->attr('options');
312 
313  if (isset($_POST[$prefix.'_no_options'])) {
314  for ($ii = 0; $ii < $_POST[$prefix.'_no_options']; $ii++) {
315  $new_option = Array('option_text' => 'Poll Option Text #'.($ii + 1), 'votes' => 0);
316  array_push($options, $new_option);
317  }
318  $asset->setAttrValue('options', $options);
319  }
320  return TRUE;
321 
322  }//end processAddPollOptions()
323 
324 
335  function paintDeleteUsers(&$asset, &$o, $prefix)
336  {
337  $am =& $GLOBALS['SQ_SYSTEM']->am;
338  $admin_access = $asset->writeAccess('attributes');
339  $prefix = $asset->getPrefix();
340  $users_array = Array('','all' => 'Delete All Users' );
341 
342  // construct delete options array
343  $voters = $GLOBALS['SQ_SYSTEM']->am->getShadowLinkByAsset($asset->id, NULL, SQ_LINK_NOTICE, NULL, 'major', TRUE);
344 
345  if ($admin_access) {
346  if (empty($voters)) {
347  ?><em><?php echo translate('cms_poll_question_no_voting_records_exist'); ?></em><?php
348  } else {
349  foreach ($voters as $voter) {
350  $voter_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($voter['minorid']));
351  $users_array[$voter['minorid']] = $voter_info[$voter['minorid']]['name'];
352  }
353 
354  combo_box($prefix.'options', $users_array, FALSE, '');
355  }
356  } else {
357  ?><em><?php echo translate('cms_poll_question_admin_access_to_delete_user'); ?></em><?php
358  }
359 
360  }//end paintDeleteUsers()
361 
362 
373  function processDeleteUsers(&$asset, &$o, $prefix)
374  {
375  $prefix = $asset->getPrefix();
376 
377  if (!empty($_POST[$prefix.'options'])) {
378  $other_assetid = ($_POST[$prefix.'options'] == 'all') ? NULL : $_POST[$prefix.'options'];
379  $voter_links = $GLOBALS['SQ_SYSTEM']->am->getShadowLinkByAsset($asset->id, $other_assetid, SQ_LINK_NOTICE, NULL, 'major', TRUE);
380 
381  foreach ($voter_links as $voter_link) {
382  $GLOBALS['SQ_SYSTEM']->am->deleteShadowAssetLink($voter_link['linkid']);
383  }
384  }
385 
386  return TRUE;
387 
388  }//end processDeleteUsers()
389 
390 
391 }//end class
392 
393 
394 ?>