12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- if (PHP_SAPI != 'cli') {
- die('This script can only be launched from the command line');
- }
- require __DIR__ . '/../../main/inc/global.inc.php';
- $referenceFields = array('razon_social', 'ruc');
- $tUserField = Database::get_main_table(TABLE_EXTRA_FIELD);
- $tUserFieldValue = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
- $tUser = Database::get_main_table(TABLE_MAIN_USER);
- $sql = "SELECT id, field_type, variable FROM $tUserField";
- $result = Database::query($sql);
- $foundFields = array();
- $fieldsNames = array();
- while ($row = Database::fetch_assoc($result)) {
- if ($row['field_type'] == 1 && in_array($row['variable'], $referenceFields)) {
- $foundFields[$row['variable']] = array('id' => $row['id']);
- $fieldsNames[$row['id']] = $row['variable'];
- }
- }
- $usersData = array();
- foreach ($foundFields as $key => $value) {
- $sql = "SELECT item_id as user_id, value FROM $tUserFieldValue WHERE field_id = " . $value['id'];
- $result = Database::query($sql);
- while ($row = Database::fetch_assoc($result)) {
- $foundFields[$key]['options'][$row['value']][] = $row['user_id'];
- if (empty($usersData[$row['user_id']])) {
- $usersData[$row['user_id']] = '';
- }
- if ($referenceFields[0] == $key) {
- $usersData[$row['user_id']] = $row['value'] . ' - ' . $usersData[$row['user_id']];
- } else {
- $usersData[$row['user_id']] .= $row['value'] . ' - ';
- }
- }
- }
- $distinctGroups = array();
- foreach ($usersData as $userId => $value) {
- $usersData[$userId] = substr($usersData[$userId], 0, -3);
- $distinctGroups[$usersData[$userId]][] = $userId;
- }
|