GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
nuno (author)
Sat Sep 13 09:44:10 -0700 2008
commit  388eda473f76d8cc0020e59a1450c84231097dd8
tree    e85465cd95bfd8ec15ce5896f214b2b7675d5a9b
parent  79e7ea4f6e42030e9504303632229079628463d0
cmsmadesimple-2-0 / lib / classes / class.cms_user_operations.php
100644 273 lines (246 sloc) 6.973 kb
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#This project's homepage is: http://cmsmadesimple.org
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program 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 General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
/**
* Represents a styelsheet in the database.
*
* @author Ted Kulp
* @since 2.0
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license GPL
**/
class CmsUserOperations extends CmsObject
{
  static private $instance = NULL;
  
  function __construct()
  {
    parent::__construct();
  }
  
  /**
   * Get an instance of this object, though most people should be using
   * the static methods instead. This is more for compatibility than
   * anything else.
   *
   * @return CmsUserOperations The instance of the singleton object.
   * @author Ted Kulp
   **/
  static public function get_instance()
  {
    if (self::$instance == NULL)
    {
      self::$instance = new CmsUserOperations();
    }
    return self::$instance;
  }
 
  /**
   * Gets a list of all users
   *
   * @returns array An array of User objects
   * @since 0.6.1
   **/
  public static function load_users()
  {
    return cmsms()->cms_user->find_all(array('order' => 'username'));
  }
  
  /**
   * @deprecated Deprecated. Use load_users instead.
   **/
  function LoadUsers()
  {
    return CmsUserOperations::load_users();
  }
 
  /**
   * Gets a list of all users in a given group
   *
   * @param mixed $groupid Group for the loaded users
   * @return array An array of User objects
   **/
  public static function load_users_in_group($groupid)
  {
    return cmsms()->cms_user->find_all_by_query("SELECT u.user_id, u.username, u.password, u.first_name, u.last_name, u.email, u.active, u.admin_access FROM ".cms_db_prefix()."users u, ".cms_db_prefix()."groups g, ".cms_db_prefix()."user_groups cg where cg.user_id = u.user_id and cg.group_id = g.group_id and g.group_id =? ORDER BY username", array($groupid));
  }
  
  /**
   * @deprecated Deprecated. Use load_users_in_group instead.
   **/
  function &LoadUsersInGroup($groupid)
  {
    return CmsUserOperations::load_users_in_group($groupid);
  }
 
  /**
   * Loads a user by username.
   *
   * @param mixed Username to load
   * @param mixed Password to check against
   * @param mixed Only load the user if they are active
   * @param mixed Only load the user if they have admin access
   *
   * @return mixed If successful, the filled User object. If it fails, it returns false.
   * @since 0.6.1
   **/
  public static function load_user_by_username($username, $password = '', $activeonly = true, $adminaccessonly = false)
  {  
    $condstring = 'username = ?';
    $params = array();
    
    if ($password != '')
    {
      $condstring .= " AND password = ?";
      $params[] = md5($password);
    }
 
    if ($activeonly == true)
    {
      $condstring .= " AND active = 1";
    }
 
    if ($adminaccessonly == true)
    {
      $condstring .= " AND admin_access = 1";
    }
    
    return cmsms()->cms_user->find(array('conditions', array($condstring, $params)));
  }
  
  /**
   * @deprecated Deprecated. Use load_user_by_username instead.
   **/
  function LoadUserByUsername($username, $password = '', $activeonly = true, $adminaccessonly = false)
  {
    return CmsUserOperations::load_user_by_username($username, $password, $activeonly, $adminaccessonly);
  }
 
  /**
   * Loads a user by user id.
   *
   * @param mixed User id to load
   *
   * @return mixed If successful, the filled User object. If it fails, it returns null.
   * @since 0.6.1
   **/
  public static function load_user_by_id($id)
  {
    return cmsms()->cms_user->find_by_id($id);
  }
  
  /**
   * @deprecated Deprecated. Use load_user_by_id instead.
   **/
  function LoadUserByID($id)
  {
    return CmsUserOperations::load_user_by_id($id);
  }
 
  /**
   * Saves a new user to the database.
   *
   * @deprecated Deprecated. User $user->save() instead.
   *
   * @param mixed User object to save
   *
   * @return mixed The new user id. If it fails, it returns -1.
   * @since 0.6.1
   */
  function InsertUser($user)
  {
    $user->save();
  }
 
  /**
   * Updates an existing user in the database.
   *
   * @deprecated Deprecated. User $user->save() instead.
   *
   * @param mixed User object to save
   *
   * @return mixed If successful, true. If it fails, false.
   * @since 0.6.1
   */
  function UpdateUser($user)
  {
    $user->save();
  }
 
  /**
   * Deletes an existing user from the database.
   *
   * @deprecated Deprecated. Use cmsms()->user->delete($id) instead.
   *
   * @param mixed Id of the user to delete
   *
   * @return mixed If successful, true. If it fails, false.
   * @since 0.6.1
   */
  function DeleteUserByID($id)
  {
    return cmsms()->cms_user->delete($id);
  }
 
  /**
   * Show the number of pages the given user's id owns.
   *
   * @param mixed Id of the user to count
   *
   * @return mixed Number of pages they own. 0 if any problems.
   * @since 0.6.1
   */
  function count_page_ownership_by_id($id)
  {
    $query = "SELECT count(*) AS count FROM ".cms_db_prefix()."content WHERE owner_id = ?";
    return cms_db()->GetOne($query, array($id));
  }
  
  /**
   * @deprecated Deprecated. Use count_page_ownership_by_id instead.
   **/
  function CountPageOwnershipByID($id)
  {
    return CmsUserOperations::count_page_ownership_by_id($id);
  }
 
  /**
   * Generates an HTML dropdown list of users in the system.
   *
   * @param string If sent, this will select that user as the default in the list.
   * @param string The name of html select item. Defaults to "ownerid".
   *
   * @return string The text for the HTML dropdown.
   **/
  function generate_user_dropdown($currentuserid='', $name='ownerid')
  {
    $result = '';
 
    $allusers = CmsUserOperations::load_users();
 
    if (count($allusers) > 0)
    {
      $result .= '<select name="'.$name.'">';
      foreach ($allusers as $oneuser)
      {
        $result .= '<option value="'.$oneuser->id.'"';
        if ($oneuser->id == $currentuserid)
        {
          $result .= ' selected="selected"';
        }
        $result .= '>'.$oneuser->username.'</option>';
      }
      $result .= '</select>';
    }
 
    return $result;
  }
  
  /**
   * @deprecated Deprecated. Use generate_user_dropdown instead.
   **/
  function GenerateDropdown($currentuserid='', $name='ownerid')
  {
    return CmsUserOperations::generate_user_dropdown($currentuserid, $name);
  }
}
 
/**
* @deprecated Deprecated. Use CmsUserOperations instead.
**/
class UserOperations extends CmsUserOperations
{}
 
?>