Browse Source

Removing unused code, removing dbname validation.

Julio Montoya 11 years ago
parent
commit
4de9a39fa0
1 changed files with 13 additions and 37 deletions
  1. 13 37
      main/admin/course_import.php

+ 13 - 37
main/admin/course_import.php

@@ -3,23 +3,15 @@
 
 /**
  * This tool allows platform admins to create courses by uploading a CSV file
- * Copyright (c) 2010 Chamilo Association
- * Copyright (c) 2008 Dokeos SPRL
  * Copyright (c) 2005 Bart Mollet <bart.mollet@hogent.be>
- * @todo Add some language variables to Chamilo Translation Application
  * @package chamilo.admin
  */
 
 /**
  * Validates imported data.
  */
-function validate_data($courses) {
-    global $_configuration;
-    global $purification_option_for_usernames;
-    $dbnamelength = strlen($_configuration['db_prefix']);
-    // Ensure the prefix + database name do not get over 40 characters.
-    $maxlength = 40 - $dbnamelength;
-
+function validate_data($courses)
+{
     $errors = array ();
     $coursecodes = array ();
     foreach ($courses as $index => $course) {
@@ -27,7 +19,7 @@ function validate_data($courses) {
 
         // 1. Check whether mandatory fields are set.
         $mandatory_fields = array ('Code', 'Title', 'CourseCategory');
-        foreach ($mandatory_fields as $key => $field) {
+        foreach ($mandatory_fields as $field) {
             if (!isset($course[$field]) || strlen($course[$field]) == 0) {
                 $course['error'] = get_lang($field.'Mandatory');
                 $errors[] = $course;
@@ -40,18 +32,10 @@ function validate_data($courses) {
             if (isset($coursecodes[$course['Code']])) {
                 $course['error'] = get_lang('CodeTwiceInFile');
                 $errors[] = $course;
-            }
-            // 2.2 Check course code length.
-            elseif (api_strlen($course['Code']) > $maxlength) {
-                $course['error'] = get_lang('Max');
-                $errors[] = $course;
-            }
-            // 2.3 Check whether course code has been occupied.
-            else {
-                $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
-                $sql = "SELECT * FROM $course_table WHERE code = '".Database::escape_string($course['Code'])."'";
-                $res = Database::query($sql);
-                if (Database::num_rows($res) > 0) {
+            } else {
+                // 2.2 Check whether course code has been occupied.
+                $courseInfo = api_get_course_info($course['Code']);
+                if (!empty($courseInfo)) {
                     $course['error'] = get_lang('CodeExists');
                     $errors[] = $course;
                 }
@@ -62,7 +46,6 @@ function validate_data($courses) {
         // 3. Check whether teacher exists.
         $teacherList = getTeacherListInArray($course['Teacher']);
 
-
         if (!empty($teacherList)) {
             foreach ($teacherList as $teacher) {
                 $teacherInfo = api_get_user_info_from_username($teacher);
@@ -78,7 +61,6 @@ function validate_data($courses) {
             }
         }
 
-
         // 4. Check whether course category exists.
         if (isset($course['CourseCategory']) && strlen($course['CourseCategory']) != 0) {
             require_once api_get_path(LIBRARY_PATH).'course_category.lib.php';
@@ -105,16 +87,11 @@ function getTeacherListInArray($teachers)
  * Saves imported data.
  * @param array   List of courses
  */
-function save_data($courses) {
-    global $purification_option_for_usernames;
-
-    $user_table = Database::get_main_table(TABLE_MAIN_USER);
+function save_data($courses)
+{
     $msg = '';
-
-    foreach ($courses as $index => $course) {
+    foreach ($courses as $course) {
         $course_language = api_get_valid_language($course['Language']);
-        $username = '';
-
         $teachers = getTeacherListInArray($course['Teacher']);
         $teacherList = array();
         $creatorId = api_get_user_id();
@@ -139,13 +116,11 @@ function save_data($courses) {
         $course_info = CourseManager::create_course($params);
 
         if (!empty($course_info)) {
-
             if (!empty($teacherList)) {
                 foreach ($teacherList as $teacher) {
                     CourseManager::add_user_to_course($teacher['user_id'], $course_info['code'], COURSEMANAGER);
                 }
             }
-
             $msg .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/">
                     '.$course_info['title'].'</a> '.get_lang('Created').'<br />';
         }
@@ -161,7 +136,8 @@ function save_data($courses) {
  * @param string $file Path to the CSV-file
  * @return array All course-information read from the file
  */
-function parse_csv_data($file) {
+function parse_csv_data($file)
+{
     $courses = Import::csv_to_array($file);
     return $courses;
 }
@@ -250,4 +226,4 @@ BIO0017;Language;LANG;;english
 </blockquote>
 
 <?php
-Display :: display_footer();
+Display :: display_footer();