source-function-F_xml_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_xml_users.php
  4: // Begin       : 2006-03-17
  5: // Last Update : 2013-09-05
  6: //
  7: // Description : Functions to export users' accounts using
  8: //               XML or JSON format.
  9: //
 10: // Author: Nicola Asuni
 11: //
 12: // (c) Copyright:
 13: //               Nicola Asuni
 14: //               Tecnick.com LTD
 15: //               www.tecnick.com
 16: //               info@tecnick.com
 17: //
 18: // License:
 19: //    Copyright (C) 2004-2013  Nicola Asuni - Tecnick.com LTD
 20: //    See LICENSE.TXT file for more information.
 21: //============================================================+
 22: 
 23: /**
 24:  * @file
 25:  * Display all users in XML or JSON format.
 26:  * @package com.tecnick.tcexam.admin
 27:  * @author Nicola Asuni
 28:  * @since 2006-03-17
 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: $output_format = isset($_REQUEST['format']) ? strtoupper($_REQUEST['format']) : 'XML';
 40: $out_filename = 'tcexam_users_'.date('YmdHis');
 41: $xml = F_xml_export_users();
 42: 
 43: switch ($output_format) {
 44:     case 'JSON': {
 45:         header('Content-Description: JSON File Transfer');
 46:         header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
 47:         header('Pragma: public');
 48:         header('Expires: Thu, 04 Jan 1973 00:00:00 GMT'); // Date in the past
 49:         header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
 50:         // force download dialog
 51:         header('Content-Type: application/force-download');
 52:         header('Content-Type: application/octet-stream', false);
 53:         header('Content-Type: application/download', false);
 54:         header('Content-Type: application/json', false);
 55:         // use the Content-Disposition header to supply a recommended filename
 56:         header('Content-Disposition: attachment; filename='.$out_filename.'.json;');
 57:         header('Content-Transfer-Encoding: binary');
 58:         $xmlobj = new SimpleXMLElement($xml);
 59:         echo json_encode($xmlobj);
 60:         break;
 61:     }
 62:     case 'XML':
 63:     default: {
 64:         header('Content-Description: XML File Transfer');
 65:         header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
 66:         header('Pragma: public');
 67:         header('Expires: Thu, 04 Jan 1973 00:00:00 GMT'); // Date in the past
 68:         header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
 69:         // force download dialog
 70:         header('Content-Type: application/force-download');
 71:         header('Content-Type: application/octet-stream', false);
 72:         header('Content-Type: application/download', false);
 73:         header('Content-Type: application/xml', false);
 74:         // use the Content-Disposition header to supply a recommended filename
 75:         header('Content-Disposition: attachment; filename='.$out_filename.'.xml;');
 76:         header('Content-Transfer-Encoding: binary');
 77:         echo $xml;
 78:         break;
 79:     }
 80: }
 81: 
 82: /**
 83:  * Export all users to XML grouped by users' groups.
 84:  * @author Nicola Asuni
 85:  * @since 2006-03-17
 86:  * @return XML data
 87:  */
 88: function F_xml_export_users()
 89: {
 90:     global $l, $db;
 91:     require_once('../config/tce_config.php');
 92: 
 93:     $boolean = array('false','true');
 94: 
 95:     $xml = ''; // XML data to be returned
 96: 
 97:     $xml .= '<'.'?xml version="1.0" encoding="UTF-8" ?'.'>'.K_NEWLINE;
 98:     $xml .= '<tcexamusers version="'.K_TCEXAM_VERSION.'">'.K_NEWLINE;
 99:     $xml .=  K_TAB.'<header';
100:     $xml .= ' lang="'.K_USER_LANG.'"';
101:     $xml .= ' date="'.date(K_TIMESTAMP_FORMAT).'">'.K_NEWLINE;
102:     $xml .= K_TAB.'</header>'.K_NEWLINE;
103:     $xml .=  K_TAB.'<body>'.K_NEWLINE;
104: 
105:     // select users
106:     $sqla = 'SELECT * FROM '.K_TABLE_USERS.' WHERE (user_id>1)';
107:     if ($_SESSION['session_user_level'] < K_AUTH_ADMINISTRATOR) {
108:         // filter for level
109:         $sqla .= ' AND ((user_level<'.$_SESSION['session_user_level'].') OR (user_id='.$_SESSION['session_user_id'].'))';
110:         // filter for groups
111:         $sqla .= ' AND user_id IN (SELECT tb.usrgrp_user_id
112:             FROM '.K_TABLE_USERGROUP.' AS ta, '.K_TABLE_USERGROUP.' AS tb
113:             WHERE ta.usrgrp_group_id=tb.usrgrp_group_id
114:                 AND ta.usrgrp_user_id='.intval($_SESSION['session_user_id']).'
115:                 AND tb.usrgrp_user_id=user_id)';
116:     }
117:     $sqla .= ' ORDER BY user_lastname,user_firstname,user_name';
118:     if ($ra = F_db_query($sqla, $db)) {
119:         while ($ma = F_db_fetch_array($ra)) {
120:             $xml .= K_TAB.K_TAB.K_TAB.'<user id="'.$ma['user_id'].'">'.K_NEWLINE;
121: 
122:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<name>';
123:             $xml .= F_text_to_xml($ma['user_name']);
124:             $xml .= '</name>'.K_NEWLINE;
125: 
126:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<password>';
127:             // password cannot be exported because is encrypted
128:             //$xml .= $ma['user_password'];
129:             $xml .= '</password>'.K_NEWLINE;
130: 
131:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<email>';
132:             $xml .= $ma['user_email'];
133:             $xml .= '</email>'.K_NEWLINE;
134: 
135:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<regdate>';
136:             $xml .= $ma['user_regdate'];
137:             $xml .= '</regdate>'.K_NEWLINE;
138: 
139:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<ip>';
140:             $xml .= $ma['user_ip'];
141:             $xml .= '</ip>'.K_NEWLINE;
142: 
143:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<firstname>';
144:             $xml .= F_text_to_xml($ma['user_firstname']);
145:             $xml .= '</firstname>'.K_NEWLINE;
146: 
147:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<lastname>';
148:             $xml .= F_text_to_xml($ma['user_lastname']);
149:             $xml .= '</lastname>'.K_NEWLINE;
150: 
151:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<birthdate>';
152:             $xml .= substr($ma['user_birthdate'], 0, 10);
153:             $xml .= '</birthdate>'.K_NEWLINE;
154: 
155:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<birthplace>';
156:             $xml .= F_text_to_xml($ma['user_birthplace']);
157:             $xml .= '</birthplace>'.K_NEWLINE;
158: 
159:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<regnumber>';
160:             $xml .= F_text_to_xml($ma['user_regnumber']);
161:             $xml .= '</regnumber>'.K_NEWLINE;
162: 
163:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<ssn>';
164:             $xml .= F_text_to_xml($ma['user_ssn']);
165:             $xml .= '</ssn>'.K_NEWLINE;
166: 
167:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<level>';
168:             $xml .= $ma['user_level'];
169:             $xml .= '</level>'.K_NEWLINE;
170: 
171:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<verifycode>';
172:             $xml .= $ma['user_verifycode'];
173:             $xml .= '</verifycode>'.K_NEWLINE;
174: 
175:             $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<otpkey>';
176:             $xml .= $ma['user_otpkey'];
177:             $xml .= '</otpkey>'.K_NEWLINE;
178: 
179:             // add user's groups
180:             $sqlg = 'SELECT *
181:                 FROM '.K_TABLE_GROUPS.', '.K_TABLE_USERGROUP.'
182:                 WHERE usrgrp_group_id=group_id
183:                     AND usrgrp_user_id='.$ma['user_id'].'
184:                 ORDER BY group_name';
185:             if ($rg = F_db_query($sqlg, $db)) {
186:                 while ($mg = F_db_fetch_array($rg)) {
187:                     $xml .= K_TAB.K_TAB.K_TAB.K_TAB.'<group id="'.$mg['group_id'].'">';
188:                     $xml .= $mg['group_name'];
189:                     $xml .= '</group>'.K_NEWLINE;
190:                 }
191:             } else {
192:                 F_display_db_error();
193:             }
194: 
195:             $xml .= K_TAB.K_TAB.K_TAB.'</user>'.K_NEWLINE;
196:         }
197:     } else {
198:         F_display_db_error();
199:     }
200: 
201:     $xml .= K_TAB.'</body>'.K_NEWLINE;
202:     $xml .= '</tcexamusers>'.K_NEWLINE;
203:     return $xml;
204: }
205: 
206: //============================================================+
207: // END OF FILE
208: //============================================================+
209: 
 

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