function user_duration_query($course_id, $start = false, $end = false, $group = false) { $terms = array(); if ($start !== false and $end !== false) { $date_where = 'AND actions_daily.day BETWEEN ?s AND ?s'; $terms = array($start . ' 00:00:00', $end . ' 23:59:59'); } elseif ($start !== false) { $date_where = 'AND actions_daily.day > ?s'; $terms[] = $start . ' 00:00:00'; } elseif ($end !== false) { $date_where = 'AND actions_daily.day < ?s'; $terms[] = $end . ' 23:59:59'; } else { $date_where = ''; } if ($group !== false) { $from = "`group_members` AS groups\n LEFT JOIN user ON groups.user_id = user.id"; $and = "AND groups.group_id = ?d"; $terms[] = $group; } else { $from = " (SELECT * FROM user UNION (SELECT 0 as id,\n '' as surname,\n 'Anonymous' as givenname,\n null as username,\n null as password,\n null as email,\n null as parent_email,\n null as status,\n null as phone,\n null as am,\n null as registered_at,\n null as expires_at,\n null as lang, \n null as description,\n null as has_icon,\n null as verified_mail,\n null as receive_mail,\n null as email_public,\n null as phone_public,\n null as am_public,\n null as whitelist,\n null as last_passreminder)) as user "; $and = ''; } return Database::get()->queryArray("SELECT SUM(actions_daily.duration) AS duration,\n user.surname AS surname,\n user.givenname AS givenname,\n user.id AS id,\n user.am AS am\n FROM {$from}\n LEFT JOIN actions_daily ON user.id = actions_daily.user_id\n WHERE (actions_daily.course_id = ?d)\n {$and}\n {$date_where}\n GROUP BY user.id\n ORDER BY surname, givenname", $course_id, $terms); }
function show() { if (empty($_POST)) { HTTP::redirectTo('index.php'); } $db = Database::get(); $username = HTTP::_GP('username', '', UTF8_SUPPORT); $password = HTTP::_GP('password', '', true); $sql = "SELECT id, password FROM %%USERS%% WHERE universe = :universe AND username = :username;"; $loginData = $db->selectSingle($sql, array(':universe' => Universe::current(), ':username' => $username)); if (isset($loginData)) { $hashedPassword = PlayerUtil::cryptPassword($password); if ($loginData['password'] != $hashedPassword) { // Fallback pre 1.7 if ($loginData['password'] == md5($password)) { $sql = "UPDATE %%USERS%% SET password = :hashedPassword WHERE id = :loginID;"; $db->update($sql, array(':hashedPassword' => $hashedPassword, ':loginID' => $loginData['id'])); } else { HTTP::redirectTo('index.php?code=1'); } } $session = Session::create(); $session->userId = (int) $loginData['id']; $session->adminAccess = 0; $session->save(); HTTP::redirectTo('game.php'); } else { HTTP::redirectTo('index.php?code=1'); } }
public function UpdateOfficier($Element) { global $USER, $PLANET, $resource, $pricelist; $costResources = BuildFunctions::getElementPrice($USER, $PLANET, $Element); if (!BuildFunctions::isTechnologieAccessible($USER, $PLANET, $Element) || !BuildFunctions::isElementBuyable($USER, $PLANET, $Element, $costResources) || $pricelist[$Element]['max'] <= $USER[$resource[$Element]]) { return; } $USER[$resource[$Element]] += 1; if (isset($costResources[901])) { $PLANET[$resource[901]] -= $costResources[901]; } if (isset($costResources[902])) { $PLANET[$resource[902]] -= $costResources[902]; } if (isset($costResources[903])) { $PLANET[$resource[903]] -= $costResources[903]; } if (isset($costResources[921])) { $USER[$resource[921]] -= $costResources[921]; } $sql = 'UPDATE %%USERS%% SET ' . $resource[$Element] . ' = :newTime WHERE id = :userId;'; Database::get()->update($sql, array(':newTime' => $USER[$resource[$Element]], ':userId' => $USER['id'])); }
function run() { require_once 'includes/classes/class.MissionFunctions.php'; require_once 'includes/classes/missions/Mission.interface.php'; $db = Database::get(); $sql = 'SELECT %%FLEETS%%.* FROM %%FLEETS_EVENT%% INNER JOIN %%FLEETS%% ON fleetID = fleet_id WHERE `lock` = :token;'; $fleetResult = $db->select($sql, array(':token' => $this->token)); foreach ($fleetResult as $fleetRow) { if (!isset(self::$missionObjPattern[$fleetRow['fleet_mission']])) { $sql = 'DELETE FROM %%FLEETS%% WHERE fleet_id = :fleetId;'; $db->delete($sql, array(':fleetId' => $fleetRow['fleet_id'])); continue; } $missionName = self::$missionObjPattern[$fleetRow['fleet_mission']]; $path = 'includes/classes/missions/' . $missionName . '.class.php'; require_once $path; /** @var $missionObj Mission */ $missionObj = new $missionName($fleetRow); switch ($fleetRow['fleet_mess']) { case 0: $missionObj->TargetEvent(); break; case 1: $missionObj->ReturnEvent(); break; case 2: $missionObj->EndStayEvent(); break; } } }
/** * @brief display list of available learning paths (if any) * @global type $id * @global type $course_id * @global type $tool_content * @global type $urlServer * @global type $langComments * @global type $langAddModulesButton * @global type $langChoice * @global type $langNoLearningPath * @global type $langLearningPaths * @global type $course_code */ function list_lps() { global $id, $course_id, $tool_content, $urlServer, $langComments, $langAddModulesButton, $langChoice, $langNoLearningPath, $langLearningPaths, $course_code; $result = Database::get()->queryArray("SELECT * FROM lp_learnPath WHERE course_id = ?d ORDER BY name", $course_id); $lpinfo = array(); foreach ($result as $row) { $lpinfo[] = array('id' => $row->learnPath_id, 'name' => $row->name, 'comment' => $row->comment, 'visible' => $row->visible, 'rank' => $row->rank); } if (count($lpinfo) == 0) { $tool_content .= "<div class='alert alert-warning'>{$langNoLearningPath}</div>"; } else { $tool_content .= "<form action='insert.php?course={$course_code}' method='post'>" . "<input type='hidden' name='id' value='{$id}'>" . "<table class='table-default'>" . "<tr>" . "<th><div align='left'> {$langLearningPaths}</div></th>" . "<th><div align='left'>{$langComments}</div></th>" . "<th width='80'>{$langChoice}</th>" . "</tr>"; foreach ($lpinfo as $entry) { if ($entry['visible'] == 0) { $vis = 'invisible'; } else { $vis = ''; } $tool_content .= "<tr class='{$vis}'>"; $tool_content .= "<td> " . icon('fa-ellipsis-h') . " <a href='{$urlServer}/modules/learnPath/learningPath.php?course={$course_code}&path_id={$entry['id']}'>" . q($entry['name']) . "</a></td>"; $tool_content .= "<td>" . q($entry['comment']) . "</td>"; $tool_content .= "<td class='text-center'><input type='checkbox' name='lp[]' value='{$entry['id']}'></td>"; $tool_content .= "</tr>"; } $tool_content .= "<tr>" . "<th colspan='3'><div align='right'>"; $tool_content .= "<input class='btn btn-primary' type='submit' name='submit_lp' value='{$langAddModulesButton}'></div></th>"; $tool_content .= "</tr></table></form>\n"; } }
function get_hybridauth_config() { $providers = array ( // openid providers 'OpenID' => array ('enabled' => false)); $q = Database::get()->queryArray("SELECT * FROM auth WHERE auth_name IN ('yahoo', 'google', 'facebook', 'twitter', 'live', 'linkedin')"); if ($q) { foreach ($q as $row) { $name = $row->auth_name == 'linkedin' ? 'LinkedIn' : ucfirst($row->auth_name); if ($row->auth_default and !empty($row->auth_settings)) { $providers[$name]['keys'] = unserialize($row->auth_settings); $providers[$name]['enabled'] = true; if ($name == 'Facebook') { $providers[$name]['scope'] = 'public_profile, email'; } } else { $providers[$name]['keys'] = array(); $providers[$name]['enabled'] = true; } } } // return configuration data as an array return array( 'base_url' => $GLOBALS['urlServer'] . 'modules/auth/methods/hybridauth/', 'providers' => $providers, // if you want to enable logging, set 'debug_mode' to true then provide a writable file by the web server on 'debug_file' 'debug_mode' => false, 'debug_file' => '/tmp/log.log'); }
/** * display list of exercises * @global type $id * @global type $course_id * @global type $tool_content * @global type $urlServer * @global type $langComments * @global type $langAddModulesButton * @global type $langChoice * @global type $langNoExercises * @global type $langExercices * @global type $course_code */ function list_exercises() { global $id, $course_id, $tool_content, $urlServer, $langComments, $langAddModulesButton, $langChoice, $langNoExercises, $langExercices, $course_code; $result = Database::get()->queryArray("SELECT * FROM exercise WHERE course_id = ?d", $course_id); $quizinfo = array(); foreach ($result as $row) { $quizinfo[] = array('id' => $row->id, 'name' => $row->title, 'comment' => $row->description, 'visibility' => $row->active); } if (count($quizinfo) == 0) { $tool_content .= "<div class='alert alert-warning'>{$langNoExercises}</div>"; } else { $tool_content .= "<form action='insert.php?course={$course_code}' method='post'><input type='hidden' name='id' value='{$id}'>" . "<table class='table-default'>" . "<tr>" . "<th width='20%' class='text-left'>{$langExercices}</th>" . "<th class='text-left'>{$langComments}</th>" . "<th>{$langChoice}</th>" . "</tr>"; foreach ($quizinfo as $entry) { if ($entry['visibility'] == '0') { $vis = 'not_visible'; } else { $vis = ''; } $tool_content .= "<tr class='{$vis}'>"; $tool_content .= "<td class='text-left'><a href='{$urlServer}modules/exercise/exercise_submit.php?course={$course_code}&exerciseId={$entry['id']}'>" . q($entry['name']) . "</a></td>"; $tool_content .= "<td class='text-left'>" . $entry['comment'] . "</td>"; $tool_content .= "<td class='text-center'><input type='checkbox' name='exercise[]' value='{$entry['id']}'></td>"; $tool_content .= "</tr>"; } $tool_content .= "<tr><th colspan='3'><div align='right'>"; $tool_content .= "<input class='btn btn-primary' type='submit' name='submit_exercise' value='{$langAddModulesButton}'></div></th>"; $tool_content .= "</tr></table></form>"; } }
/** * Create a new foreign key from $masterTableName to $detailTableName based * on the $detailFieldName field * @param type $detailTableName The detail table name * @param type $detailFieldName The detail table's field name, which * connects with the master table * @param type $masterTableName The master table name * @param type $defaultEntryResolver A numeric value or a function which * returns a numeric value, in order to get the master id field value. This * will be used as default for those entries of the detail table, who are * orphaned (have a wrong reference). If this value is null, or if the * function returns null, and the field does not accept null values, then * the orphaned entries will be removed from the detail table and recycled * to the recyclebin table. */ public static function create($detailTableName, $detailFieldName, $masterTableName, $defaultEntryResolver) { $masterIDFieldName = DBHelper::primaryKeyOf($masterTableName); if (DBHelper::foreignKeyExists($detailTableName, $detailFieldName, $masterTableName, $masterIDFieldName)) return; $detailIDFieldName = DBHelper::primaryKeyOf($detailTableName); $defaultEntryID = is_null($defaultEntryResolver) ? null : (is_numeric($defaultEntryResolver) ? $defaultEntryResolver : is_callable($defaultEntryResolver) ? $defaultEntryResolver() : null); $nullable = DBHelper::isColumnNullable($detailTableName, $detailFieldName); $wrongIDs = Database::get()->queryArray("select `$detailTableName`.`$detailIDFieldName` as detailid from `$detailTableName` left join `$masterTableName` on `$detailTableName`.`$detailFieldName` = `$masterTableName`.`$masterIDFieldName` where `$detailTableName`.`$detailFieldName` is not null and `$masterTableName`.`$masterIDFieldName` is null"); if ($wrongIDs) { foreach ($wrongIDs as $entry) { if (is_null($defaultEntryID)) { if ($nullable) Database::get()->query("update `" . $detailTableName . "` set `" . $detailFieldName . "` = NULL where $detailIDFieldName = ?d" , $entry->detailid); else Recycle::deleteObject($detailTableName, $entry->detailid, $detailIDFieldName); } else { Database::get()->query("update `" . $detailTableName . "` set `" . $detailFieldName . "` = ?d where $detailIDFieldName = ?d" , $defaultEntryID, $entry->detailid); } } } DBHelper::createForeignKey($detailTableName, $detailFieldName, $masterTableName, $masterIDFieldName); }
function show() { global $LNG, $USER; $LNG->includeData(array('FLEET')); $this->setWindow('popup'); $db = Database::get(); $RID = HTTP::_GP('raport', ''); $sql = "SELECT raport,attacker,defender FROM %%RW%% WHERE rid = :reportID;"; $reportData = $db->selectSingle($sql, array(':reportID' => $RID)); if (empty($reportData)) { $this->printMessage($LNG['sys_raport_not_found']); } // empty is BC for pre r2484 $isAttacker = empty($reportData['attacker']) || in_array($USER['id'], explode(",", $reportData['attacker'])); $isDefender = empty($reportData['defender']) || in_array($USER['id'], explode(",", $reportData['defender'])); if (empty($reportData) || !$isAttacker && !$isDefender) { $this->printMessage($LNG['sys_raport_not_found']); } $combatReport = unserialize($reportData['raport']); if ($isAttacker && !$isDefender && $combatReport['result'] == 'r' && count($combatReport['rounds']) <= 2) { $this->printMessage($LNG['sys_raport_lost_contact']); } $combatReport['time'] = _date($LNG['php_tdformat'], $combatReport['time'], $USER['timezone']); $combatReport = $this->BCWrapperPreRev2321($combatReport); $this->assign(array('Raport' => $combatReport, 'pageTitle' => $LNG['sys_mess_attack_report'])); $this->display('shared.mission.raport.tpl'); }
public static function start() { $app = Core::make('app'); if ($app->isRunThroughCommandLineInterface()) { $storage = new MockArraySessionStorage(); } else { if (Config::get('concrete.session.handler') == 'database') { $db = \Database::get(); $storage = new NativeSessionStorage(array(), new PdoSessionHandler($db->getWrappedConnection(), array('db_table' => 'Sessions', 'db_id_col' => 'sessionID', 'db_data_col' => 'sessionValue', 'db_time_col' => 'sessionTime'))); } else { //$storage = new NativeSessionStorage(array(), new NativeFileSessionHandler()); $storage = new NativeSessionStorage(array()); } $options = Config::get('concrete.session.cookie'); if ($options['cookie_path'] === false) { $options['cookie_path'] = $app['app_relative_path'] . '/'; } $options['gc_max_lifetime'] = Config::get('concrete.session.max_lifetime'); $storage->setOptions($options); } $session = new SymfonySession($storage); $session->setName(Config::get('concrete.session.name')); static::testSessionFixation($session); return $session; }
function get_agendaitems($month, $year) { global $urlServer, $uid; if ($month < 10) { $month = '0' . $month; } $query = Database::get()->queryArray("SELECT course.code k, course.public_code fc,\n course.title i, course.prof_names t, course.id id\n FROM course, course_user, course_module\n WHERE course.id = course_user.course_id\n AND course.visible != " . COURSE_INACTIVE . "\n AND course_user.user_id = {$uid}\n AND course_module.module_id = " . MODULE_ID_AGENDA . "\n AND course_module.visible = 1\n AND course_module.course_id = course.id"); $items = array(); foreach ($query as $mycours) { $result = Database::get()->queryArray("SELECT * FROM agenda WHERE course_id = ?d\n AND DATE_FORMAT(start, '%m') = ?s\n AND DATE_FORMAT(start, '%Y') = ?s\n AND visible = 1", $mycours->id, $month, $year); foreach ($result as $item) { $URL = $urlServer . "modules/agenda/index.php?course=" . $mycours->k; $agendadate = date('d', strtotime($item->start)); $time = date('H:i', strtotime($item->start)); $items[$agendadate][$time] = "<br /><small>({$time}) <a href='{$URL}' title='{$mycours->i} ({$mycours->fc})'>{$mycours->i}</a> {$item->title}</small>"; } } // sorting by hour for every day $agendaitems = array(); while (list($agendadate, $tmpitems) = each($items)) { sort($tmpitems); $agendaitems[$agendadate] = ''; while (list($key, $val) = each($tmpitems)) { $agendaitems[$agendadate] .= $val; } } return $agendaitems; }
function hybridAuthForm($auth) { global $tool_content, $langAuthenticateVia, $langInstructionsAuth; $r = Database::get()->querySingle("SELECT auth_settings, auth_instructions, auth_name FROM auth WHERE auth_id = ?d", $auth); if (!empty($r->auth_settings)) { $auth_settings = unserialize($r->auth_settings); if (isset($auth_settings['id'])) { $auth_settings['key'] = $auth_settings['id']; } } else { $auth_settings['id'] = $auth_settings['secret'] = ''; } $auth_instructions = $r->auth_instructions; $authName = q(ucfirst($r->auth_name)); $tool_content .= "<div class='alert alert-info'>" . ucfirst($langAuthenticateVia) . " $authName</div> <div class='form-group'> <label for='hybridauth_id_key' class='col-sm-2 control-label'>$authName Id/Key:</label> <div class='col-sm-10'> <input class='form-control' name='hybridauth_id_key' id='hybridauth_id_key' type='text' value='" . q($auth_settings['key']) . "'> </div> </div> <div class='form-group'> <label for='hybridauth_secret' class='col-sm-2 control-label'>" . ucfirst($r->auth_name) . " Secret:</label> <div class='col-sm-10'> <input class='form-control' name='hybridauth_secret' id='hybridauth_secret' type='text' value='" . q($auth_settings['secret']) . "'> </div> </div> <div class='form-group'> <label for='auth_instructions' class='col-sm-2 control-label'>$langInstructionsAuth:</label> <div class='col-sm-10'> <textarea class='form-control' name='hybridauth_instructions' id='hybridauth_instructions' rows='10'>" . q($auth_instructions) . "</textarea> </div> </div>"; }
function ShowTeamspeakPage() { global $LNG; $config = Config::get(Universe::getEmulated()); if ($_POST) { $config_before = array('ts_timeout' => $config->ts_timeout, 'ts_modon' => $config->ts_modon, 'ts_server' => $config->ts_server, 'ts_tcpport' => $config->ts_tcpport, 'ts_udpport' => $config->ts_udpport, 'ts_version' => $config->ts_version, 'ts_login' => $config->ts_login, 'ts_password' => $config->ts_password, 'ts_cron_interval' => $config->ts_cron_interval); $ts_modon = isset($_POST['ts_on']) && $_POST['ts_on'] == 'on' ? 1 : 0; $ts_server = HTTP::_GP('ts_ip', ''); $ts_tcpport = HTTP::_GP('ts_tcp', 0); $ts_udpport = HTTP::_GP('ts_udp', 0); $ts_timeout = HTTP::_GP('ts_to', 0); $ts_version = HTTP::_GP('ts_v', 0); $ts_login = HTTP::_GP('ts_login', ''); $ts_password = HTTP::_GP('ts_password', '', true); $ts_cron_interval = HTTP::_GP('ts_cron', 0); $config_after = array('ts_timeout' => $ts_timeout, 'ts_modon' => $ts_modon, 'ts_server' => $ts_server, 'ts_tcpport' => $ts_tcpport, 'ts_udpport' => $ts_udpport, 'ts_version' => $ts_version, 'ts_login' => $ts_login, 'ts_password' => $ts_password, 'ts_cron_interval' => $ts_cron_interval); foreach ($config_after as $key => $value) { $config->{$key} = $value; } $config->save(); $sql = "UPDATE %%CRONJOBS%%\n\t\tSET isActive = :isActive, `lock` = NULL, nextTime = 0\n\t\tWHERE name = 'teamspeak';"; Database::get()->update($sql, array(':isActive' => $ts_modon)); $LOG = new Log(3); $LOG->target = 4; $LOG->old = $config_before; $LOG->new = $config_after; $LOG->save(); } $template = new template(); $template->assign_vars(array('se_save_parameters' => $LNG['se_save_parameters'], 'ts_tcpport' => $LNG['ts_tcpport'], 'ts_serverip' => $LNG['ts_serverip'], 'ts_version' => $LNG['ts_version'], 'ts_active' => $LNG['ts_active'], 'ts_settings' => $LNG['ts_settings'], 'ts_udpport' => $LNG['ts_udpport'], 'ts_timeout' => $LNG['ts_timeout'], 'ts_server_query' => $LNG['ts_server_query'], 'ts_sq_login' => $LNG['ts_login'], 'ts_sq_pass' => $LNG['ts_pass'], 'ts_lng_cron' => $LNG['ts_cron'], 'ts_to' => $config->ts_timeout, 'ts_on' => $config->ts_modon, 'ts_ip' => $config->ts_server, 'ts_tcp' => $config->ts_tcpport, 'ts_udp' => $config->ts_udpport, 'ts_v' => $config->ts_version, 'ts_login' => $config->ts_login, 'ts_password' => $config->ts_password, 'ts_cron' => $config->ts_cron_interval)); $template->show('TeamspeakPage.tpl'); }
/** * Create a new instance of the database helper. */ public function __construct() { /** * connect to PDO here. */ $this->db = Database::get(); }
public static function usePermissionCollectionIDForIdentifier() { static $usePermissionsCollectionID; if (!isset($usePermissionsCollectionID)) { // we do this because these five items are known to be OK for caching permissions against // page IDs (well file_uploader is unrelated but we still need to check for it or it will trip this check.) // if these are the only things included in your site then you should be able to use permissionsCollectionID for // checking permissions against, which will dramatically improve performance. // If you have any custom access entities though you won't be able to use this. // Obviously a better way of doing this would be to retrieve all access entity types, run through each and see whether // they support it but this is better for performance. try { $db = \Database::get(); $q = "select pal.paID from PagePermissionAssignments ppa inner join PermissionAccessList pal on (ppa.paID = pal.paID) inner join PermissionAccessEntities pae on pal.peID = pae.peID inner join PermissionAccessEntityTypes paet on pae.petID = paet.petID where paet.petHandle not in ('group', 'user', 'group_set', 'group_combination', 'file_uploader')"; $paID = $db->GetOne($q); if ($paID) { $usePermissionsCollectionID = false; } else { $usePermissionsCollectionID = true; } } catch (\Exception $e) { $usePermissionsCollectionID = false; } } return $usePermissionsCollectionID; }
function view() { global $USER, $LNG; require 'includes/classes/BBCode.class.php'; $db = Database::get(); $ticketID = HTTP::_GP('id', 0); $sql = "SELECT a.*, t.categoryID, t.status FROM %%TICKETS_ANSWER%% a INNER JOIN %%TICKETS%% t USING(ticketID) WHERE a.ticketID = :ticketID ORDER BY a.answerID;"; $answerResult = $db->select($sql, array(':ticketID' => $ticketID)); $answerList = array(); if (empty($answerResult)) { $this->printMessage(sprintf($LNG['ti_not_exist'], $ticketID), array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=ticket'))); } $ticket_status = 0; foreach ($answerResult as $answerRow) { $answerRow['time'] = _date($LNG['php_tdformat'], $answerRow['time'], $USER['timezone']); $answerRow['message'] = BBCode::parse($answerRow['message']); $answerList[$answerRow['answerID']] = $answerRow; if (empty($ticket_status)) { $ticket_status = $answerRow['status']; } } $categoryList = $this->ticketObj->getCategoryList(); $this->assign(array('ticketID' => $ticketID, 'categoryList' => $categoryList, 'answerList' => $answerList, 'status' => $ticket_status)); $this->display('page.ticket.view.tpl'); }
function run() { global $LNG; $config = Config::get(ROOT_UNI); if ($config->mail_active == 1) { /** @var $langObjects Language[] */ $langObjects = array(); require 'includes/classes/Mail.class.php'; $sql = 'SELECT `id`, `username`, `lang`, `email`, `onlinetime`, `timezone`, `universe` FROM %%USERS%% WHERE `inactive_mail` = 0 AND `onlinetime` < :time;'; $inactiveUsers = Database::get()->select($sql, array(':time' => TIMESTAMP - $config->del_user_sendmail * 24 * 60 * 60)); foreach ($inactiveUsers as $user) { if (!isset($langObjects[$user['lang']])) { $langObjects[$user['lang']] = new Language($user['lang']); $langObjects[$user['lang']]->includeData(array('L18N', 'INGAME', 'PUBLIC', 'CUSTOM')); } $userConfig = Config::get($user['universe']); $LNG = $langObjects[$user['lang']]; $MailSubject = sprintf($LNG['spec_mail_inactive_title'], $userConfig->game_name . ' - ' . $userConfig->uni_name); $MailRAW = $LNG->getTemplate('email_inactive'); $MailContent = str_replace(array('{USERNAME}', '{GAMENAME}', '{LASTDATE}', '{HTTPPATH}'), array($user['username'], $userConfig->game_name . ' - ' . $userConfig->uni_name, _date($LNG['php_tdformat'], $user['onlinetime'], $user['timezone']), HTTP_PATH), $MailRAW); Mail::send($user['email'], $user['username'], $MailSubject, $MailContent); $sql = 'UPDATE %%USERS%% SET `inactive_mail` = 1 WHERE `id` = :userId;'; Database::get()->update($sql, array(':userId' => $user['id'])); } } }
function show() { global $PLANET, $LNG, $resource; $this->initTemplate(); $this->setWindow('popup'); $this->tplObj->loadscript('phalanx.js'); $Galaxy = HTTP::_GP('galaxy', 0); $System = HTTP::_GP('system', 0); $Planet = HTTP::_GP('planet', 0); if (!$this->allowPhalanx($Galaxy, $System)) { $this->printMessage($LNG['px_out_of_range']); } if ($PLANET[$resource[903]] < PHALANX_DEUTERIUM) { $this->printMessage($LNG['px_no_deuterium']); } $db = Database::get(); $sql = "UPDATE %%PLANETS%% SET deuterium = deuterium - :phalanxDeuterium WHERE id = :planetID;"; $db->update($sql, array(':phalanxDeuterium' => PHALANX_DEUTERIUM, ':planetID' => $PLANET['id'])); $sql = "SELECT id, name, id_owner FROM %%PLANETS%% WHERE universe = :universe\n\t\tAND galaxy = :galaxy AND system = :system AND planet = :planet AND :type;"; $TargetInfo = $db->selectSingle($sql, array(':universe' => Universe::current(), ':galaxy' => $Galaxy, ':system' => $System, ':planet' => $Planet, ':type' => 1)); if (empty($TargetInfo)) { $this->printMessage($LNG['px_out_of_range']); } require 'includes/classes/class.FlyingFleetsTable.php'; $fleetTableObj = new FlyingFleetsTable(); $fleetTableObj->setPhalanxMode(); $fleetTableObj->setUser($TargetInfo['id_owner']); $fleetTableObj->setPlanet($TargetInfo['id']); $fleetTable = $fleetTableObj->renderTable(); $this->assign(array('galaxy' => $Galaxy, 'system' => $System, 'planet' => $Planet, 'name' => $TargetInfo['name'], 'fleetTable' => $fleetTable)); $this->display('page.phalanx.default.tpl'); }
function send() { global $resource, $USER, $PLANET; if ($USER['urlaubs_modus'] == 0) { $updateSQL = array(); if (!isset($_POST['prod'])) { $_POST['prod'] = array(); } $param = array(':planetId' => $PLANET['id']); foreach ($_POST['prod'] as $resourceId => $Value) { $FieldName = $resource[$resourceId] . '_porcent'; if (!isset($PLANET[$FieldName]) || !in_array($Value, range(0, 10))) { continue; } $updateSQL[] = $FieldName . " = :" . $FieldName; $param[':' . $FieldName] = (int) $Value; $PLANET[$FieldName] = $Value; } if (!empty($updateSQL)) { $sql = 'UPDATE %%PLANETS%% SET ' . implode(', ', $updateSQL) . ' WHERE id = :planetId;'; Database::get()->update($sql, $param); $this->ecoObj->setData($USER, $PLANET); $this->ecoObj->ReBuildCache(); list($USER, $PLANET) = $this->ecoObj->getData(); $PLANET['eco_hash'] = $this->ecoObj->CreateHash(); } } $this->save(); $this->redirectTo('game.php?page=resources'); }
private function getFleets($acsID = false) { if ($this->IsPhalanx) { $where = '(fleet_start_id = :planetId AND fleet_mission != :missionId) OR (fleet_end_id = :planetId AND fleet_mess IN (0, 2))'; $param = array(':planetId' => $this->planetId, ':missionId' => 4); } elseif (!empty($acsID)) { $where = 'fleet_group = :acsId'; $param = array(':acsId' => $acsID); } elseif ($this->missions) { $where = '(fleet_owner = :userId OR fleet_target_owner = :userId) AND fleet_mission IN (' . $this->missions . ')'; $param = array(':userId' => $this->userId); } else { $where = 'fleet_owner = :userId OR (fleet_target_owner = :userId AND fleet_mission != :missionId)'; $param = array(':userId' => $this->userId, ':missionId' => 8); } $sql = 'SELECT DISTINCT fleet.*, ownuser.username as own_username, targetuser.username as target_username, ownplanet.name as own_planetname, targetplanet.name as target_planetname FROM %%FLEETS%% fleet LEFT JOIN %%USERS%% ownuser ON (ownuser.id = fleet.fleet_owner) LEFT JOIN %%USERS%% targetuser ON (targetuser.id = fleet.fleet_target_owner) LEFT JOIN %%PLANETS%% ownplanet ON (ownplanet.id = fleet.fleet_start_id) LEFT JOIN %%PLANETS%% targetplanet ON (targetplanet.id = fleet.fleet_end_id) WHERE ' . $where . ';'; return Database::get()->select($sql, $param); }
function show() { global $USER, $LNG; $order = HTTP::_GP('order', 'units'); $sort = HTTP::_GP('sort', 'desc'); $sort = strtoupper($sort) === "DESC" ? "DESC" : "ASC"; switch ($order) { case 'date': $key = '%%TOPKB%%.time ' . $sort; break; case 'units': default: $key = '%%TOPKB%%.units ' . $sort; break; } $db = Database::get(); $sql = "SELECT *, (\n\t\t\tSELECT DISTINCT\n\t\t\tIF(%%TOPKB_USERS%%.username = '', GROUP_CONCAT(%%USERS%%.username SEPARATOR ' & '), GROUP_CONCAT(%%TOPKB_USERS%%.username SEPARATOR ' & '))\n\t\t\tFROM %%TOPKB_USERS%%\n\t\t\tLEFT JOIN %%USERS%% ON uid = %%USERS%%.id\n\t\t\tWHERE %%TOPKB_USERS%%.rid = %%TOPKB%%.rid AND role = 1\n\t\t) as attacker,\n\t\t(\n\t\t\tSELECT DISTINCT\n\t\t\tIF(%%TOPKB_USERS%%.username = '', GROUP_CONCAT(%%USERS%%.username SEPARATOR ' & '), GROUP_CONCAT(%%TOPKB_USERS%%.username SEPARATOR ' & '))\n\t\t\tFROM %%TOPKB_USERS%% INNER JOIN %%USERS%% ON uid = id\n\t\t\tWHERE %%TOPKB_USERS%%.rid = %%TOPKB%%.`rid` AND `role` = 2\n\t\t) as defender\n\t\tFROM %%TOPKB%% WHERE universe = :universe ORDER BY " . $key . " LIMIT 100;"; $top = $db->select($sql, array(':universe' => Universe::current())); $TopKBList = array(); foreach ($top as $data) { $TopKBList[] = array('result' => $data['result'], 'date' => _date($LNG['php_tdformat'], $data['time'], $USER['timezone']), 'time' => TIMESTAMP - $data['time'], 'units' => $data['units'], 'rid' => $data['rid'], 'attacker' => $data['attacker'], 'defender' => $data['defender']); } $this->assign(array('TopKBList' => $TopKBList, 'sort' => $sort, 'order' => $order)); $this->display('page.battleHall.default.tpl'); }
public function getDisplayValue() { $db = \Database::get(); $q = "select * from TutorialDbTableDemoAttribute where keyID = ?"; $row = $db->getRow($q, array($this->getValue())); $json = new Json(); $jsonData = $json->decode($row['data']); ob_start(); ?> <h4><?php echo $row['displayTitle']; ?> </h4> <dl> <?php foreach ($jsonData as $handle => $value) { ?> <dt><?php echo $handle; ?> </dt> <dd><?php echo $value; ?> </dd> <?php } ?> </dl> <?php return ob_get_clean(); }
function delete_owned_of_turn($turn) { $sql = "DELETE FROM owned WHERE turn = :turn"; $req = Database::get()->prepare($sql); $req->bindValue(':turn', $turn, PDO::PARAM_INT); $req->execute(); }
public function show() { global $USER, $PLANET, $LNG; $this->tplObj->loadscript('flotten.js'); $targetGalaxy = HTTP::_GP('galaxy', 0); $targetSystem = HTTP::_GP('system', 0); $targetPlanet = HTTP::_GP('planet', 0); $targetType = HTTP::_GP('type', 0); $targetMission = HTTP::_GP('target_mission', 0); $fleetSpeed = HTTP::_GP('speed', 0); $fleetGroup = HTTP::_GP('fleet_group', 0); $token = HTTP::_GP('token', ''); if (!isset($_SESSION['fleet'][$token])) { FleetFunctions::GotoFleetPage(); } $fleetArray = $_SESSION['fleet'][$token]['fleet']; $db = Database::get(); $sql = "SELECT id, id_owner, der_metal, der_crystal FROM %%PLANETS%% WHERE universe = :universe AND galaxy = :targetGalaxy AND system = :targetSystem AND planet = :targetPlanet AND planet_type = '1';"; $targetPlanetData = $db->selectSingle($sql, array(':universe' => Universe::current(), ':targetGalaxy' => $targetGalaxy, ':targetSystem' => $targetSystem, ':targetPlanet' => $targetPlanet)); if ($targetType == 2 && $targetPlanetData['der_metal'] == 0 && $targetPlanetData['der_crystal'] == 0) { $this->printMessage($LNG['fl_error_empty_derbis'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1'))); } $MisInfo = array(); $MisInfo['galaxy'] = $targetGalaxy; $MisInfo['system'] = $targetSystem; $MisInfo['planet'] = $targetPlanet; $MisInfo['planettype'] = $targetType; $MisInfo['IsAKS'] = $fleetGroup; $MisInfo['Ship'] = $fleetArray; $MissionOutput = FleetFunctions::GetFleetMissions($USER, $MisInfo, $targetPlanetData); if (empty($MissionOutput['MissionSelector'])) { $this->printMessage($LNG['fl_empty_target'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleet1'))); } $GameSpeedFactor = FleetFunctions::GetGameSpeedFactor(); $MaxFleetSpeed = FleetFunctions::GetFleetMaxSpeed($fleetArray, $USER); $distance = FleetFunctions::GetTargetDistance(array($PLANET['galaxy'], $PLANET['system'], $PLANET['planet']), array($targetGalaxy, $targetSystem, $targetPlanet)); $duration = FleetFunctions::GetMissionDuration($fleetSpeed, $MaxFleetSpeed, $distance, $GameSpeedFactor, $USER); $consumption = FleetFunctions::GetFleetConsumption($fleetArray, $duration, $distance, $USER, $GameSpeedFactor); if ($consumption > $PLANET['deuterium']) { $this->printMessage($LNG['fl_not_enough_deuterium'], array(array('label' => $LNG['sys_back'], 'url' => 'game.php?page=fleetTable'))); } if (!FleetFunctions::CheckUserSpeed($fleetSpeed)) { FleetFunctions::GotoFleetPage(0); } $_SESSION['fleet'][$token]['speed'] = $MaxFleetSpeed; $_SESSION['fleet'][$token]['distance'] = $distance; $_SESSION['fleet'][$token]['targetGalaxy'] = $targetGalaxy; $_SESSION['fleet'][$token]['targetSystem'] = $targetSystem; $_SESSION['fleet'][$token]['targetPlanet'] = $targetPlanet; $_SESSION['fleet'][$token]['targetType'] = $targetType; $_SESSION['fleet'][$token]['fleetGroup'] = $fleetGroup; $_SESSION['fleet'][$token]['fleetSpeed'] = $fleetSpeed; if (!empty($fleet_group)) { $targetMission = 2; } $fleetData = array('fleetroom' => floatToString($_SESSION['fleet'][$token]['fleetRoom']), 'consumption' => floatToString($consumption)); $this->tplObj->execscript('calculateTransportCapacity();'); $this->assign(array('fleetdata' => $fleetData, 'consumption' => floatToString($consumption), 'mission' => $targetMission, 'galaxy' => $PLANET['galaxy'], 'system' => $PLANET['system'], 'planet' => $PLANET['planet'], 'type' => $PLANET['planet_type'], 'MissionSelector' => $MissionOutput['MissionSelector'], 'StaySelector' => $MissionOutput['StayBlock'], 'fl_dm_alert_message' => sprintf($LNG['fl_dm_alert_message'], $LNG['type_mission'][11], $LNG['tech'][921]), 'fl_continue' => $LNG['fl_continue'], 'token' => $token)); $this->display('page.fleetStep2.default.tpl'); }
function run() { $serverData['php'] = PHP_VERSION; try { $sql = 'SELECT register_time FROM %%USERS%% WHERE id = :userId'; $serverData['installSince'] = Database::get()->selectSingle($sql, array(':userId' => ROOT_USER), 'register_time'); } catch (Exception $e) { $serverData['installSince'] = NULL; } try { $sql = 'SELECT COUNT(*) as state FROM %%USERS%%;'; $serverData['users'] = Database::get()->selectSingle($sql, array(), 'state'); } catch (Exception $e) { $serverData['users'] = NULL; } try { $sql = 'SELECT COUNT(*) as state FROM %%CONFIG%%;'; $serverData['unis'] = Database::get()->selectSingle($sql, array(), 'state'); } catch (Exception $e) { $serverData['unis'] = NULL; } $serverData['version'] = Config::get(ROOT_UNI)->VERSION; $ch = curl_init('http://tracking.2moons.cc/'); curl_setopt($ch, CURLOPT_HTTPGET, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $serverData); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; 2Moons/" . $serverData['version'] . "; +http://2moons.cc)"); curl_exec($ch); curl_close($ch); }
/** * display available polls * @global type $course_id * @global type $course_code * @global type $urlServer * @global type $tool_content * @global type $id * @global type $langPollNone * @global type $langQuestionnaire * @global type $langChoice * @global type $langAddModulesButton */ function list_polls() { global $course_id, $course_code, $urlServer, $tool_content, $id, $langPollNone, $langQuestionnaire, $langChoice, $langAddModulesButton; $result = Database::get()->queryArray("SELECT * FROM poll WHERE course_id = ?d AND active = 1", $course_id); $pollinfo = array(); foreach ($result as $row) { $pollinfo[] = array( 'id' => $row->pid, 'title' => $row->name, 'active' => $row->active); } if (count($pollinfo) == 0) { $tool_content .= "<div class='alert alert-warning'>$langPollNone</div>"; } else { $tool_content .= "<form action='insert.php?course=$course_code' method='post'>" . "<input type='hidden' name='id' value='$id'>" . "<table class='table-default'>" . "<tr class='list-header'>" . "<th class='text-left'> $langQuestionnaire</th>" . "<th style='width:20px;' class='text-center'>$langChoice</th>" . "</tr>"; foreach ($pollinfo as $entry) { $tool_content .= "<tr>"; $tool_content .= "<td> ".icon('fa-question')." <a href='${urlServer}modules/questionnaire/pollresults.php?course=$course_code&pid=$entry[id]'>" . q($entry['title']) . "</a></td>"; $tool_content .= "<td class='text-center'><input type='checkbox' name='poll[]' value='$entry[id]'></td>"; $tool_content .= "</tr>"; } $tool_content .= "</table>"; $tool_content .= "<div class='text-right'>"; $tool_content .= "<input class='btn btn-primary' type='submit' name='submit_poll' value='$langAddModulesButton'></div></form>"; } }
function show() { global $USER, $LNG, $reslist; $db = Database::get(); $sql = "SELECT elementID, level, userID, username\n\t\tFROM %%USERS%%\n\t\tINNER JOIN %%RECORDS%% ON userID = id\n\t\tWHERE universe = :universe;"; $recordResult = $db->select($sql, array(':universe' => Universe::current())); $defenseList = array_fill_keys($reslist['defense'], array()); $fleetList = array_fill_keys($reslist['fleet'], array()); $researchList = array_fill_keys($reslist['tech'], array()); $buildList = array_fill_keys($reslist['build'], array()); foreach ($recordResult as $recordRow) { if (in_array($recordRow['elementID'], $reslist['defense'])) { $defenseList[$recordRow['elementID']][] = $recordRow; } elseif (in_array($recordRow['elementID'], $reslist['fleet'])) { $fleetList[$recordRow['elementID']][] = $recordRow; } elseif (in_array($recordRow['elementID'], $reslist['tech'])) { $researchList[$recordRow['elementID']][] = $recordRow; } elseif (in_array($recordRow['elementID'], $reslist['build'])) { $buildList[$recordRow['elementID']][] = $recordRow; } } require_once 'includes/classes/Cronjob.class.php'; $this->assign(array('defenseList' => $defenseList, 'fleetList' => $fleetList, 'researchList' => $researchList, 'buildList' => $buildList, 'update' => _date($LNG['php_tdformat'], Cronjob::getLastExecutionTime('statistic'), $USER['timezone']))); $this->display('page.records.default.tpl'); }
public function getDataSet($fixtures = array()) { $db = Database::get(); if (count($this->tables)) { $partial = new SimpleXMLElement('<schema></schema>'); $partial->addAttribute('version', '0.3'); $xml = simplexml_load_file(DIR_BASE_CORE . '/config/db.xml'); foreach ($xml->table as $t) { $name = (string) $t['name']; if (in_array($name, $this->tables)) { $this->appendXML($partial, $t); } } $schema = \Concrete\Core\Database\Schema\Schema::loadFromXMLElement($partial, $db); $platform = $db->getDatabasePlatform(); $queries = $schema->toSql($platform); foreach ($queries as $query) { $db->query($query); } } if (empty($fixtures)) { $fixtures = $this->fixtures; } $reflectionClass = new ReflectionClass(get_called_class()); $fixturePath = dirname($reflectionClass->getFilename()) . DIRECTORY_SEPARATOR . 'fixtures'; $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array()); foreach ((array) $fixtures as $fixture) { $path = $fixturePath . DIRECTORY_SEPARATOR . "{$fixture}.xml"; $ds = $this->createMySQLXMLDataSet($path); $compositeDs->addDataSet($ds); } return $compositeDs; }
function run() { if (Config::get(ROOT_UNI)->ref_active != 1) { return null; } /** @var $langObjects Language[] */ $langObjects = array(); $db = Database::get(); $sql = 'SELECT `username`, `ref_id`, `id`, `lang`, user.`universe` FROM %%USERS%% user INNER JOIN %%STATPOINTS%% as stats ON stats.`id_owner` = user.`id` AND stats.`stat_type` = :type AND stats.`total_points` >= :points WHERE user.`ref_bonus` = 1;'; $userArray = $db->select($sql, array(':type' => 1, ':points' => Config::get(ROOT_UNI)->ref_minpoints)); foreach ($userArray as $user) { if (!isset($langObjects[$user['lang']])) { $langObjects[$user['lang']] = new Language($user['lang']); $langObjects[$user['lang']]->includeData(array('L18N', 'INGAME', 'TECH', 'CUSTOM')); } $userConfig = Config::get($user['universe']); $LNG = $langObjects[$user['lang']]; $sql = 'UPDATE %%USERS%% SET `darkmatter` = `darkmatter` + :bonus WHERE `id` = :userId;'; $db->update($sql, array(':bonus' => $userConfig->ref_bonus, ':userId' => $user['ref_id'])); $sql = 'UPDATE %%USERS%% SET `ref_bonus` = 0 WHERE `id` = :userId;'; $db->update($sql, array(':userId' => $user['id'])); $Message = sprintf($LNG['sys_refferal_text'], $user['username'], pretty_number($userConfig->ref_minpoints), pretty_number($userConfig->ref_bonus), $LNG['tech'][921]); PlayerUtil::sendMessage($user['ref_id'], '', $LNG['sys_refferal_from'], 4, sprintf($LNG['sys_refferal_title'], $user['username']), $Message, TIMESTAMP); } return true; }
/** * * @global type $id * @global type $course_id * @global type $course_code * @global type $tool_content * @global type $urlServer * @global type $mysqlMainDb * @global type $langAddModulesButton * @global type $langChoice * @global type $langNoEbook * @global type $langEBook * @global type $course_code */ function list_ebooks() { global $id, $course_id, $course_code, $tool_content, $urlServer, $langAddModulesButton, $langChoice, $langNoEBook, $langEBook, $course_code; $result = Database::get()->queryArray("SELECT * FROM ebook WHERE course_id = ?d ORDER BY `order`", $course_id); if (count($result) == 0) { $tool_content .= "<div class='alert alert-warning'>{$langNoEBook}</div>"; } else { $tool_content .= "<form action='insert.php?course={$course_code}' method='post'>\n\t\t\t\t<input type='hidden' name='id' value='{$id}' />" . "<table class='table-default'>" . "<tr>" . "<th class='text-left'> {$langEBook}</th>" . "<th width='80' class='text-center'>{$langChoice}</th>" . "</tr>"; $unit_parameter = 'unit=' . $id; foreach ($result as $catrow) { $tool_content .= "<tr>"; $tool_content .= "<td class='bold'>" . icon('fa-folder-o') . " " . q($catrow->title) . "</td>"; $tool_content .= "<td class='text-center'>\n <input type='checkbox' name='ebook[]' value='{$catrow->id}' />\n <input type='hidden' name='ebook_title[{$catrow->id}]'\n value='" . q($catrow->title) . "'></td>"; $tool_content .= "</tr>"; $q = Database::get()->queryArray("SELECT ebook_section.id AS sid,\n ebook_section.public_id AS psid,\n ebook_section.title AS section_title,\n ebook_subsection.id AS ssid,\n ebook_subsection.public_id AS pssid,\n ebook_subsection.title AS subsection_title,\n document.path,\n document.filename\n FROM ebook, ebook_section, ebook_subsection, document\n WHERE ebook.id = ?d AND\n ebook.course_id = ?d AND\n ebook_section.ebook_id = ebook.id AND\n ebook_section.id = ebook_subsection.section_id AND\n document.id = ebook_subsection.file_id AND\n document.course_id = ?d AND\n document.subsystem = " . EBOOK . "\n ORDER BY CONVERT(psid, UNSIGNED), psid,\n CONVERT(pssid, UNSIGNED), pssid", $catrow->id, $course_id, $course_id); $ebook_url_base = "{$urlServer}modules/ebook/show.php/{$course_code}/{$catrow->id}/"; $old_sid = false; foreach ($q as $row) { $sid = $row->sid; $ssid = $row->ssid; $display_id = $sid . ',' . $ssid; $surl = $ebook_url_base . $display_id . '/' . $unit_parameter; if ($old_sid != $sid) { $tool_content .= "<tr>\n <td class='section'>" . icon('fa-link') . " \n " . q($row->section_title) . "</td>\n <td align='center'><input type='checkbox' name='section[]' value='{$sid}' />\n <input type='hidden' name='section_title[{$sid}]'\n value='" . q($row->section_title) . "'></td></tr>"; } $tool_content .= "<tr>\n <td class='subsection'>" . icon('fa-link') . " \n <a href='" . q($surl) . "' target='_blank'>" . q($row->subsection_title) . "</a></td>\n <td align='center'><input type='checkbox' name='subsection[]' value='{$ssid}' />\n <input type='hidden' name='subsection_title[{$ssid}]'\n value='" . q($row->subsection_title) . "'></td>\n </tr>"; $old_sid = $sid; } } $tool_content .= "<tr>" . "<th colspan='2'><div align='right'>" . "<input class='btn btn-primary' type='submit' name='submit_ebook' value='{$langAddModulesButton}' /></div></th>" . "</tr></table></form>"; } }