[ PHPXref.com ] [ Generated: Sun Jul 20 19:57:02 2008 ] [ PHP Timeclock 1.02 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> functions.php (source)

   1  <?php
   2  
   3  function secsToHours($secs, $round_time) {
   4  
   5  /* The logic for this function was written by Adam Woodbeck, who initially wrote it to round to the
   6     nearest 15 minutes. It has been expanded to round to the nearest 5, 10, 20, and 30 minutes, as well
   7     as giving the option to not round at all. */
   8  
   9  /* This function will convert seconds to hours in decimal form */
  10  
  11      $hours = $secs / 3600.0;
  12      $mins = ($secs % 3600.0) / 60.0;
  13      $hours = floor($hours);
  14  
  15  /* Add the minutes back on as a percentage of an hour (e.g. 8.25 hours == 8 hours, 15 minutes) */
  16  
  17      if ($round_time == '1') {
  18        if ($mins >= 57.5) $hours += 1.0;
  19        elseif ($mins >= 52.5) $hours += 0.92;
  20        elseif ($mins >= 47.5) $hours += 0.83;
  21        elseif ($mins >= 42.5) $hours += 0.75;
  22        elseif ($mins >= 37.5) $hours += 0.67;
  23        elseif ($mins >= 32.5) $hours += 0.58;
  24        elseif ($mins >= 27.5) $hours += 0.50;
  25        elseif ($mins >= 22.5) $hours += 0.42;
  26        elseif ($mins >= 17.5) $hours += 0.33;
  27        elseif ($mins >= 12.5) $hours += 0.25;
  28        elseif ($mins >= 7.5) $hours += 0.17;
  29        elseif ($mins >= 2.5) $hours += 0.08;
  30      }
  31      elseif ($round_time == '2') {
  32        if ($mins >= 55.0) $hours += 1.0;
  33        elseif ($mins >= 45.0) $hours += 0.83;
  34        elseif ($mins >= 35.0) $hours += 0.67;
  35        elseif ($mins >= 25.0) $hours += 0.50;
  36        elseif ($mins >= 15.0) $hours += 0.33;
  37        elseif ($mins >= 5.0) $hours += 0.17;
  38      }
  39      elseif ($round_time == '3') {
  40        if ($mins >= 52.5) $hours += 1.0;
  41        elseif ($mins >= 37.5) $hours += 0.75;
  42        elseif ($mins >= 22.5) $hours += 0.5;
  43        elseif ($mins >= 7.5) $hours += 0.25;
  44      }
  45      elseif ($round_time == '4') {
  46        if ($mins >= 50.0) $hours += 1.0;
  47        elseif ($mins >= 30.0) $hours += 0.67;
  48        elseif ($mins >= 10.0) $hours += 0.33;
  49      }
  50      elseif ($round_time == '5') {
  51        if ($mins >= 45.0) $hours += 1.0;
  52        elseif ($mins >= 15.0) $hours += 0.5;
  53      }
  54      elseif (empty($round_time)) {
  55        $hours += $mins / 60.0;
  56        $hours = round($hours, 2);
  57      }
  58      return number_format($hours, 2);
  59  }
  60  
  61  function disabled_acct($get_user) {
  62  
  63    $query = "select empfullname, disabled from employees where empfullname = '".addslashes($get_user)."'";
  64    $result = mysql_query($query);
  65  
  66    while ($row=mysql_fetch_array($result)) {
  67  
  68      if ("".$row["disabled"]."" == 1) {
  69        echo "<table width=100% border=0 cellpadding=7 cellspacing=1>\n";
  70       echo "  <tr class=right_main_text><td height=10 align=center valign=top scope=row class=title_underline>The account for $get_user is
  71                  disabled</td></tr>\n";
  72        echo "  <tr class=right_main_text>\n";
  73        echo "    <td align=center valign=top scope=row>\n";
  74        echo "      <table width=300 border=0 cellpadding=5 cellspacing=0>\n";
  75        echo "        <tr class=right_main_text><td align=center>Either re-enable the account or go back to the <a class=admin_headings
  76                        href='timeadmin.php'>\"Add/Edit/Delete Time\"</a> page and choose an account that is not disabled.</td></tr>\n";
  77        echo "      </table><br /></td></tr></table>\n"; exit;
  78      }
  79    }
  80  }
  81  
  82  function get_ipaddress() {
  83  
  84      if (empty($REMOTE_ADDR)) {
  85          if (!empty($_SERVER) && isset($_SERVER['REMOTE_ADDR'])) {
  86              $REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
  87          }
  88          else if (!empty($_ENV) && isset($_ENV['REMOTE_ADDR'])) {
  89              $REMOTE_ADDR = $_ENV['REMOTE_ADDR'];
  90          }
  91          else if (@getenv('REMOTE_ADDR')) {
  92              $REMOTE_ADDR = getenv('REMOTE_ADDR');
  93          }
  94      }
  95      if (empty($HTTP_X_FORWARDED_FOR)) {
  96          if (!empty($_SERVER) && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  97              $HTTP_X_FORWARDED_FOR = $_SERVER['HTTP_X_FORWARDED_FOR'];
  98          }
  99          else if (!empty($_ENV) && isset($_ENV['HTTP_X_FORWARDED_FOR'])) {
 100              $HTTP_X_FORWARDED_FOR = $_ENV['HTTP_X_FORWARDED_FOR'];
 101          }
 102          else if (@getenv('HTTP_X_FORWARDED_FOR')) {
 103              $HTTP_X_FORWARDED_FOR = getenv('HTTP_X_FORWARDED_FOR');
 104          }
 105      }
 106      if (empty($HTTP_X_FORWARDED)) {
 107          if (!empty($_SERVER) && isset($_SERVER['HTTP_X_FORWARDED'])) {
 108              $HTTP_X_FORWARDED = $_SERVER['HTTP_X_FORWARDED'];
 109          }
 110          else if (!empty($_ENV) && isset($_ENV['HTTP_X_FORWARDED'])) {
 111              $HTTP_X_FORWARDED = $_ENV['HTTP_X_FORWARDED'];
 112          }
 113          else if (@getenv('HTTP_X_FORWARDED')) {
 114              $HTTP_X_FORWARDED = getenv('HTTP_X_FORWARDED');
 115          }
 116      }
 117      if (empty($HTTP_FORWARDED_FOR)) {
 118          if (!empty($_SERVER) && isset($_SERVER['HTTP_FORWARDED_FOR'])) {
 119              $HTTP_FORWARDED_FOR = $_SERVER['HTTP_FORWARDED_FOR'];
 120          }
 121          else if (!empty($_ENV) && isset($_ENV['HTTP_FORWARDED_FOR'])) {
 122              $HTTP_FORWARDED_FOR = $_ENV['HTTP_FORWARDED_FOR'];
 123          }
 124          else if (@getenv('HTTP_FORWARDED_FOR')) {
 125              $HTTP_FORWARDED_FOR = getenv('HTTP_FORWARDED_FOR');
 126          }
 127      }
 128      if (empty($HTTP_FORWARDED)) {
 129          if (!empty($_SERVER) && isset($_SERVER['HTTP_FORWARDED'])) {
 130              $HTTP_FORWARDED = $_SERVER['HTTP_FORWARDED'];
 131          }
 132          else if (!empty($_ENV) && isset($_ENV['HTTP_FORWARDED'])) {
 133              $HTTP_FORWARDED = $_ENV['HTTP_FORWARDED'];
 134          }
 135          else if (@getenv('HTTP_FORWARDED')) {
 136              $HTTP_FORWARDED = getenv('HTTP_FORWARDED');
 137          }
 138      }
 139      if (empty($HTTP_VIA)) {
 140          if (!empty($_SERVER) && isset($_SERVER['HTTP_VIA'])) {
 141              $HTTP_VIA = $_SERVER['HTTP_VIA'];
 142          }
 143          else if (!empty($_ENV) && isset($_ENV['HTTP_VIA'])) {
 144              $HTTP_VIA = $_ENV['HTTP_VIA'];
 145          }
 146          else if (@getenv('HTTP_VIA')) {
 147              $HTTP_VIA = getenv('HTTP_VIA');
 148          }
 149      }
 150      if (empty($HTTP_X_COMING_FROM)) {
 151          if (!empty($_SERVER) && isset($_SERVER['HTTP_X_COMING_FROM'])) {
 152              $HTTP_X_COMING_FROM = $_SERVER['HTTP_X_COMING_FROM'];
 153          }
 154          else if (!empty($_ENV) && isset($_ENV['HTTP_X_COMING_FROM'])) {
 155              $HTTP_X_COMING_FROM = $_ENV['HTTP_X_COMING_FROM'];
 156          }
 157          else if (@getenv('HTTP_X_COMING_FROM')) {
 158              $HTTP_X_COMING_FROM = getenv('HTTP_X_COMING_FROM');
 159          }
 160      }
 161      if (empty($HTTP_COMING_FROM)) {
 162          if (!empty($_SERVER) && isset($_SERVER['HTTP_COMING_FROM'])) {
 163              $HTTP_COMING_FROM = $_SERVER['HTTP_COMING_FROM'];
 164          }
 165          else if (!empty($_ENV) && isset($_ENV['HTTP_COMING_FROM'])) {
 166              $HTTP_COMING_FROM = $_ENV['HTTP_COMING_FROM'];
 167          }
 168          else if (@getenv('HTTP_COMING_FROM')) {
 169              $HTTP_COMING_FROM = getenv('HTTP_COMING_FROM');
 170          }
 171      }
 172  
 173      // Gets the default ip sent by the user //
 174  
 175      if (!empty($REMOTE_ADDR)) {
 176          $direct_ip = $REMOTE_ADDR;
 177      }
 178  
 179      // Gets the proxy ip sent by the user //
 180  
 181      $proxy_ip     = '';
 182      if (!empty($HTTP_X_FORWARDED_FOR)) {
 183          $proxy_ip = $HTTP_X_FORWARDED_FOR;
 184      } else if (!empty($HTTP_X_FORWARDED)) {
 185          $proxy_ip = $HTTP_X_FORWARDED;
 186      } else if (!empty($HTTP_FORWARDED_FOR)) {
 187          $proxy_ip = $HTTP_FORWARDED_FOR;
 188      } else if (!empty($HTTP_FORWARDED)) {
 189          $proxy_ip = $HTTP_FORWARDED;
 190      } else if (!empty($HTTP_VIA)) {
 191          $proxy_ip = $HTTP_VIA;
 192      } else if (!empty($HTTP_X_COMING_FROM)) {
 193          $proxy_ip = $HTTP_X_COMING_FROM;
 194      } else if (!empty($HTTP_COMING_FROM)) {
 195          $proxy_ip = $HTTP_COMING_FROM;
 196      }
 197  
 198      // Returns the true IP if it has been found, else FALSE //
 199  
 200      if (empty($proxy_ip)) {
 201          // True IP without proxy
 202          return $direct_ip;
 203      } else {
 204          $is_ip = preg_match('|^([0-9]{1,3}\.){3,3}[0-9]{1,3}|', $proxy_ip, $regs);
 205          if ($is_ip && (count($regs) > 0)) {
 206              // True IP behind a proxy
 207              return $regs[0];
 208          } else {
 209              // Can't define IP: there is a proxy but we don't have
 210              // information about the true IP
 211              return FALSE;
 212          }
 213      }
 214  }
 215  
 216  function ip_range($network, $ip) {
 217  
 218  /**
 219   * Based on IP Pattern Matcher
 220   * Originally by J.Adams <jna@retina.net>
 221   * Found on <http://www.php.net/manual/en/function.ip2long.php>
 222   * Modified by Robbat2 <robbat2@users.sourceforge.net>
 223   *
 224   * Matches:
 225   * xxx.xxx.xxx.xxx        (exact)
 226   * xxx.xxx.xxx.[yyy-zzz]  (range)
 227   * xxx.xxx.xxx.xxx/nn     (CIDR)
 228   *
 229   * Does not match:
 230   * xxx.xxx.xxx.xx[yyy-zzz]  (range, partial octets not supported)
 231   *
 232   * @param   string   string of IP range to match
 233   * @param   string   string of IP to test against range
 234   *
 235   * @return  boolean    always true
 236   *
 237   * @access  public
 238   */
 239  
 240     $result = TRUE;
 241  
 242     if (preg_match('|([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/([0-9]+)|', $network, $regs)) {
 243         // performs a mask match
 244         $ipl    = ip2long($ip);
 245         $rangel = ip2long($regs[1] . '.' . $regs[2] . '.' . $regs[3] . '.' . $regs[4]);
 246  
 247         $maskl  = 0;
 248  
 249         for ($i = 0; $i < 31; $i++) {
 250             if ($i < $regs[5] - 1) {
 251                 $maskl = $maskl + pow(2, (30 - $i));
 252             }
 253         }
 254  
 255         if (($maskl & $rangel) == ($maskl & $ipl)) {
 256             return TRUE;
 257         } else {
 258             return FALSE;
 259         }
 260     } else {
 261         // range based
 262         $maskocts = explode('.', $network);
 263         $ipocts   = explode('.', $ip);
 264  
 265         // perform a range match
 266         for ($i = 0; $i < 4; $i++) {
 267              if (preg_match('|\[([0-9]+)\-([0-9]+)\]|', $maskocts[$i], $regs)) {
 268                  if (($ipocts[$i] > $regs[2])
 269                      || ($ipocts[$i] < $regs[1])) {
 270                      $result = FALSE;
 271                  } // end if
 272              } else {
 273                  if ($maskocts[$i] <> $ipocts[$i]) {
 274                      $result = FALSE;
 275                  }
 276              }
 277         }
 278     }
 279     return $result;
 280  }
 281  
 282  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]