]> git.mjollnir.org Git - moodle.git/commitdiff
Misc small changes while I was working on assignments
authormartin <martin>
Sun, 4 Aug 2002 16:20:30 +0000 (16:20 +0000)
committermartin <martin>
Sun, 4 Aug 2002 16:20:30 +0000 (16:20 +0000)
files/index.php
lang/en/forum.php
lib/moodlelib.php
mod/journal/lib.php
mod/journal/report.php

index 09ae0c2d29019945c0520a98fd6ce749d95adc63..020b71db1535896645d47548bccd26165f2c121d 100644 (file)
         echo "<td colspan=\"2\">";
     }
 
-    if (! file_exists($CFG->dataroot)) {
-        if (! mkdir($CFG->dataroot, 0750)) {
-            error("You need to create the directory $CFG->dataroot with web server write access");
-        }
+    if (! $basedir = make_upload_directory("$course->id") {
+        error("The site administrator needs to fix the file permissions");
     }
-    $basedir = "$CFG->dataroot/$course->id";
 
-    if (! file_exists($basedir)) {
-        if (! mkdir($basedir, 0750)) {
-            error("Could not create a directory for this course ($basedir)");
-        }
-    }
     $baseweb = $CFG->wwwroot;
 
 //  End of configuration and access control
@@ -398,12 +390,6 @@ function fulldelete($location) {
     return true;
 }
 
-function clean_filename($string) {
-    $string = eregi_replace("\.\.", "", $string);
-    $string = eregi_replace("[^([:alnum:]|\.)]", "_", $string);
-    return    eregi_replace("_+", "_", $string);
-}
-
 
 
 function setfilelist($VARS) {
index 7643e539a6905648fcbddf66af781760e6b0aa6f..09799a168118f92b8d6666cc713344243135c28f 100644 (file)
@@ -8,7 +8,6 @@ $string[modulenameplural] = "Forums";
 $string[addanewdiscussion] = "Add a new discussion topic";
 $string[bynameondate] = "by \$a->name - \$a->date";
 $string[delete] = "Delete";
-$string[description] = "Description";
 $string[discussion] = "Discussion";
 $string[discussions] = "Discussions";
 $string[discussionsstartedby] = "Discussions started by \$a";
index 92477c8b3e78f3ab63b49f0d46a47ecb7e53b5de..e67d3a34eefd0614992c769aa47fe31a0d2bcbe9 100644 (file)
@@ -190,6 +190,29 @@ function print_editing_switch($courseid) {
     }
 }
 
+function update_course_icon($courseid) {
+    global $CFG, $USER;
+
+    if (isteacher($courseid)) {
+        if ($USER->editing) {
+            return "<A TITLE=\"Turn editing OFF\" HREF=\"$CFG->wwwroot/course/view.php?id=$courseid&edit=off\"
+                    TARGET=_top><IMG SRC=\"$CFG->wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0></A>";
+        } else {
+            return "<A TITLE=\"Turn editing ON\" HREF=\"$CFG->wwwroot/course/view.php?id=$courseid&edit=on\"
+                    TARGET=_top><IMG SRC=\"$CFG->wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0></A>";
+        }
+    }
+}
+
+function update_module_icon($moduleid, $courseid) {
+    global $CFG;
+
+    if (isteacher($courseid)) {
+        return "<A TITLE=\"Edit this activity\" HREF=\"$CFG->wwwroot/course/mod.php?update=$moduleid&return=true\" TARGET=_top><IMG SRC=\"$CFG->wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0></A>";
+    }
+}
+
+
 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
@@ -237,29 +260,35 @@ function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0)
    return mktime((int)$hour,(int)$minute,(int)$second,(int)$month,(int)$day,(int)$year);
 }
 
-function update_course_icon($courseid) {
-    global $CFG, $USER;
+function format_time($totalsecs) {
+// Given an amount of time in seconds, prints it 
+// nicely as months, days, hours etc as needed
 
-    if (isteacher($courseid)) {
-        if ($USER->editing) {
-            return "<A TITLE=\"Turn editing OFF\" HREF=\"$CFG->wwwroot/course/view.php?id=$courseid&edit=off\"
-                    TARGET=_top><IMG SRC=\"$CFG->wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0></A>";
-        } else {
-            return "<A TITLE=\"Turn editing ON\" HREF=\"$CFG->wwwroot/course/view.php?id=$courseid&edit=on\"
-                    TARGET=_top><IMG SRC=\"$CFG->wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0></A>";
-        }
-    }
-}
+    $totalsecs = abs($totalsecs);
 
-function update_module_icon($moduleid, $courseid) {
-    global $CFG;
+    $days  = floor($totalsecs/86400);
+    $remainder = $totalsecs - ($days*86400);
+    $hours = floor($remainder/3600);
+    $remainder = $remainder - ($hours*3600);
+    $mins  = floor($remainder/60);
+    $secs = $remainder - ($mins*60);
 
-    if (isteacher($courseid)) {
-        return "<A TITLE=\"Edit this activity\" HREF=\"$CFG->wwwroot/course/mod.php?update=$moduleid&return=true\" TARGET=_top><IMG 
-                SRC=\"$CFG->wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0></A>";
-    }
-}
+    if ($secs  != 1) $ss = "s";
+    if ($mins  != 1) $ms = "s";
+    if ($hours != 1) $hs = "s";
+    if ($days  != 1) $ds = "s";
 
+    if ($days)  $odays  = "$days day$ds";
+    if ($hours) $ohours = "$hours hr$hs";
+    if ($mins)  $omins  = "$mins min$ms";
+    if ($secs)  $osecs  = "$secs sec$ss";
+
+    if ($days)  return "$odays $ohours";
+    if ($hours) return "$ohours $omins";
+    if ($mins)  return "$omins $osecs";
+    if ($secs)  return "$osecs";
+    return get_string("now");
+}
 
 function userdate($date, $format="", $timezone=99) {
 // Returns a formatted string that represents a date in user time
@@ -280,7 +309,9 @@ function userdate($date, $format="", $timezone=99) {
 }
 
 function usergetdate($date, $timezone=99) {
-// Returns an array that represents a date in user time
+// Given a $date timestamp in GMT, returns an array 
+// that represents the date in user time
+
     global $USER;
 
     if ($timezone == 99) {
@@ -1143,7 +1174,7 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml="", $a
     $mail->FromName = "$from->firstname $from->lastname";
     $mail->Subject  =  stripslashes($subject);
 
-    $mail->AddAddress("$user->email","$user->firstname $user->lastname"); 
+    $mail->AddAddress("$user->email", "$user->firstname $user->lastname"); 
 
     $mail->WordWrap = 70;                               // set word wrap
 
@@ -1181,6 +1212,37 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml="", $a
 
 /// FILE HANDLING  /////////////////////////////////////////////
 
+function make_upload_directory($directory) {
+// $directory = a string of directory names under $CFG->dataroot
+// eg  stuff/assignment/1
+// Returns full directory if successful, false if not
+
+    global $CFG;
+
+    $currdir = $CFG->dataroot;
+    if (!file_exists($currdir)) {
+        if (! mkdir($currdir, 0750)) {
+            notify("ERROR: You need to create the directory $currdir with web server write access");
+            return false;
+        }
+    }
+
+    $dirarray = explode("/", $directory);
+
+    foreach ($dirarray as $dir) {
+        $currdir = "$currdir/$dir";
+        if (! file_exists($currdir)) {
+            if (! mkdir($currdir, 0750)) {
+                notify("ERROR: Could not find or create a directory ($currdir)");
+                return false;
+            }
+        }
+    }
+
+    return $currdir;
+}
+
+
 function get_directory_list( $rootdir ) {
 // Returns an array with all the filenames in 
 // all subdirectories, relative to the given rootdir.
@@ -1206,6 +1268,13 @@ function get_directory_list( $rootdir ) {
     return $dirs;
 }
 
+function clean_filename($string) {
+    $string = eregi_replace("\.\.", "", $string);
+    $string = eregi_replace("[^([:alnum:]|\.)]", "_", $string);
+    return    eregi_replace("_+", "_", $string);
+}
+
+
 /// STRING TRANSLATION  ////////////////////////////////////////
 
 function print_string($identifier, $module="", $a=NULL) {
@@ -1422,30 +1491,5 @@ function generate_password($maxlen=10) {
 }
 
 
-function format_time($totalsecs) {
-
-    $days  = floor($totalsecs/86400);
-    $remainder = $totalsecs - ($days*86400);
-    $hours = floor($remainder/3600);
-    $remainder = $remainder - ($hours*3600);
-    $mins  = floor($remainder/60);
-    $secs = $remainder - ($mins*60);
-
-    if ($secs  != 1) $ss = "s";
-    if ($mins  != 1) $ms = "s";
-    if ($hours != 1) $hs = "s";
-    if ($days  != 1) $ds = "s";
-
-    if ($days)  $odays  = "$days day$ds";
-    if ($hours) $ohours = "$hours hr$hs";
-    if ($mins)  $omins  = "$mins min$ms";
-    if ($secs)  $osecs  = "$secs sec$ss";
-
-    if ($days)  return "$odays $ohours";
-    if ($hours) return "$ohours $omins";
-    if ($mins)  return "$omins $osecs";
-    if ($secs)  return "$osecs";
-    return "now";
-}
 
 ?>
index cc784ce4eacb8be5967fc537b14c7583bcb7443c..b866262904ddff7b719cc69521c4f74ccf759054 100644 (file)
@@ -150,10 +150,10 @@ function journal_cron () {
     return true;
 }
 
-function journal_get_users_done($course, $journal) {
+function journal_get_users_done($journal) {
     return get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t, journal_entries j
-                            WHERE ((s.course = '$course->id' AND s.user = u.id) OR 
-                                   (t.course = '$course->id' AND t.user = u.id))
+                            WHERE ((s.course = '$journal->course' AND s.user = u.id) OR 
+                                   (t.course = '$journal->course' AND t.user = u.id))
                               AND u.id = j.user AND j.journal = '$journal->id'
                             ORDER BY j.modified DESC");
 }
index 45225229ea3ce01eceb0963451fb2c8b57516eae..ebd4e176b4fd83aca1713eb1af5b114570e366c5 100644 (file)
@@ -91,7 +91,7 @@
     } else {
         echo "<FORM ACTION=report.php METHOD=post>\n";
 
-        if ($usersdone = journal_get_users_done($course, $journal)) {
+        if ($usersdone = journal_get_users_done($journal)) {
             foreach ($usersdone as $user) {
                 $entry = $entrybyuser[$user->id];
                 journal_print_user_entry($course, $user, $entry, $teachers, $RATING);