Example #1
0
 public function Page($template, $variables, $title, $languageFiles, $extraScripts = '', $showTopNavigation = true, $isInGame = false, $extraMetaTags = '')
 {
     global $NN_config;
     $this->_languageFiles = $languageFiles;
     $currentUser = User::GetCurrentUser();
     $userLevelName = $currentUser->AuthorisationLevelName();
     // Get name of userlevel
     // TODO: have this use $currentUser
     //$userLevelName = Database::Instance()->ExecuteQuery("SELECT name FROM authorisation WHERE level = ".$currentUser->AuthorisationLevel().";","SELECT");
     $resultSet = Database::Instance()->ExecuteQuery("SELECT name FROM authorisation WHERE level = 0;", "SELECT");
     $userLevelName = $resultSet['name'];
     if ($userLevelName == NULL) {
         return null;
     }
     // Load common variables
     $CommonVariables = self::CommonFiles();
     // Render the header, add it to the content
     $this->_content = $this->RenderHeader($CommonVariables, $title, $userLevelName, $extraMetaTags, $extraScripts);
     // If we are in the game, render the side bar
     if ($isInGame) {
         $this->_content .= $this->RenderSidebar($CommonVariables, $userLevelName);
     }
     // If required, render the top navigation bar
     if ($showTopNavigation) {
         // Load navigation variables
         $variables['TODO'] = "add some variables";
     }
     // Render the actual content
     $this->_content .= $this->RenderContent($CommonVariables, $template, $variables, $userLevelName);
     // Render the footer
     $this->_content .= $this->RenderFooter($CommonVariables, $userLevelName);
 }
Example #2
0
 function rearrange($target_id, $before_or_after)
 {
     access::verify_csrf();
     $target = ORM::factory("item", $target_id);
     $album = $target->parent();
     access::required("view", $album);
     access::required("edit", $album);
     $source_ids = $this->input->post("source_ids", array());
     if ($album->sort_column != "weight") {
         $i = 0;
         foreach ($album->children() as $child) {
             // Do this directly in the database to avoid sending notifications
             Database::Instance()->update("items", array("weight" => ++$i), array("id" => $child->id));
         }
         $album->sort_column = "weight";
         $album->sort_order = "ASC";
         $album->save();
         $target->reload();
     }
     // Find the insertion point
     $target_weight = $target->weight;
     if ($before_or_after == "after") {
         $target_weight++;
     }
     // Make a hole
     $count = count($source_ids);
     Database::Instance()->query("UPDATE {items} " . "SET `weight` = `weight` + {$count} " . "WHERE `weight` >= {$target_weight} AND `parent_id` = {$album->id}");
     // Insert source items into the hole
     foreach ($source_ids as $source_id) {
         Database::Instance()->update("items", array("weight" => $target_weight++), array("id" => $source_id));
     }
     module::event("album_rearrange", $album);
     print json_encode(array("grid" => self::_get_micro_thumb_grid($album, 0)->__toString(), "sort_column" => $album->sort_column, "sort_order" => $album->sort_order));
 }
Example #3
0
 public function GetScheduledLevelsInDatabase()
 {
     $type = $this->ID();
     $query = "SELECT SUM(amount_requested) AS total_amount FROM production_building WHERE resource_type_being_built = {$type};";
     $result = Database::Instance()->ExecuteQuery($query, "SELECT");
     if ($result['total_amount'] === NULL) {
         return 0;
     } else {
         return (int) $result['total_amount'];
     }
 }
Example #4
0
 public static function GetDefensesOfColony(Colony $colony)
 {
     $id = $colony->ID();
     $query = "SELECT * FROM colony_defences WHERE colonyID = {$id};";
     $row = Database::Instance()->ExecuteQuery($query, "SELECT");
     $row = array_slice($row, 1);
     // Get rid of colonyID
     // TODO: put these numbers in the config files or game resources,
     // otherwise when you add a new weapon you need to change all these.
     $row = array_slice($row, 0, 8);
     // Get rid of missiles
     return CombatGroup::FromList($row, $colony);
 }
Example #5
0
 public function Work()
 {
     // check for double run
     if ($this->initialized) {
         throw new Exception("Engine already initialized");
     }
     $this->initialized = true;
     // Start buffer
     ob_start();
     // Init self variables
     //$this->Debug($_SERVER, '$_SERVER');
     $this->root = $_SERVER["DOCUMENT_ROOT"];
     // Init autoload classes
     spl_autoload_register([$this, 'AutoloadClass']);
     $this->RegisterModuleClasses('system');
     //$this->Debug($this->classes, '$this->classes');
     // Init database connector
     $requisites = (include $this->DetectFilePath('config/database.php'));
     $this->DB = Database::Instance($requisites);
     //$this->Debug(Database::Instance()->Query('SELECT * FROM user;', 'wef'), '$test');
     // Init user session
     session_start();
     // Check access
     $this->ACCESS = (require $this->FindClosestFile($_SERVER['REQUEST_URI'], '.access.php'));
     // ...
     // Load section info
     $this->SECTION = (require $this->FindClosestFile($_SERVER['REQUEST_URI'], '.section.php'));
     $this->SECTION['NAME'] = $this->SECTION['NAME'] ?: 'Specify section name in .section.php';
     $this->SECTION['TEMPLATE'] = $this->SECTION['TEMPLATE'] ?: 'bootstrap';
     // Init other modules
     // ...
     Modules::Instance()->Synchronize(true);
     $this->LoadModules();
     // Start output CONTENT
     $request_uri = $this->root . $_SERVER['REQUEST_URI'];
     if (file_exists($request_uri) and !is_dir($request_uri)) {
         require $request_uri;
     } elseif (is_dir($request_uri) and file_exists($request_uri . 'index.php')) {
         require $request_uri . 'index.php';
     } else {
         // otherwise require closest controller.php
         require $this->FindClosestFile($_SERVER['REQUEST_URI'], 'controller.php');
     }
     $this->CONTENT = ob_get_clean();
     // Launch wrapper if it needs
     // ...
     require $this->DetectFilePath('templates/' . $this->SECTION['TEMPLATE'] . '/wrapper.php');
     // Do last triggers
     // ...
 }
Example #6
0
 function index()
 {
     $group_category = (int) @$_GET['cat_group_category'];
     $input = Input::Instance();
     $category = new Category();
     $db = Database::Instance();
     $return = array();
     $msgerror = null;
     $searchtxt = $input->get($this->inputtext);
     $liked = array("name_product" => $searchtxt, 'description_product' => $searchtxt);
     $likedstr = " (\n      name_product LIKE '%{$searchtxt}%' OR description_product LIKE '%{$searchtxt}%' OR\n      name_product_en LIKE '%{$searchtxt}%' OR description_product_en LIKE '%{$searchtxt}%'\n    ) ";
     /* Count of Rows */
     $result = $db->select("count(*) as total")->from("product")->where($likedstr);
     if ($group_category > 0) {
         $result = $result->from("product_has_category")->where(array('category_id_category' => $group_category))->where("product_id_product = id_product");
     }
     $result = $result->get();
     foreach ($result as $row) {
         $total = $row->total;
     }
     /* Class Pagination */
     $this->pages = new Pagination(array('base_url' => "" . $this->__("search") . "/items/" . $this->__("page") . "/", 'uri_segment' => 'pagina', 'total_items' => $total, 'items_per_page' => $category->max_items_per_category, 'style' => $category->getstyle_pagination()));
     /* List of Products */
     $result = $db->select("*")->from("product")->orderby(array("update_product" => "DESC"))->where("{$likedstr}")->limit($category->max_items_per_category)->offset($this->pages->sql_offset);
     /*Condition Category group*/
     if ($group_category > 0) {
         $result = $result->from("product_has_category")->where(array('category_id_category' => $group_category))->where("product_id_product = id_product");
     }
     /* Build The Result */
     $result = $result->get();
     foreach ($result as $row) {
         Basic::currency($row->price_product);
         if ($row->price_offer_product > 0) {
             Basic::currency($row->price_offer_product);
             $row->price_product = "<strike>" . $row->price_product . "</strike> {$this->separator_price} " . $row->price_offer_product;
         }
         $row->href_add_product = url::base() . $this->__("cart") . "/" . $this->__("add") . "/id/{$row->id_product}";
         $row->href_detail_product = url::base() . $this->__("product") . "/" . $this->__("detail") . "/" . Basic::urlizar($row->name_product) . "/id/{$row->id_product}";
         $return[] = $row;
     }
     /* Error Detecting */
     if (count($return) < 1 or $searchtxt == null) {
         $return = array();
         $msgerror = __("No se encontraron resultados", false);
         $this->pages = null;
     }
     //     $this->content = View::factory("main/search_list_products")
     $this->title = __('Resultados de la búsqueda', false);
     $this->content = View::factory("main/list_products")->set('product', $return)->set('title', __('Resultados de la búsqueda', false))->set('msgerror', $msgerror)->set('pages', $this->pages)->render();
 }
Example #7
0
 /**
  * Overload ORM::delete() to trigger an item_related_update event for all items that are
  * related to this tag.
  */
 public function delete()
 {
     $related_item_ids = array();
     $db = Database::Instance();
     foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) {
         $related_item_ids[$row->item_id] = 1;
     }
     $result = parent::delete();
     if ($related_item_ids) {
         foreach (ORM::factory("item")->in("id", array_keys($related_item_ids))->find_all() as $item) {
             module::event("item_related_update", $item);
         }
     }
     return $result;
 }
Example #8
0
 public function BuildTime(BuildItem $item)
 {
     // Calculate next build level
     $nextBuildLevel = $this->GetNextBuildLevel($group);
     // Calculate costs
     $buildCosts = $this->BuildCost($group, $nextBuildLevel);
     // Calculate time required
     $colony =& $item->BuildGroup()->Colony();
     $interGalacticLabLevel = $colony->Technologies()->GetMemberByName("intergalactic_research_network_technology")->Amount();
     $researchLabs = 0;
     if ($interGalacticLabLevel > 0) {
         // Get all the research labs from this user
         $userID = $colony->Owner()->ID();
         $query = "SELECT cs.research_lab FROM colony_structures AS cs, colony AS c WHERE cs.colonyID = c.ID AND c.userID = {$userID};";
         $results = Database::Instance()->ExecuteQuery($query, "SELECT");
         $numberOfLabs = 0;
         $labList = array();
         if (isset($results['research_lab'])) {
             // Single result
             $labList[$numberOfLabs] = $results['research_lab'];
         } else {
             // List of results
             foreach ($results as $result) {
                 $labList[$numberOfLabs] = $result['research_lab'];
                 $numberOfLabs++;
             }
         }
         asort($labList);
         // Sort from lowest to highest
         for ($i = 0; $i <= $interGalacticLabLevel; $i++) {
             $researchLabs += $labList[$lab];
         }
     } else {
         $researchLabs = $colony->Buildings()->GetMemberByName("research_lab")->Amount();
     }
     global $NN_config;
     $metalCost =& $buildCosts->Metal();
     $crystalCost =& $buildCosts->Crystal();
     $gameSpeed =& $NN_config["game_speed"];
     $scientists = $colony->Owner()->Officers()->GetMemberByName("scientist")->Amount();
     $timeRequired = ($metalCost + $crystalCost) / $gameSpeed * (1 / ($researchLabs + 1)) * 2;
     $timeRequired = floor($timeRequired * 3600 * (1 - $scientists * 0.1));
     return $timeRequired;
 }
 public function __toString()
 {
     /**
      * poa = product options atributes
      */
     $update_fields = array();
     $db = Database::Instance();
     $uri = Uri::Instance();
     $string = null;
     $tienda_id = (int) $uri->segment("edit");
     if (request::method() == 'post' and is_array(@$_POST['igallery_h'])) {
         $db->query("DELETE FROM product_images where product_id_product = {$tienda_id}");
         $ic = 0;
         if (@$_FILES['igallery'] != "") {
             $arrf = $this->reArrayFiles($_FILES['igallery']);
         }
         foreach ($_POST['igallery_h'] as $value) {
             //         echo Kohana::debug($value);
             //         echo Kohana::debug($arrf[$ic]);
             if (@$arrf[$ic]['name'] != "") {
                 $value = $this->upimg($arrf[$ic]);
             }
             //         echo Kohana::debug($value);
             //         echo "INSERT INTO product_images (product_id_product ,pi_image) VALUES ('$tienda_id','$value')";
             if ($value != "") {
                 try {
                     $db->query("INSERT INTO product_images (product_id_product ,pi_image) VALUES ('{$tienda_id}','{$value}')");
                 } catch (Exception $e) {
                     echo Kohana::debug('Error: ' . "\n" . $e->getMessage() . "\n");
                 }
             }
             $ic++;
         }
     }
     try {
         $r = $db->query("SELECT * FROM product_images WHERE product_id_product = {$tienda_id}");
         $string = View::factory("extras/galleryimage")->set("imgs", $r)->render();
     } catch (Exception $e) {
         echo Kohana::debug('Error: ' . "\n" . $e->getMessage() . "\n");
     }
     return $string;
 }
Example #10
0
 function __construct()
 {
     parent::__construct();
     //           $this->session = Session::instance();
     @session_start();
     $usr = @$_SESSION['usr'];
     $pwd = @$_SESSION['pwd'];
     $p_usr = trim($this->input->post('usr'));
     $p_pwd = $this->_crypt_me(trim($this->input->post('pwd')));
     if (request::method() == 'post' and $p_pwd != '' and $p_usr != '') {
         $usr = trim($this->input->post('usr'));
         $pwd = $this->_crypt_me(trim($this->input->post('pwd')));
     }
     //           echo $usr;
     if ($usr != '' and $pwd != '') {
         $db = Database::Instance();
         $rows = $db->from("admin")->where(array('usr_admin' => $usr, 'pwd_admin' => $pwd))->get();
         $ct = 0;
         foreach ($rows as $row) {
             $ct++;
         }
         if ($ct > 0) {
             $_SESSION['usr'] = $usr;
             $_SESSION['pwd'] = $pwd;
             if (Router::$method != 'panel') {
                 url::redirect("/admin/panel");
             }
         }
     } else {
         if (Router::$method != 'index') {
             url::redirect("/admin/index");
         }
     }
     if ($this->uri->segment('mod') == 'logout') {
         $_SESSION['usr'] = null;
         $_SESSION['pwd'] = null;
         //             fdurl::redirect("/admin/index");
     }
 }
Example #11
0
 public function _index($page)
 {
     # is the page public?
     if ('no' == $page->enable and !$this->client->can_edit($this->site_id)) {
         Event::run('system.404');
     }
     $this->page_id = $page->id;
     $this->page_name = $page->page_name;
     $this->serve_page_cache($this->page_id);
     $this->load_page_css_cache();
     $_SESSION['js_files'] = array();
     $data = array(' ', ' ', ' ', ' ', ' ', ' ');
     $tools_array = array();
     $prepend = '';
     $append = '';
     # plusjade rootsite account hook functionality
     if (ROOTACCOUNT === $this->site_name) {
         $data[1] = $this->plusjade_hook();
     }
     # get the tools on this page.
     #$tools = ORM::factory('tool')->build_page($this->site_id, $page->id);
     $tools = Database::Instance()->query("\n      SELECT *, LOWER(system_tools.name) AS name, system_tools.protected, pages_tools.id AS instance_id\n      FROM pages_tools \n      JOIN tools ON pages_tools.tool_id = tools.id\n      JOIN system_tools ON tools.system_tool_id = system_tools.id\n      WHERE (page_id BETWEEN 1 AND 5 OR page_id = '{$page->id}')\n      AND pages_tools.fk_site = '{$this->site_id}'\n      ORDER BY pages_tools.container, pages_tools.position\n    ");
     # echo kohana::debug($tools); die;
     # populate the data array based on tools.
     if ($tools->count() > 0) {
         foreach ($tools as $tool) {
             # load the tool parent
             $parent = ORM::factory($tool->name)->where('fk_site', $this->site_id)->find($tool->parent_id);
             if ($parent->loaded) {
                 # If Logged in wrap classes around tools for Javascript
                 # TODO: consider this with javascript
                 if ($this->client->can_edit($this->site_id)) {
                     $scope = '5' >= $tool->page_id ? 'global' : 'local';
                     $prepend = '<span id="instance_' . $tool->instance_id . '" class="common_tool_wrapper ' . $scope . '" rel="tool_' . $tool->tool_id . '">';
                     $append = '</span>';
                     # Throw tool into admin panel array
                     $tools_array[$tool->instance_id] = array('instance' => $tool->instance_id, 'tool_id' => $tool->tool_id, 'parent_id' => $tool->parent_id, 'name' => $tool->name, 'name_id' => $tool->system_tool_id, 'scope' => $scope);
                 }
                 # build tool output
                 $c_name = ucfirst($tool->name) . '_Controller';
                 $controller = new $c_name();
                 $output = $controller->_index($parent);
                 $tool_view = "{$prepend}{$output}{$append}";
                 # if we need to build the page_css file get the tool css.
                 if ($this->build_page_css) {
                     if ('yes' == $tool->protected) {
                         # does a theme css template exist?
                         $theme_templates = $this->assets->themes_dir("{$this->theme}/css/tool_templates");
                         if (file_exists("{$theme_templates}/{$parent->type}_{$parent->view}.sass")) {
                             $this->page_css .= Kosass::factory('compact')->compile(file("{$theme_templates}/{$parent->type}_{$parent->view}.sass"));
                         }
                     }
                     # does custom css file exist for tool?
                     $custom_file = "{$this->tool_dir}/{$tool->name}/{$tool->parent_id}/{$parent->type}_{$parent->view}.css";
                     if (file_exists($custom_file)) {
                         $this->page_css .= file_get_contents($custom_file);
                     }
                 }
             } elseif ($this->client->can_edit($this->site_id)) {
                 # show the tool error when logged in.
                 $tool_view = "{$tool->name} with id: {$tool->parent_id} could not be loaded.";
             }
             # Add output to correct container.
             # if page_id <= 5, its not a real page_id = global container.
             (int) ($index = 5 <= $tool->page_id ? $tool->container : $tool->page_id);
             $data[$index] .= $tool_view;
         }
     }
     $this->load_interface($tools_array);
     # cache the css for this page if set.
     if ($this->build_page_css) {
         file_put_contents("{$this->css_cache_dir}/{$page->id}.css", $this->page_css);
     }
     $this->template->title = $page->title;
     $this->template->meta_tags('description', $page->meta);
     $this->template->set_global('this_page_id', $page->id);
     $this->save_page_as = $page->id;
     $this->to_browser($data, $page->template);
 }
 public static function GetListCount(Colony $c)
 {
     $id = $c->ID();
     $query = "SELECT COUNT(colonyID) as count FROM production_building WHERE colonyID = {$id};";
     $result = Database::Instance()->ExecuteQuery($query, "SELECT");
     if ($result == NULL) {
         $count = 0;
     } else {
         $count = $result['count'];
     }
 }
Example #13
0
 public function GetColoniesWithUnfinishedActions()
 {
     $currentTime = time();
     $production = "SELECT DISTINCT colonyID AS id, 0 AS is_defender FROM production WHERE {$currentTime} > scheduled_time;";
     $transports = "SELECT DISTINCT colonyID AS id, 0 AS is_defender FROM scheduled_transports WHERE {$currentTime} > scheduled_time;";
     $expeditions = "SELECT DISTINCT f.colonyID AS id, 0 AS is_defender FROM scheduled_expeditions AS e, fleet AS f WHERE e.fleetID = f.fleetID AND {$currentTime} > scheduled_time;";
     $attackers = "SELECT DISTINCT attackerID, 0 AS is_defender FROM scheduled_battles WHERE {$currentTime} > scheduled_time;";
     $defenders = "SELECT DISTINCT defenderID, 1 AS is_defender FROM scheduled_battles WHERE {$currentTime} > scheduled_time;";
     $results = array();
     $queries = array($production, $transports, $expeditions, $attackers, $defenders);
     foreach ($queries as $query) {
         $results[] = Database::Instance()->ExecuteQuery($query, "SELECT");
     }
     $allColonies = array();
     foreach ($results as $rows) {
         if (is_array($rows) && isset($rows['id'])) {
             // Just one row
             $allColonies[$rows['id']] = $rows['is_defender'];
         } elseif (is_array($rows)) {
             foreach ($rows as $row) {
                 $allColonies[$row['id']] = $row['is_defender'];
             }
         }
     }
     arsort($allColonies);
     // Defenders have to be updated first, so let's sort it like that.
     return array_keys($allColonies);
 }
 public function UpdateDatabase()
 {
     $list = $this->Members();
     $userID = $this->Owner()->ID();
     $changes = $this->Changes();
     $changesNeeded = false;
     $query = "UPDATE user_technology SET ";
     foreach ($list as $technology) {
         if ($changes[$technology->Name()] == true) {
             $query .= $technology->Name() . " = " . $technology->Amount() . ", ";
             $changesNeeded = true;
         }
     }
     if ($changesNeeded) {
         // Lop off last comma
         $query = Helper::lop_off($query, 2);
         $query .= " WHERE userID = {$userID}";
         Database::Instance()->ExecuteQuery($query, "UPDATE");
     }
 }
 public function DeleteItemFromDatabase(BuildItem $item)
 {
     $colonyID = $this->BuildList()->Colony()->ID();
     $type = $item->ID();
     $pos = $item->OldPositionInList();
     $query = "DELETE FROM production WHERE colonyID = {$colonyID} AND resource_type_being_built = {$type} AND build_list_position = {$pos};";
     $result = Database::Instance()->ExecuteQuery($query, "DElETE");
 }
Example #16
0
 public function positions()
 {
     if (empty($_GET['tstml'])) {
         $this->rsp->msg = 'Nothing to Save.';
         $this->rsp->send();
     }
     $db = Database::Instance();
     foreach ($_GET['tstml'] as $position => $id) {
         $db->update('testimonials', array('position' => "{$position}"), "id = '{$id}' AND owner_id = '{$this->owner}->id'");
     }
     $this->rsp->status = 'success';
     $this->rsp->msg = 'Order Saved!';
     $this->rsp->send();
 }
Example #17
0
 public static function ShipyardIsBusyUntil()
 {
     global $NN_config;
     $sFrom = $NN_config["ship_id_range"]["from"];
     $sTo = $NN_config["ship_id_range"]["to"];
     $dFrom = $NN_config["defense_id_range"]["from"];
     $dTo = $NN_config["defense_id_range"]["to"];
     $mFrom = $NN_config["missile_id_range"]["from"];
     $mTo = $NN_config["missile_id_range"]["to"];
     $fromClause = "FROM production WHERE (resource_type_being_built BETWEEN {$sFrom} AND {$sTo} OR \n                                          resource_type_being_built BETWEEN {$dFrom} AND {$dTo} OR \n                                          resource_type_being_built BETWEEN {$mFrom} AND {$mTo})";
     $query = "SELECT MAX(build_list_position) AS pos " . $fromClause . ";";
     $maxPos = Database::Instance()->ExecuteQuery($query, "SELECT");
     if (isset($maxPos['pos'])) {
         $maxPos = $maxPos['pos'];
     } else {
         return array("build_list_position" => 0, "scheduled_time" => 0);
     }
     // TODO: simplify this with an efficient subquery
     $query = "SELECT build_list_position, scheduled_time " . $fromClause . " AND {$maxPos} = build_list_position LIMIT 1;";
     $result = Database::Instance()->ExecuteQuery($query, "SELECT");
     if (isset($result['build_list_position'])) {
         return $result;
     }
     return array("build_list_position" => 0, "scheduled_time" => 0);
 }
Example #18
0
 public static function GetCurrentUser()
 {
     if (isset($_SESSION['NewNovaID'])) {
         $query = Database::Instance()->ExecuteQuery("SELECT * FROM user WHERE ID = " . $_SESSION['NewNovaID'], "SELECT");
         return User::FromDatabase($query);
     } else {
         throw new Exception("NewNovaID wasn't set in the session variables, can't call User::GetCurrentUser!");
     }
 }
Example #19
0
 private function RenderFooter()
 {
     // "X plants inhabited" text
     $galaxy = $this->_coords->Galaxy();
     $system = $this->_coords->System();
     $query = "SELECT COUNT(ID) AS count FROM colony WHERE galaxy_position = {$galaxy} AND system_position = {$system};";
     $result = Database::Instance()->ExecuteQuery($query, "SELECT");
     if ($result['count'] == 1) {
         $planetsInhabited = $result['count'] . " " . $this->_text['single_planet_inhabited'];
     } else {
         $planetsInhabited = $result['count'] . " " . $this->_text['several_planets_inhabited'];
     }
     $footerData['planets_inhabited'] = $planetsInhabited;
     // Calculate position of outer space
     global $NN_config;
     $footerData['outer_space_pos'] = $NN_config["max_planets"] + 1;
     $footerData['legend'] = "Legend";
     // TODO: Placeholder
     $footerData['missiles_available'] = 0;
     // TODO: implement missiles // $c->Missiles()->Amount();
     $footerData['fleet_slots_available'] = 0;
     // TODO: implement fleet slots
     $footerData['fleet_slots_total'] = 0;
     // TODO: implement fleet slots
     $c = $this->_user->CurrentColony();
     $footerData['recyclers_available'] = $c->Fleet()->GetMemberByName("recycler")->Amount();
     $footerData['espionage_probes_available'] = $c->Fleet()->GetMemberByName("espionage_probe")->Amount();
     $vars = array_merge($footerData, $this->_text);
     return Page::StaticRender("galaxy/galaxy_footer", $vars, $this->_user->AuthorisationLevelName());
 }
 public static function SliderRandom($quantity = 8)
 {
     $db = Database::Instance();
     $q = $db->select("*")->from("product")->orderby(NULL, 'RAND()')->get();
     $html = View::factory("extras/product/slider_product")->set("products", $q);
     return $html;
 }
Example #21
0
include "root.inc";
require_once "{$ROOT}/common.php";
if (!$_POST) {
    // Display the page.
    $conditionalVariables['login_display_error'] = 'none';
} else {
    // Register a new user with form data
    $username = Database::Instance()->EscapeString($_POST['username']);
    $password = Database::Instance()->EscapeString($_POST['password']);
    $email = Database::Instance()->EscapeString($_POST['email']);
    $secondaryEmail = Database::Instance()->EscapeString($_POST['secondary_email']);
    if ($secondaryEmail == "") {
        $secondaryEmail = $email;
    }
    $planetName = Database::Instance()->EscapeString($_POST['planet_name']);
    if ($planetName == "") {
        $planetName = "Colony";
    }
    // TODO: localize this?
    // Create new user, is automatically added to database
    $user = User::NewUser($username, $password, 0, $email, $secondaryEmail, $planetName);
    if ($user) {
        // Set this user as the current user.
        $user->SetAsCurrentUser();
        $page = new Page("registration_complete", NULL, "Registration Complete", "account_activation");
        echo $page->Display();
        return;
    } else {
        // Display the page, with an error message
        $conditionalVariables['login_display_error'] = 'block';
 public function DeleteFromDatabase()
 {
     $query = "DELETE FROM scheduled_transports WHERE transportID = " . $this->ID() . ";";
     $res1 = Database::Instance()->ExecuteQuery($query, "DELETE");
     $query = "DELETE FROM fleet WHERE fleetID = " . $this->Fleet()->ID() . ";";
     $res2 = Database::Instance()->ExecuteQuery($query, "DELETE");
     return $res1 && $res2;
 }
Example #23
0
 public function UpdateResources()
 {
     //Set up a query
     $query = "UPDATE colony_resources SET metal_available = " . $this->_currentresources->Metal() . ", crystal_available = " . $this->_currentresources->Crystal() . ", deuterium_available = " . $this->_currentresources->Deuterium() . " WHERE colonyID = " . $this->_id . ";";
     //Update database
     Database::Instance()->ExecuteQuery($query, "UPDATE");
 }
Example #24
0
 public function __construct()
 {
     $this->DB = Database::Instance();
     $this->code = strtolower(implode('_', array_filter(explode('\\', static::class))));
     $this->Init();
     $this->ProvideIntegrity();
 }
Example #25
0
 public function DataTable($query, $block, $prefix = null, $toggles = null, $reactor = null)
 {
     $i = 0;
     $db = Database::Instance();
     $sqlquery = $db::Query($query);
     $this->StartLoop($block);
     while ($row = $db::Fetch($sqlquery)) {
         $a = array();
         if ($row !== false and is_array($row)) {
             $i++;
             foreach ($row as $var => $val) {
                 if ($prefix !== null) {
                     $var = $prefix . '.' . $var;
                 }
                 $a[$var] = $val;
             }
         }
         if ($toggles !== null) {
             foreach ($toggles as $var => $val) {
                 if (isset($row[$val])) {
                     while (($block = $this->FetchBlock($var, $this->loop['iteration'])) !== false) {
                         $innerblock = $this->FetchBlock($row[$val], $block);
                         $this->loop['iteration'] = str_replace($block, $this->Clean($innerblock), $this->loop['iteration']);
                     }
                 }
             }
         }
         $this->AffectLoop($a, null, $reactor);
         $this->IterateLoop();
     }
     $this->CommitLoop();
     return array('count' => $i, 'last' => $row);
 }
Example #26
0
                $pos = $_GET['build_position'];
                $action = new UserAction($user);
                // Check if we want to delete the first item
                $firstItem = false;
                $visualPos = $_GET['viewposition'];
                if ($visualPos == 1) {
                    $firstItem = true;
                }
                // Only recalculate commissioned time when first item is deleted
                $action->CancelBuildings(array($itemName), array($pos), $firstItem);
                break;
            case "update":
                $id = $_GET['building'];
                $itemName = ResourceParser::Instance()->GetItemNameByID($id);
                $pos = $_GET['position'];
                Database::Instance()->SetDebugging(true);
                // Tap into the Think function and override it for a second
                Think::Instance()->OverrideUser($user);
                Think::Instance()->ConstructBuildingsOf($user->CurrentColony());
                Think::Instance()->ReturnControl();
                break;
            case "reorder":
                $rows = explode("_", $_GET['rows']);
                $rb = ResourceBuilder::GetBuildingListOfColony($user->CurrentColony(), false);
                $rb->BuildList()->Reorder($rows);
                $rb->BuildList()->UpdateDatabase();
                break;
        }
    }
}
// Render new buildings page
 public function UpdateDatabase()
 {
     $list = $this->Members();
     $colonyID = $this->Colony()->ID();
     $changesNeeded = false;
     $query = "UPDATE colony SET ";
     foreach ($list as $building) {
         $query .= $building->Name() . " = " . $building->Amount() . ", ";
         $changesNeeded = true;
     }
     if ($changesNeeded) {
         // Lop off last comma
         $query = Helper::lop_off($query, 2);
         $query .= " WHERE userID = {$userID}";
         Database::Instance()->ExecuteQuery($query, "UPDATE");
     }
 }
Example #28
0
 public function rateit()
 {
     $db = Database::Instance();
     //$ip = basics::getIP();
     $user_id = $_SESSION['conf']['client']['id'];
     $r = $db->query("SELECT * FROM product_rate WHERE product_id = " . $_POST['product_id'] . " AND user_id= '" . $user_id . "'");
     $data = array('product_id' => $_POST['product_id'], 'rate' => $_POST['rateit_value'], 'user_id' => $user_id);
     if (@count($r) == 0) {
         $db->insert('product_rate', $data);
     } else {
         $db->update('product_rate', $data, array('product_id' => $_POST['product_id'], 'user_id' => $user_id));
     }
     echo true;
 }
Example #29
0
<?php

require_once "controller/classMasterController.php";
require_once "classes/classDatabase.php";
ini_set("DISPLAY_ERRORS", "1");
error_reporting(E_ALL);
$conn = Database::Instance();
$data = $conn->select("SELECT * FROM products");
echo '<pre>';
var_dump($conn);
echo '</pre>';
Example #30
0
 public function UpdateDatabase($updateOnlyMissionType = false)
 {
     $query = "UPDATE fleet SET";
     // Mission type
     $query .= " mission_type = " . $this->MissionType();
     if (!$updateOnlyMissionType) {
         // Cargo
         $query .= ", metal_in_cargo = " . $this->Cargo()->Metal();
         $query .= ", crystal_in_cargo = " . $this->Cargo()->Crystal();
         $query .= ", deuterium_in_cargo = " . $this->Cargo()->Deuterium();
         // Ships
         foreach ($this->Members() as $ship) {
             $query .= ", " . $ship->Name() . " = " . $ship->Amount();
         }
     }
     $query .= " WHERE fleetID = " . $this->ID() . ";";
     return Database::Instance()->ExecuteQuery($query, "UPDATE");
 }