summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAntoine Ginies <aginies@mandriva.com>2005-09-08 13:48:17 +0000
committerAntoine Ginies <aginies@mandriva.com>2005-09-08 13:48:17 +0000
commit5a9eada94ce001bef51ab89d6e147c944bde92aa (patch)
tree1fab917ba232eacb6f4478030d1a4e0c6b58d465 /common
parentcd78c71675430e10a535a8471661988c366007f1 (diff)
downloaddrakwizard-5a9eada94ce001bef51ab89d6e147c944bde92aa.tar
drakwizard-5a9eada94ce001bef51ab89d6e147c944bde92aa.tar.gz
drakwizard-5a9eada94ce001bef51ab89d6e147c944bde92aa.tar.bz2
drakwizard-5a9eada94ce001bef51ab89d6e147c944bde92aa.tar.xz
drakwizard-5a9eada94ce001bef51ab89d6e147c944bde92aa.zip
use set_tagged_utf8
Diffstat (limited to 'common')
-rw-r--r--common/Wizcommon_gtk2.pm1
1 files changed, 1 insertions, 0 deletions
diff --git a/common/Wizcommon_gtk2.pm b/common/Wizcommon_gtk2.pm
index 7bd34270..56d18a0a 100644
--- a/common/Wizcommon_gtk2.pm
+++ b/common/Wizcommon_gtk2.pm
@@ -90,6 +90,7 @@ sub gtk_log {
gtktext_append($log_text, "$command\n\n");
while (<$TMP>) {
s/\033\[[^mG]*[mG]//g;
+ c::set_tagged_utf8($_);
gtktext_append($log_text, $_);
gtkflush();
next;
a> 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

namespace phpbb\groupposition;

/**
* Teampage group position class
*
* Teampage position is an ascending list 1, 2, ..., n for items which are displayed. 1 is the first item, n the last.
*/
class teampage implements \phpbb\groupposition\groupposition_interface
{
	/**
	* Group is not displayed
	*/
	const GROUP_DISABLED = 0;

	/**
	* No parent item
	*/
	const NO_PARENT = 0;

	/**
	* Database object
	* @var \phpbb\db\driver\driver_interface
	*/
	protected $db;

	/**
	* User object
	* @var \phpbb\user
	*/
	protected $user;

	/**
	* Cache object
	* @var \phpbb\cache\driver\driver_interface
	*/
	protected $cache;

	/**
	* Constructor
	*
	* @param \phpbb\db\driver\driver_interface				$db		Database object
	* @param \phpbb\user						$user	User object
	* @param \phpbb\cache\driver\driver_interface	$cache	Cache object
	*/
	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\cache\driver\driver_interface $cache)
	{
		$this->db = $db;
		$this->user = $user;
		$this->cache = $cache;
	}

	/**
	* Returns the teampage position for a given group, if the group exists.
	*
	* @param	int		$group_id	group_id of the group to be selected
	* @return	int			position of the group
	* @throws \phpbb\groupposition\exception
	*/
	public function get_group_value($group_id)
	{
		// The join is required to ensure that the group itself exists
		$sql = 'SELECT g.group_id, t.teampage_position
			FROM ' . GROUPS_TABLE . ' g
			LEFT JOIN ' . TEAMPAGE_TABLE . ' t
				ON (t.group_id = g.group_id)
			WHERE g.group_id = ' . (int) $group_id;
		$result = $this->db->sql_query($sql);
		$row = $this->db->sql_fetchrow($result);
		$this->db->sql_freeresult($result);

		if ($row === false)
		{
			// Group not found.
			throw new \phpbb\groupposition\exception('NO_GROUP');
		}

		return (int) $row['teampage_position'];
	}

	/**
	* Returns the row for a given group, if the group exists.
	*
	* @param	int		$group_id	group_id of the group to be selected
	* @return	array			Data row of the group
	* @throws \phpbb\groupposition\exception
	*/
	public function get_group_values($group_id)
	{
		// The join is required to ensure that the group itself exists
		$sql = 'SELECT *
			FROM ' . GROUPS_TABLE . ' g
			LEFT JOIN ' . TEAMPAGE_TABLE . ' t
				ON (t.group_id = g.group_id)
			WHERE g.group_id = ' . (int) $group_id;
		$result = $this->db->sql_query($sql);
		$row = $this->db->sql_fetchrow($result);
		$this->db->sql_freeresult($result);

		if ($row === false)
		{
			// Group not found.
			throw new \phpbb\groupposition\exception('NO_GROUP');
		}

		return $row;
	}

	/**
	* Returns the teampage position for a given teampage item, if the item exists.
	*
	* @param	int		$teampage_id	Teampage_id of the selected item
	* @return	int			Teampage position of the item
	* @throws \phpbb\groupposition\exception
	*/
	public function get_teampage_value($teampage_id)
	{
		$sql = 'SELECT teampage_position
			FROM ' . TEAMPAGE_TABLE . '
			WHERE teampage_id = ' . (int) $teampage_id;
		$result = $this->db->sql_query($sql);
		$current_value = $this->db->sql_fetchfield('teampage_position');
		$this->db->sql_freeresult($result);

		if ($current_value === false)
		{
			// Group not found.
			throw new \phpbb\groupposition\exception('NO_GROUP');
		}

		return (int) $current_value;
	}

	/**
	* Returns the teampage row for a given teampage item, if the item exists.
	*
	* @param	int		$teampage_id	Teampage_id of the selected item
	* @return	array			Teampage row of the item
	* @throws \phpbb\groupposition\exception
	*/
	public function get_teampage_values($teampage_id)
	{
		$sql = 'SELECT teampage_position, teampage_parent
			FROM ' . TEAMPAGE_TABLE . '
			WHERE teampage_id = ' . (int) $teampage_id;
		$result = $this->db->sql_query($sql);
		$row = $this->db->sql_fetchrow($result);
		$this->db->sql_freeresult($result);

		if ($row === false)
		{
			// Group not found.
			throw new \phpbb\groupposition\exception('NO_GROUP');
		}

		return $row;
	}


	/**
	* {@inheritDoc}
	*/
	public function get_group_count()
	{
		$sql = 'SELECT teampage_position
			FROM ' . TEAMPAGE_TABLE . '
			ORDER BY teampage_position DESC';
		$result = $this->db->sql_query_limit($sql, 1);
		$group_count = (int) $this->db->sql_fetchfield('teampage_position');
		$this->db->sql_freeresult($result);

		return $group_count;
	}

	/**
	* {@inheritDoc}
	*/
	public function add_group($group_id)
	{
		return $this->add_group_teampage($group_id, self::NO_PARENT);
	}

	/**
	* Adds a group by group_id
	*
	* @param	int		$group_id	group_id of the group to be added
	* @param	int		$parent_id	Teampage ID of the parent item
	* @return	bool		True if the group was added successfully
	*/
	public function add_group_teampage($group_id, $parent_id)
	{
		$current_value = $this->get_group_value($group_id);

		if ($current_value == self::GROUP_DISABLED)
		{
			if ($parent_id != self::NO_PARENT)
			{
				// Check, whether the given parent is a category
				$sql = 'SELECT teampage_id
					FROM ' . TEAMPAGE_TABLE . '
					WHERE group_id = 0
						AND teampage_id = ' . (int) $parent_id;
				$result = $this->db->sql_query_limit($sql, 1);
				$parent_is_category = (bool) $this->db->sql_fetchfield('teampage_id');
				$this->db->sql_freeresult($result);

				if ($parent_is_category)
				{
					// Get value of last child from this parent and add group there
					$sql = 'SELECT teampage_position
						FROM ' . TEAMPAGE_TABLE . '
						WHERE teampage_parent = ' . (int) $parent_id . '
							OR teampage_id = ' . (int) $parent_id . '
						ORDER BY teampage_position DESC';
					$result = $this->db->sql_query_limit($sql, 1);
					$new_position = (int) $this->db->sql_fetchfield('teampage_position');
					$this->db->sql_freeresult($result);

					$sql = 'UPDATE ' . TEAMPAGE_TABLE . '
						SET teampage_position = teampage_position + 1
						WHERE teampage_position > ' . $new_position;
					$this->db->sql_query($sql);
				}
			}
			else
			{
				// Add group at the end
				$new_position = $this->get_group_count();
			}

			$sql_ary = array(
				'group_id'			=> $group_id,
				'teampage_position'	=> $new_position + 1,
				'teampage_parent'	=> $parent_id,
			);

			$sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
			$this->db->sql_query($sql);

			$this->cache->destroy('sql', TEAMPAGE_TABLE);
			return true;
		}

		$this->cache->destroy('sql', TEAMPAGE_TABLE);
		return false;
	}

	/**
	* Adds a new category
	*
	* @param	string	$category_name	Name of the category to be added
	* @return	bool		True if the category was added successfully
	*/
	public function add_category_teampage($category_name)
	{
		if ($category_name === '')
		{
			return false;
		}

		$num_entries = $this->get_group_count();

		$sql_ary = array(
			'group_id'			=> 0,
			'teampage_position'	=> $num_entries + 1,
			'teampage_parent'	=> 0,
			'teampage_name'		=> truncate_string($category_name, 255, 255),
		);

		$sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
		$this->db->sql_query($sql);

		$this->cache->destroy('sql', TEAMPAGE_TABLE);
		return true;
	}

	/**
	* Deletes a group from the list and closes the gap in the position list.
	*
	* @param	int		$group_id		group_id of the group to be deleted
	* @param	bool	$skip_group		Skip setting the value for this group, to save the query, when you need to update it anyway.
	* @return	bool		True if the group was deleted successfully
	*/
	public function delete_group($group_id, $skip_group = false)
	{
		$current_value = $this->get_group_value($group_id);

		if ($current_value != self::GROUP_DISABLED)
		{
			$sql = 'UPDATE ' . TEAMPAGE_TABLE . '
				SET teampage_position = teampage_position - 1
				WHERE teampage_position > ' . $current_value;
			$this->db->sql_query($sql);

			$sql = 'DELETE FROM ' . TEAMPAGE_TABLE . '
				WHERE group_id = ' . $group_id;
			$this->db->sql_query($sql);

			$this->cache->destroy('sql', TEAMPAGE_TABLE);
			return true;
		}

		$this->cache->destroy('sql', TEAMPAGE_TABLE);
		return false;
	}

	/**
	* Deletes an item from the list and closes the gap in the position list.
	*
	* @param	int		$teampage_id	teampage_id of the item to be deleted
	* @param	bool	$skip_group		Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway.
	* @return	bool		True if the item was deleted successfully
	*/
	public function delete_teampage($teampage_id, $skip_group = false)
	{
		$current_value = $this->get_teampage_value($teampage_id);

		if ($current_value != self::GROUP_DISABLED)
		{
			$sql = 'DELETE FROM ' . TEAMPAGE_TABLE . '
				WHERE teampage_id = ' . $teampage_id . '
					OR teampage_parent = ' . $teampage_id;
			$this->db->sql_query($sql);

			$delta = (int) $this->db->sql_affectedrows();

			$sql = 'UPDATE ' . TEAMPAGE_TABLE . '
				SET teampage_position = teampage_position - ' . $delta . '
				WHERE teampage_position > ' . $current_value;
			$this->db->sql_query($sql);

			$this->cache->destroy('sql', TEAMPAGE_TABLE);
			return true;
		}

		$this->cache->destroy('sql', TEAMPAGE_TABLE);
		return false;
	}

	/**
	* {@inheritDoc}
	*/
	public function move_up($group_id)
	{