dokeos
[ class tree: dokeos ] [ index: dokeos ] [ all elements ]

Source for file charEncodingTest.php

Documentation is available at charEncodingTest.php

  1. <?php
  2. require_once("../xajax.inc.php");
  3.  
  4. function setOptions($formData)
  5. {
  6.     $_SESSION['useEncoding'$formData['useEncoding'];
  7.     $_SESSION['htmlEntities'= (boolean)$formData['htmlEntities'];
  8.     $_SESSION['decodeUTF8'= (boolean)$formData['decodeUTF8'];
  9.     $objResponse new xajaxResponse();
  10.     $objResponse->addAlert("Your options have been saved.");
  11.     return $objResponse;
  12. }
  13.  
  14. function testForm($strText$formData$arrArray)
  15. {
  16.     global $useEncoding$htmlEntities;
  17.     $objResponse new xajaxResponse($useEncoding$htmlEntities);
  18.     $data "Text:\n" $strText;
  19.     $data .= "\n\nFormData:\n" print_r($formDatatrue);
  20.     $data .= "\n\nArray:\n" .print_r($arrArraytrue)
  21.     $objResponse->addAlert($data);
  22.     $objResponse->addAssign("submittedDiv""innerHTML""<pre>".$data."</pre>");
  23.     return $objResponse->getXML();
  24. }
  25.  
  26. $useEncoding "UTF-8";
  27. $htmlEntities false;
  28. $decodeUTF8 false;
  29.  
  30. session_name("xajaxCharEncodingTest");
  31.  
  32. if (@$_GET['refresh'== "yes"{
  33.     session_destroy();
  34.     header("location: charEncodingTest.php");
  35.     exit();
  36. }
  37.  
  38. if (isset($_SESSION['useEncoding'])) {
  39.     $useEncoding $_SESSION['useEncoding'];    
  40. }
  41. if (isset($_SESSION['htmlEntities'])) {
  42.     $htmlEntities $_SESSION['htmlEntities'];    
  43. }
  44. if (isset($_SESSION['decodeUTF8'])) {
  45.     $decodeUTF8 $_SESSION['decodeUTF8'];    
  46. }
  47.  
  48. $xajax new xajax();
  49. $xajax->setCharEncoding($useEncoding);
  50. if ($htmlEntities{
  51.     $xajax->outputEntitiesOn();    
  52. }
  53. if ($decodeUTF8{
  54.     $xajax->decodeUTF8InputOn();
  55. }
  56. //$xajax->debugOn();
  57. $xajax->registerFunction("setOptions");
  58. $xajax->registerFunction("testForm");
  59. $xajax->processRequests();
  60. ?>
  61. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  62.         "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
  63. <html xmlns="http://www.w3.org/1999/xhtml">
  64. <head>
  65. <title>Character Encoding Test | xajax Tests</title>
  66. <?php $xajax->printJavascript("../"?>
  67. <script type="text/javascript">
  68. function getTestArray()
  69. {
  70.     var text = xajax.$('textField1').value;
  71.     var testArray = new Array();
  72.     testArray[0] = text;
  73.     testArray[1] = text;
  74.     testArray[2] = new Array();
  75.     testArray[2][0] = text;
  76.     testArray[2][1] = text; 
  77.     testArray[3] = new Array();
  78.     testArray[3][0] = text;
  79.     testArray[3][1] = text;
  80.     testArray[3][2] = new Array();
  81.     testArray[3][2][0] = text;
  82.     testArray[3][2][1] = text;
  83.     
  84.     return testArray;
  85. }
  86.  
  87. function callXajax()
  88. {
  89.     var txt = xajax.$('textField1').value;
  90.     var frm = xajax.getFormValues('testForm1');
  91.     var arr = getTestArray();
  92.     xajax_testForm(txt,frm,arr);
  93. }
  94. </script>
  95. </head>
  96. <body>
  97.  
  98. <h2><a href="index.php">xajax Tests</a></h2>
  99. <h1>Character Encoding Test</h1>
  100.  
  101. <h2>Options Form</h2>
  102.  
  103. <p><strong>NOTE:</strong> if you change these options, make sure you click the Save Options button or the options won't be used.</p>
  104.  
  105. <form id="optionsForm" onsubmit="return false;">
  106. <p>Encoding: <input type="text" value="<?php echo $useEncoding ?>" name="useEncoding" /><br />
  107. Output HTML Entities? <input type="radio" name="htmlEntities" value="1" <?php if ($htmlEntitiesecho ' checked="checked"' ?>/> Yes
  108.  <input type="radio" name="htmlEntities" value="0" <?php if (!$htmlEntitiesecho ' checked="checked"' ?>/> No<br />
  109. Decode UTF-8 Input? <input type="radio" name="decodeUTF8" value="1" <?php if ($decodeUTF8echo ' checked="checked"' ?>/> Yes
  110.  <input type="radio" name="decodeUTF8" value="0" <?php if (!$decodeUTF8echo ' checked="checked"' ?>/> No<br />
  111. <p><input type="submit" value="Save Options" onclick="xajax_setOptions(xajax.getFormValues('optionsForm')); return false;" /></p>
  112. </form>
  113.  
  114. <p><a href="charEncodingTest.php?refresh=yes">Clear and Refresh</a></p>
  115.  
  116. <h2>Text Test Form</h2>
  117.  
  118. <p><a href="http://www.i18nguy.com/unicode-example.html" target="_blank">Here are some Unicode examples</a> you can paste into the text box below. You can see <a href="http://www.unicode.org/iuc/iuc10/languages.html" target="_blank">more examples and a list of standard encoding schemes here</a>.</p>
  119.  
  120. <form id="testForm1" onsubmit="return false;">
  121. <p><input type="text" value="Enter test text here" id="textField1" name="textField1" size="60" /></p>
  122. <p><input type="submit" value="Submit Text" onclick="callXajax(); return false;" /></p>
  123. </form>
  124.  
  125. <div id="submittedDiv"></div>
  126. <div id="debugDiv"></div>
  127.  
  128. </body>
  129. </html>

Documentation generated on Thu, 12 Jun 2008 13:03:08 -0500 by phpDocumentor 1.4.1