XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
users.php
Go to the documentation of this file.
1 <?php
2 // $Id: users.php 10265 2012-11-21 05:10:08Z beckmi $
3 // ------------------------------------------------------------------------ //
4 // XOOPS - PHP Content Management System //
5 // Copyright (c) 2000 XOOPS.org //
6 // <http://www.xoops.org/> //
7 // ------------------------------------------------------------------------ //
8 // This program is free software; you can redistribute it and/or modify //
9 // it under the terms of the GNU General Public License as published by //
10 // the Free Software Foundation; either version 2 of the License, or //
11 // (at your option) any later version. //
12 // //
13 // You may not change or alter any portion of this comment or credits //
14 // of supporting developers from this source code or any supporting //
15 // source code which is considered copyrighted (c) material of the //
16 // original comment or credit authors. //
17 // //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details. //
22 // //
23 // You should have received a copy of the GNU General Public License //
24 // along with this program; if not, write to the Free Software //
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
26 // ------------------------------------------------------------------------ //
27 // Author: Kazumi Ono (AKA onokazu) //
28 // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
29 // Project: The XOOPS Project //
30 // ------------------------------------------------------------------------- //
31 
32 // Check users rights
33 if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM );
34 
35 // Check is active
36 if ( !xoops_getModuleOption('active_users', 'system') ) redirect_header( 'admin.php', 2, _AM_SYSTEM_NOTACTIVE );
37 
38 /*********************************************************/
39 /* Users Functions */
40 /*********************************************************/
41 include_once XOOPS_ROOT_PATH."/class/xoopslists.php";
42 include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
43 
44 //Display form add or edit
45 //true = add and false = edit
46 function form_user($add_or_edit, $user='')
47 {
48  global $xoopsConfig, $xoopsUser;
49  $uid = system_CleanVars($_REQUEST, 'uid', 0);
50 
51  //RMV-NOTIFY
52  include_once XOOPS_ROOT_PATH. '/language/' . $xoopsConfig['language'] . '/notification.php';
53  include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
54 
55  if ( $add_or_edit == true )
56  {
57  //Add user
58  $uid_value = "";
59  $uname_value = "";
60  $name_value = "";
61  $email_value = "";
62  $email_cbox_value = 0;
63  $url_value = "";
64  $timezone_value = $xoopsConfig['default_TZ'];
65  $icq_value = "";
66  $aim_value = "";
67  $yim_value = "";
68  $msnm_value = "";
69  $location_value = "";
70  $occ_value = "";
71  $interest_value = "";
72  $sig_value = "";
73  $sig_cbox_value = 0;
74  $umode_value = $xoopsConfig['com_mode'];
75  $uorder_value = $xoopsConfig['com_order'];
76  // RMV-NOTIFY
77  $notify_method_value = XOOPS_NOTIFICATION_METHOD_PM;
78  $notify_mode_value = XOOPS_NOTIFICATION_MODE_SENDALWAYS;
79  $bio_value = "";
80  $rank_value = 0;
81  $mailok_value = 0;
82  $form_title = _AM_SYSTEM_USERS_ADDUSER;
83  $form_isedit = false;
84  $groups = array(XOOPS_GROUP_USERS);
85  } else
86  {
87  //Edit user
88  $member_handler =& xoops_gethandler('member');
89  $user =& $member_handler->getUser($uid);
90  if (is_object($user)) {
91  $uid_value = $uid;
92  $uname_value = $user->getVar("uname", "E");
93  $name_value = $user->getVar("name", "E");
94  $email_value = $user->getVar("email", "E");
95  $email_cbox_value = $user->getVar("user_viewemail") ? 1 : 0;
96  $url_value = $user->getVar("url", "E");
97  $temp = $user->getVar("theme");
98  $timezone_value = $user->getVar("timezone_offset");
99  $icq_value = $user->getVar("user_icq", "E");
100  $aim_value = $user->getVar("user_aim", "E");
101  $yim_value = $user->getVar("user_yim", "E");
102  $msnm_value = $user->getVar("user_msnm", "E");
103  $location_value = $user->getVar("user_from", "E");
104  $occ_value = $user->getVar("user_occ", "E");
105  $interest_value = $user->getVar("user_intrest", "E");
106  $sig_value = $user->getVar("user_sig", "E");
107  $sig_cbox_value = ($user->getVar("attachsig") == 1) ? 1 : 0;
108  $umode_value = $user->getVar("umode");
109  $uorder_value = $user->getVar("uorder");
110  // RMV-NOTIFY
111  $notify_method_value = $user->getVar("notify_method");
112  $notify_mode_value = $user->getVar("notify_mode");
113  $bio_value = $user->getVar("bio", "E");
114  $rank_value = $user->rank(false);
115  $mailok_value = $user->getVar('user_mailok', 'E');
116  $form_title = _AM_SYSTEM_USERS_UPDATEUSER.": ".$user->getVar("uname");
117  $form_isedit = true;
118  $groups = array_values($user->getGroups());
119  }
120  }
121 
122  //Affichage du formulaire
123  $form = new XoopsThemeForm($form_title, "form_user", "admin.php", "post", true);
124 
125  $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_NICKNAME, "username", 25, 25, $uname_value), true);
126  $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_NAME, "name", 30, 60, $name_value));
128  $email_text = new XoopsFormText("", "email", 30, 60, $email_value);
129  $email_tray->addElement($email_text, true);
130  $email_cbox = new XoopsFormCheckBox("", "user_viewemail", $email_cbox_value);
131  $email_cbox->addOption(1, _AM_SYSTEM_USERS_AOUTVTEAD);
132  $email_tray->addElement($email_cbox);
133  $form->addElement($email_tray, true);
134  $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_URL, "url", 30, 100, $url_value));
135  $form->addElement(new XoopsFormSelectTimezone(_AM_SYSTEM_USERS_TIMEZONE, "timezone_offset", $timezone_value));
136  $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_ICQ, "user_icq", 15, 15, $icq_value));
137  $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_AIM, "user_aim", 18, 18, $aim_value));
138  $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_YIM, "user_yim", 25, 25, $yim_value));
139  $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_MSNM, "user_msnm", 30, 100, $msnm_value));
140  $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_LOCATION, "user_from", 30, 100, $location_value));
141  $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_OCCUPATION, "user_occ", 30, 100, $occ_value));
142  $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_INTEREST, "user_intrest", 30, 150, $interest_value));
143  $sig_tray = new XoopsFormElementTray(_AM_SYSTEM_USERS_SIGNATURE, "<br />");
144  $sig_tarea = new XoopsFormTextArea("", "user_sig", $sig_value);
145  $sig_tray->addElement($sig_tarea);
146  $sig_cbox = new XoopsFormCheckBox("", "attachsig", $sig_cbox_value);
147  $sig_cbox->addOption(1, _AM_SYSTEM_USERS_SHOWSIG);
148  $sig_tray->addElement($sig_cbox);
149  $form->addElement($sig_tray);
150  $umode_select = new XoopsFormSelect(_AM_SYSTEM_USERS_CDISPLAYMODE, "umode", $umode_value);
151  $umode_select->addOptionArray(array("nest"=>_NESTED, "flat"=>_FLAT, "thread"=>_THREADED));
152  $form->addElement($umode_select);
153  $uorder_select = new XoopsFormSelect(_AM_SYSTEM_USERS_CSORTORDER, "uorder", $uorder_value);
154  $uorder_select->addOptionArray(array("0"=>_OLDESTFIRST, "1"=>_NEWESTFIRST));
155  $form->addElement($uorder_select);
156  // RMV-NOTIFY
157  $notify_method_select = new XoopsFormSelect(_NOT_NOTIFYMETHOD, 'notify_method', $notify_method_value);
159  $form->addElement($notify_method_select);
160  $notify_mode_select = new XoopsFormSelect(_NOT_NOTIFYMODE, 'notify_mode', $notify_mode_value);
162  $form->addElement($notify_mode_select);
163  $form->addElement(new XoopsFormTextArea(_AM_SYSTEM_USERS_EXTRAINFO, "bio", $bio_value));
164  $rank_select = new XoopsFormSelect(_AM_SYSTEM_USERS_RANK, "rank", $rank_value);
165  $ranklist = XoopsLists::getUserRankList();
166  if ( count($ranklist) > 0 ) {
167  $rank_select->addOption(0, "--------------");
168  $rank_select->addOptionArray($ranklist);
169  } else {
170  $rank_select->addOption(0, _AM_NSRID);
171  }
172  $form->addElement($rank_select);
173  // adding a new user requires password fields
174  if (!$form_isedit) {
175  $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_PASSWORD, "password", 10, 32), true);
176  $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_RETYPEPD, "pass2", 10, 32), true);
177  } else {
178  $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_PASSWORD, "password", 10, 32));
179  $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_RETYPEPD, "pass2", 10, 32));
180  }
181  $form->addElement(new XoopsFormRadioYN(_AM_SYSTEM_USERS_ACCEPT_EMAIL, 'user_mailok', $mailok_value));
182 
183  //Groups administration addition XOOPS 2.0.9: Mith
184  $gperm_handler =& xoops_gethandler('groupperm');
185  //If user has admin rights on groups
186  if ($gperm_handler->checkRight("system_admin", XOOPS_SYSTEM_GROUP, $xoopsUser->getGroups(), 1)) {
187  //add group selection
188  $group_select[] = new XoopsFormSelectGroup(_AM_SYSTEM_USERS_GROUPS, 'groups', false, $groups, 5, true);
189  }
190  else {
191  //add each user groups
192  foreach ($groups as $key => $group) {
193  $group_select[] = new XoopsFormHidden('groups[' . $key . ']', $group);
194  }
195  }
196  foreach ($group_select as $group) {
197  $form->addElement($group);
198  unset($group);
199  }
200 
201  $form->addElement(new XoopsFormHidden("fct", "users"));
202  $form->addElement(new XoopsFormHidden("op", "users_save"));
203  $form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit"));
204 
205  if ( !empty($uid_value) ) {
206  $form->addElement(new XoopsFormHidden("uid", $uid_value));
207  }
208  $form->display();
209 }
210 
212 {
213  global $xoopsDB;
214 
215  include_once XOOPS_ROOT_PATH . '/include/comment_constants.php';
216  include_once(XOOPS_ROOT_PATH."/kernel/module.php");
217 
218  $tables = array();
219  // Count comments (approved only: com_status == XOOPS_COMMENT_ACTIVE)
220  $tables[] = array ('table_name' => 'xoopscomments', 'uid_column' => 'com_uid', 'criteria' => new Criteria('com_status', XOOPS_COMMENT_ACTIVE));
221  // Count Content posts
222  if (XoopsModule::getByDirname("fmcontent")) {
223  $tables[] = array ('table_name' => 'fmcontent_content', 'uid_column' => 'content_uid');
224  }
225  // Count forum posts
226  if (XoopsModule::getByDirname("newbb")) {
227  $tables[] = array ('table_name' => 'bb_posts', 'uid_column' => 'uid');
228  }
229 
230  switch($type) {
231  case 'user':
232  $total_posts = 0;
233  foreach ($tables as $table) {
234  $criteria = new CriteriaCompo();
235  $criteria->add (new Criteria($table['uid_column'], $uid));
236  if (!empty($table['criteria'])) {
237  $criteria->add ($table['criteria']);
238  }
239  $sql = "SELECT COUNT(*) AS total FROM ".$xoopsDB->prefix($table['table_name']) . ' ' . $criteria->renderWhere();
240  if ( $result = $xoopsDB->query($sql) ) {
241  if ($row = $xoopsDB->fetchArray($result)) {
242  $total_posts = $total_posts + $row['total'];
243  }
244  }
245  }
246  $sql = "UPDATE ".$xoopsDB->prefix("users")." SET posts = '".$total_posts."' WHERE uid = '".$uid."'";
247  if ( !$result = $xoopsDB->queryF($sql) ) {
248  redirect_header("admin.php?fct=users",1,_AM_SYSTEM_USERS_CNUUSER);
249  }
250  break;
251 
252  case 'all users':
253  $sql = "SELECT uid FROM ".$xoopsDB->prefix("users")."";
254  if ( !$result = $xoopsDB->query($sql) ) {
255  redirect_header("admin.php?fct=users",1,sprintf(_AM_SYSTEM_USERS_CNGUSERID ,$uid));
256  }
257 
258  while ($data = $xoopsDB->fetchArray($result)) {
259  synchronize($data['uid'], "user");
260  }
261  break;
262  }
263 
264  // exit();
265 }
266 ?>