Ejemplo n.º 1
1
    function v($k, $v = false, $nr = false)
    {
        $a = isset($this->config[$k]) ? $this->config[$k] : false;
        if ($nr !== false && $v !== false) {
            $this->config[$k] = $v;
            return $v;
        }
        if ($v !== false) {
            $sql_update = array('config_value' => $v);
            if ($a !== false) {
                $sql = 'UPDATE _config SET ' . _build_array('UPDATE', $sql_update) . sql_filter('
					WHERE config_name = ?', $k);
            } else {
                $sql_update['config_name'] = $k;
                $sql = 'INSERT INTO _config' . _build_array('INSERT', $sql_update);
            }
            _sql($sql);
            $this->config[$k] = $a = $v;
        }
        return $a;
    }
Ejemplo n.º 2
0
    public function home()
    {
        global $user;
        $v = $this->__(w('alias filename ext'));
        if (!f($v['alias']) || !f($v['filename'])) {
            _fatal();
        }
        $sql = 'SELECT tree_id
			FROM _tree
			WHERE tree_alias = ?';
        if (!($tree = _fieldrow(sql_filter($sql, $v['alias'])))) {
            _fatal();
        }
        $sql = 'SELECT *
			FROM _downloads
			WHERE download_alias = ?
				AND download_tree = ?';
        if (!($download = _fieldrow(sql_filter($sql, $v['filename'], $tree['tree_id'])))) {
            _fatal();
        }
        if ($download['download_login']) {
            _login();
        }
        $sql = 'UPDATE _downloads SET download_count = download_count + 1
			WHERE download_id = ?';
        _sql(sql_filter($sql, $download['download_id']));
        $filepath = LIB . 'fetch/' . _filename($download['download_id'], $download['download_extension']);
        return;
    }
Ejemplo n.º 3
0
 function sqlresult($sql)
 {
     $result = '';
     $tt1 = _sql($sql);
     if (@mysql_num_rows($tt1) > 0) {
         $result = mysql_result($tt1, 0);
     }
     @mysql_free_result($tt1);
     return $result;
 }
Ejemplo n.º 4
0
    protected function _create_home()
    {
        if (_button()) {
            $v = $this->__(array('codigo', 'nombre', 'apellido', 'direccion', 'edad', 'sexo', 'email', 'telefono', 'identificacion', 'status', 'carne', 'carne_auto' => 0));
            /*
            padre_nombre
            padre_apellido
            
            madre_nombre
            madre_apellido
            
            encargado_nombre
            encargado_apellido
            encargado_profesion
            encargado_labora
            encargando_labora_direccion
            
            encargado_identificacion
            encargado_emergencia
            */
            $sql = 'INSERT INTO _students' . _build_array('INSERT', $v);
            $v['id'] = _sql_nextid($sql);
            if ($v['carne_auto']) {
                $v['carne'] = date('Y') . $v['id'];
                $sql = 'UPDATE _students SET carne = ?
					WHERE id_alumno = ?';
                _sql(sql_filter($sql, $v['carne'], $v['id']));
            }
            $sql_insert = '';
            // TODO: Build query
            $sql = 'INSERT INTO _registrations' . _build_array('INSERT', '');
        }
        $sql = 'SELECT grade_id, grade_name
			FROM _grades
			WHERE grade_status = 1
			ORDER BY grade_order';
        $grades = _rowset($sql);
        foreach ($grades as $i => $row) {
            if (!$i) {
                _style('grades');
            }
            _style('grades.row', array('GRADE_ID' => $row['grade_id'], 'GRADE_NAME' => $row['grade_name']));
        }
        $sql = 'SELECT section_id, section_name
			FROM _sections
			WHERE section_grade = 1';
        $sections = _rowset($sql);
        foreach ($sections as $i => $row) {
            if (!$i) {
                _style('sections');
            }
            _style('sections.row', array('SECTION_ID' => $row['section_id'], 'SECTION_NAME' => $row['section_name']));
        }
        return;
    }
Ejemplo n.º 5
0
    public function home()
    {
        $sql = 'SELECT *
			FROM _store s, _store_fields f
			WHERE s.store_field = f.field_id
			ORDER BY store_field';
        $store = _rowset($sql, 'store_assoc', false, true);
        $a_country = array('Alemania' => 82, 'Argentina' => 10, 'Bolivia' => 26, 'Chile' => 43, 'Colombia' => 47, 'Ecuador' => 63, 'El Salvador' => 65, 'Espana' => 197, 'Francia' => 74, 'Greece' => 85, 'Guatemala' => 90, 'Honduras' => 97, 'Italia' => 107, 'Mexico' => 140, 'Paraguay' => 168, 'Peru' => 169, 'Uruguay' => 227, 'Venezuela' => 230);
        foreach ($store as $i => $row) {
            $nickname = '';
            $address = '';
            $birthday = '';
            $country = '';
            foreach ($row as $field) {
                switch ($field['field_alias']) {
                    case 'nickname':
                        $nickname = $field['store_value'];
                        break;
                    case 'address':
                        $address = $field['store_value'];
                        break;
                    case 'birthday':
                        $temp = explode('/', $field['store_value']);
                        $birthday = $temp[2] . '' . $temp[1] . '' . $temp[0];
                        break;
                    case 'country':
                        $country = $a_country[$field['store_value']];
                        break;
                }
            }
            $sql_insert = array('type' => 1, 'active' => 0, 'username' => $nickname, 'password' => '', 'registration' => time(), 'lastvisit' => 0, 'lastpage' => '', 'country' => $country, 'email' => $address, 'birthday' => $birthday, 'birthday_last' => 0, 'gender' => 0, 'date' => 0, 'dateformat' => 'd M Y H:i', 'timezone' => -6, 'dst' => 0, 'login_tries' => 0);
            $sql = 'INSERT INTO _members' . _build_array('INSERT', prefix('user', $sql_insert));
            _sql($sql);
            //_pre($sql);
        }
        $this->e('Done.');
        return;
    }
Ejemplo n.º 6
0
    function home()
    {
        $sql = 'SELECT *
			FROM _members
			WHERE user_type = ?
				AND user_birthday LIKE ?
				AND user_birthday_last < ?
			ORDER BY user_username
			LIMIT ??';
        $birthday = _rowset(sql_filter($sql, 1, '%' . date('md'), date('Y'), 10));
        if (!$birthday) {
            $this->e('None.');
        }
        $process = w();
        foreach ($birthday as $i => $row) {
            if (!$i) {
                @set_time_limit(0);
                require XFS . 'core/emailer.php';
                $emailer = new emailer();
            }
            $emailer->format('plain');
            $emailer->from('TWC Kaulitz <*****@*****.**>');
            $emailer->use_template('user_birthday');
            $emailer->email_address($row['user_email']);
            $emailer->assign_vars(array('USERNAME' => $row['user_username']));
            $emailer->send();
            $emailer->reset();
            $process[$row['user_id']] = $row['user_username'];
        }
        if (count($process)) {
            $sql = 'UPDATE _members SET user_birthday_last = ?
				WHERE user_id IN (??)';
            _sql(sql_filter($sql, date('Y'), _implode(',', array_keys($process))));
        }
        return $this->e('Done @ ' . implode(',', array_values($process)));
    }
Ejemplo n.º 7
0
    protected function _groups_remove()
    {
        gfatal();
        global $core;
        $v = $this->__(array('el' => 0));
        $sql = 'SELECT group_id
			FROM _groups
			WHERE group_id = ?';
        if (!($group = _fieldrow(sql_filter($sql, $v['el'])))) {
            $this->_error('#GROUPS_NO_EXISTS');
        }
        $sql = 'SELECT ticket_id
			FROM _tickets
			WHERE ticket_group = ?';
        if (_fieldrow(sql_filter($sql, $v['el']))) {
            $this->_error('#GROUP_CANT_REMOVE_TICKETS');
        }
        $sql = 'DELETE FROM _groups
			WHERE group_id = ?';
        _sql(sql_filter($sql, $v['el']));
        $sql = 'DELETE FROM _groups_members
			WHERE member_group = ?';
        _sql(sql_filter($sql, $v['el']));
        $core->cache_unload();
        return $this->e('~OK');
    }
Ejemplo n.º 8
0
    public function home()
    {
        global $core;
        error_reporting(0);
        $v = $this->__(w('v'));
        if (!$v['v']) {
            $sql = 'SELECT media_id
				FROM _bio_media
				WHERE media_type = ?
					AND media_mp3 = ?
				LIMIT 1';
            $v['v'] = _field(sql_filter($sql, 1, 0), 'media_id', 0);
        }
        $tag_format = 'UTF-8';
        $relative_path = '/data/artists/%s/media/';
        $absolute_path = '/var/www/vhosts/rockrepublik.net/www' . $relative_path;
        $sql = 'SELECT m.*, b.bio_id, b.bio_name
			FROM _bio_media m
			LEFT JOIN _bio b ON m.media_bio = b.bio_id
			WHERE m.media_id = ?';
        //$spaths = '/data/artists/' . $songd['ub'] . '/media/';
        //$spath = '/var/www/vhosts/rockrepublik.net/httpdocs' . $spaths;
        if ($media = _fieldrow(sql_filter($sql, $v['v']))) {
            $row_relative = sprintf($relative_path, $media['bio_id']);
            $row_absolute = $absolute_path . $row_relative;
            $row_wma = $row_absolute . $media['media_id'] . '.wma';
            $row_mp3 = $row_absolute . $media['media_id'] . '.mp3';
            $rel_wma = '.' . $row_relative . $media['media_id'] . '.wma';
            $rel_mp3 = '.' . $row_relative . $media['media_id'] . '.mp3';
            if (@file_exists($rel_wma) && !@file_exists($rel_mp3) && !$media['media_mp3']) {
                exec('ffmpeg -i ' . $row_wma . ' -vn -ar 44100 -ac 2 -ab 64kb -f mp3 ' . $row_mp3);
                include_once XFS . XCOR . 'getid3/getid3.php';
                $getID3 = new getID3();
                $getID3->setOption(array('encoding' => $tag_format));
                getid3_lib::IncludeDependency(GETID3_INCLUDEPATH . 'write.php', __FILE__, true);
                $tagwriter = new getid3_writetags();
                $tagwriter->filename = getid3_lib::SafeStripSlashes($row_mp3);
                $tagwriter->tagformats = array('id3v1');
                $tagwriter->overwrite_tags = true;
                $tagwriter->tag_encoding = $tag_format;
                $tagwriter->remove_other_tags = true;
                $tag_comment = 'Visita www.rockrepublik.net';
                $media['album'] = !empty($media['media_album']) ? $media['media_album'] : 'Single';
                $media['genre'] = !empty($media['media_genre']) ? $media['media_genre'] : 'Rock';
                $media_f = array('title', 'name', 'album', 'genre');
                foreach ($media_f as $mr) {
                    $media['media_' . $mr] = getid3_lib::SafeStripSlashes(utf8_encode(html_entity_decode($media['media_' . $mr])));
                }
                $tagwriter->tag_data = array('title' => array($media['media_title']), 'artist' => array($media['media_name']), 'album' => array($media['media_album']), 'year' => array(getid3_lib::SafeStripSlashes($media['media_year'])), 'genre' => array($media['media_genre']), 'comment' => array(getid3_lib::SafeStripSlashes($tag_comment)), 'tracknumber' => array(''));
                $tagwriter->WriteTags();
                $sql = 'UPDATE _bio_media SET media_mp3 = ?
					WHERE media_id = ?';
                _sql(sql_filter($sql, 1, $media['media_id']));
                $fp = @fopen('./conv.txt', 'a+');
                fwrite($fp, $row_mp3 . "\n");
                fclose($fp);
            }
            if (!@file_exists($rel_wma)) {
                $sql = 'UPDATE _bio_media SET media_mp3 = ?
					WHERE media_id = ?';
                _sql(sql_filter($sql, 2, $media['media_id']));
            }
        }
        $sql = 'SELECT media_id
			FROM _bio_media
			WHERE media_type = ?
				AND media_mp3 = ?
			LIMIT 1';
        if ($v_next = _field(sql_filter($sql, 1, 0), 'media_id', 0)) {
            sleep(1);
            _redirect(_link($this->m(), array('v' => $v_next)));
        } else {
            $this->e('no_next');
        }
        return $this->e('.');
    }
Ejemplo n.º 9
0
/**
* Function where all data changes are executed
*/
function change_database_data(&$no_updates, $version)
{
    global $db, $map_dbms, $errored, $error_ary, $config, $phpbb_root_path;
    switch ($version) {
        case '2.0.B3':
            _sql('INSERT INTO ' . GARAGE_CONFIG_TABLE . " (config_name, config_value) VALUES ('enable_blogs_smilies', '1')", $errored, $error_ary);
            _sql('INSERT INTO ' . GARAGE_CONFIG_TABLE . " (config_name, config_value) VALUES ('enable_blogs_url', '1')", $errored, $error_ary);
            _sql('INSERT INTO ' . GARAGE_CONFIG_TABLE . " (config_name, config_value) VALUES ('enable_make_approval', '1')", $errored, $error_ary);
            _sql('INSERT INTO ' . GARAGE_CONFIG_TABLE . " (config_name, config_value) VALUES ('enable_model_approval', '1')", $errored, $error_ary);
            _sql('INSERT INTO ' . GARAGE_CONFIG_TABLE . " (config_name, config_value) VALUES ('enable_guestbooks_url', '1')", $errored, $error_ary);
            _sql('INSERT INTO ' . GARAGE_CONFIG_TABLE . " (config_name, config_value) VALUES ('enable_guestbooks_smilies', '1')", $errored, $error_ary);
            $no_updates = false;
            break;
    }
}
Ejemplo n.º 10
0
    protected function _attend_home()
    {
        global $bio;
        if (!is_ghost()) {
            _fatal();
        }
        if (!$bio->v('auth_member')) {
            _login();
        }
        $v = $this->__(_array_keys(w('event option'), 0));
        if (!$v['event'] || !$v['option']) {
            _fatal();
        }
        $sql = 'SELECT event_id
			FROM _events
			WHERE event_id = ?';
        if (!_fieldrow($sql, $v['event'])) {
            _fatal();
        }
        $sql = 'SELECT type_id
			FROM _events_attend_type
			WHERE type_id = ?';
        if (!_fieldrow(sql_filter($sql, $v['option']))) {
            _fatal();
        }
        $sql = 'SELECT attend_id
			FROM _events_attend
			WHERE attend_event = ?
				AND attend_uid = ?';
        if ($attend_id = _field(sql_filter($sql, $v['event'], $bio->v('bio_id')), 'attend_id', 0)) {
            $sql = 'UPDATE _events SET attend_option = ?
				WHERE attend_id = ?';
            _sql(sql_filter($sql, $v['option'], $attend_id));
        } else {
            $sql_insert = array('attend_event' => $v['event'], 'attend_uid' => $bio->v('bio_id'), 'attend_option' => $v['option'], 'attend_time' => time());
            sql_put('_events_attend', $sql_insert);
        }
        return $this->e('~OK');
    }
Ejemplo n.º 11
0
    protected function _friend_deny()
    {
        global $bio;
        if (!$bio->v('auth_member')) {
            _login();
        }
        $v = $this->__(w('a'));
        $sql = 'SELECT bio_id
			FROM _bio
			WHERE bio_alias = ?';
        if (!($bio_id = _field(sql_filter($sql, $v['a']), 'bio_id', 0))) {
            _fatal();
        }
        $sql = 'SELECT friend_id, friend_pending
			FROM _bio_friends
			WHERE friend_assoc = ?
				AND friend_bio = ?';
        if (!($friend = _fieldrow(sql_filter($sql, $bio_id, $bio->v('bio_id'))))) {
            _fatal();
        }
        if (!$friend['friend_pending']) {
            _fatal();
        }
        $sql = 'DELETE FROM _bio_friends
			WHERE friend_id = ?';
        _sql(sql_filter($sql, $friend['friend_id']));
        return;
    }
Ejemplo n.º 12
0
    protected function _members_profile()
    {
        global $bio;
        $sql = 'SELECT *
			FROM _bio_store
			ORDER BY a_field';
        $profiles = _rowset($sql);
        foreach ($profiles as $row) {
            $field_id = 0;
            if (isset($cache[$row['a_field']])) {
                $field_id = $cache[$row['a_field']];
            }
            if (!$field_id) {
                $sql = 'SELECT *
					FROM _bio_fields
					WHERE field_display = ?';
                if ($members_fields = _fieldrow(sql_filter($sql, $row['a_field']))) {
                    $field_id = $members_fields['field_id'];
                    $cache[$row['a_field']] = $field_id;
                }
            }
            if (!$field_id) {
                $sql_insert = array('field_alias' => $row['a_field'], 'field_name' => $row['a_field'], 'field_display' => $row['a_field'], 'field_required' => 0, 'field_unique' => 0, 'field_unique_global' => 0, 'field_show' => 1, 'field_length' => 0, 'field_type' => 'text', 'field_relation' => '', 'field_function' => '', 'field_js' => '');
                $field_id = sql_put('_bio_fields', $sql_insert);
            }
            $sql = 'UPDATE _bio_store SET a_field = ?
				WHERE a_id = ?';
            _sql(sql_filter($sql, $field_id, $row['a_id']));
        }
        $sql = "ALTER TABLE _bio_store\r\n\t\t\tCHANGE a_field a_field INT(11) NOT NULL DEFAULT '0'";
        _sql($sql);
        $this->_e('Done!');
        return;
    }
Ejemplo n.º 13
0
    protected function _download_home()
    {
        global $user;
        $v = $this->__(array('f'));
        if (!f($v['f'])) {
            _fatal();
        }
        $sql = 'SELECT *
			FROM _downloads
			WHERE download_alias = ?';
        if (!($download = _fieldrow(sql_filter($sql, $v['f'])))) {
            _fatal();
        }
        $sql = 'UPDATE _downloads
			SET download_count = download_count + 1
			WHERE download_id = ?';
        _sql(sql_filter($sql, $download['download_id']));
        sql_close();
        $orig = array('#\\.#', '#\\&(\\w)(acute|tilde)\\;#');
        $repl = array('', '\\1');
        $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|');
        $filename = preg_replace($orig, $repl, $download['download_title']) . '.' . $download['download_extension'];
        $filename = preg_replace("/%(\\w{2})/", '_', rawurlencode(str_replace($bad_chars, '_', $filename)));
        $filepath = LIB . 'get/' . $download['download_id'] . '.' . $download['download_extension'];
        // Headers
        header('Content-Type: application/octet-stream; name="' . $filename . '"');
        header('Content-Disposition: attachment; filename="' . $filename . '"');
        header('Accept-Ranges: bytes');
        header('Pragma: no-cache');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Content-transfer-encoding: binary');
        header('Content-length: ' . @filesize($filepath));
        @readfile($filepath);
        exit;
    }
Ejemplo n.º 14
0
function change_database_data(&$no_updates, $version)
{
	global $db, $errored, $error_ary, $config, $phpbb_root_path, $phpEx;

	switch ($version)
	{
		case '3.0.0':

			$sql = 'UPDATE ' . TOPICS_TABLE . "
				SET topic_last_view_time = topic_last_post_time
				WHERE topic_last_view_time = 0";
			_sql($sql, $errored, $error_ary);

			// Update smiley sizes
			$smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif');

			foreach ($smileys as $smiley)
			{
				if (file_exists($phpbb_root_path . 'images/smilies/' . $smiley))
				{
					list($width, $height) = getimagesize($phpbb_root_path . 'images/smilies/' . $smiley);

					$sql = 'UPDATE ' . SMILIES_TABLE . '
						SET smiley_width = ' . $width . ', smiley_height = ' . $height . "
						WHERE smiley_url = '" . $db->sql_escape($smiley) . "'";

					_sql($sql, $errored, $error_ary);
				}
			}

			$no_updates = false;
		break;

		// No changes from 3.0.1-RC1 to 3.0.1
		case '3.0.1-RC1':
		break;

		// changes from 3.0.1 to 3.0.2-RC1
		case '3.0.1':

			set_config('referer_validation', '1');
			set_config('check_attachment_content', '1');
			set_config('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title');

			$no_updates = false;
		break;

		// No changes from 3.0.2-RC1 to 3.0.2-RC2
		case '3.0.2-RC1':
		break;

		// No changes from 3.0.2-RC2 to 3.0.2
		case '3.0.2-RC2':
		break;

		// Changes from 3.0.2 to 3.0.3-RC1
		case '3.0.2':
			set_config('enable_queue_trigger', '0');
			set_config('queue_trigger_posts', '3');

			set_config('pm_max_recipients', '0');

			// Set maximum number of recipients for the registered users, bots, guests group
			$sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5
				WHERE ' . $db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS'));
			_sql($sql, $errored, $error_ary);

			// Not prefilling yet
			set_config('dbms_version', '');

			// Add new permission u_masspm_group and duplicate settings from u_masspm
			include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
			$auth_admin = new auth_admin();

			// Only add the new permission if it does not already exist
			if (empty($auth_admin->acl_options['id']['u_masspm_group']))
			{
				$auth_admin->acl_add_option(array('global' => array('u_masspm_group')));

				// Now the tricky part, filling the permission
				$old_id = $auth_admin->acl_options['id']['u_masspm'];
				$new_id = $auth_admin->acl_options['id']['u_masspm_group'];

				$tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE);

				foreach ($tables as $table)
				{
					$sql = 'SELECT *
						FROM ' . $table . '
						WHERE auth_option_id = ' . $old_id;
					$result = _sql($sql, $errored, $error_ary);

					$sql_ary = array();
					while ($row = $db->sql_fetchrow($result))
					{
						$row['auth_option_id'] = $new_id;
						$sql_ary[] = $row;
					}
					$db->sql_freeresult($result);

					if (sizeof($sql_ary))
					{
						$db->sql_multi_insert($table, $sql_ary);
					}
				}

				// Remove any old permission entries
				$auth_admin->acl_clear_prefetch();
			}

			/**
			* Do not resync post counts here. An admin may do this later from the ACP
			$start = 0;
			$step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;

			$sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0';
			_sql($sql, $errored, $error_ary);

			do
			{
				$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
					FROM ' . POSTS_TABLE . '
					WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
						AND post_postcount = 1 AND post_approved = 1
					GROUP BY poster_id';
				$result = _sql($sql, $errored, $error_ary);

				if ($row = $db->sql_fetchrow($result))
				{
					do
					{
						$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
						_sql($sql, $errored, $error_ary);
					}
					while ($row = $db->sql_fetchrow($result));

					$start += $step;
				}
				else
				{
					$start = 0;
				}
				$db->sql_freeresult($result);
			}
			while ($start);
			*/

			$sql = 'UPDATE ' . MODULES_TABLE . '
				SET module_auth = \'acl_a_email && cfg_email_enable\'
				WHERE module_class = \'acp\'
					AND module_basename = \'email\'';
			_sql($sql, $errored, $error_ary);

			$no_updates = false;
		break;

		// Changes from 3.0.3-RC1 to 3.0.3
		case '3.0.3-RC1':
			if ($db->sql_layer == 'oracle')
			{
				// log_operation is CLOB - but we can change this later
				$sql = 'UPDATE ' . LOG_TABLE . "
					SET log_operation = 'LOG_DELETE_TOPIC'
					WHERE log_operation LIKE 'LOG_TOPIC_DELETED'";
				_sql($sql, $errored, $error_ary);
			}
			else
			{
				$sql = 'UPDATE ' . LOG_TABLE . "
					SET log_operation = 'LOG_DELETE_TOPIC'
					WHERE log_operation = 'LOG_TOPIC_DELETED'";
				_sql($sql, $errored, $error_ary);
			}

			$no_updates = false;
		break;

		// Changes from 3.0.3 to 3.0.4-RC1
		case '3.0.3':
			// Update the Custom Profile Fields based on previous settings to the new format
			$sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide
					FROM ' . PROFILE_FIELDS_TABLE;
			$result = _sql($sql, $errored, $error_ary);

			while ($row = $db->sql_fetchrow($result))
			{
				$sql_ary = array(
					'field_required'	=> 0,
					'field_show_on_reg'	=> 0,
					'field_hide'		=> 0,
					'field_show_profile'=> 0,
				);

				if ($row['field_required'])
				{
					$sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
				}
				else if ($row['field_show_on_reg'])
				{
					$sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
				}
				else if ($row['field_hide'])
				{
					// Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module
					$sql_ary['field_hide'] = 1;
				}
				else
				{
					// equivelant to "none", which is the "Display in user control panel" option
					$sql_ary['field_show_profile'] = 1;
				}

				_sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary);
			}
			$no_updates = false;

		break;

		// Changes from 3.0.4-RC1 to 3.0.4
		case '3.0.4-RC1':
		break;

		// Changes from 3.0.4 to 3.0.5-RC1
		case '3.0.4':

			// Captcha config variables
			set_config('captcha_gd_wave', 0);
			set_config('captcha_gd_3d_noise', 1);
			set_config('captcha_gd_fonts', 1);
			set_config('confirm_refresh', 1);

			// Maximum number of keywords
			set_config('max_num_search_keywords', 10);

			// Remove static config var and put it back as dynamic variable
			$sql = 'UPDATE ' . CONFIG_TABLE . "
				SET is_dynamic = 1
				WHERE config_name = 'search_indexing_state'";
			_sql($sql, $errored, $error_ary);

			// Hash old MD5 passwords
			$sql = 'SELECT user_id, user_password
					FROM ' . USERS_TABLE . '
					WHERE user_pass_convert = 1';
			$result = _sql($sql, $errored, $error_ary);

			while ($row = $db->sql_fetchrow($result))
			{
				if (strlen($row['user_password']) == 32)
				{
					$sql_ary = array(
						'user_password'	=> phpbb_hash($row['user_password']),
					);

					_sql('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id'], $errored, $error_ary);
				}
			}
			$db->sql_freeresult($result);

			// Adjust bot entry
			$sql = 'UPDATE ' . BOTS_TABLE . "
				SET bot_agent = 'ichiro/'
				WHERE bot_agent = 'ichiro/2'";
			_sql($sql, $errored, $error_ary);


			// Before we are able to add a unique key to auth_option, we need to remove duplicate entries

			// We get duplicate entries first
			$sql = 'SELECT auth_option
				FROM ' . ACL_OPTIONS_TABLE . '
				GROUP BY auth_option
				HAVING COUNT(*) >= 2';
			$result = $db->sql_query($sql);

			$auth_options = array();
			while ($row = $db->sql_fetchrow($result))
			{
				$auth_options[] = $row['auth_option'];
			}
			$db->sql_freeresult($result);

			// Remove specific auth options
			if (!empty($auth_options))
			{
				foreach ($auth_options as $option)
				{
					// Select auth_option_ids... the largest id will be preserved
					$sql = 'SELECT auth_option_id
						FROM ' . ACL_OPTIONS_TABLE . "
						WHERE auth_option = '" . $db->sql_escape($option) . "'
						ORDER BY auth_option_id DESC";
					// sql_query_limit not possible here, due to bug in postgresql layer
					$result = $db->sql_query($sql);

					// Skip first row, this is our original auth option we want to preserve
					$row = $db->sql_fetchrow($result);

					while ($row = $db->sql_fetchrow($result))
					{
						// Ok, remove this auth option...
						_sql('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
						_sql('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
						_sql('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
						_sql('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
					}
					$db->sql_freeresult($result);
				}
			}

			// Now make auth_option UNIQUE, by dropping the old index and adding a UNIQUE one.
			$changes = array(
				'drop_keys'			=> array(
					ACL_OPTIONS_TABLE		=> array('auth_option'),
				),
			);

			global $db_tools;

			$statements = $db_tools->perform_schema_changes($changes);

			foreach ($statements as $sql)
			{
				_sql($sql, $errored, $error_ary);
			}

			$changes = array(
				'add_unique_index'	=> array(
					ACL_OPTIONS_TABLE		=> array(
						'auth_option'		=> array('auth_option'),
					),
				),
			);

			$statements = $db_tools->perform_schema_changes($changes);

			foreach ($statements as $sql)
			{
				_sql($sql, $errored, $error_ary);
			}

			$no_updates = false;

		break;

		// No changes from 3.0.5-RC1 to 3.0.5
		case '3.0.5-RC1':
		break;

		// Changes from 3.0.5 to 3.0.6-RC1
		case '3.0.5':
			// Let's see if the GD Captcha can be enabled... we simply look for what *is* enabled...
			if (!empty($config['captcha_gd']) && !isset($config['captcha_plugin']))
			{
				set_config('captcha_plugin', 'phpbb_captcha_gd');
			}
			else if (!isset($config['captcha_plugin']))
			{
				set_config('captcha_plugin', 'phpbb_captcha_nogd');
			}

			// Entries for the Feed Feature
			set_config('feed_enable', '0');
			set_config('feed_limit', '10');

			set_config('feed_overall_forums', '1');
			set_config('feed_overall_forums_limit', '15');

			set_config('feed_overall_topics', '0');
			set_config('feed_overall_topics_limit', '15');

			set_config('feed_forum', '1');
			set_config('feed_topic', '1');
			set_config('feed_item_statistics', '1');

			// Entries for smiley pagination
			set_config('smilies_per_page', '50');

			// Entry for reporting PMs
			set_config('allow_pm_report', '1');

			// Install modules
			$modules_to_install = array(
				'feed'					=> array(
					'base'		=> 'board',
					'class'		=> 'acp',
					'title'		=> 'ACP_FEED_SETTINGS',
					'auth'		=> 'acl_a_board',
					'cat'		=> 'ACP_BOARD_CONFIGURATION',
					'after'		=> array('signature', 'ACP_SIGNATURE_SETTINGS')
				),
				'warnings'				=> array(
					'base'		=> 'users',
					'class'		=> 'acp',
					'title'		=> 'ACP_USER_WARNINGS',
					'auth'		=> 'acl_a_user',
					'display'	=> 0,
					'cat'		=> 'ACP_CAT_USERS',
					'after'		=> array('feedback', 'ACP_USER_FEEDBACK')
				),
				'send_statistics'		=> array(
					'base'		=> 'send_statistics',
					'class'		=> 'acp',
					'title'		=> 'ACP_SEND_STATISTICS',
					'auth'		=> 'acl_a_server',
					'cat'		=> 'ACP_SERVER_CONFIGURATION'
				),
				'setting_forum_copy'	=> array(
					'base'		=> 'permissions',
					'class'		=> 'acp',
					'title'		=> 'ACP_FORUM_PERMISSIONS_COPY',
					'auth'		=> 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth',
					'cat'		=> 'ACP_FORUM_BASED_PERMISSIONS',
					'after'		=> array('setting_forum_local', 'ACP_FORUM_PERMISSIONS')
				),
				'pm_reports'			=> array(
					'base'		=> 'pm_reports',
					'class'		=> 'mcp',
					'title'		=> 'MCP_PM_REPORTS_OPEN',
					'auth'		=> 'aclf_m_report',
					'cat'		=> 'MCP_REPORTS'
				),
				'pm_reports_closed'		=> array(
					'base'		=> 'pm_reports',
					'class'		=> 'mcp',
					'title'		=> 'MCP_PM_REPORTS_CLOSED',
					'auth'		=> 'aclf_m_report',
					'cat'		=> 'MCP_REPORTS'
				),
				'pm_report_details'		=> array(
					'base'		=> 'pm_reports',
					'class'		=> 'mcp',
					'title'		=> 'MCP_PM_REPORT_DETAILS',
					'auth'		=> 'aclf_m_report',
					'cat'		=> 'MCP_REPORTS'
				),
			);

			_add_modules($modules_to_install);

			// Add newly_registered group... but check if it already exists (we always supported running the updater on any schema)
			$sql = 'SELECT group_id
				FROM ' . GROUPS_TABLE . "
				WHERE group_name = 'NEWLY_REGISTERED'";
			$result = $db->sql_query($sql);
			$group_id = (int) $db->sql_fetchfield('group_id');
			$db->sql_freeresult($result);

			if (!$group_id)
			{
				$sql = 'INSERT INTO ' .  GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)";
				_sql($sql, $errored, $error_ary);

				$group_id = $db->sql_nextid();
			}

			// Insert new user role... at the end of the chain
			$sql = 'SELECT role_id
				FROM ' . ACL_ROLES_TABLE . "
				WHERE role_name = 'ROLE_USER_NEW_MEMBER'
					AND role_type = 'u_'";
			$result = $db->sql_query($sql);
			$u_role = (int) $db->sql_fetchfield('role_id');
			$db->sql_freeresult($result);

			if (!$u_role)
			{
				$sql = 'SELECT MAX(role_order) as max_order_id
					FROM ' . ACL_ROLES_TABLE . "
					WHERE role_type = 'u_'";
				$result = $db->sql_query($sql);
				$next_order_id = (int) $db->sql_fetchfield('max_order_id');
				$db->sql_freeresult($result);

				$next_order_id++;

				$sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)";
				_sql($sql, $errored, $error_ary);
				$u_role = $db->sql_nextid();

				if (!$errored)
				{
					// Now add the correct data to the roles...
					// The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups
					$sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')";
					_sql($sql, $errored, $error_ary);

					// Add user role to group
					$sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)";
					_sql($sql, $errored, $error_ary);
				}
			}

			// Insert new forum role
			$sql = 'SELECT role_id
				FROM ' . ACL_ROLES_TABLE . "
				WHERE role_name = 'ROLE_FORUM_NEW_MEMBER'
					AND role_type = 'f_'";
			$result = $db->sql_query($sql);
			$f_role = (int) $db->sql_fetchfield('role_id');
			$db->sql_freeresult($result);

			if (!$f_role)
			{
				$sql = 'SELECT MAX(role_order) as max_order_id
					FROM ' . ACL_ROLES_TABLE . "
					WHERE role_type = 'f_'";
				$result = $db->sql_query($sql);
				$next_order_id = (int) $db->sql_fetchfield('max_order_id');
				$db->sql_freeresult($result);

				$next_order_id++;

				$sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES  ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)";
				_sql($sql, $errored, $error_ary);
				$f_role = $db->sql_nextid();

				if (!$errored)
				{
					$sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')";
					_sql($sql, $errored, $error_ary);
				}
			}

			// Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once)
			$sql = 'SELECT 1
				FROM ' . USERS_TABLE . '
				WHERE user_new = 0';
			$result = $db->sql_query_limit($sql, 1);
			$row = $db->sql_fetchrow($result);
			$db->sql_freeresult($result);

			if (!$row)
			{
				$sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0';
				_sql($sql, $errored, $error_ary);
			}

			// Newly registered users limit
			if (!isset($config['new_member_post_limit']))
			{
				set_config('new_member_post_limit', (!empty($config['enable_queue_trigger'])) ? $config['queue_trigger_posts'] : 0);
			}

			if (!isset($config['new_member_group_default']))
			{
				set_config('new_member_group_default', 0);
			}

			// To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts...
			// Check if the role is already assigned...
			$sql = 'SELECT forum_id
				FROM ' . ACL_GROUPS_TABLE . '
				WHERE group_id = ' . $group_id . '
					AND auth_role_id = ' . $f_role;
			$result = $db->sql_query($sql);
			$is_options = (int) $db->sql_fetchfield('forum_id');
			$db->sql_freeresult($result);

			// Not assigned at all... :/
			if (!$is_options)
			{
				// Get postable forums
				$sql = 'SELECT forum_id
					FROM ' . FORUMS_TABLE . '
					WHERE forum_type != ' . FORUM_LINK;
				$result = $db->sql_query($sql);

				while ($row = $db->sql_fetchrow($result))
				{
					_sql('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)', $errored, $error_ary);
				}
				$db->sql_freeresult($result);
			}

			// Clear permissions...
			include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
			$auth_admin = new auth_admin();
			$auth_admin->acl_clear_prefetch();

			if (!isset($config['allow_avatar']))
			{
				if ($config['allow_avatar_upload'] || $config['allow_avatar_local'] || $config['allow_avatar_remote'])
				{
					set_config('allow_avatar', '1');
				}
				else
				{
					set_config('allow_avatar', '0');
				}
			}

			if (!isset($config['allow_avatar_remote_upload']))
			{
				if ($config['allow_avatar_remote'] && $config['allow_avatar_upload'])
				{
					set_config('allow_avatar_remote_upload', '1');
				}
				else
				{
					set_config('allow_avatar_remote_upload', '0');
				}
			}

			// Minimum number of characters
			if (!isset($config['min_post_chars']))
			{
				set_config('min_post_chars', '1');
			}

			if (!isset($config['allow_quick_reply']))
			{
				set_config('allow_quick_reply', '1');
			}

			// Set every members user_options column to enable
			// bbcode, smilies and URLs for signatures by default
			$sql = 'SELECT user_options
				FROM ' . USERS_TABLE . '
				WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
			$result = $db->sql_query_limit($sql, 1);
			$user_option = (int) $db->sql_fetchfield('user_options');
			$db->sql_freeresult($result);

			// Check if we already updated the database by checking bit 15 which we used to store the sig_bbcode option
			if (!($user_option & 1 << 15))
			{
				// 229376 is the added value to enable all three signature options
				$sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376';
				_sql($sql, $errored, $error_ary);
			}

			if (!isset($config['delete_time']))
			{
				set_config('delete_time', $config['edit_time']);
			}

			$no_updates = false;
		break;

		// No changes from 3.0.6-RC1 to 3.0.6-RC2
		case '3.0.6-RC1':
		break;

		// Changes from 3.0.6-RC2 to 3.0.6-RC3
		case '3.0.6-RC2':

			// Update the Custom Profile Fields based on previous settings to the new format
			$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
				SET field_show_on_vt = 1
				WHERE field_hide = 0
					AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)';
			_sql($sql, $errored, $error_ary);
			$no_updates = false;

		break;

		// No changes from 3.0.6-RC3 to 3.0.6-RC4
		case '3.0.6-RC3':
		break;

		// No changes from 3.0.6-RC4 to 3.0.6
		case '3.0.6-RC4':
		break;

		// Changes from 3.0.6 to 3.0.7-RC1
		case '3.0.6':

			// ATOM Feeds
			set_config('feed_overall', '1');
			set_config('feed_http_auth', '0');
			set_config('feed_limit_post', (string) (isset($config['feed_limit']) ? (int) $config['feed_limit'] : 15));
			set_config('feed_limit_topic', (string) (isset($config['feed_overall_topics_limit']) ? (int) $config['feed_overall_topics_limit'] : 10));
			set_config('feed_topics_new', (!empty($config['feed_overall_topics']) ? '1' : '0'));
			set_config('feed_topics_active', (!empty($config['feed_overall_topics']) ? '1' : '0'));

			// Delete all text-templates from the template_data
			$sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
				WHERE template_filename ' . $db->sql_like_expression($db->any_char . '.txt');
			_sql($sql, $errored, $error_ary);

			$no_updates = false;
		break;

		// Changes from 3.0.7-RC1 to 3.0.7-RC2
		case '3.0.7-RC1':

			$sql = 'SELECT user_id, user_email, user_email_hash
				FROM ' . USERS_TABLE . '
				WHERE user_type <> ' . USER_IGNORE . "
					AND user_email <> ''";
			$result = $db->sql_query($sql);

			$i = 0;
			while ($row = $db->sql_fetchrow($result))
			{
				// Snapshot of the phpbb_email_hash() function
				// We cannot call it directly because the auto updater updates the DB first. :/
				$user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']);

				if ($user_email_hash != $row['user_email_hash'])
				{
					$sql_ary = array(
						'user_email_hash'	=> $user_email_hash,
					);

					$sql = 'UPDATE ' . USERS_TABLE . '
						SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
						WHERE user_id = ' . (int) $row['user_id'];
					_sql($sql, $errored, $error_ary, ($i % 100 == 0));

					++$i;
				}
			}
			$db->sql_freeresult($result);

			$no_updates = false;

		break;

		// No changes from 3.0.7-RC2 to 3.0.7
		case '3.0.7-RC2':
		break;

		// No changes from 3.0.7 to 3.0.7-PL1
		case '3.0.7':
		break;
	}
}
Ejemplo n.º 15
0
    public function _gallery_create()
    {
        global $bio, $core;
        if (_button()) {
            $upload = _import('upload');
            // Start
            $sql = 'SELECT MAX(image_id) AS total
				FROM _bio_images
				WHERE image_bio = ?';
            $image = sql_field(sql_filter($sql, $this->a('bio_id')), 'total', 0) + 1;
            $upload->chmod(array(_lib(LIB_BIO . ' ' . $this->a('bio_id'))), 0777);
            $f = $upload->process(LIB . 'tmp/', request_var('files:picture'), w('jpg'), $core->v('max_upload'));
            if ($f === false && count($upload->error)) {
                $warning->set($upload->error);
            }
            if (!$warning->exist) {
                $total = 0;
                foreach ($f as $row) {
                    //$row = $upload->_row($gallery, $image);
                    $f2 = $upload->resize($row, LIB . 'tmp', LIB . 'events/future/', $v['e_id'], array(600, 400), false, false, true);
                    if ($f2 === false) {
                        continue;
                    }
                    $f3 = $upload->resize($row, LIB . 'events/future/', LIB . 'events/preview/', $v['e_id'], array(210, 210), false, false);
                    $total++;
                    //
                    $sql_insert = array('bio' => $bio->v('bio_id'), 'image' => $image, 'width' => $i_data['width'], 'height' => $i_data['height'], 'views' => 0, 'downloads' => 0, 'allow_dl' => (int) $allow_dl);
                    sql_put('_bio_images', prefix('image', $sql_insert));
                    $image++;
                }
                $sql = 'UPDATE _bio_store SET store_value = store_value + ??
					WHERE store_bio = ?';
                _sql(sql_filter($sql, $total, $bio->v('bio_id')));
            }
            if (!$error) {
                redirect(_link_control('a', array('a' => $bio->v('bio_alias'), 'x1' => $this->x(1))));
            }
        }
        return v_style(array('U_CREATE' => _link_bio($bio->v('bio_alias'), array('x1' => $this->x(1), 'x2' => $this->x(2))), 'MAX_FILESIZE' => $core - v('max_upload')));
    }
Ejemplo n.º 16
0
$sql[] = "ALTER TABLE " . USERS_TABLE . " ADD admin_allow_points TINYINT(1) DEFAULT '1' NOT NULL";
$sql[] = "INSERT INTO " . CONFIG_TABLE . " VALUES ('points_reply', '1')";
$sql[] = "INSERT INTO " . CONFIG_TABLE . " VALUES ('points_topic', '2')";
$sql[] = "INSERT INTO " . CONFIG_TABLE . " VALUES ('points_post', '1')";
$sql[] = "INSERT INTO " . CONFIG_TABLE . " VALUES ('points_donate', '1')";
$sql[] = "INSERT INTO " . CONFIG_TABLE . " VALUES ('points_name', 'Points')";
$sql[] = "INSERT INTO " . CONFIG_TABLE . " VALUES ('points_user_group_auth_ids', '')";
$sql[] = "INSERT INTO " . CONFIG_TABLE . " VALUES ('points_system_version', '2.0.9')";
echo '<h2>Updating database schema & data</h2>' . "\n";
echo '<p>Progress :: <b>';
flush();
$error_ary = array();
$errored = false;
if (count($sql)) {
    for ($i = 0; $i < count($sql); $i++) {
        _sql($sql[$i], $errored, $error_ary);
    }
    echo '</b> <b class="ok">Done</b><br />Result &nbsp; :: ' . "\n";
    if ($errored) {
        echo '<b>Some queries failed, the statements and errors are listing below</b>' . "\n";
        echo '<ul>';
        for ($i = 0; $i < count($error_ary['sql']); $i++) {
            echo '<li>Error :: <b>' . $error_ary['error_code'][$i]['message'] . '</b><br />';
            echo 'SQL &nbsp; :: <b>' . $error_ary['sql'][$i] . '</b><br /><br /></li>';
        }
        echo '</ul>' . "\n";
        echo '<p>Contact me so I can fix the errors.</p>' . "\n";
        exit;
    } else {
        echo '<b>No errors</b>' . "\n";
    }
Ejemplo n.º 17
0
    public final function _install()
    {
        global $core;
        // TODO: Improve module installation!
        // Pre run check
        if (!($modules = $core->cache_load('modules'))) {
            $sql = 'SELECT *
				FROM _modules
				ORDER BY module_name';
            $modules = $core->cache_store(_rowset($sql));
        }
        $run_install = true;
        foreach ($modules as $row) {
            if ($row['module_alias'] === $this->m()) {
                $run_install = false;
            }
        }
        // Run module install
        if ($run_install) {
            $proc = $this->install();
            // Post install
            $sql_insert = array('alias' => $this->m(), 'name' => $proc['NAME'], 'author' => $proc['AUTHOR'], 'link' => $proc['LINK']);
            $sql = 'INSERT INTO _modules' . _build_array('INSERT', prefix('module', $sql_insert));
            _sql($sql);
        }
        return;
    }
Ejemplo n.º 18
0
Archivo: bio.php Proyecto: nopticon/mag
    public function auth_remove($f, $uid = false)
    {
        global $core;
        if ($uid === false) {
            $uid = $this->v('bio_id');
        }
        $field = $this->auth_field($f);
        if ($field !== false) {
            if (!isset($this->auth[$uid][$field['field_alias']])) {
                return;
            }
            $sql = 'DELETE FROM _bio_auth
				WHERE auth_bio = ?
					AND auth_field = ?';
            _sql(sql_filter($sql, $uid, $field['field_id']));
            unset($this->auth[$uid][$field['field_alias']]);
            $core->cache_unload();
        }
        return;
    }
Ejemplo n.º 19
0
    public function home()
    {
        global $user;
        $v = $this->__(array('faddr', 'nickname', 'address', 'birthday' => array('' => 0), 'country' => 0));
        foreach (w('year month day') as $name) {
            $v['birthday'][$name] = isset($v['birthday'][$name]) ? $v['birthday'][$name] : '';
        }
        if (f($v['faddr'])) {
            $v['address'] = $v['faddr'];
        }
        if (_button()) {
            if (!f($v['address']) || !f($v['nickname'])) {
                $this->error('COMPLETE_FIELDS');
            }
            if (f($v['address'])) {
                $sql = 'SELECT user_id
					FROM _members
					WHERE user_email = ?';
                if (_field(sql_filter($sql, $v['address']), 'user_id', 0)) {
                    $this->error('EMAIL_EXISTS');
                }
                if (!preg_match('/^[a-z0-9&\'\\.\\-_\\+]+@[a-z0-9\\-]+\\.([a-z0-9\\-]+\\.)*?[a-z]+$/is', $v['address'])) {
                    $this->error('EMAIL_BAD');
                }
            }
            $sql = 'SELECT country_id
				FROM _countries
				WHERE country_id = ?';
            if (!_field(sql_filter($sql, $v['country']), 'country_id', 0)) {
                $this->error('NO_COUNTRY');
            }
            if (!$this->errors()) {
                $v['birthday'] = _zero($v['birthday']['year']) . _zero($v['birthday']['month']) . _zero($v['birthday']['day']);
                $sql_insert = array('type' => 1, 'active' => 0, 'username' => $v['nickname'], 'password' => '', 'registration' => time(), 'lastvisit' => '', 'lastpage' => '', 'country' => $v['country'], 'email' => $v['address'], 'birthday' => $v['birthday'], 'gender' => 0, 'dateformat' => 'd M Y H:i', 'timezone' => 0, 'dst' => 0);
                $sql = 'INSERT INTO _members' . _build_array('INSERT', prefix('user', $sql_insert));
                _sql($sql);
                require XFS . 'core/emailer.php';
                $emailer = new emailer();
                $emailer->format('plain');
                $emailer->from('TWC Kaulitz <*****@*****.**>');
                $emailer->use_template('welcome');
                $emailer->email_address($v['address']);
                $emailer->assign_vars(array('USERNAME' => $v['nickname']));
                $emailer->send();
                $emailer->reset();
                //
                redirect('http://www.twckaulitz.com/', false);
            }
        }
        if ($this->errors()) {
            _style('errors', array('MSG' => $this->get_errors()));
        }
        for ($i = 1; $i < 32; $i++) {
            _style('days', array('DAY' => $i));
        }
        $months = w('Enero Febrero Marzo Abril Mayo Junio Julio Agosto Septiembre Octubre Noviembre Diciembre');
        foreach ($months as $i => $row) {
            _style('months', array('VALUE' => $i + 1, 'MONTH' => $row));
        }
        for ($i = 2005; $i > 1899; $i--) {
            _style('years', array('YEAR' => $i));
        }
        //
        // GeoIP
        //
        include XFS . 'core/geoip.php';
        $gi = geoip_open(XFS . 'core/GeoIP.dat', GEOIP_STANDARD);
        $geoip_code = strtolower(geoip_country_code_by_addr($gi, $user->ip));
        $sql = 'SELECT *
			FROM _countries
			ORDER BY country_name';
        $countries = _rowset($sql);
        $codes = w();
        foreach ($countries as $row) {
            $codes[$row['country_short']] = $row['country_id'];
            _style('countries', array('VALUE' => $row['country_id'], 'NAME' => $row['country_name']));
        }
        if (!$v['country']) {
            $v['country'] = isset($codes[$geoip_code]) ? $codes[$geoip_code] : $codes['gt'];
        }
        v_style(array('NICKNAME' => $v['nickname'], 'ADDRESS' => $v['address'], 'COUNTRY' => $v['country'], 'BIRTHDAY_YEAR' => $v['birthday']['year'], 'BIRTHDAY_MONTH' => $v['birthday']['month'], 'BIRTHDAY_DAY' => $v['birthday']['day']));
        return;
    }
/**
* Change column type (not name!)
*/
function sql_column_change($dbms, $table_name, $column_name, $column_data)
{
	global $dbms_type_map, $db;
	global $errored, $error_ary;

	$column_data = prepare_column_data($dbms, $column_data, $table_name, $column_name);

	switch ($dbms)
	{
		case 'firebird':
			// Change type...
			$sql = 'ALTER TABLE "' . $table_name . '" ALTER COLUMN "' . $column_name . '" TYPE ' . ' ' . $column_data['column_type_sql'];
			_sql($sql, $errored, $error_ary);
		break;

		case 'mssql':
			$sql = 'ALTER TABLE [' . $table_name . '] ALTER COLUMN [' . $column_name . '] ' . $column_data['column_type_sql'];
			_sql($sql, $errored, $error_ary);
		break;

		case 'mysql_40':
		case 'mysql_41':
			$sql = 'ALTER TABLE `' . $table_name . '` CHANGE `' . $column_name . '` `' . $column_name . '` ' . $column_data['column_type_sql'];
			_sql($sql, $errored, $error_ary);
		break;

		case 'oracle':
			$sql = 'ALTER TABLE ' . $table_name . ' MODIFY ' . $column_name . ' ' . $column_data['column_type_sql'];
			_sql($sql, $errored, $error_ary);
		break;

		case 'postgres':
			$sql = 'ALTER TABLE ' . $table_name . ' ';

			$sql_array = array();
			$sql_array[] = 'ALTER COLUMN ' . $column_name . ' TYPE ' . $column_data['column_type'];

			if (isset($column_data['null']))
			{
				if ($column_data['null'] == 'NOT NULL')
				{
					$sql_array[] = 'ALTER COLUMN ' . $column_name . ' SET NOT NULL';
				}
				else if ($column_data['null'] == 'NULL')
				{
					$sql_array[] = 'ALTER COLUMN ' . $column_name . ' DROP NOT NULL';
				}
			}

			if (isset($column_data['default']))
			{
				$sql_array[] = 'ALTER COLUMN ' . $column_name . ' SET DEFAULT ' . $column_data['default'];
			}

			// we don't want to double up on constraints if we change different number data types
			if (isset($column_data['constraint']))
			{
				$constraint_sql = "SELECT consrc as constraint_data
							FROM pg_constraint, pg_class bc
							WHERE conrelid = bc.oid
								AND bc.relname = '{$table_name}'
								AND NOT EXISTS (
									SELECT *
										FROM pg_constraint as c, pg_inherits as i
										WHERE i.inhrelid = pg_constraint.conrelid
											AND c.conname = pg_constraint.conname
											AND c.consrc = pg_constraint.consrc
											AND c.conrelid = i.inhparent
								)";

				$constraint_exists = false;

				$result = $db->sql_query($constraint_sql);
				while ($row = $db->sql_fetchrow($result))
				{
					if (trim($row['constraint_data']) == trim($column_data['constraint']))
					{
						$constraint_exists = true;
						break;
					}
				}
				$db->sql_freeresult($result);

				if (!$constraint_exists)
				{
					$sql_array[] = 'ADD ' . $column_data['constraint'];
				}
			}

			$sql .= implode(', ', $sql_array);

			_sql($sql, $errored, $error_ary);
		break;

		case 'sqlite':

			$sql = "SELECT sql
				FROM sqlite_master
				WHERE type = 'table'
					AND name = '{$table_name}'
				ORDER BY type DESC, name;";
			$result = _sql($sql, $errored, $error_ary);

			if (!$result)
			{
				break;
			}

			$row = $db->sql_fetchrow($result);
			$db->sql_freeresult($result);

			$db->sql_transaction('begin');

			// Create a temp table and populate it, destroy the existing one
			$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']));
			$db->sql_query('INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name);
			$db->sql_query('DROP TABLE ' . $table_name);

			preg_match('#\((.*)\)#s', $row['sql'], $matches);

			$new_table_cols = trim($matches[1]);
			$old_table_cols = preg_split('/,(?![\s\w]+\))/m', $new_table_cols);
			$column_list = array();

			foreach ($old_table_cols as $key => $declaration)
			{
				$entities = preg_split('#\s+#', trim($declaration));
				$column_list[] = $entities[0];
				if ($entities[0] == $column_name)
				{
					$old_table_cols[$key] = $column_name . ' ' . $column_data['column_type_sql'];
				}
			}

			$columns = implode(',', $column_list);

			// create a new table and fill it up. destroy the temp one
			$db->sql_query('CREATE TABLE ' . $table_name . ' (' . implode(',', $old_table_cols) . ');');
			$db->sql_query('INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;');
			$db->sql_query('DROP TABLE ' . $table_name . '_temp');

			$db->sql_transaction('commit');

		break;
	}
}
Ejemplo n.º 21
0
    protected function _create_home()
    {
        global $user;
        $v = $tree = $this->init();
        $z = $this->__(w('zmode'));
        if (_button()) {
            $v_ary = array('subject', 'content');
            if ($user->v('is_founder')) {
                $v_ary = array_merge($v_ary, array('node' => 0, 'parent' => 0, 'level' => 0, 'module' => 0, 'alias', 'child_hide' => 0, 'child_order', 'nav' => 0, 'nav_hide' => 0, 'css_parent' => 0, 'css_var', 'quickload' => 0, 'dynamic' => 0, 'tags', 'template', 'redirect', 'description', 'allow_comments' => 0, 'approve_comments' => 0, 'form' => 0, 'form_email', 'published', 'move'));
            }
            $v = $this->__($v_ary);
            /*
            $v = $this->__(array(
            	'node' => 0,
            	'parent' => 0,
            	'level' => 0,
            	'module' => 0,
            	'alias',
            	'child_hide' => 0,
            	'child_order',
            	'nav' => 0,
            	'nav_hide' => 0,
            	'css_parent' => 0,
            	'css_var',
            	'quickload' => 0,
            	'dynamic' => 0,
            	'tags',
            	'template',
            	'redirect',
            	'subject',
            	'content',
            	'description',
            	'allow_comments' => 0,
            	'approve_comments' => 0,
            	'form' => 0,
            	'form_email',
            	'published',
            	'move'
            ));
            */
            //
            $v['edited'] = time();
            foreach (w('node level parent module') as $row) {
                $v[$row] = $tree['tree_' . $row];
            }
            if ($z['zmode'] == 'create') {
                $v['parent'] = $tree['tree_id'];
                $v['level']++;
                if (!$v['node']) {
                    $v['node'] = $v['parent'];
                }
            }
            // Parse vars
            foreach ($v as $row_k => $row_v) {
                switch ($row_k) {
                    case 'subject':
                        $row_v = $this->html($row_v, 'strong');
                        break;
                    case 'content':
                        $row_v = $this->html($row_v);
                        break;
                    case 'alias':
                        $row_v = _alias($row_v, w('_'), '-');
                        break;
                    case 'checksum':
                        $row_v = _hash($v['content']);
                        break;
                    case 'published':
                        $row_v = dvar($row_v, date('d m Y'));
                        $e_date = explode(' ', $row_v);
                        $row_v = _timestamp($e_date[1], $e_date[0], $e_date[2]);
                        break;
                }
                $v[$row_k] = $row_v;
            }
            if ($z['zmode'] == 'modify' && $tree['tree_alias'] == 'home' && $v['alias'] != 'home') {
                $v['alias'] = 'home';
            }
            if (f($v['alias'])) {
                $sql = 'SELECT tree_id
					FROM _tree
					WHERE tree_alias = ?
						AND tree_id <> ?';
                if (_fieldrow(sql_filter($sql, $v['alias'], $tree['tree_id']))) {
                    $this->_error('#ALIAS_IN_USE');
                }
            }
            if ($z['zmode'] == 'modify') {
                if ($v['move']) {
                    $mv_field = !is_numb($v['move']) ? 'alias' : 'id';
                    $sql = 'SELECT *
						FROM _tree
						WHERE tree_?? = ?';
                    if ($mv_tree = _fieldrow(sql_filter($sql, $mv_field, $v['move']))) {
                        $mv_insert = array('module' => $mv_tree['module_id'], 'node' => $mv_tree['tree_node'], 'parent' => $mv_tree['tree_id'], 'level' => $mv_tree['tree_level'] + 1);
                        $sql = 'UPDATE _tree SET ' . _build_array('UPDATE', prefix('tree', $mv_insert)) . sql_filter('
							WHERE article_id = ?', $tree['tree_id']);
                        _sql($sql);
                        $sql = 'UPDATE _tree SET tree_childs = tree_childs - 1
							WHERE tree_id = ?';
                        _sql(sql_filter($sql, $tree['tree_parent']));
                        $sql = 'UPDATE _tree SET tree_childs = tree_childs + 1
							WHERE tree_id = ?';
                        _sql(sql_filter($sql, $mv_tree['tree_id']));
                    }
                }
                unset($v['move']);
                // Check input values against database
                foreach ($v as $row_k => $row_v) {
                    if ($tree['tree_' . $row_k] == $row_v) {
                        unset($v[$row_k]);
                    }
                }
                if (!(count($v) - 1)) {
                    unset($v['edited']);
                }
            } else {
                unset($v['move']);
            }
            //
            $u_tree = _rewrite($tree);
            if (count($v)) {
                if (isset($v['content']) && $v['content']) {
                    $v['content'] = str_replace(w('&lt; &gt;'), w('< >'), $v['content']);
                }
                if ($z['zmode'] == 'create') {
                    $sql = 'INSERT INTO _tree' . _build_array('INSERT', prefix('tree', $v));
                } else {
                    $sql = 'UPDATE _tree SET ' . _build_array('UPDATE', prefix('tree', $v)) . sql_filter('
						WHERE tree_id = ?', $tree['tree_id']);
                }
                _sql($sql);
                if ($z['zmode'] == 'create') {
                    $u_tree = f($v['alias']) ? $v['alias'] : _nextid();
                    $sql = 'UPDATE _tree
						SET tree_childs = tree_childs + 1
						WHERE tree_id = ?';
                    _sql(sql_filter($sql, $tree['tree_id']));
                }
            }
            redirect(_link($u_tree));
        }
        //
        // Show fieldset
        /*$v_fieldset = array(
        			'subject',
        			'content',
        			'description',
        			'alias',
        			'child_hide' => 0,
        			'child_order',
        			'nav' => 0,
        			'nav_hide' => 0,
        			'css_parent',
        			'css_var',
        			'quickload' => 0,
        			'dynamic' => 0,
        			'tags',
        			'template',
        			'redirect',
        			'allow_comments' => 0,
        			'approve_comments' => 0,
        			'form' => 0,
        			'form_email',
        			'published'
        		);
        		*/
        $v_fieldset = array('subject', 'content');
        if ($user->v('is_founder')) {
            $v_fieldset = array_merge($v_fieldset, array('description', 'alias', 'child_hide' => 0, 'child_order', 'nav' => 0, 'nav_hide' => 0, 'css_parent', 'css_var', 'quickload' => 0, 'dynamic' => 0, 'tags', 'template', 'redirect', 'allow_comments' => 0, 'approve_comments' => 0, 'form' => 0, 'form_email', 'published'));
        }
        $is_modify = $z['zmode'] == 'modify';
        foreach (_array_keys($v_fieldset, '') as $k => $row) {
            $name = 'tree_' . $k;
            $cp_lang = _lang('CP_' . $k);
            $value = $is_modify ? isset($v[$k]) ? $v[$k] : (isset($tree[$name]) ? $tree[$name] : '') : '';
            $checked = is_numb($row) && $is_modify && $tree[$name] ? ' checked="checked"' : '';
            if (f($value)) {
                switch ($k) {
                    case 'published':
                        $value = date('d m Y', $value);
                        break;
                }
            }
            $type = 'text';
            if (is_numb($row)) {
                $value = 1;
                $type = 'checkbox';
            }
            $tag = 'input';
            if ($k == 'content') {
                $tag = 'textarea';
            }
            _style('field', array('NAME' => $k, 'ID' => $k, 'TAG' => $tag, 'TYPE' => $type, 'VALUE' => $value, 'LANG' => $cp_lang, 'CHECKED' => $checked));
            if ($k == 'template') {
                $i = 0;
                $fp = @opendir('./style/custom/');
                while ($row_d = @readdir($fp)) {
                    if (_extension($row_d) != 'htm') {
                        continue;
                    }
                    if (!$i) {
                        _style('field.templated');
                        _style('field.templated.row', array('V' => '', 'FILE' => _lang('NONE')));
                    }
                    $v_file = str_replace('.htm', '', $row_d);
                    _style('field.templated.row', array('V' => $v_file, 'FILE' => $v_file));
                    $i++;
                }
                @closedir($fp);
            }
            //
        }
        $cp_format = !$is_modify ? 'CREATE' : 'MODIFY';
        v_style(array('CP_PAGE' => sprintf(_lang('CP_PAGE_' . $cp_format), $tree['tree_subject'])));
        return;
    }
Ejemplo n.º 22
0
function change_database_data(&$no_updates, $version)
{
    global $db, $db_tools, $errored, $error_ary, $config, $table_prefix, $phpbb_root_path, $phpEx;
    switch ($version) {
        case '3.0.0':
            $sql = 'UPDATE ' . TOPICS_TABLE . "\n\t\t\t\tSET topic_last_view_time = topic_last_post_time\n\t\t\t\tWHERE topic_last_view_time = 0";
            _sql($sql, $errored, $error_ary);
            // Update smiley sizes
            $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif');
            foreach ($smileys as $smiley) {
                if (file_exists($phpbb_root_path . 'images/smilies/' . $smiley)) {
                    list($width, $height) = getimagesize($phpbb_root_path . 'images/smilies/' . $smiley);
                    $sql = 'UPDATE ' . SMILIES_TABLE . '
						SET smiley_width = ' . $width . ', smiley_height = ' . $height . "\n\t\t\t\t\t\tWHERE smiley_url = '" . $db->sql_escape($smiley) . "'";
                    _sql($sql, $errored, $error_ary);
                }
            }
            $no_updates = false;
            break;
            // No changes from 3.0.1-RC1 to 3.0.1
        // No changes from 3.0.1-RC1 to 3.0.1
        case '3.0.1-RC1':
            break;
            // changes from 3.0.1 to 3.0.2-RC1
        // changes from 3.0.1 to 3.0.2-RC1
        case '3.0.1':
            set_config('referer_validation', '1');
            set_config('check_attachment_content', '1');
            set_config('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title');
            $no_updates = false;
            break;
            // No changes from 3.0.2-RC1 to 3.0.2-RC2
        // No changes from 3.0.2-RC1 to 3.0.2-RC2
        case '3.0.2-RC1':
            break;
            // No changes from 3.0.2-RC2 to 3.0.2
        // No changes from 3.0.2-RC2 to 3.0.2
        case '3.0.2-RC2':
            break;
            // Changes from 3.0.2 to 3.0.3-RC1
        // Changes from 3.0.2 to 3.0.3-RC1
        case '3.0.2':
            set_config('enable_queue_trigger', '0');
            set_config('queue_trigger_posts', '3');
            set_config('pm_max_recipients', '0');
            // Set maximum number of recipients for the registered users, bots, guests group
            $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5
				WHERE ' . $db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS'));
            _sql($sql, $errored, $error_ary);
            // Not prefilling yet
            set_config('dbms_version', '');
            // Add new permission u_masspm_group and duplicate settings from u_masspm
            include_once $phpbb_root_path . 'includes/acp/auth.' . $phpEx;
            $auth_admin = new auth_admin();
            // Only add the new permission if it does not already exist
            if (empty($auth_admin->acl_options['id']['u_masspm_group'])) {
                $auth_admin->acl_add_option(array('global' => array('u_masspm_group')));
                // Now the tricky part, filling the permission
                $old_id = $auth_admin->acl_options['id']['u_masspm'];
                $new_id = $auth_admin->acl_options['id']['u_masspm_group'];
                $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE);
                foreach ($tables as $table) {
                    $sql = 'SELECT *
						FROM ' . $table . '
						WHERE auth_option_id = ' . $old_id;
                    $result = _sql($sql, $errored, $error_ary);
                    $sql_ary = array();
                    while ($row = $db->sql_fetchrow($result)) {
                        $row['auth_option_id'] = $new_id;
                        $sql_ary[] = $row;
                    }
                    $db->sql_freeresult($result);
                    if (sizeof($sql_ary)) {
                        $db->sql_multi_insert($table, $sql_ary);
                    }
                }
                // Remove any old permission entries
                $auth_admin->acl_clear_prefetch();
            }
            /**
            * Do not resync post counts here. An admin may do this later from the ACP
            $start = 0;
            $step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
            
            $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0';
            _sql($sql, $errored, $error_ary);
            
            do
            {
            	$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
            		FROM ' . POSTS_TABLE . '
            		WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
            			AND post_postcount = 1 AND post_approved = 1
            		GROUP BY poster_id';
            	$result = _sql($sql, $errored, $error_ary);
            
            	if ($row = $db->sql_fetchrow($result))
            	{
            		do
            		{
            			$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
            			_sql($sql, $errored, $error_ary);
            		}
            		while ($row = $db->sql_fetchrow($result));
            
            		$start += $step;
            	}
            	else
            	{
            		$start = 0;
            	}
            	$db->sql_freeresult($result);
            }
            while ($start);
            */
            $sql = 'UPDATE ' . MODULES_TABLE . '
				SET module_auth = \'acl_a_email && cfg_email_enable\'
				WHERE module_class = \'acp\'
					AND module_basename = \'email\'';
            _sql($sql, $errored, $error_ary);
            $no_updates = false;
            break;
            // Changes from 3.0.3-RC1 to 3.0.3
        // Changes from 3.0.3-RC1 to 3.0.3
        case '3.0.3-RC1':
            if ($db->sql_layer == 'oracle') {
                // log_operation is CLOB - but we can change this later
                $sql = 'UPDATE ' . LOG_TABLE . "\n\t\t\t\t\tSET log_operation = 'LOG_DELETE_TOPIC'\n\t\t\t\t\tWHERE log_operation LIKE 'LOG_TOPIC_DELETED'";
                _sql($sql, $errored, $error_ary);
            } else {
                $sql = 'UPDATE ' . LOG_TABLE . "\n\t\t\t\t\tSET log_operation = 'LOG_DELETE_TOPIC'\n\t\t\t\t\tWHERE log_operation = 'LOG_TOPIC_DELETED'";
                _sql($sql, $errored, $error_ary);
            }
            $no_updates = false;
            break;
            // Changes from 3.0.3 to 3.0.4-RC1
        // Changes from 3.0.3 to 3.0.4-RC1
        case '3.0.3':
            // Update the Custom Profile Fields based on previous settings to the new format
            $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide
					FROM ' . PROFILE_FIELDS_TABLE;
            $result = _sql($sql, $errored, $error_ary);
            while ($row = $db->sql_fetchrow($result)) {
                $sql_ary = array('field_required' => 0, 'field_show_on_reg' => 0, 'field_hide' => 0, 'field_show_profile' => 0);
                if ($row['field_required']) {
                    $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
                } else {
                    if ($row['field_show_on_reg']) {
                        $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
                    } else {
                        if ($row['field_hide']) {
                            // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module
                            $sql_ary['field_hide'] = 1;
                        } else {
                            // equivelant to "none", which is the "Display in user control panel" option
                            $sql_ary['field_show_profile'] = 1;
                        }
                    }
                }
                _sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary);
            }
            $no_updates = false;
            break;
            // Changes from 3.0.4-RC1 to 3.0.4
        // Changes from 3.0.4-RC1 to 3.0.4
        case '3.0.4-RC1':
            break;
            // Changes from 3.0.4 to 3.0.5-RC1
        // Changes from 3.0.4 to 3.0.5-RC1
        case '3.0.4':
            // Captcha config variables
            set_config('captcha_gd_wave', 0);
            set_config('captcha_gd_3d_noise', 1);
            set_config('captcha_gd_fonts', 1);
            set_config('confirm_refresh', 1);
            // Maximum number of keywords
            set_config('max_num_search_keywords', 10);
            // Remove static config var and put it back as dynamic variable
            $sql = 'UPDATE ' . CONFIG_TABLE . "\n\t\t\t\tSET is_dynamic = 1\n\t\t\t\tWHERE config_name = 'search_indexing_state'";
            _sql($sql, $errored, $error_ary);
            // Hash old MD5 passwords
            $sql = 'SELECT user_id, user_password
					FROM ' . USERS_TABLE . '
					WHERE user_pass_convert = 1';
            $result = _sql($sql, $errored, $error_ary);
            while ($row = $db->sql_fetchrow($result)) {
                if (strlen($row['user_password']) == 32) {
                    $sql_ary = array('user_password' => phpbb_hash($row['user_password']));
                    _sql('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id'], $errored, $error_ary);
                }
            }
            $db->sql_freeresult($result);
            // Adjust bot entry
            $sql = 'UPDATE ' . BOTS_TABLE . "\n\t\t\t\tSET bot_agent = 'ichiro/'\n\t\t\t\tWHERE bot_agent = 'ichiro/2'";
            _sql($sql, $errored, $error_ary);
            // Before we are able to add a unique key to auth_option, we need to remove duplicate entries
            // We get duplicate entries first
            $sql = 'SELECT auth_option
				FROM ' . ACL_OPTIONS_TABLE . '
				GROUP BY auth_option
				HAVING COUNT(*) >= 2';
            $result = $db->sql_query($sql);
            $auth_options = array();
            while ($row = $db->sql_fetchrow($result)) {
                $auth_options[] = $row['auth_option'];
            }
            $db->sql_freeresult($result);
            // Remove specific auth options
            if (!empty($auth_options)) {
                foreach ($auth_options as $option) {
                    // Select auth_option_ids... the largest id will be preserved
                    $sql = 'SELECT auth_option_id
						FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\t\t\tWHERE auth_option = '" . $db->sql_escape($option) . "'\n\t\t\t\t\t\tORDER BY auth_option_id DESC";
                    // sql_query_limit not possible here, due to bug in postgresql layer
                    $result = $db->sql_query($sql);
                    // Skip first row, this is our original auth option we want to preserve
                    $row = $db->sql_fetchrow($result);
                    while ($row = $db->sql_fetchrow($result)) {
                        // Ok, remove this auth option...
                        _sql('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
                        _sql('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
                        _sql('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
                        _sql('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary);
                    }
                    $db->sql_freeresult($result);
                }
            }
            // Now make auth_option UNIQUE, by dropping the old index and adding a UNIQUE one.
            $changes = array('drop_keys' => array(ACL_OPTIONS_TABLE => array('auth_option')));
            $statements = $db_tools->perform_schema_changes($changes);
            foreach ($statements as $sql) {
                _sql($sql, $errored, $error_ary);
            }
            $changes = array('add_unique_index' => array(ACL_OPTIONS_TABLE => array('auth_option' => array('auth_option'))));
            $statements = $db_tools->perform_schema_changes($changes);
            foreach ($statements as $sql) {
                _sql($sql, $errored, $error_ary);
            }
            $no_updates = false;
            break;
            // No changes from 3.0.5-RC1 to 3.0.5
        // No changes from 3.0.5-RC1 to 3.0.5
        case '3.0.5-RC1':
            break;
            // Changes from 3.0.5 to 3.0.6-RC1
        // Changes from 3.0.5 to 3.0.6-RC1
        case '3.0.5':
            // Let's see if the GD Captcha can be enabled... we simply look for what *is* enabled...
            if (!empty($config['captcha_gd']) && !isset($config['captcha_plugin'])) {
                set_config('captcha_plugin', 'phpbb_captcha_gd');
            } else {
                if (!isset($config['captcha_plugin'])) {
                    set_config('captcha_plugin', 'phpbb_captcha_nogd');
                }
            }
            // Entries for the Feed Feature
            set_config('feed_enable', '0');
            set_config('feed_limit', '10');
            set_config('feed_overall_forums', '1');
            set_config('feed_overall_forums_limit', '15');
            set_config('feed_overall_topics', '0');
            set_config('feed_overall_topics_limit', '15');
            set_config('feed_forum', '1');
            set_config('feed_topic', '1');
            set_config('feed_item_statistics', '1');
            // Entries for smiley pagination
            set_config('smilies_per_page', '50');
            // Entry for reporting PMs
            set_config('allow_pm_report', '1');
            // Install modules
            $modules_to_install = array('feed' => array('base' => 'board', 'class' => 'acp', 'title' => 'ACP_FEED_SETTINGS', 'auth' => 'acl_a_board', 'cat' => 'ACP_BOARD_CONFIGURATION', 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS')), 'warnings' => array('base' => 'users', 'class' => 'acp', 'title' => 'ACP_USER_WARNINGS', 'auth' => 'acl_a_user', 'display' => 0, 'cat' => 'ACP_CAT_USERS', 'after' => array('feedback', 'ACP_USER_FEEDBACK')), 'send_statistics' => array('base' => 'send_statistics', 'class' => 'acp', 'title' => 'ACP_SEND_STATISTICS', 'auth' => 'acl_a_server', 'cat' => 'ACP_SERVER_CONFIGURATION'), 'setting_forum_copy' => array('base' => 'permissions', 'class' => 'acp', 'title' => 'ACP_FORUM_PERMISSIONS_COPY', 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS')), 'pm_reports' => array('base' => 'pm_reports', 'class' => 'mcp', 'title' => 'MCP_PM_REPORTS_OPEN', 'auth' => 'aclf_m_report', 'cat' => 'MCP_REPORTS'), 'pm_reports_closed' => array('base' => 'pm_reports', 'class' => 'mcp', 'title' => 'MCP_PM_REPORTS_CLOSED', 'auth' => 'aclf_m_report', 'cat' => 'MCP_REPORTS'), 'pm_report_details' => array('base' => 'pm_reports', 'class' => 'mcp', 'title' => 'MCP_PM_REPORT_DETAILS', 'auth' => 'aclf_m_report', 'cat' => 'MCP_REPORTS'));
            _add_modules($modules_to_install);
            // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema)
            $sql = 'SELECT group_id
				FROM ' . GROUPS_TABLE . "\n\t\t\t\tWHERE group_name = 'NEWLY_REGISTERED'";
            $result = $db->sql_query($sql);
            $group_id = (int) $db->sql_fetchfield('group_id');
            $db->sql_freeresult($result);
            if (!$group_id) {
                $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)";
                _sql($sql, $errored, $error_ary);
                $group_id = $db->sql_nextid();
            }
            // Insert new user role... at the end of the chain
            $sql = 'SELECT role_id
				FROM ' . ACL_ROLES_TABLE . "\n\t\t\t\tWHERE role_name = 'ROLE_USER_NEW_MEMBER'\n\t\t\t\t\tAND role_type = 'u_'";
            $result = $db->sql_query($sql);
            $u_role = (int) $db->sql_fetchfield('role_id');
            $db->sql_freeresult($result);
            if (!$u_role) {
                $sql = 'SELECT MAX(role_order) as max_order_id
					FROM ' . ACL_ROLES_TABLE . "\n\t\t\t\t\tWHERE role_type = 'u_'";
                $result = $db->sql_query($sql);
                $next_order_id = (int) $db->sql_fetchfield('max_order_id');
                $db->sql_freeresult($result);
                $next_order_id++;
                $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', {$next_order_id})";
                _sql($sql, $errored, $error_ary);
                $u_role = $db->sql_nextid();
                if (!$errored) {
                    // Now add the correct data to the roles...
                    // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups
                    $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT {$u_role}, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')";
                    _sql($sql, $errored, $error_ary);
                    // Add user role to group
                    $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ({$group_id}, 0, 0, {$u_role}, 0)";
                    _sql($sql, $errored, $error_ary);
                }
            }
            // Insert new forum role
            $sql = 'SELECT role_id
				FROM ' . ACL_ROLES_TABLE . "\n\t\t\t\tWHERE role_name = 'ROLE_FORUM_NEW_MEMBER'\n\t\t\t\t\tAND role_type = 'f_'";
            $result = $db->sql_query($sql);
            $f_role = (int) $db->sql_fetchfield('role_id');
            $db->sql_freeresult($result);
            if (!$f_role) {
                $sql = 'SELECT MAX(role_order) as max_order_id
					FROM ' . ACL_ROLES_TABLE . "\n\t\t\t\t\tWHERE role_type = 'f_'";
                $result = $db->sql_query($sql);
                $next_order_id = (int) $db->sql_fetchfield('max_order_id');
                $db->sql_freeresult($result);
                $next_order_id++;
                $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES  ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', {$next_order_id})";
                _sql($sql, $errored, $error_ary);
                $f_role = $db->sql_nextid();
                if (!$errored) {
                    $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT {$f_role}, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')";
                    _sql($sql, $errored, $error_ary);
                }
            }
            // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once)
            $sql = 'SELECT 1
				FROM ' . USERS_TABLE . '
				WHERE user_new = 0';
            $result = $db->sql_query_limit($sql, 1);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if (!$row) {
                $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0';
                _sql($sql, $errored, $error_ary);
            }
            // Newly registered users limit
            if (!isset($config['new_member_post_limit'])) {
                set_config('new_member_post_limit', !empty($config['enable_queue_trigger']) ? $config['queue_trigger_posts'] : 0);
            }
            if (!isset($config['new_member_group_default'])) {
                set_config('new_member_group_default', 0);
            }
            // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts...
            // Check if the role is already assigned...
            $sql = 'SELECT forum_id
				FROM ' . ACL_GROUPS_TABLE . '
				WHERE group_id = ' . $group_id . '
					AND auth_role_id = ' . $f_role;
            $result = $db->sql_query($sql);
            $is_options = (int) $db->sql_fetchfield('forum_id');
            $db->sql_freeresult($result);
            // Not assigned at all... :/
            if (!$is_options) {
                // Get postable forums
                $sql = 'SELECT forum_id
					FROM ' . FORUMS_TABLE . '
					WHERE forum_type != ' . FORUM_LINK;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    _sql('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)', $errored, $error_ary);
                }
                $db->sql_freeresult($result);
            }
            // Clear permissions...
            include_once $phpbb_root_path . 'includes/acp/auth.' . $phpEx;
            $auth_admin = new auth_admin();
            $auth_admin->acl_clear_prefetch();
            if (!isset($config['allow_avatar'])) {
                if ($config['allow_avatar_upload'] || $config['allow_avatar_local'] || $config['allow_avatar_remote']) {
                    set_config('allow_avatar', '1');
                } else {
                    set_config('allow_avatar', '0');
                }
            }
            if (!isset($config['allow_avatar_remote_upload'])) {
                if ($config['allow_avatar_remote'] && $config['allow_avatar_upload']) {
                    set_config('allow_avatar_remote_upload', '1');
                } else {
                    set_config('allow_avatar_remote_upload', '0');
                }
            }
            // Minimum number of characters
            if (!isset($config['min_post_chars'])) {
                set_config('min_post_chars', '1');
            }
            if (!isset($config['allow_quick_reply'])) {
                set_config('allow_quick_reply', '1');
            }
            // Set every members user_options column to enable
            // bbcode, smilies and URLs for signatures by default
            $sql = 'SELECT user_options
				FROM ' . USERS_TABLE . '
				WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
            $result = $db->sql_query_limit($sql, 1);
            $user_option = (int) $db->sql_fetchfield('user_options');
            $db->sql_freeresult($result);
            // Check if we already updated the database by checking bit 15 which we used to store the sig_bbcode option
            if (!($user_option & 1 << 15)) {
                // 229376 is the added value to enable all three signature options
                $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376';
                _sql($sql, $errored, $error_ary);
            }
            if (!isset($config['delete_time'])) {
                set_config('delete_time', $config['edit_time']);
            }
            $no_updates = false;
            break;
            // No changes from 3.0.6-RC1 to 3.0.6-RC2
        // No changes from 3.0.6-RC1 to 3.0.6-RC2
        case '3.0.6-RC1':
            break;
            // Changes from 3.0.6-RC2 to 3.0.6-RC3
        // Changes from 3.0.6-RC2 to 3.0.6-RC3
        case '3.0.6-RC2':
            // Update the Custom Profile Fields based on previous settings to the new format
            $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
				SET field_show_on_vt = 1
				WHERE field_hide = 0
					AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)';
            _sql($sql, $errored, $error_ary);
            $no_updates = false;
            break;
            // No changes from 3.0.6-RC3 to 3.0.6-RC4
        // No changes from 3.0.6-RC3 to 3.0.6-RC4
        case '3.0.6-RC3':
            break;
            // No changes from 3.0.6-RC4 to 3.0.6
        // No changes from 3.0.6-RC4 to 3.0.6
        case '3.0.6-RC4':
            break;
            // Changes from 3.0.6 to 3.0.7-RC1
        // Changes from 3.0.6 to 3.0.7-RC1
        case '3.0.6':
            // ATOM Feeds
            set_config('feed_overall', '1');
            set_config('feed_http_auth', '0');
            set_config('feed_limit_post', (string) (isset($config['feed_limit']) ? (int) $config['feed_limit'] : 15));
            set_config('feed_limit_topic', (string) (isset($config['feed_overall_topics_limit']) ? (int) $config['feed_overall_topics_limit'] : 10));
            set_config('feed_topics_new', !empty($config['feed_overall_topics']) ? '1' : '0');
            set_config('feed_topics_active', !empty($config['feed_overall_topics']) ? '1' : '0');
            // Delete all text-templates from the template_data
            $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
				WHERE template_filename ' . $db->sql_like_expression($db->any_char . '.txt');
            _sql($sql, $errored, $error_ary);
            $no_updates = false;
            break;
            // Changes from 3.0.7-RC1 to 3.0.7-RC2
        // Changes from 3.0.7-RC1 to 3.0.7-RC2
        case '3.0.7-RC1':
            $sql = 'SELECT user_id, user_email, user_email_hash
				FROM ' . USERS_TABLE . '
				WHERE user_type <> ' . USER_IGNORE . "\n\t\t\t\t\tAND user_email <> ''";
            $result = $db->sql_query($sql);
            $i = 0;
            while ($row = $db->sql_fetchrow($result)) {
                // Snapshot of the phpbb_email_hash() function
                // We cannot call it directly because the auto updater updates the DB first. :/
                $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']);
                if ($user_email_hash != $row['user_email_hash']) {
                    $sql_ary = array('user_email_hash' => $user_email_hash);
                    $sql = 'UPDATE ' . USERS_TABLE . '
						SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
						WHERE user_id = ' . (int) $row['user_id'];
                    _sql($sql, $errored, $error_ary, $i % 100 == 0);
                    ++$i;
                }
            }
            $db->sql_freeresult($result);
            $no_updates = false;
            break;
            // No changes from 3.0.7-RC2 to 3.0.7
        // No changes from 3.0.7-RC2 to 3.0.7
        case '3.0.7-RC2':
            break;
            // No changes from 3.0.7 to 3.0.7-PL1
        // No changes from 3.0.7 to 3.0.7-PL1
        case '3.0.7':
            break;
            // Changes from 3.0.7-PL1 to 3.0.8-RC1
        // Changes from 3.0.7-PL1 to 3.0.8-RC1
        case '3.0.7-PL1':
            // Update file extension group names to use language strings.
            $sql = 'SELECT lang_dir
				FROM ' . LANG_TABLE;
            $result = $db->sql_query($sql);
            $extension_groups_updated = array();
            while ($lang_dir = $db->sql_fetchfield('lang_dir')) {
                $lang_dir = basename($lang_dir);
                // The language strings we need are either in language/.../acp/attachments.php
                // in the update package if we're updating to 3.0.8-RC1 or later,
                // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier.
                // On an already updated board, they can also already be in language/.../acp/attachments.php
                // in the board root.
                $lang_files = array("{$phpbb_root_path}install/update/new/language/{$lang_dir}/acp/attachments.{$phpEx}", "{$phpbb_root_path}language/{$lang_dir}/install.{$phpEx}", "{$phpbb_root_path}language/{$lang_dir}/acp/attachments.{$phpEx}");
                foreach ($lang_files as $lang_file) {
                    if (!file_exists($lang_file)) {
                        continue;
                    }
                    $lang = array();
                    include $lang_file;
                    foreach ($lang as $lang_key => $lang_val) {
                        if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) {
                            continue;
                        }
                        $sql_ary = array('group_name' => substr($lang_key, 10));
                        $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE group_name = '" . $db->sql_escape($lang_val) . "'";
                        _sql($sql, $errored, $error_ary);
                        $extension_groups_updated[$lang_key] = true;
                    }
                }
            }
            $db->sql_freeresult($result);
            // Install modules
            $modules_to_install = array('post' => array('base' => 'board', 'class' => 'acp', 'title' => 'ACP_POST_SETTINGS', 'auth' => 'acl_a_board', 'cat' => 'ACP_MESSAGES', 'after' => array('message', 'ACP_MESSAGE_SETTINGS')));
            _add_modules($modules_to_install);
            // update
            $sql = 'UPDATE ' . MODULES_TABLE . '
				SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\'
				WHERE module_class = \'ucp\'
					AND module_basename = \'profile\'
					AND module_mode = \'avatar\'';
            _sql($sql, $errored, $error_ary);
            // add Bing Bot
            $bot_name = 'Bing [Bot]';
            $bot_name_clean = utf8_clean_string($bot_name);
            $sql = 'SELECT user_id
				FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username_clean = '" . $db->sql_escape($bot_name_clean) . "'";
            $result = $db->sql_query($sql);
            $bing_already_added = (bool) $db->sql_fetchfield('user_id');
            $db->sql_freeresult($result);
            if (!$bing_already_added) {
                $bot_agent = 'bingbot/';
                $bot_ip = '';
                $sql = 'SELECT group_id, group_colour
					FROM ' . GROUPS_TABLE . "\n\t\t\t\t\tWHERE group_name = 'BOTS'";
                $result = $db->sql_query($sql);
                $group_row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!$group_row) {
                    // default fallback, should never get here
                    $group_row['group_id'] = 6;
                    $group_row['group_colour'] = '9E8DA7';
                }
                if (!function_exists('user_add')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                $user_row = array('user_type' => USER_IGNORE, 'group_id' => $group_row['group_id'], 'username' => $bot_name, 'user_regdate' => time(), 'user_password' => '', 'user_colour' => $group_row['group_colour'], 'user_email' => '', 'user_lang' => $config['default_lang'], 'user_style' => $config['default_style'], 'user_timezone' => 0, 'user_dateformat' => $config['default_dateformat'], 'user_allow_massemail' => 0);
                $user_id = user_add($user_row);
                $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array('bot_active' => 1, 'bot_name' => (string) $bot_name, 'user_id' => (int) $user_id, 'bot_agent' => (string) $bot_agent, 'bot_ip' => (string) $bot_ip));
                _sql($sql, $errored, $error_ary);
            }
            // end Bing Bot addition
            // Delete shadow topics pointing to not existing topics
            $batch_size = 500;
            // Set of affected forums we have to resync
            $sync_forum_ids = array();
            do {
                $sql_array = array('SELECT' => 't1.topic_id, t1.forum_id', 'FROM' => array(TOPICS_TABLE => 't1'), 'LEFT_JOIN' => array(array('FROM' => array(TOPICS_TABLE => 't2'), 'ON' => 't1.topic_moved_id = t2.topic_id')), 'WHERE' => 't1.topic_moved_id <> 0
								AND t2.topic_id IS NULL');
                $sql = $db->sql_build_query('SELECT', $sql_array);
                $result = $db->sql_query_limit($sql, $batch_size);
                $topic_ids = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $topic_ids[] = (int) $row['topic_id'];
                    $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id'];
                }
                $db->sql_freeresult($result);
                if (!empty($topic_ids)) {
                    $sql = 'DELETE FROM ' . TOPICS_TABLE . '
						WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
                    $db->sql_query($sql);
                }
            } while (sizeof($topic_ids) == $batch_size);
            // Sync the forums we have deleted shadow topics from.
            sync('forum', 'forum_id', $sync_forum_ids, true, true);
            // Unread posts search load switch
            set_config('load_unreads_search', '1');
            // Reduce queue interval to 60 seconds, email package size to 20
            if ($config['queue_interval'] == 600) {
                set_config('queue_interval', '60');
            }
            if ($config['email_package_size'] == 50) {
                set_config('email_package_size', '20');
            }
            $no_updates = false;
            break;
            // No changes from 3.0.8-RC1 to 3.0.8
        // No changes from 3.0.8-RC1 to 3.0.8
        case '3.0.8-RC1':
            break;
            // Changes from 3.0.8 to 3.0.9-RC1
        // Changes from 3.0.8 to 3.0.9-RC1
        case '3.0.8':
            set_config('ip_login_limit_max', '50');
            set_config('ip_login_limit_time', '21600');
            set_config('ip_login_limit_use_forwarded', '0');
            // Update file extension group names to use language strings, again.
            $sql = 'SELECT group_id, group_name
				FROM ' . EXTENSION_GROUPS_TABLE . '
				WHERE group_name ' . $db->sql_like_expression('EXT_GROUP_' . $db->any_char);
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $sql_ary = array('group_name' => substr($row['group_name'], 10));
                $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . '
					SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
					WHERE group_id = ' . $row['group_id'];
                _sql($sql, $errored, $error_ary);
            }
            $db->sql_freeresult($result);
            /*
            * Due to a bug, vanilla phpbb could not create captcha tables
            * in 3.0.8 on firebird. It was possible for board administrators
            * to adjust the code to work. If code was manually adjusted by
            * board administrators, index names would not be the same as
            * what 3.0.9 and newer expect. This code fragment drops captcha
            * tables, destroying all entered Q&A captcha configuration, such
            * that when Q&A is configured next the respective tables will be
            * created with correct index names.
            *
            * If you wish to preserve your Q&A captcha configuration, you can
            * manually rename indexes to the currently expected name:
            * 	phpbb_captcha_questions_lang_iso	=> phpbb_captcha_questions_lang
            * 	phpbb_captcha_answers_question_id	=> phpbb_captcha_answers_qid
            *
            * Again, this needs to be done only if a board was manually modified
            * to fix broken captcha code.
            *
            if ($db_tools->sql_layer == 'firebird')
            {
            	$changes = array(
            		'drop_tables'	=> array(
            			$table_prefix . 'captcha_questions',
            			$table_prefix . 'captcha_answers',
            			$table_prefix . 'qa_confirm',
            		),
            	);
            	$statements = $db_tools->perform_schema_changes($changes);
            
            	foreach ($statements as $sql)
            	{
            		_sql($sql, $errored, $error_ary);
            	}
            }
            */
            $no_updates = false;
            break;
            // No changes from 3.0.9-RC1 to 3.0.9-RC2
        // No changes from 3.0.9-RC1 to 3.0.9-RC2
        case '3.0.9-RC1':
            break;
            // No changes from 3.0.9-RC2 to 3.0.9-RC3
        // No changes from 3.0.9-RC2 to 3.0.9-RC3
        case '3.0.9-RC2':
            break;
            // No changes from 3.0.9-RC3 to 3.0.9-RC4
        // No changes from 3.0.9-RC3 to 3.0.9-RC4
        case '3.0.9-RC3':
            break;
            // No changes from 3.0.9-RC4 to 3.0.9
        // No changes from 3.0.9-RC4 to 3.0.9
        case '3.0.9-RC4':
            break;
            // Changes from 3.0.9 to 3.0.10-RC1
        // Changes from 3.0.9 to 3.0.10-RC1
        case '3.0.9':
            if (!isset($config['email_max_chunk_size'])) {
                set_config('email_max_chunk_size', '50');
            }
            $no_updates = false;
            break;
            // No changes from 3.0.10-RC1 to 3.0.10-RC2
        // No changes from 3.0.10-RC1 to 3.0.10-RC2
        case '3.0.10-RC1':
            break;
            // No changes from 3.0.10-RC2 to 3.0.10-RC3
        // No changes from 3.0.10-RC2 to 3.0.10-RC3
        case '3.0.10-RC2':
            break;
            // No changes from 3.0.10-RC3 to 3.0.10
        // No changes from 3.0.10-RC3 to 3.0.10
        case '3.0.10-RC3':
            break;
            // Changes from 3.0.10 to 3.0.11-RC1
        // Changes from 3.0.10 to 3.0.11-RC1
        case '3.0.10':
            // Updates users having current style a deactivated one
            $sql = 'SELECT style_id
				FROM ' . STYLES_TABLE . '
				WHERE style_active = 0';
            $result = $db->sql_query($sql);
            $deactivated_style_ids = array();
            while ($style_id = $db->sql_fetchfield('style_id', false, $result)) {
                $deactivated_style_ids[] = (int) $style_id;
            }
            $db->sql_freeresult($result);
            if (!empty($deactivated_style_ids)) {
                $sql = 'UPDATE ' . USERS_TABLE . '
					SET user_style = ' . (int) $config['default_style'] . '
					WHERE ' . $db->sql_in_set('user_style', $deactivated_style_ids);
                _sql($sql, $errored, $error_ary);
            }
            // Delete orphan private messages
            $batch_size = 500;
            $sql_array = array('SELECT' => 'p.msg_id', 'FROM' => array(PRIVMSGS_TABLE => 'p'), 'LEFT_JOIN' => array(array('FROM' => array(PRIVMSGS_TO_TABLE => 't'), 'ON' => 'p.msg_id = t.msg_id')), 'WHERE' => 't.user_id IS NULL');
            $sql = $db->sql_build_query('SELECT', $sql_array);
            do {
                $result = $db->sql_query_limit($sql, $batch_size);
                $delete_pms = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $delete_pms[] = (int) $row['msg_id'];
                }
                $db->sql_freeresult($result);
                if (!empty($delete_pms)) {
                    $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . '
						WHERE ' . $db->sql_in_set('msg_id', $delete_pms);
                    _sql($sql, $errored, $error_ary);
                }
            } while (sizeof($delete_pms) == $batch_size);
            $no_updates = false;
            break;
            // No changes from 3.0.11-RC1 to 3.0.11-RC2
        // No changes from 3.0.11-RC1 to 3.0.11-RC2
        case '3.0.11-RC1':
            break;
            // No changes from 3.0.11-RC2 to 3.0.11
        // No changes from 3.0.11-RC2 to 3.0.11
        case '3.0.11-RC2':
            break;
            // Changes from 3.0.11 to 3.0.12-RC1
        // Changes from 3.0.11 to 3.0.12-RC1
        case '3.0.11':
            $sql = 'UPDATE ' . MODULES_TABLE . '
				SET module_auth = \'acl_u_sig\'
				WHERE module_class = \'ucp\'
					AND module_basename = \'profile\'
					AND module_mode = \'signature\'';
            _sql($sql, $errored, $error_ary);
            // Update bots
            if (!function_exists('user_delete')) {
                include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
            }
            $bots_updates = array('NG-Search [Bot]' => false, 'Nutch/CVS [Bot]' => false, 'OmniExplorer [Bot]' => false, 'Seekport [Bot]' => false, 'Synoo [Bot]' => false, 'WiseNut [Bot]' => false, 'Baidu [Spider]' => 'Baiduspider', 'Exabot [Bot]' => 'Exabot', 'Voyager [Bot]' => 'voyager/', 'W3C [Validator]' => 'W3C_Validator');
            foreach ($bots_updates as $bot_name => $bot_agent) {
                $sql = 'SELECT user_id
					FROM ' . USERS_TABLE . '
					WHERE user_type = ' . USER_IGNORE . "\n\t\t\t\t\t\tAND username_clean = '" . $db->sql_escape(utf8_clean_string($bot_name)) . "'";
                $result = $db->sql_query($sql);
                $bot_user_id = (int) $db->sql_fetchfield('user_id');
                $db->sql_freeresult($result);
                if ($bot_user_id) {
                    if ($bot_agent === false) {
                        $sql = 'DELETE FROM ' . BOTS_TABLE . "\n\t\t\t\t\t\t\tWHERE user_id = {$bot_user_id}";
                        _sql($sql, $errored, $error_ary);
                        user_delete('remove', $bot_user_id);
                    } else {
                        $sql = 'UPDATE ' . BOTS_TABLE . "\n\t\t\t\t\t\t\tSET bot_agent = '" . $db->sql_escape($bot_agent) . "'\n\t\t\t\t\t\t\tWHERE user_id = {$bot_user_id}";
                        _sql($sql, $errored, $error_ary);
                    }
                }
            }
            // Disable receiving pms for bots
            $sql = 'SELECT user_id
				FROM ' . BOTS_TABLE;
            $result = $db->sql_query($sql);
            $bot_user_ids = array();
            while ($row = $db->sql_fetchrow($result)) {
                $bot_user_ids[] = (int) $row['user_id'];
            }
            $db->sql_freeresult($result);
            if (!empty($bot_user_ids)) {
                $sql = 'UPDATE ' . USERS_TABLE . '
					SET user_allow_pm = 0
					WHERE ' . $db->sql_in_set('user_id', $bot_user_ids);
                _sql($sql, $errored, $error_ary);
            }
            /**
             * Update BBCodes that currently use the LOCAL_URL tag
             *
             * To fix http://tracker.phpbb.com/browse/PHPBB3-8319 we changed
             * the second_pass_replace value, so that needs updating for existing ones
             */
            $sql = 'SELECT *
				FROM ' . BBCODES_TABLE . '
				WHERE bbcode_match ' . $db->sql_like_expression($db->any_char . 'LOCAL_URL' . $db->any_char);
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                if (!class_exists('acp_bbcodes')) {
                    phpbb_require_updated('includes/acp/acp_bbcodes.' . $phpEx);
                }
                $bbcode_match = $row['bbcode_match'];
                $bbcode_tpl = $row['bbcode_tpl'];
                $acp_bbcodes = new acp_bbcodes();
                $sql_ary = $acp_bbcodes->build_regexp($bbcode_match, $bbcode_tpl);
                $sql = 'UPDATE ' . BBCODES_TABLE . '
					SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
					WHERE bbcode_id = ' . (int) $row['bbcode_id'];
                $db->sql_query($sql);
            }
            $db->sql_freeresult($result);
            $no_updates = false;
            break;
            // No changes from 3.0.12-RC1 to 3.0.12-RC2
        // No changes from 3.0.12-RC1 to 3.0.12-RC2
        case '3.0.12-RC1':
            break;
            // No changes from 3.0.12-RC2 to 3.0.12-RC3
        // No changes from 3.0.12-RC2 to 3.0.12-RC3
        case '3.0.12-RC2':
            break;
            // No changes from 3.0.12-RC3 to 3.0.12
        // No changes from 3.0.12-RC3 to 3.0.12
        case '3.0.12-RC3':
            break;
            // No changes from 3.0.12 to 3.0.13-RC1
        // No changes from 3.0.12 to 3.0.13-RC1
        case '3.0.12':
            break;
            // No changes from 3.0.13-RC1 to 3.0.13
        // No changes from 3.0.13-RC1 to 3.0.13
        case '3.0.13-RC1':
            break;
            // No changes from 3.0.13 to 3.0.13-PL1
        // No changes from 3.0.13 to 3.0.13-PL1
        case '3.0.13':
            break;
            // No changes from 3.0.13-PL1 to 3.0.14-RC1
        // No changes from 3.0.13-PL1 to 3.0.14-RC1
        case '3.0.13-PL1':
            break;
            // No changes from 3.0.14-RC1 to 3.0.14
        // No changes from 3.0.14-RC1 to 3.0.14
        case '3.0.14-RC1':
            break;
    }
}
Ejemplo n.º 23
0
    function _clear_home()
    {
        global $user;
        $v = $this->__(array('id' => 0));
        if ($v['id']) {
            $sql = 'SELECT *
				FROM _email
				WHERE email_id = ?';
            if (!($email = _fieldrow(sql_filter($sql, $v['id'])))) {
                $this->e('El registro de email no existe.');
            }
            $sql = 'UPDATE _email SET email_active = ?, email_start = ?, email_end = ?, email_last = ?
				WHERE email_id = ?';
            _sql(sql_filter($sql, 1, 0, 0, 0, $v['id']));
            $this->e('El registro de email fue reiniciado.');
        }
        $sql = 'SELECT email_id, email_subject
			FROM _email
			ORDER BY email_id';
        $emails = _rowset($sql);
        $response = '';
        foreach ($emails as $row) {
            $response .= '<a href="/faddr/email/x1:clear.id:' . $row['email_id'] . '">' . $row['email_subject'] . '</a><br />';
        }
        $this->e($response);
    }
Ejemplo n.º 24
0
 function _log($action, $uid = false)
 {
     $method = preg_replace('#^(INSERT|UPDATE|DELETE) (.*?)$#is', '\\1', $action);
     $method = strtolower($method);
     if (!in_array($method, w('insert update delete'))) {
         return;
     }
     if (!($whitelist = get_file('./base/sql_history'))) {
         return;
     }
     if (!count($whitelist)) {
         return;
     }
     $action = str_replace(array("\n", "\t", "\r"), array('', '', ' '), $action);
     $table = preg_replace('#^(INSERT\\ INTO|UPDATE|DELETE\\ FROM) (\\_[a-z\\_]+) (.*?)$#is', '\\2', $action);
     if (!in_array($table, $whitelist)) {
         return;
     }
     $actions = '';
     switch ($method) {
         case 'insert':
             if (!preg_match('#^INSERT INTO (\\_[a-z\\_]+) \\((.*?)\\) VALUES \\((.*?)\\)$#is', $action, $s_action)) {
                 return;
             }
             $keys = array_map('trim', explode(',', $s_action[2]));
             $values = array_map('trim', explode(',', $s_action[3]));
             foreach ($values as $i => $row) {
                 $values[$i] = preg_replace('#^\'(.*?)\'$#i', '\\1', $row);
             }
             if (count($keys) != count($values)) {
                 return;
             }
             $query = array('table' => $s_action[1], 'query' => array_combine($keys, $values));
             break;
         case 'update':
             if (!preg_match('#^UPDATE (\\_[a-z\\_]+) SET (.*?) WHERE (.*?)$#is', $action, $s_action)) {
                 return;
             }
             $all = array('set' => array_map('trim', explode(',', $s_action[2])), 'where' => array_map('trim', explode('AND', $s_action[3])));
             foreach ($all as $j => $v) {
                 foreach ($v as $i => $row) {
                     $v_row = array_map('trim', explode('=', $row));
                     $all[$j][$v_row[0]] = preg_replace('#^\'(.*?)\'$#i', '\\1', $v_row[1]);
                     unset($all[$j][$i]);
                 }
             }
             $query = array('table' => $s_action[1], 'set' => $all['set'], 'where' => $all['where']);
             break;
         case 'delete':
             if (!preg_match('#^DELETE FROM (\\_[a-z\\_]+) WHERE (.*?)$#is', $action, $s_action)) {
                 return;
             }
             $all = array('where' => array_map('trim', explode('AND', $s_action[2])));
             foreach ($all as $j => $v) {
                 foreach ($v as $i => $row) {
                     $v_row = array_map('trim', explode('=', $row));
                     $all[$j][$v_row[0]] = preg_replace('#^\'(.*?)\'$#i', '\\1', $v_row[1]);
                     unset($all[$j][$i]);
                 }
             }
             $query = array('table' => $s_action[1], 'where' => $all['where']);
             break;
     }
     global $user;
     $sql_insert = array('time' => time(), 'uid' => $user->v('user_id'), 'method' => $method, 'actions' => json_encode($query));
     $sql = 'INSERT INTO _log' . _build_array('INSERT', prefix('log', $sql_insert));
     _sql($sql);
     return;
 }
Ejemplo n.º 25
0
 protected function _optimize_home()
 {
     $tables = array();
     $sql = 'SHOW TABLES';
     foreach (_rowset($sql) as $row) {
         foreach ($row as $v) {
             $tables[] = $v;
         }
     }
     $sql = 'OPTIMIZE TABLE ' . _implode(', ', $tables);
     _sql($sql);
     return $this->e('Done.');
 }
Ejemplo n.º 26
0
echo "<p>Progress :: <b>";
flush();
// update the version
$sql = "UPDATE " . CONFIG_TABLE . "\n\tSET config_value = '{$updates_to_version}'\n\tWHERE config_name = 'version'";
_sql($sql, $errored, $error_ary);
// Optimize/vacuum analyze the tables where appropriate
// this should be done for each version in future along with
// the version number update
switch (SQL_LAYER) {
    case 'mysql':
    case 'mysql4':
        $sql = 'OPTIMIZE TABLE ' . $table_prefix . 'auth_access, ' . $table_prefix . 'banlist, ' . $table_prefix . 'categories, ' . $table_prefix . 'config, ' . $table_prefix . 'disallow, ' . $table_prefix . 'forum_prune, ' . $table_prefix . 'forums, ' . $table_prefix . 'groups, ' . $table_prefix . 'posts, ' . $table_prefix . 'posts_text, ' . $table_prefix . 'privmsgs, ' . $table_prefix . 'privmsgs_text, ' . $table_prefix . 'ranks, ' . $table_prefix . 'search_results, ' . $table_prefix . 'search_wordlist, ' . $table_prefix . 'search_wordmatch, ' . $table_prefix . 'smilies, ' . $table_prefix . 'themes, ' . $table_prefix . 'themes_name, ' . $table_prefix . 'topics, ' . $table_prefix . 'topics_watch, ' . $table_prefix . 'user_group, ' . $table_prefix . 'users, ' . $table_prefix . 'vote_desc, ' . $table_prefix . 'vote_results, ' . $table_prefix . 'vote_voters, ' . $table_prefix . 'words';
        _sql($sql, $errored, $error_ary);
        break;
    case 'postgresql':
        _sql("VACUUM ANALYZE", $errored, $error_ary);
        break;
}
echo "</b> <b class=\"ok\">Done</b><br />Result &nbsp; :: \n";
if ($errored) {
    echo " <b>Some queries failed, the statements and errors are listing below</b>\n<ul>";
    for ($i = 0; $i < count($error_ary['sql']); $i++) {
        echo "<li>Error :: <b>" . $error_ary['error_code'][$i]['message'] . "</b><br />";
        echo "SQL &nbsp; :: <b>" . $error_ary['sql'][$i] . "</b><br /><br /></li>";
    }
    echo "</ul>\n<p>This is probably nothing to worry about, update will continue. Should this fail to complete you may need to seek help at our development board. See <a href=\"docs\\README.html\">README</a> for details on how to obtain advice.</p>\n";
} else {
    echo "<b>No errors</b>\n";
}
echo "<h2>Update completed</h2>\n";
echo "\n" . '<p style="color:red">Please make sure you have updated your board files too, this file is only updating your database.</p>';
Ejemplo n.º 27
0
function _sql_affected($sql)
{
    _sql($sql);
    return _affectedrows();
}
Ejemplo n.º 28
0
    protected function _cat_remove()
    {
        gfatal();
        $v = $this->__(array('el' => 0));
        $sql = 'SELECT *
			FROM _tickets_cat
			WHERE cat_id = ?';
        if (!($cat = _fieldrow(sql_filter($sql, $v['el'])))) {
            $this->_error('#TICKET_CAT_NO');
        }
        $sql = 'SELECT ticket_id
			FROM _tickets
			WHERE ticket_cat = ?';
        if ($aaa = _fieldrow(sql_filter($sql, $v['el']))) {
            $this->_error('#TICKET_CAT_CANT_REMOVE');
        }
        $sql = 'DELETE FROM _tickets_cat
			WHERE cat_id = ?';
        _sql(sql_filter($sql, $v['el']));
        return $this->e('~OK');
    }
Ejemplo n.º 29
0
    protected function _ed_home()
    {
        global $bio;
        $v = $this->__(w('k'));
        if (empty($v->k) || !($rainbow = _rainbow_check($v->k))) {
            _fatal();
        }
        $sql = 'UPDATE _bio SET bio_active = 1
			WHERE bio_id = ?';
        _sql(sql_filter($sql, $rainbow->rainbow_uid));
        _rainbow_remove($rainbow->rainbow_code);
        if (!$bio->v('auth_member')) {
            $bio->session_create($rainbow->rainbow_uid);
        }
        redirect(_link('-', $bio->v('bio_alias')));
        return;
    }