PageRenderTime 36ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/smarty2/plugins/function.init.php

http://zoop.googlecode.com/
PHP | 94 lines | 80 code | 13 blank | 1 comment | 8 complexity | 4ca0f0455438329b755cd23d0ba60079 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. function smarty_function_init($params, &$smarty)
  3. {
  4. $modules = isset($params['type']) ? $params['type'] : array('dnd', 'ajax', 'input');
  5. foreach($modules as $thisModule)
  6. {
  7. GuiInit::$thisModule();
  8. }
  9. }
  10. class GuiInit
  11. {
  12. function dnd()
  13. {
  14. }
  15. function ajax()
  16. {
  17. }
  18. function input()
  19. {
  20. ?>
  21. <script>
  22. function GuiValidateForm()
  23. {
  24. var ok = true;
  25. var message = 'Please correct the following mistakes in the form:\n';
  26. var constraints = document.getElementsByTagName("constraint");
  27. // var names = {};
  28. for(var i = 0; i < constraints.length; i++)
  29. {
  30. var res = GuiCheckConstraint(constraints[i]);
  31. if(!res['ok'])
  32. {
  33. ok = false;
  34. message += "\n" + res['message'];
  35. var onemessage = res['message'];
  36. }
  37. else
  38. var onemessage = '';
  39. var status = document.getElementById('gui_status_' + constraints[i].name);
  40. if(status && onemessage)
  41. status.innerText = onemessage;
  42. }
  43. if(!ok)
  44. {
  45. alert(message);
  46. return false;
  47. }
  48. return true;
  49. }
  50. function GuiCheckConstraint(constraint)
  51. {
  52. var res = {ok: true, message: ''};
  53. switch(constraint.type)
  54. {
  55. case 'minlen':
  56. var input = document.getElementById(constraint.name);
  57. if(input.value.length < constraint.value)
  58. {
  59. res['ok'] = false;
  60. res['message'] = constraint.inline;
  61. }
  62. break;
  63. case 'sameas':
  64. var input = document.getElementById(constraint.name);
  65. var input2 = document.getElementById(constraint.value);
  66. if(input.value != input2.value)
  67. {
  68. res['ok'] = false;
  69. res['message'] = constraint.inline;
  70. }
  71. break;
  72. default:
  73. throw "Bad constraint type";
  74. break;
  75. }
  76. return res;
  77. }
  78. </script>
  79. <?php
  80. }
  81. }