function WSListCourses($params)
{
    if (!WSHelperVerifyKey($params)) {
        return return_error(WS_ERROR_SECRET_KEY);
    }
    $course_field_name = isset($params['original_course_id_name']) ? $params['original_course_id_name'] : '';
    $courses_result = array();
    $category_names = array();
    $courses = CourseManager::get_courses_list();
    foreach ($courses as $course) {
        $course_tmp = array();
        $course_tmp['id'] = $course['id'];
        $course_tmp['code'] = $course['code'];
        $course_tmp['title'] = $course['title'];
        $course_tmp['language'] = $course['course_language'];
        $course_tmp['visibility'] = $course['visibility'];
        // Determining category name
        if (!empty($course['category_code']) && $category_names[$course['category_code']]) {
            $course_tmp['category_name'] = $category_names[$course['category_code']];
        } else {
            $category = CourseManager::get_course_category($course['category_code']);
            $category_names[$course['category_code']] = $category['name'];
            $course_tmp['category_name'] = $category['name'];
        }
        // Determining number of students registered in course
        $course_tmp['number_students'] = CourseManager::get_users_count_in_course($course['code']);
        // Determining external course id
        $externalCourseId = '';
        if ($course_field_name) {
            $externalCourseId = CourseManager::get_course_extra_field_value($course_field_name, $course['code']);
        }
        $course_tmp['external_course_id'] = $externalCourseId;
        $courses_result[] = $course_tmp;
    }
    return $courses_result;
}
	/**
	 * List courses
	 *
	 * @param string API secret key
	 * @param string A list of visibility filter we want to apply
	 * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
	 * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
	 */
	public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') {
		$verifKey = $this->verifyKey($secret_key);
		if($verifKey instanceof WSError) {
			$this->handleError($verifKey);
		} else {
            $visibilities = split(',',$visibility);
            $vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0');
            foreach ($visibilities as $p => $visibility) {
                $visibilities[$p] = $vis[$visibility];
            }
			$courses_result = array();
			$category_names = array();

			$courses = CourseManager::get_courses_list();
			foreach($courses as $course) {
                //skip elements that do not match required visibility
                if (!in_array($course['visibility'],$visibilities)) { continue; }
				$course_tmp = array();
				$course_tmp['id'] = $course['id'];
				$course_tmp['code'] = $course['code'];
				$course_tmp['title'] = $course['title'];
				$course_tmp['language'] = $course['course_language'];
				$course_tmp['visibility'] = $course['visibility'];

				// Determining category name
				if($category_names[$course['category_code']]) {
					$course_tmp['category_name'] = $category_names[$course['category_code']];
				} else {
					$category = CourseManager::get_course_category($course['category_code']);
					$category_names[$course['category_code']] = $category['name'];
					$course_tmp['category_name'] = $category['name'];
				}

				// Determining number of students registered in course
				$user_list = CourseManager::get_user_list_from_course_code($course['code'], 0);
				$course_tmp['number_students'] = count($user_list);

				// Determining external course id - this code misses the external course id field name
				// $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']);


				$courses_result[] = $course_tmp;
			}

			return $courses_result;
		}
	}
 /**
  * It's used to print attendance sheet
  * @param string action
  * @param int    attendance id
  */
 public function attendance_sheet_export_to_pdf($action, $attendance_id, $student_id = 0, $course_id = '')
 {
     $attendance = new Attendance();
     $courseInfo = CourseManager::get_course_information($course_id);
     $attendance->set_course_id($courseInfo['code']);
     $data_array = array();
     $data_array['attendance_id'] = $attendance_id;
     $data_array['users_in_course'] = $attendance->get_users_rel_course($attendance_id);
     $filter_type = 'today';
     if (!empty($_REQUEST['filter'])) {
         $filter_type = $_REQUEST['filter'];
     }
     $my_calendar_id = null;
     if (is_numeric($filter_type)) {
         $my_calendar_id = $filter_type;
         $filter_type = 'calendar_id';
     }
     $data_array['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id, $filter_type, $my_calendar_id);
     if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
         $data_array['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id);
     } else {
         if (!empty($student_id)) {
             $user_id = intval($student_id);
         } else {
             $user_id = api_get_user_id();
         }
         $data_array['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, $user_id);
         $data_array['faults'] = $attendance->get_faults_of_user($user_id, $attendance_id);
         $data_array['user_id'] = $user_id;
     }
     $data_array['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id);
     //Set headers pdf
     $courseCategory = CourseManager::get_course_category($courseInfo['category_code']);
     $teacherInfo = CourseManager::get_teacher_list_from_course_code($courseInfo['real_id']);
     $teacherName = null;
     foreach ($teacherInfo as $dados) {
         if ($teacherName != null) {
             $teacherName = $teacherName . " / ";
         }
         $teacherName .= $dados['firstname'] . " " . $dados['lastname'];
     }
     // Get data table - Marco - ordenacao fixa - just fullname
     $data_table = array();
     $head_table = array('#', get_lang('Name'));
     foreach ($data_array['attendant_calendar'] as $class_day) {
         //$head_table[] = api_format_date($class_day['date_time'], DATE_FORMAT_SHORT).' <br />'.api_format_date($class_day['date_time'], TIME_NO_SEC_FORMAT);
         $head_table[] = api_format_date($class_day['date_time'], DATE_FORMAT_NUMBER_NO_YEAR);
     }
     $data_table[] = $head_table;
     $dataClass = array();
     $max_dates_per_page = 10;
     $data_attendant_calendar = $data_array['attendant_calendar'];
     $data_users_presence = $data_array['users_presence'];
     $count = 1;
     if (!empty($data_array['users_in_course'])) {
         foreach ($data_array['users_in_course'] as $user) {
             $cols = 1;
             $result = array();
             $result['count'] = $count;
             $result['full_name'] = api_get_person_name($user['firstname'], $user['lastname']);
             foreach ($data_array['attendant_calendar'] as $class_day) {
                 if ($class_day['done_attendance'] == 1) {
                     if ($data_users_presence[$user['user_id']][$class_day['id']]['presence'] == 1) {
                         $result[$class_day['id']] = get_lang('UserAttendedSymbol');
                     } else {
                         $result[$class_day['id']] = get_lang('UserNotAttendedSymbol');
                     }
                 } else {
                     $result[$class_day['id']] = " ";
                 }
                 $cols++;
             }
             $count++;
             $data_table[] = $result;
         }
     }
     $max_cols_per_page = 12;
     //10 dates + 2 name and number
     $max_dates_per_page = $max_dates_per_page_original = $max_cols_per_page - 2;
     //10
     $rows = count($data_table);
     if ($cols > $max_cols_per_page) {
         $number_tables = round(($cols - 2) / $max_dates_per_page);
         $headers = $data_table[0];
         $all = array();
         $tables = array();
         $changed = 1;
         for ($i = 0; $i <= $rows; $i++) {
             $row = $data_table[$i];
             $key = 1;
             $max_dates_per_page = 10;
             $item = $data_table[$i];
             $count_j = 0;
             if (!empty($item)) {
                 foreach ($item as $value) {
                     if ($count_j >= $max_dates_per_page) {
                         $key++;
                         $max_dates_per_page = $max_dates_per_page_original * $key;
                         //magic hack
                         $tables[$key][$i][] = $tables[1][$i][0];
                         $tables[$key][$i][] = $tables[1][$i][1];
                     }
                     $tables[$key][$i][] = $value;
                     $count_j++;
                 }
             }
         }
         $content = null;
         if (!empty($tables)) {
             foreach ($tables as $sub_table) {
                 $content .= Export::convert_array_to_html($sub_table) . '<br /><br />';
             }
         }
     } else {
         $content .= Export::convert_array_to_html($data_table, array('header_attributes' => array('align' => 'center')));
     }
     $params = array('filename' => get_lang('Attendance') . '-' . api_get_local_time(), 'pdf_title' => $courseInfo['title'], 'course_code' => $courseInfo['code'], 'add_signatures' => true, 'orientation' => 'landscape', 'pdf_teachers' => $teacherName, 'pdf_course_category' => $courseCategory['name'], 'format' => 'A4-L', 'orientation' => 'L');
     Export::export_html_to_pdf($content, $params);
     exit;
 }
	/**
	 * List courses
	 *
	 * @param string API secret key
	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
	 * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
	 * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
	 */
	public function ListCourses($secret_key, $course_id_field_name) {
		$verifKey = $this->verifyKey($secret_key);
		if($verifKey instanceof WSError) {
			$this->handleError($verifKey);
		} else {
			$courses_result = array();
			$category_names = array();

			$courses = CourseManager::get_courses_list();
			foreach($courses as $course) {
				$course_tmp = array();
				$course_tmp['id'] = $course['id'];
				$course_tmp['code'] = $course['code'];
				$course_tmp['title'] = $course['title'];
				$course_tmp['language'] = $course['course_language'];
				$course_tmp['visibility'] = $course['visibility'];

				// Determining category name
				if($category_names[$course['category_code']]) {
					$course_tmp['category_name'] = $category_names[$course['category_code']];
				} else {
					$category = CourseManager::get_course_category($course['category_code']);
					$category_names[$course['category_code']] = $category['name'];
					$course_tmp['category_name'] = $category['name'];
				}

				// Determining number of students registered in course
				$user_list = CourseManager::get_user_list_from_course_code($course['code']);
				$course_tmp['number_students'] = count($user_list);

				// Determining external course id
				$course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']);


				$courses_result[] = $course_tmp;
			}

			return $courses_result;
		}
	}