");
unset($text);
}
// ------- Quick Add User --------------
if (isset($_POST['adduser']))
{
if (!$_POST['ac'] == md5(ADMINPWCHANGE))
{
exit;
}
$e107cache->clear('online_menu_member_total');
$e107cache->clear('online_menu_member_newest');
$error = FALSE;
if (isset($_POST['generateloginname']))
{
$_POST['loginname'] = $userMethods->generateUserLogin($pref['predefinedLoginName']);
}
if (isset($_POST['generatepassword']))
{
$_POST['password1'] = $userMethods->generateRandomString('**********'); // 10-char password should be enough
$_POST['password2'] = $_POST['password1'];
}
// Now validate everything
$allData = validatorClass::validateFields($_POST,$userMethods->userVettingInfo, TRUE); // Do basic validation
validatorClass::checkMandatory('user_name,user_loginname', $allData); // Check for missing fields (email done in userValidation() )
validatorClass::dbValidateArray($allData, $userMethods->userVettingInfo, 'user', 0); // Do basic DB-related checks
$userMethods->userValidation($allData); // Do user-specific DB checks
if (!isset($allData['errors']['user_password']))
{ // No errors in password - keep it outside the main data array
$savePassword = $allData['data']['user_password'];
unset($allData['data']['user_password']); // Delete the password value in the output array
}
unset($_POST['password1']); // Restrict the scope of this
unset($_POST['password2']);
if (!check_class($pref['displayname_class'], $allData['data']['user_class']))
{
if ($allData['data']['user_name'] != $allData['data']['user_loginname'])
{
$allData['errors']['user_name'] = ERR_FIELDS_DIFFERENT;
}
}
if (count($allData['errors']))
{
require_once(e_HANDLER."message_handler.php");
$temp = validatorClass::makeErrorList($allData,'USER_ERR_','%n - %x - %t: %v', ' ', $userMethods->userVettingInfo);
message_handler('P_ALERT', $temp);
$error = TRUE;
}
// Always save some of the entered data - then we can redisplay on error
$user_data = &$allData['data'];
if (!$error)
{
$message = '';
$user_data['user_password'] = $userMethods->HashPassword($savePassword,$loginname);
$user_data['user_join'] = time();
if ($userMethods->needEmailPassword())
{ // Save separate password encryption for use with email address
$user_data['user_prefs'] = serialize(array('email_password' => $userMethods->HashPassword($savePassword, $user_data['user_email'])));
}
$userMethods->userClassUpdate($allData['data'], 'userall'); // Set any initial classes
$userMethods->addNonDefaulted($user_data);
validatorClass::addFieldTypes($userMethods->userVettingInfo,$allData);
//FIXME - (SecretR) there is a better way to fix this (missing default value, sql error in strict mode - user_realm is to be deleted from DB later)
$allData['data']['user_realm'] = '';
if ($sql -> db_Insert('user', $allData))
{
// Add to admin log
$admin_log->log_event('USET_02',"UName: {$user_data['user_name']}; Email: {$user_data['user_email']}",E_LOG_INFORMATIVE);
// Add to user audit trail
$admin_log->user_audit(USER_AUDIT_ADD_ADMIN,$user_data, 0,$user_data['user_loginname']);
$e_event->trigger('userfull', $user_data); // send everything available for user data - bit sparse compared with user-generated signup
if (isset($_POST['sendconfemail']))
{ // Send confirmation email to user
require_once(e_HANDLER.'mail.php');
$e_message = str_replace(array('--SITE--','--LOGIN--','--PASSWORD--'),array(SITEURL,$loginname,$savePassword),USRLAN_185).USRLAN_186;
if (sendemail($user_data['user_email'],USRLAN_187.SITEURL,$e_message,$user_data['user_login'],'',''))
{
$message = USRLAN_188.'
";
$ns->tablerender(USRLAN_55, $text);
}
// Add a new user - may be passed existing data if there was an entry error on first pass
function add_user($user_data)
{
global $rs, $ns, $pref, $e_userclass;
if (!is_object($e_userclass)) $e_userclass = new user_class;
$text = "
\n";
if (!isset($user_data['user_class'])) $user_data['user_class'] = varset($pref['initial_user_classes'],'');
$temp = $e_userclass->vetted_tree('class',array($e_userclass,'checkbox_desc'), $user_data['user_class'], 'classes');
if ($temp)
{
$text .= "
".USRLAN_120."
{$temp}
\n";
}
$text .= "
".USRLAN_181."
";
$ns->tablerender(USRLAN_59, $text);
}
function resend($id, $key, $name, $email, $lfile='')
{
global $sql,$mailheader_e107id, $admin_log;
$id = (int)$id;
// Check for a Language field, and if present, send the email in the user's language.
if($lfile == "")
{
if($sql -> db_Select('user_extended', 'user_language', 'user_extended_id = '.$id))
{
$row = $sql -> db_Fetch();
$lfile = e_LANGUAGEDIR.$row['user_language'].'/lan_signup.php';
}
}
if(is_readable($lfile))
{
require_once($lfile);
}
else
{
$row['user_language'] = e_LANGUAGE;
require_once(e_LANGUAGEDIR.e_LANGUAGE."/lan_signup.php");
}
$return_address = (substr(SITEURL, -1) == "/") ? SITEURL."signup.php?activate.".$id.".".$key : SITEURL."/signup.php?activate.".$id.".".$key;
$message = LAN_EMAIL_01." ".$name."\n\n".LAN_SIGNUP_24." ".SITENAME.".\n".LAN_SIGNUP_21."\n\n";
$message .= $return_address . "\n\n".SITENAME."\n".SITEURL;
$mailheader_e107id = $id;
require_once(e_HANDLER."mail.php");
if(sendemail($email, LAN_404." ".SITENAME, $message))
{
// echo str_replace("\n"," ",$message);
$admin_log->log_event('USET_11',str_replace(array('--ID--','--NAME--','--EMAIL--'),array($id,$name,$email),USRLAN_167),E_LOG_INFORMATIVE);
$this->show_message(USRLAN_140.": ".$name." (".$row['user_language'].") ");
}
else
{
$this->show_message(USRLAN_141.": ".$name);
}
}
function resend_to_all()
{
global $sql,$pref,$sql3, $admin_log;
$count = 0;
$pause_count = 1;
$pause_amount = ($pref['mail_pause']) ? $pref['mail_pause'] : 10;
$pause_time = ($pref['mail_pausetime']) ? $pref['mail_pausetime'] : 1;
if($sql -> db_Select_gen('SELECT user_language FROM `#user_extended` LIMIT 1'))
{
$query = "SELECT u.*, ue.* FROM `#user` AS u LEFT JOIN `#user_extended` AS ue ON ue.user_extended_id = u.user_id WHERE u.user_ban = 2 ORDER BY u.user_id DESC";
}
else
{
$query = 'SELECT * FROM `#user` WHERE user_ban=2';
}
if(!is_object($sql3))
{
$sql3 = new db;
}
$sql3 -> db_Select_gen($query);
while($row = $sql3-> db_Fetch())
{
echo $row['user_id']." ".$row['user_sess']." ".$row['user_name']." ".$row['user_email']." ";
$this->resend($row['user_id'],$row['user_sess'],$row['user_name'],$row['user_email'],$row['user_language']);
if($pause_count > $pause_amount)
{
sleep($pause_time);
$pause_count = 1;
}
sleep(1);
$pause_count++;
$count++;
}
if ($count)
{
$admin_log->log_event('USET_12',str_replace('--COUNT--',$count,USRLAN_168),E_LOG_INFORMATIVE);
}
}
// ---------------------------------------------------------------------
// Bounce handling
// ---------------------------------------------------------------------
// $bounce_act has the task to perform:
// 'first_check' - initial read of list of bounces
// 'delnonbounce' - delete any emails that aren't bounces
// 'clearemailbounce' - delete email address for any user whose emails bounced
// 'delchecked' - delete the emails whose comma-separated IDs are in $bounce_arr
// 'delall' - delete all bounced emails
function check_bounces($bounce_act='first_check', $bounce_arr = '')
{
global $sql,$pref;
include(e_HANDLER.'pop3_class.php');
if (!trim($bounce_act)) { $bounce_act='first_check'; }
// echo "Check bounces. Action: {$bounce_act}; Entries: {$bounce_arr} ";
$obj= new receiveMail($pref['mail_bounce_user'],$pref['mail_bounce_pass'],$pref['mail_bounce_email'],$pref['mail_bounce_pop3'],varset($pref['mail_bounce_type'],'pop3'));
$del_count = 0;
if ($bounce_act !='first_check')
{ // Must do some deleting
$obj->connect();
$tot=$obj->getTotalMails();
$del_array = explode(',',$bounce_arr);
for($i=1;$i<=$tot;$i++)
{ // Scan all emails; delete current one if meets the criteria
$dodel = FALSE;
switch ($bounce_act)
{
case 'delnonbounce' :
$head=$obj->getHeaders($i);
$dodel = (!$head['bounce']);
break;
case 'clearemailbounce' :
if (!in_array($i, $del_array)) break;
$head=$obj->getHeaders($i);
if($head['bounce'])
{
if (preg_match("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $obj->getBody($i), $result)) { $usr_email = trim($result[0]); }
if ($sql->db_Select('user','user_id, user_name, user_email',"user_email='".$usr_email."' "))
{
$row = $sql->db_Fetch();
if ($sql->db_Update('user',"`user_email`='' WHERE `user_id` = '".$row['user_id']."' ") !== FALSE)
{
// echo "Deleting user email {$row['user_email']} for user {$row['user_name']}, id={$row['user_id']} ";
$dodel = TRUE;
}
}
}
break;
case 'delall' :
$dodel = TRUE;
break;
case 'delchecked' :
$dodel = in_array($i, $del_array);
break;
}
if ($dodel)
{
// echo "Delete email ID {$i} ";
$obj->deleteMails($i);
$del_count++; // Keep track of number of emails deleted
}
} // End - Delete one email
$obj->close_mailbox(); // This actually deletes the emails
} // End of email deletion
// Now list the emails that are left
$obj->connect();
$tot=$obj->getTotalMails();
$found = FALSE;
$DEL = ($pref['mail_bounce_delete']) ? TRUE : FALSE;
$text = "
#
e107-id
email
Subject
Bounce
\n";
for($i=1;$i<=$tot;$i++)
{
$head=$obj->getHeaders($i);
if($head['bounce'])
{ // Its a 'bounce' email
if (ereg('.*X-e107-id:(.*)MIME', $obj->getBody($i), $result))
{
if($result[1])
{
$id[$i] = intval($result[1]); // This should be a user ID - but not on special mailers!
// Try and pull out an email address from body - should be the one that failed
if (preg_match("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $obj->getBody($i), $result))
{
$emails[$i] = "'".$result[0]."'";
}
$found = TRUE;
}
}
elseif (preg_match("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $obj->getBody($i), $result))
{
if($result[0] && $result[0] != $pref['mail_bounce_email'])
{
$emails[$i] = "'".$result[0]."'";
$found = TRUE;
}
elseif($result[1] && $result[1] != $pref['mail_bounce_email'])
{
$emails[$i] = "'".$result[1]."'";
$found = TRUE;
}
}
if ($DEL && $found)
{ // Auto-delete bounced emails once noticed (if option set)
$obj->deleteMails($i);
$del_count++;
}
}
else
{ // Its a warning message or similar
// $id[$i] = ''; // Don't worry about an ID for now
// Try and pull out an email address from body - should be the one that failed
if (preg_match("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $obj->getBody($i), $result))
{
$wmails[$i] = "'".$result[0]."'";
}
}
$text .= "
\n";
}
if ($del_count)
{
$admin_log->log_event('USET_13',str_replace('--COUNT--',$del_count,USRLAN_169),E_LOG_INFORMATIVE);
}
if ($tot)
{ // Option to delete emails - only if there are some in the list
$text .= "
\n
\n
\n
\n
";
}
$text .= "
";
array_unique($id);
array_unique($emails);
$all_ids = implode(',',$id);
$all_emails = implode(',',$emails);
$obj->close_mailbox(); // This will actually delete emails
// $tot has total number of emails in the mailbox
$found = count($emails); // $found - Number of bounce emails found
// $del_count has number of emails deleted
// Update bounce status for users
$ed = $sql -> db_Update('user', "user_ban=3 WHERE (`user_id` IN (".$all_ids.") OR `user_email` IN (".$all_emails.")) AND user_sess !='' ");
if (!$ed) $ed = '0';
$this->show_message(str_replace(array('{TOTAL}','{DELCOUNT}','{DELUSER}','{FOUND}'),
array($tot,$del_count,$ed,$found),USRLAN_155).$text);
}
} // End class users
function users_adminmenu()
{
global $user;
global $action;
$user->show_options($action);
}
function deleteRank($rankId)
{
global $emessage;
$e107 = e107::getInstance();
$rankId = (int)$rankId;
$e107->ecache->clear_sys('nomd5_user_ranks');
if($e107->sql->db_Delete('generic', "gen_id='{$rankId}'"))
{
$emessage->add(USRLAN_218, E_MESSAGE_SUCCESS);
}
else
{
$emessage->add(USRLAN_218, E_MESSAGE_FAIL);
}
}
function updateRanks()
{
global $pref, $emessage;
$e107 = e107::getInstance();
$config = array();
$ranks_calc = '';
$ranks_flist = '';
foreach($_POST['op'] as $f => $o)
{
$config[$f]['op'] = $o;
$config[$f]['val'] = varset($_POST['val'][$f], '');
if($_POST['val'][$f])
{
$ranks_calc .= ($ranks_calc ? ' + ' : '').'({'.$f.'} '." $o {$_POST['val'][$f]}".' )';
$ranks_flist .= ($ranks_flist ? ',' : '').$f;
}
}
$e107->sql->db_Delete('generic', "gen_type = 'user_rank_config'");
$tmp = array();
$tmp['data']['gen_type'] = 'user_rank_config';
$tmp['data']['gen_chardata'] = serialize($config);
$tmp['_FIELD_TYPES']['gen_type'] = 'string';
$tmp['_FIELD_TYPES']['gen_chardata'] = 'escape';
$e107->sql->db_Insert('generic', $tmp);
$pref['ranks_calc'] = $ranks_calc;
$pref['ranks_flist'] = $ranks_flist;
save_prefs();
//Delete existing rank data
$e107->sql->db_Delete('generic', "gen_type = 'user_rank_data'");
//Add main site admin info
$tmp = array();
$tmp['_FIELD_TYPES']['gen_datestamp'] = 'int';
$tmp['_FIELD_TYPES']['gen_ip'] = 'todb';
$tmp['_FIELD_TYPES']['gen_user_id'] = 'int';
$tmp['_FIELD_TYPES']['gen_chardata'] = 'todb';
$tmp['_FIELD_TYPES']['gen_intdata'] = 'int';
$tmp['data']['gen_datestamp'] = 1;
$tmp['data']['gen_type'] = 'user_rank_data';
$tmp['data']['gen_ip'] = $_POST['calc_name']['main_admin'];
$tmp['data']['gen_user_id'] = varset($_POST['calc_pfx']['main_admin'], 0);
$tmp['data']['gen_chardata'] = $_POST['calc_img']['main_admin'];
$e107->sql->db_Insert('generic', $tmp);
//Add site admin info
unset($tmp['data']);
$tmp['data']['gen_type'] = 'user_rank_data';
$tmp['data']['gen_datestamp'] = 2;
$tmp['data']['gen_ip'] = $_POST['calc_name']['admin'];
$tmp['data']['gen_user_id'] = varset($_POST['calc_pfx']['admin'], 0);
$tmp['data']['gen_chardata'] = $_POST['calc_img']['admin'];
$e107->sql->db_Insert('generic', $tmp);
//Add all current site defined ranks
if(isset($_POST['field_id']))
{
foreach($_POST['field_id'] as $fid => $x)
{
unset($tmp['data']);
$tmp['data']['gen_type'] = 'user_rank_data';
$tmp['data']['gen_ip'] = varset($_POST['calc_name'][$fid], '');
$tmp['data']['gen_user_id'] = varset($_POST['calc_pfx'][$fid], 0);
$tmp['data']['gen_chardata'] = varset($_POST['calc_img'][$fid], '');
$tmp['data']['gen_intdata'] = varset($_POST['calc_lower'][$fid], '_NULL_');
$e107->sql->db_Insert('generic', $tmp);
}
}
//Add new rank, if posted
if(varset($_POST['new_calc_lower']))
{
unset($tmp['data']);
$tmp['data']['gen_type'] = 'user_rank_data';
$tmp['data']['gen_datestamp'] = 0;
$tmp['data']['gen_ip'] = varset($_POST['new_calc_name']);
$tmp['data']['gen_user_id'] = varset($_POST['new_calc_pfx'], 0);
$tmp['data']['gen_chardata'] = varset($_POST['new_calc_img']);
$tmp['data']['gen_intdata'] = varset($_POST['new_calc_lower']);
$e107->sql->db_Insert('generic', $tmp);
}
$e107->ecache->clear_sys('nomd5_user_ranks');
$emessage->add(USRLAN_217, E_MESSAGE_SUCCESS);
}
function show_ranks()
{
global $pref, $emessage;
$e107 = e107::getInstance();
include_once(e_HANDLER.'file_class.php');
include_once(e_HANDLER.'level_handler.php');
require_once(e_HANDLER.'message_handler.php');
require_once(e_HANDLER."form_handler.php");
$frm = new e_form(true); //enable inner tabindex counter
$f = new e_file;
$ranks = new e107UserRank;
$imageList = $f->get_files(e_IMAGE.'ranks', '.*?\.(png|gif|jpg)');
$config = array();
if($e107->sql->db_Select('generic', 'gen_chardata', "gen_type='user_rank_config'", 'default'))
{
$row = $e107->sql->db_Fetch(MYSQL_ASSOC);
$config = unserialize($row['gen_chardata']);
}
$fieldList = array('core' => array(), 'extended' => array());
$fieldList['core'] = array(
'comments' => USRLAN_201,
'visits' => USRLAN_202,
'daysregged' => USRLAN_203
);
foreach($e107->extended_struct as $field)
{
if(strpos($field['Type'], 'int') !== false && $field['Field'] != 'user_extended_id')
{
$fieldList['extended'][] = substr($field['Field'], 5);
}
}
$opArray = array('*', '+', '-');
$text .= "
".USRLAN_197."
".USRLAN_198."
".USRLAN_199."
".USRLAN_200."
";
foreach($fieldList['core'] as $k => $f)
{
$text .= "