Source for file class.CHECK.php

Documentation is available at class.CHECK.php

  1. <?php
  2.  
  3.  
  4. /**
  5.  * Beinhaltet Funktionen mit denen Übergabeparameter auf Vollständigkeit und
  6.  * überprüft werden
  7.  *
  8.  * @author Kay Koch, <kay.koch@gmx.de>
  9.  * @package src
  10.  * @subpackage tools
  11.  */
  12.  
  13. if (version_compare(PHP_VERSION'5')) {
  14.     die('This file was generated for PHP 5');
  15. }
  16.  
  17. /* user defined includes */
  18. // section -64--88-122--2--55b78af2:103c6aa601f:-7fe1-includes begin
  19. // section -64--88-122--2--55b78af2:103c6aa601f:-7fe1-includes end
  20.  
  21. /* user defined constants */
  22. // section -64--88-122--2--55b78af2:103c6aa601f:-7fe1-constants begin
  23. // section -64--88-122--2--55b78af2:103c6aa601f:-7fe1-constants end
  24.  
  25. /**
  26.  * Beinhaltet Funktionen mit denen Übergabeparameter auf Vollständigkeit und
  27.  * überprüft werden
  28.  *
  29.  * @access public
  30.  * @author Kay Koch, <kay.koch@gmx.de>
  31.  * @package src
  32.  * @subpackage tools
  33.  */
  34. {
  35.     // --- ATTRIBUTES ---
  36.  
  37.     // --- OPERATIONS ---
  38.  
  39.     
  40.     /**
  41.      * überprüft die Korrektheit einer ID
  42.      *
  43.      * @access public
  44.      * @author Kay Koch, <kay.koch@gmx.de>
  45.      * @param void 
  46.      * @param boolean 
  47.      * @return boolean 
  48.      */
  49.     public static function checkID($id$exit 0)
  50.     {
  51.         $returnValue = (bool) false;
  52.  
  53.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fdf begin
  54.         try {
  55.             if (!isset($idOR empty($id))
  56.                 throw new Exception ("Übergabeparameter '???_id' fehlt");;
  57.             if (!eregi("^([0-9]+)$"$id))
  58.                 throw new Exception ("Übergabeparameter '???_id' ist ungültig [" $id "]");
  59.             $returnValue true;
  60.         }
  61.         catch (Exception $e{
  62.             if ($exit)
  63.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  64.         }
  65.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fdf end
  66.  
  67.         return (bool) $returnValue;
  68.     }
  69.  
  70.     /**
  71.      * überprüft die Korrektheit eines Datums
  72.      *
  73.      * @access public
  74.      * @author Kay Koch, <kay.koch@gmx.de>
  75.      * @param date 
  76.      * @param boolean 
  77.      * @return boolean 
  78.      */
  79.     public static function checkDatum($datum$exit 0)
  80.     {
  81.         $returnValue = (bool) false;
  82.  
  83.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fdc begin
  84.         try {
  85.             if (!isset($datumOR empty($datum))
  86.                 throw new Exception ("Übergabeparameter 'datum' fehlt");
  87.             if (!eregi("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})$",$datum))
  88.                 throw new Exception ("Übergabeparameter 'datum' hat ein falsches Format [" $datum "]");
  89.             list($y$m$dsplit("-"$datum);
  90.             if (!@checkdate($m$d$y))
  91.                 throw new Exception ("Übergabeparameter 'datum' ist kein Datum [" $datum "]");
  92.             $returnValue true;
  93.         }
  94.         catch (Exception $e{
  95.             if ($exit)
  96.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  97.         }
  98.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fdc end
  99.  
  100.         return (bool) $returnValue;
  101.     }
  102.  
  103.     /**
  104.      * überprüft die Korrektheit einer Zeitangabe
  105.      *
  106.      * @access public
  107.      * @author Kay Koch, <kay.koch@gmx.de>
  108.      * @param time 
  109.      * @param boolean 
  110.      * @return boolean 
  111.      */
  112.     public static function checkHour($hour$exit false)
  113.     {
  114.         $returnValue = (bool) false;
  115.  
  116.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fd9 begin
  117.         try {
  118.             if (!isset($hourOR empty($hour))
  119.                 throw new Exception ("Übergabeparameter 'stunde' fehlt");
  120.             if (!eregi("^[0-2][0-9]:([0|3]{1}[0])(:00)?$"$hour))
  121.                 throw new Exception ("Übergabeparameter 'stunde' hat ein falsches Format  [" $hour "]");
  122.  
  123.             $returnValue true;
  124.         }
  125.         catch (Exception $e{
  126.             if ($exit)
  127.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  128.         }
  129.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fd9 end
  130.  
  131.         return (bool) $returnValue;
  132.     }
  133.  
  134.     /**
  135.      * überprüft die Korrektheit eines Passwortes
  136.      *
  137.      * @access public
  138.      * @author Kay Koch, <kay.koch@gmx.de>
  139.      * @param string 
  140.      * @param boolean 
  141.      * @return boolean 
  142.      */
  143.     public static function checkPWD($pwd$exit 0)
  144.     {
  145.         $returnValue = (bool) false;
  146.  
  147.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fd6 begin
  148.         try {
  149.             if (!isset($pwdOR empty($pwd))
  150.                 throw new Exception ("Übergabeparameter 'pwd' fehlt");
  151.             if (!eregi("^[a-z0-9]{5,}"$pwd))
  152.                 throw new Exception ("Übergabeparameter 'pwd' ist ungültig [" $pwd "]");
  153.             $returnValue true;
  154.         }
  155.         catch (Exception $e{
  156.             if ($exit)
  157.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  158.         }
  159.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fd6 end
  160.  
  161.         return (bool) $returnValue;
  162.     }
  163.  
  164.     /**
  165.      * überprüft die Korrektheit einer Emailadresse
  166.      *
  167.      * @access public
  168.      * @author Kay Koch, <kay.koch@gmx.de>
  169.      * @param string 
  170.      * @param boolean 
  171.      * @return boolean 
  172.      */
  173.     public static function checkMail($mail$exit 0)
  174.     {
  175.         $returnValue = (bool) false;
  176.  
  177.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fd3 begin
  178.         try {
  179.             if (!isset($mailOR empty($mail))
  180.                 throw new Exception ("Übergabeparameter 'mail' fehlt");
  181.             if (!eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9|ü|ä|ö]+([-_\.]?[a-z0-9|ü|ä|ö])+\.[a-z]{2,4}"$mail))
  182.                 throw new Exception ("Übergabeparameter 'mail' ist ungültig [" $mail "]");
  183.             $returnValue true;
  184.         }
  185.         catch (Exception $e{
  186.             if ($exit)
  187.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  188.         }
  189.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fd3 end
  190.  
  191.         return (bool) $returnValue;
  192.     }
  193.  
  194.     /**
  195.      * überprüft die Korrektheit einer Bestätigung
  196.      *
  197.      * @access public
  198.      * @author Kay Koch, <kay.koch@gmx.de>
  199.      * @param string 
  200.      * @param boolean 
  201.      * @return boolean 
  202.      */
  203.     public static function checkConfirm($confirm$exit 0)
  204.     {
  205.         $returnValue = (bool) false;
  206.  
  207.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fd0 begin
  208.         try {
  209.             if (!isset($confirmOR empty($confirm))
  210.                 throw new Exception ("Übergabeparameter 'confirm' fehlt");
  211.             if (!eregi("^(t|c|d)"$confirm))
  212.                 throw new Exception ("Übergabeparameter 'confirm' ist ungültig [" $confirm "]");
  213.             $returnValue true;
  214.         }
  215.         catch (Exception $e{
  216.             if ($exit)
  217.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  218.         }
  219.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fd0 end
  220.  
  221.         return (bool) $returnValue;
  222.     }
  223.  
  224.     /**
  225.      * Überprüft die Korrektheit eines Namens
  226.      *
  227.      * @access public
  228.      * @author Kay Koch, <kay.koch@gmx.de>
  229.      * @param string 
  230.      * @param boolean 
  231.      * @return boolean 
  232.      */
  233.     public static function checkName($name$exit 0)
  234.     {
  235.         $returnValue = (bool) false;
  236.  
  237.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fc4 begin
  238.         try {
  239.             if (!isset($nameOR empty($name))
  240.                 throw new Exception ("Übergabeparameter 'Name' fehlt");
  241.             if (!eregi("^[.a-zA-ZäüöÄÜÖ0-9[:space:]-]+$"$name))
  242.                 throw new Exception ("Übergabeparameter 'Name' ist ungültig [" $name "]");
  243.             $returnValue true;
  244.         }
  245.         catch (Exception $e{
  246.             if ($exit)
  247.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  248.         }
  249.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fc4 end
  250.  
  251.         return (bool) $returnValue;
  252.     }
  253.  
  254.     /**
  255.      * Überprüft die Korrektheit einer Zahl
  256.      *
  257.      * @access public
  258.      * @author Kay Koch, <kay.koch@gmx.de>
  259.      * @param int 
  260.      * @param boolean 
  261.      * @return boolean 
  262.      */
  263.     public static function checkAnzahl($anzahl$exit 0)
  264.     {
  265.         $returnValue = (bool) false;
  266.  
  267.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fc0 begin
  268.         try {
  269.             if (!isset($anzahl))
  270.                 throw new Exception ("Übergabeparameter 'anzahl' fehlt");
  271.             if (!eregi("^[0-9]+$"$anzahl))
  272.                 throw new Exception ("Übergabeparameter 'anzahl' ist ungültig [" $anzahl "]");
  273.             $returnValue true;
  274.         }
  275.         catch (Exception $e{
  276.             if ($exit)
  277.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  278.         }
  279.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fc0 end
  280.  
  281.         return (bool) $returnValue;
  282.     }
  283.  
  284.     /**
  285.      * überprüft die Korrektheit einer Telefonnummer
  286.      *
  287.      * @access public
  288.      * @author Kay Koch, <kay.koch@gmx.de>
  289.      * @param string 
  290.      * @param boolean 
  291.      * @return boolean 
  292.      */
  293.     public static function checkPhone($phone$exit 0)
  294.     {
  295.         $returnValue = (bool) false;
  296.  
  297.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fbc begin
  298.         try {
  299.             if (!empty($phoneAND !eregi("^[0-9[:space:]()-+]*$"$phone))
  300.                 throw new Exception ("Übergabeparameter 'phone' ist ungültig [" $phone "]");
  301.             $returnValue true;
  302.         }
  303.         catch (Exception $e{
  304.             if ($exit)
  305.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  306.         }
  307.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fbc end
  308.  
  309.         return (bool) $returnValue;
  310.     }
  311.  
  312.     /**
  313.      * überprüft die Korrektheit einer kompletten Vereinsnummer
  314.      *
  315.      * @access public
  316.      * @author Kay Koch, <kay.koch@gmx.de>
  317.      * @param string 
  318.      * @param boolean 
  319.      * @return boolean 
  320.      */
  321.     public static function checkVnum($verein_nr$exit 0)
  322.     {
  323.         $returnValue = (bool) false;
  324.  
  325.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fb8 begin
  326.         try {
  327.             if (!empty($verein_nrAND !eregi("^([0-9]{2})/([0-9]{4})$"$verein_nr))
  328.                 throw new Exception ("übergabeparameter 'verein_nr' ist ungültig [" $verein_nr "]");
  329.             $returnValue true;
  330.         }
  331.         catch (Exception $e{
  332.             if ($exit)
  333.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  334.         }
  335.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fb8 end
  336.  
  337.         return (bool) $returnValue;
  338.     }
  339.  
  340.     /**
  341.      * überprüft ob das übergebene Token in der Session bereits gesetzt wurde
  342.      *
  343.      * In diesem Fall wurde die aufrufende Seite (Formular) bereits aufgerufen.
  344.      *
  345.      * @access public
  346.      * @author Kay Koch, <kay.koch@gmx.de>
  347.      * @param string 
  348.      * @param boolean 
  349.      * @return boolean 
  350.      */
  351.     public static function checkToken($token$exit 0)
  352.     {
  353.         $returnValue = (bool) false;
  354.  
  355.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fb4 begin
  356.         try {
  357.             session_start();
  358.             if (src_tools_TOKEN::tokenIsOK($token))
  359.                 throw new Exception ("Antrag wurde bereits abgeschickt<br><a href='index.php5'>Startseite</a>");
  360.             $returnValue true;
  361.         }
  362.         catch (Exception $e{
  363.             if ($exit)
  364.                 die($e->getMessage());
  365.         }
  366.         // section -64--88-122--2--55b78af2:103c6aa601f:-7fb4 end
  367.  
  368.         return (bool) $returnValue;
  369.     }
  370.  
  371.     /**
  372.      * überprüft die Korrektheit einer Boolschen Zahl
  373.      *
  374.      * @access public
  375.      * @author Kay Koch, <kay.koch@gmx.de>
  376.      * @param int 
  377.      * @param boolean 
  378.      * @return boolean 
  379.      */
  380.     public static function checkBool($bool$exit false)
  381.     {
  382.         $returnValue = (bool) false;
  383.  
  384.         // section -64--88-122--2--62c31de:1048594e50f:-7ff7 begin
  385.         try {
  386.             if (!isset($bool))
  387.                 throw new Exception ("übergabeparameter 'Bool' fehlt");
  388.             if (!eregi("^([0|1])$"$bool))
  389.                 throw new Exception ("übergabeparameter 'bool' ist ungültig");
  390.             $returnValue true;
  391.         }
  392.         catch (Exception $e{
  393.             if ($exit)
  394.                 die($e->getMessage());
  395.         }
  396.         // section -64--88-122--2--62c31de:1048594e50f:-7ff7 end
  397.  
  398.         return (bool) $returnValue;
  399.     }
  400.  
  401.     /**
  402.      * überprüft die Korrektheit eines HTML-Namens
  403.      *
  404.      * @access public
  405.      * @author Kay Koch, <kay.koch@gmx.de>
  406.      * @param string 
  407.      * @param boolean 
  408.      * @return boolean 
  409.      */
  410.     public static function checkHtml($pageTitle$exit false)
  411.     {
  412.         $returnValue = (bool) false;
  413.  
  414.         // section -64--88-122--2--62c31de:1048594e50f:-7ff3 begin
  415.         try {
  416.             if (!empty($pageTitleAND !eregi("^[a-z0-9]+(.html)$"$pageTitle))
  417.                 throw new Exception ("Übergabeparameter 'html-Seite' ist ungültig");
  418.             $returnValue true;
  419.         }
  420.         catch (Exception $e{
  421.             if ($exit)
  422.                 die($e->getMessage());
  423.         }
  424.         // section -64--88-122--2--62c31de:1048594e50f:-7ff3 end
  425.  
  426.         return (bool) $returnValue;
  427.     }
  428.  
  429.     /**
  430.      * überprüft die Korrektheit einer Float Zahl
  431.      *
  432.      * @access public
  433.      * @author Kay Koch, <kay.koch@gmx.de>
  434.      * @param float 
  435.      * @param boolean 
  436.      * @return boolean 
  437.      */
  438.     public static function checkFloat($float$exit false)
  439.     {
  440.         $returnValue = (bool) false;
  441.  
  442.         // section -64--88-122--2--62c31de:1048594e50f:-7fec begin
  443.         try {
  444.             if (!empty($floatAND !eregi("^[0-9]+\.[0-9]+$"$float))
  445.                 throw new Exception ("Übergabeparameter 'html-Seite' ist ungültig");
  446.             $returnValue true;
  447.         }
  448.         catch (Exception $e{
  449.             if ($exit)
  450.                 die($e->getMessage());
  451.         }
  452.         // section -64--88-122--2--62c31de:1048594e50f:-7fec end
  453.  
  454.         return (bool) $returnValue;
  455.     }
  456.  
  457.     /**
  458.      * überprüft die Korrektheit eines Brevetnamens
  459.      *
  460.      * @access public
  461.      * @author Kay Koch, <kay.koch@gmx.de>
  462.      * @param string 
  463.      * @param boolean 
  464.      * @return boolean 
  465.      */
  466.     public static function checkBrevet($brevet$exit false)
  467.     {
  468.         $returnValue = (bool) false;
  469.  
  470.         // section -64--88-122--2--62c31de:1048594e50f:-7fe8 begin
  471.         try {
  472.             if (!isset($brevetOR empty($brevet))
  473.                 throw new Exception ("Übergabeparameter 'Brevet' fehlt");
  474.             if (!eregi("^[a-zA-Z0-9äöüÄÖÜ[:space:]\./*-]+$"$brevet))
  475.                 throw new Exception ("Übergabeparameter 'brevet' ist ungültig [" $brevet "]");
  476.             $returnValue true;
  477.         }
  478.         catch (Exception $e{
  479.             if ($exit)
  480.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  481.         }
  482.         // section -64--88-122--2--62c31de:1048594e50f:-7fe8 end
  483.  
  484.         return (bool) $returnValue;
  485.     }
  486.  
  487.     /**
  488.      * überprüft die Korrektheit einer Vereinsnummer ohne Verbandszahl
  489.      *
  490.      * @access public
  491.      * @author Kay Koch, <kay.koch@gmx.de>
  492.      * @param string 
  493.      * @param boolean 
  494.      * @return boolean 
  495.      */
  496.     public static function checkVnum_small($verein_nr$exit false)
  497.     {
  498.         $returnValue = (bool) false;
  499.  
  500.         // section -64--88-122--2--62c31de:1048594e50f:-7fe4 begin
  501.         try {
  502.             if (!isset($verein_nrOR empty($verein_nr))
  503.                 throw new Exception ("Übergabeparameter '$verein_nrfehlt");
  504.             if (!empty($verein_nrAND !eregi("^[0-9]{4}$"$verein_nr))
  505.                 throw new Exception ("Übergabeparameter 'verein_nr' ist ungültig [" $verein_nr "]");
  506.             $returnValue true;
  507.         }
  508.         catch (Exception $e{
  509.             if ($exit)
  510.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  511.         }
  512.         // section -64--88-122--2--62c31de:1048594e50f:-7fe4 end
  513.  
  514.         return (bool) $returnValue;
  515.     }
  516.  
  517.     /**
  518.      * überprüft die Korrektheit einer Verbandszahl
  519.      *
  520.      * @access public
  521.      * @author Kay Koch, <kay.koch@gmx.de>
  522.      * @param string 
  523.      * @param boolean 
  524.      * @return boolean 
  525.      */
  526.     public static function checkVerband($verband_nr$exit false)
  527.     {
  528.         $returnValue = (bool) false;
  529.  
  530.         // section -64--88-122--2--62c31de:1048594e50f:-7fe0 begin
  531.         try {
  532.             if (!isset($verband_nrOR empty($verband_nr))
  533.                 throw new Exception ("Übergabeparameter 'stunde' fehlt");
  534.             if (!empty($verband_nrAND !eregi("^[0-9]{2}$"$verband_nr))
  535.                 throw new Exception ("Übergabeparameter 'verband_nr' ist ungültig [" $verband_nr "]");
  536.             $returnValue true;
  537.         }
  538.         catch (Exception $e{
  539.             if ($exit)
  540.                 die("FEHLER in index.php5:<br> " $e->getMessage());
  541.         }
  542.         // section -64--88-122--2--62c31de:1048594e50f:-7fe0 end
  543.  
  544.         return (bool) $returnValue;
  545.     }
  546.  
  547. /* end of class src_tools_CHECK */
  548.  
  549. ?>

Documentation generated on Sat, 24 Mar 2007 09:59:03 +0100 by phpDocumentor 1.3.1