dokeos-admin
[ class tree: dokeos-admin ] [ index: dokeos-admin ] [ all elements ]

Source for file class_import.php

Documentation is available at class_import.php

  1. <?php
  2. // $Id: class_import.php 10215 2006-11-27 13:57:17Z pcool $
  3. /*
  4. ==============================================================================
  5.     Dokeos - elearning and course management software
  6.  
  7.     Copyright (c) 2004 Dokeos S.A.
  8.     Copyright (c) 2003 Ghent University (UGent)
  9.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  10.     Copyright (c) Olivier Brouckaert
  11.     Copyright (c) Bart Mollet, Hogeschool Gent
  12.  
  13.     For a full list of contributors, see "credits.txt".
  14.     The full license can be read in "license.txt".
  15.  
  16.     This program is free software; you can redistribute it and/or
  17.     modify it under the terms of the GNU General Public License
  18.     as published by the Free Software Foundation; either version 2
  19.     of the License, or (at your option) any later version.
  20.  
  21.     See the GNU General Public License for more details.
  22.  
  23.     Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  24. ==============================================================================
  25. */
  26. /**
  27. ==============================================================================
  28. *   This     tool allows platform admins to add classes by uploading a CSV file
  29. @todo Add some langvars to DLTT
  30. *    @package dokeos.admin
  31. ==============================================================================
  32. */
  33. /**
  34.  * Validate the imported data
  35.  */
  36. function validate_data($classes)
  37. {
  38.     $errors array();
  39.     foreach($classes as $index => $class)
  40.     {
  41.         //1. Check if ClassName is available
  42.         if(!isset($class['ClassName']|| strlen(trim($class['ClassName'])) == 0)
  43.         {
  44.             $class['line'$index+2;
  45.             $class['error'get_lang('MissingClassName');
  46.             $errors[$class;
  47.         }    
  48.         //2. Check if class doesn't exist yet
  49.         else
  50.         {
  51.             if(ClassManager::class_name_exists($class['ClassName']))
  52.             {
  53.                 $class['line'$index+2;
  54.                 $class['error'get_lang('ClassNameExists');
  55.                 $errors[$class;                    
  56.             }    
  57.         }
  58.     }
  59.     return $errors;
  60. }
  61. /**
  62.  * Save imported class data to database
  63.  */
  64. function save_data($classes)
  65. {
  66.     $number_of_added_classes 0;
  67.     foreach($classes as $index => $class)
  68.     {
  69.         if(ClassManager::create_class($class['ClassName']))
  70.         {
  71.             $number_of_added_classes++;    
  72.         }    
  73.     }
  74.     return $number_of_added_classes;
  75. }
  76.  
  77.  
  78.  
  79. // name of the language file that needs to be included 
  80. $language_file array ('admin''registration');
  81.  
  82. // resetting the course id
  83. $cidReset true;
  84.  
  85. // including some necessary dokeos files
  86. include ('../inc/global.inc.php');
  87. require_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  88. require_once (api_get_path(LIBRARY_PATH).'classmanager.lib.php');
  89. require_once (api_get_path(LIBRARY_PATH).'import.lib.php');
  90. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  91.  
  92. // setting the section (for the tabs)
  93. $this_section SECTION_PLATFORM_ADMIN;
  94.  
  95. // Access restrictions
  96.  
  97. // setting breadcrumbs
  98. $interbreadcrumb[array ("url" => 'index.php'"name" => get_lang('PlatformAdmin'));
  99.  
  100. // Database Table Definitions
  101.  
  102. // setting the name of the tool
  103. $tool_name get_lang('ImportClassListCSV');
  104.  
  105. // Displaying the header
  106. Display :: display_header($tool_name);
  107. //api_display_tool_title($tool_name);
  108. $form new FormValidator('import_classes');
  109. $form->addElement('file','import_file',get_lang('ImportCSVFileLocation'));
  110. $form->addElement('submit','submit',get_lang('Ok'));
  111. if$form->validate())
  112. {
  113.     $classes Import::csv_to_array($_FILES['import_file']['tmp_name']);
  114.     $errors validate_data($classes);
  115.     if (count($errors== 0)
  116.     {
  117.         $number_of_added_classes save_data($classes);
  118.         Display::display_normal_message($number_of_added_classes.' '.get_lang('ClassesCreated'));
  119.     }        
  120.     else
  121.     {
  122.         $error_message get_lang('ErrorsWhenImportingFile');
  123.         $error_message .= '<ul>';
  124.         foreach ($errors as $index => $error_class)
  125.         {
  126.             $error_message .= '<li>'.$error_class['error'].' ('.get_lang('Line').' '.$error_class['line'].')';
  127.             $error_message .= '</li>';
  128.         }
  129.         $error_message .= '</ul>';
  130.         $error_message .= get_lang('NoClassesHaveBeenCreated');
  131.         Display :: display_error_message($error_message);
  132.     }
  133. }
  134. $form->display();
  135. ?>
  136. <p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'?> :</p>
  137. <blockquote>
  138.  <pre>
  139.   <b>ClassName</b>
  140.   <b>1A</b>
  141.   <b>1B</b>
  142.   <b>2A group 1</b>
  143.   <b>2A group 2</b>
  144.  </pre>
  145. </blockquote>
  146. <?php
  147. /*
  148. ==============================================================================
  149.         FOOTER 
  150. ==============================================================================
  151. */
  152. ?>

Documentation generated on Thu, 12 Jun 2008 13:07:35 -0500 by phpDocumentor 1.4.1