Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
form_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_SYSTEM_ROOT.'/core/attributes/option_list/option_list.inc';
19 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
20 
33 {
34 
35 
40  function Form_Edit_Fns()
41  {
42  $this->Asset_Edit_Fns();
43  $this->static_screens['details']['force_unlock'] = FALSE;
44 
45  }//end constructor
46 
47 
58  function paintSectionLinks(&$asset, &$o, $prefix)
59  {
60  // get the sections linked to this asset
61  if (isset($asset->tmp['section_links'])) {
62  unset($asset->tmp['section_links']);
63  }
64  $sections = $asset->getSections();
65 
66  if (empty($sections)) {
67  echo translate('cms_form_no_sections');
68  return FALSE;
69  }
70  for (reset($sections); NULL !== ($k = key($sections)); next($sections)) {
71  $s =& $sections[$k];
72  echo get_asset_tag_line($s->id, 'details').'<br />';
73  }
74 
75  return TRUE;
76 
77  }//end paintSectionLinks()
78 
79 
90  function processSectionLinks(&$asset, &$o, $prefix)
91  {
92  return TRUE;
93 
94  }//end processSectionLinks()
95 
96 
107  function paintQuestionLinks(&$asset, &$o, $prefix)
108  {
109  $am = $GLOBALS['SQ_SYSTEM']->am;
110  $admin_access = $asset->writeAccess('attributes');
111  $prefix = $asset->getPrefix();
112  $questions = $asset->getQuestions();
113 
114  // include script for re-ordering questions
115  ?>
116  <script type="text/javascript">
117  function sortOrderMoveDown(currentOrder) {
118  if (!document.getElementById) {
119  alert('<?php echo translate('cms_form_no_getelementbyid'); ?>');
120  return;
121  }
122  // move a question up a row
123  var form = document.getElementById('main_form');
124 
125  var currentElement = document.getElementById('<?php echo $prefix ?>_order_o' + currentOrder);
126  var nextElement = document.getElementById('<?php echo $prefix ?>_order_o' + (currentOrder + 1));
127 
128  // if there is no next element, then this is the last one; we shouldn't be running
129  if (!nextElement) return;
130 
131  if (!currentElement.innerHTML) {
132  alert('<?php echo translate('cms_form_no_innerhtml'); ?>');
133  return;
134  }
135 
136  // switch the question names
137  var temp = currentElement.innerHTML;
138  currentElement.innerHTML = nextElement.innerHTML;
139  nextElement.innerHTML = temp;
140 
141  // switch the question types
142  var currentElement = document.getElementById('<?php echo $prefix ?>_order_t' + currentOrder);
143  var nextElement = document.getElementById('<?php echo $prefix ?>_order_t' + (currentOrder + 1));
144 
145  var temp = currentElement.innerHTML;
146  currentElement.innerHTML = nextElement.innerHTML;
147  nextElement.innerHTML = temp;
148 
149 
150 
151  // switch the 'checked for deletion' parameters
152  temp = form.elements['<?php echo $prefix ?>_order[delete][' + (currentOrder+1) + ']'].checked;
153  form.elements['<?php echo $prefix ?>_order[delete][' + (currentOrder+1) + ']'].checked = form.elements['<?php echo $prefix ?>_order[delete][' + currentOrder + ']'].checked;
154  form.elements['<?php echo $prefix ?>_order[delete][' + currentOrder + ']'].checked = temp;
155 
156  // switch the reorder values
157  temp = form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder+1) + ']'].value;
158  form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder+1) + ']'].value = form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value;
159  form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value = temp;
160 
161  }
162 
163  function sortOrderMoveUp(currentOrder) {
164  // move a question up a row
165  if (!document.getElementById) {
166  alert('<?php echo translate('cms_form_no_getelementbyid'); ?>');
167  return;
168  }
169 
170  if (currentOrder == 0) return;
171 
172  var form = document.getElementById('main_form');
173 
174  var currentElement = document.getElementById('<?php echo $prefix ?>_order_o' + currentOrder);
175  var prevElement = document.getElementById('<?php echo $prefix ?>_order_o' + (currentOrder - 1));
176 
177  if (!currentElement.innerHTML) {
178  alert('<?php echo translate('cms_form_no_innerhtml'); ?>');
179  return;
180  }
181 
182  // switch the question names
183  var temp = currentElement.innerHTML;
184  currentElement.innerHTML = prevElement.innerHTML;
185  prevElement.innerHTML = temp;
186 
187  // switch the question types
188  var currentElement = document.getElementById('<?php echo $prefix ?>_order_t' + currentOrder);
189  var prevElement = document.getElementById('<?php echo $prefix ?>_order_t' + (currentOrder - 1));
190 
191  var temp = currentElement.innerHTML;
192  currentElement.innerHTML = prevElement.innerHTML;
193  prevElement.innerHTML = temp;
194 
195  // switch the delete checkboxes
196  temp = form.elements['<?php echo $prefix ?>_order[delete][' + (currentOrder-1) + ']'].checked;
197  form.elements['<?php echo $prefix ?>_order[delete][' + (currentOrder-1) + ']'].checked = form.elements['<?php echo $prefix ?>_order[delete][' + currentOrder + ']'].checked;
198  form.elements['<?php echo $prefix ?>_order[delete][' + currentOrder + ']'].checked = temp;
199 
200  // switch the includes checkboxes
201  temp = form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder-1) + ']'].value;
202  form.elements['<?php echo $prefix ?>_order[reorder][' + (currentOrder-1) + ']'].value = form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value;
203  form.elements['<?php echo $prefix ?>_order[reorder][' + currentOrder + ']'].value = temp;
204 
205  }
206 
207  function changeAllDelStatuses(status)
208  {
209  var inputs = document.getElementsByTagName('INPUT');
210  for (var i = 0; i < inputs.length; i++) {
211  if (inputs[i].id.indexOf("_order[delete][") < 0) continue;
212  inputs[i].checked = status;
213  }
214  }
215 
216  </script>
217  <table class="sq-backend-table">
218  <tr>
219  <td class="sq-backend-table-header">
220  <?php echo translate('question'); ?>
221  </td>
222  <td class="sq-backend-table-header">
223  <?php echo translate('type'); ?>
224  </td>
225  <?php
226  if ($admin_access) {
227  ?>
228  <td align="center" width="100" class="sq-backend-table-header" style="font-weight: bold;"><?php
229  if (!empty($questions)) {
230  $delete_all = check_box($prefix.'_order[delete]', '1', FALSE, 'changeAllDelStatuses(this.checked)');
231  } else {
232  $delete_all = '';
233  }
234  echo translate('delete_question').$delete_all; ?>
235  </td>
236  <td align="center" width="100" class="sq-backend-table-header" style="font-weight: bold;"><?php echo translate('move'); ?></td>
237  <?php
238  }
239  ?>
240  </tr>
241  <?php
242  $sort_order = $asset->attr('sort_order');
243 
244  if (!empty($sort_order)) {
245  // sort order is based upon shadow asset id (eg. '87:q1'), not just question id - this
246  // will allow sections to be sorted in later
247  $i = 0;
248  foreach ($sort_order as $sort_id => $assetid) {
249  $q = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
250  if (is_null($q)) continue;
251  $href = $q->getBackendHref('details');
252  ?>
253  <tr>
254  <td class="sq-backend-table-cell">
255  <span name="<?php echo $prefix.'_order_o'.$sort_id ?>" id="<?php echo $prefix.'_order_o'.$sort_id ?>"><?php echo get_asset_tag_line($assetid, 'details') ?></span><?php hidden_field($prefix.'_order[reorder]['.$sort_id.']', $assetid); ?>
256  </td>
257  <td class="sq-backend-table-cell">
258  <span name="<?php echo $prefix.'_order_t'.$sort_id ?>" id="<?php echo $prefix.'_order_t'.$sort_id ?>"><?php
259  $q_type = str_replace('Form_Question_Type', '', get_class($q));
260  $q_type = str_replace('_', ' ', $q_type);
261  $q_type = trim(ucwords($q_type));
262  echo $q_type;
263  ?></span>
264  </td>
265  <?php
266  if ($admin_access) {
267  ?>
268  <td align="center" width="100" class="sq-backend-table-cell">
269  <?php
270  check_box($prefix.'_order[delete]['.$sort_id.']');
271  ?>
272  </td>
273  <td align="center" width="100" class="sq-backend-table-cell">
274  <?php
275  if ($i != 0) {
276  ?><a href="#" onclick="sortOrderMoveUp(<?php echo $sort_id ?>); return false;"><script 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
277  }
278 
279  if ($i != count($sort_order) -1) {
280  ?><a href="#" onclick="sortOrderMoveDown(<?php echo $sort_id ?>); return false;"><script 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
281  }
282  ?>
283  </td>
284  <?php
285  }//end if admin access
286  ?>
287  </tr>
288  <?php
289  $i++;
290  }//end foreach data
291  }//end if
292  ?>
293  </table>
294  <?php
295  return TRUE;
296 
297  }//end paintQuestionLinks()
298 
299 
310  function processQuestionLinks(&$asset, &$o, $prefix)
311  {
312  $prefix = $asset->getPrefix();
313 
314  if (isset($_POST[$prefix.'_order']['reorder'])) {
315  $asset->setAttrValue('sort_order', array_values($_POST[$prefix.'_order']['reorder']));
316  $asset->saveAttributes();
317  }
318 
319  if (isset($_POST[$prefix.'_order']['delete'])) {
320  foreach (array_keys($_POST[$prefix.'_order']['delete']) as $sort_order) {
321  $question = $asset->getQuestionByOrder($sort_order);
322  $asset->deleteQuestion($question);
323  }
324  // bugfix 2461: make sure there is not 'gap' between question index
325  $asset->setAttrValue('sort_order', array_values($asset->attr('sort_order')));
326  $asset->saveAttributes();
327  }
328 
329  // regen the content file
330  $asset->_updated();
331 
332  return TRUE;
333 
334  }//end processQuestionLinks()
335 
336 
349  function paintUseBodycopy(&$asset, &$o, $prefix)
350  {
351  // Bodycopies by suffix and name. Note that these are not localised,
352  // because they are used for
353  $bodycopies = $this->_getBodycopiesList();
354 
355  $write_access = $asset->writeAccess('links');
356 
357  if (!$write_access) {
358  $num_bodycopies = 0;
359 
360  foreach ($bodycopies as $bc_code => $bc_name) {
361  if ($asset->attr('use_bodycopy_'.$bc_code)) {
362  $bodycopy = $asset->getBodycopy($bc_name);
363  echo get_asset_tag_line($bodycopy->id, 'contents').'<br />';
364  $num_bodycopies++;
365  }
366  }
367 
368  if ($num_bodycopies == 0) {
369  echo translate('cms_form_none_customised').'<br />';
370  }
371  } else {
372  foreach ($bodycopies as $bc_code => $bc_name) {
373  check_box('use_bodycopy_'.$bc_code, '1', $asset->attr('use_bodycopy_'.$bc_code));
374  echo label(translate('cms_form_bodycopy_'.$bc_code), 'use_bodycopy_'.$bc_code).'<br />';
375  }
376  }
377 
378  return $write_access;
379 
380  }//end paintUseBodycopy()
381 
382 
397  function processUseBodycopy(&$asset, &$o, $prefix)
398  {
399  $bodycopies = $this->_getBodycopiesList();
400 
401  // Page Contents
402  foreach ($bodycopies as $bc_suffix => $bc_name) {
403  if (isset($_POST['use_bodycopy_'.$bc_suffix]) && !$asset->getBodycopy($bc_name)) {
404  $asset->createBodycopy($bc_name);
405  }
406  $asset->setAttrValue('use_bodycopy_'.$bc_suffix, isset($_POST['use_bodycopy_'.$bc_suffix]));
407  }
408  $asset->saveAttributes();
409  $asset->_updated();
410 
411  return TRUE;
412 
413  }//end processUseBodycopy()
414 
415 
427  protected function _getBodycopiesList()
428  {
429  $bodycopies = Array(
430  'main' => 'Page Contents',
431  'confirmation' => 'Confirmation Page Contents',
432  'thank_you' => 'Thank You',
433  'unattached' => 'Unattached Questions Format',
434  'exit' => 'Exit Page Contents',
435  );
436 
437  return $bodycopies;
438 
439  }//end _getBodycopiesList()
440 
441 
454  function paintAddQuestions(&$asset, &$o, $prefix)
455  {
456  if (!$asset->writeAccess('attributes')) return FALSE;
457 
458  $am = $GLOBALS['SQ_SYSTEM']->am;
459  $question_types = $am->getTypeDescendants('form_question');
460  $questions = Array('' => '-- Choose Type --');
461 
462  foreach ($question_types as $question) {
463  $q = str_replace('form_question_type', '', $question);
464  $q = str_replace('_', ' ', $q);
465  $q = trim(ucwords($q));
466  $questions[$question] = $q;
467  }
468 
469  combo_box('question_type', $questions, FALSE, '');
470  echo '&nbsp;';
471 
472  // create a dropdown box with some numbers for the number of questions to add
473  $num = Array();
474  for ($i = 1; $i <= 10; $i++) {
475  $num[$i] = $i;
476  }
477  combo_box('num_questions', $num, FALSE, '');
478  return TRUE;
479 
480  }//end paintAddQuestions()
481 
482 
493  function processAddQuestions(&$asset, &$o, $prefix)
494  {
495  $type = (isset($_POST['question_type'])) ? $_POST['question_type'] : '';
496  $number = (isset($_POST['num_questions'])) ? $_POST['num_questions'] : '';
497  // get the number of questions in the system allready
498  // so when we create the new ones, we can give them an
499  // appropriate name
500 
501  $am = $GLOBALS['SQ_SYSTEM']->am;
502  $curr_question_count = $asset->getQuestionCount() + 1;
503 
504  if ($type && $number) {
505 
506  $am->includeAsset($type);
507  // create some questions
508  for ($i = 0; $i < $number; $i++) {
509  if (!$asset->attachQuestion($type)) return FALSE;
510  $curr_question_count++;
511  }//end for
512  }//end if
513 
514  return TRUE;
515 
516  }//end processAddQuestions()
517 
518 
529  function paintAddSections(&$asset, &$o, $prefix)
530  {
531  if (!$asset->writeAccess('links')) return FALSE;
532 
533  $option_list = new Asset_Attribute_Option_List();
534  $option_list->paint($prefix.'_sections');
535 
536  return TRUE;
537 
538  }//end paintAddSections()
539 
540 
551  function processAddSections(&$asset, &$o, $prefix)
552  {
553  $sections = Array();
554  $new = trim(array_get_index($_REQUEST, $prefix.'_sections_new_options',''));
555  if (!empty($new)) $sections[] = $new;
556 
557  $section_text = array_get_index($_POST, $prefix.'_sections_options', '');
558  if (!empty($section_text)) {
559  // make sure the section names are not empty
560  foreach ($section_text as $option) {
561  $option = trim($option);
562  if (empty($option)) continue;
563  $sections[] = $option;
564  }
565  }
566 
567  if (empty($sections)) return FALSE;
568 
569  // now that we have the section names, display them in the order entered
570  $am = $GLOBALS['SQ_SYSTEM']->am;
571 
572  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
573  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
574 
575  for ($i = 0; $i < count($sections); $i++) {
576  $section_name = $sections[$i];
577 
578  $section_count = $asset->getSectionCount() + 1;
579 
580  $am->includeAsset('form_section');
581  $section[$i] = new Form_Section();
582  $copy_link = Array('asset' => &$asset, 'link_type' => SQ_LINK_TYPE_2, 'is_dependant' => 0, 'is_exclusive' => 0);
583 
584  $section[$i]->setAttrValue('name', $section_name);
585 
586  if (!$section[$i]->create($copy_link)) {
587  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
588  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
589  return FALSE;
590  }
591 
592  // Our form section depends on form_email it is linked under although the
593  // is_dependent flag on the link isn't set we still have to make sure the
594  // status of the section is in sync with the Custom form
595  if ($section[$i]->status != $asset->status && in_array($asset->status, array_keys($section[$i]->getAvailableStatii()))) {
596  $section[$i]->processStatusChange($asset->status, FALSE, FALSE);
597  }
598 
599  }//end for
600  if (count($sections) > 0) $asset->_updated();
601 
602  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
603  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
604 
605  return TRUE;
606 
607  }//end processAddSections()
608 
609 
618  function paintSubmissions(&$asset)
619  {
620  return TRUE;
621 
622  }//end paintSubmissions()
623 
624 
633  function processSubmissions(&$asset)
634  {
635  return TRUE;
636 
637  }//end processSubmissions()
638 
639 
650  function paintSimpleFormatting(&$asset, &$o, $prefix)
651  {
652  ?>
653  <p><?php echo translate('cms_form_simple_formatting_note') ?></p>
654 
655  <?php
656  return TRUE;
657 
658  }//end paintSimpleFormatting()
659 
660 
673  function processSimpleFormatting(&$asset, &$o, $prefix)
674  {
675  return FALSE;
676 
677  }//end processSimpleFormatting()
678 
679 
690  function paintComplexFormatting(&$asset, &$o, $prefix)
691  {
692  ?>
693  <p><?php echo translate('cms_form_complex_formatting_note') ?><br/>
694  <?php echo translate('cms_form_page_contents_popup_link', sq_web_path('data').'/asset_types/form/popups/page_contents_keywords.php?assetid='.$asset->id, 580, 520) ?><br/>
695  <?php echo translate('cms_form_thank_you_popup_link', sq_web_path('data').'/asset_types/form/popups/thank_you_keywords.php?assetid='.$asset->id, 580, 520) ?><br/>
696  <?php
697  return TRUE;
698 
699  }//end paintComplexFormatting()
700 
701 
714  function processComplexFormatting(&$asset, &$o, $prefix)
715  {
716  return FALSE;
717 
718  }//end processComplexFormatting()
719 
720 
731  function paintCaptchaFontField(&$asset, &$o, $prefix)
732  {
733  if ($asset->writeAccess('attributes')) {
734  asset_finder($prefix.'_captcha_ttf', $asset->attr('captcha_ttf'), Array('file' => 'D'));
735  } else {
736  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($asset->attr('captcha_ttf'));
737  $ttf_file_id = $asset->attr('captcha_ttf');
738  if ($ttf_file_id > 0) {
739  echo get_asset_tag_line($ttf_file_id);
740  } else {
741  echo translate('none_selected');
742  }
743  }
744  return TRUE;
745 
746  }//end paintCaptchaFontField()
747 
748 
759  function processCaptchaFontField(&$asset, &$o, $prefix)
760  {
761  if (isset($_POST[$prefix.'_captcha_ttf'])) {
762  $ttf_file_id = $_POST[$prefix.'_captcha_ttf']['assetid'];
763 
764  if ($ttf_file_id != $asset->attr('captcha_ttf')) {
765  if ($ttf_file_id > 0) {
766  // Grab the specified asset - it should be a File - and ensure that it is a TrueType Font
767  $ttf_file = $GLOBALS['SQ_SYSTEM']->am->getAsset($ttf_file_id);
768 
769  $ttf_file_info = $ttf_file->getExistingFile();
770  $filename = strtolower($ttf_file_info['filename']);
771 
772  $extension_index = strpos($filename, '.ttf');
773  if (($extension_index !== FALSE) && ($extension_index == strlen($filename)-4)) {
774  return $asset->setAttrValue('captcha_ttf', $ttf_file_id);
775  } else {
776  trigger_localised_error('CMS0109', E_USER_WARNING);
777  }
778  } else {
779  return $asset->setAttrValue('captcha_ttf', NULL);
780  }
781  }
782  }
783 
784  return FALSE;
785 
786  }//end processCaptchaFontField()
787 
788 
797  function generateStandardContentFile(&$asset)
798  {
799  // Generate unattached questions if we haven't already
800  if (!$this->generateQuestionsContentFile($asset)) {
801  return FALSE;
802  }
803 
804  // Now create the full default file, including the unattached questions
805  $output = '<'.'?php'."\n";
806  $output .= '$form_asset = $GLOBALS["SQ_SYSTEM"]->am->getAsset('.$asset->id.');'."\n";
807  $output .= 'include_once('.str_replace(SQ_DATA_PATH, 'SQ_DATA_PATH."', $asset->data_path).'/content_file_questions.php'.'");'."\n";
808  $sections = $asset->getSections();
809  foreach ($sections as $section) {
810  // output an include BUT we want to make what's printed relative to SQ_DATA_PATH
811  $output .= 'include_once('.str_replace(SQ_DATA_PATH, 'SQ_DATA_PATH."', $section->data_path).'/content_file.php'.'");'."\n";
812  }
813  $output .= '?'.'>';
814 
815  // if there are any tags left that haven't been replaced,
816  // we want to strip them out
817  $output = preg_replace('/%[^<>%]+%/', '', $output);
818 
819  create_directory($asset->data_path);
820  return string_to_file($output, $asset->data_path.'/content_file.php');
821 
822  }//end generateStandardContentFile()
823 
824 
834  {
835  // Get the unattached questions into one file
836  $output = '<'.'?php $form_asset=$GLOBALS["SQ_SYSTEM"]->am->getAsset('.$asset->id.'); ?'.'>'."\n";
837  $output .= $this->generateGenericSection($asset);
838 
839  // if there are any tags left that haven't been replaced,
840  // we want to strip them out
841  $output = preg_replace('/%[^<>%]+%/', '', $output);
842 
843  create_directory($asset->data_path);
844  return string_to_file($output, $asset->data_path.'/content_file_questions.php');
845 
846  }//end generateQuestionsContentFile()
847 
848 
857  function generateGenericSection(&$asset)
858  {
859  $output = '<table';
860  if ((int)$asset->attr('form_width')) {
861  $output .= ' width="'.$asset->attr('form_width').'"';
862  }
863  $output .= '>';
864  $sort_order = $asset->attr('sort_order');
865  if (empty($sort_order)) return;
866 
867  foreach ($sort_order as $i => $assetid) {
868  $q = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
869  if (is_null($q)) continue;
870 
871  $output .= '<tr>';
872  $output .= '<td valign="top"';
873  $output .= ($asset->attr('question_col_width')) ? ' width="'.$asset->attr('question_col_width').'">' : '>';
874  $label = $q->getHtmlLabel();
875  escape_php($label);
876  $output .= $label;
877  if ($q->getVal('note')) {
878  $output .= '<br /><span style="font-size:'.($asset->attr('note_size') ? $asset->attr('note_size') : '80%').'">'.$q->getVal('note').'</span>';
879  }
880  $output .= '</td><td';
881  $output .= ($asset->attr('answer_col_width')) ? ' width="'.$asset->attr('answer_col_width').'">' : '>';
882  $output .= '<'.'?php $q = $GLOBALS["SQ_SYSTEM"]->am->getAsset("'.$assetid.'");
883  echo $q->getHtmlField(); ?'.'>'."\n";
884  $output .= '</td></tr>';
885  }
886  $output .= '</table>';
887 
888  return $output;
889 
890  }//end generateGenericSection()
891 
892 
893 //-- MOLLOM CAPTCHA --//
894 
895 
906  function paintMollomQuestionToCheck(&$asset, &$o, $prefix)
907  {
908  $write_access = $asset->writeAccess('attributes');
909  $current = $asset->attr('mollom_questions_to_check');
910 
911  $relevent_question_types = Array('form_question_type_text', 'form_question_type_email_address');
912  $form_questions = $asset->getAllQuestions();
913 
914  $questions = Array();
915  foreach ($form_questions as $q_id => $q_info) {
916 
917  $q_type = isset($q_info['question_type_code']) ? $q_info['question_type_code'] : '';
918  if (!in_array($q_type, $relevent_question_types)) {
919  continue;
920  }
921 
922  $q_name = isset($q_info['attributes']['name']) ? $q_info['attributes']['name'] : $q_id.' (No name)';
923  $questions[$q_id] = $q_id.' '.ucwords(str_replace('_', ' ', $q_name));
924  }
925 
926  if (empty($current)) {
927  echo translate('cms_form_mollom_no_question_to_check');
928  } else {
929  ?>
930  <table class="sq-backend-table">
931  <tr>
932  <td class="sq-backend-table-header"><?php echo translate('name') ?></td>
933  <td class="sq-backend-table-header">Content Type</td>
934  <?php
935  if ($write_access) {
936  ?><td class="sq-backend-table-header"><?php echo translate('delete_question') ?></td><?php
937  }
938  ?>
939  </tr>
940  <?php
941  foreach ($current as $q_id => $content_type) {
942  $question_name = isset($questions[$q_id]) ? $questions[$q_id] : '';
943  if (!$question_name) {
944  continue;
945  }
946  ?>
947  <tr>
948  <td class="sq-backend-table-cell"><?php echo $question_name; ?></td>
949  <td class="sq-backend-table-cell">
950  <?php
951  $content_types = Array();
952  if (file_exists(SQ_FUDGE_PATH.'/mollom/mollom.inc')) {
953  require_once SQ_FUDGE_PATH.'/mollom/mollom.inc';
954  $mollom = new Mollom();
955  $content_types = $mollom->getContentTypes();
956  }
957 
958  if ($write_access) {
959  combo_box($prefix.'_content_type['.$q_id.']', $content_types, FALSE, $content_type);
960  } else {
961  echo isset($content_types[$content_type]) ? $content_types[$content_type] : '';
962  }
963  ?>
964  </td>
965  <?php
966  if ($write_access) {
967  ?>
968  <td class="sq-backend-table-cell">
969  <?php check_box($prefix.'_delete_content_type['.$q_id.']'); ?>
970  </td>
971  <?php
972  }
973  ?>
974  </tr>
975  <?php
976  }//end foreach
977  ?>
978  </table>
979  <?php
980  }//end else
981 
982  if ($write_access) {
983  $new_questions = Array('' => '-- '.translate('select_question').' --');
984  foreach ($questions as $q_id => $q_name) {
985  if (isset($current[$q_id])) continue;
986  $new_questions[$q_id] = $q_name;
987  }
988 
989  echo '<br/><b>'.translate('cms_form_new_mollom_question').' </b>';
990  combo_box($prefix.'_new_content_type', $new_questions, FALSE, '');
991  }
992 
993  return $write_access;
994 
995  }//end paintMollomQuestionToCheck()
996 
997 
1008  function processMollomQuestionToCheck(&$asset, &$o, $prefix)
1009  {
1010  $current = $asset->attr('mollom_questions_to_check');
1011  $content_types = Array();
1012 
1013  // construct new questions to check fields array removing deleted questions
1014  // and updating the question's answer type
1015  foreach ($current as $q_id => $q_name) {
1016  if (!isset($_POST[$prefix.'_delete_content_type'][$q_id]) || !$_POST[$prefix.'_delete_content_type'][$q_id]) {
1017  if (isset($_POST[$prefix.'_content_type'][$q_id])) {
1018  $content_types[$q_id] = trim($_POST[$prefix.'_content_type'][$q_id]);
1019  } else {
1020  $content_types[$q_id] = $current[$q_id];
1021  }//end else
1022  }//end if
1023  }//end foreach
1024 
1025  // add new required field
1026  if (isset($_POST[$prefix.'_new_content_type']) && !empty($_POST[$prefix.'_new_content_type'])) {
1027  $new_question = $_POST[$prefix.'_new_content_type'];
1028  if (!isset($content_types[$new_question])) {
1029  $content_types[$new_question] = '';
1030  }
1031  }
1032 
1033  return $asset->setAttrValue('mollom_questions_to_check', $content_types);
1034 
1035  }//end processMollomQuestionToCheck()
1036 
1037 
1048  function paintSubmissionLimit(&$asset, &$o, $prefix)
1049  {
1050  $submission_limit = $asset->attr('submission_limit');
1051  $write_access = $asset->writeAccess('attributes');
1052  $sub_logging = $asset->attr('log_submissions');
1053 
1054  if ($sub_logging) {
1055  if ($write_access) {
1056  text_box($prefix.'_submission_limit', $submission_limit, 5);
1057  } else {
1058  echo $submission_limit;
1059  }
1060  } else {
1061  echo "<b>This feature can be used only if the Submission logging is turned on.</b>";
1062  }
1063 
1064  return FALSE;
1065 
1066  }//end paintSubmissionLimit()
1067 
1068 
1079  function processSubmissionLimit(&$asset, &$o, $prefix)
1080  {
1081  $submission_limit = $asset->attr('submission_limit');
1082  $write_access = $asset->writeAccess('attributes');
1083 
1084  $new_value = array_get_index($_REQUEST, $prefix.'_submission_limit', $submission_limit);
1085 
1086  if ($write_access && ($submission_limit != $new_value) && $asset->attr('log_submissions')) {
1087  $asset->setAttrValue('submission_limit', $new_value);
1088  $asset->saveAttributes();
1089 
1090  // now if the previous value was zero and has
1091  // been changed to non-zero or vice versa
1092  // we need to show hide the bodycopy for it
1093  if ($submission_limit == 0 || $new_value == 0) {
1094  $bc_name = 'Submission Limit Reached';
1095  if ($submission_limit == 0) {
1096  // show bodycopy
1097  $bodycopy = $asset->getBodycopy($bc_name, SQ_LINK_TYPE_2);
1098  if (is_null($bodycopy)) $bodycopy = $asset->getBodycopy($bc_name, SQ_LINK_NOTICE);
1099  if (is_null($bodycopy)) {
1100  $asset->createBodycopy($bc_name, Array('content' => 'Number of submissions allowed for this form has reached. No more submissions are allowed.'));
1101  } else {
1102  // bodycopy already exists but must be type 3 linked, convert
1103  // the link to type 2 so that it is visible in the asset map
1104  $bodycopy_link = $GLOBALS['SQ_SYSTEM']->am->getLink($bodycopy->id, SQ_LINK_NOTICE, 'folder', TRUE, NULL, 'minor');
1105  $GLOBALS['SQ_SYSTEM']->am->moveLink($bodycopy_link['linkid'], $bodycopy_link['majorid'], SQ_LINK_TYPE_2, $bodycopy_link['sort_order'], $bodycopy_link['value']);
1106  }
1107  } else if ($new_value == 0) {
1108  // hide bodycopy?
1109  // simply convert the link type to type 3 so the bodycop is hidden
1110  $bodycopy = $asset->getBodycopy($bc_name, SQ_LINK_TYPE_2);
1111  if (!is_null($bodycopy)) {
1112  $bodycopy_link = $GLOBALS['SQ_SYSTEM']->am->getLink($bodycopy->id, SQ_LINK_TYPE_2, 'folder', TRUE, NULL, 'minor');
1113  $GLOBALS['SQ_SYSTEM']->am->moveLink($bodycopy_link['linkid'], $bodycopy_link['majorid'], SQ_LINK_NOTICE, $bodycopy_link['sort_order'], $bodycopy_link['value']);
1114  }
1115  }
1116  }
1117  }
1118 
1119  return FALSE;
1120 
1121  }//end processSubmissionLimit()
1122 
1123 
1124 }//end class
1125 ?>