user_export.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. // $Id: user_export.php 9246 2006-09-25 13:24:53Z bmol $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) Olivier Brouckaert
  10. Copyright (c) Bart Mollet, Hogeschool Gent
  11. For a full list of contributors, see "credits.txt".
  12. The full license can be read in "license.txt".
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17. See the GNU General Public License for more details.
  18. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * @package dokeos.admin
  24. ==============================================================================
  25. */
  26. $langFile = 'admin';
  27. $cidReset = true;
  28. include ('../inc/global.inc.php');
  29. $this_section = SECTION_PLATFORM_ADMIN;
  30. api_protect_admin_script();
  31. include (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  32. include (api_get_path(LIBRARY_PATH).'export.lib.inc.php');
  33. include (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  34. $course_table = Database :: get_main_table(MAIN_COURSE_TABLE);
  35. $user_table = Database :: get_main_table(MAIN_USER_TABLE);
  36. $course_user_table = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
  37. $tool_name = get_lang('ExportUserListXMLCSV');
  38. //$interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('PlatformAdmin'));
  39. set_time_limit(0);
  40. $courses = array ();
  41. $courses[''] = '--';
  42. $sql = "SELECT code,visual_code,title FROM $course_table ORDER BY visual_code";
  43. $result = api_sql_query($sql, __FILE__, __LINE__);
  44. while ($course = mysql_fetch_object($result))
  45. {
  46. $courses[$course->code] = $course->visual_code.' - '.$course->title;
  47. }
  48. $form = new FormValidator('export_users');
  49. $form->addElement('radio', 'file_type', get_lang('OutputFileType'), 'XML','xml');
  50. $form->addElement('radio', 'file_type', null, 'CSV','csv');
  51. $form->addElement('select', 'course_code', get_lang('OnlyUsersFromCourse'), $courses);
  52. $form->addElement('submit', 'submit', get_lang('Ok'));
  53. $form->setDefaults(array('file_type'=>'csv'));
  54. if ($form->validate())
  55. {
  56. $export = $form->exportValues();
  57. $file_type = $export['file_type'];
  58. $course_code = $export['course_code'];
  59. $sql = "SELECT u.user_id AS UserId,
  60. u.lastname AS LastName,
  61. u.firstname AS FirstName,
  62. u.email AS Email,
  63. u.username AS UserName,
  64. u.password AS Password,
  65. u.auth_source AS AuthSource,
  66. u.status AS Statut,
  67. u.official_code AS OfficialCode,
  68. u.phone AS Phone";
  69. if (strlen($course_code) > 0)
  70. {
  71. $sql .= " FROM $user_table u, $course_user_table cu WHERE u.user_id = cu.user_id ORDER BY lastname,firstname";
  72. $filename = 'export_users_'.$course_code.'_'.date('Y-m-d_H-i-s');
  73. }
  74. else
  75. {
  76. $sql .= " FROM $user_table u ORDER BY lastname,firstname";
  77. $filename = 'export_users_'.date('Y-m-d_H-i-s');
  78. }
  79. $res = api_sql_query($sql,__FILE__,__LINE__);
  80. $data = array();
  81. while($user = mysql_fetch_array($res,MYSQL_ASSOC))
  82. {
  83. $data[] = $user ;
  84. }
  85. switch($file_type)
  86. {
  87. case 'xml':
  88. Export::export_table_xml($data,$filename,'Contact','Contacts');
  89. break;
  90. case 'csv':
  91. Export::export_table_csv($data,$filename);
  92. break;
  93. }
  94. }
  95. Display :: display_header($tool_name);
  96. //api_display_tool_title($tool_name);
  97. $form->display();
  98. /*
  99. ==============================================================================
  100. FOOTER
  101. ==============================================================================
  102. */
  103. Display :: display_footer();
  104. ?>