1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8//this script may only be included - so its better to die if called directly.
9if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) !== false) {
10	header('location: index.php');
11	exit;
12}
13
14class CopyrightsLib extends TikiLib
15{
16	function list_copyrights($page)
17	{
18		$query = 'select * from `tiki_copyrights` WHERE `page`=? order by ' . $this->convertSortMode('copyright_order_asc');
19		$query_cant = 'select count(*) from `tiki_copyrights` WHERE `page`=?';
20		$result = $this->query($query, [$page]);
21		$cant = $this->getOne($query_cant, [$page]);
22		$ret = [];
23
24		while ($res = $result->fetchRow()) {
25			$ret[] = $res;
26		}
27
28		$retval = [];
29		$retval['data'] = $ret;
30		$retval['cant'] = $cant;
31		return $retval;
32	}
33
34	function top_copyright_order($page)
35	{
36		$query = 'select MAX(`copyright_order`) from `tiki_copyrights` where `page` like ?';
37		return $this->getOne($query, [$page]);
38	}
39
40	function unique_copyright($page, $title)
41	{
42		$query = 'select `copyrightID` from `tiki_copyrights` where `page`=? and `title`=?';
43		return $this->getOne($query, [$page, $title]);
44	}
45
46	function add_copyright($page, $title, $year, $authors, $copyrightHolder, $user)
47	{
48		$top = $this->top_copyright_order($page);
49		$order = $top + 1;
50		$query = 'insert `tiki_copyrights` (`page`, `title`, `year`, `authors`, `holder`, `copyright_order`, `userName`) values (?,?,?,?,?,?,?)';
51		$this->query($query, [$page, $title, $year, $authors, $copyrightHolder, $order, $user]);
52		return true;
53	}
54
55	function edit_copyright($id, $title, $year, $authors, $copyrightHolder, $user)
56	{
57		$query = 'update `tiki_copyrights` SET `year`=?, `title`=?, `authors`=?, `holder`=?, `userName`=? where `copyrightId`=?';
58		$this->query($query, [$year, $title, $authors, $copyrightHolder, $user, (int)$id]);
59		return true;
60	}
61
62	function remove_copyright($id)
63	{
64		$query = 'delete from `tiki_copyrights` where `copyrightId`=?';
65		$this->query($query, [(int)$id]);
66		return true;
67	}
68
69	function up_copyright($id)
70	{
71		$query = 'update `tiki_copyrights` set `copyright_order`=`copyright_order`-1 where `copyrightId`=?';
72		$result = $this->query($query, [(int)$id]);
73		return true;
74	}
75
76	function down_copyright($id)
77	{
78		$query = 'update `tiki_copyrights` set `copyright_order`=`copyright_order`+1 where `copyrightId`=?';
79		$result = $this->query($query, [(int)$id]);
80		return true;
81	}
82}
83