|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if (!defined('XOOPS_ROOT_PATH')) { |
|
4
|
|
|
exit(); |
|
5
|
|
|
} |
|
6
|
|
|
|
|
7
|
|
|
include_once(dirname(dirname(__FILE__)).'/include/songlist.object.php'); |
|
8
|
|
|
include_once(dirname(dirname(__FILE__)).'/include/songlist.form.php'); |
|
9
|
|
|
|
|
10
|
|
|
class SonglistRequests extends XoopsObject |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
function SonglistRequests($fid = null) |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
$this->initVar('rid', XOBJ_DTYPE_INT, 0, false); |
|
16
|
|
|
$this->initVar('aid', XOBJ_DTYPE_INT, 0, false); |
|
17
|
|
|
$this->initVar('artist', XOBJ_DTYPE_TXTBOX, null, false, 128); |
|
18
|
|
|
$this->initVar('album', XOBJ_DTYPE_TXTBOX, null, false, 128); |
|
19
|
|
|
$this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false, 128); |
|
20
|
|
|
$this->initVar('lyrics', XOBJ_DTYPE_OTHER, null, false); |
|
21
|
|
|
$this->initVar('uid', XOBJ_DTYPE_INT, 0, false); |
|
22
|
|
|
$this->initVar('name', XOBJ_DTYPE_TXTBOX, null, false, 128); |
|
23
|
|
|
$this->initVar('email', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
24
|
|
|
$this->initVar('songid', XOBJ_DTYPE_TXTBOX, null, false, 32); |
|
25
|
|
|
$this->initVar('sid', XOBJ_DTYPE_INT, 0, false); |
|
26
|
|
|
$this->initVar('created', XOBJ_DTYPE_INT, 0, false); |
|
27
|
|
|
$this->initVar('updated', XOBJ_DTYPE_INT, 0, false); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function getForm($as_array = false) { |
|
|
|
|
|
|
31
|
|
|
return songlist_requests_get_form($this, $as_array); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function toArray() { |
|
|
|
|
|
|
35
|
|
|
$ret = parent::toArray(); |
|
36
|
|
|
$form = $this->getForm(true); |
|
37
|
|
|
$form['songid'] = new XoopsFormText('', $this->getVar('rid').'[songid]', 11, 32); |
|
38
|
|
|
foreach($form as $key => $element) { |
|
39
|
|
|
$ret['form'][$key] = $form[$key]->render(); |
|
40
|
|
|
} |
|
41
|
|
|
foreach(array('created', 'updated') as $key) { |
|
42
|
|
|
if ($this->getVar($key)>0) { |
|
43
|
|
|
$ret['form'][$key] = date(_DATESTRING, $this->getVar($key)); |
|
44
|
|
|
$ret[$key] = date(_DATESTRING, $this->getVar($key)); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
return $ret; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
class SonglistRequestsHandler extends XoopsPersistableObjectHandler |
|
54
|
|
|
{ |
|
55
|
|
|
function __construct(&$db) |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
parent::__construct($db, "songlist_requests", 'SonglistRequests', "rid", "name"); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
function filterFields() { |
|
|
|
|
|
|
61
|
|
|
return array('rid', 'artist', 'album', 'title', 'lyrics', 'uid', 'name', 'email', 'songid', 'sid', 'created', 'updated'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
function getFilterCriteria($filter) { |
|
|
|
|
|
|
65
|
|
|
$parts = explode('|', $filter); |
|
66
|
|
|
$criteria = new CriteriaCompo(); |
|
67
|
|
|
foreach($parts as $part) { |
|
68
|
|
|
$var = explode(',', $part); |
|
69
|
|
|
if (!empty($var[1])&&!is_numeric($var[0])) { |
|
70
|
|
|
$object = $this->create(); |
|
71
|
|
|
if ( $object->vars[$var[0]]['data_type']==XOBJ_DTYPE_TXTBOX || |
|
72
|
|
|
$object->vars[$var[0]]['data_type']==XOBJ_DTYPE_TXTAREA) { |
|
73
|
|
|
$criteria->add(new Criteria('`'.$var[0].'`', '%'.$var[1].'%', (isset($var[2])?$var[2]:'LIKE'))); |
|
74
|
|
|
} elseif ( $object->vars[$var[0]]['data_type']==XOBJ_DTYPE_INT || |
|
75
|
|
|
$object->vars[$var[0]]['data_type']==XOBJ_DTYPE_DECIMAL || |
|
76
|
|
|
$object->vars[$var[0]]['data_type']==XOBJ_DTYPE_FLOAT ) { |
|
77
|
|
|
$criteria->add(new Criteria('`'.$var[0].'`', $var[1], (isset($var[2])?$var[2]:'='))); |
|
78
|
|
|
} elseif ( $object->vars[$var[0]]['data_type']==XOBJ_DTYPE_ENUM ) { |
|
79
|
|
|
$criteria->add(new Criteria('`'.$var[0].'`', $var[1], (isset($var[2])?$var[2]:'='))); |
|
80
|
|
|
} elseif ( $object->vars[$var[0]]['data_type']==XOBJ_DTYPE_ARRAY ) { |
|
81
|
|
|
$criteria->add(new Criteria('`'.$var[0].'`', '%"'.$var[1].'";%', (isset($var[2])?$var[2]:'LIKE'))); |
|
82
|
|
|
} |
|
83
|
|
|
} elseif (!empty($var[1])&&is_numeric($var[0])) { |
|
84
|
|
|
$criteria->add(new Criteria($var[0], $var[1])); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
return $criteria; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
function getFilterForm($filter, $field, $sort='created', $op = 'dashboard', $fct='list') { |
|
|
|
|
|
|
91
|
|
|
$ele = songlist_getFilterElement($filter, $field, $sort, $op, $fct); |
|
92
|
|
|
if (is_object($ele)) |
|
93
|
|
|
return $ele->render(); |
|
94
|
|
|
else |
|
95
|
|
|
return ' '; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
function insert($obj, $force=true) { |
|
|
|
|
|
|
99
|
|
|
if ($obj->isNew()) { |
|
100
|
|
|
$obj->setVar('created', time()); |
|
101
|
|
|
$new = true; |
|
102
|
|
|
$sendmail = true; |
|
103
|
|
|
} else { |
|
104
|
|
|
$obj->setVar('updated', time()); |
|
105
|
|
|
$new = false; |
|
106
|
|
|
if ($obj->vars['songid']['changed']==true) { |
|
107
|
|
|
$songs_handler = xoops_getmodulehandler('songs', 'songlist'); |
|
108
|
|
|
$criteria = new Criteria('songid', $obj->getVar('songid')); |
|
109
|
|
|
$songs = $songs_handler->getObjects($criteria, false); |
|
|
|
|
|
|
110
|
|
|
if (is_object($songs[0])) { |
|
111
|
|
|
foreach($songs[0]->getVar('aids') as $aid) |
|
112
|
|
|
$ad[] = $aid; |
|
113
|
|
|
$obj->setVar('sid', $songs[0]->getVar('sid')); |
|
114
|
|
|
$obj->setVar('aid', $ad[0]); |
|
|
|
|
|
|
115
|
|
|
$sendmail = true; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
if ($rid = parent::insert($obj, $force)) { |
|
120
|
|
|
if ($sendmail==true) { |
|
|
|
|
|
|
121
|
|
|
if ($new==true) { |
|
|
|
|
|
|
122
|
|
|
xoops_loadLanguage('email', 'songlist'); |
|
123
|
|
|
$xoopsMailer =& getMailer(); |
|
124
|
|
|
$xoopsMailer->setHTML(true); |
|
125
|
|
|
$xoopsMailer->setTemplateDir($GLOBALS['xoops']->path('/modules/songlist/language/'.$GLOBALS['xoopsConfig']['language'].'/mail_templates/')); |
|
126
|
|
|
$xoopsMailer->setTemplate('songlist_request_created.html'); |
|
127
|
|
|
$xoopsMailer->setSubject(sprintf(_MN_SONGLIST_SUBJECT_REQUESTMADE, $rid)); |
|
128
|
|
|
|
|
129
|
|
|
foreach(explode('|', $GLOBALS['songlistModuleConfig']['email']) as $email) |
|
130
|
|
|
$xoopsMailer->setToEmails($email); |
|
131
|
|
|
|
|
132
|
|
|
$xoopsMailer->setToEmails($obj->getVar('email')); |
|
133
|
|
|
|
|
134
|
|
|
$xoopsMailer->assign("SITEURL", XOOPS_URL); |
|
135
|
|
|
$xoopsMailer->assign("SITENAME", $GLOBALS['xoopsConfig']['sitename']); |
|
136
|
|
|
$xoopsMailer->assign("RID", $rid); |
|
137
|
|
|
$xoopsMailer->assign("TITLE", $obj->getVar('title')); |
|
138
|
|
|
$xoopsMailer->assign("ALBUM", $obj->getVar('album')); |
|
139
|
|
|
$xoopsMailer->assign("ARTIST", $obj->getVar('artist')); |
|
140
|
|
|
$xoopsMailer->assign("EMAIL", $obj->getVar('email')); |
|
141
|
|
|
$xoopsMailer->assign("NAME", $obj->getVar('name')); |
|
142
|
|
|
|
|
143
|
|
|
if(!$xoopsMailer->send() ){ |
|
144
|
|
|
xoops_error($xoopsMailer->getErrors(true), 'Email Send Error'); |
|
145
|
|
|
} |
|
146
|
|
|
} else { |
|
147
|
|
|
xoops_loadLanguage('email', 'songlist'); |
|
148
|
|
|
$songs_handler = xoops_getmodulehandler('songs', 'songlist'); |
|
149
|
|
|
$artists_handler = xoops_getmodulehandler('artists', 'songlist'); |
|
150
|
|
|
$albums_handler = xoops_getmodulehandler('albums', 'songlist'); |
|
|
|
|
|
|
151
|
|
|
$genre_handler = xoops_getmodulehandler('genre', 'songlist'); |
|
152
|
|
|
|
|
153
|
|
|
$song = $songs_handler->get($obj->getVar('sid')); |
|
154
|
|
|
if (is_object($song)) { |
|
155
|
|
|
$sng = $genre->getVar('title'); |
|
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
$album = $album_handler->get($song->getVar('abid')); |
|
|
|
|
|
|
158
|
|
|
if (is_object($album)) { |
|
159
|
|
|
$alb = $genre->getVar('title'); |
|
160
|
|
|
$alb_img = $genre->getImage(); |
|
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
$genre = $genre_handler->get($song->getVar('abid')); |
|
163
|
|
|
if (is_object($genre)) { |
|
164
|
|
|
$gen = $genre->getVar('name'); |
|
165
|
|
|
} |
|
166
|
|
|
$artists = $artists_handler->getObjects(new Criteria('aid', '('.implode(',', $song->getVar('aid')).')', 'IN'), false); |
|
|
|
|
|
|
167
|
|
|
$art = ''; |
|
168
|
|
|
foreach($artists as $id => $artist) { |
|
169
|
|
|
$art .= $artist->getVar('name') . ($id<sizeof($artists)-1?', ':''); |
|
170
|
|
|
} |
|
171
|
|
|
$xoopsMailer =& getMailer(); |
|
172
|
|
|
$xoopsMailer->setHTML(true); |
|
173
|
|
|
$xoopsMailer->setTemplateDir($GLOBALS['xoops']->path('/modules/songlist/language/'.$GLOBALS['xoopsConfig']['language'].'/mail_templates/')); |
|
174
|
|
|
$xoopsMailer->setTemplate('songlist_request_updated.html'); |
|
175
|
|
|
$xoopsMailer->setSubject(sprintf(_MN_SONGLIST_SUBJECT_REQUESTFOUND, $rid)); |
|
176
|
|
|
|
|
177
|
|
|
$xoopsMailer->setToEmails($obj->getVar('email')); |
|
178
|
|
|
|
|
179
|
|
|
$xoopsMailer->assign("SITEURL", XOOPS_URL); |
|
180
|
|
|
$xoopsMailer->assign("SITENAME", $GLOBALS['xoopsConfig']['sitename']); |
|
181
|
|
|
$xoopsMailer->assign("RID", $rid); |
|
182
|
|
|
$xoopsMailer->assign("TITLE", $obj->getVar('title')); |
|
183
|
|
|
$xoopsMailer->assign("ALBUM", $obj->getVar('album')); |
|
184
|
|
|
$xoopsMailer->assign("ARTIST", $obj->getVar('artist')); |
|
185
|
|
|
$xoopsMailer->assign("EMAIL", $obj->getVar('email')); |
|
186
|
|
|
$xoopsMailer->assign("NAME", $obj->getVar('name')); |
|
187
|
|
|
$xoopsMailer->assign("SONGID", $song->getVar('songid')); |
|
188
|
|
|
$xoopsMailer->assign("SONGURL", $song->getURL()); |
|
|
|
|
|
|
189
|
|
|
$xoopsMailer->assign("FOUNDTITLE", $sng); |
|
|
|
|
|
|
190
|
|
|
$xoopsMailer->assign("FOUNDALBUM", $alb); |
|
|
|
|
|
|
191
|
|
|
$xoopsMailer->assign("FOUNDARTIST", $art); |
|
192
|
|
|
$xoopsMailer->assign("FOUNDGENRE", $gen); |
|
|
|
|
|
|
193
|
|
|
$xoopsMailer->assign("EMAIL", $obj->getVar('email')); |
|
194
|
|
|
$xoopsMailer->assign("NAME", $obj->getVar('name')); |
|
195
|
|
|
|
|
196
|
|
|
if(!$xoopsMailer->send() ){ |
|
197
|
|
|
xoops_error($xoopsMailer->getErrors(true), 'Email Send Error'); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
return $rid; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
function getURL() { |
|
|
|
|
|
|
206
|
|
|
global $file, $op, $fct, $id, $value, $gid, $cid, $start, $limit; |
|
207
|
|
|
if ($GLOBALS['songlistModuleConfig']['htaccess']) { |
|
208
|
|
|
return XOOPS_URL.'/'.$GLOBALS['songlistModuleConfig']['baseofurl'].'/'.$file.'/'.$op.'-'.$fct.$GLOBALS['songlistModuleConfig']['endofurl']; |
|
209
|
|
|
} else { |
|
210
|
|
|
return XOOPS_URL.'/modules/songlist/'.$file.'.php?op='.$op.'&fct='.$fct; |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
?> |
|
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.