PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/mambots/content/scform.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 122 lines | 76 code | 22 blank | 24 comment | 8 complexity | 49b33520fd748c879fb98740746ff2b9 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Components Lab Support center
  4. * www.componentslab.com
  5. *
  6. * @package SupportCenter
  7. * @copyright (C) 2000-2007 Components Lab, Lda.,
  8. * @license Commercial
  9. *
  10. **/
  11. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  12. /**
  13. * Show Form Mambot
  14. *
  15. * <b>Usage:</b>
  16. * <code>{scform}...form id...{/scform}</code>
  17. */
  18. global $mosConfig_lang, $mosConfig_absolute_path;
  19. include_once( $mosConfig_absolute_path.'/components/com_supportcenter/includes/common.php' );
  20. include_once( $mosConfig_absolute_path.'/components/com_supportcenter/classes/spam.class.php' );
  21. $_MAMBOTS->registerFunction( 'onPrepareContent', 'botCLABForms' );
  22. function botCLABForms( $published, &$row, &$params, $page=0 ) {
  23. global $database, $my, $mosConfig_absolute_path, $mosConfig_lang;
  24. if( file_exists( $mosConfig_absolute_path.'/components/com_supportcenter/language/'.$mosConfig_lang.'.php' ) ) {
  25. include( $mosConfig_absolute_path.'/components/com_supportcenter/language/'.$mosConfig_lang.'.php' );
  26. }else{
  27. include( $mosConfig_absolute_path.'/components/com_supportcenter/language/english.php' );
  28. }
  29. $blocker = new formSpamBotBlocker();
  30. $blocker->setTrap(true,"sptr@p","Do not enter anything in this field!");
  31. $hiddenTags = $blocker->makeTags(); // create the xhtml string containing the required form elements
  32. // next line is a fix for /m option not working as it should??
  33. $row->text = str_replace( "\n", "__CRLF__", $row->text );
  34. preg_match_all( "/{scform}(.*?){\/scform}/im", $row->text, $bots, PREG_SET_ORDER );
  35. // split the text around the mambot
  36. $text = preg_split( "/{scform}(.*?){\/scform}/im", $row->text );
  37. // count the number of forms present
  38. $n = count( $text );
  39. if ($n > 0) {
  40. $row->text = '';
  41. for ($i=0; $i < $n; $i++) {
  42. $row->text .= str_replace( "__CRLF__", "\n", $text[$i] );
  43. if (trim( @$bots[$i][1] )) {
  44. $code = @$bots[$i][1];
  45. $code = str_replace( "\r", "", $code );
  46. $code = str_replace( "__CRLF__", "\n", $code );
  47. //Get the form component Itemid ***************************************************************
  48. $database->setQuery( "SELECT id FROM #__components WHERE link='option=com_supportcenter'" );
  49. $comItemid = $database->loadResult();
  50. //Get the form info ***************************************************************
  51. $database->setQuery( "SELECT * FROM #__support_form WHERE id='".$code."'" );
  52. $rowForm = null;
  53. $database->loadObject( $rowForm );
  54. //Get the form actions ************************************************************
  55. $database->setQuery( "SELECT * FROM #__support_form_action WHERE id_form='".$code."'" );
  56. $rowActions = $database->loadObjectList();
  57. //Get the form fields *************************************************************
  58. $database->setQuery( "SELECT * FROM #__support_form_field WHERE id_form='".$code."' ORDER BY `order`" );
  59. $rowFields = $database->loadObjectList();
  60. //Builds the validation javascript ************************************************
  61. $row->text .= "<script>\n";
  62. $row->text .= "function ValidateFields() {\n";
  63. for ($x=0; $x < count($rowFields); $x++) {
  64. $rowField = $rowFields[$x];
  65. if($rowField->required=="1") {
  66. $row->text .= "if(document.".str_replace(" ", "", $rowForm->name).".custom".$rowField->id.".value==\"\") {\n";
  67. $row->text .= " alert(\"".str_replace( '%1', $rowField->caption, $sc2lang['field_required'] )."\")\n";
  68. $row->text .= " document.".str_replace(" ", "", $rowForm->name).".custom".$rowField->id.".focus();\n";
  69. $row->text .= " return false\n";
  70. $row->text .= "}\n";
  71. }
  72. }
  73. $row->text .= "return true\n";
  74. $row->text .= "}\n";
  75. $row->text .= "</script>\n";
  76. //Builds the form *****************************************************************
  77. $row->text .= "<form name='".str_replace(" ", "", $rowForm->name)."' action='index.php?option=com_supportcenter&task=forms_save&Itemid=".$comItemid."' method='POST' onSubmit='return ValidateFields();'>\n";
  78. $row->text .= "<table width='100%'>\n";
  79. for ($x=0; $x < count($rowFields); $x++) {
  80. $rowField = $rowFields[$x];
  81. $row->text .= '<tr>';
  82. $row->text .= '<td width="100">'.utf8_decode($rowField->caption).'</td>';
  83. $row->text .= '<td>'.WriteField( 0, $rowField->id, $rowField->type, $rowField->value, $rowField->size, $rowField->maxlength, 0, $code ).($rowField->required ? '<img src="components/com_supportcenter/images/16px/link.png" border="0" alt="'.$sc2lang['required'].'" align="absmiddle" />' : '').'</td>';
  84. $row->text .= '</tr>';
  85. }
  86. $row->text .= "</table>\n";
  87. $row->text .= '<p>'.$sc2lang['field_required_desc']."\n<br />";
  88. $row->text .= "<input type='submit' name='submit' value='".$sc2lang['save']."' class='button'></p>\n";
  89. $row->text .= "<input type='hidden' name='redirect' value='".$rowForm->redirect."'>\n";
  90. $row->text .= "<input type='hidden' name='id' value='".$rowForm->id."'>\n";
  91. $row->text .= "<input type='hidden' name='pageurl' value='".$_SERVER["PHP_SELF"]."'>\n";
  92. $row->text .= $hiddenTags;
  93. $row->text .= "</form>\n";
  94. }
  95. }
  96. } else {
  97. $row->text = str_replace( "__CRLF__", "\n", $row->text );
  98. }
  99. }
  100. ?>