-
Notifications
You must be signed in to change notification settings - Fork 0
/
clone.php
97 lines (90 loc) · 3.5 KB
/
clone.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/*
* clone.php
* Routine to clone an existing list (logged in users only)
*
* Copyright 2011 caprenter <[email protected]>
*
* This file is part of Setlistr.
*
* Setlistr is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Setlistr is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Setlistr. If not, see <http://www.gnu.org/licenses/>.
*
* Setlistr relies on other free software products. See the README.txt file
* for more details.
*/
/*
* Clone a list
*/
require_once('settings.php');
//Pass the list id via the URL
if (isset($_GET['list'])) {
//this is passed from the main set list page. We need to post it back
$list_id = filter_var($_GET['list'], FILTER_SANITIZE_NUMBER_INT);
if (!filter_var($list_id, FILTER_VALIDATE_INT)) {
unset($list_id);
}
//echo $list_id;
}
//Clone it
if (isset($list_id)){
//Is user logged in?
require_once 'phpUserClass/access.class.beta.php';
$user = new flexibleAccess();
if ( $user->is_loaded() ) {
//Find the id of the 'next' list
$listResult = mysql_query("SELECT MAX(list_id)+1 FROM tz_todo");
if(mysql_num_rows($listResult)) {
list($cloned_list_id) = mysql_fetch_array($listResult);
}
//if(!$cloned_list_id) {
// $cloned_list_id = 1;
//}
//Get all the info about the existing list (from lists table)
$query = ("SELECT name,user_id FROM lists WHERE list_id =" . $list_id);
$result = mysql_query($query);
if(mysql_num_rows($result)) {
list($name,$user_id) = mysql_fetch_array($result);
}
//echo $name;
//echo $user_id;
//die;
//Belt and braces check!!
if ($user_id == $user->get_property("userID")) {
//Fetch exisitng list items (from tz_todo)
$query = ("SELECT * FROM `tz_todo` WHERE list_id =" . $list_id);
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
//Loop through and insert new table rows as we go.
while($row = mysql_fetch_assoc($result)){
$query = ("INSERT INTO `tz_todo` SET list_id = " .$cloned_list_id . ",
type = '" . $row['type'] . "',
position =" . $row['position'] .",
in_out = " . $row['in_out'] . ", text = '" . $row['text'] . "'");
mysql_query($query);
//echo $query;
//die;
}
//Now insert the new record in the lists table
$query = ("INSERT INTO `lists` SET list_id = " .$cloned_list_id . ",
user_id = " . $user_id . ",
name = 'Clone of " . $name ."'" );
//echo $query;
mysql_query($query);
}
}
//mysql_close($link);
} //end if user is loaded
}
//Redirect to home page, hopefully still logged in, and with the cloned list.
header('Location: ' . $host);