完全日本語化プロジェクト
対象プログラム Moodle ver. 1.5 dev (rev. 9/1/2004)
内容 graphlib.php / moodlelib.php / Worksheet.php / Format.php の改変
説明 環境1:Windows 2K + Apache 1.3.31 + PHP 4.3.8 + Moodle 1.5 dev + GD2
(検証者 Takahito Kashiwagi)
環境2:WinXP Home + Apache 2 + PHP 4.3.8 cgi版 + Moodle1.5 dev + GD2
(検証者 KAGO氏)

上記環境において動作検証を行っています。

<主な対応>

  • GD2の日本語表示への対応。
  • メールの文字コードをiso-2202-jpに統一。
  • 日付表示の日本語表示への対応(KAGO氏)。
  • TEXT/EXCELワークシートの日本語表示、ファイル名の日本語表示への対応。
  • LESSON/QUIZのファイル取り込み時日本語変換の対応(AOYAGI氏)。
  • QUIZ採点時に全角/半角の区別を行わない設定を追加(AOYAGI氏)。
  • WIKIモジュールの日本語対応(Yoshida氏)。

<注意と設置方法>

  • FONTはさざなみフォントを使用しています(http://sourceforge.jp/projects/efont/)。
  • 日本語ライブラリはjcode.phpを用いています(http://www.spencernetwork.org/)。
  • それぞれの著作権表記をTEXTで添付していますので、使用する場合は内容を確認してください。
  • langlib134.lzh をダウンロードし、fonts及びlibディレクトリを、../lang/ja/ 配下に設置してください。「langlib.php」 の有無を判定して日本語化パッチが動作しますので、正確なディレクトリ位置に設置しないと正常に稼動しません。
  • GDの日本語表示は..lang/ja/fonts にある「lang_decode.php」を使用します。これは、Moodleが用意していた拡張機能を利用しています。したがって、以前のgraphlib.phpに対する変更は必要なくなりました。
  • 対象ファイルの改変位置を行番号を元に探り、赤で示されたソースをコピーペーストで挿入してください。
  • localeの設定はJapanese_Japan.20932(Windows系)またはja_JP.EUC(UNIX系) です。

<改定内容>
1.0.0 日本語ライブラリ公開
1.0.1 graphlib.phpのjcode.phpの呼び出しが正しく機能していなかったので修正した。
1.1.0 多言語環境を意識し極力日本語特有の名称を無くし、langlib.phpを追加した。
1.1.1 mbstringが使用できる場合、使用するように分岐制にした。
1.1.2 EUC環境に限定しないよう、langlib.php内にて現コードを指定できるようにした。
1.1.3 メール送信者の日本語表記に対応した。メール送信時のコード変換を修正した。
1.1.4 ヘッダの自前MIMEエンコを行うようにした。送信者、受信者、CC、BCCの日本語対応を行った。
1.1.5 レッスン/クイズのファイル取り込み時の日本語対応を行った。その他細かい修正をした。
1.2.0 採点時の全角/半角の区別をなくすオプションを用意した。langlib.phpの大幅改定。
1.2.1 langlib.phpの小改定。setup.phpの修正追加。ソースの見直しと簡略化。
1.2.2 setup.phpへのライブラリ挿入位置の修正。その他小変更。
1.2.3 langlib.phpの更新。処理をlanglib内にまとめ、ソースの変更を極力少なくした。
1.3.0 TEXT/EXCELの日本語表示を改変。ダウンロードユーザの環境に自動的に調整するようにした。
1.3.1 TEXT/EXCELの日本語ファイル名に対応。
1.3.2 GDによる日本語表示において拡張用に用意されていたMoodleの仕様を利用した。
1.3.3 WIKIモジュールの日本語表示暫定対応(モジュールを添付[version 1.4.x 138]のものに入れ替えてください)。
1.3.4 langlib.phpの修正。MAILの文字化け対策に不足がありましたので修正しました。

日付 2004/10/20
バージョン 1.3.4
作者 Takahito Kashiwagi
履歴 2004/9/1 初版作成

moodle\lib\setup.php の 86行〜 101行付近

※以下の変更を、ver. 1.2.1にて行った方は、青い部分を削除してください。

            $CFG[$config->name] = $config->value;
        }
        $CFG = (object)$CFG;
        unset($configs);
        unset($config);
    }


/// Load up Language Library

    $currlang = current_language();
    if (file_exists("$CFG->dirroot/lang/$currlang/lib/langlib.php")) {
        require_once("$CFG->dirroot/lang/$currlang/lib/langlib.php"); // Language Library
    }


/// Set error reporting back to normal
    if (empty($CFG->debug)) {
        $CFG->debug = 7;
    }
    error_reporting($CFG->debug);


/// File permissions on created directories in the $CFG->dataroot

moodle\lib\setup.php の 249行〜 275行付近

※以下が新たな挿入位置です。

    if (!empty($CFG->opentogoogle)) {
        if (empty($_SESSION['USER'])) {
            if (!empty($_SERVER['HTTP_USER_AGENT'])) {
                if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false ) {
                    $USER = guest_user();
                }
                if (strpos($_SERVER['HTTP_USER_AGENT'], 'google.com') !== false ) {
                    $USER = guest_user();
                }
            }
            if (empty($_SESSION['USER']) and !empty($_SERVER['HTTP_REFERER'])) {
                if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false ) {
                    $USER = guest_user();
                }
            }
        }
    }
/// Load up Language Library
    $currlang = current_language();
    if (file_exists("$CFG->dirroot/lang/$currlang/lib/langlib.php")) {
        require_once("$CFG->dirroot/lang/$currlang/lib/langlib.php"); // Language Library
    }
?>

moodle\lib\graphlib.php の 197行〜 212行付近

※以下の変更を以前に行った方は、青い部分を削除してください。

  $this->calculated['boundary_box']['right']  -= $this->parameter['outer_padding'];
  $this->calculated['boundary_box']['bottom'] -= $this->parameter['outer_padding'];

  $this->init_x_axis();
  $this->init_y_axis();
  $this->init_legend();
  $this->init_labels();

  if (function_exists('use_lang_lib') && use_lang_lib()) {
      graph_encoding($this);
  }

  //  take into account tick lengths
  $this->calculated['bottom_inner_padding'] = $this->parameter['inner_padding'];
  if (($this->parameter['x_ticks_colour'] != 'none') && ($this->parameter['tick_length'] < 0))
    $this->calculated['bottom_inner_padding'] -= $this->parameter['tick_length'];
  $this->calculated['boundary_box']['bottom'] -= $this->calculated['bottom_inner_padding'];

  $this->calculated['left_inner_padding'] = $this->parameter['inner_padding'];
  if ($this->parameter['y_axis_text_left']) {

moodle\lib\moodlelib.php の 1549行〜 1564行付近

            $mail->AddStringAttachment("Error in attachment.  User attempted to attach a filename with a unsafe name.", "error.txt", "8bit", "text/plain");
        } else {
            include_once("$CFG->dirroot/files/mimetypes.php");
            $mimetype = mimeinfo("type", $attachname);
            $mail->AddAttachment("$CFG->dataroot/$attachment", "$attachname", "base64", "$mimetype");
        }
    }

    if (function_exists('use_lang_lib') && use_lang_lib()) {
        email_encoding($mail);
    }

    if ($mail->Send()) {
        return true;
    } else {
        mtrace("ERROR: $mail->ErrorInfo");
        add_to_log(SITEID, "library", "mailer", $_SERVER["REQUEST_URI"], "ERROR: $mail->ErrorInfo");
        return false;
    }
}

moodle\lib\moodlelib.php の 2651行〜 2666行付近
 

    } else if (!empty($SESSION->lang) and ($SESSION->lang != $CFG->lang) ) {
        $CFG->locale = get_string('locale');
    } else if (!empty($USER->lang) and ($USER->lang != $CFG->lang) ) {
        $CFG->locale = get_string('locale');
    } else if (empty($CFG->locale)) {
        $CFG->locale = get_string('locale');
        set_config('locale', $CFG->locale);   // cache it to save lookups in future
    }

    $currlang = current_language();
    if ($currlang != 'en') {
        setlocale (LC_ALL, $CFG->locale);
    }

    setlocale (LC_TIME, $CFG->locale);
    setlocale (LC_COLLATE, $CFG->locale);

    if ($CFG->locale != 'tr_TR') {            // To workaround a well-known PHP bug with Turkish
        setlocale (LC_CTYPE, $CFG->locale);
    }
}

moodle\lib\excel\Worksheet.php の 1035行〜 1050行付近

    * @access public
    * @param integer $row    Zero indexed row
    * @param integer $col    Zero indexed column
    * @param string  $str    The string to write
    * @param mixed   $format The XF format for the cell
    */
    function write_string($row, $col, $str, $format = 0)
    {
        if (function_exists('use_lang_lib') && use_lang_lib() && define_usr_agent()) {
           $str = ex_convert_encoding($str, 'shift_jis', 'auto');
        }

        $strlen    = strlen($str);
        $record    = 0x0204;                   // Record identifier
        $length    = 0x0008 + $strlen;         // Bytes to follow
        $xf        = $this->_XF($format);      // The cell format

        $str_error = 0;

        // Check that row and col are valid and store max and min values

moodle\mod\lesson\format.php の 146行〜 161行付近

    function readdata($filename) {
    /// Returns complete file with an array, one item per line

        if (is_readable($filename)) {
            $filearray = file($filename);

            if (function_exists('use_lang_lib') && use_lang_lib()) {
                $lang_code = rtn_lang_code();
                foreach ($filearray as $i => $temp_array) {
                    $filearray[$i] = ex_convert_encoding($temp_array, $lang_code, "auto");
                }
            }


            /// Check for Macintosh OS line returns (ie file on one line), and fix
            if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) {
                return explode("\r", $filearray[0]);
            } else {
                return $filearray;
            }
        }
        return false;


moodle\mod\quiz\format.php の 78行〜 93行付近

    function readdata($filename) {
    /// Returns complete file with an array, one item per line

        if (is_readable($filename)) {
            $filearray = file($filename);

            if (function_exists('use_lang_lib') && use_lang_lib()) {
                $lang_code = rtn_lang_code();
                foreach ($filearray as $i => $temp_array) {
                    $filearray[$i] = ex_convert_encoding($temp_array, $lang_code, "auto");
                }
            }


            /// Check for Macintosh OS line returns (ie file on one line), and fix
            if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) {
                return explode("\r", $filearray[0]);
            } else {
                return $filearray;
            }
        }
        return false;


moodle\mod\quiz\questiontypes\numerical\questiontype.php の 147行〜 162行付近

    function grade_response($question, $nameprefix, $addedanswercondition='') {

        $result->answers = array();
        $units = get_records('quiz_numerical_units',
                             'question', $question->id);
        if (isset($question->response[$nameprefix])) {
            $response = trim(stripslashes($question->response[$nameprefix]));

            if (function_exists('use_lang_lib') && use_lang_lib()) {
               $response = normalize_string($response);
            }

            // Arrays with 'wild cards':
            $search = array(' ',',');
            $replace = array('','.');
            $responsenum = str_replace($search, $replace, $response);
            if (empty($units)) {
                if ('' !== $responsenum && is_numeric($responsenum)) {
                    $responsenum = (float)$responsenum;
                } else {

moodle\mod\quiz\questiontypes\shortanswer\questiontype.php の 159行〜 174行付近

                $answer->answer = trim($answer->answer);  // Just in case

                if (empty($result->answers) || $answer->fraction
                        > $result->answers[$nameprefix]->fraction) {

                    if (!$answer->usecase) { // Don't compare case
                        $response0 = strtolower($response0);
                        $answer0 = strtolower($answer->answer);

                        if (function_exists('use_lang_lib') && use_lang_lib()) {
                            $response0 = normalize_string($response0);
                            $answer0 = normalize_string($answer0);
                        }

                    } else {
                        $answer0 = $answer->answer;
                    }

                    if (strpos(' '.$answer0, '*')) {
                        $answer0 = str_replace('\*','@@@@@@',$answer0);
                        $answer0 = str_replace('*','.*',$answer0);
                        $answer0 = str_replace($search, $replace, $answer0);

moodle\mod\quiz\report\fullstat\report.php の 309行〜 324行付近

    }
    /// If spreadsheet is wanted, produce one
    if ($download == "xls") {
        require_once("$CFG->libdir/excel/Worksheet.php");
        require_once("$CFG->libdir/excel/Workbook.php");
        header("Content-type: application/vnd.ms-excel");
        $downloadfilename = clean_filename("$course->shortname $quiz->name");
        header("Content-Disposition: attachment; filename=$downloadfilename.xls");

        if (function_exists('use_lang_lib') && use_lang_lib()) {
            $set_usr_agent = define_usr_agent();
            if($set_usr_agent) {
                $quiz->name = ex_convert_encoding($quiz->name, 'sjis', 'auto');
                $course->shortname = ex_convert_encoding($course->shortname, 'sjis', 'auto');
            }
            header("Content-Disposition: attachment; filename=$course->shortname ".$quiz->name.".xls");
        }

        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
        header("Pragma: public");
        $workbook = new Workbook("-");
        // Creating the first worksheet
        $myxls = &$workbook->add_worksheet('Responses for each student');

        /// format types

moodle\mod\quiz\report\fullstat\report.php の 566行〜 581行付近

        exit;
    }

        ////////---------------------------
        /// If a text file is wanted, produce one
        if ($download == "txt") {
        /// Print header to force download

        if (function_exists('use_lang_lib') && use_lang_lib()) {
            full_text_out($course, $quiz, $data_tally, $qs_in_order, $question_ids, $qcount, $quests, $match_qs, $analysis, $max_choices, $table_colcount);
        }

        header("Content-Type: application/download\n");
        $downloadfilename = clean_filename("$course->shortname $quiz->name");
        header("Content-Disposition: attachment; filename=\"$downloadfilename.txt\"");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
        header("Pragma: public");

        /// Print names of all the fields

moodle\mod\quiz\report\simplestat\report.php の 81行〜 96行付近

                $answer->answer = trim($answer->answer);  // Just in case

                if ($answer->fraction >= 1.0) {
                    $correct[] = $answer->answer;
                }
                if (!$answer->usecase) {       // Don't compare case
                    $answer->answer = strtolower($answer->answer);
                    $question->answer = strtolower($question->answer);

                    if (function_exists('use_lang_lib') && use_lang_lib()) {
                        $answer->answer = normalize_string($answer->answer);
                        $question->answer = normalize_string($question->answer);
                    }

                }

                $potentialgrade = (float)$answer->fraction * $question->grade;

                if ($potentialgrade >= $grade and (strpos(' '.$answer->answer, '*'))) {
                    $answer->answer = str_replace('\*','@@@@@@',$answer->answer);
                    $answer->answer = str_replace('*','.*',$answer->answer);
                    $answer->answer = str_replace('@@@@@@', '\*',$answer->answer);

moodle\mod\quiz\report\simplestat\report.php の 106行〜 121行付近

                }
            }

            break;

        case NUMERICAL:
            if ($question->answer) {
                $question->answer = trim(stripslashes($question->answer[0]));

                if (function_exists('use_lang_lib') && use_lang_lib()) {
                    $question->answer = normalize_string($question->answer);
                }

            } else {
                $question->answer = "";
            }
            $response[0] = $question->answer;
            $bestshortanswer = 0;
            foreach ($answers as $answer) {  // There might be multiple right answers
                if ($answer->fraction > $bestshortanswer) {
                    $correct[$answer->id] = $answer->answer;

moodle\mod\quiz\report\simplestat\report.php の 529行〜 544行付近

        }

    /// If spreadsheet is wanted, produce one
        if ($download == "xls") {
            require_once("$CFG->libdir/excel/Worksheet.php");
            require_once("$CFG->libdir/excel/Workbook.php");
            header("Content-type: application/vnd.ms-excel");
            header("Content-Disposition: attachment; filename=$course->shortname ".$quiz->name.".xls" );

            if (function_exists('use_lang_lib') && use_lang_lib()) {
                $set_usr_agent = define_usr_agent();
                if($set_usr_agent) {
                    $quiz->name = ex_convert_encoding($quiz->name, 'sjis', 'auto');
                    $course->shortname = ex_convert_encoding($course->shortname, 'sjis', 'auto');
                }
                header("Content-Disposition: attachment; filename=$course->shortname ".$quiz->name.".xls");
            }

            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
            header("Pragma: public");

            $workbook = new Workbook("-");
            // Creating the first worksheet
            $myxls = &$workbook->add_worksheet('Simple Quiz Statistics');

moodle\mod\quiz\report\simplestat\report.php の 586行〜 601行付近

            exit;
        }


    /// If a text file is wanted, produce one
        if ($download == "txt") {
        /// Print header to force download

            if (function_exists('use_lang_lib') && use_lang_lib()) {
                simple_text_out($count, $course, $quiz, $data, $average);
            }

            header("Content-Type: application/download\n");
            header("Content-Disposition: attachment; filename=$course->shortname ".$quiz->name.".txt");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
            header("Pragma: public");


        /// Print names of all the fields



moodle\lang\ja\lib\langlib.php
※これは、「langlib***.lzh」に含まれているlanglib.phpに関する説明です。
<?php
/*  Language Library for Japanese
      by Takahito Kashiwagi (webmaster@supertak.com)
    jcode.php / jcode_wrapper.php
      by TOMO (http://www.spencernetwork.org/)
    SAZANAMI FONT
      by eFont (http://sourceforge.jp/projects/efont/) */
※langlib.phpの再配布、改造は自由に行っていただいてかまいません。
※ただし、langlibに添付しているさざなみフォント及び、jcode.phpには、
※それぞれに著作権がありますのでそれぞれの利用規約に従ってください。
// Current Language Code
// define current language type such as 'iso-2022-jp', 'sjis', 'euc-jp', or 'utf-8'.
$lang_code = 'euc-jp';
※設置環境に合わせて変更してください。
※基本的にEUC-JP環境であることを前提に改定を行っており、
※他の言語使用環境でのテストは行っていません。
// Switch to use Language Library
// 1: ON / 0: OFF
$uselibrary = '1';
※このライブラリを使用するかどうかのスイッチです。
※ライブラリの動作を止めたいときにご使用ください。
※1でON、0でOFFになります。
// Switch to compare Zenkaku and Hankaku
// 1: ON / 0: OFF
$zentohans = '1';
※小テストの判定において、大文字小文字を区別しない設定を
※行った際に、同時に半角全角の判定もなくすかどうかの
※設定を上記でおこないます。
※1でON、0でOFFになります。
※ここより、以下はFUNCTIONになります。
※改変時以外変更する必要はありません。
// Functions
function use_lang_lib()
{
	global $uselibrary;
	return $uselibrary;
}
function rtn_lang_code()
{
	global $lang_code;
	$lang_code = strtolower($lang_code);
	return $lang_code;
}
function normalize_string($string1)
{
	global $zentohans;
	if($zentohans) {
		require_once dirname(__FILE__).'/jcode.php';
		$lang_code1 = rtn_lang_code();
		if (extension_loaded('mbstring')) {
			$string1 = mb_convert_kana($string1, "KVas", $lang_code1);
		} else {
			$lang_code2 = _check_encoding($lang_code1);
			$string2 = ' ';
			$string3 = ' ';
			if($lang_code2 != 1){
				$string2 = JcodeConvert($string2, 1, $lang_code2);
				$string3 = JcodeConvert($string3, 1, $lang_code2);
			}
			$string1 = HANtoZEN($string1, $lang_code2);
			$string1 = ZENtoHAN($string1, $lang_code2, 0, 1);
			$string1 = jstr_replace($string2, $string3, $string1);
		}
	}
	return $string1;
}
function ex_convert_encoding($string1, $string2, $string3)
{
	if ($string3 == '') {
		$string3 = rtn_lang_code();
	}
	if (extension_loaded('mbstring')) {
		$lang_conv = 'mb_convert_encoding';
	} else {
		$lang_conv = 'lang_convert_encoding';
	}
	$string1  = $lang_conv($string1, $string2, $string3);
	return $string1;
}
function mm_convert_encoding($string1, $string2)
{
	if ($string2 == '') {
		$string2 = rtn_lang_code();
	}
	$string1 = ex_convert_encoding($string1, 'iso-2022-jp', $string2);
	$string1 = "=?ISO-2022-JP?B?".base64_encode($string1)."?=";
	return $string1;
}
function email_encoding(&$mail)
{
	$mail->FromName = mm_convert_encoding($mail->FromName, 'auto');
	$mail->Subject  = mm_convert_encoding($mail->Subject, 'auto');
	$mail->Body     = ex_convert_encoding($mail->Body, 'iso-2022-jp', 'auto');
	$mail->CharSet  = 'ISO-2022-JP';
	$mail->Encoding = '7bit';
	foreach ($mail->to as $i => $temp_mail) {
		$mail->to[$i][1] = mm_convert_encoding($temp_mail[1], 'auto');
	}
	foreach ($mail->cc as $i => $temp_mail) {
		$mail->cc[$i][1] = mm_convert_encoding($temp_mail[1], 'auto');
	}
	foreach ($mail->bcc as $i => $temp_mail) {
		$mail->bcc[$i][1] = mm_convert_encoding($temp_mail[1], 'auto');
	}
}
function lang_convert_encoding($str, $to, $from = '')
{
	require_once dirname(__FILE__).'/jcode.php';
	$jc_to   = _check_encoding($to);
	$jc_from = _check_encoding($from);
	if ($jc_from == 0) {
		$jc_from = AutoDetect($str);
	}
	if ($jc_to == 4) {
		global $table_jis_utf8;
		include_once dirname(__FILE__).'/code_table.jis2ucs';
	}
	if ($jc_from == 4) {
		global $table_utf8_jis;
		include_once dirname(__FILE__).'/code_table.ucs2jis';
	}
	return JcodeConvert($str, $jc_from, $jc_to);
}
function _check_encoding($str_encoding)
{
	switch (strtolower($str_encoding)) {
		case 'e':
		case 'euc':
		case 'euc-jp':
			$jc_encoding = 1;
			break;
		case 's':
		case 'sjis':
		case 'shift_jis':
			$jc_encoding = 2;
			break;
		case 'j':
		case 'jis':
		case 'iso-2022-jp':
			$jc_encoding = 3;
			break;
		case 'u':
		case 'utf8':
		case 'utf-8':
			$jc_encoding = 4;
			break;
		default:
			$jc_encoding = 0;
			break;
	}
	return $jc_encoding;
}
function simple_text_out($count, $course, $quiz, $data, $average)
{
	$set_usr_agent = define_usr_agent();
	if ($set_usr_agent == 1) {
		$set_return = "\r\n";
	} elseif ($set_usr_agent == 2) {
		$set_return = "\r";
	} else {
		$set_return = "\n";
	}
	header("Content-Type: application/download\n");
	if($set_usr_agent) {
		$quiz->name = ex_convert_encoding($quiz->name, 'sjis', 'auto');
		$course->shortname = ex_convert_encoding($course->shortname, 'sjis', 'auto');
	}
	header("Content-Disposition: attachment; filename=$course->shortname ".$quiz->name.".txt");
	header("Expires: 0");
	header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
	header("Pragma: public");
	/// Print names of all the fields
	echo "$quiz->name";
	for ($i=1; $i<=$count; $i++) {
		echo "\t$i";
	}
	echo "$set_return";
        
	/// Print all the user data
	foreach ($data as $userid => $datum) {
		if($set_usr_agent) {
			$temp_dataum = ex_convert_encoding(fullname($datum), 'sjis', 'auto');
		} else {
			$temp_dataum = fullname($datum);
		}
		echo $temp_dataum;
		for ($i=1; $i<=$count; $i++) {
			echo "\t";
			if (isset($datum->grades[$i])) {
				if($set_usr_agent) {
					$temp_dataum = ex_convert_encoding($datum->grades[$i], 'sjis', 'auto');
				} else {
					$temp_dataum = $datum->grades[$i];
				}
				echo $temp_dataum;
			}
		}
		echo "$set_return";
	}
	/// Print all the averages
	echo "\t";
	for ($i=1; $i<=$count; $i++) {
		echo "\t".$average[$i];
	}
	echo "$set_return";
	/// Print all the averages as percentages
	echo "\t%";
	for ($i=1; $i<=$count; $i++) {
		$percent = format_float($average[$i] * 100);
		echo "\t$percent";
	}
	echo "$set_return";
	exit;
}
function full_text_out($course, $quiz, $data_tally, $qs_in_order, $question_ids, $qcount, $quests, $match_qs, $analysis, $max_choices, $table_colcount)
{
	$set_usr_agent = define_usr_agent();
	if ($set_usr_agent == 1) {
		$set_return = "\r\n";
	} elseif ($set_usr_agent == 2) {
		$set_return = "\r";
	} else {
		$set_return = "\n";
	}
	header("Content-Type: application/download\n");
	if($set_usr_agent) {
		$quiz->name = ex_convert_encoding($quiz->name, 'sjis', 'auto');
		$course->shortname = ex_convert_encoding($course->shortname, 'sjis', 'auto');
	}
	header("Content-Disposition: attachment; filename=$course->shortname ".$quiz->name.".txt");
	header("Expires: 0");
	header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
	header("Pragma: public");
	/// Print names of all the fields
	echo "$quiz->name";
	echo "$set_return";
        
	/// Print all the user data
	$colcount = count($question_ids);
	foreach ($data_tally as $thisuserno=>$thisuser){
		foreach($thisuser as $thisattemptno=>$thisattempt){
			foreach($thisattempt as $thisitemkey=>$thisitem) {
				if ($thisitem['score'] < 1) {$mark = "";} else {$mark = "*";}
				//First two items are name & grade
				if ($thisitemkey < 2){
					if($set_usr_agent) {
						$temp_dataum = ex_convert_encoding($thisitem, 'sjis', 'auto');
					} else {
						$temp_dataum = $thisitem;
					}
					echo $temp_dataum . "\t";
				} elseif ($thisitemkey['qtype'] == 2){
					if($set_usr_agent) {
						$temp_dataum = ex_convert_encoding($thisitem['data']['answer'], 'sjis', 'auto');
					} else {
						$temp_dataum = $thisitem['data']['answer'];
					}
					echo $temp_dataum . "\t";
				} elseif ($thisitem['qtype'] == 5) {
					if ($thisitem['score'] == 1) {$mark = "*";} else {$mark="";}
					if(!$thisitem['data'][1]){$thisitem['data'][1]="(No Response)";}
					if($set_usr_agent) {
						$temp_dataum_1 = ex_convert_encoding($thisitem['data'][0], 'sjis', 'auto');
						$temp_dataum_2 = ex_convert_encoding($thisitem['data'][1], 'sjis', 'auto');
					} else {
						$temp_dataum_1 = $thisitem['data'][0];
						$temp_dataum_2 = $thisitem['data'][1];
					}
					echo "{$temp_dataum_1} -- $mark{$temp_dataum_2}\t";
				} else {
					if($set_usr_agent) {
						$temp_dataum = ex_convert_encoding($thisitem['data'], 'sjis', 'auto');
					} else {
						$temp_dataum = $thisitem['data'];
					}
					echo "$mark{$temp_dataum}\t";
				}
			}
		}
		echo " $set_return";
	}
	echo " $set_return";
	echo "* Asterisk indicates correct response";
	echo " $set_return";
	//Question numbers
	for  ($i = 1;$i <= $colcount;$i++) {
		echo  "Q-$i\t";
	}
	echo " $set_return";
	//Q numbers
	foreach($qs_in_order as $qid){
		$qcount++;
			if($quests[$qid]['qtype'] == 5) {
				$i = 0;
				foreach ($match_qs[$qid] as $nowq){
				$i++;
				echo  "Q-$qcount M-$i\t";
			}
		} else {
			echo  "Q-$qcount\t";
		}
	}
	echo  " $set_return";
	//Repeat for q answers
	foreach($qs_in_order as $qid){
		$qcount++;
		if($quests[$qid]['qtype'] == 5) {
			foreach ($match_qs[$qid] as $nowq){
				if($set_usr_agent) {
					$temp_dataum = ex_convert_encoding($nowq, 'sjis', 'auto');
				} else {
					$temp_dataum = $nowq;
				}
				echo $temp_dataum. "\t";
			}
		} else {
			echo  "\t";
		}
	}
	echo  " $set_return";
	for ($i = 1; $i<= $max_choices;$i++){
		echo  "M/C #$i\t";
		//display answer tallies
		for ($j = 1; $j <= $table_colcount; $j++){
			//substitute "<br>" for a "//"
			$nowdata = $analysis[$i][$j];
			if (strpos($nowdata,"//")>0) {
				$nowdata = str_replace("//"," : ",$nowdata);
			}
			if($set_usr_agent) {
				$temp_dataum = ex_convert_encoding($nowdata, 'sjis', 'auto');
			} else {
				$temp_dataum = $nowdata;
			}
			echo $nowdata . "\t";
		}
		echo  " $set_return";
	}
	exit;
}
function define_usr_agent()
{
	$usr_agent_data = getenv('HTTP_USER_AGENT');
	if (preg_match('/WIN/i', $usr_agent_data)) {
		$set_usr_agent = 1;
	} elseif (preg_match('/MAC/i', $usr_agent_data)) {
		$set_usr_agent = 2;
	} else {
		$set_usr_agent = 0;
	}
	return $set_usr_agent;
}
?>
 
moodle\lang\ja\fonts\lang_decode.php
※これは、「langlib***.lzh」に含まれているlang_decode.phpに関する説明です。
<?php
/*  Language Library for Japanese
      by Takahito Kashiwagi (webmaster@supertak.com)
    jcode.php / jcode_wrapper.php
      by TOMO (http://www.spencernetwork.org/)
    SAZANAMI FONT
      by eFont (http://sourceforge.jp/projects/efont/) */
// Switch to use Language Library
// 1: ON / 0: OFF
$uselibrary = '1';
// Functions
function lang_decode($string1)
{
	global $uselibrary;
	if(!$uselibrary) {return $string1;}
	$string2 = 'utf-8';
	$string3 = 'auto';
	if (extension_loaded('mbstring')) {
		$lang_conv = 'mb_convert_encoding';
	} else {
		$lang_conv = 'lang_convert_encoding';
	}
	$string1  = $lang_conv($string1, $string2, $string3);
	return $string1;
}
?>

 


Diff to HTML translator 1.0