public function _check_table_order()
 {
     $dbhelper = new DatabaseHelper('1.0.1');
     $dbhelper->setTableName($this->table);
     $column = array('id' => array('type' => 'bigint', 'length' => 9, 'AUTO_INCREMENT' => true), 'order_item_id' => array('type' => 'INT', 'length' => 255), 'type' => array('type' => 'varchar', 'length' => 255), 'check_in' => array('type' => 'varchar', 'length' => 255), 'check_out' => array('type' => 'varchar', 'length' => 255), 'st_booking_post_type' => array('type' => 'varchar', 'length' => 255), 'st_booking_id' => array('type' => 'INT'), 'duration' => array('type' => 'varchar', 'length' => 255), 'adult_number' => array('type' => 'varchar', 'length' => 255), 'child_number' => array('type' => 'varchar', 'length' => 255), 'infant_number' => array('type' => 'varchar', 'length' => 255), 'discount' => array('type' => 'varchar', 'length' => 255), 'room_id' => array('type' => 'varchar', 'length' => 255), 'room_num_search' => array('type' => 'varchar', 'length' => 255), 'check_in_timestamp' => array('type' => 'varchar', 'length' => 255), 'check_out_timestamp' => array('type' => 'varchar', 'length' => 255), 'status' => array('type' => 'varchar', 'length' => 255), 'wc_order_id' => array('type' => 'INT'), 'user_id' => array('type' => 'INT'), 'partner_id' => array('type' => 'INT'), 'created' => array('type' => 'date'), 'commission' => array('type' => 'varchar', 'length' => 255), 'total_order' => array('type' => 'varchar', 'length' => 255), 'origin_id' => array('type' => 'INT'));
     $dbhelper->setDefaultColums($column);
     $dbhelper->check_meta_table_is_working('neworder_table_version');
 }
 public function _check_table_availability()
 {
     $dbhelper = new DatabaseHelper('1.0.0');
     $dbhelper->setTableName($this->table);
     $column = array('id' => array('type' => 'bigint', 'length' => 9, 'AUTO_INCREMENT' => TRUE), 'post_id' => array('type' => 'INT'), 'post_type' => array('type' => 'varchar', 'length' => 255), 'check_in' => array('type' => 'varchar', 'length' => 255), 'check_out' => array('type' => 'varchar', 'length' => 255), 'number' => array('type' => 'varchar', 'length' => 255), 'price' => array('type' => 'varchar', 'length' => 255), 'adult_price' => array('type' => 'varchar', 'length' => 255), 'child_price' => array('type' => 'varchar', 'length' => 255), 'infant_price' => array('type' => 'varchar', 'length' => 255), 'status' => array('type' => 'varchar', 'length' => 255), 'groupday' => array('type' => 'INT'), 'priority' => array('type' => 'INT'));
     $this->column = $column;
     $dbhelper->setDefaultColums($column);
     $dbhelper->check_meta_table_is_working('availability_table_version');
 }
Ejemplo n.º 3
0
 private function loadAllReceiptIdsOrderByDate()
 {
     $databaseHelper = new DatabaseHelper();
     $this->allReceiptIdsOrderByDate = array();
     $receiptIdsDb = $databaseHelper->query("SELECT `id` FROM `receipt` ORDER BY `timestamp` DESC");
     if (count($receiptIdsDb) > 0) {
         foreach ($receiptIdsDb as $receiptIdDb) {
             $this->allReceiptIdsOrderByDate[] = $receiptIdDb['id'];
         }
     }
 }
Ejemplo n.º 4
0
 public static function fromID($id)
 {
     $sql = "SELECT *, COALESCE(release_date, created_date) AS \"date\" FROM articles WHERE id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $id);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     if ($res == false) {
         throw new Exception("Impossible de trouver cet article", 404);
     }
     $instance = new Article($res["id"], $res["title"], $res["summary"], $res["content"], null, null);
     $instance->_author = User::fromID($res["author_id"]);
     $instance->_categories = array();
     $instance->_date = $res["date"];
     $instance->_published = $res["published"];
     $instance->_last_modified_date = $res["last_modified_date"];
     $instance->_comment_fb_url = DOMAIN_NAME . WEBAPP_WEBSITE_URL . "news/" . $instance->_id;
     $instance->_comments = $instance->queryCommentsCount();
     // Get the count of articles.
     $sql = "SELECT * FROM categories INNER JOIN articles_categories ON (articles_categories.category_id = categories.id) WHERE article_id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $id);
     $sth->execute();
     while ($row = $sth->fetch()) {
         array_push($instance->_categories, $row);
     }
     return $instance;
 }
Ejemplo n.º 5
0
 /**
  * Grab all the articles
  */
 private static function cycleThroughAllArticles()
 {
     $csv = fopen(self::CSV_FILE, 'a');
     if (!$csv) {
         print "error: opening a file\n";
         exit;
     }
     fputcsv($csv, array('url', 'type', 'old', 'new'), chr(9));
     $res = DatabaseHelper::batchSelect('page', array('page_title'), array('page_namespace' => NS_MAIN, 'page_is_redirect' => 0));
     print 'articles: ' . count($res) . "\n";
     $count = 0;
     $num = 1;
     foreach ($res as $row) {
         //print $num.' - ';
         $title = Title::newFromRow($row);
         if ($title) {
             //print $title->getDBKey();
             if (self::processSubheaders($title, $csv)) {
                 $count++;
             }
             if ($count >= 5000) {
                 break;
             }
         }
         //print "\n";
         $num++;
     }
     print "\nchanged: " . $count . "\n";
     return;
 }
Ejemplo n.º 6
0
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new DatabaseHelper();
     }
     return self::$_instance;
 }
Ejemplo n.º 7
0
 public static function getInstance()
 {
     if (self::$__singleton == null) {
         $dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_AUTH_DBNAME . "";
         self::$__singleton = new PDO($dsn, DB_AUTH_USERNAME, DB_AUTH_PASSWORD);
     }
     return self::$__singleton;
 }
Ejemplo n.º 8
0
 function build($tpl)
 {
     $page = isset($_REQUEST["page"]) ? intval($_REQUEST["page"]) : 1;
     $categ = isset($_REQUEST["category"]) ? $_REQUEST["category"] : "developer|gaming";
     $categories = explode("|", $categ);
     $conditions = "";
     if (count($categories) > 0) {
         $conditions = $conditions . " WHERE (";
         for ($i = 0; $i < count($categories); $i++) {
             $conditions = $conditions . "categories.label LIKE ?";
             if ($i < count($categories) - 1) {
                 $conditions = $conditions . " OR ";
             }
         }
         $conditions = $conditions . ")";
     }
     if (isset($_REQUEST["author"])) {
         if ($conditions != "") {
             $conditions = $conditions . " AND username LIKE ?";
         } else {
             $conditions = $conditions . " WHERE username LIKE ?";
         }
     }
     $conditions = $conditions . " GROUP BY published_articles.id ORDER BY published_articles.published_date DESC";
     if (isset($_REQUEST["author"])) {
         array_push($categories, $_REQUEST["author"]);
     }
     // Query the count of elements.
     $sqlCount = "SELECT COUNT(published_articles.id) AS count FROM published_articles " . "INNER JOIN articles_categories ON (published_articles.id" . " = articles_categories.article_id) INNER JOIN categories " . "ON (categories.id = articles_categories.category_id) INNER" . " JOIN users ON (users.id = published_articles.author_id)" . $conditions;
     $sthCount = DatabaseHelper::getInstance()->prepare($sqlCount);
     $sthCount->execute($categories);
     $resCount = $sthCount->fetch(PDO::FETCH_ASSOC);
     $countArticles = $resCount["count"];
     // Compute the number of articles.
     $pageCount = intval($countArticles / 5);
     // Now query the IDs for the current page only.
     $offset = intval(($page - 1) * 5);
     $sql = "SELECT published_articles.id AS id FROM published_articles " . "INNER JOIN articles_categories ON (published_articles.id" . " = articles_categories.article_id) INNER JOIN categories " . "ON (categories.id = articles_categories.category_id) INNER" . " JOIN users ON (users.id = published_articles.author_id)" . $conditions . " LIMIT 5 OFFSET {$offset}";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute($categories);
     $articles = array();
     while ($row = $sth->fetch()) {
         $articleID = $row["id"];
         $articleObj = Article::fromID($articleID);
         $data = $articleObj->getProperties();
         if ($data["published"] == 0) {
             continue;
         }
         array_push($articles, $data);
     }
     $pageLink = isset($_REQUEST["category"]) ? "?category=" . $_REQUEST["category"] . "&" : "?";
     $tpl->assign("articles", $articles);
     $tpl->assign("pageLink", $pageLink);
     $tpl->assign("pageCount", $pageCount);
     $tpl->assign("pageIndex", $page);
     $tpl->display('news-list.tpl');
 }
Ejemplo n.º 9
0
function addAll404Redirects()
{
    $rows = DatabaseHelper::batchSelect('page', array('page_title', 'page_id'), array('page_namespace' => NS_MAIN, 'page_is_redirect' => 0), __METHOD__);
    foreach ($rows as $row) {
        $title = Title::newFromDBkey($row->page_title);
        if ($title) {
            Misc::modify404Redirect($row->page_id, $title);
        }
    }
}
Ejemplo n.º 10
0
 function __construct()
 {
     $sql = "SELECT *, COALESCE(release_date, created_date) AS \"date\" FROM published_articles";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $this->_articles = array();
     while ($row = $sth->fetch()) {
         array_push($this->_articles, $row);
     }
 }
Ejemplo n.º 11
0
 function build($tpl)
 {
     $sql = "SELECT * FROM articles";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $articles = array();
     while ($row = $sth->fetch()) {
         array_push($articles, $row);
     }
     $tpl->assign("articles", $articles);
 }
Ejemplo n.º 12
0
 function prepareDataForLeftPanel()
 {
     $sql = "SELECT * FROM published_articles ORDER BY published_date DESC LIMIT 5";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $lastArticles = array();
     while ($row = $sth->fetch()) {
         $row["title"] = strlen($row["title"]) > 40 ? substr($row["title"], 0, 40) . "..." : $row["title"];
         array_push($lastArticles, $row);
     }
     $this->_lastArticles = $lastArticles;
 }
Ejemplo n.º 13
0
 /**
  * Performs a query to the database and returns the representing list of objects
  *
  * This method will run the query and then build the list of objects that represent
  * the records of the table. It will also init the objects with the basic properties
  * like the reference to the global App object
  *
  * @param string $query The query to perform
  *
  * @return array The list of objects representing the records
  */
 protected function _queryObjectList($query)
 {
     // query database
     $result = $this->database->query($query);
     // fetch objects and execute init callback
     $objects = array();
     while ($object = $this->database->fetchObject($result, $this->class)) {
         $objects[$object->{$this->key}] = $this->_initObject($object);
     }
     $this->database->freeResult($result);
     return $objects;
 }
Ejemplo n.º 14
0
 /**
  * @param  null | int $ritem
  * @return bool
  */
 protected function _addRelation($ritem = null)
 {
     $query = $this->db->getQuery(true);
     // get items
     $query->select('id, params')->from('#__zoo_relateditemsproxref')->where('item_id = ' . (int) $ritem)->where('ritem_id =' . (int) $this->_item->id)->where('element_id=' . $this->db->Quote($this->_identifier));
     $existing = $this->db->setQuery($query)->loadAssoc();
     $params = $this->_item->params->get('relateditemspro.', array());
     $params = json_encode($params);
     // If params are not the same
     if (isset($existing) && array_key_exists('params', $existing) && @$existing['params'] != $params) {
         // remove relation so we can reinsert it with the right params
         $query->clear()->delete('#__zoo_relateditemsproxref')->where('item_id = ' . (int) $ritem)->where('ritem_id =' . (int) $this->_item->id)->where('element_id=' . $this->db->Quote($this->_identifier));
         $this->db->setQuery($query)->execute();
     }
     // If the relation wasn't existing or the params weren't the same
     if (!$existing || @$existing['params'] != $params) {
         // add relation if entry does not exist
         $query->insert('#__zoo_relateditemsproxref')->set('item_id = ' . (int) $ritem)->set('ritem_id = ' . (int) $this->_item->id)->set('element_id= ' . $this->db->Quote($this->_identifier))->set('params = ' . $this->db->Quote($params));
         $this->db->setQuery($query)->execute();
     }
     return true;
 }
Ejemplo n.º 15
0
 static function createSimpleRide($from, $to, $status, $notify = 1, $region = 1)
 {
     $db = DatabaseHelper::getInstance();
     $testContact = $db->addContact('test' . self::$ridesCounter, '1234', 'test' . self::$ridesCounter . '@test.com', ROLE_IDENTIFIED_REGISTERED);
     if (!$testContact) {
         return false;
     }
     $testRide = $db->addRide($from, 'city_' . $from, $to, 'city_' . $to, TIME_IRRELEVANT, TIME_IRRELEVANT, $testContact, '', $status, $notify, $region);
     if (!$testRide) {
         return false;
     }
     ++self::$ridesCounter;
     return $testRide;
 }
Ejemplo n.º 16
0
 /**
  * @param       $tableName
  * @param array $tblFields
  * @param array $tblIndex
  * @return $this
  */
 public function createTable($tableName, array $tblFields, array $tblIndex)
 {
     $params = array_merge($tblFields, $tblIndex);
     if (empty($params)) {
         return $this;
     }
     $sql = array();
     $sql[] = 'CREATE TABLE IF NOT EXISTS `' . $tableName . '`';
     $sql[] = '(' . implode(",\n ", $params) . ')';
     $sql[] = 'COLLATE=\'utf8_general_ci\' ENGINE=MyISAM;';
     $sqlString = implode(' ', $sql);
     $this->_db->query($sqlString);
     return $this;
 }
 function testSuccessLogonNewUser()
 {
     TestUtils::clearDatabase();
     $id = DatabaseHelper::getInstance()->addContact('user2', '', '*****@*****.**', ROLE_IDENTIFIED, Utils::hashPassword('---longpassword123---'));
     // First let's fail
     $params1 = array('email' => '*****@*****.**', 'password' => '---longpassword12---');
     $this->assertFalse($this->helper->authenticate($params1));
     // This should work
     $params2 = array('email' => '*****@*****.**', 'password' => '---longpassword123---');
     $contact = $this->helper->authenticate($params2);
     $this->assertTrue($contact !== false);
     $this->assertEquals($id, $contact['Id']);
     $this->assertEquals(ROLE_IDENTIFIED, $contact['Role']);
 }
 function authenticate($params)
 {
     assert(isset($params['user']) && isset($params['pass']));
     $contactId = $params['user'];
     $token = $params['pass'];
     $contact = DatabaseHelper::getInstance()->getContactByIdentifier($contactId, $identifier);
     if ($contact) {
         info(__METHOD__ . ': Contact ' . $contact['Id'] . ' succesfully authenticated');
         return array('Id' => $contact['Id'], 'Role' => $contact['Role']);
     } else {
         warn(__METHOD__ . ': Authentication failed for contact "' . $contactId . '" and token "' . $identifier . '"');
         return false;
     }
 }
Ejemplo n.º 19
0
 function build($tpl)
 {
     $sql = "SELECT a.id, (SELECT COUNT(*) FROM published_articles WHERE author_id = a.id) AS articles_count FROM users a";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $users = array();
     while ($row = $sth->fetch()) {
         $user = User::fromID($row["id"]);
         $data = $user->getProperties();
         $data["icon"] = WEBAPP_WEBSITE_URL . "upload/bc6cea68f3a413d20d17202cb67b03d2.jpg";
         $data["articles_count"] = $row["articles_count"];
         array_push($users, $data);
     }
     $tpl->assign("users", $users);
     $tpl->display('users-list.tpl');
 }
Ejemplo n.º 20
0
 /**
  * @param        $data
  * @param        $table
  * @param null   $keyId
  * @param string $keyField
  * @return bool|mixed
  */
 protected function _update($data, $table, $keyId = null, $keyField = 'id')
 {
     if (empty($data)) {
         return false;
     }
     $keyId = $keyId ? $keyId : $data['id'];
     if (isset($data[$keyField])) {
         unset($data[$keyField]);
     }
     $sql = $this->_getSelect()->update($table)->where($keyField . ' = ?', $keyId);
     foreach ($data as $key => $value) {
         $value = is_null($value) ? 'NULL' : $this->_quote($value);
         $sql->set('`' . $key . '` = ' . $value);
     }
     return $this->_dbHelper->query((string) $sql);
 }
 function testFindRidesToNotify()
 {
     TestUtils::clearDatabase();
     $ride1 = TestUtils::createSimpleRide(1, 2, STATUS_LOOKING, 1);
     $ride2 = TestUtils::createSimpleRide(3, 4, STATUS_LOOKING, 0);
     $ride3 = TestUtils::createSimpleRide(1, 2, STATUS_OFFERED, 1);
     $ride4 = TestUtils::createSimpleRide(3, 4, STATUS_OFFERED, 0);
     $ride5 = TestUtils::createSimpleRide(5, 6, STATUS_LOOKING, 0);
     DatabaseHelper::getInstance()->updateRideActive($ride5, RIDE_INACTIVE);
     $ride6 = TestUtils::createSimpleRide(5, 6, STATUS_SHARING, 1);
     $toNotify = Service_ShowInterest::findRidesToNotify(STATUS_LOOKING, 1);
     $this->assertRidesContainIds($toNotify, array($ride1));
     $toNotify = Service_ShowInterest::findRidesToNotify(STATUS_OFFERED, 1);
     $this->assertRidesContainIds($toNotify, array($ride3));
     $toNotify = Service_ShowInterest::findRidesToNotify(STATUS_SHARING, 1);
     $this->assertRidesContainIds($toNotify, array($ride6));
 }
Ejemplo n.º 22
0
 function build($tpl)
 {
     $articleID = $_GET["id"];
     $sql = "SELECT * FROM articles WHERE id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $articleID);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     $res["release_date"] = $res["release_date"] == NULL ? NULL : date("Y-m-d\\TH:i", strtotime($res["release_date"]));
     $sql = "SELECT *, (SELECT COUNT(*) FROM articles_categories AS b WHERE b.category_id = a.id AND b.article_id = ?) AS checked FROM categories a";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $articleID);
     $sth->execute();
     $categories = $sth->fetchAll();
     $tpl->assign("categories", $categories);
     $tpl->assign("article", $res);
 }
Ejemplo n.º 23
0
 function build($tpl)
 {
     $sql = "SELECT id FROM users WHERE username LIKE ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $_GET["name"]);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     $user = User::fromID($res["id"]);
     $arr = $user->getProperties();
     // Query the number of articles.
     $sql = "SELECT COUNT(*) AS count FROM published_articles INNER JOIN users ON (published_articles.author_id = users.id) WHERE published = 1";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     $arr["articles_count"] = $res["count"];
     $tpl->assign("userInfo", $arr);
     $tpl->display('users-view.tpl');
 }
Ejemplo n.º 24
0
 public static function run($contactId)
 {
     $db = DatabaseHelper::getInstance();
     try {
         $db->beginTransaction();
         if (!$db->deleteRideByContact($contactId)) {
             throw new Exception("Could not delete rides for contact {$contact}`Id");
         }
         if (!$db->deleteContact($contactId)) {
             throw new Exception("Could not delete contact {$contactId}");
         }
         $db->commit();
         AuthHandler::logout();
     } catch (Exception $e) {
         logException($e);
         $db->rollBack();
         throw $e;
     }
 }
Ejemplo n.º 25
0
 public function testGetRegionConfigration()
 {
     DatabaseHelper::getConnection()->query('DELETE FROM Regions');
     $this->dbh->insert('Regions', array('Name' => 'Region1', 'Abbrev' => 'rg1', 'DefaultSrcCityId' => 1, 'DefaultSrcLocation' => 'DefaultSrc1'));
     $id = DatabaseHelper::getConnection()->lastInsertId();
     $conf = $this->dbh->getRegionConfiguration($id);
     $this->assertNotNull($conf);
     $this->assertEquals(1, $conf['DefaultSrcCityId']);
     $this->assertEquals('DefaultSrc1', $conf['DefaultSrcLocation']);
     $this->assertNull($conf['DefaultDestLocation']);
     $this->dbh->insert('Regions', array('Name' => 'Region2', 'Abbrev' => 'rg2', 'DefaultSrcCityId' => 71, 'DefaultSrcLocation' => 'DefaultSrc2', 'DefaultDestCityId' => 70, 'DefaultDestLocation' => 'DefaultDest2'));
     $id = DatabaseHelper::getConnection()->lastInsertId();
     $conf = $this->dbh->getRegionConfiguration($id);
     $this->assertNotNull($conf);
     $this->assertEquals(71, $conf['DefaultSrcCityId']);
     $this->assertEquals('DefaultSrc2', $conf['DefaultSrcLocation']);
     $this->assertEquals(70, $conf['DefaultDestCityId']);
     $this->assertEquals('DefaultDest2', $conf['DefaultDestLocation']);
 }
Ejemplo n.º 26
0
 function authenticate($params)
 {
     assert('isset($params["user"]) && isset($params["password"])');
     $con = false;
     if (($domain = getConfiguration('auth.ldap.domain')) !== false) {
         $port = (int) getConfiguration('auth.ldap.port', self::LDAP_DEFAULT_PORT);
         $con = ldap_connect($domain, $port);
     }
     if ($con === false) {
         throw new Exception(__METHOD__ . ": Failed to connect to {$domain} in port {$port}");
     }
     $authUser = $user = $this->ldap_escape($params['user']);
     $pass = $this->ldap_escape($params['password']);
     $ldapDomainName = getConfiguration('auth.ldap.domain.name');
     if ($ldapDomainName) {
         $authUser = $ldapDomainName . '\\' . $authUser;
     }
     debug(__METHOD__ . ": Trying to authenticate {$authUser} against {$domain}");
     if (ldap_bind($con, $authUser, $pass)) {
         // We're assuming that the email used is as the user name
         $email = $email = Utils::buildEmail($user);
         // Close the connection - we don't need it any more
         ldap_unbind($con);
         // Fetch contact
         $contact = DatabaseHelper::getInstance()->getContactByEmail($email);
         if ($contact !== false) {
             return array('Id' => $contact['Id'], 'Role' => $contact['Role']);
         } else {
             // Contact is not in the database - we better create it
             // TODO: Put the option to read data
             return array('Id' => DatabaseHelper::getInstance()->addContact('', '', $email, ROLE_IDENTIFIED), 'Role' => ROLE_IDENTIFIED);
         }
     } else {
         $errCode = ldap_errno($con);
         if ($errCode == self::LDAP_INAPPROPRIATE_AUTH || $errCode == self::LDAP_INVALID_CREDENTIALS) {
             // Invalid credentials - simply fail
             return false;
         }
         // Internal error
         throw new Exception(__METHOD__ . " : LDAP error: " . ldap_err2str($errCode));
     }
 }
Ejemplo n.º 27
0
 public function initInternal()
 {
     $this->_regions = DatabaseHelper::getInstance()->getRegions();
     if (isset($_GET['regionSelector']) && array_key_exists($_GET['regionSelector'], $this->_regions)) {
         $this->_currentRegion = $this->_regions[$_GET['regionSelector']];
         // Set the cookie for 14 days
         if (!setcookie('region', $_GET['regionSelector'], time() + TWO_WEEKS, getConfiguration('public.path') . '/')) {
             warn(__METHOD__ . ': Could not set cookie for user! Output already exists.');
         }
         unset($_GET['region']);
     } else {
         if (isset($_COOKIE['region']) && array_key_exists($_COOKIE['region'], $this->_regions)) {
             $this->_currentRegion = $this->_regions[$_COOKIE['region']];
             // Update cookie expiry time
             setcookie('region', $_COOKIE['region'], time() + TWO_WEEKS, getConfiguration('public.path') . '/');
         } else {
             $this->_currentRegion = $this->_regions[self::getDefaultRegion()];
         }
     }
     info(__METHOD__ . ' region selected: ' . $this->_currentRegion['Id'] . ' (' . $this->_currentRegion['Name'] . ')');
 }
 function authenticate($params)
 {
     assert('isset($params["email"]) && isset($params["password"])');
     // TODO: A primitive brute-force defense?
     // We must call buildEmail as we may have explicitely added the
     // domain suffix during registration
     $email = Utils::buildEmail($params['email']);
     $pass = $params['password'];
     // Created a hashed hexadecimal string, use the salt if possible
     $hashed = Utils::hashPassword($pass);
     $contact = DatabaseHelper::getInstance()->getContactByEmail($email);
     if ($contact !== false) {
         if ($contact['Identifier'] === $hashed) {
             info(__METHOD__ . ': Contact ' . $contact['Id'] . ' succesfully authenticated');
             return array('Id' => $contact['Id'], 'Role' => $contact['Role']);
         } else {
             warn(__METHOD__ . ': Contact ' . $contact['Id'] . ' failed to authorize: wrong password');
         }
     }
     return false;
 }
 /**
  * Grab all the articles
  */
 private static function cycleThroughAllArticles()
 {
     $res = DatabaseHelper::batchSelect('page', array('page_title'), array('page_namespace' => NS_MAIN, 'page_is_redirect' => 0), __METHOD__, array('LIMIT' => self::CHUNK_LIMIT));
     print 'articles: ' . count($res) . "\n";
     $count = 0;
     $num = 1;
     foreach ($res as $row) {
         //print $num.' - ';
         $title = Title::newFromRow($row);
         if ($title) {
             //print $title->getDBKey();
             if (self::processSubheaders($title)) {
                 $count++;
             }
         }
         //print "\n";
         $num++;
     }
     //print "\nchanged: ".$count."\n";
     print "\ntotal: " . $count . "\n";
     return;
 }
Ejemplo n.º 30
0
 public static function fromID($id)
 {
     $sql = "SELECT * FROM users WHERE id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $id);
     $sth->execute();
     $res = $sth->fetch(PDO::FETCH_ASSOC);
     $instance = new User($res["id"], $res["username"], $res["content"], null);
     $instance->_register_date = $res["register_date"];
     $instance->_last_logon_date = $res["last_logon_date"];
     $instance->_role = $res["roles"];
     $instance->_description = $res["description"];
     $instance->_permissions = array();
     $sql = "SELECT * FROM permissions INNER JOIN users_permissions ON (users_permissions.permission_id = permissions.id) WHERE user_id = ?";
     $sth = DatabaseHelper::getInstance()->prepare($sql);
     $sth->bindParam(1, $id);
     $sth->execute();
     $res = $sth->fetchAll();
     for ($i = 0; $i < count($res); $i++) {
         array_push($instance->_permissions, $res[$i]["label"]);
     }
     return $instance;
 }