From 6b1746806cbe8068fe432ec372d0b02f9f0b2486 Mon Sep 17 00:00:00 2001 From: martin Date: Sun, 4 Aug 2002 16:20:30 +0000 Subject: [PATCH] Misc small changes while I was working on assignments --- files/index.php | 18 +----- lang/en/forum.php | 1 - lib/moodlelib.php | 136 +++++++++++++++++++++++++++-------------- mod/journal/lib.php | 6 +- mod/journal/report.php | 2 +- 5 files changed, 96 insertions(+), 67 deletions(-) diff --git a/files/index.php b/files/index.php index 09ae0c2d29..020b71db15 100644 --- a/files/index.php +++ b/files/index.php @@ -37,18 +37,10 @@ echo ""; } - 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) { diff --git a/lang/en/forum.php b/lang/en/forum.php index 7643e539a6..09799a1681 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -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"; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 92477c8b3e..e67d3a34ee 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -190,6 +190,29 @@ function print_editing_switch($courseid) { } } +function update_course_icon($courseid) { + global $CFG, $USER; + + if (isteacher($courseid)) { + if ($USER->editing) { + return "wwwroot/course/view.php?id=$courseid&edit=off\" + TARGET=_top>wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0>"; + } else { + return "wwwroot/course/view.php?id=$courseid&edit=on\" + TARGET=_top>wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0>"; + } + } +} + +function update_module_icon($moduleid, $courseid) { + global $CFG; + + if (isteacher($courseid)) { + return "wwwroot/course/mod.php?update=$moduleid&return=true\" TARGET=_top>wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0>"; + } +} + + 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 "wwwroot/course/view.php?id=$courseid&edit=off\" - TARGET=_top>wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0>"; - } else { - return "wwwroot/course/view.php?id=$courseid&edit=on\" - TARGET=_top>wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0>"; - } - } -} + $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 "wwwroot/course/mod.php?update=$moduleid&return=true\" TARGET=_top>wwwroot/pix/i/edit.gif\" ALIGN=right BORDER=0>"; - } -} + 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"; -} ?> diff --git a/mod/journal/lib.php b/mod/journal/lib.php index cc784ce4ea..b866262904 100644 --- a/mod/journal/lib.php +++ b/mod/journal/lib.php @@ -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"); } diff --git a/mod/journal/report.php b/mod/journal/report.php index 45225229ea..ebd4e176b4 100644 --- a/mod/journal/report.php +++ b/mod/journal/report.php @@ -91,7 +91,7 @@ } else { echo "
\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); -- 2.39.5