private function _GetSlotHours(&$bdata)
 {
     if ($bdata['placegap']) {
         switch ($bdata['placegaptype']) {
             case 1:
                 //minute
                 return MIN($bdata['placegap'] / 60, 24.0);
             case 2:
                 //hour
                 return MIN((double) $bdata['placegap'], 24.0);
             case 3:
                 //>= day
             //>= day
             case 4:
             case 5:
             case 6:
                 return 24.0;
             default:
                 break;
         }
     }
     //TODO if $bdata['startdate'] to $bdata['enddate'] short/< N days
     // assume nominated values are hours, return appropriate value
     return 0.0;
 }
Example #2
0
 function page($total = 0, $everpage = 10, $query = array())
 {
     $this->total = $this->totalItems = $total;
     $this->everpage = $everpage;
     $this->pages = max(1, abs(ceil($total / $everpage)));
     $this->currentPage = max((int) $_GET['pageID'], 1);
     //2
     $num = ceil(3 / 2);
     $this->max = MIN(MAX($this->currentPage + $num, 3), $this->pages);
     $this->min = MAX(MIN($this->currentPage - $num, $this->pages - 3), 1);
     $this->limit_1 = ($this->currentPage - 1) * $this->everpage;
     $this->limit_2 = $this->everpage;
     $this->limit_3 = $this->currentPage * $this->everpage;
     $this->num_1 = '';
     $this->num_3 = ' LIMIT ' . $this->limit_1 . ',' . $this->limit_2;
 }
Example #3
0
 public static function employee($D, $params)
 {
     $D['24'] = $params->def('field_53', 1);
     $D['25'] = $params->def('field_54', 1);
     $D['26'] = $params->def('field_55', 1);
     $D['27'] = $params->def('field_56', 1);
     $year = $params->def('field_67', 1);
     $D['28'] = (int) (25569 + strtotime("{$year} 12:00:00") / 86400);
     $D['29'] = $params->def('field_70', 1);
     $D['30'] = $params->def('field_71', 1);
     /*
      * Set Parameters
      */
     $D['5'] = $D['28'];
     $resignation = $D['6'];
     $intoservice = $D['7'];
     $D['6_'] = $resignation;
     $D['7_'] = $intoservice;
     $D['6'] = (int) (25569 + strtotime("{$resignation} 12:00:00") / 86400);
     $D['7'] = (int) (25569 + strtotime("{$intoservice} 12:00:00") / 86400);
     $D['8'] = ($D['6'] - $D['7']) / 365;
     /*
      * Brutto loon
      */
     $D['19'] = $D['24'] * $D['12'] + $D['13'] + $D['14'] * $D['25'] + $D['15'] * $D['25'] * $D['26'] + $D['26'] * ($D['16'] + $D['17']) + $D['27'] * $D['18'];
     $D['21'] = $D['19'] + $D['20'];
     if ($D['9'] != "0") {
         $D['22'] = $D['17'] * $D['26'] + ($D['12'] * $D['24'] + $D['13'] + $D['20'] + $D['14'] * $D['25'] + $D['15'] * 12 * $D['25'] + $D['16'] * $D['26'] + $D['18'] * $D['27']) * $D['10'] / $D['9'];
     } else {
         $D['22'] = "0";
     }
     if ($D['22'] < $D['29']) {
         $D['23'] = MIN(1.5 * ceil($D['8'] / 5), 3);
     } else {
         if ($D['22'] < $D['30']) {
             $D['23'] = 'EMPLOYEE_MAX4';
         } else {
             $D['23'] = 'EMPLOYEE_MAX6';
         }
     }
     return $D;
 }
Example #4
0
		showsetting('qqgroup_usergroup_feed_list', '', '', '<select name="groupid[]" multiple="multiple" size="10">'.$groupselect.'</select>');
		showsubmit('settingsubmit');
		showtablefooter();
		showformfooter();

	}
} elseif($_GET['anchor'] == 'block') {

	$perpage = 10;
	$maxPage = 10;
	$page = intval($_GET['page']);
	$page = MAX($page, 1);
	$page = MIN($page, $maxPage);

	$prevPage = MAX($page - 1, 1);
	$nextPage = MIN($page + 1, $maxPage);

	if(submitcheck('setMiniportalThreadsSubmit')) {

		$topic = $_GET['topic'];
		$topic = processMiniportalTopicThread($topic);
		if(!$topic) {
			cpmsg('qqgroup_msg_deficiency', '', 'error');
		}

		$normal = $_GET['normal'];
		$normal = processMiniportalNormalThreads($normal);
		if(!$normal) {
			cpmsg('qqgroup_msg_deficiency', '', 'error');
		}
 public function getCategoryImages($product_id, $module_setting)
 {
     if (!$this->installed()) {
         return false;
     }
     $this->load->model('tool/image');
     // OC 1.X old-style
     if ($module_setting && is_array($module_setting) && isset($module_setting['image_width']) && isset($module_setting['image_height'])) {
         $image_product_width = $module_setting['image_width'];
         $image_product_height = $module_setting['image_height'];
         // OC 2.0 new-style
     } elseif ($module_setting && is_array($module_setting) && isset($module_setting['width']) && isset($module_setting['height'])) {
         $image_product_width = $module_setting['width'];
         $image_product_height = $module_setting['height'];
     } elseif ($module_setting == "related_products") {
         $image_product_width = $this->config->get('config_image_related_width');
         $image_product_height = $this->config->get('config_image_related_height');
     } else {
         $image_product_width = $this->config->get('config_image_product_width');
         $image_product_height = $this->config->get('config_image_product_height');
     }
     if ($this->config->get('config_template') == "eagency") {
         $image_product_width = MIN($image_product_width, 200);
         $image_product_height = MIN($image_product_height, 200);
     }
     // ориентир размер изображения 120 (с отступами будет 128), размер иконки 24 (с отступами будет 32)
     // (120)/4-6=24
     $icon_width = round($image_product_width / 4 - 6);
     $icon_height = round($image_product_height / 4 - 6);
     // pav fashion theme compatibility
     if ($this->config->get('config_template') == "pav_fashion" && (!$module_setting || $module_setting == "related_products")) {
         $icon_width = 43;
         $icon_height = 43;
     }
     $images = $this->getProductOptionImages($product_id);
     $settings = $this->getProductSettings($product_id);
     $category_images = array();
     foreach ($images as $product_option_id => $image_po) {
         if (isset($settings[$product_option_id]) && $settings[$product_option_id]['img_category']) {
             foreach ($image_po as $product_option_value_id => $image_pov) {
                 if (count($image_pov) > 0) {
                     if (!isset($category_images[$product_option_id])) {
                         $category_images[$product_option_id] = array();
                     }
                     $image_pov[0];
                     $category_images[$product_option_id][$product_option_value_id] = array('icon' => $this->model_tool_image->resize($image_pov[0]['thumb'], $icon_width, $icon_height), 'thumb' => $this->model_tool_image->resize($image_pov[0]['image'], $image_product_width, $image_product_height), 'image' => $image_pov[0]['image']);
                     if (isset($image_pov[0]['option_name']) && $image_pov[0]['option_name'] && isset($image_pov[0]['value_name']) && $image_pov[0]['value_name']) {
                         $category_images[$product_option_id][$product_option_value_id]['title'] = "" . $image_pov[0]['option_name'] . ": " . $image_pov[0]['value_name'];
                     }
                 }
             }
         }
     }
     return $category_images;
 }
    function EndStayEvent()
    {
        global $pricelist, $reslist;
        $LNG = $this->getLanguage(NULL, $this->_fleet['fleet_owner']);
        $expeditionPoints = array();
        foreach ($reslist['fleet'] as $ID) {
            $expeditionPoints[$ID] = ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]) / 1000000;
        }
        $expeditionPoints[202] = 12;
        $expeditionPoints[203] = 47;
        $expeditionPoints[204] = 12;
        $expeditionPoints[205] = 110;
        $expeditionPoints[206] = 47;
        $expeditionPoints[207] = 160;
        $fleetRaw = explode(";", $this->_fleet['fleet_array']);
        $fleetPoints = 0;
        $fleetCapacity = 0;
        $find_stardust = 5;
        $fleetArray = array();
        $stardustCount = $GLOBALS['DATABASE']->query("SELECT COUNT(planetarium) as planetarium FROM " . PLANETS . " WHERE id_owner = " . $this->_fleet['fleet_end_id'] . ";");
        $stardustCount = $GLOBALS['DATABASE']->fetch_array($stardustCount);
        $find_stardust = $find_stardust + $stardustCount['planetarium'];
        foreach ($fleetRaw as $Group) {
            if (empty($Group)) {
                continue;
            }
            $Class = explode(",", $Group);
            $fleetArray[$Class[0]] = $Class[1];
            $fleetCapacity += $Class[1] * $pricelist[$Class[0]]['capacity'];
            $fleetPoints += $Class[1] * $expeditionPoints[$Class[0]];
        }
        $fleetCapacity -= $this->_fleet['fleet_resource_metal'] + $this->_fleet['fleet_resource_crystal'] + $this->_fleet['fleet_resource_deuterium'] + $this->_fleet['fleet_resource_darkmatter'];
        /*if($GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['purchase_bonus_timer'] > TIMESTAMP || $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['cosmonaute'] == 1){
        		$GetEvent       = mt_rand(1,7);
        		}else{
        		$GetEvent       = mt_rand(1,6);
        		} */
        $GetEvent = mt_rand(1, 7);
        $combat_bonus = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $this->_fleet['fleet_owner'] . ";");
        $Message = $LNG['sys_expe_nothing_' . mt_rand(1, 8)];
        $chancetogetstar = mt_rand(0, 100);
        if ($chancetogetstar < $find_stardust) {
            $find_stardust = 1;
        } else {
            $find_stardust = 0;
        }
        switch ($GetEvent) {
            case 1:
                $WitchFound = mt_rand(1, 3);
                $FindSize = mt_rand(0, 100);
                $Factor = 0;
                if (10 < $FindSize) {
                    $Factor = mt_rand(100, 500) / $WitchFound * $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['resource_multiplier'];
                    $Factor = $Factor + $Factor / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ress_1_' . mt_rand(1, 4)];
                } elseif (0 < $FindSize && 10 >= $FindSize) {
                    $Factor = mt_rand(520, 1000) / $WitchFound * $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['resource_multiplier'];
                    $Factor = $Factor + $Factor / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ress_2_' . mt_rand(1, 3)];
                } elseif (0 == $FindSize) {
                    $Factor = mt_rand(1020, 2000) / $WitchFound * $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['resource_multiplier'];
                    $Factor = $Factor + $Factor / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ress_3_' . mt_rand(1, 2)];
                }
                $StatFactor = $GLOBALS['DATABASE']->getFirstRow("SELECT MAX(total_points) as total FROM `" . STATPOINTS . "` WHERE `stat_type` = 1 AND `universe` = '" . $this->_fleet['fleet_universe'] . "';");
                $MaxPoints = $StatFactor['total'] < 5000000 ? 9000 : 12000;
                $Size = min($Factor * MAX(MIN($fleetPoints / 1000, $MaxPoints), 200), $fleetCapacity);
                switch ($WitchFound) {
                    case 1:
                        $this->UpdateFleet('fleet_resource_metal', $this->_fleet['fleet_resource_metal'] + $Size);
                        break;
                    case 2:
                        $this->UpdateFleet('fleet_resource_crystal', $this->_fleet['fleet_resource_crystal'] + $Size);
                        break;
                    case 3:
                        $this->UpdateFleet('fleet_resource_deuterium', $this->_fleet['fleet_resource_deuterium'] + $Size);
                        break;
                }
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `achievements_expedition` = `achievements_expedition` + '1', `expedition_count` = `expedition_count` + '1' where `id` = '" . $this->_fleet['fleet_owner'] . "';");
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET stardust = stardust + '" . $find_stardust . "' where `id` = " . $this->_fleet['fleet_owner'] . ";");
                $INFOR = $GLOBALS['DATABASE']->query("SELECT * FROM `uni1_users` WHERE id = " . $this->_fleet['fleet_owner'] . ";");
                if ($GLOBALS['DATABASE']->numRows($INFOR) > 0) {
                    while ($xkf = mysqli_fetch_assoc($INFOR)) {
                        $ACTUA = $xkf['expedition_count'];
                        $ACTUAL = 10 * $xkf['achievements_misc_expe'] + 10;
                        $expe_lvl = $xkf['achievements_misc_expe'] + 1;
                        $expe_reward_points = 50;
                        $expe_reward_am = 50;
                        $expe_reward_points = $expe_reward_points + $xkf['achievements_misc_expe'] * $expe_reward_points;
                        $expe_reward_am = $expe_reward_am + $xkf['achievements_misc_expe'] * $expe_reward_am;
                    }
                    if ($ACTUA == $ACTUAL) {
                        $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET achievements_misc_expe = achievements_misc_expe + '1', antimatter = antimatter + " . $expe_reward_am . " WHERE id = " . $this->_fleet['fleet_owner'] . ";");
                        $msg = '<img alt="" style="float:left; width:60px; margin-right:6px;" src="styles/images/achiev/ach_expedition.png">reached: <span class="achiev_mes_head">expeditions lvl. ' . $expe_lvl . '</span><br> received:<br> ' . $expe_reward_am . ' antimatter <br> ' . $expe_reward_points . ' achievement points';
                        SendSimpleMessage($this->_fleet['fleet_owner'], '', TIMESTAMP, 4, 'System', 'Achievements', $msg);
                    }
                }
                break;
            case 2:
                $FindSize = mt_rand(0, 100);
                $Size = 0;
                if (10 < $FindSize) {
                    $Size = mt_rand(1000, 3000);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_dm_1_' . mt_rand(1, 5)];
                } elseif (0 < $FindSize && 10 >= $FindSize) {
                    $Size = mt_rand(3001, 6000);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_dm_2_' . mt_rand(1, 3)];
                } elseif (0 == $FindSize) {
                    $Size = mt_rand(6001, 30000);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_dm_3_' . mt_rand(1, 2)];
                }
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `achievements_expedition` = `achievements_expedition` + '1', `expedition_count` = `expedition_count` + '1' where `id` = '" . $this->_fleet['fleet_owner'] . "';");
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET stardust = stardust + '" . $find_stardust . "' where `id` = " . $this->_fleet['fleet_owner'] . ";");
                $this->UpdateFleet('fleet_resource_darkmatter', $this->_fleet['fleet_resource_darkmatter'] + $Size);
                break;
            case 3:
                $FindSize = mt_rand(0, 100);
                $Size = 0;
                $Message = "";
                if (10 < $FindSize) {
                    $Size = mt_rand(100, 500);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ships_1_' . mt_rand(1, 4)];
                } elseif (0 < $FindSize && 10 >= $FindSize) {
                    $Size = mt_rand(520, 1000);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ships_2_' . mt_rand(1, 2)];
                } elseif (0 == $FindSize) {
                    $Size = mt_rand(1020, 2000);
                    $Size = $Size + $Size / 100 * $combat_bonus['combat_reward_expe'];
                    $Message = $LNG['sys_expe_found_ships_3_' . mt_rand(1, 2)];
                }
                $StatFactor = $GLOBALS['DATABASE']->getFirstCell("SELECT MAX(total_points) FROM `" . STATPOINTS . "` WHERE `stat_type` = 1 AND `universe` = '" . $this->_fleet['fleet_universe'] . "';");
                $MaxPoints = $StatFactor < 5000000 ? 4500 : 6000;
                $FoundShips = max(round($Size * min($fleetPoints, $MaxPoints)), 10000);
                $FoundShipMess = "";
                $NewFleetArray = "";
                $Found = array();
                foreach ($reslist['fleet'] as $ID) {
                    if (!isset($fleetArray[$ID]) || $ID == 208 || $ID == 209 || $ID == 214) {
                        continue;
                    }
                    $MaxFound = floor($FoundShips / ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]));
                    if ($MaxFound <= 0) {
                        continue;
                    }
                    $Count = mt_rand(0, $MaxFound);
                    if ($Count <= 0) {
                        continue;
                    }
                    $Found[$ID] = $Count;
                    $FoundShips -= $Count * ($pricelist[$ID]['cost'][901] + $pricelist[$ID]['cost'][902]);
                    $FoundShipMess .= '<br>' . $LNG['tech'][$ID] . ': ' . pretty_number($Count);
                    if ($FoundShips <= 0) {
                        break;
                    }
                }
                if (empty($Found)) {
                    $FoundShipMess .= '<br><br>' . $LNG['sys_expe_found_ships_nothing'];
                }
                foreach ($fleetArray as $ID => $Count) {
                    if (!empty($Found[$ID])) {
                        $Count += $Found[$ID];
                    }
                    $NewFleetArray .= $ID . "," . floattostring($Count) . ';';
                }
                $Message .= $FoundShipMess;
                $this->UpdateFleet('fleet_array', $NewFleetArray);
                $this->UpdateFleet('fleet_amount', array_sum($fleetArray));
                break;
            case 4:
                $Chance = mt_rand(1, 2);
                if ($Chance == 1) {
                    $Points = array(-6, -8, -10);
                    $Which = 1;
                    $Def = -3;
                    $Name = $LNG['sys_expe_attackname_1'];
                    $Add = 0;
                    $Rand = array(5, 3, 2);
                    $DefenderFleetArray = "204,5;206,3;207,2;";
                } else {
                    $Points = array(-7, -9, -11);
                    $Which = 2;
                    $Def = 3;
                    $Name = $LNG['sys_expe_attackname_2'];
                    $Add = 0.1;
                    $Rand = array(4, 3, 2);
                    $DefenderFleetArray = "205,5;215,3;213,2;";
                }
                $messageHTML = <<<HTML
<div class="raportMessage">
<table>
<tr>
<td colspan="2"><a href="CombatReport.php?raport=%s" target="_blank"><span %s>%s %s (%s)</span></a></td>
</tr>
<tr>
<td>%s</td><td><span %s>%s: %s</span>&nbsp;<span %s>%s: %s</span></td>
</tr>
<tr>
\t\t\t<td>%s</td><td><span>%s:&nbsp;<span style="color:#a47d7a;">%s</span>&nbsp;</span><span>%s:&nbsp;<span style="color:#5ca6aa;">%s</span>&nbsp;</span><span>%s:&nbsp;<span style="color:#339966;">%s</span></span></td>
\t\t</tr>
<tr>
\t\t\t<td>%s</td><td><span>%s:&nbsp;<span style="color:#a47d7a;">%s</font>&nbsp;</span><span>%s:&nbsp;<span style="color:#5ca6aa;">%s</span></span></td>
\t\t</tr>
</table>
</div>
HTML;
                //Minize HTML
                $messageHTML = str_replace(array("\n", "\t", "\r"), "", $messageHTML);
                $FindSize = mt_rand(0, 100);
                $maxAttack = 0;
                if (10 < $FindSize) {
                    $Message = $LNG['sys_expe_attack_' . $Which . '_1_' . $Rand[0]];
                    $maxAttack = 0.3 + $Add + mt_rand($Points[0], abs($Points[0])) * 0.01;
                } elseif (0 < $FindSize && 10 >= $FindSize) {
                    $Message = $LNG['sys_expe_attack_' . $Which . '_2_' . $Rand[1]];
                    $maxAttack = 0.3 + $Add + mt_rand($Points[1], abs($Points[1])) * 0.01;
                } elseif (0 == $FindSize) {
                    $Message = $LNG['sys_expe_attack_' . $Which . '_3_' . $Rand[2]];
                    $maxAttack = 0.3 + $Add + mt_rand($Points[2], abs($Points[2])) * 0.01;
                }
                foreach ($fleetArray as $ID => $count) {
                    $DefenderFleetArray .= $ID . "," . round($count * $maxAttack) . ";";
                }
                $AttackerTechno = $GLOBALS['DATABASE']->getFirstRow("SELECT * FROM " . USERS . " WHERE id = " . $this->_fleet['fleet_owner'] . ";");
                $DefenderTechno = array('id' => 0, 'username' => $Name, 'military_tech' => min($AttackerTechno['military_tech'] + $Def, 0), 'defence_tech' => min($AttackerTechno['defence_tech'] + $Def, 0), 'shield_tech' => min($AttackerTechno['shield_tech'] + $Def, 0), 'laser_tech' => 0, 'ion_tech' => 0, 'plasma_tech' => 0, 'gravity_tech' => 0, 'rpg_amiral' => 0, 'dm_defensive' => 0, 'dm_attack' => 0, 'experience_combat_level' => min($AttackerTechno['experience_combat_level'], 0), 'academy_1101' => 0, 'academy_1102' => 0, 'academy_1301' => 0, 'academy_1302' => 0, 'academy_1103' => 0, 'academy_1108' => 0, 'academy_1109' => 0, 'academy_1110' => 0, 'academy_1111' => 0, 'academy_1303' => 0, 'academy_1311' => 0);
                $fleetID = $this->_fleet['fleet_id'];
                $fleetAttack[$fleetID]['fleetDetail'] = $this->_fleet;
                $fleetAttack[$fleetID]['player'] = $AttackerTechno;
                $fleetAttack[$fleetID]['player']['factor'] = getFactors($fleetAttack[$this->_fleet['fleet_id']]['player'], 'attack', $this->_fleet['fleet_start_time']);
                $fleetAttack[$fleetID]['unit'] = array();
                $temp = explode(';', $this->_fleet['fleet_array']);
                foreach ($temp as $temp2) {
                    $temp2 = explode(',', $temp2);
                    if ($temp2[0] < 100) {
                        continue;
                    }
                    if (!isset($fleetAttack[$fleetID]['unit'][$temp2[0]])) {
                        $fleetAttack[$fleetID]['unit'][$temp2[0]] = 0;
                    }
                    $fleetAttack[$fleetID]['unit'][$temp2[0]] += $temp2[1];
                }
                $fleetDefend = array();
                $defRowDef = explode(';', $DefenderFleetArray);
                foreach ($defRowDef as $Element) {
                    $Element = explode(',', $Element);
                    if ($Element[0] < 100) {
                        continue;
                    }
                    if (!isset($fleetDefend[0]['unit'][$Element[0]])) {
                        $fleetDefend[0]['unit'][$Element[0]] = 0;
                    }
                    $fleetDefend[0]['unit'][$Element[0]] += $Element[1];
                }
                $fleetDefend[0]['fleetDetail'] = array('fleet_start_galaxy' => $this->_fleet['fleet_end_galaxy'], 'fleet_start_system' => $this->_fleet['fleet_end_system'], 'fleet_start_planet' => $this->_fleet['fleet_end_planet'], 'fleet_start_type' => 1, 'fleet_end_galaxy' => $this->_fleet['fleet_end_galaxy'], 'fleet_end_system' => $this->_fleet['fleet_end_system'], 'fleet_end_planet' => $this->_fleet['fleet_end_planet'], 'fleet_end_type' => 1, 'fleet_resource_metal' => 0, 'fleet_resource_crystal' => 0, 'fleet_resource_deuterium' => 0);
                $fleetDefend[0]['player'] = $DefenderTechno;
                $fleetDefend[0]['player']['factor'] = 0;
                require_once 'calculateAttack.php';
                $fleetIntoDebris = $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['Fleet_Cdr'];
                $defIntoDebris = $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['Defs_Cdr'];
                $combatResult = calculateAttack($fleetAttack, $fleetDefend, $fleetIntoDebris, $defIntoDebris);
                $fleetArray = '';
                $totalCount = 0;
                $fleetAttack[$fleetID]['unit'] = array_filter($fleetAttack[$fleetID]['unit']);
                foreach ($fleetAttack[$fleetID]['unit'] as $element => $amount) {
                    $fleetArray .= $element . ',' . $amount . ';';
                    $totalCount += $amount;
                }
                if ($totalCount <= 0) {
                    $this->KillFleet();
                } else {
                    $this->UpdateFleet('fleet_array', substr($fleetArray, 0, -1));
                    $this->UpdateFleet('fleet_amount', $totalCount);
                }
                require_once 'GenerateReport.php';
                $debrisRessource = array(901, 902);
                foreach ($debrisRessource as $elementID) {
                    $debris[$elementID] = 0;
                }
                $stealResource = array(901 => 0, 902 => 0, 903 => 0);
                $raportInfo = array('thisFleet' => $this->_fleet, 'debris' => $debris, 'stealResource' => $stealResource, 'moonChance' => 0, 'moonDestroy' => false, 'moonName' => null, 'moonDestroyChance' => null, 'moonDestroySuccess' => null, 'fleetDestroyChance' => null, 'fleetDestroySuccess' => null);
                $raportData = GenerateReport($combatResult, $raportInfo);
                $raportID = md5(uniqid('', true) . TIMESTAMP);
                $sqlQuery = "INSERT INTO " . RW . " SET rid = '" . $raportID . "', raport = '" . serialize($raportData) . "', time = '" . $this->_fleet['fleet_start_time'] . "', attacker = '" . $this->_fleet['fleet_owner'] . "';";
                $GLOBALS['DATABASE']->query($sqlQuery);
                switch ($combatResult['won']) {
                    case "a":
                        $attackClass = 'style="color:green;"';
                        $defendClass = 'style="color:red;"';
                        break;
                    case "w":
                        $attackClass = 'style="color:orange;"';
                        $defendClass = 'style="color:orange;"';
                        break;
                    case "r":
                        $attackClass = 'style="color:red;"';
                        $defendClass = 'style="color:green;"';
                        break;
                }
                $message = sprintf($messageHTML, $raportID, $attackClass, $LNG['sys_mess_attack_report'], sprintf($LNG['sys_adress_planet'], $this->_fleet['fleet_start_galaxy'], $this->_fleet['fleet_start_system'], $this->_fleet['fleet_start_planet'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']), $LNG['type_planet_short'][$this->_fleet['fleet_end_type']], $LNG['sys_lost'], $attackClass, $LNG['sys_attack_attacker_pos'], pretty_number($combatResult['unitLost']['attacker']), $defendClass, $LNG['sys_attack_defender_pos'], pretty_number($combatResult['unitLost']['defender']), $LNG['sys_gain'], $LNG['tech'][901], pretty_number($stealResource[901]), $LNG['tech'][902], pretty_number($stealResource[902]), $LNG['tech'][903], pretty_number($stealResource[903]), $LNG['sys_debris'], $LNG['tech'][901], pretty_number($debris[901]), $LNG['tech'][902], pretty_number($debris[902]));
                if ($combatResult['won'] == 'a') {
                    $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `achievements_expedition` = `achievements_expedition` + '1', `expedition_count` = `expedition_count` + '1' where `id` = '" . $this->_fleet['fleet_owner'] . "';");
                    $GLOBALS['DATABASE']->query("UPDATE " . USERS . " SET stardust = stardust + '" . $find_stardust . "' where `id` = " . $this->_fleet['fleet_owner'] . ";");
                }
                SendSimpleMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_end_stay'], 3, $LNG['sys_mess_tower'], $LNG['sys_mess_attack_report'], $message);
                break;
            case 5:
                $this->KillFleet();
                $Message = $LNG['sys_expe_lost_fleet_' . mt_rand(1, 4)];
                break;
            case 6:
                # http://owiki.de/Expedition#Ver.C3.A4nderte_Flugzeit
                $MoreTime = mt_rand(0, 100);
                $Wrapper = array();
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 2;
                $Wrapper[] = 3;
                $Wrapper[] = 3;
                $Wrapper[] = 5;
                if ($MoreTime < 75) {
                    $this->UpdateFleet('fleet_end_time', $this->_fleet['fleet_end_stay'] + ($this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay'] + ($this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time']) * $Wrapper[mt_rand(0, 9)]));
                    $Message = $LNG['sys_expe_time_slow_' . mt_rand(1, 6)];
                } else {
                    $this->UpdateFleet('fleet_end_time', $this->_fleet['fleet_end_stay'] + max(1, $this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay'] - ($this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time']) / 3 * $Wrapper[mt_rand(0, 9)]));
                    $Message = $LNG['sys_expe_time_fast_' . mt_rand(1, 3)];
                }
                break;
            case 7:
                $FindSize = mt_rand(0, 100);
                if (30 < $FindSize) {
                    $Message = 'You found one frisbee';
                    $varis = 'frisbee';
                } elseif (10 < $FindSize && 30 >= $FindSize) {
                    $Message = 'You found one alien';
                    $varis = 'alien';
                } elseif (0 < $FindSize && 10 >= $FindSize) {
                    $Message = 'You found one rocket';
                    $varis = 'rocket';
                }
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set `achievements_expedition` = `achievements_expedition` + '1', `expedition_count` = `expedition_count` + '1' where `id` = '" . $this->_fleet['fleet_owner'] . "';");
                $GLOBALS['DATABASE']->query("UPDATE " . USERS . " set " . $varis . " = " . $varis . " + '1' where `id` = '" . $this->_fleet['fleet_owner'] . "';");
                break;
        }
        SendSimpleMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_end_stay'], 15, $LNG['sys_mess_tower'], $LNG['sys_expe_report'], $Message);
        $this->setState(FLEET_RETURN);
        $this->SaveFleet();
    }
 function EndStayEvent()
 {
     global $pricelist, $CONF, $db, $reslist;
     $LNG = $this->GetUserLang($this->_fleet['fleet_owner']);
     foreach ($reslist['fleet'] as $ID) {
         $Expowert[$ID] = ($pricelist[$ID]['metal'] + $pricelist[$ID]['crystal']) / 1000;
     }
     $Expowert[202] = 12;
     $Expowert[203] = 47;
     $Expowert[204] = 12;
     $Expowert[205] = 110;
     $Expowert[206] = 47;
     $Expowert[207] = 160;
     $farray = explode(";", $this->_fleet['fleet_array']);
     $FleetPoints = 0;
     $FleetCapacity = 0;
     foreach ($farray as $Item => $Group) {
         if (empty($Group)) {
             continue;
         }
         $Class = explode(",", $Group);
         $FleetCount[$Class[0]] = $Class[1];
         $FleetCapacity += $Class[1] * $pricelist[$Class[0]]['capacity'];
         $FleetPoints += $Class[1] * $Expowert[$Class[0]];
     }
     $FleetCapacity -= $this->_fleet['fleet_resource_metal'] + $this->_fleet['fleet_resource_crystal'] + $this->_fleet['fleet_resource_deuterium'] + $this->_fleet['fleet_resource_darkmatter'];
     $GetEvent = mt_rand(0, 10);
     switch ($GetEvent) {
         case 1:
             $WitchFound = mt_rand(1, 3);
             $FindSize = mt_rand(0, 100);
             if (10 < $FindSize) {
                 $WitchSize = 1;
                 $Factor = mt_rand(10, 50) / $WitchFound * $CONF['resource_multiplier'];
                 $Message = $LNG['sys_expe_found_ress_1_' . mt_rand(1, 4)];
             } elseif (0 < $FindSize && 10 >= $FindSize) {
                 $WitchSize = 2;
                 $Factor = mt_rand(52, 100) / $WitchFound * $CONF['resource_multiplier'];
                 $Message = $LNG['sys_expe_found_ress_2_' . mt_rand(1, 3)];
             } elseif (0 == $FindSize) {
                 $WitchSize = 3;
                 $Factor = mt_rand(102, 200) / $WitchFound * $CONF['resource_multiplier'];
                 $Message = $LNG['sys_expe_found_ress_3_' . mt_rand(1, 2)];
             }
             $StatFactor = $db->uniquequery("SELECT MAX(total_points) as total FROM `" . STATPOINTS . "` WHERE `stat_type` = 1;");
             $MaxPoints = $StatFactor['total'] < 5000000 ? 9000 : 12000;
             $Size = min($Factor * MAX(MIN($FleetPoints / 1000, $MaxPoints), 200), $FleetCapacity);
             switch ($WitchFound) {
                 case 1:
                     $this->UpdateFleet('fleet_resource_metal', $this->_fleet['fleet_resource_metal'] + $Size);
                     break;
                 case 2:
                     $this->UpdateFleet('fleet_resource_crystal', $this->_fleet['fleet_resource_crystal'] + $Size);
                     break;
                 case 3:
                     $this->UpdateFleet('fleet_resource_deuterium', $this->_fleet['fleet_resource_deuterium'] + $Size);
                     break;
             }
             break;
         case 2:
             $FindSize = mt_rand(0, 100);
             if (10 < $FindSize) {
                 $Size = mt_rand(100, 300);
                 $Message = $LNG['sys_expe_found_dm_1_' . mt_rand(1, 5)];
             } elseif (0 < $FindSize && 10 >= $FindSize) {
                 $Size = mt_rand(301, 600);
                 $Message = $LNG['sys_expe_found_dm_2_' . mt_rand(1, 4)];
             } elseif (0 == $FindSize) {
                 $Size = mt_rand(601, 3000);
                 $Message = $LNG['sys_expe_found_dm_3_' . mt_rand(1, 2)];
             }
             $this->UpdateFleet('fleet_resource_darkmatter', $this->_fleet['fleet_resource_darkmatter'] + $Size);
             break;
         case 3:
         default:
             unset($FleetCount[208]);
             unset($FleetCount[209]);
             unset($FleetCount[214]);
             $FindSize = mt_rand(0, 100);
             if (10 < $FindSize) {
                 $Size = mt_rand(2, 50);
                 $Message = $LNG['sys_expe_found_ships_1_' . mt_rand(1, 4)];
                 $MaxFound = 300000;
             } elseif (0 < $FindSize && 10 >= $FindSize) {
                 $Size = mt_rand(51, 100);
                 $Message = $LNG['sys_expe_found_ships_2_' . mt_rand(1, 2)];
                 $MaxFound = 600000;
             } elseif (0 == $FindSize) {
                 $Size = mt_rand(101, 200);
                 $Message = $LNG['sys_expe_found_ships_3_' . mt_rand(1, 2)];
                 $MaxFound = 1200000;
             }
             $StatFactor = $db->uniquequery("SELECT MAX(total_points) as total FROM `" . STATPOINTS . "` WHERE `stat_type` = 1;");
             $MaxPoints = $StatFactor['total'] < 5000000 ? 4500 : 6000;
             $FoundShips = max(min(round($Size * $FleetPoints), $MaxPoints), 10000);
             $MinFound = mt_rand(7000, 10000);
             $FoundShipMess = "";
             $NewFleetArray = "";
             $LNG += $this->GetUserLang($this->_fleet['fleet_owner'], 'TECH');
             foreach ($reslist['fleet'] as $ID) {
                 if (!isset($FleetCount[$ID])) {
                     continue;
                 }
                 $Count = mt_rand(1, floor($FoundShips / ($pricelist[$ID]['metal'] + $pricelist[$ID]['crystal'])));
                 $FleetCount[$ID] = bcadd($Count, $FleetCount[$ID]);
                 $NewFleetArray .= $ID . "," . floattostring($Count + $FleetCount[$ID]) . ";";
                 $FoundShips -= $Count * ($pricelist[$ID]['metal'] + $pricelist[$ID]['crystal']);
                 $FoundShipMess .= '<br>' . $LNG['tech'][$ID] . ': ' . pretty_number($Count);
                 if ($FoundShips <= 0) {
                     break;
                 }
             }
             $Message .= $FoundShipMess;
             foreach ($FleetCount as $ID => $Count) {
                 if (empty($Count)) {
                     continue;
                 }
             }
             $this->UpdateFleet('fleet_array', $NewFleetArray);
             $this->UpdateFleet('fleet_amount', array_sum($FleetCount));
             break;
         case 4:
             $Chance = mt_rand(1, 2);
             if ($Chance == 1) {
                 $Points = array(-3, -5, -8);
                 $Which = 1;
                 $Def = -3;
                 $Name = $LNG['sys_expe_attackname_1'];
                 $Add = 0;
                 $Rand = array(5, 3, 2);
                 $DefenderFleetArray = "204,5;206,3;207,2;";
             } else {
                 $Points = array(-4, -6, -9);
                 $Which = 2;
                 $Def = 3;
                 $Name = $LNG['sys_expe_attackname_2'];
                 $Add = 0.1;
                 $Rand = array(4, 3, 2);
                 $DefenderFleetArray = "205,5;215,3;213,2;";
             }
             $FindSize = mt_rand(0, 100);
             if (10 < $FindSize) {
                 $Message = $LNG['sys_expe_attack_' . $Which . '_1_' . $Rand[0]];
                 $MaxAttackerPoints = 0.3 + $Add + mt_rand($Points[0], abs($Points[0])) * 0.01;
             } elseif (0 < $FindSize && 10 >= $FindSize) {
                 $Message = $LNG['sys_expe_attack_' . $Which . '_2_' . $Rand[1]];
                 $MaxAttackerPoints = 0.3 + $Add + mt_rand($Points[1], abs($Points[1])) * 0.01;
             } elseif (0 == $FindSize) {
                 $Message = $LNG['sys_expe_attack_' . $Which . '_3_' . $Rand[2]];
                 $MaxAttackerPoints = 0.3 + $Add + mt_rand($Points[2], abs($Points[2])) * 0.01;
             }
             foreach ($FleetCount as $ID => $count) {
                 $DefenderFleetArray .= $ID . "," . round($count * $MaxAttackerPoints) . ";";
             }
             $AttackerTechno = $db->uniquequery('SELECT id,username,military_tech,defence_tech,shield_tech,rpg_amiral,dm_defensive,dm_attack FROM ' . USERS . ' WHERE id=' . $this->_fleet['fleet_owner'] . ";");
             $DefenderTechno = array('id' => 0, 'username' => $Name, 'military_tech' => min($AttackerTechno['military_tech'] + $Def, 0), 'defence_tech' => min($AttackerTechno['defence_tech'] + $Def, 0), 'shield_tech' => min($AttackerTechno['shield_tech'] + $Def, 0), 'rpg_amiral' => 0, 'dm_defensive' => 0, 'dm_attack' => 0);
             $attackFleets[$this->_fleet['fleet_id']]['fleet'] = $this->_fleet;
             $attackFleets[$this->_fleet['fleet_id']]['user'] = $AttackerTechno;
             $attackFleets[$this->_fleet['fleet_id']]['detail'] = array();
             $temp = explode(';', $this->_fleet['fleet_array']);
             foreach ($temp as $temp2) {
                 $temp2 = explode(',', $temp2);
                 if ($temp2[0] < 100) {
                     continue;
                 }
                 if (!isset($attackFleets[$this->_fleet['fleet_id']]['detail'][$temp2[0]])) {
                     $attackFleets[$this->_fleet['fleet_id']]['detail'][$temp2[0]] = 0;
                 }
                 $attackFleets[$this->_fleet['fleet_id']]['detail'][$temp2[0]] += $temp2[1];
             }
             $defense = array();
             $defRowDef = explode(';', $DefenderFleetArray);
             foreach ($defRowDef as $Element) {
                 $Element = explode(',', $Element);
                 if ($Element[0] < 100) {
                     continue;
                 }
                 if (!isset($defense[$defRow['fleet_id']]['def'][$Element[0]])) {
                     $defense[0][$Element[0]] = 0;
                 }
                 $defense[0]['def'][$Element[0]] += $Element[1];
             }
             $defense[0]['user'] = $DefenderTechno;
             require_once 'calculateAttack.' . PHP_EXT;
             $start = microtime(true);
             $result = calculateAttack($attackFleets, $defense);
             $totaltime = microtime(true) - $start;
             foreach ($attackFleets as $fleetID => $attacker) {
                 $fleetArray = '';
                 $totalCount = 0;
                 foreach ($attacker['detail'] as $element => $amount) {
                     if ($amount) {
                         $fleetArray .= $element . ',' . $amount . ';';
                     }
                     $totalCount += $amount;
                 }
                 if ($totalCount <= 0) {
                     $this->KillFleet();
                 } else {
                     $this->UpdateFleet('fleet_array', substr($fleetArray, 0, -1));
                     $this->UpdateFleet('fleet_amount', $totalCount);
                 }
             }
             require_once 'GenerateReport.' . PHP_EXT;
             $raport = GenerateReport($result, $INFO);
             $rid = md5(microtime(true) . mt_rand(1, 100));
             file_put_contents(ROOT_PATH . 'raports/raport_' . $rid . '.php', '<?php' . "\n" . '$raport = ' . $raport . ';' . "\n" . '?>');
             $SQLQuery = "INSERT INTO " . RW . " SET `time` = '" . TIMESTAMP . "', `owners` = '" . $this->_fleet['fleet_owner'] . ",0', `rid` = '" . $rid . "', `raport` = '';";
             $db->query($SQLQuery);
             switch ($result['won']) {
                 case "r":
                     $ColorAtt = "red";
                     $ColorDef = "green";
                     break;
                 case "w":
                     $ColorAtt = "orange";
                     $ColorDef = "orange";
                 case "a":
                     $ColorAtt = "green";
                     $ColorDef = "red";
                     break;
             }
             $MessageAtt = sprintf('<a href="CombatReport.php?raport=%s" onclick="OpenPopup(\'CombatReport.php?raport=%s\', \'combat\', screen.width, screen.height);return false" target="combat"><center><font color="%s">%s %s</font></a><br><br><font color="%s">%s: %s</font> <font color="%s">%s: %s</font><br>%s %s:<font color="#adaead">%s</font> %s:<font color="#ef51ef">%s</font> %s:<font color="#f77542">%s</font><br>%s %s:<font color="#adaead">%s</font> %s:<font color="#ef51ef">%s</font><br></center>', $rid, $rid, $ColorAtt, $LNG['sys_mess_attack_report'], sprintf($LNG['sys_adress_planet'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']), $ColorAtt, $LNG['sys_perte_attaquant'], pretty_number($result['lost']['att']), $ColorDef, $LNG['sys_perte_defenseur'], pretty_number($result['lost']['def']), $LNG['sys_gain'], $LNG['Metal'], pretty_number($steal['metal']), $LNG['Crystal'], pretty_number($steal['crystal']), $LNG['Deuterium'], pretty_number($steal['deuterium']), $LNG['sys_debris'], $LNG['Metal'], pretty_number($result['debree']['att'][0] + $result['debree']['def'][0]), $LNG['Crystal'], pretty_number($result['debree']['att'][1] + $result['debree']['def'][1]));
             SendSimpleMessage($this->_fleet['fleet_owner'], '', $this->_fleet['fleet_start_time'], 3, $LNG['sys_mess_tower'], $LNG['sys_mess_attack_report'], $MessageAtt);
             break;
         case 5:
             $this->KillFleet();
             $Message = $LNG['sys_expe_lost_fleet_' . mt_rand(1, 4)];
             break;
         case 6:
             $MoreTime = mt_rand(0, 100);
             if ($MoreTime < 75) {
                 $this->UpdateFleet('fleet_end_time', $this->_fleet['fleet_end_time'] - TIMESTAMP * mt_rand(1, 5) + TIMESTAMP);
                 $Message = $LNG['sys_expe_time_slow_' . mt_rand(1, 6)];
             } else {
                 $this->UpdateFleet('fleet_end_time', round($this->_fleet['fleet_end_stay'] + ($this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay']) / 2));
                 $Message = $LNG['sys_expe_time_fast_' . mt_rand(1, 3)];
             }
             break;
         default:
             $Message = $LNG['sys_expe_nothing_' . mt_rand(1, 8)];
             break;
     }
     SendSimpleMessage($this->_fleet['fleet_owner'], '', $this->_fleet['fleet_end_stay'], 15, $LNG['sys_mess_tower'], $LNG['sys_expe_report'], $Message);
     $this->UpdateFleet('fleet_mess', 1);
     $this->SaveFleet();
 }
            $category = get_category_by_sku($inventory->sku);
            if ($category !== 0) {
                $categories = $category["GetProductCategoriesForSKUResponse"]["GetProductCategoriesForSKUResult"]["Self"][1];
                if (isset($categories)) {
                    $category = $categories;
                    $arrCategories = array();
                    while (true) {
                        if ($category["ProductCategoryName"] != "Subjects") {
                            array_unshift($arrCategories, $category["ProductCategoryName"]);
                        }
                        if (!isset($category['Parent'])) {
                            break;
                        }
                        $category = $category['Parent'];
                    }
                    for ($i = 0; $i < MIN(count($arrCategories), 3); $i++) {
                        $aminfo['category' . ($i + 1)] = $arrCategories[$i];
                    }
                }
            } else {
            }
            $aminfo->inventory_id = $inventory->id;
            $aminfo->save();
            //usleep(100);
        }
        $start += count($inventories);
    }
}
/*
	Process description...
*/
 function get_week_info($tabrange, $week, $chapter = 0)
 {
     global $SESSION, $DB, $USER;
     $c = $this->get_chapter($chapter);
     // added by oncampus
     $lections = $c['lections'];
     // added by oncampus
     //$fnmaxtab = $DB->get_field('course_config_fn', 'value', array('courseid' => $this->course->id, 'variable' => 'maxtabs'));
     /* if ($fnmaxtab) {
            $maximumtabs = $fnmaxtab;
        } else {
            $maximumtabs = 12;
        } */
     $maximumtabs = 6;
     if ($lections < 6) {
         $maximumtabs = $lections;
     }
     $last_lection = $this->get_last_lection();
     // oncampus
     if ($USER->username == 'rieger') {
         //echo 'range: '.$tabrange.', week: '.$week.', chapter: '.$chapter.', last_section: '.$last_lection.'<br />';
     }
     if ($last_lection == $maximumtabs) {
         // oncampus
         //if ($USER->username == 'rieger') { echo '1<br />';}
         $tablow = 1;
         $tabhigh = $maximumtabs;
     } else {
         if ($maximumtabs < 6) {
             //if ($USER->username == 'rieger') { echo '1.5<br />';}
             $tablow = 1;
             $tabhigh = $maximumtabs;
         } else {
             if ($tabrange > 1000) {
                 //if ($USER->username == 'rieger') { echo '2<br />';}
                 $tablow = (int) ($tabrange / 1000);
                 $tabhigh = (int) ($tablow + $maximumtabs - 1);
             } else {
                 if ($tabrange == 0 && $week == 0) {
                     //if ($USER->username == 'rieger') { echo '3<br />';}
                     $tablow = (int) ((int) ($last_lection - 1) / (int) $maximumtabs) * $maximumtabs + 1;
                     $tabhigh = $tablow + $maximumtabs - 1;
                 } else {
                     if ($tabrange == 0) {
                         $tablow = $week;
                         //((int) ((int) $week / (int) $maximumtabs) * $maximumtabs) + 1;
                         $tabhigh = $tablow + $maximumtabs - 1;
                         //if ($USER->username == 'rieger') { echo 'nr. 4 ('.$tablow.' '.$tabhigh.')<br />';}
                         //echo '('.$tablow.' '.$tabhigh.')';
                     } else {
                         //if ($USER->username == 'rieger') { echo '5<br />';}
                         $tablow = 1;
                         $tabhigh = $maximumtabs;
                     }
                 }
             }
         }
     }
     $tabhigh = MIN($tabhigh, $last_lection);
     /// Normalize the tabs to always display FNMAXTABS...
     if ($tabhigh - $tablow + 1 < $maximumtabs) {
         $tablow = $tabhigh - $maximumtabs + 1;
     }
     /// Save the low and high week in SESSION variables... If they already exist, and the selected
     /// week is in their range, leave them as is.
     if ($tabrange >= 1000 || !isset($SESSION->FN_tablow[$this->course->id]) || !isset($SESSION->FN_tabhigh[$this->course->id]) || $week < $SESSION->FN_tablow[$this->course->id] || $week > $SESSION->FN_tabhigh[$this->course->id]) {
         $SESSION->FN_tablow[$this->course->id] = $tablow;
         $SESSION->FN_tabhigh[$this->course->id] = $tabhigh;
     } else {
         $tablow = $SESSION->FN_tablow[$this->course->id];
         $tabhigh = $SESSION->FN_tabhigh[$this->course->id];
     }
     $tablow = MAX($tablow, 1);
     $tabhigh = MIN($tabhigh, $last_lection);
     // oncampus
     /* $low = $c['first_lection'] - ((int)(($maximumtabs - $lections) / 2));
     		
     		if (($low + $maximumtabs - 1) > $last_lection) {
     			$low = $last_lection - $maximumtabs + 1;
     		}
     		$high = $low + $maximumtabs - 1;
     		if ($chapter != 0 and (($tabrange > $low and $tabrange <= $high) or $tabrange == 0 )) {
     			$tablow = $low;
                 $tabhigh = $high;
     		} */
     // oncampus ende
     unset($maximumtabs);
     return array($tablow, $tabhigh, $week);
 }
Example #10
0
function processMergePlayers()
{
    // This script will merge 2 player ID's, setting the first one as .  Use with EXTREME cation!!
    global $cfg;
    $connection = @mysql_connect($cfg->get('db_host'), $cfg->get('db_user'), $cfg->get('db_pass'));
    @mysql_select_db($cfg->get('db_name'), $connection) or die("Database Error: " . mysql_error());
    // Get PlayerID's
    $pids = array();
    $pids[0] = $_POST['target_pid'] ? $_POST['target_pid'] : 0;
    // Target PID
    $pids[1] = $_POST['source_pid'] ? $_POST['source_pid'] : 0;
    // Source PID
    // Check PID Values
    if ($pids[0] == 0 || $pids[1] == 0) {
        showLog("<font color='red'>ERROR:</font> Data input missing!");
        return;
    }
    if ($pids[0] == $pids[1]) {
        showLog("<font color='red'>ERROR:</font> Target &amp; Source are Identical!!");
        return;
    }
    // Check Players Exist
    foreach ($pids as $pid) {
        if (!is_numeric($pid)) {
            showLog("<font color='red'>ERROR:</font> PID ({$pid}) is not a valid player!");
            return;
        }
        $query = "SELECT id FROM player WHERE id = {$pid}";
        $result = mysql_query($query);
        if (mysql_num_rows($result) == 1) {
            $pids_exist = true;
        } else {
            showLog("<<font color='red'>ERROR:</font> PID ({$pid}) is not a valid player!");
            return;
        }
    }
    // We are still here, so everything must have checked out
    showLog("Merging Player Data...");
    // Note: PID1 -->> PID0.  PID0 becomes the primary and PID1 is removed!  Make sure you get this RIGHT!!!!
    // Merge Single-line data tables
    $DataTables = array('army', 'kits', 'vehicles', 'weapons', 'player');
    foreach ($DataTables as $DataTable) {
        showLog(" -> Merging {$DataTable} table...");
        $query = "SELECT * FROM {$DataTable} WHERE id = {$pids[1]}";
        $result = mysql_query($query);
        if (mysql_num_rows($result) == 1) {
            $fieldCount = mysql_num_fields($result);
            $row = mysql_fetch_row($result);
            // Build Update Query
            $query = "UPDATE {$DataTable} SET ";
            for ($i = 1; $i < $fieldCount; $i++) {
                if (mysql_field_type($result, $i) == 'int') {
                    if ($DataTable == 'player' && mysql_field_name($result, $i) == 'joined') {
                        $query .= "`" . mysql_field_name($result, $i) . "` = " . $row[$i] . ",\n";
                    } elseif ($DataTable == 'player' && mysql_field_name($result, $i) == 'lastonline') {
                        $query .= "`" . mysql_field_name($result, $i) . "` = `" . mysql_field_name($result, $i) . "`,\n";
                    } elseif ($DataTable == 'player' && mysql_field_name($result, $i) == 'rndscore') {
                        $query .= "`" . mysql_field_name($result, $i) . "` = (SELECT IF(" . $row[$i] . " > `" . mysql_field_name($result, $i) . "`, " . $row[$i] . ", `" . mysql_field_name($result, $i) . "`)),\n";
                    } else {
                        $query .= "`" . mysql_field_name($result, $i) . "` = `" . mysql_field_name($result, $i) . "` + " . $row[$i] . ",\n";
                    }
                }
            }
            $query = rtrim($query, ",\n") . "\nWHERE id = {$pids[0]};";
            // Update Data
            if (mysql_query($query)) {
                showLog("\t\tSuccess!");
                // Remove Old Data
                $query = "DELETE FROM `{$DataTable}` WHERE id = {$pids[1]};";
                if (mysql_query($query)) {
                    showLog(" -> Old Player Data ({$DataTable}) Removed.");
                } else {
                    showLog("\t\t<font color='red'>ERROR:</font> " . mysql_error());
                }
            } else {
                showLog("\t\t<font color='red'>ERROR:</font> " . mysql_error());
                return;
            }
        } else {
            showLog("\t\tNo Data");
        }
    }
    // Reset Unlocks
    showLog(" -> Reseting Unlocks for Player ({$pids[0]})...");
    $query = "UPDATE unlocks SET state = 'n' WHERE (id = {$pids[0]})";
    if (mysql_query($query)) {
        $query = "UPDATE player SET availunlocks = 0, usedunlocks = 0 WHERE id = {$pids[0]}";
        mysql_query($query) or die(mysql_error());
        showLog("\t\tSuccess!");
        // Remove Old Unlocks Data
        showLog(" -> Removing Old Unlocks for Player ({$pids[1]})...");
        $query = "DELETE FROM unlocks WHERE (id = {$pids[1]})";
        if (mysql_query($query)) {
            showLog("\t\tUnlocks Removed!");
        } else {
            showLog("\t\t<font color='red'>ERROR:</font> Unlocks Removal Failed!" . mysql_error());
        }
    } else {
        showLog("\t\t<font color='red'>ERROR:</font> " . mysql_error());
        return;
    }
    // Merge Awards Data
    showLog(" -> Merging Awards table...");
    $query = "SELECT * FROM awards WHERE id = {$pids[1]};";
    $result = mysql_query($query);
    if (mysql_num_rows($result)) {
        while ($rowsrc = mysql_fetch_array($result)) {
            // Check Awards exist
            if ($rowsrc['awd']) {
                $query = "SELECT * FROM awards WHERE id = {$pids[0]} AND awd = " . $rowsrc['awd'] . ";";
                $chkresult = mysql_query($query);
                if (mysql_num_rows($chkresult)) {
                    // Update Award
                    $rowdest = mysql_fetch_array($chkresult);
                    $query = "UPDATE `awards` SET\n";
                    switch ($rowsrc['awd']) {
                        case 2051902:
                            // Gold
                        // Gold
                        case 2051907:
                            // Silver
                        // Silver
                        case 2051919:
                            // Bronze
                            $query .= "`level` = `level` + " . $rowsrc['level'] . ",\n";
                            break;
                        default:
                            $query .= "level = " . MAX($rowsrc['level'], $rowdest['level']) . ",\n";
                    }
                    $query .= "earned = " . MIN($rowsrc['earned'], $rowdest['earned']) . ",\n";
                    $query .= "first = " . MIN($rowsrc['first'], $rowdest['first']) . "\n";
                    $query .= "WHERE id = {$pids[0]} AND `awd` = " . $rowsrc['awd'] . ";";
                    if (mysql_query($query)) {
                        showLog("\t\tAward {$rowsrc[awd]} Update Success!");
                    } else {
                        showLog("\t\t<font color='red'>ERROR:</font> Award {$rowsrc[awd]} Update Failed: " . mysql_error());
                    }
                } else {
                    // Insert Award
                    $query = "INSERT INTO `awards` SET\n";
                    $query .= "`id` = {$pids[0]},\n";
                    $query .= "`awd` = " . $rowsrc['awd'] . ",\n";
                    $query .= "`level` = " . $rowsrc['level'] . ",\n";
                    $query .= "`earned` = " . $rowsrc['earned'] . ",\n";
                    $query .= "`first` = " . $rowsrc['first'] . ";";
                    if (mysql_query($query)) {
                        showLog("\t\tAward {$rowsrc[awd]} Insert Success!");
                    } else {
                        showLog("\t\t<font color='red'>ERROR:</font> Award {$rowsrc[awd]} Insert Failed: " . mysql_error());
                    }
                }
            } else {
                showLog("\t\t<font color='red'>ERROR:</font> Err, that shouldn't have happend! :(");
            }
        }
        showLog("\t\tAwards Table Merged!");
        // Remove Old Awards Data
        showLog(" -> Removing Old Awards for Player ({$pids[1]})...");
        $query = "DELETE FROM awards WHERE (id = {$pids[1]})";
        if (mysql_query($query)) {
            showLog("\t\tSuccess!");
        } else {
            showLog("\t\t<font color='red'>ERROR:</font> " . mysql_error());
        }
    }
    // Merge Maps Data
    showLog(" -> Merging Maps table...");
    $query = "SELECT * FROM `maps` WHERE `id` = {$pids[1]};";
    $result = mysql_query($query);
    if (mysql_num_rows($result)) {
        while ($rowsrc = mysql_fetch_array($result)) {
            // Check Map exist
            if ($rowsrc['mapid'] >= 0) {
                $query = "SELECT * FROM `maps` WHERE `id`= {$pids[0]} AND `mapid` = " . $rowsrc['mapid'] . ";";
                $chkresult = mysql_query($query);
                if (mysql_num_rows($chkresult)) {
                    // Update Map Data
                    $rowdest = mysql_fetch_array($chkresult);
                    $query = "UPDATE `maps` SET\n";
                    $query .= "`time` = `time` + " . $rowsrc['time'] . ",\n";
                    $query .= "`win` = `win` + " . $rowsrc['win'] . ",\n";
                    $query .= "`loss` = `loss` + " . $rowsrc['loss'] . ",\n";
                    if ($rowsrc['best'] > $rowdest['best']) {
                        $query .= "`best` = " . $rowsrc['best'] . ",\n";
                    }
                    if ($rowsrc['worst'] < $rowdest['worst']) {
                        $query .= "`worst` = `worst` + " . $rowsrc['worst'] . "\n";
                    }
                    $query .= "WHERE id = {$pids[0]} AND `mapid` = " . $rowsrc['mapid'] . ";";
                    if (mysql_query($query)) {
                        showLog("\t\tMap {$rowsrc[mapid]} Update Success!");
                    } else {
                        showLog("\t\t<font color='red'>ERROR:</font> Map {$rowsrc[mapid]} Update Failed: " . mysql_error());
                    }
                } else {
                    // Insert Map Data
                    $query = "INSERT INTO `maps` SET\n";
                    $query .= "`id` = {$pids[0]},\n";
                    $query .= "`mapid` = " . $rowsrc['mapid'] . ",\n";
                    $query .= "`time` = " . $rowsrc['time'] . ",\n";
                    $query .= "`win` = " . $rowsrc['win'] . ",\n";
                    $query .= "`loss` = " . $rowsrc['loss'] . ",\n";
                    $query .= "`best` = " . $rowsrc['best'] . ",\n";
                    $query .= "`worst` = " . $rowsrc['worst'] . ";";
                    if (mysql_query($query)) {
                        showLog("\t\tMap {$rowsrc[mapid]} Insert Success!");
                    } else {
                        showLog("\t\t<font color='red'>ERROR:</font> Map {$rowsrc[mapid]} Insert Failed: " . mysql_error());
                    }
                }
            } else {
                showLog("\t\t<font color='red'>ERROR:</font> MapID Invalid!");
            }
        }
        showLog("\t\tDone!");
        // Remove Old Maps Data
        showLog(" -> Removing Old Maps for Player ({$pids[1]})...");
        $query = "DELETE FROM maps WHERE (id = {$pids[1]})";
        if (mysql_query($query)) {
            showLog("\t\tSuccess!");
        } else {
            showLog("\t\t<font color='red'>ERROR:</font> " . mysql_error());
        }
    }
    // Update Kills Data
    showLog(" -> Updating Kills Data...");
    $query = "SELECT * FROM kills WHERE attacker = {$pids[1]};";
    $result = mysql_query($query);
    if (mysql_num_rows($result)) {
        while ($rowsrc = mysql_fetch_array($result)) {
            // Check Kills exist
            if ($rowsrc['victim']) {
                $query = "SELECT * FROM kills WHERE attacker = {$pids[0]} AND victim = " . $rowsrc['victim'] . ";";
                $chkresult = mysql_query($query);
                if (mysql_num_rows($chkresult)) {
                    // Update Existing record
                    $query = "UPDATE `kills` SET\n";
                    $query .= "`count` = `count` + " . $rowsrc['count'] . "\n";
                    $query .= "WHERE attacker = {$pids[0]} AND victim = " . $rowsrc['victim'] . ";";
                    if (mysql_query($query)) {
                        // Success
                    } else {
                        showLog("\t\t<font color='red'>ERROR:</font> Kills data not updated: " . mysql_error());
                    }
                } else {
                    // Insert Kills
                    $query = "INSERT INTO `kills` SET\n";
                    $query .= "attacker = {$pids[0]},\n";
                    $query .= "victim = " . $rowsrc['victim'] . ",\n";
                    $query .= "`count` = " . $rowsrc['count'] . ";";
                    if (mysql_query($query)) {
                        // Success
                    } else {
                        showLog("\t\t<font color='red'>ERROR:</font> Kills data not inserted: " . mysql_error());
                    }
                }
            } else {
                showLog("<font color='red'>#</font>");
            }
        }
        showLog("\t\tKills Done!");
        // Remove Old Kills Data
        showLog(" -> Removing Old Kills for Player ({$pids[1]})...");
        $query = "DELETE FROM kills WHERE (attacker = {$pids[1]})";
        if (mysql_query($query)) {
            showLog("\t\tSuccess!");
        } else {
            showLog("\t\t<font color='red'>ERROR:</font> " . mysql_error());
        }
    }
    // Update Deaths Data
    showLog(" -> Updating Deaths Data...");
    $query = "SELECT * FROM kills WHERE victim = {$pids[1]};";
    $result = mysql_query($query);
    if (mysql_num_rows($result)) {
        while ($rowsrc = mysql_fetch_array($result)) {
            // Check Deaths exist
            if ($rowsrc['attacker']) {
                $query = "SELECT * FROM kills WHERE attacker = " . $rowsrc['attacker'] . " AND victim = {$pids[0]};;";
                $chkresult = mysql_query($query);
                if (mysql_num_rows($chkresult)) {
                    // Update Existing record
                    $query = "UPDATE `kills` SET\n";
                    $query .= "`count` = `count` + " . $rowsrc['count'] . "\n";
                    $query .= "WHERE attacker = " . $rowsrc['attacker'] . " AND victim = {$pids[0]};";
                    if (mysql_query($query)) {
                        // Success
                    } else {
                        showLog("\t\t<font color='red'>ERROR:</font> Kills data not updated: " . mysql_error());
                    }
                } else {
                    // Insert Deaths
                    $query = "INSERT INTO `kills` SET\n";
                    $query .= "attacker = " . $rowsrc['attacker'] . ",\n";
                    $query .= "victim = {$pids[0]},\n";
                    $query .= "`count` = " . $rowsrc['count'] . ";";
                    if (mysql_query($query)) {
                        // Success
                    } else {
                        showLog("\t\t<font color='red'>ERROR:</font> Kills data not inserted: " . mysql_error());
                    }
                }
            } else {
                showLog("<font color='red'>#</font>");
            }
        }
        showLog("\t\tDeaths Done!");
        // Remove Old Deaths Data
        showLog(" -> Removing Old Deaths for Player ({$pids[1]})...");
        $query = "DELETE FROM kills WHERE (victim = {$pids[1]})";
        if (mysql_query($query)) {
            showLog("\t\tSuccess!");
        } else {
            showLog("\t\t<font color='red'>ERROR:</font> " . mysql_error());
        }
    }
    showLog("Done! :)\n");
    // Close database connection
    @mysql_close($connection);
    //Validating Rank
    $_POST['selitems'] = array($pids[0]);
    processValidateRanks();
    // Ensure Old player does not exist
    $_POST['selitems'] = array($pids[1]);
    processDeletePlayers();
}
Example #11
0
            $progName = IO_MIDI_GM::getProgramName($prog);
            echo " {$prog}({$progName})";
        }
        echo PHP_EOL;
        if ($noteOnTable[$channel] === $noteOffTable[$channel]) {
            echo "        NoteOn/OffCount: " . $noteOnTable[$channel];
        } else {
            echo "        NoteOnCount: " . $noteOnTable[$channel];
            echo "  NoteOffCount: " . $noteOffTable[$channel];
        }
        $noteKeyList = array_keys($noteKeyTable[$channel]);
        echo "  KeyRange: " . MIN($noteKeyList) . " <-> " . MAX($noteKeyList);
        echo PHP_EOL;
        if ($pitchbendTable[$channel] > 0) {
            $pitchbendRangeList = array_keys($pitchbendRangeTable[$channel]);
            echo "        PitchBendCount: " . $pitchbendTable[$channel];
            echo "  PitchBendRange: " . MIN($pitchbendRangeList) . " <-> " . MAX($pitchbendRangeList);
        } else {
            echo "        PitchBend: (none)";
        }
        echo PHP_EOL;
        if (count($controllerTypeTable) > 0) {
            $controllerTypeList = array_keys($controllerTypeTable[$channel]);
            sort($controllerTypeList);
            echo "        ControllerType: " . implode(' ', $controllerTypeList);
        } else {
            echo "        ControllerType: (none)";
        }
        echo PHP_EOL;
    }
}
function get_week_info($tabrange, $week, $resubmission = false)
{
    global $SESSION;
    $fnmaxtab = $DB->get_field('course_config_fn', 'value', array('courseid' => $this->course->id, 'variable' => 'maxtabs'));
    if ($fnmaxtab) {
        $maximumtabs = $fnmaxtab;
    } else {
        $maximumtabs = 12;
    }
    if ($this->course->numsections == $maximumtabs) {
        $tablow = 1;
        $tabhigh = $maximumtabs;
    } else {
        if ($tabrange > 1000) {
            $tablow = $tabrange / 1000;
            $tabhigh = $tablow + $maximumtabs - 1;
        } else {
            if ($tabrange == 0 && $week == 0) {
                $tablow = (int) ((int) ($this->course->numsections - 1) / (int) $maximumtabs) * $maximumtabs + 1;
                $tabhigh = $tablow + $maximumtabs - 1;
            } else {
                if ($tabrange == 0) {
                    $tablow = (int) ((int) $week / (int) $maximumtabs) * $maximumtabs + 1;
                    $tabhigh = $tablow + $maximumtabs - 1;
                } else {
                    $tablow = 1;
                    $tabhigh = $maximumtabs;
                }
            }
        }
    }
    $tabhigh = MIN($tabhigh, $this->course->numsections);
    /// Normalize the tabs to always display FNMAXTABS...
    if ($tabhigh - $tablow + 1 < $maximumtabs) {
        $tablow = $tabhigh - $maximumtabs + 1;
    }
    /// Save the low and high week in SESSION variables... If they already exist, and the selected
    /// week is in their range, leave them as is.
    if ($tabrange >= 1000 || !isset($SESSION->FN_tablow[$this->course->id]) || !isset($SESSION->FN_tabhigh[$this->course->id]) || $week < $SESSION->FN_tablow[$this->course->id] || $week > $SESSION->FN_tabhigh[$this->course->id]) {
        $SESSION->FN_tablow[$this->course->id] = $tablow;
        $SESSION->FN_tabhigh[$this->course->id] = $tabhigh;
    } else {
        $tablow = $SESSION->FN_tablow[$this->course->id];
        $tabhigh = $SESSION->FN_tabhigh[$this->course->id];
    }
    $tablow = MAX($tablow, 1);
    $tabhigh = MIN($tabhigh, $this->course->numsections);
    /// If selected week in a different set of tabs, move it to the current set...
    if ($week != 0 && $week < $tablow) {
        $week = $SESSION->G8_selected_week[$this->course->id] = $tablow;
    } else {
        if ($week > $tabhigh) {
            $week = $SESSION->G8_selected_week[$this->course->id] = $tabhigh;
        }
    }
    return array($tablow, $tabhigh, $week);
}
Example #13
0
 /**
  * Calculate account WN8
  * 
  * @return   Integer
  */
 protected function getWN8()
 {
     // If WN8 was not calculated yet
     if (is_null($this->wn8)) {
         // Get account_id
         $account_id = $this->account_id;
         // Get summary values
         $summary = $this->api->get('wot/account/info', array('fields' => 'statistics.all.battles,statistics.all.frags,statistics.all.damage_dealt,statistics.all.dropped_capture_points,statistics.all.spotted,statistics.all.wins', 'account_id' => $account_id))->{$account_id}->statistics->all;
         // Get tanks values
         $tanks = $this->api->get('wot/account/tanks', array('fields' => 'tank_id,statistics.battles', 'account_id' => $account_id))->{$account_id};
         // If this account has no tanks data skip calculation and return 0
         if (empty($tanks)) {
             $this->wn8 = 0;
             return $this->wn8;
         }
         // WN8 expected calculation
         $expDAMAGE = $expFRAGS = $expSPOT = $expDEF = $expWIN = 0;
         // Tanks missing in expected tank values but existing in account
         $missing = array();
         // Calculated account expected values
         foreach ($tanks as $tank) {
             // Tank exists in expected tank values
             if (isset($this->expected_tank_values[$tank->tank_id])) {
                 // Expected values for current tank
                 $expected = $this->expected_tank_values[$tank->tank_id];
                 // Battles on current tank
                 $tank_battles = $tank->statistics->battles;
                 // Calculate expected values for current tank
                 $expDAMAGE += $expected->expDamage * $tank_battles;
                 $expSPOT += $expected->expSpot * $tank_battles;
                 $expFRAGS += $expected->expFrag * $tank_battles;
                 $expDEF += $expected->expDef * $tank_battles;
                 $expWIN += 0.01 * $expected->expWinRate * $tank_battles;
                 // Tank missing in expected tank values so add it to the list
             } else {
                 $missing[] = $tank->tank_id;
             }
         }
         // User want accurate calculation
         if ($this->accurate_calculation and !empty($missing)) {
             // Get missing tanks stats from API server
             $missing_tanks = $this->api->get('wot/tanks/stats', array('tank_id' => implode(',', $missing), 'fields' => 'tank_id,all.battles,all.frags,all.damage_dealt,all.dropped_capture_points,all.spotted,all.wins', 'account_id' => $account_id))->{$account_id};
             // Reduce account summary data
             foreach ($missing_tanks as $tank) {
                 $summary->damage_dealt -= $tank->all->damage_dealt;
                 $summary->spotted -= $tank->all->spotted;
                 $summary->frags -= $tank->all->frags;
                 $summary->dropped_capture_points -= $tank->all->dropped_capture_points;
                 $summary->wins -= $tank->all->wins;
             }
         }
         // If there are missing tanks and searching for info is set to TRUE, get those values
         if (!empty($missing) and $this->search_missing_tanks) {
             $this->missing_tanks = $this->api->get('wot/encyclopedia/tankinfo', array('tank_id' => implode(',', $missing), 'fields' => 'localized_name'));
         }
         // Calculate WN8
         $rDAMAGE = $summary->damage_dealt / $expDAMAGE;
         $rSPOT = $summary->spotted / $expSPOT;
         $rFRAG = $summary->frags / $expFRAGS;
         $rDEF = $summary->dropped_capture_points / $expDEF;
         $rWIN = $summary->wins / $expWIN;
         $rWINc = max(0, ($rWIN - 0.71) / (1 - 0.71));
         $rDAMAGEc = max(0, ($rDAMAGE - 0.22) / (1 - 0.22));
         $rFRAGc = max(0, min($rDAMAGEc + 0.2, ($rFRAG - 0.12) / (1 - 0.12)));
         $rSPOTc = max(0, min($rDAMAGEc + 0.1, ($rSPOT - 0.38) / (1 - 0.38)));
         $rDEFc = max(0, min($rDAMAGEc + 0.1, ($rDEF - 0.1) / (1 - 0.1)));
         $wn8 = 980 * $rDAMAGEc + 210 * $rDAMAGEc * $rFRAGc + 155 * $rFRAGc * $rSPOTc + 75 * $rDEFc * $rFRAGc + 145 * MIN(1.8, $rWINc);
         // Ok we have WN8, store it
         $this->wn8 = round($wn8, 2);
     }
     // Return our mighty number
     return $this->wn8;
 }
Example #14
0
             $res1t['opacity'] = 0;
         }
         $res[] = $res1t;
     }
     $responseData = json_encode($res, FALSE);
     echo $responseData;
     exit;
 }
 if ($action_ajax == 'add_links') {
     if (!API::Host()->isWritable(array($hostid))) {
         rightsErrorAjax();
     }
     $shost = $hostid;
     foreach ($thostid as $thost) {
         if (API::Host()->isWritable(array($hostid))) {
             $newlink = array('host1' => MIN($shost, $thost), 'host2' => MAX($shost, $thost));
             $res = DBimap::insert('hosts_links', array($newlink));
         }
     }
     $responseData = json_encode(array('result' => $res), FALSE);
     echo $responseData;
     exit;
 }
 if ($action_ajax == 'update_link') {
     if (!rightsForLink($linkid)) {
         rightsErrorAjax();
     }
     $link = $linkid;
     $newlink = array('values' => array('name' => $linkoptions['linkname']), 'where' => array('id' => $link));
     $res = DBimap::update('hosts_links', array($newlink));
     $res = DBimap::delete('hosts_links_settings', array('ids' => array($link)));
 function get_week_info($tabrange, $week)
 {
     global $SESSION;
     if ($this->course->numsections == FNMAXTABS) {
         $tablow = 1;
         $tabhigh = FNMAXTABS;
     } else {
         if ($tabrange > 1000) {
             $tablow = $tabrange / 1000;
             $tabhigh = $tablow + FNMAXTABS - 1;
         } else {
             if ($tabrange == 0 && $week == 0) {
                 $tablow = (int) ((int) ($this->course->numsections - 1) / (int) FNMAXTABS) * FNMAXTABS + 1;
                 $tabhigh = $tablow + FNMAXTABS - 1;
             } else {
                 if ($tabrange == 0) {
                     $tablow = (int) ((int) $week / (int) FNMAXTABS) * FNMAXTABS + 1;
                     $tabhigh = $tablow + FNMAXTABS - 1;
                 } else {
                     $tablow = 1;
                     $tabhigh = FNMAXTABS;
                 }
             }
         }
     }
     $tabhigh = MIN($tabhigh, $this->course->numsections);
     /// Normalize the tabs to always display FNMAXTABS...
     if ($tabhigh - $tablow + 1 < FNMAXTABS) {
         $tablow = $tabhigh - FNMAXTABS + 1;
     }
     /// Save the low and high week in SESSION variables... If they already exist, and the selected
     /// week is in their range, leave them as is.
     if ($tabrange >= 1000 || !isset($SESSION->FN_tablow[$this->course->id]) || !isset($SESSION->FN_tabhigh[$this->course->id]) || $week < $SESSION->FN_tablow[$this->course->id] || $week > $SESSION->FN_tabhigh[$this->course->id]) {
         $SESSION->FN_tablow[$this->course->id] = $tablow;
         $SESSION->FN_tabhigh[$this->course->id] = $tabhigh;
     } else {
         $tablow = $SESSION->FN_tablow[$this->course->id];
         $tabhigh = $SESSION->FN_tabhigh[$this->course->id];
     }
     $tablow = MAX($tablow, 1);
     $tabhigh = MIN($tabhigh, $this->course->numsections);
     /// If selected week in a different set of tabs, move it to the current set...
     if ($week != 0 && $week < $tablow) {
         $week = $SESSION->G8_selected_week[$this->course->id] = $tablow;
     } else {
         if ($week > $tabhigh) {
             $week = $SESSION->G8_selected_week[$this->course->id] = $tabhigh;
         }
     }
     return array($tablow, $tabhigh, $week);
 }
Example #16
0
function printdivbuffer() {
	$p1 = $this->blk[$this->blklvl]['startpage'];
	$p2 = $this->page;
	$bottom[$p1] = $this->ktBlock[$p1]['bottom_margin'];
	$bottom[$p2] = $this->y;	// $this->ktBlock[$p2]['bottom_margin'];
	$top[$p1] = $this->kt_y00;

	$top2 = $this->h;
	foreach($this->divbuffer AS $key=>$s) { 
		if ($s['page'] == $p2) {
			$top2 = MIN($s['y'], $top2);
		}
	}
	$top[$p2] = $top2;
	$height[$p1] = ($bottom[$p1] - $top[$p1]);
	$height[$p2] = ($bottom[$p2] - $top[$p2]);
	$xadj[$p1] = $this->MarginCorrection;
	$yadj[$p1] = -($top[$p1] - $top[$p2]);
	$xadj[$p2] = 0;
	$yadj[$p2] = $height[$p1];

	// Output without any transformation
	if ($this->ColActive || !$this->keep_block_together || $this->blk[$this->blklvl]['startpage'] == $this->page || ($this->page - $this->blk[$this->blklvl]['startpage']) > 1 || ($height[$p1]+$height[$p2]) > $this->h) { 
		foreach($this->divbuffer AS $s) { $this->pages[$s['page']] .= $s['s']."\n"; }
		foreach($this->ktLinks AS $p => $l) {
		   foreach($l AS $v) {
			$this->PageLinks[$p][] = $v;
		   }
		}
		foreach($this->ktForms AS $key => $f) {
			$this->form->forms[$f['n']] = $f;
		}
/*-- ANNOTATIONS --*/
		foreach($this->ktAnnots AS $p => $l) {
		   foreach($l AS $v) {
			$this->PageAnnots[$p][] = $v;
		   }
		}
/*-- END ANNOTATIONS --*/
/*-- INDEX --*/
	      // Adjust Reference (index)
	      foreach($this->ktReference AS $v) {
			$Present=0;
			//Search the reference (AND Ref/PageNo) in the array
			for ($i=0;$i<count($this->Reference);$i++){
				if ($this->Reference[$i]['t']==$v['t']){
					$Present=1;
					if (!in_array($p2,$this->Reference[$i]['p'])) {
						$this->Reference[$i]['p'][] = $p2;
					}
				}
			}
			//If not found, add it
			if ($Present==0) {
				$this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
			}
	      }
/*-- END INDEX --*/

/*-- BOOKMARKS --*/
	      // Adjust Bookmarks
	      foreach($this->ktBMoutlines AS $v) {
			$this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$v['p']);
	      }
/*-- END BOOKMARKS --*/

/*-- TOC --*/
	      // Adjust ToC
	      foreach($this->_kttoc AS $v) {
			$this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$v['p'],'link'=>$v['link'],'toc_id'=>$v['toc_id']);
	      }
/*-- END TOC --*/

		$this->divbuffer = array();
		$this->ktLinks = array();
		$this->ktAnnots = array();
		$this->ktForms = array();
		$this->ktBlock = array();
		$this->ktReference = array();
		$this->ktBMoutlines = array();
		$this->_kttoc = array();
		$this->keep_block_together = 0;
		return; 
	}
	else {
	// Output with transformation
	   // mPDF 5.6.17
	   $np = '';
	   $lastpage = -1;
	   foreach($this->divbuffer AS $key=>$s) { 
		// callback function
		$t = $s['s'];
		$p = $s['page'];
		if ($p != $lastpage) {
			$q = '';
			if ($lastpage != -1) { $q =  ' Q'."\n"; }
			$t = $q . $this->StartTransform(true)."\n" . $this->transformTranslate($xadj[$p], $yadj[$p] , true)."\n" . $t;
			$lastpage = $p;
		}
		$np .= $t."\n";
	   }
	   if ($lastpage != -1) { $np .=  ' Q'."\n"; }

	   $this->pages[$this->page] .= $np;

	   // Adjust hyperLinks
	   foreach($this->ktLinks AS $p => $l) {
	    foreach($l AS $v) {
		$v[0] += ($xadj[$p]*_MPDFK);
		$v[1] -= ($yadj[$p]*_MPDFK);
		$this->PageLinks[$p2][] = $v;
	    }
	   }
	   foreach($this->ktForms AS $key => $f) {
		$p = $f['page'];
		$f['x'] += ($xadj[$p]);
		$f['y'] += ($yadj[$p]);
		$f['page'] = $p2;
		$this->form->forms[$f['n']] = $f;
	   }
	   foreach($this->internallink AS $key => $f) {
		if (is_array($f) && isset($f['kt'])) {
			$f['Y'] += ($yadj[$f['PAGE']]);
			$f['PAGE'] = $p2;
			unset($f['kt']);
			$this->internallink[$key] = $f;
		}
	   }
/*-- ANNOTATIONS --*/
	   foreach($this->ktAnnots AS $p => $l) {
	    foreach($l AS $v) {
		if ($v['x']>0) { $v['x'] += $xadj[$p]; }
		else if ($v['x']<0) { $v['x'] -= $xadj[$p]; }
		$v['y'] += $yadj[$p];
		$this->PageAnnots[$p2][] = $v;
	    }
	   }
/*-- END ANNOTATIONS --*/

/*-- BOOKMARKS --*/
	   // Adjust Bookmarks
	   foreach($this->ktBMoutlines AS $v) {
		if ($v['y'] != 0) { $v['y'] += ($yadj[$v['p']]); }
		$this->BMoutlines[]=array('t'=>$v['t'],'l'=>$v['l'],'y'=>$v['y'],'p'=>$p2);
	   }
/*-- END BOOKMARKS --*/

/*-- INDEX --*/
	   // Adjust Reference (index)
	   foreach($this->ktReference AS $v) {
		$Present=0;
		//Search the reference (AND Ref/PageNo) in the array
		for ($i=0;$i<count($this->Reference);$i++){
			if ($this->Reference[$i]['t']==$v['t']){
				$Present=1;
				if (!in_array($p2,$this->Reference[$i]['p'])) {
					$this->Reference[$i]['p'][] = $p2;
				}
			}
		}
		//If not found, add it
		if ($Present==0) {
			$this->Reference[]=array('t'=>$v['t'],'p'=>array($p2));
		}
	   }
/*-- END INDEX --*/

/*-- TOC --*/
	   // Adjust ToC
	   foreach($this->_kttoc AS $v) {
		$this->tocontents->_toc[]=array('t'=>$v['t'],'l'=>$v['l'],'p'=>$p2,'link'=>$v['link'],'toc_id'=>$v['toc_id']);
		$this->links[$v['link']][0] = $p2;
		$this->links[$v['link']][1] += $yadj[$v['p']];
	   }
/*-- END TOC --*/

	   $this->y = $top[$p2] + $height[$p1] + $height[$p2];
	   $this->x = $this->lMargin;

	   $this->divbuffer = array();
	   $this->ktLinks = array();
	   $this->ktAnnots = array();
	   $this->ktForms = array();
	   $this->ktBlock = array();
	   $this->ktReference = array();
	   $this->ktBMoutlines = array();
	   $this->_kttoc = array();
	   $this->keep_block_together = 0;
	}
}
Example #17
0
 case "textbox":
     if ($fields[$i]->getVar('field_valuetype') == XOBJ_DTYPE_INT) {
         $searchform->addElement(new XoopsFormText(sprintf(_PROFILE_MA_LARGERTHAN, $fields[$i]->getVar('field_title')), $fields[$i]->getVar('field_name') . "_larger", 35, 35));
         $searchform->addElement(new XoopsFormText(sprintf(_PROFILE_MA_SMALLERTHAN, $fields[$i]->getVar('field_title')), $fields[$i]->getVar('field_name') . "_smaller", 35, 35));
     } else {
         $tray = new XoopsFormElementTray($fields[$i]->getVar('field_title'));
         $tray->addElement(new XoopsFormSelectMatchOption('', $fields[$i]->getVar('field_name') . "_match"));
         $tray->addElement(new XoopsFormText('', $fields[$i]->getVar('field_name'), 35, $fields[$i]->getVar('field_maxlength')));
         $searchform->addElement($tray);
         unset($tray);
     }
     break;
 case "radio":
 case "select":
     $options = $fields[$i]->getVar('field_options');
     $size = MIN(count($options), 10);
     $element = new XoopsFormSelect($fields[$i]->getVar('field_title'), $fields[$i]->getVar('field_name'), null, $size, true);
     asort($options);
     $element->addOptionArray($options);
     $searchform->addElement($element);
     unset($element);
     break;
 case "yesno":
     $element = new XoopsFormSelect($fields[$i]->getVar('field_title'), $fields[$i]->getVar('field_name'), null, 2, true);
     $element->addOption(1, _YES);
     $element->addOption(0, _NO);
     $searchform->addElement($element);
     unset($element);
     break;
 case "date":
 case "datetime":
Example #18
0
echo '<option value="6"' . ($ratio == 6 ? ' selected' : '') . '>&gt;= 5.000</option>';
echo '</select></td>';
echo '</tr><tr><td colspan="4"><input name="submit" type="submit"></td></tr>';
end_table();
echo '</form>';
$query = 'WHERE enabled = 1 AND downloaded > 0 AND uploaded > 0';
//' AND cheat >= '.$min
if ($class > 2) {
    $query .= ' AND class < ' . ($class - 1);
}
if ($ratio > 1) {
    $query .= ' AND (uploaded / downloaded) > ' . ($ratio - 1);
}
$res = sql_query("SELECT COUNT(*),MIN(cheat),MAX(cheat) FROM users {$query}") or sqlerr();
$arr = mysql_fetch_row($res);
$top = MIN($top, $arr[0]);
$min = $arr[1];
$max = $arr[2];
$pages = ceil($top / 20);
if ($page < 1) {
    $page = 1;
} elseif ($page > $pages) {
    $page = $pages;
}
list($pagertop, $pagerbottom, $limit) = pager(20, $top, "cheaters.php?");
echo $pagertop;
begin_table();
print "<tr><th class=\"left\">User name</th><th>Registered</th><th>Uploaded</th><th>Downloaded</th><th>Ratio</th><th>Cheat Value</th><th>Cheat Spread</th></tr>\n";
$res = sql_query("SELECT * FROM users {$query} ORDER BY cheat DESC {$limit}") or sqlerr();
while ($arr = mysql_fetch_assoc($res)) {
    if ($arr['added'] == "0000-00-00 00:00:00") {