Example #1
0
 public static function getLastSheets($count)
 {
     Database::query("SELECT sheet FROM `myexcel` GROUP BY sheet LIMIT {$count}");
     $ret = array();
     while ($row = Database::fetchRow()) {
         $ret[] = $row['sheet'];
     }
     return $ret;
 }
 /**
  * @param string $serverType
  * @param array $tables
  */
 protected function buildTestDatabase($tables)
 {
     global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
     $wgDBprefix = 'parsertest';
     $db = new Database($wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname);
     if ($db->isOpen()) {
         if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
             # Database that supports CREATE TABLE ... LIKE
             foreach ($tables as $tbl) {
                 $newTableName = $db->tableName($tbl);
                 #$tableName = $this->oldTableNames[$tbl];
                 $tableName = $tbl;
                 $db->query("CREATE TEMPORARY TABLE {$newTableName} (LIKE {$tableName})");
             }
         } else {
             # Hack for MySQL versions < 4.1, which don't support
             # "CREATE TABLE ... LIKE". Note that
             # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
             # would not create the indexes we need....
             foreach ($tables as $tbl) {
                 $res = $db->query("SHOW CREATE TABLE {$tbl}");
                 $row = $db->fetchRow($res);
                 $create = $row[1];
                 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `' . $wgDBprefix . '\\1`', $create);
                 if ($create === $create_tmp) {
                     # Couldn't do replacement
                     wfDie("could not create temporary table {$tbl}");
                 }
                 $db->query($create_tmp);
             }
         }
         return $db;
     } else {
         // Something amiss
         return null;
     }
 }
        } else {
            $dbsByMaster[$defaultMaster][] = $db;
        }
    }
    foreach ($dbsByMaster as $master => $dbs) {
        $dbConn = new Database($master, $wgDBuser, $wgDBpassword, $dbs[0]);
        $stype = $dbConn->addQuotes($type);
        # Padding row for MySQL bug
        $sql = "(SELECT '-------------------------------------------')";
        foreach ($dbs as $dbName) {
            if ($sql != '') {
                $sql .= ' UNION ';
            }
            if ($type === false) {
                $sql .= "(SELECT '{$dbName}' FROM `{$dbName}`.job LIMIT 1)";
            } else {
                $sql .= "(SELECT '{$dbName}' FROM `{$dbName}`.job WHERE job_cmd={$stype} LIMIT 1)";
            }
        }
        $res = $dbConn->query($sql, 'nextJobDB.php');
        $row = $dbConn->fetchRow($res);
        // discard padding row
        while ($row = $dbConn->fetchRow($res)) {
            $pendingDBs[] = $row[0];
        }
    }
    $wgMemc->set($mckey, $pendingDBs, 300);
}
if ($pendingDBs) {
    echo $pendingDBs[mt_rand(0, count($pendingDBs) - 1)];
}
Example #4
0
        $this->currentStationName = $b;
        // the departure/arrival arrays are set in Javascript when it handles this ajax response
        $this->currentFullName = $c;
        $this->latitude = $d;
        $this->longitude = $e;
    }
}
if (isset($_POST['choice'])) {
    // verify AJAX sent a POST request
    $routeChoice = $_POST['choice'];
    // store the user's chosen route
    // Ask SQL for the # of stops of the given route.
    // Then decrement to get the last stop #.
    $db->prepare("SELECT rt_num_station FROM routeinfo WHERE rt_num=?", [$routeChoice]);
    $db->execute();
    while ($fetch = $db->fetchRow()) {
        $lastStop = $fetch['rt_num_station'];
    }
    $lastStop--;
    // Ask SQL for data on each stop in the given route.
    // stop abbr name, stop #, latitude, longitude, stop full name.
    $db->prepare("\n            SELECT \n                stations.st_name, stations.rt_stop_pos, locations.latitude, locations.longitude, locations.fullname\n            FROM \n                stations INNER JOIN locations on stations.st_name = locations.st_name \n            WHERE rt_num = ?", [$routeChoice]);
    $db->execute();
    while ($result = $db->fetchRow()) {
        $obj = new trainStop((int) $result['rt_stop_pos'], $result['st_name'], $result['fullname'], (double) $result['latitude'], (double) $result['longitude']);
        array_push($dummyArr, $obj);
        // push each stop's object into the dummy array
    }
    // end while
    // iterate through the dummy array, and for each stop, set the names for the next & previous stations
    // this'll be used in Javascript to query the BART API for real-time departure times to display
Example #5
0
    5) user clicks on the link, link opens a page verifying the that the reset code is correct
    6) after verification, user can change password on that new page that opened.
***************************************************************************************************/
// user supplies the email needing password change.
//database object is used to that the account is already registered (in the database)
$db = new Database();
if (isset($_POST['pw-reset-submit']) && !fieldsEmpty($_POST)) {
    // if post, user has requested password change...
    $userEmail = $_POST['pw-reset-email'];
    // extract user email address
    $db->prepare("SELECT * FROM users WHERE email=?", [$userEmail]);
    // verify that the email address is in database
    $db->execute();
    if ($db->rowCount() !== 0) {
        // if it's in the database...
        $resultSet = $db->fetchRow();
        // store the row result
        $userName = $resultSet['firstName'] . ' ' . $resultSet['lastName'];
        // create an array: ['first name', 'last name']
        $resetKey = createResetKey();
        // call helper function to generate a reset key
        // create a URL link with the reset key as part of the URL
        // an email will be sent to the user with this link
        // user will click on this link to verify they are the owner of the email address.
        $clickStr = "http://176.32.230.8/pliustock.com/change&email=" . urlencode($userEmail) . "&reset-key=" . $resetKey;
        // store the generated key in the database.
        // later a check will be made between database key & the key in the URL clicked on by user
        // if they match then that confirms the user is the owner of the email
        $db->prepare("UPDATE users SET reset_key=? WHERE email=?", [$resetKey, $userEmail]);
        $db->execute();
        // email parameters (subject, body message)
 /**
  * Extract the Database schema from a MySQL database.
  *
  * @param Database $db
  *
  * @return array schema definition
  */
 private function getSchemaMySql($db, $prefix = '')
 {
     $schema = [];
     if ($prefix != '') {
         $tables = $db->query('SHOW TABLES LIKE ' . $db->quote($prefix . '%'));
     } else {
         $tables = $db->query('SHOW TABLES');
     }
     foreach ($tables as $row) {
         $table = current($row);
         $referencedBy = isset($schema[$table]) ? $schema[$table]['referencedBy'] : [];
         $schema[$table] = ['table' => $table, 'columns' => [], 'primaryKeys' => [], 'referencedBy' => $referencedBy];
         $config =& $schema[$table];
         $showCreate = $db->fetchRow('SHOW CREATE TABLE ' . $db->quoteIdentifier($table));
         $createSyntax = $showCreate['Create Table'];
         $lines = explode("\n", $createSyntax);
         unset($lines[0]);
         // CREATE TABLE * (
         unset($lines[count($lines)]);
         // ) ENGINE=*
         foreach ($lines as $line) {
             $line = preg_replace('/^  |,$/', '', $line);
             // "  " & "," weghalen
             $line = str_replace('NOT ', 'NOT_', $line);
             $line = str_replace(' KEY', '_KEY', $line);
             $line = str_ireplace('CHARACTER SET', 'CHARACTER_SET', $line);
             $line = str_ireplace('ON UPDATE', 'ON_UPDATE', $line);
             $line = str_replace('  ', ' ', $line);
             $parts = explode(' ', $line);
             if (substr($parts[0], 0, 1) == '`') {
                 // Column description
                 $column = substr($parts[0], 1, -1);
                 $config['columns'][$column] = ['type' => $parts[1], 'null' => true];
                 $columnConfig =& $config['columns'][$column];
                 for ($i = 2; $i < count($parts); ++$i) {
                     $part = $parts[$i];
                     switch (strtoupper($part)) {
                         case 'NOT_NULL':
                             $columnConfig['null'] = false;
                             break;
                         case 'NULL':
                             $columnConfig['null'] = true;
                             break;
                         case 'AUTO_INCREMENT':
                             break;
                         case 'DEFAULT':
                             $default = '';
                             while ($part = $parts[$i + 1]) {
                                 ++$i;
                                 $default .= $part;
                                 if (substr($default, 0, 1) != "'") {
                                     // Not a quoted string value?
                                     break;
                                     // end for loop
                                 }
                                 if (substr($default, -1) == "'") {
                                     // End of quoted string?
                                     break;
                                     // end for loop
                                 }
                                 $default .= ' ';
                             }
                             if (substr($default, 0, 1) == "'") {
                                 $config['columns'][$column]['default'] = substr($default, 1, -1);
                                 // remove quotes
                             } else {
                                 switch ($default) {
                                     case 'NULL':
                                         $default = null;
                                         break;
                                     case 'CURRENT_TIMESTAMP':
                                         $default = null;
                                         break;
                                     default:
                                         notice('Unknown default "' . $default . '" in "' . $line . '"');
                                         break;
                                 }
                                 $config['columns'][$column]['default'] = $default;
                             }
                             break;
                         case 'UNSIGNED':
                             $config['columns'][$column]['type'] = 'unsigned ' . $config['columns'][$column]['type'];
                             break;
                         case 'COMMENT':
                             $i += $this->stripQuotedValue($parts, $comment, $i);
                             $config['columns'][$column]['comment'] = $comment;
                             break;
                         case 'ON_UPDATE':
                         case 'CHARACTER_SET':
                         case 'COLLATE':
                             $i++;
                             // ignore value
                             break;
                         default:
                             notice('Unknown part "' . $part . '" in "' . $line . '"');
                             break;
                     }
                 }
             } else {
                 // Key description
                 $exploded = explode(' ', $line);
                 $parts = [];
                 for ($i = 0; $i < count($exploded); ++$i) {
                     $part = $exploded[$i];
                     if (substr($part, 0, 1) === '`') {
                         --$i;
                         $i += $this->stripQuotedValue($exploded, $value, $i, '`');
                         $parts[] = $value;
                     } else {
                         $parts[] = str_replace('`', '', $part);
                         // @todo Parse the "(`id`)" parts. Spaces in columnnames are unlikely but possible.
                     }
                 }
                 switch ($parts[0]) {
                     case 'PRIMARY_KEY':
                         $config['primaryKeys'] = explode(',', substr($parts[1], 1, -1));
                         break;
                     case 'KEY':
                     case 'UNIQUE_KEY':
                     case 'FULLTEXT_KEY':
                         break;
                         // Skip
                     // Skip
                     case 'CONSTRAINT':
                         if ($parts[2] != 'FOREIGN_KEY') {
                             notice('Unknown constraint: "' . $line . '"');
                             break;
                         }
                         if ($parts[4] != 'REFERENCES') {
                             notice('Unknown foreign key: "' . $line . '"');
                             break;
                         }
                         $column = substr($parts[3], 1, -1);
                         $foreignTable = $parts[5];
                         $foreignColumn = substr($parts[6], 1, -1);
                         $config['columns'][$column]['foreignKeys'][] = ['table' => $foreignTable, 'column' => $foreignColumn];
                         $schema[$foreignTable]['referencedBy'][] = ['table' => $table, 'column' => $column];
                         break;
                     default:
                         notice('Unknown metadata "' . $parts[0] . '" in "' . $line . '"', $lines);
                         break;
                 }
             }
         }
         unset($config);
     }
     return $schema;
 }
Example #7
0
if (isset($_POST)) {
    // check if POST AJAX request was sent...
    $routeNumber = (int) $_POST['rtNum'];
    // store the user's route #
    $stopNumber = (int) $_POST['stopNum'];
    // store the user's stop #
    $prevStopNumber = (int) $_POST['prevStop'];
    // store the previous stop #
    $nextStopNumber = (int) $_POST['nextStop'];
    // store the next stop #
    $nowNextStop = [];
    // this array will store the station names of current, previous, next stops
    // Query for the route's last stop
    $db->prepare("SELECT rt_num_station FROM routeinfo WHERE rt_num=?", [$routeNumber]);
    $db->execute();
    while ($fetch = $db->fetchRow()) {
        $lastStop = $fetch['rt_num_station'];
    }
    // If we have stops 0-25, SQL reports back '26'.  Need to decrement.
    $lastStop--;
    // if user clicks on stop 0, there can't be any previous stops.
    // Set to NULL. This'll decide later if HTML needs to be generated for arrivals from previous stops.
    if ($stopNumber == 0) {
        $prevStopNumber = NULL;
    } else {
        if ($stopNumber == $lastStop) {
            $nextStopNumber = NULL;
        }
    }
    // Query for data of current / next / previous stops
    $db->prepare("(SELECT * FROM stations WHERE rt_num=? AND rt_stop_pos=?)     \n                  UNION \n                  (SELECT * FROM stations WHERE rt_num=? AND rt_stop_pos=?)\n                  UNION \n                  (SELECT * FROM stations WHERE rt_num=? AND rt_stop_pos=?)", [$routeNumber, $stopNumber, $routeNumber, $nextStopNumber, $routeNumber, $prevStopNumber]);
Example #8
0
 /**
  * Load the tables that the Database user has access to into memory
  * @return void
  */
 function loadTables()
 {
     $r = $this->query("SHOW TABLES FROM `" . mysql_escape_string($this->db) . "`");
     while ($row = Database::fetchRow($r)) {
         if (empty($this->tblPrefix) || strstr($row[0], $this->tblPrefix) === 0) {
             $rName = substr($row[0], strlen($this->tblPrefix));
             if (!in_array($rName, $this->tableNames)) {
                 $this->tables[$rName] = new DatabaseTable($row[0], $this);
                 $this->tableNames[] = $rName;
             }
         }
     }
 }
 function CallHook($hookname, $params)
 {
     global $use_mediawikiplugin, $G_SESSION, $HTML;
     if (isset($params['group_id'])) {
         $group_id = $params['group_id'];
     } elseif (isset($params['group'])) {
         $group_id = $params['group'];
     } else {
         $group_id = null;
     }
     if ($hookname == "outermenu") {
         $params['TITLES'][] = 'MediaWiki';
         $params['DIRS'][] = '/mediawiki';
     } elseif ($hookname == "usermenu") {
         $text = $this->text;
         // this is what shows in the tab
         if ($G_SESSION->usesPlugin("mediawiki")) {
             echo ' | ' . $HTML->PrintSubMenu(array($text), array('/mediawiki/index.php?title=User:'******'TITLES'][] = $this->text;
             $params['DIRS'][] = '/plugins/mediawiki/index.php?group_id=' . $project->getID();
         }
         $params['toptab'] == $this->name ? $params['selected'] = count($params['TITLES']) - 1 : '';
     } elseif ($hookname == "groupisactivecheckbox") {
         //Check if the group is active
         // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
         $group =& group_get_object($group_id);
         echo "<tr>";
         echo "<td>";
         echo ' <input type="CHECKBOX" name="use_mediawikiplugin" value="1" ';
         // CHECKED OR UNCHECKED?
         if ($group->usesPlugin($this->name)) {
             echo "CHECKED";
         }
         echo "><br/>";
         echo "</td>";
         echo "<td>";
         echo "<strong>Use " . $this->text . " Plugin</strong>";
         echo "</td>";
         echo "</tr>";
     } elseif ($hookname == "groupisactivecheckboxpost") {
         // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
         $group =& group_get_object($group_id);
         $use_mediawikiplugin = getStringFromRequest('use_mediawikiplugin');
         if ($use_mediawikiplugin == 1) {
             $group->setPluginUse($this->name);
         } else {
             $group->setPluginUse($this->name, false);
         }
     } elseif ($hookname == "userisactivecheckbox") {
         //check if user is active
         // this code creates the checkbox in the user account manteinance page to activate/deactivate the plugin
         $user = $params['user'];
         echo "<tr>";
         echo "<td>";
         echo ' <input type="CHECKBOX" name="use_mediawikiplugin" value="1" ';
         // CHECKED OR UNCHECKED?
         if ($user->usesPlugin($this->name)) {
             echo "CHECKED";
         }
         echo ">    Use " . $this->text . " Plugin";
         echo "</td>";
         echo "</tr>";
     } elseif ($hookname == "userisactivecheckboxpost") {
         // this code actually activates/deactivates the plugin after the form was submitted in the user account manteinance page
         $user = $params['user'];
         $use_mediawikiplugin = getStringFromRequest('use_mediawikiplugin');
         if ($use_mediawikiplugin == 1) {
             $user->setPluginUse($this->name);
         } else {
             $user->setPluginUse($this->name, false);
         }
         echo "<tr>";
         echo "<td>";
         echo ' <input type="CHECKBOX" name="use_mediawikiplugin" value="1" ';
         // CHECKED OR UNCHECKED?
         if ($user->usesPlugin($this->name)) {
             echo "CHECKED";
         }
         echo ">    Use " . $this->text . " Plugin";
         echo "</td>";
         echo "</tr>";
     } elseif ($hookname == "user_personal_links") {
         // this displays the link in the user's profile page to it's personal MediaWiki (if you want other sto access it, youll have to change the permissions in the index.php
         $userid = $params['user_id'];
         $user = user_get_object($userid);
         $text = $params['text'];
         //check if the user has the plugin activated
         if ($user->usesPlugin($this->name)) {
             echo '	<p>';
             echo util_make_link("/plugins/helloworld/index.php?id={$userid}&type=user&pluginname=" . $this->name, _('View Personal MediaWiki'));
             echo '</p>';
         }
     } elseif ($hookname == "project_admin_plugins") {
         // this displays the link in the project admin options page to it's  MediaWiki administration
         $group_id = $params['group_id'];
         $group =& group_get_object($group_id);
         if ($group->usesPlugin($this->name)) {
             echo util_make_link("/plugins/projects_hierarchy/index.php?id=" . $group->getID() . '&type=admin&pluginname=' . $this->name, _('View the MediaWiki Administration'));
             echo '</p>';
         }
     } elseif ($hookname == "session_before_login") {
         $loginname = $params['loginname'];
         $passwd = $params['passwd'];
         if (!session_login_valid_dbonly($loginname, $passwd, false)) {
             return;
         }
         $u = user_get_object_by_name($loginname);
         define('MEDIAWIKI', true);
         if (is_file('/var/lib/mediawiki/LocalSettings.php')) {
             require_once '/var/lib/mediawiki/LocalSettings.php';
         } elseif (is_file('/var/lib/mediawiki1.10/LocalSettings.php')) {
             require_once '/var/lib/mediawiki1.10/LocalSettings.php';
         } else {
             return 1;
         }
         if (is_dir('/usr/share/mediawiki')) {
             $mw_share_path = "/usr/share/mediawiki";
         } elseif (is_dir('/usr/share/mediawiki1.10')) {
             $mw_share_path = "/usr/share/mediawiki1.10";
         } else {
             return 1;
         }
         require_once $mw_share_path . '/includes/Defines.php';
         require_once $mw_share_path . '/includes/Exception.php';
         require_once $mw_share_path . '/includes/GlobalFunctions.php';
         require_once $mw_share_path . '/StartProfiler.php';
         require_once $mw_share_path . '/includes/Database.php';
         $mwdb = new Database();
         $mwdb->open($wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname);
         $sql = "select count(*) from user where user_name=?";
         $res = $mwdb->safeQuery($sql, ucfirst($loginname));
         $row = $mwdb->fetchRow($res);
         if ($row[0] == 1) {
             $sql = "update user set user_password=?, user_email=?, user_real_name=? where user_name=?";
             $res = $mwdb->safeQuery($sql, md5($passwd), $u->getEmail(), $u->getRealName(), array(ucfirst($loginname)));
         } else {
             $sql = "insert into user (user_name, user_real_name, user_password, user_email, user_options) values (?, ?, ?, ?, ?)";
             $res = $mwdb->safeQuery($sql, array(ucfirst($loginname), $u->getRealName(), md5($passwd), $u->getEmail(), "skin=gforge\ncols=80\nrows=25"));
         }
     } elseif ($hookname == "blahblahblah") {
         // ...
     }
 }