Просмотр исходного кода

Add teachers to course from a session see BT#6782

Julio Montoya 11 лет назад
Родитель
Сommit
09a2e8a903
2 измененных файлов с 264 добавлено и 1 удалено
  1. 240 0
      main/admin/add_teachers_to_session.php
  2. 24 1
      main/inc/lib/sessionmanager.lib.php

+ 240 - 0
main/admin/add_teachers_to_session.php

@@ -0,0 +1,240 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ *   @package chamilo.admin
+ */
+
+// name of the language file that needs to be included
+$language_file = array('admin','registration');
+
+// resetting the course id
+$cidReset = true;
+
+// including some necessary files
+require_once '../inc/global.inc.php';
+require_once '../inc/lib/xajax/xajax.inc.php';
+require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
+
+// setting the section (for the tabs)
+$this_section = SECTION_PLATFORM_ADMIN;
+
+// Access restrictions
+api_protect_admin_script(true);
+
+// setting breadcrumbs
+$interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
+
+// Setting the name of the tool
+$tool_name = get_lang('SubscribeTeachersToSession');
+$add_type = 'multiple';
+if (isset($_REQUEST['add_type']) && $_REQUEST['add_type']!='') {
+    $add_type = Security::remove_XSS($_REQUEST['add_type']);
+}
+$form_sent  = 0;
+$errorMsg   = '';
+$users = $sessions = array();
+
+$id = intval($_GET['id']);
+$htmlResult = null;
+
+if (isset($_POST['form_sent']) && $_POST['form_sent']) {
+    $form_sent = $_POST['form_sent'];
+    if ($form_sent == 1) {
+        $sessions = $_POST['sessions'];
+        $courses = $_POST['courses'];
+
+        $coachesPerSession = array();
+        foreach ($sessions as $sessionId) {
+            $coaches = SessionManager::getCoachesBySession($sessionId);
+            $coachesPerSession[$sessionId] = $coaches;
+        }
+
+        $result = array();
+
+        if (!empty($courses)) {
+            foreach ($courses as $courseId) {
+                $courseInfo = api_get_course_info_by_id($courseId);
+                foreach ($coachesPerSession as $sessionId => $coachList) {
+                    CourseManager::updateTeachers(
+                        $courseInfo['code'],
+                        $coachList,
+                        false,
+                        false,
+                        false
+                    );
+                    $result[$courseInfo['code']][$sessionId] = $coachList;
+                }
+            }
+        }
+        $sessionUrl = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session=';
+        if (!empty($result)) {
+            foreach ($result as $courseCode => $data) {
+                $url = api_get_course_url($courseCode);
+                $htmlResult .= get_lang('Course').': '.Display::url($courseCode, $url, array('target' => '_blank'));
+                foreach ($data as $sessionId => $coachList) {
+                    $htmlResult .= '<br />';
+                    $htmlResult .= Display::url(
+                        get_lang('Session').' #'.$sessionId.' ', $sessionUrl.$sessionId,
+                        array('target' => '_blank')
+                    );
+                    $teacherList = array();
+                    foreach ($coachList as $coachId) {
+                        $userInfo = api_get_user_info($coachId);
+                        $teacherList[] = $userInfo['complete_name'];
+                    }
+                    if (!empty($teacherList)) {
+                        $htmlResult .= implode(', ', $teacherList);
+                    } else {
+                        $htmlResult .= get_lang('NothingToAdd');
+                    }
+                }
+                $htmlResult .= '<br />';
+            }
+            $htmlResult = Display::return_message($htmlResult, 'normal', false);
+        }
+    }
+}
+
+$session_list = SessionManager::get_sessions_list(array(), array('name'));
+$sessionList = array();
+foreach ($session_list as $session) {
+    $sessionList[$session['id']] = $session['name'];
+}
+
+$courseList = CourseManager::get_courses_list();
+$courseOptions = array();
+foreach ($courseList as $course) {
+    $courseOptions[$course['id']] = $course['title'];
+}
+Display::display_header($tool_name);
+?>
+
+<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;" >
+<?php echo '<legend>'.$tool_name.' </legend>';
+echo $htmlResult;
+echo Display::input('hidden', 'form_sent', '1');
+?>
+    <table border="0" cellpadding="5" cellspacing="0" width="100%">
+        <tr>
+            <td align="center">
+                <b><?php echo get_lang('Sessions') ?> :</b>
+            </td>
+            <td></td>
+            <td align="center">
+                <b><?php echo get_lang('Courses') ?> :</b>
+            </td>
+        </tr>
+        <tr>
+            <td align="center">
+                <?php
+                 echo Display::select(
+                     'sessions[]',
+                     $sessionList,
+                     '',
+                     array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'sessions', 'size'=>'15px'),
+                     false
+                 );
+                ?>
+            </td>
+            <td align="center">
+            </td>
+            <td align="center">
+                <?php
+                echo Display::select(
+                    'courses[]',
+                    $courseOptions,
+                    '',
+                    array('style'=>'width:360px', 'id'=>'courses', 'size'=>'15px'),
+                    false
+                );
+                ?>
+            </td>
+        </tr>
+        <tr>
+            <td colspan="3" align="center">
+                <br />
+                <?php
+                echo '<button class="save" type="submit"" >'.
+                    get_lang('SubscribeTeachersToSession').'</button>';
+                ?>
+            </td>
+        </tr>
+    </table>
+</form>
+<script>
+    function moveItem(origin , destination) {
+        for(var i = 0 ; i<origin.options.length ; i++) {
+            if(origin.options[i].selected) {
+                destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
+                origin.options[i]=null;
+                i = i-1;
+            }
+        }
+        destination.selectedIndex = -1;
+        sortOptions(destination.options);
+    }
+
+    function sortOptions(options) {
+        newOptions = new Array();
+        for (i = 0 ; i<options.length ; i++)
+            newOptions[i] = options[i];
+
+        newOptions = newOptions.sort(mysort);
+        options.length = 0;
+        for(i = 0 ; i < newOptions.length ; i++)
+            options[i] = newOptions[i];
+    }
+
+    function mysort(a, b){
+        if (a.text.toLowerCase() > b.text.toLowerCase()){
+            return 1;
+        }
+        if (a.text.toLowerCase() < b.text.toLowerCase()){
+            return -1;
+        }
+        return 0;
+    }
+
+    function valide(){
+        var options = document.getElementById('session_in_promotion').options;
+        for (i = 0 ; i<options.length ; i++)
+            options[i].selected = true;
+        document.forms.formulaire.submit();
+    }
+
+    function loadUsersInSelect(select) {
+        var xhr_object = null;
+        if(window.XMLHttpRequest) // Firefox
+            xhr_object = new XMLHttpRequest();
+        else if(window.ActiveXObject) // Internet Explorer
+            xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
+        else  // XMLHttpRequest non supporté par le navigateur
+            alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
+
+        //xhr_object.open("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session ?>&letter="+select.options[select.selectedIndex].text, false);
+        xhr_object.open("POST", "loadUsersInSelect.ajax.php");
+        xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+        nosessionUsers = makepost(document.getElementById('session_not_in_promotion'));
+        sessionUsers = makepost(document.getElementById('session_in_promotion'));
+        nosessionClasses = makepost(document.getElementById('origin_classes'));
+        sessionClasses = makepost(document.getElementById('destination_classes'));
+        xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
+
+        xhr_object.onreadystatechange = function() {
+            if(xhr_object.readyState == 4) {
+                document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
+                //alert(xhr_object.responseText);
+            }
+        }
+    }
+
+    function makepost(select) {
+        var options = select.options;
+        var ret = "";
+        for (i = 0 ; i<options.length ; i++)
+            ret = ret + options[i].value +'::'+options[i].text+";;";
+        return ret;
+    }
+</script>
+<?php
+Display::display_footer();

+ 24 - 1
main/inc/lib/sessionmanager.lib.php

@@ -1347,7 +1347,7 @@ class SessionManager
 
 	/**
      * Get a list of sessions of which the given conditions match with an = 'cond'
-	 * @param  array $conditions a list of condition (exemple : array('status =' =>STUDENT) or array('s.name LIKE' => "%$needle%")
+	 * @param  array $conditions a list of condition (example : array('status =' =>STUDENT) or array('s.name LIKE' => "%$needle%")
 	 * @param  array $order_by a list of fields on which sort
 	 * @return array An array with all sessions of the platform.
 	 * @todo   optional course code parameter, optional sorting parameters...
@@ -2384,6 +2384,29 @@ class SessionManager
         return $coaches;
     }
 
+    /**
+     * Get all coaches added in the session - course relationship
+     * @param int $sessionId
+     * @return array
+     */
+    public static function getCoachesBySession($sessionId)
+    {
+        $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+        $sessionId = intval($sessionId);
+
+        $sql = "SELECT DISTINCT id_user FROM $tbl_session_rel_course_rel_user
+                WHERE id_session = '$sessionId' AND status = 2";
+        $result = Database::query($sql);
+
+        $coaches = array();
+        if (Database::num_rows($result) > 0) {
+            while ($row = Database::fetch_array($result)) {
+                $coaches[] = $row['id_user'];
+            }
+        }
+        return $coaches;
+    }
+
     /**
      * @param int $userId
      * @return array