<?php
$objConnect = mysql_connect("localhost","root","") or die ("ไม่สามารถติดต่อฐานข้อมุลได้");
$objDB = mysql_select_db("db_erp");
//get checked user that want to active
$emails = $active = $verify = array();
foreach ($_POST['chkDel'] as $email => $status) {
$email = urlencode($email);
if($status==="active") $active[$email] = true;
else $active[$email] = false;
$email = '\''.mysql_real_escape_string($email).'\'';
$emails[] = $email;
}
$strSQL = sprintf(
"SELECT `employee_email` AS 'email' FROM `employees` WHERE `employee_email` IN (%s)",
implode(',', $emails)
);
unset($emails); //for performance
//var_dump($strSQL); //uncomment if you want to see SQl command
$objQuery = mysql_query($strSQL) or die ("Error Query [{$strSQL}]");
if(!empty($objQuery)){
while ($objResult = mysql_fetch_assoc($objQuery)) {
if(!empty($active[$objResult['email']])){ //verify that this mail active and exist
$email = '\''.mysql_real_escape_string($email).'\'';
$verify[] = $email;
unset($emails[$email]);
}
}
}
unset($active); //for performance
mysql_free_result($objQuery); //for performance
mysql_query(
sprintf(
"UPDATE `employees` SET `employee_status` = 'active' WHERE `employee_email` IN (%s)",
implode(',', $verify)
)
) OR die("Can't update active user");
mysql_query(
sprintf(
"UPDATE `employees` SET `employee_status` = 'block' WHERE `employee_email` IN (%s)",
implode(',', $emails)
)
) OR die("Can't update blocked user");
mysql_close($objConnect);
?>