Exemplo n.º 1
0
 /**
  * Ensure that all database tables are included as designed
  * 
  * @return void
  */
 public function testDatabaseTables()
 {
     if (!file_exists(SITE_ROOT . '/install/sql/structure.xml')) {
         $this->markTestSkipped('The install folder is unavailable, can\'t run this test.');
     }
     $db = simplexml_load_file(SITE_ROOT . '/install/sql/structure.xml');
     foreach ($db->database->table_structure as $table) {
         $tablename = str_replace('phpvms_', TABLE_PREFIX, $table['name']);
         DB::query('SELECT * FROM ' . $tablename . ' WHERE 1=1 LIMIT 1');
         $this->assertNotEquals('1146', DB::errno(), "\"{$tablename}\" is missing");
         if (DB::$errno == '1146') {
             continue;
         }
         /* loop through all the columns returned by the above query and all the columns
          		from the fields in the xml file, and make sure they all match up, with the
          		fieldlist from the xml being the "master" outside loop which it looks up against */
         $anyerrors = false;
         $colinfo = DB::$DB->col_info;
         foreach ($table->field as $field) {
             $found = false;
             foreach ($colinfo as $column) {
                 if ($column->name == $field['Field']) {
                     $found = true;
                     break;
                 }
             }
             $this->assertTrue($found, "Column {$field['Field']} from {$tablename} missing");
         }
     }
 }
Exemplo n.º 2
0
 /**
  * UserTest::testRegisterUser()
  * 
  * @return void
  */
 public function testRegisterUser()
 {
     $data = RegistrationData::addUser($this->registrationData);
     $this->assertTrue($data, 'Reported error: ' . RegistrationData::$error);
     $this->pilotid = RegistrationData::$pilotid;
     $this->assertGreaterThan(0, $this->pilotid, 'Valid pilot ID');
     $this->assertEquals(0, DB::errno(), 'User Registration');
     # See if it was written
     $this->pilot_data = PilotData::getPilotData($this->pilotid);
     $this->assertObjectHasAttribute('pilotid', $this->pilot_data, 'Retrieve user data');
 }
Exemplo n.º 3
0
 public static function AddGroup($groupname, $type)
 {
     $groupname = DB::escape($groupname);
     if ($type != 'a' || $type != 'd') {
         $type = 'd';
     }
     $query = "INSERT INTO " . TABLE_PREFIX . "groups (name, groupstype) VALUES ('{$groupname}', '{$type}')";
     $res = DB::query($sql);
     if (DB::errno() != 0) {
         return false;
     }
     return true;
 }
Exemplo n.º 4
0
 function make($rule = '', $num = 1, $cardval = array())
 {
     global $_G;
     $this->rule = empty($rule) ? $this->set['rule'] : trim($rule);
     if (empty($this->rule)) {
         return -1;
     }
     $this->fail($num);
     if (is_array($cardval)) {
         foreach ($cardval as $key => $val) {
             $sqlkey .= ", {$key}";
             $sqlval .= ", '{$val}'";
         }
     }
     for ($i = 0; $i < $num; $i++) {
         if ($this->checkrule($this->rule)) {
             $card = $this->rule;
             foreach ($this->rulereturn as $key => $val) {
                 $search = array();
                 foreach ($val as $skey => $sval) {
                     $search[] = '/' . $this->rulekey[$key] . '/';
                 }
                 $card = preg_replace($search, $val, $card, 1);
             }
         } else {
             return 0;
         }
         $sql = "INSERT INTO " . DB::table('common_card') . " (id, makeruid, dateline {$sqlkey})VALUES('{$card}', '{$_G['uid']}', '{$_G['timestamp']}' {$sqlval})";
         DB::query($sql, 'SILENT');
         if ($sqlerror = DB::error()) {
             if (DB::errno() == 1062) {
                 $this->fail++;
                 if ($this->failmin > $this->fail) {
                     $num++;
                 } else {
                     $num = $i - 1;
                 }
             } else {
                 DB::halt($sqlerror, $sql);
             }
         } else {
             $this->succeed += intval(DB::affected_rows());
             $this->cardlist[] = $card;
         }
     }
     return true;
 }
Exemplo n.º 5
0
 function testEditUserData()
 {
     # Check a save profile
     $save = PilotData::SaveProfile($this->pilotid, '*****@*****.**', 'PK', '', '', true);
     $this->assertEqual(0, DB::errno());
     #unset($save);
     # Verify if data was written, and if it differs
     $changeset1 = PilotData::GetPilotData($this->pilotid);
     $this->assertNotEqual($changeset1, $this->pilot_data);
     $this->assertNotEqual($changeset1->retired, $this->pilot_data->retired);
     unset($data);
     # Change it back
     $save = PilotData::SaveProfile($this->pilotid, '*****@*****.**', 'US', '', '', false);
     $this->assertTrue($save, DB::error(), 'Reverting user data');
     unset($save);
     # And verify once more
     $changeset2 = PilotData::GetPilotData($this->pilotid);
     $this->assertNotEqual($changeset1, $changeset2);
     $this->assertNotEqual($changeset1->retired, $changeset2->retired);
     unset($changeset1);
     unset($changeset2);
     echo '<br />';
 }
Exemplo n.º 6
0
    public static function IncrementDLCount($id)
    {
        $sql = 'UPDATE ' . TABLE_PREFIX . 'downloads
					SET hits=hits+1
					WHERE id=' . intval($id);
        $res = DB::query($sql);
        if (DB::errno() != 0) {
            return false;
        }
        return true;
    }
Exemplo n.º 7
0
 /**
  * Update a pilot, $params is an array of column_name=>value
  *
  * @param mixed $pilotid This is a description
  * @param mixed $params This is a description
  * @return mixed This is the return value description
  *
  */
 public static function updateProfile($pilotid, $params)
 {
     /*$params = array(
          'pilotid' => '',
          'code' => '',
          'email' => '',
          'location' => '',
          'hub' => '',
          'bgimage' => '',
          'retired' => false,
          );
       */
     if (empty($pilotid)) {
         return false;
     }
     if (!is_array($params)) {
         return false;
     }
     /* Cleanup any specific parameters */
     if (isset($params['location'])) {
         $params['location'] = strtoupper($params['location']);
     }
     if (isset($params['pilotid'])) {
         unset($params['pilotid']);
     }
     $sql = "UPDATE " . TABLE_PREFIX . "pilots SET ";
     $sql .= DB::build_update($params);
     $sql .= " WHERE `pilotid`={$pilotid}";
     $res = DB::query($sql);
     if (DB::errno() != 0) {
         return false;
     }
     # Auto groups?
     $groups = Config::get('PILOT_STATUS_TYPES');
     if (isset($params['retired'])) {
         $info = $groups[$params['retired']];
         # Automatically add into these groups
         if (is_array($info['group_add']) && count($info['group_add']) > 0) {
             foreach ($info['group_add'] as $group) {
                 PilotGroups::addUsertoGroup($pilotid, $group);
             }
         }
         if (is_array($info['group_remove']) && count($info['group_remove']) > 0) {
             foreach ($info['group_remove'] as $group) {
                 PilotGroups::removeUserFromGroup($pilotid, $group);
             }
         }
     }
     return true;
 }
Exemplo n.º 8
0
 /**
  * Perform a query
  *
  * @param unknown_type $query
  * @return boolean/int Returns true/false, or rows affected
  */
 public static function query($query)
 {
     $ret = self::$DB->query($query);
     self::$error = self::$DB->error;
     self::$errno = self::$DB->errno;
     self::$rows_affected = self::$num_rows = self::$DB->num_rows;
     self::$insert_id = self::$DB->insert_id;
     return $ret;
     //self::$insert_id;
 }
Exemplo n.º 9
0
 /**
  * Edit a certain expense
  */
 public static function editExpense($id, $name, $cost, $type)
 {
     if ($name == '' || $cost == '') {
         self::$lasterror = 'Name and cost must be entered';
         return false;
     }
     $name = DB::escape($name);
     $cost = DB::escape($cost);
     $type = strtoupper($type);
     if ($type == '') {
         $type = 'M';
     }
     // Default as monthly
     $sql = 'UPDATE ' . TABLE_PREFIX . "expenses\n\t\t\t\t\tSET `name`='{$name}', `cost`='{$cost}', `type`='{$type}'\n\t\t\t\t\tWHERE `id`={$id}";
     DB::query($sql);
     if (DB::errno() != 0) {
         return false;
     }
     return true;
 }
Exemplo n.º 10
0
    /**
     * Save site settings
     *
     * @param string $name Setting name. Must be unique
     * @param string $value Value of the setting
     * @param boolean $core Whether it's "vital" to the engine or not. Bascially blocks deletion
     */
    public static function saveSetting($name, $value, $descrip = '', $core = false)
    {
        if (is_bool($value)) {
            if ($value == true) {
                $value = 'true';
            } elseif ($value == false) {
                $value = 'false';
            }
        }
        //see if it's an update
        if ($core == true) {
            $core = 't';
        } else {
            $core = 'f';
        }
        $name = strtoupper(DB::escape($name));
        $value = DB::escape($value);
        $descrip = DB::escape($descrip);
        $sql = 'UPDATE ' . TABLE_PREFIX . 'settings
					SET value=\'' . $value . '\' WHERE name=\'' . $name . '\'';
        $res = DB::query($sql);
        if (DB::errno() != 0) {
            return false;
        }
        CodonCache::delete('site_settings');
        return true;
    }
Exemplo n.º 11
0
    public static function show_error($type, $errormsg, $phpmsg = '', $typemsg = '')
    {
        global $_G;
        ob_end_clean();
        $gzip = getglobal('gzipcompress');
        ob_start($gzip ? 'ob_gzhandler' : null);
        $host = $_SERVER['HTTP_HOST'];
        $title = $type == 'db' ? 'Database' : 'System';
        //出错处理 改为记日志而不是直接输出到页面
        $messagesave = $host . '\\r' . $title . '\\r\\n' . $errormsg;
        !empty($phpmsg) && ($messagesave = $messagesave . '\\r\\n' . var_export($phpmsg, true));
        discuz_error::write_error_log($messagesave);
        header("Location: /");
        exit;
        echo <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
\t<title>{$host} - {$title} Error</title>
\t<meta http-equiv="Content-Type" content="text/html; charset={$_G['config']['output']['charset']}" />
\t<meta name="ROBOTS" content="NOINDEX,NOFOLLOW,NOARCHIVE" />
\t<style type="text/css">
\t<!--
\tbody { background-color: white; color: black; font: 9pt/11pt verdana, arial, sans-serif;}
\t#container { width: 1024px; }
\t#message   { width: 1024px; color: black; }

\t.red  {color: red;}
\ta:link     { font: 9pt/11pt verdana, arial, sans-serif; color: red; }
\ta:visited  { font: 9pt/11pt verdana, arial, sans-serif; color: #4e4e4e; }
\th1 { color: #FF0000; font: 18pt "Verdana"; margin-bottom: 0.5em;}
\t.bg1{ background-color: #FFFFCC;}
\t.bg2{ background-color: #EEEEEE;}
\t.table {background: #AAAAAA; font: 11pt Menlo,Consolas,"Lucida Console"}
\t.info {
\t    background: none repeat scroll 0 0 #F3F3F3;
\t    border: 0px solid #aaaaaa;
\t    border-radius: 10px 10px 10px 10px;
\t    color: #000000;
\t    font-size: 11pt;
\t    line-height: 160%;
\t    margin-bottom: 1em;
\t    padding: 1em;
\t}

\t.help {
\t    background: #F3F3F3;
\t    border-radius: 10px 10px 10px 10px;
\t    font: 12px verdana, arial, sans-serif;
\t    text-align: center;
\t    line-height: 160%;
\t    padding: 1em;
\t}

\t.sql {
\t    background: none repeat scroll 0 0 #FFFFCC;
\t    border: 1px solid #aaaaaa;
\t    color: #000000;
\t    font: arial, sans-serif;
\t    font-size: 9pt;
\t    line-height: 160%;
\t    margin-top: 1em;
\t    padding: 4px;
\t}
\t-->
\t</style>
</head>
<body>
<div id="container">
<h1>Discuz! {$title} Error</h1>
<div class='info'>{$errormsg}</div>


EOT;
        if (!empty($phpmsg)) {
            echo '<div class="info">';
            echo '<p><strong>PHP Debug</strong></p>';
            echo '<table cellpadding="5" cellspacing="1" width="100%" class="table">';
            if (is_array($phpmsg)) {
                echo '<tr class="bg2"><td>No.</td><td>File</td><td>Line</td><td>Code</td></tr>';
                foreach ($phpmsg as $k => $msg) {
                    $k++;
                    echo '<tr class="bg1">';
                    echo '<td>' . $k . '</td>';
                    echo '<td>' . $msg['file'] . '</td>';
                    echo '<td>' . $msg['line'] . '</td>';
                    echo '<td>' . $msg['function'] . '</td>';
                    echo '</tr>';
                }
            } else {
                echo '<tr><td><ul>' . $phpmsg . '</ul></td></tr>';
            }
            echo '</table></div>';
        }
        $helplink = '';
        if ($type == 'db') {
            $helplink = "http://faq.comsenz.com/?type=mysql&dberrno=" . rawurlencode(DB::errno()) . "&dberror=" . rawurlencode(str_replace(DB::object()->tablepre, '', DB::error()));
            $helplink = "<a href=\"{$helplink}\" target=\"_blank\"><span class=\"red\">Need Help?</span></a>";
        }
        $endmsg = lang('error', 'error_end_message', array('host' => $host));
        echo <<<EOT
<div class="help">{$endmsg}. {$helplink}</div>
</div>
</body>
</html>
EOT;
        $exit && exit;
    }
Exemplo n.º 12
0
 public static function deleteAllAirports()
 {
     $sql = 'DELETE FROM ' . TABLE_PREFIX . 'airports';
     $res = DB::query($sql);
     if (DB::errno() != 0) {
         return false;
     }
     return true;
 }
Exemplo n.º 13
0
 /**
  * Perform a query
  *
  * @param unknown_type $query
  * @return boolean/int Returns true/false, or rows affected
  */
 public static function query($query)
 {
     self::$DB->throw_exceptions = self::$throw_exceptions;
     $ret = self::$DB->query($query);
     self::$error = self::$DB->error;
     self::$errno = self::$DB->errno;
     self::$rows_affected = self::$num_rows = self::$DB->num_rows;
     self::$insert_id = self::$DB->insert_id;
     self::$last_query = $query;
     // Log any erronious queries
     if (self::$DB->errno != 0) {
         self::write_debug();
     }
     return $ret;
     //self::$insert_id;
 }
Exemplo n.º 14
0
     }
     $firstlist = getatidheap($threadlist);
     $tidsarray = array_keys($threadlist);
     if (!empty($firstlist['tids'])) {
         $continue = true;
     }
     if ($continue) {
         foreach ($firstlist['tids'] as $tid) {
             $posttableid = $threadlist[$tid]['posttableid'];
             if ($posttableid == $_G['gp_tableid']) {
                 continue;
             }
             $posttable_source = $posttableid ? "forum_post_{$posttableid}" : 'forum_post';
             $posttable_target = $_G['gp_tableid'] ? "forum_post_{$_G['gp_tableid']}" : 'forum_post';
             DB::query("INSERT INTO " . DB::table($posttable_target) . " SELECT * FROM " . DB::table($posttable_source) . " WHERE tid='{$tid}'", 'SILENT');
             if (DB::errno()) {
                 DB::delete($posttable_target, "tid='{$tid}'");
                 DB::query("INSERT INTO " . DB::table($posttable_target) . " SELECT * FROM " . DB::table($posttable_source) . " WHERE tid='{$tid}'");
             }
             DB::update($threadtable, array('posttableid' => intval($_G['gp_tableid'])), "tid='{$tid}'");
             DB::delete($posttable_source, "tid='{$tid}'");
         }
         $completed = intval($_G['gp_completed']) + count($firstlist['tids']);
         foreach ($firstlist['tids'] as $tid) {
             unset($threadlist[$tid]);
         }
         $nextstep = $step + 1;
         cpmsg('postsplit_moving', "action=postsplit&operation=move&{$_G['gp_urladd']}&tableid={$_G['gp_tableid']}&completed={$completed}&threadtomove={$_G['gp_threadtomove']}&step={$nextstep}&moving=1", 'loadingform', array('count' => $completed, 'total' => intval($_G['gp_threadtomove']), 'tids' => implode(',', array_keys($threadlist)), 'threads_per_time' => $_G['gp_threads_per_time'], 'conditions' => stripslashes(htmlspecialchars($_G['gp_conditions']))));
     }
     cpmsg('postsplit_move_succeed', "action=postsplit&operation=manage", 'succeed');
 }
Exemplo n.º 15
0
 protected function delete_schedule_post()
 {
     $schedule = SchedulesData::findSchedules(array('s.id' => $this->post->id));
     SchedulesData::DeleteSchedule($this->post->id);
     $params = array();
     if (DB::errno() != 0) {
         $params['status'] = 'There was an error deleting the schedule';
         $params['error'] = DB::error();
         echo json_encode($params);
         return;
     }
     $params['status'] = 'ok';
     echo json_encode($params);
     LogData::addLog(Auth::$userinfo->pilotid, 'Deleted schedule "' . $schedule->code . $schedule->flightnum . '"');
 }
Exemplo n.º 16
0
 /**
  * SiteData::DeletePage()
  * 
  * @param mixed $pageid
  * @return
  */
 public static function DeletePage($pageid)
 {
     $info = self::GetPageData($pageid);
     $sql = 'DELETE FROM ' . TABLE_PREFIX . 'pages WHERE pageid=' . $pageid;
     @unlink(PAGES_PATH . '/' . $info->filename . PAGE_EXT);
     $res = DB::query($sql);
     if (DB::errno() != 0) {
         return false;
     }
     return true;
 }
Exemplo n.º 17
0
 public static function ValidateConfirm()
 {
     $confid = Vars::GET('confirmid');
     $sql = "UPDATE " . TABLE_PREFIX . "pilots SET confirmed=1, retired=0 WHERE salt='{$confid}'";
     $res = DB::query($sql);
     if (DB::errno() != 0) {
         return false;
     }
     return true;
 }
Exemplo n.º 18
0
 protected function edit_rank_post()
 {
     if ($this->post->minhours == '' || $this->post->rank == '') {
         $this->set('message', 'Hours and Rank must be blank');
         $this->render('core_error.tpl');
         return;
     }
     if (!is_numeric($this->post->minhours)) {
         $this->set('message', 'The hours must be a number');
         $this->render('core_error.tpl');
         return;
     }
     $this->post->payrate = abs($this->post->payrate);
     $ret = RanksData::UpdateRank($this->post->rankid, $this->post->rank, $this->post->minhours, $this->post->rankimage, $this->post->payrate);
     if (DB::errno() != 0) {
         $this->set('message', 'Error updating the rank: ' . DB::error());
         $this->render('core_error.tpl');
         return;
     }
     $this->set('message', 'Rank Added!');
     $this->render('core_success.tpl');
     LogData::addLog(Auth::$userinfo->pilotid, 'Edited the rank "' . $this->post->rank . '"');
 }
Exemplo n.º 19
0
 public static function removeAirport($icao)
 {
     $icao = DB::escape($icao);
     $icao = strtoupper($icao);
     $sql = "DELETE FROM " . TABLE_PREFIX . "airports WHERE `icao`='{$icao}'";
     $res = DB::query($sql);
     if (DB::errno() != 0) {
         return false;
     }
     CodonCache::delete('get_airport_' . $icao);
     CodonCache::delete('all_airports_json');
     CodonCache::delete('all_airports');
     return true;
 }
Exemplo n.º 20
0
    /**
     * Delete a rank, and then recalculate
     */
    public static function deleteRank($rankid)
    {
        $sql = 'DELETE FROM ' . TABLE_PREFIX . 'ranks 
					WHERE rankid=' . $rankid;
        DB::query($sql);
        if (DB::errno() != 0) {
            return false;
        }
        CodonCache::delete('all_ranks');
        self::CalculatePilotRanks();
        return true;
    }
Exemplo n.º 21
0
 protected function PIREP_DeleteField()
 {
     $id = DB::escape($this->post->id);
     $ret = PIREPData::DeleteField($id);
     if (DB::errno() != 0) {
         $this->set('message', 'There was an error deleting the field: ' . DB::$err);
         $this->render('core_error.tpl');
     } else {
         LogData::addLog(Auth::$userinfo->pilotid, 'Deleted PIREP field');
         $this->set('message', 'The field was deleted');
         $this->render('core_success.tpl');
     }
 }
Exemplo n.º 22
0
    /**
     * Remove a bid, by passing it's bid id
     */
    public static function removeBid($bidid)
    {
        $bidid = intval($bidid);
        $bid_info = self::getBid($bidid);
        $sql = 'DELETE FROM ' . TABLE_PREFIX . 'bids 
				WHERE `bidid`=' . $bidid;
        DB::query($sql);
        self::SetBidOnSchedule($bid_info->routeid, 0);
        if (DB::errno() != 0) {
            return false;
        }
        return true;
    }
Exemplo n.º 23
0
    function show_error($type, $errormsg, $phpmsg = '')
    {
        global $_G;
        ob_end_clean();
        $gzip = getglobal('gzipcompress');
        ob_start($gzip ? 'ob_gzhandler' : null);
        $host = $_SERVER['HTTP_HOST'];
        $phpmsg = trim($phpmsg);
        $title = $type == 'db' ? 'Database' : 'System';
        echo <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
\t<title>{$host} - {$title} Error</title>
\t<meta http-equiv="Content-Type" content="text/html; charset={$_G['config']['output']['charset']}" />
\t<meta name="ROBOTS" content="NOINDEX,NOFOLLOW,NOARCHIVE" />
\t<style type="text/css">
\t<!--
\tbody { background-color: white; color: black; }
\t#container { width: 650px; }
\t#message   { width: 650px; color: black; background-color: #FFFFCC; }
\t#bodytitle { font: 13pt/15pt verdana, arial, sans-serif; height: 35px; vertical-align: top; }
\t.bodytext  { font: 8pt/11pt verdana, arial, sans-serif; }
\t.help  { font: 12px verdana, arial, sans-serif; color: red;}
\t.red  {color: red;}
\ta:link     { font: 8pt/11pt verdana, arial, sans-serif; color: red; }
\ta:visited  { font: 8pt/11pt verdana, arial, sans-serif; color: #4e4e4e; }
\t-->
\t</style>
</head>
<body>
<table cellpadding="1" cellspacing="5" id="container">
<tr>
\t<td id="bodytitle" width="100%">Discuz! {$title} Error </td>
</tr>
EOT;
        if ($type == 'db') {
            $helplink = "http://faq.comsenz.com/?type=mysql&dberrno=" . rawurlencode(DB::errno()) . "&dberror=" . rawurlencode(DB::error());
            echo <<<EOT
<tr>
\t<td class="bodytext">The database has encountered a problem. <a href="{$helplink}" target="_blank"><span class="red">Need Help?</span></a></td>
</tr>
EOT;
        } else {
            echo <<<EOT
<tr>
\t<td class="bodytext">Your request has encountered a problem. </td>
</tr>
EOT;
        }
        echo <<<EOT
<tr><td><hr size="1"/></td></tr>
<tr><td class="bodytext">Error messages: </td></tr>
<tr>
\t<td class="bodytext" id="message">
\t\t<ul> {$errormsg}</ul>
\t</td>
</tr>
EOT;
        if (!empty($phpmsg)) {
            echo <<<EOT
<tr><td class="bodytext">&nbsp;</td></tr>
<tr><td class="bodytext">Program messages: </td></tr>
<tr>
\t<td class="bodytext">
\t\t<ul> {$phpmsg} </ul>
\t</td>
</tr>
EOT;
        }
        $endmsg = lang('error', 'error_end_message', array('host' => $host));
        echo <<<EOT
<tr>
\t<td class="help"><br /><br />{$endmsg}</td>
</tr>
</table>
</body>
</html>
EOT;
        $exit && exit;
    }
Exemplo n.º 24
0
 public static function sql_file_update($filename)
 {
     if (isset($_GET['test'])) {
         return true;
     }
     # Table changes, other SQL updates
     $sql_file = file_get_contents($filename);
     for ($i = 0; $i < strlen($sql_file); $i++) {
         $str = $sql_file[$i];
         if ($str == ';') {
             $sql .= $str;
             $sql = str_replace('phpvms_', TABLE_PREFIX, $sql);
             DB::query($sql);
             $errno = DB::errno();
             $sql = '';
         } else {
             $sql .= $str;
         }
     }
 }
Exemplo n.º 25
0
                 }
             }
         } else {
             if (!empty($oldcols[$key])) {
                 if (strtolower($value) != strtolower($oldcols[$key])) {
                     $updates[] = "CHANGE `{$key}` `{$key}` {$value}";
                 }
             } else {
                 $updates[] = "ADD `{$key}` {$value}";
             }
         }
     }
     if (!empty($updates)) {
         $usql = "ALTER TABLE " . DB::table($newtable) . " " . implode(', ', $updates);
         if (!DB::query($usql, 'SILENT')) {
             show_msg(lang('update', 'upgrade_table') . DB::table($newtable) . lang('update', 'sql_error') . ':<br><br><b>' . lang('update', 'sql_statement') . '</b>:<div style=\\"position:absolute;font-size:11px;font-family:verdana,arial;background:#EBEBEB;padding:0.5em;\\">' . dhtmlspecialchars($usql) . "</div><br><b>Error</b>: " . DB::error() . "<br><b>Errno.</b>: " . DB::errno());
         } else {
             $msg = lang('update', 'upgrade_table') . DB::table($newtable) . lang('update', 'completed');
         }
     } else {
         $msg = lang('update', 'check_table') . DB::table($newtable) . lang('update', 'skip_table');
     }
 }
 if ($specid) {
     $newtable = $spectable;
 }
 if (get_special_table_by_num($newtable, $specid + 1)) {
     $next = $theurl . '?step=sql&i=' . $_GET['i'] . '&specid=' . ($specid + 1);
 } else {
     $next = $theurl . '?step=sql&i=' . ($_GET['i'] + 1);
 }
Exemplo n.º 26
0
function sqldumptable($table, $startfrom = 0, $currsize = 0)
{
    global $_G, $db, $startrow, $dumpcharset, $complete, $excepttables;
    $offset = 300;
    $tabledump = '';
    $tablefields = array();
    $query = DB::query("SHOW FULL COLUMNS FROM {$table}", 'SILENT');
    if (strexists($table, 'adminsessions')) {
        return;
    } elseif (!$query && DB::errno() == 1146) {
        return;
    } elseif (!$query) {
        $_GET['usehex'] = FALSE;
    } else {
        while ($fieldrow = DB::fetch($query)) {
            $tablefields[] = $fieldrow;
        }
    }
    if (!in_array($table, $excepttables)) {
        $tabledumped = 0;
        $numrows = $offset;
        $firstfield = $tablefields[0];
        if ($_GET['extendins'] == '0') {
            while ($currsize + strlen($tabledump) + 500 < $_GET['sizelimit'] * 1000 && $numrows == $offset) {
                if ($firstfield['Extra'] == 'auto_increment') {
                    $selectsql = "SELECT * FROM {$table} WHERE {$firstfield['Field']} > {$startfrom} ORDER BY {$firstfield['Field']} LIMIT {$offset}";
                } else {
                    $selectsql = "SELECT * FROM {$table} LIMIT {$startfrom}, {$offset}";
                }
                $tabledumped = 1;
                $rows = DB::query($selectsql);
                $numfields = $db->num_fields($rows);
                $numrows = DB::num_rows($rows);
                while ($row = $db->fetch_row($rows)) {
                    $comma = $t = '';
                    for ($i = 0; $i < $numfields; $i++) {
                        $t .= $comma . ($_GET['usehex'] && !empty($row[$i]) && (strexists($tablefields[$i]['Type'], 'char') || strexists($tablefields[$i]['Type'], 'text')) ? '0x' . bin2hex($row[$i]) : '\'' . mysql_escape_string($row[$i]) . '\'');
                        $comma = ',';
                    }
                    if (strlen($t) + $currsize + strlen($tabledump) + 500 < $_GET['sizelimit'] * 1000) {
                        if ($firstfield['Extra'] == 'auto_increment') {
                            $startfrom = $row[0];
                        } else {
                            $startfrom++;
                        }
                        $tabledump .= "INSERT INTO {$table} VALUES ({$t});\n";
                    } else {
                        $complete = FALSE;
                        break 2;
                    }
                }
            }
        } else {
            while ($currsize + strlen($tabledump) + 500 < $_GET['sizelimit'] * 1000 && $numrows == $offset) {
                if ($firstfield['Extra'] == 'auto_increment') {
                    $selectsql = "SELECT * FROM {$table} WHERE {$firstfield['Field']} > {$startfrom} LIMIT {$offset}";
                } else {
                    $selectsql = "SELECT * FROM {$table} LIMIT {$startfrom}, {$offset}";
                }
                $tabledumped = 1;
                $rows = DB::query($selectsql);
                $numfields = $db->num_fields($rows);
                if ($numrows = DB::num_rows($rows)) {
                    $t1 = $comma1 = '';
                    while ($row = $db->fetch_row($rows)) {
                        $t2 = $comma2 = '';
                        for ($i = 0; $i < $numfields; $i++) {
                            $t2 .= $comma2 . ($_GET['usehex'] && !empty($row[$i]) && (strexists($tablefields[$i]['Type'], 'char') || strexists($tablefields[$i]['Type'], 'text')) ? '0x' . bin2hex($row[$i]) : '\'' . mysql_escape_string($row[$i]) . '\'');
                            $comma2 = ',';
                        }
                        if (strlen($t1) + $currsize + strlen($tabledump) + 500 < $_GET['sizelimit'] * 1000) {
                            if ($firstfield['Extra'] == 'auto_increment') {
                                $startfrom = $row[0];
                            } else {
                                $startfrom++;
                            }
                            $t1 .= "{$comma1} ({$t2})";
                            $comma1 = ',';
                        } else {
                            $tabledump .= "INSERT INTO {$table} VALUES {$t1};\n";
                            $complete = FALSE;
                            break 2;
                        }
                    }
                    $tabledump .= "INSERT INTO {$table} VALUES {$t1};\n";
                }
            }
        }
        $startrow = $startfrom;
        $tabledump .= "\n";
    }
    return $tabledump;
}
Exemplo n.º 27
0
function movedate($query)
{
    global $sourcesize, $tableid, $movesize, $targettableid, $hash, $tableindex, $threadtableids, $fieldstr, $fromtableid, $posttable_info;
    $tids = array();
    while ($value = DB::fetch($query)) {
        $tids[$value['tid']] = $value['tid'];
    }
    $fromtable = getposttable($fromtableid, true);
    $condition = " tid IN(" . dimplode($tids) . ")";
    DB::query("INSERT INTO " . DB::table(getposttable($targettableid)) . " ({$fieldstr}) SELECT {$fieldstr} FROM {$fromtable} WHERE {$condition}", 'SILENT');
    if (DB::errno()) {
        DB::delete(getposttable($targettableid), $condition);
    } else {
        foreach ($threadtableids as $threadtableid) {
            $table = $threadtableid ? "forum_thread_{$threadtableid}" : 'forum_thread';
            DB::update($table, array('posttableid' => $targettableid), $condition);
            if (DB::affected_rows() == count($tids)) {
                break;
            }
        }
        DB::delete(getposttable($fromtableid), $condition);
    }
    $status = gettablestatus(DB::table(getposttable($targettableid)), false);
    $targetsize = $sourcesize + $movesize * 1048576;
    $nowdatasize = $targetsize - $status['Data_length'];
    if ($status['Data_length'] >= $targetsize) {
        cpmsg('postsplit_done', 'action=postsplit&operation=optimize&tableid=' . $fromtableid, 'form');
    }
    cpmsg('postsplit_doing', 'action=postsplit&operation=movepost&fromtable=' . $tableid . '&movesize=' . $movesize . '&targettable=' . $targettableid . '&hash=' . $hash . '&tindex=' . $tableindex, 'loadingform', array('datalength' => sizecount($status['Data_length']), 'nowdatalength' => sizecount($nowdatasize)));
}
Exemplo n.º 28
0
    /**
     * Update a pilot's pay. Pass the pilot ID, and the number of
     * hours they are being paid for
     *
     * @param int $pilotid The pilot ID
     * @param int $flighthours Number of hours to pay the pilot for
     * @return bool Success
     *
     */
    public static function updatePilotPay($pilotid, $flighthours)
    {
        $sql = 'SELECT payrate
					FROM ' . TABLE_PREFIX . 'ranks r, ' . TABLE_PREFIX . 'pilots p
					WHERE p.rank=r.rank
						AND p.pilotid=' . $pilotid;
        $payrate = DB::get_row($sql);
        $payupdate = self::getPilotPay($flighthours, $payrate->payrate);
        $sql = 'UPDATE ' . TABLE_PREFIX . 'pilots
					SET totalpay=totalpay+' . $payupdate . '
					WHERE pilotid=' . $pilotid;
        DB::query($sql);
        if (DB::errno() != 0) {
            return false;
        }
        return true;
    }
Exemplo n.º 29
0
 /**
  * Write all of the SQL tables to the database
  * 
  * @return
  */
 public static function AddTables()
 {
     if (!DB::init($_POST['DBASE_TYPE'])) {
         self::$error = DB::$error;
         return false;
     }
     DB::set_caching(false);
     $ret = DB::connect($_POST['DBASE_USER'], $_POST['DBASE_PASS'], $_POST['DBASE_NAME'], $_POST['DBASE_SERVER']);
     if ($ret == false) {
         self::$error = DB::$error;
         return false;
     }
     if (!DB::select($_POST['DBASE_NAME'])) {
         self::$error = DB::$error;
         return false;
     }
     DB::$throw_exceptions = false;
     echo '<h2>Writing Tables...</h2>';
     $sqlLines = self::readSQLFile(SITE_ROOT . '/install/sql/install.sql', $_POST['TABLE_PREFIX']);
     foreach ($sqlLines as $sql) {
         DB::query($sql['sql']);
         if (DB::errno() != 0) {
             #echo 'failed - manually run this query: <br /><br />"'.$sql.'"';
             echo '<div id="error" style="text-align: left;">Writing "' . $sql['table'] . '" table... ';
             echo "<br /><br />" . DB::error();
             echo '</div>';
         }
     }
     echo "Wrote {$totalTables} tables<br />";
     echo '<h2>Populating Initial Data...</h2>';
     $sqlLines = self::readSQLFile(SITE_ROOT . '/install/fixtures/install.sql', $_POST['TABLE_PREFIX']);
     foreach ($sqlLines as $sql) {
         DB::query($sql['sql']);
         if (DB::errno() != 0) {
             echo '<div id="error" style="text-align: left;">Writing to "' . $sql['table'] . '" table... ';
             echo "<br /><br />" . DB::error();
             echo '</div>';
         }
     }
     return true;
 }
Exemplo n.º 30
0
    /**
     * Remove a user from a group (pass the ID or the name)
     */
    public static function RemoveUserFromGroup($pilotid, $groupid)
    {
        $pilotid = DB::escape($pilotid);
        $groupid = DB::escape($groupid);
        if (!is_numeric($groupid)) {
            $groupid = self::getGroupID($groupid);
        }
        $sql = 'DELETE FROM ' . TABLE_PREFIX . 'groupmembers
					WHERE pilotid=' . $pilotid . ' AND groupid=' . $groupid;
        $res = DB::query($sql);
        if (DB::errno() != 0) {
            return false;
        }
        return true;
    }