home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / calendar-2010-08-23.tar.gz / calendar-2010-08-23.tar / calendar / functions / draw_functions.php < prev    next >
PHP Script  |  2003-10-12  |  1KB  |  49 lines

  1. <?php
  2. // function returns starttime and endtime and event length for drawing into a grid
  3.  
  4. function drawEventTimes ($start, $end) {
  5.     global $gridLength;
  6.     
  7.     ereg ("([0-9]{2})([0-9]{2})", $start, $time);
  8.     $sta_h = $time[1];
  9.     $sta_min = $time[2];
  10.     $sta_min = sprintf("%02d", floor($sta_min / $gridLength) * $gridLength);
  11.     if ($sta_min == 60) {
  12.         $sta_h = sprintf("%02d", ($sta_h + 1));
  13.         $sta_min = "00";
  14.     }
  15.     
  16.     ereg ("([0-9]{2})([0-9]{2})", $end, $time);
  17.     $end_h = $time[1];
  18.     $end_min = $time[2];
  19.     $end_min = sprintf("%02d", floor($end_min / $gridLength) * $gridLength);
  20.     if ($end_min == 60) {
  21.         $end_h = sprintf("%02d", ($end_h + 1));
  22.         $end_min = "00";
  23.     }
  24.     
  25.     if (($sta_h . $sta_min) == ($end_h . $end_min))  {
  26.         $end_min += $gridLength;
  27.         if ($end_min == 60) {
  28.             $end_h = sprintf("%02d", ($end_h + 1));
  29.             $end_min = "00";
  30.         }
  31.     }
  32.     
  33.     $draw_len = ($end_h * 60 + $end_min) - ($sta_h * 60 + $sta_min);
  34.     
  35.     return array ("draw_start" => ($sta_h . $sta_min), "draw_end" => ($end_h . $end_min), "draw_length" => $draw_len);
  36. }
  37.  
  38. // word wrap function that returns specified number of lines
  39. // when lines is 0, it returns the entire string as wordwrap() does it
  40. function word_wrap($str, $length, $lines=0) {
  41.     if ($lines > 0) {
  42.         $len = $length * $lines;
  43.         if ($len < strlen($str)) {
  44.             $str = substr($str,0,$len).'...';
  45.         }
  46.     }
  47.     return $str;
  48. }
  49. ?>