]> git.mjollnir.org Git - moodle.git/commitdiff
New functions for printing date selector forms and reconstructing dates
authormartin <martin>
Mon, 29 Jul 2002 06:21:37 +0000 (06:21 +0000)
committermartin <martin>
Mon, 29 Jul 2002 06:21:37 +0000 (06:21 +0000)
afterwards.  Also a new function for counting words in a text

lib/moodlelib.php

index 4fddc405f5dcece5729218b33bd788b2572726cb..2c7d966c9a915ddd5b1a7b37be1222644d5b6ec3 100644 (file)
@@ -177,6 +177,53 @@ function print_editing_switch($courseid) {
     }
 }
 
+function print_date_selector($day, $month, $year, $currenttime=0) {
+// Currenttime is a default timestamp in GMT
+// Prints form items with the names $day, $month and $year
+
+    if (!$currenttime) {
+        $currenttime = time();
+    }
+    $currentdate = usergetdate($currenttime);
+
+    for ($i=1; $i<=31; $i++) {
+        $days[$i] = "$i";
+    }
+    for ($i=1; $i<=12; $i++) {
+        $months[$i] = date("F", mktime(0,0,0,$i,1,2000));
+    }
+    for ($i=2000; $i<=2010; $i++) {
+        $years[$i] = $i;
+    }
+    choose_from_menu($days,   $day,   $currentdate[mday], "");
+    choose_from_menu($months, $month, $currentdate[mon],  "");
+    choose_from_menu($years,  $year,  $currentdate[year], "");
+}
+
+function print_time_selector($hour, $minute, $currenttime=0) {
+// Currenttime is a default timestamp in GMT
+// Prints form items with the names $hour and $minute
+
+    if (!$currenttime) {
+        $currenttime = time();
+    }
+    $currentdate = usergetdate($currenttime);
+    for ($i=0; $i<=23; $i++) {
+        $hours[$i] = sprintf("%02d",$i);
+    }
+    for ($i=0; $i<=59; $i++) {
+        $minutes[$i] = sprintf("%02d",$i);
+    }
+    choose_from_menu($hours,   $hour,   $currentdate[hours],   "");
+    choose_from_menu($minutes, $minute, $currentdate[minutes], "");
+}
+
+function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0) {
+// Given date parts in user time, produce a GMT timestamp
+
+   return mktime((int)$hour,(int)$minute,(int)$second,(int)$month,(int)$day,(int)$year);
+}
+
 function update_course_icon($courseid) {
     global $CFG, $USER;
 
@@ -1256,6 +1303,11 @@ function endecrypt ($pwd, $data, $case) {
 
 /// MISCELLANEOUS ////////////////////////////////////////////////////////////////////
 
+function count_words($string) {
+    $string = strip_tags($string);
+    return count(preg_split("/\w\b/", $string)) - 1;
+}
+
 function getweek ($startdate, $thedate) {
 // Given dates in seconds, how many weeks is the date from startdate
 // The first week is 1, the second 2 etc ...