diff --git a/main/admin/course_edit.php b/main/admin/course_edit.php old mode 100644 new mode 100755 index 62fd25762e..81fbc29aed --- a/main/admin/course_edit.php +++ b/main/admin/course_edit.php @@ -1,16 +1,9 @@ "course_list.php", "name" => get_lang('Admi define('USER_FIELD_TYPE_CHECKBOX', 10); -/* ------------------------------------------------------------ - Libraries ------------------------------------------------------------ -*/ -/* -============================================================================== - FUNCTIONS -============================================================================== -*/ - -/* -============================================================================== - MAIN CODE -============================================================================== -*/ +/* Libraries */ +/* MAIN CODE */ // Get all course categories $table_user = Database :: get_main_table(TABLE_MAIN_USER); @@ -54,8 +33,7 @@ $table_user = Database :: get_main_table(TABLE_MAIN_USER); //Get the course infos $sql = "SELECT * FROM $course_table WHERE code='".Database::escape_string($course_code)."'"; $result = Database::query($sql); -if (Database::num_rows($result) != 1) -{ +if (Database::num_rows($result) != 1) { header('Location: course_list.php'); exit (); } @@ -67,8 +45,7 @@ $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' O $sql = "SELECT user.user_id,lastname,firstname FROM $table_user as user,$table_course_user as course_user WHERE course_user.status='1' AND course_user.user_id=user.user_id AND course_user.course_code='".$course_code."'".$order_clause; $res = Database::query($sql); $course_teachers = array(); -while($obj = Database::fetch_object($res)) -{ +while ($obj = Database::fetch_object($res)) { $course_teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname); } @@ -78,14 +55,13 @@ $res = Database::query($sql); $teachers = array(); $platform_teachers[0] = '-- '.get_lang('NoManager').' --'; -while($obj = Database::fetch_object($res)) -{ - if(!array_key_exists($obj->user_id,$course_teachers)){ +while ($obj = Database::fetch_object($res)) { + if (!array_key_exists($obj->user_id,$course_teachers)) { $teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname); } - if($course['tutor_name']==$course_teachers[$obj->user_id]){ + if ($course['tutor_name']==$course_teachers[$obj->user_id]) { $course['tutor_name']=$obj->user_id; } //We add in the array platform teachers @@ -93,7 +69,7 @@ while($obj = Database::fetch_object($res)) } //Case where there is no teacher in the course -if(count($course_teachers)==0){ +if (count($course_teachers)==0) { $sql='SELECT tutor_name FROM '.$course_table.' WHERE code="'.$course_code.'"'; $res = Database::query($sql); $tutor_name=Database::result($res,0,0); @@ -171,8 +147,8 @@ $form->addRule('disk_quota', get_lang('ThisFieldIsRequired'),'required'); $form->addRule('disk_quota',get_lang('ThisFieldShouldBeNumeric'),'numeric'); $list_course_extra_field = CourseManager::get_course_extra_field_list($course_code); -foreach($list_course_extra_field as $extra_field){ - switch($extra_field['field_type']){ +foreach ($list_course_extra_field as $extra_field) { + switch ($extra_field['field_type']) { /* case USER_FIELD_TYPE_TEXT: case USER_FIELD_TYPE_TEXTAREA: case USER_FIELD_TYPE_RADIO: */ @@ -196,8 +172,7 @@ $course_db_name = $course['db_name']; $course['title'] = api_html_entity_decode($course['title'], ENT_QUOTES, $charset); $form->setDefaults($course); // Validate form -if( $form->validate()) -{ +if ($form->validate()) { $course = $form->getSubmitValues(); $dbName = $_POST['dbName']; $course_code = $course['code']; @@ -219,11 +194,11 @@ if( $form->validate()) } // an extra field $extras = array(); - foreach($course as $key => $value) { - if(substr($key,0,6)=='extra_') { + foreach ($course as $key => $value) { + if (substr($key,0,6)=='extra_') { $extras[substr($key,6)] = $value; } - if(substr($key,0,7)=='_extra_') { + if (substr($key,0,7)=='_extra_') { if(!array_key_exists(substr($key,7), $extras)) $extras[substr($key,7)] = $value; } } @@ -242,8 +217,7 @@ if( $form->validate()) $visibility = $course['visibility']; $subscribe = $course['subscribe']; $unsubscribe = $course['unsubscribe']; - if (!stristr($department_url, 'http://')) - { + if (!stristr($department_url, 'http://')) { $department_url = 'http://'.$department_url; } $sql = "UPDATE $course_table SET course_language='".Database::escape_string($course_language)."', @@ -261,31 +235,30 @@ if( $form->validate()) Database::query($sql); //update the extra fields - if(count($extras) > 0){ - foreach($extras as $key => $value) { + if (count($extras) > 0) { + foreach ($extras as $key => $value) { CourseManager::update_course_extra_field_value($course_code, $key, $value); } } //Delete only teacher relations that doesn't match the selected teachers $cond=''; - if(count($teachers)>0){ + if (count($teachers)>0) { foreach($teachers as $key) $cond.=" AND user_id<>'".$key."'"; } $sql='DELETE FROM '.$course_user_table.' WHERE course_code="'.Database::escape_string($course_code).'" AND status="1"'.$cond; Database::query($sql); - if(count($teachers)>0){ - foreach($teachers as $key){ + if (count($teachers)>0) { + foreach ($teachers as $key) { //We check if the teacher is already subscribed in this course $sql_select_teacher = 'SELECT 1 FROM '.$course_user_table.' WHERE user_id = "'.$key.'" AND course_code = "'.$course_code.'" '; $result = Database::query($sql_select_teacher); - if(Database::num_rows($result) == 1){ + if (Database::num_rows($result) == 1) { $sql = 'UPDATE '.$course_user_table.' SET status = "1" WHERE course_code = "'.$course_code.'" AND user_id = "'.$key.'" '; - } - else{ + } else { $sql = "INSERT INTO ".$course_user_table . " SET course_code = '".Database::escape_string($course_code). "', user_id = '".$key . "', @@ -296,9 +269,7 @@ if( $form->validate()) user_course_cat='0'"; } Database::query($sql); - } - } $sql = "INSERT IGNORE INTO ".$course_user_table . " SET @@ -325,8 +296,8 @@ Display::display_header($tool_name); echo ""; //api_display_tool_title($tool_name); // Display the form $form->display(); -/* -============================================================================== - FOOTER -============================================================================== -*/ -Display :: display_footer(); -?> +/* FOOTER */ +Display :: display_footer(); \ No newline at end of file