Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set_time_limit(0);
- ini_set("error_log", 1);
- error_reporting(E_ALL);
- $start = microtime(TRUE);
- //require_once('inc/header.inc.php');
- require_once(BX_DIRECTORY_PATH_INC . 'phpmailer.inc.php');
- bx_import('BxDolDb');
- $db = new BxDolDb();
- echo "Comienza el cron <br>";
- $inserts = $updates = 0;
- $thecore_users = file_get_contents("http://tag/thecore/webservices/tlife_sync.php");
- $mail_body = "";
- $new_profiles = $update_profiles = $no_new = $no_updates = array();
- $vhurs = $netlogins = array();
- if ($thecore_users === FALSE) {
- echo "No se pudo leer el web service<br>";
- } else {
- $thecore_users = json_decode($thecore_users, TRUE);
- if ($thecore_users === FALSE) {
- echo "No se pudo convertir la data leida del web service a array: $thecore_users<br>";
- } else {
- echo "Se leyeron " . count($thecore_users) . " desde The Core<br>";
- foreach ($thecore_users as $user) {
- $processed = NULL;
- $vhur = $user["VHUR"];
- $network_login = addslashes($user["network_login"]);
- if ((!is_null($vhur) || strlen($vhur) > 0) && $vhur !== "0") {// Actualizar por VHUR
- $query_select = "SELECT ID_VHUR,Position_id,SuperUnit_id,Position_id FROM Profiles WHERE ID_VHUR = $vhur";
- $profile = $db->getAll($query_select);
- if (count($profile) >= 1) {
- $profile = $profile[0];
- if (validate_user($user)) {
- $query_update = prepared_update($user, $db, 1);
- if ($db->query($query_update)) {
- $updates++;
- }
- $processed = TRUE;
- $last_user = $db->getAll("SELECT * FROM Profiles WHERE ID_VHUR = $vhur");
- $last_user = $last_user[0];
- if ($last_user["SuperUnit_id"] !== $profile["SuperUnit_id"]) {
- $net = $last_user['network_login'];
- $oldsu = $last_user['SuperUnit_id'];
- $newsu = $profile['SuperUnit_id'];
- privacy_group($last_user, $user, $db);
- }
- array_push($vhurs, $vhur);
- } else {
- $temp_array = array("network_login" => $user["NickName"], "email" => $user["email"], "vhur" => $user["VHUR"], "position" => $user["position"], "position_id" => $user["position_id"], "unit" => $user["unit"], "unit_id" => $user["unit_id"], "superunit" => $user["superunit"], "superunit_id" => $user["superunit_id"], "domain_id" => $user["domain_id"], "domain" => $user["domain"]);
- array_push($no_updates, $temp_array);
- $processed = TRUE;
- }
- }
- }
- if (!empty($network_login) && is_null($processed)) {//Actualizar por network login
- $query_select = "SELECT ID_VHUR,Position_id,SuperUnit_id,Position_id FROM Profiles WHERE network_login = '$network_login'";
- $profile2 = $db->getAll($query_select);
- if (count($profile2) >= 1) {
- //Actualizar toda la informacion menos el network_login
- $profile2 = $profile2[0];
- if (validate_user($user)) {//is_numeric
- $query_update = prepared_update($user, $db, 2);
- if ($db->query($query_update)) {
- $updates++;
- }
- $processed = TRUE;
- $last_user = $db->getAll("SELECT * FROM Profiles WHERE network_login = '$network_login'");
- $last_user = $last_user[0];
- if ($last_user["SuperUnit_id"] !== $profile2["SuperUnit_id"]) {
- $net = $last_user['network_login'];
- $oldsu = $last_user['SuperUnit_id'];
- $newsu = $profile2['SuperUnit_id'];
- privacy_group($last_user, $user, $db);
- }
- $vhur = $user["VHUR"];
- array_push($vhurs, $vhur);
- } else {
- $temp_array = array("network_login" => $user["NickName"], "email" => $user["email"], "vhur" => $user["VHUR"], "position" => $user["position"], "position_id" => $user["position_id"], "unit" => $user["unit"], "unit_id" => $user["unit_id"], "superunit" => $user["superunit"], "superunit_id" => $user["superunit_id"], "domain_id" => $user["domain_id"], "domain" => $user["domain"]);
- array_push($no_updates, $temp_array);
- $processed = TRUE;
- }
- }
- }
- if (!$processed || is_null($processed)) {
- if (validate_user($user)) {//is_numeric
- $vhur = $user["VHUR"];
- $network_login = addslashes($user["NickName"]);
- $query_insert = prepared_insert($user, $db);
- if ($db->query($query_insert)) {
- $inserts++;
- }
- $processed = TRUE;
- $temp = $db->lastId();
- $last_user = $db->getAll("SELECT * FROM Profiles WHERE ID = $temp");
- $last_user = $last_user[0];
- /* Hacer al usuario amigo de los perfiles administrativos */
- $query = "SELECT ID
- FROM Profiles AS p
- WHERE p.NickName LIKE 'TLifeSupport'";
- $admin_profiles = $db->getAll($query);
- foreach ($admin_profiles as $profile) {
- $id = $profile["ID"];
- $pro = $last_user["ID"];
- $query_insert = "INSERT INTO `sys_friend_list` (`ID`, `Profile`, `Check`) VALUES ($pro,$id, 1);"; //"INSERT INTO sys_friend_list (ID, Profile,Check) VALUES ($id,$pro,1);";
- $db->query($query_insert);
- }
- $query_insert = "";
- $date_time = date("Y-m-d H:i:s");
- $db->query("INSERT INTO `sys_acl_levels_members` SET `IDMember` = '{$last_user['ID']}', `IDLevel` = 5, `DateStarts` = '$date_time', `TransactionID` = 0; ");
- privacy_group($last_user, $user, $db);
- $temp_array = array("network_login" => $user["NickName"], "email" => $user["email"], "vhur" => $user["VHUR"], "position" => $user["position"], "position_id" => $user["position_id"], "unit" => $user["unit"], "unit_id" => $user["unit_id"], "superunit" => $user["superunit"], "superunit_id" => $user["superunit_id"], "domain_id" => $user["domain_id"], "domain" => $user["domain"]);
- array_push($new_profiles, $temp_array);
- array_push($vhurs, $vhur);
- } else {
- $temp_array = array("network_login" => $user["NickName"], "email" => $user["email"], "vhur" => $user["VHUR"], "position" => $user["position"], "position_id" => $user["position_id"], "unit" => $user["unit"], "unit_id" => $user["unit_id"], "superunit" => $user["superunit"], "superunit_id" => $user["superunit_id"], "domain_id" => $user["domain_id"], "domain" => $user["domain"]);
- array_push($no_new, $temp_array);
- $processed = TRUE;
- }//else no se pudo insertar el usuario
- }
- if (is_null($user["VHUR"]) || strlen($user["VHUR"]) === 0) {
- $vhur = 0;
- } else {
- $vhur = $user["VHUR"];
- }
- array_push($vhurs, $vhur);
- }//foreach para recorrer los usuarios
- $new_disabled = disable_profiles($db, $vhurs, $netlogins);
- }//else se pudo convertir el contenido del WS a array
- }//else se pudo leer el WS
- $end = microtime(TRUE);
- $time = $end - $start;
- $hours = (int) ($time / 60 / 60);
- $minutes = (int) ($time / 60) - $hours * 60;
- $seconds = (int) $time - $hours * 60 * 60 - $minutes * 60;
- $no_new_count = count($no_new);
- $no_updates_count = count($no_updates);
- $time = "$hours horas - $minutes minutos - $seconds segundos.<br>";
- $resultados = "Se realizaron $inserts inserciones y $updates actualizaciones.<br> No se pudieron realizar $no_new_count nuevas inserciones y $no_updates_count actulizaciones <br>";
- $mail_body .= "La ejecucion tardo: $time $resultados $insert_table";
- $body = "<html><body>";
- if ($inserts > 0) {
- $insert_table = "<b>New profiles: $inserts</b><br><br>
- <table style='border: 1px solid #ccc;width: 100%;margin: 0;padding: 0;border-collapse: collapse;border-spacing: 0;'>
- <tr style='border: 1px solid #ddd;padding: 5px;'>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Network login</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Email</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >VHUR</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Position</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Position ID</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Unit</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Unit ID</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Superunit</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Superunit ID</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Domain</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Domain ID</th>
- </tr>";
- foreach ($new_profiles as $temp) {
- $insert_table .= "<tr style='border: 1px solid #ddd;padding: 5px;'>";
- $insert_table .= validate_data($temp['network_login']);
- $insert_table .= validate_data($temp['email']);
- $insert_table .= validate_data($temp['vhur']);
- $insert_table .= validate_data($temp['position']);
- $insert_table .= validate_data($temp['position_id']);
- $insert_table .= validate_data($temp['unit']);
- $insert_table .= validate_data($temp['unit_id']);
- $insert_table .= validate_data($temp['superunit']);
- $insert_table .= validate_data($temp['superunit_id']);
- $insert_table .= validate_data($temp['domain']);
- $insert_table .= validate_data($temp['domain_id']);
- /* $insert_table .= "<tr>
- <td>{$temp['network_login']}</td>
- <td>{$temp['email']}</td>
- <td>{$temp['position']}</td>
- <td>{$temp['position_id']}</td>
- <td>{$temp['unit']}</td>
- <td>{$temp['unit_id']}</td>
- <td>{$temp['superunit']}</td>
- <td>{$temp['superunit_id']}</td>
- </tr>"; */
- }
- $insert_table .= "</table><br><br>";
- $body .= "$insert_table";
- //$mail_body .= "$insert_table";
- }
- $new_disabled_count = count($new_disabled);
- if ($new_disabled_count > 0) {
- $disabled_table = "<b>Disbale users: {$new_disabled_count}</b><br><br>
- <table style='border: 1px solid #ccc;width: 100%;margin: 0;padding: 0;border-collapse: collapse;border-spacing: 0;'>
- <tr style='border: 1px solid #ddd;padding: 5px;'>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Network login</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Email</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >VHUR</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Position</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Position Id</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Unit</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Unit Id</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Superunit</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Superunit Id</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Domain</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Domain ID</th>
- </tr>";
- foreach ($new_disabled as $temp) {
- $disabled_table .= "<tr style='border: 1px solid #ddd;padding: 5px;'>";
- $disabled_table .= validate_data($temp['network_login']);
- $disabled_table .= validate_data($temp['email']);
- $disabled_table .= validate_data($temp['vhur']);
- $disabled_table .= validate_data($temp['position']);
- $disabled_table .= validate_data($temp['position_id']);
- $disabled_table .= validate_data($temp['unit']);
- $disabled_table .= validate_data($temp['unit_id']);
- $disabled_table .= validate_data($temp['superunit']);
- $disabled_table .= validate_data($temp['superunit_id']);
- $disabled_table .= validate_data($temp['domain']);
- $disabled_table .= validate_data($temp['domain_id']);
- }
- $disabled_table .= "</table><br><br>";
- $body .= "$disabled_table";
- //$mail_body .= "$disabled_table";
- }
- if ($no_new_count > 0) {
- $no_insert_table = "<b>Profiles that cannot be inserted: $no_new_count</b><br><br>
- <table style='border: 1px solid #ccc;width: 100%;margin: 0;padding: 0;border-collapse: collapse;border-spacing: 0;'>
- <tr style='border: 1px solid #ddd;padding: 5px;'>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Network login</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Email</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >VHUR</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Position</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Position Id</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Unit</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Unit Id</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Superunit</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Superunit Id</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Domain</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Domain ID</th>
- </tr>";
- foreach ($no_new as $temp) {
- $no_insert_table .= "<tr style='border: 1px solid #ddd;padding: 5px;'>";
- $no_insert_table .= validate_data($temp['network_login']);
- $no_insert_table .= validate_data($temp['email']);
- $no_insert_table .= validate_data($temp['vhur']);
- $no_insert_table .= validate_data($temp['position']);
- $no_insert_table .= validate_data($temp['position_id']);
- $no_insert_table .= validate_data($temp['unit']);
- $no_insert_table .= validate_data($temp['unit_id']);
- $no_insert_table .= validate_data($temp['superunit']);
- $no_insert_table .= validate_data($temp['superunit_id']);
- $no_insert_table .= validate_data($temp['domain']);
- $no_insert_table .= validate_data($temp['domain_id']);
- }
- $no_insert_table .= "</table><br><br>";
- $body .= "$no_insert_table";
- //$mail_body .= "$no_insert_table";
- }
- if ($no_updates_count > 0) {
- $no_update_table = "<br><br><b>Profiles that cannot be updated: $no_updates_count</b><br><br>
- <table style='border: 1px solid #ccc;width: 100%;margin: 0;padding: 0;border-collapse: collapse;border-spacing: 0;'>
- <tr style='border: 1px solid #ddd;padding: 5px;'>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Network login</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Email</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >VHUR</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Position</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Position Id</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Unit</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Unit Id</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Superunit</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;'>Superunit Id</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Domain</th>
- <th style = 'padding: 10px;text-align: left;font-size: 14px;letter-spacing: 1px;background-color:#49166D;color:white;' >Domain ID</th>
- </tr>";
- foreach ($no_updates as $temp) {
- $no_update_table .= "<tr style='border: 1px solid #ddd;padding: 5px;'>";
- $no_update_table .= validate_data($temp['network_login']);
- $no_update_table .= validate_data($temp['email']);
- $no_update_table .= validate_data($temp['vhur']);
- $no_update_table .= validate_data($temp['position']);
- $no_update_table .= validate_data($temp['position_id']);
- $no_update_table .= validate_data($temp['unit']);
- $no_update_table .= validate_data($temp['unit_id']);
- $no_update_table .= validate_data($temp['superunit']);
- $no_update_table .= validate_data($temp['superunit_id']);
- $no_update_table .= validate_data($temp['domain']);
- $no_update_table .= validate_data($temp['domain_id']);
- /* $no_update_table .= "<tr style='border: 1px solid #ddd;padding: 5px;'>
- <td style = 'padding:10px;text-align:left;' >{$temp['network_login']}</td>
- <td style = 'padding:10px;text-align:left;' >{$temp['email']}</td>
- <td style = 'padding:10px;text-align:left;' >{$temp['position']}</td>
- <td style = 'padding:10px;text-align:left;' >{$temp['position_id']}</td>
- <td style = 'padding:10px;text-align:left;' >{$temp['unit']}</td>
- <td style = 'padding:10px;text-align:left;' >{$temp['unit_id']}</td>
- <td style = 'padding:10px;text-align:left;' >{$temp['superunit']}</td>
- <td style = 'padding:10px;text-align:left;' >{$temp['superunit_id']}</td>
- </tr>"; */
- }
- $no_update_table .= "</table><br><br>";
- $body .= "$no_update_table";
- $mail_body .= "$no_update_table";
- }
- $body .= "</body></html>";
- echo "<br>" . $mail_body;
- echo "<br>" . $body;
- send_report_synch($body, "Tlife SV - Profiles synchronization", $db);
- function validate_user($user) {
- if (!is_null($user["VHUR"]) && strlen($user["VHUR"]) > 0 && !empty($user["NickName"]) && !is_null($user["first"]) && strlen($user["first"]) > 0 && !is_null($user["last"]) && strlen($user["last"]) > 0 && !is_null($user["email"]) && strlen($user["email"]) > 0 && !is_null($user["unit_id"]) && strlen($user["unit_id"]) > 0 && !is_null($user["superunit_id"]) && strlen($user["superunit_id"]) > 0 && !is_null($user["position_id"]) && strlen($user["position_id"]) > 0 && !is_null($user["domain_id"]) && strlen($user["domain_id"]) > 0 && !is_null($user["domain"]) && strlen($user["domain"]) > 0) {
- return TRUE;
- } else {
- return FALSE;
- }
- }
- function prepared_update($user, $db, $type) {
- //echo "entra a la funcion <br>";
- $data = prepared_data($user, $db);
- //echo "Va a entrar al la funcion <br>";
- if ($type === 1) {
- $query_update = "UPDATE Profiles SET `Email` = '{$data['email']}',`Password` = '{$data['password']}',`Salt` = '{$data['salt']}',`Status` = '{$data['status']}',
- `Role` = {$data['role']},`Sex` = '{$data['sex']}',`Country` = '{$data['country']}',`PrivacyDefaultGroup` = {$data['privacy_default_group']},
- `FirstName` = '{$data['first_name']}', `LastName` = '{$data['last_name']}', `Position` = '{$data['position']}', `Unit`= '{$data['unit']}',
- `SuperUnit` = '{$data['superunit']}', `Position_id` = {$data['position_id']},`Unit_id` = {$data['unit_id']}, `SuperUnit_id` = {$data['superunit_id']},
- `Supervisor` = '{$data['supervisor']}', `Active` = {$data['active']},`Full_name`= '{$data['full_name']}',`PersonalEmail` = '{$data['personal_email']}',
- `FullName` = '{$data['full_name']}', `network_login` = '{$data['network_login']}',`Is_sup` = {$data['is_sup']},`adl_domain` = '{$data['adl_domain']}',
- `adl_domain_id` = {$data['adl_domain_id']},`hire_date` = '{$data['hire_date']}', `DateLastEdit` = NOW(),`NickName` = '{$data['Nickname']}' WHERE ID_VHUR = {$data['vhur']} AND `NickName`NOT LIKE '%disabled%' AND CHAR_LENGTH(`NickName`) > 3 LIMIT 1;";
- } elseif ($type === 2) {
- $query_update = "UPDATE Profiles SET `Email` = '{$data['email']}',`Password` = '{$data['password']}',`Salt` = '{$data['salt']}',`Status` = '{$data['status']}',
- `Role` = {$data['role']},`Sex` = '{$data['sex']}',`Country` = '{$data['country']}',`PrivacyDefaultGroup` = {$data['privacy_default_group']},
- `FirstName` = '{$data['first_name']}', `LastName` = '{$data['last_name']}', `Position` = '{$data['position']}', `Unit`= '{$data['unit']}',
- `SuperUnit` = '{$data['superunit']}', `Position_id` = {$data['position_id']},`Unit_id` = {$data['unit_id']}, `SuperUnit_id` = {$data['superunit_id']},
- `Supervisor` = '{$data['supervisor']}', `Active` = {$data['active']},`Full_name`= '{$data['full_name']}',`PersonalEmail` = '{$data['personal_email']}',
- `FullName` = '{$data['full_name']}', ID_VHUR = {$data['vhur']},`Is_sup` = {$data['is_sup']},`adl_domain` = '{$data['adl_domain']}',
- `adl_domain_id` = {$data['adl_domain_id']},`hire_date` = '{$data['hire_date']}',`DateLastEdit` = NOW(),`NickName` = '{$data['Nickname']}' WHERE `network_login` = '{$data['network_login']}' AND `NickName`NOT LIKE '%disabled%' AND CHAR_LENGTH(`NickName`) > 3 LIMIT 1;";
- }
- return $query_update;
- }
- function prepared_insert($user, $db) {
- $data = prepared_data($user, $db);
- $query_insert = "INSERT INTO `Profiles` (`NickName`, `Email`,`Password`, `Salt`, `Status`, `Role`, `Sex`, `Country`, `DateReg`, `EmailNotify`, `LangID`, `PrivacyDefaultGroup`, `FirstName`, `LastName`, `Position`, `Unit`, `SuperUnit`, `ID_VHUR`, `Position_id`, `Unit_id`, `SuperUnit_id`, `Supervisor`, `Active`, `Full_name`, `PersonalEmail`, `FullName`, `network_login`, `Is_sup`, `hire_date`, `adl_domain`, `adl_domain_id`)
- VALUES ('{$data['Nickname']}','{$data['email']}','{$data['password']}','{$data['salt']}','{$data['status']}',{$data['role']},'{$data['sex']}','{$data['country']}',NOW(),'{$data['email_notify']}',{$data['lang_id']},{$data['privacy_default_group']},'{$data['first_name']}','{$data['last_name']}','{$data['position']}','{$data['unit']}','{$data['superunit']}',{$data['vhur']},{$data['position_id']},{$data['unit_id']},{$data['superunit_id']},'{$data['supervisor']}',{$data['active']},'{$data['full_name']}','{$data['personal_email']}','{$data['full_name']}','{$data['network_login']}',{$data['is_sup']},'{$data['hire_date']}','{$data['adl_domain']}',{$data['adl_domain_id']})";
- return $query_insert;
- }
- function prepared_data($user, $db) {
- $user_data = array();
- $email = strtolower(addslashes($user["email"]));
- $user_data["email"] = $email;
- $first_new = ucfirst(strtolower($user["first"]));
- $last_new = ucfirst(strtolower($user["last"]));
- $first_new = str_replace('"', '', $first_new);
- $last_new = str_replace('"', '', $last_new);
- $first_new = str_replace("'", "", $first_new);
- $user_data["first_name"] = $first_new;
- $last_new = str_replace("'", "", $last_new);
- $user_data["last_name"] = $last_new;
- $password = "eb74a10e0eff3b74f1e10408db817f59c0b8e744";
- $user_data["password"] = $password;
- $salt = "AWwHT9Pt";
- $user_data["salt"] = $salt;
- $status = "Active";
- $user_data["status"] = $status;
- $role = 1;
- $user_data["role"] = $role;
- $sex = ucfirst(strtolower($user["gender"]));
- $user_data["sex"] = $sex;
- $country = $db->getParam('default_country');
- $user_data["country"] = $country;
- $email_notify = 1;
- $user_data["email_notify"] = $email_notify;
- $lang_id = 1;
- $user_data["lang_id"] = $lang_id;
- $privacy_default_group = 3;
- $user_data["privacy_default_group"] = $privacy_default_group;
- $first_name = addslashes(ucfirst(strtolower($first_new)));
- $user_data["first_name"] = $first_name;
- $last_name = addslashes(ucfirst(strtolower($last_new)));
- $user_data["last_name"] = $last_name;
- $unit = addslashes($user["unit"]);
- $user_data["unit"] = $unit;
- $superunit = addslashes($user["superunit"]);
- $user_data["superunit"] = $superunit;
- $vhur = $user["VHUR"];
- $user_data["vhur"] = $vhur;
- $position_id = $user["position_id"];
- $user_data["position_id"] = $position_id;
- $unit_id = $user["unit_id"];
- $user_data["unit_id"] = $unit_id;
- $superunit_id = $user["superunit_id"];
- $user_data["superunit_id"] = $superunit_id;
- $active = 1;
- $user_data["active"] = $active;
- $full_name = $first_name . " " . $last_name;
- $user_data["full_name"] = $full_name;
- $personal_email = strtolower(addslashes($user["personal_email"]));
- $user_data["personal_email"] = $personal_email;
- $network_login = addslashes($user["NickName"]);
- $user_data["network_login"] = $network_login;
- $is_sup = $user["Is_sup"];
- $user_data["is_sup"] = $is_sup;
- if (strtolower($user["position"]) !== "null") {
- $position = $user["position"];
- } else {
- $position = "";
- }
- $user_data["position"] = $position;
- if (strtolower($user["hire_date"]) !== "null") {
- $hire_date = $user["hire_date"];
- } else {
- $hire_date = "";
- }
- $user_data["hire_date"] = $hire_date;
- if (is_numeric($user["position_id"])) {
- $position_id = $user["position_id"];
- } else {
- $position_id = 0;
- }
- $user_data["position_id"] = $position_id;
- if (!is_null($user["supervisor"]) && strlen($user["supervisor"]) > 0) {
- $supervisor = $user["supervisor"];
- } else {
- $supervisor = 0;
- }
- $user_data["supervisor"] = $supervisor;
- $adl_domain = strtoupper($user["domain"]);
- switch ($adl_domain) {
- case 'SV':
- $adl_domain_id = 3; //$user["ad_domain_id"];
- break;
- case 'TRTEL':
- $adl_domain_id = 2; //$user["ad_domain_id"];
- break;
- case 'TI':
- $adl_domain_id = 1; //$user["ad_domain_id"];
- break;
- default:
- break;
- }
- $user_data["adl_domain"] = $adl_domain;
- $user_data["adl_domain_id"] = $adl_domain_id;
- $user_data["Nickname"] = create_nickname2($first_name, $last_name, $email, $vhur, $db);
- return $user_data;
- }
- function create_nickname2($first, $last, $email, $vhur, $db) {
- if (empty($first) || empty($last)) {
- $parts = explode("@", $email);
- $temp = explode(".", $parts[0]);
- preg_replace('/[0-9]+/', '', $words);
- $new_nickname = ucfirst($temp[0]) . ucfirst($temp[1]);
- $nick_name = $new_nickname . "_" . $vhur;
- } else {
- $first = trim($first);
- $last = trim($last);
- $first_parts = explode(" ", $first);
- $last_parts = explode(" ", $last);
- $first_new = $last_new = "";
- foreach ($first_parts as $key) {
- $key = ucfirst($key);
- $first_new .= $key;
- }
- foreach ($last_parts as $key) {
- $key = ucfirst($key);
- $last_new .= $key;
- }
- $nick_name = $first_new . $last_new . "_" . $vhur;
- }
- //echo "$nick_name ---- $vhur<br>";
- return $nick_name;
- }
- function create_nickname($first, $last, $email, $db) {
- $first_temp = str_replace(" ", "-", $first);
- $first_temp2 = explode("-", $first_temp);
- if (is_array($first_temp2)) {
- for ($i = 0; $i < count($first_temp2); $i++) {
- $first_temp2[$i] = ucfirst(strtolower($first_temp2[$i]));
- }
- $first_new = "";
- $first_new = implode("", $first_temp2);
- } else {
- $first_new = ucfirst(strtolower($first_temp2));
- }
- $last_temp = str_replace(" ", "-", $last);
- $last_temp2 = explode("-", $last_temp);
- if (is_array($first_temp2)) {
- for ($i = 0; $i < count($last_temp2); $i++) {
- $last_temp2[$i] = ucfirst(strtolower($last_temp2[$i]));
- }
- $last_new = "";
- $last_new = implode("", $last_temp2);
- } else {
- $first_new = ucfirst(strtolower($first_temp2));
- }
- //echo "$first_new $last_new<br>";
- $nick_name = $first_new . $last_new;
- $exit = TRUE;
- $new_nickname = "";
- $query = "SELECT ID_VHUR FROM Profiles WHERE NickName LIKE '$nick_name'";
- $exits = $db->getAll($query);
- if (count($exits) === 1) {
- $temp_nickname = explode("@", $email);
- $temp_nickname2 = explode(".", $temp_nickname[0]);
- //echo count($temp_nickname2)."<br>";
- for ($i = 0; $i < count($temp_nickname2); $i++) {
- $temp_nickname2[$i] = ucfirst(strtolower($temp_nickname2[$i]));
- }
- $new_nickname = "";
- $new_nickname = implode("", $temp_nickname2);
- /* foreach ($temp_nickname2 as $temp_n) {
- echo "Nickname: $new_nickname<br>";
- $new_nickname .= $new_nickname.ucfirst(strtolower($temp_n));
- } */
- $prefix = 1;
- while ($exit) {
- $query = "SELECT ID_VHUR FROM Profiles WHERE NickName LIKE '$new_nickname'";
- //echo "$query <br>";
- $exits = $db->getAll($query);
- if (count($exits) >= 1) {
- $new_nickname = $new_nickname . $prefix;
- $prefix++;
- } else {
- $exit = FALSE;
- }
- }
- } else {
- $new_nickname = $nick_name;
- }
- return $new_nickname;
- }
- function privacy_group($last_user, $user, $db) {
- $privacy_groups = array();
- $query = "SELECT `id` FROM `sys_privacy_groups` WHERE `unit_id_relac` = '{$last_user['SuperUnit_id']}'; ";
- $superunit_pg = (int) $db->getOne($query);
- if (!$superunit_pg) {
- $last_user['SuperUnit'] = addslashes($last_user['SuperUnit']);
- $query = "INSERT INTO `sys_privacy_groups` SET `title` = '{$last_user['SuperUnit']}', `owner_id` = 1, `unit_id_relac` = '{$last_user['SuperUnit_id']}';";
- $db->query($query);
- $superunit_pg = $db->lastId();
- }
- $privacy_groups[] = $superunit_pg;
- if ($last_user["SuperUnit_id"] !== $last_user["Unit_id"]) {
- $superunit_pg = (int) $db->getOne("SELECT `id` FROM `sys_privacy_groups` WHERE `unit_id_relac` = '{$user['unit_id']}'; ");
- if (!$superunit_pg) {
- $last_user['SuperUnit'] = addslashes($last_user['Unit']);
- $db->query("INSERT INTO `sys_privacy_groups` SET `title` = '{$last_user['Unit']}', `owner_id` = 1, `unit_id_relac` = '{$last_user['Unit_id']}'; ");
- $superunit_pg = $db->lastId();
- }
- $privacy_groups[] = $superunit_pg;
- }
- $query_delete = "DELETE FROM sys_privacy_members WHERE member_id = '{$last_user['ID']}'";
- if ($db->query($query_delete)) {
- //
- }
- foreach ($privacy_groups as $privacy_group) {
- $db->query("INSERT IGNORE INTO `sys_privacy_members` SET `group_id` = '$privacy_group', `member_id` = '{$last_user['ID']}';");
- }
- }
- function validate_data($var) {
- $temp = set_null($var);
- if ($temp === "N/A") {
- $row = "<td style = 'padding:10px;text-align:left;color:red;font-weight: bold;'>$temp</td>";
- } else {
- $row = "<td style = 'padding:10px;text-align:left;'>$temp</td>";
- }
- return $row;
- }
- function set_null($var) {
- if (is_null($var) || strlen($var) === 0) {
- return "N/A";
- } else {
- return $var;
- }
- }
- function disable_profiles($db, $vhurs, $netlogins) {
- $sql_vhurs = "(";
- $sql_vhurs .= implode(",", $vhurs);
- $sql_vhurs .= ")";
- $sql_netlogins = "(";
- $sql_netlogins .= implode(",", $netlogins);
- $sql_netlogins .= ")";
- $query = "SELECT pro.network_login AS 'network_login',pro.Email AS 'email',pro.ID_VHUR AS 'vhur',pro.Position AS 'position',pro.Position_id AS 'position_id',pro.Unit AS 'unit',pro.Unit_id AS 'unit_id',pro.SuperUnit AS 'superunit',pro.SuperUnit_id AS 'superunit_id',pro.adl_domain AS 'domain',pro.adl_domain_id AS 'domain_id'
- FROM Profiles AS pro
- WHERE pro.ID_VHUR NOT IN $sql_vhurs AND
- pro.Role <> 3 AND pro.Active = 1
- ORDER BY pro.ID_VHUR";
- $oldVhrus = array();
- $result = $db->getAll($query);
- if (count($result) > 0) {
- foreach ($result as $vhur) {
- array_push($oldVhrus, $vhur["vhur"]);
- }
- $sql_vhurs = "(";
- $sql_vhurs .= implode(",", $oldVhrus);
- $sql_vhurs .= ")";
- $query_disable = "UPDATE Profiles SET Active = 2, Status = 'Suspended' WHERE ID_VHUR IN $sql_vhurs";
- echo "$query_disable <br><br><br><br>";
- $result2 = $db->query($query_disable);
- }
- return $result; //echo $query;
- }
- function send_report_synch($body, $email_subject, $db) {
- /* Get email params */
- $host = $db->getParam("email_setting_host");
- $from = $db->getParam("bx_mailread_mail");
- $email_password = $db->getParam("email_setting_password");
- $email_port = $db->getParam("email_setting_port");
- $recipients = $db->getParam("synch_profile_recipients");
- /* Send mail */
- $mail = new PHPMailer(); // the true param means it will throw exceptions on errors, which we need to catch
- $mail->CharSet = 'UTF-8';
- $mail->Host = $host; //"imap.gmail.com"; // SMTP server
- //$mail->IsSMTP();
- $mail->Username = $from; //"notifications@telusinternational.com"; // SMTP server
- $mail->Password = $email_password; //"Tr@nsact3l2013"; // SMTP server
- $mail->From = $from; //"notifications@telusinternational.com"; // SMTP server
- $mail->Port = $email_port; //25;
- //$mail->addAddress("carlos.recinos@telusinternational.com");
- $emails = explode(";", $recipients);
- foreach ($emails as $temp) {
- $mail->addAddress($temp);
- }
- $mail->SetFrom($from, 'Tlife SV - Profiles synchronization');
- $mail->Subject = $email_subject;
- $mail->MsgHTML($body);
- if (!$mail->Send()) {
- //echo "Message was not sent";
- echo "<div>$email_subject\n</div> \n
- \n host: $host from: $from Password: $email_password port: $email_port recipients: $recipients\n" . $mail->ErrorInfo;
- //echo "Mailer Error: " . $mail->ErrorInfo;
- //exit;
- } else {
- echo "<div>$email_subject\n
- </div>\n host: $host from: $from Password: $email_password port: $email_port recipients: $recipients";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement