Browse Source

Fix: PHP coding style problems

MOODLE_20_STABLE
bdaloukas 8 years ago
parent
commit
552fad457f
  1. 202
      exporthtml_snakes.php
  2. 2
      exportjavame.php
  3. 2
      hangman/play.php
  4. 26
      lib.php
  5. 38
      locallib.php
  6. 2
      mod_form.php
  7. 2
      preview.php
  8. 4
      report/overview/report.php
  9. 2
      settings.php
  10. 4
      showattempts.php
  11. 36
      sudoku/class.Sudoku.php
  12. 2
      sudoku/play.php
  13. 2
      tabs.php
  14. 3
      translate.php

202
exporthtml_snakes.php

@ -169,12 +169,13 @@ function ShowMainForm()
direction=Math.floor((current_position /cols))%2;
if (direction == 1) {
axis_x=(cols-(current_position %cols)-1);
} else {
axis_x=current_position %cols;
} else {
axis_x=current_position %cols;
}
axis_y=Math.floor((current_position /rows));
pawn_x=board_headerx[current_board]+(axis_x*col_width)+(col_width-pawn_width[current_board])/2;
pawn_y=board_footery[current_board]+pawn_height[current_board]+(axis_y*col_height)+(col_height-pawn_height[current_board])/2;
pawn_y=board_footery[current_board]+pawn_height[current_board]+(axis_y*col_height);
pawn_y += (col_height-pawn_height[current_board])/2;
document.write('<div id="pawn1"><img id="pawn" alt="" src="images/player1.png"></div>');
move_pawn();
@ -183,7 +184,7 @@ function ShowMainForm()
function selectBoard() {
current_board = document.getElementById("boardtype").value;
document.getElementById("boardimage").src = "images/" + board_images[ current_board];
document.getElementById("boardimage").src = "images/" + board_images[ current_board];
}
function select_quest() {
@ -238,7 +239,7 @@ function check_answer_M() {
return;
}
var feedbacks = decode_multiple_choice(quest_feedb);
var feedbacks = decode_multiple_choice(quest_feedb);
var j;
for (j=0;j<n;j++) {
@ -252,38 +253,42 @@ function check_answer_M() {
current_position += current_dice;
correct_ans =correct_ans+1; //calculate new score----
score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
var s = '<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
document.getElementById("show_score").innerHTML = s;
check_game_over();
check_exists_ladder();
} else {
score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
score = Math.round((correct_ans/all_ans)*100);
var s = '<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
document.getElementById("show_score").innerHTML = s;
check_exists_snake();
}
document.getElementById("OK_btn").style.display = "block";
document.getElementById("OK_btn").style.display = "block";
}
function check_answer_S() {
document.getElementById("answer").disabled = "true";
document.getElementById("check_btn").style.display = "none";
if (document.getElementById("answer").value.toUpperCase() == quest_resp[ 1].toUpperCase()) {
document.getElementById("feedb").style.display = "block";
current_position += current_dice;
correct_ans =correct_ans+1; //calculate new score
score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
var s = '<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
document.getElementById("show_score").innerHTML = s;
check_game_over();
check_exists_ladder();
} else {
check_exists_ladder();
} else {
document.getElementById("feedb_wrong").style.display = "block";
score = Math.round((correct_ans/all_ans)*100);
document.getElementById("show_score").innerHTML='<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
var s = '<strong>'+str_score+': </strong><strong class="score">' +score+ '</strong>';
document.getElementById("show_score").innerHTML = s;
check_exists_snake();
}
document.getElementById("OK_btn").style.display = "block";
document.getElementById("OK_btn").style.display = "block";
}
function check_game_over() {
@ -301,7 +306,7 @@ function check_exists_ladder() {
if( pos < 0) {
return;
}
var s = board_contents[ current_board].substr( pos+find.length)
pos = s.indexOf( ',');
if (pos >= 0) {
@ -357,7 +362,7 @@ function display_quest() {
if( IsMultipleChoiceQuestion()) {
display_quest_M();
} else {
} else {
display_quest_S();
}
}
@ -376,12 +381,12 @@ function display_quest_M() {
for(i=0; i < mchoice_count ; i++) {
mchoice_positions[ i] = i+1;
}
for(i=0; i < mchoice_count ; i++) {
for(i=0; i < mchoice_count ; i++) {
var j = Math.floor((Math.random() * mchoice_count));
var temp = mchoice_positions[ i];
mchoice_positions[ i] = mchoice_positions[ j];
mchoice_positions[ j] = temp;
}
}
for(i=0; i < mchoice_count;i++) {
s = s + '<input type="radio" name="radio_answer" id="radio_answer" value="';
@ -398,7 +403,7 @@ function display_quest_M() {
document.getElementById("dicecont").innerHTML = s;
document.getElementById("question_area").style.display = "block";
document.getElementById("check_btn").style.display = "block";
document.getElementById("check_btn").style.display = "block";
}
function display_quest_S() {
@ -414,9 +419,9 @@ function display_quest_S() {
s = s + feedb_wrong_S+' </div> <div id="feedb" style="display:none; color:yellow;"> ';
s = s + feedb_correct_S+'</div> <br /><div id="OK_btn" style="display:none;">';
s = s + '<input type="button" onclick="display_quest();" value="OK"/></div> </div>';
document.getElementById("dicecont").innerHTML = s;
document.getElementById("question_area").style.display = "block";
document.getElementById("check_btn").style.display = "block";
document.getElementById("dicecont").innerHTML = s;
document.getElementById("question_area").style.display = "block";
document.getElementById("check_btn").style.display = "block";
}
function move_pawn() {
@ -428,91 +433,86 @@ function move_pawn() {
var col_width = (board_width[current_board]-board_headerx[current_board]-board_footerx[current_board])/cols;
var col_height = (board_height[current_board]-board_headery[current_board]-board_footery[current_board])/rows;
if( current_position >= 0) {
direction=Math.floor((current_position /cols))%2;
if (direction == 1) {
axis_x=(cols-(current_position %cols)-1);
} else {
axis_x=current_position %cols;
if( current_position >= 0) {
direction=Math.floor((current_position /cols))%2;
if (direction == 1) {
axis_x=(cols-(current_position %cols)-1);
} else {
axis_x=current_position %cols;
}
axis_y=Math.floor((current_position /rows));
pawn_x=board_headerx[current_board]+(axis_x*col_width)+(col_width-pawn_width[current_board])/2;
pawn_y=board_footery[current_board]+pawn_height[current_board]+(axis_y*col_height)+(col_height-pawn_height[current_board])/2;
axis_y=Math.floor((current_position /rows));
pawn_x=board_headerx[current_board]+(axis_x*col_width)+(col_width-pawn_width[current_board])/2;
pawn_y = board_footery[current_board]+pawn_height[current_board]+(axis_y*col_height);
pawn_y += (col_height-pawn_height[current_board])/2;
document.getElementById("pawn1").style.position='relative';
document.getElementById("pawn1").style.left=pawn_x+'px';
document.getElementById("pawn1").style.bottom=pawn_y+'px';
}
document.getElementById("pawn1").style.left=pawn_x+'px';
document.getElementById("pawn1").style.bottom=pawn_y+'px';
}
}
function Base64decode(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
var keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = keyStr.indexOf(input.charAt(i++));
enc2 = keyStr.indexOf(input.charAt(i++));
enc3 = keyStr.indexOf(input.charAt(i++));
enc4 = keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = Base64_utf8_decode(output);
return output;
};
function Base64decode(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
var keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
// Private method for UTF-8 decoding.
function Base64_utf8_decode(utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = keyStr.indexOf(input.charAt(i++));
enc2 = keyStr.indexOf(input.charAt(i++));
enc3 = keyStr.indexOf(input.charAt(i++));
enc4 = keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = Base64_utf8_decode(output);
return output;
};
// Private method for UTF-8 decoding.
function Base64_utf8_decode(utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
} else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
</script>
</body>

2
exportjavame.php

@ -16,7 +16,7 @@
/**
* This page export the game to javame for mobile phones
*
*
* @author bdaloukas
* @package game
**/

2
hangman/play.php

@ -16,6 +16,8 @@
// This file plays the game hangman.
defined('MOODLE_INTERNAL') || die();
function game_hangman_continue( $id, $game, $attempt, $hangman, $newletter, $action, $context) {
global $DB, $USER;

26
lib.php

@ -17,7 +17,7 @@
/**
* Library of functions and constants for module game
*
* @author
* @author Vasilis Daloukas
* @package game
**/
@ -179,7 +179,7 @@ function game_before_add_or_update(&$game) {
}
/**
* Given an ID of an instance of this module,
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
*
@ -262,7 +262,7 @@ function game_user_outline($course, $user, $mod, $game) {
}
/**
* Print a detailed representation of what a user has done with
* Print a detailed representation of what a user has done with
* a given particular instance of this module, for user activity reports.
**/
function game_user_complete($course, $user, $mod, $game) {
@ -291,7 +291,7 @@ function game_user_complete($course, $user, $mod, $game) {
/**
* Given a course and a time, this module should find recent activity
* that has occurred in game activities and print it out.
* Return true if there was output, or false is there was none.
* Return true if there was output, or false is there was none.
*
* @uses $CFG
* @return boolean
@ -320,9 +320,9 @@ function game_cron() {
}
/**
* Must return an array of grades for a given instance of this module,
* Must return an array of grades for a given instance of this module,
* indexed by user. It also returns a maximum allowed grade.
*
*
* Example:
* $return->grades = array of grades;
* $return->maxgrade = maximum allowed grade;
@ -972,7 +972,7 @@ if (!defined('USE_GET_SHORTCUTS')) {
if (defined('USE_GET_SHORTCUTS')) {
/**
* Returns an array of game type objects to construct
* menu list when adding new game
* menu list when adding new game
*
*/
function game_get_shortcuts($defaultitem) {
@ -1359,11 +1359,11 @@ function game_get_context_course_instance( $courseid) {
}
function game_pix_url( $filename) {
global $OUTPUT;
global $OUTPUT;
if (game_get_moodle_version() >= '03.03') {
return $OUTPUT->image_url($filename, 'mod_game');
} else {
return $OUTPUT->pix_url($filename, 'mod_game');
}
if (game_get_moodle_version() >= '03.03') {
return $OUTPUT->image_url($filename, 'mod_game');
} else {
return $OUTPUT->pix_url($filename, 'mod_game');
}
}

38
locallib.php

@ -1579,17 +1579,17 @@ function game_print_question_multichoice( $game, $question, $context) {
</div>
<table class="answer">
<?php
$row = 1;
foreach ($anss as $answer) {
<?php
$row = 1;
foreach ($anss as $answer) {
?>
<tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">
<td>
<?php echo $answer->control; ?>
</td>
</tr>
<?php
}
<?php
}
?>
</table>
</div>
@ -1635,17 +1635,17 @@ function game_print_question_multianswer( $game, $question, $context) {
</div>
<table class="answer">
<?php
$row = 1;
foreach ($anss as $answer) {
<?php
$row = 1;
foreach ($anss as $answer) {
?>
<tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">
<td>
<?php echo $answer->control; ?>
</td>
</tr>
<?php
}
<?php
}
?>
</table>
</div>
@ -1657,7 +1657,9 @@ function game_print_question_shortanswer( $game, $question, $context) {
?>
<div class="qtext">
<?php echo game_filterquestion(str_replace( '\"', '"', $questiontext), $question->id, $context->id, $game->course); ?>
<?php
echo game_filterquestion(str_replace( '\"', '"', $questiontext), $question->id, $context->id, $game->course);
?>
</div>
<div class="ablock clearfix">
@ -1890,12 +1892,6 @@ function game_addattempt( $game) {
return $DB->get_record_select( 'game_attempts', 'id='.$newid);
}
/*
function game_print_r( $title, $a) {
echo "\r\n<hr><b>$title</b><br>";print_r( $a);echo "<hr>\r\n";
}
*/
function game_get_contexts() {
global $CFG, $COURSE;
@ -2016,14 +2012,6 @@ function game_question_get_id_from_name_prefix($name) {
return (integer) $matches[ 1];
}
/*
function game_debug_array( $title, $a) {
echo '<br>'.$title.' ';
print_r( $a);
echo '<br>';
}
*/
function game_get_version() {
global $CFG, $DB;

2
mod_form.php

@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once( $CFG->dirroot.'/course/moodleform_mod.php');
require( 'locallib.php');

2
preview.php

@ -16,7 +16,7 @@
/**
* This page prints a particular attempt of game
*
*
* @author bdaloukas
* @package game
**/

4
report/overview/report.php

@ -16,13 +16,13 @@
defined('MOODLE_INTERNAL') || die();
/**
/*
* This script lists student attempts
*
* @author bdaloukas.
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package game
*//** */
*/
require_once($CFG->libdir.'/tablelib.php');

2
settings.php

@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Form for creating and modifying a game
* Form for creating and modifying a game
*
* @package game
* @author Vasilis Daloukas

4
showattempts.php

@ -75,7 +75,7 @@ function game_showusers($game) {
window.location.href = "<?php echo $href;?>" + document.getElementById('menuuser').value + '&groupid='+groupid;
}
</script>
<?php
<?php
$attributes = 'onchange="javascript:onselectuser();"';
$name = 'user';
@ -128,7 +128,7 @@ function game_showgroups($game) {
window.location.href = "<?php echo $href;?>" + document.getElementById('menugroup').value;
}
</script>
<?php
<?php
$attributes = 'onchange="javascript:onselectgroup();"';
$name = 'group';

36
sudoku/class.Sudoku.php

@ -336,7 +336,7 @@ class cell extends objects {
* @package Sudoku
*/
class rcs extends ObjectS{
class rcs extends ObjectS {
protected $theindex;
protected $therow = array();
@ -346,7 +346,7 @@ class rcs extends ObjectS{
protected $thetag = "";
/**
* This
* This
* @desc Constructor
* @access public
* @param string $theTag "Row", "Column", "Square", used primarily in debugging.
@ -557,7 +557,7 @@ class rcs extends ObjectS{
/**
* @desc Get the header set by the last call to doAnInference.
*
*
*/
public function getheader() {
@ -570,7 +570,7 @@ class rcs extends ObjectS{
* This is a second positive inference that provides additional negative information.
* Thanks to Ghica van Emde Boas (also an author of a Sudoku class) for convincing
* me that these situations really occurred.
*
*
* @desc Eliminate tuple-locked alternatives.
* @access private
* @return boolean True if something changed.
@ -640,9 +640,9 @@ class rcs extends ObjectS{
/**
* Find a solution to a row/column/square.
*
*
* Find any unique numbers within the row/column/square under consideration.
* Look through a row structure for a value that appears in only one cell.
* Look through a row structure for a value that appears in only one cell.
* When you find one, that's a solution for that cell.
*
* There is a second inference that can be taken. Given "n" cells in a row/column/square
@ -726,7 +726,7 @@ class rcs extends ObjectS{
/**
* Validate a part of a trial solution.
*
*
* Check a row/column/square to see if there are any invalidations on this solution.
* Only items that are actually solved are compared. This is used during puzzle
* generation.
@ -781,8 +781,8 @@ class r extends rcs {
* @access private
* @param integer $theIndex the index of the cell within the row or column.
* @return integer the "coupling coefficient" for the cell. The sum of the
* sizes of the intersection between this and all other
* cells in the row or column.
* sizes of the intersection between this and all other
* cells in the row or column.
*/
protected function _coupling($theindex) {
@ -913,7 +913,7 @@ class s extends rcs {
* to that position, I just retry and so far I've always succeeded in
* generating an initial state. Not guarateed, but in engineering terms
* "close enough".
*
*
* @package Sudoku
* @example ./example.php
* @example ./example1.php
@ -1525,7 +1525,7 @@ class sudoku extends ObjectS {
*
* @desc Initialize puzzle from a string.
* @access public
* @param string $theString The initial state of each cell in the puzzle.
* @param string $theString The initial state of each cell in the puzzle.
*/
public function initializepuzzlefromstring($thestring) {
@ -1560,7 +1560,7 @@ class sudoku extends ObjectS {
/**
* Convert pending to actual solutions.
*
*
* This step is actually unnecessary unless you want a pretty output of the
* intermediate.
*
@ -1585,7 +1585,7 @@ class sudoku extends ObjectS {
/**
* Print the contents of the board in HTML format.
*
*
* A "hook" so that extension classes can show all the steps taken by
* the solve function.
*
@ -1691,7 +1691,7 @@ class sudoku extends ObjectS {
* two cells containing a pair of values eliminate those values from
* consideration in the rest of the RC or S.
* 3b. The n/n+1 set rule as discovered by me, e.g., in any RCS, three cells
* containing the following pattern, (i, j)/(j, k)/(i, j, k) eliminate
* containing the following pattern, (i, j)/(j, k)/(i, j, k) eliminate
* the values i, j, k from consideration in the rest of the RC or S.
*
* During processing I explain which structures (row, column, square)
@ -1776,7 +1776,7 @@ class sudoku extends ObjectS {
*
* There's a bit of bookkeeping to keep the state right when backing up, but that's pretty
* straightforward and looks a lot like that of generatePuzzle.
*
*
* @desc Brute force additional solutions.
* @access public
* @returns array The clues added sufficient to solve the puzzle.
@ -1841,7 +1841,7 @@ class sudoku extends ObjectS {
/**
* Validate a complete solution.
*
*
* After a complete solution has been generated check the board and
* report any inconsistencies. This is primarily intended for debugging
* purposes.
@ -1895,7 +1895,7 @@ class sudoku extends ObjectS {
* Extend Sudoku to generate puzzles based on templates.
*
* Templates are either input files or arrays containing doubles.
*
*
* @package Sudoku
*/
@ -1938,7 +1938,7 @@ class SudokuTemplates extends Sudoku
/**
* Extend Sudoku to print all intermediate results.
*
*
* @package Sudoku
*/

2
sudoku/play.php

@ -285,7 +285,7 @@ function game_sudoku_showsudoku( $data, $guess, $bshowlegend, $bshowsolution, $o
window.location.href = "<?php echo $href; ?>&pos=" + pos + "&num=" + s;
}
</script>
<?php
<?php
// Here are the congratulations.
if ($attempt->timefinish) {

2
tabs.php

@ -72,7 +72,7 @@ if ($currenttab == 'reports' and isset($mode)) {
$activated[] = 'reports';
$allreports = get_list_of_plugins("mod/game/report");
// Standard reports we want to show first
// Standard reports we want to show first.
$reportlist = array ('overview');
foreach ($allreports as $report) {

3
translate.php

@ -17,8 +17,7 @@
/**
* Check translation of module Game
*
* @author
* @version $Id: translate.php,v 1.10 2012/07/25 23:07:43 bdaloukas Exp $
* @author Vasilis Daloukas
* @package game
**/
require( "../../config.php");

Loading…
Cancel
Save