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
|
<?php
class UserMenuLib extends BitBase {
function UserMenuLib() {
BitBase::BitBase();
}
function add_bk($user) {
$query = "select tubu.`name`,`url` from `".BIT_DB_PREFIX."tiki_user_bookmarks_urls` tubu, `".BIT_DB_PREFIX."tiki_user_bookmarks_folders` tubf where tubu.`folder_id`=tubf.`folder_id` and tubf.`parent_id`=? and tubu.`user_id`=?";
$result = $this->query($query,array(0,$user));
$start = $this->get_max_position($user) + 1;
while ($res = $result->fetchRow()) {
// Check for duplicate URL
if (!$this->getOne("select count(*) from `".BIT_DB_PREFIX."tiki_user_menus` where `url`=?",array($res['url']))) {
$this->replace_usermenu($user, 0, $res['name'], $res['url'], $start, 'w');
$start++;
} else {
}
}
$query = "select tubu.`name`,`url` from `".BIT_DB_PREFIX."tiki_user_bookmarks_urls` tubu where tubu.`folder_id`=? and tubu.user=?";
$result = $this->query($query,array(0,$user));
$start = $this->get_max_position($user) + 1;
while ($res = $result->fetchRow()) {
// Check for duplicate URL
if (!$this->getOne("select count(*) from `".BIT_DB_PREFIX."tiki_user_menus` where `url`=?",array($res['url']))) {
$this->replace_usermenu($user, 0, $res['name'], $res['url'], $start, 'w');
$start++;
} else {
}
}
}
function list_usermenus($user, $offset, $maxRecords, $sort_mode, $find) {
if ($find) {
$findesc = '%' . $find . '%';
$mid = " and (`name` like ? or url like ?)";
$bindvars=array($user,$findesc,$findesc);
} else {
$mid = " ";
$bindvars=array($user);
}
$query = "select * from `".BIT_DB_PREFIX."tiki_user_menus` where `user_id`=? $mid order by ".$this->convert_sortmode($sort_mode);
$query_cant = "select count(*) from `".BIT_DB_PREFIX."tiki_user_menus` where `user_id`=? $mid";
$result = $this->query($query,$bindvars,$maxRecords,$offset);
$cant = $this->getOne($query_cant,$bindvars);
$ret = array();
while ($res = $result->fetchRow()) {
$ret[] = $res;
}
$retval = array();
$retval["data"] = $ret;
$retval["cant"] = $cant;
return $retval;
}
function get_usermenu($user, $menu_id) {
$query = "select * from `".BIT_DB_PREFIX."tiki_user_menus` where `user_id`=? and `menu_id`=?";
$result = $this->query($query,array($user,$menu_id));
$res = $result->fetchRow();
return $res;
}
function get_max_position($user) {
return $this->getOne("select max(`position`) from `".BIT_DB_PREFIX."tiki_user_menus` where `user_id`=?",array($user));
}
function replace_usermenu($user, $menu_id, $name, $url, $position, $mode) {
$now = date("U");
if ($menu_id) {
$query = "update `".BIT_DB_PREFIX."tiki_user_menus` set `name`=?, `position`=?, `url`=?, `mode`=? where `user_id`=? and `menu_id`=?";
$this->query($query,array($name,$position,$url,$mode,$user,$menu_id));
return $menu_id;
} else {
$query = "insert into `".BIT_DB_PREFIX."tiki_user_menus`(`user_id`,`name`,`url`,`position`,`mode`) values(?,?,?,?,?)";
$this->query($query,array($user,$name,$url,$position,$mode));
$Id = $this->getOne("select max(`menu_id`) from `".BIT_DB_PREFIX."tiki_user_menus` where `user_id`=? and `url`=? and `name`=?",array($user,$url,$name));
return $Id;
}
}
function remove_usermenu($user, $menu_id) {
$query = "delete from `".BIT_DB_PREFIX."tiki_user_menus` where `user_id`=? and `menu_id`=?";
$this->query($query,array($user,$menu_id));
}
}
$usermenulib = new UserMenuLib();
?>
|