| @@ -57,19 +57,19 @@ discard block | ||
| 57 | 57 | |
| 58 | 58 | // If player username provided, map it to a user ID, overriding any provided value of player user ID. | 
| 59 | 59 |  if (!empty($player_uname)) { | 
| 60 | - $player_uid = chess_uname_to_uid($player_uname); | |
| 61 | - // Otherwise, if player user ID provided, map it to a username. | |
| 60 | + $player_uid = chess_uname_to_uid($player_uname); | |
| 61 | + // Otherwise, if player user ID provided, map it to a username. | |
| 62 | 62 |  } elseif (0 != $player_uid) { | 
| 63 | -    $memberHandler = xoops_getHandler('member'); | |
| 63 | +	$memberHandler = xoops_getHandler('member'); | |
| 64 | 64 | |
| 65 | - $player_user = $memberHandler->getUser($player_uid); | |
| 65 | + $player_user = $memberHandler->getUser($player_uid); | |
| 66 | 66 | |
| 67 | -    $player_uname = is_object($player_user) ? $player_user->getVar('uname') : ''; | |
| 67 | +	$player_uname = is_object($player_user) ? $player_user->getVar('uname') : ''; | |
| 68 | 68 | } | 
| 69 | 69 | |
| 70 | 70 | // Check that both user ID and username are now defined. | 
| 71 | 71 |  if (0 == $player_uid || empty($player_uname)) { | 
| 72 | - redirect_header(XOOPS_URL . '/modules/chess/index.php', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_PLAYER_NOT_FOUND); | |
| 72 | + redirect_header(XOOPS_URL . '/modules/chess/index.php', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_PLAYER_NOT_FOUND); | |
| 73 | 73 | } | 
| 74 | 74 | |
| 75 | 75 | // Display stats | 
| @@ -89,96 +89,96 @@ discard block | ||
| 89 | 89 | */ | 
| 90 | 90 | function chess_player_stats($player_uid, $player_uname, $show_option = _CHESS_SHOW_EXCEPT_SELFPLAY, $cstart = 0, $gstart = 0) | 
| 91 | 91 |  { | 
| 92 | - global $xoopsDB, $xoopsTpl; | |
| 92 | + global $xoopsDB, $xoopsTpl; | |
| 93 | 93 | |
| 94 | -    $rating_system = chess_moduleConfig('rating_system'); | |
| 94 | +	$rating_system = chess_moduleConfig('rating_system'); | |
| 95 | 95 | |
| 96 | - $num_provisional_games = chess_ratings_num_provisional_games(); | |
| 96 | + $num_provisional_games = chess_ratings_num_provisional_games(); | |
| 97 | 97 | |
| 98 | - // set show_option to default if appropriate | |
| 98 | + // set show_option to default if appropriate | |
| 99 | 99 | |
| 100 | -    if (!$show_option || ('none' == $rating_system && _CHESS_SHOW_RATED_ONLY == $show_option)) { | |
| 101 | - $show_option = _CHESS_SHOW_EXCEPT_SELFPLAY; | |
| 102 | - } | |
| 100 | +	if (!$show_option || ('none' == $rating_system && _CHESS_SHOW_RATED_ONLY == $show_option)) { | |
| 101 | + $show_option = _CHESS_SHOW_EXCEPT_SELFPLAY; | |
| 102 | + } | |
| 103 | 103 | |
| 104 | - // get maximum number of items to display on a page, and constrain it to a reasonable value | |
| 104 | + // get maximum number of items to display on a page, and constrain it to a reasonable value | |
| 105 | 105 | |
| 106 | -    $max_items_to_display = chess_moduleConfig('max_items'); | |
| 106 | +	$max_items_to_display = chess_moduleConfig('max_items'); | |
| 107 | 107 | |
| 108 | - $max_items_to_display = min(max($max_items_to_display, 1), 1000); | |
| 108 | + $max_items_to_display = min(max($max_items_to_display, 1), 1000); | |
| 109 | 109 | |
| 110 | -    $challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 110 | +	$challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 111 | 111 | |
| 112 | -    $games_table = $xoopsDB->prefix('chess_games'); | |
| 112 | +	$games_table = $xoopsDB->prefix('chess_games'); | |
| 113 | 113 | |
| 114 | -    $ratings_table = $xoopsDB->prefix('chess_ratings'); | |
| 114 | +	$ratings_table = $xoopsDB->prefix('chess_ratings'); | |
| 115 | 115 | |
| 116 | - $player = []; | |
| 116 | + $player = []; | |
| 117 | 117 | |
| 118 | - $player['uid'] = $player_uid; | |
| 118 | + $player['uid'] = $player_uid; | |
| 119 | 119 | |
| 120 | - $player['uname'] = $player_uname; | |
| 120 | + $player['uname'] = $player_uname; | |
| 121 | 121 | |
| 122 | - // --------------------------------------------- | |
| 122 | + // --------------------------------------------- | |
| 123 | 123 | |
| 124 | - // form for selecting player and display-options | |
| 124 | + // form for selecting player and display-options | |
| 125 | 125 | |
| 126 | - // --------------------------------------------- | |
| 126 | + // --------------------------------------------- | |
| 127 | 127 | |
| 128 | - // security token not needed for this form | |
| 128 | + // security token not needed for this form | |
| 129 | 129 | |
| 130 | - $form = new XoopsThemeForm(_MD_CHESS_SELECT_PLAYER, 'form1', 'player_stats.php'); | |
| 130 | + $form = new XoopsThemeForm(_MD_CHESS_SELECT_PLAYER, 'form1', 'player_stats.php'); | |
| 131 | 131 | |
| 132 | -    $form->addElement(new XoopsFormText('', 'player_uname', 25, 50, $player_uname)); | |
| 132 | +	$form->addElement(new XoopsFormText('', 'player_uname', 25, 50, $player_uname)); | |
| 133 | 133 | |
| 134 | -    $form->addElement(new XoopsFormButton('', 'submit_select_player', _MD_CHESS_SUBMIT_BUTTON, 'submit')); | |
| 134 | +	$form->addElement(new XoopsFormButton('', 'submit_select_player', _MD_CHESS_SUBMIT_BUTTON, 'submit')); | |
| 135 | 135 | |
| 136 | -    $menu_show_option = new XoopsFormSelect('', 'show_option', $show_option, 1, false); | |
| 136 | +	$menu_show_option = new XoopsFormSelect('', 'show_option', $show_option, 1, false); | |
| 137 | 137 | |
| 138 | - $menu_show_option->addOption(_CHESS_SHOW_ALL_GAMES, _MD_CHESS_SHOW_ALL_GAMES); | |
| 138 | + $menu_show_option->addOption(_CHESS_SHOW_ALL_GAMES, _MD_CHESS_SHOW_ALL_GAMES); | |
| 139 | 139 | |
| 140 | - $menu_show_option->addOption(_CHESS_SHOW_EXCEPT_SELFPLAY, _MD_CHESS_SHOW_EXCEPT_SELFPLAY); // default | |
| 140 | + $menu_show_option->addOption(_CHESS_SHOW_EXCEPT_SELFPLAY, _MD_CHESS_SHOW_EXCEPT_SELFPLAY); // default | |
| 141 | 141 | |
| 142 | -    if ('none' != $rating_system) { | |
| 143 | - $menu_show_option->addOption(_CHESS_SHOW_RATED_ONLY, _MD_CHESS_SHOW_RATED_ONLY); | |
| 144 | - } | |
| 142 | +	if ('none' != $rating_system) { | |
| 143 | + $menu_show_option->addOption(_CHESS_SHOW_RATED_ONLY, _MD_CHESS_SHOW_RATED_ONLY); | |
| 144 | + } | |
| 145 | 145 | |
| 146 | - $form->addElement($menu_show_option); | |
| 146 | + $form->addElement($menu_show_option); | |
| 147 | 147 | |
| 148 | - $form->assign($xoopsTpl); | |
| 148 | + $form->assign($xoopsTpl); | |
| 149 | 149 | |
| 150 | - // user IDs that will require mapping to usernames | |
| 150 | + // user IDs that will require mapping to usernames | |
| 151 | 151 | |
| 152 | - $userids = []; | |
| 152 | + $userids = []; | |
| 153 | 153 | |
| 154 | - // -------------- | |
| 154 | + // -------------- | |
| 155 | 155 | |
| 156 | - // player's games | |
| 156 | + // player's games | |
| 157 | 157 | |
| 158 | - // -------------- | |
| 158 | + // -------------- | |
| 159 | 159 | |
| 160 | - // Two queries are performed, one without a limit clause to count the total number of rows for the page navigator, | |
| 160 | + // Two queries are performed, one without a limit clause to count the total number of rows for the page navigator, | |
| 161 | 161 | |
| 162 | - // and one with a limit clause to get the data for display on the current page. | |
| 162 | + // and one with a limit clause to get the data for display on the current page. | |
| 163 | 163 | |
| 164 | - // SQL_CALC_FOUND_ROWS and FOUND_ROWS(), available in MySQL 4.0.0, provide a more efficient way of doing this. | |
| 164 | + // SQL_CALC_FOUND_ROWS and FOUND_ROWS(), available in MySQL 4.0.0, provide a more efficient way of doing this. | |
| 165 | 165 | |
| 166 | - $where = "'$player_uid' IN (white_uid, black_uid)"; | |
| 166 | + $where = "'$player_uid' IN (white_uid, black_uid)"; | |
| 167 | 167 | |
| 168 | -    if (_CHESS_SHOW_EXCEPT_SELFPLAY == $show_option) { | |
| 169 | - $where .= ' AND white_uid != black_uid'; | |
| 170 | -    } elseif (_CHESS_SHOW_RATED_ONLY == $show_option) { | |
| 171 | - $where .= ' AND is_rated = "1" AND white_uid != black_uid'; | |
| 172 | - } | |
| 168 | +	if (_CHESS_SHOW_EXCEPT_SELFPLAY == $show_option) { | |
| 169 | + $where .= ' AND white_uid != black_uid'; | |
| 170 | +	} elseif (_CHESS_SHOW_RATED_ONLY == $show_option) { | |
| 171 | + $where .= ' AND is_rated = "1" AND white_uid != black_uid'; | |
| 172 | + } | |
| 173 | 173 | |
| 174 | -    $result = $xoopsDB->query("SELECT COUNT(*) FROM $games_table WHERE $where"); | |
| 174 | +	$result = $xoopsDB->query("SELECT COUNT(*) FROM $games_table WHERE $where"); | |
| 175 | 175 | |
| 176 | - [$num_items] = $xoopsDB->fetchRow($result); | |
| 176 | + [$num_items] = $xoopsDB->fetchRow($result); | |
| 177 | 177 | |
| 178 | - $xoopsDB->freeRecordSet($result); | |
| 178 | + $xoopsDB->freeRecordSet($result); | |
| 179 | 179 | |
| 180 | - $result = $xoopsDB->query( | |
| 181 | - " | |
| 180 | + $result = $xoopsDB->query( | |
| 181 | + " | |
| 182 | 182 | SELECT game_id, fen_active_color, white_uid, black_uid, pgn_result, is_rated, | 
| 183 | 183 | UNIX_TIMESTAMP(GREATEST(create_date,start_date,last_date)) AS last_activity | 
| 184 | 184 | FROM $games_table | 
| @@ -186,191 +186,191 @@ discard block | ||
| 186 | 186 | ORDER BY last_activity DESC | 
| 187 | 187 | LIMIT $gstart, $max_items_to_display | 
| 188 | 188 | " | 
| 189 | - ); | |
| 189 | + ); | |
| 190 | 190 | |
| 191 | - $games = []; | |
| 191 | + $games = []; | |
| 192 | 192 | |
| 193 | -    while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 194 | - $games[] = [ | |
| 195 | - 'game_id' => $row['game_id'], | |
| 196 | - 'white_uid' => $row['white_uid'], | |
| 197 | - 'black_uid' => $row['black_uid'], | |
| 198 | - 'fen_active_color' => $row['fen_active_color'], | |
| 199 | - 'pgn_result' => $row['pgn_result'], | |
| 200 | - 'last_activity' => $row['last_activity'], | |
| 201 | - 'is_rated' => $row['is_rated'], | |
| 202 | - ]; | |
| 193 | +	while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 194 | + $games[] = [ | |
| 195 | + 'game_id' => $row['game_id'], | |
| 196 | + 'white_uid' => $row['white_uid'], | |
| 197 | + 'black_uid' => $row['black_uid'], | |
| 198 | + 'fen_active_color' => $row['fen_active_color'], | |
| 199 | + 'pgn_result' => $row['pgn_result'], | |
| 200 | + 'last_activity' => $row['last_activity'], | |
| 201 | + 'is_rated' => $row['is_rated'], | |
| 202 | + ]; | |
| 203 | 203 | |
| 204 | - // save user IDs that will require mapping to usernames | |
| 204 | + // save user IDs that will require mapping to usernames | |
| 205 | 205 | |
| 206 | -        if ($row['white_uid']) { | |
| 207 | - $userids[$row['white_uid']] = 1; | |
| 208 | - } | |
| 206 | +		if ($row['white_uid']) { | |
| 207 | + $userids[$row['white_uid']] = 1; | |
| 208 | + } | |
| 209 | 209 | |
| 210 | -        if ($row['black_uid']) { | |
| 211 | - $userids[$row['black_uid']] = 1; | |
| 212 | - } | |
| 213 | - } | |
| 210 | +		if ($row['black_uid']) { | |
| 211 | + $userids[$row['black_uid']] = 1; | |
| 212 | + } | |
| 213 | + } | |
| 214 | 214 | |
| 215 | - $xoopsDB->freeRecordSet($result); | |
| 215 | + $xoopsDB->freeRecordSet($result); | |
| 216 | 216 | |
| 217 | - $show_option_urlparam = "&show_option=$show_option"; | |
| 217 | + $show_option_urlparam = "&show_option=$show_option"; | |
| 218 | 218 | |
| 219 | - $games_pagenav = new XoopsPageNav($num_items, $max_items_to_display, $gstart, 'gstart', "player_uid=$player_uid$show_option_urlparam"); | |
| 219 | + $games_pagenav = new XoopsPageNav($num_items, $max_items_to_display, $gstart, 'gstart', "player_uid=$player_uid$show_option_urlparam"); | |
| 220 | 220 | |
| 221 | - // ------------------- | |
| 221 | + // ------------------- | |
| 222 | 222 | |
| 223 | - // player's challenges | |
| 223 | + // player's challenges | |
| 224 | 224 | |
| 225 | - // ------------------- | |
| 225 | + // ------------------- | |
| 226 | 226 | |
| 227 | - // Two queries are performed, one without a limit clause to count the total number of rows for the page navigator, | |
| 227 | + // Two queries are performed, one without a limit clause to count the total number of rows for the page navigator, | |
| 228 | 228 | |
| 229 | - // and one with a limit clause to get the data for display on the current page. | |
| 229 | + // and one with a limit clause to get the data for display on the current page. | |
| 230 | 230 | |
| 231 | - // SQL_CALC_FOUND_ROWS and FOUND_ROWS(), available in MySQL 4.0.0, provide a more efficient way of doing this. | |
| 231 | + // SQL_CALC_FOUND_ROWS and FOUND_ROWS(), available in MySQL 4.0.0, provide a more efficient way of doing this. | |
| 232 | 232 | |
| 233 | - $where = "'$player_uid' IN (player1_uid, player2_uid)"; | |
| 233 | + $where = "'$player_uid' IN (player1_uid, player2_uid)"; | |
| 234 | 234 | |
| 235 | -    if (_CHESS_SHOW_RATED_ONLY == $show_option) { | |
| 236 | - $where .= ' AND is_rated = "1"'; | |
| 237 | - } | |
| 235 | +	if (_CHESS_SHOW_RATED_ONLY == $show_option) { | |
| 236 | + $where .= ' AND is_rated = "1"'; | |
| 237 | + } | |
| 238 | 238 | |
| 239 | -    $result = $xoopsDB->query("SELECT COUNT(*) FROM $challenges_table WHERE $where"); | |
| 239 | +	$result = $xoopsDB->query("SELECT COUNT(*) FROM $challenges_table WHERE $where"); | |
| 240 | 240 | |
| 241 | - [$num_items] = $xoopsDB->fetchRow($result); | |
| 241 | + [$num_items] = $xoopsDB->fetchRow($result); | |
| 242 | 242 | |
| 243 | - $xoopsDB->freeRecordSet($result); | |
| 243 | + $xoopsDB->freeRecordSet($result); | |
| 244 | 244 | |
| 245 | - $result = $xoopsDB->query( | |
| 246 | - " | |
| 245 | + $result = $xoopsDB->query( | |
| 246 | + " | |
| 247 | 247 | SELECT challenge_id, game_type, color_option, player1_uid, player2_uid, UNIX_TIMESTAMP(create_date) AS create_date, is_rated | 
| 248 | 248 | FROM $challenges_table | 
| 249 | 249 | WHERE $where | 
| 250 | 250 | ORDER BY create_date DESC | 
| 251 | 251 | LIMIT $cstart, $max_items_to_display | 
| 252 | 252 | " | 
| 253 | - ); | |
| 253 | + ); | |
| 254 | 254 | |
| 255 | - $challenges = []; | |
| 255 | + $challenges = []; | |
| 256 | 256 | |
| 257 | -    while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 258 | - $challenges[] = [ | |
| 259 | - 'challenge_id' => $row['challenge_id'], | |
| 260 | - 'game_type' => $row['game_type'], | |
| 261 | - 'color_option' => $row['color_option'], | |
| 262 | - 'player1_uid' => $row['player1_uid'], | |
| 263 | - 'player2_uid' => $row['player2_uid'], | |
| 264 | - 'create_date' => $row['create_date'], | |
| 265 | - 'is_rated' => $row['is_rated'], | |
| 266 | - ]; | |
| 257 | +	while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 258 | + $challenges[] = [ | |
| 259 | + 'challenge_id' => $row['challenge_id'], | |
| 260 | + 'game_type' => $row['game_type'], | |
| 261 | + 'color_option' => $row['color_option'], | |
| 262 | + 'player1_uid' => $row['player1_uid'], | |
| 263 | + 'player2_uid' => $row['player2_uid'], | |
| 264 | + 'create_date' => $row['create_date'], | |
| 265 | + 'is_rated' => $row['is_rated'], | |
| 266 | + ]; | |
| 267 | 267 | |
| 268 | - // save user IDs that will require mapping to usernames | |
| 268 | + // save user IDs that will require mapping to usernames | |
| 269 | 269 | |
| 270 | -        if ($row['player1_uid']) { | |
| 271 | - $userids[$row['player1_uid']] = 1; | |
| 272 | - } | |
| 270 | +		if ($row['player1_uid']) { | |
| 271 | + $userids[$row['player1_uid']] = 1; | |
| 272 | + } | |
| 273 | 273 | |
| 274 | -        if ($row['player2_uid']) { | |
| 275 | - $userids[$row['player2_uid']] = 1; | |
| 276 | - } | |
| 277 | - } | |
| 274 | +		if ($row['player2_uid']) { | |
| 275 | + $userids[$row['player2_uid']] = 1; | |
| 276 | + } | |
| 277 | + } | |
| 278 | 278 | |
| 279 | - $xoopsDB->freeRecordSet($result); | |
| 279 | + $xoopsDB->freeRecordSet($result); | |
| 280 | 280 | |
| 281 | - $show_option_urlparam = "&show_option=$show_option"; | |
| 281 | + $show_option_urlparam = "&show_option=$show_option"; | |
| 282 | 282 | |
| 283 | - $challenges_pagenav = new XoopsPageNav($num_items, $max_items_to_display, $cstart, 'cstart', "player_uid=$player_uid$show_option_urlparam"); | |
| 283 | + $challenges_pagenav = new XoopsPageNav($num_items, $max_items_to_display, $cstart, 'cstart', "player_uid=$player_uid$show_option_urlparam"); | |
| 284 | 284 | |
| 285 | - // --------- | |
| 285 | + // --------- | |
| 286 | 286 | |
| 287 | - // usernames | |
| 287 | + // usernames | |
| 288 | 288 | |
| 289 | - // --------- | |
| 289 | + // --------- | |
| 290 | 290 | |
| 291 | - // get mapping of user IDs to usernames | |
| 291 | + // get mapping of user IDs to usernames | |
| 292 | 292 | |
| 293 | -    $memberHandler = xoops_getHandler('member'); | |
| 293 | +	$memberHandler = xoops_getHandler('member'); | |
| 294 | 294 | |
| 295 | -    $criteria = new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'); | |
| 295 | +	$criteria = new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'); | |
| 296 | 296 | |
| 297 | - $usernames = $memberHandler->getUserList($criteria); | |
| 297 | + $usernames = $memberHandler->getUserList($criteria); | |
| 298 | 298 | |
| 299 | - // add usernames to $games | |
| 299 | + // add usernames to $games | |
| 300 | 300 | |
| 301 | -    foreach ($games as $k => $game) { | |
| 302 | - $games[$k]['white_uname'] = $usernames[$game['white_uid']] ?? '?'; | |
| 301 | +	foreach ($games as $k => $game) { | |
| 302 | + $games[$k]['white_uname'] = $usernames[$game['white_uid']] ?? '?'; | |
| 303 | 303 | |
| 304 | - $games[$k]['black_uname'] = $usernames[$game['black_uid']] ?? '?'; | |
| 305 | - } | |
| 304 | + $games[$k]['black_uname'] = $usernames[$game['black_uid']] ?? '?'; | |
| 305 | + } | |
| 306 | 306 | |
| 307 | - // add usernames to $challenges | |
| 307 | + // add usernames to $challenges | |
| 308 | 308 | |
| 309 | -    foreach ($challenges as $k => $challenge) { | |
| 310 | - $challenges[$k]['player1_uname'] = $usernames[$challenge['player1_uid']] ?? '?'; | |
| 309 | +	foreach ($challenges as $k => $challenge) { | |
| 310 | + $challenges[$k]['player1_uname'] = $usernames[$challenge['player1_uid']] ?? '?'; | |
| 311 | 311 | |
| 312 | - $challenges[$k]['player2_uname'] = $usernames[$challenge['player2_uid']] ?? '?'; | |
| 313 | - } | |
| 312 | + $challenges[$k]['player2_uname'] = $usernames[$challenge['player2_uid']] ?? '?'; | |
| 313 | + } | |
| 314 | 314 | |
| 315 | - // --------------------------------------------------- | |
| 315 | + // --------------------------------------------------- | |
| 316 | 316 | |
| 317 | - // player's rating info (if rating feature is enabled) | |
| 317 | + // player's rating info (if rating feature is enabled) | |
| 318 | 318 | |
| 319 | - // --------------------------------------------------- | |
| 319 | + // --------------------------------------------------- | |
| 320 | 320 | |
| 321 | -    if ('none' != $rating_system) { | |
| 322 | - $result = $xoopsDB->query( | |
| 323 | - " | |
| 321 | +	if ('none' != $rating_system) { | |
| 322 | + $result = $xoopsDB->query( | |
| 323 | + " | |
| 324 | 324 | SELECT player_uid, rating, games_won, games_lost, games_drawn, (games_won+games_lost+games_drawn) AS games_played | 
| 325 | 325 | FROM $ratings_table | 
| 326 | 326 | ORDER BY rating DESC, player_uid ASC | 
| 327 | 327 | " | 
| 328 | - ); | |
| 328 | + ); | |
| 329 | 329 | |
| 330 | - $ranking = 0; | |
| 330 | + $ranking = 0; | |
| 331 | 331 | |
| 332 | -        while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 333 | -            if ($row['games_played'] >= $num_provisional_games) { | |
| 334 | - ++$ranking; | |
| 335 | - } | |
| 332 | +		while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 333 | +			if ($row['games_played'] >= $num_provisional_games) { | |
| 334 | + ++$ranking; | |
| 335 | + } | |
| 336 | 336 | |
| 337 | -            if ($row['player_uid'] == $player_uid) { | |
| 338 | - break; | |
| 339 | - } | |
| 340 | - } | |
| 337 | +			if ($row['player_uid'] == $player_uid) { | |
| 338 | + break; | |
| 339 | + } | |
| 340 | + } | |
| 341 | 341 | |
| 342 | - $xoopsDB->freeRecordSet($result); | |
| 342 | + $xoopsDB->freeRecordSet($result); | |
| 343 | 343 | |
| 344 | -        if ($row['player_uid'] == $player_uid) { | |
| 345 | - $player['ranking'] = $ranking; | |
| 344 | +		if ($row['player_uid'] == $player_uid) { | |
| 345 | + $player['ranking'] = $ranking; | |
| 346 | 346 | |
| 347 | - $player['rating'] = $row['rating']; | |
| 347 | + $player['rating'] = $row['rating']; | |
| 348 | 348 | |
| 349 | - $player['games_won'] = $row['games_won']; | |
| 349 | + $player['games_won'] = $row['games_won']; | |
| 350 | 350 | |
| 351 | - $player['games_lost'] = $row['games_lost']; | |
| 351 | + $player['games_lost'] = $row['games_lost']; | |
| 352 | 352 | |
| 353 | - $player['games_drawn'] = $row['games_drawn']; | |
| 353 | + $player['games_drawn'] = $row['games_drawn']; | |
| 354 | 354 | |
| 355 | - $player['games_played'] = $row['games_played']; | |
| 356 | - } | |
| 357 | - } | |
| 355 | + $player['games_played'] = $row['games_played']; | |
| 356 | + } | |
| 357 | + } | |
| 358 | 358 | |
| 359 | - // Template variables | |
| 359 | + // Template variables | |
| 360 | 360 | |
| 361 | - $player['games'] = $games; | |
| 361 | + $player['games'] = $games; | |
| 362 | 362 | |
| 363 | - $player['challenges'] = $challenges; | |
| 363 | + $player['challenges'] = $challenges; | |
| 364 | 364 | |
| 365 | -    $xoopsTpl->assign('chess_player', $player); | |
| 365 | +	$xoopsTpl->assign('chess_player', $player); | |
| 366 | 366 | |
| 367 | -    $xoopsTpl->assign('chess_rating_system', chess_moduleConfig('rating_system')); | |
| 367 | +	$xoopsTpl->assign('chess_rating_system', chess_moduleConfig('rating_system')); | |
| 368 | 368 | |
| 369 | -    $xoopsTpl->assign('chess_provisional_games', $num_provisional_games); | |
| 369 | +	$xoopsTpl->assign('chess_provisional_games', $num_provisional_games); | |
| 370 | 370 | |
| 371 | -    $xoopsTpl->assign('chess_show_option_urlparam', $show_option_urlparam); | |
| 371 | +	$xoopsTpl->assign('chess_show_option_urlparam', $show_option_urlparam); | |
| 372 | 372 | |
| 373 | -    $xoopsTpl->assign('chess_games_pagenav', $games_pagenav->renderNav()); | |
| 373 | +	$xoopsTpl->assign('chess_games_pagenav', $games_pagenav->renderNav()); | |
| 374 | 374 | |
| 375 | -    $xoopsTpl->assign('chess_challenges_pagenav', $challenges_pagenav->renderNav()); | |
| 375 | +	$xoopsTpl->assign('chess_challenges_pagenav', $challenges_pagenav->renderNav()); | |
| 376 | 376 | } | 
| @@ -35,4 +35,4 @@ | ||
| 35 | 35 | /**#@+ | 
| 36 | 36 | */ | 
| 37 | 37 | |
| 38 | -require dirname(__DIR__, 2) . '/mainfile.php'; | |
| 38 | +require dirname(__DIR__, 2).'/mainfile.php'; | |
| @@ -50,18 +50,18 @@ discard block | ||
| 50 | 50 | xoops_cp_header(); | 
| 51 | 51 | |
| 52 | 52 |  switch ($op) { | 
| 53 | - case 'suspended_games': | |
| 54 | - chess_admin_suspended_games(); | |
| 55 | - break; | |
| 56 | - case 'active_games': | |
| 57 | - chess_admin_active_games(); | |
| 58 | - break; | |
| 59 | - case 'challenges': | |
| 60 | - chess_admin_challenges(); | |
| 61 | - break; | |
| 62 | - default: | |
| 63 | - chess_admin_menu(); | |
| 64 | - break; | |
| 53 | + case 'suspended_games': | |
| 54 | + chess_admin_suspended_games(); | |
| 55 | + break; | |
| 56 | + case 'active_games': | |
| 57 | + chess_admin_active_games(); | |
| 58 | + break; | |
| 59 | + case 'challenges': | |
| 60 | + chess_admin_challenges(); | |
| 61 | + break; | |
| 62 | + default: | |
| 63 | + chess_admin_menu(); | |
| 64 | + break; | |
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | 67 | xoops_cp_footer(); | 
| @@ -72,30 +72,30 @@ discard block | ||
| 72 | 72 | */ | 
| 73 | 73 | function chess_admin_menu() | 
| 74 | 74 |  { | 
| 75 | - global $xoopsModule; | |
| 75 | + global $xoopsModule; | |
| 76 | 76 | |
| 77 | - echo ' | |
| 77 | + echo ' | |
| 78 | 78 | <h4> ' . _AM_CHESS_CONF . ' </h4>' | 
| 79 | - // <table width='100%' border='0' cellspacing='1' class='outer'> | |
| 80 | - // <tr> | |
| 81 | -        //        <td><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/admin/index.php?op=suspended_games'>" . _AM_CHESS_SUSPENDED_GAMES . '</a> | |
| 82 | - // <td>' . _AM_CHESS_SUSPENDED_GAMES_DES . "</td> | |
| 83 | - // </tr> | |
| 84 | - // <tr> | |
| 85 | -        //        <td><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/admin/index.php?op=active_games'>" . _AM_CHESS_ACTIVE_GAMES . '</a> | |
| 86 | - // <td>' . _AM_CHESS_ACTIVE_GAMES_DES . "</td> | |
| 87 | - // </tr> | |
| 88 | - // <tr> | |
| 89 | -        //        <td><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/admin/index.php?op=challenges'>" . _AM_CHESS_CHALLENGES . '</a> | |
| 90 | - // <td>' . _AM_CHESS_CHALLENGES_DES . "</td> | |
| 91 | - // </tr> | |
| 92 | - // <tr> | |
| 93 | -        //        <td><a href='" . XOOPS_URL . '/modules/system/admin.php?fct=preferences&op=showmod&mod=' . $xoopsModule->getVar('mid') . "'>" . _AM_CHESS_PREFS . '</a> | |
| 94 | - // <td>' . _AM_CHESS_PREFS_DESC . '</td> | |
| 95 | - // </tr> | |
| 96 | - // </table> | |
| 97 | - //' | |
| 98 | - ; | |
| 79 | + // <table width='100%' border='0' cellspacing='1' class='outer'> | |
| 80 | + // <tr> | |
| 81 | +		//        <td><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/admin/index.php?op=suspended_games'>" . _AM_CHESS_SUSPENDED_GAMES . '</a> | |
| 82 | + // <td>' . _AM_CHESS_SUSPENDED_GAMES_DES . "</td> | |
| 83 | + // </tr> | |
| 84 | + // <tr> | |
| 85 | +		//        <td><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/admin/index.php?op=active_games'>" . _AM_CHESS_ACTIVE_GAMES . '</a> | |
| 86 | + // <td>' . _AM_CHESS_ACTIVE_GAMES_DES . "</td> | |
| 87 | + // </tr> | |
| 88 | + // <tr> | |
| 89 | +		//        <td><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/admin/index.php?op=challenges'>" . _AM_CHESS_CHALLENGES . '</a> | |
| 90 | + // <td>' . _AM_CHESS_CHALLENGES_DES . "</td> | |
| 91 | + // </tr> | |
| 92 | + // <tr> | |
| 93 | +		//        <td><a href='" . XOOPS_URL . '/modules/system/admin.php?fct=preferences&op=showmod&mod=' . $xoopsModule->getVar('mid') . "'>" . _AM_CHESS_PREFS . '</a> | |
| 94 | + // <td>' . _AM_CHESS_PREFS_DESC . '</td> | |
| 95 | + // </tr> | |
| 96 | + // </table> | |
| 97 | + //' | |
| 98 | + ; | |
| 99 | 99 | } | 
| 100 | 100 | |
| 101 | 101 | /** | 
| @@ -103,103 +103,103 @@ discard block | ||
| 103 | 103 | */ | 
| 104 | 104 | function chess_admin_suspended_games() | 
| 105 | 105 |  { | 
| 106 | - global $start, $max_items_to_display, $op, $xoopsDB, $xoopsModule; | |
| 106 | + global $start, $max_items_to_display, $op, $xoopsDB, $xoopsModule; | |
| 107 | 107 | |
| 108 | -    $memberHandler = xoops_getHandler('member'); | |
| 108 | +	$memberHandler = xoops_getHandler('member'); | |
| 109 | 109 | |
| 110 | - // Two queries are performed, one without a limit clause to count the total number of rows for the page navigator, | |
| 110 | + // Two queries are performed, one without a limit clause to count the total number of rows for the page navigator, | |
| 111 | 111 | |
| 112 | - // and one with a limit clause to get the data for display on the current page. | |
| 112 | + // and one with a limit clause to get the data for display on the current page. | |
| 113 | 113 | |
| 114 | - // SQL_CALC_FOUND_ROWS and FOUND_ROWS(), available in MySQL 4.0.0, provide a more efficient way of doing this. | |
| 114 | + // SQL_CALC_FOUND_ROWS and FOUND_ROWS(), available in MySQL 4.0.0, provide a more efficient way of doing this. | |
| 115 | 115 | |
| 116 | -    $games_table = $xoopsDB->prefix('chess_games'); | |
| 116 | +	$games_table = $xoopsDB->prefix('chess_games'); | |
| 117 | 117 | |
| 118 | -    $result = $xoopsDB->query("SELECT COUNT(*) FROM $games_table WHERE suspended != ''"); | |
| 118 | +	$result = $xoopsDB->query("SELECT COUNT(*) FROM $games_table WHERE suspended != ''"); | |
| 119 | 119 | |
| 120 | - [$num_rows] = $xoopsDB->fetchRow($result); | |
| 120 | + [$num_rows] = $xoopsDB->fetchRow($result); | |
| 121 | 121 | |
| 122 | - $xoopsDB->freeRecordSet($result); | |
| 122 | + $xoopsDB->freeRecordSet($result); | |
| 123 | 123 | |
| 124 | - // Sort by date-suspended in ascending order, so that games that were suspended the earliest will be displayed | |
| 124 | + // Sort by date-suspended in ascending order, so that games that were suspended the earliest will be displayed | |
| 125 | 125 | |
| 126 | - // at the top, and can more easily be arbitrated on a first-come first-serve basis. | |
| 126 | + // at the top, and can more easily be arbitrated on a first-come first-serve basis. | |
| 127 | 127 | |
| 128 | - // Note that the suspended column begins with the date-suspended in the format 'YYYY-MM-DD HH:MM:SS', so the sorting | |
| 128 | + // Note that the suspended column begins with the date-suspended in the format 'YYYY-MM-DD HH:MM:SS', so the sorting | |
| 129 | 129 | |
| 130 | - // will work as desired. | |
| 130 | + // will work as desired. | |
| 131 | 131 | |
| 132 | - $result = $xoopsDB->query( | |
| 133 | - trim( | |
| 134 | - " | |
| 132 | + $result = $xoopsDB->query( | |
| 133 | + trim( | |
| 134 | + " | |
| 135 | 135 | SELECT game_id, white_uid, black_uid, UNIX_TIMESTAMP(start_date) AS start_date, suspended | 
| 136 | 136 | FROM $games_table | 
| 137 | 137 | WHERE suspended != '' | 
| 138 | 138 | ORDER BY suspended | 
| 139 | 139 | LIMIT $start, $max_items_to_display | 
| 140 | 140 | " | 
| 141 | - ) | |
| 142 | - ); | |
| 141 | + ) | |
| 142 | + ); | |
| 143 | 143 | |
| 144 | -    if ($xoopsDB->getRowsNum($result) > 0) { | |
| 145 | - echo '<h3>' . _AM_CHESS_SUSPENDED_GAMES . "</h3>\n"; | |
| 144 | +	if ($xoopsDB->getRowsNum($result) > 0) { | |
| 145 | + echo '<h3>' . _AM_CHESS_SUSPENDED_GAMES . "</h3>\n"; | |
| 146 | 146 | |
| 147 | -        while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 148 | - $user_white = $memberHandler->getUser($row['white_uid']); | |
| 147 | +		while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 148 | + $user_white = $memberHandler->getUser($row['white_uid']); | |
| 149 | 149 | |
| 150 | -            $username_white = is_object($user_white) ? $user_white->getVar('uname') : '(open)'; | |
| 150 | +			$username_white = is_object($user_white) ? $user_white->getVar('uname') : '(open)'; | |
| 151 | 151 | |
| 152 | - $user_black = $memberHandler->getUser($row['black_uid']); | |
| 152 | + $user_black = $memberHandler->getUser($row['black_uid']); | |
| 153 | 153 | |
| 154 | -            $username_black = is_object($user_black) ? $user_black->getVar('uname') : '(open)'; | |
| 154 | +			$username_black = is_object($user_black) ? $user_black->getVar('uname') : '(open)'; | |
| 155 | 155 | |
| 156 | -            $date = $row['start_date'] ? date('Y.m.d', $row['start_date']) : 'not yet started'; | |
| 156 | +			$date = $row['start_date'] ? date('Y.m.d', $row['start_date']) : 'not yet started'; | |
| 157 | 157 | |
| 158 | -            $title_text = _AM_CHESS_GAME . " #{$row['game_id']}   $username_white " . _AM_CHESS_VS . " $username_black   ($date)"; | |
| 158 | +			$title_text = _AM_CHESS_GAME . " #{$row['game_id']}   $username_white " . _AM_CHESS_VS . " $username_black   ($date)"; | |
| 159 | 159 | |
| 160 | -            $form = new XoopsThemeForm($title_text, "game_{$row['game_id']}", XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/game.php?game_id={$row['game_id']}", 'post', true); | |
| 160 | +			$form = new XoopsThemeForm($title_text, "game_{$row['game_id']}", XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/game.php?game_id={$row['game_id']}", 'post', true); | |
| 161 | 161 | |
| 162 | -            [$date, $suspender_uid, $type, $explain] = explode('|', $row['suspended']); | |
| 162 | +			[$date, $suspender_uid, $type, $explain] = explode('|', $row['suspended']); | |
| 163 | 163 | |
| 164 | -            switch ($type) { | |
| 165 | - case 'arbiter_suspend': | |
| 166 | - $type_display = _AM_CHESS_SUSP_TYPE_ARBITER; | |
| 167 | - break; | |
| 168 | - case 'want_arbitration': | |
| 169 | - $type_display = _AM_CHESS_SUSP_TYPE_PLAYER; | |
| 170 | - break; | |
| 171 | - default: | |
| 172 | - $type_display = _AM_CHESS_ERROR; | |
| 173 | - break; | |
| 174 | - } | |
| 164 | +			switch ($type) { | |
| 165 | + case 'arbiter_suspend': | |
| 166 | + $type_display = _AM_CHESS_SUSP_TYPE_ARBITER; | |
| 167 | + break; | |
| 168 | + case 'want_arbitration': | |
| 169 | + $type_display = _AM_CHESS_SUSP_TYPE_PLAYER; | |
| 170 | + break; | |
| 171 | + default: | |
| 172 | + $type_display = _AM_CHESS_ERROR; | |
| 173 | + break; | |
| 174 | + } | |
| 175 | 175 | |
| 176 | - $suspender_user = $memberHandler->getUser($suspender_uid); | |
| 176 | + $suspender_user = $memberHandler->getUser($suspender_uid); | |
| 177 | 177 | |
| 178 | -            $suspender_username = is_object($suspender_user) ? $suspender_user->getVar('uname') : _AM_CHESS_UNKNOWN_USER; | |
| 178 | +			$suspender_username = is_object($suspender_user) ? $suspender_user->getVar('uname') : _AM_CHESS_UNKNOWN_USER; | |
| 179 | 179 | |
| 180 | - $form->addElement(new XoopsFormLabel(_AM_CHESS_WHEN_SUSPENDED . ':', formatTimestamp(strtotime($date)))); | |
| 180 | + $form->addElement(new XoopsFormLabel(_AM_CHESS_WHEN_SUSPENDED . ':', formatTimestamp(strtotime($date)))); | |
| 181 | 181 | |
| 182 | - $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENDED_BY . ':', $suspender_username)); | |
| 182 | + $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENDED_BY . ':', $suspender_username)); | |
| 183 | 183 | |
| 184 | - $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENSION_TYPE . ':', $type_display)); | |
| 184 | + $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENSION_TYPE . ':', $type_display)); | |
| 185 | 185 | |
| 186 | - $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENSION_REASON . ':', $explain)); | |
| 186 | + $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENSION_REASON . ':', $explain)); | |
| 187 | 187 | |
| 188 | -            $form->addElement(new XoopsFormButton('', 'submit', _AM_CHESS_ARBITRATE_SUBMIT, 'submit')); | |
| 188 | +			$form->addElement(new XoopsFormButton('', 'submit', _AM_CHESS_ARBITRATE_SUBMIT, 'submit')); | |
| 189 | 189 | |
| 190 | -            $form->addElement(new XoopsFormHidden('show_arbiter_ctrl', 1)); | |
| 190 | +			$form->addElement(new XoopsFormHidden('show_arbiter_ctrl', 1)); | |
| 191 | 191 | |
| 192 | - $form->display(); | |
| 193 | - } | |
| 192 | + $form->display(); | |
| 193 | + } | |
| 194 | 194 | |
| 195 | - $pagenav = new XoopsPageNav($num_rows, $max_items_to_display, $start, 'start', "op=$op"); | |
| 195 | + $pagenav = new XoopsPageNav($num_rows, $max_items_to_display, $start, 'start', "op=$op"); | |
| 196 | 196 | |
| 197 | - echo '<div align="center">' . $pagenav->renderNav() . " </div>\n"; | |
| 198 | -    } else { | |
| 199 | - echo '<h3>' . _AM_CHESS_NO_SUSPENDED_GAMES . "</h3>\n"; | |
| 200 | - } | |
| 197 | + echo '<div align="center">' . $pagenav->renderNav() . " </div>\n"; | |
| 198 | +	} else { | |
| 199 | + echo '<h3>' . _AM_CHESS_NO_SUSPENDED_GAMES . "</h3>\n"; | |
| 200 | + } | |
| 201 | 201 | |
| 202 | - $xoopsDB->freeRecordSet($result); | |
| 202 | + $xoopsDB->freeRecordSet($result); | |
| 203 | 203 | } | 
| 204 | 204 | |
| 205 | 205 | /** | 
| @@ -207,69 +207,69 @@ discard block | ||
| 207 | 207 | */ | 
| 208 | 208 | function chess_admin_active_games() | 
| 209 | 209 |  { | 
| 210 | - global $start, $max_items_to_display, $op, $xoopsDB, $xoopsModule; | |
| 210 | + global $start, $max_items_to_display, $op, $xoopsDB, $xoopsModule; | |
| 211 | 211 | |
| 212 | -    $memberHandler = xoops_getHandler('member'); | |
| 212 | +	$memberHandler = xoops_getHandler('member'); | |
| 213 | 213 | |
| 214 | - // Two queries are performed, one without a limit clause to count the total number of rows for the page navigator, | |
| 214 | + // Two queries are performed, one without a limit clause to count the total number of rows for the page navigator, | |
| 215 | 215 | |
| 216 | - // and one with a limit clause to get the data for display on the current page. | |
| 216 | + // and one with a limit clause to get the data for display on the current page. | |
| 217 | 217 | |
| 218 | - // SQL_CALC_FOUND_ROWS and FOUND_ROWS(), available in MySQL 4.0.0, provide a more efficient way of doing this. | |
| 218 | + // SQL_CALC_FOUND_ROWS and FOUND_ROWS(), available in MySQL 4.0.0, provide a more efficient way of doing this. | |
| 219 | 219 | |
| 220 | -    $games_table = $xoopsDB->prefix('chess_games'); | |
| 220 | +	$games_table = $xoopsDB->prefix('chess_games'); | |
| 221 | 221 | |
| 222 | -    $result = $xoopsDB->query("SELECT COUNT(*) FROM $games_table WHERE pgn_result = '*' and suspended = ''"); | |
| 222 | +	$result = $xoopsDB->query("SELECT COUNT(*) FROM $games_table WHERE pgn_result = '*' and suspended = ''"); | |
| 223 | 223 | |
| 224 | - [$num_rows] = $xoopsDB->fetchRow($result); | |
| 224 | + [$num_rows] = $xoopsDB->fetchRow($result); | |
| 225 | 225 | |
| 226 | - $xoopsDB->freeRecordSet($result); | |
| 226 | + $xoopsDB->freeRecordSet($result); | |
| 227 | 227 | |
| 228 | - $result = $xoopsDB->query( | |
| 229 | - trim( | |
| 230 | - " | |
| 228 | + $result = $xoopsDB->query( | |
| 229 | + trim( | |
| 230 | + " | |
| 231 | 231 | SELECT game_id, white_uid, black_uid, UNIX_TIMESTAMP(start_date) AS start_date, GREATEST(create_date,start_date,last_date) AS most_recent_date | 
| 232 | 232 | FROM $games_table | 
| 233 | 233 | WHERE pgn_result = '*' and suspended = '' | 
| 234 | 234 | ORDER BY most_recent_date DESC | 
| 235 | 235 | LIMIT $start, $max_items_to_display | 
| 236 | 236 | " | 
| 237 | - ) | |
| 238 | - ); | |
| 237 | + ) | |
| 238 | + ); | |
| 239 | 239 | |
| 240 | -    if ($xoopsDB->getRowsNum($result) > 0) { | |
| 241 | - echo '<h3>' . _AM_CHESS_ACTIVE_GAMES . "</h3>\n"; | |
| 240 | +	if ($xoopsDB->getRowsNum($result) > 0) { | |
| 241 | + echo '<h3>' . _AM_CHESS_ACTIVE_GAMES . "</h3>\n"; | |
| 242 | 242 | |
| 243 | -        while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 244 | - $user_white = $memberHandler->getUser($row['white_uid']); | |
| 243 | +		while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 244 | + $user_white = $memberHandler->getUser($row['white_uid']); | |
| 245 | 245 | |
| 246 | -            $username_white = is_object($user_white) ? $user_white->getVar('uname') : '(open)'; | |
| 246 | +			$username_white = is_object($user_white) ? $user_white->getVar('uname') : '(open)'; | |
| 247 | 247 | |
| 248 | - $user_black = $memberHandler->getUser($row['black_uid']); | |
| 248 | + $user_black = $memberHandler->getUser($row['black_uid']); | |
| 249 | 249 | |
| 250 | -            $username_black = is_object($user_black) ? $user_black->getVar('uname') : '(open)'; | |
| 250 | +			$username_black = is_object($user_black) ? $user_black->getVar('uname') : '(open)'; | |
| 251 | 251 | |
| 252 | -            $date = $row['start_date'] ? date('Y.m.d', $row['start_date']) : 'not yet started'; | |
| 252 | +			$date = $row['start_date'] ? date('Y.m.d', $row['start_date']) : 'not yet started'; | |
| 253 | 253 | |
| 254 | -            $title_text = _AM_CHESS_GAME . " #{$row['game_id']}   $username_white " . _AM_CHESS_VS . " $username_black   ($date)"; | |
| 254 | +			$title_text = _AM_CHESS_GAME . " #{$row['game_id']}   $username_white " . _AM_CHESS_VS . " $username_black   ($date)"; | |
| 255 | 255 | |
| 256 | -            $form = new XoopsThemeForm($title_text, "game_{$row['game_id']}", XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/game.php?game_id={$row['game_id']}", 'post', true); | |
| 256 | +			$form = new XoopsThemeForm($title_text, "game_{$row['game_id']}", XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/game.php?game_id={$row['game_id']}", 'post', true); | |
| 257 | 257 | |
| 258 | -            $form->addElement(new XoopsFormButton('', 'submit', _AM_CHESS_ARBITRATE_SUBMIT, 'submit')); | |
| 258 | +			$form->addElement(new XoopsFormButton('', 'submit', _AM_CHESS_ARBITRATE_SUBMIT, 'submit')); | |
| 259 | 259 | |
| 260 | -            $form->addElement(new XoopsFormHidden('show_arbiter_ctrl', 1)); | |
| 260 | +			$form->addElement(new XoopsFormHidden('show_arbiter_ctrl', 1)); | |
| 261 | 261 | |
| 262 | - $form->display(); | |
| 263 | - } | |
| 262 | + $form->display(); | |
| 263 | + } | |
| 264 | 264 | |
| 265 | - $pagenav = new XoopsPageNav($num_rows, $max_items_to_display, $start, 'start', "op=$op"); | |
| 265 | + $pagenav = new XoopsPageNav($num_rows, $max_items_to_display, $start, 'start', "op=$op"); | |
| 266 | 266 | |
| 267 | - echo '<div align="center">' . $pagenav->renderNav() . " </div>\n"; | |
| 268 | -    } else { | |
| 269 | - echo '<h3>' . _AM_CHESS_NO_ACTIVE_GAMES . "</h3>\n"; | |
| 270 | - } | |
| 267 | + echo '<div align="center">' . $pagenav->renderNav() . " </div>\n"; | |
| 268 | +	} else { | |
| 269 | + echo '<h3>' . _AM_CHESS_NO_ACTIVE_GAMES . "</h3>\n"; | |
| 270 | + } | |
| 271 | 271 | |
| 272 | - $xoopsDB->freeRecordSet($result); | |
| 272 | + $xoopsDB->freeRecordSet($result); | |
| 273 | 273 | } | 
| 274 | 274 | |
| 275 | 275 | /** | 
| @@ -277,66 +277,66 @@ discard block | ||
| 277 | 277 | */ | 
| 278 | 278 | function chess_admin_challenges() | 
| 279 | 279 |  { | 
| 280 | - global $start, $max_items_to_display, $op, $xoopsDB, $xoopsModule; | |
| 280 | + global $start, $max_items_to_display, $op, $xoopsDB, $xoopsModule; | |
| 281 | 281 | |
| 282 | -    $memberHandler = xoops_getHandler('member'); | |
| 282 | +	$memberHandler = xoops_getHandler('member'); | |
| 283 | 283 | |
| 284 | - // Two queries are performed, one without a limit clause to count the total number of rows for the page navigator, | |
| 284 | + // Two queries are performed, one without a limit clause to count the total number of rows for the page navigator, | |
| 285 | 285 | |
| 286 | - // and one with a limit clause to get the data for display on the current page. | |
| 286 | + // and one with a limit clause to get the data for display on the current page. | |
| 287 | 287 | |
| 288 | - // SQL_CALC_FOUND_ROWS and FOUND_ROWS(), available in MySQL 4.0.0, provide a more efficient way of doing this. | |
| 288 | + // SQL_CALC_FOUND_ROWS and FOUND_ROWS(), available in MySQL 4.0.0, provide a more efficient way of doing this. | |
| 289 | 289 | |
| 290 | -    $challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 290 | +	$challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 291 | 291 | |
| 292 | -    $result = $xoopsDB->query("SELECT COUNT(*) FROM $challenges_table"); | |
| 292 | +	$result = $xoopsDB->query("SELECT COUNT(*) FROM $challenges_table"); | |
| 293 | 293 | |
| 294 | - [$num_rows] = $xoopsDB->fetchRow($result); | |
| 294 | + [$num_rows] = $xoopsDB->fetchRow($result); | |
| 295 | 295 | |
| 296 | - $xoopsDB->freeRecordSet($result); | |
| 296 | + $xoopsDB->freeRecordSet($result); | |
| 297 | 297 | |
| 298 | - $result = $xoopsDB->query( | |
| 299 | - trim( | |
| 300 | - " | |
| 298 | + $result = $xoopsDB->query( | |
| 299 | + trim( | |
| 300 | + " | |
| 301 | 301 | SELECT challenge_id, game_type, color_option, player1_uid, player2_uid, UNIX_TIMESTAMP(create_date) AS create_date | 
| 302 | 302 | FROM $challenges_table | 
| 303 | 303 | ORDER BY create_date DESC | 
| 304 | 304 | LIMIT $start, $max_items_to_display | 
| 305 | 305 | " | 
| 306 | - ) | |
| 307 | - ); | |
| 306 | + ) | |
| 307 | + ); | |
| 308 | 308 | |
| 309 | -    if ($xoopsDB->getRowsNum($result) > 0) { | |
| 310 | - echo '<h3>' . _AM_CHESS_CHALLENGES . "</h3>\n"; | |
| 309 | +	if ($xoopsDB->getRowsNum($result) > 0) { | |
| 310 | + echo '<h3>' . _AM_CHESS_CHALLENGES . "</h3>\n"; | |
| 311 | 311 | |
| 312 | -        while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 313 | - $user_player1 = $memberHandler->getUser($row['player1_uid']); | |
| 312 | +		while (false !== ($row = $xoopsDB->fetchArray($result))) { | |
| 313 | + $user_player1 = $memberHandler->getUser($row['player1_uid']); | |
| 314 | 314 | |
| 315 | -            $username_player1 = is_object($user_player1) ? $user_player1->getVar('uname') : '?'; | |
| 315 | +			$username_player1 = is_object($user_player1) ? $user_player1->getVar('uname') : '?'; | |
| 316 | 316 | |
| 317 | - $user_player2 = $memberHandler->getUser($row['player2_uid']); | |
| 317 | + $user_player2 = $memberHandler->getUser($row['player2_uid']); | |
| 318 | 318 | |
| 319 | -            $username_player2 = is_object($user_player2) ? $user_player2->getVar('uname') : '(open)'; | |
| 319 | +			$username_player2 = is_object($user_player2) ? $user_player2->getVar('uname') : '(open)'; | |
| 320 | 320 | |
| 321 | -            $date = date('Y.m.d', $row['create_date']); | |
| 321 | +			$date = date('Y.m.d', $row['create_date']); | |
| 322 | 322 | |
| 323 | -            $title_text = _AM_CHESS_CHALLENGE . " #{$row['challenge_id']}   $username_player1 " . _AM_CHESS_CHALLENGED . ": $username_player2   (" . _AM_CHESS_CREATED . " $date)"; | |
| 323 | +			$title_text = _AM_CHESS_CHALLENGE . " #{$row['challenge_id']}   $username_player1 " . _AM_CHESS_CHALLENGED . ": $username_player2   (" . _AM_CHESS_CREATED . " $date)"; | |
| 324 | 324 | |
| 325 | -            $form = new XoopsThemeForm($title_text, "challenge_{$row['challenge_id']}", XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/create.php?challenge_id={$row['challenge_id']}", 'post', true); | |
| 325 | +			$form = new XoopsThemeForm($title_text, "challenge_{$row['challenge_id']}", XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/create.php?challenge_id={$row['challenge_id']}", 'post', true); | |
| 326 | 326 | |
| 327 | -            $form->addElement(new XoopsFormButton('', 'submit', _AM_CHESS_ARBITRATE_SUBMIT, 'submit')); | |
| 327 | +			$form->addElement(new XoopsFormButton('', 'submit', _AM_CHESS_ARBITRATE_SUBMIT, 'submit')); | |
| 328 | 328 | |
| 329 | -            $form->addElement(new XoopsFormHidden('show_arbiter_ctrl', 1)); | |
| 329 | +			$form->addElement(new XoopsFormHidden('show_arbiter_ctrl', 1)); | |
| 330 | 330 | |
| 331 | - $form->display(); | |
| 332 | - } | |
| 331 | + $form->display(); | |
| 332 | + } | |
| 333 | 333 | |
| 334 | - $pagenav = new XoopsPageNav($num_rows, $max_items_to_display, $start, 'start', "op=$op"); | |
| 334 | + $pagenav = new XoopsPageNav($num_rows, $max_items_to_display, $start, 'start', "op=$op"); | |
| 335 | 335 | |
| 336 | - echo '<div align="center">' . $pagenav->renderNav() . " </div>\n"; | |
| 337 | -    } else { | |
| 338 | - echo '<h3>' . _AM_CHESS_NO_CHALLENGES . "</h3>\n"; | |
| 339 | - } | |
| 336 | + echo '<div align="center">' . $pagenav->renderNav() . " </div>\n"; | |
| 337 | +	} else { | |
| 338 | + echo '<h3>' . _AM_CHESS_NO_CHALLENGES . "</h3>\n"; | |
| 339 | + } | |
| 340 | 340 | |
| 341 | - $xoopsDB->freeRecordSet($result); | |
| 341 | + $xoopsDB->freeRecordSet($result); | |
| 342 | 342 | } | 
| @@ -34,14 +34,14 @@ discard block | ||
| 34 | 34 | |
| 35 | 35 | /**#@+ | 
| 36 | 36 | */ | 
| 37 | -require_once __DIR__ . '/admin_header.php'; | |
| 38 | -require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; | |
| 39 | -require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; | |
| 40 | -require_once XOOPS_ROOT_PATH . '/modules/chess/include/functions.php'; | |
| 37 | +require_once __DIR__.'/admin_header.php'; | |
| 38 | +require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; | |
| 39 | +require_once XOOPS_ROOT_PATH.'/class/pagenav.php'; | |
| 40 | +require_once XOOPS_ROOT_PATH.'/modules/chess/include/functions.php'; | |
| 41 | 41 | |
| 42 | 42 | // user input | 
| 43 | 43 | $op = chess_sanitize(@$_GET['op']); | 
| 44 | -$start = (int)@$_GET['start']; // offset of first row of table to display (default to 0) | |
| 44 | +$start = (int) @$_GET['start']; // offset of first row of table to display (default to 0) | |
| 45 | 45 | |
| 46 | 46 | // get maximum number of items to display on a page, and constrain it to a reasonable value | 
| 47 | 47 |  $max_items_to_display = chess_moduleConfig('max_items'); | 
| @@ -75,7 +75,7 @@ discard block | ||
| 75 | 75 | global $xoopsModule; | 
| 76 | 76 | |
| 77 | 77 | echo ' | 
| 78 | - <h4> ' . _AM_CHESS_CONF . ' </h4>' | |
| 78 | + <h4> ' . _AM_CHESS_CONF.' </h4>' | |
| 79 | 79 | // <table width='100%' border='0' cellspacing='1' class='outer'> | 
| 80 | 80 | // <tr> | 
| 81 | 81 |          //        <td><a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/admin/index.php?op=suspended_games'>" . _AM_CHESS_SUSPENDED_GAMES . '</a> | 
| @@ -142,7 +142,7 @@ discard block | ||
| 142 | 142 | ); | 
| 143 | 143 | |
| 144 | 144 |      if ($xoopsDB->getRowsNum($result) > 0) { | 
| 145 | - echo '<h3>' . _AM_CHESS_SUSPENDED_GAMES . "</h3>\n"; | |
| 145 | + echo '<h3>'._AM_CHESS_SUSPENDED_GAMES."</h3>\n"; | |
| 146 | 146 | |
| 147 | 147 |          while (false !== ($row = $xoopsDB->fetchArray($result))) { | 
| 148 | 148 | $user_white = $memberHandler->getUser($row['white_uid']); | 
| @@ -155,9 +155,9 @@ discard block | ||
| 155 | 155 | |
| 156 | 156 |              $date = $row['start_date'] ? date('Y.m.d', $row['start_date']) : 'not yet started'; | 
| 157 | 157 | |
| 158 | -            $title_text = _AM_CHESS_GAME . " #{$row['game_id']}   $username_white " . _AM_CHESS_VS . " $username_black   ($date)"; | |
| 158 | +            $title_text = _AM_CHESS_GAME." #{$row['game_id']}   $username_white "._AM_CHESS_VS." $username_black   ($date)"; | |
| 159 | 159 | |
| 160 | -            $form = new XoopsThemeForm($title_text, "game_{$row['game_id']}", XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/game.php?game_id={$row['game_id']}", 'post', true); | |
| 160 | +            $form = new XoopsThemeForm($title_text, "game_{$row['game_id']}", XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/game.php?game_id={$row['game_id']}", 'post', true); | |
| 161 | 161 | |
| 162 | 162 |              [$date, $suspender_uid, $type, $explain] = explode('|', $row['suspended']); | 
| 163 | 163 | |
| @@ -177,13 +177,13 @@ discard block | ||
| 177 | 177 | |
| 178 | 178 |              $suspender_username = is_object($suspender_user) ? $suspender_user->getVar('uname') : _AM_CHESS_UNKNOWN_USER; | 
| 179 | 179 | |
| 180 | - $form->addElement(new XoopsFormLabel(_AM_CHESS_WHEN_SUSPENDED . ':', formatTimestamp(strtotime($date)))); | |
| 180 | + $form->addElement(new XoopsFormLabel(_AM_CHESS_WHEN_SUSPENDED.':', formatTimestamp(strtotime($date)))); | |
| 181 | 181 | |
| 182 | - $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENDED_BY . ':', $suspender_username)); | |
| 182 | + $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENDED_BY.':', $suspender_username)); | |
| 183 | 183 | |
| 184 | - $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENSION_TYPE . ':', $type_display)); | |
| 184 | + $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENSION_TYPE.':', $type_display)); | |
| 185 | 185 | |
| 186 | - $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENSION_REASON . ':', $explain)); | |
| 186 | + $form->addElement(new XoopsFormLabel(_AM_CHESS_SUSPENSION_REASON.':', $explain)); | |
| 187 | 187 | |
| 188 | 188 |              $form->addElement(new XoopsFormButton('', 'submit', _AM_CHESS_ARBITRATE_SUBMIT, 'submit')); | 
| 189 | 189 | |
| @@ -194,9 +194,9 @@ discard block | ||
| 194 | 194 | |
| 195 | 195 | $pagenav = new XoopsPageNav($num_rows, $max_items_to_display, $start, 'start', "op=$op"); | 
| 196 | 196 | |
| 197 | - echo '<div align="center">' . $pagenav->renderNav() . " </div>\n"; | |
| 197 | + echo '<div align="center">'.$pagenav->renderNav()." </div>\n"; | |
| 198 | 198 |      } else { | 
| 199 | - echo '<h3>' . _AM_CHESS_NO_SUSPENDED_GAMES . "</h3>\n"; | |
| 199 | + echo '<h3>'._AM_CHESS_NO_SUSPENDED_GAMES."</h3>\n"; | |
| 200 | 200 | } | 
| 201 | 201 | |
| 202 | 202 | $xoopsDB->freeRecordSet($result); | 
| @@ -238,7 +238,7 @@ discard block | ||
| 238 | 238 | ); | 
| 239 | 239 | |
| 240 | 240 |      if ($xoopsDB->getRowsNum($result) > 0) { | 
| 241 | - echo '<h3>' . _AM_CHESS_ACTIVE_GAMES . "</h3>\n"; | |
| 241 | + echo '<h3>'._AM_CHESS_ACTIVE_GAMES."</h3>\n"; | |
| 242 | 242 | |
| 243 | 243 |          while (false !== ($row = $xoopsDB->fetchArray($result))) { | 
| 244 | 244 | $user_white = $memberHandler->getUser($row['white_uid']); | 
| @@ -251,9 +251,9 @@ discard block | ||
| 251 | 251 | |
| 252 | 252 |              $date = $row['start_date'] ? date('Y.m.d', $row['start_date']) : 'not yet started'; | 
| 253 | 253 | |
| 254 | -            $title_text = _AM_CHESS_GAME . " #{$row['game_id']}   $username_white " . _AM_CHESS_VS . " $username_black   ($date)"; | |
| 254 | +            $title_text = _AM_CHESS_GAME." #{$row['game_id']}   $username_white "._AM_CHESS_VS." $username_black   ($date)"; | |
| 255 | 255 | |
| 256 | -            $form = new XoopsThemeForm($title_text, "game_{$row['game_id']}", XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/game.php?game_id={$row['game_id']}", 'post', true); | |
| 256 | +            $form = new XoopsThemeForm($title_text, "game_{$row['game_id']}", XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/game.php?game_id={$row['game_id']}", 'post', true); | |
| 257 | 257 | |
| 258 | 258 |              $form->addElement(new XoopsFormButton('', 'submit', _AM_CHESS_ARBITRATE_SUBMIT, 'submit')); | 
| 259 | 259 | |
| @@ -264,9 +264,9 @@ discard block | ||
| 264 | 264 | |
| 265 | 265 | $pagenav = new XoopsPageNav($num_rows, $max_items_to_display, $start, 'start', "op=$op"); | 
| 266 | 266 | |
| 267 | - echo '<div align="center">' . $pagenav->renderNav() . " </div>\n"; | |
| 267 | + echo '<div align="center">'.$pagenav->renderNav()." </div>\n"; | |
| 268 | 268 |      } else { | 
| 269 | - echo '<h3>' . _AM_CHESS_NO_ACTIVE_GAMES . "</h3>\n"; | |
| 269 | + echo '<h3>'._AM_CHESS_NO_ACTIVE_GAMES."</h3>\n"; | |
| 270 | 270 | } | 
| 271 | 271 | |
| 272 | 272 | $xoopsDB->freeRecordSet($result); | 
| @@ -307,7 +307,7 @@ discard block | ||
| 307 | 307 | ); | 
| 308 | 308 | |
| 309 | 309 |      if ($xoopsDB->getRowsNum($result) > 0) { | 
| 310 | - echo '<h3>' . _AM_CHESS_CHALLENGES . "</h3>\n"; | |
| 310 | + echo '<h3>'._AM_CHESS_CHALLENGES."</h3>\n"; | |
| 311 | 311 | |
| 312 | 312 |          while (false !== ($row = $xoopsDB->fetchArray($result))) { | 
| 313 | 313 | $user_player1 = $memberHandler->getUser($row['player1_uid']); | 
| @@ -320,9 +320,9 @@ discard block | ||
| 320 | 320 | |
| 321 | 321 |              $date = date('Y.m.d', $row['create_date']); | 
| 322 | 322 | |
| 323 | -            $title_text = _AM_CHESS_CHALLENGE . " #{$row['challenge_id']}   $username_player1 " . _AM_CHESS_CHALLENGED . ": $username_player2   (" . _AM_CHESS_CREATED . " $date)"; | |
| 323 | +            $title_text = _AM_CHESS_CHALLENGE." #{$row['challenge_id']}   $username_player1 "._AM_CHESS_CHALLENGED.": $username_player2   ("._AM_CHESS_CREATED." $date)"; | |
| 324 | 324 | |
| 325 | -            $form = new XoopsThemeForm($title_text, "challenge_{$row['challenge_id']}", XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/create.php?challenge_id={$row['challenge_id']}", 'post', true); | |
| 325 | +            $form = new XoopsThemeForm($title_text, "challenge_{$row['challenge_id']}", XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/create.php?challenge_id={$row['challenge_id']}", 'post', true); | |
| 326 | 326 | |
| 327 | 327 |              $form->addElement(new XoopsFormButton('', 'submit', _AM_CHESS_ARBITRATE_SUBMIT, 'submit')); | 
| 328 | 328 | |
| @@ -333,9 +333,9 @@ discard block | ||
| 333 | 333 | |
| 334 | 334 | $pagenav = new XoopsPageNav($num_rows, $max_items_to_display, $start, 'start', "op=$op"); | 
| 335 | 335 | |
| 336 | - echo '<div align="center">' . $pagenav->renderNav() . " </div>\n"; | |
| 336 | + echo '<div align="center">'.$pagenav->renderNav()." </div>\n"; | |
| 337 | 337 |      } else { | 
| 338 | - echo '<h3>' . _AM_CHESS_NO_CHALLENGES . "</h3>\n"; | |
| 338 | + echo '<h3>'._AM_CHESS_NO_CHALLENGES."</h3>\n"; | |
| 339 | 339 | } | 
| 340 | 340 | |
| 341 | 341 | $xoopsDB->freeRecordSet($result); | 
| @@ -66,402 +66,402 @@ discard block | ||
| 66 | 66 | */ | 
| 67 | 67 | function chess_game() | 
| 68 | 68 |  { | 
| 69 | - // user input | |
| 69 | + // user input | |
| 70 | 70 | |
| 71 | - $game_id = (int)@$_GET['game_id']; | |
| 71 | + $game_id = (int)@$_GET['game_id']; | |
| 72 | 72 | |
| 73 | - $submit_move = isset($_POST['submit_move']); | |
| 73 | + $submit_move = isset($_POST['submit_move']); | |
| 74 | 74 | |
| 75 | - $submit_refresh = isset($_POST['submit_refresh']); | |
| 75 | + $submit_refresh = isset($_POST['submit_refresh']); | |
| 76 | 76 | |
| 77 | - $move = chess_sanitize(trim(@$_POST['chessmove']), 'A-Za-z0-9=-'); | |
| 77 | + $move = chess_sanitize(trim(@$_POST['chessmove']), 'A-Za-z0-9=-'); | |
| 78 | 78 | |
| 79 | - $movetype = chess_sanitize(@$_POST['movetype']); | |
| 79 | + $movetype = chess_sanitize(@$_POST['movetype']); | |
| 80 | 80 | |
| 81 | - $confirm = isset($_POST['confirm']) ? 1 : 0; | |
| 81 | + $confirm = isset($_POST['confirm']) ? 1 : 0; | |
| 82 | 82 | |
| 83 | - $move_explain = chess_sanitize(trim(@$_POST['move_explain']), 'A-Za-z0-9 .,;:=()[]*?!-'); | |
| 83 | + $move_explain = chess_sanitize(trim(@$_POST['move_explain']), 'A-Za-z0-9 .,;:=()[]*?!-'); | |
| 84 | 84 | |
| 85 | - $arbiter_explain = chess_sanitize(trim(@$_POST['arbiter_explain']), 'A-Za-z0-9 .,;:=()[]*?!-'); | |
| 85 | + $arbiter_explain = chess_sanitize(trim(@$_POST['arbiter_explain']), 'A-Za-z0-9 .,;:=()[]*?!-'); | |
| 86 | 86 | |
| 87 | - $orientation = chess_sanitize(@$_POST['orientation']); | |
| 87 | + $orientation = chess_sanitize(@$_POST['orientation']); | |
| 88 | 88 | |
| 89 | - $show_arbiter_ctrl = isset($_POST['show_arbiter_ctrl']); | |
| 89 | + $show_arbiter_ctrl = isset($_POST['show_arbiter_ctrl']); | |
| 90 | 90 | |
| 91 | - $submit_arbitrate = isset($_POST['submit_arbitrate']); | |
| 91 | + $submit_arbitrate = isset($_POST['submit_arbitrate']); | |
| 92 | 92 | |
| 93 | - $arbiter_action = chess_sanitize(@$_POST['arbiter_action']); | |
| 93 | + $arbiter_action = chess_sanitize(@$_POST['arbiter_action']); | |
| 94 | 94 | |
| 95 | - // If form-submit, check security token. | |
| 95 | + // If form-submit, check security token. | |
| 96 | 96 | |
| 97 | -    if (($submit_move || $submit_refresh || $submit_arbitrate || $show_arbiter_ctrl) && is_object($GLOBALS['xoopsSecurity']) && !$GLOBALS['xoopsSecurity']->check()) { | |
| 98 | - redirect_header( | |
| 99 | - XOOPS_URL . '/modules/chess/', | |
| 100 | - _CHESS_REDIRECT_DELAY_FAILURE, | |
| 101 | -            _MD_CHESS_TOKEN_ERROR . '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()) | |
| 102 | - ); | |
| 103 | - } | |
| 97 | +	if (($submit_move || $submit_refresh || $submit_arbitrate || $show_arbiter_ctrl) && is_object($GLOBALS['xoopsSecurity']) && !$GLOBALS['xoopsSecurity']->check()) { | |
| 98 | + redirect_header( | |
| 99 | + XOOPS_URL . '/modules/chess/', | |
| 100 | + _CHESS_REDIRECT_DELAY_FAILURE, | |
| 101 | +			_MD_CHESS_TOKEN_ERROR . '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()) | |
| 102 | + ); | |
| 103 | + } | |
| 104 | 104 | |
| 105 | - // Fetch the game data from the database. | |
| 105 | + // Fetch the game data from the database. | |
| 106 | 106 | |
| 107 | - $gamedata = chess_get_game($game_id); | |
| 107 | + $gamedata = chess_get_game($game_id); | |
| 108 | 108 | |
| 109 | -    if (false === $gamedata) { | |
| 110 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 111 | - } | |
| 109 | +	if (false === $gamedata) { | |
| 110 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 111 | + } | |
| 112 | 112 | |
| 113 | - $gamedata_updated = false; | |
| 113 | + $gamedata_updated = false; | |
| 114 | 114 | |
| 115 | - $move_performed = false; // status result from move-handler | |
| 116 | - $move_result_text = ''; // text result from move-handler | |
| 117 | - $draw_claim_error_text = ''; // text describing invalid draw-claim | |
| 118 | - $notify = ''; // text description of action for notification | |
| 119 | - $delete_game = false; | |
| 115 | + $move_performed = false; // status result from move-handler | |
| 116 | + $move_result_text = ''; // text result from move-handler | |
| 117 | + $draw_claim_error_text = ''; // text describing invalid draw-claim | |
| 118 | + $notify = ''; // text description of action for notification | |
| 119 | + $delete_game = false; | |
| 120 | 120 | |
| 121 | - global $xoopsUser; | |
| 121 | + global $xoopsUser; | |
| 122 | 122 | |
| 123 | -    $uid = $xoopsUser ? $xoopsUser->getVar('uid') : 0; | |
| 123 | +	$uid = $xoopsUser ? $xoopsUser->getVar('uid') : 0; | |
| 124 | 124 | |
| 125 | - $selfplay = $gamedata['white_uid'] == $gamedata['black_uid']; | |
| 125 | + $selfplay = $gamedata['white_uid'] == $gamedata['black_uid']; | |
| 126 | 126 | |
| 127 | -    if ($selfplay) { | |
| 128 | -        if ($uid == $gamedata['white_uid']) { | |
| 129 | - $user_color = $gamedata['fen_active_color']; // current user is either player, so consider him active player | |
| 130 | -        } else { | |
| 131 | - $user_color = ''; // current user is not a player | |
| 132 | - } | |
| 133 | - // not self-play | |
| 134 | -    } else { | |
| 135 | -        if ($uid == $gamedata['white_uid']) { | |
| 136 | - $user_color = 'w'; // current user is white | |
| 137 | -        } elseif ($uid == $gamedata['black_uid']) { | |
| 138 | - $user_color = 'b'; // current user is black | |
| 139 | -        } else { | |
| 140 | - $user_color = ''; // current user is not a player | |
| 141 | - } | |
| 142 | - } | |
| 127 | +	if ($selfplay) { | |
| 128 | +		if ($uid == $gamedata['white_uid']) { | |
| 129 | + $user_color = $gamedata['fen_active_color']; // current user is either player, so consider him active player | |
| 130 | +		} else { | |
| 131 | + $user_color = ''; // current user is not a player | |
| 132 | + } | |
| 133 | + // not self-play | |
| 134 | +	} else { | |
| 135 | +		if ($uid == $gamedata['white_uid']) { | |
| 136 | + $user_color = 'w'; // current user is white | |
| 137 | +		} elseif ($uid == $gamedata['black_uid']) { | |
| 138 | + $user_color = 'b'; // current user is black | |
| 139 | +		} else { | |
| 140 | + $user_color = ''; // current user is not a player | |
| 141 | + } | |
| 142 | + } | |
| 143 | 143 | |
| 144 | - // Determine whether current user is a player in the current game, and whether it's his move. | |
| 144 | + // Determine whether current user is a player in the current game, and whether it's his move. | |
| 145 | 145 | |
| 146 | - $user_is_player = 'w' == $user_color || 'b' == $user_color; | |
| 146 | + $user_is_player = 'w' == $user_color || 'b' == $user_color; | |
| 147 | 147 | |
| 148 | - $user_is_player_to_move = $user_color == $gamedata['fen_active_color']; | |
| 148 | + $user_is_player_to_move = $user_color == $gamedata['fen_active_color']; | |
| 149 | 149 | |
| 150 | - $user_color_name = 'w' == $user_color ? _MD_CHESS_WHITE : _MD_CHESS_BLACK; | |
| 150 | + $user_color_name = 'w' == $user_color ? _MD_CHESS_WHITE : _MD_CHESS_BLACK; | |
| 151 | 151 | |
| 152 | -    if ($submit_move && !$gamedata['suspended']) { | |
| 153 | - // If the player has changed his confirm-move preference, it needs to be updated in the database. | |
| 152 | +	if ($submit_move && !$gamedata['suspended']) { | |
| 153 | + // If the player has changed his confirm-move preference, it needs to be updated in the database. | |
| 154 | 154 | |
| 155 | - // For a self-play game, the white and black confirm-move preferences are kept the same, to avoid confusion. | |
| 155 | + // For a self-play game, the white and black confirm-move preferences are kept the same, to avoid confusion. | |
| 156 | 156 | |
| 157 | -        if ($user_is_player) { | |
| 158 | -            if ('w' == $user_color && $gamedata['white_confirm'] != $confirm) { | |
| 159 | - $gamedata['white_confirm'] = $confirm; | |
| 157 | +		if ($user_is_player) { | |
| 158 | +			if ('w' == $user_color && $gamedata['white_confirm'] != $confirm) { | |
| 159 | + $gamedata['white_confirm'] = $confirm; | |
| 160 | 160 | |
| 161 | -                if ($selfplay) { | |
| 162 | - $gamedata['black_confirm'] = $confirm; | |
| 163 | - } | |
| 161 | +				if ($selfplay) { | |
| 162 | + $gamedata['black_confirm'] = $confirm; | |
| 163 | + } | |
| 164 | 164 | |
| 165 | - $gamedata_updated = true; | |
| 166 | -            } elseif ('b' == $user_color && $gamedata['black_confirm'] != $confirm) { | |
| 167 | - $gamedata['black_confirm'] = $confirm; | |
| 165 | + $gamedata_updated = true; | |
| 166 | +			} elseif ('b' == $user_color && $gamedata['black_confirm'] != $confirm) { | |
| 167 | + $gamedata['black_confirm'] = $confirm; | |
| 168 | 168 | |
| 169 | -                if ($selfplay) { | |
| 170 | - $gamedata['white_confirm'] = $confirm; | |
| 171 | - } | |
| 169 | +				if ($selfplay) { | |
| 170 | + $gamedata['white_confirm'] = $confirm; | |
| 171 | + } | |
| 172 | 172 | |
| 173 | - $gamedata_updated = true; | |
| 174 | - } | |
| 175 | - } | |
| 173 | + $gamedata_updated = true; | |
| 174 | + } | |
| 175 | + } | |
| 176 | 176 | |
| 177 | -        switch ($movetype) { | |
| 178 | - default: | |
| 179 | - case _CHESS_MOVETYPE_NORMAL: | |
| 180 | -                if ($user_is_player_to_move && $gamedata['offer_draw'] != $user_color) { | |
| 181 | - [$move_performed, $move_result_text] = chess_move($gamedata, $move); | |
| 177 | +		switch ($movetype) { | |
| 178 | + default: | |
| 179 | + case _CHESS_MOVETYPE_NORMAL: | |
| 180 | +				if ($user_is_player_to_move && $gamedata['offer_draw'] != $user_color) { | |
| 181 | + [$move_performed, $move_result_text] = chess_move($gamedata, $move); | |
| 182 | 182 | |
| 183 | -                    if ($move_performed) { | |
| 184 | -                        if ($selfplay) { // If self-play, the current user's color switches. | |
| 185 | - $user_color = $gamedata['fen_active_color']; | |
| 186 | - } | |
| 183 | +					if ($move_performed) { | |
| 184 | +						if ($selfplay) { // If self-play, the current user's color switches. | |
| 185 | + $user_color = $gamedata['fen_active_color']; | |
| 186 | + } | |
| 187 | 187 | |
| 188 | - $gamedata['offer_draw'] = ''; | |
| 188 | + $gamedata['offer_draw'] = ''; | |
| 189 | 189 | |
| 190 | - $gamedata_updated = true; | |
| 190 | + $gamedata_updated = true; | |
| 191 | 191 | |
| 192 | - $notify = "$user_color_name: $move"; | |
| 193 | - } | |
| 194 | - } | |
| 195 | - break; | |
| 196 | - case _CHESS_MOVETYPE_CLAIM_DRAW_3: | |
| 197 | - case _CHESS_MOVETYPE_CLAIM_DRAW_50: | |
| 198 | -                if ($user_is_player_to_move && $gamedata['offer_draw'] != $user_color) { | |
| 199 | -                    if (!empty($move)) { | |
| 200 | - [$move_performed, $move_result_text] = chess_move($gamedata, $move); | |
| 192 | + $notify = "$user_color_name: $move"; | |
| 193 | + } | |
| 194 | + } | |
| 195 | + break; | |
| 196 | + case _CHESS_MOVETYPE_CLAIM_DRAW_3: | |
| 197 | + case _CHESS_MOVETYPE_CLAIM_DRAW_50: | |
| 198 | +				if ($user_is_player_to_move && $gamedata['offer_draw'] != $user_color) { | |
| 199 | +					if (!empty($move)) { | |
| 200 | + [$move_performed, $move_result_text] = chess_move($gamedata, $move); | |
| 201 | 201 | |
| 202 | -                        #var_dump('chess_game', $move_performed, $move_result_text);#*#DEBUG# | |
| 202 | +						#var_dump('chess_game', $move_performed, $move_result_text);#*#DEBUG# | |
| 203 | 203 | |
| 204 | -                        if ($move_performed) { | |
| 205 | -                            if ($selfplay) { // If self-play, the current user's color switches. | |
| 206 | - $user_color = $gamedata['fen_active_color']; | |
| 207 | - } | |
| 204 | +						if ($move_performed) { | |
| 205 | +							if ($selfplay) { // If self-play, the current user's color switches. | |
| 206 | + $user_color = $gamedata['fen_active_color']; | |
| 207 | + } | |
| 208 | 208 | |
| 209 | - $gamedata['offer_draw'] = ''; | |
| 209 | + $gamedata['offer_draw'] = ''; | |
| 210 | 210 | |
| 211 | - $gamedata_updated = true; | |
| 211 | + $gamedata_updated = true; | |
| 212 | 212 | |
| 213 | - $notify = "$user_color_name: $move"; | |
| 214 | -                        } else { | |
| 215 | - break; // move invalid, so don't bother checking draw-claim | |
| 216 | - } | |
| 217 | - } | |
| 213 | + $notify = "$user_color_name: $move"; | |
| 214 | +						} else { | |
| 215 | + break; // move invalid, so don't bother checking draw-claim | |
| 216 | + } | |
| 217 | + } | |
| 218 | 218 | |
| 219 | - [$draw_claim_valid, $draw_claim_text] = _CHESS_MOVETYPE_CLAIM_DRAW_3 == $movetype ? chess_is_draw_threefold_repetition($gamedata) : chess_is_draw_50_move_rule($gamedata); | |
| 219 | + [$draw_claim_valid, $draw_claim_text] = _CHESS_MOVETYPE_CLAIM_DRAW_3 == $movetype ? chess_is_draw_threefold_repetition($gamedata) : chess_is_draw_50_move_rule($gamedata); | |
| 220 | 220 | |
| 221 | -                    #var_dump('chess_game', $draw_claim_valid, $draw_claim_text);#*#DEBUG# | |
| 221 | +					#var_dump('chess_game', $draw_claim_valid, $draw_claim_text);#*#DEBUG# | |
| 222 | 222 | |
| 223 | -                    if ($draw_claim_valid) { | |
| 224 | - $gamedata['offer_draw'] = ''; | |
| 223 | +					if ($draw_claim_valid) { | |
| 224 | + $gamedata['offer_draw'] = ''; | |
| 225 | 225 | |
| 226 | - $gamedata['pgn_result'] = '1/2-1/2'; | |
| 226 | + $gamedata['pgn_result'] = '1/2-1/2'; | |
| 227 | 227 | |
| 228 | -                        $comment = '{' . $draw_claim_text . '}'; | |
| 228 | +						$comment = '{' . $draw_claim_text . '}'; | |
| 229 | 229 | |
| 230 | -                        $gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | |
| 230 | +						$gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | |
| 231 | 231 | |
| 232 | - $gamedata_updated = true; | |
| 232 | + $gamedata_updated = true; | |
| 233 | 233 | |
| 234 | - $notify = !empty($move) ? "$user_color_name: $move: $draw_claim_text" : "$user_color_name: $draw_claim_text"; | |
| 235 | -                    } else { | |
| 236 | - $draw_claim_error_text = $draw_claim_text; | |
| 237 | - } | |
| 238 | - } | |
| 239 | - break; | |
| 240 | - case _CHESS_MOVETYPE_RESIGN: | |
| 241 | -                if ($user_is_player) { | |
| 242 | - $gamedata['offer_draw'] = ''; | |
| 234 | + $notify = !empty($move) ? "$user_color_name: $move: $draw_claim_text" : "$user_color_name: $draw_claim_text"; | |
| 235 | +					} else { | |
| 236 | + $draw_claim_error_text = $draw_claim_text; | |
| 237 | + } | |
| 238 | + } | |
| 239 | + break; | |
| 240 | + case _CHESS_MOVETYPE_RESIGN: | |
| 241 | +				if ($user_is_player) { | |
| 242 | + $gamedata['offer_draw'] = ''; | |
| 243 | 243 | |
| 244 | - $gamedata['pgn_result'] = 'w' == $user_color ? '0-1' : '1-0'; | |
| 244 | + $gamedata['pgn_result'] = 'w' == $user_color ? '0-1' : '1-0'; | |
| 245 | 245 | |
| 246 | -                    $comment = '{' . $user_color_name . ' ' . _MD_CHESS_RESIGNED . '}'; | |
| 246 | +					$comment = '{' . $user_color_name . ' ' . _MD_CHESS_RESIGNED . '}'; | |
| 247 | 247 | |
| 248 | -                    $gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | |
| 248 | +					$gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | |
| 249 | 249 | |
| 250 | - $gamedata_updated = true; | |
| 250 | + $gamedata_updated = true; | |
| 251 | 251 | |
| 252 | - $notify = "$user_color_name " . _MD_CHESS_RESIGNED; | |
| 253 | - } | |
| 254 | - break; | |
| 255 | - case _CHESS_MOVETYPE_OFFER_DRAW: | |
| 256 | -                if ($user_is_player && empty($gamedata['offer_draw']) && !$selfplay) { | |
| 257 | - $gamedata['offer_draw'] = $user_color; | |
| 252 | + $notify = "$user_color_name " . _MD_CHESS_RESIGNED; | |
| 253 | + } | |
| 254 | + break; | |
| 255 | + case _CHESS_MOVETYPE_OFFER_DRAW: | |
| 256 | +				if ($user_is_player && empty($gamedata['offer_draw']) && !$selfplay) { | |
| 257 | + $gamedata['offer_draw'] = $user_color; | |
| 258 | 258 | |
| 259 | - $gamedata_updated = true; | |
| 259 | + $gamedata_updated = true; | |
| 260 | 260 | |
| 261 | - $notify = "$user_color_name " . _MD_CHESS_OFFERED_DRAW; | |
| 262 | - } | |
| 263 | - break; | |
| 264 | - case _CHESS_MOVETYPE_ACCEPT_DRAW: | |
| 265 | -                if ($user_is_player && !empty($gamedata['offer_draw']) && $gamedata['offer_draw'] != $user_color && !$selfplay) { | |
| 266 | - $gamedata['offer_draw'] = ''; | |
| 261 | + $notify = "$user_color_name " . _MD_CHESS_OFFERED_DRAW; | |
| 262 | + } | |
| 263 | + break; | |
| 264 | + case _CHESS_MOVETYPE_ACCEPT_DRAW: | |
| 265 | +				if ($user_is_player && !empty($gamedata['offer_draw']) && $gamedata['offer_draw'] != $user_color && !$selfplay) { | |
| 266 | + $gamedata['offer_draw'] = ''; | |
| 267 | 267 | |
| 268 | - $gamedata['pgn_result'] = '1/2-1/2'; | |
| 268 | + $gamedata['pgn_result'] = '1/2-1/2'; | |
| 269 | 269 | |
| 270 | -                    $comment = '{' . _MD_CHESS_DRAW_BY_AGREEMENT . '}'; | |
| 270 | +					$comment = '{' . _MD_CHESS_DRAW_BY_AGREEMENT . '}'; | |
| 271 | 271 | |
| 272 | -                    $gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | |
| 272 | +					$gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | |
| 273 | 273 | |
| 274 | - $gamedata_updated = true; | |
| 274 | + $gamedata_updated = true; | |
| 275 | 275 | |
| 276 | - $notify = "$user_color_name " . _MD_CHESS_ACCEPTED_DRAW; | |
| 277 | - } | |
| 276 | + $notify = "$user_color_name " . _MD_CHESS_ACCEPTED_DRAW; | |
| 277 | + } | |
| 278 | 278 | |
| 279 | - // no break | |
| 280 | - case _CHESS_MOVETYPE_REJECT_DRAW: | |
| 281 | -                if ($user_is_player && !empty($gamedata['offer_draw']) && $gamedata['offer_draw'] != $user_color && !$selfplay) { | |
| 282 | - $gamedata['offer_draw'] = ''; | |
| 279 | + // no break | |
| 280 | + case _CHESS_MOVETYPE_REJECT_DRAW: | |
| 281 | +				if ($user_is_player && !empty($gamedata['offer_draw']) && $gamedata['offer_draw'] != $user_color && !$selfplay) { | |
| 282 | + $gamedata['offer_draw'] = ''; | |
| 283 | 283 | |
| 284 | - $gamedata_updated = true; | |
| 284 | + $gamedata_updated = true; | |
| 285 | 285 | |
| 286 | - $notify = "$user_color_name " . _MD_CHESS_REJECTED_DRAW; | |
| 287 | - } | |
| 288 | - break; | |
| 289 | - case _CHESS_MOVETYPE_RESTART: | |
| 290 | -                if ($user_is_player && $selfplay) { | |
| 291 | - // instantiate a ChessGame to get a "fresh" gamestate | |
| 286 | + $notify = "$user_color_name " . _MD_CHESS_REJECTED_DRAW; | |
| 287 | + } | |
| 288 | + break; | |
| 289 | + case _CHESS_MOVETYPE_RESTART: | |
| 290 | +				if ($user_is_player && $selfplay) { | |
| 291 | + // instantiate a ChessGame to get a "fresh" gamestate | |
| 292 | 292 | |
| 293 | - $chessgame = new Chess\ChessGame($gamedata['pgn_fen']); | |
| 293 | + $chessgame = new Chess\ChessGame($gamedata['pgn_fen']); | |
| 294 | 294 | |
| 295 | - $new_gamestate = $chessgame->gamestate(); | |
| 295 | + $new_gamestate = $chessgame->gamestate(); | |
| 296 | 296 | |
| 297 | - // update the game data | |
| 297 | + // update the game data | |
| 298 | 298 | |
| 299 | - $gamedata['fen_piece_placement'] = $new_gamestate['fen_piece_placement']; | |
| 299 | + $gamedata['fen_piece_placement'] = $new_gamestate['fen_piece_placement']; | |
| 300 | 300 | |
| 301 | - $gamedata['fen_active_color'] = $new_gamestate['fen_active_color']; | |
| 301 | + $gamedata['fen_active_color'] = $new_gamestate['fen_active_color']; | |
| 302 | 302 | |
| 303 | - $gamedata['fen_castling_availability'] = $new_gamestate['fen_castling_availability']; | |
| 303 | + $gamedata['fen_castling_availability'] = $new_gamestate['fen_castling_availability']; | |
| 304 | 304 | |
| 305 | - $gamedata['fen_en_passant_target_square'] = $new_gamestate['fen_en_passant_target_square']; | |
| 305 | + $gamedata['fen_en_passant_target_square'] = $new_gamestate['fen_en_passant_target_square']; | |
| 306 | 306 | |
| 307 | - $gamedata['fen_halfmove_clock'] = $new_gamestate['fen_halfmove_clock']; | |
| 307 | + $gamedata['fen_halfmove_clock'] = $new_gamestate['fen_halfmove_clock']; | |
| 308 | 308 | |
| 309 | - $gamedata['fen_fullmove_number'] = $new_gamestate['fen_fullmove_number']; | |
| 309 | + $gamedata['fen_fullmove_number'] = $new_gamestate['fen_fullmove_number']; | |
| 310 | 310 | |
| 311 | - $gamedata['pgn_fen'] = $new_gamestate['pgn_fen']; | |
| 311 | + $gamedata['pgn_fen'] = $new_gamestate['pgn_fen']; | |
| 312 | 312 | |
| 313 | - $gamedata['pgn_result'] = $new_gamestate['pgn_result']; | |
| 313 | + $gamedata['pgn_result'] = $new_gamestate['pgn_result']; | |
| 314 | 314 | |
| 315 | - $gamedata['pgn_movetext'] = $new_gamestate['pgn_movetext']; | |
| 315 | + $gamedata['pgn_movetext'] = $new_gamestate['pgn_movetext']; | |
| 316 | 316 | |
| 317 | - // update user color | |
| 317 | + // update user color | |
| 318 | 318 | |
| 319 | - $user_color = $gamedata['fen_active_color']; | |
| 319 | + $user_color = $gamedata['fen_active_color']; | |
| 320 | 320 | |
| 321 | - $gamedata_updated = true; | |
| 322 | - } | |
| 323 | - break; | |
| 324 | - case _CHESS_MOVETYPE_DELETE: | |
| 325 | -                if ($user_is_player && ($selfplay || chess_can_delete())) { | |
| 326 | - $delete_game = true; // must defer actual deletion until after notifications are sent | |
| 327 | -                    $notify      = eval('return \'' . _MD_CHESS_DELETED_GAME . '\';'); // eval references $username | |
| 328 | - } | |
| 329 | - break; | |
| 330 | - case _CHESS_MOVETYPE_WANT_ARBITRATION: | |
| 331 | -                if ($user_is_player) { | |
| 332 | - // Ensure that $move_explain does not contain separator $sep. | |
| 321 | + $gamedata_updated = true; | |
| 322 | + } | |
| 323 | + break; | |
| 324 | + case _CHESS_MOVETYPE_DELETE: | |
| 325 | +				if ($user_is_player && ($selfplay || chess_can_delete())) { | |
| 326 | + $delete_game = true; // must defer actual deletion until after notifications are sent | |
| 327 | +					$notify      = eval('return \'' . _MD_CHESS_DELETED_GAME . '\';'); // eval references $username | |
| 328 | + } | |
| 329 | + break; | |
| 330 | + case _CHESS_MOVETYPE_WANT_ARBITRATION: | |
| 331 | +				if ($user_is_player) { | |
| 332 | + // Ensure that $move_explain does not contain separator $sep. | |
| 333 | 333 | |
| 334 | - $sep = '|'; | |
| 334 | + $sep = '|'; | |
| 335 | 335 | |
| 336 | - $move_explain = str_replace($sep, '_', $move_explain); | |
| 336 | + $move_explain = str_replace($sep, '_', $move_explain); | |
| 337 | 337 | |
| 338 | -                    $gamedata['suspended'] = implode($sep, [date('Y-m-d H:i:s'), $uid, _CHESS_MOVETYPE_WANT_ARBITRATION, $move_explain]); | |
| 338 | +					$gamedata['suspended'] = implode($sep, [date('Y-m-d H:i:s'), $uid, _CHESS_MOVETYPE_WANT_ARBITRATION, $move_explain]); | |
| 339 | 339 | |
| 340 | - $gamedata_updated = true; | |
| 340 | + $gamedata_updated = true; | |
| 341 | 341 | |
| 342 | - $notify = "$user_color_name " . _MD_CHESS_RQSTED_ARBT . ' ' . _MD_CHESS_BEEN_SUSPENDED; | |
| 343 | - } | |
| 344 | - break; | |
| 345 | - } | |
| 346 | - } | |
| 342 | + $notify = "$user_color_name " . _MD_CHESS_RQSTED_ARBT . ' ' . _MD_CHESS_BEEN_SUSPENDED; | |
| 343 | + } | |
| 344 | + break; | |
| 345 | + } | |
| 346 | + } | |
| 347 | 347 | |
| 348 | - // If board orientation setting uninitialized or invalid, set it to the appropriate default. | |
| 348 | + // If board orientation setting uninitialized or invalid, set it to the appropriate default. | |
| 349 | 349 | |
| 350 | -    if (!in_array($orientation, [_CHESS_ORIENTATION_ACTIVE, _CHESS_ORIENTATION_WHITE, _CHESS_ORIENTATION_BLACK])) { | |
| 351 | -        if ($user_is_player && 'b' == $user_color) { | |
| 352 | - $orientation = _CHESS_ORIENTATION_BLACK; | |
| 353 | -        } else { | |
| 354 | - $orientation = _CHESS_ORIENTATION_WHITE; | |
| 355 | - } | |
| 356 | - } | |
| 350 | +	if (!in_array($orientation, [_CHESS_ORIENTATION_ACTIVE, _CHESS_ORIENTATION_WHITE, _CHESS_ORIENTATION_BLACK])) { | |
| 351 | +		if ($user_is_player && 'b' == $user_color) { | |
| 352 | + $orientation = _CHESS_ORIENTATION_BLACK; | |
| 353 | +		} else { | |
| 354 | + $orientation = _CHESS_ORIENTATION_WHITE; | |
| 355 | + } | |
| 356 | + } | |
| 357 | 357 | |
| 358 | - // Determine if user is a valid arbiter. | |
| 358 | + // Determine if user is a valid arbiter. | |
| 359 | 359 | |
| 360 | - global $xoopsModule; | |
| 360 | + global $xoopsModule; | |
| 361 | 361 | |
| 362 | -    $is_arbiter = is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid')); | |
| 362 | +	$is_arbiter = is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid')); | |
| 363 | 363 | |
| 364 | - // If arbiter action was submitted, and user is a valid arbiter, process the action. | |
| 364 | + // If arbiter action was submitted, and user is a valid arbiter, process the action. | |
| 365 | 365 | |
| 366 | -    if ($submit_arbitrate && $is_arbiter) { | |
| 367 | -        $username = $xoopsUser ? $xoopsUser->getVar('uname') : '*unknown*'; | |
| 366 | +	if ($submit_arbitrate && $is_arbiter) { | |
| 367 | +		$username = $xoopsUser ? $xoopsUser->getVar('uname') : '*unknown*'; | |
| 368 | 368 | |
| 369 | -        switch ($arbiter_action) { | |
| 370 | - case _CHESS_ARBITER_RESUME: | |
| 371 | -                if ($gamedata['suspended'] && '*' == $gamedata['pgn_result']) { | |
| 372 | - $gamedata['suspended'] = ''; | |
| 369 | +		switch ($arbiter_action) { | |
| 370 | + case _CHESS_ARBITER_RESUME: | |
| 371 | +				if ($gamedata['suspended'] && '*' == $gamedata['pgn_result']) { | |
| 372 | + $gamedata['suspended'] = ''; | |
| 373 | 373 | |
| 374 | - $gamedata_updated = true; | |
| 374 | + $gamedata_updated = true; | |
| 375 | 375 | |
| 376 | -                    $notify = eval('return \'' . _MD_CHESS_RESUMED_PLAY . '\';'); // eval references $username | |
| 377 | - } | |
| 378 | - break; | |
| 379 | - case _CHESS_ARBITER_DRAW: | |
| 380 | -                if ($gamedata['suspended'] && '*' == $gamedata['pgn_result']) { | |
| 381 | - $gamedata['offer_draw'] = ''; | |
| 376 | +					$notify = eval('return \'' . _MD_CHESS_RESUMED_PLAY . '\';'); // eval references $username | |
| 377 | + } | |
| 378 | + break; | |
| 379 | + case _CHESS_ARBITER_DRAW: | |
| 380 | +				if ($gamedata['suspended'] && '*' == $gamedata['pgn_result']) { | |
| 381 | + $gamedata['offer_draw'] = ''; | |
| 382 | 382 | |
| 383 | - $gamedata['pgn_result'] = '1/2-1/2'; | |
| 383 | + $gamedata['pgn_result'] = '1/2-1/2'; | |
| 384 | 384 | |
| 385 | -                    $arbiter_explain = str_replace('{', '(', $arbiter_explain); | |
| 385 | +					$arbiter_explain = str_replace('{', '(', $arbiter_explain); | |
| 386 | 386 | |
| 387 | -                    $arbiter_explain = str_replace('}', ')', $arbiter_explain); | |
| 387 | +					$arbiter_explain = str_replace('}', ')', $arbiter_explain); | |
| 388 | 388 | |
| 389 | -                    $comment = '{' . sprintf(_MD_CHESS_DRAW_DECLARED, $arbiter_explain) . '}'; | |
| 389 | +					$comment = '{' . sprintf(_MD_CHESS_DRAW_DECLARED, $arbiter_explain) . '}'; | |
| 390 | 390 | |
| 391 | -                    $gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | |
| 391 | +					$gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | |
| 392 | 392 | |
| 393 | - $gamedata['suspended'] = ''; | |
| 393 | + $gamedata['suspended'] = ''; | |
| 394 | 394 | |
| 395 | - $gamedata_updated = true; | |
| 395 | + $gamedata_updated = true; | |
| 396 | 396 | |
| 397 | -                    $notify = eval('return \'' . _MD_CHESS_DECLARED_DRAW . '\';'); // eval references $username | |
| 398 | - } | |
| 399 | - break; | |
| 400 | - case _CHESS_ARBITER_DELETE: | |
| 401 | -                if ($gamedata['suspended']) { | |
| 402 | - $delete_game = true; // must defer actual deletion until after notifications are sent | |
| 403 | -                    $notify      = eval('return \'' . _MD_CHESS_DELETED_GAME . '\';'); // eval references $username | |
| 404 | - } | |
| 405 | - break; | |
| 406 | - case _CHESS_ARBITER_SUSPEND: | |
| 407 | -                if (!$gamedata['suspended'] && '*' == $gamedata['pgn_result']) { | |
| 408 | - // Ensure that $arbiter_explain does not contain separator $sep. | |
| 397 | +					$notify = eval('return \'' . _MD_CHESS_DECLARED_DRAW . '\';'); // eval references $username | |
| 398 | + } | |
| 399 | + break; | |
| 400 | + case _CHESS_ARBITER_DELETE: | |
| 401 | +				if ($gamedata['suspended']) { | |
| 402 | + $delete_game = true; // must defer actual deletion until after notifications are sent | |
| 403 | +					$notify      = eval('return \'' . _MD_CHESS_DELETED_GAME . '\';'); // eval references $username | |
| 404 | + } | |
| 405 | + break; | |
| 406 | + case _CHESS_ARBITER_SUSPEND: | |
| 407 | +				if (!$gamedata['suspended'] && '*' == $gamedata['pgn_result']) { | |
| 408 | + // Ensure that $arbiter_explain does not contain separator $sep. | |
| 409 | 409 | |
| 410 | - $sep = '|'; | |
| 410 | + $sep = '|'; | |
| 411 | 411 | |
| 412 | - $arbiter_explain = str_replace($sep, '_', $arbiter_explain); | |
| 412 | + $arbiter_explain = str_replace($sep, '_', $arbiter_explain); | |
| 413 | 413 | |
| 414 | -                    $gamedata['suspended'] = implode('|', [date('Y-m-d H:i:s'), $uid, _CHESS_MOVETYPE_ARBITER_SUSPEND, $arbiter_explain]); | |
| 414 | +					$gamedata['suspended'] = implode('|', [date('Y-m-d H:i:s'), $uid, _CHESS_MOVETYPE_ARBITER_SUSPEND, $arbiter_explain]); | |
| 415 | 415 | |
| 416 | - $gamedata_updated = true; | |
| 416 | + $gamedata_updated = true; | |
| 417 | 417 | |
| 418 | -                    $notify = eval('return \'' . _MD_CHESS_SUSPENDED_PLAY . '\';'); // eval references $username | |
| 419 | - } | |
| 420 | - break; | |
| 421 | - default: | |
| 422 | - break; | |
| 423 | - } | |
| 424 | - } | |
| 418 | +					$notify = eval('return \'' . _MD_CHESS_SUSPENDED_PLAY . '\';'); // eval references $username | |
| 419 | + } | |
| 420 | + break; | |
| 421 | + default: | |
| 422 | + break; | |
| 423 | + } | |
| 424 | + } | |
| 425 | 425 | |
| 426 | - // Store the updated game data in the database. | |
| 426 | + // Store the updated game data in the database. | |
| 427 | 427 | |
| 428 | -    if ($gamedata_updated) { | |
| 429 | - chess_put_game($game_id, $gamedata); | |
| 430 | - } | |
| 428 | +	if ($gamedata_updated) { | |
| 429 | + chess_put_game($game_id, $gamedata); | |
| 430 | + } | |
| 431 | 431 | |
| 432 | - // Display the (possibly updated) board. | |
| 432 | + // Display the (possibly updated) board. | |
| 433 | 433 | |
| 434 | -    if (!$delete_game) { | |
| 435 | - chess_show_board($gamedata, $orientation, $user_color, $move_performed, $move_result_text, $draw_claim_error_text, $show_arbiter_ctrl && $is_arbiter); | |
| 436 | - } | |
| 434 | +	if (!$delete_game) { | |
| 435 | + chess_show_board($gamedata, $orientation, $user_color, $move_performed, $move_result_text, $draw_claim_error_text, $show_arbiter_ctrl && $is_arbiter); | |
| 436 | + } | |
| 437 | 437 | |
| 438 | - // If a move (or other action) was made, notify any subscribers. | |
| 438 | + // If a move (or other action) was made, notify any subscribers. | |
| 439 | 439 | |
| 440 | -    if (!empty($notify)) { | |
| 441 | -        $notificationHandler = xoops_getHandler('notification'); | |
| 440 | +	if (!empty($notify)) { | |
| 441 | +		$notificationHandler = xoops_getHandler('notification'); | |
| 442 | 442 | |
| 443 | -        $notificationHandler->triggerEvent('game', $game_id, 'notify_game_move', ['CHESS_ACTION' => $notify]); | |
| 443 | +		$notificationHandler->triggerEvent('game', $game_id, 'notify_game_move', ['CHESS_ACTION' => $notify]); | |
| 444 | 444 | |
| 445 | - // admin notifications | |
| 445 | + // admin notifications | |
| 446 | 446 | |
| 447 | -        if (_CHESS_MOVETYPE_WANT_ARBITRATION == $movetype) { | |
| 448 | - $event = 'notify_request_arbitration'; | |
| 447 | +		if (_CHESS_MOVETYPE_WANT_ARBITRATION == $movetype) { | |
| 448 | + $event = 'notify_request_arbitration'; | |
| 449 | 449 | |
| 450 | -            $username = $xoopsUser ? $xoopsUser->getVar('uname') : '(' . _MD_CHESS_UNKNOWN . ')'; | |
| 450 | +			$username = $xoopsUser ? $xoopsUser->getVar('uname') : '(' . _MD_CHESS_UNKNOWN . ')'; | |
| 451 | 451 | |
| 452 | - $extra_tags = ['CHESS_REQUESTOR' => $username, 'CHESS_GAME_ID' => $game_id, 'CHESS_EXPLAIN' => $move_explain]; | |
| 452 | + $extra_tags = ['CHESS_REQUESTOR' => $username, 'CHESS_GAME_ID' => $game_id, 'CHESS_EXPLAIN' => $move_explain]; | |
| 453 | 453 | |
| 454 | -            $notificationHandler->triggerEvent('global', 0, $event, $extra_tags); | |
| 455 | - } | |
| 456 | - } | |
| 454 | +			$notificationHandler->triggerEvent('global', 0, $event, $extra_tags); | |
| 455 | + } | |
| 456 | + } | |
| 457 | 457 | |
| 458 | - // Handle delete-game action. | |
| 458 | + // Handle delete-game action. | |
| 459 | 459 | |
| 460 | -    if ($delete_game) { | |
| 461 | - chess_delete_game($game_id); | |
| 460 | +	if ($delete_game) { | |
| 461 | + chess_delete_game($game_id); | |
| 462 | 462 | |
| 463 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_DELETED); | |
| 464 | - } | |
| 463 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_DELETED); | |
| 464 | + } | |
| 465 | 465 | } | 
| 466 | 466 | |
| 467 | 467 | /** | 
| @@ -472,19 +472,19 @@ discard block | ||
| 472 | 472 | */ | 
| 473 | 473 | function chess_get_game($game_id) | 
| 474 | 474 |  { | 
| 475 | - global $xoopsDB; | |
| 475 | + global $xoopsDB; | |
| 476 | 476 | |
| 477 | -    $games_table = $xoopsDB->prefix('chess_games'); | |
| 477 | +	$games_table = $xoopsDB->prefix('chess_games'); | |
| 478 | 478 | |
| 479 | -    $result = $xoopsDB->query("SELECT * FROM $games_table WHERE game_id = '$game_id'"); | |
| 479 | +	$result = $xoopsDB->query("SELECT * FROM $games_table WHERE game_id = '$game_id'"); | |
| 480 | 480 | |
| 481 | - $gamedata = $xoopsDB->fetchArray($result); | |
| 481 | + $gamedata = $xoopsDB->fetchArray($result); | |
| 482 | 482 | |
| 483 | -    #var_dump('chess_get_game, gamedata', $gamedata);#*#DEBUG# | |
| 483 | +	#var_dump('chess_get_game, gamedata', $gamedata);#*#DEBUG# | |
| 484 | 484 | |
| 485 | - $xoopsDB->freeRecordSet($result); | |
| 485 | + $xoopsDB->freeRecordSet($result); | |
| 486 | 486 | |
| 487 | - return $gamedata; | |
| 487 | + return $gamedata; | |
| 488 | 488 | } | 
| 489 | 489 | |
| 490 | 490 | /** | 
| @@ -495,21 +495,21 @@ discard block | ||
| 495 | 495 | */ | 
| 496 | 496 | function chess_put_game($game_id, $gamedata) | 
| 497 | 497 |  { | 
| 498 | - global $xoopsDB; | |
| 498 | + global $xoopsDB; | |
| 499 | 499 | |
| 500 | - $myts = MyTextSanitizer::getInstance(); | |
| 500 | + $myts = MyTextSanitizer::getInstance(); | |
| 501 | 501 | |
| 502 | - $suspended_q = $myts->addSlashes($gamedata['suspended']); | |
| 502 | + $suspended_q = $myts->addSlashes($gamedata['suspended']); | |
| 503 | 503 | |
| 504 | - $movetext_q = $myts->addSlashes($gamedata['pgn_movetext']); | |
| 504 | + $movetext_q = $myts->addSlashes($gamedata['pgn_movetext']); | |
| 505 | 505 | |
| 506 | -    $table = $xoopsDB->prefix('chess_games'); | |
| 506 | +	$table = $xoopsDB->prefix('chess_games'); | |
| 507 | 507 | |
| 508 | - #echo "updating database table $table<br>\n";#*#DEBUG# | |
| 508 | + #echo "updating database table $table<br>\n";#*#DEBUG# | |
| 509 | 509 | |
| 510 | - $xoopsDB->query( | |
| 511 | - trim( | |
| 512 | - " | |
| 510 | + $xoopsDB->query( | |
| 511 | + trim( | |
| 512 | + " | |
| 513 | 513 | UPDATE $table | 
| 514 | 514 | SET | 
| 515 | 515 |              start_date                   = '{$gamedata['start_date']}', | 
| @@ -528,18 +528,18 @@ discard block | ||
| 528 | 528 |              black_confirm                = '{$gamedata['black_confirm']}' | 
| 529 | 529 | WHERE game_id = '$game_id' | 
| 530 | 530 | " | 
| 531 | - ) | |
| 532 | - ); | |
| 531 | + ) | |
| 532 | + ); | |
| 533 | 533 | |
| 534 | -    if ($xoopsDB->errno()) { | |
| 535 | - trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 536 | - } | |
| 534 | +	if ($xoopsDB->errno()) { | |
| 535 | + trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 536 | + } | |
| 537 | 537 | |
| 538 | -    if ('*' != $gamedata['pgn_result'] && '1' == $gamedata['is_rated']) { | |
| 539 | - require_once XOOPS_ROOT_PATH . '/modules/chess/include/ratings.php'; | |
| 538 | +	if ('*' != $gamedata['pgn_result'] && '1' == $gamedata['is_rated']) { | |
| 539 | + require_once XOOPS_ROOT_PATH . '/modules/chess/include/ratings.php'; | |
| 540 | 540 | |
| 541 | - chess_ratings_adj($game_id); | |
| 542 | - } | |
| 541 | + chess_ratings_adj($game_id); | |
| 542 | + } | |
| 543 | 543 | } | 
| 544 | 544 | |
| 545 | 545 | /** | 
| @@ -549,19 +549,19 @@ discard block | ||
| 549 | 549 | */ | 
| 550 | 550 | function chess_delete_game($game_id) | 
| 551 | 551 |  { | 
| 552 | - global $xoopsModule, $xoopsDB; | |
| 552 | + global $xoopsModule, $xoopsDB; | |
| 553 | 553 | |
| 554 | - // delete notifications associated with this game | |
| 554 | + // delete notifications associated with this game | |
| 555 | 555 | |
| 556 | -    xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'game', $game_id); | |
| 556 | +	xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'game', $game_id); | |
| 557 | 557 | |
| 558 | -    $table = $xoopsDB->prefix('chess_games'); | |
| 558 | +	$table = $xoopsDB->prefix('chess_games'); | |
| 559 | 559 | |
| 560 | -    $xoopsDB->query("DELETE FROM $table WHERE game_id='$game_id'"); | |
| 560 | +	$xoopsDB->query("DELETE FROM $table WHERE game_id='$game_id'"); | |
| 561 | 561 | |
| 562 | -    if ($xoopsDB->errno()) { | |
| 563 | - trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 564 | - } | |
| 562 | +	if ($xoopsDB->errno()) { | |
| 563 | + trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 564 | + } | |
| 565 | 565 | } | 
| 566 | 566 | |
| 567 | 567 | /** | 
| @@ -575,71 +575,71 @@ discard block | ||
| 575 | 575 | */ | 
| 576 | 576 | function chess_move(&$gamedata, $move) | 
| 577 | 577 |  { | 
| 578 | - $gamestate = [ | |
| 579 | - 'fen_piece_placement' => $gamedata['fen_piece_placement'], | |
| 580 | - 'fen_active_color' => $gamedata['fen_active_color'], | |
| 581 | - 'fen_castling_availability' => $gamedata['fen_castling_availability'], | |
| 582 | - 'fen_en_passant_target_square' => $gamedata['fen_en_passant_target_square'], | |
| 583 | - 'fen_halfmove_clock' => $gamedata['fen_halfmove_clock'], | |
| 584 | - 'fen_fullmove_number' => $gamedata['fen_fullmove_number'], | |
| 585 | - 'pgn_fen' => $gamedata['pgn_fen'], | |
| 586 | - 'pgn_result' => $gamedata['pgn_result'], | |
| 587 | - 'pgn_movetext' => $gamedata['pgn_movetext'], | |
| 588 | - ]; | |
| 578 | + $gamestate = [ | |
| 579 | + 'fen_piece_placement' => $gamedata['fen_piece_placement'], | |
| 580 | + 'fen_active_color' => $gamedata['fen_active_color'], | |
| 581 | + 'fen_castling_availability' => $gamedata['fen_castling_availability'], | |
| 582 | + 'fen_en_passant_target_square' => $gamedata['fen_en_passant_target_square'], | |
| 583 | + 'fen_halfmove_clock' => $gamedata['fen_halfmove_clock'], | |
| 584 | + 'fen_fullmove_number' => $gamedata['fen_fullmove_number'], | |
| 585 | + 'pgn_fen' => $gamedata['pgn_fen'], | |
| 586 | + 'pgn_result' => $gamedata['pgn_result'], | |
| 587 | + 'pgn_movetext' => $gamedata['pgn_movetext'], | |
| 588 | + ]; | |
| 589 | 589 | |
| 590 | - $chessgame = new Chess\ChessGame($gamestate); | |
| 590 | + $chessgame = new Chess\ChessGame($gamestate); | |
| 591 | 591 | |
| 592 | - #echo "Performing move: '$move'<br>\n";#*#DEBUG# | |
| 592 | + #echo "Performing move: '$move'<br>\n";#*#DEBUG# | |
| 593 | 593 | |
| 594 | - [$move_performed, $move_result_text] = $chessgame->move($move); | |
| 594 | + [$move_performed, $move_result_text] = $chessgame->move($move); | |
| 595 | 595 | |
| 596 | - #echo "Move result: '$move_result_text'<br>\n";#*#DEBUG# | |
| 596 | + #echo "Move result: '$move_result_text'<br>\n";#*#DEBUG# | |
| 597 | 597 | |
| 598 | -    if ($move_performed) { | |
| 599 | - // The move was valid - update the game data. | |
| 598 | +	if ($move_performed) { | |
| 599 | + // The move was valid - update the game data. | |
| 600 | 600 | |
| 601 | - $new_gamestate = $chessgame->gamestate(); | |
| 601 | + $new_gamestate = $chessgame->gamestate(); | |
| 602 | 602 | |
| 603 | -        #var_dump('new_gamestate', $new_gamestate);#*#DEBUG# | |
| 603 | +		#var_dump('new_gamestate', $new_gamestate);#*#DEBUG# | |
| 604 | 604 | |
| 605 | - #*#DEBUG# - start | |
| 605 | + #*#DEBUG# - start | |
| 606 | 606 | |
| 607 | -        #if ($new_gamestate['fen_castling_availability'] != $gamedata['fen_castling_availability']) { | |
| 607 | +		#if ($new_gamestate['fen_castling_availability'] != $gamedata['fen_castling_availability']) { | |
| 608 | 608 | |
| 609 | -        #    echo "*** castling_availability changed from '{$gamedata['fen_castling_availability']}' to '{$new_gamestate['fen_castling_availability']}' ***<br>\n"; | |
| 609 | +		#    echo "*** castling_availability changed from '{$gamedata['fen_castling_availability']}' to '{$new_gamestate['fen_castling_availability']}' ***<br>\n"; | |
| 610 | 610 | |
| 611 | - #} | |
| 611 | + #} | |
| 612 | 612 | |
| 613 | - #*#DEBUG# - end | |
| 613 | + #*#DEBUG# - end | |
| 614 | 614 | |
| 615 | - $gamedata['fen_piece_placement'] = $new_gamestate['fen_piece_placement']; | |
| 615 | + $gamedata['fen_piece_placement'] = $new_gamestate['fen_piece_placement']; | |
| 616 | 616 | |
| 617 | - $gamedata['fen_active_color'] = $new_gamestate['fen_active_color']; | |
| 617 | + $gamedata['fen_active_color'] = $new_gamestate['fen_active_color']; | |
| 618 | 618 | |
| 619 | - $gamedata['fen_castling_availability'] = $new_gamestate['fen_castling_availability']; | |
| 619 | + $gamedata['fen_castling_availability'] = $new_gamestate['fen_castling_availability']; | |
| 620 | 620 | |
| 621 | - $gamedata['fen_en_passant_target_square'] = $new_gamestate['fen_en_passant_target_square']; | |
| 621 | + $gamedata['fen_en_passant_target_square'] = $new_gamestate['fen_en_passant_target_square']; | |
| 622 | 622 | |
| 623 | - $gamedata['fen_halfmove_clock'] = $new_gamestate['fen_halfmove_clock']; | |
| 623 | + $gamedata['fen_halfmove_clock'] = $new_gamestate['fen_halfmove_clock']; | |
| 624 | 624 | |
| 625 | - $gamedata['fen_fullmove_number'] = $new_gamestate['fen_fullmove_number']; | |
| 625 | + $gamedata['fen_fullmove_number'] = $new_gamestate['fen_fullmove_number']; | |
| 626 | 626 | |
| 627 | - $gamedata['pgn_fen'] = $new_gamestate['pgn_fen']; | |
| 627 | + $gamedata['pgn_fen'] = $new_gamestate['pgn_fen']; | |
| 628 | 628 | |
| 629 | - $gamedata['pgn_result'] = $new_gamestate['pgn_result']; | |
| 629 | + $gamedata['pgn_result'] = $new_gamestate['pgn_result']; | |
| 630 | 630 | |
| 631 | - $gamedata['pgn_movetext'] = $new_gamestate['pgn_movetext']; | |
| 631 | + $gamedata['pgn_movetext'] = $new_gamestate['pgn_movetext']; | |
| 632 | 632 | |
| 633 | -        $gamedata['last_date'] = date('Y-m-d H:i:s'); | |
| 633 | +		$gamedata['last_date'] = date('Y-m-d H:i:s'); | |
| 634 | 634 | |
| 635 | - // if start_date undefined (first move), initialize it | |
| 635 | + // if start_date undefined (first move), initialize it | |
| 636 | 636 | |
| 637 | -        if ('0000-00-00 00:00:00' == $gamedata['start_date']) { | |
| 638 | - $gamedata['start_date'] = $gamedata['last_date']; | |
| 639 | - } | |
| 640 | - } | |
| 637 | +		if ('0000-00-00 00:00:00' == $gamedata['start_date']) { | |
| 638 | + $gamedata['start_date'] = $gamedata['last_date']; | |
| 639 | + } | |
| 640 | + } | |
| 641 | 641 | |
| 642 | - return [$move_performed, $move_result_text]; | |
| 642 | + return [$move_performed, $move_result_text]; | |
| 643 | 643 | } | 
| 644 | 644 | |
| 645 | 645 | /** | 
| @@ -652,19 +652,19 @@ discard block | ||
| 652 | 652 | */ | 
| 653 | 653 | function chess_is_draw_50_move_rule($gamedata) | 
| 654 | 654 |  { | 
| 655 | -    #var_dump('gamedata', $gamedata);#*#DEBUG# | |
| 655 | +	#var_dump('gamedata', $gamedata);#*#DEBUG# | |
| 656 | 656 | |
| 657 | -    if ($gamedata['fen_halfmove_clock'] >= 100) { | |
| 658 | - $draw_claim_valid = true; | |
| 657 | +	if ($gamedata['fen_halfmove_clock'] >= 100) { | |
| 658 | + $draw_claim_valid = true; | |
| 659 | 659 | |
| 660 | - $draw_claim_text = _MD_CHESS_DRAW_50; | |
| 661 | -    } else { | |
| 662 | - $draw_claim_valid = false; | |
| 660 | + $draw_claim_text = _MD_CHESS_DRAW_50; | |
| 661 | +	} else { | |
| 662 | + $draw_claim_valid = false; | |
| 663 | 663 | |
| 664 | - $draw_claim_text = _MD_CHESS_NO_DRAW_50; | |
| 665 | - } | |
| 664 | + $draw_claim_text = _MD_CHESS_NO_DRAW_50; | |
| 665 | + } | |
| 666 | 666 | |
| 667 | - return [$draw_claim_valid, $draw_claim_text]; | |
| 667 | + return [$draw_claim_valid, $draw_claim_text]; | |
| 668 | 668 | } | 
| 669 | 669 | |
| 670 | 670 | /** | 
| @@ -680,41 +680,41 @@ discard block | ||
| 680 | 680 | */ | 
| 681 | 681 | function chess_is_draw_threefold_repetition($gamedata) | 
| 682 | 682 |  { | 
| 683 | -    #var_dump('gamedata', $gamedata);#*#DEBUG# | |
| 683 | +	#var_dump('gamedata', $gamedata);#*#DEBUG# | |
| 684 | 684 | |
| 685 | - // Define this constant as true to output a log file containing a move analysis. | |
| 685 | + // Define this constant as true to output a log file containing a move analysis. | |
| 686 | 686 | |
| 687 | -    define('CHESS_LOG_3FOLD', false); | |
| 687 | +	define('CHESS_LOG_3FOLD', false); | |
| 688 | 688 | |
| 689 | -    if (CHESS_LOG_3FOLD) { | |
| 690 | - $log = []; | |
| 691 | - } | |
| 689 | +	if (CHESS_LOG_3FOLD) { | |
| 690 | + $log = []; | |
| 691 | + } | |
| 692 | 692 | |
| 693 | - $chessgame = new Chess\ChessGame($gamedata); | |
| 693 | + $chessgame = new Chess\ChessGame($gamedata); | |
| 694 | 694 | |
| 695 | - // board position against which to check for repetitions | |
| 695 | + // board position against which to check for repetitions | |
| 696 | 696 | |
| 697 | -    $last_board_state = "{$gamedata['fen_piece_placement']} {$gamedata['fen_active_color']} {$gamedata['fen_castling_availability']} {$gamedata['fen_en_passant_target_square']}"; | |
| 697 | +	$last_board_state = "{$gamedata['fen_piece_placement']} {$gamedata['fen_active_color']} {$gamedata['fen_castling_availability']} {$gamedata['fen_en_passant_target_square']}"; | |
| 698 | 698 | |
| 699 | - $last_move_number = $gamedata['fen_fullmove_number']; | |
| 699 | + $last_move_number = $gamedata['fen_fullmove_number']; | |
| 700 | 700 | |
| 701 | - #echo "last_board_state='$last_board_state'<br>\n";#*#DEBUG# | |
| 701 | + #echo "last_board_state='$last_board_state'<br>\n";#*#DEBUG# | |
| 702 | 702 | |
| 703 | -    if (CHESS_LOG_3FOLD) { | |
| 704 | -        $log[] = sprintf('%08x %03d%1s %s', crc32($last_board_state), $gamedata['fen_fullmove_number'], $gamedata['fen_active_color'], $last_board_state); | |
| 705 | - } | |
| 703 | +	if (CHESS_LOG_3FOLD) { | |
| 704 | +		$log[] = sprintf('%08x %03d%1s %s', crc32($last_board_state), $gamedata['fen_fullmove_number'], $gamedata['fen_active_color'], $last_board_state); | |
| 705 | + } | |
| 706 | 706 | |
| 707 | - $chessgame = new Chess\ChessGame($gamedata['pgn_fen']); | |
| 707 | + $chessgame = new Chess\ChessGame($gamedata['pgn_fen']); | |
| 708 | 708 | |
| 709 | -    empty($chessgame->error) or trigger_error('chessgame invalid', E_USER_ERROR); | |
| 709 | +	empty($chessgame->error) or trigger_error('chessgame invalid', E_USER_ERROR); | |
| 710 | 710 | |
| 711 | - $tmp_gamedata = $chessgame->gamestate(); | |
| 711 | + $tmp_gamedata = $chessgame->gamestate(); | |
| 712 | 712 | |
| 713 | -    is_array($tmp_gamedata) or trigger_error('gamestate invalid', E_USER_ERROR); | |
| 713 | +	is_array($tmp_gamedata) or trigger_error('gamestate invalid', E_USER_ERROR); | |
| 714 | 714 | |
| 715 | - #*#DEBUG# - start | |
| 715 | + #*#DEBUG# - start | |
| 716 | 716 | |
| 717 | - /*** | |
| 717 | + /*** | |
| 718 | 718 |       * if (function_exists('posix_times')) { | 
| 719 | 719 | * $posix_times = posix_times(); | 
| 720 | 720 |       * var_dump('posix_times', $posix_times); | 
| @@ -725,31 +725,31 @@ discard block | ||
| 725 | 725 | * } | 
| 726 | 726 | ***/ | 
| 727 | 727 | |
| 728 | - #*#DEBUG# - end | |
| 728 | + #*#DEBUG# - end | |
| 729 | 729 | |
| 730 | - // $repeats is the list of moves for which the board positions are identical. | |
| 730 | + // $repeats is the list of moves for which the board positions are identical. | |
| 731 | 731 | |
| 732 | - // For example, '6w' would represent the board position immediately before white's sixth move. | |
| 732 | + // For example, '6w' would represent the board position immediately before white's sixth move. | |
| 733 | 733 | |
| 734 | - // The current position is included, since that's the position against which the other positions will be compared. | |
| 734 | + // The current position is included, since that's the position against which the other positions will be compared. | |
| 735 | 735 | |
| 736 | - $repeats[] = $gamedata['fen_fullmove_number'] . $gamedata['fen_active_color']; | |
| 736 | + $repeats[] = $gamedata['fen_fullmove_number'] . $gamedata['fen_active_color']; | |
| 737 | 737 | |
| 738 | - // Compare initial board position with last board position, unless the move number is the same, meaning that there haven't been any moves. | |
| 738 | + // Compare initial board position with last board position, unless the move number is the same, meaning that there haven't been any moves. | |
| 739 | 739 | |
| 740 | -    #echo "FEN: '{$tmp_gamedata['fen_piece_placement']} {$tmp_gamedata['fen_active_color']} {$tmp_gamedata['fen_castling_availability']} {$tmp_gamedata['fen_en_passant_target_square']} {$tmp_gamedata['fen_halfmove_clock']} {$tmp_gamedata['fen_fullmove_number']}'<br>\n";#*#DEBUG# | |
| 740 | +	#echo "FEN: '{$tmp_gamedata['fen_piece_placement']} {$tmp_gamedata['fen_active_color']} {$tmp_gamedata['fen_castling_availability']} {$tmp_gamedata['fen_en_passant_target_square']} {$tmp_gamedata['fen_halfmove_clock']} {$tmp_gamedata['fen_fullmove_number']}'<br>\n";#*#DEBUG# | |
| 741 | 741 | |
| 742 | -    $board_state = "{$tmp_gamedata['fen_piece_placement']} {$tmp_gamedata['fen_active_color']} {$tmp_gamedata['fen_castling_availability']} {$tmp_gamedata['fen_en_passant_target_square']}"; | |
| 742 | +	$board_state = "{$tmp_gamedata['fen_piece_placement']} {$tmp_gamedata['fen_active_color']} {$tmp_gamedata['fen_castling_availability']} {$tmp_gamedata['fen_en_passant_target_square']}"; | |
| 743 | 743 | |
| 744 | -    if ($tmp_gamedata['fen_fullmove_number'] != $last_move_number && $board_state == $last_board_state) { | |
| 745 | - $repeats[] = $tmp_gamedata['fen_fullmove_number'] . $tmp_gamedata['fen_active_color']; | |
| 744 | +	if ($tmp_gamedata['fen_fullmove_number'] != $last_move_number && $board_state == $last_board_state) { | |
| 745 | + $repeats[] = $tmp_gamedata['fen_fullmove_number'] . $tmp_gamedata['fen_active_color']; | |
| 746 | 746 | |
| 747 | -        if (CHESS_LOG_3FOLD) { | |
| 748 | -            $log[] = sprintf('%08x %03d%1s %s', crc32($board_state), $tmp_gamedata['fen_fullmove_number'], $tmp_gamedata['fen_active_color'], $board_state); | |
| 749 | - } | |
| 747 | +		if (CHESS_LOG_3FOLD) { | |
| 748 | +			$log[] = sprintf('%08x %03d%1s %s', crc32($board_state), $tmp_gamedata['fen_fullmove_number'], $tmp_gamedata['fen_active_color'], $board_state); | |
| 749 | + } | |
| 750 | 750 | |
| 751 | - #*#DEBUG# - start | |
| 752 | - /*** | |
| 751 | + #*#DEBUG# - start | |
| 752 | + /*** | |
| 753 | 753 |           * if (count($repeats) >= 3) { | 
| 754 | 754 |           * echo "*** Three repetitions! {$repeats[1]},{$repeats[2]},{$repeats[0]} ***<br>\n"; | 
| 755 | 755 |           * } elseif (count($repeats) >= 2) { | 
| @@ -757,61 +757,61 @@ discard block | ||
| 757 | 757 | * } | 
| 758 | 758 | ***/ | 
| 759 | 759 | |
| 760 | - #*#DEBUG# - end | |
| 761 | - } | |
| 760 | + #*#DEBUG# - end | |
| 761 | + } | |
| 762 | 762 | |
| 763 | - // Convert pgn_movetext into Nx3 array $movelist. | |
| 763 | + // Convert pgn_movetext into Nx3 array $movelist. | |
| 764 | 764 | |
| 765 | - $movelist = chess_make_movelist($gamedata['pgn_movetext']); | |
| 765 | + $movelist = chess_make_movelist($gamedata['pgn_movetext']); | |
| 766 | 766 | |
| 767 | -    #var_dump('movelist', $movelist);#*#DEBUG# | |
| 767 | +	#var_dump('movelist', $movelist);#*#DEBUG# | |
| 768 | 768 | |
| 769 | - // Compare board positions after each move with last board position. | |
| 769 | + // Compare board positions after each move with last board position. | |
| 770 | 770 | |
| 771 | -    foreach ($movelist as $fullmove) { | |
| 772 | -        #echo "'{$fullmove[0]}' '{$fullmove[1]}' '{$fullmove[2]}'<br>\n";#*#DEBUG# | |
| 771 | +	foreach ($movelist as $fullmove) { | |
| 772 | +		#echo "'{$fullmove[0]}' '{$fullmove[1]}' '{$fullmove[2]}'<br>\n";#*#DEBUG# | |
| 773 | 773 | |
| 774 | -        if (CHESS_LOG_3FOLD) { | |
| 775 | -            #$log[] = "'{$fullmove[0]}' '{$fullmove[1]}' '{$fullmove[2]}'";#*#LOG_3FOLD# #*#DEBUG# | |
| 776 | - } | |
| 774 | +		if (CHESS_LOG_3FOLD) { | |
| 775 | +			#$log[] = "'{$fullmove[0]}' '{$fullmove[1]}' '{$fullmove[2]}'";#*#LOG_3FOLD# #*#DEBUG# | |
| 776 | + } | |
| 777 | 777 | |
| 778 | -        for ($i = 1; $i <= 2; ++$i) { | |
| 779 | -            if (!empty($fullmove[$i])) { | |
| 780 | - $move = $fullmove[$i]; | |
| 781 | -            } else { | |
| 782 | - continue; // $fullmove[$i] can be empty if last move was white's, or if game was setup with black to move first. | |
| 783 | - } | |
| 778 | +		for ($i = 1; $i <= 2; ++$i) { | |
| 779 | +			if (!empty($fullmove[$i])) { | |
| 780 | + $move = $fullmove[$i]; | |
| 781 | +			} else { | |
| 782 | + continue; // $fullmove[$i] can be empty if last move was white's, or if game was setup with black to move first. | |
| 783 | + } | |
| 784 | 784 | |
| 785 | - // Remove check/checkmate annotation, if present. | |
| 785 | + // Remove check/checkmate annotation, if present. | |
| 786 | 786 | |
| 787 | -            $move = str_replace('+', '', $move); | |
| 787 | +			$move = str_replace('+', '', $move); | |
| 788 | 788 | |
| 789 | -            $move = str_replace('#', '', $move); | |
| 789 | +			$move = str_replace('#', '', $move); | |
| 790 | 790 | |
| 791 | - #echo "Performing move: '$move'<br>\n";#*#DEBUG# | |
| 791 | + #echo "Performing move: '$move'<br>\n";#*#DEBUG# | |
| 792 | 792 | |
| 793 | - [$tmp_move_performed, $tmp_move_result_text] = $chessgame->move($move); | |
| 793 | + [$tmp_move_performed, $tmp_move_result_text] = $chessgame->move($move); | |
| 794 | 794 | |
| 795 | - #echo "Move result: '$tmp_move_result_text'<br>\n";#*#DEBUG# | |
| 795 | + #echo "Move result: '$tmp_move_result_text'<br>\n";#*#DEBUG# | |
| 796 | 796 | |
| 797 | -            $tmp_move_performed or trigger_error("Failed to perform move $move: $tmp_move_result_text", E_USER_ERROR); | |
| 797 | +			$tmp_move_performed or trigger_error("Failed to perform move $move: $tmp_move_result_text", E_USER_ERROR); | |
| 798 | 798 | |
| 799 | - $tmp_gamedata = $chessgame->gamestate(); | |
| 799 | + $tmp_gamedata = $chessgame->gamestate(); | |
| 800 | 800 | |
| 801 | -            #echo "FEN: '{$tmp_gamedata['fen_piece_placement']} {$tmp_gamedata['fen_active_color']} {$tmp_gamedata['fen_castling_availability']} {$tmp_gamedata['fen_en_passant_target_square']} {$tmp_gamedata['fen_halfmove_clock']} {$tmp_gamedata['fen_fullmove_number']}'<br>\n";#*#DEBUG# | |
| 801 | +			#echo "FEN: '{$tmp_gamedata['fen_piece_placement']} {$tmp_gamedata['fen_active_color']} {$tmp_gamedata['fen_castling_availability']} {$tmp_gamedata['fen_en_passant_target_square']} {$tmp_gamedata['fen_halfmove_clock']} {$tmp_gamedata['fen_fullmove_number']}'<br>\n";#*#DEBUG# | |
| 802 | 802 | |
| 803 | -            $board_state = "{$tmp_gamedata['fen_piece_placement']} {$tmp_gamedata['fen_active_color']} {$tmp_gamedata['fen_castling_availability']} {$tmp_gamedata['fen_en_passant_target_square']}"; | |
| 803 | +			$board_state = "{$tmp_gamedata['fen_piece_placement']} {$tmp_gamedata['fen_active_color']} {$tmp_gamedata['fen_castling_availability']} {$tmp_gamedata['fen_en_passant_target_square']}"; | |
| 804 | 804 | |
| 805 | -            if (CHESS_LOG_3FOLD) { | |
| 806 | -                $log[] = sprintf('%08x %03d%1s %s', crc32($board_state), $tmp_gamedata['fen_fullmove_number'], $tmp_gamedata['fen_active_color'], $board_state); | |
| 807 | - } | |
| 805 | +			if (CHESS_LOG_3FOLD) { | |
| 806 | +				$log[] = sprintf('%08x %03d%1s %s', crc32($board_state), $tmp_gamedata['fen_fullmove_number'], $tmp_gamedata['fen_active_color'], $board_state); | |
| 807 | + } | |
| 808 | 808 | |
| 809 | -            if ($tmp_gamedata['fen_fullmove_number'] != $last_move_number && $board_state == $last_board_state) { | |
| 810 | - $repeats[] = $tmp_gamedata['fen_fullmove_number'] . $tmp_gamedata['fen_active_color']; | |
| 809 | +			if ($tmp_gamedata['fen_fullmove_number'] != $last_move_number && $board_state == $last_board_state) { | |
| 810 | + $repeats[] = $tmp_gamedata['fen_fullmove_number'] . $tmp_gamedata['fen_active_color']; | |
| 811 | 811 | |
| 812 | - #*#DEBUG# - start | |
| 812 | + #*#DEBUG# - start | |
| 813 | 813 | |
| 814 | - /*** | |
| 814 | + /*** | |
| 815 | 815 |                   * if (count($repeats) >= 3) { | 
| 816 | 816 |                   * echo "*** Three repetitions! {$repeats[1]},{$repeats[2]},{$repeats[0]} ***<br>\n"; | 
| 817 | 817 |                   * } elseif (count($repeats) >= 2) { | 
| @@ -819,18 +819,18 @@ discard block | ||
| 819 | 819 | * } | 
| 820 | 820 | ***/ | 
| 821 | 821 | |
| 822 | - #*#DEBUG# - end | |
| 822 | + #*#DEBUG# - end | |
| 823 | 823 | |
| 824 | -                if (count($repeats) >= 3) { | |
| 825 | - break 2; | |
| 826 | - } | |
| 827 | - } | |
| 828 | - } | |
| 829 | - } | |
| 824 | +				if (count($repeats) >= 3) { | |
| 825 | + break 2; | |
| 826 | + } | |
| 827 | + } | |
| 828 | + } | |
| 829 | + } | |
| 830 | 830 | |
| 831 | - #*#DEBUG# - start | |
| 831 | + #*#DEBUG# - start | |
| 832 | 832 | |
| 833 | - /*** | |
| 833 | + /*** | |
| 834 | 834 |       * if (function_exists('posix_times')) { | 
| 835 | 835 | * $posix_times = posix_times(); | 
| 836 | 836 |       * var_dump('posix_times', $posix_times); | 
| @@ -841,27 +841,27 @@ discard block | ||
| 841 | 841 | * } | 
| 842 | 842 | ***/ | 
| 843 | 843 | |
| 844 | - #*#DEBUG# - end | |
| 844 | + #*#DEBUG# - end | |
| 845 | 845 | |
| 846 | -    if (count($repeats) >= 3) { | |
| 847 | - $draw_claim_valid = true; | |
| 846 | +	if (count($repeats) >= 3) { | |
| 847 | + $draw_claim_valid = true; | |
| 848 | 848 | |
| 849 | -        $draw_claim_text = sprintf(_MD_CHESS_DRAW_3, "{$repeats[1]},{$repeats[2]},{$repeats[0]}"); | |
| 850 | -    } else { | |
| 851 | - $draw_claim_valid = false; | |
| 849 | +		$draw_claim_text = sprintf(_MD_CHESS_DRAW_3, "{$repeats[1]},{$repeats[2]},{$repeats[0]}"); | |
| 850 | +	} else { | |
| 851 | + $draw_claim_valid = false; | |
| 852 | 852 | |
| 853 | - $draw_claim_text = _MD_CHESS_NO_DRAW_3; | |
| 854 | - } | |
| 853 | + $draw_claim_text = _MD_CHESS_NO_DRAW_3; | |
| 854 | + } | |
| 855 | 855 | |
| 856 | -    if (CHESS_LOG_3FOLD) { | |
| 857 | -        $logfile = XOOPS_ROOT_PATH . '/cache/' . date('Ymd_His') . '_3fold.log'; | |
| 856 | +	if (CHESS_LOG_3FOLD) { | |
| 857 | +		$logfile = XOOPS_ROOT_PATH . '/cache/' . date('Ymd_His') . '_3fold.log'; | |
| 858 | 858 | |
| 859 | - sort($log); | |
| 859 | + sort($log); | |
| 860 | 860 | |
| 861 | -        error_log(implode("\n", $log), 3, $logfile); | |
| 862 | - } | |
| 861 | +		error_log(implode("\n", $log), 3, $logfile); | |
| 862 | + } | |
| 863 | 863 | |
| 864 | - return [$draw_claim_valid, $draw_claim_text]; | |
| 864 | + return [$draw_claim_valid, $draw_claim_text]; | |
| 865 | 865 | } | 
| 866 | 866 | |
| 867 | 867 | /** | 
| @@ -872,31 +872,31 @@ discard block | ||
| 872 | 872 | */ | 
| 873 | 873 | function chess_make_movelist($movetext) | 
| 874 | 874 |  { | 
| 875 | - $movelist = []; | |
| 875 | + $movelist = []; | |
| 876 | 876 | |
| 877 | -    $move_tokens = explode(' ', preg_replace('/\{.*\}/', '', $movetext)); | |
| 877 | +	$move_tokens = explode(' ', preg_replace('/\{.*\}/', '', $movetext)); | |
| 878 | 878 | |
| 879 | - $index = -1; | |
| 879 | + $index = -1; | |
| 880 | 880 | |
| 881 | -    while ($move_tokens) { | |
| 882 | - $move_token = array_shift($move_tokens); | |
| 881 | +	while ($move_tokens) { | |
| 882 | + $move_token = array_shift($move_tokens); | |
| 883 | 883 | |
| 884 | -        if (in_array($move_token, ['1-0', '0-1', '1/2-1/2', '*'])) { | |
| 885 | - break; | |
| 886 | -        } elseif (preg_match('/^\d+(\.|\.\.\.)$/', $move_token, $matches)) { | |
| 887 | - ++$index; | |
| 884 | +		if (in_array($move_token, ['1-0', '0-1', '1/2-1/2', '*'])) { | |
| 885 | + break; | |
| 886 | +		} elseif (preg_match('/^\d+(\.|\.\.\.)$/', $move_token, $matches)) { | |
| 887 | + ++$index; | |
| 888 | 888 | |
| 889 | - $movelist[$index][] = $move_token; | |
| 889 | + $movelist[$index][] = $move_token; | |
| 890 | 890 | |
| 891 | -            if ('...' == $matches[1]) { // setup-game with initial black move - add padding for white's move | |
| 892 | - $movelist[$index][] = ''; | |
| 893 | - } | |
| 894 | -        } else { | |
| 895 | - $movelist[$index][] = $move_token; | |
| 896 | - } | |
| 897 | - } | |
| 891 | +			if ('...' == $matches[1]) { // setup-game with initial black move - add padding for white's move | |
| 892 | + $movelist[$index][] = ''; | |
| 893 | + } | |
| 894 | +		} else { | |
| 895 | + $movelist[$index][] = $move_token; | |
| 896 | + } | |
| 897 | + } | |
| 898 | 898 | |
| 899 | - return $movelist; | |
| 899 | + return $movelist; | |
| 900 | 900 | } | 
| 901 | 901 | |
| 902 | 902 | /** | 
| @@ -912,252 +912,252 @@ discard block | ||
| 912 | 912 | */ | 
| 913 | 913 | function chess_show_board($gamedata, $orientation, $user_color, $move_performed, $move_result_text = '', $draw_claim_error_text = '', $show_arbiter_ctrl = false) | 
| 914 | 914 |  { | 
| 915 | - global $xoopsTpl; | |
| 915 | + global $xoopsTpl; | |
| 916 | 916 | |
| 917 | - $xoopsTpl->assign( | |
| 918 | - 'xoops_module_header', | |
| 919 | - ' | |
| 917 | + $xoopsTpl->assign( | |
| 918 | + 'xoops_module_header', | |
| 919 | + ' | |
| 920 | 920 | <link rel="stylesheet" type="text/css" media="screen" href="' . XOOPS_URL . '/modules/chess/assets/css/style.css"> | 
| 921 | 921 | ' | 
| 922 | - ); | |
| 922 | + ); | |
| 923 | 923 | |
| 924 | -    $memberHandler = xoops_getHandler('member'); | |
| 924 | +	$memberHandler = xoops_getHandler('member'); | |
| 925 | 925 | |
| 926 | - $white_user = $memberHandler->getUser($gamedata['white_uid']); | |
| 926 | + $white_user = $memberHandler->getUser($gamedata['white_uid']); | |
| 927 | 927 | |
| 928 | -    $white_username = is_object($white_user) ? $white_user->getVar('uname') : '?'; | |
| 928 | +	$white_username = is_object($white_user) ? $white_user->getVar('uname') : '?'; | |
| 929 | 929 | |
| 930 | - $black_user = $memberHandler->getUser($gamedata['black_uid']); | |
| 930 | + $black_user = $memberHandler->getUser($gamedata['black_uid']); | |
| 931 | 931 | |
| 932 | -    $black_username = is_object($black_user) ? $black_user->getVar('uname') : '?'; | |
| 932 | +	$black_username = is_object($black_user) ? $black_user->getVar('uname') : '?'; | |
| 933 | 933 | |
| 934 | - // Determine whether board is flipped (black at bottom) or "normal" (white at bottom). | |
| 934 | + // Determine whether board is flipped (black at bottom) or "normal" (white at bottom). | |
| 935 | 935 | |
| 936 | -    switch ($orientation) { | |
| 937 | - default: | |
| 938 | - case _CHESS_ORIENTATION_ACTIVE: | |
| 939 | - $flip = 'b' == $gamedata['fen_active_color']; | |
| 940 | - break; | |
| 941 | - case _CHESS_ORIENTATION_WHITE: | |
| 942 | - $flip = false; | |
| 943 | - break; | |
| 944 | - case _CHESS_ORIENTATION_BLACK: | |
| 945 | - $flip = true; | |
| 946 | - break; | |
| 947 | - } | |
| 936 | +	switch ($orientation) { | |
| 937 | + default: | |
| 938 | + case _CHESS_ORIENTATION_ACTIVE: | |
| 939 | + $flip = 'b' == $gamedata['fen_active_color']; | |
| 940 | + break; | |
| 941 | + case _CHESS_ORIENTATION_WHITE: | |
| 942 | + $flip = false; | |
| 943 | + break; | |
| 944 | + case _CHESS_ORIENTATION_BLACK: | |
| 945 | + $flip = true; | |
| 946 | + break; | |
| 947 | + } | |
| 948 | 948 | |
| 949 | - // Convert fen_piece_placement string into 8x8-array $tiles. | |
| 949 | + // Convert fen_piece_placement string into 8x8-array $tiles. | |
| 950 | 950 | |
| 951 | - $tiles = []; | |
| 951 | + $tiles = []; | |
| 952 | 952 | |
| 953 | -    $ranks = explode('/', $gamedata['fen_piece_placement']); | |
| 953 | +	$ranks = explode('/', $gamedata['fen_piece_placement']); | |
| 954 | 954 | |
| 955 | -    if ($flip) { | |
| 956 | - $ranks = array_reverse($ranks); | |
| 957 | - } | |
| 955 | +	if ($flip) { | |
| 956 | + $ranks = array_reverse($ranks); | |
| 957 | + } | |
| 958 | 958 | |
| 959 | -    foreach ($ranks as $rank) { | |
| 960 | - $expanded_row = preg_replace_callback( | |
| 961 | - '/(\d)/', | |
| 959 | +	foreach ($ranks as $rank) { | |
| 960 | + $expanded_row = preg_replace_callback( | |
| 961 | + '/(\d)/', | |
| 962 | 962 | |
| 963 | -            static function ($matches) { | |
| 964 | -                return str_repeat('x', $matches[1]); | |
| 965 | - }, | |
| 966 | - $rank | |
| 967 | - ); | |
| 963 | +			static function ($matches) { | |
| 964 | +				return str_repeat('x', $matches[1]); | |
| 965 | + }, | |
| 966 | + $rank | |
| 967 | + ); | |
| 968 | 968 | |
| 969 | -        $rank_tiles = preg_split('//', $expanded_row, -1, PREG_SPLIT_NO_EMPTY); | |
| 969 | +		$rank_tiles = preg_split('//', $expanded_row, -1, PREG_SPLIT_NO_EMPTY); | |
| 970 | 970 | |
| 971 | - $tiles[] = $flip ? array_reverse($rank_tiles) : $rank_tiles; | |
| 972 | - } | |
| 971 | + $tiles[] = $flip ? array_reverse($rank_tiles) : $rank_tiles; | |
| 972 | + } | |
| 973 | 973 | |
| 974 | -    #var_dump('tiles', $tiles);#*#DEBUG# | |
| 974 | +	#var_dump('tiles', $tiles);#*#DEBUG# | |
| 975 | 975 | |
| 976 | - // Convert pgn_movetext into Nx3 array $movelist. | |
| 976 | + // Convert pgn_movetext into Nx3 array $movelist. | |
| 977 | 977 | |
| 978 | - $movelist = chess_make_movelist($gamedata['pgn_movetext']); | |
| 978 | + $movelist = chess_make_movelist($gamedata['pgn_movetext']); | |
| 979 | 979 | |
| 980 | - static $file_labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; | |
| 980 | + static $file_labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; | |
| 981 | 981 | |
| 982 | -    if ($flip) { | |
| 983 | - $file_labels = array_reverse($file_labels); | |
| 984 | - } | |
| 982 | +	if ($flip) { | |
| 983 | + $file_labels = array_reverse($file_labels); | |
| 984 | + } | |
| 985 | 985 | |
| 986 | -    $xoopsTpl->assign('chess_gamedata', $gamedata); | |
| 986 | +	$xoopsTpl->assign('chess_gamedata', $gamedata); | |
| 987 | 987 | |
| 988 | - // comment at end of movetext | |
| 988 | + // comment at end of movetext | |
| 989 | 989 | |
| 990 | -    if (preg_match('/\{(.*?)\}\s*$/', $gamedata['pgn_movetext'], $matches)) { | |
| 991 | -        $xoopsTpl->assign('chess_result_comment', $matches[1]); | |
| 992 | -    } else { | |
| 993 | -        $xoopsTpl->assign('chess_result_comment', ''); | |
| 994 | - } | |
| 990 | +	if (preg_match('/\{(.*?)\}\s*$/', $gamedata['pgn_movetext'], $matches)) { | |
| 991 | +		$xoopsTpl->assign('chess_result_comment', $matches[1]); | |
| 992 | +	} else { | |
| 993 | +		$xoopsTpl->assign('chess_result_comment', ''); | |
| 994 | + } | |
| 995 | 995 | |
| 996 | -    $xoopsTpl->assign('chess_create_date', '0000-00-00 00:00:00' != $gamedata['create_date'] ? strtotime($gamedata['create_date']) : 0); | |
| 996 | +	$xoopsTpl->assign('chess_create_date', '0000-00-00 00:00:00' != $gamedata['create_date'] ? strtotime($gamedata['create_date']) : 0); | |
| 997 | 997 | |
| 998 | -    $xoopsTpl->assign('chess_start_date', '0000-00-00 00:00:00' != $gamedata['start_date'] ? strtotime($gamedata['start_date']) : 0); | |
| 998 | +	$xoopsTpl->assign('chess_start_date', '0000-00-00 00:00:00' != $gamedata['start_date'] ? strtotime($gamedata['start_date']) : 0); | |
| 999 | 999 | |
| 1000 | -    $xoopsTpl->assign('chess_last_date', '0000-00-00 00:00:00' != $gamedata['last_date'] ? strtotime($gamedata['last_date']) : 0); | |
| 1000 | +	$xoopsTpl->assign('chess_last_date', '0000-00-00 00:00:00' != $gamedata['last_date'] ? strtotime($gamedata['last_date']) : 0); | |
| 1001 | 1001 | |
| 1002 | -    $xoopsTpl->assign('chess_white_user', $white_username); | |
| 1002 | +	$xoopsTpl->assign('chess_white_user', $white_username); | |
| 1003 | 1003 | |
| 1004 | -    $xoopsTpl->assign('chess_black_user', $black_username); | |
| 1004 | +	$xoopsTpl->assign('chess_black_user', $black_username); | |
| 1005 | 1005 | |
| 1006 | -    $xoopsTpl->assign('chess_tiles', $tiles); | |
| 1006 | +	$xoopsTpl->assign('chess_tiles', $tiles); | |
| 1007 | 1007 | |
| 1008 | -    $xoopsTpl->assign('chess_file_labels', $file_labels); | |
| 1008 | +	$xoopsTpl->assign('chess_file_labels', $file_labels); | |
| 1009 | 1009 | |
| 1010 | - $xoopsTpl->assign( | |
| 1011 | - 'chess_pgn_string', | |
| 1012 | - chess_to_pgn_string( | |
| 1013 | - [ | |
| 1014 | - 'event' => '?', | |
| 1015 | - 'site' => $_SERVER['SERVER_NAME'], | |
| 1016 | - 'datetime' => $gamedata['start_date'], | |
| 1017 | - 'round' => '?', | |
| 1018 | - 'white' => $white_username, | |
| 1019 | - 'black' => $black_username, | |
| 1020 | - 'result' => $gamedata['pgn_result'], | |
| 1021 | - 'setup' => !empty($gamedata['pgn_fen']) ? 1 : 0, | |
| 1022 | - 'fen' => $gamedata['pgn_fen'], | |
| 1023 | - 'movetext' => $gamedata['pgn_movetext'], | |
| 1024 | - ] | |
| 1025 | - ) | |
| 1026 | - ); | |
| 1010 | + $xoopsTpl->assign( | |
| 1011 | + 'chess_pgn_string', | |
| 1012 | + chess_to_pgn_string( | |
| 1013 | + [ | |
| 1014 | + 'event' => '?', | |
| 1015 | + 'site' => $_SERVER['SERVER_NAME'], | |
| 1016 | + 'datetime' => $gamedata['start_date'], | |
| 1017 | + 'round' => '?', | |
| 1018 | + 'white' => $white_username, | |
| 1019 | + 'black' => $black_username, | |
| 1020 | + 'result' => $gamedata['pgn_result'], | |
| 1021 | + 'setup' => !empty($gamedata['pgn_fen']) ? 1 : 0, | |
| 1022 | + 'fen' => $gamedata['pgn_fen'], | |
| 1023 | + 'movetext' => $gamedata['pgn_movetext'], | |
| 1024 | + ] | |
| 1025 | + ) | |
| 1026 | + ); | |
| 1027 | 1027 | |
| 1028 | -    $xoopsTpl->assign('chess_movelist', $movelist); | |
| 1028 | +	$xoopsTpl->assign('chess_movelist', $movelist); | |
| 1029 | 1029 | |
| 1030 | -    $xoopsTpl->assign('chess_date_format', _MEDIUMDATESTRING); | |
| 1030 | +	$xoopsTpl->assign('chess_date_format', _MEDIUMDATESTRING); | |
| 1031 | 1031 | |
| 1032 | -    #if (empty($move_result_text)) {$move_result_text = 'test';}#*#DEBUG# | |
| 1032 | +	#if (empty($move_result_text)) {$move_result_text = 'test';}#*#DEBUG# | |
| 1033 | 1033 | |
| 1034 | -    $xoopsTpl->assign('chess_move_performed', $move_performed); | |
| 1034 | +	$xoopsTpl->assign('chess_move_performed', $move_performed); | |
| 1035 | 1035 | |
| 1036 | -    $xoopsTpl->assign('chess_move_result', $move_result_text); | |
| 1036 | +	$xoopsTpl->assign('chess_move_result', $move_result_text); | |
| 1037 | 1037 | |
| 1038 | -    $xoopsTpl->assign('chess_draw_claim_error_text', $draw_claim_error_text); | |
| 1038 | +	$xoopsTpl->assign('chess_draw_claim_error_text', $draw_claim_error_text); | |
| 1039 | 1039 | |
| 1040 | -    $xoopsTpl->assign('chess_user_color', $user_color); | |
| 1040 | +	$xoopsTpl->assign('chess_user_color', $user_color); | |
| 1041 | 1041 | |
| 1042 | -    $xoopsTpl->assign('chess_confirm', $gamedata['w' == $user_color ? 'white_confirm' : 'black_confirm']); | |
| 1042 | +	$xoopsTpl->assign('chess_confirm', $gamedata['w' == $user_color ? 'white_confirm' : 'black_confirm']); | |
| 1043 | 1043 | |
| 1044 | -    $xoopsTpl->assign('chess_orientation', $orientation); | |
| 1044 | +	$xoopsTpl->assign('chess_orientation', $orientation); | |
| 1045 | 1045 | |
| 1046 | -    $xoopsTpl->assign('chess_rank_start', $flip ? 1 : 8); | |
| 1046 | +	$xoopsTpl->assign('chess_rank_start', $flip ? 1 : 8); | |
| 1047 | 1047 | |
| 1048 | -    $xoopsTpl->assign('chess_rank_direction', $flip ? 'up' : 'down'); | |
| 1048 | +	$xoopsTpl->assign('chess_rank_direction', $flip ? 'up' : 'down'); | |
| 1049 | 1049 | |
| 1050 | -    $xoopsTpl->assign('chess_file_start', $flip ? 8 : 1); | |
| 1050 | +	$xoopsTpl->assign('chess_file_start', $flip ? 8 : 1); | |
| 1051 | 1051 | |
| 1052 | -    $xoopsTpl->assign('chess_file_direction', $flip ? 'down' : 'up'); | |
| 1052 | +	$xoopsTpl->assign('chess_file_direction', $flip ? 'down' : 'up'); | |
| 1053 | 1053 | |
| 1054 | - static $pieces = [ | |
| 1055 | - 'K' => ['color' => 'w', 'name' => 'wking', 'alt' => _MD_CHESS_ALT_WKING], | |
| 1056 | - 'Q' => ['color' => 'w', 'name' => 'wqueen', 'alt' => _MD_CHESS_ALT_WQUEEN], | |
| 1057 | - 'R' => ['color' => 'w', 'name' => 'wrook', 'alt' => _MD_CHESS_ALT_WROOK], | |
| 1058 | - 'B' => ['color' => 'w', 'name' => 'wbishop', 'alt' => _MD_CHESS_ALT_WBISHOP], | |
| 1059 | - 'N' => ['color' => 'w', 'name' => 'wknight', 'alt' => _MD_CHESS_ALT_WKNIGHT], | |
| 1060 | - 'P' => ['color' => 'w', 'name' => 'wpawn', 'alt' => _MD_CHESS_ALT_WPAWN], | |
| 1061 | - 'k' => ['color' => 'b', 'name' => 'bking', 'alt' => _MD_CHESS_ALT_BKING], | |
| 1062 | - 'q' => ['color' => 'b', 'name' => 'bqueen', 'alt' => _MD_CHESS_ALT_BQUEEN], | |
| 1063 | - 'r' => ['color' => 'b', 'name' => 'brook', 'alt' => _MD_CHESS_ALT_BROOK], | |
| 1064 | - 'b' => ['color' => 'b', 'name' => 'bbishop', 'alt' => _MD_CHESS_ALT_BBISHOP], | |
| 1065 | - 'n' => ['color' => 'b', 'name' => 'bknight', 'alt' => _MD_CHESS_ALT_BKNIGHT], | |
| 1066 | - 'p' => ['color' => 'b', 'name' => 'bpawn', 'alt' => _MD_CHESS_ALT_BPAWN], | |
| 1067 | - 'x' => ['color' => 'x', 'name' => 'empty', 'alt' => _MD_CHESS_ALT_EMPTY], | |
| 1068 | - ]; | |
| 1054 | + static $pieces = [ | |
| 1055 | + 'K' => ['color' => 'w', 'name' => 'wking', 'alt' => _MD_CHESS_ALT_WKING], | |
| 1056 | + 'Q' => ['color' => 'w', 'name' => 'wqueen', 'alt' => _MD_CHESS_ALT_WQUEEN], | |
| 1057 | + 'R' => ['color' => 'w', 'name' => 'wrook', 'alt' => _MD_CHESS_ALT_WROOK], | |
| 1058 | + 'B' => ['color' => 'w', 'name' => 'wbishop', 'alt' => _MD_CHESS_ALT_WBISHOP], | |
| 1059 | + 'N' => ['color' => 'w', 'name' => 'wknight', 'alt' => _MD_CHESS_ALT_WKNIGHT], | |
| 1060 | + 'P' => ['color' => 'w', 'name' => 'wpawn', 'alt' => _MD_CHESS_ALT_WPAWN], | |
| 1061 | + 'k' => ['color' => 'b', 'name' => 'bking', 'alt' => _MD_CHESS_ALT_BKING], | |
| 1062 | + 'q' => ['color' => 'b', 'name' => 'bqueen', 'alt' => _MD_CHESS_ALT_BQUEEN], | |
| 1063 | + 'r' => ['color' => 'b', 'name' => 'brook', 'alt' => _MD_CHESS_ALT_BROOK], | |
| 1064 | + 'b' => ['color' => 'b', 'name' => 'bbishop', 'alt' => _MD_CHESS_ALT_BBISHOP], | |
| 1065 | + 'n' => ['color' => 'b', 'name' => 'bknight', 'alt' => _MD_CHESS_ALT_BKNIGHT], | |
| 1066 | + 'p' => ['color' => 'b', 'name' => 'bpawn', 'alt' => _MD_CHESS_ALT_BPAWN], | |
| 1067 | + 'x' => ['color' => 'x', 'name' => 'empty', 'alt' => _MD_CHESS_ALT_EMPTY], | |
| 1068 | + ]; | |
| 1069 | 1069 | |
| 1070 | -    $xoopsTpl->assign('chess_pieces', $pieces); | |
| 1070 | +	$xoopsTpl->assign('chess_pieces', $pieces); | |
| 1071 | 1071 | |
| 1072 | -    $xoopsTpl->assign('chess_show_arbitration_controls', $show_arbiter_ctrl); | |
| 1072 | +	$xoopsTpl->assign('chess_show_arbitration_controls', $show_arbiter_ctrl); | |
| 1073 | 1073 | |
| 1074 | -    if ($show_arbiter_ctrl && $gamedata['suspended']) { | |
| 1075 | -        [$susp_date, $susp_uid, $susp_type, $susp_explain] = explode('|', $gamedata['suspended']); | |
| 1074 | +	if ($show_arbiter_ctrl && $gamedata['suspended']) { | |
| 1075 | +		[$susp_date, $susp_uid, $susp_type, $susp_explain] = explode('|', $gamedata['suspended']); | |
| 1076 | 1076 | |
| 1077 | -        switch ($susp_type) { | |
| 1078 | - case 'arbiter_suspend': | |
| 1079 | - $susp_type_display = _MD_CHESS_SUSP_TYPE_ARBITER; | |
| 1080 | - break; | |
| 1081 | - case 'want_arbitration': | |
| 1082 | - $susp_type_display = _MD_CHESS_SUSP_TYPE_PLAYER; | |
| 1083 | - break; | |
| 1084 | - default: | |
| 1085 | - $susp_type_display = _MD_CHESS_LABEL_ERROR; | |
| 1086 | - break; | |
| 1087 | - } | |
| 1077 | +		switch ($susp_type) { | |
| 1078 | + case 'arbiter_suspend': | |
| 1079 | + $susp_type_display = _MD_CHESS_SUSP_TYPE_ARBITER; | |
| 1080 | + break; | |
| 1081 | + case 'want_arbitration': | |
| 1082 | + $susp_type_display = _MD_CHESS_SUSP_TYPE_PLAYER; | |
| 1083 | + break; | |
| 1084 | + default: | |
| 1085 | + $susp_type_display = _MD_CHESS_LABEL_ERROR; | |
| 1086 | + break; | |
| 1087 | + } | |
| 1088 | 1088 | |
| 1089 | - $susp_user = $memberHandler->getUser($susp_uid); | |
| 1089 | + $susp_user = $memberHandler->getUser($susp_uid); | |
| 1090 | 1090 | |
| 1091 | -        $susp_username = is_object($susp_user) ? $susp_user->getVar('uname') : _MD_CHESS_UNKNOWN; | |
| 1091 | +		$susp_username = is_object($susp_user) ? $susp_user->getVar('uname') : _MD_CHESS_UNKNOWN; | |
| 1092 | 1092 | |
| 1093 | - $suspend_info = [ | |
| 1094 | - 'date' => strtotime($susp_date), | |
| 1095 | - 'user' => $susp_username, | |
| 1096 | - 'type' => $susp_type_display, | |
| 1097 | - 'reason' => $susp_explain, | |
| 1098 | - ]; | |
| 1093 | + $suspend_info = [ | |
| 1094 | + 'date' => strtotime($susp_date), | |
| 1095 | + 'user' => $susp_username, | |
| 1096 | + 'type' => $susp_type_display, | |
| 1097 | + 'reason' => $susp_explain, | |
| 1098 | + ]; | |
| 1099 | 1099 | |
| 1100 | -        $xoopsTpl->assign('chess_suspend_info', $suspend_info); | |
| 1101 | - } | |
| 1100 | +		$xoopsTpl->assign('chess_suspend_info', $suspend_info); | |
| 1101 | + } | |
| 1102 | 1102 | |
| 1103 | - // Initialize $captured_pieces_all to indicate all pieces captured, then subtract off the pieces remaining on the board. | |
| 1103 | + // Initialize $captured_pieces_all to indicate all pieces captured, then subtract off the pieces remaining on the board. | |
| 1104 | 1104 | |
| 1105 | - $captured_pieces_all = [ | |
| 1106 | - 'Q' => 1, | |
| 1107 | - 'R' => 2, | |
| 1108 | - 'B' => 2, | |
| 1109 | - 'N' => 2, | |
| 1110 | - 'P' => 8, | |
| 1111 | - 'q' => 1, | |
| 1112 | - 'r' => 2, | |
| 1113 | - 'b' => 2, | |
| 1114 | - 'n' => 2, | |
| 1115 | - 'p' => 8, | |
| 1116 | - ]; | |
| 1105 | + $captured_pieces_all = [ | |
| 1106 | + 'Q' => 1, | |
| 1107 | + 'R' => 2, | |
| 1108 | + 'B' => 2, | |
| 1109 | + 'N' => 2, | |
| 1110 | + 'P' => 8, | |
| 1111 | + 'q' => 1, | |
| 1112 | + 'r' => 2, | |
| 1113 | + 'b' => 2, | |
| 1114 | + 'n' => 2, | |
| 1115 | + 'p' => 8, | |
| 1116 | + ]; | |
| 1117 | 1117 | |
| 1118 | -    for ($i = 0, $iMax = mb_strlen($gamedata['fen_piece_placement']); $i < $iMax; ++$i) { | |
| 1119 | - $piece = $gamedata['fen_piece_placement'][$i]; | |
| 1118 | +	for ($i = 0, $iMax = mb_strlen($gamedata['fen_piece_placement']); $i < $iMax; ++$i) { | |
| 1119 | + $piece = $gamedata['fen_piece_placement'][$i]; | |
| 1120 | 1120 | |
| 1121 | -        if (!empty($captured_pieces_all[$piece])) { | |
| 1122 | - --$captured_pieces_all[$piece]; | |
| 1123 | - } | |
| 1124 | - } | |
| 1121 | +		if (!empty($captured_pieces_all[$piece])) { | |
| 1122 | + --$captured_pieces_all[$piece]; | |
| 1123 | + } | |
| 1124 | + } | |
| 1125 | 1125 | |
| 1126 | - // Construct lists of white's and black's captured pieces. | |
| 1126 | + // Construct lists of white's and black's captured pieces. | |
| 1127 | 1127 | |
| 1128 | - $captured_pieces = ['white' => [], 'black' => []]; | |
| 1128 | + $captured_pieces = ['white' => [], 'black' => []]; | |
| 1129 | 1129 | |
| 1130 | -    foreach ($captured_pieces_all as $piece => $count) { | |
| 1131 | -        if ($count > 0) { | |
| 1132 | -            if (ctype_upper($piece)) { | |
| 1133 | - $captured_pieces['white'] = array_merge($captured_pieces['white'], array_pad([], $count, $piece)); | |
| 1134 | -            } elseif (ctype_lower($piece)) { | |
| 1135 | - $captured_pieces['black'] = array_merge($captured_pieces['black'], array_pad([], $count, $piece)); | |
| 1136 | - } | |
| 1137 | - } | |
| 1138 | - } | |
| 1130 | +	foreach ($captured_pieces_all as $piece => $count) { | |
| 1131 | +		if ($count > 0) { | |
| 1132 | +			if (ctype_upper($piece)) { | |
| 1133 | + $captured_pieces['white'] = array_merge($captured_pieces['white'], array_pad([], $count, $piece)); | |
| 1134 | +			} elseif (ctype_lower($piece)) { | |
| 1135 | + $captured_pieces['black'] = array_merge($captured_pieces['black'], array_pad([], $count, $piece)); | |
| 1136 | + } | |
| 1137 | + } | |
| 1138 | + } | |
| 1139 | 1139 | |
| 1140 | -    #var_dump('captured_pieces_all', $captured_pieces_all);#*#DEBUG# | |
| 1140 | +	#var_dump('captured_pieces_all', $captured_pieces_all);#*#DEBUG# | |
| 1141 | 1141 | |
| 1142 | -    #var_dump('captured_pieces', $captured_pieces);#*#DEBUG# | |
| 1142 | +	#var_dump('captured_pieces', $captured_pieces);#*#DEBUG# | |
| 1143 | 1143 | |
| 1144 | -    $xoopsTpl->assign('chess_captured_pieces', $captured_pieces); | |
| 1144 | +	$xoopsTpl->assign('chess_captured_pieces', $captured_pieces); | |
| 1145 | 1145 | |
| 1146 | -    $xoopsTpl->assign('chess_pawn_promote_choices', 'w' == $gamedata['fen_active_color'] ? ['Q', 'R', 'B', 'N'] : ['q', 'r', 'b', 'n']); | |
| 1146 | +	$xoopsTpl->assign('chess_pawn_promote_choices', 'w' == $gamedata['fen_active_color'] ? ['Q', 'R', 'B', 'N'] : ['q', 'r', 'b', 'n']); | |
| 1147 | 1147 | |
| 1148 | -    $xoopsTpl->assign('chess_allow_delete', chess_can_delete()); | |
| 1148 | +	$xoopsTpl->assign('chess_allow_delete', chess_can_delete()); | |
| 1149 | 1149 | |
| 1150 | - // popup window contents for selecting piece to which pawn is promoted | |
| 1150 | + // popup window contents for selecting piece to which pawn is promoted | |
| 1151 | 1151 | |
| 1152 | - // (Note that template is compiled here by fetch(), so any template variables it uses must already be defined.) | |
| 1152 | + // (Note that template is compiled here by fetch(), so any template variables it uses must already be defined.) | |
| 1153 | 1153 | |
| 1154 | -    $xoopsTpl->assign('chess_pawn_promote_popup', $user_color ? $xoopsTpl->fetch('db:chess_game_promote_popup.tpl') : ''); | |
| 1154 | +	$xoopsTpl->assign('chess_pawn_promote_popup', $user_color ? $xoopsTpl->fetch('db:chess_game_promote_popup.tpl') : ''); | |
| 1155 | 1155 | |
| 1156 | -    $xoopsTpl->assign('chess_ratings_enabled', 'none' != chess_moduleConfig('rating_system')); | |
| 1156 | +	$xoopsTpl->assign('chess_ratings_enabled', 'none' != chess_moduleConfig('rating_system')); | |
| 1157 | 1157 | |
| 1158 | - // security token | |
| 1158 | + // security token | |
| 1159 | 1159 | |
| 1160 | -    $xoopsTpl->assign('chess_xoops_request_token', is_object($GLOBALS['xoopsSecurity']) ? $GLOBALS['xoopsSecurity']->getTokenHTML() : ''); | |
| 1160 | +	$xoopsTpl->assign('chess_xoops_request_token', is_object($GLOBALS['xoopsSecurity']) ? $GLOBALS['xoopsSecurity']->getTokenHTML() : ''); | |
| 1161 | 1161 | } | 
| 1162 | 1162 | |
| 1163 | 1163 | ?> | 
| @@ -40,19 +40,19 @@ discard block | ||
| 40 | 40 | |
| 41 | 41 | /**#@+ | 
| 42 | 42 | */ | 
| 43 | -require_once dirname(__DIR__, 2) . '/mainfile.php'; | |
| 44 | -require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; | |
| 43 | +require_once dirname(__DIR__, 2).'/mainfile.php'; | |
| 44 | +require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; | |
| 45 | 45 | |
| 46 | 46 | $GLOBALS['xoopsOption']['template_main'] = 'chess_game_main.tpl'; | 
| 47 | 47 |  $xoopsConfig['module_cache'][$xoopsModule->getVar('mid')] = 0; // disable caching | 
| 48 | -require_once XOOPS_ROOT_PATH . '/header.php'; | |
| 49 | -require_once XOOPS_ROOT_PATH . '/modules/chess/include/constants.inc.php'; | |
| 50 | -require_once XOOPS_ROOT_PATH . '/modules/chess/include/functions.php'; | |
| 48 | +require_once XOOPS_ROOT_PATH.'/header.php'; | |
| 49 | +require_once XOOPS_ROOT_PATH.'/modules/chess/include/constants.inc.php'; | |
| 50 | +require_once XOOPS_ROOT_PATH.'/modules/chess/include/functions.php'; | |
| 51 | 51 | |
| 52 | 52 | chess_game(); | 
| 53 | 53 | |
| 54 | -require_once XOOPS_ROOT_PATH . '/include/comment_view.php'; | |
| 55 | -require_once XOOPS_ROOT_PATH . '/footer.php'; | |
| 54 | +require_once XOOPS_ROOT_PATH.'/include/comment_view.php'; | |
| 55 | +require_once XOOPS_ROOT_PATH.'/footer.php'; | |
| 56 | 56 | /**#@-*/ | 
| 57 | 57 | |
| 58 | 58 | /** | 
| @@ -68,7 +68,7 @@ discard block | ||
| 68 | 68 |  { | 
| 69 | 69 | // user input | 
| 70 | 70 | |
| 71 | - $game_id = (int)@$_GET['game_id']; | |
| 71 | + $game_id = (int) @$_GET['game_id']; | |
| 72 | 72 | |
| 73 | 73 | $submit_move = isset($_POST['submit_move']); | 
| 74 | 74 | |
| @@ -96,9 +96,9 @@ discard block | ||
| 96 | 96 | |
| 97 | 97 |      if (($submit_move || $submit_refresh || $submit_arbitrate || $show_arbiter_ctrl) && is_object($GLOBALS['xoopsSecurity']) && !$GLOBALS['xoopsSecurity']->check()) { | 
| 98 | 98 | redirect_header( | 
| 99 | - XOOPS_URL . '/modules/chess/', | |
| 99 | + XOOPS_URL.'/modules/chess/', | |
| 100 | 100 | _CHESS_REDIRECT_DELAY_FAILURE, | 
| 101 | -            _MD_CHESS_TOKEN_ERROR . '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()) | |
| 101 | +            _MD_CHESS_TOKEN_ERROR.'<br>'.implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()) | |
| 102 | 102 | ); | 
| 103 | 103 | } | 
| 104 | 104 | |
| @@ -107,15 +107,15 @@ discard block | ||
| 107 | 107 | $gamedata = chess_get_game($game_id); | 
| 108 | 108 | |
| 109 | 109 |      if (false === $gamedata) { | 
| 110 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 110 | + redirect_header(XOOPS_URL.'/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 111 | 111 | } | 
| 112 | 112 | |
| 113 | 113 | $gamedata_updated = false; | 
| 114 | 114 | |
| 115 | 115 | $move_performed = false; // status result from move-handler | 
| 116 | - $move_result_text = ''; // text result from move-handler | |
| 117 | - $draw_claim_error_text = ''; // text describing invalid draw-claim | |
| 118 | - $notify = ''; // text description of action for notification | |
| 116 | + $move_result_text = ''; // text result from move-handler | |
| 117 | + $draw_claim_error_text = ''; // text describing invalid draw-claim | |
| 118 | + $notify = ''; // text description of action for notification | |
| 119 | 119 | $delete_game = false; | 
| 120 | 120 | |
| 121 | 121 | global $xoopsUser; | 
| @@ -128,7 +128,7 @@ discard block | ||
| 128 | 128 |          if ($uid == $gamedata['white_uid']) { | 
| 129 | 129 | $user_color = $gamedata['fen_active_color']; // current user is either player, so consider him active player | 
| 130 | 130 |          } else { | 
| 131 | - $user_color = ''; // current user is not a player | |
| 131 | + $user_color = ''; // current user is not a player | |
| 132 | 132 | } | 
| 133 | 133 | // not self-play | 
| 134 | 134 |      } else { | 
| @@ -137,7 +137,7 @@ discard block | ||
| 137 | 137 |          } elseif ($uid == $gamedata['black_uid']) { | 
| 138 | 138 | $user_color = 'b'; // current user is black | 
| 139 | 139 |          } else { | 
| 140 | - $user_color = ''; // current user is not a player | |
| 140 | + $user_color = ''; // current user is not a player | |
| 141 | 141 | } | 
| 142 | 142 | } | 
| 143 | 143 | |
| @@ -225,7 +225,7 @@ discard block | ||
| 225 | 225 | |
| 226 | 226 | $gamedata['pgn_result'] = '1/2-1/2'; | 
| 227 | 227 | |
| 228 | -                        $comment = '{' . $draw_claim_text . '}'; | |
| 228 | +                        $comment = '{'.$draw_claim_text.'}'; | |
| 229 | 229 | |
| 230 | 230 |                          $gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | 
| 231 | 231 | |
| @@ -243,13 +243,13 @@ discard block | ||
| 243 | 243 | |
| 244 | 244 | $gamedata['pgn_result'] = 'w' == $user_color ? '0-1' : '1-0'; | 
| 245 | 245 | |
| 246 | -                    $comment = '{' . $user_color_name . ' ' . _MD_CHESS_RESIGNED . '}'; | |
| 246 | +                    $comment = '{'.$user_color_name.' '._MD_CHESS_RESIGNED.'}'; | |
| 247 | 247 | |
| 248 | 248 |                      $gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | 
| 249 | 249 | |
| 250 | 250 | $gamedata_updated = true; | 
| 251 | 251 | |
| 252 | - $notify = "$user_color_name " . _MD_CHESS_RESIGNED; | |
| 252 | + $notify = "$user_color_name "._MD_CHESS_RESIGNED; | |
| 253 | 253 | } | 
| 254 | 254 | break; | 
| 255 | 255 | case _CHESS_MOVETYPE_OFFER_DRAW: | 
| @@ -258,7 +258,7 @@ discard block | ||
| 258 | 258 | |
| 259 | 259 | $gamedata_updated = true; | 
| 260 | 260 | |
| 261 | - $notify = "$user_color_name " . _MD_CHESS_OFFERED_DRAW; | |
| 261 | + $notify = "$user_color_name "._MD_CHESS_OFFERED_DRAW; | |
| 262 | 262 | } | 
| 263 | 263 | break; | 
| 264 | 264 | case _CHESS_MOVETYPE_ACCEPT_DRAW: | 
| @@ -267,13 +267,13 @@ discard block | ||
| 267 | 267 | |
| 268 | 268 | $gamedata['pgn_result'] = '1/2-1/2'; | 
| 269 | 269 | |
| 270 | -                    $comment = '{' . _MD_CHESS_DRAW_BY_AGREEMENT . '}'; | |
| 270 | +                    $comment = '{'._MD_CHESS_DRAW_BY_AGREEMENT.'}'; | |
| 271 | 271 | |
| 272 | 272 |                      $gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | 
| 273 | 273 | |
| 274 | 274 | $gamedata_updated = true; | 
| 275 | 275 | |
| 276 | - $notify = "$user_color_name " . _MD_CHESS_ACCEPTED_DRAW; | |
| 276 | + $notify = "$user_color_name "._MD_CHESS_ACCEPTED_DRAW; | |
| 277 | 277 | } | 
| 278 | 278 | |
| 279 | 279 | // no break | 
| @@ -283,7 +283,7 @@ discard block | ||
| 283 | 283 | |
| 284 | 284 | $gamedata_updated = true; | 
| 285 | 285 | |
| 286 | - $notify = "$user_color_name " . _MD_CHESS_REJECTED_DRAW; | |
| 286 | + $notify = "$user_color_name "._MD_CHESS_REJECTED_DRAW; | |
| 287 | 287 | } | 
| 288 | 288 | break; | 
| 289 | 289 | case _CHESS_MOVETYPE_RESTART: | 
| @@ -324,7 +324,7 @@ discard block | ||
| 324 | 324 | case _CHESS_MOVETYPE_DELETE: | 
| 325 | 325 |                  if ($user_is_player && ($selfplay || chess_can_delete())) { | 
| 326 | 326 | $delete_game = true; // must defer actual deletion until after notifications are sent | 
| 327 | -                    $notify      = eval('return \'' . _MD_CHESS_DELETED_GAME . '\';'); // eval references $username | |
| 327 | +                    $notify      = eval('return \''._MD_CHESS_DELETED_GAME.'\';'); // eval references $username | |
| 328 | 328 | } | 
| 329 | 329 | break; | 
| 330 | 330 | case _CHESS_MOVETYPE_WANT_ARBITRATION: | 
| @@ -339,7 +339,7 @@ discard block | ||
| 339 | 339 | |
| 340 | 340 | $gamedata_updated = true; | 
| 341 | 341 | |
| 342 | - $notify = "$user_color_name " . _MD_CHESS_RQSTED_ARBT . ' ' . _MD_CHESS_BEEN_SUSPENDED; | |
| 342 | + $notify = "$user_color_name "._MD_CHESS_RQSTED_ARBT.' '._MD_CHESS_BEEN_SUSPENDED; | |
| 343 | 343 | } | 
| 344 | 344 | break; | 
| 345 | 345 | } | 
| @@ -373,7 +373,7 @@ discard block | ||
| 373 | 373 | |
| 374 | 374 | $gamedata_updated = true; | 
| 375 | 375 | |
| 376 | -                    $notify = eval('return \'' . _MD_CHESS_RESUMED_PLAY . '\';'); // eval references $username | |
| 376 | +                    $notify = eval('return \''._MD_CHESS_RESUMED_PLAY.'\';'); // eval references $username | |
| 377 | 377 | } | 
| 378 | 378 | break; | 
| 379 | 379 | case _CHESS_ARBITER_DRAW: | 
| @@ -386,7 +386,7 @@ discard block | ||
| 386 | 386 | |
| 387 | 387 |                      $arbiter_explain = str_replace('}', ')', $arbiter_explain); | 
| 388 | 388 | |
| 389 | -                    $comment = '{' . sprintf(_MD_CHESS_DRAW_DECLARED, $arbiter_explain) . '}'; | |
| 389 | +                    $comment = '{'.sprintf(_MD_CHESS_DRAW_DECLARED, $arbiter_explain).'}'; | |
| 390 | 390 | |
| 391 | 391 |                      $gamedata['pgn_movetext'] = str_replace('*', "{$gamedata['pgn_result']} $comment", $gamedata['pgn_movetext']); | 
| 392 | 392 | |
| @@ -394,13 +394,13 @@ discard block | ||
| 394 | 394 | |
| 395 | 395 | $gamedata_updated = true; | 
| 396 | 396 | |
| 397 | -                    $notify = eval('return \'' . _MD_CHESS_DECLARED_DRAW . '\';'); // eval references $username | |
| 397 | +                    $notify = eval('return \''._MD_CHESS_DECLARED_DRAW.'\';'); // eval references $username | |
| 398 | 398 | } | 
| 399 | 399 | break; | 
| 400 | 400 | case _CHESS_ARBITER_DELETE: | 
| 401 | 401 |                  if ($gamedata['suspended']) { | 
| 402 | 402 | $delete_game = true; // must defer actual deletion until after notifications are sent | 
| 403 | -                    $notify      = eval('return \'' . _MD_CHESS_DELETED_GAME . '\';'); // eval references $username | |
| 403 | +                    $notify      = eval('return \''._MD_CHESS_DELETED_GAME.'\';'); // eval references $username | |
| 404 | 404 | } | 
| 405 | 405 | break; | 
| 406 | 406 | case _CHESS_ARBITER_SUSPEND: | 
| @@ -415,7 +415,7 @@ discard block | ||
| 415 | 415 | |
| 416 | 416 | $gamedata_updated = true; | 
| 417 | 417 | |
| 418 | -                    $notify = eval('return \'' . _MD_CHESS_SUSPENDED_PLAY . '\';'); // eval references $username | |
| 418 | +                    $notify = eval('return \''._MD_CHESS_SUSPENDED_PLAY.'\';'); // eval references $username | |
| 419 | 419 | } | 
| 420 | 420 | break; | 
| 421 | 421 | default: | 
| @@ -447,7 +447,7 @@ discard block | ||
| 447 | 447 |          if (_CHESS_MOVETYPE_WANT_ARBITRATION == $movetype) { | 
| 448 | 448 | $event = 'notify_request_arbitration'; | 
| 449 | 449 | |
| 450 | -            $username = $xoopsUser ? $xoopsUser->getVar('uname') : '(' . _MD_CHESS_UNKNOWN . ')'; | |
| 450 | +            $username = $xoopsUser ? $xoopsUser->getVar('uname') : '('._MD_CHESS_UNKNOWN.')'; | |
| 451 | 451 | |
| 452 | 452 | $extra_tags = ['CHESS_REQUESTOR' => $username, 'CHESS_GAME_ID' => $game_id, 'CHESS_EXPLAIN' => $move_explain]; | 
| 453 | 453 | |
| @@ -460,7 +460,7 @@ discard block | ||
| 460 | 460 |      if ($delete_game) { | 
| 461 | 461 | chess_delete_game($game_id); | 
| 462 | 462 | |
| 463 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_DELETED); | |
| 463 | + redirect_header(XOOPS_URL.'/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_DELETED); | |
| 464 | 464 | } | 
| 465 | 465 | } | 
| 466 | 466 | |
| @@ -532,11 +532,11 @@ discard block | ||
| 532 | 532 | ); | 
| 533 | 533 | |
| 534 | 534 |      if ($xoopsDB->errno()) { | 
| 535 | - trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 535 | + trigger_error($xoopsDB->errno().':'.$xoopsDB->error(), E_USER_ERROR); | |
| 536 | 536 | } | 
| 537 | 537 | |
| 538 | 538 |      if ('*' != $gamedata['pgn_result'] && '1' == $gamedata['is_rated']) { | 
| 539 | - require_once XOOPS_ROOT_PATH . '/modules/chess/include/ratings.php'; | |
| 539 | + require_once XOOPS_ROOT_PATH.'/modules/chess/include/ratings.php'; | |
| 540 | 540 | |
| 541 | 541 | chess_ratings_adj($game_id); | 
| 542 | 542 | } | 
| @@ -560,7 +560,7 @@ discard block | ||
| 560 | 560 |      $xoopsDB->query("DELETE FROM $table WHERE game_id='$game_id'"); | 
| 561 | 561 | |
| 562 | 562 |      if ($xoopsDB->errno()) { | 
| 563 | - trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 563 | + trigger_error($xoopsDB->errno().':'.$xoopsDB->error(), E_USER_ERROR); | |
| 564 | 564 | } | 
| 565 | 565 | } | 
| 566 | 566 | |
| @@ -733,7 +733,7 @@ discard block | ||
| 733 | 733 | |
| 734 | 734 | // The current position is included, since that's the position against which the other positions will be compared. | 
| 735 | 735 | |
| 736 | - $repeats[] = $gamedata['fen_fullmove_number'] . $gamedata['fen_active_color']; | |
| 736 | + $repeats[] = $gamedata['fen_fullmove_number'].$gamedata['fen_active_color']; | |
| 737 | 737 | |
| 738 | 738 | // Compare initial board position with last board position, unless the move number is the same, meaning that there haven't been any moves. | 
| 739 | 739 | |
| @@ -742,7 +742,7 @@ discard block | ||
| 742 | 742 |      $board_state = "{$tmp_gamedata['fen_piece_placement']} {$tmp_gamedata['fen_active_color']} {$tmp_gamedata['fen_castling_availability']} {$tmp_gamedata['fen_en_passant_target_square']}"; | 
| 743 | 743 | |
| 744 | 744 |      if ($tmp_gamedata['fen_fullmove_number'] != $last_move_number && $board_state == $last_board_state) { | 
| 745 | - $repeats[] = $tmp_gamedata['fen_fullmove_number'] . $tmp_gamedata['fen_active_color']; | |
| 745 | + $repeats[] = $tmp_gamedata['fen_fullmove_number'].$tmp_gamedata['fen_active_color']; | |
| 746 | 746 | |
| 747 | 747 |          if (CHESS_LOG_3FOLD) { | 
| 748 | 748 |              $log[] = sprintf('%08x %03d%1s %s', crc32($board_state), $tmp_gamedata['fen_fullmove_number'], $tmp_gamedata['fen_active_color'], $board_state); | 
| @@ -807,7 +807,7 @@ discard block | ||
| 807 | 807 | } | 
| 808 | 808 | |
| 809 | 809 |              if ($tmp_gamedata['fen_fullmove_number'] != $last_move_number && $board_state == $last_board_state) { | 
| 810 | - $repeats[] = $tmp_gamedata['fen_fullmove_number'] . $tmp_gamedata['fen_active_color']; | |
| 810 | + $repeats[] = $tmp_gamedata['fen_fullmove_number'].$tmp_gamedata['fen_active_color']; | |
| 811 | 811 | |
| 812 | 812 | #*#DEBUG# - start | 
| 813 | 813 | |
| @@ -854,7 +854,7 @@ discard block | ||
| 854 | 854 | } | 
| 855 | 855 | |
| 856 | 856 |      if (CHESS_LOG_3FOLD) { | 
| 857 | -        $logfile = XOOPS_ROOT_PATH . '/cache/' . date('Ymd_His') . '_3fold.log'; | |
| 857 | +        $logfile = XOOPS_ROOT_PATH.'/cache/'.date('Ymd_His').'_3fold.log'; | |
| 858 | 858 | |
| 859 | 859 | sort($log); | 
| 860 | 860 | |
| @@ -917,7 +917,7 @@ discard block | ||
| 917 | 917 | $xoopsTpl->assign( | 
| 918 | 918 | 'xoops_module_header', | 
| 919 | 919 | ' | 
| 920 | - <link rel="stylesheet" type="text/css" media="screen" href="' . XOOPS_URL . '/modules/chess/assets/css/style.css"> | |
| 920 | + <link rel="stylesheet" type="text/css" media="screen" href="' . XOOPS_URL.'/modules/chess/assets/css/style.css"> | |
| 921 | 921 | ' | 
| 922 | 922 | ); | 
| 923 | 923 | |
| @@ -960,7 +960,7 @@ discard block | ||
| 960 | 960 | $expanded_row = preg_replace_callback( | 
| 961 | 961 | '/(\d)/', | 
| 962 | 962 | |
| 963 | -            static function ($matches) { | |
| 963 | +            static function($matches) { | |
| 964 | 964 |                  return str_repeat('x', $matches[1]); | 
| 965 | 965 | }, | 
| 966 | 966 | $rank | 
| @@ -30,63 +30,63 @@ discard block | ||
| 30 | 30 | */ | 
| 31 | 31 | function perform() | 
| 32 | 32 |  { | 
| 33 | - $challenges_table = 'chess_challenges'; | |
| 33 | + $challenges_table = 'chess_challenges'; | |
| 34 | 34 | |
| 35 | - $games_table = 'chess_games'; | |
| 35 | + $games_table = 'chess_games'; | |
| 36 | 36 | |
| 37 | - $ratings_table = 'chess_ratings'; | |
| 37 | + $ratings_table = 'chess_ratings'; | |
| 38 | 38 | |
| 39 | -    mysqli_connect(DBHOST, DBUSER, DBPASS) or trigger_error('[' . $GLOBALS['xoopsDB']->errno() . '] ' . $GLOBALS['xoopsDB']->error(), E_USER_ERROR); | |
| 39 | +	mysqli_connect(DBHOST, DBUSER, DBPASS) or trigger_error('[' . $GLOBALS['xoopsDB']->errno() . '] ' . $GLOBALS['xoopsDB']->error(), E_USER_ERROR); | |
| 40 | 40 | |
| 41 | -    mysqli_select_db($GLOBALS['xoopsDB']->conn, DBNAME) or trigger_error('[' . $GLOBALS['xoopsDB']->errno() . '] ' . $GLOBALS['xoopsDB']->error(), E_USER_ERROR); | |
| 41 | +	mysqli_select_db($GLOBALS['xoopsDB']->conn, DBNAME) or trigger_error('[' . $GLOBALS['xoopsDB']->errno() . '] ' . $GLOBALS['xoopsDB']->error(), E_USER_ERROR); | |
| 42 | 42 | |
| 43 | - // For safety, don't generate test data unless the tables are empty. | |
| 43 | + // For safety, don't generate test data unless the tables are empty. | |
| 44 | 44 | |
| 45 | -    if (!table_empty($challenges_table) || !table_empty($games_table) || !table_empty($ratings_table)) { | |
| 46 | - echo "Tables already contain data - no action performed.\n"; | |
| 45 | +	if (!table_empty($challenges_table) || !table_empty($games_table) || !table_empty($ratings_table)) { | |
| 46 | + echo "Tables already contain data - no action performed.\n"; | |
| 47 | 47 | |
| 48 | - exit; | |
| 49 | - } | |
| 48 | + exit; | |
| 49 | + } | |
| 50 | 50 | |
| 51 | - // Generate the challenges table | |
| 51 | + // Generate the challenges table | |
| 52 | 52 | |
| 53 | - $game_types = ['open', 'user']; | |
| 53 | + $game_types = ['open', 'user']; | |
| 54 | 54 | |
| 55 | - $color_options = ['player2', 'random', 'white', 'black']; | |
| 55 | + $color_options = ['player2', 'random', 'white', 'black']; | |
| 56 | 56 | |
| 57 | -    for ($i = 0; $i < NUM_CHALLENGES; ++$i) { | |
| 58 | - $game_type = rand_array_value($game_types); | |
| 57 | +	for ($i = 0; $i < NUM_CHALLENGES; ++$i) { | |
| 58 | + $game_type = rand_array_value($game_types); | |
| 59 | 59 | |
| 60 | - $fen_index = random_int(1, 10); | |
| 60 | + $fen_index = random_int(1, 10); | |
| 61 | 61 | |
| 62 | - $fen = 10 == $fen_index ? 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' : ''; | |
| 62 | + $fen = 10 == $fen_index ? 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' : ''; | |
| 63 | 63 | |
| 64 | - $color_option = rand_array_value($color_options); | |
| 64 | + $color_option = rand_array_value($color_options); | |
| 65 | 65 | |
| 66 | - $notify_move_player1 = random_int(0, 1); | |
| 66 | + $notify_move_player1 = random_int(0, 1); | |
| 67 | 67 | |
| 68 | - $player1_uid = random_int(1, NUM_USERS); | |
| 68 | + $player1_uid = random_int(1, NUM_USERS); | |
| 69 | 69 | |
| 70 | -        if ('open' == $game_type) { | |
| 71 | - $player2_uid = 0; | |
| 72 | -        } else { | |
| 73 | - // select $player2_uid != $player1_uid | |
| 70 | +		if ('open' == $game_type) { | |
| 71 | + $player2_uid = 0; | |
| 72 | +		} else { | |
| 73 | + // select $player2_uid != $player1_uid | |
| 74 | 74 | |
| 75 | -            do { | |
| 76 | - $player2_uid = random_int(1, NUM_USERS); | |
| 77 | - } while ($player2_uid == $player1_uid); | |
| 78 | - } | |
| 75 | +			do { | |
| 76 | + $player2_uid = random_int(1, NUM_USERS); | |
| 77 | + } while ($player2_uid == $player1_uid); | |
| 78 | + } | |
| 79 | 79 | |
| 80 | - $create_date_max = time(); | |
| 80 | + $create_date_max = time(); | |
| 81 | 81 | |
| 82 | - $create_date_min = $create_date_max - 30 * 24 * 3600; | |
| 82 | + $create_date_min = $create_date_max - 30 * 24 * 3600; | |
| 83 | 83 | |
| 84 | -        $create_date = date('Y-m-d H:i:s', random_int($create_date_min, $create_date_max)); | |
| 84 | +		$create_date = date('Y-m-d H:i:s', random_int($create_date_min, $create_date_max)); | |
| 85 | 85 | |
| 86 | - $is_rated = random_int(0, 1); | |
| 86 | + $is_rated = random_int(0, 1); | |
| 87 | 87 | |
| 88 | - do_query( | |
| 89 | - " | |
| 88 | + do_query( | |
| 89 | + " | |
| 90 | 90 | INSERT INTO $challenges_table | 
| 91 | 91 | SET | 
| 92 | 92 | game_type = '$game_type', | 
| @@ -98,68 +98,68 @@ discard block | ||
| 98 | 98 | create_date = '$create_date', | 
| 99 | 99 | is_rated = '$is_rated' | 
| 100 | 100 | " | 
| 101 | - ); | |
| 102 | - } | |
| 101 | + ); | |
| 102 | + } | |
| 103 | 103 | |
| 104 | - // Generate the games table | |
| 104 | + // Generate the games table | |
| 105 | 105 | |
| 106 | - $pgn_results = ['*', '0-1', '1-0', '1/2-1/2']; | |
| 106 | + $pgn_results = ['*', '0-1', '1-0', '1/2-1/2']; | |
| 107 | 107 | |
| 108 | - $suspended_explains = ['foo', 'bar', 'baz', 'quux']; | |
| 108 | + $suspended_explains = ['foo', 'bar', 'baz', 'quux']; | |
| 109 | 109 | |
| 110 | -    for ($i = 0; $i < NUM_GAMES; ++$i) { | |
| 111 | - $white_uid = random_int(1, NUM_USERS); | |
| 110 | +	for ($i = 0; $i < NUM_GAMES; ++$i) { | |
| 111 | + $white_uid = random_int(1, NUM_USERS); | |
| 112 | 112 | |
| 113 | - $black_uid = random_int(1, NUM_USERS); | |
| 113 | + $black_uid = random_int(1, NUM_USERS); | |
| 114 | 114 | |
| 115 | - // Force some games to be self-play. | |
| 115 | + // Force some games to be self-play. | |
| 116 | 116 | |
| 117 | -        if (10 == random_int(1, 10)) { | |
| 118 | - $black_uid = $white_uid; | |
| 119 | - } | |
| 117 | +		if (10 == random_int(1, 10)) { | |
| 118 | + $black_uid = $white_uid; | |
| 119 | + } | |
| 120 | 120 | |
| 121 | - $create_date_max = time(); | |
| 121 | + $create_date_max = time(); | |
| 122 | 122 | |
| 123 | - $create_date_min = $create_date_max - 365 * 24 * 3600; | |
| 123 | + $create_date_min = $create_date_max - 365 * 24 * 3600; | |
| 124 | 124 | |
| 125 | - $create_date_sec = random_int($create_date_min, $create_date_max); | |
| 125 | + $create_date_sec = random_int($create_date_min, $create_date_max); | |
| 126 | 126 | |
| 127 | -        $create_date = date('Y-m-d H:i:s', $create_date_sec); | |
| 127 | +		$create_date = date('Y-m-d H:i:s', $create_date_sec); | |
| 128 | 128 | |
| 129 | - $is_started = random_int(1, 4) < 4; | |
| 129 | + $is_started = random_int(1, 4) < 4; | |
| 130 | 130 | |
| 131 | - $start_date_sec = $is_started ? $create_date_sec + random_int(3600, 3 * 24 * 3600) : 0; | |
| 131 | + $start_date_sec = $is_started ? $create_date_sec + random_int(3600, 3 * 24 * 3600) : 0; | |
| 132 | 132 | |
| 133 | -        $start_date = $is_started ? date('Y-m-d H:i:s', $start_date_sec) : '0000-00-00 00:00:00'; | |
| 133 | +		$start_date = $is_started ? date('Y-m-d H:i:s', $start_date_sec) : '0000-00-00 00:00:00'; | |
| 134 | 134 | |
| 135 | - $multiple_moves = $is_started && random_int(1, 10) < 10; | |
| 135 | + $multiple_moves = $is_started && random_int(1, 10) < 10; | |
| 136 | 136 | |
| 137 | - $last_date_sec = $multiple_moves ? $start_date_sec + random_int(3600, 90 * 24 * 3600) : 0; | |
| 137 | + $last_date_sec = $multiple_moves ? $start_date_sec + random_int(3600, 90 * 24 * 3600) : 0; | |
| 138 | 138 | |
| 139 | -        $last_date = $multiple_moves ? date('Y-m-d H:i:s', $last_date_sec) : '0000-00-00 00:00:00'; | |
| 139 | +		$last_date = $multiple_moves ? date('Y-m-d H:i:s', $last_date_sec) : '0000-00-00 00:00:00'; | |
| 140 | 140 | |
| 141 | - $pgn_result = $multiple_moves ? rand_array_value($pgn_results) : '*'; | |
| 141 | + $pgn_result = $multiple_moves ? rand_array_value($pgn_results) : '*'; | |
| 142 | 142 | |
| 143 | -        if ($multiple_moves && '*' == $pgn_result && 5 == random_int(1, 5)) { | |
| 144 | -            $suspended_date = date('Y-m-d H:i:s', $last_date_sec + random_int(60, 72 * 3600)); | |
| 143 | +		if ($multiple_moves && '*' == $pgn_result && 5 == random_int(1, 5)) { | |
| 144 | +			$suspended_date = date('Y-m-d H:i:s', $last_date_sec + random_int(60, 72 * 3600)); | |
| 145 | 145 | |
| 146 | - $suspended_uids = [1, $white_uid, $black_uid]; | |
| 146 | + $suspended_uids = [1, $white_uid, $black_uid]; | |
| 147 | 147 | |
| 148 | - $suspended_uid = rand_array_value($suspended_uids); | |
| 148 | + $suspended_uid = rand_array_value($suspended_uids); | |
| 149 | 149 | |
| 150 | - $suspended_type = 1 == $suspended_uid ? 'arbiter_suspend' : 'want_arbitration'; | |
| 150 | + $suspended_type = 1 == $suspended_uid ? 'arbiter_suspend' : 'want_arbitration'; | |
| 151 | 151 | |
| 152 | - $suspended_explain = rand_array_value($suspended_explains); | |
| 152 | + $suspended_explain = rand_array_value($suspended_explains); | |
| 153 | 153 | |
| 154 | - $suspended = "$suspended_date|$suspended_uid|$suspended_type|$suspended_explain"; | |
| 155 | -        } else { | |
| 156 | - $suspended = ''; | |
| 157 | - } | |
| 154 | + $suspended = "$suspended_date|$suspended_uid|$suspended_type|$suspended_explain"; | |
| 155 | +		} else { | |
| 156 | + $suspended = ''; | |
| 157 | + } | |
| 158 | 158 | |
| 159 | - $is_rated = $white_uid != $black_uid ? random_int(0, 1) : 0; | |
| 159 | + $is_rated = $white_uid != $black_uid ? random_int(0, 1) : 0; | |
| 160 | 160 | |
| 161 | - do_query( | |
| 162 | - " | |
| 161 | + do_query( | |
| 162 | + " | |
| 163 | 163 | INSERT INTO $games_table | 
| 164 | 164 | SET | 
| 165 | 165 | white_uid = '$white_uid', | 
| @@ -171,10 +171,10 @@ discard block | ||
| 171 | 171 | suspended = '$suspended', | 
| 172 | 172 | is_rated = '$is_rated' | 
| 173 | 173 | " | 
| 174 | - ); | |
| 175 | - } | |
| 174 | + ); | |
| 175 | + } | |
| 176 | 176 | |
| 177 | - $GLOBALS['xoopsDB']->close(); | |
| 177 | + $GLOBALS['xoopsDB']->close(); | |
| 178 | 178 | } | 
| 179 | 179 | |
| 180 | 180 | /** | 
| @@ -185,13 +185,13 @@ discard block | ||
| 185 | 185 | */ | 
| 186 | 186 | function table_empty($table) | 
| 187 | 187 |  { | 
| 188 | -    $result = do_query("SELECT COUNT(*) FROM $table"); | |
| 188 | +	$result = do_query("SELECT COUNT(*) FROM $table"); | |
| 189 | 189 | |
| 190 | - [$num_rows] = $GLOBALS['xoopsDB']->fetchRow($result); | |
| 190 | + [$num_rows] = $GLOBALS['xoopsDB']->fetchRow($result); | |
| 191 | 191 | |
| 192 | - $GLOBALS['xoopsDB']->freeRecordSet($result); | |
| 192 | + $GLOBALS['xoopsDB']->freeRecordSet($result); | |
| 193 | 193 | |
| 194 | - return 0 == $num_rows; | |
| 194 | + return 0 == $num_rows; | |
| 195 | 195 | } | 
| 196 | 196 | |
| 197 | 197 | /** | 
| @@ -204,17 +204,17 @@ discard block | ||
| 204 | 204 | */ | 
| 205 | 205 | function do_query($query) | 
| 206 | 206 |  { | 
| 207 | - $result = $GLOBALS['xoopsDB']->queryF($query); | |
| 207 | + $result = $GLOBALS['xoopsDB']->queryF($query); | |
| 208 | 208 | |
| 209 | -    if (false === $result) { | |
| 210 | - $errno = $GLOBALS['xoopsDB']->errno(); | |
| 209 | +	if (false === $result) { | |
| 210 | + $errno = $GLOBALS['xoopsDB']->errno(); | |
| 211 | 211 | |
| 212 | - $error = $GLOBALS['xoopsDB']->error(); | |
| 212 | + $error = $GLOBALS['xoopsDB']->error(); | |
| 213 | 213 | |
| 214 | -        trigger_error("[$errno] $error\n$query", E_USER_ERROR); | |
| 215 | - } | |
| 214 | +		trigger_error("[$errno] $error\n$query", E_USER_ERROR); | |
| 215 | + } | |
| 216 | 216 | |
| 217 | - return $result; | |
| 217 | + return $result; | |
| 218 | 218 | } | 
| 219 | 219 | |
| 220 | 220 | /** | 
| @@ -223,5 +223,5 @@ discard block | ||
| 223 | 223 | */ | 
| 224 | 224 | function rand_array_value($array) | 
| 225 | 225 |  { | 
| 226 | - return $array[array_rand($array)]; | |
| 226 | + return $array[array_rand($array)]; | |
| 227 | 227 | } | 
| @@ -30,98 +30,98 @@ discard block | ||
| 30 | 30 | |
| 31 | 31 | // ------------------- Informations ------------------- // | 
| 32 | 32 | $modversion = [ | 
| 33 | - 'version' => 2.01, | |
| 34 | - 'module_status' => 'Alpha 1', | |
| 35 | - 'release_date' => '2020/05/25', | |
| 36 | - 'name' => _MI_CHESS, | |
| 37 | - 'description' => _MI_CHESS_DES, | |
| 38 | - 'official' => 0, | |
| 39 | - //1 indicates official XOOPS module supported by XOOPS Dev Team, 0 means 3rd party supported | |
| 40 | - 'author' => '<a target="_blank" href="http://Dave-L.com/">Dave Lerner</a>, Mamba', | |
| 41 | - | |
| 42 | - 'credits' => 'XOOPS Development Team', | |
| 43 | - 'author_mail' => 'author-email', | |
| 44 | - 'author_website_url' => 'https://xoops.org', | |
| 45 | - 'author_website_name' => 'XOOPS', | |
| 46 | - 'license' => 'GPL 2.0 or later', | |
| 47 | - 'license_url' => 'www.gnu.org/licenses/gpl-2.0.html/', | |
| 48 | - // ------------------- Folders & Files ------------------- | |
| 49 | - 'release_info' => 'Changelog', | |
| 50 | - 'release_file' => XOOPS_URL . "/modules/$moduleDirName/docs/changelog.txt", | |
| 51 | - | |
| 52 | - 'manual' => 'link to manual file', | |
| 53 | - 'manual_file' => XOOPS_URL . "/modules/$moduleDirName/docs/install.txt", | |
| 54 | - // images | |
| 55 | - 'image' => 'assets/images/logoModule.png', | |
| 56 | - 'iconsmall' => 'assets/images/iconsmall.png', | |
| 57 | - 'iconbig' => 'assets/images/iconbig.png', | |
| 58 | - 'dirname' => $moduleDirName, | |
| 59 | - //Frameworks | |
| 60 | - // 'dirmoduleadmin' => 'Frameworks/moduleclasses/moduleadmin', | |
| 61 | - // 'sysicons16' => 'Frameworks/moduleclasses/icons/16', | |
| 62 | - // 'sysicons32' => 'Frameworks/moduleclasses/icons/32', | |
| 63 | - // Local path icons | |
| 64 | - 'modicons16' => 'assets/images/icons/16', | |
| 65 | - 'modicons32' => 'assets/images/icons/32', | |
| 66 | - //About | |
| 67 | - 'demo_site_url' => 'https://xoops.org', | |
| 68 | - 'demo_site_name' => 'XOOPS Demo Site', | |
| 69 | - 'support_url' => 'https://xoops.org/modules/newbb/viewforum.php?forum=28/', | |
| 70 | - 'support_name' => 'Support Forum', | |
| 71 | - 'submit_bug' => 'https://github.com/XoopsModules25x/' . $moduleDirName . '/issues', | |
| 72 | - 'module_website_url' => 'www.xoops.org', | |
| 73 | - 'module_website_name' => 'XOOPS Project', | |
| 74 | - // ------------------- Min Requirements ------------------- | |
| 75 | - 'min_php' => '7.2', | |
| 76 | - 'min_xoops' => '2.5.10', | |
| 77 | - 'min_admin' => '1.2', | |
| 78 | - 'min_db' => ['mysql' => '5.5'], | |
| 79 | - // ------------------- Admin Menu ------------------- | |
| 80 | - 'system_menu' => 1, | |
| 81 | - 'hasAdmin' => 1, | |
| 82 | - 'adminindex' => 'admin/index.php', | |
| 83 | - 'adminmenu' => 'admin/menu.php', | |
| 84 | - // ------------------- Install/Update ------------------- | |
| 85 | - 'onInstall' => 'include/install.php', | |
| 86 | - // 'onInstall' => 'include/oninstall.php', | |
| 87 | - // 'onUpdate' => 'include/onupdate.php', | |
| 88 | - // 'onUninstall' => 'include/onuninstall.php', | |
| 89 | - // ------------------- PayPal --------------------------- | |
| 90 | - 'paypal' => [ | |
| 91 | - 'business' => '[email protected]', | |
| 92 | - 'item_name' => 'Donation : ' . _MI_CHESS_NAME, | |
| 93 | - 'amount' => 0, | |
| 94 | - 'currency_code' => 'USD', | |
| 95 | - ], | |
| 96 | - // ------------------- Search --------------------------- | |
| 97 | - 'hasSearch' => 0, | |
| 98 | - // 'search' => [ | |
| 99 | - // 'file' => 'include/search.inc.php', | |
| 100 | - // 'func' => 'pedigree_search', | |
| 101 | - // ], | |
| 102 | - // ------------------- Comments ------------------------- | |
| 103 | - 'hasComments' => 1, | |
| 104 | - 'comments' => [ | |
| 105 | - 'itemName' => 'game_id', | |
| 106 | - 'pageName' => 'game.php', | |
| 107 | - ], | |
| 108 | - // ------------------- Mysql ----------------------------- | |
| 109 | - 'sqlfile' => ['mysql' => 'sql/mysql.sql'], | |
| 110 | - // ------------------- Tables ---------------------------- | |
| 111 | - 'tables' => [ | |
| 112 | - $moduleDirName . '_' . 'games', | |
| 113 | - $moduleDirName . '_' . 'challenges', | |
| 114 | - $moduleDirName . '_' . 'ratings', | |
| 115 | - ], | |
| 33 | + 'version' => 2.01, | |
| 34 | + 'module_status' => 'Alpha 1', | |
| 35 | + 'release_date' => '2020/05/25', | |
| 36 | + 'name' => _MI_CHESS, | |
| 37 | + 'description' => _MI_CHESS_DES, | |
| 38 | + 'official' => 0, | |
| 39 | + //1 indicates official XOOPS module supported by XOOPS Dev Team, 0 means 3rd party supported | |
| 40 | + 'author' => '<a target="_blank" href="http://Dave-L.com/">Dave Lerner</a>, Mamba', | |
| 41 | + | |
| 42 | + 'credits' => 'XOOPS Development Team', | |
| 43 | + 'author_mail' => 'author-email', | |
| 44 | + 'author_website_url' => 'https://xoops.org', | |
| 45 | + 'author_website_name' => 'XOOPS', | |
| 46 | + 'license' => 'GPL 2.0 or later', | |
| 47 | + 'license_url' => 'www.gnu.org/licenses/gpl-2.0.html/', | |
| 48 | + // ------------------- Folders & Files ------------------- | |
| 49 | + 'release_info' => 'Changelog', | |
| 50 | + 'release_file' => XOOPS_URL . "/modules/$moduleDirName/docs/changelog.txt", | |
| 51 | + | |
| 52 | + 'manual' => 'link to manual file', | |
| 53 | + 'manual_file' => XOOPS_URL . "/modules/$moduleDirName/docs/install.txt", | |
| 54 | + // images | |
| 55 | + 'image' => 'assets/images/logoModule.png', | |
| 56 | + 'iconsmall' => 'assets/images/iconsmall.png', | |
| 57 | + 'iconbig' => 'assets/images/iconbig.png', | |
| 58 | + 'dirname' => $moduleDirName, | |
| 59 | + //Frameworks | |
| 60 | + // 'dirmoduleadmin' => 'Frameworks/moduleclasses/moduleadmin', | |
| 61 | + // 'sysicons16' => 'Frameworks/moduleclasses/icons/16', | |
| 62 | + // 'sysicons32' => 'Frameworks/moduleclasses/icons/32', | |
| 63 | + // Local path icons | |
| 64 | + 'modicons16' => 'assets/images/icons/16', | |
| 65 | + 'modicons32' => 'assets/images/icons/32', | |
| 66 | + //About | |
| 67 | + 'demo_site_url' => 'https://xoops.org', | |
| 68 | + 'demo_site_name' => 'XOOPS Demo Site', | |
| 69 | + 'support_url' => 'https://xoops.org/modules/newbb/viewforum.php?forum=28/', | |
| 70 | + 'support_name' => 'Support Forum', | |
| 71 | + 'submit_bug' => 'https://github.com/XoopsModules25x/' . $moduleDirName . '/issues', | |
| 72 | + 'module_website_url' => 'www.xoops.org', | |
| 73 | + 'module_website_name' => 'XOOPS Project', | |
| 74 | + // ------------------- Min Requirements ------------------- | |
| 75 | + 'min_php' => '7.2', | |
| 76 | + 'min_xoops' => '2.5.10', | |
| 77 | + 'min_admin' => '1.2', | |
| 78 | + 'min_db' => ['mysql' => '5.5'], | |
| 79 | + // ------------------- Admin Menu ------------------- | |
| 80 | + 'system_menu' => 1, | |
| 81 | + 'hasAdmin' => 1, | |
| 82 | + 'adminindex' => 'admin/index.php', | |
| 83 | + 'adminmenu' => 'admin/menu.php', | |
| 84 | + // ------------------- Install/Update ------------------- | |
| 85 | + 'onInstall' => 'include/install.php', | |
| 86 | + // 'onInstall' => 'include/oninstall.php', | |
| 87 | + // 'onUpdate' => 'include/onupdate.php', | |
| 88 | + // 'onUninstall' => 'include/onuninstall.php', | |
| 89 | + // ------------------- PayPal --------------------------- | |
| 90 | + 'paypal' => [ | |
| 91 | + 'business' => '[email protected]', | |
| 92 | + 'item_name' => 'Donation : ' . _MI_CHESS_NAME, | |
| 93 | + 'amount' => 0, | |
| 94 | + 'currency_code' => 'USD', | |
| 95 | + ], | |
| 96 | + // ------------------- Search --------------------------- | |
| 97 | + 'hasSearch' => 0, | |
| 98 | + // 'search' => [ | |
| 99 | + // 'file' => 'include/search.inc.php', | |
| 100 | + // 'func' => 'pedigree_search', | |
| 101 | + // ], | |
| 102 | + // ------------------- Comments ------------------------- | |
| 103 | + 'hasComments' => 1, | |
| 104 | + 'comments' => [ | |
| 105 | + 'itemName' => 'game_id', | |
| 106 | + 'pageName' => 'game.php', | |
| 107 | + ], | |
| 108 | + // ------------------- Mysql ----------------------------- | |
| 109 | + 'sqlfile' => ['mysql' => 'sql/mysql.sql'], | |
| 110 | + // ------------------- Tables ---------------------------- | |
| 111 | + 'tables' => [ | |
| 112 | + $moduleDirName . '_' . 'games', | |
| 113 | + $moduleDirName . '_' . 'challenges', | |
| 114 | + $moduleDirName . '_' . 'ratings', | |
| 115 | + ], | |
| 116 | 116 | ]; | 
| 117 | 117 | |
| 118 | 118 | // ------------------- Help files ------------------- // | 
| 119 | 119 | $modversion['help'] = 'page=help'; | 
| 120 | 120 | $modversion['helpsection'] = [ | 
| 121 | - ['name' => _MI_CHESS_OVERVIEW, 'link' => 'page=help'], | |
| 122 | - ['name' => _MI_CHESS_DISCLAIMER, 'link' => 'page=disclaimer'], | |
| 123 | - ['name' => _MI_CHESS_LICENSE, 'link' => 'page=license'], | |
| 124 | - ['name' => _MI_CHESS_SUPPORT, 'link' => 'page=support'], | |
| 121 | + ['name' => _MI_CHESS_OVERVIEW, 'link' => 'page=help'], | |
| 122 | + ['name' => _MI_CHESS_DISCLAIMER, 'link' => 'page=disclaimer'], | |
| 123 | + ['name' => _MI_CHESS_LICENSE, 'link' => 'page=license'], | |
| 124 | + ['name' => _MI_CHESS_SUPPORT, 'link' => 'page=support'], | |
| 125 | 125 | ]; | 
| 126 | 126 | |
| 127 | 127 | // Config | 
| @@ -129,77 +129,77 @@ discard block | ||
| 129 | 129 |  $memberHandler = xoops_getHandler('member'); | 
| 130 | 130 | $groups = $memberHandler->getGroups(); | 
| 131 | 131 |  foreach ($groups as $group) { | 
| 132 | -    if (XOOPS_GROUP_ANONYMOUS != $group->getVar('groupid')) { | |
| 133 | -        $grouparray[$group->getVar('name')] = $group->getVar('groupid'); | |
| 134 | - } | |
| 132 | +	if (XOOPS_GROUP_ANONYMOUS != $group->getVar('groupid')) { | |
| 133 | +		$grouparray[$group->getVar('name')] = $group->getVar('groupid'); | |
| 134 | + } | |
| 135 | 135 | } | 
| 136 | 136 | |
| 137 | 137 | $modversion['config'][] = [ | 
| 138 | - 'name' => 'groups_play', | |
| 139 | - 'title' => '_MI_CHESS_GROUPS_PLAY', | |
| 140 | - 'description' => '_MI_CHESS_GROUPS_PLAY_DES', | |
| 141 | - 'formtype' => 'group_multi', | |
| 142 | - 'valuetype' => 'array', | |
| 143 | - 'default' => [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS], | |
| 138 | + 'name' => 'groups_play', | |
| 139 | + 'title' => '_MI_CHESS_GROUPS_PLAY', | |
| 140 | + 'description' => '_MI_CHESS_GROUPS_PLAY_DES', | |
| 141 | + 'formtype' => 'group_multi', | |
| 142 | + 'valuetype' => 'array', | |
| 143 | + 'default' => [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS], | |
| 144 | 144 | ]; | 
| 145 | 145 | |
| 146 | 146 | $modversion['config'][] = [ | 
| 147 | - 'name' => 'groups_delete', | |
| 148 | - 'title' => '_MI_CHESS_GROUPS_DELETE', | |
| 149 | - 'description' => '_MI_CHESS_GROUPS_DELETE_DES', | |
| 150 | - 'formtype' => 'group_multi', | |
| 151 | - 'valuetype' => 'array', | |
| 152 | - 'default' => [], | |
| 147 | + 'name' => 'groups_delete', | |
| 148 | + 'title' => '_MI_CHESS_GROUPS_DELETE', | |
| 149 | + 'description' => '_MI_CHESS_GROUPS_DELETE_DES', | |
| 150 | + 'formtype' => 'group_multi', | |
| 151 | + 'valuetype' => 'array', | |
| 152 | + 'default' => [], | |
| 153 | 153 | ]; | 
| 154 | 154 | |
| 155 | 155 | $modversion['config'][] = [ | 
| 156 | - 'name' => 'allow_setup', | |
| 157 | - 'title' => '_MI_CHESS_ALLOW_SETUP', | |
| 158 | - 'description' => '_MI_CHESS_ALLOW_SETUP_DES', | |
| 159 | - 'formtype' => 'yesno', | |
| 160 | - 'valuetype' => 'int', | |
| 161 | - 'default' => 0, | |
| 156 | + 'name' => 'allow_setup', | |
| 157 | + 'title' => '_MI_CHESS_ALLOW_SETUP', | |
| 158 | + 'description' => '_MI_CHESS_ALLOW_SETUP_DES', | |
| 159 | + 'formtype' => 'yesno', | |
| 160 | + 'valuetype' => 'int', | |
| 161 | + 'default' => 0, | |
| 162 | 162 | ]; | 
| 163 | 163 | |
| 164 | 164 | $modversion['config'][] = [ | 
| 165 | - 'name' => 'max_items', | |
| 166 | - 'title' => '_MI_CHESS_MAX_ITEMS', | |
| 167 | - 'description' => '_MI_CHESS_MAX_ITEMS_DES', | |
| 168 | - 'formtype' => 'textbox', | |
| 169 | - 'valuetype' => 'int', | |
| 170 | - 'default' => 10, | |
| 165 | + 'name' => 'max_items', | |
| 166 | + 'title' => '_MI_CHESS_MAX_ITEMS', | |
| 167 | + 'description' => '_MI_CHESS_MAX_ITEMS_DES', | |
| 168 | + 'formtype' => 'textbox', | |
| 169 | + 'valuetype' => 'int', | |
| 170 | + 'default' => 10, | |
| 171 | 171 | ]; | 
| 172 | 172 | |
| 173 | 173 | $modversion['config'][] = [ | 
| 174 | - 'name' => 'rating_system', | |
| 175 | - 'title' => '_MI_CHESS_RATING_SYSTEM', | |
| 176 | - 'description' => '_MI_CHESS_RATING_SYSTEM_DES', | |
| 177 | - 'formtype' => 'select', | |
| 178 | - 'valuetype' => 'text', | |
| 179 | - 'options' => [ | |
| 180 | - _MI_CHESS_RATING_SYSTEM_NONE => 'none', | |
| 181 | - _MI_CHESS_RATING_SYSTEM_CXR => 'cxr', | |
| 182 | - _MI_CHESS_RATING_SYSTEM_LINEAR => 'linear', | |
| 183 | - ], | |
| 184 | - 'default' => 'cxr', | |
| 174 | + 'name' => 'rating_system', | |
| 175 | + 'title' => '_MI_CHESS_RATING_SYSTEM', | |
| 176 | + 'description' => '_MI_CHESS_RATING_SYSTEM_DES', | |
| 177 | + 'formtype' => 'select', | |
| 178 | + 'valuetype' => 'text', | |
| 179 | + 'options' => [ | |
| 180 | + _MI_CHESS_RATING_SYSTEM_NONE => 'none', | |
| 181 | + _MI_CHESS_RATING_SYSTEM_CXR => 'cxr', | |
| 182 | + _MI_CHESS_RATING_SYSTEM_LINEAR => 'linear', | |
| 183 | + ], | |
| 184 | + 'default' => 'cxr', | |
| 185 | 185 | ]; | 
| 186 | 186 | |
| 187 | 187 | $modversion['config'][] = [ | 
| 188 | - 'name' => 'initial_rating', | |
| 189 | - 'title' => '_MI_CHESS_INITIAL_RATING', | |
| 190 | - 'description' => '_MI_CHESS_INITIAL_RATING_DES', | |
| 191 | - 'formtype' => 'textbox', | |
| 192 | - 'valuetype' => 'int', | |
| 193 | - 'default' => 1200, | |
| 188 | + 'name' => 'initial_rating', | |
| 189 | + 'title' => '_MI_CHESS_INITIAL_RATING', | |
| 190 | + 'description' => '_MI_CHESS_INITIAL_RATING_DES', | |
| 191 | + 'formtype' => 'textbox', | |
| 192 | + 'valuetype' => 'int', | |
| 193 | + 'default' => 1200, | |
| 194 | 194 | ]; | 
| 195 | 195 | |
| 196 | 196 | $modversion['config'][] = [ | 
| 197 | - 'name' => 'allow_unrated_games', | |
| 198 | - 'title' => '_MI_CHESS_ALLOW_UNRATED', | |
| 199 | - 'description' => '_MI_CHESS_ALLOW_UNRATED_DES', | |
| 200 | - 'formtype' => 'yesno', | |
| 201 | - 'valuetype' => 'int', | |
| 202 | - 'default' => 1, | |
| 197 | + 'name' => 'allow_unrated_games', | |
| 198 | + 'title' => '_MI_CHESS_ALLOW_UNRATED', | |
| 199 | + 'description' => '_MI_CHESS_ALLOW_UNRATED_DES', | |
| 200 | + 'formtype' => 'yesno', | |
| 201 | + 'valuetype' => 'int', | |
| 202 | + 'default' => 1, | |
| 203 | 203 | ]; | 
| 204 | 204 | |
| 205 | 205 | // Menu | 
| @@ -214,83 +214,83 @@ discard block | ||
| 214 | 214 | // Conditional menu items | 
| 215 | 215 | global $xoopsModule, $xoopsModuleConfig, $xoopsUser; | 
| 216 | 216 |  if (is_object($xoopsModule) && 'chess' == $xoopsModule->getVar('dirname')) { | 
| 217 | - // Display create-game menu item if current user has the play-chess right. | |
| 217 | + // Display create-game menu item if current user has the play-chess right. | |
| 218 | 218 | |
| 219 | - if (!empty($xoopsModuleConfig['groups_play']) && is_array($xoopsModuleConfig['groups_play']) | |
| 220 | - && (in_array(XOOPS_GROUP_ANONYMOUS, $xoopsModuleConfig['groups_play']) | |
| 221 | -            || (is_object($xoopsUser) && count(array_intersect($xoopsUser->getGroups(), $xoopsModuleConfig['groups_play'])) > 0))) { | |
| 222 | - $modversion['sub'][3]['name'] = _MI_CHESS_SMNAME3; | |
| 223 | - $modversion['sub'][3]['url'] = 'create.php'; | |
| 224 | - } | |
| 219 | + if (!empty($xoopsModuleConfig['groups_play']) && is_array($xoopsModuleConfig['groups_play']) | |
| 220 | + && (in_array(XOOPS_GROUP_ANONYMOUS, $xoopsModuleConfig['groups_play']) | |
| 221 | +			|| (is_object($xoopsUser) && count(array_intersect($xoopsUser->getGroups(), $xoopsModuleConfig['groups_play'])) > 0))) { | |
| 222 | + $modversion['sub'][3]['name'] = _MI_CHESS_SMNAME3; | |
| 223 | + $modversion['sub'][3]['url'] = 'create.php'; | |
| 224 | + } | |
| 225 | 225 | |
| 226 | - // Display ratings menu item if ratings system is enabled. | |
| 226 | + // Display ratings menu item if ratings system is enabled. | |
| 227 | 227 | |
| 228 | -    if ('none' != $xoopsModuleConfig['rating_system']) { | |
| 229 | - $modversion['sub'][4]['name'] = _MI_CHESS_SMNAME4; | |
| 230 | - $modversion['sub'][4]['url'] = 'ratings.php'; | |
| 231 | - } | |
| 228 | +	if ('none' != $xoopsModuleConfig['rating_system']) { | |
| 229 | + $modversion['sub'][4]['name'] = _MI_CHESS_SMNAME4; | |
| 230 | + $modversion['sub'][4]['url'] = 'ratings.php'; | |
| 231 | + } | |
| 232 | 232 | |
| 233 | - // Display my-games menu item if current user is logged in. | |
| 233 | + // Display my-games menu item if current user is logged in. | |
| 234 | 234 | |
| 235 | -    if (is_object($xoopsUser)) { | |
| 236 | - $modversion['sub'][5]['name'] = _MI_CHESS_SMNAME5; | |
| 237 | -        $modversion['sub'][5]['url']  = 'player_stats.php?player_uid=' . $xoopsUser->getVar('uid'); | |
| 238 | - } | |
| 235 | +	if (is_object($xoopsUser)) { | |
| 236 | + $modversion['sub'][5]['name'] = _MI_CHESS_SMNAME5; | |
| 237 | +		$modversion['sub'][5]['url']  = 'player_stats.php?player_uid=' . $xoopsUser->getVar('uid'); | |
| 238 | + } | |
| 239 | 239 | } | 
| 240 | 240 | |
| 241 | 241 | // Page Awareness | 
| 242 | 242 | $modversion['pages'][] = [ | 
| 243 | - ['name' => _MI_CHESS_SMNAME1, 'url' => 'help.php'], | |
| 244 | - ['name' => _MI_CHESS_SMNAME2, 'url' => 'index.php'], | |
| 245 | - ['name' => _MI_CHESS_SMNAME3, 'url' => 'create.php'], | |
| 246 | - ['name' => _MI_CHESS_SMNAME4, 'url' => 'ratings.php'], | |
| 247 | - ['name' => _MI_CHESS_SMNAME5, 'url' => 'player_stats.php'], | |
| 243 | + ['name' => _MI_CHESS_SMNAME1, 'url' => 'help.php'], | |
| 244 | + ['name' => _MI_CHESS_SMNAME2, 'url' => 'index.php'], | |
| 245 | + ['name' => _MI_CHESS_SMNAME3, 'url' => 'create.php'], | |
| 246 | + ['name' => _MI_CHESS_SMNAME4, 'url' => 'ratings.php'], | |
| 247 | + ['name' => _MI_CHESS_SMNAME5, 'url' => 'player_stats.php'], | |
| 248 | 248 | ]; | 
| 249 | 249 | |
| 250 | 250 | // Templates | 
| 251 | 251 | $modversion['templates'] = [ | 
| 252 | - ['file' => 'chess_games.tpl', 'description' => _MI_CHESS_INDEX], | |
| 253 | - ['file' => 'chess_game_main.tpl', 'description' => _MI_CHESS_GAME], | |
| 254 | - ['file' => 'chess_game_moveform.tpl', 'description' => _MI_CHESS_MOVE_FORM], | |
| 255 | - ['file' => 'chess_game_promote_popup.tpl', 'description' => _MI_CHESS_PROMOTE_POPUP], | |
| 256 | - ['file' => 'chess_game_board.tpl', 'description' => _MI_CHESS_BOARD], | |
| 257 | - ['file' => 'chess_game_prefsform.tpl', 'description' => _MI_CHESS_PREFS_FORM], | |
| 258 | - ['file' => 'chess_game_arbitrateform.tpl', 'description' => _MI_CHESS_ARBITER_FORM], | |
| 259 | - ['file' => 'chess_help.tpl', 'description' => _MI_CHESS_HELP], | |
| 260 | - ['file' => 'chess_ratings.tpl', 'description' => _MI_CHESS_RATINGS], | |
| 261 | - ['file' => 'chess_player_stats.tpl', 'description' => _MI_CHESS_PLAYER_STATS], | |
| 252 | + ['file' => 'chess_games.tpl', 'description' => _MI_CHESS_INDEX], | |
| 253 | + ['file' => 'chess_game_main.tpl', 'description' => _MI_CHESS_GAME], | |
| 254 | + ['file' => 'chess_game_moveform.tpl', 'description' => _MI_CHESS_MOVE_FORM], | |
| 255 | + ['file' => 'chess_game_promote_popup.tpl', 'description' => _MI_CHESS_PROMOTE_POPUP], | |
| 256 | + ['file' => 'chess_game_board.tpl', 'description' => _MI_CHESS_BOARD], | |
| 257 | + ['file' => 'chess_game_prefsform.tpl', 'description' => _MI_CHESS_PREFS_FORM], | |
| 258 | + ['file' => 'chess_game_arbitrateform.tpl', 'description' => _MI_CHESS_ARBITER_FORM], | |
| 259 | + ['file' => 'chess_help.tpl', 'description' => _MI_CHESS_HELP], | |
| 260 | + ['file' => 'chess_ratings.tpl', 'description' => _MI_CHESS_RATINGS], | |
| 261 | + ['file' => 'chess_player_stats.tpl', 'description' => _MI_CHESS_PLAYER_STATS], | |
| 262 | 262 | ]; | 
| 263 | 263 | // Blocks | 
| 264 | 264 | $modversion['blocks'][] = [ | 
| 265 | - 'file' => 'blocks.php', | |
| 266 | - 'name' => _MI_CHESS_GAMES, | |
| 267 | - 'description' => _MI_CHESS_GAMES_DES, | |
| 268 | - 'show_func' => 'b_chess_games_show', | |
| 269 | - // options: maximum number of games to display | 1=show games in play only/2=show concluded games only/3=show both | 1=show rated games only/2=show rated and unrated games | |
| 270 | - 'options' => '4|3', | |
| 271 | - 'edit_func' => 'b_chess_games_edit', | |
| 272 | - 'template' => 'chess_block_games.tpl', | |
| 265 | + 'file' => 'blocks.php', | |
| 266 | + 'name' => _MI_CHESS_GAMES, | |
| 267 | + 'description' => _MI_CHESS_GAMES_DES, | |
| 268 | + 'show_func' => 'b_chess_games_show', | |
| 269 | + // options: maximum number of games to display | 1=show games in play only/2=show concluded games only/3=show both | 1=show rated games only/2=show rated and unrated games | |
| 270 | + 'options' => '4|3', | |
| 271 | + 'edit_func' => 'b_chess_games_edit', | |
| 272 | + 'template' => 'chess_block_games.tpl', | |
| 273 | 273 | ]; | 
| 274 | 274 | |
| 275 | 275 | $modversion['blocks'][] = [ | 
| 276 | - 'file' => 'blocks.php', | |
| 277 | - 'name' => _MI_CHESS_CHALLENGES, | |
| 278 | - 'description' => _MI_CHESS_CHALLENGES_DES, | |
| 279 | - 'show_func' => 'b_chess_challenges_show', | |
| 280 | - // options: maximum number of challenges to display | 1=show open challenges only/2=show individual challenges only/3=show both | |
| 281 | - 'options' => '4|3', | |
| 282 | - 'edit_func' => 'b_chess_challenges_edit', | |
| 283 | - 'template' => 'chess_block_challenges.tpl', | |
| 276 | + 'file' => 'blocks.php', | |
| 277 | + 'name' => _MI_CHESS_CHALLENGES, | |
| 278 | + 'description' => _MI_CHESS_CHALLENGES_DES, | |
| 279 | + 'show_func' => 'b_chess_challenges_show', | |
| 280 | + // options: maximum number of challenges to display | 1=show open challenges only/2=show individual challenges only/3=show both | |
| 281 | + 'options' => '4|3', | |
| 282 | + 'edit_func' => 'b_chess_challenges_edit', | |
| 283 | + 'template' => 'chess_block_challenges.tpl', | |
| 284 | 284 | ]; | 
| 285 | 285 | $modversion['blocks'][] = [ | 
| 286 | - 'file' => 'blocks.php', | |
| 287 | - 'name' => _MI_CHESS_PLAYERS, | |
| 288 | - 'description' => _MI_CHESS_PLAYERS_DES, | |
| 289 | - 'show_func' => 'b_chess_players_show', | |
| 290 | - // options: maximum number of players to display | 1=show non-provisional ratings only/2=show all ratings | |
| 291 | - 'options' => '4|1', | |
| 292 | - 'edit_func' => 'b_chess_players_edit', | |
| 293 | - 'template' => 'chess_block_players.tpl', | |
| 286 | + 'file' => 'blocks.php', | |
| 287 | + 'name' => _MI_CHESS_PLAYERS, | |
| 288 | + 'description' => _MI_CHESS_PLAYERS_DES, | |
| 289 | + 'show_func' => 'b_chess_players_show', | |
| 290 | + // options: maximum number of players to display | 1=show non-provisional ratings only/2=show all ratings | |
| 291 | + 'options' => '4|1', | |
| 292 | + 'edit_func' => 'b_chess_players_edit', | |
| 293 | + 'template' => 'chess_block_players.tpl', | |
| 294 | 294 | ]; | 
| 295 | 295 | |
| 296 | 296 | // Notification | 
| @@ -299,68 +299,68 @@ discard block | ||
| 299 | 299 | $modversion['notification']['lookup_func'] = 'chess_notify_item_info'; | 
| 300 | 300 | |
| 301 | 301 | $modversion['notification']['category'][] = [ | 
| 302 | - 'name' => 'game', | |
| 303 | - 'title' => _MI_CHESS_NCAT_GAME, | |
| 304 | - 'description' => _MI_CHESS_NCAT_GAME_DES, | |
| 305 | - 'subscribe_from' => 'game.php', | |
| 306 | - 'item_name' => 'game_id', | |
| 307 | - 'allow_bookmark' => 1, | |
| 302 | + 'name' => 'game', | |
| 303 | + 'title' => _MI_CHESS_NCAT_GAME, | |
| 304 | + 'description' => _MI_CHESS_NCAT_GAME_DES, | |
| 305 | + 'subscribe_from' => 'game.php', | |
| 306 | + 'item_name' => 'game_id', | |
| 307 | + 'allow_bookmark' => 1, | |
| 308 | 308 | ]; | 
| 309 | 309 | |
| 310 | 310 | $modversion['notification']['category'][] = [ | 
| 311 | - 'name' => 'global', | |
| 312 | - 'title' => _MI_CHESS_NCAT_GLOBAL, | |
| 313 | - 'description' => _MI_CHESS_NCAT_GLOBAL_DES, | |
| 314 | - 'subscribe_from' => ['index.php', 'game.php'], | |
| 311 | + 'name' => 'global', | |
| 312 | + 'title' => _MI_CHESS_NCAT_GLOBAL, | |
| 313 | + 'description' => _MI_CHESS_NCAT_GLOBAL_DES, | |
| 314 | + 'subscribe_from' => ['index.php', 'game.php'], | |
| 315 | 315 | ]; | 
| 316 | 316 | |
| 317 | 317 | $modversion['notification']['event'][] = [ | 
| 318 | - 'name' => 'notify_game_move', | |
| 319 | - 'category' => 'game', | |
| 320 | - 'title' => _MI_CHESS_NEVT_MOVE, | |
| 321 | - 'caption' => _MI_CHESS_NEVT_MOVE_CAP, | |
| 322 | - 'description' => _MI_CHESS_NEVT_MOVE_DES, | |
| 323 | - 'mail_template' => 'notify_game_move', | |
| 324 | - 'mail_subject' => _MI_CHESS_NEVT_MOVE_SUB, | |
| 318 | + 'name' => 'notify_game_move', | |
| 319 | + 'category' => 'game', | |
| 320 | + 'title' => _MI_CHESS_NEVT_MOVE, | |
| 321 | + 'caption' => _MI_CHESS_NEVT_MOVE_CAP, | |
| 322 | + 'description' => _MI_CHESS_NEVT_MOVE_DES, | |
| 323 | + 'mail_template' => 'notify_game_move', | |
| 324 | + 'mail_subject' => _MI_CHESS_NEVT_MOVE_SUB, | |
| 325 | 325 | ]; | 
| 326 | 326 | |
| 327 | 327 | $modversion['notification']['event'][] = [ | 
| 328 | - 'name' => 'notify_challenge_user', | |
| 329 | - 'category' => 'global', | |
| 330 | - 'title' => _MI_CHESS_NEVT_CHAL_USER, | |
| 331 | - 'caption' => _MI_CHESS_NEVT_CHAL_USER_CAP, | |
| 332 | - 'description' => _MI_CHESS_NEVT_CHAL_USER_DES, | |
| 333 | - 'mail_template' => 'notify_challenge_user', | |
| 334 | - 'mail_subject' => _MI_CHESS_NEVT_CHAL_USER_SUB, | |
| 328 | + 'name' => 'notify_challenge_user', | |
| 329 | + 'category' => 'global', | |
| 330 | + 'title' => _MI_CHESS_NEVT_CHAL_USER, | |
| 331 | + 'caption' => _MI_CHESS_NEVT_CHAL_USER_CAP, | |
| 332 | + 'description' => _MI_CHESS_NEVT_CHAL_USER_DES, | |
| 333 | + 'mail_template' => 'notify_challenge_user', | |
| 334 | + 'mail_subject' => _MI_CHESS_NEVT_CHAL_USER_SUB, | |
| 335 | 335 | ]; | 
| 336 | 336 | |
| 337 | 337 | $modversion['notification']['event'][] = [ | 
| 338 | - 'name' => 'notify_challenge_open', | |
| 339 | - 'category' => 'global', | |
| 340 | - 'title' => _MI_CHESS_NEVT_CHAL_OPEN, | |
| 341 | - 'caption' => _MI_CHESS_NEVT_CHAL_OPEN_CAP, | |
| 342 | - 'description' => _MI_CHESS_NEVT_CHAL_OPEN_DES, | |
| 343 | - 'mail_template' => 'notify_challenge_open', | |
| 344 | - 'mail_subject' => _MI_CHESS_NEVT_CHAL_OPEN_SUB, | |
| 338 | + 'name' => 'notify_challenge_open', | |
| 339 | + 'category' => 'global', | |
| 340 | + 'title' => _MI_CHESS_NEVT_CHAL_OPEN, | |
| 341 | + 'caption' => _MI_CHESS_NEVT_CHAL_OPEN_CAP, | |
| 342 | + 'description' => _MI_CHESS_NEVT_CHAL_OPEN_DES, | |
| 343 | + 'mail_template' => 'notify_challenge_open', | |
| 344 | + 'mail_subject' => _MI_CHESS_NEVT_CHAL_OPEN_SUB, | |
| 345 | 345 | ]; | 
| 346 | 346 | |
| 347 | 347 | $modversion['notification']['event'][] = [ | 
| 348 | - 'name' => 'notify_accept_challenge', | |
| 349 | - 'category' => 'global', | |
| 350 | - 'title' => _MI_CHESS_NEVT_ACPT_CHAL, | |
| 351 | - 'caption' => _MI_CHESS_NEVT_ACPT_CHAL_CAP, | |
| 352 | - 'description' => _MI_CHESS_NEVT_ACPT_CHAL_DES, | |
| 353 | - 'mail_template' => 'notify_accept_challenge', | |
| 354 | - 'mail_subject' => _MI_CHESS_NEVT_ACPT_CHAL_SUB, | |
| 348 | + 'name' => 'notify_accept_challenge', | |
| 349 | + 'category' => 'global', | |
| 350 | + 'title' => _MI_CHESS_NEVT_ACPT_CHAL, | |
| 351 | + 'caption' => _MI_CHESS_NEVT_ACPT_CHAL_CAP, | |
| 352 | + 'description' => _MI_CHESS_NEVT_ACPT_CHAL_DES, | |
| 353 | + 'mail_template' => 'notify_accept_challenge', | |
| 354 | + 'mail_subject' => _MI_CHESS_NEVT_ACPT_CHAL_SUB, | |
| 355 | 355 | ]; | 
| 356 | 356 | |
| 357 | 357 | $modversion['notification']['event'][] = [ | 
| 358 | - 'name' => 'notify_request_arbitration', | |
| 359 | - 'category' => 'global', | |
| 360 | - 'title' => _MI_CHESS_NEVT_RQST_ARBT, | |
| 361 | - 'caption' => _MI_CHESS_NEVT_RQST_ARBT_CAP, | |
| 362 | - 'description' => _MI_CHESS_NEVT_RQST_ARBT_DES, | |
| 363 | - 'mail_template' => 'notify_request_arbitration', | |
| 364 | - 'mail_subject' => _MI_CHESS_NEVT_RQST_ARBT_SUB, | |
| 365 | - 'admin_only' => 1, | |
| 358 | + 'name' => 'notify_request_arbitration', | |
| 359 | + 'category' => 'global', | |
| 360 | + 'title' => _MI_CHESS_NEVT_RQST_ARBT, | |
| 361 | + 'caption' => _MI_CHESS_NEVT_RQST_ARBT_CAP, | |
| 362 | + 'description' => _MI_CHESS_NEVT_RQST_ARBT_DES, | |
| 363 | + 'mail_template' => 'notify_request_arbitration', | |
| 364 | + 'mail_subject' => _MI_CHESS_NEVT_RQST_ARBT_SUB, | |
| 365 | + 'admin_only' => 1, | |
| 366 | 366 | ]; | 
| @@ -56,7 +56,7 @@ discard block | ||
| 56 | 56 | #var_dump($_REQUEST);#*#DEBUG# | 
| 57 | 57 | |
| 58 | 58 |  if (!chess_can_play()) { | 
| 59 | - redirect_header(XOOPS_URL . '/index.php', _CHESS_REDIRECT_DELAY_FAILURE, _NOPERM); | |
| 59 | + redirect_header(XOOPS_URL . '/index.php', _CHESS_REDIRECT_DELAY_FAILURE, _NOPERM); | |
| 60 | 60 | } | 
| 61 | 61 | |
| 62 | 62 | // user input | 
| @@ -87,16 +87,16 @@ discard block | ||
| 87 | 87 | |
| 88 | 88 | // If form-submit, check security token. | 
| 89 | 89 |  if (($submit_challenge1 || $submit_challenge2 || $submit_challenge3 || $submit_accept || $submit_delete || $show_arbiter_ctrl) && is_object($GLOBALS['xoopsSecurity']) && !$GLOBALS['xoopsSecurity']->check()) { | 
| 90 | - redirect_header( | |
| 91 | - XOOPS_URL . '/modules/chess/', | |
| 92 | - _CHESS_REDIRECT_DELAY_FAILURE, | |
| 93 | -        _MD_CHESS_TOKEN_ERROR . '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()) | |
| 94 | - ); | |
| 90 | + redirect_header( | |
| 91 | + XOOPS_URL . '/modules/chess/', | |
| 92 | + _CHESS_REDIRECT_DELAY_FAILURE, | |
| 93 | +		_MD_CHESS_TOKEN_ERROR . '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()) | |
| 94 | + ); | |
| 95 | 95 | } | 
| 96 | 96 | |
| 97 | 97 | // If rating feature disabled, force ratings to off. | 
| 98 | 98 |  if ('none' == chess_moduleConfig('rating_system')) { | 
| 99 | - $rated = 0; | |
| 99 | + $rated = 0; | |
| 100 | 100 | } | 
| 101 | 101 | |
| 102 | 102 |  $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; | 
| @@ -105,87 +105,87 @@ discard block | ||
| 105 | 105 |  $is_arbiter = is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->getVar('mid')); | 
| 106 | 106 | |
| 107 | 107 |  if ($cancel_challenge1) { | 
| 108 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _TAKINGBACK); | |
| 108 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _TAKINGBACK); | |
| 109 | 109 |  } elseif ($cancel_challenge2) { | 
| 110 | - chess_show_create_form1($gametype); | |
| 110 | + chess_show_create_form1($gametype); | |
| 111 | 111 |  } elseif ($cancel_challenge3) { | 
| 112 | -    if (_CHESS_GAMETYPE_OPEN == $gametype || _CHESS_GAMETYPE_USER == $gametype) { | |
| 113 | - chess_show_create_form2($gametype, $fen); | |
| 114 | -    } else { | |
| 115 | - chess_show_create_form1($gametype, $fen); | |
| 116 | - } | |
| 112 | +	if (_CHESS_GAMETYPE_OPEN == $gametype || _CHESS_GAMETYPE_USER == $gametype) { | |
| 113 | + chess_show_create_form2($gametype, $fen); | |
| 114 | +	} else { | |
| 115 | + chess_show_create_form1($gametype, $fen); | |
| 116 | + } | |
| 117 | 117 |  } elseif ($cancel_accept) { | 
| 118 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _TAKINGBACK); | |
| 118 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _TAKINGBACK); | |
| 119 | 119 |  } elseif ($submit_challenge1) { | 
| 120 | - $fen_error = chess_fen_error($fen); | |
| 121 | - | |
| 122 | -    if (!empty($fen_error)) { | |
| 123 | - chess_show_create_form1($gametype, $fen, _MD_CHESS_FEN_INVALID . ': ' . $fen_error); | |
| 124 | -    } elseif (_CHESS_GAMETYPE_OPEN == $gametype || _CHESS_GAMETYPE_USER == $gametype) { | |
| 125 | - chess_show_create_form2($gametype, $fen); | |
| 126 | -    } else { | |
| 127 | - chess_show_create_form3($gametype, $fen, $coloroption, $opponent_uid, $rated); | |
| 128 | - } | |
| 120 | + $fen_error = chess_fen_error($fen); | |
| 121 | + | |
| 122 | +	if (!empty($fen_error)) { | |
| 123 | + chess_show_create_form1($gametype, $fen, _MD_CHESS_FEN_INVALID . ': ' . $fen_error); | |
| 124 | +	} elseif (_CHESS_GAMETYPE_OPEN == $gametype || _CHESS_GAMETYPE_USER == $gametype) { | |
| 125 | + chess_show_create_form2($gametype, $fen); | |
| 126 | +	} else { | |
| 127 | + chess_show_create_form3($gametype, $fen, $coloroption, $opponent_uid, $rated); | |
| 128 | + } | |
| 129 | 129 |  } elseif ($submit_challenge2) { | 
| 130 | -    if (_CHESS_GAMETYPE_USER == $gametype) { | |
| 131 | -        if (empty($opponent)) { | |
| 132 | - chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_MISSING); | |
| 133 | -        } elseif (!$opponent_uid) { | |
| 134 | - chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_INVALID); | |
| 135 | -        } elseif ($opponent_uid == $uid) { | |
| 136 | - chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_SELF); | |
| 137 | -        } else { | |
| 138 | - chess_show_create_form3($gametype, $fen, $coloroption, $opponent_uid, $rated); | |
| 139 | - } | |
| 140 | -    } else { | |
| 141 | - chess_show_create_form3($gametype, $fen, $coloroption, $opponent_uid, $rated); | |
| 142 | - } | |
| 130 | +	if (_CHESS_GAMETYPE_USER == $gametype) { | |
| 131 | +		if (empty($opponent)) { | |
| 132 | + chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_MISSING); | |
| 133 | +		} elseif (!$opponent_uid) { | |
| 134 | + chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_INVALID); | |
| 135 | +		} elseif ($opponent_uid == $uid) { | |
| 136 | + chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_SELF); | |
| 137 | +		} else { | |
| 138 | + chess_show_create_form3($gametype, $fen, $coloroption, $opponent_uid, $rated); | |
| 139 | + } | |
| 140 | +	} else { | |
| 141 | + chess_show_create_form3($gametype, $fen, $coloroption, $opponent_uid, $rated); | |
| 142 | + } | |
| 143 | 143 |  } elseif ($submit_challenge3) { | 
| 144 | -    if (_CHESS_GAMETYPE_OPEN == $gametype) { | |
| 145 | - chess_create_challenge($gametype, $fen, $coloroption, $rated, $notify_accept, $notify_move); | |
| 146 | - | |
| 147 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_CREATED); | |
| 148 | -    } elseif (_CHESS_GAMETYPE_USER == $gametype) { | |
| 149 | -        if (empty($opponent)) { | |
| 150 | - chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_MISSING); | |
| 151 | -        } elseif (!$opponent_uid) { | |
| 152 | - chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_INVALID); | |
| 153 | -        } elseif ($opponent_uid == $uid) { | |
| 154 | - chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_SELF); | |
| 155 | -        } else { | |
| 156 | - chess_create_challenge($gametype, $fen, $coloroption, $rated, $notify_accept, $notify_move, $opponent_uid); | |
| 157 | - | |
| 158 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_CREATED); | |
| 159 | - } | |
| 160 | -    } elseif (_CHESS_GAMETYPE_SELF == $gametype) { | |
| 161 | - $game_id = chess_create_game($uid, $uid, $fen, $rated); | |
| 162 | - | |
| 163 | - redirect_header(XOOPS_URL . "/modules/chess/game.php?game_id=$game_id", _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_CREATED); | |
| 164 | -    } else { | |
| 165 | - chess_show_create_form1($gametype, $fen, _MD_CHESS_GAMETYPE_INVALID); | |
| 166 | - } | |
| 144 | +	if (_CHESS_GAMETYPE_OPEN == $gametype) { | |
| 145 | + chess_create_challenge($gametype, $fen, $coloroption, $rated, $notify_accept, $notify_move); | |
| 146 | + | |
| 147 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_CREATED); | |
| 148 | +	} elseif (_CHESS_GAMETYPE_USER == $gametype) { | |
| 149 | +		if (empty($opponent)) { | |
| 150 | + chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_MISSING); | |
| 151 | +		} elseif (!$opponent_uid) { | |
| 152 | + chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_INVALID); | |
| 153 | +		} elseif ($opponent_uid == $uid) { | |
| 154 | + chess_show_create_form2($gametype, $fen, $coloroption, $opponent_uid, $rated, _MD_CHESS_OPPONENT_SELF); | |
| 155 | +		} else { | |
| 156 | + chess_create_challenge($gametype, $fen, $coloroption, $rated, $notify_accept, $notify_move, $opponent_uid); | |
| 157 | + | |
| 158 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_CREATED); | |
| 159 | + } | |
| 160 | +	} elseif (_CHESS_GAMETYPE_SELF == $gametype) { | |
| 161 | + $game_id = chess_create_game($uid, $uid, $fen, $rated); | |
| 162 | + | |
| 163 | + redirect_header(XOOPS_URL . "/modules/chess/game.php?game_id=$game_id", _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_CREATED); | |
| 164 | +	} else { | |
| 165 | + chess_show_create_form1($gametype, $fen, _MD_CHESS_GAMETYPE_INVALID); | |
| 166 | + } | |
| 167 | 167 |  } elseif ($submit_accept) { | 
| 168 | - chess_accept_challenge($challenge_id, $coloroption, $notify_move); | |
| 168 | + chess_accept_challenge($challenge_id, $coloroption, $notify_move); | |
| 169 | 169 |  } elseif ($submit_delete) { | 
| 170 | -    if ($confirm_delete) { | |
| 171 | -        if ($is_arbiter || chess_is_challenger($challenge_id)) { | |
| 172 | - chess_delete_challenge($challenge_id); | |
| 173 | - | |
| 174 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_DELETED); | |
| 175 | -        } else { | |
| 176 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _NOPERM); | |
| 177 | - } | |
| 178 | -    } else { | |
| 179 | - chess_show_delete_form($challenge_id, $show_arbiter_ctrl && $is_arbiter, _MD_CHESS_NO_CONFIRM_DELETE); | |
| 180 | - } | |
| 170 | +	if ($confirm_delete) { | |
| 171 | +		if ($is_arbiter || chess_is_challenger($challenge_id)) { | |
| 172 | + chess_delete_challenge($challenge_id); | |
| 173 | + | |
| 174 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_DELETED); | |
| 175 | +		} else { | |
| 176 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _NOPERM); | |
| 177 | + } | |
| 178 | +	} else { | |
| 179 | + chess_show_delete_form($challenge_id, $show_arbiter_ctrl && $is_arbiter, _MD_CHESS_NO_CONFIRM_DELETE); | |
| 180 | + } | |
| 181 | 181 |  } elseif ($challenge_id) { | 
| 182 | -    if (($show_arbiter_ctrl && $is_arbiter) || chess_is_challenger($challenge_id)) { | |
| 183 | - chess_show_delete_form($challenge_id, $show_arbiter_ctrl && $is_arbiter); | |
| 184 | -    } else { | |
| 185 | - chess_show_accept_form($challenge_id); | |
| 186 | - } | |
| 182 | +	if (($show_arbiter_ctrl && $is_arbiter) || chess_is_challenger($challenge_id)) { | |
| 183 | + chess_show_delete_form($challenge_id, $show_arbiter_ctrl && $is_arbiter); | |
| 184 | +	} else { | |
| 185 | + chess_show_accept_form($challenge_id); | |
| 186 | + } | |
| 187 | 187 |  } else { | 
| 188 | - chess_show_create_form1($gametype); | |
| 188 | + chess_show_create_form1($gametype); | |
| 189 | 189 | } | 
| 190 | 190 | |
| 191 | 191 | require_once XOOPS_ROOT_PATH . '/footer.php'; | 
| @@ -200,41 +200,41 @@ discard block | ||
| 200 | 200 | */ | 
| 201 | 201 | function chess_show_create_form1($gametype = _CHESS_GAMETYPE_OPEN, $fen = '', $error_msg = '') | 
| 202 | 202 |  { | 
| 203 | - $form = new XoopsThemeForm(_MD_CHESS_CREATE_FORM, 'create_form1', 'create.php', 'post', true); | |
| 203 | + $form = new XoopsThemeForm(_MD_CHESS_CREATE_FORM, 'create_form1', 'create.php', 'post', true); | |
| 204 | 204 | |
| 205 | -    if ($error_msg) { | |
| 206 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_ERROR . ': ', '<div class="errorMsg">' . $error_msg . '</div>')); | |
| 207 | - } | |
| 205 | +	if ($error_msg) { | |
| 206 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_ERROR . ': ', '<div class="errorMsg">' . $error_msg . '</div>')); | |
| 207 | + } | |
| 208 | 208 | |
| 209 | - $menu_gametype = new XoopsFormSelect(_MD_CHESS_LABEL_GAMETYPE . ':', 'gametype', $gametype, 1, false); | |
| 209 | + $menu_gametype = new XoopsFormSelect(_MD_CHESS_LABEL_GAMETYPE . ':', 'gametype', $gametype, 1, false); | |
| 210 | 210 | |
| 211 | - $menu_gametype->addOption(_CHESS_GAMETYPE_OPEN, _MD_CHESS_MENU_GAMETYPE_OPEN); | |
| 211 | + $menu_gametype->addOption(_CHESS_GAMETYPE_OPEN, _MD_CHESS_MENU_GAMETYPE_OPEN); | |
| 212 | 212 | |
| 213 | - $menu_gametype->addOption(_CHESS_GAMETYPE_USER, _MD_CHESS_MENU_GAMETYPE_USER); | |
| 213 | + $menu_gametype->addOption(_CHESS_GAMETYPE_USER, _MD_CHESS_MENU_GAMETYPE_USER); | |
| 214 | 214 | |
| 215 | - $menu_gametype->addOption(_CHESS_GAMETYPE_SELF, _MD_CHESS_MENU_GAMETYPE_SELF); | |
| 215 | + $menu_gametype->addOption(_CHESS_GAMETYPE_SELF, _MD_CHESS_MENU_GAMETYPE_SELF); | |
| 216 | 216 | |
| 217 | - $form->addElement($menu_gametype); | |
| 217 | + $form->addElement($menu_gametype); | |
| 218 | 218 | |
| 219 | -    if (chess_moduleConfig('allow_setup')) { | |
| 220 | -        $form->addElement(new XoopsFormLabel('', ' ')); | |
| 219 | +	if (chess_moduleConfig('allow_setup')) { | |
| 220 | +		$form->addElement(new XoopsFormLabel('', ' ')); | |
| 221 | 221 | |
| 222 | -        $form->addElement(new XoopsFormLabel('', _MD_CHESS_LABEL_FEN_EXPLAIN)); | |
| 222 | +		$form->addElement(new XoopsFormLabel('', _MD_CHESS_LABEL_FEN_EXPLAIN)); | |
| 223 | 223 | |
| 224 | - $form->addElement(new XoopsFormText(_MD_CHESS_LABEL_FEN_SETUP . ':', 'fen', 80, _CHESS_TEXTBOX_FEN_MAXLEN, $fen)); | |
| 225 | - } | |
| 224 | + $form->addElement(new XoopsFormText(_MD_CHESS_LABEL_FEN_SETUP . ':', 'fen', 80, _CHESS_TEXTBOX_FEN_MAXLEN, $fen)); | |
| 225 | + } | |
| 226 | 226 | |
| 227 | -    $form->addElement(new XoopsFormLabel(' ', ' ')); | |
| 227 | +	$form->addElement(new XoopsFormLabel(' ', ' ')); | |
| 228 | 228 | |
| 229 | -    $buttons = new XoopsFormElementTray(''); | |
| 229 | +	$buttons = new XoopsFormElementTray(''); | |
| 230 | 230 | |
| 231 | -    $buttons->addElement(new XoopsFormButton('', 'submit_challenge1', _MD_CHESS_CREATE_SUBMIT, 'submit')); | |
| 231 | +	$buttons->addElement(new XoopsFormButton('', 'submit_challenge1', _MD_CHESS_CREATE_SUBMIT, 'submit')); | |
| 232 | 232 | |
| 233 | -    $buttons->addElement(new XoopsFormButton('', 'cancel_challenge1', _MD_CHESS_CREATE_CANCEL, 'submit')); | |
| 233 | +	$buttons->addElement(new XoopsFormButton('', 'cancel_challenge1', _MD_CHESS_CREATE_CANCEL, 'submit')); | |
| 234 | 234 | |
| 235 | - $form->addElement($buttons); | |
| 235 | + $form->addElement($buttons); | |
| 236 | 236 | |
| 237 | - $form->display(); | |
| 237 | + $form->display(); | |
| 238 | 238 | } | 
| 239 | 239 | |
| 240 | 240 | /** | 
| @@ -249,69 +249,69 @@ discard block | ||
| 249 | 249 | */ | 
| 250 | 250 | function chess_show_create_form2($gametype, $fen, $coloroption = _CHESS_COLOROPTION_OPPONENT, $opponent_uid = 0, $rated = 1, $error_msg = '') | 
| 251 | 251 |  { | 
| 252 | - $form = new XoopsThemeForm(_MD_CHESS_CREATE_FORM, 'create_form2', 'create.php', 'post', true); | |
| 252 | + $form = new XoopsThemeForm(_MD_CHESS_CREATE_FORM, 'create_form2', 'create.php', 'post', true); | |
| 253 | 253 | |
| 254 | -    $form->addElement(new XoopsFormHidden('gametype', $gametype)); | |
| 254 | +	$form->addElement(new XoopsFormHidden('gametype', $gametype)); | |
| 255 | 255 | |
| 256 | -    $form->addElement(new XoopsFormHidden('fen', $fen)); | |
| 256 | +	$form->addElement(new XoopsFormHidden('fen', $fen)); | |
| 257 | 257 | |
| 258 | -    if ($error_msg) { | |
| 259 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_ERROR . ':', '<div class="errorMsg">' . $error_msg . '</div>')); | |
| 260 | - } | |
| 258 | +	if ($error_msg) { | |
| 259 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_ERROR . ':', '<div class="errorMsg">' . $error_msg . '</div>')); | |
| 260 | + } | |
| 261 | 261 | |
| 262 | -    $memberHandler = xoops_getHandler('member'); | |
| 262 | +	$memberHandler = xoops_getHandler('member'); | |
| 263 | 263 | |
| 264 | - $opponent_user = $memberHandler->getUser($opponent_uid); | |
| 264 | + $opponent_user = $memberHandler->getUser($opponent_uid); | |
| 265 | 265 | |
| 266 | -    $opponent_username = is_object($opponent_user) ? $opponent_user->getVar('uname') : ''; | |
| 266 | +	$opponent_username = is_object($opponent_user) ? $opponent_user->getVar('uname') : ''; | |
| 267 | 267 | |
| 268 | -    if (_CHESS_GAMETYPE_USER == $gametype) { | |
| 269 | - $form->addElement( | |
| 270 | - new XoopsFormText( | |
| 271 | - _MD_CHESS_LABEL_OPPONENT . ':', 'opponent', _CHESS_TEXTBOX_OPPONENT_SIZE, _CHESS_TEXTBOX_OPPONENT_MAXLEN, $opponent_username | |
| 272 | - ) | |
| 273 | - ); | |
| 274 | - } | |
| 268 | +	if (_CHESS_GAMETYPE_USER == $gametype) { | |
| 269 | + $form->addElement( | |
| 270 | + new XoopsFormText( | |
| 271 | + _MD_CHESS_LABEL_OPPONENT . ':', 'opponent', _CHESS_TEXTBOX_OPPONENT_SIZE, _CHESS_TEXTBOX_OPPONENT_MAXLEN, $opponent_username | |
| 272 | + ) | |
| 273 | + ); | |
| 274 | + } | |
| 275 | 275 | |
| 276 | - $radio_color = new XoopsFormRadio(_MD_CHESS_LABEL_COLOR . ':', 'coloroption', $coloroption); | |
| 276 | + $radio_color = new XoopsFormRadio(_MD_CHESS_LABEL_COLOR . ':', 'coloroption', $coloroption); | |
| 277 | 277 | |
| 278 | - $radio_color->addOption(_CHESS_COLOROPTION_OPPONENT, _MD_CHESS_RADIO_COLOR_OPPONENT); | |
| 278 | + $radio_color->addOption(_CHESS_COLOROPTION_OPPONENT, _MD_CHESS_RADIO_COLOR_OPPONENT); | |
| 279 | 279 | |
| 280 | - $radio_color->addOption(_CHESS_COLOROPTION_RANDOM, _MD_CHESS_RADIO_COLOR_RANDOM); | |
| 280 | + $radio_color->addOption(_CHESS_COLOROPTION_RANDOM, _MD_CHESS_RADIO_COLOR_RANDOM); | |
| 281 | 281 | |
| 282 | - $radio_color->addOption(_CHESS_COLOROPTION_WHITE, _MD_CHESS_RADIO_COLOR_WHITE); | |
| 282 | + $radio_color->addOption(_CHESS_COLOROPTION_WHITE, _MD_CHESS_RADIO_COLOR_WHITE); | |
| 283 | 283 | |
| 284 | - $radio_color->addOption(_CHESS_COLOROPTION_BLACK, _MD_CHESS_RADIO_COLOR_BLACK); | |
| 284 | + $radio_color->addOption(_CHESS_COLOROPTION_BLACK, _MD_CHESS_RADIO_COLOR_BLACK); | |
| 285 | 285 | |
| 286 | - $form->addElement($radio_color); | |
| 286 | + $form->addElement($radio_color); | |
| 287 | 287 | |
| 288 | -    if ('none' !== chess_moduleConfig('rating_system')) { | |
| 289 | -        if (_CHESS_GAMETYPE_OPEN == $gametype || _CHESS_GAMETYPE_USER == $gametype) { | |
| 290 | -            if (chess_moduleConfig('allow_unrated_games')) { | |
| 291 | - $radio_rated = new XoopsFormRadio(_MD_CHESS_RATED_GAME . ':', 'rated', $rated); | |
| 288 | +	if ('none' !== chess_moduleConfig('rating_system')) { | |
| 289 | +		if (_CHESS_GAMETYPE_OPEN == $gametype || _CHESS_GAMETYPE_USER == $gametype) { | |
| 290 | +			if (chess_moduleConfig('allow_unrated_games')) { | |
| 291 | + $radio_rated = new XoopsFormRadio(_MD_CHESS_RATED_GAME . ':', 'rated', $rated); | |
| 292 | 292 | |
| 293 | - $radio_rated->addOption(1, _YES); | |
| 293 | + $radio_rated->addOption(1, _YES); | |
| 294 | 294 | |
| 295 | - $radio_rated->addOption(0, _NO); | |
| 295 | + $radio_rated->addOption(0, _NO); | |
| 296 | 296 | |
| 297 | - $form->addElement($radio_rated); | |
| 298 | -            } else { | |
| 299 | -                $form->addElement(new XoopsFormHidden('rated', $rated)); | |
| 300 | - } | |
| 301 | - } | |
| 302 | -    } else { | |
| 303 | -        $form->addElement(new XoopsFormHidden('rated', 0)); | |
| 304 | - } | |
| 297 | + $form->addElement($radio_rated); | |
| 298 | +			} else { | |
| 299 | +				$form->addElement(new XoopsFormHidden('rated', $rated)); | |
| 300 | + } | |
| 301 | + } | |
| 302 | +	} else { | |
| 303 | +		$form->addElement(new XoopsFormHidden('rated', 0)); | |
| 304 | + } | |
| 305 | 305 | |
| 306 | -    $buttons = new XoopsFormElementTray(''); | |
| 306 | +	$buttons = new XoopsFormElementTray(''); | |
| 307 | 307 | |
| 308 | -    $buttons->addElement(new XoopsFormButton('', 'submit_challenge2', _MD_CHESS_CREATE_SUBMIT, 'submit')); | |
| 308 | +	$buttons->addElement(new XoopsFormButton('', 'submit_challenge2', _MD_CHESS_CREATE_SUBMIT, 'submit')); | |
| 309 | 309 | |
| 310 | -    $buttons->addElement(new XoopsFormButton('', 'cancel_challenge2', _MD_CHESS_CREATE_CANCEL, 'submit')); | |
| 310 | +	$buttons->addElement(new XoopsFormButton('', 'cancel_challenge2', _MD_CHESS_CREATE_CANCEL, 'submit')); | |
| 311 | 311 | |
| 312 | - $form->addElement($buttons); | |
| 312 | + $form->addElement($buttons); | |
| 313 | 313 | |
| 314 | - $form->display(); | |
| 314 | + $form->display(); | |
| 315 | 315 | } | 
| 316 | 316 | |
| 317 | 317 | /** | 
| @@ -325,124 +325,124 @@ discard block | ||
| 325 | 325 | */ | 
| 326 | 326 | function chess_show_create_form3($gametype, $fen, $coloroption, $opponent_uid, $rated) | 
| 327 | 327 |  { | 
| 328 | -    $memberHandler = xoops_getHandler('member'); | |
| 328 | +	$memberHandler = xoops_getHandler('member'); | |
| 329 | 329 | |
| 330 | - $opponent_user = $memberHandler->getUser($opponent_uid); | |
| 330 | + $opponent_user = $memberHandler->getUser($opponent_uid); | |
| 331 | 331 | |
| 332 | -    $opponent_username = is_object($opponent_user) ? $opponent_user->getVar('uname') : ''; | |
| 332 | +	$opponent_username = is_object($opponent_user) ? $opponent_user->getVar('uname') : ''; | |
| 333 | 333 | |
| 334 | - $form = new XoopsThemeForm(_MD_CHESS_CREATE_FORM, 'create_form3', 'create.php', 'post', true); | |
| 334 | + $form = new XoopsThemeForm(_MD_CHESS_CREATE_FORM, 'create_form3', 'create.php', 'post', true); | |
| 335 | 335 | |
| 336 | -    $form->addElement(new XoopsFormHidden('gametype', $gametype)); | |
| 336 | +	$form->addElement(new XoopsFormHidden('gametype', $gametype)); | |
| 337 | 337 | |
| 338 | -    $form->addElement(new XoopsFormHidden('fen', $fen)); | |
| 338 | +	$form->addElement(new XoopsFormHidden('fen', $fen)); | |
| 339 | 339 | |
| 340 | -    $form->addElement(new XoopsFormHidden('opponent', $opponent_username)); | |
| 340 | +	$form->addElement(new XoopsFormHidden('opponent', $opponent_username)); | |
| 341 | 341 | |
| 342 | -    $form->addElement(new XoopsFormHidden('coloroption', $coloroption)); | |
| 342 | +	$form->addElement(new XoopsFormHidden('coloroption', $coloroption)); | |
| 343 | 343 | |
| 344 | -    $form->addElement(new XoopsFormHidden('rated', $rated)); | |
| 344 | +	$form->addElement(new XoopsFormHidden('rated', $rated)); | |
| 345 | 345 | |
| 346 | -    $form->addElement(new XoopsFormLabel('', '<div class="confirmMsg">' . _MD_CHESS_GAME_CONFIRM . '</div>')); | |
| 346 | +	$form->addElement(new XoopsFormLabel('', '<div class="confirmMsg">' . _MD_CHESS_GAME_CONFIRM . '</div>')); | |
| 347 | 347 | |
| 348 | -    switch ($gametype) { | |
| 349 | - case _CHESS_GAMETYPE_OPEN: | |
| 350 | - $label_gametype = _MD_CHESS_LABEL_GAMETYPE_OPEN; | |
| 351 | - break; | |
| 352 | - case _CHESS_GAMETYPE_USER: | |
| 353 | - $label_gametype = _MD_CHESS_LABEL_GAMETYPE_USER; | |
| 354 | - break; | |
| 355 | - case _CHESS_GAMETYPE_SELF: | |
| 356 | - $label_gametype = _MD_CHESS_LABEL_GAMETYPE_SELF; | |
| 357 | - break; | |
| 358 | - default: | |
| 359 | - $label_gametype = _MD_CHESS_LABEL_ERROR; | |
| 360 | - break; | |
| 361 | - } | |
| 348 | +	switch ($gametype) { | |
| 349 | + case _CHESS_GAMETYPE_OPEN: | |
| 350 | + $label_gametype = _MD_CHESS_LABEL_GAMETYPE_OPEN; | |
| 351 | + break; | |
| 352 | + case _CHESS_GAMETYPE_USER: | |
| 353 | + $label_gametype = _MD_CHESS_LABEL_GAMETYPE_USER; | |
| 354 | + break; | |
| 355 | + case _CHESS_GAMETYPE_SELF: | |
| 356 | + $label_gametype = _MD_CHESS_LABEL_GAMETYPE_SELF; | |
| 357 | + break; | |
| 358 | + default: | |
| 359 | + $label_gametype = _MD_CHESS_LABEL_ERROR; | |
| 360 | + break; | |
| 361 | + } | |
| 362 | 362 | |
| 363 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_GAMETYPE . ':', $label_gametype)); | |
| 363 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_GAMETYPE . ':', $label_gametype)); | |
| 364 | 364 | |
| 365 | -    if (!empty($fen)) { | |
| 366 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_FEN_SETUP . ':', $fen)); | |
| 367 | - } | |
| 365 | +	if (!empty($fen)) { | |
| 366 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_FEN_SETUP . ':', $fen)); | |
| 367 | + } | |
| 368 | 368 | |
| 369 | -    if (_CHESS_GAMETYPE_USER == $gametype) { | |
| 370 | -        $memberHandler = xoops_getHandler('member'); | |
| 369 | +	if (_CHESS_GAMETYPE_USER == $gametype) { | |
| 370 | +		$memberHandler = xoops_getHandler('member'); | |
| 371 | 371 | |
| 372 | - $opponent_user = $memberHandler->getUser($opponent_uid); | |
| 372 | + $opponent_user = $memberHandler->getUser($opponent_uid); | |
| 373 | 373 | |
| 374 | -        $opponent_username = is_object($opponent_user) ? $opponent_user->getVar('uname') : ''; | |
| 374 | +		$opponent_username = is_object($opponent_user) ? $opponent_user->getVar('uname') : ''; | |
| 375 | 375 | |
| 376 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_OPPONENT . ':', $opponent_username)); | |
| 377 | - } | |
| 376 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_OPPONENT . ':', $opponent_username)); | |
| 377 | + } | |
| 378 | 378 | |
| 379 | -    if (_CHESS_GAMETYPE_OPEN == $gametype || _CHESS_GAMETYPE_USER == $gametype) { | |
| 380 | -        switch ($coloroption) { | |
| 381 | - case _CHESS_COLOROPTION_OPPONENT: | |
| 382 | - $label_coloroption = _MD_CHESS_RADIO_COLOR_OPPONENT; | |
| 383 | - break; | |
| 384 | - case _CHESS_COLOROPTION_RANDOM: | |
| 385 | - $label_coloroption = _MD_CHESS_RADIO_COLOR_RANDOM; | |
| 386 | - break; | |
| 387 | - case _CHESS_COLOROPTION_WHITE: | |
| 388 | - $label_coloroption = _MD_CHESS_RADIO_COLOR_WHITE; | |
| 389 | - break; | |
| 390 | - case _CHESS_COLOROPTION_BLACK: | |
| 391 | - $label_coloroption = _MD_CHESS_RADIO_COLOR_BLACK; | |
| 392 | - break; | |
| 393 | - default: | |
| 394 | - $label_coloroption = _MD_CHESS_LABEL_ERROR; | |
| 395 | - break; | |
| 396 | - } | |
| 379 | +	if (_CHESS_GAMETYPE_OPEN == $gametype || _CHESS_GAMETYPE_USER == $gametype) { | |
| 380 | +		switch ($coloroption) { | |
| 381 | + case _CHESS_COLOROPTION_OPPONENT: | |
| 382 | + $label_coloroption = _MD_CHESS_RADIO_COLOR_OPPONENT; | |
| 383 | + break; | |
| 384 | + case _CHESS_COLOROPTION_RANDOM: | |
| 385 | + $label_coloroption = _MD_CHESS_RADIO_COLOR_RANDOM; | |
| 386 | + break; | |
| 387 | + case _CHESS_COLOROPTION_WHITE: | |
| 388 | + $label_coloroption = _MD_CHESS_RADIO_COLOR_WHITE; | |
| 389 | + break; | |
| 390 | + case _CHESS_COLOROPTION_BLACK: | |
| 391 | + $label_coloroption = _MD_CHESS_RADIO_COLOR_BLACK; | |
| 392 | + break; | |
| 393 | + default: | |
| 394 | + $label_coloroption = _MD_CHESS_LABEL_ERROR; | |
| 395 | + break; | |
| 396 | + } | |
| 397 | 397 | |
| 398 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_COLOR . ':', $label_coloroption)); | |
| 398 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_COLOR . ':', $label_coloroption)); | |
| 399 | 399 | |
| 400 | -        if ('none' != chess_moduleConfig('rating_system')) { | |
| 401 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_RATED_GAME . ':', $rated ? _YES : _NO)); | |
| 402 | - } | |
| 400 | +		if ('none' != chess_moduleConfig('rating_system')) { | |
| 401 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_RATED_GAME . ':', $rated ? _YES : _NO)); | |
| 402 | + } | |
| 403 | 403 | |
| 404 | - // Determine whether current user is subscribed to receive a notification when his challenge is accepted. | |
| 404 | + // Determine whether current user is subscribed to receive a notification when his challenge is accepted. | |
| 405 | 405 | |
| 406 | - global $xoopsModule, $xoopsUser; | |
| 406 | + global $xoopsModule, $xoopsUser; | |
| 407 | 407 | |
| 408 | -        $uid = $xoopsUser->getVar('uid'); | |
| 408 | +		$uid = $xoopsUser->getVar('uid'); | |
| 409 | 409 | |
| 410 | -        $mid = $xoopsModule->getVar('mid'); | |
| 410 | +		$mid = $xoopsModule->getVar('mid'); | |
| 411 | 411 | |
| 412 | -        $notificationHandler = xoops_getHandler('notification'); | |
| 412 | +		$notificationHandler = xoops_getHandler('notification'); | |
| 413 | 413 | |
| 414 | -        $is_subscribed = 0 != $notificationHandler->isSubscribed('global', 0, 'notify_accept_challenge', $mid, $uid); | |
| 414 | +		$is_subscribed = 0 != $notificationHandler->isSubscribed('global', 0, 'notify_accept_challenge', $mid, $uid); | |
| 415 | 415 | |
| 416 | - // Display checkbox with checked-state reflecting subscription status. | |
| 416 | + // Display checkbox with checked-state reflecting subscription status. | |
| 417 | 417 | |
| 418 | - $checked_value = 1; | |
| 418 | + $checked_value = 1; | |
| 419 | 419 | |
| 420 | -        $checkbox_notify_acpt_chal = new XoopsFormCheckBox('', 'notify_accept', $is_subscribed ? $checked_value : null); | |
| 420 | +		$checkbox_notify_acpt_chal = new XoopsFormCheckBox('', 'notify_accept', $is_subscribed ? $checked_value : null); | |
| 421 | 421 | |
| 422 | - $checkbox_notify_acpt_chal->addOption($checked_value, _MD_CHESS_NEVT_ACPT_CHAL_CAP); | |
| 422 | + $checkbox_notify_acpt_chal->addOption($checked_value, _MD_CHESS_NEVT_ACPT_CHAL_CAP); | |
| 423 | 423 | |
| 424 | - $form->addElement($checkbox_notify_acpt_chal); | |
| 424 | + $form->addElement($checkbox_notify_acpt_chal); | |
| 425 | 425 | |
| 426 | - // Display checkbox, initially checked. | |
| 426 | + // Display checkbox, initially checked. | |
| 427 | 427 | |
| 428 | - $checked_value = 1; | |
| 428 | + $checked_value = 1; | |
| 429 | 429 | |
| 430 | -        $checkbox_notify_move = new XoopsFormCheckBox('', 'notify_move', $checked_value); | |
| 430 | +		$checkbox_notify_move = new XoopsFormCheckBox('', 'notify_move', $checked_value); | |
| 431 | 431 | |
| 432 | - $checkbox_notify_move->addOption($checked_value, _MD_CHESS_NEVT_MOVE_CAP); | |
| 432 | + $checkbox_notify_move->addOption($checked_value, _MD_CHESS_NEVT_MOVE_CAP); | |
| 433 | 433 | |
| 434 | - $form->addElement($checkbox_notify_move); | |
| 435 | - } | |
| 434 | + $form->addElement($checkbox_notify_move); | |
| 435 | + } | |
| 436 | 436 | |
| 437 | -    $buttons = new XoopsFormElementTray(''); | |
| 437 | +	$buttons = new XoopsFormElementTray(''); | |
| 438 | 438 | |
| 439 | -    $buttons->addElement(new XoopsFormButton('', 'submit_challenge3', _MD_CHESS_CREATE_SUBMIT, 'submit')); | |
| 439 | +	$buttons->addElement(new XoopsFormButton('', 'submit_challenge3', _MD_CHESS_CREATE_SUBMIT, 'submit')); | |
| 440 | 440 | |
| 441 | -    $buttons->addElement(new XoopsFormButton('', 'cancel_challenge3', _MD_CHESS_CREATE_CANCEL, 'submit')); | |
| 441 | +	$buttons->addElement(new XoopsFormButton('', 'cancel_challenge3', _MD_CHESS_CREATE_CANCEL, 'submit')); | |
| 442 | 442 | |
| 443 | - $form->addElement($buttons); | |
| 443 | + $form->addElement($buttons); | |
| 444 | 444 | |
| 445 | - $form->display(); | |
| 445 | + $form->display(); | |
| 446 | 446 | } | 
| 447 | 447 | |
| 448 | 448 | /** | 
| @@ -452,125 +452,125 @@ discard block | ||
| 452 | 452 | */ | 
| 453 | 453 | function chess_show_accept_form($challenge_id) | 
| 454 | 454 |  { | 
| 455 | - global $xoopsDB, $xoopsUser; | |
| 455 | + global $xoopsDB, $xoopsUser; | |
| 456 | 456 | |
| 457 | -    $challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 457 | +	$challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 458 | 458 | |
| 459 | - $result = $xoopsDB->query( | |
| 460 | - trim( | |
| 461 | - " | |
| 459 | + $result = $xoopsDB->query( | |
| 460 | + trim( | |
| 461 | + " | |
| 462 | 462 | SELECT game_type, fen, color_option, player1_uid, player2_uid, UNIX_TIMESTAMP(create_date) as create_date, is_rated | 
| 463 | 463 | FROM $challenges_table | 
| 464 | 464 | WHERE challenge_id = '$challenge_id' | 
| 465 | 465 | " | 
| 466 | - ) | |
| 467 | - ); | |
| 466 | + ) | |
| 467 | + ); | |
| 468 | 468 | |
| 469 | -    if ($xoopsDB->getRowsNum($result) < 1) { | |
| 470 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 471 | - } | |
| 469 | +	if ($xoopsDB->getRowsNum($result) < 1) { | |
| 470 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 471 | + } | |
| 472 | 472 | |
| 473 | - $row = $xoopsDB->fetchArray($result); | |
| 473 | + $row = $xoopsDB->fetchArray($result); | |
| 474 | 474 | |
| 475 | - $xoopsDB->freeRecordSet($result); | |
| 475 | + $xoopsDB->freeRecordSet($result); | |
| 476 | 476 | |
| 477 | - $form = new XoopsThemeForm(_MD_CHESS_ACCEPT_FORM, 'accept_form', 'create.php', 'post', true); | |
| 477 | + $form = new XoopsThemeForm(_MD_CHESS_ACCEPT_FORM, 'accept_form', 'create.php', 'post', true); | |
| 478 | 478 | |
| 479 | -    $form->addElement(new XoopsFormHidden('challenge_id', $challenge_id)); | |
| 479 | +	$form->addElement(new XoopsFormHidden('challenge_id', $challenge_id)); | |
| 480 | 480 | |
| 481 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_DATE_CREATED . ':', formatTimestamp($row['create_date'], 'm'))); | |
| 481 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_DATE_CREATED . ':', formatTimestamp($row['create_date'], 'm'))); | |
| 482 | 482 | |
| 483 | -    $memberHandler = xoops_getHandler('member'); | |
| 483 | +	$memberHandler = xoops_getHandler('member'); | |
| 484 | 484 | |
| 485 | -    switch ($row['game_type']) { | |
| 486 | - case _CHESS_GAMETYPE_OPEN: | |
| 487 | - $label_gametype = _MD_CHESS_LABEL_GAMETYPE_OPEN; | |
| 488 | - break; | |
| 489 | - case _CHESS_GAMETYPE_USER: | |
| 490 | - $player2_user = $memberHandler->getUser($row['player2_uid']); | |
| 491 | -            $player2_username = is_object($player2_user) ? $player2_user->getVar('uname') : '?'; | |
| 492 | - $label_gametype = _MD_CHESS_LABEL_GAMETYPE_USER . ': ' . $player2_username; | |
| 493 | - break; | |
| 494 | - case _CHESS_GAMETYPE_SELF: | |
| 495 | - $label_gametype = _MD_CHESS_LABEL_GAMETYPE_SELF; | |
| 496 | - break; | |
| 497 | - default: | |
| 498 | - $label_gametype = _MD_CHESS_LABEL_ERROR; | |
| 499 | - break; | |
| 500 | - } | |
| 485 | +	switch ($row['game_type']) { | |
| 486 | + case _CHESS_GAMETYPE_OPEN: | |
| 487 | + $label_gametype = _MD_CHESS_LABEL_GAMETYPE_OPEN; | |
| 488 | + break; | |
| 489 | + case _CHESS_GAMETYPE_USER: | |
| 490 | + $player2_user = $memberHandler->getUser($row['player2_uid']); | |
| 491 | +			$player2_username = is_object($player2_user) ? $player2_user->getVar('uname') : '?'; | |
| 492 | + $label_gametype = _MD_CHESS_LABEL_GAMETYPE_USER . ': ' . $player2_username; | |
| 493 | + break; | |
| 494 | + case _CHESS_GAMETYPE_SELF: | |
| 495 | + $label_gametype = _MD_CHESS_LABEL_GAMETYPE_SELF; | |
| 496 | + break; | |
| 497 | + default: | |
| 498 | + $label_gametype = _MD_CHESS_LABEL_ERROR; | |
| 499 | + break; | |
| 500 | + } | |
| 501 | 501 | |
| 502 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_GAMETYPE . ':', $label_gametype)); | |
| 502 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_GAMETYPE . ':', $label_gametype)); | |
| 503 | 503 | |
| 504 | - $player1_user = $memberHandler->getUser($row['player1_uid']); | |
| 504 | + $player1_user = $memberHandler->getUser($row['player1_uid']); | |
| 505 | 505 | |
| 506 | -    $player1_username = is_object($player1_user) ? $player1_user->getVar('uname') : '?'; | |
| 506 | +	$player1_username = is_object($player1_user) ? $player1_user->getVar('uname') : '?'; | |
| 507 | 507 | |
| 508 | - $form->addElement( | |
| 509 | - new XoopsFormLabel( | |
| 510 | -            _MD_CHESS_LABEL_CHALLENGER . ':', "<a href='" . XOOPS_URL . "/modules/chess/player_stats.php?player_uid={$row['player1_uid']}'>$player1_username</a>" | |
| 511 | - ) | |
| 512 | - ); | |
| 508 | + $form->addElement( | |
| 509 | + new XoopsFormLabel( | |
| 510 | +			_MD_CHESS_LABEL_CHALLENGER . ':', "<a href='" . XOOPS_URL . "/modules/chess/player_stats.php?player_uid={$row['player1_uid']}'>$player1_username</a>" | |
| 511 | + ) | |
| 512 | + ); | |
| 513 | 513 | |
| 514 | -    $player2_username = $xoopsUser ? $xoopsUser->getVar('uname') : '?'; | |
| 514 | +	$player2_username = $xoopsUser ? $xoopsUser->getVar('uname') : '?'; | |
| 515 | 515 | |
| 516 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_OPPONENT . ':', $player2_username)); | |
| 516 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_OPPONENT . ':', $player2_username)); | |
| 517 | 517 | |
| 518 | -    if (!empty($row['fen'])) { | |
| 519 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_FEN_SETUP . ':', $row['fen'])); | |
| 520 | - } | |
| 518 | +	if (!empty($row['fen'])) { | |
| 519 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_FEN_SETUP . ':', $row['fen'])); | |
| 520 | + } | |
| 521 | 521 | |
| 522 | -    if (_CHESS_COLOROPTION_OPPONENT == $row['color_option']) { | |
| 523 | - $radio_color = new XoopsFormRadio(_MD_CHESS_LABEL_COLOR . ':', 'coloroption', _CHESS_COLOROPTION_RANDOM); | |
| 522 | +	if (_CHESS_COLOROPTION_OPPONENT == $row['color_option']) { | |
| 523 | + $radio_color = new XoopsFormRadio(_MD_CHESS_LABEL_COLOR . ':', 'coloroption', _CHESS_COLOROPTION_RANDOM); | |
| 524 | 524 | |
| 525 | - $radio_color->addOption(_CHESS_COLOROPTION_RANDOM, _MD_CHESS_RADIO_COLOR_RANDOM); | |
| 525 | + $radio_color->addOption(_CHESS_COLOROPTION_RANDOM, _MD_CHESS_RADIO_COLOR_RANDOM); | |
| 526 | 526 | |
| 527 | - $radio_color->addOption(_CHESS_COLOROPTION_WHITE, _MD_CHESS_RADIO_COLOR_WHITE); | |
| 527 | + $radio_color->addOption(_CHESS_COLOROPTION_WHITE, _MD_CHESS_RADIO_COLOR_WHITE); | |
| 528 | 528 | |
| 529 | - $radio_color->addOption(_CHESS_COLOROPTION_BLACK, _MD_CHESS_RADIO_COLOR_BLACK); | |
| 529 | + $radio_color->addOption(_CHESS_COLOROPTION_BLACK, _MD_CHESS_RADIO_COLOR_BLACK); | |
| 530 | 530 | |
| 531 | - $form->addElement($radio_color); | |
| 532 | -    } else { | |
| 533 | -        switch ($row['color_option']) { | |
| 534 | - case _CHESS_COLOROPTION_RANDOM: | |
| 535 | - $label_coloroption = _MD_CHESS_RADIO_COLOR_RANDOM; | |
| 536 | - break; | |
| 537 | - case _CHESS_COLOROPTION_WHITE: | |
| 538 | - $label_coloroption = _MD_CHESS_RADIO_COLOR_BLACK; // player1 white, player2 black | |
| 539 | - break; | |
| 540 | - case _CHESS_COLOROPTION_BLACK: | |
| 541 | - $label_coloroption = _MD_CHESS_RADIO_COLOR_WHITE; // player1 black, player2 white | |
| 542 | - break; | |
| 543 | - default: | |
| 544 | - $label_coloroption = _MD_CHESS_LABEL_ERROR; | |
| 545 | - break; | |
| 546 | - } | |
| 531 | + $form->addElement($radio_color); | |
| 532 | +	} else { | |
| 533 | +		switch ($row['color_option']) { | |
| 534 | + case _CHESS_COLOROPTION_RANDOM: | |
| 535 | + $label_coloroption = _MD_CHESS_RADIO_COLOR_RANDOM; | |
| 536 | + break; | |
| 537 | + case _CHESS_COLOROPTION_WHITE: | |
| 538 | + $label_coloroption = _MD_CHESS_RADIO_COLOR_BLACK; // player1 white, player2 black | |
| 539 | + break; | |
| 540 | + case _CHESS_COLOROPTION_BLACK: | |
| 541 | + $label_coloroption = _MD_CHESS_RADIO_COLOR_WHITE; // player1 black, player2 white | |
| 542 | + break; | |
| 543 | + default: | |
| 544 | + $label_coloroption = _MD_CHESS_LABEL_ERROR; | |
| 545 | + break; | |
| 546 | + } | |
| 547 | 547 | |
| 548 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_COLOR . ':', $label_coloroption)); | |
| 549 | - } | |
| 548 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_COLOR . ':', $label_coloroption)); | |
| 549 | + } | |
| 550 | 550 | |
| 551 | -    if ('none' != chess_moduleConfig('rating_system')) { | |
| 552 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_RATED_GAME . ':', $row['is_rated'] ? _YES : _NO)); | |
| 553 | - } | |
| 551 | +	if ('none' != chess_moduleConfig('rating_system')) { | |
| 552 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_RATED_GAME . ':', $row['is_rated'] ? _YES : _NO)); | |
| 553 | + } | |
| 554 | 554 | |
| 555 | - // Display notification-subscribe checkbox, initially checked. | |
| 555 | + // Display notification-subscribe checkbox, initially checked. | |
| 556 | 556 | |
| 557 | - $checked_value = 1; | |
| 557 | + $checked_value = 1; | |
| 558 | 558 | |
| 559 | -    $checkbox_notify_move = new XoopsFormCheckBox('', 'notify_move', $checked_value); | |
| 559 | +	$checkbox_notify_move = new XoopsFormCheckBox('', 'notify_move', $checked_value); | |
| 560 | 560 | |
| 561 | - $checkbox_notify_move->addOption($checked_value, _MD_CHESS_NEVT_MOVE_CAP); | |
| 561 | + $checkbox_notify_move->addOption($checked_value, _MD_CHESS_NEVT_MOVE_CAP); | |
| 562 | 562 | |
| 563 | - $form->addElement($checkbox_notify_move); | |
| 563 | + $form->addElement($checkbox_notify_move); | |
| 564 | 564 | |
| 565 | -    $tray = new XoopsFormElementTray(''); | |
| 565 | +	$tray = new XoopsFormElementTray(''); | |
| 566 | 566 | |
| 567 | -    $tray->addElement(new XoopsFormButton('', 'submit_accept', _MD_CHESS_CREATE_ACCEPT, 'submit')); | |
| 567 | +	$tray->addElement(new XoopsFormButton('', 'submit_accept', _MD_CHESS_CREATE_ACCEPT, 'submit')); | |
| 568 | 568 | |
| 569 | -    $tray->addElement(new XoopsFormButton('', 'cancel_accept', _MD_CHESS_CREATE_CANCEL, 'submit')); | |
| 569 | +	$tray->addElement(new XoopsFormButton('', 'cancel_accept', _MD_CHESS_CREATE_CANCEL, 'submit')); | |
| 570 | 570 | |
| 571 | - $form->addElement($tray); | |
| 571 | + $form->addElement($tray); | |
| 572 | 572 | |
| 573 | - $form->display(); | |
| 573 | + $form->display(); | |
| 574 | 574 | } | 
| 575 | 575 | |
| 576 | 576 | /** | 
| @@ -582,114 +582,114 @@ discard block | ||
| 582 | 582 | */ | 
| 583 | 583 | function chess_show_delete_form($challenge_id, $show_arbiter_ctrl, $error_msg = '') | 
| 584 | 584 |  { | 
| 585 | - global $xoopsDB; | |
| 585 | + global $xoopsDB; | |
| 586 | 586 | |
| 587 | -    $challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 587 | +	$challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 588 | 588 | |
| 589 | - $result = $xoopsDB->query( | |
| 590 | - trim( | |
| 591 | - " | |
| 589 | + $result = $xoopsDB->query( | |
| 590 | + trim( | |
| 591 | + " | |
| 592 | 592 | SELECT game_type, fen, color_option, player1_uid, player2_uid, UNIX_TIMESTAMP(create_date) as create_date, is_rated | 
| 593 | 593 | FROM $challenges_table | 
| 594 | 594 | WHERE challenge_id = '$challenge_id' | 
| 595 | 595 | " | 
| 596 | - ) | |
| 597 | - ); | |
| 596 | + ) | |
| 597 | + ); | |
| 598 | 598 | |
| 599 | -    if ($xoopsDB->getRowsNum($result) < 1) { | |
| 600 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 601 | - } | |
| 599 | +	if ($xoopsDB->getRowsNum($result) < 1) { | |
| 600 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 601 | + } | |
| 602 | 602 | |
| 603 | - $row = $xoopsDB->fetchArray($result); | |
| 603 | + $row = $xoopsDB->fetchArray($result); | |
| 604 | 604 | |
| 605 | - $xoopsDB->freeRecordSet($result); | |
| 605 | + $xoopsDB->freeRecordSet($result); | |
| 606 | 606 | |
| 607 | - $form = new XoopsThemeForm(_MD_CHESS_DELETE_FORM, 'delete_form', 'create.php', 'post', true); | |
| 607 | + $form = new XoopsThemeForm(_MD_CHESS_DELETE_FORM, 'delete_form', 'create.php', 'post', true); | |
| 608 | 608 | |
| 609 | -    $form->addElement(new XoopsFormHidden('challenge_id', $challenge_id)); | |
| 609 | +	$form->addElement(new XoopsFormHidden('challenge_id', $challenge_id)); | |
| 610 | 610 | |
| 611 | -    if ($show_arbiter_ctrl) { | |
| 612 | -        $form->addElement(new XoopsFormHidden('show_arbiter_ctrl', $show_arbiter_ctrl)); | |
| 613 | - } | |
| 611 | +	if ($show_arbiter_ctrl) { | |
| 612 | +		$form->addElement(new XoopsFormHidden('show_arbiter_ctrl', $show_arbiter_ctrl)); | |
| 613 | + } | |
| 614 | 614 | |
| 615 | -    if ($error_msg) { | |
| 616 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_ERROR . ': ', '<div class="errorMsg">' . $error_msg . '</div>')); | |
| 617 | - } | |
| 615 | +	if ($error_msg) { | |
| 616 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_ERROR . ': ', '<div class="errorMsg">' . $error_msg . '</div>')); | |
| 617 | + } | |
| 618 | 618 | |
| 619 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_DATE_CREATED . ':', formatTimestamp($row['create_date'], 'm'))); | |
| 619 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_DATE_CREATED . ':', formatTimestamp($row['create_date'], 'm'))); | |
| 620 | 620 | |
| 621 | -    $memberHandler = xoops_getHandler('member'); | |
| 621 | +	$memberHandler = xoops_getHandler('member'); | |
| 622 | 622 | |
| 623 | -    switch ($row['game_type']) { | |
| 624 | - case _CHESS_GAMETYPE_OPEN: | |
| 625 | - $label_gametype = _MD_CHESS_LABEL_GAMETYPE_OPEN; | |
| 626 | - break; | |
| 627 | - case _CHESS_GAMETYPE_USER: | |
| 628 | - $player2_user = $memberHandler->getUser($row['player2_uid']); | |
| 629 | -            $player2_username = is_object($player2_user) ? $player2_user->getVar('uname') : '?'; | |
| 630 | - $label_gametype = _MD_CHESS_LABEL_GAMETYPE_USER . ': ' . $player2_username; | |
| 631 | - break; | |
| 632 | - case _CHESS_GAMETYPE_SELF: | |
| 633 | - $label_gametype = _MD_CHESS_LABEL_GAMETYPE_SELF; | |
| 634 | - break; | |
| 635 | - default: | |
| 636 | - $label_gametype = _MD_CHESS_LABEL_ERROR; | |
| 637 | - break; | |
| 638 | - } | |
| 623 | +	switch ($row['game_type']) { | |
| 624 | + case _CHESS_GAMETYPE_OPEN: | |
| 625 | + $label_gametype = _MD_CHESS_LABEL_GAMETYPE_OPEN; | |
| 626 | + break; | |
| 627 | + case _CHESS_GAMETYPE_USER: | |
| 628 | + $player2_user = $memberHandler->getUser($row['player2_uid']); | |
| 629 | +			$player2_username = is_object($player2_user) ? $player2_user->getVar('uname') : '?'; | |
| 630 | + $label_gametype = _MD_CHESS_LABEL_GAMETYPE_USER . ': ' . $player2_username; | |
| 631 | + break; | |
| 632 | + case _CHESS_GAMETYPE_SELF: | |
| 633 | + $label_gametype = _MD_CHESS_LABEL_GAMETYPE_SELF; | |
| 634 | + break; | |
| 635 | + default: | |
| 636 | + $label_gametype = _MD_CHESS_LABEL_ERROR; | |
| 637 | + break; | |
| 638 | + } | |
| 639 | 639 | |
| 640 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_GAMETYPE . ':', $label_gametype)); | |
| 640 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_GAMETYPE . ':', $label_gametype)); | |
| 641 | 641 | |
| 642 | - $player1_user = $memberHandler->getUser($row['player1_uid']); | |
| 642 | + $player1_user = $memberHandler->getUser($row['player1_uid']); | |
| 643 | 643 | |
| 644 | -    $player1_username = is_object($player1_user) ? $player1_user->getVar('uname') : '?'; | |
| 644 | +	$player1_username = is_object($player1_user) ? $player1_user->getVar('uname') : '?'; | |
| 645 | 645 | |
| 646 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_CHALLENGER . ':', $player1_username)); | |
| 646 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_CHALLENGER . ':', $player1_username)); | |
| 647 | 647 | |
| 648 | -    if (!empty($row['fen'])) { | |
| 649 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_FEN_SETUP . ':', $row['fen'])); | |
| 650 | - } | |
| 648 | +	if (!empty($row['fen'])) { | |
| 649 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_FEN_SETUP . ':', $row['fen'])); | |
| 650 | + } | |
| 651 | 651 | |
| 652 | -    switch ($row['color_option']) { | |
| 653 | - case _CHESS_COLOROPTION_OPPONENT: | |
| 654 | - $label_coloroption = _MD_CHESS_RADIO_COLOR_OPPONENT; | |
| 655 | - break; | |
| 656 | - case _CHESS_COLOROPTION_RANDOM: | |
| 657 | - $label_coloroption = _MD_CHESS_RADIO_COLOR_RANDOM; | |
| 658 | - break; | |
| 659 | - case _CHESS_COLOROPTION_WHITE: | |
| 660 | - $label_coloroption = _MD_CHESS_RADIO_COLOR_WHITE; | |
| 661 | - break; | |
| 662 | - case _CHESS_COLOROPTION_BLACK: | |
| 663 | - $label_coloroption = _MD_CHESS_RADIO_COLOR_BLACK; | |
| 664 | - break; | |
| 665 | - default: | |
| 666 | - $label_coloroption = _MD_CHESS_LABEL_ERROR; | |
| 667 | - break; | |
| 668 | - } | |
| 652 | +	switch ($row['color_option']) { | |
| 653 | + case _CHESS_COLOROPTION_OPPONENT: | |
| 654 | + $label_coloroption = _MD_CHESS_RADIO_COLOR_OPPONENT; | |
| 655 | + break; | |
| 656 | + case _CHESS_COLOROPTION_RANDOM: | |
| 657 | + $label_coloroption = _MD_CHESS_RADIO_COLOR_RANDOM; | |
| 658 | + break; | |
| 659 | + case _CHESS_COLOROPTION_WHITE: | |
| 660 | + $label_coloroption = _MD_CHESS_RADIO_COLOR_WHITE; | |
| 661 | + break; | |
| 662 | + case _CHESS_COLOROPTION_BLACK: | |
| 663 | + $label_coloroption = _MD_CHESS_RADIO_COLOR_BLACK; | |
| 664 | + break; | |
| 665 | + default: | |
| 666 | + $label_coloroption = _MD_CHESS_LABEL_ERROR; | |
| 667 | + break; | |
| 668 | + } | |
| 669 | 669 | |
| 670 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_COLOR . ':', $label_coloroption)); | |
| 670 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_LABEL_COLOR . ':', $label_coloroption)); | |
| 671 | 671 | |
| 672 | -    if ('none' != chess_moduleConfig('rating_system')) { | |
| 673 | - $form->addElement(new XoopsFormLabel(_MD_CHESS_RATED_GAME . ':', $row['is_rated'] ? _YES : _NO)); | |
| 674 | - } | |
| 672 | +	if ('none' != chess_moduleConfig('rating_system')) { | |
| 673 | + $form->addElement(new XoopsFormLabel(_MD_CHESS_RATED_GAME . ':', $row['is_rated'] ? _YES : _NO)); | |
| 674 | + } | |
| 675 | 675 | |
| 676 | - // Display confirm-delete checkbox, initially unchecked. | |
| 676 | + // Display confirm-delete checkbox, initially unchecked. | |
| 677 | 677 | |
| 678 | - $checked_value = 1; | |
| 678 | + $checked_value = 1; | |
| 679 | 679 | |
| 680 | -    $checkbox_confirm_delete = new XoopsFormCheckBox('', 'confirm_delete', !$checked_value); | |
| 680 | +	$checkbox_confirm_delete = new XoopsFormCheckBox('', 'confirm_delete', !$checked_value); | |
| 681 | 681 | |
| 682 | - $checkbox_confirm_delete->addOption($checked_value, _MD_CHESS_CONFIRM_DELETE); | |
| 682 | + $checkbox_confirm_delete->addOption($checked_value, _MD_CHESS_CONFIRM_DELETE); | |
| 683 | 683 | |
| 684 | -    $tray = new XoopsFormElementTray(''); | |
| 684 | +	$tray = new XoopsFormElementTray(''); | |
| 685 | 685 | |
| 686 | -    $tray->addElement(new XoopsFormButton('', 'submit_delete', _MD_CHESS_CREATE_DELETE, 'submit')); | |
| 686 | +	$tray->addElement(new XoopsFormButton('', 'submit_delete', _MD_CHESS_CREATE_DELETE, 'submit')); | |
| 687 | 687 | |
| 688 | - $tray->addElement($checkbox_confirm_delete); | |
| 688 | + $tray->addElement($checkbox_confirm_delete); | |
| 689 | 689 | |
| 690 | - $form->addElement($tray); | |
| 690 | + $form->addElement($tray); | |
| 691 | 691 | |
| 692 | - $form->display(); | |
| 692 | + $form->display(); | |
| 693 | 693 | } | 
| 694 | 694 | |
| 695 | 695 | /** | 
| @@ -702,100 +702,100 @@ discard block | ||
| 702 | 702 | */ | 
| 703 | 703 | function chess_accept_challenge($challenge_id, $coloroption, $notify_move_player2 = false) | 
| 704 | 704 |  { | 
| 705 | - global $xoopsDB, $xoopsUser; | |
| 705 | + global $xoopsDB, $xoopsUser; | |
| 706 | 706 | |
| 707 | -    $challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 707 | +	$challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 708 | 708 | |
| 709 | - $result = $xoopsDB->query( | |
| 710 | - trim( | |
| 711 | - " | |
| 709 | + $result = $xoopsDB->query( | |
| 710 | + trim( | |
| 711 | + " | |
| 712 | 712 | SELECT game_type, fen, color_option, notify_move_player1, player1_uid, player2_uid, UNIX_TIMESTAMP(create_date) as create_date, is_rated | 
| 713 | 713 | FROM $challenges_table | 
| 714 | 714 | WHERE challenge_id = '$challenge_id' | 
| 715 | 715 | " | 
| 716 | - ) | |
| 717 | - ); | |
| 718 | - | |
| 719 | -    if ($xoopsDB->getRowsNum($result) < 1) { | |
| 720 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 721 | - } | |
| 722 | - | |
| 723 | - $row = $xoopsDB->fetchArray($result); | |
| 724 | - | |
| 725 | - $xoopsDB->freeRecordSet($result); | |
| 726 | - | |
| 727 | -    $uid = $xoopsUser ? $xoopsUser->getVar('uid') : 0; | |
| 728 | - | |
| 729 | -    if (_CHESS_GAMETYPE_USER == $row['game_type'] && $uid != $row['player2_uid']) { | |
| 730 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_WRONG_PLAYER2); | |
| 731 | -    } elseif ($uid == $row['player1_uid']) { | |
| 732 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_SAME_PLAYER2); | |
| 733 | - } | |
| 734 | - | |
| 735 | -    switch ($row['color_option']) { | |
| 736 | - case _CHESS_COLOROPTION_OPPONENT: | |
| 737 | -            switch ($coloroption) { | |
| 738 | - default: | |
| 739 | - case _CHESS_COLOROPTION_RANDOM: | |
| 740 | -                    if (1 == random_int(1, 2)) { | |
| 741 | - $white_uid = $row['player1_uid']; | |
| 742 | - $black_uid = $uid; | |
| 743 | -                    } else { | |
| 744 | - $white_uid = $uid; | |
| 745 | - $black_uid = $row['player1_uid']; | |
| 746 | - } | |
| 747 | - break; | |
| 748 | - case _CHESS_COLOROPTION_WHITE: | |
| 749 | - $white_uid = $uid; | |
| 750 | - $black_uid = $row['player1_uid']; | |
| 751 | - break; | |
| 752 | - case _CHESS_COLOROPTION_BLACK: | |
| 753 | - $white_uid = $row['player1_uid']; | |
| 754 | - $black_uid = $uid; | |
| 755 | - break; | |
| 756 | - } | |
| 757 | - break; | |
| 758 | - default: | |
| 759 | - case _CHESS_COLOROPTION_RANDOM: | |
| 760 | -            if (1 == random_int(1, 2)) { | |
| 761 | - $white_uid = $row['player1_uid']; | |
| 762 | - | |
| 763 | - $black_uid = $uid; | |
| 764 | -            } else { | |
| 765 | - $white_uid = $uid; | |
| 766 | - | |
| 767 | - $black_uid = $row['player1_uid']; | |
| 768 | - } | |
| 769 | - break; | |
| 770 | - case _CHESS_COLOROPTION_WHITE: | |
| 771 | - $white_uid = $row['player1_uid']; | |
| 772 | - $black_uid = $uid; | |
| 773 | - break; | |
| 774 | - case _CHESS_COLOROPTION_BLACK: | |
| 775 | - $white_uid = $uid; | |
| 776 | - $black_uid = $row['player1_uid']; | |
| 777 | - break; | |
| 778 | - } | |
| 779 | - | |
| 780 | - $game_id = chess_create_game($white_uid, $black_uid, $row['fen'], $row['is_rated'], $row['notify_move_player1'] ? $row['player1_uid'] : 0, $notify_move_player2); | |
| 781 | - | |
| 782 | -    $xoopsDB->query("DELETE FROM $challenges_table WHERE challenge_id = '$challenge_id'"); | |
| 783 | - | |
| 784 | -    if ($xoopsDB->errno()) { | |
| 785 | - trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 786 | - } | |
| 787 | - | |
| 788 | - // Notify player 1 that his challenge has been accepted (if he has subscribed to the notification). | |
| 789 | - | |
| 790 | -    $player2_username = $xoopsUser ? $xoopsUser->getVar('uname') : '*unknown*'; | |
| 791 | - | |
| 792 | -    $notificationHandler = xoops_getHandler('notification'); | |
| 793 | - | |
| 794 | - $extra_tags = ['CHESS_PLAYER' => $player2_username, 'CHESS_GAME_ID' => $game_id]; | |
| 795 | - | |
| 796 | -    $notificationHandler->triggerEvent('global', 0, 'notify_accept_challenge', $extra_tags, [$row['player1_uid']]); | |
| 797 | - | |
| 798 | - redirect_header(XOOPS_URL . "/modules/chess/game.php?game_id=$game_id", _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_CREATED); | |
| 716 | + ) | |
| 717 | + ); | |
| 718 | + | |
| 719 | +	if ($xoopsDB->getRowsNum($result) < 1) { | |
| 720 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 721 | + } | |
| 722 | + | |
| 723 | + $row = $xoopsDB->fetchArray($result); | |
| 724 | + | |
| 725 | + $xoopsDB->freeRecordSet($result); | |
| 726 | + | |
| 727 | +	$uid = $xoopsUser ? $xoopsUser->getVar('uid') : 0; | |
| 728 | + | |
| 729 | +	if (_CHESS_GAMETYPE_USER == $row['game_type'] && $uid != $row['player2_uid']) { | |
| 730 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_WRONG_PLAYER2); | |
| 731 | +	} elseif ($uid == $row['player1_uid']) { | |
| 732 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_SAME_PLAYER2); | |
| 733 | + } | |
| 734 | + | |
| 735 | +	switch ($row['color_option']) { | |
| 736 | + case _CHESS_COLOROPTION_OPPONENT: | |
| 737 | +			switch ($coloroption) { | |
| 738 | + default: | |
| 739 | + case _CHESS_COLOROPTION_RANDOM: | |
| 740 | +					if (1 == random_int(1, 2)) { | |
| 741 | + $white_uid = $row['player1_uid']; | |
| 742 | + $black_uid = $uid; | |
| 743 | +					} else { | |
| 744 | + $white_uid = $uid; | |
| 745 | + $black_uid = $row['player1_uid']; | |
| 746 | + } | |
| 747 | + break; | |
| 748 | + case _CHESS_COLOROPTION_WHITE: | |
| 749 | + $white_uid = $uid; | |
| 750 | + $black_uid = $row['player1_uid']; | |
| 751 | + break; | |
| 752 | + case _CHESS_COLOROPTION_BLACK: | |
| 753 | + $white_uid = $row['player1_uid']; | |
| 754 | + $black_uid = $uid; | |
| 755 | + break; | |
| 756 | + } | |
| 757 | + break; | |
| 758 | + default: | |
| 759 | + case _CHESS_COLOROPTION_RANDOM: | |
| 760 | +			if (1 == random_int(1, 2)) { | |
| 761 | + $white_uid = $row['player1_uid']; | |
| 762 | + | |
| 763 | + $black_uid = $uid; | |
| 764 | +			} else { | |
| 765 | + $white_uid = $uid; | |
| 766 | + | |
| 767 | + $black_uid = $row['player1_uid']; | |
| 768 | + } | |
| 769 | + break; | |
| 770 | + case _CHESS_COLOROPTION_WHITE: | |
| 771 | + $white_uid = $row['player1_uid']; | |
| 772 | + $black_uid = $uid; | |
| 773 | + break; | |
| 774 | + case _CHESS_COLOROPTION_BLACK: | |
| 775 | + $white_uid = $uid; | |
| 776 | + $black_uid = $row['player1_uid']; | |
| 777 | + break; | |
| 778 | + } | |
| 779 | + | |
| 780 | + $game_id = chess_create_game($white_uid, $black_uid, $row['fen'], $row['is_rated'], $row['notify_move_player1'] ? $row['player1_uid'] : 0, $notify_move_player2); | |
| 781 | + | |
| 782 | +	$xoopsDB->query("DELETE FROM $challenges_table WHERE challenge_id = '$challenge_id'"); | |
| 783 | + | |
| 784 | +	if ($xoopsDB->errno()) { | |
| 785 | + trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 786 | + } | |
| 787 | + | |
| 788 | + // Notify player 1 that his challenge has been accepted (if he has subscribed to the notification). | |
| 789 | + | |
| 790 | +	$player2_username = $xoopsUser ? $xoopsUser->getVar('uname') : '*unknown*'; | |
| 791 | + | |
| 792 | +	$notificationHandler = xoops_getHandler('notification'); | |
| 793 | + | |
| 794 | + $extra_tags = ['CHESS_PLAYER' => $player2_username, 'CHESS_GAME_ID' => $game_id]; | |
| 795 | + | |
| 796 | +	$notificationHandler->triggerEvent('global', 0, 'notify_accept_challenge', $extra_tags, [$row['player1_uid']]); | |
| 797 | + | |
| 798 | + redirect_header(XOOPS_URL . "/modules/chess/game.php?game_id=$game_id", _CHESS_REDIRECT_DELAY_SUCCESS, _MD_CHESS_GAME_CREATED); | |
| 799 | 799 | } | 
| 800 | 800 | |
| 801 | 801 | /** | 
| @@ -806,23 +806,23 @@ discard block | ||
| 806 | 806 | */ | 
| 807 | 807 | function chess_is_challenger($challenge_id) | 
| 808 | 808 |  { | 
| 809 | - global $xoopsDB, $xoopsUser; | |
| 809 | + global $xoopsDB, $xoopsUser; | |
| 810 | 810 | |
| 811 | -    $challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 811 | +	$challenges_table = $xoopsDB->prefix('chess_challenges'); | |
| 812 | 812 | |
| 813 | -    $result = $xoopsDB->query("SELECT player1_uid FROM $challenges_table WHERE challenge_id = '$challenge_id'"); | |
| 813 | +	$result = $xoopsDB->query("SELECT player1_uid FROM $challenges_table WHERE challenge_id = '$challenge_id'"); | |
| 814 | 814 | |
| 815 | -    if ($xoopsDB->getRowsNum($result) < 1) { | |
| 816 | - redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 817 | - } | |
| 815 | +	if ($xoopsDB->getRowsNum($result) < 1) { | |
| 816 | + redirect_header(XOOPS_URL . '/modules/chess/', _CHESS_REDIRECT_DELAY_FAILURE, _MD_CHESS_GAME_NOT_FOUND); | |
| 817 | + } | |
| 818 | 818 | |
| 819 | - $row = $xoopsDB->fetchArray($result); | |
| 819 | + $row = $xoopsDB->fetchArray($result); | |
| 820 | 820 | |
| 821 | - $xoopsDB->freeRecordSet($result); | |
| 821 | + $xoopsDB->freeRecordSet($result); | |
| 822 | 822 | |
| 823 | -    $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; | |
| 823 | +	$uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; | |
| 824 | 824 | |
| 825 | - return $uid == $row['player1_uid']; | |
| 825 | + return $uid == $row['player1_uid']; | |
| 826 | 826 | } | 
| 827 | 827 | |
| 828 | 828 | /** | 
| @@ -838,27 +838,27 @@ discard block | ||
| 838 | 838 | */ | 
| 839 | 839 | function chess_create_challenge($gametype, $fen, $coloroption, $rated, $notify_accept, $notify_move_player1, $opponent_uid = 0) | 
| 840 | 840 |  { | 
| 841 | - #$where = __CLASS__ . '::' . __FUNCTION__;#*#DEBUG# | |
| 841 | + #$where = __CLASS__ . '::' . __FUNCTION__;#*#DEBUG# | |
| 842 | 842 | |
| 843 | - #echo "In $where\n";#*#DEBUG# | |
| 843 | + #echo "In $where\n";#*#DEBUG# | |
| 844 | 844 | |
| 845 | - global $xoopsUser; | |
| 845 | + global $xoopsUser; | |
| 846 | 846 | |
| 847 | -    $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; | |
| 847 | +	$uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; | |
| 848 | 848 | |
| 849 | - $myts = MyTextSanitizer::getInstance(); | |
| 849 | + $myts = MyTextSanitizer::getInstance(); | |
| 850 | 850 | |
| 851 | - $fen_q = $myts->addSlashes($fen); | |
| 851 | + $fen_q = $myts->addSlashes($fen); | |
| 852 | 852 | |
| 853 | -    #trigger_error("inserting new game'", E_USER_NOTICE);#*#DEBUG# | |
| 853 | +	#trigger_error("inserting new game'", E_USER_NOTICE);#*#DEBUG# | |
| 854 | 854 | |
| 855 | - global $xoopsDB; | |
| 855 | + global $xoopsDB; | |
| 856 | 856 | |
| 857 | -    $table = $xoopsDB->prefix('chess_challenges'); | |
| 857 | +	$table = $xoopsDB->prefix('chess_challenges'); | |
| 858 | 858 | |
| 859 | - $xoopsDB->query( | |
| 860 | - trim( | |
| 861 | - " | |
| 859 | + $xoopsDB->query( | |
| 860 | + trim( | |
| 861 | + " | |
| 862 | 862 | INSERT INTO $table | 
| 863 | 863 | SET | 
| 864 | 864 | game_type = '$gametype', | 
| @@ -870,36 +870,36 @@ discard block | ||
| 870 | 870 | create_date = NOW(), | 
| 871 | 871 | is_rated = '$rated' | 
| 872 | 872 | " | 
| 873 | - ) | |
| 874 | - ); | |
| 873 | + ) | |
| 874 | + ); | |
| 875 | 875 | |
| 876 | -    if ($xoopsDB->errno()) { | |
| 877 | - trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 878 | - } | |
| 876 | +	if ($xoopsDB->errno()) { | |
| 877 | + trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 878 | + } | |
| 879 | 879 | |
| 880 | - $challenge_id = $xoopsDB->getInsertId(); | |
| 880 | + $challenge_id = $xoopsDB->getInsertId(); | |
| 881 | 881 | |
| 882 | -    $notificationHandler = xoops_getHandler('notification'); | |
| 882 | +	$notificationHandler = xoops_getHandler('notification'); | |
| 883 | 883 | |
| 884 | - // Update the challenger's subscription for receiving a notification when the challenge is accepted. | |
| 884 | + // Update the challenger's subscription for receiving a notification when the challenge is accepted. | |
| 885 | 885 | |
| 886 | -    if ($notify_accept) { | |
| 887 | -        $notificationHandler->subscribe('global', 0, 'notify_accept_challenge'); | |
| 888 | -    } else { | |
| 889 | -        $notificationHandler->unsubscribe('global', 0, 'notify_accept_challenge'); | |
| 890 | - } | |
| 886 | +	if ($notify_accept) { | |
| 887 | +		$notificationHandler->subscribe('global', 0, 'notify_accept_challenge'); | |
| 888 | +	} else { | |
| 889 | +		$notificationHandler->unsubscribe('global', 0, 'notify_accept_challenge'); | |
| 890 | + } | |
| 891 | 891 | |
| 892 | - // Notify any subscribers that a challenge has been offered. | |
| 892 | + // Notify any subscribers that a challenge has been offered. | |
| 893 | 893 | |
| 894 | -    $player1_username = $xoopsUser ? $xoopsUser->getVar('uname') : '*unknown*'; | |
| 894 | +	$player1_username = $xoopsUser ? $xoopsUser->getVar('uname') : '*unknown*'; | |
| 895 | 895 | |
| 896 | - $extra_tags = ['CHESS_CHALLENGER' => $player1_username, 'CHESS_CHALLENGE_ID' => $challenge_id]; | |
| 896 | + $extra_tags = ['CHESS_CHALLENGER' => $player1_username, 'CHESS_CHALLENGE_ID' => $challenge_id]; | |
| 897 | 897 | |
| 898 | -    if (_CHESS_GAMETYPE_OPEN == $gametype) { | |
| 899 | -        $notificationHandler->triggerEvent('global', 0, 'notify_challenge_open', $extra_tags); | |
| 900 | -    } elseif (_CHESS_GAMETYPE_USER == $gametype) { | |
| 901 | -        $notificationHandler->triggerEvent('global', 0, 'notify_challenge_user', $extra_tags, [$opponent_uid]); | |
| 902 | - } | |
| 898 | +	if (_CHESS_GAMETYPE_OPEN == $gametype) { | |
| 899 | +		$notificationHandler->triggerEvent('global', 0, 'notify_challenge_open', $extra_tags); | |
| 900 | +	} elseif (_CHESS_GAMETYPE_USER == $gametype) { | |
| 901 | +		$notificationHandler->triggerEvent('global', 0, 'notify_challenge_user', $extra_tags, [$opponent_uid]); | |
| 902 | + } | |
| 903 | 903 | } | 
| 904 | 904 | |
| 905 | 905 | /** | 
| @@ -909,15 +909,15 @@ discard block | ||
| 909 | 909 | */ | 
| 910 | 910 | function chess_delete_challenge($challenge_id) | 
| 911 | 911 |  { | 
| 912 | - global $xoopsDB; | |
| 912 | + global $xoopsDB; | |
| 913 | 913 | |
| 914 | -    $table = $xoopsDB->prefix('chess_challenges'); | |
| 914 | +	$table = $xoopsDB->prefix('chess_challenges'); | |
| 915 | 915 | |
| 916 | -    $xoopsDB->query("DELETE FROM $table WHERE challenge_id='$challenge_id'"); | |
| 916 | +	$xoopsDB->query("DELETE FROM $table WHERE challenge_id='$challenge_id'"); | |
| 917 | 917 | |
| 918 | -    if ($xoopsDB->errno()) { | |
| 919 | - trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 920 | - } | |
| 918 | +	if ($xoopsDB->errno()) { | |
| 919 | + trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 920 | + } | |
| 921 | 921 | } | 
| 922 | 922 | |
| 923 | 923 | /** | 
| @@ -933,33 +933,33 @@ discard block | ||
| 933 | 933 | */ | 
| 934 | 934 | function chess_create_game($white_uid, $black_uid, $fen, $rated, $notify_move_player1_uid = 0, $notify_move_player2 = false) | 
| 935 | 935 |  { | 
| 936 | - #$where = __CLASS__ . '::' . __FUNCTION__;#*#DEBUG# | |
| 936 | + #$where = __CLASS__ . '::' . __FUNCTION__;#*#DEBUG# | |
| 937 | 937 | |
| 938 | - #echo "In $where\n";#*#DEBUG# | |
| 938 | + #echo "In $where\n";#*#DEBUG# | |
| 939 | 939 | |
| 940 | -    #var_dump('white_uid', $white_uid, 'black_uid', $black_uid);#*#DEBUG# | |
| 940 | +	#var_dump('white_uid', $white_uid, 'black_uid', $black_uid);#*#DEBUG# | |
| 941 | 941 | |
| 942 | - $chessgame = new Chess\ChessGame($fen); | |
| 942 | + $chessgame = new Chess\ChessGame($fen); | |
| 943 | 943 | |
| 944 | -    empty($chessgame->error) or trigger_error('chessgame invalid', E_USER_ERROR); | |
| 944 | +	empty($chessgame->error) or trigger_error('chessgame invalid', E_USER_ERROR); | |
| 945 | 945 | |
| 946 | - $gamestate = $chessgame->gamestate(); | |
| 946 | + $gamestate = $chessgame->gamestate(); | |
| 947 | 947 | |
| 948 | -    is_array($gamestate) or trigger_error('gamestate invalid', E_USER_ERROR); | |
| 948 | +	is_array($gamestate) or trigger_error('gamestate invalid', E_USER_ERROR); | |
| 949 | 949 | |
| 950 | -    #trigger_error("inserting new game'", E_USER_NOTICE);#*#DEBUG# | |
| 950 | +	#trigger_error("inserting new game'", E_USER_NOTICE);#*#DEBUG# | |
| 951 | 951 | |
| 952 | - $myts = MyTextSanitizer::getInstance(); | |
| 952 | + $myts = MyTextSanitizer::getInstance(); | |
| 953 | 953 | |
| 954 | - $fen_q = $myts->addSlashes($fen); | |
| 954 | + $fen_q = $myts->addSlashes($fen); | |
| 955 | 955 | |
| 956 | - global $xoopsDB; | |
| 956 | + global $xoopsDB; | |
| 957 | 957 | |
| 958 | -    $table = $xoopsDB->prefix('chess_games'); | |
| 958 | +	$table = $xoopsDB->prefix('chess_games'); | |
| 959 | 959 | |
| 960 | - $xoopsDB->query( | |
| 961 | - trim( | |
| 962 | - " | |
| 960 | + $xoopsDB->query( | |
| 961 | + trim( | |
| 962 | + " | |
| 963 | 963 | INSERT INTO $table | 
| 964 | 964 | SET | 
| 965 | 965 | white_uid = '$white_uid', | 
| @@ -978,30 +978,30 @@ discard block | ||
| 978 | 978 |              pgn_movetext                 = '{$gamestate['pgn_movetext']}', | 
| 979 | 979 | is_rated = '$rated' | 
| 980 | 980 | " | 
| 981 | - ) | |
| 982 | - ); | |
| 981 | + ) | |
| 982 | + ); | |
| 983 | 983 | |
| 984 | -    if ($xoopsDB->errno()) { | |
| 985 | - trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 986 | - } | |
| 984 | +	if ($xoopsDB->errno()) { | |
| 985 | + trigger_error($xoopsDB->errno() . ':' . $xoopsDB->error(), E_USER_ERROR); | |
| 986 | + } | |
| 987 | 987 | |
| 988 | - $game_id = $xoopsDB->getInsertId(); | |
| 988 | + $game_id = $xoopsDB->getInsertId(); | |
| 989 | 989 | |
| 990 | -    $notificationHandler = xoops_getHandler('notification'); | |
| 990 | +	$notificationHandler = xoops_getHandler('notification'); | |
| 991 | 991 | |
| 992 | - // If requested, subscribe the challenger to receive a notification when a new move is made. | |
| 992 | + // If requested, subscribe the challenger to receive a notification when a new move is made. | |
| 993 | 993 | |
| 994 | -    if ($notify_move_player1_uid) { | |
| 995 | -        $notificationHandler->subscribe('game', $game_id, 'notify_game_move', null, null, $notify_move_player1_uid); | |
| 996 | - } | |
| 994 | +	if ($notify_move_player1_uid) { | |
| 995 | +		$notificationHandler->subscribe('game', $game_id, 'notify_game_move', null, null, $notify_move_player1_uid); | |
| 996 | + } | |
| 997 | 997 | |
| 998 | - // If requested, subscribe the accepter to receive a notification when a new move is made. | |
| 998 | + // If requested, subscribe the accepter to receive a notification when a new move is made. | |
| 999 | 999 | |
| 1000 | -    if ($notify_move_player2) { | |
| 1001 | -        $notificationHandler->subscribe('game', $game_id, 'notify_game_move'); | |
| 1002 | - } | |
| 1000 | +	if ($notify_move_player2) { | |
| 1001 | +		$notificationHandler->subscribe('game', $game_id, 'notify_game_move'); | |
| 1002 | + } | |
| 1003 | 1003 | |
| 1004 | - return $game_id; | |
| 1004 | + return $game_id; | |
| 1005 | 1005 | } | 
| 1006 | 1006 | |
| 1007 | 1007 | /** | 
| @@ -1012,15 +1012,15 @@ discard block | ||
| 1012 | 1012 | */ | 
| 1013 | 1013 | function chess_fen_error($fen) | 
| 1014 | 1014 |  { | 
| 1015 | -    if (!empty($fen)) { | |
| 1016 | - $chessgame = new Chess\ChessGame($fen); | |
| 1015 | +	if (!empty($fen)) { | |
| 1016 | + $chessgame = new Chess\ChessGame($fen); | |
| 1017 | 1017 | |
| 1018 | - $fen_error = $chessgame->error; | |
| 1019 | -    } else { | |
| 1020 | - $fen_error = ''; | |
| 1021 | - } | |
| 1018 | + $fen_error = $chessgame->error; | |
| 1019 | +	} else { | |
| 1020 | + $fen_error = ''; | |
| 1021 | + } | |
| 1022 | 1022 | |
| 1023 | - return $fen_error; | |
| 1023 | + return $fen_error; | |
| 1024 | 1024 | } | 
| 1025 | 1025 | |
| 1026 | 1026 | /** | 
| @@ -1033,9 +1033,9 @@ discard block | ||
| 1033 | 1033 | */ | 
| 1034 | 1034 | function chess_opponent_uid($username) | 
| 1035 | 1035 |  { | 
| 1036 | - $uid = chess_uname_to_uid($username); | |
| 1036 | + $uid = chess_uname_to_uid($username); | |
| 1037 | 1037 | |
| 1038 | - $can_play = $uid > 0 ? chess_can_play($uid) : false; | |
| 1038 | + $can_play = $uid > 0 ? chess_can_play($uid) : false; | |
| 1039 | 1039 | |
| 1040 | - return $can_play ? $uid : 0; | |
| 1040 | + return $can_play ? $uid : 0; | |
| 1041 | 1041 | } | 
| @@ -40,9 +40,9 @@ discard block | ||
| 40 | 40 | // but not when viewing the notifications page via notifications.php. | 
| 41 | 41 | global $xoopsConfig; | 
| 42 | 42 |  if (file_exists(XOOPS_ROOT_PATH . "/modules/chess/language/{$xoopsConfig['language']}/main.php")) { | 
| 43 | -    require_once XOOPS_ROOT_PATH . "/modules/chess/language/{$xoopsConfig['language']}/main.php"; | |
| 43 | +	require_once XOOPS_ROOT_PATH . "/modules/chess/language/{$xoopsConfig['language']}/main.php"; | |
| 44 | 44 |  } else { | 
| 45 | - require_once XOOPS_ROOT_PATH . '/modules/chess/language/english/main.php'; | |
| 45 | + require_once XOOPS_ROOT_PATH . '/modules/chess/language/english/main.php'; | |
| 46 | 46 | } | 
| 47 | 47 | /**#@-*/ | 
| 48 | 48 | |
| @@ -57,57 +57,57 @@ discard block | ||
| 57 | 57 | */ | 
| 58 | 58 | function chess_notify_item_info($category, $item_id) | 
| 59 | 59 |  { | 
| 60 | -    if ('global' == $category) { | |
| 61 | - $item['name'] = 'Chess'; | |
| 60 | +	if ('global' == $category) { | |
| 61 | + $item['name'] = 'Chess'; | |
| 62 | 62 | |
| 63 | - $item['url'] = XOOPS_URL . '/modules/chess/'; | |
| 63 | + $item['url'] = XOOPS_URL . '/modules/chess/'; | |
| 64 | 64 | |
| 65 | - return $item; | |
| 66 | -    } elseif ('game' == $category) { | |
| 67 | - global $xoopsDB; | |
| 65 | + return $item; | |
| 66 | +	} elseif ('game' == $category) { | |
| 67 | + global $xoopsDB; | |
| 68 | 68 | |
| 69 | -        $table = $xoopsDB->prefix('chess_games'); | |
| 69 | +		$table = $xoopsDB->prefix('chess_games'); | |
| 70 | 70 | |
| 71 | - $result = $xoopsDB->query( | |
| 72 | - trim( | |
| 73 | - " | |
| 71 | + $result = $xoopsDB->query( | |
| 72 | + trim( | |
| 73 | + " | |
| 74 | 74 | SELECT white_uid, black_uid, UNIX_TIMESTAMP(start_date) AS start_date | 
| 75 | 75 | FROM $table | 
| 76 | 76 | WHERE game_id = '$item_id' | 
| 77 | 77 | " | 
| 78 | - ) | |
| 79 | - ); | |
| 78 | + ) | |
| 79 | + ); | |
| 80 | 80 | |
| 81 | - $gamedata = $xoopsDB->fetchArray($result); | |
| 81 | + $gamedata = $xoopsDB->fetchArray($result); | |
| 82 | 82 | |
| 83 | - $xoopsDB->freeRecordSet($result); | |
| 83 | + $xoopsDB->freeRecordSet($result); | |
| 84 | 84 | |
| 85 | -        if (false !== $gamedata) { | |
| 86 | - // get mapping of user IDs to usernames | |
| 85 | +		if (false !== $gamedata) { | |
| 86 | + // get mapping of user IDs to usernames | |
| 87 | 87 | |
| 88 | -            $criteria = new \Criteria('uid', "({$gamedata['white_uid']}, {$gamedata['black_uid']})", 'IN'); | |
| 88 | +			$criteria = new \Criteria('uid', "({$gamedata['white_uid']}, {$gamedata['black_uid']})", 'IN'); | |
| 89 | 89 | |
| 90 | -            $memberHandler = xoops_getHandler('member'); | |
| 90 | +			$memberHandler = xoops_getHandler('member'); | |
| 91 | 91 | |
| 92 | - $usernames = $memberHandler->getUserList($criteria); | |
| 92 | + $usernames = $memberHandler->getUserList($criteria); | |
| 93 | 93 | |
| 94 | - $username_white = $usernames[$gamedata['white_uid']] ?? _MD_CHESS_NA; | |
| 94 | + $username_white = $usernames[$gamedata['white_uid']] ?? _MD_CHESS_NA; | |
| 95 | 95 | |
| 96 | - $username_black = $usernames[$gamedata['black_uid']] ?? _MD_CHESS_NA; | |
| 96 | + $username_black = $usernames[$gamedata['black_uid']] ?? _MD_CHESS_NA; | |
| 97 | 97 | |
| 98 | -            $date = $gamedata['start_date'] ? date('Y.m.d', $gamedata['start_date']) : _MD_CHESS_NA; | |
| 99 | -        } else { | |
| 100 | - $username_white = _MD_CHESS_NA; | |
| 98 | +			$date = $gamedata['start_date'] ? date('Y.m.d', $gamedata['start_date']) : _MD_CHESS_NA; | |
| 99 | +		} else { | |
| 100 | + $username_white = _MD_CHESS_NA; | |
| 101 | 101 | |
| 102 | - $username_black = _MD_CHESS_NA; | |
| 102 | + $username_black = _MD_CHESS_NA; | |
| 103 | 103 | |
| 104 | - $date = _MD_CHESS_NA; | |
| 105 | - } | |
| 104 | + $date = _MD_CHESS_NA; | |
| 105 | + } | |
| 106 | 106 | |
| 107 | - $item['name'] = "$username_white " . _MD_CHESS_LABEL_VS . " $username_black ($date)"; | |
| 107 | + $item['name'] = "$username_white " . _MD_CHESS_LABEL_VS . " $username_black ($date)"; | |
| 108 | 108 | |
| 109 | - $item['url'] = XOOPS_URL . '/modules/chess/game.php?game_id=' . $item_id; | |
| 109 | + $item['url'] = XOOPS_URL . '/modules/chess/game.php?game_id=' . $item_id; | |
| 110 | 110 | |
| 111 | - return $item; | |
| 112 | - } | |
| 111 | + return $item; | |
| 112 | + } | |
| 113 | 113 | } | 
| @@ -44,72 +44,72 @@ discard block | ||
| 44 | 44 | */ | 
| 45 | 45 | function chess_ratings_adj_cxr($white_rating, $white_games, $black_rating, $black_games, $pgn_result) | 
| 46 | 46 |  { | 
| 47 | - // compute score: +1 for win, 0 for draw, -1 for loss | |
| 48 | -    switch ($pgn_result) { | |
| 49 | - case '1-0': | |
| 50 | - $S = 1; | |
| 51 | - break; | |
| 52 | - case '1/2-1/2': | |
| 53 | - default: // should not occur | |
| 54 | - $S = 0; | |
| 55 | - break; | |
| 56 | - case '0-1': | |
| 57 | - $S = -1; | |
| 58 | - break; | |
| 59 | - } | |
| 47 | + // compute score: +1 for win, 0 for draw, -1 for loss | |
| 48 | +	switch ($pgn_result) { | |
| 49 | + case '1-0': | |
| 50 | + $S = 1; | |
| 51 | + break; | |
| 52 | + case '1/2-1/2': | |
| 53 | + default: // should not occur | |
| 54 | + $S = 0; | |
| 55 | + break; | |
| 56 | + case '0-1': | |
| 57 | + $S = -1; | |
| 58 | + break; | |
| 59 | + } | |
| 60 | 60 | |
| 61 | -    if (($white_games < 5 && $black_games < 5) || ($white_games > 5 && $black_games > 5)) { | |
| 62 | - // Formula 1: Rnew = Rold + (S x 21) + (Ropponent - Rold) / 25 | |
| 63 | - $w_new = ($S * 21) + ($black_rating - $white_rating) / 25; | |
| 64 | - $b_new = (-$S * 21) + ($white_rating - $black_rating) / 25; | |
| 65 | -    } elseif ($white_games > 5 && $black_games < 5) { | |
| 66 | - // Formula 2: Rnew = Rold + (S x 6) + (Ropponent - Rold) / 100 | |
| 67 | - $w_new = ($S * 6) + ($black_rating - $white_rating) / 100; | |
| 61 | +	if (($white_games < 5 && $black_games < 5) || ($white_games > 5 && $black_games > 5)) { | |
| 62 | + // Formula 1: Rnew = Rold + (S x 21) + (Ropponent - Rold) / 25 | |
| 63 | + $w_new = ($S * 21) + ($black_rating - $white_rating) / 25; | |
| 64 | + $b_new = (-$S * 21) + ($white_rating - $black_rating) / 25; | |
| 65 | +	} elseif ($white_games > 5 && $black_games < 5) { | |
| 66 | + // Formula 2: Rnew = Rold + (S x 6) + (Ropponent - Rold) / 100 | |
| 67 | + $w_new = ($S * 6) + ($black_rating - $white_rating) / 100; | |
| 68 | 68 | |
| 69 | - // Formula 3: Rnew = (4/5) x Rold + (1/5) x Ropponent + (S x 80) | |
| 70 | - $b_new = ($white_rating / 5) + ($S * -80) - ($black_rating / 5); | |
| 71 | -    } else { | |
| 72 | - // Formula 2: Rnew = Rold + (S x 6) + (Ropponent - Rold) / 100 | |
| 73 | - $b_new = ($S * 6) + ($white_rating - $black_rating) / 100; | |
| 69 | + // Formula 3: Rnew = (4/5) x Rold + (1/5) x Ropponent + (S x 80) | |
| 70 | + $b_new = ($white_rating / 5) + ($S * -80) - ($black_rating / 5); | |
| 71 | +	} else { | |
| 72 | + // Formula 2: Rnew = Rold + (S x 6) + (Ropponent - Rold) / 100 | |
| 73 | + $b_new = ($S * 6) + ($white_rating - $black_rating) / 100; | |
| 74 | 74 | |
| 75 | - // Formula 3: Rnew = (4/5) x Rold + (1/5) x Ropponent + (S x 80) | |
| 76 | - $w_new = ($black_rating / 5) + ($S * -80) - ($white_rating / 5); | |
| 77 | - } | |
| 75 | + // Formula 3: Rnew = (4/5) x Rold + (1/5) x Ropponent + (S x 80) | |
| 76 | + $w_new = ($black_rating / 5) + ($S * -80) - ($white_rating / 5); | |
| 77 | + } | |
| 78 | 78 | |
| 79 | - // Rule R1: The winning rated player must gain at least two points. | |
| 80 | - // Rule R2: The losing rated player must lose at least two points. | |
| 81 | -    if (abs($w_new) < 2) { | |
| 82 | - $w_new = $S * 2; | |
| 83 | - } | |
| 84 | -    if (abs($b_new) < 2) { | |
| 85 | - $b_new = $S * -2; | |
| 86 | - } | |
| 79 | + // Rule R1: The winning rated player must gain at least two points. | |
| 80 | + // Rule R2: The losing rated player must lose at least two points. | |
| 81 | +	if (abs($w_new) < 2) { | |
| 82 | + $w_new = $S * 2; | |
| 83 | + } | |
| 84 | +	if (abs($b_new) < 2) { | |
| 85 | + $b_new = $S * -2; | |
| 86 | + } | |
| 87 | 87 | |
| 88 | - // Rule R3: The rated player must not gain nor lose more than 41 points. | |
| 89 | -    if (abs($w_new) > 41) { | |
| 90 | - $w_new = $S * 41; | |
| 91 | - } | |
| 92 | -    if (abs($b_new) > 41) { | |
| 93 | - $b_new = $S * -41; | |
| 94 | - } | |
| 88 | + // Rule R3: The rated player must not gain nor lose more than 41 points. | |
| 89 | +	if (abs($w_new) > 41) { | |
| 90 | + $w_new = $S * 41; | |
| 91 | + } | |
| 92 | +	if (abs($b_new) > 41) { | |
| 93 | + $b_new = $S * -41; | |
| 94 | + } | |
| 95 | 95 | |
| 96 | -    if (1 == $S) { | |
| 97 | -        if ($white_games < 5 && $w_new < 0) { | |
| 98 | - $w_new = 2; | |
| 99 | - } | |
| 100 | -        if ($black_games < 5 && $b_new > 0) { | |
| 101 | - $b_new = -2; | |
| 102 | - } | |
| 103 | -    } elseif (-1 == $S) { | |
| 104 | -        if ($white_games < 5 && $w_new > 0) { | |
| 105 | - $w_new = -2; | |
| 106 | - } | |
| 107 | -        if ($black_games < 5 && $b_new < 0) { | |
| 108 | - $b_new = 2; | |
| 109 | - } | |
| 110 | - } | |
| 96 | +	if (1 == $S) { | |
| 97 | +		if ($white_games < 5 && $w_new < 0) { | |
| 98 | + $w_new = 2; | |
| 99 | + } | |
| 100 | +		if ($black_games < 5 && $b_new > 0) { | |
| 101 | + $b_new = -2; | |
| 102 | + } | |
| 103 | +	} elseif (-1 == $S) { | |
| 104 | +		if ($white_games < 5 && $w_new > 0) { | |
| 105 | + $w_new = -2; | |
| 106 | + } | |
| 107 | +		if ($black_games < 5 && $b_new < 0) { | |
| 108 | + $b_new = 2; | |
| 109 | + } | |
| 110 | + } | |
| 111 | 111 | |
| 112 | - return [$white_rating + $w_new, $black_rating + $b_new]; | |
| 112 | + return [$white_rating + $w_new, $black_rating + $b_new]; | |
| 113 | 113 | } | 
| 114 | 114 | |
| 115 | 115 | /** | 
| @@ -119,7 +119,7 @@ discard block | ||
| 119 | 119 | */ | 
| 120 | 120 | function chess_ratings_num_provisional_games_cxr() | 
| 121 | 121 |  { | 
| 122 | - return 5; | |
| 122 | + return 5; | |
| 123 | 123 | } | 
| 124 | 124 | |
| 125 | 125 | ?> |