Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
simple_form_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 
20 
33 {
34 
35 
43  {
44  $this->Asset_Edit_Fns();
45  $this->static_screens['details']['force_unlock'] = FALSE;
46 
47  }//end constructor
48 
49 
50 //-- QUESTION DISPLAY FUNCTIONS --//
51 
52 
63  function paintQuestions(&$asset, &$o, $prefix)
64  {
65  $write_access = $asset->writeAccess('attributes');
66 
67  $parents = $GLOBALS['SQ_SYSTEM']->am->getParents($asset->id.':q1', '', TRUE);
68 
69  // TRANSLATE
70  ?>
71  <script type="text/javascript" src="<?php echo sq_web_path('data') ?>/asset_types/simple_form/js/sort_order_manip.js"></script>
72  <div style="display:none"><?php sq_print_icon(sq_web_path('lib').'/web/images/icons/internal_message/priority_2.png', 16, 16, '', '', 'id="'.$prefix.'_moved_up" align="absmiddle"') ?>
73  <?php sq_print_icon(sq_web_path('lib').'/web/images/icons/internal_message/priority_4.png', 16, 16, '', '', 'id="'.$prefix.'_moved_down" align="absmiddle"') ?></div>
74  <table class="sq-backend-table">
75  <thead>
76  <tr>
77  <th>
78  <?php echo translate('question'); ?>
79  </th>
80  <th>
81  <?php echo translate('type'); ?>
82  </th>
83  <?php if ($write_access) {
84  ?><th style="width:30px; text-align:center">
85  <?php echo translate('up'); ?>
86  </th>
87  <th colspan="2" style="text-align:center">
88  <?php echo translate('position'); ?>
89  </th>
90  <th style="width:30px; text-align:center">
91  <?php echo translate('down'); ?>
92  </th>
93  <th style="width:50px; text-align:center">
94  <?php echo translate('delete'); ?>
95  </th><?php
96  }
97  ?></tr>
98  </thead>
99  <tbody>
100  <?php if (count($asset->attr('questions')) <= 0) {
101  ?><tr><td colspan="<?php echo $write_access ? 8 : 3 ?>" style="font-style:italic; text-align:center"><?php echo translate('core_simple_form_no_questions'); ?></td></tr><?php
102  } else {
103  foreach ($asset->attr('questions') as $shadowid => $asset_data) {
104  $assetid = $asset->id.':q'.$shadowid;
105  $q = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
106  $href = $q->getBackendHref('details');
107  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($q);
108  unset($q); ?>
109  <tr id="<?php echo $prefix.'_order_row'.$asset_data['sort_order'] ?>">
110  <td>
111  <span name="<?php echo $prefix.'_order_o'.$asset_data['sort_order'] ?>" id="<?php echo $prefix.'_order_o'.$asset_data['sort_order'] ?>"><?php echo get_asset_tag_line($assetid, 'details') ?><!-- <b><a href="<?php echo $href ?>"><?php // echo $asset_data['attributes']['name']; ?></a></b> --></span><?php hidden_field($prefix.'_order[reorder]['.$asset_data['sort_order'].']', $shadowid); ?>
112  </td>
113  <td>
114  <span name="<?php echo $prefix.'_order_t'.$asset_data['sort_order'] ?>" id="<?php echo $prefix.'_order_t'.$asset_data['sort_order'] ?>"><?php
115  $q_type = str_replace('form_question_type', '', $asset_data['type_code']);
116  $q_type = str_replace('_', ' ', $q_type);
117  $q_type = trim(ucwords($q_type));
118  echo $q_type;
119  ?></span>
120  </td>
121  <?php if ($write_access) {
122  ?><td style="width:30px; text-align:center">
123  <?php
124  if ($asset_data['sort_order'] != 0) {
125  ?><a href="#" onclick="moveQuestion(document.main_form, '<?php echo $prefix ?>', <?php echo $asset_data['sort_order'] ?>, <?php echo $asset_data['sort_order'] - 1 ?>); 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
126  }
127  ?>
128  </td>
129  <td style="width:30px; text-align:right">
130  <span id="<?php echo $prefix.'_order_so'.$asset_data['sort_order'] ?>"><?php echo $asset_data['sort_order'] + 1; ?></span>
131  </td>
132  <td style="width:30px; text-align:left">
133  <span id="<?php echo $prefix.'_order_soa'.$asset_data['sort_order'] ?>"></span><span style="visibility:hidden; font-weight: bold" name="<?php echo $prefix.'_order_soc'.$asset_data['sort_order'] ?>" id="<?php echo $prefix.'_order_soc'.$asset_data['sort_order'] ?>"><?php echo $asset_data['sort_order'] + 1; ?></span>
134  </td>
135  <td style="width:30px; text-align:center">
136  <?php
137  if ($asset_data['sort_order'] != count($asset->attr('questions')) -1) {
138  ?><a href="#" onclick="moveQuestion(document.main_form, '<?php echo $prefix ?>', <?php echo $asset_data['sort_order'] ?>, <?php echo $asset_data['sort_order'] + 1 ?>); return false;"><script language="JavaScript" type="text/javascript">sq_print_icon("<?php echo sq_web_path('lib').'/web/images/icons/down_arrow.png' ?>", "16", "16", "Move Down");</script></a><?php
139  }
140  ?>
141  </td>
142  <td style="width:50px; text-align:center">
143  <?php check_box($prefix.'_order[delete]['.$asset_data['sort_order'].']'); ?>
144  </td>
145  <?php }
146  ?></tr>
147  <?php }//end foreach
148  }//end else
149  ?></tbody>
150  </table>
151  <?php
152 
153  return $write_access;
154 
155  }//end paintQuestions()
156 
157 
168  function processQuestions(&$asset, &$o, $prefix)
169  {
170  if (!$asset->writeAccess('attributes')) return FALSE;
171  if (!isset($_POST[$prefix.'_order']['reorder'])) {
172  return FALSE;
173  }
174 
175  $old_questions = $asset->attr('questions');
176  $questions = Array();
177 
178  $old_sort_order = 0;
179  $new_sort_order = 0;
180  foreach ($_POST[$prefix.'_order']['reorder'] as $order_shadowid) {
181  if (empty($_POST[$prefix.'_order']['delete'][$old_sort_order])) {
182  $questions[$order_shadowid] =& $old_questions[$order_shadowid];
183  $questions[$order_shadowid]['sort_order'] = $new_sort_order;
184  $new_sort_order++;
185  }
186  $old_sort_order++;
187  }
188 
189  $asset->setAttrValue('questions', $questions);
190  return TRUE;
191 
192  }//end processQuestions()
193 
194 
205  function paintAddQuestions(&$asset, &$o, $prefix)
206  {
207  if (!$asset->writeAccess('attributes')) {
208  ?><i><?php echo translate('core_simple_form_lock_to_add_questions'); ?></i><?php
209  return FALSE;
210  }
211 
212  $am =& $GLOBALS['SQ_SYSTEM']->am;
213  $question_types = $am->getTypeDescendants('form_question');
214  $questions = Array('' => '-- '.translate('choose_type').' --');
215 
216  foreach ($question_types as $question) {
217  $q = str_replace('form_question_type', '', $question);
218  $q = str_replace('_', ' ', $q);
219  $q = trim(ucwords($q));
220  $questions[$question] = $q;
221  }
222 
223  $prefix = str_replace(':','_',$prefix); // handle shadow assets
224  ?>
225  <div id="question-list-<?php echo $prefix; ?>">
226  <?php
227  for ($i =0; $i < 2; $i++) {
228  ?>
229  <div><input type="text" name="<?php echo $prefix; ?>_add[names][]" /><?php echo combo_box($prefix.'_add[types][]', $questions, FALSE, ''); ?><button type="button" tabindex="99999" class="delete-button">&nbsp;</button></div>
230  <?php
231  }
232  ?>
233  </div>
234  <script type="text/javascript">
235  // attach the event handlers
236  var optionList = document.getElementById('question-list-<?php echo $prefix; ?>');
237  var divs = optionList.getElementsByTagName('DIV');
238  for (var i=0; i < divs.length; i++) {
239  var thisDiv = divs[i];
240 
241  var inputs = thisDiv.getElementsByTagName('INPUT');
242  for (var j=0; j < inputs.length; j++) {
243  inputs[j].onfocus = expandListFormFn;
244  }
245  var selects = thisDiv.getElementsByTagName('SELECT');
246  for (var j=0; j < selects.length; j++) {
247  selects[j].onfocus = expandListFormFn;
248  }
249  var buttons = thisDiv.getElementsByTagName('BUTTON');
250  for (var j=0; j < buttons.length; j++) {
251  buttons[j].onclick = deleteRowFormFn;
252  }
253  }
254  </script>
255  <?php
256  return TRUE;
257 
258  }//end paintAddQuestions()
259 
260 
271  function processAddQuestions(&$asset, &$o, $prefix)
272  {
273  if (!$asset->writeAccess('attributes')) return FALSE;
274 
275  $names = $_POST[$prefix.'_add']['names'];
276  $types = $_POST[$prefix.'_add']['types'];
277 
278  // this can eventually be expanded to handle named questions
279  $am =& $GLOBALS['SQ_SYSTEM']->am;
280 
281  foreach ($types as $i => $type) {
282  if (empty($type)) continue;
283 
284  $am->includeAsset($type);
285  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
286  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
287 
288  // create some questions
289  if (!$asset->createQuestion($type, $names[$i])) {
290  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
291  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
292  return FALSE;
293  }//end if
294 
295  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
296  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
297 
298  }//end foreach
299 
300  return TRUE;
301 
302  }//end processAddQuestions()
303 
304 
315  function paintUseBodycopy(&$asset, &$o, $prefix)
316  {
317  $write_access = $asset->writeAccess('links');
318  $bodycopy_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_TYPE_2, 'bodycopy', 'format');
319  $enabled = !empty($bodycopy_link);
320 
321  if ($write_access) {
322  $options = Array(
323  '1' => translate('yes'),
324  '0' => translate('no'),
325  );
326 
327  combo_box($prefix.'_use_bodycopy', $options, FALSE, Array($enabled));
328 
329  } else {
330  echo $enabled ? translate('on') : translate('off');
331  }
332 
333  return $write_access;
334 
335  }//end paintUseBodycopy()
336 
337 
348  function processUseBodycopy(&$asset, &$o, $prefix)
349  {
350  if (!$asset->writeAccess('links')) return FALSE;
351  $enabled = $_POST[$prefix.'_use_bodycopy'];
352 
353  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
354  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
355 
356  if (!$asset->setUseFormatBodycopy($enabled)) {
357  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
358  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
359  return FALSE;
360  }
361 
362  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
363  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
364 
365  return TRUE;
366 
367  }//end processUseBodycopy()
368 
369 
370 }//end class
371 
372 
373 ?>