");
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.'
";
$emessage = & eMessage :: getInstance();
$ns->tablerender(USRLAN_55,$emessage->render().$text);
}
// Add a new user - may be passed existing data if there was an entry error on first pass
function user_add($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."
";
$emessage = & eMessage :: getInstance();
$ns->tablerender(USRLAN_59,$emessage->render().$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;
//@FIXME use array
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);
}
}
// ------- Ban User. --------------
function user_ban($user_id)
{
global $sql,$user,$admin_log;
// $sub_action = $user_id;
$sql->db_Select("user","*","user_id='".$user_id."'");
$row = $sql->db_Fetch();
if (($row['user_perms'] == "0") || ($row['user_perms'] == "0."))
{
$this->show_message(USRLAN_7);
}
else
{
if ($sql->db_Update("user","user_ban='1' WHERE user_id='".$user_id."' "))
{
$admin_log->log_event('USET_05',str_replace(array('--UID--','--NAME--'),array($row['user_id'],$row['user_name']),USRLAN_161),E_LOG_INFORMATIVE);
$this->show_message(USRLAN_8);
}
if (trim($row['user_ip']) == "")
{
$this->show_message(USRLAN_135);
}
else
{
if ($sql->db_Count("user","(*)","WHERE user_ip = '{$row['user_ip']}'") > 1)
{
// Multiple users have same IP address
$this->show_message(str_replace("{IP}",$row['user_ip'],USRLAN_136));
}
else
{
if ($e107->add_ban(6,USRLAN_149.$row['user_name'].'/'.$row['user_loginname'],$row['user_ip'],USERID))
{
// Successful IP ban
$this->show_message(str_replace("{IP}",$row['user_ip'],USRLAN_137));
}
else
{
// IP address on whitelist
$this->show_message(str_replace("{IP}",$row['user_ip'],USRLAN_150));
}
}
}
}
$action = "main";
if (!$sub_action)
{
$sub_action = "user_id";
}
}
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';
}
$sql3 = e107::getDb('sql3');
$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);
}
function check_allowed($class_id) // check userclass change is permitted.
{
global $e_userclass;
if (!isset ($e_userclass->class_tree[$class_id]))
{
header("location:".SITEURL);
exit;
}
if (!getperms("0") && !check_class($e_userclass->class_tree[$class_id]['userclass_editclass']))
{
header("location:".SITEURL);
exit;
}
return true;
}
// ------------------------------------------------------------------------
function show_userclass($userid)
{
global $sql,$ns, $e_userclass;
$sql->db_Select("user","*","user_id={$userid} ");
$row = $sql->db_Fetch();
$caption = UCSLAN_6." ".$row['user_name']." (".$row['user_class'].")";
$text = "