Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.13 KB | None | 0 0
  1. <?php
  2.     require_once('connection.class.php');
  3.     $connection = new connection();
  4.     $conn = $connection->getConnection();
  5.  
  6.     if (!isset($conn)) {
  7.         return json_encode(array("Error" => "Connection couldn't be stablished"));
  8.     }
  9.  
  10.     $stmt = "SELECT e.employee_global AS employee_global,
  11.                    e.first_name AS first_name,
  12.                    e.first_surname AS first_surname,
  13.                    CONCAT_WS(' ', first_name, second_name, first_surname, second_surname) AS full_name,
  14.                    per_info.gender AS gender,
  15.                    per_info.birthdate AS birthdate,
  16.                    e.company_email AS company_email,
  17.                    e.company_email AS email,
  18.                    e.second_company_email AS second_email,
  19.                    e.domain_username AS username,
  20.                    pos.name AS pos_name,
  21.                    pos_wd.name AS pos_name_wd,
  22.                    emp_subunit.position_id AS position_id, IFNULL(unit.name,unit_wd.name) AS unit_name,
  23.                    unit_wd.name AS unit_name_wd, IFNULL(emp_subunit.unit_id, emp_subunit.unit_id_wd) AS unit_id,
  24.                    emp_subunit.unit_id_wd AS unit_id_wd, IFNULL(subunit.name,subunit_wd.name) AS subunit_name,
  25.                    subunit_wd.name AS subunit_name_wd, IFNULL(emp_subunit.subunit_id, emp_subunit.subunit_id_wd) AS subunit_id,
  26.                    emp_subunit.subunit_id_wd AS subunit_id_wd,
  27.                    ope_info.supervisor_id AS supervisor_id,
  28.                    per_info.personal_email AS personal_email,
  29.                    e.is_active AS is_active,
  30.                    e.vhur AS vhur,
  31.  
  32.                    e.legacy_id AS legacy_id,
  33.                    emp_subunit.position_id_wd AS position_id_wd
  34.            FROM employee AS e
  35.            LEFT JOIN employee_operation_info AS ope_info ON (e.employee_global = ope_info.employee_id)
  36.            LEFT JOIN employee_personal_info AS per_info ON (e.employee_global = per_info.employee_id)
  37.            LEFT JOIN employee_subunit AS emp_subunit ON (e.employee_global = emp_subunit.employee_id)
  38.            LEFT JOIN posicion AS pos ON (emp_subunit.position_id = pos.id)
  39.            LEFT JOIN posicion AS pos_wd ON (emp_subunit.position_id_wd = pos_wd.id)
  40.            LEFT JOIN unit AS unit ON (emp_subunit.unit_id = unit.id)
  41.            LEFT JOIN unit AS unit_wd ON (emp_subunit.unit_id_wd = unit_wd.id)
  42.            LEFT JOIN subunit AS subunit ON (emp_subunit.subunit_id = subunit.id)
  43.            LEFT JOIN subunit AS subunit_wd ON (emp_subunit.subunit_id_wd = subunit_wd.id)
  44.            WHERE e.is_active = 1 ";
  45.    
  46.     /* Perform Query */
  47.     $result = mysql_query($stmt, $conn);
  48.     if (!$result) {
  49.         $sError = mysql_error($conn);
  50.        echo json_encode(array("Invalid query" => $sError));
  51.     }
  52.    
  53.     /* Use result */
  54.     $resp = array();
  55.     if ($result) {
  56.         /* Build array with the information */
  57.         while ($row = mysql_fetch_assoc($result)) {
  58.             $network_login = strongParseString($row['username']);
  59.             $resp[] = array(
  60.                 'employee_global' => $row['employee_global'],
  61.                 'first_name' => strongParseString($row['first_name']),
  62.                 'first_surname' => strongParseString($row['first_surname']),
  63.                 'full_name' => strongParseString($row['full_name']),
  64.                 'gender' => strongParseString($row['gender']),
  65.                 'birthdate' => strongParseString($row['birthdate']),
  66.                 'company_email' => strongParseString($row['company_email']),
  67.                 'email' => strongParseString($row['email']),
  68.                 'second_email' => strongParseString($row['second_email']),
  69.                 'username' => $network_login,
  70.                 'pos_name' => strongParseString($row['pos_name']),
  71.                 'position_id' => $row['position_id'],
  72.                 'unit_name' => strongParseString($row['unit_name']),
  73.                 'unit_id' => $row['unit_id'],
  74.                 'subunit_name' => strongParseString($row['subunit_name']),
  75.                 'subunit_id' => $row['subunit_id'],
  76.                 'supervisor_id' => $row['supervisor_id'],
  77.                 'personal_email' => strongParseString($row['personal_email']),
  78.                 'is_active' => $row['is_active'],
  79.                 'vhur' => preg_replace("/[^0-9]/","",  $row['vhur']),                
  80.                 'legacy_id' => $row['legacy_id'],
  81.                 'pos_name_wd' => strongParseString($row['pos_name_wd']),
  82.                 'position_id_wd' => $row['position_id_wd'],
  83.                 'unit_name_wd' => strongParseString($row['unit_name_wd']),
  84.                 'unit_id_wd' => $row['unit_id_wd'],
  85.                 'subunit_name_wd' => strongParseString($row['subunit_name_wd']),
  86.                 'subunit_id_wd' => $row['subunit_id_wd']
  87.             );
  88.         }
  89.     }
  90.     mysql_free_result($result);
  91.     mysql_close($conn);
  92.     echo json_encode($resp, JSON_HEX_AMP); /* Return the array in json format */
  93.    
  94.     function strongParseString($sString) {
  95.         return htmlspecialchars(str_replace("\0", "", str_replace("&#x0", "", mb_convert_encoding($sString, "UTF-8"))));
  96.     }
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement