source-function-F_tsv_export_users

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
Overview

Classes

Interfaces

Exceptions

Functions

  1: <?php
  2: //============================================================+
  3: // File name   : tce_tsv_users.php
  4: // Begin       : 2006-03-30
  5: // Last Update : 2013-09-05
  6: //
  7: // Description : Functions to export users using TSV format.
  8: //
  9: // Author: Nicola Asuni
 10: //
 11: // (c) Copyright:
 12: //               Nicola Asuni
 13: //               Tecnick.com LTD
 14: //               www.tecnick.com
 15: //               info@tecnick.com
 16: //
 17: // License:
 18: //    Copyright (C) 2004-2013 Nicola Asuni - Tecnick.com LTD
 19: //    See LICENSE.TXT file for more information.
 20: //============================================================+
 21: 
 22: /**
 23:  * @file
 24:  * Display all users in TSV format.
 25:  * (Tab Delimited Text File)
 26:  * @package com.tecnick.tcexam.admin
 27:  * @author Nicola Asuni
 28:  * @since 2006-03-30
 29:  */
 30: 
 31: /**
 32:  */
 33: 
 34: // check user's authorization
 35: require_once('../config/tce_config.php');
 36: $pagelevel = K_AUTH_EXPORT_USERS;
 37: require_once('../../shared/code/tce_authorization.php');
 38: 
 39: // send headers
 40: header('Content-Description: TXT File Transfer');
 41: header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
 42: header('Pragma: public');
 43: header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
 44: header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
 45: // force download dialog
 46: header('Content-Type: application/force-download');
 47: header('Content-Type: application/octet-stream', false);
 48: header('Content-Type: application/download', false);
 49: header('Content-Type: text/tab-separated-values', false);
 50: // use the Content-Disposition header to supply a recommended filename
 51: header('Content-Disposition: attachment; filename=tcexam_users_'.date('YmdHis').'.tsv;');
 52: header('Content-Transfer-Encoding: binary');
 53: 
 54: echo F_tsv_export_users();
 55: 
 56: /**
 57:  * Export all users to TSV grouped by users' groups.
 58:  * @author Nicola Asuni
 59:  * @since 2006-03-30
 60:  * @return TSV data
 61:  */
 62: function F_tsv_export_users()
 63: {
 64:     global $l, $db;
 65:     require_once('../config/tce_config.php');
 66: 
 67:     $tsv = ''; // TSV data to be returned
 68: 
 69:     // print column names
 70:     $tsv .= 'user_id';
 71:     $tsv .= K_TAB.'user_name';
 72:     $tsv .= K_TAB.'user_password';
 73:     $tsv .= K_TAB.'user_email';
 74:     $tsv .= K_TAB.'user_regdate';
 75:     $tsv .= K_TAB.'user_ip';
 76:     $tsv .= K_TAB.'user_firstname';
 77:     $tsv .= K_TAB.'user_lastname';
 78:     $tsv .= K_TAB.'user_birthdate';
 79:     $tsv .= K_TAB.'user_birthplace';
 80:     $tsv .= K_TAB.'user_regnumber';
 81:     $tsv .= K_TAB.'user_ssn';
 82:     $tsv .= K_TAB.'user_level';
 83:     $tsv .= K_TAB.'user_verifycode';
 84:     $tsv .= K_TAB.'user_otpkey';
 85:     $tsv .= K_TAB.'user_groups';
 86: 
 87:     $sql = 'SELECT * FROM '.K_TABLE_USERS.' WHERE (user_id>1)';
 88:     if ($_SESSION['session_user_level'] < K_AUTH_ADMINISTRATOR) {
 89:         // filter for level
 90:         $sql .= ' AND ((user_level<'.$_SESSION['session_user_level'].') OR (user_id='.$_SESSION['session_user_id'].'))';
 91:         // filter for groups
 92:         $sql .= ' AND user_id IN (SELECT tb.usrgrp_user_id
 93:             FROM '.K_TABLE_USERGROUP.' AS ta, '.K_TABLE_USERGROUP.' AS tb
 94:             WHERE ta.usrgrp_group_id=tb.usrgrp_group_id
 95:                 AND ta.usrgrp_user_id='.intval($_SESSION['session_user_id']).'
 96:                 AND tb.usrgrp_user_id=user_id)';
 97:     }
 98:     $sql .= ' ORDER BY user_lastname,user_firstname,user_name';
 99:     if ($r = F_db_query($sql, $db)) {
100:         while ($m = F_db_fetch_array($r)) {
101:             $tsv .= K_NEWLINE.$m['user_id'];
102:             $tsv .= K_TAB.$m['user_name'];
103:             $tsv .= K_TAB; // password cannot be exported because is encrypted
104:             $tsv .= K_TAB.$m['user_email'];
105:             $tsv .= K_TAB.$m['user_regdate'];
106:             $tsv .= K_TAB.$m['user_ip'];
107:             $tsv .= K_TAB.$m['user_firstname'];
108:             $tsv .= K_TAB.$m['user_lastname'];
109:             $tsv .= K_TAB.substr($m['user_birthdate'], 0, 10);
110:             $tsv .= K_TAB.$m['user_birthplace'];
111:             $tsv .= K_TAB.$m['user_regnumber'];
112:             $tsv .= K_TAB.$m['user_ssn'];
113:             $tsv .= K_TAB.$m['user_level'];
114:             $tsv .= K_TAB.$m['user_verifycode'];
115:             $tsv .= K_TAB.$m['user_otpkey'];
116:             $tsv .= K_TAB;
117:             $grp = '';
118:             // comma separated list of user's groups
119:             $sqlg = 'SELECT *
120:                 FROM '.K_TABLE_GROUPS.', '.K_TABLE_USERGROUP.'
121:                 WHERE usrgrp_group_id=group_id
122:                     AND usrgrp_user_id='.$m['user_id'].'
123:                 ORDER BY group_name';
124:             if ($rg = F_db_query($sqlg, $db)) {
125:                 while ($mg = F_db_fetch_array($rg)) {
126:                     $grp .= $mg['group_name'].',';
127:                 }
128:             } else {
129:                 F_display_db_error();
130:             }
131:             if (!empty($grp)) {
132:                 // add user's groups removing last comma
133:                 $tsv .= substr($grp, 0, -1);
134:             }
135:         }
136:     } else {
137:         F_display_db_error();
138:     }
139:     return $tsv;
140: }
141: 
142: //============================================================+
143: // END OF FILE
144: //============================================================+
145: 
 

© 2004-2018 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy