/[drupal]/contributions/modules/wowroster/wowroster.inc
ViewVC logotype

Contents of /contributions/modules/wowroster/wowroster.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Sun Dec 3 13:57:59 2006 UTC (2 years, 11 months ago) by mosh
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +11 -7 lines
File MIME type: text/x-php
added a check if the profile module is activated to function _drupal_get_profile_fields
1 <?php
2 /**
3 * $Id: wowroster.inc,v 1.2.4.1 2006/12/03 13:45:03 mosh Exp $
4 */
5
6
7
8 /**
9 * remove a directory
10 */
11 function _removeDir($path) {
12 // Add trailing slash to $path if one is not there
13 if (substr($path, -1, 1) != "/") {
14 $path .= "/";
15 }
16 foreach (glob($path . "*") as $file) {
17 if (is_file($file) === TRUE) {
18 // Remove each file in this Directory
19 unlink($file);
20 } else if (is_dir($file) === TRUE) {
21 // If this Directory contains a Subdirectory, run this Function on it
22 _removeDir($file);
23 }
24 }
25 // Remove Directory once Files have been removed (If Exists)
26 if (is_dir($path) === TRUE) {
27 rmdir($path);
28 }
29 }
30 /** END: remove a directory ***************************************************/
31
32
33
34 /**
35 * get the status of your WoWRoster installation
36 * @return TRUE if WoWRoster is properly installed, otherwise FALSE
37 */
38 function _wowroster_get_status() {
39 $result = db_query("SELECT * FROM {wowroster_status}");
40 $status = db_fetch_array($result);
41 return $status['wowroster_is_installed'] == FALSE ? FALSE : TRUE;
42 }
43 /** END: _wowroster_get_status ************************************************/
44
45
46
47 /**
48 * Determines if a character has an uploaded profile
49 *
50 * @param id the id number of the user
51 * @return true or false
52 */
53 function _wowroster_is_uploaded($id) {
54 // Get the varialbes we need
55 $roster_tblpref = variable_get('wowroster_roster_tableprefix', '');
56
57 // Check to see if the member has uploaded their profile
58 $query = 'SELECT * FROM '.$roster_tblpref.'players WHERE member_id='.$id.'';
59 db_set_active('wowroster');
60 $result = db_query($query);
61 db_set_active('default');
62 if (!db_num_rows($result)) {
63 return FALSE;
64 }
65 else {
66 return TRUE;
67 }
68 }
69 /** END: _wowroster_is_uploaded ***********************************************/
70
71
72
73 /**
74 * Generate a link to the users page
75 *
76 * @param name the name of the user
77 * @param id the id number of the user
78 * @return a full link to the users profile page
79 */
80 function _wowroster_simpleroster_link($name, $id) {
81 return l($name, 'wowroster/profile/'.$id.'');
82 }
83 /** END: _wowroster_simpleroster_link *****************************************/
84
85
86
87 /**
88 * Get fields from drupal profiles
89 *
90 * @return returns an array of available profile fields
91 */
92 function _drupal_get_profile_fields() {
93 if (module_exists('profile')) {
94 $query = 'SELECT title FROM {profile_fields}';
95 $result = db_query($query);
96
97 while ($fields = db_fetch_array($result)) {
98 $profile_fields[] = $fields['title'];
99 }
100 return $profile_fields;
101 } else {
102 return FALSE;
103 }
104 }
105 /** END: _drupal_get_profile_fields *******************************************/
106
107
108
109 /**
110 * determine if the current drupal-user has a drupal_char-text-field
111 * corresponding to a valid wow player
112 *
113 * @return returns a valid member_id
114 */
115 function _wowroster_drupaluser_to_wowplayer() {
116 $drupal_text_field = variable_get('drupal_char-text-field', t('Drupal-User'));
117 $roster_tblpref = variable_get('wowroster_roster_tableprefix', '');
118
119 if ($drupal_text_field = t('Drupal-User')) {
120 // Drupal search field is the username
121 $query = ("
122 SELECT name
123 FROM {users}
124 WHERE uid = '%s'
125 ");
126 $result = db_query($query, arg(1));
127 $value = db_fetch_array($result);
128 $drupal_value = $value['name'];
129 } else {
130 // Drupal search field is a profile_field
131 }
132
133 // get the wowroster member_id (if there is one)
134 $query = ('
135 SELECT '.$roster_tblpref.'players.member_id
136 FROM '.$roster_tblpref.'players
137 LEFT JOIN '.$roster_tblpref.'members
138 ON '.$roster_tblpref.'members.member_id = '.$roster_tblpref.'players.member_id
139 WHERE '.$roster_tblpref.'players.name = "%s"
140 ');
141 db_set_active('wowroster');
142 $result = db_query($query, $drupal_value);
143 db_set_active('default');
144 $member_id = db_fetch_array($result);
145 return $member_id['member_id'];
146 }
147 /** END: _wowroster_drupaluser_to_wowplayer ***********************************/
148
149
150
151 /**
152 * determine if the member is a main, alt or undefined char
153 *
154 * @param memberid MemberID
155 * @return string chartype
156 */
157 function _wowroster_player_is_chartype($memberid) {
158 $roster_tblpref = variable_get('wowroster_roster_tableprefix', '');
159 $main_text_field = variable_get('wowroster_main-text_field', 'note');
160 $main_text_search = variable_get('wowroster_main-text_search', 'Main');
161 $alt_text_field = variable_get('wowroster_alt-text_field', 'note');
162 $alt_text_search = variable_get('wowroster_alt-text_search', 'Twink');
163
164 $query = 'SELECT '.$roster_tblpref.'members.'.$main_text_field.' AS main,
165 '.$roster_tblpref.'members.'.$alt_text_field.' AS alt
166 FROM '.$roster_tblpref.'members
167 WHERE '.$roster_tblpref.'members.member_id='.$memberid.'';
168
169 db_set_active('wowroster');
170 $result = db_query($query);
171 db_set_active('default');
172
173 $member = db_fetch_array($result);
174
175 if (strstr($member['main'],$main_text_search)) {
176 $chartype = "main";
177 } else if (strstr($member['alt'],$alt_text_search)) {
178 $chartype = "alt";
179 } else {
180 $chartype = "undefined";
181 }
182 return $chartype;
183 }
184 /** END: _wowroster_player_is_chartype ****************************************/
185
186
187
188 /**
189 * get the mainchar or if chartype is undefined treat it as a mainchar
190 *
191 * @param memberid MemberID
192 * @param chartype main/alt/undefined
193 * @return return an array width the main-chars data
194 */
195 function _wowroster_get_main($memberid, $chartype) {
196 $roster_tblpref = variable_get('wowroster_roster_tableprefix', '');
197 $alt_text_field = variable_get('wowroster_alt-text-field', 'note');
198
199 $query = 'SELECT *
200 FROM '.$roster_tblpref.'members
201 LEFT JOIN '.$roster_tblpref.'players
202 ON '.$roster_tblpref.'members.member_id = '.$roster_tblpref.'players.member_id ';
203
204 // requested char is main
205 if ($chartype === 'main' || $chartype === 'undefined') {
206 $query .= 'WHERE '.$roster_tblpref.'members.member_id = '.$memberid.'';
207
208 // requested char is alt
209 } else if ($chartype === 'alt') {
210 $query .=
211 'WHERE '.$roster_tblpref.'members.name = (
212 SELECT SUBSTRING('.$roster_tblpref.'members.'.$alt_text_field.',8)
213 FROM '.$roster_tblpref.'members
214 WHERE '.$roster_tblpref.'members.member_id = '.$memberid.')';
215 }
216
217 db_set_active('wowroster');
218 $result = db_query($query);
219 db_set_active('default');
220
221 $main = db_fetch_array($result);
222
223 return $main;
224 }
225 /** END: _wowroster_get_main **************************************************/
226
227
228
229 /**
230 * get all related chars of one mainchar
231 */
232 function _wowroster_get_alts($main_member_name) {
233 $roster_tblpref = variable_get('wowroster_roster_tableprefix', '');
234 $alt_text_field = variable_get('wowroster_alt-text-field', 'note');
235
236 $query =
237 'SELECT *
238 FROM '.$roster_tblpref.'members
239 LEFT JOIN '.$roster_tblpref.'players
240 ON '.$roster_tblpref.'members.member_id = '.$roster_tblpref.'players.member_id
241 WHERE '.$roster_tblpref.'members.'.$alt_text_field.' LIKE "%'.$main_member_name.'%"';
242
243 db_set_active('wowroster');
244 $result = db_query($query);
245 db_set_active('default');
246 while ($alt = db_fetch_array($result)) {
247 if ($alt['member_id'] && _wowroster_is_uploaded($alt['member_id'])) {
248 $alts[] = $alt;
249 }
250 }
251
252 return $alts;
253 }
254 /** END: _wowroster_get_alts **************************************************/
255 ?>

  ViewVC Help
Powered by ViewVC 1.1.2