Guest User

Untitled

a guest
May 27th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1. <?php
  2. /*
  3. *
  4. * @(#) $Id: form_custom_validation.php,v 1.3 2008/02/12 02:02:30 mlemos Exp $
  5. *
  6. */
  7.  
  8. function seDay($begin, $end, $format, $sep)
  9. {
  10. $pos1 = strpos($format, 'd');
  11. $pos2 = strpos($format, 'm');
  12. $pos3 = strpos($format, 'Y');
  13.  
  14. $begin = explode($sep, $begin);
  15. $end = explode($sep, $end);
  16.  
  17. $first = GregorianToJD($end[$pos2], $end[$pos1], $end[$pos3]);
  18. $second = GregorianToJD($begin[$pos2], $begin[$pos1], $begin[$pos3]);
  19.  
  20.  
  21. if ($first > $second)
  22. return $first - $second;
  23. else
  24. return $second - $first;
  25. }
  26.  
  27.  
  28. if(!defined("PHP_LIBRARY_CUSTOM_VALIDATION_FORMS"))
  29. {
  30. define("PHP_LIBRARY_CUSTOM_VALIDATION_FORMS",1);
  31.  
  32. class form_custom_validation_class extends form_custom_class
  33. {
  34. /*
  35. * Tell the forms class that this custom input will perform both server
  36. * side and client side validation.
  37. */
  38. var $client_validate=1;
  39. var $server_validate=1;
  40.  
  41. var $anreisetag='';
  42. var $anreisemonat='';
  43. var $anreisejahr='';
  44.  
  45. var $abreisetag='';
  46. var $abreisemonat='';
  47. var $abreisejahr='';
  48.  
  49. var $minstay='';
  50.  
  51. var $minstay_validation_error_message='Minstay nicht korrekt.';
  52.  
  53.  
  54. var $first='';
  55. var $second='';
  56.  
  57.  
  58.  
  59.  
  60. var $first_validation_error_message='The first input value is contained in the second.';
  61. var $second_validation_error_message='The second input value is contained in the first.';
  62.  
  63.  
  64. Function AddInput(&$form, $arguments)
  65. {
  66. /*
  67. * Get the identifiers of the inputs to validate
  68. */
  69. if(!IsSet($arguments['FirstInput'])
  70. || strlen($this->first=$arguments['FirstInput'])==0)
  71. return('It was not specified a valid first input identifier');
  72.  
  73. if(!IsSet($arguments['SecondInput'])
  74. || strlen($this->second=$arguments['SecondInput'])==0)
  75. return('It was not specified a valid second input identifier');
  76.  
  77. if(!IsSet($arguments['AnreisetagInput'])
  78. || strlen($this->anreisetag=$arguments['AnreisetagInput'])==0)
  79. return('It was not specified a valid AnreisetagInput input identifier');
  80.  
  81. if(!IsSet($arguments['AnreisemonatInput'])
  82. || strlen($this->anreisemonat=$arguments['AnreisemonatInput'])==0)
  83. return('It was not specified a valid AnreisemonatInput input identifier');
  84.  
  85. if(!IsSet($arguments['AnreisejahrInput'])
  86. || strlen($this->anreisejahr=$arguments['AnreisejahrInput'])==0)
  87. return('It was not specified a valid AnreisejahrInput input identifier');
  88.  
  89.  
  90.  
  91. if(!IsSet($arguments['AbreisetagInput'])
  92. || strlen($this->abreisetag=$arguments['AbreisetagInput'])==0)
  93. return('It was not specified a valid AbreisetagInput input identifier');
  94.  
  95. if(!IsSet($arguments['AbreisemonatInput'])
  96. || strlen($this->abreisemonat=$arguments['AbreisemonatInput'])==0)
  97. return('It was not specified a valid AbreisemonatInput input identifier');
  98.  
  99. if(!IsSet($arguments['AbreisejahrInput'])
  100. || strlen($this->abreisejahr=$arguments['AbreisejahrInput'])==0)
  101. return('It was not specified a valid AbreisejahrInput input identifier');
  102.  
  103.  
  104. if(!IsSet($arguments['MinstayInput'])
  105. || strlen($this->minstay=$arguments['MinstayInput'])==0)
  106. return('It was not specified a valid MinstayInput input identifier');
  107.  
  108.  
  109. /*
  110. * Get the error messages to assign when the inputs are invalid.
  111. */
  112.  
  113. if(IsSet($arguments['SecondValidationErrorMessage']))
  114. {
  115. if(strlen($arguments['SecondValidationErrorMessage'])==0)
  116. return('It was not specified a valid second validation error message');
  117. $this->second_validation_error_message=$arguments['SecondValidationErrorMessage'];
  118. }
  119.  
  120. if(IsSet($arguments['MinstayValidationErrorMessage']))
  121. {
  122. if(strlen($arguments['MinstayValidationErrorMessage'])==0)
  123. return('It was not specified a valid Minstay validation error message');
  124. $this->minstay_validation_error_message=$arguments['MinstayValidationErrorMessage'];
  125. }
  126.  
  127. if(IsSet($arguments['FirstValidationErrorMessage']))
  128. {
  129. if(strlen($arguments['FirstValidationErrorMessage'])==0)
  130. return('It was not specified a valid first validation error message');
  131. $this->first_validation_error_message=$arguments['FirstValidationErrorMessage'];
  132. }
  133.  
  134. return('');
  135. }
  136.  
  137.  
  138.  
  139.  
  140.  
  141. Function ValidateInput(&$form)
  142. {
  143. /*
  144. * Perform server side validation by checking whether one of the
  145. * input values contains the other.
  146. *
  147. * This function is called after all validations were performed on
  148. * all basic inputs.
  149. */
  150.  
  151. $first=$form->GetInputValue($this->first);
  152. $second=$form->GetInputValue($this->second);
  153.  
  154. $anreisetag=$form->GetInputValue($this->anreisetag);
  155. $anreisemonat=$form->GetInputValue($this->anreisemonat);
  156. $anreisejahr=$form->GetInputValue($this->anreisejahr);
  157.  
  158. $abreisetag=$form->GetInputValue($this->abreisetag);
  159. $abreisemonat=$form->GetInputValue($this->abreisemonat);
  160. $abreisejahr=$form->GetInputValue($this->abreisejahr);
  161.  
  162. $minstay=$form->GetInputValue($this->minstay);
  163.  
  164.  
  165. $datum1 = $anreisetag.".".$anreisemonat.".".$anreisejahr;
  166. $datum2 = $abreisetag.".".$abreisemonat.".".$abreisejahr;
  167.  
  168.  
  169. $stay = seDay($datum1,$datum2,"dmY",".");
  170.  
  171.  
  172. if($minstay > $stay)
  173.  
  174. {
  175. $form->FlagInvalidInput($this->minstay, $this->minstay_validation_error_message);
  176. return('');
  177. }
  178.  
  179.  
  180.  
  181.  
  182. if(strlen($first)
  183. && strstr($second, $first))
  184. {
  185. $form->FlagInvalidInput($this->first, $this->first_validation_error_message);
  186. return('');
  187. }
  188.  
  189.  
  190. if(strlen($second)
  191. && strstr($first, $second))
  192. {
  193. $form->FlagInvalidInput($this->second, $this->second_validation_error_message);
  194. return('');
  195. }
  196. return('');
  197. }
  198.  
  199. Function GetJavascriptValidations(&$form, $form_object, &$validations)
  200. {
  201. /*
  202. * Generate all the necessary Javascript to perform server side
  203. * validation.
  204. */
  205.  
  206.  
  207.  
  208. if(strlen($first=$form->GetJavascriptInputValue($form_object,$this->first))==0)
  209. return('it was not possible to retrieve the first input Javascript value');
  210.  
  211. if(strlen($second=$form->GetJavascriptInputValue($form_object,$this->second))==0)
  212. return('it was not possible to retrieve the second input Javascript value');
  213.  
  214. if(strlen($anreisetag=$form->GetJavascriptInputValue($form_object,$this->anreisetag))==0)
  215. return('it was not possible to retrieve the anreisetag input Javascript value');
  216.  
  217. if(strlen($anreisemonat=$form->GetJavascriptInputValue($form_object,$this->anreisemonat))==0)
  218. return('it was not possible to retrieve the anreisemonat input Javascript value');
  219.  
  220. if(strlen($anreisejahr=$form->GetJavascriptInputValue($form_object,$this->anreisejahr))==0)
  221. return('it was not possible to retrieve the anreisejahr input Javascript value');
  222.  
  223. if(strlen($abreisetag=$form->GetJavascriptInputValue($form_object,$this->abreisetag))==0)
  224. return('it was not possible to retrieve the abreisetag input Javascript value');
  225.  
  226. if(strlen($abreisemonat=$form->GetJavascriptInputValue($form_object,$this->abreisemonat))==0)
  227. return('it was not possible to retrieve the abreisemonat input Javascript value');
  228.  
  229. if(strlen($abreisejahr=$form->GetJavascriptInputValue($form_object,$this->abreisejahr))==0)
  230. return('it was not possible to retrieve the abreisejahr input Javascript value');
  231.  
  232. if(strlen($minstay=$form->GetJavascriptInputValue($form_object,$this->minstay))==0)
  233. return('it was not possible to retrieve the minstay input Javascript value');
  234.  
  235.  
  236.  
  237. $first=$form->GetInputValue($this->first);
  238. $second=$form->GetInputValue($this->second);
  239.  
  240. $anreisetag=$form->GetInputValue($this->anreisetag);
  241. $anreisemonat=$form->GetInputValue($this->anreisemonat);
  242. $anreisejahr=$form->GetInputValue($this->anreisejahr);
  243.  
  244. $abreisetag=$form->GetInputValue($this->abreisetag);
  245. $abreisemonat=$form->GetInputValue($this->abreisemonat);
  246. $abreisejahr=$form->GetInputValue($this->abreisejahr);
  247.  
  248. $minstay=$form->GetInputValue($this->minstay);
  249.  
  250.  
  251. $datum1 = $anreisetag.".".$anreisemonat.".".$anreisejahr;
  252. $datum2 = $abreisetag.".".$abreisemonat.".".$abreisejahr;
  253.  
  254.  
  255. $stay = seDay($datum1,$datum2,"dmY",".");
  256.  
  257.  
  258. /*
  259. * Return an array with a list of all validation checks to be
  260. * performed.
  261. */
  262. $validations=array();
  263. $validations[]=array(
  264.  
  265. /*
  266. * Each.validation check may be preceed by a list of Javascript
  267. * commands that are executed before each validation is performed.
  268. */
  269. 'Commands'=>array(
  270. 'first='.$first,
  271. 'second='.$second,
  272.  
  273. ),
  274.  
  275. /*
  276. * The condition is a boolean Javascript expression that is true
  277. * when the input is invalid.
  278. */
  279. 'Condition'=>'second.indexOf(first) != -1',
  280.  
  281. /*
  282. * Error message associated to the invalid input
  283. */
  284. 'ErrorMessage'=>$this->first_validation_error_message,
  285.  
  286. /*
  287. * Input that gets the user input focus so the user fixes its value
  288. * to make the input valid
  289. */
  290. 'Focus'=>$this->first
  291. );
  292.  
  293.  
  294. $validations[]=array(
  295. 'Commands'=>array(
  296. 'first='.$first,
  297. 'second='.$second,
  298.  
  299. ),
  300. 'Condition'=>'first.indexOf(second) != -1',
  301. 'ErrorMessage'=>$this->second_validation_error_message,
  302. 'Focus'=>$this->second
  303. );
  304.  
  305.  
  306.  
  307. $validations[]=array(
  308. 'Commands'=>array(
  309. 'minstay='.$minstay,
  310. 'stay='.$stay,
  311. ),
  312. 'Condition'=>'stay < minstay',
  313. 'ErrorMessage'=>$this->minstay_validation_error_message,
  314.  
  315. );
  316.  
  317.  
  318. return('');
  319. }
  320.  
  321. Function AddInputPart(&$form)
  322. {
  323. /*
  324. * Inputs that do not appear in the form must implement an empty
  325. * AddInputPart function.
  326. */
  327. return('');
  328. }
  329. };
  330.  
  331. }
  332.  
  333. ?>
Add Comment
Please, Sign In to add comment